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 enum {
15 	MLX5E_TC_TUNNEL_TYPE_UNKNOWN,
16 	MLX5E_TC_TUNNEL_TYPE_VXLAN,
17 	MLX5E_TC_TUNNEL_TYPE_GENEVE,
18 	MLX5E_TC_TUNNEL_TYPE_GRETAP,
19 	MLX5E_TC_TUNNEL_TYPE_MPLSOUDP,
20 };
21 
22 struct mlx5e_tc_tunnel {
23 	int tunnel_type;
24 	enum mlx5_flow_match_level match_level;
25 
26 	bool (*can_offload)(struct mlx5e_priv *priv);
27 	int (*calc_hlen)(struct mlx5e_encap_entry *e);
28 	int (*init_encap_attr)(struct net_device *tunnel_dev,
29 			       struct mlx5e_priv *priv,
30 			       struct mlx5e_encap_entry *e,
31 			       struct netlink_ext_ack *extack);
32 	int (*generate_ip_tun_hdr)(char buf[],
33 				   __u8 *ip_proto,
34 				   struct mlx5e_encap_entry *e);
35 	int (*parse_udp_ports)(struct mlx5e_priv *priv,
36 			       struct mlx5_flow_spec *spec,
37 			       struct flow_cls_offload *f,
38 			       void *headers_c,
39 			       void *headers_v);
40 	int (*parse_tunnel)(struct mlx5e_priv *priv,
41 			    struct mlx5_flow_spec *spec,
42 			    struct flow_cls_offload *f,
43 			    void *headers_c,
44 			    void *headers_v);
45 };
46 
47 extern struct mlx5e_tc_tunnel vxlan_tunnel;
48 extern struct mlx5e_tc_tunnel geneve_tunnel;
49 extern struct mlx5e_tc_tunnel gre_tunnel;
50 extern struct mlx5e_tc_tunnel mplsoudp_tunnel;
51 
52 struct mlx5e_tc_tunnel *mlx5e_get_tc_tun(struct net_device *tunnel_dev);
53 
54 int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev,
55 				 struct mlx5e_priv *priv,
56 				 struct mlx5e_encap_entry *e,
57 				 struct netlink_ext_ack *extack);
58 
59 int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
60 				    struct net_device *mirred_dev,
61 				    struct mlx5e_encap_entry *e);
62 
63 #if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6)
64 int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
65 				    struct net_device *mirred_dev,
66 				    struct mlx5e_encap_entry *e);
67 #else
68 static inline int
mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv * priv,struct net_device * mirred_dev,struct mlx5e_encap_entry * e)69 mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
70 				struct net_device *mirred_dev,
71 				struct mlx5e_encap_entry *e) { return -EOPNOTSUPP; }
72 #endif
73 
74 bool mlx5e_tc_tun_device_to_offload(struct mlx5e_priv *priv,
75 				    struct net_device *netdev);
76 
77 int mlx5e_tc_tun_parse(struct net_device *filter_dev,
78 		       struct mlx5e_priv *priv,
79 		       struct mlx5_flow_spec *spec,
80 		       struct flow_cls_offload *f,
81 		       u8 *match_level);
82 
83 int mlx5e_tc_tun_parse_udp_ports(struct mlx5e_priv *priv,
84 				 struct mlx5_flow_spec *spec,
85 				 struct flow_cls_offload *f,
86 				 void *headers_c,
87 				 void *headers_v);
88 
89 #endif //__MLX5_EN_TC_TUNNEL_H__
90