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 u16 mlxsw_sp_ipip_lb_ul_rif_id(const struct mlxsw_sp_rif_ipip_lb *lb_rif);
33 u32 mlxsw_sp_ipip_dev_ul_tb_id(const struct net_device *ol_dev);
34 int mlxsw_sp_rif_dev_ifindex(const struct mlxsw_sp_rif *rif);
35 const struct net_device *mlxsw_sp_rif_dev(const struct mlxsw_sp_rif *rif);
36 int mlxsw_sp_rif_counter_value_get(struct mlxsw_sp *mlxsw_sp,
37 				   struct mlxsw_sp_rif *rif,
38 				   enum mlxsw_sp_rif_counter_dir dir,
39 				   u64 *cnt);
40 void mlxsw_sp_rif_counter_free(struct mlxsw_sp *mlxsw_sp,
41 			       struct mlxsw_sp_rif *rif,
42 			       enum mlxsw_sp_rif_counter_dir dir);
43 int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp,
44 			       struct mlxsw_sp_rif *rif,
45 			       enum mlxsw_sp_rif_counter_dir dir);
46 struct mlxsw_sp_neigh_entry *
47 mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif,
48 			struct mlxsw_sp_neigh_entry *neigh_entry);
49 int mlxsw_sp_neigh_entry_type(struct mlxsw_sp_neigh_entry *neigh_entry);
50 unsigned char *
51 mlxsw_sp_neigh_entry_ha(struct mlxsw_sp_neigh_entry *neigh_entry);
52 u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
53 struct in6_addr *
54 mlxsw_sp_neigh6_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
55 
56 #define mlxsw_sp_rif_neigh_for_each(neigh_entry, rif)				\
57 	for (neigh_entry = mlxsw_sp_rif_neigh_next(rif, NULL); neigh_entry;	\
58 	     neigh_entry = mlxsw_sp_rif_neigh_next(rif, neigh_entry))
59 int mlxsw_sp_neigh_counter_get(struct mlxsw_sp *mlxsw_sp,
60 			       struct mlxsw_sp_neigh_entry *neigh_entry,
61 			       u64 *p_counter);
62 void
63 mlxsw_sp_neigh_entry_counter_update(struct mlxsw_sp *mlxsw_sp,
64 				    struct mlxsw_sp_neigh_entry *neigh_entry,
65 				    bool adding);
66 bool mlxsw_sp_neigh_ipv6_ignore(struct mlxsw_sp_neigh_entry *neigh_entry);
67 int __mlxsw_sp_ipip_entry_update_tunnel(struct mlxsw_sp *mlxsw_sp,
68 					struct mlxsw_sp_ipip_entry *ipip_entry,
69 					bool recreate_loopback,
70 					bool keep_encap,
71 					bool update_nexthops,
72 					struct netlink_ext_ack *extack);
73 void mlxsw_sp_ipip_entry_demote_tunnel(struct mlxsw_sp *mlxsw_sp,
74 				       struct mlxsw_sp_ipip_entry *ipip_entry);
75 bool
76 mlxsw_sp_ipip_demote_tunnel_by_saddr(struct mlxsw_sp *mlxsw_sp,
77 				     enum mlxsw_sp_l3proto ul_proto,
78 				     union mlxsw_sp_l3addr saddr,
79 				     u32 ul_tb_id,
80 				     const struct mlxsw_sp_ipip_entry *except);
81 struct mlxsw_sp_nexthop *mlxsw_sp_nexthop_next(struct mlxsw_sp_router *router,
82 					       struct mlxsw_sp_nexthop *nh);
83 bool mlxsw_sp_nexthop_offload(struct mlxsw_sp_nexthop *nh);
84 unsigned char *mlxsw_sp_nexthop_ha(struct mlxsw_sp_nexthop *nh);
85 int mlxsw_sp_nexthop_indexes(struct mlxsw_sp_nexthop *nh, u32 *p_adj_index,
86 			     u32 *p_adj_size, u32 *p_adj_hash_index);
87 struct mlxsw_sp_rif *mlxsw_sp_nexthop_rif(struct mlxsw_sp_nexthop *nh);
88 bool mlxsw_sp_nexthop_group_has_ipip(struct mlxsw_sp_nexthop *nh);
89 #define mlxsw_sp_nexthop_for_each(nh, router)				\
90 	for (nh = mlxsw_sp_nexthop_next(router, NULL); nh;		\
91 	     nh = mlxsw_sp_nexthop_next(router, nh))
92 int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
93 				 struct mlxsw_sp_nexthop *nh, u64 *p_counter);
94 int mlxsw_sp_nexthop_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
95 			    struct mlxsw_sp_nexthop *nh);
96 void mlxsw_sp_nexthop_counter_alloc(struct mlxsw_sp *mlxsw_sp,
97 				    struct mlxsw_sp_nexthop *nh);
98 void mlxsw_sp_nexthop_counter_free(struct mlxsw_sp *mlxsw_sp,
99 				   struct mlxsw_sp_nexthop *nh);
100 
101 static inline bool mlxsw_sp_l3addr_eq(const union mlxsw_sp_l3addr *addr1,
102 				      const union mlxsw_sp_l3addr *addr2)
103 {
104 	return !memcmp(addr1, addr2, sizeof(*addr1));
105 }
106 
107 int mlxsw_sp_ipip_ecn_encap_init(struct mlxsw_sp *mlxsw_sp);
108 int mlxsw_sp_ipip_ecn_decap_init(struct mlxsw_sp *mlxsw_sp);
109 
110 #endif /* _MLXSW_ROUTER_H_*/
111