Skip to content

Commit 39ac237

Browse files
Paul BlakeySaeed Mahameed
authored andcommitted
net/mlx5: E-Switch, Refactor chains and priorities
To support the entire chain and prio range (32bit + 16bit), instead of a using a static array of chains/prios of limited size, create them dynamically, and use a rhashtable to search for existing chains/prio combinations. This will be used in next patch to actually increase the number using unamanged tables support and ignore flow level capability. Signed-off-by: Paul Blakey <[email protected]> Reviewed-by: Roi Dayan <[email protected]> Reviewed-by: Oz Shlomo <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 82270e1 commit 39ac237

File tree

7 files changed

+637
-292
lines changed

7 files changed

+637
-292
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mlx5_core-$(CONFIG_PCI_HYPERV_INTERFACE) += en/hv_vhca_stats.o
4242
# Core extra
4343
#
4444
mlx5_core-$(CONFIG_MLX5_ESWITCH) += eswitch.o eswitch_offloads.o eswitch_offloads_termtbl.o \
45-
ecpf.o rdma.o
45+
ecpf.o rdma.o eswitch_offloads_chains.o
4646
mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o
4747
mlx5_core-$(CONFIG_VXLAN) += lib/vxlan.o
4848
mlx5_core-$(CONFIG_PTP_1588_CLOCK) += lib/clock.o

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <net/ipv6_stubs.h>
4242

4343
#include "eswitch.h"
44+
#include "eswitch_offloads_chains.h"
4445
#include "en.h"
4546
#include "en_rep.h"
4647
#include "en_tc.h"
@@ -1262,25 +1263,25 @@ static int mlx5e_rep_setup_ft_cb(enum tc_setup_type type, void *type_data,
12621263
case TC_SETUP_CLSFLOWER:
12631264
memcpy(&tmp, f, sizeof(*f));
12641265

1265-
if (!mlx5_eswitch_prios_supported(esw) ||
1266+
if (!mlx5_esw_chains_prios_supported(esw) ||
12661267
tmp.common.chain_index)
12671268
return -EOPNOTSUPP;
12681269

12691270
/* Re-use tc offload path by moving the ft flow to the
12701271
* reserved ft chain.
12711272
*
1272-
* FT offload can use prio range [0, INT_MAX], so we
1273-
* normalize it to range [1, mlx5_eswitch_get_prio_range(esw)]
1273+
* FT offload can use prio range [0, INT_MAX], so we normalize
1274+
* it to range [1, mlx5_esw_chains_get_prio_range(esw)]
12741275
* as with tc, where prio 0 isn't supported.
12751276
*
12761277
* We only support chain 0 of FT offload.
12771278
*/
1278-
if (tmp.common.prio >= mlx5_eswitch_get_prio_range(esw))
1279+
if (tmp.common.prio >= mlx5_esw_chains_get_prio_range(esw))
12791280
return -EOPNOTSUPP;
12801281
if (tmp.common.chain_index != 0)
12811282
return -EOPNOTSUPP;
12821283

1283-
tmp.common.chain_index = mlx5_eswitch_get_ft_chain(esw);
1284+
tmp.common.chain_index = mlx5_esw_chains_get_ft_chain(esw);
12841285
tmp.common.prio++;
12851286
err = mlx5e_rep_setup_tc_cls_flower(priv, &tmp, flags);
12861287
memcpy(&f->stats, &tmp.stats, sizeof(f->stats));

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "en_rep.h"
5252
#include "en_tc.h"
5353
#include "eswitch.h"
54+
#include "eswitch_offloads_chains.h"
5455
#include "fs_core.h"
5556
#include "en/port.h"
5657
#include "en/tc_tun.h"
@@ -1083,7 +1084,7 @@ mlx5e_tc_offload_to_slow_path(struct mlx5_eswitch *esw,
10831084
memcpy(slow_attr, flow->esw_attr, sizeof(*slow_attr));
10841085
slow_attr->action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
10851086
slow_attr->split_count = 0;
1086-
slow_attr->dest_chain = FDB_TC_SLOW_PATH_CHAIN;
1087+
slow_attr->flags |= MLX5_ESW_ATTR_FLAG_SLOW_PATH;
10871088

10881089
rule = mlx5e_tc_offload_fdb_rules(esw, flow, spec, slow_attr);
10891090
if (!IS_ERR(rule))
@@ -1100,7 +1101,7 @@ mlx5e_tc_unoffload_from_slow_path(struct mlx5_eswitch *esw,
11001101
memcpy(slow_attr, flow->esw_attr, sizeof(*slow_attr));
11011102
slow_attr->action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
11021103
slow_attr->split_count = 0;
1103-
slow_attr->dest_chain = FDB_TC_SLOW_PATH_CHAIN;
1104+
slow_attr->flags |= MLX5_ESW_ATTR_FLAG_SLOW_PATH;
11041105
mlx5e_tc_unoffload_fdb_rules(esw, flow, slow_attr);
11051106
flow_flag_clear(flow, SLOW);
11061107
}
@@ -1160,19 +1161,18 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
11601161
struct netlink_ext_ack *extack)
11611162
{
11621163
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
1163-
u32 max_chain = mlx5_eswitch_get_chain_range(esw);
11641164
struct mlx5_esw_flow_attr *attr = flow->esw_attr;
11651165
struct mlx5e_tc_flow_parse_attr *parse_attr = attr->parse_attr;
1166-
u16 max_prio = mlx5_eswitch_get_prio_range(esw);
11671166
struct net_device *out_dev, *encap_dev = NULL;
11681167
struct mlx5_fc *counter = NULL;
11691168
struct mlx5e_rep_priv *rpriv;
11701169
struct mlx5e_priv *out_priv;
11711170
bool encap_valid = true;
1171+
u32 max_prio, max_chain;
11721172
int err = 0;
11731173
int out_index;
11741174

1175-
if (!mlx5_eswitch_prios_supported(esw) && attr->prio != 1) {
1175+
if (!mlx5_esw_chains_prios_supported(esw) && attr->prio != 1) {
11761176
NL_SET_ERR_MSG(extack, "E-switch priorities unsupported, upgrade FW");
11771177
return -EOPNOTSUPP;
11781178
}
@@ -1182,11 +1182,13 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
11821182
* FDB_FT_CHAIN which is outside tc range.
11831183
* See mlx5e_rep_setup_ft_cb().
11841184
*/
1185+
max_chain = mlx5_esw_chains_get_chain_range(esw);
11851186
if (!mlx5e_is_ft_flow(flow) && attr->chain > max_chain) {
11861187
NL_SET_ERR_MSG(extack, "Requested chain is out of supported range");
11871188
return -EOPNOTSUPP;
11881189
}
11891190

1191+
max_prio = mlx5_esw_chains_get_prio_range(esw);
11901192
if (attr->prio > max_prio) {
11911193
NL_SET_ERR_MSG(extack, "Requested priority is out of supported range");
11921194
return -EOPNOTSUPP;
@@ -3469,7 +3471,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
34693471
break;
34703472
case FLOW_ACTION_GOTO: {
34713473
u32 dest_chain = act->chain_index;
3472-
u32 max_chain = mlx5_eswitch_get_chain_range(esw);
3474+
u32 max_chain = mlx5_esw_chains_get_chain_range(esw);
34733475

34743476
if (ft_flow) {
34753477
NL_SET_ERR_MSG_MOD(extack, "Goto action is not supported");

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ enum offloads_fdb_flags {
157157
ESW_FDB_CHAINS_AND_PRIOS_SUPPORTED = BIT(0),
158158
};
159159

160-
extern const unsigned int ESW_POOLS[4];
160+
struct mlx5_esw_chains_priv;
161161

162162
struct mlx5_eswitch_fdb {
163163
union {
@@ -182,14 +182,7 @@ struct mlx5_eswitch_fdb {
182182
struct mlx5_flow_handle *miss_rule_multi;
183183
int vlan_push_pop_refcount;
184184

185-
struct {
186-
struct mlx5_flow_table *fdb;
187-
u32 num_rules;
188-
} fdb_prio[FDB_NUM_CHAINS][FDB_TC_MAX_PRIO + 1][FDB_TC_LEVELS_PER_PRIO];
189-
/* Protects fdb_prio table */
190-
struct mutex fdb_prio_lock;
191-
192-
int fdb_left[ARRAY_SIZE(ESW_POOLS)];
185+
struct mlx5_esw_chains_priv *esw_chains_priv;
193186
} offloads;
194187
};
195188
u32 flags;
@@ -355,18 +348,6 @@ mlx5_eswitch_del_fwd_rule(struct mlx5_eswitch *esw,
355348
struct mlx5_flow_handle *rule,
356349
struct mlx5_esw_flow_attr *attr);
357350

358-
bool
359-
mlx5_eswitch_prios_supported(struct mlx5_eswitch *esw);
360-
361-
u16
362-
mlx5_eswitch_get_prio_range(struct mlx5_eswitch *esw);
363-
364-
u32
365-
mlx5_eswitch_get_chain_range(struct mlx5_eswitch *esw);
366-
367-
unsigned int
368-
mlx5_eswitch_get_ft_chain(struct mlx5_eswitch *esw);
369-
370351
struct mlx5_flow_handle *
371352
mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, u16 vport,
372353
struct mlx5_flow_destination *dest);
@@ -391,6 +372,11 @@ enum {
391372
MLX5_ESW_DEST_ENCAP_VALID = BIT(1),
392373
};
393374

375+
enum {
376+
MLX5_ESW_ATTR_FLAG_VLAN_HANDLED = BIT(0),
377+
MLX5_ESW_ATTR_FLAG_SLOW_PATH = BIT(1),
378+
};
379+
394380
struct mlx5_esw_flow_attr {
395381
struct mlx5_eswitch_rep *in_rep;
396382
struct mlx5_core_dev *in_mdev;
@@ -404,7 +390,6 @@ struct mlx5_esw_flow_attr {
404390
u16 vlan_vid[MLX5_FS_VLAN_DEPTH];
405391
u8 vlan_prio[MLX5_FS_VLAN_DEPTH];
406392
u8 total_vlan;
407-
bool vlan_handled;
408393
struct {
409394
u32 flags;
410395
struct mlx5_eswitch_rep *rep;
@@ -419,6 +404,7 @@ struct mlx5_esw_flow_attr {
419404
u32 chain;
420405
u16 prio;
421406
u32 dest_chain;
407+
u32 flags;
422408
struct mlx5e_tc_flow_parse_attr *parse_attr;
423409
};
424410

0 commit comments

Comments
 (0)