BPF List
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/2] net: ti: icssg: Multi-flow RX and ethtool RX flow classification
@ 2026-12-03 12:14 Meghana Malladi
  2026-12-03 12:14 ` [PATCH net-next v2 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI Meghana Malladi
  2026-12-03 12:14 ` [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support Meghana Malladi
  0 siblings, 2 replies; 7+ messages in thread
From: Meghana Malladi @ 2026-12-03 12:14 UTC (permalink / raw)
  To: marco.crivellari, kees+treewide, laixiangwu, philippe.schenker,
	haokexin, devnexen, horms, m-malladi, sdf, john.fastabend, hawk,
	daniel, ast, pabeni, kuba, edumazet, davem, andrew+netdev
  Cc: bpf, netdev, linux-arm-kernel, srk, Vignesh Raghavendra,
	Roger Quadros, danishanwar

This series adds multi-flow RX support to the ICSSG ethernet driver and
exposes it via ethtool RX flow classification (rxnfc).

Patch (1/2): restructures the driver to support up to 8 independent RX flows
per EMAC interface. Each flow gets its own NAPI instance, IRQ, hrtimer,
page pool, and XDP/AF_XDP context while sharing a single UDMA channel and
descriptor pool. AF_XDP zero-copy is updated to track per-flow pools via a
bitmap, and per-flow page pool recycling is fixed by storing the flow_id in
prueth_swdata.

Patch (2/2): adds ethtool ETHTOOL_SRXCLSRLINS/SRXCLSRLDEL/SRXCLSRLALL support.
Rules match on EtherType (ETHER_FLOW) and steer matched frames to a
user-specified RX queue via ICSSG FT3 hardware content filters and the
16-entry classifier table. The classifier N result maps directly to UDMA
flow rx_flow_id_base+N, so queue steering takes effect in hardware without
per-packet CPU involvement.

Tested on AM64x EVM (SR2), both eth1 (PRU0/slice0) and eth2
(PRU1/slice1) with 8 RX flows. Verified via /proc/interrupts IRQ deltas

v1: https://lore.kernel.org/all/20261118184729.2302130-1-m-malladi@ti.com/

Meghana Malladi (2):
  net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI
  net: ti: icssg-prueth: Add ethtool RX flow classification support

 .../net/ethernet/ti/icssg/icssg_classifier.c  | 440 +++++++++++++++++-
 drivers/net/ethernet/ti/icssg/icssg_common.c  | 391 ++++++++++------
 drivers/net/ethernet/ti/icssg/icssg_config.h  |   7 +-
 drivers/net/ethernet/ti/icssg/icssg_ethtool.c |  82 +++-
 drivers/net/ethernet/ti/icssg/icssg_prueth.c  | 378 +++++++++------
 drivers/net/ethernet/ti/icssg/icssg_prueth.h  |  97 ++--
 .../net/ethernet/ti/icssg/icssg_prueth_sr1.c  | 303 ++++++++++--
 7 files changed, 1308 insertions(+), 390 deletions(-)


base-commit: 612848d37e68b858e15815175f1c5e609e09d719
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI
  2026-12-03 12:14 [PATCH net-next v2 0/2] net: ti: icssg: Multi-flow RX and ethtool RX flow classification Meghana Malladi
@ 2026-12-03 12:14 ` Meghana Malladi
  2026-12-04 12:44   ` sashiko-bot
  2026-12-04 13:25   ` netdev-bot+sashiko
  2026-12-03 12:14 ` [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support Meghana Malladi
  1 sibling, 2 replies; 7+ messages in thread
From: Meghana Malladi @ 2026-12-03 12:14 UTC (permalink / raw)
  To: marco.crivellari, kees+treewide, laixiangwu, philippe.schenker,
	haokexin, devnexen, horms, m-malladi, sdf, john.fastabend, hawk,
	daniel, ast, pabeni, kuba, edumazet, davem, andrew+netdev
  Cc: bpf, netdev, linux-arm-kernel, srk, Vignesh Raghavendra,
	Roger Quadros, danishanwar

Extend ICSSG driver to support up to 8 independent RX flows per EMAC
(PRUETH_MAX_RX_FLOWS 1 --> 8), enabling ethtool queue steering via set_rxnfc.

Data structures:
- Introduce prueth_rx_flow for per-flow state: NAPI, hrtimer, page pool,
  XDP rxq, AF_XDP pool, IRQ. All flows share one UDMA channel and
  descriptor pool (PRUETH_MAX_RX_DESC x flow_count).
- Restructure prueth_rx_chn: strip per-flow fields, add flows[] array.
- Add flow_id to prueth_swdata so recycled pages return to the correct
  per-flow page pool (previously always used flows[0]).
- Replace xsk_qid int with xsk_queues bitmap for multi-pool AF_XDP.

Channel lifecycle:
- prueth_create_rxq / prueth_destroy_rxq operate on a single flow.
- prueth_create_rxqs / prueth_destroy_rxqs iterate all active flows and
  enable the shared UDMA channel only after all flows are ready.
- prueth_ndev_add_rx_napi / prueth_ndev_del_rx_napi register per-flow
  NAPI, hrtimer, and IRQ with teardown on partial failure.
ethtool: report rx_flow_num active queues; ICSSG_MAX_RFLOWS as max.

Known limitations:
- AM654 (UDMAP) uses a shared FDQ ring across all flows; per-flow page
  pool enforcement breaks under XDP. Multi-flow on AM654 deferred.
- ndev->stats.rx_errors/rx_dropped use plain RMW from concurrent NAPIs;
  per-cpu stats refactor deferred.
- XSK per-flow teardown while the shared UDMA channel is live; UDMA may
  have prefetched FDQ descriptors before the RXCQ drain completes.
  Per-channel teardown support needed; deferred.
- emac_rx_packet_zc() uses shared desc_pool free count for alloc_budget;
  concurrent NAPIs can race for pool entries. Deferred with AM654 FDQ fix.

Signed-off-by: Meghana Malladi <m-malladi@ti.com>
---

Changelog for v2-v1:
  - SR1: set rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1; fixes OOB access on
    flows[PRUETH_RX_FLOW_DATA_SR1]                                                                   
  - SR1 mgm page pool: add PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV; fixes invalid DMA addresses
  - prueth_xsk_pool_enable/disable(): err_napi: label clears pool state and best-effort
    recreates page pool flow; unmap DMA on PORT_DISABLE failure; int ret = 0 in disable path                                                                                                                                                           
  - prueth_sr1_reset_rx_mgm_chn(): add k3_udma_glue_reset_rx_chn() and disable_rx_chn()                                                                                  
  - prueth_sr1_cleanup_rx_mgm_chn(): add k3_cppi_desc_pool_destroy() on mgm desc_pool                                                                                    
  - SR1 emac_ndo_open() error labels: move cleanup_rx_mgm: past NAPI/IRQ setup labels; early mgm
    failures no longer call free_irq() on unregistered IRQs
  - SR1 emac_ndo_open/stop(): explicit page_pool_destroy() for flows[PRUETH_RX_FLOW_DATA_SR1]                                                                            
  - prueth_ndev_del_rx_napi(): add hrtimer_cancel() per flow; fixes SR1 timer never cancelled                                                                            
  - prueth_destroy_rxq(): remove enable_irq(); moved to prueth_create_rxq() after napi_enable()
    to fix irq_disabled race                                                 
  - prueth_create_rxq() error path: direct cleanup without calling prueth_destroy_rxq() to avoid
    double napi_disable()                                                   
  - emac_ndo_open(): bitmap_zero(emac->xsk_queues) on open; invalidates AF_XDP pool bound while down                                                                     
  - emac_set_coalesce(): loop PRUETH_MAX_RX_FLOWS instead of rx_flow_num                                                                                                 
  - emac_get_channels(): ch->max_rx = 1 for SR1                                                                                                                          
  - SR1 mgm IRQ check: fix to flow->irq <= 0                                                                                                                             
  - Remove leftover int xsk_qid from struct prueth_emac
  - Add skb_record_rx_queue(skb, flow_id) in both emac_rx_packet() and emac_dispatch_skb_zc()
  - Document known limitations: AM654 shared FDQ, ndev->stats RMW race, XSK per-flow teardown,
    shared desc_pool race 

 drivers/net/ethernet/ti/icssg/icssg_common.c  | 391 +++++++++++-------
 drivers/net/ethernet/ti/icssg/icssg_config.h  |   7 +-
 drivers/net/ethernet/ti/icssg/icssg_ethtool.c |  22 +-
 drivers/net/ethernet/ti/icssg/icssg_prueth.c  | 371 ++++++++++-------
 drivers/net/ethernet/ti/icssg/icssg_prueth.h  |  96 +++--
 .../net/ethernet/ti/icssg/icssg_prueth_sr1.c  | 303 +++++++++++---
 6 files changed, 801 insertions(+), 389 deletions(-)

diff --git a/drivers/net/ethernet/ti/icssg/icssg_common.c b/drivers/net/ethernet/ti/icssg/icssg_common.c
index 4a7d1a6f470b1..fc7e7847580f8 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_common.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_common.c
@@ -39,22 +39,20 @@
 				 NETIF_MSG_HW | \
 				 NETIF_MSG_WOL)
 
-#define prueth_napi_to_emac(napi) container_of(napi, struct prueth_emac, napi_rx)
 
-void prueth_cleanup_rx_chns(struct prueth_emac *emac,
-			    struct prueth_rx_chn *rx_chn,
-			    int max_rflows)
+void prueth_cleanup_rx_chns(struct prueth_emac *emac)
 {
-	if (rx_chn->pg_pool) {
-		page_pool_destroy(rx_chn->pg_pool);
-		rx_chn->pg_pool = NULL;
-	}
+	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
 
-	if (rx_chn->desc_pool)
+	if (rx_chn->desc_pool) {
 		k3_cppi_desc_pool_destroy(rx_chn->desc_pool);
+		rx_chn->desc_pool = NULL;
+	}
 
-	if (rx_chn->rx_chn)
+	if (rx_chn->rx_chn) {
 		k3_udma_glue_release_rx_chn(rx_chn->rx_chn);
+		rx_chn->rx_chn = NULL;
+	}
 }
 EXPORT_SYMBOL_GPL(prueth_cleanup_rx_chns);
 
@@ -79,6 +77,21 @@ void prueth_cleanup_tx_chns(struct prueth_emac *emac)
 }
 EXPORT_SYMBOL_GPL(prueth_cleanup_tx_chns);
 
+void prueth_ndev_del_rx_napi(struct prueth_emac *emac, int num)
+{
+	int i;
+
+	for (i = 0; i < num; i++) {
+		struct prueth_rx_flow *rx_flow = &emac->rx_chns.flows[i];
+
+		hrtimer_cancel(&rx_flow->rx_hrtimer);
+		if (rx_flow->irq)
+			free_irq(rx_flow->irq, &rx_flow->napi_rx);
+		netif_napi_del(&rx_flow->napi_rx);
+	}
+}
+EXPORT_SYMBOL_GPL(prueth_ndev_del_rx_napi);
+
 void prueth_ndev_del_tx_napi(struct prueth_emac *emac, int num)
 {
 	int i;
@@ -311,6 +324,19 @@ int emac_tx_complete_packets(struct prueth_emac *emac, int chn,
 	return num_tx;
 }
 
+static enum hrtimer_restart emac_rx_timer_callback(struct hrtimer *timer)
+{
+	struct prueth_rx_flow *rx_flow =
+				container_of(timer, struct prueth_rx_flow, rx_hrtimer);
+
+	if (rx_flow->irq_disabled) {
+		/* re-enable the RX IRQ */
+		rx_flow->irq_disabled = false;
+		enable_irq(rx_flow->irq);
+	}
+	return HRTIMER_NORESTART;
+}
+
 static enum hrtimer_restart emac_tx_timer_callback(struct hrtimer *timer)
 {
 	struct prueth_tx_chn *tx_chns =
@@ -363,6 +389,35 @@ static irqreturn_t prueth_tx_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+int prueth_ndev_add_rx_napi(struct prueth_emac *emac)
+{
+	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth *prueth = emac->prueth;
+	struct prueth_rx_flow *flow;
+	int i, ret;
+
+	for (i = 0; i < emac->rx_flow_num; i++) {
+		flow = &rx_chn->flows[i];
+
+		netif_napi_add(emac->ndev, &flow->napi_rx, icssg_napi_rx_poll);
+		hrtimer_setup(&flow->rx_hrtimer, &emac_rx_timer_callback, CLOCK_MONOTONIC,
+			      HRTIMER_MODE_REL_PINNED);
+		ret = request_irq(emac->rx_chns.flows[i].irq, prueth_rx_irq,
+				  IRQF_TRIGGER_HIGH, flow->name, &flow->napi_rx);
+		if (ret) {
+			netif_napi_del(&flow->napi_rx);
+			dev_err(prueth->dev, "unable to request RX IRQ\n");
+			goto fail;
+		}
+	}
+
+	return 0;
+fail:
+	prueth_ndev_del_rx_napi(emac, i);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(prueth_ndev_add_rx_napi);
+
 int prueth_ndev_add_tx_napi(struct prueth_emac *emac)
 {
 	struct prueth *prueth = emac->prueth;
@@ -475,7 +530,8 @@ EXPORT_SYMBOL_GPL(prueth_init_tx_chns);
 
 static struct page_pool *prueth_create_page_pool(struct prueth_emac *emac,
 						 struct device *dma_dev,
-						 int size)
+						 int size,
+						 struct prueth_rx_flow *rx_flow)
 {
 	struct page_pool_params pp_params = { 0 };
 	struct page_pool *pool;
@@ -486,7 +542,7 @@ static struct page_pool *prueth_create_page_pool(struct prueth_emac *emac,
 	pp_params.nid = dev_to_node(emac->prueth->dev);
 	pp_params.dma_dir = DMA_BIDIRECTIONAL;
 	pp_params.dev = dma_dev;
-	pp_params.napi = &emac->napi_rx;
+	pp_params.napi = &rx_flow->napi_rx;
 	pp_params.max_len = PAGE_SIZE;
 
 	pool = page_pool_create(&pp_params);
@@ -496,38 +552,30 @@ static struct page_pool *prueth_create_page_pool(struct prueth_emac *emac,
 	return pool;
 }
 
-int prueth_init_rx_chns(struct prueth_emac *emac,
-			struct prueth_rx_chn *rx_chn,
-			char *name, u32 max_rflows,
-			u32 max_desc_num)
+int prueth_init_rx_chns(struct prueth_emac *emac)
 {
+	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
 	struct k3_udma_glue_rx_channel_cfg rx_cfg;
 	struct device *dev = emac->prueth->dev;
 	struct net_device *ndev = emac->ndev;
+	struct prueth_rx_flow *flow;
 	u32 fdqring_id, hdesc_size;
-	struct page_pool *pool;
 	int i, ret = 0, slice;
-	int flow_id_base;
+	char udma_name[32];
 
 	slice = prueth_emac_slice(emac);
 	if (slice < 0)
 		return slice;
 
-	/* To differentiate channels for SLICE0 vs SLICE1 */
-	snprintf(rx_chn->name, sizeof(rx_chn->name), "%s%d", name, slice);
-
 	hdesc_size = cppi5_hdesc_calc_size(true, PRUETH_NAV_PS_DATA_SIZE,
 					   PRUETH_NAV_SW_DATA_SIZE);
 	memset(&rx_cfg, 0, sizeof(rx_cfg));
 	rx_cfg.swdata_size = PRUETH_NAV_SW_DATA_SIZE;
-	rx_cfg.flow_id_num = max_rflows;
+	rx_cfg.flow_id_num = emac->rx_flow_num;
 	rx_cfg.flow_id_base = -1; /* udmax will auto select flow id base */
 
-	/* init all flows */
-	rx_chn->dev = dev;
-	rx_chn->descs_num = max_desc_num;
-
-	rx_chn->rx_chn = k3_udma_glue_request_rx_chn(dev, rx_chn->name,
+	snprintf(udma_name, sizeof(udma_name), "%s%d", "rx", slice);
+	rx_chn->rx_chn = k3_udma_glue_request_rx_chn(dev, udma_name,
 						     &rx_cfg);
 	if (IS_ERR(rx_chn->rx_chn)) {
 		ret = PTR_ERR(rx_chn->rx_chn);
@@ -536,11 +584,14 @@ int prueth_init_rx_chns(struct prueth_emac *emac,
 		goto fail;
 	}
 
+	/* Initialize the RX channel (shared by all flows) */
+	rx_chn->emac = emac;
+	rx_chn->descs_num = PRUETH_MAX_RX_DESC * rx_cfg.flow_id_num;
 	rx_chn->dma_dev = k3_udma_glue_rx_get_dma_device(rx_chn->rx_chn);
 	rx_chn->desc_pool = k3_cppi_desc_pool_create_name(rx_chn->dma_dev,
 							  rx_chn->descs_num,
 							  hdesc_size,
-							  rx_chn->name);
+							  "rx_desc_pool");
 	if (IS_ERR(rx_chn->desc_pool)) {
 		ret = PTR_ERR(rx_chn->desc_pool);
 		rx_chn->desc_pool = NULL;
@@ -548,22 +599,14 @@ int prueth_init_rx_chns(struct prueth_emac *emac,
 		goto fail;
 	}
 
-	pool = prueth_create_page_pool(emac, rx_chn->dma_dev, rx_chn->descs_num);
-	if (IS_ERR(pool)) {
-		ret = PTR_ERR(pool);
-		goto fail;
+	for (i = 0; i < rx_cfg.flow_id_num; i++) {
+		flow = &rx_chn->flows[i];
+		flow->pg_pool = NULL;
+		flow->xsk_pool = NULL;
 	}
 
-	rx_chn->pg_pool = pool;
-
-	flow_id_base = k3_udma_glue_rx_get_flow_id_base(rx_chn->rx_chn);
-	if (emac->is_sr1 && !strcmp(name, "rxmgm")) {
-		emac->rx_mgm_flow_id_base = flow_id_base;
-		netdev_dbg(ndev, "mgm flow id base = %d\n", flow_id_base);
-	} else {
-		emac->rx_flow_id_base = flow_id_base;
-		netdev_dbg(ndev, "flow id base = %d\n", flow_id_base);
-	}
+	emac->rx_flow_id_base = k3_udma_glue_rx_get_flow_id_base(rx_chn->rx_chn);
+	netdev_dbg(ndev, "flow id base = %d\n", emac->rx_flow_id_base);
 
 	fdqring_id = K3_RINGACC_RING_ID_ANY;
 	for (i = 0; i < rx_cfg.flow_id_num; i++) {
@@ -584,9 +627,14 @@ int prueth_init_rx_chns(struct prueth_emac *emac,
 				K3_UDMA_GLUE_SRC_TAG_LO_USE_REMOTE_SRC_TAG,
 		};
 
+		flow = &rx_chn->flows[i];
+		flow->emac = emac;
+		flow->id = i;
+		flow->irq = -EINVAL;
+
 		rx_flow_cfg.ring_rxfdq0_id = fdqring_id;
-		rx_flow_cfg.rx_cfg.size = max_desc_num;
-		rx_flow_cfg.rxfdq_cfg.size = max_desc_num;
+		rx_flow_cfg.rx_cfg.size = PRUETH_MAX_RX_DESC;
+		rx_flow_cfg.rxfdq_cfg.size = PRUETH_MAX_RX_DESC;
 		rx_flow_cfg.rxfdq_cfg.mode = emac->prueth->pdata.fdqring_mode;
 
 		ret = k3_udma_glue_rx_flow_init(rx_chn->rx_chn,
@@ -599,31 +647,36 @@ int prueth_init_rx_chns(struct prueth_emac *emac,
 		if (!i)
 			fdqring_id = k3_udma_glue_rx_flow_get_fdq_id(rx_chn->rx_chn,
 								     i);
-		ret = k3_udma_glue_rx_get_irq(rx_chn->rx_chn, i);
-		if (ret < 0) {
+		flow->irq = k3_udma_glue_rx_get_irq(rx_chn->rx_chn, i);
+		if (flow->irq <= 0) {
+			ret = flow->irq < 0 ? flow->irq : -EINVAL;
 			netdev_err(ndev, "Failed to get rx dma irq");
 			goto fail;
 		}
-		rx_chn->irq[i] = ret;
+
+		snprintf(flow->name, sizeof(flow->name),
+			 "%s-rx%d-%d", dev_name(dev), slice, i);
 	}
 
 	return 0;
 
 fail:
-	prueth_cleanup_rx_chns(emac, rx_chn, max_rflows);
+	prueth_cleanup_rx_chns(emac);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(prueth_init_rx_chns);
 
 int prueth_dma_rx_push_mapped(struct prueth_emac *emac,
 			      struct prueth_rx_chn *rx_chn,
-			      struct page *page, u32 buf_len)
+			      struct page *page, u32 buf_len,
+			      int flow_id)
 {
 	struct net_device *ndev = emac->ndev;
 	struct cppi5_host_desc_t *desc_rx;
 	struct prueth_swdata *swdata;
 	dma_addr_t desc_dma;
 	dma_addr_t buf_dma;
+	int ret;
 
 	buf_dma = page_pool_get_dma_addr(page) + PRUETH_HEADROOM;
 	desc_rx = k3_cppi_desc_pool_alloc(rx_chn->desc_pool);
@@ -641,9 +694,12 @@ int prueth_dma_rx_push_mapped(struct prueth_emac *emac,
 	swdata = cppi5_hdesc_get_swdata(desc_rx);
 	swdata->type = PRUETH_SWDATA_PAGE;
 	swdata->data.page = page;
+	swdata->flow_id = flow_id;
 
-	return k3_udma_glue_push_rx_chn(rx_chn->rx_chn, PRUETH_RX_FLOW_DATA,
-					desc_rx, desc_dma);
+	ret = k3_udma_glue_push_rx_chn(rx_chn->rx_chn, flow_id, desc_rx, desc_dma);
+	if (ret)
+		k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(prueth_dma_rx_push_mapped);
 
@@ -860,14 +916,17 @@ static u32 emac_run_xdp(struct prueth_emac *emac, struct xdp_buff *xdp, u32 *len
 
 static int prueth_dma_rx_push_mapped_zc(struct prueth_emac *emac,
 					struct prueth_rx_chn *rx_chn,
-					struct xdp_buff *xdp)
+					struct xdp_buff *xdp,
+					int flow_id)
 {
+	struct prueth_rx_flow *rx_flow = &emac->rx_chns.flows[flow_id];
 	struct net_device *ndev = emac->ndev;
 	struct cppi5_host_desc_t *desc_rx;
 	struct prueth_swdata *swdata;
 	dma_addr_t desc_dma;
 	dma_addr_t buf_dma;
 	int buf_len;
+	int ret;
 
 	buf_dma = xsk_buff_xdp_get_dma(xdp);
 	desc_rx = k3_cppi_desc_pool_alloc(rx_chn->desc_pool);
@@ -880,28 +939,32 @@ static int prueth_dma_rx_push_mapped_zc(struct prueth_emac *emac,
 	cppi5_hdesc_init(desc_rx, CPPI5_INFO0_HDESC_EPIB_PRESENT,
 			 PRUETH_NAV_PS_DATA_SIZE);
 	k3_udma_glue_rx_dma_to_cppi5_addr(rx_chn->rx_chn, &buf_dma);
-	buf_len = xsk_pool_get_rx_frame_size(rx_chn->xsk_pool);
+	buf_len = xsk_pool_get_rx_frame_size(rx_flow->xsk_pool);
 	cppi5_hdesc_attach_buf(desc_rx, buf_dma, buf_len, buf_dma, buf_len);
 	swdata = cppi5_hdesc_get_swdata(desc_rx);
 	swdata->type = PRUETH_SWDATA_XSK;
 	swdata->data.xdp = xdp;
+	swdata->flow_id = flow_id;
 
-	return k3_udma_glue_push_rx_chn(rx_chn->rx_chn, PRUETH_RX_FLOW_DATA,
+	ret = k3_udma_glue_push_rx_chn(rx_chn->rx_chn, flow_id,
 					desc_rx, desc_dma);
+	if (ret)
+		k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
+	return ret;
 }
 
-static int prueth_rx_alloc_zc(struct prueth_emac *emac, int budget)
+static int prueth_rx_alloc_zc(struct prueth_emac *emac, int flow_id, int budget)
 {
-	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_rx_flow *rx_flow = &emac->rx_chns.flows[flow_id];
 	struct xdp_buff *xdp;
 	int i, ret;
 
 	for (i = 0; i < budget; i++) {
-		xdp = xsk_buff_alloc(rx_chn->xsk_pool);
+		xdp = xsk_buff_alloc(rx_flow->xsk_pool);
 		if (!xdp)
 			break;
 
-		ret = prueth_dma_rx_push_mapped_zc(emac, rx_chn, xdp);
+		ret = prueth_dma_rx_push_mapped_zc(emac, &emac->rx_chns, xdp, flow_id);
 		if (ret) {
 			netdev_err(emac->ndev, "rx alloc: failed to map descriptors to xdp buff\n");
 			xsk_buff_free(xdp);
@@ -912,14 +975,14 @@ static int prueth_rx_alloc_zc(struct prueth_emac *emac, int budget)
 	return i;
 }
 
-static void emac_dispatch_skb_zc(struct prueth_emac *emac, struct xdp_buff *xdp, u32 *psdata)
+static void emac_dispatch_skb_zc(struct prueth_emac *emac, struct xdp_buff *xdp, u32 *psdata, int flow_id)
 {
 	unsigned int headroom = xdp->data - xdp->data_hard_start;
 	unsigned int pkt_len = xdp->data_end - xdp->data;
 	struct net_device *ndev = emac->ndev;
 	struct sk_buff *skb;
 
-	skb = napi_alloc_skb(&emac->napi_rx, xdp->data_end - xdp->data_hard_start);
+	skb = napi_alloc_skb(&emac->rx_chns.flows[flow_id].napi_rx, xdp->data_end - xdp->data_hard_start);
 	if (unlikely(!skb)) {
 		ndev->stats.rx_dropped++;
 		return;
@@ -938,7 +1001,8 @@ static void emac_dispatch_skb_zc(struct prueth_emac *emac, struct xdp_buff *xdp,
 		skb->offload_fwd_mark = emac->offload_fwd_mark;
 	skb->protocol = eth_type_trans(skb, ndev);
 
-	napi_gro_receive(&emac->napi_rx, skb);
+	skb_record_rx_queue(skb, flow_id);
+	napi_gro_receive(&emac->rx_chns.flows[flow_id].napi_rx, skb);
 	ndev->stats.rx_bytes += pkt_len;
 	ndev->stats.rx_packets++;
 }
@@ -947,6 +1011,7 @@ static int emac_rx_packet_zc(struct prueth_emac *emac, u32 flow_id,
 			     int budget)
 {
 	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_rx_flow *rx_flow = &emac->rx_chns.flows[flow_id];
 	u32 buf_dma_len, pkt_len, port_id = 0;
 	struct net_device *ndev = emac->ndev;
 	struct cppi5_host_desc_t *desc_rx;
@@ -997,7 +1062,7 @@ static int emac_rx_packet_zc(struct prueth_emac *emac, u32 flow_id,
 			switch (ret) {
 			case ICSSG_XDP_PASS:
 				/* prepare skb and send to n/w stack */
-				emac_dispatch_skb_zc(emac, xdp, psdata);
+				emac_dispatch_skb_zc(emac, xdp, psdata, flow_id);
 				xsk_buff_free(xdp);
 				break;
 			case ICSSG_XDP_CONSUMED:
@@ -1010,7 +1075,7 @@ static int emac_rx_packet_zc(struct prueth_emac *emac, u32 flow_id,
 			}
 		} else {
 			/* prepare skb and send to n/w stack */
-			emac_dispatch_skb_zc(emac, xdp, psdata);
+			emac_dispatch_skb_zc(emac, xdp, psdata, flow_id);
 			xsk_buff_free(xdp);
 		}
 		k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
@@ -1022,13 +1087,13 @@ static int emac_rx_packet_zc(struct prueth_emac *emac, u32 flow_id,
 	avail_desc = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
 	alloc_budget = min_t(int, budget, avail_desc);
 
-	ret = prueth_rx_alloc_zc(emac, alloc_budget);
+	ret = prueth_rx_alloc_zc(emac, flow_id, alloc_budget);
 
-	if (xsk_uses_need_wakeup(rx_chn->xsk_pool)) {
+	if (xsk_uses_need_wakeup(rx_flow->xsk_pool)) {
 		if (ret < alloc_budget)
-			xsk_set_rx_need_wakeup(rx_chn->xsk_pool);
+			xsk_set_rx_need_wakeup(rx_flow->xsk_pool);
 		else
-			xsk_clear_rx_need_wakeup(rx_chn->xsk_pool);
+			xsk_clear_rx_need_wakeup(rx_flow->xsk_pool);
 	}
 
 	return count;
@@ -1037,6 +1102,7 @@ static int emac_rx_packet_zc(struct prueth_emac *emac, u32 flow_id,
 static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id, u32 *xdp_state)
 {
 	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_rx_flow *rx_flow = &emac->rx_chns.flows[flow_id];
 	u32 buf_dma_len, pkt_len, port_id = 0;
 	struct net_device *ndev = emac->ndev;
 	struct cppi5_host_desc_t *desc_rx;
@@ -1051,7 +1117,7 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id, u32 *xdp_state)
 	void *pa;
 
 	*xdp_state = 0;
-	pool = rx_chn->pg_pool;
+	pool = rx_flow->pg_pool;
 	ret = k3_udma_glue_pop_rx_chn(rx_chn->rx_chn, flow_id, &desc_dma);
 	if (ret) {
 		if (ret != -ENODATA)
@@ -1093,7 +1159,7 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id, u32 *xdp_state)
 
 	pa = page_address(page);
 	if (prueth_xdp_is_enabled(emac)) {
-		xdp_init_buff(&xdp, PAGE_SIZE, &rx_chn->xdp_rxq);
+		xdp_init_buff(&xdp, PAGE_SIZE, &rx_flow->xdp_rxq);
 		xdp_prepare_buff(&xdp, pa, PRUETH_HEADROOM, pkt_len, false);
 
 		*xdp_state = emac_run_xdp(emac, &xdp, &pkt_len);
@@ -1132,15 +1198,16 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id, u32 *xdp_state)
 	skb->protocol = eth_type_trans(skb, ndev);
 
 	skb_mark_for_recycle(skb);
-	napi_gro_receive(&emac->napi_rx, skb);
+	skb_record_rx_queue(skb, flow_id);
+	napi_gro_receive(&emac->rx_chns.flows[flow_id].napi_rx, skb);
 	ndev->stats.rx_bytes += pkt_len;
 	ndev->stats.rx_packets++;
 
 requeue:
 	k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
 	/* queue another RX DMA */
-	ret = prueth_dma_rx_push_mapped(emac, &emac->rx_chns, new_page,
-					PRUETH_MAX_PKT_SIZE);
+	ret = prueth_dma_rx_push_mapped(emac, rx_chn, new_page,
+					PRUETH_MAX_PKT_SIZE, flow_id);
 	if (WARN_ON(ret < 0)) {
 		page_pool_recycle_direct(pool, new_page);
 		ndev->stats.rx_errors++;
@@ -1155,19 +1222,22 @@ void prueth_rx_cleanup(void *data, dma_addr_t desc_dma)
 	struct prueth_rx_chn *rx_chn = data;
 	struct cppi5_host_desc_t *desc_rx;
 	struct prueth_swdata *swdata;
-	struct page_pool *pool;
+	struct page_pool *pool = NULL;
 	struct xdp_buff *xdp;
 	struct page *page;
 
-	pool = rx_chn->pg_pool;
 	desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma);
 	swdata = cppi5_hdesc_get_swdata(desc_rx);
-	if (rx_chn->xsk_pool) {
+
+	if (swdata->type == PRUETH_SWDATA_XSK) {
 		xdp = swdata->data.xdp;
 		xsk_buff_free(xdp);
-	} else {
-		page = swdata->data.page;
-		page_pool_recycle_direct(pool, page);
+	} else if (swdata->type == PRUETH_SWDATA_PAGE) {
+		pool = rx_chn->flows[swdata->flow_id].pg_pool;
+		if (pool) {
+			page = swdata->data.page;
+			page_pool_recycle_direct(pool, page);
+		}
 	}
 
 	k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
@@ -1411,11 +1481,12 @@ EXPORT_SYMBOL_GPL(prueth_tx_cleanup);
 
 irqreturn_t prueth_rx_irq(int irq, void *dev_id)
 {
-	struct prueth_emac *emac = dev_id;
+	struct napi_struct *napi_rx = dev_id;
+	struct prueth_rx_flow *rx_flow = container_of(napi_rx, struct prueth_rx_flow, napi_rx);
 
-	emac->rx_chns.irq_disabled = true;
+	rx_flow->irq_disabled = true;
 	disable_irq_nosync(irq);
-	napi_schedule(&emac->napi_rx);
+	napi_schedule(napi_rx);
 
 	return IRQ_HANDLED;
 }
@@ -1436,50 +1507,38 @@ EXPORT_SYMBOL_GPL(prueth_cleanup_tx_ts);
 
 int icssg_napi_rx_poll(struct napi_struct *napi_rx, int budget)
 {
-	struct prueth_emac *emac = prueth_napi_to_emac(napi_rx);
-	int rx_flow = emac->is_sr1 ?
-		PRUETH_RX_FLOW_DATA_SR1 : PRUETH_RX_FLOW_DATA;
-	int flow = emac->is_sr1 ?
-		PRUETH_MAX_RX_FLOWS_SR1 : PRUETH_MAX_RX_FLOWS;
-	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_rx_flow *rx_flow = prueth_napi_to_rx_chn(napi_rx);
+	struct prueth_emac *emac = rx_flow->emac;
 	int xdp_state_or = 0;
 	int num_rx = 0;
-	int cur_budget;
 	u32 xdp_state;
 	int ret;
 
-	while (flow--) {
-		if (rx_chn->xsk_pool) {
-			num_rx = emac_rx_packet_zc(emac, flow, budget);
-		} else {
-			cur_budget = budget - num_rx;
-
-			while (cur_budget--) {
-				ret = emac_rx_packet(emac, flow, &xdp_state);
-				xdp_state_or |= xdp_state;
-				if (ret)
-					break;
-				num_rx++;
-			}
+	if (rx_flow->xsk_pool) {
+		num_rx = emac_rx_packet_zc(emac, rx_flow->id, budget);
+	} else {
+		while (budget - num_rx > 0) {
+			ret = emac_rx_packet(emac, rx_flow->id, &xdp_state);
+			xdp_state_or |= xdp_state;
+			if (ret)
+				break;
+			num_rx++;
 		}
-
-		if (num_rx >= budget)
-			break;
 	}
 
 	if (xdp_state_or & ICSSG_XDP_REDIR)
 		xdp_do_flush();
 
 	if (num_rx < budget && napi_complete_done(napi_rx, num_rx)) {
-		if (unlikely(emac->rx_pace_timeout_ns)) {
-			hrtimer_start(&emac->rx_hrtimer,
-				      ns_to_ktime(emac->rx_pace_timeout_ns),
+		if (unlikely(rx_flow->rx_pace_timeout_ns)) {
+			hrtimer_start(&rx_flow->rx_hrtimer,
+				      ns_to_ktime(rx_flow->rx_pace_timeout_ns),
 				      HRTIMER_MODE_REL_PINNED);
 		} else {
-			if (emac->rx_chns.irq_disabled) {
+			if (rx_flow->irq_disabled) {
 				/* re-enable the RX IRQ */
-				emac->rx_chns.irq_disabled = false;
-				enable_irq(emac->rx_chns.irq[rx_flow]);
+				rx_flow->irq_disabled = false;
+				enable_irq(rx_flow->irq);
 			}
 		}
 	}
@@ -1488,59 +1547,81 @@ int icssg_napi_rx_poll(struct napi_struct *napi_rx, int budget)
 }
 EXPORT_SYMBOL_GPL(icssg_napi_rx_poll);
 
-int prueth_prepare_rx_chan(struct prueth_emac *emac,
-			   struct prueth_rx_chn *chn,
-			   int buf_size)
+int prueth_prepare_rx_flow(struct prueth_emac *emac,
+			   int flow)
 {
+	int buf_size = PRUETH_MAX_PKT_SIZE;
+	struct prueth_rx_flow *rx_flow;
+	struct prueth_rx_chn *rx_chn;
+	struct page_pool *pool;
 	struct page *page;
 	int desc_avail;
 	int i, ret;
 
-	desc_avail = k3_cppi_desc_pool_avail(chn->desc_pool);
-	if (desc_avail < chn->descs_num)
-		netdev_warn(emac->ndev,
-			    "not enough RX descriptors available %d < %d\n",
-			    desc_avail, chn->descs_num);
+	rx_chn = &emac->rx_chns;
+	rx_flow = &emac->rx_chns.flows[flow];
 
-	if (chn->xsk_pool) {
-		/* get pages from xsk_pool and push to RX ring
-		 * queue as much as possible
+	if (rx_flow->xsk_pool) {
+		/* XSK zero-copy: buffers come from the XSK fill ring, no page
+		 * pool needed.  Push up to PRUETH_MAX_RX_DESC XSK buffers.
 		 */
-		ret = prueth_rx_alloc_zc(emac, desc_avail);
-		if (!ret)
-			goto recycle_alloc_pg;
-	} else {
-		for (i = 0; i < desc_avail; i++) {
-			/* NOTE: we're not using memory efficiently here.
-			 * 1 full page (4KB?) used here instead of
-			 * PRUETH_MAX_PKT_SIZE (~1.5KB?)
-			 */
-			page = page_pool_dev_alloc_pages(chn->pg_pool);
-			if (!page) {
-				netdev_err(emac->ndev, "couldn't allocate rx page\n");
-				ret = -ENOMEM;
-				goto recycle_alloc_pg;
-			}
+		desc_avail = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
+		if (desc_avail < PRUETH_MAX_RX_DESC) {
+			netdev_err(emac->ndev,
+				   "not enough RX descriptors available %d < %d\n",
+				   desc_avail, PRUETH_MAX_RX_DESC);
+			return -ENOSPC;
+		}
 
-			ret = prueth_dma_rx_push_mapped(emac, chn, page, buf_size);
-			if (ret < 0) {
-				netdev_err(emac->ndev,
-					   "cannot submit page for rx chan %s ret %d\n",
-					   chn->name, ret);
-				page_pool_recycle_direct(chn->pg_pool, page);
-				goto recycle_alloc_pg;
-			}
+		prueth_rx_alloc_zc(emac, flow, PRUETH_MAX_RX_DESC);
+		return 0;
+	}
+
+	pool = prueth_create_page_pool(emac, rx_chn->dma_dev, rx_chn->descs_num, rx_flow);
+	if (IS_ERR(pool))
+		return PTR_ERR(pool);
+
+	rx_flow->pg_pool = pool;
+
+	desc_avail = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
+	if (desc_avail < PRUETH_MAX_RX_DESC) {
+		netdev_err(emac->ndev,
+			   "not enough RX descriptors available %d < %d\n",
+			   desc_avail, PRUETH_MAX_RX_DESC);
+		ret = -ENOSPC;
+		goto err_free_pushed;
+	}
+
+	for (i = 0; i < PRUETH_MAX_RX_DESC; ++i) {
+		page = page_pool_dev_alloc_pages(pool);
+		if (!page) {
+			netdev_err(emac->ndev, "couldn't allocate rx page\n");
+			ret = -ENOMEM;
+			goto err_free_pushed;
+		}
+
+		ret = prueth_dma_rx_push_mapped(emac, rx_chn, page, buf_size, flow);
+		if (ret < 0) {
+			netdev_err(emac->ndev,
+				   "cannot submit skb for rx chan %s ret %d\n",
+				   rx_flow->name, ret);
+			page_pool_recycle_direct(pool, page);
+			goto err_free_pushed;
 		}
 	}
 
 	return 0;
 
-recycle_alloc_pg:
-	prueth_reset_rx_chan(&emac->rx_chns, PRUETH_MAX_RX_FLOWS, false);
-
+err_free_pushed:
+	/* i pages were successfully pushed to the ring.  Reset the channel
+	 * to drain them back and recycle via prueth_rx_cleanup before the
+	 * caller destroys the page pool.
+	 */
+	k3_udma_glue_reset_rx_chn(rx_chn->rx_chn, flow, rx_chn,
+				   prueth_rx_cleanup);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(prueth_prepare_rx_chan);
+EXPORT_SYMBOL_GPL(prueth_prepare_rx_flow);
 
 void prueth_reset_tx_chan(struct prueth_emac *emac, int ch_num,
 			  bool free_skb)
@@ -1557,16 +1638,20 @@ void prueth_reset_tx_chan(struct prueth_emac *emac, int ch_num,
 }
 EXPORT_SYMBOL_GPL(prueth_reset_tx_chan);
 
-void prueth_reset_rx_chan(struct prueth_rx_chn *chn,
-			  int num_flows, bool disable)
+void prueth_reset_rx_chan(struct prueth_emac *emac, bool disable)
 {
 	int i;
+	int num_flows = emac->rx_flow_num;
+	struct prueth_rx_chn *chn;
+
+	chn = &emac->rx_chns;
 
 	for (i = 0; i < num_flows; i++)
 		k3_udma_glue_reset_rx_chn(chn->rx_chn, i, chn,
 					  prueth_rx_cleanup);
+
 	if (disable)
-		k3_udma_glue_disable_rx_chn(chn->rx_chn);
+		k3_udma_glue_disable_rx_chn(emac->rx_chns.rx_chn);
 }
 EXPORT_SYMBOL_GPL(prueth_reset_rx_chan);
 
@@ -1752,7 +1837,9 @@ void prueth_netdev_exit(struct prueth *prueth,
 	if (of_phy_is_fixed_link(emac->phy_node))
 		of_phy_deregister_fixed_link(emac->phy_node);
 
-	netif_napi_del(&emac->napi_rx);
+	/* Free any rules added while the interface was down */
+	if (!emac->is_sr1)
+		icssg_rxnfc_rule_cleanup(emac);
 
 	pruss_release_mem_region(prueth->pruss, &emac->dram);
 	free_netdev(emac->ndev);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_config.h b/drivers/net/ethernet/ti/icssg/icssg_config.h
index 60d69744ffae2..25f5863d27028 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_config.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_config.h
@@ -23,7 +23,12 @@ struct icssg_flow_cfg {
 #define PRUETH_NAV_SW_DATA_SIZE	16	/* SW related data size */
 #define PRUETH_MAX_TX_DESC	512
 #define PRUETH_MAX_RX_DESC	512
-#define PRUETH_MAX_RX_FLOWS	1	/* excluding default flow */
+
+/* There are 4 Tx DMA channels, but the highest priority is CH3 (thread 3)
+ * and lower three are lower priority channels or threads.
+ */
+#define PRUETH_MAX_TX_QUEUES	4
+#define PRUETH_MAX_RX_FLOWS	8
 #define PRUETH_RX_FLOW_DATA	0
 
 /* Defines for forwarding path buffer pools:
diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
index b715af21d23ac..8af4bba62efa7 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
@@ -140,13 +140,14 @@ static int emac_set_channels(struct net_device *ndev,
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
 
-	/* Check if interface is up. Can change the num queues when
-	 * the interface is down.
+	/* Check if interface is up. Can't change the num queues when
+	 * the interface is up.
 	 */
 	if (netif_running(emac->ndev))
 		return -EBUSY;
 
 	emac->tx_ch_num = ch->tx_count;
+	emac->rx_flow_num = ch->rx_count;
 
 	if (emac->is_sr1)
 		emac->tx_ch_num++;
@@ -159,15 +160,17 @@ static void emac_get_channels(struct net_device *ndev,
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
 
-	ch->max_rx = 1;
+	ch->max_rx = ICSSG_MAX_RFLOWS;
 	ch->max_tx = PRUETH_MAX_TX_QUEUES;
 
 	/* Disable multiple TX channels due to timeouts
 	 * when using more than one queue */
-	if (emac->is_sr1)
+	if (emac->is_sr1) {
+		ch->max_rx = 1;
 		ch->max_tx = 1;
+	}
 
-	ch->rx_count = 1;
+	ch->rx_count = emac->rx_flow_num;
 	ch->tx_count = emac->tx_ch_num;
 
 	if (emac->is_sr1)
@@ -213,11 +216,13 @@ static int emac_get_coalesce(struct net_device *ndev,
 			     struct netlink_ext_ack *extack)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_rx_flow *flow = &rx_chn->flows[0];
 	struct prueth_tx_chn *tx_chn;
 
 	tx_chn = &emac->tx_chns[0];
 
-	coal->rx_coalesce_usecs = emac->rx_pace_timeout_ns / 1000;
+	coal->rx_coalesce_usecs = flow->rx_pace_timeout_ns / 1000;
 	coal->tx_coalesce_usecs = tx_chn->tx_pace_timeout_ns / 1000;
 
 	return 0;
@@ -245,8 +250,10 @@ static int emac_set_coalesce(struct net_device *ndev,
 			     struct netlink_ext_ack *extack)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
 	struct prueth *prueth = emac->prueth;
 	struct prueth_tx_chn *tx_chn;
+	int i;
 
 	tx_chn = &emac->tx_chns[0];
 
@@ -264,7 +271,8 @@ static int emac_set_coalesce(struct net_device *ndev,
 		coal->tx_coalesce_usecs = ICSSG_MIN_COALESCE_USECS;
 	}
 
-	emac->rx_pace_timeout_ns = coal->rx_coalesce_usecs * 1000;
+	for (i = 0; i < PRUETH_MAX_RX_FLOWS; i++)
+		rx_chn->flows[i].rx_pace_timeout_ns = coal->rx_coalesce_usecs * 1000;
 	tx_chn->tx_pace_timeout_ns = coal->tx_coalesce_usecs * 1000;
 
 	return 0;
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index 9bb67e185a3ea..bda6d92a8158d 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -36,8 +36,6 @@
 #include "icssg_switchdev.h"
 #include "../k3-cppi-desc-pool.h"
 
-#define PRUETH_MODULE_DESCRIPTION "PRUSS ICSSG Ethernet driver"
-
 #define DEFAULT_VID		1
 #define DEFAULT_PORT_MASK	1
 #define DEFAULT_UNTAG_MASK	1
@@ -50,8 +48,6 @@
 #define PRUETH_RX_DMA_ATTR			(DMA_ATTR_SKIP_CPU_SYNC |\
 						 DMA_ATTR_WEAK_ORDERING)
 
-/* CTRLMMR_ICSSG_RGMII_CTRL register bits */
-#define ICSSG_CTRL_RGMII_ID_MODE                BIT(24)
 
 static void emac_adjust_link(struct net_device *ndev);
 
@@ -403,20 +399,6 @@ static void emac_adjust_link(struct net_device *ndev)
 	}
 }
 
-static enum hrtimer_restart emac_rx_timer_callback(struct hrtimer *timer)
-{
-	struct prueth_emac *emac =
-			container_of(timer, struct prueth_emac, rx_hrtimer);
-	int rx_flow = PRUETH_RX_FLOW_DATA;
-
-	if (emac->rx_chns.irq_disabled) {
-		/* re-enable the RX IRQ */
-		emac->rx_chns.irq_disabled = false;
-		enable_irq(emac->rx_chns.irq[rx_flow]);
-	}
-	return HRTIMER_NORESTART;
-}
-
 static int emac_phy_connect(struct prueth_emac *emac)
 {
 	struct prueth *prueth = emac->prueth;
@@ -587,43 +569,6 @@ const struct icss_iep_clockops prueth_iep_clockops = {
 	.perout_enable = prueth_perout_enable,
 };
 
-static void prueth_destroy_xdp_rxqs(struct prueth_emac *emac)
-{
-	struct xdp_rxq_info *rxq = &emac->rx_chns.xdp_rxq;
-
-	if (xdp_rxq_info_is_reg(rxq))
-		xdp_rxq_info_unreg(rxq);
-}
-
-static int prueth_create_xdp_rxqs(struct prueth_emac *emac)
-{
-	struct xdp_rxq_info *rxq = &emac->rx_chns.xdp_rxq;
-	struct page_pool *pool = emac->rx_chns.pg_pool;
-	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
-	int ret;
-
-	ret = xdp_rxq_info_reg(rxq, emac->ndev, 0, emac->napi_rx.napi_id);
-	if (ret)
-		return ret;
-
-	if (rx_chn->xsk_pool) {
-		ret = xdp_rxq_info_reg_mem_model(rxq, MEM_TYPE_XSK_BUFF_POOL, NULL);
-		if (ret)
-			goto xdp_unreg;
-		xsk_pool_set_rxq_info(rx_chn->xsk_pool, rxq);
-	} else {
-		ret = xdp_rxq_info_reg_mem_model(rxq, MEM_TYPE_PAGE_POOL, pool);
-		if (ret)
-			goto xdp_unreg;
-	}
-
-	return 0;
-
-xdp_unreg:
-	prueth_destroy_xdp_rxqs(emac);
-	return ret;
-}
-
 static int icssg_prueth_add_mcast(struct net_device *ndev, const u8 *addr)
 {
 	struct net_device *real_dev;
@@ -883,14 +828,14 @@ static int icssg_update_vlan_mcast(struct net_device *vdev, int vid,
 static void prueth_set_xsk_pool(struct prueth_emac *emac, u16 queue_id)
 {
 	struct prueth_tx_chn *tx_chn = &emac->tx_chns[queue_id];
-	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_rx_flow *rx_flow = &emac->rx_chns.flows[queue_id];
 
-	if (emac->xsk_qid != queue_id) {
-		rx_chn->xsk_pool = NULL;
-		tx_chn->xsk_pool = NULL;
-	} else {
-		rx_chn->xsk_pool = xsk_get_pool_from_qid(emac->ndev, queue_id);
+	if (test_bit(queue_id, emac->xsk_queues)) {
+		rx_flow->xsk_pool = xsk_get_pool_from_qid(emac->ndev, queue_id);
 		tx_chn->xsk_pool = xsk_get_pool_from_qid(emac->ndev, queue_id);
+	} else {
+		rx_flow->xsk_pool = NULL;
+		tx_chn->xsk_pool = NULL;
 	}
 }
 
@@ -921,7 +866,39 @@ static void prueth_destroy_txq(struct prueth_emac *emac)
 	}
 }
 
-static void prueth_destroy_rxq(struct prueth_emac *emac)
+static void prueth_destroy_rxq(struct prueth_emac *emac, int qid)
+{
+	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_rx_flow *flow = &rx_chn->flows[qid];
+	dma_addr_t desc_dma;
+
+	napi_disable(&flow->napi_rx);
+	hrtimer_cancel(&flow->rx_hrtimer);
+
+	/* k3_udma_glue_reset_rx_chn() only drains the FDQ; it resets the
+	 * completion ring (RXCQ) without freeing descriptors still in it.
+	 * Teardown posts TDCM only to flow 0's RXCQ; flows 1..N have no
+	 * NAPI trigger to drain their RXCQs. Drain each flow's RXCQ here
+	 * so page_pool_destroy() finds no inflight pages.
+	 */
+	while (!k3_udma_glue_pop_rx_chn(rx_chn->rx_chn, qid, &desc_dma)) {
+		if (!cppi5_desc_is_tdcm(desc_dma))
+			prueth_rx_cleanup(rx_chn, desc_dma);
+	}
+
+	k3_udma_glue_reset_rx_chn(rx_chn->rx_chn, flow->id, rx_chn,
+				  prueth_rx_cleanup);
+
+	if (xdp_rxq_info_is_reg(&flow->xdp_rxq))
+		xdp_rxq_info_unreg(&flow->xdp_rxq);
+
+	if (flow->pg_pool) {
+		page_pool_destroy(flow->pg_pool);
+		flow->pg_pool = NULL;
+	}
+}
+
+static void prueth_destroy_rxqs(struct prueth_emac *emac)
 {
 	int i, ret;
 
@@ -929,16 +906,14 @@ static void prueth_destroy_rxq(struct prueth_emac *emac)
 	reinit_completion(&emac->tdown_complete);
 	k3_udma_glue_tdown_rx_chn(emac->rx_chns.rx_chn, true);
 
-	/* When RX DMA Channel Teardown is initiated, it will result in an
-	 * interrupt and a Teardown Completion Marker (TDCM) is queued into
-	 * the RX Completion queue. Acknowledging the interrupt involves
-	 * popping the TDCM descriptor from the RX Completion queue via the
-	 * RX NAPI Handler. To avoid timing out when waiting for the TDCM to
-	 * be popped, schedule the RX NAPI handler to run immediately.
+	/* When RX DMA Channel Teardown is initiated, the hardware posts a
+	 * Teardown Completion Marker (TDCM) to flow 0's RXCQ. Schedule flow
+	 * 0's NAPI unconditionally so the TDCM is popped promptly regardless
+	 * of whether the RX IRQ is currently disabled by hrtimer coalescing.
 	 */
-	if (!napi_if_scheduled_mark_missed(&emac->napi_rx)) {
-		if (napi_schedule_prep(&emac->napi_rx))
-			__napi_schedule(&emac->napi_rx);
+	if (!napi_if_scheduled_mark_missed(&emac->rx_chns.flows[0].napi_rx)) {
+		if (napi_schedule_prep(&emac->rx_chns.flows[0].napi_rx))
+			__napi_schedule(&emac->rx_chns.flows[0].napi_rx);
 	}
 
 	ret = wait_for_completion_timeout(&emac->tdown_complete,
@@ -946,15 +921,9 @@ static void prueth_destroy_rxq(struct prueth_emac *emac)
 	if (!ret)
 		netdev_err(emac->ndev, "rx teardown timeout\n");
 
-	for (i = 0; i < PRUETH_MAX_RX_FLOWS; i++) {
-		napi_disable(&emac->napi_rx);
-		hrtimer_cancel(&emac->rx_hrtimer);
-		k3_udma_glue_reset_rx_chn(emac->rx_chns.rx_chn, i,
-					  &emac->rx_chns,
-					  prueth_rx_cleanup);
-	}
+	for (i = 0; i < emac->rx_flow_num; i++)
+		prueth_destroy_rxq(emac, i);
 
-	prueth_destroy_xdp_rxqs(emac);
 	k3_udma_glue_disable_rx_chn(emac->rx_chns.rx_chn);
 }
 
@@ -978,27 +947,81 @@ static int prueth_create_txq(struct prueth_emac *emac)
 	return ret;
 }
 
-static int prueth_create_rxq(struct prueth_emac *emac)
+static int prueth_create_rxq(struct prueth_emac *emac, int id)
 {
+	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_rx_flow *flow = &rx_chn->flows[id];
+	struct xdp_rxq_info *rxq = &flow->xdp_rxq;
 	int ret;
 
-	ret = prueth_prepare_rx_chan(emac, &emac->rx_chns, PRUETH_MAX_PKT_SIZE);
+	ret = prueth_prepare_rx_flow(emac, id);
 	if (ret)
-		return ret;
+		goto err;
 
-	ret = k3_udma_glue_enable_rx_chn(emac->rx_chns.rx_chn);
+	ret = xdp_rxq_info_reg(rxq, emac->ndev, id, flow->napi_rx.napi_id);
 	if (ret)
-		goto reset_rx_chn;
+		goto err;
 
-	ret = prueth_create_xdp_rxqs(emac);
-	if (ret)
-		goto reset_rx_chn;
+	if (flow->xsk_pool) {
+		ret = xdp_rxq_info_reg_mem_model(rxq, MEM_TYPE_XSK_BUFF_POOL, NULL);
+		if (ret)
+			goto err;
+		xsk_pool_set_rxq_info(flow->xsk_pool, rxq);
+	} else {
+		ret = xdp_rxq_info_reg_mem_model(rxq, MEM_TYPE_PAGE_POOL, flow->pg_pool);
+		if (ret)
+			goto err;
+	}
+
+	napi_enable(&flow->napi_rx);
+	/* Re-enable IRQ now that NAPI is live. IRQ may have been left
+	 * disabled by hrtimer coalescing or a previous destroy_rxq.
+	 */
+	if (flow->irq_disabled) {
+		flow->irq_disabled = false;
+		enable_irq(flow->irq);
+	}
+	return 0;
+
+err:
+	/* napi_enable() not yet called; prueth_destroy_rxq() calls
+	 * napi_disable() which busy-waits for NAPI_STATE_SCHED to clear —
+	 * a bit set by netif_napi_add() that only clears after napi_enable().
+	 * Clean up directly to avoid hanging.
+	 */
+	hrtimer_cancel(&flow->rx_hrtimer);
+	k3_udma_glue_reset_rx_chn(rx_chn->rx_chn, id, rx_chn, prueth_rx_cleanup);
+	if (xdp_rxq_info_is_reg(&flow->xdp_rxq))
+		xdp_rxq_info_unreg(&flow->xdp_rxq);
+	if (flow->pg_pool) {
+		page_pool_destroy(flow->pg_pool);
+		flow->pg_pool = NULL;
+	}
+	return ret;
+}
+
+static int prueth_create_rxqs(struct prueth_emac *emac)
+{
+	int i, ret;
+
+	for (i = 0; i < emac->rx_flow_num; i++) {
+		ret = prueth_create_rxq(emac, i);
+		if (ret) {
+			netdev_err(emac->ndev, "failed to create rxq for flow %d: %d\n",
+				   i, ret);
+			goto err;
+		}
+	}
 
-	napi_enable(&emac->napi_rx);
+	/* All flows share the same DMA channel */
+	ret = k3_udma_glue_enable_rx_chn(emac->rx_chns.rx_chn);
+	if (ret)
+		goto err;
 	return 0;
 
-reset_rx_chn:
-	prueth_reset_rx_chan(&emac->rx_chns, PRUETH_MAX_RX_FLOWS, false);
+err:
+	for (--i; i >= 0; i--)
+		prueth_destroy_rxq(emac, i);
 	return ret;
 }
 
@@ -1018,8 +1041,6 @@ static int emac_ndo_open(struct net_device *ndev)
 	struct prueth *prueth = emac->prueth;
 	int slice = prueth_emac_slice(emac);
 	struct device *dev = prueth->dev;
-	int max_rx_flows;
-	int rx_flow;
 
 	/* set h/w MAC as user might have re-configured */
 	ether_addr_copy(emac->mac_addr, ndev->dev_addr);
@@ -1034,7 +1055,12 @@ static int emac_ndo_open(struct net_device *ndev)
 		return ret;
 	}
 
-	emac->xsk_qid = -EINVAL;
+	ret = netif_set_real_num_rx_queues(ndev, emac->rx_flow_num);
+	if (ret) {
+		dev_err(dev, "cannot set real number of rx queues\n");
+		return ret;
+	}
+
 	init_completion(&emac->cmd_complete);
 	ret = prueth_init_tx_chns(emac);
 	if (ret) {
@@ -1042,9 +1068,13 @@ static int emac_ndo_open(struct net_device *ndev)
 		return ret;
 	}
 
-	max_rx_flows = PRUETH_MAX_RX_FLOWS;
-	ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx",
-				  max_rx_flows, PRUETH_MAX_RX_DESC);
+	/* Clear XSK state on open: any pool bound while interface was down
+	 * is no longer valid. User must re-enable AF_XDP after bringing
+	 * the interface up.
+	 */
+	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);
+
+	ret = prueth_init_rx_chns(emac);
 	if (ret) {
 		dev_err(dev, "failed to init rx channel: %d\n", ret);
 		goto cleanup_tx;
@@ -1054,14 +1084,9 @@ static int emac_ndo_open(struct net_device *ndev)
 	if (ret)
 		goto cleanup_rx;
 
-	/* we use only the highest priority flow for now i.e. @irq[3] */
-	rx_flow = PRUETH_RX_FLOW_DATA;
-	ret = request_irq(emac->rx_chns.irq[rx_flow], prueth_rx_irq,
-			  IRQF_TRIGGER_HIGH, dev_name(dev), emac);
-	if (ret) {
-		dev_err(dev, "unable to request RX IRQ\n");
+	ret = prueth_ndev_add_rx_napi(emac);
+	if (ret)
 		goto cleanup_napi;
-	}
 
 	if (!prueth->emacs_initialized) {
 		ret = prueth_emac_common_start(prueth);
@@ -1081,13 +1106,19 @@ static int emac_ndo_open(struct net_device *ndev)
 
 	icssg_mii_update_mtu(prueth->mii_rt, slice, ndev->max_mtu);
 
+	/* Re-program FT3 filters and classifier OR tables from the persistent
+	 * rule list. icssg_class_default() called above resets all classifiers,
+	 * so rules must be restored here on every open/restart.
+	 */
+	icssg_rxnfc_rule_restore(emac);
+
 	ret = request_threaded_irq(emac->tx_ts_irq, NULL, prueth_tx_ts_irq,
 				   IRQF_ONESHOT, dev_name(dev), emac);
 	if (ret)
 		goto stop;
 
 	/* Prepare RX */
-	ret = prueth_create_rxq(emac);
+	ret = prueth_create_rxqs(emac);
 	if (ret)
 		goto free_tx_ts_irq;
 
@@ -1105,18 +1136,18 @@ static int emac_ndo_open(struct net_device *ndev)
 	return 0;
 
 destroy_rxq:
-	prueth_destroy_rxq(emac);
+	prueth_destroy_rxqs(emac);
 free_tx_ts_irq:
 	free_irq(emac->tx_ts_irq, emac);
 stop:
 	if (!prueth->emacs_initialized)
 		prueth_emac_common_stop(prueth);
 free_rx_irq:
-	free_irq(emac->rx_chns.irq[rx_flow], emac);
+	prueth_ndev_del_rx_napi(emac, emac->rx_flow_num);
 cleanup_napi:
 	prueth_ndev_del_tx_napi(emac, emac->tx_ch_num);
 cleanup_rx:
-	prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows);
+	prueth_cleanup_rx_chns(emac);
 cleanup_tx:
 	prueth_cleanup_tx_chns(emac);
 
@@ -1136,6 +1167,8 @@ static int emac_ndo_stop(struct net_device *ndev)
 	struct prueth_emac *emac = netdev_priv(ndev);
 	struct prueth *prueth = emac->prueth;
 
+	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);
+
 	/* inform the upper layers. */
 	netif_tx_stop_all_queues(ndev);
 
@@ -1149,7 +1182,7 @@ static int emac_ndo_stop(struct net_device *ndev)
 		__dev_mc_unsync(ndev, icssg_prueth_del_mcast);
 
 	prueth_destroy_txq(emac);
-	prueth_destroy_rxq(emac);
+	prueth_destroy_rxqs(emac);
 
 	cancel_work_sync(&emac->rx_mode_work);
 
@@ -1162,10 +1195,10 @@ static int emac_ndo_stop(struct net_device *ndev)
 
 	free_irq(emac->tx_ts_irq, emac);
 
-	free_irq(emac->rx_chns.irq[PRUETH_RX_FLOW_DATA], emac);
+	prueth_ndev_del_rx_napi(emac, emac->rx_flow_num);
 	prueth_ndev_del_tx_napi(emac, emac->tx_ch_num);
 
-	prueth_cleanup_rx_chns(emac, &emac->rx_chns, PRUETH_MAX_RX_FLOWS);
+	prueth_cleanup_rx_chns(emac);
 	prueth_cleanup_tx_chns(emac);
 
 	prueth->emacs_initialized--;
@@ -1467,11 +1500,11 @@ static int emac_xdp_setup(struct prueth_emac *emac, struct netdev_bpf *bpf)
 static int prueth_xsk_pool_enable(struct prueth_emac *emac,
 				  struct xsk_buff_pool *pool, u16 queue_id)
 {
-	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
 	u32 frame_size;
 	int ret;
 
 	if (queue_id >= PRUETH_MAX_RX_FLOWS ||
+	    queue_id >= emac->rx_flow_num ||
 	    queue_id >= emac->tx_ch_num) {
 		netdev_err(emac->ndev, "Invalid XSK queue ID %d\n", queue_id);
 		return -EINVAL;
@@ -1481,7 +1514,7 @@ static int prueth_xsk_pool_enable(struct prueth_emac *emac,
 	if (frame_size < PRUETH_MAX_PKT_SIZE)
 		return -EOPNOTSUPP;
 
-	ret = xsk_pool_dma_map(pool, rx_chn->dma_dev, PRUETH_RX_DMA_ATTR);
+	ret = xsk_pool_dma_map(pool, emac->rx_chns.dma_dev, PRUETH_RX_DMA_ATTR);
 	if (ret) {
 		netdev_err(emac->ndev, "Failed to map XSK pool: %d\n", ret);
 		return ret;
@@ -1490,45 +1523,66 @@ static int prueth_xsk_pool_enable(struct prueth_emac *emac,
 	if (netif_running(emac->ndev)) {
 		/* stop packets from wire for graceful teardown */
 		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
-		if (ret)
+		if (ret) {
+			xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);
 			return ret;
-		prueth_destroy_rxq(emac);
+		}
+		prueth_destroy_rxq(emac, queue_id);
 	}
 
-	emac->xsk_qid = queue_id;
+	set_bit(queue_id, emac->xsk_queues);
 	prueth_set_xsk_pool(emac, queue_id);
 
 	if (netif_running(emac->ndev)) {
-		ret = prueth_create_rxq(emac);
+		ret = prueth_create_rxq(emac, queue_id);
 		if (ret) {
 			netdev_err(emac->ndev, "Failed to create RX queue: %d\n", ret);
-			return ret;
+			goto err_napi;
 		}
+
 		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
 		if (ret) {
-			prueth_destroy_rxq(emac);
-			return ret;
+			netdev_err(emac->ndev, "Failed to enable port forwarding: %d\n", ret);
+			prueth_destroy_rxq(emac, queue_id);
+			goto err_napi;
 		}
+
 		ret = prueth_xsk_wakeup(emac->ndev, queue_id, XDP_WAKEUP_RX);
 		if (ret)
-			return ret;
+			netdev_err(emac->ndev, "xsk wakeup failed: %d\n", ret);
 	}
 
 	return 0;
+
+err_napi:
+	clear_bit(queue_id, emac->xsk_queues);
+	prueth_set_xsk_pool(emac, queue_id);
+	xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);
+	/* Best-effort: recreate the page pool flow we tore down.
+	 * On failure the queue is dead until next ifdown/ifup.
+	 */
+	if (!prueth_create_rxq(emac, queue_id))
+		icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
+	else
+		netdev_err(emac->ndev,
+			   "failed to restore RX queue %d; bring interface down to recover\n",
+			   queue_id);
+	return ret;
 }
 
 static int prueth_xsk_pool_disable(struct prueth_emac *emac, u16 queue_id)
 {
 	struct xsk_buff_pool *pool;
-	int ret;
+	int ret = 0;
 
 	if (queue_id >= PRUETH_MAX_RX_FLOWS ||
+	    queue_id >= emac->rx_flow_num ||
 	    queue_id >= emac->tx_ch_num) {
 		netdev_err(emac->ndev, "Invalid XSK queue ID %d\n", queue_id);
 		return -EINVAL;
 	}
 
-	if (emac->xsk_qid != queue_id) {
+	if (!test_bit(queue_id, emac->xsk_queues)) {
 		netdev_err(emac->ndev, "XSK queue ID %d not registered\n", queue_id);
 		return -EINVAL;
 	}
@@ -1544,27 +1598,29 @@ static int prueth_xsk_pool_disable(struct prueth_emac *emac, u16 queue_id)
 		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
 		if (ret)
 			return ret;
-		prueth_destroy_rxq(emac);
+		prueth_destroy_rxq(emac, queue_id);
 	}
 
 	xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);
-	emac->xsk_qid = -EINVAL;
+	clear_bit(queue_id, emac->xsk_queues);
 	prueth_set_xsk_pool(emac, queue_id);
 
 	if (netif_running(emac->ndev)) {
-		ret = prueth_create_rxq(emac);
-		if (ret) {
-			netdev_err(emac->ndev, "Failed to create RX queue: %d\n", ret);
-			return ret;
-		}
-		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
-		if (ret) {
-			prueth_destroy_rxq(emac);
-			return ret;
-		}
+		ret = prueth_create_rxq(emac, queue_id);
+		if (ret)
+			netdev_err(emac->ndev,
+				   "failed to recreate RX queue %d after XSK disable; bring interface down to recover: %d\n",
+				   queue_id, ret);
+
+		/* Always re-enable port forwarding so the interface is not left
+		 * permanently disabled if prueth_create_rxq() failed due to a
+		 * transient descriptor shortage (inflight pages not yet returned
+		 * by the network stack).
+		 */
+		icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
 	}
 
-	return 0;
+	return ret;
 }
 
 /**
@@ -1593,25 +1649,31 @@ static int emac_ndo_bpf(struct net_device *ndev, struct netdev_bpf *bpf)
 int prueth_xsk_wakeup(struct net_device *ndev, u32 qid, u32 flags)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
-	struct prueth_tx_chn *tx_chn = &emac->tx_chns[qid];
-	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
+	struct prueth_tx_chn *tx_chn;
+	struct prueth_rx_flow *rx_flow;
 
-	if (emac->xsk_qid != qid) {
-		netdev_err(ndev, "XSK queue %d not registered\n", qid);
+	/* Bounds check before any array/bitmap access */
+	if (qid >= PRUETH_MAX_RX_FLOWS ||
+	    qid >= emac->rx_flow_num ||
+	    qid >= emac->tx_ch_num) {
+		netdev_err(ndev, "Invalid XSK queue ID %d\n", qid);
 		return -EINVAL;
 	}
 
-	if (qid >= PRUETH_MAX_RX_FLOWS || qid >= emac->tx_ch_num) {
-		netdev_err(ndev, "Invalid XSK queue ID %d\n", qid);
+	if (!test_bit(qid, emac->xsk_queues)) {
+		netdev_err(ndev, "XSK queue %d not registered\n", qid);
 		return -EINVAL;
 	}
 
+	tx_chn = &emac->tx_chns[qid];
+	rx_flow = &emac->rx_chns.flows[qid];
+
 	if (!tx_chn->xsk_pool) {
 		netdev_err(ndev, "XSK pool not registered for queue %d\n", qid);
 		return -EINVAL;
 	}
 
-	if (!rx_chn->xsk_pool) {
+	if (!rx_flow->xsk_pool) {
 		netdev_err(ndev, "XSK pool not registered for RX queue %d\n", qid);
 		return -EINVAL;
 	}
@@ -1624,9 +1686,9 @@ int prueth_xsk_wakeup(struct net_device *ndev, u32 qid, u32 flags)
 	}
 
 	if (flags & XDP_WAKEUP_RX) {
-		if (!napi_if_scheduled_mark_missed(&emac->napi_rx)) {
-			if (likely(napi_schedule_prep(&emac->napi_rx)))
-				__napi_schedule(&emac->napi_rx);
+		if (!napi_if_scheduled_mark_missed(&rx_flow->napi_rx)) {
+			if (likely(napi_schedule_prep(&rx_flow->napi_rx)))
+				__napi_schedule(&rx_flow->napi_rx);
 		}
 	}
 
@@ -1657,12 +1719,12 @@ static const struct net_device_ops emac_netdev_ops = {
 static int prueth_netdev_init(struct prueth *prueth,
 			      struct device_node *eth_node)
 {
-	int ret, num_tx_chn = PRUETH_MAX_TX_QUEUES;
 	struct prueth_emac *emac;
 	struct net_device *ndev;
 	enum prueth_port port;
 	const char *irq_name;
 	enum prueth_mac mac;
+	int ret;
 
 	port = prueth_node_port(eth_node);
 	if (port == PRUETH_PORT_INVALID)
@@ -1672,7 +1734,7 @@ static int prueth_netdev_init(struct prueth *prueth,
 	if (mac == PRUETH_MAC_INVALID)
 		return -EINVAL;
 
-	ndev = alloc_etherdev_mq(sizeof(*emac), num_tx_chn);
+	ndev = alloc_etherdev_mqs(sizeof(*emac), PRUETH_MAX_TX_QUEUES, PRUETH_MAX_RX_FLOWS);
 	if (!ndev)
 		return -ENOMEM;
 
@@ -1684,6 +1746,9 @@ static int prueth_netdev_init(struct prueth *prueth,
 	emac->ndev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
 	INIT_WORK(&emac->rx_mode_work, emac_ndo_set_rx_mode_work);
 
+	/* Initialize RX flow classification */
+	icssg_rxnfc_rule_init(emac);
+
 	INIT_DELAYED_WORK(&emac->stats_work, icssg_stats_work_handler);
 
 	ret = pruss_request_mem_region(prueth->pruss,
@@ -1697,6 +1762,14 @@ static int prueth_netdev_init(struct prueth *prueth,
 	}
 
 	emac->tx_ch_num = 1;
+	emac->rx_flow_num = 1;
+	emac->xsk_queues = devm_bitmap_zalloc(prueth->dev,
+					      PRUETH_MAX_RX_FLOWS, GFP_KERNEL);
+	if (!emac->xsk_queues) {
+		dev_err(prueth->dev, "failed to allocate xsk_queues bitmap\n");
+		ret = -ENOMEM;
+		goto free;
+	}
 
 	irq_name = "tx_ts0";
 	if (emac->port_id == PRUETH_PORT_MII1)
@@ -1783,11 +1856,7 @@ static int prueth_netdev_init(struct prueth *prueth,
 			      NETDEV_XDP_ACT_NDO_XMIT |
 			      NETDEV_XDP_ACT_XSK_ZEROCOPY);
 
-	netif_napi_add(ndev, &emac->napi_rx, icssg_napi_rx_poll);
-	hrtimer_setup(&emac->rx_hrtimer, &emac_rx_timer_callback, CLOCK_MONOTONIC,
-		      HRTIMER_MODE_REL_PINNED);
 	prueth->emac[mac] = emac;
-
 	return 0;
 
 free:
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
index df93d15c5b786..9feb1866d34c9 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
@@ -11,6 +11,7 @@
 #include <linux/bpf.h>
 #include <linux/bpf_trace.h>
 #include <linux/etherdevice.h>
+#include <linux/ethtool.h>
 #include <linux/genalloc.h>
 #include <linux/if_vlan.h>
 #include <linux/if_hsr.h>
@@ -132,18 +133,27 @@ struct prueth_tx_chn {
 	bool irq_disabled;
 };
 
+struct prueth_rx_flow {
+	u32 id;
+	struct prueth_emac *emac;
+	struct napi_struct napi_rx;
+	int irq;
+	bool irq_disabled;
+	struct hrtimer rx_hrtimer;
+	unsigned long rx_pace_timeout_ns;
+	struct page_pool *pg_pool;
+	struct xdp_rxq_info xdp_rxq;
+	struct xsk_buff_pool *xsk_pool;
+	char name[32];
+};
+
 struct prueth_rx_chn {
-	struct device *dev;
 	struct device *dma_dev;
 	struct k3_cppi_desc_pool *desc_pool;
 	struct k3_udma_glue_rx_channel *rx_chn;
+	struct prueth_emac *emac;
 	u32 descs_num;
-	unsigned int irq[ICSSG_MAX_RFLOWS];	/* separate irq per flow */
-	char name[32];
-	struct page_pool *pg_pool;
-	struct xdp_rxq_info xdp_rxq;
-	struct xsk_buff_pool *xsk_pool;
-	bool irq_disabled;
+	struct prueth_rx_flow flows[PRUETH_MAX_RX_FLOWS];
 };
 
 enum prueth_swdata_type {
@@ -162,6 +172,7 @@ enum prueth_tx_buff_type {
 
 struct prueth_swdata {
 	enum prueth_swdata_type type;
+	u32 flow_id;
 	union prueth_data {
 		struct sk_buff *skb;
 		struct page *page;
@@ -171,11 +182,6 @@ struct prueth_swdata {
 	} data;
 };
 
-/* There are 4 Tx DMA channels, but the highest priority is CH3 (thread 3)
- * and lower three are lower priority channels or threads.
- */
-#define PRUETH_MAX_TX_QUEUES	4
-
 #define PRUETH_MAX_TX_TS_REQUESTS	50 /* Max simultaneous TX_TS requests */
 
 /* XDP BPF state */
@@ -187,13 +193,32 @@ struct prueth_swdata {
 /* Minimum coalesce time in usecs for both Tx and Rx */
 #define ICSSG_MIN_COALESCE_USECS 20
 
+/* RX flow classification (ethtool) */
+#define ICSSG_RXNFC_MAX_RULES    15      /* Max user-installable rules */
+#define ICSSG_FT3_RESERVED_SLOTS BIT(14) /* Slot 14 reserved for HSR/PRP */
+
+/* RX flow classification rule structure */
+struct icssg_rxnfc_rule {
+	struct list_head list;
+	struct ethtool_rx_flow_spec flow_spec;  /* User-provided filter */
+	u16 ft3_slot;                            /* Allocated FT3 slot (0-15, excluding 14) */
+	int location;                            /* Rule location (user-provided) */
+	u32 queue_index;                         /* RX flow to route matches to */
+};
+
+struct prueth_rxnfc {
+	struct list_head rules;
+	struct mutex rxnfc_lock;
+	unsigned int rxnfc_rule_count;
+	u16 ft3_slots_used;
+};
+
 /* data for each emac port */
 struct prueth_emac {
 	bool is_sr1;
 	struct prueth *prueth;
 	struct net_device *ndev;
 	u8 mac_addr[6];
-	struct napi_struct napi_rx;
 	u32 msg_enable;
 
 	int link;
@@ -216,6 +241,7 @@ struct prueth_emac {
 	struct prueth_rx_chn rx_chns;
 	int rx_flow_id_base;
 	int tx_ch_num;
+	int rx_flow_num;
 
 	/* SR1.0 Management channel */
 	struct prueth_rx_chn rx_mgm_chn;
@@ -246,14 +272,13 @@ struct prueth_emac {
 	u64 stats[ICSSG_NUM_MIIG_STATS];
 	u64 pa_stats[ICSSG_NUM_PA_STATS];
 
-	/* RX IRQ Coalescing Related */
-	struct hrtimer rx_hrtimer;
-	unsigned long rx_pace_timeout_ns;
-
 	struct netdev_hw_addr_list vlan_mcast_list[MAX_VLAN_ID];
 	struct bpf_prog *xdp_prog;
 	struct xdp_attachment_info xdpi;
-	int xsk_qid;
+	unsigned long *xsk_queues;
+
+	/* RX flow classification via ethtool */
+	struct prueth_rxnfc rxnfc;
 };
 
 /* The buf includes headroom compatible with both skb and xdpf */
@@ -398,6 +423,17 @@ static inline int prueth_emac_slice(struct prueth_emac *emac)
 	}
 }
 
+/* RX flow classification functions */
+void icssg_rxnfc_rule_init(struct prueth_emac *emac);
+void icssg_rxnfc_rule_restore(struct prueth_emac *emac);
+void icssg_rxnfc_rule_cleanup(struct prueth_emac *emac);
+int icssg_rxnfc_rule_add(struct prueth_emac *emac, struct ethtool_rxnfc *info);
+int icssg_rxnfc_rule_del(struct prueth_emac *emac, u32 location);
+int icssg_rxnfc_rule_get(struct prueth_emac *emac, u32 location,
+			 struct ethtool_rx_flow_spec *fs);
+int icssg_rxnfc_rule_get_all(struct prueth_emac *emac, u32 *rule_locs,
+			     u32 rule_locs_capacity, u32 *rule_cnt);
+
 extern const struct ethtool_ops icssg_ethtool_ops;
 extern const struct dev_pm_ops prueth_dev_pm_ops;
 
@@ -455,30 +491,30 @@ void icssg_set_pvid(struct prueth *prueth, u8 vid, u8 port);
 int emac_fdb_flow_id_updated(struct prueth_emac *emac);
 #define prueth_napi_to_tx_chn(pnapi) \
 	container_of(pnapi, struct prueth_tx_chn, napi_tx)
+#define prueth_napi_to_rx_chn(pnapi) \
+	container_of(pnapi, struct prueth_rx_flow, napi_rx)
 
 void icssg_stats_work_handler(struct work_struct *work);
 void emac_update_hardware_stats(struct prueth_emac *emac);
 int emac_get_stat_by_name(struct prueth_emac *emac, char *stat_name);
 
 /* Common functions */
-void prueth_cleanup_rx_chns(struct prueth_emac *emac,
-			    struct prueth_rx_chn *rx_chn,
-			    int max_rflows);
+void prueth_cleanup_rx_chns(struct prueth_emac *emac);
 void prueth_cleanup_tx_chns(struct prueth_emac *emac);
 void prueth_ndev_del_tx_napi(struct prueth_emac *emac, int num);
+void prueth_ndev_del_rx_napi(struct prueth_emac *emac, int num);
 void prueth_xmit_free(struct prueth_tx_chn *tx_chn,
 		      struct cppi5_host_desc_t *desc);
 int emac_tx_complete_packets(struct prueth_emac *emac, int chn,
 			     int budget, bool *tdown);
 int prueth_ndev_add_tx_napi(struct prueth_emac *emac);
+int prueth_ndev_add_rx_napi(struct prueth_emac *emac);
 int prueth_init_tx_chns(struct prueth_emac *emac);
-int prueth_init_rx_chns(struct prueth_emac *emac,
-			struct prueth_rx_chn *rx_chn,
-			char *name, u32 max_rflows,
-			u32 max_desc_num);
+int prueth_init_rx_chns(struct prueth_emac *emac);
 int prueth_dma_rx_push_mapped(struct prueth_emac *emac,
 			      struct prueth_rx_chn *rx_chn,
-			      struct page *page, u32 buf_len);
+			      struct page *page, u32 buf_len,
+			      int flow_id);
 unsigned int prueth_rxbuf_total_len(unsigned int len);
 void emac_rx_timestamp(struct prueth_emac *emac,
 		       struct sk_buff *skb, u32 *psdata);
@@ -486,13 +522,11 @@ enum netdev_tx icssg_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev
 irqreturn_t prueth_rx_irq(int irq, void *dev_id);
 void prueth_cleanup_tx_ts(struct prueth_emac *emac);
 int icssg_napi_rx_poll(struct napi_struct *napi_rx, int budget);
-int prueth_prepare_rx_chan(struct prueth_emac *emac,
-			   struct prueth_rx_chn *chn,
-			   int buf_size);
+int prueth_prepare_rx_flow(struct prueth_emac *emac,
+			   int flow);
 void prueth_reset_tx_chan(struct prueth_emac *emac, int ch_num,
 			  bool free_skb);
-void prueth_reset_rx_chan(struct prueth_rx_chn *chn,
-			  int num_flows, bool disable);
+void prueth_reset_rx_chan(struct prueth_emac *emac, bool disable);
 void icssg_ndo_tx_timeout(struct net_device *ndev, unsigned int txqueue);
 int icssg_ndo_get_ts_config(struct net_device *ndev,
 			    struct kernel_hwtstamp_config *config);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
index 21a14b3bc889b..c166977b424ef 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
@@ -303,10 +303,10 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,
 	page = swdata->data.page;
 	cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
 
-	dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE);
+	page_pool_dma_sync_for_cpu(rx_chn->flows[flow_id].pg_pool, page, 0, PAGE_SIZE);
 	k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
 
-	new_page = page_pool_dev_alloc_pages(rx_chn->pg_pool);
+	new_page = page_pool_dev_alloc_pages(rx_chn->flows[flow_id].pg_pool);
 	/* if allocation fails we drop the packet but push the
 	 * descriptor back to the ring with old skb to prevent a stall
 	 */
@@ -319,14 +319,123 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,
 	}
 
 	/* queue another DMA */
-	ret = prueth_dma_rx_push_mapped(emac, &emac->rx_chns, new_page,
-					PRUETH_MAX_PKT_SIZE);
+	ret = prueth_dma_rx_push_mapped(emac, rx_chn, new_page,
+					PRUETH_MAX_PKT_SIZE, flow_id);
 	if (WARN_ON(ret < 0))
-		page_pool_recycle_direct(rx_chn->pg_pool, new_page);
+		page_pool_recycle_direct(rx_chn->flows[flow_id].pg_pool, new_page);
 
 	return page;
 }
 
+/* SR1-specific helpers for rx_mgm_chn */
+
+static int prueth_sr1_prepare_rx_mgm_flow(struct prueth_emac *emac, int flow, u32 buf_len)
+{
+	struct prueth_rx_flow *rx_flow;
+	struct prueth_rx_chn *rx_chn;
+	struct page_pool *pool;
+	struct page *page;
+	int desc_avail;
+	int i, ret;
+
+	rx_chn = &emac->rx_mgm_chn;
+	rx_flow = &rx_chn->flows[flow];
+
+	/* Initialize page pool for this flow - using simple page pool */
+	pool = page_pool_create(&(struct page_pool_params){
+		.order = 0,
+		.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
+		.pool_size = PRUETH_MAX_RX_MGM_DESC_SR1,
+		.nid = dev_to_node(emac->prueth->dev),
+		.dev = rx_chn->dma_dev,
+		.dma_dir = DMA_BIDIRECTIONAL,
+		.max_len = PAGE_SIZE,
+	});
+
+	if (IS_ERR(pool))
+		return PTR_ERR(pool);
+
+	rx_flow->pg_pool = pool;
+
+	desc_avail = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
+	if (desc_avail < PRUETH_MAX_RX_DESC)
+		netdev_warn(emac->ndev,
+			    "not enough RX descriptors available %d < %d\n",
+			    desc_avail, PRUETH_MAX_RX_DESC);
+
+	for (i = 0; i < desc_avail; i++) {
+		page = page_pool_dev_alloc_pages(rx_flow->pg_pool);
+		if (!page)
+			break;
+
+		ret = prueth_dma_rx_push_mapped(emac, rx_chn, page, buf_len, flow);
+		if (ret < 0) {
+			page_pool_recycle_direct(rx_flow->pg_pool, page);
+			netdev_err(emac->ndev, "failed to push rx mgm buf %d\n", ret);
+			break;
+		}
+	}
+
+	return 0;
+}
+
+static void prueth_sr1_cleanup_rx_mgm_chn(struct prueth_emac *emac)
+{
+	struct prueth_rx_chn *chn = &emac->rx_mgm_chn;
+	struct prueth_rx_flow *flow;
+	int i;
+
+	for (i = 0; i < PRUETH_MAX_RX_MGM_FLOWS_SR1; i++) {
+		flow = &chn->flows[i];
+		if (flow->pg_pool) {
+			page_pool_destroy(flow->pg_pool);
+			flow->pg_pool = NULL;
+		}
+	}
+
+	if (chn->desc_pool) {
+		k3_cppi_desc_pool_destroy(chn->desc_pool);
+		chn->desc_pool = NULL;
+	}
+
+	if (chn->rx_chn) {
+		k3_udma_glue_release_rx_chn(chn->rx_chn);
+		chn->rx_chn = NULL;
+	}
+}
+
+static void prueth_sr1_reset_rx_mgm_chn(struct prueth_emac *emac, bool disable)
+{
+	struct prueth_rx_chn *chn = &emac->rx_mgm_chn;
+	struct prueth_rx_flow *flow;
+	int i;
+
+	/* Disable mgm IRQs before UDMA reset to prevent handler re-entry */
+	for (i = 0; i < PRUETH_MAX_RX_MGM_FLOWS_SR1; i++) {
+		flow = &chn->flows[i];
+		if (flow->irq <= 0)
+			continue;
+		if (!flow->irq_disabled) {
+			disable_irq(flow->irq);
+			flow->irq_disabled = true;
+		}
+	}
+
+	for (i = 0; i < PRUETH_MAX_RX_MGM_FLOWS_SR1; i++)
+		k3_udma_glue_reset_rx_chn(chn->rx_chn, i, chn, prueth_rx_cleanup);
+
+	if (disable)
+		k3_udma_glue_disable_rx_chn(chn->rx_chn);
+	else
+		for (i = 0; i < PRUETH_MAX_RX_MGM_FLOWS_SR1; i++) {
+			flow = &chn->flows[i];
+			if (flow->irq > 0 && flow->irq_disabled) {
+				flow->irq_disabled = false;
+				enable_irq(flow->irq);
+			}
+		}
+}
+
 static void prueth_tx_ts_sr1(struct prueth_emac *emac,
 			     struct emac_tx_ts_response_sr1 *tsr)
 {
@@ -484,9 +593,15 @@ static int emac_ndo_open(struct net_device *ndev)
 	struct prueth *prueth = emac->prueth;
 	int slice = prueth_emac_slice(emac);
 	struct device *dev = prueth->dev;
-	int max_rx_flows, rx_flow;
+	struct k3_udma_glue_rx_channel_cfg rx_cfg;
+	struct prueth_rx_flow *flow;
+	char udma_name[32];
+	u32 hdesc_size;
 	int ret, i;
 
+	if (slice < 0)
+		return slice;
+
 	/* clear SMEM and MSMC settings for all slices */
 	if (!prueth->emacs_initialized) {
 		memset_io(prueth->msmcram.va, 0, prueth->msmcram.size);
@@ -514,37 +629,123 @@ static int emac_ndo_open(struct net_device *ndev)
 		return ret;
 	}
 
-	max_rx_flows = PRUETH_MAX_RX_FLOWS_SR1;
-	ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx",
-				  max_rx_flows, PRUETH_MAX_RX_DESC);
+	emac->rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1;
+
+	/* Clear XSK state on open: any pool bound while interface was down
+	 * is no longer valid. User must re-enable AF_XDP after bringing
+	 * the interface up.
+	 */
+	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);
+
+	ret = prueth_init_rx_chns(emac);
 	if (ret) {
 		dev_err(dev, "failed to init rx channel: %d\n", ret);
 		goto cleanup_tx;
 	}
 
-	ret = prueth_init_rx_chns(emac, &emac->rx_mgm_chn, "rxmgm",
-				  PRUETH_MAX_RX_MGM_FLOWS_SR1,
-				  PRUETH_MAX_RX_MGM_DESC_SR1);
-	if (ret) {
-		dev_err(dev, "failed to init rx mgmt channel: %d\n",
-			ret);
+	/* Initialize management channel - SR1 specific */
+	emac->rx_mgm_chn.emac = emac;
+	hdesc_size = cppi5_hdesc_calc_size(true, PRUETH_NAV_PS_DATA_SIZE,
+					   PRUETH_NAV_SW_DATA_SIZE);
+	memset(&rx_cfg, 0, sizeof(rx_cfg));
+	rx_cfg.swdata_size = PRUETH_NAV_SW_DATA_SIZE;
+	rx_cfg.flow_id_num = PRUETH_MAX_RX_MGM_FLOWS_SR1;
+	rx_cfg.flow_id_base = -1;
+
+	snprintf(udma_name, sizeof(udma_name), "%s%d", "rxmgm", slice);
+	emac->rx_mgm_chn.rx_chn = k3_udma_glue_request_rx_chn(dev, udma_name,
+							     &rx_cfg);
+	if (IS_ERR(emac->rx_mgm_chn.rx_chn)) {
+		ret = PTR_ERR(emac->rx_mgm_chn.rx_chn);
+		emac->rx_mgm_chn.rx_chn = NULL;
+		dev_err(dev, "Failed to request rx mgm dma ch: %d\n", ret);
 		goto cleanup_rx;
 	}
 
+	emac->rx_mgm_chn.descs_num = PRUETH_MAX_RX_MGM_DESC_SR1 * rx_cfg.flow_id_num;
+	emac->rx_mgm_chn.dma_dev = k3_udma_glue_rx_get_dma_device(emac->rx_mgm_chn.rx_chn);
+	emac->rx_mgm_chn.desc_pool = k3_cppi_desc_pool_create_name(emac->rx_mgm_chn.dma_dev,
+								    emac->rx_mgm_chn.descs_num,
+								    hdesc_size,
+								    "rx_mgm_desc_pool");
+	if (IS_ERR(emac->rx_mgm_chn.desc_pool)) {
+		ret = PTR_ERR(emac->rx_mgm_chn.desc_pool);
+		emac->rx_mgm_chn.desc_pool = NULL;
+		dev_err(dev, "Failed to create rx mgm pool: %d\n", ret);
+		k3_udma_glue_release_rx_chn(emac->rx_mgm_chn.rx_chn);
+		emac->rx_mgm_chn.rx_chn = NULL;
+		goto cleanup_rx_mgm;
+	}
+
+	for (i = 0; i < rx_cfg.flow_id_num; i++) {
+		flow = &emac->rx_mgm_chn.flows[i];
+		flow->pg_pool = NULL;
+		flow->xsk_pool = NULL;
+	}
+
+	emac->rx_mgm_flow_id_base = k3_udma_glue_rx_get_flow_id_base(emac->rx_mgm_chn.rx_chn);
+	netdev_dbg(ndev, "rx mgm flow id base = %d\n", emac->rx_mgm_flow_id_base);
+
+	for (i = 0; i < rx_cfg.flow_id_num; i++) {
+		struct k3_ring_cfg rxring_cfg = {
+			.elm_size = K3_RINGACC_RING_ELSIZE_8,
+			.mode = K3_RINGACC_RING_MODE_RING,
+			.flags = 0,
+		};
+		struct k3_ring_cfg fdqring_cfg = {
+			.elm_size = K3_RINGACC_RING_ELSIZE_8,
+			.flags = K3_RINGACC_RING_SHARED,
+		};
+		struct k3_udma_glue_rx_flow_cfg rx_flow_cfg = {
+			.rx_cfg = rxring_cfg,
+			.rxfdq_cfg = fdqring_cfg,
+			.ring_rxq_id = K3_RINGACC_RING_ID_ANY,
+			.src_tag_lo_sel =
+				K3_UDMA_GLUE_SRC_TAG_LO_USE_REMOTE_SRC_TAG,
+		};
+
+		flow = &emac->rx_mgm_chn.flows[i];
+		flow->emac = emac;
+		flow->id = i;
+		flow->irq = -EINVAL;
+
+		rx_flow_cfg.ring_rxfdq0_id = K3_RINGACC_RING_ID_ANY;
+		rx_flow_cfg.rx_cfg.size = PRUETH_MAX_RX_MGM_DESC_SR1;
+		rx_flow_cfg.rxfdq_cfg.size = PRUETH_MAX_RX_MGM_DESC_SR1;
+		rx_flow_cfg.rxfdq_cfg.mode = prueth->pdata.fdqring_mode;
+
+		ret = k3_udma_glue_rx_flow_init(emac->rx_mgm_chn.rx_chn,
+					i, &rx_flow_cfg);
+		if (ret) {
+			dev_err(dev, "Failed to init rx mgm flow%d %d\n",
+				i, ret);
+			goto cleanup_rx_mgm;
+		}
+
+		flow->irq = k3_udma_glue_rx_get_irq(emac->rx_mgm_chn.rx_chn, i);
+		if (flow->irq <= 0) {
+			ret = flow->irq ? flow->irq : -ENXIO;
+			dev_err(dev, "Failed to get rx mgm dma irq: %d\n", ret);
+			goto cleanup_rx_mgm;
+		}
+
+		snprintf(flow->name, sizeof(flow->name),
+			 "%s-rxmgm%d-%d", dev_name(dev), slice, i);
+	}
+
 	ret = prueth_ndev_add_tx_napi(emac);
 	if (ret)
 		goto cleanup_rx_mgm;
 
-	/* we use only the highest priority flow for now i.e. @irq[3] */
-	rx_flow = PRUETH_RX_FLOW_DATA_SR1;
-	ret = request_irq(emac->rx_chns.irq[rx_flow], prueth_rx_irq,
-			  IRQF_TRIGGER_HIGH, dev_name(dev), emac);
+	/* Data NAPI and IRQ registration via common API */
+	ret = prueth_ndev_add_rx_napi(emac);
 	if (ret) {
-		dev_err(dev, "unable to request RX IRQ\n");
+		dev_err(dev, "unable to add rx napi\n");
 		goto cleanup_napi;
 	}
 
-	ret = request_threaded_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_RESPONSE_SR1],
+	/* Management channel IRQs - SR1 specific */
+	ret = request_threaded_irq(emac->rx_mgm_chn.flows[PRUETH_RX_MGM_FLOW_RESPONSE_SR1].irq,
 				   NULL, prueth_rx_mgm_rsp_thread,
 				   IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
 				   dev_name(dev), emac);
@@ -553,7 +754,7 @@ static int emac_ndo_open(struct net_device *ndev)
 		goto free_rx_irq;
 	}
 
-	ret = request_threaded_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1],
+	ret = request_threaded_irq(emac->rx_mgm_chn.flows[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1].irq,
 				   NULL, prueth_rx_mgm_ts_thread_sr1,
 				   IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
 				   dev_name(dev), emac);
@@ -570,11 +771,15 @@ static int emac_ndo_open(struct net_device *ndev)
 	icssg_mii_update_mtu(prueth->mii_rt, slice, ndev->max_mtu);
 
 	/* Prepare RX */
-	ret = prueth_prepare_rx_chan(emac, &emac->rx_chns, PRUETH_MAX_PKT_SIZE);
+	ret = prueth_prepare_rx_flow(emac, PRUETH_RX_FLOW_DATA_SR1);
 	if (ret)
 		goto stop;
 
-	ret = prueth_prepare_rx_chan(emac, &emac->rx_mgm_chn, 64);
+	ret = prueth_sr1_prepare_rx_mgm_flow(emac, PRUETH_RX_MGM_FLOW_RESPONSE_SR1, 64);
+	if (ret)
+		goto reset_rx_chn;
+
+	ret = prueth_sr1_prepare_rx_mgm_flow(emac, PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1, 64);
 	if (ret)
 		goto reset_rx_chn;
 
@@ -595,7 +800,7 @@ static int emac_ndo_open(struct net_device *ndev)
 	/* Enable NAPI in Tx and Rx direction */
 	for (i = 0; i < emac->tx_ch_num; i++)
 		napi_enable(&emac->tx_chns[i].napi_tx);
-	napi_enable(&emac->napi_rx);
+	napi_enable(&emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].napi_rx);
 
 	/* start PHY */
 	phy_start(ndev->phydev);
@@ -612,27 +817,29 @@ static int emac_ndo_open(struct net_device *ndev)
 	 */
 	prueth_reset_tx_chan(emac, i, false);
 reset_rx_mgm_chn:
-	prueth_reset_rx_chan(&emac->rx_mgm_chn,
-			     PRUETH_MAX_RX_MGM_FLOWS_SR1, true);
+	prueth_sr1_reset_rx_mgm_chn(emac, true);
 reset_rx_chn:
-	prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, false);
+	prueth_reset_rx_chan(emac, false);
+	if (emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool) {
+		page_pool_destroy(emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool);
+		emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool = NULL;
+	}
 stop:
 	prueth_emac_stop(emac);
 free_rx_mgmt_ts_irq:
-	free_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1],
+	free_irq(emac->rx_mgm_chn.flows[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1].irq,
 		 emac);
 free_rx_mgm_rsp_irq:
-	free_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_RESPONSE_SR1],
+	free_irq(emac->rx_mgm_chn.flows[PRUETH_RX_MGM_FLOW_RESPONSE_SR1].irq,
 		 emac);
 free_rx_irq:
-	free_irq(emac->rx_chns.irq[rx_flow], emac);
+	prueth_ndev_del_rx_napi(emac, 1);
 cleanup_napi:
 	prueth_ndev_del_tx_napi(emac, emac->tx_ch_num);
 cleanup_rx_mgm:
-	prueth_cleanup_rx_chns(emac, &emac->rx_mgm_chn,
-			       PRUETH_MAX_RX_MGM_FLOWS_SR1);
+	prueth_sr1_cleanup_rx_mgm_chn(emac);
 cleanup_rx:
-	prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows);
+	prueth_cleanup_rx_chns(emac);
 cleanup_tx:
 	prueth_cleanup_tx_chns(emac);
 
@@ -650,9 +857,7 @@ static int emac_ndo_open(struct net_device *ndev)
 static int emac_ndo_stop(struct net_device *ndev)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
-	int rx_flow = PRUETH_RX_FLOW_DATA_SR1;
 	struct prueth *prueth = emac->prueth;
-	int max_rx_flows;
 	int ret, i;
 
 	/* inform the upper layers. */
@@ -683,16 +888,20 @@ static int emac_ndo_stop(struct net_device *ndev)
 	for (i = 0; i < emac->tx_ch_num; i++)
 		napi_disable(&emac->tx_chns[i].napi_tx);
 
-	max_rx_flows = PRUETH_MAX_RX_FLOWS_SR1;
 	k3_udma_glue_tdown_rx_chn(emac->rx_chns.rx_chn, true);
 
-	prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, true);
+	prueth_reset_rx_chan(emac, true);
+
+	if (emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool) {
+		page_pool_destroy(emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool);
+		emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool = NULL;
+	}
+
 	/* Teardown RX MGM channel */
 	k3_udma_glue_tdown_rx_chn(emac->rx_mgm_chn.rx_chn, true);
-	prueth_reset_rx_chan(&emac->rx_mgm_chn,
-			     PRUETH_MAX_RX_MGM_FLOWS_SR1, true);
+	prueth_sr1_reset_rx_mgm_chn(emac, true);
 
-	napi_disable(&emac->napi_rx);
+	napi_disable(&emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].napi_rx);
 
 	/* Destroying the queued work in ndo_stop() */
 	cancel_delayed_work_sync(&emac->stats_work);
@@ -700,14 +909,14 @@ static int emac_ndo_stop(struct net_device *ndev)
 	/* stop PRUs */
 	prueth_emac_stop(emac);
 
-	free_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1], emac);
-	free_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_RESPONSE_SR1], emac);
-	free_irq(emac->rx_chns.irq[rx_flow], emac);
+	free_irq(emac->rx_mgm_chn.flows[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1].irq, emac);
+	free_irq(emac->rx_mgm_chn.flows[PRUETH_RX_MGM_FLOW_RESPONSE_SR1].irq, emac);
+	prueth_ndev_del_rx_napi(emac, PRUETH_MAX_RX_FLOWS_SR1);
 	prueth_ndev_del_tx_napi(emac, emac->tx_ch_num);
 	prueth_cleanup_tx_chns(emac);
 
-	prueth_cleanup_rx_chns(emac, &emac->rx_mgm_chn, PRUETH_MAX_RX_MGM_FLOWS_SR1);
-	prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows);
+	prueth_sr1_cleanup_rx_mgm_chn(emac);
+	prueth_cleanup_rx_chns(emac);
 
 	prueth->emacs_initialized--;
 
@@ -800,6 +1009,7 @@ static int prueth_netdev_init(struct prueth *prueth,
 	 * to send commands to the firmware
 	 */
 	emac->tx_ch_num = 2;
+	emac->rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1;
 
 	SET_NETDEV_DEV(ndev, prueth->dev);
 	spin_lock_init(&emac->lock);
@@ -871,7 +1081,6 @@ static int prueth_netdev_init(struct prueth *prueth,
 	ndev->hw_features = NETIF_F_SG;
 	ndev->features = ndev->hw_features;
 
-	netif_napi_add(ndev, &emac->napi_rx, icssg_napi_rx_poll);
 	prueth->emac[mac] = emac;
 
 	return 0;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support
  2026-12-03 12:14 [PATCH net-next v2 0/2] net: ti: icssg: Multi-flow RX and ethtool RX flow classification Meghana Malladi
  2026-12-03 12:14 ` [PATCH net-next v2 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI Meghana Malladi
@ 2026-12-03 12:14 ` Meghana Malladi
  2026-12-04 12:44   ` sashiko-bot
  2026-12-04 13:25   ` netdev-bot+sashiko
  1 sibling, 2 replies; 7+ messages in thread
From: Meghana Malladi @ 2026-12-03 12:14 UTC (permalink / raw)
  To: marco.crivellari, kees+treewide, laixiangwu, philippe.schenker,
	haokexin, devnexen, horms, m-malladi, sdf, john.fastabend, hawk,
	daniel, ast, pabeni, kuba, edumazet, davem, andrew+netdev
  Cc: bpf, netdev, linux-arm-kernel, srk, Vignesh Raghavendra,
	Roger Quadros, danishanwar

Enable dynamic RX flow classification via ethtool set_rxnfc/get_rxnfc.
Users can install/remove filter rules to steer packets to specific RX flows
based on EtherType patterns via FT3 hardware filters.

- Add RXNFC rule tracking structures and lifecycle management
- Implement ethtool get_rxnfc/set_rxnfc callbacks
- FT3 slot allocation and hardware programming for pattern matching
- RX classifier OR table updates based on active rules
- Max 15 rules per EMAC, using FT3 slots 0-13,15 (slot 14 reserved)
- Reserve FT3 slot 9 when HSR offload is active: classifier 10's OR_EN
  (RX_CLASS_OR_DUP_PTP) has slot 9 set, so a user rule there would
  inadvertently trigger the HSR PTP duplicate classifier

Known limitation:
- ndev->stats.rx_errors/rx_dropped racy with concurrent NAPIs;
  per-cpu stats refactor deferred.

Signed-off-by: Meghana Malladi <m-malladi@ti.com>
---

Changelog for v2-v1:
  - prueth_emac_restart(): call icssg_rxnfc_rule_restore() for both ports;
    rules were lost after bridge/HSR mode change
  - icssg_rxnfc_classifier_update(): RMW for classifier 0 preserves BC|DA_P;
    add BC|DA_P to classifiers 1..N with active rules
  - icssg_rxnfc_rule_cleanup(): RMW for classifier 0 when clearing FT3 bits                                                                                              
  - icssg_rxnfc_rule_add(): change location bound to >= ICSSG_NUM_FT3_SLOTS (16);
    slot 15 now reachable explicitly
  - emac_get_rxnfc(): set info->data = ICSSG_NUM_FT3_SLOTS | RX_CLS_LOC_SPECIAL in
    both GRXCLSRLCNT and GRXCLSRLALL                                                      
  - allocate_ft3_slot(), icssg_rxnfc_rule_add(): reserve slot 9 in HSR offload mode;
    RX_CLASS_OR_DUP_PTP bit 9 in classifier 10's OR_EN causes user rules in slot 9 to   
    trigger the HSR PTP duplicate path                                                                                                                                     
  - icssg_ft3_program_filter(): declare ether_type as __be16; fixes sparse warning                                                                                       
  - Remove FT3_CFG_REGISTER_EQUAL and FT3_CFG_REGISTER_VLAN_SKIP;
    use FT3_VLAN_MODE_BOTH directly                                                                        
  - Document ndev->stats RMW race as known limitation, deferred

 .../net/ethernet/ti/icssg/icssg_classifier.c  | 440 +++++++++++++++++-
 drivers/net/ethernet/ti/icssg/icssg_ethtool.c |  60 +++
 drivers/net/ethernet/ti/icssg/icssg_prueth.c  |   7 +
 drivers/net/ethernet/ti/icssg/icssg_prueth.h  |   3 +-
 4 files changed, 508 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ti/icssg/icssg_classifier.c b/drivers/net/ethernet/ti/icssg/icssg_classifier.c
index 87a8577093dbb..cf664e93d5c3d 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_classifier.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_classifier.c
@@ -5,6 +5,7 @@
  *
  */
 
+#include <linux/cleanup.h>
 #include <linux/etherdevice.h>
 #include <linux/types.h>
 #include <linux/regmap.h>
@@ -13,7 +14,6 @@
 
 #define ICSSG_NUM_CLASSIFIERS	16
 #define ICSSG_NUM_FT1_SLOTS	8
-#define ICSSG_NUM_FT3_SLOTS	16
 
 #define ICSSG_NUM_CLASSIFIERS_IN_USE	5
 
@@ -105,6 +105,11 @@ enum ft1_cfg_type {
 	((BIT(slot) << RX_CLASS_FT_FT1_MATCH_SHIFT) & \
 	RX_CLASS_FT_FT1_MATCH_MASK)
 
+#define RX_CLASS_FT_FT3_MATCH(slot)	\
+	((BIT(slot) << RX_CLASS_FT_FT3_MATCH_SHIFT) & \
+	RX_CLASS_FT_FT3_MATCH_MASK)
+
+
 /* HSR/PRP protocol frame filtering */
 #define HSR_PTP_ETHERTYPE_OFFSET	0x12
 #define PRP_PTP_ETHERTYPE_OFFSET	0x0C
@@ -120,6 +125,12 @@ enum ft1_cfg_type {
 #define CLASSIFIER_PTP_DUP		10
 #define CLASSIFIER_HSR_TAG		11
 #define FT3_PTP_SLOT			14
+/* FT3 slot 9 is referenced by RX_CLASS_OR_DUP_PTP (bit 9) in classifier 10's
+ * OR_EN. HSR setup never programs the slot 9 FT3 filter, but if a user RXNFC
+ * rule occupies it, classifier 10 fires on that rule's EtherType. Reserve slot
+ * 9 when HSR offload mode is active.
+ */
+#define FT3_HSR_OR_SLOT			9
 
 /* RX class type */
 enum rx_class_sel_type {
@@ -532,3 +543,430 @@ void icssg_ft3_hsr_configurations(struct regmap *miig_rt, int slice,
 	}
 }
 EXPORT_SYMBOL_GPL(icssg_ft3_hsr_configurations);
+
+/* RX Flow Classification (ethtool) rule management */
+
+/* Allocate free FT3 slot, avoiding reserved slots */
+static int allocate_ft3_slot(struct prueth_emac *emac)
+{
+	u16 used = emac->rxnfc.ft3_slots_used | ICSSG_FT3_RESERVED_SLOTS;
+	int slot;
+
+	/* Slot 9 is implicitly used by the HSR PTP duplicate classifier's OR_EN.
+	 * Prevent user rules from triggering it accidentally.
+	 */
+	if (emac->prueth->is_hsr_offload_mode)
+		used |= BIT(FT3_HSR_OR_SLOT);
+
+	for (slot = 0; slot < ICSSG_NUM_FT3_SLOTS; slot++) {
+		if (!(used & BIT(slot))) {
+			emac->rxnfc.ft3_slots_used |= BIT(slot);
+			return slot;
+		}
+	}
+	return -ENOSPC;
+}
+
+/* Free allocated FT3 slot */
+static void free_ft3_slot(struct prueth_emac *emac, int slot)
+{
+	emac->rxnfc.ft3_slots_used &= ~BIT(slot);
+}
+
+/* Program FT3 filter slot with ethertype pattern */
+static void icssg_ft3_program_filter(struct regmap *miig_rt, int slice,
+				     int slot, struct icssg_rxnfc_rule *rule)
+{
+	const struct ethtool_rx_flow_spec *fs = &rule->flow_spec;
+	__be16 ether_type;
+
+	/* Extract EtherType from flow spec (network byte order) */
+	ether_type = fs->h_u.ether_spec.h_proto;
+
+	/* Deactivate filter before programming */
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0);
+
+	/* EtherType is at byte 12 in standard Ethernet frames */
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START),
+		     PRP_PTP_ETHERTYPE_OFFSET);
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_AUTO), 0);
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_OFFSET), 0);
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_JUMP_OFFSET), 0);
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_LEN), 0);
+
+	/* FT3 compares a 32-bit LE word at FT3_START. EtherType occupies the
+	 * lower 16 bits of that word. FT3_T_MASK=0xFFFF0000 masks the upper
+	 * 16 bits (payload bytes), so only the lower 16 bits are compared.
+	 *
+	 * h_proto is __be16 (network byte order). On LE the raw integer value
+	 * equals the lower 16 bits of the LE 32-bit word at the EtherType
+	 * offset in the frame — e.g. IPv4 0x0800 BE → h_proto = 0x0008 on LE,
+	 * which is exactly what FT3 sees in the lower 16 bits of the word at
+	 * byte 12. No conversion needed; using be16_to_cpu() here would invert
+	 * the byte order and break the match.
+	 * Reference: FT3_PTP_PATTERN = 0xF788 = htons(0x88F7) = raw h_proto value.
+	 */
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T),
+		     (__force u32)ether_type);
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T_MASK), FT3_ETHERTYPE_MASK);
+
+	/* Enable filter: register-equal mode (same value as FT3_VLAN_MODE_BOTH) */
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG),
+		     FT3_VLAN_MODE_BOTH);
+}
+
+/* Disable FT3 filter slot */
+static void icssg_ft3_disable_filter(struct regmap *miig_rt, int slice, int slot)
+{
+	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0);
+}
+
+/* Update RX classifiers for all active FT3 rules.
+ * Classifier N maps to RX flow N (firmware routes classifier-N hits to
+ * UDMA flow rx_flow_id_base + N). Build a per-classifier OR table so
+ * that each target queue gets its own classifier entry.
+ */
+static void icssg_rxnfc_classifier_update(struct prueth_emac *emac)
+{
+	struct prueth *prueth = emac->prueth;
+	struct regmap *miig_rt = prueth->miig_rt;
+	int slice = prueth_emac_slice(emac);
+	u32 or_table[ICSSG_NUM_CLASSIFIERS] = { };
+	struct icssg_rxnfc_rule *rule;
+	int n;
+
+	if (slice < 0)
+		return;
+
+	/* Build per-classifier OR table: classifier index = target queue index */
+	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
+		int cls = rule->queue_index;
+
+		if (cls < emac->rx_flow_num)
+			or_table[cls] |= RX_CLASS_FT_FT3_MATCH(rule->ft3_slot);
+	}
+
+	/* Update OR tables for classifiers 0..rx_flow_num-1 using RMW so that
+	 * non-FT3 bits (e.g. RX_CLASS_FT_BC | RX_CLASS_FT_DA_P set by
+	 * icssg_class_default()) are preserved. Only the FT3-match field
+	 * (RX_CLASS_FT_FT3_MATCH_MASK) is replaced.
+	 *
+	 * Classifiers 1..N start with OR_EN=0 after icssg_class_default()
+	 * (non-SR1 sets num_classifiers=1, leaving them zeroed). Add BC|DA_P
+	 * when they carry FT3 rules so that only host-addressed frames are
+	 * steered — without it the classifier is a promiscuous EtherType match.
+	 *
+	 * Use RX_CLASS_N_REG (rx_class_base), NOT RX_CLASS_OR_REG
+	 * (rx_class_or_base = rx_class_base + 4): the latter lands on AND_EN
+	 * of classifier n+1 instead of OR_EN of classifier n.
+	 */
+	for (n = 0; n < emac->rx_flow_num; n++) {
+		u32 val;
+
+		if (n == 0) {
+			/* Classifier 0: RMW to preserve default BC|DA_P bits
+			 * set by icssg_class_default().
+			 */
+			regmap_read(miig_rt,
+				    RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), &val);
+			val &= ~RX_CLASS_FT_FT3_MATCH_MASK;
+			val |= or_table[n];
+		} else if (or_table[n]) {
+			/* Classifiers 1..N with active rules: add BC|DA_P so
+			 * only host-addressed frames are steered.
+			 */
+			val = RX_CLASS_FT_BC | RX_CLASS_FT_DA_P | or_table[n];
+		} else {
+			/* Classifiers 1..N with no rules: clear entirely.
+			 * Must not leave BC|DA_P here — it would steal all
+			 * host traffic away from classifier 0.
+			 */
+			val = 0;
+		}
+		regmap_write(miig_rt, RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), val);
+	}
+}
+
+/* Validate rule parameters */
+static int validate_rule(struct prueth_emac *emac,
+			 struct ethtool_rx_flow_spec *fs)
+{
+	/* Only ETHER_FLOW supported; reject extension flags */
+	if (fs->flow_type != ETHER_FLOW)
+		return -EOPNOTSUPP;
+
+	/* Only exact EtherType match supported — reject partial proto mask,
+	 * non-zero MAC address masks, and flow extension flags.
+	 */
+	if (fs->m_u.ether_spec.h_proto != htons(0xFFFF))
+		return -EOPNOTSUPP;
+	if (!is_zero_ether_addr(fs->m_u.ether_spec.h_dest) ||
+	    !is_zero_ether_addr(fs->m_u.ether_spec.h_source))
+		return -EOPNOTSUPP;
+
+	/* Check RX queue is valid */
+	if (fs->ring_cookie >= emac->rx_flow_num)
+		return -EINVAL;
+
+	return 0;
+}
+
+/* Check if identical rule already exists */
+static bool rule_exists(struct prueth_emac *emac,
+			struct ethtool_rx_flow_spec *fs)
+{
+	struct icssg_rxnfc_rule *rule;
+
+	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
+		if (rule->flow_spec.flow_type == fs->flow_type &&
+		    rule->flow_spec.h_u.ether_spec.h_proto ==
+		    fs->h_u.ether_spec.h_proto) {
+			return true;
+		}
+	}
+	return false;
+}
+
+/* Initialize RX flow classification */
+void icssg_rxnfc_rule_init(struct prueth_emac *emac)
+{
+	INIT_LIST_HEAD(&emac->rxnfc.rules);
+	mutex_init(&emac->rxnfc.rxnfc_lock);
+	emac->rxnfc.rxnfc_rule_count = 0;
+	emac->rxnfc.ft3_slots_used = ICSSG_FT3_RESERVED_SLOTS; /* Mark slot 14 reserved */
+}
+EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_init);
+
+/* Restore RX flow classification hardware state from the in-memory rule list.
+ * Call after icssg_class_default() resets the classifier registers on open or
+ * after firmware restart so that existing rules take effect again.
+ */
+void icssg_rxnfc_rule_restore(struct prueth_emac *emac)
+{
+	struct prueth *prueth = emac->prueth;
+	struct regmap *miig_rt = prueth->miig_rt;
+	int slice = prueth_emac_slice(emac);
+	struct icssg_rxnfc_rule *rule;
+
+	if (slice < 0)
+		return;
+
+	guard(mutex)(&emac->rxnfc.rxnfc_lock);
+
+	list_for_each_entry(rule, &emac->rxnfc.rules, list)
+		icssg_ft3_program_filter(miig_rt, slice, rule->ft3_slot, rule);
+
+	icssg_rxnfc_classifier_update(emac);
+}
+EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_restore);
+
+/* Cleanup RX flow classification */
+void icssg_rxnfc_rule_cleanup(struct prueth_emac *emac)
+{
+	struct prueth *prueth = emac->prueth;
+	struct regmap *miig_rt = prueth->miig_rt;
+	int slice = prueth_emac_slice(emac);
+	struct icssg_rxnfc_rule *rule, *tmp;
+	int n;
+
+	if (slice < 0)
+		return;
+
+	guard(mutex)(&emac->rxnfc.rxnfc_lock);
+
+	/* Disable all active FT3 filters */
+	list_for_each_entry_safe(rule, tmp, &emac->rxnfc.rules, list) {
+		icssg_ft3_disable_filter(miig_rt, slice, rule->ft3_slot);
+		free_ft3_slot(emac, rule->ft3_slot);
+		list_del(&rule->list);
+		kfree(rule);
+	}
+
+	emac->rxnfc.rxnfc_rule_count = 0;
+	emac->rxnfc.ft3_slots_used = ICSSG_FT3_RESERVED_SLOTS;
+
+	/* Clear FT3 bits from classifiers 0..rx_flow_num-1. Use RMW for
+	 * classifier 0 to preserve its BC|DA_P default-accept bits; for
+	 * classifiers 1..N (which had BC|DA_P added by classifier_update)
+	 * clear everything since no rules remain to steer traffic there.
+	 */
+	for (n = 0; n < emac->rx_flow_num; n++) {
+		u32 val;
+
+		if (n == 0) {
+			regmap_read(miig_rt,
+				    RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), &val);
+			val &= ~RX_CLASS_FT_FT3_MATCH_MASK;
+		} else {
+			val = 0;
+		}
+		regmap_write(miig_rt, RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), val);
+	}
+}
+EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_cleanup);
+
+/* Add a new RX flow classification rule */
+int icssg_rxnfc_rule_add(struct prueth_emac *emac, struct ethtool_rxnfc *info)
+{
+	struct ethtool_rx_flow_spec *fs = &info->fs;
+	struct prueth *prueth = emac->prueth;
+	struct regmap *miig_rt = prueth->miig_rt;
+	int slice = prueth_emac_slice(emac);
+	struct icssg_rxnfc_rule *rule;
+	int ft3_slot;
+	int ret;
+
+	if (slice < 0)
+		return -EINVAL;
+
+	/* Validate rule parameters */
+	ret = validate_rule(emac, fs);
+	if (ret)
+		return ret;
+
+	/* Validate explicit location: reject special specifiers, out-of-range
+	 * values, and the reserved slot 14 used by HSR/PRP.
+	 * Bound against ICSSG_NUM_FT3_SLOTS (16), not ICSSG_RXNFC_MAX_RULES
+	 * (15), so that slot 15 is reachable as an explicit location.
+	 */
+	if (fs->location != RX_CLS_LOC_ANY) {
+		if (fs->location >= ICSSG_NUM_FT3_SLOTS ||
+		    BIT(fs->location) & ICSSG_FT3_RESERVED_SLOTS ||
+		    (emac->prueth->is_hsr_offload_mode &&
+		     fs->location == FT3_HSR_OR_SLOT))
+			return -EINVAL;
+	}
+
+	guard(mutex)(&emac->rxnfc.rxnfc_lock);
+
+	/* Check max rules */
+	if (emac->rxnfc.rxnfc_rule_count >= ICSSG_RXNFC_MAX_RULES)
+		return -ENOSPC;
+
+	/* Check for duplicate flow spec */
+	if (rule_exists(emac, fs))
+		return -EEXIST;
+
+	/* Allocate FT3 slot. For explicit locations, the location IS the FT3
+	 * slot — this keeps location and slot aligned so rule_del operates on
+	 * the correct hardware slot. For RX_CLS_LOC_ANY, auto-allocate the
+	 * lowest free slot and assign it as the location.
+	 */
+	if (fs->location != RX_CLS_LOC_ANY) {
+		ft3_slot = fs->location;
+		if (emac->rxnfc.ft3_slots_used & BIT(ft3_slot))
+			return -EBUSY;
+		emac->rxnfc.ft3_slots_used |= BIT(ft3_slot);
+	} else {
+		ft3_slot = allocate_ft3_slot(emac);
+		if (ft3_slot < 0)
+			return -ENOSPC;
+		fs->location = ft3_slot;
+	}
+
+	/* Allocate rule structure */
+	rule = kzalloc(sizeof(*rule), GFP_KERNEL);
+	if (!rule) {
+		free_ft3_slot(emac, ft3_slot);
+		return -ENOMEM;
+	}
+
+	/* Program FT3 hardware */
+	rule->flow_spec = *fs;
+	rule->ft3_slot = ft3_slot;
+	rule->queue_index = fs->ring_cookie;
+	rule->location = fs->location;
+
+	icssg_ft3_program_filter(miig_rt, slice, ft3_slot, rule);
+
+	/* Add to rule list */
+	list_add(&rule->list, &emac->rxnfc.rules);
+	emac->rxnfc.rxnfc_rule_count++;
+
+	/* Update classifier */
+	icssg_rxnfc_classifier_update(emac);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_add);
+
+/* Delete a RX flow classification rule */
+int icssg_rxnfc_rule_del(struct prueth_emac *emac, u32 location)
+{
+	struct prueth *prueth = emac->prueth;
+	struct regmap *miig_rt = prueth->miig_rt;
+	int slice = prueth_emac_slice(emac);
+	struct icssg_rxnfc_rule *rule, *tmp;
+	int ret = -ENOENT;
+
+	if (slice < 0)
+		return -EINVAL;
+
+	guard(mutex)(&emac->rxnfc.rxnfc_lock);
+
+	list_for_each_entry_safe(rule, tmp, &emac->rxnfc.rules, list) {
+		if (rule->location == location) {
+			icssg_ft3_disable_filter(miig_rt, slice, rule->ft3_slot);
+			free_ft3_slot(emac, rule->ft3_slot);
+			list_del(&rule->list);
+			kfree(rule);
+			emac->rxnfc.rxnfc_rule_count--;
+			icssg_rxnfc_classifier_update(emac);
+			ret = 0;
+			break;
+		}
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_del);
+
+/* Get single RX flow classification rule */
+int icssg_rxnfc_rule_get(struct prueth_emac *emac, u32 location,
+			 struct ethtool_rx_flow_spec *fs)
+{
+	struct icssg_rxnfc_rule *rule;
+	int ret = -ENOENT;
+
+	guard(mutex)(&emac->rxnfc.rxnfc_lock);
+
+	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
+		if (rule->location == location) {
+			*fs = rule->flow_spec;
+			ret = 0;
+			break;
+		}
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_get);
+
+/* Get all RX flow classification rules */
+int icssg_rxnfc_rule_get_all(struct prueth_emac *emac, u32 *rule_locs,
+			     u32 rule_locs_capacity, u32 *rule_cnt)
+{
+	struct icssg_rxnfc_rule *rule;
+	u32 count = 0;
+	int ret = 0;
+
+	guard(mutex)(&emac->rxnfc.rxnfc_lock);
+
+	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
+		if (!rule_locs) {
+			/* Caller passed rule_cnt=0: just count active rules */
+			count++;
+			continue;
+		}
+		if (count >= rule_locs_capacity) {
+			ret = -EMSGSIZE;
+			break;
+		}
+		rule_locs[count++] = rule->location;
+	}
+
+	*rule_cnt = count;
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_get_all);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
index 8af4bba62efa7..b74e1a9706e40 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
@@ -302,6 +302,63 @@ static int emac_set_per_queue_coalesce(struct net_device *ndev, u32 queue,
 	return 0;
 }
 
+static u32 emac_get_rx_ring_count(struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+
+	return emac->rx_flow_num;
+}
+
+static int emac_get_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *info,
+			  u32 *rule_locs)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	int ret = 0;
+
+	if (emac->is_sr1)
+		return -EOPNOTSUPP;
+
+	switch (info->cmd) {
+	case ETHTOOL_GRXCLSRLCNT:
+		info->rule_cnt = emac->rxnfc.rxnfc_rule_count;
+		info->data = ICSSG_NUM_FT3_SLOTS | RX_CLS_LOC_SPECIAL;
+		break;
+	case ETHTOOL_GRXCLSRULE:
+		ret = icssg_rxnfc_rule_get(emac, info->fs.location, &info->fs);
+		break;
+	case ETHTOOL_GRXCLSRLALL: {
+		u32 rule_cnt = 0;
+
+		info->data = ICSSG_NUM_FT3_SLOTS | RX_CLS_LOC_SPECIAL;
+		ret = icssg_rxnfc_rule_get_all(emac, rule_locs,
+					       info->rule_cnt, &rule_cnt);
+		info->rule_cnt = rule_cnt;
+		break;
+	}
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return ret;
+}
+
+static int emac_set_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *info)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+
+	if (emac->is_sr1)
+		return -EOPNOTSUPP;
+
+	switch (info->cmd) {
+	case ETHTOOL_SRXCLSRLINS:
+		return icssg_rxnfc_rule_add(emac, info);
+	case ETHTOOL_SRXCLSRLDEL:
+		return icssg_rxnfc_rule_del(emac, info->fs.location);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 const struct ethtool_ops icssg_ethtool_ops = {
 	.get_drvinfo = emac_get_drvinfo,
 	.get_msglevel = emac_get_msglevel,
@@ -325,5 +382,8 @@ const struct ethtool_ops icssg_ethtool_ops = {
 	.set_eee = emac_set_eee,
 	.nway_reset = emac_nway_reset,
 	.get_rmon_stats = emac_get_rmon_stats,
+	.get_rx_ring_count = emac_get_rx_ring_count,
+	.get_rxnfc = emac_get_rxnfc,
+	.set_rxnfc = emac_set_rxnfc,
 };
 EXPORT_SYMBOL_GPL(icssg_ethtool_ops);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index bda6d92a8158d..ecd42abe9a3f9 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -1932,6 +1932,13 @@ static int prueth_emac_restart(struct prueth *prueth)
 		return ret;
 	}
 
+	/* Restore RXNFC rules: prueth_emac_common_start() calls
+	 * icssg_class_default() which resets all classifier OR_EN registers,
+	 * wiping any active FT3 steering rules.
+	 */
+	icssg_rxnfc_rule_restore(emac0);
+	icssg_rxnfc_rule_restore(emac1);
+
 	/* Enable forwarding for both PRUeth ports */
 	ret = icssg_set_port_state(emac0, ICSSG_EMAC_PORT_FORWARD);
 	ret |= icssg_set_port_state(emac1, ICSSG_EMAC_PORT_FORWARD);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
index 9feb1866d34c9..555b1774e03c6 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
@@ -194,7 +194,8 @@ struct prueth_swdata {
 #define ICSSG_MIN_COALESCE_USECS 20
 
 /* RX flow classification (ethtool) */
-#define ICSSG_RXNFC_MAX_RULES    15      /* Max user-installable rules */
+#define ICSSG_NUM_FT3_SLOTS      16      /* Total FT3 filter slots */
+#define ICSSG_RXNFC_MAX_RULES    15      /* Max user-installable rules (slot 14 reserved) */
 #define ICSSG_FT3_RESERVED_SLOTS BIT(14) /* Slot 14 reserved for HSR/PRP */
 
 /* RX flow classification rule structure */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI
  2026-12-03 12:14 ` [PATCH net-next v2 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI Meghana Malladi
@ 2026-12-04 12:44   ` sashiko-bot
  2026-12-04 13:25   ` netdev-bot+sashiko
  1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 12:44 UTC (permalink / raw)
  To: Meghana Malladi; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 28 potential
issues to consider:
- [High] net: ti: icssg: undefined icssg_rxnfc_rule_* calls break build
  and linking
- [High] net: ti: icssg: AM654 UDMAP exposes 8 RX flows despite shared
  512-entry FDQ
- [High] net: ti: icssg: zeroing xsk_queues on open/stop leaks XSK DMA
  mappings
- [High] net: ti: icssg: double napi_disable() deadlock after XSK queue
  create error
- [High] net: ti: icssg: per-flow XSK teardown frees buffers while UDMA
  RX is active
- [High] net: ti: icssg: NULL deref on emac->xsk_queues in SR1
  emac_ndo_open()
- [High] net: ti: icssg: SR1 emac_ndo_stop() destroys page_pool before
  napi_disable()
- [High] net: ti: icssg: SR1 rx_mgm_chn leaks flow 1 FDQ buffers on
  UDMAP single_fdq
- [High] net: ti: icssg-prueth: SR1 registers IRQs for
  unprepared/disabled RX flows 0..2
- [Medium] net: ti: icssg: stale/racy flow->irq_disabled causes
  unbalanced enable_irq()
- [Medium] net: ti: icssg-sr1: stale mgm flow->irq_disabled skips
  disable_irq() on stop
- [Medium] net: ti: icssg: per-flow page_pool sized to total
  rx_chn->descs_num
- [Medium] net: ti: icssg: emac_rx_packet_zc() refill uses shared
  desc_pool avail
- [Medium] net: ti: icssg: unsynchronized concurrent ndev->stats writes
  across RX NAPIs
- [Medium] net: ti: icssg: shared rx_chn->desc_pool gen_pool contends
  across RX NAPIs
- [Medium] net: ti: icssg: prueth_xsk_pool_enable() error unmaps pool
  with live TX NAPI
- [Medium] net: ti: icssg: stale SR1 mgm flow->irq_disabled skips
  disable_irq() on stop
- [Medium] net: ti: icssg: SR1 prueth_sr1_prepare_rx_mgm_flow()
  overflows 8-entry FDQ
- [Medium] net: ti: icssg: SR1 emac_ndo_open() error path deletes only 1
  of 4 RX NAPIs
- [Medium] net: ti: icssg: SR1 emac_ndo_open() leaks page_pool on RX
  prepare failure
- [Medium] net: ti: icssg: SR1 emac_ndo_open() skips mgm reset on
  partial setup error
- [Medium] net: ti: icssg-prueth: SR1 stale irq_disabled skips
  disable_irq() on re-close
- [Medium] net: ti: icssg-prueth: stale/racy flow->irq_disabled causes
  bad enable_irq()
- [Medium] net: ti: icssg-prueth: SR1 records out-of-range RX queue 3 on
  1-queue netdev
- [Medium] net: ti: icssg: emac_rx_packet() records out-of-range RX
  queue on SR1.0
- [Medium] net: ti: icssg: emac_get_channels() reports rx_count > max_rx
  on SR1
- [Low] net: ti: icssg: prueth_ndev_del_rx_napi() calls netif_napi_del()
  in loop
- [Low] net: ti: icssg: emac_get_channels() reports rx_count 4 > max_rx
  1 on SR1
--

commit d48a43c55ee89f865fc4ca3c4ae7110625497ddd
Author: Meghana Malladi <m-malladi@ti.com>

net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI

This commit extends the TI ICSSG Ethernet driver to support up to 8 RX
flows per EMAC with per-flow NAPI, hrtimers, page pools, and AF_XDP
pools, and updates the SR1.0 driver and ethtool channel callbacks for
the restructured RX channel layout.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_common.c b/drivers/net/ethernet/ti/icssg/icssg_common.c
> index 4a7d1a6f470b1..fc7e7847580f8 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_common.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_common.c

[ ... ]

> @@ -79,6 +77,21 @@ void prueth_cleanup_tx_chns(struct prueth_emac *emac)
>  }
>  EXPORT_SYMBOL_GPL(prueth_cleanup_tx_chns);
>  
> +void prueth_ndev_del_rx_napi(struct prueth_emac *emac, int num)
> +{
> +	int i;
> +
> +	for (i = 0; i < num; i++) {
> +		struct prueth_rx_flow *rx_flow = &emac->rx_chns.flows[i];
> +
> +		hrtimer_cancel(&rx_flow->rx_hrtimer);
> +		if (rx_flow->irq)
> +			free_irq(rx_flow->irq, &rx_flow->napi_rx);
> +		netif_napi_del(&rx_flow->napi_rx);
> +	}
> +}
> +EXPORT_SYMBOL_GPL(prueth_ndev_del_rx_napi);

[Severity: Low]
Should this loop call __netif_napi_del() and follow the loop with a single
synchronize_net()?  Calling netif_napi_del() per flow serializes up to 8
RCU grace periods under rtnl_lock() on every stop or open-error unwind.

[ ... ]

> @@ -584,9 +627,14 @@ int prueth_init_rx_chns(struct prueth_emac *emac,
>  				K3_UDMA_GLUE_SRC_TAG_LO_USE_REMOTE_SRC_TAG,
>  		};
>  
> +		flow = &rx_chn->flows[i];
> +		flow->emac = emac;
> +		flow->id = i;
> +		flow->irq = -EINVAL;

[Severity: Medium]
Does flow->irq_disabled stay stale across an interface stop and reopen?

Neither prueth_init_rx_chns() nor prueth_ndev_del_rx_napi() clears
flow->irq_disabled.  If emac_ndo_stop() cancels an armed rx_hrtimer while
flow->irq_disabled is true, the next emac_ndo_open() requests the IRQ in
the enabled state and prueth_create_rxq() then calls an unbalanced
enable_irq().  Additionally, emac_set_coalesce() does not cancel an armed
rx_hrtimer, allowing icssg_napi_rx_poll() and emac_rx_timer_callback() to
race on checking and clearing rx_flow->irq_disabled.

[ ... ]

> @@ -1022,13 +1087,13 @@ static int emac_rx_packet_zc(struct prueth_emac *emac, u32 flow_id,
>  	avail_desc = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
>  	alloc_budget = min_t(int, budget, avail_desc);
>  
> -	ret = prueth_rx_alloc_zc(emac, alloc_budget);
> +	ret = prueth_rx_alloc_zc(emac, flow_id, alloc_budget);
>  
> -	if (xsk_uses_need_wakeup(rx_chn->xsk_pool)) {
> +	if (xsk_uses_need_wakeup(rx_flow->xsk_pool)) {
>  		if (ret < alloc_budget)
> -			xsk_set_rx_need_wakeup(rx_chn->xsk_pool);
> +			xsk_set_rx_need_wakeup(rx_flow->xsk_pool);
>  		else
> -			xsk_clear_rx_need_wakeup(rx_chn->xsk_pool);
> +			xsk_clear_rx_need_wakeup(rx_flow->xsk_pool);
>  	}

[Severity: Medium]
Can computing alloc_budget from the shared rx_chn->desc_pool overflow
flow_id's 512-entry FDQ ring on PKTDMA (AM64x)?

Whenever another flow holds fewer than 512 descriptors, avail_desc is
non-zero even if flow_id's FDQ is full, so prueth_rx_alloc_zc() pushes past
the ring limit, hits -ENOMEM with netdev_err() spam, drops popped fill-ring
frames, and spuriously sets xsk_set_rx_need_wakeup().  Concurrently, an XSK
flow can also claim a descriptor just freed by emac_rx_packet() on another
CPU, causing the page-pool flow to hit WARN_ON(ret < 0) and permanently
lose a posted RX buffer.

[ ... ]

> @@ -1132,15 +1198,16 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id, u32 *xdp_state)
>  	skb->protocol = eth_type_trans(skb, ndev);
>  
>  	skb_mark_for_recycle(skb);
> -	napi_gro_receive(&emac->napi_rx, skb);
> +	skb_record_rx_queue(skb, flow_id);
> +	napi_gro_receive(&emac->rx_chns.flows[flow_id].napi_rx, skb);
>  	ndev->stats.rx_bytes += pkt_len;
>  	ndev->stats.rx_packets++;
>  
>  requeue:
>  	k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
>  	/* queue another RX DMA */
> -	ret = prueth_dma_rx_push_mapped(emac, &emac->rx_chns, new_page,
> -					PRUETH_MAX_PKT_SIZE);
> +	ret = prueth_dma_rx_push_mapped(emac, rx_chn, new_page,
> +					PRUETH_MAX_PKT_SIZE, flow_id);

[Severity: Medium]
Does skb_record_rx_queue(skb, flow_id) record an out-of-range queue index
on SR1.0?

SR1.0 allocates its netdev with a single RX queue (real_num_rx_queues == 1)
while receiving data on flow_id == PRUETH_RX_FLOW_DATA_SR1 (3).  In
get_rps_cpu(), index >= dev->real_num_rx_queues aborts early, silently
disabling RPS/RFS for all SR1.0 traffic.

[Severity: Medium]
Are the plain RMW updates to ndev->stats.rx_bytes and ndev->stats.rx_packets
here (and in emac_dispatch_skb_zc()) both racy and unused?

With up to 8 concurrent RX NAPIs, these per-packet writes bounce the shared
ndev->stats cacheline across CPUs even though icssg_ndo_get_stats64() reads
rx_bytes and rx_packets from hardware MIIG counters instead.  The plain RMW
updates to ndev->stats.rx_dropped and ndev->stats.rx_errors also race
across NAPIs and lose increments.

[Severity: Medium]
Will freeing desc_rx to the shared rx_chn->desc_pool and immediately
reallocating it in prueth_dma_rx_push_mapped() limit multi-flow RX scaling?

With up to 8 concurrent RX NAPIs sharing a 4096-entry gen_pool, every
packet runs a first-fit bitmap scan and atomic chunk->avail updates across
CPUs.  Reusing desc_rx directly in emac_rx_packet() (or using per-flow
descriptor pools on PKTDMA) would avoid this contention.

[ ... ]

> @@ -1488,59 +1547,81 @@ int prueth_prepare_rx_chan(struct prueth_emac *emac,
>  
> -	if (chn->xsk_pool) {
> -		/* get pages from xsk_pool and push to RX ring
> -		 * queue as much as possible
> +	pool = prueth_create_page_pool(emac, rx_chn->dma_dev, rx_chn->descs_num, rx_flow);
> +	if (IS_ERR(pool))
> +		return PTR_ERR(pool);

[Severity: Medium]
Should prueth_create_page_pool() receive PRUETH_MAX_RX_DESC instead of
rx_chn->descs_num?

Because rx_chn->descs_num is scaled by flow_id_num, each of the 8 per-flow
page pools allocates a 4096-entry ptr_ring (up to 128 MiB of cached pages
per port instead of 16 MiB), and SR1.0 over-sizes its single data flow pool
by 4x.

[ ... ]

> @@ -1752,7 +1837,9 @@ void prueth_netdev_exit(struct prueth *prueth,
>  	if (of_phy_is_fixed_link(emac->phy_node))
>  		of_phy_deregister_fixed_link(emac->phy_node);
>  
> -	netif_napi_del(&emac->napi_rx);
> +	/* Free any rules added while the interface was down */
> +	if (!emac->is_sr1)
> +		icssg_rxnfc_rule_cleanup(emac);

[Severity: High]
Does this break building and linking for both CONFIG_TI_ICSSG_PRUETH and
CONFIG_TI_ICSSG_PRUETH_SR1?

icssg_rxnfc_rule_cleanup(), icssg_rxnfc_rule_init(), and
icssg_rxnfc_rule_restore() are declared in icssg_prueth.h and called here
and in icssg_prueth.c, but they are not defined until commit "net: ti:
icssg-prueth: Add ethtool RX flow classification support".  Moving these
declarations, struct fields, and calls into that patch would keep this
commit bisectable.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index b715af21d23ac..8af4bba62efa7 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> @@ -140,13 +140,14 @@ static int emac_set_channels(struct net_device *ndev,
>  {
>  	struct prueth_emac *emac = netdev_priv(ndev);
>  
> -	/* Check if interface is up. Can change the num queues when
> -	 * the interface is down.
> +	/* Check if interface is up. Can't change the num queues when
> +	 * the interface is up.
>  	 */
>  	if (netif_running(emac->ndev))
>  		return -EBUSY;
>  
>  	emac->tx_ch_num = ch->tx_count;
> +	emac->rx_flow_num = ch->rx_count;

[Severity: Medium]
Can emac_set_channels() drift emac->rx_flow_num on SR1.0 and reject valid
ethtool -L requests?

On SR1.0, emac_get_channels() reports max_rx = 1 with rx_count = 4
(PRUETH_MAX_RX_FLOWS_SR1).  ethnl_set_channels() and ethtool_set_channels()
reject requests with -EINVAL when rx_count stays 4, ethtool -L rx 1 fails
with -EBUSY while up instead of being a no-op, and running it while down
overwrites emac->rx_flow_num to 1 until emac_ndo_open() silently resets it
back to 4.

> @@ -159,15 +160,17 @@ static void emac_get_channels(struct net_device *ndev,
>  {
>  	struct prueth_emac *emac = netdev_priv(ndev);
>  
> -	ch->max_rx = 1;
> +	ch->max_rx = ICSSG_MAX_RFLOWS;
>  	ch->max_tx = PRUETH_MAX_TX_QUEUES;
>  
>  	/* Disable multiple TX channels due to timeouts
>  	 * when using more than one queue */
> -	if (emac->is_sr1)
> +	if (emac->is_sr1) {
> +		ch->max_rx = 1;
>  		ch->max_tx = 1;
> +	}
>  
> -	ch->rx_count = 1;
> +	ch->rx_count = emac->rx_flow_num;

[Severity: High]
Does setting ch->max_rx = ICSSG_MAX_RFLOWS for all !emac->is_sr1 devices
expose 8 RX flows on AM654 SR2.0 (ti,am654-icssg-prueth) despite UDMAP's
shared 512-entry FDQ?

On AM654 SR2.0, k3_udma_glue_request_rx_chn() sets single_fdq = true, so
all flows share one 512-entry FDQ ring.  Setting rx_count > 1 causes
emac_ndo_open() to fail deterministically with -ENOMEM on flow 1, leaks
pages on error unwind and teardown because k3_udma_glue_reset_rx_chn()
skips draining when single_fdq && flow_num, and allows unlocked concurrent
k3_ringacc_ring_push() calls on the shared FDQ.

[Severity: Low]
Should ch->rx_count be normalized to 1 when emac->is_sr1 is set?  Because
emac->rx_flow_num is PRUETH_MAX_RX_FLOWS_SR1 (4), ethtool -l reports
rx_count = 4 exceeding max_rx = 1.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 9bb67e185a3ea..bda6d92a8158d 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c

[ ... ]

> @@ -978,27 +947,81 @@ static int prueth_create_txq(struct prueth_emac *emac)
>  	return ret;
>  }
>  
> -static int prueth_create_rxq(struct prueth_emac *emac)
> +static int prueth_create_rxq(struct prueth_emac *emac, int id)
>  {
> +	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
> +	struct prueth_rx_flow *flow = &rx_chn->flows[id];
> +	struct xdp_rxq_info *rxq = &flow->xdp_rxq;
>  	int ret;

[ ... ]

> +	napi_enable(&flow->napi_rx);
> +	/* Re-enable IRQ now that NAPI is live. IRQ may have been left
> +	 * disabled by hrtimer coalescing or a previous destroy_rxq.
> +	 */
> +	if (flow->irq_disabled) {
> +		flow->irq_disabled = false;
> +		enable_irq(flow->irq);
> +	}

[Severity: Medium]
Can checking flow->irq_disabled after napi_enable() race with
prueth_rx_irq() and leave the RX IRQ permanently disabled?

When prueth_create_rxq() runs on a live shared RX channel (such as during
XSK pool enable/disable), prueth_rx_irq() sets irq_disabled = true before
calling disable_irq_nosync():

CPU0                                CPU1
prueth_create_rxq()
  napi_enable(&flow->napi_rx)
                                    prueth_rx_irq()
                                      rx_flow->irq_disabled = true
  if (flow->irq_disabled)
    flow->irq_disabled = false
    enable_irq(flow->irq)           <-- unbalanced enable_irq()
                                      disable_irq_nosync(irq)
                                      napi_schedule(napi_rx)

Because flow->irq_disabled is now false, icssg_napi_rx_poll() will never
re-enable the IRQ, stalling RX on that queue until reset.  Re-enabling the
IRQ before napi_enable() (or synchronizing with the IRQ) avoids this race.

[ ... ]

> @@ -1042,9 +1068,13 @@ static int emac_ndo_open(struct net_device *ndev)
>  		return ret;
>  	}
>  
> -	max_rx_flows = PRUETH_MAX_RX_FLOWS;
> -	ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx",
> -				  max_rx_flows, PRUETH_MAX_RX_DESC);
> +	/* Clear XSK state on open: any pool bound while interface was down
> +	 * is no longer valid. User must re-enable AF_XDP after bringing
> +	 * the interface up.
> +	 */
> +	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);

[Severity: High]
Does clearing emac->xsk_queues in emac_ndo_open() and emac_ndo_stop() leak
XSK DMA mappings and trigger a kernel WARN on socket close?

Core AF_XDP keeps zero-copy pools bound across interface down/up and
suspend/resume cycles.  When the socket later closes, xp_disable_drv_zc()
calls prueth_xsk_pool_disable(), which hits !test_bit(queue_id,
emac->xsk_queues) and returns -EINVAL before xsk_pool_dma_unmap(),
emitting WARN(1, "Failed to disable zero-copy!") and leaking the DMA
mappings.

[ ... ]

> @@ -1490,45 +1523,66 @@ static int prueth_xsk_pool_enable(struct prueth_emac *emac,
>  	if (netif_running(emac->ndev)) {
>  		/* stop packets from wire for graceful teardown */
>  		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
> -		if (ret)
> +		if (ret) {
> +			xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);
>  			return ret;
> -		prueth_destroy_rxq(emac);
> +		}
> +		prueth_destroy_rxq(emac, queue_id);
>  	}

[Severity: High]
Can calling prueth_destroy_rxq() while the shared UDMA RX channel is still
enabled cause DMA use-after-free?

ICSSG_EMAC_PORT_DISABLE stops new frames from the wire, but does not flush
in-flight frames or descriptors already prefetched by UDMA from the FDQ.
Destroying flow->pg_pool here (or calling xsk_pool_dma_unmap() in
prueth_xsk_pool_disable()) lets UDMA write into freed or unmapped memory
and leaks any prefetched descriptors from rx_chn->desc_pool.

> +err_napi:
> +	clear_bit(queue_id, emac->xsk_queues);
> +	prueth_set_xsk_pool(emac, queue_id);
> +	xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);

[Severity: Medium]
Can this error path unmap the XSK pool while TX NAPI is still using it?

prueth_set_xsk_pool() already published pool into tx_chn->xsk_pool while
tx_chn->napi_tx is live:

CPU0                                CPU1
prueth_xsk_pool_enable()
  prueth_set_xsk_pool()
                                    emac_napi_tx_poll()
                                      emac_tx_complete_packets()
                                        if (tx_chn->xsk_pool)
  err_napi:
    prueth_set_xsk_pool()  /* NULL */
    xsk_pool_dma_unmap(pool, ...)
                                          emac_xsk_xmit_zc()
                                            <-- use-after-free on dma_pages

Disabling or synchronizing with tx_chn->napi_tx before unmapping pool would
close this window.

> @@ -1544,27 +1598,29 @@ static int prueth_xsk_pool_disable(struct prueth_emac *emac, u16 queue_id)

[ ... ]

>  	if (netif_running(emac->ndev)) {
> -		ret = prueth_create_rxq(emac);
> -		if (ret) {
> -			netdev_err(emac->ndev, "Failed to create RX queue: %d\n", ret);
> -			return ret;
> -		}
> -		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
> -		if (ret) {
> -			prueth_destroy_rxq(emac);
> -			return ret;
> -		}
> +		ret = prueth_create_rxq(emac, queue_id);
> +		if (ret)
> +			netdev_err(emac->ndev,
> +				   "failed to recreate RX queue %d after XSK disable; bring interface down to recover: %d\n",
> +				   queue_id, ret);

[Severity: High]
Does a failure in prueth_create_rxq() here (or in prueth_xsk_pool_enable()
at err_napi:) cause a permanent deadlock on the next interface down?

prueth_destroy_rxq() already called napi_disable(&flow->napi_rx), and when
prueth_create_rxq() fails it returns without calling napi_enable().  When
the user brings the interface down to recover, emac_ndo_stop() ->
prueth_destroy_rxqs() -> prueth_destroy_rxq() calls napi_disable() a second
time, spinning forever in napi_disable_locked() while holding netdev_lock()
and rtnl_lock().  In prueth_xsk_pool_enable()'s err_napi: path, a failure
also leaves ICSSG_EMAC_PORT_FORWARD disabled across all flows.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> index 21a14b3bc889b..c166977b424ef 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c

[ ... ]

> @@ -319,14 +319,123 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,

[ ... ]

> +	desc_avail = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
> +	if (desc_avail < PRUETH_MAX_RX_DESC)
> +		netdev_warn(emac->ndev,
> +			    "not enough RX descriptors available %d < %d\n",
> +			    desc_avail, PRUETH_MAX_RX_DESC);
> +
> +	for (i = 0; i < desc_avail; i++) {
> +		page = page_pool_dev_alloc_pages(rx_flow->pg_pool);
> +		if (!page)
> +			break;
> +
> +		ret = prueth_dma_rx_push_mapped(emac, rx_chn, page, buf_len, flow);
> +		if (ret < 0) {
> +			page_pool_recycle_direct(rx_flow->pg_pool, page);
> +			netdev_err(emac->ndev, "failed to push rx mgm buf %d\n", ret);
> +			break;
> +		}
> +	}
> +
> +	return 0;
> +}

[Severity: Medium]
Does prueth_sr1_prepare_rx_mgm_flow() overflow flow 0's 8-entry FDQ ring on
every SR1.0 open?

rx_mgm_chn.desc_pool has 16 descriptors (8 per flow), while each flow's FDQ
ring holds PRUETH_MAX_RX_MGM_DESC_SR1 (8).  Comparing against
PRUETH_MAX_RX_DESC (512) always logs a warning, looping up to desc_avail
(16) overflows flow 0's ring with -ENOMEM on iteration 8, and breaking out
returns 0 even if zero buffers were pushed.

[ ... ]

> +static void prueth_sr1_reset_rx_mgm_chn(struct prueth_emac *emac, bool disable)
> +{
> +	struct prueth_rx_chn *chn = &emac->rx_mgm_chn;
> +	struct prueth_rx_flow *flow;
> +	int i;
> +
> +	/* Disable mgm IRQs before UDMA reset to prevent handler re-entry */
> +	for (i = 0; i < PRUETH_MAX_RX_MGM_FLOWS_SR1; i++) {
> +		flow = &chn->flows[i];
> +		if (flow->irq <= 0)
> +			continue;
> +		if (!flow->irq_disabled) {
> +			disable_irq(flow->irq);
> +			flow->irq_disabled = true;
> +		}
> +	}

[Severity: Medium]
Will stale flow->irq_disabled skip disable_irq() on the second SR1.0
emac_ndo_stop()?

When called with disable == true, this sets flow->irq_disabled = true and
neither prueth_sr1_cleanup_rx_mgm_chn() nor the next emac_ndo_open() resets
it to false.  On the next stop, disable_irq() is skipped, letting the
threaded management IRQ handlers run concurrently with
k3_udma_glue_reset_rx_chn() and k3_udma_glue_disable_rx_chn().

[ ... ]

> @@ -514,37 +629,123 @@ static int emac_ndo_open(struct net_device *ndev)
>  		return ret;
>  	}
>  
> -	max_rx_flows = PRUETH_MAX_RX_FLOWS_SR1;
> -	ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx",
> -				  max_rx_flows, PRUETH_MAX_RX_DESC);
> +	emac->rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1;
> +
> +	/* Clear XSK state on open: any pool bound while interface was down
> +	 * is no longer valid. User must re-enable AF_XDP after bringing
> +	 * the interface up.
> +	 */
> +	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);

[Severity: High]
Does this unconditionally dereference a NULL pointer on SR1.0?

icssg_prueth_sr1.c:prueth_netdev_init() never allocates emac->xsk_queues,
so bitmap_zero() writes through NULL on every SR1.0 interface open.
Embedding DECLARE_BITMAP(xsk_queues, PRUETH_MAX_RX_FLOWS) in struct
prueth_emac (or removing this call on SR1.0) avoids the NULL dereference.

[ ... ]

> +		flow = &emac->rx_mgm_chn.flows[i];
> +		flow->emac = emac;
> +		flow->id = i;
> +		flow->irq = -EINVAL;
> +
> +		rx_flow_cfg.ring_rxfdq0_id = K3_RINGACC_RING_ID_ANY;
> +		rx_flow_cfg.rx_cfg.size = PRUETH_MAX_RX_MGM_DESC_SR1;
> +		rx_flow_cfg.rxfdq_cfg.size = PRUETH_MAX_RX_MGM_DESC_SR1;

[Severity: Medium]
Should this loop also reset flow->irq_disabled = false?  Without resetting
it on reopen, request_threaded_irq() enables the management IRQs while
flow->irq_disabled remains true from a previous stop, defeating the IRQ
disable guard in prueth_sr1_reset_rx_mgm_chn().

[Severity: High]
Does hardcoding K3_RINGACC_RING_ID_ANY here leak all 8 pages and CPPI
descriptors on management flow 1 during SR1.0 teardown?

AM654 SR1.0 uses UDMAP where k3_udma_glue_request_rx_chn() sets
single_fdq = true.  Allocating a separate FDQ ring for flow 1 causes
k3_udma_glue_reset_rx_chn() to skip draining it (single_fdq && flow_num),
leaking its pages and firing WARN() in k3_cppi_desc_pool_destroy().

[ ... ]

> +	/* Data NAPI and IRQ registration via common API */
> +	ret = prueth_ndev_add_rx_napi(emac);
>  	if (ret) {
> -		dev_err(dev, "unable to request RX IRQ\n");
> +		dev_err(dev, "unable to add rx napi\n");
>  		goto cleanup_napi;
>  	}

[Severity: High]
Does calling prueth_ndev_add_rx_napi() register live IRQs for unprepared
SR1.0 flows 0..2?

With emac->rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1 (4), this registers NAPIs
and requests IRQs for flows 0..3, while emac_ndo_open() only prepares and
enables NAPI for flow 3 (PRUETH_RX_FLOW_DATA_SR1) and icssg_napi_rx_poll()
no longer drains flows 0..2.  Any packet arriving on flows 0..2 fires
prueth_rx_irq(), disables the IRQ, fails to schedule the disabled NAPI, and
stalls that flow.

[ ... ]

> @@ -570,11 +771,15 @@ static int emac_ndo_open(struct net_device *ndev)
>  	icssg_mii_update_mtu(prueth->mii_rt, slice, ndev->max_mtu);
>  
>  	/* Prepare RX */
> -	ret = prueth_prepare_rx_chan(emac, &emac->rx_chns, PRUETH_MAX_PKT_SIZE);
> +	ret = prueth_prepare_rx_flow(emac, PRUETH_RX_FLOW_DATA_SR1);
>  	if (ret)
>  		goto stop;
>  
> -	ret = prueth_prepare_rx_chan(emac, &emac->rx_mgm_chn, 64);
> +	ret = prueth_sr1_prepare_rx_mgm_flow(emac, PRUETH_RX_MGM_FLOW_RESPONSE_SR1, 64);
> +	if (ret)
> +		goto reset_rx_chn;
> +
> +	ret = prueth_sr1_prepare_rx_mgm_flow(emac, PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1, 64);
>  	if (ret)
>  		goto reset_rx_chn;

[Severity: Medium]
Does jumping to stop: on prueth_prepare_rx_flow() failure leak
flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool and any already-pushed buffers?

prueth_prepare_rx_flow() leaves destroying pg_pool to the caller, and its
err_free_pushed: path passes flow == 3 to k3_udma_glue_reset_rx_chn(),
which skips draining the shared FDQ on UDMAP (single_fdq == true).
Bypassing reset_rx_chn: therefore leaks the page pool, pushed pages, and
CPPI descriptors.

[Severity: Medium]
When packets arrive on PRUETH_RX_FLOW_DATA_SR1 (3), does emac_rx_packet()
record an out-of-range RX queue mapping for SR1.0's 1-queue netdev?

Because SR1.0 calls alloc_etherdev_mq(..., 1), skb_record_rx_queue(skb, 3)
sets skb->queue_mapping to 4 while real_num_rx_queues is 1, breaking
RPS/RFS in get_rps_cpu() and exposing an invalid queue index to XPS and
BPF.  Skipping skb_record_rx_queue() (or recording 0) when emac->is_sr1 is
set would preserve SR1.0 behavior.

[Severity: Medium]
If preparing PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1 or enabling
emac->rx_mgm_chn.rx_chn fails, should both jump to reset_rx_mgm_chn:
instead of reset_rx_chn:?  Skipping reset_rx_mgm_chn: leaves flow 0's
pushed pages and CPPI descriptors undrained when
prueth_sr1_cleanup_rx_mgm_chn() runs, triggering WARN() in
k3_cppi_desc_pool_destroy().

[ ... ]

> @@ -612,27 +817,29 @@ static int emac_ndo_open(struct net_device *ndev)

[ ... ]

>  free_rx_irq:
> -	free_irq(emac->rx_chns.irq[rx_flow], emac);
> +	prueth_ndev_del_rx_napi(emac, 1);

[Severity: Medium]
Does passing 1 instead of PRUETH_MAX_RX_FLOWS_SR1 leak 3 RX IRQs and NAPI
registrations on SR1.0 open failure?  prueth_ndev_add_rx_napi() registered
4 flows, so flows 1..3 remain registered while cleanup_rx releases the UDMA
channel.

[ ... ]

> @@ -683,16 +888,20 @@ static int emac_ndo_stop(struct net_device *ndev)

[ ... ]

>  	k3_udma_glue_tdown_rx_chn(emac->rx_chns.rx_chn, true);
>  
> -	prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, true);
> +	prueth_reset_rx_chan(emac, true);
> +
> +	if (emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool) {
> +		page_pool_destroy(emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool);
> +		emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool = NULL;
> +	}
> +
>  	/* Teardown RX MGM channel */
>  	k3_udma_glue_tdown_rx_chn(emac->rx_mgm_chn.rx_chn, true);
> -	prueth_reset_rx_chan(&emac->rx_mgm_chn,
> -			     PRUETH_MAX_RX_MGM_FLOWS_SR1, true);
> +	prueth_sr1_reset_rx_mgm_chn(emac, true);
>  
> -	napi_disable(&emac->napi_rx);
> +	napi_disable(&emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].napi_rx);

[Severity: High]
Does destroying the data flow's page_pool before napi_disable() trigger a
use-after-free and a WARN in napi_assert_will_not_race()?

Because prueth_create_page_pool() binds pp_params.napi to
&rx_flow->napi_rx, page_pool_destroy() checks napi_assert_will_not_race()
and warns deterministically while NAPI is still enabled.  Concurrently,
icssg_napi_rx_poll() -> emac_rx_packet() can dereference the destroyed or
NULL rx_flow->pg_pool while racing with prueth_reset_rx_chan().

[Severity: Medium]
On a second emac_ndo_stop() after reopening an SR1.0 interface, can
prueth_sr1_reset_rx_mgm_chn(emac, true) race with the threaded management
IRQ handlers on rx_mgm_chn?

Because flow->irq_disabled stays true from the first stop,
prueth_sr1_reset_rx_mgm_chn() skips disable_irq(), allowing
prueth_rx_mgm_rsp_thread() and prueth_rx_mgm_ts_thread_sr1() to run
concurrently with k3_udma_glue_reset_rx_chn() -> prueth_rx_cleanup() on the
UDMA rings and lockless page_pool caches.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203121447.2605779-1-m-malladi@ti.com?part=1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support
  2026-12-03 12:14 ` [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support Meghana Malladi
@ 2026-12-04 12:44   ` sashiko-bot
  2026-12-04 13:25   ` netdev-bot+sashiko
  1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 12:44 UTC (permalink / raw)
  To: Meghana Malladi; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 13 potential
issues to consider:
- [High] net: ti: icssg: BC|DA_P in OR_EN steals host traffic in
  classifiers 1..N
- [High] net: ti: icssg-prueth: uncapped multi-flow breaks AM654 shared
  RX FDQ
- [High] net: ti: icssg-prueth: live-channel XSK teardown in
  prueth_xsk_pool_enable()
- [High] net: ti: icssg-prueth: NULL deref of emac->xsk_queues in SR1.0
  emac_ndo_open()
- [Medium] net: ti: icssg: icssg_rxnfc_rule_restore() restores slot 9 in
  HSR mode
- [Medium] net: ti: icssg: parent commit calls undefined
  icssg_rxnfc_rule_* helpers
- [Medium] net: ti: icssg: big-endian EtherType bug in
  icssg_ft3_program_filter()
- [Medium] net: ti: icssg-prueth: ETHTOOL_GRXCLSRLALL sets
  RX_CLS_LOC_SPECIAL in data
- [Medium] net: ti: icssg-prueth: icssg_rxnfc_rule_get_all() misses
  EMSGSIZE on empty buf
- [Medium] net: ti: icssg-prueth: unbalanced enable_irq() from stale
  flow->irq_disabled
- [Medium] net: ti: icssg-prueth: leak of RX NAPIs and IRQs in SR1.0
  emac_ndo_open()
- [Low] net: ti: icssg: guard(mutex) used in >20-line functions in
  icssg_classifier.c
- [Low] net: ti: icssg-prueth: emac_get_rx_ring_count() reports 4 rings
  on SR1
--

commit 41a5974310fc852a53e14b269769284ab4fbcb14
Author: Meghana Malladi <m-malladi@ti.com>

net: ti: icssg-prueth: Add ethtool RX flow classification support

This commit adds ethtool get_rxnfc/set_rxnfc and get_rx_ring_count support
for the TI ICSSG PRUeth driver, using FT3 hardware filters and RX classifier
OR tables to steer packets by EtherType to specific RX flows.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_classifier.c b/drivers/net/ethernet/ti/icssg/icssg_classifier.c
> index 87a8577093dbb..cf664e93d5c3d 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_classifier.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_classifier.c

[ ... ]

> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T),
> +		     (__force u32)ether_type);

[Severity: Medium]
Does casting __be16 ether_type directly to u32 break EtherType matching on
big-endian kernels?

regmap_write() takes a CPU-order value, so FT3_T expects the wire bytes
swapped into host order (as icssg_ft3_hsr_configurations() does with
FT3_PTP_PATTERN = 0xF788 for PTP 0x88F7).  On big-endian ARM64 (ARCH_K3),
(__force u32)ether_type writes 0x88F7 instead of 0xF788 and inverts the
pattern.  Using swab16(be16_to_cpu(ether_type)) works on both endiannesses
without a __force cast.

[ ... ]

> +		} else if (or_table[n]) {
> +			/* Classifiers 1..N with active rules: add BC|DA_P so
> +			 * only host-addressed frames are steered.
> +			 */
> +			val = RX_CLASS_FT_BC | RX_CLASS_FT_DA_P | or_table[n];
> +		} else {
> +			/* Classifiers 1..N with no rules: clear entirely.
> +			 * Must not leave BC|DA_P here — it would steal all
> +			 * host traffic away from classifier 0.
> +			 */
> +			val = 0;
> +		}
> +		regmap_write(miig_rt, RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), val);

[Severity: High]
Doesn't setting RX_CLASS_FT_BC | RX_CLASS_FT_DA_P in RX_CLASS_OR_EN for
classifiers 1..N steal all host broadcast and unicast traffic away from
classifier 0?

icssg_class_disable() leaves classifiers 1..15 in RX_CLASS_SEL_TYPE_OR mode
with AND_EN = 0, so RX_CLASS_OR_EN evaluates (BC || DA_P || FT3) rather than
((BC || DA_P) && FT3).  Installing any rule targeting queue n >= 1 therefore
steers every broadcast and host-unicast frame to queue n regardless of
EtherType, while still accepting foreign-MAC frames matching the FT3 slot.

[ ... ]

> +/* Initialize RX flow classification */
> +void icssg_rxnfc_rule_init(struct prueth_emac *emac)

[Severity: Medium]
Does the preceding commit "net: ti: icssg-prueth: Add multi-flow RX support
with per-flow NAPI" fail to link because it calls icssg_rxnfc_rule_init(),
icssg_rxnfc_rule_restore(), and icssg_rxnfc_rule_cleanup() before this
commit defines them?

Moving those declarations and call sites into this commit would keep the
series bisectable.

[ ... ]

> +void icssg_rxnfc_rule_restore(struct prueth_emac *emac)
> +{
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule;
> +
> +	if (slice < 0)
> +		return;
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);
> +
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list)
> +		icssg_ft3_program_filter(miig_rt, slice, rule->ft3_slot, rule);
> +
> +	icssg_rxnfc_classifier_update(emac);
> +}

[Severity: Medium]
Can icssg_rxnfc_rule_restore() reprogram a pre-existing rule into FT3 slot 9
after HSR offload mode is enabled?

Slot 9 is only reserved in allocate_ft3_slot() and icssg_rxnfc_rule_add()
when is_hsr_offload_mode is already true.  If a user installs a rule in
slot 9 in EMAC mode and later transitions to HSR offload via
prueth_hsr_port_link() -> icssg_change_mode() -> prueth_emac_restart(),
prueth_emac_common_start() configures classifier 10 with RX_CLASS_OR_DUP_PTP
(bit 9 set) and icssg_rxnfc_rule_restore() then restores slot 9, causing
that rule's EtherType to falsely trigger classifier 10.

[ ... ]

> +/* Add a new RX flow classification rule */
> +int icssg_rxnfc_rule_add(struct prueth_emac *emac, struct ethtool_rxnfc *info)
> +{
> +	struct ethtool_rx_flow_spec *fs = &info->fs;
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule;
> +	int ft3_slot;
> +	int ret;
> +
> +	if (slice < 0)
> +		return -EINVAL;
> +
> +	/* Validate rule parameters */
> +	ret = validate_rule(emac, fs);
> +	if (ret)
> +		return ret;
> +
> +	/* Validate explicit location: reject special specifiers, out-of-range
> +	 * values, and the reserved slot 14 used by HSR/PRP.
> +	 * Bound against ICSSG_NUM_FT3_SLOTS (16), not ICSSG_RXNFC_MAX_RULES
> +	 * (15), so that slot 15 is reachable as an explicit location.
> +	 */
> +	if (fs->location != RX_CLS_LOC_ANY) {
> +		if (fs->location >= ICSSG_NUM_FT3_SLOTS ||
> +		    BIT(fs->location) & ICSSG_FT3_RESERVED_SLOTS ||
> +		    (emac->prueth->is_hsr_offload_mode &&
> +		     fs->location == FT3_HSR_OR_SLOT))
> +			return -EINVAL;
> +	}
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);

[Severity: Low]
As reported by Simon Horman on v1 [1],
Documentation/process/maintainer-netdev.rst discourages guard() in functions
longer than 20 lines and prefers normal lock/unlock or scoped_guard().
icssg_rxnfc_rule_cleanup(), icssg_rxnfc_rule_add(), icssg_rxnfc_rule_del(),
and icssg_rxnfc_rule_get_all() all exceed 20 lines and still use
guard(mutex).

[ ... ]

> +	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
> +		if (!rule_locs) {
> +			/* Caller passed rule_cnt=0: just count active rules */
> +			count++;
> +			continue;
> +		}
> +		if (count >= rule_locs_capacity) {
> +			ret = -EMSGSIZE;
> +			break;
> +		}
> +		rule_locs[count++] = rule->location;
> +	}

[Severity: Medium]
Should icssg_rxnfc_rule_get_all() return -EMSGSIZE when rule_locs is NULL
and active rules exist?

ethtool_get_rxnfc() passes rule_buf = NULL whenever userspace supplies
info.rule_cnt == 0 to ETHTOOL_GRXCLSRLALL.  Bypassing the capacity check on
!rule_locs returns 0 with a non-zero info->rule_cnt even though no rule
locations were written to userspace.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index b715af21d23ac..b74e1a9706e40 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c

[ ... ]

> @@ -159,15 +160,17 @@ static void emac_get_channels(struct net_device *ndev,
>  {
>  	struct prueth_emac *emac = netdev_priv(ndev);
>  
> -	ch->max_rx = 1;
> +	ch->max_rx = ICSSG_MAX_RFLOWS;
>  	ch->max_tx = PRUETH_MAX_TX_QUEUES;

[Severity: High]
In commit "net: ti: icssg-prueth: Add multi-flow RX support with per-flow
NAPI", does emac_get_channels() still advertise ICSSG_MAX_RFLOWS on AM654
SR2.0 even though AM654 multi-flow is broken and deferred?

On AM654 (UDMAP), k3_udma_glue sets rx_chn->single_fdq = true, so all flows
share a single 512-entry FDQ ring.  Configuring rx_flow_num > 1 overflows
the shared FDQ on open when flow 1 pushes descriptors after flow 0 fills it,
leaks pages or destroys flows[i].pg_pool prematurely during
prueth_create_rxqs() unwind and prueth_destroy_rxqs() teardown, and recycles
pages against the wrong flow's page_pool in emac_rx_packet().  Should max_rx
be capped to 1 on AM654 until shared-FDQ support is implemented?

[ ... ]

> +static u32 emac_get_rx_ring_count(struct net_device *ndev)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +
> +	return emac->rx_flow_num;
> +}

[Severity: Low]
Does emac_get_rx_ring_count() report 4 RX rings instead of 1 on AM654 SR1.0?

icssg_prueth_sr1.c sets emac->rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1 (4) for
internal UDMA flow allocation, even though SR1 only allocates 1 netdev RX
queue and enables 1 data flow (and emac_get_channels() reports max_rx = 1).
Returning 1 when emac->is_sr1 is set would keep ETHTOOL_GRXRINGS consistent.

[ ... ]

> +	case ETHTOOL_GRXCLSRLALL: {
> +		u32 rule_cnt = 0;
> +
> +		info->data = ICSSG_NUM_FT3_SLOTS | RX_CLS_LOC_SPECIAL;
> +		ret = icssg_rxnfc_rule_get_all(emac, rule_locs,
> +					       info->rule_cnt, &rule_cnt);
> +		info->rule_cnt = rule_cnt;
> +		break;
> +	}

[Severity: Medium]
Should RX_CLS_LOC_SPECIAL be omitted from info->data in the
ETHTOOL_GRXCLSRLALL case?

Per struct ethtool_rxnfc in include/uapi/linux/ethtool.h, RX_CLS_LOC_SPECIAL
is only ORed into data for ETHTOOL_GRXCLSRLCNT.  ETHTOOL_GRXCLSRLALL must
return only the rule table size (ICSSG_NUM_FT3_SLOTS), otherwise userspace
sees 0x80000010 instead of 16.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 9bb67e185a3ea..ecd42abe9a3f9 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c

[ ... ]

> +	napi_enable(&flow->napi_rx);
> +	/* Re-enable IRQ now that NAPI is live. IRQ may have been left
> +	 * disabled by hrtimer coalescing or a previous destroy_rxq.
> +	 */
> +	if (flow->irq_disabled) {
> +		flow->irq_disabled = false;
> +		enable_irq(flow->irq);
> +	}

[Severity: Medium]
In commit "net: ti: icssg-prueth: Add multi-flow RX support with per-flow
NAPI", can a stale flow->irq_disabled trigger an unbalanced enable_irq()
warning on reopen?

If emac_ndo_stop() runs while RX coalescing has flow->rx_hrtimer armed
(leaving flow->irq_disabled true), neither prueth_destroy_rxq() nor
prueth_ndev_del_rx_napi() clears flow->irq_disabled, and
prueth_init_rx_chns() does not reset it on the next emac_ndo_open().
Because request_irq() in prueth_ndev_add_rx_napi() enables the IRQ at depth
0, prueth_create_rxq() then calls enable_irq() on an already-enabled IRQ.

[ ... ]

>  	if (netif_running(emac->ndev)) {
>  		/* stop packets from wire for graceful teardown */
>  		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
> -		if (ret)
> +		if (ret) {
> +			xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);
>  			return ret;
> -		prueth_destroy_rxq(emac);
> +		}
> +		prueth_destroy_rxq(emac, queue_id);
>  	}

[Severity: High]
In commit "net: ti: icssg-prueth: Add multi-flow RX support with per-flow
NAPI", do prueth_xsk_pool_enable() and prueth_xsk_pool_disable() tear down a
single RX flow while the shared UDMA RX channel is still enabled?

prueth_destroy_rxq() resets the flow and destroys flow->pg_pool (or unmaps
the XSK pool in prueth_xsk_pool_disable()) without calling
k3_udma_glue_disable_rx_chn().  Because the live UDMA channel may still hold
prefetched FDQ descriptors, this risks DMA use-after-free, page leaks, or
page_pool_destroy() stalls when attaching or detaching AF_XDP zero-copy on a
running interface.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> index 21a14b3bc889b..c166977b424ef 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c

[ ... ]

> +	emac->rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1;
> +
> +	/* Clear XSK state on open: any pool bound while interface was down
> +	 * is no longer valid. User must re-enable AF_XDP after bringing
> +	 * the interface up.
> +	 */
> +	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);

[Severity: High]
In commit "net: ti: icssg-prueth: Add multi-flow RX support with per-flow
NAPI", does this bitmap_zero() cause a NULL pointer dereference whenever an
SR1.0 interface is opened?

Unlike icssg_prueth.c, prueth_netdev_init() in icssg_prueth_sr1.c never
allocates emac->xsk_queues, so the pointer is always NULL.

[ ... ]

>  free_rx_irq:
> -	free_irq(emac->rx_chns.irq[rx_flow], emac);
> +	prueth_ndev_del_rx_napi(emac, 1);

[Severity: Medium]
In commit "net: ti: icssg-prueth: Add multi-flow RX support with per-flow
NAPI", does this error-unwind path leak 3 of the 4 RX NAPIs and IRQs on
SR1.0?

emac_ndo_open() sets emac->rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1 (4) before
calling prueth_ndev_add_rx_napi(), which registers 4 NAPIs and 4 IRQs.
Passing 1 instead of PRUETH_MAX_RX_FLOWS_SR1 (as emac_ndo_stop() does) leaks
flows 1..3 if a later open step fails, leaving stale NAPI entries on
ndev->napi_list and stale IRQ handlers.

[1] https://lore.kernel.org/r/20261125113634.GT31322@horms.kernel.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203121447.2605779-1-m-malladi@ti.com?part=2

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI
  2026-12-03 12:14 ` [PATCH net-next v2 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI Meghana Malladi
  2026-12-04 12:44   ` sashiko-bot
@ 2026-12-04 13:25   ` netdev-bot+sashiko
  1 sibling, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 13:25 UTC (permalink / raw)
  To: m-malladi
  Cc: marco.crivellari, kees+treewide, laixiangwu, philippe.schenker,
	haokexin, devnexen, horms, sdf, john.fastabend, hawk, daniel, ast,
	pabeni, kuba, edumazet, davem, andrew+netdev, bpf, netdev,
	linux-arm-kernel, srk, vigneshr, rogerq, danishanwar

Thank you for your contribution! Sashiko AI review found 23 potential
issue(s) to consider.

Critical: 0 · High: 8 · Medium: 10 · Low: 5

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] NULL pointer dereference on every SR1 interface open.
- [High] emac_ndo_stop() now runs bitmap_zero(emac->xsk_queues, ...) at
  icssg_prueth.c:1170, and emac_ndo_open() does the same at :1075.
- [High] Unbalanced NAPI disable leads to an ifdown hang.
- [High] The rewritten SR1 management channel gives each mgm flow its own
  FDQ (rx_flow_cfg.ring_rxfdq0_id = K3_RINGACC_RING_ID_ANY per flow, so…
- [High] In SR1 emac_ndo_open(), a failure of
  prueth_prepare_rx_flow(emac, PRUETH_RX_FLOW_DATA_SR1) does 'goto stop'.
- [High] In SR1 emac_ndo_open(), a failure of the newly added second
  prueth_sr1_prepare_rx_mgm_flow(TIMESTAMP) call, or of…
- [High] prueth_xsk_pool_enable() and prueth_xsk_pool_disable() now tear
  down one flow with prueth_destroy_rxq(emac, qid) while the shared UDMA…
- [High] net: ti: icssg: undefined icssg_rxnfc_rule_* calls break build
  and linking
- [Medium] On AM654 SR2 (UDMAP, am654_icssg_pdata), emac_get_channels()
  advertises max_rx = ICSSG_MAX_RFLOWS (8) and emac_set_channels()…
- [Medium] SR1 data flows 0..2 are no longer serviced.
- [Medium] The patch silently fixes two real SR1 bugs in
  prueth_process_rx_mgm().
- [Medium] In the SR1 emac_ndo_open() error path, the 'free_rx_irq:'
  label calls prueth_ndev_del_rx_napi(emac, 1).
- [Medium] The per-flow 'bool irq_disabled' is an ad-hoc flag used to
  keep disable_irq/enable_irq balanced.
- [Medium] In the SR1 emac_ndo_stop(),
  page_pool_destroy(flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool) runs at…
- [Medium] With up to 8 RX flows, each with its own NAPI and IRQ that can
  run on different CPUs, emac_rx_packet() and emac_dispatch_skb_zc()…
- [Medium] net: ti: icssg: SR1 emac_ndo_open() skips mgm reset on partial
  setup error
- [Medium] net: ti: icssg: per-flow page_pool sized to total
  rx_chn->descs_num
- [Medium] net: ti: icssg: emac_rx_packet_zc() refill uses shared
  desc_pool avail
- [Low] The commit message does not match the diff.
- [Low] On SR1, emac_get_channels() reports ch->max_rx = 1 but
  ch->rx_count = emac->rx_flow_num, which is PRUETH_MAX_RX_FLOWS_SR1 (4)…
- [Low] On SR1, emac_rx_packet() calls skb_record_rx_queue(skb, flow_id)
  with flow_id = PRUETH_RX_FLOW_DATA_SR1 (3), which sets queue_mapping…
- [Low] prueth_sr1_prepare_rx_mgm_flow() compares the mgm descriptor
  pool's availability (PRUETH_MAX_RX_MGM_DESC_SR1 * 2 = 16) against…
- [Low] The patch adds per-flow RX coalescing state
  (prueth_rx_flow.rx_pace_timeout_ns for 8 flows) and multiple RX…

--

net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI

This commit raises the ICSSG driver from one RX flow per EMAC to up to
eight. Each flow gets its own NAPI, hrtimer, IRQ, page pool, XDP rxq and
AF_XDP pool, and all flows share one UDMA channel and descriptor pool. It
also replaces xsk_qid with an xsk_queues bitmap and open-codes the SR1
management channel setup in icssg_prueth_sr1.c.

> Extend ICSSG driver to support up to 8 independent RX flows per EMAC
> (PRUETH_MAX_RX_FLOWS 1 --> 8), enabling ethtool queue steering via set_rxnfc.

[Severity: Low]
Does this describe this patch accurately? It adds no .set_rxnfc or
.get_rxnfc callback. Those seem to arrive in the follow-up commit "net:
ti: icssg-prueth: Add ethtool RX flow classification support".

This patch does already add the rxnfc structures and prototypes in
icssg_prueth.h. It also calls icssg_rxnfc_rule_init(),
icssg_rxnfc_rule_restore() and icssg_rxnfc_rule_cleanup() from
prueth_netdev_init(), emac_ndo_open() and prueth_netdev_exit().

Would that plumbing fit better in the classification commit?

The patch also removes PRUETH_MODULE_DESCRIPTION and
ICSSG_CTRL_RGMII_ID_MODE, and moves PRUETH_MAX_TX_QUEUES into
icssg_config.h. The commit message mentions none of these.

> - ndev->stats.rx_errors/rx_dropped use plain RMW from concurrent NAPIs;
>   per-cpu stats refactor deferred.

The per-packet rx_bytes and rx_packets updates in emac_rx_packet() and
emac_dispatch_skb_zc() race the same way. Should this limitation list
them too?

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_common.c b/drivers/net/ethernet/ti/icssg/icssg_common.c
> index 4a7d1a6f470b1..fc7e7847580f8 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_common.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_common.c

[ ... ]

> @@ -1132,15 +1198,16 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id, u32 *xdp_state)
>  	skb->protocol = eth_type_trans(skb, ndev);
>  
>  	skb_mark_for_recycle(skb);
> -	napi_gro_receive(&emac->napi_rx, skb);
> +	skb_record_rx_queue(skb, flow_id);

[Severity: Low]
On SR1, flow_id here is PRUETH_RX_FLOW_DATA_SR1 (3), so queue_mapping
becomes 4. The SR1 prueth_netdev_init() still allocates the netdev with
alloc_etherdev_mq(sizeof(*emac), num_tx_chn), which gives a single RX
queue. The SR1 emac_ndo_open() never calls netif_set_real_num_rx_queues().

Is recording an RX queue index outside the registered range intended?
get_rps_cpu() and netif_get_rxqueue() quietly fall back to queue 0, so
per-queue RPS/RFS see the wrong queue.

> +	napi_gro_receive(&emac->rx_chns.flows[flow_id].napi_rx, skb);
>  	ndev->stats.rx_bytes += pkt_len;
>  	ndev->stats.rx_packets++;

[Severity: Medium]
There can now be up to eight flows, each with its own NAPI and IRQ, and
they can run on different CPUs. Can these plain read-modify-write updates
of the shared ndev->stats lose increments?

The same applies to rx_dropped and rx_errors here and in
emac_dispatch_skb_zc(). Before this patch a single RX NAPI serialized
these updates.

The netdev already uses NETDEV_PCPU_STAT_TSTATS. Could
dev_sw_netstats_rx_add() be used for the per-packet counters?

[ ... ]

> @@ -1436,50 +1507,38 @@ EXPORT_SYMBOL_GPL(prueth_cleanup_tx_ts);
>  
>  int icssg_napi_rx_poll(struct napi_struct *napi_rx, int budget)
>  {
> -	struct prueth_emac *emac = prueth_napi_to_emac(napi_rx);
> -	int rx_flow = emac->is_sr1 ?
> -		PRUETH_RX_FLOW_DATA_SR1 : PRUETH_RX_FLOW_DATA;
> -	int flow = emac->is_sr1 ?
> -		PRUETH_MAX_RX_FLOWS_SR1 : PRUETH_MAX_RX_FLOWS;
> -	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
> +	struct prueth_rx_flow *rx_flow = prueth_napi_to_rx_chn(napi_rx);
> +	struct prueth_emac *emac = rx_flow->emac;
>  	int xdp_state_or = 0;
>  	int num_rx = 0;
> -	int cur_budget;
>  	u32 xdp_state;
>  	int ret;
>  
> -	while (flow--) {
> -		if (rx_chn->xsk_pool) {
> -			num_rx = emac_rx_packet_zc(emac, flow, budget);
> -		} else {
> -			cur_budget = budget - num_rx;
> -
> -			while (cur_budget--) {
> -				ret = emac_rx_packet(emac, flow, &xdp_state);
> -				xdp_state_or |= xdp_state;
> -				if (ret)
> -					break;
> -				num_rx++;
> -			}
> +	if (rx_flow->xsk_pool) {
> +		num_rx = emac_rx_packet_zc(emac, rx_flow->id, budget);
> +	} else {
> +		while (budget - num_rx > 0) {
> +			ret = emac_rx_packet(emac, rx_flow->id, &xdp_state);
> +			xdp_state_or |= xdp_state;
> +			if (ret)
> +				break;
> +			num_rx++;
>  		}
> -
> -		if (num_rx >= budget)
> -			break;
>  	}

[Severity: Medium]
Are SR1 data flows 0..2 still serviced after this change? Previously the
SR1 poll looped over all PRUETH_MAX_RX_FLOWS_SR1 flows. Now each NAPI polls
only its own flow.

prueth_ndev_add_rx_napi() requests IRQs for all four flows. The SR1
emac_ndo_open(), however, only creates a page pool for
flows[PRUETH_RX_FLOW_DATA_SR1] and only enables that flow's NAPI.

Suppose the firmware completes a frame on flow 0..2. prueth_rx_irq()
disables the IRQ, and napi_schedule() does nothing on the never-enabled
NAPI, so nothing ever pops the RXCQ entry.

Could this keep consuming shared FDQ descriptors until flow 3 starves? At
ifdown, could it also leave descriptors outstanding when
k3_cppi_desc_pool_destroy() runs, and so reach the BUG_ON in
gen_pool_destroy()?

[ ... ]

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index b715af21d23ac..8af4bba62efa7 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c

[ ... ]

> @@ -159,15 +160,17 @@ static void emac_get_channels(struct net_device *ndev,
>  {
>  	struct prueth_emac *emac = netdev_priv(ndev);
>  
> -	ch->max_rx = 1;
> +	ch->max_rx = ICSSG_MAX_RFLOWS;

[Severity: Medium]
Can more than one RX flow actually come up on AM654 SR2 (UDMAP)? The UDMAP
RX channel is single_fdq. prueth_init_rx_chns() binds flows 1..N to flow
0's FDQ with K3_RINGACC_RING_SHARED. k3_ringacc_ring_cfg() returns early
when use_count != 1, so the shared ring keeps flow 0's size of
PRUETH_MAX_RX_DESC.

prueth_prepare_rx_flow() for flow 0 fills that ring with 512 descriptors.
For flow 1 the desc_avail check passes, because the pool holds 512 * N.
The first push then fails with -ENOMEM because the ring is full, so
prueth_create_rxqs() unwinds and ndo_open fails.

On AM654 SR2, "ethtool -L ethX rx 2" followed by ifup would leave the
interface unable to come up. The commit message says multi-flow on AM654
is deferred. Should max_rx stay at 1 on UDMAP until then?

>  	ch->max_tx = PRUETH_MAX_TX_QUEUES;
>  
>  	/* Disable multiple TX channels due to timeouts
>  	 * when using more than one queue */
> -	if (emac->is_sr1)
> +	if (emac->is_sr1) {
> +		ch->max_rx = 1;
>  		ch->max_tx = 1;
> +	}
>  
> -	ch->rx_count = 1;
> +	ch->rx_count = emac->rx_flow_num;

[Severity: Low]
On SR1, rx_flow_num is PRUETH_MAX_RX_FLOWS_SR1 (4), set in both
prueth_netdev_init() and emac_ndo_open(), while max_rx is 1. "ethtool -l"
would then show a current value above the maximum.

The ethtool core starts from the get_channels() values and rejects
rx_count > max_rx. Doesn't that mean "ethtool -L ethX tx N" without an rx
argument now fails with -EINVAL on SR1?

[ ... ]

> @@ -264,7 +271,8 @@ static int emac_set_coalesce(struct net_device *ndev,
>  		coal->tx_coalesce_usecs = ICSSG_MIN_COALESCE_USECS;
>  	}
>  
> -	emac->rx_pace_timeout_ns = coal->rx_coalesce_usecs * 1000;
> +	for (i = 0; i < PRUETH_MAX_RX_FLOWS; i++)
> +		rx_chn->flows[i].rx_pace_timeout_ns = coal->rx_coalesce_usecs * 1000;
>  	tx_chn->tx_pace_timeout_ns = coal->tx_coalesce_usecs * 1000;

[Severity: Low]
Now that RX coalescing is per flow, should emac_get_per_queue_coalesce()
and emac_set_per_queue_coalesce() handle it as well? Both still bound the
queue by PRUETH_MAX_TX_QUEUES and only touch tx_coalesce_usecs.

As a result, a per-queue rx-usecs request on queues 1..3 returns success
but has no effect, and RX queues 4..7 are rejected with -EINVAL.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 9bb67e185a3ea..bda6d92a8158d 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c

[ ... ]

> @@ -921,7 +866,39 @@ static void prueth_destroy_txq(struct prueth_emac *emac)
>  	}
>  }
>  
> -static void prueth_destroy_rxq(struct prueth_emac *emac)
> +static void prueth_destroy_rxq(struct prueth_emac *emac, int qid)
> +{
> +	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
> +	struct prueth_rx_flow *flow = &rx_chn->flows[qid];
> +	dma_addr_t desc_dma;
> +
> +	napi_disable(&flow->napi_rx);
> +	hrtimer_cancel(&flow->rx_hrtimer);
> +
> +	/* k3_udma_glue_reset_rx_chn() only drains the FDQ; it resets the
> +	 * completion ring (RXCQ) without freeing descriptors still in it.
> +	 * Teardown posts TDCM only to flow 0's RXCQ; flows 1..N have no
> +	 * NAPI trigger to drain their RXCQs. Drain each flow's RXCQ here
> +	 * so page_pool_destroy() finds no inflight pages.
> +	 */
> +	while (!k3_udma_glue_pop_rx_chn(rx_chn->rx_chn, qid, &desc_dma)) {
> +		if (!cppi5_desc_is_tdcm(desc_dma))
> +			prueth_rx_cleanup(rx_chn, desc_dma);
> +	}
> +
> +	k3_udma_glue_reset_rx_chn(rx_chn->rx_chn, flow->id, rx_chn,
> +				  prueth_rx_cleanup);

[Severity: High]
When prueth_xsk_pool_enable() or prueth_xsk_pool_disable() calls this,
the shared UDMA RX channel is still enabled. Nothing calls
k3_udma_glue_tdown_rx_chn() or disables the channel, and
prueth_create_rxq() does not re-enable it. Is it safe to drain and reset
the rings of a live channel here?

A descriptor can complete after the drain loop but before the RXCQ reset
inside k3_udma_glue_reset_rx_chn(). That reset is k3_ringacc_ring_reset(),
which runs no cleanup, so the descriptor is dropped without being freed.

It then stays allocated in desc_pool, and the next ndo_stop reaches
k3_cppi_desc_pool_destroy() with outstanding descriptors, which hits the
BUG_ON in gen_pool_destroy(). Its page also keeps the old page_pool in
flight.

The FDQ popped here is still being consumed by the DMA engine. The commit
message also notes that UDMA may have prefetched FDQ descriptors, which
could complete later with stale swdata.

The baseline did a full channel teardown, waited for the TDCM, and then
disabled and re-enabled the channel. So this also affects the default
rx_flow_num == 1 XSK case.

[ ... ]

> @@ -978,27 +947,81 @@ static int prueth_create_txq(struct prueth_emac *emac)
>  	return ret;
>  }
>  
> -static int prueth_create_rxq(struct prueth_emac *emac)
> +static int prueth_create_rxq(struct prueth_emac *emac, int id)
>  {

[ ... ]

> +	napi_enable(&flow->napi_rx);
> +	/* Re-enable IRQ now that NAPI is live. IRQ may have been left
> +	 * disabled by hrtimer coalescing or a previous destroy_rxq.
> +	 */
> +	if (flow->irq_disabled) {
> +		flow->irq_disabled = false;
> +		enable_irq(flow->irq);
> +	}
> +	return 0;

[Severity: Medium]
Can this lead to unbalanced enable_irq() calls? irq_disabled is written
from prueth_rx_irq() (hardirq), emac_rx_timer_callback(), the NAPI poll,
and now here from process context. There is no lock and no atomic
test-and-clear.

The flag is never reset across close/open. It stays true if the IRQ fired
after napi_disable(), or if prueth_destroy_rxq() cancelled a pending
pacing hrtimer. free_irq() followed by request_irq() resets the IRQ depth
to 0, so this enable_irq() on the next open would trigger the "Unbalanced
enable for IRQ" warning.

In the XSK enable/disable path, the flow's NAPI may also complete on
another CPU right after napi_enable(). Both sides can then see
irq_disabled == true and both call enable_irq().

prueth_sr1_reset_rx_mgm_chn() uses the same flag. After the disable path
it leaves the mgm flows with irq_disabled = true, and open does not reset
it. From the second SR1 stop on, disable_irq() is skipped while the mgm
rings are reset.

[ ... ]

> @@ -1136,6 +1167,8 @@ static int emac_ndo_stop(struct net_device *ndev)
>  	struct prueth_emac *emac = netdev_priv(ndev);
>  	struct prueth *prueth = emac->prueth;
>  
> +	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);
> +

[Severity: High]
Does clearing xsk_queues here, and again in emac_ndo_open(), leave XSK
pools DMA-mapped with no way to unmap them? The XSK core keeps the pool
bound across ifdown, because xsk_notifier only acts on NETDEV_UNREGISTER.

When the AF_XDP socket is closed later:

xp_disable_drv_zc()
  emac_ndo_bpf(XDP_SETUP_XSK_POOL, pool = NULL)
    prueth_xsk_pool_disable()
        if (!test_bit(queue_id, emac->xsk_queues)) {
            ...
            return -EINVAL;

xsk_pool_dma_unmap() is skipped, and xp_disable_drv_zc() hits
WARN(1, "Failed to disable zero-copy!"). The mapping made by
xsk_pool_dma_map() is never released, even after the umem pages are
freed.

After ifdown/ifup, rx_flow->xsk_pool and tx_chn->xsk_pool are also NULL,
so the driver silently stops servicing the still-bound socket.

Before this patch ndo_stop did not touch xsk_qid, so bind, ifdown and
close unmapped correctly.

[ ... ]

> @@ -1544,27 +1598,29 @@ static int prueth_xsk_pool_disable(struct prueth_emac *emac, u16 queue_id)
>  		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
>  		if (ret)
>  			return ret;
> -		prueth_destroy_rxq(emac);
> +		prueth_destroy_rxq(emac, queue_id);
>  	}
>  
>  	xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);
> -	emac->xsk_qid = -EINVAL;
> +	clear_bit(queue_id, emac->xsk_queues);
>  	prueth_set_xsk_pool(emac, queue_id);
>  
>  	if (netif_running(emac->ndev)) {
> -		ret = prueth_create_rxq(emac);
> -		if (ret) {
> -			netdev_err(emac->ndev, "Failed to create RX queue: %d\n", ret);
> -			return ret;
> -		}
> -		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
> -		if (ret) {
> -			prueth_destroy_rxq(emac);
> -			return ret;
> -		}
> +		ret = prueth_create_rxq(emac, queue_id);
> +		if (ret)
> +			netdev_err(emac->ndev,
> +				   "failed to recreate RX queue %d after XSK disable; bring interface down to recover: %d\n",
> +				   queue_id, ret);

[Severity: High]
What happens on the ifdown that this message recommends? prueth_destroy_rxq()
has already run napi_disable() on this flow, and the err: path in
prueth_create_rxq() skips napi_enable(). Later:

emac_ndo_stop()
  prueth_destroy_rxqs()
    prueth_destroy_rxq()
      napi_disable(&flow->napi_rx);

This calls napi_disable() a second time on the same NAPI.
NAPI_STATE_SCHED stays set on a disabled NAPI, so napi_disable_locked()
spins forever while holding the netdev lock and RTNL.

The best-effort prueth_create_rxq() in the err_napi path of
prueth_xsk_pool_enable() has the same problem when it fails. If the
failed queue is flow 0, the RX TDCM would never be popped either.

[ ... ]

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> index 21a14b3bc889b..c166977b424ef 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> @@ -303,10 +303,10 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,
>  	page = swdata->data.page;
>  	cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
>  
> -	dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE);
> +	page_pool_dma_sync_for_cpu(rx_chn->flows[flow_id].pg_pool, page, 0, PAGE_SIZE);
>  	k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
>  
> -	new_page = page_pool_dev_alloc_pages(rx_chn->pg_pool);
> +	new_page = page_pool_dev_alloc_pages(rx_chn->flows[flow_id].pg_pool);
>  	/* if allocation fails we drop the packet but push the
>  	 * descriptor back to the ring with old skb to prevent a stall
>  	 */
> @@ -319,14 +319,123 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,
>  	}
>  
>  	/* queue another DMA */
> -	ret = prueth_dma_rx_push_mapped(emac, &emac->rx_chns, new_page,
> -					PRUETH_MAX_PKT_SIZE);
> +	ret = prueth_dma_rx_push_mapped(emac, rx_chn, new_page,
> +					PRUETH_MAX_PKT_SIZE, flow_id);

[Severity: Medium]
With several flows sharing rx_chn->desc_pool, the free count of the
whole pool no longer tells how many buffers this flow can post.
Whenever another flow holds fewer than PRUETH_MAX_RX_DESC descriptors,
avail_desc is non-zero even when this flow's 512-entry FDQ is already
full. A second XSK flow whose fill ring is not full is one example.

prueth_rx_alloc_zc() then allocates an xdp_buff and a descriptor, and
k3_udma_glue_push_rx_chn() fails with -ENOMEM because the ring is
full. As a result:

- a netdev_err() is logged on every poll
- the buffer is handed back with xsk_buff_free()
- need_wakeup is set because ret < alloc_budget

So userspace keeps kicking NAPI into the same failure. This happens on
AM64x PKTDMA, where each flow has its own FDQ, even with only one NAPI
running.

The concurrent case also hits page-pool flows. emac_rx_packet() frees
its descriptor with k3_cppi_desc_pool_free() before
prueth_dma_rx_push_mapped() allocates the replacement. An XSK flow
refilling on another CPU can take that descriptor in between.

The page-pool flow then hits WARN_ON(ret < 0) and recycles new_page.
It permanently loses one posted buffer, since it only refills
one-for-one on completions.

The commit message defers this together with the AM654 FDQ work, but
this patch already enables multiple flows on AM64x. Could the refill
budget be bounded per flow, for example by tracking how many buffers
each flow has posted? Or should each flow get its own share of the
descriptor pool?

[Severity: Medium]
These hunks fix two existing SR1 bugs in prueth_process_rx_mgm(). The old
dma_unmap_single() unmapped a page owned by a PP_FLAG_DMA_MAP page_pool.
The old refill pushed into the data channel (&emac->rx_chns) instead of
the management channel.

The commit message mentions neither fix, and there is no Fixes: tag.
Could they be split into a separate patch so stable kernels pick them up?

[ ... ]

> +	desc_avail = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
> +	if (desc_avail < PRUETH_MAX_RX_DESC)
> +		netdev_warn(emac->ndev,
> +			    "not enough RX descriptors available %d < %d\n",
> +			    desc_avail, PRUETH_MAX_RX_DESC);
> +
> +	for (i = 0; i < desc_avail; i++) {

[Severity: Low]
Should this compare against the mgm sizes instead? The mgm descriptor
pool holds PRUETH_MAX_RX_MGM_DESC_SR1 * 2 = 16 entries. Comparing against
PRUETH_MAX_RX_DESC (512) makes this warning fire on every SR1 open.

The loop then pushes 16 buffers into an FDQ sized
PRUETH_MAX_RX_MGM_DESC_SR1 (8). The 9th push fails, so "failed to push rx
mgm buf" is also logged on every open.

[ ... ]

> @@ -514,37 +629,123 @@ static int emac_ndo_open(struct net_device *ndev)
>  		return ret;
>  	}
>  
> -	max_rx_flows = PRUETH_MAX_RX_FLOWS_SR1;
> -	ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx",
> -				  max_rx_flows, PRUETH_MAX_RX_DESC);
> +	emac->rx_flow_num = PRUETH_MAX_RX_FLOWS_SR1;
> +
> +	/* Clear XSK state on open: any pool bound while interface was down
> +	 * is no longer valid. User must re-enable AF_XDP after bringing
> +	 * the interface up.
> +	 */
> +	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);

[Severity: High]
Where is emac->xsk_queues allocated for SR1? devm_bitmap_zalloc() is only
called from the SR2 prueth_netdev_init() in icssg_prueth.c. The SR1
prueth_netdev_init() in this file never allocates it, so the pointer is
NULL in the zeroed netdev_priv.

With nbits = 8, bitmap_zero() compiles to *dst = 0. Wouldn't every SR1
ifup oops here?

[ ... ]

> +		flow = &emac->rx_mgm_chn.flows[i];
> +		flow->emac = emac;
> +		flow->id = i;
> +		flow->irq = -EINVAL;
> +
> +		rx_flow_cfg.ring_rxfdq0_id = K3_RINGACC_RING_ID_ANY;

[Severity: High]
This gives each mgm flow its own FDQ. k3-udma-glue still marks UDMAP
channels single_fdq, so k3_udma_glue_reset_rx_chn() skips the FDQ drain
for every flow except flow 0:

	if (rx_chn->single_fdq && flow_num)
		goto do_reset;

prueth_sr1_prepare_rx_mgm_flow() fills the TIMESTAMP flow's FDQ, and
prueth_sr1_reset_rx_mgm_chn() then never drains it.

Could prueth_sr1_cleanup_rx_mgm_chn() then call page_pool_destroy() with
pages in flight and k3_cppi_desc_pool_destroy() with 8 descriptors
outstanding? That would hit the BUG_ON in gen_pool_destroy() on every SR1
ifdown.

The baseline shared flow 0's FDQ across the mgm flows, which matched
single_fdq.

[ ... ]

> @@ -570,11 +771,15 @@ static int emac_ndo_open(struct net_device *ndev)
>  	icssg_mii_update_mtu(prueth->mii_rt, slice, ndev->max_mtu);
>  
>  	/* Prepare RX */
> -	ret = prueth_prepare_rx_chan(emac, &emac->rx_chns, PRUETH_MAX_PKT_SIZE);
> +	ret = prueth_prepare_rx_flow(emac, PRUETH_RX_FLOW_DATA_SR1);
>  	if (ret)
>  		goto stop;

[Severity: High]
Does this goto leak flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool? The new
page_pool_destroy() sits under reset_rx_chn:, and prueth_cleanup_rx_chns()
no longer destroys page pools.

The failure can also happen partway through the push loop. In that case
prueth_prepare_rx_flow() calls k3_udma_glue_reset_rx_chn() for flow 3
under err_free_pushed. On UDMAP that call skips the FDQ drain
(single_fdq && flow_num), and the stop path never resets rx_chns.

Wouldn't cleanup_rx then call k3_cppi_desc_pool_destroy() with
descriptors still allocated and hit the BUG_ON in gen_pool_destroy()?

>  
> -	ret = prueth_prepare_rx_chan(emac, &emac->rx_mgm_chn, 64);
> +	ret = prueth_sr1_prepare_rx_mgm_flow(emac, PRUETH_RX_MGM_FLOW_RESPONSE_SR1, 64);
> +	if (ret)
> +		goto reset_rx_chn;
> +
> +	ret = prueth_sr1_prepare_rx_mgm_flow(emac, PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1, 64);
>  	if (ret)
>  		goto reset_rx_chn;

[Severity: Medium]
If prueth_sr1_prepare_rx_mgm_flow() fails here for the TIMESTAMP flow,
or k3_udma_glue_enable_rx_chn() on rx_mgm_chn fails just below, the
RESPONSE flow has already pushed pages and descriptors into its FDQ.
Both branches jump to reset_rx_chn:, which skips
prueth_sr1_reset_rx_mgm_chn().

Nothing drains rx_mgm_chn before prueth_sr1_cleanup_rx_mgm_chn() runs.
It then destroys flows[0].pg_pool with pages still in flight and calls
k3_cppi_desc_pool_destroy() with descriptors still allocated. That
trips the WARN there and the BUG_ON in gen_pool_destroy().

Should both branches go to reset_rx_mgm_chn: instead? That label calls
prueth_sr1_reset_rx_mgm_chn(emac, true), which also disables a channel
that was never enabled. Is that harmless here, or does this unwind
need a reset-only step?

[Severity: High]
The TIMESTAMP flow setup can fail here, for example if page_pool_create()
fails. By then the RESPONSE flow's FDQ is already filled. Jumping to
reset_rx_chn: skips prueth_sr1_reset_rx_mgm_chn().

Does anything drain those descriptors and pages before
prueth_sr1_cleanup_rx_mgm_chn() destroys the page pool and the mgm
descriptor pool? Without that, this also looks like it reaches the
BUG_ON in gen_pool_destroy().

The k3_udma_glue_enable_rx_chn(emac->rx_mgm_chn.rx_chn) failure already
used this label before the patch. The new call adds another failure
point, reached after the RESPONSE flow has been filled.

[ ... ]

> @@ -612,27 +817,29 @@ static int emac_ndo_open(struct net_device *ndev)
>  	 */
>  	prueth_reset_tx_chan(emac, i, false);
>  reset_rx_mgm_chn:

[ ... ]

>  free_rx_irq:
> -	free_irq(emac->rx_chns.irq[rx_flow], emac);
> +	prueth_ndev_del_rx_napi(emac, 1);

[Severity: Medium]
prueth_ndev_add_rx_napi() registered a NAPI, hrtimer and IRQ for every
flow up to emac->rx_flow_num (PRUETH_MAX_RX_FLOWS_SR1), but only flow 0
is torn down here. Doesn't this leave the IRQs and NAPIs for flows 1..3,
including data flow 3, registered?

The next open's request_irq() would then fail with -EBUSY. After
free_netdev(), those handlers would also keep a dev_id pointing into the
freed netdev_priv. emac_ndo_stop() passes PRUETH_MAX_RX_FLOWS_SR1 here.

[ ... ]

> @@ -683,16 +888,20 @@ static int emac_ndo_stop(struct net_device *ndev)
>  	for (i = 0; i < emac->tx_ch_num; i++)
>  		napi_disable(&emac->tx_chns[i].napi_tx);
>  
> -	max_rx_flows = PRUETH_MAX_RX_FLOWS_SR1;
>  	k3_udma_glue_tdown_rx_chn(emac->rx_chns.rx_chn, true);
>  
> -	prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, true);
> +	prueth_reset_rx_chan(emac, true);
> +
> +	if (emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool) {
> +		page_pool_destroy(emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool);
> +		emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].pg_pool = NULL;
> +	}
> +
>  	/* Teardown RX MGM channel */
>  	k3_udma_glue_tdown_rx_chn(emac->rx_mgm_chn.rx_chn, true);
> -	prueth_reset_rx_chan(&emac->rx_mgm_chn,
> -			     PRUETH_MAX_RX_MGM_FLOWS_SR1, true);
> +	prueth_sr1_reset_rx_mgm_chn(emac, true);
>  
> -	napi_disable(&emac->napi_rx);
> +	napi_disable(&emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].napi_rx);

[Severity: Medium]
The data flow's page pool was created with
pp_params.napi = &rx_flow->napi_rx, but it is destroyed here before that
NAPI is disabled. Doesn't page_pool_destroy() ->
page_pool_disable_direct_recycling() -> napi_assert_will_not_race() warn
when the NAPI is still enabled and idle?

A NAPI run during this window could also reach emac_rx_packet() after
the pool has been destroyed and pg_pool set to NULL.

Before the patch, prueth_cleanup_rx_chns() destroyed the pool after
napi_disable(). Should page_pool_destroy() move after this napi_disable()?

[ ... ]

> @@ -1752,7 +1837,9 @@ void prueth_netdev_exit(struct prueth *prueth,
>  	if (of_phy_is_fixed_link(emac->phy_node))
>  		of_phy_deregister_fixed_link(emac->phy_node);
>  
> -	netif_napi_del(&emac->napi_rx);
> +	/* Free any rules added while the interface was down */
> +	if (!emac->is_sr1)
> +		icssg_rxnfc_rule_cleanup(emac);
>  
>  	pruss_release_mem_region(prueth->pruss, &emac->dram);
>  	free_netdev(emac->ndev);

[Severity: High]
This patch calls three rxnfc functions:

- icssg_rxnfc_rule_init() from prueth_netdev_init()
- icssg_rxnfc_rule_restore() from emac_ndo_open()
- icssg_rxnfc_rule_cleanup() from prueth_netdev_exit()

It also declares them in icssg_prueth.h. None of them is defined until
patch 2/2.

icssg_common.o is linked into icssg.o for both CONFIG_TI_ICSSG_PRUETH
and CONFIG_TI_ICSSG_PRUETH_SR1. Doesn't this patch on its own then fail
to link with undefined symbols for both drivers? That breaks bisection
through the series.

Could the following move into the classification patch, so this one
builds on its own?

- the rxnfc declarations
- struct prueth_rxnfc and the rxnfc member of struct prueth_emac
- these three calls

[ ... ]

> @@ -1488,59 +1547,81 @@ int icssg_napi_rx_poll(struct napi_struct *napi_rx, int budget)
>  }
>  EXPORT_SYMBOL_GPL(icssg_napi_rx_poll);
>  
> -int prueth_prepare_rx_chan(struct prueth_emac *emac,
> -			   struct prueth_rx_chn *chn,
> -			   int buf_size)
> +int prueth_prepare_rx_flow(struct prueth_emac *emac,
> +			   int flow)
>  {
> +	int buf_size = PRUETH_MAX_PKT_SIZE;
> +	struct prueth_rx_flow *rx_flow;
> +	struct prueth_rx_chn *rx_chn;
> +	struct page_pool *pool;
>  	struct page *page;
>  	int desc_avail;
>  	int i, ret;
>  
> -	desc_avail = k3_cppi_desc_pool_avail(chn->desc_pool);
> -	if (desc_avail < chn->descs_num)
> -		netdev_warn(emac->ndev,
> -			    "not enough RX descriptors available %d < %d\n",
> -			    desc_avail, chn->descs_num);
> +	rx_chn = &emac->rx_chns;
> +	rx_flow = &emac->rx_chns.flows[flow];
>  
> -	if (chn->xsk_pool) {
> -		/* get pages from xsk_pool and push to RX ring
> -		 * queue as much as possible
> +	if (rx_flow->xsk_pool) {
> +		/* XSK zero-copy: buffers come from the XSK fill ring, no page
> +		 * pool needed.  Push up to PRUETH_MAX_RX_DESC XSK buffers.
>  		 */
> -		ret = prueth_rx_alloc_zc(emac, desc_avail);
> -		if (!ret)
> -			goto recycle_alloc_pg;
> -	} else {
> -		for (i = 0; i < desc_avail; i++) {
> -			/* NOTE: we're not using memory efficiently here.
> -			 * 1 full page (4KB?) used here instead of
> -			 * PRUETH_MAX_PKT_SIZE (~1.5KB?)
> -			 */
> -			page = page_pool_dev_alloc_pages(chn->pg_pool);
> -			if (!page) {
> -				netdev_err(emac->ndev, "couldn't allocate rx page\n");
> -				ret = -ENOMEM;
> -				goto recycle_alloc_pg;
> -			}
> +		desc_avail = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
> +		if (desc_avail < PRUETH_MAX_RX_DESC) {
> +			netdev_err(emac->ndev,
> +				   "not enough RX descriptors available %d < %d\n",
> +				   desc_avail, PRUETH_MAX_RX_DESC);
> +			return -ENOSPC;
> +		}
>  
> -			ret = prueth_dma_rx_push_mapped(emac, chn, page, buf_size);
> -			if (ret < 0) {
> -				netdev_err(emac->ndev,
> -					   "cannot submit page for rx chan %s ret %d\n",
> -					   chn->name, ret);
> -				page_pool_recycle_direct(chn->pg_pool, page);
> -				goto recycle_alloc_pg;
> -			}
> +		prueth_rx_alloc_zc(emac, flow, PRUETH_MAX_RX_DESC);
> +		return 0;
> +	}
> +
> +	pool = prueth_create_page_pool(emac, rx_chn->dma_dev, rx_chn->descs_num, rx_flow);
> +	if (IS_ERR(pool))
> +		return PTR_ERR(pool);
> +
> +	rx_flow->pg_pool = pool;
> +
> +	desc_avail = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
> +	if (desc_avail < PRUETH_MAX_RX_DESC) {
> +		netdev_err(emac->ndev,
> +			   "not enough RX descriptors available %d < %d\n",
> +			   desc_avail, PRUETH_MAX_RX_DESC);
> +		ret = -ENOSPC;
> +		goto err_free_pushed;
> +	}
> +
> +	for (i = 0; i < PRUETH_MAX_RX_DESC; ++i) {
> +		page = page_pool_dev_alloc_pages(pool);
> +		if (!page) {
> +			netdev_err(emac->ndev, "couldn't allocate rx page\n");
> +			ret = -ENOMEM;
> +			goto err_free_pushed;
> +		}
> +
> +		ret = prueth_dma_rx_push_mapped(emac, rx_chn, page, buf_size, flow);
> +		if (ret < 0) {
> +			netdev_err(emac->ndev,
> +				   "cannot submit skb for rx chan %s ret %d\n",
> +				   rx_flow->name, ret);
> +			page_pool_recycle_direct(pool, page);
> +			goto err_free_pushed;
>  		}
>  	}
>  
>  	return 0;
>  
> -recycle_alloc_pg:
> -	prueth_reset_rx_chan(&emac->rx_chns, PRUETH_MAX_RX_FLOWS, false);
> -
> +err_free_pushed:
> +	/* i pages were successfully pushed to the ring.  Reset the channel
> +	 * to drain them back and recycle via prueth_rx_cleanup before the
> +	 * caller destroys the page pool.
> +	 */
> +	k3_udma_glue_reset_rx_chn(rx_chn->rx_chn, flow, rx_chn,
> +				   prueth_rx_cleanup);
>  	return ret;
>  }
> -EXPORT_SYMBOL_GPL(prueth_prepare_rx_chan);
> +EXPORT_SYMBOL_GPL(prueth_prepare_rx_flow);
>  
>  void prueth_reset_tx_chan(struct prueth_emac *emac, int ch_num,
>  			  bool free_skb)

[Severity: Medium]
prueth_init_rx_chns() now sets rx_chn->descs_num to
PRUETH_MAX_RX_DESC * rx_flow_num for the shared descriptor pool. This
call passes that total as the pool_size of every per-flow page pool,
but each flow only ever posts PRUETH_MAX_RX_DESC pages.

page_pool_init() sizes the ptr_ring from pool_size. With 8 flows, each
flow gets a 4096-entry ring, and its pool can keep up to 4096 recycled
pages DMA-mapped.

With 4 KiB pages that is up to 128 MiB per port rather than 16 MiB,
and it grows with the square of the flow count. On SR1, rx_flow_num is
PRUETH_MAX_RX_FLOWS_SR1, so the one data flow's pool is sized 2048
instead of 512.

Should this pass PRUETH_MAX_RX_DESC instead?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203121447.2605779-1-m-malladi%40ti.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support
  2026-12-03 12:14 ` [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support Meghana Malladi
  2026-12-04 12:44   ` sashiko-bot
@ 2026-12-04 13:25   ` netdev-bot+sashiko
  1 sibling, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 13:25 UTC (permalink / raw)
  To: m-malladi
  Cc: marco.crivellari, kees+treewide, laixiangwu, philippe.schenker,
	haokexin, devnexen, horms, sdf, john.fastabend, hawk, daniel, ast,
	pabeni, kuba, edumazet, davem, andrew+netdev, bpf, netdev,
	linux-arm-kernel, srk, vigneshr, rogerq, danishanwar

Thank you for your contribution! Sashiko AI review found 16 potential
issue(s) to consider.

Critical: 0 · High: 4 · Medium: 9 · Low: 3

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The rule installed in icssg_rxnfc_classifier_update() widens the
  classifier match instead of narrowing it.
- [High] net: ti: icssg-prueth: uncapped multi-flow breaks AM654 shared
  RX FDQ
- [High] net: ti: icssg-prueth: live-channel XSK teardown in
  prueth_xsk_pool_enable()
- [High] net: ti: icssg-prueth: NULL deref of emac->xsk_queues in SR1.0
  emac_ndo_open()
- [Medium] The commit message says FT3 slot 9 is reserved in HSR offload
  mode, because classifier 10's OR_EN (RX_CLASS_OR_DUP_PTP = 0x4200)…
- [Medium] The series is split so that the previous patch, commit "net:
  ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI", does…
- [Medium] This patch is the first to steer RX traffic to flows 1..N, via
  the classifier programming in icssg_rxnfc_classifier_update().
- [Medium] icssg_ft3_program_filter() always sets FT3_START to
  PRP_PTP_ETHERTYPE_OFFSET (12), whatever the HSR/PRP mode.
- [Medium] icssg_ft3_program_filter() writes `(__force u32)ether_type`
  (the raw __be16 h_proto) into FT3_T (icssg_classifier.c:609-610).
- [Medium] net: ti: icssg-prueth: unbalanced enable_irq() from stale
  flow->irq_disabled
- [Medium] net: ti: icssg-prueth: leak of RX NAPIs and IRQs in SR1.0
  emac_ndo_open()
- [Medium] net: ti: icssg-prueth: icssg_rxnfc_rule_get_all() misses
  EMSGSIZE on empty buf
- [Medium] net: ti: icssg-prueth: ETHTOOL_GRXCLSRLALL sets
  RX_CLS_LOC_SPECIAL in data
- [Low] include/uapi/linux/ethtool.h says that for ETHTOOL_SRXCLSRLINS
  '@fs specifies the rule to add or update'.
- [Low] net: ti: icssg-prueth: emac_get_rx_ring_count() reports 4 rings
  on SR1
- [Low] net: ti: icssg: guard(mutex) used in >20-line functions in
  icssg_classifier.c

--

net: ti: icssg-prueth: Add ethtool RX flow classification support

This adds ethtool get_rxnfc/set_rxnfc support to the ICSSG driver, so
EtherType rules can steer received frames to specific RX flows using the FT3
hardware filters. Rules are kept in a per-EMAC list and programmed into FT3
slots and the RX classifier OR_EN registers. They are restored after a
firmware restart.

> - Add RXNFC rule tracking structures and lifecycle management

[Severity: Medium]
Is this accurate for this patch?

The previous patch, "net: ti: icssg-prueth: Add multi-flow RX support with
per-flow NAPI", already adds these:

- struct prueth_rxnfc
- the icssg_rxnfc_rule_* prototypes
- the call sites:

prueth_netdev_init()
    icssg_rxnfc_rule_init(emac);

emac_ndo_open()
    icssg_rxnfc_rule_restore(emac);

prueth_netdev_exit()
    icssg_rxnfc_rule_cleanup(emac);

The definitions only appear in this patch, in icssg_classifier.c. Doesn't
that leave the previous commit failing to link, which breaks bisection?

> Known limitation:
> - ndev->stats.rx_errors/rx_dropped racy with concurrent NAPIs;
>   per-cpu stats refactor deferred.

[Severity: Medium]
Can this be deferred when this patch is the one that makes the race
reachable?

Before this patch, non-SR1 hardware only enabled classifier 0
(icssg_class_default() uses num_classifiers = 1), so only one RX NAPI got
traffic. Once a rule steers an EtherType to queue N >= 1, the flow 0 and
flow N NAPIs can run at the same time on different CPUs.

Both then do plain read-modify-write updates on the shared ndev->stats
fields. The rx_dropped and rx_errors error paths do this, and so does the
fast path in emac_rx_packet():

	ndev->stats.rx_bytes += pkt_len;
	ndev->stats.rx_packets++;

Won't concurrent increments be lost? icssg_ndo_get_stats64() would also
report the racy rx_errors and rx_dropped values directly. The limitation as
written also leaves out rx_bytes and rx_packets.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_classifier.c b/drivers/net/ethernet/ti/icssg/icssg_classifier.c
> index 87a8577093dbb..cf664e93d5c3d 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_classifier.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_classifier.c

[ ... ]

> @@ -532,3 +543,430 @@ void icssg_ft3_hsr_configurations(struct regmap *miig_rt, int slice,

[ ... ]

> +/* Program FT3 filter slot with ethertype pattern */
> +static void icssg_ft3_program_filter(struct regmap *miig_rt, int slice,
> +				     int slot, struct icssg_rxnfc_rule *rule)
> +{
> +	const struct ethtool_rx_flow_spec *fs = &rule->flow_spec;
> +	__be16 ether_type;
> +
> +	/* Extract EtherType from flow spec (network byte order) */
> +	ether_type = fs->h_u.ether_spec.h_proto;
> +
> +	/* Deactivate filter before programming */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0);
> +
> +	/* EtherType is at byte 12 in standard Ethernet frames */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START),
> +		     PRP_PTP_ETHERTYPE_OFFSET);

[Severity: Medium]
How do these rules behave in HSR offload mode?

icssg_ft3_hsr_configurations() chooses the offset by HSR/PRP version,
because HSR-tagged frames carry a 6-byte tag before the payload EtherType:

	u8 offset = (prueth->hsr_prp_version == PRP_V1) ?
		    PRP_PTP_ETHERTYPE_OFFSET : HSR_PTP_ETHERTYPE_OFFSET;

With FT3_START fixed at 12, offset 12 of an HSR-tagged frame holds the HSR
EtherType 0x892F.

Wouldn't a rule such as proto 0x0800 then never match HSR-tagged IPv4
frames? The driver would still accept it and report it as installed.

> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_AUTO), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_OFFSET), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_JUMP_OFFSET), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_LEN), 0);
> +

[ ... ]

> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T),
> +		     (__force u32)ether_type);

[Severity: Medium]
Does this still match on big-endian kernels?

The comment above says no conversion is needed because, on LE, the raw
h_proto value equals the lower 16 bits of the LE word at the EtherType
offset. The HSR filter instead uses the endian-independent constant
FT3_PTP_PATTERN (0xF788).

TI_ICSSG_PRUETH depends on ARCH_K3 with no !CPU_BIG_ENDIAN restriction. On a
big-endian build the raw value of htons(0x0800) is 0x0800, while the
hardware expects 0x0008. It looks like no rule would ever match there.

Would something like swab16(ntohs(ether_type)) give the same encoding as
FT3_PTP_PATTERN on both endiannesses?

> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T_MASK), FT3_ETHERTYPE_MASK);

[ ... ]

> +	for (n = 0; n < emac->rx_flow_num; n++) {
> +		u32 val;
> +
> +		if (n == 0) {
> +			/* Classifier 0: RMW to preserve default BC|DA_P bits
> +			 * set by icssg_class_default().
> +			 */
> +			regmap_read(miig_rt,
> +				    RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), &val);
> +			val &= ~RX_CLASS_FT_FT3_MATCH_MASK;
> +			val |= or_table[n];
> +		} else if (or_table[n]) {
> +			/* Classifiers 1..N with active rules: add BC|DA_P so
> +			 * only host-addressed frames are steered.
> +			 */
> +			val = RX_CLASS_FT_BC | RX_CLASS_FT_DA_P | or_table[n];

[Severity: High]
Can this widen the match for classifier N instead of narrowing it?

icssg_class_disable() leaves classifiers 1..15 with AND_EN = 0 and the
select type set to OR:

	/* AND_EN = 0 */
	rx_class_set_and(miig_rt, slice, n, 0);
	...
	/* set CFG1 to OR */
	rx_class_sel_set_type(miig_rt, slice, n, RX_CLASS_SEL_TYPE_OR);

Nothing in this patch changes AND_EN or the select type for those
classifiers. The existing code treats OR_EN as a disjunction:

icssg_class_default() {
	...
	/* match on Broadcast or MAC_PRU address */
	data = RX_CLASS_FT_BC | RX_CLASS_FT_DA_P;
	...
}

With OR_EN = BC | DA_P | FT3_MATCH(slot), wouldn't classifier N fire on
broadcast, or own MAC, or the EtherType? That covers all host traffic plus
foreign-DA frames of that EtherType.

It looks like the case the else branch below warns about ("it would steal
all host traffic away from classifier 0"), and it would happen as soon as
one rule targets queue N >= 1.

For a rule targeting queue 0, the RMW path ORs the FT3 bit into classifier
0's OR_EN. Would frames of that EtherType then reach the host whatever
their destination MAC?

Either way, the hardware steering would not match what get_rxnfc reports.

> +		} else {

[ ... ]

> +void icssg_rxnfc_rule_restore(struct prueth_emac *emac)
> +{
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule;
> +
> +	if (slice < 0)
> +		return;
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);
> +
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list)
> +		icssg_ft3_program_filter(miig_rt, slice, rule->ft3_slot, rule);

[Severity: Low]
Documentation/process/maintainer-netdev.rst discourages guard() in any
function longer than 20 lines, considers scoped_guard() more readable,
and still weakly prefers plain lock/unlock.

These functions all take rxnfc_lock with guard(mutex) and are well past
that length:

- icssg_rxnfc_rule_add()
- icssg_rxnfc_rule_cleanup()
- icssg_rxnfc_rule_del()
- icssg_rxnfc_rule_get_all()

This also came up in the v1 review, where the reply was that the
locking would go back to explicit mutex_lock()/mutex_unlock(). Was that
dropped from v2 by accident?

[Severity: Medium]
This isn't introduced here. It comes from the previous patch in the
series, but it sits on the open path that now calls
icssg_rxnfc_rule_restore().

Can flow->irq_disabled survive an ifdown/ifup cycle?

With RX coalescing enabled (rx_pace_timeout_ns != 0), prueth_rx_irq()
sets flow->irq_disabled = true and disables the IRQ.
icssg_napi_rx_poll() leaves it set while flow->rx_hrtimer is armed. If
emac_ndo_stop() runs in that window:

prueth_destroy_rxq()
    hrtimer_cancel(&flow->rx_hrtimer);
prueth_ndev_del_rx_napi()
    free_irq()

Neither of these clears flow->irq_disabled, and prueth_init_rx_chns()
doesn't reset it on the next emac_ndo_open() either. request_irq() in
prueth_ndev_add_rx_napi() then installs the handler with the line
enabled, and prueth_create_rxq() does:

	if (flow->irq_disabled) {
		flow->irq_disabled = false;
		enable_irq(flow->irq);
	}

Wouldn't that hit the "Unbalanced enable for IRQ" WARN in
__enable_irq()? Should irq_disabled be reset when the flows are
initialized in prueth_init_rx_chns(), or cleared on the stop path once
the hrtimer has been cancelled?

[Severity: Medium]
Can this re-arm a user rule in FT3 slot 9 after HSR offload is enabled?

The slot 9 reservation is only checked at insert time, in
allocate_ft3_slot() and in the explicit location check in
icssg_rxnfc_rule_add(). A rule placed in slot 9 before HSR offload is
enabled stays in the list. That can be loc 9, or an auto-allocated slot
once slots 0-8 are in use.

When both ports then join an HSR device:

prueth_hsr_port_link()
    prueth->is_hsr_offload_mode = true;
    icssg_change_mode()
        prueth_emac_restart()
            prueth_emac_common_start()
                icssg_ft3_hsr_configurations()
            icssg_rxnfc_rule_restore(emac0)
            icssg_rxnfc_rule_restore(emac1)

icssg_ft3_hsr_configurations() enables classifier 10 with OR_EN bits 9 and
14. icssg_rxnfc_rule_restore() then reprograms slot 9 without checking
is_hsr_offload_mode. emac_ndo_open() does the same in HSR mode.

Wouldn't classifier 10 then fire on the user's EtherType? The commit
message says reserving slot 9 is meant to prevent exactly that.

> +
> +	icssg_rxnfc_classifier_update(emac);
> +}

[ ... ]

> +	/* Check for duplicate flow spec */
> +	if (rule_exists(emac, fs))
> +		return -EEXIST;
> +

[ ... ]

> +	if (fs->location != RX_CLS_LOC_ANY) {
> +		ft3_slot = fs->location;
> +		if (emac->rxnfc.ft3_slots_used & BIT(ft3_slot))
> +			return -EBUSY;

[Severity: Low]
Should ETHTOOL_SRXCLSRLINS be able to update an existing rule here?
include/uapi/linux/ethtool.h documents it as:

  For %ETHTOOL_SRXCLSRLINS, @fs specifies the rule to add or update.

rule_exists() returns -EEXIST for any rule with the same EtherType, and an
occupied explicit location returns -EBUSY. So re-running a command such as:

  ethtool -N ethX flow-type ether proto 0x88b5 action 2 loc 3

to move an existing rule to another queue always fails. The rule has to be
deleted and re-inserted, and matching traffic falls back to the default
queue in between.

> +		emac->rxnfc.ft3_slots_used |= BIT(ft3_slot);

[ ... ]

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> @@ -302,6 +302,63 @@ static int emac_set_per_queue_coalesce(struct net_device *ndev, u32 queue,
>  	return 0;
>  }
>  
> +static u32 emac_get_rx_ring_count(struct net_device *ndev)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +
> +	return emac->rx_flow_num;
> +}
> +
> +static int emac_get_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *info,
> +			  u32 *rule_locs)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +	int ret = 0;
> +
> +	if (emac->is_sr1)

[Severity: High]
Not part of this patch, but it breaks SR1, which this patch otherwise
keeps away from rxnfc.

The previous patch adds this to the SR1 emac_ndo_open() in
icssg_prueth_sr1.c:

	bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS);

icssg_prueth.c allocates emac->xsk_queues in prueth_netdev_init() with
devm_bitmap_zalloc(). The SR1 prueth_netdev_init() never does, so the
pointer is still NULL from alloc_etherdev_mq().

Doesn't that oops on every SR1 interface bring-up? Should SR1 allocate
the bitmap too, or skip the XSK bookkeeping if it isn't used there?

[Severity: Medium]
This is outside this patch, in the SR1 emac_ndo_open() added by the
previous patch. It follows from the same SR1 rx_flow_num handling.

emac_ndo_open() in icssg_prueth_sr1.c sets emac->rx_flow_num to
PRUETH_MAX_RX_FLOWS_SR1 and then calls prueth_ndev_add_rx_napi(). That
function does netif_napi_add(), hrtimer_setup() and request_irq() for
each of the rx_flow_num flows. The error unwind only undoes one of
them:

free_rx_irq:
	prueth_ndev_del_rx_napi(emac, 1);

emac_ndo_stop(), by contrast, passes PRUETH_MAX_RX_FLOWS_SR1.

Suppose request_threaded_irq(), prueth_emac_start() or a later step
fails. Don't flows 1..3 then keep their IRQ handlers registered and
their NAPI instances on ndev->napi_list?

The next open would add the same napi_rx structures again. Device
removal could also run with handlers still pointing into
emac->rx_chns.flows[]. Should the unwind use emac->rx_flow_num to match
the add?

> +		return -EOPNOTSUPP;
> +
> +	switch (info->cmd) {
> +	case ETHTOOL_GRXCLSRLCNT:
> +		info->rule_cnt = emac->rxnfc.rxnfc_rule_count;
> +		info->data = ICSSG_NUM_FT3_SLOTS | RX_CLS_LOC_SPECIAL;
> +		break;
> +	case ETHTOOL_GRXCLSRULE:
> +		ret = icssg_rxnfc_rule_get(emac, info->fs.location, &info->fs);
> +		break;
> +	case ETHTOOL_GRXCLSRLALL: {
> +		u32 rule_cnt = 0;
> +
> +		info->data = ICSSG_NUM_FT3_SLOTS | RX_CLS_LOC_SPECIAL;
> +		ret = icssg_rxnfc_rule_get_all(emac, rule_locs,
> +					       info->rule_cnt, &rule_cnt);
> +		info->rule_cnt = rule_cnt;
> +		break;
> +	}
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +
> +	return ret;
> +}
> +
> +static int emac_set_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *info)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +
> +	if (emac->is_sr1)
> +		return -EOPNOTSUPP;
> +
> +	switch (info->cmd) {
> +	case ETHTOOL_SRXCLSRLINS:
> +		return icssg_rxnfc_rule_add(emac, info);
> +	case ETHTOOL_SRXCLSRLDEL:
> +		return icssg_rxnfc_rule_del(emac, info->fs.location);
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +}
> +
>  const struct ethtool_ops icssg_ethtool_ops = {
>  	.get_drvinfo = emac_get_drvinfo,
>  	.get_msglevel = emac_get_msglevel,

[Severity: Medium]
include/uapi/linux/ethtool.h only defines RX_CLS_LOC_SPECIAL as a flag
in @data for ETHTOOL_GRXCLSRLCNT. For ETHTOOL_GRXCLSRLALL, @data on
return is just the size of the rule table.

With the flag ORed in here, ETHTOOL_GRXCLSRLALL reports a table size of
0x80000010 instead of 16. Userspace that takes @data from this command
as the table size gets a bogus value, for example when it sizes a
bitmap of rule locations from it. Other drivers that support special
locations, such as fbnic, set the flag only for ETHTOOL_GRXCLSRLCNT.

The v2 changelog says this was added to both cases deliberately. Was
there a reason for doing it in ETHTOOL_GRXCLSRLALL, or can this be
plain ICSSG_NUM_FT3_SLOTS?

[Severity: Low]
Should this check emac->is_sr1, like emac_get_rxnfc() and
emac_set_rxnfc() do?

On SR1, icssg_prueth_sr1.c sets emac->rx_flow_num to
PRUETH_MAX_RX_FLOWS_SR1 (4) because its UDMA RX channel has four flows.
However, the SR1 netdev has a single RX queue, allocated by
alloc_etherdev_mq(sizeof(*emac), 1). Only PRUETH_RX_FLOW_DATA_SR1 is
prepared and enabled for data, and emac_get_channels() reports
max_rx = 1.

ETHTOOL_GRXRINGS would then report 4 RX rings on SR1, which disagrees
with the rest of the ethtool interface. Since rxnfc isn't supported on
SR1 anyway, would returning 1 there be more accurate?

[ ... ]

> @@ -532,3 +543,430 @@ void icssg_ft3_hsr_configurations(struct regmap *miig_rt, int slice,
>  	}
>  }
>  EXPORT_SYMBOL_GPL(icssg_ft3_hsr_configurations);
> +
> +/* RX Flow Classification (ethtool) rule management */
> +
> +/* Allocate free FT3 slot, avoiding reserved slots */
> +static int allocate_ft3_slot(struct prueth_emac *emac)
> +{
> +	u16 used = emac->rxnfc.ft3_slots_used | ICSSG_FT3_RESERVED_SLOTS;
> +	int slot;
> +
> +	/* Slot 9 is implicitly used by the HSR PTP duplicate classifier's OR_EN.
> +	 * Prevent user rules from triggering it accidentally.
> +	 */
> +	if (emac->prueth->is_hsr_offload_mode)
> +		used |= BIT(FT3_HSR_OR_SLOT);
> +
> +	for (slot = 0; slot < ICSSG_NUM_FT3_SLOTS; slot++) {
> +		if (!(used & BIT(slot))) {
> +			emac->rxnfc.ft3_slots_used |= BIT(slot);
> +			return slot;
> +		}
> +	}
> +	return -ENOSPC;
> +}
> +
> +/* Free allocated FT3 slot */
> +static void free_ft3_slot(struct prueth_emac *emac, int slot)
> +{
> +	emac->rxnfc.ft3_slots_used &= ~BIT(slot);
> +}
> +
> +/* Program FT3 filter slot with ethertype pattern */
> +static void icssg_ft3_program_filter(struct regmap *miig_rt, int slice,
> +				     int slot, struct icssg_rxnfc_rule *rule)
> +{
> +	const struct ethtool_rx_flow_spec *fs = &rule->flow_spec;
> +	__be16 ether_type;
> +
> +	/* Extract EtherType from flow spec (network byte order) */
> +	ether_type = fs->h_u.ether_spec.h_proto;
> +
> +	/* Deactivate filter before programming */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0);
> +
> +	/* EtherType is at byte 12 in standard Ethernet frames */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START),
> +		     PRP_PTP_ETHERTYPE_OFFSET);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_AUTO), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_OFFSET), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_JUMP_OFFSET), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_LEN), 0);
> +
> +	/* FT3 compares a 32-bit LE word at FT3_START. EtherType occupies the
> +	 * lower 16 bits of that word. FT3_T_MASK=0xFFFF0000 masks the upper
> +	 * 16 bits (payload bytes), so only the lower 16 bits are compared.
> +	 *
> +	 * h_proto is __be16 (network byte order). On LE the raw integer value
> +	 * equals the lower 16 bits of the LE 32-bit word at the EtherType
> +	 * offset in the frame — e.g. IPv4 0x0800 BE → h_proto = 0x0008 on LE,
> +	 * which is exactly what FT3 sees in the lower 16 bits of the word at
> +	 * byte 12. No conversion needed; using be16_to_cpu() here would invert
> +	 * the byte order and break the match.
> +	 * Reference: FT3_PTP_PATTERN = 0xF788 = htons(0x88F7) = raw h_proto value.
> +	 */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T),
> +		     (__force u32)ether_type);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T_MASK), FT3_ETHERTYPE_MASK);
> +
> +	/* Enable filter: register-equal mode (same value as FT3_VLAN_MODE_BOTH) */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG),
> +		     FT3_VLAN_MODE_BOTH);
> +}
> +
> +/* Disable FT3 filter slot */
> +static void icssg_ft3_disable_filter(struct regmap *miig_rt, int slice, int slot)
> +{
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0);
> +}
> +
> +/* Update RX classifiers for all active FT3 rules.
> + * Classifier N maps to RX flow N (firmware routes classifier-N hits to

[Severity: High]
This is in the previous patch. This patch is what makes RX flows 1..N
carry traffic, so it seems worth raising here.

What keeps rx_flow_num at 1 on AM654 SR2.0? The multi-flow patch says
AM654 multi-flow support is deferred, but emac_get_channels() still
sets ch->max_rx = ICSSG_MAX_RFLOWS for every non-SR1 device, including
ti,am654-icssg-prueth.

AM654 uses UDMAP, where k3_udma_glue sets rx_chn->single_fdq and all
flows share flow 0's free descriptor ring. After ethtool -L with rx > 1
there, a few things look wrong:

- prueth_init_rx_chns() sizes the shared FDQ to PRUETH_MAX_RX_DESC, and
  each flow then pushes PRUETH_MAX_RX_DESC buffers into it, so the ring
  overflows while flow 1 is being prepared on open.

- k3_udma_glue_reset_rx_chn() skips the FDQ drain for flow_num != 0
  on a single_fdq channel. The prueth_create_rxqs() error unwind runs
  from the highest flow down, so flows[i].pg_pool for i > 0 is
  destroyed before flow 0 drains their buffers from the shared FDQ.
  prueth_rx_cleanup() then sees a NULL pg_pool for those buffers and
  the pages leak.

- prueth_destroy_rxqs() goes from flow 0 up. The shared FDQ is reset
  and flows[0].pg_pool destroyed while flows 1..N still have NAPI
  enabled and undrained completion rings.

- emac_rx_packet() syncs and recycles against rx_flow->pg_pool, but
  with a shared FDQ the buffer can come from another flow's pool, i.e.
  rx_chn->flows[swdata->flow_id].pg_pool.

- NAPIs for different flows refill the same FDQ ring concurrently with
  no serialization.

Should max_rx be capped to 1 on AM654 until the shared FDQ case is
handled?

> + * UDMA flow rx_flow_id_base + N). Build a per-classifier OR table so
> + * that each target queue gets its own classifier entry.
> + */
> +static void icssg_rxnfc_classifier_update(struct prueth_emac *emac)
> +{
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	u32 or_table[ICSSG_NUM_CLASSIFIERS] = { };
> +	struct icssg_rxnfc_rule *rule;
> +	int n;
> +
> +	if (slice < 0)
> +		return;
> +
> +	/* Build per-classifier OR table: classifier index = target queue index */
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
> +		int cls = rule->queue_index;
> +
> +		if (cls < emac->rx_flow_num)
> +			or_table[cls] |= RX_CLASS_FT_FT3_MATCH(rule->ft3_slot);
> +	}
> +
> +	/* Update OR tables for classifiers 0..rx_flow_num-1 using RMW so that
> +	 * non-FT3 bits (e.g. RX_CLASS_FT_BC | RX_CLASS_FT_DA_P set by
> +	 * icssg_class_default()) are preserved. Only the FT3-match field
> +	 * (RX_CLASS_FT_FT3_MATCH_MASK) is replaced.
> +	 *
> +	 * Classifiers 1..N start with OR_EN=0 after icssg_class_default()
> +	 * (non-SR1 sets num_classifiers=1, leaving them zeroed). Add BC|DA_P
> +	 * when they carry FT3 rules so that only host-addressed frames are
> +	 * steered — without it the classifier is a promiscuous EtherType match.
> +	 *
> +	 * Use RX_CLASS_N_REG (rx_class_base), NOT RX_CLASS_OR_REG
> +	 * (rx_class_or_base = rx_class_base + 4): the latter lands on AND_EN
> +	 * of classifier n+1 instead of OR_EN of classifier n.
> +	 */
> +	for (n = 0; n < emac->rx_flow_num; n++) {
> +		u32 val;
> +
> +		if (n == 0) {
> +			/* Classifier 0: RMW to preserve default BC|DA_P bits
> +			 * set by icssg_class_default().
> +			 */
> +			regmap_read(miig_rt,
> +				    RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), &val);
> +			val &= ~RX_CLASS_FT_FT3_MATCH_MASK;
> +			val |= or_table[n];
> +		} else if (or_table[n]) {
> +			/* Classifiers 1..N with active rules: add BC|DA_P so
> +			 * only host-addressed frames are steered.
> +			 */
> +			val = RX_CLASS_FT_BC | RX_CLASS_FT_DA_P | or_table[n];
> +		} else {
> +			/* Classifiers 1..N with no rules: clear entirely.
> +			 * Must not leave BC|DA_P here — it would steal all
> +			 * host traffic away from classifier 0.
> +			 */
> +			val = 0;
> +		}
> +		regmap_write(miig_rt, RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), val);
> +	}
> +}
> +
> +/* Validate rule parameters */
> +static int validate_rule(struct prueth_emac *emac,
> +			 struct ethtool_rx_flow_spec *fs)
> +{
> +	/* Only ETHER_FLOW supported; reject extension flags */
> +	if (fs->flow_type != ETHER_FLOW)
> +		return -EOPNOTSUPP;
> +
> +	/* Only exact EtherType match supported — reject partial proto mask,
> +	 * non-zero MAC address masks, and flow extension flags.
> +	 */
> +	if (fs->m_u.ether_spec.h_proto != htons(0xFFFF))
> +		return -EOPNOTSUPP;
> +	if (!is_zero_ether_addr(fs->m_u.ether_spec.h_dest) ||
> +	    !is_zero_ether_addr(fs->m_u.ether_spec.h_source))
> +		return -EOPNOTSUPP;
> +
> +	/* Check RX queue is valid */
> +	if (fs->ring_cookie >= emac->rx_flow_num)

[Severity: High]
This is in prueth_xsk_pool_enable() and prueth_xsk_pool_disable() from
the previous patch. A rule steering traffic to a queue is the natural
way to feed an AF_XDP socket bound to it, so this patch makes that
path more likely to be used.

When the interface is running, both functions call
icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE) and then
prueth_destroy_rxq(emac, queue_id). That pops the flow's completion
ring, calls k3_udma_glue_reset_rx_chn() for the flow and destroys
flow->pg_pool. The shared UDMA RX channel is never disabled with
k3_udma_glue_disable_rx_chn() and keeps running for the other flows.

Can the DMA engine still hold descriptors it prefetched from this
flow's FDQ at that point? If so, wouldn't the page_pool pages or XSK
buffers be released or unmapped while the hardware can still write to
them?

On single_fdq UDMAP platforms, resetting flow 0 also resets the FDQ
shared by all flows. Resetting queue_id > 0 doesn't drain the FDQ at
all.

Is there a supported way to quiesce a single flow on this hardware, or
does this need the full RX channel teardown done on the stop path?

> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
> +/* Check if identical rule already exists */
> +static bool rule_exists(struct prueth_emac *emac,
> +			struct ethtool_rx_flow_spec *fs)
> +{
> +	struct icssg_rxnfc_rule *rule;
> +
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
> +		if (rule->flow_spec.flow_type == fs->flow_type &&
> +		    rule->flow_spec.h_u.ether_spec.h_proto ==
> +		    fs->h_u.ether_spec.h_proto) {
> +			return true;
> +		}
> +	}
> +	return false;
> +}
> +
> +/* Initialize RX flow classification */
> +void icssg_rxnfc_rule_init(struct prueth_emac *emac)
> +{
> +	INIT_LIST_HEAD(&emac->rxnfc.rules);
> +	mutex_init(&emac->rxnfc.rxnfc_lock);
> +	emac->rxnfc.rxnfc_rule_count = 0;
> +	emac->rxnfc.ft3_slots_used = ICSSG_FT3_RESERVED_SLOTS; /* Mark slot 14 reserved */
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_init);
> +
> +/* Restore RX flow classification hardware state from the in-memory rule list.
> + * Call after icssg_class_default() resets the classifier registers on open or
> + * after firmware restart so that existing rules take effect again.
> + */
> +void icssg_rxnfc_rule_restore(struct prueth_emac *emac)
> +{
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule;
> +
> +	if (slice < 0)
> +		return;
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);
> +
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list)
> +		icssg_ft3_program_filter(miig_rt, slice, rule->ft3_slot, rule);
> +
> +	icssg_rxnfc_classifier_update(emac);
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_restore);
> +
> +/* Cleanup RX flow classification */
> +void icssg_rxnfc_rule_cleanup(struct prueth_emac *emac)
> +{
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule, *tmp;
> +	int n;
> +
> +	if (slice < 0)
> +		return;
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);
> +
> +	/* Disable all active FT3 filters */
> +	list_for_each_entry_safe(rule, tmp, &emac->rxnfc.rules, list) {
> +		icssg_ft3_disable_filter(miig_rt, slice, rule->ft3_slot);
> +		free_ft3_slot(emac, rule->ft3_slot);
> +		list_del(&rule->list);
> +		kfree(rule);
> +	}
> +
> +	emac->rxnfc.rxnfc_rule_count = 0;
> +	emac->rxnfc.ft3_slots_used = ICSSG_FT3_RESERVED_SLOTS;
> +
> +	/* Clear FT3 bits from classifiers 0..rx_flow_num-1. Use RMW for
> +	 * classifier 0 to preserve its BC|DA_P default-accept bits; for
> +	 * classifiers 1..N (which had BC|DA_P added by classifier_update)
> +	 * clear everything since no rules remain to steer traffic there.
> +	 */
> +	for (n = 0; n < emac->rx_flow_num; n++) {
> +		u32 val;
> +
> +		if (n == 0) {
> +			regmap_read(miig_rt,
> +				    RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), &val);
> +			val &= ~RX_CLASS_FT_FT3_MATCH_MASK;
> +		} else {
> +			val = 0;
> +		}
> +		regmap_write(miig_rt, RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), val);
> +	}
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_cleanup);
> +
> +/* Add a new RX flow classification rule */
> +int icssg_rxnfc_rule_add(struct prueth_emac *emac, struct ethtool_rxnfc *info)
> +{
> +	struct ethtool_rx_flow_spec *fs = &info->fs;
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule;
> +	int ft3_slot;
> +	int ret;
> +
> +	if (slice < 0)
> +		return -EINVAL;
> +
> +	/* Validate rule parameters */
> +	ret = validate_rule(emac, fs);
> +	if (ret)
> +		return ret;
> +
> +	/* Validate explicit location: reject special specifiers, out-of-range
> +	 * values, and the reserved slot 14 used by HSR/PRP.
> +	 * Bound against ICSSG_NUM_FT3_SLOTS (16), not ICSSG_RXNFC_MAX_RULES
> +	 * (15), so that slot 15 is reachable as an explicit location.
> +	 */
> +	if (fs->location != RX_CLS_LOC_ANY) {
> +		if (fs->location >= ICSSG_NUM_FT3_SLOTS ||
> +		    BIT(fs->location) & ICSSG_FT3_RESERVED_SLOTS ||
> +		    (emac->prueth->is_hsr_offload_mode &&
> +		     fs->location == FT3_HSR_OR_SLOT))
> +			return -EINVAL;
> +	}
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);
> +
> +	/* Check max rules */
> +	if (emac->rxnfc.rxnfc_rule_count >= ICSSG_RXNFC_MAX_RULES)
> +		return -ENOSPC;
> +
> +	/* Check for duplicate flow spec */
> +	if (rule_exists(emac, fs))
> +		return -EEXIST;
> +
> +	/* Allocate FT3 slot. For explicit locations, the location IS the FT3
> +	 * slot — this keeps location and slot aligned so rule_del operates on
> +	 * the correct hardware slot. For RX_CLS_LOC_ANY, auto-allocate the
> +	 * lowest free slot and assign it as the location.
> +	 */
> +	if (fs->location != RX_CLS_LOC_ANY) {
> +		ft3_slot = fs->location;
> +		if (emac->rxnfc.ft3_slots_used & BIT(ft3_slot))
> +			return -EBUSY;
> +		emac->rxnfc.ft3_slots_used |= BIT(ft3_slot);
> +	} else {
> +		ft3_slot = allocate_ft3_slot(emac);
> +		if (ft3_slot < 0)
> +			return -ENOSPC;
> +		fs->location = ft3_slot;
> +	}
> +
> +	/* Allocate rule structure */
> +	rule = kzalloc(sizeof(*rule), GFP_KERNEL);
> +	if (!rule) {
> +		free_ft3_slot(emac, ft3_slot);
> +		return -ENOMEM;
> +	}
> +
> +	/* Program FT3 hardware */
> +	rule->flow_spec = *fs;
> +	rule->ft3_slot = ft3_slot;
> +	rule->queue_index = fs->ring_cookie;
> +	rule->location = fs->location;
> +
> +	icssg_ft3_program_filter(miig_rt, slice, ft3_slot, rule);
> +
> +	/* Add to rule list */
> +	list_add(&rule->list, &emac->rxnfc.rules);
> +	emac->rxnfc.rxnfc_rule_count++;
> +
> +	/* Update classifier */
> +	icssg_rxnfc_classifier_update(emac);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_add);
> +
> +/* Delete a RX flow classification rule */
> +int icssg_rxnfc_rule_del(struct prueth_emac *emac, u32 location)
> +{
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule, *tmp;
> +	int ret = -ENOENT;
> +
> +	if (slice < 0)
> +		return -EINVAL;
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);
> +
> +	list_for_each_entry_safe(rule, tmp, &emac->rxnfc.rules, list) {
> +		if (rule->location == location) {
> +			icssg_ft3_disable_filter(miig_rt, slice, rule->ft3_slot);
> +			free_ft3_slot(emac, rule->ft3_slot);
> +			list_del(&rule->list);
> +			kfree(rule);
> +			emac->rxnfc.rxnfc_rule_count--;
> +			icssg_rxnfc_classifier_update(emac);
> +			ret = 0;
> +			break;
> +		}
> +	}
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_del);
> +
> +/* Get single RX flow classification rule */
> +int icssg_rxnfc_rule_get(struct prueth_emac *emac, u32 location,
> +			 struct ethtool_rx_flow_spec *fs)
> +{
> +	struct icssg_rxnfc_rule *rule;
> +	int ret = -ENOENT;
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);
> +
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
> +		if (rule->location == location) {
> +			*fs = rule->flow_spec;
> +			ret = 0;
> +			break;
> +		}
> +	}
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_get);
> +
> +/* Get all RX flow classification rules */
> +int icssg_rxnfc_rule_get_all(struct prueth_emac *emac, u32 *rule_locs,
> +			     u32 rule_locs_capacity, u32 *rule_cnt)
> +{
> +	struct icssg_rxnfc_rule *rule;
> +	u32 count = 0;
> +	int ret = 0;
> +
> +	guard(mutex)(&emac->rxnfc.rxnfc_lock);
> +
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
> +		if (!rule_locs) {
> +			/* Caller passed rule_cnt=0: just count active rules */
> +			count++;
> +			continue;
> +		}
> +		if (count >= rule_locs_capacity) {
> +			ret = -EMSGSIZE;
> +			break;
> +		}
> +		rule_locs[count++] = rule->location;
> +	}
> +
> +	*rule_cnt = count;
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_get_all);

[Severity: Medium]
When userspace issues ETHTOOL_GRXCLSRLALL with rule_cnt == 0,
ethtool_get_rxnfc() doesn't allocate rule_buf. It calls get_rxnfc()
with rule_locs == NULL.

With one or more rules installed, this branch counts them and skips the
capacity check. icssg_rxnfc_rule_get_all() then returns 0, and
emac_get_rxnfc() sets info->rule_cnt to the number of rules. The caller
is told the request succeeded with N rule locations, but none were
written. Other drivers return -EMSGSIZE once the rule count exceeds the
supplied rule_cnt, including when it is zero.

The comment describes ETHTOOL_GRXCLSRLCNT behaviour, but this helper is
only called for ETHTOOL_GRXCLSRLALL, and emac_get_rxnfc() answers the
count query itself. Can the NULL special case be dropped, so that the
capacity check also covers rule_cnt == 0?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203121447.2605779-1-m-malladi%40ti.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-04 13:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 12:14 [PATCH net-next v2 0/2] net: ti: icssg: Multi-flow RX and ethtool RX flow classification Meghana Malladi
2026-12-03 12:14 ` [PATCH net-next v2 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI Meghana Malladi
2026-12-04 12:44   ` sashiko-bot
2026-12-04 13:25   ` netdev-bot+sashiko
2026-12-03 12:14 ` [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support Meghana Malladi
2026-12-04 12:44   ` sashiko-bot
2026-12-04 13:25   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox