2 * SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
4 * Copyright (C) 2019 - 2022 Intel Corporation
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
39 #include <sys/queue.h>
40 #include <infiniband/verbs.h>
41 #include <infiniband/driver.h>
45 #include "irdma_defs.h"
47 #include "irdma_user.h"
49 #define PFX "libirdma-"
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
56 LIST_HEAD(list_head, irdma_cq_buf);
57 LIST_HEAD(list_head_cmpl, irdma_cmpl_gen);
59 enum irdma_supported_wc_flags_ex {
60 IRDMA_STANDARD_WC_FLAGS_EX = IBV_WC_EX_WITH_BYTE_LEN
62 | IBV_WC_EX_WITH_QP_NUM
63 | IBV_WC_EX_WITH_SRC_QP
67 struct irdma_udevice {
68 struct verbs_device ibv_dev;
74 struct ibv_global_route grh;
84 struct irdma_uvcontext {
85 struct ibv_context ibv_ctx;
86 struct irdma_upd *iwupd;
87 struct irdma_uk_attrs uk_attrs;
97 LIST_ENTRY(irdma_cq_buf) list;
98 struct irdma_cq_uk cq;
103 extern pthread_mutex_t sigusr1_wait_mutex;
108 struct ibv_cq_ex cq_ex;
113 struct verbs_cq verbs_cq;
115 struct verbs_mr vmr_shadow_area;
116 pthread_spinlock_t lock;
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;
131 struct ibv_qp ibv_qp;
132 struct irdma_ucq *send_cq;
133 struct irdma_ucq *recv_cq;
136 uint32_t irdma_drv_opt;
137 pthread_spinlock_t lock;
141 uint32_t pending_rcvs;
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;
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,
160 int irdma_udereg_mr(struct ibv_mr *mr);
162 int irdma_urereg_mr(struct verbs_mr *mr, int flags, struct ibv_pd *pd, void *addr,
163 size_t length, int access);
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,
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,
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,
196 int irdma_udetach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
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 */