Skip to content

Commit 53d9489

Browse files
committed
Merge branch 'mlx5-bulk-flow-stats-sriov-tc-offloads'
Saeed Mahameed says: ==================== Mellanox 100G mlx5 Bulk flow statistics and SRIOV TC offloads This series from Amir and Or deals with two enhancements for the mlx5 TC offloads. The 1st two patches add bulk reading of flow counters. Few bulk counter queries are used instead of issuing thousands firmware commands per second to get statistics of all flows set to HW. The next patches add TC based SRIOV offloading to mlx5, as a follow up for the e-switch offloads mode and the VF representors. When the e-switch is set to the (new) "offloads" mode, we can now offload TC/flower drop and forward rules, the forward action we offload is TC mirred/redirect. The above is done by the VF representor netdevices exporting the setup_tc ndo where from there we're re-using and enhancing the existing mlx5 TC offloads sub-module which now works for both the NIC and the SRIOV cases. The series is applied on top b38a75d ('mlxsw: core: Trace EMAD messages') and it has no merge issues with the on-going net submission ('mlx5 tx timeout watchdog fixes') V2: - Fixed compilation warning. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 1801772 + d957b4e commit 53d9489

13 files changed

Lines changed: 436 additions & 70 deletions

File tree

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
#include <generated/utsrelease.h>
3434
#include <linux/mlx5/fs.h>
3535
#include <net/switchdev.h>
36+
#include <net/pkt_cls.h>
3637

3738
#include "eswitch.h"
3839
#include "en.h"
40+
#include "en_tc.h"
3941

4042
static const char mlx5e_rep_driver_name[] = "mlx5e_rep";
4143

@@ -201,6 +203,10 @@ void mlx5e_nic_rep_unload(struct mlx5_eswitch *esw,
201203

202204
if (test_bit(MLX5E_STATE_OPENED, &priv->state))
203205
mlx5e_remove_sqs_fwd_rules(priv);
206+
207+
/* clean (and re-init) existing uplink offloaded TC rules */
208+
mlx5e_tc_cleanup(priv);
209+
mlx5e_tc_init(priv);
204210
}
205211

206212
static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
@@ -217,6 +223,29 @@ static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
217223
return 0;
218224
}
219225

226+
static int mlx5e_rep_ndo_setup_tc(struct net_device *dev, u32 handle,
227+
__be16 proto, struct tc_to_netdev *tc)
228+
{
229+
struct mlx5e_priv *priv = netdev_priv(dev);
230+
231+
if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
232+
return -EOPNOTSUPP;
233+
234+
switch (tc->type) {
235+
case TC_SETUP_CLSFLOWER:
236+
switch (tc->cls_flower->command) {
237+
case TC_CLSFLOWER_REPLACE:
238+
return mlx5e_configure_flower(priv, proto, tc->cls_flower);
239+
case TC_CLSFLOWER_DESTROY:
240+
return mlx5e_delete_flower(priv, tc->cls_flower);
241+
case TC_CLSFLOWER_STATS:
242+
return mlx5e_stats_flower(priv, tc->cls_flower);
243+
}
244+
default:
245+
return -EOPNOTSUPP;
246+
}
247+
}
248+
220249
static const struct switchdev_ops mlx5e_rep_switchdev_ops = {
221250
.switchdev_port_attr_get = mlx5e_attr_get,
222251
};
@@ -226,6 +255,7 @@ static const struct net_device_ops mlx5e_netdev_ops_rep = {
226255
.ndo_stop = mlx5e_close,
227256
.ndo_start_xmit = mlx5e_xmit,
228257
.ndo_get_phys_port_name = mlx5e_rep_get_phys_port_name,
258+
.ndo_setup_tc = mlx5e_rep_ndo_setup_tc,
229259
.ndo_get_stats64 = mlx5e_get_stats,
230260
};
231261

@@ -279,7 +309,8 @@ static void mlx5e_build_rep_netdev(struct net_device *netdev)
279309
netdev->switchdev_ops = &mlx5e_rep_switchdev_ops;
280310
#endif
281311

282-
netdev->features |= NETIF_F_VLAN_CHALLENGED;
312+
netdev->features |= NETIF_F_VLAN_CHALLENGED | NETIF_F_HW_TC;
313+
netdev->hw_features |= NETIF_F_HW_TC;
283314

284315
eth_hw_addr_random(netdev);
285316
}
@@ -323,8 +354,14 @@ static int mlx5e_init_rep_rx(struct mlx5e_priv *priv)
323354
}
324355
rep->vport_rx_rule = flow_rule;
325356

357+
err = mlx5e_tc_init(priv);
358+
if (err)
359+
goto err_del_flow_rule;
360+
326361
return 0;
327362

363+
err_del_flow_rule:
364+
mlx5_del_flow_rule(rep->vport_rx_rule);
328365
err_destroy_direct_tirs:
329366
mlx5e_destroy_direct_tirs(priv);
330367
err_destroy_direct_rqts:
@@ -338,6 +375,7 @@ static void mlx5e_cleanup_rep_rx(struct mlx5e_priv *priv)
338375
struct mlx5_eswitch_rep *rep = priv->ppriv;
339376
int i;
340377

378+
mlx5e_tc_cleanup(priv);
341379
mlx5_del_flow_rule(rep->vport_rx_rule);
342380
mlx5e_destroy_direct_tirs(priv);
343381
for (i = 0; i < priv->params.num_channels; i++)

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

Lines changed: 96 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
#include <linux/mlx5/fs.h>
3838
#include <linux/mlx5/device.h>
3939
#include <linux/rhashtable.h>
40+
#include <net/switchdev.h>
41+
#include <net/tc_act/tc_mirred.h>
4042
#include "en.h"
4143
#include "en_tc.h"
44+
#include "eswitch.h"
4245

4346
struct mlx5e_tc_flow {
4447
struct rhash_head node;
@@ -49,9 +52,9 @@ struct mlx5e_tc_flow {
4952
#define MLX5E_TC_TABLE_NUM_ENTRIES 1024
5053
#define MLX5E_TC_TABLE_NUM_GROUPS 4
5154

52-
static struct mlx5_flow_rule *mlx5e_tc_add_flow(struct mlx5e_priv *priv,
53-
struct mlx5_flow_spec *spec,
54-
u32 action, u32 flow_tag)
55+
static struct mlx5_flow_rule *mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
56+
struct mlx5_flow_spec *spec,
57+
u32 action, u32 flow_tag)
5558
{
5659
struct mlx5_core_dev *dev = priv->mdev;
5760
struct mlx5_flow_destination dest = { 0 };
@@ -62,7 +65,7 @@ static struct mlx5_flow_rule *mlx5e_tc_add_flow(struct mlx5e_priv *priv,
6265
if (action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
6366
dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
6467
dest.ft = priv->fs.vlan.ft.t;
65-
} else {
68+
} else if (action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
6669
counter = mlx5_fc_create(dev, true);
6770
if (IS_ERR(counter))
6871
return ERR_CAST(counter);
@@ -109,6 +112,22 @@ static struct mlx5_flow_rule *mlx5e_tc_add_flow(struct mlx5e_priv *priv,
109112
return rule;
110113
}
111114

115+
static struct mlx5_flow_rule *mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
116+
struct mlx5_flow_spec *spec,
117+
u32 action, u32 dst_vport)
118+
{
119+
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
120+
struct mlx5_eswitch_rep *rep = priv->ppriv;
121+
u32 src_vport;
122+
123+
if (rep->vport) /* set source vport for the flow */
124+
src_vport = rep->vport;
125+
else
126+
src_vport = FDB_UPLINK_VPORT;
127+
128+
return mlx5_eswitch_add_offloaded_rule(esw, spec, action, src_vport, dst_vport);
129+
}
130+
112131
static void mlx5e_tc_del_flow(struct mlx5e_priv *priv,
113132
struct mlx5_flow_rule *rule)
114133
{
@@ -120,7 +139,7 @@ static void mlx5e_tc_del_flow(struct mlx5e_priv *priv,
120139

121140
mlx5_fc_destroy(priv->mdev, counter);
122141

123-
if (!mlx5e_tc_num_filters(priv)) {
142+
if (!mlx5e_tc_num_filters(priv) && (priv->fs.tc.t)) {
124143
mlx5_destroy_flow_table(priv->fs.tc.t);
125144
priv->fs.tc.t = NULL;
126145
}
@@ -295,8 +314,8 @@ static int parse_cls_flower(struct mlx5e_priv *priv, struct mlx5_flow_spec *spec
295314
return 0;
296315
}
297316

298-
static int parse_tc_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
299-
u32 *action, u32 *flow_tag)
317+
static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
318+
u32 *action, u32 *flow_tag)
300319
{
301320
const struct tc_action *a;
302321

@@ -339,16 +358,66 @@ static int parse_tc_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
339358
return 0;
340359
}
341360

361+
static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
362+
u32 *action, u32 *dest_vport)
363+
{
364+
const struct tc_action *a;
365+
366+
if (tc_no_actions(exts))
367+
return -EINVAL;
368+
369+
*action = 0;
370+
371+
tc_for_each_action(a, exts) {
372+
/* Only support a single action per rule */
373+
if (*action)
374+
return -EINVAL;
375+
376+
if (is_tcf_gact_shot(a)) {
377+
*action = MLX5_FLOW_CONTEXT_ACTION_DROP |
378+
MLX5_FLOW_CONTEXT_ACTION_COUNT;
379+
continue;
380+
}
381+
382+
if (is_tcf_mirred_redirect(a)) {
383+
int ifindex = tcf_mirred_ifindex(a);
384+
struct net_device *out_dev;
385+
struct mlx5e_priv *out_priv;
386+
struct mlx5_eswitch_rep *out_rep;
387+
388+
out_dev = __dev_get_by_index(dev_net(priv->netdev), ifindex);
389+
390+
if (!switchdev_port_same_parent_id(priv->netdev, out_dev)) {
391+
pr_err("devices %s %s not on same switch HW, can't offload forwarding\n",
392+
priv->netdev->name, out_dev->name);
393+
return -EINVAL;
394+
}
395+
396+
out_priv = netdev_priv(out_dev);
397+
out_rep = out_priv->ppriv;
398+
if (out_rep->vport == 0)
399+
*dest_vport = FDB_UPLINK_VPORT;
400+
else
401+
*dest_vport = out_rep->vport;
402+
*action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
403+
continue;
404+
}
405+
406+
return -EINVAL;
407+
}
408+
return 0;
409+
}
410+
342411
int mlx5e_configure_flower(struct mlx5e_priv *priv, __be16 protocol,
343412
struct tc_cls_flower_offload *f)
344413
{
345414
struct mlx5e_tc_table *tc = &priv->fs.tc;
346415
int err = 0;
347-
u32 flow_tag;
348-
u32 action;
416+
u32 flow_tag, action, dest_vport = 0;
349417
struct mlx5e_tc_flow *flow;
350418
struct mlx5_flow_spec *spec;
351419
struct mlx5_flow_rule *old = NULL;
420+
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
352421

353422
flow = rhashtable_lookup_fast(&tc->ht, &f->cookie,
354423
tc->ht_params);
@@ -369,28 +438,35 @@ int mlx5e_configure_flower(struct mlx5e_priv *priv, __be16 protocol,
369438
if (err < 0)
370439
goto err_free;
371440

372-
err = parse_tc_actions(priv, f->exts, &action, &flow_tag);
373-
if (err < 0)
441+
if (esw && esw->mode == SRIOV_OFFLOADS) {
442+
err = parse_tc_fdb_actions(priv, f->exts, &action, &dest_vport);
443+
if (err < 0)
444+
goto err_free;
445+
flow->rule = mlx5e_tc_add_fdb_flow(priv, spec, action, dest_vport);
446+
} else {
447+
err = parse_tc_nic_actions(priv, f->exts, &action, &flow_tag);
448+
if (err < 0)
449+
goto err_free;
450+
flow->rule = mlx5e_tc_add_nic_flow(priv, spec, action, flow_tag);
451+
}
452+
453+
if (IS_ERR(flow->rule)) {
454+
err = PTR_ERR(flow->rule);
374455
goto err_free;
456+
}
375457

376458
err = rhashtable_insert_fast(&tc->ht, &flow->node,
377459
tc->ht_params);
378460
if (err)
379-
goto err_free;
380-
381-
flow->rule = mlx5e_tc_add_flow(priv, spec, action, flow_tag);
382-
if (IS_ERR(flow->rule)) {
383-
err = PTR_ERR(flow->rule);
384-
goto err_hash_del;
385-
}
461+
goto err_del_rule;
386462

387463
if (old)
388464
mlx5e_tc_del_flow(priv, old);
389465

390466
goto out;
391467

392-
err_hash_del:
393-
rhashtable_remove_fast(&tc->ht, &flow->node, tc->ht_params);
468+
err_del_rule:
469+
mlx5_del_flow_rule(flow->rule);
394470

395471
err_free:
396472
if (!old)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ struct mlx5_eswitch_fdb {
145145
} legacy;
146146

147147
struct offloads_fdb {
148+
struct mlx5_flow_table *fdb;
148149
struct mlx5_flow_group *send_to_vport_grp;
149150
struct mlx5_flow_group *miss_grp;
150151
struct mlx5_flow_rule *miss_rule;
@@ -221,6 +222,12 @@ int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw,
221222
int vport,
222223
struct ifla_vf_stats *vf_stats);
223224

225+
struct mlx5_flow_spec;
226+
227+
struct mlx5_flow_rule *
228+
mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
229+
struct mlx5_flow_spec *spec,
230+
u32 action, u32 src_vport, u32 dst_vport);
224231
struct mlx5_flow_rule *
225232
mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, int vport, u32 tirn);
226233

0 commit comments

Comments
 (0)