aboutsummaryrefslogtreecommitdiffstats
path: root/net/dsa
diff options
context:
space:
mode:
authorAndrew Lunn <andrew@lunn.ch>2016-06-04 15:17:01 -0400
committerDavid S. Miller <davem@davemloft.net>2016-06-04 17:29:53 -0400
commit9b8e895c4e9d217dfa0e48aafa072258e2a3480e (patch)
tree4f64692e9a032093e5024c5f65c94e427afd9d03 /net/dsa
parent66472fc04e8be62858f29c7798ed17e984c1ab3b (diff)
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: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa')
-rw-r--r--net/dsa/dsa.c86
-rw-r--r--net/dsa/dsa_priv.h3
2 files changed, 54 insertions, 35 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index bfe1d03d4730..7140de475c07 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -180,36 +180,47 @@ __ATTRIBUTE_GROUPS(dsa_hwmon);
180#endif /* CONFIG_NET_DSA_HWMON */ 180#endif /* CONFIG_NET_DSA_HWMON */
181 181
182/* basic switch operations **************************************************/ 182/* basic switch operations **************************************************/
183static int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct net_device *master) 183int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
184 struct device_node *port_dn, int port)
184{ 185{
185 struct device_node *port_dn;
186 struct phy_device *phydev; 186 struct phy_device *phydev;
187 int ret, port, mode; 187 int ret, mode;
188
189 if (of_phy_is_fixed_link(port_dn)) {
190 ret = of_phy_register_fixed_link(port_dn);
191 if (ret) {
192 dev_err(dev, "failed to register fixed PHY\n");
193 return ret;
194 }
195 phydev = of_phy_find_device(port_dn);
196
197 mode = of_get_phy_mode(port_dn);
198 if (mode < 0)
199 mode = PHY_INTERFACE_MODE_NA;
200 phydev->interface = mode;
201
202 genphy_config_init(phydev);
203 genphy_read_status(phydev);
204 if (ds->drv->adjust_link)
205 ds->drv->adjust_link(ds, port, phydev);
206 }
207
208 return 0;
209}
210
211static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
212{
213 struct device_node *port_dn;
214 int ret, port;
188 215
189 for (port = 0; port < DSA_MAX_PORTS; port++) { 216 for (port = 0; port < DSA_MAX_PORTS; port++) {
190 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) 217 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
191 continue; 218 continue;
192 219
193 port_dn = ds->ports[port].dn; 220 port_dn = ds->ports[port].dn;
194 if (of_phy_is_fixed_link(port_dn)) { 221 ret = dsa_cpu_dsa_setup(ds, dev, port_dn, port);
195 ret = of_phy_register_fixed_link(port_dn); 222 if (ret)
196 if (ret) { 223 return ret;
197 netdev_err(master,
198 "failed to register fixed PHY\n");
199 return ret;
200 }
201 phydev = of_phy_find_device(port_dn);
202
203 mode = of_get_phy_mode(port_dn);
204 if (mode < 0)
205 mode = PHY_INTERFACE_MODE_NA;
206 phydev->interface = mode;
207
208 genphy_config_init(phydev);
209 genphy_read_status(phydev);
210 if (ds->drv->adjust_link)
211 ds->drv->adjust_link(ds, port, phydev);
212 }
213 } 224 }
214 return 0; 225 return 0;
215} 226}
@@ -340,7 +351,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
340 } 351 }
341 352
342 /* Perform configuration of the CPU and DSA ports */ 353 /* Perform configuration of the CPU and DSA ports */
343 ret = dsa_cpu_dsa_setup(ds, dst->master_netdev); 354 ret = dsa_cpu_dsa_setups(ds, parent);
344 if (ret < 0) { 355 if (ret < 0) {
345 netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n", 356 netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n",
346 index); 357 index);
@@ -423,10 +434,21 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
423 return ds; 434 return ds;
424} 435}
425 436
426static void dsa_switch_destroy(struct dsa_switch *ds) 437void dsa_cpu_dsa_destroy(struct device_node *port_dn)
427{ 438{
428 struct device_node *port_dn;
429 struct phy_device *phydev; 439 struct phy_device *phydev;
440
441 if (of_phy_is_fixed_link(port_dn)) {
442 phydev = of_phy_find_device(port_dn);
443 if (phydev) {
444 phy_device_free(phydev);
445 fixed_phy_unregister(phydev);
446 }
447 }
448}
449
450static void dsa_switch_destroy(struct dsa_switch *ds)
451{
430 int port; 452 int port;
431 453
432#ifdef CONFIG_NET_DSA_HWMON 454#ifdef CONFIG_NET_DSA_HWMON
@@ -445,17 +467,11 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
445 dsa_slave_destroy(ds->ports[port].netdev); 467 dsa_slave_destroy(ds->ports[port].netdev);
446 } 468 }
447 469
448 /* Remove any fixed link PHYs */ 470 /* Disable configuration of the CPU and DSA ports */
449 for (port = 0; port < DSA_MAX_PORTS; port++) { 471 for (port = 0; port < DSA_MAX_PORTS; port++) {
450 port_dn = ds->ports[port].dn; 472 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
451 if (of_phy_is_fixed_link(port_dn)) { 473 continue;
452 phydev = of_phy_find_device(port_dn); 474 dsa_cpu_dsa_destroy(ds->ports[port].dn);
453 if (phydev) {
454 phy_device_free(phydev);
455 of_node_put(port_dn);
456 fixed_phy_unregister(phydev);
457 }
458 }
459 } 475 }
460 476
461 mdiobus_unregister(ds->slave_mii_bus); 477 mdiobus_unregister(ds->slave_mii_bus);
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index dfa33779d49c..dbea5d9e7f75 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -50,6 +50,9 @@ struct dsa_slave_priv {
50 50
51/* dsa.c */ 51/* dsa.c */
52extern char dsa_driver_version[]; 52extern char dsa_driver_version[];
53int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
54 struct device_node *port_dn, int port);
55void dsa_cpu_dsa_destroy(struct device_node *port_dn);
53 56
54/* slave.c */ 57/* slave.c */
55extern const struct dsa_device_ops notag_netdev_ops; 58extern const struct dsa_device_ops notag_netdev_ops;