dsa2.c 16 KB

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