xgene_enet_main.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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/io.h>
  27. #include <linux/of_platform.h>
  28. #include <linux/of_net.h>
  29. #include <linux/of_mdio.h>
  30. #include <linux/module.h>
  31. #include <net/ip.h>
  32. #include <linux/prefetch.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/phy.h>
  35. #include "xgene_enet_hw.h"
  36. #include "xgene_enet_ring2.h"
  37. #define XGENE_DRV_VERSION "v1.0"
  38. #define XGENE_ENET_MAX_MTU 1536
  39. #define SKB_BUFFER_SIZE (XGENE_ENET_MAX_MTU - NET_IP_ALIGN)
  40. #define NUM_PKT_BUF 64
  41. #define NUM_BUFPOOL 32
  42. #define START_CPU_BUFNUM_0 0
  43. #define START_ETH_BUFNUM_0 2
  44. #define START_BP_BUFNUM_0 0x22
  45. #define START_RING_NUM_0 8
  46. #define START_CPU_BUFNUM_1 12
  47. #define START_ETH_BUFNUM_1 10
  48. #define START_BP_BUFNUM_1 0x2A
  49. #define START_RING_NUM_1 264
  50. #define X2_START_CPU_BUFNUM_0 0
  51. #define X2_START_ETH_BUFNUM_0 0
  52. #define X2_START_BP_BUFNUM_0 0x20
  53. #define X2_START_RING_NUM_0 0
  54. #define X2_START_CPU_BUFNUM_1 0xc
  55. #define X2_START_ETH_BUFNUM_1 0
  56. #define X2_START_BP_BUFNUM_1 0x20
  57. #define X2_START_RING_NUM_1 256
  58. #define IRQ_ID_SIZE 16
  59. #define XGENE_MAX_TXC_RINGS 1
  60. #define PHY_POLL_LINK_ON (10 * HZ)
  61. #define PHY_POLL_LINK_OFF (PHY_POLL_LINK_ON / 5)
  62. enum xgene_enet_id {
  63. XGENE_ENET1 = 1,
  64. XGENE_ENET2
  65. };
  66. /* software context of a descriptor ring */
  67. struct xgene_enet_desc_ring {
  68. struct net_device *ndev;
  69. u16 id;
  70. u16 num;
  71. u16 head;
  72. u16 tail;
  73. u16 slots;
  74. u16 irq;
  75. char irq_name[IRQ_ID_SIZE];
  76. u32 size;
  77. u32 state[X2_NUM_RING_CONFIG];
  78. void __iomem *cmd_base;
  79. void __iomem *cmd;
  80. dma_addr_t dma;
  81. dma_addr_t irq_mbox_dma;
  82. void *irq_mbox_addr;
  83. u16 dst_ring_num;
  84. u8 nbufpool;
  85. struct sk_buff *(*rx_skb);
  86. struct sk_buff *(*cp_skb);
  87. enum xgene_enet_ring_cfgsize cfgsize;
  88. struct xgene_enet_desc_ring *cp_ring;
  89. struct xgene_enet_desc_ring *buf_pool;
  90. struct napi_struct napi;
  91. union {
  92. void *desc_addr;
  93. struct xgene_enet_raw_desc *raw_desc;
  94. struct xgene_enet_raw_desc16 *raw_desc16;
  95. };
  96. };
  97. struct xgene_mac_ops {
  98. void (*init)(struct xgene_enet_pdata *pdata);
  99. void (*reset)(struct xgene_enet_pdata *pdata);
  100. void (*tx_enable)(struct xgene_enet_pdata *pdata);
  101. void (*rx_enable)(struct xgene_enet_pdata *pdata);
  102. void (*tx_disable)(struct xgene_enet_pdata *pdata);
  103. void (*rx_disable)(struct xgene_enet_pdata *pdata);
  104. void (*set_mac_addr)(struct xgene_enet_pdata *pdata);
  105. void (*link_state)(struct work_struct *work);
  106. };
  107. struct xgene_port_ops {
  108. int (*reset)(struct xgene_enet_pdata *pdata);
  109. void (*cle_bypass)(struct xgene_enet_pdata *pdata,
  110. u32 dst_ring_num, u16 bufpool_id);
  111. void (*shutdown)(struct xgene_enet_pdata *pdata);
  112. };
  113. struct xgene_ring_ops {
  114. u8 num_ring_config;
  115. u8 num_ring_id_shift;
  116. struct xgene_enet_desc_ring * (*setup)(struct xgene_enet_desc_ring *);
  117. void (*clear)(struct xgene_enet_desc_ring *);
  118. void (*wr_cmd)(struct xgene_enet_desc_ring *, int);
  119. u32 (*len)(struct xgene_enet_desc_ring *);
  120. };
  121. /* ethernet private data */
  122. struct xgene_enet_pdata {
  123. struct net_device *ndev;
  124. struct mii_bus *mdio_bus;
  125. struct phy_device *phy_dev;
  126. int phy_speed;
  127. struct clk *clk;
  128. struct platform_device *pdev;
  129. enum xgene_enet_id enet_id;
  130. struct xgene_enet_desc_ring *tx_ring;
  131. struct xgene_enet_desc_ring *rx_ring;
  132. char *dev_name;
  133. u32 rx_buff_cnt;
  134. u32 tx_qcnt_hi;
  135. u32 cp_qcnt_hi;
  136. u32 cp_qcnt_low;
  137. u32 rx_irq;
  138. u32 txc_irq;
  139. u8 cq_cnt;
  140. void __iomem *eth_csr_addr;
  141. void __iomem *eth_ring_if_addr;
  142. void __iomem *eth_diag_csr_addr;
  143. void __iomem *mcx_mac_addr;
  144. void __iomem *mcx_mac_csr_addr;
  145. void __iomem *base_addr;
  146. void __iomem *ring_csr_addr;
  147. void __iomem *ring_cmd_addr;
  148. int phy_mode;
  149. enum xgene_enet_rm rm;
  150. struct rtnl_link_stats64 stats;
  151. struct xgene_mac_ops *mac_ops;
  152. struct xgene_port_ops *port_ops;
  153. struct xgene_ring_ops *ring_ops;
  154. struct delayed_work link_work;
  155. u32 port_id;
  156. u8 cpu_bufnum;
  157. u8 eth_bufnum;
  158. u8 bp_bufnum;
  159. u16 ring_num;
  160. };
  161. struct xgene_indirect_ctl {
  162. void __iomem *addr;
  163. void __iomem *ctl;
  164. void __iomem *cmd;
  165. void __iomem *cmd_done;
  166. };
  167. /* Set the specified value into a bit-field defined by its starting position
  168. * and length within a single u64.
  169. */
  170. static inline u64 xgene_enet_set_field_value(int pos, int len, u64 val)
  171. {
  172. return (val & ((1ULL << len) - 1)) << pos;
  173. }
  174. #define SET_VAL(field, val) \
  175. xgene_enet_set_field_value(field ## _POS, field ## _LEN, val)
  176. #define SET_BIT(field) \
  177. xgene_enet_set_field_value(field ## _POS, 1, 1)
  178. /* Get the value from a bit-field defined by its starting position
  179. * and length within the specified u64.
  180. */
  181. static inline u64 xgene_enet_get_field_value(int pos, int len, u64 src)
  182. {
  183. return (src >> pos) & ((1ULL << len) - 1);
  184. }
  185. #define GET_VAL(field, src) \
  186. xgene_enet_get_field_value(field ## _POS, field ## _LEN, src)
  187. static inline struct device *ndev_to_dev(struct net_device *ndev)
  188. {
  189. return ndev->dev.parent;
  190. }
  191. void xgene_enet_set_ethtool_ops(struct net_device *netdev);
  192. #endif /* __XGENE_ENET_MAIN_H__ */