xref: /freebsd/contrib/ofed/libirdma/irdma_umain.h (revision 2b833162)
1 /*-
2  * SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
3  *
4  * Copyright (C) 2019 - 2022 Intel Corporation
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  * OpenFabrics.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 #ifndef IRDMA_UMAIN_H
37 #define IRDMA_UMAIN_H
38 
39 #include <sys/queue.h>
40 #include <infiniband/verbs.h>
41 #include <infiniband/driver.h>
42 
43 #include "osdep.h"
44 #include "irdma.h"
45 #include "irdma_defs.h"
46 #include "i40iw_hw.h"
47 #include "irdma_user.h"
48 
49 #define PFX	"libirdma-"
50 
51 #define IRDMA_BASE_PUSH_PAGE		1
52 #define IRDMA_U_MINCQ_SIZE		4
53 #define IRDMA_DB_SHADOW_AREA_SIZE	64
54 #define IRDMA_DB_CQ_OFFSET		64
55 
56 LIST_HEAD(list_head, irdma_cq_buf);
57 LIST_HEAD(list_head_cmpl, irdma_cmpl_gen);
58 
59 enum irdma_supported_wc_flags_ex {
60 	IRDMA_STANDARD_WC_FLAGS_EX = IBV_WC_EX_WITH_BYTE_LEN
61 				    | IBV_WC_EX_WITH_IMM
62 				    | IBV_WC_EX_WITH_QP_NUM
63 				    | IBV_WC_EX_WITH_SRC_QP
64 				    | IBV_WC_EX_WITH_SL,
65 };
66 
67 struct irdma_udevice {
68 	struct verbs_device ibv_dev;
69 };
70 
71 struct irdma_uah {
72 	struct ibv_ah ibv_ah;
73 	uint32_t ah_id;
74 	struct ibv_global_route grh;
75 };
76 
77 struct irdma_upd {
78 	struct ibv_pd ibv_pd;
79 	void *arm_cq_page;
80 	void *arm_cq;
81 	uint32_t pd_id;
82 };
83 
84 struct irdma_uvcontext {
85 	struct ibv_context ibv_ctx;
86 	struct irdma_upd *iwupd;
87 	struct irdma_uk_attrs uk_attrs;
88 	void *db;
89 	int abi_ver;
90 	bool legacy_mode:1;
91 	bool use_raw_attrs:1;
92 };
93 
94 struct irdma_uqp;
95 
96 struct irdma_cq_buf {
97 	LIST_ENTRY(irdma_cq_buf) list;
98 	struct irdma_cq_uk cq;
99 	struct verbs_mr vmr;
100 	size_t buf_size;
101 };
102 
103 extern pthread_mutex_t sigusr1_wait_mutex;
104 
105 struct verbs_cq {
106 	union {
107 		struct ibv_cq cq;
108 		struct ibv_cq_ex cq_ex;
109 	};
110 };
111 
112 struct irdma_cmpl_gen {
113 	LIST_ENTRY(irdma_cmpl_gen) list;
114 	struct irdma_cq_poll_info cpi;
115 };
116 
117 struct irdma_ucq {
118 	struct verbs_cq verbs_cq;
119 	struct verbs_mr vmr;
120 	struct verbs_mr vmr_shadow_area;
121 	pthread_spinlock_t lock;
122 	size_t buf_size;
123 	bool is_armed;
124 	bool skip_arm;
125 	bool arm_sol;
126 	bool skip_sol;
127 	int comp_vector;
128 	struct irdma_uqp *uqp;
129 	struct irdma_cq_uk cq;
130 	struct list_head resize_list;
131 	/* for extended CQ completion fields */
132 	struct irdma_cq_poll_info cur_cqe;
133 	struct list_head_cmpl cmpl_generated;
134 };
135 
136 struct irdma_uqp {
137 	struct ibv_qp ibv_qp;
138 	struct irdma_ucq *send_cq;
139 	struct irdma_ucq *recv_cq;
140 	struct verbs_mr vmr;
141 	size_t buf_size;
142 	uint32_t irdma_drv_opt;
143 	pthread_spinlock_t lock;
144 	uint16_t sq_sig_all;
145 	uint16_t qperr;
146 	uint16_t rsvd;
147 	uint32_t pending_rcvs;
148 	uint32_t wq_size;
149 	struct ibv_recv_wr *pend_rx_wr;
150 	struct irdma_qp_uk qp;
151 	enum ibv_qp_type qp_type;
152 	struct irdma_sge *recv_sges;
153 	pthread_t flush_thread;
154 };
155 
156 /* irdma_uverbs.c */
157 int irdma_uquery_device_ex(struct ibv_context *context,
158 			   const struct ibv_query_device_ex_input *input,
159 			   struct ibv_device_attr_ex *attr, size_t attr_size);
160 int irdma_uquery_port(struct ibv_context *context, uint8_t port,
161 		      struct ibv_port_attr *attr);
162 struct ibv_pd *irdma_ualloc_pd(struct ibv_context *context);
163 int irdma_ufree_pd(struct ibv_pd *pd);
164 int irdma_uquery_device(struct ibv_context *, struct ibv_device_attr *);
165 struct ibv_mr *irdma_ureg_mr(struct ibv_pd *pd, void *addr, size_t length,
166 			     int access);
167 int irdma_udereg_mr(struct ibv_mr *mr);
168 
169 int irdma_urereg_mr(struct verbs_mr *mr, int flags, struct ibv_pd *pd, void *addr,
170 		    size_t length, int access);
171 
172 struct ibv_mw *irdma_ualloc_mw(struct ibv_pd *pd, enum ibv_mw_type type);
173 int irdma_ubind_mw(struct ibv_qp *qp, struct ibv_mw *mw,
174 		   struct ibv_mw_bind *mw_bind);
175 int irdma_udealloc_mw(struct ibv_mw *mw);
176 struct ibv_cq *irdma_ucreate_cq(struct ibv_context *context, int cqe,
177 				struct ibv_comp_channel *channel,
178 				int comp_vector);
179 struct ibv_cq_ex *irdma_ucreate_cq_ex(struct ibv_context *context,
180 				      struct ibv_cq_init_attr_ex *attr_ex);
181 void irdma_ibvcq_ex_fill_priv_funcs(struct irdma_ucq *iwucq,
182 				    struct ibv_cq_init_attr_ex *attr_ex);
183 int irdma_uresize_cq(struct ibv_cq *cq, int cqe);
184 int irdma_udestroy_cq(struct ibv_cq *cq);
185 int irdma_upoll_cq(struct ibv_cq *cq, int entries, struct ibv_wc *entry);
186 int irdma_uarm_cq(struct ibv_cq *cq, int solicited);
187 void irdma_cq_event(struct ibv_cq *cq);
188 struct ibv_qp *irdma_ucreate_qp(struct ibv_pd *pd,
189 				struct ibv_qp_init_attr *attr);
190 int irdma_uquery_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask,
191 		    struct ibv_qp_init_attr *init_attr);
192 int irdma_umodify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
193 		     int attr_mask);
194 int irdma_udestroy_qp(struct ibv_qp *qp);
195 int irdma_upost_send(struct ibv_qp *ib_qp, struct ibv_send_wr *ib_wr,
196 		     struct ibv_send_wr **bad_wr);
197 int irdma_upost_recv(struct ibv_qp *ib_qp, struct ibv_recv_wr *ib_wr,
198 		     struct ibv_recv_wr **bad_wr);
199 struct ibv_ah *irdma_ucreate_ah(struct ibv_pd *ibpd, struct ibv_ah_attr *attr);
200 int irdma_udestroy_ah(struct ibv_ah *ibah);
201 int irdma_uattach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
202 			uint16_t lid);
203 int irdma_udetach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
204 			uint16_t lid);
205 void irdma_async_event(struct ibv_context *context,
206 		       struct ibv_async_event *event);
207 void irdma_set_hw_attrs(struct irdma_hw_attrs *attrs);
208 void *irdma_mmap(int fd, off_t offset);
209 void irdma_munmap(void *map);
210 void *irdma_flush_thread(void *arg);
211 #endif /* IRDMA_UMAIN_H */
212