Merge tag 'perf-core-for-mingo-4.21-20190104' of git://git.kernel.org/pub/scm/linux...
[sfrench/cifs-2.6.git] / drivers / infiniband / core / core_priv.h
1 /*
2  * Copyright (c) 2004 Topspin Communications.  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 _CORE_PRIV_H
34 #define _CORE_PRIV_H
35
36 #include <linux/list.h>
37 #include <linux/spinlock.h>
38 #include <linux/cgroup_rdma.h>
39
40 #include <rdma/ib_verbs.h>
41 #include <rdma/opa_addr.h>
42 #include <rdma/ib_mad.h>
43 #include <rdma/restrack.h>
44 #include "mad_priv.h"
45
46 /* Total number of ports combined across all struct ib_devices's */
47 #define RDMA_MAX_PORTS 8192
48
49 struct pkey_index_qp_list {
50         struct list_head    pkey_index_list;
51         u16                 pkey_index;
52         /* Lock to hold while iterating the qp_list. */
53         spinlock_t          qp_list_lock;
54         struct list_head    qp_list;
55 };
56
57 int  ib_device_register_sysfs(struct ib_device *device,
58                               int (*port_callback)(struct ib_device *,
59                                                    u8, struct kobject *));
60 void ib_device_unregister_sysfs(struct ib_device *device);
61 int ib_device_rename(struct ib_device *ibdev, const char *name);
62
63 typedef void (*roce_netdev_callback)(struct ib_device *device, u8 port,
64               struct net_device *idev, void *cookie);
65
66 typedef bool (*roce_netdev_filter)(struct ib_device *device, u8 port,
67                                    struct net_device *idev, void *cookie);
68
69 void ib_enum_roce_netdev(struct ib_device *ib_dev,
70                          roce_netdev_filter filter,
71                          void *filter_cookie,
72                          roce_netdev_callback cb,
73                          void *cookie);
74 void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
75                               void *filter_cookie,
76                               roce_netdev_callback cb,
77                               void *cookie);
78
79 typedef int (*nldev_callback)(struct ib_device *device,
80                               struct sk_buff *skb,
81                               struct netlink_callback *cb,
82                               unsigned int idx);
83
84 int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb,
85                      struct netlink_callback *cb);
86
87 enum ib_cache_gid_default_mode {
88         IB_CACHE_GID_DEFAULT_MODE_SET,
89         IB_CACHE_GID_DEFAULT_MODE_DELETE
90 };
91
92 int ib_cache_gid_parse_type_str(const char *buf);
93
94 const char *ib_cache_gid_type_str(enum ib_gid_type gid_type);
95
96 void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port,
97                                   struct net_device *ndev,
98                                   unsigned long gid_type_mask,
99                                   enum ib_cache_gid_default_mode mode);
100
101 int ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
102                      union ib_gid *gid, struct ib_gid_attr *attr);
103
104 int ib_cache_gid_del(struct ib_device *ib_dev, u8 port,
105                      union ib_gid *gid, struct ib_gid_attr *attr);
106
107 int ib_cache_gid_del_all_netdev_gids(struct ib_device *ib_dev, u8 port,
108                                      struct net_device *ndev);
109
110 int roce_gid_mgmt_init(void);
111 void roce_gid_mgmt_cleanup(void);
112
113 unsigned long roce_gid_type_mask_support(struct ib_device *ib_dev, u8 port);
114
115 int ib_cache_setup_one(struct ib_device *device);
116 void ib_cache_cleanup_one(struct ib_device *device);
117 void ib_cache_release_one(struct ib_device *device);
118
119 #ifdef CONFIG_CGROUP_RDMA
120 int ib_device_register_rdmacg(struct ib_device *device);
121 void ib_device_unregister_rdmacg(struct ib_device *device);
122
123 int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
124                          struct ib_device *device,
125                          enum rdmacg_resource_type resource_index);
126
127 void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
128                         struct ib_device *device,
129                         enum rdmacg_resource_type resource_index);
130 #else
131 static inline int ib_device_register_rdmacg(struct ib_device *device)
132 { return 0; }
133
134 static inline void ib_device_unregister_rdmacg(struct ib_device *device)
135 { }
136
137 static inline int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
138                                        struct ib_device *device,
139                                        enum rdmacg_resource_type resource_index)
140 { return 0; }
141
142 static inline void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
143                                       struct ib_device *device,
144                                       enum rdmacg_resource_type resource_index)
145 { }
146 #endif
147
148 static inline bool rdma_is_upper_dev_rcu(struct net_device *dev,
149                                          struct net_device *upper)
150 {
151         return netdev_has_upper_dev_all_rcu(dev, upper);
152 }
153
154 int addr_init(void);
155 void addr_cleanup(void);
156
157 int ib_mad_init(void);
158 void ib_mad_cleanup(void);
159
160 int ib_sa_init(void);
161 void ib_sa_cleanup(void);
162
163 int rdma_nl_init(void);
164 void rdma_nl_exit(void);
165
166 int ib_nl_handle_resolve_resp(struct sk_buff *skb,
167                               struct nlmsghdr *nlh,
168                               struct netlink_ext_ack *extack);
169 int ib_nl_handle_set_timeout(struct sk_buff *skb,
170                              struct nlmsghdr *nlh,
171                              struct netlink_ext_ack *extack);
172 int ib_nl_handle_ip_res_resp(struct sk_buff *skb,
173                              struct nlmsghdr *nlh,
174                              struct netlink_ext_ack *extack);
175
176 int ib_get_cached_subnet_prefix(struct ib_device *device,
177                                 u8                port_num,
178                                 u64              *sn_pfx);
179
180 #ifdef CONFIG_SECURITY_INFINIBAND
181 void ib_security_destroy_port_pkey_list(struct ib_device *device);
182
183 void ib_security_cache_change(struct ib_device *device,
184                               u8 port_num,
185                               u64 subnet_prefix);
186
187 int ib_security_modify_qp(struct ib_qp *qp,
188                           struct ib_qp_attr *qp_attr,
189                           int qp_attr_mask,
190                           struct ib_udata *udata);
191
192 int ib_create_qp_security(struct ib_qp *qp, struct ib_device *dev);
193 void ib_destroy_qp_security_begin(struct ib_qp_security *sec);
194 void ib_destroy_qp_security_abort(struct ib_qp_security *sec);
195 void ib_destroy_qp_security_end(struct ib_qp_security *sec);
196 int ib_open_shared_qp_security(struct ib_qp *qp, struct ib_device *dev);
197 void ib_close_shared_qp_security(struct ib_qp_security *sec);
198 int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
199                                 enum ib_qp_type qp_type);
200 void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent);
201 int ib_mad_enforce_security(struct ib_mad_agent_private *map, u16 pkey_index);
202 #else
203 static inline void ib_security_destroy_port_pkey_list(struct ib_device *device)
204 {
205 }
206
207 static inline void ib_security_cache_change(struct ib_device *device,
208                                             u8 port_num,
209                                             u64 subnet_prefix)
210 {
211 }
212
213 static inline int ib_security_modify_qp(struct ib_qp *qp,
214                                         struct ib_qp_attr *qp_attr,
215                                         int qp_attr_mask,
216                                         struct ib_udata *udata)
217 {
218         return qp->device->ops.modify_qp(qp->real_qp,
219                                          qp_attr,
220                                          qp_attr_mask,
221                                          udata);
222 }
223
224 static inline int ib_create_qp_security(struct ib_qp *qp,
225                                         struct ib_device *dev)
226 {
227         return 0;
228 }
229
230 static inline void ib_destroy_qp_security_begin(struct ib_qp_security *sec)
231 {
232 }
233
234 static inline void ib_destroy_qp_security_abort(struct ib_qp_security *sec)
235 {
236 }
237
238 static inline void ib_destroy_qp_security_end(struct ib_qp_security *sec)
239 {
240 }
241
242 static inline int ib_open_shared_qp_security(struct ib_qp *qp,
243                                              struct ib_device *dev)
244 {
245         return 0;
246 }
247
248 static inline void ib_close_shared_qp_security(struct ib_qp_security *sec)
249 {
250 }
251
252 static inline int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
253                                               enum ib_qp_type qp_type)
254 {
255         return 0;
256 }
257
258 static inline void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent)
259 {
260 }
261
262 static inline int ib_mad_enforce_security(struct ib_mad_agent_private *map,
263                                           u16 pkey_index)
264 {
265         return 0;
266 }
267 #endif
268
269 struct ib_device *ib_device_get_by_index(u32 ifindex);
270 void ib_device_put(struct ib_device *device);
271 /* RDMA device netlink */
272 void nldev_init(void);
273 void nldev_exit(void);
274
275 static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
276                                           struct ib_pd *pd,
277                                           struct ib_qp_init_attr *attr,
278                                           struct ib_udata *udata,
279                                           struct ib_uobject *uobj)
280 {
281         struct ib_qp *qp;
282
283         if (!dev->ops.create_qp)
284                 return ERR_PTR(-EOPNOTSUPP);
285
286         qp = dev->ops.create_qp(pd, attr, udata);
287         if (IS_ERR(qp))
288                 return qp;
289
290         qp->device = dev;
291         qp->pd = pd;
292         qp->uobject = uobj;
293         /*
294          * We don't track XRC QPs for now, because they don't have PD
295          * and more importantly they are created internaly by driver,
296          * see mlx5 create_dev_resources() as an example.
297          */
298         if (attr->qp_type < IB_QPT_XRC_INI) {
299                 qp->res.type = RDMA_RESTRACK_QP;
300                 if (uobj)
301                         rdma_restrack_uadd(&qp->res);
302                 else
303                         rdma_restrack_kadd(&qp->res);
304         } else
305                 qp->res.valid = false;
306
307         return qp;
308 }
309
310 struct rdma_dev_addr;
311 int rdma_resolve_ip_route(struct sockaddr *src_addr,
312                           const struct sockaddr *dst_addr,
313                           struct rdma_dev_addr *addr);
314
315 int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
316                                  const union ib_gid *dgid,
317                                  u8 *dmac, const struct ib_gid_attr *sgid_attr,
318                                  int *hoplimit);
319 void rdma_copy_src_l2_addr(struct rdma_dev_addr *dev_addr,
320                            const struct net_device *dev);
321
322 struct sa_path_rec;
323 int roce_resolve_route_from_path(struct sa_path_rec *rec,
324                                  const struct ib_gid_attr *attr);
325
326 struct net_device *rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr);
327 #endif /* _CORE_PRIV_H */