Skip to contentSkip to conversation

stmmac: Add XDP support

PATCH Superseded Ong Boon Leong 2 participants 8 messages Mar 29, 2021

Subsystems (6)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/6 stmmac: intel: set IRQ affinity hint for multi MSI vectors

In reply to Ong Boon Leong

Intel mGBE has independent hardware IRQ resources for TX and RX DMA operation. In preparation to support XDP TX, we add IRQ affinity hint to group both RX and TX queue of the same queue ID to the same CPU.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +7 -0
index 08b4852eed4c..53a24932a192 100644
@@ -810,6 +810,7 @@ static int stmmac_config_multi_msi(struct pci_dev *pdev,
 				   struct plat_stmmacenet_data *plat,
 				   struct stmmac_resources *res)
 {
+	cpumask_t cpu_mask;
 	int ret;
 	int i;
 
@@ -832,12 +833,18 @@ static int stmmac_config_multi_msi(struct pci_dev *pdev,
 	for (i = 0; i < plat->rx_queues_to_use; i++) {
 		res->rx_irq[i] = pci_irq_vector(pdev,
 						plat->msi_rx_base_vec + i * 2);
+		cpumask_clear(&cpu_mask);
+		cpumask_set_cpu(i % num_online_cpus(), &cpu_mask);
+		irq_set_affinity_hint(res->rx_irq[i], &cpu_mask);
 	}
 
 	/* For TX MSI */
 	for (i = 0; i < plat->tx_queues_to_use; i++) {
 		res->tx_irq[i] = pci_irq_vector(pdev,
 						plat->msi_tx_base_vec + i * 2);
+		cpumask_clear(&cpu_mask);
+		cpumask_set_cpu(i % num_online_cpus(), &cpu_mask);
+		irq_set_affinity_hint(res->tx_irq[i], &cpu_mask);
 	}
 
 	if (plat->msi_mac_vec < STMMAC_MSI_VEC_MAX)
Signature · 1 line
2.25.1
#0 lore raw

cover stmmac: Add XDP support

Hi,

This is the patch series to adds XDP support to stmmac driver. Summary of the changes as follow:-

1/6: Add IRQ affinity hint to make RXQ and TXQ to be by default serviced
by the same CPU. This is required for Intel mGbE controller which has independent per DMA channel RX & and TX IRQ resources.

2/6: To add capability to enable/disable Split Header (SPH) dynamically.
Disable SPH for XDP and revert back to the SPH capability of the IP when XDP exits.

3/6: To rearrange TX tail pointer update into common function for reuse
across driver.

4/6: Add basic XDP framework into stmmac driver. This patch only support
XDP_DROP only.

5/6: Add support for XDP_TX.

6/6: Add support for XDP_REDIRECT and ndo_xdp_xmit() implementation.

To send burst traffics to DUT, we use samples/pktgen script called pktgen_sample03_burst_single_flow.sh. Following shows the test steps and results that are obtained using Intel mGbE controller under preempt-rt environment. In such environment, I also have sent a patch that fixes an issue found in xdp_return_frame() earlier:

https://patchwork.kernel.org/project/netdevbpf/list/?series=457139

########################################################################

root@intel-corei7-64:~# ./xdp1 eth0
libbpf: elf: skipping unrecognized data section(16) .eh_frame
libbpf: elf: skipping relo section(17) .rel.eh_frame for section(16) .eh_frame
proto 17:     421844 pkt/s
proto 17:     684396 pkt/s
proto 17:     684332 pkt/s
proto 17:     684074 pkt/s
proto 17:     683837 pkt/s
proto 17:     684357 pkt/s
proto 17:     684371 pkt/s
proto 17:     684419 pkt/s
proto 17:     683996 pkt/s
root@intel-corei7-64:~# ./xdp1 -S eth0
libbpf: elf: skipping unrecognized data section(16) .eh_frame
libbpf: elf: skipping relo section(17) .rel.eh_frame for section(16) .eh_frame
proto 0:          1 pkt/s
proto 17:          1 pkt/s
proto 17:          1 pkt/s
proto 17:      65564 pkt/s
proto 17:     117450 pkt/s
proto 17:     117600 pkt/s
proto 17:     118108 pkt/s
proto 17:     118032 pkt/s
proto 17:     118092 pkt/s
root@intel-corei7-64:~# ./xdp2 eth0
libbpf: elf: skipping unrecognized data section(16) .eh_frame
libbpf: elf: skipping relo section(17) .rel.eh_frame for section(16) .eh_frame
proto 17:          0 pkt/s
proto 17:      49338 pkt/s
proto 17:     714255 pkt/s
proto 17:     714495 pkt/s
proto 17:     710120 pkt/s
proto 17:     712892 pkt/s
proto 17:     712585 pkt/s
proto 17:     713883 pkt/s
root@intel-corei7-64:~# ./xdp2 -S eth0
libbpf: elf: skipping unrecognized data section(16) .eh_frame
libbpf: elf: skipping relo section(17) .rel.eh_frame for section(16) .eh_frame
proto 0:          0 pkt/s
proto 17:      89483 pkt/s
proto 17:      89540 pkt/s
proto 17:      89358 pkt/s
proto 17:      89797 pkt/s
proto 0:          1 pkt/s
proto 17:      89672 pkt/s
root@intel-corei7-64:~# ./xdp_redirect eth0 eth1
input: 7 output: 8
libbpf: elf: skipping unrecognized data section(20) .eh_frame
libbpf: elf: skipping relo section(21) .rel.eh_frame for section(20) .eh_frame
ifindex 8:     143805 pkt/s
ifindex 8:     676900 pkt/s
ifindex 8:     676801 pkt/s
ifindex 8:     677657 pkt/s
ifindex 8:     677916 pkt/s
root@intel-corei7-64:~# ./xdp_redirect -S eth0 eth1
input: 7 output: 8
libbpf: elf: skipping unrecognized data section(20) .eh_frame
libbpf: elf: skipping relo section(21) .rel.eh_frame for section(20) .eh_frame
ifindex 8:          2 pkt/s
ifindex 8:          0 pkt/s
ifindex 8:      33505 pkt/s
ifindex 8:      73536 pkt/s
ifindex 8:      52512 pkt/s
ifindex 8:      97600 pkt/s
ifindex 8:      96928 pkt/s
ifindex 8:      96480 pkt/s
ifindex 8:      96760 pkt/s
ifindex 8:      96949 pkt/s
ifindex 8:      96591 pkt/s
root@intel-corei7-64:~# ./xdp_redirect_cpu --dev eth0 --cpu 0
libbpf: elf: skipping unrecognized data section(39) .eh_frame
libbpf: elf: skipping relo section(40) .rel.eh_frame for section(39) .eh_frame
libbpf: elf: skipping unrecognized data section(20) .eh_frame
libbpf: elf: skipping relo section(21) .rel.eh_frame for section(20) .eh_frame
Add-new CPU:0 as idx:0 qsize:192 prog_fd: 33 (cpus_count:1)

Running XDP/eBPF prog_name:xdp_cpu_map5_lb_hash_ip_pairs

XDP-cpumap      CPU:to  pps            drop-pps    extra-info
XDP-RX          0       667,952        0           0
XDP-RX          total   667,952        0
cpumap-enqueue    0:0   667,952        550,150     7.82       bulk-average
cpumap-enqueue  sum:0   667,952        550,150     7.82       bulk-average
cpumap_kthread  0       117,821        0           0
cpumap_kthread  total   117,821        0           0
redirect_err    total   0              0
xdp_exception   total   0              0

2nd remote XDP/eBPF prog_name: xdp_redirect_dummy

XDP-cpumap      CPU:to  xdp-pass       xdp-drop    xdp-redir
xdp-in-kthread  0       117,822        0           0
xdp-in-kthread  total   117,822        0           0

Running XDP/eBPF prog_name:xdp_cpu_map5_lb_hash_ip_pairs

XDP-cpumap      CPU:to  pps            drop-pps    extra-info
XDP-RX          0       667,871        0           0
XDP-RX          total   667,871        0
cpumap-enqueue    0:0   667,877        550,820     7.82       bulk-average
cpumap-enqueue  sum:0   667,877        550,820     7.82       bulk-average
cpumap_kthread  0       117,041        0           0
cpumap_kthread  total   117,041        0           0
redirect_err    total   0              0
xdp_exception   total   0              0

2nd remote XDP/eBPF prog_name: xdp_redirect_dummy

XDP-cpumap      CPU:to  xdp-pass       xdp-drop    xdp-redir
xdp-in-kthread  0       117,041        0           0
xdp-in-kthread  total   117,041        0           0

Running XDP/eBPF prog_name:xdp_cpu_map5_lb_hash_ip_pairs

XDP-cpumap      CPU:to  pps            drop-pps    extra-info
XDP-RX          0       667,856        0           0
XDP-RX          total   667,856        0
cpumap-enqueue    0:0   667,849        549,672     7.82       bulk-average
cpumap-enqueue  sum:0   667,849        549,672     7.82       bulk-average
cpumap_kthread  0       118,177        0           0
cpumap_kthread  total   118,177        0           0
redirect_err    total   0              0
xdp_exception   total   0              0

2nd remote XDP/eBPF prog_name: xdp_redirect_dummy

XDP-cpumap      CPU:to  xdp-pass       xdp-drop    xdp-redir
xdp-in-kthread  0       118,177        0           0
xdp-in-kthread  total   118,177        0           0

########################################################################

As stmmac driver is using page_pool mechanism, I waited > 1min after each of above apps is terminated to make sure there is no stalled pool warning prints on the terminal, and I found none which looks good on Intel mGbE platform.

It will be great if community help tes out these patch series on your platform and provide me feedback.

Thank you very much,
Boon Leong

Ong Boon Leong (6):
stmmac: intel: set IRQ affinity hint for multi MSI vectors
net: stmmac: make SPH enable/disable to be configurable
net: stmmac: arrange Tx tail pointer update to
stmmac_flush_tx_descriptors
net: stmmac: Add initial XDP support
net: stmmac: Add support for XDP_TX action
net: stmmac: Add support for XDP_REDIRECT action

 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c |   7 +
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  35 +-
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 502 +++++++++++++++---
 .../net/ethernet/stmicro/stmmac/stmmac_xdp.c  |  40 ++
 .../net/ethernet/stmicro/stmmac/stmmac_xdp.h  |  12 +
 6 files changed, 523 insertions(+), 74 deletions(-)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/6 net: stmmac: make SPH enable/disable to be configurable

SPH functionality splits header and payload according to split mode and offsef fields (SPLM and SPLOFST). It is beneficials for Linux network stack RX processing however it adds a lot of complexity in XDP processing.

So, this patch makes the split-header (SPH) capability of the controller is stored in "priv->sph_cap" and the enabling/disabling of SPH is decided by "priv->sph".

This is to prepare initial XDP enabling for stmmac to disable the use of SPH whenever XDP is enabled.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h      |  1 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -0
index 9966f6f10905..e293423f98c3 100644
@@ -160,6 +160,7 @@ struct stmmac_priv {
 	bool tx_path_in_lpi_mode;
 	bool tso;
 	int sph;
+	int sph_cap;
 	u32 sarc_type;
 
 	unsigned int dma_buf_sz;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -5
index d34388b1ffcc..ace3c3835a9f 100644
@@ -2858,6 +2858,7 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
 	struct stmmac_priv *priv = netdev_priv(dev);
 	u32 rx_cnt = priv->plat->rx_queues_to_use;
 	u32 tx_cnt = priv->plat->tx_queues_to_use;
+	bool sph_en;
 	u32 chan;
 	int ret;
 
@@ -2952,10 +2953,10 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
 	}
 
 	/* Enable Split Header */
-	if (priv->sph && priv->hw->rx_csum) {
-		for (chan = 0; chan < rx_cnt; chan++)
-			stmmac_enable_sph(priv, priv->ioaddr, 1, chan);
-	}
+	sph_en = (priv->hw->rx_csum > 0) && priv->sph;
+	for (chan = 0; chan < rx_cnt; chan++)
+		stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan);
+
 
 	/* VLAN Tag Insertion */
 	if (priv->dma_cap.vlins)
@@ -5697,7 +5698,8 @@ int stmmac_dvr_probe(struct device *device,
 
 	if (priv->dma_cap.sphen) {
 		ndev->hw_features |= NETIF_F_GRO;
-		priv->sph = true;
+		priv->sph_cap = true;
+		priv->sph = priv->sph_cap;
 		dev_info(priv->device, "SPH feature enabled\n");
 	}
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/6 net: stmmac: arrange Tx tail pointer update to stmmac_flush_tx_descriptors

In reply to Ong Boon Leong

This patch organizes TX tail pointer update into a new function called stmmac_flush_tx_descriptors() so that we can reuse it in stmmac_xmit(), stmmac_tso_xmit() and up-coming XDP implementation.

---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 52 +++++++++----------
 1 file changed, 24 insertions(+), 28 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +24 -28
index ace3c3835a9f..18578239b438 100644
@@ -3507,6 +3507,28 @@ static void stmmac_tso_allocator(struct stmmac_priv *priv, dma_addr_t des,
 	}
 }
 
+static void stmmac_flush_tx_descriptors(struct stmmac_priv *priv, int queue)
+{
+	struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue];
+	int desc_size;
+
+	if (likely(priv->extend_desc))
+		desc_size = sizeof(struct dma_extended_desc);
+	else if (tx_q->tbs & STMMAC_TBS_AVAIL)
+		desc_size = sizeof(struct dma_edesc);
+	else
+		desc_size = sizeof(struct dma_desc);
+
+	/* The own bit must be the latest setting done when prepare the
+	 * descriptor and then barrier is needed to make sure that
+	 * all is coherent before granting the DMA engine.
+	 */
+	wmb();
+
+	tx_q->tx_tail_addr = tx_q->dma_tx_phy + (tx_q->cur_tx * desc_size);
+	stmmac_set_tx_tail_ptr(priv, priv->ioaddr, tx_q->tx_tail_addr, queue);
+}
+
 /**
  *  stmmac_tso_xmit - Tx entry point of the driver for oversized frames (TSO)
  *  @skb : the socket buffer
@@ -3739,12 +3761,6 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
 		stmmac_set_tx_owner(priv, mss_desc);
 	}
 
-	/* The own bit must be the latest setting done when prepare the
-	 * descriptor and then barrier is needed to make sure that
-	 * all is coherent before granting the DMA engine.
-	 */
-	wmb();
-
 	if (netif_msg_pktdata(priv)) {
 		pr_info("%s: curr=%d dirty=%d f=%d, e=%d, f_p=%p, nfrags %d\n",
 			__func__, tx_q->cur_tx, tx_q->dirty_tx, first_entry,
@@ -3755,13 +3771,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
 
-	if (tx_q->tbs & STMMAC_TBS_AVAIL)
-		desc_size = sizeof(struct dma_edesc);
-	else
-		desc_size = sizeof(struct dma_desc);
-
-	tx_q->tx_tail_addr = tx_q->dma_tx_phy + (tx_q->cur_tx * desc_size);
-	stmmac_set_tx_tail_ptr(priv, priv->ioaddr, tx_q->tx_tail_addr, queue);
+	stmmac_flush_tx_descriptors(priv, queue);
 	stmmac_tx_timer_arm(priv, queue);
 
 	return NETDEV_TX_OK;
@@ -3996,25 +4006,11 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	stmmac_set_tx_owner(priv, first);
 
-	/* The own bit must be the latest setting done when prepare the
-	 * descriptor and then barrier is needed to make sure that
-	 * all is coherent before granting the DMA engine.
-	 */
-	wmb();
-
 	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
 
 	stmmac_enable_dma_transmission(priv, priv->ioaddr);
 
-	if (likely(priv->extend_desc))
-		desc_size = sizeof(struct dma_extended_desc);
-	else if (tx_q->tbs & STMMAC_TBS_AVAIL)
-		desc_size = sizeof(struct dma_edesc);
-	else
-		desc_size = sizeof(struct dma_desc);
-
-	tx_q->tx_tail_addr = tx_q->dma_tx_phy + (tx_q->cur_tx * desc_size);
-	stmmac_set_tx_tail_ptr(priv, priv->ioaddr, tx_q->tx_tail_addr, queue);
+	stmmac_flush_tx_descriptors(priv, queue);
 	stmmac_tx_timer_arm(priv, queue);
 
 	return NETDEV_TX_OK;
Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/6 net: stmmac: Add initial XDP support

In reply to Ong Boon Leong

This patch adds the initial XDP support to stmmac driver. It supports XDP_PASS, XDP_DROP and XDP_ABORTED actions. Upcoming patches will add support for XDP_TX and XDP_REDIRECT.

To support XDP headroom, this patch adds page_offset into RX buffer and change the dma_sync_single_for_device|cpu(). The DMA address used for RX operation are changed to take into page_offset too. As page_pool can handle dma_sync_single_for_device() on behalf of driver with PP_FLAG_DMA_SYNC_DEV flag, we skip doing that in stmmac driver.

Current stmmac driver supports split header support (SPH) in RX but the flexibility of splitting header and payload at different position makes it very complex to be supported for XDP processing. In addition, jumbo frame is not supported in XDP to keep the initial codes simple.

This patch has been tested with the sample app "xdp1" located in samples/bpf directory for both SKB and Native (XDP) mode. The burst traffic generated using pktgen_sample03_burst_single_flow.sh in samples/pktgen directory.

---
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  21 ++-
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 146 +++++++++++++++---
 .../net/ethernet/stmicro/stmmac/stmmac_xdp.c  |  40 +++++
 .../net/ethernet/stmicro/stmmac/stmmac_xdp.h  |  12 ++
 5 files changed, 195 insertions(+), 25 deletions(-)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
index 366740ab9c5a..f2e478b884b0 100644
@@ -6,6 +6,7 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o	\
 	      mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o dwmac4_descs.o	\
 	      dwmac4_dma.o dwmac4_lib.o dwmac4_core.o dwmac5.o hwif.o \
 	      stmmac_tc.o dwxgmac2_core.o dwxgmac2_dma.o dwxgmac2_descs.o \
+	      stmmac_xdp.o \
 	      $(stmmac-y)
 
 stmmac-$(CONFIG_STMMAC_SELFTESTS) += stmmac_selftests.o
drivers/net/ethernet/stmicro/stmmac/stmmac.h +20 -1
index e293423f98c3..e72224c8fbac 100644
@@ -68,8 +68,9 @@ struct stmmac_tx_queue {
 
 struct stmmac_rx_buffer {
 	struct page *page;
-	struct page *sec_page;
 	dma_addr_t addr;
+	__u32 page_offset;
+	struct page *sec_page;
 	dma_addr_t sec_addr;
 };
 
@@ -269,6 +270,9 @@ struct stmmac_priv {
 
 	/* Receive Side Scaling */
 	struct stmmac_rss rss;
+
+	/* XDP BPF Program */
+	struct bpf_prog *xdp_prog;
 };
 
 enum stmmac_state {
@@ -285,6 +289,8 @@ void stmmac_set_ethtool_ops(struct net_device *netdev);
 
 void stmmac_ptp_register(struct stmmac_priv *priv);
 void stmmac_ptp_unregister(struct stmmac_priv *priv);
+int stmmac_open(struct net_device *dev);
+int stmmac_release(struct net_device *dev);
 int stmmac_resume(struct device *dev);
 int stmmac_suspend(struct device *dev);
 int stmmac_dvr_remove(struct device *dev);
@@ -298,6 +304,19 @@ int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
 int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);
 void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable);
 
+static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv)
+{
+	return !!priv->xdp_prog;
+}
+
+static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
+{
+	if (stmmac_xdp_is_enabled(priv))
+		return XDP_PACKET_HEADROOM;
+
+	return 0;
+}
+
 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
 void stmmac_selftest_run(struct net_device *dev,
 			 struct ethtool_test *etest, u64 *buf);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +122 -24

297 lines not on this page · raw message

drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c new file +40 -0
new file mode 100644
index 000000000000..bf38d231860b
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2021, Intel Corporation. */
+
+#include "stmmac.h"
+#include "stmmac_xdp.h"
+
+int stmmac_xdp_set_prog(struct stmmac_priv *priv, struct bpf_prog *prog,
+			struct netlink_ext_ack *extack)
+{
+	struct net_device *dev = priv->dev;
+	struct bpf_prog *old_prog;
+	bool need_update;
+	bool if_running;
+
+	if_running = netif_running(dev);
+
+	if (prog && 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;
+	}
+
+	need_update = !!priv->xdp_prog != !!prog;
+	if (if_running && need_update)
+		stmmac_release(dev);
+
+	old_prog = xchg(&priv->xdp_prog, prog);
+	if (old_prog)
+		bpf_prog_put(old_prog);
+
+	/* Disable RX SPH for XDP operation */
+	priv->sph = priv->sph_cap && !stmmac_xdp_is_enabled(priv);
+
+	if (if_running && need_update)
+		stmmac_open(dev);
+
+	return 0;
+}
drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h new file +12 -0
new file mode 100644
index 000000000000..93948569d92a
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2021, Intel Corporation. */
+
+#ifndef _STMMAC_XDP_H_
+#define _STMMAC_XDP_H_
+
+#define STMMAC_MAX_RX_BUF_SIZE(num)	(((num) * PAGE_SIZE) - XDP_PACKET_HEADROOM)
+
+int stmmac_xdp_set_prog(struct stmmac_priv *priv, struct bpf_prog *prog,
+			struct netlink_ext_ack *extack);
+
+#endif /* _STMMAC_XDP_H_ */
Signature · 1 line
2.25.1
#6 lore raw

PATCH 5/6 net: stmmac: Add support for XDP_TX action

In reply to Ong Boon Leong

This patch adds support for XDP_TX action which enables XDP program to transmit back received frames.

This patch has been tested with the "xdp2" app located in samples/bpf dir. The DUT receives burst traffic packet generated using pktgen script 'pktgen_sample03_burst_single_flow.sh'.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  12 +-
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 220 ++++++++++++++++--
 2 files changed, 214 insertions(+), 18 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +11 -1
index e72224c8fbac..a93e22a6be59 100644
@@ -36,12 +36,18 @@ struct stmmac_resources {
 	int tx_irq[MTL_MAX_TX_QUEUES];
 };
 
+enum stmmac_txbuf_type {
+	STMMAC_TXBUF_T_SKB,
+	STMMAC_TXBUF_T_XDP_TX,
+};
+
 struct stmmac_tx_info {
 	dma_addr_t buf;
 	bool map_as_page;
 	unsigned len;
 	bool last_segment;
 	bool is_jumbo;
+	enum stmmac_txbuf_type buf_type;
 };
 
 #define STMMAC_TBS_AVAIL	BIT(0)
@@ -57,7 +63,10 @@ struct stmmac_tx_queue {
 	struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
 	struct dma_edesc *dma_entx;
 	struct dma_desc *dma_tx;
-	struct sk_buff **tx_skbuff;
+	union {
+		struct sk_buff **tx_skbuff;
+		struct xdp_frame **xdpf;
+	};
 	struct stmmac_tx_info *tx_skbuff_dma;
 	unsigned int cur_tx;
 	unsigned int dirty_tx;
@@ -77,6 +86,7 @@ struct stmmac_rx_buffer {
 struct stmmac_rx_queue {
 	u32 rx_count_frames;
 	u32 queue_index;
+	struct xdp_rxq_info xdp_rxq;
 	struct page_pool *page_pool;
 	struct stmmac_rx_buffer *buf_pool;
 	struct stmmac_priv *priv_data;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +203 -17

378 lines not on this page · raw message

Signature · 1 line
2.25.1
#7 lore raw

PATCH 6/6 net: stmmac: Add support for XDP_REDIRECT action

In reply to Ong Boon Leong

This patch adds the support of XDP_REDIRECT to another remote cpu for further action. It also implements ndo_xdp_xmit ops, enabling the driver to transmit packets forwarded to it by XDP program running on another interface.

This patch has been tested using "xdp_redirect_cpu" for XDP_REDIRECT
+ drop testing. It also been tested with "xdp_redirect" sample app which can be used to exercise ndo_xdp_xmit ops. The burst traffics are generated using pktgen_sample03_burst_single_flow.sh in samples/pktgen directory.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  1 +
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 96 +++++++++++++++++--
 2 files changed, 87 insertions(+), 10 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -0
index a93e22a6be59..c49debb62b05 100644
@@ -39,6 +39,7 @@ struct stmmac_resources {
 enum stmmac_txbuf_type {
 	STMMAC_TXBUF_T_SKB,
 	STMMAC_TXBUF_T_XDP_TX,
+	STMMAC_TXBUF_T_XDP_NDO,
 };
 
 struct stmmac_tx_info {
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +86 -10

177 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH net-next 4/6] net: stmmac: Add initial XDP support

In reply to Ong Boon Leong
Thank you for the patch! Perhaps something to improve:

Hi Ong,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Ong-Boon-Leong/stmmac-Add-XDP-support/20210329-213915
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9d0365448b5b954bba1b551ade5b273d629446bb
config: arc-allyesconfig (attached as .config)
compiler: arceb-elf-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/2eb2e788a389bf190a004f6416ea2bfd57783f4a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ong-Boon-Leong/stmmac-Add-XDP-support/20210329-213915 git checkout 2eb2e788a389bf190a004f6416ea2bfd57783f4a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c: In function 'stmmac_rx_refill':

>> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:4067:6: warning: variable 'len' set but not used [-Wunused-but-set-variable]
    4067 |  int len, dirty = stmmac_rx_dirty(priv, queue);
         |      ^~~

vim +/len +4067 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

b93819854d6e79 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Vince Bridgers     2014-01-14  4056  
32ceabcad3c8ab drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-04-08  4057  /**
732fdf0e5253e9 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2014-11-18  4058   * stmmac_rx_refill - refill used skb preallocated buffers
32ceabcad3c8ab drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-04-08  4059   * @priv: driver private structure
54139cf3bb33fa drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joao Pinto         2017-04-06  4060   * @queue: RX queue index
32ceabcad3c8ab drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-04-08  4061   * Description : this is to reallocate the skb for the reception process
32ceabcad3c8ab drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-04-08  4062   * that is based on zero-copy.
32ceabcad3c8ab drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-04-08  4063   */
54139cf3bb33fa drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joao Pinto         2017-04-06  4064  static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
47dd7a540b8a0c drivers/net/stmmac/stmmac_main.c                  Giuseppe Cavallaro 2009-10-14  4065  {
54139cf3bb33fa drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joao Pinto         2017-04-06  4066  	struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];
3caa61c2087534 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-30 @4067  	int len, dirty = stmmac_rx_dirty(priv, queue);
54139cf3bb33fa drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joao Pinto         2017-04-06  4068  	unsigned int entry = rx_q->dirty_rx;
54139cf3bb33fa drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joao Pinto         2017-04-06  4069  
3caa61c2087534 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-30  4070  	len = DIV_ROUND_UP(priv->dma_buf_sz, PAGE_SIZE) * PAGE_SIZE;
3caa61c2087534 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-30  4071  
e3ad57c96715df drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe Cavallaro 2016-02-29  4072  	while (dirty-- > 0) {
2af6106ae94965 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4073  		struct stmmac_rx_buffer *buf = &rx_q->buf_pool[entry];
c24602ef866493 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-03-26  4074  		struct dma_desc *p;
d429b66e2ebcec drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4075  		bool use_rx_wd;
c24602ef866493 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-03-26  4076  
c24602ef866493 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-03-26  4077  		if (priv->extend_desc)
54139cf3bb33fa drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joao Pinto         2017-04-06  4078  			p = (struct dma_desc *)(rx_q->dma_erx + entry);
c24602ef866493 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-03-26  4079  		else
54139cf3bb33fa drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joao Pinto         2017-04-06  4080  			p = rx_q->dma_rx + entry;
c24602ef866493 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2013-03-26  4081  
2af6106ae94965 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4082  		if (!buf->page) {
2af6106ae94965 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4083  			buf->page = page_pool_dev_alloc_pages(rx_q->page_pool);
2af6106ae94965 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4084  			if (!buf->page)
362b37be01edc7 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2014-08-27  4085  				break;
362b37be01edc7 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2014-08-27  4086  		}
286a837217204b drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2011-10-18  4087  
67afd6d1cfdf0d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-08-17  4088  		if (priv->sph && !buf->sec_page) {
67afd6d1cfdf0d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-08-17  4089  			buf->sec_page = page_pool_dev_alloc_pages(rx_q->page_pool);
67afd6d1cfdf0d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-08-17  4090  			if (!buf->sec_page)
67afd6d1cfdf0d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-08-17  4091  				break;
67afd6d1cfdf0d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-08-17  4092  
67afd6d1cfdf0d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-08-17  4093  			buf->sec_addr = page_pool_get_dma_addr(buf->sec_page);
67afd6d1cfdf0d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-08-17  4094  		}
67afd6d1cfdf0d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-08-17  4095  
2eb2e788a389bf drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Ong Boon Leong     2021-03-29  4096  		buf->addr = page_pool_get_dma_addr(buf->page) + buf->page_offset;
3caa61c2087534 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-30  4097  
2af6106ae94965 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4098  		stmmac_set_desc_addr(priv, p, buf->addr);
396e13e11577b6 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joakim Zhang       2021-02-25  4099  		if (priv->sph)
396e13e11577b6 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joakim Zhang       2021-02-25  4100  			stmmac_set_desc_sec_addr(priv, p, buf->sec_addr, true);
396e13e11577b6 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joakim Zhang       2021-02-25  4101  		else
396e13e11577b6 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joakim Zhang       2021-02-25  4102  			stmmac_set_desc_sec_addr(priv, p, buf->sec_addr, false);
2c520b1c9cfa7d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2018-04-16  4103  		stmmac_refill_desc3(priv, rx_q, p);
286a837217204b drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe CAVALLARO 2011-10-18  4104  
d429b66e2ebcec drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4105  		rx_q->rx_count_frames++;
db2f2842e6f560 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Ong Boon Leong     2021-03-17  4106  		rx_q->rx_count_frames += priv->rx_coal_frames[queue];
db2f2842e6f560 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Ong Boon Leong     2021-03-17  4107  		if (rx_q->rx_count_frames > priv->rx_coal_frames[queue])
6fa9d691b91ac6 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-09-10  4108  			rx_q->rx_count_frames = 0;
09146abebc788a drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-11-14  4109  
db2f2842e6f560 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Ong Boon Leong     2021-03-17  4110  		use_rx_wd = !priv->rx_coal_frames[queue];
09146abebc788a drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-11-14  4111  		use_rx_wd |= rx_q->rx_count_frames > 0;
09146abebc788a drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-11-14  4112  		if (!priv->use_riwt)
09146abebc788a drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-11-14  4113  			use_rx_wd = false;
d429b66e2ebcec drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4114  
ad688cdbb07683 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Pavel Machek       2016-12-18  4115  		dma_wmb();
2af6106ae94965 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-07-09  4116  		stmmac_set_rx_owner(priv, p, use_rx_wd);
e3ad57c96715df drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Giuseppe Cavallaro 2016-02-29  4117  
aa042f60e4961d drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Song, Yoong Siang  2020-09-16  4118  		entry = STMMAC_GET_ENTRY(entry, priv->dma_rx_size);
47dd7a540b8a0c drivers/net/stmmac/stmmac_main.c                  Giuseppe Cavallaro 2009-10-14  4119  	}
54139cf3bb33fa drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Joao Pinto         2017-04-06  4120  	rx_q->dirty_rx = entry;
858a31ffc3d97a drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-06-28  4121  	rx_q->rx_tail_addr = rx_q->dma_rx_phy +
858a31ffc3d97a drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Jose Abreu         2019-06-28  4122  			    (rx_q->dirty_rx * sizeof(struct dma_desc));
4523a561152670 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c Biao Huang         2019-05-24  4123  	stmmac_set_rx_tail_ptr(priv, priv->ioaddr, rx_q->rx_tail_addr, queue);
47dd7a540b8a0c drivers/net/stmmac/stmmac_main.c                  Giuseppe Cavallaro 2009-10-14  4124  }
47dd7a540b8a0c drivers/net/stmmac/stmmac_main.c                  Giuseppe Cavallaro 2009-10-14  4125  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org