owl-emac.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Actions Semi Owl SoCs Ethernet MAC driver
  4. *
  5. * Copyright (c) 2012 Actions Semi Inc.
  6. * Copyright (c) 2021 Cristian Ciocaltea <[email protected]>
  7. */
  8. #ifndef __OWL_EMAC_H__
  9. #define __OWL_EMAC_H__
  10. #define OWL_EMAC_DRVNAME "owl-emac"
  11. #define OWL_EMAC_POLL_DELAY_USEC 5
  12. #define OWL_EMAC_MDIO_POLL_TIMEOUT_USEC 1000
  13. #define OWL_EMAC_RESET_POLL_TIMEOUT_USEC 2000
  14. #define OWL_EMAC_TX_TIMEOUT (2 * HZ)
  15. #define OWL_EMAC_MTU_MIN ETH_MIN_MTU
  16. #define OWL_EMAC_MTU_MAX ETH_DATA_LEN
  17. #define OWL_EMAC_RX_FRAME_MAX_LEN (ETH_FRAME_LEN + ETH_FCS_LEN)
  18. #define OWL_EMAC_SKB_ALIGN 4
  19. #define OWL_EMAC_SKB_RESERVE 18
  20. #define OWL_EMAC_MAX_MULTICAST_ADDRS 14
  21. #define OWL_EMAC_SETUP_FRAME_LEN 192
  22. #define OWL_EMAC_RX_RING_SIZE 64
  23. #define OWL_EMAC_TX_RING_SIZE 32
  24. /* Bus mode register */
  25. #define OWL_EMAC_REG_MAC_CSR0 0x0000
  26. #define OWL_EMAC_BIT_MAC_CSR0_SWR BIT(0) /* Software reset */
  27. /* Transmit/receive poll demand registers */
  28. #define OWL_EMAC_REG_MAC_CSR1 0x0008
  29. #define OWL_EMAC_VAL_MAC_CSR1_TPD 0x01
  30. #define OWL_EMAC_REG_MAC_CSR2 0x0010
  31. #define OWL_EMAC_VAL_MAC_CSR2_RPD 0x01
  32. /* Receive/transmit descriptor list base address registers */
  33. #define OWL_EMAC_REG_MAC_CSR3 0x0018
  34. #define OWL_EMAC_REG_MAC_CSR4 0x0020
  35. /* Status register */
  36. #define OWL_EMAC_REG_MAC_CSR5 0x0028
  37. #define OWL_EMAC_MSK_MAC_CSR5_TS GENMASK(22, 20) /* Transmit process state */
  38. #define OWL_EMAC_OFF_MAC_CSR5_TS 20
  39. #define OWL_EMAC_VAL_MAC_CSR5_TS_DATA 0x03 /* Transferring data HOST -> FIFO */
  40. #define OWL_EMAC_VAL_MAC_CSR5_TS_CDES 0x07 /* Closing transmit descriptor */
  41. #define OWL_EMAC_MSK_MAC_CSR5_RS GENMASK(19, 17) /* Receive process state */
  42. #define OWL_EMAC_OFF_MAC_CSR5_RS 17
  43. #define OWL_EMAC_VAL_MAC_CSR5_RS_FDES 0x01 /* Fetching receive descriptor */
  44. #define OWL_EMAC_VAL_MAC_CSR5_RS_CDES 0x05 /* Closing receive descriptor */
  45. #define OWL_EMAC_VAL_MAC_CSR5_RS_DATA 0x07 /* Transferring data FIFO -> HOST */
  46. #define OWL_EMAC_BIT_MAC_CSR5_NIS BIT(16) /* Normal interrupt summary */
  47. #define OWL_EMAC_BIT_MAC_CSR5_AIS BIT(15) /* Abnormal interrupt summary */
  48. #define OWL_EMAC_BIT_MAC_CSR5_ERI BIT(14) /* Early receive interrupt */
  49. #define OWL_EMAC_BIT_MAC_CSR5_GTE BIT(11) /* General-purpose timer expiration */
  50. #define OWL_EMAC_BIT_MAC_CSR5_ETI BIT(10) /* Early transmit interrupt */
  51. #define OWL_EMAC_BIT_MAC_CSR5_RPS BIT(8) /* Receive process stopped */
  52. #define OWL_EMAC_BIT_MAC_CSR5_RU BIT(7) /* Receive buffer unavailable */
  53. #define OWL_EMAC_BIT_MAC_CSR5_RI BIT(6) /* Receive interrupt */
  54. #define OWL_EMAC_BIT_MAC_CSR5_UNF BIT(5) /* Transmit underflow */
  55. #define OWL_EMAC_BIT_MAC_CSR5_LCIS BIT(4) /* Link change status */
  56. #define OWL_EMAC_BIT_MAC_CSR5_LCIQ BIT(3) /* Link change interrupt */
  57. #define OWL_EMAC_BIT_MAC_CSR5_TU BIT(2) /* Transmit buffer unavailable */
  58. #define OWL_EMAC_BIT_MAC_CSR5_TPS BIT(1) /* Transmit process stopped */
  59. #define OWL_EMAC_BIT_MAC_CSR5_TI BIT(0) /* Transmit interrupt */
  60. /* Operation mode register */
  61. #define OWL_EMAC_REG_MAC_CSR6 0x0030
  62. #define OWL_EMAC_BIT_MAC_CSR6_RA BIT(30) /* Receive all */
  63. #define OWL_EMAC_BIT_MAC_CSR6_TTM BIT(22) /* Transmit threshold mode */
  64. #define OWL_EMAC_BIT_MAC_CSR6_SF BIT(21) /* Store and forward */
  65. #define OWL_EMAC_MSK_MAC_CSR6_SPEED GENMASK(17, 16) /* Eth speed selection */
  66. #define OWL_EMAC_OFF_MAC_CSR6_SPEED 16
  67. #define OWL_EMAC_VAL_MAC_CSR6_SPEED_100M 0x00
  68. #define OWL_EMAC_VAL_MAC_CSR6_SPEED_10M 0x02
  69. #define OWL_EMAC_BIT_MAC_CSR6_ST BIT(13) /* Start/stop transmit command */
  70. #define OWL_EMAC_BIT_MAC_CSR6_LP BIT(10) /* Loopback mode */
  71. #define OWL_EMAC_BIT_MAC_CSR6_FD BIT(9) /* Full duplex mode */
  72. #define OWL_EMAC_BIT_MAC_CSR6_PM BIT(7) /* Pass all multicast */
  73. #define OWL_EMAC_BIT_MAC_CSR6_PR BIT(6) /* Promiscuous mode */
  74. #define OWL_EMAC_BIT_MAC_CSR6_IF BIT(4) /* Inverse filtering */
  75. #define OWL_EMAC_BIT_MAC_CSR6_PB BIT(3) /* Pass bad frames */
  76. #define OWL_EMAC_BIT_MAC_CSR6_HO BIT(2) /* Hash only filtering mode */
  77. #define OWL_EMAC_BIT_MAC_CSR6_SR BIT(1) /* Start/stop receive command */
  78. #define OWL_EMAC_BIT_MAC_CSR6_HP BIT(0) /* Hash/perfect receive filtering mode */
  79. #define OWL_EMAC_MSK_MAC_CSR6_STSR (OWL_EMAC_BIT_MAC_CSR6_ST | \
  80. OWL_EMAC_BIT_MAC_CSR6_SR)
  81. /* Interrupt enable register */
  82. #define OWL_EMAC_REG_MAC_CSR7 0x0038
  83. #define OWL_EMAC_BIT_MAC_CSR7_NIE BIT(16) /* Normal interrupt summary enable */
  84. #define OWL_EMAC_BIT_MAC_CSR7_AIE BIT(15) /* Abnormal interrupt summary enable */
  85. #define OWL_EMAC_BIT_MAC_CSR7_ERE BIT(14) /* Early receive interrupt enable */
  86. #define OWL_EMAC_BIT_MAC_CSR7_GTE BIT(11) /* General-purpose timer overflow */
  87. #define OWL_EMAC_BIT_MAC_CSR7_ETE BIT(10) /* Early transmit interrupt enable */
  88. #define OWL_EMAC_BIT_MAC_CSR7_RSE BIT(8) /* Receive stopped enable */
  89. #define OWL_EMAC_BIT_MAC_CSR7_RUE BIT(7) /* Receive buffer unavailable enable */
  90. #define OWL_EMAC_BIT_MAC_CSR7_RIE BIT(6) /* Receive interrupt enable */
  91. #define OWL_EMAC_BIT_MAC_CSR7_UNE BIT(5) /* Underflow interrupt enable */
  92. #define OWL_EMAC_BIT_MAC_CSR7_TUE BIT(2) /* Transmit buffer unavailable enable */
  93. #define OWL_EMAC_BIT_MAC_CSR7_TSE BIT(1) /* Transmit stopped enable */
  94. #define OWL_EMAC_BIT_MAC_CSR7_TIE BIT(0) /* Transmit interrupt enable */
  95. #define OWL_EMAC_BIT_MAC_CSR7_ALL_NOT_TUE (OWL_EMAC_BIT_MAC_CSR7_ERE | \
  96. OWL_EMAC_BIT_MAC_CSR7_GTE | \
  97. OWL_EMAC_BIT_MAC_CSR7_ETE | \
  98. OWL_EMAC_BIT_MAC_CSR7_RSE | \
  99. OWL_EMAC_BIT_MAC_CSR7_RUE | \
  100. OWL_EMAC_BIT_MAC_CSR7_RIE | \
  101. OWL_EMAC_BIT_MAC_CSR7_UNE | \
  102. OWL_EMAC_BIT_MAC_CSR7_TSE | \
  103. OWL_EMAC_BIT_MAC_CSR7_TIE)
  104. /* Missed frames and overflow counter register */
  105. #define OWL_EMAC_REG_MAC_CSR8 0x0040
  106. /* MII management and serial ROM register */
  107. #define OWL_EMAC_REG_MAC_CSR9 0x0048
  108. /* MII serial management register */
  109. #define OWL_EMAC_REG_MAC_CSR10 0x0050
  110. #define OWL_EMAC_BIT_MAC_CSR10_SB BIT(31) /* Start transfer or busy */
  111. #define OWL_EMAC_MSK_MAC_CSR10_CLKDIV GENMASK(30, 28) /* Clock divider */
  112. #define OWL_EMAC_OFF_MAC_CSR10_CLKDIV 28
  113. #define OWL_EMAC_VAL_MAC_CSR10_CLKDIV_128 0x04
  114. #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_WR 0x01 /* Register write command */
  115. #define OWL_EMAC_OFF_MAC_CSR10_OPCODE 26 /* Operation mode */
  116. #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_DCG 0x00 /* Disable clock generation */
  117. #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_WR 0x01 /* Register write command */
  118. #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_RD 0x02 /* Register read command */
  119. #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_CDS 0x03 /* Clock divider set */
  120. #define OWL_EMAC_MSK_MAC_CSR10_PHYADD GENMASK(25, 21) /* Physical layer address */
  121. #define OWL_EMAC_OFF_MAC_CSR10_PHYADD 21
  122. #define OWL_EMAC_MSK_MAC_CSR10_REGADD GENMASK(20, 16) /* Register address */
  123. #define OWL_EMAC_OFF_MAC_CSR10_REGADD 16
  124. #define OWL_EMAC_MSK_MAC_CSR10_DATA GENMASK(15, 0) /* Register data */
  125. /* General-purpose timer and interrupt mitigation control register */
  126. #define OWL_EMAC_REG_MAC_CSR11 0x0058
  127. #define OWL_EMAC_OFF_MAC_CSR11_TT 27 /* Transmit timer */
  128. #define OWL_EMAC_OFF_MAC_CSR11_NTP 24 /* No. of transmit packets */
  129. #define OWL_EMAC_OFF_MAC_CSR11_RT 20 /* Receive timer */
  130. #define OWL_EMAC_OFF_MAC_CSR11_NRP 17 /* No. of receive packets */
  131. /* MAC address low/high registers */
  132. #define OWL_EMAC_REG_MAC_CSR16 0x0080
  133. #define OWL_EMAC_REG_MAC_CSR17 0x0088
  134. /* Pause time & cache thresholds register */
  135. #define OWL_EMAC_REG_MAC_CSR18 0x0090
  136. #define OWL_EMAC_OFF_MAC_CSR18_CPTL 24 /* Cache pause threshold level */
  137. #define OWL_EMAC_OFF_MAC_CSR18_CRTL 16 /* Cache restart threshold level */
  138. #define OWL_EMAC_OFF_MAC_CSR18_PQT 0 /* Flow control pause quanta time */
  139. /* FIFO pause & restart threshold register */
  140. #define OWL_EMAC_REG_MAC_CSR19 0x0098
  141. #define OWL_EMAC_OFF_MAC_CSR19_FPTL 16 /* FIFO pause threshold level */
  142. #define OWL_EMAC_OFF_MAC_CSR19_FRTL 0 /* FIFO restart threshold level */
  143. /* Flow control setup & status register */
  144. #define OWL_EMAC_REG_MAC_CSR20 0x00A0
  145. #define OWL_EMAC_BIT_MAC_CSR20_FCE BIT(31) /* Flow Control Enable */
  146. #define OWL_EMAC_BIT_MAC_CSR20_TUE BIT(30) /* Transmit Un-pause frames Enable */
  147. #define OWL_EMAC_BIT_MAC_CSR20_TPE BIT(29) /* Transmit Pause frames Enable */
  148. #define OWL_EMAC_BIT_MAC_CSR20_RPE BIT(28) /* Receive Pause frames Enable */
  149. #define OWL_EMAC_BIT_MAC_CSR20_BPE BIT(27) /* Back pressure (half-duplex) Enable */
  150. /* MII control register */
  151. #define OWL_EMAC_REG_MAC_CTRL 0x00B0
  152. #define OWL_EMAC_BIT_MAC_CTRL_RRSB BIT(8) /* RMII_REFCLK select bit */
  153. #define OWL_EMAC_OFF_MAC_CTRL_SSDC 4 /* SMII SYNC delay cycle */
  154. #define OWL_EMAC_BIT_MAC_CTRL_RCPS BIT(1) /* REF_CLK phase select */
  155. #define OWL_EMAC_BIT_MAC_CTRL_RSIS BIT(0) /* RMII/SMII interface select */
  156. /* Receive descriptor status field */
  157. #define OWL_EMAC_BIT_RDES0_OWN BIT(31) /* Ownership bit */
  158. #define OWL_EMAC_BIT_RDES0_FF BIT(30) /* Filtering fail */
  159. #define OWL_EMAC_MSK_RDES0_FL GENMASK(29, 16) /* Frame length */
  160. #define OWL_EMAC_OFF_RDES0_FL 16
  161. #define OWL_EMAC_BIT_RDES0_ES BIT(15) /* Error summary */
  162. #define OWL_EMAC_BIT_RDES0_DE BIT(14) /* Descriptor error */
  163. #define OWL_EMAC_BIT_RDES0_RF BIT(11) /* Runt frame */
  164. #define OWL_EMAC_BIT_RDES0_MF BIT(10) /* Multicast frame */
  165. #define OWL_EMAC_BIT_RDES0_FS BIT(9) /* First descriptor */
  166. #define OWL_EMAC_BIT_RDES0_LS BIT(8) /* Last descriptor */
  167. #define OWL_EMAC_BIT_RDES0_TL BIT(7) /* Frame too long */
  168. #define OWL_EMAC_BIT_RDES0_CS BIT(6) /* Collision seen */
  169. #define OWL_EMAC_BIT_RDES0_FT BIT(5) /* Frame type */
  170. #define OWL_EMAC_BIT_RDES0_RE BIT(3) /* Report on MII error */
  171. #define OWL_EMAC_BIT_RDES0_DB BIT(2) /* Dribbling bit */
  172. #define OWL_EMAC_BIT_RDES0_CE BIT(1) /* CRC error */
  173. #define OWL_EMAC_BIT_RDES0_ZERO BIT(0) /* Legal frame length indicator */
  174. /* Receive descriptor control and count field */
  175. #define OWL_EMAC_BIT_RDES1_RER BIT(25) /* Receive end of ring */
  176. #define OWL_EMAC_MSK_RDES1_RBS1 GENMASK(10, 0) /* Buffer 1 size */
  177. /* Transmit descriptor status field */
  178. #define OWL_EMAC_BIT_TDES0_OWN BIT(31) /* Ownership bit */
  179. #define OWL_EMAC_BIT_TDES0_ES BIT(15) /* Error summary */
  180. #define OWL_EMAC_BIT_TDES0_LO BIT(11) /* Loss of carrier */
  181. #define OWL_EMAC_BIT_TDES0_NC BIT(10) /* No carrier */
  182. #define OWL_EMAC_BIT_TDES0_LC BIT(9) /* Late collision */
  183. #define OWL_EMAC_BIT_TDES0_EC BIT(8) /* Excessive collisions */
  184. #define OWL_EMAC_MSK_TDES0_CC GENMASK(6, 3) /* Collision count */
  185. #define OWL_EMAC_BIT_TDES0_UF BIT(1) /* Underflow error */
  186. #define OWL_EMAC_BIT_TDES0_DE BIT(0) /* Deferred */
  187. /* Transmit descriptor control and count field */
  188. #define OWL_EMAC_BIT_TDES1_IC BIT(31) /* Interrupt on completion */
  189. #define OWL_EMAC_BIT_TDES1_LS BIT(30) /* Last descriptor */
  190. #define OWL_EMAC_BIT_TDES1_FS BIT(29) /* First descriptor */
  191. #define OWL_EMAC_BIT_TDES1_FT1 BIT(28) /* Filtering type */
  192. #define OWL_EMAC_BIT_TDES1_SET BIT(27) /* Setup packet */
  193. #define OWL_EMAC_BIT_TDES1_AC BIT(26) /* Add CRC disable */
  194. #define OWL_EMAC_BIT_TDES1_TER BIT(25) /* Transmit end of ring */
  195. #define OWL_EMAC_BIT_TDES1_DPD BIT(23) /* Disabled padding */
  196. #define OWL_EMAC_BIT_TDES1_FT0 BIT(22) /* Filtering type */
  197. #define OWL_EMAC_MSK_TDES1_TBS1 GENMASK(10, 0) /* Buffer 1 size */
  198. static const char *const owl_emac_clk_names[] = { "eth", "rmii" };
  199. #define OWL_EMAC_NCLKS ARRAY_SIZE(owl_emac_clk_names)
  200. enum owl_emac_clk_map {
  201. OWL_EMAC_CLK_ETH = 0,
  202. OWL_EMAC_CLK_RMII
  203. };
  204. struct owl_emac_addr_list {
  205. u8 addrs[OWL_EMAC_MAX_MULTICAST_ADDRS][ETH_ALEN];
  206. int count;
  207. };
  208. /* TX/RX descriptors */
  209. struct owl_emac_ring_desc {
  210. u32 status;
  211. u32 control;
  212. u32 buf_addr;
  213. u32 reserved; /* 2nd buffer address is not used */
  214. };
  215. struct owl_emac_ring {
  216. struct owl_emac_ring_desc *descs;
  217. dma_addr_t descs_dma;
  218. struct sk_buff **skbs;
  219. dma_addr_t *skbs_dma;
  220. unsigned int size;
  221. unsigned int head;
  222. unsigned int tail;
  223. };
  224. struct owl_emac_priv {
  225. struct net_device *netdev;
  226. void __iomem *base;
  227. struct clk_bulk_data clks[OWL_EMAC_NCLKS];
  228. struct reset_control *reset;
  229. struct owl_emac_ring rx_ring;
  230. struct owl_emac_ring tx_ring;
  231. struct mii_bus *mii;
  232. struct napi_struct napi;
  233. phy_interface_t phy_mode;
  234. unsigned int link;
  235. int speed;
  236. int duplex;
  237. int pause;
  238. struct owl_emac_addr_list mcaddr_list;
  239. struct work_struct mac_reset_task;
  240. u32 msg_enable; /* Debug message level */
  241. spinlock_t lock; /* Sync concurrent ring access */
  242. };
  243. #endif /* __OWL_EMAC_H__ */