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;
59 int ib_device_register_sysfs(struct ib_device *device);
60 void ib_device_unregister_sysfs(struct ib_device *device);
61 int ib_device_rename(struct ib_device *ibdev, const char *name);
63 typedef void (*roce_netdev_callback)(struct ib_device *device, u8 port,
64 struct net_device *idev, void *cookie);
66 typedef bool (*roce_netdev_filter)(struct ib_device *device, u8 port,
67 struct net_device *idev, void *cookie);
69 struct net_device *ib_device_get_netdev(struct ib_device *ib_dev,
72 void ib_enum_roce_netdev(struct ib_device *ib_dev,
73 roce_netdev_filter filter,
75 roce_netdev_callback cb,
77 void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
79 roce_netdev_callback cb,
82 typedef int (*nldev_callback)(struct ib_device *device,
84 struct netlink_callback *cb,
87 int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb,
88 struct netlink_callback *cb);
90 enum ib_cache_gid_default_mode {
91 IB_CACHE_GID_DEFAULT_MODE_SET,
92 IB_CACHE_GID_DEFAULT_MODE_DELETE
95 int ib_cache_gid_parse_type_str(const char *buf);
97 const char *ib_cache_gid_type_str(enum ib_gid_type gid_type);
99 void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port,
100 struct net_device *ndev,
101 unsigned long gid_type_mask,
102 enum ib_cache_gid_default_mode mode);
104 int ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
105 union ib_gid *gid, struct ib_gid_attr *attr);
107 int ib_cache_gid_del(struct ib_device *ib_dev, u8 port,
108 union ib_gid *gid, struct ib_gid_attr *attr);
110 int ib_cache_gid_del_all_netdev_gids(struct ib_device *ib_dev, u8 port,
111 struct net_device *ndev);
113 int roce_gid_mgmt_init(void);
114 void roce_gid_mgmt_cleanup(void);
116 unsigned long roce_gid_type_mask_support(struct ib_device *ib_dev, u8 port);
118 int ib_cache_setup_one(struct ib_device *device);
119 void ib_cache_cleanup_one(struct ib_device *device);
120 void ib_cache_release_one(struct ib_device *device);
122 #ifdef CONFIG_CGROUP_RDMA
123 void ib_device_register_rdmacg(struct ib_device *device);
124 void ib_device_unregister_rdmacg(struct ib_device *device);
126 int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
127 struct ib_device *device,
128 enum rdmacg_resource_type resource_index);
130 void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
131 struct ib_device *device,
132 enum rdmacg_resource_type resource_index);
134 static inline void ib_device_register_rdmacg(struct ib_device *device)
138 static inline void ib_device_unregister_rdmacg(struct ib_device *device)
142 static inline int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
143 struct ib_device *device,
144 enum rdmacg_resource_type resource_index)
149 static inline void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
150 struct ib_device *device,
151 enum rdmacg_resource_type resource_index)
156 static inline bool rdma_is_upper_dev_rcu(struct net_device *dev,
157 struct net_device *upper)
159 return netdev_has_upper_dev_all_rcu(dev, upper);
163 void addr_cleanup(void);
165 int ib_mad_init(void);
166 void ib_mad_cleanup(void);
168 int ib_sa_init(void);
169 void ib_sa_cleanup(void);
171 int rdma_nl_init(void);
172 void rdma_nl_exit(void);
174 int ib_nl_handle_resolve_resp(struct sk_buff *skb,
175 struct nlmsghdr *nlh,
176 struct netlink_ext_ack *extack);
177 int ib_nl_handle_set_timeout(struct sk_buff *skb,
178 struct nlmsghdr *nlh,
179 struct netlink_ext_ack *extack);
180 int ib_nl_handle_ip_res_resp(struct sk_buff *skb,
181 struct nlmsghdr *nlh,
182 struct netlink_ext_ack *extack);
184 int ib_get_cached_subnet_prefix(struct ib_device *device,
188 #ifdef CONFIG_SECURITY_INFINIBAND
189 void ib_security_release_port_pkey_list(struct ib_device *device);
191 void ib_security_cache_change(struct ib_device *device,
195 int ib_security_modify_qp(struct ib_qp *qp,
196 struct ib_qp_attr *qp_attr,
198 struct ib_udata *udata);
200 int ib_create_qp_security(struct ib_qp *qp, struct ib_device *dev);
201 void ib_destroy_qp_security_begin(struct ib_qp_security *sec);
202 void ib_destroy_qp_security_abort(struct ib_qp_security *sec);
203 void ib_destroy_qp_security_end(struct ib_qp_security *sec);
204 int ib_open_shared_qp_security(struct ib_qp *qp, struct ib_device *dev);
205 void ib_close_shared_qp_security(struct ib_qp_security *sec);
206 int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
207 enum ib_qp_type qp_type);
208 void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent);
209 int ib_mad_enforce_security(struct ib_mad_agent_private *map, u16 pkey_index);
210 void ib_mad_agent_security_change(void);
212 static inline void ib_security_release_port_pkey_list(struct ib_device *device)
216 static inline void ib_security_cache_change(struct ib_device *device,
222 static inline int ib_security_modify_qp(struct ib_qp *qp,
223 struct ib_qp_attr *qp_attr,
225 struct ib_udata *udata)
227 return qp->device->ops.modify_qp(qp->real_qp,
233 static inline int ib_create_qp_security(struct ib_qp *qp,
234 struct ib_device *dev)
239 static inline void ib_destroy_qp_security_begin(struct ib_qp_security *sec)
243 static inline void ib_destroy_qp_security_abort(struct ib_qp_security *sec)
247 static inline void ib_destroy_qp_security_end(struct ib_qp_security *sec)
251 static inline int ib_open_shared_qp_security(struct ib_qp *qp,
252 struct ib_device *dev)
257 static inline void ib_close_shared_qp_security(struct ib_qp_security *sec)
261 static inline int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
262 enum ib_qp_type qp_type)
267 static inline void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent)
271 static inline int ib_mad_enforce_security(struct ib_mad_agent_private *map,
277 static inline void ib_mad_agent_security_change(void)
282 struct ib_device *ib_device_get_by_index(u32 ifindex);
283 /* RDMA device netlink */
284 void nldev_init(void);
285 void nldev_exit(void);
287 static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
289 struct ib_qp_init_attr *attr,
290 struct ib_udata *udata,
291 struct ib_uobject *uobj)
295 if (!dev->ops.create_qp)
296 return ERR_PTR(-EOPNOTSUPP);
298 qp = dev->ops.create_qp(pd, attr, udata);
306 * We don't track XRC QPs for now, because they don't have PD
307 * and more importantly they are created internaly by driver,
308 * see mlx5 create_dev_resources() as an example.
310 if (attr->qp_type < IB_QPT_XRC_INI) {
311 qp->res.type = RDMA_RESTRACK_QP;
313 rdma_restrack_uadd(&qp->res);
315 rdma_restrack_kadd(&qp->res);
317 qp->res.valid = false;
322 struct rdma_dev_addr;
323 int rdma_resolve_ip_route(struct sockaddr *src_addr,
324 const struct sockaddr *dst_addr,
325 struct rdma_dev_addr *addr);
327 int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
328 const union ib_gid *dgid,
329 u8 *dmac, const struct ib_gid_attr *sgid_attr,
331 void rdma_copy_src_l2_addr(struct rdma_dev_addr *dev_addr,
332 const struct net_device *dev);
335 int roce_resolve_route_from_path(struct sa_path_rec *rec,
336 const struct ib_gid_attr *attr);
338 struct net_device *rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr);
339 #endif /* _CORE_PRIV_H */