Commit | Line | Data |
---|---|---|
1d447a39 SM |
1 | /* |
2 | * Copyright (c) 2017, Mellanox Technologies. All rights reserved. | |
3 | * | |
4 | * This software is available to you under a choice of one of two | |
5 | * licenses. You may choose to be licensed under the terms of the GNU | |
6 | * General Public License (GPL) Version 2, available from the file | |
7 | * COPYING in the main directory of this source tree, or the | |
8 | * OpenIB.org BSD license below: | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or | |
11 | * without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistributions of source code must retain the above | |
15 | * copyright notice, this list of conditions and the following | |
16 | * disclaimer. | |
17 | * | |
18 | * - Redistributions in binary form must reproduce the above | |
19 | * copyright notice, this list of conditions and the following | |
20 | * disclaimer in the documentation and/or other materials | |
21 | * provided with the distribution. | |
22 | * | |
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
30 | * SOFTWARE. | |
31 | */ | |
32 | ||
33 | #ifndef __MLX5E_REP_H__ | |
34 | #define __MLX5E_REP_H__ | |
35 | ||
c1ae1152 | 36 | #include <net/ip_tunnels.h> |
37b498ff | 37 | #include <linux/rhashtable.h> |
1d447a39 SM |
38 | #include "eswitch.h" |
39 | #include "en.h" | |
97417f61 | 40 | #include "lib/port_tun.h" |
1d447a39 | 41 | |
e80541ec | 42 | #ifdef CONFIG_MLX5_ESWITCH |
37b498ff HHZ |
43 | struct mlx5e_neigh_update_table { |
44 | struct rhashtable neigh_ht; | |
45 | /* Save the neigh hash entries in a list in addition to the hash table | |
46 | * (neigh_ht). In order to iterate easily over the neigh entries. | |
47 | * Used for stats query. | |
48 | */ | |
49 | struct list_head neigh_list; | |
232c0013 HHZ |
50 | /* protect lookup/remove operations */ |
51 | spinlock_t encap_lock; | |
52 | struct notifier_block netevent_nb; | |
f6dfb4c3 HHZ |
53 | struct delayed_work neigh_stats_work; |
54 | unsigned long min_interval; /* jiffies */ | |
37b498ff HHZ |
55 | }; |
56 | ||
ec1366c2 OS |
57 | struct mlx5_rep_uplink_priv { |
58 | /* Filters DB - instantiated by the uplink representor and shared by | |
59 | * the uplink's VFs | |
60 | */ | |
61 | struct rhashtable tc_ht; | |
f5bc2c5d OS |
62 | |
63 | /* indirect block callbacks are invoked on bind/unbind events | |
64 | * on registered higher level devices (e.g. tunnel devices) | |
65 | * | |
66 | * tc_indr_block_cb_priv_list is used to lookup indirect callback | |
67 | * private data | |
68 | * | |
69 | * netdevice_nb is the netdev events notifier - used to register | |
70 | * tunnel devices for block events | |
71 | * | |
72 | */ | |
73 | struct list_head tc_indr_block_priv_list; | |
74 | struct notifier_block netdevice_nb; | |
97417f61 EB |
75 | |
76 | struct mlx5_tun_entropy tun_entropy; | |
b4a23329 RD |
77 | |
78 | struct list_head unready_flows; | |
79 | struct work_struct reoffload_flows_work; | |
ec1366c2 OS |
80 | }; |
81 | ||
1d447a39 SM |
82 | struct mlx5e_rep_priv { |
83 | struct mlx5_eswitch_rep *rep; | |
37b498ff | 84 | struct mlx5e_neigh_update_table neigh_update; |
5ed99fb4 MB |
85 | struct net_device *netdev; |
86 | struct mlx5_flow_handle *vport_rx_rule; | |
87 | struct list_head vport_sqs_list; | |
ec1366c2 | 88 | struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */ |
f60f315d | 89 | struct devlink_port dl_port; |
37b498ff HHZ |
90 | }; |
91 | ||
5ed99fb4 MB |
92 | static inline |
93 | struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep) | |
94 | { | |
8693115a | 95 | return rep->rep_data[REP_ETH].priv; |
5ed99fb4 MB |
96 | } |
97 | ||
37b498ff HHZ |
98 | struct mlx5e_neigh { |
99 | struct net_device *dev; | |
100 | union { | |
101 | __be32 v4; | |
102 | struct in6_addr v6; | |
103 | } dst_ip; | |
f6dfb4c3 | 104 | int family; |
37b498ff HHZ |
105 | }; |
106 | ||
107 | struct mlx5e_neigh_hash_entry { | |
108 | struct rhash_head rhash_node; | |
109 | struct mlx5e_neigh m_neigh; | |
110 | ||
111 | /* Save the neigh hash entry in a list on the representor in | |
112 | * addition to the hash table. In order to iterate easily over the | |
113 | * neighbour entries. Used for stats query. | |
114 | */ | |
115 | struct list_head neigh_list; | |
232c0013 HHZ |
116 | |
117 | /* encap list sharing the same neigh */ | |
118 | struct list_head encap_list; | |
119 | ||
120 | /* valid only when the neigh reference is taken during | |
121 | * neigh_update_work workqueue callback. | |
122 | */ | |
123 | struct neighbour *n; | |
124 | struct work_struct neigh_update_work; | |
125 | ||
126 | /* neigh hash entry can be deleted only when the refcount is zero. | |
127 | * refcount is needed to avoid neigh hash entry removal by TC, while | |
128 | * it's used by the neigh notification call. | |
129 | */ | |
130 | refcount_t refcnt; | |
f6dfb4c3 HHZ |
131 | |
132 | /* Save the last reported time offloaded trafic pass over one of the | |
133 | * neigh hash entry flows. Use it to periodically update the neigh | |
134 | * 'used' value and avoid neigh deleting by the kernel. | |
135 | */ | |
136 | unsigned long reported_lastuse; | |
232c0013 HHZ |
137 | }; |
138 | ||
139 | enum { | |
140 | /* set when the encap entry is successfully offloaded into HW */ | |
141 | MLX5_ENCAP_ENTRY_VALID = BIT(0), | |
1d447a39 SM |
142 | }; |
143 | ||
c1ae1152 | 144 | struct mlx5e_encap_entry { |
232c0013 HHZ |
145 | /* neigh hash entry list of encaps sharing the same neigh */ |
146 | struct list_head encap_list; | |
147 | struct mlx5e_neigh m_neigh; | |
148 | /* a node of the eswitch encap hash table which keeping all the encap | |
149 | * entries | |
150 | */ | |
c1ae1152 OG |
151 | struct hlist_node encap_hlist; |
152 | struct list_head flows; | |
153 | u32 encap_id; | |
1f6da306 | 154 | const struct ip_tunnel_info *tun_info; |
c1ae1152 OG |
155 | unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ |
156 | ||
157 | struct net_device *out_dev; | |
6707f74b | 158 | struct net_device *route_dev; |
d386939a | 159 | struct mlx5e_tc_tunnel *tunnel; |
54c177ca | 160 | int reformat_type; |
232c0013 HHZ |
161 | u8 flags; |
162 | char *encap_header; | |
163 | int encap_size; | |
c1ae1152 OG |
164 | }; |
165 | ||
2c47bf80 MB |
166 | struct mlx5e_rep_sq { |
167 | struct mlx5_flow_handle *send_to_vport_rule; | |
168 | struct list_head list; | |
169 | }; | |
170 | ||
07c9f1e5 | 171 | void *mlx5e_alloc_nic_rep_priv(struct mlx5_core_dev *mdev); |
aec002f6 OG |
172 | void mlx5e_rep_register_vport_reps(struct mlx5_core_dev *mdev); |
173 | void mlx5e_rep_unregister_vport_reps(struct mlx5_core_dev *mdev); | |
1d447a39 SM |
174 | bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv); |
175 | int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv); | |
176 | void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv); | |
177 | ||
1d447a39 SM |
178 | void mlx5e_handle_rx_cqe_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe); |
179 | ||
232c0013 HHZ |
180 | int mlx5e_rep_encap_entry_attach(struct mlx5e_priv *priv, |
181 | struct mlx5e_encap_entry *e); | |
182 | void mlx5e_rep_encap_entry_detach(struct mlx5e_priv *priv, | |
183 | struct mlx5e_encap_entry *e); | |
184 | ||
f6dfb4c3 | 185 | void mlx5e_rep_queue_neigh_stats_work(struct mlx5e_priv *priv); |
a0646c88 EB |
186 | |
187 | bool mlx5e_eswitch_rep(struct net_device *netdev); | |
188 | ||
e80541ec | 189 | #else /* CONFIG_MLX5_ESWITCH */ |
e80541ec SM |
190 | static inline bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv) { return false; } |
191 | static inline int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv) { return 0; } | |
192 | static inline void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv) {} | |
193 | #endif | |
f6dfb4c3 | 194 | |
d9ee0491 OG |
195 | static inline bool mlx5e_is_vport_rep(struct mlx5e_priv *priv) |
196 | { | |
197 | return (MLX5_ESWITCH_MANAGER(priv->mdev) && priv->ppriv); | |
198 | } | |
1d447a39 | 199 | #endif /* __MLX5E_REP_H__ */ |