bcmgenet.h 20 KB

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