dsa.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <net/dsa.h>
  3. #include <linux/if_bridge.h>
  4. #include <asm/mach-rtl838x/mach-rtl83xx.h>
  5. #include "rtl83xx.h"
  6. extern struct rtl83xx_soc_info soc_info;
  7. static void rtl83xx_init_stats(struct rtl838x_switch_priv *priv)
  8. {
  9. mutex_lock(&priv->reg_mutex);
  10. /* Enable statistics module: all counters plus debug.
  11. * On RTL839x all counters are enabled by default
  12. */
  13. if (priv->family_id == RTL8380_FAMILY_ID)
  14. sw_w32_mask(0, 3, RTL838X_STAT_CTRL);
  15. /* Reset statistics counters */
  16. sw_w32_mask(0, 1, priv->r->stat_rst);
  17. mutex_unlock(&priv->reg_mutex);
  18. }
  19. static void rtl83xx_enable_phy_polling(struct rtl838x_switch_priv *priv)
  20. {
  21. u64 v = 0;
  22. msleep(1000);
  23. /* Enable all ports with a PHY, including the SFP-ports */
  24. for (int i = 0; i < priv->cpu_port; i++) {
  25. if (priv->ports[i].phy)
  26. v |= BIT_ULL(i);
  27. }
  28. pr_info("%s: %16llx\n", __func__, v);
  29. priv->r->set_port_reg_le(v, priv->r->smi_poll_ctrl);
  30. /* PHY update complete, there is no global PHY polling enable bit on the 9300 */
  31. if (priv->family_id == RTL8390_FAMILY_ID)
  32. sw_w32_mask(0, BIT(7), RTL839X_SMI_GLB_CTRL);
  33. else if(priv->family_id == RTL9300_FAMILY_ID)
  34. sw_w32_mask(0, 0x8000, RTL838X_SMI_GLB_CTRL);
  35. }
  36. const struct rtl83xx_mib_desc rtl83xx_mib[] = {
  37. MIB_DESC(2, 0xf8, "ifInOctets"),
  38. MIB_DESC(2, 0xf0, "ifOutOctets"),
  39. MIB_DESC(1, 0xec, "dot1dTpPortInDiscards"),
  40. MIB_DESC(1, 0xe8, "ifInUcastPkts"),
  41. MIB_DESC(1, 0xe4, "ifInMulticastPkts"),
  42. MIB_DESC(1, 0xe0, "ifInBroadcastPkts"),
  43. MIB_DESC(1, 0xdc, "ifOutUcastPkts"),
  44. MIB_DESC(1, 0xd8, "ifOutMulticastPkts"),
  45. MIB_DESC(1, 0xd4, "ifOutBroadcastPkts"),
  46. MIB_DESC(1, 0xd0, "ifOutDiscards"),
  47. MIB_DESC(1, 0xcc, ".3SingleCollisionFrames"),
  48. MIB_DESC(1, 0xc8, ".3MultipleCollisionFrames"),
  49. MIB_DESC(1, 0xc4, ".3DeferredTransmissions"),
  50. MIB_DESC(1, 0xc0, ".3LateCollisions"),
  51. MIB_DESC(1, 0xbc, ".3ExcessiveCollisions"),
  52. MIB_DESC(1, 0xb8, ".3SymbolErrors"),
  53. MIB_DESC(1, 0xb4, ".3ControlInUnknownOpcodes"),
  54. MIB_DESC(1, 0xb0, ".3InPauseFrames"),
  55. MIB_DESC(1, 0xac, ".3OutPauseFrames"),
  56. MIB_DESC(1, 0xa8, "DropEvents"),
  57. MIB_DESC(1, 0xa4, "tx_BroadcastPkts"),
  58. MIB_DESC(1, 0xa0, "tx_MulticastPkts"),
  59. MIB_DESC(1, 0x9c, "CRCAlignErrors"),
  60. MIB_DESC(1, 0x98, "tx_UndersizePkts"),
  61. MIB_DESC(1, 0x94, "rx_UndersizePkts"),
  62. MIB_DESC(1, 0x90, "rx_UndersizedropPkts"),
  63. MIB_DESC(1, 0x8c, "tx_OversizePkts"),
  64. MIB_DESC(1, 0x88, "rx_OversizePkts"),
  65. MIB_DESC(1, 0x84, "Fragments"),
  66. MIB_DESC(1, 0x80, "Jabbers"),
  67. MIB_DESC(1, 0x7c, "Collisions"),
  68. MIB_DESC(1, 0x78, "tx_Pkts64Octets"),
  69. MIB_DESC(1, 0x74, "rx_Pkts64Octets"),
  70. MIB_DESC(1, 0x70, "tx_Pkts65to127Octets"),
  71. MIB_DESC(1, 0x6c, "rx_Pkts65to127Octets"),
  72. MIB_DESC(1, 0x68, "tx_Pkts128to255Octets"),
  73. MIB_DESC(1, 0x64, "rx_Pkts128to255Octets"),
  74. MIB_DESC(1, 0x60, "tx_Pkts256to511Octets"),
  75. MIB_DESC(1, 0x5c, "rx_Pkts256to511Octets"),
  76. MIB_DESC(1, 0x58, "tx_Pkts512to1023Octets"),
  77. MIB_DESC(1, 0x54, "rx_Pkts512to1023Octets"),
  78. MIB_DESC(1, 0x50, "tx_Pkts1024to1518Octets"),
  79. MIB_DESC(1, 0x4c, "rx_StatsPkts1024to1518Octets"),
  80. MIB_DESC(1, 0x48, "tx_Pkts1519toMaxOctets"),
  81. MIB_DESC(1, 0x44, "rx_Pkts1519toMaxOctets"),
  82. MIB_DESC(1, 0x40, "rxMacDiscards")
  83. };
  84. /* DSA callbacks */
  85. static enum dsa_tag_protocol rtl83xx_get_tag_protocol(struct dsa_switch *ds,
  86. int port,
  87. enum dsa_tag_protocol mprot)
  88. {
  89. /* The switch does not tag the frames, instead internally the header
  90. * structure for each packet is tagged accordingly.
  91. */
  92. return DSA_TAG_PROTO_TRAILER;
  93. }
  94. /* Initialize all VLANS */
  95. static void rtl83xx_vlan_setup(struct rtl838x_switch_priv *priv)
  96. {
  97. struct rtl838x_vlan_info info;
  98. pr_info("In %s\n", __func__);
  99. priv->r->vlan_profile_setup(0);
  100. priv->r->vlan_profile_setup(1);
  101. pr_info("UNKNOWN_MC_PMASK: %016llx\n", priv->r->read_mcast_pmask(UNKNOWN_MC_PMASK));
  102. priv->r->vlan_profile_dump(0);
  103. info.fid = 0; /* Default Forwarding ID / MSTI */
  104. info.hash_uc_fid = false; /* Do not build the L2 lookup hash with FID, but VID */
  105. info.hash_mc_fid = false; /* Do the same for Multicast packets */
  106. info.profile_id = 0; /* Use default Vlan Profile 0 */
  107. info.tagged_ports = 0; /* Initially no port members */
  108. if (priv->family_id == RTL9310_FAMILY_ID) {
  109. info.if_id = 0;
  110. info.multicast_grp_mask = 0;
  111. info.l2_tunnel_list_id = -1;
  112. }
  113. /* Initialize all vlans 0-4095 */
  114. for (int i = 0; i < MAX_VLANS; i ++)
  115. priv->r->vlan_set_tagged(i, &info);
  116. /* reset PVIDs; defaults to 1 on reset */
  117. for (int i = 0; i <= priv->ds->num_ports; i++) {
  118. priv->r->vlan_port_pvid_set(i, PBVLAN_TYPE_INNER, 0);
  119. priv->r->vlan_port_pvid_set(i, PBVLAN_TYPE_OUTER, 0);
  120. priv->r->vlan_port_pvidmode_set(i, PBVLAN_TYPE_INNER, PBVLAN_MODE_UNTAG_AND_PRITAG);
  121. priv->r->vlan_port_pvidmode_set(i, PBVLAN_TYPE_OUTER, PBVLAN_MODE_UNTAG_AND_PRITAG);
  122. }
  123. /* Set forwarding action based on inner VLAN tag */
  124. for (int i = 0; i < priv->cpu_port; i++)
  125. priv->r->vlan_fwd_on_inner(i, true);
  126. }
  127. static void rtl83xx_setup_bpdu_traps(struct rtl838x_switch_priv *priv)
  128. {
  129. for (int i = 0; i < priv->cpu_port; i++)
  130. priv->r->set_receive_management_action(i, BPDU, COPY2CPU);
  131. }
  132. static void rtl83xx_port_set_salrn(struct rtl838x_switch_priv *priv,
  133. int port, bool enable)
  134. {
  135. int shift = SALRN_PORT_SHIFT(port);
  136. int val = enable ? SALRN_MODE_HARDWARE : SALRN_MODE_DISABLED;
  137. sw_w32_mask(SALRN_MODE_MASK << shift, val << shift,
  138. priv->r->l2_port_new_salrn(port));
  139. }
  140. static int rtl83xx_setup(struct dsa_switch *ds)
  141. {
  142. struct rtl838x_switch_priv *priv = ds->priv;
  143. pr_debug("%s called\n", __func__);
  144. /* Disable MAC polling the PHY so that we can start configuration */
  145. priv->r->set_port_reg_le(0ULL, priv->r->smi_poll_ctrl);
  146. for (int i = 0; i < ds->num_ports; i++)
  147. priv->ports[i].enable = false;
  148. priv->ports[priv->cpu_port].enable = true;
  149. /* Configure ports so they are disabled by default, but once enabled
  150. * they will work in isolated mode (only traffic between port and CPU).
  151. */
  152. for (int i = 0; i < priv->cpu_port; i++) {
  153. if (priv->ports[i].phy) {
  154. priv->ports[i].pm = BIT_ULL(priv->cpu_port);
  155. priv->r->traffic_set(i, BIT_ULL(i));
  156. }
  157. }
  158. priv->r->traffic_set(priv->cpu_port, BIT_ULL(priv->cpu_port));
  159. /* For standalone ports, forward packets even if a static fdb
  160. * entry for the source address exists on another port.
  161. */
  162. if (priv->r->set_static_move_action) {
  163. for (int i = 0; i <= priv->cpu_port; i++)
  164. priv->r->set_static_move_action(i, true);
  165. }
  166. if (priv->family_id == RTL8380_FAMILY_ID)
  167. rtl838x_print_matrix();
  168. else
  169. rtl839x_print_matrix();
  170. rtl83xx_init_stats(priv);
  171. rtl83xx_vlan_setup(priv);
  172. rtl83xx_setup_bpdu_traps(priv);
  173. ds->configure_vlan_while_not_filtering = true;
  174. priv->r->l2_learning_setup();
  175. rtl83xx_port_set_salrn(priv, priv->cpu_port, false);
  176. ds->assisted_learning_on_cpu_port = true;
  177. /* Make sure all frames sent to the switch's MAC are trapped to the CPU-port
  178. * 0: FWD, 1: DROP, 2: TRAP2CPU
  179. */
  180. if (priv->family_id == RTL8380_FAMILY_ID)
  181. sw_w32(0x2, RTL838X_SPCL_TRAP_SWITCH_MAC_CTRL);
  182. else
  183. sw_w32(0x2, RTL839X_SPCL_TRAP_SWITCH_MAC_CTRL);
  184. /* Enable MAC Polling PHY again */
  185. rtl83xx_enable_phy_polling(priv);
  186. pr_debug("Please wait until PHY is settled\n");
  187. msleep(1000);
  188. priv->r->pie_init(priv);
  189. return 0;
  190. }
  191. static int rtl93xx_setup(struct dsa_switch *ds)
  192. {
  193. struct rtl838x_switch_priv *priv = ds->priv;
  194. pr_info("%s called\n", __func__);
  195. /* Disable MAC polling the PHY so that we can start configuration */
  196. if (priv->family_id == RTL9300_FAMILY_ID)
  197. sw_w32(0, RTL930X_SMI_POLL_CTRL);
  198. if (priv->family_id == RTL9310_FAMILY_ID) {
  199. sw_w32(0, RTL931X_SMI_PORT_POLLING_CTRL);
  200. sw_w32(0, RTL931X_SMI_PORT_POLLING_CTRL + 4);
  201. }
  202. /* Disable all ports except CPU port */
  203. for (int i = 0; i < ds->num_ports; i++)
  204. priv->ports[i].enable = false;
  205. priv->ports[priv->cpu_port].enable = true;
  206. /* Configure ports so they are disabled by default, but once enabled
  207. * they will work in isolated mode (only traffic between port and CPU).
  208. */
  209. for (int i = 0; i < priv->cpu_port; i++) {
  210. if (priv->ports[i].phy) {
  211. priv->ports[i].pm = BIT_ULL(priv->cpu_port);
  212. priv->r->traffic_set(i, BIT_ULL(i));
  213. }
  214. }
  215. priv->r->traffic_set(priv->cpu_port, BIT_ULL(priv->cpu_port));
  216. rtl930x_print_matrix();
  217. /* TODO: Initialize statistics */
  218. rtl83xx_vlan_setup(priv);
  219. ds->configure_vlan_while_not_filtering = true;
  220. priv->r->l2_learning_setup();
  221. rtl83xx_port_set_salrn(priv, priv->cpu_port, false);
  222. ds->assisted_learning_on_cpu_port = true;
  223. rtl83xx_enable_phy_polling(priv);
  224. priv->r->pie_init(priv);
  225. priv->r->led_init(priv);
  226. return 0;
  227. }
  228. static int rtl93xx_get_sds(struct phy_device *phydev)
  229. {
  230. struct device *dev = &phydev->mdio.dev;
  231. struct device_node *dn;
  232. u32 sds_num;
  233. if (!dev)
  234. return -1;
  235. if (dev->of_node) {
  236. dn = dev->of_node;
  237. if (of_property_read_u32(dn, "sds", &sds_num))
  238. sds_num = -1;
  239. } else {
  240. dev_err(dev, "No DT node.\n");
  241. return -1;
  242. }
  243. return sds_num;
  244. }
  245. static void rtl83xx_phylink_validate(struct dsa_switch *ds, int port,
  246. unsigned long *supported,
  247. struct phylink_link_state *state)
  248. {
  249. struct rtl838x_switch_priv *priv = ds->priv;
  250. __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
  251. pr_debug("In %s port %d, state is %d", __func__, port, state->interface);
  252. if (!phy_interface_mode_is_rgmii(state->interface) &&
  253. state->interface != PHY_INTERFACE_MODE_NA &&
  254. state->interface != PHY_INTERFACE_MODE_1000BASEX &&
  255. state->interface != PHY_INTERFACE_MODE_MII &&
  256. state->interface != PHY_INTERFACE_MODE_REVMII &&
  257. state->interface != PHY_INTERFACE_MODE_GMII &&
  258. state->interface != PHY_INTERFACE_MODE_QSGMII &&
  259. state->interface != PHY_INTERFACE_MODE_INTERNAL &&
  260. state->interface != PHY_INTERFACE_MODE_SGMII) {
  261. bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
  262. dev_err(ds->dev,
  263. "Unsupported interface: %d for port %d\n",
  264. state->interface, port);
  265. return;
  266. }
  267. /* Allow all the expected bits */
  268. phylink_set(mask, Autoneg);
  269. phylink_set_port_modes(mask);
  270. phylink_set(mask, Pause);
  271. phylink_set(mask, Asym_Pause);
  272. /* With the exclusion of MII and Reverse MII, we support Gigabit,
  273. * including Half duplex
  274. */
  275. if (state->interface != PHY_INTERFACE_MODE_MII &&
  276. state->interface != PHY_INTERFACE_MODE_REVMII) {
  277. phylink_set(mask, 1000baseT_Full);
  278. phylink_set(mask, 1000baseT_Half);
  279. }
  280. /* On both the 8380 and 8382, ports 24-27 are SFP ports */
  281. if (port >= 24 && port <= 27 && priv->family_id == RTL8380_FAMILY_ID)
  282. phylink_set(mask, 1000baseX_Full);
  283. /* On the RTL839x family of SoCs, ports 48 to 51 are SFP ports */
  284. if (port >= 48 && port <= 51 && priv->family_id == RTL8390_FAMILY_ID)
  285. phylink_set(mask, 1000baseX_Full);
  286. phylink_set(mask, 10baseT_Half);
  287. phylink_set(mask, 10baseT_Full);
  288. phylink_set(mask, 100baseT_Half);
  289. phylink_set(mask, 100baseT_Full);
  290. bitmap_and(supported, supported, mask,
  291. __ETHTOOL_LINK_MODE_MASK_NBITS);
  292. bitmap_and(state->advertising, state->advertising, mask,
  293. __ETHTOOL_LINK_MODE_MASK_NBITS);
  294. }
  295. static void rtl93xx_phylink_validate(struct dsa_switch *ds, int port,
  296. unsigned long *supported,
  297. struct phylink_link_state *state)
  298. {
  299. struct rtl838x_switch_priv *priv = ds->priv;
  300. __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
  301. pr_debug("In %s port %d, state is %d (%s)", __func__, port, state->interface,
  302. phy_modes(state->interface));
  303. if (!phy_interface_mode_is_rgmii(state->interface) &&
  304. state->interface != PHY_INTERFACE_MODE_NA &&
  305. state->interface != PHY_INTERFACE_MODE_1000BASEX &&
  306. state->interface != PHY_INTERFACE_MODE_MII &&
  307. state->interface != PHY_INTERFACE_MODE_REVMII &&
  308. state->interface != PHY_INTERFACE_MODE_GMII &&
  309. state->interface != PHY_INTERFACE_MODE_QSGMII &&
  310. state->interface != PHY_INTERFACE_MODE_XGMII &&
  311. state->interface != PHY_INTERFACE_MODE_HSGMII &&
  312. state->interface != PHY_INTERFACE_MODE_10GBASER &&
  313. state->interface != PHY_INTERFACE_MODE_10GKR &&
  314. state->interface != PHY_INTERFACE_MODE_USXGMII &&
  315. state->interface != PHY_INTERFACE_MODE_INTERNAL &&
  316. state->interface != PHY_INTERFACE_MODE_SGMII) {
  317. bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
  318. dev_err(ds->dev,
  319. "Unsupported interface: %d for port %d\n",
  320. state->interface, port);
  321. return;
  322. }
  323. /* Allow all the expected bits */
  324. phylink_set(mask, Autoneg);
  325. phylink_set_port_modes(mask);
  326. phylink_set(mask, Pause);
  327. phylink_set(mask, Asym_Pause);
  328. /* With the exclusion of MII and Reverse MII, we support Gigabit,
  329. * including Half duplex
  330. */
  331. if (state->interface != PHY_INTERFACE_MODE_MII &&
  332. state->interface != PHY_INTERFACE_MODE_REVMII) {
  333. phylink_set(mask, 1000baseT_Full);
  334. phylink_set(mask, 1000baseT_Half);
  335. }
  336. /* Internal phys of the RTL93xx family provide 10G */
  337. if (priv->ports[port].phy_is_integrated &&
  338. state->interface == PHY_INTERFACE_MODE_1000BASEX) {
  339. phylink_set(mask, 1000baseX_Full);
  340. } else if (priv->ports[port].phy_is_integrated) {
  341. phylink_set(mask, 1000baseX_Full);
  342. phylink_set(mask, 10000baseKR_Full);
  343. phylink_set(mask, 10000baseSR_Full);
  344. phylink_set(mask, 10000baseCR_Full);
  345. }
  346. if (state->interface == PHY_INTERFACE_MODE_INTERNAL) {
  347. phylink_set(mask, 1000baseX_Full);
  348. phylink_set(mask, 1000baseT_Full);
  349. phylink_set(mask, 10000baseKR_Full);
  350. phylink_set(mask, 10000baseT_Full);
  351. phylink_set(mask, 10000baseSR_Full);
  352. phylink_set(mask, 10000baseCR_Full);
  353. }
  354. if (state->interface == PHY_INTERFACE_MODE_USXGMII)
  355. phylink_set(mask, 10000baseT_Full);
  356. phylink_set(mask, 10baseT_Half);
  357. phylink_set(mask, 10baseT_Full);
  358. phylink_set(mask, 100baseT_Half);
  359. phylink_set(mask, 100baseT_Full);
  360. bitmap_and(supported, supported, mask,
  361. __ETHTOOL_LINK_MODE_MASK_NBITS);
  362. bitmap_and(state->advertising, state->advertising, mask,
  363. __ETHTOOL_LINK_MODE_MASK_NBITS);
  364. pr_debug("%s leaving supported: %*pb", __func__, __ETHTOOL_LINK_MODE_MASK_NBITS, supported);
  365. }
  366. static int rtl83xx_phylink_mac_link_state(struct dsa_switch *ds, int port,
  367. struct phylink_link_state *state)
  368. {
  369. struct rtl838x_switch_priv *priv = ds->priv;
  370. u64 speed;
  371. u64 link;
  372. if (port < 0 || port > priv->cpu_port)
  373. return -EINVAL;
  374. state->link = 0;
  375. link = priv->r->get_port_reg_le(priv->r->mac_link_sts);
  376. if (link & BIT_ULL(port))
  377. state->link = 1;
  378. pr_debug("%s: link state port %d: %llx\n", __func__, port, link & BIT_ULL(port));
  379. state->duplex = 0;
  380. if (priv->r->get_port_reg_le(priv->r->mac_link_dup_sts) & BIT_ULL(port))
  381. state->duplex = 1;
  382. speed = priv->r->get_port_reg_le(priv->r->mac_link_spd_sts(port));
  383. speed >>= (port % 16) << 1;
  384. switch (speed & 0x3) {
  385. case 0:
  386. state->speed = SPEED_10;
  387. break;
  388. case 1:
  389. state->speed = SPEED_100;
  390. break;
  391. case 2:
  392. state->speed = SPEED_1000;
  393. break;
  394. case 3:
  395. if (priv->family_id == RTL9300_FAMILY_ID
  396. && (port == 24 || port == 26)) /* Internal serdes */
  397. state->speed = SPEED_2500;
  398. else
  399. state->speed = SPEED_100; /* Is in fact 500Mbit */
  400. }
  401. state->pause &= (MLO_PAUSE_RX | MLO_PAUSE_TX);
  402. if (priv->r->get_port_reg_le(priv->r->mac_rx_pause_sts) & BIT_ULL(port))
  403. state->pause |= MLO_PAUSE_RX;
  404. if (priv->r->get_port_reg_le(priv->r->mac_tx_pause_sts) & BIT_ULL(port))
  405. state->pause |= MLO_PAUSE_TX;
  406. return 1;
  407. }
  408. static int rtl93xx_phylink_mac_link_state(struct dsa_switch *ds, int port,
  409. struct phylink_link_state *state)
  410. {
  411. struct rtl838x_switch_priv *priv = ds->priv;
  412. u64 speed;
  413. u64 link;
  414. u64 media;
  415. if (port < 0 || port > priv->cpu_port)
  416. return -EINVAL;
  417. /* On the RTL9300 for at least the RTL8226B PHY, the MAC-side link
  418. * state needs to be read twice in order to read a correct result.
  419. * This would not be necessary for ports connected e.g. to RTL8218D
  420. * PHYs.
  421. */
  422. state->link = 0;
  423. link = priv->r->get_port_reg_le(priv->r->mac_link_sts);
  424. link = priv->r->get_port_reg_le(priv->r->mac_link_sts);
  425. if (link & BIT_ULL(port))
  426. state->link = 1;
  427. if (priv->family_id == RTL9310_FAMILY_ID)
  428. media = priv->r->get_port_reg_le(RTL931X_MAC_LINK_MEDIA_STS);
  429. if (priv->family_id == RTL9300_FAMILY_ID)
  430. media = sw_r32(RTL930X_MAC_LINK_MEDIA_STS);
  431. if (media & BIT_ULL(port))
  432. state->link = 1;
  433. pr_debug("%s: link state port %d: %llx, media %llx\n", __func__, port,
  434. link & BIT_ULL(port), media);
  435. state->duplex = 0;
  436. if (priv->r->get_port_reg_le(priv->r->mac_link_dup_sts) & BIT_ULL(port))
  437. state->duplex = 1;
  438. speed = priv->r->get_port_reg_le(priv->r->mac_link_spd_sts(port));
  439. speed >>= (port % 8) << 2;
  440. switch (speed & 0xf) {
  441. case 0:
  442. state->speed = SPEED_10;
  443. break;
  444. case 1:
  445. state->speed = SPEED_100;
  446. break;
  447. case 2:
  448. case 7:
  449. state->speed = SPEED_1000;
  450. break;
  451. case 4:
  452. state->speed = SPEED_10000;
  453. break;
  454. case 5:
  455. case 8:
  456. state->speed = SPEED_2500;
  457. break;
  458. case 6:
  459. state->speed = SPEED_5000;
  460. break;
  461. default:
  462. pr_err("%s: unknown speed: %d\n", __func__, (u32)speed & 0xf);
  463. }
  464. if (priv->family_id == RTL9310_FAMILY_ID
  465. && (port >= 52 || port <= 55)) { /* Internal serdes */
  466. state->speed = SPEED_10000;
  467. state->link = 1;
  468. state->duplex = 1;
  469. }
  470. pr_debug("%s: speed is: %d %d\n", __func__, (u32)speed & 0xf, state->speed);
  471. state->pause &= (MLO_PAUSE_RX | MLO_PAUSE_TX);
  472. if (priv->r->get_port_reg_le(priv->r->mac_rx_pause_sts) & BIT_ULL(port))
  473. state->pause |= MLO_PAUSE_RX;
  474. if (priv->r->get_port_reg_le(priv->r->mac_tx_pause_sts) & BIT_ULL(port))
  475. state->pause |= MLO_PAUSE_TX;
  476. return 1;
  477. }
  478. static void rtl83xx_config_interface(int port, phy_interface_t interface)
  479. {
  480. u32 old, int_shift, sds_shift;
  481. switch (port) {
  482. case 24:
  483. int_shift = 0;
  484. sds_shift = 5;
  485. break;
  486. case 26:
  487. int_shift = 3;
  488. sds_shift = 0;
  489. break;
  490. default:
  491. return;
  492. }
  493. old = sw_r32(RTL838X_SDS_MODE_SEL);
  494. switch (interface) {
  495. case PHY_INTERFACE_MODE_1000BASEX:
  496. if ((old >> sds_shift & 0x1f) == 4)
  497. return;
  498. sw_w32_mask(0x7 << int_shift, 1 << int_shift, RTL838X_INT_MODE_CTRL);
  499. sw_w32_mask(0x1f << sds_shift, 4 << sds_shift, RTL838X_SDS_MODE_SEL);
  500. break;
  501. case PHY_INTERFACE_MODE_SGMII:
  502. if ((old >> sds_shift & 0x1f) == 2)
  503. return;
  504. sw_w32_mask(0x7 << int_shift, 2 << int_shift, RTL838X_INT_MODE_CTRL);
  505. sw_w32_mask(0x1f << sds_shift, 2 << sds_shift, RTL838X_SDS_MODE_SEL);
  506. break;
  507. default:
  508. return;
  509. }
  510. pr_debug("configured port %d for interface %s\n", port, phy_modes(interface));
  511. }
  512. static void rtl83xx_phylink_mac_config(struct dsa_switch *ds, int port,
  513. unsigned int mode,
  514. const struct phylink_link_state *state)
  515. {
  516. struct rtl838x_switch_priv *priv = ds->priv;
  517. u32 reg;
  518. int speed_bit = priv->family_id == RTL8380_FAMILY_ID ? 4 : 3;
  519. pr_debug("%s port %d, mode %x\n", __func__, port, mode);
  520. if (port == priv->cpu_port) {
  521. /* Set Speed, duplex, flow control
  522. * FORCE_EN | LINK_EN | NWAY_EN | DUP_SEL
  523. * | SPD_SEL = 0b10 | FORCE_FC_EN | PHY_MASTER_SLV_MANUAL_EN
  524. * | MEDIA_SEL
  525. */
  526. if (priv->family_id == RTL8380_FAMILY_ID) {
  527. sw_w32(0x6192F, priv->r->mac_force_mode_ctrl(priv->cpu_port));
  528. /* allow CRC errors on CPU-port */
  529. sw_w32_mask(0, 0x8, RTL838X_MAC_PORT_CTRL(priv->cpu_port));
  530. } else {
  531. sw_w32_mask(0, 3, priv->r->mac_force_mode_ctrl(priv->cpu_port));
  532. }
  533. return;
  534. }
  535. reg = sw_r32(priv->r->mac_force_mode_ctrl(port));
  536. /* Auto-Negotiation does not work for MAC in RTL8390 */
  537. if (priv->family_id == RTL8380_FAMILY_ID) {
  538. if (mode == MLO_AN_PHY || phylink_autoneg_inband(mode)) {
  539. pr_debug("PHY autonegotiates\n");
  540. reg |= RTL838X_NWAY_EN;
  541. sw_w32(reg, priv->r->mac_force_mode_ctrl(port));
  542. rtl83xx_config_interface(port, state->interface);
  543. return;
  544. }
  545. }
  546. if (mode != MLO_AN_FIXED)
  547. pr_debug("Fixed state.\n");
  548. /* Clear id_mode_dis bit, and the existing port mode, let
  549. * RGMII_MODE_EN bet set by mac_link_{up,down} */
  550. if (priv->family_id == RTL8380_FAMILY_ID) {
  551. reg &= ~(RTL838X_RX_PAUSE_EN | RTL838X_TX_PAUSE_EN);
  552. if (state->pause & MLO_PAUSE_TXRX_MASK) {
  553. if (state->pause & MLO_PAUSE_TX)
  554. reg |= RTL838X_TX_PAUSE_EN;
  555. reg |= RTL838X_RX_PAUSE_EN;
  556. }
  557. } else if (priv->family_id == RTL8390_FAMILY_ID) {
  558. reg &= ~(RTL839X_RX_PAUSE_EN | RTL839X_TX_PAUSE_EN);
  559. if (state->pause & MLO_PAUSE_TXRX_MASK) {
  560. if (state->pause & MLO_PAUSE_TX)
  561. reg |= RTL839X_TX_PAUSE_EN;
  562. reg |= RTL839X_RX_PAUSE_EN;
  563. }
  564. }
  565. reg &= ~(3 << speed_bit);
  566. switch (state->speed) {
  567. case SPEED_1000:
  568. reg |= 2 << speed_bit;
  569. break;
  570. case SPEED_100:
  571. reg |= 1 << speed_bit;
  572. break;
  573. default:
  574. break; /* Ignore, including 10MBit which has a speed value of 0 */
  575. }
  576. if (priv->family_id == RTL8380_FAMILY_ID) {
  577. reg &= ~(RTL838X_DUPLEX_MODE | RTL838X_FORCE_LINK_EN);
  578. if (state->link)
  579. reg |= RTL838X_FORCE_LINK_EN;
  580. if (state->duplex == RTL838X_DUPLEX_MODE)
  581. reg |= RTL838X_DUPLEX_MODE;
  582. } else if (priv->family_id == RTL8390_FAMILY_ID) {
  583. reg &= ~(RTL839X_DUPLEX_MODE | RTL839X_FORCE_LINK_EN);
  584. if (state->link)
  585. reg |= RTL839X_FORCE_LINK_EN;
  586. if (state->duplex == RTL839X_DUPLEX_MODE)
  587. reg |= RTL839X_DUPLEX_MODE;
  588. }
  589. /* LAG members must use DUPLEX and we need to enable the link */
  590. if (priv->lagmembers & BIT_ULL(port)) {
  591. switch(priv->family_id) {
  592. case RTL8380_FAMILY_ID:
  593. reg |= (RTL838X_DUPLEX_MODE | RTL838X_FORCE_LINK_EN);
  594. break;
  595. case RTL8390_FAMILY_ID:
  596. reg |= (RTL839X_DUPLEX_MODE | RTL839X_FORCE_LINK_EN);
  597. break;
  598. }
  599. }
  600. /* Disable AN */
  601. if (priv->family_id == RTL8380_FAMILY_ID)
  602. reg &= ~RTL838X_NWAY_EN;
  603. sw_w32(reg, priv->r->mac_force_mode_ctrl(port));
  604. }
  605. static void rtl931x_phylink_mac_config(struct dsa_switch *ds, int port,
  606. unsigned int mode,
  607. const struct phylink_link_state *state)
  608. {
  609. struct rtl838x_switch_priv *priv = ds->priv;
  610. int sds_num;
  611. u32 reg, band;
  612. sds_num = priv->ports[port].sds_num;
  613. pr_info("%s: speed %d sds_num %d\n", __func__, state->speed, sds_num);
  614. switch (state->interface) {
  615. case PHY_INTERFACE_MODE_HSGMII:
  616. pr_info("%s setting mode PHY_INTERFACE_MODE_HSGMII\n", __func__);
  617. band = rtl931x_sds_cmu_band_get(sds_num, PHY_INTERFACE_MODE_HSGMII);
  618. rtl931x_sds_init(sds_num, PHY_INTERFACE_MODE_HSGMII);
  619. band = rtl931x_sds_cmu_band_set(sds_num, true, 62, PHY_INTERFACE_MODE_HSGMII);
  620. break;
  621. case PHY_INTERFACE_MODE_1000BASEX:
  622. band = rtl931x_sds_cmu_band_get(sds_num, PHY_INTERFACE_MODE_1000BASEX);
  623. rtl931x_sds_init(sds_num, PHY_INTERFACE_MODE_1000BASEX);
  624. break;
  625. case PHY_INTERFACE_MODE_XGMII:
  626. band = rtl931x_sds_cmu_band_get(sds_num, PHY_INTERFACE_MODE_XGMII);
  627. rtl931x_sds_init(sds_num, PHY_INTERFACE_MODE_XGMII);
  628. break;
  629. case PHY_INTERFACE_MODE_10GBASER:
  630. case PHY_INTERFACE_MODE_10GKR:
  631. band = rtl931x_sds_cmu_band_get(sds_num, PHY_INTERFACE_MODE_10GBASER);
  632. rtl931x_sds_init(sds_num, PHY_INTERFACE_MODE_10GBASER);
  633. break;
  634. case PHY_INTERFACE_MODE_USXGMII:
  635. /* Translates to MII_USXGMII_10GSXGMII */
  636. band = rtl931x_sds_cmu_band_get(sds_num, PHY_INTERFACE_MODE_USXGMII);
  637. rtl931x_sds_init(sds_num, PHY_INTERFACE_MODE_USXGMII);
  638. break;
  639. case PHY_INTERFACE_MODE_SGMII:
  640. pr_info("%s setting mode PHY_INTERFACE_MODE_SGMII\n", __func__);
  641. band = rtl931x_sds_cmu_band_get(sds_num, PHY_INTERFACE_MODE_SGMII);
  642. rtl931x_sds_init(sds_num, PHY_INTERFACE_MODE_SGMII);
  643. band = rtl931x_sds_cmu_band_set(sds_num, true, 62, PHY_INTERFACE_MODE_SGMII);
  644. break;
  645. case PHY_INTERFACE_MODE_QSGMII:
  646. band = rtl931x_sds_cmu_band_get(sds_num, PHY_INTERFACE_MODE_QSGMII);
  647. rtl931x_sds_init(sds_num, PHY_INTERFACE_MODE_QSGMII);
  648. break;
  649. default:
  650. pr_err("%s: unknown serdes mode: %s\n",
  651. __func__, phy_modes(state->interface));
  652. return;
  653. }
  654. reg = sw_r32(priv->r->mac_force_mode_ctrl(port));
  655. pr_info("%s reading FORCE_MODE_CTRL: %08x\n", __func__, reg);
  656. reg &= ~(RTL931X_DUPLEX_MODE | RTL931X_FORCE_EN | RTL931X_FORCE_LINK_EN);
  657. reg &= ~(0xf << 12);
  658. reg |= 0x2 << 12; /* Set SMI speed to 0x2 */
  659. reg |= RTL931X_TX_PAUSE_EN | RTL931X_RX_PAUSE_EN;
  660. if (priv->lagmembers & BIT_ULL(port))
  661. reg |= RTL931X_DUPLEX_MODE;
  662. if (state->duplex == DUPLEX_FULL)
  663. reg |= RTL931X_DUPLEX_MODE;
  664. sw_w32(reg, priv->r->mac_force_mode_ctrl(port));
  665. }
  666. static void rtl93xx_phylink_mac_config(struct dsa_switch *ds, int port,
  667. unsigned int mode,
  668. const struct phylink_link_state *state)
  669. {
  670. struct rtl838x_switch_priv *priv = ds->priv;
  671. int sds_num, sds_mode;
  672. u32 reg;
  673. pr_info("%s port %d, mode %x, phy-mode: %s, speed %d, link %d\n", __func__,
  674. port, mode, phy_modes(state->interface), state->speed, state->link);
  675. /* Nothing to be done for the CPU-port */
  676. if (port == priv->cpu_port)
  677. return;
  678. if (priv->family_id == RTL9310_FAMILY_ID)
  679. return rtl931x_phylink_mac_config(ds, port, mode, state);
  680. sds_num = priv->ports[port].sds_num;
  681. pr_info("%s SDS is %d\n", __func__, sds_num);
  682. if (sds_num >= 0) {
  683. switch (state->interface) {
  684. case PHY_INTERFACE_MODE_HSGMII:
  685. sds_mode = 0x12;
  686. break;
  687. case PHY_INTERFACE_MODE_1000BASEX:
  688. sds_mode = 0x04;
  689. break;
  690. case PHY_INTERFACE_MODE_XGMII:
  691. sds_mode = 0x10;
  692. break;
  693. case PHY_INTERFACE_MODE_10GBASER:
  694. case PHY_INTERFACE_MODE_10GKR:
  695. sds_mode = 0x1b; /* 10G 1000X Auto */
  696. break;
  697. case PHY_INTERFACE_MODE_USXGMII:
  698. sds_mode = 0x0d;
  699. break;
  700. default:
  701. pr_err("%s: unknown serdes mode: %s\n",
  702. __func__, phy_modes(state->interface));
  703. return;
  704. }
  705. if (state->interface == PHY_INTERFACE_MODE_10GBASER)
  706. rtl9300_serdes_setup(sds_num, state->interface);
  707. }
  708. reg = sw_r32(priv->r->mac_force_mode_ctrl(port));
  709. reg &= ~(0xf << 3);
  710. switch (state->speed) {
  711. case SPEED_10000:
  712. reg |= 4 << 3;
  713. break;
  714. case SPEED_5000:
  715. reg |= 6 << 3;
  716. break;
  717. case SPEED_2500:
  718. reg |= 5 << 3;
  719. break;
  720. case SPEED_1000:
  721. reg |= 2 << 3;
  722. break;
  723. default:
  724. reg |= 2 << 3;
  725. break;
  726. }
  727. if (state->link)
  728. reg |= RTL930X_FORCE_LINK_EN;
  729. if (priv->lagmembers & BIT_ULL(port))
  730. reg |= RTL930X_DUPLEX_MODE | RTL930X_FORCE_LINK_EN;
  731. if (state->duplex == DUPLEX_FULL)
  732. reg |= RTL930X_DUPLEX_MODE;
  733. if (priv->ports[port].phy_is_integrated)
  734. reg &= ~RTL930X_FORCE_EN; /* Clear MAC_FORCE_EN to allow SDS-MAC link */
  735. else
  736. reg |= RTL930X_FORCE_EN;
  737. sw_w32(reg, priv->r->mac_force_mode_ctrl(port));
  738. }
  739. static void rtl83xx_phylink_mac_link_down(struct dsa_switch *ds, int port,
  740. unsigned int mode,
  741. phy_interface_t interface)
  742. {
  743. struct rtl838x_switch_priv *priv = ds->priv;
  744. /* Stop TX/RX to port */
  745. sw_w32_mask(0x3, 0, priv->r->mac_port_ctrl(port));
  746. /* No longer force link */
  747. sw_w32_mask(0x3, 0, priv->r->mac_force_mode_ctrl(port));
  748. }
  749. static void rtl93xx_phylink_mac_link_down(struct dsa_switch *ds, int port,
  750. unsigned int mode,
  751. phy_interface_t interface)
  752. {
  753. struct rtl838x_switch_priv *priv = ds->priv;
  754. u32 v = 0;
  755. /* Stop TX/RX to port */
  756. sw_w32_mask(0x3, 0, priv->r->mac_port_ctrl(port));
  757. /* No longer force link */
  758. if (priv->family_id == RTL9300_FAMILY_ID)
  759. v = RTL930X_FORCE_EN | RTL930X_FORCE_LINK_EN;
  760. else if (priv->family_id == RTL9310_FAMILY_ID)
  761. v = RTL931X_FORCE_EN | RTL931X_FORCE_LINK_EN;
  762. sw_w32_mask(v, 0, priv->r->mac_force_mode_ctrl(port));
  763. }
  764. static void rtl83xx_phylink_mac_link_up(struct dsa_switch *ds, int port,
  765. unsigned int mode,
  766. phy_interface_t interface,
  767. struct phy_device *phydev,
  768. int speed, int duplex,
  769. bool tx_pause, bool rx_pause)
  770. {
  771. struct rtl838x_switch_priv *priv = ds->priv;
  772. /* Restart TX/RX to port */
  773. sw_w32_mask(0, 0x3, priv->r->mac_port_ctrl(port));
  774. /* TODO: Set speed/duplex/pauses */
  775. }
  776. static void rtl93xx_phylink_mac_link_up(struct dsa_switch *ds, int port,
  777. unsigned int mode,
  778. phy_interface_t interface,
  779. struct phy_device *phydev,
  780. int speed, int duplex,
  781. bool tx_pause, bool rx_pause)
  782. {
  783. struct rtl838x_switch_priv *priv = ds->priv;
  784. /* Restart TX/RX to port */
  785. sw_w32_mask(0, 0x3, priv->r->mac_port_ctrl(port));
  786. /* TODO: Set speed/duplex/pauses */
  787. }
  788. static void rtl83xx_get_strings(struct dsa_switch *ds,
  789. int port, u32 stringset, u8 *data)
  790. {
  791. if (stringset != ETH_SS_STATS)
  792. return;
  793. for (int i = 0; i < ARRAY_SIZE(rtl83xx_mib); i++)
  794. strncpy(data + i * ETH_GSTRING_LEN, rtl83xx_mib[i].name,
  795. ETH_GSTRING_LEN);
  796. }
  797. static void rtl83xx_get_ethtool_stats(struct dsa_switch *ds, int port,
  798. uint64_t *data)
  799. {
  800. struct rtl838x_switch_priv *priv = ds->priv;
  801. const struct rtl83xx_mib_desc *mib;
  802. u64 h;
  803. for (int i = 0; i < ARRAY_SIZE(rtl83xx_mib); i++) {
  804. mib = &rtl83xx_mib[i];
  805. data[i] = sw_r32(priv->r->stat_port_std_mib + (port << 8) + 252 - mib->offset);
  806. if (mib->size == 2) {
  807. h = sw_r32(priv->r->stat_port_std_mib + (port << 8) + 248 - mib->offset);
  808. data[i] |= h << 32;
  809. }
  810. }
  811. }
  812. static int rtl83xx_get_sset_count(struct dsa_switch *ds, int port, int sset)
  813. {
  814. if (sset != ETH_SS_STATS)
  815. return 0;
  816. return ARRAY_SIZE(rtl83xx_mib);
  817. }
  818. static int rtl83xx_mc_group_alloc(struct rtl838x_switch_priv *priv, int port)
  819. {
  820. int mc_group = find_first_zero_bit(priv->mc_group_bm, MAX_MC_GROUPS - 1);
  821. u64 portmask;
  822. if (mc_group >= MAX_MC_GROUPS - 1)
  823. return -1;
  824. if (priv->is_lagmember[port]) {
  825. pr_info("%s: %d is lag slave. ignore\n", __func__, port);
  826. return 0;
  827. }
  828. set_bit(mc_group, priv->mc_group_bm);
  829. portmask = BIT_ULL(port);
  830. priv->r->write_mcast_pmask(mc_group, portmask);
  831. return mc_group;
  832. }
  833. static u64 rtl83xx_mc_group_add_port(struct rtl838x_switch_priv *priv, int mc_group, int port)
  834. {
  835. u64 portmask = priv->r->read_mcast_pmask(mc_group);
  836. pr_debug("%s: %d\n", __func__, port);
  837. if (priv->is_lagmember[port]) {
  838. pr_info("%s: %d is lag slave. ignore\n", __func__, port);
  839. return portmask;
  840. }
  841. portmask |= BIT_ULL(port);
  842. priv->r->write_mcast_pmask(mc_group, portmask);
  843. return portmask;
  844. }
  845. static u64 rtl83xx_mc_group_del_port(struct rtl838x_switch_priv *priv, int mc_group, int port)
  846. {
  847. u64 portmask = priv->r->read_mcast_pmask(mc_group);
  848. pr_debug("%s: %d\n", __func__, port);
  849. if (priv->is_lagmember[port]) {
  850. pr_info("%s: %d is lag slave. ignore\n", __func__, port);
  851. return portmask;
  852. }
  853. portmask &= ~BIT_ULL(port);
  854. priv->r->write_mcast_pmask(mc_group, portmask);
  855. if (!portmask)
  856. clear_bit(mc_group, priv->mc_group_bm);
  857. return portmask;
  858. }
  859. static void store_mcgroups(struct rtl838x_switch_priv *priv, int port)
  860. {
  861. for (int mc_group = 0; mc_group < MAX_MC_GROUPS; mc_group++) {
  862. u64 portmask = priv->r->read_mcast_pmask(mc_group);
  863. if (portmask & BIT_ULL(port)) {
  864. priv->mc_group_saves[mc_group] = port;
  865. rtl83xx_mc_group_del_port(priv, mc_group, port);
  866. }
  867. }
  868. }
  869. static void load_mcgroups(struct rtl838x_switch_priv *priv, int port)
  870. {
  871. for (int mc_group = 0; mc_group < MAX_MC_GROUPS; mc_group++) {
  872. if (priv->mc_group_saves[mc_group] == port) {
  873. rtl83xx_mc_group_add_port(priv, mc_group, port);
  874. priv->mc_group_saves[mc_group] = -1;
  875. }
  876. }
  877. }
  878. static int rtl83xx_port_enable(struct dsa_switch *ds, int port,
  879. struct phy_device *phydev)
  880. {
  881. struct rtl838x_switch_priv *priv = ds->priv;
  882. u64 v;
  883. pr_debug("%s: %x %d", __func__, (u32) priv, port);
  884. priv->ports[port].enable = true;
  885. /* enable inner tagging on egress, do not keep any tags */
  886. priv->r->vlan_port_keep_tag_set(port, 0, 1);
  887. if (dsa_is_cpu_port(ds, port))
  888. return 0;
  889. /* add port to switch mask of CPU_PORT */
  890. priv->r->traffic_enable(priv->cpu_port, port);
  891. load_mcgroups(priv, port);
  892. if (priv->is_lagmember[port]) {
  893. pr_debug("%s: %d is lag slave. ignore\n", __func__, port);
  894. return 0;
  895. }
  896. /* add all other ports in the same bridge to switch mask of port */
  897. v = priv->r->traffic_get(port);
  898. v |= priv->ports[port].pm;
  899. priv->r->traffic_set(port, v);
  900. /* TODO: Figure out if this is necessary */
  901. if (priv->family_id == RTL9300_FAMILY_ID) {
  902. sw_w32_mask(0, BIT(port), RTL930X_L2_PORT_SABLK_CTRL);
  903. sw_w32_mask(0, BIT(port), RTL930X_L2_PORT_DABLK_CTRL);
  904. }
  905. if (priv->ports[port].sds_num < 0)
  906. priv->ports[port].sds_num = rtl93xx_get_sds(phydev);
  907. return 0;
  908. }
  909. static void rtl83xx_port_disable(struct dsa_switch *ds, int port)
  910. {
  911. struct rtl838x_switch_priv *priv = ds->priv;
  912. u64 v;
  913. pr_debug("%s %x: %d", __func__, (u32)priv, port);
  914. /* you can only disable user ports */
  915. if (!dsa_is_user_port(ds, port))
  916. return;
  917. /* BUG: This does not work on RTL931X */
  918. /* remove port from switch mask of CPU_PORT */
  919. priv->r->traffic_disable(priv->cpu_port, port);
  920. store_mcgroups(priv, port);
  921. /* remove all other ports in the same bridge from switch mask of port */
  922. v = priv->r->traffic_get(port);
  923. v &= ~priv->ports[port].pm;
  924. priv->r->traffic_set(port, v);
  925. priv->ports[port].enable = false;
  926. }
  927. static int rtl83xx_set_mac_eee(struct dsa_switch *ds, int port,
  928. struct ethtool_eee *e)
  929. {
  930. struct rtl838x_switch_priv *priv = ds->priv;
  931. if (e->eee_enabled && !priv->eee_enabled) {
  932. pr_info("Globally enabling EEE\n");
  933. priv->r->init_eee(priv, true);
  934. }
  935. priv->r->port_eee_set(priv, port, e->eee_enabled);
  936. if (e->eee_enabled)
  937. pr_info("Enabled EEE for port %d\n", port);
  938. else
  939. pr_info("Disabled EEE for port %d\n", port);
  940. return 0;
  941. }
  942. static int rtl83xx_get_mac_eee(struct dsa_switch *ds, int port,
  943. struct ethtool_eee *e)
  944. {
  945. struct rtl838x_switch_priv *priv = ds->priv;
  946. e->supported = SUPPORTED_100baseT_Full | SUPPORTED_1000baseT_Full;
  947. priv->r->eee_port_ability(priv, e, port);
  948. e->eee_enabled = priv->ports[port].eee_enabled;
  949. e->eee_active = !!(e->advertised & e->lp_advertised);
  950. return 0;
  951. }
  952. static int rtl93xx_get_mac_eee(struct dsa_switch *ds, int port,
  953. struct ethtool_eee *e)
  954. {
  955. struct rtl838x_switch_priv *priv = ds->priv;
  956. e->supported = SUPPORTED_100baseT_Full |
  957. SUPPORTED_1000baseT_Full |
  958. SUPPORTED_2500baseX_Full;
  959. priv->r->eee_port_ability(priv, e, port);
  960. e->eee_enabled = priv->ports[port].eee_enabled;
  961. e->eee_active = !!(e->advertised & e->lp_advertised);
  962. return 0;
  963. }
  964. static int rtl83xx_set_ageing_time(struct dsa_switch *ds, unsigned int msec)
  965. {
  966. struct rtl838x_switch_priv *priv = ds->priv;
  967. priv->r->set_ageing_time(msec);
  968. return 0;
  969. }
  970. static int rtl83xx_port_bridge_join(struct dsa_switch *ds, int port,
  971. struct net_device *bridge)
  972. {
  973. struct rtl838x_switch_priv *priv = ds->priv;
  974. u64 port_bitmap = BIT_ULL(priv->cpu_port), v;
  975. pr_debug("%s %x: %d %llx", __func__, (u32)priv, port, port_bitmap);
  976. if (priv->is_lagmember[port]) {
  977. pr_debug("%s: %d is lag slave. ignore\n", __func__, port);
  978. return 0;
  979. }
  980. mutex_lock(&priv->reg_mutex);
  981. for (int i = 0; i < ds->num_ports; i++) {
  982. /* Add this port to the port matrix of the other ports in the
  983. * same bridge. If the port is disabled, port matrix is kept
  984. * and not being setup until the port becomes enabled.
  985. */
  986. if (dsa_is_user_port(ds, i) && !priv->is_lagmember[i] && i != port) {
  987. if (dsa_to_port(ds, i)->bridge_dev != bridge)
  988. continue;
  989. if (priv->ports[i].enable)
  990. priv->r->traffic_enable(i, port);
  991. priv->ports[i].pm |= BIT_ULL(port);
  992. port_bitmap |= BIT_ULL(i);
  993. }
  994. }
  995. load_mcgroups(priv, port);
  996. /* Add all other ports to this port matrix. */
  997. if (priv->ports[port].enable) {
  998. priv->r->traffic_enable(priv->cpu_port, port);
  999. v = priv->r->traffic_get(port);
  1000. v |= port_bitmap;
  1001. priv->r->traffic_set(port, v);
  1002. }
  1003. priv->ports[port].pm |= port_bitmap;
  1004. if (priv->r->set_static_move_action)
  1005. priv->r->set_static_move_action(port, false);
  1006. mutex_unlock(&priv->reg_mutex);
  1007. return 0;
  1008. }
  1009. static void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port,
  1010. struct net_device *bridge)
  1011. {
  1012. struct rtl838x_switch_priv *priv = ds->priv;
  1013. u64 port_bitmap = 0, v;
  1014. pr_debug("%s %x: %d", __func__, (u32)priv, port);
  1015. mutex_lock(&priv->reg_mutex);
  1016. for (int i = 0; i < ds->num_ports; i++) {
  1017. /* Remove this port from the port matrix of the other ports
  1018. * in the same bridge. If the port is disabled, port matrix
  1019. * is kept and not being setup until the port becomes enabled.
  1020. * And the other port's port matrix cannot be broken when the
  1021. * other port is still a VLAN-aware port.
  1022. */
  1023. if (dsa_is_user_port(ds, i) && i != port) {
  1024. if (dsa_to_port(ds, i)->bridge_dev != bridge)
  1025. continue;
  1026. if (priv->ports[i].enable)
  1027. priv->r->traffic_disable(i, port);
  1028. priv->ports[i].pm &= ~BIT_ULL(port);
  1029. port_bitmap |= BIT_ULL(i);
  1030. }
  1031. }
  1032. store_mcgroups(priv, port);
  1033. /* Remove all other ports from this port matrix. */
  1034. if (priv->ports[port].enable) {
  1035. v = priv->r->traffic_get(port);
  1036. v &= ~port_bitmap;
  1037. priv->r->traffic_set(port, v);
  1038. }
  1039. priv->ports[port].pm &= ~port_bitmap;
  1040. if (priv->r->set_static_move_action)
  1041. priv->r->set_static_move_action(port, true);
  1042. mutex_unlock(&priv->reg_mutex);
  1043. }
  1044. void rtl83xx_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
  1045. {
  1046. u32 msti = 0;
  1047. u32 port_state[4];
  1048. int index, bit;
  1049. int pos = port;
  1050. struct rtl838x_switch_priv *priv = ds->priv;
  1051. int n = priv->port_width << 1;
  1052. /* Ports above or equal CPU port can never be configured */
  1053. if (port >= priv->cpu_port)
  1054. return;
  1055. mutex_lock(&priv->reg_mutex);
  1056. /* For the RTL839x and following, the bits are left-aligned, 838x and 930x
  1057. * have 64 bit fields, 839x and 931x have 128 bit fields
  1058. */
  1059. if (priv->family_id == RTL8390_FAMILY_ID)
  1060. pos += 12;
  1061. if (priv->family_id == RTL9300_FAMILY_ID)
  1062. pos += 3;
  1063. if (priv->family_id == RTL9310_FAMILY_ID)
  1064. pos += 8;
  1065. index = n - (pos >> 4) - 1;
  1066. bit = (pos << 1) % 32;
  1067. priv->r->stp_get(priv, msti, port_state);
  1068. pr_debug("Current state, port %d: %d\n", port, (port_state[index] >> bit) & 3);
  1069. port_state[index] &= ~(3 << bit);
  1070. switch (state) {
  1071. case BR_STATE_DISABLED: /* 0 */
  1072. port_state[index] |= (0 << bit);
  1073. break;
  1074. case BR_STATE_BLOCKING: /* 4 */
  1075. case BR_STATE_LISTENING: /* 1 */
  1076. port_state[index] |= (1 << bit);
  1077. break;
  1078. case BR_STATE_LEARNING: /* 2 */
  1079. port_state[index] |= (2 << bit);
  1080. break;
  1081. case BR_STATE_FORWARDING: /* 3 */
  1082. port_state[index] |= (3 << bit);
  1083. default:
  1084. break;
  1085. }
  1086. priv->r->stp_set(priv, msti, port_state);
  1087. mutex_unlock(&priv->reg_mutex);
  1088. }
  1089. void rtl83xx_fast_age(struct dsa_switch *ds, int port)
  1090. {
  1091. struct rtl838x_switch_priv *priv = ds->priv;
  1092. int s = priv->family_id == RTL8390_FAMILY_ID ? 2 : 0;
  1093. pr_debug("FAST AGE port %d\n", port);
  1094. mutex_lock(&priv->reg_mutex);
  1095. /* RTL838X_L2_TBL_FLUSH_CTRL register bits, 839x has 1 bit larger
  1096. * port fields:
  1097. * 0-4: Replacing port
  1098. * 5-9: Flushed/replaced port
  1099. * 10-21: FVID
  1100. * 22: Entry types: 1: dynamic, 0: also static
  1101. * 23: Match flush port
  1102. * 24: Match FVID
  1103. * 25: Flush (0) or replace (1) L2 entries
  1104. * 26: Status of action (1: Start, 0: Done)
  1105. */
  1106. sw_w32(1 << (26 + s) | 1 << (23 + s) | port << (5 + (s / 2)), priv->r->l2_tbl_flush_ctrl);
  1107. do { } while (sw_r32(priv->r->l2_tbl_flush_ctrl) & BIT(26 + s));
  1108. mutex_unlock(&priv->reg_mutex);
  1109. }
  1110. void rtl931x_fast_age(struct dsa_switch *ds, int port)
  1111. {
  1112. struct rtl838x_switch_priv *priv = ds->priv;
  1113. pr_info("%s port %d\n", __func__, port);
  1114. mutex_lock(&priv->reg_mutex);
  1115. sw_w32(port << 11, RTL931X_L2_TBL_FLUSH_CTRL + 4);
  1116. sw_w32(BIT(24) | BIT(28), RTL931X_L2_TBL_FLUSH_CTRL);
  1117. do { } while (sw_r32(RTL931X_L2_TBL_FLUSH_CTRL) & BIT (28));
  1118. mutex_unlock(&priv->reg_mutex);
  1119. }
  1120. void rtl930x_fast_age(struct dsa_switch *ds, int port)
  1121. {
  1122. struct rtl838x_switch_priv *priv = ds->priv;
  1123. if (priv->family_id == RTL9310_FAMILY_ID)
  1124. return rtl931x_fast_age(ds, port);
  1125. pr_debug("FAST AGE port %d\n", port);
  1126. mutex_lock(&priv->reg_mutex);
  1127. sw_w32(port << 11, RTL930X_L2_TBL_FLUSH_CTRL + 4);
  1128. sw_w32(BIT(26) | BIT(30), RTL930X_L2_TBL_FLUSH_CTRL);
  1129. do { } while (sw_r32(priv->r->l2_tbl_flush_ctrl) & BIT(30));
  1130. mutex_unlock(&priv->reg_mutex);
  1131. }
  1132. static int rtl83xx_vlan_filtering(struct dsa_switch *ds, int port,
  1133. bool vlan_filtering,
  1134. struct netlink_ext_ack *extack)
  1135. {
  1136. struct rtl838x_switch_priv *priv = ds->priv;
  1137. pr_debug("%s: port %d\n", __func__, port);
  1138. mutex_lock(&priv->reg_mutex);
  1139. if (vlan_filtering) {
  1140. /* Enable ingress and egress filtering
  1141. * The VLAN_PORT_IGR_FILTER register uses 2 bits for each port to define
  1142. * the filter action:
  1143. * 0: Always Forward
  1144. * 1: Drop packet
  1145. * 2: Trap packet to CPU port
  1146. * The Egress filter used 1 bit per state (0: DISABLED, 1: ENABLED)
  1147. */
  1148. if (port != priv->cpu_port)
  1149. priv->r->set_vlan_igr_filter(port, IGR_DROP);
  1150. priv->r->set_vlan_egr_filter(port, EGR_ENABLE);
  1151. } else {
  1152. /* Disable ingress and egress filtering */
  1153. if (port != priv->cpu_port)
  1154. priv->r->set_vlan_igr_filter(port, IGR_FORWARD);
  1155. priv->r->set_vlan_egr_filter(port, EGR_DISABLE);
  1156. }
  1157. /* Do we need to do something to the CPU-Port, too? */
  1158. mutex_unlock(&priv->reg_mutex);
  1159. return 0;
  1160. }
  1161. static int rtl83xx_vlan_prepare(struct dsa_switch *ds, int port,
  1162. const struct switchdev_obj_port_vlan *vlan)
  1163. {
  1164. struct rtl838x_vlan_info info;
  1165. struct rtl838x_switch_priv *priv = ds->priv;
  1166. priv->r->vlan_tables_read(0, &info);
  1167. pr_debug("VLAN 0: Tagged ports %llx, untag %llx, profile %d, MC# %d, UC# %d, FID %x\n",
  1168. info.tagged_ports, info.untagged_ports, info.profile_id,
  1169. info.hash_mc_fid, info.hash_uc_fid, info.fid);
  1170. priv->r->vlan_tables_read(1, &info);
  1171. pr_debug("VLAN 1: Tagged ports %llx, untag %llx, profile %d, MC# %d, UC# %d, FID %x\n",
  1172. info.tagged_ports, info.untagged_ports, info.profile_id,
  1173. info.hash_mc_fid, info.hash_uc_fid, info.fid);
  1174. priv->r->vlan_set_untagged(1, info.untagged_ports);
  1175. pr_debug("SET: Untagged ports, VLAN %d: %llx\n", 1, info.untagged_ports);
  1176. priv->r->vlan_set_tagged(1, &info);
  1177. pr_debug("SET: Tagged ports, VLAN %d: %llx\n", 1, info.tagged_ports);
  1178. return 0;
  1179. }
  1180. static void rtl83xx_vlan_set_pvid(struct rtl838x_switch_priv *priv,
  1181. int port, int pvid)
  1182. {
  1183. /* Set both inner and outer PVID of the port */
  1184. priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_INNER, pvid);
  1185. priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_OUTER, pvid);
  1186. priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_INNER,
  1187. PBVLAN_MODE_UNTAG_AND_PRITAG);
  1188. priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_OUTER,
  1189. PBVLAN_MODE_UNTAG_AND_PRITAG);
  1190. priv->ports[port].pvid = pvid;
  1191. }
  1192. static int rtl83xx_vlan_add(struct dsa_switch *ds, int port,
  1193. const struct switchdev_obj_port_vlan *vlan,
  1194. struct netlink_ext_ack *extack)
  1195. {
  1196. struct rtl838x_vlan_info info;
  1197. struct rtl838x_switch_priv *priv = ds->priv;
  1198. int err;
  1199. pr_debug("%s port %d, vid %d, flags %x\n",
  1200. __func__, port, vlan->vid, vlan->flags);
  1201. if (vlan->vid > 4095) {
  1202. dev_err(priv->dev, "VLAN out of range: %d", vlan->vid);
  1203. return -ENOTSUPP;
  1204. }
  1205. err = rtl83xx_vlan_prepare(ds, port, vlan);
  1206. if (err)
  1207. return err;
  1208. mutex_lock(&priv->reg_mutex);
  1209. if (vlan->flags & BRIDGE_VLAN_INFO_PVID)
  1210. rtl83xx_vlan_set_pvid(priv, port, vlan->vid);
  1211. else if (priv->ports[port].pvid == vlan->vid)
  1212. rtl83xx_vlan_set_pvid(priv, port, 0);
  1213. /* Get port memberships of this vlan */
  1214. priv->r->vlan_tables_read(vlan->vid, &info);
  1215. /* new VLAN? */
  1216. if (!info.tagged_ports) {
  1217. info.fid = 0;
  1218. info.hash_mc_fid = false;
  1219. info.hash_uc_fid = false;
  1220. info.profile_id = 0;
  1221. }
  1222. /* sanitize untagged_ports - must be a subset */
  1223. if (info.untagged_ports & ~info.tagged_ports)
  1224. info.untagged_ports = 0;
  1225. info.tagged_ports |= BIT_ULL(port);
  1226. if (vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED)
  1227. info.untagged_ports |= BIT_ULL(port);
  1228. else
  1229. info.untagged_ports &= ~BIT_ULL(port);
  1230. priv->r->vlan_set_untagged(vlan->vid, info.untagged_ports);
  1231. pr_debug("Untagged ports, VLAN %d: %llx\n", vlan->vid, info.untagged_ports);
  1232. priv->r->vlan_set_tagged(vlan->vid, &info);
  1233. pr_debug("Tagged ports, VLAN %d: %llx\n", vlan->vid, info.tagged_ports);
  1234. mutex_unlock(&priv->reg_mutex);
  1235. return 0;
  1236. }
  1237. static int rtl83xx_vlan_del(struct dsa_switch *ds, int port,
  1238. const struct switchdev_obj_port_vlan *vlan)
  1239. {
  1240. struct rtl838x_vlan_info info;
  1241. struct rtl838x_switch_priv *priv = ds->priv;
  1242. u16 pvid;
  1243. pr_debug("%s: port %d, vid %d, flags %x\n",
  1244. __func__, port, vlan->vid, vlan->flags);
  1245. if (vlan->vid > 4095) {
  1246. dev_err(priv->dev, "VLAN out of range: %d", vlan->vid);
  1247. return -ENOTSUPP;
  1248. }
  1249. mutex_lock(&priv->reg_mutex);
  1250. pvid = priv->ports[port].pvid;
  1251. /* Reset to default if removing the current PVID */
  1252. if (vlan->vid == pvid) {
  1253. rtl83xx_vlan_set_pvid(priv, port, 0);
  1254. }
  1255. /* Get port memberships of this vlan */
  1256. priv->r->vlan_tables_read(vlan->vid, &info);
  1257. /* remove port from both tables */
  1258. info.untagged_ports &= (~BIT_ULL(port));
  1259. info.tagged_ports &= (~BIT_ULL(port));
  1260. priv->r->vlan_set_untagged(vlan->vid, info.untagged_ports);
  1261. pr_debug("Untagged ports, VLAN %d: %llx\n", vlan->vid, info.untagged_ports);
  1262. priv->r->vlan_set_tagged(vlan->vid, &info);
  1263. pr_debug("Tagged ports, VLAN %d: %llx\n", vlan->vid, info.tagged_ports);
  1264. mutex_unlock(&priv->reg_mutex);
  1265. return 0;
  1266. }
  1267. static void rtl83xx_setup_l2_uc_entry(struct rtl838x_l2_entry *e, int port, int vid, u64 mac)
  1268. {
  1269. memset(e, 0, sizeof(*e));
  1270. e->type = L2_UNICAST;
  1271. e->valid = true;
  1272. e->age = 3;
  1273. e->is_static = true;
  1274. e->port = port;
  1275. e->rvid = e->vid = vid;
  1276. e->is_ip_mc = e->is_ipv6_mc = false;
  1277. u64_to_ether_addr(mac, e->mac);
  1278. }
  1279. static void rtl83xx_setup_l2_mc_entry(struct rtl838x_l2_entry *e, int vid, u64 mac, int mc_group)
  1280. {
  1281. memset(e, 0, sizeof(*e));
  1282. e->type = L2_MULTICAST;
  1283. e->valid = true;
  1284. e->mc_portmask_index = mc_group;
  1285. e->rvid = e->vid = vid;
  1286. e->is_ip_mc = e->is_ipv6_mc = false;
  1287. u64_to_ether_addr(mac, e->mac);
  1288. }
  1289. /* Uses the seed to identify a hash bucket in the L2 using the derived hash key and then loops
  1290. * over the entries in the bucket until either a matching entry is found or an empty slot
  1291. * Returns the filled in rtl838x_l2_entry and the index in the bucket when an entry was found
  1292. * when an empty slot was found and must exist is false, the index of the slot is returned
  1293. * when no slots are available returns -1
  1294. */
  1295. static int rtl83xx_find_l2_hash_entry(struct rtl838x_switch_priv *priv, u64 seed,
  1296. bool must_exist, struct rtl838x_l2_entry *e)
  1297. {
  1298. int idx = -1;
  1299. u32 key = priv->r->l2_hash_key(priv, seed);
  1300. u64 entry;
  1301. pr_debug("%s: using key %x, for seed %016llx\n", __func__, key, seed);
  1302. /* Loop over all entries in the hash-bucket and over the second block on 93xx SoCs */
  1303. for (int i = 0; i < priv->l2_bucket_size; i++) {
  1304. entry = priv->r->read_l2_entry_using_hash(key, i, e);
  1305. pr_debug("valid %d, mac %016llx\n", e->valid, ether_addr_to_u64(&e->mac[0]));
  1306. if (must_exist && !e->valid)
  1307. continue;
  1308. if (!e->valid || ((entry & 0x0fffffffffffffffULL) == seed)) {
  1309. idx = i > 3 ? ((key >> 14) & 0xffff) | i >> 1 : ((key << 2) | i) & 0xffff;
  1310. break;
  1311. }
  1312. }
  1313. return idx;
  1314. }
  1315. /* Uses the seed to identify an entry in the CAM by looping over all its entries
  1316. * Returns the filled in rtl838x_l2_entry and the index in the CAM when an entry was found
  1317. * when an empty slot was found the index of the slot is returned
  1318. * when no slots are available returns -1
  1319. */
  1320. static int rtl83xx_find_l2_cam_entry(struct rtl838x_switch_priv *priv, u64 seed,
  1321. bool must_exist, struct rtl838x_l2_entry *e)
  1322. {
  1323. int idx = -1;
  1324. u64 entry;
  1325. for (int i = 0; i < 64; i++) {
  1326. entry = priv->r->read_cam(i, e);
  1327. if (!must_exist && !e->valid) {
  1328. if (idx < 0) /* First empty entry? */
  1329. idx = i;
  1330. break;
  1331. } else if ((entry & 0x0fffffffffffffffULL) == seed) {
  1332. pr_debug("Found entry in CAM\n");
  1333. idx = i;
  1334. break;
  1335. }
  1336. }
  1337. return idx;
  1338. }
  1339. static int rtl83xx_port_fdb_add(struct dsa_switch *ds, int port,
  1340. const unsigned char *addr, u16 vid)
  1341. {
  1342. struct rtl838x_switch_priv *priv = ds->priv;
  1343. u64 mac = ether_addr_to_u64(addr);
  1344. struct rtl838x_l2_entry e;
  1345. int err = 0, idx;
  1346. u64 seed = priv->r->l2_hash_seed(mac, vid);
  1347. if (priv->is_lagmember[port]) {
  1348. pr_debug("%s: %d is lag slave. ignore\n", __func__, port);
  1349. return 0;
  1350. }
  1351. mutex_lock(&priv->reg_mutex);
  1352. idx = rtl83xx_find_l2_hash_entry(priv, seed, false, &e);
  1353. /* Found an existing or empty entry */
  1354. if (idx >= 0) {
  1355. rtl83xx_setup_l2_uc_entry(&e, port, vid, mac);
  1356. priv->r->write_l2_entry_using_hash(idx >> 2, idx & 0x3, &e);
  1357. goto out;
  1358. }
  1359. /* Hash buckets full, try CAM */
  1360. idx = rtl83xx_find_l2_cam_entry(priv, seed, false, &e);
  1361. if (idx >= 0) {
  1362. rtl83xx_setup_l2_uc_entry(&e, port, vid, mac);
  1363. priv->r->write_cam(idx, &e);
  1364. goto out;
  1365. }
  1366. err = -ENOTSUPP;
  1367. out:
  1368. mutex_unlock(&priv->reg_mutex);
  1369. return err;
  1370. }
  1371. static int rtl83xx_port_fdb_del(struct dsa_switch *ds, int port,
  1372. const unsigned char *addr, u16 vid)
  1373. {
  1374. struct rtl838x_switch_priv *priv = ds->priv;
  1375. u64 mac = ether_addr_to_u64(addr);
  1376. struct rtl838x_l2_entry e;
  1377. int err = 0, idx;
  1378. u64 seed = priv->r->l2_hash_seed(mac, vid);
  1379. pr_debug("In %s, mac %llx, vid: %d\n", __func__, mac, vid);
  1380. mutex_lock(&priv->reg_mutex);
  1381. idx = rtl83xx_find_l2_hash_entry(priv, seed, true, &e);
  1382. if (idx >= 0) {
  1383. pr_debug("Found entry index %d, key %d and bucket %d\n", idx, idx >> 2, idx & 3);
  1384. e.valid = false;
  1385. priv->r->write_l2_entry_using_hash(idx >> 2, idx & 0x3, &e);
  1386. goto out;
  1387. }
  1388. /* Check CAM for spillover from hash buckets */
  1389. idx = rtl83xx_find_l2_cam_entry(priv, seed, true, &e);
  1390. if (idx >= 0) {
  1391. e.valid = false;
  1392. priv->r->write_cam(idx, &e);
  1393. goto out;
  1394. }
  1395. err = -ENOENT;
  1396. out:
  1397. mutex_unlock(&priv->reg_mutex);
  1398. return err;
  1399. }
  1400. static int rtl83xx_port_fdb_dump(struct dsa_switch *ds, int port,
  1401. dsa_fdb_dump_cb_t *cb, void *data)
  1402. {
  1403. struct rtl838x_l2_entry e;
  1404. struct rtl838x_switch_priv *priv = ds->priv;
  1405. mutex_lock(&priv->reg_mutex);
  1406. for (int i = 0; i < priv->fib_entries; i++) {
  1407. priv->r->read_l2_entry_using_hash(i >> 2, i & 0x3, &e);
  1408. if (!e.valid)
  1409. continue;
  1410. if (e.port == port || e.port == RTL930X_PORT_IGNORE)
  1411. cb(e.mac, e.vid, e.is_static, data);
  1412. if (!((i + 1) % 64))
  1413. cond_resched();
  1414. }
  1415. for (int i = 0; i < 64; i++) {
  1416. priv->r->read_cam(i, &e);
  1417. if (!e.valid)
  1418. continue;
  1419. if (e.port == port)
  1420. cb(e.mac, e.vid, e.is_static, data);
  1421. }
  1422. mutex_unlock(&priv->reg_mutex);
  1423. return 0;
  1424. }
  1425. static int rtl83xx_port_mdb_add(struct dsa_switch *ds, int port,
  1426. const struct switchdev_obj_port_mdb *mdb)
  1427. {
  1428. struct rtl838x_switch_priv *priv = ds->priv;
  1429. u64 mac = ether_addr_to_u64(mdb->addr);
  1430. struct rtl838x_l2_entry e;
  1431. int err = 0, idx;
  1432. int vid = mdb->vid;
  1433. u64 seed = priv->r->l2_hash_seed(mac, vid);
  1434. int mc_group;
  1435. if (priv->id >= 0x9300)
  1436. return -EOPNOTSUPP;
  1437. pr_debug("In %s port %d, mac %llx, vid: %d\n", __func__, port, mac, vid);
  1438. if (priv->is_lagmember[port]) {
  1439. pr_debug("%s: %d is lag slave. ignore\n", __func__, port);
  1440. return -EINVAL;
  1441. }
  1442. mutex_lock(&priv->reg_mutex);
  1443. idx = rtl83xx_find_l2_hash_entry(priv, seed, false, &e);
  1444. /* Found an existing or empty entry */
  1445. if (idx >= 0) {
  1446. if (e.valid) {
  1447. pr_debug("Found an existing entry %016llx, mc_group %d\n",
  1448. ether_addr_to_u64(e.mac), e.mc_portmask_index);
  1449. rtl83xx_mc_group_add_port(priv, e.mc_portmask_index, port);
  1450. } else {
  1451. pr_debug("New entry for seed %016llx\n", seed);
  1452. mc_group = rtl83xx_mc_group_alloc(priv, port);
  1453. if (mc_group < 0) {
  1454. err = -ENOTSUPP;
  1455. goto out;
  1456. }
  1457. rtl83xx_setup_l2_mc_entry(&e, vid, mac, mc_group);
  1458. priv->r->write_l2_entry_using_hash(idx >> 2, idx & 0x3, &e);
  1459. }
  1460. goto out;
  1461. }
  1462. /* Hash buckets full, try CAM */
  1463. idx = rtl83xx_find_l2_cam_entry(priv, seed, false, &e);
  1464. if (idx >= 0) {
  1465. if (e.valid) {
  1466. pr_debug("Found existing CAM entry %016llx, mc_group %d\n",
  1467. ether_addr_to_u64(e.mac), e.mc_portmask_index);
  1468. rtl83xx_mc_group_add_port(priv, e.mc_portmask_index, port);
  1469. } else {
  1470. pr_debug("New entry\n");
  1471. mc_group = rtl83xx_mc_group_alloc(priv, port);
  1472. if (mc_group < 0) {
  1473. err = -ENOTSUPP;
  1474. goto out;
  1475. }
  1476. rtl83xx_setup_l2_mc_entry(&e, vid, mac, mc_group);
  1477. priv->r->write_cam(idx, &e);
  1478. }
  1479. goto out;
  1480. }
  1481. err = -ENOTSUPP;
  1482. out:
  1483. mutex_unlock(&priv->reg_mutex);
  1484. if (err)
  1485. dev_err(ds->dev, "failed to add MDB entry\n");
  1486. return err;
  1487. }
  1488. int rtl83xx_port_mdb_del(struct dsa_switch *ds, int port,
  1489. const struct switchdev_obj_port_mdb *mdb)
  1490. {
  1491. struct rtl838x_switch_priv *priv = ds->priv;
  1492. u64 mac = ether_addr_to_u64(mdb->addr);
  1493. struct rtl838x_l2_entry e;
  1494. int err = 0, idx;
  1495. int vid = mdb->vid;
  1496. u64 seed = priv->r->l2_hash_seed(mac, vid);
  1497. u64 portmask;
  1498. pr_debug("In %s, port %d, mac %llx, vid: %d\n", __func__, port, mac, vid);
  1499. if (priv->is_lagmember[port]) {
  1500. pr_info("%s: %d is lag slave. ignore\n", __func__, port);
  1501. return 0;
  1502. }
  1503. mutex_lock(&priv->reg_mutex);
  1504. idx = rtl83xx_find_l2_hash_entry(priv, seed, true, &e);
  1505. if (idx >= 0) {
  1506. pr_debug("Found entry index %d, key %d and bucket %d\n", idx, idx >> 2, idx & 3);
  1507. portmask = rtl83xx_mc_group_del_port(priv, e.mc_portmask_index, port);
  1508. if (!portmask) {
  1509. e.valid = false;
  1510. priv->r->write_l2_entry_using_hash(idx >> 2, idx & 0x3, &e);
  1511. }
  1512. goto out;
  1513. }
  1514. /* Check CAM for spillover from hash buckets */
  1515. idx = rtl83xx_find_l2_cam_entry(priv, seed, true, &e);
  1516. if (idx >= 0) {
  1517. portmask = rtl83xx_mc_group_del_port(priv, e.mc_portmask_index, port);
  1518. if (!portmask) {
  1519. e.valid = false;
  1520. priv->r->write_cam(idx, &e);
  1521. }
  1522. goto out;
  1523. }
  1524. /* TODO: Re-enable with a newer kernel: err = -ENOENT; */
  1525. out:
  1526. mutex_unlock(&priv->reg_mutex);
  1527. return err;
  1528. }
  1529. static int rtl83xx_port_mirror_add(struct dsa_switch *ds, int port,
  1530. struct dsa_mall_mirror_tc_entry *mirror,
  1531. bool ingress)
  1532. {
  1533. /* We support 4 mirror groups, one destination port per group */
  1534. int group;
  1535. struct rtl838x_switch_priv *priv = ds->priv;
  1536. int ctrl_reg, dpm_reg, spm_reg;
  1537. pr_debug("In %s\n", __func__);
  1538. for (group = 0; group < 4; group++) {
  1539. if (priv->mirror_group_ports[group] == mirror->to_local_port)
  1540. break;
  1541. }
  1542. if (group >= 4) {
  1543. for (group = 0; group < 4; group++) {
  1544. if (priv->mirror_group_ports[group] < 0)
  1545. break;
  1546. }
  1547. }
  1548. if (group >= 4)
  1549. return -ENOSPC;
  1550. ctrl_reg = priv->r->mir_ctrl + group * 4;
  1551. dpm_reg = priv->r->mir_dpm + group * 4 * priv->port_width;
  1552. spm_reg = priv->r->mir_spm + group * 4 * priv->port_width;
  1553. pr_debug("Using group %d\n", group);
  1554. mutex_lock(&priv->reg_mutex);
  1555. if (priv->family_id == RTL8380_FAMILY_ID) {
  1556. /* Enable mirroring to port across VLANs (bit 11) */
  1557. sw_w32(1 << 11 | (mirror->to_local_port << 4) | 1, ctrl_reg);
  1558. } else {
  1559. /* Enable mirroring to destination port */
  1560. sw_w32((mirror->to_local_port << 4) | 1, ctrl_reg);
  1561. }
  1562. if (ingress && (priv->r->get_port_reg_be(spm_reg) & (1ULL << port))) {
  1563. mutex_unlock(&priv->reg_mutex);
  1564. return -EEXIST;
  1565. }
  1566. if ((!ingress) && (priv->r->get_port_reg_be(dpm_reg) & (1ULL << port))) {
  1567. mutex_unlock(&priv->reg_mutex);
  1568. return -EEXIST;
  1569. }
  1570. if (ingress)
  1571. priv->r->mask_port_reg_be(0, 1ULL << port, spm_reg);
  1572. else
  1573. priv->r->mask_port_reg_be(0, 1ULL << port, dpm_reg);
  1574. priv->mirror_group_ports[group] = mirror->to_local_port;
  1575. mutex_unlock(&priv->reg_mutex);
  1576. return 0;
  1577. }
  1578. static void rtl83xx_port_mirror_del(struct dsa_switch *ds, int port,
  1579. struct dsa_mall_mirror_tc_entry *mirror)
  1580. {
  1581. int group = 0;
  1582. struct rtl838x_switch_priv *priv = ds->priv;
  1583. int ctrl_reg, dpm_reg, spm_reg;
  1584. pr_debug("In %s\n", __func__);
  1585. for (group = 0; group < 4; group++) {
  1586. if (priv->mirror_group_ports[group] == mirror->to_local_port)
  1587. break;
  1588. }
  1589. if (group >= 4)
  1590. return;
  1591. ctrl_reg = priv->r->mir_ctrl + group * 4;
  1592. dpm_reg = priv->r->mir_dpm + group * 4 * priv->port_width;
  1593. spm_reg = priv->r->mir_spm + group * 4 * priv->port_width;
  1594. mutex_lock(&priv->reg_mutex);
  1595. if (mirror->ingress) {
  1596. /* Ingress, clear source port matrix */
  1597. priv->r->mask_port_reg_be(1ULL << port, 0, spm_reg);
  1598. } else {
  1599. /* Egress, clear destination port matrix */
  1600. priv->r->mask_port_reg_be(1ULL << port, 0, dpm_reg);
  1601. }
  1602. if (!(sw_r32(spm_reg) || sw_r32(dpm_reg))) {
  1603. priv->mirror_group_ports[group] = -1;
  1604. sw_w32(0, ctrl_reg);
  1605. }
  1606. mutex_unlock(&priv->reg_mutex);
  1607. }
  1608. static int rtl83xx_port_pre_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, struct netlink_ext_ack *extack)
  1609. {
  1610. struct rtl838x_switch_priv *priv = ds->priv;
  1611. unsigned long features = 0;
  1612. pr_debug("%s: %d %lX\n", __func__, port, flags.val);
  1613. if (priv->r->enable_learning)
  1614. features |= BR_LEARNING;
  1615. if (priv->r->enable_flood)
  1616. features |= BR_FLOOD;
  1617. if (priv->r->enable_mcast_flood)
  1618. features |= BR_MCAST_FLOOD;
  1619. if (priv->r->enable_bcast_flood)
  1620. features |= BR_BCAST_FLOOD;
  1621. if (flags.mask & ~(features))
  1622. return -EINVAL;
  1623. return 0;
  1624. }
  1625. static int rtl83xx_port_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, struct netlink_ext_ack *extack)
  1626. {
  1627. struct rtl838x_switch_priv *priv = ds->priv;
  1628. pr_debug("%s: %d %lX\n", __func__, port, flags.val);
  1629. if (priv->r->enable_learning && (flags.mask & BR_LEARNING))
  1630. priv->r->enable_learning(port, !!(flags.val & BR_LEARNING));
  1631. if (priv->r->enable_flood && (flags.mask & BR_FLOOD))
  1632. priv->r->enable_flood(port, !!(flags.val & BR_FLOOD));
  1633. if (priv->r->enable_mcast_flood && (flags.mask & BR_MCAST_FLOOD))
  1634. priv->r->enable_mcast_flood(port, !!(flags.val & BR_MCAST_FLOOD));
  1635. if (priv->r->enable_bcast_flood && (flags.mask & BR_BCAST_FLOOD))
  1636. priv->r->enable_bcast_flood(port, !!(flags.val & BR_BCAST_FLOOD));
  1637. return 0;
  1638. }
  1639. static bool rtl83xx_lag_can_offload(struct dsa_switch *ds,
  1640. struct net_device *lag,
  1641. struct netdev_lag_upper_info *info)
  1642. {
  1643. int id;
  1644. id = dsa_lag_id(ds->dst, lag);
  1645. if (id < 0 || id >= ds->num_lag_ids)
  1646. return false;
  1647. if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
  1648. return false;
  1649. }
  1650. if (info->hash_type != NETDEV_LAG_HASH_L2 && info->hash_type != NETDEV_LAG_HASH_L23)
  1651. return false;
  1652. return true;
  1653. }
  1654. static int rtl83xx_port_lag_change(struct dsa_switch *ds, int port)
  1655. {
  1656. struct rtl838x_switch_priv *priv = ds->priv;
  1657. pr_debug("%s: %d\n", __func__, port);
  1658. /* Nothing to be done... */
  1659. return 0;
  1660. }
  1661. static int rtl83xx_port_lag_join(struct dsa_switch *ds, int port,
  1662. struct net_device *lag,
  1663. struct netdev_lag_upper_info *info)
  1664. {
  1665. struct rtl838x_switch_priv *priv = ds->priv;
  1666. int i, err = 0;
  1667. if (!rtl83xx_lag_can_offload(ds, lag, info))
  1668. return -EOPNOTSUPP;
  1669. mutex_lock(&priv->reg_mutex);
  1670. for (i = 0; i < priv->n_lags; i++) {
  1671. if ((!priv->lag_devs[i]) || (priv->lag_devs[i] == lag))
  1672. break;
  1673. }
  1674. if (port >= priv->cpu_port) {
  1675. err = -EINVAL;
  1676. goto out;
  1677. }
  1678. pr_info("port_lag_join: group %d, port %d\n",i, port);
  1679. if (!priv->lag_devs[i])
  1680. priv->lag_devs[i] = lag;
  1681. if (priv->lag_primary[i] == -1) {
  1682. priv->lag_primary[i] = port;
  1683. } else
  1684. priv->is_lagmember[port] = 1;
  1685. priv->lagmembers |= (1ULL << port);
  1686. pr_debug("lag_members = %llX\n", priv->lagmembers);
  1687. err = rtl83xx_lag_add(priv->ds, i, port, info);
  1688. if (err) {
  1689. err = -EINVAL;
  1690. goto out;
  1691. }
  1692. out:
  1693. mutex_unlock(&priv->reg_mutex);
  1694. return err;
  1695. }
  1696. static int rtl83xx_port_lag_leave(struct dsa_switch *ds, int port,
  1697. struct net_device *lag)
  1698. {
  1699. int i, group = -1, err;
  1700. struct rtl838x_switch_priv *priv = ds->priv;
  1701. mutex_lock(&priv->reg_mutex);
  1702. for (i = 0; i < priv->n_lags; i++) {
  1703. if (priv->lags_port_members[i] & BIT_ULL(port)) {
  1704. group = i;
  1705. break;
  1706. }
  1707. }
  1708. if (group == -1) {
  1709. pr_info("port_lag_leave: port %d is not a member\n", port);
  1710. err = -EINVAL;
  1711. goto out;
  1712. }
  1713. if (port >= priv->cpu_port) {
  1714. err = -EINVAL;
  1715. goto out;
  1716. }
  1717. pr_info("port_lag_del: group %d, port %d\n",group, port);
  1718. priv->lagmembers &=~ (1ULL << port);
  1719. priv->lag_primary[i] = -1;
  1720. priv->is_lagmember[port] = 0;
  1721. pr_debug("lag_members = %llX\n", priv->lagmembers);
  1722. err = rtl83xx_lag_del(priv->ds, group, port);
  1723. if (err) {
  1724. err = -EINVAL;
  1725. goto out;
  1726. }
  1727. if (!priv->lags_port_members[i])
  1728. priv->lag_devs[i] = NULL;
  1729. out:
  1730. mutex_unlock(&priv->reg_mutex);
  1731. return 0;
  1732. }
  1733. int dsa_phy_read(struct dsa_switch *ds, int phy_addr, int phy_reg)
  1734. {
  1735. u32 val;
  1736. u32 offset = 0;
  1737. struct rtl838x_switch_priv *priv = ds->priv;
  1738. if ((phy_addr >= 24) &&
  1739. (phy_addr <= 27) &&
  1740. (priv->ports[24].phy == PHY_RTL838X_SDS)) {
  1741. if (phy_addr == 26)
  1742. offset = 0x100;
  1743. val = sw_r32(RTL838X_SDS4_FIB_REG0 + offset + (phy_reg << 2)) & 0xffff;
  1744. return val;
  1745. }
  1746. read_phy(phy_addr, 0, phy_reg, &val);
  1747. return val;
  1748. }
  1749. int dsa_phy_write(struct dsa_switch *ds, int phy_addr, int phy_reg, u16 val)
  1750. {
  1751. u32 offset = 0;
  1752. struct rtl838x_switch_priv *priv = ds->priv;
  1753. if ((phy_addr >= 24) &&
  1754. (phy_addr <= 27) &&
  1755. (priv->ports[24].phy == PHY_RTL838X_SDS)) {
  1756. if (phy_addr == 26)
  1757. offset = 0x100;
  1758. sw_w32(val, RTL838X_SDS4_FIB_REG0 + offset + (phy_reg << 2));
  1759. return 0;
  1760. }
  1761. return write_phy(phy_addr, 0, phy_reg, val);
  1762. }
  1763. const struct dsa_switch_ops rtl83xx_switch_ops = {
  1764. .get_tag_protocol = rtl83xx_get_tag_protocol,
  1765. .setup = rtl83xx_setup,
  1766. .phy_read = dsa_phy_read,
  1767. .phy_write = dsa_phy_write,
  1768. .phylink_validate = rtl83xx_phylink_validate,
  1769. .phylink_mac_link_state = rtl83xx_phylink_mac_link_state,
  1770. .phylink_mac_config = rtl83xx_phylink_mac_config,
  1771. .phylink_mac_link_down = rtl83xx_phylink_mac_link_down,
  1772. .phylink_mac_link_up = rtl83xx_phylink_mac_link_up,
  1773. .get_strings = rtl83xx_get_strings,
  1774. .get_ethtool_stats = rtl83xx_get_ethtool_stats,
  1775. .get_sset_count = rtl83xx_get_sset_count,
  1776. .port_enable = rtl83xx_port_enable,
  1777. .port_disable = rtl83xx_port_disable,
  1778. .get_mac_eee = rtl83xx_get_mac_eee,
  1779. .set_mac_eee = rtl83xx_set_mac_eee,
  1780. .set_ageing_time = rtl83xx_set_ageing_time,
  1781. .port_bridge_join = rtl83xx_port_bridge_join,
  1782. .port_bridge_leave = rtl83xx_port_bridge_leave,
  1783. .port_stp_state_set = rtl83xx_port_stp_state_set,
  1784. .port_fast_age = rtl83xx_fast_age,
  1785. .port_vlan_filtering = rtl83xx_vlan_filtering,
  1786. .port_vlan_add = rtl83xx_vlan_add,
  1787. .port_vlan_del = rtl83xx_vlan_del,
  1788. .port_fdb_add = rtl83xx_port_fdb_add,
  1789. .port_fdb_del = rtl83xx_port_fdb_del,
  1790. .port_fdb_dump = rtl83xx_port_fdb_dump,
  1791. .port_mdb_add = rtl83xx_port_mdb_add,
  1792. .port_mdb_del = rtl83xx_port_mdb_del,
  1793. .port_mirror_add = rtl83xx_port_mirror_add,
  1794. .port_mirror_del = rtl83xx_port_mirror_del,
  1795. .port_lag_change = rtl83xx_port_lag_change,
  1796. .port_lag_join = rtl83xx_port_lag_join,
  1797. .port_lag_leave = rtl83xx_port_lag_leave,
  1798. .port_pre_bridge_flags = rtl83xx_port_pre_bridge_flags,
  1799. .port_bridge_flags = rtl83xx_port_bridge_flags,
  1800. };
  1801. const struct dsa_switch_ops rtl930x_switch_ops = {
  1802. .get_tag_protocol = rtl83xx_get_tag_protocol,
  1803. .setup = rtl93xx_setup,
  1804. .phy_read = dsa_phy_read,
  1805. .phy_write = dsa_phy_write,
  1806. .phylink_validate = rtl93xx_phylink_validate,
  1807. .phylink_mac_link_state = rtl93xx_phylink_mac_link_state,
  1808. .phylink_mac_config = rtl93xx_phylink_mac_config,
  1809. .phylink_mac_link_down = rtl93xx_phylink_mac_link_down,
  1810. .phylink_mac_link_up = rtl93xx_phylink_mac_link_up,
  1811. .get_strings = rtl83xx_get_strings,
  1812. .get_ethtool_stats = rtl83xx_get_ethtool_stats,
  1813. .get_sset_count = rtl83xx_get_sset_count,
  1814. .port_enable = rtl83xx_port_enable,
  1815. .port_disable = rtl83xx_port_disable,
  1816. .get_mac_eee = rtl93xx_get_mac_eee,
  1817. .set_mac_eee = rtl83xx_set_mac_eee,
  1818. .set_ageing_time = rtl83xx_set_ageing_time,
  1819. .port_bridge_join = rtl83xx_port_bridge_join,
  1820. .port_bridge_leave = rtl83xx_port_bridge_leave,
  1821. .port_stp_state_set = rtl83xx_port_stp_state_set,
  1822. .port_fast_age = rtl930x_fast_age,
  1823. .port_vlan_filtering = rtl83xx_vlan_filtering,
  1824. .port_vlan_add = rtl83xx_vlan_add,
  1825. .port_vlan_del = rtl83xx_vlan_del,
  1826. .port_fdb_add = rtl83xx_port_fdb_add,
  1827. .port_fdb_del = rtl83xx_port_fdb_del,
  1828. .port_fdb_dump = rtl83xx_port_fdb_dump,
  1829. .port_mdb_add = rtl83xx_port_mdb_add,
  1830. .port_mdb_del = rtl83xx_port_mdb_del,
  1831. .port_lag_change = rtl83xx_port_lag_change,
  1832. .port_lag_join = rtl83xx_port_lag_join,
  1833. .port_lag_leave = rtl83xx_port_lag_leave,
  1834. .port_pre_bridge_flags = rtl83xx_port_pre_bridge_flags,
  1835. .port_bridge_flags = rtl83xx_port_bridge_flags,
  1836. };