Skip to content

Commit e2ab5aa

Browse files
Chris MiSaeed Mahameed
Chris Mi
authored and
Saeed Mahameed
committed
net/mlx5e: Extract remaining tunnel encap code to dedicated file
Move set_encap_dests() and clean_encap_dests() to the tunnel encap dedicated file. And rename them to mlx5e_tc_tun_encap_dests_set() and mlx5e_tc_tun_encap_dests_unset(). No functional change in this patch. It is needed in the next patch. Signed-off-by: Chris Mi <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 878ecb0 commit e2ab5aa

File tree

3 files changed

+94
-87
lines changed

3 files changed

+94
-87
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c

+83
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,89 @@ int mlx5e_attach_decap(struct mlx5e_priv *priv,
10161016
return err;
10171017
}
10181018

1019+
int mlx5e_tc_tun_encap_dests_set(struct mlx5e_priv *priv,
1020+
struct mlx5e_tc_flow *flow,
1021+
struct mlx5_flow_attr *attr,
1022+
struct netlink_ext_ack *extack,
1023+
bool *vf_tun)
1024+
{
1025+
struct mlx5e_tc_flow_parse_attr *parse_attr;
1026+
struct mlx5_esw_flow_attr *esw_attr;
1027+
struct net_device *encap_dev = NULL;
1028+
struct mlx5e_rep_priv *rpriv;
1029+
struct mlx5e_priv *out_priv;
1030+
int out_index;
1031+
int err = 0;
1032+
1033+
if (!mlx5e_is_eswitch_flow(flow))
1034+
return 0;
1035+
1036+
parse_attr = attr->parse_attr;
1037+
esw_attr = attr->esw_attr;
1038+
*vf_tun = false;
1039+
1040+
for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) {
1041+
struct net_device *out_dev;
1042+
int mirred_ifindex;
1043+
1044+
if (!(esw_attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP))
1045+
continue;
1046+
1047+
mirred_ifindex = parse_attr->mirred_ifindex[out_index];
1048+
out_dev = dev_get_by_index(dev_net(priv->netdev), mirred_ifindex);
1049+
if (!out_dev) {
1050+
NL_SET_ERR_MSG_MOD(extack, "Requested mirred device not found");
1051+
err = -ENODEV;
1052+
goto out;
1053+
}
1054+
err = mlx5e_attach_encap(priv, flow, attr, out_dev, out_index,
1055+
extack, &encap_dev);
1056+
dev_put(out_dev);
1057+
if (err)
1058+
goto out;
1059+
1060+
if (esw_attr->dests[out_index].flags &
1061+
MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE &&
1062+
!esw_attr->dest_int_port)
1063+
*vf_tun = true;
1064+
1065+
out_priv = netdev_priv(encap_dev);
1066+
rpriv = out_priv->ppriv;
1067+
esw_attr->dests[out_index].rep = rpriv->rep;
1068+
esw_attr->dests[out_index].mdev = out_priv->mdev;
1069+
}
1070+
1071+
if (*vf_tun && esw_attr->out_count > 1) {
1072+
NL_SET_ERR_MSG_MOD(extack, "VF tunnel encap with mirroring is not supported");
1073+
err = -EOPNOTSUPP;
1074+
goto out;
1075+
}
1076+
1077+
out:
1078+
return err;
1079+
}
1080+
1081+
void mlx5e_tc_tun_encap_dests_unset(struct mlx5e_priv *priv,
1082+
struct mlx5e_tc_flow *flow,
1083+
struct mlx5_flow_attr *attr)
1084+
{
1085+
struct mlx5_esw_flow_attr *esw_attr;
1086+
int out_index;
1087+
1088+
if (!mlx5e_is_eswitch_flow(flow))
1089+
return;
1090+
1091+
esw_attr = attr->esw_attr;
1092+
1093+
for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) {
1094+
if (!(esw_attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP))
1095+
continue;
1096+
1097+
mlx5e_detach_encap(flow->priv, flow, attr, out_index);
1098+
kfree(attr->parse_attr->tun_info[out_index]);
1099+
}
1100+
}
1101+
10191102
static int cmp_route_info(struct mlx5e_route_key *a,
10201103
struct mlx5e_route_key *b)
10211104
{

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

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ int mlx5e_attach_decap_route(struct mlx5e_priv *priv,
3030
void mlx5e_detach_decap_route(struct mlx5e_priv *priv,
3131
struct mlx5e_tc_flow *flow);
3232

33+
int mlx5e_tc_tun_encap_dests_set(struct mlx5e_priv *priv,
34+
struct mlx5e_tc_flow *flow,
35+
struct mlx5_flow_attr *attr,
36+
struct netlink_ext_ack *extack,
37+
bool *vf_tun);
38+
void mlx5e_tc_tun_encap_dests_unset(struct mlx5e_priv *priv,
39+
struct mlx5e_tc_flow *flow,
40+
struct mlx5_flow_attr *attr);
41+
3342
struct ip_tunnel_info *mlx5e_dup_tun_info(const struct ip_tunnel_info *tun_info);
3443

3544
int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow,

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

+2-87
Original file line numberDiff line numberDiff line change
@@ -1699,91 +1699,6 @@ int mlx5e_tc_query_route_vport(struct net_device *out_dev, struct net_device *ro
16991699
return mlx5_eswitch_vhca_id_to_vport(esw, vhca_id, vport);
17001700
}
17011701

1702-
static int
1703-
set_encap_dests(struct mlx5e_priv *priv,
1704-
struct mlx5e_tc_flow *flow,
1705-
struct mlx5_flow_attr *attr,
1706-
struct netlink_ext_ack *extack,
1707-
bool *vf_tun)
1708-
{
1709-
struct mlx5e_tc_flow_parse_attr *parse_attr;
1710-
struct mlx5_esw_flow_attr *esw_attr;
1711-
struct net_device *encap_dev = NULL;
1712-
struct mlx5e_rep_priv *rpriv;
1713-
struct mlx5e_priv *out_priv;
1714-
int out_index;
1715-
int err = 0;
1716-
1717-
if (!mlx5e_is_eswitch_flow(flow))
1718-
return 0;
1719-
1720-
parse_attr = attr->parse_attr;
1721-
esw_attr = attr->esw_attr;
1722-
*vf_tun = false;
1723-
1724-
for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) {
1725-
struct net_device *out_dev;
1726-
int mirred_ifindex;
1727-
1728-
if (!(esw_attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP))
1729-
continue;
1730-
1731-
mirred_ifindex = parse_attr->mirred_ifindex[out_index];
1732-
out_dev = dev_get_by_index(dev_net(priv->netdev), mirred_ifindex);
1733-
if (!out_dev) {
1734-
NL_SET_ERR_MSG_MOD(extack, "Requested mirred device not found");
1735-
err = -ENODEV;
1736-
goto out;
1737-
}
1738-
err = mlx5e_attach_encap(priv, flow, attr, out_dev, out_index,
1739-
extack, &encap_dev);
1740-
dev_put(out_dev);
1741-
if (err)
1742-
goto out;
1743-
1744-
if (esw_attr->dests[out_index].flags &
1745-
MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE &&
1746-
!esw_attr->dest_int_port)
1747-
*vf_tun = true;
1748-
1749-
out_priv = netdev_priv(encap_dev);
1750-
rpriv = out_priv->ppriv;
1751-
esw_attr->dests[out_index].rep = rpriv->rep;
1752-
esw_attr->dests[out_index].mdev = out_priv->mdev;
1753-
}
1754-
1755-
if (*vf_tun && esw_attr->out_count > 1) {
1756-
NL_SET_ERR_MSG_MOD(extack, "VF tunnel encap with mirroring is not supported");
1757-
err = -EOPNOTSUPP;
1758-
goto out;
1759-
}
1760-
1761-
out:
1762-
return err;
1763-
}
1764-
1765-
static void
1766-
clean_encap_dests(struct mlx5e_priv *priv,
1767-
struct mlx5e_tc_flow *flow,
1768-
struct mlx5_flow_attr *attr)
1769-
{
1770-
struct mlx5_esw_flow_attr *esw_attr;
1771-
int out_index;
1772-
1773-
if (!mlx5e_is_eswitch_flow(flow))
1774-
return;
1775-
1776-
esw_attr = attr->esw_attr;
1777-
1778-
for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) {
1779-
if (!(esw_attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP))
1780-
continue;
1781-
1782-
mlx5e_detach_encap(priv, flow, attr, out_index);
1783-
kfree(attr->parse_attr->tun_info[out_index]);
1784-
}
1785-
}
1786-
17871702
static int
17881703
verify_attr_actions(u32 actions, struct netlink_ext_ack *extack)
17891704
{
@@ -1820,7 +1735,7 @@ post_process_attr(struct mlx5e_tc_flow *flow,
18201735
if (err)
18211736
goto err_out;
18221737

1823-
err = set_encap_dests(flow->priv, flow, attr, extack, &vf_tun);
1738+
err = mlx5e_tc_tun_encap_dests_set(flow->priv, flow, attr, extack, &vf_tun);
18241739
if (err)
18251740
goto err_out;
18261741

@@ -4324,7 +4239,7 @@ mlx5_free_flow_attr_actions(struct mlx5e_tc_flow *flow, struct mlx5_flow_attr *a
43244239
if (attr->post_act_handle)
43254240
mlx5e_tc_post_act_del(get_post_action(flow->priv), attr->post_act_handle);
43264241

4327-
clean_encap_dests(flow->priv, flow, attr);
4242+
mlx5e_tc_tun_encap_dests_unset(flow->priv, flow, attr);
43284243

43294244
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT)
43304245
mlx5_fc_destroy(counter_dev, attr->counter);

0 commit comments

Comments
 (0)