bcmgenet.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /*
  2. * Copyright (c) 2014 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. *
  17. *
  18. */
  19. #ifndef __BCMGENET_H__
  20. #define __BCMGENET_H__
  21. #include <linux/skbuff.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/clk.h>
  25. #include <linux/mii.h>
  26. #include <linux/if_vlan.h>
  27. #include <linux/phy.h>
  28. /* total number of Buffer Descriptors, same for Rx/Tx */
  29. #define TOTAL_DESC 256
  30. /* which ring is descriptor based */
  31. #define DESC_INDEX 16
  32. /* Body(1500) + EH_SIZE(14) + VLANTAG(4) + BRCMTAG(6) + FCS(4) = 1528.
  33. * 1536 is multiple of 256 bytes
  34. */
  35. #define ENET_BRCM_TAG_LEN 6
  36. #define ENET_PAD 8
  37. #define ENET_MAX_MTU_SIZE (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
  38. ENET_BRCM_TAG_LEN + ETH_FCS_LEN + ENET_PAD)
  39. #define DMA_MAX_BURST_LENGTH 0x10
  40. /* misc. configuration */
  41. #define CLEAR_ALL_HFB 0xFF
  42. #define DMA_FC_THRESH_HI (TOTAL_DESC >> 4)
  43. #define DMA_FC_THRESH_LO 5
  44. /* 64B receive/transmit status block */
  45. struct status_64 {
  46. u32 length_status; /* length and peripheral status */
  47. u32 ext_status; /* Extended status*/
  48. u32 rx_csum; /* partial rx checksum */
  49. u32 unused1[9]; /* unused */
  50. u32 tx_csum_info; /* Tx checksum info. */
  51. u32 unused2[3]; /* unused */
  52. };
  53. /* Rx status bits */
  54. #define STATUS_RX_EXT_MASK 0x1FFFFF
  55. #define STATUS_RX_CSUM_MASK 0xFFFF
  56. #define STATUS_RX_CSUM_OK 0x10000
  57. #define STATUS_RX_CSUM_FR 0x20000
  58. #define STATUS_RX_PROTO_TCP 0
  59. #define STATUS_RX_PROTO_UDP 1
  60. #define STATUS_RX_PROTO_ICMP 2
  61. #define STATUS_RX_PROTO_OTHER 3
  62. #define STATUS_RX_PROTO_MASK 3
  63. #define STATUS_RX_PROTO_SHIFT 18
  64. #define STATUS_FILTER_INDEX_MASK 0xFFFF
  65. /* Tx status bits */
  66. #define STATUS_TX_CSUM_START_MASK 0X7FFF
  67. #define STATUS_TX_CSUM_START_SHIFT 16
  68. #define STATUS_TX_CSUM_PROTO_UDP 0x8000
  69. #define STATUS_TX_CSUM_OFFSET_MASK 0x7FFF
  70. #define STATUS_TX_CSUM_LV 0x80000000
  71. /* DMA Descriptor */
  72. #define DMA_DESC_LENGTH_STATUS 0x00 /* in bytes of data in buffer */
  73. #define DMA_DESC_ADDRESS_LO 0x04 /* lower bits of PA */
  74. #define DMA_DESC_ADDRESS_HI 0x08 /* upper 32 bits of PA, GENETv4+ */
  75. /* Rx/Tx common counter group */
  76. struct bcmgenet_pkt_counters {
  77. u32 cnt_64; /* RO Received/Transmited 64 bytes packet */
  78. u32 cnt_127; /* RO Rx/Tx 127 bytes packet */
  79. u32 cnt_255; /* RO Rx/Tx 65-255 bytes packet */
  80. u32 cnt_511; /* RO Rx/Tx 256-511 bytes packet */
  81. u32 cnt_1023; /* RO Rx/Tx 512-1023 bytes packet */
  82. u32 cnt_1518; /* RO Rx/Tx 1024-1518 bytes packet */
  83. u32 cnt_mgv; /* RO Rx/Tx 1519-1522 good VLAN packet */
  84. u32 cnt_2047; /* RO Rx/Tx 1522-2047 bytes packet*/
  85. u32 cnt_4095; /* RO Rx/Tx 2048-4095 bytes packet*/
  86. u32 cnt_9216; /* RO Rx/Tx 4096-9216 bytes packet*/
  87. };
  88. /* RSV, Receive Status Vector */
  89. struct bcmgenet_rx_counters {
  90. struct bcmgenet_pkt_counters pkt_cnt;
  91. u32 pkt; /* RO (0x428) Received pkt count*/
  92. u32 bytes; /* RO Received byte count */
  93. u32 mca; /* RO # of Received multicast pkt */
  94. u32 bca; /* RO # of Receive broadcast pkt */
  95. u32 fcs; /* RO # of Received FCS error */
  96. u32 cf; /* RO # of Received control frame pkt*/
  97. u32 pf; /* RO # of Received pause frame pkt */
  98. u32 uo; /* RO # of unknown op code pkt */
  99. u32 aln; /* RO # of alignment error count */
  100. u32 flr; /* RO # of frame length out of range count */
  101. u32 cde; /* RO # of code error pkt */
  102. u32 fcr; /* RO # of carrier sense error pkt */
  103. u32 ovr; /* RO # of oversize pkt*/
  104. u32 jbr; /* RO # of jabber count */
  105. u32 mtue; /* RO # of MTU error pkt*/
  106. u32 pok; /* RO # of Received good pkt */
  107. u32 uc; /* RO # of unicast pkt */
  108. u32 ppp; /* RO # of PPP pkt */
  109. u32 rcrc; /* RO (0x470),# of CRC match pkt */
  110. };
  111. /* TSV, Transmit Status Vector */
  112. struct bcmgenet_tx_counters {
  113. struct bcmgenet_pkt_counters pkt_cnt;
  114. u32 pkts; /* RO (0x4a8) Transmited pkt */
  115. u32 mca; /* RO # of xmited multicast pkt */
  116. u32 bca; /* RO # of xmited broadcast pkt */
  117. u32 pf; /* RO # of xmited pause frame count */
  118. u32 cf; /* RO # of xmited control frame count */
  119. u32 fcs; /* RO # of xmited FCS error count */
  120. u32 ovr; /* RO # of xmited oversize pkt */
  121. u32 drf; /* RO # of xmited deferral pkt */
  122. u32 edf; /* RO # of xmited Excessive deferral pkt*/
  123. u32 scl; /* RO # of xmited single collision pkt */
  124. u32 mcl; /* RO # of xmited multiple collision pkt*/
  125. u32 lcl; /* RO # of xmited late collision pkt */
  126. u32 ecl; /* RO # of xmited excessive collision pkt*/
  127. u32 frg; /* RO # of xmited fragments pkt*/
  128. u32 ncl; /* RO # of xmited total collision count */
  129. u32 jbr; /* RO # of xmited jabber count*/
  130. u32 bytes; /* RO # of xmited byte count */
  131. u32 pok; /* RO # of xmited good pkt */
  132. u32 uc; /* RO (0x0x4f0)# of xmited unitcast pkt */
  133. };
  134. struct bcmgenet_mib_counters {
  135. struct bcmgenet_rx_counters rx;
  136. struct bcmgenet_tx_counters tx;
  137. u32 rx_runt_cnt;
  138. u32 rx_runt_fcs;
  139. u32 rx_runt_fcs_align;
  140. u32 rx_runt_bytes;
  141. u32 rbuf_ovflow_cnt;
  142. u32 rbuf_err_cnt;
  143. u32 mdf_err_cnt;
  144. };
  145. #define UMAC_HD_BKP_CTRL 0x004
  146. #define HD_FC_EN (1 << 0)
  147. #define HD_FC_BKOFF_OK (1 << 1)
  148. #define IPG_CONFIG_RX_SHIFT 2
  149. #define IPG_CONFIG_RX_MASK 0x1F
  150. #define UMAC_CMD 0x008
  151. #define CMD_TX_EN (1 << 0)
  152. #define CMD_RX_EN (1 << 1)
  153. #define UMAC_SPEED_10 0
  154. #define UMAC_SPEED_100 1
  155. #define UMAC_SPEED_1000 2
  156. #define UMAC_SPEED_2500 3
  157. #define CMD_SPEED_SHIFT 2
  158. #define CMD_SPEED_MASK 3
  159. #define CMD_PROMISC (1 << 4)
  160. #define CMD_PAD_EN (1 << 5)
  161. #define CMD_CRC_FWD (1 << 6)
  162. #define CMD_PAUSE_FWD (1 << 7)
  163. #define CMD_RX_PAUSE_IGNORE (1 << 8)
  164. #define CMD_TX_ADDR_INS (1 << 9)
  165. #define CMD_HD_EN (1 << 10)
  166. #define CMD_SW_RESET (1 << 13)
  167. #define CMD_LCL_LOOP_EN (1 << 15)
  168. #define CMD_AUTO_CONFIG (1 << 22)
  169. #define CMD_CNTL_FRM_EN (1 << 23)
  170. #define CMD_NO_LEN_CHK (1 << 24)
  171. #define CMD_RMT_LOOP_EN (1 << 25)
  172. #define CMD_PRBL_EN (1 << 27)
  173. #define CMD_TX_PAUSE_IGNORE (1 << 28)
  174. #define CMD_TX_RX_EN (1 << 29)
  175. #define CMD_RUNT_FILTER_DIS (1 << 30)
  176. #define UMAC_MAC0 0x00C
  177. #define UMAC_MAC1 0x010
  178. #define UMAC_MAX_FRAME_LEN 0x014
  179. #define UMAC_TX_FLUSH 0x334
  180. #define UMAC_MIB_START 0x400
  181. #define UMAC_MDIO_CMD 0x614
  182. #define MDIO_START_BUSY (1 << 29)
  183. #define MDIO_READ_FAIL (1 << 28)
  184. #define MDIO_RD (2 << 26)
  185. #define MDIO_WR (1 << 26)
  186. #define MDIO_PMD_SHIFT 21
  187. #define MDIO_PMD_MASK 0x1F
  188. #define MDIO_REG_SHIFT 16
  189. #define MDIO_REG_MASK 0x1F
  190. #define UMAC_RBUF_OVFL_CNT 0x61C
  191. #define UMAC_MPD_CTRL 0x620
  192. #define MPD_EN (1 << 0)
  193. #define MPD_PW_EN (1 << 27)
  194. #define MPD_MSEQ_LEN_SHIFT 16
  195. #define MPD_MSEQ_LEN_MASK 0xFF
  196. #define UMAC_MPD_PW_MS 0x624
  197. #define UMAC_MPD_PW_LS 0x628
  198. #define UMAC_RBUF_ERR_CNT 0x634
  199. #define UMAC_MDF_ERR_CNT 0x638
  200. #define UMAC_MDF_CTRL 0x650
  201. #define UMAC_MDF_ADDR 0x654
  202. #define UMAC_MIB_CTRL 0x580
  203. #define MIB_RESET_RX (1 << 0)
  204. #define MIB_RESET_RUNT (1 << 1)
  205. #define MIB_RESET_TX (1 << 2)
  206. #define RBUF_CTRL 0x00
  207. #define RBUF_64B_EN (1 << 0)
  208. #define RBUF_ALIGN_2B (1 << 1)
  209. #define RBUF_BAD_DIS (1 << 2)
  210. #define RBUF_STATUS 0x0C
  211. #define RBUF_STATUS_WOL (1 << 0)
  212. #define RBUF_STATUS_MPD_INTR_ACTIVE (1 << 1)
  213. #define RBUF_STATUS_ACPI_INTR_ACTIVE (1 << 2)
  214. #define RBUF_CHK_CTRL 0x14
  215. #define RBUF_RXCHK_EN (1 << 0)
  216. #define RBUF_SKIP_FCS (1 << 4)
  217. #define RBUF_TBUF_SIZE_CTRL 0xb4
  218. #define RBUF_HFB_CTRL_V1 0x38
  219. #define RBUF_HFB_FILTER_EN_SHIFT 16
  220. #define RBUF_HFB_FILTER_EN_MASK 0xffff0000
  221. #define RBUF_HFB_EN (1 << 0)
  222. #define RBUF_HFB_256B (1 << 1)
  223. #define RBUF_ACPI_EN (1 << 2)
  224. #define RBUF_HFB_LEN_V1 0x3C
  225. #define RBUF_FLTR_LEN_MASK 0xFF
  226. #define RBUF_FLTR_LEN_SHIFT 8
  227. #define TBUF_CTRL 0x00
  228. #define TBUF_BP_MC 0x0C
  229. #define TBUF_CTRL_V1 0x80
  230. #define TBUF_BP_MC_V1 0xA0
  231. #define HFB_CTRL 0x00
  232. #define HFB_FLT_ENABLE_V3PLUS 0x04
  233. #define HFB_FLT_LEN_V2 0x04
  234. #define HFB_FLT_LEN_V3PLUS 0x1C
  235. /* uniMac intrl2 registers */
  236. #define INTRL2_CPU_STAT 0x00
  237. #define INTRL2_CPU_SET 0x04
  238. #define INTRL2_CPU_CLEAR 0x08
  239. #define INTRL2_CPU_MASK_STATUS 0x0C
  240. #define INTRL2_CPU_MASK_SET 0x10
  241. #define INTRL2_CPU_MASK_CLEAR 0x14
  242. /* INTRL2 instance 0 definitions */
  243. #define UMAC_IRQ_SCB (1 << 0)
  244. #define UMAC_IRQ_EPHY (1 << 1)
  245. #define UMAC_IRQ_PHY_DET_R (1 << 2)
  246. #define UMAC_IRQ_PHY_DET_F (1 << 3)
  247. #define UMAC_IRQ_LINK_UP (1 << 4)
  248. #define UMAC_IRQ_LINK_DOWN (1 << 5)
  249. #define UMAC_IRQ_UMAC (1 << 6)
  250. #define UMAC_IRQ_UMAC_TSV (1 << 7)
  251. #define UMAC_IRQ_TBUF_UNDERRUN (1 << 8)
  252. #define UMAC_IRQ_RBUF_OVERFLOW (1 << 9)
  253. #define UMAC_IRQ_HFB_SM (1 << 10)
  254. #define UMAC_IRQ_HFB_MM (1 << 11)
  255. #define UMAC_IRQ_MPD_R (1 << 12)
  256. #define UMAC_IRQ_RXDMA_MBDONE (1 << 13)
  257. #define UMAC_IRQ_RXDMA_PDONE (1 << 14)
  258. #define UMAC_IRQ_RXDMA_BDONE (1 << 15)
  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. /* Only valid for GENETv3+ */
  263. #define UMAC_IRQ_MDIO_DONE (1 << 23)
  264. #define UMAC_IRQ_MDIO_ERROR (1 << 24)
  265. /* Register block offsets */
  266. #define GENET_SYS_OFF 0x0000
  267. #define GENET_GR_BRIDGE_OFF 0x0040
  268. #define GENET_EXT_OFF 0x0080
  269. #define GENET_INTRL2_0_OFF 0x0200
  270. #define GENET_INTRL2_1_OFF 0x0240
  271. #define GENET_RBUF_OFF 0x0300
  272. #define GENET_UMAC_OFF 0x0800
  273. /* SYS block offsets and register definitions */
  274. #define SYS_REV_CTRL 0x00
  275. #define SYS_PORT_CTRL 0x04
  276. #define PORT_MODE_INT_EPHY 0
  277. #define PORT_MODE_INT_GPHY 1
  278. #define PORT_MODE_EXT_EPHY 2
  279. #define PORT_MODE_EXT_GPHY 3
  280. #define PORT_MODE_EXT_RVMII_25 (4 | BIT(4))
  281. #define PORT_MODE_EXT_RVMII_50 4
  282. #define LED_ACT_SOURCE_MAC (1 << 9)
  283. #define SYS_RBUF_FLUSH_CTRL 0x08
  284. #define SYS_TBUF_FLUSH_CTRL 0x0C
  285. #define RBUF_FLUSH_CTRL_V1 0x04
  286. /* Ext block register offsets and definitions */
  287. #define EXT_EXT_PWR_MGMT 0x00
  288. #define EXT_PWR_DOWN_BIAS (1 << 0)
  289. #define EXT_PWR_DOWN_DLL (1 << 1)
  290. #define EXT_PWR_DOWN_PHY (1 << 2)
  291. #define EXT_PWR_DN_EN_LD (1 << 3)
  292. #define EXT_ENERGY_DET (1 << 4)
  293. #define EXT_IDDQ_FROM_PHY (1 << 5)
  294. #define EXT_PHY_RESET (1 << 8)
  295. #define EXT_ENERGY_DET_MASK (1 << 12)
  296. #define EXT_RGMII_OOB_CTRL 0x0C
  297. #define RGMII_LINK (1 << 4)
  298. #define OOB_DISABLE (1 << 5)
  299. #define RGMII_MODE_EN (1 << 6)
  300. #define ID_MODE_DIS (1 << 16)
  301. #define EXT_GPHY_CTRL 0x1C
  302. #define EXT_CFG_IDDQ_BIAS (1 << 0)
  303. #define EXT_CFG_PWR_DOWN (1 << 1)
  304. #define EXT_GPHY_RESET (1 << 5)
  305. /* DMA rings size */
  306. #define DMA_RING_SIZE (0x40)
  307. #define DMA_RINGS_SIZE (DMA_RING_SIZE * (DESC_INDEX + 1))
  308. /* DMA registers common definitions */
  309. #define DMA_RW_POINTER_MASK 0x1FF
  310. #define DMA_P_INDEX_DISCARD_CNT_MASK 0xFFFF
  311. #define DMA_P_INDEX_DISCARD_CNT_SHIFT 16
  312. #define DMA_BUFFER_DONE_CNT_MASK 0xFFFF
  313. #define DMA_BUFFER_DONE_CNT_SHIFT 16
  314. #define DMA_P_INDEX_MASK 0xFFFF
  315. #define DMA_C_INDEX_MASK 0xFFFF
  316. /* DMA ring size register */
  317. #define DMA_RING_SIZE_MASK 0xFFFF
  318. #define DMA_RING_SIZE_SHIFT 16
  319. #define DMA_RING_BUFFER_SIZE_MASK 0xFFFF
  320. /* DMA interrupt threshold register */
  321. #define DMA_INTR_THRESHOLD_MASK 0x00FF
  322. /* DMA XON/XOFF register */
  323. #define DMA_XON_THREHOLD_MASK 0xFFFF
  324. #define DMA_XOFF_THRESHOLD_MASK 0xFFFF
  325. #define DMA_XOFF_THRESHOLD_SHIFT 16
  326. /* DMA flow period register */
  327. #define DMA_FLOW_PERIOD_MASK 0xFFFF
  328. #define DMA_MAX_PKT_SIZE_MASK 0xFFFF
  329. #define DMA_MAX_PKT_SIZE_SHIFT 16
  330. /* DMA control register */
  331. #define DMA_EN (1 << 0)
  332. #define DMA_RING_BUF_EN_SHIFT 0x01
  333. #define DMA_RING_BUF_EN_MASK 0xFFFF
  334. #define DMA_TSB_SWAP_EN (1 << 20)
  335. /* DMA status register */
  336. #define DMA_DISABLED (1 << 0)
  337. #define DMA_DESC_RAM_INIT_BUSY (1 << 1)
  338. /* DMA SCB burst size register */
  339. #define DMA_SCB_BURST_SIZE_MASK 0x1F
  340. /* DMA activity vector register */
  341. #define DMA_ACTIVITY_VECTOR_MASK 0x1FFFF
  342. /* DMA backpressure mask register */
  343. #define DMA_BACKPRESSURE_MASK 0x1FFFF
  344. #define DMA_PFC_ENABLE (1 << 31)
  345. /* DMA backpressure status register */
  346. #define DMA_BACKPRESSURE_STATUS_MASK 0x1FFFF
  347. /* DMA override register */
  348. #define DMA_LITTLE_ENDIAN_MODE (1 << 0)
  349. #define DMA_REGISTER_MODE (1 << 1)
  350. /* DMA timeout register */
  351. #define DMA_TIMEOUT_MASK 0xFFFF
  352. #define DMA_TIMEOUT_VAL 5000 /* micro seconds */
  353. /* TDMA rate limiting control register */
  354. #define DMA_RATE_LIMIT_EN_MASK 0xFFFF
  355. /* TDMA arbitration control register */
  356. #define DMA_ARBITER_MODE_MASK 0x03
  357. #define DMA_RING_BUF_PRIORITY_MASK 0x1F
  358. #define DMA_RING_BUF_PRIORITY_SHIFT 5
  359. #define DMA_RATE_ADJ_MASK 0xFF
  360. /* Tx/Rx Dma Descriptor common bits*/
  361. #define DMA_BUFLENGTH_MASK 0x0fff
  362. #define DMA_BUFLENGTH_SHIFT 16
  363. #define DMA_OWN 0x8000
  364. #define DMA_EOP 0x4000
  365. #define DMA_SOP 0x2000
  366. #define DMA_WRAP 0x1000
  367. /* Tx specific Dma descriptor bits */
  368. #define DMA_TX_UNDERRUN 0x0200
  369. #define DMA_TX_APPEND_CRC 0x0040
  370. #define DMA_TX_OW_CRC 0x0020
  371. #define DMA_TX_DO_CSUM 0x0010
  372. #define DMA_TX_QTAG_SHIFT 7
  373. /* Rx Specific Dma descriptor bits */
  374. #define DMA_RX_CHK_V3PLUS 0x8000
  375. #define DMA_RX_CHK_V12 0x1000
  376. #define DMA_RX_BRDCAST 0x0040
  377. #define DMA_RX_MULT 0x0020
  378. #define DMA_RX_LG 0x0010
  379. #define DMA_RX_NO 0x0008
  380. #define DMA_RX_RXER 0x0004
  381. #define DMA_RX_CRC_ERROR 0x0002
  382. #define DMA_RX_OV 0x0001
  383. #define DMA_RX_FI_MASK 0x001F
  384. #define DMA_RX_FI_SHIFT 0x0007
  385. #define DMA_DESC_ALLOC_MASK 0x00FF
  386. #define DMA_ARBITER_RR 0x00
  387. #define DMA_ARBITER_WRR 0x01
  388. #define DMA_ARBITER_SP 0x02
  389. struct enet_cb {
  390. struct sk_buff *skb;
  391. void __iomem *bd_addr;
  392. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  393. DEFINE_DMA_UNMAP_LEN(dma_len);
  394. };
  395. /* power management mode */
  396. enum bcmgenet_power_mode {
  397. GENET_POWER_CABLE_SENSE = 0,
  398. GENET_POWER_PASSIVE,
  399. };
  400. struct bcmgenet_priv;
  401. /* We support both runtime GENET detection and compile-time
  402. * to optimize code-paths for a given hardware
  403. */
  404. enum bcmgenet_version {
  405. GENET_V1 = 1,
  406. GENET_V2,
  407. GENET_V3,
  408. GENET_V4
  409. };
  410. #define GENET_IS_V1(p) ((p)->version == GENET_V1)
  411. #define GENET_IS_V2(p) ((p)->version == GENET_V2)
  412. #define GENET_IS_V3(p) ((p)->version == GENET_V3)
  413. #define GENET_IS_V4(p) ((p)->version == GENET_V4)
  414. /* Hardware flags */
  415. #define GENET_HAS_40BITS (1 << 0)
  416. #define GENET_HAS_EXT (1 << 1)
  417. #define GENET_HAS_MDIO_INTR (1 << 2)
  418. /* BCMGENET hardware parameters, keep this structure nicely aligned
  419. * since it is going to be used in hot paths
  420. */
  421. struct bcmgenet_hw_params {
  422. u8 tx_queues;
  423. u8 rx_queues;
  424. u8 bds_cnt;
  425. u8 bp_in_en_shift;
  426. u32 bp_in_mask;
  427. u8 hfb_filter_cnt;
  428. u8 qtag_mask;
  429. u16 tbuf_offset;
  430. u32 hfb_offset;
  431. u32 hfb_reg_offset;
  432. u32 rdma_offset;
  433. u32 tdma_offset;
  434. u32 words_per_bd;
  435. u32 flags;
  436. };
  437. struct bcmgenet_tx_ring {
  438. spinlock_t lock; /* ring lock */
  439. unsigned int index; /* ring index */
  440. unsigned int queue; /* queue index */
  441. struct enet_cb *cbs; /* tx ring buffer control block*/
  442. unsigned int size; /* size of each tx ring */
  443. unsigned int c_index; /* last consumer index of each ring*/
  444. unsigned int free_bds; /* # of free bds for each ring */
  445. unsigned int write_ptr; /* Tx ring write pointer SW copy */
  446. unsigned int prod_index; /* Tx ring producer index SW copy */
  447. unsigned int cb_ptr; /* Tx ring initial CB ptr */
  448. unsigned int end_ptr; /* Tx ring end CB ptr */
  449. void (*int_enable)(struct bcmgenet_priv *priv,
  450. struct bcmgenet_tx_ring *);
  451. void (*int_disable)(struct bcmgenet_priv *priv,
  452. struct bcmgenet_tx_ring *);
  453. };
  454. /* device context */
  455. struct bcmgenet_priv {
  456. void __iomem *base;
  457. enum bcmgenet_version version;
  458. struct net_device *dev;
  459. u32 int0_mask;
  460. u32 int1_mask;
  461. /* NAPI for descriptor based rx */
  462. struct napi_struct napi ____cacheline_aligned;
  463. /* transmit variables */
  464. void __iomem *tx_bds;
  465. struct enet_cb *tx_cbs;
  466. unsigned int num_tx_bds;
  467. struct bcmgenet_tx_ring tx_rings[DESC_INDEX + 1];
  468. /* receive variables */
  469. void __iomem *rx_bds;
  470. void __iomem *rx_bd_assign_ptr;
  471. int rx_bd_assign_index;
  472. struct enet_cb *rx_cbs;
  473. unsigned int num_rx_bds;
  474. unsigned int rx_buf_len;
  475. unsigned int rx_read_ptr;
  476. unsigned int rx_c_index;
  477. /* other misc variables */
  478. struct bcmgenet_hw_params *hw_params;
  479. /* MDIO bus variables */
  480. wait_queue_head_t wq;
  481. struct phy_device *phydev;
  482. struct device_node *phy_dn;
  483. struct mii_bus *mii_bus;
  484. /* PHY device variables */
  485. int old_duplex;
  486. int old_link;
  487. int old_pause;
  488. phy_interface_t phy_interface;
  489. int phy_addr;
  490. int ext_phy;
  491. /* Interrupt variables */
  492. struct work_struct bcmgenet_irq_work;
  493. int irq0;
  494. int irq1;
  495. unsigned int irq0_stat;
  496. unsigned int irq1_stat;
  497. /* HW descriptors/checksum variables */
  498. bool desc_64b_en;
  499. bool desc_rxchk_en;
  500. bool crc_fwd_en;
  501. unsigned int dma_rx_chk_bit;
  502. u32 msg_enable;
  503. struct clk *clk;
  504. struct platform_device *pdev;
  505. /* WOL */
  506. unsigned long wol_enabled;
  507. struct clk *clk_wol;
  508. u32 wolopts;
  509. struct bcmgenet_mib_counters mib;
  510. };
  511. #define GENET_IO_MACRO(name, offset) \
  512. static inline u32 bcmgenet_##name##_readl(struct bcmgenet_priv *priv, \
  513. u32 off) \
  514. { \
  515. return __raw_readl(priv->base + offset + off); \
  516. } \
  517. static inline void bcmgenet_##name##_writel(struct bcmgenet_priv *priv, \
  518. u32 val, u32 off) \
  519. { \
  520. __raw_writel(val, priv->base + offset + off); \
  521. }
  522. GENET_IO_MACRO(ext, GENET_EXT_OFF);
  523. GENET_IO_MACRO(umac, GENET_UMAC_OFF);
  524. GENET_IO_MACRO(sys, GENET_SYS_OFF);
  525. /* interrupt l2 registers accessors */
  526. GENET_IO_MACRO(intrl2_0, GENET_INTRL2_0_OFF);
  527. GENET_IO_MACRO(intrl2_1, GENET_INTRL2_1_OFF);
  528. /* HFB register accessors */
  529. GENET_IO_MACRO(hfb, priv->hw_params->hfb_offset);
  530. /* GENET v2+ HFB control and filter len helpers */
  531. GENET_IO_MACRO(hfb_reg, priv->hw_params->hfb_reg_offset);
  532. /* RBUF register accessors */
  533. GENET_IO_MACRO(rbuf, GENET_RBUF_OFF);
  534. /* MDIO routines */
  535. int bcmgenet_mii_init(struct net_device *dev);
  536. int bcmgenet_mii_config(struct net_device *dev);
  537. void bcmgenet_mii_exit(struct net_device *dev);
  538. void bcmgenet_mii_reset(struct net_device *dev);
  539. #endif /* __BCMGENET_H__ */