Skip to contentSkip to conversation

tsnep: XDP support

PATCH Applied Gerhard Engleder 2 participants 11 messages Jan 16, 2023 – Jan 18, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v5 cover tsnep: XDP support

Implement XDP support for tsnep driver. I tried to follow existing drivers like igb/igc as far as possible. Some prework was already done in previous patch series, so in this series only actual XDP stuff is included.

Thanks for the NetDev 0x14 slides "Add XDP support on a NIC driver".

Some commits contain changes not related to XDP but found during review of XDP support patches.

v5:
- fix spelling of 'subtract' in commit message (Alexander Duyck)
- call txq_trans_cond_update() only if TX is complete (Alexander Duyck)
- remove const from static functions (Alexander Duyck)
- replace TX spin_lock with __netif_tx_lock (Alexander Duyck)
- use xdp_return_frame_rx_napi() instead of xdp_return_frame_bulk() (Alexander Duyck)
- eliminate __TSNEP_DOWN (Alexander Duyck)
- introduce single function for xdp_rxq and napi init (Alexander Duyck)
- use TX queue of pair instead of expensive processor id modulo for XDP_TX (Alexander Duyck)
- eliminate processor id modulo in tsnep_netdev_xdp_xmit (Alexander Duyck)
- use bitmap for TX type and add fragment type (Alexander Duyck)
- always use XDP_PACKET_HEADROOM and DMA_BIDIRECTIONAL

v4:
- remove process context from spin_lock_bh commit message (Alexander Lobakin)
- move tsnep_adapter::state to prevent 4 byte hole (Alexander Lobakin)
- braces for bitops in combination logical ops (Alexander Lobakin)
- make various pointers const (Alexander Lobakin)
- '!i' instead of 'i == 0' (Alexander Lobakin)
- removed redundant braces (Alexander Lobakin)
- squash variables into same line if same type (Alexander Lobakin)
- use fact that ::skb and ::xdpf use same slot for simplification (Alexander Lobakin)
- use u32 for smp_processor_id() (Alexander Lobakin)
- don't add $(tsnep-y) to $(tsnep-objs) (Alexander Lobakin)
- use rev xmas tree in tsnep_netdev_open() (Alexander Lobakin)
- do not move tsnep_queue::napi (Alexander Lobakin)
- call xdp_init_buff() only once (Alexander Lobakin)
- get nq and tx only once for XDP TX (Alexander Lobakin)
- move XDP BPF program setup to end of patch series (Alexander Lobakin)
- check for XDP state change and prevent redundant down-ups (Alexander Lobakin)
- access tsnep_adapter::xdp_prog only with READ_ONCE in RX path (Alexander Lobakin)
- forward NAPI budget to napi_consume_skb() (Alexander Lobakin)
- fix errno leftover in tsnep_xdp_xmit_back() (Dan Carpenter)
- eliminate tsnep_xdp_is_enabled() by setting RX offset during init

v3:
- use spin_lock_bh for TX (Paolo Abeni)
- add comment for XDP TX descriptor available check (Maciej Fijalkowski)
- return value bool for tsnep_xdp_xmit_frame_ring() (Saeed Mahameed)
- do not print DMA mapping error (Saeed Mahameed)
- use reverse xmas tree variable declaration (Saeed Mahameed)
- move struct xdp_rxq_info to end of struct tsnep_rx (Maciej Fijalkowski)
- check __TSNEP_DOWN flag on close to prevent double free (Saeed Mahameed)
- describe TSNEP_RX_INLINE_METADATA_SIZE in comment (Maciej Fijalkowski)
- substract TSNEP_RX_INLINE_METADATA_SIZE after DMA sync (Maciej Fijalkowski)
- use enum tsnep_tx_type for tsnep_xdp_tx_map (Saeed Mahameed)
- use nxmit as loop iterator in tsnep_netdev_xdp_xmit (Saeed Mahameed)
- stop netdev in tsnep_netdev_close() which is called during BPF prog setup

v2:
- move tsnep_xdp_xmit_back() to commit where it is used (Paolo Abeni)
- remove inline from tsnep_rx_offset() (Paolo Abeni)
- remove inline from tsnep_rx_offset_xdp() (Paolo Abeni)
- simplify tsnep_xdp_run_prog() call by moving xdp_status update to it (Paolo Abeni)

Gerhard Engleder (9):
tsnep: Replace TX spin_lock with __netif_tx_lock
tsnep: Forward NAPI budget to napi_consume_skb()
tsnep: Do not print DMA mapping error
tsnep: Add XDP TX support
tsnep: Subtract TSNEP_RX_INLINE_METADATA_SIZE once
tsnep: Prepare RX buffer for XDP support
tsnep: Add RX queue info for XDP support
tsnep: Add XDP RX support
tsnep: Support XDP BPF program setup

 drivers/net/ethernet/engleder/Makefile     |   2 +-
 drivers/net/ethernet/engleder/tsnep.h      |  16 +-
 drivers/net/ethernet/engleder/tsnep_main.c | 474 ++++++++++++++++++---
 drivers/net/ethernet/engleder/tsnep_xdp.c  |  19 +
 4 files changed, 445 insertions(+), 66 deletions(-)
 create mode 100644 drivers/net/ethernet/engleder/tsnep_xdp.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH v5 1/9 tsnep: Replace TX spin_lock with __netif_tx_lock

TX spin_lock can be eliminated, because the normal TX path is already protected with __netif_tx_lock and this lock can be used for access to queue outside of normal TX path too.

---
 drivers/net/ethernet/engleder/tsnep.h      |  2 --
 drivers/net/ethernet/engleder/tsnep_main.c | 29 ++++++++--------------
 2 files changed, 10 insertions(+), 21 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +0 -2
index f93ba48bac3f..48910cb1bd8a 100644
@@ -78,8 +78,6 @@ struct tsnep_tx {
 	void *page[TSNEP_RING_PAGE_COUNT];
 	dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
 
-	/* TX ring lock */
-	spinlock_t lock;
 	struct tsnep_tx_entry entry[TSNEP_RING_SIZE];
 	int write;
 	int read;
drivers/net/ethernet/engleder/tsnep_main.c +10 -19
index bf0190e1d2ea..c182c40277dd 100644
@@ -434,7 +434,6 @@ static int tsnep_tx_unmap(struct tsnep_tx *tx, int index, int count)
 static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
 					 struct tsnep_tx *tx)
 {
-	unsigned long flags;
 	int count = 1;
 	struct tsnep_tx_entry *entry;
 	int length;
@@ -444,16 +443,12 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
 	if (skb_shinfo(skb)->nr_frags > 0)
 		count += skb_shinfo(skb)->nr_frags;
 
-	spin_lock_irqsave(&tx->lock, flags);
-
 	if (tsnep_tx_desc_available(tx) < count) {
 		/* ring full, shall not happen because queue is stopped if full
 		 * below
 		 */
 		netif_stop_queue(tx->adapter->netdev);
 
-		spin_unlock_irqrestore(&tx->lock, flags);
-
 		return NETDEV_TX_BUSY;
 	}
 
@@ -468,8 +463,6 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
 
 		tx->dropped++;
 
-		spin_unlock_irqrestore(&tx->lock, flags);
-
 		netdev_err(tx->adapter->netdev, "TX DMA map failed\n");
 
 		return NETDEV_TX_OK;
@@ -496,20 +489,19 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
 		netif_stop_queue(tx->adapter->netdev);
 	}
 
-	spin_unlock_irqrestore(&tx->lock, flags);
-
 	return NETDEV_TX_OK;
 }
 
 static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)
 {
-	unsigned long flags;
-	int budget = 128;
 	struct tsnep_tx_entry *entry;
-	int count;
+	struct netdev_queue *nq;
+	int budget = 128;
 	int length;
+	int count;
 
-	spin_lock_irqsave(&tx->lock, flags);
+	nq = netdev_get_tx_queue(tx->adapter->netdev, tx->queue_index);
+	__netif_tx_lock(nq, smp_processor_id());
 
 	do {
 		if (tx->read == tx->write)
@@ -568,18 +560,19 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)
 		netif_wake_queue(tx->adapter->netdev);
 	}
 
-	spin_unlock_irqrestore(&tx->lock, flags);
+	__netif_tx_unlock(nq);
 
 	return (budget != 0);
 }
 
 static bool tsnep_tx_pending(struct tsnep_tx *tx)
 {
-	unsigned long flags;
 	struct tsnep_tx_entry *entry;
+	struct netdev_queue *nq;
 	bool pending = false;
 
-	spin_lock_irqsave(&tx->lock, flags);
+	nq = netdev_get_tx_queue(tx->adapter->netdev, tx->queue_index);
+	__netif_tx_lock(nq, smp_processor_id());
 
 	if (tx->read != tx->write) {
 		entry = &tx->entry[tx->read];
@@ -589,7 +582,7 @@ static bool tsnep_tx_pending(struct tsnep_tx *tx)
 			pending = true;
 	}
 
-	spin_unlock_irqrestore(&tx->lock, flags);
+	__netif_tx_unlock(nq);
 
 	return pending;
 }
@@ -615,8 +608,6 @@ static int tsnep_tx_open(struct tsnep_adapter *adapter, void __iomem *addr,
 	tx->owner_counter = 1;
 	tx->increment_owner_counter = TSNEP_RING_SIZE - 1;
 
-	spin_lock_init(&tx->lock);
-
 	return 0;
 }
 
Signature · 1 line
2.30.2
#2 lore raw

PATCH v5 2/9 tsnep: Forward NAPI budget to napi_consume_skb()

In reply to Gerhard Engleder

NAPI budget must be forwarded to napi_consume_skb(). It is used to detect non-NAPI context.

---
 drivers/net/ethernet/engleder/tsnep_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/engleder/tsnep_main.c +1 -1
index c182c40277dd..8abe65a8c2f1 100644
@@ -544,7 +544,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)
 			skb_tstamp_tx(entry->skb, &hwtstamps);
 		}
 
-		napi_consume_skb(entry->skb, budget);
+		napi_consume_skb(entry->skb, napi_budget);
 		entry->skb = NULL;
 
 		tx->read = (tx->read + count) % TSNEP_RING_SIZE;
Signature · 1 line
2.30.2
#3 lore raw

PATCH v5 3/9 tsnep: Do not print DMA mapping error

In reply to Gerhard Engleder

Printing in data path shall be avoided. DMA mapping error is already counted in stats so printing is not necessary.

---
 drivers/net/ethernet/engleder/tsnep_main.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/ethernet/engleder/tsnep_main.c +0 -2
index 8abe65a8c2f1..d25608e81ad8 100644
@@ -463,8 +463,6 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
 
 		tx->dropped++;
 
-		netdev_err(tx->adapter->netdev, "TX DMA map failed\n");
-
 		return NETDEV_TX_OK;
 	}
 	length = retval;
Signature · 1 line
2.30.2
#4 lore raw

PATCH v5 4/9 tsnep: Add XDP TX support

In reply to Gerhard Engleder

Implement ndo_xdp_xmit() for XDP TX support. Support for fragmented XDP frames is included.

Also some braces and logic cleanups are done in normal TX path to keep both TX paths in sync.

---
 drivers/net/ethernet/engleder/tsnep.h      |   6 +-
 drivers/net/ethernet/engleder/tsnep_main.c | 193 ++++++++++++++++++++-
 2 files changed, 189 insertions(+), 10 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +5 -1
index 48910cb1bd8a..bd0fbddd3a75 100644
@@ -65,7 +65,11 @@ struct tsnep_tx_entry {
 
 	u32 properties;
 
-	struct sk_buff *skb;
+	u32 type;
+	union {
+		struct sk_buff *skb;
+		struct xdp_frame *xdpf;
+	};
 	size_t len;
 	DEFINE_DMA_UNMAP_ADDR(dma);
 };
drivers/net/ethernet/engleder/tsnep_main.c +184 -9

278 lines not on this page · raw message

Signature · 1 line
2.30.2
#5 lore raw

PATCH v5 5/9 tsnep: Subtract TSNEP_RX_INLINE_METADATA_SIZE once

In reply to Gerhard Engleder

Subtract size of metadata in front of received data only once. This simplifies the RX code.

---
 drivers/net/ethernet/engleder/tsnep_main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/ethernet/engleder/tsnep_main.c +9 -2
index 9b3eddda3f06..0730cd45f9a3 100644
@@ -948,7 +948,7 @@ static struct sk_buff *tsnep_build_skb(struct tsnep_rx *rx, struct page *page,
 
 	/* update pointers within the skb to store the data */
 	skb_reserve(skb, TSNEP_SKB_PAD + TSNEP_RX_INLINE_METADATA_SIZE);
-	__skb_put(skb, length - TSNEP_RX_INLINE_METADATA_SIZE - ETH_FCS_LEN);
+	__skb_put(skb, length - ETH_FCS_LEN);
 
 	if (rx->adapter->hwtstamp_config.rx_filter == HWTSTAMP_FILTER_ALL) {
 		struct skb_shared_hwtstamps *hwtstamps = skb_hwtstamps(skb);
@@ -1020,6 +1020,13 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,
 		dma_sync_single_range_for_cpu(dmadev, entry->dma, TSNEP_SKB_PAD,
 					      length, dma_dir);
 
+		/* RX metadata with timestamps is in front of actual data,
+		 * subtract metadata size to get length of actual data and
+		 * consider metadata size as offset of actual data during RX
+		 * processing
+		 */
+		length -= TSNEP_RX_INLINE_METADATA_SIZE;
+
 		rx->read = (rx->read + 1) % TSNEP_RING_SIZE;
 		desc_available++;
 
@@ -1028,7 +1035,7 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,
 			page_pool_release_page(rx->page_pool, entry->page);
 
 			rx->packets++;
-			rx->bytes += length - TSNEP_RX_INLINE_METADATA_SIZE;
+			rx->bytes += length;
 			if (skb->pkt_type == PACKET_MULTICAST)
 				rx->multicast++;
 
Signature · 1 line
2.30.2
#6 lore raw

PATCH v5 6/9 tsnep: Prepare RX buffer for XDP support

In reply to Gerhard Engleder

Always reserve XDP_PACKET_HEADROOM in front of RX buffer. Similar DMA direction is always set to DMA_BIDIRECTIONAL. This eliminates the need for RX queue reconfiguration during BPF program setup. The RX queue is always prepared for XDP.

No negative impact of DMA_BIDIRECTIONAL was measured.

---
 drivers/net/ethernet/engleder/tsnep_main.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/net/ethernet/engleder/tsnep_main.c +11 -10
index 0730cd45f9a3..45e576e74510 100644
@@ -26,9 +26,10 @@
 #include <linux/etherdevice.h>
 #include <linux/phy.h>
 #include <linux/iopoll.h>
+#include <linux/bpf.h>
 
-#define TSNEP_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
-#define TSNEP_HEADROOM ALIGN(TSNEP_SKB_PAD, 4)
+#define TSNEP_RX_OFFSET (max(NET_SKB_PAD, XDP_PACKET_HEADROOM) + NET_IP_ALIGN)
+#define TSNEP_HEADROOM ALIGN(TSNEP_RX_OFFSET, 4)
 #define TSNEP_MAX_RX_BUF_SIZE (PAGE_SIZE - TSNEP_HEADROOM - \
 			       SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
 
@@ -806,9 +807,9 @@ static int tsnep_rx_ring_init(struct tsnep_rx *rx)
 	pp_params.pool_size = TSNEP_RING_SIZE;
 	pp_params.nid = dev_to_node(dmadev);
 	pp_params.dev = dmadev;
-	pp_params.dma_dir = DMA_FROM_DEVICE;
+	pp_params.dma_dir = DMA_BIDIRECTIONAL;
 	pp_params.max_len = TSNEP_MAX_RX_BUF_SIZE;
-	pp_params.offset = TSNEP_SKB_PAD;
+	pp_params.offset = TSNEP_RX_OFFSET;
 	rx->page_pool = page_pool_create(&pp_params);
 	if (IS_ERR(rx->page_pool)) {
 		retval = PTR_ERR(rx->page_pool);
@@ -843,7 +844,7 @@ static void tsnep_rx_set_page(struct tsnep_rx *rx, struct tsnep_rx_entry *entry,
 	entry->page = page;
 	entry->len = TSNEP_MAX_RX_BUF_SIZE;
 	entry->dma = page_pool_get_dma_addr(entry->page);
-	entry->desc->rx = __cpu_to_le64(entry->dma + TSNEP_SKB_PAD);
+	entry->desc->rx = __cpu_to_le64(entry->dma + TSNEP_RX_OFFSET);
 }
 
 static int tsnep_rx_alloc_buffer(struct tsnep_rx *rx, int index)
@@ -947,14 +948,14 @@ static struct sk_buff *tsnep_build_skb(struct tsnep_rx *rx, struct page *page,
 		return NULL;
 
 	/* update pointers within the skb to store the data */
-	skb_reserve(skb, TSNEP_SKB_PAD + TSNEP_RX_INLINE_METADATA_SIZE);
+	skb_reserve(skb, TSNEP_RX_OFFSET + TSNEP_RX_INLINE_METADATA_SIZE);
 	__skb_put(skb, length - ETH_FCS_LEN);
 
 	if (rx->adapter->hwtstamp_config.rx_filter == HWTSTAMP_FILTER_ALL) {
 		struct skb_shared_hwtstamps *hwtstamps = skb_hwtstamps(skb);
 		struct tsnep_rx_inline *rx_inline =
 			(struct tsnep_rx_inline *)(page_address(page) +
-						   TSNEP_SKB_PAD);
+						   TSNEP_RX_OFFSET);
 
 		skb_shinfo(skb)->tx_flags |=
 			SKBTX_HW_TSTAMP_NETDEV;
@@ -1014,11 +1015,11 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,
 		 */
 		dma_rmb();
 
-		prefetch(page_address(entry->page) + TSNEP_SKB_PAD);
+		prefetch(page_address(entry->page) + TSNEP_RX_OFFSET);
 		length = __le32_to_cpu(entry->desc_wb->properties) &
 			 TSNEP_DESC_LENGTH_MASK;
-		dma_sync_single_range_for_cpu(dmadev, entry->dma, TSNEP_SKB_PAD,
-					      length, dma_dir);
+		dma_sync_single_range_for_cpu(dmadev, entry->dma,
+					      TSNEP_RX_OFFSET, length, dma_dir);
 
 		/* RX metadata with timestamps is in front of actual data,
 		 * subtract metadata size to get length of actual data and
Signature · 1 line
2.30.2
#7 lore raw

PATCH v5 7/9 tsnep: Add RX queue info for XDP support

In reply to Gerhard Engleder

Register xdp_rxq_info with page_pool memory model. This is needed for XDP buffer handling.

Additionally fix error path by removing call of tsnep_phy_close() after failed tsnep_phy_open().

---
 drivers/net/ethernet/engleder/tsnep.h      |  2 +
 drivers/net/ethernet/engleder/tsnep_main.c | 74 ++++++++++++++++------
 2 files changed, 58 insertions(+), 18 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +2 -0
index bd0fbddd3a75..c9bfe6ff3add 100644
@@ -125,6 +125,8 @@ struct tsnep_rx {
 	u32 dropped;
 	u32 multicast;
 	u32 alloc_failed;
+
+	struct xdp_rxq_info xdp_rxq;
 };
 
 struct tsnep_queue {
drivers/net/ethernet/engleder/tsnep_main.c +56 -18

121 lines not on this page · raw message

Signature · 1 line
2.30.2
#8 lore raw

PATCH v5 8/9 tsnep: Add XDP RX support

In reply to Gerhard Engleder

If BPF program is set up, then run BPF program for every received frame and execute the selected action.

---
 drivers/net/ethernet/engleder/tsnep.h      |   3 +
 drivers/net/ethernet/engleder/tsnep_main.c | 131 ++++++++++++++++++++-
 2 files changed, 132 insertions(+), 2 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +3 -0
index c9bfe6ff3add..999fa47be4ba 100644
@@ -109,6 +109,7 @@ struct tsnep_rx {
 	struct tsnep_adapter *adapter;
 	void __iomem *addr;
 	int queue_index;
+	int tx_queue_index;
 
 	void *page[TSNEP_RING_PAGE_COUNT];
 	dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
@@ -176,6 +177,8 @@ struct tsnep_adapter {
 	int rxnfc_count;
 	int rxnfc_max;
 
+	struct bpf_prog *xdp_prog;
+
 	int num_tx_queues;
 	struct tsnep_tx tx[TSNEP_MAX_QUEUES];
 	int num_rx_queues;
drivers/net/ethernet/engleder/tsnep_main.c +129 -2

192 lines not on this page · raw message

Signature · 1 line
2.30.2
#9 lore raw

PATCH v5 9/9 tsnep: Support XDP BPF program setup

In reply to Gerhard Engleder

Implement setup of BPF programs for XDP RX path with command XDP_SETUP_PROG of ndo_bpf(). This is the final step for XDP RX path support.

There is no need to reinit the RX queues as they are always prepared for XDP.

Additionally remove $(tsnep-y) from $(tsnep-objs) because it is added automatically.

Test results with A53 1.2GHz:

XDP_DROP (samples/bpf/xdp1)
proto 17: 883878 pkt/s

XDP_TX (samples/bpf/xdp2)
proto 17: 255693 pkt/s

XDP_REDIRECT (samples/bpf/xdpsock)
sock0@eth2:0 rxdrop xdp-drv

                   pps            pkts           1.00
rx                 855,582        5,404,523
tx                 0              0

XDP_REDIRECT (samples/bpf/xdp_redirect)
eth2->eth1 613,267 rx/s 0 err,drop/s 613,272 xmit/s

---
 drivers/net/ethernet/engleder/Makefile     |  2 +-
 drivers/net/ethernet/engleder/tsnep.h      |  3 +++
 drivers/net/ethernet/engleder/tsnep_main.c | 13 +++++++++++++
 drivers/net/ethernet/engleder/tsnep_xdp.c  | 19 +++++++++++++++++++
 4 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/engleder/tsnep_xdp.c
drivers/net/ethernet/engleder/Makefile +1 -1
index b6e3b16623de..b98135f65eb7 100644
@@ -6,5 +6,5 @@
 obj-$(CONFIG_TSNEP) += tsnep.o
 
 tsnep-objs := tsnep_main.o tsnep_ethtool.o tsnep_ptp.o tsnep_tc.o \
-	      tsnep_rxnfc.o $(tsnep-y)
+	      tsnep_rxnfc.o tsnep_xdp.o
 tsnep-$(CONFIG_TSNEP_SELFTESTS) += tsnep_selftests.o
drivers/net/ethernet/engleder/tsnep.h +3 -0
index 999fa47be4ba..058c2bcf31a7 100644
@@ -211,6 +211,9 @@ int tsnep_rxnfc_add_rule(struct tsnep_adapter *adapter,
 int tsnep_rxnfc_del_rule(struct tsnep_adapter *adapter,
 			 struct ethtool_rxnfc *cmd);
 
+int tsnep_xdp_setup_prog(struct tsnep_adapter *adapter, struct bpf_prog *prog,
+			 struct netlink_ext_ack *extack);
+
 #if IS_ENABLED(CONFIG_TSNEP_SELFTESTS)
 int tsnep_ethtool_get_test_count(void);
 void tsnep_ethtool_get_test_strings(u8 *data);
drivers/net/ethernet/engleder/tsnep_main.c +13 -0
index bbf21a6a9e15..5a909c1c11bc 100644
@@ -1614,6 +1614,18 @@ static ktime_t tsnep_netdev_get_tstamp(struct net_device *netdev,
 	return ns_to_ktime(timestamp);
 }
 
+static int tsnep_netdev_bpf(struct net_device *dev, struct netdev_bpf *bpf)
+{
+	struct tsnep_adapter *adapter = netdev_priv(dev);
+
+	switch (bpf->command) {
+	case XDP_SETUP_PROG:
+		return tsnep_xdp_setup_prog(adapter, bpf->prog, bpf->extack);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 static struct tsnep_tx *tsnep_xdp_get_tx(struct tsnep_adapter *adapter, u32 cpu)
 {
 	if (cpu >= TSNEP_MAX_QUEUES)
@@ -1674,6 +1686,7 @@ static const struct net_device_ops tsnep_netdev_ops = {
 	.ndo_set_features = tsnep_netdev_set_features,
 	.ndo_get_tstamp = tsnep_netdev_get_tstamp,
 	.ndo_setup_tc = tsnep_tc_setup,
+	.ndo_bpf = tsnep_netdev_bpf,
 	.ndo_xdp_xmit = tsnep_netdev_xdp_xmit,
 };
 
drivers/net/ethernet/engleder/tsnep_xdp.c new file +19 -0
new file mode 100644
index 000000000000..4d14cb1fd772
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2022 Gerhard Engleder <[email protected]> */
+
+#include <linux/if_vlan.h>
+#include <net/xdp_sock_drv.h>
+
+#include "tsnep.h"
+
+int tsnep_xdp_setup_prog(struct tsnep_adapter *adapter, struct bpf_prog *prog,
+			 struct netlink_ext_ack *extack)
+{
+	struct bpf_prog *old_prog;
+
+	old_prog = xchg(&adapter->xdp_prog, prog);
+	if (old_prog)
+		bpf_prog_put(old_prog);
+
+	return 0;
+}
Signature · 1 line
2.30.2
#10 lore raw
In reply to Gerhard Engleder
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 8 lines · On Mon, 16 Jan 2023 21:24:49 +0100 you wrote:

Implement XDP support for tsnep driver. I tried to follow existing drivers like igb/igc as far as possible. Some prework was already done in previous patch series, so in this series only actual XDP stuff is included.

Thanks for the NetDev 0x14 slides "Add XDP support on a NIC driver".

[...]

Here is the summary with links:
- [net-next,v5,1/9] tsnep: Replace TX spin_lock with __netif_tx_lock

    https://git.kernel.org/netdev/net-next/c/25faa6a4c5ca
  - [net-next,v5,2/9] tsnep: Forward NAPI budget to napi_consume_skb()
    https://git.kernel.org/netdev/net-next/c/0625dff38b17
  - [net-next,v5,3/9] tsnep: Do not print DMA mapping error
    https://git.kernel.org/netdev/net-next/c/95337b938476
  - [net-next,v5,4/9] tsnep: Add XDP TX support
    https://git.kernel.org/netdev/net-next/c/d24bc0bcbbff
  - [net-next,v5,5/9] tsnep: Subtract TSNEP_RX_INLINE_METADATA_SIZE once
    https://git.kernel.org/netdev/net-next/c/59d562aa1983
  - [net-next,v5,6/9] tsnep: Prepare RX buffer for XDP support
    https://git.kernel.org/netdev/net-next/c/cc3e254f9443
  - [net-next,v5,7/9] tsnep: Add RX queue info for XDP support
    https://git.kernel.org/netdev/net-next/c/e77832abd90a
  - [net-next,v5,8/9] tsnep: Add XDP RX support
    https://git.kernel.org/netdev/net-next/c/65b28c810035
  - [net-next,v5,9/9] tsnep: Support XDP BPF program setup
    https://git.kernel.org/netdev/net-next/c/f0f6460f9130

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html