GNU Linux-libre 4.14.332-gnu1
[releases.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 mlx5e_rep_priv {
57         struct mlx5_eswitch_rep *rep;
58         struct mlx5e_neigh_update_table neigh_update;
59 };
60
61 struct mlx5e_neigh {
62         struct net_device *dev;
63         union {
64                 __be32  v4;
65                 struct in6_addr v6;
66         } dst_ip;
67         int family;
68 };
69
70 struct mlx5e_neigh_hash_entry {
71         struct rhash_head rhash_node;
72         struct mlx5e_neigh m_neigh;
73
74         /* Save the neigh hash entry in a list on the representor in
75          * addition to the hash table. In order to iterate easily over the
76          * neighbour entries. Used for stats query.
77          */
78         struct list_head neigh_list;
79
80         /* encap list sharing the same neigh */
81         struct list_head encap_list;
82
83         /* valid only when the neigh reference is taken during
84          * neigh_update_work workqueue callback.
85          */
86         struct neighbour *n;
87         struct work_struct neigh_update_work;
88
89         /* neigh hash entry can be deleted only when the refcount is zero.
90          * refcount is needed to avoid neigh hash entry removal by TC, while
91          * it's used by the neigh notification call.
92          */
93         refcount_t refcnt;
94
95         /* Save the last reported time offloaded trafic pass over one of the
96          * neigh hash entry flows. Use it to periodically update the neigh
97          * 'used' value and avoid neigh deleting by the kernel.
98          */
99         unsigned long reported_lastuse;
100 };
101
102 enum {
103         /* set when the encap entry is successfully offloaded into HW */
104         MLX5_ENCAP_ENTRY_VALID     = BIT(0),
105 };
106
107 struct mlx5e_encap_entry {
108         /* neigh hash entry list of encaps sharing the same neigh */
109         struct list_head encap_list;
110         struct mlx5e_neigh m_neigh;
111         /* a node of the eswitch encap hash table which keeping all the encap
112          * entries
113          */
114         struct hlist_node encap_hlist;
115         struct list_head flows;
116         u32 encap_id;
117         struct ip_tunnel_info tun_info;
118         unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
119
120         struct net_device *out_dev;
121         int tunnel_type;
122         u8 flags;
123         char *encap_header;
124         int encap_size;
125 };
126
127 void *mlx5e_alloc_nic_rep_priv(struct mlx5_core_dev *mdev);
128 void mlx5e_register_vport_reps(struct mlx5e_priv *priv);
129 void mlx5e_unregister_vport_reps(struct mlx5e_priv *priv);
130 bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv);
131 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
132 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
133
134 int mlx5e_get_offload_stats(int attr_id, const struct net_device *dev, void *sp);
135 bool mlx5e_has_offload_stats(const struct net_device *dev, int attr_id);
136
137 int mlx5e_attr_get(struct net_device *dev, struct switchdev_attr *attr);
138 void mlx5e_handle_rx_cqe_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
139
140 int mlx5e_rep_encap_entry_attach(struct mlx5e_priv *priv,
141                                  struct mlx5e_encap_entry *e);
142 void mlx5e_rep_encap_entry_detach(struct mlx5e_priv *priv,
143                                   struct mlx5e_encap_entry *e);
144
145 void mlx5e_rep_queue_neigh_stats_work(struct mlx5e_priv *priv);
146 #else /* CONFIG_MLX5_ESWITCH */
147 static inline void mlx5e_register_vport_reps(struct mlx5e_priv *priv) {}
148 static inline void mlx5e_unregister_vport_reps(struct mlx5e_priv *priv) {}
149 static inline bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv) { return false; }
150 static inline int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv) { return 0; }
151 static inline void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv) {}
152 #endif
153
154 #endif /* __MLX5E_REP_H__ */