Skip to contentSkip to conversation

net: ethernet: zte: zx279128s: offload flows to and from WLAN interfaces

RFC PATCH New Agustin Santiago Isasmendi 1 participant 6 messages Nov 11

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

cover net: ethernet: zte: zx279128s: offload flows to and from WLAN interfaces

Hi,

This series lets the ZX279128S switch driver offload flows whose ingress or egress is a mac80211 AP interface, so that WiFi <-> WAN NAT traffic no longer goes through the CPU's forwarding path. It is based on Navid Ghahremani's v2 platform series, which adds the SoC and the driver:

https://lore.kernel.org/r/[email protected]

The switch fabric has a second DMA engine (a ring pair the vendor firmware uses for exactly this) and 16 "WLAN logical ports" that a classifier entry can name as ingress or egress. Patch 3 adds the ring and the ports; patch 4 binds a mac80211 interface to a port on first use and accepts flows from the flowtable in both directions; patch 5 adds debugfs testing aids. Patches 1 and 2 describe the engine's interrupt. The WLAN drivers are not touched: the frames the fabric forwards are handed to the interface's normal transmit path, and the frames of offloaded flows are picked up on the interface's ingress hook and injected into the ring. Any mac80211 driver works.

This is not a WED-like path: the SoC has no block that chains the two DMA engines, so the CPU still runs the WLAN driver's own transmit and receive paths for these frames and moves the buffers between the rings (no copies on the forwarded path). What it no longer does is the bridge, routing, conntrack and NAT work, which is where the CPU time
went: CPU0 drops from 54 % to 13-25 % at the rates below. This is also how the vendor firmware uses the engine.

Sent as RFC because:

- the base series is not merged yet, so this cannot be applied as is;
- a mac80211 AP interface cannot be put in an offload-enabled flowtable today, since mac80211 answers -EOPNOTSUPP to TC_SETUP_FT and nf_tables rejects the device. This series was tested with Felix Fietkau's OpenWrt patch that ignores -EOPNOTSUPP there (target/linux/generic/pending-6.18/ 701-netfilter-nf_tables-ignore-EOPNOTSUPP-on-flowtable-d.patch). Felix, do you plan to send that upstream? Without it, or something like it, this feature cannot be enabled on mainline;
- design: binding a WLAN interface to a switch port from the ethernet driver, through the interface's regular paths, keeps the WLAN drivers out of it. I would like to know whether that is acceptable or whether this should go through something closer to the mediatek WED model.

The SoC has an unrelated problem under WiFi traffic: a PCIe read on one CPU deadlocks against L2C-310 maintenance on the other, discussed in

https://lore.kernel.org/r/[email protected]

This series was tested with both workarounds under discussion (a lock around the PCIe reads, and the L2 cache off through the device tree) with the same results.

Results on a ZTE ZXHN H3600 (MT7915 as AP, a phone as client, flowtable with lan, wan and the AP interface, NAT on wan):

  WAN -> WiFi download     393 Mbps offloaded, 109 Mbps on the CPU path
  WiFi -> WAN upload       186 Mbps (capped by the upload server), 60
  30 min soak              111 transfers, none failed, ring counters

consistent, kernel log clean
cold / warm boot gate 17/17 and 5/5 boots, offloaded traffic on
each, no hang

IPv6 flows are not offloaded, as in the base driver. The register sequence and descriptor layout were reverse engineered from the vendor's GPL kernel. Builds without warnings with W=1 (board config and multi_v7_defconfig); checkpatch --strict, dt_binding_check and dtbs_check are clean.

Agustin Santiago Isasmendi (5):
dt-bindings: net: zte,zx279128s-gmac: add the WLAN DMA interrupt
ARM: dts: zte: zx279128s: add the WLAN DMA interrupt
net: ethernet: zte: zx279128s: WLAN DMA ring and logical ports
net: ethernet: zte: zx279128s: offload flows to and from WLAN ports
net: ethernet: zte: zx279128s: debugfs knobs for the WLAN ring

 .../bindings/net/zte,zx279128s-gmac.yaml      |  20 +-
 arch/arm/boot/dts/zte/zx279128s.dtsi          |   4 +-
 drivers/net/ethernet/zte/Kconfig              |   5 +-
 drivers/net/ethernet/zte/Makefile             |   3 +-
 drivers/net/ethernet/zte/zx279128s-eth.h      | 124 ++-
 drivers/net/ethernet/zte/zx279128s-main.c     |  18 +-
 drivers/net/ethernet/zte/zx279128s-ppe.c      |  92 +-
 drivers/net/ethernet/zte/zx279128s-wlan.c     | 874 ++++++++++++++++++
 8 files changed, 1114 insertions(+), 26 deletions(-)
 create mode 100644 drivers/net/ethernet/zte/zx279128s-wlan.c

base-commit: 96b4b72978e9fcfdd74f809c159f26813995631b

Signature · 1 line
2.30.2
#1 lore raw

RFC PATCH 1/5 dt-bindings: net: zte,zx279128s-gmac: add the WLAN DMA interrupt

Besides the traffic manager's interrupt the switch has a second DMA engine with its own interrupt line, the ring pair the vendor firmware uses to exchange frames of offloaded flows with the WLAN drivers. Describe it as an optional second interrupt, named "wlan".

---
 .../bindings/net/zte,zx279128s-gmac.yaml      | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/net/zte,zx279128s-gmac.yaml +16 -4
index fcbdbafa766d..b9a419e5d44a 100644
@@ -23,9 +23,19 @@ properties:
     maxItems: 1
 
   interrupts:
-    maxItems: 1
-    description: The traffic manager's interrupt, which signals frames
-      received for the CPU.
+    minItems: 1
+    items:
+      - description: The traffic manager's interrupt, which signals frames
+          received for the CPU.
+      - description: The WLAN DMA ring's interrupt, through which the
+          switch exchanges frames of offloaded flows with the WLAN
+          interfaces.
+
+  interrupt-names:
+    minItems: 1
+    items:
+      - const: tm
+      - const: wlan
 
   ethernet-ports:
     type: object
@@ -98,7 +108,9 @@ examples:
     ethernet@92000000 {
         compatible = "zte,zx279128s-gmac";
         reg = <0x92000000 0x400000>;
-        interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>;
+        interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-names = "tm", "wlan";
 
         ethernet-ports {
             #address-cells = <1>;
Signature · 1 line
2.30.2
#2 lore raw

RFC PATCH 2/5 ARM: dts: zte: zx279128s: add the WLAN DMA interrupt

In reply to Agustin Santiago Isasmendi

The switch's second DMA engine, the ring pair the vendor firmware uses for offloaded WLAN flows, has its own interrupt line, GIC SPI 38. Add it to the ethernet node as the optional "wlan" interrupt.

---
 arch/arm/boot/dts/zte/zx279128s.dtsi | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/boot/dts/zte/zx279128s.dtsi +3 -1
index 8896a8b06725..9ddc5ee02687 100644
@@ -201,7 +201,9 @@ pcie1: pcie@f100000 {
 		gmac: ethernet@92000000 {
 			compatible = "zte,zx279128s-gmac";
 			reg = <0x92000000 0x400000>;
-			interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>;
+			interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "tm", "wlan";
 			status = "disabled";
 
 			ethernet-ports {
Signature · 1 line
2.30.2
#3 lore raw

RFC PATCH 3/5 net: ethernet: zte: zx279128s: WLAN DMA ring and logical ports

In reply to Agustin Santiago Isasmendi

The switch fabric has a second DMA engine ("IDM" in the vendor code):
one RX and one TX ring of 8-byte descriptors. A frame written to the TX ring enters the fabric on port 6 or 7 (descriptor bit 31) as if sent by the station the 3-bit "ssid" field names, and a classifier entry whose egress is such a WLAN logical port (0x10 | port << 3 | ssid) makes the fabric write the rewritten frame to the RX ring with that ssid. The vendor firmware uses this to forward WLAN traffic without the CPU.

Add the ring (coherent descriptor area, buffer pool, NAPI, the vendor's register sequence) behind the optional "wlan" interrupt, and the 16 logical ports as slots a mac80211 AP interface can be bound to:

- frames the fabric forwards to a bound port are handed to the interface for transmission through its ordinary queueing path, after the IPv4 header checksum is recomputed (the packet modifier decrements the TTL, and only the MAC egress pipeline repairs the checksum, which this path does not pass);
- a netfilter ingress hook on the bound interface injects the frames of flows the fabric holds for that port into the TX ring, re-segmenting mac80211's GRO superframes to wire size first; SYN, FIN and RST stay on the CPU so that conntrack sees connections open and close;
- an injected frame the classifier does not forward comes back on the switch RX ring with the WLAN port as ingress (0x10-0x1f instead of a switch port); it is delivered as received by the interface, marked so that the hook lets it pass.

Nothing binds a port yet: the flow offload code does that in the next change. The WLAN drivers are not involved, only the interfaces' normal transmit and receive paths, so any mac80211 driver works. Without the "wlan" interrupt in the device tree the driver behaves as before.

Register sequence and descriptor layout reverse engineered from the vendor's pon_npp_idm_init() / idm_net_tx() / idm_net_poll() and verified on a ZTE ZXHN H3600 (two MT7915 radios on PCIe).

---
 drivers/net/ethernet/zte/Kconfig          |   5 +-
 drivers/net/ethernet/zte/Makefile         |   3 +-
 drivers/net/ethernet/zte/zx279128s-eth.h  | 123 +++-
 drivers/net/ethernet/zte/zx279128s-main.c |  18 +-
 drivers/net/ethernet/zte/zx279128s-wlan.c | 837 ++++++++++++++++++++++
 5 files changed, 982 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/ethernet/zte/zx279128s-wlan.c
drivers/net/ethernet/zte/Kconfig +4 -1
index 20df75486f81..b9a4a8520fc7 100644
@@ -22,12 +22,15 @@ config ZX279128S_ETH
 	depends on ARCH_ZTE || COMPILE_TEST
 	depends on OF
 	depends on BRIDGE=y || BRIDGE=n
+	depends on NETFILTER
 	select NET_SWITCHDEV
 	select PHYLINK
 	help
 	  This driver supports the five-port gigabit switch of the ZTE
 	  zx279128s SoC and the DMA engine that connects it to the CPU.
 	  Each switch port becomes its own network interface, such as the
-	  four LAN ports and the WAN port of the ZTE ZXHN H3600.
+	  four LAN ports and the WAN port of the ZTE ZXHN H3600.  Flows
+	  to and from the AP interfaces of the SoC's PCIe WLAN cards can
+	  be offloaded through the switch's WLAN DMA ring.
 
 endif # NET_VENDOR_ZTE
drivers/net/ethernet/zte/Makefile +2 -1
index 09b4f6558d2f..88eddc43ae18 100644
@@ -6,4 +6,5 @@
 obj-$(CONFIG_DINGHAI) += dinghai/
 
 obj-$(CONFIG_ZX279128S_ETH) += zx279128s-eth.o
-zx279128s-eth-y := zx279128s-main.o zx279128s-ppe.o zx279128s-switch.o
+zx279128s-eth-y := zx279128s-main.o zx279128s-ppe.o zx279128s-switch.o \
+		   zx279128s-wlan.o
drivers/net/ethernet/zte/zx279128s-eth.h +122 -1

162 lines not on this page · raw message

drivers/net/ethernet/zte/zx279128s-main.c +17 -1
index 45a0dc13639e..a0dcb4d7011a 100644
@@ -804,7 +804,17 @@ static int zx_eth_rx(struct zx_eth_adapter *adapter, int budget)
 			/* Deliver to the netdev of the ingress port */
 			dest_dev = port < ZX_NUM_PORTS ? adapter->ports[port] : NULL;
 
-			skb = napi_alloc_skb(&adapter->napi, len);
+			/* A frame injected for a WLAN logical port (ingress
+			 * 0x10-0x1f) that the classifier did not forward.
+			 */
+			if (port >= 15) {
+				zx_wlan_trap_rx(adapter, port - 15,
+						adapter->buffer_pool +
+						bp * ZX_BUF_SIZE + 16, len);
+				skb = NULL;
+			} else {
+				skb = napi_alloc_skb(&adapter->napi, len);
+			}
 			if (skb && dest_dev && (dest_dev->flags & IFF_UP)) {
 				dma_rmb();
 				memcpy(skb_put(skb, len), adapter->buffer_pool +
@@ -1197,6 +1207,7 @@ static void zx_eth_debugfs_init(struct zx_eth_adapter *adapter)
 
 	debugfs_create_devm_seqfile(adapter->dev, "dma_state", dir,
 				    zx_eth_dma_state_show);
+	zx_wlan_debugfs_init(adapter, dir);
 }
 
 static int zx_eth_probe(struct platform_device *pdev)
@@ -1419,6 +1430,10 @@ static int zx_eth_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, adapter);
 
+	ret = zx_wlan_init(adapter, pdev);
+	if (ret)
+		dev_warn(dev, "no WLAN offload: %d\n", ret);
+
 	zx_sw_init(adapter);
 	schedule_delayed_work(&adapter->mib_work, ZX_MIB_INTERVAL);
 
@@ -1465,6 +1480,7 @@ static void zx_eth_shutdown(struct platform_device *pdev)
 		return;
 
 	zx_sw_fini(adapter);
+	zx_wlan_fini(adapter);
 
 	rtnl_lock();
 	for (i = 0; i < ZX_NUM_PORTS; i++) {
drivers/net/ethernet/zte/zx279128s-wlan.c new file +837 -0

837 lines not on this page · raw message

Signature · 1 line
2.30.2
#4 lore raw

RFC PATCH 4/5 net: ethernet: zte: zx279128s: offload flows to and from WLAN ports

In reply to Agustin Santiago Isasmendi

Accept flows whose egress or ingress is a mac80211 AP interface, bound to a WLAN logical port on first use:

- egress: the flowtable hands over the AP interface, or the bridge in front of it (mac80211 fills no forwarding path, so the route stops at the bridge); one step of the bridge's forwarding path for the next hop MAC gives the interface. The classifier entry's egress field takes the WLAN port instead of a bridge port; the fabric then writes the rewritten frame to the WLAN RX ring, and the ring delivers it to the interface.
- ingress: the flowtable reports the AP interface, or its bridge; the flow's pre-NAT source address leads through the bridge's neighbour entry and forwarding database to the interface. The entry is installed like a switch port's, and its key is listed for the interface's ingress hook, which injects the matching frames so that they reach the entry.

The flows of a port are dropped when its interface is unregistered; their traffic returns to the software path and the flowtable offers them again once their hardware statistics stop.

---
 drivers/net/ethernet/zte/zx279128s-eth.h  |  1 +
 drivers/net/ethernet/zte/zx279128s-ppe.c  | 92 ++++++++++++++++++-----
 drivers/net/ethernet/zte/zx279128s-wlan.c |  9 ++-
 3 files changed, 82 insertions(+), 20 deletions(-)
drivers/net/ethernet/zte/zx279128s-eth.h +1 -0
index b5a547eade35..a5c8df1c60c3 100644
@@ -480,6 +480,7 @@ void zx_set_trap_dmac(struct zx_eth_adapter *adapter, int idx, const u8 *mac);
 extern const struct rhashtable_params zx_ppe_ht_params;
 void zx_update_traps(struct zx_eth_adapter *adapter);
 void zx_update_mac_tables(struct zx_eth_adapter *adapter);
+void zx_ppe_wlan_flush(struct zx_eth_adapter *adapter, int wlan_port);
 int zx_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
 		    void *type_data);
 
drivers/net/ethernet/zte/zx279128s-ppe.c +75 -17

169 lines not on this page · raw message

drivers/net/ethernet/zte/zx279128s-wlan.c +6 -3
index 17ba32bd993a..6c6f6a36d34f 100644
@@ -707,9 +707,12 @@ static int zx_wlan_netdev_event(struct notifier_block *nb, unsigned long event,
 	if (event != NETDEV_UNREGISTER || !zx_wlan_is_ap(dev))
 		return NOTIFY_DONE;
 	mutex_lock(&w->adapter->ppe_lock);
-	for (i = 0; i < ZX_WLAN_PORTS; i++)
-		if (w->ports[i].vif == dev)
-			zx_wlan_port_put(w, i);
+	for (i = 0; i < ZX_WLAN_PORTS; i++) {
+		if (w->ports[i].vif != dev)
+			continue;
+		zx_ppe_wlan_flush(w->adapter, i);
+		zx_wlan_port_put(w, i);
+	}
 	mutex_unlock(&w->adapter->ppe_lock);
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.30.2
#5 lore raw

RFC PATCH 5/5 net: ethernet: zte: zx279128s: debugfs knobs for the WLAN ring

In reply to Agustin Santiago Isasmendi

wlan_state (counters and port table), wlan_inject_all (inject every frame of the bound interfaces, as the vendor firmware does, to exercise the ring and the trap path without flows) and wlan_bind (bind an interface by name). Testing aids, kept apart so they can be dropped.

---
 drivers/net/ethernet/zte/zx279128s-wlan.c | 34 +++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/net/ethernet/zte/zx279128s-wlan.c +34 -0
index 6c6f6a36d34f..29970db47a41 100644
@@ -18,6 +18,7 @@
 #include <linux/platform_device.h>
 #include <linux/seq_file.h>
 #include <linux/tcp.h>
+#include <linux/uaccess.h>
 #include <linux/udp.h>
 #include <net/arp.h>
 #include <net/cfg80211.h>
@@ -751,6 +752,38 @@ static int zx_wlan_state_show(struct seq_file *s, void *data)
 	return 0;
 }
 
+/* Bind an interface by name without waiting for a flow (testing) */
+static ssize_t zx_wlan_bind_write(struct file *file, const char __user *ubuf,
+				  size_t count, loff_t *ppos)
+{
+	struct zx_eth_adapter *adapter = file->private_data;
+	char name[IFNAMSIZ + 1];
+	struct net_device *vif;
+	int ret;
+
+	if (count == 0 || count > IFNAMSIZ)
+		return -EINVAL;
+	if (copy_from_user(name, ubuf, count))
+		return -EFAULT;
+	name[count] = 0;
+	strim(name);
+	vif = dev_get_by_name(dev_net(adapter->wlan->napi.dev), name);
+	if (!vif)
+		return -ENODEV;
+	mutex_lock(&adapter->ppe_lock);
+	ret = zx_wlan_is_ap(vif) ? zx_wlan_port_get(adapter->wlan, vif) : -EINVAL;
+	mutex_unlock(&adapter->ppe_lock);
+	dev_put(vif);
+	return ret < 0 ? ret : count;
+}
+
+static const struct file_operations zx_wlan_bind_fops = {
+	.owner	= THIS_MODULE,
+	.open	= simple_open,
+	.write	= zx_wlan_bind_write,
+	.llseek	= noop_llseek,
+};
+
 void zx_wlan_debugfs_init(struct zx_eth_adapter *adapter, struct dentry *dir)
 {
 	if (!adapter->wlan)
@@ -759,6 +792,7 @@ void zx_wlan_debugfs_init(struct zx_eth_adapter *adapter, struct dentry *dir)
 				    zx_wlan_state_show);
 	debugfs_create_bool("wlan_inject_all", 0600, dir,
 			    &adapter->wlan->inject_all);
+	debugfs_create_file("wlan_bind", 0200, dir, adapter, &zx_wlan_bind_fops);
 }
 
 /* ---- init / fini --------------------------------------------------- */
Signature · 1 line
2.30.2