OSDN Git Service

MAINTAINERS: Update the ocores i2c bus driver maintainer, etc
[uclinux-h8/linux.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_rep.h
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
36 #include <net/ip_tunnels.h>
37 #include <linux/rhashtable.h>
38 #include "eswitch.h"
39 #include "en.h"
40
41 #ifdef CONFIG_MLX5_ESWITCH
42 struct mlx5e_neigh_update_table {
43         struct rhashtable       neigh_ht;
44         /* Save the neigh hash entries in a list in addition to the hash table
45          * (neigh_ht). In order to iterate easily over the neigh entries.
46          * Used for stats query.
47          */
48         struct list_head        neigh_list;
49         /* protect lookup/remove operations */
50         spinlock_t              encap_lock;
51         struct notifier_block   netevent_nb;
52         struct delayed_work     neigh_stats_work;
53         unsigned long           min_interval; /* jiffies */
54 };
55
56 struct mlx5_rep_uplink_priv {
57         /* Filters DB - instantiated by the uplink representor and shared by
58          * the uplink's VFs
59          */
60         struct rhashtable  tc_ht;
61
62         /* indirect block callbacks are invoked on bind/unbind events
63          * on registered higher level devices (e.g. tunnel devices)
64          *
65          * tc_indr_block_cb_priv_list is used to lookup indirect callback
66          * private data
67          *
68          * netdevice_nb is the netdev events notifier - used to register
69          * tunnel devices for block events
70          *
71          */
72         struct list_head            tc_indr_block_priv_list;
73         struct notifier_block       netdevice_nb;
74 };
75
76 struct mlx5e_rep_priv {
77         struct mlx5_eswitch_rep *rep;
78         struct mlx5e_neigh_update_table neigh_update;
79         struct net_device      *netdev;
80         struct mlx5_flow_handle *vport_rx_rule;
81         struct list_head       vport_sqs_list;
82         struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
83 };
84
85 static inline
86 struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep)
87 {
88         return (struct mlx5e_rep_priv *)rep->rep_if[REP_ETH].priv;
89 }
90
91 struct mlx5e_neigh {
92         struct net_device *dev;
93         union {
94                 __be32  v4;
95                 struct in6_addr v6;
96         } dst_ip;
97         int family;
98 };
99
100 struct mlx5e_neigh_hash_entry {
101         struct rhash_head rhash_node;
102         struct mlx5e_neigh m_neigh;
103
104         /* Save the neigh hash entry in a list on the representor in
105          * addition to the hash table. In order to iterate easily over the
106          * neighbour entries. Used for stats query.
107          */
108         struct list_head neigh_list;
109
110         /* encap list sharing the same neigh */
111         struct list_head encap_list;
112
113         /* valid only when the neigh reference is taken during
114          * neigh_update_work workqueue callback.
115          */
116         struct neighbour *n;
117         struct work_struct neigh_update_work;
118
119         /* neigh hash entry can be deleted only when the refcount is zero.
120          * refcount is needed to avoid neigh hash entry removal by TC, while
121          * it's used by the neigh notification call.
122          */
123         refcount_t refcnt;
124
125         /* Save the last reported time offloaded trafic pass over one of the
126          * neigh hash entry flows. Use it to periodically update the neigh
127          * 'used' value and avoid neigh deleting by the kernel.
128          */
129         unsigned long reported_lastuse;
130 };
131
132 enum {
133         /* set when the encap entry is successfully offloaded into HW */
134         MLX5_ENCAP_ENTRY_VALID     = BIT(0),
135 };
136
137 struct mlx5e_encap_entry {
138         /* neigh hash entry list of encaps sharing the same neigh */
139         struct list_head encap_list;
140         struct mlx5e_neigh m_neigh;
141         /* a node of the eswitch encap hash table which keeping all the encap
142          * entries
143          */
144         struct hlist_node encap_hlist;
145         struct list_head flows;
146         u32 encap_id;
147         struct ip_tunnel_info tun_info;
148         unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
149
150         struct net_device *out_dev;
151         int tunnel_type;
152         int tunnel_hlen;
153         int reformat_type;
154         u8 flags;
155         char *encap_header;
156         int encap_size;
157 };
158
159 struct mlx5e_rep_sq {
160         struct mlx5_flow_handle *send_to_vport_rule;
161         struct list_head         list;
162 };
163
164 void *mlx5e_alloc_nic_rep_priv(struct mlx5_core_dev *mdev);
165 void mlx5e_rep_register_vport_reps(struct mlx5_core_dev *mdev);
166 void mlx5e_rep_unregister_vport_reps(struct mlx5_core_dev *mdev);
167 bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv);
168 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
169 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
170
171 void mlx5e_handle_rx_cqe_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
172
173 int mlx5e_rep_encap_entry_attach(struct mlx5e_priv *priv,
174                                  struct mlx5e_encap_entry *e);
175 void mlx5e_rep_encap_entry_detach(struct mlx5e_priv *priv,
176                                   struct mlx5e_encap_entry *e);
177
178 void mlx5e_rep_queue_neigh_stats_work(struct mlx5e_priv *priv);
179
180 bool mlx5e_eswitch_rep(struct net_device *netdev);
181
182 #else /* CONFIG_MLX5_ESWITCH */
183 static inline bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv) { return false; }
184 static inline int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv) { return 0; }
185 static inline void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv) {}
186 #endif
187
188 static inline bool mlx5e_is_vport_rep(struct mlx5e_priv *priv)
189 {
190         return (MLX5_ESWITCH_MANAGER(priv->mdev) && priv->ppriv);
191 }
192 #endif /* __MLX5E_REP_H__ */