From: Maxime Chevallier <maxime.chevallier@bootlin.com> Date: 2021-11-26 11:23:05
Hello everyone,
This is the second version of the series that adds some improvements to the
existing mqprio implementation in mvneta, and adds support for
egress shaping offload.
The first 3 patches are some minor cleanups, such as using the
tc_mqprio_qopt_offload structure to get access to more offloading
options, cleaning the logic to detect whether or not we should offload
mqprio setting, and allowing to have a 1 to N mapping between TCs and
queues.
The last patch adds traffic shaping offload, using mvneta's per-queue
token buckets, allowing to limit rates from 10Kbps up to 5Gbps with
10Kbps increments.
This was tested only on an Armada 3720, with traffic up to 2.5Gbps.
Changes since V1 fixes the build for 32bits kernels, using the right
div helpers as suggested by Jakub.
Maxime Chevallier (4):
net: mvneta: Use struct tc_mqprio_qopt_offload for MQPrio
configuration
net: mvneta: Don't force-set the offloading flag
net: mvneta: Allow having more than one queue per TC
net: mvneta: Add TC traffic shaping offload
drivers/net/ethernet/marvell/mvneta.c | 160 +++++++++++++++++++++++---
1 file changed, 144 insertions(+), 16 deletions(-)
--
2.25.4
From: Maxime Chevallier <maxime.chevallier@bootlin.com> Date: 2021-11-26 11:23:07
The struct tc_mqprio_qopt_offload is a container for struct tc_mqprio_qopt,
that allows passing extra parameters, such as traffic shaping. This commit
converts the current mqprio code to that new struct.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
V2 : No changes
drivers/net/ethernet/marvell/mvneta.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
From: Maxime Chevallier <maxime.chevallier@bootlin.com> Date: 2021-11-26 11:23:09
The current mqprio implementation assumed that we are only using one
queue per TC. Use the offset and count parameters to allow using
multiple queues per TC. In that case, the controller will use a standard
round-robin algorithm to pick queues assigned to the same TC, with the
same priority.
This only applies to VLAN priorities in ingress traffic, each TC
corresponding to a vlan priority.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
V2 : No changes
drivers/net/ethernet/marvell/mvneta.c | 35 +++++++++++++++------------
1 file changed, 20 insertions(+), 15 deletions(-)
From: Maxime Chevallier <maxime.chevallier@bootlin.com> Date: 2021-11-26 11:23:12
The qopt->hw flag is set by the TC code according to the offloading mode
asked by user. Don't force-set it in the driver, but instead read it to
make sure we do what's asked.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
V2 : No changes
drivers/net/ethernet/marvell/mvneta.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
From: Maxime Chevallier <maxime.chevallier@bootlin.com> Date: 2021-11-26 11:23:13
The mvneta controller is able to do some tocken-bucket per-queue traffic
shaping. This commit adds support for setting these using the TC mqprio
interface.
The token-bucket parameters are customisable, but the current
implementation configures them to have a 10kbps resolution for the
rate limitation, since it allows to cover the whole range of max_rate
values from 10kbps to 5Gbps with 10kbps increments.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
V2 : Use div_u64_rem for u64 division, as suggested by Jakub. It also
allowed to simplify the code a little bit.
drivers/net/ethernet/marvell/mvneta.c | 120 +++++++++++++++++++++++++-
1 file changed, 119 insertions(+), 1 deletion(-)
@@ -248,12 +248,39 @@#define MVNETA_TXQ_SENT_DESC_MASK 0x3fff0000#define MVNETA_PORT_TX_RESET 0x3cf0#define MVNETA_PORT_TX_DMA_RESET BIT(0)+#define MVNETA_TXQ_CMD1_REG 0x3e00+#define MVNETA_TXQ_CMD1_BW_LIM_SEL_V1 BIT(3)+#define MVNETA_TXQ_CMD1_BW_LIM_EN BIT(0)+#define MVNETA_REFILL_NUM_CLK_REG 0x3e08+#define MVNETA_REFILL_MAX_NUM_CLK 0x0000ffff#define MVNETA_TX_MTU 0x3e0c#define MVNETA_TX_TOKEN_SIZE 0x3e14#define MVNETA_TX_TOKEN_SIZE_MAX 0xffffffff+#define MVNETA_TXQ_BUCKET_REFILL_REG(q) (0x3e20 + ((q) << 2))+#define MVNETA_TXQ_BUCKET_REFILL_PERIOD_MASK 0x3ff00000+#define MVNETA_TXQ_BUCKET_REFILL_PERIOD_SHIFT 20+#define MVNETA_TXQ_BUCKET_REFILL_VALUE_MAX 0x0007ffff#define MVNETA_TXQ_TOKEN_SIZE_REG(q) (0x3e40 + ((q) << 2))#define MVNETA_TXQ_TOKEN_SIZE_MAX 0x7fffffff+/* The values of the bucket refill base period and refill period are taken from+*thereferencemanual,andaddsuptoabaseresolutionof10Kbps.Thisallows+*tocoverallrate-limitvaluesfrom10Kbpsupto5Gbps+*/++/* Base period for the rate limit algorithm */+#define MVNETA_TXQ_BUCKET_REFILL_BASE_PERIOD_NS 100++/* Number of Base Period to wait between each bucket refill */+#define MVNETA_TXQ_BUCKET_REFILL_PERIOD 1000++/* The base resolution for rate limiting, in bps. Any max_rate value should be+*amultipleofthatvalue.+*/+#define MVNETA_TXQ_RATE_LIMIT_RESOLUTION (NSEC_PER_SEC / \+(MVNETA_TXQ_BUCKET_REFILL_BASE_PERIOD_NS*\+MVNETA_TXQ_BUCKET_REFILL_PERIOD))+#define MVNETA_LPI_CTRL_0 0x2cc0#define MVNETA_LPI_CTRL_1 0x2cc4#define MVNETA_LPI_REQUEST_ENABLE BIT(0)
@@ -4906,11 +4933,74 @@ static void mvneta_map_vlan_prio_to_rxq(struct mvneta_port *pp, u8 pri, u8 rxq)mvreg_write(pp,MVNETA_VLAN_PRIO_TO_RXQ,val);}+staticintmvneta_enable_per_queue_rate_limit(structmvneta_port*pp)+{+unsignedlongcore_clk_rate;+u32refill_cycles;+u32val;++core_clk_rate=clk_get_rate(pp->clk);+if(!core_clk_rate)+return-EINVAL;++refill_cycles=MVNETA_TXQ_BUCKET_REFILL_BASE_PERIOD_NS/+(NSEC_PER_SEC/core_clk_rate);++if(refill_cycles>MVNETA_REFILL_MAX_NUM_CLK)+return-EINVAL;++/* Enable bw limit algorithm version 3 */+val=mvreg_read(pp,MVNETA_TXQ_CMD1_REG);+val&=~(MVNETA_TXQ_CMD1_BW_LIM_SEL_V1|MVNETA_TXQ_CMD1_BW_LIM_EN);+mvreg_write(pp,MVNETA_TXQ_CMD1_REG,val);++/* Set the base refill rate */+mvreg_write(pp,MVNETA_REFILL_NUM_CLK_REG,refill_cycles);++return0;+}++staticvoidmvneta_disable_per_queue_rate_limit(structmvneta_port*pp)+{+u32val=mvreg_read(pp,MVNETA_TXQ_CMD1_REG);++val|=(MVNETA_TXQ_CMD1_BW_LIM_SEL_V1|MVNETA_TXQ_CMD1_BW_LIM_EN);+mvreg_write(pp,MVNETA_TXQ_CMD1_REG,val);+}++staticintmvneta_setup_queue_rates(structmvneta_port*pp,intqueue,+u64min_rate,u64max_rate)+{+u32refill_val,rem;+u32val=0;++/* Convert to from Bps to bps */+max_rate*=8;++if(min_rate)+return-EINVAL;++refill_val=div_u64_rem(max_rate,MVNETA_TXQ_RATE_LIMIT_RESOLUTION,+&rem);++if(rem||!refill_val||+refill_val>MVNETA_TXQ_BUCKET_REFILL_VALUE_MAX)+return-EINVAL;++val=refill_val;+val|=(MVNETA_TXQ_BUCKET_REFILL_PERIOD<<+MVNETA_TXQ_BUCKET_REFILL_PERIOD_SHIFT);++mvreg_write(pp,MVNETA_TXQ_BUCKET_REFILL_REG(queue),val);++return0;+}+staticintmvneta_setup_mqprio(structnet_device*dev,structtc_mqprio_qopt_offload*mqprio){structmvneta_port*pp=netdev_priv(dev);-intrxq,tc;+intrxq,txq,tc,ret;u8num_tc;if(mqprio->qopt.hw!=TC_MQPRIO_HW_OFFLOAD_TCS)
@@ -4924,6 +5014,7 @@ static int mvneta_setup_mqprio(struct net_device *dev,mvneta_clear_rx_prio_map(pp);if(!num_tc){+mvneta_disable_per_queue_rate_limit(pp);netdev_reset_tc(dev);return0;}
@@ -4944,6 +5035,33 @@ static int mvneta_setup_mqprio(struct net_device *dev,}}+if(mqprio->shaper!=TC_MQPRIO_SHAPER_BW_RATE){+mvneta_disable_per_queue_rate_limit(pp);+return0;+}++if(mqprio->qopt.num_tc>txq_number)+return-EINVAL;++ret=mvneta_enable_per_queue_rate_limit(pp);+if(ret)+returnret;++for(tc=0;tc<mqprio->qopt.num_tc;tc++){+for(txq=mqprio->qopt.offset[tc];+txq<mqprio->qopt.count[tc]+mqprio->qopt.offset[tc];+txq++){+if(txq>=txq_number)+return-EINVAL;++ret=mvneta_setup_queue_rates(pp,txq,+mqprio->min_rate[tc],+mqprio->max_rate[tc]);+if(ret)+returnret;+}+}+return0;}
Hello:
This series was applied to netdev/net-next.git (master)
by David S. Miller [off-list ref]:
On Fri, 26 Nov 2021 12:20:52 +0100 you wrote:
Hello everyone,
This is the second version of the series that adds some improvements to the
existing mqprio implementation in mvneta, and adds support for
egress shaping offload.
The first 3 patches are some minor cleanups, such as using the
tc_mqprio_qopt_offload structure to get access to more offloading
options, cleaning the logic to detect whether or not we should offload
mqprio setting, and allowing to have a 1 to N mapping between TCs and
queues.
[...]