dsa2.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. /*
  2. * net/dsa/dsa2.c - Hardware switch handling, binding version 2
  3. * Copyright (c) 2008-2009 Marvell Semiconductor
  4. * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
  5. * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/err.h>
  14. #include <linux/list.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/slab.h>
  17. #include <linux/rtnetlink.h>
  18. #include <linux/of.h>
  19. #include <linux/of_net.h>
  20. #include <net/dsa.h>
  21. #include "dsa_priv.h"
  22. static LIST_HEAD(dsa_switch_trees);
  23. static DEFINE_MUTEX(dsa2_mutex);
  24. static struct dsa_switch_tree *dsa_get_dst(u32 tree)
  25. {
  26. struct dsa_switch_tree *dst;
  27. list_for_each_entry(dst, &dsa_switch_trees, list)
  28. if (dst->tree == tree) {
  29. kref_get(&dst->refcount);
  30. return dst;
  31. }
  32. return NULL;
  33. }
  34. static void dsa_free_dst(struct kref *ref)
  35. {
  36. struct dsa_switch_tree *dst = container_of(ref, struct dsa_switch_tree,
  37. refcount);
  38. list_del(&dst->list);
  39. kfree(dst);
  40. }
  41. static void dsa_put_dst(struct dsa_switch_tree *dst)
  42. {
  43. kref_put(&dst->refcount, dsa_free_dst);
  44. }
  45. static struct dsa_switch_tree *dsa_add_dst(u32 tree)
  46. {
  47. struct dsa_switch_tree *dst;
  48. dst = kzalloc(sizeof(*dst), GFP_KERNEL);
  49. if (!dst)
  50. return NULL;
  51. dst->tree = tree;
  52. INIT_LIST_HEAD(&dst->list);
  53. list_add_tail(&dsa_switch_trees, &dst->list);
  54. kref_init(&dst->refcount);
  55. return dst;
  56. }
  57. static void dsa_dst_add_ds(struct dsa_switch_tree *dst,
  58. struct dsa_switch *ds, u32 index)
  59. {
  60. kref_get(&dst->refcount);
  61. dst->ds[index] = ds;
  62. }
  63. static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
  64. struct dsa_switch *ds, u32 index)
  65. {
  66. dst->ds[index] = NULL;
  67. kref_put(&dst->refcount, dsa_free_dst);
  68. }
  69. /* For platform data configurations, we need to have a valid name argument to
  70. * differentiate a disabled port from an enabled one
  71. */
  72. static bool dsa_port_is_valid(struct dsa_port *port)
  73. {
  74. return !!(port->dn || port->name);
  75. }
  76. static bool dsa_port_is_dsa(struct dsa_port *port)
  77. {
  78. if (port->name && !strcmp(port->name, "dsa"))
  79. return true;
  80. else
  81. return !!of_parse_phandle(port->dn, "link", 0);
  82. }
  83. static bool dsa_port_is_cpu(struct dsa_port *port)
  84. {
  85. if (port->name && !strcmp(port->name, "cpu"))
  86. return true;
  87. else
  88. return !!of_parse_phandle(port->dn, "ethernet", 0);
  89. }
  90. static bool dsa_ds_find_port_dn(struct dsa_switch *ds,
  91. struct device_node *port)
  92. {
  93. u32 index;
  94. for (index = 0; index < ds->num_ports; index++)
  95. if (ds->ports[index].dn == port)
  96. return true;
  97. return false;
  98. }
  99. static struct dsa_switch *dsa_dst_find_port_dn(struct dsa_switch_tree *dst,
  100. struct device_node *port)
  101. {
  102. struct dsa_switch *ds;
  103. u32 index;
  104. for (index = 0; index < DSA_MAX_SWITCHES; index++) {
  105. ds = dst->ds[index];
  106. if (!ds)
  107. continue;
  108. if (dsa_ds_find_port_dn(ds, port))
  109. return ds;
  110. }
  111. return NULL;
  112. }
  113. static int dsa_port_complete(struct dsa_switch_tree *dst,
  114. struct dsa_switch *src_ds,
  115. struct dsa_port *port,
  116. u32 src_port)
  117. {
  118. struct device_node *link;
  119. int index;
  120. struct dsa_switch *dst_ds;
  121. for (index = 0;; index++) {
  122. link = of_parse_phandle(port->dn, "link", index);
  123. if (!link)
  124. break;
  125. dst_ds = dsa_dst_find_port_dn(dst, link);
  126. of_node_put(link);
  127. if (!dst_ds)
  128. return 1;
  129. src_ds->rtable[dst_ds->index] = src_port;
  130. }
  131. return 0;
  132. }
  133. /* A switch is complete if all the DSA ports phandles point to ports
  134. * known in the tree. A return value of 1 means the tree is not
  135. * complete. This is not an error condition. A value of 0 is
  136. * success.
  137. */
  138. static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds)
  139. {
  140. struct dsa_port *port;
  141. u32 index;
  142. int err;
  143. for (index = 0; index < ds->num_ports; index++) {
  144. port = &ds->ports[index];
  145. if (!dsa_port_is_valid(port))
  146. continue;
  147. if (!dsa_port_is_dsa(port))
  148. continue;
  149. err = dsa_port_complete(dst, ds, port, index);
  150. if (err != 0)
  151. return err;
  152. ds->dsa_port_mask |= BIT(index);
  153. }
  154. return 0;
  155. }
  156. /* A tree is complete if all the DSA ports phandles point to ports
  157. * known in the tree. A return value of 1 means the tree is not
  158. * complete. This is not an error condition. A value of 0 is
  159. * success.
  160. */
  161. static int dsa_dst_complete(struct dsa_switch_tree *dst)
  162. {
  163. struct dsa_switch *ds;
  164. u32 index;
  165. int err;
  166. for (index = 0; index < DSA_MAX_SWITCHES; index++) {
  167. ds = dst->ds[index];
  168. if (!ds)
  169. continue;
  170. err = dsa_ds_complete(dst, ds);
  171. if (err != 0)
  172. return err;
  173. }
  174. return 0;
  175. }
  176. static int dsa_dsa_port_apply(struct dsa_port *port, u32 index,
  177. struct dsa_switch *ds)
  178. {
  179. int err;
  180. err = dsa_cpu_dsa_setup(ds, ds->dev, port, index);
  181. if (err) {
  182. dev_warn(ds->dev, "Failed to setup dsa port %d: %d\n",
  183. index, err);
  184. return err;
  185. }
  186. return 0;
  187. }
  188. static void dsa_dsa_port_unapply(struct dsa_port *port, u32 index,
  189. struct dsa_switch *ds)
  190. {
  191. dsa_cpu_dsa_destroy(port);
  192. }
  193. static int dsa_cpu_port_apply(struct dsa_port *port, u32 index,
  194. struct dsa_switch *ds)
  195. {
  196. int err;
  197. err = dsa_cpu_dsa_setup(ds, ds->dev, port, index);
  198. if (err) {
  199. dev_warn(ds->dev, "Failed to setup cpu port %d: %d\n",
  200. index, err);
  201. return err;
  202. }
  203. ds->cpu_port_mask |= BIT(index);
  204. return 0;
  205. }
  206. static void dsa_cpu_port_unapply(struct dsa_port *port, u32 index,
  207. struct dsa_switch *ds)
  208. {
  209. dsa_cpu_dsa_destroy(port);
  210. ds->cpu_port_mask &= ~BIT(index);
  211. }
  212. static int dsa_user_port_apply(struct dsa_port *port, u32 index,
  213. struct dsa_switch *ds)
  214. {
  215. const char *name = port->name;
  216. int err;
  217. if (port->dn)
  218. name = of_get_property(port->dn, "label", NULL);
  219. if (!name)
  220. name = "eth%d";
  221. err = dsa_slave_create(ds, ds->dev, index, name);
  222. if (err) {
  223. dev_warn(ds->dev, "Failed to create slave %d: %d\n",
  224. index, err);
  225. ds->ports[index].netdev = NULL;
  226. return err;
  227. }
  228. return 0;
  229. }
  230. static void dsa_user_port_unapply(struct dsa_port *port, u32 index,
  231. struct dsa_switch *ds)
  232. {
  233. if (ds->ports[index].netdev) {
  234. dsa_slave_destroy(ds->ports[index].netdev);
  235. ds->ports[index].netdev = NULL;
  236. ds->enabled_port_mask &= ~(1 << index);
  237. }
  238. }
  239. static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
  240. {
  241. struct dsa_port *port;
  242. u32 index;
  243. int err;
  244. /* Initialize ds->phys_mii_mask before registering the slave MDIO bus
  245. * driver and before ops->setup() has run, since the switch drivers and
  246. * the slave MDIO bus driver rely on these values for probing PHY
  247. * devices or not
  248. */
  249. ds->phys_mii_mask = ds->enabled_port_mask;
  250. err = ds->ops->setup(ds);
  251. if (err < 0)
  252. return err;
  253. err = dsa_switch_register_notifier(ds);
  254. if (err)
  255. return err;
  256. if (ds->ops->set_addr) {
  257. err = ds->ops->set_addr(ds, dst->master_netdev->dev_addr);
  258. if (err < 0)
  259. return err;
  260. }
  261. if (!ds->slave_mii_bus && ds->ops->phy_read) {
  262. ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
  263. if (!ds->slave_mii_bus)
  264. return -ENOMEM;
  265. dsa_slave_mii_bus_init(ds);
  266. err = mdiobus_register(ds->slave_mii_bus);
  267. if (err < 0)
  268. return err;
  269. }
  270. for (index = 0; index < ds->num_ports; index++) {
  271. port = &ds->ports[index];
  272. if (!dsa_port_is_valid(port))
  273. continue;
  274. if (dsa_port_is_dsa(port)) {
  275. err = dsa_dsa_port_apply(port, index, ds);
  276. if (err)
  277. return err;
  278. continue;
  279. }
  280. if (dsa_port_is_cpu(port)) {
  281. err = dsa_cpu_port_apply(port, index, ds);
  282. if (err)
  283. return err;
  284. continue;
  285. }
  286. err = dsa_user_port_apply(port, index, ds);
  287. if (err)
  288. continue;
  289. }
  290. return 0;
  291. }
  292. static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
  293. {
  294. struct dsa_port *port;
  295. u32 index;
  296. for (index = 0; index < ds->num_ports; index++) {
  297. port = &ds->ports[index];
  298. if (!dsa_port_is_valid(port))
  299. continue;
  300. if (dsa_port_is_dsa(port)) {
  301. dsa_dsa_port_unapply(port, index, ds);
  302. continue;
  303. }
  304. if (dsa_port_is_cpu(port)) {
  305. dsa_cpu_port_unapply(port, index, ds);
  306. continue;
  307. }
  308. dsa_user_port_unapply(port, index, ds);
  309. }
  310. if (ds->slave_mii_bus && ds->ops->phy_read)
  311. mdiobus_unregister(ds->slave_mii_bus);
  312. dsa_switch_unregister_notifier(ds);
  313. }
  314. static int dsa_dst_apply(struct dsa_switch_tree *dst)
  315. {
  316. struct dsa_switch *ds;
  317. u32 index;
  318. int err;
  319. for (index = 0; index < DSA_MAX_SWITCHES; index++) {
  320. ds = dst->ds[index];
  321. if (!ds)
  322. continue;
  323. err = dsa_ds_apply(dst, ds);
  324. if (err)
  325. return err;
  326. }
  327. if (dst->cpu_switch) {
  328. err = dsa_cpu_port_ethtool_setup(dst->cpu_switch);
  329. if (err)
  330. return err;
  331. }
  332. /* If we use a tagging format that doesn't have an ethertype
  333. * field, make sure that all packets from this point on get
  334. * sent to the tag format's receive function.
  335. */
  336. wmb();
  337. dst->master_netdev->dsa_ptr = (void *)dst;
  338. dst->applied = true;
  339. return 0;
  340. }
  341. static void dsa_dst_unapply(struct dsa_switch_tree *dst)
  342. {
  343. struct dsa_switch *ds;
  344. u32 index;
  345. if (!dst->applied)
  346. return;
  347. dst->master_netdev->dsa_ptr = NULL;
  348. /* If we used a tagging format that doesn't have an ethertype
  349. * field, make sure that all packets from this point get sent
  350. * without the tag and go through the regular receive path.
  351. */
  352. wmb();
  353. for (index = 0; index < DSA_MAX_SWITCHES; index++) {
  354. ds = dst->ds[index];
  355. if (!ds)
  356. continue;
  357. dsa_ds_unapply(dst, ds);
  358. }
  359. if (dst->cpu_switch)
  360. dsa_cpu_port_ethtool_restore(dst->cpu_switch);
  361. pr_info("DSA: tree %d unapplied\n", dst->tree);
  362. dst->applied = false;
  363. }
  364. static int dsa_cpu_parse(struct dsa_port *port, u32 index,
  365. struct dsa_switch_tree *dst,
  366. struct dsa_switch *ds)
  367. {
  368. enum dsa_tag_protocol tag_protocol;
  369. struct net_device *ethernet_dev;
  370. struct device_node *ethernet;
  371. if (port->dn) {
  372. ethernet = of_parse_phandle(port->dn, "ethernet", 0);
  373. if (!ethernet)
  374. return -EINVAL;
  375. ethernet_dev = of_find_net_device_by_node(ethernet);
  376. } else {
  377. ethernet_dev = dsa_dev_to_net_device(ds->cd->netdev[index]);
  378. dev_put(ethernet_dev);
  379. }
  380. if (!ethernet_dev)
  381. return -EPROBE_DEFER;
  382. if (!ds->master_netdev)
  383. ds->master_netdev = ethernet_dev;
  384. if (!dst->master_netdev)
  385. dst->master_netdev = ethernet_dev;
  386. if (!dst->cpu_switch) {
  387. dst->cpu_switch = ds;
  388. dst->cpu_port = index;
  389. }
  390. tag_protocol = ds->ops->get_tag_protocol(ds);
  391. dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
  392. if (IS_ERR(dst->tag_ops)) {
  393. dev_warn(ds->dev, "No tagger for this switch\n");
  394. return PTR_ERR(dst->tag_ops);
  395. }
  396. dst->rcv = dst->tag_ops->rcv;
  397. return 0;
  398. }
  399. static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
  400. {
  401. struct dsa_port *port;
  402. u32 index;
  403. int err;
  404. for (index = 0; index < ds->num_ports; index++) {
  405. port = &ds->ports[index];
  406. if (!dsa_port_is_valid(port))
  407. continue;
  408. if (dsa_port_is_cpu(port)) {
  409. err = dsa_cpu_parse(port, index, dst, ds);
  410. if (err)
  411. return err;
  412. }
  413. }
  414. pr_info("DSA: switch %d %d parsed\n", dst->tree, ds->index);
  415. return 0;
  416. }
  417. static int dsa_dst_parse(struct dsa_switch_tree *dst)
  418. {
  419. struct dsa_switch *ds;
  420. u32 index;
  421. int err;
  422. for (index = 0; index < DSA_MAX_SWITCHES; index++) {
  423. ds = dst->ds[index];
  424. if (!ds)
  425. continue;
  426. err = dsa_ds_parse(dst, ds);
  427. if (err)
  428. return err;
  429. }
  430. if (!dst->master_netdev) {
  431. pr_warn("Tree has no master device\n");
  432. return -EINVAL;
  433. }
  434. pr_info("DSA: tree %d parsed\n", dst->tree);
  435. return 0;
  436. }
  437. static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
  438. {
  439. struct device_node *port;
  440. int err;
  441. u32 reg;
  442. for_each_available_child_of_node(ports, port) {
  443. err = of_property_read_u32(port, "reg", &reg);
  444. if (err)
  445. return err;
  446. if (reg >= ds->num_ports)
  447. return -EINVAL;
  448. ds->ports[reg].dn = port;
  449. /* Initialize enabled_port_mask now for ops->setup()
  450. * to have access to a correct value, just like what
  451. * net/dsa/dsa.c::dsa_switch_setup_one does.
  452. */
  453. if (!dsa_port_is_cpu(&ds->ports[reg]))
  454. ds->enabled_port_mask |= 1 << reg;
  455. }
  456. return 0;
  457. }
  458. static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
  459. {
  460. bool valid_name_found = false;
  461. unsigned int i;
  462. for (i = 0; i < DSA_MAX_PORTS; i++) {
  463. if (!cd->port_names[i])
  464. continue;
  465. ds->ports[i].name = cd->port_names[i];
  466. /* Initialize enabled_port_mask now for drv->setup()
  467. * to have access to a correct value, just like what
  468. * net/dsa/dsa.c::dsa_switch_setup_one does.
  469. */
  470. if (!dsa_port_is_cpu(&ds->ports[i]))
  471. ds->enabled_port_mask |= 1 << i;
  472. valid_name_found = true;
  473. }
  474. if (!valid_name_found && i == DSA_MAX_PORTS)
  475. return -EINVAL;
  476. return 0;
  477. }
  478. static int dsa_parse_member_dn(struct device_node *np, u32 *tree, u32 *index)
  479. {
  480. int err;
  481. *tree = *index = 0;
  482. err = of_property_read_u32_index(np, "dsa,member", 0, tree);
  483. if (err) {
  484. /* Does not exist, but it is optional */
  485. if (err == -EINVAL)
  486. return 0;
  487. return err;
  488. }
  489. err = of_property_read_u32_index(np, "dsa,member", 1, index);
  490. if (err)
  491. return err;
  492. if (*index >= DSA_MAX_SWITCHES)
  493. return -EINVAL;
  494. return 0;
  495. }
  496. static int dsa_parse_member(struct dsa_chip_data *pd, u32 *tree, u32 *index)
  497. {
  498. if (!pd)
  499. return -ENODEV;
  500. /* We do not support complex trees with dsa_chip_data */
  501. *tree = 0;
  502. *index = 0;
  503. return 0;
  504. }
  505. static struct device_node *dsa_get_ports(struct dsa_switch *ds,
  506. struct device_node *np)
  507. {
  508. struct device_node *ports;
  509. ports = of_get_child_by_name(np, "ports");
  510. if (!ports) {
  511. dev_err(ds->dev, "no ports child node found\n");
  512. return ERR_PTR(-EINVAL);
  513. }
  514. return ports;
  515. }
  516. static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev)
  517. {
  518. struct dsa_chip_data *pdata = dev->platform_data;
  519. struct device_node *np = dev->of_node;
  520. struct dsa_switch_tree *dst;
  521. struct device_node *ports;
  522. u32 tree, index;
  523. int i, err;
  524. if (np) {
  525. err = dsa_parse_member_dn(np, &tree, &index);
  526. if (err)
  527. return err;
  528. ports = dsa_get_ports(ds, np);
  529. if (IS_ERR(ports))
  530. return PTR_ERR(ports);
  531. err = dsa_parse_ports_dn(ports, ds);
  532. if (err)
  533. return err;
  534. } else {
  535. err = dsa_parse_member(pdata, &tree, &index);
  536. if (err)
  537. return err;
  538. err = dsa_parse_ports(pdata, ds);
  539. if (err)
  540. return err;
  541. }
  542. dst = dsa_get_dst(tree);
  543. if (!dst) {
  544. dst = dsa_add_dst(tree);
  545. if (!dst)
  546. return -ENOMEM;
  547. }
  548. if (dst->ds[index]) {
  549. err = -EBUSY;
  550. goto out;
  551. }
  552. ds->dst = dst;
  553. ds->index = index;
  554. ds->cd = pdata;
  555. /* Initialize the routing table */
  556. for (i = 0; i < DSA_MAX_SWITCHES; ++i)
  557. ds->rtable[i] = DSA_RTABLE_NONE;
  558. dsa_dst_add_ds(dst, ds, index);
  559. err = dsa_dst_complete(dst);
  560. if (err < 0)
  561. goto out_del_dst;
  562. if (err == 1) {
  563. /* Not all switches registered yet */
  564. err = 0;
  565. goto out;
  566. }
  567. if (dst->applied) {
  568. pr_info("DSA: Disjoint trees?\n");
  569. return -EINVAL;
  570. }
  571. err = dsa_dst_parse(dst);
  572. if (err) {
  573. if (err == -EPROBE_DEFER) {
  574. dsa_dst_del_ds(dst, ds, ds->index);
  575. return err;
  576. }
  577. goto out_del_dst;
  578. }
  579. err = dsa_dst_apply(dst);
  580. if (err) {
  581. dsa_dst_unapply(dst);
  582. goto out_del_dst;
  583. }
  584. dsa_put_dst(dst);
  585. return 0;
  586. out_del_dst:
  587. dsa_dst_del_ds(dst, ds, ds->index);
  588. out:
  589. dsa_put_dst(dst);
  590. return err;
  591. }
  592. struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n)
  593. {
  594. size_t size = sizeof(struct dsa_switch) + n * sizeof(struct dsa_port);
  595. struct dsa_switch *ds;
  596. int i;
  597. ds = devm_kzalloc(dev, size, GFP_KERNEL);
  598. if (!ds)
  599. return NULL;
  600. ds->dev = dev;
  601. ds->num_ports = n;
  602. for (i = 0; i < ds->num_ports; ++i) {
  603. ds->ports[i].index = i;
  604. ds->ports[i].ds = ds;
  605. }
  606. return ds;
  607. }
  608. EXPORT_SYMBOL_GPL(dsa_switch_alloc);
  609. int dsa_register_switch(struct dsa_switch *ds, struct device *dev)
  610. {
  611. int err;
  612. mutex_lock(&dsa2_mutex);
  613. err = _dsa_register_switch(ds, dev);
  614. mutex_unlock(&dsa2_mutex);
  615. return err;
  616. }
  617. EXPORT_SYMBOL_GPL(dsa_register_switch);
  618. static void _dsa_unregister_switch(struct dsa_switch *ds)
  619. {
  620. struct dsa_switch_tree *dst = ds->dst;
  621. dsa_dst_unapply(dst);
  622. dsa_dst_del_ds(dst, ds, ds->index);
  623. }
  624. void dsa_unregister_switch(struct dsa_switch *ds)
  625. {
  626. mutex_lock(&dsa2_mutex);
  627. _dsa_unregister_switch(ds);
  628. mutex_unlock(&dsa2_mutex);
  629. }
  630. EXPORT_SYMBOL_GPL(dsa_unregister_switch);