bcm63xx_enet.h 6.6 KB

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