Skip to content
/ linux Public

Commit 854f599

Browse files
vladimirolteanSasha Levin
authored andcommitted
net: ixp4xx_eth: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
[ Upstream commit c14e1ec ] New timestamping API was introduced in commit 66f7223 ("net: add NDOs for configuring hardware timestamping") from kernel v6.6. It is time to convert the intel ixp4xx ethernet driver to the new API, so that the ndo_eth_ioctl() path can be removed completely. hwtstamp_get() and hwtstamp_set() are only called if netif_running() when the code path is engaged through the legacy ioctl. As I don't want to make an unnecessary functional change which I can't test, preserve that restriction when going through the new operations. When cpu_is_ixp46x() is false, the execution of SIOCGHWTSTAMP and SIOCSHWTSTAMP falls through to phy_mii_ioctl(), which may process it in case of a timestamping PHY, or may return -EOPNOTSUPP. In the new API, the core handles timestamping PHYs directly and does not call the netdev driver, so just return -EOPNOTSUPP directly for equivalent logic. A gratuitous change I chose to do anyway is prefixing hwtstamp_get() and hwtstamp_set() with the driver name, ipx4xx. This reflects modern coding sensibilities, and we are touching the involved lines anyway. The remainder of eth_ioctl() is exactly equivalent to phy_do_ioctl_running(), so use that. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Link: https://patch.msgid.link/20250508211043.3388702-1-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: 594163e ("net: ethernet: xscale: Check for PTP support properly") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 19f3599 commit 854f599

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

drivers/net/ethernet/xscale/ixp4xx_eth.c

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,20 @@ static void ixp_tx_timestamp(struct port *port, struct sk_buff *skb)
386386
__raw_writel(TX_SNAPSHOT_LOCKED, &regs->channel[ch].ch_event);
387387
}
388388

389-
static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
389+
static int ixp4xx_hwtstamp_set(struct net_device *netdev,
390+
struct kernel_hwtstamp_config *cfg,
391+
struct netlink_ext_ack *extack)
390392
{
391-
struct hwtstamp_config cfg;
392393
struct ixp46x_ts_regs *regs;
393394
struct port *port = netdev_priv(netdev);
394395
int ret;
395396
int ch;
396397

397-
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
398-
return -EFAULT;
398+
if (!cpu_is_ixp46x())
399+
return -EOPNOTSUPP;
400+
401+
if (!netif_running(netdev))
402+
return -EINVAL;
399403

400404
ret = ixp46x_ptp_find(&port->timesync_regs, &port->phc_index);
401405
if (ret)
@@ -404,10 +408,10 @@ static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
404408
ch = PORT2CHANNEL(port);
405409
regs = port->timesync_regs;
406410

407-
if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
411+
if (cfg->tx_type != HWTSTAMP_TX_OFF && cfg->tx_type != HWTSTAMP_TX_ON)
408412
return -ERANGE;
409413

410-
switch (cfg.rx_filter) {
414+
switch (cfg->rx_filter) {
411415
case HWTSTAMP_FILTER_NONE:
412416
port->hwts_rx_en = 0;
413417
break;
@@ -423,39 +427,45 @@ static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
423427
return -ERANGE;
424428
}
425429

426-
port->hwts_tx_en = cfg.tx_type == HWTSTAMP_TX_ON;
430+
port->hwts_tx_en = cfg->tx_type == HWTSTAMP_TX_ON;
427431

428432
/* Clear out any old time stamps. */
429433
__raw_writel(TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED,
430434
&regs->channel[ch].ch_event);
431435

432-
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
436+
return 0;
433437
}
434438

435-
static int hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
439+
static int ixp4xx_hwtstamp_get(struct net_device *netdev,
440+
struct kernel_hwtstamp_config *cfg)
436441
{
437-
struct hwtstamp_config cfg;
438442
struct port *port = netdev_priv(netdev);
439443

440-
cfg.flags = 0;
441-
cfg.tx_type = port->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
444+
if (!cpu_is_ixp46x())
445+
return -EOPNOTSUPP;
446+
447+
if (!netif_running(netdev))
448+
return -EINVAL;
449+
450+
cfg->flags = 0;
451+
cfg->tx_type = port->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
442452

443453
switch (port->hwts_rx_en) {
444454
case 0:
445-
cfg.rx_filter = HWTSTAMP_FILTER_NONE;
455+
cfg->rx_filter = HWTSTAMP_FILTER_NONE;
446456
break;
447457
case PTP_SLAVE_MODE:
448-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
458+
cfg->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
449459
break;
450460
case PTP_MASTER_MODE:
451-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
461+
cfg->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
452462
break;
453463
default:
454464
WARN_ON_ONCE(1);
455465
return -ERANGE;
456466
}
457467

458-
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
468+
return 0;
459469
}
460470

461471
static int ixp4xx_mdio_cmd(struct mii_bus *bus, int phy_id, int location,
@@ -977,21 +987,6 @@ static void eth_set_mcast_list(struct net_device *dev)
977987
}
978988

979989

980-
static int eth_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
981-
{
982-
if (!netif_running(dev))
983-
return -EINVAL;
984-
985-
if (cpu_is_ixp46x()) {
986-
if (cmd == SIOCSHWTSTAMP)
987-
return hwtstamp_set(dev, req);
988-
if (cmd == SIOCGHWTSTAMP)
989-
return hwtstamp_get(dev, req);
990-
}
991-
992-
return phy_mii_ioctl(dev->phydev, req, cmd);
993-
}
994-
995990
/* ethtool support */
996991

997992
static void ixp4xx_get_drvinfo(struct net_device *dev,
@@ -1376,9 +1371,11 @@ static const struct net_device_ops ixp4xx_netdev_ops = {
13761371
.ndo_stop = eth_close,
13771372
.ndo_start_xmit = eth_xmit,
13781373
.ndo_set_rx_mode = eth_set_mcast_list,
1379-
.ndo_eth_ioctl = eth_ioctl,
1374+
.ndo_eth_ioctl = phy_do_ioctl_running,
13801375
.ndo_set_mac_address = eth_mac_addr,
13811376
.ndo_validate_addr = eth_validate_addr,
1377+
.ndo_hwtstamp_get = ixp4xx_hwtstamp_get,
1378+
.ndo_hwtstamp_set = ixp4xx_hwtstamp_set,
13821379
};
13831380

13841381
static struct eth_plat_info *ixp4xx_of_get_platdata(struct device *dev)

0 commit comments

Comments
 (0)