Skip to content

Commit 54c177c

Browse files
ozshlomoSaeed Mahameed
authored andcommitted
net/mlx5e: Branch according to classified tunnel type
Currently the tunnel offloading encap/decap methods assumes that VXLAN is the sole tunneling protocol. Lay the infrastructure for supporting multiple tunneling protocols by branching according to the tunnel net device kind. Encap filters tunnel type is determined according to the egress/mirred net device. Decap filters classify the tunnel type according to the filter's ingress net device kind. Distinguish between the tunnel type as defined by the SW model and the FW reformat type that specifies the HW operation being made. Signed-off-by: Oz Shlomo <ozsh@mellanox.com> Reviewed-by: Eli Britstein <elibr@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
1 parent 4d70564 commit 54c177c

2 files changed

Lines changed: 114 additions & 48 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ struct mlx5e_encap_entry {
149149

150150
struct net_device *out_dev;
151151
int tunnel_type;
152+
int tunnel_hlen;
153+
int reformat_type;
152154
u8 flags;
153155
char *encap_header;
154156
int encap_size;

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

Lines changed: 112 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ enum {
7979

8080
#define MLX5E_TC_MAX_SPLITS 1
8181

82+
enum {
83+
MLX5E_TC_TUNNEL_TYPE_UNKNOWN,
84+
MLX5E_TC_TUNNEL_TYPE_VXLAN
85+
};
86+
87+
static int mlx5e_get_tunnel_type(struct net_device *tunnel_dev);
88+
8289
struct mlx5e_tc_flow {
8390
struct rhash_head node;
8491
struct mlx5e_priv *priv;
@@ -677,6 +684,14 @@ static void mlx5e_hairpin_flow_del(struct mlx5e_priv *priv,
677684
}
678685
}
679686

687+
static const char *mlx5e_netdev_kind(struct net_device *dev)
688+
{
689+
if (dev->rtnl_link_ops)
690+
return dev->rtnl_link_ops->kind;
691+
else
692+
return "";
693+
}
694+
680695
static int
681696
mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
682697
struct mlx5e_tc_flow_parse_attr *parse_attr,
@@ -1037,7 +1052,8 @@ void mlx5e_tc_encap_flows_add(struct mlx5e_priv *priv,
10371052
struct mlx5e_tc_flow *flow;
10381053
int err;
10391054

1040-
err = mlx5_packet_reformat_alloc(priv->mdev, e->tunnel_type,
1055+
err = mlx5_packet_reformat_alloc(priv->mdev,
1056+
e->reformat_type,
10411057
e->encap_size, e->encap_header,
10421058
MLX5_FLOW_NAMESPACE_FDB,
10431059
&e->encap_id);
@@ -1265,7 +1281,8 @@ static int parse_tunnel_vxlan_attr(struct mlx5e_priv *priv,
12651281

12661282
static int parse_tunnel_attr(struct mlx5e_priv *priv,
12671283
struct mlx5_flow_spec *spec,
1268-
struct tc_cls_flower_offload *f)
1284+
struct tc_cls_flower_offload *f,
1285+
struct net_device *filter_dev)
12691286
{
12701287
struct netlink_ext_ack *extack = f->common.extack;
12711288
void *headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria,
@@ -1277,20 +1294,28 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv,
12771294
skb_flow_dissector_target(f->dissector,
12781295
FLOW_DISSECTOR_KEY_ENC_CONTROL,
12791296
f->key);
1297+
int tunnel_type;
1298+
int err = 0;
12801299

1281-
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ENC_PORTS)) {
1282-
int err = 0;
1283-
1300+
tunnel_type = mlx5e_get_tunnel_type(filter_dev);
1301+
if (tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN) {
12841302
err = parse_tunnel_vxlan_attr(priv, spec, f,
12851303
headers_c, headers_v);
1286-
if (err)
1287-
goto vxlan_match_offload_err;
1288-
} else { /* udp dst port must be given */
1289-
vxlan_match_offload_err:
1304+
} else {
12901305
NL_SET_ERR_MSG_MOD(extack,
1291-
"IP tunnel decap offload supported only for vxlan, must set UDP dport");
1306+
"decapsulation offload is not supported");
12921307
netdev_warn(priv->netdev,
1293-
"IP tunnel decap offload supported only for vxlan, must set UDP dport\n");
1308+
"decapsulation offload is not supported for %s net device (%d)\n",
1309+
mlx5e_netdev_kind(filter_dev), tunnel_type);
1310+
return -EOPNOTSUPP;
1311+
}
1312+
1313+
if (err) {
1314+
NL_SET_ERR_MSG_MOD(extack,
1315+
"failed to parse tunnel attributes");
1316+
netdev_warn(priv->netdev,
1317+
"failed to parse %s tunnel attributes (%d)\n",
1318+
mlx5e_netdev_kind(filter_dev), tunnel_type);
12941319
return -EOPNOTSUPP;
12951320
}
12961321

@@ -1395,6 +1420,7 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv,
13951420
static int __parse_cls_flower(struct mlx5e_priv *priv,
13961421
struct mlx5_flow_spec *spec,
13971422
struct tc_cls_flower_offload *f,
1423+
struct net_device *filter_dev,
13981424
u8 *match_level)
13991425
{
14001426
struct netlink_ext_ack *extack = f->common.extack;
@@ -1446,7 +1472,7 @@ static int __parse_cls_flower(struct mlx5e_priv *priv,
14461472
switch (key->addr_type) {
14471473
case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
14481474
case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
1449-
if (parse_tunnel_attr(priv, spec, f))
1475+
if (parse_tunnel_attr(priv, spec, f, filter_dev))
14501476
return -EOPNOTSUPP;
14511477
break;
14521478
default:
@@ -1788,7 +1814,8 @@ static int __parse_cls_flower(struct mlx5e_priv *priv,
17881814
static int parse_cls_flower(struct mlx5e_priv *priv,
17891815
struct mlx5e_tc_flow *flow,
17901816
struct mlx5_flow_spec *spec,
1791-
struct tc_cls_flower_offload *f)
1817+
struct tc_cls_flower_offload *f,
1818+
struct net_device *filter_dev)
17921819
{
17931820
struct netlink_ext_ack *extack = f->common.extack;
17941821
struct mlx5_core_dev *dev = priv->mdev;
@@ -1798,7 +1825,7 @@ static int parse_cls_flower(struct mlx5e_priv *priv,
17981825
u8 match_level;
17991826
int err;
18001827

1801-
err = __parse_cls_flower(priv, spec, f, &match_level);
1828+
err = __parse_cls_flower(priv, spec, f, filter_dev, &match_level);
18021829

18031830
if (!err && (flow->flags & MLX5E_TC_FLOW_ESWITCH)) {
18041831
rep = rpriv->rep;
@@ -2443,10 +2470,21 @@ static int mlx5e_gen_vxlan_header(char buf[], struct ip_tunnel_key *tun_key)
24432470
}
24442471

24452472
static int mlx5e_gen_ip_tunnel_header(char buf[], __u8 *ip_proto,
2446-
struct ip_tunnel_key *tun_key)
2473+
struct mlx5e_encap_entry *e)
24472474
{
2448-
*ip_proto = IPPROTO_UDP;
2449-
return mlx5e_gen_vxlan_header(buf, tun_key);
2475+
int err = 0;
2476+
struct ip_tunnel_key *key = &e->tun_info.key;
2477+
2478+
if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN) {
2479+
*ip_proto = IPPROTO_UDP;
2480+
err = mlx5e_gen_vxlan_header(buf, key);
2481+
} else {
2482+
pr_warn("mlx5: Cannot generate tunnel header for tunnel type (%d)\n"
2483+
, e->tunnel_type);
2484+
err = -EOPNOTSUPP;
2485+
}
2486+
2487+
return err;
24502488
}
24512489

24522490
static int mlx5e_create_encap_header_ipv4(struct mlx5e_priv *priv,
@@ -2456,7 +2494,7 @@ static int mlx5e_create_encap_header_ipv4(struct mlx5e_priv *priv,
24562494
int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size);
24572495
int ipv4_encap_size = ETH_HLEN +
24582496
sizeof(struct iphdr) +
2459-
VXLAN_HLEN;
2497+
e->tunnel_hlen;
24602498
struct ip_tunnel_key *tun_key = &e->tun_info.key;
24612499
struct net_device *out_dev;
24622500
struct neighbour *n = NULL;
@@ -2527,7 +2565,7 @@ static int mlx5e_create_encap_header_ipv4(struct mlx5e_priv *priv,
25272565

25282566
/* add tunneling protocol header */
25292567
err = mlx5e_gen_ip_tunnel_header((char *)ip + sizeof(struct iphdr),
2530-
&ip->protocol, tun_key);
2568+
&ip->protocol, e);
25312569
if (err)
25322570
goto destroy_neigh_entry;
25332571

@@ -2540,7 +2578,8 @@ static int mlx5e_create_encap_header_ipv4(struct mlx5e_priv *priv,
25402578
goto out;
25412579
}
25422580

2543-
err = mlx5_packet_reformat_alloc(priv->mdev, e->tunnel_type,
2581+
err = mlx5_packet_reformat_alloc(priv->mdev,
2582+
e->reformat_type,
25442583
ipv4_encap_size, encap_header,
25452584
MLX5_FLOW_NAMESPACE_FDB,
25462585
&e->encap_id);
@@ -2569,7 +2608,7 @@ static int mlx5e_create_encap_header_ipv6(struct mlx5e_priv *priv,
25692608
int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size);
25702609
int ipv6_encap_size = ETH_HLEN +
25712610
sizeof(struct ipv6hdr) +
2572-
VXLAN_HLEN;
2611+
e->tunnel_hlen;
25732612
struct ip_tunnel_key *tun_key = &e->tun_info.key;
25742613
struct net_device *out_dev;
25752614
struct neighbour *n = NULL;
@@ -2639,7 +2678,7 @@ static int mlx5e_create_encap_header_ipv6(struct mlx5e_priv *priv,
26392678

26402679
/* add tunneling protocol header */
26412680
err = mlx5e_gen_ip_tunnel_header((char *)ip6h + sizeof(struct ipv6hdr),
2642-
&ip6h->nexthdr, tun_key);
2681+
&ip6h->nexthdr, e);
26432682
if (err)
26442683
goto destroy_neigh_entry;
26452684

@@ -2652,7 +2691,8 @@ static int mlx5e_create_encap_header_ipv6(struct mlx5e_priv *priv,
26522691
goto out;
26532692
}
26542693

2655-
err = mlx5_packet_reformat_alloc(priv->mdev, e->tunnel_type,
2694+
err = mlx5_packet_reformat_alloc(priv->mdev,
2695+
e->reformat_type,
26562696
ipv6_encap_size, encap_header,
26572697
MLX5_FLOW_NAMESPACE_FDB,
26582698
&e->encap_id);
@@ -2674,14 +2714,52 @@ static int mlx5e_create_encap_header_ipv6(struct mlx5e_priv *priv,
26742714
return err;
26752715
}
26762716

2717+
static int mlx5e_get_tunnel_type(struct net_device *tunnel_dev)
2718+
{
2719+
if (netif_is_vxlan(tunnel_dev))
2720+
return MLX5E_TC_TUNNEL_TYPE_VXLAN;
2721+
else
2722+
return MLX5E_TC_TUNNEL_TYPE_UNKNOWN;
2723+
}
2724+
26772725
bool mlx5e_tc_tun_device_to_offload(struct mlx5e_priv *priv,
26782726
struct net_device *netdev)
26792727
{
2680-
if (netif_is_vxlan(netdev) &&
2728+
int tunnel_type = mlx5e_get_tunnel_type(netdev);
2729+
2730+
if (tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN &&
26812731
MLX5_CAP_ESW(priv->mdev, vxlan_encap_decap))
26822732
return true;
2733+
else
2734+
return false;
2735+
}
26832736

2684-
return false;
2737+
static int mlx5e_init_tunnel_attr(struct net_device *tunnel_dev,
2738+
struct mlx5e_priv *priv,
2739+
struct mlx5e_encap_entry *e,
2740+
struct netlink_ext_ack *extack)
2741+
{
2742+
e->tunnel_type = mlx5e_get_tunnel_type(tunnel_dev);
2743+
2744+
if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN) {
2745+
int dst_port = be16_to_cpu(e->tun_info.key.tp_dst);
2746+
2747+
if (!mlx5_vxlan_lookup_port(priv->mdev->vxlan, dst_port)) {
2748+
NL_SET_ERR_MSG_MOD(extack,
2749+
"vxlan udp dport was not registered with the HW");
2750+
netdev_warn(priv->netdev,
2751+
"%d isn't an offloaded vxlan udp dport\n",
2752+
dst_port);
2753+
return -EOPNOTSUPP;
2754+
}
2755+
e->reformat_type = MLX5_REFORMAT_TYPE_L2_TO_VXLAN;
2756+
e->tunnel_hlen = VXLAN_HLEN;
2757+
} else {
2758+
e->reformat_type = -1;
2759+
e->tunnel_hlen = -1;
2760+
return -EOPNOTSUPP;
2761+
}
2762+
return 0;
26852763
}
26862764

26872765
static int mlx5e_attach_encap(struct mlx5e_priv *priv,
@@ -2696,28 +2774,9 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
26962774
struct mlx5_esw_flow_attr *attr = flow->esw_attr;
26972775
struct ip_tunnel_key *key = &tun_info->key;
26982776
struct mlx5e_encap_entry *e;
2699-
int tunnel_type, err = 0;
27002777
uintptr_t hash_key;
27012778
bool found = false;
2702-
2703-
if (!MLX5_CAP_ESW(priv->mdev, vxlan_encap_decap)) {
2704-
NL_SET_ERR_MSG_MOD(extack,
2705-
"vxlan HW offloading is not supported");
2706-
netdev_warn(priv->netdev,
2707-
"vxlan HW offloading is not supported\n");
2708-
return -EOPNOTSUPP;
2709-
}
2710-
2711-
if (mlx5_vxlan_lookup_port(priv->mdev->vxlan, be16_to_cpu(key->tp_dst)) &&
2712-
MLX5_CAP_ESW(priv->mdev, vxlan_encap_decap)) {
2713-
tunnel_type = MLX5_REFORMAT_TYPE_L2_TO_VXLAN;
2714-
} else {
2715-
NL_SET_ERR_MSG_MOD(extack,
2716-
"port isn't an offloaded vxlan udp dport");
2717-
netdev_warn(priv->netdev,
2718-
"%d isn't an offloaded vxlan udp dport\n", be16_to_cpu(key->tp_dst));
2719-
return -EOPNOTSUPP;
2720-
}
2779+
int err = 0;
27212780

27222781
hash_key = hash_encap_info(key);
27232782

@@ -2738,7 +2797,10 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
27382797
return -ENOMEM;
27392798

27402799
e->tun_info = *tun_info;
2741-
e->tunnel_type = tunnel_type;
2800+
err = mlx5e_init_tunnel_attr(mirred_dev, priv, e, extack);
2801+
if (err)
2802+
goto out_err;
2803+
27422804
INIT_LIST_HEAD(&e->flows);
27432805

27442806
if (family == AF_INET)
@@ -3063,7 +3125,8 @@ mlx5e_add_fdb_flow(struct mlx5e_priv *priv,
30633125
goto out;
30643126
parse_attr->filter_dev = filter_dev;
30653127
flow->esw_attr->parse_attr = parse_attr;
3066-
err = parse_cls_flower(flow->priv, flow, &parse_attr->spec, f);
3128+
err = parse_cls_flower(flow->priv, flow, &parse_attr->spec,
3129+
f, filter_dev);
30673130
if (err)
30683131
goto err_free;
30693132

@@ -3116,7 +3179,8 @@ mlx5e_add_nic_flow(struct mlx5e_priv *priv,
31163179
goto out;
31173180

31183181
parse_attr->filter_dev = filter_dev;
3119-
err = parse_cls_flower(flow->priv, flow, &parse_attr->spec, f);
3182+
err = parse_cls_flower(flow->priv, flow, &parse_attr->spec,
3183+
f, filter_dev);
31203184
if (err)
31213185
goto err_free;
31223186

0 commit comments

Comments
 (0)