bcm63xx_enet.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #ifndef BCM63XX_ENET_H_
  2. #define BCM63XX_ENET_H_
  3. #include <linux/types.h>
  4. #include <linux/mii.h>
  5. #include <linux/mutex.h>
  6. #include <linux/phy.h>
  7. #include <linux/platform_device.h>
  8. #include <bcm63xx_regs.h>
  9. #include <bcm63xx_irq.h>
  10. #include <bcm63xx_io.h>
  11. #include <bcm63xx_iudma.h>
  12. /* default number of descriptor */
  13. #define BCMENET_DEF_RX_DESC 64
  14. #define BCMENET_DEF_TX_DESC 32
  15. /* maximum burst len for dma (4 bytes unit) */
  16. #define BCMENET_DMA_MAXBURST 16
  17. /* tx transmit threshold (4 bytes unit), fifo is 256 bytes, the value
  18. * must be low enough so that a DMA transfer of above burst length can
  19. * not overflow the fifo */
  20. #define BCMENET_TX_FIFO_TRESH 32
  21. /*
  22. * hardware maximum rx/tx packet size including FCS, max mtu is
  23. * actually 2047, but if we set max rx size register to 2047 we won't
  24. * get overflow information if packet size is 2048 or above
  25. */
  26. #define BCMENET_MAX_MTU 2046
  27. /*
  28. * MIB Counters register definitions
  29. */
  30. #define ETH_MIB_TX_GD_OCTETS 0
  31. #define ETH_MIB_TX_GD_PKTS 1
  32. #define ETH_MIB_TX_ALL_OCTETS 2
  33. #define ETH_MIB_TX_ALL_PKTS 3
  34. #define ETH_MIB_TX_BRDCAST 4
  35. #define ETH_MIB_TX_MULT 5
  36. #define ETH_MIB_TX_64 6
  37. #define ETH_MIB_TX_65_127 7
  38. #define ETH_MIB_TX_128_255 8
  39. #define ETH_MIB_TX_256_511 9
  40. #define ETH_MIB_TX_512_1023 10
  41. #define ETH_MIB_TX_1024_MAX 11
  42. #define ETH_MIB_TX_JAB 12
  43. #define ETH_MIB_TX_OVR 13
  44. #define ETH_MIB_TX_FRAG 14
  45. #define ETH_MIB_TX_UNDERRUN 15
  46. #define ETH_MIB_TX_COL 16
  47. #define ETH_MIB_TX_1_COL 17
  48. #define ETH_MIB_TX_M_COL 18
  49. #define ETH_MIB_TX_EX_COL 19
  50. #define ETH_MIB_TX_LATE 20
  51. #define ETH_MIB_TX_DEF 21
  52. #define ETH_MIB_TX_CRS 22
  53. #define ETH_MIB_TX_PAUSE 23
  54. #define ETH_MIB_RX_GD_OCTETS 32
  55. #define ETH_MIB_RX_GD_PKTS 33
  56. #define ETH_MIB_RX_ALL_OCTETS 34
  57. #define ETH_MIB_RX_ALL_PKTS 35
  58. #define ETH_MIB_RX_BRDCAST 36
  59. #define ETH_MIB_RX_MULT 37
  60. #define ETH_MIB_RX_64 38
  61. #define ETH_MIB_RX_65_127 39
  62. #define ETH_MIB_RX_128_255 40
  63. #define ETH_MIB_RX_256_511 41
  64. #define ETH_MIB_RX_512_1023 42
  65. #define ETH_MIB_RX_1024_MAX 43
  66. #define ETH_MIB_RX_JAB 44
  67. #define ETH_MIB_RX_OVR 45
  68. #define ETH_MIB_RX_FRAG 46
  69. #define ETH_MIB_RX_DROP 47
  70. #define ETH_MIB_RX_CRC_ALIGN 48
  71. #define ETH_MIB_RX_UND 49
  72. #define ETH_MIB_RX_CRC 50
  73. #define ETH_MIB_RX_ALIGN 51
  74. #define ETH_MIB_RX_SYM 52
  75. #define ETH_MIB_RX_PAUSE 53
  76. #define ETH_MIB_RX_CNTRL 54
  77. struct bcm_enet_mib_counters {
  78. u64 tx_gd_octets;
  79. u32 tx_gd_pkts;
  80. u32 tx_all_octets;
  81. u32 tx_all_pkts;
  82. u32 tx_brdcast;
  83. u32 tx_mult;
  84. u32 tx_64;
  85. u32 tx_65_127;
  86. u32 tx_128_255;
  87. u32 tx_256_511;
  88. u32 tx_512_1023;
  89. u32 tx_1024_max;
  90. u32 tx_jab;
  91. u32 tx_ovr;
  92. u32 tx_frag;
  93. u32 tx_underrun;
  94. u32 tx_col;
  95. u32 tx_1_col;
  96. u32 tx_m_col;
  97. u32 tx_ex_col;
  98. u32 tx_late;
  99. u32 tx_def;
  100. u32 tx_crs;
  101. u32 tx_pause;
  102. u64 rx_gd_octets;
  103. u32 rx_gd_pkts;
  104. u32 rx_all_octets;
  105. u32 rx_all_pkts;
  106. u32 rx_brdcast;
  107. u32 rx_mult;
  108. u32 rx_64;
  109. u32 rx_65_127;
  110. u32 rx_128_255;
  111. u32 rx_256_511;
  112. u32 rx_512_1023;
  113. u32 rx_1024_max;
  114. u32 rx_jab;
  115. u32 rx_ovr;
  116. u32 rx_frag;
  117. u32 rx_drop;
  118. u32 rx_crc_align;
  119. u32 rx_und;
  120. u32 rx_crc;
  121. u32 rx_align;
  122. u32 rx_sym;
  123. u32 rx_pause;
  124. u32 rx_cntrl;
  125. };
  126. struct bcm_enet_priv {
  127. /* mac id (from platform device id) */
  128. int mac_id;
  129. /* base remapped address of device */
  130. void __iomem *base;
  131. /* mac irq, rx_dma irq, tx_dma irq */
  132. int irq;
  133. int irq_rx;
  134. int irq_tx;
  135. /* hw view of rx & tx dma ring */
  136. dma_addr_t rx_desc_dma;
  137. dma_addr_t tx_desc_dma;
  138. /* allocated size (in bytes) for rx & tx dma ring */
  139. unsigned int rx_desc_alloc_size;
  140. unsigned int tx_desc_alloc_size;
  141. struct napi_struct napi;
  142. /* dma channel id for rx */
  143. int rx_chan;
  144. /* number of dma desc in rx ring */
  145. int rx_ring_size;
  146. /* cpu view of rx dma ring */
  147. struct bcm_enet_desc *rx_desc_cpu;
  148. /* current number of armed descriptor given to hardware for rx */
  149. int rx_desc_count;
  150. /* next rx descriptor to fetch from hardware */
  151. int rx_curr_desc;
  152. /* next dirty rx descriptor to refill */
  153. int rx_dirty_desc;
  154. /* size of allocated rx skbs */
  155. unsigned int rx_skb_size;
  156. /* list of skb given to hw for rx */
  157. struct sk_buff **rx_skb;
  158. /* used when rx skb allocation failed, so we defer rx queue
  159. * refill */
  160. struct timer_list rx_timeout;
  161. /* lock rx_timeout against rx normal operation */
  162. spinlock_t rx_lock;
  163. /* dma channel id for tx */
  164. int tx_chan;
  165. /* number of dma desc in tx ring */
  166. int tx_ring_size;
  167. /* cpu view of rx dma ring */
  168. struct bcm_enet_desc *tx_desc_cpu;
  169. /* number of available descriptor for tx */
  170. int tx_desc_count;
  171. /* next tx descriptor avaiable */
  172. int tx_curr_desc;
  173. /* next dirty tx descriptor to reclaim */
  174. int tx_dirty_desc;
  175. /* list of skb given to hw for tx */
  176. struct sk_buff **tx_skb;
  177. /* lock used by tx reclaim and xmit */
  178. spinlock_t tx_lock;
  179. /* set if internal phy is ignored and external mii interface
  180. * is selected */
  181. int use_external_mii;
  182. /* set if a phy is connected, phy address must be known,
  183. * probing is not possible */
  184. int has_phy;
  185. int phy_id;
  186. /* set if connected phy has an associated irq */
  187. int has_phy_interrupt;
  188. int phy_interrupt;
  189. /* used when a phy is connected (phylib used) */
  190. struct mii_bus *mii_bus;
  191. struct phy_device *phydev;
  192. int old_link;
  193. int old_duplex;
  194. int old_pause;
  195. /* used when no phy is connected */
  196. int force_speed_100;
  197. int force_duplex_full;
  198. /* pause parameters */
  199. int pause_auto;
  200. int pause_rx;
  201. int pause_tx;
  202. /* stats */
  203. struct bcm_enet_mib_counters mib;
  204. /* after mib interrupt, mib registers update is done in this
  205. * work queue */
  206. struct work_struct mib_update_task;
  207. /* lock mib update between userspace request and workqueue */
  208. struct mutex mib_update_lock;
  209. /* mac clock */
  210. struct clk *mac_clk;
  211. /* phy clock if internal phy is used */
  212. struct clk *phy_clk;
  213. /* network device reference */
  214. struct net_device *net_dev;
  215. /* platform device reference */
  216. struct platform_device *pdev;
  217. /* maximum hardware transmit/receive size */
  218. unsigned int hw_mtu;
  219. };
  220. #endif /* ! BCM63XX_ENET_H_ */