1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2018 Mellanox Technologies. */
3
4 #ifndef __MLX5_EN_TC_TUNNEL_H__
5 #define __MLX5_EN_TC_TUNNEL_H__
6
7 #include <linux/netdevice.h>
8 #include <linux/mlx5/fs.h>
9 #include <net/pkt_cls.h>
10 #include <linux/netlink.h>
11 #include "en.h"
12 #include "en_rep.h"
13
14 #ifdef CONFIG_MLX5_ESWITCH
15
16 enum {
17 MLX5E_TC_TUNNEL_TYPE_UNKNOWN,
18 MLX5E_TC_TUNNEL_TYPE_VXLAN,
19 MLX5E_TC_TUNNEL_TYPE_GENEVE,
20 MLX5E_TC_TUNNEL_TYPE_GRETAP,
21 MLX5E_TC_TUNNEL_TYPE_MPLSOUDP,
22 };
23
24 struct mlx5e_encap_key {
25 const struct ip_tunnel_key *ip_tun_key;
26 struct mlx5e_tc_tunnel *tc_tunnel;
27 };
28
29 struct mlx5e_tc_tunnel {
30 int tunnel_type;
31 enum mlx5_flow_match_level match_level;
32
33 bool (*can_offload)(struct mlx5e_priv *priv);
34 int (*calc_hlen)(struct mlx5e_encap_entry *e);
35 int (*init_encap_attr)(struct net_device *tunnel_dev,
36 struct mlx5e_priv *priv,
37 struct mlx5e_encap_entry *e,
38 struct netlink_ext_ack *extack);
39 int (*generate_ip_tun_hdr)(char buf[],
40 __u8 *ip_proto,
41 struct mlx5e_encap_entry *e);
42 int (*parse_udp_ports)(struct mlx5e_priv *priv,
43 struct mlx5_flow_spec *spec,
44 struct flow_cls_offload *f,
45 void *headers_c,
46 void *headers_v);
47 int (*parse_tunnel)(struct mlx5e_priv *priv,
48 struct mlx5_flow_spec *spec,
49 struct flow_cls_offload *f,
50 void *headers_c,
51 void *headers_v);
52 bool (*encap_info_equal)(struct mlx5e_encap_key *a,
53 struct mlx5e_encap_key *b);
54 };
55
56 extern struct mlx5e_tc_tunnel vxlan_tunnel;
57 extern struct mlx5e_tc_tunnel geneve_tunnel;
58 extern struct mlx5e_tc_tunnel gre_tunnel;
59 extern struct mlx5e_tc_tunnel mplsoudp_tunnel;
60
61 struct mlx5e_tc_tunnel *mlx5e_get_tc_tun(struct net_device *tunnel_dev);
62
63 int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev,
64 struct mlx5e_priv *priv,
65 struct mlx5e_encap_entry *e,
66 struct netlink_ext_ack *extack);
67
68 int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
69 struct net_device *mirred_dev,
70 struct mlx5e_encap_entry *e);
71 int mlx5e_tc_tun_update_header_ipv4(struct mlx5e_priv *priv,
72 struct net_device *mirred_dev,
73 struct mlx5e_encap_entry *e);
74
75 #if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6)
76 int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
77 struct net_device *mirred_dev,
78 struct mlx5e_encap_entry *e);
79 int mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv *priv,
80 struct net_device *mirred_dev,
81 struct mlx5e_encap_entry *e);
82 #else
83 static inline int
mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv * priv,struct net_device * mirred_dev,struct mlx5e_encap_entry * e)84 mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
85 struct net_device *mirred_dev,
86 struct mlx5e_encap_entry *e)
87 { return -EOPNOTSUPP; }
88 static inline int
mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv * priv,struct net_device * mirred_dev,struct mlx5e_encap_entry * e)89 mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv *priv,
90 struct net_device *mirred_dev,
91 struct mlx5e_encap_entry *e)
92 { return -EOPNOTSUPP; }
93 #endif
94 int mlx5e_tc_tun_route_lookup(struct mlx5e_priv *priv,
95 struct mlx5_flow_spec *spec,
96 struct mlx5_flow_attr *attr);
97
98 bool mlx5e_tc_tun_device_to_offload(struct mlx5e_priv *priv,
99 struct net_device *netdev);
100
101 int mlx5e_tc_tun_parse(struct net_device *filter_dev,
102 struct mlx5e_priv *priv,
103 struct mlx5_flow_spec *spec,
104 struct flow_cls_offload *f,
105 u8 *match_level);
106
107 int mlx5e_tc_tun_parse_udp_ports(struct mlx5e_priv *priv,
108 struct mlx5_flow_spec *spec,
109 struct flow_cls_offload *f,
110 void *headers_c,
111 void *headers_v);
112
113 bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,
114 struct mlx5e_encap_key *b);
115
116 #endif /* CONFIG_MLX5_ESWITCH */
117
118 #endif //__MLX5_EN_TC_TUNNEL_H__
119