bcmsysport.h 23 KB

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