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_tc_tunnel { 25 int tunnel_type; 26 enum mlx5_flow_match_level match_level; 27 28 bool (*can_offload)(struct mlx5e_priv *priv); 29 int (*calc_hlen)(struct mlx5e_encap_entry *e); 30 int (*init_encap_attr)(struct net_device *tunnel_dev, 31 struct mlx5e_priv *priv, 32 struct mlx5e_encap_entry *e, 33 struct netlink_ext_ack *extack); 34 int (*generate_ip_tun_hdr)(char buf[], 35 __u8 *ip_proto, 36 struct mlx5e_encap_entry *e); 37 int (*parse_udp_ports)(struct mlx5e_priv *priv, 38 struct mlx5_flow_spec *spec, 39 struct flow_cls_offload *f, 40 void *headers_c, 41 void *headers_v); 42 int (*parse_tunnel)(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 }; 48 49 extern struct mlx5e_tc_tunnel vxlan_tunnel; 50 extern struct mlx5e_tc_tunnel geneve_tunnel; 51 extern struct mlx5e_tc_tunnel gre_tunnel; 52 extern struct mlx5e_tc_tunnel mplsoudp_tunnel; 53 54 struct mlx5e_tc_tunnel *mlx5e_get_tc_tun(struct net_device *tunnel_dev); 55 56 int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev, 57 struct mlx5e_priv *priv, 58 struct mlx5e_encap_entry *e, 59 struct netlink_ext_ack *extack); 60 61 int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, 62 struct net_device *mirred_dev, 63 struct mlx5e_encap_entry *e); 64 int mlx5e_tc_tun_update_header_ipv4(struct mlx5e_priv *priv, 65 struct net_device *mirred_dev, 66 struct mlx5e_encap_entry *e); 67 68 #if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6) 69 int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, 70 struct net_device *mirred_dev, 71 struct mlx5e_encap_entry *e); 72 int mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv *priv, 73 struct net_device *mirred_dev, 74 struct mlx5e_encap_entry *e); 75 #else 76 static inline int 77 mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, 78 struct net_device *mirred_dev, 79 struct mlx5e_encap_entry *e) { return -EOPNOTSUPP; } 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 { return -EOPNOTSUPP; } 84 #endif 85 int mlx5e_tc_tun_route_lookup(struct mlx5e_priv *priv, 86 struct mlx5_flow_spec *spec, 87 struct mlx5_flow_attr *attr); 88 89 bool mlx5e_tc_tun_device_to_offload(struct mlx5e_priv *priv, 90 struct net_device *netdev); 91 92 int mlx5e_tc_tun_parse(struct net_device *filter_dev, 93 struct mlx5e_priv *priv, 94 struct mlx5_flow_spec *spec, 95 struct flow_cls_offload *f, 96 u8 *match_level); 97 98 int mlx5e_tc_tun_parse_udp_ports(struct mlx5e_priv *priv, 99 struct mlx5_flow_spec *spec, 100 struct flow_cls_offload *f, 101 void *headers_c, 102 void *headers_v); 103 104 #endif /* CONFIG_MLX5_ESWITCH */ 105 106 #endif //__MLX5_EN_TC_TUNNEL_H__ 107