bcm63xx_enet.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. #define BCMENETSW_DMA_MAXBURST 8
  18. /* tx transmit threshold (4 bytes unit), fifo is 256 bytes, the value
  19. * must be low enough so that a DMA transfer of above burst length can
  20. * not overflow the fifo */
  21. #define BCMENET_TX_FIFO_TRESH 32
  22. /*
  23. * hardware maximum rx/tx packet size including FCS, max mtu is
  24. * actually 2047, but if we set max rx size register to 2047 we won't
  25. * get overflow information if packet size is 2048 or above
  26. */
  27. #define BCMENET_MAX_MTU 2046
  28. /*
  29. * MIB Counters register definitions
  30. */
  31. #define ETH_MIB_TX_GD_OCTETS 0
  32. #define ETH_MIB_TX_GD_PKTS 1
  33. #define ETH_MIB_TX_ALL_OCTETS 2
  34. #define ETH_MIB_TX_ALL_PKTS 3
  35. #define ETH_MIB_TX_BRDCAST 4
  36. #define ETH_MIB_TX_MULT 5
  37. #define ETH_MIB_TX_64 6
  38. #define ETH_MIB_TX_65_127 7
  39. #define ETH_MIB_TX_128_255 8
  40. #define ETH_MIB_TX_256_511 9
  41. #define ETH_MIB_TX_512_1023 10
  42. #define ETH_MIB_TX_1024_MAX 11
  43. #define ETH_MIB_TX_JAB 12
  44. #define ETH_MIB_TX_OVR 13
  45. #define ETH_MIB_TX_FRAG 14
  46. #define ETH_MIB_TX_UNDERRUN 15
  47. #define ETH_MIB_TX_COL 16
  48. #define ETH_MIB_TX_1_COL 17
  49. #define ETH_MIB_TX_M_COL 18
  50. #define ETH_MIB_TX_EX_COL 19
  51. #define ETH_MIB_TX_LATE 20
  52. #define ETH_MIB_TX_DEF 21
  53. #define ETH_MIB_TX_CRS 22
  54. #define ETH_MIB_TX_PAUSE 23
  55. #define ETH_MIB_RX_GD_OCTETS 32
  56. #define ETH_MIB_RX_GD_PKTS 33
  57. #define ETH_MIB_RX_ALL_OCTETS 34
  58. #define ETH_MIB_RX_ALL_PKTS 35
  59. #define ETH_MIB_RX_BRDCAST 36
  60. #define ETH_MIB_RX_MULT 37
  61. #define ETH_MIB_RX_64 38
  62. #define ETH_MIB_RX_65_127 39
  63. #define ETH_MIB_RX_128_255 40
  64. #define ETH_MIB_RX_256_511 41
  65. #define ETH_MIB_RX_512_1023 42
  66. #define ETH_MIB_RX_1024_MAX 43
  67. #define ETH_MIB_RX_JAB 44
  68. #define ETH_MIB_RX_OVR 45
  69. #define ETH_MIB_RX_FRAG 46
  70. #define ETH_MIB_RX_DROP 47
  71. #define ETH_MIB_RX_CRC_ALIGN 48
  72. #define ETH_MIB_RX_UND 49
  73. #define ETH_MIB_RX_CRC 50
  74. #define ETH_MIB_RX_ALIGN 51
  75. #define ETH_MIB_RX_SYM 52
  76. #define ETH_MIB_RX_PAUSE 53
  77. #define ETH_MIB_RX_CNTRL 54
  78. /*
  79. * SW MIB Counters register definitions
  80. */
  81. #define ETHSW_MIB_TX_ALL_OCT 0
  82. #define ETHSW_MIB_TX_DROP_PKTS 2
  83. #define ETHSW_MIB_TX_QOS_PKTS 3
  84. #define ETHSW_MIB_TX_BRDCAST 4
  85. #define ETHSW_MIB_TX_MULT 5
  86. #define ETHSW_MIB_TX_UNI 6
  87. #define ETHSW_MIB_TX_COL 7
  88. #define ETHSW_MIB_TX_1_COL 8
  89. #define ETHSW_MIB_TX_M_COL 9
  90. #define ETHSW_MIB_TX_DEF 10
  91. #define ETHSW_MIB_TX_LATE 11
  92. #define ETHSW_MIB_TX_EX_COL 12
  93. #define ETHSW_MIB_TX_PAUSE 14
  94. #define ETHSW_MIB_TX_QOS_OCT 15
  95. #define ETHSW_MIB_RX_ALL_OCT 17
  96. #define ETHSW_MIB_RX_UND 19
  97. #define ETHSW_MIB_RX_PAUSE 20
  98. #define ETHSW_MIB_RX_64 21
  99. #define ETHSW_MIB_RX_65_127 22
  100. #define ETHSW_MIB_RX_128_255 23
  101. #define ETHSW_MIB_RX_256_511 24
  102. #define ETHSW_MIB_RX_512_1023 25
  103. #define ETHSW_MIB_RX_1024_1522 26
  104. #define ETHSW_MIB_RX_OVR 27
  105. #define ETHSW_MIB_RX_JAB 28
  106. #define ETHSW_MIB_RX_ALIGN 29
  107. #define ETHSW_MIB_RX_CRC 30
  108. #define ETHSW_MIB_RX_GD_OCT 31
  109. #define ETHSW_MIB_RX_DROP 33
  110. #define ETHSW_MIB_RX_UNI 34
  111. #define ETHSW_MIB_RX_MULT 35
  112. #define ETHSW_MIB_RX_BRDCAST 36
  113. #define ETHSW_MIB_RX_SA_CHANGE 37
  114. #define ETHSW_MIB_RX_FRAG 38
  115. #define ETHSW_MIB_RX_OVR_DISC 39
  116. #define ETHSW_MIB_RX_SYM 40
  117. #define ETHSW_MIB_RX_QOS_PKTS 41
  118. #define ETHSW_MIB_RX_QOS_OCT 42
  119. #define ETHSW_MIB_RX_1523_2047 44
  120. #define ETHSW_MIB_RX_2048_4095 45
  121. #define ETHSW_MIB_RX_4096_8191 46
  122. #define ETHSW_MIB_RX_8192_9728 47
  123. struct bcm_enet_mib_counters {
  124. u64 tx_gd_octets;
  125. u32 tx_gd_pkts;
  126. u32 tx_all_octets;
  127. u32 tx_all_pkts;
  128. u32 tx_unicast;
  129. u32 tx_brdcast;
  130. u32 tx_mult;
  131. u32 tx_64;
  132. u32 tx_65_127;
  133. u32 tx_128_255;
  134. u32 tx_256_511;
  135. u32 tx_512_1023;
  136. u32 tx_1024_max;
  137. u32 tx_1523_2047;
  138. u32 tx_2048_4095;
  139. u32 tx_4096_8191;
  140. u32 tx_8192_9728;
  141. u32 tx_jab;
  142. u32 tx_drop;
  143. u32 tx_ovr;
  144. u32 tx_frag;
  145. u32 tx_underrun;
  146. u32 tx_col;
  147. u32 tx_1_col;
  148. u32 tx_m_col;
  149. u32 tx_ex_col;
  150. u32 tx_late;
  151. u32 tx_def;
  152. u32 tx_crs;
  153. u32 tx_pause;
  154. u64 rx_gd_octets;
  155. u32 rx_gd_pkts;
  156. u32 rx_all_octets;
  157. u32 rx_all_pkts;
  158. u32 rx_brdcast;
  159. u32 rx_unicast;
  160. u32 rx_mult;
  161. u32 rx_64;
  162. u32 rx_65_127;
  163. u32 rx_128_255;
  164. u32 rx_256_511;
  165. u32 rx_512_1023;
  166. u32 rx_1024_max;
  167. u32 rx_jab;
  168. u32 rx_ovr;
  169. u32 rx_frag;
  170. u32 rx_drop;
  171. u32 rx_crc_align;
  172. u32 rx_und;
  173. u32 rx_crc;
  174. u32 rx_align;
  175. u32 rx_sym;
  176. u32 rx_pause;
  177. u32 rx_cntrl;
  178. };
  179. struct bcm_enet_priv {
  180. /* mac id (from platform device id) */
  181. int mac_id;
  182. /* base remapped address of device */
  183. void __iomem *base;
  184. /* mac irq, rx_dma irq, tx_dma irq */
  185. int irq;
  186. int irq_rx;
  187. int irq_tx;
  188. /* hw view of rx & tx dma ring */
  189. dma_addr_t rx_desc_dma;
  190. dma_addr_t tx_desc_dma;
  191. /* allocated size (in bytes) for rx & tx dma ring */
  192. unsigned int rx_desc_alloc_size;
  193. unsigned int tx_desc_alloc_size;
  194. struct napi_struct napi;
  195. /* dma channel id for rx */
  196. int rx_chan;
  197. /* number of dma desc in rx ring */
  198. int rx_ring_size;
  199. /* cpu view of rx dma ring */
  200. struct bcm_enet_desc *rx_desc_cpu;
  201. /* current number of armed descriptor given to hardware for rx */
  202. int rx_desc_count;
  203. /* next rx descriptor to fetch from hardware */
  204. int rx_curr_desc;
  205. /* next dirty rx descriptor to refill */
  206. int rx_dirty_desc;
  207. /* size of allocated rx skbs */
  208. unsigned int rx_skb_size;
  209. /* list of skb given to hw for rx */
  210. struct sk_buff **rx_skb;
  211. /* used when rx skb allocation failed, so we defer rx queue
  212. * refill */
  213. struct timer_list rx_timeout;
  214. /* lock rx_timeout against rx normal operation */
  215. spinlock_t rx_lock;
  216. /* dma channel id for tx */
  217. int tx_chan;
  218. /* number of dma desc in tx ring */
  219. int tx_ring_size;
  220. /* maximum dma burst size */
  221. int dma_maxburst;
  222. /* cpu view of rx dma ring */
  223. struct bcm_enet_desc *tx_desc_cpu;
  224. /* number of available descriptor for tx */
  225. int tx_desc_count;
  226. /* next tx descriptor avaiable */
  227. int tx_curr_desc;
  228. /* next dirty tx descriptor to reclaim */
  229. int tx_dirty_desc;
  230. /* list of skb given to hw for tx */
  231. struct sk_buff **tx_skb;
  232. /* lock used by tx reclaim and xmit */
  233. spinlock_t tx_lock;
  234. /* set if internal phy is ignored and external mii interface
  235. * is selected */
  236. int use_external_mii;
  237. /* set if a phy is connected, phy address must be known,
  238. * probing is not possible */
  239. int has_phy;
  240. int phy_id;
  241. /* set if connected phy has an associated irq */
  242. int has_phy_interrupt;
  243. int phy_interrupt;
  244. /* used when a phy is connected (phylib used) */
  245. struct mii_bus *mii_bus;
  246. int old_link;
  247. int old_duplex;
  248. int old_pause;
  249. /* used when no phy is connected */
  250. int force_speed_100;
  251. int force_duplex_full;
  252. /* pause parameters */
  253. int pause_auto;
  254. int pause_rx;
  255. int pause_tx;
  256. /* stats */
  257. struct bcm_enet_mib_counters mib;
  258. /* after mib interrupt, mib registers update is done in this
  259. * work queue */
  260. struct work_struct mib_update_task;
  261. /* lock mib update between userspace request and workqueue */
  262. struct mutex mib_update_lock;
  263. /* mac clock */
  264. struct clk *mac_clk;
  265. /* phy clock if internal phy is used */
  266. struct clk *phy_clk;
  267. /* network device reference */
  268. struct net_device *net_dev;
  269. /* platform device reference */
  270. struct platform_device *pdev;
  271. /* maximum hardware transmit/receive size */
  272. unsigned int hw_mtu;
  273. bool enet_is_sw;
  274. /* port mapping for switch devices */
  275. int num_ports;
  276. struct bcm63xx_enetsw_port used_ports[ENETSW_MAX_PORT];
  277. int sw_port_link[ENETSW_MAX_PORT];
  278. /* used to poll switch port state */
  279. struct timer_list swphy_poll;
  280. spinlock_t enetsw_mdio_lock;
  281. /* dma channel enable mask */
  282. u32 dma_chan_en_mask;
  283. /* dma channel interrupt mask */
  284. u32 dma_chan_int_mask;
  285. /* DMA engine has internal SRAM */
  286. bool dma_has_sram;
  287. /* dma channel width */
  288. unsigned int dma_chan_width;
  289. /* dma descriptor shift value */
  290. unsigned int dma_desc_shift;
  291. };
  292. #endif /* ! BCM63XX_ENET_H_ */