dsa.c 60 KB

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