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