dnet.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Dave DNET Ethernet Controller driver
  3. *
  4. * Copyright (C) 2008 Dave S.r.l. <www.dave.eu>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _DNET_H
  11. #define _DNET_H
  12. #define DRV_NAME "dnet"
  13. #define DRV_VERSION "0.9.1"
  14. #define PFX DRV_NAME ": "
  15. /* Register access macros */
  16. #define dnet_writel(port, value, reg) \
  17. writel((value), (port)->regs + DNET_##reg)
  18. #define dnet_readl(port, reg) readl((port)->regs + DNET_##reg)
  19. /* ALL DNET FIFO REGISTERS */
  20. #define DNET_RX_LEN_FIFO 0x000 /* RX_LEN_FIFO */
  21. #define DNET_RX_DATA_FIFO 0x004 /* RX_DATA_FIFO */
  22. #define DNET_TX_LEN_FIFO 0x008 /* TX_LEN_FIFO */
  23. #define DNET_TX_DATA_FIFO 0x00C /* TX_DATA_FIFO */
  24. /* ALL DNET CONTROL/STATUS REGISTERS OFFSETS */
  25. #define DNET_VERCAPS 0x100 /* VERCAPS */
  26. #define DNET_INTR_SRC 0x104 /* INTR_SRC */
  27. #define DNET_INTR_ENB 0x108 /* INTR_ENB */
  28. #define DNET_RX_STATUS 0x10C /* RX_STATUS */
  29. #define DNET_TX_STATUS 0x110 /* TX_STATUS */
  30. #define DNET_RX_FRAMES_CNT 0x114 /* RX_FRAMES_CNT */
  31. #define DNET_TX_FRAMES_CNT 0x118 /* TX_FRAMES_CNT */
  32. #define DNET_RX_FIFO_TH 0x11C /* RX_FIFO_TH */
  33. #define DNET_TX_FIFO_TH 0x120 /* TX_FIFO_TH */
  34. #define DNET_SYS_CTL 0x124 /* SYS_CTL */
  35. #define DNET_PAUSE_TMR 0x128 /* PAUSE_TMR */
  36. #define DNET_RX_FIFO_WCNT 0x12C /* RX_FIFO_WCNT */
  37. #define DNET_TX_FIFO_WCNT 0x130 /* TX_FIFO_WCNT */
  38. /* ALL DNET MAC REGISTERS */
  39. #define DNET_MACREG_DATA 0x200 /* Mac-Reg Data */
  40. #define DNET_MACREG_ADDR 0x204 /* Mac-Reg Addr */
  41. /* ALL DNET RX STATISTICS COUNTERS */
  42. #define DNET_RX_PKT_IGNR_CNT 0x300
  43. #define DNET_RX_LEN_CHK_ERR_CNT 0x304
  44. #define DNET_RX_LNG_FRM_CNT 0x308
  45. #define DNET_RX_SHRT_FRM_CNT 0x30C
  46. #define DNET_RX_IPG_VIOL_CNT 0x310
  47. #define DNET_RX_CRC_ERR_CNT 0x314
  48. #define DNET_RX_OK_PKT_CNT 0x318
  49. #define DNET_RX_CTL_FRM_CNT 0x31C
  50. #define DNET_RX_PAUSE_FRM_CNT 0x320
  51. #define DNET_RX_MULTICAST_CNT 0x324
  52. #define DNET_RX_BROADCAST_CNT 0x328
  53. #define DNET_RX_VLAN_TAG_CNT 0x32C
  54. #define DNET_RX_PRE_SHRINK_CNT 0x330
  55. #define DNET_RX_DRIB_NIB_CNT 0x334
  56. #define DNET_RX_UNSUP_OPCD_CNT 0x338
  57. #define DNET_RX_BYTE_CNT 0x33C
  58. /* DNET TX STATISTICS COUNTERS */
  59. #define DNET_TX_UNICAST_CNT 0x400
  60. #define DNET_TX_PAUSE_FRM_CNT 0x404
  61. #define DNET_TX_MULTICAST_CNT 0x408
  62. #define DNET_TX_BRDCAST_CNT 0x40C
  63. #define DNET_TX_VLAN_TAG_CNT 0x410
  64. #define DNET_TX_BAD_FCS_CNT 0x414
  65. #define DNET_TX_JUMBO_CNT 0x418
  66. #define DNET_TX_BYTE_CNT 0x41C
  67. /* SOME INTERNAL MAC-CORE REGISTER */
  68. #define DNET_INTERNAL_MODE_REG 0x0
  69. #define DNET_INTERNAL_RXTX_CONTROL_REG 0x2
  70. #define DNET_INTERNAL_MAX_PKT_SIZE_REG 0x4
  71. #define DNET_INTERNAL_IGP_REG 0x8
  72. #define DNET_INTERNAL_MAC_ADDR_0_REG 0xa
  73. #define DNET_INTERNAL_MAC_ADDR_1_REG 0xc
  74. #define DNET_INTERNAL_MAC_ADDR_2_REG 0xe
  75. #define DNET_INTERNAL_TX_RX_STS_REG 0x12
  76. #define DNET_INTERNAL_GMII_MNG_CTL_REG 0x14
  77. #define DNET_INTERNAL_GMII_MNG_DAT_REG 0x16
  78. #define DNET_INTERNAL_GMII_MNG_CMD_FIN (1 << 14)
  79. #define DNET_INTERNAL_WRITE (1 << 31)
  80. /* MAC-CORE REGISTER FIELDS */
  81. /* MAC-CORE MODE REGISTER FIELDS */
  82. #define DNET_INTERNAL_MODE_GBITEN (1 << 0)
  83. #define DNET_INTERNAL_MODE_FCEN (1 << 1)
  84. #define DNET_INTERNAL_MODE_RXEN (1 << 2)
  85. #define DNET_INTERNAL_MODE_TXEN (1 << 3)
  86. /* MAC-CORE RXTX CONTROL REGISTER FIELDS */
  87. #define DNET_INTERNAL_RXTX_CONTROL_RXSHORTFRAME (1 << 8)
  88. #define DNET_INTERNAL_RXTX_CONTROL_RXBROADCAST (1 << 7)
  89. #define DNET_INTERNAL_RXTX_CONTROL_RXMULTICAST (1 << 4)
  90. #define DNET_INTERNAL_RXTX_CONTROL_RXPAUSE (1 << 3)
  91. #define DNET_INTERNAL_RXTX_CONTROL_DISTXFCS (1 << 2)
  92. #define DNET_INTERNAL_RXTX_CONTROL_DISCFXFCS (1 << 1)
  93. #define DNET_INTERNAL_RXTX_CONTROL_ENPROMISC (1 << 0)
  94. #define DNET_INTERNAL_RXTX_CONTROL_DROPCONTROL (1 << 6)
  95. #define DNET_INTERNAL_RXTX_CONTROL_ENABLEHALFDUP (1 << 5)
  96. /* SYSTEM CONTROL REGISTER FIELDS */
  97. #define DNET_SYS_CTL_IGNORENEXTPKT (1 << 0)
  98. #define DNET_SYS_CTL_SENDPAUSE (1 << 2)
  99. #define DNET_SYS_CTL_RXFIFOFLUSH (1 << 3)
  100. #define DNET_SYS_CTL_TXFIFOFLUSH (1 << 4)
  101. /* TX STATUS REGISTER FIELDS */
  102. #define DNET_TX_STATUS_FIFO_ALMOST_EMPTY (1 << 2)
  103. #define DNET_TX_STATUS_FIFO_ALMOST_FULL (1 << 1)
  104. /* INTERRUPT SOURCE REGISTER FIELDS */
  105. #define DNET_INTR_SRC_TX_PKTSENT (1 << 0)
  106. #define DNET_INTR_SRC_TX_FIFOAF (1 << 1)
  107. #define DNET_INTR_SRC_TX_FIFOAE (1 << 2)
  108. #define DNET_INTR_SRC_TX_DISCFRM (1 << 3)
  109. #define DNET_INTR_SRC_TX_FIFOFULL (1 << 4)
  110. #define DNET_INTR_SRC_RX_CMDFIFOAF (1 << 8)
  111. #define DNET_INTR_SRC_RX_CMDFIFOFF (1 << 9)
  112. #define DNET_INTR_SRC_RX_DATAFIFOFF (1 << 10)
  113. #define DNET_INTR_SRC_TX_SUMMARY (1 << 16)
  114. #define DNET_INTR_SRC_RX_SUMMARY (1 << 17)
  115. #define DNET_INTR_SRC_PHY (1 << 19)
  116. /* INTERRUPT ENABLE REGISTER FIELDS */
  117. #define DNET_INTR_ENB_TX_PKTSENT (1 << 0)
  118. #define DNET_INTR_ENB_TX_FIFOAF (1 << 1)
  119. #define DNET_INTR_ENB_TX_FIFOAE (1 << 2)
  120. #define DNET_INTR_ENB_TX_DISCFRM (1 << 3)
  121. #define DNET_INTR_ENB_TX_FIFOFULL (1 << 4)
  122. #define DNET_INTR_ENB_RX_PKTRDY (1 << 8)
  123. #define DNET_INTR_ENB_RX_FIFOAF (1 << 9)
  124. #define DNET_INTR_ENB_RX_FIFOERR (1 << 10)
  125. #define DNET_INTR_ENB_RX_ERROR (1 << 11)
  126. #define DNET_INTR_ENB_RX_FIFOFULL (1 << 12)
  127. #define DNET_INTR_ENB_RX_FIFOAE (1 << 13)
  128. #define DNET_INTR_ENB_TX_SUMMARY (1 << 16)
  129. #define DNET_INTR_ENB_RX_SUMMARY (1 << 17)
  130. #define DNET_INTR_ENB_GLOBAL_ENABLE (1 << 18)
  131. /* default values:
  132. * almost empty = less than one full sized ethernet frame (no jumbo) inside
  133. * the fifo almost full = can write less than one full sized ethernet frame
  134. * (no jumbo) inside the fifo
  135. */
  136. #define DNET_CFG_TX_FIFO_FULL_THRES 25
  137. #define DNET_CFG_RX_FIFO_FULL_THRES 20
  138. /*
  139. * Capabilities. Used by the driver to know the capabilities that the ethernet
  140. * controller inside the FPGA have.
  141. */
  142. #define DNET_HAS_MDIO (1 << 0)
  143. #define DNET_HAS_IRQ (1 << 1)
  144. #define DNET_HAS_GIGABIT (1 << 2)
  145. #define DNET_HAS_DMA (1 << 3)
  146. #define DNET_HAS_MII (1 << 4) /* or GMII */
  147. #define DNET_HAS_RMII (1 << 5) /* or RGMII */
  148. #define DNET_CAPS_MASK 0xFFFF
  149. #define DNET_FIFO_SIZE 1024 /* 1K x 32 bit */
  150. #define DNET_FIFO_TX_DATA_AF_TH (DNET_FIFO_SIZE - 384) /* 384 = 1536 / 4 */
  151. #define DNET_FIFO_TX_DATA_AE_TH 384
  152. #define DNET_FIFO_RX_CMD_AF_TH (1 << 16) /* just one frame inside the FIFO */
  153. /*
  154. * Hardware-collected statistics.
  155. */
  156. struct dnet_stats {
  157. u32 rx_pkt_ignr;
  158. u32 rx_len_chk_err;
  159. u32 rx_lng_frm;
  160. u32 rx_shrt_frm;
  161. u32 rx_ipg_viol;
  162. u32 rx_crc_err;
  163. u32 rx_ok_pkt;
  164. u32 rx_ctl_frm;
  165. u32 rx_pause_frm;
  166. u32 rx_multicast;
  167. u32 rx_broadcast;
  168. u32 rx_vlan_tag;
  169. u32 rx_pre_shrink;
  170. u32 rx_drib_nib;
  171. u32 rx_unsup_opcd;
  172. u32 rx_byte;
  173. u32 tx_unicast;
  174. u32 tx_pause_frm;
  175. u32 tx_multicast;
  176. u32 tx_brdcast;
  177. u32 tx_vlan_tag;
  178. u32 tx_bad_fcs;
  179. u32 tx_jumbo;
  180. u32 tx_byte;
  181. };
  182. struct dnet {
  183. void __iomem *regs;
  184. spinlock_t lock;
  185. struct platform_device *pdev;
  186. struct net_device *dev;
  187. struct dnet_stats hw_stats;
  188. unsigned int capabilities; /* read from FPGA */
  189. struct napi_struct napi;
  190. /* PHY stuff */
  191. struct mii_bus *mii_bus;
  192. struct phy_device *phy_dev;
  193. unsigned int link;
  194. unsigned int speed;
  195. unsigned int duplex;
  196. };
  197. #endif /* _DNET_H */