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_ROUTER_H_
5 #define _MLXSW_ROUTER_H_
6 
7 #include "spectrum.h"
8 #include "reg.h"
9 
10 struct mlxsw_sp_rif_ipip_lb;
11 struct mlxsw_sp_rif_ipip_lb_config {
12 	enum mlxsw_reg_ritr_loopback_ipip_type lb_ipipt;
13 	u32 okey;
14 	enum mlxsw_sp_l3proto ul_protocol; /* Underlay. */
15 	union mlxsw_sp_l3addr saddr;
16 };
17 
18 enum mlxsw_sp_rif_counter_dir {
19 	MLXSW_SP_RIF_COUNTER_INGRESS,
20 	MLXSW_SP_RIF_COUNTER_EGRESS,
21 };
22 
23 struct mlxsw_sp_neigh_entry;
24 struct mlxsw_sp_nexthop;
25 struct mlxsw_sp_ipip_entry;
26 
27 struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp,
28 					   u16 rif_index);
29 u16 mlxsw_sp_rif_index(const struct mlxsw_sp_rif *rif);
30 u16 mlxsw_sp_ipip_lb_rif_index(const struct mlxsw_sp_rif_ipip_lb *rif);
31 u16 mlxsw_sp_ipip_lb_ul_vr_id(const struct mlxsw_sp_rif_ipip_lb *rif);
32 u32 mlxsw_sp_ipip_dev_ul_tb_id(const struct net_device *ol_dev);
33 int mlxsw_sp_rif_dev_ifindex(const struct mlxsw_sp_rif *rif);
34 const struct net_device *mlxsw_sp_rif_dev(const struct mlxsw_sp_rif *rif);
35 int mlxsw_sp_rif_counter_value_get(struct mlxsw_sp *mlxsw_sp,
36 				   struct mlxsw_sp_rif *rif,
37 				   enum mlxsw_sp_rif_counter_dir dir,
38 				   u64 *cnt);
39 void mlxsw_sp_rif_counter_free(struct mlxsw_sp *mlxsw_sp,
40 			       struct mlxsw_sp_rif *rif,
41 			       enum mlxsw_sp_rif_counter_dir dir);
42 int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp,
43 			       struct mlxsw_sp_rif *rif,
44 			       enum mlxsw_sp_rif_counter_dir dir);
45 struct mlxsw_sp_neigh_entry *
46 mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif,
47 			struct mlxsw_sp_neigh_entry *neigh_entry);
48 int mlxsw_sp_neigh_entry_type(struct mlxsw_sp_neigh_entry *neigh_entry);
49 unsigned char *
50 mlxsw_sp_neigh_entry_ha(struct mlxsw_sp_neigh_entry *neigh_entry);
51 u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
52 struct in6_addr *
53 mlxsw_sp_neigh6_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
54 
55 #define mlxsw_sp_rif_neigh_for_each(neigh_entry, rif)				\
56 	for (neigh_entry = mlxsw_sp_rif_neigh_next(rif, NULL); neigh_entry;	\
57 	     neigh_entry = mlxsw_sp_rif_neigh_next(rif, neigh_entry))
58 int mlxsw_sp_neigh_counter_get(struct mlxsw_sp *mlxsw_sp,
59 			       struct mlxsw_sp_neigh_entry *neigh_entry,
60 			       u64 *p_counter);
61 void
62 mlxsw_sp_neigh_entry_counter_update(struct mlxsw_sp *mlxsw_sp,
63 				    struct mlxsw_sp_neigh_entry *neigh_entry,
64 				    bool adding);
65 bool mlxsw_sp_neigh_ipv6_ignore(struct mlxsw_sp_neigh_entry *neigh_entry);
66 int __mlxsw_sp_ipip_entry_update_tunnel(struct mlxsw_sp *mlxsw_sp,
67 					struct mlxsw_sp_ipip_entry *ipip_entry,
68 					bool recreate_loopback,
69 					bool keep_encap,
70 					bool update_nexthops,
71 					struct netlink_ext_ack *extack);
72 void mlxsw_sp_ipip_entry_demote_tunnel(struct mlxsw_sp *mlxsw_sp,
73 				       struct mlxsw_sp_ipip_entry *ipip_entry);
74 bool
75 mlxsw_sp_ipip_demote_tunnel_by_saddr(struct mlxsw_sp *mlxsw_sp,
76 				     enum mlxsw_sp_l3proto ul_proto,
77 				     union mlxsw_sp_l3addr saddr,
78 				     u32 ul_tb_id,
79 				     const struct mlxsw_sp_ipip_entry *except);
80 struct mlxsw_sp_nexthop *mlxsw_sp_nexthop_next(struct mlxsw_sp_router *router,
81 					       struct mlxsw_sp_nexthop *nh);
82 bool mlxsw_sp_nexthop_offload(struct mlxsw_sp_nexthop *nh);
83 unsigned char *mlxsw_sp_nexthop_ha(struct mlxsw_sp_nexthop *nh);
84 int mlxsw_sp_nexthop_indexes(struct mlxsw_sp_nexthop *nh, u32 *p_adj_index,
85 			     u32 *p_adj_size, u32 *p_adj_hash_index);
86 struct mlxsw_sp_rif *mlxsw_sp_nexthop_rif(struct mlxsw_sp_nexthop *nh);
87 bool mlxsw_sp_nexthop_group_has_ipip(struct mlxsw_sp_nexthop *nh);
88 #define mlxsw_sp_nexthop_for_each(nh, router)				\
89 	for (nh = mlxsw_sp_nexthop_next(router, NULL); nh;		\
90 	     nh = mlxsw_sp_nexthop_next(router, nh))
91 int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
92 				 struct mlxsw_sp_nexthop *nh, u64 *p_counter);
93 int mlxsw_sp_nexthop_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
94 			    struct mlxsw_sp_nexthop *nh);
95 void mlxsw_sp_nexthop_counter_alloc(struct mlxsw_sp *mlxsw_sp,
96 				    struct mlxsw_sp_nexthop *nh);
97 void mlxsw_sp_nexthop_counter_free(struct mlxsw_sp *mlxsw_sp,
98 				   struct mlxsw_sp_nexthop *nh);
99 
100 static inline bool mlxsw_sp_l3addr_eq(const union mlxsw_sp_l3addr *addr1,
101 				      const union mlxsw_sp_l3addr *addr2)
102 {
103 	return !memcmp(addr1, addr2, sizeof(*addr1));
104 }
105 
106 #endif /* _MLXSW_ROUTER_H_*/
107