netcp.h 6.4 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. u32 rx_buffer_sizes[KNAV_DMA_FDQ_PER_CHAN];
  79. struct napi_struct rx_napi;
  80. struct napi_struct tx_napi;
  81. void *rx_channel;
  82. const char *dma_chan_name;
  83. u32 rx_pool_size;
  84. u32 rx_pool_region_id;
  85. u32 tx_pool_size;
  86. u32 tx_pool_region_id;
  87. struct list_head module_head;
  88. struct list_head interface_list;
  89. struct list_head addr_list;
  90. bool netdev_registered;
  91. bool primary_module_attached;
  92. /* Lock used for protecting Rx/Tx hook list management */
  93. spinlock_t lock;
  94. struct netcp_device *netcp_device;
  95. struct device_node *node_interface;
  96. /* DMA configuration data */
  97. u32 msg_enable;
  98. u32 rx_queue_depths[KNAV_DMA_FDQ_PER_CHAN];
  99. };
  100. #define NETCP_PSDATA_LEN KNAV_DMA_NUM_PS_WORDS
  101. struct netcp_packet {
  102. struct sk_buff *skb;
  103. u32 *epib;
  104. u32 *psdata;
  105. unsigned int psdata_len;
  106. struct netcp_intf *netcp;
  107. struct netcp_tx_pipe *tx_pipe;
  108. bool rxtstamp_complete;
  109. void *ts_context;
  110. int (*txtstamp_complete)(void *ctx, struct netcp_packet *pkt);
  111. };
  112. static inline u32 *netcp_push_psdata(struct netcp_packet *p_info,
  113. unsigned int bytes)
  114. {
  115. u32 *buf;
  116. unsigned int words;
  117. if ((bytes & 0x03) != 0)
  118. return NULL;
  119. words = bytes >> 2;
  120. if ((p_info->psdata_len + words) > NETCP_PSDATA_LEN)
  121. return NULL;
  122. p_info->psdata_len += words;
  123. buf = &p_info->psdata[NETCP_PSDATA_LEN - p_info->psdata_len];
  124. return buf;
  125. }
  126. static inline int netcp_align_psdata(struct netcp_packet *p_info,
  127. unsigned int byte_align)
  128. {
  129. int padding;
  130. switch (byte_align) {
  131. case 0:
  132. padding = -EINVAL;
  133. break;
  134. case 1:
  135. case 2:
  136. case 4:
  137. padding = 0;
  138. break;
  139. case 8:
  140. padding = (p_info->psdata_len << 2) % 8;
  141. break;
  142. case 16:
  143. padding = (p_info->psdata_len << 2) % 16;
  144. break;
  145. default:
  146. padding = (p_info->psdata_len << 2) % byte_align;
  147. break;
  148. }
  149. return padding;
  150. }
  151. struct netcp_module {
  152. const char *name;
  153. struct module *owner;
  154. bool primary;
  155. /* probe/remove: called once per NETCP instance */
  156. int (*probe)(struct netcp_device *netcp_device,
  157. struct device *device, struct device_node *node,
  158. void **inst_priv);
  159. int (*remove)(struct netcp_device *netcp_device, void *inst_priv);
  160. /* attach/release: called once per network interface */
  161. int (*attach)(void *inst_priv, struct net_device *ndev,
  162. struct device_node *node, void **intf_priv);
  163. int (*release)(void *intf_priv);
  164. int (*open)(void *intf_priv, struct net_device *ndev);
  165. int (*close)(void *intf_priv, struct net_device *ndev);
  166. int (*add_addr)(void *intf_priv, struct netcp_addr *naddr);
  167. int (*del_addr)(void *intf_priv, struct netcp_addr *naddr);
  168. int (*add_vid)(void *intf_priv, int vid);
  169. int (*del_vid)(void *intf_priv, int vid);
  170. int (*ioctl)(void *intf_priv, struct ifreq *req, int cmd);
  171. /* used internally */
  172. struct list_head module_list;
  173. struct list_head interface_list;
  174. };
  175. int netcp_register_module(struct netcp_module *module);
  176. void netcp_unregister_module(struct netcp_module *module);
  177. void *netcp_module_get_intf_data(struct netcp_module *module,
  178. struct netcp_intf *intf);
  179. int netcp_txpipe_init(struct netcp_tx_pipe *tx_pipe,
  180. struct netcp_device *netcp_device,
  181. const char *dma_chan_name, unsigned int dma_queue_id);
  182. int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe);
  183. int netcp_txpipe_close(struct netcp_tx_pipe *tx_pipe);
  184. typedef int netcp_hook_rtn(int order, void *data, struct netcp_packet *packet);
  185. int netcp_register_txhook(struct netcp_intf *netcp_priv, int order,
  186. netcp_hook_rtn *hook_rtn, void *hook_data);
  187. int netcp_unregister_txhook(struct netcp_intf *netcp_priv, int order,
  188. netcp_hook_rtn *hook_rtn, void *hook_data);
  189. int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order,
  190. netcp_hook_rtn *hook_rtn, void *hook_data);
  191. int netcp_unregister_rxhook(struct netcp_intf *netcp_priv, int order,
  192. netcp_hook_rtn *hook_rtn, void *hook_data);
  193. void *netcp_device_find_module(struct netcp_device *netcp_device,
  194. const char *name);
  195. /* SGMII functions */
  196. int netcp_sgmii_reset(void __iomem *sgmii_ofs, int port);
  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__ */