2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
36 #include <linux/list.h>
37 #include <linux/spinlock.h>
38 #include <linux/cgroup_rdma.h>
40 #include <rdma/ib_verbs.h>
41 #include <rdma/opa_addr.h>
42 #include <rdma/ib_mad.h>
43 #include <rdma/restrack.h>
46 /* Total number of ports combined across all struct ib_devices's */
47 #define RDMA_MAX_PORTS 8192
49 struct pkey_index_qp_list
{
50 struct list_head pkey_index_list
;
52 /* Lock to hold while iterating the qp_list. */
53 spinlock_t qp_list_lock
;
54 struct list_head qp_list
;
57 extern const struct attribute_group ib_dev_attr_group
;
58 extern bool ib_devices_shared_netns
;
60 int ib_device_register_sysfs(struct ib_device
*device
);
61 void ib_device_unregister_sysfs(struct ib_device
*device
);
62 int ib_device_rename(struct ib_device
*ibdev
, const char *name
);
63 int ib_device_set_dim(struct ib_device
*ibdev
, u8 use_dim
);
65 typedef void (*roce_netdev_callback
)(struct ib_device
*device
, u8 port
,
66 struct net_device
*idev
, void *cookie
);
68 typedef bool (*roce_netdev_filter
)(struct ib_device
*device
, u8 port
,
69 struct net_device
*idev
, void *cookie
);
71 struct net_device
*ib_device_get_netdev(struct ib_device
*ib_dev
,
74 void ib_enum_roce_netdev(struct ib_device
*ib_dev
,
75 roce_netdev_filter filter
,
77 roce_netdev_callback cb
,
79 void ib_enum_all_roce_netdevs(roce_netdev_filter filter
,
81 roce_netdev_callback cb
,
84 typedef int (*nldev_callback
)(struct ib_device
*device
,
86 struct netlink_callback
*cb
,
89 int ib_enum_all_devs(nldev_callback nldev_cb
, struct sk_buff
*skb
,
90 struct netlink_callback
*cb
);
92 struct ib_client_nl_info
{
93 struct sk_buff
*nl_msg
;
98 int ib_get_client_nl_info(struct ib_device
*ibdev
, const char *client_name
,
99 struct ib_client_nl_info
*res
);
101 enum ib_cache_gid_default_mode
{
102 IB_CACHE_GID_DEFAULT_MODE_SET
,
103 IB_CACHE_GID_DEFAULT_MODE_DELETE
106 int ib_cache_gid_parse_type_str(const char *buf
);
108 const char *ib_cache_gid_type_str(enum ib_gid_type gid_type
);
110 void 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
);
115 int ib_cache_gid_add(struct ib_device
*ib_dev
, u8 port
,
116 union ib_gid
*gid
, struct ib_gid_attr
*attr
);
118 int ib_cache_gid_del(struct ib_device
*ib_dev
, u8 port
,
119 union ib_gid
*gid
, struct ib_gid_attr
*attr
);
121 int ib_cache_gid_del_all_netdev_gids(struct ib_device
*ib_dev
, u8 port
,
122 struct net_device
*ndev
);
124 int roce_gid_mgmt_init(void);
125 void roce_gid_mgmt_cleanup(void);
127 unsigned long roce_gid_type_mask_support(struct ib_device
*ib_dev
, u8 port
);
129 int ib_cache_setup_one(struct ib_device
*device
);
130 void ib_cache_cleanup_one(struct ib_device
*device
);
131 void ib_cache_release_one(struct ib_device
*device
);
133 #ifdef CONFIG_CGROUP_RDMA
134 void ib_device_register_rdmacg(struct ib_device
*device
);
135 void ib_device_unregister_rdmacg(struct ib_device
*device
);
137 int ib_rdmacg_try_charge(struct ib_rdmacg_object
*cg_obj
,
138 struct ib_device
*device
,
139 enum rdmacg_resource_type resource_index
);
141 void ib_rdmacg_uncharge(struct ib_rdmacg_object
*cg_obj
,
142 struct ib_device
*device
,
143 enum rdmacg_resource_type resource_index
);
145 static inline void ib_device_register_rdmacg(struct ib_device
*device
)
149 static inline void ib_device_unregister_rdmacg(struct ib_device
*device
)
153 static inline int ib_rdmacg_try_charge(struct ib_rdmacg_object
*cg_obj
,
154 struct ib_device
*device
,
155 enum rdmacg_resource_type resource_index
)
160 static inline void ib_rdmacg_uncharge(struct ib_rdmacg_object
*cg_obj
,
161 struct ib_device
*device
,
162 enum rdmacg_resource_type resource_index
)
167 static inline bool rdma_is_upper_dev_rcu(struct net_device
*dev
,
168 struct net_device
*upper
)
170 return netdev_has_upper_dev_all_rcu(dev
, upper
);
174 void addr_cleanup(void);
176 int ib_mad_init(void);
177 void ib_mad_cleanup(void);
179 int ib_sa_init(void);
180 void ib_sa_cleanup(void);
182 int rdma_nl_init(void);
183 void rdma_nl_exit(void);
185 int ib_nl_handle_resolve_resp(struct sk_buff
*skb
,
186 struct nlmsghdr
*nlh
,
187 struct netlink_ext_ack
*extack
);
188 int ib_nl_handle_set_timeout(struct sk_buff
*skb
,
189 struct nlmsghdr
*nlh
,
190 struct netlink_ext_ack
*extack
);
191 int ib_nl_handle_ip_res_resp(struct sk_buff
*skb
,
192 struct nlmsghdr
*nlh
,
193 struct netlink_ext_ack
*extack
);
195 int ib_get_cached_subnet_prefix(struct ib_device
*device
,
199 #ifdef CONFIG_SECURITY_INFINIBAND
200 void ib_security_release_port_pkey_list(struct ib_device
*device
);
202 void ib_security_cache_change(struct ib_device
*device
,
206 int ib_security_modify_qp(struct ib_qp
*qp
,
207 struct ib_qp_attr
*qp_attr
,
209 struct ib_udata
*udata
);
211 int ib_create_qp_security(struct ib_qp
*qp
, struct ib_device
*dev
);
212 void ib_destroy_qp_security_begin(struct ib_qp_security
*sec
);
213 void ib_destroy_qp_security_abort(struct ib_qp_security
*sec
);
214 void ib_destroy_qp_security_end(struct ib_qp_security
*sec
);
215 int ib_open_shared_qp_security(struct ib_qp
*qp
, struct ib_device
*dev
);
216 void ib_close_shared_qp_security(struct ib_qp_security
*sec
);
217 int ib_mad_agent_security_setup(struct ib_mad_agent
*agent
,
218 enum ib_qp_type qp_type
);
219 void ib_mad_agent_security_cleanup(struct ib_mad_agent
*agent
);
220 int ib_mad_enforce_security(struct ib_mad_agent_private
*map
, u16 pkey_index
);
221 void ib_mad_agent_security_change(void);
223 static inline void ib_security_release_port_pkey_list(struct ib_device
*device
)
227 static inline void ib_security_cache_change(struct ib_device
*device
,
233 static inline int ib_security_modify_qp(struct ib_qp
*qp
,
234 struct ib_qp_attr
*qp_attr
,
236 struct ib_udata
*udata
)
238 return qp
->device
->ops
.modify_qp(qp
->real_qp
,
244 static inline int ib_create_qp_security(struct ib_qp
*qp
,
245 struct ib_device
*dev
)
250 static inline void ib_destroy_qp_security_begin(struct ib_qp_security
*sec
)
254 static inline void ib_destroy_qp_security_abort(struct ib_qp_security
*sec
)
258 static inline void ib_destroy_qp_security_end(struct ib_qp_security
*sec
)
262 static inline int ib_open_shared_qp_security(struct ib_qp
*qp
,
263 struct ib_device
*dev
)
268 static inline void ib_close_shared_qp_security(struct ib_qp_security
*sec
)
272 static inline int ib_mad_agent_security_setup(struct ib_mad_agent
*agent
,
273 enum ib_qp_type qp_type
)
278 static inline void ib_mad_agent_security_cleanup(struct ib_mad_agent
*agent
)
282 static inline int ib_mad_enforce_security(struct ib_mad_agent_private
*map
,
288 static inline void ib_mad_agent_security_change(void)
293 struct ib_device
*ib_device_get_by_index(const struct net
*net
, u32 index
);
295 /* RDMA device netlink */
296 void nldev_init(void);
297 void nldev_exit(void);
299 static inline struct ib_qp
*_ib_create_qp(struct ib_device
*dev
,
301 struct ib_qp_init_attr
*attr
,
302 struct ib_udata
*udata
,
303 struct ib_uobject
*uobj
)
305 enum ib_qp_type qp_type
= attr
->qp_type
;
309 if (!dev
->ops
.create_qp
)
310 return ERR_PTR(-EOPNOTSUPP
);
312 qp
= dev
->ops
.create_qp(pd
, attr
, udata
);
321 * We don't track XRC QPs for now, because they don't have PD
322 * and more importantly they are created internaly by driver,
323 * see mlx5 create_dev_resources() as an example.
325 is_xrc
= qp_type
== IB_QPT_XRC_INI
|| qp_type
== IB_QPT_XRC_TGT
;
326 if ((qp_type
< IB_QPT_MAX
&& !is_xrc
) || qp_type
== IB_QPT_DRIVER
) {
327 qp
->res
.type
= RDMA_RESTRACK_QP
;
329 rdma_restrack_uadd(&qp
->res
);
331 rdma_restrack_kadd(&qp
->res
);
333 qp
->res
.valid
= false;
338 struct rdma_dev_addr
;
339 int rdma_resolve_ip_route(struct sockaddr
*src_addr
,
340 const struct sockaddr
*dst_addr
,
341 struct rdma_dev_addr
*addr
);
343 int rdma_addr_find_l2_eth_by_grh(const union ib_gid
*sgid
,
344 const union ib_gid
*dgid
,
345 u8
*dmac
, const struct ib_gid_attr
*sgid_attr
,
347 void rdma_copy_src_l2_addr(struct rdma_dev_addr
*dev_addr
,
348 const struct net_device
*dev
);
351 int roce_resolve_route_from_path(struct sa_path_rec
*rec
,
352 const struct ib_gid_attr
*attr
);
354 struct net_device
*rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr
*attr
);
356 void ib_free_port_attrs(struct ib_core_device
*coredev
);
357 int ib_setup_port_attrs(struct ib_core_device
*coredev
);
359 int rdma_compatdev_set(u8 enable
);
361 int ib_port_register_module_stat(struct ib_device
*device
, u8 port_num
,
362 struct kobject
*kobj
, struct kobj_type
*ktype
,
364 void ib_port_unregister_module_stat(struct kobject
*kobj
);
366 int ib_device_set_netns_put(struct sk_buff
*skb
,
367 struct ib_device
*dev
, u32 ns_fd
);
368 #endif /* _CORE_PRIV_H */