Skip to contentSkip to conversation

igb: Fix XDP with PTP enabled

PATCH Superseded Kurt Kanzenbach 2 participants 3 messages Apr 19, 2021 – Apr 21, 2021

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 igb: Fix XDP with PTP enabled

When using native XDP with the igb driver, the XDP frame data doesn't point to the beginning of the packet. It's off by 16 bytes. Everything works as expected with XDP skb mode.

Actually these 16 bytes are used to store the packet timestamps. Therefore, pull the timestamp before executing any XDP operations and adjust all other code accordingly. The igc driver does it like that as well.

Tested with Intel i210 card and AF_XDP sockets.

Fixes 9cbc948b5a20 ("igb: add XDP support")

---

Changes since v1:

* Use xdp_prepare_buff() (Lorenzo Bianconi)

Changes since RFC:

* Removed unused return value definitions (Alexander Duyck)

Previous versions:

* https://lkml.kernel.org/netdev/20210415092145.27322-1-kurt at linutronix.de/
* https://lkml.kernel.org/netdev/20210412101713.15161-1-kurt at linutronix.de/

 drivers/net/ethernet/intel/igb/igb.h      |  3 +-
 drivers/net/ethernet/intel/igb/igb_main.c | 42 +++++++++++++----------
 drivers/net/ethernet/intel/igb/igb_ptp.c  | 21 ++++--------
 3 files changed, 31 insertions(+), 35 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +1 -2
index 7bda8c5edea5..72cf967c1a00 100644
@@ -748,8 +748,7 @@ void igb_ptp_suspend(struct igb_adapter *adapter);
 void igb_ptp_rx_hang(struct igb_adapter *adapter);
 void igb_ptp_tx_hang(struct igb_adapter *adapter);
 void igb_ptp_rx_rgtstamp(struct igb_q_vector *q_vector, struct sk_buff *skb);
-int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
-			struct sk_buff *skb);
+ktime_t igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va);
 int igb_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
 int igb_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
 void igb_set_flag_queue_pairs(struct igb_adapter *, const u32);
drivers/net/ethernet/intel/igb/igb_main.c +23 -19

91 lines not on this page · raw message

drivers/net/ethernet/intel/igb/igb_ptp.c +7 -14
index 86a576201f5f..8e23df7da641 100644
@@ -856,30 +856,26 @@ static void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter)
 	dev_kfree_skb_any(skb);
 }
 
-#define IGB_RET_PTP_DISABLED 1
-#define IGB_RET_PTP_INVALID 2
-
 /**
  * igb_ptp_rx_pktstamp - retrieve Rx per packet timestamp
  * @q_vector: Pointer to interrupt specific structure
  * @va: Pointer to address containing Rx buffer
- * @skb: Buffer containing timestamp and packet
  *
  * This function is meant to retrieve a timestamp from the first buffer of an
  * incoming frame.  The value is stored in little endian format starting on
  * byte 8
  *
- * Returns: 0 if success, nonzero if failure
+ * Returns: 0 on failure, timestamp on success
  **/
-int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
-			struct sk_buff *skb)
+ktime_t igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va)
 {
 	struct igb_adapter *adapter = q_vector->adapter;
+	struct skb_shared_hwtstamps ts;
 	__le64 *regval = (__le64 *)va;
 	int adjust = 0;
 
 	if (!(adapter->ptp_flags & IGB_PTP_ENABLED))
-		return IGB_RET_PTP_DISABLED;
+		return 0;
 
 	/* The timestamp is recorded in little endian format.
 	 * DWORD: 0        1        2        3
@@ -888,10 +884,9 @@ int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
 
 	/* check reserved dwords are zero, be/le doesn't matter for zero */
 	if (regval[0])
-		return IGB_RET_PTP_INVALID;
+		return 0;
 
-	igb_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb),
-				   le64_to_cpu(regval[1]));
+	igb_ptp_systim_to_hwtstamp(adapter, &ts, le64_to_cpu(regval[1]));
 
 	/* adjust timestamp for the RX latency based on link speed */
 	if (adapter->hw.mac.type == e1000_i210) {
@@ -907,10 +902,8 @@ int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
 			break;
 		}
 	}
-	skb_hwtstamps(skb)->hwtstamp =
-		ktime_sub_ns(skb_hwtstamps(skb)->hwtstamp, adjust);
 
-	return 0;
+	return ktime_sub_ns(ts.hwtstamp, adjust);
 }
 
 /**
Signature · 1 line
2.20.1
#1 lore raw
Quoted 17 lines · Kurt Kanzenbach

When using native XDP with the igb driver, the XDP frame data doesn't point to
the beginning of the packet. It's off by 16 bytes. Everything works as expected
with XDP skb mode.

Actually these 16 bytes are used to store the packet timestamps. Therefore, pull
the timestamp before executing any XDP operations and adjust all other code
accordingly. The igc driver does it like that as well.

Tested with Intel i210 card and AF_XDP sockets.

Fixes 9cbc948b5a20 ("igb: add XDP support")

---

<snip>

Quoted 18 lines
drivers/net/ethernet/intel/igb/igb_main.c +3 -0
@@ -8683,7 +8676,10 @@ static int igb_clean_rx_irq(struct
 igb_q_vector *q_vector, const int budget)
 	while (likely(total_packets < budget)) {
 		union e1000_adv_rx_desc *rx_desc;
 		struct igb_rx_buffer *rx_buffer;
+		ktime_t timestamp = 0;
+		int pkt_offset = 0;
 		unsigned int size;
+		void *pktbuf;
 
 		/* return some buffers to hardware, one at a time is

too slow */

drivers/net/ethernet/intel/igb/igb_main.c +0 -0
 		if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
@@ -8703,14 +8699,21 @@ static int igb_clean_rx_irq(struct
 igb_q_vector *q_vector, const int budget)
 		dma_rmb();
 
 		rx_buffer = igb_get_rx_buffer(rx_ring, size,

drivers/net/ethernet/intel/igb/igb_main.c static int igb_clean_rx_irq(struct · line 8712

Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_main.c +6 -0
 &rx_buf_pgcnt);
+		pktbuf = page_address(rx_buffer->page) + rx_buffer-
 >page_offset;
+
+		/* pull rx packet timestamp if available */
+		if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))
 {
+			timestamp = igb_ptp_rx_pktstamp(rx_ring-
 >q_vector,
+							pktbuf);

The timestamp should be checked for failure and not adjust these values if the timestamp was invalid.

Quoted 3 lines
drivers/net/ethernet/intel/igb/igb_main.c +3 -0
+			pkt_offset += IGB_TS_HDR_LEN;
+			size -= IGB_TS_HDR_LEN;
+		}
#2 lore raw
Quoted 9 lines

drivers/net/ethernet/intel/igb/igb_main.c static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget) · line 8707

Quoted 6 lines
(quoted diff) +2 -0
+		/* pull rx packet timestamp if available */
+		if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))

{

(quoted diff) +1 -0
+			timestamp = igb_ptp_rx_pktstamp(rx_ring-
Quoted 1 line

q_vector,

drivers/net/ethernet/intel/igb/igb_main.c +1 -0
+							pktbuf);

The timestamp should be checked for failure and not adjust these values if the timestamp was invalid.

OK. I'll adjust it.

Thanks,
Kurt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20210421/b45d280f/attachment.asc>