legacy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /*
  2. * net/dsa/legacy.c - Hardware switch handling
  3. * Copyright (c) 2008-2009 Marvell Semiconductor
  4. * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/device.h>
  12. #include <linux/list.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/slab.h>
  15. #include <linux/module.h>
  16. #include <linux/of.h>
  17. #include <linux/of_mdio.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/of_net.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/sysfs.h>
  22. #include <linux/phy_fixed.h>
  23. #include <linux/etherdevice.h>
  24. #include "dsa_priv.h"
  25. /* switch driver registration ***********************************************/
  26. static DEFINE_MUTEX(dsa_switch_drivers_mutex);
  27. static LIST_HEAD(dsa_switch_drivers);
  28. void register_switch_driver(struct dsa_switch_driver *drv)
  29. {
  30. mutex_lock(&dsa_switch_drivers_mutex);
  31. list_add_tail(&drv->list, &dsa_switch_drivers);
  32. mutex_unlock(&dsa_switch_drivers_mutex);
  33. }
  34. EXPORT_SYMBOL_GPL(register_switch_driver);
  35. void unregister_switch_driver(struct dsa_switch_driver *drv)
  36. {
  37. mutex_lock(&dsa_switch_drivers_mutex);
  38. list_del_init(&drv->list);
  39. mutex_unlock(&dsa_switch_drivers_mutex);
  40. }
  41. EXPORT_SYMBOL_GPL(unregister_switch_driver);
  42. static const struct dsa_switch_ops *
  43. dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
  44. const char **_name, void **priv)
  45. {
  46. const struct dsa_switch_ops *ret;
  47. struct list_head *list;
  48. const char *name;
  49. ret = NULL;
  50. name = NULL;
  51. mutex_lock(&dsa_switch_drivers_mutex);
  52. list_for_each(list, &dsa_switch_drivers) {
  53. const struct dsa_switch_ops *ops;
  54. struct dsa_switch_driver *drv;
  55. drv = list_entry(list, struct dsa_switch_driver, list);
  56. ops = drv->ops;
  57. name = ops->probe(parent, host_dev, sw_addr, priv);
  58. if (name != NULL) {
  59. ret = ops;
  60. break;
  61. }
  62. }
  63. mutex_unlock(&dsa_switch_drivers_mutex);
  64. *_name = name;
  65. return ret;
  66. }
  67. /* basic switch operations **************************************************/
  68. static int dsa_cpu_dsa_setups(struct dsa_switch *ds)
  69. {
  70. int ret, port;
  71. for (port = 0; port < ds->num_ports; port++) {
  72. if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
  73. continue;
  74. ret = dsa_cpu_dsa_setup(&ds->ports[port]);
  75. if (ret)
  76. return ret;
  77. }
  78. return 0;
  79. }
  80. static int dsa_switch_setup_one(struct dsa_switch *ds,
  81. struct net_device *master)
  82. {
  83. const struct dsa_switch_ops *ops = ds->ops;
  84. struct dsa_switch_tree *dst = ds->dst;
  85. struct dsa_chip_data *cd = ds->cd;
  86. bool valid_name_found = false;
  87. int index = ds->index;
  88. int i, ret;
  89. /*
  90. * Validate supplied switch configuration.
  91. */
  92. for (i = 0; i < ds->num_ports; i++) {
  93. char *name;
  94. name = cd->port_names[i];
  95. if (name == NULL)
  96. continue;
  97. if (!strcmp(name, "cpu")) {
  98. if (dst->cpu_dp) {
  99. netdev_err(master,
  100. "multiple cpu ports?!\n");
  101. return -EINVAL;
  102. }
  103. dst->cpu_dp = &ds->ports[i];
  104. dst->cpu_dp->netdev = master;
  105. ds->cpu_port_mask |= 1 << i;
  106. } else if (!strcmp(name, "dsa")) {
  107. ds->dsa_port_mask |= 1 << i;
  108. } else {
  109. ds->enabled_port_mask |= 1 << i;
  110. }
  111. valid_name_found = true;
  112. }
  113. if (!valid_name_found && i == ds->num_ports)
  114. return -EINVAL;
  115. /* Make the built-in MII bus mask match the number of ports,
  116. * switch drivers can override this later
  117. */
  118. ds->phys_mii_mask = ds->enabled_port_mask;
  119. /*
  120. * If the CPU connects to this switch, set the switch tree
  121. * tagging protocol to the preferred tagging format of this
  122. * switch.
  123. */
  124. if (dst->cpu_dp->ds == ds) {
  125. const struct dsa_device_ops *tag_ops;
  126. enum dsa_tag_protocol tag_protocol;
  127. tag_protocol = ops->get_tag_protocol(ds);
  128. tag_ops = dsa_resolve_tag_protocol(tag_protocol);
  129. if (IS_ERR(tag_ops))
  130. return PTR_ERR(tag_ops);
  131. dst->cpu_dp->tag_ops = tag_ops;
  132. dst->tag_ops = tag_ops;
  133. /* Few copies for faster access in master receive hot path */
  134. dst->cpu_dp->rcv = dst->cpu_dp->tag_ops->rcv;
  135. dst->rcv = dst->tag_ops->rcv;
  136. dst->cpu_dp->dst = dst;
  137. }
  138. memcpy(ds->rtable, cd->rtable, sizeof(ds->rtable));
  139. /*
  140. * Do basic register setup.
  141. */
  142. ret = ops->setup(ds);
  143. if (ret < 0)
  144. return ret;
  145. ret = dsa_switch_register_notifier(ds);
  146. if (ret)
  147. return ret;
  148. if (ops->set_addr) {
  149. ret = ops->set_addr(ds, master->dev_addr);
  150. if (ret < 0)
  151. return ret;
  152. }
  153. if (!ds->slave_mii_bus && ops->phy_read) {
  154. ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
  155. if (!ds->slave_mii_bus)
  156. return -ENOMEM;
  157. dsa_slave_mii_bus_init(ds);
  158. ret = mdiobus_register(ds->slave_mii_bus);
  159. if (ret < 0)
  160. return ret;
  161. }
  162. /*
  163. * Create network devices for physical switch ports.
  164. */
  165. for (i = 0; i < ds->num_ports; i++) {
  166. ds->ports[i].dn = cd->port_dn[i];
  167. ds->ports[i].cpu_dp = dst->cpu_dp;
  168. if (!(ds->enabled_port_mask & (1 << i)))
  169. continue;
  170. ret = dsa_slave_create(&ds->ports[i], cd->port_names[i]);
  171. if (ret < 0)
  172. netdev_err(master, "[%d]: can't create dsa slave device for port %d(%s): %d\n",
  173. index, i, cd->port_names[i], ret);
  174. }
  175. /* Perform configuration of the CPU and DSA ports */
  176. ret = dsa_cpu_dsa_setups(ds);
  177. if (ret < 0)
  178. netdev_err(master, "[%d] : can't configure CPU and DSA ports\n",
  179. index);
  180. return 0;
  181. }
  182. static struct dsa_switch *
  183. dsa_switch_setup(struct dsa_switch_tree *dst, struct net_device *master,
  184. int index, struct device *parent, struct device *host_dev)
  185. {
  186. struct dsa_chip_data *cd = dst->pd->chip + index;
  187. const struct dsa_switch_ops *ops;
  188. struct dsa_switch *ds;
  189. int ret;
  190. const char *name;
  191. void *priv;
  192. /*
  193. * Probe for switch model.
  194. */
  195. ops = dsa_switch_probe(parent, host_dev, cd->sw_addr, &name, &priv);
  196. if (!ops) {
  197. netdev_err(master, "[%d]: could not detect attached switch\n",
  198. index);
  199. return ERR_PTR(-EINVAL);
  200. }
  201. netdev_info(master, "[%d]: detected a %s switch\n",
  202. index, name);
  203. /*
  204. * Allocate and initialise switch state.
  205. */
  206. ds = dsa_switch_alloc(parent, DSA_MAX_PORTS);
  207. if (!ds)
  208. return ERR_PTR(-ENOMEM);
  209. ds->dst = dst;
  210. ds->index = index;
  211. ds->cd = cd;
  212. ds->ops = ops;
  213. ds->priv = priv;
  214. ret = dsa_switch_setup_one(ds, master);
  215. if (ret)
  216. return ERR_PTR(ret);
  217. return ds;
  218. }
  219. static void dsa_switch_destroy(struct dsa_switch *ds)
  220. {
  221. int port;
  222. /* Destroy network devices for physical switch ports. */
  223. for (port = 0; port < ds->num_ports; port++) {
  224. if (!(ds->enabled_port_mask & (1 << port)))
  225. continue;
  226. if (!ds->ports[port].netdev)
  227. continue;
  228. dsa_slave_destroy(ds->ports[port].netdev);
  229. }
  230. /* Disable configuration of the CPU and DSA ports */
  231. for (port = 0; port < ds->num_ports; port++) {
  232. if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
  233. continue;
  234. dsa_cpu_dsa_destroy(&ds->ports[port]);
  235. /* Clearing a bit which is not set does no harm */
  236. ds->cpu_port_mask |= ~(1 << port);
  237. ds->dsa_port_mask |= ~(1 << port);
  238. }
  239. if (ds->slave_mii_bus && ds->ops->phy_read)
  240. mdiobus_unregister(ds->slave_mii_bus);
  241. dsa_switch_unregister_notifier(ds);
  242. }
  243. /* platform driver init and cleanup *****************************************/
  244. static int dev_is_class(struct device *dev, void *class)
  245. {
  246. if (dev->class != NULL && !strcmp(dev->class->name, class))
  247. return 1;
  248. return 0;
  249. }
  250. static struct device *dev_find_class(struct device *parent, char *class)
  251. {
  252. if (dev_is_class(parent, class)) {
  253. get_device(parent);
  254. return parent;
  255. }
  256. return device_find_child(parent, class, dev_is_class);
  257. }
  258. struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev)
  259. {
  260. struct device *d;
  261. d = dev_find_class(dev, "mdio_bus");
  262. if (d != NULL) {
  263. struct mii_bus *bus;
  264. bus = to_mii_bus(d);
  265. put_device(d);
  266. return bus;
  267. }
  268. return NULL;
  269. }
  270. EXPORT_SYMBOL_GPL(dsa_host_dev_to_mii_bus);
  271. #ifdef CONFIG_OF
  272. static int dsa_of_setup_routing_table(struct dsa_platform_data *pd,
  273. struct dsa_chip_data *cd,
  274. int chip_index, int port_index,
  275. struct device_node *link)
  276. {
  277. const __be32 *reg;
  278. int link_sw_addr;
  279. struct device_node *parent_sw;
  280. int len;
  281. parent_sw = of_get_parent(link);
  282. if (!parent_sw)
  283. return -EINVAL;
  284. reg = of_get_property(parent_sw, "reg", &len);
  285. if (!reg || (len != sizeof(*reg) * 2))
  286. return -EINVAL;
  287. /*
  288. * Get the destination switch number from the second field of its 'reg'
  289. * property, i.e. for "reg = <0x19 1>" sw_addr is '1'.
  290. */
  291. link_sw_addr = be32_to_cpup(reg + 1);
  292. if (link_sw_addr >= pd->nr_chips)
  293. return -EINVAL;
  294. cd->rtable[link_sw_addr] = port_index;
  295. return 0;
  296. }
  297. static int dsa_of_probe_links(struct dsa_platform_data *pd,
  298. struct dsa_chip_data *cd,
  299. int chip_index, int port_index,
  300. struct device_node *port,
  301. const char *port_name)
  302. {
  303. struct device_node *link;
  304. int link_index;
  305. int ret;
  306. for (link_index = 0;; link_index++) {
  307. link = of_parse_phandle(port, "link", link_index);
  308. if (!link)
  309. break;
  310. if (!strcmp(port_name, "dsa") && pd->nr_chips > 1) {
  311. ret = dsa_of_setup_routing_table(pd, cd, chip_index,
  312. port_index, link);
  313. if (ret)
  314. return ret;
  315. }
  316. }
  317. return 0;
  318. }
  319. static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
  320. {
  321. int i;
  322. int port_index;
  323. for (i = 0; i < pd->nr_chips; i++) {
  324. port_index = 0;
  325. while (port_index < DSA_MAX_PORTS) {
  326. kfree(pd->chip[i].port_names[port_index]);
  327. port_index++;
  328. }
  329. /* Drop our reference to the MDIO bus device */
  330. if (pd->chip[i].host_dev)
  331. put_device(pd->chip[i].host_dev);
  332. }
  333. kfree(pd->chip);
  334. }
  335. static int dsa_of_probe(struct device *dev)
  336. {
  337. struct device_node *np = dev->of_node;
  338. struct device_node *child, *mdio, *ethernet, *port;
  339. struct mii_bus *mdio_bus, *mdio_bus_switch;
  340. struct net_device *ethernet_dev;
  341. struct dsa_platform_data *pd;
  342. struct dsa_chip_data *cd;
  343. const char *port_name;
  344. int chip_index, port_index;
  345. const unsigned int *sw_addr, *port_reg;
  346. u32 eeprom_len;
  347. int ret;
  348. mdio = of_parse_phandle(np, "dsa,mii-bus", 0);
  349. if (!mdio)
  350. return -EINVAL;
  351. mdio_bus = of_mdio_find_bus(mdio);
  352. if (!mdio_bus)
  353. return -EPROBE_DEFER;
  354. ethernet = of_parse_phandle(np, "dsa,ethernet", 0);
  355. if (!ethernet) {
  356. ret = -EINVAL;
  357. goto out_put_mdio;
  358. }
  359. ethernet_dev = of_find_net_device_by_node(ethernet);
  360. if (!ethernet_dev) {
  361. ret = -EPROBE_DEFER;
  362. goto out_put_mdio;
  363. }
  364. pd = kzalloc(sizeof(*pd), GFP_KERNEL);
  365. if (!pd) {
  366. ret = -ENOMEM;
  367. goto out_put_ethernet;
  368. }
  369. dev->platform_data = pd;
  370. pd->of_netdev = ethernet_dev;
  371. pd->nr_chips = of_get_available_child_count(np);
  372. if (pd->nr_chips > DSA_MAX_SWITCHES)
  373. pd->nr_chips = DSA_MAX_SWITCHES;
  374. pd->chip = kcalloc(pd->nr_chips, sizeof(struct dsa_chip_data),
  375. GFP_KERNEL);
  376. if (!pd->chip) {
  377. ret = -ENOMEM;
  378. goto out_free;
  379. }
  380. chip_index = -1;
  381. for_each_available_child_of_node(np, child) {
  382. int i;
  383. chip_index++;
  384. cd = &pd->chip[chip_index];
  385. cd->of_node = child;
  386. /* Initialize the routing table */
  387. for (i = 0; i < DSA_MAX_SWITCHES; ++i)
  388. cd->rtable[i] = DSA_RTABLE_NONE;
  389. /* When assigning the host device, increment its refcount */
  390. cd->host_dev = get_device(&mdio_bus->dev);
  391. sw_addr = of_get_property(child, "reg", NULL);
  392. if (!sw_addr)
  393. continue;
  394. cd->sw_addr = be32_to_cpup(sw_addr);
  395. if (cd->sw_addr >= PHY_MAX_ADDR)
  396. continue;
  397. if (!of_property_read_u32(child, "eeprom-length", &eeprom_len))
  398. cd->eeprom_len = eeprom_len;
  399. mdio = of_parse_phandle(child, "mii-bus", 0);
  400. if (mdio) {
  401. mdio_bus_switch = of_mdio_find_bus(mdio);
  402. if (!mdio_bus_switch) {
  403. ret = -EPROBE_DEFER;
  404. goto out_free_chip;
  405. }
  406. /* Drop the mdio_bus device ref, replacing the host
  407. * device with the mdio_bus_switch device, keeping
  408. * the refcount from of_mdio_find_bus() above.
  409. */
  410. put_device(cd->host_dev);
  411. cd->host_dev = &mdio_bus_switch->dev;
  412. }
  413. for_each_available_child_of_node(child, port) {
  414. port_reg = of_get_property(port, "reg", NULL);
  415. if (!port_reg)
  416. continue;
  417. port_index = be32_to_cpup(port_reg);
  418. if (port_index >= DSA_MAX_PORTS)
  419. break;
  420. port_name = of_get_property(port, "label", NULL);
  421. if (!port_name)
  422. continue;
  423. cd->port_dn[port_index] = port;
  424. cd->port_names[port_index] = kstrdup(port_name,
  425. GFP_KERNEL);
  426. if (!cd->port_names[port_index]) {
  427. ret = -ENOMEM;
  428. goto out_free_chip;
  429. }
  430. ret = dsa_of_probe_links(pd, cd, chip_index,
  431. port_index, port, port_name);
  432. if (ret)
  433. goto out_free_chip;
  434. }
  435. }
  436. /* The individual chips hold their own refcount on the mdio bus,
  437. * so drop ours */
  438. put_device(&mdio_bus->dev);
  439. return 0;
  440. out_free_chip:
  441. dsa_of_free_platform_data(pd);
  442. out_free:
  443. kfree(pd);
  444. dev->platform_data = NULL;
  445. out_put_ethernet:
  446. put_device(&ethernet_dev->dev);
  447. out_put_mdio:
  448. put_device(&mdio_bus->dev);
  449. return ret;
  450. }
  451. static void dsa_of_remove(struct device *dev)
  452. {
  453. struct dsa_platform_data *pd = dev->platform_data;
  454. if (!dev->of_node)
  455. return;
  456. dsa_of_free_platform_data(pd);
  457. put_device(&pd->of_netdev->dev);
  458. kfree(pd);
  459. }
  460. #else
  461. static inline int dsa_of_probe(struct device *dev)
  462. {
  463. return 0;
  464. }
  465. static inline void dsa_of_remove(struct device *dev)
  466. {
  467. }
  468. #endif
  469. static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
  470. struct device *parent, struct dsa_platform_data *pd)
  471. {
  472. int i;
  473. unsigned configured = 0;
  474. dst->pd = pd;
  475. for (i = 0; i < pd->nr_chips; i++) {
  476. struct dsa_switch *ds;
  477. ds = dsa_switch_setup(dst, dev, i, parent, pd->chip[i].host_dev);
  478. if (IS_ERR(ds)) {
  479. netdev_err(dev, "[%d]: couldn't create dsa switch instance (error %ld)\n",
  480. i, PTR_ERR(ds));
  481. continue;
  482. }
  483. dst->ds[i] = ds;
  484. ++configured;
  485. }
  486. /*
  487. * If no switch was found, exit cleanly
  488. */
  489. if (!configured)
  490. return -EPROBE_DEFER;
  491. /*
  492. * If we use a tagging format that doesn't have an ethertype
  493. * field, make sure that all packets from this point on get
  494. * sent to the tag format's receive function.
  495. */
  496. wmb();
  497. dev->dsa_ptr = dst->cpu_dp;
  498. return dsa_master_ethtool_setup(dst->cpu_dp->netdev);
  499. }
  500. static int dsa_probe(struct platform_device *pdev)
  501. {
  502. struct dsa_platform_data *pd = pdev->dev.platform_data;
  503. struct net_device *dev;
  504. struct dsa_switch_tree *dst;
  505. int ret;
  506. if (pdev->dev.of_node) {
  507. ret = dsa_of_probe(&pdev->dev);
  508. if (ret)
  509. return ret;
  510. pd = pdev->dev.platform_data;
  511. }
  512. if (pd == NULL || (pd->netdev == NULL && pd->of_netdev == NULL))
  513. return -EINVAL;
  514. if (pd->of_netdev) {
  515. dev = pd->of_netdev;
  516. dev_hold(dev);
  517. } else {
  518. dev = dsa_dev_to_net_device(pd->netdev);
  519. }
  520. if (dev == NULL) {
  521. ret = -EPROBE_DEFER;
  522. goto out;
  523. }
  524. if (dev->dsa_ptr != NULL) {
  525. dev_put(dev);
  526. ret = -EEXIST;
  527. goto out;
  528. }
  529. dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
  530. if (dst == NULL) {
  531. dev_put(dev);
  532. ret = -ENOMEM;
  533. goto out;
  534. }
  535. platform_set_drvdata(pdev, dst);
  536. ret = dsa_setup_dst(dst, dev, &pdev->dev, pd);
  537. if (ret) {
  538. dev_put(dev);
  539. goto out;
  540. }
  541. return 0;
  542. out:
  543. dsa_of_remove(&pdev->dev);
  544. return ret;
  545. }
  546. static void dsa_remove_dst(struct dsa_switch_tree *dst)
  547. {
  548. int i;
  549. dsa_master_ethtool_restore(dst->cpu_dp->netdev);
  550. dst->cpu_dp->netdev->dsa_ptr = NULL;
  551. /* If we used a tagging format that doesn't have an ethertype
  552. * field, make sure that all packets from this point get sent
  553. * without the tag and go through the regular receive path.
  554. */
  555. wmb();
  556. for (i = 0; i < dst->pd->nr_chips; i++) {
  557. struct dsa_switch *ds = dst->ds[i];
  558. if (ds)
  559. dsa_switch_destroy(ds);
  560. }
  561. dev_put(dst->cpu_dp->netdev);
  562. }
  563. static int dsa_remove(struct platform_device *pdev)
  564. {
  565. struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
  566. dsa_remove_dst(dst);
  567. dsa_of_remove(&pdev->dev);
  568. return 0;
  569. }
  570. static void dsa_shutdown(struct platform_device *pdev)
  571. {
  572. }
  573. #ifdef CONFIG_PM_SLEEP
  574. static int dsa_suspend(struct device *d)
  575. {
  576. struct platform_device *pdev = to_platform_device(d);
  577. struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
  578. int i, ret = 0;
  579. for (i = 0; i < dst->pd->nr_chips; i++) {
  580. struct dsa_switch *ds = dst->ds[i];
  581. if (ds != NULL)
  582. ret = dsa_switch_suspend(ds);
  583. }
  584. return ret;
  585. }
  586. static int dsa_resume(struct device *d)
  587. {
  588. struct platform_device *pdev = to_platform_device(d);
  589. struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
  590. int i, ret = 0;
  591. for (i = 0; i < dst->pd->nr_chips; i++) {
  592. struct dsa_switch *ds = dst->ds[i];
  593. if (ds != NULL)
  594. ret = dsa_switch_resume(ds);
  595. }
  596. return ret;
  597. }
  598. #endif
  599. /* legacy way, bypassing the bridge *****************************************/
  600. int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  601. struct net_device *dev,
  602. const unsigned char *addr, u16 vid,
  603. u16 flags)
  604. {
  605. struct dsa_slave_priv *p = netdev_priv(dev);
  606. struct dsa_port *dp = p->dp;
  607. return dsa_port_fdb_add(dp, addr, vid);
  608. }
  609. int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
  610. struct net_device *dev,
  611. const unsigned char *addr, u16 vid)
  612. {
  613. struct dsa_slave_priv *p = netdev_priv(dev);
  614. struct dsa_port *dp = p->dp;
  615. return dsa_port_fdb_del(dp, addr, vid);
  616. }
  617. static SIMPLE_DEV_PM_OPS(dsa_pm_ops, dsa_suspend, dsa_resume);
  618. static const struct of_device_id dsa_of_match_table[] = {
  619. { .compatible = "marvell,dsa", },
  620. {}
  621. };
  622. MODULE_DEVICE_TABLE(of, dsa_of_match_table);
  623. static struct platform_driver dsa_driver = {
  624. .probe = dsa_probe,
  625. .remove = dsa_remove,
  626. .shutdown = dsa_shutdown,
  627. .driver = {
  628. .name = "dsa",
  629. .of_match_table = dsa_of_match_table,
  630. .pm = &dsa_pm_ops,
  631. },
  632. };
  633. int dsa_legacy_register(void)
  634. {
  635. return platform_driver_register(&dsa_driver);
  636. }
  637. void dsa_legacy_unregister(void)
  638. {
  639. platform_driver_unregister(&dsa_driver);
  640. }