xref: /freebsd/contrib/ofed/libirdma/irdma_umain.h (revision a4e5e0106ac7145f56eb39a691e302cabb4635be)
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_ucq {
113 	struct verbs_cq verbs_cq;
114 	struct verbs_mr vmr;
115 	struct verbs_mr vmr_shadow_area;
116 	pthread_spinlock_t lock;
117 	size_t buf_size;
118 	bool is_armed;
119 	bool skip_arm;
120 	bool arm_sol;
121 	bool skip_sol;
122 	int comp_vector;
123 	struct irdma_uqp *uqp;
124 	struct irdma_cq_uk cq;
125 	struct list_head resize_list;
126 	/* for extended CQ completion fields */
127 	struct irdma_cq_poll_info cur_cqe;
128 };
129 
130 struct irdma_uqp {
131 	struct ibv_qp ibv_qp;
132 	struct irdma_ucq *send_cq;
133 	struct irdma_ucq *recv_cq;
134 	struct verbs_mr vmr;
135 	size_t buf_size;
136 	uint32_t irdma_drv_opt;
137 	pthread_spinlock_t lock;
138 	uint16_t sq_sig_all;
139 	uint16_t qperr;
140 	uint16_t rsvd;
141 	uint32_t pending_rcvs;
142 	uint32_t wq_size;
143 	struct ibv_recv_wr *pend_rx_wr;
144 	struct irdma_qp_uk qp;
145 	enum ibv_qp_type qp_type;
146 	struct irdma_sge *recv_sges;
147 };
148 
149 /* irdma_uverbs.c */
150 int irdma_uquery_device_ex(struct ibv_context *context,
151 			   const struct ibv_query_device_ex_input *input,
152 			   struct ibv_device_attr_ex *attr, size_t attr_size);
153 int irdma_uquery_port(struct ibv_context *context, uint8_t port,
154 		      struct ibv_port_attr *attr);
155 struct ibv_pd *irdma_ualloc_pd(struct ibv_context *context);
156 int irdma_ufree_pd(struct ibv_pd *pd);
157 int irdma_uquery_device(struct ibv_context *, struct ibv_device_attr *);
158 struct ibv_mr *irdma_ureg_mr(struct ibv_pd *pd, void *addr, size_t length,
159 			     int access);
160 int irdma_udereg_mr(struct ibv_mr *mr);
161 
162 int irdma_urereg_mr(struct verbs_mr *mr, int flags, struct ibv_pd *pd, void *addr,
163 		    size_t length, int access);
164 
165 struct ibv_mw *irdma_ualloc_mw(struct ibv_pd *pd, enum ibv_mw_type type);
166 int irdma_ubind_mw(struct ibv_qp *qp, struct ibv_mw *mw,
167 		   struct ibv_mw_bind *mw_bind);
168 int irdma_udealloc_mw(struct ibv_mw *mw);
169 struct ibv_cq *irdma_ucreate_cq(struct ibv_context *context, int cqe,
170 				struct ibv_comp_channel *channel,
171 				int comp_vector);
172 struct ibv_cq_ex *irdma_ucreate_cq_ex(struct ibv_context *context,
173 				      struct ibv_cq_init_attr_ex *attr_ex);
174 void irdma_ibvcq_ex_fill_priv_funcs(struct irdma_ucq *iwucq,
175 				    struct ibv_cq_init_attr_ex *attr_ex);
176 int irdma_uresize_cq(struct ibv_cq *cq, int cqe);
177 int irdma_udestroy_cq(struct ibv_cq *cq);
178 int irdma_upoll_cq(struct ibv_cq *cq, int entries, struct ibv_wc *entry);
179 int irdma_uarm_cq(struct ibv_cq *cq, int solicited);
180 void irdma_cq_event(struct ibv_cq *cq);
181 struct ibv_qp *irdma_ucreate_qp(struct ibv_pd *pd,
182 				struct ibv_qp_init_attr *attr);
183 int irdma_uquery_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask,
184 		    struct ibv_qp_init_attr *init_attr);
185 int irdma_umodify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
186 		     int attr_mask);
187 int irdma_udestroy_qp(struct ibv_qp *qp);
188 int irdma_upost_send(struct ibv_qp *ib_qp, struct ibv_send_wr *ib_wr,
189 		     struct ibv_send_wr **bad_wr);
190 int irdma_upost_recv(struct ibv_qp *ib_qp, struct ibv_recv_wr *ib_wr,
191 		     struct ibv_recv_wr **bad_wr);
192 struct ibv_ah *irdma_ucreate_ah(struct ibv_pd *ibpd, struct ibv_ah_attr *attr);
193 int irdma_udestroy_ah(struct ibv_ah *ibah);
194 int irdma_uattach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
195 			uint16_t lid);
196 int irdma_udetach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
197 			uint16_t lid);
198 void irdma_async_event(struct ibv_context *context,
199 		       struct ibv_async_event *event);
200 void irdma_set_hw_attrs(struct irdma_hw_attrs *attrs);
201 void *irdma_mmap(int fd, off_t offset);
202 void irdma_munmap(void *map);
203 #endif /* IRDMA_UMAIN_H */
204