mv88e6xxx: Add per port devlink regions
Subsystems (5)
Andrew Lunn
maintainerv2 cover mv88e6xxx: Add per port devlink regions
This patchset extends devlink regions to support per port regions, and them makes use of them to support the ports of the mv88e6xxx switches.
root@rap:~# devlink region show mdio_bus/gpio-0:00/global1: size 64 snapshot [] mdio_bus/gpio-0:00/global2: size 64 snapshot [] mdio_bus/gpio-0:00/atu: size 49152 snapshot [] mdio_bus/gpio-0:00/0/port: size 64 snapshot [] mdio_bus/gpio-0:00/1/port: size 64 snapshot [] mdio_bus/gpio-0:00/2/port: size 64 snapshot [] mdio_bus/gpio-0:00/3/port: size 64 snapshot [] mdio_bus/gpio-0:00/4/port: size 64 snapshot [] mdio_bus/gpio-0:00/5/port: size 64 snapshot [] mdio_bus/gpio-0:00/6/port: size 64 snapshot [] mdio_bus/gpio-0:00/7/port: size 64 snapshot [] mdio_bus/gpio-0:00/8/port: size 64 snapshot [] mdio_bus/gpio-0:00/9/port: size 64 snapshot [] mdio_bus/gpio-0:00/10/port: size 64 snapshot []
root@rap:~# devlink region new mdio_bus/gpio-0:00/1/port snapshot 42 root@rap:~# devlink region dump mdio_bus/gpio-0:00/1/port snapshot 42 0000000000000000 4f 1e 3e 20 00 01 01 39 3f 05 00 00 fd 07 00 00 0000000000000010 80 00 01 00 00 00 00 00 00 00 00 00 00 00 00 91 0000000000000020 00 00 00 00 00 00 00 00 00 00 00 00 22 00 00 00 0000000000000030 07 3e 00 00 00 00 00 80 00 00 00 00 00 00 5b 00
In order to support all ports of the switch, a new devlink flavour has been added for unused ports:
# devlink port show mdio_bus/gpio-0:00/0: type notset flavour unused splittable false mdio_bus/gpio-0:00/1: type notset flavour cpu port 1 splittable false mdio_bus/gpio-0:00/2: type eth netdev red flavour physical port 2 splittable fae mdio_bus/gpio-0:00/3: type eth netdev blue flavour physical port 3 splittable fe mdio_bus/gpio-0:00/4: type eth netdev green flavour physical port 4 splittable e mdio_bus/gpio-0:00/5: type notset flavour unused splittable false mdio_bus/gpio-0:00/6: type notset flavour unused splittable false mdio_bus/gpio-0:00/7: type notset flavour unused splittable false mdio_bus/gpio-0:00/8: type eth netdev waic0 flavour physical port 8 splittable e mdio_bus/gpio-0:00/9: type notset flavour unused splittable false mdio_bus/gpio-0:00/10: type notset flavour unused splittable false
The DSA core now creates the devlink port instances earlier, so that the driver setup function can make use of them.
Andrew Lunn (7):
net: devlink: Add unused port flavour
net: dsa: Make use of devlink port flavour unused
net: dsa: Register devlink ports before calling DSA driver setup()
net: devlink: Add support for port regions
net: dsa: Add devlink port regions support to DSA
net: dsa: Add helper for converting devlink port to ds and port
net: dsa: mv88e6xxx: Add per port devlink regions
drivers/net/dsa/mv88e6xxx/devlink.c | 109 +++++++++++- include/net/devlink.h | 27 +++ include/net/dsa.h | 20 +++ include/uapi/linux/devlink.h | 3 + net/core/devlink.c | 254 +++++++++++++++++++++++++--- net/dsa/dsa.c | 14 ++ net/dsa/dsa2.c | 123 +++++++++----- 7 files changed, 478 insertions(+), 72 deletions(-)
Signature · 1 line
2.28.0
Andrew Lunn
maintainerPATCH v2 1/7 net: devlink: Add unused port flavour
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
--- include/uapi/linux/devlink.h | 3 +++ net/core/devlink.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-)
include/uapi/linux/devlink.h +3 -0
@@ -195,6 +195,9 @@ enum devlink_port_flavour {* port that faces the PCI VF. */ DEVLINK_PORT_FLAVOUR_VIRTUAL ,/* Any virtual port facing the user. */ + DEVLINK_PORT_FLAVOUR_UNUSED, /* Port which exists in the switch, but + * is not used in any way. + */ }; enum devlink_param_cmode {
net/core/devlink.c +3 -1
@@ -7569,7 +7569,8 @@ static bool devlink_port_type_should_warn(struct devlink_port *devlink_port) {/* Ignore CPU and DSA flavours. */ return devlink_port->attrs.flavour !=DEVLINK_PORT_FLAVOUR_CPU && - devlink_port->attrs.flavour !=DEVLINK_PORT_FLAVOUR_DSA ; + devlink_port->attrs.flavour !=DEVLINK_PORT_FLAVOUR_DSA && + devlink_port->attrs.flavour !=DEVLINK_PORT_FLAVOUR_UNUSED ; }#define DEVLINK_PORT_TYPE_WARN_TIMEOUT (HZ * 3600)
@@ -7854,6 +7855,7 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,break ;case DEVLINK_PORT_FLAVOUR_CPU :case DEVLINK_PORT_FLAVOUR_DSA : +case DEVLINK_PORT_FLAVOUR_UNUSED :/* As CPU and DSA ports do not have a netdevice associated * case should not ever happen. */
Signature · 1 line
2.28.0
Vladimir Oltean
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 16 lines · Andrew Lunn
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
Signed-off-by Andrew Lunn <[email protected]>--- include/uapi/linux/devlink.h | 3 +++ net/core/devlink.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-)include/uapi/linux/devlink.h +0
-0
include/uapi/linux/devlink.h enum devlink_port_flavour { · line 199
Quoted 5 lines
include/uapi/linux/devlink.h +2
-0@@ -195,6 +195,9 @@ enum devlink_port_flavour {* port that faces the PCI VF. */ DEVLINK_PORT_FLAVOUR_VIRTUAL ,/* Any virtual port facing the user. */ + DEVLINK_PORT_FLAVOUR_UNUSED, /* Port which exists in the switch, but +* is not used in any way.
Nitpicking: there is an extraneous tab character here between "*" and "is".
Quoted 29 lines
include/uapi/linux/devlink.h +1
-0+*/ };enum devlink_param_cmode {net/core/devlink.c +3
-1@@ -7569,7 +7569,8 @@ static bool devlink_port_type_should_warn(struct devlink_port *devlink_port) {/* Ignore CPU and DSA flavours. */ return devlink_port->attrs.flavour !=DEVLINK_PORT_FLAVOUR_CPU && - devlink_port->attrs.flavour !=DEVLINK_PORT_FLAVOUR_DSA ; + devlink_port->attrs.flavour !=DEVLINK_PORT_FLAVOUR_DSA && + devlink_port->attrs.flavour !=DEVLINK_PORT_FLAVOUR_UNUSED ; }#define DEVLINK_PORT_TYPE_WARN_TIMEOUT (HZ * 3600)@@ -7854,6 +7855,7 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,break ;case DEVLINK_PORT_FLAVOUR_CPU :case DEVLINK_PORT_FLAVOUR_DSA : +case DEVLINK_PORT_FLAVOUR_UNUSED :/* As CPU and DSA ports do not have a netdevice associated * case should not ever happen. */ Signature · 1 line
2.28.0
Vladimir Oltean
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
In reply to Andrew LunnQuoted 7 lines · Andrew Lunn
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
Signed-off-by Andrew Lunn <[email protected]>---
You also have an iproute2 patch prepared, right?
$ devlink port spi/spi0.1/0: type notset flavour <unknown flavour> <- this should read "unused" spi/spi0.1/1: type eth netdev swp2 flavour physical port 1 spi/spi0.1/2: type eth netdev swp3 flavour physical port 2 spi/spi0.1/3: type eth netdev swp4 flavour physical port 3 spi/spi0.1/4: type notset flavour cpu port 4
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 10 lines · Vladimir Oltean
Quoted 7 lines · Andrew Lunn
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
Signed-off-by Andrew Lunn <[email protected]>---
You also have an iproute2 patch prepared, right?
https://github.com/lunn/iproute2 port-regions
Andrew
Jakub Kicinski
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
In reply to Andrew LunnQuoted 4 lines · On Sat, 26 Sep 2020 23:06:26 +0200 Andrew Lunn wrote:
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
This is missing the explanation of why reporting such ports makes sense.
Re: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Sat, 26 Sep 2020 23:06:26 +0200 Andrew Lunn wrote:
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
This is missing the explanation of why reporting such ports makes sense.
Because this is a core devlink patch, we're talking really generalistic here. And since devlink regions are a debugging features, it makes sense to tell a debugging story. Let's say there is a switch which had configured all its ports to be part of the flooding replication lists, but also configured other things incorrectly such that attempting to flood a frame to a disabled port would leak a memory buffer. After enough time, the system would lock up. So unused ports are not absent from the system and they might even make a difference if the procedure to disable a port is buggy (and there would be no debugging without bugs, right?). I see no reason why we would hide them. Devlink ports are not net devices, I thought that was the whole point, to have insight into the hardware and not have to deal with an approximate abstraction.
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 11 lines · Vladimir Oltean
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Sat, 26 Sep 2020 23:06:26 +0200 Andrew Lunn wrote:
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
This is missing the explanation of why reporting such ports makes sense.
Because this is a core devlink patch, we're talking really generalistic here.
Hi Vladimir
I don't think Jakub is questioning the why. He just wants it in the commit message.
Andrew
Jakub Kicinski
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 10 lines · On Tue, 29 Sep 2020 00:07:30 +0200 Andrew Lunn wrote:
Quoted 9 lines · Vladimir Oltean
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Sat, 26 Sep 2020 23:06:26 +0200 Andrew Lunn wrote:
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
This is missing the explanation of why reporting such ports makes sense.
Quoted 7 lines
Quoted 2 lines
Because this is a core devlink patch, we're talking really generalistic here.
Hi Vladimir
I don't think Jakub is questioning the why. He just wants it in the commit message.
Ack, I think we need to clearly say when those should be exposed. Most ASICs will have disabled ports, and we don't expect NICs to suddenly start reporting ports for all PCI PFs they may have.
Also I keep thinking that these ports and all their objects should be hidden under some switch from user space perspective because they are unlikely to be valuable to see for a normal user. Thoughts?
Re: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 19 lines · Jakub Kicinski
Quoted 10 lines · On Tue, 29 Sep 2020 00:07:30 +0200 Andrew Lunn wrote:
Quoted 9 lines · Vladimir Oltean
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Sat, 26 Sep 2020 23:06:26 +0200 Andrew Lunn wrote:
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
This is missing the explanation of why reporting such ports makes sense.
Quoted 7 lines
Quoted 2 lines
Because this is a core devlink patch, we're talking really generalistic here.
Hi Vladimir
I don't think Jakub is questioning the why. He just wants it in the commit message.
Quoted 7 lines
Ack, I think we need to clearly say when those should be exposed. Most ASICs will have disabled ports, and we don't expect NICs to suddenly start reporting ports for all PCI PFs they may have.
Also I keep thinking that these ports and all their objects should be hidden under some switch from user space perspective because they are unlikely to be valuable to see for a normal user. Thoughts?
Hidden in what sense? They are already hidden in that there is no net_device object being created for them. Are you asking for adding another option to say, devlink show like:
devlink show -a
which would also show the ports that are disabled during a dump?
Signature · 1 line
Florian
Jakub Kicinski
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 28 lines · On Mon, 28 Sep 2020 15:36:50 -0700 Florian Fainelli wrote:
Quoted 19 lines · Jakub Kicinski
Quoted 10 lines · On Tue, 29 Sep 2020 00:07:30 +0200 Andrew Lunn wrote:
Quoted 9 lines · Vladimir Oltean
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Sat, 26 Sep 2020 23:06:26 +0200 Andrew Lunn wrote:
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
This is missing the explanation of why reporting such ports makes sense.
Quoted 7 lines
Quoted 2 lines
Because this is a core devlink patch, we're talking really generalistic here.
Hi Vladimir
I don't think Jakub is questioning the why. He just wants it in the commit message.
Quoted 7 lines
Ack, I think we need to clearly say when those should be exposed. Most ASICs will have disabled ports, and we don't expect NICs to suddenly start reporting ports for all PCI PFs they may have.
Also I keep thinking that these ports and all their objects should be hidden under some switch from user space perspective because they are unlikely to be valuable to see for a normal user. Thoughts?
Quoted 7 lines
Hidden in what sense? They are already hidden in that there is no
net_deviceobject being created for them. Are you asking for adding another option to say, devlink show like:devlink show -a
which would also show the ports that are disabled during a dump?
Yup, exactly. Looks like ip uses -a for something I don't quite understand - but some switch along those lines. We already have -d for hiding less-relevant attributes.
Do you think this is an overkill? I don't feel strongly.
Re: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 35 lines · Jakub Kicinski
Quoted 34 lines · On Mon, 28 Sep 2020 15:36:50 -0700 Florian Fainelli wrote:
Quoted 19 lines · Jakub Kicinski
Quoted 10 lines · On Tue, 29 Sep 2020 00:07:30 +0200 Andrew Lunn wrote:
Quoted 9 lines · Vladimir Oltean
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Sat, 26 Sep 2020 23:06:26 +0200 Andrew Lunn wrote:
Not all ports of a switch need to be used, particularly in embedded systems. Add a port flavour for ports which physically exist in the switch, but are not connected to the front panel etc, and so are unused.
This is missing the explanation of why reporting such ports makes sense.
Quoted 7 lines
Quoted 2 lines
Because this is a core devlink patch, we're talking really generalistic here.
Hi Vladimir
I don't think Jakub is questioning the why. He just wants it in the commit message.
Quoted 7 lines
Ack, I think we need to clearly say when those should be exposed. Most ASICs will have disabled ports, and we don't expect NICs to suddenly start reporting ports for all PCI PFs they may have.
Also I keep thinking that these ports and all their objects should be hidden under some switch from user space perspective because they are unlikely to be valuable to see for a normal user. Thoughts?
Hidden in what sense? They are already hidden in that there is no
net_deviceobject being created for them. Are you asking for adding another option to say, devlink show like:devlink show -a
Quoted 7 lines
Quoted 1 line
which would also show the ports that are disabled during a dump?
Yup, exactly. Looks like ip uses -a for something I don't quite understand - but some switch along those lines. We already have -d for hiding less-relevant attributes.
Do you think this is an overkill? I don't feel strongly.
That makes sense to me as it would be confusing to suddenly show unused port flavors after this patch series land. Andrew, Vladimir, does that work for you as well?
Signature · 1 line
Florian
Re: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 3 lines · Florian Fainelli
That makes sense to me as it would be confusing to suddenly show unused port flavors after this patch series land. Andrew, Vladimir, does that work for you as well?
I have nothing to object against somebody adding a '--all' argument to devlink port commands.
Jiri Pirko
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 7 lines · Tue, Sep 29, 2020 at 01:03:56PM CEST, [email protected] wrote:
Quoted 3 lines · Florian Fainelli
That makes sense to me as it would be confusing to suddenly show unused port flavors after this patch series land. Andrew, Vladimir, does that work for you as well?
I have nothing to object against somebody adding a '--all' argument to devlink port commands.
How "unused" is a "flavour"? It seems to me more like a separate attribute as port of any "flavour" may be potentially "unused". I don't think we should mix these 2.
Re: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 6 lines · Jiri Pirko
Quoted 5 lines · Tue, Sep 29, 2020 at 01:03:56PM CEST, [email protected] wrote:
Quoted 3 lines · Florian Fainelli
That makes sense to me as it would be confusing to suddenly show unused port flavors after this patch series land. Andrew, Vladimir, does that work for you as well?
Quoted 7 lines
Quoted 2 lines
I have nothing to object against somebody adding a '--all' argument to devlink port commands.
How "unused" is a "flavour"? It seems to me more like a separate attribute as port of any "flavour" may be potentially "unused". I don't think we should mix these 2.
I guess it's you who suggested it might make sense to add an "unused" port flavour?
Quoted 2 lines
Okay. That looks fine. I wonder if it would make sense to have another flavour for "unused" ports.
https://patchwork.ozlabs.org/project/netdev/cover/[email protected]/
Thanks,
-Vladimir
Jiri Pirko
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 10 lines · Tue, Sep 29, 2020 at 03:48:56PM CEST, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
Quoted 7 lines · Tue, Sep 29, 2020 at 01:03:56PM CEST, [email protected] wrote:
Quoted 3 lines · Florian Fainelli
That makes sense to me as it would be confusing to suddenly show unused port flavors after this patch series land. Andrew, Vladimir, does that work for you as well?
I have nothing to object against somebody adding a '--all' argument to devlink port commands.
Quoted 7 lines
Quoted 4 lines
How "unused" is a "flavour"? It seems to me more like a separate attribute as port of any "flavour" may be potentially "unused". I don't think we should mix these 2.
I guess it's you who suggested it might make sense to add an "unused" port flavour?
Maybe, but that was just an idea. 2 years later, I don't think it is a good idea.
Quoted 8 lines
Quoted 3 lines
Okay. That looks fine. I wonder if it would make sense to have another flavour for "unused" ports.
https://patchwork.ozlabs.org/project/netdev/cover/[email protected]/
Thanks,
-Vladimir
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
In reply to Jiri PirkoQuoted 6 lines · Jiri Pirko
Quoted 5 lines · Tue, Sep 29, 2020 at 01:03:56PM CEST, [email protected] wrote:
Quoted 3 lines · Florian Fainelli
That makes sense to me as it would be confusing to suddenly show unused port flavors after this patch series land. Andrew, Vladimir, does that work for you as well?
Quoted 6 lines
Quoted 2 lines
I have nothing to object against somebody adding a '--all' argument to devlink port commands.
How "unused" is a "flavour"? It seems to me more like a separate attribute as port of any "flavour" may be potentially "unused". I don't think we should mix these 2.
Hi Jiri
Current flavours are:
enum devlink_port_flavour {
DEVLINK_PORT_FLAVOUR_PHYSICAL, /* Any kind of a port physically
* facing the user.
*/
DEVLINK_PORT_FLAVOUR_CPU, /* CPU port */ DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
* interconnect port.
*/
DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
* the PCI PF. It is an internal
* port that faces the PCI PF. */
DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
* for the PCI VF. It is an internal
* port that faces the PCI VF. */
DEVLINK_PORT_FLAVOUR_VIRTUAL, /* Any virtual port facing the user. */
};
A port in the DSA world is generally just a port on the switch. It is not limited in nature. It can be used as a PHYSICAL, or CPU, or a DSA port. We don't consider them as unused PHYISCAL ports, or unused CPU ports. They are just unused ports. Which is why i added an UNUSED flavour.
Now, it could be this world view is actually just a DSA world view. Maybe some ASICs have strict roles for their ports? They are not configurable? And then i could see it being an attribute? But that messes up the DSA world view :-(
Andrew
Jiri Pirko
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 37 lines · Tue, Sep 29, 2020 at 03:57:00PM CEST, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
Quoted 5 lines · Tue, Sep 29, 2020 at 01:03:56PM CEST, [email protected] wrote:
Quoted 3 lines · Florian Fainelli
That makes sense to me as it would be confusing to suddenly show unused port flavors after this patch series land. Andrew, Vladimir, does that work for you as well?
Quoted 6 lines
Quoted 2 lines
I have nothing to object against somebody adding a '--all' argument to devlink port commands.
How "unused" is a "flavour"? It seems to me more like a separate attribute as port of any "flavour" may be potentially "unused". I don't think we should mix these 2.
Hi Jiri
Current flavours are:
enum
devlink_port_flavour{
DEVLINK_PORT_FLAVOUR_PHYSICAL, /* Any kind of a port physically
* facing the user.
*/
DEVLINK_PORT_FLAVOUR_CPU, /* CPU port */DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
* interconnect port.
*/
DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
* the PCI PF. It is an internal
* port that faces the PCI PF. */
DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
* for the PCI VF. It is an internal
* port that faces the PCI VF. */
DEVLINK_PORT_FLAVOUR_VIRTUAL, /* Any virtual port facing the user. */
};
Quoted 5 lines
A port in the DSA world is generally just a port on the switch. It is not limited in nature. It can be used as a PHYSICAL, or CPU, or a DSA port. We don't consider them as unused PHYISCAL ports, or unused CPU ports. They are just unused ports. Which is why i added an UNUSED flavour.
I get it. But I as I wrote previously, I wonder if used/unused should not be another attribute. Then the flavour can be "undefined".
But, why do you want to show "unused" ports? Can the user do something with them? What is the value in showing them?
Quoted 7 lines
Now, it could be this world view is actually just a DSA world view. Maybe some ASICs have strict roles for their ports? They are not configurable? And then i could see it being an attribute? But that messes up the DSA world view :-(
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 2 lines
I get it. But I as I wrote previously, I wonder if used/unused should not be another attribute. Then the flavour can be "undefined".
In the DSA world, it is not undefined. It is clear defined as unused. And it cannot be on-the-fly changed. It is a property of the PCB, in that the pins exist on the chip, but they simply don't go anywhere on the PCB. This is quite common on appliances, e.g. The switch has 7 ports, but the installation in the aircraft is a big ring, so there is a 'left', 'right', 'aux' and the CPU port. That leaves 3 ports totally unused.
Quoted 2 lines
But, why do you want to show "unused" ports? Can the user do something with them? What is the value in showing them?
Because they are just ports, they can have regions. We can look at the region and be sure they are powered off, the boot loader etc has not left them in a funny state, bridged to other ports, etc.
Regions are a developers tool, not a 'user' tools. So the idea of hiding them by default in 'devlink port show' does make some sense, and have a flag like -d for details, which includes them. In 'devlink region show' i would probably list all regions, independent of any -d flag.
Andrew
Jiri Pirko
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 10 lines · Wed, Sep 30, 2020 at 03:57:25PM CEST, [email protected] wrote:
Quoted 2 lines
I get it. But I as I wrote previously, I wonder if used/unused should not be another attribute. Then the flavour can be "undefined".
In the DSA world, it is not undefined. It is clear defined as unused. And it cannot be on-the-fly changed. It is a property of the PCB, in that the pins exist on the chip, but they simply don't go anywhere on the PCB. This is quite common on appliances, e.g. The switch has 7 ports, but the installation in the aircraft is a big ring, so there is a 'left', 'right', 'aux' and the CPU port. That leaves 3 ports totally unused.
Understand the DSA usecase.
Quoted 5 lines
Quoted 3 lines
But, why do you want to show "unused" ports? Can the user do something with them? What is the value in showing them?
Because they are just ports, they can have regions. We can look at the
What do you mean by "regions"? Devlink regions? They are per-device, not per-port. I have to be missing something.
Quoted 2 lines
region and be sure they are powered off, the boot loader etc has not left them in a funny state, bridged to other ports, etc.
It is driver's responsibility to ensure that. But that does not mean that the devlink port needs to be visible.
Quoted 8 lines
Regions are a developers tool, not a 'user' tools. So the idea of hiding them by default in 'devlink port show' does make some sense, and have a flag like -d for details, which includes them. In 'devlink region show' i would probably list all regions, independent of any -d flag.
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 2 lines
What do you mean by "regions"? Devlink regions? They are per-device, not per-port. I have to be missing something.
The rest of the patch series, which add regions per port! This came out of the discussion from the first version of this patchset, and Jakub said it would make sense to add per port regions, rather than have regions which embedded a port number in there name.
Andrew
Jiri Pirko
maintainerRe: [PATCH net-next v2 1/7] net: devlink: Add unused port flavour
Quoted 4 lines · Wed, Sep 30, 2020 at 04:53:57PM CEST, [email protected] wrote:
Quoted 2 lines
What do you mean by "regions"? Devlink regions? They are per-device, not per-port. I have to be missing something.
The rest of the patch series, which add regions per port! This came
Okay. Sorry about that. netdev ml kicked me out so I didn't receive emails from it for couple of days :/
Quoted 3 lines
out of the discussion from the first version of this patchset, and Jakub said it would make sense to add per port regions, rather than have regions which embedded a port number in there name.
For sure. If something is per-port, should be per-port. I agree.
Quoted 3 lines
Andrew
Andrew Lunn
maintainerPATCH v2 2/7 net: dsa: Make use of devlink port flavour unused
In reply to Andrew LunnIf a port is unused, still create a devlink port for it, but set the flavour to unused. This allows us to attach devlink regions to the port, etc.
--- net/dsa/dsa2.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/dsa/dsa2.c +10 -0
@@ -272,6 +272,15 @@ static int dsa_port_setup(struct dsa_port *dp)switch (dp->type) {case DSA_PORT_TYPE_UNUSED : +memset (dlp,0 ,sizeof (*dlp)); + attrs.flavour =DEVLINK_PORT_FLAVOUR_UNUSED ; +devlink_port_attrs_set (dlp, &attrs); + err =devlink_port_register (dl, dlp, dp->index); +if (err) +break ; + + devlink_port_registered = true; +dsa_port_disable (dp);break ;case DSA_PORT_TYPE_CPU :
@@ -355,6 +364,7 @@ static void dsa_port_teardown(struct dsa_port *dp)switch (dp->type) {case DSA_PORT_TYPE_UNUSED : +devlink_port_unregister (dlp);break ;case DSA_PORT_TYPE_CPU :dsa_port_disable (dp);
Signature · 1 line
2.28.0
Re: [PATCH net-next v2 2/7] net: dsa: Make use of devlink port flavour unused
Quoted 6 lines · Andrew Lunn
If a port is unused, still create a devlink port for it, but set the flavour to unused. This allows us to attach devlink regions to the port, etc.
Signed-off-by Andrew Lunn <[email protected]>---
Andrew Lunn
maintainerPATCH v2 3/7 net: dsa: Register devlink ports before calling DSA driver setup()
In reply to Andrew LunnDSA drivers want to create regions on devlink ports as well as the devlink device instance, in order to export registers and other tables per port. To keep all this code together in the drivers, have the devlink ports registered early, so the setup() method can setup both device and port devlink regions.
--- include/net/dsa.h | 1 + net/dsa/dsa2.c | 133 ++++++++++++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 51 deletions(-)
include/net/dsa.h +1 -0
@@ -208,6 +208,7 @@ struct dsa_port {u8 stp_state;struct net_device *bridge_dev;struct devlink_port devlink_port; +bool devlink_port_setup;struct phylink *pl;struct phylink_config pl_config;
net/dsa/dsa2.c +82 -51
231 lines not on this page · raw message
Signature · 1 line
2.28.0
Vladimir Oltean
maintainerRe: [PATCH net-next v2 3/7] net: dsa: Register devlink ports before calling DSA driver setup()
Quoted 130 lines · Andrew Lunn
DSA drivers want to create regions on devlink ports as well as the devlink device instance, in order to export registers and other tables per port. To keep all this code together in the drivers, have the devlink ports registered early, so the
setup()method can setup both device and port devlink regions.Signed-off-by Andrew Lunn <[email protected]>--- include/net/dsa.h | 1 + net/dsa/dsa2.c | 133 ++++++++++++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 51 deletions(-)include/net/dsa.h +1
-0@@ -208,6 +208,7 @@ struct dsa_port {u8 stp_state;struct net_device *bridge_dev;struct devlink_port devlink_port; +bool devlink_port_setup;struct phylink *pl;struct phylink_config pl_config;net/dsa/dsa2.c +8
-47@@ -251,47 +251,19 @@ static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)static int dsa_port_setup (struct dsa_port *dp) { -struct dsa_switch *ds = dp->ds; -struct dsa_switch_tree *dst = ds->dst; -const unsigned char *id = (const unsigned char *)&dst->index; -const unsigned char len =sizeof (dst->index);struct devlink_port *dlp = &dp->devlink_port;bool dsa_port_link_registered = false; -bool devlink_port_registered = false; -struct devlink_port_attrs attrs = {}; -struct devlink *dl = ds->devlink;bool dsa_port_enabled = false;int err =0 ; - attrs.phys.port_number = dp->index; -memcpy (attrs.switch_id.id, id, len); - attrs.switch_id.id_len = len; -if (dp->setup)return 0 ;switch (dp->type) {case DSA_PORT_TYPE_UNUSED : -memset (dlp,0 ,sizeof (*dlp)); - attrs.flavour =DEVLINK_PORT_FLAVOUR_UNUSED ; -devlink_port_attrs_set (dlp, &attrs); - err =devlink_port_register (dl, dlp, dp->index); -if (err) -break ; - - devlink_port_registered = true; -dsa_port_disable (dp);break ;case DSA_PORT_TYPE_CPU : -memset (dlp,0 ,sizeof (*dlp)); - attrs.flavour =DEVLINK_PORT_FLAVOUR_CPU ; -devlink_port_attrs_set (dlp, &attrs); - err =devlink_port_register (dl, dlp, dp->index); -if (err) -break ; - devlink_port_registered = true; - err =dsa_port_link_register_of (dp);if (err)break ;@@ -304,14 +276,6 @@ static int dsa_port_setup(struct dsa_port *dp)break ;case DSA_PORT_TYPE_DSA : -memset (dlp,0 ,sizeof (*dlp)); - attrs.flavour =DEVLINK_PORT_FLAVOUR_DSA ; -devlink_port_attrs_set (dlp, &attrs); - err =devlink_port_register (dl, dlp, dp->index); -if (err) -break ; - devlink_port_registered = true; - err =dsa_port_link_register_of (dp);if (err)break ;@@ -324,14 +288,6 @@ static int dsa_port_setup(struct dsa_port *dp)break ;case DSA_PORT_TYPE_USER : -memset (dlp,0 ,sizeof (*dlp)); - attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; -devlink_port_attrs_set (dlp, &attrs); - err =devlink_port_register (dl, dlp, dp->index); -if (err) -break ; - devlink_port_registered = true; - dp->mac =of_get_mac_address (dp->dn); err =dsa_slave_create (dp);if (err)@@ -345,8 +301,6 @@ static int dsa_port_setup(struct dsa_port *dp)dsa_port_disable (dp);if (err && dsa_port_link_registered)dsa_port_link_unregister_of (dp); -if (err && devlink_port_registered) -devlink_port_unregister (dlp);if (err)return err;@@ -355,30 +309,77 @@ static int dsa_port_setup(struct dsa_port *dp)return 0 ; } -static void dsa_port_teardown (struct dsa_port *dp) +static int dsa_port_devlink_setup (struct dsa_port *dp) {struct devlink_port *dlp = &dp->devlink_port; +struct dsa_switch_tree *dst = dp->ds->dst; +struct devlink_port_attrs attrs = {}; +struct devlink *dl = dp->ds->devlink; +const unsigned char *id; +unsigned char len; +int err; +
net/dsa/dsa2.c static int dsa_port_setup(struct dsa_port *dp) · line 331
Quoted 10 lines
net/dsa/dsa2.c +9
-0+ id = (const unsigned char *)&dst->index; + len =sizeof (dst->index); + + attrs.phys.port_number = dp->index; +memcpy (attrs.switch_id.id, id, len); + attrs.switch_id.id_len = len; + +if (dp->setup) +return 0 ;
I wonder what this is protecting against? I ran on a multi-switch tree without these 2 lines and I didn't get anything like multiple registration or things like that. What is the call path that would call dsa_port_devlink_setup twice?
net/dsa/dsa2.c static int dsa_port_setup(struct dsa_port *dp)
Quoted 7 lines
net/dsa/dsa2.c +6
-0+switch (dp->type) { +case DSA_PORT_TYPE_UNUSED : +memset (dlp,0 ,sizeof (*dlp)); + attrs.flavour =DEVLINK_PORT_FLAVOUR_UNUSED ; +devlink_port_attrs_set (dlp, &attrs); + err =devlink_port_register (dl, dlp, dp->index);
These 2 lines are common everywhere. Could you move them out of the switch-case statement?
Quoted 84 lines
net/dsa/dsa2.c +29
-4+break ; +case DSA_PORT_TYPE_CPU : +memset (dlp,0 ,sizeof (*dlp)); + attrs.flavour =DEVLINK_PORT_FLAVOUR_CPU ; +devlink_port_attrs_set (dlp, &attrs); + err =devlink_port_register (dl, dlp, dp->index); +break ; +case DSA_PORT_TYPE_DSA : +memset (dlp,0 ,sizeof (*dlp)); + attrs.flavour =DEVLINK_PORT_FLAVOUR_DSA ; +devlink_port_attrs_set (dlp, &attrs); + err =devlink_port_register (dl, dlp, dp->index); +break ; +case DSA_PORT_TYPE_USER : +memset (dlp,0 ,sizeof (*dlp)); + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; +devlink_port_attrs_set (dlp, &attrs); + err =devlink_port_register (dl, dlp, dp->index); +break ; + } + +if (!err) + dp->devlink_port_setup = true; + +return err; +} + +static void dsa_port_teardown (struct dsa_port *dp) +{if (!dp->setup)return ;switch (dp->type) {case DSA_PORT_TYPE_UNUSED : -devlink_port_unregister (dlp);break ;case DSA_PORT_TYPE_CPU :dsa_port_disable (dp);dsa_tag_driver_put (dp->tag_ops); -devlink_port_unregister (dlp);dsa_port_link_unregister_of (dp);break ;case DSA_PORT_TYPE_DSA :dsa_port_disable (dp); -devlink_port_unregister (dlp);dsa_port_link_unregister_of (dp);break ;case DSA_PORT_TYPE_USER : -devlink_port_unregister (dlp);if (dp->slave) {dsa_slave_destroy (dp->slave);net/dsa/dsa2.c +14
-0dp->slave =NULL ;@@ -389,6 +390,15 @@ static void dsa_port_teardown(struct dsa_port *dp) dp->setup = false; } +static void dsa_port_devlink_teardown (struct dsa_port *dp) +{ +struct devlink_port *dlp = &dp->devlink_port; + +if (dp->devlink_port_setup) +devlink_port_unregister (dlp); + dp->devlink_port_setup = false; +} +static int dsa_devlink_info_get (struct devlink *dl,struct devlink_info_req *req,struct netlink_ext_ack *extack)@@ -408,6 +418,7 @@ static const struct devlink_ops dsa_devlink_ops = {static int dsa_switch_setup (struct dsa_switch *ds) {struct dsa_devlink_priv *dl_priv; +struct dsa_port *dp;int err;if (ds->setup)@@ -433,6 +444,17 @@ static int dsa_switch_setup(struct dsa_switch *ds)if (err) goto free_devlink; +/* Setup devlink port instances now, so that the switch +* setup() can register regions etc, against the ports +*/ +list_for_each_entry (dp, &ds->dst->ports, list) {
net/dsa/dsa2.c static int dsa_switch_setup(struct dsa_switch *ds) · line 460
Quoted 10 lines
net/dsa/dsa2.c +7
-0+if (dp->ds == ds) { + err =dsa_port_devlink_setup (dp); +if (err) + goto unregister_devlink_ports; + } + } + err =dsa_switch_register_notifier (ds);if (err) goto unregister_devlink;
Need to use goto unregister_devlink_ports here.
Quoted 33 lines
net/dsa/dsa2.c +9
-0@@ -463,6 +485,10 @@ static int dsa_switch_setup(struct dsa_switch *ds) unregister_notifier:dsa_switch_unregister_notifier (ds); +unregister_devlink_ports: +list_for_each_entry (dp, &ds->dst->ports, list) +if (dp->ds == ds) +dsa_port_devlink_teardown (dp); unregister_devlink:devlink_unregister (ds->devlink); free_devlink:@@ -474,6 +500,8 @@ static int dsa_switch_setup(struct dsa_switch *ds)static void dsa_switch_teardown (struct dsa_switch *ds) { +struct dsa_port *dp; +if (!ds->setup)return ;@@ -486,6 +514,9 @@ static void dsa_switch_teardown(struct dsa_switch *ds) ds->ops->teardown (ds);if (ds->devlink) { +list_for_each_entry (dp, &ds->dst->ports, list) +if (dp->ds == ds) +dsa_port_devlink_teardown (dp);devlink_unregister (ds->devlink);devlink_free (ds->devlink); ds->devlink =NULL ;Signature · 1 line
2.28.0
Andrew Lunn
maintainerRe: [PATCH net-next v2 3/7] net: dsa: Register devlink ports before calling DSA driver setup()
Quoted 17 lines
Quoted 17 lines
net/dsa/dsa2.c +15
-0+static int dsa_port_devlink_setup (struct dsa_port *dp) {struct devlink_port *dlp = &dp->devlink_port; +struct dsa_switch_tree *dst = dp->ds->dst; +struct devlink_port_attrs attrs = {}; +struct devlink *dl = dp->ds->devlink; +const unsigned char *id; +unsigned char len; +int err; + + id = (const unsigned char *)&dst->index; + len =sizeof (dst->index); + + attrs.phys.port_number = dp->index; +memcpy (attrs.switch_id.id, id, len); + attrs.switch_id.id_len = len; +
Quoted 8 lines
net/dsa/dsa2.c static int dsa_port_setup(struct dsa_port *dp) · line 330
Quoted 3 lines
net/dsa/dsa2.c +2
-0+if (dp->setup) +return 0 ;I wonder what this is protecting against? I ran on a multi-switch tree without these 2 lines and I didn't get anything like multiple registration or things like that. What is the call path that would call
dsa_port_devlink_setuptwice?
I made a duplicate copy of dsa_port_setup() and trimmed out what was not needed to give the new dsa_port_setup() and dsa_port_devlink_setup(). I did not trim enough...
Quoted 11 lines
net/dsa/dsa2.c static int dsa_port_setup(struct dsa_port *dp)
Quoted 8 lines
net/dsa/dsa2.c +6
-0+switch (dp->type) { +case DSA_PORT_TYPE_UNUSED : +memset (dlp,0 ,sizeof (*dlp)); + attrs.flavour =DEVLINK_PORT_FLAVOUR_UNUSED ; +devlink_port_attrs_set (dlp, &attrs); + err =devlink_port_register (dl, dlp, dp->index);These 2 lines are common everywhere. Could you move them out of the switch-case statement?
Yes, that makes sense. Too much blind copy/paste without actually reviewing the code afterwards.
Andrew
Andrew Lunn
maintainerPATCH v2 4/7 net: devlink: Add support for port regions
In reply to Andrew LunnAllow regions to be registered to a devlink port. The same netlink API is used, but the port index is provided to indicate when a region is a port region as opposed to a device region.
--- include/net/devlink.h | 27 +++++ net/core/devlink.c | 250 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 251 insertions(+), 26 deletions(-)
include/net/devlink.h +27 -0
@@ -110,6 +110,7 @@ struct devlink_port_attrs {struct devlink_port {struct list_head list;struct list_head param_list; +struct list_head region_list;struct devlink *devlink;unsigned int index;bool registered;
@@ -573,6 +574,26 @@ struct devlink_region_ops {void *priv; }; +/** +* struct devlink_port_region_ops - Region operations for a port +* @name: region name +* @destructor: callback used to free snapshot memory when deleting +* @snapshot: callback to request an immediate snapshot. On success, +* the data variable must be updated to point to the snapshot data. +* The function will be called while the devlink instance lock is +* held. +* @priv: Pointer to driver private data for the region operation +*/ +struct devlink_port_region_ops { +const char *name; +void (*destructor)(const void *data); +int (*snapshot)(struct devlink_port *port, +const struct devlink_port_region_ops *ops, +struct netlink_ext_ack *extack, +u8 **data); +void *priv; +}; +struct devlink_fmsg ;struct devlink_health_reporter ;
@@ -1336,7 +1357,13 @@ struct devlink_region * devlink_region_create(struct devlink *devlink, const struct devlink_region_ops *ops, u32 region_max_snapshots, u64 region_size); +struct devlink_region * +devlink_port_region_create (struct devlink_port *port, +const struct devlink_port_region_ops *ops, +u32 region_max_snapshots,u64 region_size);void devlink_region_destroy (struct devlink_region *region); +void devlink_port_region_destroy (struct devlink_region *region); +int devlink_region_snapshot_id_get (struct devlink *devlink,u32 *id);void devlink_region_snapshot_id_put (struct devlink *devlink,u32 id); int devlink_region_snapshot_create(struct devlink_region *region,
net/core/devlink.c +224 -26
381 lines not on this page · raw message
Signature · 1 line
2.28.0
Andrew Lunn
maintainerPATCH v2 5/7 net: dsa: Add devlink port regions support to DSA
In reply to Andrew LunnAllow DSA drivers to make use of devlink port regions, via simple wrappers.
--- include/net/dsa.h | 5 +++++ net/dsa/dsa.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+)
include/net/dsa.h +5 -0
@@ -666,6 +666,11 @@ struct devlink_region * dsa_devlink_region_create(struct dsa_switch *ds, const struct devlink_region_ops *ops, u32 region_max_snapshots, u64 region_size); +struct devlink_region * +dsa_devlink_port_region_create (struct dsa_switch *ds, +int port, +const struct devlink_port_region_ops *ops, +u32 region_max_snapshots,u64 region_size);void dsa_devlink_region_destroy (struct devlink_region *region);struct dsa_port *dsa_port_from_netdev (struct net_device *netdev);
net/dsa/dsa.c +14 -0
@@ -414,6 +414,20 @@ dsa_devlink_region_create(struct dsa_switch *ds, }EXPORT_SYMBOL_GPL (dsa_devlink_region_create); +struct devlink_region * +dsa_devlink_port_region_create (struct dsa_switch *ds, +int port, +const struct devlink_port_region_ops *ops, +u32 region_max_snapshots,u64 region_size) +{ +struct dsa_port *dp =dsa_to_port (ds, port); + +return devlink_port_region_create (&dp->devlink_port, ops, + region_max_snapshots, + region_size); +} +EXPORT_SYMBOL_GPL (dsa_devlink_port_region_create); +void dsa_devlink_region_destroy (struct devlink_region *region) {devlink_region_destroy (region);
Signature · 1 line
2.28.0
Re: [PATCH net-next v2 5/7] net: dsa: Add devlink port regions support to DSA
Quoted 5 lines · Andrew Lunn
Allow DSA drivers to make use of devlink port regions, via simple wrappers.
Signed-off-by Andrew Lunn <[email protected]>---
Andrew Lunn
maintainerPATCH v2 6/7 net: dsa: Add helper for converting devlink port to ds and port
In reply to Andrew LunnHide away from DSA drivers how devlink works.
--- include/net/dsa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/net/dsa.h +14 -0
@@ -686,6 +686,20 @@ static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)return dl_priv->ds; } +static inline +struct dsa_switch *dsa_devlink_port_to_ds (struct devlink_port *port) +{ +struct devlink *dl = port->devlink; +struct dsa_devlink_priv *dl_priv =devlink_priv (dl); + +return dl_priv->ds; +} + +static inline int dsa_devlink_port_to_port (struct devlink_port *port) +{ +return port->index; +} +struct dsa_switch_driver {struct list_head list;const struct dsa_switch_ops *ops;
Signature · 1 line
2.28.0
Andrew Lunn
maintainerPATCH v2 7/7 net: dsa: mv88e6xxx: Add per port devlink regions
In reply to Andrew LunnAdd a devlink region to return the per port registers.
--- drivers/net/dsa/mv88e6xxx/devlink.c | 109 +++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 4 deletions(-)
drivers/net/dsa/mv88e6xxx/devlink.c +105 -4
@@ -415,6 +415,36 @@ static int mv88e6xxx_region_atu_snapshot(struct devlink *dl,return err; } +static int mv88e6xxx_region_port_snapshot (struct devlink_port *devlink_port, +const struct devlink_port_region_ops *ops, +struct netlink_ext_ack *extack, +u8 **data) +{ +struct dsa_switch *ds =dsa_devlink_port_to_ds (devlink_port); +int port =dsa_devlink_port_to_port (devlink_port); +struct mv88e6xxx_chip *chip = ds->priv; +u16 *registers; +int i, err; + + registers =kmalloc_array (32 ,sizeof (u16),GFP_KERNEL ); +if (!registers) +return -ENOMEM ; + +mv88e6xxx_reg_lock (chip); +for (i =0 ; i <32 ; i++) { + err =mv88e6xxx_port_read (chip, port, i, ®isters[i]); +if (err) { +kfree (registers); + goto out; + } + } + *data = (u8 *)registers; +out: +mv88e6xxx_reg_unlock (chip); + +return err; +} +static struct mv88e6xxx_region_priv mv88e6xxx_region_global1_priv = { .id =MV88E6XXX_REGION_GLOBAL1 , };
@@ -443,6 +473,12 @@ static struct devlink_region_ops mv88e6xxx_region_atu_ops = { .destructor = kfree, }; +static const struct devlink_port_region_ops mv88e6xxx_region_port_ops = { + .name ="port" , + .snapshot = mv88e6xxx_region_port_snapshot, + .destructor = kfree, +}; +struct mv88e6xxx_region {struct devlink_region_ops *ops;u64 size;
@@ -471,11 +507,59 @@ mv88e6xxx_teardown_devlink_regions_global(struct mv88e6xxx_chip *chip)dsa_devlink_region_destroy (chip->regions[i]); } -void mv88e6xxx_teardown_devlink_regions (struct dsa_switch *ds) +static void +mv88e6xxx_teardown_devlink_regions_port (struct mv88e6xxx_chip *chip, +int port) { -struct mv88e6xxx_chip *chip = ds->priv; +dsa_devlink_region_destroy (chip->ports[port].region); +} -mv88e6xxx_teardown_devlink_regions_global (chip); +static int mv88e6xxx_setup_devlink_regions_port (struct dsa_switch *ds, +struct mv88e6xxx_chip *chip, +int port) +{ +struct devlink_region *region; + + region =dsa_devlink_port_region_create (ds, + port, + &mv88e6xxx_region_port_ops,1 , +32 *sizeof (u16)); +if (IS_ERR (region)) +return PTR_ERR (region); + + chip->ports[port].region = region; + +return 0 ; +} + +static void +mv88e6xxx_teardown_devlink_regions_ports (struct mv88e6xxx_chip *chip) +{ +int port; + +for (port =0 ; port <mv88e6xxx_num_ports (chip); port++) +mv88e6xxx_teardown_devlink_regions_port (chip, port); +} + +static int mv88e6xxx_setup_devlink_regions_ports (struct dsa_switch *ds, +struct mv88e6xxx_chip *chip) +{ +int port, port_err; +int err; + +for (port =0 ; port <mv88e6xxx_num_ports (chip); port++) { + err =mv88e6xxx_setup_devlink_regions_port (ds, chip, port); +if (err) + goto out; + } + +return 0 ; + +out: +for (port_err =0 ; port_err < port; port_err++) +mv88e6xxx_teardown_devlink_regions_port (chip, port_err); + +return err; } static int mv88e6xxx_setup_devlink_regions_global(struct dsa_switch *ds,
@@ -511,8 +595,25 @@ static int mv88e6xxx_setup_devlink_regions_global(struct dsa_switch *ds,int mv88e6xxx_setup_devlink_regions (struct dsa_switch *ds) {struct mv88e6xxx_chip *chip = ds->priv; +int err; + + err =mv88e6xxx_setup_devlink_regions_global (ds, chip); +if (err) +return err; + + err =mv88e6xxx_setup_devlink_regions_ports (ds, chip); +if (err) +mv88e6xxx_teardown_devlink_regions_global (chip); -return mv88e6xxx_setup_devlink_regions_global (ds, chip); +return err; +} + +void mv88e6xxx_teardown_devlink_regions (struct dsa_switch *ds) +{ +struct mv88e6xxx_chip *chip = ds->priv; + +mv88e6xxx_teardown_devlink_regions_ports (chip); +mv88e6xxx_teardown_devlink_regions_global (chip); } int mv88e6xxx_devlink_info_get(struct dsa_switch *ds,
Signature · 1 line
2.28.0
Vladimir Oltean
maintainerRe: [PATCH net-next v2 7/7] net: dsa: mv88e6xxx: Add per port devlink regions
Quoted 15 lines · Andrew Lunn
Add a devlink region to return the per port registers.
Signed-off-by Andrew Lunn <[email protected]>--- drivers/net/dsa/mv88e6xxx/devlink.c | 109 +++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 4 deletions(-)drivers/net/dsa/mv88e6xxx/devlink.c +0
-0@@ -415,6 +415,36 @@ static int mv88e6xxx_region_atu_snapshot(struct devlink *dl,return err; }
drivers/net/dsa/mv88e6xxx/devlink.c static int mv88e6xxx_region_atu_snapshot(struct devlink *dl, · line 427
Quoted 10 lines
drivers/net/dsa/mv88e6xxx/devlink.c +9
-0+static int mv88e6xxx_region_port_snapshot (struct devlink_port *devlink_port, +const struct devlink_port_region_ops *ops, +struct netlink_ext_ack *extack, +u8 **data) +{ +struct dsa_switch *ds =dsa_devlink_port_to_ds (devlink_port); +int port =dsa_devlink_port_to_port (devlink_port); +struct mv88e6xxx_chip *chip = ds->priv; +u16 *registers;
I was meaning to ask this since the global regions patchset, but I forgot.
Do we not expect to see, under the same circumstances, the same region snapshot on a big endian and on a little endian system?
Quoted 84 lines
drivers/net/dsa/mv88e6xxx/devlink.c +21
-0+int i, err; + + registers =kmalloc_array (32 ,sizeof (u16),GFP_KERNEL ); +if (!registers) +return -ENOMEM ; + +mv88e6xxx_reg_lock (chip); +for (i =0 ; i <32 ; i++) { + err =mv88e6xxx_port_read (chip, port, i, ®isters[i]); +if (err) { +kfree (registers); + goto out; + } + } + *data = (u8 *)registers; +out: +mv88e6xxx_reg_unlock (chip); + +return err; +} +static struct mv88e6xxx_region_priv mv88e6xxx_region_global1_priv = { .id =MV88E6XXX_REGION_GLOBAL1 ,};
drivers/net/dsa/mv88e6xxx/devlink.c +44
-3@@ -443,6 +473,12 @@ static struct devlink_region_ops mv88e6xxx_region_atu_ops = { .destructor = kfree, }; +static const struct devlink_port_region_ops mv88e6xxx_region_port_ops = { + .name ="port" , + .snapshot = mv88e6xxx_region_port_snapshot, + .destructor = kfree, +}; +struct mv88e6xxx_region {struct devlink_region_ops *ops;u64 size;@@ -471,11 +507,59 @@ mv88e6xxx_teardown_devlink_regions_global(struct mv88e6xxx_chip *chip)dsa_devlink_region_destroy (chip->regions[i]); } -void mv88e6xxx_teardown_devlink_regions (struct dsa_switch *ds) +static void +mv88e6xxx_teardown_devlink_regions_port (struct mv88e6xxx_chip *chip, +int port) { -struct mv88e6xxx_chip *chip = ds->priv; +dsa_devlink_region_destroy (chip->ports[port].region); +} -mv88e6xxx_teardown_devlink_regions_global (chip); +static int mv88e6xxx_setup_devlink_regions_port (struct dsa_switch *ds, +struct mv88e6xxx_chip *chip, +int port) +{ +struct devlink_region *region; + + region =dsa_devlink_port_region_create (ds, + port, + &mv88e6xxx_region_port_ops,1 , +32 *sizeof (u16)); +if (IS_ERR (region)) +return PTR_ERR (region); + + chip->ports[port].region = region; + +return 0 ; +} + +static void +mv88e6xxx_teardown_devlink_regions_ports (struct mv88e6xxx_chip *chip) +{ +int port; + +for (port =0 ; port <mv88e6xxx_num_ports (chip); port++) +mv88e6xxx_teardown_devlink_regions_port (chip, port); +} + +static int mv88e6xxx_setup_devlink_regions_ports (struct dsa_switch *ds, +struct mv88e6xxx_chip *chip) +{ +int port, port_err; +int err; +
drivers/net/dsa/mv88e6xxx/devlink.c mv88e6xxx_teardown_devlink_regions_global(struct mv88e6xxx_chip *chip) · line 559
Quoted 10 lines
drivers/net/dsa/mv88e6xxx/devlink.c +10
-0+for (port =0 ; port <mv88e6xxx_num_ports (chip); port++) { + err =mv88e6xxx_setup_devlink_regions_port (ds, chip, port); +if (err) + goto out; + } + +return 0 ; + +out: +for (port_err =0 ; port_err < port; port_err++)
"while (port-- >= 0)" should do the trick. Also, maybe it would be overall more aesthetic if you wouldn't use the goto and have 2 exit points in such a small function, but a simple break here. Like this:
int err;
for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
err = mv88e6xxx_setup_devlink_regions_port(ds, chip, port);
if (err) {
while (port-- >= 0)
mv88e6xxx_teardown_devlink_regions_port(chip,
port);
break;
}
}
return err;Quoted 36 lines
drivers/net/dsa/mv88e6xxx/devlink.c +21
-1+mv88e6xxx_teardown_devlink_regions_port (chip, port_err); + +return err; } static int mv88e6xxx_setup_devlink_regions_global(struct dsa_switch *ds,@@ -511,8 +595,25 @@ static int mv88e6xxx_setup_devlink_regions_global(struct dsa_switch *ds,int mv88e6xxx_setup_devlink_regions (struct dsa_switch *ds) {struct mv88e6xxx_chip *chip = ds->priv; +int err; + + err =mv88e6xxx_setup_devlink_regions_global (ds, chip); +if (err) +return err; + + err =mv88e6xxx_setup_devlink_regions_ports (ds, chip); +if (err) +mv88e6xxx_teardown_devlink_regions_global (chip); -return mv88e6xxx_setup_devlink_regions_global (ds, chip); +return err; +} + +void mv88e6xxx_teardown_devlink_regions (struct dsa_switch *ds) +{ +struct mv88e6xxx_chip *chip = ds->priv; + +mv88e6xxx_teardown_devlink_regions_ports (chip); +mv88e6xxx_teardown_devlink_regions_global (chip); } int mv88e6xxx_devlink_info_get(struct dsa_switch *ds,Signature · 1 line
2.28.0
Andrew Lunn
maintainerRe: [PATCH net-next v2 7/7] net: dsa: mv88e6xxx: Add per port devlink regions
Quoted 5 lines
I was meaning to ask this since the global regions patchset, but I forgot.
Do we not expect to see, under the same circumstances, the same region snapshot on a big endian and on a little endian system?
We have never had any issues with endinness with MDIO. PHY/DSA drivers work with host endian. The MDIO bus controller does what it needs to do when shifting the bits out, as required by class 22 or 45.
netlink in general assume host endian, as far as i know. So a big endian and a little endian snapshot are going to be different.
Arnd did an interesting presentation for LPC. He basically shows that big endian is going away, with the exception of IBM big iron. I don't expect an IBM Z to have a DSA switch!
Andrew
Vladimir Oltean
maintainerRe: [PATCH net-next v2 7/7] net: dsa: mv88e6xxx: Add per port devlink regions
Quoted 6 lines · Andrew Lunn
Quoted 5 lines
I was meaning to ask this since the global regions patchset, but I forgot.
Do we not expect to see, under the same circumstances, the same region snapshot on a big endian and on a little endian system?
Quoted 6 lines
We have never had any issues with endinness with MDIO. PHY/DSA drivers work with host endian. The MDIO bus controller does what it needs to do when shifting the bits out, as required by class 22 or 45.
netlink in general assume host endian, as far as i know. So a big endian and a little endian snapshot are going to be different.
If the binary form of the snapshot is supposed to be consumed and done with immediately after the netlink communication is over, sure. But it is presented to the user, and in fact this is even the way it is presented by default, with devlink, there's no pretty-printing.
Quoted 3 lines
Arnd did an interesting presentation for LPC. He basically shows that big endian is going away, with the exception of IBM big iron. I don't expect an IBM Z to have a DSA switch!
Tell that to my T1040 chip with an 8-port Seville switch driven by the Ocelot driver.
Also, armv8 can also boot in big-endian mode.
Andrew, can this be used to write the registers from userspace, or only to read it?
Marek
Vladimir Oltean
maintainerHi Marek,
Quoted 2 lines · Marek Behun
Andrew, can this be used to write the registers from userspace, or only to read it?
It is intended for reading only.
https://www.kernel.org/doc/html/latest/networking/devlink/devlink-region.html
Thanks,
-Vladimir