Skip to content

Commit

Permalink
mlxsw: spectrum_matchall: Process matchall events from the same cb as…
Browse files Browse the repository at this point in the history
… flower

Currently there are two callbacks registered: one for matchall,
one for flower. This causes the user to see "in_hw_count 2" in TC filter
dump. Because of this and also as a preparation for future matchall
offload for rules equivalent to flower-all-match, move the processing of
shared block into matchall.c. Leave only one cb for mlxsw driver
per-block.

Signed-off-by: Jiri Pirko <[email protected]>
Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jpirko authored and davem330 committed Apr 27, 2020
1 parent 481ff57 commit 3c65013
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 120 deletions.
125 changes: 27 additions & 98 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1350,15 +1350,15 @@ static int mlxsw_sp_port_kill_vid(struct net_device *dev,
return 0;
}

static int mlxsw_sp_setup_tc_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_cls_matchall_offload *f,
bool ingress)
static int
mlxsw_sp_setup_tc_cls_matchall(struct mlxsw_sp_flow_block *flow_block,
struct tc_cls_matchall_offload *f)
{
switch (f->command) {
case TC_CLSMATCHALL_REPLACE:
return mlxsw_sp_mall_replace(mlxsw_sp_port, f, ingress);
return mlxsw_sp_mall_replace(flow_block, f);
case TC_CLSMATCHALL_DESTROY:
mlxsw_sp_mall_destroy(mlxsw_sp_port, f);
mlxsw_sp_mall_destroy(flow_block, f);
return 0;
default:
return -EOPNOTSUPP;
Expand Down Expand Up @@ -1389,62 +1389,25 @@ mlxsw_sp_setup_tc_cls_flower(struct mlxsw_sp_flow_block *flow_block,
}
}

static int mlxsw_sp_setup_tc_block_cb_matchall(enum tc_setup_type type,
void *type_data,
void *cb_priv, bool ingress)
static int mlxsw_sp_setup_tc_block_cb(enum tc_setup_type type,
void *type_data, void *cb_priv)
{
struct mlxsw_sp_port *mlxsw_sp_port = cb_priv;

switch (type) {
case TC_SETUP_CLSMATCHALL:
if (!tc_cls_can_offload_and_chain0(mlxsw_sp_port->dev,
type_data))
return -EOPNOTSUPP;
struct mlxsw_sp_flow_block *flow_block = cb_priv;

return mlxsw_sp_setup_tc_cls_matchall(mlxsw_sp_port, type_data,
ingress);
case TC_SETUP_CLSFLOWER:
return 0;
default:
if (mlxsw_sp_flow_block_disabled(flow_block))
return -EOPNOTSUPP;
}
}

static int mlxsw_sp_setup_tc_block_cb_matchall_ig(enum tc_setup_type type,
void *type_data,
void *cb_priv)
{
return mlxsw_sp_setup_tc_block_cb_matchall(type, type_data,
cb_priv, true);
}

static int mlxsw_sp_setup_tc_block_cb_matchall_eg(enum tc_setup_type type,
void *type_data,
void *cb_priv)
{
return mlxsw_sp_setup_tc_block_cb_matchall(type, type_data,
cb_priv, false);
}

static int mlxsw_sp_setup_tc_block_cb_flower(enum tc_setup_type type,
void *type_data, void *cb_priv)
{
struct mlxsw_sp_flow_block *flow_block = cb_priv;

switch (type) {
case TC_SETUP_CLSMATCHALL:
return 0;
return mlxsw_sp_setup_tc_cls_matchall(flow_block, type_data);
case TC_SETUP_CLSFLOWER:
if (mlxsw_sp_flow_block_disabled(flow_block))
return -EOPNOTSUPP;

return mlxsw_sp_setup_tc_cls_flower(flow_block, type_data);
default:
return -EOPNOTSUPP;
}
}

static void mlxsw_sp_tc_block_flower_release(void *cb_priv)
static void mlxsw_sp_tc_block_release(void *cb_priv)
{
struct mlxsw_sp_flow_block *flow_block = cb_priv;

Expand All @@ -1453,26 +1416,25 @@ static void mlxsw_sp_tc_block_flower_release(void *cb_priv)

static LIST_HEAD(mlxsw_sp_block_cb_list);

static int
mlxsw_sp_setup_tc_block_flower_bind(struct mlxsw_sp_port *mlxsw_sp_port,
struct flow_block_offload *f, bool ingress)
static int mlxsw_sp_setup_tc_block_bind(struct mlxsw_sp_port *mlxsw_sp_port,
struct flow_block_offload *f,
bool ingress)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
struct mlxsw_sp_flow_block *flow_block;
struct flow_block_cb *block_cb;
bool register_block = false;
int err;

block_cb = flow_block_cb_lookup(f->block,
mlxsw_sp_setup_tc_block_cb_flower,
block_cb = flow_block_cb_lookup(f->block, mlxsw_sp_setup_tc_block_cb,
mlxsw_sp);
if (!block_cb) {
flow_block = mlxsw_sp_flow_block_create(mlxsw_sp, f->net);
if (!flow_block)
return -ENOMEM;
block_cb = flow_block_cb_alloc(mlxsw_sp_setup_tc_block_cb_flower,
block_cb = flow_block_cb_alloc(mlxsw_sp_setup_tc_block_cb,
mlxsw_sp, flow_block,
mlxsw_sp_tc_block_flower_release);
mlxsw_sp_tc_block_release);
if (IS_ERR(block_cb)) {
mlxsw_sp_flow_block_destroy(flow_block);
err = PTR_ERR(block_cb);
Expand Down Expand Up @@ -1507,18 +1469,16 @@ mlxsw_sp_setup_tc_block_flower_bind(struct mlxsw_sp_port *mlxsw_sp_port,
return err;
}

static void
mlxsw_sp_setup_tc_block_flower_unbind(struct mlxsw_sp_port *mlxsw_sp_port,
struct flow_block_offload *f,
bool ingress)
static void mlxsw_sp_setup_tc_block_unbind(struct mlxsw_sp_port *mlxsw_sp_port,
struct flow_block_offload *f,
bool ingress)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
struct mlxsw_sp_flow_block *flow_block;
struct flow_block_cb *block_cb;
int err;

block_cb = flow_block_cb_lookup(f->block,
mlxsw_sp_setup_tc_block_cb_flower,
block_cb = flow_block_cb_lookup(f->block, mlxsw_sp_setup_tc_block_cb,
mlxsw_sp);
if (!block_cb)
return;
Expand All @@ -1540,51 +1500,22 @@ mlxsw_sp_setup_tc_block_flower_unbind(struct mlxsw_sp_port *mlxsw_sp_port,
static int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port,
struct flow_block_offload *f)
{
struct flow_block_cb *block_cb;
flow_setup_cb_t *cb;
bool ingress;
int err;

if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS) {
cb = mlxsw_sp_setup_tc_block_cb_matchall_ig;
if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
ingress = true;
} else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS) {
cb = mlxsw_sp_setup_tc_block_cb_matchall_eg;
else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS)
ingress = false;
} else {
else
return -EOPNOTSUPP;
}

f->driver_block_list = &mlxsw_sp_block_cb_list;

switch (f->command) {
case FLOW_BLOCK_BIND:
if (flow_block_cb_is_busy(cb, mlxsw_sp_port,
&mlxsw_sp_block_cb_list))
return -EBUSY;

block_cb = flow_block_cb_alloc(cb, mlxsw_sp_port,
mlxsw_sp_port, NULL);
if (IS_ERR(block_cb))
return PTR_ERR(block_cb);
err = mlxsw_sp_setup_tc_block_flower_bind(mlxsw_sp_port, f,
ingress);
if (err) {
flow_block_cb_free(block_cb);
return err;
}
flow_block_cb_add(block_cb, f);
list_add_tail(&block_cb->driver_list, &mlxsw_sp_block_cb_list);
return 0;
return mlxsw_sp_setup_tc_block_bind(mlxsw_sp_port, f, ingress);
case FLOW_BLOCK_UNBIND:
mlxsw_sp_setup_tc_block_flower_unbind(mlxsw_sp_port,
f, ingress);
block_cb = flow_block_cb_lookup(f->block, cb, mlxsw_sp_port);
if (!block_cb)
return -ENOENT;

flow_block_cb_remove(block_cb, f);
list_del(&block_cb->driver_list);
mlxsw_sp_setup_tc_block_unbind(mlxsw_sp_port, f, ingress);
return 0;
default:
return -EOPNOTSUPP;
Expand Down Expand Up @@ -1621,8 +1552,7 @@ static int mlxsw_sp_feature_hw_tc(struct net_device *dev, bool enable)

if (!enable) {
if (mlxsw_sp_flow_block_rule_count(mlxsw_sp_port->ing_flow_block) ||
mlxsw_sp_flow_block_rule_count(mlxsw_sp_port->eg_flow_block) ||
!list_empty(&mlxsw_sp_port->mall_list)) {
mlxsw_sp_flow_block_rule_count(mlxsw_sp_port->eg_flow_block)) {
netdev_err(dev, "Active offloaded tc filters, can't turn hw_tc_offload off\n");
return -EINVAL;
}
Expand Down Expand Up @@ -3518,7 +3448,6 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
mlxsw_sp_port->mapping = *port_mapping;
mlxsw_sp_port->link.autoneg = 1;
INIT_LIST_HEAD(&mlxsw_sp_port->vlans_list);
INIT_LIST_HEAD(&mlxsw_sp_port->mall_list);

mlxsw_sp_port->pcpu_stats =
netdev_alloc_pcpu_stats(struct mlxsw_sp_port_pcpu_stats);
Expand Down
12 changes: 8 additions & 4 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ struct mlxsw_sp_port {
* the same localport can have
* different mapping.
*/
struct list_head mall_list;
struct {
#define MLXSW_HW_STATS_UPDATE_TIME HZ
struct rtnl_link_stats64 stats;
Expand Down Expand Up @@ -637,6 +636,7 @@ struct mlxsw_sp_acl_rule_info {
/* spectrum_flow.c */
struct mlxsw_sp_flow_block {
struct list_head binding_list;
struct list_head mall_list;
struct mlxsw_sp_acl_ruleset *ruleset_zero;
struct mlxsw_sp *mlxsw_sp;
unsigned int rule_count;
Expand Down Expand Up @@ -894,10 +894,14 @@ extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;

/* spectrum_matchall.c */
int mlxsw_sp_mall_replace(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_cls_matchall_offload *f, bool ingress);
void mlxsw_sp_mall_destroy(struct mlxsw_sp_port *mlxsw_sp_port,
int mlxsw_sp_mall_replace(struct mlxsw_sp_flow_block *block,
struct tc_cls_matchall_offload *f);
void mlxsw_sp_mall_destroy(struct mlxsw_sp_flow_block *block,
struct tc_cls_matchall_offload *f);
int mlxsw_sp_mall_port_bind(struct mlxsw_sp_flow_block *block,
struct mlxsw_sp_port *mlxsw_sp_port);
void mlxsw_sp_mall_port_unbind(struct mlxsw_sp_flow_block *block,
struct mlxsw_sp_port *mlxsw_sp_port);

/* spectrum_flower.c */
int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
Expand Down
17 changes: 15 additions & 2 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mlxsw_sp_flow_block_create(struct mlxsw_sp *mlxsw_sp, struct net *net)
if (!block)
return NULL;
INIT_LIST_HEAD(&block->binding_list);
INIT_LIST_HEAD(&block->mall_list);
block->mlxsw_sp = mlxsw_sp;
block->net = net;
return block;
Expand Down Expand Up @@ -70,9 +71,15 @@ int mlxsw_sp_flow_block_bind(struct mlxsw_sp *mlxsw_sp,
return -EOPNOTSUPP;
}

err = mlxsw_sp_mall_port_bind(block, mlxsw_sp_port);
if (err)
return err;

binding = kzalloc(sizeof(*binding), GFP_KERNEL);
if (!binding)
return -ENOMEM;
if (!binding) {
err = -ENOMEM;
goto err_binding_alloc;
}
binding->mlxsw_sp_port = mlxsw_sp_port;
binding->ingress = ingress;

Expand All @@ -91,6 +98,9 @@ int mlxsw_sp_flow_block_bind(struct mlxsw_sp *mlxsw_sp,

err_ruleset_bind:
kfree(binding);
err_binding_alloc:
mlxsw_sp_mall_port_unbind(block, mlxsw_sp_port);

return err;
}

Expand All @@ -116,5 +126,8 @@ int mlxsw_sp_flow_block_unbind(struct mlxsw_sp *mlxsw_sp,
mlxsw_sp_acl_ruleset_unbind(mlxsw_sp, block, binding);

kfree(binding);

mlxsw_sp_mall_port_unbind(block, mlxsw_sp_port);

return 0;
}
Loading

0 comments on commit 3c65013

Please sign in to comment.