From: Andrew Lunn <andrew@lunn.ch>
To: netdev <netdev@vger.kernel.org>
Cc: Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
Florian Fainelli <f.fainelli@gmail.com>,
John Crispin <john@phrozen.org>,
Bryan.Whitehead@microchip.com, Andrew Lunn <andrew@lunn.ch>
Subject: [RFC PATCH 09/16] dsa: dsa: Split up creating/destroying of DSA and CPU ports
Date: Fri, 27 May 2016 03:20:43 +0200 [thread overview]
Message-ID: <1464312050-23023-10-git-send-email-andrew@lunn.ch> (raw)
In-Reply-To: <1464312050-23023-1-git-send-email-andrew@lunn.ch>
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.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
net/dsa/dsa.c | 86 ++++++++++++++++++++++++++++++++----------------------
net/dsa/dsa_priv.h | 3 ++
2 files changed, 54 insertions(+), 35 deletions(-)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index bfe1d03d4730..20eede3facf5 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -180,36 +180,47 @@ __ATTRIBUTE_GROUPS(dsa_hwmon);
#endif /* CONFIG_NET_DSA_HWMON */
/* 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;
- int ret, port, mode;
+ int ret, mode;
+
+ if (of_phy_is_fixed_link(port_dn)) {
+ ret = of_phy_register_fixed_link(port_dn);
+ if (ret) {
+ dev_err(dev, "failed to register fixed PHY\n");
+ return ret;
+ }
+ phydev = of_phy_find_device(port_dn);
+
+ mode = of_get_phy_mode(port_dn);
+ if (mode < 0)
+ mode = PHY_INTERFACE_MODE_NA;
+ phydev->interface = mode;
+
+ genphy_config_init(phydev);
+ genphy_read_status(phydev);
+ if (ds->drv->adjust_link)
+ 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;
- if (of_phy_is_fixed_link(port_dn)) {
- ret = of_phy_register_fixed_link(port_dn);
- if (ret) {
- netdev_err(master,
- "failed to register fixed PHY\n");
- return ret;
- }
- phydev = of_phy_find_device(port_dn);
-
- mode = of_get_phy_mode(port_dn);
- if (mode < 0)
- mode = PHY_INTERFACE_MODE_NA;
- phydev->interface = mode;
-
- genphy_config_init(phydev);
- genphy_read_status(phydev);
- if (ds->drv->adjust_link)
- ds->drv->adjust_link(ds, port, phydev);
- }
+ ret = dsa_cpu_dsa_setup(ds, dev, port_dn, port);
+ if (ret)
+ return ret;
}
return 0;
}
@@ -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 */
- ret = dsa_cpu_dsa_setup(ds, dst->master_netdev);
+ ret = dsa_cpu_dsa_setups(ds, parent);
if (ret < 0) {
netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n",
index);
@@ -423,10 +434,21 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
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;
+
+ 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;
#ifdef CONFIG_NET_DSA_HWMON
@@ -445,17 +467,11 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
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++) {
- port_dn = ds->ports[port].dn;
- if (of_phy_is_fixed_link(port_dn)) {
- phydev = of_phy_find_device(port_dn);
- if (phydev) {
- phy_device_free(phydev);
- of_node_put(port_dn);
- fixed_phy_unregister(phydev);
- }
- }
+ if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
+ continue;
+ dsa_cpu_dsa_destroy(ds->ports[port].dn);
}
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 {
/* dsa.c */
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 */
extern const struct dsa_device_ops notag_netdev_ops;
--
2.8.1
next prev parent reply other threads:[~2016-05-27 1:23 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-27 1:20 [RFC PATCH 00/16] New DSA bind, switches as devices Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 01/16] dsa: slave: chip data is optional, don't dereference NULL Andrew Lunn
2016-05-27 18:45 ` Vivien Didelot
2016-05-27 21:24 ` Florian Fainelli
2016-05-27 1:20 ` [RFC PATCH 02/16] net: dsa: mv88e6xxx: fix circular lock in PPU work Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 03/16] dsa: slave: Remove MDIO address from switch MDIO bus name Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 04/16] dsa: tag_{e}dsa.c: Remove dependency on platform data Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 05/16] dsa: Add a ports structure and use it in the switch structure Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 06/16] dsa: Move port device node into port structure Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 07/16] dsa: Remove dynamic allocate of routing table Andrew Lunn
2016-05-27 18:54 ` Vivien Didelot
2016-05-27 1:20 ` [RFC PATCH 08/16] dsa: Copy the routing table into the switch structure Andrew Lunn
2016-05-27 1:20 ` Andrew Lunn [this message]
2016-05-27 14:33 ` [RFC PATCH 09/16] dsa: dsa: Split up creating/destroying of DSA and CPU ports Vivien Didelot
2016-05-27 15:07 ` Andrew Lunn
2016-05-27 16:36 ` Vivien Didelot
2016-05-27 19:25 ` Vivien Didelot
2016-05-27 20:01 ` Andrew Lunn
2016-05-27 20:29 ` Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 10/16] net: dsa: mv88e6xxx: Only support EDSA tagging Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 11/16] net: dsa: Refactor selection of tag ops into a function Andrew Lunn
2016-05-27 19:35 ` Vivien Didelot
2016-05-27 20:11 ` Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 12/16] dsa: Make mdio bus optional Andrew Lunn
2016-05-27 14:55 ` Vivien Didelot
2016-05-27 15:18 ` Andrew Lunn
2016-05-27 16:38 ` Vivien Didelot
2016-05-27 1:20 ` [RFC PATCH 13/16] net: dsa: mv88e6xxx: Refactor MDIO so driver registers mdio bus Andrew Lunn
2016-05-27 19:45 ` Vivien Didelot
2016-05-27 1:20 ` [RFC PATCH 14/16] net: dsa: Add new binding implementation Andrew Lunn
2016-05-27 20:39 ` Vivien Didelot
2016-05-27 20:57 ` Andrew Lunn
2016-05-27 21:29 ` Florian Fainelli
2016-05-28 8:23 ` Richard Cochran
2016-05-27 1:20 ` [RFC PATCH 15/16] arm: dt: vf610-zii-devel-b: Make use of new DSA binding Andrew Lunn
2016-05-27 1:20 ` [RFC PATCH 16/16] dsa: Document new binding Andrew Lunn
2016-05-27 18:30 ` [RFC PATCH 00/16] New DSA bind, switches as devices Vivien Didelot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1464312050-23023-10-git-send-email-andrew@lunn.ch \
--to=andrew@lunn.ch \
--cc=Bryan.Whitehead@microchip.com \
--cc=f.fainelli@gmail.com \
--cc=john@phrozen.org \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@savoirfairelinux.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).