Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20230807193324.4128292-8-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
b63e78fc 40b0425f

+24 -1
+1
drivers/net/Kconfig
··· 592 592 depends on INET 593 593 depends on IPV6 || IPV6=n 594 594 depends on PSAMPLE || PSAMPLE=n 595 + depends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n 595 596 select NET_DEVLINK 596 597 help 597 598 This driver is a developer testing tool and software model that can
+11
drivers/net/netdevsim/ethtool.c
··· 140 140 return 0; 141 141 } 142 142 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 + 143 153 static const struct ethtool_ops nsim_ethtool_ops = { 144 154 .supported_coalesce_params = ETHTOOL_COALESCE_ALL_PARAMS, 145 155 .get_pause_stats = nsim_get_pause_stats, ··· 163 153 .set_channels = nsim_set_channels, 164 154 .get_fecparam = nsim_get_fecparam, 165 155 .set_fecparam = nsim_set_fecparam, 156 + .get_ts_info = nsim_get_ts_info, 166 157 }; 167 158 168 159 static void nsim_ethtool_ring_init(struct netdevsim *ns)
+10 -1
drivers/net/netdevsim/netdev.c
··· 291 291 292 292 static int nsim_init_netdevsim(struct netdevsim *ns) 293 293 { 294 + struct mock_phc *phc; 294 295 int err; 295 296 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; 296 302 ns->netdev->netdev_ops = &nsim_netdev_ops; 297 303 298 304 err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev); 299 305 if (err) 300 - return err; 306 + goto err_phc_destroy; 301 307 302 308 rtnl_lock(); 303 309 err = nsim_bpf_init(ns); ··· 326 320 err_utn_destroy: 327 321 rtnl_unlock(); 328 322 nsim_udp_tunnels_info_destroy(ns->netdev); 323 + err_phc_destroy: 324 + mock_phc_destroy(ns->phc); 329 325 return err; 330 326 } 331 327 ··· 391 383 rtnl_unlock(); 392 384 if (nsim_dev_port_is_pf(ns->nsim_dev_port)) 393 385 nsim_udp_tunnels_info_destroy(dev); 386 + mock_phc_destroy(ns->phc); 394 387 free_netdev(dev); 395 388 } 396 389
+2
drivers/net/netdevsim/netdevsim.h
··· 19 19 #include <linux/kernel.h> 20 20 #include <linux/list.h> 21 21 #include <linux/netdevice.h> 22 + #include <linux/ptp_mock.h> 22 23 #include <linux/u64_stats_sync.h> 23 24 #include <net/devlink.h> 24 25 #include <net/udp_tunnel.h> ··· 94 93 struct net_device *netdev; 95 94 struct nsim_dev *nsim_dev; 96 95 struct nsim_dev_port *nsim_dev_port; 96 + struct mock_phc *phc; 97 97 98 98 u64 tx_packets; 99 99 u64 tx_bytes;