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_dev { 31 struct ib_device ib_dev; 32 struct gdma_dev *gdma_dev; 33 }; 34 35 struct mana_ib_wq { 36 struct ib_wq ibwq; 37 struct ib_umem *umem; 38 int wqe; 39 u32 wq_buf_size; 40 u64 gdma_region; 41 u64 id; 42 mana_handle_t rx_object; 43 }; 44 45 struct mana_ib_pd { 46 struct ib_pd ibpd; 47 u32 pdn; 48 mana_handle_t pd_handle; 49 50 /* Mutex for sharing access to vport_use_count */ 51 struct mutex vport_mutex; 52 int vport_use_count; 53 54 bool tx_shortform_allowed; 55 u32 tx_vp_offset; 56 }; 57 58 struct mana_ib_mr { 59 struct ib_mr ibmr; 60 struct ib_umem *umem; 61 mana_handle_t mr_handle; 62 }; 63 64 struct mana_ib_cq { 65 struct ib_cq ibcq; 66 struct ib_umem *umem; 67 int cqe; 68 u64 gdma_region; 69 u64 id; 70 }; 71 72 struct mana_ib_qp { 73 struct ib_qp ibqp; 74 75 /* Work queue info */ 76 struct ib_umem *sq_umem; 77 int sqe; 78 u64 sq_gdma_region; 79 u64 sq_id; 80 mana_handle_t tx_object; 81 82 /* The port on the IB device, starting with 1 */ 83 u32 port; 84 }; 85 86 struct mana_ib_ucontext { 87 struct ib_ucontext ibucontext; 88 u32 doorbell; 89 }; 90 91 struct mana_ib_rwq_ind_table { 92 struct ib_rwq_ind_table ib_ind_table; 93 }; 94 95 int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, 96 mana_handle_t *gdma_region); 97 98 int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev, 99 mana_handle_t gdma_region); 100 101 struct ib_wq *mana_ib_create_wq(struct ib_pd *pd, 102 struct ib_wq_init_attr *init_attr, 103 struct ib_udata *udata); 104 105 int mana_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr, 106 u32 wq_attr_mask, struct ib_udata *udata); 107 108 int mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_udata *udata); 109 110 int mana_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table, 111 struct ib_rwq_ind_table_init_attr *init_attr, 112 struct ib_udata *udata); 113 114 int mana_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl); 115 116 struct ib_mr *mana_ib_get_dma_mr(struct ib_pd *ibpd, int access_flags); 117 118 struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, 119 u64 iova, int access_flags, 120 struct ib_udata *udata); 121 122 int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata); 123 124 int mana_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr, 125 struct ib_udata *udata); 126 127 int mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 128 int attr_mask, struct ib_udata *udata); 129 130 int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata); 131 132 int mana_ib_cfg_vport(struct mana_ib_dev *dev, u32 port_id, 133 struct mana_ib_pd *pd, u32 doorbell_id); 134 void mana_ib_uncfg_vport(struct mana_ib_dev *dev, struct mana_ib_pd *pd, 135 u32 port); 136 137 int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, 138 struct ib_udata *udata); 139 140 int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata); 141 142 int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); 143 int mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); 144 145 int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontext, 146 struct ib_udata *udata); 147 void mana_ib_dealloc_ucontext(struct ib_ucontext *ibcontext); 148 149 int mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma); 150 151 int mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num, 152 struct ib_port_immutable *immutable); 153 int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props, 154 struct ib_udata *uhw); 155 int mana_ib_query_port(struct ib_device *ibdev, u32 port, 156 struct ib_port_attr *props); 157 int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index, 158 union ib_gid *gid); 159 160 void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext); 161 162 #endif 163