dsa.c 61 KB

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