1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
3 
4 #ifndef _MLXSW_IPIP_H_
5 #define _MLXSW_IPIP_H_
6 
7 #include "spectrum_router.h"
8 #include <net/ip_fib.h>
9 #include <linux/if_tunnel.h>
10 
11 struct ip_tunnel_parm
12 mlxsw_sp_ipip_netdev_parms4(const struct net_device *ol_dev);
13 struct __ip6_tnl_parm
14 mlxsw_sp_ipip_netdev_parms6(const struct net_device *ol_dev);
15 
16 union mlxsw_sp_l3addr
17 mlxsw_sp_ipip_netdev_saddr(enum mlxsw_sp_l3proto proto,
18 			   const struct net_device *ol_dev);
19 
20 bool mlxsw_sp_l3addr_is_zero(union mlxsw_sp_l3addr addr);
21 
22 enum mlxsw_sp_ipip_type {
23 	MLXSW_SP_IPIP_TYPE_GRE4,
24 	MLXSW_SP_IPIP_TYPE_MAX,
25 };
26 
27 struct mlxsw_sp_ipip_entry {
28 	enum mlxsw_sp_ipip_type ipipt;
29 	struct net_device *ol_dev; /* Overlay. */
30 	struct mlxsw_sp_rif_ipip_lb *ol_lb;
31 	struct mlxsw_sp_fib_entry *decap_fib_entry;
32 	struct list_head ipip_list_node;
33 	union {
34 		struct ip_tunnel_parm parms4;
35 	};
36 };
37 
38 struct mlxsw_sp_ipip_ops {
39 	int dev_type;
40 	enum mlxsw_sp_l3proto ul_proto; /* Underlay. */
41 
42 	int (*nexthop_update)(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
43 			      struct mlxsw_sp_ipip_entry *ipip_entry);
44 
45 	bool (*can_offload)(const struct mlxsw_sp *mlxsw_sp,
46 			    const struct net_device *ol_dev);
47 
48 	/* Return a configuration for creating an overlay loopback RIF. */
49 	struct mlxsw_sp_rif_ipip_lb_config
50 	(*ol_loopback_config)(struct mlxsw_sp *mlxsw_sp,
51 			      const struct net_device *ol_dev);
52 
53 	int (*decap_config)(struct mlxsw_sp *mlxsw_sp,
54 			    struct mlxsw_sp_ipip_entry *ipip_entry,
55 			    u32 tunnel_index);
56 
57 	int (*ol_netdev_change)(struct mlxsw_sp *mlxsw_sp,
58 				struct mlxsw_sp_ipip_entry *ipip_entry,
59 				struct netlink_ext_ack *extack);
60 };
61 
62 extern const struct mlxsw_sp_ipip_ops *mlxsw_sp_ipip_ops_arr[];
63 
64 #endif /* _MLXSW_IPIP_H_*/
65