Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: move rest of devlink setup/teardown to devlink.c

The code that needed further refactoring into dedicated functions in
dsa2.c was left aside. Move it now to devlink.c, and make dsa2.c stop
including net/devlink.h.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
7aea535d d95fa750

+49 -20
+37 -1
net/dsa/devlink.c
··· 167 167 p_max); 168 168 } 169 169 170 - const struct devlink_ops dsa_devlink_ops = { 170 + static const struct devlink_ops dsa_devlink_ops = { 171 171 .info_get = dsa_devlink_info_get, 172 172 .sb_pool_get = dsa_devlink_sb_pool_get, 173 173 .sb_pool_set = dsa_devlink_sb_pool_set, ··· 352 352 ds->ops->port_teardown(ds, dp->index); 353 353 354 354 devlink_port_fini(dlp); 355 + } 356 + 357 + void dsa_switch_devlink_register(struct dsa_switch *ds) 358 + { 359 + devlink_register(ds->devlink); 360 + } 361 + 362 + void dsa_switch_devlink_unregister(struct dsa_switch *ds) 363 + { 364 + devlink_unregister(ds->devlink); 365 + } 366 + 367 + int dsa_switch_devlink_alloc(struct dsa_switch *ds) 368 + { 369 + struct dsa_devlink_priv *dl_priv; 370 + struct devlink *dl; 371 + 372 + /* Add the switch to devlink before calling setup, so that setup can 373 + * add dpipe tables 374 + */ 375 + dl = devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev); 376 + if (!dl) 377 + return -ENOMEM; 378 + 379 + ds->devlink = dl; 380 + 381 + dl_priv = devlink_priv(ds->devlink); 382 + dl_priv->ds = ds; 383 + 384 + return 0; 385 + } 386 + 387 + void dsa_switch_devlink_free(struct dsa_switch *ds) 388 + { 389 + devlink_free(ds->devlink); 390 + ds->devlink = NULL; 355 391 }
+5 -2
net/dsa/devlink.h
··· 4 4 #define __DSA_DEVLINK_H 5 5 6 6 struct dsa_port; 7 - 8 - extern const struct devlink_ops dsa_devlink_ops; 7 + struct dsa_switch; 9 8 10 9 int dsa_port_devlink_setup(struct dsa_port *dp); 11 10 void dsa_port_devlink_teardown(struct dsa_port *dp); 11 + void dsa_switch_devlink_register(struct dsa_switch *ds); 12 + void dsa_switch_devlink_unregister(struct dsa_switch *ds); 13 + int dsa_switch_devlink_alloc(struct dsa_switch *ds); 14 + void dsa_switch_devlink_free(struct dsa_switch *ds); 12 15 13 16 #endif
+7 -17
net/dsa/dsa2.c
··· 15 15 #include <linux/of.h> 16 16 #include <linux/of_mdio.h> 17 17 #include <linux/of_net.h> 18 - #include <net/devlink.h> 19 18 #include <net/sch_generic.h> 20 19 21 20 #include "devlink.h" ··· 626 627 627 628 static int dsa_switch_setup(struct dsa_switch *ds) 628 629 { 629 - struct dsa_devlink_priv *dl_priv; 630 630 struct device_node *dn; 631 631 int err; 632 632 ··· 639 641 */ 640 642 ds->phys_mii_mask |= dsa_user_ports(ds); 641 643 642 - /* Add the switch to devlink before calling setup, so that setup can 643 - * add dpipe tables 644 - */ 645 - ds->devlink = 646 - devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev); 647 - if (!ds->devlink) 648 - return -ENOMEM; 649 - dl_priv = devlink_priv(ds->devlink); 650 - dl_priv->ds = ds; 644 + err = dsa_switch_devlink_alloc(ds); 645 + if (err) 646 + return err; 651 647 652 648 err = dsa_switch_register_notifier(ds); 653 649 if (err) ··· 674 682 goto free_slave_mii_bus; 675 683 } 676 684 677 - devlink_register(ds->devlink); 685 + dsa_switch_devlink_register(ds); 678 686 679 687 ds->setup = true; 680 688 return 0; ··· 688 696 unregister_notifier: 689 697 dsa_switch_unregister_notifier(ds); 690 698 devlink_free: 691 - devlink_free(ds->devlink); 692 - ds->devlink = NULL; 699 + dsa_switch_devlink_free(ds); 693 700 return err; 694 701 } 695 702 ··· 697 706 if (!ds->setup) 698 707 return; 699 708 700 - devlink_unregister(ds->devlink); 709 + dsa_switch_devlink_unregister(ds); 701 710 702 711 if (ds->slave_mii_bus && ds->ops->phy_read) { 703 712 mdiobus_unregister(ds->slave_mii_bus); ··· 712 721 713 722 dsa_switch_unregister_notifier(ds); 714 723 715 - devlink_free(ds->devlink); 716 - ds->devlink = NULL; 724 + dsa_switch_devlink_free(ds); 717 725 718 726 ds->setup = false; 719 727 }