Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1238896 > unrolled thread

[PATCH v2 3/5] net: dsa: complete dsa_switch_destroy

Started byNeil Armstrong <narmstrong@baylibre.com>
First post2015-10-03 16:30 +0200
Last post2015-10-06 09:30 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2 3/5] net: dsa: complete dsa_switch_destroy Neil Armstrong <narmstrong@baylibre.com> - 2015-10-03 16:30 +0200
    Re: [PATCH v2 3/5] net: dsa: complete dsa_switch_destroy Florian Fainelli <f.fainelli@gmail.com> - 2015-10-03 22:30 +0200
      Re: [PATCH v2 3/5] net: dsa: complete dsa_switch_destroy Neil Armstrong <narmstrong@baylibre.com> - 2015-10-06 09:30 +0200

#1238896 — [PATCH v2 3/5] net: dsa: complete dsa_switch_destroy

FromNeil Armstrong <narmstrong@baylibre.com>
Date2015-10-03 16:30 +0200
Subject[PATCH v2 3/5] net: dsa: complete dsa_switch_destroy
Message-ID<qfvZ0-4oI-11@gated-at.bofh.it>
When unbinding dsa, complete the dsa_switch_destroy to unregister the
fixed link phy then cleanly unregister and destroy the net devices.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
 net/dsa/dsa.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 91918a3..f937f7a 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -22,6 +22,7 @@
 #include <linux/of_platform.h>
 #include <linux/of_net.h>
 #include <linux/sysfs.h>
+#include <linux/phy_fixed.h>
 #include "dsa_priv.h"

 char dsa_driver_version[] = "0.1";
@@ -420,10 +421,45 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,

 static void dsa_switch_destroy(struct dsa_switch *ds)
 {
+	struct device_node *port_dn;
+	struct phy_device *phydev;
+	struct dsa_chip_data *cd = ds->pd;
+	int port;
+
 #ifdef CONFIG_NET_DSA_HWMON
 	if (ds->hwmon_dev)
 		hwmon_device_unregister(ds->hwmon_dev);
 #endif
+
+	/* Disable configuration of the CPU and DSA ports */
+	for (port = 0; port < DSA_MAX_PORTS; port++) {
+		if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
+			continue;
+
+		port_dn = cd->port_dn[port];
+		if (of_phy_is_fixed_link(port_dn)) {
+			phydev = of_phy_find_device(port_dn);
+			if (phydev) {
+				int addr = phydev->addr;
+				phy_device_free(phydev);
+				of_node_put(port_dn);
+				fixed_phy_del(addr);
+			}
+		}
+	}
+
+	/* Destroy network devices for physical switch ports. */
+	for (port = 0; port < DSA_MAX_PORTS; port++) {
+		if (!(ds->phys_port_mask & (1 << port)))
+			continue;
+
+		if (!ds->ports[port])
+			continue;
+
+		unregister_netdev(ds->ports[port]);
+		free_netdev(ds->ports[port]);
+	}
+
 	mdiobus_unregister(ds->slave_mii_bus);
 	mdiobus_free(ds->slave_mii_bus);
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1238988

FromFlorian Fainelli <f.fainelli@gmail.com>
Date2015-10-03 22:30 +0200
Message-ID<qfBBo-43g-5@gated-at.bofh.it>
In reply to#1238896
Le 03/10/2015 07:26, Neil Armstrong a écrit :
> When unbinding dsa, complete the dsa_switch_destroy to unregister the
> fixed link phy then cleanly unregister and destroy the net devices.
> 
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---

[snip]

> +		port_dn = cd->port_dn[port];
> +		if (of_phy_is_fixed_link(port_dn)) {
> +			phydev = of_phy_find_device(port_dn);
> +			if (phydev) {
> +				int addr = phydev->addr;
> +				phy_device_free(phydev);
> +				of_node_put(port_dn);
> +				fixed_phy_del(addr);

fixed_phy_del() removes the fixed PHY from the platform fixed MDIO bus
list of PHYs, so we should be okay even with switch drivers which
register a link_update callback via fixed_phy_set_link_update(), but I
have not checked that. The sequence of call looks (phy_device_free then
fixed_phy_del) looks sane though.

Eventually this logic might be better moved into net/dsa/slave.c such
that it is easy to see how it balances dsa_slave_phy_setup().

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1240202

FromNeil Armstrong <narmstrong@baylibre.com>
Date2015-10-06 09:30 +0200
Message-ID<qguRc-7Jr-23@gated-at.bofh.it>
In reply to#1238988
On 10/03/2015 09:25 PM, Florian Fainelli wrote:
> Le 03/10/2015 07:26, Neil Armstrong a écrit :
>> When unbinding dsa, complete the dsa_switch_destroy to unregister the
>> fixed link phy then cleanly unregister and destroy the net devices.
>>
>> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
>> ---
> 
> [snip]
> 
>> +		port_dn = cd->port_dn[port];
>> +		if (of_phy_is_fixed_link(port_dn)) {
>> +			phydev = of_phy_find_device(port_dn);
>> +			if (phydev) {
>> +				int addr = phydev->addr;
>> +				phy_device_free(phydev);
>> +				of_node_put(port_dn);
>> +				fixed_phy_del(addr);
> 
> fixed_phy_del() removes the fixed PHY from the platform fixed MDIO bus
> list of PHYs, so we should be okay even with switch drivers which
> register a link_update callback via fixed_phy_set_link_update(), but I
> have not checked that. The sequence of call looks (phy_device_free then
> fixed_phy_del) looks sane though.
Actually I copied the exact sequence from the fixed link module, eventually this should be done in this module with a proper fixed_link_remove function.

> 
> Eventually this logic might be better moved into net/dsa/slave.c such
> that it is easy to see how it balances dsa_slave_phy_setup().
> 
> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
> 

Thanks for the review,

Neil
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web