Skip to content

Commit 74491de

Browse files
mark-blochrleon
authored andcommitted
net/mlx5: Add multi dest support
Currently when calling mlx5_add_flow_rule we accept only one flow destination, this commit allows to pass multiple destinations. This change forces us to change the return structure to a more flexible one. We introduce a flow handle (struct mlx5_flow_handle), it holds internally the number for rules created and holds an array where each cell points the to a flow rule. From the consumers (of mlx5_add_flow_rule) point of view this change is only cosmetic and requires only to change the type of the returned value they store. From the core point of view, we now need to use a loop when allocating and deleting rules (e.g given to us a flow handler). Signed-off-by: Mark Bloch <markb@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent a622498 commit 74491de

File tree

14 files changed

+374
-254
lines changed

14 files changed

+374
-254
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,13 +1771,13 @@ static int mlx5_ib_destroy_flow(struct ib_flow *flow_id)
17711771
mutex_lock(&dev->flow_db.lock);
17721772

17731773
list_for_each_entry_safe(iter, tmp, &handler->list, list) {
1774-
mlx5_del_flow_rule(iter->rule);
1774+
mlx5_del_flow_rules(iter->rule);
17751775
put_flow_table(dev, iter->prio, true);
17761776
list_del(&iter->list);
17771777
kfree(iter);
17781778
}
17791779

1780-
mlx5_del_flow_rule(handler->rule);
1780+
mlx5_del_flow_rules(handler->rule);
17811781
put_flow_table(dev, handler->prio, true);
17821782
mutex_unlock(&dev->flow_db.lock);
17831783

@@ -1907,10 +1907,10 @@ static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev,
19071907
spec->match_criteria_enable = get_match_criteria_enable(spec->match_criteria);
19081908
action = dst ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST :
19091909
MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO;
1910-
handler->rule = mlx5_add_flow_rule(ft, spec,
1910+
handler->rule = mlx5_add_flow_rules(ft, spec,
19111911
action,
19121912
MLX5_FS_DEFAULT_FLOW_TAG,
1913-
dst);
1913+
dst, 1);
19141914

19151915
if (IS_ERR(handler->rule)) {
19161916
err = PTR_ERR(handler->rule);
@@ -1941,7 +1941,7 @@ static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *de
19411941
handler_dst = create_flow_rule(dev, ft_prio,
19421942
flow_attr, dst);
19431943
if (IS_ERR(handler_dst)) {
1944-
mlx5_del_flow_rule(handler->rule);
1944+
mlx5_del_flow_rules(handler->rule);
19451945
ft_prio->refcount--;
19461946
kfree(handler);
19471947
handler = handler_dst;
@@ -2004,7 +2004,7 @@ static struct mlx5_ib_flow_handler *create_leftovers_rule(struct mlx5_ib_dev *de
20042004
&leftovers_specs[LEFTOVERS_UC].flow_attr,
20052005
dst);
20062006
if (IS_ERR(handler_ucast)) {
2007-
mlx5_del_flow_rule(handler->rule);
2007+
mlx5_del_flow_rules(handler->rule);
20082008
ft_prio->refcount--;
20092009
kfree(handler);
20102010
handler = handler_ucast;
@@ -2046,7 +2046,7 @@ static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev,
20462046
return handler_rx;
20472047

20482048
err_tx:
2049-
mlx5_del_flow_rule(handler_rx->rule);
2049+
mlx5_del_flow_rules(handler_rx->rule);
20502050
ft_rx->refcount--;
20512051
kfree(handler_rx);
20522052
err:

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ struct mlx5_ib_flow_handler {
153153
struct list_head list;
154154
struct ib_flow ibflow;
155155
struct mlx5_ib_flow_prio *prio;
156-
struct mlx5_flow_rule *rule;
156+
struct mlx5_flow_handle *rule;
157157
};
158158

159159
struct mlx5_ib_flow_db {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ struct mlx5e_vxlan_db {
520520

521521
struct mlx5e_l2_rule {
522522
u8 addr[ETH_ALEN + 2];
523-
struct mlx5_flow_rule *rule;
523+
struct mlx5_flow_handle *rule;
524524
};
525525

526526
struct mlx5e_flow_table {
@@ -541,10 +541,10 @@ struct mlx5e_tc_table {
541541
struct mlx5e_vlan_table {
542542
struct mlx5e_flow_table ft;
543543
unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
544-
struct mlx5_flow_rule *active_vlans_rule[VLAN_N_VID];
545-
struct mlx5_flow_rule *untagged_rule;
546-
struct mlx5_flow_rule *any_vlan_rule;
547-
bool filter_disabled;
544+
struct mlx5_flow_handle *active_vlans_rule[VLAN_N_VID];
545+
struct mlx5_flow_handle *untagged_rule;
546+
struct mlx5_flow_handle *any_vlan_rule;
547+
bool filter_disabled;
548548
};
549549

550550
struct mlx5e_l2_table {
@@ -562,14 +562,14 @@ struct mlx5e_l2_table {
562562
/* L3/L4 traffic type classifier */
563563
struct mlx5e_ttc_table {
564564
struct mlx5e_flow_table ft;
565-
struct mlx5_flow_rule *rules[MLX5E_NUM_TT];
565+
struct mlx5_flow_handle *rules[MLX5E_NUM_TT];
566566
};
567567

568568
#define ARFS_HASH_SHIFT BITS_PER_BYTE
569569
#define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
570570
struct arfs_table {
571571
struct mlx5e_flow_table ft;
572-
struct mlx5_flow_rule *default_rule;
572+
struct mlx5_flow_handle *default_rule;
573573
struct hlist_head rules_hash[ARFS_HASH_SIZE];
574574
};
575575

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct arfs_tuple {
5656
struct arfs_rule {
5757
struct mlx5e_priv *priv;
5858
struct work_struct arfs_work;
59-
struct mlx5_flow_rule *rule;
59+
struct mlx5_flow_handle *rule;
6060
struct hlist_node hlist;
6161
int rxq;
6262
/* Flow ID passed to ndo_rx_flow_steer */
@@ -104,7 +104,7 @@ static int arfs_disable(struct mlx5e_priv *priv)
104104
tt = arfs_get_tt(i);
105105
/* Modify ttc rules destination to bypass the aRFS tables*/
106106
err = mlx5_modify_rule_destination(priv->fs.ttc.rules[tt],
107-
&dest);
107+
&dest, NULL);
108108
if (err) {
109109
netdev_err(priv->netdev,
110110
"%s: modify ttc destination failed\n",
@@ -137,7 +137,7 @@ int mlx5e_arfs_enable(struct mlx5e_priv *priv)
137137
tt = arfs_get_tt(i);
138138
/* Modify ttc rules destination to point on the aRFS FTs */
139139
err = mlx5_modify_rule_destination(priv->fs.ttc.rules[tt],
140-
&dest);
140+
&dest, NULL);
141141
if (err) {
142142
netdev_err(priv->netdev,
143143
"%s: modify ttc destination failed err=%d\n",
@@ -151,7 +151,7 @@ int mlx5e_arfs_enable(struct mlx5e_priv *priv)
151151

152152
static void arfs_destroy_table(struct arfs_table *arfs_t)
153153
{
154-
mlx5_del_flow_rule(arfs_t->default_rule);
154+
mlx5_del_flow_rules(arfs_t->default_rule);
155155
mlx5e_destroy_flow_table(&arfs_t->ft);
156156
}
157157

@@ -205,10 +205,10 @@ static int arfs_add_default_rule(struct mlx5e_priv *priv,
205205
goto out;
206206
}
207207

208-
arfs_t->default_rule = mlx5_add_flow_rule(arfs_t->ft.t, spec,
209-
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
210-
MLX5_FS_DEFAULT_FLOW_TAG,
211-
&dest);
208+
arfs_t->default_rule = mlx5_add_flow_rules(arfs_t->ft.t, spec,
209+
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
210+
MLX5_FS_DEFAULT_FLOW_TAG,
211+
&dest, 1);
212212
if (IS_ERR(arfs_t->default_rule)) {
213213
err = PTR_ERR(arfs_t->default_rule);
214214
arfs_t->default_rule = NULL;
@@ -396,7 +396,7 @@ static void arfs_may_expire_flow(struct mlx5e_priv *priv)
396396
spin_unlock_bh(&priv->fs.arfs.arfs_lock);
397397
hlist_for_each_entry_safe(arfs_rule, htmp, &del_list, hlist) {
398398
if (arfs_rule->rule)
399-
mlx5_del_flow_rule(arfs_rule->rule);
399+
mlx5_del_flow_rules(arfs_rule->rule);
400400
hlist_del(&arfs_rule->hlist);
401401
kfree(arfs_rule);
402402
}
@@ -420,7 +420,7 @@ static void arfs_del_rules(struct mlx5e_priv *priv)
420420
hlist_for_each_entry_safe(rule, htmp, &del_list, hlist) {
421421
cancel_work_sync(&rule->arfs_work);
422422
if (rule->rule)
423-
mlx5_del_flow_rule(rule->rule);
423+
mlx5_del_flow_rules(rule->rule);
424424
hlist_del(&rule->hlist);
425425
kfree(rule);
426426
}
@@ -462,12 +462,12 @@ static struct arfs_table *arfs_get_table(struct mlx5e_arfs_tables *arfs,
462462
return NULL;
463463
}
464464

465-
static struct mlx5_flow_rule *arfs_add_rule(struct mlx5e_priv *priv,
466-
struct arfs_rule *arfs_rule)
465+
static struct mlx5_flow_handle *arfs_add_rule(struct mlx5e_priv *priv,
466+
struct arfs_rule *arfs_rule)
467467
{
468468
struct mlx5e_arfs_tables *arfs = &priv->fs.arfs;
469469
struct arfs_tuple *tuple = &arfs_rule->tuple;
470-
struct mlx5_flow_rule *rule = NULL;
470+
struct mlx5_flow_handle *rule = NULL;
471471
struct mlx5_flow_destination dest;
472472
struct arfs_table *arfs_table;
473473
struct mlx5_flow_spec *spec;
@@ -544,9 +544,9 @@ static struct mlx5_flow_rule *arfs_add_rule(struct mlx5e_priv *priv,
544544
}
545545
dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
546546
dest.tir_num = priv->direct_tir[arfs_rule->rxq].tirn;
547-
rule = mlx5_add_flow_rule(ft, spec, MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
548-
MLX5_FS_DEFAULT_FLOW_TAG,
549-
&dest);
547+
rule = mlx5_add_flow_rules(ft, spec, MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
548+
MLX5_FS_DEFAULT_FLOW_TAG,
549+
&dest, 1);
550550
if (IS_ERR(rule)) {
551551
err = PTR_ERR(rule);
552552
netdev_err(priv->netdev, "%s: add rule(filter id=%d, rq idx=%d) failed, err=%d\n",
@@ -559,14 +559,14 @@ static struct mlx5_flow_rule *arfs_add_rule(struct mlx5e_priv *priv,
559559
}
560560

561561
static void arfs_modify_rule_rq(struct mlx5e_priv *priv,
562-
struct mlx5_flow_rule *rule, u16 rxq)
562+
struct mlx5_flow_handle *rule, u16 rxq)
563563
{
564564
struct mlx5_flow_destination dst;
565565
int err = 0;
566566

567567
dst.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
568568
dst.tir_num = priv->direct_tir[rxq].tirn;
569-
err = mlx5_modify_rule_destination(rule, &dst);
569+
err = mlx5_modify_rule_destination(rule, &dst, NULL);
570570
if (err)
571571
netdev_warn(priv->netdev,
572572
"Failed to modfiy aRFS rule destination to rq=%d\n", rxq);
@@ -578,7 +578,7 @@ static void arfs_handle_work(struct work_struct *work)
578578
struct arfs_rule,
579579
arfs_work);
580580
struct mlx5e_priv *priv = arfs_rule->priv;
581-
struct mlx5_flow_rule *rule;
581+
struct mlx5_flow_handle *rule;
582582

583583
mutex_lock(&priv->state_lock);
584584
if (!test_bit(MLX5E_STATE_OPENED, &priv->state)) {

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static int __mlx5e_add_vlan_rule(struct mlx5e_priv *priv,
160160
{
161161
struct mlx5_flow_table *ft = priv->fs.vlan.ft.t;
162162
struct mlx5_flow_destination dest;
163-
struct mlx5_flow_rule **rule_p;
163+
struct mlx5_flow_handle **rule_p;
164164
int err = 0;
165165

166166
dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
@@ -187,10 +187,10 @@ static int __mlx5e_add_vlan_rule(struct mlx5e_priv *priv,
187187
break;
188188
}
189189

190-
*rule_p = mlx5_add_flow_rule(ft, spec,
191-
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
192-
MLX5_FS_DEFAULT_FLOW_TAG,
193-
&dest);
190+
*rule_p = mlx5_add_flow_rules(ft, spec,
191+
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
192+
MLX5_FS_DEFAULT_FLOW_TAG,
193+
&dest, 1);
194194

195195
if (IS_ERR(*rule_p)) {
196196
err = PTR_ERR(*rule_p);
@@ -229,20 +229,20 @@ static void mlx5e_del_vlan_rule(struct mlx5e_priv *priv,
229229
switch (rule_type) {
230230
case MLX5E_VLAN_RULE_TYPE_UNTAGGED:
231231
if (priv->fs.vlan.untagged_rule) {
232-
mlx5_del_flow_rule(priv->fs.vlan.untagged_rule);
232+
mlx5_del_flow_rules(priv->fs.vlan.untagged_rule);
233233
priv->fs.vlan.untagged_rule = NULL;
234234
}
235235
break;
236236
case MLX5E_VLAN_RULE_TYPE_ANY_VID:
237237
if (priv->fs.vlan.any_vlan_rule) {
238-
mlx5_del_flow_rule(priv->fs.vlan.any_vlan_rule);
238+
mlx5_del_flow_rules(priv->fs.vlan.any_vlan_rule);
239239
priv->fs.vlan.any_vlan_rule = NULL;
240240
}
241241
break;
242242
case MLX5E_VLAN_RULE_TYPE_MATCH_VID:
243243
mlx5e_vport_context_update_vlans(priv);
244244
if (priv->fs.vlan.active_vlans_rule[vid]) {
245-
mlx5_del_flow_rule(priv->fs.vlan.active_vlans_rule[vid]);
245+
mlx5_del_flow_rules(priv->fs.vlan.active_vlans_rule[vid]);
246246
priv->fs.vlan.active_vlans_rule[vid] = NULL;
247247
}
248248
mlx5e_vport_context_update_vlans(priv);
@@ -560,7 +560,7 @@ static void mlx5e_cleanup_ttc_rules(struct mlx5e_ttc_table *ttc)
560560

561561
for (i = 0; i < MLX5E_NUM_TT; i++) {
562562
if (!IS_ERR_OR_NULL(ttc->rules[i])) {
563-
mlx5_del_flow_rule(ttc->rules[i]);
563+
mlx5_del_flow_rules(ttc->rules[i]);
564564
ttc->rules[i] = NULL;
565565
}
566566
}
@@ -616,13 +616,14 @@ static struct {
616616
},
617617
};
618618

619-
static struct mlx5_flow_rule *mlx5e_generate_ttc_rule(struct mlx5e_priv *priv,
620-
struct mlx5_flow_table *ft,
621-
struct mlx5_flow_destination *dest,
622-
u16 etype,
623-
u8 proto)
619+
static struct mlx5_flow_handle *
620+
mlx5e_generate_ttc_rule(struct mlx5e_priv *priv,
621+
struct mlx5_flow_table *ft,
622+
struct mlx5_flow_destination *dest,
623+
u16 etype,
624+
u8 proto)
624625
{
625-
struct mlx5_flow_rule *rule;
626+
struct mlx5_flow_handle *rule;
626627
struct mlx5_flow_spec *spec;
627628
int err = 0;
628629

@@ -643,10 +644,10 @@ static struct mlx5_flow_rule *mlx5e_generate_ttc_rule(struct mlx5e_priv *priv,
643644
MLX5_SET(fte_match_param, spec->match_value, outer_headers.ethertype, etype);
644645
}
645646

646-
rule = mlx5_add_flow_rule(ft, spec,
647-
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
648-
MLX5_FS_DEFAULT_FLOW_TAG,
649-
dest);
647+
rule = mlx5_add_flow_rules(ft, spec,
648+
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
649+
MLX5_FS_DEFAULT_FLOW_TAG,
650+
dest, 1);
650651
if (IS_ERR(rule)) {
651652
err = PTR_ERR(rule);
652653
netdev_err(priv->netdev, "%s: add rule failed\n", __func__);
@@ -660,7 +661,7 @@ static int mlx5e_generate_ttc_table_rules(struct mlx5e_priv *priv)
660661
{
661662
struct mlx5_flow_destination dest;
662663
struct mlx5e_ttc_table *ttc;
663-
struct mlx5_flow_rule **rules;
664+
struct mlx5_flow_handle **rules;
664665
struct mlx5_flow_table *ft;
665666
int tt;
666667
int err;
@@ -801,7 +802,7 @@ static void mlx5e_del_l2_flow_rule(struct mlx5e_priv *priv,
801802
struct mlx5e_l2_rule *ai)
802803
{
803804
if (!IS_ERR_OR_NULL(ai->rule)) {
804-
mlx5_del_flow_rule(ai->rule);
805+
mlx5_del_flow_rules(ai->rule);
805806
ai->rule = NULL;
806807
}
807808
}
@@ -847,9 +848,9 @@ static int mlx5e_add_l2_flow_rule(struct mlx5e_priv *priv,
847848
break;
848849
}
849850

850-
ai->rule = mlx5_add_flow_rule(ft, spec,
851-
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
852-
MLX5_FS_DEFAULT_FLOW_TAG, &dest);
851+
ai->rule = mlx5_add_flow_rules(ft, spec,
852+
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
853+
MLX5_FS_DEFAULT_FLOW_TAG, &dest, 1);
853854
if (IS_ERR(ai->rule)) {
854855
netdev_err(priv->netdev, "%s: add l2 rule(mac:%pM) failed\n",
855856
__func__, mv_dmac);

0 commit comments

Comments
 (0)