netcp.h 6.3 KB

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