From: Vladimir Oltean <olteanv@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org, 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, jiri@resnulli.us,
idosch@idosch.org, UNGLinuxDriver@microchip.com
Subject: Re: [PATCH v3 net-next 08/10] net: mscc: ocelot: register devlink ports
Date: Mon, 11 Jan 2021 19:13:44 +0200 [thread overview]
Message-ID: <20210111171344.j6chsp5djr5t5ykk@skbuf> (raw)
In-Reply-To: <20210109174439.404713f6@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
On Sat, Jan 09, 2021 at 05:44:39PM -0800, Jakub Kicinski wrote:
> On Fri, 8 Jan 2021 19:59:48 +0200 Vladimir Oltean wrote:
> > From: Vladimir Oltean <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.
> >
> > Since we use devlink_port_type_eth_set to link the devlink port to the
> > net_device, we can as well remove the .ndo_get_phys_port_name and
> > .ndo_get_port_parent_id implementations, since devlink takes care of
> > retrieving the port name and number automatically, once
> > .ndo_get_devlink_port is implemented.
> >
> > 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. This is
> > the reason why these devlink stubs were put in ocelot_net.c and not in
> > the common library.
> >
> > Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
>
> > diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c
> > index 2bd2840d88bd..d0d98c6adea8 100644
> > --- a/drivers/net/ethernet/mscc/ocelot_net.c
> > +++ b/drivers/net/ethernet/mscc/ocelot_net.c
> > @@ -8,6 +8,116 @@
> > #include "ocelot.h"
> > #include "ocelot_vcap.h"
> >
> > +struct ocelot_devlink_private {
> > + struct ocelot *ocelot;
> > +};
>
> Why not make struct ocelot part of devlink_priv?
I am not sure what you mean.
> > +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];
> > + int id_len = sizeof(ocelot->base_mac);
> > + struct devlink *dl = ocelot->devlink;
> > + struct devlink_port_attrs attrs = {};
> > + struct ocelot_port_private *priv;
> > + struct devlink_port *dlp;
> > + int err;
> > +
> > + if (!ocelot_port)
> > + return 0;
> > +
> > + priv = container_of(ocelot_port, struct ocelot_port_private, port);
> > + dlp = &priv->devlink_port;
> > +
> > + memcpy(attrs.switch_id.id, &ocelot->base_mac, id_len);
> > + attrs.switch_id.id_len = id_len;
> > + 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);
> > +
> > + err = devlink_port_register(dl, dlp, port);
> > + if (err)
> > + return err;
> > +
> > + if (priv->dev)
> > + devlink_port_type_eth_set(dlp, priv->dev);
>
> devlink_port_attrs_set() should be called before netdev is registered,
> and devlink_port_type_eth_set() after. So this sequence makes me a tad
> suspicious.
>
> In particular IIRC devlink's .ndo_get_phys_port_name depends on it,
> because udev event needs to carry the right info for interface renaming
> to work reliably. No?
>
If I change the driver's Kconfig from tristate to bool, all is fine,
isn't it?
> > + return 0;
> > +}
> > +
> > +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;
>
> nit: should this also be on the error path below?
>
> > + }
> > + }
> > +
> > + return 0;
> > +
> > +unregister_devlink:
> > + devlink_unregister(ocelot->devlink);
> > +free_devlink:
> > + devlink_free(ocelot->devlink);
> > + return err;
> > +}
>
> > --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c
> > +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c
> > @@ -1293,6 +1293,12 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
> > }
> > }
> >
> > + err = ocelot_devlink_init(ocelot);
> > + if (err) {
> > + mscc_ocelot_release_ports(ocelot);
> > + goto out_ocelot_deinit;
>
> No need to add ocelot_deinit_timestamp(ocelot); to the error path?
Yes, the error handling could be better.
next prev parent reply other threads:[~2021-01-11 17:14 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-08 17:59 [PATCH v3 net-next 00/10] Configuring congestion watermarks on ocelot switch using devlink-sb Vladimir Oltean
2021-01-08 17:59 ` [PATCH v3 net-next 01/10] net: mscc: ocelot: auto-detect packet buffer size and number of frame references Vladimir Oltean
2021-01-08 18:30 ` Florian Fainelli
2021-01-08 17:59 ` [PATCH v3 net-next 02/10] net: mscc: ocelot: add ops for decoding watermark threshold and occupancy Vladimir Oltean
2021-01-08 18:30 ` Florian Fainelli
2021-01-10 1:20 ` Jakub Kicinski
2021-01-11 16:53 ` Vladimir Oltean
2021-01-11 19:10 ` Jakub Kicinski
2021-01-08 17:59 ` [PATCH v3 net-next 03/10] net: dsa: add ops for devlink-sb Vladimir Oltean
2021-01-08 18:20 ` Andrew Lunn
2021-01-08 18:31 ` Florian Fainelli
2021-01-08 17:59 ` [PATCH v3 net-next 04/10] net: dsa: felix: reindent struct dsa_switch_ops Vladimir Oltean
2021-01-08 18:33 ` Florian Fainelli
2021-01-10 1:24 ` Jakub Kicinski
2021-01-11 17:01 ` Vladimir Oltean
2021-01-11 19:12 ` Jakub Kicinski
2021-01-08 17:59 ` [PATCH v3 net-next 05/10] net: dsa: felix: perform teardown in reverse order of setup Vladimir Oltean
2021-01-08 18:34 ` Florian Fainelli
2021-01-08 17:59 ` [PATCH v3 net-next 06/10] net: mscc: ocelot: export NUM_TC constant from felix to common switch lib Vladimir Oltean
2021-01-08 18:34 ` Florian Fainelli
2021-01-08 17:59 ` [PATCH v3 net-next 07/10] net: mscc: ocelot: delete unused ocelot_set_cpu_port prototype Vladimir Oltean
2021-01-08 18:35 ` Florian Fainelli
2021-01-08 17:59 ` [PATCH v3 net-next 08/10] net: mscc: ocelot: register devlink ports Vladimir Oltean
2021-01-08 18:36 ` Florian Fainelli
2021-01-10 1:44 ` Jakub Kicinski
2021-01-11 17:13 ` Vladimir Oltean [this message]
2021-01-11 19:19 ` Jakub Kicinski
2021-01-14 10:34 ` Vladimir Oltean
2021-01-14 16:44 ` Jakub Kicinski
2021-01-15 17:11 ` Renaming interfaces that are up (Was "Re: [PATCH v3 net-next 08/10] net: mscc: ocelot: register devlink") ports Vladimir Oltean
2021-01-15 19:54 ` Vladimir Oltean
2021-01-10 2:01 ` [PATCH v3 net-next 08/10] net: mscc: ocelot: register devlink ports Jakub Kicinski
2021-01-08 17:59 ` [PATCH v3 net-next 09/10] net: mscc: ocelot: initialize watermarks to sane defaults Vladimir Oltean
2021-01-09 3:59 ` Florian Fainelli
2021-01-08 17:59 ` [PATCH v3 net-next 10/10] net: mscc: ocelot: configure watermarks using devlink-sb Vladimir Oltean
2021-01-09 4:03 ` Florian Fainelli
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=20210111171344.j6chsp5djr5t5ykk@skbuf \
--to=olteanv@gmail.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