Skip to content

Commit 0336369

Browse files
bstreiffdavem330
authored andcommitted
net: dsa: forward hardware timestamping ioctls to switch driver
This patch adds support to the dsa slave network device so that switch drivers can implement the SIOC[GS]HWTSTAMP ioctls and the ethtool timestamp-info interface. Signed-off-by: Brandon Streiff <[email protected]> Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4eb3be2 commit 0336369

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

include/net/dsa.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/workqueue.h>
2020
#include <linux/of.h>
2121
#include <linux/ethtool.h>
22+
#include <linux/net_tstamp.h>
2223
#include <net/devlink.h>
2324
#include <net/switchdev.h>
2425

@@ -367,6 +368,12 @@ struct dsa_switch_ops {
367368
int (*set_wol)(struct dsa_switch *ds, int port,
368369
struct ethtool_wolinfo *w);
369370

371+
/*
372+
* ethtool timestamp info
373+
*/
374+
int (*get_ts_info)(struct dsa_switch *ds, int port,
375+
struct ethtool_ts_info *ts);
376+
370377
/*
371378
* Suspend and resume
372379
*/
@@ -469,6 +476,14 @@ struct dsa_switch_ops {
469476
int port, struct net_device *br);
470477
void (*crosschip_bridge_leave)(struct dsa_switch *ds, int sw_index,
471478
int port, struct net_device *br);
479+
480+
/*
481+
* PTP functionality
482+
*/
483+
int (*port_hwtstamp_get)(struct dsa_switch *ds, int port,
484+
struct ifreq *ifr);
485+
int (*port_hwtstamp_set)(struct dsa_switch *ds, int port,
486+
struct ifreq *ifr);
472487
};
473488

474489
struct dsa_switch_driver {

net/dsa/slave.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,22 @@ dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
255255

256256
static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
257257
{
258+
struct dsa_slave_priv *p = netdev_priv(dev);
259+
struct dsa_switch *ds = p->dp->ds;
260+
int port = p->dp->index;
261+
262+
/* Pass through to switch driver if it supports timestamping */
263+
switch (cmd) {
264+
case SIOCGHWTSTAMP:
265+
if (ds->ops->port_hwtstamp_get)
266+
return ds->ops->port_hwtstamp_get(ds, port, ifr);
267+
break;
268+
case SIOCSHWTSTAMP:
269+
if (ds->ops->port_hwtstamp_set)
270+
return ds->ops->port_hwtstamp_set(ds, port, ifr);
271+
break;
272+
}
273+
258274
if (!dev->phydev)
259275
return -ENODEV;
260276

@@ -918,6 +934,18 @@ static int dsa_slave_set_rxnfc(struct net_device *dev,
918934
return ds->ops->set_rxnfc(ds, dp->index, nfc);
919935
}
920936

937+
static int dsa_slave_get_ts_info(struct net_device *dev,
938+
struct ethtool_ts_info *ts)
939+
{
940+
struct dsa_slave_priv *p = netdev_priv(dev);
941+
struct dsa_switch *ds = p->dp->ds;
942+
943+
if (!ds->ops->get_ts_info)
944+
return -EOPNOTSUPP;
945+
946+
return ds->ops->get_ts_info(ds, p->dp->index, ts);
947+
}
948+
921949
static const struct ethtool_ops dsa_slave_ethtool_ops = {
922950
.get_drvinfo = dsa_slave_get_drvinfo,
923951
.get_regs_len = dsa_slave_get_regs_len,
@@ -938,6 +966,7 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
938966
.set_link_ksettings = phy_ethtool_set_link_ksettings,
939967
.get_rxnfc = dsa_slave_get_rxnfc,
940968
.set_rxnfc = dsa_slave_set_rxnfc,
969+
.get_ts_info = dsa_slave_get_ts_info,
941970
};
942971

943972
/* legacy way, bypassing the bridge *****************************************/

0 commit comments

Comments
 (0)