2023-06-07 09:26:01

by Wei Fang

[permalink] [raw]
Subject: [PATCH V2 net] net: enetc: correct the indexes of highest and 2nd highest TCs

From: Wei Fang <[email protected]>

For ENETC hardware, the TCs are numbered from 0 to N-1, where N
is the number of TCs. Numerically higher TC has higher priority.
It's obvious that the highest priority TC index should be N-1 and
the 2nd highest priority TC index should be N-2.

However, the previous logic uses netdev_get_prio_tc_map() to get
the indexes of highest priority and 2nd highest priority TCs, it
does not make sense and is incorrect to give a "tc" argument to
netdev_get_prio_tc_map(). So the driver may get the wrong indexes
of the two highest priotiry TCs which would lead to failed to set
the CBS for the two highest priotiry TCs.

e.g.
$ tc qdisc add dev eno0 parent root handle 100: mqprio num_tc 6 \
map 0 0 1 1 2 3 4 5 queues 1@0 1@1 1@2 1@3 2@4 2@6 hw 1
$ tc qdisc replace dev eno0 parent 100:6 cbs idleslope 100000 \
sendslope -900000 hicredit 12 locredit -113 offload 1
$ Error: Specified device failed to setup cbs hardware offload.
^^^^^

In this example, the previous logic deems the indexes of the two
highest priotiry TCs should be 3 and 2. Actually, the indexes are
5 and 4, because the number of TCs is 6. So it would be failed to
configure the CBS for the two highest priority TCs.

Fixes: c431047c4efe ("enetc: add support Credit Based Shaper(CBS) for hardware offload")
Signed-off-by: Wei Fang <[email protected]>
Reviewed-by: Vladimir Oltean <[email protected]>
---
V2:
Improved the commit message based on Maciej's comments.
---
drivers/net/ethernet/freescale/enetc/enetc_qos.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_qos.c b/drivers/net/ethernet/freescale/enetc/enetc_qos.c
index 83c27bbbc6ed..126007ab70f6 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_qos.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_qos.c
@@ -181,8 +181,8 @@ int enetc_setup_tc_cbs(struct net_device *ndev, void *type_data)
int bw_sum = 0;
u8 bw;

- prio_top = netdev_get_prio_tc_map(ndev, tc_nums - 1);
- prio_next = netdev_get_prio_tc_map(ndev, tc_nums - 2);
+ prio_top = tc_nums - 1;
+ prio_next = tc_nums - 2;

/* Support highest prio and second prio tc in cbs mode */
if (tc != prio_top && tc != prio_next)
--
2.25.1



2023-06-07 11:33:48

by Maciej Fijalkowski

[permalink] [raw]
Subject: Re: [PATCH V2 net] net: enetc: correct the indexes of highest and 2nd highest TCs

On Wed, Jun 07, 2023 at 05:10:48PM +0800, [email protected] wrote:
> From: Wei Fang <[email protected]>
>
> For ENETC hardware, the TCs are numbered from 0 to N-1, where N
> is the number of TCs. Numerically higher TC has higher priority.
> It's obvious that the highest priority TC index should be N-1 and
> the 2nd highest priority TC index should be N-2.
>
> However, the previous logic uses netdev_get_prio_tc_map() to get
> the indexes of highest priority and 2nd highest priority TCs, it
> does not make sense and is incorrect to give a "tc" argument to
> netdev_get_prio_tc_map(). So the driver may get the wrong indexes
> of the two highest priotiry TCs which would lead to failed to set
> the CBS for the two highest priotiry TCs.
>
> e.g.
> $ tc qdisc add dev eno0 parent root handle 100: mqprio num_tc 6 \
> map 0 0 1 1 2 3 4 5 queues 1@0 1@1 1@2 1@3 2@4 2@6 hw 1
> $ tc qdisc replace dev eno0 parent 100:6 cbs idleslope 100000 \
> sendslope -900000 hicredit 12 locredit -113 offload 1
> $ Error: Specified device failed to setup cbs hardware offload.
> ^^^^^
>
> In this example, the previous logic deems the indexes of the two
> highest priotiry TCs should be 3 and 2. Actually, the indexes are
> 5 and 4, because the number of TCs is 6. So it would be failed to
> configure the CBS for the two highest priority TCs.
>
> Fixes: c431047c4efe ("enetc: add support Credit Based Shaper(CBS) for hardware offload")
> Signed-off-by: Wei Fang <[email protected]>
> Reviewed-by: Vladimir Oltean <[email protected]>

Reviewed-by: Maciej Fijalkowski <[email protected]>

Thanks!

> ---
> V2:
> Improved the commit message based on Maciej's comments.
> ---
> drivers/net/ethernet/freescale/enetc/enetc_qos.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_qos.c b/drivers/net/ethernet/freescale/enetc/enetc_qos.c
> index 83c27bbbc6ed..126007ab70f6 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_qos.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_qos.c
> @@ -181,8 +181,8 @@ int enetc_setup_tc_cbs(struct net_device *ndev, void *type_data)
> int bw_sum = 0;
> u8 bw;
>
> - prio_top = netdev_get_prio_tc_map(ndev, tc_nums - 1);
> - prio_next = netdev_get_prio_tc_map(ndev, tc_nums - 2);
> + prio_top = tc_nums - 1;
> + prio_next = tc_nums - 2;
>
> /* Support highest prio and second prio tc in cbs mode */
> if (tc != prio_top && tc != prio_next)
> --
> 2.25.1
>

2023-06-08 20:24:49

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH V2 net] net: enetc: correct the indexes of highest and 2nd highest TCs

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

On Wed, 7 Jun 2023 17:10:48 +0800 you wrote:
> From: Wei Fang <[email protected]>
>
> For ENETC hardware, the TCs are numbered from 0 to N-1, where N
> is the number of TCs. Numerically higher TC has higher priority.
> It's obvious that the highest priority TC index should be N-1 and
> the 2nd highest priority TC index should be N-2.
>
> [...]

Here is the summary with links:
- [V2,net] net: enetc: correct the indexes of highest and 2nd highest TCs
https://git.kernel.org/netdev/net/c/21225873be14

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html