Skip to content

Commit cf2ef00

Browse files
vladimirolteanNipaLocal
authored and
NipaLocal
committed
net: stmmac: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
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 stmmac driver to the new API, so that timestamping configuration can be removed from the ndo_eth_ioctl() path completely. The existing timestamping calls are guarded by netif_running(). For stmmac_hwtstamp_get() that is probably unnecessary, since no hardware access is performed. But for stmmac_hwtstamp_set() I've preserved it, since at least some IPs probably need pm_runtime_resume_and_get() to access registers, which is otherwise called by __stmmac_open(). Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Vadim Fedorenko <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 10ff4a3 commit cf2ef00

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ struct stmmac_priv {
301301
unsigned int mode;
302302
unsigned int chain_mode;
303303
int extend_desc;
304-
struct hwtstamp_config tstamp_config;
304+
struct kernel_hwtstamp_config tstamp_config;
305305
struct ptp_clock *ptp_clock;
306306
struct ptp_clock_info ptp_clock_ops;
307307
unsigned int default_addend;

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -568,18 +568,19 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p,
568568
/**
569569
* stmmac_hwtstamp_set - control hardware timestamping.
570570
* @dev: device pointer.
571-
* @ifr: An IOCTL specific structure, that can contain a pointer to
572-
* a proprietary structure used to pass information to the driver.
571+
* @config: the timestamping configuration.
572+
* @extack: netlink extended ack structure for error reporting.
573573
* Description:
574574
* This function configures the MAC to enable/disable both outgoing(TX)
575575
* and incoming(RX) packets time stamping based on user input.
576576
* Return Value:
577577
* 0 on success and an appropriate -ve integer on failure.
578578
*/
579-
static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
579+
static int stmmac_hwtstamp_set(struct net_device *dev,
580+
struct kernel_hwtstamp_config *config,
581+
struct netlink_ext_ack *extack)
580582
{
581583
struct stmmac_priv *priv = netdev_priv(dev);
582-
struct hwtstamp_config config;
583584
u32 ptp_v2 = 0;
584585
u32 tstamp_all = 0;
585586
u32 ptp_over_ipv4_udp = 0;
@@ -590,34 +591,36 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
590591
u32 ts_event_en = 0;
591592

592593
if (!(priv->dma_cap.time_stamp || priv->adv_ts)) {
593-
netdev_alert(priv->dev, "No support for HW time stamping\n");
594+
NL_SET_ERR_MSG_MOD(extack, "No support for HW time stamping");
594595
priv->hwts_tx_en = 0;
595596
priv->hwts_rx_en = 0;
596597

597598
return -EOPNOTSUPP;
598599
}
599600

600-
if (copy_from_user(&config, ifr->ifr_data,
601-
sizeof(config)))
602-
return -EFAULT;
601+
if (!netif_running(dev)) {
602+
NL_SET_ERR_MSG_MOD(extack,
603+
"Cannot change timestamping configuration while up");
604+
return -ENODEV;
605+
}
603606

604607
netdev_dbg(priv->dev, "%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
605-
__func__, config.flags, config.tx_type, config.rx_filter);
608+
__func__, config->flags, config->tx_type, config->rx_filter);
606609

607-
if (config.tx_type != HWTSTAMP_TX_OFF &&
608-
config.tx_type != HWTSTAMP_TX_ON)
610+
if (config->tx_type != HWTSTAMP_TX_OFF &&
611+
config->tx_type != HWTSTAMP_TX_ON)
609612
return -ERANGE;
610613

611614
if (priv->adv_ts) {
612-
switch (config.rx_filter) {
615+
switch (config->rx_filter) {
613616
case HWTSTAMP_FILTER_NONE:
614617
/* time stamp no incoming packet at all */
615-
config.rx_filter = HWTSTAMP_FILTER_NONE;
618+
config->rx_filter = HWTSTAMP_FILTER_NONE;
616619
break;
617620

618621
case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
619622
/* PTP v1, UDP, any kind of event packet */
620-
config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
623+
config->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
621624
/* 'xmac' hardware can support Sync, Pdelay_Req and
622625
* Pdelay_resp by setting bit14 and bits17/16 to 01
623626
* This leaves Delay_Req timestamps out.
@@ -631,7 +634,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
631634

632635
case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
633636
/* PTP v1, UDP, Sync packet */
634-
config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
637+
config->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
635638
/* take time stamp for SYNC messages only */
636639
ts_event_en = PTP_TCR_TSEVNTENA;
637640

@@ -641,7 +644,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
641644

642645
case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
643646
/* PTP v1, UDP, Delay_req packet */
644-
config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
647+
config->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
645648
/* take time stamp for Delay_Req messages only */
646649
ts_master_en = PTP_TCR_TSMSTRENA;
647650
ts_event_en = PTP_TCR_TSEVNTENA;
@@ -652,7 +655,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
652655

653656
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
654657
/* PTP v2, UDP, any kind of event packet */
655-
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
658+
config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
656659
ptp_v2 = PTP_TCR_TSVER2ENA;
657660
/* take time stamp for all event messages */
658661
snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
@@ -663,7 +666,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
663666

664667
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
665668
/* PTP v2, UDP, Sync packet */
666-
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC;
669+
config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC;
667670
ptp_v2 = PTP_TCR_TSVER2ENA;
668671
/* take time stamp for SYNC messages only */
669672
ts_event_en = PTP_TCR_TSEVNTENA;
@@ -674,7 +677,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
674677

675678
case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
676679
/* PTP v2, UDP, Delay_req packet */
677-
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ;
680+
config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ;
678681
ptp_v2 = PTP_TCR_TSVER2ENA;
679682
/* take time stamp for Delay_Req messages only */
680683
ts_master_en = PTP_TCR_TSMSTRENA;
@@ -686,7 +689,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
686689

687690
case HWTSTAMP_FILTER_PTP_V2_EVENT:
688691
/* PTP v2/802.AS1 any layer, any kind of event packet */
689-
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
692+
config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
690693
ptp_v2 = PTP_TCR_TSVER2ENA;
691694
snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
692695
if (priv->synopsys_id < DWMAC_CORE_4_10)
@@ -698,7 +701,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
698701

699702
case HWTSTAMP_FILTER_PTP_V2_SYNC:
700703
/* PTP v2/802.AS1, any layer, Sync packet */
701-
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC;
704+
config->rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC;
702705
ptp_v2 = PTP_TCR_TSVER2ENA;
703706
/* take time stamp for SYNC messages only */
704707
ts_event_en = PTP_TCR_TSEVNTENA;
@@ -710,7 +713,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
710713

711714
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
712715
/* PTP v2/802.AS1, any layer, Delay_req packet */
713-
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ;
716+
config->rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ;
714717
ptp_v2 = PTP_TCR_TSVER2ENA;
715718
/* take time stamp for Delay_Req messages only */
716719
ts_master_en = PTP_TCR_TSMSTRENA;
@@ -724,26 +727,26 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
724727
case HWTSTAMP_FILTER_NTP_ALL:
725728
case HWTSTAMP_FILTER_ALL:
726729
/* time stamp any incoming packet */
727-
config.rx_filter = HWTSTAMP_FILTER_ALL;
730+
config->rx_filter = HWTSTAMP_FILTER_ALL;
728731
tstamp_all = PTP_TCR_TSENALL;
729732
break;
730733

731734
default:
732735
return -ERANGE;
733736
}
734737
} else {
735-
switch (config.rx_filter) {
738+
switch (config->rx_filter) {
736739
case HWTSTAMP_FILTER_NONE:
737-
config.rx_filter = HWTSTAMP_FILTER_NONE;
740+
config->rx_filter = HWTSTAMP_FILTER_NONE;
738741
break;
739742
default:
740743
/* PTP v1, UDP, any kind of event packet */
741-
config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
744+
config->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
742745
break;
743746
}
744747
}
745-
priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1);
746-
priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
748+
priv->hwts_rx_en = config->rx_filter != HWTSTAMP_FILTER_NONE;
749+
priv->hwts_tx_en = config->tx_type == HWTSTAMP_TX_ON;
747750

748751
priv->systime_flags = STMMAC_HWTS_ACTIVE;
749752

@@ -756,31 +759,30 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
756759

757760
stmmac_config_hw_tstamping(priv, priv->ptpaddr, priv->systime_flags);
758761

759-
memcpy(&priv->tstamp_config, &config, sizeof(config));
762+
priv->tstamp_config = *config;
760763

761-
return copy_to_user(ifr->ifr_data, &config,
762-
sizeof(config)) ? -EFAULT : 0;
764+
return 0;
763765
}
764766

765767
/**
766768
* stmmac_hwtstamp_get - read hardware timestamping.
767769
* @dev: device pointer.
768-
* @ifr: An IOCTL specific structure, that can contain a pointer to
769-
* a proprietary structure used to pass information to the driver.
770+
* @config: the timestamping configuration.
770771
* Description:
771772
* This function obtain the current hardware timestamping settings
772773
* as requested.
773774
*/
774-
static int stmmac_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
775+
static int stmmac_hwtstamp_get(struct net_device *dev,
776+
struct kernel_hwtstamp_config *config)
775777
{
776778
struct stmmac_priv *priv = netdev_priv(dev);
777-
struct hwtstamp_config *config = &priv->tstamp_config;
778779

779780
if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
780781
return -EOPNOTSUPP;
781782

782-
return copy_to_user(ifr->ifr_data, config,
783-
sizeof(*config)) ? -EFAULT : 0;
783+
*config = priv->tstamp_config;
784+
785+
return 0;
784786
}
785787

786788
/**
@@ -6225,12 +6227,6 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
62256227
case SIOCSMIIREG:
62266228
ret = phylink_mii_ioctl(priv->phylink, rq, cmd);
62276229
break;
6228-
case SIOCSHWTSTAMP:
6229-
ret = stmmac_hwtstamp_set(dev, rq);
6230-
break;
6231-
case SIOCGHWTSTAMP:
6232-
ret = stmmac_hwtstamp_get(dev, rq);
6233-
break;
62346230
default:
62356231
break;
62366232
}
@@ -7169,6 +7165,8 @@ static const struct net_device_ops stmmac_netdev_ops = {
71697165
.ndo_bpf = stmmac_bpf,
71707166
.ndo_xdp_xmit = stmmac_xdp_xmit,
71717167
.ndo_xsk_wakeup = stmmac_xsk_wakeup,
7168+
.ndo_hwtstamp_get = stmmac_hwtstamp_get,
7169+
.ndo_hwtstamp_set = stmmac_hwtstamp_set,
71727170
};
71737171

71747172
static void stmmac_reset_subtask(struct stmmac_priv *priv)

0 commit comments

Comments
 (0)