bcmgenet.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2014-2025 Broadcom
  4. */
  5. #ifndef __BCMGENET_H__
  6. #define __BCMGENET_H__
  7. #include <linux/skbuff.h>
  8. #include <linux/netdevice.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/clk.h>
  11. #include <linux/mii.h>
  12. #include <linux/if_vlan.h>
  13. #include <linux/phy.h>
  14. #include <linux/dim.h>
  15. #include <linux/ethtool.h>
  16. #include "../unimac.h"
  17. /* Maximum number of hardware queues, downsized if needed */
  18. #define GENET_MAX_MQ_CNT 4
  19. /* total number of Buffer Descriptors, same for Rx/Tx */
  20. #define TOTAL_DESC 256
  21. /* which ring is descriptor based */
  22. #define DESC_INDEX 16
  23. /* Body(1500) + EH_SIZE(14) + VLANTAG(4) + BRCMTAG(6) + FCS(4) = 1528.
  24. * 1536 is multiple of 256 bytes
  25. */
  26. #define ENET_BRCM_TAG_LEN 6
  27. #define ENET_PAD 8
  28. #define ENET_MAX_MTU_SIZE (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
  29. ENET_BRCM_TAG_LEN + ETH_FCS_LEN + ENET_PAD)
  30. #define DMA_MAX_BURST_LENGTH 0x10
  31. /* misc. configuration */
  32. #define MAX_NUM_OF_FS_RULES 16
  33. #define CLEAR_ALL_HFB 0xFF
  34. #define DMA_FC_THRESH_HI (TOTAL_DESC >> 4)
  35. #define DMA_FC_THRESH_LO 5
  36. /* 64B receive/transmit status block */
  37. struct status_64 {
  38. u32 length_status; /* length and peripheral status */
  39. u32 ext_status; /* Extended status*/
  40. u32 rx_csum; /* partial rx checksum */
  41. u32 unused1[9]; /* unused */
  42. u32 tx_csum_info; /* Tx checksum info. */
  43. u32 unused2[3]; /* unused */
  44. };
  45. /* Rx status bits */
  46. #define STATUS_RX_EXT_MASK 0x1FFFFF
  47. #define STATUS_RX_CSUM_MASK 0xFFFF
  48. #define STATUS_RX_CSUM_OK 0x10000
  49. #define STATUS_RX_CSUM_FR 0x20000
  50. #define STATUS_RX_PROTO_TCP 0
  51. #define STATUS_RX_PROTO_UDP 1
  52. #define STATUS_RX_PROTO_ICMP 2
  53. #define STATUS_RX_PROTO_OTHER 3
  54. #define STATUS_RX_PROTO_MASK 3
  55. #define STATUS_RX_PROTO_SHIFT 18
  56. #define STATUS_FILTER_INDEX_MASK 0xFFFF
  57. /* Tx status bits */
  58. #define STATUS_TX_CSUM_START_MASK 0X7FFF
  59. #define STATUS_TX_CSUM_START_SHIFT 16
  60. #define STATUS_TX_CSUM_PROTO_UDP 0x8000
  61. #define STATUS_TX_CSUM_OFFSET_MASK 0x7FFF
  62. #define STATUS_TX_CSUM_LV 0x80000000
  63. /* DMA Descriptor */
  64. #define DMA_DESC_LENGTH_STATUS 0x00 /* in bytes of data in buffer */
  65. #define DMA_DESC_ADDRESS_LO 0x04 /* lower bits of PA */
  66. #define DMA_DESC_ADDRESS_HI 0x08 /* upper 32 bits of PA, GENETv4+ */
  67. /* Rx/Tx common counter group */
  68. struct bcmgenet_pkt_counters {
  69. u32 cnt_64; /* RO Received/Transmited 64 bytes packet */
  70. u32 cnt_127; /* RO Rx/Tx 127 bytes packet */
  71. u32 cnt_255; /* RO Rx/Tx 65-255 bytes packet */
  72. u32 cnt_511; /* RO Rx/Tx 256-511 bytes packet */
  73. u32 cnt_1023; /* RO Rx/Tx 512-1023 bytes packet */
  74. u32 cnt_1518; /* RO Rx/Tx 1024-1518 bytes packet */
  75. u32 cnt_mgv; /* RO Rx/Tx 1519-1522 good VLAN packet */
  76. u32 cnt_2047; /* RO Rx/Tx 1522-2047 bytes packet*/
  77. u32 cnt_4095; /* RO Rx/Tx 2048-4095 bytes packet*/
  78. u32 cnt_9216; /* RO Rx/Tx 4096-9216 bytes packet*/
  79. };
  80. /* RSV, Receive Status Vector */
  81. struct bcmgenet_rx_counters {
  82. struct bcmgenet_pkt_counters pkt_cnt;
  83. u32 pkt; /* RO (0x428) Received pkt count*/
  84. u32 bytes; /* RO Received byte count */
  85. u32 mca; /* RO # of Received multicast pkt */
  86. u32 bca; /* RO # of Receive broadcast pkt */
  87. u32 fcs; /* RO # of Received FCS error */
  88. u32 cf; /* RO # of Received control frame pkt*/
  89. u32 pf; /* RO # of Received pause frame pkt */
  90. u32 uo; /* RO # of unknown op code pkt */
  91. u32 aln; /* RO # of alignment error count */
  92. u32 flr; /* RO # of frame length out of range count */
  93. u32 cde; /* RO # of code error pkt */
  94. u32 fcr; /* RO # of carrier sense error pkt */
  95. u32 ovr; /* RO # of oversize pkt*/
  96. u32 jbr; /* RO # of jabber count */
  97. u32 mtue; /* RO # of MTU error pkt*/
  98. u32 pok; /* RO # of Received good pkt */
  99. u32 uc; /* RO # of unicast pkt */
  100. u32 ppp; /* RO # of PPP pkt */
  101. u32 rcrc; /* RO (0x470),# of CRC match pkt */
  102. };
  103. /* TSV, Transmit Status Vector */
  104. struct bcmgenet_tx_counters {
  105. struct bcmgenet_pkt_counters pkt_cnt;
  106. u32 pkts; /* RO (0x4a8) Transmited pkt */
  107. u32 mca; /* RO # of xmited multicast pkt */
  108. u32 bca; /* RO # of xmited broadcast pkt */
  109. u32 pf; /* RO # of xmited pause frame count */
  110. u32 cf; /* RO # of xmited control frame count */
  111. u32 fcs; /* RO # of xmited FCS error count */
  112. u32 ovr; /* RO # of xmited oversize pkt */
  113. u32 drf; /* RO # of xmited deferral pkt */
  114. u32 edf; /* RO # of xmited Excessive deferral pkt*/
  115. u32 scl; /* RO # of xmited single collision pkt */
  116. u32 mcl; /* RO # of xmited multiple collision pkt*/
  117. u32 lcl; /* RO # of xmited late collision pkt */
  118. u32 ecl; /* RO # of xmited excessive collision pkt*/
  119. u32 frg; /* RO # of xmited fragments pkt*/
  120. u32 ncl; /* RO # of xmited total collision count */
  121. u32 jbr; /* RO # of xmited jabber count*/
  122. u32 bytes; /* RO # of xmited byte count */
  123. u32 pok; /* RO # of xmited good pkt */
  124. u32 uc; /* RO (0x0x4f0)# of xmited unitcast pkt */
  125. };
  126. struct bcmgenet_mib_counters {
  127. struct bcmgenet_rx_counters rx;
  128. struct bcmgenet_tx_counters tx;
  129. u32 rx_runt_cnt;
  130. u32 rx_runt_fcs;
  131. u32 rx_runt_fcs_align;
  132. u32 rx_runt_bytes;
  133. u32 rbuf_ovflow_cnt;
  134. u32 rbuf_err_cnt;
  135. u32 mdf_err_cnt;
  136. u32 alloc_rx_buff_failed;
  137. u32 rx_dma_failed;
  138. u32 tx_dma_failed;
  139. u32 tx_realloc_tsb;
  140. u32 tx_realloc_tsb_failed;
  141. };
  142. struct bcmgenet_tx_stats64 {
  143. struct u64_stats_sync syncp;
  144. u64_stats_t packets;
  145. u64_stats_t bytes;
  146. u64_stats_t errors;
  147. u64_stats_t dropped;
  148. };
  149. struct bcmgenet_rx_stats64 {
  150. struct u64_stats_sync syncp;
  151. u64_stats_t bytes;
  152. u64_stats_t packets;
  153. u64_stats_t errors;
  154. u64_stats_t dropped;
  155. u64_stats_t multicast;
  156. u64_stats_t broadcast;
  157. u64_stats_t missed;
  158. u64_stats_t length_errors;
  159. u64_stats_t over_errors;
  160. u64_stats_t crc_errors;
  161. u64_stats_t frame_errors;
  162. u64_stats_t fragmented_errors;
  163. };
  164. #define UMAC_MIB_START 0x400
  165. #define UMAC_MDIO_CMD 0x614
  166. #define MDIO_START_BUSY (1 << 29)
  167. #define MDIO_READ_FAIL (1 << 28)
  168. #define MDIO_RD (2 << 26)
  169. #define MDIO_WR (1 << 26)
  170. #define MDIO_PMD_SHIFT 21
  171. #define MDIO_PMD_MASK 0x1F
  172. #define MDIO_REG_SHIFT 16
  173. #define MDIO_REG_MASK 0x1F
  174. #define UMAC_RBUF_OVFL_CNT_V1 0x61C
  175. #define RBUF_OVFL_CNT_V2 0x80
  176. #define RBUF_OVFL_CNT_V3PLUS 0x94
  177. #define UMAC_MPD_CTRL 0x620
  178. #define MPD_EN (1 << 0)
  179. #define MPD_PW_EN (1 << 27)
  180. #define MPD_MSEQ_LEN_SHIFT 16
  181. #define MPD_MSEQ_LEN_MASK 0xFF
  182. #define UMAC_MPD_PW_MS 0x624
  183. #define UMAC_MPD_PW_LS 0x628
  184. #define UMAC_RBUF_ERR_CNT_V1 0x634
  185. #define RBUF_ERR_CNT_V2 0x84
  186. #define RBUF_ERR_CNT_V3PLUS 0x98
  187. #define UMAC_MDF_ERR_CNT 0x638
  188. #define UMAC_MDF_CTRL 0x650
  189. #define UMAC_MDF_ADDR 0x654
  190. #define UMAC_MIB_CTRL 0x580
  191. #define MIB_RESET_RX (1 << 0)
  192. #define MIB_RESET_RUNT (1 << 1)
  193. #define MIB_RESET_TX (1 << 2)
  194. #define RBUF_CTRL 0x00
  195. #define RBUF_64B_EN (1 << 0)
  196. #define RBUF_ALIGN_2B (1 << 1)
  197. #define RBUF_BAD_DIS (1 << 2)
  198. #define RBUF_STATUS 0x0C
  199. #define RBUF_STATUS_WOL (1 << 0)
  200. #define RBUF_STATUS_MPD_INTR_ACTIVE (1 << 1)
  201. #define RBUF_STATUS_ACPI_INTR_ACTIVE (1 << 2)
  202. #define RBUF_CHK_CTRL 0x14
  203. #define RBUF_RXCHK_EN (1 << 0)
  204. #define RBUF_SKIP_FCS (1 << 4)
  205. #define RBUF_L3_PARSE_DIS (1 << 5)
  206. #define RBUF_ENERGY_CTRL 0x9c
  207. #define RBUF_EEE_EN (1 << 0)
  208. #define RBUF_PM_EN (1 << 1)
  209. #define RBUF_TBUF_SIZE_CTRL 0xb4
  210. #define RBUF_HFB_CTRL_V1 0x38
  211. #define RBUF_HFB_FILTER_EN_SHIFT 16
  212. #define RBUF_HFB_FILTER_EN_MASK 0xffff0000
  213. #define RBUF_HFB_EN (1 << 0)
  214. #define RBUF_HFB_256B (1 << 1)
  215. #define RBUF_ACPI_EN (1 << 2)
  216. #define RBUF_HFB_LEN_V1 0x3C
  217. #define RBUF_FLTR_LEN_MASK 0xFF
  218. #define RBUF_FLTR_LEN_SHIFT 8
  219. #define TBUF_CTRL 0x00
  220. #define TBUF_64B_EN (1 << 0)
  221. #define TBUF_BP_MC 0x0C
  222. #define TBUF_ENERGY_CTRL 0x14
  223. #define TBUF_EEE_EN (1 << 0)
  224. #define TBUF_PM_EN (1 << 1)
  225. #define TBUF_CTRL_V1 0x80
  226. #define TBUF_BP_MC_V1 0xA0
  227. #define HFB_CTRL 0x00
  228. #define HFB_FLT_ENABLE_V3PLUS 0x04
  229. #define HFB_FLT_LEN_V2 0x04
  230. #define HFB_FLT_LEN_V3PLUS 0x1C
  231. /* uniMac intrl2 registers */
  232. #define INTRL2_CPU_STAT 0x00
  233. #define INTRL2_CPU_SET 0x04
  234. #define INTRL2_CPU_CLEAR 0x08
  235. #define INTRL2_CPU_MASK_STATUS 0x0C
  236. #define INTRL2_CPU_MASK_SET 0x10
  237. #define INTRL2_CPU_MASK_CLEAR 0x14
  238. /* INTRL2 instance 0 definitions */
  239. #define UMAC_IRQ_SCB (1 << 0)
  240. #define UMAC_IRQ_EPHY (1 << 1)
  241. #define UMAC_IRQ_PHY_DET_R (1 << 2)
  242. #define UMAC_IRQ_PHY_DET_F (1 << 3)
  243. #define UMAC_IRQ_LINK_UP (1 << 4)
  244. #define UMAC_IRQ_LINK_DOWN (1 << 5)
  245. #define UMAC_IRQ_LINK_EVENT (UMAC_IRQ_LINK_UP | UMAC_IRQ_LINK_DOWN)
  246. #define UMAC_IRQ_UMAC (1 << 6)
  247. #define UMAC_IRQ_UMAC_TSV (1 << 7)
  248. #define UMAC_IRQ_TBUF_UNDERRUN (1 << 8)
  249. #define UMAC_IRQ_RBUF_OVERFLOW (1 << 9)
  250. #define UMAC_IRQ_HFB_SM (1 << 10)
  251. #define UMAC_IRQ_HFB_MM (1 << 11)
  252. #define UMAC_IRQ_MPD_R (1 << 12)
  253. #define UMAC_IRQ_WAKE_EVENT (UMAC_IRQ_HFB_SM | UMAC_IRQ_HFB_MM | \
  254. UMAC_IRQ_MPD_R)
  255. #define UMAC_IRQ_RXDMA_MBDONE (1 << 13)
  256. #define UMAC_IRQ_RXDMA_PDONE (1 << 14)
  257. #define UMAC_IRQ_RXDMA_BDONE (1 << 15)
  258. #define UMAC_IRQ_RXDMA_DONE UMAC_IRQ_RXDMA_MBDONE
  259. #define UMAC_IRQ_TXDMA_MBDONE (1 << 16)
  260. #define UMAC_IRQ_TXDMA_PDONE (1 << 17)
  261. #define UMAC_IRQ_TXDMA_BDONE (1 << 18)
  262. #define UMAC_IRQ_TXDMA_DONE UMAC_IRQ_TXDMA_MBDONE
  263. /* Only valid for GENETv3+ */
  264. #define UMAC_IRQ_MDIO_DONE (1 << 23)
  265. #define UMAC_IRQ_MDIO_ERROR (1 << 24)
  266. #define UMAC_IRQ_MDIO_EVENT (UMAC_IRQ_MDIO_DONE | \
  267. UMAC_IRQ_MDIO_ERROR)
  268. /* INTRL2 instance 1 definitions */
  269. #define UMAC_IRQ1_TX_INTR_MASK 0xFFFF
  270. #define UMAC_IRQ1_RX_INTR_MASK 0xFFFF
  271. #define UMAC_IRQ1_RX_INTR_SHIFT 16
  272. /* Register block offsets */
  273. #define GENET_SYS_OFF 0x0000
  274. #define GENET_GR_BRIDGE_OFF 0x0040
  275. #define GENET_EXT_OFF 0x0080
  276. #define GENET_INTRL2_0_OFF 0x0200
  277. #define GENET_INTRL2_1_OFF 0x0240
  278. #define GENET_RBUF_OFF 0x0300
  279. #define GENET_UMAC_OFF 0x0800
  280. /* SYS block offsets and register definitions */
  281. #define SYS_REV_CTRL 0x00
  282. #define SYS_PORT_CTRL 0x04
  283. #define PORT_MODE_INT_EPHY 0
  284. #define PORT_MODE_INT_GPHY 1
  285. #define PORT_MODE_EXT_EPHY 2
  286. #define PORT_MODE_EXT_GPHY 3
  287. #define PORT_MODE_EXT_RVMII_25 (4 | BIT(4))
  288. #define PORT_MODE_EXT_RVMII_50 4
  289. #define LED_ACT_SOURCE_MAC (1 << 9)
  290. #define SYS_RBUF_FLUSH_CTRL 0x08
  291. #define SYS_TBUF_FLUSH_CTRL 0x0C
  292. #define RBUF_FLUSH_CTRL_V1 0x04
  293. /* Ext block register offsets and definitions */
  294. #define EXT_EXT_PWR_MGMT 0x00
  295. #define EXT_PWR_DOWN_BIAS (1 << 0)
  296. #define EXT_PWR_DOWN_DLL (1 << 1)
  297. #define EXT_PWR_DOWN_PHY (1 << 2)
  298. #define EXT_PWR_DN_EN_LD (1 << 3)
  299. #define EXT_ENERGY_DET (1 << 4)
  300. #define EXT_IDDQ_FROM_PHY (1 << 5)
  301. #define EXT_IDDQ_GLBL_PWR (1 << 7)
  302. #define EXT_PHY_RESET (1 << 8)
  303. #define EXT_ENERGY_DET_MASK (1 << 12)
  304. #define EXT_PWR_DOWN_PHY_TX (1 << 16)
  305. #define EXT_PWR_DOWN_PHY_RX (1 << 17)
  306. #define EXT_PWR_DOWN_PHY_SD (1 << 18)
  307. #define EXT_PWR_DOWN_PHY_RD (1 << 19)
  308. #define EXT_PWR_DOWN_PHY_EN (1 << 20)
  309. #define EXT_RGMII_OOB_CTRL 0x0C
  310. #define RGMII_MODE_EN_V123 (1 << 0)
  311. #define RGMII_LINK (1 << 4)
  312. #define OOB_DISABLE (1 << 5)
  313. #define RGMII_MODE_EN (1 << 6)
  314. #define ID_MODE_DIS (1 << 16)
  315. #define EXT_GPHY_CTRL 0x1C
  316. #define EXT_CFG_IDDQ_BIAS (1 << 0)
  317. #define EXT_CFG_PWR_DOWN (1 << 1)
  318. #define EXT_CK25_DIS (1 << 4)
  319. #define EXT_CFG_IDDQ_GLOBAL_PWR (1 << 3)
  320. #define EXT_GPHY_RESET (1 << 5)
  321. /* DMA rings size */
  322. #define DMA_RING_SIZE (0x40)
  323. #define DMA_RINGS_SIZE (DMA_RING_SIZE * (DESC_INDEX + 1))
  324. /* DMA registers common definitions */
  325. #define DMA_RW_POINTER_MASK 0x1FF
  326. #define DMA_P_INDEX_DISCARD_CNT_MASK 0xFFFF
  327. #define DMA_P_INDEX_DISCARD_CNT_SHIFT 16
  328. #define DMA_BUFFER_DONE_CNT_MASK 0xFFFF
  329. #define DMA_BUFFER_DONE_CNT_SHIFT 16
  330. #define DMA_P_INDEX_MASK 0xFFFF
  331. #define DMA_C_INDEX_MASK 0xFFFF
  332. /* DMA ring size register */
  333. #define DMA_RING_SIZE_MASK 0xFFFF
  334. #define DMA_RING_SIZE_SHIFT 16
  335. #define DMA_RING_BUFFER_SIZE_MASK 0xFFFF
  336. /* DMA interrupt threshold register */
  337. #define DMA_INTR_THRESHOLD_MASK 0x01FF
  338. /* DMA XON/XOFF register */
  339. #define DMA_XON_THREHOLD_MASK 0xFFFF
  340. #define DMA_XOFF_THRESHOLD_MASK 0xFFFF
  341. #define DMA_XOFF_THRESHOLD_SHIFT 16
  342. /* DMA flow period register */
  343. #define DMA_FLOW_PERIOD_MASK 0xFFFF
  344. #define DMA_MAX_PKT_SIZE_MASK 0xFFFF
  345. #define DMA_MAX_PKT_SIZE_SHIFT 16
  346. /* DMA control register */
  347. #define DMA_EN (1 << 0)
  348. #define DMA_RING_BUF_EN_SHIFT 0x01
  349. #define DMA_RING_BUF_EN_MASK 0xFFFF
  350. #define DMA_TSB_SWAP_EN (1 << 20)
  351. /* DMA status register */
  352. #define DMA_DISABLED (1 << 0)
  353. #define DMA_DESC_RAM_INIT_BUSY (1 << 1)
  354. /* DMA SCB burst size register */
  355. #define DMA_SCB_BURST_SIZE_MASK 0x1F
  356. /* DMA activity vector register */
  357. #define DMA_ACTIVITY_VECTOR_MASK 0x1FFFF
  358. /* DMA backpressure mask register */
  359. #define DMA_BACKPRESSURE_MASK 0x1FFFF
  360. #define DMA_PFC_ENABLE (1 << 31)
  361. /* DMA backpressure status register */
  362. #define DMA_BACKPRESSURE_STATUS_MASK 0x1FFFF
  363. /* DMA override register */
  364. #define DMA_LITTLE_ENDIAN_MODE (1 << 0)
  365. #define DMA_REGISTER_MODE (1 << 1)
  366. /* DMA timeout register */
  367. #define DMA_TIMEOUT_MASK 0xFFFF
  368. #define DMA_TIMEOUT_VAL 5000 /* micro seconds */
  369. /* TDMA rate limiting control register */
  370. #define DMA_RATE_LIMIT_EN_MASK 0xFFFF
  371. /* TDMA arbitration control register */
  372. #define DMA_ARBITER_MODE_MASK 0x03
  373. #define DMA_RING_BUF_PRIORITY_MASK 0x1F
  374. #define DMA_RING_BUF_PRIORITY_SHIFT 5
  375. #define DMA_PRIO_REG_INDEX(q) ((q) / 6)
  376. #define DMA_PRIO_REG_SHIFT(q) (((q) % 6) * DMA_RING_BUF_PRIORITY_SHIFT)
  377. #define DMA_RATE_ADJ_MASK 0xFF
  378. /* Tx/Rx Dma Descriptor common bits*/
  379. #define DMA_BUFLENGTH_MASK 0x0fff
  380. #define DMA_BUFLENGTH_SHIFT 16
  381. #define DMA_OWN 0x8000
  382. #define DMA_EOP 0x4000
  383. #define DMA_SOP 0x2000
  384. #define DMA_WRAP 0x1000
  385. /* Tx specific Dma descriptor bits */
  386. #define DMA_TX_UNDERRUN 0x0200
  387. #define DMA_TX_APPEND_CRC 0x0040
  388. #define DMA_TX_OW_CRC 0x0020
  389. #define DMA_TX_DO_CSUM 0x0010
  390. #define DMA_TX_QTAG_SHIFT 7
  391. /* Rx Specific Dma descriptor bits */
  392. #define DMA_RX_CHK_V3PLUS 0x8000
  393. #define DMA_RX_CHK_V12 0x1000
  394. #define DMA_RX_BRDCAST 0x0040
  395. #define DMA_RX_MULT 0x0020
  396. #define DMA_RX_LG 0x0010
  397. #define DMA_RX_NO 0x0008
  398. #define DMA_RX_RXER 0x0004
  399. #define DMA_RX_CRC_ERROR 0x0002
  400. #define DMA_RX_OV 0x0001
  401. #define DMA_RX_FI_MASK 0x001F
  402. #define DMA_RX_FI_SHIFT 0x0007
  403. #define DMA_DESC_ALLOC_MASK 0x00FF
  404. #define DMA_ARBITER_RR 0x00
  405. #define DMA_ARBITER_WRR 0x01
  406. #define DMA_ARBITER_SP 0x02
  407. struct enet_cb {
  408. struct sk_buff *skb;
  409. void __iomem *bd_addr;
  410. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  411. DEFINE_DMA_UNMAP_LEN(dma_len);
  412. };
  413. /* power management mode */
  414. enum bcmgenet_power_mode {
  415. GENET_POWER_CABLE_SENSE = 0,
  416. GENET_POWER_PASSIVE,
  417. GENET_POWER_WOL_MAGIC,
  418. };
  419. struct bcmgenet_priv;
  420. /* We support both runtime GENET detection and compile-time
  421. * to optimize code-paths for a given hardware
  422. */
  423. enum bcmgenet_version {
  424. GENET_V1 = 1,
  425. GENET_V2,
  426. GENET_V3,
  427. GENET_V4,
  428. GENET_V5
  429. };
  430. #define GENET_IS_V1(p) ((p)->version == GENET_V1)
  431. #define GENET_IS_V2(p) ((p)->version == GENET_V2)
  432. #define GENET_IS_V3(p) ((p)->version == GENET_V3)
  433. #define GENET_IS_V4(p) ((p)->version == GENET_V4)
  434. #define GENET_IS_V5(p) ((p)->version == GENET_V5)
  435. /* Hardware flags */
  436. #define GENET_HAS_40BITS (1 << 0)
  437. #define GENET_HAS_EXT (1 << 1)
  438. #define GENET_HAS_MDIO_INTR (1 << 2)
  439. #define GENET_HAS_MOCA_LINK_DET (1 << 3)
  440. #define GENET_HAS_EPHY_16NM (1 << 4)
  441. /* BCMGENET hardware parameters, keep this structure nicely aligned
  442. * since it is going to be used in hot paths
  443. */
  444. struct bcmgenet_hw_params {
  445. u8 tx_queues;
  446. u8 tx_bds_per_q;
  447. u8 rx_queues;
  448. u8 rx_bds_per_q;
  449. u8 bp_in_en_shift;
  450. u32 bp_in_mask;
  451. u8 hfb_filter_cnt;
  452. u8 hfb_filter_size;
  453. u8 qtag_mask;
  454. u16 tbuf_offset;
  455. u32 hfb_offset;
  456. u32 hfb_reg_offset;
  457. u32 rdma_offset;
  458. u32 tdma_offset;
  459. u32 words_per_bd;
  460. };
  461. struct bcmgenet_skb_cb {
  462. struct enet_cb *first_cb; /* First control block of SKB */
  463. struct enet_cb *last_cb; /* Last control block of SKB */
  464. unsigned int bytes_sent; /* bytes on the wire (no TSB) */
  465. };
  466. #define GENET_CB(skb) ((struct bcmgenet_skb_cb *)((skb)->cb))
  467. struct bcmgenet_tx_ring {
  468. spinlock_t lock; /* ring lock */
  469. struct napi_struct napi; /* NAPI per tx queue */
  470. struct bcmgenet_tx_stats64 stats64;
  471. unsigned int index; /* ring index */
  472. struct enet_cb *cbs; /* tx ring buffer control block*/
  473. unsigned int size; /* size of each tx ring */
  474. unsigned int clean_ptr; /* Tx ring clean pointer */
  475. unsigned int c_index; /* last consumer index of each ring*/
  476. unsigned int free_bds; /* # of free bds for each ring */
  477. unsigned int write_ptr; /* Tx ring write pointer SW copy */
  478. unsigned int prod_index; /* Tx ring producer index SW copy */
  479. unsigned int cb_ptr; /* Tx ring initial CB ptr */
  480. unsigned int end_ptr; /* Tx ring end CB ptr */
  481. struct bcmgenet_priv *priv;
  482. };
  483. struct bcmgenet_net_dim {
  484. u16 use_dim;
  485. u16 event_ctr;
  486. unsigned long packets;
  487. unsigned long bytes;
  488. struct dim dim;
  489. };
  490. struct bcmgenet_rx_ring {
  491. struct napi_struct napi; /* Rx NAPI struct */
  492. struct bcmgenet_rx_stats64 stats64;
  493. unsigned int index; /* Rx ring index */
  494. struct enet_cb *cbs; /* Rx ring buffer control block */
  495. unsigned int size; /* Rx ring size */
  496. unsigned int c_index; /* Rx last consumer index */
  497. unsigned int read_ptr; /* Rx ring read pointer */
  498. unsigned int cb_ptr; /* Rx ring initial CB ptr */
  499. unsigned int end_ptr; /* Rx ring end CB ptr */
  500. unsigned int old_discards;
  501. struct bcmgenet_net_dim dim;
  502. u32 rx_max_coalesced_frames;
  503. u32 rx_coalesce_usecs;
  504. struct bcmgenet_priv *priv;
  505. };
  506. enum bcmgenet_rxnfc_state {
  507. BCMGENET_RXNFC_STATE_UNUSED = 0,
  508. BCMGENET_RXNFC_STATE_DISABLED,
  509. BCMGENET_RXNFC_STATE_ENABLED
  510. };
  511. struct bcmgenet_rxnfc_rule {
  512. struct list_head list;
  513. struct ethtool_rx_flow_spec fs;
  514. enum bcmgenet_rxnfc_state state;
  515. };
  516. /* device context */
  517. struct bcmgenet_priv {
  518. void __iomem *base;
  519. /* reg_lock: lock to serialize access to shared registers */
  520. spinlock_t reg_lock;
  521. enum bcmgenet_version version;
  522. struct net_device *dev;
  523. /* transmit variables */
  524. void __iomem *tx_bds;
  525. struct enet_cb *tx_cbs;
  526. unsigned int num_tx_bds;
  527. struct bcmgenet_tx_ring tx_rings[GENET_MAX_MQ_CNT + 1];
  528. /* receive variables */
  529. void __iomem *rx_bds;
  530. struct enet_cb *rx_cbs;
  531. unsigned int num_rx_bds;
  532. unsigned int rx_buf_len;
  533. struct bcmgenet_rxnfc_rule rxnfc_rules[MAX_NUM_OF_FS_RULES];
  534. struct list_head rxnfc_list;
  535. struct bcmgenet_rx_ring rx_rings[GENET_MAX_MQ_CNT + 1];
  536. /* other misc variables */
  537. const struct bcmgenet_hw_params *hw_params;
  538. u32 flags;
  539. unsigned autoneg_pause:1;
  540. unsigned tx_pause:1;
  541. unsigned rx_pause:1;
  542. /* MDIO bus variables */
  543. wait_queue_head_t wq;
  544. bool internal_phy;
  545. struct device_node *phy_dn;
  546. struct device_node *mdio_dn;
  547. struct mii_bus *mii_bus;
  548. u16 gphy_rev;
  549. struct clk *clk_eee;
  550. bool clk_eee_enabled;
  551. /* PHY device variables */
  552. phy_interface_t phy_interface;
  553. int phy_addr;
  554. int ext_phy;
  555. /* Interrupt variables */
  556. struct work_struct bcmgenet_irq_work;
  557. int irq0;
  558. int irq1;
  559. int wol_irq;
  560. bool wol_irq_disabled;
  561. /* shared status */
  562. spinlock_t lock;
  563. unsigned int irq0_stat;
  564. /* HW descriptors/checksum variables */
  565. bool crc_fwd_en;
  566. u32 dma_max_burst_length;
  567. u32 msg_enable;
  568. struct clk *clk;
  569. struct platform_device *pdev;
  570. struct platform_device *mii_pdev;
  571. /* WOL */
  572. struct clk *clk_wol;
  573. u32 wolopts;
  574. u8 sopass[SOPASS_MAX];
  575. struct bcmgenet_mib_counters mib;
  576. };
  577. static inline bool bcmgenet_has_40bits(struct bcmgenet_priv *priv)
  578. {
  579. return !!(priv->flags & GENET_HAS_40BITS);
  580. }
  581. static inline bool bcmgenet_has_ext(struct bcmgenet_priv *priv)
  582. {
  583. return !!(priv->flags & GENET_HAS_EXT);
  584. }
  585. static inline bool bcmgenet_has_mdio_intr(struct bcmgenet_priv *priv)
  586. {
  587. return !!(priv->flags & GENET_HAS_MDIO_INTR);
  588. }
  589. static inline bool bcmgenet_has_moca_link_det(struct bcmgenet_priv *priv)
  590. {
  591. return !!(priv->flags & GENET_HAS_MOCA_LINK_DET);
  592. }
  593. static inline bool bcmgenet_has_ephy_16nm(struct bcmgenet_priv *priv)
  594. {
  595. return !!(priv->flags & GENET_HAS_EPHY_16NM);
  596. }
  597. #define GENET_IO_MACRO(name, offset) \
  598. static inline u32 bcmgenet_##name##_readl(struct bcmgenet_priv *priv, \
  599. u32 off) \
  600. { \
  601. /* MIPS chips strapped for BE will automagically configure the \
  602. * peripheral registers for CPU-native byte order. \
  603. */ \
  604. if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) \
  605. return __raw_readl(priv->base + offset + off); \
  606. else \
  607. return readl_relaxed(priv->base + offset + off); \
  608. } \
  609. static inline void bcmgenet_##name##_writel(struct bcmgenet_priv *priv, \
  610. u32 val, u32 off) \
  611. { \
  612. if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) \
  613. __raw_writel(val, priv->base + offset + off); \
  614. else \
  615. writel_relaxed(val, priv->base + offset + off); \
  616. }
  617. GENET_IO_MACRO(ext, GENET_EXT_OFF);
  618. GENET_IO_MACRO(umac, GENET_UMAC_OFF);
  619. GENET_IO_MACRO(sys, GENET_SYS_OFF);
  620. /* interrupt l2 registers accessors */
  621. GENET_IO_MACRO(intrl2_0, GENET_INTRL2_0_OFF);
  622. GENET_IO_MACRO(intrl2_1, GENET_INTRL2_1_OFF);
  623. /* HFB register accessors */
  624. GENET_IO_MACRO(hfb, priv->hw_params->hfb_offset);
  625. /* GENET v2+ HFB control and filter len helpers */
  626. GENET_IO_MACRO(hfb_reg, priv->hw_params->hfb_reg_offset);
  627. /* RBUF register accessors */
  628. GENET_IO_MACRO(rbuf, GENET_RBUF_OFF);
  629. /* MDIO routines */
  630. int bcmgenet_mii_init(struct net_device *dev);
  631. int bcmgenet_mii_config(struct net_device *dev, bool init);
  632. int bcmgenet_mii_probe(struct net_device *dev);
  633. void bcmgenet_mii_exit(struct net_device *dev);
  634. void bcmgenet_phy_pause_set(struct net_device *dev, bool rx, bool tx);
  635. void bcmgenet_phy_power_set(struct net_device *dev, bool enable);
  636. void bcmgenet_mii_setup(struct net_device *dev);
  637. /* Wake-on-LAN routines */
  638. void bcmgenet_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol);
  639. int bcmgenet_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol);
  640. int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
  641. enum bcmgenet_power_mode mode);
  642. int bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv,
  643. enum bcmgenet_power_mode mode);
  644. void bcmgenet_eee_enable_set(struct net_device *dev, bool enable);
  645. #endif /* __BCMGENET_H__ */