netcp.h 6.8 KB

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