• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_router_nve_decap {
11 	u32 ul_tb_id;
12 	u32 tunnel_index;
13 	enum mlxsw_sp_l3proto ul_proto;
14 	union mlxsw_sp_l3addr ul_sip;
15 	u8 valid:1;
16 };
17 
18 struct mlxsw_sp_router {
19 	struct mlxsw_sp *mlxsw_sp;
20 	struct mlxsw_sp_rif **rifs;
21 	struct mlxsw_sp_vr *vrs;
22 	struct rhashtable neigh_ht;
23 	struct rhashtable nexthop_group_ht;
24 	struct rhashtable nexthop_ht;
25 	struct list_head nexthop_list;
26 	struct {
27 		/* One tree for each protocol: IPv4 and IPv6 */
28 		struct mlxsw_sp_lpm_tree *proto_trees[2];
29 		struct mlxsw_sp_lpm_tree *trees;
30 		unsigned int tree_count;
31 	} lpm;
32 	struct {
33 		struct delayed_work dw;
34 		unsigned long interval;	/* ms */
35 	} neighs_update;
36 	struct delayed_work nexthop_probe_dw;
37 #define MLXSW_SP_UNRESOLVED_NH_PROBE_INTERVAL 5000 /* ms */
38 	struct list_head nexthop_neighs_list;
39 	struct list_head ipip_list;
40 	bool aborted;
41 	struct notifier_block fib_nb;
42 	struct notifier_block netevent_nb;
43 	struct notifier_block inetaddr_nb;
44 	struct notifier_block inet6addr_nb;
45 	const struct mlxsw_sp_rif_ops **rif_ops_arr;
46 	const struct mlxsw_sp_ipip_ops **ipip_ops_arr;
47 	u32 adj_discard_index;
48 	bool adj_discard_index_valid;
49 	struct mlxsw_sp_router_nve_decap nve_decap_config;
50 	struct mutex lock; /* Protects shared router resources */
51 };
52 
53 struct mlxsw_sp_rif_ipip_lb;
54 struct mlxsw_sp_rif_ipip_lb_config {
55 	enum mlxsw_reg_ritr_loopback_ipip_type lb_ipipt;
56 	u32 okey;
57 	enum mlxsw_sp_l3proto ul_protocol; /* Underlay. */
58 	union mlxsw_sp_l3addr saddr;
59 };
60 
61 enum mlxsw_sp_rif_counter_dir {
62 	MLXSW_SP_RIF_COUNTER_INGRESS,
63 	MLXSW_SP_RIF_COUNTER_EGRESS,
64 };
65 
66 struct mlxsw_sp_neigh_entry;
67 struct mlxsw_sp_nexthop;
68 struct mlxsw_sp_ipip_entry;
69 
70 struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp,
71 					   u16 rif_index);
72 u16 mlxsw_sp_rif_index(const struct mlxsw_sp_rif *rif);
73 u16 mlxsw_sp_ipip_lb_rif_index(const struct mlxsw_sp_rif_ipip_lb *rif);
74 u16 mlxsw_sp_ipip_lb_ul_vr_id(const struct mlxsw_sp_rif_ipip_lb *rif);
75 u16 mlxsw_sp_ipip_lb_ul_rif_id(const struct mlxsw_sp_rif_ipip_lb *lb_rif);
76 u32 mlxsw_sp_ipip_dev_ul_tb_id(const struct net_device *ol_dev);
77 int mlxsw_sp_rif_dev_ifindex(const struct mlxsw_sp_rif *rif);
78 const struct net_device *mlxsw_sp_rif_dev(const struct mlxsw_sp_rif *rif);
79 int mlxsw_sp_rif_counter_value_get(struct mlxsw_sp *mlxsw_sp,
80 				   struct mlxsw_sp_rif *rif,
81 				   enum mlxsw_sp_rif_counter_dir dir,
82 				   u64 *cnt);
83 void mlxsw_sp_rif_counter_free(struct mlxsw_sp *mlxsw_sp,
84 			       struct mlxsw_sp_rif *rif,
85 			       enum mlxsw_sp_rif_counter_dir dir);
86 int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp,
87 			       struct mlxsw_sp_rif *rif,
88 			       enum mlxsw_sp_rif_counter_dir dir);
89 struct mlxsw_sp_neigh_entry *
90 mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif,
91 			struct mlxsw_sp_neigh_entry *neigh_entry);
92 int mlxsw_sp_neigh_entry_type(struct mlxsw_sp_neigh_entry *neigh_entry);
93 unsigned char *
94 mlxsw_sp_neigh_entry_ha(struct mlxsw_sp_neigh_entry *neigh_entry);
95 u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
96 struct in6_addr *
97 mlxsw_sp_neigh6_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
98 
99 #define mlxsw_sp_rif_neigh_for_each(neigh_entry, rif)				\
100 	for (neigh_entry = mlxsw_sp_rif_neigh_next(rif, NULL); neigh_entry;	\
101 	     neigh_entry = mlxsw_sp_rif_neigh_next(rif, neigh_entry))
102 int mlxsw_sp_neigh_counter_get(struct mlxsw_sp *mlxsw_sp,
103 			       struct mlxsw_sp_neigh_entry *neigh_entry,
104 			       u64 *p_counter);
105 void
106 mlxsw_sp_neigh_entry_counter_update(struct mlxsw_sp *mlxsw_sp,
107 				    struct mlxsw_sp_neigh_entry *neigh_entry,
108 				    bool adding);
109 bool mlxsw_sp_neigh_ipv6_ignore(struct mlxsw_sp_neigh_entry *neigh_entry);
110 int __mlxsw_sp_ipip_entry_update_tunnel(struct mlxsw_sp *mlxsw_sp,
111 					struct mlxsw_sp_ipip_entry *ipip_entry,
112 					bool recreate_loopback,
113 					bool keep_encap,
114 					bool update_nexthops,
115 					struct netlink_ext_ack *extack);
116 void mlxsw_sp_ipip_entry_demote_tunnel(struct mlxsw_sp *mlxsw_sp,
117 				       struct mlxsw_sp_ipip_entry *ipip_entry);
118 bool
119 mlxsw_sp_ipip_demote_tunnel_by_saddr(struct mlxsw_sp *mlxsw_sp,
120 				     enum mlxsw_sp_l3proto ul_proto,
121 				     union mlxsw_sp_l3addr saddr,
122 				     u32 ul_tb_id,
123 				     const struct mlxsw_sp_ipip_entry *except);
124 struct mlxsw_sp_nexthop *mlxsw_sp_nexthop_next(struct mlxsw_sp_router *router,
125 					       struct mlxsw_sp_nexthop *nh);
126 bool mlxsw_sp_nexthop_offload(struct mlxsw_sp_nexthop *nh);
127 unsigned char *mlxsw_sp_nexthop_ha(struct mlxsw_sp_nexthop *nh);
128 int mlxsw_sp_nexthop_indexes(struct mlxsw_sp_nexthop *nh, u32 *p_adj_index,
129 			     u32 *p_adj_size, u32 *p_adj_hash_index);
130 struct mlxsw_sp_rif *mlxsw_sp_nexthop_rif(struct mlxsw_sp_nexthop *nh);
131 bool mlxsw_sp_nexthop_group_has_ipip(struct mlxsw_sp_nexthop *nh);
132 #define mlxsw_sp_nexthop_for_each(nh, router)				\
133 	for (nh = mlxsw_sp_nexthop_next(router, NULL); nh;		\
134 	     nh = mlxsw_sp_nexthop_next(router, nh))
135 int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
136 				 struct mlxsw_sp_nexthop *nh, u64 *p_counter);
137 int mlxsw_sp_nexthop_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
138 			    struct mlxsw_sp_nexthop *nh);
139 void mlxsw_sp_nexthop_counter_alloc(struct mlxsw_sp *mlxsw_sp,
140 				    struct mlxsw_sp_nexthop *nh);
141 void mlxsw_sp_nexthop_counter_free(struct mlxsw_sp *mlxsw_sp,
142 				   struct mlxsw_sp_nexthop *nh);
143 
mlxsw_sp_l3addr_eq(const union mlxsw_sp_l3addr * addr1,const union mlxsw_sp_l3addr * addr2)144 static inline bool mlxsw_sp_l3addr_eq(const union mlxsw_sp_l3addr *addr1,
145 				      const union mlxsw_sp_l3addr *addr2)
146 {
147 	return !memcmp(addr1, addr2, sizeof(*addr1));
148 }
149 
150 int mlxsw_sp_ipip_ecn_encap_init(struct mlxsw_sp *mlxsw_sp);
151 int mlxsw_sp_ipip_ecn_decap_init(struct mlxsw_sp *mlxsw_sp);
152 
153 #endif /* _MLXSW_ROUTER_H_*/
154