Skip to content

Commit 202cb22

Browse files
kmaincentdavem330
authored andcommitted
net: macb: Convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
The hardware timestamping through ndo_eth_ioctl() is going away. Convert the macb driver to the new API before that can be removed. Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b8768dc commit 202cb22

File tree

3 files changed

+53
-32
lines changed

3 files changed

+53
-32
lines changed

drivers/net/ethernet/cadence/macb.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,9 +1165,10 @@ struct macb_ptp_info {
11651165
int (*get_ts_info)(struct net_device *dev,
11661166
struct ethtool_ts_info *info);
11671167
int (*get_hwtst)(struct net_device *netdev,
1168-
struct ifreq *ifr);
1168+
struct kernel_hwtstamp_config *tstamp_config);
11691169
int (*set_hwtst)(struct net_device *netdev,
1170-
struct ifreq *ifr, int cmd);
1170+
struct kernel_hwtstamp_config *tstamp_config,
1171+
struct netlink_ext_ack *extack);
11711172
};
11721173

11731174
struct macb_pm_data {
@@ -1314,7 +1315,7 @@ struct macb {
13141315
struct ptp_clock *ptp_clock;
13151316
struct ptp_clock_info ptp_clock_info;
13161317
struct tsu_incr tsu_incr;
1317-
struct hwtstamp_config tstamp_config;
1318+
struct kernel_hwtstamp_config tstamp_config;
13181319

13191320
/* RX queue filer rule set*/
13201321
struct ethtool_rx_fs_list rx_fs_list;
@@ -1363,8 +1364,12 @@ static inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, stru
13631364

13641365
gem_ptp_rxstamp(bp, skb, desc);
13651366
}
1366-
int gem_get_hwtst(struct net_device *dev, struct ifreq *rq);
1367-
int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd);
1367+
1368+
int gem_get_hwtst(struct net_device *dev,
1369+
struct kernel_hwtstamp_config *tstamp_config);
1370+
int gem_set_hwtst(struct net_device *dev,
1371+
struct kernel_hwtstamp_config *tstamp_config,
1372+
struct netlink_ext_ack *extack);
13681373
#else
13691374
static inline void gem_ptp_init(struct net_device *ndev) { }
13701375
static inline void gem_ptp_remove(struct net_device *ndev) { }

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,18 +3773,38 @@ static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37733773
if (!netif_running(dev))
37743774
return -EINVAL;
37753775

3776-
if (bp->ptp_info) {
3777-
switch (cmd) {
3778-
case SIOCSHWTSTAMP:
3779-
return bp->ptp_info->set_hwtst(dev, rq, cmd);
3780-
case SIOCGHWTSTAMP:
3781-
return bp->ptp_info->get_hwtst(dev, rq);
3782-
}
3783-
}
3784-
37853776
return phylink_mii_ioctl(bp->phylink, rq, cmd);
37863777
}
37873778

3779+
static int macb_hwtstamp_get(struct net_device *dev,
3780+
struct kernel_hwtstamp_config *cfg)
3781+
{
3782+
struct macb *bp = netdev_priv(dev);
3783+
3784+
if (!netif_running(dev))
3785+
return -EINVAL;
3786+
3787+
if (!bp->ptp_info)
3788+
return -EOPNOTSUPP;
3789+
3790+
return bp->ptp_info->get_hwtst(dev, cfg);
3791+
}
3792+
3793+
static int macb_hwtstamp_set(struct net_device *dev,
3794+
struct kernel_hwtstamp_config *cfg,
3795+
struct netlink_ext_ack *extack)
3796+
{
3797+
struct macb *bp = netdev_priv(dev);
3798+
3799+
if (!netif_running(dev))
3800+
return -EINVAL;
3801+
3802+
if (!bp->ptp_info)
3803+
return -EOPNOTSUPP;
3804+
3805+
return bp->ptp_info->set_hwtst(dev, cfg, extack);
3806+
}
3807+
37883808
static inline void macb_set_txcsum_feature(struct macb *bp,
37893809
netdev_features_t features)
37903810
{
@@ -3884,6 +3904,8 @@ static const struct net_device_ops macb_netdev_ops = {
38843904
#endif
38853905
.ndo_set_features = macb_set_features,
38863906
.ndo_features_check = macb_features_check,
3907+
.ndo_hwtstamp_set = macb_hwtstamp_set,
3908+
.ndo_hwtstamp_get = macb_hwtstamp_get,
38873909
};
38883910

38893911
/* Configure peripheral capabilities according to device tree
@@ -4539,6 +4561,8 @@ static const struct net_device_ops at91ether_netdev_ops = {
45394561
#ifdef CONFIG_NET_POLL_CONTROLLER
45404562
.ndo_poll_controller = at91ether_poll_controller,
45414563
#endif
4564+
.ndo_hwtstamp_set = macb_hwtstamp_set,
4565+
.ndo_hwtstamp_get = macb_hwtstamp_get,
45424566
};
45434567

45444568
static int at91ether_clk_init(struct platform_device *pdev, struct clk **pclk,

drivers/net/ethernet/cadence/macb_ptp.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,16 @@ static int gem_ptp_set_ts_mode(struct macb *bp,
374374
return 0;
375375
}
376376

377-
int gem_get_hwtst(struct net_device *dev, struct ifreq *rq)
377+
int gem_get_hwtst(struct net_device *dev,
378+
struct kernel_hwtstamp_config *tstamp_config)
378379
{
379-
struct hwtstamp_config *tstamp_config;
380380
struct macb *bp = netdev_priv(dev);
381381

382-
tstamp_config = &bp->tstamp_config;
382+
*tstamp_config = bp->tstamp_config;
383383
if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0)
384384
return -EOPNOTSUPP;
385385

386-
if (copy_to_user(rq->ifr_data, tstamp_config, sizeof(*tstamp_config)))
387-
return -EFAULT;
388-
else
389-
return 0;
386+
return 0;
390387
}
391388

392389
static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable)
@@ -401,22 +398,18 @@ static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable)
401398
macb_writel(bp, NCR, reg_val & ~MACB_BIT(OSSMODE));
402399
}
403400

404-
int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd)
401+
int gem_set_hwtst(struct net_device *dev,
402+
struct kernel_hwtstamp_config *tstamp_config,
403+
struct netlink_ext_ack *extack)
405404
{
406405
enum macb_bd_control tx_bd_control = TSTAMP_DISABLED;
407406
enum macb_bd_control rx_bd_control = TSTAMP_DISABLED;
408-
struct hwtstamp_config *tstamp_config;
409407
struct macb *bp = netdev_priv(dev);
410408
u32 regval;
411409

412-
tstamp_config = &bp->tstamp_config;
413410
if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0)
414411
return -EOPNOTSUPP;
415412

416-
if (copy_from_user(tstamp_config, ifr->ifr_data,
417-
sizeof(*tstamp_config)))
418-
return -EFAULT;
419-
420413
switch (tstamp_config->tx_type) {
421414
case HWTSTAMP_TX_OFF:
422415
break;
@@ -463,12 +456,11 @@ int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd)
463456
return -ERANGE;
464457
}
465458

459+
bp->tstamp_config = *tstamp_config;
460+
466461
if (gem_ptp_set_ts_mode(bp, tx_bd_control, rx_bd_control) != 0)
467462
return -ERANGE;
468463

469-
if (copy_to_user(ifr->ifr_data, tstamp_config, sizeof(*tstamp_config)))
470-
return -EFAULT;
471-
else
472-
return 0;
464+
return 0;
473465
}
474466

0 commit comments

Comments
 (0)