From: Colin Foster <colin.foster@in-advantage.com>
To: linux-phy@lists.infradead.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Russell King <linux@armlinux.org.uk>,
Kishon Vijay Abraham I <kishon@kernel.org>,
Vinod Koul <vkoul@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
"David S. Miller" <davem@davemloft.net>,
Florian Fainelli <f.fainelli@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
UNGLinuxDriver@microchip.com,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Manoil <claudiu.manoil@nxp.com>,
Vladimir Oltean <vladimir.oltean@nxp.com>,
Lee Jones <lee@kernel.org>
Subject: [RFC v1 net-next 7/7] net: dsa: ocelot_ext: add support for external phys
Date: Wed, 15 Feb 2023 23:53:21 -0800 [thread overview]
Message-ID: <20230216075321.2898003-8-colin.foster@in-advantage.com> (raw)
In-Reply-To: <20230216075321.2898003-1-colin.foster@in-advantage.com>
The VSC7512 has four internal copper ports, and can be configured to work
in various configurations with up to six additional ports. Support for the
initial four ports was added in commit 3d7316ac81ac ("net: dsa: ocelot: add
external ocelot switch control"). This patch adds support for the
additional ports.
The specific hardware configuration for this development uses a QSGMII link
between a VSC7512 and a VSC8514. The VSC8514 offers connection to four RJ45
ports, all of which are verified functional.
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
---
drivers/net/dsa/ocelot/felix.h | 1 +
drivers/net/dsa/ocelot/ocelot_ext.c | 319 ++++++++++++++++++++++++++--
2 files changed, 305 insertions(+), 15 deletions(-)
diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h
index ffb60bcf1817..fdd402305925 100644
--- a/drivers/net/dsa/ocelot/felix.h
+++ b/drivers/net/dsa/ocelot/felix.h
@@ -6,6 +6,7 @@
#define ocelot_to_felix(o) container_of((o), struct felix, ocelot)
#define FELIX_MAC_QUIRKS OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION
+#define OCELOT_EXT_MAC_QUIRKS OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP
#define OCELOT_PORT_MODE_NONE 0
#define OCELOT_PORT_MODE_INTERNAL BIT(0)
diff --git a/drivers/net/dsa/ocelot/ocelot_ext.c b/drivers/net/dsa/ocelot/ocelot_ext.c
index 14efa6387bd7..f10271b973b2 100644
--- a/drivers/net/dsa/ocelot/ocelot_ext.c
+++ b/drivers/net/dsa/ocelot/ocelot_ext.c
@@ -4,10 +4,13 @@
*/
#include <linux/mfd/ocelot.h>
+#include <linux/of_net.h>
+#include <linux/phy/phy.h>
#include <linux/phylink.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <soc/mscc/ocelot.h>
+#include <soc/mscc/ocelot_dev.h>
#include <soc/mscc/vsc7514_regs.h>
#include "felix.h"
@@ -16,20 +19,283 @@
#define OCELOT_PORT_MODE_SERDES (OCELOT_PORT_MODE_SGMII | \
OCELOT_PORT_MODE_QSGMII)
+#define phylink_config_to_ocelot_port(config) \
+ container_of(config, struct ocelot_ext_port_priv, phylink_config)
+#define phylink_pcs_to_ocelot_port(pl_pcs) \
+ container_of(pl_pcs, struct ocelot_ext_port_priv, pcs)
+
+struct ocelot_ext_port_priv {
+ struct device_node *node;
+ struct phylink_config phylink_config;
+ struct phylink *phylink;
+ struct ocelot *ocelot;
+ int chip_port;
+ struct phylink_pcs pcs;
+};
+
+struct ocelot_ext_priv {
+ struct felix felix;
+ struct ocelot_ext_port_priv *port_priv[VSC7514_NUM_PORTS];
+};
+
+static struct ocelot_ext_priv *felix_to_ocelot_ext_priv(struct felix *felix)
+{
+ return container_of(felix, struct ocelot_ext_priv, felix);
+}
+
static const u32 vsc7512_port_modes[VSC7514_NUM_PORTS] = {
OCELOT_PORT_MODE_INTERNAL,
OCELOT_PORT_MODE_INTERNAL,
OCELOT_PORT_MODE_INTERNAL,
OCELOT_PORT_MODE_INTERNAL,
- OCELOT_PORT_MODE_NONE,
- OCELOT_PORT_MODE_NONE,
- OCELOT_PORT_MODE_NONE,
- OCELOT_PORT_MODE_NONE,
- OCELOT_PORT_MODE_NONE,
- OCELOT_PORT_MODE_NONE,
- OCELOT_PORT_MODE_NONE,
+ OCELOT_PORT_MODE_SERDES,
+ OCELOT_PORT_MODE_SERDES,
+ OCELOT_PORT_MODE_SERDES,
+ OCELOT_PORT_MODE_SERDES,
+ OCELOT_PORT_MODE_SERDES,
+ OCELOT_PORT_MODE_SGMII,
+ OCELOT_PORT_MODE_SERDES,
+};
+
+static void ocelot_ext_phylink_of_cleanup(struct ocelot *ocelot)
+{
+ struct felix *felix = ocelot_to_felix(ocelot);
+ struct ocelot_ext_priv *ocelot_ext_priv;
+ int i;
+
+ ocelot_ext_priv = felix_to_ocelot_ext_priv(felix);
+ for (i = 0; i < VSC7514_NUM_PORTS; i++) {
+ struct ocelot_ext_port_priv *port_priv;
+
+ port_priv = ocelot_ext_priv->port_priv[i];
+ if (port_priv && port_priv->node)
+ of_node_put(port_priv->node);
+ }
+}
+
+static void ocelot_ext_phylink_mac_config(struct phylink_config *config,
+ unsigned int link_an_mode,
+ const struct phylink_link_state *state)
+{
+ struct ocelot_ext_port_priv *priv =
+ phylink_config_to_ocelot_port(config);
+ struct ocelot *ocelot = priv->ocelot;
+ int port = priv->chip_port;
+
+ ocelot_phylink_mac_config(ocelot, port, link_an_mode, state);
+}
+
+static void ocelot_ext_phylink_mac_link_down(struct phylink_config *config,
+ unsigned int link_an_mode,
+ phy_interface_t interface)
+{
+ struct ocelot_ext_port_priv *priv =
+ phylink_config_to_ocelot_port(config);
+ struct ocelot *ocelot = priv->ocelot;
+ struct felix *felix = ocelot_to_felix(ocelot);
+ int port = priv->chip_port;
+
+ ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface,
+ felix->info->quirks);
+}
+
+static void ocelot_ext_phylink_mac_link_up(struct phylink_config *config,
+ struct phy_device *phydev,
+ unsigned int link_an_mode,
+ phy_interface_t interface,
+ int speed, int duplex,
+ bool tx_pause, bool rx_pause)
+{
+ struct ocelot_ext_port_priv *priv =
+ phylink_config_to_ocelot_port(config);
+ struct ocelot *ocelot = priv->ocelot;
+ struct felix *felix = ocelot_to_felix(ocelot);
+ int port = priv->chip_port;
+
+ ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode,
+ interface, speed, duplex, tx_pause, rx_pause,
+ felix->info->quirks);
+}
+
+static const struct phylink_mac_ops ocelot_ext_phylink_ops = {
+ .validate = phylink_generic_validate,
+ .mac_config = ocelot_ext_phylink_mac_config,
+ .mac_link_down = ocelot_ext_phylink_mac_link_down,
+ .mac_link_up = ocelot_ext_phylink_mac_link_up,
+};
+
+static void ocelot_ext_pcs_get_state(struct phylink_pcs *pcs,
+ struct phylink_link_state *state)
+{
+ struct ocelot_ext_port_priv *port_priv =
+ phylink_pcs_to_ocelot_port(pcs);
+
+ /* TODO: Determine state from hardware? */
+}
+
+static int ocelot_ext_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
+ phy_interface_t interface,
+ const unsigned long *advertising,
+ bool permit_pause_to_mac)
+{
+ struct ocelot_ext_port_priv *port_priv =
+ phylink_pcs_to_ocelot_port(pcs);
+
+ switch (interface) {
+ case PHY_INTERFACE_MODE_QSGMII:
+ ocelot_ext_phylink_mac_config(&port_priv->phylink_config, mode,
+ NULL);
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static void ocelot_ext_pcs_an_restart(struct phylink_pcs *pcs)
+{
+ /* TODO: Restart autonegotiaion process */
+}
+
+static void ocelot_ext_pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
+ phy_interface_t interface, int speed,
+ int duplex)
+{
+ struct ocelot_ext_port_priv *port_priv =
+ phylink_pcs_to_ocelot_port(pcs);
+
+ ocelot_ext_phylink_mac_link_up(&port_priv->phylink_config, NULL, mode,
+ interface, speed, duplex, false, false);
+}
+
+static const struct phylink_pcs_ops ocelot_ext_pcs_ops = {
+ .pcs_get_state = ocelot_ext_pcs_get_state,
+ .pcs_config = ocelot_ext_pcs_config,
+ .pcs_an_restart = ocelot_ext_pcs_an_restart,
+ .pcs_link_up = ocelot_ext_pcs_link_up,
};
+static int ocelot_ext_parse_port_node(struct ocelot *ocelot,
+ struct device_node *ports_node,
+ phy_interface_t phy_mode, int port)
+{
+ struct ocelot_ext_port_priv *ocelot_ext_port_priv;
+ struct felix *felix = ocelot_to_felix(ocelot);
+ struct ocelot_ext_priv *ocelot_ext_priv;
+
+ ocelot_ext_priv = felix_to_ocelot_ext_priv(felix);
+
+ ocelot_ext_port_priv = devm_kzalloc(ocelot->dev,
+ sizeof(*ocelot_ext_port_priv),
+ GFP_KERNEL);
+ if (!ocelot_ext_port_priv)
+ return -ENOMEM;
+
+ ocelot_ext_port_priv->ocelot = ocelot;
+ ocelot_ext_port_priv->chip_port = port;
+ ocelot_ext_port_priv->pcs.ops = &ocelot_ext_pcs_ops;
+
+ if (!felix->pcs)
+ felix->pcs = devm_kcalloc(ocelot->dev, felix->info->num_ports,
+ sizeof(struct phylink_pcs *),
+ GFP_KERNEL);
+
+ if (!felix->pcs)
+ return -ENOMEM;
+
+ felix->pcs[port] = &ocelot_ext_port_priv->pcs;
+
+ ocelot_ext_priv->port_priv[port] = ocelot_ext_port_priv;
+
+ ocelot_ext_port_priv->node = of_node_get(ports_node);
+
+ return 0;
+}
+
+static int ocelot_ext_phylink_create(struct ocelot *ocelot, int port)
+{
+ struct ocelot_ext_port_priv *ocelot_ext_port_priv;
+ struct felix *felix = ocelot_to_felix(ocelot);
+ struct ocelot_ext_priv *ocelot_ext_priv;
+ struct device *dev = ocelot->dev;
+ struct ocelot_port *ocelot_port;
+ struct device_node *portnp;
+ phy_interface_t phy_mode;
+ struct phylink *phylink;
+ int err;
+
+ ocelot_ext_priv = felix_to_ocelot_ext_priv(felix);
+ ocelot_port = ocelot->ports[port];
+ ocelot_ext_port_priv = ocelot_ext_priv->port_priv[port];
+
+ if (!ocelot_ext_port_priv)
+ return 0;
+
+ portnp = ocelot_ext_port_priv->node;
+ phy_mode = ocelot_port->phy_mode;
+
+ /* Break out early if we're internal...? */
+ if (phy_mode == PHY_INTERFACE_MODE_INTERNAL)
+ return 0;
+
+ if (phy_mode == PHY_INTERFACE_MODE_QSGMII)
+ ocelot_port_rmwl(ocelot_port, 0,
+ DEV_CLOCK_CFG_MAC_TX_RST |
+ DEV_CLOCK_CFG_MAC_RX_RST,
+ DEV_CLOCK_CFG);
+
+ if (phy_mode != PHY_INTERFACE_MODE_INTERNAL) {
+ struct phy *serdes = of_phy_get(portnp, NULL);
+
+ if (IS_ERR(serdes)) {
+ err = PTR_ERR(serdes);
+ dev_err_probe(dev, err,
+ "missing SerDes phys for port %d\n",
+ port);
+ return err;
+ }
+
+ err = phy_set_mode_ext(serdes, PHY_MODE_ETHERNET, phy_mode);
+ of_phy_put(serdes);
+ if (err) {
+ dev_err(dev,
+ "Could not set SerDes mode on port %d: %pe\n",
+ port, ERR_PTR(err));
+ return err;
+ }
+ }
+
+ ocelot_ext_port_priv->phylink_config.dev = dev;
+ ocelot_ext_port_priv->phylink_config.type = PHYLINK_DEV;
+ ocelot_ext_port_priv->phylink_config.mac_capabilities = MAC_ASYM_PAUSE |
+ MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000FD | MAC_2500FD;
+
+ __set_bit(ocelot_port->phy_mode,
+ ocelot_ext_port_priv->phylink_config.supported_interfaces);
+
+ phylink = phylink_create(&ocelot_ext_port_priv->phylink_config,
+ of_fwnode_handle(portnp),
+ phy_mode, &ocelot_ext_phylink_ops);
+ if (IS_ERR(phylink)) {
+ err = PTR_ERR(phylink);
+ dev_err(dev, "Could not create phylink (%pe)\n", phylink);
+ return err;
+ }
+
+ ocelot_ext_port_priv->phylink = phylink;
+
+ err = phylink_of_phy_connect(phylink, portnp, 0);
+ if (err) {
+ dev_err(dev, "Could not connect to PHY: %pe\n", ERR_PTR(err));
+ phylink_destroy(phylink);
+ ocelot_ext_port_priv->phylink = NULL;
+ return err;
+ }
+
+ return 0;
+}
+
static const struct ocelot_ops ocelot_ext_ops = {
.reset = ocelot_reset,
.wm_enc = ocelot_wm_enc,
@@ -48,6 +314,7 @@ static const char * const vsc7512_resource_names[TARGET_MAX] = {
[QS] = "qs",
[QSYS] = "qsys",
[ANA] = "ana",
+ [HSIO] = "hsio",
};
static const struct felix_info vsc7512_info = {
@@ -56,25 +323,32 @@ static const struct felix_info vsc7512_info = {
.map = vsc7514_regmap,
.ops = &ocelot_ext_ops,
.vcap = vsc7514_vcap_props,
+ .quirks = OCELOT_EXT_MAC_QUIRKS,
.num_mact_rows = 1024,
.num_ports = VSC7514_NUM_PORTS,
.num_tx_queues = OCELOT_NUM_TC,
.port_modes = vsc7512_port_modes,
+ .parse_port_node = ocelot_ext_parse_port_node,
+ .phylink_create = ocelot_ext_phylink_create,
+ .phylink_of_cleanup = ocelot_ext_phylink_of_cleanup,
};
static int ocelot_ext_probe(struct platform_device *pdev)
{
+ struct ocelot_ext_priv *ocelot_ext_priv;
struct device *dev = &pdev->dev;
struct dsa_switch *ds;
struct ocelot *ocelot;
struct felix *felix;
int err;
- felix = kzalloc(sizeof(*felix), GFP_KERNEL);
- if (!felix)
+ ocelot_ext_priv = kzalloc(sizeof(*ocelot_ext_priv), GFP_KERNEL);
+ if (!ocelot_ext_priv)
return -ENOMEM;
- dev_set_drvdata(dev, felix);
+ dev_set_drvdata(dev, ocelot_ext_priv);
+
+ felix = &ocelot_ext_priv->felix;
ocelot = &felix->ocelot;
ocelot->dev = dev;
@@ -116,28 +390,43 @@ static int ocelot_ext_probe(struct platform_device *pdev)
static int ocelot_ext_remove(struct platform_device *pdev)
{
- struct felix *felix = dev_get_drvdata(&pdev->dev);
+ struct ocelot_ext_priv *ocelot_ext_priv = dev_get_drvdata(&pdev->dev);
+ struct felix *felix;
- if (!felix)
+ if (!ocelot_ext_priv)
return 0;
+ felix = &ocelot_ext_priv->felix;
+
dsa_unregister_switch(felix->ds);
kfree(felix->ds);
- kfree(felix);
+ kfree(ocelot_ext_priv);
return 0;
}
static void ocelot_ext_shutdown(struct platform_device *pdev)
{
- struct felix *felix = dev_get_drvdata(&pdev->dev);
+ struct ocelot_ext_priv *ocelot_ext_priv = dev_get_drvdata(&pdev->dev);
+ struct ocelot_ext_port_priv *port_priv;
+ struct felix *felix;
+ int i;
- if (!felix)
+ if (!ocelot_ext_priv)
return;
+ felix = &ocelot_ext_priv->felix;
+
dsa_switch_shutdown(felix->ds);
+ for (i = 0; i < felix->info->num_ports; i++) {
+ port_priv = ocelot_ext_priv->port_priv[i];
+
+ if (port_priv && port_priv->phylink)
+ phylink_destroy(port_priv->phylink);
+ }
+
dev_set_drvdata(&pdev->dev, NULL);
}
--
2.25.1
next prev parent reply other threads:[~2023-02-16 7:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 7:53 [RFC v1 net-next 0/7] add support for ocelot external ports Colin Foster
2023-02-16 7:53 ` [RFC v1 net-next 1/7] phy: phy-ocelot-serdes: add ability to be used in a non-syscon configuration Colin Foster
2023-02-16 7:53 ` [RFC v1 net-next 2/7] mfd: ocelot: add ocelot-serdes capability Colin Foster
2023-03-03 10:48 ` Lee Jones
2023-03-03 15:12 ` Colin Foster
2023-03-03 21:57 ` Lee Jones
2023-02-16 7:53 ` [RFC v1 net-next 3/7] net: mscc: ocelot: expose ocelot_pll5_init routine Colin Foster
2023-02-16 7:53 ` [RFC v1 net-next 4/7] net: mscc: ocelot: expose generic phylink_mac_config routine Colin Foster
2023-02-16 7:53 ` [RFC v1 net-next 5/7] net: dsa: felix: attempt to initialize internal hsio plls Colin Foster
2023-02-16 7:53 ` [RFC v1 net-next 6/7] net: dsa: felix: allow external parsing of port nodes Colin Foster
2023-02-16 7:53 ` Colin Foster [this message]
2023-02-16 11:17 ` [RFC v1 net-next 7/7] net: dsa: ocelot_ext: add support for external phys Russell King (Oracle)
2023-02-17 1:31 ` Colin Foster
2023-02-16 12:14 ` [RFC v1 net-next 0/7] add support for ocelot external ports Russell King (Oracle)
2023-02-17 0:42 ` Colin Foster
2023-02-17 1:11 ` Vladimir Oltean
2023-02-17 7:02 ` Colin Foster
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=20230216075321.2898003-8-colin.foster@in-advantage.com \
--to=colin.foster@in-advantage.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andrew@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kishon@kernel.org \
--cc=kuba@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vkoul@kernel.org \
--cc=vladimir.oltean@nxp.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
all inboxes | Powered by JetHome®