1
2
3
4#ifndef _MLXSW_ROUTER_H_
5#define _MLXSW_ROUTER_H_
6
7#include "spectrum.h"
8#include "reg.h"
9
10struct 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
18struct mlxsw_sp_fib_entry_op_ctx {
19 u8 bulk_ok:1,
20
21
22
23 initialized:1;
24
25
26 struct list_head fib_entry_priv_list;
27 unsigned long event;
28 unsigned long ll_priv[];
29};
30
31static inline void
32mlxsw_sp_fib_entry_op_ctx_clear(struct mlxsw_sp_fib_entry_op_ctx *op_ctx)
33{
34 WARN_ON_ONCE(!list_empty(&op_ctx->fib_entry_priv_list));
35 memset(op_ctx, 0, sizeof(*op_ctx));
36 INIT_LIST_HEAD(&op_ctx->fib_entry_priv_list);
37}
38
39struct mlxsw_sp_router {
40 struct mlxsw_sp *mlxsw_sp;
41 struct mlxsw_sp_rif **rifs;
42 struct idr rif_mac_profiles_idr;
43 atomic_t rif_mac_profiles_count;
44 u8 max_rif_mac_profile;
45 struct mlxsw_sp_vr *vrs;
46 struct rhashtable neigh_ht;
47 struct rhashtable nexthop_group_ht;
48 struct rhashtable nexthop_ht;
49 struct list_head nexthop_list;
50 struct {
51
52 struct mlxsw_sp_lpm_tree *proto_trees[2];
53 struct mlxsw_sp_lpm_tree *trees;
54 unsigned int tree_count;
55 } lpm;
56 struct {
57 struct delayed_work dw;
58 unsigned long interval;
59 } neighs_update;
60 struct delayed_work nexthop_probe_dw;
61#define MLXSW_SP_UNRESOLVED_NH_PROBE_INTERVAL 5000
62 struct list_head nexthop_neighs_list;
63 struct list_head ipip_list;
64 struct notifier_block nexthop_nb;
65 struct notifier_block fib_nb;
66 struct notifier_block netevent_nb;
67 struct notifier_block inetaddr_nb;
68 struct notifier_block inet6addr_nb;
69 const struct mlxsw_sp_rif_ops **rif_ops_arr;
70 const struct mlxsw_sp_ipip_ops **ipip_ops_arr;
71 struct mlxsw_sp_router_nve_decap nve_decap_config;
72 struct mutex lock;
73 struct work_struct fib_event_work;
74 struct list_head fib_event_queue;
75 spinlock_t fib_event_queue_lock;
76
77 const struct mlxsw_sp_router_ll_ops *proto_ll_ops[MLXSW_SP_L3_PROTO_MAX];
78 struct mlxsw_sp_fib_entry_op_ctx *ll_op_ctx;
79 u16 lb_rif_index;
80 struct mlxsw_sp_router_xm *xm;
81 const struct mlxsw_sp_adj_grp_size_range *adj_grp_size_ranges;
82 size_t adj_grp_size_ranges_count;
83 struct delayed_work nh_grp_activity_dw;
84 struct list_head nh_res_grp_list;
85 bool inc_parsing_depth;
86 refcount_t num_groups;
87 u32 adj_trap_index;
88};
89
90struct mlxsw_sp_fib_entry_priv {
91 refcount_t refcnt;
92 struct list_head list;
93 unsigned long priv[];
94};
95
96enum mlxsw_sp_fib_entry_op {
97 MLXSW_SP_FIB_ENTRY_OP_WRITE,
98 MLXSW_SP_FIB_ENTRY_OP_UPDATE,
99 MLXSW_SP_FIB_ENTRY_OP_DELETE,
100};
101
102
103
104
105struct mlxsw_sp_router_ll_ops {
106 int (*init)(struct mlxsw_sp *mlxsw_sp, u16 vr_id,
107 enum mlxsw_sp_l3proto proto);
108 int (*ralta_write)(struct mlxsw_sp *mlxsw_sp, char *xralta_pl);
109 int (*ralst_write)(struct mlxsw_sp *mlxsw_sp, char *xralst_pl);
110 int (*raltb_write)(struct mlxsw_sp *mlxsw_sp, char *xraltb_pl);
111 size_t fib_entry_op_ctx_size;
112 size_t fib_entry_priv_size;
113 void (*fib_entry_pack)(struct mlxsw_sp_fib_entry_op_ctx *op_ctx,
114 enum mlxsw_sp_l3proto proto, enum mlxsw_sp_fib_entry_op op,
115 u16 virtual_router, u8 prefix_len, unsigned char *addr,
116 struct mlxsw_sp_fib_entry_priv *priv);
117 void (*fib_entry_act_remote_pack)(struct mlxsw_sp_fib_entry_op_ctx *op_ctx,
118 enum mlxsw_reg_ralue_trap_action trap_action,
119 u16 trap_id, u32 adjacency_index, u16 ecmp_size);
120 void (*fib_entry_act_local_pack)(struct mlxsw_sp_fib_entry_op_ctx *op_ctx,
121 enum mlxsw_reg_ralue_trap_action trap_action,
122 u16 trap_id, u16 local_erif);
123 void (*fib_entry_act_ip2me_pack)(struct mlxsw_sp_fib_entry_op_ctx *op_ctx);
124 void (*fib_entry_act_ip2me_tun_pack)(struct mlxsw_sp_fib_entry_op_ctx *op_ctx,
125 u32 tunnel_ptr);
126 int (*fib_entry_commit)(struct mlxsw_sp *mlxsw_sp,
127 struct mlxsw_sp_fib_entry_op_ctx *op_ctx,
128 bool *postponed_for_bulk);
129 bool (*fib_entry_is_committed)(struct mlxsw_sp_fib_entry_priv *priv);
130};
131
132struct mlxsw_sp_rif_ipip_lb;
133struct mlxsw_sp_rif_ipip_lb_config {
134 enum mlxsw_reg_ritr_loopback_ipip_type lb_ipipt;
135 u32 okey;
136 enum mlxsw_sp_l3proto ul_protocol;
137 union mlxsw_sp_l3addr saddr;
138};
139
140enum mlxsw_sp_rif_counter_dir {
141 MLXSW_SP_RIF_COUNTER_INGRESS,
142 MLXSW_SP_RIF_COUNTER_EGRESS,
143};
144
145struct mlxsw_sp_neigh_entry;
146struct mlxsw_sp_nexthop;
147struct mlxsw_sp_ipip_entry;
148
149struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp,
150 u16 rif_index);
151u16 mlxsw_sp_rif_index(const struct mlxsw_sp_rif *rif);
152u16 mlxsw_sp_ipip_lb_rif_index(const struct mlxsw_sp_rif_ipip_lb *rif);
153u16 mlxsw_sp_ipip_lb_ul_vr_id(const struct mlxsw_sp_rif_ipip_lb *rif);
154u16 mlxsw_sp_ipip_lb_ul_rif_id(const struct mlxsw_sp_rif_ipip_lb *lb_rif);
155u32 mlxsw_sp_ipip_dev_ul_tb_id(const struct net_device *ol_dev);
156int mlxsw_sp_rif_dev_ifindex(const struct mlxsw_sp_rif *rif);
157const struct net_device *mlxsw_sp_rif_dev(const struct mlxsw_sp_rif *rif);
158int mlxsw_sp_rif_counter_value_get(struct mlxsw_sp *mlxsw_sp,
159 struct mlxsw_sp_rif *rif,
160 enum mlxsw_sp_rif_counter_dir dir,
161 u64 *cnt);
162void mlxsw_sp_rif_counter_free(struct mlxsw_sp *mlxsw_sp,
163 struct mlxsw_sp_rif *rif,
164 enum mlxsw_sp_rif_counter_dir dir);
165int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp,
166 struct mlxsw_sp_rif *rif,
167 enum mlxsw_sp_rif_counter_dir dir);
168struct mlxsw_sp_neigh_entry *
169mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif,
170 struct mlxsw_sp_neigh_entry *neigh_entry);
171int mlxsw_sp_neigh_entry_type(struct mlxsw_sp_neigh_entry *neigh_entry);
172unsigned char *
173mlxsw_sp_neigh_entry_ha(struct mlxsw_sp_neigh_entry *neigh_entry);
174u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
175struct in6_addr *
176mlxsw_sp_neigh6_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
177
178#define mlxsw_sp_rif_neigh_for_each(neigh_entry, rif) \
179 for (neigh_entry = mlxsw_sp_rif_neigh_next(rif, NULL); neigh_entry; \
180 neigh_entry = mlxsw_sp_rif_neigh_next(rif, neigh_entry))
181int mlxsw_sp_neigh_counter_get(struct mlxsw_sp *mlxsw_sp,
182 struct mlxsw_sp_neigh_entry *neigh_entry,
183 u64 *p_counter);
184void
185mlxsw_sp_neigh_entry_counter_update(struct mlxsw_sp *mlxsw_sp,
186 struct mlxsw_sp_neigh_entry *neigh_entry,
187 bool adding);
188bool mlxsw_sp_neigh_ipv6_ignore(struct mlxsw_sp_neigh_entry *neigh_entry);
189int __mlxsw_sp_ipip_entry_update_tunnel(struct mlxsw_sp *mlxsw_sp,
190 struct mlxsw_sp_ipip_entry *ipip_entry,
191 bool recreate_loopback,
192 bool keep_encap,
193 bool update_nexthops,
194 struct netlink_ext_ack *extack);
195void mlxsw_sp_ipip_entry_demote_tunnel(struct mlxsw_sp *mlxsw_sp,
196 struct mlxsw_sp_ipip_entry *ipip_entry);
197bool
198mlxsw_sp_ipip_demote_tunnel_by_saddr(struct mlxsw_sp *mlxsw_sp,
199 enum mlxsw_sp_l3proto ul_proto,
200 union mlxsw_sp_l3addr saddr,
201 u32 ul_tb_id,
202 const struct mlxsw_sp_ipip_entry *except);
203struct mlxsw_sp_nexthop *mlxsw_sp_nexthop_next(struct mlxsw_sp_router *router,
204 struct mlxsw_sp_nexthop *nh);
205bool mlxsw_sp_nexthop_is_forward(const struct mlxsw_sp_nexthop *nh);
206unsigned char *mlxsw_sp_nexthop_ha(struct mlxsw_sp_nexthop *nh);
207int mlxsw_sp_nexthop_indexes(struct mlxsw_sp_nexthop *nh, u32 *p_adj_index,
208 u32 *p_adj_size, u32 *p_adj_hash_index);
209struct mlxsw_sp_rif *mlxsw_sp_nexthop_rif(struct mlxsw_sp_nexthop *nh);
210bool mlxsw_sp_nexthop_group_has_ipip(struct mlxsw_sp_nexthop *nh);
211#define mlxsw_sp_nexthop_for_each(nh, router) \
212 for (nh = mlxsw_sp_nexthop_next(router, NULL); nh; \
213 nh = mlxsw_sp_nexthop_next(router, nh))
214int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
215 struct mlxsw_sp_nexthop *nh, u64 *p_counter);
216int mlxsw_sp_nexthop_eth_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
217 struct mlxsw_sp_nexthop *nh, bool force,
218 char *ratr_pl);
219void mlxsw_sp_nexthop_counter_alloc(struct mlxsw_sp *mlxsw_sp,
220 struct mlxsw_sp_nexthop *nh);
221void mlxsw_sp_nexthop_counter_free(struct mlxsw_sp *mlxsw_sp,
222 struct mlxsw_sp_nexthop *nh);
223
224static inline bool mlxsw_sp_l3addr_eq(const union mlxsw_sp_l3addr *addr1,
225 const union mlxsw_sp_l3addr *addr2)
226{
227 return !memcmp(addr1, addr2, sizeof(*addr1));
228}
229
230int mlxsw_sp_ipip_ecn_encap_init(struct mlxsw_sp *mlxsw_sp);
231int mlxsw_sp_ipip_ecn_decap_init(struct mlxsw_sp *mlxsw_sp);
232struct net_device *
233mlxsw_sp_ipip_netdev_ul_dev_get(const struct net_device *ol_dev);
234
235extern const struct mlxsw_sp_router_ll_ops mlxsw_sp_router_ll_xm_ops;
236
237int mlxsw_sp_router_xm_init(struct mlxsw_sp *mlxsw_sp);
238void mlxsw_sp_router_xm_fini(struct mlxsw_sp *mlxsw_sp);
239bool mlxsw_sp_router_xm_ipv4_is_supported(const struct mlxsw_sp *mlxsw_sp);
240
241#endif
242