Skip to content

Commit c83954a

Browse files
Rabie LoulouSaeed Mahameed
authored andcommitted
net/mlx5e: Change return type of tc add flow functions
Refactor the flow add utility functions to return err code instead of rule pointers. This will allow for simpler logic when one tc rule is duplicated to two HW rules in downstream patches. Signed-off-by: Rabie Loulou <[email protected]> Signed-off-by: Shahar Klein <[email protected]> Reviewed-by: Roi Dayan <[email protected]> Reviewed-by: Or Gerlitz <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 171c762 commit c83954a

File tree

1 file changed

+39
-47
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+39
-47
lines changed

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

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ static void mlx5e_hairpin_flow_del(struct mlx5e_priv *priv,
673673
}
674674
}
675675

676-
static struct mlx5_flow_handle *
676+
static int
677677
mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
678678
struct mlx5e_tc_flow_parse_attr *parse_attr,
679679
struct mlx5e_tc_flow *flow,
@@ -689,14 +689,12 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
689689
.reformat_id = 0,
690690
};
691691
struct mlx5_fc *counter = NULL;
692-
struct mlx5_flow_handle *rule;
693692
bool table_created = false;
694693
int err, dest_ix = 0;
695694

696695
if (flow->flags & MLX5E_TC_FLOW_HAIRPIN) {
697696
err = mlx5e_hairpin_flow_add(priv, flow, parse_attr, extack);
698697
if (err) {
699-
rule = ERR_PTR(err);
700698
goto err_add_hairpin_flow;
701699
}
702700
if (flow->flags & MLX5E_TC_FLOW_HAIRPIN_RSS) {
@@ -716,7 +714,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
716714
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
717715
counter = mlx5_fc_create(dev, true);
718716
if (IS_ERR(counter)) {
719-
rule = ERR_CAST(counter);
717+
err = PTR_ERR(counter);
720718
goto err_fc_create;
721719
}
722720
dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
@@ -729,10 +727,8 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
729727
err = mlx5e_attach_mod_hdr(priv, flow, parse_attr);
730728
flow_act.modify_id = attr->mod_hdr_id;
731729
kfree(parse_attr->mod_hdr_actions);
732-
if (err) {
733-
rule = ERR_PTR(err);
730+
if (err)
734731
goto err_create_mod_hdr_id;
735-
}
736732
}
737733

738734
if (IS_ERR_OR_NULL(priv->fs.tc.t)) {
@@ -758,7 +754,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
758754
"Failed to create tc offload table\n");
759755
netdev_err(priv->netdev,
760756
"Failed to create tc offload table\n");
761-
rule = ERR_CAST(priv->fs.tc.t);
757+
err = PTR_ERR(priv->fs.tc.t);
762758
goto err_create_ft;
763759
}
764760

@@ -768,13 +764,15 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
768764
if (attr->match_level != MLX5_MATCH_NONE)
769765
parse_attr->spec.match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
770766

771-
rule = mlx5_add_flow_rules(priv->fs.tc.t, &parse_attr->spec,
772-
&flow_act, dest, dest_ix);
767+
flow->rule[0] = mlx5_add_flow_rules(priv->fs.tc.t, &parse_attr->spec,
768+
&flow_act, dest, dest_ix);
773769

774-
if (IS_ERR(rule))
770+
if (IS_ERR(flow->rule[0])) {
771+
err = PTR_ERR(flow->rule[0]);
775772
goto err_add_rule;
773+
}
776774

777-
return rule;
775+
return 0;
778776

779777
err_add_rule:
780778
if (table_created) {
@@ -790,7 +788,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
790788
if (flow->flags & MLX5E_TC_FLOW_HAIRPIN)
791789
mlx5e_hairpin_flow_del(priv, flow);
792790
err_add_hairpin_flow:
793-
return rule;
791+
return err;
794792
}
795793

796794
static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv,
@@ -825,7 +823,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
825823
struct mlx5e_tc_flow *flow,
826824
struct netlink_ext_ack *extack);
827825

828-
static struct mlx5_flow_handle *
826+
static int
829827
mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
830828
struct mlx5e_tc_flow_parse_attr *parse_attr,
831829
struct mlx5e_tc_flow *flow,
@@ -834,21 +832,20 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
834832
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
835833
struct mlx5_esw_flow_attr *attr = flow->esw_attr;
836834
struct net_device *out_dev, *encap_dev = NULL;
837-
struct mlx5_flow_handle *rule = NULL;
838835
struct mlx5_fc *counter = NULL;
839836
struct mlx5e_rep_priv *rpriv;
840837
struct mlx5e_priv *out_priv;
841-
int err;
838+
int err = 0, encap_err = 0;
842839

843840
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) {
844841
out_dev = __dev_get_by_index(dev_net(priv->netdev),
845842
attr->parse_attr->mirred_ifindex);
846-
err = mlx5e_attach_encap(priv, &parse_attr->tun_info,
847-
out_dev, &encap_dev, flow, extack);
848-
if (err) {
849-
rule = ERR_PTR(err);
850-
if (err != -EAGAIN)
851-
goto err_attach_encap;
843+
encap_err = mlx5e_attach_encap(priv, &parse_attr->tun_info,
844+
out_dev, &encap_dev, flow,
845+
extack);
846+
if (encap_err && encap_err != -EAGAIN) {
847+
err = encap_err;
848+
goto err_attach_encap;
852849
}
853850
out_priv = netdev_priv(encap_dev);
854851
rpriv = out_priv->ppriv;
@@ -857,49 +854,49 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
857854
}
858855

859856
err = mlx5_eswitch_add_vlan_action(esw, attr);
860-
if (err) {
861-
rule = ERR_PTR(err);
857+
if (err)
862858
goto err_add_vlan;
863-
}
864859

865860
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) {
866861
err = mlx5e_attach_mod_hdr(priv, flow, parse_attr);
867862
kfree(parse_attr->mod_hdr_actions);
868-
if (err) {
869-
rule = ERR_PTR(err);
863+
if (err)
870864
goto err_mod_hdr;
871-
}
872865
}
873866

874867
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
875868
counter = mlx5_fc_create(esw->dev, true);
876869
if (IS_ERR(counter)) {
877-
rule = ERR_CAST(counter);
870+
err = PTR_ERR(counter);
878871
goto err_create_counter;
879872
}
880873

881874
attr->counter = counter;
882875
}
883876

884-
/* we get here if (1) there's no error (rule being null) or when
877+
/* we get here if (1) there's no error or when
885878
* (2) there's an encap action and we're on -EAGAIN (no valid neigh)
886879
*/
887-
if (rule != ERR_PTR(-EAGAIN)) {
888-
rule = mlx5_eswitch_add_offloaded_rule(esw, &parse_attr->spec, attr);
889-
if (IS_ERR(rule))
880+
if (encap_err != -EAGAIN) {
881+
flow->rule[0] = mlx5_eswitch_add_offloaded_rule(esw, &parse_attr->spec, attr);
882+
if (IS_ERR(flow->rule[0])) {
883+
err = PTR_ERR(flow->rule[0]);
890884
goto err_add_rule;
885+
}
891886

892887
if (attr->mirror_count) {
893888
flow->rule[1] = mlx5_eswitch_add_fwd_rule(esw, &parse_attr->spec, attr);
894-
if (IS_ERR(flow->rule[1]))
889+
if (IS_ERR(flow->rule[1])) {
890+
err = PTR_ERR(flow->rule[1]);
895891
goto err_fwd_rule;
892+
}
896893
}
897894
}
898-
return rule;
895+
896+
return encap_err;
899897

900898
err_fwd_rule:
901-
mlx5_eswitch_del_offloaded_rule(esw, rule, attr);
902-
rule = flow->rule[1];
899+
mlx5_eswitch_del_offloaded_rule(esw, flow->rule[0], attr);
903900
err_add_rule:
904901
mlx5_fc_destroy(esw->dev, counter);
905902
err_create_counter:
@@ -911,7 +908,7 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
911908
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT)
912909
mlx5e_detach_encap(priv, flow);
913910
err_attach_encap:
914-
return rule;
911+
return err;
915912
}
916913

917914
static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
@@ -2959,22 +2956,17 @@ int mlx5e_configure_flower(struct mlx5e_priv *priv,
29592956
extack);
29602957
if (err < 0)
29612958
goto err_free;
2962-
flow->rule[0] = mlx5e_tc_add_fdb_flow(priv, parse_attr, flow,
2963-
extack);
2959+
err = mlx5e_tc_add_fdb_flow(priv, parse_attr, flow, extack);
29642960
} else {
29652961
err = parse_tc_nic_actions(priv, f->exts, parse_attr, flow,
29662962
extack);
29672963
if (err < 0)
29682964
goto err_free;
2969-
flow->rule[0] = mlx5e_tc_add_nic_flow(priv, parse_attr, flow,
2970-
extack);
2965+
err = mlx5e_tc_add_nic_flow(priv, parse_attr, flow, extack);
29712966
}
29722967

2973-
if (IS_ERR(flow->rule[0])) {
2974-
err = PTR_ERR(flow->rule[0]);
2975-
if (err != -EAGAIN)
2976-
goto err_free;
2977-
}
2968+
if (err && err != -EAGAIN)
2969+
goto err_free;
29782970

29792971
if (err != -EAGAIN)
29802972
flow->flags |= MLX5E_TC_FLOW_OFFLOADED;

0 commit comments

Comments
 (0)