ocelot.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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_ts_stats {
  726. u64 pkts;
  727. u64 onestep_pkts_unconfirmed;
  728. u64 lost;
  729. u64 err;
  730. struct u64_stats_sync syncp;
  731. };
  732. struct ocelot_port;
  733. struct ocelot_port {
  734. struct ocelot *ocelot;
  735. struct regmap *target;
  736. struct net_device *bond;
  737. struct net_device *bridge;
  738. struct ocelot_port *dsa_8021q_cpu;
  739. /* VLAN that untagged frames are classified to, on ingress */
  740. const struct ocelot_bridge_vlan *pvid_vlan;
  741. struct tc_taprio_qopt_offload *taprio;
  742. phy_interface_t phy_mode;
  743. struct ocelot_ts_stats *ts_stats;
  744. struct sk_buff_head tx_skbs;
  745. unsigned int trap_proto;
  746. u16 mrp_ring_id;
  747. u8 ptp_cmd;
  748. u8 index;
  749. u8 stp_state;
  750. bool vlan_aware;
  751. bool is_dsa_8021q_cpu;
  752. bool learn_ena;
  753. bool lag_tx_active;
  754. int bridge_num;
  755. int speed;
  756. };
  757. struct ocelot {
  758. struct device *dev;
  759. struct devlink *devlink;
  760. struct devlink_port *devlink_ports;
  761. const struct ocelot_ops *ops;
  762. struct regmap *targets[TARGET_MAX];
  763. struct regmap_field *regfields[REGFIELD_MAX];
  764. const u32 *const *map;
  765. struct list_head stats_regions;
  766. spinlock_t inj_lock;
  767. spinlock_t xtr_lock;
  768. u32 pool_size[OCELOT_SB_NUM][OCELOT_SB_POOL_NUM];
  769. int packet_buffer_size;
  770. int num_frame_refs;
  771. int num_mact_rows;
  772. struct ocelot_port **ports;
  773. u8 base_mac[ETH_ALEN];
  774. struct list_head vlans;
  775. struct list_head traps;
  776. struct list_head lag_fdbs;
  777. /* Switches like VSC9959 have flooding per traffic class */
  778. int num_flooding_pgids;
  779. /* In tables like ANA:PORT and the ANA:PGID:PGID mask,
  780. * the CPU is located after the physical ports (at the
  781. * num_phys_ports index).
  782. */
  783. u8 num_phys_ports;
  784. int npi;
  785. enum ocelot_tag_prefix npi_inj_prefix;
  786. enum ocelot_tag_prefix npi_xtr_prefix;
  787. unsigned long bridges;
  788. struct list_head multicast;
  789. struct list_head pgids;
  790. struct list_head dummy_rules;
  791. struct ocelot_vcap_block block[3];
  792. struct ocelot_vcap_policer vcap_pol;
  793. struct vcap_props *vcap;
  794. struct ocelot_mirror *mirror;
  795. struct ocelot_psfp_list psfp;
  796. /* Workqueue to check statistics for overflow */
  797. struct delayed_work stats_work;
  798. struct workqueue_struct *stats_queue;
  799. /* Lock for serializing access to the statistics array */
  800. spinlock_t stats_lock;
  801. u64 *stats;
  802. /* Lock for serializing indirect access to STAT_VIEW registers */
  803. struct mutex stat_view_lock;
  804. /* Lock for serializing access to the MAC table */
  805. struct mutex mact_lock;
  806. /* Lock for serializing forwarding domain changes, including the
  807. * configuration of the Time-Aware Shaper, MAC Merge layer and
  808. * cut-through forwarding, on which it depends
  809. */
  810. struct mutex fwd_domain_lock;
  811. struct workqueue_struct *owq;
  812. u8 ptp:1;
  813. u8 mm_supported:1;
  814. struct ptp_clock *ptp_clock;
  815. struct ptp_clock_info ptp_info;
  816. unsigned int ptp_skbs_in_flight;
  817. /* Protects the 2-step TX timestamp ID logic */
  818. spinlock_t ts_id_lock;
  819. /* Protects the PTP clock */
  820. spinlock_t ptp_clock_lock;
  821. struct ptp_pin_desc ptp_pins[OCELOT_PTP_PINS_NUM];
  822. struct ocelot_mm_state *mm;
  823. struct ocelot_fdma *fdma;
  824. };
  825. struct ocelot_policer {
  826. u32 rate; /* kilobit per second */
  827. u32 burst; /* bytes */
  828. };
  829. #define ocelot_bulk_read(ocelot, reg, buf, count) \
  830. __ocelot_bulk_read_ix(ocelot, reg, 0, buf, count)
  831. #define ocelot_read_ix(ocelot, reg, gi, ri) \
  832. __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  833. #define ocelot_read_gix(ocelot, reg, gi) \
  834. __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
  835. #define ocelot_read_rix(ocelot, reg, ri) \
  836. __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
  837. #define ocelot_read(ocelot, reg) \
  838. __ocelot_read_ix(ocelot, reg, 0)
  839. #define ocelot_write_ix(ocelot, val, reg, gi, ri) \
  840. __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  841. #define ocelot_write_gix(ocelot, val, reg, gi) \
  842. __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi))
  843. #define ocelot_write_rix(ocelot, val, reg, ri) \
  844. __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
  845. #define ocelot_write(ocelot, val, reg) __ocelot_write_ix(ocelot, val, reg, 0)
  846. #define ocelot_rmw_ix(ocelot, val, m, reg, gi, ri) \
  847. __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  848. #define ocelot_rmw_gix(ocelot, val, m, reg, gi) \
  849. __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi))
  850. #define ocelot_rmw_rix(ocelot, val, m, reg, ri) \
  851. __ocelot_rmw_ix(ocelot, val, m, reg, reg##_RSZ * (ri))
  852. #define ocelot_rmw(ocelot, val, m, reg) __ocelot_rmw_ix(ocelot, val, m, reg, 0)
  853. #define ocelot_field_write(ocelot, reg, val) \
  854. regmap_field_write((ocelot)->regfields[(reg)], (val))
  855. #define ocelot_field_read(ocelot, reg, val) \
  856. regmap_field_read((ocelot)->regfields[(reg)], (val))
  857. #define ocelot_fields_write(ocelot, id, reg, val) \
  858. regmap_fields_write((ocelot)->regfields[(reg)], (id), (val))
  859. #define ocelot_fields_read(ocelot, id, reg, val) \
  860. regmap_fields_read((ocelot)->regfields[(reg)], (id), (val))
  861. #define ocelot_target_read_ix(ocelot, target, reg, gi, ri) \
  862. __ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  863. #define ocelot_target_read_gix(ocelot, target, reg, gi) \
  864. __ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi))
  865. #define ocelot_target_read_rix(ocelot, target, reg, ri) \
  866. __ocelot_target_read_ix(ocelot, target, reg, reg##_RSZ * (ri))
  867. #define ocelot_target_read(ocelot, target, reg) \
  868. __ocelot_target_read_ix(ocelot, target, reg, 0)
  869. #define ocelot_target_write_ix(ocelot, target, val, reg, gi, ri) \
  870. __ocelot_target_write_ix(ocelot, target, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
  871. #define ocelot_target_write_gix(ocelot, target, val, reg, gi) \
  872. __ocelot_target_write_ix(ocelot, target, val, reg, reg##_GSZ * (gi))
  873. #define ocelot_target_write_rix(ocelot, target, val, reg, ri) \
  874. __ocelot_target_write_ix(ocelot, target, val, reg, reg##_RSZ * (ri))
  875. #define ocelot_target_write(ocelot, target, val, reg) \
  876. __ocelot_target_write_ix(ocelot, target, val, reg, 0)
  877. /* I/O */
  878. u32 ocelot_port_readl(struct ocelot_port *port, enum ocelot_reg reg);
  879. void ocelot_port_writel(struct ocelot_port *port, u32 val, enum ocelot_reg reg);
  880. void ocelot_port_rmwl(struct ocelot_port *port, u32 val, u32 mask,
  881. enum ocelot_reg reg);
  882. int __ocelot_bulk_read_ix(struct ocelot *ocelot, enum ocelot_reg reg,
  883. u32 offset, void *buf, int count);
  884. u32 __ocelot_read_ix(struct ocelot *ocelot, enum ocelot_reg reg, u32 offset);
  885. void __ocelot_write_ix(struct ocelot *ocelot, u32 val, enum ocelot_reg reg,
  886. u32 offset);
  887. void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask,
  888. enum ocelot_reg reg, u32 offset);
  889. u32 __ocelot_target_read_ix(struct ocelot *ocelot, enum ocelot_target target,
  890. u32 reg, u32 offset);
  891. void __ocelot_target_write_ix(struct ocelot *ocelot, enum ocelot_target target,
  892. u32 val, u32 reg, u32 offset);
  893. /* Packet I/O */
  894. void ocelot_lock_inj_grp(struct ocelot *ocelot, int grp);
  895. void ocelot_unlock_inj_grp(struct ocelot *ocelot, int grp);
  896. void ocelot_lock_xtr_grp(struct ocelot *ocelot, int grp);
  897. void ocelot_unlock_xtr_grp(struct ocelot *ocelot, int grp);
  898. void ocelot_lock_xtr_grp_bh(struct ocelot *ocelot, int grp);
  899. void ocelot_unlock_xtr_grp_bh(struct ocelot *ocelot, int grp);
  900. bool ocelot_can_inject(struct ocelot *ocelot, int grp);
  901. void ocelot_port_inject_frame(struct ocelot *ocelot, int port, int grp,
  902. u32 rew_op, struct sk_buff *skb);
  903. void ocelot_ifh_set_basic(void *ifh, struct ocelot *ocelot, int port,
  904. u32 rew_op, struct sk_buff *skb);
  905. int ocelot_xtr_poll_frame(struct ocelot *ocelot, int grp, struct sk_buff **skb);
  906. void ocelot_drain_cpu_queue(struct ocelot *ocelot, int grp);
  907. void ocelot_ptp_rx_timestamp(struct ocelot *ocelot, struct sk_buff *skb,
  908. u64 timestamp);
  909. /* Hardware initialization */
  910. int ocelot_regfields_init(struct ocelot *ocelot,
  911. const struct reg_field *const regfields);
  912. struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
  913. int ocelot_reset(struct ocelot *ocelot);
  914. int ocelot_init(struct ocelot *ocelot);
  915. void ocelot_deinit(struct ocelot *ocelot);
  916. void ocelot_init_port(struct ocelot *ocelot, int port);
  917. void ocelot_deinit_port(struct ocelot *ocelot, int port);
  918. void ocelot_port_setup_dsa_8021q_cpu(struct ocelot *ocelot, int cpu);
  919. void ocelot_port_teardown_dsa_8021q_cpu(struct ocelot *ocelot, int cpu);
  920. void ocelot_port_assign_dsa_8021q_cpu(struct ocelot *ocelot, int port, int cpu);
  921. void ocelot_port_unassign_dsa_8021q_cpu(struct ocelot *ocelot, int port);
  922. u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port);
  923. /* Watermark interface */
  924. u16 ocelot_wm_enc(u16 value);
  925. u16 ocelot_wm_dec(u16 wm);
  926. void ocelot_wm_stat(u32 val, u32 *inuse, u32 *maxuse);
  927. /* DSA callbacks */
  928. void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data);
  929. void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data);
  930. int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset);
  931. void ocelot_port_get_stats64(struct ocelot *ocelot, int port,
  932. struct rtnl_link_stats64 *stats);
  933. void ocelot_port_get_pause_stats(struct ocelot *ocelot, int port,
  934. struct ethtool_pause_stats *pause_stats);
  935. void ocelot_port_get_mm_stats(struct ocelot *ocelot, int port,
  936. struct ethtool_mm_stats *stats);
  937. void ocelot_port_get_rmon_stats(struct ocelot *ocelot, int port,
  938. struct ethtool_rmon_stats *rmon_stats,
  939. const struct ethtool_rmon_hist_range **ranges);
  940. void ocelot_port_get_eth_ctrl_stats(struct ocelot *ocelot, int port,
  941. struct ethtool_eth_ctrl_stats *ctrl_stats);
  942. void ocelot_port_get_eth_mac_stats(struct ocelot *ocelot, int port,
  943. struct ethtool_eth_mac_stats *mac_stats);
  944. void ocelot_port_get_eth_phy_stats(struct ocelot *ocelot, int port,
  945. struct ethtool_eth_phy_stats *phy_stats);
  946. void ocelot_port_get_ts_stats(struct ocelot *ocelot, int port,
  947. struct ethtool_ts_stats *ts_stats);
  948. int ocelot_get_ts_info(struct ocelot *ocelot, int port,
  949. struct kernel_ethtool_ts_info *info);
  950. void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs);
  951. int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, bool enabled,
  952. struct netlink_ext_ack *extack);
  953. void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state);
  954. u32 ocelot_get_bridge_fwd_mask(struct ocelot *ocelot, int src_port);
  955. int ocelot_port_pre_bridge_flags(struct ocelot *ocelot, int port,
  956. struct switchdev_brport_flags val);
  957. void ocelot_port_bridge_flags(struct ocelot *ocelot, int port,
  958. struct switchdev_brport_flags val);
  959. int ocelot_port_get_default_prio(struct ocelot *ocelot, int port);
  960. int ocelot_port_set_default_prio(struct ocelot *ocelot, int port, u8 prio);
  961. int ocelot_port_get_dscp_prio(struct ocelot *ocelot, int port, u8 dscp);
  962. int ocelot_port_add_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio);
  963. int ocelot_port_del_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio);
  964. int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
  965. struct net_device *bridge, int bridge_num,
  966. struct netlink_ext_ack *extack);
  967. void ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
  968. struct net_device *bridge);
  969. int ocelot_mact_flush(struct ocelot *ocelot, int port);
  970. int ocelot_fdb_dump(struct ocelot *ocelot, int port,
  971. dsa_fdb_dump_cb_t *cb, void *data);
  972. int ocelot_fdb_add(struct ocelot *ocelot, int port, const unsigned char *addr,
  973. u16 vid, const struct net_device *bridge);
  974. int ocelot_fdb_del(struct ocelot *ocelot, int port, const unsigned char *addr,
  975. u16 vid, const struct net_device *bridge);
  976. int ocelot_lag_fdb_add(struct ocelot *ocelot, struct net_device *bond,
  977. const unsigned char *addr, u16 vid,
  978. const struct net_device *bridge);
  979. int ocelot_lag_fdb_del(struct ocelot *ocelot, struct net_device *bond,
  980. const unsigned char *addr, u16 vid,
  981. const struct net_device *bridge);
  982. int ocelot_vlan_prepare(struct ocelot *ocelot, int port, u16 vid, bool pvid,
  983. bool untagged, struct netlink_ext_ack *extack);
  984. int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
  985. bool untagged);
  986. int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid);
  987. void ocelot_hwstamp_get(struct ocelot *ocelot, int port,
  988. struct kernel_hwtstamp_config *cfg);
  989. int ocelot_hwstamp_set(struct ocelot *ocelot, int port,
  990. struct kernel_hwtstamp_config *cfg,
  991. struct netlink_ext_ack *extack);
  992. int ocelot_port_txtstamp_request(struct ocelot *ocelot, int port,
  993. struct sk_buff *skb,
  994. struct sk_buff **clone);
  995. void ocelot_get_txtstamp(struct ocelot *ocelot);
  996. void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu);
  997. int ocelot_get_max_mtu(struct ocelot *ocelot, int port);
  998. int ocelot_port_policer_add(struct ocelot *ocelot, int port,
  999. struct ocelot_policer *pol);
  1000. int ocelot_port_policer_del(struct ocelot *ocelot, int port);
  1001. int ocelot_port_mirror_add(struct ocelot *ocelot, int from, int to,
  1002. bool ingress, struct netlink_ext_ack *extack);
  1003. void ocelot_port_mirror_del(struct ocelot *ocelot, int from, bool ingress);
  1004. int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,
  1005. struct flow_cls_offload *f, bool ingress);
  1006. int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,
  1007. struct flow_cls_offload *f, bool ingress);
  1008. int ocelot_cls_flower_stats(struct ocelot *ocelot, int port,
  1009. struct flow_cls_offload *f, bool ingress);
  1010. int ocelot_port_mdb_add(struct ocelot *ocelot, int port,
  1011. const struct switchdev_obj_port_mdb *mdb,
  1012. const struct net_device *bridge);
  1013. int ocelot_port_mdb_del(struct ocelot *ocelot, int port,
  1014. const struct switchdev_obj_port_mdb *mdb,
  1015. const struct net_device *bridge);
  1016. int ocelot_port_lag_join(struct ocelot *ocelot, int port,
  1017. struct net_device *bond,
  1018. struct netdev_lag_upper_info *info,
  1019. struct netlink_ext_ack *extack);
  1020. void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
  1021. struct net_device *bond);
  1022. void ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active);
  1023. int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond);
  1024. int ocelot_devlink_sb_register(struct ocelot *ocelot);
  1025. void ocelot_devlink_sb_unregister(struct ocelot *ocelot);
  1026. int ocelot_sb_pool_get(struct ocelot *ocelot, unsigned int sb_index,
  1027. u16 pool_index,
  1028. struct devlink_sb_pool_info *pool_info);
  1029. int ocelot_sb_pool_set(struct ocelot *ocelot, unsigned int sb_index,
  1030. u16 pool_index, u32 size,
  1031. enum devlink_sb_threshold_type threshold_type,
  1032. struct netlink_ext_ack *extack);
  1033. int ocelot_sb_port_pool_get(struct ocelot *ocelot, int port,
  1034. unsigned int sb_index, u16 pool_index,
  1035. u32 *p_threshold);
  1036. int ocelot_sb_port_pool_set(struct ocelot *ocelot, int port,
  1037. unsigned int sb_index, u16 pool_index,
  1038. u32 threshold, struct netlink_ext_ack *extack);
  1039. int ocelot_sb_tc_pool_bind_get(struct ocelot *ocelot, int port,
  1040. unsigned int sb_index, u16 tc_index,
  1041. enum devlink_sb_pool_type pool_type,
  1042. u16 *p_pool_index, u32 *p_threshold);
  1043. int ocelot_sb_tc_pool_bind_set(struct ocelot *ocelot, int port,
  1044. unsigned int sb_index, u16 tc_index,
  1045. enum devlink_sb_pool_type pool_type,
  1046. u16 pool_index, u32 threshold,
  1047. struct netlink_ext_ack *extack);
  1048. int ocelot_sb_occ_snapshot(struct ocelot *ocelot, unsigned int sb_index);
  1049. int ocelot_sb_occ_max_clear(struct ocelot *ocelot, unsigned int sb_index);
  1050. int ocelot_sb_occ_port_pool_get(struct ocelot *ocelot, int port,
  1051. unsigned int sb_index, u16 pool_index,
  1052. u32 *p_cur, u32 *p_max);
  1053. int ocelot_sb_occ_tc_port_bind_get(struct ocelot *ocelot, int port,
  1054. unsigned int sb_index, u16 tc_index,
  1055. enum devlink_sb_pool_type pool_type,
  1056. u32 *p_cur, u32 *p_max);
  1057. int ocelot_port_configure_serdes(struct ocelot *ocelot, int port,
  1058. struct device_node *portnp);
  1059. void ocelot_phylink_mac_config(struct ocelot *ocelot, int port,
  1060. unsigned int link_an_mode,
  1061. const struct phylink_link_state *state);
  1062. void ocelot_phylink_mac_link_down(struct ocelot *ocelot, int port,
  1063. unsigned int link_an_mode,
  1064. phy_interface_t interface,
  1065. unsigned long quirks);
  1066. void ocelot_phylink_mac_link_up(struct ocelot *ocelot, int port,
  1067. struct phy_device *phydev,
  1068. unsigned int link_an_mode,
  1069. phy_interface_t interface,
  1070. int speed, int duplex,
  1071. bool tx_pause, bool rx_pause,
  1072. unsigned long quirks);
  1073. int ocelot_mact_lookup(struct ocelot *ocelot, int *dst_idx,
  1074. const unsigned char mac[ETH_ALEN],
  1075. unsigned int vid, enum macaccess_entry_type *type);
  1076. int ocelot_mact_learn_streamdata(struct ocelot *ocelot, int dst_idx,
  1077. const unsigned char mac[ETH_ALEN],
  1078. unsigned int vid,
  1079. enum macaccess_entry_type type,
  1080. int sfid, int ssid);
  1081. int ocelot_migrate_mdbs(struct ocelot *ocelot, unsigned long from_mask,
  1082. unsigned long to_mask);
  1083. int ocelot_vcap_policer_add(struct ocelot *ocelot, u32 pol_ix,
  1084. struct ocelot_policer *pol);
  1085. int ocelot_vcap_policer_del(struct ocelot *ocelot, u32 pol_ix);
  1086. void ocelot_mm_irq(struct ocelot *ocelot);
  1087. int ocelot_port_set_mm(struct ocelot *ocelot, int port,
  1088. struct ethtool_mm_cfg *cfg,
  1089. struct netlink_ext_ack *extack);
  1090. int ocelot_port_get_mm(struct ocelot *ocelot, int port,
  1091. struct ethtool_mm_state *state);
  1092. int ocelot_port_mqprio(struct ocelot *ocelot, int port,
  1093. struct tc_mqprio_qopt_offload *mqprio);
  1094. #if IS_ENABLED(CONFIG_BRIDGE_MRP)
  1095. int ocelot_mrp_add(struct ocelot *ocelot, int port,
  1096. const struct switchdev_obj_mrp *mrp);
  1097. int ocelot_mrp_del(struct ocelot *ocelot, int port,
  1098. const struct switchdev_obj_mrp *mrp);
  1099. int ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port,
  1100. const struct switchdev_obj_ring_role_mrp *mrp);
  1101. int ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port,
  1102. const struct switchdev_obj_ring_role_mrp *mrp);
  1103. #else
  1104. static inline int ocelot_mrp_add(struct ocelot *ocelot, int port,
  1105. const struct switchdev_obj_mrp *mrp)
  1106. {
  1107. return -EOPNOTSUPP;
  1108. }
  1109. static inline int ocelot_mrp_del(struct ocelot *ocelot, int port,
  1110. const struct switchdev_obj_mrp *mrp)
  1111. {
  1112. return -EOPNOTSUPP;
  1113. }
  1114. static inline int
  1115. ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port,
  1116. const struct switchdev_obj_ring_role_mrp *mrp)
  1117. {
  1118. return -EOPNOTSUPP;
  1119. }
  1120. static inline int
  1121. ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port,
  1122. const struct switchdev_obj_ring_role_mrp *mrp)
  1123. {
  1124. return -EOPNOTSUPP;
  1125. }
  1126. #endif
  1127. void ocelot_pll5_init(struct ocelot *ocelot);
  1128. #endif