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