dsa.c 60 KB

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