xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
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 	int (*get_remote_ifindex)(struct net_device *mirred_dev);
55 };
56 
57 extern struct mlx5e_tc_tunnel vxlan_tunnel;
58 extern struct mlx5e_tc_tunnel geneve_tunnel;
59 extern struct mlx5e_tc_tunnel gre_tunnel;
60 extern struct mlx5e_tc_tunnel mplsoudp_tunnel;
61 
62 struct mlx5e_tc_tunnel *mlx5e_get_tc_tun(struct net_device *tunnel_dev);
63 
64 int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev,
65 				 struct mlx5e_priv *priv,
66 				 struct mlx5e_encap_entry *e,
67 				 struct netlink_ext_ack *extack);
68 
69 int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
70 				    struct net_device *mirred_dev,
71 				    struct mlx5e_encap_entry *e);
72 int mlx5e_tc_tun_update_header_ipv4(struct mlx5e_priv *priv,
73 				    struct net_device *mirred_dev,
74 				    struct mlx5e_encap_entry *e);
75 
76 #if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6)
77 int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
78 				    struct net_device *mirred_dev,
79 				    struct mlx5e_encap_entry *e);
80 int mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv *priv,
81 				    struct net_device *mirred_dev,
82 				    struct mlx5e_encap_entry *e);
83 #else
84 static inline int
mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv * priv,struct net_device * mirred_dev,struct mlx5e_encap_entry * e)85 mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
86 				struct net_device *mirred_dev,
87 				struct mlx5e_encap_entry *e)
88 { return -EOPNOTSUPP; }
89 static inline int
mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv * priv,struct net_device * mirred_dev,struct mlx5e_encap_entry * e)90 mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv *priv,
91 				struct net_device *mirred_dev,
92 				struct mlx5e_encap_entry *e)
93 { return -EOPNOTSUPP; }
94 #endif
95 int mlx5e_tc_tun_route_lookup(struct mlx5e_priv *priv,
96 			      struct mlx5_flow_spec *spec,
97 			      struct mlx5_flow_attr *attr,
98 			      struct net_device *filter_dev);
99 
100 bool mlx5e_tc_tun_device_to_offload(struct mlx5e_priv *priv,
101 				    struct net_device *netdev);
102 
103 int mlx5e_tc_tun_parse(struct net_device *filter_dev,
104 		       struct mlx5e_priv *priv,
105 		       struct mlx5_flow_spec *spec,
106 		       struct flow_cls_offload *f,
107 		       u8 *match_level);
108 
109 int mlx5e_tc_tun_parse_udp_ports(struct mlx5e_priv *priv,
110 				 struct mlx5_flow_spec *spec,
111 				 struct flow_cls_offload *f,
112 				 void *headers_c,
113 				 void *headers_v);
114 
115 bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,
116 					   struct mlx5e_encap_key *b);
117 
118 bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a,
119 					   struct mlx5e_encap_key *b,
120 					   u32 tun_type);
121 #endif /* CONFIG_MLX5_ESWITCH */
122 
123 #endif //__MLX5_EN_TC_TUNNEL_H__
124