Skip to content

Commit 08fb1da

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5e: Support DCBNL IEEE ETS
Support the ndo_setup_tc callback and the needed methods for multi TC/UP support, and removed the default_vlan_prio from mlx5e_priv which is always 0, it was replaced with hardcoded "0" in the new select queue method. For that we now create MAX_NUM_TC num of TISs (one per prio) on netdevice creation instead of priv->params.num_tc which was always 1. So far each channel had a single TXQ, Now each channel has a TXQ per TC (Traffic Class). Added en_dcbnl.c which implements the set/get DCBNL IEEE ETS, set/get dcbx and registers the mlx5e dcbnl ops. We still use the kernel's default TXQ selection method to select the channel to transmit through but now we use our own method to select the TXQ inside the channel based on VLAN priority. In mlx5, as opposed to mlx4, tc group N gets lower priority than tc group N+1. CC: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Rana Shahout <ranas@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4f3961e commit 08fb1da

File tree

6 files changed

+317
-15
lines changed

6 files changed

+317
-15
lines changed

drivers/net/ethernet/mellanox/mlx5/core/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ config MLX5_CORE_EN
1919
Ethernet support in Mellanox Technologies ConnectX-4 NIC.
2020
Ethernet and Infiniband support in ConnectX-4 are currently mutually
2121
exclusive.
22+
23+
config MLX5_CORE_EN_DCB
24+
bool "Data Center Bridging (DCB) Support"
25+
default y
26+
depends on MLX5_CORE_EN && DCB
27+
---help---
28+
Say Y here if you want to use Data Center Bridging (DCB) in the
29+
driver.
30+
If set to N, will not be able to configure QoS and ratelimit attributes.
31+
This flag is depended on the kernel's DCB support.
32+
33+
If unsure, set to Y

drivers/net/ethernet/mellanox/mlx5/core/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ obj-$(CONFIG_MLX5_CORE) += mlx5_core.o
33
mlx5_core-y := main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \
44
health.o mcg.o cq.o srq.o alloc.o qp.o port.o mr.o pd.o \
55
mad.o transobj.o vport.o sriov.o fs_cmd.o fs_core.o
6+
67
mlx5_core-$(CONFIG_MLX5_CORE_EN) += wq.o eswitch.o \
78
en_main.o en_fs.o en_ethtool.o en_tx.o en_rx.o \
89
en_txrx.o en_clock.o
10+
11+
mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o

drivers/net/ethernet/mellanox/mlx5/core/en.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070

7171
#define MLX5E_NUM_MAIN_GROUPS 9
7272

73+
#ifdef CONFIG_MLX5_CORE_EN_DCB
74+
#define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
75+
#define MLX5E_MIN_BW_ALLOC 1 /* Min percentage of BW allocation */
76+
#endif
77+
7378
static const char vport_strings[][ETH_GSTRING_LEN] = {
7479
/* vport statistics */
7580
"rx_packets",
@@ -273,7 +278,6 @@ struct mlx5e_params {
273278
u8 log_sq_size;
274279
u8 log_rq_size;
275280
u16 num_channels;
276-
u8 default_vlan_prio;
277281
u8 num_tc;
278282
u16 rx_cq_moderation_usec;
279283
u16 rx_cq_moderation_pkts;
@@ -286,6 +290,9 @@ struct mlx5e_params {
286290
u8 rss_hfunc;
287291
u8 toeplitz_hash_key[40];
288292
u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
293+
#ifdef CONFIG_MLX5_CORE_EN_DCB
294+
struct ieee_ets ets;
295+
#endif
289296
};
290297

291298
struct mlx5e_tstamp {
@@ -506,7 +513,6 @@ struct mlx5e_flow_tables {
506513

507514
struct mlx5e_priv {
508515
/* priv data path fields - start */
509-
int default_vlan_prio;
510516
struct mlx5e_sq **txq_to_sq_map;
511517
int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
512518
/* priv data path fields - end */
@@ -666,4 +672,9 @@ static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
666672
}
667673

668674
extern const struct ethtool_ops mlx5e_ethtool_ops;
675+
#ifdef CONFIG_MLX5_CORE_EN_DCB
676+
extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
677+
int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
678+
#endif
679+
669680
u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/*
2+
* Copyright (c) 2016, Mellanox Technologies. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*/
32+
#include <linux/device.h>
33+
#include <linux/netdevice.h>
34+
#include "en.h"
35+
36+
#define MLX5E_MAX_PRIORITY 8
37+
38+
static int mlx5e_dcbnl_ieee_getets(struct net_device *netdev,
39+
struct ieee_ets *ets)
40+
{
41+
struct mlx5e_priv *priv = netdev_priv(netdev);
42+
43+
if (!MLX5_CAP_GEN(priv->mdev, ets))
44+
return -ENOTSUPP;
45+
46+
memcpy(ets, &priv->params.ets, sizeof(*ets));
47+
return 0;
48+
}
49+
50+
enum {
51+
MLX5E_VENDOR_TC_GROUP_NUM = 7,
52+
MLX5E_ETS_TC_GROUP_NUM = 0,
53+
};
54+
55+
static void mlx5e_build_tc_group(struct ieee_ets *ets, u8 *tc_group, int max_tc)
56+
{
57+
bool any_tc_mapped_to_ets = false;
58+
int strict_group;
59+
int i;
60+
61+
for (i = 0; i <= max_tc; i++)
62+
if (ets->tc_tsa[i] == IEEE_8021QAZ_TSA_ETS)
63+
any_tc_mapped_to_ets = true;
64+
65+
strict_group = any_tc_mapped_to_ets ? 1 : 0;
66+
67+
for (i = 0; i <= max_tc; i++) {
68+
switch (ets->tc_tsa[i]) {
69+
case IEEE_8021QAZ_TSA_VENDOR:
70+
tc_group[i] = MLX5E_VENDOR_TC_GROUP_NUM;
71+
break;
72+
case IEEE_8021QAZ_TSA_STRICT:
73+
tc_group[i] = strict_group++;
74+
break;
75+
case IEEE_8021QAZ_TSA_ETS:
76+
tc_group[i] = MLX5E_ETS_TC_GROUP_NUM;
77+
break;
78+
}
79+
}
80+
}
81+
82+
static void mlx5e_build_tc_tx_bw(struct ieee_ets *ets, u8 *tc_tx_bw,
83+
u8 *tc_group, int max_tc)
84+
{
85+
int i;
86+
87+
for (i = 0; i <= max_tc; i++) {
88+
switch (ets->tc_tsa[i]) {
89+
case IEEE_8021QAZ_TSA_VENDOR:
90+
tc_tx_bw[i] = MLX5E_MAX_BW_ALLOC;
91+
break;
92+
case IEEE_8021QAZ_TSA_STRICT:
93+
tc_tx_bw[i] = MLX5E_MAX_BW_ALLOC;
94+
break;
95+
case IEEE_8021QAZ_TSA_ETS:
96+
tc_tx_bw[i] = ets->tc_tx_bw[i] ?: MLX5E_MIN_BW_ALLOC;
97+
break;
98+
}
99+
}
100+
}
101+
102+
int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets)
103+
{
104+
struct mlx5_core_dev *mdev = priv->mdev;
105+
u8 tc_tx_bw[IEEE_8021QAZ_MAX_TCS];
106+
u8 tc_group[IEEE_8021QAZ_MAX_TCS];
107+
int max_tc = mlx5_max_tc(mdev);
108+
int err;
109+
110+
if (!MLX5_CAP_GEN(mdev, ets))
111+
return -ENOTSUPP;
112+
113+
mlx5e_build_tc_group(ets, tc_group, max_tc);
114+
mlx5e_build_tc_tx_bw(ets, tc_tx_bw, tc_group, max_tc);
115+
116+
err = mlx5_set_port_prio_tc(mdev, ets->prio_tc);
117+
if (err)
118+
return err;
119+
120+
err = mlx5_set_port_tc_group(mdev, tc_group);
121+
if (err)
122+
return err;
123+
124+
return mlx5_set_port_tc_bw_alloc(mdev, tc_tx_bw);
125+
}
126+
127+
static int mlx5e_dbcnl_validate_ets(struct ieee_ets *ets)
128+
{
129+
int bw_sum = 0;
130+
int i;
131+
132+
/* Validate Priority */
133+
for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
134+
if (ets->prio_tc[i] >= MLX5E_MAX_PRIORITY)
135+
return -EINVAL;
136+
}
137+
138+
/* Validate Bandwidth Sum */
139+
for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
140+
if (ets->tc_tsa[i] == IEEE_8021QAZ_TSA_ETS)
141+
bw_sum += ets->tc_tx_bw[i];
142+
}
143+
144+
if (bw_sum != 0 && bw_sum != 100)
145+
return -EINVAL;
146+
return 0;
147+
}
148+
149+
static int mlx5e_dcbnl_ieee_setets(struct net_device *netdev,
150+
struct ieee_ets *ets)
151+
{
152+
struct mlx5e_priv *priv = netdev_priv(netdev);
153+
int err;
154+
155+
err = mlx5e_dbcnl_validate_ets(ets);
156+
if (err)
157+
return err;
158+
159+
err = mlx5e_dcbnl_ieee_setets_core(priv, ets);
160+
if (err)
161+
return err;
162+
163+
memcpy(&priv->params.ets, ets, sizeof(*ets));
164+
priv->params.ets.ets_cap = mlx5_max_tc(priv->mdev) + 1;
165+
166+
return 0;
167+
}
168+
169+
static u8 mlx5e_dcbnl_getdcbx(struct net_device *dev)
170+
{
171+
return DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
172+
}
173+
174+
static u8 mlx5e_dcbnl_setdcbx(struct net_device *dev, u8 mode)
175+
{
176+
if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
177+
(mode & DCB_CAP_DCBX_VER_CEE) ||
178+
!(mode & DCB_CAP_DCBX_VER_IEEE) ||
179+
!(mode & DCB_CAP_DCBX_HOST))
180+
return 1;
181+
182+
return 0;
183+
}
184+
185+
const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops = {
186+
.ieee_getets = mlx5e_dcbnl_ieee_getets,
187+
.ieee_setets = mlx5e_dcbnl_ieee_setets,
188+
.getdcbx = mlx5e_dcbnl_getdcbx,
189+
.setdcbx = mlx5e_dcbnl_setdcbx,
190+
};

0 commit comments

Comments
 (0)