Skip to content

Commit be0f161

Browse files
Huy NguyenSaeed Mahameed
authored andcommitted
net/mlx5e: DCBNL, Implement tc with ets type and zero bandwidth
Previously, tc with ets type and zero bandwidth is not accepted by driver. This behavior does not follow the IEEE802.1qaz spec. If there are tcs with ets type and zero bandwidth, these tcs are assigned to the lowest priority tc_group #0. We equally distribute 100% bw of the tc_group #0 to these zero bandwidth ets tcs. Also, the non zero bandwidth ets tcs are assigned to tc_group raspberrypi#1. If there is no zero bandwidth ets tc, the non zero bandwidth ets tcs are assigned to tc_group #0. Fixes: cdcf112 ("net/mlx5e: Validate BW weight values of ETS") Signed-off-by: Huy Nguyen <huyn@mellanox.com> Reviewed-by: Parav Pandit <parav@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
1 parent 3c37745 commit be0f161

3 files changed

Lines changed: 106 additions & 30 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c‎

Lines changed: 83 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
#define MLX5E_CEE_STATE_UP 1
4242
#define MLX5E_CEE_STATE_DOWN 0
4343

44+
enum {
45+
MLX5E_VENDOR_TC_GROUP_NUM = 7,
46+
MLX5E_LOWEST_PRIO_GROUP = 0,
47+
};
48+
4449
/* If dcbx mode is non-host set the dcbx mode to host.
4550
*/
4651
static int mlx5e_dcbnl_set_dcbx_mode(struct mlx5e_priv *priv,
@@ -85,6 +90,9 @@ static int mlx5e_dcbnl_ieee_getets(struct net_device *netdev,
8590
{
8691
struct mlx5e_priv *priv = netdev_priv(netdev);
8792
struct mlx5_core_dev *mdev = priv->mdev;
93+
u8 tc_group[IEEE_8021QAZ_MAX_TCS];
94+
bool is_tc_group_6_exist = false;
95+
bool is_zero_bw_ets_tc = false;
8896
int err = 0;
8997
int i;
9098

@@ -96,37 +104,64 @@ static int mlx5e_dcbnl_ieee_getets(struct net_device *netdev,
96104
err = mlx5_query_port_prio_tc(mdev, i, &ets->prio_tc[i]);
97105
if (err)
98106
return err;
99-
}
100107

101-
for (i = 0; i < ets->ets_cap; i++) {
108+
err = mlx5_query_port_tc_group(mdev, i, &tc_group[i]);
109+
if (err)
110+
return err;
111+
102112
err = mlx5_query_port_tc_bw_alloc(mdev, i, &ets->tc_tx_bw[i]);
103113
if (err)
104114
return err;
115+
116+
if (ets->tc_tx_bw[i] < MLX5E_MAX_BW_ALLOC &&
117+
tc_group[i] == (MLX5E_LOWEST_PRIO_GROUP + 1))
118+
is_zero_bw_ets_tc = true;
119+
120+
if (tc_group[i] == (MLX5E_VENDOR_TC_GROUP_NUM - 1))
121+
is_tc_group_6_exist = true;
122+
}
123+
124+
/* Report 0% ets tc if exits*/
125+
if (is_zero_bw_ets_tc) {
126+
for (i = 0; i < ets->ets_cap; i++)
127+
if (tc_group[i] == MLX5E_LOWEST_PRIO_GROUP)
128+
ets->tc_tx_bw[i] = 0;
129+
}
130+
131+
/* Update tc_tsa based on fw setting*/
132+
for (i = 0; i < ets->ets_cap; i++) {
105133
if (ets->tc_tx_bw[i] < MLX5E_MAX_BW_ALLOC)
106134
priv->dcbx.tc_tsa[i] = IEEE_8021QAZ_TSA_ETS;
135+
else if (tc_group[i] == MLX5E_VENDOR_TC_GROUP_NUM &&
136+
!is_tc_group_6_exist)
137+
priv->dcbx.tc_tsa[i] = IEEE_8021QAZ_TSA_VENDOR;
107138
}
108-
109139
memcpy(ets->tc_tsa, priv->dcbx.tc_tsa, sizeof(ets->tc_tsa));
110140

111141
return err;
112142
}
113143

114-
enum {
115-
MLX5E_VENDOR_TC_GROUP_NUM = 7,
116-
MLX5E_ETS_TC_GROUP_NUM = 0,
117-
};
118-
119144
static void mlx5e_build_tc_group(struct ieee_ets *ets, u8 *tc_group, int max_tc)
120145
{
121146
bool any_tc_mapped_to_ets = false;
147+
bool ets_zero_bw = false;
122148
int strict_group;
123149
int i;
124150

125-
for (i = 0; i <= max_tc; i++)
126-
if (ets->tc_tsa[i] == IEEE_8021QAZ_TSA_ETS)
151+
for (i = 0; i <= max_tc; i++) {
152+
if (ets->tc_tsa[i] == IEEE_8021QAZ_TSA_ETS) {
127153
any_tc_mapped_to_ets = true;
154+
if (!ets->tc_tx_bw[i])
155+
ets_zero_bw = true;
156+
}
157+
}
128158

129-
strict_group = any_tc_mapped_to_ets ? 1 : 0;
159+
/* strict group has higher priority than ets group */
160+
strict_group = MLX5E_LOWEST_PRIO_GROUP;
161+
if (any_tc_mapped_to_ets)
162+
strict_group++;
163+
if (ets_zero_bw)
164+
strict_group++;
130165

131166
for (i = 0; i <= max_tc; i++) {
132167
switch (ets->tc_tsa[i]) {
@@ -137,7 +172,9 @@ static void mlx5e_build_tc_group(struct ieee_ets *ets, u8 *tc_group, int max_tc)
137172
tc_group[i] = strict_group++;
138173
break;
139174
case IEEE_8021QAZ_TSA_ETS:
140-
tc_group[i] = MLX5E_ETS_TC_GROUP_NUM;
175+
tc_group[i] = MLX5E_LOWEST_PRIO_GROUP;
176+
if (ets->tc_tx_bw[i] && ets_zero_bw)
177+
tc_group[i] = MLX5E_LOWEST_PRIO_GROUP + 1;
141178
break;
142179
}
143180
}
@@ -146,8 +183,22 @@ static void mlx5e_build_tc_group(struct ieee_ets *ets, u8 *tc_group, int max_tc)
146183
static void mlx5e_build_tc_tx_bw(struct ieee_ets *ets, u8 *tc_tx_bw,
147184
u8 *tc_group, int max_tc)
148185
{
186+
int bw_for_ets_zero_bw_tc = 0;
187+
int last_ets_zero_bw_tc = -1;
188+
int num_ets_zero_bw = 0;
149189
int i;
150190

191+
for (i = 0; i <= max_tc; i++) {
192+
if (ets->tc_tsa[i] == IEEE_8021QAZ_TSA_ETS &&
193+
!ets->tc_tx_bw[i]) {
194+
num_ets_zero_bw++;
195+
last_ets_zero_bw_tc = i;
196+
}
197+
}
198+
199+
if (num_ets_zero_bw)
200+
bw_for_ets_zero_bw_tc = MLX5E_MAX_BW_ALLOC / num_ets_zero_bw;
201+
151202
for (i = 0; i <= max_tc; i++) {
152203
switch (ets->tc_tsa[i]) {
153204
case IEEE_8021QAZ_TSA_VENDOR:
@@ -157,12 +208,26 @@ static void mlx5e_build_tc_tx_bw(struct ieee_ets *ets, u8 *tc_tx_bw,
157208
tc_tx_bw[i] = MLX5E_MAX_BW_ALLOC;
158209
break;
159210
case IEEE_8021QAZ_TSA_ETS:
160-
tc_tx_bw[i] = ets->tc_tx_bw[i];
211+
tc_tx_bw[i] = ets->tc_tx_bw[i] ?
212+
ets->tc_tx_bw[i] :
213+
bw_for_ets_zero_bw_tc;
161214
break;
162215
}
163216
}
217+
218+
/* Make sure the total bw for ets zero bw group is 100% */
219+
if (last_ets_zero_bw_tc != -1)
220+
tc_tx_bw[last_ets_zero_bw_tc] +=
221+
MLX5E_MAX_BW_ALLOC % num_ets_zero_bw;
164222
}
165223

224+
/* If there are ETS BW 0,
225+
* Set ETS group # to 1 for all ETS non zero BW tcs. Their sum must be 100%.
226+
* Set group #0 to all the ETS BW 0 tcs and
227+
* equally splits the 100% BW between them
228+
* Report both group #0 and #1 as ETS type.
229+
* All the tcs in group #0 will be reported with 0% BW.
230+
*/
166231
int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets)
167232
{
168233
struct mlx5_core_dev *mdev = priv->mdev;
@@ -188,7 +253,6 @@ int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets)
188253
return err;
189254

190255
memcpy(priv->dcbx.tc_tsa, ets->tc_tsa, sizeof(ets->tc_tsa));
191-
192256
return err;
193257
}
194258

@@ -209,17 +273,9 @@ static int mlx5e_dbcnl_validate_ets(struct net_device *netdev,
209273
}
210274

211275
/* Validate Bandwidth Sum */
212-
for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
213-
if (ets->tc_tsa[i] == IEEE_8021QAZ_TSA_ETS) {
214-
if (!ets->tc_tx_bw[i]) {
215-
netdev_err(netdev,
216-
"Failed to validate ETS: BW 0 is illegal\n");
217-
return -EINVAL;
218-
}
219-
276+
for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
277+
if (ets->tc_tsa[i] == IEEE_8021QAZ_TSA_ETS)
220278
bw_sum += ets->tc_tx_bw[i];
221-
}
222-
}
223279

224280
if (bw_sum != 0 && bw_sum != 100) {
225281
netdev_err(netdev,
@@ -533,17 +589,16 @@ static void mlx5e_dcbnl_getpgtccfgtx(struct net_device *netdev,
533589
static void mlx5e_dcbnl_getpgbwgcfgtx(struct net_device *netdev,
534590
int pgid, u8 *bw_pct)
535591
{
536-
struct mlx5e_priv *priv = netdev_priv(netdev);
537-
struct mlx5_core_dev *mdev = priv->mdev;
592+
struct ieee_ets ets;
538593

539594
if (pgid >= CEE_DCBX_MAX_PGS) {
540595
netdev_err(netdev,
541596
"%s, priority group is out of range\n", __func__);
542597
return;
543598
}
544599

545-
if (mlx5_query_port_tc_bw_alloc(mdev, pgid, bw_pct))
546-
*bw_pct = 0;
600+
mlx5e_dcbnl_ieee_getets(netdev, &ets);
601+
*bw_pct = ets.tc_tx_bw[pgid];
547602
}
548603

549604
static void mlx5e_dcbnl_setpfccfg(struct net_device *netdev,
@@ -739,8 +794,6 @@ static void mlx5e_ets_init(struct mlx5e_priv *priv)
739794
ets.prio_tc[i] = i;
740795
}
741796

742-
memcpy(priv->dcbx.tc_tsa, ets.tc_tsa, sizeof(ets.tc_tsa));
743-
744797
/* tclass[prio=0]=1, tclass[prio=1]=0, tclass[prio=i]=i (for i>1) */
745798
ets.prio_tc[0] = 1;
746799
ets.prio_tc[1] = 0;

‎drivers/net/ethernet/mellanox/mlx5/core/port.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,27 @@ int mlx5_set_port_tc_group(struct mlx5_core_dev *mdev, u8 *tc_group)
677677
}
678678
EXPORT_SYMBOL_GPL(mlx5_set_port_tc_group);
679679

680+
int mlx5_query_port_tc_group(struct mlx5_core_dev *mdev,
681+
u8 tc, u8 *tc_group)
682+
{
683+
u32 out[MLX5_ST_SZ_DW(qetc_reg)];
684+
void *ets_tcn_conf;
685+
int err;
686+
687+
err = mlx5_query_port_qetcr_reg(mdev, out, sizeof(out));
688+
if (err)
689+
return err;
690+
691+
ets_tcn_conf = MLX5_ADDR_OF(qetc_reg, out,
692+
tc_configuration[tc]);
693+
694+
*tc_group = MLX5_GET(ets_tcn_config_reg, ets_tcn_conf,
695+
group);
696+
697+
return 0;
698+
}
699+
EXPORT_SYMBOL_GPL(mlx5_query_port_tc_group);
700+
680701
int mlx5_set_port_tc_bw_alloc(struct mlx5_core_dev *mdev, u8 *tc_bw)
681702
{
682703
u32 in[MLX5_ST_SZ_DW(qetc_reg)] = {0};

‎include/linux/mlx5/port.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ int mlx5_set_port_prio_tc(struct mlx5_core_dev *mdev, u8 *prio_tc);
157157
int mlx5_query_port_prio_tc(struct mlx5_core_dev *mdev,
158158
u8 prio, u8 *tc);
159159
int mlx5_set_port_tc_group(struct mlx5_core_dev *mdev, u8 *tc_group);
160+
int mlx5_query_port_tc_group(struct mlx5_core_dev *mdev,
161+
u8 tc, u8 *tc_group);
160162
int mlx5_set_port_tc_bw_alloc(struct mlx5_core_dev *mdev, u8 *tc_bw);
161163
int mlx5_query_port_tc_bw_alloc(struct mlx5_core_dev *mdev,
162164
u8 tc, u8 *bw_pct);

0 commit comments

Comments
 (0)