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

Merge branch 'user_mii_bus-cleanup-part-one'

Vladimir Oltean says:

====================
ds->user_mii_bus cleanup (part 1)

There are some drivers which assign ds->user_mii_bus when they
don't really need its specific functionality, aka non-OF based
dsa_user_phy_connect(). There was some confusion regarding the
fact that yes, this is why ds->user_mii_bus really exists, so
I've started a cleanup series which aims to eliminate the usage
of ds->user_mii_bus from drivers when there is nothing to gain
from it.

Today's drivers are lantiq_gswip, qca8k and bcm_sf2. The work is
not done here, but a "part 2" may or may not come, depending on
other priorities.

All patches were only compile-tested.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+68 -64
+3 -4
drivers/net/dsa/bcm_sf2.c
··· 621 621 goto err_of_node_put; 622 622 } 623 623 624 - priv->master_mii_dn = dn; 625 - 626 624 priv->user_mii_bus = mdiobus_alloc(); 627 625 if (!priv->user_mii_bus) { 628 626 err = -ENOMEM; ··· 633 635 priv->user_mii_bus->write = bcm_sf2_sw_mdio_write; 634 636 snprintf(priv->user_mii_bus->id, MII_BUS_ID_SIZE, "sf2-%d", 635 637 index++); 636 - priv->user_mii_bus->dev.of_node = dn; 637 638 638 639 /* Include the pseudo-PHY address to divert reads towards our 639 640 * workaround. This is only required for 7445D0, since 7445E0 ··· 680 683 } 681 684 682 685 err = mdiobus_register(priv->user_mii_bus); 683 - if (err && dn) 686 + if (err) 684 687 goto err_free_user_mii_bus; 688 + 689 + of_node_put(dn); 685 690 686 691 return 0; 687 692
-1
drivers/net/dsa/bcm_sf2.h
··· 107 107 108 108 /* Master and slave MDIO bus controller */ 109 109 unsigned int indir_phy_mask; 110 - struct device_node *master_mii_dn; 111 110 struct mii_bus *user_mii_bus; 112 111 struct mii_bus *master_mii_bus; 113 112
+32 -40
drivers/net/dsa/lantiq_gswip.c
··· 505 505 return gswip_mdio_r(priv, GSWIP_MDIO_READ); 506 506 } 507 507 508 - static int gswip_mdio(struct gswip_priv *priv, struct device_node *mdio_np) 508 + static int gswip_mdio(struct gswip_priv *priv) 509 509 { 510 - struct dsa_switch *ds = priv->ds; 511 - int err; 510 + struct device_node *mdio_np, *switch_np = priv->dev->of_node; 511 + struct device *dev = priv->dev; 512 + struct mii_bus *bus; 513 + int err = 0; 512 514 513 - ds->user_mii_bus = mdiobus_alloc(); 514 - if (!ds->user_mii_bus) 515 - return -ENOMEM; 515 + mdio_np = of_get_compatible_child(switch_np, "lantiq,xrx200-mdio"); 516 + if (!of_device_is_available(mdio_np)) 517 + goto out_put_node; 516 518 517 - ds->user_mii_bus->priv = priv; 518 - ds->user_mii_bus->read = gswip_mdio_rd; 519 - ds->user_mii_bus->write = gswip_mdio_wr; 520 - ds->user_mii_bus->name = "lantiq,xrx200-mdio"; 521 - snprintf(ds->user_mii_bus->id, MII_BUS_ID_SIZE, "%s-mii", 522 - dev_name(priv->dev)); 523 - ds->user_mii_bus->parent = priv->dev; 524 - ds->user_mii_bus->phy_mask = ~ds->phys_mii_mask; 519 + bus = devm_mdiobus_alloc(dev); 520 + if (!bus) { 521 + err = -ENOMEM; 522 + goto out_put_node; 523 + } 525 524 526 - err = of_mdiobus_register(ds->user_mii_bus, mdio_np); 527 - if (err) 528 - mdiobus_free(ds->user_mii_bus); 525 + bus->priv = priv; 526 + bus->read = gswip_mdio_rd; 527 + bus->write = gswip_mdio_wr; 528 + bus->name = "lantiq,xrx200-mdio"; 529 + snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(priv->dev)); 530 + bus->parent = priv->dev; 531 + 532 + err = devm_of_mdiobus_register(dev, bus, mdio_np); 533 + 534 + out_put_node: 535 + of_node_put(mdio_np); 529 536 530 537 return err; 531 538 } ··· 2101 2094 2102 2095 static int gswip_probe(struct platform_device *pdev) 2103 2096 { 2104 - struct gswip_priv *priv; 2105 - struct device_node *np, *mdio_np, *gphy_fw_np; 2097 + struct device_node *np, *gphy_fw_np; 2106 2098 struct device *dev = &pdev->dev; 2099 + struct gswip_priv *priv; 2107 2100 int err; 2108 2101 int i; 2109 2102 u32 version; ··· 2170 2163 } 2171 2164 2172 2165 /* bring up the mdio bus */ 2173 - mdio_np = of_get_compatible_child(dev->of_node, "lantiq,xrx200-mdio"); 2174 - if (mdio_np) { 2175 - err = gswip_mdio(priv, mdio_np); 2176 - if (err) { 2177 - dev_err(dev, "mdio probe failed\n"); 2178 - goto put_mdio_node; 2179 - } 2166 + err = gswip_mdio(priv); 2167 + if (err) { 2168 + dev_err(dev, "mdio probe failed\n"); 2169 + goto gphy_fw_remove; 2180 2170 } 2181 2171 2182 2172 err = dsa_register_switch(priv->ds); 2183 2173 if (err) { 2184 2174 dev_err(dev, "dsa switch register failed: %i\n", err); 2185 - goto mdio_bus; 2175 + goto gphy_fw_remove; 2186 2176 } 2187 2177 if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) { 2188 2178 dev_err(dev, "wrong CPU port defined, HW only supports port: %i", ··· 2198 2194 disable_switch: 2199 2195 gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); 2200 2196 dsa_unregister_switch(priv->ds); 2201 - mdio_bus: 2202 - if (mdio_np) { 2203 - mdiobus_unregister(priv->ds->user_mii_bus); 2204 - mdiobus_free(priv->ds->user_mii_bus); 2205 - } 2206 - put_mdio_node: 2207 - of_node_put(mdio_np); 2197 + gphy_fw_remove: 2208 2198 for (i = 0; i < priv->num_gphy_fw; i++) 2209 2199 gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); 2210 2200 return err; ··· 2216 2218 gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); 2217 2219 2218 2220 dsa_unregister_switch(priv->ds); 2219 - 2220 - if (priv->ds->user_mii_bus) { 2221 - mdiobus_unregister(priv->ds->user_mii_bus); 2222 - of_node_put(priv->ds->user_mii_bus->dev.of_node); 2223 - mdiobus_free(priv->ds->user_mii_bus); 2224 - } 2225 2221 2226 2222 for (i = 0; i < priv->num_gphy_fw; i++) 2227 2223 gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
+30 -17
drivers/net/dsa/qca/qca8k-8xxx.c
··· 947 947 qca8k_mdio_register(struct qca8k_priv *priv) 948 948 { 949 949 struct dsa_switch *ds = priv->ds; 950 + struct device *dev = ds->dev; 950 951 struct device_node *mdio; 951 952 struct mii_bus *bus; 953 + int err = 0; 952 954 953 - bus = devm_mdiobus_alloc(ds->dev); 954 - if (!bus) 955 - return -ENOMEM; 955 + mdio = of_get_child_by_name(dev->of_node, "mdio"); 956 + if (mdio && !of_device_is_available(mdio)) 957 + goto out; 956 958 959 + bus = devm_mdiobus_alloc(dev); 960 + if (!bus) { 961 + err = -ENOMEM; 962 + goto out_put_node; 963 + } 964 + 965 + priv->internal_mdio_bus = bus; 957 966 bus->priv = (void *)priv; 958 967 snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d.%d", 959 968 ds->dst->index, ds->index); 960 - bus->parent = ds->dev; 961 - bus->phy_mask = ~ds->phys_mii_mask; 962 - ds->user_mii_bus = bus; 969 + bus->parent = dev; 963 970 964 - /* Check if the devicetree declare the port:phy mapping */ 965 - mdio = of_get_child_by_name(priv->dev->of_node, "mdio"); 966 - if (of_device_is_available(mdio)) { 971 + if (mdio) { 972 + /* Check if the device tree declares the port:phy mapping */ 967 973 bus->name = "qca8k user mii"; 968 974 bus->read = qca8k_internal_mdio_read; 969 975 bus->write = qca8k_internal_mdio_write; 970 - return devm_of_mdiobus_register(priv->dev, bus, mdio); 976 + } else { 977 + /* If a mapping can't be found, the legacy mapping is used, 978 + * using qca8k_port_to_phy() 979 + */ 980 + ds->user_mii_bus = bus; 981 + bus->phy_mask = ~ds->phys_mii_mask; 982 + bus->name = "qca8k-legacy user mii"; 983 + bus->read = qca8k_legacy_mdio_read; 984 + bus->write = qca8k_legacy_mdio_write; 971 985 } 972 986 973 - /* If a mapping can't be found the legacy mapping is used, 974 - * using the qca8k_port_to_phy function 975 - */ 976 - bus->name = "qca8k-legacy user mii"; 977 - bus->read = qca8k_legacy_mdio_read; 978 - bus->write = qca8k_legacy_mdio_write; 979 - return devm_mdiobus_register(priv->dev, bus); 987 + err = devm_of_mdiobus_register(dev, bus, mdio); 988 + 989 + out_put_node: 990 + of_node_put(mdio); 991 + out: 992 + return err; 980 993 } 981 994 982 995 static int
+2 -2
drivers/net/dsa/qca/qca8k-leds.c
··· 366 366 { 367 367 struct fwnode_handle *led = NULL, *leds = NULL; 368 368 struct led_init_data init_data = { }; 369 - struct dsa_switch *ds = priv->ds; 370 369 enum led_default_state state; 371 370 struct qca8k_led *port_led; 372 371 int led_num, led_index; ··· 428 429 init_data.default_label = ":port"; 429 430 init_data.fwnode = led; 430 431 init_data.devname_mandatory = true; 431 - init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d", ds->user_mii_bus->id, 432 + init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d", 433 + priv->internal_mdio_bus->id, 432 434 port_num); 433 435 if (!init_data.devicename) 434 436 return -ENOMEM;
+1
drivers/net/dsa/qca/qca8k.h
··· 454 454 struct qca8k_ports_config ports_config; 455 455 struct regmap *regmap; 456 456 struct mii_bus *bus; 457 + struct mii_bus *internal_mdio_bus; 457 458 struct dsa_switch *ds; 458 459 struct mutex reg_mutex; 459 460 struct device *dev;