Skip to contentSkip to conversation

octeontx2-pf: add mqprio bandwidth offload for NIX TX schedulers

PATCH Superseded Ratheesh Kannoth 1 participant 2 messages Aug 11 – Aug 12

Subsystems (5)

v7 of 21 Superseded Latest is v21 →

lore
Share & tools
lore

Ratheesh Kannoth

author maintainer
#0 lore raw

PATCH v7 1/1 octeontx2-pf: add mqprio bandwidth offload for NIX TX schedulers

Add TC_SETUP_QDISC_MQPRIO handling to offload per-queue MDQ CIR/PIR shaping for mqprio channel mode with TC_MQPRIO_SHAPER_BW_RATE. When bandwidth offload is enabled, allocate one SMQ per non-QoS transmit queue, parent all MDQs under TL4[0], and program min/max rates by dividing each traffic class byte/s limit across its queues.

Setting up or tearing down the offload restarts the netdev via ndo_stop()/ndo_open() to rebuild the TX scheduler hierarchy. That clears carrier, tears down IRQ/NAPI and drops in-flight traffic; if ndo_open() fails the interface is left administratively down. Offload setup is rejected unless the interface is already running.

Reject incompatible configurations (HTB, PFC, XDP, SDP rep, missing CIR+PIR support) and out-of-range rates. Validate queue mappings against hw.non_qos_queues and reject per-TC rates smaller than the queue count that integer division would truncate to zero. Track offload state in mqprio_rate_limit instead of pfvf->flags to avoid races with the mbox up-handler, skip spurious teardown on tc qdisc replace, and clear all MDQ shapers before applying a new mapping so queues dropped from a TC layout do not retain stale limits. Restore cached shapers across routine netdev stop/open via otx2_mqprio_up().

---

v6 -> v7: Addressed Sashiko comments

	https://sashiko.dev/#/message/20260810034738.1786029-1-rkannoth%40marvell.com
v5 -> v6: Addressed Sashiko comments
	https://lore.kernel.org/netdev/[email protected]/
v4 -> v5: Addressed sashiko comments
	https://sashiko.dev/#/patchset/20260803042724.3380209-1-rkannoth%40marvell.com
v3 -> v4: Addressed sashiko comments
	https://lore.kernel.org/netdev/[email protected]/
v2 -> v3: Addressed sashiko comments
	https://lore.kernel.org/netdev/amnYX866mYx02cBe@rkannoth-OptiPlex-7090/T/#m67310cbec48b21c7720858ab3a1ea083a0f8dc10
v1 -> v2: Addressed sashiko comments
	https://lore.kernel.org/netdev/[email protected]/
---
 .../ethernet/marvell/octeontx2/af/rvu_nix.c   |   6 +-
 .../marvell/octeontx2/nic/otx2_common.c       | 154 +++++-
 .../marvell/octeontx2/nic/otx2_common.h       |  11 +
 .../marvell/octeontx2/nic/otx2_dcbnl.c        |   6 +
 .../marvell/octeontx2/nic/otx2_ethtool.c      |   8 +
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |  11 +
 .../ethernet/marvell/octeontx2/nic/otx2_tc.c  | 454 ++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/qos.c  |  15 +
 .../net/ethernet/marvell/octeontx2/nic/qos.h  |   1 +
 9 files changed, 664 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +5 -1
index b81c47ea023b..22f64c1ede91 100644
@@ -331,8 +331,12 @@ static bool is_valid_txschq(struct rvu *rvu, int blkaddr,
 			return true;
 	}
 
-	if (map_func != pcifunc)
+	if (map_func != pcifunc) {
+		dev_err_ratelimited(rvu->dev,
+				    "pcifunc %x map pcifunc %x not equal, lvl=%u schq=%u\n",
+				    pcifunc, map_func, lvl, schq);
 		return false;
+	}
 
 	return true;
 }
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +153 -1

172 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +11 -0
index eecee612b7b2..cf1cd391bf52 100644
@@ -515,6 +515,12 @@ struct otx2_nic {
 	u64			flags;
 	u64			*cq_op_addr;
 
+	u32			mqprio_flags;
+	u64			*mqprio_min_rate;
+	u64			*mqprio_max_rate;
+	bool			mqprio_rate_limit;
+	bool			mqprio_skip_teardown;
+
 	struct bpf_prog		*xdp_prog;
 	struct otx2_qset	qset;
 	struct otx2_hw		hw;
@@ -1246,6 +1252,11 @@ dma_addr_t otx2_dma_map_skb_frag(struct otx2_nic *pfvf,
 				 struct sk_buff *skb, int seg, int *len);
 void otx2_dma_unmap_skb_frags(struct otx2_nic *pfvf, struct sg_list *sg);
 int otx2_read_free_sqe(struct otx2_nic *pfvf, u16 qidx);
+int otx2_nix_tm_set_queue_shaper(struct otx2_nic *pfvf, int txq,
+				 u64 minrate, u64 maxrate);
+int otx2_nix_tm_clear_queue_shaper(struct otx2_nic *pfvf);
+int otx2_mqprio_down(struct otx2_nic *pfvf);
+int otx2_mqprio_up(struct otx2_nic *pfvf);
 void otx2_queue_vf_work(struct mbox *mw, struct workqueue_struct *mbox_wq,
 			int first, int mdevs, u64 intr);
 int otx2_del_mcam_flow_entry(struct otx2_nic *nic, u16 entry,
drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c +6 -0
index f110dfa42360..832f05cf129e 100644
@@ -413,6 +413,12 @@ static int otx2_dcbnl_ieee_setpfc(struct net_device *dev, struct ieee_pfc *pfc)
 	u8 old_pfc_en;
 	int err;
 
+	if (pfvf->mqprio_rate_limit && pfc->pfc_en) {
+		netdev_err(dev,
+			   "PFC: cannot enable while mqprio bandwidth offload is active\n");
+		return -EOPNOTSUPP;
+	}
+
 	old_pfc_en = pfvf->pfc_en;
 	pfvf->pfc_en = pfc->pfc_en;
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +8 -0
index a0340f3422bf..c1317fbcd848 100644
@@ -287,6 +287,14 @@ static int otx2_set_channels(struct net_device *dev,
 		return -EINVAL;
 	}
 
+	if (pfvf->mqprio_rate_limit &&
+	    (channel->tx_count != pfvf->hw.tx_queues ||
+	     channel->rx_count != pfvf->hw.rx_queues)) {
+		netdev_info(dev,
+			    "Not permitted to change channel count while MQ prio is active\n");
+		return -EINVAL;
+	}
+
 	if (if_up)
 		dev->netdev_ops->ndo_stop(dev);
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +11 -0
index c995f2900859..70c95e9c5bf8 100644
@@ -1980,6 +1980,10 @@ int otx2_open(struct net_device *netdev)
 	if (err)
 		goto err_free_mem;
 
+	err = otx2_mqprio_up(pf);
+	if (err)
+		goto err_free_hw;
+
 	/* Register NAPI handler */
 	for (qidx = 0; qidx < pf->hw.cint_cnt; qidx++) {
 		cq_poll = &qset->napi[qidx];
@@ -2140,6 +2144,7 @@ int otx2_open(struct net_device *netdev)
 	free_irq(vec, pf);
 err_disable_napi:
 	otx2_disable_napi(pf);
+err_free_hw:
 	otx2_free_hw_resources(pf);
 err_free_mem:
 	otx2_free_queue_mem(qset);
@@ -2846,6 +2851,12 @@ static int otx2_xdp_setup(struct otx2_nic *pf, struct bpf_prog *prog)
 	bool if_up = netif_running(pf->netdev);
 	struct bpf_prog *old_prog;
 
+	if (prog && pf->mqprio_rate_limit) {
+		netdev_err(dev,
+			   "XDP: cannot attach while mqprio bandwidth offload is active\n");
+		return -EOPNOTSUPP;
+	}
+
 	if (prog && dev->mtu > MAX_XDP_MTU) {
 		netdev_warn(dev, "Jumbo frames not yet supported with XDP\n");
 		return -EOPNOTSUPP;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +454 -0

486 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/qos.c +15 -0
index 69c0911e28e9..f7693f02a07c 100644
@@ -118,6 +118,9 @@ static void otx2_config_sched_shaping(struct otx2_nic *pfvf,
 	/* configure PIR */
 	maxrate = (node->rate > node->ceil) ? node->rate : node->ceil;
 
+	/* 65536 is the kernel-side default burst when HTB does not supply an
+	 * explicit value, not the NIX hardware maximum (CN10K_MAX_BURST_SIZE).
+	 */
 	cfg->regval[*num_regs] =
 		otx2_get_txschq_rate_regval(pfvf, maxrate, 65536);
 	(*num_regs)++;
@@ -1729,11 +1732,23 @@ void otx2_qos_config_txschq(struct otx2_nic *pfvf)
 	otx2_qos_root_destroy(pfvf);
 }
 
+bool otx2_qos_htb_active(struct otx2_nic *pfvf)
+{
+	return otx2_sw_node_find(pfvf, OTX2_QOS_ROOT_CLASSID);
+}
+
 int otx2_setup_tc_htb(struct net_device *ndev, struct tc_htb_qopt_offload *htb)
 {
 	struct otx2_nic *pfvf = netdev_priv(ndev);
 	int res;
 
+	if (pfvf->mqprio_rate_limit &&
+	    htb->command != TC_HTB_DESTROY) {
+		NL_SET_ERR_MSG_MOD(htb->extack,
+				   "HTB offload cannot be used with mqprio bandwidth offload active");
+		return -EOPNOTSUPP;
+	}
+
 	switch (htb->command) {
 	case TC_HTB_CREATE:
 		return otx2_qos_root_add(pfvf, htb->parent_classid,
drivers/net/ethernet/marvell/octeontx2/nic/qos.h +1 -0
index 221bd0438f60..c777cc42eac9 100644
@@ -23,6 +23,7 @@ enum qos_smq_operations {
 u64 otx2_get_txschq_rate_regval(struct otx2_nic *nic, u64 maxrate, u32 burst);
 
 int otx2_setup_tc_htb(struct net_device *ndev, struct tc_htb_qopt_offload *htb);
+bool otx2_qos_htb_active(struct otx2_nic *pfvf);
 int otx2_qos_get_qid(struct otx2_nic *pfvf);
 void otx2_qos_free_qid(struct otx2_nic *pfvf, int qidx);
 int otx2_qos_enable_sq(struct otx2_nic *pfvf, int qidx);
Signature · 1 line
2.43.0
author maintainer
#1 lore raw
Quoted 12 lines · Ratheesh Kannoth

Add TC_SETUP_QDISC_MQPRIO handling to offload per-queue MDQ CIR/PIR shaping for mqprio channel mode with TC_MQPRIO_SHAPER_BW_RATE. When bandwidth offload is enabled, allocate one SMQ per non-QoS transmit queue, parent all MDQs under TL4[0], and program min/max rates by dividing each traffic class byte/s limit across its queues.

Setting up or tearing down the offload restarts the netdev via ndo_stop()/ndo_open() to rebuild the TX scheduler hierarchy. That clears carrier, tears down IRQ/NAPI and drops in-flight traffic; if ndo_open() fails the interface is left administratively down. Offload setup is rejected unless the interface is already running.

Quoted 9 lines

Reject incompatible configurations (HTB, PFC, XDP, SDP rep, missing CIR+PIR support) and out-of-range rates. Validate queue mappings against hw.non_qos_queues and reject per-TC rates smaller than the queue count that integer division would truncate to zero. Track offload state in mqprio_rate_limit instead of pfvf->flags to avoid races with the mbox up-handler, skip spurious teardown on tc qdisc replace, and clear all MDQ shapers before applying a new mapping so queues dropped from a TC layout do not retain stale limits. Restore cached shapers across routine netdev stop/open via otx2_mqprio_up().

Will address sashiko issues in v8

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260811085050.3212280-1-rkannoth%40marvell.com

pw-bot: changes-requested