From: Zaiyu Wang <zaiyuwang@trustnetic.com>
To: dev@dpdk.org
Cc: Zaiyu Wang <zaiyuwang@trustnetic.com>,
Jiawen Wu <jiawenwu@trustnetic.com>,
Jian Wang <jianwang@trustnetic.com>
Subject: [PATCH v4 16/20] net/txgbe: add support for TX queue rate limiting
Date: Tue, 30 Sep 2025 17:59:48 +0800 [thread overview]
Message-ID: <20250930095953.18508-17-zaiyuwang@trustnetic.com> (raw)
In-Reply-To: <20250930095953.18508-1-zaiyuwang@trustnetic.com>
Add TX queue rate limiting functionality for Amber-Lite NICs.
Due to hardware design differences, the TX queue rate limiting
configuration for Amber-Lite NICs requires updates compared to
Sapphire NICs.
Signed-off-by: Zaiyu Wang <zaiyuwang@trustnetic.com>
---
drivers/net/txgbe/base/txgbe_osdep.h | 2 +
drivers/net/txgbe/base/txgbe_regs.h | 12 +++++
drivers/net/txgbe/txgbe_ethdev.c | 69 +++++++++++++++++++++++-----
3 files changed, 72 insertions(+), 11 deletions(-)
diff --git a/drivers/net/txgbe/base/txgbe_osdep.h b/drivers/net/txgbe/base/txgbe_osdep.h
index a1477653e2..f4282b3241 100644
--- a/drivers/net/txgbe/base/txgbe_osdep.h
+++ b/drivers/net/txgbe/base/txgbe_osdep.h
@@ -164,6 +164,8 @@ static inline u64 REVERT_BIT_MASK64(u64 mask)
#define IOMEM
+#define BIT(nr) (1UL << (nr))
+
#define prefetch(x) rte_prefetch0(x)
#define ARRAY_SIZE(x) ((int32_t)RTE_DIM(x))
diff --git a/drivers/net/txgbe/base/txgbe_regs.h b/drivers/net/txgbe/base/txgbe_regs.h
index 2e0ac9c742..f2e4994863 100644
--- a/drivers/net/txgbe/base/txgbe_regs.h
+++ b/drivers/net/txgbe/base/txgbe_regs.h
@@ -1656,6 +1656,18 @@ enum txgbe_5tuple_protocol {
#define TXGBE_ARBTXRATE_MIN(v) LS(v, 0, 0x3FFF)
#define TXGBE_ARBTXRATE_MAX(v) LS(v, 16, 0x3FFF)
+#define TXGBE_TDM_RL_QUEUE_IDX 0x018210
+#define TXGBE_TDM_RL_QUEUE_CFG 0x018214
+#define TXGBE_TDM_FACTOR_INT_MASK MS(16, 0xFFFF)
+#define TXGBE_TDM_FACTOR_FRA_MASK MS(0, 0xFFFC)
+#define TXGBE_TDM_FACTOR_INT_SHIFT 16
+#define TXGBE_TDM_FACTOR_FRA_SHIFT 2
+
+#define TXGBE_TDM_RL_VM_IDX 0x018218
+#define TXGBE_TDM_RL_VM_CFG 0x01821C
+#define TXGBE_TDM_RL_CFG 0x018400
+#define TXGBE_TDM_RL_EN MS(0, 0x1)
+
/* qos */
#define TXGBE_ARBTXCTL 0x018200
#define TXGBE_ARBTXCTL_RRM MS(1, 0x1)
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index e6694f7fc2..c7c3668066 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -4245,33 +4245,80 @@ txgbe_configure_msix(struct rte_eth_dev *dev)
| TXGBE_ITR_WRDSA);
}
+static u16 txgbe_frac_to_bi(u16 frac, u16 denom, int max_bits)
+{
+ u16 value = 0;
+
+ while (frac > 0 && max_bits > 0) {
+ max_bits -= 1;
+ frac *= 2;
+ if (frac >= denom) {
+ value |= BIT(max_bits);
+ frac -= denom;
+ }
+ }
+
+ return value;
+}
+
int
txgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
uint16_t queue_idx, uint32_t tx_rate)
{
struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
uint32_t bcnrc_val;
+ int factor_int, factor_fra;
+ uint32_t link_speed;
if (queue_idx >= hw->mac.max_tx_queues)
return -EINVAL;
- if (tx_rate != 0) {
- bcnrc_val = TXGBE_ARBTXRATE_MAX(tx_rate);
- bcnrc_val |= TXGBE_ARBTXRATE_MIN(tx_rate / 2);
- } else {
- bcnrc_val = 0;
- }
-
/*
* Set global transmit compensation time to the MMW_SIZE in ARBTXMMW
* register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
*/
wr32(hw, TXGBE_ARBTXMMW, 0x14);
- /* Set ARBTXRATE of queue X */
- wr32(hw, TXGBE_ARBPOOLIDX, queue_idx);
- wr32(hw, TXGBE_ARBTXRATE, bcnrc_val);
- txgbe_flush(hw);
+ if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40) {
+ if (tx_rate) {
+ u16 frac;
+
+ link_speed = dev->data->dev_link.link_speed;
+ tx_rate = tx_rate * 105 / 100;
+ /* Calculate the rate factor values to set */
+ factor_int = link_speed / tx_rate;
+ frac = (link_speed % tx_rate) * 10000 / tx_rate;
+ factor_fra = txgbe_frac_to_bi(frac, 10000, 14);
+ if (tx_rate > link_speed) {
+ factor_int = 1;
+ factor_fra = 0;
+ }
+
+ wr32(hw, TXGBE_TDM_RL_QUEUE_IDX, queue_idx);
+ wr32m(hw, TXGBE_TDM_RL_QUEUE_CFG,
+ TXGBE_TDM_FACTOR_INT_MASK, factor_int << TXGBE_TDM_FACTOR_INT_SHIFT);
+ wr32m(hw, TXGBE_TDM_RL_QUEUE_CFG,
+ TXGBE_TDM_FACTOR_FRA_MASK, factor_fra << TXGBE_TDM_FACTOR_FRA_SHIFT);
+ wr32m(hw, TXGBE_TDM_RL_QUEUE_CFG,
+ TXGBE_TDM_RL_EN, TXGBE_TDM_RL_EN);
+ } else {
+ wr32(hw, TXGBE_TDM_RL_QUEUE_IDX, queue_idx);
+ wr32m(hw, TXGBE_TDM_RL_QUEUE_CFG,
+ TXGBE_TDM_RL_EN, 0);
+ }
+ } else {
+ if (tx_rate != 0) {
+ bcnrc_val = TXGBE_ARBTXRATE_MAX(tx_rate);
+ bcnrc_val |= TXGBE_ARBTXRATE_MIN(tx_rate / 2);
+ } else {
+ bcnrc_val = 0;
+ }
+
+ /* Set ARBTXRATE of queue X */
+ wr32(hw, TXGBE_ARBPOOLIDX, queue_idx);
+ wr32(hw, TXGBE_ARBTXRATE, bcnrc_val);
+ txgbe_flush(hw);
+ }
return 0;
}
--
2.21.0.windows.1
next prev parent reply other threads:[~2025-09-30 10:02 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 9:41 [PATCH 0/2] *** Wangxun new NIC support *** Zaiyu Wang
2025-04-18 9:41 ` [PATCH 1/2] net/txgbe: add support for Wangxun new NIC Amber-Lite 25g/40g Zaiyu Wang
2025-04-18 9:41 ` [PATCH 2/2] net/txgbe: add basic code for Amber-Liter NIC configuration Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 00/15] Wangxun new NIC support Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 01/15] net/txgbe: add basic information for Amber-Lite 25G/40G NICs Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 02/15] net/txgbe: add new SW-FW mailbox interface Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 03/15] net/txgbe: add identification support for new SFP/QSFP modules Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 04/15] net/txgbe: add basic link configuration for Amber-Lite NICs Zaiyu Wang
2025-08-04 6:34 ` Jiawen Wu
2025-06-25 12:50 ` [PATCH v2 05/15] net/txgbe: add support for PHY configuration via SW-FW mailbox Zaiyu Wang
2025-08-04 6:51 ` Jiawen Wu
2025-06-25 12:50 ` [PATCH v2 06/15] net/txgbe: add RX&TX support for Amber-Lite NICs Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 07/15] net/txgbe: add hardware reset change " Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 08/15] net/txgbe: add MAC reconfiguration to avoid packet loss Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 09/15] net/txgbe: add TX head Write-Back mode for Amber-Lite NICs Zaiyu Wang
2025-08-04 7:15 ` Jiawen Wu
2025-06-25 12:50 ` [PATCH v2 10/15] net/txgbe: add RX desc merge " Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 11/15] net/txgbe: add FEC support for Amber-Lite 25G NICs Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 12/15] net/txgbe: add GPIO configuration Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 13/15] net/txgbe: disable unstable features Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 14/15] net/txgbe: add other hardware-related changes Zaiyu Wang
2025-06-25 12:50 ` [PATCH v2 15/15] doc: update for txgbe Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 00/15] Wangxun new NIC support Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 01/15] net/txgbe: add basic information for Amber-Lite 25G/40G NICs Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 02/15] net/txgbe: add new SW-FW mailbox interface Zaiyu Wang
2025-08-04 6:12 ` Jiawen Wu
2025-06-26 8:02 ` [PATCH v3 03/15] net/txgbe: add identification support for new SFP/QSFP modules Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 04/15] net/txgbe: add basic link configuration for Amber-Lite NICs Zaiyu Wang
2025-08-03 16:42 ` Stephen Hemminger
2025-06-26 8:02 ` [PATCH v3 05/15] net/txgbe: add support for PHY configuration via SW-FW mailbox Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 06/15] net/txgbe: add RX&TX support for Amber-Lite NICs Zaiyu Wang
2025-08-04 7:07 ` Jiawen Wu
2025-06-26 8:02 ` [PATCH v3 07/15] net/txgbe: add hardware reset change " Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 08/15] net/txgbe: add MAC reconfiguration to avoid packet loss Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 09/15] net/txgbe: add TX head Write-Back mode for Amber-Lite NICs Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 10/15] net/txgbe: add RX desc merge " Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 11/15] net/txgbe: add FEC support for Amber-Lite 25G NICs Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 12/15] net/txgbe: add GPIO configuration Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 13/15] net/txgbe: disable unstable features Zaiyu Wang
2025-06-26 8:02 ` [PATCH v3 14/15] net/txgbe: add other hardware-related changes Zaiyu Wang
2025-08-04 7:23 ` Jiawen Wu
2025-06-26 8:02 ` [PATCH v3 15/15] doc: update for txgbe Zaiyu Wang
2025-06-30 19:40 ` [PATCH v3 00/15] Wangxun new NIC support Stephen Hemminger
2025-09-30 9:59 ` [PATCH v4 00/20] " Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 01/20] net/txgbe: add basic information for Amber-Lite 25G/40G NICs Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 02/20] net/txgbe: add new SW-FW mailbox interface Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 03/20] net/txgbe: add identification support for new SFP/QSFP modules Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 04/20] net/txgbe: rename raptor to sp for Sapphire-specific code Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 05/20] net/txgbe: add basic link configuration for Amber-Lite NICs Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 06/20] net/txgbe: add support for PHY configuration via SW-FW mailbox Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 07/20] net/txgbe: add RX&TX support for Amber-Lite NICs Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 08/20] net/txgbe: add hardware reset change " Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 09/20] net/txgbe: add MAC reconfiguration to avoid packet loss Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 10/20] net/txgbe: add TX head Write-Back mode for Amber-Lite NICs Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 11/20] net/txgbe: add RX desc merge " Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 12/20] net/txgbe: add FEC support for Amber-Lite 25G NICs Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 13/20] net/txgbe: add GPIO configuration Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 14/20] net/txgbe: disable unstable features Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 15/20] net/txgbe: add support for TX laser enable/disable Zaiyu Wang
2025-09-30 9:59 ` Zaiyu Wang [this message]
2025-09-30 9:59 ` [PATCH v4 17/20] net/txgbe: add support for getting PHY ID Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 18/20] net/txgbe: add thermal sensor configuration for Amber-Lite NICs Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 19/20] net/txgbe: add RSS " Zaiyu Wang
2025-09-30 9:59 ` [PATCH v4 20/20] doc: update for txgbe Zaiyu Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250930095953.18508-17-zaiyuwang@trustnetic.com \
--to=zaiyuwang@trustnetic.com \
--cc=dev@dpdk.org \
--cc=jianwang@trustnetic.com \
--cc=jiawenwu@trustnetic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).