igc: PTP timestamping fixes
Subsystems (2)
cover igc: PTP timestamping fixes
Hi all,
This patch series provides some fixes and improvements to ptp timestamp handling in IGC driver.
IGC ptp implementation was based on IGB, but there are a few differences on how I225 handles rx timestamps that need to be considered. For example, I225 doesn't report rx timestamps via the TS bit rx descriptor + RXSTMPL/RXSTMPH registers mechanism. They are reported via the packet buffer only.
Apart from that, this patch series also fixes other issues like code duplication, dummy UDP filter configuration, and missing SRRCTL register clean up.
Regards,
Andre
Andre Guedes (6):
igc: Clean up rx timestamping logic
igc: Remove duplicate code in tx timestamp handling
igc: Check __IGC_PTP_TX_IN_PROGRESS instead of ptp_tx_skb
igc: Remove UDP filter setup in PTP code
igc: Refactor igc_ptp_set_timestamp_mode()
igc: Fix rx timestamp disabling
drivers/net/ethernet/intel/igc/igc.h | 3 - drivers/net/ethernet/intel/igc/igc_defines.h | 2 - drivers/net/ethernet/intel/igc/igc_main.c | 12 +- drivers/net/ethernet/intel/igc/igc_ptp.c | 256 +++++-------------- drivers/net/ethernet/intel/igc/igc_regs.h | 2 - 5 files changed, 75 insertions(+), 200 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/6 igc: Clean up rx timestamping logic
Differently from I210, I225 doesn't report rx timestamps via the TS bit rx descriptor + RXSTMPL/RXSTMPH registers mechanism. Rx timestamps are reported in the packet buffer only, which is implemented by igc_ptp_rx_ pktstamp(). So this patch removes igc_ptp_rx_rgtstamp() and all code related to it, copied from igb driver.
--- drivers/net/ethernet/intel/igc/igc.h | 3 -- drivers/net/ethernet/intel/igc/igc_defines.h | 2 - drivers/net/ethernet/intel/igc/igc_main.c | 12 ++---- drivers/net/ethernet/intel/igc/igc_ptp.c | 44 +------------------- drivers/net/ethernet/intel/igc/igc_regs.h | 2 - 5 files changed, 5 insertions(+), 58 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +0 -3
@@ -210,8 +210,6 @@ struct igc_adapter {struct sk_buff *ptp_tx_skb;struct hwtstamp_config tstamp_config;unsigned long ptp_tx_start; -unsigned long last_rx_ptp_check; -unsigned long last_rx_timestamp;unsigned int ptp_flags;/* System time value lock */ spinlock_t tmreg_lock;
@@ -549,7 +547,6 @@ void igc_ptp_init(struct igc_adapter *adapter);void igc_ptp_reset (struct igc_adapter *adapter);void igc_ptp_suspend (struct igc_adapter *adapter);void igc_ptp_stop (struct igc_adapter *adapter); -void igc_ptp_rx_rgtstamp (struct igc_q_vector *q_vector,struct sk_buff *skb);void igc_ptp_rx_pktstamp (struct igc_q_vector *q_vector,void *va,struct sk_buff *skb);int igc_ptp_set_ts_config (struct net_device *netdev,struct ifreq *ifr);
drivers/net/ethernet/intel/igc/igc_defines.h +0 -2
@@ -323,7 +323,6 @@/* Advanced Receive Descriptor bit definitions */ #define IGC_RXDADV_STAT_TSIP 0x08000/* timestamp in packet */ -#define IGC_RXDADV_STAT_TS 0x10000/* Pkt was time stamped */ #define IGC_RXDEXT_STATERR_CE 0x01000000#define IGC_RXDEXT_STATERR_SE 0x02000000
@@ -384,7 +383,6 @@#define IGC_FTQF_MASK_PROTO_BP 0x10000000/* Time Sync Receive Control bit definitions */ -#define IGC_TSYNCRXCTL_VALID 0x00000001/* Rx timestamp valid */ #define IGC_TSYNCRXCTL_TYPE_MASK 0x0000000E/* Rx type mask */ #define IGC_TSYNCRXCTL_TYPE_L2_V2 0x00#define IGC_TSYNCRXCTL_TYPE_L4_V1 0x02
drivers/net/ethernet/intel/igc/igc_main.c +4 -8
@@ -1480,9 +1480,9 @@ static inline void igc_rx_hash(struct igc_ring *ring,* @rx_desc: pointer to the EOP Rx descriptor * @skb: pointer to current skb being populated * -* This function checks the ring, descriptor, and packet information in -* order to populate the hash, checksum, VLAN, timestamp, protocol, and -* other fields within the skb. +* This function checks the ring, descriptor, and packet information in order +* to populate the hash, checksum, VLAN, protocol, and other fields within the +* skb. */ static void igc_process_skb_fields(struct igc_ring *rx_ring, union igc_adv_rx_desc *rx_desc,
@@ -1492,10 +1492,6 @@ static void igc_process_skb_fields(struct igc_ring *rx_ring,igc_rx_checksum (rx_ring, rx_desc, skb); -if (igc_test_staterr (rx_desc,IGC_RXDADV_STAT_TS ) && - !igc_test_staterr (rx_desc,IGC_RXDADV_STAT_TSIP )) -igc_ptp_rx_rgtstamp (rx_ring->q_vector, skb); -skb_record_rx_queue (skb, rx_ring->queue_index); skb->protocol =eth_type_trans (skb, rx_ring->netdev);
@@ -1976,7 +1972,7 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)/* probably a little skewed due to removing CRC */ total_bytes += skb->len; -/* populate checksum, timestamp, VLAN, and protocol */ +/* populate checksum, VLAN, and protocol */ igc_process_skb_fields (rx_ring, rx_desc, skb);napi_gro_receive (&q_vector->napi, skb);
drivers/net/ethernet/intel/igc/igc_ptp.c +1 -43
58 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_regs.h +0 -2
@@ -228,8 +228,6 @@#define IGC_SYSTIMR 0x0B6F8/* System time register Residue */ #define IGC_TIMINCA 0x0B608/* Increment attributes register - RW */ -#define IGC_RXSTMPL 0x0B624/* Rx timestamp Low - RO */ -#define IGC_RXSTMPH 0x0B628/* Rx timestamp High - RO */ #define IGC_TXSTMPL 0x0B618/* Tx timestamp value Low - RO */ #define IGC_TXSTMPH 0x0B61C/* Tx timestamp value High - RO */
Signature · 1 line
2.26.2
Brown
PATCH 1/6 igc: Clean up rx timestamping logic
Quoted 12 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Wednesday, June 3, 2020 5:01 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 1/6] igc: Clean up rx timestamping logicDifferently from I210, I225 doesn't report rx timestamps via the TS bit rx descriptor + RXSTMPL/RXSTMPH registers mechanism. Rx timestamps are reported in the packet buffer only, which is implemented by
igc_ptp_rx_pktstamp(). So this patch removesigc_ptp_rx_rgtstamp()and all code related to it, copied from igb driver.
Quoted 9 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 3 -- drivers/net/ethernet/intel/igc/igc_defines.h | 2 - drivers/net/ethernet/intel/igc/igc_main.c | 12 ++---- drivers/net/ethernet/intel/igc/igc_ptp.c | 44 +------------------- drivers/net/ethernet/intel/igc/igc_regs.h | 2 - 5 files changed, 5 insertions(+), 58 deletions(-)
PATCH 2/6 igc: Remove duplicate code in tx timestamp handling
In reply to Andre GuedesThe functions igc_ptp_tx_hang() and igc_ptp_tx_work() have duplicate code which handles tx timestamp timeouts. This patch does a trivial refactoring by moving that code to its own function and reusing it.
--- drivers/net/ethernet/intel/igc/igc_ptp.c | 34 +++++++++++------------- 1 file changed, 15 insertions(+), 19 deletions(-)
drivers/net/ethernet/intel/igc/igc_ptp.c +15 -19
@@ -386,11 +386,23 @@ static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter,return 0 ; } +static void igc_ptp_tx_timeout (struct igc_adapter *adapter) +{ +struct igc_hw *hw = &adapter->hw; + +dev_kfree_skb_any (adapter->ptp_tx_skb); + adapter->ptp_tx_skb =NULL ; + adapter->tx_hwtstamp_timeouts++; +clear_bit_unlock (__IGC_PTP_TX_IN_PROGRESS, &adapter->state); +/* Clear the tx valid bit in TSYNCTXCTL register to enable interrupt. */ +rd32 (IGC_TXSTMPH ); +netdev_warn (adapter->netdev,"Tx timestamp timeout\n" ); +} +void igc_ptp_tx_hang (struct igc_adapter *adapter) {bool timeout =time_is_before_jiffies (adapter->ptp_tx_start +IGC_PTP_TX_TIMEOUT ); -struct igc_hw *hw = &adapter->hw;if (!adapter->ptp_tx_skb)return ;
@@ -404,15 +416,7 @@ void igc_ptp_tx_hang(struct igc_adapter *adapter)*/ if (timeout) {cancel_work_sync (&adapter->ptp_tx_work); -dev_kfree_skb_any (adapter->ptp_tx_skb); - adapter->ptp_tx_skb =NULL ; -clear_bit_unlock (__IGC_PTP_TX_IN_PROGRESS, &adapter->state); - adapter->tx_hwtstamp_timeouts++; -/* Clear the Tx valid bit in TSYNCTXCTL register to enable -* interrupt -*/ -rd32 (IGC_TXSTMPH ); -netdev_warn (adapter->netdev,"Clearing Tx timestamp hang\n" ); +igc_ptp_tx_timeout (adapter); } }
@@ -467,15 +471,7 @@ static void igc_ptp_tx_work(struct work_struct *work)if (time_is_before_jiffies (adapter->ptp_tx_start +IGC_PTP_TX_TIMEOUT )) { -dev_kfree_skb_any (adapter->ptp_tx_skb); - adapter->ptp_tx_skb =NULL ; -clear_bit_unlock (__IGC_PTP_TX_IN_PROGRESS, &adapter->state); - adapter->tx_hwtstamp_timeouts++; -/* Clear the tx valid bit in TSYNCTXCTL register to enable -* interrupt -*/ -rd32 (IGC_TXSTMPH ); -netdev_warn (adapter->netdev,"Clearing Tx timestamp hang\n" ); +igc_ptp_tx_timeout (adapter);return ; }
Signature · 1 line
2.26.2
Brown
PATCH 2/6 igc: Remove duplicate code in tx timestamp handling
Quoted 7 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Wednesday, June 3, 2020 5:01 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 2/6] igc: Remove duplicate code in tx timestamp handling
Quoted 9 lines
The functions
igc_ptp_tx_hang()andigc_ptp_tx_work()have duplicate code which handles tx timestamp timeouts. This patch does a trivial refactoring by moving that code to its own function and reusing it.Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ptp.c | 34 +++++++++++------------- 1 file changed, 15 insertions(+), 19 deletions(-)
PATCH 3/6 igc: Check __IGC_PTP_TX_IN_PROGRESS instead of ptp_tx_skb
In reply to Andre GuedesThe __IGC_PTP_TX_IN_PROGRESS flag indicates we have a pending tx timestamp. In some places, instead of checking that flag, we check adapter->ptp_tx_skb. This patch fixes those places to use the flag.
Quick note about igc_ptp_tx_hwtstamp() change: when that function is called, adapter->ptp_tx_skb is expected to be valid always so we WARN_ON_ONCE() in case it is not.
Quick note about igc_ptp_suspend() change: when suspending, we don't really need to check if there is a pending timestamp. We can simply clear it unconditionally.
--- drivers/net/ethernet/intel/igc/igc_ptp.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/igc/igc_ptp.c +7 -9
@@ -404,9 +404,6 @@ void igc_ptp_tx_hang(struct igc_adapter *adapter)bool timeout =time_is_before_jiffies (adapter->ptp_tx_start +IGC_PTP_TX_TIMEOUT ); -if (!adapter->ptp_tx_skb) -return ; -if (!test_bit (__IGC_PTP_TX_IN_PROGRESS, &adapter->state))return ;
@@ -435,6 +432,9 @@ static void igc_ptp_tx_hwtstamp(struct igc_adapter *adapter)struct igc_hw *hw = &adapter->hw;u64 regval; +if (WARN_ON_ONCE (!skb)) +return ; + regval =rd32 (IGC_TXSTMPL ); regval |= (u64 )rd32 (IGC_TXSTMPH ) <<32 ;igc_ptp_systim_to_hwtstamp (adapter, &shhwtstamps, regval);
@@ -466,7 +466,7 @@ static void igc_ptp_tx_work(struct work_struct *work)struct igc_hw *hw = &adapter->hw;u32 tsynctxctl; -if (!adapter->ptp_tx_skb) +if (!test_bit (__IGC_PTP_TX_IN_PROGRESS, &adapter->state))return ; if (time_is_before_jiffies(adapter->ptp_tx_start +
@@ -588,11 +588,9 @@ void igc_ptp_suspend(struct igc_adapter *adapter)return ;cancel_work_sync (&adapter->ptp_tx_work); -if (adapter->ptp_tx_skb) { -dev_kfree_skb_any (adapter->ptp_tx_skb); - adapter->ptp_tx_skb =NULL ; -clear_bit_unlock (__IGC_PTP_TX_IN_PROGRESS, &adapter->state); - } +dev_kfree_skb_any (adapter->ptp_tx_skb); + adapter->ptp_tx_skb =NULL ; +clear_bit_unlock (__IGC_PTP_TX_IN_PROGRESS, &adapter->state); }/**
Signature · 1 line
2.26.2
Brown
PATCH 3/6 igc: Check __IGC_PTP_TX_IN_PROGRESS instead of ptp_tx_skb
Quoted 15 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Wednesday, June 3, 2020 5:01 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 3/6] igc: Check__IGC_PTP_TX_IN_PROGRESSinstead ofptp_tx_skbThe
__IGC_PTP_TX_IN_PROGRESSflag indicates we have a pending tx timestamp. In some places, instead of checking that flag, we checkadapter->ptp_tx_skb. This patch fixes those places to use the flag.Quick note about
igc_ptp_tx_hwtstamp()change: when that function is called,adapter->ptp_tx_skbis expected to be valid always so weWARN_ON_ONCE()in case it is not.
Quoted 9 lines
Quick note about
igc_ptp_suspend()change: when suspending, we don't really need to check if there is a pending timestamp. We can simply clear it unconditionally.Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ptp.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
PATCH 4/6 igc: Remove UDP filter setup in PTP code
In reply to Andre GuedesAs implemented in igc_ethtool_get_ts_info(), igc only supports HWTSTAMP_ FILTER_ALL so any HWTSTAMP_FILTER_* option the user may set falls back to HWTSTAMP_FILTER_ALL.
HWTSTAMP_FILTER_ALL is implemented via Rx Time Sync Control (TSYNCRXCTL) configuration which timestamps all incoming packets. Configuring an UDP filter, in addition to TSYNCRXCTL, doesn't add much so this patch removes that code. It also takes this opportunity to remove some non-applicable comments.
--- drivers/net/ethernet/intel/igc/igc_ptp.c | 51 +----------------------- 1 file changed, 1 insertion(+), 50 deletions(-)
drivers/net/ethernet/intel/igc/igc_ptp.c +1 -50
@@ -244,18 +244,7 @@ static void igc_ptp_enable_tstamp_all_rxqueues(struct igc_adapter *adapter,* @adapter: networking device structure * @config: hwtstamp configuration * -* Outgoing time stamping can be enabled and disabled. Play nice and -* disable it when requested, although it shouldn't case any overhead -* when no packet needs it. At most one packet in the queue may be -* marked for time stamping, otherwise it would be impossible to tell -* for sure to which packet the hardware time stamp belongs. -* -* Incoming time stamping has to be configured via the hardware -* filters. Not all combinations are supported, in particular event -* type has to be specified. Matching the kind of event packet is -* not supported, with the exception of "all V2 events regardless of -* level 2 or 4". -* +* Return: 0 in case of success, negative errno code otherwise. */ static int igc_ptp_set_timestamp_mode (struct igc_adapter *adapter,struct hwtstamp_config *config)
@@ -263,8 +252,6 @@ static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter,u32 tsync_tx_ctl =IGC_TSYNCTXCTL_ENABLED ;u32 tsync_rx_ctl =IGC_TSYNCRXCTL_ENABLED ;struct igc_hw *hw = &adapter->hw; -u32 tsync_rx_cfg =0 ; -bool is_l4 = false;u32 regval;/* reserved for future extensions */
@@ -285,15 +272,7 @@ static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter, tsync_rx_ctl =0 ;break ;case HWTSTAMP_FILTER_PTP_V1_L4_SYNC : - tsync_rx_ctl |=IGC_TSYNCRXCTL_TYPE_L4_V1 ; - tsync_rx_cfg =IGC_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE ; - is_l4 = true; -break ;case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ : - tsync_rx_ctl |=IGC_TSYNCRXCTL_TYPE_L4_V1 ; - tsync_rx_cfg =IGC_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE ; - is_l4 = true; -break ;case HWTSTAMP_FILTER_PTP_V2_EVENT :case HWTSTAMP_FILTER_PTP_V2_L2_EVENT :case HWTSTAMP_FILTER_PTP_V2_L4_EVENT :
@@ -303,32 +282,22 @@ static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter,case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ :case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ :case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ : - tsync_rx_ctl |=IGC_TSYNCRXCTL_TYPE_EVENT_V2 ; - config->rx_filter =HWTSTAMP_FILTER_PTP_V2_EVENT ; - is_l4 = true; -break ;case HWTSTAMP_FILTER_PTP_V1_L4_EVENT :case HWTSTAMP_FILTER_NTP_ALL :case HWTSTAMP_FILTER_ALL : tsync_rx_ctl |=IGC_TSYNCRXCTL_TYPE_ALL ; config->rx_filter =HWTSTAMP_FILTER_ALL ;break ; -/* fall through */ default : config->rx_filter =HWTSTAMP_FILTER_NONE ;return -ERANGE ; } -/* Per-packet timestamping only works if all packets are -* timestamped, so enable timestamping in all packets as long -* as one Rx filter was configured. -*/ if (tsync_rx_ctl) { tsync_rx_ctl =IGC_TSYNCRXCTL_ENABLED ; tsync_rx_ctl |=IGC_TSYNCRXCTL_TYPE_ALL ; tsync_rx_ctl |=IGC_TSYNCRXCTL_RXSYNSIG ; config->rx_filter =HWTSTAMP_FILTER_ALL ; - is_l4 = true;if (hw->mac.type == igc_i225) { regval =rd32 (IGC_RXPBS );
@@ -359,24 +328,6 @@ static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter, regval |= tsync_rx_ctl;wr32 (IGC_TSYNCRXCTL , regval); -/* define which PTP packets are time stamped */ -wr32 (IGC_TSYNCRXCFG , tsync_rx_cfg); - -/* L4 Queue Filter[3]: filter by destination port and protocol */ -if (is_l4) { -u32 ftqf = (IPPROTO_UDP /* UDP */ - |IGC_FTQF_VF_BP /* VF not compared */ - |IGC_FTQF_1588_TIME_STAMP /* Enable Timestamp */ - |IGC_FTQF_MASK );/* mask all inputs */ - ftqf &= ~IGC_FTQF_MASK_PROTO_BP ;/* enable protocol check */ - -wr32 (IGC_IMIR (3 ),htons (PTP_EV_PORT )); -wr32 (IGC_IMIREXT (3 ), - (IGC_IMIREXT_SIZE_BP |IGC_IMIREXT_CTRL_BP )); -wr32 (IGC_FTQF (3 ), ftqf); - }else { -wr32 (IGC_FTQF (3 ),IGC_FTQF_MASK ); - }wrfl ();/* clear TX time stamp registers, just to be sure */
Signature · 1 line
2.26.2
Brown
PATCH 4/6 igc: Remove UDP filter setup in PTP code
Quoted 20 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Wednesday, June 3, 2020 5:01 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 4/6] igc: Remove UDP filter setup in PTP codeAs implemented in
igc_ethtool_get_ts_info(), igc only supportsHWTSTAMP_FILTER_ALLso any HWTSTAMP_FILTER_* option the user may set falls back toHWTSTAMP_FILTER_ALL.
HWTSTAMP_FILTER_ALLis implemented via Rx Time Sync Control (TSYNCRXCTL)
configuration which timestamps all incoming packets. Configuring an UDP filter, in addition to TSYNCRXCTL, doesn't add much so this patch removes that code. It also takes this opportunity to remove some non-applicable comments.
Quoted 5 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ptp.c | 51 +----------------------- 1 file changed, 1 insertion(+), 50 deletions(-)
PATCH 5/6 igc: Refactor igc_ptp_set_timestamp_mode()
In reply to Andre GuedesCurrent igc_ptp_set_timestamp_mode() logic is a bit tangled since it handles many different hardware configurations in one single place, making it harder to follow. This patch untangles that code by breaking it into helper functions.
Quick note about the hw->mac.type check which was removed in this
refactoring: this check it not really needed since igc_i225 is the only type supported by the IGC driver.
--- drivers/net/ethernet/intel/igc/igc_ptp.c | 103 ++++++++++++----------- 1 file changed, 53 insertions(+), 50 deletions(-)
drivers/net/ethernet/intel/igc/igc_ptp.c +53 -50
@@ -239,6 +239,54 @@ static void igc_ptp_enable_tstamp_all_rxqueues(struct igc_adapter *adapter, } } +static void igc_ptp_disable_rx_timestamp (struct igc_adapter *adapter) +{ +struct igc_hw *hw = &adapter->hw; +u32 val; + +wr32 (IGC_TSYNCRXCTL ,0 ); + + val =rd32 (IGC_RXPBS ); + val &= ~IGC_RXPBS_CFG_TS_EN ; +wr32 (IGC_RXPBS , val); +} + +static void igc_ptp_enable_rx_timestamp (struct igc_adapter *adapter) +{ +struct igc_hw *hw = &adapter->hw; +u32 val; + + val =rd32 (IGC_RXPBS ); + val |=IGC_RXPBS_CFG_TS_EN ; +wr32 (IGC_RXPBS , val); + +/* FIXME: For now, only support retrieving RX timestamps from timer 0 +*/ +igc_ptp_enable_tstamp_all_rxqueues (adapter,0 ); + + val =IGC_TSYNCRXCTL_ENABLED |IGC_TSYNCRXCTL_TYPE_ALL | +IGC_TSYNCRXCTL_RXSYNSIG ; +wr32 (IGC_TSYNCRXCTL , val); +} + +static void igc_ptp_disable_tx_timestamp (struct igc_adapter *adapter) +{ +struct igc_hw *hw = &adapter->hw; + +wr32 (IGC_TSYNCTXCTL ,0 ); +} + +static void igc_ptp_enable_tx_timestamp (struct igc_adapter *adapter) +{ +struct igc_hw *hw = &adapter->hw; + +wr32 (IGC_TSYNCTXCTL ,IGC_TSYNCTXCTL_ENABLED |IGC_TSYNCTXCTL_TXSYNSIG ); + +/* Read TXSTMP registers to discard any timestamp previously stored. */ +rd32 (IGC_TXSTMPL ); +rd32 (IGC_TXSTMPH ); +} +/** * igc_ptp_set_timestamp_mode - setup hardware for timestamping * @adapter: networking device structure
@@ -249,19 +297,16 @@ static void igc_ptp_enable_tstamp_all_rxqueues(struct igc_adapter *adapter,static int igc_ptp_set_timestamp_mode (struct igc_adapter *adapter,struct hwtstamp_config *config) { -u32 tsync_tx_ctl =IGC_TSYNCTXCTL_ENABLED ; -u32 tsync_rx_ctl =IGC_TSYNCRXCTL_ENABLED ; -struct igc_hw *hw = &adapter->hw; -u32 regval; -/* reserved for future extensions */ if (config->flags)return -EINVAL ;switch (config->tx_type) {case HWTSTAMP_TX_OFF : - tsync_tx_ctl =0 ; +igc_ptp_disable_tx_timestamp (adapter); +break ;case HWTSTAMP_TX_ON : +igc_ptp_enable_tx_timestamp (adapter);break ;default :return -ERANGE ;
@@ -269,7 +314,7 @@ static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter,switch (config->rx_filter) {case HWTSTAMP_FILTER_NONE : - tsync_rx_ctl =0 ; +igc_ptp_disable_rx_timestamp (adapter);break ;case HWTSTAMP_FILTER_PTP_V1_L4_SYNC :case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ :
@@ -285,55 +330,13 @@ static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter,case HWTSTAMP_FILTER_PTP_V1_L4_EVENT :case HWTSTAMP_FILTER_NTP_ALL :case HWTSTAMP_FILTER_ALL : - tsync_rx_ctl |=IGC_TSYNCRXCTL_TYPE_ALL ; +igc_ptp_enable_rx_timestamp (adapter); config->rx_filter =HWTSTAMP_FILTER_ALL ;break ;default : - config->rx_filter =HWTSTAMP_FILTER_NONE ;return -ERANGE ; } -if (tsync_rx_ctl) { - tsync_rx_ctl =IGC_TSYNCRXCTL_ENABLED ; - tsync_rx_ctl |=IGC_TSYNCRXCTL_TYPE_ALL ; - tsync_rx_ctl |=IGC_TSYNCRXCTL_RXSYNSIG ; - config->rx_filter =HWTSTAMP_FILTER_ALL ; - -if (hw->mac.type == igc_i225) { - regval =rd32 (IGC_RXPBS ); - regval |=IGC_RXPBS_CFG_TS_EN ; -wr32 (IGC_RXPBS , regval); - -/* FIXME: For now, only support retrieving RX -* timestamps from timer 0 -*/ -igc_ptp_enable_tstamp_all_rxqueues (adapter,0 ); - } - } - -if (tsync_tx_ctl) { - tsync_tx_ctl =IGC_TSYNCTXCTL_ENABLED ; - tsync_tx_ctl |=IGC_TSYNCTXCTL_TXSYNSIG ; - } - -/* enable/disable TX */ - regval =rd32 (IGC_TSYNCTXCTL ); - regval &= ~IGC_TSYNCTXCTL_ENABLED ; - regval |= tsync_tx_ctl; -wr32 (IGC_TSYNCTXCTL , regval); - -/* enable/disable RX */ - regval =rd32 (IGC_TSYNCRXCTL ); - regval &= ~(IGC_TSYNCRXCTL_ENABLED |IGC_TSYNCRXCTL_TYPE_MASK ); - regval |= tsync_rx_ctl; -wr32 (IGC_TSYNCRXCTL , regval); - -wrfl (); - -/* clear TX time stamp registers, just to be sure */ - regval =rd32 (IGC_TXSTMPL ); - regval =rd32 (IGC_TXSTMPH ); -return 0 ; }
Signature · 1 line
2.26.2
Brown
PATCH 5/6 igc: Refactor igc_ptp_set_timestamp_mode()
Quoted 12 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Wednesday, June 3, 2020 5:01 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 5/6] igc: Refactorigc_ptp_set_timestamp_mode()Current
igc_ptp_set_timestamp_mode()logic is a bit tangled since it handles many different hardware configurations in one single place, making it harder to follow. This patch untangles that code by breaking it into helper functions.
Quoted 9 lines
Quick note about the
hw->mac.typecheck which was removed in this
refactoring: this check it not really needed sinceigc_i225is the only type supported by the IGC driver.Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ptp.c | 103 ++++++++++++----------- 1 file changed, 53 insertions(+), 50 deletions(-)
PATCH 6/6 igc: Fix rx timestamp disabling
In reply to Andre GuedesWhen rx timestamping is enabled, we set the timestamp bit in SRRCTL register for each queue, but we don't clear it when disabling. This patch fixes igc_ptp_disable_rx_timestamp() accordingly.
Also, this patch gets rid of igc_ptp_enable_tstamp_rxqueue() and igc_ptp_enable_tstamp_all_rxqueues() and move their logic into igc_ptp_enable_rx_timestamp() to keep the enable and disable helpers symmetric.
--- drivers/net/ethernet/intel/igc/igc_ptp.c | 54 ++++++++---------------- 1 file changed, 17 insertions(+), 37 deletions(-)
drivers/net/ethernet/intel/igc/igc_ptp.c +17 -37
@@ -205,47 +205,20 @@ void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, void *va,ktime_sub_ns (skb_hwtstamps (skb)->hwtstamp, adjust); } -/** -* igc_ptp_enable_tstamp_rxqueue - Enable RX timestamp for a queue -* @rx_ring: Pointer to RX queue -* @timer: Index for timer -* -* This function enables RX timestamping for a queue, and selects -* which 1588 timer will provide the timestamp. -*/ -static void igc_ptp_enable_tstamp_rxqueue (struct igc_adapter *adapter, -struct igc_ring *rx_ring,u8 timer) -{ -struct igc_hw *hw = &adapter->hw; -int reg_idx = rx_ring->reg_idx; -u32 srrctl =rd32 (IGC_SRRCTL (reg_idx)); - - srrctl |=IGC_SRRCTL_TIMESTAMP ; - srrctl |=IGC_SRRCTL_TIMER1SEL (timer); - srrctl |=IGC_SRRCTL_TIMER0SEL (timer); - -wr32 (IGC_SRRCTL (reg_idx), srrctl); -} - -static void igc_ptp_enable_tstamp_all_rxqueues (struct igc_adapter *adapter, -u8 timer) -{ -int i; - -for (i =0 ; i < adapter->num_rx_queues; i++) { -struct igc_ring *ring = adapter->rx_ring[i]; - -igc_ptp_enable_tstamp_rxqueue (adapter, ring, timer); - } -} -static void igc_ptp_disable_rx_timestamp (struct igc_adapter *adapter) {struct igc_hw *hw = &adapter->hw;u32 val; +int i;wr32 (IGC_TSYNCRXCTL ,0 ); +for (i =0 ; i < adapter->num_rx_queues; i++) { + val =rd32 (IGC_SRRCTL (i)); + val &= ~IGC_SRRCTL_TIMESTAMP ; +wr32 (IGC_SRRCTL (i), val); + } + val =rd32 (IGC_RXPBS ); val &= ~IGC_RXPBS_CFG_TS_EN ;wr32 (IGC_RXPBS , val);
@@ -255,14 +228,21 @@ static void igc_ptp_enable_rx_timestamp(struct igc_adapter *adapter) {struct igc_hw *hw = &adapter->hw;u32 val; +int i; val =rd32 (IGC_RXPBS ); val |=IGC_RXPBS_CFG_TS_EN ;wr32 (IGC_RXPBS , val); -/* FIXME: For now, only support retrieving RX timestamps from timer 0 -*/ -igc_ptp_enable_tstamp_all_rxqueues (adapter,0 ); +for (i =0 ; i < adapter->num_rx_queues; i++) { + val =rd32 (IGC_SRRCTL (i)); +/* FIXME: For now, only support retrieving RX timestamps from +* timer 0. +*/ + val |=IGC_SRRCTL_TIMER1SEL (0 ) |IGC_SRRCTL_TIMER0SEL (0 ) | +IGC_SRRCTL_TIMESTAMP ; +wr32 (IGC_SRRCTL (i), val); + } val =IGC_TSYNCRXCTL_ENABLED |IGC_TSYNCRXCTL_TYPE_ALL |IGC_TSYNCRXCTL_RXSYNSIG ;
Signature · 1 line
2.26.2
Brown
PATCH 6/6 igc: Fix rx timestamp disabling
Quoted 15 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Wednesday, June 3, 2020 5:01 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 6/6] igc: Fix rx timestamp disablingWhen rx timestamping is enabled, we set the timestamp bit in SRRCTL register for each queue, but we don't clear it when disabling. This patch fixes
igc_ptp_disable_rx_timestamp()accordingly.Also, this patch gets rid of
igc_ptp_enable_tstamp_rxqueue()andigc_ptp_enable_tstamp_all_rxqueues()and move their logic intoigc_ptp_enable_rx_timestamp()to keep the enable and disable helpers symmetric.
Quoted 5 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ptp.c | 54 ++++++++---------------- 1 file changed, 17 insertions(+), 37 deletions(-)