mvpp2.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. /*
  2. * Definitions for Marvell PPv2 network controller for Armada 375 SoC.
  3. *
  4. * Copyright (C) 2014 Marvell
  5. *
  6. * Marcin Wojtas <mw@semihalf.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #ifndef _MVPP2_H_
  13. #define _MVPP2_H_
  14. #include <linux/kernel.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/phy.h>
  17. #include <linux/phylink.h>
  18. /* Fifo Registers */
  19. #define MVPP2_RX_DATA_FIFO_SIZE_REG(port) (0x00 + 4 * (port))
  20. #define MVPP2_RX_ATTR_FIFO_SIZE_REG(port) (0x20 + 4 * (port))
  21. #define MVPP2_RX_MIN_PKT_SIZE_REG 0x60
  22. #define MVPP2_RX_FIFO_INIT_REG 0x64
  23. #define MVPP22_TX_FIFO_THRESH_REG(port) (0x8840 + 4 * (port))
  24. #define MVPP22_TX_FIFO_SIZE_REG(port) (0x8860 + 4 * (port))
  25. /* RX DMA Top Registers */
  26. #define MVPP2_RX_CTRL_REG(port) (0x140 + 4 * (port))
  27. #define MVPP2_RX_LOW_LATENCY_PKT_SIZE(s) (((s) & 0xfff) << 16)
  28. #define MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK BIT(31)
  29. #define MVPP2_POOL_BUF_SIZE_REG(pool) (0x180 + 4 * (pool))
  30. #define MVPP2_POOL_BUF_SIZE_OFFSET 5
  31. #define MVPP2_RXQ_CONFIG_REG(rxq) (0x800 + 4 * (rxq))
  32. #define MVPP2_SNOOP_PKT_SIZE_MASK 0x1ff
  33. #define MVPP2_SNOOP_BUF_HDR_MASK BIT(9)
  34. #define MVPP2_RXQ_POOL_SHORT_OFFS 20
  35. #define MVPP21_RXQ_POOL_SHORT_MASK 0x700000
  36. #define MVPP22_RXQ_POOL_SHORT_MASK 0xf00000
  37. #define MVPP2_RXQ_POOL_LONG_OFFS 24
  38. #define MVPP21_RXQ_POOL_LONG_MASK 0x7000000
  39. #define MVPP22_RXQ_POOL_LONG_MASK 0xf000000
  40. #define MVPP2_RXQ_PACKET_OFFSET_OFFS 28
  41. #define MVPP2_RXQ_PACKET_OFFSET_MASK 0x70000000
  42. #define MVPP2_RXQ_DISABLE_MASK BIT(31)
  43. /* Top Registers */
  44. #define MVPP2_MH_REG(port) (0x5040 + 4 * (port))
  45. #define MVPP2_DSA_EXTENDED BIT(5)
  46. /* Parser Registers */
  47. #define MVPP2_PRS_INIT_LOOKUP_REG 0x1000
  48. #define MVPP2_PRS_PORT_LU_MAX 0xf
  49. #define MVPP2_PRS_PORT_LU_MASK(port) (0xff << ((port) * 4))
  50. #define MVPP2_PRS_PORT_LU_VAL(port, val) ((val) << ((port) * 4))
  51. #define MVPP2_PRS_INIT_OFFS_REG(port) (0x1004 + ((port) & 4))
  52. #define MVPP2_PRS_INIT_OFF_MASK(port) (0x3f << (((port) % 4) * 8))
  53. #define MVPP2_PRS_INIT_OFF_VAL(port, val) ((val) << (((port) % 4) * 8))
  54. #define MVPP2_PRS_MAX_LOOP_REG(port) (0x100c + ((port) & 4))
  55. #define MVPP2_PRS_MAX_LOOP_MASK(port) (0xff << (((port) % 4) * 8))
  56. #define MVPP2_PRS_MAX_LOOP_VAL(port, val) ((val) << (((port) % 4) * 8))
  57. #define MVPP2_PRS_TCAM_IDX_REG 0x1100
  58. #define MVPP2_PRS_TCAM_DATA_REG(idx) (0x1104 + (idx) * 4)
  59. #define MVPP2_PRS_TCAM_INV_MASK BIT(31)
  60. #define MVPP2_PRS_SRAM_IDX_REG 0x1200
  61. #define MVPP2_PRS_SRAM_DATA_REG(idx) (0x1204 + (idx) * 4)
  62. #define MVPP2_PRS_TCAM_CTRL_REG 0x1230
  63. #define MVPP2_PRS_TCAM_EN_MASK BIT(0)
  64. /* RSS Registers */
  65. #define MVPP22_RSS_INDEX 0x1500
  66. #define MVPP22_RSS_INDEX_TABLE_ENTRY(idx) (idx)
  67. #define MVPP22_RSS_INDEX_TABLE(idx) ((idx) << 8)
  68. #define MVPP22_RSS_INDEX_QUEUE(idx) ((idx) << 16)
  69. #define MVPP22_RSS_TABLE_ENTRY 0x1508
  70. #define MVPP22_RSS_TABLE 0x1510
  71. #define MVPP22_RSS_TABLE_POINTER(p) (p)
  72. #define MVPP22_RSS_WIDTH 0x150c
  73. /* Classifier Registers */
  74. #define MVPP2_CLS_MODE_REG 0x1800
  75. #define MVPP2_CLS_MODE_ACTIVE_MASK BIT(0)
  76. #define MVPP2_CLS_PORT_WAY_REG 0x1810
  77. #define MVPP2_CLS_PORT_WAY_MASK(port) (1 << (port))
  78. #define MVPP2_CLS_LKP_INDEX_REG 0x1814
  79. #define MVPP2_CLS_LKP_INDEX_WAY_OFFS 6
  80. #define MVPP2_CLS_LKP_TBL_REG 0x1818
  81. #define MVPP2_CLS_LKP_TBL_RXQ_MASK 0xff
  82. #define MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK BIT(25)
  83. #define MVPP2_CLS_FLOW_INDEX_REG 0x1820
  84. #define MVPP2_CLS_FLOW_TBL0_REG 0x1824
  85. #define MVPP2_CLS_FLOW_TBL1_REG 0x1828
  86. #define MVPP2_CLS_FLOW_TBL2_REG 0x182c
  87. #define MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port) (0x1980 + ((port) * 4))
  88. #define MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS 3
  89. #define MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK 0x7
  90. #define MVPP2_CLS_SWFWD_P2HQ_REG(port) (0x19b0 + ((port) * 4))
  91. #define MVPP2_CLS_SWFWD_PCTRL_REG 0x19d0
  92. #define MVPP2_CLS_SWFWD_PCTRL_MASK(port) (1 << (port))
  93. /* Descriptor Manager Top Registers */
  94. #define MVPP2_RXQ_NUM_REG 0x2040
  95. #define MVPP2_RXQ_DESC_ADDR_REG 0x2044
  96. #define MVPP22_DESC_ADDR_OFFS 8
  97. #define MVPP2_RXQ_DESC_SIZE_REG 0x2048
  98. #define MVPP2_RXQ_DESC_SIZE_MASK 0x3ff0
  99. #define MVPP2_RXQ_STATUS_UPDATE_REG(rxq) (0x3000 + 4 * (rxq))
  100. #define MVPP2_RXQ_NUM_PROCESSED_OFFSET 0
  101. #define MVPP2_RXQ_NUM_NEW_OFFSET 16
  102. #define MVPP2_RXQ_STATUS_REG(rxq) (0x3400 + 4 * (rxq))
  103. #define MVPP2_RXQ_OCCUPIED_MASK 0x3fff
  104. #define MVPP2_RXQ_NON_OCCUPIED_OFFSET 16
  105. #define MVPP2_RXQ_NON_OCCUPIED_MASK 0x3fff0000
  106. #define MVPP2_RXQ_THRESH_REG 0x204c
  107. #define MVPP2_OCCUPIED_THRESH_OFFSET 0
  108. #define MVPP2_OCCUPIED_THRESH_MASK 0x3fff
  109. #define MVPP2_RXQ_INDEX_REG 0x2050
  110. #define MVPP2_TXQ_NUM_REG 0x2080
  111. #define MVPP2_TXQ_DESC_ADDR_REG 0x2084
  112. #define MVPP2_TXQ_DESC_SIZE_REG 0x2088
  113. #define MVPP2_TXQ_DESC_SIZE_MASK 0x3ff0
  114. #define MVPP2_TXQ_THRESH_REG 0x2094
  115. #define MVPP2_TXQ_THRESH_OFFSET 16
  116. #define MVPP2_TXQ_THRESH_MASK 0x3fff
  117. #define MVPP2_AGGR_TXQ_UPDATE_REG 0x2090
  118. #define MVPP2_TXQ_INDEX_REG 0x2098
  119. #define MVPP2_TXQ_PREF_BUF_REG 0x209c
  120. #define MVPP2_PREF_BUF_PTR(desc) ((desc) & 0xfff)
  121. #define MVPP2_PREF_BUF_SIZE_4 (BIT(12) | BIT(13))
  122. #define MVPP2_PREF_BUF_SIZE_16 (BIT(12) | BIT(14))
  123. #define MVPP2_PREF_BUF_THRESH(val) ((val) << 17)
  124. #define MVPP2_TXQ_DRAIN_EN_MASK BIT(31)
  125. #define MVPP2_TXQ_PENDING_REG 0x20a0
  126. #define MVPP2_TXQ_PENDING_MASK 0x3fff
  127. #define MVPP2_TXQ_INT_STATUS_REG 0x20a4
  128. #define MVPP2_TXQ_SENT_REG(txq) (0x3c00 + 4 * (txq))
  129. #define MVPP2_TRANSMITTED_COUNT_OFFSET 16
  130. #define MVPP2_TRANSMITTED_COUNT_MASK 0x3fff0000
  131. #define MVPP2_TXQ_RSVD_REQ_REG 0x20b0
  132. #define MVPP2_TXQ_RSVD_REQ_Q_OFFSET 16
  133. #define MVPP2_TXQ_RSVD_RSLT_REG 0x20b4
  134. #define MVPP2_TXQ_RSVD_RSLT_MASK 0x3fff
  135. #define MVPP2_TXQ_RSVD_CLR_REG 0x20b8
  136. #define MVPP2_TXQ_RSVD_CLR_OFFSET 16
  137. #define MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu) (0x2100 + 4 * (cpu))
  138. #define MVPP22_AGGR_TXQ_DESC_ADDR_OFFS 8
  139. #define MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu) (0x2140 + 4 * (cpu))
  140. #define MVPP2_AGGR_TXQ_DESC_SIZE_MASK 0x3ff0
  141. #define MVPP2_AGGR_TXQ_STATUS_REG(cpu) (0x2180 + 4 * (cpu))
  142. #define MVPP2_AGGR_TXQ_PENDING_MASK 0x3fff
  143. #define MVPP2_AGGR_TXQ_INDEX_REG(cpu) (0x21c0 + 4 * (cpu))
  144. /* MBUS bridge registers */
  145. #define MVPP2_WIN_BASE(w) (0x4000 + ((w) << 2))
  146. #define MVPP2_WIN_SIZE(w) (0x4020 + ((w) << 2))
  147. #define MVPP2_WIN_REMAP(w) (0x4040 + ((w) << 2))
  148. #define MVPP2_BASE_ADDR_ENABLE 0x4060
  149. /* AXI Bridge Registers */
  150. #define MVPP22_AXI_BM_WR_ATTR_REG 0x4100
  151. #define MVPP22_AXI_BM_RD_ATTR_REG 0x4104
  152. #define MVPP22_AXI_AGGRQ_DESCR_RD_ATTR_REG 0x4110
  153. #define MVPP22_AXI_TXQ_DESCR_WR_ATTR_REG 0x4114
  154. #define MVPP22_AXI_TXQ_DESCR_RD_ATTR_REG 0x4118
  155. #define MVPP22_AXI_RXQ_DESCR_WR_ATTR_REG 0x411c
  156. #define MVPP22_AXI_RX_DATA_WR_ATTR_REG 0x4120
  157. #define MVPP22_AXI_TX_DATA_RD_ATTR_REG 0x4130
  158. #define MVPP22_AXI_RD_NORMAL_CODE_REG 0x4150
  159. #define MVPP22_AXI_RD_SNOOP_CODE_REG 0x4154
  160. #define MVPP22_AXI_WR_NORMAL_CODE_REG 0x4160
  161. #define MVPP22_AXI_WR_SNOOP_CODE_REG 0x4164
  162. /* Values for AXI Bridge registers */
  163. #define MVPP22_AXI_ATTR_CACHE_OFFS 0
  164. #define MVPP22_AXI_ATTR_DOMAIN_OFFS 12
  165. #define MVPP22_AXI_CODE_CACHE_OFFS 0
  166. #define MVPP22_AXI_CODE_DOMAIN_OFFS 4
  167. #define MVPP22_AXI_CODE_CACHE_NON_CACHE 0x3
  168. #define MVPP22_AXI_CODE_CACHE_WR_CACHE 0x7
  169. #define MVPP22_AXI_CODE_CACHE_RD_CACHE 0xb
  170. #define MVPP22_AXI_CODE_DOMAIN_OUTER_DOM 2
  171. #define MVPP22_AXI_CODE_DOMAIN_SYSTEM 3
  172. /* Interrupt Cause and Mask registers */
  173. #define MVPP2_ISR_TX_THRESHOLD_REG(port) (0x5140 + 4 * (port))
  174. #define MVPP2_MAX_ISR_TX_THRESHOLD 0xfffff0
  175. #define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq))
  176. #define MVPP2_MAX_ISR_RX_THRESHOLD 0xfffff0
  177. #define MVPP21_ISR_RXQ_GROUP_REG(port) (0x5400 + 4 * (port))
  178. #define MVPP22_ISR_RXQ_GROUP_INDEX_REG 0x5400
  179. #define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
  180. #define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380
  181. #define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET 7
  182. #define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
  183. #define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380
  184. #define MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG 0x5404
  185. #define MVPP22_ISR_RXQ_SUB_GROUP_STARTQ_MASK 0x1f
  186. #define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_MASK 0xf00
  187. #define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET 8
  188. #define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port))
  189. #define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff)
  190. #define MVPP2_ISR_DISABLE_INTERRUPT(mask) (((mask) << 16) & 0xffff0000)
  191. #define MVPP2_ISR_RX_TX_CAUSE_REG(port) (0x5480 + 4 * (port))
  192. #define MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
  193. #define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK 0xff0000
  194. #define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_OFFSET 16
  195. #define MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK BIT(24)
  196. #define MVPP2_CAUSE_FCS_ERR_MASK BIT(25)
  197. #define MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK BIT(26)
  198. #define MVPP2_CAUSE_TX_EXCEPTION_SUM_MASK BIT(29)
  199. #define MVPP2_CAUSE_RX_EXCEPTION_SUM_MASK BIT(30)
  200. #define MVPP2_CAUSE_MISC_SUM_MASK BIT(31)
  201. #define MVPP2_ISR_RX_TX_MASK_REG(port) (0x54a0 + 4 * (port))
  202. #define MVPP2_ISR_PON_RX_TX_MASK_REG 0x54bc
  203. #define MVPP2_PON_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
  204. #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK 0x3fc00000
  205. #define MVPP2_PON_CAUSE_MISC_SUM_MASK BIT(31)
  206. #define MVPP2_ISR_MISC_CAUSE_REG 0x55b0
  207. /* Buffer Manager registers */
  208. #define MVPP2_BM_POOL_BASE_REG(pool) (0x6000 + ((pool) * 4))
  209. #define MVPP2_BM_POOL_BASE_ADDR_MASK 0xfffff80
  210. #define MVPP2_BM_POOL_SIZE_REG(pool) (0x6040 + ((pool) * 4))
  211. #define MVPP2_BM_POOL_SIZE_MASK 0xfff0
  212. #define MVPP2_BM_POOL_READ_PTR_REG(pool) (0x6080 + ((pool) * 4))
  213. #define MVPP2_BM_POOL_GET_READ_PTR_MASK 0xfff0
  214. #define MVPP2_BM_POOL_PTRS_NUM_REG(pool) (0x60c0 + ((pool) * 4))
  215. #define MVPP2_BM_POOL_PTRS_NUM_MASK 0xfff0
  216. #define MVPP2_BM_BPPI_READ_PTR_REG(pool) (0x6100 + ((pool) * 4))
  217. #define MVPP2_BM_BPPI_PTRS_NUM_REG(pool) (0x6140 + ((pool) * 4))
  218. #define MVPP2_BM_BPPI_PTR_NUM_MASK 0x7ff
  219. #define MVPP22_BM_POOL_PTRS_NUM_MASK 0xfff8
  220. #define MVPP2_BM_BPPI_PREFETCH_FULL_MASK BIT(16)
  221. #define MVPP2_BM_POOL_CTRL_REG(pool) (0x6200 + ((pool) * 4))
  222. #define MVPP2_BM_START_MASK BIT(0)
  223. #define MVPP2_BM_STOP_MASK BIT(1)
  224. #define MVPP2_BM_STATE_MASK BIT(4)
  225. #define MVPP2_BM_LOW_THRESH_OFFS 8
  226. #define MVPP2_BM_LOW_THRESH_MASK 0x7f00
  227. #define MVPP2_BM_LOW_THRESH_VALUE(val) ((val) << \
  228. MVPP2_BM_LOW_THRESH_OFFS)
  229. #define MVPP2_BM_HIGH_THRESH_OFFS 16
  230. #define MVPP2_BM_HIGH_THRESH_MASK 0x7f0000
  231. #define MVPP2_BM_HIGH_THRESH_VALUE(val) ((val) << \
  232. MVPP2_BM_HIGH_THRESH_OFFS)
  233. #define MVPP2_BM_INTR_CAUSE_REG(pool) (0x6240 + ((pool) * 4))
  234. #define MVPP2_BM_RELEASED_DELAY_MASK BIT(0)
  235. #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
  236. #define MVPP2_BM_BPPE_EMPTY_MASK BIT(2)
  237. #define MVPP2_BM_BPPE_FULL_MASK BIT(3)
  238. #define MVPP2_BM_AVAILABLE_BP_LOW_MASK BIT(4)
  239. #define MVPP2_BM_INTR_MASK_REG(pool) (0x6280 + ((pool) * 4))
  240. #define MVPP2_BM_PHY_ALLOC_REG(pool) (0x6400 + ((pool) * 4))
  241. #define MVPP2_BM_PHY_ALLOC_GRNTD_MASK BIT(0)
  242. #define MVPP2_BM_VIRT_ALLOC_REG 0x6440
  243. #define MVPP22_BM_ADDR_HIGH_ALLOC 0x6444
  244. #define MVPP22_BM_ADDR_HIGH_PHYS_MASK 0xff
  245. #define MVPP22_BM_ADDR_HIGH_VIRT_MASK 0xff00
  246. #define MVPP22_BM_ADDR_HIGH_VIRT_SHIFT 8
  247. #define MVPP2_BM_PHY_RLS_REG(pool) (0x6480 + ((pool) * 4))
  248. #define MVPP2_BM_PHY_RLS_MC_BUFF_MASK BIT(0)
  249. #define MVPP2_BM_PHY_RLS_PRIO_EN_MASK BIT(1)
  250. #define MVPP2_BM_PHY_RLS_GRNTD_MASK BIT(2)
  251. #define MVPP2_BM_VIRT_RLS_REG 0x64c0
  252. #define MVPP22_BM_ADDR_HIGH_RLS_REG 0x64c4
  253. #define MVPP22_BM_ADDR_HIGH_PHYS_RLS_MASK 0xff
  254. #define MVPP22_BM_ADDR_HIGH_VIRT_RLS_MASK 0xff00
  255. #define MVPP22_BM_ADDR_HIGH_VIRT_RLS_SHIFT 8
  256. /* TX Scheduler registers */
  257. #define MVPP2_TXP_SCHED_PORT_INDEX_REG 0x8000
  258. #define MVPP2_TXP_SCHED_Q_CMD_REG 0x8004
  259. #define MVPP2_TXP_SCHED_ENQ_MASK 0xff
  260. #define MVPP2_TXP_SCHED_DISQ_OFFSET 8
  261. #define MVPP2_TXP_SCHED_CMD_1_REG 0x8010
  262. #define MVPP2_TXP_SCHED_PERIOD_REG 0x8018
  263. #define MVPP2_TXP_SCHED_MTU_REG 0x801c
  264. #define MVPP2_TXP_MTU_MAX 0x7FFFF
  265. #define MVPP2_TXP_SCHED_REFILL_REG 0x8020
  266. #define MVPP2_TXP_REFILL_TOKENS_ALL_MASK 0x7ffff
  267. #define MVPP2_TXP_REFILL_PERIOD_ALL_MASK 0x3ff00000
  268. #define MVPP2_TXP_REFILL_PERIOD_MASK(v) ((v) << 20)
  269. #define MVPP2_TXP_SCHED_TOKEN_SIZE_REG 0x8024
  270. #define MVPP2_TXP_TOKEN_SIZE_MAX 0xffffffff
  271. #define MVPP2_TXQ_SCHED_REFILL_REG(q) (0x8040 + ((q) << 2))
  272. #define MVPP2_TXQ_REFILL_TOKENS_ALL_MASK 0x7ffff
  273. #define MVPP2_TXQ_REFILL_PERIOD_ALL_MASK 0x3ff00000
  274. #define MVPP2_TXQ_REFILL_PERIOD_MASK(v) ((v) << 20)
  275. #define MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(q) (0x8060 + ((q) << 2))
  276. #define MVPP2_TXQ_TOKEN_SIZE_MAX 0x7fffffff
  277. #define MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(q) (0x8080 + ((q) << 2))
  278. #define MVPP2_TXQ_TOKEN_CNTR_MAX 0xffffffff
  279. /* TX general registers */
  280. #define MVPP2_TX_SNOOP_REG 0x8800
  281. #define MVPP2_TX_PORT_FLUSH_REG 0x8810
  282. #define MVPP2_TX_PORT_FLUSH_MASK(port) (1 << (port))
  283. /* LMS registers */
  284. #define MVPP2_SRC_ADDR_MIDDLE 0x24
  285. #define MVPP2_SRC_ADDR_HIGH 0x28
  286. #define MVPP2_PHY_AN_CFG0_REG 0x34
  287. #define MVPP2_PHY_AN_STOP_SMI0_MASK BIT(7)
  288. #define MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG 0x305c
  289. #define MVPP2_EXT_GLOBAL_CTRL_DEFAULT 0x27
  290. /* Per-port registers */
  291. #define MVPP2_GMAC_CTRL_0_REG 0x0
  292. #define MVPP2_GMAC_PORT_EN_MASK BIT(0)
  293. #define MVPP2_GMAC_PORT_TYPE_MASK BIT(1)
  294. #define MVPP2_GMAC_MAX_RX_SIZE_OFFS 2
  295. #define MVPP2_GMAC_MAX_RX_SIZE_MASK 0x7ffc
  296. #define MVPP2_GMAC_MIB_CNTR_EN_MASK BIT(15)
  297. #define MVPP2_GMAC_CTRL_1_REG 0x4
  298. #define MVPP2_GMAC_PERIODIC_XON_EN_MASK BIT(1)
  299. #define MVPP2_GMAC_GMII_LB_EN_MASK BIT(5)
  300. #define MVPP2_GMAC_PCS_LB_EN_BIT 6
  301. #define MVPP2_GMAC_PCS_LB_EN_MASK BIT(6)
  302. #define MVPP2_GMAC_SA_LOW_OFFS 7
  303. #define MVPP2_GMAC_CTRL_2_REG 0x8
  304. #define MVPP2_GMAC_INBAND_AN_MASK BIT(0)
  305. #define MVPP2_GMAC_FLOW_CTRL_MASK GENMASK(2, 1)
  306. #define MVPP2_GMAC_PCS_ENABLE_MASK BIT(3)
  307. #define MVPP2_GMAC_INTERNAL_CLK_MASK BIT(4)
  308. #define MVPP2_GMAC_DISABLE_PADDING BIT(5)
  309. #define MVPP2_GMAC_PORT_RESET_MASK BIT(6)
  310. #define MVPP2_GMAC_AUTONEG_CONFIG 0xc
  311. #define MVPP2_GMAC_FORCE_LINK_DOWN BIT(0)
  312. #define MVPP2_GMAC_FORCE_LINK_PASS BIT(1)
  313. #define MVPP2_GMAC_IN_BAND_AUTONEG BIT(2)
  314. #define MVPP2_GMAC_IN_BAND_AUTONEG_BYPASS BIT(3)
  315. #define MVPP2_GMAC_IN_BAND_RESTART_AN BIT(4)
  316. #define MVPP2_GMAC_CONFIG_MII_SPEED BIT(5)
  317. #define MVPP2_GMAC_CONFIG_GMII_SPEED BIT(6)
  318. #define MVPP2_GMAC_AN_SPEED_EN BIT(7)
  319. #define MVPP2_GMAC_FC_ADV_EN BIT(9)
  320. #define MVPP2_GMAC_FC_ADV_ASM_EN BIT(10)
  321. #define MVPP2_GMAC_FLOW_CTRL_AUTONEG BIT(11)
  322. #define MVPP2_GMAC_CONFIG_FULL_DUPLEX BIT(12)
  323. #define MVPP2_GMAC_AN_DUPLEX_EN BIT(13)
  324. #define MVPP2_GMAC_STATUS0 0x10
  325. #define MVPP2_GMAC_STATUS0_LINK_UP BIT(0)
  326. #define MVPP2_GMAC_STATUS0_GMII_SPEED BIT(1)
  327. #define MVPP2_GMAC_STATUS0_MII_SPEED BIT(2)
  328. #define MVPP2_GMAC_STATUS0_FULL_DUPLEX BIT(3)
  329. #define MVPP2_GMAC_STATUS0_RX_PAUSE BIT(6)
  330. #define MVPP2_GMAC_STATUS0_TX_PAUSE BIT(7)
  331. #define MVPP2_GMAC_STATUS0_AN_COMPLETE BIT(11)
  332. #define MVPP2_GMAC_PORT_FIFO_CFG_1_REG 0x1c
  333. #define MVPP2_GMAC_TX_FIFO_MIN_TH_OFFS 6
  334. #define MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK 0x1fc0
  335. #define MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(v) (((v) << 6) & \
  336. MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK)
  337. #define MVPP22_GMAC_INT_STAT 0x20
  338. #define MVPP22_GMAC_INT_STAT_LINK BIT(1)
  339. #define MVPP22_GMAC_INT_MASK 0x24
  340. #define MVPP22_GMAC_INT_MASK_LINK_STAT BIT(1)
  341. #define MVPP22_GMAC_CTRL_4_REG 0x90
  342. #define MVPP22_CTRL4_EXT_PIN_GMII_SEL BIT(0)
  343. #define MVPP22_CTRL4_RX_FC_EN BIT(3)
  344. #define MVPP22_CTRL4_TX_FC_EN BIT(4)
  345. #define MVPP22_CTRL4_DP_CLK_SEL BIT(5)
  346. #define MVPP22_CTRL4_SYNC_BYPASS_DIS BIT(6)
  347. #define MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE BIT(7)
  348. #define MVPP22_GMAC_INT_SUM_MASK 0xa4
  349. #define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
  350. /* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
  351. * relative to port->base.
  352. */
  353. #define MVPP22_XLG_CTRL0_REG 0x100
  354. #define MVPP22_XLG_CTRL0_PORT_EN BIT(0)
  355. #define MVPP22_XLG_CTRL0_MAC_RESET_DIS BIT(1)
  356. #define MVPP22_XLG_CTRL0_RX_FLOW_CTRL_EN BIT(7)
  357. #define MVPP22_XLG_CTRL0_TX_FLOW_CTRL_EN BIT(8)
  358. #define MVPP22_XLG_CTRL0_MIB_CNT_DIS BIT(14)
  359. #define MVPP22_XLG_CTRL1_REG 0x104
  360. #define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_OFFS 0
  361. #define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_MASK 0x1fff
  362. #define MVPP22_XLG_STATUS 0x10c
  363. #define MVPP22_XLG_STATUS_LINK_UP BIT(0)
  364. #define MVPP22_XLG_INT_STAT 0x114
  365. #define MVPP22_XLG_INT_STAT_LINK BIT(1)
  366. #define MVPP22_XLG_INT_MASK 0x118
  367. #define MVPP22_XLG_INT_MASK_LINK BIT(1)
  368. #define MVPP22_XLG_CTRL3_REG 0x11c
  369. #define MVPP22_XLG_CTRL3_MACMODESELECT_MASK (7 << 13)
  370. #define MVPP22_XLG_CTRL3_MACMODESELECT_GMAC (0 << 13)
  371. #define MVPP22_XLG_CTRL3_MACMODESELECT_10G (1 << 13)
  372. #define MVPP22_XLG_EXT_INT_MASK 0x15c
  373. #define MVPP22_XLG_EXT_INT_MASK_XLG BIT(1)
  374. #define MVPP22_XLG_EXT_INT_MASK_GIG BIT(2)
  375. #define MVPP22_XLG_CTRL4_REG 0x184
  376. #define MVPP22_XLG_CTRL4_FWD_FC BIT(5)
  377. #define MVPP22_XLG_CTRL4_FWD_PFC BIT(6)
  378. #define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
  379. #define MVPP22_XLG_CTRL4_EN_IDLE_CHECK BIT(14)
  380. /* SMI registers. PPv2.2 only, relative to priv->iface_base. */
  381. #define MVPP22_SMI_MISC_CFG_REG 0x1204
  382. #define MVPP22_SMI_POLLING_EN BIT(10)
  383. #define MVPP22_GMAC_BASE(port) (0x7000 + (port) * 0x1000 + 0xe00)
  384. #define MVPP2_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
  385. /* Descriptor ring Macros */
  386. #define MVPP2_QUEUE_NEXT_DESC(q, index) \
  387. (((index) < (q)->last_desc) ? ((index) + 1) : 0)
  388. /* XPCS registers. PPv2.2 only */
  389. #define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
  390. #define MVPP22_MPCS_CTRL 0x14
  391. #define MVPP22_MPCS_CTRL_FWD_ERR_CONN BIT(10)
  392. #define MVPP22_MPCS_CLK_RESET 0x14c
  393. #define MAC_CLK_RESET_SD_TX BIT(0)
  394. #define MAC_CLK_RESET_SD_RX BIT(1)
  395. #define MAC_CLK_RESET_MAC BIT(2)
  396. #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
  397. #define MVPP22_MPCS_CLK_RESET_DIV_SET BIT(11)
  398. /* XPCS registers. PPv2.2 only */
  399. #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
  400. #define MVPP22_XPCS_CFG0 0x0
  401. #define MVPP22_XPCS_CFG0_PCS_MODE(n) ((n) << 3)
  402. #define MVPP22_XPCS_CFG0_ACTIVE_LANE(n) ((n) << 5)
  403. /* System controller registers. Accessed through a regmap. */
  404. #define GENCONF_SOFT_RESET1 0x1108
  405. #define GENCONF_SOFT_RESET1_GOP BIT(6)
  406. #define GENCONF_PORT_CTRL0 0x1110
  407. #define GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT BIT(1)
  408. #define GENCONF_PORT_CTRL0_RX_DATA_SAMPLE BIT(29)
  409. #define GENCONF_PORT_CTRL0_CLK_DIV_PHASE_CLR BIT(31)
  410. #define GENCONF_PORT_CTRL1 0x1114
  411. #define GENCONF_PORT_CTRL1_EN(p) BIT(p)
  412. #define GENCONF_PORT_CTRL1_RESET(p) (BIT(p) << 28)
  413. #define GENCONF_CTRL0 0x1120
  414. #define GENCONF_CTRL0_PORT0_RGMII BIT(0)
  415. #define GENCONF_CTRL0_PORT1_RGMII_MII BIT(1)
  416. #define GENCONF_CTRL0_PORT1_RGMII BIT(2)
  417. /* Various constants */
  418. /* Coalescing */
  419. #define MVPP2_TXDONE_COAL_PKTS_THRESH 64
  420. #define MVPP2_TXDONE_HRTIMER_PERIOD_NS 1000000UL
  421. #define MVPP2_TXDONE_COAL_USEC 1000
  422. #define MVPP2_RX_COAL_PKTS 32
  423. #define MVPP2_RX_COAL_USEC 64
  424. /* The two bytes Marvell header. Either contains a special value used
  425. * by Marvell switches when a specific hardware mode is enabled (not
  426. * supported by this driver) or is filled automatically by zeroes on
  427. * the RX side. Those two bytes being at the front of the Ethernet
  428. * header, they allow to have the IP header aligned on a 4 bytes
  429. * boundary automatically: the hardware skips those two bytes on its
  430. * own.
  431. */
  432. #define MVPP2_MH_SIZE 2
  433. #define MVPP2_ETH_TYPE_LEN 2
  434. #define MVPP2_PPPOE_HDR_SIZE 8
  435. #define MVPP2_VLAN_TAG_LEN 4
  436. #define MVPP2_VLAN_TAG_EDSA_LEN 8
  437. /* Lbtd 802.3 type */
  438. #define MVPP2_IP_LBDT_TYPE 0xfffa
  439. #define MVPP2_TX_CSUM_MAX_SIZE 9800
  440. /* Timeout constants */
  441. #define MVPP2_TX_DISABLE_TIMEOUT_MSEC 1000
  442. #define MVPP2_TX_PENDING_TIMEOUT_MSEC 1000
  443. #define MVPP2_TX_MTU_MAX 0x7ffff
  444. /* Maximum number of T-CONTs of PON port */
  445. #define MVPP2_MAX_TCONT 16
  446. /* Maximum number of supported ports */
  447. #define MVPP2_MAX_PORTS 4
  448. /* Maximum number of TXQs used by single port */
  449. #define MVPP2_MAX_TXQ 8
  450. /* MVPP2_MAX_TSO_SEGS is the maximum number of fragments to allow in the GSO
  451. * skb. As we need a maxium of two descriptors per fragments (1 header, 1 data),
  452. * multiply this value by two to count the maximum number of skb descs needed.
  453. */
  454. #define MVPP2_MAX_TSO_SEGS 300
  455. #define MVPP2_MAX_SKB_DESCS (MVPP2_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS)
  456. /* Dfault number of RXQs in use */
  457. #define MVPP2_DEFAULT_RXQ 4
  458. /* Max number of Rx descriptors */
  459. #define MVPP2_MAX_RXD_MAX 1024
  460. #define MVPP2_MAX_RXD_DFLT 128
  461. /* Max number of Tx descriptors */
  462. #define MVPP2_MAX_TXD_MAX 2048
  463. #define MVPP2_MAX_TXD_DFLT 1024
  464. /* Amount of Tx descriptors that can be reserved at once by CPU */
  465. #define MVPP2_CPU_DESC_CHUNK 64
  466. /* Max number of Tx descriptors in each aggregated queue */
  467. #define MVPP2_AGGR_TXQ_SIZE 256
  468. /* Descriptor aligned size */
  469. #define MVPP2_DESC_ALIGNED_SIZE 32
  470. /* Descriptor alignment mask */
  471. #define MVPP2_TX_DESC_ALIGN (MVPP2_DESC_ALIGNED_SIZE - 1)
  472. /* RX FIFO constants */
  473. #define MVPP2_RX_FIFO_PORT_DATA_SIZE_32KB 0x8000
  474. #define MVPP2_RX_FIFO_PORT_DATA_SIZE_8KB 0x2000
  475. #define MVPP2_RX_FIFO_PORT_DATA_SIZE_4KB 0x1000
  476. #define MVPP2_RX_FIFO_PORT_ATTR_SIZE_32KB 0x200
  477. #define MVPP2_RX_FIFO_PORT_ATTR_SIZE_8KB 0x80
  478. #define MVPP2_RX_FIFO_PORT_ATTR_SIZE_4KB 0x40
  479. #define MVPP2_RX_FIFO_PORT_MIN_PKT 0x80
  480. /* TX FIFO constants */
  481. #define MVPP22_TX_FIFO_DATA_SIZE_10KB 0xa
  482. #define MVPP22_TX_FIFO_DATA_SIZE_3KB 0x3
  483. #define MVPP2_TX_FIFO_THRESHOLD_MIN 256
  484. #define MVPP2_TX_FIFO_THRESHOLD_10KB \
  485. (MVPP22_TX_FIFO_DATA_SIZE_10KB * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
  486. #define MVPP2_TX_FIFO_THRESHOLD_3KB \
  487. (MVPP22_TX_FIFO_DATA_SIZE_3KB * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
  488. /* RX buffer constants */
  489. #define MVPP2_SKB_SHINFO_SIZE \
  490. SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
  491. #define MVPP2_RX_PKT_SIZE(mtu) \
  492. ALIGN((mtu) + MVPP2_MH_SIZE + MVPP2_VLAN_TAG_LEN + \
  493. ETH_HLEN + ETH_FCS_LEN, cache_line_size())
  494. #define MVPP2_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD)
  495. #define MVPP2_RX_TOTAL_SIZE(buf_size) ((buf_size) + MVPP2_SKB_SHINFO_SIZE)
  496. #define MVPP2_RX_MAX_PKT_SIZE(total_size) \
  497. ((total_size) - NET_SKB_PAD - MVPP2_SKB_SHINFO_SIZE)
  498. #define MVPP2_BIT_TO_BYTE(bit) ((bit) / 8)
  499. /* IPv6 max L3 address size */
  500. #define MVPP2_MAX_L3_ADDR_SIZE 16
  501. /* Port flags */
  502. #define MVPP2_F_LOOPBACK BIT(0)
  503. /* Marvell tag types */
  504. enum mvpp2_tag_type {
  505. MVPP2_TAG_TYPE_NONE = 0,
  506. MVPP2_TAG_TYPE_MH = 1,
  507. MVPP2_TAG_TYPE_DSA = 2,
  508. MVPP2_TAG_TYPE_EDSA = 3,
  509. MVPP2_TAG_TYPE_VLAN = 4,
  510. MVPP2_TAG_TYPE_LAST = 5
  511. };
  512. /* L2 cast enum */
  513. enum mvpp2_prs_l2_cast {
  514. MVPP2_PRS_L2_UNI_CAST,
  515. MVPP2_PRS_L2_MULTI_CAST,
  516. };
  517. /* L3 cast enum */
  518. enum mvpp2_prs_l3_cast {
  519. MVPP2_PRS_L3_UNI_CAST,
  520. MVPP2_PRS_L3_MULTI_CAST,
  521. MVPP2_PRS_L3_BROAD_CAST
  522. };
  523. /* BM constants */
  524. #define MVPP2_BM_JUMBO_BUF_NUM 512
  525. #define MVPP2_BM_LONG_BUF_NUM 1024
  526. #define MVPP2_BM_SHORT_BUF_NUM 2048
  527. #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
  528. #define MVPP2_BM_POOL_PTR_ALIGN 128
  529. /* BM cookie (32 bits) definition */
  530. #define MVPP2_BM_COOKIE_POOL_OFFS 8
  531. #define MVPP2_BM_COOKIE_CPU_OFFS 24
  532. #define MVPP2_BM_SHORT_FRAME_SIZE 512
  533. #define MVPP2_BM_LONG_FRAME_SIZE 2048
  534. #define MVPP2_BM_JUMBO_FRAME_SIZE 10240
  535. /* BM short pool packet size
  536. * These value assure that for SWF the total number
  537. * of bytes allocated for each buffer will be 512
  538. */
  539. #define MVPP2_BM_SHORT_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(MVPP2_BM_SHORT_FRAME_SIZE)
  540. #define MVPP2_BM_LONG_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(MVPP2_BM_LONG_FRAME_SIZE)
  541. #define MVPP2_BM_JUMBO_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(MVPP2_BM_JUMBO_FRAME_SIZE)
  542. #define MVPP21_ADDR_SPACE_SZ 0
  543. #define MVPP22_ADDR_SPACE_SZ SZ_64K
  544. #define MVPP2_MAX_THREADS 8
  545. #define MVPP2_MAX_QVECS MVPP2_MAX_THREADS
  546. /* GMAC MIB Counters register definitions */
  547. #define MVPP21_MIB_COUNTERS_OFFSET 0x1000
  548. #define MVPP21_MIB_COUNTERS_PORT_SZ 0x400
  549. #define MVPP22_MIB_COUNTERS_OFFSET 0x0
  550. #define MVPP22_MIB_COUNTERS_PORT_SZ 0x100
  551. #define MVPP2_MIB_GOOD_OCTETS_RCVD 0x0
  552. #define MVPP2_MIB_BAD_OCTETS_RCVD 0x8
  553. #define MVPP2_MIB_CRC_ERRORS_SENT 0xc
  554. #define MVPP2_MIB_UNICAST_FRAMES_RCVD 0x10
  555. #define MVPP2_MIB_BROADCAST_FRAMES_RCVD 0x18
  556. #define MVPP2_MIB_MULTICAST_FRAMES_RCVD 0x1c
  557. #define MVPP2_MIB_FRAMES_64_OCTETS 0x20
  558. #define MVPP2_MIB_FRAMES_65_TO_127_OCTETS 0x24
  559. #define MVPP2_MIB_FRAMES_128_TO_255_OCTETS 0x28
  560. #define MVPP2_MIB_FRAMES_256_TO_511_OCTETS 0x2c
  561. #define MVPP2_MIB_FRAMES_512_TO_1023_OCTETS 0x30
  562. #define MVPP2_MIB_FRAMES_1024_TO_MAX_OCTETS 0x34
  563. #define MVPP2_MIB_GOOD_OCTETS_SENT 0x38
  564. #define MVPP2_MIB_UNICAST_FRAMES_SENT 0x40
  565. #define MVPP2_MIB_MULTICAST_FRAMES_SENT 0x48
  566. #define MVPP2_MIB_BROADCAST_FRAMES_SENT 0x4c
  567. #define MVPP2_MIB_FC_SENT 0x54
  568. #define MVPP2_MIB_FC_RCVD 0x58
  569. #define MVPP2_MIB_RX_FIFO_OVERRUN 0x5c
  570. #define MVPP2_MIB_UNDERSIZE_RCVD 0x60
  571. #define MVPP2_MIB_FRAGMENTS_RCVD 0x64
  572. #define MVPP2_MIB_OVERSIZE_RCVD 0x68
  573. #define MVPP2_MIB_JABBER_RCVD 0x6c
  574. #define MVPP2_MIB_MAC_RCV_ERROR 0x70
  575. #define MVPP2_MIB_BAD_CRC_EVENT 0x74
  576. #define MVPP2_MIB_COLLISION 0x78
  577. #define MVPP2_MIB_LATE_COLLISION 0x7c
  578. #define MVPP2_MIB_COUNTERS_STATS_DELAY (1 * HZ)
  579. #define MVPP2_DESC_DMA_MASK DMA_BIT_MASK(40)
  580. /* Definitions */
  581. /* Shared Packet Processor resources */
  582. struct mvpp2 {
  583. /* Shared registers' base addresses */
  584. void __iomem *lms_base;
  585. void __iomem *iface_base;
  586. /* On PPv2.2, each "software thread" can access the base
  587. * register through a separate address space, each 64 KB apart
  588. * from each other. Typically, such address spaces will be
  589. * used per CPU.
  590. */
  591. void __iomem *swth_base[MVPP2_MAX_THREADS];
  592. /* On PPv2.2, some port control registers are located into the system
  593. * controller space. These registers are accessible through a regmap.
  594. */
  595. struct regmap *sysctrl_base;
  596. /* Common clocks */
  597. struct clk *pp_clk;
  598. struct clk *gop_clk;
  599. struct clk *mg_clk;
  600. struct clk *mg_core_clk;
  601. struct clk *axi_clk;
  602. /* List of pointers to port structures */
  603. int port_count;
  604. struct mvpp2_port *port_list[MVPP2_MAX_PORTS];
  605. /* Aggregated TXQs */
  606. struct mvpp2_tx_queue *aggr_txqs;
  607. /* BM pools */
  608. struct mvpp2_bm_pool *bm_pools;
  609. /* PRS shadow table */
  610. struct mvpp2_prs_shadow *prs_shadow;
  611. /* PRS auxiliary table for double vlan entries control */
  612. bool *prs_double_vlans;
  613. /* Tclk value */
  614. u32 tclk;
  615. /* HW version */
  616. enum { MVPP21, MVPP22 } hw_version;
  617. /* Maximum number of RXQs per port */
  618. unsigned int max_port_rxqs;
  619. /* Workqueue to gather hardware statistics */
  620. char queue_name[30];
  621. struct workqueue_struct *stats_queue;
  622. };
  623. struct mvpp2_pcpu_stats {
  624. struct u64_stats_sync syncp;
  625. u64 rx_packets;
  626. u64 rx_bytes;
  627. u64 tx_packets;
  628. u64 tx_bytes;
  629. };
  630. /* Per-CPU port control */
  631. struct mvpp2_port_pcpu {
  632. struct hrtimer tx_done_timer;
  633. bool timer_scheduled;
  634. /* Tasklet for egress finalization */
  635. struct tasklet_struct tx_done_tasklet;
  636. };
  637. struct mvpp2_queue_vector {
  638. int irq;
  639. struct napi_struct napi;
  640. enum { MVPP2_QUEUE_VECTOR_SHARED, MVPP2_QUEUE_VECTOR_PRIVATE } type;
  641. int sw_thread_id;
  642. u16 sw_thread_mask;
  643. int first_rxq;
  644. int nrxqs;
  645. u32 pending_cause_rx;
  646. struct mvpp2_port *port;
  647. };
  648. struct mvpp2_port {
  649. u8 id;
  650. /* Index of the port from the "group of ports" complex point
  651. * of view
  652. */
  653. int gop_id;
  654. int link_irq;
  655. struct mvpp2 *priv;
  656. /* Firmware node associated to the port */
  657. struct fwnode_handle *fwnode;
  658. /* Is a PHY always connected to the port */
  659. bool has_phy;
  660. /* Per-port registers' base address */
  661. void __iomem *base;
  662. void __iomem *stats_base;
  663. struct mvpp2_rx_queue **rxqs;
  664. unsigned int nrxqs;
  665. struct mvpp2_tx_queue **txqs;
  666. unsigned int ntxqs;
  667. struct net_device *dev;
  668. int pkt_size;
  669. /* Per-CPU port control */
  670. struct mvpp2_port_pcpu __percpu *pcpu;
  671. /* Flags */
  672. unsigned long flags;
  673. u16 tx_ring_size;
  674. u16 rx_ring_size;
  675. struct mvpp2_pcpu_stats __percpu *stats;
  676. u64 *ethtool_stats;
  677. /* Per-port work and its lock to gather hardware statistics */
  678. struct mutex gather_stats_lock;
  679. struct delayed_work stats_work;
  680. struct device_node *of_node;
  681. phy_interface_t phy_interface;
  682. struct phylink *phylink;
  683. struct phy *comphy;
  684. struct mvpp2_bm_pool *pool_long;
  685. struct mvpp2_bm_pool *pool_short;
  686. /* Index of first port's physical RXQ */
  687. u8 first_rxq;
  688. struct mvpp2_queue_vector qvecs[MVPP2_MAX_QVECS];
  689. unsigned int nqvecs;
  690. bool has_tx_irqs;
  691. u32 tx_time_coal;
  692. };
  693. /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
  694. * layout of the transmit and reception DMA descriptors, and their
  695. * layout is therefore defined by the hardware design
  696. */
  697. #define MVPP2_TXD_L3_OFF_SHIFT 0
  698. #define MVPP2_TXD_IP_HLEN_SHIFT 8
  699. #define MVPP2_TXD_L4_CSUM_FRAG BIT(13)
  700. #define MVPP2_TXD_L4_CSUM_NOT BIT(14)
  701. #define MVPP2_TXD_IP_CSUM_DISABLE BIT(15)
  702. #define MVPP2_TXD_PADDING_DISABLE BIT(23)
  703. #define MVPP2_TXD_L4_UDP BIT(24)
  704. #define MVPP2_TXD_L3_IP6 BIT(26)
  705. #define MVPP2_TXD_L_DESC BIT(28)
  706. #define MVPP2_TXD_F_DESC BIT(29)
  707. #define MVPP2_RXD_ERR_SUMMARY BIT(15)
  708. #define MVPP2_RXD_ERR_CODE_MASK (BIT(13) | BIT(14))
  709. #define MVPP2_RXD_ERR_CRC 0x0
  710. #define MVPP2_RXD_ERR_OVERRUN BIT(13)
  711. #define MVPP2_RXD_ERR_RESOURCE (BIT(13) | BIT(14))
  712. #define MVPP2_RXD_BM_POOL_ID_OFFS 16
  713. #define MVPP2_RXD_BM_POOL_ID_MASK (BIT(16) | BIT(17) | BIT(18))
  714. #define MVPP2_RXD_HWF_SYNC BIT(21)
  715. #define MVPP2_RXD_L4_CSUM_OK BIT(22)
  716. #define MVPP2_RXD_IP4_HEADER_ERR BIT(24)
  717. #define MVPP2_RXD_L4_TCP BIT(25)
  718. #define MVPP2_RXD_L4_UDP BIT(26)
  719. #define MVPP2_RXD_L3_IP4 BIT(28)
  720. #define MVPP2_RXD_L3_IP6 BIT(30)
  721. #define MVPP2_RXD_BUF_HDR BIT(31)
  722. /* HW TX descriptor for PPv2.1 */
  723. struct mvpp21_tx_desc {
  724. u32 command; /* Options used by HW for packet transmitting.*/
  725. u8 packet_offset; /* the offset from the buffer beginning */
  726. u8 phys_txq; /* destination queue ID */
  727. u16 data_size; /* data size of transmitted packet in bytes */
  728. u32 buf_dma_addr; /* physical addr of transmitted buffer */
  729. u32 buf_cookie; /* cookie for access to TX buffer in tx path */
  730. u32 reserved1[3]; /* hw_cmd (for future use, BM, PON, PNC) */
  731. u32 reserved2; /* reserved (for future use) */
  732. };
  733. /* HW RX descriptor for PPv2.1 */
  734. struct mvpp21_rx_desc {
  735. u32 status; /* info about received packet */
  736. u16 reserved1; /* parser_info (for future use, PnC) */
  737. u16 data_size; /* size of received packet in bytes */
  738. u32 buf_dma_addr; /* physical address of the buffer */
  739. u32 buf_cookie; /* cookie for access to RX buffer in rx path */
  740. u16 reserved2; /* gem_port_id (for future use, PON) */
  741. u16 reserved3; /* csum_l4 (for future use, PnC) */
  742. u8 reserved4; /* bm_qset (for future use, BM) */
  743. u8 reserved5;
  744. u16 reserved6; /* classify_info (for future use, PnC) */
  745. u32 reserved7; /* flow_id (for future use, PnC) */
  746. u32 reserved8;
  747. };
  748. /* HW TX descriptor for PPv2.2 */
  749. struct mvpp22_tx_desc {
  750. u32 command;
  751. u8 packet_offset;
  752. u8 phys_txq;
  753. u16 data_size;
  754. u64 reserved1;
  755. u64 buf_dma_addr_ptp;
  756. u64 buf_cookie_misc;
  757. };
  758. /* HW RX descriptor for PPv2.2 */
  759. struct mvpp22_rx_desc {
  760. u32 status;
  761. u16 reserved1;
  762. u16 data_size;
  763. u32 reserved2;
  764. u32 reserved3;
  765. u64 buf_dma_addr_key_hash;
  766. u64 buf_cookie_misc;
  767. };
  768. /* Opaque type used by the driver to manipulate the HW TX and RX
  769. * descriptors
  770. */
  771. struct mvpp2_tx_desc {
  772. union {
  773. struct mvpp21_tx_desc pp21;
  774. struct mvpp22_tx_desc pp22;
  775. };
  776. };
  777. struct mvpp2_rx_desc {
  778. union {
  779. struct mvpp21_rx_desc pp21;
  780. struct mvpp22_rx_desc pp22;
  781. };
  782. };
  783. struct mvpp2_txq_pcpu_buf {
  784. /* Transmitted SKB */
  785. struct sk_buff *skb;
  786. /* Physical address of transmitted buffer */
  787. dma_addr_t dma;
  788. /* Size transmitted */
  789. size_t size;
  790. };
  791. /* Per-CPU Tx queue control */
  792. struct mvpp2_txq_pcpu {
  793. int cpu;
  794. /* Number of Tx DMA descriptors in the descriptor ring */
  795. int size;
  796. /* Number of currently used Tx DMA descriptor in the
  797. * descriptor ring
  798. */
  799. int count;
  800. int wake_threshold;
  801. int stop_threshold;
  802. /* Number of Tx DMA descriptors reserved for each CPU */
  803. int reserved_num;
  804. /* Infos about transmitted buffers */
  805. struct mvpp2_txq_pcpu_buf *buffs;
  806. /* Index of last TX DMA descriptor that was inserted */
  807. int txq_put_index;
  808. /* Index of the TX DMA descriptor to be cleaned up */
  809. int txq_get_index;
  810. /* DMA buffer for TSO headers */
  811. char *tso_headers;
  812. dma_addr_t tso_headers_dma;
  813. };
  814. struct mvpp2_tx_queue {
  815. /* Physical number of this Tx queue */
  816. u8 id;
  817. /* Logical number of this Tx queue */
  818. u8 log_id;
  819. /* Number of Tx DMA descriptors in the descriptor ring */
  820. int size;
  821. /* Number of currently used Tx DMA descriptor in the descriptor ring */
  822. int count;
  823. /* Per-CPU control of physical Tx queues */
  824. struct mvpp2_txq_pcpu __percpu *pcpu;
  825. u32 done_pkts_coal;
  826. /* Virtual address of thex Tx DMA descriptors array */
  827. struct mvpp2_tx_desc *descs;
  828. /* DMA address of the Tx DMA descriptors array */
  829. dma_addr_t descs_dma;
  830. /* Index of the last Tx DMA descriptor */
  831. int last_desc;
  832. /* Index of the next Tx DMA descriptor to process */
  833. int next_desc_to_proc;
  834. };
  835. struct mvpp2_rx_queue {
  836. /* RX queue number, in the range 0-31 for physical RXQs */
  837. u8 id;
  838. /* Num of rx descriptors in the rx descriptor ring */
  839. int size;
  840. u32 pkts_coal;
  841. u32 time_coal;
  842. /* Virtual address of the RX DMA descriptors array */
  843. struct mvpp2_rx_desc *descs;
  844. /* DMA address of the RX DMA descriptors array */
  845. dma_addr_t descs_dma;
  846. /* Index of the last RX DMA descriptor */
  847. int last_desc;
  848. /* Index of the next RX DMA descriptor to process */
  849. int next_desc_to_proc;
  850. /* ID of port to which physical RXQ is mapped */
  851. int port;
  852. /* Port's logic RXQ number to which physical RXQ is mapped */
  853. int logic_rxq;
  854. };
  855. struct mvpp2_bm_pool {
  856. /* Pool number in the range 0-7 */
  857. int id;
  858. /* Buffer Pointers Pool External (BPPE) size */
  859. int size;
  860. /* BPPE size in bytes */
  861. int size_bytes;
  862. /* Number of buffers for this pool */
  863. int buf_num;
  864. /* Pool buffer size */
  865. int buf_size;
  866. /* Packet size */
  867. int pkt_size;
  868. int frag_size;
  869. /* BPPE virtual base address */
  870. u32 *virt_addr;
  871. /* BPPE DMA base address */
  872. dma_addr_t dma_addr;
  873. /* Ports using BM pool */
  874. u32 port_map;
  875. };
  876. #define IS_TSO_HEADER(txq_pcpu, addr) \
  877. ((addr) >= (txq_pcpu)->tso_headers_dma && \
  878. (addr) < (txq_pcpu)->tso_headers_dma + \
  879. (txq_pcpu)->size * TSO_HEADER_SIZE)
  880. #define MVPP2_DRIVER_NAME "mvpp2"
  881. #define MVPP2_DRIVER_VERSION "1.0"
  882. void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data);
  883. u32 mvpp2_read(struct mvpp2 *priv, u32 offset);
  884. u32 mvpp2_read_relaxed(struct mvpp2 *priv, u32 offset);
  885. void mvpp2_percpu_write(struct mvpp2 *priv, int cpu, u32 offset, u32 data);
  886. u32 mvpp2_percpu_read(struct mvpp2 *priv, int cpu, u32 offset);
  887. void mvpp2_percpu_write_relaxed(struct mvpp2 *priv, int cpu, u32 offset,
  888. u32 data);
  889. #endif