History

net/mlx5: Add flow steering actions to fs_cmd shim layer

Add flow steering actions: modify header and packet reformat to the fs_cmd shim layer. This allows each namespace to define possibly different functionality for alloc/dealloc action commands.

Maor Gottlieb committed 7 years ago

Commit 2b688ea1 parent a06ebb813 files · +289 −110Browse files

Unified · Split

13 files
  1. drivers/infiniband/hw/mlx5/flow.c +12 −9
  2. drivers/infiniband/hw/mlx5/main.c +4 −3
  3. drivers/infiniband/hw/mlx5/mlx5_ib.h +4 −1
  4. drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +14 −13
  5. drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +1 −1
  6. drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +22 −24
  7. drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +3 −3
  8. drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +14 −12
  9. drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c +66 −26
  10. drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.h +18 −0
  11. drivers/net/ethernet/mellanox/mlx5/core/fs_core.c +104 −1
  12. drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +11 −0
  13. include/linux/mlx5/fs.h +16 −17
drivers/infiniband/hw/mlx5/flow.c+12−9
@@ -322,11 +322,11 @@ void mlx5_ib_destroy_flow_action_raw(struct mlx5_ib_flow_action *maction) · 321 unmodified lines
322322 switch (maction->flow_action_raw.sub_type) {
323323 case MLX5_IB_FLOW_ACTION_MODIFY_HEADER:
324324 mlx5_modify_header_dealloc(maction->flow_action_raw.dev->mdev,
325− maction->flow_action_raw.action_id);
325+ maction->flow_action_raw.modify_hdr);
326326 break;
327327 case MLX5_IB_FLOW_ACTION_PACKET_REFORMAT:
328328 mlx5_packet_reformat_dealloc(maction->flow_action_raw.dev->mdev,
329− maction->flow_action_raw.action_id);
329+ maction->flow_action_raw.pkt_reformat);
330330 break;
331331 case MLX5_IB_FLOW_ACTION_DECAP:
332332 break;
@@ -352,10 +352,11 @@ mlx5_ib_create_modify_header(struct mlx5_ib_dev *dev, · 19 unmodified lines
352352 if (!maction)
353353 return ERR_PTR(-ENOMEM);
354354
355− ret = mlx5_modify_header_alloc(dev->mdev, namespace, num_actions, in,
356− &maction->flow_action_raw.action_id);
355+ maction->flow_action_raw.modify_hdr =
356+ mlx5_modify_header_alloc(dev->mdev, namespace, num_actions, in);
357357
358− if (ret) {
358+ if (IS_ERR(maction->flow_action_raw.modify_hdr)) {
359+ ret = PTR_ERR(maction->flow_action_raw.modify_hdr);
359360 kfree(maction);
360361 return ERR_PTR(ret);
361362 }
@@ -479,11 +480,13 @@ static int mlx5_ib_flow_action_create_packet_reformat_ctx( · 117 unmodified lines
479480 if (ret)
480481 return ret;
481482
482− ret = mlx5_packet_reformat_alloc(dev->mdev, prm_prt, len,
483− in, namespace,
484− &maction->flow_action_raw.action_id);
485− if (ret)
483+ maction->flow_action_raw.pkt_reformat =
484+ mlx5_packet_reformat_alloc(dev->mdev, prm_prt, len,
485+ in, namespace);
486+ if (IS_ERR(maction->flow_action_raw.pkt_reformat)) {
487+ ret = PTR_ERR(maction->flow_action_raw.pkt_reformat);
486488 return ret;
489+ }
487490
488491 maction->flow_action_raw.sub_type =
489492 MLX5_IB_FLOW_ACTION_PACKET_REFORMAT;
drivers/infiniband/hw/mlx5/main.c+4−3
@@ -2658,7 +2658,8 @@ int parse_flow_flow_action(struct mlx5_ib_flow_action *maction, · 2657 unmodified lines
26582658 if (action->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
26592659 return -EINVAL;
26602660 action->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
2661− action->modify_id = maction->flow_action_raw.action_id;
2661+ action->modify_hdr =
2662+ maction->flow_action_raw.modify_hdr;
26622663 return 0;
26632664 }
26642665 if (maction->flow_action_raw.sub_type ==
@@ -2675,8 +2676,8 @@ int parse_flow_flow_action(struct mlx5_ib_flow_action *maction, · 10 unmodified lines
26752676 return -EINVAL;
26762677 action->action |=
26772678 MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
2678− action->reformat_id =
2679− maction->flow_action_raw.action_id;
2679+ action->pkt_reformat =
2680+ maction->flow_action_raw.pkt_reformat;
26802681 return 0;
26812682 }
26822683 /* fall through */
drivers/infiniband/hw/mlx5/mlx5_ib.h+4−1
@@ -868,7 +868,10 @@ struct mlx5_ib_flow_action { · 867 unmodified lines
868868 struct {
869869 struct mlx5_ib_dev *dev;
870870 u32 sub_type;
871− u32 action_id;
871+ union {
872+ struct mlx5_modify_hdr *modify_hdr;
873+ struct mlx5_pkt_reformat *pkt_reformat;
874+ };
872875 } flow_action_raw;
873876 };
874877 };
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c+14−13
@@ -291,14 +291,14 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, · 290 unmodified lines
291291 */
292292 goto out;
293293 }
294−
295− err = mlx5_packet_reformat_alloc(priv->mdev,
296− e->reformat_type,
297− ipv4_encap_size, encap_header,
298− MLX5_FLOW_NAMESPACE_FDB,
299− &e->encap_id);
300− if (err)
294+ e->pkt_reformat = mlx5_packet_reformat_alloc(priv->mdev,
295+ e->reformat_type,
296+ ipv4_encap_size, encap_header,
297+ MLX5_FLOW_NAMESPACE_FDB);
298+ if (IS_ERR(e->pkt_reformat)) {
299+ err = PTR_ERR(e->pkt_reformat);
301300 goto destroy_neigh_entry;
301+ }
302302
303303 e->flags |= MLX5_ENCAP_ENTRY_VALID;
304304 mlx5e_rep_queue_neigh_stats_work(netdev_priv(out_dev));
@@ -407,13 +407,14 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, · 102 unmodified lines
407407 goto out;
408408 }
409409
410− err = mlx5_packet_reformat_alloc(priv->mdev,
411− e->reformat_type,
412− ipv6_encap_size, encap_header,
413− MLX5_FLOW_NAMESPACE_FDB,
414− &e->encap_id);
415− if (err)
410+ e->pkt_reformat = mlx5_packet_reformat_alloc(priv->mdev,
411+ e->reformat_type,
412+ ipv6_encap_size, encap_header,
413+ MLX5_FLOW_NAMESPACE_FDB);
414+ if (IS_ERR(e->pkt_reformat)) {
415+ err = PTR_ERR(e->pkt_reformat);
416416 goto destroy_neigh_entry;
417+ }
417418
418419 e->flags |= MLX5_ENCAP_ENTRY_VALID;
419420 mlx5e_rep_queue_neigh_stats_work(netdev_priv(out_dev));
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h+1−1
@@ -161,7 +161,7 @@ struct mlx5e_encap_entry { · 160 unmodified lines
161161 */
162162 struct hlist_node encap_hlist;
163163 struct list_head flows;
164− u32 encap_id;
164+ struct mlx5_pkt_reformat *pkt_reformat;
165165 const struct ip_tunnel_info *tun_info;
166166 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
167167
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c+22−24
@@ -61,7 +61,7 @@ · 60 unmodified lines
6161 struct mlx5_nic_flow_attr {
6262 u32 action;
6363 u32 flow_tag;
64− u32 mod_hdr_id;
64+ struct mlx5_modify_hdr *modify_hdr;
6565 u32 hairpin_tirn;
6666 u8 match_level;
6767 struct mlx5_flow_table *hairpin_ft;
@@ -201,7 +201,7 @@ struct mlx5e_mod_hdr_entry { · 133 unmodified lines
201201
202202 struct mod_hdr_key key;
203203
204− u32 mod_hdr_id;
204+ struct mlx5_modify_hdr *modify_hdr;
205205
206206 refcount_t refcnt;
207207 struct completion res_ready;
@@ -334,7 +334,7 @@ static void mlx5e_mod_hdr_put(struct mlx5e_priv *priv, · 126 unmodified lines
334334
335335 WARN_ON(!list_empty(&mh->flows));
336336 if (mh->compl_result > 0)
337− mlx5_modify_header_dealloc(priv->mdev, mh->mod_hdr_id);
337+ mlx5_modify_header_dealloc(priv->mdev, mh->modify_hdr);
338338
339339 kfree(mh);
340340 }
@@ -395,11 +395,11 @@ static int mlx5e_attach_mod_hdr(struct mlx5e_priv *priv, · 54 unmodified lines
395395 hash_add(tbl->hlist, &mh->mod_hdr_hlist, hash_key);
396396 mutex_unlock(&tbl->lock);
397397
398− err = mlx5_modify_header_alloc(priv->mdev, namespace,
399− mh->key.num_actions,
400− mh->key.actions,
401− &mh->mod_hdr_id);
402− if (err) {
398+ mh->modify_hdr = mlx5_modify_header_alloc(priv->mdev, namespace,
399+ mh->key.num_actions,
400+ mh->key.actions);
401+ if (IS_ERR(mh->modify_hdr)) {
402+ err = PTR_ERR(mh->modify_hdr);
403403 mh->compl_result = err;
404404 goto alloc_header_err;
405405 }
@@ -412,9 +412,9 @@ attach_flow: · 6 unmodified lines
412412 list_add(&flow->mod_hdr, &mh->flows);
413413 spin_unlock(&mh->flows_lock);
414414 if (mlx5e_is_eswitch_flow(flow))
415− flow->esw_attr->mod_hdr_id = mh->mod_hdr_id;
415+ flow->esw_attr->modify_hdr = mh->modify_hdr;
416416 else
417− flow->nic_attr->mod_hdr_id = mh->mod_hdr_id;
417+ flow->nic_attr->modify_hdr = mh->modify_hdr;
418418
419419 return 0;
420420
@@ -906,7 +906,6 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv, · 485 unmodified lines
906906 struct mlx5_flow_destination dest[2] = {};
907907 struct mlx5_flow_act flow_act = {
908908 .action = attr->action,
909− .reformat_id = 0,
910909 .flags = FLOW_ACT_NO_APPEND,
911910 };
912911 struct mlx5_fc *counter = NULL;
@@ -947,7 +946,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv, · 34 unmodified lines
947946
948947 if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) {
949948 err = mlx5e_attach_mod_hdr(priv, flow, parse_attr);
950− flow_act.modify_id = attr->mod_hdr_id;
949+ flow_act.modify_hdr = attr->modify_hdr;
951950 kfree(parse_attr->mod_hdr_actions);
952951 if (err)
953952 return err;
@@ -1304,14 +1303,13 @@ void mlx5e_tc_encap_flows_add(struct mlx5e_priv *priv, · 350 unmodified lines
13041303 struct mlx5e_tc_flow *flow;
13051304 int err;
13061305
1307− err = mlx5_packet_reformat_alloc(priv->mdev,
1308− e->reformat_type,
1309− e->encap_size, e->encap_header,
1310− MLX5_FLOW_NAMESPACE_FDB,
1311− &e->encap_id);
1312− if (err) {
1313− mlx5_core_warn(priv->mdev, "Failed to offload cached encapsulation header, %d\n",
1314− err);
1306+ e->pkt_reformat = mlx5_packet_reformat_alloc(priv->mdev,
1307+ e->reformat_type,
1308+ e->encap_size, e->encap_header,
1309+ MLX5_FLOW_NAMESPACE_FDB);
1310+ if (IS_ERR(e->pkt_reformat)) {
1311+ mlx5_core_warn(priv->mdev, "Failed to offload cached encapsulation header, %lu\n",
1312+ PTR_ERR(e->pkt_reformat));
13151313 return;
13161314 }
13171315 e->flags |= MLX5_ENCAP_ENTRY_VALID;
@@ -1326,7 +1324,7 @@ void mlx5e_tc_encap_flows_add(struct mlx5e_priv *priv, · 8 unmodified lines
13261324 esw_attr = flow->esw_attr;
13271325 spec = &esw_attr->parse_attr->spec;
13281326
1329− esw_attr->dests[flow->tmp_efi_index].encap_id = e->encap_id;
1327+ esw_attr->dests[flow->tmp_efi_index].pkt_reformat = e->pkt_reformat;
13301328 esw_attr->dests[flow->tmp_efi_index].flags |= MLX5_ESW_DEST_ENCAP_VALID;
13311329 /* Flow can be associated with multiple encap entries.
13321330 * Before offloading the flow verify that all of them have
@@ -1395,7 +1393,7 @@ void mlx5e_tc_encap_flows_del(struct mlx5e_priv *priv, · 62 unmodified lines
13951393
13961394 /* we know that the encap is valid */
13971395 e->flags &= ~MLX5_ENCAP_ENTRY_VALID;
1398− mlx5_packet_reformat_dealloc(priv->mdev, e->encap_id);
1396+ mlx5_packet_reformat_dealloc(priv->mdev, e->pkt_reformat);
13991397 }
14001398
14011399 static struct mlx5_fc *mlx5e_tc_get_counter(struct mlx5e_tc_flow *flow)
@@ -1561,7 +1559,7 @@ static void mlx5e_encap_dealloc(struct mlx5e_priv *priv, struct mlx5e_encap_entr · 159 unmodified lines
15611559 mlx5e_rep_encap_entry_detach(netdev_priv(e->out_dev), e);
15621560
15631561 if (e->flags & MLX5_ENCAP_ENTRY_VALID)
1564− mlx5_packet_reformat_dealloc(priv->mdev, e->encap_id);
1562+ mlx5_packet_reformat_dealloc(priv->mdev, e->pkt_reformat);
15651563 }
15661564
15671565 kfree(e->encap_header);
@@ -3048,7 +3046,7 @@ attach_flow: · 1480 unmodified lines
30483046 flow->encaps[out_index].index = out_index;
30493047 *encap_dev = e->out_dev;
30503048 if (e->flags & MLX5_ENCAP_ENTRY_VALID) {
3051− attr->dests[out_index].encap_id = e->encap_id;
3049+ attr->dests[out_index].pkt_reformat = e->pkt_reformat;
30523050 attr->dests[out_index].flags |= MLX5_ESW_DEST_ENCAP_VALID;
30533051 *encap_valid = true;
30543052 } else {
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h+3−3
@@ -69,7 +69,7 @@ struct vport_ingress { · 68 unmodified lines
6969 struct mlx5_flow_group *allow_spoofchk_only_grp;
7070 struct mlx5_flow_group *allow_untagged_only_grp;
7171 struct mlx5_flow_group *drop_grp;
72− int modify_metadata_id;
72+ struct mlx5_modify_hdr *modify_metadata;
7373 struct mlx5_flow_handle *modify_metadata_rule;
7474 struct mlx5_flow_handle *allow_rule;
7575 struct mlx5_flow_handle *drop_rule;
@@ -385,11 +385,11 @@ struct mlx5_esw_flow_attr { · 309 unmodified lines
385385 struct {
386386 u32 flags;
387387 struct mlx5_eswitch_rep *rep;
388+ struct mlx5_pkt_reformat *pkt_reformat;
388389 struct mlx5_core_dev *mdev;
389− u32 encap_id;
390390 struct mlx5_termtbl_handle *termtbl;
391391 } dests[MLX5_MAX_FLOW_FWD_VPORTS];
392− u32 mod_hdr_id;
392+ struct mlx5_modify_hdr *modify_hdr;
393393 u8 inner_match_level;
394394 u8 outer_match_level;
395395 struct mlx5_fc *counter;
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c+14−12
@@ -190,10 +190,10 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, · 189 unmodified lines
190190 MLX5_FLOW_DEST_VPORT_VHCA_ID;
191191 if (attr->dests[j].flags & MLX5_ESW_DEST_ENCAP) {
192192 flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
193− flow_act.reformat_id = attr->dests[j].encap_id;
193+ flow_act.pkt_reformat = attr->dests[j].pkt_reformat;
194194 dest[i].vport.flags |= MLX5_FLOW_DEST_VPORT_REFORMAT_ID;
195− dest[i].vport.reformat_id =
196− attr->dests[j].encap_id;
195+ dest[i].vport.pkt_reformat =
196+ attr->dests[j].pkt_reformat;
197197 }
198198 i++;
199199 }
@@ -213,7 +213,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, · 13 unmodified lines
213213 spec->match_criteria_enable |= MLX5_MATCH_INNER_HEADERS;
214214
215215 if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
216− flow_act.modify_id = attr->mod_hdr_id;
216+ flow_act.modify_hdr = attr->modify_hdr;
217217
218218 fdb = esw_get_prio_table(esw, attr->chain, attr->prio, !!split);
219219 if (IS_ERR(fdb)) {
@@ -276,7 +276,7 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw, · 56 unmodified lines
276276 dest[i].vport.flags |= MLX5_FLOW_DEST_VPORT_VHCA_ID;
277277 if (attr->dests[i].flags & MLX5_ESW_DEST_ENCAP) {
278278 dest[i].vport.flags |= MLX5_FLOW_DEST_VPORT_REFORMAT_ID;
279− dest[i].vport.reformat_id = attr->dests[i].encap_id;
279+ dest[i].vport.pkt_reformat = attr->dests[i].pkt_reformat;
280280 }
281281 }
282282 dest[i].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
@@ -1734,7 +1734,7 @@ static int esw_vport_ingress_prio_tag_config(struct mlx5_eswitch *esw, · 1451 unmodified lines
17341734
17351735 if (vport->ingress.modify_metadata_rule) {
17361736 flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
1737− flow_act.modify_id = vport->ingress.modify_metadata_id;
1737+ flow_act.modify_hdr = vport->ingress.modify_metadata;
17381738 }
17391739
17401740 vport->ingress.allow_rule =
@@ -1770,9 +1770,11 @@ static int esw_vport_add_ingress_acl_modify_metadata(struct mlx5_eswitch *esw, · 29 unmodified lines
17701770 MLX5_SET(set_action_in, action, data,
17711771 mlx5_eswitch_get_vport_metadata_for_match(esw, vport->vport));
17721772
1773− err = mlx5_modify_header_alloc(esw->dev, MLX5_FLOW_NAMESPACE_ESW_INGRESS,
1774− 1, action, &vport->ingress.modify_metadata_id);
1775− if (err) {
1773+ vport->ingress.modify_metadata =
1774+ mlx5_modify_header_alloc(esw->dev, MLX5_FLOW_NAMESPACE_ESW_INGRESS,
1775+ 1, action);
1776+ if (IS_ERR(vport->ingress.modify_metadata)) {
1777+ err = PTR_ERR(vport->ingress.modify_metadata);
17761778 esw_warn(esw->dev,
17771779 "failed to alloc modify header for vport %d ingress acl (%d)\n",
17781780 vport->vport, err);
@@ -1780,7 +1782,7 @@ static int esw_vport_add_ingress_acl_modify_metadata(struct mlx5_eswitch *esw, · 1 unmodified line
17801782 }
17811783
17821784 flow_act.action = MLX5_FLOW_CONTEXT_ACTION_MOD_HDR | MLX5_FLOW_CONTEXT_ACTION_ALLOW;
1783− flow_act.modify_id = vport->ingress.modify_metadata_id;
1785+ flow_act.modify_hdr = vport->ingress.modify_metadata;
17841786 vport->ingress.modify_metadata_rule = mlx5_add_flow_rules(vport->ingress.acl,
17851787 &spec, &flow_act, NULL, 0);
17861788 if (IS_ERR(vport->ingress.modify_metadata_rule)) {
@@ -1794,7 +1796,7 @@ static int esw_vport_add_ingress_acl_modify_metadata(struct mlx5_eswitch *esw, · 7 unmodified lines
17941796
17951797 out:
17961798 if (err)
1797− mlx5_modify_header_dealloc(esw->dev, vport->ingress.modify_metadata_id);
1799+ mlx5_modify_header_dealloc(esw->dev, vport->ingress.modify_metadata);
17981800 return err;
17991801 }
18001802
@@ -1803,7 +1805,7 @@ void esw_vport_del_ingress_acl_modify_metadata(struct mlx5_eswitch *esw, · 2 unmodified lines
18031805 {
18041806 if (vport->ingress.modify_metadata_rule) {
18051807 mlx5_del_flow_rules(vport->ingress.modify_metadata_rule);
1806− mlx5_modify_header_dealloc(esw->dev, vport->ingress.modify_metadata_id);
1808+ mlx5_modify_header_dealloc(esw->dev, vport->ingress.modify_metadata);
18071809
18081810 vport->ingress.modify_metadata_rule = NULL;
18091811 }
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c+66−26
@@ -107,6 +107,34 @@ static int mlx5_cmd_stub_delete_fte(struct mlx5_flow_root_namespace *ns, · 106 unmodified lines
107107 return 0;
108108 }
109109
110+static int mlx5_cmd_stub_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
111+ int reformat_type,
112+ size_t size,
113+ void *reformat_data,
114+ enum mlx5_flow_namespace_type namespace,
115+ struct mlx5_pkt_reformat *pkt_reformat)
116+{
117+ return 0;
118+}
119+
120+static void mlx5_cmd_stub_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
121+ struct mlx5_pkt_reformat *pkt_reformat)
122+{
123+}
124+
125+static int mlx5_cmd_stub_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
126+ u8 namespace, u8 num_actions,
127+ void *modify_actions,
128+ struct mlx5_modify_hdr *modify_hdr)
129+{
130+ return 0;
131+}
132+
133+static void mlx5_cmd_stub_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
134+ struct mlx5_modify_hdr *modify_hdr)
135+{
136+}
137+
110138 static int mlx5_cmd_update_root_ft(struct mlx5_flow_root_namespace *ns,
111139 struct mlx5_flow_table *ft, u32 underlay_qpn,
112140 bool disconnect)
@@ -412,11 +440,13 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev, · 299 unmodified lines
412440 } else {
413441 MLX5_SET(flow_context, in_flow_context, action,
414442 fte->action.action);
415− MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
416− fte->action.reformat_id);
443+ if (fte->action.pkt_reformat)
444+ MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
445+ fte->action.pkt_reformat->id);
417446 }
418− MLX5_SET(flow_context, in_flow_context, modify_header_id,
419− fte->action.modify_id);
447+ if (fte->action.modify_hdr)
448+ MLX5_SET(flow_context, in_flow_context, modify_header_id,
449+ fte->action.modify_hdr->id);
420450
421451 vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan);
422452
@@ -468,7 +498,7 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev, · 45 unmodified lines
468498 MLX5_FLOW_DEST_VPORT_REFORMAT_ID));
469499 MLX5_SET(extended_dest_format, in_dests,
470500 packet_reformat_id,
471− dst->dest_attr.vport.reformat_id);
501+ dst->dest_attr.vport.pkt_reformat->id);
472502 }
473503 break;
474504 default:
@@ -643,14 +673,15 @@ int mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, u32 base_id, int bulk_len, · 168 unmodified lines
643673 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
644674 }
645675
646−int mlx5_packet_reformat_alloc(struct mlx5_core_dev *dev,
647− int reformat_type,
648− size_t size,
649− void *reformat_data,
650− enum mlx5_flow_namespace_type namespace,
651− u32 *packet_reformat_id)
676+static int mlx5_cmd_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
677+ int reformat_type,
678+ size_t size,
679+ void *reformat_data,
680+ enum mlx5_flow_namespace_type namespace,
681+ struct mlx5_pkt_reformat *pkt_reformat)
652682 {
653683 u32 out[MLX5_ST_SZ_DW(alloc_packet_reformat_context_out)];
684+ struct mlx5_core_dev *dev = ns->dev;
654685 void *packet_reformat_context_in;
655686 int max_encap_size;
656687 void *reformat;
@@ -693,35 +724,36 @@ int mlx5_packet_reformat_alloc(struct mlx5_core_dev *dev, · 36 unmodified lines
693724 memset(out, 0, sizeof(out));
694725 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
695726
696− *packet_reformat_id = MLX5_GET(alloc_packet_reformat_context_out,
697− out, packet_reformat_id);
727+ pkt_reformat->id = MLX5_GET(alloc_packet_reformat_context_out,
728+ out, packet_reformat_id);
698729 kfree(in);
699730 return err;
700731 }
701−EXPORT_SYMBOL(mlx5_packet_reformat_alloc);
702732
703−void mlx5_packet_reformat_dealloc(struct mlx5_core_dev *dev,
704− u32 packet_reformat_id)
733+static void mlx5_cmd_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
734+ struct mlx5_pkt_reformat *pkt_reformat)
705735 {
706736 u32 in[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_in)];
707737 u32 out[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_out)];
738+ struct mlx5_core_dev *dev = ns->dev;
708739
709740 memset(in, 0, sizeof(in));
710741 MLX5_SET(dealloc_packet_reformat_context_in, in, opcode,
711742 MLX5_CMD_OP_DEALLOC_PACKET_REFORMAT_CONTEXT);
712743 MLX5_SET(dealloc_packet_reformat_context_in, in, packet_reformat_id,
713− packet_reformat_id);
744+ pkt_reformat->id);
714745
715746 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
716747 }
717−EXPORT_SYMBOL(mlx5_packet_reformat_dealloc);
718748
719−int mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
720− u8 namespace, u8 num_actions,
721− void *modify_actions, u32 *modify_header_id)
749+static int mlx5_cmd_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
750+ u8 namespace, u8 num_actions,
751+ void *modify_actions,
752+ struct mlx5_modify_hdr *modify_hdr)
722753 {
723754 u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)];
724755 int max_actions, actions_size, inlen, err;
756+ struct mlx5_core_dev *dev = ns->dev;
725757 void *actions_in;
726758 u8 table_type;
727759 u32 *in;
@@ -772,26 +804,26 @@ int mlx5_modify_header_alloc(struct mlx5_core_dev *dev, · 44 unmodified lines
772804 memset(out, 0, sizeof(out));
773805 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
774806
775− *modify_header_id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
807+ modify_hdr->id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
776808 kfree(in);
777809 return err;
778810 }
779−EXPORT_SYMBOL(mlx5_modify_header_alloc);
780811
781−void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev, u32 modify_header_id)
812+static void mlx5_cmd_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
813+ struct mlx5_modify_hdr *modify_hdr)
782814 {
783815 u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)];
784816 u32 out[MLX5_ST_SZ_DW(dealloc_modify_header_context_out)];
817+ struct mlx5_core_dev *dev = ns->dev;
785818
786819 memset(in, 0, sizeof(in));
787820 MLX5_SET(dealloc_modify_header_context_in, in, opcode,
788821 MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT);
789822 MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id,
790− modify_header_id);
823+ modify_hdr->id);
791824
792825 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
793826 }
794−EXPORT_SYMBOL(mlx5_modify_header_dealloc);
795827
796828 static const struct mlx5_flow_cmds mlx5_flow_cmds = {
797829 .create_flow_table = mlx5_cmd_create_flow_table,
@@ -803,6 +835,10 @@ static const struct mlx5_flow_cmds mlx5_flow_cmds = { · 5 unmodified lines
803835 .update_fte = mlx5_cmd_update_fte,
804836 .delete_fte = mlx5_cmd_delete_fte,
805837 .update_root_ft = mlx5_cmd_update_root_ft,
838+ .packet_reformat_alloc = mlx5_cmd_packet_reformat_alloc,
839+ .packet_reformat_dealloc = mlx5_cmd_packet_reformat_dealloc,
840+ .modify_header_alloc = mlx5_cmd_modify_header_alloc,
841+ .modify_header_dealloc = mlx5_cmd_modify_header_dealloc
806842 };
807843
808844 static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = {
@@ -815,6 +851,10 @@ static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = { · 6 unmodified lines
815851 .update_fte = mlx5_cmd_stub_update_fte,
816852 .delete_fte = mlx5_cmd_stub_delete_fte,
817853 .update_root_ft = mlx5_cmd_stub_update_root_ft,
854+ .packet_reformat_alloc = mlx5_cmd_stub_packet_reformat_alloc,
855+ .packet_reformat_dealloc = mlx5_cmd_stub_packet_reformat_dealloc,
856+ .modify_header_alloc = mlx5_cmd_stub_modify_header_alloc,
857+ .modify_header_dealloc = mlx5_cmd_stub_modify_header_dealloc
818858 };
819859
820860 static const struct mlx5_flow_cmds *mlx5_fs_cmd_get_fw_cmds(void)
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.h+18−0
@@ -75,6 +75,24 @@ struct mlx5_flow_cmds { · 74 unmodified lines
7575 struct mlx5_flow_table *ft,
7676 u32 underlay_qpn,
7777 bool disconnect);
78+
79+ int (*packet_reformat_alloc)(struct mlx5_flow_root_namespace *ns,
80+ int reformat_type,
81+ size_t size,
82+ void *reformat_data,
83+ enum mlx5_flow_namespace_type namespace,
84+ struct mlx5_pkt_reformat *pkt_reformat);
85+
86+ void (*packet_reformat_dealloc)(struct mlx5_flow_root_namespace *ns,
87+ struct mlx5_pkt_reformat *pkt_reformat);
88+
89+ int (*modify_header_alloc)(struct mlx5_flow_root_namespace *ns,
90+ u8 namespace, u8 num_actions,
91+ void *modify_actions,
92+ struct mlx5_modify_hdr *modify_hdr);
93+
94+ void (*modify_header_dealloc)(struct mlx5_flow_root_namespace *ns,
95+ struct mlx5_modify_hdr *modify_hdr);
7896 };
7997
8098 int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id);
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c+104−1
@@ -1415,7 +1415,8 @@ static bool mlx5_flow_dests_cmp(struct mlx5_flow_destination *d1, · 1414 unmodified lines
14151415 ((d1->vport.flags & MLX5_FLOW_DEST_VPORT_VHCA_ID) ?
14161416 (d1->vport.vhca_id == d2->vport.vhca_id) : true) &&
14171417 ((d1->vport.flags & MLX5_FLOW_DEST_VPORT_REFORMAT_ID) ?
1418− (d1->vport.reformat_id == d2->vport.reformat_id) : true)) ||
1418+ (d1->vport.pkt_reformat->id ==
1419+ d2->vport.pkt_reformat->id) : true)) ||
14191420 (d1->type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE &&
14201421 d1->ft == d2->ft) ||
14211422 (d1->type == MLX5_FLOW_DESTINATION_TYPE_TIR &&
@@ -2888,3 +2889,105 @@ out: · 1466 unmodified lines
28882889 return err;
28892890 }
28902891 EXPORT_SYMBOL(mlx5_fs_remove_rx_underlay_qpn);
2892+
2893+static struct mlx5_flow_root_namespace
2894+*get_root_namespace(struct mlx5_core_dev *dev, enum mlx5_flow_namespace_type ns_type)
2895+{
2896+ struct mlx5_flow_namespace *ns;
2897+
2898+ if (ns_type == MLX5_FLOW_NAMESPACE_ESW_EGRESS ||
2899+ ns_type == MLX5_FLOW_NAMESPACE_ESW_INGRESS)
2900+ ns = mlx5_get_flow_vport_acl_namespace(dev, ns_type, 0);
2901+ else
2902+ ns = mlx5_get_flow_namespace(dev, ns_type);
2903+ if (!ns)
2904+ return NULL;
2905+
2906+ return find_root(&ns->node);
2907+}
2908+
2909+struct mlx5_modify_hdr *mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
2910+ u8 ns_type, u8 num_actions,
2911+ void *modify_actions)
2912+{
2913+ struct mlx5_flow_root_namespace *root;
2914+ struct mlx5_modify_hdr *modify_hdr;
2915+ int err;
2916+
2917+ root = get_root_namespace(dev, ns_type);
2918+ if (!root)
2919+ return ERR_PTR(-EOPNOTSUPP);
2920+
2921+ modify_hdr = kzalloc(sizeof(*modify_hdr), GFP_KERNEL);
2922+ if (!modify_hdr)
2923+ return ERR_PTR(-ENOMEM);
2924+
2925+ modify_hdr->ns_type = ns_type;
2926+ err = root->cmds->modify_header_alloc(root, ns_type, num_actions,
2927+ modify_actions, modify_hdr);
2928+ if (err) {
2929+ kfree(modify_hdr);
2930+ return ERR_PTR(err);
2931+ }
2932+
2933+ return modify_hdr;
2934+}
2935+EXPORT_SYMBOL(mlx5_modify_header_alloc);
2936+
2937+void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev,
2938+ struct mlx5_modify_hdr *modify_hdr)
2939+{
2940+ struct mlx5_flow_root_namespace *root;
2941+
2942+ root = get_root_namespace(dev, modify_hdr->ns_type);
2943+ if (WARN_ON(!root))
2944+ return;
2945+ root->cmds->modify_header_dealloc(root, modify_hdr);
2946+ kfree(modify_hdr);
2947+}
2948+EXPORT_SYMBOL(mlx5_modify_header_dealloc);
2949+
2950+struct mlx5_pkt_reformat *mlx5_packet_reformat_alloc(struct mlx5_core_dev *dev,
2951+ int reformat_type,
2952+ size_t size,
2953+ void *reformat_data,
2954+ enum mlx5_flow_namespace_type ns_type)
2955+{
2956+ struct mlx5_pkt_reformat *pkt_reformat;
2957+ struct mlx5_flow_root_namespace *root;
2958+ int err;
2959+
2960+ root = get_root_namespace(dev, ns_type);
2961+ if (!root)
2962+ return ERR_PTR(-EOPNOTSUPP);
2963+
2964+ pkt_reformat = kzalloc(sizeof(*pkt_reformat), GFP_KERNEL);
2965+ if (!pkt_reformat)
2966+ return ERR_PTR(-ENOMEM);
2967+
2968+ pkt_reformat->ns_type = ns_type;
2969+ pkt_reformat->reformat_type = reformat_type;
2970+ err = root->cmds->packet_reformat_alloc(root, reformat_type, size,
2971+ reformat_data, ns_type,
2972+ pkt_reformat);
2973+ if (err) {
2974+ kfree(pkt_reformat);
2975+ return ERR_PTR(err);
2976+ }
2977+
2978+ return pkt_reformat;
2979+}
2980+EXPORT_SYMBOL(mlx5_packet_reformat_alloc);
2981+
2982+void mlx5_packet_reformat_dealloc(struct mlx5_core_dev *dev,
2983+ struct mlx5_pkt_reformat *pkt_reformat)
2984+{
2985+ struct mlx5_flow_root_namespace *root;
2986+
2987+ root = get_root_namespace(dev, pkt_reformat->ns_type);
2988+ if (WARN_ON(!root))
2989+ return;
2990+ root->cmds->packet_reformat_dealloc(root, pkt_reformat);
2991+ kfree(pkt_reformat);
2992+}
2993+EXPORT_SYMBOL(mlx5_packet_reformat_dealloc);
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h+11−0
@@ -38,6 +38,17 @@ · 37 unmodified lines
3838 #include <linux/rhashtable.h>
3939 #include <linux/llist.h>
4040
41+struct mlx5_modify_hdr {
42+ enum mlx5_flow_namespace_type ns_type;
43+ u32 id;
44+};
45+
46+struct mlx5_pkt_reformat {
47+ enum mlx5_flow_namespace_type ns_type;
48+ int reformat_type; /* from mlx5_ifc */
49+ u32 id;
50+};
51+
4152 /* FS_TYPE_PRIO_CHAINS is a PRIO that will have namespaces only,
4253 * and those are in parallel to one another when going over them to connect
4354 * a new flow table. Meaning the last flow table in a TYPE_PRIO prio in one
include/linux/mlx5/fs.h+16−17
@@ -84,6 +84,8 @@ enum { · 83 unmodified lines
8484 FDB_SLOW_PATH,
8585 };
8686
87+struct mlx5_pkt_reformat;
88+struct mlx5_modify_hdr;
8789 struct mlx5_flow_table;
8890 struct mlx5_flow_group;
8991 struct mlx5_flow_namespace;
@@ -121,7 +123,7 @@ struct mlx5_flow_destination { · 31 unmodified lines
121123 struct {
122124 u16 num;
123125 u16 vhca_id;
124− u32 reformat_id;
126+ struct mlx5_pkt_reformat *pkt_reformat;
125127 u8 flags;
126128 } vport;
127129 };
@@ -195,8 +197,8 @@ enum { · 67 unmodified lines
195197
196198 struct mlx5_flow_act {
197199 u32 action;
198− u32 reformat_id;
199− u32 modify_id;
200+ struct mlx5_modify_hdr *modify_hdr;
201+ struct mlx5_pkt_reformat *pkt_reformat;
200202 uintptr_t esp_id;
201203 u32 flags;
202204 struct mlx5_fs_vlan vlan[MLX5_FS_VLAN_DEPTH];
@@ -205,8 +207,6 @@ struct mlx5_flow_act { · 2 unmodified lines
205207
206208 #define MLX5_DECLARE_FLOW_ACT(name) \
207209 struct mlx5_flow_act name = { .action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,\
208− .reformat_id = 0, \
209− .modify_id = 0, \
210210 .flags = 0, }
211211
212212 /* Single destination per rule.
@@ -236,19 +236,18 @@ u32 mlx5_fc_id(struct mlx5_fc *counter); · 23 unmodified lines
236236 int mlx5_fs_add_rx_underlay_qpn(struct mlx5_core_dev *dev, u32 underlay_qpn);
237237 int mlx5_fs_remove_rx_underlay_qpn(struct mlx5_core_dev *dev, u32 underlay_qpn);
238238
239−int mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
240− u8 namespace, u8 num_actions,
241− void *modify_actions, u32 *modify_header_id);
239+struct mlx5_modify_hdr *mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
240+ u8 ns_type, u8 num_actions,
241+ void *modify_actions);
242242 void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev,
243− u32 modify_header_id);
244−
245−int mlx5_packet_reformat_alloc(struct mlx5_core_dev *dev,
246− int reformat_type,
247− size_t size,
248− void *reformat_data,
249− enum mlx5_flow_namespace_type namespace,
250− u32 *packet_reformat_id);
243+ struct mlx5_modify_hdr *modify_hdr);
244+
245+struct mlx5_pkt_reformat *mlx5_packet_reformat_alloc(struct mlx5_core_dev *dev,
246+ int reformat_type,
247+ size_t size,
248+ void *reformat_data,
249+ enum mlx5_flow_namespace_type ns_type);
251250 void mlx5_packet_reformat_dealloc(struct mlx5_core_dev *dev,
252− u32 packet_reformat_id);
251+ struct mlx5_pkt_reformat *reformat);
253252
254253 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t