moxart_ether.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /* MOXA ART Ethernet (RTL8201CP) driver.
  2. *
  3. * Copyright (C) 2013 Jonas Jensen
  4. *
  5. * Jonas Jensen <jonas.jensen@gmail.com>
  6. *
  7. * Based on code from
  8. * Moxa Technology Co., Ltd. <www.moxa.com>
  9. *
  10. * This file is licensed under the terms of the GNU General Public
  11. * License version 2. This program is licensed "as is" without any
  12. * warranty of any kind, whether express or implied.
  13. */
  14. #ifndef _MOXART_ETHERNET_H
  15. #define _MOXART_ETHERNET_H
  16. #define TX_REG_OFFSET_DESC0 0
  17. #define TX_REG_OFFSET_DESC1 4
  18. #define TX_REG_OFFSET_DESC2 8
  19. #define TX_REG_DESC_SIZE 16
  20. #define RX_REG_OFFSET_DESC0 0
  21. #define RX_REG_OFFSET_DESC1 4
  22. #define RX_REG_OFFSET_DESC2 8
  23. #define RX_REG_DESC_SIZE 16
  24. #define TX_DESC0_PKT_LATE_COL 0x1 /* abort, late collision */
  25. #define TX_DESC0_RX_PKT_EXS_COL 0x2 /* abort, >16 collisions */
  26. #define TX_DESC0_DMA_OWN 0x80000000 /* owned by controller */
  27. #define TX_DESC1_BUF_SIZE_MASK 0x7ff
  28. #define TX_DESC1_LTS 0x8000000 /* last TX packet */
  29. #define TX_DESC1_FTS 0x10000000 /* first TX packet */
  30. #define TX_DESC1_FIFO_COMPLETE 0x20000000
  31. #define TX_DESC1_INTR_COMPLETE 0x40000000
  32. #define TX_DESC1_END 0x80000000
  33. #define TX_DESC2_ADDRESS_PHYS 0
  34. #define TX_DESC2_ADDRESS_VIRT 4
  35. #define RX_DESC0_FRAME_LEN 0
  36. #define RX_DESC0_FRAME_LEN_MASK 0x7FF
  37. #define RX_DESC0_MULTICAST 0x10000
  38. #define RX_DESC0_BROADCAST 0x20000
  39. #define RX_DESC0_ERR 0x40000
  40. #define RX_DESC0_CRC_ERR 0x80000
  41. #define RX_DESC0_FTL 0x100000
  42. #define RX_DESC0_RUNT 0x200000 /* packet less than 64 bytes */
  43. #define RX_DESC0_ODD_NB 0x400000 /* receive odd nibbles */
  44. #define RX_DESC0_LRS 0x10000000 /* last receive segment */
  45. #define RX_DESC0_FRS 0x20000000 /* first receive segment */
  46. #define RX_DESC0_DMA_OWN 0x80000000
  47. #define RX_DESC1_BUF_SIZE_MASK 0x7FF
  48. #define RX_DESC1_END 0x80000000
  49. #define RX_DESC2_ADDRESS_PHYS 0
  50. #define RX_DESC2_ADDRESS_VIRT 4
  51. #define TX_DESC_NUM 64
  52. #define TX_DESC_NUM_MASK (TX_DESC_NUM - 1)
  53. #define TX_NEXT(N) (((N) + 1) & (TX_DESC_NUM_MASK))
  54. #define TX_BUF_SIZE 1600
  55. #define TX_BUF_SIZE_MAX (TX_DESC1_BUF_SIZE_MASK + 1)
  56. #define TX_WAKE_THRESHOLD 16
  57. #define RX_DESC_NUM 64
  58. #define RX_DESC_NUM_MASK (RX_DESC_NUM - 1)
  59. #define RX_NEXT(N) (((N) + 1) & (RX_DESC_NUM_MASK))
  60. #define RX_BUF_SIZE 1600
  61. #define RX_BUF_SIZE_MAX (RX_DESC1_BUF_SIZE_MASK + 1)
  62. #define REG_INTERRUPT_STATUS 0
  63. #define REG_INTERRUPT_MASK 4
  64. #define REG_MAC_MS_ADDRESS 8
  65. #define REG_MAC_LS_ADDRESS 12
  66. #define REG_MCAST_HASH_TABLE0 16
  67. #define REG_MCAST_HASH_TABLE1 20
  68. #define REG_TX_POLL_DEMAND 24
  69. #define REG_RX_POLL_DEMAND 28
  70. #define REG_TXR_BASE_ADDRESS 32
  71. #define REG_RXR_BASE_ADDRESS 36
  72. #define REG_INT_TIMER_CTRL 40
  73. #define REG_APOLL_TIMER_CTRL 44
  74. #define REG_DMA_BLEN_CTRL 48
  75. #define REG_RESERVED1 52
  76. #define REG_MAC_CTRL 136
  77. #define REG_MAC_STATUS 140
  78. #define REG_PHY_CTRL 144
  79. #define REG_PHY_WRITE_DATA 148
  80. #define REG_FLOW_CTRL 152
  81. #define REG_BACK_PRESSURE 156
  82. #define REG_RESERVED2 160
  83. #define REG_TEST_SEED 196
  84. #define REG_DMA_FIFO_STATE 200
  85. #define REG_TEST_MODE 204
  86. #define REG_RESERVED3 208
  87. #define REG_TX_COL_COUNTER 212
  88. #define REG_RPF_AEP_COUNTER 216
  89. #define REG_XM_PG_COUNTER 220
  90. #define REG_RUNT_TLC_COUNTER 224
  91. #define REG_CRC_FTL_COUNTER 228
  92. #define REG_RLC_RCC_COUNTER 232
  93. #define REG_BROC_COUNTER 236
  94. #define REG_MULCA_COUNTER 240
  95. #define REG_RP_COUNTER 244
  96. #define REG_XP_COUNTER 248
  97. #define REG_PHY_CTRL_OFFSET 0x0
  98. #define REG_PHY_STATUS 0x1
  99. #define REG_PHY_ID1 0x2
  100. #define REG_PHY_ID2 0x3
  101. #define REG_PHY_ANA 0x4
  102. #define REG_PHY_ANLPAR 0x5
  103. #define REG_PHY_ANE 0x6
  104. #define REG_PHY_ECTRL1 0x10
  105. #define REG_PHY_QPDS 0x11
  106. #define REG_PHY_10BOP 0x12
  107. #define REG_PHY_ECTRL2 0x13
  108. #define REG_PHY_FTMAC100_WRITE 0x8000000
  109. #define REG_PHY_FTMAC100_READ 0x4000000
  110. /* REG_INTERRUPT_STATUS */
  111. #define RPKT_FINISH BIT(0) /* DMA data received */
  112. #define NORXBUF BIT(1) /* receive buffer unavailable */
  113. #define XPKT_FINISH BIT(2) /* DMA moved data to TX FIFO */
  114. #define NOTXBUF BIT(3) /* transmit buffer unavailable */
  115. #define XPKT_OK_INT_STS BIT(4) /* transmit to ethernet success */
  116. #define XPKT_LOST_INT_STS BIT(5) /* transmit ethernet lost (collision) */
  117. #define RPKT_SAV BIT(6) /* FIFO receive success */
  118. #define RPKT_LOST_INT_STS BIT(7) /* FIFO full, receive failed */
  119. #define AHB_ERR BIT(8) /* AHB error */
  120. #define PHYSTS_CHG BIT(9) /* PHY link status change */
  121. /* REG_INTERRUPT_MASK */
  122. #define RPKT_FINISH_M BIT(0)
  123. #define NORXBUF_M BIT(1)
  124. #define XPKT_FINISH_M BIT(2)
  125. #define NOTXBUF_M BIT(3)
  126. #define XPKT_OK_M BIT(4)
  127. #define XPKT_LOST_M BIT(5)
  128. #define RPKT_SAV_M BIT(6)
  129. #define RPKT_LOST_M BIT(7)
  130. #define AHB_ERR_M BIT(8)
  131. #define PHYSTS_CHG_M BIT(9)
  132. /* REG_MAC_MS_ADDRESS */
  133. #define MAC_MADR_MASK 0xffff /* 2 MSB MAC address */
  134. /* REG_INT_TIMER_CTRL */
  135. #define TXINT_TIME_SEL BIT(15) /* TX cycle time period */
  136. #define TXINT_THR_MASK 0x7000
  137. #define TXINT_CNT_MASK 0xf00
  138. #define RXINT_TIME_SEL BIT(7) /* RX cycle time period */
  139. #define RXINT_THR_MASK 0x70
  140. #define RXINT_CNT_MASK 0xF
  141. /* REG_APOLL_TIMER_CTRL */
  142. #define TXPOLL_TIME_SEL BIT(12) /* TX poll time period */
  143. #define TXPOLL_CNT_MASK 0xf00
  144. #define TXPOLL_CNT_SHIFT_BIT 8
  145. #define RXPOLL_TIME_SEL BIT(4) /* RX poll time period */
  146. #define RXPOLL_CNT_MASK 0xF
  147. #define RXPOLL_CNT_SHIFT_BIT 0
  148. /* REG_DMA_BLEN_CTRL */
  149. #define RX_THR_EN BIT(9) /* RX FIFO threshold arbitration */
  150. #define RXFIFO_HTHR_MASK 0x1c0
  151. #define RXFIFO_LTHR_MASK 0x38
  152. #define INCR16_EN BIT(2) /* AHB bus INCR16 burst command */
  153. #define INCR8_EN BIT(1) /* AHB bus INCR8 burst command */
  154. #define INCR4_EN BIT(0) /* AHB bus INCR4 burst command */
  155. /* REG_MAC_CTRL */
  156. #define RX_BROADPKT BIT(17) /* receive broadcast packets */
  157. #define RX_MULTIPKT BIT(16) /* receive all multicast packets */
  158. #define FULLDUP BIT(15) /* full duplex */
  159. #define CRC_APD BIT(14) /* append CRC to transmitted packet */
  160. #define RCV_ALL BIT(12) /* ignore incoming packet destination */
  161. #define RX_FTL BIT(11) /* accept packets larger than 1518 B */
  162. #define RX_RUNT BIT(10) /* accept packets smaller than 64 B */
  163. #define HT_MULTI_EN BIT(9) /* accept on hash and mcast pass */
  164. #define RCV_EN BIT(8) /* receiver enable */
  165. #define ENRX_IN_HALFTX BIT(6) /* enable receive in half duplex mode */
  166. #define XMT_EN BIT(5) /* transmit enable */
  167. #define CRC_DIS BIT(4) /* disable CRC check when receiving */
  168. #define LOOP_EN BIT(3) /* internal loop-back */
  169. #define SW_RST BIT(2) /* software reset, last 64 AHB clocks */
  170. #define RDMA_EN BIT(1) /* enable receive DMA chan */
  171. #define XDMA_EN BIT(0) /* enable transmit DMA chan */
  172. /* REG_MAC_STATUS */
  173. #define COL_EXCEED BIT(11) /* more than 16 collisions */
  174. #define LATE_COL BIT(10) /* transmit late collision detected */
  175. #define XPKT_LOST BIT(9) /* transmit to ethernet lost */
  176. #define XPKT_OK BIT(8) /* transmit to ethernet success */
  177. #define RUNT_MAC_STS BIT(7) /* receive runt detected */
  178. #define FTL_MAC_STS BIT(6) /* receive frame too long detected */
  179. #define CRC_ERR_MAC_STS BIT(5)
  180. #define RPKT_LOST BIT(4) /* RX FIFO full, receive failed */
  181. #define RPKT_SAVE BIT(3) /* RX FIFO receive success */
  182. #define COL BIT(2) /* collision, incoming packet dropped */
  183. #define MCPU_BROADCAST BIT(1)
  184. #define MCPU_MULTICAST BIT(0)
  185. /* REG_PHY_CTRL */
  186. #define MIIWR BIT(27) /* init write sequence (auto cleared)*/
  187. #define MIIRD BIT(26)
  188. #define REGAD_MASK 0x3e00000
  189. #define PHYAD_MASK 0x1f0000
  190. #define MIIRDATA_MASK 0xffff
  191. /* REG_PHY_WRITE_DATA */
  192. #define MIIWDATA_MASK 0xffff
  193. /* REG_FLOW_CTRL */
  194. #define PAUSE_TIME_MASK 0xffff0000
  195. #define FC_HIGH_MASK 0xf000
  196. #define FC_LOW_MASK 0xf00
  197. #define RX_PAUSE BIT(4) /* receive pause frame */
  198. #define TX_PAUSED BIT(3) /* transmit pause due to receive */
  199. #define FCTHR_EN BIT(2) /* enable threshold mode. */
  200. #define TX_PAUSE BIT(1) /* transmit pause frame */
  201. #define FC_EN BIT(0) /* flow control mode enable */
  202. /* REG_BACK_PRESSURE */
  203. #define BACKP_LOW_MASK 0xf00
  204. #define BACKP_JAM_LEN_MASK 0xf0
  205. #define BACKP_MODE BIT(1) /* address mode */
  206. #define BACKP_ENABLE BIT(0)
  207. /* REG_TEST_SEED */
  208. #define TEST_SEED_MASK 0x3fff
  209. /* REG_DMA_FIFO_STATE */
  210. #define TX_DMA_REQUEST BIT(31)
  211. #define RX_DMA_REQUEST BIT(30)
  212. #define TX_DMA_GRANT BIT(29)
  213. #define RX_DMA_GRANT BIT(28)
  214. #define TX_FIFO_EMPTY BIT(27)
  215. #define RX_FIFO_EMPTY BIT(26)
  216. #define TX_DMA2_SM_MASK 0x7000
  217. #define TX_DMA1_SM_MASK 0xf00
  218. #define RX_DMA2_SM_MASK 0x70
  219. #define RX_DMA1_SM_MASK 0xF
  220. /* REG_TEST_MODE */
  221. #define SINGLE_PKT BIT(26) /* single packet mode */
  222. #define PTIMER_TEST BIT(25) /* automatic polling timer test mode */
  223. #define ITIMER_TEST BIT(24) /* interrupt timer test mode */
  224. #define TEST_SEED_SELECT BIT(22)
  225. #define SEED_SELECT BIT(21)
  226. #define TEST_MODE BIT(20)
  227. #define TEST_TIME_MASK 0xffc00
  228. #define TEST_EXCEL_MASK 0x3e0
  229. /* REG_TX_COL_COUNTER */
  230. #define TX_MCOL_MASK 0xffff0000
  231. #define TX_MCOL_SHIFT_BIT 16
  232. #define TX_SCOL_MASK 0xffff
  233. #define TX_SCOL_SHIFT_BIT 0
  234. /* REG_RPF_AEP_COUNTER */
  235. #define RPF_MASK 0xffff0000
  236. #define RPF_SHIFT_BIT 16
  237. #define AEP_MASK 0xffff
  238. #define AEP_SHIFT_BIT 0
  239. /* REG_XM_PG_COUNTER */
  240. #define XM_MASK 0xffff0000
  241. #define XM_SHIFT_BIT 16
  242. #define PG_MASK 0xffff
  243. #define PG_SHIFT_BIT 0
  244. /* REG_RUNT_TLC_COUNTER */
  245. #define RUNT_CNT_MASK 0xffff0000
  246. #define RUNT_CNT_SHIFT_BIT 16
  247. #define TLCC_MASK 0xffff
  248. #define TLCC_SHIFT_BIT 0
  249. /* REG_CRC_FTL_COUNTER */
  250. #define CRCER_CNT_MASK 0xffff0000
  251. #define CRCER_CNT_SHIFT_BIT 16
  252. #define FTL_CNT_MASK 0xffff
  253. #define FTL_CNT_SHIFT_BIT 0
  254. /* REG_RLC_RCC_COUNTER */
  255. #define RLC_MASK 0xffff0000
  256. #define RLC_SHIFT_BIT 16
  257. #define RCC_MASK 0xffff
  258. #define RCC_SHIFT_BIT 0
  259. /* REG_PHY_STATUS */
  260. #define AN_COMPLETE 0x20
  261. #define LINK_STATUS 0x4
  262. struct moxart_mac_priv_t {
  263. struct platform_device *pdev;
  264. void __iomem *base;
  265. unsigned int reg_maccr;
  266. unsigned int reg_imr;
  267. struct napi_struct napi;
  268. struct net_device *ndev;
  269. dma_addr_t rx_base;
  270. dma_addr_t rx_mapping[RX_DESC_NUM];
  271. void *rx_desc_base;
  272. unsigned char *rx_buf_base;
  273. unsigned char *rx_buf[RX_DESC_NUM];
  274. unsigned int rx_head;
  275. unsigned int rx_buf_size;
  276. dma_addr_t tx_base;
  277. dma_addr_t tx_mapping[TX_DESC_NUM];
  278. void *tx_desc_base;
  279. unsigned char *tx_buf_base;
  280. unsigned char *tx_buf[RX_DESC_NUM];
  281. unsigned int tx_head;
  282. unsigned int tx_buf_size;
  283. spinlock_t txlock;
  284. unsigned int tx_len[TX_DESC_NUM];
  285. struct sk_buff *tx_skb[TX_DESC_NUM];
  286. unsigned int tx_tail;
  287. };
  288. #if TX_BUF_SIZE >= TX_BUF_SIZE_MAX
  289. #error MOXA ART Ethernet device driver TX buffer is too large!
  290. #endif
  291. #if RX_BUF_SIZE >= RX_BUF_SIZE_MAX
  292. #error MOXA ART Ethernet device driver RX buffer is too large!
  293. #endif
  294. #endif