netcp.h 6.5 KB

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