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