| 1 |
/* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-only */ |
| 2 |
/* SPDX-FileCopyrightText: Copyright Amazon.com, Inc. or its affiliates. All rights reserved. */ |
| 3 |
|
| 4 |
#ifndef EFA_UNIT_TEST_RDMA_CORE_MOCKS_H |
| 5 |
#define EFA_UNIT_TEST_RDMA_CORE_MOCKS_H |
| 6 |
|
| 7 |
extern struct efa_unit_test_mocks g_efa_unit_test_mocks; |
| 8 |
|
| 9 |
struct efa_mock_ibv_send_wr_list |
| 10 |
{ |
| 11 |
struct ibv_send_wr *head; |
| 12 |
struct ibv_send_wr *tail; |
| 13 |
}; |
| 14 |
|
| 15 |
void efa_mock_ibv_send_wr_list_destruct(struct efa_mock_ibv_send_wr_list *wr_list); |
| 16 |
|
| 17 |
struct ibv_ah *__real_ibv_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr); |
| 18 |
|
| 19 |
struct ibv_ah *efa_mock_ibv_create_ah_check_mock(struct ibv_pd *pd, struct ibv_ah_attr *attr); |
| 20 |
|
| 21 |
int __real_efadv_query_device(struct ibv_context *ibvctx, struct efadv_device_attr *attr, |
| 22 |
uint32_t inlen); |
| 23 |
|
| 24 |
int efa_mock_efadv_query_device_return_mock(struct ibv_context *ibvctx, struct efadv_device_attr *attr, |
| 25 |
uint32_t inlen); |
| 26 |
|
| 27 |
extern void *g_ibv_submitted_wr_id_vec[EFA_RDM_EP_MAX_WR_PER_IBV_POST_SEND]; |
| 28 |
|
| 29 |
extern int g_ibv_submitted_wr_id_cnt; |
| 30 |
|
| 31 |
void efa_ibv_submitted_wr_id_vec_clear(); |
| 32 |
|
| 33 |
void efa_mock_ibv_wr_start_no_op(struct ibv_qp_ex *qp); |
| 34 |
|
| 35 |
void efa_mock_ibv_wr_send_save_wr(struct ibv_qp_ex *qp); |
| 36 |
|
| 37 |
void efa_mock_ibv_wr_send_verify_handshake_pkt_local_host_id_and_save_wr(struct ibv_qp_ex *qp); |
| 38 |
|
| 39 |
void efa_mock_ibv_wr_rdma_write_save_wr(struct ibv_qp_ex *qp, uint32_t rkey, |
| 40 |
uint64_t remote_addr); |
| 41 |
|
| 42 |
void efa_mock_ibv_wr_set_inline_data_list_no_op(struct ibv_qp_ex *qp, |
| 43 |
size_t num_buf, |
| 44 |
const struct ibv_data_buf *buf_list); |
| 45 |
|
| 46 |
void efa_mock_ibv_wr_set_sge_list_no_op(struct ibv_qp_ex *qp, |
| 47 |
size_t num_sge, |
| 48 |
const struct ibv_sge *sge_list); |
| 49 |
|
| 50 |
void efa_mock_ibv_wr_set_ud_addr_no_op(struct ibv_qp_ex *qp, struct ibv_ah *ah, |
| 51 |
uint32_t remote_qpn, uint32_t remote_qkey); |
| 52 |
|
| 53 |
int efa_mock_ibv_wr_complete_no_op(struct ibv_qp_ex *qp); |
| 54 |
|
| 55 |
int efa_mock_ibv_start_poll_return_mock(struct ibv_cq_ex *ibvcqx, |
| 56 |
struct ibv_poll_cq_attr *attr); |
| 57 |
|
| 58 |
int efa_mock_ibv_start_poll_use_saved_send_wr_with_mock_status(struct ibv_cq_ex *ibvcqx, |
| 59 |
struct ibv_poll_cq_attr *attr); |
| 60 |
|
| 61 |
int efa_mock_ibv_next_poll_return_mock(struct ibv_cq_ex *ibvcqx); |
| 62 |
|
| 63 |
int efa_mock_ibv_next_poll_use_saved_send_wr_with_mock_status(struct ibv_cq_ex *ibvcqx); |
| 64 |
|
| 65 |
void efa_mock_ibv_end_poll_check_mock(struct ibv_cq_ex *ibvcqx); |
| 66 |
|
| 67 |
uint32_t efa_mock_ibv_read_opcode_return_mock(struct ibv_cq_ex *current); |
| 68 |
|
| 69 |
uint32_t efa_mock_ibv_read_vendor_err_return_mock(struct ibv_cq_ex *current); |
| 70 |
|
| 71 |
uint32_t efa_mock_ibv_read_qp_num_return_mock(struct ibv_cq_ex *current); |
| 72 |
|
| 73 |
uint32_t efa_mock_ibv_read_wc_flags_return_mock(struct ibv_cq_ex *current); |
| 74 |
|
| 75 |
uint32_t efa_mock_ibv_wc_read_imm_data_return_mock(struct ibv_cq_ex *current); |
| 76 |
|
| 77 |
bool efa_mock_efadv_wc_is_unsolicited(struct efadv_cq *efadv_cq); |
| 78 |
|
| 79 |
void efa_mock_ibv_wr_send_imm_save_wr(struct ibv_qp_ex *qp, __be32 imm_data); |
| 80 |
|
| 81 |
ssize_t __real_ofi_copy_from_hmem_iov(void *dest, size_t size, |
| 82 |
enum fi_hmem_iface hmem_iface, uint64_t device, |
| 83 |
const struct iovec *hmem_iov, |
| 84 |
size_t hmem_iov_count, uint64_t hmem_iov_offset); |
| 85 |
|
| 86 |
extern int g_ofi_copy_from_hmem_iov_call_counter; |
| 87 |
ssize_t efa_mock_ofi_copy_from_hmem_iov_inc_counter(void *dest, size_t size, |
| 88 |
enum fi_hmem_iface hmem_iface, uint64_t device, |
| 89 |
const struct iovec *hmem_iov, |
| 90 |
size_t hmem_iov_count, uint64_t hmem_iov_offset); |
| 91 |
|
| 92 |
int __real_efa_rdm_pke_read(struct efa_rdm_ope *ope); |
| 93 |
|
| 94 |
bool __real_efa_device_support_unsolicited_write_recv(); |
| 95 |
|
| 96 |
int efa_mock_efa_rdm_pke_read_return_mock(struct efa_rdm_ope *ope); |
| 97 |
|
| 98 |
ssize_t __real_efa_rdm_pke_proc_matched_rtm(struct efa_rdm_pke *pkt_entry); |
| 99 |
|
| 100 |
ssize_t efa_mock_efa_rdm_pke_proc_matched_rtm_no_op(struct efa_rdm_pke *pkt_entry); |
| 101 |
|
| 102 |
ssize_t __real_efa_rdm_ope_post_send(struct efa_rdm_ope *ope, int pkt_type); |
| 103 |
|
| 104 |
ssize_t efa_mock_efa_rdm_ope_post_send_return_mock(struct efa_rdm_ope *ope, int pkt_type); |
| 105 |
|
| 106 |
bool efa_mock_efa_device_support_unsolicited_write_recv(void); |
| 107 |
|
| 108 |
int efa_mock_ibv_post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr, |
| 109 |
struct ibv_recv_wr **bad_wr); |
| 110 |
|
| 111 |
void efa_mock_ibv_wr_rdma_read_save_wr(struct ibv_qp_ex *qp, uint32_t rkey, |
| 112 |
uint64_t remote_addr); |
| 113 |
|
| 114 |
void efa_mock_ibv_wr_rdma_write_imm_save_wr(struct ibv_qp_ex *qp, uint32_t rkey, |
| 115 |
uint64_t remote_addr, |
| 116 |
__be32 imm_data); |
| 117 |
|
| 118 |
struct efa_unit_test_mocks |
| 119 |
{ |
| 120 |
uint64_t local_host_id; |
| 121 |
uint64_t peer_host_id; |
| 122 |
struct ibv_ah *(*ibv_create_ah)(struct ibv_pd *pd, struct ibv_ah_attr *attr); |
| 123 |
|
| 124 |
int (*efadv_query_device)(struct ibv_context *ibvctx, struct efadv_device_attr *attr, |
| 125 |
uint32_t inlen); |
| 126 |
#if HAVE_EFADV_CQ_EX |
| 127 |
|
| 128 |
struct ibv_cq_ex *(*efadv_create_cq)(struct ibv_context *ibvctx, |
| 129 |
struct ibv_cq_init_attr_ex *attr_ex, |
| 130 |
struct efadv_cq_init_attr *efa_attr, |
| 131 |
uint32_t inlen); |
| 132 |
#endif |
| 133 |
|
| 134 |
#if HAVE_NEURON |
| 135 |
void *(*neuron_alloc)(void **handle, size_t size); |
| 136 |
#endif |
| 137 |
|
| 138 |
#if HAVE_CUDA |
| 139 |
cudaError_t (*ofi_cudaMalloc)(void **ptr, size_t size); |
| 140 |
#endif |
| 141 |
|
| 142 |
ssize_t (*ofi_copy_from_hmem_iov)(void *dest, size_t size, |
| 143 |
enum fi_hmem_iface hmem_iface, uint64_t device, |
| 144 |
const struct iovec *hmem_iov, |
| 145 |
size_t hmem_iov_count, uint64_t hmem_iov_offset); |
| 146 |
|
| 147 |
int (*efa_rdm_pke_read)(struct efa_rdm_ope *ope); |
| 148 |
|
| 149 |
ssize_t (*efa_rdm_pke_proc_matched_rtm)(struct efa_rdm_pke *pkt_entry); |
| 150 |
|
| 151 |
ssize_t (*efa_rdm_ope_post_send)(struct efa_rdm_ope *ope, int pkt_type); |
| 152 |
|
| 153 |
bool (*efa_device_support_unsolicited_write_recv)(void); |
| 154 |
|
| 155 |
enum ibv_fork_status (*ibv_is_fork_initialized)(void); |
| 156 |
|
| 157 |
#if HAVE_EFADV_QUERY_MR |
| 158 |
int (*efadv_query_mr)(struct ibv_mr *ibv_mr, struct efadv_mr_attr *attr, uint32_t inlen); |
| 159 |
#endif |
| 160 |
|
| 161 |
#if HAVE_EFA_DATA_IN_ORDER_ALIGNED_128_BYTES |
| 162 |
int (*ibv_query_qp_data_in_order)(struct ibv_qp *qp, enum ibv_wr_opcode op, uint32_t flags); |
| 163 |
#endif |
| 164 |
}; |
| 165 |
|
| 166 |
struct ibv_cq_ex *efa_mock_create_cq_ex_return_null(struct ibv_context *context, struct ibv_cq_init_attr_ex *init_attr); |
| 167 |
|
| 168 |
#if HAVE_EFADV_CQ_EX |
| 169 |
struct ibv_cq_ex *__real_efadv_create_cq(struct ibv_context *ibvctx, |
| 170 |
struct ibv_cq_init_attr_ex *attr_ex, |
| 171 |
struct efadv_cq_init_attr *efa_attr, |
| 172 |
uint32_t inlen); |
| 173 |
uint32_t efa_mock_ibv_read_src_qp_return_mock(struct ibv_cq_ex *current); |
| 174 |
uint32_t efa_mock_ibv_read_byte_len_return_mock(struct ibv_cq_ex *current); |
| 175 |
uint32_t efa_mock_ibv_read_slid_return_mock(struct ibv_cq_ex *current); |
| 176 |
int efa_mock_efadv_wc_read_sgid_return_mock(struct efadv_cq *efadv_cq, union ibv_gid *sgid); |
| 177 |
int efa_mock_efadv_wc_read_sgid_return_zero_code_and_expect_next_poll_and_set_gid(struct efadv_cq *efadv_cq, union ibv_gid *sgid); |
| 178 |
int efa_mock_ibv_start_poll_expect_efadv_wc_read_ah_and_return_mock(struct ibv_cq_ex *ibvcqx, |
| 179 |
struct ibv_poll_cq_attr *attr); |
| 180 |
int efa_mock_ibv_next_poll_check_function_called_and_return_mock(struct ibv_cq_ex *ibvcqx); |
| 181 |
struct ibv_cq_ex *efa_mock_efadv_create_cq_with_ibv_create_cq_ex(struct ibv_context *ibvctx, |
| 182 |
struct ibv_cq_init_attr_ex *attr_ex, |
| 183 |
struct efadv_cq_init_attr *efa_attr, |
| 184 |
uint32_t inlen); |
| 185 |
struct ibv_cq_ex *efa_mock_efadv_create_cq_set_eopnotsupp_and_return_null(struct ibv_context *ibvctx, |
| 186 |
struct ibv_cq_init_attr_ex *attr_ex, |
| 187 |
struct efadv_cq_init_attr *efa_attr, |
| 188 |
uint32_t inlen); |
| 189 |
#endif |
| 190 |
|
| 191 |
#if HAVE_NEURON |
| 192 |
void *__real_neuron_alloc(void **handle, size_t size); |
| 193 |
void *efa_mock_neuron_alloc_return_null(void **handle, size_t size); |
| 194 |
void *efa_mock_neuron_alloc_return_mock(void **handle, size_t size); |
| 195 |
#endif |
| 196 |
|
| 197 |
#if HAVE_CUDA |
| 198 |
cudaError_t __real_ofi_cudaMalloc(void **ptr, size_t size); |
| 199 |
cudaError_t efa_mock_ofi_cudaMalloc_return_mock(void **ptr, size_t size); |
| 200 |
#endif |
| 201 |
|
| 202 |
#if HAVE_EFADV_QUERY_MR |
| 203 |
int __real_efadv_query_mr(struct ibv_mr *ibv_mr, struct efadv_mr_attr *attr, uint32_t inlen); |
| 204 |
int efa_mock_efadv_query_mr_recv_ic_id_0(struct ibv_mr *ibv_mr, struct efadv_mr_attr *attr, uint32_t inlen); |
| 205 |
int efa_mock_efadv_query_mr_rdma_read_ic_id_1(struct ibv_mr *ibv_mr, struct efadv_mr_attr *attr, uint32_t inlen); |
| 206 |
int efa_mock_efadv_query_mr_rdma_recv_ic_id_2(struct ibv_mr *ibv_mr, struct efadv_mr_attr *attr, uint32_t inlen); |
| 207 |
int efa_mock_efadv_query_mr_recv_and_rdma_read_ic_id_0_1(struct ibv_mr *ibv_mr, struct efadv_mr_attr *attr, uint32_t inlen); |
| 208 |
#endif |
| 209 |
|
| 210 |
#if HAVE_EFA_DATA_IN_ORDER_ALIGNED_128_BYTES |
| 211 |
int __real_ibv_query_qp_data_in_order(struct ibv_qp *qp, enum ibv_wr_opcode op, uint32_t flags); |
| 212 |
int efa_mock_ibv_query_qp_data_in_order_return_0(struct ibv_qp *qp, enum ibv_wr_opcode op, uint32_t flags); |
| 213 |
int efa_mock_ibv_query_qp_data_in_order_return_in_order_aligned_128_bytes(struct ibv_qp *qp, enum ibv_wr_opcode op, uint32_t flags); |
| 214 |
#endif |
| 215 |
|
| 216 |
enum ibv_fork_status __real_ibv_is_fork_initialized(void); |
| 217 |
|
| 218 |
enum ibv_fork_status efa_mock_ibv_is_fork_initialized_return_mock(void); |
| 219 |
|
| 220 |
#endif |