net: dsa: Expose tagging protocol to user-space
Subsystems (3)
PATCH 1/1 net: dsa: Expose tagging protocol to user-space
There is no way for user-space to know what a given DSA network device's tagging protocol is. Expose this information through a dsa/tagging attribute which reflects the tagging protocol currently in use.
This is helpful for configuration (e.g: none behaves dramatically different wrt. bridges) as well as for packet capture tools when there is not a proper Ethernet type available.
--- Documentation/ABI/testing/sysfs-class-net-dsa | 7 +++ net/dsa/dsa.c | 43 +++++++++++++++++++ net/dsa/dsa_priv.h | 1 + net/dsa/slave.c | 28 ++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-net-dsa
Documentation/ABI/testing/sysfs-class-net-dsa new file +7 -0
@@ -0,0 +1,7 @@ +What: /sys/class/net/<iface>/tagging +Date: August 2018 +KernelVersion: 4.20 +Contact: [email protected] +Description: + String indicating the type of tagging protocol used by the + DSA slave network device.
net/dsa/dsa.c +43 -0
49 lines not on this page · raw message
net/dsa/dsa_priv.h +1 -0
@@ -86,6 +86,7 @@ struct dsa_slave_priv {/* dsa.c */ const struct dsa_device_ops *dsa_resolve_tag_protocol (int tag_protocol);bool dsa_schedule_work (struct work_struct *work); +const char *dsa_tag_protocol_to_str (const struct dsa_device_ops *ops);/* legacy.c */ #if IS_ENABLED (CONFIG_NET_DSA_LEGACY )
net/dsa/slave.c +28 -0
@@ -1058,6 +1058,27 @@ static struct device_type dsa_type = { .name = "dsa", }; +static ssize_t tagging_show (struct device *d,struct device_attribute *attr, +char *buf) +{ +struct net_device *dev =to_net_dev (d); +struct dsa_port *dp =dsa_slave_to_port (dev); + +return sprintf (buf,"%s\n" , +dsa_tag_protocol_to_str (dp->cpu_dp->tag_ops)); +} +static DEVICE_ATTR_RO (tagging); + +static struct attribute *dsa_slave_attrs[] = { + &dev_attr_tagging.attr, +NULL +}; + +static const struct attribute_group dsa_group = { + .name ="dsa" , + .attrs = dsa_slave_attrs, +}; +static void dsa_slave_phylink_validate (struct net_device *dev,unsigned long *supported,struct phylink_link_state *state)
@@ -1353,8 +1374,14 @@ int dsa_slave_create(struct dsa_port *port) goto out_phy; } + ret =sysfs_create_group (&slave_dev->dev.kobj, &dsa_group); +if (ret) + goto out_unreg; +return 0 ; +out_unreg: +unregister_netdev (slave_dev); out_phy:rtnl_lock ();phylink_disconnect_phy (p->dp->pl);
@@ -1378,6 +1405,7 @@ void dsa_slave_destroy(struct net_device *slave_dev)rtnl_unlock ();dsa_slave_notify (slave_dev,DSA_PORT_UNREGISTER ); +sysfs_remove_group (&slave_dev->dev.kobj, &dsa_group);unregister_netdev (slave_dev);phylink_destroy (dp->pl);free_percpu (p->stats64);
Signature · 1 line
2.17.1
From: Florian Fainelli <[email protected]>
Date: Fri, 7 Sep 2018 11:09:02 -0700
Quoted 9 lines
There is no way for user-space to know what a given DSA network device's tagging protocol is. Expose this information through a dsa/tagging attribute which reflects the tagging protocol currently in use.
This is helpful for configuration (e.g: none behaves dramatically different wrt. bridges) as well as for packet capture tools when there is not a proper Ethernet type available.
Signed-off-by Florian Fainelli <[email protected]>
Applied, thanks Florian.
Quoted 7 lines · Fri, Sep 07, 2018 at 08:09:02PM CEST, [email protected] wrote:
There is no way for user-space to know what a given DSA network device's tagging protocol is. Expose this information through a dsa/tagging attribute which reflects the tagging protocol currently in use.
This is helpful for configuration (e.g: none behaves dramatically different wrt. bridges) as well as for packet capture tools when there is not a proper Ethernet type available.
Hmm, I wonder. It this something that varies between ports of an individual ASIC? Or is it rather something defined per-ASIC. If so, this looks more like a devlink-api material.
Andrew Lunn
maintainerQuoted 5 lines · Jiri Pirko
Quoted 4 lines · Fri, Sep 07, 2018 at 08:09:02PM CEST, [email protected] wrote:
There is no way for user-space to know what a given DSA network device's tagging protocol is. Expose this information through a dsa/tagging attribute which reflects the tagging protocol currently in use.
Quoted 8 lines
Quoted 3 lines
This is helpful for configuration (e.g: none behaves dramatically different wrt. bridges) as well as for packet capture tools when there is not a proper Ethernet type available.
Hmm, I wonder. It this something that varies between ports of an individual ASIC? Or is it rather something defined per-ASIC. If so, this looks more like a devlink-api material.
Hi Jiri
This is between the CPU ethernet device and the switch port that interface is connect to.
For the Marvell devices, any switch port can be connected to the CPU Ethernet interface, and the same protocol is used. However, some switches have a special port which should be used to connect to the CPU ethernet and supports this tagging protocol. If the designer gets it wrong and uses a different port to connect the CPU, no tagging protocol can be used, which as Florian indicated, has a big impact on bridging, etc.
And just to make it more complex, Marvel has two tagging schemes. Older devices use DSA, newer devices uses EDSA. However, for the very new devices in the 6390 family, Marvell made a subtle change to how EDSA works, which broke it, so we had to go back to DSA.
Of the different tagging protocols used by the 50 or so switches Linux supports, only the EDSA tagging protocol makes use of an Ethertype. tcpdump knows how to decode these packets. For all the other tagging protocols, it has no idea, the Ethertype is all messed up, and it just prints hex. What i think Florian wants to do is stuff the tagging protocol into the pcap-ng header so that tcpdump knows what protocol is in use, and can put the correct protocol dissector in the chain.
And just for completeness, there potentially is a second tagging scheme when you have multiple switches connected together in a cluster, but that is internal to the cluster. The CPU is unaware of it. But if you are snooping on the traffic, you need to know what the protocol is, so you can decode the frames. In theory, that could be EDSA or DSA, and can be selected per intra-switch link. In practice, they are all DSA, and i've not heard of anybody actually snooping this traffic.
Andrew