netcp.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * NetCP driver local header
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated
  5. * Authors: Sandeep Nair <sandeep_n@ti.com>
  6. * Sandeep Paulraj <s-paulraj@ti.com>
  7. * Cyril Chemparathy <cyril@ti.com>
  8. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  9. * Wingman Kwok <w-kwok2@ti.com>
  10. * Murali Karicheri <m-karicheri2@ti.com>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation version 2.
  15. *
  16. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  17. * kind, whether express or implied; without even the implied warranty
  18. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. */
  21. #ifndef __NETCP_H__
  22. #define __NETCP_H__
  23. #include <linux/netdevice.h>
  24. #include <linux/soc/ti/knav_dma.h>
  25. #include <linux/u64_stats_sync.h>
  26. /* Maximum Ethernet frame size supported by Keystone switch */
  27. #define NETCP_MAX_FRAME_SIZE 9504
  28. #define SGMII_LINK_MAC_MAC_AUTONEG 0
  29. #define SGMII_LINK_MAC_PHY 1
  30. #define SGMII_LINK_MAC_MAC_FORCED 2
  31. #define SGMII_LINK_MAC_FIBER 3
  32. #define SGMII_LINK_MAC_PHY_NO_MDIO 4
  33. #define RGMII_LINK_MAC_PHY 5
  34. #define RGMII_LINK_MAC_PHY_NO_MDIO 7
  35. #define XGMII_LINK_MAC_PHY 10
  36. #define XGMII_LINK_MAC_MAC_FORCED 11
  37. struct netcp_device;
  38. struct netcp_tx_pipe {
  39. struct netcp_device *netcp_device;
  40. void *dma_queue;
  41. unsigned int dma_queue_id;
  42. /* To port for packet forwarded to switch. Used only by ethss */
  43. u8 switch_to_port;
  44. #define SWITCH_TO_PORT_IN_TAGINFO BIT(0)
  45. u8 flags;
  46. void *dma_channel;
  47. const char *dma_chan_name;
  48. };
  49. #define ADDR_NEW BIT(0)
  50. #define ADDR_VALID BIT(1)
  51. enum netcp_addr_type {
  52. ADDR_ANY,
  53. ADDR_DEV,
  54. ADDR_UCAST,
  55. ADDR_MCAST,
  56. ADDR_BCAST
  57. };
  58. struct netcp_addr {
  59. struct netcp_intf *netcp;
  60. unsigned char addr[ETH_ALEN];
  61. enum netcp_addr_type type;
  62. unsigned int flags;
  63. struct list_head node;
  64. };
  65. struct netcp_stats {
  66. struct u64_stats_sync syncp_rx ____cacheline_aligned_in_smp;
  67. u64 rx_packets;
  68. u64 rx_bytes;
  69. u32 rx_errors;
  70. u32 rx_dropped;
  71. struct u64_stats_sync syncp_tx ____cacheline_aligned_in_smp;
  72. u64 tx_packets;
  73. u64 tx_bytes;
  74. u32 tx_errors;
  75. u32 tx_dropped;
  76. };
  77. struct netcp_intf {
  78. struct device *dev;
  79. struct device *ndev_dev;
  80. struct net_device *ndev;
  81. bool big_endian;
  82. unsigned int tx_compl_qid;
  83. void *tx_pool;
  84. struct list_head txhook_list_head;
  85. unsigned int tx_pause_threshold;
  86. void *tx_compl_q;
  87. unsigned int tx_resume_threshold;
  88. void *rx_queue;
  89. void *rx_pool;
  90. struct list_head rxhook_list_head;
  91. unsigned int rx_queue_id;
  92. void *rx_fdq[KNAV_DMA_FDQ_PER_CHAN];
  93. struct napi_struct rx_napi;
  94. struct napi_struct tx_napi;
  95. #define ETH_SW_CAN_REMOVE_ETH_FCS BIT(0)
  96. u32 hw_cap;
  97. /* 64-bit netcp stats */
  98. struct netcp_stats stats;
  99. void *rx_channel;
  100. const char *dma_chan_name;
  101. u32 rx_pool_size;
  102. u32 rx_pool_region_id;
  103. u32 tx_pool_size;
  104. u32 tx_pool_region_id;
  105. struct list_head module_head;
  106. struct list_head interface_list;
  107. struct list_head addr_list;
  108. bool netdev_registered;
  109. bool primary_module_attached;
  110. /* Lock used for protecting Rx/Tx hook list management */
  111. spinlock_t lock;
  112. struct netcp_device *netcp_device;
  113. struct device_node *node_interface;
  114. /* DMA configuration data */
  115. u32 msg_enable;
  116. u32 rx_queue_depths[KNAV_DMA_FDQ_PER_CHAN];
  117. };
  118. #define NETCP_PSDATA_LEN KNAV_DMA_NUM_PS_WORDS
  119. struct netcp_packet {
  120. struct sk_buff *skb;
  121. __le32 *epib;
  122. u32 *psdata;
  123. u32 eflags;
  124. unsigned int psdata_len;
  125. struct netcp_intf *netcp;
  126. struct netcp_tx_pipe *tx_pipe;
  127. bool rxtstamp_complete;
  128. void *ts_context;
  129. void (*txtstamp)(void *ctx, struct sk_buff *skb);
  130. };
  131. static inline u32 *netcp_push_psdata(struct netcp_packet *p_info,
  132. unsigned int bytes)
  133. {
  134. u32 *buf;
  135. unsigned int words;
  136. if ((bytes & 0x03) != 0)
  137. return NULL;
  138. words = bytes >> 2;
  139. if ((p_info->psdata_len + words) > NETCP_PSDATA_LEN)
  140. return NULL;
  141. p_info->psdata_len += words;
  142. buf = &p_info->psdata[NETCP_PSDATA_LEN - p_info->psdata_len];
  143. return buf;
  144. }
  145. static inline int netcp_align_psdata(struct netcp_packet *p_info,
  146. unsigned int byte_align)
  147. {
  148. int padding;
  149. switch (byte_align) {
  150. case 0:
  151. padding = -EINVAL;
  152. break;
  153. case 1:
  154. case 2:
  155. case 4:
  156. padding = 0;
  157. break;
  158. case 8:
  159. padding = (p_info->psdata_len << 2) % 8;
  160. break;
  161. case 16:
  162. padding = (p_info->psdata_len << 2) % 16;
  163. break;
  164. default:
  165. padding = (p_info->psdata_len << 2) % byte_align;
  166. break;
  167. }
  168. return padding;
  169. }
  170. struct netcp_module {
  171. const char *name;
  172. struct module *owner;
  173. bool primary;
  174. /* probe/remove: called once per NETCP instance */
  175. int (*probe)(struct netcp_device *netcp_device,
  176. struct device *device, struct device_node *node,
  177. void **inst_priv);
  178. int (*remove)(struct netcp_device *netcp_device, void *inst_priv);
  179. /* attach/release: called once per network interface */
  180. int (*attach)(void *inst_priv, struct net_device *ndev,
  181. struct device_node *node, void **intf_priv);
  182. int (*release)(void *intf_priv);
  183. int (*open)(void *intf_priv, struct net_device *ndev);
  184. int (*close)(void *intf_priv, struct net_device *ndev);
  185. int (*add_addr)(void *intf_priv, struct netcp_addr *naddr);
  186. int (*del_addr)(void *intf_priv, struct netcp_addr *naddr);
  187. int (*add_vid)(void *intf_priv, int vid);
  188. int (*del_vid)(void *intf_priv, int vid);
  189. int (*ioctl)(void *intf_priv, struct ifreq *req, int cmd);
  190. int (*set_rx_mode)(void *intf_priv, bool promisc);
  191. /* used internally */
  192. struct list_head module_list;
  193. struct list_head interface_list;
  194. };
  195. int netcp_register_module(struct netcp_module *module);
  196. void netcp_unregister_module(struct netcp_module *module);
  197. void *netcp_module_get_intf_data(struct netcp_module *module,
  198. struct netcp_intf *intf);
  199. int netcp_txpipe_init(struct netcp_tx_pipe *tx_pipe,
  200. struct netcp_device *netcp_device,
  201. const char *dma_chan_name, unsigned int dma_queue_id);
  202. int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe);
  203. int netcp_txpipe_close(struct netcp_tx_pipe *tx_pipe);
  204. typedef int netcp_hook_rtn(int order, void *data, struct netcp_packet *packet);
  205. int netcp_register_txhook(struct netcp_intf *netcp_priv, int order,
  206. netcp_hook_rtn *hook_rtn, void *hook_data);
  207. int netcp_unregister_txhook(struct netcp_intf *netcp_priv, int order,
  208. netcp_hook_rtn *hook_rtn, void *hook_data);
  209. int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order,
  210. netcp_hook_rtn *hook_rtn, void *hook_data);
  211. int netcp_unregister_rxhook(struct netcp_intf *netcp_priv, int order,
  212. netcp_hook_rtn *hook_rtn, void *hook_data);
  213. void *netcp_device_find_module(struct netcp_device *netcp_device,
  214. const char *name);
  215. /* SGMII functions */
  216. int netcp_sgmii_reset(void __iomem *sgmii_ofs, int port);
  217. bool netcp_sgmii_rtreset(void __iomem *sgmii_ofs, int port, bool set);
  218. int netcp_sgmii_get_port_link(void __iomem *sgmii_ofs, int port);
  219. int netcp_sgmii_config(void __iomem *sgmii_ofs, int port, u32 interface);
  220. /* XGBE SERDES init functions */
  221. int netcp_xgbe_serdes_init(void __iomem *serdes_regs, void __iomem *xgbe_regs);
  222. #endif /* __NETCP_H__ */