ocelot.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
  2. /* Copyright (c) 2017 Microsemi Corporation
  3. */
  4. #ifndef _SOC_MSCC_OCELOT_H
  5. #define _SOC_MSCC_OCELOT_H
  6. #include <linux/ptp_clock_kernel.h>
  7. #include <linux/net_tstamp.h>
  8. #include <linux/if_vlan.h>
  9. #include <linux/regmap.h>
  10. #include <net/dsa.h>
  11. struct tc_mqprio_qopt_offload;
  12. /* Port Group IDs (PGID) are masks of destination ports.
  13. *
  14. * For L2 forwarding, the switch performs 3 lookups in the PGID table for each
  15. * frame, and forwards the frame to the ports that are present in the logical
  16. * AND of all 3 PGIDs.
  17. *
  18. * These PGID lookups are:
  19. * - In one of PGID[0-63]: for the destination masks. There are 2 paths by
  20. * which the switch selects a destination PGID:
  21. * - The {DMAC, VID} is present in the MAC table. In that case, the
  22. * destination PGID is given by the DEST_IDX field of the MAC table entry
  23. * that matched.
  24. * - The {DMAC, VID} is not present in the MAC table (it is unknown). The
  25. * frame is disseminated as being either unicast, multicast or broadcast,
  26. * and according to that, the destination PGID is chosen as being the
  27. * value contained by ANA_FLOODING_FLD_UNICAST,
  28. * ANA_FLOODING_FLD_MULTICAST or ANA_FLOODING_FLD_BROADCAST.
  29. * The destination PGID can be an unicast set: the first PGIDs, 0 to
  30. * ocelot->num_phys_ports - 1, or a multicast set: the PGIDs from
  31. * ocelot->num_phys_ports to 63. By convention, a unicast PGID corresponds to
  32. * a physical port and has a single bit set in the destination ports mask:
  33. * that corresponding to the port number itself. In contrast, a multicast
  34. * PGID will have potentially more than one single bit set in the destination
  35. * ports mask.
  36. * - In one of PGID[64-79]: for the aggregation mask. The switch classifier
  37. * dissects each frame and generates a 4-bit Link Aggregation Code which is
  38. * used for this second PGID table lookup. The goal of link aggregation is to
  39. * hash multiple flows within the same LAG on to different destination ports.
  40. * The first lookup will result in a PGID with all the LAG members present in
  41. * the destination ports mask, and the second lookup, by Link Aggregation
  42. * Code, will ensure that each flow gets forwarded only to a single port out
  43. * of that mask (there are no duplicates).
  44. * - In one of PGID[80-90]: for the source mask. The third time, the PGID table
  45. * is indexed with the ingress port (plus 80). These PGIDs answer the
  46. * question "is port i allowed to forward traffic to port j?" If yes, then
  47. * BIT(j) of PGID 80+i will be found set. The third PGID lookup can be used
  48. * to enforce the L2 forwarding matrix imposed by e.g. a Linux bridge.
  49. */
  50. /* Reserve some destination PGIDs at the end of the range:
  51. * PGID_BLACKHOLE: used for not forwarding the frames
  52. * PGID_CPU: used for whitelisting certain MAC addresses, such as the addresses
  53. * of the switch port net devices, towards the CPU port module.
  54. * PGID_UC: the flooding destinations for unknown unicast traffic.
  55. * PGID_MC: the flooding destinations for non-IP multicast traffic.
  56. * PGID_MCIPV4: the flooding destinations for IPv4 multicast traffic.
  57. * PGID_MCIPV6: the flooding destinations for IPv6 multicast traffic.
  58. * PGID_BC: the flooding destinations for broadcast traffic.
  59. */
  60. #define PGID_BLACKHOLE 57
  61. #define PGID_CPU 58
  62. #define PGID_UC 59
  63. #define PGID_MC 60
  64. #define PGID_MCIPV4 61
  65. #define PGID_MCIPV6 62
  66. #define PGID_BC 63
  67. #define for_each_unicast_dest_pgid(ocelot, pgid) \
  68. for ((pgid) = 0; \
  69. (pgid) < (ocelot)->num_phys_ports; \
  70. (pgid)++)
  71. #define for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) \
  72. for ((pgid) = (ocelot)->num_phys_ports + 1; \
  73. (pgid) < PGID_BLACKHOLE; \
  74. (pgid)++)
  75. #define for_each_aggr_pgid(ocelot, pgid) \
  76. for ((pgid) = PGID_AGGR; \
  77. (pgid) < PGID_SRC; \
  78. (pgid)++)
  79. /* Aggregation PGIDs, one per Link Aggregation Code */
  80. #define PGID_AGGR 64
  81. /* Source PGIDs, one per physical port */
  82. #define PGID_SRC 80
  83. #define OCELOT_NUM_TC 8
  84. #define OCELOT_SPEED_2500 0
  85. #define OCELOT_SPEED_1000 1
  86. #define OCELOT_SPEED_100 2
  87. #define OCELOT_SPEED_10 3
  88. #define OCELOT_PTP_PINS_NUM 4
  89. #define TARGET_OFFSET 24
  90. #define REG_MASK GENMASK(TARGET_OFFSET - 1, 0)
  91. #define REG(reg, offset) [reg & REG_MASK] = offset
  92. #define REG_RESERVED_ADDR 0xffffffff
  93. #define REG_RESERVED(reg) REG(reg, REG_RESERVED_ADDR)
  94. enum ocelot_target {
  95. ANA = 1,
  96. QS,
  97. QSYS,
  98. REW,
  99. SYS,
  100. S0,
  101. S1,
  102. S2,
  103. HSIO,
  104. PTP,
  105. FDMA,
  106. GCB,
  107. DEV_GMII,
  108. TARGET_MAX,
  109. };
  110. enum ocelot_reg {
  111. ANA_ADVLEARN = ANA << TARGET_OFFSET,
  112. ANA_VLANMASK,
  113. ANA_PORT_B_DOMAIN,
  114. ANA_ANAGEFIL,
  115. ANA_ANEVENTS,
  116. ANA_STORMLIMIT_BURST,
  117. ANA_STORMLIMIT_CFG,
  118. ANA_ISOLATED_PORTS,
  119. ANA_COMMUNITY_PORTS,
  120. ANA_AUTOAGE,
  121. ANA_MACTOPTIONS,
  122. ANA_LEARNDISC,
  123. ANA_AGENCTRL,
  124. ANA_MIRRORPORTS,
  125. ANA_EMIRRORPORTS,
  126. ANA_FLOODING,
  127. ANA_FLOODING_IPMC,
  128. ANA_SFLOW_CFG,
  129. ANA_PORT_MODE,
  130. ANA_CUT_THRU_CFG,
  131. ANA_PGID_PGID,
  132. ANA_TABLES_ANMOVED,
  133. ANA_TABLES_MACHDATA,
  134. ANA_TABLES_MACLDATA,
  135. ANA_TABLES_STREAMDATA,
  136. ANA_TABLES_MACACCESS,
  137. ANA_TABLES_MACTINDX,
  138. ANA_TABLES_VLANACCESS,
  139. ANA_TABLES_VLANTIDX,
  140. ANA_TABLES_ISDXACCESS,
  141. ANA_TABLES_ISDXTIDX,
  142. ANA_TABLES_ENTRYLIM,
  143. ANA_TABLES_PTP_ID_HIGH,
  144. ANA_TABLES_PTP_ID_LOW,
  145. ANA_TABLES_STREAMACCESS,
  146. ANA_TABLES_STREAMTIDX,
  147. ANA_TABLES_SEQ_HISTORY,
  148. ANA_TABLES_SEQ_MASK,
  149. ANA_TABLES_SFID_MASK,
  150. ANA_TABLES_SFIDACCESS,
  151. ANA_TABLES_SFIDTIDX,
  152. ANA_MSTI_STATE,
  153. ANA_OAM_UPM_LM_CNT,
  154. ANA_SG_ACCESS_CTRL,
  155. ANA_SG_CONFIG_REG_1,
  156. ANA_SG_CONFIG_REG_2,
  157. ANA_SG_CONFIG_REG_3,
  158. ANA_SG_CONFIG_REG_4,
  159. ANA_SG_CONFIG_REG_5,
  160. ANA_SG_GCL_GS_CONFIG,
  161. ANA_SG_GCL_TI_CONFIG,
  162. ANA_SG_STATUS_REG_1,
  163. ANA_SG_STATUS_REG_2,
  164. ANA_SG_STATUS_REG_3,
  165. ANA_PORT_VLAN_CFG,
  166. ANA_PORT_DROP_CFG,
  167. ANA_PORT_QOS_CFG,
  168. ANA_PORT_VCAP_CFG,
  169. ANA_PORT_VCAP_S1_KEY_CFG,
  170. ANA_PORT_VCAP_S2_CFG,
  171. ANA_PORT_PCP_DEI_MAP,
  172. ANA_PORT_CPU_FWD_CFG,
  173. ANA_PORT_CPU_FWD_BPDU_CFG,
  174. ANA_PORT_CPU_FWD_GARP_CFG,
  175. ANA_PORT_CPU_FWD_CCM_CFG,
  176. ANA_PORT_PORT_CFG,
  177. ANA_PORT_POL_CFG,
  178. ANA_PORT_PTP_CFG,
  179. ANA_PORT_PTP_DLY1_CFG,
  180. ANA_PORT_PTP_DLY2_CFG,
  181. ANA_PORT_SFID_CFG,
  182. ANA_PFC_PFC_CFG,
  183. ANA_PFC_PFC_TIMER,
  184. ANA_IPT_OAM_MEP_CFG,
  185. ANA_IPT_IPT,
  186. ANA_PPT_PPT,
  187. ANA_FID_MAP_FID_MAP,
  188. ANA_AGGR_CFG,
  189. ANA_CPUQ_CFG,
  190. ANA_CPUQ_CFG2,
  191. ANA_CPUQ_8021_CFG,
  192. ANA_DSCP_CFG,
  193. ANA_DSCP_REWR_CFG,
  194. ANA_VCAP_RNG_TYPE_CFG,
  195. ANA_VCAP_RNG_VAL_CFG,
  196. ANA_VRAP_CFG,
  197. ANA_VRAP_HDR_DATA,
  198. ANA_VRAP_HDR_MASK,
  199. ANA_DISCARD_CFG,
  200. ANA_FID_CFG,
  201. ANA_POL_PIR_CFG,
  202. ANA_POL_CIR_CFG,
  203. ANA_POL_MODE_CFG,
  204. ANA_POL_PIR_STATE,
  205. ANA_POL_CIR_STATE,
  206. ANA_POL_STATE,
  207. ANA_POL_FLOWC,
  208. ANA_POL_HYST,
  209. ANA_POL_MISC_CFG,
  210. QS_XTR_GRP_CFG = QS << TARGET_OFFSET,
  211. QS_XTR_RD,
  212. QS_XTR_FRM_PRUNING,
  213. QS_XTR_FLUSH,
  214. QS_XTR_DATA_PRESENT,
  215. QS_XTR_CFG,
  216. QS_INJ_GRP_CFG,
  217. QS_INJ_WR,
  218. QS_INJ_CTRL,
  219. QS_INJ_STATUS,
  220. QS_INJ_ERR,
  221. QS_INH_DBG,
  222. QSYS_PORT_MODE = QSYS << TARGET_OFFSET,
  223. QSYS_SWITCH_PORT_MODE,
  224. QSYS_STAT_CNT_CFG,
  225. QSYS_EEE_CFG,
  226. QSYS_EEE_THRES,
  227. QSYS_IGR_NO_SHARING,
  228. QSYS_EGR_NO_SHARING,
  229. QSYS_SW_STATUS,
  230. QSYS_EXT_CPU_CFG,
  231. QSYS_PAD_CFG,
  232. QSYS_CPU_GROUP_MAP,
  233. QSYS_QMAP,
  234. QSYS_ISDX_SGRP,
  235. QSYS_TIMED_FRAME_ENTRY,
  236. QSYS_TFRM_MISC,
  237. QSYS_TFRM_PORT_DLY,
  238. QSYS_TFRM_TIMER_CFG_1,
  239. QSYS_TFRM_TIMER_CFG_2,
  240. QSYS_TFRM_TIMER_CFG_3,
  241. QSYS_TFRM_TIMER_CFG_4,
  242. QSYS_TFRM_TIMER_CFG_5,
  243. QSYS_TFRM_TIMER_CFG_6,
  244. QSYS_TFRM_TIMER_CFG_7,
  245. QSYS_TFRM_TIMER_CFG_8,
  246. QSYS_RED_PROFILE,
  247. QSYS_RES_QOS_MODE,
  248. QSYS_RES_CFG,
  249. QSYS_RES_STAT,
  250. QSYS_EGR_DROP_MODE,
  251. QSYS_EQ_CTRL,
  252. QSYS_EVENTS_CORE,
  253. QSYS_QMAXSDU_CFG_0,
  254. QSYS_QMAXSDU_CFG_1,
  255. QSYS_QMAXSDU_CFG_2,
  256. QSYS_QMAXSDU_CFG_3,
  257. QSYS_QMAXSDU_CFG_4,
  258. QSYS_QMAXSDU_CFG_5,
  259. QSYS_QMAXSDU_CFG_6,
  260. QSYS_QMAXSDU_CFG_7,
  261. QSYS_PREEMPTION_CFG,
  262. QSYS_CIR_CFG,
  263. QSYS_EIR_CFG,
  264. QSYS_SE_CFG,
  265. QSYS_SE_DWRR_CFG,
  266. QSYS_SE_CONNECT,
  267. QSYS_SE_DLB_SENSE,
  268. QSYS_CIR_STATE,
  269. QSYS_EIR_STATE,
  270. QSYS_SE_STATE,
  271. QSYS_HSCH_MISC_CFG,
  272. QSYS_TAG_CONFIG,
  273. QSYS_TAS_PARAM_CFG_CTRL,
  274. QSYS_PORT_MAX_SDU,
  275. QSYS_PARAM_CFG_REG_1,
  276. QSYS_PARAM_CFG_REG_2,
  277. QSYS_PARAM_CFG_REG_3,
  278. QSYS_PARAM_CFG_REG_4,
  279. QSYS_PARAM_CFG_REG_5,
  280. QSYS_GCL_CFG_REG_1,
  281. QSYS_GCL_CFG_REG_2,
  282. QSYS_PARAM_STATUS_REG_1,
  283. QSYS_PARAM_STATUS_REG_2,
  284. QSYS_PARAM_STATUS_REG_3,
  285. QSYS_PARAM_STATUS_REG_4,
  286. QSYS_PARAM_STATUS_REG_5,
  287. QSYS_PARAM_STATUS_REG_6,
  288. QSYS_PARAM_STATUS_REG_7,
  289. QSYS_PARAM_STATUS_REG_8,
  290. QSYS_PARAM_STATUS_REG_9,
  291. QSYS_GCL_STATUS_REG_1,
  292. QSYS_GCL_STATUS_REG_2,
  293. REW_PORT_VLAN_CFG = REW << TARGET_OFFSET,
  294. REW_TAG_CFG,
  295. REW_PORT_CFG,
  296. REW_DSCP_CFG,
  297. REW_PCP_DEI_QOS_MAP_CFG,
  298. REW_PTP_CFG,
  299. REW_PTP_DLY1_CFG,
  300. REW_RED_TAG_CFG,
  301. REW_DSCP_REMAP_DP1_CFG,
  302. REW_DSCP_REMAP_CFG,
  303. REW_STAT_CFG,
  304. REW_REW_STICKY,
  305. REW_PPT,
  306. SYS_COUNT_RX_OCTETS = SYS << TARGET_OFFSET,
  307. SYS_COUNT_RX_UNICAST,
  308. SYS_COUNT_RX_MULTICAST,
  309. SYS_COUNT_RX_BROADCAST,
  310. SYS_COUNT_RX_SHORTS,
  311. SYS_COUNT_RX_FRAGMENTS,
  312. SYS_COUNT_RX_JABBERS,
  313. SYS_COUNT_RX_CRC_ALIGN_ERRS,
  314. SYS_COUNT_RX_SYM_ERRS,
  315. SYS_COUNT_RX_64,
  316. SYS_COUNT_RX_65_127,
  317. SYS_COUNT_RX_128_255,
  318. SYS_COUNT_RX_256_511,
  319. SYS_COUNT_RX_512_1023,
  320. SYS_COUNT_RX_1024_1526,
  321. SYS_COUNT_RX_1527_MAX,
  322. SYS_COUNT_RX_PAUSE,
  323. SYS_COUNT_RX_CONTROL,
  324. SYS_COUNT_RX_LONGS,
  325. SYS_COUNT_RX_CLASSIFIED_DROPS,
  326. SYS_COUNT_RX_RED_PRIO_0,
  327. SYS_COUNT_RX_RED_PRIO_1,
  328. SYS_COUNT_RX_RED_PRIO_2,
  329. SYS_COUNT_RX_RED_PRIO_3,
  330. SYS_COUNT_RX_RED_PRIO_4,
  331. SYS_COUNT_RX_RED_PRIO_5,
  332. SYS_COUNT_RX_RED_PRIO_6,
  333. SYS_COUNT_RX_RED_PRIO_7,
  334. SYS_COUNT_RX_YELLOW_PRIO_0,
  335. SYS_COUNT_RX_YELLOW_PRIO_1,
  336. SYS_COUNT_RX_YELLOW_PRIO_2,
  337. SYS_COUNT_RX_YELLOW_PRIO_3,
  338. SYS_COUNT_RX_YELLOW_PRIO_4,
  339. SYS_COUNT_RX_YELLOW_PRIO_5,
  340. SYS_COUNT_RX_YELLOW_PRIO_6,
  341. SYS_COUNT_RX_YELLOW_PRIO_7,
  342. SYS_COUNT_RX_GREEN_PRIO_0,
  343. SYS_COUNT_RX_GREEN_PRIO_1,
  344. SYS_COUNT_RX_GREEN_PRIO_2,
  345. SYS_COUNT_RX_GREEN_PRIO_3,
  346. SYS_COUNT_RX_GREEN_PRIO_4,
  347. SYS_COUNT_RX_GREEN_PRIO_5,
  348. SYS_COUNT_RX_GREEN_PRIO_6,
  349. SYS_COUNT_RX_GREEN_PRIO_7,
  350. SYS_COUNT_RX_ASSEMBLY_ERRS,
  351. SYS_COUNT_RX_SMD_ERRS,
  352. SYS_COUNT_RX_ASSEMBLY_OK,
  353. SYS_COUNT_RX_MERGE_FRAGMENTS,
  354. SYS_COUNT_RX_PMAC_OCTETS,
  355. SYS_COUNT_RX_PMAC_UNICAST,
  356. SYS_COUNT_RX_PMAC_MULTICAST,
  357. SYS_COUNT_RX_PMAC_BROADCAST,
  358. SYS_COUNT_RX_PMAC_SHORTS,
  359. SYS_COUNT_RX_PMAC_FRAGMENTS,
  360. SYS_COUNT_RX_PMAC_JABBERS,
  361. SYS_COUNT_RX_PMAC_CRC_ALIGN_ERRS,
  362. SYS_COUNT_RX_PMAC_SYM_ERRS,
  363. SYS_COUNT_RX_PMAC_64,
  364. SYS_COUNT_RX_PMAC_65_127,
  365. SYS_COUNT_RX_PMAC_128_255,
  366. SYS_COUNT_RX_PMAC_256_511,
  367. SYS_COUNT_RX_PMAC_512_1023,
  368. SYS_COUNT_RX_PMAC_1024_1526,
  369. SYS_COUNT_RX_PMAC_1527_MAX,
  370. SYS_COUNT_RX_PMAC_PAUSE,
  371. SYS_COUNT_RX_PMAC_CONTROL,
  372. SYS_COUNT_RX_PMAC_LONGS,
  373. SYS_COUNT_TX_OCTETS,
  374. SYS_COUNT_TX_UNICAST,
  375. SYS_COUNT_TX_MULTICAST,
  376. SYS_COUNT_TX_BROADCAST,
  377. SYS_COUNT_TX_COLLISION,
  378. SYS_COUNT_TX_DROPS,
  379. SYS_COUNT_TX_PAUSE,
  380. SYS_COUNT_TX_64,
  381. SYS_COUNT_TX_65_127,
  382. SYS_COUNT_TX_128_255,
  383. SYS_COUNT_TX_256_511,
  384. SYS_COUNT_TX_512_1023,
  385. SYS_COUNT_TX_1024_1526,
  386. SYS_COUNT_TX_1527_MAX,
  387. SYS_COUNT_TX_YELLOW_PRIO_0,
  388. SYS_COUNT_TX_YELLOW_PRIO_1,
  389. SYS_COUNT_TX_YELLOW_PRIO_2,
  390. SYS_COUNT_TX_YELLOW_PRIO_3,
  391. SYS_COUNT_TX_YELLOW_PRIO_4,
  392. SYS_COUNT_TX_YELLOW_PRIO_5,
  393. SYS_COUNT_TX_YELLOW_PRIO_6,
  394. SYS_COUNT_TX_YELLOW_PRIO_7,
  395. SYS_COUNT_TX_GREEN_PRIO_0,
  396. SYS_COUNT_TX_GREEN_PRIO_1,
  397. SYS_COUNT_TX_GREEN_PRIO_2,
  398. SYS_COUNT_TX_GREEN_PRIO_3,
  399. SYS_COUNT_TX_GREEN_PRIO_4,
  400. SYS_COUNT_TX_GREEN_PRIO_5,
  401. SYS_COUNT_TX_GREEN_PRIO_6,
  402. SYS_COUNT_TX_GREEN_PRIO_7,
  403. SYS_COUNT_TX_AGED,
  404. SYS_COUNT_TX_MM_HOLD,
  405. SYS_COUNT_TX_MERGE_FRAGMENTS,
  406. SYS_COUNT_TX_PMAC_OCTETS,
  407. SYS_COUNT_TX_PMAC_UNICAST,
  408. SYS_COUNT_TX_PMAC_MULTICAST,
  409. SYS_COUNT_TX_PMAC_BROADCAST,
  410. SYS_COUNT_TX_PMAC_PAUSE,
  411. SYS_COUNT_TX_PMAC_64,
  412. SYS_COUNT_TX_PMAC_65_127,
  413. SYS_COUNT_TX_PMAC_128_255,
  414. SYS_COUNT_TX_PMAC_256_511,
  415. SYS_COUNT_TX_PMAC_512_1023,
  416. SYS_COUNT_TX_PMAC_1024_1526,
  417. SYS_COUNT_TX_PMAC_1527_MAX,
  418. SYS_COUNT_DROP_LOCAL,
  419. SYS_COUNT_DROP_TAIL,
  420. SYS_COUNT_DROP_YELLOW_PRIO_0,
  421. SYS_COUNT_DROP_YELLOW_PRIO_1,
  422. SYS_COUNT_DROP_YELLOW_PRIO_2,
  423. SYS_COUNT_DROP_YELLOW_PRIO_3,
  424. SYS_COUNT_DROP_YELLOW_PRIO_4,
  425. SYS_COUNT_DROP_YELLOW_PRIO_5,
  426. SYS_COUNT_DROP_YELLOW_PRIO_6,
  427. SYS_COUNT_DROP_YELLOW_PRIO_7,
  428. SYS_COUNT_DROP_GREEN_PRIO_0,
  429. SYS_COUNT_DROP_GREEN_PRIO_1,
  430. SYS_COUNT_DROP_GREEN_PRIO_2,
  431. SYS_COUNT_DROP_GREEN_PRIO_3,
  432. SYS_COUNT_DROP_GREEN_PRIO_4,
  433. SYS_COUNT_DROP_GREEN_PRIO_5,
  434. SYS_COUNT_DROP_GREEN_PRIO_6,
  435. SYS_COUNT_DROP_GREEN_PRIO_7,
  436. SYS_COUNT_SF_MATCHING_FRAMES,
  437. SYS_COUNT_SF_NOT_PASSING_FRAMES,
  438. SYS_COUNT_SF_NOT_PASSING_SDU,
  439. SYS_COUNT_SF_RED_FRAMES,
  440. SYS_RESET_CFG,
  441. SYS_SR_ETYPE_CFG,
  442. SYS_VLAN_ETYPE_CFG,
  443. SYS_PORT_MODE,
  444. SYS_FRONT_PORT_MODE,
  445. SYS_FRM_AGING,
  446. SYS_STAT_CFG,
  447. SYS_SW_STATUS,
  448. SYS_MISC_CFG,
  449. SYS_REW_MAC_HIGH_CFG,
  450. SYS_REW_MAC_LOW_CFG,
  451. SYS_TIMESTAMP_OFFSET,
  452. SYS_CMID,
  453. SYS_PAUSE_CFG,
  454. SYS_PAUSE_TOT_CFG,
  455. SYS_ATOP,
  456. SYS_ATOP_TOT_CFG,
  457. SYS_MAC_FC_CFG,
  458. SYS_MMGT,
  459. SYS_MMGT_FAST,
  460. SYS_EVENTS_DIF,
  461. SYS_EVENTS_CORE,
  462. SYS_PTP_STATUS,
  463. SYS_PTP_TXSTAMP,
  464. SYS_PTP_NXT,
  465. SYS_PTP_CFG,
  466. SYS_RAM_INIT,
  467. SYS_CM_ADDR,
  468. SYS_CM_DATA_WR,
  469. SYS_CM_DATA_RD,
  470. SYS_CM_OP,
  471. SYS_CM_DATA,
  472. PTP_PIN_CFG = PTP << TARGET_OFFSET,
  473. PTP_PIN_TOD_SEC_MSB,
  474. PTP_PIN_TOD_SEC_LSB,
  475. PTP_PIN_TOD_NSEC,
  476. PTP_PIN_WF_HIGH_PERIOD,
  477. PTP_PIN_WF_LOW_PERIOD,
  478. PTP_CFG_MISC,
  479. PTP_CLK_CFG_ADJ_CFG,
  480. PTP_CLK_CFG_ADJ_FREQ,
  481. GCB_SOFT_RST = GCB << TARGET_OFFSET,
  482. GCB_MIIM_MII_STATUS,
  483. GCB_MIIM_MII_CMD,
  484. GCB_MIIM_MII_DATA,
  485. DEV_CLOCK_CFG = DEV_GMII << TARGET_OFFSET,
  486. DEV_PORT_MISC,
  487. DEV_EVENTS,
  488. DEV_EEE_CFG,
  489. DEV_RX_PATH_DELAY,
  490. DEV_TX_PATH_DELAY,
  491. DEV_PTP_PREDICT_CFG,
  492. DEV_MAC_ENA_CFG,
  493. DEV_MAC_MODE_CFG,
  494. DEV_MAC_MAXLEN_CFG,
  495. DEV_MAC_TAGS_CFG,
  496. DEV_MAC_ADV_CHK_CFG,
  497. DEV_MAC_IFG_CFG,
  498. DEV_MAC_HDX_CFG,
  499. DEV_MAC_DBG_CFG,
  500. DEV_MAC_FC_MAC_LOW_CFG,
  501. DEV_MAC_FC_MAC_HIGH_CFG,
  502. DEV_MAC_STICKY,
  503. DEV_MM_ENABLE_CONFIG,
  504. DEV_MM_VERIF_CONFIG,
  505. DEV_MM_STATUS,
  506. PCS1G_CFG,
  507. PCS1G_MODE_CFG,
  508. PCS1G_SD_CFG,
  509. PCS1G_ANEG_CFG,
  510. PCS1G_ANEG_NP_CFG,
  511. PCS1G_LB_CFG,
  512. PCS1G_DBG_CFG,
  513. PCS1G_CDET_CFG,
  514. PCS1G_ANEG_STATUS,
  515. PCS1G_ANEG_NP_STATUS,
  516. PCS1G_LINK_STATUS,
  517. PCS1G_LINK_DOWN_CNT,
  518. PCS1G_STICKY,
  519. PCS1G_DEBUG_STATUS,
  520. PCS1G_LPI_CFG,
  521. PCS1G_LPI_WAKE_ERROR_CNT,
  522. PCS1G_LPI_STATUS,
  523. PCS1G_TSTPAT_MODE_CFG,
  524. PCS1G_TSTPAT_STATUS,
  525. DEV_PCS_FX100_CFG,
  526. DEV_PCS_FX100_STATUS,
  527. };
  528. enum ocelot_regfield {
  529. ANA_ADVLEARN_VLAN_CHK,
  530. ANA_ADVLEARN_LEARN_MIRROR,
  531. ANA_ANEVENTS_FLOOD_DISCARD,
  532. ANA_ANEVENTS_MSTI_DROP,
  533. ANA_ANEVENTS_ACLKILL,
  534. ANA_ANEVENTS_ACLUSED,
  535. ANA_ANEVENTS_AUTOAGE,
  536. ANA_ANEVENTS_VS2TTL1,
  537. ANA_ANEVENTS_STORM_DROP,
  538. ANA_ANEVENTS_LEARN_DROP,
  539. ANA_ANEVENTS_AGED_ENTRY,
  540. ANA_ANEVENTS_CPU_LEARN_FAILED,
  541. ANA_ANEVENTS_AUTO_LEARN_FAILED,
  542. ANA_ANEVENTS_LEARN_REMOVE,
  543. ANA_ANEVENTS_AUTO_LEARNED,
  544. ANA_ANEVENTS_AUTO_MOVED,
  545. ANA_ANEVENTS_DROPPED,
  546. ANA_ANEVENTS_CLASSIFIED_DROP,
  547. ANA_ANEVENTS_CLASSIFIED_COPY,
  548. ANA_ANEVENTS_VLAN_DISCARD,
  549. ANA_ANEVENTS_FWD_DISCARD,
  550. ANA_ANEVENTS_MULTICAST_FLOOD,
  551. ANA_ANEVENTS_UNICAST_FLOOD,
  552. ANA_ANEVENTS_DEST_KNOWN,
  553. ANA_ANEVENTS_BUCKET3_MATCH,
  554. ANA_ANEVENTS_BUCKET2_MATCH,
  555. ANA_ANEVENTS_BUCKET1_MATCH,
  556. ANA_ANEVENTS_BUCKET0_MATCH,
  557. ANA_ANEVENTS_CPU_OPERATION,
  558. ANA_ANEVENTS_DMAC_LOOKUP,
  559. ANA_ANEVENTS_SMAC_LOOKUP,
  560. ANA_ANEVENTS_SEQ_GEN_ERR_0,
  561. ANA_ANEVENTS_SEQ_GEN_ERR_1,
  562. ANA_TABLES_MACACCESS_B_DOM,
  563. ANA_TABLES_MACTINDX_BUCKET,
  564. ANA_TABLES_MACTINDX_M_INDEX,
  565. QSYS_SWITCH_PORT_MODE_PORT_ENA,
  566. QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG,
  567. QSYS_SWITCH_PORT_MODE_YEL_RSRVD,
  568. QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE,
  569. QSYS_SWITCH_PORT_MODE_TX_PFC_ENA,
  570. QSYS_SWITCH_PORT_MODE_TX_PFC_MODE,
  571. QSYS_TIMED_FRAME_ENTRY_TFRM_VLD,
  572. QSYS_TIMED_FRAME_ENTRY_TFRM_FP,
  573. QSYS_TIMED_FRAME_ENTRY_TFRM_PORTNO,
  574. QSYS_TIMED_FRAME_ENTRY_TFRM_TM_SEL,
  575. QSYS_TIMED_FRAME_ENTRY_TFRM_TM_T,
  576. SYS_PORT_MODE_DATA_WO_TS,
  577. SYS_PORT_MODE_INCL_INJ_HDR,
  578. SYS_PORT_MODE_INCL_XTR_HDR,
  579. SYS_PORT_MODE_INCL_HDR_ERR,
  580. SYS_RESET_CFG_CORE_ENA,
  581. SYS_RESET_CFG_MEM_ENA,
  582. SYS_RESET_CFG_MEM_INIT,
  583. GCB_SOFT_RST_SWC_RST,
  584. GCB_MIIM_MII_STATUS_PENDING,
  585. GCB_MIIM_MII_STATUS_BUSY,
  586. SYS_PAUSE_CFG_PAUSE_START,
  587. SYS_PAUSE_CFG_PAUSE_STOP,
  588. SYS_PAUSE_CFG_PAUSE_ENA,
  589. REGFIELD_MAX
  590. };
  591. enum {
  592. /* VCAP_CORE_CFG */
  593. VCAP_CORE_UPDATE_CTRL,
  594. VCAP_CORE_MV_CFG,
  595. /* VCAP_CORE_CACHE */
  596. VCAP_CACHE_ENTRY_DAT,
  597. VCAP_CACHE_MASK_DAT,
  598. VCAP_CACHE_ACTION_DAT,
  599. VCAP_CACHE_CNT_DAT,
  600. VCAP_CACHE_TG_DAT,
  601. /* VCAP_CONST */
  602. VCAP_CONST_VCAP_VER,
  603. VCAP_CONST_ENTRY_WIDTH,
  604. VCAP_CONST_ENTRY_CNT,
  605. VCAP_CONST_ENTRY_SWCNT,
  606. VCAP_CONST_ENTRY_TG_WIDTH,
  607. VCAP_CONST_ACTION_DEF_CNT,
  608. VCAP_CONST_ACTION_WIDTH,
  609. VCAP_CONST_CNT_WIDTH,
  610. VCAP_CONST_CORE_CNT,
  611. VCAP_CONST_IF_CNT,
  612. };
  613. enum ocelot_ptp_pins {
  614. PTP_PIN_0,
  615. PTP_PIN_1,
  616. PTP_PIN_2,
  617. PTP_PIN_3,
  618. TOD_ACC_PIN
  619. };
  620. enum ocelot_tag_prefix {
  621. OCELOT_TAG_PREFIX_DISABLED = 0,
  622. OCELOT_TAG_PREFIX_NONE,
  623. OCELOT_TAG_PREFIX_SHORT,
  624. OCELOT_TAG_PREFIX_LONG,
  625. };
  626. struct ocelot;
  627. struct device_node;
  628. struct ocelot_ops {
  629. struct net_device *(*port_to_netdev)(struct ocelot *ocelot, int port);
  630. int (*netdev_to_port)(struct net_device *dev);
  631. int (*reset)(struct ocelot *ocelot);
  632. u16 (*wm_enc)(u16 value);
  633. u16 (*wm_dec)(u16 value);
  634. void (*wm_stat)(u32 val, u32 *inuse, u32 *maxuse);
  635. void (*psfp_init)(struct ocelot *ocelot);
  636. int (*psfp_filter_add)(struct ocelot *ocelot, int port,
  637. struct flow_cls_offload *f);
  638. int (*psfp_filter_del)(struct ocelot *ocelot, struct flow_cls_offload *f);
  639. int (*psfp_stats_get)(struct ocelot *ocelot, struct flow_cls_offload *f,
  640. struct flow_stats *stats);
  641. void (*cut_through_fwd)(struct ocelot *ocelot);
  642. void (*tas_clock_adjust)(struct ocelot *ocelot);
  643. void (*tas_guard_bands_update)(struct ocelot *ocelot, int port);
  644. void (*update_stats)(struct ocelot *ocelot);
  645. };
  646. struct ocelot_vcap_policer {
  647. struct list_head pol_list;
  648. u16 base;
  649. u16 max;
  650. u16 base2;
  651. u16 max2;
  652. };
  653. struct ocelot_vcap_block {
  654. struct list_head rules;
  655. int count;
  656. };
  657. struct ocelot_bridge_vlan {
  658. u16 vid;
  659. unsigned long portmask;
  660. unsigned long untagged;
  661. struct list_head list;
  662. };
  663. enum ocelot_port_tag_config {
  664. /* all VLANs are egress-untagged */
  665. OCELOT_PORT_TAG_DISABLED = 0,
  666. /* all VLANs except the native VLAN and VID 0 are egress-tagged */
  667. OCELOT_PORT_TAG_NATIVE = 1,
  668. /* all VLANs except VID 0 are egress-tagged */
  669. OCELOT_PORT_TAG_TRUNK_NO_VID0 = 2,
  670. /* all VLANs are egress-tagged */
  671. OCELOT_PORT_TAG_TRUNK = 3,
  672. };
  673. struct ocelot_psfp_list {
  674. struct list_head stream_list;
  675. struct list_head sfi_list;
  676. struct list_head sgi_list;
  677. /* Serialize access to the lists */
  678. struct mutex lock;
  679. };
  680. enum ocelot_sb {
  681. OCELOT_SB_BUF,
  682. OCELOT_SB_REF,
  683. OCELOT_SB_NUM,
  684. };
  685. enum ocelot_sb_pool {
  686. OCELOT_SB_POOL_ING,
  687. OCELOT_SB_POOL_EGR,
  688. OCELOT_SB_POOL_NUM,
  689. };
  690. /* MAC table entry types.
  691. * ENTRYTYPE_NORMAL is subject to aging.
  692. * ENTRYTYPE_LOCKED is not subject to aging.
  693. * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast.
  694. * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast.
  695. */
  696. enum macaccess_entry_type {
  697. ENTRYTYPE_NORMAL = 0,
  698. ENTRYTYPE_LOCKED,
  699. ENTRYTYPE_MACv4,
  700. ENTRYTYPE_MACv6,
  701. };
  702. enum ocelot_proto {
  703. OCELOT_PROTO_PTP_L2 = BIT(0),
  704. OCELOT_PROTO_PTP_L4 = BIT(1),
  705. };
  706. #define OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION BIT(0)
  707. #define OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP BIT(1)
  708. struct ocelot_lag_fdb {
  709. unsigned char addr[ETH_ALEN];
  710. u16 vid;
  711. struct net_device *bond;
  712. struct list_head list;
  713. };
  714. struct ocelot_mirror {
  715. refcount_t refcount;
  716. int to;
  717. };
  718. struct ocelot_mm_state {
  719. enum ethtool_mm_verify_status verify_status;
  720. bool tx_enabled;
  721. bool tx_active;
  722. u8 preemptible_tcs;
  723. u8 active_preemptible_tcs;
  724. };
  725. struct ocelot_port;
  726. struct ocelot_port {
  727. struct ocelot *ocelot;
  728. struct regmap *target;
  729. struct net_device *bond;
  730. struct net_device *bridge;
  731. struct ocelot_port *dsa_8021q_cpu;
  732. /* VLAN that untagged frames are classified to, on ingress */
  733. const struct ocelot_bridge_vlan *pvid_vlan;
  734. struct tc_taprio_qopt_offload *taprio;
  735. phy_interface_t phy_mode;
  736. struct sk_buff_head tx_skbs;
  737. unsigned int trap_proto;
  738. u16 mrp_ring_id;
  739. u8 ptp_cmd;
  740. u8 index;
  741. u8 stp_state;
  742. bool vlan_aware;
  743. bool is_dsa_8021q_cpu;
  744. bool learn_ena;
  745. bool lag_tx_active;
  746. int bridge_num;
  747. int speed;
  748. };
  749. struct ocelot {
  750. struct device *dev;
  751. struct devlink *devlink;
  752. struct devlink_port *devlink_ports;
  753. const struct ocelot_ops *ops;
  754. struct regmap *targets[TARGET_MAX];
  755. struct regmap_field *regfields[REGFIELD_MAX];
  756. const u32 *const *map;
  757. struct list_head stats_regions;
  758. spinlock_t inj_lock;
  759. spinlock_t xtr_lock;
  760. u32 pool_size[OCELOT_SB_NUM][OCELOT_SB_POOL_NUM];
  761. int packet_buffer_size;
  762. int num_frame_refs;
  763. int num_mact_rows;
  764. struct ocelot_port **ports;
  765. u8 base_mac[ETH_ALEN];
  766. struct list_head vlans;
  767. struct list_head traps;
  768. struct list_head lag_fdbs;
  769. /* Switches like VSC9959 have flooding per traffic class */
  770. int num_flooding_pgids;
  771. /* In tables like ANA:PORT and the ANA:PGID:PGID mask,
  772. * the CPU is located after the physical ports (at the
  773. * num_phys_ports index).
  774. */
  775. u8 num_phys_ports;
  776. int npi;
  777. enum ocelot_tag_prefix npi_inj_prefix;
  778. enum ocelot_tag_prefix npi_xtr_prefix;
  779. unsigned long bridges;
  780. struct list_head multicast;
  781. struct list_head pgids;
  782. struct list_head dummy_rules;
  783. struct ocelot_vcap_block block[3];
  784. struct ocelot_vcap_policer vcap_pol;
  785. struct vcap_props *vcap;
  786. struct ocelot_mirror *mirror;
  787. struct ocelot_psfp_list psfp;
  788. /* Workqueue to check statistics for overflow */
  789. struct delayed_work stats_work;
  790. struct workqueue_struct *stats_queue;
  791. /* Lock for serializing access to the statistics array */
  792. spinlock_t stats_lock;
  793. u64 *stats;
  794. /* Lock for serializing indirect access to STAT_VIEW registers */
  795. struct mutex stat_view_lock;
  796. /* Lock for serializing access to the MAC table */
  797. struct mutex mact_lock;
  798. /* Lock for serializing forwarding domain changes, including the
  799. * configuration of the Time-Aware Shaper, MAC Merge layer and
  800. * cut-through forwarding, on which it depends
  801. */
  802. struct mutex fwd_domain_lock;
  803. struct workqueue_struct *owq;
  804. u8 ptp:1;
  805. u8 mm_supported:1;
  806. struct ptp_clock *ptp_clock;
  807. struct ptp_clock_info ptp_info;
  808. unsigned int ptp_skbs_in_flight;
  809. /* Protects the 2-step TX timestamp ID logic */
  810. spinlock_t ts_id_lock;
  811. /* Protects the PTP clock */
  812. spinlock_t ptp_clock_lock;
  813. struct ptp_pin_desc ptp_pins[OCELOT_PTP_PINS_NUM];
  814. struct ocelot_mm_state *mm;
  815. struct ocelot_fdma *fdma;
  816. };
  817. struct ocelot_policer {
  818. u32 rate; /* kilobit per second */
  819. u32 burst; /* bytes */
  820. };
  821. #define ocelot_bulk_read(ocelot, reg, buf, count) \
  822. __ocelot_bulk_read_ix(ocelot, reg, 0, buf, count)
  823. #define ocelot_read_ix(ocelot, reg, gi, ri) \
  824. __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  825. #define ocelot_read_gix(ocelot, reg, gi) \
  826. __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
  827. #define ocelot_read_rix(ocelot, reg, ri) \
  828. __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
  829. #define ocelot_read(ocelot, reg) \
  830. __ocelot_read_ix(ocelot, reg, 0)
  831. #define ocelot_write_ix(ocelot, val, reg, gi, ri) \
  832. __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  833. #define ocelot_write_gix(ocelot, val, reg, gi) \
  834. __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi))
  835. #define ocelot_write_rix(ocelot, val, reg, ri) \
  836. __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
  837. #define ocelot_write(ocelot, val, reg) __ocelot_write_ix(ocelot, val, reg, 0)
  838. #define ocelot_rmw_ix(ocelot, val, m, reg, gi, ri) \
  839. __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  840. #define ocelot_rmw_gix(ocelot, val, m, reg, gi) \
  841. __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi))
  842. #define ocelot_rmw_rix(ocelot, val, m, reg, ri) \
  843. __ocelot_rmw_ix(ocelot, val, m, reg, reg##_RSZ * (ri))
  844. #define ocelot_rmw(ocelot, val, m, reg) __ocelot_rmw_ix(ocelot, val, m, reg, 0)
  845. #define ocelot_field_write(ocelot, reg, val) \
  846. regmap_field_write((ocelot)->regfields[(reg)], (val))
  847. #define ocelot_field_read(ocelot, reg, val) \
  848. regmap_field_read((ocelot)->regfields[(reg)], (val))
  849. #define ocelot_fields_write(ocelot, id, reg, val) \
  850. regmap_fields_write((ocelot)->regfields[(reg)], (id), (val))
  851. #define ocelot_fields_read(ocelot, id, reg, val) \
  852. regmap_fields_read((ocelot)->regfields[(reg)], (id), (val))
  853. #define ocelot_target_read_ix(ocelot, target, reg, gi, ri) \
  854. __ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  855. #define ocelot_target_read_gix(ocelot, target, reg, gi) \
  856. __ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi))
  857. #define ocelot_target_read_rix(ocelot, target, reg, ri) \
  858. __ocelot_target_read_ix(ocelot, target, reg, reg##_RSZ * (ri))
  859. #define ocelot_target_read(ocelot, target, reg) \
  860. __ocelot_target_read_ix(ocelot, target, reg, 0)
  861. #define ocelot_target_write_ix(ocelot, target, val, reg, gi, ri) \
  862. __ocelot_target_write_ix(ocelot, target, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  863. #define ocelot_target_write_gix(ocelot, target, val, reg, gi) \
  864. __ocelot_target_write_ix(ocelot, target, val, reg, reg##_GSZ * (gi))
  865. #define ocelot_target_write_rix(ocelot, target, val, reg, ri) \
  866. __ocelot_target_write_ix(ocelot, target, val, reg, reg##_RSZ * (ri))
  867. #define ocelot_target_write(ocelot, target, val, reg) \
  868. __ocelot_target_write_ix(ocelot, target, val, reg, 0)
  869. /* I/O */
  870. u32 ocelot_port_readl(struct ocelot_port *port, enum ocelot_reg reg);
  871. void ocelot_port_writel(struct ocelot_port *port, u32 val, enum ocelot_reg reg);
  872. void ocelot_port_rmwl(struct ocelot_port *port, u32 val, u32 mask,
  873. enum ocelot_reg reg);
  874. int __ocelot_bulk_read_ix(struct ocelot *ocelot, enum ocelot_reg reg,
  875. u32 offset, void *buf, int count);
  876. u32 __ocelot_read_ix(struct ocelot *ocelot, enum ocelot_reg reg, u32 offset);
  877. void __ocelot_write_ix(struct ocelot *ocelot, u32 val, enum ocelot_reg reg,
  878. u32 offset);
  879. void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask,
  880. enum ocelot_reg reg, u32 offset);
  881. u32 __ocelot_target_read_ix(struct ocelot *ocelot, enum ocelot_target target,
  882. u32 reg, u32 offset);
  883. void __ocelot_target_write_ix(struct ocelot *ocelot, enum ocelot_target target,
  884. u32 val, u32 reg, u32 offset);
  885. /* Packet I/O */
  886. void ocelot_lock_inj_grp(struct ocelot *ocelot, int grp);
  887. void ocelot_unlock_inj_grp(struct ocelot *ocelot, int grp);
  888. void ocelot_lock_xtr_grp(struct ocelot *ocelot, int grp);
  889. void ocelot_unlock_xtr_grp(struct ocelot *ocelot, int grp);
  890. void ocelot_lock_xtr_grp_bh(struct ocelot *ocelot, int grp);
  891. void ocelot_unlock_xtr_grp_bh(struct ocelot *ocelot, int grp);
  892. bool ocelot_can_inject(struct ocelot *ocelot, int grp);
  893. void ocelot_port_inject_frame(struct ocelot *ocelot, int port, int grp,
  894. u32 rew_op, struct sk_buff *skb);
  895. void ocelot_ifh_set_basic(void *ifh, struct ocelot *ocelot, int port,
  896. u32 rew_op, struct sk_buff *skb);
  897. int ocelot_xtr_poll_frame(struct ocelot *ocelot, int grp, struct sk_buff **skb);
  898. void ocelot_drain_cpu_queue(struct ocelot *ocelot, int grp);
  899. void ocelot_ptp_rx_timestamp(struct ocelot *ocelot, struct sk_buff *skb,
  900. u64 timestamp);
  901. /* Hardware initialization */
  902. int ocelot_regfields_init(struct ocelot *ocelot,
  903. const struct reg_field *const regfields);
  904. struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
  905. int ocelot_reset(struct ocelot *ocelot);
  906. int ocelot_init(struct ocelot *ocelot);
  907. void ocelot_deinit(struct ocelot *ocelot);
  908. void ocelot_init_port(struct ocelot *ocelot, int port);
  909. void ocelot_deinit_port(struct ocelot *ocelot, int port);
  910. void ocelot_port_setup_dsa_8021q_cpu(struct ocelot *ocelot, int cpu);
  911. void ocelot_port_teardown_dsa_8021q_cpu(struct ocelot *ocelot, int cpu);
  912. void ocelot_port_assign_dsa_8021q_cpu(struct ocelot *ocelot, int port, int cpu);
  913. void ocelot_port_unassign_dsa_8021q_cpu(struct ocelot *ocelot, int port);
  914. u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port);
  915. /* Watermark interface */
  916. u16 ocelot_wm_enc(u16 value);
  917. u16 ocelot_wm_dec(u16 wm);
  918. void ocelot_wm_stat(u32 val, u32 *inuse, u32 *maxuse);
  919. /* DSA callbacks */
  920. void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data);
  921. void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data);
  922. int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset);
  923. void ocelot_port_get_stats64(struct ocelot *ocelot, int port,
  924. struct rtnl_link_stats64 *stats);
  925. void ocelot_port_get_pause_stats(struct ocelot *ocelot, int port,
  926. struct ethtool_pause_stats *pause_stats);
  927. void ocelot_port_get_mm_stats(struct ocelot *ocelot, int port,
  928. struct ethtool_mm_stats *stats);
  929. void ocelot_port_get_rmon_stats(struct ocelot *ocelot, int port,
  930. struct ethtool_rmon_stats *rmon_stats,
  931. const struct ethtool_rmon_hist_range **ranges);
  932. void ocelot_port_get_eth_ctrl_stats(struct ocelot *ocelot, int port,
  933. struct ethtool_eth_ctrl_stats *ctrl_stats);
  934. void ocelot_port_get_eth_mac_stats(struct ocelot *ocelot, int port,
  935. struct ethtool_eth_mac_stats *mac_stats);
  936. void ocelot_port_get_eth_phy_stats(struct ocelot *ocelot, int port,
  937. struct ethtool_eth_phy_stats *phy_stats);
  938. int ocelot_get_ts_info(struct ocelot *ocelot, int port,
  939. struct kernel_ethtool_ts_info *info);
  940. void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs);
  941. int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, bool enabled,
  942. struct netlink_ext_ack *extack);
  943. void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state);
  944. u32 ocelot_get_bridge_fwd_mask(struct ocelot *ocelot, int src_port);
  945. int ocelot_port_pre_bridge_flags(struct ocelot *ocelot, int port,
  946. struct switchdev_brport_flags val);
  947. void ocelot_port_bridge_flags(struct ocelot *ocelot, int port,
  948. struct switchdev_brport_flags val);
  949. int ocelot_port_get_default_prio(struct ocelot *ocelot, int port);
  950. int ocelot_port_set_default_prio(struct ocelot *ocelot, int port, u8 prio);
  951. int ocelot_port_get_dscp_prio(struct ocelot *ocelot, int port, u8 dscp);
  952. int ocelot_port_add_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio);
  953. int ocelot_port_del_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio);
  954. int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
  955. struct net_device *bridge, int bridge_num,
  956. struct netlink_ext_ack *extack);
  957. void ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
  958. struct net_device *bridge);
  959. int ocelot_mact_flush(struct ocelot *ocelot, int port);
  960. int ocelot_fdb_dump(struct ocelot *ocelot, int port,
  961. dsa_fdb_dump_cb_t *cb, void *data);
  962. int ocelot_fdb_add(struct ocelot *ocelot, int port, const unsigned char *addr,
  963. u16 vid, const struct net_device *bridge);
  964. int ocelot_fdb_del(struct ocelot *ocelot, int port, const unsigned char *addr,
  965. u16 vid, const struct net_device *bridge);
  966. int ocelot_lag_fdb_add(struct ocelot *ocelot, struct net_device *bond,
  967. const unsigned char *addr, u16 vid,
  968. const struct net_device *bridge);
  969. int ocelot_lag_fdb_del(struct ocelot *ocelot, struct net_device *bond,
  970. const unsigned char *addr, u16 vid,
  971. const struct net_device *bridge);
  972. int ocelot_vlan_prepare(struct ocelot *ocelot, int port, u16 vid, bool pvid,
  973. bool untagged, struct netlink_ext_ack *extack);
  974. int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
  975. bool untagged);
  976. int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid);
  977. int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr);
  978. int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr);
  979. int ocelot_port_txtstamp_request(struct ocelot *ocelot, int port,
  980. struct sk_buff *skb,
  981. struct sk_buff **clone);
  982. void ocelot_get_txtstamp(struct ocelot *ocelot);
  983. void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu);
  984. int ocelot_get_max_mtu(struct ocelot *ocelot, int port);
  985. int ocelot_port_policer_add(struct ocelot *ocelot, int port,
  986. struct ocelot_policer *pol);
  987. int ocelot_port_policer_del(struct ocelot *ocelot, int port);
  988. int ocelot_port_mirror_add(struct ocelot *ocelot, int from, int to,
  989. bool ingress, struct netlink_ext_ack *extack);
  990. void ocelot_port_mirror_del(struct ocelot *ocelot, int from, bool ingress);
  991. int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,
  992. struct flow_cls_offload *f, bool ingress);
  993. int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,
  994. struct flow_cls_offload *f, bool ingress);
  995. int ocelot_cls_flower_stats(struct ocelot *ocelot, int port,
  996. struct flow_cls_offload *f, bool ingress);
  997. int ocelot_port_mdb_add(struct ocelot *ocelot, int port,
  998. const struct switchdev_obj_port_mdb *mdb,
  999. const struct net_device *bridge);
  1000. int ocelot_port_mdb_del(struct ocelot *ocelot, int port,
  1001. const struct switchdev_obj_port_mdb *mdb,
  1002. const struct net_device *bridge);
  1003. int ocelot_port_lag_join(struct ocelot *ocelot, int port,
  1004. struct net_device *bond,
  1005. struct netdev_lag_upper_info *info,
  1006. struct netlink_ext_ack *extack);
  1007. void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
  1008. struct net_device *bond);
  1009. void ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active);
  1010. int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond);
  1011. int ocelot_devlink_sb_register(struct ocelot *ocelot);
  1012. void ocelot_devlink_sb_unregister(struct ocelot *ocelot);
  1013. int ocelot_sb_pool_get(struct ocelot *ocelot, unsigned int sb_index,
  1014. u16 pool_index,
  1015. struct devlink_sb_pool_info *pool_info);
  1016. int ocelot_sb_pool_set(struct ocelot *ocelot, unsigned int sb_index,
  1017. u16 pool_index, u32 size,
  1018. enum devlink_sb_threshold_type threshold_type,
  1019. struct netlink_ext_ack *extack);
  1020. int ocelot_sb_port_pool_get(struct ocelot *ocelot, int port,
  1021. unsigned int sb_index, u16 pool_index,
  1022. u32 *p_threshold);
  1023. int ocelot_sb_port_pool_set(struct ocelot *ocelot, int port,
  1024. unsigned int sb_index, u16 pool_index,
  1025. u32 threshold, struct netlink_ext_ack *extack);
  1026. int ocelot_sb_tc_pool_bind_get(struct ocelot *ocelot, int port,
  1027. unsigned int sb_index, u16 tc_index,
  1028. enum devlink_sb_pool_type pool_type,
  1029. u16 *p_pool_index, u32 *p_threshold);
  1030. int ocelot_sb_tc_pool_bind_set(struct ocelot *ocelot, int port,
  1031. unsigned int sb_index, u16 tc_index,
  1032. enum devlink_sb_pool_type pool_type,
  1033. u16 pool_index, u32 threshold,
  1034. struct netlink_ext_ack *extack);
  1035. int ocelot_sb_occ_snapshot(struct ocelot *ocelot, unsigned int sb_index);
  1036. int ocelot_sb_occ_max_clear(struct ocelot *ocelot, unsigned int sb_index);
  1037. int ocelot_sb_occ_port_pool_get(struct ocelot *ocelot, int port,
  1038. unsigned int sb_index, u16 pool_index,
  1039. u32 *p_cur, u32 *p_max);
  1040. int ocelot_sb_occ_tc_port_bind_get(struct ocelot *ocelot, int port,
  1041. unsigned int sb_index, u16 tc_index,
  1042. enum devlink_sb_pool_type pool_type,
  1043. u32 *p_cur, u32 *p_max);
  1044. int ocelot_port_configure_serdes(struct ocelot *ocelot, int port,
  1045. struct device_node *portnp);
  1046. void ocelot_phylink_mac_config(struct ocelot *ocelot, int port,
  1047. unsigned int link_an_mode,
  1048. const struct phylink_link_state *state);
  1049. void ocelot_phylink_mac_link_down(struct ocelot *ocelot, int port,
  1050. unsigned int link_an_mode,
  1051. phy_interface_t interface,
  1052. unsigned long quirks);
  1053. void ocelot_phylink_mac_link_up(struct ocelot *ocelot, int port,
  1054. struct phy_device *phydev,
  1055. unsigned int link_an_mode,
  1056. phy_interface_t interface,
  1057. int speed, int duplex,
  1058. bool tx_pause, bool rx_pause,
  1059. unsigned long quirks);
  1060. int ocelot_mact_lookup(struct ocelot *ocelot, int *dst_idx,
  1061. const unsigned char mac[ETH_ALEN],
  1062. unsigned int vid, enum macaccess_entry_type *type);
  1063. int ocelot_mact_learn_streamdata(struct ocelot *ocelot, int dst_idx,
  1064. const unsigned char mac[ETH_ALEN],
  1065. unsigned int vid,
  1066. enum macaccess_entry_type type,
  1067. int sfid, int ssid);
  1068. int ocelot_migrate_mdbs(struct ocelot *ocelot, unsigned long from_mask,
  1069. unsigned long to_mask);
  1070. int ocelot_vcap_policer_add(struct ocelot *ocelot, u32 pol_ix,
  1071. struct ocelot_policer *pol);
  1072. int ocelot_vcap_policer_del(struct ocelot *ocelot, u32 pol_ix);
  1073. void ocelot_mm_irq(struct ocelot *ocelot);
  1074. int ocelot_port_set_mm(struct ocelot *ocelot, int port,
  1075. struct ethtool_mm_cfg *cfg,
  1076. struct netlink_ext_ack *extack);
  1077. int ocelot_port_get_mm(struct ocelot *ocelot, int port,
  1078. struct ethtool_mm_state *state);
  1079. int ocelot_port_mqprio(struct ocelot *ocelot, int port,
  1080. struct tc_mqprio_qopt_offload *mqprio);
  1081. #if IS_ENABLED(CONFIG_BRIDGE_MRP)
  1082. int ocelot_mrp_add(struct ocelot *ocelot, int port,
  1083. const struct switchdev_obj_mrp *mrp);
  1084. int ocelot_mrp_del(struct ocelot *ocelot, int port,
  1085. const struct switchdev_obj_mrp *mrp);
  1086. int ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port,
  1087. const struct switchdev_obj_ring_role_mrp *mrp);
  1088. int ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port,
  1089. const struct switchdev_obj_ring_role_mrp *mrp);
  1090. #else
  1091. static inline int ocelot_mrp_add(struct ocelot *ocelot, int port,
  1092. const struct switchdev_obj_mrp *mrp)
  1093. {
  1094. return -EOPNOTSUPP;
  1095. }
  1096. static inline int ocelot_mrp_del(struct ocelot *ocelot, int port,
  1097. const struct switchdev_obj_mrp *mrp)
  1098. {
  1099. return -EOPNOTSUPP;
  1100. }
  1101. static inline int
  1102. ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port,
  1103. const struct switchdev_obj_ring_role_mrp *mrp)
  1104. {
  1105. return -EOPNOTSUPP;
  1106. }
  1107. static inline int
  1108. ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port,
  1109. const struct switchdev_obj_ring_role_mrp *mrp)
  1110. {
  1111. return -EOPNOTSUPP;
  1112. }
  1113. #endif
  1114. void ocelot_pll5_init(struct ocelot *ocelot);
  1115. #endif