xgene_enet_main.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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/clk.h>
  24. #include <linux/of_platform.h>
  25. #include <linux/of_net.h>
  26. #include <linux/of_mdio.h>
  27. #include <linux/module.h>
  28. #include <net/ip.h>
  29. #include <linux/prefetch.h>
  30. #include <linux/if_vlan.h>
  31. #include <linux/phy.h>
  32. #include "xgene_enet_hw.h"
  33. #define XGENE_DRV_VERSION "v1.0"
  34. #define XGENE_ENET_MAX_MTU 1536
  35. #define SKB_BUFFER_SIZE (XGENE_ENET_MAX_MTU - NET_IP_ALIGN)
  36. #define NUM_PKT_BUF 64
  37. #define NUM_BUFPOOL 32
  38. #define START_ETH_BUFNUM 2
  39. #define START_BP_BUFNUM 0x22
  40. #define START_RING_NUM 8
  41. #define PHY_POLL_LINK_ON (10 * HZ)
  42. #define PHY_POLL_LINK_OFF (PHY_POLL_LINK_ON / 5)
  43. /* software context of a descriptor ring */
  44. struct xgene_enet_desc_ring {
  45. struct net_device *ndev;
  46. u16 id;
  47. u16 num;
  48. u16 head;
  49. u16 tail;
  50. u16 slots;
  51. u16 irq;
  52. u32 size;
  53. u32 state[NUM_RING_CONFIG];
  54. void __iomem *cmd_base;
  55. void __iomem *cmd;
  56. dma_addr_t dma;
  57. u16 dst_ring_num;
  58. u8 nbufpool;
  59. struct sk_buff *(*rx_skb);
  60. struct sk_buff *(*cp_skb);
  61. enum xgene_enet_ring_cfgsize cfgsize;
  62. struct xgene_enet_desc_ring *cp_ring;
  63. struct xgene_enet_desc_ring *buf_pool;
  64. struct napi_struct napi;
  65. union {
  66. void *desc_addr;
  67. struct xgene_enet_raw_desc *raw_desc;
  68. struct xgene_enet_raw_desc16 *raw_desc16;
  69. };
  70. };
  71. struct xgene_mac_ops {
  72. void (*init)(struct xgene_enet_pdata *pdata);
  73. void (*reset)(struct xgene_enet_pdata *pdata);
  74. void (*tx_enable)(struct xgene_enet_pdata *pdata);
  75. void (*rx_enable)(struct xgene_enet_pdata *pdata);
  76. void (*tx_disable)(struct xgene_enet_pdata *pdata);
  77. void (*rx_disable)(struct xgene_enet_pdata *pdata);
  78. void (*set_mac_addr)(struct xgene_enet_pdata *pdata);
  79. void (*link_state)(struct work_struct *work);
  80. };
  81. struct xgene_port_ops {
  82. int (*reset)(struct xgene_enet_pdata *pdata);
  83. void (*cle_bypass)(struct xgene_enet_pdata *pdata,
  84. u32 dst_ring_num, u16 bufpool_id);
  85. void (*shutdown)(struct xgene_enet_pdata *pdata);
  86. };
  87. /* ethernet private data */
  88. struct xgene_enet_pdata {
  89. struct net_device *ndev;
  90. struct mii_bus *mdio_bus;
  91. struct phy_device *phy_dev;
  92. int phy_speed;
  93. struct clk *clk;
  94. struct platform_device *pdev;
  95. struct xgene_enet_desc_ring *tx_ring;
  96. struct xgene_enet_desc_ring *rx_ring;
  97. char *dev_name;
  98. u32 rx_buff_cnt;
  99. u32 tx_qcnt_hi;
  100. u32 cp_qcnt_hi;
  101. u32 cp_qcnt_low;
  102. u32 rx_irq;
  103. void __iomem *eth_csr_addr;
  104. void __iomem *eth_ring_if_addr;
  105. void __iomem *eth_diag_csr_addr;
  106. void __iomem *mcx_mac_addr;
  107. void __iomem *mcx_mac_csr_addr;
  108. void __iomem *base_addr;
  109. void __iomem *ring_csr_addr;
  110. void __iomem *ring_cmd_addr;
  111. int phy_mode;
  112. enum xgene_enet_rm rm;
  113. struct rtnl_link_stats64 stats;
  114. struct xgene_mac_ops *mac_ops;
  115. struct xgene_port_ops *port_ops;
  116. struct delayed_work link_work;
  117. };
  118. struct xgene_indirect_ctl {
  119. void __iomem *addr;
  120. void __iomem *ctl;
  121. void __iomem *cmd;
  122. void __iomem *cmd_done;
  123. };
  124. /* Set the specified value into a bit-field defined by its starting position
  125. * and length within a single u64.
  126. */
  127. static inline u64 xgene_enet_set_field_value(int pos, int len, u64 val)
  128. {
  129. return (val & ((1ULL << len) - 1)) << pos;
  130. }
  131. #define SET_VAL(field, val) \
  132. xgene_enet_set_field_value(field ## _POS, field ## _LEN, val)
  133. #define SET_BIT(field) \
  134. xgene_enet_set_field_value(field ## _POS, 1, 1)
  135. /* Get the value from a bit-field defined by its starting position
  136. * and length within the specified u64.
  137. */
  138. static inline u64 xgene_enet_get_field_value(int pos, int len, u64 src)
  139. {
  140. return (src >> pos) & ((1ULL << len) - 1);
  141. }
  142. #define GET_VAL(field, src) \
  143. xgene_enet_get_field_value(field ## _POS, field ## _LEN, src)
  144. static inline struct device *ndev_to_dev(struct net_device *ndev)
  145. {
  146. return ndev->dev.parent;
  147. }
  148. void xgene_enet_set_ethtool_ops(struct net_device *netdev);
  149. #endif /* __XGENE_ENET_MAIN_H__ */