bcmsysport.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  2. * Broadcom BCM7xxx System Port Ethernet MAC driver
  3. *
  4. * Copyright (C) 2014 Broadcom Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef __BCM_SYSPORT_H
  11. #define __BCM_SYSPORT_H
  12. #include <linux/if_vlan.h>
  13. /* Receive/transmit descriptor format */
  14. #define DESC_ADDR_HI_STATUS_LEN 0x00
  15. #define DESC_ADDR_HI_SHIFT 0
  16. #define DESC_ADDR_HI_MASK 0xff
  17. #define DESC_STATUS_SHIFT 8
  18. #define DESC_STATUS_MASK 0x3ff
  19. #define DESC_LEN_SHIFT 18
  20. #define DESC_LEN_MASK 0x7fff
  21. #define DESC_ADDR_LO 0x04
  22. /* HW supports 40-bit addressing hence the */
  23. #define DESC_SIZE (WORDS_PER_DESC * sizeof(u32))
  24. /* Default RX buffer allocation size */
  25. #define RX_BUF_LENGTH 2048
  26. /* Body(1500) + EH_SIZE(14) + VLANTAG(4) + BRCMTAG(4) + FCS(4) = 1526.
  27. * 1536 is multiple of 256 bytes
  28. */
  29. #define ENET_BRCM_TAG_LEN 4
  30. #define ENET_PAD 10
  31. #define UMAC_MAX_MTU_SIZE (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
  32. ENET_BRCM_TAG_LEN + ETH_FCS_LEN + ENET_PAD)
  33. /* Transmit status block */
  34. struct bcm_tsb {
  35. u32 pcp_dei_vid;
  36. #define PCP_DEI_MASK 0xf
  37. #define VID_SHIFT 4
  38. #define VID_MASK 0xfff
  39. u32 l4_ptr_dest_map;
  40. #define L4_CSUM_PTR_MASK 0x1ff
  41. #define L4_PTR_SHIFT 9
  42. #define L4_PTR_MASK 0x1ff
  43. #define L4_UDP (1 << 18)
  44. #define L4_LENGTH_VALID (1 << 19)
  45. #define DEST_MAP_SHIFT 20
  46. #define DEST_MAP_MASK 0x1ff
  47. };
  48. /* Receive status block uses the same
  49. * definitions as the DMA descriptor
  50. */
  51. struct bcm_rsb {
  52. u32 rx_status_len;
  53. u32 brcm_egress_tag;
  54. };
  55. /* Common Receive/Transmit status bits */
  56. #define DESC_L4_CSUM (1 << 7)
  57. #define DESC_SOP (1 << 8)
  58. #define DESC_EOP (1 << 9)
  59. /* Receive Status bits */
  60. #define RX_STATUS_UCAST 0
  61. #define RX_STATUS_BCAST 0x04
  62. #define RX_STATUS_MCAST 0x08
  63. #define RX_STATUS_L2_MCAST 0x0c
  64. #define RX_STATUS_ERR (1 << 4)
  65. #define RX_STATUS_OVFLOW (1 << 5)
  66. #define RX_STATUS_PARSE_FAIL (1 << 6)
  67. /* Transmit Status bits */
  68. #define TX_STATUS_VLAN_NO_ACT 0x00
  69. #define TX_STATUS_VLAN_PCP_TSB 0x01
  70. #define TX_STATUS_VLAN_QUEUE 0x02
  71. #define TX_STATUS_VLAN_VID_TSB 0x03
  72. #define TX_STATUS_OWR_CRC (1 << 2)
  73. #define TX_STATUS_APP_CRC (1 << 3)
  74. #define TX_STATUS_BRCM_TAG_NO_ACT 0
  75. #define TX_STATUS_BRCM_TAG_ZERO 0x10
  76. #define TX_STATUS_BRCM_TAG_ONE_QUEUE 0x20
  77. #define TX_STATUS_BRCM_TAG_ONE_TSB 0x30
  78. #define TX_STATUS_SKIP_BYTES (1 << 6)
  79. /* Specific register definitions */
  80. #define SYS_PORT_TOPCTRL_OFFSET 0
  81. #define REV_CNTL 0x00
  82. #define REV_MASK 0xffff
  83. #define RX_FLUSH_CNTL 0x04
  84. #define RX_FLUSH (1 << 0)
  85. #define TX_FLUSH_CNTL 0x08
  86. #define TX_FLUSH (1 << 0)
  87. #define MISC_CNTL 0x0c
  88. #define SYS_CLK_SEL (1 << 0)
  89. #define TDMA_EOP_SEL (1 << 1)
  90. /* Level-2 Interrupt controller offsets and defines */
  91. #define SYS_PORT_INTRL2_0_OFFSET 0x200
  92. #define SYS_PORT_INTRL2_1_OFFSET 0x240
  93. #define INTRL2_CPU_STATUS 0x00
  94. #define INTRL2_CPU_SET 0x04
  95. #define INTRL2_CPU_CLEAR 0x08
  96. #define INTRL2_CPU_MASK_STATUS 0x0c
  97. #define INTRL2_CPU_MASK_SET 0x10
  98. #define INTRL2_CPU_MASK_CLEAR 0x14
  99. /* Level-2 instance 0 interrupt bits */
  100. #define INTRL2_0_GISB_ERR (1 << 0)
  101. #define INTRL2_0_RBUF_OVFLOW (1 << 1)
  102. #define INTRL2_0_TBUF_UNDFLOW (1 << 2)
  103. #define INTRL2_0_MPD (1 << 3)
  104. #define INTRL2_0_BRCM_MATCH_TAG (1 << 4)
  105. #define INTRL2_0_RDMA_MBDONE (1 << 5)
  106. #define INTRL2_0_OVER_MAX_THRESH (1 << 6)
  107. #define INTRL2_0_BELOW_HYST_THRESH (1 << 7)
  108. #define INTRL2_0_FREE_LIST_EMPTY (1 << 8)
  109. #define INTRL2_0_TX_RING_FULL (1 << 9)
  110. #define INTRL2_0_DESC_ALLOC_ERR (1 << 10)
  111. #define INTRL2_0_UNEXP_PKTSIZE_ACK (1 << 11)
  112. /* RXCHK offset and defines */
  113. #define SYS_PORT_RXCHK_OFFSET 0x300
  114. #define RXCHK_CONTROL 0x00
  115. #define RXCHK_EN (1 << 0)
  116. #define RXCHK_SKIP_FCS (1 << 1)
  117. #define RXCHK_BAD_CSUM_DIS (1 << 2)
  118. #define RXCHK_BRCM_TAG_EN (1 << 3)
  119. #define RXCHK_BRCM_TAG_MATCH_SHIFT 4
  120. #define RXCHK_BRCM_TAG_MATCH_MASK 0xff
  121. #define RXCHK_PARSE_TNL (1 << 12)
  122. #define RXCHK_VIOL_EN (1 << 13)
  123. #define RXCHK_VIOL_DIS (1 << 14)
  124. #define RXCHK_INCOM_PKT (1 << 15)
  125. #define RXCHK_V6_DUPEXT_EN (1 << 16)
  126. #define RXCHK_V6_DUPEXT_DIS (1 << 17)
  127. #define RXCHK_ETHERTYPE_DIS (1 << 18)
  128. #define RXCHK_L2_HDR_DIS (1 << 19)
  129. #define RXCHK_L3_HDR_DIS (1 << 20)
  130. #define RXCHK_MAC_RX_ERR_DIS (1 << 21)
  131. #define RXCHK_PARSE_AUTH (1 << 22)
  132. #define RXCHK_BRCM_TAG0 0x04
  133. #define RXCHK_BRCM_TAG(i) ((i) * RXCHK_BRCM_TAG0)
  134. #define RXCHK_BRCM_TAG0_MASK 0x24
  135. #define RXCHK_BRCM_TAG_MASK(i) ((i) * RXCHK_BRCM_TAG0_MASK)
  136. #define RXCHK_BRCM_TAG_MATCH_STATUS 0x44
  137. #define RXCHK_ETHERTYPE 0x48
  138. #define RXCHK_BAD_CSUM_CNTR 0x4C
  139. #define RXCHK_OTHER_DISC_CNTR 0x50
  140. /* TXCHCK offsets and defines */
  141. #define SYS_PORT_TXCHK_OFFSET 0x380
  142. #define TXCHK_PKT_RDY_THRESH 0x00
  143. /* Receive buffer offset and defines */
  144. #define SYS_PORT_RBUF_OFFSET 0x400
  145. #define RBUF_CONTROL 0x00
  146. #define RBUF_RSB_EN (1 << 0)
  147. #define RBUF_4B_ALGN (1 << 1)
  148. #define RBUF_BRCM_TAG_STRIP (1 << 2)
  149. #define RBUF_BAD_PKT_DISC (1 << 3)
  150. #define RBUF_RESUME_THRESH_SHIFT 4
  151. #define RBUF_RESUME_THRESH_MASK 0xff
  152. #define RBUF_OK_TO_SEND_SHIFT 12
  153. #define RBUF_OK_TO_SEND_MASK 0xff
  154. #define RBUF_CRC_REPLACE (1 << 20)
  155. #define RBUF_OK_TO_SEND_MODE (1 << 21)
  156. #define RBUF_RSB_SWAP (1 << 22)
  157. #define RBUF_ACPI_EN (1 << 23)
  158. #define RBUF_PKT_RDY_THRESH 0x04
  159. #define RBUF_STATUS 0x08
  160. #define RBUF_WOL_MODE (1 << 0)
  161. #define RBUF_MPD (1 << 1)
  162. #define RBUF_ACPI (1 << 2)
  163. #define RBUF_OVFL_DISC_CNTR 0x0c
  164. #define RBUF_ERR_PKT_CNTR 0x10
  165. /* Transmit buffer offset and defines */
  166. #define SYS_PORT_TBUF_OFFSET 0x600
  167. #define TBUF_CONTROL 0x00
  168. #define TBUF_BP_EN (1 << 0)
  169. #define TBUF_MAX_PKT_THRESH_SHIFT 1
  170. #define TBUF_MAX_PKT_THRESH_MASK 0x1f
  171. #define TBUF_FULL_THRESH_SHIFT 8
  172. #define TBUF_FULL_THRESH_MASK 0x1f
  173. /* UniMAC offset and defines */
  174. #define SYS_PORT_UMAC_OFFSET 0x800
  175. #define UMAC_CMD 0x008
  176. #define CMD_TX_EN (1 << 0)
  177. #define CMD_RX_EN (1 << 1)
  178. #define CMD_SPEED_SHIFT 2
  179. #define CMD_SPEED_10 0
  180. #define CMD_SPEED_100 1
  181. #define CMD_SPEED_1000 2
  182. #define CMD_SPEED_2500 3
  183. #define CMD_SPEED_MASK 3
  184. #define CMD_PROMISC (1 << 4)
  185. #define CMD_PAD_EN (1 << 5)
  186. #define CMD_CRC_FWD (1 << 6)
  187. #define CMD_PAUSE_FWD (1 << 7)
  188. #define CMD_RX_PAUSE_IGNORE (1 << 8)
  189. #define CMD_TX_ADDR_INS (1 << 9)
  190. #define CMD_HD_EN (1 << 10)
  191. #define CMD_SW_RESET (1 << 13)
  192. #define CMD_LCL_LOOP_EN (1 << 15)
  193. #define CMD_AUTO_CONFIG (1 << 22)
  194. #define CMD_CNTL_FRM_EN (1 << 23)
  195. #define CMD_NO_LEN_CHK (1 << 24)
  196. #define CMD_RMT_LOOP_EN (1 << 25)
  197. #define CMD_PRBL_EN (1 << 27)
  198. #define CMD_TX_PAUSE_IGNORE (1 << 28)
  199. #define CMD_TX_RX_EN (1 << 29)
  200. #define CMD_RUNT_FILTER_DIS (1 << 30)
  201. #define UMAC_MAC0 0x00c
  202. #define UMAC_MAC1 0x010
  203. #define UMAC_MAX_FRAME_LEN 0x014
  204. #define UMAC_TX_FLUSH 0x334
  205. #define UMAC_MIB_START 0x400
  206. /* There is a 0xC gap between the end of RX and beginning of TX stats and then
  207. * between the end of TX stats and the beginning of the RX RUNT
  208. */
  209. #define UMAC_MIB_STAT_OFFSET 0xc
  210. #define UMAC_MIB_CTRL 0x580
  211. #define MIB_RX_CNT_RST (1 << 0)
  212. #define MIB_RUNT_CNT_RST (1 << 1)
  213. #define MIB_TX_CNT_RST (1 << 2)
  214. #define UMAC_MPD_CTRL 0x620
  215. #define MPD_EN (1 << 0)
  216. #define MSEQ_LEN_SHIFT 16
  217. #define MSEQ_LEN_MASK 0xff
  218. #define PSW_EN (1 << 27)
  219. #define UMAC_PSW_MS 0x624
  220. #define UMAC_PSW_LS 0x628
  221. #define UMAC_MDF_CTRL 0x650
  222. #define UMAC_MDF_ADDR 0x654
  223. /* Receive DMA offset and defines */
  224. #define SYS_PORT_RDMA_OFFSET 0x2000
  225. #define RDMA_CONTROL 0x1000
  226. #define RDMA_EN (1 << 0)
  227. #define RDMA_RING_CFG (1 << 1)
  228. #define RDMA_DISC_EN (1 << 2)
  229. #define RDMA_BUF_DATA_OFFSET_SHIFT 4
  230. #define RDMA_BUF_DATA_OFFSET_MASK 0x3ff
  231. #define RDMA_STATUS 0x1004
  232. #define RDMA_DISABLED (1 << 0)
  233. #define RDMA_DESC_RAM_INIT_BUSY (1 << 1)
  234. #define RDMA_BP_STATUS (1 << 2)
  235. #define RDMA_SCB_BURST_SIZE 0x1008
  236. #define RDMA_RING_BUF_SIZE 0x100c
  237. #define RDMA_RING_SIZE_SHIFT 16
  238. #define RDMA_WRITE_PTR_HI 0x1010
  239. #define RDMA_WRITE_PTR_LO 0x1014
  240. #define RDMA_PROD_INDEX 0x1018
  241. #define RDMA_PROD_INDEX_MASK 0xffff
  242. #define RDMA_CONS_INDEX 0x101c
  243. #define RDMA_CONS_INDEX_MASK 0xffff
  244. #define RDMA_START_ADDR_HI 0x1020
  245. #define RDMA_START_ADDR_LO 0x1024
  246. #define RDMA_END_ADDR_HI 0x1028
  247. #define RDMA_END_ADDR_LO 0x102c
  248. #define RDMA_MBDONE_INTR 0x1030
  249. #define RDMA_INTR_THRESH_MASK 0x1ff
  250. #define RDMA_TIMEOUT_SHIFT 16
  251. #define RDMA_TIMEOUT_MASK 0xffff
  252. #define RDMA_XON_XOFF_THRESH 0x1034
  253. #define RDMA_XON_XOFF_THRESH_MASK 0xffff
  254. #define RDMA_XOFF_THRESH_SHIFT 16
  255. #define RDMA_READ_PTR_HI 0x1038
  256. #define RDMA_READ_PTR_LO 0x103c
  257. #define RDMA_OVERRIDE 0x1040
  258. #define RDMA_LE_MODE (1 << 0)
  259. #define RDMA_REG_MODE (1 << 1)
  260. #define RDMA_TEST 0x1044
  261. #define RDMA_TP_OUT_SEL (1 << 0)
  262. #define RDMA_MEM_SEL (1 << 1)
  263. #define RDMA_DEBUG 0x1048
  264. /* Transmit DMA offset and defines */
  265. #define TDMA_NUM_RINGS 32 /* rings = queues */
  266. #define TDMA_PORT_SIZE DESC_SIZE /* two 32-bits words */
  267. #define SYS_PORT_TDMA_OFFSET 0x4000
  268. #define TDMA_WRITE_PORT_OFFSET 0x0000
  269. #define TDMA_WRITE_PORT_HI(i) (TDMA_WRITE_PORT_OFFSET + \
  270. (i) * TDMA_PORT_SIZE)
  271. #define TDMA_WRITE_PORT_LO(i) (TDMA_WRITE_PORT_OFFSET + \
  272. sizeof(u32) + (i) * TDMA_PORT_SIZE)
  273. #define TDMA_READ_PORT_OFFSET (TDMA_WRITE_PORT_OFFSET + \
  274. (TDMA_NUM_RINGS * TDMA_PORT_SIZE))
  275. #define TDMA_READ_PORT_HI(i) (TDMA_READ_PORT_OFFSET + \
  276. (i) * TDMA_PORT_SIZE)
  277. #define TDMA_READ_PORT_LO(i) (TDMA_READ_PORT_OFFSET + \
  278. sizeof(u32) + (i) * TDMA_PORT_SIZE)
  279. #define TDMA_READ_PORT_CMD_OFFSET (TDMA_READ_PORT_OFFSET + \
  280. (TDMA_NUM_RINGS * TDMA_PORT_SIZE))
  281. #define TDMA_READ_PORT_CMD(i) (TDMA_READ_PORT_CMD_OFFSET + \
  282. (i) * sizeof(u32))
  283. #define TDMA_DESC_RING_00_BASE (TDMA_READ_PORT_CMD_OFFSET + \
  284. (TDMA_NUM_RINGS * sizeof(u32)))
  285. /* Register offsets and defines relatives to a specific ring number */
  286. #define RING_HEAD_TAIL_PTR 0x00
  287. #define RING_HEAD_MASK 0x7ff
  288. #define RING_TAIL_SHIFT 11
  289. #define RING_TAIL_MASK 0x7ff
  290. #define RING_FLUSH (1 << 24)
  291. #define RING_EN (1 << 25)
  292. #define RING_COUNT 0x04
  293. #define RING_COUNT_MASK 0x7ff
  294. #define RING_BUFF_DONE_SHIFT 11
  295. #define RING_BUFF_DONE_MASK 0x7ff
  296. #define RING_MAX_HYST 0x08
  297. #define RING_MAX_THRESH_MASK 0x7ff
  298. #define RING_HYST_THRESH_SHIFT 11
  299. #define RING_HYST_THRESH_MASK 0x7ff
  300. #define RING_INTR_CONTROL 0x0c
  301. #define RING_INTR_THRESH_MASK 0x7ff
  302. #define RING_EMPTY_INTR_EN (1 << 15)
  303. #define RING_TIMEOUT_SHIFT 16
  304. #define RING_TIMEOUT_MASK 0xffff
  305. #define RING_PROD_CONS_INDEX 0x10
  306. #define RING_PROD_INDEX_MASK 0xffff
  307. #define RING_CONS_INDEX_SHIFT 16
  308. #define RING_CONS_INDEX_MASK 0xffff
  309. #define RING_MAPPING 0x14
  310. #define RING_QID_MASK 0x3
  311. #define RING_PORT_ID_SHIFT 3
  312. #define RING_PORT_ID_MASK 0x7
  313. #define RING_IGNORE_STATUS (1 << 6)
  314. #define RING_FAILOVER_EN (1 << 7)
  315. #define RING_CREDIT_SHIFT 8
  316. #define RING_CREDIT_MASK 0xffff
  317. #define RING_PCP_DEI_VID 0x18
  318. #define RING_VID_MASK 0x7ff
  319. #define RING_DEI (1 << 12)
  320. #define RING_PCP_SHIFT 13
  321. #define RING_PCP_MASK 0x7
  322. #define RING_PKT_SIZE_ADJ_SHIFT 16
  323. #define RING_PKT_SIZE_ADJ_MASK 0xf
  324. #define TDMA_DESC_RING_SIZE 28
  325. /* Defininition for a given TX ring base address */
  326. #define TDMA_DESC_RING_BASE(i) (TDMA_DESC_RING_00_BASE + \
  327. ((i) * TDMA_DESC_RING_SIZE))
  328. /* Ring indexed register addreses */
  329. #define TDMA_DESC_RING_HEAD_TAIL_PTR(i) (TDMA_DESC_RING_BASE(i) + \
  330. RING_HEAD_TAIL_PTR)
  331. #define TDMA_DESC_RING_COUNT(i) (TDMA_DESC_RING_BASE(i) + \
  332. RING_COUNT)
  333. #define TDMA_DESC_RING_MAX_HYST(i) (TDMA_DESC_RING_BASE(i) + \
  334. RING_MAX_HYST)
  335. #define TDMA_DESC_RING_INTR_CONTROL(i) (TDMA_DESC_RING_BASE(i) + \
  336. RING_INTR_CONTROL)
  337. #define TDMA_DESC_RING_PROD_CONS_INDEX(i) \
  338. (TDMA_DESC_RING_BASE(i) + \
  339. RING_PROD_CONS_INDEX)
  340. #define TDMA_DESC_RING_MAPPING(i) (TDMA_DESC_RING_BASE(i) + \
  341. RING_MAPPING)
  342. #define TDMA_DESC_RING_PCP_DEI_VID(i) (TDMA_DESC_RING_BASE(i) + \
  343. RING_PCP_DEI_VID)
  344. #define TDMA_CONTROL 0x600
  345. #define TDMA_EN (1 << 0)
  346. #define TSB_EN (1 << 1)
  347. #define TSB_SWAP (1 << 2)
  348. #define ACB_ALGO (1 << 3)
  349. #define BUF_DATA_OFFSET_SHIFT 4
  350. #define BUF_DATA_OFFSET_MASK 0x3ff
  351. #define VLAN_EN (1 << 14)
  352. #define SW_BRCM_TAG (1 << 15)
  353. #define WNC_KPT_SIZE_UPDATE (1 << 16)
  354. #define SYNC_PKT_SIZE (1 << 17)
  355. #define ACH_TXDONE_DELAY_SHIFT 18
  356. #define ACH_TXDONE_DELAY_MASK 0xff
  357. #define TDMA_STATUS 0x604
  358. #define TDMA_DISABLED (1 << 0)
  359. #define TDMA_LL_RAM_INIT_BUSY (1 << 1)
  360. #define TDMA_SCB_BURST_SIZE 0x608
  361. #define TDMA_OVER_MAX_THRESH_STATUS 0x60c
  362. #define TDMA_OVER_HYST_THRESH_STATUS 0x610
  363. #define TDMA_TPID 0x614
  364. #define TDMA_FREE_LIST_HEAD_TAIL_PTR 0x618
  365. #define TDMA_FREE_HEAD_MASK 0x7ff
  366. #define TDMA_FREE_TAIL_SHIFT 11
  367. #define TDMA_FREE_TAIL_MASK 0x7ff
  368. #define TDMA_FREE_LIST_COUNT 0x61c
  369. #define TDMA_FREE_LIST_COUNT_MASK 0x7ff
  370. #define TDMA_TIER2_ARB_CTRL 0x620
  371. #define TDMA_ARB_MODE_RR 0
  372. #define TDMA_ARB_MODE_WEIGHT_RR 0x1
  373. #define TDMA_ARB_MODE_STRICT 0x2
  374. #define TDMA_ARB_MODE_DEFICIT_RR 0x3
  375. #define TDMA_CREDIT_SHIFT 4
  376. #define TDMA_CREDIT_MASK 0xffff
  377. #define TDMA_TIER1_ARB_0_CTRL 0x624
  378. #define TDMA_ARB_EN (1 << 0)
  379. #define TDMA_TIER1_ARB_0_QUEUE_EN 0x628
  380. #define TDMA_TIER1_ARB_1_CTRL 0x62c
  381. #define TDMA_TIER1_ARB_1_QUEUE_EN 0x630
  382. #define TDMA_TIER1_ARB_2_CTRL 0x634
  383. #define TDMA_TIER1_ARB_2_QUEUE_EN 0x638
  384. #define TDMA_TIER1_ARB_3_CTRL 0x63c
  385. #define TDMA_TIER1_ARB_3_QUEUE_EN 0x640
  386. #define TDMA_SCB_ENDIAN_OVERRIDE 0x644
  387. #define TDMA_LE_MODE (1 << 0)
  388. #define TDMA_REG_MODE (1 << 1)
  389. #define TDMA_TEST 0x648
  390. #define TDMA_TP_OUT_SEL (1 << 0)
  391. #define TDMA_MEM_TM (1 << 1)
  392. #define TDMA_DEBUG 0x64c
  393. /* Transmit/Receive descriptor */
  394. struct dma_desc {
  395. u32 addr_status_len;
  396. u32 addr_lo;
  397. };
  398. /* Number of Receive hardware descriptor words */
  399. #define NUM_HW_RX_DESC_WORDS 1024
  400. /* Real number of usable descriptors */
  401. #define NUM_RX_DESC (NUM_HW_RX_DESC_WORDS / WORDS_PER_DESC)
  402. /* Internal linked-list RAM has up to 1536 entries */
  403. #define NUM_TX_DESC 1536
  404. #define WORDS_PER_DESC (sizeof(struct dma_desc) / sizeof(u32))
  405. /* Rx/Tx common counter group.*/
  406. struct bcm_sysport_pkt_counters {
  407. u32 cnt_64; /* RO Received/Transmited 64 bytes packet */
  408. u32 cnt_127; /* RO Rx/Tx 127 bytes packet */
  409. u32 cnt_255; /* RO Rx/Tx 65-255 bytes packet */
  410. u32 cnt_511; /* RO Rx/Tx 256-511 bytes packet */
  411. u32 cnt_1023; /* RO Rx/Tx 512-1023 bytes packet */
  412. u32 cnt_1518; /* RO Rx/Tx 1024-1518 bytes packet */
  413. u32 cnt_mgv; /* RO Rx/Tx 1519-1522 good VLAN packet */
  414. u32 cnt_2047; /* RO Rx/Tx 1522-2047 bytes packet*/
  415. u32 cnt_4095; /* RO Rx/Tx 2048-4095 bytes packet*/
  416. u32 cnt_9216; /* RO Rx/Tx 4096-9216 bytes packet*/
  417. };
  418. /* RSV, Receive Status Vector */
  419. struct bcm_sysport_rx_counters {
  420. struct bcm_sysport_pkt_counters pkt_cnt;
  421. u32 pkt; /* RO (0x428) Received pkt count*/
  422. u32 bytes; /* RO Received byte count */
  423. u32 mca; /* RO # of Received multicast pkt */
  424. u32 bca; /* RO # of Receive broadcast pkt */
  425. u32 fcs; /* RO # of Received FCS error */
  426. u32 cf; /* RO # of Received control frame pkt*/
  427. u32 pf; /* RO # of Received pause frame pkt */
  428. u32 uo; /* RO # of unknown op code pkt */
  429. u32 aln; /* RO # of alignment error count */
  430. u32 flr; /* RO # of frame length out of range count */
  431. u32 cde; /* RO # of code error pkt */
  432. u32 fcr; /* RO # of carrier sense error pkt */
  433. u32 ovr; /* RO # of oversize pkt*/
  434. u32 jbr; /* RO # of jabber count */
  435. u32 mtue; /* RO # of MTU error pkt*/
  436. u32 pok; /* RO # of Received good pkt */
  437. u32 uc; /* RO # of unicast pkt */
  438. u32 ppp; /* RO # of PPP pkt */
  439. u32 rcrc; /* RO (0x470),# of CRC match pkt */
  440. };
  441. /* TSV, Transmit Status Vector */
  442. struct bcm_sysport_tx_counters {
  443. struct bcm_sysport_pkt_counters pkt_cnt;
  444. u32 pkts; /* RO (0x4a8) Transmited pkt */
  445. u32 mca; /* RO # of xmited multicast pkt */
  446. u32 bca; /* RO # of xmited broadcast pkt */
  447. u32 pf; /* RO # of xmited pause frame count */
  448. u32 cf; /* RO # of xmited control frame count */
  449. u32 fcs; /* RO # of xmited FCS error count */
  450. u32 ovr; /* RO # of xmited oversize pkt */
  451. u32 drf; /* RO # of xmited deferral pkt */
  452. u32 edf; /* RO # of xmited Excessive deferral pkt*/
  453. u32 scl; /* RO # of xmited single collision pkt */
  454. u32 mcl; /* RO # of xmited multiple collision pkt*/
  455. u32 lcl; /* RO # of xmited late collision pkt */
  456. u32 ecl; /* RO # of xmited excessive collision pkt*/
  457. u32 frg; /* RO # of xmited fragments pkt*/
  458. u32 ncl; /* RO # of xmited total collision count */
  459. u32 jbr; /* RO # of xmited jabber count*/
  460. u32 bytes; /* RO # of xmited byte count */
  461. u32 pok; /* RO # of xmited good pkt */
  462. u32 uc; /* RO (0x4f0) # of xmited unicast pkt */
  463. };
  464. struct bcm_sysport_mib {
  465. struct bcm_sysport_rx_counters rx;
  466. struct bcm_sysport_tx_counters tx;
  467. u32 rx_runt_cnt;
  468. u32 rx_runt_fcs;
  469. u32 rx_runt_fcs_align;
  470. u32 rx_runt_bytes;
  471. u32 rxchk_bad_csum;
  472. u32 rxchk_other_pkt_disc;
  473. u32 rbuf_ovflow_cnt;
  474. u32 rbuf_err_cnt;
  475. u32 alloc_rx_buff_failed;
  476. u32 rx_dma_failed;
  477. u32 tx_dma_failed;
  478. };
  479. /* HW maintains a large list of counters */
  480. enum bcm_sysport_stat_type {
  481. BCM_SYSPORT_STAT_NETDEV = -1,
  482. BCM_SYSPORT_STAT_MIB_RX,
  483. BCM_SYSPORT_STAT_MIB_TX,
  484. BCM_SYSPORT_STAT_RUNT,
  485. BCM_SYSPORT_STAT_RXCHK,
  486. BCM_SYSPORT_STAT_RBUF,
  487. BCM_SYSPORT_STAT_SOFT,
  488. };
  489. /* Macros to help define ethtool statistics */
  490. #define STAT_NETDEV(m) { \
  491. .stat_string = __stringify(m), \
  492. .stat_sizeof = sizeof(((struct net_device_stats *)0)->m), \
  493. .stat_offset = offsetof(struct net_device_stats, m), \
  494. .type = BCM_SYSPORT_STAT_NETDEV, \
  495. }
  496. #define STAT_MIB(str, m, _type) { \
  497. .stat_string = str, \
  498. .stat_sizeof = sizeof(((struct bcm_sysport_priv *)0)->m), \
  499. .stat_offset = offsetof(struct bcm_sysport_priv, m), \
  500. .type = _type, \
  501. }
  502. #define STAT_MIB_RX(str, m) STAT_MIB(str, m, BCM_SYSPORT_STAT_MIB_RX)
  503. #define STAT_MIB_TX(str, m) STAT_MIB(str, m, BCM_SYSPORT_STAT_MIB_TX)
  504. #define STAT_RUNT(str, m) STAT_MIB(str, m, BCM_SYSPORT_STAT_RUNT)
  505. #define STAT_MIB_SOFT(str, m) STAT_MIB(str, m, BCM_SYSPORT_STAT_SOFT)
  506. #define STAT_RXCHK(str, m, ofs) { \
  507. .stat_string = str, \
  508. .stat_sizeof = sizeof(((struct bcm_sysport_priv *)0)->m), \
  509. .stat_offset = offsetof(struct bcm_sysport_priv, m), \
  510. .type = BCM_SYSPORT_STAT_RXCHK, \
  511. .reg_offset = ofs, \
  512. }
  513. #define STAT_RBUF(str, m, ofs) { \
  514. .stat_string = str, \
  515. .stat_sizeof = sizeof(((struct bcm_sysport_priv *)0)->m), \
  516. .stat_offset = offsetof(struct bcm_sysport_priv, m), \
  517. .type = BCM_SYSPORT_STAT_RBUF, \
  518. .reg_offset = ofs, \
  519. }
  520. struct bcm_sysport_stats {
  521. char stat_string[ETH_GSTRING_LEN];
  522. int stat_sizeof;
  523. int stat_offset;
  524. enum bcm_sysport_stat_type type;
  525. /* reg offset from UMAC base for misc counters */
  526. u16 reg_offset;
  527. };
  528. /* Software house keeping helper structure */
  529. struct bcm_sysport_cb {
  530. struct sk_buff *skb; /* SKB for RX packets */
  531. void __iomem *bd_addr; /* Buffer descriptor PHYS addr */
  532. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  533. DEFINE_DMA_UNMAP_LEN(dma_len);
  534. };
  535. /* Software view of the TX ring */
  536. struct bcm_sysport_tx_ring {
  537. spinlock_t lock; /* Ring lock for tx reclaim/xmit */
  538. struct napi_struct napi; /* NAPI per tx queue */
  539. dma_addr_t desc_dma; /* DMA cookie */
  540. unsigned int index; /* Ring index */
  541. unsigned int size; /* Ring current size */
  542. unsigned int alloc_size; /* Ring one-time allocated size */
  543. unsigned int desc_count; /* Number of descriptors */
  544. unsigned int curr_desc; /* Current descriptor */
  545. unsigned int c_index; /* Last consumer index */
  546. unsigned int clean_index; /* Current clean index */
  547. struct bcm_sysport_cb *cbs; /* Transmit control blocks */
  548. struct dma_desc *desc_cpu; /* CPU view of the descriptor */
  549. struct bcm_sysport_priv *priv; /* private context backpointer */
  550. };
  551. /* Driver private structure */
  552. struct bcm_sysport_priv {
  553. void __iomem *base;
  554. u32 irq0_stat;
  555. u32 irq0_mask;
  556. u32 irq1_stat;
  557. u32 irq1_mask;
  558. struct napi_struct napi ____cacheline_aligned;
  559. struct net_device *netdev;
  560. struct platform_device *pdev;
  561. int irq0;
  562. int irq1;
  563. int wol_irq;
  564. /* Transmit rings */
  565. struct bcm_sysport_tx_ring tx_rings[TDMA_NUM_RINGS];
  566. /* Receive queue */
  567. void __iomem *rx_bds;
  568. struct bcm_sysport_cb *rx_cbs;
  569. unsigned int num_rx_bds;
  570. unsigned int rx_read_ptr;
  571. unsigned int rx_c_index;
  572. /* PHY device */
  573. struct device_node *phy_dn;
  574. phy_interface_t phy_interface;
  575. int old_pause;
  576. int old_link;
  577. int old_duplex;
  578. /* Misc fields */
  579. unsigned int rx_chk_en:1;
  580. unsigned int tsb_en:1;
  581. unsigned int crc_fwd:1;
  582. u16 rev;
  583. u32 wolopts;
  584. unsigned int wol_irq_disabled:1;
  585. /* MIB related fields */
  586. struct bcm_sysport_mib mib;
  587. /* Ethtool */
  588. u32 msg_enable;
  589. };
  590. #endif /* __BCM_SYSPORT_H */