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  * $FreeBSD$
35  */
36 
37 #ifndef _CORE_PRIV_H
38 #define _CORE_PRIV_H
39 
40 #include <linux/list.h>
41 #include <linux/spinlock.h>
42 
43 #include <rdma/ib_verbs.h>
44 
45 #include <net/if_vlan_var.h>
46 
47 /* Total number of ports combined across all struct ib_devices's */
48 #define RDMA_MAX_PORTS 8192
49 
50 #ifdef CONFIG_INFINIBAND_ADDR_TRANS_CONFIGFS
51 int cma_configfs_init(void);
52 void cma_configfs_exit(void);
53 #else
54 static inline int cma_configfs_init(void)
55 {
56 	return 0;
57 }
58 
59 static inline void cma_configfs_exit(void)
60 {
61 }
62 #endif
63 struct cma_device;
64 void cma_ref_dev(struct cma_device *cma_dev);
65 void cma_deref_dev(struct cma_device *cma_dev);
66 typedef bool (*cma_device_filter)(struct ib_device *, void *);
67 struct cma_device *cma_enum_devices_by_ibdev(cma_device_filter	filter,
68 					     void		*cookie);
69 int cma_get_default_gid_type(struct cma_device *cma_dev,
70 			     unsigned int port);
71 int cma_set_default_gid_type(struct cma_device *cma_dev,
72 			     unsigned int port,
73 			     enum ib_gid_type default_gid_type);
74 struct ib_device *cma_get_ib_dev(struct cma_device *cma_dev);
75 
76 int  ib_device_register_sysfs(struct ib_device *device,
77 			      int (*port_callback)(struct ib_device *,
78 						   u8, struct kobject *));
79 void ib_device_unregister_sysfs(struct ib_device *device);
80 
81 void ib_cache_setup(void);
82 void ib_cache_cleanup(void);
83 
84 typedef void (*roce_netdev_callback)(struct ib_device *device, u8 port,
85 	      struct ifnet *idev, void *cookie);
86 
87 typedef int (*roce_netdev_filter)(struct ib_device *device, u8 port,
88 	     struct ifnet *idev, void *cookie);
89 
90 void ib_enum_roce_netdev(struct ib_device *ib_dev,
91 			 roce_netdev_filter filter,
92 			 void *filter_cookie,
93 			 roce_netdev_callback cb,
94 			 void *cookie);
95 void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
96 			      void *filter_cookie,
97 			      roce_netdev_callback cb,
98 			      void *cookie);
99 
100 enum ib_cache_gid_default_mode {
101 	IB_CACHE_GID_DEFAULT_MODE_SET,
102 	IB_CACHE_GID_DEFAULT_MODE_DELETE
103 };
104 
105 int ib_cache_gid_parse_type_str(const char *buf);
106 
107 const char *ib_cache_gid_type_str(enum ib_gid_type gid_type);
108 
109 void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port,
110 				  struct ifnet *ndev,
111 				  unsigned long gid_type_mask,
112 				  enum ib_cache_gid_default_mode mode);
113 
114 int ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
115 		     union ib_gid *gid, struct ib_gid_attr *attr);
116 
117 int ib_cache_gid_del(struct ib_device *ib_dev, u8 port,
118 		     union ib_gid *gid, struct ib_gid_attr *attr);
119 
120 int ib_cache_gid_del_all_netdev_gids(struct ib_device *ib_dev, u8 port,
121 				     struct ifnet *ndev);
122 void ib_cache_gid_del_all_by_netdev(struct ifnet *ndev);
123 
124 int roce_gid_mgmt_init(void);
125 void roce_gid_mgmt_cleanup(void);
126 
127 int roce_rescan_device(struct ib_device *ib_dev);
128 unsigned long roce_gid_type_mask_support(struct ib_device *ib_dev, u8 port);
129 
130 int ib_cache_setup_one(struct ib_device *device);
131 void ib_cache_cleanup_one(struct ib_device *device);
132 void ib_cache_release_one(struct ib_device *device);
133 
134 #define	ib_rdmacg_try_charge(...) ({ 0; })
135 
136 int addr_init(void);
137 void addr_cleanup(void);
138 
139 int ib_mad_init(void);
140 void ib_mad_cleanup(void);
141 
142 int ib_sa_init(void);
143 void ib_sa_cleanup(void);
144 
145 int ib_port_register_module_stat(struct ib_device *device, u8 port_num,
146 				 struct kobject *kobj, struct kobj_type *ktype,
147 				 const char *name);
148 void ib_port_unregister_module_stat(struct kobject *kobj);
149 
150 static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
151 					  struct ib_pd *pd,
152 					  struct ib_qp_init_attr *attr,
153 					  struct ib_udata *udata,
154 					  struct ib_uqp_object *uobj)
155 {
156 	struct ib_qp *qp;
157 
158 	if (!dev->create_qp)
159 		return ERR_PTR(-EOPNOTSUPP);
160 
161 	qp = dev->create_qp(pd, attr, udata);
162 	if (IS_ERR(qp))
163 		return qp;
164 
165 	qp->device = dev;
166 	qp->pd = pd;
167 	qp->uobject = uobj;
168 	qp->real_qp = qp;
169 
170 	qp->qp_type = attr->qp_type;
171 	qp->rwq_ind_tbl = attr->rwq_ind_tbl;
172 	qp->send_cq = attr->send_cq;
173 	qp->recv_cq = attr->recv_cq;
174 	qp->srq = attr->srq;
175 	qp->rwq_ind_tbl = attr->rwq_ind_tbl;
176 	qp->event_handler = attr->event_handler;
177 
178 	atomic_set(&qp->usecnt, 0);
179 	spin_lock_init(&qp->mr_lock);
180 
181 	return qp;
182 }
183 
184 struct rdma_umap_priv {
185 	struct vm_area_struct *vma;
186 	struct list_head list;
187 	struct rdma_user_mmap_entry *entry;
188 };
189 
190 void rdma_umap_priv_init(struct rdma_umap_priv *priv,
191 			 struct vm_area_struct *vma,
192 			 struct rdma_user_mmap_entry *entry);
193 
194 #endif /* _CORE_PRIV_H */
195