xref: /freebsd/sys/ofed/drivers/infiniband/core/core_priv.h (revision 4726b80d9379cdefd00ae77d0b91973bde573790)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3  *
4  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  */
34 
35 #ifndef _CORE_PRIV_H
36 #define _CORE_PRIV_H
37 
38 #include <linux/list.h>
39 #include <linux/spinlock.h>
40 
41 #include <rdma/ib_verbs.h>
42 #include <rdma/opa_addr.h>
43 
44 #include <net/if_vlan_var.h>
45 
46 /* Total number of ports combined across all struct ib_devices's */
47 #define RDMA_MAX_PORTS 8192
48 
49 #ifdef CONFIG_INFINIBAND_ADDR_TRANS_CONFIGFS
50 int cma_configfs_init(void);
51 void cma_configfs_exit(void);
52 #else
cma_configfs_init(void)53 static inline int cma_configfs_init(void)
54 {
55 	return 0;
56 }
57 
cma_configfs_exit(void)58 static inline void cma_configfs_exit(void)
59 {
60 }
61 #endif
62 struct cma_device;
63 void cma_ref_dev(struct cma_device *cma_dev);
64 void cma_deref_dev(struct cma_device *cma_dev);
65 typedef bool (*cma_device_filter)(struct ib_device *, void *);
66 struct cma_device *cma_enum_devices_by_ibdev(cma_device_filter	filter,
67 					     void		*cookie);
68 int cma_get_default_gid_type(struct cma_device *cma_dev,
69 			     unsigned int port);
70 int cma_set_default_gid_type(struct cma_device *cma_dev,
71 			     unsigned int port,
72 			     enum ib_gid_type default_gid_type);
73 int cma_get_default_roce_tos(struct cma_device *cma_dev, unsigned int port);
74 int cma_set_default_roce_tos(struct cma_device *a_dev, unsigned int port,
75 			     u8 default_roce_tos);
76 struct ib_device *cma_get_ib_dev(struct cma_device *cma_dev);
77 
78 int  ib_device_register_sysfs(struct ib_device *device,
79 			      int (*port_callback)(struct ib_device *,
80 						   u8, struct kobject *));
81 void ib_device_unregister_sysfs(struct ib_device *device);
82 
83 void ib_cache_setup(void);
84 void ib_cache_cleanup(void);
85 
86 typedef void (*roce_netdev_callback)(struct ib_device *device, u8 port,
87 	      if_t idev, void *cookie);
88 
89 typedef bool (*roce_netdev_filter)(struct ib_device *device, u8 port,
90 				   if_t idev, void *cookie);
91 
92 void ib_enum_roce_netdev(struct ib_device *ib_dev,
93 			 roce_netdev_filter filter,
94 			 void *filter_cookie,
95 			 roce_netdev_callback cb,
96 			 void *cookie);
97 void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
98 			      void *filter_cookie,
99 			      roce_netdev_callback cb,
100 			      void *cookie);
101 
102 enum ib_cache_gid_default_mode {
103 	IB_CACHE_GID_DEFAULT_MODE_SET,
104 	IB_CACHE_GID_DEFAULT_MODE_DELETE
105 };
106 
107 int ib_cache_gid_parse_type_str(const char *buf);
108 
109 const char *ib_cache_gid_type_str(enum ib_gid_type gid_type);
110 
111 void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port,
112 				  if_t ndev,
113 				  unsigned long gid_type_mask,
114 				  enum ib_cache_gid_default_mode mode);
115 
116 int ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
117 		     union ib_gid *gid, struct ib_gid_attr *attr);
118 
119 int ib_cache_gid_del(struct ib_device *ib_dev, u8 port,
120 		     union ib_gid *gid, struct ib_gid_attr *attr);
121 
122 int ib_cache_gid_del_all_netdev_gids(struct ib_device *ib_dev, u8 port,
123 				     if_t ndev);
124 void ib_cache_gid_del_all_by_netdev(if_t ndev);
125 
126 int roce_gid_mgmt_init(void);
127 void roce_gid_mgmt_cleanup(void);
128 
129 int roce_rescan_device(struct ib_device *ib_dev);
130 unsigned long roce_gid_type_mask_support(struct ib_device *ib_dev, u8 port);
131 
132 int ib_cache_setup_one(struct ib_device *device);
133 void ib_cache_cleanup_one(struct ib_device *device);
134 void ib_cache_release_one(struct ib_device *device);
135 
136 #define	ib_rdmacg_try_charge(...) ({ 0; })
137 
138 int addr_init(void);
139 void addr_cleanup(void);
140 
141 int ib_mad_init(void);
142 void ib_mad_cleanup(void);
143 
144 int ib_sa_init(void);
145 void ib_sa_cleanup(void);
146 
147 int ib_port_register_module_stat(struct ib_device *device, u8 port_num,
148 				 struct kobject *kobj, struct kobj_type *ktype,
149 				 const char *name);
150 void ib_port_unregister_module_stat(struct kobject *kobj);
151 
_ib_create_qp(struct ib_device * dev,struct ib_pd * pd,struct ib_qp_init_attr * attr,struct ib_udata * udata,struct ib_uqp_object * uobj)152 static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
153 					  struct ib_pd *pd,
154 					  struct ib_qp_init_attr *attr,
155 					  struct ib_udata *udata,
156 					  struct ib_uqp_object *uobj)
157 {
158 	struct ib_qp *qp;
159 
160 	if (!dev->create_qp)
161 		return ERR_PTR(-EOPNOTSUPP);
162 
163 	qp = dev->create_qp(pd, attr, udata);
164 	if (IS_ERR(qp))
165 		return qp;
166 
167 	qp->device = dev;
168 	qp->pd = pd;
169 	qp->uobject = uobj;
170 	qp->real_qp = qp;
171 
172 	qp->qp_type = attr->qp_type;
173 	qp->rwq_ind_tbl = attr->rwq_ind_tbl;
174 	qp->send_cq = attr->send_cq;
175 	qp->recv_cq = attr->recv_cq;
176 	qp->srq = attr->srq;
177 	qp->rwq_ind_tbl = attr->rwq_ind_tbl;
178 	qp->event_handler = attr->event_handler;
179 
180 	atomic_set(&qp->usecnt, 0);
181 	spin_lock_init(&qp->mr_lock);
182 
183 	return qp;
184 }
185 
186 struct rdma_dev_addr;
187 int rdma_resolve_ip_route(struct sockaddr *src_addr,
188 			  const struct sockaddr *dst_addr,
189 			  struct rdma_dev_addr *addr);
190 
191 int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
192 				 const union ib_gid *dgid,
193 				 u8 *dmac, const struct ib_gid_attr *sgid_attr,
194 				 int *hoplimit);
195 void rdma_copy_src_l2_addr(struct rdma_dev_addr *dev_addr,
196                            const if_t dev);
197 
198 struct sa_path_rec;
199 int roce_resolve_route_from_path(struct sa_path_rec *rec,
200 				 const struct ib_gid_attr *attr);
201 
202 if_t rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr);
203 
204 struct rdma_umap_priv {
205 	struct vm_area_struct *vma;
206 	struct list_head list;
207 	struct rdma_user_mmap_entry *entry;
208 };
209 
210 void rdma_umap_priv_init(struct rdma_umap_priv *priv,
211 			 struct vm_area_struct *vma,
212 			 struct rdma_user_mmap_entry *entry);
213 
214 #endif /* _CORE_PRIV_H */
215