@@ -568,18 +568,19 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p,
568
568
/**
569
569
* stmmac_hwtstamp_set - control hardware timestamping.
570
570
* @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 .
573
573
* Description:
574
574
* This function configures the MAC to enable/disable both outgoing(TX)
575
575
* and incoming(RX) packets time stamping based on user input.
576
576
* Return Value:
577
577
* 0 on success and an appropriate -ve integer on failure.
578
578
*/
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 )
580
582
{
581
583
struct stmmac_priv * priv = netdev_priv (dev );
582
- struct hwtstamp_config config ;
583
584
u32 ptp_v2 = 0 ;
584
585
u32 tstamp_all = 0 ;
585
586
u32 ptp_over_ipv4_udp = 0 ;
@@ -590,34 +591,36 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
590
591
u32 ts_event_en = 0 ;
591
592
592
593
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" );
594
595
priv -> hwts_tx_en = 0 ;
595
596
priv -> hwts_rx_en = 0 ;
596
597
597
598
return - EOPNOTSUPP ;
598
599
}
599
600
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
+ }
603
606
604
607
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 );
606
609
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 )
609
612
return - ERANGE ;
610
613
611
614
if (priv -> adv_ts ) {
612
- switch (config . rx_filter ) {
615
+ switch (config -> rx_filter ) {
613
616
case HWTSTAMP_FILTER_NONE :
614
617
/* time stamp no incoming packet at all */
615
- config . rx_filter = HWTSTAMP_FILTER_NONE ;
618
+ config -> rx_filter = HWTSTAMP_FILTER_NONE ;
616
619
break ;
617
620
618
621
case HWTSTAMP_FILTER_PTP_V1_L4_EVENT :
619
622
/* 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 ;
621
624
/* 'xmac' hardware can support Sync, Pdelay_Req and
622
625
* Pdelay_resp by setting bit14 and bits17/16 to 01
623
626
* This leaves Delay_Req timestamps out.
@@ -631,7 +634,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
631
634
632
635
case HWTSTAMP_FILTER_PTP_V1_L4_SYNC :
633
636
/* 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 ;
635
638
/* take time stamp for SYNC messages only */
636
639
ts_event_en = PTP_TCR_TSEVNTENA ;
637
640
@@ -641,7 +644,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
641
644
642
645
case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ :
643
646
/* 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 ;
645
648
/* take time stamp for Delay_Req messages only */
646
649
ts_master_en = PTP_TCR_TSMSTRENA ;
647
650
ts_event_en = PTP_TCR_TSEVNTENA ;
@@ -652,7 +655,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
652
655
653
656
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT :
654
657
/* 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 ;
656
659
ptp_v2 = PTP_TCR_TSVER2ENA ;
657
660
/* take time stamp for all event messages */
658
661
snap_type_sel = PTP_TCR_SNAPTYPSEL_1 ;
@@ -663,7 +666,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
663
666
664
667
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC :
665
668
/* 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 ;
667
670
ptp_v2 = PTP_TCR_TSVER2ENA ;
668
671
/* take time stamp for SYNC messages only */
669
672
ts_event_en = PTP_TCR_TSEVNTENA ;
@@ -674,7 +677,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
674
677
675
678
case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ :
676
679
/* 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 ;
678
681
ptp_v2 = PTP_TCR_TSVER2ENA ;
679
682
/* take time stamp for Delay_Req messages only */
680
683
ts_master_en = PTP_TCR_TSMSTRENA ;
@@ -686,7 +689,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
686
689
687
690
case HWTSTAMP_FILTER_PTP_V2_EVENT :
688
691
/* 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 ;
690
693
ptp_v2 = PTP_TCR_TSVER2ENA ;
691
694
snap_type_sel = PTP_TCR_SNAPTYPSEL_1 ;
692
695
if (priv -> synopsys_id < DWMAC_CORE_4_10 )
@@ -698,7 +701,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
698
701
699
702
case HWTSTAMP_FILTER_PTP_V2_SYNC :
700
703
/* 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 ;
702
705
ptp_v2 = PTP_TCR_TSVER2ENA ;
703
706
/* take time stamp for SYNC messages only */
704
707
ts_event_en = PTP_TCR_TSEVNTENA ;
@@ -710,7 +713,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
710
713
711
714
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ :
712
715
/* 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 ;
714
717
ptp_v2 = PTP_TCR_TSVER2ENA ;
715
718
/* take time stamp for Delay_Req messages only */
716
719
ts_master_en = PTP_TCR_TSMSTRENA ;
@@ -724,26 +727,26 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
724
727
case HWTSTAMP_FILTER_NTP_ALL :
725
728
case HWTSTAMP_FILTER_ALL :
726
729
/* time stamp any incoming packet */
727
- config . rx_filter = HWTSTAMP_FILTER_ALL ;
730
+ config -> rx_filter = HWTSTAMP_FILTER_ALL ;
728
731
tstamp_all = PTP_TCR_TSENALL ;
729
732
break ;
730
733
731
734
default :
732
735
return - ERANGE ;
733
736
}
734
737
} else {
735
- switch (config . rx_filter ) {
738
+ switch (config -> rx_filter ) {
736
739
case HWTSTAMP_FILTER_NONE :
737
- config . rx_filter = HWTSTAMP_FILTER_NONE ;
740
+ config -> rx_filter = HWTSTAMP_FILTER_NONE ;
738
741
break ;
739
742
default :
740
743
/* 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 ;
742
745
break ;
743
746
}
744
747
}
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 ;
747
750
748
751
priv -> systime_flags = STMMAC_HWTS_ACTIVE ;
749
752
@@ -756,31 +759,30 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
756
759
757
760
stmmac_config_hw_tstamping (priv , priv -> ptpaddr , priv -> systime_flags );
758
761
759
- memcpy ( & priv -> tstamp_config , & config , sizeof ( config )) ;
762
+ priv -> tstamp_config = * config ;
760
763
761
- return copy_to_user (ifr -> ifr_data , & config ,
762
- sizeof (config )) ? - EFAULT : 0 ;
764
+ return 0 ;
763
765
}
764
766
765
767
/**
766
768
* stmmac_hwtstamp_get - read hardware timestamping.
767
769
* @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.
770
771
* Description:
771
772
* This function obtain the current hardware timestamping settings
772
773
* as requested.
773
774
*/
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 )
775
777
{
776
778
struct stmmac_priv * priv = netdev_priv (dev );
777
- struct hwtstamp_config * config = & priv -> tstamp_config ;
778
779
779
780
if (!(priv -> dma_cap .time_stamp || priv -> dma_cap .atime_stamp ))
780
781
return - EOPNOTSUPP ;
781
782
782
- return copy_to_user (ifr -> ifr_data , config ,
783
- sizeof (* config )) ? - EFAULT : 0 ;
783
+ * config = priv -> tstamp_config ;
784
+
785
+ return 0 ;
784
786
}
785
787
786
788
/**
@@ -6225,12 +6227,6 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6225
6227
case SIOCSMIIREG :
6226
6228
ret = phylink_mii_ioctl (priv -> phylink , rq , cmd );
6227
6229
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 ;
6234
6230
default :
6235
6231
break ;
6236
6232
}
@@ -7169,6 +7165,8 @@ static const struct net_device_ops stmmac_netdev_ops = {
7169
7165
.ndo_bpf = stmmac_bpf ,
7170
7166
.ndo_xdp_xmit = stmmac_xdp_xmit ,
7171
7167
.ndo_xsk_wakeup = stmmac_xsk_wakeup ,
7168
+ .ndo_hwtstamp_get = stmmac_hwtstamp_get ,
7169
+ .ndo_hwtstamp_set = stmmac_hwtstamp_set ,
7172
7170
};
7173
7171
7174
7172
static void stmmac_reset_subtask (struct stmmac_priv * priv )
0 commit comments