xgene_enet_main.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /* Applied Micro X-Gene SoC Ethernet Driver
  2. *
  3. * Copyright (c) 2014, Applied Micro Circuits Corporation
  4. * Authors: Iyappan Subramanian <isubramanian@apm.com>
  5. * Ravi Patel <rapatel@apm.com>
  6. * Keyur Chudgar <kchudgar@apm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef __XGENE_ENET_MAIN_H__
  22. #define __XGENE_ENET_MAIN_H__
  23. #include <linux/acpi.h>
  24. #include <linux/clk.h>
  25. #include <linux/efi.h>
  26. #include <linux/irq.h>
  27. #include <linux/io.h>
  28. #include <linux/of_platform.h>
  29. #include <linux/of_net.h>
  30. #include <linux/of_mdio.h>
  31. #include <linux/module.h>
  32. #include <net/ip.h>
  33. #include <linux/prefetch.h>
  34. #include <linux/if_vlan.h>
  35. #include <linux/phy.h>
  36. #include "xgene_enet_hw.h"
  37. #include "xgene_enet_cle.h"
  38. #include "xgene_enet_ring2.h"
  39. #include "../../../phy/mdio-xgene.h"
  40. #define XGENE_DRV_VERSION "v1.0"
  41. #define ETHER_MIN_PACKET 64
  42. #define ETHER_STD_PACKET 1518
  43. #define XGENE_ENET_STD_MTU 1536
  44. #define XGENE_ENET_MAX_MTU 9600
  45. #define SKB_BUFFER_SIZE (XGENE_ENET_STD_MTU - NET_IP_ALIGN)
  46. #define BUFLEN_16K (16 * 1024)
  47. #define NUM_PKT_BUF 1024
  48. #define NUM_BUFPOOL 32
  49. #define NUM_NXTBUFPOOL 8
  50. #define MAX_EXP_BUFFS 256
  51. #define NUM_MSS_REG 4
  52. #define XGENE_MIN_ENET_FRAME_SIZE 60
  53. #define XGENE_MAX_ENET_IRQ 16
  54. #define XGENE_NUM_RX_RING 8
  55. #define XGENE_NUM_TX_RING 8
  56. #define XGENE_NUM_TXC_RING 8
  57. #define START_CPU_BUFNUM_0 0
  58. #define START_ETH_BUFNUM_0 2
  59. #define START_BP_BUFNUM_0 0x22
  60. #define START_RING_NUM_0 8
  61. #define START_CPU_BUFNUM_1 12
  62. #define START_ETH_BUFNUM_1 10
  63. #define START_BP_BUFNUM_1 0x2A
  64. #define START_RING_NUM_1 264
  65. #define XG_START_CPU_BUFNUM_1 12
  66. #define XG_START_ETH_BUFNUM_1 2
  67. #define XG_START_BP_BUFNUM_1 0x22
  68. #define XG_START_RING_NUM_1 264
  69. #define X2_START_CPU_BUFNUM_0 0
  70. #define X2_START_ETH_BUFNUM_0 0
  71. #define X2_START_BP_BUFNUM_0 0x20
  72. #define X2_START_RING_NUM_0 0
  73. #define X2_START_CPU_BUFNUM_1 0xc
  74. #define X2_START_ETH_BUFNUM_1 0
  75. #define X2_START_BP_BUFNUM_1 0x20
  76. #define X2_START_RING_NUM_1 256
  77. #define IRQ_ID_SIZE 16
  78. #define PHY_POLL_LINK_ON (10 * HZ)
  79. #define PHY_POLL_LINK_OFF (PHY_POLL_LINK_ON / 5)
  80. enum xgene_enet_id {
  81. XGENE_ENET1 = 1,
  82. XGENE_ENET2
  83. };
  84. enum xgene_enet_buf_len {
  85. SIZE_2K = 2048,
  86. SIZE_4K = 4096,
  87. SIZE_16K = 16384
  88. };
  89. /* software context of a descriptor ring */
  90. struct xgene_enet_desc_ring {
  91. struct net_device *ndev;
  92. u16 id;
  93. u16 num;
  94. u16 head;
  95. u16 tail;
  96. u16 exp_buf_tail;
  97. u16 slots;
  98. u16 irq;
  99. char irq_name[IRQ_ID_SIZE];
  100. u32 size;
  101. u32 state[X2_NUM_RING_CONFIG];
  102. void __iomem *cmd_base;
  103. void __iomem *cmd;
  104. dma_addr_t dma;
  105. dma_addr_t irq_mbox_dma;
  106. void *irq_mbox_addr;
  107. u16 dst_ring_num;
  108. u16 nbufpool;
  109. int npagepool;
  110. u8 index;
  111. u32 flags;
  112. struct sk_buff *(*rx_skb);
  113. struct sk_buff *(*cp_skb);
  114. dma_addr_t *frag_dma_addr;
  115. struct page *(*frag_page);
  116. enum xgene_enet_ring_cfgsize cfgsize;
  117. struct xgene_enet_desc_ring *cp_ring;
  118. struct xgene_enet_desc_ring *buf_pool;
  119. struct xgene_enet_desc_ring *page_pool;
  120. struct napi_struct napi;
  121. union {
  122. void *desc_addr;
  123. struct xgene_enet_raw_desc *raw_desc;
  124. struct xgene_enet_raw_desc16 *raw_desc16;
  125. };
  126. __le64 *exp_bufs;
  127. u64 tx_packets;
  128. u64 tx_bytes;
  129. u64 tx_dropped;
  130. u64 tx_errors;
  131. u64 rx_packets;
  132. u64 rx_bytes;
  133. u64 rx_dropped;
  134. u64 rx_errors;
  135. u64 rx_length_errors;
  136. u64 rx_crc_errors;
  137. u64 rx_frame_errors;
  138. u64 rx_fifo_errors;
  139. };
  140. struct xgene_mac_ops {
  141. void (*init)(struct xgene_enet_pdata *pdata);
  142. void (*reset)(struct xgene_enet_pdata *pdata);
  143. void (*tx_enable)(struct xgene_enet_pdata *pdata);
  144. void (*rx_enable)(struct xgene_enet_pdata *pdata);
  145. void (*tx_disable)(struct xgene_enet_pdata *pdata);
  146. void (*rx_disable)(struct xgene_enet_pdata *pdata);
  147. void (*get_drop_cnt)(struct xgene_enet_pdata *pdata, u32 *rx, u32 *tx);
  148. void (*set_speed)(struct xgene_enet_pdata *pdata);
  149. void (*set_mac_addr)(struct xgene_enet_pdata *pdata);
  150. void (*set_framesize)(struct xgene_enet_pdata *pdata, int framesize);
  151. void (*set_mss)(struct xgene_enet_pdata *pdata, u16 mss, u8 index);
  152. void (*link_state)(struct work_struct *work);
  153. void (*enable_tx_pause)(struct xgene_enet_pdata *pdata, bool enable);
  154. void (*flowctl_rx)(struct xgene_enet_pdata *pdata, bool enable);
  155. void (*flowctl_tx)(struct xgene_enet_pdata *pdata, bool enable);
  156. };
  157. struct xgene_port_ops {
  158. int (*reset)(struct xgene_enet_pdata *pdata);
  159. void (*clear)(struct xgene_enet_pdata *pdata,
  160. struct xgene_enet_desc_ring *ring);
  161. void (*cle_bypass)(struct xgene_enet_pdata *pdata,
  162. u32 dst_ring_num, u16 bufpool_id, u16 nxtbufpool_id);
  163. void (*shutdown)(struct xgene_enet_pdata *pdata);
  164. };
  165. struct xgene_ring_ops {
  166. u8 num_ring_config;
  167. u8 num_ring_id_shift;
  168. struct xgene_enet_desc_ring * (*setup)(struct xgene_enet_desc_ring *);
  169. void (*clear)(struct xgene_enet_desc_ring *);
  170. void (*wr_cmd)(struct xgene_enet_desc_ring *, int);
  171. u32 (*len)(struct xgene_enet_desc_ring *);
  172. void (*coalesce)(struct xgene_enet_desc_ring *);
  173. };
  174. struct xgene_cle_ops {
  175. int (*cle_init)(struct xgene_enet_pdata *pdata);
  176. };
  177. /* ethernet private data */
  178. struct xgene_enet_pdata {
  179. struct net_device *ndev;
  180. struct mii_bus *mdio_bus;
  181. int phy_speed;
  182. struct clk *clk;
  183. struct platform_device *pdev;
  184. enum xgene_enet_id enet_id;
  185. struct xgene_enet_desc_ring *tx_ring[XGENE_NUM_TX_RING];
  186. struct xgene_enet_desc_ring *rx_ring[XGENE_NUM_RX_RING];
  187. u16 tx_level[XGENE_NUM_TX_RING];
  188. u16 txc_level[XGENE_NUM_TX_RING];
  189. char *dev_name;
  190. u32 rx_buff_cnt;
  191. u32 tx_qcnt_hi;
  192. u32 irqs[XGENE_MAX_ENET_IRQ];
  193. u8 rxq_cnt;
  194. u8 txq_cnt;
  195. u8 cq_cnt;
  196. void __iomem *eth_csr_addr;
  197. void __iomem *eth_ring_if_addr;
  198. void __iomem *eth_diag_csr_addr;
  199. void __iomem *mcx_mac_addr;
  200. void __iomem *mcx_mac_csr_addr;
  201. void __iomem *mcx_stats_addr;
  202. void __iomem *base_addr;
  203. void __iomem *pcs_addr;
  204. void __iomem *ring_csr_addr;
  205. void __iomem *ring_cmd_addr;
  206. int phy_mode;
  207. enum xgene_enet_rm rm;
  208. struct xgene_enet_cle cle;
  209. u64 *extd_stats;
  210. u64 false_rflr;
  211. u64 vlan_rjbr;
  212. spinlock_t stats_lock; /* statistics lock */
  213. const struct xgene_mac_ops *mac_ops;
  214. spinlock_t mac_lock; /* mac lock */
  215. const struct xgene_port_ops *port_ops;
  216. struct xgene_ring_ops *ring_ops;
  217. const struct xgene_cle_ops *cle_ops;
  218. struct delayed_work link_work;
  219. u32 port_id;
  220. u8 cpu_bufnum;
  221. u8 eth_bufnum;
  222. u8 bp_bufnum;
  223. u16 ring_num;
  224. u32 mss[NUM_MSS_REG];
  225. u32 mss_refcnt[NUM_MSS_REG];
  226. spinlock_t mss_lock; /* mss lock */
  227. u8 tx_delay;
  228. u8 rx_delay;
  229. bool mdio_driver;
  230. struct gpio_desc *sfp_rdy;
  231. bool sfp_gpio_en;
  232. u32 pause_autoneg;
  233. bool tx_pause;
  234. bool rx_pause;
  235. };
  236. struct xgene_indirect_ctl {
  237. void __iomem *addr;
  238. void __iomem *ctl;
  239. void __iomem *cmd;
  240. void __iomem *cmd_done;
  241. };
  242. static inline struct device *ndev_to_dev(struct net_device *ndev)
  243. {
  244. return ndev->dev.parent;
  245. }
  246. static inline u16 xgene_enet_dst_ring_num(struct xgene_enet_desc_ring *ring)
  247. {
  248. struct xgene_enet_pdata *pdata = netdev_priv(ring->ndev);
  249. return ((u16)pdata->rm << 10) | ring->num;
  250. }
  251. void xgene_enet_set_ethtool_ops(struct net_device *netdev);
  252. int xgene_extd_stats_init(struct xgene_enet_pdata *pdata);
  253. #endif /* __XGENE_ENET_MAIN_H__ */