dsa.c 62 KB

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