dsa.c 62 KB

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