netcp.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 XGMII_LINK_MAC_PHY 10
  34. #define XGMII_LINK_MAC_MAC_FORCED 11
  35. struct netcp_device;
  36. struct netcp_tx_pipe {
  37. struct netcp_device *netcp_device;
  38. void *dma_queue;
  39. unsigned int dma_queue_id;
  40. /* To port for packet forwarded to switch. Used only by ethss */
  41. u8 switch_to_port;
  42. #define SWITCH_TO_PORT_IN_TAGINFO BIT(0)
  43. u8 flags;
  44. void *dma_channel;
  45. const char *dma_chan_name;
  46. };
  47. #define ADDR_NEW BIT(0)
  48. #define ADDR_VALID BIT(1)
  49. enum netcp_addr_type {
  50. ADDR_ANY,
  51. ADDR_DEV,
  52. ADDR_UCAST,
  53. ADDR_MCAST,
  54. ADDR_BCAST
  55. };
  56. struct netcp_addr {
  57. struct netcp_intf *netcp;
  58. unsigned char addr[ETH_ALEN];
  59. enum netcp_addr_type type;
  60. unsigned int flags;
  61. struct list_head node;
  62. };
  63. struct netcp_stats {
  64. struct u64_stats_sync syncp_rx ____cacheline_aligned_in_smp;
  65. u64 rx_packets;
  66. u64 rx_bytes;
  67. u32 rx_errors;
  68. u32 rx_dropped;
  69. struct u64_stats_sync syncp_tx ____cacheline_aligned_in_smp;
  70. u64 tx_packets;
  71. u64 tx_bytes;
  72. u32 tx_errors;
  73. u32 tx_dropped;
  74. };
  75. struct netcp_intf {
  76. struct device *dev;
  77. struct device *ndev_dev;
  78. struct net_device *ndev;
  79. bool big_endian;
  80. unsigned int tx_compl_qid;
  81. void *tx_pool;
  82. struct list_head txhook_list_head;
  83. unsigned int tx_pause_threshold;
  84. void *tx_compl_q;
  85. unsigned int tx_resume_threshold;
  86. void *rx_queue;
  87. void *rx_pool;
  88. struct list_head rxhook_list_head;
  89. unsigned int rx_queue_id;
  90. void *rx_fdq[KNAV_DMA_FDQ_PER_CHAN];
  91. struct napi_struct rx_napi;
  92. struct napi_struct tx_napi;
  93. #define ETH_SW_CAN_REMOVE_ETH_FCS BIT(0)
  94. u32 hw_cap;
  95. /* 64-bit netcp stats */
  96. struct netcp_stats stats;
  97. void *rx_channel;
  98. const char *dma_chan_name;
  99. u32 rx_pool_size;
  100. u32 rx_pool_region_id;
  101. u32 tx_pool_size;
  102. u32 tx_pool_region_id;
  103. struct list_head module_head;
  104. struct list_head interface_list;
  105. struct list_head addr_list;
  106. bool netdev_registered;
  107. bool primary_module_attached;
  108. /* Lock used for protecting Rx/Tx hook list management */
  109. spinlock_t lock;
  110. struct netcp_device *netcp_device;
  111. struct device_node *node_interface;
  112. /* DMA configuration data */
  113. u32 msg_enable;
  114. u32 rx_queue_depths[KNAV_DMA_FDQ_PER_CHAN];
  115. };
  116. #define NETCP_PSDATA_LEN KNAV_DMA_NUM_PS_WORDS
  117. struct netcp_packet {
  118. struct sk_buff *skb;
  119. __le32 *epib;
  120. u32 *psdata;
  121. u32 eflags;
  122. unsigned int psdata_len;
  123. struct netcp_intf *netcp;
  124. struct netcp_tx_pipe *tx_pipe;
  125. bool rxtstamp_complete;
  126. void *ts_context;
  127. void (*txtstamp)(void *ctx, struct sk_buff *skb);
  128. };
  129. static inline u32 *netcp_push_psdata(struct netcp_packet *p_info,
  130. unsigned int bytes)
  131. {
  132. u32 *buf;
  133. unsigned int words;
  134. if ((bytes & 0x03) != 0)
  135. return NULL;
  136. words = bytes >> 2;
  137. if ((p_info->psdata_len + words) > NETCP_PSDATA_LEN)
  138. return NULL;
  139. p_info->psdata_len += words;
  140. buf = &p_info->psdata[NETCP_PSDATA_LEN - p_info->psdata_len];
  141. return buf;
  142. }
  143. static inline int netcp_align_psdata(struct netcp_packet *p_info,
  144. unsigned int byte_align)
  145. {
  146. int padding;
  147. switch (byte_align) {
  148. case 0:
  149. padding = -EINVAL;
  150. break;
  151. case 1:
  152. case 2:
  153. case 4:
  154. padding = 0;
  155. break;
  156. case 8:
  157. padding = (p_info->psdata_len << 2) % 8;
  158. break;
  159. case 16:
  160. padding = (p_info->psdata_len << 2) % 16;
  161. break;
  162. default:
  163. padding = (p_info->psdata_len << 2) % byte_align;
  164. break;
  165. }
  166. return padding;
  167. }
  168. struct netcp_module {
  169. const char *name;
  170. struct module *owner;
  171. bool primary;
  172. /* probe/remove: called once per NETCP instance */
  173. int (*probe)(struct netcp_device *netcp_device,
  174. struct device *device, struct device_node *node,
  175. void **inst_priv);
  176. int (*remove)(struct netcp_device *netcp_device, void *inst_priv);
  177. /* attach/release: called once per network interface */
  178. int (*attach)(void *inst_priv, struct net_device *ndev,
  179. struct device_node *node, void **intf_priv);
  180. int (*release)(void *intf_priv);
  181. int (*open)(void *intf_priv, struct net_device *ndev);
  182. int (*close)(void *intf_priv, struct net_device *ndev);
  183. int (*add_addr)(void *intf_priv, struct netcp_addr *naddr);
  184. int (*del_addr)(void *intf_priv, struct netcp_addr *naddr);
  185. int (*add_vid)(void *intf_priv, int vid);
  186. int (*del_vid)(void *intf_priv, int vid);
  187. int (*ioctl)(void *intf_priv, struct ifreq *req, int cmd);
  188. /* used internally */
  189. struct list_head module_list;
  190. struct list_head interface_list;
  191. };
  192. int netcp_register_module(struct netcp_module *module);
  193. void netcp_unregister_module(struct netcp_module *module);
  194. void *netcp_module_get_intf_data(struct netcp_module *module,
  195. struct netcp_intf *intf);
  196. int netcp_txpipe_init(struct netcp_tx_pipe *tx_pipe,
  197. struct netcp_device *netcp_device,
  198. const char *dma_chan_name, unsigned int dma_queue_id);
  199. int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe);
  200. int netcp_txpipe_close(struct netcp_tx_pipe *tx_pipe);
  201. typedef int netcp_hook_rtn(int order, void *data, struct netcp_packet *packet);
  202. int netcp_register_txhook(struct netcp_intf *netcp_priv, int order,
  203. netcp_hook_rtn *hook_rtn, void *hook_data);
  204. int netcp_unregister_txhook(struct netcp_intf *netcp_priv, int order,
  205. netcp_hook_rtn *hook_rtn, void *hook_data);
  206. int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order,
  207. netcp_hook_rtn *hook_rtn, void *hook_data);
  208. int netcp_unregister_rxhook(struct netcp_intf *netcp_priv, int order,
  209. netcp_hook_rtn *hook_rtn, void *hook_data);
  210. void *netcp_device_find_module(struct netcp_device *netcp_device,
  211. const char *name);
  212. /* SGMII functions */
  213. int netcp_sgmii_reset(void __iomem *sgmii_ofs, int port);
  214. bool netcp_sgmii_rtreset(void __iomem *sgmii_ofs, int port, bool set);
  215. int netcp_sgmii_get_port_link(void __iomem *sgmii_ofs, int port);
  216. int netcp_sgmii_config(void __iomem *sgmii_ofs, int port, u32 interface);
  217. /* XGBE SERDES init functions */
  218. int netcp_xgbe_serdes_init(void __iomem *serdes_regs, void __iomem *xgbe_regs);
  219. #endif /* __NETCP_H__ */