From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: netdev@vger.kernel.org
Cc: alexandre.belloni@bootlin.com, andrew@lunn.ch,
f.fainelli@gmail.com, vivien.didelot@gmail.com,
alexandru.marginean@nxp.com, claudiu.manoil@nxp.com,
xiaoliang.yang_1@nxp.com, hongbo.wang@nxp.com, kuba@kernel.org,
jiri@resnulli.us, idosch@idosch.org,
UNGLinuxDriver@microchip.com
Subject: [RFC PATCH 08/10] net: mscc: ocelot: register devlink ports
Date: Tue, 13 Oct 2020 16:48:47 +0300 [thread overview]
Message-ID: <20201013134849.395986-9-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20201013134849.395986-1-vladimir.oltean@nxp.com>
Add devlink integration into the mscc_ocelot switchdev driver. Only the
probed interfaces are registered with devlink, because for convenience,
struct devlink_port was included into struct ocelot_port_private, which
is only initialized for the ports that are used.
Note that the felix DSA driver is already integrated with devlink by
default, since that is a thing that the DSA core takes care of.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/mscc/ocelot.h | 4 +
drivers/net/ethernet/mscc/ocelot_net.c | 92 ++++++++++++++++++++++
drivers/net/ethernet/mscc/ocelot_vsc7514.c | 7 ++
include/soc/mscc/ocelot.h | 1 +
4 files changed, 104 insertions(+)
diff --git a/drivers/net/ethernet/mscc/ocelot.h b/drivers/net/ethernet/mscc/ocelot.h
index 8eae68e0fd0b..3fee5f565920 100644
--- a/drivers/net/ethernet/mscc/ocelot.h
+++ b/drivers/net/ethernet/mscc/ocelot.h
@@ -65,6 +65,8 @@ struct ocelot_port_private {
struct phy *serdes;
struct ocelot_port_tc tc;
+
+ struct devlink_port devlink_port;
};
struct ocelot_dump_ctx {
@@ -106,6 +108,8 @@ void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,
struct phy_device *phy);
+int ocelot_devlink_init(struct ocelot *ocelot);
+void ocelot_devlink_teardown(struct ocelot *ocelot);
extern struct notifier_block ocelot_netdevice_nb;
extern struct notifier_block ocelot_switchdev_nb;
diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c
index d3c03942546d..a11e5e7a0228 100644
--- a/drivers/net/ethernet/mscc/ocelot_net.c
+++ b/drivers/net/ethernet/mscc/ocelot_net.c
@@ -8,6 +8,98 @@
#include "ocelot.h"
#include "ocelot_vcap.h"
+struct ocelot_devlink_private {
+ struct ocelot *ocelot;
+};
+
+static const struct devlink_ops ocelot_devlink_ops = {
+};
+
+static int ocelot_port_devlink_init(struct ocelot *ocelot, int port)
+{
+ struct ocelot_port *ocelot_port = ocelot->ports[port];
+ struct devlink *dl = ocelot->devlink;
+ struct devlink_port_attrs attrs = {};
+ struct ocelot_port_private *priv;
+ struct devlink_port *dlp;
+
+ if (!ocelot_port)
+ return 0;
+
+ priv = container_of(ocelot_port, struct ocelot_port_private, port);
+ dlp = &priv->devlink_port;
+
+ attrs.phys.port_number = port;
+
+ if (priv->dev)
+ attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
+ else
+ attrs.flavour = DEVLINK_PORT_FLAVOUR_UNUSED;
+
+ devlink_port_attrs_set(dlp, &attrs);
+
+ return devlink_port_register(dl, dlp, port);
+}
+
+static void ocelot_port_devlink_teardown(struct ocelot *ocelot, int port)
+{
+ struct ocelot_port *ocelot_port = ocelot->ports[port];
+ struct ocelot_port_private *priv;
+ struct devlink_port *dlp;
+
+ if (!ocelot_port)
+ return;
+
+ priv = container_of(ocelot_port, struct ocelot_port_private, port);
+ dlp = &priv->devlink_port;
+
+ devlink_port_unregister(dlp);
+}
+
+int ocelot_devlink_init(struct ocelot *ocelot)
+{
+ struct ocelot_devlink_private *dl_priv;
+ int port, err;
+
+ ocelot->devlink = devlink_alloc(&ocelot_devlink_ops, sizeof(*dl_priv));
+ if (!ocelot->devlink)
+ return -ENOMEM;
+ dl_priv = devlink_priv(ocelot->devlink);
+ dl_priv->ocelot = ocelot;
+
+ err = devlink_register(ocelot->devlink, ocelot->dev);
+ if (err)
+ goto free_devlink;
+
+ for (port = 0; port < ocelot->num_phys_ports; port++) {
+ err = ocelot_port_devlink_init(ocelot, port);
+ if (err) {
+ while (port-- > 0)
+ ocelot_port_devlink_teardown(ocelot, port);
+ goto unregister_devlink;
+ }
+ }
+
+ return 0;
+
+unregister_devlink:
+ devlink_unregister(ocelot->devlink);
+free_devlink:
+ devlink_free(ocelot->devlink);
+ return err;
+}
+
+void ocelot_devlink_teardown(struct ocelot *ocelot)
+{
+ int port;
+
+ for (port = 0; port < ocelot->num_phys_ports; port++)
+ ocelot_port_devlink_teardown(ocelot, port);
+
+ devlink_unregister(ocelot->devlink);
+ devlink_free(ocelot->devlink);
+}
+
int ocelot_setup_tc_cls_flower(struct ocelot_port_private *priv,
struct flow_cls_offload *f,
bool ingress)
diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c
index ea55f4d20ecc..6512ddeafd50 100644
--- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c
+++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c
@@ -1292,6 +1292,12 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
}
}
+ err = ocelot_devlink_init(ocelot);
+ if (err) {
+ mscc_ocelot_release_ports(ocelot);
+ goto out_put_ports;
+ }
+
register_netdevice_notifier(&ocelot_netdevice_nb);
register_switchdev_notifier(&ocelot_switchdev_nb);
register_switchdev_blocking_notifier(&ocelot_switchdev_blocking_nb);
@@ -1307,6 +1313,7 @@ static int mscc_ocelot_remove(struct platform_device *pdev)
{
struct ocelot *ocelot = platform_get_drvdata(pdev);
+ ocelot_devlink_teardown(ocelot);
ocelot_deinit_timestamp(ocelot);
mscc_ocelot_release_ports(ocelot);
ocelot_deinit(ocelot);
diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h
index c6153c73dbfe..19ce7ea11163 100644
--- a/include/soc/mscc/ocelot.h
+++ b/include/soc/mscc/ocelot.h
@@ -599,6 +599,7 @@ struct ocelot_port {
struct ocelot {
struct device *dev;
+ struct devlink *devlink;
const struct ocelot_ops *ops;
struct regmap *targets[TARGET_MAX];
--
2.25.1
next prev parent reply other threads:[~2020-10-13 13:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-13 13:48 [RFC PATCH 00/10] Configuring congestion watermarks on ocelot switch using devlink-sb Vladimir Oltean
2020-10-13 13:48 ` [RFC PATCH 01/10] net: mscc: ocelot: auto-detect packet buffer size and number of frame references Vladimir Oltean
2020-10-13 13:48 ` [RFC PATCH 02/10] net: mscc: ocelot: add ops for decoding watermark threshold and occupancy Vladimir Oltean
2020-10-13 13:48 ` [RFC PATCH 03/10] net: dsa: add ops for devlink-sb Vladimir Oltean
2020-10-13 13:48 ` [RFC PATCH 04/10] net: dsa: felix: reindent struct dsa_switch_ops Vladimir Oltean
2020-10-13 13:48 ` [RFC PATCH 05/10] net: dsa: felix: perform teardown in reverse order of setup Vladimir Oltean
2020-10-13 13:48 ` [RFC PATCH 06/10] net: mscc: ocelot: export NUM_TC constant from felix to common switch lib Vladimir Oltean
2020-10-13 13:48 ` [RFC PATCH 07/10] net: mscc: ocelot: delete unused ocelot_set_cpu_port prototype Vladimir Oltean
2020-10-13 13:48 ` Vladimir Oltean [this message]
2020-10-13 14:13 ` [RFC PATCH 08/10] net: mscc: ocelot: register devlink ports Jiri Pirko
2020-10-13 13:48 ` [RFC PATCH 09/10] net: mscc: ocelot: initialize watermarks to sane defaults Vladimir Oltean
2020-10-13 13:48 ` [RFC PATCH 10/10] net: mscc: ocelot: configure watermarks using devlink-sb Vladimir Oltean
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=20201013134849.395986-9-vladimir.oltean@nxp.com \
--to=vladimir.oltean@nxp.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandru.marginean@nxp.com \
--cc=andrew@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=f.fainelli@gmail.com \
--cc=hongbo.wang@nxp.com \
--cc=idosch@idosch.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@gmail.com \
--cc=xiaoliang.yang_1@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;
as well as URLs for NNTP newsgroup(s).