Skip to content

Commit 5df5661

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: stop overriding master's ndo_get_phys_port_name
The purpose of this override is to give the user an indication of what the number of the CPU port is (in DSA, the CPU port is a hardware implementation detail and not a network interface capable of traffic). However, it has always failed (by design) at providing this information to the user in a reliable fashion. Prior to commit 3369afb ("net: Call into DSA netdevice_ops wrappers"), the behavior was to only override this callback if it was not provided by the DSA master. That was its first failure: if the DSA master itself was a DSA port or a switchdev, then the user would not see the number of the CPU port in /sys/class/net/eth0/phys_port_name, but the number of the DSA master port within its respective physical switch. But that was actually ok in a way. The commit mentioned above changed that behavior, and now overrides the master's ndo_get_phys_port_name unconditionally. That comes with problems of its own, which are worse in a way. The idea is that it's typical for switchdev users to have udev rules for consistent interface naming. These are based, among other things, on the phys_port_name attribute. If we let the DSA switch at the bottom to start randomly overriding ndo_get_phys_port_name with its own CPU port, we basically lose any predictability in interface naming, or even uniqueness, for that matter. So, there are reasons to let DSA override the master's callback (to provide a consistent interface, a number which has a clear meaning and must not be interpreted according to context), and there are reasons to not let DSA override it (it breaks udev matching for the DSA master). But, there is an alternative method for users to retrieve the number of the CPU port of each DSA switch in the system: $ devlink port pci/0000:00:00.5/0: type eth netdev swp0 flavour physical port 0 pci/0000:00:00.5/2: type eth netdev swp2 flavour physical port 2 pci/0000:00:00.5/4: type notset flavour cpu port 4 spi/spi2.0/0: type eth netdev sw0p0 flavour physical port 0 spi/spi2.0/1: type eth netdev sw0p1 flavour physical port 1 spi/spi2.0/2: type eth netdev sw0p2 flavour physical port 2 spi/spi2.0/4: type notset flavour cpu port 4 spi/spi2.1/0: type eth netdev sw1p0 flavour physical port 0 spi/spi2.1/1: type eth netdev sw1p1 flavour physical port 1 spi/spi2.1/2: type eth netdev sw1p2 flavour physical port 2 spi/spi2.1/3: type eth netdev sw1p3 flavour physical port 3 spi/spi2.1/4: type notset flavour cpu port 4 So remove this duplicated, unreliable and troublesome method. From this patch on, the phys_port_name attribute of the DSA master will only contain information about itself (if at all). If the users need reliable information about the CPU port they're probably using devlink anyway. Signed-off-by: Vladimir Oltean <olteanv@gmail.com> Acked-by: florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7235ffa commit 5df5661

File tree

3 files changed

+0
-40
lines changed

3 files changed

+0
-40
lines changed

include/net/dsa.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ struct dsa_device_ops {
9494
struct dsa_netdevice_ops {
9595
int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr,
9696
int cmd);
97-
int (*ndo_get_phys_port_name)(struct net_device *dev, char *name,
98-
size_t len);
9997
};
10098

10199
#define DSA_TAG_DRIVER_ALIAS "dsa_tag-"
@@ -719,33 +717,12 @@ static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr,
719717

720718
return ops->ndo_do_ioctl(dev, ifr, cmd);
721719
}
722-
723-
static inline int dsa_ndo_get_phys_port_name(struct net_device *dev,
724-
char *name, size_t len)
725-
{
726-
const struct dsa_netdevice_ops *ops;
727-
int err;
728-
729-
err = __dsa_netdevice_ops_check(dev);
730-
if (err)
731-
return err;
732-
733-
ops = dev->dsa_ptr->netdev_ops;
734-
735-
return ops->ndo_get_phys_port_name(dev, name, len);
736-
}
737720
#else
738721
static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr,
739722
int cmd)
740723
{
741724
return -EOPNOTSUPP;
742725
}
743-
744-
static inline int dsa_ndo_get_phys_port_name(struct net_device *dev,
745-
char *name, size_t len)
746-
{
747-
return -EOPNOTSUPP;
748-
}
749726
#endif
750727

751728
void dsa_unregister_switch(struct dsa_switch *ds);

net/core/dev.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
#include <net/busy_poll.h>
9999
#include <linux/rtnetlink.h>
100100
#include <linux/stat.h>
101-
#include <net/dsa.h>
102101
#include <net/dst.h>
103102
#include <net/dst_metadata.h>
104103
#include <net/pkt_sched.h>
@@ -8605,10 +8604,6 @@ int dev_get_phys_port_name(struct net_device *dev,
86058604
const struct net_device_ops *ops = dev->netdev_ops;
86068605
int err;
86078606

8608-
err = dsa_ndo_get_phys_port_name(dev, name, len);
8609-
if (err == 0 || err != -EOPNOTSUPP)
8610-
return err;
8611-
86128607
if (ops->ndo_get_phys_port_name) {
86138608
err = ops->ndo_get_phys_port_name(dev, name, len);
86148609
if (err != -EOPNOTSUPP)

net/dsa/master.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,6 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset,
186186
}
187187
}
188188

189-
static int dsa_master_get_phys_port_name(struct net_device *dev,
190-
char *name, size_t len)
191-
{
192-
struct dsa_port *cpu_dp = dev->dsa_ptr;
193-
194-
if (snprintf(name, len, "p%d", cpu_dp->index) >= len)
195-
return -EINVAL;
196-
197-
return 0;
198-
}
199-
200189
static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
201190
{
202191
struct dsa_port *cpu_dp = dev->dsa_ptr;
@@ -228,7 +217,6 @@ static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
228217

229218
static const struct dsa_netdevice_ops dsa_netdev_ops = {
230219
.ndo_do_ioctl = dsa_master_ioctl,
231-
.ndo_get_phys_port_name = dsa_master_get_phys_port_name,
232220
};
233221

234222
static int dsa_master_ethtool_setup(struct net_device *dev)

0 commit comments

Comments
 (0)