dsa.c 60 KB

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