Commit 9b8e895c authored by Andrew Lunn's avatar Andrew Lunn Committed by David S. Miller

net: dsa: Split up creating/destroying of DSA and CPU ports

Refactor the code to setup a single DSA/CPU port into a function of
its own, and export it, so it can be used by the new binding.

Similarly, refactor the destroy code into a function.  When destroying
the ports, don't put the of node. They should be released at the end
along with the normal ports.
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Reviewed-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 66472fc0
...@@ -180,22 +180,16 @@ __ATTRIBUTE_GROUPS(dsa_hwmon); ...@@ -180,22 +180,16 @@ __ATTRIBUTE_GROUPS(dsa_hwmon);
#endif /* CONFIG_NET_DSA_HWMON */ #endif /* CONFIG_NET_DSA_HWMON */
/* basic switch operations **************************************************/ /* basic switch operations **************************************************/
static int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct net_device *master) int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
struct device_node *port_dn, int port)
{ {
struct device_node *port_dn;
struct phy_device *phydev; struct phy_device *phydev;
int ret, port, mode; int ret, mode;
for (port = 0; port < DSA_MAX_PORTS; port++) {
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
continue;
port_dn = ds->ports[port].dn;
if (of_phy_is_fixed_link(port_dn)) { if (of_phy_is_fixed_link(port_dn)) {
ret = of_phy_register_fixed_link(port_dn); ret = of_phy_register_fixed_link(port_dn);
if (ret) { if (ret) {
netdev_err(master, dev_err(dev, "failed to register fixed PHY\n");
"failed to register fixed PHY\n");
return ret; return ret;
} }
phydev = of_phy_find_device(port_dn); phydev = of_phy_find_device(port_dn);
...@@ -210,6 +204,23 @@ static int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct net_device *master) ...@@ -210,6 +204,23 @@ static int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct net_device *master)
if (ds->drv->adjust_link) if (ds->drv->adjust_link)
ds->drv->adjust_link(ds, port, phydev); ds->drv->adjust_link(ds, port, phydev);
} }
return 0;
}
static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
{
struct device_node *port_dn;
int ret, port;
for (port = 0; port < DSA_MAX_PORTS; port++) {
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
continue;
port_dn = ds->ports[port].dn;
ret = dsa_cpu_dsa_setup(ds, dev, port_dn, port);
if (ret)
return ret;
} }
return 0; return 0;
} }
...@@ -340,7 +351,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent) ...@@ -340,7 +351,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
} }
/* Perform configuration of the CPU and DSA ports */ /* Perform configuration of the CPU and DSA ports */
ret = dsa_cpu_dsa_setup(ds, dst->master_netdev); ret = dsa_cpu_dsa_setups(ds, parent);
if (ret < 0) { if (ret < 0) {
netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n", netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n",
index); index);
...@@ -423,10 +434,21 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index, ...@@ -423,10 +434,21 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
return ds; return ds;
} }
static void dsa_switch_destroy(struct dsa_switch *ds) void dsa_cpu_dsa_destroy(struct device_node *port_dn)
{ {
struct device_node *port_dn;
struct phy_device *phydev; struct phy_device *phydev;
if (of_phy_is_fixed_link(port_dn)) {
phydev = of_phy_find_device(port_dn);
if (phydev) {
phy_device_free(phydev);
fixed_phy_unregister(phydev);
}
}
}
static void dsa_switch_destroy(struct dsa_switch *ds)
{
int port; int port;
#ifdef CONFIG_NET_DSA_HWMON #ifdef CONFIG_NET_DSA_HWMON
...@@ -445,17 +467,11 @@ static void dsa_switch_destroy(struct dsa_switch *ds) ...@@ -445,17 +467,11 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
dsa_slave_destroy(ds->ports[port].netdev); dsa_slave_destroy(ds->ports[port].netdev);
} }
/* Remove any fixed link PHYs */ /* Disable configuration of the CPU and DSA ports */
for (port = 0; port < DSA_MAX_PORTS; port++) { for (port = 0; port < DSA_MAX_PORTS; port++) {
port_dn = ds->ports[port].dn; if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
if (of_phy_is_fixed_link(port_dn)) { continue;
phydev = of_phy_find_device(port_dn); dsa_cpu_dsa_destroy(ds->ports[port].dn);
if (phydev) {
phy_device_free(phydev);
of_node_put(port_dn);
fixed_phy_unregister(phydev);
}
}
} }
mdiobus_unregister(ds->slave_mii_bus); mdiobus_unregister(ds->slave_mii_bus);
......
...@@ -50,6 +50,9 @@ struct dsa_slave_priv { ...@@ -50,6 +50,9 @@ struct dsa_slave_priv {
/* dsa.c */ /* dsa.c */
extern char dsa_driver_version[]; extern char dsa_driver_version[];
int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
struct device_node *port_dn, int port);
void dsa_cpu_dsa_destroy(struct device_node *port_dn);
/* slave.c */ /* slave.c */
extern const struct dsa_device_ops notag_netdev_ops; extern const struct dsa_device_ops notag_netdev_ops;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment