1 From foo@baz Mon Mar 27 18:18:08 CEST 2017
2 From: Or Gerlitz <ogerlitz@mellanox.com>
3 Date: Tue, 21 Mar 2017 15:59:13 +0200
4 Subject: net/mlx5e: Change the TC offload rule add/del code path to be per NIC or E-Switch
6 From: Or Gerlitz <ogerlitz@mellanox.com>
9 [ Upstream commit d85cdccbb3fe9a632ec9d0f4e4526c8c84fc3523 ]
11 Refactor the code to deal with add/del TC rules to have handler per NIC/E-switch
12 offloading use case, and push the latter into the e-switch code. This provides
13 better separation and is to be used in down-stream patch for applying a fix.
15 Fixes: bffaa916588e ("net/mlx5: E-Switch, Add control for inline mode")
16 Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
17 Reviewed-by: Roi Dayan <roid@mellanox.com>
18 Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 57 ++++++++-----
23 drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 5 +
24 drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 14 +++
25 3 files changed, 58 insertions(+), 18 deletions(-)
27 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
28 +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
29 @@ -128,6 +128,23 @@ err_create_ft:
33 +static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv,
34 + struct mlx5e_tc_flow *flow)
36 + struct mlx5_fc *counter = NULL;
38 + if (!IS_ERR(flow->rule)) {
39 + counter = mlx5_flow_rule_counter(flow->rule);
40 + mlx5_del_flow_rules(flow->rule);
41 + mlx5_fc_destroy(priv->mdev, counter);
44 + if (!mlx5e_tc_num_filters(priv) && (priv->fs.tc.t)) {
45 + mlx5_destroy_flow_table(priv->fs.tc.t);
46 + priv->fs.tc.t = NULL;
50 static struct mlx5_flow_handle *
51 mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
52 struct mlx5_flow_spec *spec,
53 @@ -144,7 +161,24 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv
56 static void mlx5e_detach_encap(struct mlx5e_priv *priv,
57 - struct mlx5e_tc_flow *flow) {
58 + struct mlx5e_tc_flow *flow);
60 +static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
61 + struct mlx5e_tc_flow *flow)
63 + struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
65 + mlx5_eswitch_del_offloaded_rule(esw, flow->rule, flow->attr);
67 + mlx5_eswitch_del_vlan_action(esw, flow->attr);
69 + if (flow->attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)
70 + mlx5e_detach_encap(priv, flow);
73 +static void mlx5e_detach_encap(struct mlx5e_priv *priv,
74 + struct mlx5e_tc_flow *flow)
76 struct list_head *next = flow->encap.next;
78 list_del(&flow->encap);
79 @@ -169,24 +203,11 @@ static void mlx5e_tc_del_flow(struct mlx
80 struct mlx5e_tc_flow *flow)
82 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
83 - struct mlx5_fc *counter = NULL;
85 - if (!IS_ERR(flow->rule)) {
86 - counter = mlx5_flow_rule_counter(flow->rule);
87 - mlx5_del_flow_rules(flow->rule);
88 - mlx5_fc_destroy(priv->mdev, counter);
91 - if (esw && esw->mode == SRIOV_OFFLOADS) {
92 - mlx5_eswitch_del_vlan_action(esw, flow->attr);
93 - if (flow->attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)
94 - mlx5e_detach_encap(priv, flow);
97 - if (!mlx5e_tc_num_filters(priv) && (priv->fs.tc.t)) {
98 - mlx5_destroy_flow_table(priv->fs.tc.t);
99 - priv->fs.tc.t = NULL;
101 + if (esw && esw->mode == SRIOV_OFFLOADS)
102 + mlx5e_tc_del_fdb_flow(priv, flow);
104 + mlx5e_tc_del_nic_flow(priv, flow);
107 static void parse_vxlan_attr(struct mlx5_flow_spec *spec,
108 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
109 +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
110 @@ -263,6 +263,11 @@ struct mlx5_flow_handle *
111 mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
112 struct mlx5_flow_spec *spec,
113 struct mlx5_esw_flow_attr *attr);
115 +mlx5_eswitch_del_offloaded_rule(struct mlx5_eswitch *esw,
116 + struct mlx5_flow_handle *rule,
117 + struct mlx5_esw_flow_attr *attr);
119 struct mlx5_flow_handle *
120 mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, int vport, u32 tirn);
122 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
123 +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
124 @@ -97,6 +97,20 @@ mlx5_eswitch_add_offloaded_rule(struct m
129 +mlx5_eswitch_del_offloaded_rule(struct mlx5_eswitch *esw,
130 + struct mlx5_flow_handle *rule,
131 + struct mlx5_esw_flow_attr *attr)
133 + struct mlx5_fc *counter = NULL;
135 + if (!IS_ERR(rule)) {
136 + counter = mlx5_flow_rule_counter(rule);
137 + mlx5_del_flow_rules(rule);
138 + mlx5_fc_destroy(esw->dev, counter);
142 static int esw_set_global_vlan_pop(struct mlx5_eswitch *esw, u8 val)
144 struct mlx5_eswitch_rep *rep;