port.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Handling of a single switch port
  4. *
  5. * Copyright (c) 2017 Savoir-faire Linux Inc.
  6. * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
  7. */
  8. #include <linux/if_bridge.h>
  9. #include <linux/netdevice.h>
  10. #include <linux/notifier.h>
  11. #include <linux/of_mdio.h>
  12. #include <linux/of_net.h>
  13. #include "dsa.h"
  14. #include "port.h"
  15. #include "switch.h"
  16. #include "tag_8021q.h"
  17. #include "user.h"
  18. /**
  19. * dsa_port_notify - Notify the switching fabric of changes to a port
  20. * @dp: port on which change occurred
  21. * @e: event, must be of type DSA_NOTIFIER_*
  22. * @v: event-specific value.
  23. *
  24. * Notify all switches in the DSA tree that this port's switch belongs to,
  25. * including this switch itself, of an event. Allows the other switches to
  26. * reconfigure themselves for cross-chip operations. Can also be used to
  27. * reconfigure ports without net_devices (CPU ports, DSA links) whenever
  28. * a user port's state changes.
  29. */
  30. static int dsa_port_notify(const struct dsa_port *dp, unsigned long e, void *v)
  31. {
  32. return dsa_tree_notify(dp->ds->dst, e, v);
  33. }
  34. static void dsa_port_notify_bridge_fdb_flush(const struct dsa_port *dp, u16 vid)
  35. {
  36. struct net_device *brport_dev = dsa_port_to_bridge_port(dp);
  37. struct switchdev_notifier_fdb_info info = {
  38. .vid = vid,
  39. };
  40. /* When the port becomes standalone it has already left the bridge.
  41. * Don't notify the bridge in that case.
  42. */
  43. if (!brport_dev)
  44. return;
  45. call_switchdev_notifiers(SWITCHDEV_FDB_FLUSH_TO_BRIDGE,
  46. brport_dev, &info.info, NULL);
  47. }
  48. static void dsa_port_fast_age(const struct dsa_port *dp)
  49. {
  50. struct dsa_switch *ds = dp->ds;
  51. if (!ds->ops->port_fast_age)
  52. return;
  53. ds->ops->port_fast_age(ds, dp->index);
  54. /* flush all VLANs */
  55. dsa_port_notify_bridge_fdb_flush(dp, 0);
  56. }
  57. static int dsa_port_vlan_fast_age(const struct dsa_port *dp, u16 vid)
  58. {
  59. struct dsa_switch *ds = dp->ds;
  60. int err;
  61. if (!ds->ops->port_vlan_fast_age)
  62. return -EOPNOTSUPP;
  63. err = ds->ops->port_vlan_fast_age(ds, dp->index, vid);
  64. if (!err)
  65. dsa_port_notify_bridge_fdb_flush(dp, vid);
  66. return err;
  67. }
  68. static int dsa_port_msti_fast_age(const struct dsa_port *dp, u16 msti)
  69. {
  70. DECLARE_BITMAP(vids, VLAN_N_VID) = { 0 };
  71. int err, vid;
  72. err = br_mst_get_info(dsa_port_bridge_dev_get(dp), msti, vids);
  73. if (err)
  74. return err;
  75. for_each_set_bit(vid, vids, VLAN_N_VID) {
  76. err = dsa_port_vlan_fast_age(dp, vid);
  77. if (err)
  78. return err;
  79. }
  80. return 0;
  81. }
  82. static bool dsa_port_can_configure_learning(struct dsa_port *dp)
  83. {
  84. struct switchdev_brport_flags flags = {
  85. .mask = BR_LEARNING,
  86. };
  87. struct dsa_switch *ds = dp->ds;
  88. int err;
  89. if (!ds->ops->port_bridge_flags || !ds->ops->port_pre_bridge_flags)
  90. return false;
  91. err = ds->ops->port_pre_bridge_flags(ds, dp->index, flags, NULL);
  92. return !err;
  93. }
  94. bool dsa_port_supports_hwtstamp(struct dsa_port *dp)
  95. {
  96. struct kernel_hwtstamp_config config = {};
  97. struct dsa_switch *ds = dp->ds;
  98. int err;
  99. if (!ds->ops->port_hwtstamp_get || !ds->ops->port_hwtstamp_set)
  100. return false;
  101. /* "See through" shim implementations of the "get" method. */
  102. err = ds->ops->port_hwtstamp_get(ds, dp->index, &config);
  103. return err != -EOPNOTSUPP;
  104. }
  105. int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age)
  106. {
  107. struct dsa_switch *ds = dp->ds;
  108. int port = dp->index;
  109. if (!ds->ops->port_stp_state_set)
  110. return -EOPNOTSUPP;
  111. ds->ops->port_stp_state_set(ds, port, state);
  112. if (!dsa_port_can_configure_learning(dp) ||
  113. (do_fast_age && dp->learning)) {
  114. /* Fast age FDB entries or flush appropriate forwarding database
  115. * for the given port, if we are moving it from Learning or
  116. * Forwarding state, to Disabled or Blocking or Listening state.
  117. * Ports that were standalone before the STP state change don't
  118. * need to fast age the FDB, since address learning is off in
  119. * standalone mode.
  120. */
  121. if ((dp->stp_state == BR_STATE_LEARNING ||
  122. dp->stp_state == BR_STATE_FORWARDING) &&
  123. (state == BR_STATE_DISABLED ||
  124. state == BR_STATE_BLOCKING ||
  125. state == BR_STATE_LISTENING))
  126. dsa_port_fast_age(dp);
  127. }
  128. dp->stp_state = state;
  129. return 0;
  130. }
  131. static void dsa_port_set_state_now(struct dsa_port *dp, u8 state,
  132. bool do_fast_age)
  133. {
  134. struct dsa_switch *ds = dp->ds;
  135. int err;
  136. err = dsa_port_set_state(dp, state, do_fast_age);
  137. if (err && err != -EOPNOTSUPP) {
  138. dev_err(ds->dev, "port %d failed to set STP state %u: %pe\n",
  139. dp->index, state, ERR_PTR(err));
  140. }
  141. }
  142. int dsa_port_set_mst_state(struct dsa_port *dp,
  143. const struct switchdev_mst_state *state,
  144. struct netlink_ext_ack *extack)
  145. {
  146. struct dsa_switch *ds = dp->ds;
  147. u8 prev_state;
  148. int err;
  149. if (!ds->ops->port_mst_state_set)
  150. return -EOPNOTSUPP;
  151. err = br_mst_get_state(dsa_port_to_bridge_port(dp), state->msti,
  152. &prev_state);
  153. if (err)
  154. return err;
  155. err = ds->ops->port_mst_state_set(ds, dp->index, state);
  156. if (err)
  157. return err;
  158. if (!(dp->learning &&
  159. (prev_state == BR_STATE_LEARNING ||
  160. prev_state == BR_STATE_FORWARDING) &&
  161. (state->state == BR_STATE_DISABLED ||
  162. state->state == BR_STATE_BLOCKING ||
  163. state->state == BR_STATE_LISTENING)))
  164. return 0;
  165. err = dsa_port_msti_fast_age(dp, state->msti);
  166. if (err)
  167. NL_SET_ERR_MSG_MOD(extack,
  168. "Unable to flush associated VLANs");
  169. return 0;
  170. }
  171. int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy)
  172. {
  173. struct dsa_switch *ds = dp->ds;
  174. int port = dp->index;
  175. int err;
  176. if (ds->ops->port_enable) {
  177. err = ds->ops->port_enable(ds, port, phy);
  178. if (err)
  179. return err;
  180. }
  181. if (!dp->bridge)
  182. dsa_port_set_state_now(dp, BR_STATE_FORWARDING, false);
  183. if (dp->pl)
  184. phylink_start(dp->pl);
  185. return 0;
  186. }
  187. int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy)
  188. {
  189. int err;
  190. rtnl_lock();
  191. err = dsa_port_enable_rt(dp, phy);
  192. rtnl_unlock();
  193. return err;
  194. }
  195. void dsa_port_disable_rt(struct dsa_port *dp)
  196. {
  197. struct dsa_switch *ds = dp->ds;
  198. int port = dp->index;
  199. if (dp->pl)
  200. phylink_stop(dp->pl);
  201. if (!dp->bridge)
  202. dsa_port_set_state_now(dp, BR_STATE_DISABLED, false);
  203. if (ds->ops->port_disable)
  204. ds->ops->port_disable(ds, port);
  205. }
  206. void dsa_port_disable(struct dsa_port *dp)
  207. {
  208. rtnl_lock();
  209. dsa_port_disable_rt(dp);
  210. rtnl_unlock();
  211. }
  212. static void dsa_port_reset_vlan_filtering(struct dsa_port *dp,
  213. struct dsa_bridge bridge)
  214. {
  215. struct netlink_ext_ack extack = {0};
  216. bool change_vlan_filtering = false;
  217. struct dsa_switch *ds = dp->ds;
  218. struct dsa_port *other_dp;
  219. bool vlan_filtering;
  220. int err;
  221. if (ds->needs_standalone_vlan_filtering &&
  222. !br_vlan_enabled(bridge.dev)) {
  223. change_vlan_filtering = true;
  224. vlan_filtering = true;
  225. } else if (!ds->needs_standalone_vlan_filtering &&
  226. br_vlan_enabled(bridge.dev)) {
  227. change_vlan_filtering = true;
  228. vlan_filtering = false;
  229. }
  230. /* If the bridge was vlan_filtering, the bridge core doesn't trigger an
  231. * event for changing vlan_filtering setting upon user ports leaving
  232. * it. That is a good thing, because that lets us handle it and also
  233. * handle the case where the switch's vlan_filtering setting is global
  234. * (not per port). When that happens, the correct moment to trigger the
  235. * vlan_filtering callback is only when the last port leaves the last
  236. * VLAN-aware bridge.
  237. */
  238. if (change_vlan_filtering && ds->vlan_filtering_is_global) {
  239. dsa_switch_for_each_port(other_dp, ds) {
  240. struct net_device *br = dsa_port_bridge_dev_get(other_dp);
  241. if (br && br_vlan_enabled(br)) {
  242. change_vlan_filtering = false;
  243. break;
  244. }
  245. }
  246. }
  247. if (!change_vlan_filtering)
  248. return;
  249. err = dsa_port_vlan_filtering(dp, vlan_filtering, &extack);
  250. if (extack._msg) {
  251. dev_err(ds->dev, "port %d: %s\n", dp->index,
  252. extack._msg);
  253. }
  254. if (err && err != -EOPNOTSUPP) {
  255. dev_err(ds->dev,
  256. "port %d failed to reset VLAN filtering to %d: %pe\n",
  257. dp->index, vlan_filtering, ERR_PTR(err));
  258. }
  259. }
  260. static int dsa_port_inherit_brport_flags(struct dsa_port *dp,
  261. struct netlink_ext_ack *extack)
  262. {
  263. const unsigned long mask = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
  264. BR_BCAST_FLOOD | BR_PORT_LOCKED;
  265. struct net_device *brport_dev = dsa_port_to_bridge_port(dp);
  266. int flag, err;
  267. for_each_set_bit(flag, &mask, 32) {
  268. struct switchdev_brport_flags flags = {0};
  269. flags.mask = BIT(flag);
  270. if (br_port_flag_is_set(brport_dev, BIT(flag)))
  271. flags.val = BIT(flag);
  272. err = dsa_port_bridge_flags(dp, flags, extack);
  273. if (err && err != -EOPNOTSUPP)
  274. return err;
  275. }
  276. return 0;
  277. }
  278. static void dsa_port_clear_brport_flags(struct dsa_port *dp)
  279. {
  280. const unsigned long val = BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD;
  281. const unsigned long mask = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
  282. BR_BCAST_FLOOD | BR_PORT_LOCKED;
  283. int flag, err;
  284. for_each_set_bit(flag, &mask, 32) {
  285. struct switchdev_brport_flags flags = {0};
  286. flags.mask = BIT(flag);
  287. flags.val = val & BIT(flag);
  288. err = dsa_port_bridge_flags(dp, flags, NULL);
  289. if (err && err != -EOPNOTSUPP)
  290. dev_err(dp->ds->dev,
  291. "failed to clear bridge port flag %lu: %pe\n",
  292. flags.val, ERR_PTR(err));
  293. }
  294. }
  295. static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,
  296. struct netlink_ext_ack *extack)
  297. {
  298. struct net_device *brport_dev = dsa_port_to_bridge_port(dp);
  299. struct net_device *br = dsa_port_bridge_dev_get(dp);
  300. int err;
  301. err = dsa_port_inherit_brport_flags(dp, extack);
  302. if (err)
  303. return err;
  304. err = dsa_port_set_state(dp, br_port_get_stp_state(brport_dev), false);
  305. if (err && err != -EOPNOTSUPP)
  306. return err;
  307. err = dsa_port_vlan_filtering(dp, br_vlan_enabled(br), extack);
  308. if (err && err != -EOPNOTSUPP)
  309. return err;
  310. err = dsa_port_ageing_time(dp, br_get_ageing_time(br));
  311. if (err && err != -EOPNOTSUPP)
  312. return err;
  313. return 0;
  314. }
  315. static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp,
  316. struct dsa_bridge bridge)
  317. {
  318. /* Configure the port for standalone mode (no address learning,
  319. * flood everything).
  320. * The bridge only emits SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS events
  321. * when the user requests it through netlink or sysfs, but not
  322. * automatically at port join or leave, so we need to handle resetting
  323. * the brport flags ourselves. But we even prefer it that way, because
  324. * otherwise, some setups might never get the notification they need,
  325. * for example, when a port leaves a LAG that offloads the bridge,
  326. * it becomes standalone, but as far as the bridge is concerned, no
  327. * port ever left.
  328. */
  329. dsa_port_clear_brport_flags(dp);
  330. /* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer,
  331. * so allow it to be in BR_STATE_FORWARDING to be kept functional
  332. */
  333. dsa_port_set_state_now(dp, BR_STATE_FORWARDING, true);
  334. dsa_port_reset_vlan_filtering(dp, bridge);
  335. /* Ageing time may be global to the switch chip, so don't change it
  336. * here because we have no good reason (or value) to change it to.
  337. */
  338. }
  339. static int dsa_port_bridge_create(struct dsa_port *dp,
  340. struct net_device *br,
  341. struct netlink_ext_ack *extack)
  342. {
  343. struct dsa_switch *ds = dp->ds;
  344. struct dsa_bridge *bridge;
  345. bridge = dsa_tree_bridge_find(ds->dst, br);
  346. if (bridge) {
  347. refcount_inc(&bridge->refcount);
  348. dp->bridge = bridge;
  349. return 0;
  350. }
  351. bridge = kzalloc_obj(*bridge);
  352. if (!bridge)
  353. return -ENOMEM;
  354. refcount_set(&bridge->refcount, 1);
  355. bridge->dev = br;
  356. bridge->num = dsa_bridge_num_get(br, ds->max_num_bridges);
  357. if (ds->max_num_bridges && !bridge->num) {
  358. NL_SET_ERR_MSG_MOD(extack,
  359. "Range of offloadable bridges exceeded");
  360. kfree(bridge);
  361. return -EOPNOTSUPP;
  362. }
  363. dp->bridge = bridge;
  364. return 0;
  365. }
  366. static void dsa_port_bridge_destroy(struct dsa_port *dp,
  367. const struct net_device *br)
  368. {
  369. struct dsa_bridge *bridge = dp->bridge;
  370. dp->bridge = NULL;
  371. if (!refcount_dec_and_test(&bridge->refcount))
  372. return;
  373. if (bridge->num)
  374. dsa_bridge_num_put(br, bridge->num);
  375. kfree(bridge);
  376. }
  377. static bool dsa_port_supports_mst(struct dsa_port *dp)
  378. {
  379. struct dsa_switch *ds = dp->ds;
  380. return ds->ops->vlan_msti_set &&
  381. ds->ops->port_mst_state_set &&
  382. ds->ops->port_vlan_fast_age &&
  383. dsa_port_can_configure_learning(dp);
  384. }
  385. int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
  386. struct netlink_ext_ack *extack)
  387. {
  388. struct dsa_notifier_bridge_info info = {
  389. .dp = dp,
  390. .extack = extack,
  391. };
  392. struct net_device *dev = dp->user;
  393. struct net_device *brport_dev;
  394. int err;
  395. if (br_mst_enabled(br) && !dsa_port_supports_mst(dp))
  396. return -EOPNOTSUPP;
  397. /* Here the interface is already bridged. Reflect the current
  398. * configuration so that drivers can program their chips accordingly.
  399. */
  400. err = dsa_port_bridge_create(dp, br, extack);
  401. if (err)
  402. return err;
  403. brport_dev = dsa_port_to_bridge_port(dp);
  404. info.bridge = *dp->bridge;
  405. err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info);
  406. if (err)
  407. goto out_rollback;
  408. /* Drivers which support bridge TX forwarding should set this */
  409. dp->bridge->tx_fwd_offload = info.tx_fwd_offload;
  410. err = switchdev_bridge_port_offload(brport_dev, dev, dp,
  411. &dsa_user_switchdev_notifier,
  412. &dsa_user_switchdev_blocking_notifier,
  413. dp->bridge->tx_fwd_offload, extack);
  414. if (err)
  415. goto out_rollback_unbridge;
  416. err = dsa_port_switchdev_sync_attrs(dp, extack);
  417. if (err)
  418. goto out_rollback_unoffload;
  419. return 0;
  420. out_rollback_unoffload:
  421. switchdev_bridge_port_unoffload(brport_dev, dp,
  422. &dsa_user_switchdev_notifier,
  423. &dsa_user_switchdev_blocking_notifier);
  424. dsa_flush_workqueue();
  425. out_rollback_unbridge:
  426. dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
  427. out_rollback:
  428. dsa_port_bridge_destroy(dp, br);
  429. return err;
  430. }
  431. void dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br)
  432. {
  433. struct net_device *brport_dev = dsa_port_to_bridge_port(dp);
  434. /* Don't try to unoffload something that is not offloaded */
  435. if (!brport_dev)
  436. return;
  437. switchdev_bridge_port_unoffload(brport_dev, dp,
  438. &dsa_user_switchdev_notifier,
  439. &dsa_user_switchdev_blocking_notifier);
  440. dsa_flush_workqueue();
  441. }
  442. void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br)
  443. {
  444. struct dsa_notifier_bridge_info info = {
  445. .dp = dp,
  446. };
  447. int err;
  448. /* If the port could not be offloaded to begin with, then
  449. * there is nothing to do.
  450. */
  451. if (!dp->bridge)
  452. return;
  453. info.bridge = *dp->bridge;
  454. /* Here the port is already unbridged. Reflect the current configuration
  455. * so that drivers can program their chips accordingly.
  456. */
  457. dsa_port_bridge_destroy(dp, br);
  458. err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
  459. if (err)
  460. dev_err(dp->ds->dev,
  461. "port %d failed to notify DSA_NOTIFIER_BRIDGE_LEAVE: %pe\n",
  462. dp->index, ERR_PTR(err));
  463. dsa_port_switchdev_unsync_attrs(dp, info.bridge);
  464. }
  465. int dsa_port_lag_change(struct dsa_port *dp,
  466. struct netdev_lag_lower_state_info *linfo)
  467. {
  468. struct dsa_notifier_lag_info info = {
  469. .dp = dp,
  470. };
  471. bool tx_enabled;
  472. if (!dp->lag)
  473. return 0;
  474. /* On statically configured aggregates (e.g. loadbalance
  475. * without LACP) ports will always be tx_enabled, even if the
  476. * link is down. Thus we require both link_up and tx_enabled
  477. * in order to include it in the tx set.
  478. */
  479. tx_enabled = linfo->link_up && linfo->tx_enabled;
  480. if (tx_enabled == dp->lag_tx_enabled)
  481. return 0;
  482. dp->lag_tx_enabled = tx_enabled;
  483. return dsa_port_notify(dp, DSA_NOTIFIER_LAG_CHANGE, &info);
  484. }
  485. static int dsa_port_lag_create(struct dsa_port *dp,
  486. struct net_device *lag_dev)
  487. {
  488. struct dsa_switch *ds = dp->ds;
  489. struct dsa_lag *lag;
  490. lag = dsa_tree_lag_find(ds->dst, lag_dev);
  491. if (lag) {
  492. refcount_inc(&lag->refcount);
  493. dp->lag = lag;
  494. return 0;
  495. }
  496. lag = kzalloc_obj(*lag);
  497. if (!lag)
  498. return -ENOMEM;
  499. refcount_set(&lag->refcount, 1);
  500. mutex_init(&lag->fdb_lock);
  501. INIT_LIST_HEAD(&lag->fdbs);
  502. lag->dev = lag_dev;
  503. dsa_lag_map(ds->dst, lag);
  504. dp->lag = lag;
  505. return 0;
  506. }
  507. static void dsa_port_lag_destroy(struct dsa_port *dp)
  508. {
  509. struct dsa_lag *lag = dp->lag;
  510. dp->lag = NULL;
  511. dp->lag_tx_enabled = false;
  512. if (!refcount_dec_and_test(&lag->refcount))
  513. return;
  514. WARN_ON(!list_empty(&lag->fdbs));
  515. dsa_lag_unmap(dp->ds->dst, lag);
  516. kfree(lag);
  517. }
  518. int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev,
  519. struct netdev_lag_upper_info *uinfo,
  520. struct netlink_ext_ack *extack)
  521. {
  522. struct dsa_notifier_lag_info info = {
  523. .dp = dp,
  524. .info = uinfo,
  525. .extack = extack,
  526. };
  527. struct net_device *bridge_dev;
  528. int err;
  529. err = dsa_port_lag_create(dp, lag_dev);
  530. if (err)
  531. goto err_lag_create;
  532. info.lag = *dp->lag;
  533. err = dsa_port_notify(dp, DSA_NOTIFIER_LAG_JOIN, &info);
  534. if (err)
  535. goto err_lag_join;
  536. bridge_dev = netdev_master_upper_dev_get(lag_dev);
  537. if (!bridge_dev || !netif_is_bridge_master(bridge_dev))
  538. return 0;
  539. err = dsa_port_bridge_join(dp, bridge_dev, extack);
  540. if (err)
  541. goto err_bridge_join;
  542. return 0;
  543. err_bridge_join:
  544. dsa_port_notify(dp, DSA_NOTIFIER_LAG_LEAVE, &info);
  545. err_lag_join:
  546. dsa_port_lag_destroy(dp);
  547. err_lag_create:
  548. return err;
  549. }
  550. void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag_dev)
  551. {
  552. struct net_device *br = dsa_port_bridge_dev_get(dp);
  553. if (br)
  554. dsa_port_pre_bridge_leave(dp, br);
  555. }
  556. void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag_dev)
  557. {
  558. struct net_device *br = dsa_port_bridge_dev_get(dp);
  559. struct dsa_notifier_lag_info info = {
  560. .dp = dp,
  561. };
  562. int err;
  563. if (!dp->lag)
  564. return;
  565. /* Port might have been part of a LAG that in turn was
  566. * attached to a bridge.
  567. */
  568. if (br)
  569. dsa_port_bridge_leave(dp, br);
  570. info.lag = *dp->lag;
  571. dsa_port_lag_destroy(dp);
  572. err = dsa_port_notify(dp, DSA_NOTIFIER_LAG_LEAVE, &info);
  573. if (err)
  574. dev_err(dp->ds->dev,
  575. "port %d failed to notify DSA_NOTIFIER_LAG_LEAVE: %pe\n",
  576. dp->index, ERR_PTR(err));
  577. }
  578. /* Must be called under rcu_read_lock() */
  579. static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp,
  580. bool vlan_filtering,
  581. struct netlink_ext_ack *extack)
  582. {
  583. struct dsa_switch *ds = dp->ds;
  584. struct dsa_port *other_dp;
  585. int err;
  586. /* VLAN awareness was off, so the question is "can we turn it on".
  587. * We may have had 8021q uppers, those need to go. Make sure we don't
  588. * enter an inconsistent state: deny changing the VLAN awareness state
  589. * as long as we have 8021q uppers.
  590. */
  591. if (vlan_filtering && dsa_port_is_user(dp)) {
  592. struct net_device *br = dsa_port_bridge_dev_get(dp);
  593. struct net_device *upper_dev, *user = dp->user;
  594. struct list_head *iter;
  595. netdev_for_each_upper_dev_rcu(user, upper_dev, iter) {
  596. struct bridge_vlan_info br_info;
  597. u16 vid;
  598. if (!is_vlan_dev(upper_dev))
  599. continue;
  600. vid = vlan_dev_vlan_id(upper_dev);
  601. /* br_vlan_get_info() returns -EINVAL or -ENOENT if the
  602. * device, respectively the VID is not found, returning
  603. * 0 means success, which is a failure for us here.
  604. */
  605. err = br_vlan_get_info(br, vid, &br_info);
  606. if (err == 0) {
  607. NL_SET_ERR_MSG_MOD(extack,
  608. "Must first remove VLAN uppers having VIDs also present in bridge");
  609. return false;
  610. }
  611. }
  612. }
  613. if (!ds->vlan_filtering_is_global)
  614. return true;
  615. /* For cases where enabling/disabling VLAN awareness is global to the
  616. * switch, we need to handle the case where multiple bridges span
  617. * different ports of the same switch device and one of them has a
  618. * different setting than what is being requested.
  619. */
  620. dsa_switch_for_each_port(other_dp, ds) {
  621. struct net_device *other_br = dsa_port_bridge_dev_get(other_dp);
  622. /* If it's the same bridge, it also has same
  623. * vlan_filtering setting => no need to check
  624. */
  625. if (!other_br || other_br == dsa_port_bridge_dev_get(dp))
  626. continue;
  627. if (br_vlan_enabled(other_br) != vlan_filtering) {
  628. NL_SET_ERR_MSG_MOD(extack,
  629. "VLAN filtering is a global setting");
  630. return false;
  631. }
  632. }
  633. return true;
  634. }
  635. int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
  636. struct netlink_ext_ack *extack)
  637. {
  638. bool old_vlan_filtering = dsa_port_is_vlan_filtering(dp);
  639. struct dsa_switch *ds = dp->ds;
  640. bool apply;
  641. int err;
  642. if (!ds->ops->port_vlan_filtering)
  643. return -EOPNOTSUPP;
  644. /* We are called from dsa_user_switchdev_blocking_event(),
  645. * which is not under rcu_read_lock(), unlike
  646. * dsa_user_switchdev_event().
  647. */
  648. rcu_read_lock();
  649. apply = dsa_port_can_apply_vlan_filtering(dp, vlan_filtering, extack);
  650. rcu_read_unlock();
  651. if (!apply)
  652. return -EINVAL;
  653. if (dsa_port_is_vlan_filtering(dp) == vlan_filtering)
  654. return 0;
  655. err = ds->ops->port_vlan_filtering(ds, dp->index, vlan_filtering,
  656. extack);
  657. if (err)
  658. return err;
  659. if (ds->vlan_filtering_is_global) {
  660. struct dsa_port *other_dp;
  661. ds->vlan_filtering = vlan_filtering;
  662. dsa_switch_for_each_user_port(other_dp, ds) {
  663. struct net_device *user = other_dp->user;
  664. /* We might be called in the unbind path, so not
  665. * all user devices might still be registered.
  666. */
  667. if (!user)
  668. continue;
  669. err = dsa_user_manage_vlan_filtering(user,
  670. vlan_filtering);
  671. if (err)
  672. goto restore;
  673. }
  674. } else {
  675. dp->vlan_filtering = vlan_filtering;
  676. err = dsa_user_manage_vlan_filtering(dp->user,
  677. vlan_filtering);
  678. if (err)
  679. goto restore;
  680. }
  681. return 0;
  682. restore:
  683. ds->ops->port_vlan_filtering(ds, dp->index, old_vlan_filtering, NULL);
  684. if (ds->vlan_filtering_is_global)
  685. ds->vlan_filtering = old_vlan_filtering;
  686. else
  687. dp->vlan_filtering = old_vlan_filtering;
  688. return err;
  689. }
  690. /* This enforces legacy behavior for switch drivers which assume they can't
  691. * receive VLAN configuration when joining a bridge with vlan_filtering=0
  692. */
  693. bool dsa_port_skip_vlan_configuration(struct dsa_port *dp)
  694. {
  695. struct net_device *br = dsa_port_bridge_dev_get(dp);
  696. struct dsa_switch *ds = dp->ds;
  697. if (!br)
  698. return false;
  699. return !ds->configure_vlan_while_not_filtering && !br_vlan_enabled(br);
  700. }
  701. int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock)
  702. {
  703. unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock);
  704. unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies);
  705. struct dsa_notifier_ageing_time_info info;
  706. int err;
  707. info.ageing_time = ageing_time;
  708. err = dsa_port_notify(dp, DSA_NOTIFIER_AGEING_TIME, &info);
  709. if (err)
  710. return err;
  711. dp->ageing_time = ageing_time;
  712. return 0;
  713. }
  714. int dsa_port_mst_enable(struct dsa_port *dp, bool on,
  715. struct netlink_ext_ack *extack)
  716. {
  717. if (on && !dsa_port_supports_mst(dp)) {
  718. NL_SET_ERR_MSG_MOD(extack, "Hardware does not support MST");
  719. return -EINVAL;
  720. }
  721. return 0;
  722. }
  723. int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
  724. struct switchdev_brport_flags flags,
  725. struct netlink_ext_ack *extack)
  726. {
  727. struct dsa_switch *ds = dp->ds;
  728. if (!ds->ops->port_pre_bridge_flags)
  729. return -EINVAL;
  730. return ds->ops->port_pre_bridge_flags(ds, dp->index, flags, extack);
  731. }
  732. int dsa_port_bridge_flags(struct dsa_port *dp,
  733. struct switchdev_brport_flags flags,
  734. struct netlink_ext_ack *extack)
  735. {
  736. struct dsa_switch *ds = dp->ds;
  737. int err;
  738. if (!ds->ops->port_bridge_flags)
  739. return -EOPNOTSUPP;
  740. err = ds->ops->port_bridge_flags(ds, dp->index, flags, extack);
  741. if (err)
  742. return err;
  743. if (flags.mask & BR_LEARNING) {
  744. bool learning = flags.val & BR_LEARNING;
  745. if (learning == dp->learning)
  746. return 0;
  747. if ((dp->learning && !learning) &&
  748. (dp->stp_state == BR_STATE_LEARNING ||
  749. dp->stp_state == BR_STATE_FORWARDING))
  750. dsa_port_fast_age(dp);
  751. dp->learning = learning;
  752. }
  753. return 0;
  754. }
  755. void dsa_port_set_host_flood(struct dsa_port *dp, bool uc, bool mc)
  756. {
  757. struct dsa_switch *ds = dp->ds;
  758. if (ds->ops->port_set_host_flood)
  759. ds->ops->port_set_host_flood(ds, dp->index, uc, mc);
  760. }
  761. int dsa_port_vlan_msti(struct dsa_port *dp,
  762. const struct switchdev_vlan_msti *msti)
  763. {
  764. struct dsa_switch *ds = dp->ds;
  765. if (!ds->ops->vlan_msti_set)
  766. return -EOPNOTSUPP;
  767. return ds->ops->vlan_msti_set(ds, *dp->bridge, msti);
  768. }
  769. int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu)
  770. {
  771. struct dsa_notifier_mtu_info info = {
  772. .dp = dp,
  773. .mtu = new_mtu,
  774. };
  775. return dsa_port_notify(dp, DSA_NOTIFIER_MTU, &info);
  776. }
  777. int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
  778. u16 vid)
  779. {
  780. struct dsa_notifier_fdb_info info = {
  781. .dp = dp,
  782. .addr = addr,
  783. .vid = vid,
  784. .db = {
  785. .type = DSA_DB_BRIDGE,
  786. .bridge = *dp->bridge,
  787. },
  788. };
  789. /* Refcounting takes bridge.num as a key, and should be global for all
  790. * bridges in the absence of FDB isolation, and per bridge otherwise.
  791. * Force the bridge.num to zero here in the absence of FDB isolation.
  792. */
  793. if (!dp->ds->fdb_isolation)
  794. info.db.bridge.num = 0;
  795. return dsa_port_notify(dp, DSA_NOTIFIER_FDB_ADD, &info);
  796. }
  797. int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
  798. u16 vid)
  799. {
  800. struct dsa_notifier_fdb_info info = {
  801. .dp = dp,
  802. .addr = addr,
  803. .vid = vid,
  804. .db = {
  805. .type = DSA_DB_BRIDGE,
  806. .bridge = *dp->bridge,
  807. },
  808. };
  809. if (!dp->ds->fdb_isolation)
  810. info.db.bridge.num = 0;
  811. return dsa_port_notify(dp, DSA_NOTIFIER_FDB_DEL, &info);
  812. }
  813. static int dsa_port_host_fdb_add(struct dsa_port *dp,
  814. const unsigned char *addr, u16 vid,
  815. struct dsa_db db)
  816. {
  817. struct dsa_notifier_fdb_info info = {
  818. .dp = dp,
  819. .addr = addr,
  820. .vid = vid,
  821. .db = db,
  822. };
  823. return dsa_port_notify(dp, DSA_NOTIFIER_HOST_FDB_ADD, &info);
  824. }
  825. int dsa_port_standalone_host_fdb_add(struct dsa_port *dp,
  826. const unsigned char *addr, u16 vid)
  827. {
  828. struct dsa_db db = {
  829. .type = DSA_DB_PORT,
  830. .dp = dp,
  831. };
  832. return dsa_port_host_fdb_add(dp, addr, vid, db);
  833. }
  834. int dsa_port_bridge_host_fdb_add(struct dsa_port *dp,
  835. const unsigned char *addr, u16 vid)
  836. {
  837. struct net_device *conduit = dsa_port_to_conduit(dp);
  838. struct dsa_db db = {
  839. .type = DSA_DB_BRIDGE,
  840. .bridge = *dp->bridge,
  841. };
  842. int err;
  843. if (!dp->ds->fdb_isolation)
  844. db.bridge.num = 0;
  845. /* Avoid a call to __dev_set_promiscuity() on the conduit, which
  846. * requires rtnl_lock(), since we can't guarantee that is held here,
  847. * and we can't take it either.
  848. */
  849. if (conduit->priv_flags & IFF_UNICAST_FLT) {
  850. err = dev_uc_add(conduit, addr);
  851. if (err)
  852. return err;
  853. }
  854. return dsa_port_host_fdb_add(dp, addr, vid, db);
  855. }
  856. static int dsa_port_host_fdb_del(struct dsa_port *dp,
  857. const unsigned char *addr, u16 vid,
  858. struct dsa_db db)
  859. {
  860. struct dsa_notifier_fdb_info info = {
  861. .dp = dp,
  862. .addr = addr,
  863. .vid = vid,
  864. .db = db,
  865. };
  866. return dsa_port_notify(dp, DSA_NOTIFIER_HOST_FDB_DEL, &info);
  867. }
  868. int dsa_port_standalone_host_fdb_del(struct dsa_port *dp,
  869. const unsigned char *addr, u16 vid)
  870. {
  871. struct dsa_db db = {
  872. .type = DSA_DB_PORT,
  873. .dp = dp,
  874. };
  875. return dsa_port_host_fdb_del(dp, addr, vid, db);
  876. }
  877. int dsa_port_bridge_host_fdb_del(struct dsa_port *dp,
  878. const unsigned char *addr, u16 vid)
  879. {
  880. struct net_device *conduit = dsa_port_to_conduit(dp);
  881. struct dsa_db db = {
  882. .type = DSA_DB_BRIDGE,
  883. .bridge = *dp->bridge,
  884. };
  885. int err;
  886. if (!dp->ds->fdb_isolation)
  887. db.bridge.num = 0;
  888. if (conduit->priv_flags & IFF_UNICAST_FLT) {
  889. err = dev_uc_del(conduit, addr);
  890. if (err)
  891. return err;
  892. }
  893. return dsa_port_host_fdb_del(dp, addr, vid, db);
  894. }
  895. int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
  896. u16 vid)
  897. {
  898. struct dsa_notifier_lag_fdb_info info = {
  899. .lag = dp->lag,
  900. .addr = addr,
  901. .vid = vid,
  902. .db = {
  903. .type = DSA_DB_BRIDGE,
  904. .bridge = *dp->bridge,
  905. },
  906. };
  907. if (!dp->ds->fdb_isolation)
  908. info.db.bridge.num = 0;
  909. return dsa_port_notify(dp, DSA_NOTIFIER_LAG_FDB_ADD, &info);
  910. }
  911. int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr,
  912. u16 vid)
  913. {
  914. struct dsa_notifier_lag_fdb_info info = {
  915. .lag = dp->lag,
  916. .addr = addr,
  917. .vid = vid,
  918. .db = {
  919. .type = DSA_DB_BRIDGE,
  920. .bridge = *dp->bridge,
  921. },
  922. };
  923. if (!dp->ds->fdb_isolation)
  924. info.db.bridge.num = 0;
  925. return dsa_port_notify(dp, DSA_NOTIFIER_LAG_FDB_DEL, &info);
  926. }
  927. int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data)
  928. {
  929. struct dsa_switch *ds = dp->ds;
  930. int port = dp->index;
  931. if (!ds->ops->port_fdb_dump)
  932. return -EOPNOTSUPP;
  933. return ds->ops->port_fdb_dump(ds, port, cb, data);
  934. }
  935. int dsa_port_mdb_add(const struct dsa_port *dp,
  936. const struct switchdev_obj_port_mdb *mdb)
  937. {
  938. struct dsa_notifier_mdb_info info = {
  939. .dp = dp,
  940. .mdb = mdb,
  941. .db = {
  942. .type = DSA_DB_BRIDGE,
  943. .bridge = *dp->bridge,
  944. },
  945. };
  946. if (!dp->ds->fdb_isolation)
  947. info.db.bridge.num = 0;
  948. return dsa_port_notify(dp, DSA_NOTIFIER_MDB_ADD, &info);
  949. }
  950. int dsa_port_mdb_del(const struct dsa_port *dp,
  951. const struct switchdev_obj_port_mdb *mdb)
  952. {
  953. struct dsa_notifier_mdb_info info = {
  954. .dp = dp,
  955. .mdb = mdb,
  956. .db = {
  957. .type = DSA_DB_BRIDGE,
  958. .bridge = *dp->bridge,
  959. },
  960. };
  961. if (!dp->ds->fdb_isolation)
  962. info.db.bridge.num = 0;
  963. return dsa_port_notify(dp, DSA_NOTIFIER_MDB_DEL, &info);
  964. }
  965. static int dsa_port_host_mdb_add(const struct dsa_port *dp,
  966. const struct switchdev_obj_port_mdb *mdb,
  967. struct dsa_db db)
  968. {
  969. struct dsa_notifier_mdb_info info = {
  970. .dp = dp,
  971. .mdb = mdb,
  972. .db = db,
  973. };
  974. return dsa_port_notify(dp, DSA_NOTIFIER_HOST_MDB_ADD, &info);
  975. }
  976. int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp,
  977. const struct switchdev_obj_port_mdb *mdb)
  978. {
  979. struct dsa_db db = {
  980. .type = DSA_DB_PORT,
  981. .dp = dp,
  982. };
  983. return dsa_port_host_mdb_add(dp, mdb, db);
  984. }
  985. int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp,
  986. const struct switchdev_obj_port_mdb *mdb)
  987. {
  988. struct net_device *conduit = dsa_port_to_conduit(dp);
  989. struct dsa_db db = {
  990. .type = DSA_DB_BRIDGE,
  991. .bridge = *dp->bridge,
  992. };
  993. int err;
  994. if (!dp->ds->fdb_isolation)
  995. db.bridge.num = 0;
  996. err = dev_mc_add(conduit, mdb->addr);
  997. if (err)
  998. return err;
  999. return dsa_port_host_mdb_add(dp, mdb, db);
  1000. }
  1001. static int dsa_port_host_mdb_del(const struct dsa_port *dp,
  1002. const struct switchdev_obj_port_mdb *mdb,
  1003. struct dsa_db db)
  1004. {
  1005. struct dsa_notifier_mdb_info info = {
  1006. .dp = dp,
  1007. .mdb = mdb,
  1008. .db = db,
  1009. };
  1010. return dsa_port_notify(dp, DSA_NOTIFIER_HOST_MDB_DEL, &info);
  1011. }
  1012. int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp,
  1013. const struct switchdev_obj_port_mdb *mdb)
  1014. {
  1015. struct dsa_db db = {
  1016. .type = DSA_DB_PORT,
  1017. .dp = dp,
  1018. };
  1019. return dsa_port_host_mdb_del(dp, mdb, db);
  1020. }
  1021. int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp,
  1022. const struct switchdev_obj_port_mdb *mdb)
  1023. {
  1024. struct net_device *conduit = dsa_port_to_conduit(dp);
  1025. struct dsa_db db = {
  1026. .type = DSA_DB_BRIDGE,
  1027. .bridge = *dp->bridge,
  1028. };
  1029. int err;
  1030. if (!dp->ds->fdb_isolation)
  1031. db.bridge.num = 0;
  1032. err = dev_mc_del(conduit, mdb->addr);
  1033. if (err)
  1034. return err;
  1035. return dsa_port_host_mdb_del(dp, mdb, db);
  1036. }
  1037. int dsa_port_vlan_add(struct dsa_port *dp,
  1038. const struct switchdev_obj_port_vlan *vlan,
  1039. struct netlink_ext_ack *extack)
  1040. {
  1041. struct dsa_notifier_vlan_info info = {
  1042. .dp = dp,
  1043. .vlan = vlan,
  1044. .extack = extack,
  1045. };
  1046. return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, &info);
  1047. }
  1048. int dsa_port_vlan_del(struct dsa_port *dp,
  1049. const struct switchdev_obj_port_vlan *vlan)
  1050. {
  1051. struct dsa_notifier_vlan_info info = {
  1052. .dp = dp,
  1053. .vlan = vlan,
  1054. };
  1055. return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, &info);
  1056. }
  1057. int dsa_port_host_vlan_add(struct dsa_port *dp,
  1058. const struct switchdev_obj_port_vlan *vlan,
  1059. struct netlink_ext_ack *extack)
  1060. {
  1061. struct net_device *conduit = dsa_port_to_conduit(dp);
  1062. struct dsa_notifier_vlan_info info = {
  1063. .dp = dp,
  1064. .vlan = vlan,
  1065. .extack = extack,
  1066. };
  1067. int err;
  1068. err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_ADD, &info);
  1069. if (err && err != -EOPNOTSUPP)
  1070. return err;
  1071. vlan_vid_add(conduit, htons(ETH_P_8021Q), vlan->vid);
  1072. return err;
  1073. }
  1074. int dsa_port_host_vlan_del(struct dsa_port *dp,
  1075. const struct switchdev_obj_port_vlan *vlan)
  1076. {
  1077. struct net_device *conduit = dsa_port_to_conduit(dp);
  1078. struct dsa_notifier_vlan_info info = {
  1079. .dp = dp,
  1080. .vlan = vlan,
  1081. };
  1082. int err;
  1083. err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_DEL, &info);
  1084. if (err && err != -EOPNOTSUPP)
  1085. return err;
  1086. vlan_vid_del(conduit, htons(ETH_P_8021Q), vlan->vid);
  1087. return err;
  1088. }
  1089. int dsa_port_mrp_add(const struct dsa_port *dp,
  1090. const struct switchdev_obj_mrp *mrp)
  1091. {
  1092. struct dsa_switch *ds = dp->ds;
  1093. if (!ds->ops->port_mrp_add)
  1094. return -EOPNOTSUPP;
  1095. return ds->ops->port_mrp_add(ds, dp->index, mrp);
  1096. }
  1097. int dsa_port_mrp_del(const struct dsa_port *dp,
  1098. const struct switchdev_obj_mrp *mrp)
  1099. {
  1100. struct dsa_switch *ds = dp->ds;
  1101. if (!ds->ops->port_mrp_del)
  1102. return -EOPNOTSUPP;
  1103. return ds->ops->port_mrp_del(ds, dp->index, mrp);
  1104. }
  1105. int dsa_port_mrp_add_ring_role(const struct dsa_port *dp,
  1106. const struct switchdev_obj_ring_role_mrp *mrp)
  1107. {
  1108. struct dsa_switch *ds = dp->ds;
  1109. if (!ds->ops->port_mrp_add_ring_role)
  1110. return -EOPNOTSUPP;
  1111. return ds->ops->port_mrp_add_ring_role(ds, dp->index, mrp);
  1112. }
  1113. int dsa_port_mrp_del_ring_role(const struct dsa_port *dp,
  1114. const struct switchdev_obj_ring_role_mrp *mrp)
  1115. {
  1116. struct dsa_switch *ds = dp->ds;
  1117. if (!ds->ops->port_mrp_del_ring_role)
  1118. return -EOPNOTSUPP;
  1119. return ds->ops->port_mrp_del_ring_role(ds, dp->index, mrp);
  1120. }
  1121. static int dsa_port_assign_conduit(struct dsa_port *dp,
  1122. struct net_device *conduit,
  1123. struct netlink_ext_ack *extack,
  1124. bool fail_on_err)
  1125. {
  1126. struct dsa_switch *ds = dp->ds;
  1127. int port = dp->index, err;
  1128. err = ds->ops->port_change_conduit(ds, port, conduit, extack);
  1129. if (err && !fail_on_err)
  1130. dev_err(ds->dev, "port %d failed to assign conduit %s: %pe\n",
  1131. port, conduit->name, ERR_PTR(err));
  1132. if (err && fail_on_err)
  1133. return err;
  1134. dp->cpu_dp = conduit->dsa_ptr;
  1135. dp->cpu_port_in_lag = netif_is_lag_master(conduit);
  1136. return 0;
  1137. }
  1138. /* Change the dp->cpu_dp affinity for a user port. Note that both cross-chip
  1139. * notifiers and drivers have implicit assumptions about user-to-CPU-port
  1140. * mappings, so we unfortunately cannot delay the deletion of the objects
  1141. * (switchdev, standalone addresses, standalone VLANs) on the old CPU port
  1142. * until the new CPU port has been set up. So we need to completely tear down
  1143. * the old CPU port before changing it, and restore it on errors during the
  1144. * bringup of the new one.
  1145. */
  1146. int dsa_port_change_conduit(struct dsa_port *dp, struct net_device *conduit,
  1147. struct netlink_ext_ack *extack)
  1148. {
  1149. struct net_device *bridge_dev = dsa_port_bridge_dev_get(dp);
  1150. struct net_device *old_conduit = dsa_port_to_conduit(dp);
  1151. struct net_device *dev = dp->user;
  1152. struct dsa_switch *ds = dp->ds;
  1153. bool vlan_filtering;
  1154. int err, tmp;
  1155. /* Bridges may hold host FDB, MDB and VLAN objects. These need to be
  1156. * migrated, so dynamically unoffload and later reoffload the bridge
  1157. * port.
  1158. */
  1159. if (bridge_dev) {
  1160. dsa_port_pre_bridge_leave(dp, bridge_dev);
  1161. dsa_port_bridge_leave(dp, bridge_dev);
  1162. }
  1163. /* The port might still be VLAN filtering even if it's no longer
  1164. * under a bridge, either due to ds->vlan_filtering_is_global or
  1165. * ds->needs_standalone_vlan_filtering. In turn this means VLANs
  1166. * on the CPU port.
  1167. */
  1168. vlan_filtering = dsa_port_is_vlan_filtering(dp);
  1169. if (vlan_filtering) {
  1170. err = dsa_user_manage_vlan_filtering(dev, false);
  1171. if (err) {
  1172. NL_SET_ERR_MSG_MOD(extack,
  1173. "Failed to remove standalone VLANs");
  1174. goto rewind_old_bridge;
  1175. }
  1176. }
  1177. /* Standalone addresses, and addresses of upper interfaces like
  1178. * VLAN, LAG, HSR need to be migrated.
  1179. */
  1180. dsa_user_unsync_ha(dev);
  1181. /* If live-changing, we also need to uninstall the user device address
  1182. * from the port FDB and the conduit interface.
  1183. */
  1184. if (dev->flags & IFF_UP)
  1185. dsa_user_host_uc_uninstall(dev);
  1186. err = dsa_port_assign_conduit(dp, conduit, extack, true);
  1187. if (err)
  1188. goto rewind_old_addrs;
  1189. /* If the port doesn't have its own MAC address and relies on the DSA
  1190. * conduit's one, inherit it again from the new DSA conduit.
  1191. */
  1192. if (is_zero_ether_addr(dp->mac))
  1193. eth_hw_addr_inherit(dev, conduit);
  1194. /* If live-changing, we need to install the user device address to the
  1195. * port FDB and the conduit interface.
  1196. */
  1197. if (dev->flags & IFF_UP) {
  1198. err = dsa_user_host_uc_install(dev, dev->dev_addr);
  1199. if (err) {
  1200. NL_SET_ERR_MSG_MOD(extack,
  1201. "Failed to install host UC address");
  1202. goto rewind_addr_inherit;
  1203. }
  1204. }
  1205. dsa_user_sync_ha(dev);
  1206. if (vlan_filtering) {
  1207. err = dsa_user_manage_vlan_filtering(dev, true);
  1208. if (err) {
  1209. NL_SET_ERR_MSG_MOD(extack,
  1210. "Failed to restore standalone VLANs");
  1211. goto rewind_new_addrs;
  1212. }
  1213. }
  1214. if (bridge_dev) {
  1215. err = dsa_port_bridge_join(dp, bridge_dev, extack);
  1216. if (err && err == -EOPNOTSUPP) {
  1217. NL_SET_ERR_MSG_MOD(extack,
  1218. "Failed to reoffload bridge");
  1219. goto rewind_new_vlan;
  1220. }
  1221. }
  1222. return 0;
  1223. rewind_new_vlan:
  1224. if (vlan_filtering)
  1225. dsa_user_manage_vlan_filtering(dev, false);
  1226. rewind_new_addrs:
  1227. dsa_user_unsync_ha(dev);
  1228. if (dev->flags & IFF_UP)
  1229. dsa_user_host_uc_uninstall(dev);
  1230. rewind_addr_inherit:
  1231. if (is_zero_ether_addr(dp->mac))
  1232. eth_hw_addr_inherit(dev, old_conduit);
  1233. dsa_port_assign_conduit(dp, old_conduit, NULL, false);
  1234. /* Restore the objects on the old CPU port */
  1235. rewind_old_addrs:
  1236. if (dev->flags & IFF_UP) {
  1237. tmp = dsa_user_host_uc_install(dev, dev->dev_addr);
  1238. if (tmp) {
  1239. dev_err(ds->dev,
  1240. "port %d failed to restore host UC address: %pe\n",
  1241. dp->index, ERR_PTR(tmp));
  1242. }
  1243. }
  1244. dsa_user_sync_ha(dev);
  1245. if (vlan_filtering) {
  1246. tmp = dsa_user_manage_vlan_filtering(dev, true);
  1247. if (tmp) {
  1248. dev_err(ds->dev,
  1249. "port %d failed to restore standalone VLANs: %pe\n",
  1250. dp->index, ERR_PTR(tmp));
  1251. }
  1252. }
  1253. rewind_old_bridge:
  1254. if (bridge_dev) {
  1255. tmp = dsa_port_bridge_join(dp, bridge_dev, extack);
  1256. if (tmp) {
  1257. dev_err(ds->dev,
  1258. "port %d failed to rejoin bridge %s: %pe\n",
  1259. dp->index, bridge_dev->name, ERR_PTR(tmp));
  1260. }
  1261. }
  1262. return err;
  1263. }
  1264. void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp,
  1265. const struct dsa_device_ops *tag_ops)
  1266. {
  1267. cpu_dp->rcv = tag_ops->rcv;
  1268. cpu_dp->tag_ops = tag_ops;
  1269. }
  1270. /* dsa_supports_eee - indicate that EEE is supported
  1271. * @ds: pointer to &struct dsa_switch
  1272. * @port: port index
  1273. *
  1274. * A default implementation for the .support_eee() DSA operations member,
  1275. * which drivers can use to indicate that they support EEE on all of their
  1276. * user ports.
  1277. *
  1278. * Returns: true
  1279. */
  1280. bool dsa_supports_eee(struct dsa_switch *ds, int port)
  1281. {
  1282. return true;
  1283. }
  1284. EXPORT_SYMBOL_GPL(dsa_supports_eee);
  1285. static void dsa_port_phylink_mac_config(struct phylink_config *config,
  1286. unsigned int mode,
  1287. const struct phylink_link_state *state)
  1288. {
  1289. }
  1290. static void dsa_port_phylink_mac_link_down(struct phylink_config *config,
  1291. unsigned int mode,
  1292. phy_interface_t interface)
  1293. {
  1294. }
  1295. static void dsa_port_phylink_mac_link_up(struct phylink_config *config,
  1296. struct phy_device *phydev,
  1297. unsigned int mode,
  1298. phy_interface_t interface,
  1299. int speed, int duplex,
  1300. bool tx_pause, bool rx_pause)
  1301. {
  1302. }
  1303. static const struct phylink_mac_ops dsa_port_phylink_mac_ops = {
  1304. .mac_config = dsa_port_phylink_mac_config,
  1305. .mac_link_down = dsa_port_phylink_mac_link_down,
  1306. .mac_link_up = dsa_port_phylink_mac_link_up,
  1307. };
  1308. int dsa_port_phylink_create(struct dsa_port *dp)
  1309. {
  1310. const struct phylink_mac_ops *mac_ops;
  1311. struct dsa_switch *ds = dp->ds;
  1312. phy_interface_t mode;
  1313. struct phylink *pl;
  1314. int err;
  1315. err = of_get_phy_mode(dp->dn, &mode);
  1316. if (err)
  1317. mode = PHY_INTERFACE_MODE_NA;
  1318. if (ds->ops->phylink_get_caps) {
  1319. ds->ops->phylink_get_caps(ds, dp->index, &dp->pl_config);
  1320. } else {
  1321. /* For legacy drivers */
  1322. if (mode != PHY_INTERFACE_MODE_NA) {
  1323. __set_bit(mode, dp->pl_config.supported_interfaces);
  1324. } else {
  1325. __set_bit(PHY_INTERFACE_MODE_INTERNAL,
  1326. dp->pl_config.supported_interfaces);
  1327. __set_bit(PHY_INTERFACE_MODE_GMII,
  1328. dp->pl_config.supported_interfaces);
  1329. }
  1330. }
  1331. mac_ops = &dsa_port_phylink_mac_ops;
  1332. if (ds->phylink_mac_ops)
  1333. mac_ops = ds->phylink_mac_ops;
  1334. pl = phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn), mode,
  1335. mac_ops);
  1336. if (IS_ERR(pl)) {
  1337. pr_err("error creating PHYLINK: %ld\n", PTR_ERR(pl));
  1338. return PTR_ERR(pl);
  1339. }
  1340. dp->pl = pl;
  1341. return 0;
  1342. }
  1343. void dsa_port_phylink_destroy(struct dsa_port *dp)
  1344. {
  1345. phylink_destroy(dp->pl);
  1346. dp->pl = NULL;
  1347. }
  1348. static int dsa_shared_port_phylink_register(struct dsa_port *dp)
  1349. {
  1350. struct dsa_switch *ds = dp->ds;
  1351. struct device_node *port_dn = dp->dn;
  1352. int err;
  1353. dp->pl_config.dev = ds->dev;
  1354. dp->pl_config.type = PHYLINK_DEV;
  1355. err = dsa_port_phylink_create(dp);
  1356. if (err)
  1357. return err;
  1358. err = phylink_of_phy_connect(dp->pl, port_dn, 0);
  1359. if (err && err != -ENODEV) {
  1360. pr_err("could not attach to PHY: %d\n", err);
  1361. goto err_phy_connect;
  1362. }
  1363. return 0;
  1364. err_phy_connect:
  1365. dsa_port_phylink_destroy(dp);
  1366. return err;
  1367. }
  1368. /* During the initial DSA driver migration to OF, port nodes were sometimes
  1369. * added to device trees with no indication of how they should operate from a
  1370. * link management perspective (phy-handle, fixed-link, etc). Additionally, the
  1371. * phy-mode may be absent. The interpretation of these port OF nodes depends on
  1372. * their type.
  1373. *
  1374. * User ports with no phy-handle or fixed-link are expected to connect to an
  1375. * internal PHY located on the ds->user_mii_bus at an MDIO address equal to
  1376. * the port number. This description is still actively supported.
  1377. *
  1378. * Shared (CPU and DSA) ports with no phy-handle or fixed-link are expected to
  1379. * operate at the maximum speed that their phy-mode is capable of. If the
  1380. * phy-mode is absent, they are expected to operate using the phy-mode
  1381. * supported by the port that gives the highest link speed. It is unspecified
  1382. * if the port should use flow control or not, half duplex or full duplex, or
  1383. * if the phy-mode is a SERDES link, whether in-band autoneg is expected to be
  1384. * enabled or not.
  1385. *
  1386. * In the latter case of shared ports, omitting the link management description
  1387. * from the firmware node is deprecated and strongly discouraged. DSA uses
  1388. * phylink, which rejects the firmware nodes of these ports for lacking
  1389. * required properties.
  1390. *
  1391. * For switches in this table, DSA will skip enforcing validation and will
  1392. * later omit registering a phylink instance for the shared ports, if they lack
  1393. * a fixed-link, a phy-handle, or a managed = "in-band-status" property.
  1394. * It becomes the responsibility of the driver to ensure that these ports
  1395. * operate at the maximum speed (whatever this means) and will interoperate
  1396. * with the DSA conduit or other cascade port, since phylink methods will not be
  1397. * invoked for them.
  1398. *
  1399. * If you are considering expanding this table for newly introduced switches,
  1400. * think again. It is OK to remove switches from this table if there aren't DT
  1401. * blobs in circulation which rely on defaulting the shared ports.
  1402. */
  1403. static const char * const dsa_switches_apply_workarounds[] = {
  1404. #if IS_ENABLED(CONFIG_NET_DSA_XRS700X)
  1405. "arrow,xrs7003e",
  1406. "arrow,xrs7003f",
  1407. "arrow,xrs7004e",
  1408. "arrow,xrs7004f",
  1409. #endif
  1410. #if IS_ENABLED(CONFIG_B53)
  1411. "brcm,bcm5325",
  1412. "brcm,bcm53115",
  1413. "brcm,bcm53125",
  1414. "brcm,bcm53128",
  1415. "brcm,bcm5365",
  1416. "brcm,bcm5389",
  1417. "brcm,bcm5395",
  1418. "brcm,bcm5397",
  1419. "brcm,bcm5398",
  1420. "brcm,bcm53010-srab",
  1421. "brcm,bcm53011-srab",
  1422. "brcm,bcm53012-srab",
  1423. "brcm,bcm53018-srab",
  1424. "brcm,bcm53019-srab",
  1425. "brcm,bcm5301x-srab",
  1426. "brcm,bcm11360-srab",
  1427. "brcm,bcm58522-srab",
  1428. "brcm,bcm58525-srab",
  1429. "brcm,bcm58535-srab",
  1430. "brcm,bcm58622-srab",
  1431. "brcm,bcm58623-srab",
  1432. "brcm,bcm58625-srab",
  1433. "brcm,bcm88312-srab",
  1434. "brcm,cygnus-srab",
  1435. "brcm,nsp-srab",
  1436. "brcm,omega-srab",
  1437. "brcm,bcm3384-switch",
  1438. "brcm,bcm6328-switch",
  1439. "brcm,bcm6368-switch",
  1440. "brcm,bcm63xx-switch",
  1441. #endif
  1442. #if IS_ENABLED(CONFIG_NET_DSA_BCM_SF2)
  1443. "brcm,bcm7445-switch-v4.0",
  1444. "brcm,bcm7278-switch-v4.0",
  1445. "brcm,bcm7278-switch-v4.8",
  1446. #endif
  1447. #if IS_ENABLED(CONFIG_NET_DSA_LANTIQ_GSWIP)
  1448. "lantiq,xrx200-gswip",
  1449. "lantiq,xrx300-gswip",
  1450. "lantiq,xrx330-gswip",
  1451. #endif
  1452. #if IS_ENABLED(CONFIG_NET_DSA_MV88E6060)
  1453. "marvell,mv88e6060",
  1454. #endif
  1455. #if IS_ENABLED(CONFIG_NET_DSA_MV88E6XXX)
  1456. "marvell,mv88e6085",
  1457. "marvell,mv88e6190",
  1458. "marvell,mv88e6250",
  1459. #endif
  1460. #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON)
  1461. "microchip,ksz8765",
  1462. "microchip,ksz8794",
  1463. "microchip,ksz8795",
  1464. "microchip,ksz8863",
  1465. "microchip,ksz8873",
  1466. "microchip,ksz9477",
  1467. "microchip,ksz9897",
  1468. "microchip,ksz9893",
  1469. "microchip,ksz9563",
  1470. "microchip,ksz8563",
  1471. "microchip,ksz9567",
  1472. #endif
  1473. #if IS_ENABLED(CONFIG_NET_DSA_SMSC_LAN9303_MDIO)
  1474. "smsc,lan9303-mdio",
  1475. #endif
  1476. #if IS_ENABLED(CONFIG_NET_DSA_SMSC_LAN9303_I2C)
  1477. "smsc,lan9303-i2c",
  1478. #endif
  1479. NULL,
  1480. };
  1481. static void dsa_shared_port_validate_of(struct dsa_port *dp,
  1482. bool *missing_phy_mode,
  1483. bool *missing_link_description)
  1484. {
  1485. struct device_node *dn = dp->dn, *phy_np;
  1486. struct dsa_switch *ds = dp->ds;
  1487. phy_interface_t mode;
  1488. *missing_phy_mode = false;
  1489. *missing_link_description = false;
  1490. if (of_get_phy_mode(dn, &mode)) {
  1491. *missing_phy_mode = true;
  1492. dev_err(ds->dev,
  1493. "OF node %pOF of %s port %d lacks the required \"phy-mode\" property\n",
  1494. dn, dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index);
  1495. }
  1496. /* Note: of_phy_is_fixed_link() also returns true for
  1497. * managed = "in-band-status"
  1498. */
  1499. if (of_phy_is_fixed_link(dn))
  1500. return;
  1501. phy_np = of_parse_phandle(dn, "phy-handle", 0);
  1502. if (phy_np) {
  1503. of_node_put(phy_np);
  1504. return;
  1505. }
  1506. *missing_link_description = true;
  1507. dev_err(ds->dev,
  1508. "OF node %pOF of %s port %d lacks the required \"phy-handle\", \"fixed-link\" or \"managed\" properties\n",
  1509. dn, dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index);
  1510. }
  1511. static void dsa_shared_port_link_down(struct dsa_port *dp)
  1512. {
  1513. struct dsa_switch *ds = dp->ds;
  1514. if (ds->phylink_mac_ops && ds->phylink_mac_ops->mac_link_down)
  1515. ds->phylink_mac_ops->mac_link_down(&dp->pl_config, MLO_AN_FIXED,
  1516. PHY_INTERFACE_MODE_NA);
  1517. }
  1518. int dsa_shared_port_link_register_of(struct dsa_port *dp)
  1519. {
  1520. struct dsa_switch *ds = dp->ds;
  1521. bool missing_link_description;
  1522. bool missing_phy_mode;
  1523. dsa_shared_port_validate_of(dp, &missing_phy_mode,
  1524. &missing_link_description);
  1525. if ((missing_phy_mode || missing_link_description) &&
  1526. !of_device_compatible_match(ds->dev->of_node,
  1527. dsa_switches_apply_workarounds))
  1528. return -EINVAL;
  1529. if (missing_link_description) {
  1530. dev_warn(ds->dev,
  1531. "Skipping phylink registration for %s port %d\n",
  1532. dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index);
  1533. } else {
  1534. dsa_shared_port_link_down(dp);
  1535. return dsa_shared_port_phylink_register(dp);
  1536. }
  1537. return 0;
  1538. }
  1539. void dsa_shared_port_link_unregister_of(struct dsa_port *dp)
  1540. {
  1541. if (dp->pl) {
  1542. rtnl_lock();
  1543. phylink_disconnect_phy(dp->pl);
  1544. rtnl_unlock();
  1545. dsa_port_phylink_destroy(dp);
  1546. return;
  1547. }
  1548. }
  1549. int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr,
  1550. struct netlink_ext_ack *extack)
  1551. {
  1552. struct dsa_switch *ds = dp->ds;
  1553. int err;
  1554. if (!ds->ops->port_hsr_join)
  1555. return -EOPNOTSUPP;
  1556. dp->hsr_dev = hsr;
  1557. err = ds->ops->port_hsr_join(ds, dp->index, hsr, extack);
  1558. if (err)
  1559. dp->hsr_dev = NULL;
  1560. return err;
  1561. }
  1562. void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr)
  1563. {
  1564. struct dsa_switch *ds = dp->ds;
  1565. int err;
  1566. if (!dp->hsr_dev)
  1567. return;
  1568. dp->hsr_dev = NULL;
  1569. if (ds->ops->port_hsr_leave) {
  1570. err = ds->ops->port_hsr_leave(ds, dp->index, hsr);
  1571. if (err)
  1572. dev_err(dp->ds->dev,
  1573. "port %d failed to leave HSR %s: %pe\n",
  1574. dp->index, hsr->name, ERR_PTR(err));
  1575. }
  1576. }
  1577. int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast)
  1578. {
  1579. struct dsa_notifier_tag_8021q_vlan_info info = {
  1580. .dp = dp,
  1581. .vid = vid,
  1582. };
  1583. if (broadcast)
  1584. return dsa_broadcast(DSA_NOTIFIER_TAG_8021Q_VLAN_ADD, &info);
  1585. return dsa_port_notify(dp, DSA_NOTIFIER_TAG_8021Q_VLAN_ADD, &info);
  1586. }
  1587. void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast)
  1588. {
  1589. struct dsa_notifier_tag_8021q_vlan_info info = {
  1590. .dp = dp,
  1591. .vid = vid,
  1592. };
  1593. int err;
  1594. if (broadcast)
  1595. err = dsa_broadcast(DSA_NOTIFIER_TAG_8021Q_VLAN_DEL, &info);
  1596. else
  1597. err = dsa_port_notify(dp, DSA_NOTIFIER_TAG_8021Q_VLAN_DEL, &info);
  1598. if (err)
  1599. dev_err(dp->ds->dev,
  1600. "port %d failed to notify tag_8021q VLAN %d deletion: %pe\n",
  1601. dp->index, vid, ERR_PTR(err));
  1602. }