1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2022 Microsoft Corporation. All rights reserved. 4 */ 5 6 #ifndef _MANA_IB_H_ 7 #define _MANA_IB_H_ 8 9 #include <rdma/ib_verbs.h> 10 #include <rdma/ib_mad.h> 11 #include <rdma/ib_umem.h> 12 #include <rdma/mana-abi.h> 13 #include <rdma/uverbs_ioctl.h> 14 15 #include <net/mana/mana.h> 16 17 #define PAGE_SZ_BM \ 18 (SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K | SZ_256K | \ 19 SZ_512K | SZ_1M | SZ_2M) 20 21 /* MANA doesn't have any limit for MR size */ 22 #define MANA_IB_MAX_MR_SIZE U64_MAX 23 24 /* 25 * The hardware limit of number of MRs is greater than maximum number of MRs 26 * that can possibly represent in 24 bits 27 */ 28 #define MANA_IB_MAX_MR 0xFFFFFFu 29 30 struct mana_ib_adapter_caps { 31 u32 max_sq_id; 32 u32 max_rq_id; 33 u32 max_cq_id; 34 u32 max_qp_count; 35 u32 max_cq_count; 36 u32 max_mr_count; 37 u32 max_pd_count; 38 u32 max_inbound_read_limit; 39 u32 max_outbound_read_limit; 40 u32 mw_count; 41 u32 max_srq_count; 42 u32 max_qp_wr; 43 u32 max_send_sge_count; 44 u32 max_recv_sge_count; 45 u32 max_inline_data_size; 46 }; 47 48 struct mana_ib_dev { 49 struct ib_device ib_dev; 50 struct gdma_dev *gdma_dev; 51 struct mana_ib_adapter_caps adapter_caps; 52 }; 53 54 struct mana_ib_wq { 55 struct ib_wq ibwq; 56 struct ib_umem *umem; 57 int wqe; 58 u32 wq_buf_size; 59 u64 gdma_region; 60 u64 id; 61 mana_handle_t rx_object; 62 }; 63 64 struct mana_ib_pd { 65 struct ib_pd ibpd; 66 u32 pdn; 67 mana_handle_t pd_handle; 68 69 /* Mutex for sharing access to vport_use_count */ 70 struct mutex vport_mutex; 71 int vport_use_count; 72 73 bool tx_shortform_allowed; 74 u32 tx_vp_offset; 75 }; 76 77 struct mana_ib_mr { 78 struct ib_mr ibmr; 79 struct ib_umem *umem; 80 mana_handle_t mr_handle; 81 }; 82 83 struct mana_ib_cq { 84 struct ib_cq ibcq; 85 struct ib_umem *umem; 86 int cqe; 87 u64 gdma_region; 88 u64 id; 89 u32 comp_vector; 90 }; 91 92 struct mana_ib_qp { 93 struct ib_qp ibqp; 94 95 /* Work queue info */ 96 struct ib_umem *sq_umem; 97 int sqe; 98 u64 sq_gdma_region; 99 u64 sq_id; 100 mana_handle_t tx_object; 101 102 /* The port on the IB device, starting with 1 */ 103 u32 port; 104 }; 105 106 struct mana_ib_ucontext { 107 struct ib_ucontext ibucontext; 108 u32 doorbell; 109 }; 110 111 struct mana_ib_rwq_ind_table { 112 struct ib_rwq_ind_table ib_ind_table; 113 }; 114 115 enum mana_ib_command_code { 116 MANA_IB_GET_ADAPTER_CAP = 0x30001, 117 }; 118 119 struct mana_ib_query_adapter_caps_req { 120 struct gdma_req_hdr hdr; 121 }; /*HW Data */ 122 123 struct mana_ib_query_adapter_caps_resp { 124 struct gdma_resp_hdr hdr; 125 u32 max_sq_id; 126 u32 max_rq_id; 127 u32 max_cq_id; 128 u32 max_qp_count; 129 u32 max_cq_count; 130 u32 max_mr_count; 131 u32 max_pd_count; 132 u32 max_inbound_read_limit; 133 u32 max_outbound_read_limit; 134 u32 mw_count; 135 u32 max_srq_count; 136 u32 max_requester_sq_size; 137 u32 max_responder_sq_size; 138 u32 max_requester_rq_size; 139 u32 max_responder_rq_size; 140 u32 max_send_sge_count; 141 u32 max_recv_sge_count; 142 u32 max_inline_data_size; 143 }; /* HW Data */ 144 145 static inline struct gdma_context *mdev_to_gc(struct mana_ib_dev *mdev) 146 { 147 return mdev->gdma_dev->gdma_context; 148 } 149 150 static inline struct net_device *mana_ib_get_netdev(struct ib_device *ibdev, u32 port) 151 { 152 struct mana_ib_dev *mdev = container_of(ibdev, struct mana_ib_dev, ib_dev); 153 struct gdma_context *gc = mdev_to_gc(mdev); 154 struct mana_context *mc = gc->mana.driver_data; 155 156 if (port < 1 || port > mc->num_ports) 157 return NULL; 158 return mc->ports[port - 1]; 159 } 160 161 int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); 162 163 int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, 164 mana_handle_t *gdma_region); 165 166 int mana_ib_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, 167 mana_handle_t *gdma_region, u64 virt); 168 169 int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev, 170 mana_handle_t gdma_region); 171 172 struct ib_wq *mana_ib_create_wq(struct ib_pd *pd, 173 struct ib_wq_init_attr *init_attr, 174 struct ib_udata *udata); 175 176 int mana_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr, 177 u32 wq_attr_mask, struct ib_udata *udata); 178 179 int mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_udata *udata); 180 181 int mana_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table, 182 struct ib_rwq_ind_table_init_attr *init_attr, 183 struct ib_udata *udata); 184 185 int mana_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl); 186 187 struct ib_mr *mana_ib_get_dma_mr(struct ib_pd *ibpd, int access_flags); 188 189 struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, 190 u64 iova, int access_flags, 191 struct ib_udata *udata); 192 193 int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata); 194 195 int mana_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr, 196 struct ib_udata *udata); 197 198 int mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 199 int attr_mask, struct ib_udata *udata); 200 201 int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata); 202 203 int mana_ib_cfg_vport(struct mana_ib_dev *dev, u32 port_id, 204 struct mana_ib_pd *pd, u32 doorbell_id); 205 void mana_ib_uncfg_vport(struct mana_ib_dev *dev, struct mana_ib_pd *pd, 206 u32 port); 207 208 int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, 209 struct ib_udata *udata); 210 211 int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata); 212 213 int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); 214 int mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); 215 216 int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontext, 217 struct ib_udata *udata); 218 void mana_ib_dealloc_ucontext(struct ib_ucontext *ibcontext); 219 220 int mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma); 221 222 int mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num, 223 struct ib_port_immutable *immutable); 224 int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props, 225 struct ib_udata *uhw); 226 int mana_ib_query_port(struct ib_device *ibdev, u32 port, 227 struct ib_port_attr *props); 228 int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index, 229 union ib_gid *gid); 230 231 void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext); 232 233 int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *mdev); 234 #endif 235