2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-09-19 23:57:00 +08:00
|
|
|
/*
|
|
|
|
* Handling of a master device, switching frames via its switch fabric CPU port
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Savoir-faire Linux Inc.
|
|
|
|
* Vivien Didelot <vivien.didelot@savoirfairelinux.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dsa_priv.h"
|
|
|
|
|
2019-08-03 03:34:55 +08:00
|
|
|
static int dsa_master_get_regs_len(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
|
|
|
const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
|
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
|
|
|
int port = cpu_dp->index;
|
|
|
|
int ret = 0;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (ops->get_regs_len) {
|
|
|
|
len = ops->get_regs_len(dev);
|
|
|
|
if (len < 0)
|
|
|
|
return len;
|
|
|
|
ret += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += sizeof(struct ethtool_drvinfo);
|
|
|
|
ret += sizeof(struct ethtool_regs);
|
|
|
|
|
|
|
|
if (ds->ops->get_regs_len) {
|
|
|
|
len = ds->ops->get_regs_len(ds, port);
|
|
|
|
if (len < 0)
|
|
|
|
return len;
|
|
|
|
ret += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dsa_master_get_regs(struct net_device *dev,
|
|
|
|
struct ethtool_regs *regs, void *data)
|
|
|
|
{
|
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
|
|
|
const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
|
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
|
|
|
struct ethtool_drvinfo *cpu_info;
|
|
|
|
struct ethtool_regs *cpu_regs;
|
|
|
|
int port = cpu_dp->index;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (ops->get_regs_len && ops->get_regs) {
|
|
|
|
len = ops->get_regs_len(dev);
|
|
|
|
if (len < 0)
|
|
|
|
return;
|
|
|
|
regs->len = len;
|
|
|
|
ops->get_regs(dev, regs, data);
|
|
|
|
data += regs->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_info = (struct ethtool_drvinfo *)data;
|
|
|
|
strlcpy(cpu_info->driver, "dsa", sizeof(cpu_info->driver));
|
|
|
|
data += sizeof(*cpu_info);
|
|
|
|
cpu_regs = (struct ethtool_regs *)data;
|
|
|
|
data += sizeof(*cpu_regs);
|
|
|
|
|
|
|
|
if (ds->ops->get_regs_len && ds->ops->get_regs) {
|
|
|
|
len = ds->ops->get_regs_len(ds, port);
|
|
|
|
if (len < 0)
|
|
|
|
return;
|
|
|
|
cpu_regs->len = len;
|
|
|
|
ds->ops->get_regs(ds, port, cpu_regs, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-19 23:57:00 +08:00
|
|
|
static void dsa_master_get_ethtool_stats(struct net_device *dev,
|
|
|
|
struct ethtool_stats *stats,
|
|
|
|
uint64_t *data)
|
|
|
|
{
|
2017-09-30 05:19:20 +08:00
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
2017-09-30 05:19:16 +08:00
|
|
|
const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
|
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
|
|
|
int port = cpu_dp->index;
|
2017-09-19 23:57:00 +08:00
|
|
|
int count = 0;
|
|
|
|
|
2018-04-26 03:12:49 +08:00
|
|
|
if (ops->get_sset_count && ops->get_ethtool_stats) {
|
2017-09-19 23:57:00 +08:00
|
|
|
count = ops->get_sset_count(dev, ETH_SS_STATS);
|
|
|
|
ops->get_ethtool_stats(dev, stats, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ds->ops->get_ethtool_stats)
|
2017-09-30 05:19:16 +08:00
|
|
|
ds->ops->get_ethtool_stats(ds, port, data + count);
|
2017-09-19 23:57:00 +08:00
|
|
|
}
|
|
|
|
|
2018-04-26 03:12:52 +08:00
|
|
|
static void dsa_master_get_ethtool_phy_stats(struct net_device *dev,
|
|
|
|
struct ethtool_stats *stats,
|
|
|
|
uint64_t *data)
|
|
|
|
{
|
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
|
|
|
const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
|
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
|
|
|
int port = cpu_dp->index;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (dev->phydev && !ops->get_ethtool_phy_stats) {
|
|
|
|
count = phy_ethtool_get_sset_count(dev->phydev);
|
|
|
|
if (count >= 0)
|
|
|
|
phy_ethtool_get_stats(dev->phydev, stats, data);
|
|
|
|
} else if (ops->get_sset_count && ops->get_ethtool_phy_stats) {
|
|
|
|
count = ops->get_sset_count(dev, ETH_SS_PHY_STATS);
|
|
|
|
ops->get_ethtool_phy_stats(dev, stats, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count < 0)
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
if (ds->ops->get_ethtool_phy_stats)
|
|
|
|
ds->ops->get_ethtool_phy_stats(ds, port, data + count);
|
|
|
|
}
|
|
|
|
|
2017-09-19 23:57:00 +08:00
|
|
|
static int dsa_master_get_sset_count(struct net_device *dev, int sset)
|
|
|
|
{
|
2017-09-30 05:19:20 +08:00
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
2017-09-30 05:19:16 +08:00
|
|
|
const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
|
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
2017-09-19 23:57:00 +08:00
|
|
|
int count = 0;
|
|
|
|
|
2018-04-26 03:12:52 +08:00
|
|
|
if (sset == ETH_SS_PHY_STATS && dev->phydev &&
|
|
|
|
!ops->get_ethtool_phy_stats)
|
|
|
|
count = phy_ethtool_get_sset_count(dev->phydev);
|
|
|
|
else if (ops->get_sset_count)
|
2018-04-26 03:12:50 +08:00
|
|
|
count = ops->get_sset_count(dev, sset);
|
2018-04-26 03:12:52 +08:00
|
|
|
|
|
|
|
if (count < 0)
|
|
|
|
count = 0;
|
2017-09-19 23:57:00 +08:00
|
|
|
|
2018-04-26 03:12:50 +08:00
|
|
|
if (ds->ops->get_sset_count)
|
|
|
|
count += ds->ops->get_sset_count(ds, cpu_dp->index, sset);
|
2017-09-19 23:57:00 +08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset,
|
|
|
|
uint8_t *data)
|
|
|
|
{
|
2017-09-30 05:19:20 +08:00
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
2017-09-30 05:19:16 +08:00
|
|
|
const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
|
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
|
|
|
int port = cpu_dp->index;
|
2017-09-19 23:57:00 +08:00
|
|
|
int len = ETH_GSTRING_LEN;
|
|
|
|
int mcount = 0, count;
|
|
|
|
unsigned int i;
|
|
|
|
uint8_t pfx[4];
|
|
|
|
uint8_t *ndata;
|
|
|
|
|
2017-09-30 05:19:16 +08:00
|
|
|
snprintf(pfx, sizeof(pfx), "p%.2d", port);
|
2017-09-19 23:57:00 +08:00
|
|
|
/* We do not want to be NULL-terminated, since this is a prefix */
|
|
|
|
pfx[sizeof(pfx) - 1] = '_';
|
|
|
|
|
2018-04-26 03:12:52 +08:00
|
|
|
if (stringset == ETH_SS_PHY_STATS && dev->phydev &&
|
|
|
|
!ops->get_ethtool_phy_stats) {
|
|
|
|
mcount = phy_ethtool_get_sset_count(dev->phydev);
|
|
|
|
if (mcount < 0)
|
|
|
|
mcount = 0;
|
|
|
|
else
|
|
|
|
phy_ethtool_get_strings(dev->phydev, data);
|
|
|
|
} else if (ops->get_sset_count && ops->get_strings) {
|
2018-04-26 03:12:50 +08:00
|
|
|
mcount = ops->get_sset_count(dev, stringset);
|
|
|
|
if (mcount < 0)
|
|
|
|
mcount = 0;
|
2017-09-19 23:57:00 +08:00
|
|
|
ops->get_strings(dev, stringset, data);
|
|
|
|
}
|
|
|
|
|
2018-04-26 03:12:50 +08:00
|
|
|
if (ds->ops->get_strings) {
|
2017-09-19 23:57:00 +08:00
|
|
|
ndata = data + mcount * len;
|
|
|
|
/* This function copies ETH_GSTRINGS_LEN bytes, we will mangle
|
|
|
|
* the output after to prepend our CPU port prefix we
|
|
|
|
* constructed earlier
|
|
|
|
*/
|
2018-04-26 03:12:50 +08:00
|
|
|
ds->ops->get_strings(ds, port, stringset, ndata);
|
|
|
|
count = ds->ops->get_sset_count(ds, port, stringset);
|
2017-09-19 23:57:00 +08:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
memmove(ndata + (i * len + sizeof(pfx)),
|
|
|
|
ndata + i * len, len - sizeof(pfx));
|
|
|
|
memcpy(ndata + i * len, pfx, sizeof(pfx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 06:43:04 +08:00
|
|
|
static int dsa_master_get_phys_port_name(struct net_device *dev,
|
|
|
|
char *name, size_t len)
|
|
|
|
{
|
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
|
|
|
|
|
|
|
if (snprintf(name, len, "p%d", cpu_dp->index) >= len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
net: dsa: Deny PTP on master if switch supports it
It is possible to kill PTP on a DSA switch completely and absolutely,
until a reboot, with a simple command:
tcpdump -i eth2 -j adapter_unsynced
where eth2 is the switch's DSA master.
Why? Well, in short, the PTP API in place today is a bit rudimentary and
relies on applications to retrieve the TX timestamps by polling the
error queue and looking at the cmsg structure. But there is no timestamp
identification of any sorts (except whether it's HW or SW), you don't
know how many more timestamps are there to come, which one is this one,
from whom it is, etc. In other words, the SO_TIMESTAMPING API is
fundamentally limited in that you can get a single HW timestamp from the
stack.
And the "-j adapter_unsynced" flag of tcpdump enables hardware
timestamping.
So let's imagine what happens when the DSA master decides it wants to
deliver TX timestamps to the skb's socket too:
- The timestamp that the user space sees is taken by the DSA master.
Whereas the RX timestamp will eventually be overwritten by the DSA
switch. So the RX and TX timestamps will be in different time bases
(aka garbage).
- The user space applications have no way to deal with the second (real)
TX timestamp finally delivered by the DSA switch, or even to know to
wait for it.
Take ptp4l from the linuxptp project, for example. This is its behavior
after running tcpdump, before the patch:
ptp4l[172]: [6469.594] Unexpected data on socket err queue:
ptp4l[172]: [6469.693] rms 8 max 16 freq -21257 +/- 11 delay 748 +/- 0
ptp4l[172]: [6469.711] Unexpected data on socket err queue:
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 03 aa 05 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: [6469.721] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 10 02
ptp4l[172]: 0010 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 01 c6 b1 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: [6469.838] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 10 02
ptp4l[172]: 0010 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 03 aa 06 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: [6469.848] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 13 02
ptp4l[172]: 0010 00 36 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 04 1a 45 05 7f
ptp4l[172]: 0030 00 00 5e 05 41 32 27 c2 1a 68 00 04 9f ff fe 05
ptp4l[172]: 0040 de 06 00 01
ptp4l[172]: [6469.855] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 10 02
ptp4l[172]: 0010 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 01 c6 b2 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: [6469.974] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 10 02
ptp4l[172]: 0010 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 03 aa 07 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
The ptp4l program itself is heavily patched to show this (more details
here [0]). Otherwise, by default it just hangs.
On the other hand, with the DSA patch to disallow HW timestamping
applied:
tcpdump -i eth2 -j adapter_unsynced
tcpdump: SIOCSHWTSTAMP failed: Device or resource busy
So it is a fact of life that PTP timestamping on the DSA master is
incompatible with timestamping on the switch MAC, at least with the
current API. And if the switch supports PTP, taking the timestamps from
the switch MAC is highly preferable anyway, due to the fact that those
don't contain the queuing latencies of the switch. So just disallow PTP
on the DSA master if there is any PTP-capable switch attached.
[0]: https://sourceforge.net/p/linuxptp/mailman/message/36880648/
Fixes: 0336369d3a4d ("net: dsa: forward hardware timestamping ioctls to switch driver")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-28 21:30:46 +08:00
|
|
|
static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
|
|
|
|
{
|
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
|
|
|
struct dsa_switch_tree *dst;
|
|
|
|
int err = -EOPNOTSUPP;
|
|
|
|
struct dsa_port *dp;
|
|
|
|
|
|
|
|
dst = ds->dst;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGHWTSTAMP:
|
|
|
|
case SIOCSHWTSTAMP:
|
|
|
|
/* Deny PTP operations on master if there is at least one
|
|
|
|
* switch in the tree that is PTP capable.
|
|
|
|
*/
|
|
|
|
list_for_each_entry(dp, &dst->ports, list)
|
|
|
|
if (dp->ds->ops->port_hwtstamp_get ||
|
|
|
|
dp->ds->ops->port_hwtstamp_set)
|
|
|
|
return -EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpu_dp->orig_ndo_ops && cpu_dp->orig_ndo_ops->ndo_do_ioctl)
|
|
|
|
err = cpu_dp->orig_ndo_ops->ndo_do_ioctl(dev, ifr, cmd);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-11-07 05:11:45 +08:00
|
|
|
static int dsa_master_ethtool_setup(struct net_device *dev)
|
2017-09-19 23:57:00 +08:00
|
|
|
{
|
2017-09-30 05:19:20 +08:00
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
2017-09-30 05:19:16 +08:00
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
2017-09-19 23:57:00 +08:00
|
|
|
struct ethtool_ops *ops;
|
|
|
|
|
|
|
|
ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL);
|
|
|
|
if (!ops)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-09-30 05:19:16 +08:00
|
|
|
cpu_dp->orig_ethtool_ops = dev->ethtool_ops;
|
|
|
|
if (cpu_dp->orig_ethtool_ops)
|
|
|
|
memcpy(ops, cpu_dp->orig_ethtool_ops, sizeof(*ops));
|
2017-09-19 23:57:00 +08:00
|
|
|
|
2019-08-03 03:34:55 +08:00
|
|
|
ops->get_regs_len = dsa_master_get_regs_len;
|
|
|
|
ops->get_regs = dsa_master_get_regs;
|
2017-09-19 23:57:00 +08:00
|
|
|
ops->get_sset_count = dsa_master_get_sset_count;
|
|
|
|
ops->get_ethtool_stats = dsa_master_get_ethtool_stats;
|
|
|
|
ops->get_strings = dsa_master_get_strings;
|
2018-04-26 03:12:52 +08:00
|
|
|
ops->get_ethtool_phy_stats = dsa_master_get_ethtool_phy_stats;
|
2017-09-19 23:57:00 +08:00
|
|
|
|
|
|
|
dev->ethtool_ops = ops;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-07 05:11:45 +08:00
|
|
|
static void dsa_master_ethtool_teardown(struct net_device *dev)
|
2017-09-19 23:57:00 +08:00
|
|
|
{
|
2017-09-30 05:19:20 +08:00
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
2017-09-19 23:57:00 +08:00
|
|
|
|
2017-09-30 05:19:16 +08:00
|
|
|
dev->ethtool_ops = cpu_dp->orig_ethtool_ops;
|
|
|
|
cpu_dp->orig_ethtool_ops = NULL;
|
2017-09-19 23:57:00 +08:00
|
|
|
}
|
2017-11-07 05:11:45 +08:00
|
|
|
|
2019-01-16 06:43:04 +08:00
|
|
|
static int dsa_master_ndo_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
|
|
|
struct dsa_switch *ds = cpu_dp->ds;
|
|
|
|
struct net_device_ops *ops;
|
|
|
|
|
|
|
|
if (dev->netdev_ops->ndo_get_phys_port_name)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL);
|
|
|
|
if (!ops)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
cpu_dp->orig_ndo_ops = dev->netdev_ops;
|
|
|
|
if (cpu_dp->orig_ndo_ops)
|
|
|
|
memcpy(ops, cpu_dp->orig_ndo_ops, sizeof(*ops));
|
|
|
|
|
|
|
|
ops->ndo_get_phys_port_name = dsa_master_get_phys_port_name;
|
net: dsa: Deny PTP on master if switch supports it
It is possible to kill PTP on a DSA switch completely and absolutely,
until a reboot, with a simple command:
tcpdump -i eth2 -j adapter_unsynced
where eth2 is the switch's DSA master.
Why? Well, in short, the PTP API in place today is a bit rudimentary and
relies on applications to retrieve the TX timestamps by polling the
error queue and looking at the cmsg structure. But there is no timestamp
identification of any sorts (except whether it's HW or SW), you don't
know how many more timestamps are there to come, which one is this one,
from whom it is, etc. In other words, the SO_TIMESTAMPING API is
fundamentally limited in that you can get a single HW timestamp from the
stack.
And the "-j adapter_unsynced" flag of tcpdump enables hardware
timestamping.
So let's imagine what happens when the DSA master decides it wants to
deliver TX timestamps to the skb's socket too:
- The timestamp that the user space sees is taken by the DSA master.
Whereas the RX timestamp will eventually be overwritten by the DSA
switch. So the RX and TX timestamps will be in different time bases
(aka garbage).
- The user space applications have no way to deal with the second (real)
TX timestamp finally delivered by the DSA switch, or even to know to
wait for it.
Take ptp4l from the linuxptp project, for example. This is its behavior
after running tcpdump, before the patch:
ptp4l[172]: [6469.594] Unexpected data on socket err queue:
ptp4l[172]: [6469.693] rms 8 max 16 freq -21257 +/- 11 delay 748 +/- 0
ptp4l[172]: [6469.711] Unexpected data on socket err queue:
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 03 aa 05 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: [6469.721] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 10 02
ptp4l[172]: 0010 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 01 c6 b1 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: [6469.838] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 10 02
ptp4l[172]: 0010 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 03 aa 06 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: [6469.848] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 13 02
ptp4l[172]: 0010 00 36 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 04 1a 45 05 7f
ptp4l[172]: 0030 00 00 5e 05 41 32 27 c2 1a 68 00 04 9f ff fe 05
ptp4l[172]: 0040 de 06 00 01
ptp4l[172]: [6469.855] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 10 02
ptp4l[172]: 0010 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 01 c6 b2 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: [6469.974] Unexpected data on socket err queue:
ptp4l[172]: 0000 01 80 c2 00 00 0e 00 1f 7b 63 02 48 88 f7 10 02
ptp4l[172]: 0010 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00
ptp4l[172]: 0020 00 00 00 1f 7b ff fe 63 02 48 00 03 aa 07 00 fd
ptp4l[172]: 0030 00 00 00 00 00 00 00 00 00 00
The ptp4l program itself is heavily patched to show this (more details
here [0]). Otherwise, by default it just hangs.
On the other hand, with the DSA patch to disallow HW timestamping
applied:
tcpdump -i eth2 -j adapter_unsynced
tcpdump: SIOCSHWTSTAMP failed: Device or resource busy
So it is a fact of life that PTP timestamping on the DSA master is
incompatible with timestamping on the switch MAC, at least with the
current API. And if the switch supports PTP, taking the timestamps from
the switch MAC is highly preferable anyway, due to the fact that those
don't contain the queuing latencies of the switch. So just disallow PTP
on the DSA master if there is any PTP-capable switch attached.
[0]: https://sourceforge.net/p/linuxptp/mailman/message/36880648/
Fixes: 0336369d3a4d ("net: dsa: forward hardware timestamping ioctls to switch driver")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-28 21:30:46 +08:00
|
|
|
ops->ndo_do_ioctl = dsa_master_ioctl;
|
2019-01-16 06:43:04 +08:00
|
|
|
|
|
|
|
dev->netdev_ops = ops;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dsa_master_ndo_teardown(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
|
|
|
|
|
|
|
dev->netdev_ops = cpu_dp->orig_ndo_ops;
|
|
|
|
cpu_dp->orig_ndo_ops = NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-29 05:40:04 +08:00
|
|
|
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 *cpu_dp = dev->dsa_ptr;
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n",
|
|
|
|
dsa_tag_protocol_to_str(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,
|
|
|
|
};
|
|
|
|
|
2018-12-09 00:05:18 +08:00
|
|
|
static void dsa_master_reset_mtu(struct net_device *dev)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
err = dev_set_mtu(dev, ETH_DATA_LEN);
|
|
|
|
if (err)
|
|
|
|
netdev_dbg(dev,
|
|
|
|
"Unable to reset MTU to exclude DSA overheads\n");
|
|
|
|
rtnl_unlock();
|
|
|
|
}
|
|
|
|
|
2017-11-07 05:11:45 +08:00
|
|
|
int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
|
|
|
|
{
|
2018-11-29 05:40:04 +08:00
|
|
|
int ret;
|
|
|
|
|
net: dsa: configure the MTU for switch ports
It is useful be able to configure port policers on a switch to accept
frames of various sizes:
- Increase the MTU for better throughput from the default of 1500 if it
is known that there is no 10/100 Mbps device in the network.
- Decrease the MTU to limit the latency of high-priority frames under
congestion, or work around various network segments that add extra
headers to packets which can't be fragmented.
For DSA slave ports, this is mostly a pass-through callback, called
through the regular ndo ops and at probe time (to ensure consistency
across all supported switches).
The CPU port is called with an MTU equal to the largest configured MTU
of the slave ports. The assumption is that the user might want to
sustain a bidirectional conversation with a partner over any switch
port.
The DSA master is configured the same as the CPU port, plus the tagger
overhead. Since the MTU is by definition L2 payload (sans Ethernet
header), it is up to each individual driver to figure out if it needs to
do anything special for its frame tags on the CPU port (it shouldn't
except in special cases). So the MTU does not contain the tagger
overhead on the CPU port.
However the MTU of the DSA master, minus the tagger overhead, is used as
a proxy for the MTU of the CPU port, which does not have a net device.
This is to avoid uselessly calling the .change_mtu function on the CPU
port when nothing should change.
So it is safe to assume that the DSA master and the CPU port MTUs are
apart by exactly the tagger's overhead in bytes.
Some changes were made around dsa_master_set_mtu(), function which was
now removed, for 2 reasons:
- dev_set_mtu() already calls dev_validate_mtu(), so it's redundant to
do the same thing in DSA
- __dev_set_mtu() returns 0 if ops->ndo_change_mtu is an absent method
That is to say, there's no need for this function in DSA, we can safely
call dev_set_mtu() directly, take the rtnl lock when necessary, and just
propagate whatever errors get reported (since the user probably wants to
be informed).
Some inspiration (mainly in the MTU DSA notifier) was taken from a
vaguely similar patch from Murali and Florian, who are credited as
co-developers down below.
Co-developed-by: Murali Krishna Policharla <murali.policharla@broadcom.com>
Signed-off-by: Murali Krishna Policharla <murali.policharla@broadcom.com>
Co-developed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-03-28 03:55:42 +08:00
|
|
|
rtnl_lock();
|
|
|
|
ret = dev_set_mtu(dev, ETH_DATA_LEN + cpu_dp->tag_ops->overhead);
|
|
|
|
rtnl_unlock();
|
|
|
|
if (ret)
|
|
|
|
netdev_warn(dev, "error %d setting MTU to include DSA overhead\n",
|
|
|
|
ret);
|
2018-12-06 18:36:05 +08:00
|
|
|
|
2017-11-07 05:11:45 +08:00
|
|
|
/* If we use a tagging format that doesn't have an ethertype
|
|
|
|
* field, make sure that all packets from this point on get
|
|
|
|
* sent to the tag format's receive function.
|
|
|
|
*/
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
dev->dsa_ptr = cpu_dp;
|
2018-11-29 05:40:04 +08:00
|
|
|
ret = dsa_master_ethtool_setup(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-01-16 06:43:04 +08:00
|
|
|
ret = dsa_master_ndo_setup(dev);
|
|
|
|
if (ret)
|
|
|
|
goto out_err_ethtool_teardown;
|
|
|
|
|
2018-11-29 05:40:04 +08:00
|
|
|
ret = sysfs_create_group(&dev->dev.kobj, &dsa_group);
|
|
|
|
if (ret)
|
2019-01-16 06:43:04 +08:00
|
|
|
goto out_err_ndo_teardown;
|
|
|
|
|
|
|
|
return ret;
|
2018-11-29 05:40:04 +08:00
|
|
|
|
2019-01-16 06:43:04 +08:00
|
|
|
out_err_ndo_teardown:
|
|
|
|
dsa_master_ndo_teardown(dev);
|
|
|
|
out_err_ethtool_teardown:
|
|
|
|
dsa_master_ethtool_teardown(dev);
|
2018-11-29 05:40:04 +08:00
|
|
|
return ret;
|
2017-11-07 05:11:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void dsa_master_teardown(struct net_device *dev)
|
|
|
|
{
|
2018-11-29 05:40:04 +08:00
|
|
|
sysfs_remove_group(&dev->dev.kobj, &dsa_group);
|
2019-01-16 06:43:04 +08:00
|
|
|
dsa_master_ndo_teardown(dev);
|
2017-11-07 05:11:45 +08:00
|
|
|
dsa_master_ethtool_teardown(dev);
|
2018-12-09 00:05:18 +08:00
|
|
|
dsa_master_reset_mtu(dev);
|
2017-11-07 05:11:45 +08:00
|
|
|
|
|
|
|
dev->dsa_ptr = NULL;
|
|
|
|
|
|
|
|
/* If we used a tagging format that doesn't have an ethertype
|
|
|
|
* field, make sure that all packets from this point get sent
|
|
|
|
* without the tag and go through the regular receive path.
|
|
|
|
*/
|
|
|
|
wmb();
|
|
|
|
}
|