1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
47#define RDMA_MAX_PORTS 8192
48
49struct pkey_index_qp_list {
50 struct list_head pkey_index_list;
51 u16 pkey_index;
52
53 spinlock_t qp_list_lock;
54 struct list_head qp_list;
55};
56
57extern const struct attribute_group ib_dev_attr_group;
58extern bool ib_devices_shared_netns;
59
60int ib_device_register_sysfs(struct ib_device *device);
61void ib_device_unregister_sysfs(struct ib_device *device);
62int ib_device_rename(struct ib_device *ibdev, const char *name);
63int ib_device_set_dim(struct ib_device *ibdev, u8 use_dim);
64
65typedef void (*roce_netdev_callback)(struct ib_device *device, u8 port,
66 struct net_device *idev, void *cookie);
67
68typedef bool (*roce_netdev_filter)(struct ib_device *device, u8 port,
69 struct net_device *idev, void *cookie);
70
71struct net_device *ib_device_get_netdev(struct ib_device *ib_dev,
72 unsigned int port);
73
74void ib_enum_roce_netdev(struct ib_device *ib_dev,
75 roce_netdev_filter filter,
76 void *filter_cookie,
77 roce_netdev_callback cb,
78 void *cookie);
79void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
80 void *filter_cookie,
81 roce_netdev_callback cb,
82 void *cookie);
83
84typedef int (*nldev_callback)(struct ib_device *device,
85 struct sk_buff *skb,
86 struct netlink_callback *cb,
87 unsigned int idx);
88
89int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb,
90 struct netlink_callback *cb);
91
92struct ib_client_nl_info {
93 struct sk_buff *nl_msg;
94 struct device *cdev;
95 unsigned int port;
96 u64 abi;
97};
98int ib_get_client_nl_info(struct ib_device *ibdev, const char *client_name,
99 struct ib_client_nl_info *res);
100
101enum ib_cache_gid_default_mode {
102 IB_CACHE_GID_DEFAULT_MODE_SET,
103 IB_CACHE_GID_DEFAULT_MODE_DELETE
104};
105
106int ib_cache_gid_parse_type_str(const char *buf);
107
108const char *ib_cache_gid_type_str(enum ib_gid_type gid_type);
109
110void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port,
111 struct net_device *ndev,
112 unsigned long gid_type_mask,
113 enum ib_cache_gid_default_mode mode);
114
115int ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
116 union ib_gid *gid, struct ib_gid_attr *attr);
117
118int ib_cache_gid_del(struct ib_device *ib_dev, u8 port,
119 union ib_gid *gid, struct ib_gid_attr *attr);
120
121int ib_cache_gid_del_all_netdev_gids(struct ib_device *ib_dev, u8 port,
122 struct net_device *ndev);
123
124int roce_gid_mgmt_init(void);
125void roce_gid_mgmt_cleanup(void);
126
127unsigned long roce_gid_type_mask_support(struct ib_device *ib_dev, u8 port);
128
129int ib_cache_setup_one(struct ib_device *device);
130void ib_cache_cleanup_one(struct ib_device *device);
131void ib_cache_release_one(struct ib_device *device);
132void ib_dispatch_event_clients(struct ib_event *event);
133
134#ifdef CONFIG_CGROUP_RDMA
135void ib_device_register_rdmacg(struct ib_device *device);
136void ib_device_unregister_rdmacg(struct ib_device *device);
137
138int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
139 struct ib_device *device,
140 enum rdmacg_resource_type resource_index);
141
142void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
143 struct ib_device *device,
144 enum rdmacg_resource_type resource_index);
145#else
146static inline void ib_device_register_rdmacg(struct ib_device *device)
147{
148}
149
150static inline void ib_device_unregister_rdmacg(struct ib_device *device)
151{
152}
153
154static inline int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
155 struct ib_device *device,
156 enum rdmacg_resource_type resource_index)
157{
158 return 0;
159}
160
161static inline void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
162 struct ib_device *device,
163 enum rdmacg_resource_type resource_index)
164{
165}
166#endif
167
168static inline bool rdma_is_upper_dev_rcu(struct net_device *dev,
169 struct net_device *upper)
170{
171 return netdev_has_upper_dev_all_rcu(dev, upper);
172}
173
174int addr_init(void);
175void addr_cleanup(void);
176
177int ib_mad_init(void);
178void ib_mad_cleanup(void);
179
180int ib_sa_init(void);
181void ib_sa_cleanup(void);
182
183int rdma_nl_init(void);
184void rdma_nl_exit(void);
185
186int ib_nl_handle_resolve_resp(struct sk_buff *skb,
187 struct nlmsghdr *nlh,
188 struct netlink_ext_ack *extack);
189int ib_nl_handle_set_timeout(struct sk_buff *skb,
190 struct nlmsghdr *nlh,
191 struct netlink_ext_ack *extack);
192int ib_nl_handle_ip_res_resp(struct sk_buff *skb,
193 struct nlmsghdr *nlh,
194 struct netlink_ext_ack *extack);
195
196int ib_get_cached_subnet_prefix(struct ib_device *device,
197 u8 port_num,
198 u64 *sn_pfx);
199
200#ifdef CONFIG_SECURITY_INFINIBAND
201void ib_security_release_port_pkey_list(struct ib_device *device);
202
203void ib_security_cache_change(struct ib_device *device,
204 u8 port_num,
205 u64 subnet_prefix);
206
207int ib_security_modify_qp(struct ib_qp *qp,
208 struct ib_qp_attr *qp_attr,
209 int qp_attr_mask,
210 struct ib_udata *udata);
211
212int ib_create_qp_security(struct ib_qp *qp, struct ib_device *dev);
213void ib_destroy_qp_security_begin(struct ib_qp_security *sec);
214void ib_destroy_qp_security_abort(struct ib_qp_security *sec);
215void ib_destroy_qp_security_end(struct ib_qp_security *sec);
216int ib_open_shared_qp_security(struct ib_qp *qp, struct ib_device *dev);
217void ib_close_shared_qp_security(struct ib_qp_security *sec);
218int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
219 enum ib_qp_type qp_type);
220void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent);
221int ib_mad_enforce_security(struct ib_mad_agent_private *map, u16 pkey_index);
222void ib_mad_agent_security_change(void);
223#else
224static inline void ib_security_release_port_pkey_list(struct ib_device *device)
225{
226}
227
228static inline void ib_security_cache_change(struct ib_device *device,
229 u8 port_num,
230 u64 subnet_prefix)
231{
232}
233
234static inline int ib_security_modify_qp(struct ib_qp *qp,
235 struct ib_qp_attr *qp_attr,
236 int qp_attr_mask,
237 struct ib_udata *udata)
238{
239 return qp->device->ops.modify_qp(qp->real_qp,
240 qp_attr,
241 qp_attr_mask,
242 udata);
243}
244
245static inline int ib_create_qp_security(struct ib_qp *qp,
246 struct ib_device *dev)
247{
248 return 0;
249}
250
251static inline void ib_destroy_qp_security_begin(struct ib_qp_security *sec)
252{
253}
254
255static inline void ib_destroy_qp_security_abort(struct ib_qp_security *sec)
256{
257}
258
259static inline void ib_destroy_qp_security_end(struct ib_qp_security *sec)
260{
261}
262
263static inline int ib_open_shared_qp_security(struct ib_qp *qp,
264 struct ib_device *dev)
265{
266 return 0;
267}
268
269static inline void ib_close_shared_qp_security(struct ib_qp_security *sec)
270{
271}
272
273static inline int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
274 enum ib_qp_type qp_type)
275{
276 return 0;
277}
278
279static inline void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent)
280{
281}
282
283static inline int ib_mad_enforce_security(struct ib_mad_agent_private *map,
284 u16 pkey_index)
285{
286 return 0;
287}
288
289static inline void ib_mad_agent_security_change(void)
290{
291}
292#endif
293
294struct ib_device *ib_device_get_by_index(const struct net *net, u32 index);
295
296
297void nldev_init(void);
298void nldev_exit(void);
299
300static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
301 struct ib_pd *pd,
302 struct ib_qp_init_attr *attr,
303 struct ib_udata *udata,
304 struct ib_uobject *uobj)
305{
306 enum ib_qp_type qp_type = attr->qp_type;
307 struct ib_qp *qp;
308 bool is_xrc;
309
310 if (!dev->ops.create_qp)
311 return ERR_PTR(-EOPNOTSUPP);
312
313 qp = dev->ops.create_qp(pd, attr, udata);
314 if (IS_ERR(qp))
315 return qp;
316
317 qp->device = dev;
318 qp->pd = pd;
319 qp->uobject = uobj;
320 qp->real_qp = qp;
321
322
323
324
325
326 is_xrc = qp_type == IB_QPT_XRC_INI || qp_type == IB_QPT_XRC_TGT;
327 if ((qp_type < IB_QPT_MAX && !is_xrc) || qp_type == IB_QPT_DRIVER) {
328 qp->res.type = RDMA_RESTRACK_QP;
329 if (uobj)
330 rdma_restrack_uadd(&qp->res);
331 else
332 rdma_restrack_kadd(&qp->res);
333 } else
334 qp->res.valid = false;
335
336 return qp;
337}
338
339struct rdma_dev_addr;
340int rdma_resolve_ip_route(struct sockaddr *src_addr,
341 const struct sockaddr *dst_addr,
342 struct rdma_dev_addr *addr);
343
344int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
345 const union ib_gid *dgid,
346 u8 *dmac, const struct ib_gid_attr *sgid_attr,
347 int *hoplimit);
348void rdma_copy_src_l2_addr(struct rdma_dev_addr *dev_addr,
349 const struct net_device *dev);
350
351struct sa_path_rec;
352int roce_resolve_route_from_path(struct sa_path_rec *rec,
353 const struct ib_gid_attr *attr);
354
355struct net_device *rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr);
356
357void ib_free_port_attrs(struct ib_core_device *coredev);
358int ib_setup_port_attrs(struct ib_core_device *coredev);
359
360int rdma_compatdev_set(u8 enable);
361
362int ib_port_register_module_stat(struct ib_device *device, u8 port_num,
363 struct kobject *kobj, struct kobj_type *ktype,
364 const char *name);
365void ib_port_unregister_module_stat(struct kobject *kobj);
366
367int ib_device_set_netns_put(struct sk_buff *skb,
368 struct ib_device *dev, u32 ns_fd);
369#endif
370