dsa.c 60 KB

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