Skip to contentSkip to conversation

igc: Add XDP support

PATCH Superseded Andre Guedes 4 participants 24 messages Oct 30, 2020 – Nov 6, 2020

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover igc: Add XDP support

Hi all,

This is the third version of this series which adds XDP support to igc driver.

The main changes from v2 are:

- Moved functions that belong to the driver's hot path to igc_main.c to allow the compiler to inline them if convenient.
- Squashed ndo_xdp_xmit patch into XDP_REDIRECT patch.

v2 is here:

    https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20201028201943.93147-1-andre.guedes at intel.com/

v1 is here:

    https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20201009025349.4037-1-andre.guedes at intel.com/

Cheers,
Andre

Andre Guedes (9):
igc: Fix igc_ptp_rx_pktstamp()
igc: Remove unused argument from igc_tx_cmd_type()
igc: Introduce igc_rx_buffer_flip() helper
igc: Introduce igc_get_rx_frame_truesize() helper
igc: Refactor rx timestamp handling
igc: Add set/clear large buffer helpers
igc: Add initial XDP support
igc: Add support for XDP_TX action
igc: Add support for XDP_REDIRECT action

 drivers/net/ethernet/intel/igc/Makefile   |   2 +-
 drivers/net/ethernet/intel/igc/igc.h      |  18 +-
 drivers/net/ethernet/intel/igc/igc_main.c | 431 +++++++++++++++++++---
 drivers/net/ethernet/intel/igc/igc_ptp.c  |  89 +++--
 drivers/net/ethernet/intel/igc/igc_xdp.c  |  60 +++
 drivers/net/ethernet/intel/igc/igc_xdp.h  |  13 +
 6 files changed, 512 insertions(+), 101 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/igc/igc_xdp.c
 create mode 100644 drivers/net/ethernet/intel/igc/igc_xdp.h
Signature · 1 line
2.28.0
#1 lore raw

PATCH v3 1/9 igc: Fix igc_ptp_rx_pktstamp()

The comment describing the timestamps layout in the packet buffer is wrong and the code is actually retrieving the timestamp in Timer 1 reference instead of Timer 0. This hasn't been a big issue so far because hardware is configured to report both timestamps using Timer 0 (see IGC_SRRCTL register configuration in igc_ptp_enable_rx_timestamp() helper). This patch fixes the comment and the code so we retrieve the timestamp in Timer 0 reference as expected.

This patch also takes the opportunity to get rid of the hw.mac.type check since it is not required.

Fixes 81b055205e8ba ("igc: Add support for RX timestamping")
---
 drivers/net/ethernet/intel/igc/igc.h     |  2 +-
 drivers/net/ethernet/intel/igc/igc_ptp.c | 72 +++++++++++++-----------
 2 files changed, 41 insertions(+), 33 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +1 -1
index 83d59b08e883..b66dda992d32 100644
@@ -552,7 +552,7 @@ 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_pktstamp(struct igc_q_vector *q_vector, void *va,
+void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, u32 *va,
 			 struct sk_buff *skb);
 int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
 int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
drivers/net/ethernet/intel/igc/igc_ptp.c +40 -32

86 lines not on this page · raw message

Signature · 1 line
2.28.0
#6 lore raw

PATCH v3 2/9 igc: Remove unused argument from igc_tx_cmd_type()

In reply to Andre Guedes

The 'skb' argument from igc_tx_cmd_type() is not used so this patch removes it.

---
 drivers/net/ethernet/intel/igc/igc_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +2 -2
index 240565aee2a3..5ce9253cca19 100644
@@ -1042,7 +1042,7 @@ static inline int igc_maybe_stop_tx(struct igc_ring *tx_ring, const u16 size)
 	 ((u32)((_input) & (_flag)) * ((_result) / (_flag))) :	\
 	 ((u32)((_input) & (_flag)) / ((_flag) / (_result))))
 
-static u32 igc_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
+static u32 igc_tx_cmd_type(u32 tx_flags)
 {
 	/* set type for advanced descriptor with frame checksum insertion */
 	u32 cmd_type = IGC_ADVTXD_DTYP_DATA |
@@ -1091,7 +1091,7 @@ static int igc_tx_map(struct igc_ring *tx_ring,
 	u16 i = tx_ring->next_to_use;
 	unsigned int data_len, size;
 	dma_addr_t dma;
-	u32 cmd_type = igc_tx_cmd_type(skb, tx_flags);
+	u32 cmd_type = igc_tx_cmd_type(tx_flags);
 
 	tx_desc = IGC_TX_DESC(tx_ring, i);
 
Signature · 1 line
2.28.0
#7 lore raw

PATCH v3 3/9 igc: Introduce igc_rx_buffer_flip() helper

In reply to Andre Guedes

The igc driver implements the same page recycling scheme from other Intel drivers which reuses the page by flipping the buffer. The code to handle buffer flips is duplicated in many locations so this patch introduces the igc_rx_buffer_flip() helper and uses it where applicable.

---
 drivers/net/ethernet/intel/igc/igc_main.c | 42 +++++++++++------------
 1 file changed, 20 insertions(+), 22 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +20 -22
index 5ce9253cca19..31dc58a82cf3 100644
@@ -1513,6 +1513,16 @@ static struct igc_rx_buffer *igc_get_rx_buffer(struct igc_ring *rx_ring,
 	return rx_buffer;
 }
 
+static void igc_rx_buffer_flip(struct igc_rx_buffer *buffer,
+			       unsigned int truesize)
+{
+#if (PAGE_SIZE < 8192)
+	buffer->page_offset ^= truesize;
+#else
+	buffer->page_offset += truesize;
+#endif
+}
+
 /**
  * igc_add_rx_frag - Add contents of Rx buffer to sk_buff
  * @rx_ring: rx descriptor ring to transact packets on
@@ -1527,20 +1537,18 @@ static void igc_add_rx_frag(struct igc_ring *rx_ring,
 			    struct sk_buff *skb,
 			    unsigned int size)
 {
+	unsigned int truesize;
 #if (PAGE_SIZE < 8192)
-	unsigned int truesize = igc_rx_pg_size(rx_ring) / 2;
-
-	skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
-			rx_buffer->page_offset, size, truesize);
-	rx_buffer->page_offset ^= truesize;
+	truesize = igc_rx_pg_size(rx_ring) / 2;
 #else
-	unsigned int truesize = ring_uses_build_skb(rx_ring) ?
-				SKB_DATA_ALIGN(IGC_SKB_PAD + size) :
-				SKB_DATA_ALIGN(size);
+	truesize = ring_uses_build_skb(rx_ring) ?
+		   SKB_DATA_ALIGN(IGC_SKB_PAD + size) :
+		   SKB_DATA_ALIGN(size);
+#endif
 	skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
 			rx_buffer->page_offset, size, truesize);
-	rx_buffer->page_offset += truesize;
-#endif
+
+	igc_rx_buffer_flip(rx_buffer, truesize);
 }
 
 static struct sk_buff *igc_build_skb(struct igc_ring *rx_ring,
@@ -1569,13 +1577,7 @@ static struct sk_buff *igc_build_skb(struct igc_ring *rx_ring,
 	skb_reserve(skb, IGC_SKB_PAD);
 	__skb_put(skb, size);
 
-	/* update buffer offset */
-#if (PAGE_SIZE < 8192)
-	rx_buffer->page_offset ^= truesize;
-#else
-	rx_buffer->page_offset += truesize;
-#endif
-
+	igc_rx_buffer_flip(rx_buffer, truesize);
 	return skb;
 }
 
@@ -1621,11 +1623,7 @@ static struct sk_buff *igc_construct_skb(struct igc_ring *rx_ring,
 		skb_add_rx_frag(skb, 0, rx_buffer->page,
 				(va + headlen) - page_address(rx_buffer->page),
 				size, truesize);
-#if (PAGE_SIZE < 8192)
-		rx_buffer->page_offset ^= truesize;
-#else
-		rx_buffer->page_offset += truesize;
-#endif
+		igc_rx_buffer_flip(rx_buffer, truesize);
 	} else {
 		rx_buffer->pagecnt_bias++;
 	}
Signature · 1 line
2.28.0
#8 lore raw

PATCH v3 4/9 igc: Introduce igc_get_rx_frame_truesize() helper

In reply to Andre Guedes

The RX frame truesize calculation is scattered throughout the RX code. This patch creates the helper function igc_get_rx_frame_truesize() and uses it where applicable.

---
 drivers/net/ethernet/intel/igc/igc_main.c | 29 ++++++++++++++---------
 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +18 -11
index 31dc58a82cf3..15c67e5763d3 100644
@@ -1523,6 +1523,22 @@ static void igc_rx_buffer_flip(struct igc_rx_buffer *buffer,
 #endif
 }
 
+static unsigned int igc_get_rx_frame_truesize(struct igc_ring *ring,
+					      unsigned int size)
+{
+	unsigned int truesize;
+
+#if (PAGE_SIZE < 8192)
+	truesize = igc_rx_pg_size(ring) / 2;
+#else
+	truesize = ring_uses_build_skb(ring) ?
+		   SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
+		   SKB_DATA_ALIGN(IGC_SKB_PAD + size) :
+		   SKB_DATA_ALIGN(size);
+#endif
+	return truesize;
+}
+
 /**
  * igc_add_rx_frag - Add contents of Rx buffer to sk_buff
  * @rx_ring: rx descriptor ring to transact packets on
@@ -1557,12 +1573,7 @@ static struct sk_buff *igc_build_skb(struct igc_ring *rx_ring,
 				     unsigned int size)
 {
 	void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
-#if (PAGE_SIZE < 8192)
-	unsigned int truesize = igc_rx_pg_size(rx_ring) / 2;
-#else
-	unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
-				SKB_DATA_ALIGN(IGC_SKB_PAD + size);
-#endif
+	unsigned int truesize = igc_get_rx_frame_truesize(rx_ring, size);
 	struct sk_buff *skb;
 
 	/* prefetch first cache line of first page */
@@ -1587,11 +1598,7 @@ static struct sk_buff *igc_construct_skb(struct igc_ring *rx_ring,
 					 unsigned int size)
 {
 	void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
-#if (PAGE_SIZE < 8192)
-	unsigned int truesize = igc_rx_pg_size(rx_ring) / 2;
-#else
-	unsigned int truesize = SKB_DATA_ALIGN(size);
-#endif
+	unsigned int truesize = igc_get_rx_frame_truesize(rx_ring, size);
 	unsigned int headlen;
 	struct sk_buff *skb;
 
Signature · 1 line
2.28.0
#9 lore raw

PATCH v3 5/9 igc: Refactor rx timestamp handling

In reply to Andre Guedes

This patch refactors the rx timestamp handling in preparation to land XDP support.

RX timestamps are put in the rx buffer by hardware, before the packet data. When creating the xdp buffer, we will need to check the rx descriptor to determine if the buffer contains timestamp information and consider the offset when setting xdp.data.

The rx descriptor check is already done in igc_construct_skb(). To avoid code duplication, this patch moves the timestamp handling to igc_clean_rx_irq() so both skb and xdp paths can reuse it.

---
 drivers/net/ethernet/intel/igc/igc.h      |  3 +--
 drivers/net/ethernet/intel/igc/igc_main.c | 30 +++++++++++++++--------
 drivers/net/ethernet/intel/igc/igc_ptp.c  | 25 ++++++++++---------
 3 files changed, 34 insertions(+), 24 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +1 -2
index b66dda992d32..ae91d51073ca 100644
@@ -552,8 +552,7 @@ 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_pktstamp(struct igc_q_vector *q_vector, u32 *va,
-			 struct sk_buff *skb);
+ktime_t igc_ptp_rx_pktstamp(struct igc_adapter *adapter, u32 *buf);
 int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
 int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
 void igc_ptp_tx_hang(struct igc_adapter *adapter);
drivers/net/ethernet/intel/igc/igc_main.c +20 -10
index 15c67e5763d3..84ffde75e968 100644
@@ -1594,10 +1594,11 @@ static struct sk_buff *igc_build_skb(struct igc_ring *rx_ring,
 
 static struct sk_buff *igc_construct_skb(struct igc_ring *rx_ring,
 					 struct igc_rx_buffer *rx_buffer,
-					 union igc_adv_rx_desc *rx_desc,
-					 unsigned int size)
+					 unsigned int size, int pkt_offset,
+					 ktime_t timestamp)
 {
-	void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
+	void *va = page_address(rx_buffer->page) + rx_buffer->page_offset +
+		   pkt_offset;
 	unsigned int truesize = igc_get_rx_frame_truesize(rx_ring, size);
 	unsigned int headlen;
 	struct sk_buff *skb;
@@ -1610,11 +1611,8 @@ static struct sk_buff *igc_construct_skb(struct igc_ring *rx_ring,
 	if (unlikely(!skb))
 		return NULL;
 
-	if (unlikely(igc_test_staterr(rx_desc, IGC_RXDADV_STAT_TSIP))) {
-		igc_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
-		va += IGC_TS_HDR_LEN;
-		size -= IGC_TS_HDR_LEN;
-	}
+	if (timestamp)
+		skb_hwtstamps(skb)->hwtstamp = timestamp;
 
 	/* Determine available headroom for copy */
 	headlen = size;
@@ -1913,6 +1911,8 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
 	while (likely(total_packets < budget)) {
 		union igc_adv_rx_desc *rx_desc;
 		struct igc_rx_buffer *rx_buffer;
+		ktime_t timestamp = 0;
+		int pkt_offset = 0;
 		unsigned int size;
 
 		/* return some buffers to hardware, one@a time is too slow */
@@ -1934,14 +1934,24 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
 
 		rx_buffer = igc_get_rx_buffer(rx_ring, size);
 
+		if (igc_test_staterr(rx_desc, IGC_RXDADV_STAT_TSIP)) {
+			void *pktbuf = page_address(rx_buffer->page) +
+				       rx_buffer->page_offset;
+
+			timestamp = igc_ptp_rx_pktstamp(q_vector->adapter,
+							pktbuf);
+			pkt_offset = IGC_TS_HDR_LEN;
+			size -= IGC_TS_HDR_LEN;
+		}
+
 		/* retrieve a buffer from the ring */
 		if (skb)
 			igc_add_rx_frag(rx_ring, rx_buffer, skb, size);
 		else if (ring_uses_build_skb(rx_ring))
 			skb = igc_build_skb(rx_ring, rx_buffer, rx_desc, size);
 		else
-			skb = igc_construct_skb(rx_ring, rx_buffer,
-						rx_desc, size);
+			skb = igc_construct_skb(rx_ring, rx_buffer, size,
+						pkt_offset, timestamp);
 
 		/* exit if we failed to retrieve a buffer */
 		if (!skb) {
drivers/net/ethernet/intel/igc/igc_ptp.c +13 -12
index 79873f6df335..4331c2dcffb2 100644
@@ -155,20 +155,20 @@ static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
 
 /**
  * igc_ptp_rx_pktstamp - Retrieve timestamp from rx packet buffer
- * @q_vector: Pointer to interrupt specific structure
- * @va: Pointer to address containing Rx buffer
- * @skb: Buffer containing timestamp and packet
+ * @adapter: Pointer to adapter the packet buffer belongs to
+ * @buf: Pointer to packet buffer
  *
  * This function retrieves the timestamp saved in the beginning of packet
  * buffer. While two timestamps are available, one in timer0 reference and the
  * other in timer1 reference, this function considers only the timestamp in
  * timer0 reference.
+ *
+ * Returns: Timestamp value.
  */
-void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, u32 *va,
-			 struct sk_buff *skb)
+ktime_t igc_ptp_rx_pktstamp(struct igc_adapter *adapter, u32 *buf)
 {
-	struct igc_adapter *adapter = q_vector->adapter;
-	u64 regval;
+	ktime_t timestamp;
+	u32 secs, nsecs;
 	int adjust;
 
 	/* Timestamps are saved in little endian at the beginning of the packet
@@ -180,9 +180,10 @@ void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, u32 *va,
 	 * SYSTIML holds the nanoseconds part while SYSTIMH holds the seconds
 	 * part of the timestamp.
 	 */
-	regval = le32_to_cpu(va[2]);
-	regval |= (u64)le32_to_cpu(va[3]) << 32;
-	igc_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval);
+	nsecs = le32_to_cpu(buf[2]);
+	secs = le32_to_cpu(buf[3]);
+
+	timestamp = ktime_set(secs, nsecs);
 
 	/* Adjust timestamp for the RX latency based on link speed */
 	switch (adapter->link_speed) {
@@ -203,8 +204,8 @@ void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, u32 *va,
 		netdev_warn_once(adapter->netdev, "Imprecise timestamp\n");
 		break;
 	}
-	skb_hwtstamps(skb)->hwtstamp =
-		ktime_sub_ns(skb_hwtstamps(skb)->hwtstamp, adjust);
+
+	return ktime_sub_ns(timestamp, adjust);
 }
 
 static void igc_ptp_disable_rx_timestamp(struct igc_adapter *adapter)
Signature · 1 line
2.28.0
#10 lore raw

PATCH v3 6/9 igc: Add set/clear large buffer helpers

In reply to Andre Guedes

While commit 13b5b7fd6a4a ("igc: Add support for Tx/Rx rings") introduced code to handle larger packet buffers, it missed the set/clear helpers which enable/disable that feature. This patch introduces the missing helpers which will be use in the next patch.

---
 drivers/net/ethernet/intel/igc/igc.h | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/intel/igc/igc.h +4 -0
index ae91d51073ca..e72f1fc772aa 100644
@@ -509,6 +509,10 @@ enum igc_ring_flags_t {
 
 #define ring_uses_large_buffer(ring) \
 	test_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags)
+#define set_ring_uses_large_buffer(ring) \
+	set_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags)
+#define clear_ring_uses_large_buffer(ring) \
+	clear_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags)
 
 #define ring_uses_build_skb(ring) \
 	test_bit(IGC_RING_FLAG_RX_BUILD_SKB_ENABLED, &(ring)->flags)
Signature · 1 line
2.28.0
#11 lore raw

PATCH v3 7/9 igc: Add initial XDP support

In reply to Andre Guedes

This patch adds the initial XDP support to the igc driver. For now, only XDP_PASS, XDP_DROP, XDP_ABORTED actions are supported. Upcoming patches will add support for the remaining XDP actions.

XDP configuration helpers are defined in a new file, igc_xdp.c. These helpers are utilized in igc_main.c to implement the ndo_bpf callback. XDP-related code that belongs to the driver's hot path is landed in igc_main.c.

By default, the driver uses rx buffers with 2 KB size. When XDP is enabled, it uses larger buffers so we have enough space to accommodate the headroom and tailroom required by XDP infrastructure. Also, the driver doesn't support XDP functionality with frames that span over multiple buffers so jumbo frames are not allowed for now.

The approach implemented by this patch follows the approach implemented in other Intel drivers as much as possible for the sake of consistency across the drivers.

Quick comment regarding igc_build_skb(): this patch doesn't touch it because the function is never called. It seems its support is incomplete/in progress. The function was added by commit 0507ef8a0372b ("igc: Add transmit and receive fastpath and interrupt handlers") but ring_uses_build_skb() always return False since the IGC_RING_FLAG_RX_ BUILD_SKB_ENABLED isn't set anywhere in the driver code.

This patch has been tested with the sample app "xdp1" located in samples/bpf/ dir.

---
 drivers/net/ethernet/intel/igc/Makefile   |   2 +-
 drivers/net/ethernet/intel/igc/igc.h      |   2 +
 drivers/net/ethernet/intel/igc/igc_main.c | 118 ++++++++++++++++++++--
 drivers/net/ethernet/intel/igc/igc_xdp.c  |  33 ++++++
 drivers/net/ethernet/intel/igc/igc_xdp.h  |  10 ++
 5 files changed, 153 insertions(+), 12 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/igc/igc_xdp.c
 create mode 100644 drivers/net/ethernet/intel/igc/igc_xdp.h
drivers/net/ethernet/intel/igc/Makefile +1 -1
index 1c3051db9085..95d1e8c490a4 100644
@@ -8,4 +8,4 @@
 obj-$(CONFIG_IGC) += igc.o
 
 igc-objs := igc_main.o igc_mac.o igc_i225.o igc_base.o igc_nvm.o igc_phy.o \
-igc_diag.o igc_ethtool.o igc_ptp.o igc_dump.o igc_tsn.o
+igc_diag.o igc_ethtool.o igc_ptp.o igc_dump.o igc_tsn.o igc_xdp.o
drivers/net/ethernet/intel/igc/igc.h +2 -0
index e72f1fc772aa..5c2f363106ae 100644
@@ -224,6 +224,8 @@ struct igc_adapter {
 	struct mutex ptm_time_lock; /* protects host and device timestamps */
 	ktime_t ptm_device_time;
 	struct system_counterval_t ptm_host_time;
+
+	struct bpf_prog *xdp_prog;
 };
 
 void igc_up(struct igc_adapter *adapter);
drivers/net/ethernet/intel/igc/igc_main.c +107 -11

223 lines not on this page · raw message

drivers/net/ethernet/intel/igc/igc_xdp.c new file +33 -0
new file mode 100644
index 000000000000..27c886a254f1
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2020, Intel Corporation. */
+
+#include "igc.h"
+#include "igc_xdp.h"
+
+int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
+		     struct netlink_ext_ack *extack)
+{
+	struct net_device *dev = adapter->netdev;
+	bool if_running = netif_running(dev);
+	struct bpf_prog *old_prog;
+
+	if (dev->mtu > ETH_DATA_LEN) {
+		/* For now, the driver doesn't support XDP functionality with
+		 * jumbo frames so we return error.
+		 */
+		NL_SET_ERR_MSG_MOD(extack, "Jumbo frames not supported");
+		return -EOPNOTSUPP;
+	}
+
+	if (if_running)
+		igc_close(dev);
+
+	old_prog = xchg(&adapter->xdp_prog, prog);
+	if (old_prog)
+		bpf_prog_put(old_prog);
+
+	if (if_running)
+		igc_open(dev);
+
+	return 0;
+}
drivers/net/ethernet/intel/igc/igc_xdp.h new file +10 -0
new file mode 100644
index 000000000000..8a410bcefe1a
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2020, Intel Corporation. */
+
+#ifndef _IGC_XDP_H_
+#define _IGC_XDP_H_
+
+int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
+		     struct netlink_ext_ack *extack);
+
+#endif /* _IGC_XDP_H_ */
Signature · 1 line
2.28.0
#15 lore raw

PATCH v3 8/9 igc: Add support for XDP_TX action

In reply to Andre Guedes

This patch adds support for XDP_TX action which enables XDP programs to transmit back receiving frames.

I225 controller has only 4 tx hardware queues. Since XDP programs may not even issue an XDP_TX action, this patch doesn't reserve dedicated queues just for XDP like other Intel drivers do. Instead, the queues are shared between the network stack and XDP. The netdev queue lock is used to ensure mutual exclusion.

Since frames can now be transmitted via XDP_TX, the igc_tx_buffer structure is modified so we are able to save a reference to the xdp frame for later clean up once the packet is transmitted. The tx_buffer is mapped to either a skb or a xdpf so we use a union to save the skb or xdpf pointer and have a bit in tx_flags to indicate which field to use.

This patch has been tested with the sample app "xdp2" located in samples/bpf/ dir.

---
 drivers/net/ethernet/intel/igc/igc.h      |   9 +-
 drivers/net/ethernet/intel/igc/igc_main.c | 173 ++++++++++++++++++++--
 drivers/net/ethernet/intel/igc/igc_xdp.c  |  27 ++++
 drivers/net/ethernet/intel/igc/igc_xdp.h  |   3 +
 4 files changed, 201 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +8 -1
index 5c2f363106ae..9c566d930ab0 100644
@@ -112,6 +112,8 @@ struct igc_ring {
 			struct sk_buff *skb;
 		};
 	};
+
+	struct xdp_rxq_info xdp_rxq;
 } ____cacheline_internodealigned_in_smp;
 
 /* Board specific private data structure */
@@ -380,6 +382,8 @@ enum igc_tx_flags {
 	/* olinfo flags */
 	IGC_TX_FLAGS_IPV4	= 0x10,
 	IGC_TX_FLAGS_CSUM	= 0x20,
+
+	IGC_TX_FLAGS_XDP	= 0x100,
 };
 
 enum igc_boards {
@@ -402,7 +406,10 @@ enum igc_boards {
 struct igc_tx_buffer {
 	union igc_adv_tx_desc *next_to_watch;
 	unsigned long time_stamp;
-	struct sk_buff *skb;
+	union {
+		struct sk_buff *skb;
+		struct xdp_frame *xdpf;
+	};
 	unsigned int bytecount;
 	u16 gso_segs;
 	__be16 protocol;
drivers/net/ethernet/intel/igc/igc_main.c +163 -10

267 lines not on this page · raw message

drivers/net/ethernet/intel/igc/igc_xdp.c +27 -0
index 27c886a254f1..aa65c99c8c4d 100644
@@ -31,3 +31,30 @@ int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
 
 	return 0;
 }
+
+int igc_xdp_register_rxq_info(struct igc_ring *ring)
+{
+	struct net_device *dev = ring->netdev;
+	int err;
+
+	err = xdp_rxq_info_reg(&ring->xdp_rxq, dev, ring->queue_index);
+	if (err) {
+		netdev_err(dev, "Failed to register xdp rxq info\n");
+		return err;
+	}
+
+	err = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq, MEM_TYPE_PAGE_SHARED,
+					 NULL);
+	if (err) {
+		netdev_err(dev, "Failed to register xdp rxq mem model\n");
+		xdp_rxq_info_unreg(&ring->xdp_rxq);
+		return err;
+	}
+
+	return 0;
+}
+
+void igc_xdp_unregister_rxq_info(struct igc_ring *ring)
+{
+	xdp_rxq_info_unreg(&ring->xdp_rxq);
+}
drivers/net/ethernet/intel/igc/igc_xdp.h +3 -0
index 8a410bcefe1a..cfecb515b718 100644
@@ -7,4 +7,7 @@
 int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
 		     struct netlink_ext_ack *extack);
 
+int igc_xdp_register_rxq_info(struct igc_ring *ring);
+void igc_xdp_unregister_rxq_info(struct igc_ring *ring);
+
 #endif /* _IGC_XDP_H_ */
Signature · 1 line
2.28.0
#19 lore raw

PATCH v3 9/9 igc: Add support for XDP_REDIRECT action

In reply to Andre Guedes

This patch adds support for the XDP_REDIRECT action which enables XDP programs to redirect packets arriving at I225 NIC. It also implements the ndo_xdp_xmit ops, enabling the igc driver to transmit packets forwarded to it by xdp programs running on other interfaces.

The patch tweaks the driver's page counting scheme (as described in '8ce29c679a6e i40e: tweak page counting for XDP_REDIRECT' and implemented by other Intel drivers) in order to properly support XDP_REDIRECT action.

This patch has been tested with the sample apps "xdp_redirect_cpu" and "xdp_redirect_map" located in samples/bpf/.

---
 drivers/net/ethernet/intel/igc/igc_main.c | 59 +++++++++++++++++++++--
 1 file changed, 56 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +56 -3
index ae933982e239..33dab5976cbc 100644
@@ -27,6 +27,7 @@
 #define IGC_XDP_PASS		0
 #define IGC_XDP_CONSUMED	BIT(0)
 #define IGC_XDP_TX		BIT(1)
+#define IGC_XDP_REDIRECT	BIT(2)
 
 static int debug = -1;
 
@@ -1720,8 +1721,8 @@ static bool igc_can_reuse_rx_page(struct igc_rx_buffer *rx_buffer)
 	 * the pagecnt_bias and page count so that we fully restock the
 	 * number of references the driver holds.
 	 */
-	if (unlikely(!pagecnt_bias)) {
-		page_ref_add(page, USHRT_MAX);
+	if (unlikely(pagecnt_bias == 1)) {
+		page_ref_add(page, USHRT_MAX - 1);
 		rx_buffer->pagecnt_bias = USHRT_MAX;
 	}
 
@@ -1862,7 +1863,8 @@ static bool igc_alloc_mapped_page(struct igc_ring *rx_ring,
 	bi->dma = dma;
 	bi->page = page;
 	bi->page_offset = igc_rx_offset(rx_ring);
-	bi->pagecnt_bias = 1;
+	page_ref_add(page, USHRT_MAX - 1);
+	bi->pagecnt_bias = USHRT_MAX;
 
 	return true;
 }
@@ -2055,6 +2057,12 @@ static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter,
 		else
 			res = IGC_XDP_TX;
 		break;
+	case XDP_REDIRECT:
+		if (xdp_do_redirect(adapter->netdev, xdp, prog) < 0)
+			res = IGC_XDP_CONSUMED;
+		else
+			res = IGC_XDP_REDIRECT;
+		break;
 	default:
 		bpf_warn_invalid_xdp_action(act);
 		fallthrough;
@@ -2096,6 +2104,9 @@ static void igc_finalize_xdp(struct igc_adapter *adapter, int status)
 		igc_flush_tx_descriptors(ring);
 		__netif_tx_unlock(nq);
 	}
+
+	if (status & IGC_XDP_REDIRECT)
+		xdp_do_flush();
 }
 
 static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
@@ -2164,6 +2175,7 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
 				rx_buffer->pagecnt_bias++;
 				break;
 			case IGC_XDP_TX:
+			case IGC_XDP_REDIRECT:
 				igc_rx_buffer_flip(rx_buffer, truesize);
 				xdp_status |= xdp_res;
 				break;
@@ -5129,6 +5141,46 @@ static int igc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
 	}
 }
 
+static int igc_xdp_xmit(struct net_device *dev, int num_frames,
+			struct xdp_frame **frames, u32 flags)
+{
+	struct igc_adapter *adapter = netdev_priv(dev);
+	int cpu = smp_processor_id();
+	struct netdev_queue *nq;
+	struct igc_ring *ring;
+	int i, drops;
+
+	if (unlikely(test_bit(__IGC_DOWN, &adapter->state)))
+		return -ENETDOWN;
+
+	if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
+		return -EINVAL;
+
+	ring = igc_xdp_get_tx_ring(adapter, cpu);
+	nq = txring_txq(ring);
+
+	__netif_tx_lock(nq, cpu);
+
+	drops = 0;
+	for (i = 0; i < num_frames; i++) {
+		int err;
+		struct xdp_frame *xdpf = frames[i];
+
+		err = igc_xdp_init_tx_descriptor(ring, xdpf);
+		if (err) {
+			xdp_return_frame_rx_napi(xdpf);
+			drops++;
+		}
+	}
+
+	if (flags & XDP_XMIT_FLUSH)
+		igc_flush_tx_descriptors(ring);
+
+	__netif_tx_unlock(nq);
+
+	return num_frames - drops;
+}
+
 static const struct net_device_ops igc_netdev_ops = {
 	.ndo_open		= igc_open,
 	.ndo_stop		= igc_close,
@@ -5143,6 +5195,7 @@ static const struct net_device_ops igc_netdev_ops = {
 	.ndo_do_ioctl		= igc_ioctl,
 	.ndo_setup_tc		= igc_setup_tc,
 	.ndo_bpf		= igc_bpf,
+	.ndo_xdp_xmit		= igc_xdp_xmit,
 };
 
 /* PCIe configuration access */
Signature · 1 line
2.28.0
#2 lore raw

PATCH v3 1/9 igc: Fix igc_ptp_rx_pktstamp()

In reply to Andre Guedes
Quoted 63 lines · Andre Guedes

The comment describing the timestamps layout in the packet buffer is wrong and the code is actually retrieving the timestamp in Timer 1 reference instead of Timer 0. This hasn't been a big issue so far because hardware is configured to report both timestamps using Timer 0 (see IGC_SRRCTL register configuration in igc_ptp_enable_rx_timestamp() helper). This patch fixes the comment and the code so we retrieve the timestamp in Timer 0 reference as expected.

This patch also takes the opportunity to get rid of the hw.mac.type check since it is not required.

Fixes 81b055205e8ba ("igc: Add support for RX timestamping")
---
 drivers/net/ethernet/intel/igc/igc.h     |  2 +-
 drivers/net/ethernet/intel/igc/igc_ptp.c | 72 +++++++++++++-----------
 2 files changed, 41 insertions(+), 33 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +1 -1
index 83d59b08e883..b66dda992d32 100644
@@ -552,7 +552,7 @@ 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_pktstamp(struct igc_q_vector *q_vector, void *va,
+void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, u32 *va,
 			 struct sk_buff *skb);
 int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
 int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
drivers/net/ethernet/intel/igc/igc_ptp.c +7 -10
index d73c4aaac610..79873f6df335 100644
@@ -154,46 +154,54 @@ static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
 }
 
 /**
- * igc_ptp_rx_pktstamp - retrieve Rx per packet timestamp
+ * igc_ptp_rx_pktstamp - Retrieve timestamp from rx packet buffer
  * @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 the first timestamp from the
- * first buffer of an incoming frame. The value is stored in little
- * endian format starting on byte 0. There's a second timestamp
- * starting on byte 8.
- **/
-void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, void *va,
+ * This function retrieves the timestamp saved in the beginning of packet
+ * buffer. While two timestamps are available, one in timer0 reference and the
+ * other in timer1 reference, this function considers only the timestamp in
+ * timer0 reference.
+ */
+void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, u32 *va,
 			 struct sk_buff *skb)
 {
 	struct igc_adapter *adapter = q_vector->adapter;
-	__le64 *regval = (__le64 *)va;
-	int adjust = 0;
-

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 177

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +7 -3
-	/* The timestamp is recorded in little endian format.
-	 * DWORD: | 0          | 1           | 2          | 3
-	 * Field: | Timer0 Low | Timer0 High | Timer1 Low | Timer1 High
+	u64 regval;
+	int adjust;
+
+	/* Timestamps are saved in little endian at the beginning of the packet
+	 * buffer following the layout:
+	 *
+	 * | 0              | 1              | 2              | 3              |

Minor nit, I find DWORD comment helpful from previous version of this description.

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 178

Quoted 1 line
drivers/net/ethernet/intel/igc/igc_ptp.c +1 -0
+	 * | Timer1 SYSTIML | Timer1 SYSTIMH | Timer0 SYSTIML | Timer0 SYSTIMH |

A dumb question from ptp/igc noob: why two timers?

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 182

Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -5
+	 *
+	 * SYSTIML holds the nanoseconds part while SYSTIMH holds the seconds
+	 * part of the timestamp.
 	 */
-	igc_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb),
-				   le64_to_cpu(regval[0]));
-
-	/* adjust timestamp for the RX latency based on link speed */
-	if (adapter->hw.mac.type == igc_i225) {

if this check is not required here, then is it within igc_ptp_systim_to_hwtstamp?

Quoted 25 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +11 -14
-		switch (adapter->link_speed) {
-		case SPEED_10:
-			adjust = IGC_I225_RX_LATENCY_10;
-			break;
-		case SPEED_100:
-			adjust = IGC_I225_RX_LATENCY_100;
-			break;
-		case SPEED_1000:
-			adjust = IGC_I225_RX_LATENCY_1000;
-			break;
-		case SPEED_2500:
-			adjust = IGC_I225_RX_LATENCY_2500;
-			break;
-		}
+	regval = le32_to_cpu(va[2]);
+	regval |= (u64)le32_to_cpu(va[3]) << 32;
+	igc_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval);
+
+	/* Adjust timestamp for the RX latency based on link speed */
+	switch (adapter->link_speed) {
+	case SPEED_10:
+		adjust = IGC_I225_RX_LATENCY_10;
+		break;
+	case SPEED_100:
+		adjust = IGC_I225_RX_LATENCY_100;

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 203

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +10 -0
+		break;
+	case SPEED_1000:
+		adjust = IGC_I225_RX_LATENCY_1000;
+		break;
+	case SPEED_2500:
+		adjust = IGC_I225_RX_LATENCY_2500;
+		break;
+	default:
+		adjust = 0;
+		netdev_warn_once(adapter->netdev, "Imprecise timestamp\n");

How is timestamp related to link speed? I mean, this warning is telling me that there is something wrong with the timestamp that hw put onto frame, not that link speed is cranky.

Quoted 11 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +1 -0
+		break;
 	}
 	skb_hwtstamps(skb)->hwtstamp =
 		ktime_sub_ns(skb_hwtstamps(skb)->hwtstamp, adjust);
Signature · 6 lines
2.28.0

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
#12 lore raw

PATCH v3 7/9 igc: Add initial XDP support

In reply to Andre Guedes
Quoted 208 lines · Andre Guedes

This patch adds the initial XDP support to the igc driver. For now, only XDP_PASS, XDP_DROP, XDP_ABORTED actions are supported. Upcoming patches will add support for the remaining XDP actions.

XDP configuration helpers are defined in a new file, igc_xdp.c. These helpers are utilized in igc_main.c to implement the ndo_bpf callback. XDP-related code that belongs to the driver's hot path is landed in igc_main.c.

By default, the driver uses rx buffers with 2 KB size. When XDP is enabled, it uses larger buffers so we have enough space to accommodate the headroom and tailroom required by XDP infrastructure. Also, the driver doesn't support XDP functionality with frames that span over multiple buffers so jumbo frames are not allowed for now.

The approach implemented by this patch follows the approach implemented in other Intel drivers as much as possible for the sake of consistency across the drivers.

Quick comment regarding igc_build_skb(): this patch doesn't touch it because the function is never called. It seems its support is incomplete/in progress. The function was added by commit 0507ef8a0372b ("igc: Add transmit and receive fastpath and interrupt handlers") but ring_uses_build_skb() always return False since the IGC_RING_FLAG_RX_ BUILD_SKB_ENABLED isn't set anywhere in the driver code.

This patch has been tested with the sample app "xdp1" located in samples/bpf/ dir.

---
 drivers/net/ethernet/intel/igc/Makefile   |   2 +-
 drivers/net/ethernet/intel/igc/igc.h      |   2 +
 drivers/net/ethernet/intel/igc/igc_main.c | 118 ++++++++++++++++++++--
 drivers/net/ethernet/intel/igc/igc_xdp.c  |  33 ++++++
 drivers/net/ethernet/intel/igc/igc_xdp.h  |  10 ++
 5 files changed, 153 insertions(+), 12 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/igc/igc_xdp.c
 create mode 100644 drivers/net/ethernet/intel/igc/igc_xdp.h
drivers/net/ethernet/intel/igc/Makefile +1 -1
index 1c3051db9085..95d1e8c490a4 100644
@@ -8,4 +8,4 @@
 obj-$(CONFIG_IGC) += igc.o
 
 igc-objs := igc_main.o igc_mac.o igc_i225.o igc_base.o igc_nvm.o igc_phy.o \
-igc_diag.o igc_ethtool.o igc_ptp.o igc_dump.o igc_tsn.o
+igc_diag.o igc_ethtool.o igc_ptp.o igc_dump.o igc_tsn.o igc_xdp.o
drivers/net/ethernet/intel/igc/igc.h +2 -0
index e72f1fc772aa..5c2f363106ae 100644
@@ -224,6 +224,8 @@ struct igc_adapter {
 	struct mutex ptm_time_lock; /* protects host and device timestamps */
 	ktime_t ptm_device_time;
 	struct system_counterval_t ptm_host_time;
+
+	struct bpf_prog *xdp_prog;
 };
 
 void igc_up(struct igc_adapter *adapter);
drivers/net/ethernet/intel/igc/igc_main.c +66 -4
index 84ffde75e968..734a570bbadb 100644
@@ -11,17 +11,22 @@
 #include <linux/pm_runtime.h>
 #include <net/pkt_sched.h>
 #include <linux/pci.h>
+#include <linux/bpf_trace.h>
 
 #include <net/ipv6.h>
 
 #include "igc.h"
 #include "igc_hw.h"
 #include "igc_tsn.h"
+#include "igc_xdp.h"
 
 #define DRV_SUMMARY	"Intel(R) 2.5G Ethernet Linux Driver"
 
 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+#define IGC_XDP_PASS		0
+#define IGC_XDP_CONSUMED	BIT(0)
+
 static int debug = -1;
 
 MODULE_AUTHOR("Intel Corporation, <[email protected]>");
@@ -346,6 +351,8 @@ static void igc_clean_rx_ring(struct igc_ring *rx_ring)
 {
 	u16 i = rx_ring->next_to_clean;
 
+	clear_ring_uses_large_buffer(rx_ring);
+
 	dev_kfree_skb(rx_ring->skb);
 	rx_ring->skb = NULL;
 
@@ -498,6 +505,11 @@ static int igc_setup_all_rx_resources(struct igc_adapter *adapter)
 	return err;
 }
 
+static bool igc_xdp_is_enabled(struct igc_adapter *adapter)
+{
+	return !!adapter->xdp_prog;
+}
+
 /**
  * igc_configure_rx_ring - Configure a receive ring after Reset
  * @adapter: board private structure
@@ -514,6 +526,9 @@ static void igc_configure_rx_ring(struct igc_adapter *adapter,
 	u32 srrctl = 0, rxdctl = 0;
 	u64 rdba = ring->dma;
 
+	if (igc_xdp_is_enabled(adapter))
+		set_ring_uses_large_buffer(ring);
+
 	/* disable the queue */
 	wr32(IGC_RXDCTL(reg_idx), 0);
 
@@ -1594,12 +1609,12 @@ static struct sk_buff *igc_build_skb(struct igc_ring *rx_ring,
 
 static struct sk_buff *igc_construct_skb(struct igc_ring *rx_ring,
 					 struct igc_rx_buffer *rx_buffer,
-					 unsigned int size, int pkt_offset,
+					 struct xdp_buff *xdp,
 					 ktime_t timestamp)
 {
-	void *va = page_address(rx_buffer->page) + rx_buffer->page_offset +
-		   pkt_offset;
+	unsigned int size = xdp->data_end - xdp->data;
 	unsigned int truesize = igc_get_rx_frame_truesize(rx_ring, size);
+	void *va = xdp->data;
 	unsigned int headlen;
 	struct sk_buff *skb;
 
@@ -1748,6 +1763,10 @@ static bool igc_cleanup_headers(struct igc_ring *rx_ring,
 				union igc_adv_rx_desc *rx_desc,
 				struct sk_buff *skb)
 {
+	/* XDP packets use error pointer so abort at this point */
+	if (IS_ERR(skb))
+		return true;
+
 	if (unlikely(igc_test_staterr(rx_desc, IGC_RXDEXT_STATERR_RXE))) {
 		struct net_device *netdev = rx_ring->netdev;
 
@@ -1787,7 +1806,14 @@ static void igc_put_rx_buffer(struct igc_ring *rx_ring,
 
 static inline unsigned int igc_rx_offset(struct igc_ring *rx_ring)
 {
-	return ring_uses_build_skb(rx_ring) ? IGC_SKB_PAD : 0;
+	struct igc_adapter *adapter = rx_ring->q_vector->adapter;
+
+	if (ring_uses_build_skb(rx_ring))
+		return IGC_SKB_PAD;
+	if (igc_xdp_is_enabled(adapter))
+		return XDP_PACKET_HEADROOM;
+
+	return 0;
 }
 
 static bool igc_alloc_mapped_page(struct igc_ring *rx_ring,
@@ -1901,6 +1927,42 @@ static void igc_alloc_rx_buffers(struct igc_ring *rx_ring, u16 cleaned_count)
 	}
 }
 
+static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter,
+					struct xdp_buff *xdp)
+{
+	struct bpf_prog *prog;
+	int res;
+	u32 act;
+
+	rcu_read_lock();
+
+	prog = READ_ONCE(adapter->xdp_prog);
+	if (!prog) {
+		res = IGC_XDP_PASS;
+		goto unlock;
+	}
+
+	act = bpf_prog_run_xdp(prog, xdp);
+	switch (act) {
+	case XDP_PASS:
+		res = IGC_XDP_PASS;
+		break;
+	default:
+		bpf_warn_invalid_xdp_action(act);
+		fallthrough;
+	case XDP_ABORTED:
+		trace_xdp_exception(adapter->netdev, prog, act);
+		fallthrough;
+	case XDP_DROP:
+		res = IGC_XDP_CONSUMED;
+		break;
+	}
+
+unlock:
+	rcu_read_unlock();
+	return ERR_PTR(-res);
+}
+
 static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
 {
 	unsigned int total_bytes = 0, total_packets = 0;

drivers/net/ethernet/intel/igc/igc_main.c static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) · line 1977

Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +1 -0
@@ -1912,8 +1974,10 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
 		union igc_adv_rx_desc *rx_desc;
 		struct igc_rx_buffer *rx_buffer;
 		ktime_t timestamp = 0;
+		struct xdp_buff xdp;

I'm wondering if this patch should zero-init the xdp_buff. There are two pointers that are left untouched below (rxq/txq) so maybe bpf prog would get some weird behavior if it would be touching them.

Quoted 153 lines
drivers/net/ethernet/intel/igc/igc_main.c +40 -7
 		int pkt_offset = 0;
 		unsigned int size;
+		void *pktbuf;
 
 		/* return some buffers to hardware, one at a time is too slow */
 		if (cleaned_count >= IGC_RX_BUFFER_WRITE) {
@@ -1934,24 +1998,38 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
 
 		rx_buffer = igc_get_rx_buffer(rx_ring, size);
 
-		if (igc_test_staterr(rx_desc, IGC_RXDADV_STAT_TSIP)) {
-			void *pktbuf = page_address(rx_buffer->page) +
-				       rx_buffer->page_offset;
+		pktbuf = page_address(rx_buffer->page) + rx_buffer->page_offset;
 
+		if (igc_test_staterr(rx_desc, IGC_RXDADV_STAT_TSIP)) {
 			timestamp = igc_ptp_rx_pktstamp(q_vector->adapter,
 							pktbuf);
 			pkt_offset = IGC_TS_HDR_LEN;
 			size -= IGC_TS_HDR_LEN;
 		}
 
-		/* retrieve a buffer from the ring */
-		if (skb)
+		if (!skb) {
+			struct igc_adapter *adapter = q_vector->adapter;
+
+			xdp.data = pktbuf + pkt_offset;
+			xdp.data_end = xdp.data + size;
+			xdp.data_hard_start = pktbuf - igc_rx_offset(rx_ring);
+			xdp_set_data_meta_invalid(&xdp);
+			xdp.frame_sz = igc_get_rx_frame_truesize(rx_ring, size);
+
+			skb = igc_xdp_run_prog(adapter, &xdp);
+		}
+
+		if (IS_ERR(skb)) {
+			rx_buffer->pagecnt_bias++;
+			total_packets++;
+			total_bytes += size;
+		} else if (skb)
 			igc_add_rx_frag(rx_ring, rx_buffer, skb, size);
 		else if (ring_uses_build_skb(rx_ring))
 			skb = igc_build_skb(rx_ring, rx_buffer, rx_desc, size);
 		else
-			skb = igc_construct_skb(rx_ring, rx_buffer, size,
-						pkt_offset, timestamp);
+			skb = igc_construct_skb(rx_ring, rx_buffer, &xdp,
+						timestamp);
 
 		/* exit if we failed to retrieve a buffer */
 		if (!skb) {
@@ -3893,6 +3971,11 @@ static int igc_change_mtu(struct net_device *netdev, int new_mtu)
 	int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
 	struct igc_adapter *adapter = netdev_priv(netdev);
 
+	if (igc_xdp_is_enabled(adapter) && new_mtu > ETH_DATA_LEN) {
+		netdev_dbg(netdev, "Jumbo frames not supported with XDP");
+		return -EINVAL;
+	}
+
 	/* adjust max frame to be at least the size of a standard frame */
 	if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
 		max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
@@ -4881,6 +4964,18 @@ static int igc_setup_tc(struct net_device *dev, enum tc_setup_type type,
 	}
 }
 
+static int igc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
+{
+	struct igc_adapter *adapter = netdev_priv(dev);
+
+	switch (bpf->command) {
+	case XDP_SETUP_PROG:
+		return igc_xdp_set_prog(adapter, bpf->prog, bpf->extack);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 static const struct net_device_ops igc_netdev_ops = {
 	.ndo_open		= igc_open,
 	.ndo_stop		= igc_close,
@@ -4894,6 +4989,7 @@ static const struct net_device_ops igc_netdev_ops = {
 	.ndo_features_check	= igc_features_check,
 	.ndo_do_ioctl		= igc_ioctl,
 	.ndo_setup_tc		= igc_setup_tc,
+	.ndo_bpf		= igc_bpf,
 };
 
 /* PCIe configuration access */
drivers/net/ethernet/intel/igc/igc_xdp.c new file +33 -0
new file mode 100644
index 000000000000..27c886a254f1
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2020, Intel Corporation. */
+
+#include "igc.h"
+#include "igc_xdp.h"
+
+int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
+		     struct netlink_ext_ack *extack)
+{
+	struct net_device *dev = adapter->netdev;
+	bool if_running = netif_running(dev);
+	struct bpf_prog *old_prog;
+
+	if (dev->mtu > ETH_DATA_LEN) {
+		/* For now, the driver doesn't support XDP functionality with
+		 * jumbo frames so we return error.
+		 */
+		NL_SET_ERR_MSG_MOD(extack, "Jumbo frames not supported");
+		return -EOPNOTSUPP;
+	}
+
+	if (if_running)
+		igc_close(dev);
+
+	old_prog = xchg(&adapter->xdp_prog, prog);
+	if (old_prog)
+		bpf_prog_put(old_prog);
+
+	if (if_running)
+		igc_open(dev);
+
+	return 0;
+}
drivers/net/ethernet/intel/igc/igc_xdp.h new file +10 -0
new file mode 100644
index 000000000000..8a410bcefe1a
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2020, Intel Corporation. */
+
+#ifndef _IGC_XDP_H_
+#define _IGC_XDP_H_
+
+int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
+		     struct netlink_ext_ack *extack);
+
+#endif /* _IGC_XDP_H_ */
Signature · 6 lines
2.28.0

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
#16 lore raw

PATCH v3 8/9 igc: Add support for XDP_TX action

In reply to Andre Guedes
Quoted 21 lines · Andre Guedes

This patch adds support for XDP_TX action which enables XDP programs to transmit back receiving frames.

I225 controller has only 4 tx hardware queues. Since XDP programs may not even issue an XDP_TX action, this patch doesn't reserve dedicated queues just for XDP like other Intel drivers do. Instead, the queues are shared between the network stack and XDP. The netdev queue lock is used to ensure mutual exclusion.

Since frames can now be transmitted via XDP_TX, the igc_tx_buffer structure is modified so we are able to save a reference to the xdp frame for later clean up once the packet is transmitted. The tx_buffer is mapped to either a skb or a xdpf so we use a union to save the skb or xdpf pointer and have a bit in tx_flags to indicate which field to use.

This patch has been tested with the sample app "xdp2" located in samples/bpf/ dir.

---

[...]

drivers/net/ethernet/intel/igc/igc_main.c static void igc_alloc_rx_buffers(struct igc_ring *rx_ring, u16 cleaned_count) · line 2007

Quoted 8 lines
drivers/net/ethernet/intel/igc/igc_main.c +8 -0
+
+static struct igc_ring *igc_xdp_get_tx_ring(struct igc_adapter *adapter,
+					    int cpu)
+{
+	int index = cpu;
+
+	if (index >= adapter->num_tx_queues)
+		index = index % adapter->num_tx_queues;

I'm not sure why you don't want to take the suggestion for getting rid of modulo op. I won't insist anymore ;)

Quoted 3 lines
drivers/net/ethernet/intel/igc/igc_main.c +3 -0
+
+	return adapter->tx_ring[index];
+}

[...]

#20 lore raw

PATCH v3 9/9 igc: Add support for XDP_REDIRECT action

In reply to Andre Guedes
Quoted 5 lines · Andre Guedes

This patch adds support for the XDP_REDIRECT action which enables XDP programs to redirect packets arriving at I225 NIC. It also implements the ndo_xdp_xmit ops, enabling the igc driver to transmit packets forwarded to it by xdp programs running on other interfaces.

Quoted 7 lines

The patch tweaks the driver's page counting scheme (as described in '8ce29c679a6e i40e: tweak page counting for XDP_REDIRECT' and implemented by other Intel drivers) in order to properly support XDP_REDIRECT action.

This patch has been tested with the sample apps "xdp_redirect_cpu" and "xdp_redirect_map" located in samples/bpf/.

Did you test in a way that the igc interface was the second interface for redirect samples and you checked that tx happened?

Quoted 3 lines

---

#22 lore raw

v3 cover igc: Add XDP support

In reply to Andre Guedes
Quoted 12 lines · Andre Guedes

Hi all,

This is the third version of this series which adds XDP support to igc driver.

The main changes from v2 are:

- Moved functions that belong to the driver's hot path to igc_main.c to allow the compiler to inline them if convenient.
- Squashed ndo_xdp_xmit patch into XDP_REDIRECT patch.

v2 is here:

Quoted 8 lines
    https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20201028201943.93147-1-andre.guedes at intel.com/

v1 is here:

    https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20201009025349.4037-1-andre.guedes at intel.com/

Cheers,
Andre

I had only minor comments/questions for this version, so you can take my:

for series.

Quoted 30 lines

Andre Guedes (9):
igc: Fix igc_ptp_rx_pktstamp()
igc: Remove unused argument from igc_tx_cmd_type()
igc: Introduce igc_rx_buffer_flip() helper
igc: Introduce igc_get_rx_frame_truesize() helper
igc: Refactor rx timestamp handling
igc: Add set/clear large buffer helpers
igc: Add initial XDP support
igc: Add support for XDP_TX action
igc: Add support for XDP_REDIRECT action

 drivers/net/ethernet/intel/igc/Makefile   |   2 +-
 drivers/net/ethernet/intel/igc/igc.h      |  18 +-
 drivers/net/ethernet/intel/igc/igc_main.c | 431 +++++++++++++++++++---
 drivers/net/ethernet/intel/igc/igc_ptp.c  |  89 +++--
 drivers/net/ethernet/intel/igc/igc_xdp.c  |  60 +++
 drivers/net/ethernet/intel/igc/igc_xdp.h  |  13 +
 6 files changed, 512 insertions(+), 101 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/igc/igc_xdp.c
 create mode 100644 drivers/net/ethernet/intel/igc/igc_xdp.h
Signature · 6 lines
2.28.0

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
#3 lore raw

PATCH v3 1/9 igc: Fix igc_ptp_rx_pktstamp()

In reply to Maciej Fijalkowski

Quoting Maciej Fijalkowski (2020-11-02 09:56:17)

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -6
+void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, u32 *va,
                       struct sk_buff *skb)
 {
      struct igc_adapter *adapter = q_vector->adapter;
-     __le64 *regval = (__le64 *)va;
-     int adjust = 0;
-
-     /* The timestamp is recorded in little endian format.
-      * DWORD: | 0          | 1           | 2          | 3
-      * Field: | Timer0 Low | Timer0 High | Timer1 Low | Timer1 High
+     u64 regval;
+     int adjust;
Quoted 8 lines

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 177

Quoted 5 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +5 -0
+
+     /* Timestamps are saved in little endian at the beginning of the packet
+      * buffer following the layout:
+      *
+      * | 0              | 1              | 2              | 3              |

Minor nit, I find DWORD comment helpful from previous version of this description.

Let me bring that comment back.

Quoted 4 lines
Quoted 2 lines

+ * | Timer1 SYSTIML | Timer1 SYSTIMH | Timer0 SYSTIML | Timer0 SYSTIMH |

A dumb question from ptp/igc noob: why two timers?

i225 has 4 independent timers and software can select 2 of them to be sampled when the packet is received. One use case I can think of is to help with cross-timestamping in multiple clocks scenario so you could have a "global" timestamp and a "local" timestamp for a single packet.

Quoted 10 lines

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 182

Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -5
+      *
+      * SYSTIML holds the nanoseconds part while SYSTIMH holds the seconds
+      * part of the timestamp.
       */
-     igc_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb),
-                                le64_to_cpu(regval[0]));
-
-     /* adjust timestamp for the RX latency based on link speed */
-     if (adapter->hw.mac.type == igc_i225) {
Quoted 2 lines

if this check is not required here, then is it within igc_ptp_systim_to_hwtstamp?

It is not required in igc_ptp_systim_to_hwtstamp() either. As discussed in [1] these checks will be cleaned up in a separate series.

Quoted 18 lines
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +7 -0
+     /* Adjust timestamp for the RX latency based on link speed */
+     switch (adapter->link_speed) {
+     case SPEED_10:
+             adjust = IGC_I225_RX_LATENCY_10;
+             break;
+     case SPEED_100:
+             adjust = IGC_I225_RX_LATENCY_100;

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 203

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +10 -0
+             break;
+     case SPEED_1000:
+             adjust = IGC_I225_RX_LATENCY_1000;
+             break;
+     case SPEED_2500:
+             adjust = IGC_I225_RX_LATENCY_2500;
+             break;
+     default:
+             adjust = 0;
+             netdev_warn_once(adapter->netdev, "Imprecise timestamp\n");
Quoted 3 lines

How is timestamp related to link speed? I mean, this warning is telling me that there is something wrong with the timestamp that hw put onto frame, not that link speed is cranky.

The timestamp is sampled at the beginning of the packet. Although the timestamp logic is located as close as possible to the PHY interface, there is a latency between the moment the PHY received the first bit of the packet and the moment the timestamp logic samples. That latency depends on the link speed and is specified in the datasheet so software can adjust it.

In this regards, i225 is similar to i210 so you can take a look at section 7.8.3.1 Capture Timestamp Mechanism from i210 datasheet for further details.

Best,
Andre

[1] https://patchwork.ozlabs.org/project/intel-wired-lan/patch/20200519101644.8246-1-sasha.neftin at intel.com/

#13 lore raw

PATCH v3 7/9 igc: Add initial XDP support

In reply to Maciej Fijalkowski

Quoting Maciej Fijalkowski (2020-11-02 10:07:00)

Quoted 4 lines
Quoted 4 lines

static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)

 {
      unsigned int total_bytes = 0, total_packets = 0;
(quoted diff) +0 -0
@@ -1912,8 +1974,10 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
Quoted 8 lines

drivers/net/ethernet/intel/igc/igc_main.c static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) · line 1977

Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +1 -0
              union igc_adv_rx_desc *rx_desc;
              struct igc_rx_buffer *rx_buffer;
              ktime_t timestamp = 0;
+             struct xdp_buff xdp;

I'm wondering if this patch should zero-init the xdp_buff. There are two pointers that are left untouched below (rxq/txq) so maybe bpf prog would get some weird behavior if it would be touching them.

I see your point. While rxq is set by the next patch txq is not. I took a look at ice, i40e, ixgbe, and they don't seem to zero-init neither set txq so maybe that's OK.

#17 lore raw

PATCH v3 8/9 igc: Add support for XDP_TX action

In reply to Maciej Fijalkowski

Quoting Maciej Fijalkowski (2020-11-02 10:26:59)

Quoted 10 lines

drivers/net/ethernet/intel/igc/igc_main.c static void igc_alloc_rx_buffers(struct igc_ring *rx_ring, u16 cleaned_count) · line 2007

Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_main.c +7 -0
+static struct igc_ring *igc_xdp_get_tx_ring(struct igc_adapter *adapter,
+                                         int cpu)
+{
+     int index = cpu;
+
+     if (index >= adapter->num_tx_queues)
+             index = index % adapter->num_tx_queues;

I'm not sure why you don't want to take the suggestion for getting rid of modulo op. I won't insist anymore ;)

As I mentioned in the previous comment, I was just following the same approach from igb. Since I'll submit a v4 already, I'll do that as well.

#21 lore raw

PATCH v3 9/9 igc: Add support for XDP_REDIRECT action

In reply to Maciej Fijalkowski

Quoting Maciej Fijalkowski (2020-11-02 10:30:07)

Quoted 11 lines · Andre Guedes
Quoted 10 lines

This patch adds support for the XDP_REDIRECT action which enables XDP programs to redirect packets arriving at I225 NIC. It also implements the ndo_xdp_xmit ops, enabling the igc driver to transmit packets forwarded to it by xdp programs running on other interfaces.

The patch tweaks the driver's page counting scheme (as described in '8ce29c679a6e i40e: tweak page counting for XDP_REDIRECT' and implemented by other Intel drivers) in order to properly support XDP_REDIRECT action.

Quoted 5 lines
Quoted 2 lines

This patch has been tested with the sample apps "xdp_redirect_cpu" and "xdp_redirect_map" located in samples/bpf/.

Did you test in a way that the igc interface was the second interface for redirect samples and you checked that tx happened?

I tested both ways with xdp_redirect_map i.e. igc interface as the IFNAME_IN and as the IFNAME_OUT arguments.

#23 lore raw

v3 cover igc: Add XDP support

In reply to Maciej Fijalkowski

Quoting Maciej Fijalkowski (2020-11-02 10:31:29)

Quoted 19 lines · Andre Guedes
Quoted 18 lines

Hi all,

This is the third version of this series which adds XDP support to igc driver.

The main changes from v2 are:

- Moved functions that belong to the driver's hot path to igc_main.c to allow the compiler to inline them if convenient.
- Squashed ndo_xdp_xmit patch into XDP_REDIRECT patch.

v2 is here:

    https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20201028201943.93147-1-andre.guedes at intel.com/

v1 is here:

    https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20201009025349.4037-1-andre.guedes at intel.com/
Quoted 8 lines
Quoted 2 lines

Cheers,
Andre

I had only minor comments/questions for this version, so you can take my:

for series.

Thanks for the review, Maceij! I'm adding your Reviewed-by to the next version of this series I'm submitting soon.

#14 lore raw

PATCH v3 7/9 igc: Add initial XDP support

In reply to Andre Guedes
Quoted 14 lines · Andre Guedes

Quoting Maciej Fijalkowski (2020-11-02 10:07:00)

Quoted 4 lines
Quoted 4 lines

static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)

 {
      unsigned int total_bytes = 0, total_packets = 0;
(quoted diff) +0 -0
@@ -1912,8 +1974,10 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
Quoted 8 lines

drivers/net/ethernet/intel/igc/igc_main.c static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) · line 1977

Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +1 -0
              union igc_adv_rx_desc *rx_desc;
              struct igc_rx_buffer *rx_buffer;
              ktime_t timestamp = 0;
+             struct xdp_buff xdp;

I'm wondering if this patch should zero-init the xdp_buff. There are two pointers that are left untouched below (rxq/txq) so maybe bpf prog would get some weird behavior if it would be touching them.

Quoted 3 lines

I see your point. While rxq is set by the next patch txq is not. I took a look at ice, i40e, ixgbe, and they don't seem to zero-init neither set txq so maybe that's OK.

To clear it up, txq in xdp_buff is explicitly set in dev_map_run_prog(), which is sort of a xdp tx hook. That's why none of the driver has to do that. Sorry for confusion :)

#4 lore raw

PATCH v3 1/9 igc: Fix igc_ptp_rx_pktstamp()

In reply to Andre Guedes
Quoted 44 lines · Andre Guedes

Quoting Maciej Fijalkowski (2020-11-02 09:56:17)

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -6
+void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, u32 *va,
                       struct sk_buff *skb)
 {
      struct igc_adapter *adapter = q_vector->adapter;
-     __le64 *regval = (__le64 *)va;
-     int adjust = 0;
-
-     /* The timestamp is recorded in little endian format.
-      * DWORD: | 0          | 1           | 2          | 3
-      * Field: | Timer0 Low | Timer0 High | Timer1 Low | Timer1 High
+     u64 regval;
+     int adjust;
Quoted 8 lines

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 177

Quoted 5 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +5 -0
+
+     /* Timestamps are saved in little endian at the beginning of the packet
+      * buffer following the layout:
+      *
+      * | 0              | 1              | 2              | 3              |

Minor nit, I find DWORD comment helpful from previous version of this description.

Let me bring that comment back.

Quoted 4 lines
Quoted 2 lines

+ * | Timer1 SYSTIML | Timer1 SYSTIMH | Timer0 SYSTIML | Timer0 SYSTIMH |

A dumb question from ptp/igc noob: why two timers?

i225 has 4 independent timers and software can select 2 of them to be sampled when the packet is received. One use case I can think of is to help with cross-timestamping in multiple clocks scenario so you could have a "global" timestamp and a "local" timestamp for a single packet.

Quoted 10 lines
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -5
+      *
+      * SYSTIML holds the nanoseconds part while SYSTIMH holds the seconds
+      * part of the timestamp.
       */
-     igc_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb),
-                                le64_to_cpu(regval[0]));
-
-     /* adjust timestamp for the RX latency based on link speed */
-     if (adapter->hw.mac.type == igc_i225) {
Quoted 5 lines
Quoted 2 lines

if this check is not required here, then is it within igc_ptp_systim_to_hwtstamp?

It is not required in igc_ptp_systim_to_hwtstamp() either. As discussed in [1] these checks will be cleaned up in a separate series.

Okay thanks.

Quoted 23 lines
Quoted 19 lines
Quoted 8 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +7 -0
+     /* Adjust timestamp for the RX latency based on link speed */
+     switch (adapter->link_speed) {
+     case SPEED_10:
+             adjust = IGC_I225_RX_LATENCY_10;
+             break;
+     case SPEED_100:
+             adjust = IGC_I225_RX_LATENCY_100;

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 203

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +10 -0
+             break;
+     case SPEED_1000:
+             adjust = IGC_I225_RX_LATENCY_1000;
+             break;
+     case SPEED_2500:
+             adjust = IGC_I225_RX_LATENCY_2500;
+             break;
+     default:
+             adjust = 0;
+             netdev_warn_once(adapter->netdev, "Imprecise timestamp\n");
Quoted 3 lines

How is timestamp related to link speed? I mean, this warning is telling me that there is something wrong with the timestamp that hw put onto frame, not that link speed is cranky.

Quoted 5 lines

The timestamp is sampled at the beginning of the packet. Although the timestamp logic is located as close as possible to the PHY interface, there is a latency between the moment the PHY received the first bit of the packet and the moment the timestamp logic samples. That latency depends on the link speed and is specified in the datasheet so software can adjust it.

Thanks for that explanation! I meant that warning should say something like "wrong link speed, can not adjust timestamp", but OTOH I have a feeling that all of the speeds that this HW supports are handled in this switch statement, so probably arguing about that warning is pointless? :)

Quoted 8 lines

In this regards, i225 is similar to i210 so you can take a look at section 7.8.3.1 Capture Timestamp Mechanism from i210 datasheet for further details.

Best,
Andre

[1] https://patchwork.ozlabs.org/project/intel-wired-lan/patch/20200519101644.8246-1-sasha.neftin at intel.com/

#18 lore raw

PATCH v3 8/9 igc: Add support for XDP_TX action

In reply to Andre Guedes

Hi,

Quoted 12 lines · Andre Guedes

Quoting Maciej Fijalkowski (2020-11-02 10:26:59)

Quoted 10 lines

drivers/net/ethernet/intel/igc/igc_main.c static void igc_alloc_rx_buffers(struct igc_ring *rx_ring, u16 cleaned_count) · line 2007

Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_main.c +7 -0
+static struct igc_ring *igc_xdp_get_tx_ring(struct igc_adapter *adapter,
+                                         int cpu)
+{
+     int index = cpu;
+
+     if (index >= adapter->num_tx_queues)
+             index = index % adapter->num_tx_queues;

I'm not sure why you don't want to take the suggestion for getting rid of modulo op. I won't insist anymore ;)

Quoted 3 lines

As I mentioned in the previous comment, I was just following the same approach from igb. Since I'll submit a v4 already, I'll do that as well.

Another idea is to use iter_div_u64_rem() as the expected difference between divident and divisor should be small.

Cheers,

Signature · 1 line
Vinicius
#5 lore raw

PATCH v3 1/9 igc: Fix igc_ptp_rx_pktstamp()

In reply to Maciej Fijalkowski
Quoted 32 lines · Maciej
Quoted 24 lines
Quoted 20 lines
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +7 -0
+     /* Adjust timestamp for the RX latency based on link speed */
+     switch (adapter->link_speed) {
+     case SPEED_10:
+             adjust = IGC_I225_RX_LATENCY_10;
+             break;
+     case SPEED_100:
+             adjust = IGC_I225_RX_LATENCY_100;

drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, · line 203

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +10 -0
+             break;
+     case SPEED_1000:
+             adjust = IGC_I225_RX_LATENCY_1000;
+             break;
+     case SPEED_2500:
+             adjust = IGC_I225_RX_LATENCY_2500;
+             break;
+     default:
+             adjust = 0;
+             netdev_warn_once(adapter->netdev, "Imprecise timestamp\n");
Quoted 3 lines

How is timestamp related to link speed? I mean, this warning is telling me that there is something wrong with the timestamp that hw put onto frame, not that link speed is cranky.

Quoted 5 lines

The timestamp is sampled at the beginning of the packet. Although the timestamp logic is located as close as possible to the PHY interface, there is a latency between the moment the PHY received the first bit of the packet and the moment the timestamp logic samples. That latency depends on the link speed and is specified in the datasheet so software can adjust it.

Quoted 4 lines

Thanks for that explanation! I meant that warning should say something like "wrong link speed, can not adjust timestamp", but OTOH I have a feeling that all of the speeds that this HW supports are handled in this switch statement, so probably arguing about that warning is pointless? :)

For TSN use cases, timestamp precision is very important. If, for any reason, adapter->link_speed is off, we want to at least log that information.