ice: Add low latency Tx timestamp read
Subsystems (2)
PATCH 1/1 ice: Add low latency Tx timestamp read
E810 products can support low latency Tx timestamp register read. This requires usage of threaded IRQ instead of kthread to reduce the kthread start latency (spikes up to 20 ms).
Add a check for the device capability and use the new method if supported.
--- drivers/net/ethernet/intel/ice/ice_common.c | 4 + drivers/net/ethernet/intel/ice/ice_main.c | 32 +++++-- drivers/net/ethernet/intel/ice/ice_ptp.c | 47 +++++----- drivers/net/ethernet/intel/ice/ice_ptp.h | 7 +- drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 98 ++++++++++++++++++--- drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 7 ++ drivers/net/ethernet/intel/ice/ice_type.h | 2 + 7 files changed, 152 insertions(+), 45 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +4 -0
@@ -2397,6 +2397,8 @@ ice_parse_1588_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p, info->tmr1_owned = ((number &ICE_TS_TMR1_OWND_M ) !=0 ); info->tmr1_ena = ((number &ICE_TS_TMR1_ENA_M ) !=0 ); + info->ts_ll_read = ((number &ICE_TS_LL_TX_TS_READ_M ) !=0 ); + info->ena_ports = logical_id; info->tmr_own_map = phys_id;
@@ -2414,6 +2416,8 @@ ice_parse_1588_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p, info->tmr1_owned);ice_debug (hw,ICE_DBG_INIT ,"dev caps: tmr1_ena = %u\n" , info->tmr1_ena); +ice_debug (hw,ICE_DBG_INIT ,"dev caps: ts_ll_read = %u\n" , + info->ts_ll_read);ice_debug (hw,ICE_DBG_INIT ,"dev caps: ieee_1588 ena_ports = %u\n" , info->ena_ports); ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr_own_map = %u\n",
drivers/net/ethernet/intel/ice/ice_main.c +27 -5
@@ -3078,7 +3078,8 @@ static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)if (oicr &PFINT_OICR_TSYN_TX_M ) { ena_mask &= ~PFINT_OICR_TSYN_TX_M ; -ice_ptp_process_ts (pf); +if (!hw->reset_ongoing) + ret =IRQ_WAKE_THREAD ; }if (oicr &PFINT_OICR_TSYN_EVNT_M ) {
@@ -3113,7 +3114,8 @@ static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)ice_service_task_schedule (pf); } } - ret =IRQ_HANDLED ; +if (!ret) + ret =IRQ_HANDLED ;ice_service_task_schedule (pf);ice_irq_dynamic_ena (hw,NULL ,NULL );
@@ -3121,6 +3123,24 @@ static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)return ret; } +/** +* ice_misc_intr_thread_fn - misc interrupt thread function +* @irq: interrupt number +* @data: pointer to a q_vector +*/ +static irqreturn_t ice_misc_intr_thread_fn (int __always_unused irq,void *data) +{ +struct ice_pf *pf = (struct ice_pf *)data; +irqreturn_t ret =IRQ_HANDLED ; +bool irq_handled; + + irq_handled =ice_ptp_process_ts (pf); +if (!irq_handled) + ret =IRQ_WAKE_THREAD ; + +return ret; +} +/** * ice_dis_ctrlq_interrupts - disable control queue interrupts * @hw: pointer to HW structure
@@ -3233,10 +3253,12 @@ static int ice_req_irq_msix_misc(struct ice_pf *pf) pf->num_avail_sw_msix -=1 ; pf->oicr_idx = (u16 )oicr_idx; - err =devm_request_irq (dev, pf->msix_entries[pf->oicr_idx].vector, - ice_misc_intr,0 , pf->int_name, pf); + err =devm_request_threaded_irq (dev, + pf->msix_entries[pf->oicr_idx].vector, + ice_misc_intr, ice_misc_intr_thread_fn, +0 , pf->int_name, pf);if (err) { -dev_err (dev,"devm_request_irq for %s failed: %d\n" , +dev_err (dev,"devm_request_threaded_irq for %s failed: %d\n" , pf->int_name, err);ice_free_res (pf->irq_tracker,1 ,ICE_RES_MISC_VEC_ID ); pf->num_avail_sw_msix +=1 ;
drivers/net/ethernet/intel/ice/ice_ptp.c +22 -25
114 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp.h +3 -4
@@ -105,7 +105,6 @@ struct ice_tx_tstamp {/** * struct ice_ptp_tx - Tracking structure for all Tx timestamp requests on a port -* @work: work function to handle processing of Tx timestamps * @lock: lock to prevent concurrent write to in_use bitmap * @tstamps: array of len to store outstanding requests * @in_use: bitmap of len to indicate which slots are in use
@@ -117,7 +116,6 @@ struct ice_tx_tstamp {* window, timestamps are temporarily disabled. */ struct ice_ptp_tx { -struct kthread_work work;spinlock_t lock;/* lock protecting in_use bitmap */ struct ice_tx_tstamp *tstamps;unsigned long *in_use;
@@ -236,7 +234,7 @@ void ice_ptp_cfg_timestamp(struct ice_pf *pf, bool ena);int ice_get_ptp_clock_index (struct ice_pf *pf);s8 ice_ptp_request_ts (struct ice_ptp_tx *tx,struct sk_buff *skb); -void ice_ptp_process_ts (struct ice_pf *pf); +bool ice_ptp_process_ts (struct ice_pf *pf); void ice_ptp_rx_hwtstamp(struct ice_rx_ring *rx_ring,
@@ -269,7 +267,8 @@ ice_ptp_request_ts(struct ice_ptp_tx *tx, struct sk_buff *skb)return -1 ; } -static inline void ice_ptp_process_ts (struct ice_pf *pf) { } +static inline bool ice_ptp_process_ts (struct ice_pf *pf) +{return true; }static inline void ice_ptp_rx_hwtstamp (struct ice_rx_ring *rx_ring,union ice_32b_rx_flex_desc *rx_desc,struct sk_buff *skb) { }
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +87 -11
131 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +7 -0
@@ -402,6 +402,7 @@ bool ice_is_pca9575_present(struct ice_hw *hw);#define INCVAL_HIGH_M 0xFF/* Timestamp block macros */ +#define TS_VALID BIT(0)#define TS_LOW_M 0xFFFFFFFF#define TS_HIGH_M 0xFF#define TS_HIGH_S 32
@@ -413,6 +414,12 @@ bool ice_is_pca9575_present(struct ice_hw *hw);#define BYTES_PER_IDX_ADDR_L_U 8#define BYTES_PER_IDX_ADDR_L 4 +/* Tx timestamp low latency read definitions */ +#define TS_LL_READ_RETRIES 200 +#define TS_LL_READ_TS_HIGH GENMASK(23, 16) +#define TS_LL_READ_TS_IDX GENMASK(29, 24) +#define TS_LL_READ_TS BIT(31) +/* Internal PHY timestamp address */ #define TS_L (a, idx) ((a) + ((idx) * BYTES_PER_IDX_ADDR_L_U))#define TS_H (a, idx) ((a) + ((idx) * BYTES_PER_IDX_ADDR_L_U + \
drivers/net/ethernet/intel/ice/ice_type.h +2 -0
@@ -347,6 +347,7 @@ struct ice_ts_func_info {#define ICE_TS_DEV_ENA_M BIT(24)#define ICE_TS_TMR0_ENA_M BIT(25)#define ICE_TS_TMR1_ENA_M BIT(26) +#define ICE_TS_LL_TX_TS_READ_M BIT(28)struct ice_ts_dev_info {/* Device specific info */
@@ -359,6 +360,7 @@ struct ice_ts_dev_info {u8 ena;u8 tmr0_ena;u8 tmr1_ena; +u8 ts_ll_read; };/* Function specific capabilities */
Signature · 6 lines
2.34.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
From: Karol Kolacinski <[email protected]>
Date: Fri, 22 Jul 2022 17:36:10 +0200
(offtop below)
Quoted 16 lines
E810 products can support low latency Tx timestamp register read. This requires usage of threaded IRQ instead of kthread to reduce the kthread start latency (spikes up to 20 ms).
Add a check for the device capability and use the new method if supported.Signed-off-by Karol Kolacinski <[email protected]>--- drivers/net/ethernet/intel/ice/ice_common.c | 4 + drivers/net/ethernet/intel/ice/ice_main.c | 32 +++++-- drivers/net/ethernet/intel/ice/ice_ptp.c | 47 +++++----- drivers/net/ethernet/intel/ice/ice_ptp.h | 7 +- drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 98 ++++++++++++++++++--- drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 7 ++ drivers/net/ethernet/intel/ice/ice_type.h | 2 + 7 files changed, 152 insertions(+), 45 deletions(-)
[...]
Quoted 13 lines
drivers/net/ethernet/intel/ice/ice_type.h +1
-0@@ -347,6 +347,7 @@ struct ice_ts_func_info {#define ICE_TS_DEV_ENA_M BIT(24)#define ICE_TS_TMR0_ENA_M BIT(25)#define ICE_TS_TMR1_ENA_M BIT(26) +#define ICE_TS_LL_TX_TS_READ_M BIT(28)struct ice_ts_dev_info {/* Device specific info */
drivers/net/ethernet/intel/ice/ice_type.h struct ice_ts_dev_info { · line 363
Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_type.h +1
-0@@ -359,6 +360,7 @@ struct ice_ts_dev_info {u8 ena;u8 tmr0_ena;u8 tmr1_ena; +u8 ts_ll_read;
Those all are flags, what about converting them to a bitfield/bitmap (in a separate patch)? 1 byte per bit is a waste. Even though currently there are 6 bytes accupied (after your addition) and long (unsigned) is of 8 bytes, more flags here will waste more and more space.
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_type.h +0
-0};/* Function specific capabilities */ Signature · 1 line
2.34.1
Thanks,
Olek
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Tony Nguyen
maintainerQuoted 8 lines · Karol Kolacinski
E810 products can support low latency Tx timestamp register read. This requires usage of threaded IRQ instead of kthread to reduce the kthread start latency (spikes up to 20 ms).
Add a check for the device capability and use the new method if supported.Signed-off-by Karol Kolacinski <[email protected]>---
<snip>
drivers/net/ethernet/intel/ice/ice_main.c static irqreturn_t ice_misc_intr(int __always_unused irq, void *data) · line 3133
Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_main.c +8
-0@@ -3121,6 +3123,24 @@ static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)return ret; } +/** +* ice_misc_intr_thread_fn - misc interrupt thread function +* @irq: interrupt number +* @data: pointer to a q_vector +*/ +static irqreturn_t ice_misc_intr_thread_fn (int __always_unused irq,void *data) +{ +struct ice_pf *pf = (struct ice_pf *)data;
Cast shouldn't be needed.
Quoted 13 lines
drivers/net/ethernet/intel/ice/ice_main.c +10
-0+irqreturn_t ret =IRQ_HANDLED ; +bool irq_handled; + + irq_handled =ice_ptp_process_ts (pf); +if (!irq_handled) + ret =IRQ_WAKE_THREAD ; + +return ret; +} +/** * ice_dis_ctrlq_interrupts - disable control queue interrupts * @hw: pointer to HW structure
<snip>
Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +1
-3@@ -2171,16 +2170,17 @@ s8 ice_ptp_request_ts(struct ice_ptp_tx *tx, struct sk_buff *skb) }/** -* ice_ptp_process_ts - Spawn kthread work to handle timestamps +* ice_ptp_process_ts - Process the PTP Tx timestamps * @pf: Board private structure * -* Queue work required to process the PTP Tx timestamps outside of interrupt -* context.
drivers/net/ethernet/intel/ice/ice_ptp.c s8 ice_ptp_request_ts(struct ice_ptp_tx *tx, struct sk_buff *skb) · line 2183
Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +5
-2+* Returns true if timestamps are processed. */ -void ice_ptp_process_ts (struct ice_pf *pf) +bool ice_ptp_process_ts (struct ice_pf *pf) {if (pf->ptp.port.tx.init) -kthread_queue_work (pf->ptp.kworker, &pf->ptp.port.tx.work); +return ice_ptp_tx_tstamp (&pf->ptp.port.tx); +else +return false;
I believe preference is to remove the else and have an un-indented return false.
<snip>
Quoted 30 lines
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +25
-1@@ -2587,38 +2588,113 @@ static int ice_write_phy_reg_e810(struct ice_hw *hw, u32 addr, u32 val) }/** -* ice_read_phy_tstamp_e810 - Read a PHY timestamp out of the external PHY +* ice_read_phy_tstamp_ll_e810 - Read a PHY timestamp registers through the FW +* @hw: pointer to the HW struct +* @idx: the timestamp index to read +* @hi: 8 bit timestamp high value +* @lo: 32 bit timestamp low value +* +* Read a 8bit timestamp high value and 32 bit timestamp low value out of the +* timestamp block of the external PHY on the E810 device using the low latency +* timestamp read. +*/ +static int +ice_read_phy_tstamp_ll_e810 (struct ice_hw *hw,u8 idx,u8 *hi,u32 *lo) +{ +u32 val; +u8 i; + +/* Write TS index to read to the PF register so the FW can read it */ + val =FIELD_PREP (TS_LL_READ_TS_IDX , idx) |TS_LL_READ_TS ; +wr32 (hw,PF_SB_ATQBAL , val); + +/* Read the register repeatedly until the FW provides us the TS */ +for (i =TS_LL_READ_RETRIES ; i >0 ; i--) { + val =rd32 (hw,PF_SB_ATQBAL ); + +/* When the bit is cleared, the TS is ready in the register */
drivers/net/ethernet/intel/ice/ice_ptp_hw.c static int ice_write_phy_reg_e810(struct ice_hw *hw, u32 addr, u32 val) · line 2625
Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +10
-0+if (!(FIELD_GET (TS_LL_READ_TS , val))) { +/* High 8 bit value of the TS is on the bits 16:23 */ + *hi =FIELD_GET (TS_LL_READ_TS_HIGH , val); + +/* Read the low 32 bit value and set the TS valid bit */ + *lo =rd32 (hw,PF_SB_ATQBAH ) |TS_VALID ; +return 0 ; + } + +udelay (10 );
CHECK: usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst
drivers/net/ethernet/intel/ice/ice_ptp_hw.c static int ice_write_phy_reg_e810(struct ice_hw *hw, u32 addr, u32 val) · line 2631
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +6
-0+ } + +/* FW failed to provide the TS in time */ +ice_debug (hw,ICE_DBG_PTP ,"Failed to read PTP timestamp using low latency read\n" ); +return -EINVAL ; +}
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
PATCH 1/1 ice: Add low latency Tx timestamp read
Hi Tony,
Quoted 6 lines · Anthony L Nguyen
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_main.c +0
-0@@ -3121,6 +3123,24 @@ static irqreturn_t ice_misc_intr(int __always_unused irq, void *data) return ret; }
+/**
+ *ice_misc_intr_thread_fn- misc interrupt thread function
Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_main.c static irqreturn_t ice_misc_intr(int __always_unused irq, void *data) · line 3133
Quoted 6 lines
+ * @irq: interrupt number
+ * @data: pointer to aq_vector
+ */drivers/net/ethernet/intel/ice/ice_main.c +3
-0+static irqreturn_t ice_misc_intr_thread_fn (int __always_unused irq,void *data) +{ + struct ice_pf *pf = (struct ice_pf *)data;Cast shouldn't be needed.
Done
Quoted 15 lines
Quoted 15 lines
(quoted diff) +0
-0@@ -2171,16 +2170,17 @@ s8 ice_ptp_request_ts(struct ice_ptp_tx *tx, struct sk_buff *skb) }
/**
- *ice_ptp_process_ts- Spawn kthread work to handle timestamps
+ *ice_ptp_process_ts- Process the PTP Tx timestamps
* @pf: Board private structure
*
- * Queue work required to process the PTP Tx timestamps outside of interrupt
- * context.
+ * Returns true if timestamps are processed.
*/drivers/net/ethernet/intel/ice/ice_ptp.c +1
-1-void ice_ptp_process_ts (struct ice_pf *pf) +bool ice_ptp_process_ts (struct ice_pf *pf){
Quoted 8 lines
Quoted 5 lines
if (
pf->ptp.port.tx.init)
-kthread_queue_work(pf->ptp.kworker, &pf->ptp.port.tx.work); + returnice_ptp_tx_tstamp(&pf->ptp.port.tx);
+ else
+ return false;I believe preference is to remove the else and have an un-indented return false.
Done
Quoted 35 lines
Quoted 35 lines
(quoted diff) +0
-0@@ -2587,38 +2588,113 @@ static int ice_write_phy_reg_e810(struct ice_hw *hw, u32 addr, u32 val) }
/**
- *ice_read_phy_tstamp_e810- Read a PHY timestamp out of the external PHY
+ *ice_read_phy_tstamp_ll_e810- Read a PHY timestamp registers through the FW
+ * @hw: pointer to the HW struct
+ * @idx: the timestamp index to read
+ * @hi: 8 bit timestamp high value
+ * @lo: 32 bit timestamp low value
+ *
+ * Read a 8bit timestamp high value and 32 bit timestamp low value out of the
+ * timestamp block of the external PHY on the E810 device using the low latency
+ * timestamp read.
+ */drivers/net/ethernet/intel/ice/ice_ptp_hw.c +20
-0+static int +ice_read_phy_tstamp_ll_e810 (struct ice_hw *hw,u8 idx,u8 *hi,u32 *lo) +{ + u32 val; + u8 i; + + /* Write TS index to read to the PF register so the FW can read it */ + val = FIELD_PREP(TS_LL_READ_TS_IDX, idx) | TS_LL_READ_TS; + wr32(hw, PF_SB_ATQBAL, val); + + /* Read the register repeatedly until the FW provides us the TS */ + for (i = TS_LL_READ_RETRIES; i > 0; i--) { + val = rd32(hw, PF_SB_ATQBAL); + + /* When the bit is cleared, the TS is ready in the register */ + if (!(FIELD_GET(TS_LL_READ_TS, val))) { + /* High 8 bit value of the TS is on the bits 16:23 */ + *hi = FIELD_GET(TS_LL_READ_TS_HIGH, val); + + /* Read the low 32 bit value and set the TS valid bit */
Quoted 8 lines
Quoted 5 lines
+ *lo =
rd32(hw, PF_SB_ATQBAH)|TS_VALID; + return 0;
+ }
+
+ udelay(10);CHECK:
usleep_rangeis preferred over udelay; seeDocumentation/timers/timers-howto.rst
This udelay use is intentional as the delay value is small and this loop is time sensitive.
Kind regards,
Karol
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan