2 * Copyright (c) 2017, Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
33 #ifndef __MLX5E_REP_H__
34 #define __MLX5E_REP_H__
36 #include <net/ip_tunnels.h>
37 #include <linux/rhashtable.h>
38 #include <linux/mutex.h>
41 #include "lib/port_tun.h"
43 #ifdef CONFIG_MLX5_ESWITCH
44 struct mlx5e_neigh_update_table {
45 struct rhashtable neigh_ht;
46 /* Save the neigh hash entries in a list in addition to the hash table
47 * (neigh_ht). In order to iterate easily over the neigh entries.
48 * Used for stats query.
50 struct list_head neigh_list;
51 /* protect lookup/remove operations */
52 struct mutex encap_lock;
53 struct notifier_block netevent_nb;
54 struct delayed_work neigh_stats_work;
55 unsigned long min_interval; /* jiffies */
58 struct mlx5_rep_uplink_priv {
59 /* Filters DB - instantiated by the uplink representor and shared by
62 struct rhashtable tc_ht;
64 /* indirect block callbacks are invoked on bind/unbind events
65 * on registered higher level devices (e.g. tunnel devices)
67 * tc_indr_block_cb_priv_list is used to lookup indirect callback
70 * netdevice_nb is the netdev events notifier - used to register
71 * tunnel devices for block events
74 struct list_head tc_indr_block_priv_list;
75 struct notifier_block netdevice_nb;
76 struct netdev_net_notifier netdevice_nn;
78 struct mlx5_tun_entropy tun_entropy;
80 /* protects unready_flows */
81 struct mutex unready_flows_lock;
82 struct list_head unready_flows;
83 struct work_struct reoffload_flows_work;
86 struct mlx5e_rep_priv {
87 struct mlx5_eswitch_rep *rep;
88 struct mlx5e_neigh_update_table neigh_update;
89 struct net_device *netdev;
90 struct mlx5_flow_handle *vport_rx_rule;
91 struct list_head vport_sqs_list;
92 struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
93 struct rtnl_link_stats64 prev_vf_vport_stats;
94 struct devlink_port dl_port;
98 struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep)
100 return rep->rep_data[REP_ETH].priv;
104 struct net_device *dev;
112 struct mlx5e_neigh_hash_entry {
113 struct rhash_head rhash_node;
114 struct mlx5e_neigh m_neigh;
115 struct mlx5e_priv *priv;
117 /* Save the neigh hash entry in a list on the representor in
118 * addition to the hash table. In order to iterate easily over the
119 * neighbour entries. Used for stats query.
121 struct list_head neigh_list;
123 /* protects encap list */
124 spinlock_t encap_list_lock;
125 /* encap list sharing the same neigh */
126 struct list_head encap_list;
128 /* valid only when the neigh reference is taken during
129 * neigh_update_work workqueue callback.
132 struct work_struct neigh_update_work;
134 /* neigh hash entry can be deleted only when the refcount is zero.
135 * refcount is needed to avoid neigh hash entry removal by TC, while
136 * it's used by the neigh notification call.
140 /* Save the last reported time offloaded trafic pass over one of the
141 * neigh hash entry flows. Use it to periodically update the neigh
142 * 'used' value and avoid neigh deleting by the kernel.
144 unsigned long reported_lastuse;
150 /* set when the encap entry is successfully offloaded into HW */
151 MLX5_ENCAP_ENTRY_VALID = BIT(0),
154 struct mlx5e_encap_entry {
155 /* attached neigh hash entry */
156 struct mlx5e_neigh_hash_entry *nhe;
157 /* neigh hash entry list of encaps sharing the same neigh */
158 struct list_head encap_list;
159 struct mlx5e_neigh m_neigh;
160 /* a node of the eswitch encap hash table which keeping all the encap
163 struct hlist_node encap_hlist;
164 struct list_head flows;
165 struct mlx5_pkt_reformat *pkt_reformat;
166 const struct ip_tunnel_info *tun_info;
167 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
169 struct net_device *out_dev;
170 struct net_device *route_dev;
171 struct mlx5e_tc_tunnel *tunnel;
177 struct completion res_ready;
182 struct mlx5e_rep_sq {
183 struct mlx5_flow_handle *send_to_vport_rule;
184 struct list_head list;
187 void mlx5e_rep_register_vport_reps(struct mlx5_core_dev *mdev);
188 void mlx5e_rep_unregister_vport_reps(struct mlx5_core_dev *mdev);
189 bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv);
190 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
191 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
193 void mlx5e_handle_rx_cqe_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
195 int mlx5e_rep_encap_entry_attach(struct mlx5e_priv *priv,
196 struct mlx5e_encap_entry *e);
197 void mlx5e_rep_encap_entry_detach(struct mlx5e_priv *priv,
198 struct mlx5e_encap_entry *e);
200 void mlx5e_rep_queue_neigh_stats_work(struct mlx5e_priv *priv);
202 bool mlx5e_eswitch_rep(struct net_device *netdev);
204 #else /* CONFIG_MLX5_ESWITCH */
205 static inline bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv) { return false; }
206 static inline int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv) { return 0; }
207 static inline void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv) {}
210 static inline bool mlx5e_is_vport_rep(struct mlx5e_priv *priv)
212 return (MLX5_ESWITCH_MANAGER(priv->mdev) && priv->ppriv);
214 #endif /* __MLX5E_REP_H__ */