Skip to content

Commit b63e78f

Browse files
vladimirolteankuba-moo
authored andcommitted
net: netdevsim: use mock PHC driver
I'd like to make netdevsim offload tc-taprio, but currently, this Qdisc emits a ETHTOOL_GET_TS_INFO call to the driver to make sure that it has a PTP clock, so that it is reasonably capable of offloading the schedule. By using the mock PHC driver, that becomes possible. Hardware timestamping is not necessary, and netdevsim does not support packet I/O anyway. Signed-off-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 40b0425 commit b63e78f

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

drivers/net/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ config NETDEVSIM
592592
depends on INET
593593
depends on IPV6 || IPV6=n
594594
depends on PSAMPLE || PSAMPLE=n
595+
depends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n
595596
select NET_DEVLINK
596597
help
597598
This driver is a developer testing tool and software model that can

drivers/net/netdevsim/ethtool.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ nsim_set_fecparam(struct net_device *dev, struct ethtool_fecparam *fecparam)
140140
return 0;
141141
}
142142

143+
static int nsim_get_ts_info(struct net_device *dev,
144+
struct ethtool_ts_info *info)
145+
{
146+
struct netdevsim *ns = netdev_priv(dev);
147+
148+
info->phc_index = mock_phc_index(ns->phc);
149+
150+
return 0;
151+
}
152+
143153
static const struct ethtool_ops nsim_ethtool_ops = {
144154
.supported_coalesce_params = ETHTOOL_COALESCE_ALL_PARAMS,
145155
.get_pause_stats = nsim_get_pause_stats,
@@ -153,6 +163,7 @@ static const struct ethtool_ops nsim_ethtool_ops = {
153163
.set_channels = nsim_set_channels,
154164
.get_fecparam = nsim_get_fecparam,
155165
.set_fecparam = nsim_set_fecparam,
166+
.get_ts_info = nsim_get_ts_info,
156167
};
157168

158169
static void nsim_ethtool_ring_init(struct netdevsim *ns)

drivers/net/netdevsim/netdev.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,19 @@ static void nsim_setup(struct net_device *dev)
291291

292292
static int nsim_init_netdevsim(struct netdevsim *ns)
293293
{
294+
struct mock_phc *phc;
294295
int err;
295296

297+
phc = mock_phc_create(&ns->nsim_bus_dev->dev);
298+
if (IS_ERR(phc))
299+
return PTR_ERR(phc);
300+
301+
ns->phc = phc;
296302
ns->netdev->netdev_ops = &nsim_netdev_ops;
297303

298304
err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev);
299305
if (err)
300-
return err;
306+
goto err_phc_destroy;
301307

302308
rtnl_lock();
303309
err = nsim_bpf_init(ns);
@@ -320,6 +326,8 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
320326
err_utn_destroy:
321327
rtnl_unlock();
322328
nsim_udp_tunnels_info_destroy(ns->netdev);
329+
err_phc_destroy:
330+
mock_phc_destroy(ns->phc);
323331
return err;
324332
}
325333

@@ -383,6 +391,7 @@ void nsim_destroy(struct netdevsim *ns)
383391
rtnl_unlock();
384392
if (nsim_dev_port_is_pf(ns->nsim_dev_port))
385393
nsim_udp_tunnels_info_destroy(dev);
394+
mock_phc_destroy(ns->phc);
386395
free_netdev(dev);
387396
}
388397

drivers/net/netdevsim/netdevsim.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/kernel.h>
2020
#include <linux/list.h>
2121
#include <linux/netdevice.h>
22+
#include <linux/ptp_mock.h>
2223
#include <linux/u64_stats_sync.h>
2324
#include <net/devlink.h>
2425
#include <net/udp_tunnel.h>
@@ -93,6 +94,7 @@ struct netdevsim {
9394
struct net_device *netdev;
9495
struct nsim_dev *nsim_dev;
9596
struct nsim_dev_port *nsim_dev_port;
97+
struct mock_phc *phc;
9698

9799
u64 tx_packets;
98100
u64 tx_bytes;

0 commit comments

Comments
 (0)