diff --git a/arch/x86/mm/memory.c b/arch/x86/mm/memory.c index c4db0eb32..e858616e7 100644 --- a/arch/x86/mm/memory.c +++ b/arch/x86/mm/memory.c @@ -373,32 +373,3 @@ oom: LOG_ERROR("BUG: Failed to init mm!\n"); while(1) {HALT; } } - -void * ib_memory_init(void) -{ - size_t phyaddr, viraddr, bits; - int err; - - phyaddr = (size_t) &kernel_end - IB_MEMORY_SIZE; - bits = PG_RW|PG_GLOBAL|PG_NX; - viraddr = vma_alloc(IB_MEMORY_NPAGES * PAGE_SIZE, VMA_READ|VMA_WRITE|VMA_CACHEABLE); - if (BUILTIN_EXPECT(!viraddr, 0)) { - LOG_INFO("BUILTIN_EXPECT failed: ib_memory_init 1\n"); - return NULL; - } - - LOG_INFO("ib_memory_init, size: %lu\n", IB_MEMORY_SIZE); - LOG_INFO("\tGuest Phys Start: %p\tEnd: %p\n", (uint8_t *) phyaddr, (uint8_t *) &kernel_end); - /* LOG_INFO("\tHost Virt Start: %p\tEnd: %p\n", */ - /* phyaddr + host_kernel_start, (size_t) &kernel_end + host_kernel_start); */ - - err = page_map(viraddr, phyaddr, IB_MEMORY_NPAGES, bits); - if (BUILTIN_EXPECT(err, 0)) { - LOG_INFO("BUILTIN_EXPECT failed: ib_memory_init 2\n"); - vma_free(viraddr, viraddr + IB_MEMORY_NPAGES*PAGE_SIZE); - return NULL; - } - - LOG_INFO("ib_memory_init finished\n"); - return (void *) viraddr; -} diff --git a/arch/x86/mm/page.c b/arch/x86/mm/page.c index e95939366..2d78bad7a 100644 --- a/arch/x86/mm/page.c +++ b/arch/x86/mm/page.c @@ -118,10 +118,14 @@ size_t virt_to_phys(size_t addr) size_t phys_to_virt(size_t phy) { LOG_INFO("phys_to_virt called.\n"); + LOG_INFO("phy: Hex: %zx\n", phy); size_t pfn = phy & PFN_MASK; size_t off = phy & ~PAGE_MASK; LOG_INFO("off: Hex: %zx, Dec: %zd\n", off, off); LOG_INFO("pfn: Hex: %zx, Dec: %zd\n", pfn, pfn); + if (phy == 0) { + return 0; + } size_t * pml4 = self[PAGE_LEVELS-1]; for(size_t i=0; i<(1 << PAGE_MAP_BITS); i++) { @@ -149,23 +153,23 @@ size_t phys_to_virt(size_t phy) /* LOG_INFO("Fourth for.\n"); */ if (pgt[l] & PG_PRESENT) { // Valid page table entry - /* LOG_INFO("Present.\n"); */ + /* LOG_INFO("p"); */ if ((pgt[l] & PFN_MASK) == pfn) { // Page frame found LOG_INFO("SAME PAGE.\n"); - LOG_INFO("i: Hex: %zx, Dec: %zd\n", i, i); - LOG_INFO("j: Hex: %zx, Dec: %zd\n", j, j); - LOG_INFO("k: Hex: %zx, Dec: %zd\n", k, k); - LOG_INFO("l: Hex: %zx, Dec: %zd\n", l, l); + /* LOG_INFO("i: Hex: %zx, Dec: %zd\n", i, i); */ + /* LOG_INFO("j: Hex: %zx, Dec: %zd\n", j, j); */ + /* LOG_INFO("k: Hex: %zx, Dec: %zd\n", k, k); */ + /* LOG_INFO("l: Hex: %zx, Dec: %zd\n", l, l); */ size_t vpn = ((((((i << PAGE_MAP_BITS) | j) << PAGE_MAP_BITS) | k) << PAGE_MAP_BITS) | l) << PAGE_BITS; - LOG_INFO("vpn: Hex: %zx, Dec: %zd\n", vpn, vpn); + /* LOG_INFO("vpn: Hex: %zx, Dec: %zd\n", vpn, vpn); */ size_t sext = i & (1UL << (PAGE_MAP_BITS - 1)); - LOG_INFO("sext: Hex: %zx, Dec: %zd\n", sext, sext); + /* LOG_INFO("sext: Hex: %zx, Dec: %zd\n", sext, sext); */ if (sext) { - LOG_INFO("sext true"); + /* LOG_INFO("sext true"); */ vpn |= ~0UL << VIRT_BITS; - LOG_INFO("vpn: Hex: %zx, Dec: %zd\n", vpn, vpn); + /* LOG_INFO("vpn: Hex: %zx, Dec: %zd\n", vpn, vpn); */ } - LOG_INFO("return: Hex: %zx, Dec: %zd\n", vpn | off, vpn | off); + /* LOG_INFO("return: Hex: %zx, Dec: %zd\n", vpn | off, vpn | off); */ return vpn | off; } } @@ -174,7 +178,8 @@ size_t phys_to_virt(size_t phy) } } - sys_exit(-EFAULT); // TODO: remove this. + LOG_INFO("PAGE NOT FOUND\n"); + /* sys_exit(-EFAULT); // TODO: remove this. */ return 0; } diff --git a/include/hermit/ibv.h b/include/hermit/ibv.h index ad4a3692b..d4ffac9db 100644 --- a/include/hermit/ibv.h +++ b/include/hermit/ibv.h @@ -41,13 +41,82 @@ extern "C" { #endif -struct ibv_device ** ibv_get_device_list(int * num_devices); -const char * ibv_get_device_name(struct ibv_device *device); -struct ibv_context * ibv_open_device(struct ibv_device * device); -int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr); -struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context); +// struct ibv_device ** ibv_get_device_list(int * num_devices); +// const char * ibv_get_device_name(struct ibv_device *device); +// struct ibv_context * ibv_open_device(struct ibv_device * device); +// int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr); +// struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context); -void kernel_ibv_log(); +const char * ibv_wc_status_str(enum ibv_wc_status status); +int ibv_rate_to_mult(enum ibv_rate rate); +enum ibv_rate mult_to_ibv_rate(int mult); +int ibv_rate_to_mbps(enum ibv_rate rate); +enum ibv_rate mbps_to_ibv_rate(int mbps); +struct verbs_context * verbs_get_ctx(struct ibv_context * ctx); +struct ibv_device ** ibv_get_device_list(int * num_devices); +void ibv_free_device_list(struct ibv_device ** list); +const char * ibv_get_device_name(struct ibv_device * device); +__be64 ibv_get_device_guid(struct ibv_device * device); +struct ibv_context * ibv_open_device(struct ibv_device * device); +int ibv_close_device(struct ibv_context * context); +int ibv_get_async_event(struct ibv_context * context, struct ibv_async_event * event); +void ibv_ack_async_event(struct ibv_async_event * event); +int ibv_query_device(struct ibv_context * context, struct ibv_device_attr * device_attr); +int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr); +int ___ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr); +int ibv_query_gid(struct ibv_context * context, uint8_t port_num, int index, union ibv_gid * gid); +int ibv_query_pkey(struct ibv_context * context, uint8_t port_num, int index, __be16 * pkey); +struct ibv_pd * ibv_alloc_pd(struct ibv_context * context); +int ibv_dealloc_pd(struct ibv_pd * pd); +struct ibv_flow * ibv_create_flow(struct ibv_qp * qp, struct ibv_flow_attr * flow); +int ibv_destroy_flow(struct ibv_flow * flow_id); +struct ibv_xrcd * ibv_open_xrcd(struct ibv_context * context, struct ibv_xrcd_init_attr * xrcd_init_attr); +int ibv_close_xrcd(struct ibv_xrcd * xrcd); +struct ibv_mr * ibv_reg_mr(struct ibv_pd * pd, void * addr, int length, int access); +int ibv_rereg_mr(struct ibv_mr * mr, int flags, struct ibv_pd * pd, void * addr, int length, int access); +int ibv_dereg_mr(struct ibv_mr * mr); +struct ibv_mw * ibv_alloc_mw(struct ibv_pd * pd, enum ibv_mw_type type); +int ibv_dealloc_mw(struct ibv_mw * mw); +uint32_t ibv_inc_rkey(uint32_t rkey); +int ibv_bind_mw(struct ibv_qp * qp, struct ibv_mw * mw, struct ibv_mw_bind * mw_bind); +struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context); +int ibv_destroy_comp_channel(struct ibv_comp_channel * channel); +struct ibv_cq * ibv_create_cq(struct ibv_context * context, int cqe, void * cq_context, struct ibv_comp_channel * channel, int comp_vector); +int ibv_resize_cq(struct ibv_cq * cq, int cqe); +int ibv_destroy_cq(struct ibv_cq * cq); +int ibv_get_cq_event(struct ibv_comp_channel * channel, struct ibv_cq ** cq, void ** cq_context); +void ibv_ack_cq_events(struct ibv_cq * cq, unsigned int nevents); +int ibv_poll_cq(struct ibv_cq * cq, int num_entries, struct ibv_wc * wc); +int ibv_req_notify_cq(struct ibv_cq * cq, int solicited_only); +struct ibv_srq * ibv_create_srq(struct ibv_pd * pd, struct ibv_srq_init_attr * srq_init_attr); +struct ibv_srq * ibv_create_srq_ex(struct ibv_context * context, struct ibv_srq_init_attr_ex * srq_init_attr_ex); +int ibv_modify_srq(struct ibv_srq * srq, struct ibv_srq_attr * srq_attr, int srq_attr_mask); +int ibv_query_srq(struct ibv_srq * srq, struct ibv_srq_attr * srq_attr); +int ibv_get_srq_num(struct ibv_srq * srq, uint32_t * srq_num); +int ibv_destroy_srq(struct ibv_srq * srq); +int ibv_post_srq_recv(struct ibv_srq * srq, struct ibv_recv_wr * recv_wr, struct ibv_recv_wr ** bad_recv_wr); +struct ibv_qp * ibv_create_qp(struct ibv_pd * pd, struct ibv_qp_init_attr * qp_init_attr); +struct ibv_qp * ibv_create_qp_ex(struct ibv_context * context, struct ibv_qp_init_attr_ex * qp_init_attr_ex); +int ibv_query_device_ex(struct ibv_context * context, const struct ibv_query_device_ex_input * input, struct ibv_device_attr_ex * attr); +struct ibv_qp * ibv_open_qp(struct ibv_context * context, struct ibv_qp_open_attr * qp_open_attr); +int ibv_modify_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask); +int ibv_query_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask, struct ibv_qp_init_attr * init_attr); +int ibv_destroy_qp(struct ibv_qp * qp); +int ibv_post_send(struct ibv_qp * qp, struct ibv_send_wr * wr, struct ibv_send_wr ** bad_wr); +int ibv_post_recv(struct ibv_qp * qp, struct ibv_recv_wr * wr, struct ibv_recv_wr ** bad_wr); +struct ibv_ah * ibv_create_ah(struct ibv_pd * pd, struct ibv_ah_attr * attr); +int ibv_init_ah_from_wc(struct ibv_context * context, uint8_t port_num, struct ibv_wc * wc, struct ibv_grh * grh, struct ibv_ah_attr * ah_attr); +struct ibv_ah * ibv_create_ah_from_wc(struct ibv_pd * pd, struct ibv_wc * wc, struct ibv_grh * grh, uint8_t port_num); +int ibv_destroy_ah(struct ibv_ah * ah); +int ibv_attach_mcast(struct ibv_qp * qp, const union ibv_gid * gid, uint16_t lid); +int ibv_detach_mcast(struct ibv_qp * qp, const union ibv_gid * gid, uint16_t lid); +int ibv_fork_init( ); +const char * ibv_node_type_str(enum ibv_node_type node_type); +const char * ibv_port_state_str(enum ibv_port_state port_state); +const char * ibv_event_type_str(enum ibv_event_type event); +int ibv_is_qpt_supported(uint32_t caps, enum ibv_qp_type qpt); + +// void kernel_ibv_log(); #ifdef __cplusplus diff --git a/include/hermit/ibv_guest_host.h b/include/hermit/ibv_guest_host.h index 21691a818..139236f03 100644 --- a/include/hermit/ibv_guest_host.h +++ b/include/hermit/ibv_guest_host.h @@ -49,7 +49,8 @@ struct ibv_device * guest_to_host_ibv_device(struct ibv_device * device); struct ibv_context * guest_to_host_ibv_context(struct ibv_context * context); struct ibv_context_ops * guest_to_host_ibv_context_ops(struct ibv_context_ops * context_ops); struct ibv_port_attr * guest_to_host_ibv_port_attr(struct ibv_port_attr * port_attr); -struct ibv_comp_channel * guest_to_host_ibv_comp_channel(struct ibv_comp_channel * channel); +struct ibv_recv_wr * guest_to_host_ibv_recv_wr(struct ibv_recv_wr * wr); +struct ibv_sge * guest_to_host_ibv_sge(struct ibv_sge * sg); struct ibv_abi_compat_v2 * guest_to_host_ibv_abi_compat_v2(struct ibv_abi_compat_v2 * abi_compat); pthread_mutex_t * guest_to_host_pthread_mutex_t(pthread_mutex_t * mutex); @@ -58,6 +59,8 @@ struct ibv_context * host_to_guest_ibv_context(struct ibv_context * contex struct ibv_context_ops * host_to_guest_ibv_context_ops(struct ibv_context_ops * context_ops, addr_type type); struct ibv_port_attr * host_to_guest_ibv_port_attr(struct ibv_port_attr * port_attr, addr_type type); struct ibv_comp_channel * host_to_guest_ibv_comp_channel(struct ibv_comp_channel * channel, addr_type type); +struct ibv_recv_wr * host_to_guest_ibv_recv_wr(struct ibv_recv_wr * wr, addr_type type); +struct ibv_sge * host_to_guest_ibv_sge(struct ibv_sge * sg, addr_type type); struct ibv_abi_compat_v2 * host_to_guest_ibv_abi_compat_v2(struct ibv_abi_compat_v2 * abi_compat, addr_type type); pthread_mutex_t * host_to_guest_pthread_mutex_t(pthread_mutex_t * mutex, addr_type type); diff --git a/include/hermit/memory.h b/include/hermit/memory.h index 762de0b9c..89ed45f0c 100644 --- a/include/hermit/memory.h +++ b/include/hermit/memory.h @@ -39,9 +39,6 @@ /** @brief Initialize the memory subsystem */ int memory_init(void); -/** @brief Initialize the IB memory space */ -void * ib_memory_init(void); - /** @brief Request physical page frames */ size_t get_pages(size_t npages); diff --git a/include/hermit/stddef.h b/include/hermit/stddef.h index abba048ed..f5560f3f6 100644 --- a/include/hermit/stddef.h +++ b/include/hermit/stddef.h @@ -67,13 +67,76 @@ extern const size_t image_size; #define UHYVE_PORT_LSEEK 0x504 // InfiniBand uhyve port IDs -#define UHYVE_PORT_IBV_OPEN_DEVICE 0x510 -#define UHYVE_PORT_IBV_GET_DEVICE_LIST 0x511 -#define UHYVE_PORT_IBV_GET_DEVICE_NAME 0x512 -#define UHYVE_PORT_IBV_QUERY_PORT 0x513 -#define UHYVE_PORT_IBV_CREATE_COMP_CHANNEL 0x514 +#define UHYVE_PORT_IBV_WC_STATUS_STR 0x510 +#define UHYVE_PORT_IBV_RATE_TO_MULT 0x511 +#define UHYVE_PORT_MULT_TO_IBV_RATE 0x512 +#define UHYVE_PORT_IBV_RATE_TO_MBPS 0x513 +#define UHYVE_PORT_MBPS_TO_IBV_RATE 0x514 +#define UHYVE_PORT_VERBS_GET_CTX 0x528 +#define UHYVE_PORT_IBV_GET_DEVICE_LIST 0x529 +#define UHYVE_PORT_IBV_FREE_DEVICE_LIST 0x52A +#define UHYVE_PORT_IBV_GET_DEVICE_NAME 0x52B +#define UHYVE_PORT_IBV_GET_DEVICE_GUID 0x52C +#define UHYVE_PORT_IBV_OPEN_DEVICE 0x52D +#define UHYVE_PORT_IBV_CLOSE_DEVICE 0x52E +#define UHYVE_PORT_IBV_GET_ASYNC_EVENT 0x52F +#define UHYVE_PORT_IBV_ACK_ASYNC_EVENT 0x530 +#define UHYVE_PORT_IBV_QUERY_DEVICE 0x531 +#define UHYVE_PORT_IBV_QUERY_PORT 0x532 +#define UHYVE_PORT____IBV_QUERY_PORT 0x533 +#define UHYVE_PORT_IBV_QUERY_GID 0x534 +#define UHYVE_PORT_IBV_QUERY_PKEY 0x535 +#define UHYVE_PORT_IBV_ALLOC_PD 0x536 +#define UHYVE_PORT_IBV_DEALLOC_PD 0x537 +#define UHYVE_PORT_IBV_CREATE_FLOW 0x538 +#define UHYVE_PORT_IBV_DESTROY_FLOW 0x539 +#define UHYVE_PORT_IBV_OPEN_XRCD 0x53A +#define UHYVE_PORT_IBV_CLOSE_XRCD 0x53B +#define UHYVE_PORT_IBV_REG_MR 0x53C +#define UHYVE_PORT_IBV_REREG_MR 0x53D +#define UHYVE_PORT_IBV_DEREG_MR 0x53E +#define UHYVE_PORT_IBV_ALLOC_MW 0x53F +#define UHYVE_PORT_IBV_DEALLOC_MW 0x540 +#define UHYVE_PORT_IBV_INC_RKEY 0x541 +#define UHYVE_PORT_IBV_BIND_MW 0x542 +#define UHYVE_PORT_IBV_CREATE_COMP_CHANNEL 0x543 +#define UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL 0x544 +#define UHYVE_PORT_IBV_CREATE_CQ 0x545 +#define UHYVE_PORT_IBV_RESIZE_CQ 0x547 +#define UHYVE_PORT_IBV_DESTROY_CQ 0x548 +#define UHYVE_PORT_IBV_GET_CQ_EVENT 0x549 +#define UHYVE_PORT_IBV_ACK_CQ_EVENTS 0x54A +#define UHYVE_PORT_IBV_POLL_CQ 0x54B +#define UHYVE_PORT_IBV_REQ_NOTIFY_CQ 0x54C +#define UHYVE_PORT_IBV_CREATE_SRQ 0x54D +#define UHYVE_PORT_IBV_CREATE_SRQ_EX 0x54E +#define UHYVE_PORT_IBV_MODIFY_SRQ 0x54F +#define UHYVE_PORT_IBV_QUERY_SRQ 0x550 +#define UHYVE_PORT_IBV_GET_SRQ_NUM 0x551 +#define UHYVE_PORT_IBV_DESTROY_SRQ 0x552 +#define UHYVE_PORT_IBV_POST_SRQ_RECV 0x553 +#define UHYVE_PORT_IBV_CREATE_QP 0x554 +#define UHYVE_PORT_IBV_CREATE_QP_EX 0x555 +#define UHYVE_PORT_IBV_QUERY_DEVICE_EX 0x557 +#define UHYVE_PORT_IBV_OPEN_QP 0x558 +#define UHYVE_PORT_IBV_MODIFY_QP 0x559 +#define UHYVE_PORT_IBV_QUERY_QP 0x55A +#define UHYVE_PORT_IBV_DESTROY_QP 0x55B +#define UHYVE_PORT_IBV_POST_SEND 0x561 +#define UHYVE_PORT_IBV_POST_RECV 0x562 +#define UHYVE_PORT_IBV_CREATE_AH 0x563 +#define UHYVE_PORT_IBV_INIT_AH_FROM_WC 0x564 +#define UHYVE_PORT_IBV_CREATE_AH_FROM_WC 0x565 +#define UHYVE_PORT_IBV_DESTROY_AH 0x566 +#define UHYVE_PORT_IBV_ATTACH_MCAST 0x567 +#define UHYVE_PORT_IBV_DETACH_MCAST 0x568 +#define UHYVE_PORT_IBV_FORK_INIT 0x569 +#define UHYVE_PORT_IBV_NODE_TYPE_STR 0x56A +#define UHYVE_PORT_IBV_PORT_STATE_STR 0x56B +#define UHYVE_PORT_IBV_EVENT_TYPE_STR 0x56C +#define UHYVE_PORT_IBV_IS_QPT_SUPPORTED 0x56E -#define UHYVE_PORT_KERNEL_IBV_LOG 0x515 +// #define UHYVE_PORT_KERNEL_IBV_LOG 0x56F #define BUILTIN_EXPECT(exp, b) __builtin_expect((exp), (b)) diff --git a/kernel/ibv.c b/kernel/ibv.c index 3190dc515..c9b50e917 100644 --- a/kernel/ibv.c +++ b/kernel/ibv.c @@ -39,12 +39,9 @@ #include #include - -// TODO: Can/should we separate ibv_get_device_list into two KVM exit IOs to -// allocate the right amount of memory? -#define MAX_NUM_OF_IBV_DEVICES 16 - -static void * ret_guest; +#define MAX_CHAR_ARR_LENGTH 1024 +#define MAX_NUM_OF_IBV_DEVICES 16 // TODO: is this enough? +#define ETHERNET_LL_SIZE 6 /* @@ -55,35 +52,19 @@ typedef struct { // Parameters: int * num_devices; // Return value: - /* struct ibv_device * ret[MAX_NUM_OF_IBV_DEVICES]; */ struct ibv_device ** ret; } __attribute__((packed)) uhyve_ibv_get_device_list_t; -struct ibv_device ** ibv_get_device_list(int * num_devices) { - struct ibv_device ** ret_guest; +struct ibv_device ** ibv_get_device_list(int * num_devices) { // ! uhyve_ibv_get_device_list_t uhyve_args; uhyve_args.num_devices = (int *) guest_to_host((size_t) num_devices); - // Allocate memory for return value. - /* struct ibv_device * devs = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device)); */ - /* struct ibv_device ** ret_guest = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device *)); */ - - // We keep a list of the virtual addresses, so we can return it later, and map - // to physical addresses for the args struct passed to uhyve. - /* for (int i = 0; i < MAX_NUM_OF_IBV_DEVICES; i++) { */ - /* struct ibv_device * device_address = devs + i; */ - /* ret_guest[i] = device_address; */ - /* uhyve_args.ret[i] = (struct ibv_device *) guest_to_host((size_t) device_address); */ - /* } */ + struct ibv_device ** list; + list = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device *)); // NUM + 1 ??? + uhyve_args.ret = (struct ibv_device **) guest_to_host((size_t) list); uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_LIST, (unsigned) virt_to_phys((size_t) &uhyve_args)); - - ret_guest = (struct ibv_device **) host_to_guest((size_t) uhyve_args.ret); - for (int i = 0; i < *num_devices; i++) { - ret_guest[i] = host_to_guest_ibv_device(ret_guest[i], HOST); // TODO: Make this a host_to_guest fcn for lists of ptrs - } - - return ret_guest; + return list; } @@ -95,48 +76,17 @@ typedef struct { // Parameters: struct ibv_device * device; // Return value: - char * ret; // TODO: const? + char * ret; } __attribute__((packed)) uhyve_ibv_get_device_name_t; const char * ibv_get_device_name(struct ibv_device * device) { - char * ret_guest; uhyve_ibv_get_device_name_t uhyve_args; - uhyve_args.device = guest_to_host_ibv_device(device); + uhyve_args.device = device; + uhyve_args.ret = kmalloc(MAX_CHAR_ARR_LENGTH); uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_NAME, (unsigned) virt_to_phys((size_t) &uhyve_args)); - host_to_guest_ibv_device(device, GUEST); - ret_guest = (char *) host_to_guest((size_t) uhyve_args.ret); - - return ret_guest; -} - - -/* - * ibv_open_device - */ - -typedef struct { - // Parameters: - struct ibv_device * device; - // Return value: - struct ibv_context * ret; -} __attribute__((packed)) uhyve_ibv_open_device_t; - -struct ibv_context * ibv_open_device(struct ibv_device * device) { - struct ibv_context * ret_guest; - uhyve_ibv_open_device_t uhyve_args; - uhyve_args.device = guest_to_host_ibv_device(device); - - /* ret_guest = kmalloc(sizeof(struct ibv_context)); */ - /* uhyve_args.ret = (struct ibv_context *) guest_to_host((size_t) ret_guest); */ - - uhyve_send(UHYVE_PORT_IBV_OPEN_DEVICE, (unsigned) virt_to_phys((size_t)&uhyve_args)); - - host_to_guest_ibv_device(device, GUEST); - ret_guest = host_to_guest_ibv_context(uhyve_args.ret, HOST); - - return ret_guest; + return uhyve_args.ret; } @@ -155,14 +105,656 @@ typedef struct { int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr) { uhyve_ibv_query_port_t uhyve_args; - uhyve_args.context = guest_to_host_ibv_context(context); + uhyve_args.context = context; uhyve_args.port_num = port_num; - uhyve_args.port_attr = guest_to_host_ibv_port_attr(port_attr); + uhyve_args.port_attr = guest_to_host_ibv_port_attr(port_attr); // ! uhyve_send(UHYVE_PORT_IBV_QUERY_PORT, (unsigned) virt_to_phys((size_t) &uhyve_args)); - host_to_guest_ibv_context(context, GUEST); - host_to_guest_ibv_port_attr(port_attr, GUEST); + /* host_to_guest_ibv_port_attr(port_attr, GUEST); // ! */ + + return uhyve_args.ret; +} + + +/* + * IBV KERNEL LOG + */ + +/* void kernel_ibv_log() { */ + /* char log_message[128]; */ + /* ksprintf(log_message, "%p", kernel_start_host); */ + /* uhyve_send(UHYVE_PORT_KERNEL_IBV_LOG, (unsigned) virt_to_phys((size_t) log_message)); */ +/* } */ + + + +// ---------------------------------------------------------------------------- + + + + + +/* + * ibv_wc_status_str + */ + +typedef struct { + // Parameters: + enum ibv_wc_status status; + // Return value: + char * ret; +} __attribute__((packed)) uhyve_ibv_wc_status_str_t; + +const char * ibv_wc_status_str(enum ibv_wc_status status) { + uhyve_ibv_wc_status_str_t uhyve_args; + uhyve_args.status = status; + + uhyve_args.ret = kmalloc(MAX_CHAR_ARR_LENGTH); // ! + uhyve_send(UHYVE_PORT_IBV_WC_STATUS_STR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_rate_to_mult + */ + +typedef struct { + // Parameters: + enum ibv_rate rate; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rate_to_mult_t; + +int ibv_rate_to_mult(enum ibv_rate rate) { + uhyve_ibv_rate_to_mult_t uhyve_args; + uhyve_args.rate = rate; + + uhyve_send(UHYVE_PORT_IBV_RATE_TO_MULT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * mult_to_ibv_rate + */ + +typedef struct { + // Parameters: + int mult; + // Return value: + enum ibv_rate ret; +} __attribute__((packed)) uhyve_mult_to_ibv_rate_t; + +enum ibv_rate mult_to_ibv_rate(int mult) { + uhyve_mult_to_ibv_rate_t uhyve_args; + uhyve_args.mult = mult; + + uhyve_send(UHYVE_PORT_MULT_TO_IBV_RATE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_rate_to_mbps + */ + +typedef struct { + // Parameters: + enum ibv_rate rate; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rate_to_mbps_t; + +int ibv_rate_to_mbps(enum ibv_rate rate) { + uhyve_ibv_rate_to_mbps_t uhyve_args; + uhyve_args.rate = rate; + + uhyve_send(UHYVE_PORT_IBV_RATE_TO_MBPS, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * mbps_to_ibv_rate + */ + +typedef struct { + // Parameters: + int mbps; + // Return value: + enum ibv_rate ret; +} __attribute__((packed)) uhyve_mbps_to_ibv_rate_t; + +enum ibv_rate mbps_to_ibv_rate(int mbps) { + uhyve_mbps_to_ibv_rate_t uhyve_args; + uhyve_args.mbps = mbps; + + uhyve_send(UHYVE_PORT_MBPS_TO_IBV_RATE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * verbs_get_ctx + */ + +typedef struct { + // Parameters: + struct ibv_context * ctx; + // Return value: + struct verbs_context * ret; +} __attribute__((packed)) uhyve_verbs_get_ctx_t; + +struct verbs_context * verbs_get_ctx(struct ibv_context * ctx) { + uhyve_verbs_get_ctx_t uhyve_args; + uhyve_args.ctx = ctx; + + uhyve_send(UHYVE_PORT_VERBS_GET_CTX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_free_device_list + */ + +typedef struct { + // Parameters: + struct ibv_device ** list; +} __attribute__((packed)) uhyve_ibv_free_device_list_t; + +void ibv_free_device_list(struct ibv_device ** list) { + uhyve_ibv_free_device_list_t uhyve_args; + uhyve_args.list = (struct ibv_device **) guest_to_host((size_t) list); + + kfree(list); + + uhyve_send(UHYVE_PORT_IBV_FREE_DEVICE_LIST, (unsigned) virt_to_phys((size_t) &uhyve_args)); +} + + +/* + * ibv_get_device_guid + */ + +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + __be64 ret; +} __attribute__((packed)) uhyve_ibv_get_device_guid_t; + +__be64 ibv_get_device_guid(struct ibv_device * device) { + uhyve_ibv_get_device_guid_t uhyve_args; + uhyve_args.device = device; + + uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_GUID, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_open_device + */ + +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + struct ibv_context * ret; +} __attribute__((packed)) uhyve_ibv_open_device_t; + +struct ibv_context * ibv_open_device(struct ibv_device * device) { + uhyve_ibv_open_device_t uhyve_args; + uhyve_args.device = device; + + uhyve_send(UHYVE_PORT_IBV_OPEN_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_close_device + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_close_device_t; + +int ibv_close_device(struct ibv_context * context) { + uhyve_ibv_close_device_t uhyve_args; + uhyve_args.context = context; + + uhyve_send(UHYVE_PORT_IBV_CLOSE_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_get_async_event + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_async_event * event; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_async_event_t; + +int ibv_get_async_event(struct ibv_context * context, struct ibv_async_event * event) { + uhyve_ibv_get_async_event_t uhyve_args; + uhyve_args.context = context; + uhyve_args.event = event; + + uhyve_send(UHYVE_PORT_IBV_GET_ASYNC_EVENT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_ack_async_event + */ + +typedef struct { + // Parameters: + struct ibv_async_event * event; +} __attribute__((packed)) uhyve_ibv_ack_async_event_t; + +void ibv_ack_async_event(struct ibv_async_event * event) { + uhyve_ibv_ack_async_event_t uhyve_args; + uhyve_args.event = event; + + uhyve_send(UHYVE_PORT_IBV_ACK_ASYNC_EVENT, (unsigned) virt_to_phys((size_t) &uhyve_args)); +} + + +/* + * ibv_query_device + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_device_attr * device_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_device_t; + +int ibv_query_device(struct ibv_context * context, struct ibv_device_attr * device_attr) { + uhyve_ibv_query_device_t uhyve_args; + uhyve_args.context = context; + uhyve_args.device_attr = device_attr; + + uhyve_send(UHYVE_PORT_IBV_QUERY_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_gid + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + int index; + union ibv_gid * gid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_gid_t; + +int ibv_query_gid(struct ibv_context * context, uint8_t port_num, int index, union ibv_gid * gid) { + uhyve_ibv_query_gid_t uhyve_args; + uhyve_args.context = context; + uhyve_args.port_num = port_num; + uhyve_args.index = index; + uhyve_args.gid = gid; + + uhyve_send(UHYVE_PORT_IBV_QUERY_GID, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_pkey + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + int index; + __be16 * pkey; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_pkey_t; + +int ibv_query_pkey(struct ibv_context * context, uint8_t port_num, int index, __be16 * pkey) { + uhyve_ibv_query_pkey_t uhyve_args; + uhyve_args.context = context; + uhyve_args.port_num = port_num; + uhyve_args.index = index; + uhyve_args.pkey = pkey; + + uhyve_send(UHYVE_PORT_IBV_QUERY_PKEY, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_alloc_pd + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + struct ibv_pd * ret; +} __attribute__((packed)) uhyve_ibv_alloc_pd_t; + +struct ibv_pd * ibv_alloc_pd(struct ibv_context * context) { + uhyve_ibv_alloc_pd_t uhyve_args; + uhyve_args.context = context; + + uhyve_send(UHYVE_PORT_IBV_ALLOC_PD, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_dealloc_pd + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dealloc_pd_t; + +int ibv_dealloc_pd(struct ibv_pd * pd) { + uhyve_ibv_dealloc_pd_t uhyve_args; + uhyve_args.pd = pd; + + uhyve_send(UHYVE_PORT_IBV_DEALLOC_PD, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_flow + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_flow_attr * flow; + // Return value: + struct ibv_flow * ret; +} __attribute__((packed)) uhyve_ibv_create_flow_t; + +struct ibv_flow * ibv_create_flow(struct ibv_qp * qp, struct ibv_flow_attr * flow) { + uhyve_ibv_create_flow_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.flow = flow; + + uhyve_send(UHYVE_PORT_IBV_CREATE_FLOW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_flow + */ + +typedef struct { + // Parameters: + struct ibv_flow * flow_id; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_flow_t; + +int ibv_destroy_flow(struct ibv_flow * flow_id) { + uhyve_ibv_destroy_flow_t uhyve_args; + uhyve_args.flow_id = flow_id; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_FLOW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_open_xrcd + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_xrcd_init_attr * xrcd_init_attr; + // Return value: + struct ibv_xrcd * ret; +} __attribute__((packed)) uhyve_ibv_open_xrcd_t; + +struct ibv_xrcd * ibv_open_xrcd(struct ibv_context * context, struct ibv_xrcd_init_attr * xrcd_init_attr) { + uhyve_ibv_open_xrcd_t uhyve_args; + uhyve_args.context = context; + uhyve_args.xrcd_init_attr = xrcd_init_attr; + + uhyve_send(UHYVE_PORT_IBV_OPEN_XRCD, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_close_xrcd + */ + +typedef struct { + // Parameters: + struct ibv_xrcd * xrcd; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_close_xrcd_t; + +int ibv_close_xrcd(struct ibv_xrcd * xrcd) { + uhyve_ibv_close_xrcd_t uhyve_args; + uhyve_args.xrcd = xrcd; + + uhyve_send(UHYVE_PORT_IBV_CLOSE_XRCD, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_reg_mr + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + void * addr; + int length; + int access; + // Return value: + struct ibv_mr * ret; +} __attribute__((packed)) uhyve_ibv_reg_mr_t; + +struct ibv_mr * ibv_reg_mr(struct ibv_pd * pd, void * addr, int length, int access) { + uhyve_ibv_reg_mr_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.addr = (void *) guest_to_host((size_t) addr); // ! + uhyve_args.length = length; + uhyve_args.access = access; + + uhyve_send(UHYVE_PORT_IBV_REG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_rereg_mr + */ + +typedef struct { + // Parameters: + struct ibv_mr * mr; + int flags; + struct ibv_pd * pd; + void * addr; + int length; + int access; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rereg_mr_t; + +int ibv_rereg_mr(struct ibv_mr * mr, int flags, struct ibv_pd * pd, void * addr, int length, int access) { + uhyve_ibv_rereg_mr_t uhyve_args; + uhyve_args.mr = mr; + uhyve_args.flags = flags; + uhyve_args.pd = pd; + uhyve_args.addr = (void *) guest_to_host((size_t) addr); // ! + uhyve_args.length = length; + uhyve_args.access = access; + + uhyve_send(UHYVE_PORT_IBV_REREG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_dereg_mr + */ + +typedef struct { + // Parameters: + struct ibv_mr * mr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dereg_mr_t; + +int ibv_dereg_mr(struct ibv_mr * mr) { + uhyve_ibv_dereg_mr_t uhyve_args; + uhyve_args.mr = mr; + + uhyve_send(UHYVE_PORT_IBV_DEREG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_alloc_mw + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + enum ibv_mw_type type; + // Return value: + struct ibv_mw * ret; +} __attribute__((packed)) uhyve_ibv_alloc_mw_t; + +struct ibv_mw * ibv_alloc_mw(struct ibv_pd * pd, enum ibv_mw_type type) { + uhyve_ibv_alloc_mw_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.type = type; + + uhyve_send(UHYVE_PORT_IBV_ALLOC_MW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_dealloc_mw + */ + +typedef struct { + // Parameters: + struct ibv_mw * mw; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dealloc_mw_t; + +int ibv_dealloc_mw(struct ibv_mw * mw) { + uhyve_ibv_dealloc_mw_t uhyve_args; + uhyve_args.mw = mw; + + uhyve_send(UHYVE_PORT_IBV_DEALLOC_MW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_inc_rkey + */ + +typedef struct { + // Parameters: + uint32_t rkey; + // Return value: + uint32_t ret; +} __attribute__((packed)) uhyve_ibv_inc_rkey_t; + +uint32_t ibv_inc_rkey(uint32_t rkey) { + uhyve_ibv_inc_rkey_t uhyve_args; + uhyve_args.rkey = rkey; + + uhyve_send(UHYVE_PORT_IBV_INC_RKEY, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_bind_mw + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_mw * mw; + struct ibv_mw_bind * mw_bind; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_bind_mw_t; + +int ibv_bind_mw(struct ibv_qp * qp, struct ibv_mw * mw, struct ibv_mw_bind * mw_bind) { + uhyve_ibv_bind_mw_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.mw = mw; + uhyve_args.mw_bind = mw_bind; + + uhyve_send(UHYVE_PORT_IBV_BIND_MW, (unsigned) virt_to_phys((size_t) &uhyve_args)); return uhyve_args.ret; } @@ -180,28 +772,847 @@ typedef struct { } __attribute__((packed)) uhyve_ibv_create_comp_channel_t; struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context) { - struct ibv_comp_channel * ret_guest; uhyve_ibv_create_comp_channel_t uhyve_args; - uhyve_args.context = guest_to_host_ibv_context(context); - - /* ret_guest = kmalloc(sizeof(struct ibv_comp_channel)); */ - /* uhyve_args.ret = (struct ibv_comp_channel *) guest_to_host((size_t) ret_guest); */ + uhyve_args.context = context; uhyve_send(UHYVE_PORT_IBV_CREATE_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args)); - host_to_guest_ibv_context(context, GUEST); - ret_guest = host_to_guest_ibv_comp_channel(uhyve_args.ret, HOST); - - return ret_guest; + return uhyve_args.ret; } /* - * IBV KERNEL LOG + * ibv_destroy_comp_channel */ -void kernel_ibv_log() { - char log_message[128]; - ksprintf(log_message, "%p", kernel_start_host); - uhyve_send(UHYVE_PORT_KERNEL_IBV_LOG, (unsigned) virt_to_phys((size_t) log_message)); +typedef struct { + // Parameters: + struct ibv_comp_channel * channel; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_comp_channel_t; + +int ibv_destroy_comp_channel(struct ibv_comp_channel * channel) { + uhyve_ibv_destroy_comp_channel_t uhyve_args; + uhyve_args.channel = channel; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; } + + +/* + * ibv_create_cq + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + int cqe; + void * cq_context; + struct ibv_comp_channel * channel; + int comp_vector; + // Return value: + struct ibv_cq * ret; +} __attribute__((packed)) uhyve_ibv_create_cq_t; + +struct ibv_cq * ibv_create_cq(struct ibv_context * context, int cqe, void * cq_context, struct ibv_comp_channel * channel, int comp_vector) { + uhyve_ibv_create_cq_t uhyve_args; + uhyve_args.context = context; + uhyve_args.cqe = cqe; + uhyve_args.cq_context = cq_context; + uhyve_args.channel = channel; + uhyve_args.comp_vector = comp_vector; + + uhyve_send(UHYVE_PORT_IBV_CREATE_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_resize_cq + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int cqe; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_resize_cq_t; + +int ibv_resize_cq(struct ibv_cq * cq, int cqe) { + uhyve_ibv_resize_cq_t uhyve_args; + uhyve_args.cq = cq; + uhyve_args.cqe = cqe; + + uhyve_send(UHYVE_PORT_IBV_RESIZE_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_cq + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_cq_t; + +int ibv_destroy_cq(struct ibv_cq * cq) { + uhyve_ibv_destroy_cq_t uhyve_args; + uhyve_args.cq = cq; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_get_cq_event + */ + +typedef struct { + // Parameters: + struct ibv_comp_channel * channel; + struct ibv_cq ** cq; + void ** cq_context; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_cq_event_t; + +int ibv_get_cq_event(struct ibv_comp_channel * channel, struct ibv_cq ** cq, void ** cq_context) { + uhyve_ibv_get_cq_event_t uhyve_args; + uhyve_args.channel = channel; + uhyve_args.cq = (struct ibv_cq **) guest_to_host((size_t) cq); // ! + uhyve_args.cq_context = (void **) guest_to_host((size_t) cq_context); // ! + + uhyve_send(UHYVE_PORT_IBV_GET_CQ_EVENT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_ack_cq_events + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + unsigned int nevents; +} __attribute__((packed)) uhyve_ibv_ack_cq_events_t; + +void ibv_ack_cq_events(struct ibv_cq * cq, unsigned int nevents) { + uhyve_ibv_ack_cq_events_t uhyve_args; + uhyve_args.cq = cq; + uhyve_args.nevents = nevents; + + uhyve_send(UHYVE_PORT_IBV_ACK_CQ_EVENTS, (unsigned) virt_to_phys((size_t) &uhyve_args)); +} + + +/* + * ibv_poll_cq + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int num_entries; + struct ibv_wc * wc; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_poll_cq_t; + +int ibv_poll_cq(struct ibv_cq * cq, int num_entries, struct ibv_wc * wc) { + uhyve_ibv_poll_cq_t uhyve_args; + uhyve_args.cq = cq; + uhyve_args.num_entries = num_entries; + uhyve_args.wc = wc; + + uhyve_send(UHYVE_PORT_IBV_POLL_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_req_notify_cq + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int solicited_only; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_req_notify_cq_t; + +int ibv_req_notify_cq(struct ibv_cq * cq, int solicited_only) { + uhyve_ibv_req_notify_cq_t uhyve_args; + uhyve_args.cq = cq; + uhyve_args.solicited_only = solicited_only; + + uhyve_send(UHYVE_PORT_IBV_REQ_NOTIFY_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_srq + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_srq_init_attr * srq_init_attr; + // Return value: + struct ibv_srq * ret; +} __attribute__((packed)) uhyve_ibv_create_srq_t; + +struct ibv_srq * ibv_create_srq(struct ibv_pd * pd, struct ibv_srq_init_attr * srq_init_attr) { + uhyve_ibv_create_srq_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.srq_init_attr = srq_init_attr; + + uhyve_send(UHYVE_PORT_IBV_CREATE_SRQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_srq_ex + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_srq_init_attr_ex * srq_init_attr_ex; + // Return value: + struct ibv_srq * ret; +} __attribute__((packed)) uhyve_ibv_create_srq_ex_t; + +struct ibv_srq * ibv_create_srq_ex(struct ibv_context * context, struct ibv_srq_init_attr_ex * srq_init_attr_ex) { + uhyve_ibv_create_srq_ex_t uhyve_args; + uhyve_args.context = context; + uhyve_args.srq_init_attr_ex = srq_init_attr_ex; + + uhyve_send(UHYVE_PORT_IBV_CREATE_SRQ_EX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_modify_srq + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_srq_attr * srq_attr; + int srq_attr_mask; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_srq_t; + +int ibv_modify_srq(struct ibv_srq * srq, struct ibv_srq_attr * srq_attr, int srq_attr_mask) { + uhyve_ibv_modify_srq_t uhyve_args; + uhyve_args.srq = srq; + uhyve_args.srq_attr = srq_attr; + uhyve_args.srq_attr_mask = srq_attr_mask; + + uhyve_send(UHYVE_PORT_IBV_MODIFY_SRQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_srq + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_srq_attr * srq_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_srq_t; + +int ibv_query_srq(struct ibv_srq * srq, struct ibv_srq_attr * srq_attr) { + uhyve_ibv_query_srq_t uhyve_args; + uhyve_args.srq = srq; + uhyve_args.srq_attr = srq_attr; + + uhyve_send(UHYVE_PORT_IBV_QUERY_SRQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_get_srq_num + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + uint32_t * srq_num; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_srq_num_t; + +int ibv_get_srq_num(struct ibv_srq * srq, uint32_t * srq_num) { + uhyve_ibv_get_srq_num_t uhyve_args; + uhyve_args.srq = srq; + uhyve_args.srq_num = srq_num; + + uhyve_send(UHYVE_PORT_IBV_GET_SRQ_NUM, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_srq + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_srq_t; + +int ibv_destroy_srq(struct ibv_srq * srq) { + uhyve_ibv_destroy_srq_t uhyve_args; + uhyve_args.srq = srq; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_SRQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_post_srq_recv + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_recv_wr * recv_wr; + struct ibv_recv_wr ** bad_recv_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_srq_recv_t; + +int ibv_post_srq_recv(struct ibv_srq * srq, struct ibv_recv_wr * recv_wr, struct ibv_recv_wr ** bad_recv_wr) { + uhyve_ibv_post_srq_recv_t uhyve_args; + uhyve_args.srq = srq; + uhyve_args.recv_wr = recv_wr; + // TODO: Take care of ** parameter. + + uhyve_send(UHYVE_PORT_IBV_POST_SRQ_RECV, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_qp + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_qp_init_attr * qp_init_attr; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_create_qp_t; + +struct ibv_qp * ibv_create_qp(struct ibv_pd * pd, struct ibv_qp_init_attr * qp_init_attr) { + uhyve_ibv_create_qp_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.qp_init_attr = (struct ibv_qp_init_attr *) guest_to_host((size_t) qp_init_attr); // ! + + uhyve_send(UHYVE_PORT_IBV_CREATE_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_qp_ex + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_qp_init_attr_ex * qp_init_attr_ex; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_create_qp_ex_t; + +struct ibv_qp * ibv_create_qp_ex(struct ibv_context * context, struct ibv_qp_init_attr_ex * qp_init_attr_ex) { + uhyve_ibv_create_qp_ex_t uhyve_args; + uhyve_args.context = context; + uhyve_args.qp_init_attr_ex = qp_init_attr_ex; + + uhyve_send(UHYVE_PORT_IBV_CREATE_QP_EX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_device_ex + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + const struct ibv_query_device_ex_input * input; + struct ibv_device_attr_ex * attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_device_ex_t; + +int ibv_query_device_ex(struct ibv_context * context, const struct ibv_query_device_ex_input * input, struct ibv_device_attr_ex * attr) { + uhyve_ibv_query_device_ex_t uhyve_args; + uhyve_args.context = context; + uhyve_args.input = input; + uhyve_args.attr = attr; + + uhyve_send(UHYVE_PORT_IBV_QUERY_DEVICE_EX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_open_qp + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_qp_open_attr * qp_open_attr; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_open_qp_t; + +struct ibv_qp * ibv_open_qp(struct ibv_context * context, struct ibv_qp_open_attr * qp_open_attr) { + uhyve_ibv_open_qp_t uhyve_args; + uhyve_args.context = context; + uhyve_args.qp_open_attr = qp_open_attr; + + uhyve_send(UHYVE_PORT_IBV_OPEN_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_modify_qp + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_qp_attr * attr; + int attr_mask; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_qp_t; + +int ibv_modify_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask) { + uhyve_ibv_modify_qp_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.attr = (struct ibv_qp_attr *) guest_to_host((size_t) attr); // ! + uhyve_args.attr_mask = attr_mask; + + uhyve_send(UHYVE_PORT_IBV_MODIFY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_qp + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_qp_attr * attr; + int attr_mask; + struct ibv_qp_init_attr * init_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_qp_t; + +int ibv_query_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask, struct ibv_qp_init_attr * init_attr) { + uhyve_ibv_query_qp_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.attr = (struct ibv_qp_attr *) guest_to_host((size_t) attr); // ! + uhyve_args.attr_mask = attr_mask; + uhyve_args.init_attr = (struct ibv_qp_init_attr *) guest_to_host((size_t) init_attr); // ! + + uhyve_send(UHYVE_PORT_IBV_QUERY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_qp + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_qp_t; + +int ibv_destroy_qp(struct ibv_qp * qp) { + uhyve_ibv_destroy_qp_t uhyve_args; + uhyve_args.qp = qp; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_post_send + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_send_wr * wr; + struct ibv_send_wr ** bad_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_send_t; + +int ibv_post_send(struct ibv_qp * qp, struct ibv_send_wr * wr, struct ibv_send_wr ** bad_wr) { + uhyve_ibv_post_send_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.wr = wr; + // TODO: Take care of ** parameter. + + uhyve_send(UHYVE_PORT_IBV_POST_SEND, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_post_recv + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_recv_wr * wr; + struct ibv_recv_wr ** bad_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_recv_t; + +int ibv_post_recv(struct ibv_qp * qp, struct ibv_recv_wr * wr, struct ibv_recv_wr ** bad_wr) { + LOG_INFO("KERNEL: ibv_post_recv()\n"); + + uhyve_ibv_post_recv_t uhyve_args; + LOG_INFO("KERNEL: ibv_post_recv()\n"); + uhyve_args.qp = qp; + LOG_INFO("KERNEL: ibv_post_recv()\n"); + uhyve_args.wr = guest_to_host_ibv_recv_wr(wr); + LOG_INFO("KERNEL: ibv_post_recv()\n"); + uhyve_args.bad_wr = (struct ibv_recv_wr **) guest_to_host((size_t) bad_wr); + + LOG_INFO("KERNEL: ibv_post_recv()\n"); + uhyve_send(UHYVE_PORT_IBV_POST_RECV, (unsigned) virt_to_phys((size_t) &uhyve_args)); + LOG_INFO("KERNEL: ibv_post_recv()\n"); + + /* host_to_guest_ibv_recv_wr(wr, GUEST); */ // TODO: add this back in + /* LOG_INFO("KERNEL: ibv_post_recv()\n"); */ + + // TODO: Do we want to convert bad_wr's content back to guest memory? + + return uhyve_args.ret; +} + + +/* + * ibv_create_ah + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_ah_attr * attr; + // Return value: + struct ibv_ah * ret; +} __attribute__((packed)) uhyve_ibv_create_ah_t; + +struct ibv_ah * ibv_create_ah(struct ibv_pd * pd, struct ibv_ah_attr * attr) { + uhyve_ibv_create_ah_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.attr = attr; + + uhyve_send(UHYVE_PORT_IBV_CREATE_AH, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_init_ah_from_wc + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_wc * wc; + struct ibv_grh * grh; + struct ibv_ah_attr * ah_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_init_ah_from_wc_t; + +int ibv_init_ah_from_wc(struct ibv_context * context, uint8_t port_num, struct ibv_wc * wc, struct ibv_grh * grh, struct ibv_ah_attr * ah_attr) { + uhyve_ibv_init_ah_from_wc_t uhyve_args; + uhyve_args.context = context; + uhyve_args.port_num = port_num; + uhyve_args.wc = wc; + uhyve_args.grh = grh; + uhyve_args.ah_attr = ah_attr; + + uhyve_send(UHYVE_PORT_IBV_INIT_AH_FROM_WC, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_ah_from_wc + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_wc * wc; + struct ibv_grh * grh; + uint8_t port_num; + // Return value: + struct ibv_ah * ret; +} __attribute__((packed)) uhyve_ibv_create_ah_from_wc_t; + +struct ibv_ah * ibv_create_ah_from_wc(struct ibv_pd * pd, struct ibv_wc * wc, struct ibv_grh * grh, uint8_t port_num) { + uhyve_ibv_create_ah_from_wc_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.wc = wc; + uhyve_args.grh = grh; + uhyve_args.port_num = port_num; + + uhyve_send(UHYVE_PORT_IBV_CREATE_AH_FROM_WC, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_ah + */ + +typedef struct { + // Parameters: + struct ibv_ah * ah; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_ah_t; + +int ibv_destroy_ah(struct ibv_ah * ah) { + uhyve_ibv_destroy_ah_t uhyve_args; + uhyve_args.ah = ah; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_AH, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_attach_mcast + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + const union ibv_gid * gid; + uint16_t lid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_attach_mcast_t; + +int ibv_attach_mcast(struct ibv_qp * qp, const union ibv_gid * gid, uint16_t lid) { + uhyve_ibv_attach_mcast_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.gid = gid; + uhyve_args.lid = lid; + + uhyve_send(UHYVE_PORT_IBV_ATTACH_MCAST, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_detach_mcast + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + const union ibv_gid * gid; + uint16_t lid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_detach_mcast_t; + +int ibv_detach_mcast(struct ibv_qp * qp, const union ibv_gid * gid, uint16_t lid) { + uhyve_ibv_detach_mcast_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.gid = gid; + uhyve_args.lid = lid; + + uhyve_send(UHYVE_PORT_IBV_DETACH_MCAST, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_fork_init + */ + +typedef struct { + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_fork_init_t; + +int ibv_fork_init( ) { + uhyve_ibv_fork_init_t uhyve_args; + + uhyve_send(UHYVE_PORT_IBV_FORK_INIT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_node_type_str + */ + +typedef struct { + // Parameters: + enum ibv_node_type node_type; + // Return value: + char * ret; +} __attribute__((packed)) uhyve_ibv_node_type_str_t; + +const char * ibv_node_type_str(enum ibv_node_type node_type) { + uhyve_ibv_node_type_str_t uhyve_args; + uhyve_args.node_type = node_type; + + uhyve_args.ret = kmalloc(MAX_CHAR_ARR_LENGTH); // ! + uhyve_send(UHYVE_PORT_IBV_NODE_TYPE_STR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_port_state_str + */ + +typedef struct { + // Parameters: + enum ibv_port_state port_state; + // Return value: + char * ret; +} __attribute__((packed)) uhyve_ibv_port_state_str_t; + +const char * ibv_port_state_str(enum ibv_port_state port_state) { + uhyve_ibv_port_state_str_t uhyve_args; + uhyve_args.port_state = port_state; + + uhyve_args.ret = kmalloc(MAX_CHAR_ARR_LENGTH); // ! + uhyve_send(UHYVE_PORT_IBV_PORT_STATE_STR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_event_type_str + */ + +typedef struct { + // Parameters: + enum ibv_event_type event; + // Return value: + char * ret; +} __attribute__((packed)) uhyve_ibv_event_type_str_t; + +const char * ibv_event_type_str(enum ibv_event_type event) { + uhyve_ibv_event_type_str_t uhyve_args; + uhyve_args.event = event; + + uhyve_args.ret = kmalloc(MAX_CHAR_ARR_LENGTH); // ! + uhyve_send(UHYVE_PORT_IBV_EVENT_TYPE_STR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_is_qpt_supported + */ + +typedef struct { + // Parameters: + uint32_t caps; + enum ibv_qp_type qpt; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_is_qpt_supported_t; + +int ibv_is_qpt_supported(uint32_t caps, enum ibv_qp_type qpt) { + uhyve_ibv_is_qpt_supported_t uhyve_args; + uhyve_args.caps = caps; + uhyve_args.qpt = qpt; + + uhyve_send(UHYVE_PORT_IBV_IS_QPT_SUPPORTED, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + diff --git a/kernel/ibv_guest_host.c b/kernel/ibv_guest_host.c index 4b606e356..4a1f61f5c 100644 --- a/kernel/ibv_guest_host.c +++ b/kernel/ibv_guest_host.c @@ -32,6 +32,7 @@ #include #include +#include /* @@ -95,6 +96,73 @@ struct ibv_port_attr * host_to_guest_ibv_port_attr(struct ibv_port_attr * port_a } +/* + * struct ibv_sge + */ + +struct ibv_sge * guest_to_host_ibv_sge(struct ibv_sge * sg) { + LOG_INFO("Entered guest_to_host_ibv_recv_wr()\n"); + LOG_INFO("\tsg->addr before conversion: %lu\n", sg->addr); + sg->addr = (uint64_t) guest_to_host((size_t) sg->addr); + LOG_INFO("\tsg->addr after conversion: %lu\n", sg->addr); + + return (struct ibv_sge *) guest_to_host((size_t) sg); +} + +struct ibv_sge * host_to_guest_ibv_sge(struct ibv_sge * sg, addr_type type) { + LOG_INFO("Entered host_to_guest_ibv_recv_wr()\n"); + struct ibv_sge * vaddr = (type == GUEST) ? sg + : (struct ibv_sge *) host_to_guest((size_t) sg); + + vaddr->addr = (uint64_t) host_to_guest((size_t) vaddr->addr); + + return vaddr; +} + + +// struct ibv_recv_wr { +// uint64_t wr_id; +// struct ibv_recv_wr *next; +// struct ibv_sge *sg_list; +// int num_sge; +// }; + +// struct ibv_sge { // scatter/gather element +// uint64_t addr; // might have to be converted +// uint32_t length; +// uint32_t lkey; +// }; + +/* + * struct ibv_recv_wr + */ + +struct ibv_recv_wr * guest_to_host_ibv_recv_wr(struct ibv_recv_wr * wr) { + LOG_INFO("Entered guest_to_host_ibv_recv_wr()\n"); + if (wr->next) { + LOG_INFO("\twr->next is not NULL\n"); + wr->next = guest_to_host_ibv_recv_wr(wr->next); // linked list + } + wr->sg_list = guest_to_host_ibv_sge(wr->sg_list); + + return (struct ibv_recv_wr *) guest_to_host((size_t) wr); +} + +struct ibv_recv_wr * host_to_guest_ibv_recv_wr(struct ibv_recv_wr * wr, addr_type type) { + LOG_INFO("Entered host_to_guest_ibv_recv_wr()\n"); + struct ibv_recv_wr * vaddr = (type == GUEST) ? wr + : (struct ibv_recv_wr *) host_to_guest((size_t) wr); + + if (wr->next) { + LOG_INFO("\twr->next is not NULL\n"); + vaddr->next = host_to_guest_ibv_recv_wr(vaddr->next, HOST); // linked list + } + vaddr->sg_list = host_to_guest_ibv_sge(vaddr->sg_list, HOST); + + return vaddr; +} + + /* * struct ibv_comp_channel */ diff --git a/kernel/main.c b/kernel/main.c index 36ee162b6..ece3fcbff 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -122,7 +122,6 @@ static int hermit_init(void) timer_init(); multitasking_init(); memory_init(); - ib_memory_init(); signal_init(); return 0; diff --git a/tools/ibv_code_generator/GEN-include-hermit-stddef.h b/tools/ibv_code_generator/GEN-include-hermit-stddef.h index 3e1b9533c..91d60757a 100644 --- a/tools/ibv_code_generator/GEN-include-hermit-stddef.h +++ b/tools/ibv_code_generator/GEN-include-hermit-stddef.h @@ -1,5 +1,77 @@ - -#define UHYVE_PORT_IBV_OPEN_DEVICE 0x510 -#define UHYVE_PORT_IBV_GET_DEVICE_NAME 0x511 -#define UHYVE_PORT_IBV_QUERY_PORT 0x512 -#define UHYVE_PORT_IBV_CREATE_COMP_CHANNEL 0x513 \ No newline at end of file +#define UHYVE_PORT_IBV_WC_STATUS_STR 0x510 +#define UHYVE_PORT_IBV_RATE_TO_MULT 0x511 +#define UHYVE_PORT_MULT_TO_IBV_RATE 0x512 +#define UHYVE_PORT_IBV_RATE_TO_MBPS 0x513 +#define UHYVE_PORT_MBPS_TO_IBV_RATE 0x514 +#define UHYVE_PORT_IBV_POST_WQ_RECV 0x515 +#define UHYVE_PORT_VERBS_GET_CTX 0x516 +#define UHYVE_PORT_IBV_GET_DEVICE_LIST 0x517 +#define UHYVE_PORT_IBV_FREE_DEVICE_LIST 0x518 +#define UHYVE_PORT_IBV_GET_DEVICE_NAME 0x519 +#define UHYVE_PORT_IBV_GET_DEVICE_GUID 0x51A +#define UHYVE_PORT_IBV_OPEN_DEVICE 0x51B +#define UHYVE_PORT_IBV_CLOSE_DEVICE 0x51C +#define UHYVE_PORT_IBV_GET_ASYNC_EVENT 0x51D +#define UHYVE_PORT_IBV_ACK_ASYNC_EVENT 0x51E +#define UHYVE_PORT_IBV_QUERY_DEVICE 0x51F +#define UHYVE_PORT_IBV_QUERY_PORT 0x520 +#define UHYVE_PORT____IBV_QUERY_PORT 0x521 +#define UHYVE_PORT_IBV_QUERY_GID 0x522 +#define UHYVE_PORT_IBV_QUERY_PKEY 0x523 +#define UHYVE_PORT_IBV_ALLOC_PD 0x524 +#define UHYVE_PORT_IBV_DEALLOC_PD 0x525 +#define UHYVE_PORT_IBV_CREATE_FLOW 0x526 +#define UHYVE_PORT_IBV_DESTROY_FLOW 0x527 +#define UHYVE_PORT_IBV_OPEN_XRCD 0x528 +#define UHYVE_PORT_IBV_CLOSE_XRCD 0x529 +#define UHYVE_PORT_IBV_REG_MR 0x52A +#define UHYVE_PORT_IBV_REREG_MR 0x52B +#define UHYVE_PORT_IBV_DEREG_MR 0x52C +#define UHYVE_PORT_IBV_ALLOC_MW 0x52D +#define UHYVE_PORT_IBV_DEALLOC_MW 0x52E +#define UHYVE_PORT_IBV_INC_RKEY 0x52F +#define UHYVE_PORT_IBV_BIND_MW 0x530 +#define UHYVE_PORT_IBV_CREATE_COMP_CHANNEL 0x531 +#define UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL 0x532 +#define UHYVE_PORT_IBV_CREATE_CQ 0x533 +#define UHYVE_PORT_IBV_CREATE_CQ_EX 0x534 +#define UHYVE_PORT_IBV_RESIZE_CQ 0x535 +#define UHYVE_PORT_IBV_DESTROY_CQ 0x536 +#define UHYVE_PORT_IBV_GET_CQ_EVENT 0x537 +#define UHYVE_PORT_IBV_ACK_CQ_EVENTS 0x538 +#define UHYVE_PORT_IBV_POLL_CQ 0x539 +#define UHYVE_PORT_IBV_REQ_NOTIFY_CQ 0x53A +#define UHYVE_PORT_IBV_CREATE_SRQ 0x53B +#define UHYVE_PORT_IBV_CREATE_SRQ_EX 0x53C +#define UHYVE_PORT_IBV_MODIFY_SRQ 0x53D +#define UHYVE_PORT_IBV_QUERY_SRQ 0x53E +#define UHYVE_PORT_IBV_GET_SRQ_NUM 0x53F +#define UHYVE_PORT_IBV_DESTROY_SRQ 0x540 +#define UHYVE_PORT_IBV_POST_SRQ_RECV 0x541 +#define UHYVE_PORT_IBV_CREATE_QP 0x542 +#define UHYVE_PORT_IBV_CREATE_QP_EX 0x543 +#define UHYVE_PORT_IBV_QUERY_RT_VALUES_EX 0x544 +#define UHYVE_PORT_IBV_QUERY_DEVICE_EX 0x545 +#define UHYVE_PORT_IBV_OPEN_QP 0x546 +#define UHYVE_PORT_IBV_MODIFY_QP 0x547 +#define UHYVE_PORT_IBV_QUERY_QP 0x548 +#define UHYVE_PORT_IBV_DESTROY_QP 0x549 +#define UHYVE_PORT_IBV_CREATE_WQ 0x54A +#define UHYVE_PORT_IBV_MODIFY_WQ 0x54B +#define UHYVE_PORT_IBV_DESTROY_WQ 0x54C +#define UHYVE_PORT_IBV_CREATE_RWQ_IND_TABLE 0x54D +#define UHYVE_PORT_IBV_DESTROY_RWQ_IND_TABLE 0x54E +#define UHYVE_PORT_IBV_POST_SEND 0x54F +#define UHYVE_PORT_IBV_POST_RECV 0x550 +#define UHYVE_PORT_IBV_CREATE_AH 0x551 +#define UHYVE_PORT_IBV_INIT_AH_FROM_WC 0x552 +#define UHYVE_PORT_IBV_CREATE_AH_FROM_WC 0x553 +#define UHYVE_PORT_IBV_DESTROY_AH 0x554 +#define UHYVE_PORT_IBV_ATTACH_MCAST 0x555 +#define UHYVE_PORT_IBV_DETACH_MCAST 0x556 +#define UHYVE_PORT_IBV_FORK_INIT 0x557 +#define UHYVE_PORT_IBV_NODE_TYPE_STR 0x558 +#define UHYVE_PORT_IBV_PORT_STATE_STR 0x559 +#define UHYVE_PORT_IBV_EVENT_TYPE_STR 0x55A +#define UHYVE_PORT_IBV_RESOLVE_ETH_L2_FROM_GID 0x55B +#define UHYVE_PORT_IBV_IS_QPT_SUPPORTED 0x55C diff --git a/tools/ibv_code_generator/GEN-kernel-header.h b/tools/ibv_code_generator/GEN-kernel-header.h new file mode 100644 index 000000000..7fc03e5ff --- /dev/null +++ b/tools/ibv_code_generator/GEN-kernel-header.h @@ -0,0 +1,77 @@ +const char * ibv_wc_status_str(enum ibv_wc_status status); +int ibv_rate_to_mult(enum ibv_rate rate); +enum ibv_rate mult_to_ibv_rate(int mult); +int ibv_rate_to_mbps(enum ibv_rate rate); +enum ibv_rate mbps_to_ibv_rate(int mbps); +int ibv_post_wq_recv(struct ibv_wq * wq, struct ibv_recv_wr * recv_wr, struct ibv_recv_wr ** bad_recv_wr); +struct verbs_context * verbs_get_ctx(struct ibv_context * ctx); +struct ibv_device ** ibv_get_device_list(int * num_devices); +void ibv_free_device_list(struct ibv_device ** list); +const char * ibv_get_device_name(struct ibv_device * device); +__be64 ibv_get_device_guid(struct ibv_device * device); +struct ibv_context * ibv_open_device(struct ibv_device * device); +int ibv_close_device(struct ibv_context * context); +int ibv_get_async_event(struct ibv_context * context, struct ibv_async_event * event); +void ibv_ack_async_event(struct ibv_async_event * event); +int ibv_query_device(struct ibv_context * context, struct ibv_device_attr * device_attr); +int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr); +int ___ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr); +int ibv_query_gid(struct ibv_context * context, uint8_t port_num, int index, union ibv_gid * gid); +int ibv_query_pkey(struct ibv_context * context, uint8_t port_num, int index, __be16 * pkey); +struct ibv_pd * ibv_alloc_pd(struct ibv_context * context); +int ibv_dealloc_pd(struct ibv_pd * pd); +struct ibv_flow * ibv_create_flow(struct ibv_qp * qp, struct ibv_flow_attr * flow); +int ibv_destroy_flow(struct ibv_flow * flow_id); +struct ibv_xrcd * ibv_open_xrcd(struct ibv_context * context, struct ibv_xrcd_init_attr * xrcd_init_attr); +int ibv_close_xrcd(struct ibv_xrcd * xrcd); +struct ibv_mr * ibv_reg_mr(struct ibv_pd * pd, void * addr, int length, int access); +int ibv_rereg_mr(struct ibv_mr * mr, int flags, struct ibv_pd * pd, void * addr, int length, int access); +int ibv_dereg_mr(struct ibv_mr * mr); +struct ibv_mw * ibv_alloc_mw(struct ibv_pd * pd, enum ibv_mw_type type); +int ibv_dealloc_mw(struct ibv_mw * mw); +uint32_t ibv_inc_rkey(uint32_t rkey); +int ibv_bind_mw(struct ibv_qp * qp, struct ibv_mw * mw, struct ibv_mw_bind * mw_bind); +struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context); +int ibv_destroy_comp_channel(struct ibv_comp_channel * channel); +struct ibv_cq * ibv_create_cq(struct ibv_context * context, int cqe, void * cq_context, struct ibv_comp_channel * channel, int comp_vector); +struct ibv_cq_ex * ibv_create_cq_ex(struct ibv_context * context, struct ibv_cq_init_attr_ex * cq_attr); +int ibv_resize_cq(struct ibv_cq * cq, int cqe); +int ibv_destroy_cq(struct ibv_cq * cq); +int ibv_get_cq_event(struct ibv_comp_channel * channel, struct ibv_cq ** cq, void ** cq_context); +void ibv_ack_cq_events(struct ibv_cq * cq, unsigned int nevents); +int ibv_poll_cq(struct ibv_cq * cq, int num_entries, struct ibv_wc * wc); +int ibv_req_notify_cq(struct ibv_cq * cq, int solicited_only); +struct ibv_srq * ibv_create_srq(struct ibv_pd * pd, struct ibv_srq_init_attr * srq_init_attr); +struct ibv_srq * ibv_create_srq_ex(struct ibv_context * context, struct ibv_srq_init_attr_ex * srq_init_attr_ex); +int ibv_modify_srq(struct ibv_srq * srq, struct ibv_srq_attr * srq_attr, int srq_attr_mask); +int ibv_query_srq(struct ibv_srq * srq, struct ibv_srq_attr * srq_attr); +int ibv_get_srq_num(struct ibv_srq * srq, uint32_t * srq_num); +int ibv_destroy_srq(struct ibv_srq * srq); +int ibv_post_srq_recv(struct ibv_srq * srq, struct ibv_recv_wr * recv_wr, struct ibv_recv_wr ** bad_recv_wr); +struct ibv_qp * ibv_create_qp(struct ibv_pd * pd, struct ibv_qp_init_attr * qp_init_attr); +struct ibv_qp * ibv_create_qp_ex(struct ibv_context * context, struct ibv_qp_init_attr_ex * qp_init_attr_ex); +int ibv_query_rt_values_ex(struct ibv_context * context, struct ibv_values_ex * values); +int ibv_query_device_ex(struct ibv_context * context, const struct ibv_query_device_ex_input * input, struct ibv_device_attr_ex * attr); +struct ibv_qp * ibv_open_qp(struct ibv_context * context, struct ibv_qp_open_attr * qp_open_attr); +int ibv_modify_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask); +int ibv_query_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask, struct ibv_qp_init_attr * init_attr); +int ibv_destroy_qp(struct ibv_qp * qp); +struct ibv_wq * ibv_create_wq(struct ibv_context * context, struct ibv_wq_init_attr * wq_init_attr); +int ibv_modify_wq(struct ibv_wq * wq, struct ibv_wq_attr * wq_attr); +int ibv_destroy_wq(struct ibv_wq * wq); +struct ibv_rwq_ind_table * ibv_create_rwq_ind_table(struct ibv_context * context, struct ibv_rwq_ind_table_init_attr * init_attr); +int ibv_destroy_rwq_ind_table(struct ibv_rwq_ind_table * rwq_ind_table); +int ibv_post_send(struct ibv_qp * qp, struct ibv_send_wr * wr, struct ibv_send_wr ** bad_wr); +int ibv_post_recv(struct ibv_qp * qp, struct ibv_recv_wr * wr, struct ibv_recv_wr ** bad_wr); +struct ibv_ah * ibv_create_ah(struct ibv_pd * pd, struct ibv_ah_attr * attr); +int ibv_init_ah_from_wc(struct ibv_context * context, uint8_t port_num, struct ibv_wc * wc, struct ibv_grh * grh, struct ibv_ah_attr * ah_attr); +struct ibv_ah * ibv_create_ah_from_wc(struct ibv_pd * pd, struct ibv_wc * wc, struct ibv_grh * grh, uint8_t port_num); +int ibv_destroy_ah(struct ibv_ah * ah); +int ibv_attach_mcast(struct ibv_qp * qp, const union ibv_gid * gid, uint16_t lid); +int ibv_detach_mcast(struct ibv_qp * qp, const union ibv_gid * gid, uint16_t lid); +int ibv_fork_init( ); +const char * ibv_node_type_str(enum ibv_node_type node_type); +const char * ibv_port_state_str(enum ibv_port_state port_state); +const char * ibv_event_type_str(enum ibv_event_type event); +int ibv_resolve_eth_l2_from_gid(struct ibv_context * context, struct ibv_ah_attr * attr, uint8_t eth_mac[6], uint16_t * vid); +int ibv_is_qpt_supported(uint32_t caps, enum ibv_qp_type qpt); diff --git a/tools/ibv_code_generator/GEN-kernel-ibv.c b/tools/ibv_code_generator/GEN-kernel-ibv.c deleted file mode 100644 index 699e9e659..000000000 --- a/tools/ibv_code_generator/GEN-kernel-ibv.c +++ /dev/null @@ -1,82 +0,0 @@ -typedef struct { - // Parameters: - struct ibv_device * device; - // Return value: - struct ibv_context * ret; -} __attribute__((packed)) uhyve_ibv_open_device_t; - -struct ibv_context * ibv_open_device(struct ibv_device * device) { - uhyve_ibv_open_device_t uhyve_args; - uhyve_args->device = (struct ibv_device *) virt_to_phys((size_t) device); - - uhyve_args->ret = kmalloc(sizeof(struct ibv_context)); - - uhyve_send(UHYVE_PORT_IBV_OPEN_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args)); - - // TODO: Fix pointers in returned data structures. - return uhyve_args.ret; -} - - -typedef struct { - // Parameters: - struct ibv_device * device; - // Return value: - const char * ret; -} __attribute__((packed)) uhyve_ibv_get_device_name_t; - -const char * ibv_get_device_name(struct ibv_device * device) { - uhyve_ibv_get_device_name_t uhyve_args; - uhyve_args->device = (struct ibv_device *) virt_to_phys((size_t) device); - - uhyve_args->ret = kmalloc(sizeof(const char)); - - uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_NAME, (unsigned) virt_to_phys((size_t) &uhyve_args)); - - // TODO: Fix pointers in returned data structures. - return uhyve_args.ret; -} - - -typedef struct { - // Parameters: - struct ibv_context * context; - uint8_t port_num; - struct ibv_port_attr * port_attr; - // Return value: - int ret; -} __attribute__((packed)) uhyve_ibv_query_port_t; - -int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr) { - uhyve_ibv_query_port_t uhyve_args; - uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context); - uhyve_args->port_num = port_num; - uhyve_args->port_attr = (struct ibv_port_attr *) virt_to_phys((size_t) port_attr); - - uhyve_send(UHYVE_PORT_IBV_QUERY_PORT, (unsigned) virt_to_phys((size_t) &uhyve_args)); - - // TODO: Fix pointers in returned data structures. - return uhyve_args.ret; -} - - -typedef struct { - // Parameters: - struct ibv_context * context; - // Return value: - struct ibv_comp_channel * ret; -} __attribute__((packed)) uhyve_ibv_create_comp_channel_t; - -struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context) { - uhyve_ibv_create_comp_channel_t uhyve_args; - uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context); - - uhyve_args->ret = kmalloc(sizeof(struct ibv_comp_channel)); - - uhyve_send(UHYVE_PORT_IBV_CREATE_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args)); - - // TODO: Fix pointers in returned data structures. - return uhyve_args.ret; -} - - diff --git a/tools/ibv_code_generator/GEN-kernel.c b/tools/ibv_code_generator/GEN-kernel.c new file mode 100644 index 000000000..009bbd5f6 --- /dev/null +++ b/tools/ibv_code_generator/GEN-kernel.c @@ -0,0 +1,1767 @@ +/* + * ibv_wc_status_str + */ + +typedef struct { + // Parameters: + enum ibv_wc_status status; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_wc_status_str_t; + +const char * ibv_wc_status_str(enum ibv_wc_status status) { + uhyve_ibv_wc_status_str_t uhyve_args; + uhyve_args.status = status; + + uhyve_send(UHYVE_PORT_IBV_WC_STATUS_STR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_rate_to_mult + */ + +typedef struct { + // Parameters: + enum ibv_rate rate; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rate_to_mult_t; + +int ibv_rate_to_mult(enum ibv_rate rate) { + uhyve_ibv_rate_to_mult_t uhyve_args; + uhyve_args.rate = rate; + + uhyve_send(UHYVE_PORT_IBV_RATE_TO_MULT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * mult_to_ibv_rate + */ + +typedef struct { + // Parameters: + int mult; + // Return value: + enum ibv_rate ret; +} __attribute__((packed)) uhyve_mult_to_ibv_rate_t; + +enum ibv_rate mult_to_ibv_rate(int mult) { + uhyve_mult_to_ibv_rate_t uhyve_args; + uhyve_args.mult = mult; + + uhyve_send(UHYVE_PORT_MULT_TO_IBV_RATE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_rate_to_mbps + */ + +typedef struct { + // Parameters: + enum ibv_rate rate; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rate_to_mbps_t; + +int ibv_rate_to_mbps(enum ibv_rate rate) { + uhyve_ibv_rate_to_mbps_t uhyve_args; + uhyve_args.rate = rate; + + uhyve_send(UHYVE_PORT_IBV_RATE_TO_MBPS, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * mbps_to_ibv_rate + */ + +typedef struct { + // Parameters: + int mbps; + // Return value: + enum ibv_rate ret; +} __attribute__((packed)) uhyve_mbps_to_ibv_rate_t; + +enum ibv_rate mbps_to_ibv_rate(int mbps) { + uhyve_mbps_to_ibv_rate_t uhyve_args; + uhyve_args.mbps = mbps; + + uhyve_send(UHYVE_PORT_MBPS_TO_IBV_RATE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_post_wq_recv + */ + +typedef struct { + // Parameters: + struct ibv_wq * wq; + struct ibv_recv_wr * recv_wr; + struct ibv_recv_wr ** bad_recv_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_wq_recv_t; + +int ibv_post_wq_recv(struct ibv_wq * wq, struct ibv_recv_wr * recv_wr, struct ibv_recv_wr ** bad_recv_wr) { + uhyve_ibv_post_wq_recv_t uhyve_args; + uhyve_args.wq = wq; + uhyve_args.recv_wr = recv_wr; + // TODO: Take care of ** parameter. + + uhyve_send(UHYVE_PORT_IBV_POST_WQ_RECV, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * verbs_get_ctx + */ + +typedef struct { + // Parameters: + struct ibv_context * ctx; + // Return value: + struct verbs_context * ret; +} __attribute__((packed)) uhyve_verbs_get_ctx_t; + +struct verbs_context * verbs_get_ctx(struct ibv_context * ctx) { + uhyve_verbs_get_ctx_t uhyve_args; + uhyve_args.ctx = ctx; + + uhyve_send(UHYVE_PORT_VERBS_GET_CTX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_get_device_list + */ + +typedef struct { + // Parameters: + int * num_devices; + // Return value: + struct ibv_device ** ret; +} __attribute__((packed)) uhyve_ibv_get_device_list_t; + +struct ibv_device ** ibv_get_device_list(int * num_devices) { + uhyve_ibv_get_device_list_t uhyve_args; + uhyve_args.num_devices = num_devices; + + uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_LIST, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_free_device_list + */ + +typedef struct { + // Parameters: + struct ibv_device ** list; +} __attribute__((packed)) uhyve_ibv_free_device_list_t; + +void ibv_free_device_list(struct ibv_device ** list) { + uhyve_ibv_free_device_list_t uhyve_args; + // TODO: Take care of ** parameter. + + uhyve_send(UHYVE_PORT_IBV_FREE_DEVICE_LIST, (unsigned) virt_to_phys((size_t) &uhyve_args)); +} + + +/* + * ibv_get_device_name + */ + +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_get_device_name_t; + +const char * ibv_get_device_name(struct ibv_device * device) { + uhyve_ibv_get_device_name_t uhyve_args; + uhyve_args.device = device; + + uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_NAME, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_get_device_guid + */ + +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + __be64 ret; +} __attribute__((packed)) uhyve_ibv_get_device_guid_t; + +__be64 ibv_get_device_guid(struct ibv_device * device) { + uhyve_ibv_get_device_guid_t uhyve_args; + uhyve_args.device = device; + + uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_GUID, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_open_device + */ + +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + struct ibv_context * ret; +} __attribute__((packed)) uhyve_ibv_open_device_t; + +struct ibv_context * ibv_open_device(struct ibv_device * device) { + uhyve_ibv_open_device_t uhyve_args; + uhyve_args.device = device; + + uhyve_send(UHYVE_PORT_IBV_OPEN_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_close_device + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_close_device_t; + +int ibv_close_device(struct ibv_context * context) { + uhyve_ibv_close_device_t uhyve_args; + uhyve_args.context = context; + + uhyve_send(UHYVE_PORT_IBV_CLOSE_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_get_async_event + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_async_event * event; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_async_event_t; + +int ibv_get_async_event(struct ibv_context * context, struct ibv_async_event * event) { + uhyve_ibv_get_async_event_t uhyve_args; + uhyve_args.context = context; + uhyve_args.event = event; + + uhyve_send(UHYVE_PORT_IBV_GET_ASYNC_EVENT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_ack_async_event + */ + +typedef struct { + // Parameters: + struct ibv_async_event * event; +} __attribute__((packed)) uhyve_ibv_ack_async_event_t; + +void ibv_ack_async_event(struct ibv_async_event * event) { + uhyve_ibv_ack_async_event_t uhyve_args; + uhyve_args.event = event; + + uhyve_send(UHYVE_PORT_IBV_ACK_ASYNC_EVENT, (unsigned) virt_to_phys((size_t) &uhyve_args)); +} + + +/* + * ibv_query_device + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_device_attr * device_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_device_t; + +int ibv_query_device(struct ibv_context * context, struct ibv_device_attr * device_attr) { + uhyve_ibv_query_device_t uhyve_args; + uhyve_args.context = context; + uhyve_args.device_attr = device_attr; + + uhyve_send(UHYVE_PORT_IBV_QUERY_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_port + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_port_attr * port_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_port_t; + +int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr) { + uhyve_ibv_query_port_t uhyve_args; + uhyve_args.context = context; + uhyve_args.port_num = port_num; + uhyve_args.port_attr = port_attr; + + uhyve_send(UHYVE_PORT_IBV_QUERY_PORT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ___ibv_query_port + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_port_attr * port_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve____ibv_query_port_t; + +int ___ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr) { + uhyve____ibv_query_port_t uhyve_args; + uhyve_args.context = context; + uhyve_args.port_num = port_num; + uhyve_args.port_attr = port_attr; + + uhyve_send(UHYVE_PORT____IBV_QUERY_PORT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_gid + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + int index; + union ibv_gid * gid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_gid_t; + +int ibv_query_gid(struct ibv_context * context, uint8_t port_num, int index, union ibv_gid * gid) { + uhyve_ibv_query_gid_t uhyve_args; + uhyve_args.context = context; + uhyve_args.port_num = port_num; + uhyve_args.index = index; + uhyve_args.gid = gid; + + uhyve_send(UHYVE_PORT_IBV_QUERY_GID, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_pkey + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + int index; + __be16 * pkey; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_pkey_t; + +int ibv_query_pkey(struct ibv_context * context, uint8_t port_num, int index, __be16 * pkey) { + uhyve_ibv_query_pkey_t uhyve_args; + uhyve_args.context = context; + uhyve_args.port_num = port_num; + uhyve_args.index = index; + uhyve_args.pkey = pkey; + + uhyve_send(UHYVE_PORT_IBV_QUERY_PKEY, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_alloc_pd + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + struct ibv_pd * ret; +} __attribute__((packed)) uhyve_ibv_alloc_pd_t; + +struct ibv_pd * ibv_alloc_pd(struct ibv_context * context) { + uhyve_ibv_alloc_pd_t uhyve_args; + uhyve_args.context = context; + + uhyve_send(UHYVE_PORT_IBV_ALLOC_PD, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_dealloc_pd + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dealloc_pd_t; + +int ibv_dealloc_pd(struct ibv_pd * pd) { + uhyve_ibv_dealloc_pd_t uhyve_args; + uhyve_args.pd = pd; + + uhyve_send(UHYVE_PORT_IBV_DEALLOC_PD, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_flow + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_flow_attr * flow; + // Return value: + struct ibv_flow * ret; +} __attribute__((packed)) uhyve_ibv_create_flow_t; + +struct ibv_flow * ibv_create_flow(struct ibv_qp * qp, struct ibv_flow_attr * flow) { + uhyve_ibv_create_flow_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.flow = flow; + + uhyve_send(UHYVE_PORT_IBV_CREATE_FLOW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_flow + */ + +typedef struct { + // Parameters: + struct ibv_flow * flow_id; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_flow_t; + +int ibv_destroy_flow(struct ibv_flow * flow_id) { + uhyve_ibv_destroy_flow_t uhyve_args; + uhyve_args.flow_id = flow_id; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_FLOW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_open_xrcd + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_xrcd_init_attr * xrcd_init_attr; + // Return value: + struct ibv_xrcd * ret; +} __attribute__((packed)) uhyve_ibv_open_xrcd_t; + +struct ibv_xrcd * ibv_open_xrcd(struct ibv_context * context, struct ibv_xrcd_init_attr * xrcd_init_attr) { + uhyve_ibv_open_xrcd_t uhyve_args; + uhyve_args.context = context; + uhyve_args.xrcd_init_attr = xrcd_init_attr; + + uhyve_send(UHYVE_PORT_IBV_OPEN_XRCD, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_close_xrcd + */ + +typedef struct { + // Parameters: + struct ibv_xrcd * xrcd; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_close_xrcd_t; + +int ibv_close_xrcd(struct ibv_xrcd * xrcd) { + uhyve_ibv_close_xrcd_t uhyve_args; + uhyve_args.xrcd = xrcd; + + uhyve_send(UHYVE_PORT_IBV_CLOSE_XRCD, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_reg_mr + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + void * addr; + int length; + int access; + // Return value: + struct ibv_mr * ret; +} __attribute__((packed)) uhyve_ibv_reg_mr_t; + +struct ibv_mr * ibv_reg_mr(struct ibv_pd * pd, void * addr, int length, int access) { + uhyve_ibv_reg_mr_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.addr = addr; + uhyve_args.length = length; + uhyve_args.access = access; + + uhyve_send(UHYVE_PORT_IBV_REG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_rereg_mr + */ + +typedef struct { + // Parameters: + struct ibv_mr * mr; + int flags; + struct ibv_pd * pd; + void * addr; + int length; + int access; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rereg_mr_t; + +int ibv_rereg_mr(struct ibv_mr * mr, int flags, struct ibv_pd * pd, void * addr, int length, int access) { + uhyve_ibv_rereg_mr_t uhyve_args; + uhyve_args.mr = mr; + uhyve_args.flags = flags; + uhyve_args.pd = pd; + uhyve_args.addr = addr; + uhyve_args.length = length; + uhyve_args.access = access; + + uhyve_send(UHYVE_PORT_IBV_REREG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_dereg_mr + */ + +typedef struct { + // Parameters: + struct ibv_mr * mr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dereg_mr_t; + +int ibv_dereg_mr(struct ibv_mr * mr) { + uhyve_ibv_dereg_mr_t uhyve_args; + uhyve_args.mr = mr; + + uhyve_send(UHYVE_PORT_IBV_DEREG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_alloc_mw + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + enum ibv_mw_type type; + // Return value: + struct ibv_mw * ret; +} __attribute__((packed)) uhyve_ibv_alloc_mw_t; + +struct ibv_mw * ibv_alloc_mw(struct ibv_pd * pd, enum ibv_mw_type type) { + uhyve_ibv_alloc_mw_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.type = type; + + uhyve_send(UHYVE_PORT_IBV_ALLOC_MW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_dealloc_mw + */ + +typedef struct { + // Parameters: + struct ibv_mw * mw; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dealloc_mw_t; + +int ibv_dealloc_mw(struct ibv_mw * mw) { + uhyve_ibv_dealloc_mw_t uhyve_args; + uhyve_args.mw = mw; + + uhyve_send(UHYVE_PORT_IBV_DEALLOC_MW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_inc_rkey + */ + +typedef struct { + // Parameters: + uint32_t rkey; + // Return value: + uint32_t ret; +} __attribute__((packed)) uhyve_ibv_inc_rkey_t; + +uint32_t ibv_inc_rkey(uint32_t rkey) { + uhyve_ibv_inc_rkey_t uhyve_args; + uhyve_args.rkey = rkey; + + uhyve_send(UHYVE_PORT_IBV_INC_RKEY, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_bind_mw + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_mw * mw; + struct ibv_mw_bind * mw_bind; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_bind_mw_t; + +int ibv_bind_mw(struct ibv_qp * qp, struct ibv_mw * mw, struct ibv_mw_bind * mw_bind) { + uhyve_ibv_bind_mw_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.mw = mw; + uhyve_args.mw_bind = mw_bind; + + uhyve_send(UHYVE_PORT_IBV_BIND_MW, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_comp_channel + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + struct ibv_comp_channel * ret; +} __attribute__((packed)) uhyve_ibv_create_comp_channel_t; + +struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context) { + uhyve_ibv_create_comp_channel_t uhyve_args; + uhyve_args.context = context; + + uhyve_send(UHYVE_PORT_IBV_CREATE_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_comp_channel + */ + +typedef struct { + // Parameters: + struct ibv_comp_channel * channel; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_comp_channel_t; + +int ibv_destroy_comp_channel(struct ibv_comp_channel * channel) { + uhyve_ibv_destroy_comp_channel_t uhyve_args; + uhyve_args.channel = channel; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_cq + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + int cqe; + void * cq_context; + struct ibv_comp_channel * channel; + int comp_vector; + // Return value: + struct ibv_cq * ret; +} __attribute__((packed)) uhyve_ibv_create_cq_t; + +struct ibv_cq * ibv_create_cq(struct ibv_context * context, int cqe, void * cq_context, struct ibv_comp_channel * channel, int comp_vector) { + uhyve_ibv_create_cq_t uhyve_args; + uhyve_args.context = context; + uhyve_args.cqe = cqe; + uhyve_args.cq_context = cq_context; + uhyve_args.channel = channel; + uhyve_args.comp_vector = comp_vector; + + uhyve_send(UHYVE_PORT_IBV_CREATE_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_cq_ex + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_cq_init_attr_ex * cq_attr; + // Return value: + struct ibv_cq_ex * ret; +} __attribute__((packed)) uhyve_ibv_create_cq_ex_t; + +struct ibv_cq_ex * ibv_create_cq_ex(struct ibv_context * context, struct ibv_cq_init_attr_ex * cq_attr) { + uhyve_ibv_create_cq_ex_t uhyve_args; + uhyve_args.context = context; + uhyve_args.cq_attr = cq_attr; + + uhyve_send(UHYVE_PORT_IBV_CREATE_CQ_EX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_resize_cq + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int cqe; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_resize_cq_t; + +int ibv_resize_cq(struct ibv_cq * cq, int cqe) { + uhyve_ibv_resize_cq_t uhyve_args; + uhyve_args.cq = cq; + uhyve_args.cqe = cqe; + + uhyve_send(UHYVE_PORT_IBV_RESIZE_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_cq + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_cq_t; + +int ibv_destroy_cq(struct ibv_cq * cq) { + uhyve_ibv_destroy_cq_t uhyve_args; + uhyve_args.cq = cq; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_get_cq_event + */ + +typedef struct { + // Parameters: + struct ibv_comp_channel * channel; + struct ibv_cq ** cq; + void ** cq_context; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_cq_event_t; + +int ibv_get_cq_event(struct ibv_comp_channel * channel, struct ibv_cq ** cq, void ** cq_context) { + uhyve_ibv_get_cq_event_t uhyve_args; + uhyve_args.channel = channel; + // TODO: Take care of ** parameter. + // TODO: Take care of ** parameter. + + uhyve_send(UHYVE_PORT_IBV_GET_CQ_EVENT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_ack_cq_events + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + unsigned int nevents; +} __attribute__((packed)) uhyve_ibv_ack_cq_events_t; + +void ibv_ack_cq_events(struct ibv_cq * cq, unsigned int nevents) { + uhyve_ibv_ack_cq_events_t uhyve_args; + uhyve_args.cq = cq; + uhyve_args.nevents = nevents; + + uhyve_send(UHYVE_PORT_IBV_ACK_CQ_EVENTS, (unsigned) virt_to_phys((size_t) &uhyve_args)); +} + + +/* + * ibv_poll_cq + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int num_entries; + struct ibv_wc * wc; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_poll_cq_t; + +int ibv_poll_cq(struct ibv_cq * cq, int num_entries, struct ibv_wc * wc) { + uhyve_ibv_poll_cq_t uhyve_args; + uhyve_args.cq = cq; + uhyve_args.num_entries = num_entries; + uhyve_args.wc = wc; + + uhyve_send(UHYVE_PORT_IBV_POLL_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_req_notify_cq + */ + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int solicited_only; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_req_notify_cq_t; + +int ibv_req_notify_cq(struct ibv_cq * cq, int solicited_only) { + uhyve_ibv_req_notify_cq_t uhyve_args; + uhyve_args.cq = cq; + uhyve_args.solicited_only = solicited_only; + + uhyve_send(UHYVE_PORT_IBV_REQ_NOTIFY_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_srq + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_srq_init_attr * srq_init_attr; + // Return value: + struct ibv_srq * ret; +} __attribute__((packed)) uhyve_ibv_create_srq_t; + +struct ibv_srq * ibv_create_srq(struct ibv_pd * pd, struct ibv_srq_init_attr * srq_init_attr) { + uhyve_ibv_create_srq_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.srq_init_attr = srq_init_attr; + + uhyve_send(UHYVE_PORT_IBV_CREATE_SRQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_srq_ex + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_srq_init_attr_ex * srq_init_attr_ex; + // Return value: + struct ibv_srq * ret; +} __attribute__((packed)) uhyve_ibv_create_srq_ex_t; + +struct ibv_srq * ibv_create_srq_ex(struct ibv_context * context, struct ibv_srq_init_attr_ex * srq_init_attr_ex) { + uhyve_ibv_create_srq_ex_t uhyve_args; + uhyve_args.context = context; + uhyve_args.srq_init_attr_ex = srq_init_attr_ex; + + uhyve_send(UHYVE_PORT_IBV_CREATE_SRQ_EX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_modify_srq + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_srq_attr * srq_attr; + int srq_attr_mask; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_srq_t; + +int ibv_modify_srq(struct ibv_srq * srq, struct ibv_srq_attr * srq_attr, int srq_attr_mask) { + uhyve_ibv_modify_srq_t uhyve_args; + uhyve_args.srq = srq; + uhyve_args.srq_attr = srq_attr; + uhyve_args.srq_attr_mask = srq_attr_mask; + + uhyve_send(UHYVE_PORT_IBV_MODIFY_SRQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_srq + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_srq_attr * srq_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_srq_t; + +int ibv_query_srq(struct ibv_srq * srq, struct ibv_srq_attr * srq_attr) { + uhyve_ibv_query_srq_t uhyve_args; + uhyve_args.srq = srq; + uhyve_args.srq_attr = srq_attr; + + uhyve_send(UHYVE_PORT_IBV_QUERY_SRQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_get_srq_num + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + uint32_t * srq_num; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_srq_num_t; + +int ibv_get_srq_num(struct ibv_srq * srq, uint32_t * srq_num) { + uhyve_ibv_get_srq_num_t uhyve_args; + uhyve_args.srq = srq; + uhyve_args.srq_num = srq_num; + + uhyve_send(UHYVE_PORT_IBV_GET_SRQ_NUM, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_srq + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_srq_t; + +int ibv_destroy_srq(struct ibv_srq * srq) { + uhyve_ibv_destroy_srq_t uhyve_args; + uhyve_args.srq = srq; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_SRQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_post_srq_recv + */ + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_recv_wr * recv_wr; + struct ibv_recv_wr ** bad_recv_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_srq_recv_t; + +int ibv_post_srq_recv(struct ibv_srq * srq, struct ibv_recv_wr * recv_wr, struct ibv_recv_wr ** bad_recv_wr) { + uhyve_ibv_post_srq_recv_t uhyve_args; + uhyve_args.srq = srq; + uhyve_args.recv_wr = recv_wr; + // TODO: Take care of ** parameter. + + uhyve_send(UHYVE_PORT_IBV_POST_SRQ_RECV, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_qp + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_qp_init_attr * qp_init_attr; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_create_qp_t; + +struct ibv_qp * ibv_create_qp(struct ibv_pd * pd, struct ibv_qp_init_attr * qp_init_attr) { + uhyve_ibv_create_qp_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.qp_init_attr = qp_init_attr; + + uhyve_send(UHYVE_PORT_IBV_CREATE_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_qp_ex + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_qp_init_attr_ex * qp_init_attr_ex; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_create_qp_ex_t; + +struct ibv_qp * ibv_create_qp_ex(struct ibv_context * context, struct ibv_qp_init_attr_ex * qp_init_attr_ex) { + uhyve_ibv_create_qp_ex_t uhyve_args; + uhyve_args.context = context; + uhyve_args.qp_init_attr_ex = qp_init_attr_ex; + + uhyve_send(UHYVE_PORT_IBV_CREATE_QP_EX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_rt_values_ex + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_values_ex * values; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_rt_values_ex_t; + +int ibv_query_rt_values_ex(struct ibv_context * context, struct ibv_values_ex * values) { + uhyve_ibv_query_rt_values_ex_t uhyve_args; + uhyve_args.context = context; + uhyve_args.values = values; + + uhyve_send(UHYVE_PORT_IBV_QUERY_RT_VALUES_EX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_device_ex + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + const struct ibv_query_device_ex_input * input; + struct ibv_device_attr_ex * attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_device_ex_t; + +int ibv_query_device_ex(struct ibv_context * context, const struct ibv_query_device_ex_input * input, struct ibv_device_attr_ex * attr) { + uhyve_ibv_query_device_ex_t uhyve_args; + uhyve_args.context = context; + uhyve_args.input = input; + uhyve_args.attr = attr; + + uhyve_send(UHYVE_PORT_IBV_QUERY_DEVICE_EX, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_open_qp + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_qp_open_attr * qp_open_attr; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_open_qp_t; + +struct ibv_qp * ibv_open_qp(struct ibv_context * context, struct ibv_qp_open_attr * qp_open_attr) { + uhyve_ibv_open_qp_t uhyve_args; + uhyve_args.context = context; + uhyve_args.qp_open_attr = qp_open_attr; + + uhyve_send(UHYVE_PORT_IBV_OPEN_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_modify_qp + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_qp_attr * attr; + int attr_mask; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_qp_t; + +int ibv_modify_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask) { + uhyve_ibv_modify_qp_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.attr = attr; + uhyve_args.attr_mask = attr_mask; + + uhyve_send(UHYVE_PORT_IBV_MODIFY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_query_qp + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_qp_attr * attr; + int attr_mask; + struct ibv_qp_init_attr * init_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_qp_t; + +int ibv_query_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask, struct ibv_qp_init_attr * init_attr) { + uhyve_ibv_query_qp_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.attr = attr; + uhyve_args.attr_mask = attr_mask; + uhyve_args.init_attr = init_attr; + + uhyve_send(UHYVE_PORT_IBV_QUERY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_qp + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_qp_t; + +int ibv_destroy_qp(struct ibv_qp * qp) { + uhyve_ibv_destroy_qp_t uhyve_args; + uhyve_args.qp = qp; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_wq + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_wq_init_attr * wq_init_attr; + // Return value: + struct ibv_wq * ret; +} __attribute__((packed)) uhyve_ibv_create_wq_t; + +struct ibv_wq * ibv_create_wq(struct ibv_context * context, struct ibv_wq_init_attr * wq_init_attr) { + uhyve_ibv_create_wq_t uhyve_args; + uhyve_args.context = context; + uhyve_args.wq_init_attr = wq_init_attr; + + uhyve_send(UHYVE_PORT_IBV_CREATE_WQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_modify_wq + */ + +typedef struct { + // Parameters: + struct ibv_wq * wq; + struct ibv_wq_attr * wq_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_wq_t; + +int ibv_modify_wq(struct ibv_wq * wq, struct ibv_wq_attr * wq_attr) { + uhyve_ibv_modify_wq_t uhyve_args; + uhyve_args.wq = wq; + uhyve_args.wq_attr = wq_attr; + + uhyve_send(UHYVE_PORT_IBV_MODIFY_WQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_wq + */ + +typedef struct { + // Parameters: + struct ibv_wq * wq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_wq_t; + +int ibv_destroy_wq(struct ibv_wq * wq) { + uhyve_ibv_destroy_wq_t uhyve_args; + uhyve_args.wq = wq; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_WQ, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_rwq_ind_table + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_rwq_ind_table_init_attr * init_attr; + // Return value: + struct ibv_rwq_ind_table * ret; +} __attribute__((packed)) uhyve_ibv_create_rwq_ind_table_t; + +struct ibv_rwq_ind_table * ibv_create_rwq_ind_table(struct ibv_context * context, struct ibv_rwq_ind_table_init_attr * init_attr) { + uhyve_ibv_create_rwq_ind_table_t uhyve_args; + uhyve_args.context = context; + uhyve_args.init_attr = init_attr; + + uhyve_send(UHYVE_PORT_IBV_CREATE_RWQ_IND_TABLE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_rwq_ind_table + */ + +typedef struct { + // Parameters: + struct ibv_rwq_ind_table * rwq_ind_table; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_rwq_ind_table_t; + +int ibv_destroy_rwq_ind_table(struct ibv_rwq_ind_table * rwq_ind_table) { + uhyve_ibv_destroy_rwq_ind_table_t uhyve_args; + uhyve_args.rwq_ind_table = rwq_ind_table; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_RWQ_IND_TABLE, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_post_send + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_send_wr * wr; + struct ibv_send_wr ** bad_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_send_t; + +int ibv_post_send(struct ibv_qp * qp, struct ibv_send_wr * wr, struct ibv_send_wr ** bad_wr) { + uhyve_ibv_post_send_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.wr = wr; + // TODO: Take care of ** parameter. + + uhyve_send(UHYVE_PORT_IBV_POST_SEND, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_post_recv + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_recv_wr * wr; + struct ibv_recv_wr ** bad_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_recv_t; + +int ibv_post_recv(struct ibv_qp * qp, struct ibv_recv_wr * wr, struct ibv_recv_wr ** bad_wr) { + uhyve_ibv_post_recv_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.wr = wr; + // TODO: Take care of ** parameter. + + uhyve_send(UHYVE_PORT_IBV_POST_RECV, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_ah + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_ah_attr * attr; + // Return value: + struct ibv_ah * ret; +} __attribute__((packed)) uhyve_ibv_create_ah_t; + +struct ibv_ah * ibv_create_ah(struct ibv_pd * pd, struct ibv_ah_attr * attr) { + uhyve_ibv_create_ah_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.attr = attr; + + uhyve_send(UHYVE_PORT_IBV_CREATE_AH, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_init_ah_from_wc + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_wc * wc; + struct ibv_grh * grh; + struct ibv_ah_attr * ah_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_init_ah_from_wc_t; + +int ibv_init_ah_from_wc(struct ibv_context * context, uint8_t port_num, struct ibv_wc * wc, struct ibv_grh * grh, struct ibv_ah_attr * ah_attr) { + uhyve_ibv_init_ah_from_wc_t uhyve_args; + uhyve_args.context = context; + uhyve_args.port_num = port_num; + uhyve_args.wc = wc; + uhyve_args.grh = grh; + uhyve_args.ah_attr = ah_attr; + + uhyve_send(UHYVE_PORT_IBV_INIT_AH_FROM_WC, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_create_ah_from_wc + */ + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_wc * wc; + struct ibv_grh * grh; + uint8_t port_num; + // Return value: + struct ibv_ah * ret; +} __attribute__((packed)) uhyve_ibv_create_ah_from_wc_t; + +struct ibv_ah * ibv_create_ah_from_wc(struct ibv_pd * pd, struct ibv_wc * wc, struct ibv_grh * grh, uint8_t port_num) { + uhyve_ibv_create_ah_from_wc_t uhyve_args; + uhyve_args.pd = pd; + uhyve_args.wc = wc; + uhyve_args.grh = grh; + uhyve_args.port_num = port_num; + + uhyve_send(UHYVE_PORT_IBV_CREATE_AH_FROM_WC, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_destroy_ah + */ + +typedef struct { + // Parameters: + struct ibv_ah * ah; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_ah_t; + +int ibv_destroy_ah(struct ibv_ah * ah) { + uhyve_ibv_destroy_ah_t uhyve_args; + uhyve_args.ah = ah; + + uhyve_send(UHYVE_PORT_IBV_DESTROY_AH, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_attach_mcast + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + const union ibv_gid * gid; + uint16_t lid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_attach_mcast_t; + +int ibv_attach_mcast(struct ibv_qp * qp, const union ibv_gid * gid, uint16_t lid) { + uhyve_ibv_attach_mcast_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.gid = gid; + uhyve_args.lid = lid; + + uhyve_send(UHYVE_PORT_IBV_ATTACH_MCAST, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_detach_mcast + */ + +typedef struct { + // Parameters: + struct ibv_qp * qp; + const union ibv_gid * gid; + uint16_t lid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_detach_mcast_t; + +int ibv_detach_mcast(struct ibv_qp * qp, const union ibv_gid * gid, uint16_t lid) { + uhyve_ibv_detach_mcast_t uhyve_args; + uhyve_args.qp = qp; + uhyve_args.gid = gid; + uhyve_args.lid = lid; + + uhyve_send(UHYVE_PORT_IBV_DETACH_MCAST, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_fork_init + */ + +typedef struct { + // Parameters: + ; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_fork_init_t; + +int ibv_fork_init( ) { + uhyve_ibv_fork_init_t uhyve_args; + uhyve_args. = ; + + uhyve_send(UHYVE_PORT_IBV_FORK_INIT, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_node_type_str + */ + +typedef struct { + // Parameters: + enum ibv_node_type node_type; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_node_type_str_t; + +const char * ibv_node_type_str(enum ibv_node_type node_type) { + uhyve_ibv_node_type_str_t uhyve_args; + uhyve_args.node_type = node_type; + + uhyve_send(UHYVE_PORT_IBV_NODE_TYPE_STR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_port_state_str + */ + +typedef struct { + // Parameters: + enum ibv_port_state port_state; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_port_state_str_t; + +const char * ibv_port_state_str(enum ibv_port_state port_state) { + uhyve_ibv_port_state_str_t uhyve_args; + uhyve_args.port_state = port_state; + + uhyve_send(UHYVE_PORT_IBV_PORT_STATE_STR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_event_type_str + */ + +typedef struct { + // Parameters: + enum ibv_event_type event; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_event_type_str_t; + +const char * ibv_event_type_str(enum ibv_event_type event) { + uhyve_ibv_event_type_str_t uhyve_args; + uhyve_args.event = event; + + uhyve_send(UHYVE_PORT_IBV_EVENT_TYPE_STR, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_resolve_eth_l2_from_gid + */ + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_ah_attr * attr; + uint8_t eth_mac[6]; + uint16_t * vid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_resolve_eth_l2_from_gid_t; + +int ibv_resolve_eth_l2_from_gid(struct ibv_context * context, struct ibv_ah_attr * attr, uint8_t eth_mac[6], uint16_t * vid) { + uhyve_ibv_resolve_eth_l2_from_gid_t uhyve_args; + uhyve_args.context = context; + uhyve_args.attr = attr; + uhyve_args.eth_mac[6] = eth_mac[6]; + uhyve_args.vid = vid; + + uhyve_send(UHYVE_PORT_IBV_RESOLVE_ETH_L2_FROM_GID, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + +/* + * ibv_is_qpt_supported + */ + +typedef struct { + // Parameters: + uint32_t caps; + enum ibv_qp_type qpt; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_is_qpt_supported_t; + +int ibv_is_qpt_supported(uint32_t caps, enum ibv_qp_type qpt) { + uhyve_ibv_is_qpt_supported_t uhyve_args; + uhyve_args.caps = caps; + uhyve_args.qpt = qpt; + + uhyve_send(UHYVE_PORT_IBV_IS_QPT_SUPPORTED, (unsigned) virt_to_phys((size_t) &uhyve_args)); + + return uhyve_args.ret; +} + + diff --git a/tools/ibv_code_generator/GEN-tools-uhyve-ibv-ports.h b/tools/ibv_code_generator/GEN-tools-uhyve-ibv-ports.h index 0ac2d4c23..481ce6165 100644 --- a/tools/ibv_code_generator/GEN-tools-uhyve-ibv-ports.h +++ b/tools/ibv_code_generator/GEN-tools-uhyve-ibv-ports.h @@ -1,6 +1,773 @@ typedef enum { - UHYVE_PORT_IBV_OPEN_DEVICE = 0x510, - UHYVE_PORT_IBV_GET_DEVICE_NAME = 0x511, - UHYVE_PORT_IBV_QUERY_PORT = 0x512, - UHYVE_PORT_IBV_CREATE_COMP_CHANNEL = 0x513, -} uhyve_ibv_t; \ No newline at end of file + UHYVE_PORT_IBV_WC_STATUS_STR = 0x510, + UHYVE_PORT_IBV_RATE_TO_MULT = 0x511, + UHYVE_PORT_MULT_TO_IBV_RATE = 0x512, + UHYVE_PORT_IBV_RATE_TO_MBPS = 0x513, + UHYVE_PORT_MBPS_TO_IBV_RATE = 0x514, + UHYVE_PORT_IBV_POST_WQ_RECV = 0x515, + UHYVE_PORT_VERBS_GET_CTX = 0x516, + UHYVE_PORT_IBV_GET_DEVICE_LIST = 0x517, + UHYVE_PORT_IBV_FREE_DEVICE_LIST = 0x518, + UHYVE_PORT_IBV_GET_DEVICE_NAME = 0x519, + UHYVE_PORT_IBV_GET_DEVICE_GUID = 0x51A, + UHYVE_PORT_IBV_OPEN_DEVICE = 0x51B, + UHYVE_PORT_IBV_CLOSE_DEVICE = 0x51C, + UHYVE_PORT_IBV_GET_ASYNC_EVENT = 0x51D, + UHYVE_PORT_IBV_ACK_ASYNC_EVENT = 0x51E, + UHYVE_PORT_IBV_QUERY_DEVICE = 0x51F, + UHYVE_PORT_IBV_QUERY_PORT = 0x520, + UHYVE_PORT____IBV_QUERY_PORT = 0x521, + UHYVE_PORT_IBV_QUERY_GID = 0x522, + UHYVE_PORT_IBV_QUERY_PKEY = 0x523, + UHYVE_PORT_IBV_ALLOC_PD = 0x524, + UHYVE_PORT_IBV_DEALLOC_PD = 0x525, + UHYVE_PORT_IBV_CREATE_FLOW = 0x526, + UHYVE_PORT_IBV_DESTROY_FLOW = 0x527, + UHYVE_PORT_IBV_OPEN_XRCD = 0x528, + UHYVE_PORT_IBV_CLOSE_XRCD = 0x529, + UHYVE_PORT_IBV_REG_MR = 0x52A, + UHYVE_PORT_IBV_REREG_MR = 0x52B, + UHYVE_PORT_IBV_DEREG_MR = 0x52C, + UHYVE_PORT_IBV_ALLOC_MW = 0x52D, + UHYVE_PORT_IBV_DEALLOC_MW = 0x52E, + UHYVE_PORT_IBV_INC_RKEY = 0x52F, + UHYVE_PORT_IBV_BIND_MW = 0x530, + UHYVE_PORT_IBV_CREATE_COMP_CHANNEL = 0x531, + UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL = 0x532, + UHYVE_PORT_IBV_CREATE_CQ = 0x533, + UHYVE_PORT_IBV_CREATE_CQ_EX = 0x534, + UHYVE_PORT_IBV_RESIZE_CQ = 0x535, + UHYVE_PORT_IBV_DESTROY_CQ = 0x536, + UHYVE_PORT_IBV_GET_CQ_EVENT = 0x537, + UHYVE_PORT_IBV_ACK_CQ_EVENTS = 0x538, + UHYVE_PORT_IBV_POLL_CQ = 0x539, + UHYVE_PORT_IBV_REQ_NOTIFY_CQ = 0x53A, + UHYVE_PORT_IBV_CREATE_SRQ = 0x53B, + UHYVE_PORT_IBV_CREATE_SRQ_EX = 0x53C, + UHYVE_PORT_IBV_MODIFY_SRQ = 0x53D, + UHYVE_PORT_IBV_QUERY_SRQ = 0x53E, + UHYVE_PORT_IBV_GET_SRQ_NUM = 0x53F, + UHYVE_PORT_IBV_DESTROY_SRQ = 0x540, + UHYVE_PORT_IBV_POST_SRQ_RECV = 0x541, + UHYVE_PORT_IBV_CREATE_QP = 0x542, + UHYVE_PORT_IBV_CREATE_QP_EX = 0x543, + UHYVE_PORT_IBV_QUERY_RT_VALUES_EX = 0x544, + UHYVE_PORT_IBV_QUERY_DEVICE_EX = 0x545, + UHYVE_PORT_IBV_OPEN_QP = 0x546, + UHYVE_PORT_IBV_MODIFY_QP = 0x547, + UHYVE_PORT_IBV_QUERY_QP = 0x548, + UHYVE_PORT_IBV_DESTROY_QP = 0x549, + UHYVE_PORT_IBV_CREATE_WQ = 0x54A, + UHYVE_PORT_IBV_MODIFY_WQ = 0x54B, + UHYVE_PORT_IBV_DESTROY_WQ = 0x54C, + UHYVE_PORT_IBV_CREATE_RWQ_IND_TABLE = 0x54D, + UHYVE_PORT_IBV_DESTROY_RWQ_IND_TABLE = 0x54E, + UHYVE_PORT_IBV_POST_SEND = 0x54F, + UHYVE_PORT_IBV_POST_RECV = 0x550, + UHYVE_PORT_IBV_CREATE_AH = 0x551, + UHYVE_PORT_IBV_INIT_AH_FROM_WC = 0x552, + UHYVE_PORT_IBV_CREATE_AH_FROM_WC = 0x553, + UHYVE_PORT_IBV_DESTROY_AH = 0x554, + UHYVE_PORT_IBV_ATTACH_MCAST = 0x555, + UHYVE_PORT_IBV_DETACH_MCAST = 0x556, + UHYVE_PORT_IBV_FORK_INIT = 0x557, + UHYVE_PORT_IBV_NODE_TYPE_STR = 0x558, + UHYVE_PORT_IBV_PORT_STATE_STR = 0x559, + UHYVE_PORT_IBV_EVENT_TYPE_STR = 0x55A, + UHYVE_PORT_IBV_RESOLVE_ETH_L2_FROM_GID = 0x55B, + UHYVE_PORT_IBV_IS_QPT_SUPPORTED = 0x55C, +} uhyve_ibv_t; + +typedef struct { + // Parameters: + enum ibv_wc_status status; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_wc_status_str_t; + +typedef struct { + // Parameters: + enum ibv_rate rate; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rate_to_mult_t; + +typedef struct { + // Parameters: + int mult; + // Return value: + enum ibv_rate ret; +} __attribute__((packed)) uhyve_mult_to_ibv_rate_t; + +typedef struct { + // Parameters: + enum ibv_rate rate; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rate_to_mbps_t; + +typedef struct { + // Parameters: + int mbps; + // Return value: + enum ibv_rate ret; +} __attribute__((packed)) uhyve_mbps_to_ibv_rate_t; + +typedef struct { + // Parameters: + struct ibv_wq * wq; + struct ibv_recv_wr * recv_wr; + struct ibv_recv_wr ** bad_recv_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_wq_recv_t; + +typedef struct { + // Parameters: + struct ibv_context * ctx; + // Return value: + struct verbs_context * ret; +} __attribute__((packed)) uhyve_verbs_get_ctx_t; + +typedef struct { + // Parameters: + int * num_devices; + // Return value: + struct ibv_device ** ret; +} __attribute__((packed)) uhyve_ibv_get_device_list_t; + +typedef struct { + // Parameters: + struct ibv_device ** list; +} __attribute__((packed)) uhyve_ibv_free_device_list_t; + +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_get_device_name_t; + +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + __be64 ret; +} __attribute__((packed)) uhyve_ibv_get_device_guid_t; + +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + struct ibv_context * ret; +} __attribute__((packed)) uhyve_ibv_open_device_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_close_device_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_async_event * event; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_async_event_t; + +typedef struct { + // Parameters: + struct ibv_async_event * event; +} __attribute__((packed)) uhyve_ibv_ack_async_event_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_device_attr * device_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_device_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_port_attr * port_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_port_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_port_attr * port_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve____ibv_query_port_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + int index; + union ibv_gid * gid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_gid_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + int index; + __be16 * pkey; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_pkey_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + struct ibv_pd * ret; +} __attribute__((packed)) uhyve_ibv_alloc_pd_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dealloc_pd_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_flow_attr * flow; + // Return value: + struct ibv_flow * ret; +} __attribute__((packed)) uhyve_ibv_create_flow_t; + +typedef struct { + // Parameters: + struct ibv_flow * flow_id; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_flow_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_xrcd_init_attr * xrcd_init_attr; + // Return value: + struct ibv_xrcd * ret; +} __attribute__((packed)) uhyve_ibv_open_xrcd_t; + +typedef struct { + // Parameters: + struct ibv_xrcd * xrcd; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_close_xrcd_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + void * addr; + int length; + int access; + // Return value: + struct ibv_mr * ret; +} __attribute__((packed)) uhyve_ibv_reg_mr_t; + +typedef struct { + // Parameters: + struct ibv_mr * mr; + int flags; + struct ibv_pd * pd; + void * addr; + int length; + int access; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rereg_mr_t; + +typedef struct { + // Parameters: + struct ibv_mr * mr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dereg_mr_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + enum ibv_mw_type type; + // Return value: + struct ibv_mw * ret; +} __attribute__((packed)) uhyve_ibv_alloc_mw_t; + +typedef struct { + // Parameters: + struct ibv_mw * mw; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dealloc_mw_t; + +typedef struct { + // Parameters: + uint32_t rkey; + // Return value: + uint32_t ret; +} __attribute__((packed)) uhyve_ibv_inc_rkey_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_mw * mw; + struct ibv_mw_bind * mw_bind; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_bind_mw_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + struct ibv_comp_channel * ret; +} __attribute__((packed)) uhyve_ibv_create_comp_channel_t; + +typedef struct { + // Parameters: + struct ibv_comp_channel * channel; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_comp_channel_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + int cqe; + void * cq_context; + struct ibv_comp_channel * channel; + int comp_vector; + // Return value: + struct ibv_cq * ret; +} __attribute__((packed)) uhyve_ibv_create_cq_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_cq_init_attr_ex * cq_attr; + // Return value: + struct ibv_cq_ex * ret; +} __attribute__((packed)) uhyve_ibv_create_cq_ex_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int cqe; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_resize_cq_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_cq_t; + +typedef struct { + // Parameters: + struct ibv_comp_channel * channel; + struct ibv_cq ** cq; + void ** cq_context; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_cq_event_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + unsigned int nevents; +} __attribute__((packed)) uhyve_ibv_ack_cq_events_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int num_entries; + struct ibv_wc * wc; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_poll_cq_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int solicited_only; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_req_notify_cq_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_srq_init_attr * srq_init_attr; + // Return value: + struct ibv_srq * ret; +} __attribute__((packed)) uhyve_ibv_create_srq_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_srq_init_attr_ex * srq_init_attr_ex; + // Return value: + struct ibv_srq * ret; +} __attribute__((packed)) uhyve_ibv_create_srq_ex_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_srq_attr * srq_attr; + int srq_attr_mask; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_srq_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_srq_attr * srq_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_srq_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + uint32_t * srq_num; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_srq_num_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_srq_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_recv_wr * recv_wr; + struct ibv_recv_wr ** bad_recv_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_srq_recv_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_qp_init_attr * qp_init_attr; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_create_qp_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_qp_init_attr_ex * qp_init_attr_ex; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_create_qp_ex_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_values_ex * values; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_rt_values_ex_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + const struct ibv_query_device_ex_input * input; + struct ibv_device_attr_ex * attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_device_ex_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_qp_open_attr * qp_open_attr; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_open_qp_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_qp_attr * attr; + int attr_mask; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_qp_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_qp_attr * attr; + int attr_mask; + struct ibv_qp_init_attr * init_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_qp_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_qp_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_wq_init_attr * wq_init_attr; + // Return value: + struct ibv_wq * ret; +} __attribute__((packed)) uhyve_ibv_create_wq_t; + +typedef struct { + // Parameters: + struct ibv_wq * wq; + struct ibv_wq_attr * wq_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_wq_t; + +typedef struct { + // Parameters: + struct ibv_wq * wq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_wq_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_rwq_ind_table_init_attr * init_attr; + // Return value: + struct ibv_rwq_ind_table * ret; +} __attribute__((packed)) uhyve_ibv_create_rwq_ind_table_t; + +typedef struct { + // Parameters: + struct ibv_rwq_ind_table * rwq_ind_table; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_rwq_ind_table_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_send_wr * wr; + struct ibv_send_wr ** bad_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_send_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_recv_wr * wr; + struct ibv_recv_wr ** bad_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_recv_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_ah_attr * attr; + // Return value: + struct ibv_ah * ret; +} __attribute__((packed)) uhyve_ibv_create_ah_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_wc * wc; + struct ibv_grh * grh; + struct ibv_ah_attr * ah_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_init_ah_from_wc_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_wc * wc; + struct ibv_grh * grh; + uint8_t port_num; + // Return value: + struct ibv_ah * ret; +} __attribute__((packed)) uhyve_ibv_create_ah_from_wc_t; + +typedef struct { + // Parameters: + struct ibv_ah * ah; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_ah_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + const union ibv_gid * gid; + uint16_t lid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_attach_mcast_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + const union ibv_gid * gid; + uint16_t lid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_detach_mcast_t; + +typedef struct { + // Parameters: + ; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_fork_init_t; + +typedef struct { + // Parameters: + enum ibv_node_type node_type; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_node_type_str_t; + +typedef struct { + // Parameters: + enum ibv_port_state port_state; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_port_state_str_t; + +typedef struct { + // Parameters: + enum ibv_event_type event; + // Return value: + const char * ret; +} __attribute__((packed)) uhyve_ibv_event_type_str_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_ah_attr * attr; + uint8_t eth_mac[6]; + uint16_t * vid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_resolve_eth_l2_from_gid_t; + +typedef struct { + // Parameters: + uint32_t caps; + enum ibv_qp_type qpt; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_is_qpt_supported_t; + + + +void call_ibv_wc_status_str(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_rate_to_mult(struct kvm_run * run, uint8_t * guest_mem); +void call_mult_to_ibv_rate(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_rate_to_mbps(struct kvm_run * run, uint8_t * guest_mem); +void call_mbps_to_ibv_rate(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_post_wq_recv(struct kvm_run * run, uint8_t * guest_mem); +void call_verbs_get_ctx(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_device_list(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_free_device_list(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_device_name(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_device_guid(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_close_device(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_async_event(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_ack_async_event(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_device(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_port(struct kvm_run * run, uint8_t * guest_mem); +void call____ibv_query_port(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_gid(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_pkey(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_alloc_pd(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_dealloc_pd(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_flow(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_flow(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_open_xrcd(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_close_xrcd(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_reg_mr(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_rereg_mr(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_dereg_mr(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_alloc_mw(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_dealloc_mw(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_inc_rkey(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_bind_mw(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_comp_channel(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_comp_channel(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_cq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_cq_ex(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_resize_cq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_cq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_cq_event(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_ack_cq_events(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_poll_cq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_req_notify_cq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_srq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_srq_ex(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_modify_srq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_srq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_srq_num(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_srq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_post_srq_recv(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_qp(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_qp_ex(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_rt_values_ex(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_device_ex(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_open_qp(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_modify_qp(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_qp(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_qp(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_wq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_modify_wq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_wq(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_rwq_ind_table(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_rwq_ind_table(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_post_send(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_post_recv(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_ah(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_init_ah_from_wc(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_ah_from_wc(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_ah(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_attach_mcast(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_detach_mcast(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_fork_init(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_node_type_str(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_port_state_str(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_event_type_str(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_resolve_eth_l2_from_gid(struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_is_qpt_supported(struct kvm_run * run, uint8_t * guest_mem); diff --git a/tools/ibv_code_generator/GEN-tools-uhyve-ibv-structs.h b/tools/ibv_code_generator/GEN-tools-uhyve-ibv-structs.h deleted file mode 100644 index c8a682bec..000000000 --- a/tools/ibv_code_generator/GEN-tools-uhyve-ibv-structs.h +++ /dev/null @@ -1,30 +0,0 @@ -typedef struct { - // Parameters: - struct ibv_device * device; - // Return value: - struct ibv_context * ret; -} __attribute__((packed)) uhyve_ibv_open_device_t; - -typedef struct { - // Parameters: - struct ibv_device * device; - // Return value: - const char * ret; -} __attribute__((packed)) uhyve_ibv_get_device_name_t; - -typedef struct { - // Parameters: - struct ibv_context * context; - uint8_t port_num; - struct ibv_port_attr * port_attr; - // Return value: - int ret; -} __attribute__((packed)) uhyve_ibv_query_port_t; - -typedef struct { - // Parameters: - struct ibv_context * context; - // Return value: - struct ibv_comp_channel * ret; -} __attribute__((packed)) uhyve_ibv_create_comp_channel_t; - diff --git a/tools/ibv_code_generator/GEN-tools-uhyve-ibv.c b/tools/ibv_code_generator/GEN-tools-uhyve-ibv.c index e5ec8a6a4..d822f28e6 100644 --- a/tools/ibv_code_generator/GEN-tools-uhyve-ibv.c +++ b/tools/ibv_code_generator/GEN-tools-uhyve-ibv.c @@ -1,37 +1,539 @@ -void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem) { - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); - uhyve_ibv_open_device_t * args = (uhyve_ibv_open_device_t *) (guest_mem + data); +void call_ibv_wc_status_str(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_wc_status_str_t * args = (uhyve_ibv_wc_status_str_t *) (guest_mem + data); - struct ibv_context * host_ret = ibv_open_device(guest_mem+(size_t)args->device); - memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret)); - // TODO: Convert ptrs contained in return value. - // TODO: Delete host_ret data structure. + const char * host_ret = ibv_wc_status_str(args->status); +);memcpy(args->ret, host_ret, sizeof(host_ret));} + +void call_ibv_rate_to_mult(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_rate_to_mult_t * args = (uhyve_ibv_rate_to_mult_t *) (guest_mem + data); + + args.ret = ibv_rate_to_mult(args->rate); +);} + +void call_mult_to_ibv_rate(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_mult_to_ibv_rate_t * args = (uhyve_mult_to_ibv_rate_t *) (guest_mem + data); + + args.ret = mult_to_ibv_rate(args->mult); +);} + +void call_ibv_rate_to_mbps(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_rate_to_mbps_t * args = (uhyve_ibv_rate_to_mbps_t *) (guest_mem + data); + + args.ret = ibv_rate_to_mbps(args->rate); +);} + +void call_mbps_to_ibv_rate(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_mbps_to_ibv_rate_t * args = (uhyve_mbps_to_ibv_rate_t *) (guest_mem + data); + + args.ret = mbps_to_ibv_rate(args->mbps); +);} + +void call_ibv_post_wq_recv(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_post_wq_recv_t * args = (uhyve_ibv_post_wq_recv_t *) (guest_mem + data); + + args.ret = ibv_post_wq_recv(args->wq, args->recv_wr, args->bad_recv_wr); +);} + +void call_verbs_get_ctx(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_verbs_get_ctx_t * args = (uhyve_verbs_get_ctx_t *) (guest_mem + data); + + args.ret = verbs_get_ctx(args->ctx); +);} + +void call_ibv_get_device_list(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_device_list_t * args = (uhyve_ibv_get_device_list_t *) (guest_mem + data); + + // TODO: Take care of ** here. } +void call_ibv_free_device_list(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_free_device_list_t * args = (uhyve_ibv_free_device_list_t *) (guest_mem + data); + + ibv_free_device_list(args->list); +);} + void call_ibv_get_device_name(struct kvm_run * run, uint8_t * guest_mem) { - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); uhyve_ibv_get_device_name_t * args = (uhyve_ibv_get_device_name_t *) (guest_mem + data); - const char * host_ret = ibv_get_device_name(guest_mem+(size_t)args->device); - memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret)); - // TODO: Convert ptrs contained in return value. - // TODO: Delete host_ret data structure. -} + const char * host_ret = ibv_get_device_name(args->device); +);memcpy(args->ret, host_ret, sizeof(host_ret));} + +void call_ibv_get_device_guid(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_device_guid_t * args = (uhyve_ibv_get_device_guid_t *) (guest_mem + data); + + args.ret = ibv_get_device_guid(args->device); +);} + +void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_open_device_t * args = (uhyve_ibv_open_device_t *) (guest_mem + data); + + args.ret = ibv_open_device(args->device); +);} + +void call_ibv_close_device(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_close_device_t * args = (uhyve_ibv_close_device_t *) (guest_mem + data); + + args.ret = ibv_close_device(args->context); +);} + +void call_ibv_get_async_event(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_async_event_t * args = (uhyve_ibv_get_async_event_t *) (guest_mem + data); + + args.ret = ibv_get_async_event(args->context, args->event); +);} + +void call_ibv_ack_async_event(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_ack_async_event_t * args = (uhyve_ibv_ack_async_event_t *) (guest_mem + data); + + ibv_ack_async_event(args->event); +);} + +void call_ibv_query_device(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_device_t * args = (uhyve_ibv_query_device_t *) (guest_mem + data); + + args.ret = ibv_query_device(args->context, args->device_attr); +);} void call_ibv_query_port(struct kvm_run * run, uint8_t * guest_mem) { - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); uhyve_ibv_query_port_t * args = (uhyve_ibv_query_port_t *) (guest_mem + data); - int host_ret = ibv_query_port(guest_mem+(size_t)args->context, port_num, guest_mem+(size_t)args->port_attr); - args->ret = host_ret; -} + args.ret = ibv_query_port(args->context, args->port_num, args->port_attr); +);} + +void call____ibv_query_port(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve____ibv_query_port_t * args = (uhyve____ibv_query_port_t *) (guest_mem + data); + + args.ret = ___ibv_query_port(args->context, args->port_num, args->port_attr); +);} + +void call_ibv_query_gid(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_gid_t * args = (uhyve_ibv_query_gid_t *) (guest_mem + data); + + args.ret = ibv_query_gid(args->context, args->port_num, args->index, args->gid); +);} + +void call_ibv_query_pkey(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_pkey_t * args = (uhyve_ibv_query_pkey_t *) (guest_mem + data); + + args.ret = ibv_query_pkey(args->context, args->port_num, args->index, args->pkey); +);} + +void call_ibv_alloc_pd(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_alloc_pd_t * args = (uhyve_ibv_alloc_pd_t *) (guest_mem + data); + + args.ret = ibv_alloc_pd(args->context); +);} + +void call_ibv_dealloc_pd(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_dealloc_pd_t * args = (uhyve_ibv_dealloc_pd_t *) (guest_mem + data); + + args.ret = ibv_dealloc_pd(args->pd); +);} + +void call_ibv_create_flow(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_flow_t * args = (uhyve_ibv_create_flow_t *) (guest_mem + data); + + args.ret = ibv_create_flow(args->qp, args->flow); +);} + +void call_ibv_destroy_flow(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_flow_t * args = (uhyve_ibv_destroy_flow_t *) (guest_mem + data); + + args.ret = ibv_destroy_flow(args->flow_id); +);} + +void call_ibv_open_xrcd(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_open_xrcd_t * args = (uhyve_ibv_open_xrcd_t *) (guest_mem + data); + + args.ret = ibv_open_xrcd(args->context, args->xrcd_init_attr); +);} + +void call_ibv_close_xrcd(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_close_xrcd_t * args = (uhyve_ibv_close_xrcd_t *) (guest_mem + data); + + args.ret = ibv_close_xrcd(args->xrcd); +);} + +void call_ibv_reg_mr(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_reg_mr_t * args = (uhyve_ibv_reg_mr_t *) (guest_mem + data); + + args.ret = ibv_reg_mr(args->pd, args->addr, args->length, args->access); +);} + +void call_ibv_rereg_mr(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_rereg_mr_t * args = (uhyve_ibv_rereg_mr_t *) (guest_mem + data); + + args.ret = ibv_rereg_mr(args->mr, args->flags, args->pd, args->addr, args->length, args->access); +);} + +void call_ibv_dereg_mr(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_dereg_mr_t * args = (uhyve_ibv_dereg_mr_t *) (guest_mem + data); + + args.ret = ibv_dereg_mr(args->mr); +);} + +void call_ibv_alloc_mw(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_alloc_mw_t * args = (uhyve_ibv_alloc_mw_t *) (guest_mem + data); + + args.ret = ibv_alloc_mw(args->pd, args->type); +);} + +void call_ibv_dealloc_mw(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_dealloc_mw_t * args = (uhyve_ibv_dealloc_mw_t *) (guest_mem + data); + + args.ret = ibv_dealloc_mw(args->mw); +);} + +void call_ibv_inc_rkey(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_inc_rkey_t * args = (uhyve_ibv_inc_rkey_t *) (guest_mem + data); + + args.ret = ibv_inc_rkey(args->rkey); +);} + +void call_ibv_bind_mw(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_bind_mw_t * args = (uhyve_ibv_bind_mw_t *) (guest_mem + data); + + args.ret = ibv_bind_mw(args->qp, args->mw, args->mw_bind); +);} void call_ibv_create_comp_channel(struct kvm_run * run, uint8_t * guest_mem) { - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); uhyve_ibv_create_comp_channel_t * args = (uhyve_ibv_create_comp_channel_t *) (guest_mem + data); - struct ibv_comp_channel * host_ret = ibv_create_comp_channel(guest_mem+(size_t)args->context); - memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret)); - // TODO: Convert ptrs contained in return value. - // TODO: Delete host_ret data structure. -} + args.ret = ibv_create_comp_channel(args->context); +);} + +void call_ibv_destroy_comp_channel(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_comp_channel_t * args = (uhyve_ibv_destroy_comp_channel_t *) (guest_mem + data); + + args.ret = ibv_destroy_comp_channel(args->channel); +);} + +void call_ibv_create_cq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_cq_t * args = (uhyve_ibv_create_cq_t *) (guest_mem + data); + + args.ret = ibv_create_cq(args->context, args->cqe, args->cq_context, args->channel, args->comp_vector); +);} + +void call_ibv_create_cq_ex(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_cq_ex_t * args = (uhyve_ibv_create_cq_ex_t *) (guest_mem + data); + + args.ret = ibv_create_cq_ex(args->context, args->cq_attr); +);} + +void call_ibv_resize_cq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_resize_cq_t * args = (uhyve_ibv_resize_cq_t *) (guest_mem + data); + + args.ret = ibv_resize_cq(args->cq, args->cqe); +);} + +void call_ibv_destroy_cq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_cq_t * args = (uhyve_ibv_destroy_cq_t *) (guest_mem + data); + + args.ret = ibv_destroy_cq(args->cq); +);} + +void call_ibv_get_cq_event(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_cq_event_t * args = (uhyve_ibv_get_cq_event_t *) (guest_mem + data); + + args.ret = ibv_get_cq_event(args->channel, args->cq, args->cq_context); +);} + +void call_ibv_ack_cq_events(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_ack_cq_events_t * args = (uhyve_ibv_ack_cq_events_t *) (guest_mem + data); + + ibv_ack_cq_events(args->cq, args->nevents); +);} + +void call_ibv_poll_cq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_poll_cq_t * args = (uhyve_ibv_poll_cq_t *) (guest_mem + data); + + args.ret = ibv_poll_cq(args->cq, args->num_entries, args->wc); +);} + +void call_ibv_req_notify_cq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_req_notify_cq_t * args = (uhyve_ibv_req_notify_cq_t *) (guest_mem + data); + + args.ret = ibv_req_notify_cq(args->cq, args->solicited_only); +);} + +void call_ibv_create_srq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_srq_t * args = (uhyve_ibv_create_srq_t *) (guest_mem + data); + + args.ret = ibv_create_srq(args->pd, args->srq_init_attr); +);} + +void call_ibv_create_srq_ex(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_srq_ex_t * args = (uhyve_ibv_create_srq_ex_t *) (guest_mem + data); + + args.ret = ibv_create_srq_ex(args->context, args->srq_init_attr_ex); +);} + +void call_ibv_modify_srq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_modify_srq_t * args = (uhyve_ibv_modify_srq_t *) (guest_mem + data); + + args.ret = ibv_modify_srq(args->srq, args->srq_attr, args->srq_attr_mask); +);} + +void call_ibv_query_srq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_srq_t * args = (uhyve_ibv_query_srq_t *) (guest_mem + data); + + args.ret = ibv_query_srq(args->srq, args->srq_attr); +);} + +void call_ibv_get_srq_num(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_srq_num_t * args = (uhyve_ibv_get_srq_num_t *) (guest_mem + data); + + args.ret = ibv_get_srq_num(args->srq, args->srq_num); +);} + +void call_ibv_destroy_srq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_srq_t * args = (uhyve_ibv_destroy_srq_t *) (guest_mem + data); + + args.ret = ibv_destroy_srq(args->srq); +);} + +void call_ibv_post_srq_recv(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_post_srq_recv_t * args = (uhyve_ibv_post_srq_recv_t *) (guest_mem + data); + + args.ret = ibv_post_srq_recv(args->srq, args->recv_wr, args->bad_recv_wr); +);} + +void call_ibv_create_qp(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_qp_t * args = (uhyve_ibv_create_qp_t *) (guest_mem + data); + + args.ret = ibv_create_qp(args->pd, args->qp_init_attr); +);} + +void call_ibv_create_qp_ex(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_qp_ex_t * args = (uhyve_ibv_create_qp_ex_t *) (guest_mem + data); + + args.ret = ibv_create_qp_ex(args->context, args->qp_init_attr_ex); +);} + +void call_ibv_query_rt_values_ex(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_rt_values_ex_t * args = (uhyve_ibv_query_rt_values_ex_t *) (guest_mem + data); + + args.ret = ibv_query_rt_values_ex(args->context, args->values); +);} + +void call_ibv_query_device_ex(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_device_ex_t * args = (uhyve_ibv_query_device_ex_t *) (guest_mem + data); + + args.ret = ibv_query_device_ex(args->context, args->input, args->attr); +);} + +void call_ibv_open_qp(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_open_qp_t * args = (uhyve_ibv_open_qp_t *) (guest_mem + data); + + args.ret = ibv_open_qp(args->context, args->qp_open_attr); +);} + +void call_ibv_modify_qp(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_modify_qp_t * args = (uhyve_ibv_modify_qp_t *) (guest_mem + data); + + args.ret = ibv_modify_qp(args->qp, args->attr, args->attr_mask); +);} + +void call_ibv_query_qp(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_qp_t * args = (uhyve_ibv_query_qp_t *) (guest_mem + data); + + args.ret = ibv_query_qp(args->qp, args->attr, args->attr_mask, args->init_attr); +);} + +void call_ibv_destroy_qp(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_qp_t * args = (uhyve_ibv_destroy_qp_t *) (guest_mem + data); + + args.ret = ibv_destroy_qp(args->qp); +);} + +void call_ibv_create_wq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_wq_t * args = (uhyve_ibv_create_wq_t *) (guest_mem + data); + + args.ret = ibv_create_wq(args->context, args->wq_init_attr); +);} + +void call_ibv_modify_wq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_modify_wq_t * args = (uhyve_ibv_modify_wq_t *) (guest_mem + data); + + args.ret = ibv_modify_wq(args->wq, args->wq_attr); +);} + +void call_ibv_destroy_wq(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_wq_t * args = (uhyve_ibv_destroy_wq_t *) (guest_mem + data); + + args.ret = ibv_destroy_wq(args->wq); +);} + +void call_ibv_create_rwq_ind_table(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_rwq_ind_table_t * args = (uhyve_ibv_create_rwq_ind_table_t *) (guest_mem + data); + + args.ret = ibv_create_rwq_ind_table(args->context, args->init_attr); +);} + +void call_ibv_destroy_rwq_ind_table(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_rwq_ind_table_t * args = (uhyve_ibv_destroy_rwq_ind_table_t *) (guest_mem + data); + + args.ret = ibv_destroy_rwq_ind_table(args->rwq_ind_table); +);} + +void call_ibv_post_send(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_post_send_t * args = (uhyve_ibv_post_send_t *) (guest_mem + data); + + args.ret = ibv_post_send(args->qp, args->wr, args->bad_wr); +);} + +void call_ibv_post_recv(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_post_recv_t * args = (uhyve_ibv_post_recv_t *) (guest_mem + data); + + args.ret = ibv_post_recv(args->qp, args->wr, args->bad_wr); +);} + +void call_ibv_create_ah(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_ah_t * args = (uhyve_ibv_create_ah_t *) (guest_mem + data); + + args.ret = ibv_create_ah(args->pd, args->attr); +);} + +void call_ibv_init_ah_from_wc(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_init_ah_from_wc_t * args = (uhyve_ibv_init_ah_from_wc_t *) (guest_mem + data); + + args.ret = ibv_init_ah_from_wc(args->context, args->port_num, args->wc, args->grh, args->ah_attr); +);} + +void call_ibv_create_ah_from_wc(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_ah_from_wc_t * args = (uhyve_ibv_create_ah_from_wc_t *) (guest_mem + data); + + args.ret = ibv_create_ah_from_wc(args->pd, args->wc, args->grh, args->port_num); +);} + +void call_ibv_destroy_ah(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_ah_t * args = (uhyve_ibv_destroy_ah_t *) (guest_mem + data); + + args.ret = ibv_destroy_ah(args->ah); +);} + +void call_ibv_attach_mcast(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_attach_mcast_t * args = (uhyve_ibv_attach_mcast_t *) (guest_mem + data); + + args.ret = ibv_attach_mcast(args->qp, args->gid, args->lid); +);} + +void call_ibv_detach_mcast(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_detach_mcast_t * args = (uhyve_ibv_detach_mcast_t *) (guest_mem + data); + + args.ret = ibv_detach_mcast(args->qp, args->gid, args->lid); +);} + +void call_ibv_fork_init(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_fork_init_t * args = (uhyve_ibv_fork_init_t *) (guest_mem + data); + + args.ret = ibv_fork_init(args->); +);} + +void call_ibv_node_type_str(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_node_type_str_t * args = (uhyve_ibv_node_type_str_t *) (guest_mem + data); + + const char * host_ret = ibv_node_type_str(args->node_type); +);memcpy(args->ret, host_ret, sizeof(host_ret));} + +void call_ibv_port_state_str(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_port_state_str_t * args = (uhyve_ibv_port_state_str_t *) (guest_mem + data); + + const char * host_ret = ibv_port_state_str(args->port_state); +);memcpy(args->ret, host_ret, sizeof(host_ret));} + +void call_ibv_event_type_str(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_event_type_str_t * args = (uhyve_ibv_event_type_str_t *) (guest_mem + data); + + const char * host_ret = ibv_event_type_str(args->event); +);memcpy(args->ret, host_ret, sizeof(host_ret));} + +void call_ibv_resolve_eth_l2_from_gid(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_resolve_eth_l2_from_gid_t * args = (uhyve_ibv_resolve_eth_l2_from_gid_t *) (guest_mem + data); + + args.ret = ibv_resolve_eth_l2_from_gid(args->context, args->attr, args->eth_mac[6], args->vid); +);} + +void call_ibv_is_qpt_supported(struct kvm_run * run, uint8_t * guest_mem) { + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_is_qpt_supported_t * args = (uhyve_ibv_is_qpt_supported_t *) (guest_mem + data); + + args.ret = ibv_is_qpt_supported(args->caps, args->qpt); +);} + diff --git a/tools/ibv_code_generator/GEN-tools-uhyve.c b/tools/ibv_code_generator/GEN-tools-uhyve.c index 845868592..abe792cf8 100644 --- a/tools/ibv_code_generator/GEN-tools-uhyve.c +++ b/tools/ibv_code_generator/GEN-tools-uhyve.c @@ -1,12 +1,231 @@ - case UHYVE_PORT_IBV_OPEN_DEVICE: - call_ibv_open_device(run, guest_mem); + case UHYVE_PORT_IBV_WC_STATUS_STR: + call_ibv_wc_status_str(run, guest_mem); + break; + case UHYVE_PORT_IBV_RATE_TO_MULT: + call_ibv_rate_to_mult(run, guest_mem); + break; + case UHYVE_PORT_MULT_TO_IBV_RATE: + call_mult_to_ibv_rate(run, guest_mem); + break; + case UHYVE_PORT_IBV_RATE_TO_MBPS: + call_ibv_rate_to_mbps(run, guest_mem); + break; + case UHYVE_PORT_MBPS_TO_IBV_RATE: + call_mbps_to_ibv_rate(run, guest_mem); + break; + case UHYVE_PORT_IBV_POST_WQ_RECV: + call_ibv_post_wq_recv(run, guest_mem); + break; + case UHYVE_PORT_VERBS_GET_CTX: + call_verbs_get_ctx(run, guest_mem); + break; + case UHYVE_PORT_IBV_GET_DEVICE_LIST: + call_ibv_get_device_list(run, guest_mem); + break; + case UHYVE_PORT_IBV_FREE_DEVICE_LIST: + call_ibv_free_device_list(run, guest_mem); break; case UHYVE_PORT_IBV_GET_DEVICE_NAME: call_ibv_get_device_name(run, guest_mem); break; + case UHYVE_PORT_IBV_GET_DEVICE_GUID: + call_ibv_get_device_guid(run, guest_mem); + break; + case UHYVE_PORT_IBV_OPEN_DEVICE: + call_ibv_open_device(run, guest_mem); + break; + case UHYVE_PORT_IBV_CLOSE_DEVICE: + call_ibv_close_device(run, guest_mem); + break; + case UHYVE_PORT_IBV_GET_ASYNC_EVENT: + call_ibv_get_async_event(run, guest_mem); + break; + case UHYVE_PORT_IBV_ACK_ASYNC_EVENT: + call_ibv_ack_async_event(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_DEVICE: + call_ibv_query_device(run, guest_mem); + break; case UHYVE_PORT_IBV_QUERY_PORT: call_ibv_query_port(run, guest_mem); break; + case UHYVE_PORT____IBV_QUERY_PORT: + call____ibv_query_port(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_GID: + call_ibv_query_gid(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_PKEY: + call_ibv_query_pkey(run, guest_mem); + break; + case UHYVE_PORT_IBV_ALLOC_PD: + call_ibv_alloc_pd(run, guest_mem); + break; + case UHYVE_PORT_IBV_DEALLOC_PD: + call_ibv_dealloc_pd(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_FLOW: + call_ibv_create_flow(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_FLOW: + call_ibv_destroy_flow(run, guest_mem); + break; + case UHYVE_PORT_IBV_OPEN_XRCD: + call_ibv_open_xrcd(run, guest_mem); + break; + case UHYVE_PORT_IBV_CLOSE_XRCD: + call_ibv_close_xrcd(run, guest_mem); + break; + case UHYVE_PORT_IBV_REG_MR: + call_ibv_reg_mr(run, guest_mem); + break; + case UHYVE_PORT_IBV_REREG_MR: + call_ibv_rereg_mr(run, guest_mem); + break; + case UHYVE_PORT_IBV_DEREG_MR: + call_ibv_dereg_mr(run, guest_mem); + break; + case UHYVE_PORT_IBV_ALLOC_MW: + call_ibv_alloc_mw(run, guest_mem); + break; + case UHYVE_PORT_IBV_DEALLOC_MW: + call_ibv_dealloc_mw(run, guest_mem); + break; + case UHYVE_PORT_IBV_INC_RKEY: + call_ibv_inc_rkey(run, guest_mem); + break; + case UHYVE_PORT_IBV_BIND_MW: + call_ibv_bind_mw(run, guest_mem); + break; case UHYVE_PORT_IBV_CREATE_COMP_CHANNEL: call_ibv_create_comp_channel(run, guest_mem); break; + case UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL: + call_ibv_destroy_comp_channel(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_CQ: + call_ibv_create_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_CQ_EX: + call_ibv_create_cq_ex(run, guest_mem); + break; + case UHYVE_PORT_IBV_RESIZE_CQ: + call_ibv_resize_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_CQ: + call_ibv_destroy_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_GET_CQ_EVENT: + call_ibv_get_cq_event(run, guest_mem); + break; + case UHYVE_PORT_IBV_ACK_CQ_EVENTS: + call_ibv_ack_cq_events(run, guest_mem); + break; + case UHYVE_PORT_IBV_POLL_CQ: + call_ibv_poll_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_REQ_NOTIFY_CQ: + call_ibv_req_notify_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_SRQ: + call_ibv_create_srq(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_SRQ_EX: + call_ibv_create_srq_ex(run, guest_mem); + break; + case UHYVE_PORT_IBV_MODIFY_SRQ: + call_ibv_modify_srq(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_SRQ: + call_ibv_query_srq(run, guest_mem); + break; + case UHYVE_PORT_IBV_GET_SRQ_NUM: + call_ibv_get_srq_num(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_SRQ: + call_ibv_destroy_srq(run, guest_mem); + break; + case UHYVE_PORT_IBV_POST_SRQ_RECV: + call_ibv_post_srq_recv(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_QP: + call_ibv_create_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_QP_EX: + call_ibv_create_qp_ex(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_RT_VALUES_EX: + call_ibv_query_rt_values_ex(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_DEVICE_EX: + call_ibv_query_device_ex(run, guest_mem); + break; + case UHYVE_PORT_IBV_OPEN_QP: + call_ibv_open_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_MODIFY_QP: + call_ibv_modify_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_QP: + call_ibv_query_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_QP: + call_ibv_destroy_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_WQ: + call_ibv_create_wq(run, guest_mem); + break; + case UHYVE_PORT_IBV_MODIFY_WQ: + call_ibv_modify_wq(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_WQ: + call_ibv_destroy_wq(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_RWQ_IND_TABLE: + call_ibv_create_rwq_ind_table(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_RWQ_IND_TABLE: + call_ibv_destroy_rwq_ind_table(run, guest_mem); + break; + case UHYVE_PORT_IBV_POST_SEND: + call_ibv_post_send(run, guest_mem); + break; + case UHYVE_PORT_IBV_POST_RECV: + call_ibv_post_recv(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_AH: + call_ibv_create_ah(run, guest_mem); + break; + case UHYVE_PORT_IBV_INIT_AH_FROM_WC: + call_ibv_init_ah_from_wc(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_AH_FROM_WC: + call_ibv_create_ah_from_wc(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_AH: + call_ibv_destroy_ah(run, guest_mem); + break; + case UHYVE_PORT_IBV_ATTACH_MCAST: + call_ibv_attach_mcast(run, guest_mem); + break; + case UHYVE_PORT_IBV_DETACH_MCAST: + call_ibv_detach_mcast(run, guest_mem); + break; + case UHYVE_PORT_IBV_FORK_INIT: + call_ibv_fork_init(run, guest_mem); + break; + case UHYVE_PORT_IBV_NODE_TYPE_STR: + call_ibv_node_type_str(run, guest_mem); + break; + case UHYVE_PORT_IBV_PORT_STATE_STR: + call_ibv_port_state_str(run, guest_mem); + break; + case UHYVE_PORT_IBV_EVENT_TYPE_STR: + call_ibv_event_type_str(run, guest_mem); + break; + case UHYVE_PORT_IBV_RESOLVE_ETH_L2_FROM_GID: + call_ibv_resolve_eth_l2_from_gid(run, guest_mem); + break; + case UHYVE_PORT_IBV_IS_QPT_SUPPORTED: + call_ibv_is_qpt_supported(run, guest_mem); + break; diff --git a/tools/ibv_code_generator/function-prototypes.txt b/tools/ibv_code_generator/function-prototypes.txt index b57d7c34e..82dc96885 100644 --- a/tools/ibv_code_generator/function-prototypes.txt +++ b/tools/ibv_code_generator/function-prototypes.txt @@ -3,25 +3,6 @@ int ibv_rate_to_mult(enum ibv_rate rate) enum ibv_rate mult_to_ibv_rate(int mult) int ibv_rate_to_mbps(enum ibv_rate rate) enum ibv_rate mbps_to_ibv_rate(int mbps) -struct ibv_cq * ibv_cq_ex_to_cq(struct ibv_cq_ex * cq) -int ibv_start_poll(struct ibv_cq_ex * cq,struct ibv_poll_cq_attr * attr) -int ibv_next_poll(struct ibv_cq_ex * cq) -void ibv_end_poll(struct ibv_cq_ex * cq) -enum ibv_wc_opcode ibv_wc_read_opcode(struct ibv_cq_ex * cq) -uint32_t ibv_wc_read_vendor_err(struct ibv_cq_ex * cq) -uint32_t ibv_wc_read_byte_len(struct ibv_cq_ex * cq) -__be32 ibv_wc_read_imm_data(struct ibv_cq_ex * cq) -uint32_t ibv_wc_read_invalidated_rkey(struct ibv_cq_ex * cq) -uint32_t ibv_wc_read_qp_num(struct ibv_cq_ex * cq) -uint32_t ibv_wc_read_src_qp(struct ibv_cq_ex * cq) -int ibv_wc_read_wc_flags(struct ibv_cq_ex * cq) -uint32_t ibv_wc_read_slid(struct ibv_cq_ex * cq) -uint8_t ibv_wc_read_sl(struct ibv_cq_ex * cq) -uint8_t ibv_wc_read_dlid_path_bits(struct ibv_cq_ex * cq) -uint64_t ibv_wc_read_completion_ts(struct ibv_cq_ex * cq) -uint16_t ibv_wc_read_cvlan(struct ibv_cq_ex * cq) -uint32_t ibv_wc_read_flow_tag(struct ibv_cq_ex * cq) -int ibv_post_wq_recv(struct ibv_wq * wq,struct ibv_recv_wr * recv_wr,struct ibv_recv_wr ** bad_recv_wr) struct verbs_context * verbs_get_ctx(struct ibv_context * ctx) struct ibv_device ** ibv_get_device_list(int * num_devices) void ibv_free_device_list(struct ibv_device ** list) @@ -52,7 +33,6 @@ int ibv_bind_mw(struct ibv_qp * qp,struct ibv_mw * mw,struct ibv_mw_bind * mw_bi struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context) int ibv_destroy_comp_channel(struct ibv_comp_channel * channel) struct ibv_cq * ibv_create_cq(struct ibv_context * context,int cqe,void * cq_context,struct ibv_comp_channel * channel,int comp_vector) -struct ibv_cq_ex * ibv_create_cq_ex(struct ibv_context * context,struct ibv_cq_init_attr_ex * cq_attr) int ibv_resize_cq(struct ibv_cq * cq,int cqe) int ibv_destroy_cq(struct ibv_cq * cq) int ibv_get_cq_event(struct ibv_comp_channel * channel,struct ibv_cq ** cq,void ** cq_context) @@ -68,17 +48,11 @@ int ibv_destroy_srq(struct ibv_srq * srq) int ibv_post_srq_recv(struct ibv_srq * srq,struct ibv_recv_wr * recv_wr,struct ibv_recv_wr ** bad_recv_wr) struct ibv_qp * ibv_create_qp(struct ibv_pd * pd,struct ibv_qp_init_attr * qp_init_attr) struct ibv_qp * ibv_create_qp_ex(struct ibv_context * context,struct ibv_qp_init_attr_ex * qp_init_attr_ex) -int ibv_query_rt_values_ex(struct ibv_context * context,struct ibv_values_ex * values) int ibv_query_device_ex(struct ibv_context * context,const struct ibv_query_device_ex_input * input,struct ibv_device_attr_ex * attr) struct ibv_qp * ibv_open_qp(struct ibv_context * context,struct ibv_qp_open_attr * qp_open_attr) int ibv_modify_qp(struct ibv_qp * qp,struct ibv_qp_attr * attr,int attr_mask) int ibv_query_qp(struct ibv_qp * qp,struct ibv_qp_attr * attr,int attr_mask,struct ibv_qp_init_attr * init_attr) int ibv_destroy_qp(struct ibv_qp * qp) -struct ibv_wq * ibv_create_wq(struct ibv_context * context,struct ibv_wq_init_attr * wq_init_attr) -int ibv_modify_wq(struct ibv_wq * wq,struct ibv_wq_attr * wq_attr) -int ibv_destroy_wq(struct ibv_wq * wq) -struct ibv_rwq_ind_table * ibv_create_rwq_ind_table(struct ibv_context * context,struct ibv_rwq_ind_table_init_attr * init_attr) -int ibv_destroy_rwq_ind_table(struct ibv_rwq_ind_table * rwq_ind_table) int ibv_post_send(struct ibv_qp * qp,struct ibv_send_wr * wr,struct ibv_send_wr ** bad_wr) int ibv_post_recv(struct ibv_qp * qp,struct ibv_recv_wr * wr,struct ibv_recv_wr ** bad_wr) struct ibv_ah * ibv_create_ah(struct ibv_pd * pd,struct ibv_ah_attr * attr) @@ -91,5 +65,4 @@ int ibv_fork_init() const char * ibv_node_type_str(enum ibv_node_type node_type) const char * ibv_port_state_str(enum ibv_port_state port_state) const char * ibv_event_type_str(enum ibv_event_type event) -int ibv_resolve_eth_l2_from_gid(struct ibv_context * context,struct ibv_ah_attr * attr,uint8_t [6] eth_mac,uint16_t * vid) int ibv_is_qpt_supported(uint32_t caps,enum ibv_qp_type qpt) diff --git a/tools/ibv_code_generator/generate-code.py b/tools/ibv_code_generator/generate-code.py index 9add6f23e..3ecb3c761 100755 --- a/tools/ibv_code_generator/generate-code.py +++ b/tools/ibv_code_generator/generate-code.py @@ -92,14 +92,15 @@ from parser import generate_struct_conversions # Path of the input file containing function prototypes. -SRC_PATH = "function-prototypes-0.txt" +SRC_PATH = "function-prototypes.txt" # Paths of the files that are generated by the script. -IBV_GEN_PATH = "GEN-kernel-ibv.c" +KERNEL_GEN_PATH = "GEN-kernel.c" +KERNEL_HEADER_GEN_PATH = "GEN-kernel-header.h" UHYVE_CASES_GEN_PATH = "GEN-tools-uhyve.c" UHYVE_IBV_HEADER_GEN_PATH = "GEN-tools-uhyve-ibv-ports.h" INCLUDE_STDDEF_GEN_PATH = "GEN-include-hermit-stddef.h" -UHYVE_IBV_HEADER_STRUCTS_GEN_PATH = "GEN-tools-uhyve-ibv-structs.h" +# UHYVE_IBV_HEADER_STRUCTS_GEN_PATH = "GEN-tools-uhyve-ibv-structs.h" UHYVE_HOST_FCNS_GEN_PATH = "GEN-tools-uhyve-ibv.c" # VERBS_HEADER_PATH = "verbs-0.h" @@ -112,8 +113,12 @@ NEWLINES = ["", "\n", "\n\n"] class Type: def __init__(self, string): ts = string - if (string[-1] is "*") and (string[-2] is not " "): - ts = string[:-1] + " *" + + # if len(string) > 2 and string[-1] is "*": + # if string[-2] is "*" and string[-3] is not " ": + # ts = string[:-2] + " **" + # elif string[-2] is not " ": + # ts = string[:-1] + " *" self.type_string = ts self.type_components = ts.split(" ") @@ -127,9 +132,15 @@ class Type: def is_struct(self): return self.type_components[0] == "struct" + def is_char_arr(self): + return self.is_pointer() and "char" in self.type_components + def is_pointer(self): return self.type_components[-1] == "*" + def is_pointer_pointer(self): + return self.type_components[-1] == "**" + def is_void(self): return self.type_string == "void" @@ -139,10 +150,12 @@ class FunctionParameter: components = string.split(" ") type_string = " ".join(components[:-1]) + # print("string in FunctionParameter: ", string) + self.type = Type(type_string) self.name = components[-1] - def get_full_expression: + def get_full_expression(self): return self.type.type_string + " " + self.name def get_struct_name(self): @@ -154,6 +167,9 @@ class FunctionParameter: def is_pointer(self): return self.type.is_pointer() + def is_pointer_pointer(self): + return self.type.is_pointer_pointer() + class FunctionPrototype: def __init__(self, string): @@ -166,33 +182,40 @@ class FunctionPrototype: self.ret = Type(" ".join(ret_and_name[:-1])) self.function_name = ret_and_name[-1] - def generate_args_struct(ret, function_name, params): + def generate_args_struct(self): """Generates the struct to hold a function's parameters and return value. - Args: - ret: Return type as string. - function_name: Function name as string. - params: Parameters as list of strings. - Returns: Generated struct as string. """ - code = "" code = "typedef struct {\n" - if self.get_num_parameters() > 0: - code += "\t// Parameters:\n" - for param in self.parameters: - code += "\t{0};\n".format(param.get_full_expression()) + code += "\t// Parameters:\n" + for param in self.parameters or []: + code += "\t{0};\n".format(param.get_full_expression()) if not self.ret.is_void(): code += "\t// Return value:\n" code += "\t{0} ret;\n".format(self.ret.type_string) - code += "}} __attribute__((packed)) {0};\n\n".format( self.get_args_struct_name()) + code += "}} __attribute__((packed)) {0};\n\n".format(self.get_args_struct_name()) return code + def generate_function_declaration(self): + return "{} {}({});\n".format(self.ret.type_string, self.function_name, + self.get_string_of_parameters()) + + def get_string_of_parameters(self): + return ", ".join([param.get_full_expression() for param in self.parameters]) + + def generate_uhyve_function_declaration(self): + name = self.get_uhyve_call_function_name() + return "void {0}(struct kvm_run * run, uint8_t * guest_mem);\n".format(name) + + def get_uhyve_call_function_name(self): + return "call_{0}".format(self.function_name) + def get_num_parameters(self): return len(self.parameters) @@ -210,131 +233,47 @@ class FunctionPrototype: # ----------------------------------------------------------------------------- +def generate_pretty_comment(string): + return "/*\n * {0}\n */\n\n".format(string) -# def get_struct_name(function_name): - # """Returns the matching struct name for a given function name. - # """ - # return "uhyve_{0}_t".format(function_name) +def generate_kernel_header_declarations(function_prototypes): + code = "" + for pt in function_prototypes: + code += pt.generate_function_declaration() + return code -# def parse_line(line): - # """Parses a line containing a function prototype. - - # Args: - # line: Line of the following format: - # ( , [...]) - - # Returns: - # [Return type, function name, parameters] as Tuple[string, string, list[string]] - # """ - # parens_split = line.split("(") - - # ret_and_name = parens_split[0].split(" ") - # all_params = parens_split[-1][:-1] - - # ret = " ".join(ret_and_name[:-1]) - # function_name = ret_and_name[-1] - - # params = all_params.split(",") - # params[-1] = params[-1][:-1] - - # return ret, function_name, params - - -# def generate_struct(ret, function_name, params): - # """Generates the struct to hold a function's parameters and return value. - - # Args: - # ret: Return type as string. - # function_name: Function name as string. - # params: Parameters as list of strings. - - # Returns: - # Generated struct as string. - # """ - # struct = "typedef struct {\n" - # if params: - # struct += "\t// Parameters:\n" - # for param in params: - # struct += "\t{0};\n".format(param) - - # if ret is not "void": - # struct += "\t// Return value:\n" - # struct += "\t{0} ret;\n".format(ret) - - # struct_name = get_struct_name(function_name) - # struct += "}} __attribute__((packed)) {0};\n\n".format(struct_name) - - # return struct - -# TODO: hier gehts weiter -def generate_kernel_function(ret, function_name, params): +def generate_kernel_function(function_prototype): """Generates the kernel function that sends the KVM exit IO to uhyve. - Args: - ret: Return type as string. - function_name: Function name as string. - params: Parameters as list of strings. - Returns: Generated function as string. """ - code = "" + fnc_name = function_prototype.function_name + ret_type = function_prototype.ret + params = function_prototype.parameters + port_name = function_prototype.get_port_name() - code = "{0} {1}({2}) {{\n".format(ret, function_name, ", ".join(params)) + comma_separated_params = function_prototype.get_string_of_parameters() + code = "{0} {1}({2}) {{\n".format(ret_type.type_string, fnc_name, comma_separated_params) + code += "\t{0} uhyve_args;\n".format(function_prototype.get_args_struct_name()) - # Create uhyve_args and define parameters - struct_name = get_struct_name(function_name) - code += "\t{0} ret_guest;\n".format(ret) - code += "\t{0} uhyve_args;\n".format(struct_name) - - # TODO: Make a class for function prototypes - for param in params: - param_split = param.split(" ") - param_type = " ".join(param_split[:-1]) - param_name = param_split[-1] - - # Define struct members according to their type. - if "**" in param_type: + for p in params or []: + if p.is_pointer_pointer(): code += "\t// TODO: Take care of ** parameter.\n" - elif "*" in param_type: - # TODO: char ptrs - code += "\tuhyve_args.{0} = guest_to_host_{1}({2});\n".format(param_name, - param_split[1]) else: - code += "\tuhyve_args,{0} = {0};\n".format(param_name) + code += "\tuhyve_args.{0} = {0};\n".format(p.name) + code += "\n" - # call uhyve_send() using the respective port ID. - port_name = "UHYVE_PORT_" + function_name.upper() - code += "\n\tuhyve_send({0}, (unsigned) virt_to_phys((size_t) " \ - "&uhyve_args));\n\n".format(port_name) - - for param in params: - param_split = param.split(" ") - param_type = " ".join(param_split[:-1]) - param_name = param_split[-1] - - # Define struct members according to their type. - if "**" in param_type: - code += "\t// TODO: Take care of ** parameter.\n" - elif "*" in param_type: - code += "\thost_to_guest_{0}({1}, GUEST);".format(param_split[1], param_name) - - if "**" in ret: - code += "\t// TODO: Take care of ** parameter.\n" - elif "*" in ret: - code += "\tret_guest = host_to_guest_{0}(uhyve_args.ret, HOST)\n".format(ret[1]) - else: - code += "\tret_guest = uhyve_args.ret;\n" - - code += "\n\treturn ret_guest;\n" - code += "}\n\n\n" + code += "\tuhyve_send({0}, (unsigned) virt_to_phys((size_t) &uhyve_args));\n".format(port_name) + if not ret_type.is_void(): + code += "\n\treturn uhyve_args.ret;\n" + code += "}\n\n" return code -# TODO: done def generate_uhyve_cases(function_prototypes): """ Generates all switch-cases for uhyve's KVM exit IO. @@ -342,100 +281,73 @@ def generate_uhyve_cases(function_prototypes): Generated switch-cases [string] """ code = "" - for pt in function_prototypes: - name = pt.function_name + call_fnc_name = pt.get_uhyve_call_function_name() port_name = pt.get_port_name() - code += "{0}{1}case {2}:".format(NEWLINES[1], TABS[3], port_name) - code += "{0}{1}call_{2}(run, guest_mem);".format(NEWLINES[1], TABS[4], name) - code += "{0}{1}break;".format(NEWLINES[1], TABS[4]) + code += "\t\t\tcase {0}:\n".format(port_name) + code += "\t\t\t\t{0}(run, guest_mem);\n".format(call_fnc_name) + code += "\t\t\t\tbreak;\n" + + return code + + # const char * host_ret = ibv_wc_status_str(args->status); // ! + # memcpy(args->ret, host_ret, sizeof(host_ret)); // ! + +def generate_uhyve_function(prototype): + args_struct_name = prototype.get_args_struct_name() + fnc_name = prototype.function_name + ret_type = prototype.ret + + code = "void call_{0}(struct kvm_run * run, uint8_t * guest_mem) {{\n".format(fnc_name) + code += "\tunsigned data = *((unsigned*) ((size_t) run + run->io.data_offset));\n" + code += "\t{0} * args = ({0} *) (guest_mem + data);\n\n".format(args_struct_name) + + if prototype.ret.is_pointer_pointer(): + code += "\t// TODO: Take care of ** here.\n" + else: + code += "\t" + if not ret_type.is_void(): + if ret_type.is_char_arr(): + code += "const char * host_ret = " + else: + code += "args.ret = " + code += "{0}(".format(fnc_name) + + if prototype.get_num_parameters() > 0: + for param in prototype.parameters[:-1] or []: + code += "args->{}, ".format(param.name) + code += "args->{});\n".format(prototype.parameters[-1].name) + code += ");" + + if ret_type.is_char_arr(): + code += "memcpy(args->ret, host_ret, sizeof(host_ret));" + + + code += "}\n\n" return code -# TODO: hier gehts weiter -def generate_uhyve_host_function(ret, function_name, params): - """Generates a switch-case that catches a KVM exit IO for the given function in uhyve. - - Args: - ret: Return type as string. - function_name: Function name as string. - params: Parameters as list of strings. - - Returns: - Generated switch-case code as string. - """ - - def generate_host_call_parameter(param): - """Generates the parameter for the host's function called from within uhyve. - - This distinguishes between pointers and non-pointers since pointers have to - be converted to host memory addresses. - Example for pointer: guest_mem+(size_t)args->param - Example for non-pointer: args->param - - Args: - param: The parameter type and name as a single string. - - Returns: - Generated parameter, - """ - param_name = param.split(" ")[-1] - if "**" in param: - host_param = "/* TODO: param {0}*/".format(param_name) - elif "*" in param: - host_param = "guest_mem+(size_t)args->{0}".format(param_name) - else: - host_param = "{0}".format(param_name) - - return host_param - - struct_name = get_struct_name(function_name) - - fcn = "{0}void call_{1}(struct kvm_run * run, uint8_t * guest_mem) {{".format(NEWLINES[1], function_name) - fcn += "{0}{1}unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));".format(NEWLINES[1], TABS[1]) - fcn += "{0}{1}{2} * args = ({2} *) (guest_mem + data);".format(NEWLINES[1], TABS[1], struct_name) - fcn += "{0}{1}{2} host_ret = {3}(".format(NEWLINES[2], TABS[1], ret, function_name) - - for param in params[:-1]: - fcn += generate_host_call_parameter(param) + ", " - else: - fcn += generate_host_call_parameter(params[-1]) + ");" - - if "**" in ret: - fcn += "{0}{1}// TODO: Take care of {2} return value.".format(NEWLINES[1], TABS[1], ret) - elif "*" in ret: - fcn += "{0}{1}memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));".format(NEWLINES[1], TABS[1]) - fcn += "{0}{1}// TODO: Convert ptrs contained in return value.".format(NEWLINES[1], TABS[1]) - fcn += "{0}{1}// TODO: Delete host_ret data structure.".format(NEWLINES[1], TABS[1]) - else: - fcn += "{0}{1}args->ret = host_ret;".format(NEWLINES[1], TABS[1]) - - fcn += "{0}}}{0}".format(NEWLINES[1]) - - return fcn - - -def generate_port_enum(function_names): +def generate_port_enum(function_prototypes): """Generates the enum mapping KVM exit IO port names to port numbers. Args: - function_names: All function names to be mapped to ports as list of strings. + function_prototypes: All function names to be mapped to ports as list of strings. Returns: Generated complete enum. """ - port_enum = "typedef enum {" - for num, function_name in enumerate(function_names, PORT_NUMBER_START): - port_enum += "\n\tUHYVE_PORT_{0} = 0x{1},".format(function_name.upper(), - format(num, "X")) - port_enum += "\n} uhyve_ibv_t;" + code = "typedef enum {\n" + for num, pt in enumerate(function_prototypes, PORT_NUMBER_START): + port_name = pt.get_port_name() + code += "\t{0} = 0x{1},\n".format(port_name, format(num, "X")) + code += "} uhyve_ibv_t;" - return port_enum + return code -def generate_port_macros(function_names): +def generate_port_macros(function_prototypes): """Generates the compiler macros mapping KVM exit IO port names to port numbers. Args: @@ -444,47 +356,47 @@ def generate_port_macros(function_names): Returns: Generated list of compiler macros. """ - macros = "" - for num, function_name in enumerate(function_names, PORT_NUMBER_START): - macros += "\n#define UHYVE_PORT_{0} 0x{1}".format(function_name.upper(), - format(num, "X")) - return macros - + code = "" + for num, pt in enumerate(function_prototypes, PORT_NUMBER_START): + port_name = pt.get_port_name() + code += "#define {0} 0x{1}\n".format(port_name, format(num, "X")) + return code if __name__ == "__main__": - """TODO: Doc - """ - with open(SRC_PATH, "r") as f_src, \ - open(IBV_GEN_PATH, "w") as f_ibv, \ - open(UHYVE_HOST_FCNS_GEN_PATH, "w") as f_uhyve_host_fncs, \ - open(UHYVE_IBV_HEADER_STRUCTS_GEN_PATH, "w") as f_structs: - function_names = [] - # Make this like the structure below. - for line in f_src: - ret, function_name, params = parse_line(line) - function_names.append(function_name) + prototypes = [] - struct = generate_struct(ret, function_name, params) - f_ibv.write(struct) - f_structs.write(struct) + with open(SRC_PATH, "r") as f: + for line in f: + if line: + prototypes.append(FunctionPrototype(line)) - kernel_function = generate_kernel_function(ret, function_name, params) - f_ibv.write(kernel_function) + with open(UHYVE_CASES_GEN_PATH, "w") as f: + f.write(generate_uhyve_cases(prototypes)) - uhyve_fnc = generate_uhyve_host_function(ret, function_name, params) - f_uhyve_host_fncs.write(uhyve_fnc) + with open(INCLUDE_STDDEF_GEN_PATH, "w") as f: + f.write(generate_port_macros(prototypes)) - with open(UHYVE_IBV_HEADER_GEN_PATH, "w") as f_uhyve_ibv: - port_enum = generate_port_enum(function_names) - f_uhyve_ibv.write(port_enum) + with open(UHYVE_IBV_HEADER_GEN_PATH, "w") as f: + f.write(generate_port_enum(prototypes)) + f.write("\n\n") - with open(UHYVE_CASES_GEN_PATH, "w") as f_cases: - uhyve_cases = generate_uhyve_cases(function_names) - f_cases.write(uhyve_cases) + for pt in prototypes: + f.write(pt.generate_args_struct()) + f.write("\n\n") - with open(INCLUDE_STDDEF_GEN_PATH, "w") as f_stddef: - port_macros = generate_port_macros(function_names) - f_stddef.write(port_macros) + for pt in prototypes: + f.write(pt.generate_uhyve_function_declaration()) - generate_struct_conversions() + with open(UHYVE_HOST_FCNS_GEN_PATH, "w") as f: + for pt in prototypes: + f.write(generate_uhyve_function(pt)) + with open(KERNEL_HEADER_GEN_PATH, "w") as f: + f.write(generate_kernel_header_declarations(prototypes)) + + with open(KERNEL_GEN_PATH, "w") as f: + for pt in prototypes: + f.write(generate_pretty_comment(pt.function_name)) + f.write(pt.generate_args_struct()) + f.write(generate_kernel_function(pt)) + f.write("\n") diff --git a/tools/uhyve-ibv.c b/tools/uhyve-ibv.c index 6b8366bb3..5a07ad9c1 100644 --- a/tools/uhyve-ibv.c +++ b/tools/uhyve-ibv.c @@ -37,100 +37,555 @@ * ibv_get_device_list */ -void call_ibv_get_device_list(struct kvm_run * run, uint8_t * guest_mem) { - printf("LOG: UHYVE - call_ibv_get_device_list\n"); - - printf("temp check 1\n"); - int * temp = malloc(sizeof(int)); - *temp = 42; - free(temp); - - ib_malloc = true; - unsigned data = *((unsigned *)((size_t)run+run->io.data_offset)); +void call_ibv_get_device_list(struct kvm_run * run, uint8_t * guest_mem) { // ! + printf("UHYVE call: call_ibv_get_device_list\n"); + unsigned data = *((unsigned *) ((size_t) run + run->io.data_offset)); uhyve_ibv_get_device_list_t * args = (uhyve_ibv_get_device_list_t *) (guest_mem + data); - printf("temp check 2\n"); - temp = malloc(sizeof(int)); - *temp = 42; - free(temp); + int num_devices; + struct ibv_device ** host_ret = ibv_get_device_list(&num_devices); - printf("LOG: UHYVE - call_ibv_get_device_list -- before ibv call\n"); - args->ret = ibv_get_device_list(args->num_devices); - printf("LOG: UHYVE - call_ibv_get_device_list -- after ibv call\n"); - - ib_malloc = false; + if (args->num_devices != NULL) { + *args->num_devices = num_devices; + } + for (int d = 0; d < num_devices; d++) { + args->ret[d] = host_ret[d]; + } } +void call_ibv_wc_status_str(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_wc_status_str\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_wc_status_str_t * args = (uhyve_ibv_wc_status_str_t *) (guest_mem + data); -/* - * ibv_get_device_name - */ + const char * host_ret = ibv_wc_status_str(args->status); // ! + memcpy(args->ret, host_ret, sizeof(host_ret)); // ! +} + +void call_ibv_rate_to_mult(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_rate_to_mult\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_rate_to_mult_t * args = (uhyve_ibv_rate_to_mult_t *) (guest_mem + data); + + args->ret = ibv_rate_to_mult(args->rate); +} + +void call_mult_to_ibv_rate(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_mult_to_ibv_rate\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_mult_to_ibv_rate_t * args = (uhyve_mult_to_ibv_rate_t *) (guest_mem + data); + + args->ret = mult_to_ibv_rate(args->mult); +} + +void call_ibv_rate_to_mbps(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_rate_to_mbps\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_rate_to_mbps_t * args = (uhyve_ibv_rate_to_mbps_t *) (guest_mem + data); + + args->ret = ibv_rate_to_mbps(args->rate); +} + +void call_mbps_to_ibv_rate(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_mbps_to_ibv_rate\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_mbps_to_ibv_rate_t * args = (uhyve_mbps_to_ibv_rate_t *) (guest_mem + data); + + args->ret = mbps_to_ibv_rate(args->mbps); +} + +void call_verbs_get_ctx(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_verbs_get_ctx\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_verbs_get_ctx_t * args = (uhyve_verbs_get_ctx_t *) (guest_mem + data); + + args->ret = verbs_get_ctx(args->ctx); +} + +void call_ibv_free_device_list(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_free_device_list\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_free_device_list_t * args = (uhyve_ibv_free_device_list_t *) (guest_mem + data); +} void call_ibv_get_device_name(struct kvm_run * run, uint8_t * guest_mem) { - printf("LOG: UHYVE - call_ibv_get_device_name\n"); - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); + printf("UHYVE call: call_ibv_get_device_name\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); uhyve_ibv_get_device_name_t * args = (uhyve_ibv_get_device_name_t *) (guest_mem + data); - // TODO: Tricky because char ptr isn't allocated in called function. - args->ret = ibv_get_device_name(args->device); - /* memcpy(args->ret, host_ret, sizeof(host_ret)); */ - // TODO: Convert ptrs contained in return value. - // TODO: How to tell if ret needs to be deleted? + const char * host_ret = ibv_get_device_name(args->device); // ! + memcpy(args->ret, host_ret, sizeof(host_ret)); // ! } +void call_ibv_get_device_guid(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_get_device_guid\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_device_guid_t * args = (uhyve_ibv_get_device_guid_t *) (guest_mem + data); -/* - * ibv_open_device - */ + args->ret = ibv_get_device_guid(args->device); +} void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem) { - printf("LOG: UHYVE - call_ibv_open_device\n"); - - ib_malloc = true; - - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); + printf("UHYVE call: call_ibv_open_device\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); uhyve_ibv_open_device_t * args = (uhyve_ibv_open_device_t *) (guest_mem + data); - printf("LOG: UHYVE - call_ibv_open_device\n"); - struct ibv_context * host_ret = ibv_open_device(args->device); - printf("LOG: UHYVE - call_ibv_open_device\n"); - memcpy(args->ret, host_ret, sizeof(host_ret)); - printf("LOG: UHYVE - call_ibv_open_device\n"); - // TODO: Convert ptrs contained in return value. - free(host_ret); - printf("LOG: UHYVE - call_ibv_open_device\n"); - - ib_malloc = false; + args->ret = ibv_open_device(args->device); } +void call_ibv_close_device(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_close_device\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_close_device_t * args = (uhyve_ibv_close_device_t *) (guest_mem + data); -/* - * ibv_query_port - */ + args->ret = ibv_close_device(args->context); +} + +void call_ibv_get_async_event(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_get_async_event\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_async_event_t * args = (uhyve_ibv_get_async_event_t *) (guest_mem + data); + + args->ret = ibv_get_async_event(args->context, args->event); +} + +void call_ibv_ack_async_event(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_ack_async_event\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_ack_async_event_t * args = (uhyve_ibv_ack_async_event_t *) (guest_mem + data); +} + +void call_ibv_query_device(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_query_device\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_device_t * args = (uhyve_ibv_query_device_t *) (guest_mem + data); + + args->ret = ibv_query_device(args->context, args->device_attr); +} void call_ibv_query_port(struct kvm_run * run, uint8_t * guest_mem) { - printf("LOG: UHYVE - call_ibv_query_port"); - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); + printf("UHYVE call: call_ibv_query_port\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); uhyve_ibv_query_port_t * args = (uhyve_ibv_query_port_t *) (guest_mem + data); - int host_ret = ibv_query_port(args->context, args->port_num, args->port_attr); - args->ret = host_ret; + args->ret = ibv_query_port(args->context, args->port_num, args->port_attr); } +void call____ibv_query_port(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call____ibv_query_port\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve____ibv_query_port_t * args = (uhyve____ibv_query_port_t *) (guest_mem + data); -/* - * ibv_create_comp_channel - */ + args->ret = ___ibv_query_port(args->context, args->port_num, args->port_attr); +} + +void call_ibv_query_gid(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_query_gid\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_gid_t * args = (uhyve_ibv_query_gid_t *) (guest_mem + data); + + args->ret = ibv_query_gid(args->context, args->port_num, args->index, args->gid); +} + +void call_ibv_query_pkey(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_query_pkey\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_pkey_t * args = (uhyve_ibv_query_pkey_t *) (guest_mem + data); + + args->ret = ibv_query_pkey(args->context, args->port_num, args->index, args->pkey); +} + +void call_ibv_alloc_pd(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_alloc_pd\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_alloc_pd_t * args = (uhyve_ibv_alloc_pd_t *) (guest_mem + data); + + args->ret = ibv_alloc_pd(args->context); +} + +void call_ibv_dealloc_pd(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_dealloc_pd\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_dealloc_pd_t * args = (uhyve_ibv_dealloc_pd_t *) (guest_mem + data); + + args->ret = ibv_dealloc_pd(args->pd); +} + +void call_ibv_create_flow(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_create_flow\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_flow_t * args = (uhyve_ibv_create_flow_t *) (guest_mem + data); + + args->ret = ibv_create_flow(args->qp, args->flow); +} + +void call_ibv_destroy_flow(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_destroy_flow\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_flow_t * args = (uhyve_ibv_destroy_flow_t *) (guest_mem + data); + + args->ret = ibv_destroy_flow(args->flow_id); +} + +void call_ibv_open_xrcd(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_open_xrcd\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_open_xrcd_t * args = (uhyve_ibv_open_xrcd_t *) (guest_mem + data); + + args->ret = ibv_open_xrcd(args->context, args->xrcd_init_attr); +} + +void call_ibv_close_xrcd(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_close_xrcd\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_close_xrcd_t * args = (uhyve_ibv_close_xrcd_t *) (guest_mem + data); + + args->ret = ibv_close_xrcd(args->xrcd); +} + +void call_ibv_reg_mr(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_reg_mr\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_reg_mr_t * args = (uhyve_ibv_reg_mr_t *) (guest_mem + data); + + args->ret = ibv_reg_mr(args->pd, args->addr, args->length, args->access); +} + +void call_ibv_rereg_mr(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_rereg_mr\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_rereg_mr_t * args = (uhyve_ibv_rereg_mr_t *) (guest_mem + data); + + args->ret = ibv_rereg_mr(args->mr, args->flags, args->pd, args->addr, args->length, args->access); +} + +void call_ibv_dereg_mr(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_dereg_mr\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_dereg_mr_t * args = (uhyve_ibv_dereg_mr_t *) (guest_mem + data); + + args->ret = ibv_dereg_mr(args->mr); +} + +void call_ibv_alloc_mw(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_alloc_mw\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_alloc_mw_t * args = (uhyve_ibv_alloc_mw_t *) (guest_mem + data); + + args->ret = ibv_alloc_mw(args->pd, args->type); +} + +void call_ibv_dealloc_mw(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_dealloc_mw\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_dealloc_mw_t * args = (uhyve_ibv_dealloc_mw_t *) (guest_mem + data); + + args->ret = ibv_dealloc_mw(args->mw); +} + +void call_ibv_inc_rkey(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_inc_rkey\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_inc_rkey_t * args = (uhyve_ibv_inc_rkey_t *) (guest_mem + data); + + args->ret = ibv_inc_rkey(args->rkey); +} + +void call_ibv_bind_mw(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_bind_mw\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_bind_mw_t * args = (uhyve_ibv_bind_mw_t *) (guest_mem + data); + + args->ret = ibv_bind_mw(args->qp, args->mw, args->mw_bind); +} void call_ibv_create_comp_channel(struct kvm_run * run, uint8_t * guest_mem) { - printf("LOG: UHYVE - call_ibv_create_comp_channel"); - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); + printf("UHYVE call: call_ibv_create_comp_channel\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); uhyve_ibv_create_comp_channel_t * args = (uhyve_ibv_create_comp_channel_t *) (guest_mem + data); - /*uhyve_ibv_create_comp_channel_t * args = (uhyve_ibv_create_comp_channel_t *) get_data(run);*/ - struct ibv_comp_channel * host_ret = ibv_create_comp_channel(args->context); - memcpy(args->ret, host_ret, sizeof(host_ret)); // TODO: This will only work for ABI ver > 2. - free(host_ret); + args->ret = ibv_create_comp_channel(args->context); } +void call_ibv_destroy_comp_channel(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_destroy_comp_channel\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_comp_channel_t * args = (uhyve_ibv_destroy_comp_channel_t *) (guest_mem + data); + + args->ret = ibv_destroy_comp_channel(args->channel); +} + +void call_ibv_create_cq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_create_cq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_cq_t * args = (uhyve_ibv_create_cq_t *) (guest_mem + data); + + args->ret = ibv_create_cq(args->context, args->cqe, args->cq_context, args->channel, args->comp_vector); +} + +void call_ibv_resize_cq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_resize_cq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_resize_cq_t * args = (uhyve_ibv_resize_cq_t *) (guest_mem + data); + + args->ret = ibv_resize_cq(args->cq, args->cqe); +} + +void call_ibv_destroy_cq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_destroy_cq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_cq_t * args = (uhyve_ibv_destroy_cq_t *) (guest_mem + data); + + args->ret = ibv_destroy_cq(args->cq); +} + +void call_ibv_get_cq_event(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_get_cq_event\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_cq_event_t * args = (uhyve_ibv_get_cq_event_t *) (guest_mem + data); + + args->ret = ibv_get_cq_event(args->channel, args->cq, args->cq_context); +} + +void call_ibv_ack_cq_events(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_ack_cq_events\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_ack_cq_events_t * args = (uhyve_ibv_ack_cq_events_t *) (guest_mem + data); +} + +void call_ibv_poll_cq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_poll_cq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_poll_cq_t * args = (uhyve_ibv_poll_cq_t *) (guest_mem + data); + + args->ret = ibv_poll_cq(args->cq, args->num_entries, args->wc); +} + +void call_ibv_req_notify_cq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_req_notify_cq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_req_notify_cq_t * args = (uhyve_ibv_req_notify_cq_t *) (guest_mem + data); + + args->ret = ibv_req_notify_cq(args->cq, args->solicited_only); +} + +void call_ibv_create_srq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_create_srq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_srq_t * args = (uhyve_ibv_create_srq_t *) (guest_mem + data); + + args->ret = ibv_create_srq(args->pd, args->srq_init_attr); +} + +void call_ibv_create_srq_ex(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_create_srq_ex\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_srq_ex_t * args = (uhyve_ibv_create_srq_ex_t *) (guest_mem + data); + + args->ret = ibv_create_srq_ex(args->context, args->srq_init_attr_ex); +} + +void call_ibv_modify_srq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_modify_srq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_modify_srq_t * args = (uhyve_ibv_modify_srq_t *) (guest_mem + data); + + args->ret = ibv_modify_srq(args->srq, args->srq_attr, args->srq_attr_mask); +} + +void call_ibv_query_srq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_query_srq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_srq_t * args = (uhyve_ibv_query_srq_t *) (guest_mem + data); + + args->ret = ibv_query_srq(args->srq, args->srq_attr); +} + +void call_ibv_get_srq_num(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_get_srq_num\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_get_srq_num_t * args = (uhyve_ibv_get_srq_num_t *) (guest_mem + data); + + args->ret = ibv_get_srq_num(args->srq, args->srq_num); +} + +void call_ibv_destroy_srq(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_destroy_srq\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_srq_t * args = (uhyve_ibv_destroy_srq_t *) (guest_mem + data); + + args->ret = ibv_destroy_srq(args->srq); +} + +void call_ibv_post_srq_recv(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_post_srq_recv\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_post_srq_recv_t * args = (uhyve_ibv_post_srq_recv_t *) (guest_mem + data); + + args->ret = ibv_post_srq_recv(args->srq, args->recv_wr, args->bad_recv_wr); +} + +void call_ibv_create_qp(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_create_qp\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_qp_t * args = (uhyve_ibv_create_qp_t *) (guest_mem + data); + + args->ret = ibv_create_qp(args->pd, args->qp_init_attr); +} + +void call_ibv_create_qp_ex(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_create_qp_ex\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_qp_ex_t * args = (uhyve_ibv_create_qp_ex_t *) (guest_mem + data); + + args->ret = ibv_create_qp_ex(args->context, args->qp_init_attr_ex); +} + +void call_ibv_query_device_ex(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_query_device_ex\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_device_ex_t * args = (uhyve_ibv_query_device_ex_t *) (guest_mem + data); + + args->ret = ibv_query_device_ex(args->context, args->input, args->attr); +} + +void call_ibv_open_qp(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_open_qp\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_open_qp_t * args = (uhyve_ibv_open_qp_t *) (guest_mem + data); + + args->ret = ibv_open_qp(args->context, args->qp_open_attr); +} + +void call_ibv_modify_qp(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_modify_qp\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_modify_qp_t * args = (uhyve_ibv_modify_qp_t *) (guest_mem + data); + + args->ret = ibv_modify_qp(args->qp, args->attr, args->attr_mask); +} + +void call_ibv_query_qp(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_query_qp\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_query_qp_t * args = (uhyve_ibv_query_qp_t *) (guest_mem + data); + + args->ret = ibv_query_qp(args->qp, args->attr, args->attr_mask, args->init_attr); +} + +void call_ibv_destroy_qp(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_destroy_qp\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_qp_t * args = (uhyve_ibv_destroy_qp_t *) (guest_mem + data); + + args->ret = ibv_destroy_qp(args->qp); +} + +void call_ibv_post_send(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_post_send\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_post_send_t * args = (uhyve_ibv_post_send_t *) (guest_mem + data); + + args->ret = ibv_post_send(args->qp, args->wr, args->bad_wr); +} + +void call_ibv_post_recv(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_post_recv\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_post_recv_t * args = (uhyve_ibv_post_recv_t *) (guest_mem + data); + + args->ret = ibv_post_recv(args->qp, args->wr, args->bad_wr); +} + +void call_ibv_create_ah(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_create_ah\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_ah_t * args = (uhyve_ibv_create_ah_t *) (guest_mem + data); + + args->ret = ibv_create_ah(args->pd, args->attr); +} + +void call_ibv_init_ah_from_wc(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_init_ah_from_wc\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_init_ah_from_wc_t * args = (uhyve_ibv_init_ah_from_wc_t *) (guest_mem + data); + + args->ret = ibv_init_ah_from_wc(args->context, args->port_num, args->wc, args->grh, args->ah_attr); +} + +void call_ibv_create_ah_from_wc(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_create_ah_from_wc\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_create_ah_from_wc_t * args = (uhyve_ibv_create_ah_from_wc_t *) (guest_mem + data); + + args->ret = ibv_create_ah_from_wc(args->pd, args->wc, args->grh, args->port_num); +} + +void call_ibv_destroy_ah(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_destroy_ah\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_destroy_ah_t * args = (uhyve_ibv_destroy_ah_t *) (guest_mem + data); + + args->ret = ibv_destroy_ah(args->ah); +} + +void call_ibv_attach_mcast(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_attach_mcast\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_attach_mcast_t * args = (uhyve_ibv_attach_mcast_t *) (guest_mem + data); + + args->ret = ibv_attach_mcast(args->qp, args->gid, args->lid); +} + +void call_ibv_detach_mcast(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_detach_mcast\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_detach_mcast_t * args = (uhyve_ibv_detach_mcast_t *) (guest_mem + data); + + args->ret = ibv_detach_mcast(args->qp, args->gid, args->lid); +} + +void call_ibv_fork_init(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_fork_init\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_fork_init_t * args = (uhyve_ibv_fork_init_t *) (guest_mem + data); + + args->ret = ibv_fork_init(); +} + +void call_ibv_node_type_str(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_node_type_str\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_node_type_str_t * args = (uhyve_ibv_node_type_str_t *) (guest_mem + data); + + const char * host_ret = ibv_node_type_str(args->node_type); // ! + memcpy(args->ret, host_ret, sizeof(host_ret)); // ! +} + +void call_ibv_port_state_str(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_port_state_str\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_port_state_str_t * args = (uhyve_ibv_port_state_str_t *) (guest_mem + data); + + const char * host_ret = ibv_port_state_str(args->port_state); // ! + memcpy(args->ret, host_ret, sizeof(host_ret)); // ! +} + +void call_ibv_event_type_str(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_event_type_str\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_event_type_str_t * args = (uhyve_ibv_event_type_str_t *) (guest_mem + data); + + const char * host_ret = ibv_event_type_str(args->event); // ! + memcpy(args->ret, host_ret, sizeof(host_ret)); // ! + +} + +void call_ibv_is_qpt_supported(struct kvm_run * run, uint8_t * guest_mem) { + printf("UHYVE call: call_ibv_is_qpt_supported\n"); + unsigned data = *((unsigned*) ((size_t) run + run->io.data_offset)); + uhyve_ibv_is_qpt_supported_t * args = (uhyve_ibv_is_qpt_supported_t *) (guest_mem + data); + + args->ret = ibv_is_qpt_supported(args->caps, args->qpt); +} diff --git a/tools/uhyve-ibv.h b/tools/uhyve-ibv.h index 8f410c07f..ce31e9f14 100644 --- a/tools/uhyve-ibv.h +++ b/tools/uhyve-ibv.h @@ -23,35 +23,150 @@ #include #include -#define MAX_NUM_OF_IBV_DEVICES 16 - -extern bool ib_malloc; - typedef enum { - UHYVE_PORT_IBV_OPEN_DEVICE = 0x510, - UHYVE_PORT_IBV_GET_DEVICE_LIST = 0x511, - UHYVE_PORT_IBV_GET_DEVICE_NAME = 0x512, - UHYVE_PORT_IBV_QUERY_PORT = 0x513, - UHYVE_PORT_IBV_CREATE_COMP_CHANNEL = 0x514, - UHYVE_PORT_KERNEL_IBV_LOG = 0x515, + UHYVE_PORT_IBV_WC_STATUS_STR = 0x510, + UHYVE_PORT_IBV_RATE_TO_MULT = 0x511, + UHYVE_PORT_MULT_TO_IBV_RATE = 0x512, + UHYVE_PORT_IBV_RATE_TO_MBPS = 0x513, + UHYVE_PORT_MBPS_TO_IBV_RATE = 0x514, + UHYVE_PORT_VERBS_GET_CTX = 0x528, + UHYVE_PORT_IBV_GET_DEVICE_LIST = 0x529, + UHYVE_PORT_IBV_FREE_DEVICE_LIST = 0x52A, + UHYVE_PORT_IBV_GET_DEVICE_NAME = 0x52B, + UHYVE_PORT_IBV_GET_DEVICE_GUID = 0x52C, + UHYVE_PORT_IBV_OPEN_DEVICE = 0x52D, + UHYVE_PORT_IBV_CLOSE_DEVICE = 0x52E, + UHYVE_PORT_IBV_GET_ASYNC_EVENT = 0x52F, + UHYVE_PORT_IBV_ACK_ASYNC_EVENT = 0x530, + UHYVE_PORT_IBV_QUERY_DEVICE = 0x531, + UHYVE_PORT_IBV_QUERY_PORT = 0x532, + UHYVE_PORT____IBV_QUERY_PORT = 0x533, + UHYVE_PORT_IBV_QUERY_GID = 0x534, + UHYVE_PORT_IBV_QUERY_PKEY = 0x535, + UHYVE_PORT_IBV_ALLOC_PD = 0x536, + UHYVE_PORT_IBV_DEALLOC_PD = 0x537, + UHYVE_PORT_IBV_CREATE_FLOW = 0x538, + UHYVE_PORT_IBV_DESTROY_FLOW = 0x539, + UHYVE_PORT_IBV_OPEN_XRCD = 0x53A, + UHYVE_PORT_IBV_CLOSE_XRCD = 0x53B, + UHYVE_PORT_IBV_REG_MR = 0x53C, + UHYVE_PORT_IBV_REREG_MR = 0x53D, + UHYVE_PORT_IBV_DEREG_MR = 0x53E, + UHYVE_PORT_IBV_ALLOC_MW = 0x53F, + UHYVE_PORT_IBV_DEALLOC_MW = 0x540, + UHYVE_PORT_IBV_INC_RKEY = 0x541, + UHYVE_PORT_IBV_BIND_MW = 0x542, + UHYVE_PORT_IBV_CREATE_COMP_CHANNEL = 0x543, + UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL = 0x544, + UHYVE_PORT_IBV_CREATE_CQ = 0x545, + UHYVE_PORT_IBV_RESIZE_CQ = 0x547, + UHYVE_PORT_IBV_DESTROY_CQ = 0x548, + UHYVE_PORT_IBV_GET_CQ_EVENT = 0x549, + UHYVE_PORT_IBV_ACK_CQ_EVENTS = 0x54A, + UHYVE_PORT_IBV_POLL_CQ = 0x54B, + UHYVE_PORT_IBV_REQ_NOTIFY_CQ = 0x54C, + UHYVE_PORT_IBV_CREATE_SRQ = 0x54D, + UHYVE_PORT_IBV_CREATE_SRQ_EX = 0x54E, + UHYVE_PORT_IBV_MODIFY_SRQ = 0x54F, + UHYVE_PORT_IBV_QUERY_SRQ = 0x550, + UHYVE_PORT_IBV_GET_SRQ_NUM = 0x551, + UHYVE_PORT_IBV_DESTROY_SRQ = 0x552, + UHYVE_PORT_IBV_POST_SRQ_RECV = 0x553, + UHYVE_PORT_IBV_CREATE_QP = 0x554, + UHYVE_PORT_IBV_CREATE_QP_EX = 0x555, + UHYVE_PORT_IBV_QUERY_DEVICE_EX = 0x557, + UHYVE_PORT_IBV_OPEN_QP = 0x558, + UHYVE_PORT_IBV_MODIFY_QP = 0x559, + UHYVE_PORT_IBV_QUERY_QP = 0x55A, + UHYVE_PORT_IBV_DESTROY_QP = 0x55B, + UHYVE_PORT_IBV_MODIFY_WQ = 0x55D, + UHYVE_PORT_IBV_DESTROY_WQ = 0x55E, + UHYVE_PORT_IBV_CREATE_RWQ_IND_TABLE = 0x55F, + UHYVE_PORT_IBV_DESTROY_RWQ_IND_TABLE = 0x560, + UHYVE_PORT_IBV_POST_SEND = 0x561, + UHYVE_PORT_IBV_POST_RECV = 0x562, + UHYVE_PORT_IBV_CREATE_AH = 0x563, + UHYVE_PORT_IBV_INIT_AH_FROM_WC = 0x564, + UHYVE_PORT_IBV_CREATE_AH_FROM_WC = 0x565, + UHYVE_PORT_IBV_DESTROY_AH = 0x566, + UHYVE_PORT_IBV_ATTACH_MCAST = 0x567, + UHYVE_PORT_IBV_DETACH_MCAST = 0x568, + UHYVE_PORT_IBV_FORK_INIT = 0x569, + UHYVE_PORT_IBV_NODE_TYPE_STR = 0x56A, + UHYVE_PORT_IBV_PORT_STATE_STR = 0x56B, + UHYVE_PORT_IBV_EVENT_TYPE_STR = 0x56C, + UHYVE_PORT_IBV_RESOLVE_ETH_L2_FROM_GID = 0x56D, + UHYVE_PORT_IBV_IS_QPT_SUPPORTED = 0x56E, } uhyve_ibv_t; +typedef struct { + // Parameters: + enum ibv_wc_status status; + // Return value: + char * ret; +} __attribute__((packed)) uhyve_ibv_wc_status_str_t; + +typedef struct { + // Parameters: + enum ibv_rate rate; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rate_to_mult_t; + +typedef struct { + // Parameters: + int mult; + // Return value: + enum ibv_rate ret; +} __attribute__((packed)) uhyve_mult_to_ibv_rate_t; + +typedef struct { + // Parameters: + enum ibv_rate rate; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rate_to_mbps_t; + +typedef struct { + // Parameters: + int mbps; + // Return value: + enum ibv_rate ret; +} __attribute__((packed)) uhyve_mbps_to_ibv_rate_t; + +typedef struct { + // Parameters: + struct ibv_context * ctx; + // Return value: + struct verbs_context * ret; +} __attribute__((packed)) uhyve_verbs_get_ctx_t; typedef struct { // Parameters: int * num_devices; // Return value: - // struct ibv_device * ret[MAX_NUM_OF_IBV_DEVICES]; struct ibv_device ** ret; } __attribute__((packed)) uhyve_ibv_get_device_list_t; +typedef struct { + // Parameters: + struct ibv_device ** list; +} __attribute__((packed)) uhyve_ibv_free_device_list_t; + typedef struct { // Parameters: struct ibv_device * device; // Return value: - const char * ret; // TODO Should this be const? + char * ret; } __attribute__((packed)) uhyve_ibv_get_device_name_t; +typedef struct { + // Parameters: + struct ibv_device * device; + // Return value: + __be64 ret; +} __attribute__((packed)) uhyve_ibv_get_device_guid_t; + typedef struct { // Parameters: struct ibv_device * device; @@ -59,6 +174,34 @@ typedef struct { struct ibv_context * ret; } __attribute__((packed)) uhyve_ibv_open_device_t; +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_close_device_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_async_event * event; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_async_event_t; + +typedef struct { + // Parameters: + struct ibv_async_event * event; +} __attribute__((packed)) uhyve_ibv_ack_async_event_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_device_attr * device_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_device_t; + typedef struct { // Parameters: struct ibv_context * context; @@ -68,6 +211,139 @@ typedef struct { int ret; } __attribute__((packed)) uhyve_ibv_query_port_t; +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_port_attr * port_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve____ibv_query_port_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + int index; + union ibv_gid * gid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_gid_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + int index; + __be16 * pkey; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_pkey_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + // Return value: + struct ibv_pd * ret; +} __attribute__((packed)) uhyve_ibv_alloc_pd_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dealloc_pd_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_flow_attr * flow; + // Return value: + struct ibv_flow * ret; +} __attribute__((packed)) uhyve_ibv_create_flow_t; + +typedef struct { + // Parameters: + struct ibv_flow * flow_id; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_flow_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_xrcd_init_attr * xrcd_init_attr; + // Return value: + struct ibv_xrcd * ret; +} __attribute__((packed)) uhyve_ibv_open_xrcd_t; + +typedef struct { + // Parameters: + struct ibv_xrcd * xrcd; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_close_xrcd_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + void * addr; + int length; + int access; + // Return value: + struct ibv_mr * ret; +} __attribute__((packed)) uhyve_ibv_reg_mr_t; + +typedef struct { + // Parameters: + struct ibv_mr * mr; + int flags; + struct ibv_pd * pd; + void * addr; + int length; + int access; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_rereg_mr_t; + +typedef struct { + // Parameters: + struct ibv_mr * mr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dereg_mr_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + enum ibv_mw_type type; + // Return value: + struct ibv_mw * ret; +} __attribute__((packed)) uhyve_ibv_alloc_mw_t; + +typedef struct { + // Parameters: + struct ibv_mw * mw; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_dealloc_mw_t; + +typedef struct { + // Parameters: + uint32_t rkey; + // Return value: + uint32_t ret; +} __attribute__((packed)) uhyve_ibv_inc_rkey_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_mw * mw; + struct ibv_mw_bind * mw_bind; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_bind_mw_t; + typedef struct { // Parameters: struct ibv_context * context; @@ -75,10 +351,369 @@ typedef struct { struct ibv_comp_channel * ret; } __attribute__((packed)) uhyve_ibv_create_comp_channel_t; -void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem); -void call_ibv_get_device_name(struct kvm_run * run, uint8_t * guest_mem); -void call_ibv_query_port(struct kvm_run * run, uint8_t * guest_mem); -void call_ibv_create_comp_channel(struct kvm_run * run, uint8_t * guest_mem); -void call_ibv_get_device_list(struct kvm_run * run, uint8_t * guest_mem); +typedef struct { + // Parameters: + struct ibv_comp_channel * channel; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_comp_channel_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + int cqe; + void * cq_context; + struct ibv_comp_channel * channel; + int comp_vector; + // Return value: + struct ibv_cq * ret; +} __attribute__((packed)) uhyve_ibv_create_cq_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int cqe; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_resize_cq_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_cq_t; + +typedef struct { + // Parameters: + struct ibv_comp_channel * channel; + struct ibv_cq ** cq; + void ** cq_context; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_cq_event_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + unsigned int nevents; +} __attribute__((packed)) uhyve_ibv_ack_cq_events_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int num_entries; + struct ibv_wc * wc; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_poll_cq_t; + +typedef struct { + // Parameters: + struct ibv_cq * cq; + int solicited_only; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_req_notify_cq_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_srq_init_attr * srq_init_attr; + // Return value: + struct ibv_srq * ret; +} __attribute__((packed)) uhyve_ibv_create_srq_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_srq_init_attr_ex * srq_init_attr_ex; + // Return value: + struct ibv_srq * ret; +} __attribute__((packed)) uhyve_ibv_create_srq_ex_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_srq_attr * srq_attr; + int srq_attr_mask; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_srq_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_srq_attr * srq_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_srq_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + uint32_t * srq_num; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_get_srq_num_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_srq_t; + +typedef struct { + // Parameters: + struct ibv_srq * srq; + struct ibv_recv_wr * recv_wr; + struct ibv_recv_wr ** bad_recv_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_srq_recv_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_qp_init_attr * qp_init_attr; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_create_qp_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_qp_init_attr_ex * qp_init_attr_ex; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_create_qp_ex_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + const struct ibv_query_device_ex_input * input; + struct ibv_device_attr_ex * attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_device_ex_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + struct ibv_qp_open_attr * qp_open_attr; + // Return value: + struct ibv_qp * ret; +} __attribute__((packed)) uhyve_ibv_open_qp_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_qp_attr * attr; + int attr_mask; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_modify_qp_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_qp_attr * attr; + int attr_mask; + struct ibv_qp_init_attr * init_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_query_qp_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_qp_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_send_wr * wr; + struct ibv_send_wr ** bad_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_send_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + struct ibv_recv_wr * wr; + struct ibv_recv_wr ** bad_wr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_post_recv_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_ah_attr * attr; + // Return value: + struct ibv_ah * ret; +} __attribute__((packed)) uhyve_ibv_create_ah_t; + +typedef struct { + // Parameters: + struct ibv_context * context; + uint8_t port_num; + struct ibv_wc * wc; + struct ibv_grh * grh; + struct ibv_ah_attr * ah_attr; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_init_ah_from_wc_t; + +typedef struct { + // Parameters: + struct ibv_pd * pd; + struct ibv_wc * wc; + struct ibv_grh * grh; + uint8_t port_num; + // Return value: + struct ibv_ah * ret; +} __attribute__((packed)) uhyve_ibv_create_ah_from_wc_t; + +typedef struct { + // Parameters: + struct ibv_ah * ah; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_destroy_ah_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + const union ibv_gid * gid; + uint16_t lid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_attach_mcast_t; + +typedef struct { + // Parameters: + struct ibv_qp * qp; + const union ibv_gid * gid; + uint16_t lid; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_detach_mcast_t; + +typedef struct { + // Parameters: + ; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_fork_init_t; + +typedef struct { + // Parameters: + enum ibv_node_type node_type; + // Return value: + char * ret; +} __attribute__((packed)) uhyve_ibv_node_type_str_t; + +typedef struct { + // Parameters: + enum ibv_port_state port_state; + // Return value: + char * ret; +} __attribute__((packed)) uhyve_ibv_port_state_str_t; + +typedef struct { + // Parameters: + enum ibv_event_type event; + // Return value: + char * ret; +} __attribute__((packed)) uhyve_ibv_event_type_str_t; + +typedef struct { + // Parameters: + uint32_t caps; + enum ibv_qp_type qpt; + // Return value: + int ret; +} __attribute__((packed)) uhyve_ibv_is_qpt_supported_t; + + +void call_ibv_wc_status_str (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_rate_to_mult (struct kvm_run * run, uint8_t * guest_mem); +void call_mult_to_ibv_rate (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_rate_to_mbps (struct kvm_run * run, uint8_t * guest_mem); +void call_mbps_to_ibv_rate (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_cq_ex_to_cq (struct kvm_run * run, uint8_t * guest_mem); +void call_verbs_get_ctx (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_device_list (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_free_device_list (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_device_name (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_device_guid (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_open_device (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_close_device (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_async_event (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_ack_async_event (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_device (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_port (struct kvm_run * run, uint8_t * guest_mem); +void call____ibv_query_port (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_gid (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_pkey (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_alloc_pd (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_dealloc_pd (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_flow (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_flow (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_open_xrcd (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_close_xrcd (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_reg_mr (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_rereg_mr (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_dereg_mr (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_alloc_mw (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_dealloc_mw (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_inc_rkey (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_bind_mw (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_comp_channel (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_comp_channel (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_cq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_resize_cq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_cq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_cq_event (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_ack_cq_events (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_poll_cq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_req_notify_cq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_srq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_srq_ex (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_modify_srq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_srq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_get_srq_num (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_srq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_post_srq_recv (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_qp (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_qp_ex (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_device_ex (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_open_qp (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_modify_qp (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_query_qp (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_qp (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_modify_wq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_wq (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_rwq_ind_table (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_rwq_ind_table (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_post_send (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_post_recv (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_ah (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_init_ah_from_wc (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_create_ah_from_wc (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_destroy_ah (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_attach_mcast (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_detach_mcast (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_fork_init (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_node_type_str (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_port_state_str (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_event_type_str (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_resolve_eth_l2_from_gid (struct kvm_run * run, uint8_t * guest_mem); +void call_ibv_is_qpt_supported (struct kvm_run * run, uint8_t * guest_mem); #endif // UHYVE_IBV_H diff --git a/tools/uhyve.c b/tools/uhyve.c index 32d007a65..65750f516 100644 --- a/tools/uhyve.c +++ b/tools/uhyve.c @@ -168,8 +168,6 @@ #define IOAPIC_DEFAULT_BASE 0xfec00000 #define APIC_DEFAULT_BASE 0xfee00000 -#define IB_MEM_DEBUG 1 - static bool restart = false; static bool cap_tsc_deadline = false; static bool cap_irqchip = false; @@ -195,199 +193,6 @@ static __thread struct kvm_run *run = NULL; static __thread int vcpufd = -1; static __thread uint32_t cpuid = 0; - - - - -static uint8_t * ib_mem = NULL; -bool ib_malloc = false; -static const size_t std_alignment = 16; // TODO: Use sizeof(maxint_t) (?) or similar -static pthread_mutex_t ib_hooks_mutex = PTHREAD_MUTEX_INITIALIZER; - -// Definition of malloc hooks for IBV library -static void init_ib_hooks(void); - -static void * ib_malloc_hook(size_t, const void *); -static void * ib_realloc_hook(void *, size_t, const void *); -static void * ib_memalign_hook(size_t, size_t, const void *); -static void ib_free_hook(void *, const void *); - -static void * (* default_malloc_hook) (size_t, const void *); -static void * (* default_realloc_hook) (void *, size_t, const void *); -static void * (* default_memalign_hook)(size_t, size_t, const void *); -static void (* default_free_hook) (void *, const void *); - -/* void (* __malloc_initialize_hook) (void) = init_ib_hooks; */ -/* __malloc_initialize_hook = init_ib_hooks; */ - -static void init_ib_hooks(void) { - default_malloc_hook = __malloc_hook; - default_realloc_hook = __realloc_hook; - default_memalign_hook = __memalign_hook; - default_free_hook = __free_hook; - - __malloc_hook = ib_malloc_hook; - __realloc_hook = ib_realloc_hook; - __memalign_hook = ib_memalign_hook; - __free_hook = ib_free_hook; -} - -void init_default_hooks() { - __malloc_hook = default_malloc_hook; - __realloc_hook = default_realloc_hook; - __memalign_hook = default_memalign_hook; - __free_hook = default_free_hook; -} - -void * new_ib_malloc_region(size_t size) { - void * result = NULL; - - if (size > 0) { - ib_mem -= size; - ib_mem -= (size_t) ((uintptr_t) ib_mem % std_alignment); -#ifdef IB_MEM_DEBUG - printf("ib_mem aligned: %p\n", ib_mem); -#endif - result = ib_mem; - - ib_mem -= std_alignment; - size_t * block_size = (size_t *) ib_mem; - *block_size = size; - } - - if ((uint8_t *) result < guest_mem + guest_size - (size_t) (1UL << 20)) { // TODO: remove this -#ifdef IB_MEM_DEBUG - printf("WARNING, IB MEM OUT OF BOUNDS\n\n"); -#endif - } - - return result; -} - -// Malloc Hook -static void * ib_malloc_hook(size_t size, const void * caller) { -#ifdef IB_MEM_DEBUG - /* printf("Before Mutex Lock."); */ -#endif - pthread_mutex_lock(&ib_hooks_mutex); - init_default_hooks(); - -#ifdef IB_MEM_DEBUG - printf(" ib_malloc_hook\tib_malloc %s\t Args:\tsize = %lu\t", ib_malloc ? "true " : "false", size); -#endif - - void * result; - if (ib_malloc) { - result = new_ib_malloc_region(size); - } else { // !ib_malloc -#ifdef IB_MEM_DEBUG - printf("\n"); -#endif - result = malloc(size); - } - - init_ib_hooks(); - pthread_mutex_unlock(&ib_hooks_mutex); - return result; -} - -// Realloc Hook -static void * ib_realloc_hook(void * ptr, size_t new_size, const void * caller) { - pthread_mutex_lock(&ib_hooks_mutex); - init_default_hooks(); - -#ifdef IB_MEM_DEBUG - printf("ib_realloc_hook\tib_malloc %s\t Args:\tptr = %p, size = %lu\t", ib_malloc ? "true " : "false", ptr, new_size); -#endif - void * result; - - if (ib_malloc) { - size_t * mem_block_size_ptr = (size_t *) (ptr - std_alignment); - size_t orig_size = *mem_block_size_ptr; - - if (new_size <= 0 || ptr == NULL) { -#ifdef IB_MEM_DEBUG - printf("new_size <= 0 || ptr == NULL\n"); -#endif - result = NULL; - } else if (new_size <= orig_size) { -#ifdef IB_MEM_DEBUG - printf("new_size <= orig_size = %lu\n", orig_size); -#endif - *mem_block_size_ptr = new_size; - result = ptr; - } else { // new_size > orig_size - result = new_ib_malloc_region(new_size); - memcpy(result, ptr, orig_size); - } - - } else { // !ib_malloc -#ifdef IB_MEM_DEBUG - printf("\n"); -#endif - result = realloc(ptr, new_size); - } - - init_ib_hooks(); - pthread_mutex_unlock(&ib_hooks_mutex); - return result; -} - -// Memalign Hook - just a dummy for now -static void * ib_memalign_hook(size_t alignment, size_t size, const void * caller) { - pthread_mutex_lock(&ib_hooks_mutex); - init_default_hooks(); - -#ifdef IB_MEM_DEBUG - printf("\tCALLED! ib_memalign_hook\tib_malloc %s\t Args:\talignment = %lu\tsize = %lu\t", - ib_malloc ? "true " : "false", alignment, size); -#endif - - void * result; - if (ib_malloc) { - /* result = new_ib_malloc_region(size); */ - } else { // !ib_malloc -#ifdef IB_MEM_DEBUG - printf("\n"); -#endif - result = memalign(alignment, size); - } - - init_ib_hooks(); - pthread_mutex_unlock(&ib_hooks_mutex); - return result; -} - -// Free Hook -static void ib_free_hook(void * ptr, const void * caller) { - pthread_mutex_lock(&ib_hooks_mutex); - init_default_hooks(); - -#ifdef IB_MEM_DEBUG - printf(" ib_free_hook\tib_malloc %s\t Args:\tptr = %p", ib_malloc ? "true " : "false", ptr); -#endif - - if (!ib_malloc) { - free(ptr); - } else if (ptr != NULL && (ptr <= ib_mem || ptr > guest_mem + guest_size)) { -#ifdef IB_MEM_DEBUG - printf("\t!!! ptr out of ib bounds !!!"); -#endif - } -#ifdef IB_MEM_DEBUG - printf("\n"); -#endif - - init_ib_hooks(); - pthread_mutex_unlock(&ib_hooks_mutex); -} - - - - - - - static uint64_t memparse(const char *ptr) { // local pointer to end of parsed string @@ -1165,34 +970,218 @@ static int vcpu_loop(void) break; } - case UHYVE_PORT_KERNEL_IBV_LOG: { - unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); - char* str = (char*) (guest_mem + data); - printf("KERNEL IBV LOG: %s\n", str); - break; - } + /* case UHYVE_PORT_KERNEL_IBV_LOG: { */ + /* unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); */ + /* char* str = (char*) (guest_mem + data); */ + /* printf("KERNEL IBV LOG: %s\n", str); */ + /* break; */ + /* } */ // InfiniBand + case UHYVE_PORT_IBV_WC_STATUS_STR: + call_ibv_wc_status_str(run, guest_mem); + break; + case UHYVE_PORT_IBV_RATE_TO_MULT: + call_ibv_rate_to_mult(run, guest_mem); + break; + case UHYVE_PORT_MULT_TO_IBV_RATE: + call_mult_to_ibv_rate(run, guest_mem); + break; + case UHYVE_PORT_IBV_RATE_TO_MBPS: + call_ibv_rate_to_mbps(run, guest_mem); + break; + case UHYVE_PORT_MBPS_TO_IBV_RATE: + call_mbps_to_ibv_rate(run, guest_mem); + break; + case UHYVE_PORT_VERBS_GET_CTX: + call_verbs_get_ctx(run, guest_mem); + break; case UHYVE_PORT_IBV_GET_DEVICE_LIST: - printf("LOG: UHYVE CASE\n"); call_ibv_get_device_list(run, guest_mem); break; + case UHYVE_PORT_IBV_FREE_DEVICE_LIST: + call_ibv_free_device_list(run, guest_mem); + break; case UHYVE_PORT_IBV_GET_DEVICE_NAME: - printf("LOG: UHYVE CASE UHYVE_PORT_IBV_GET_DEVICE_NAME\n"); call_ibv_get_device_name(run, guest_mem); break; + case UHYVE_PORT_IBV_GET_DEVICE_GUID: + call_ibv_get_device_guid(run, guest_mem); + break; case UHYVE_PORT_IBV_OPEN_DEVICE: - printf("LOG: UHYVE CASE UHYVE_PORT_IBV_OPEN_DEVICE\n"); call_ibv_open_device(run, guest_mem); break; + case UHYVE_PORT_IBV_CLOSE_DEVICE: + call_ibv_close_device(run, guest_mem); + break; + case UHYVE_PORT_IBV_GET_ASYNC_EVENT: + call_ibv_get_async_event(run, guest_mem); + break; + case UHYVE_PORT_IBV_ACK_ASYNC_EVENT: + call_ibv_ack_async_event(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_DEVICE: + call_ibv_query_device(run, guest_mem); + break; case UHYVE_PORT_IBV_QUERY_PORT: - printf("LOG: UHYVE CASE UHYVE_PORT_IBV_QUERY_PORT\n"); call_ibv_query_port(run, guest_mem); break; + case UHYVE_PORT____IBV_QUERY_PORT: + call____ibv_query_port(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_GID: + call_ibv_query_gid(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_PKEY: + call_ibv_query_pkey(run, guest_mem); + break; + case UHYVE_PORT_IBV_ALLOC_PD: + call_ibv_alloc_pd(run, guest_mem); + break; + case UHYVE_PORT_IBV_DEALLOC_PD: + call_ibv_dealloc_pd(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_FLOW: + call_ibv_create_flow(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_FLOW: + call_ibv_destroy_flow(run, guest_mem); + break; + case UHYVE_PORT_IBV_OPEN_XRCD: + call_ibv_open_xrcd(run, guest_mem); + break; + case UHYVE_PORT_IBV_CLOSE_XRCD: + call_ibv_close_xrcd(run, guest_mem); + break; + case UHYVE_PORT_IBV_REG_MR: + call_ibv_reg_mr(run, guest_mem); + break; + case UHYVE_PORT_IBV_REREG_MR: + call_ibv_rereg_mr(run, guest_mem); + break; + case UHYVE_PORT_IBV_DEREG_MR: + call_ibv_dereg_mr(run, guest_mem); + break; + case UHYVE_PORT_IBV_ALLOC_MW: + call_ibv_alloc_mw(run, guest_mem); + break; + case UHYVE_PORT_IBV_DEALLOC_MW: + call_ibv_dealloc_mw(run, guest_mem); + break; + case UHYVE_PORT_IBV_INC_RKEY: + call_ibv_inc_rkey(run, guest_mem); + break; + case UHYVE_PORT_IBV_BIND_MW: + call_ibv_bind_mw(run, guest_mem); + break; case UHYVE_PORT_IBV_CREATE_COMP_CHANNEL: - printf("LOG: UHYVE CASE UHYVE_PORT_IBV_CREATE_COMP_CHANNEL\n"); call_ibv_create_comp_channel(run, guest_mem); break; + case UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL: + call_ibv_destroy_comp_channel(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_CQ: + call_ibv_create_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_RESIZE_CQ: + call_ibv_resize_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_CQ: + call_ibv_destroy_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_GET_CQ_EVENT: + call_ibv_get_cq_event(run, guest_mem); + break; + case UHYVE_PORT_IBV_ACK_CQ_EVENTS: + call_ibv_ack_cq_events(run, guest_mem); + break; + case UHYVE_PORT_IBV_POLL_CQ: + call_ibv_poll_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_REQ_NOTIFY_CQ: + call_ibv_req_notify_cq(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_SRQ: + call_ibv_create_srq(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_SRQ_EX: + call_ibv_create_srq_ex(run, guest_mem); + break; + case UHYVE_PORT_IBV_MODIFY_SRQ: + call_ibv_modify_srq(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_SRQ: + call_ibv_query_srq(run, guest_mem); + break; + case UHYVE_PORT_IBV_GET_SRQ_NUM: + call_ibv_get_srq_num(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_SRQ: + call_ibv_destroy_srq(run, guest_mem); + break; + case UHYVE_PORT_IBV_POST_SRQ_RECV: + call_ibv_post_srq_recv(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_QP: + call_ibv_create_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_QP_EX: + call_ibv_create_qp_ex(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_DEVICE_EX: + call_ibv_query_device_ex(run, guest_mem); + break; + case UHYVE_PORT_IBV_OPEN_QP: + call_ibv_open_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_MODIFY_QP: + call_ibv_modify_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_QUERY_QP: + call_ibv_query_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_QP: + call_ibv_destroy_qp(run, guest_mem); + break; + case UHYVE_PORT_IBV_POST_SEND: + call_ibv_post_send(run, guest_mem); + break; + case UHYVE_PORT_IBV_POST_RECV: + call_ibv_post_recv(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_AH: + call_ibv_create_ah(run, guest_mem); + break; + case UHYVE_PORT_IBV_INIT_AH_FROM_WC: + call_ibv_init_ah_from_wc(run, guest_mem); + break; + case UHYVE_PORT_IBV_CREATE_AH_FROM_WC: + call_ibv_create_ah_from_wc(run, guest_mem); + break; + case UHYVE_PORT_IBV_DESTROY_AH: + call_ibv_destroy_ah(run, guest_mem); + break; + case UHYVE_PORT_IBV_ATTACH_MCAST: + call_ibv_attach_mcast(run, guest_mem); + break; + case UHYVE_PORT_IBV_DETACH_MCAST: + call_ibv_detach_mcast(run, guest_mem); + break; + case UHYVE_PORT_IBV_FORK_INIT: + call_ibv_fork_init(run, guest_mem); + break; + case UHYVE_PORT_IBV_NODE_TYPE_STR: + call_ibv_node_type_str(run, guest_mem); + break; + case UHYVE_PORT_IBV_PORT_STATE_STR: + call_ibv_port_state_str(run, guest_mem); + break; + case UHYVE_PORT_IBV_EVENT_TYPE_STR: + call_ibv_event_type_str(run, guest_mem); + break; + case UHYVE_PORT_IBV_IS_QPT_SUPPORTED: + call_ibv_is_qpt_supported(run, guest_mem); + break; default: err(1, "KVM: unhandled KVM_EXIT_IO at port 0x%x, direction %d\n", run->io.port, run->io.direction); @@ -1624,12 +1613,6 @@ int uhyve_init(char *path) err(1, "unable to initialized network"); } - printf("UHYVE: Initialize malloc hooks (init_ib_hooks())\n"); - ib_mem = guest_mem + guest_size; - printf("guest_mem: %p, guest_size: %p\n", guest_mem, guest_size); - printf("ib_mem = guest_mem + guest_size: %p\n", ib_mem); - init_ib_hooks(); - return ret; } diff --git a/usr/tests/ib-test.c b/usr/tests/ib-test.c index 8b14b7131..b2eacf12f 100644 --- a/usr/tests/ib-test.c +++ b/usr/tests/ib-test.c @@ -54,21 +54,26 @@ int main(int argc, char** argv) printf("ib-test.c: before get dev list.\n"); dev_list = ibv_get_device_list(&num_devices); - printf("after get device list -- ib-test.c: num devices: %d\n", num_devices); - printf("after get device list -- ib-test.c: ptr 1: %p\n", dev_list[0]); - printf("after get device list -- ib-test.c: ptr 2: %p\n", dev_list[1]); - printf("after get device list -- ib-test.c: name 1: %s\n", dev_list[0]->name); - printf("after get device list -- ib-test.c: name 2: %s\n", dev_list[1]->name); + printf("ib-test.c: after get device list - num devices: %d\n", num_devices); + /* printf("after get device list -- ib-test.c: ptr 1: %p\n", dev_list[0]); */ + /* printf("after get device list -- ib-test.c: ptr 2: %p\n", dev_list[1]); */ + /* printf("after get device list -- ib-test.c: name 1: %s\n", dev_list[0]->name); */ + /* printf("after get device list -- ib-test.c: name 2: %s\n", dev_list[1]->name); */ - printf("before get device name loop.\n"); - for (int i=0; i < num_devices; i++) { - const char* dev_name = ibv_get_device_name(dev_list[i]); - printf("after get device name -- Device name %d: %s\n", i, dev_name); - } + /* printf("before get device name loop.\n"); */ + /* for (int i=0; i < num_devices; i++) { */ + /* const char* dev_name = ibv_get_device_name(dev_list[i]); */ + /* printf("after get device name -- Device name %d: %s\n", i, dev_name); */ + /* } */ - printf("before open_device\n"); + printf("ib-test.c: before open_device\n"); struct ibv_context * context = ibv_open_device(dev_list[0]); - printf("after open device\n"); + printf("ib-test.c: after open device\n"); + + struct ibv_port_attr port_info = {}; + uint8_t port = 1; + int success = ibv_query_port(context, port, &port_info); + printf("ib-test.c: after ibv_query_port\n"); return 0; } diff --git a/usr/tests/ib/pingpong-ud.c b/usr/tests/ib/pingpong-ud.c index 70a02809c..22fcefa79 100644 --- a/usr/tests/ib/pingpong-ud.c +++ b/usr/tests/ib/pingpong-ud.c @@ -92,228 +92,226 @@ struct pingpong_dest { union ibv_gid gid; }; -/*static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,*/ - /*int sl, struct pingpong_dest *dest, int sgid_idx)*/ -/*{*/ - /*struct ibv_ah_attr ah_attr = {*/ - /*.is_global = 0,*/ - /*.dlid = dest->lid,*/ - /*.sl = sl,*/ - /*.src_path_bits = 0,*/ - /*.port_num = port*/ - /*};*/ - /*struct ibv_qp_attr attr = {*/ - /*.qp_state = IBV_QPS_RTR*/ - /*};*/ +static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn, + int sl, struct pingpong_dest *dest, int sgid_idx) +{ + struct ibv_ah_attr ah_attr = { + .is_global = 0, + .dlid = dest->lid, + .sl = sl, + .src_path_bits = 0, + .port_num = port + }; + struct ibv_qp_attr attr = { + .qp_state = IBV_QPS_RTR + }; - /*if (ibv_modify_qp(ctx->qp, &attr, IBV_QP_STATE)) {*/ - /*fprintf(stderr, "Failed to modify QP to RTR\n");*/ - /*return 1;*/ - /*}*/ + if (ibv_modify_qp(ctx->qp, &attr, IBV_QP_STATE)) { + fprintf(stderr, "Failed to modify QP to RTR\n"); + return 1; + } - /*attr.qp_state = IBV_QPS_RTS;*/ - /*attr.sq_psn = my_psn;*/ + attr.qp_state = IBV_QPS_RTS; + attr.sq_psn = my_psn; - /*if (ibv_modify_qp(ctx->qp, &attr,*/ - /*IBV_QP_STATE |*/ - /*IBV_QP_SQ_PSN)) {*/ - /*fprintf(stderr, "Failed to modify QP to RTS\n");*/ - /*return 1;*/ - /*}*/ + if (ibv_modify_qp(ctx->qp, &attr, + IBV_QP_STATE | + IBV_QP_SQ_PSN)) { + fprintf(stderr, "Failed to modify QP to RTS\n"); + return 1; + } - /*if (dest->gid.global.interface_id) {*/ - /*ah_attr.is_global = 1;*/ - /*ah_attr.grh.hop_limit = 1;*/ - /*ah_attr.grh.dgid = dest->gid;*/ - /*ah_attr.grh.sgid_index = sgid_idx;*/ - /*}*/ + if (dest->gid.global.interface_id) { + ah_attr.is_global = 1; + ah_attr.grh.hop_limit = 1; + ah_attr.grh.dgid = dest->gid; + ah_attr.grh.sgid_index = sgid_idx; + } - /*ctx->ah = ibv_create_ah(ctx->pd, &ah_attr);*/ - /*if (!ctx->ah) {*/ - /*fprintf(stderr, "Failed to create AH\n");*/ - /*return 1;*/ - /*}*/ + ctx->ah = ibv_create_ah(ctx->pd, &ah_attr); + if (!ctx->ah) { + fprintf(stderr, "Failed to create AH\n"); + return 1; + } - /*return 0;*/ -/*}*/ + return 0; +} -/*static struct pingpong_dest *pp_client_exch_dest(const char *servername, int port,*/ - /*const struct pingpong_dest *my_dest)*/ -/*{*/ - /*struct addrinfo *res, *t;*/ - /*struct addrinfo hints = {*/ - /*.ai_family = AF_UNSPEC,*/ - /*.ai_socktype = SOCK_STREAM*/ - /*};*/ - /*char *service;*/ - /*char msg[sizeof "0000:000000:000000:00000000000000000000000000000000"];*/ - /*int n;*/ - /*int sockfd = -1;*/ - /*struct pingpong_dest *rem_dest = NULL;*/ - /*char gid[33];*/ +static struct pingpong_dest *pp_client_exch_dest(const char *servername, int port, + const struct pingpong_dest *my_dest) +{ + struct addrinfo *res, *t; + struct addrinfo hints = { + .ai_family = AF_UNSPEC, + .ai_socktype = SOCK_STREAM + }; + char *service; + char msg[sizeof "0000:000000:000000:00000000000000000000000000000000"]; + int n; + int sockfd = -1; + struct pingpong_dest *rem_dest = NULL; + char gid[33]; - /*if (asprintf(&service, "%d", port) < 0)*/ - /*return NULL;*/ + if (asprintf(&service, "%d", port) < 0) + return NULL; - /*n = getaddrinfo(servername, service, &hints, &res);*/ + n = getaddrinfo(servername, service, &hints, &res); - /*if (n < 0) {*/ - /*fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);*/ - /*free(service);*/ - /*return NULL;*/ - /*}*/ + if (n < 0) { + fprintf(stderr, "error for %s:%d\n", servername, port); + free(service); + return NULL; + } - /*for (t = res; t; t = t->ai_next) {*/ - /*sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);*/ - /*if (sockfd >= 0) {*/ - /*if (!connect(sockfd, t->ai_addr, t->ai_addrlen))*/ - /*break;*/ - /*close(sockfd);*/ - /*sockfd = -1;*/ - /*}*/ - /*}*/ + for (t = res; t; t = t->ai_next) { + sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol); + if (sockfd >= 0) { + if (!connect(sockfd, t->ai_addr, t->ai_addrlen)) + break; + close(sockfd); + sockfd = -1; + } + } - /*freeaddrinfo(res);*/ - /*free(service);*/ + freeaddrinfo(res); + free(service); - /*if (sockfd < 0) {*/ - /*fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port);*/ - /*return NULL;*/ - /*}*/ + if (sockfd < 0) { + fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port); + return NULL; + } - /*gid_to_wire_gid(&my_dest->gid, gid);*/ - /*sprintf(msg, "%04x:%06x:%06x:%s", my_dest->lid, my_dest->qpn,*/ - /*my_dest->psn, gid);*/ - /*if (write(sockfd, msg, sizeof msg) != sizeof msg) {*/ - /*fprintf(stderr, "Couldn't send local address\n");*/ - /*goto out;*/ - /*}*/ + gid_to_wire_gid(&my_dest->gid, gid); + sprintf(msg, "%04x:%06x:%06x:%s", my_dest->lid, my_dest->qpn, + my_dest->psn, gid); + if (write(sockfd, msg, sizeof msg) != sizeof msg) { + fprintf(stderr, "Couldn't send local address\n"); + goto out; + } - /*if (read(sockfd, msg, sizeof msg) != sizeof msg ||*/ - /*write(sockfd, "done", sizeof "done") != sizeof "done") {*/ - /*perror("client read/write");*/ - /*fprintf(stderr, "Couldn't read/write remote address\n");*/ - /*goto out;*/ - /*}*/ + if (read(sockfd, msg, sizeof msg) != sizeof msg || + write(sockfd, "done", sizeof "done") != sizeof "done") { + perror("client read/write"); + fprintf(stderr, "Couldn't read/write remote address\n"); + goto out; + } - /*rem_dest = malloc(sizeof *rem_dest);*/ - /*if (!rem_dest)*/ - /*goto out;*/ + rem_dest = malloc(sizeof *rem_dest); + if (!rem_dest) + goto out; - /*sscanf(msg, "%x:%x:%x:%s", &rem_dest->lid, &rem_dest->qpn,*/ - /*&rem_dest->psn, gid);*/ - /*wire_gid_to_gid(gid, &rem_dest->gid);*/ + sscanf(msg, "%x:%x:%x:%s", &rem_dest->lid, &rem_dest->qpn, + &rem_dest->psn, gid); + wire_gid_to_gid(gid, &rem_dest->gid); -/*out:*/ - /*close(sockfd);*/ - /*return rem_dest;*/ -/*}*/ +out: + close(sockfd); + return rem_dest; +} -/*static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,*/ - /*int ib_port, int port, int sl,*/ - /*const struct pingpong_dest *my_dest,*/ - /*int sgid_idx)*/ -/*{*/ - /*struct addrinfo *res, *t;*/ - /*struct addrinfo hints = {*/ - /*.ai_flags = AI_PASSIVE,*/ - /*.ai_family = AF_UNSPEC,*/ - /*.ai_socktype = SOCK_STREAM*/ - /*};*/ - /*char *service;*/ - /*char msg[sizeof "0000:000000:000000:00000000000000000000000000000000"];*/ - /*int n;*/ - /*int sockfd = -1, connfd;*/ - /*struct pingpong_dest *rem_dest = NULL;*/ - /*char gid[33];*/ +static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx, + int ib_port, int port, int sl, + const struct pingpong_dest *my_dest, + int sgid_idx) +{ + struct addrinfo *res, *t; + struct addrinfo hints = { + .ai_flags = AI_PASSIVE, + .ai_family = AF_UNSPEC, + .ai_socktype = SOCK_STREAM + }; + char *service; + char msg[sizeof "0000:000000:000000:00000000000000000000000000000000"]; + int n; + int sockfd = -1, connfd; + struct pingpong_dest *rem_dest = NULL; + char gid[33]; - /*if (asprintf(&service, "%d", port) < 0)*/ - /*return NULL;*/ + if (asprintf(&service, "%d", port) < 0) + return NULL; - /*n = getaddrinfo(NULL, service, &hints, &res);*/ + n = getaddrinfo(NULL, service, &hints, &res); - /*if (n < 0) {*/ - /*fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);*/ - /*free(service);*/ - /*return NULL;*/ - /*}*/ + if (n < 0) { + fprintf(stderr, "error for port %d\n", port); + free(service); + return NULL; + } - /*for (t = res; t; t = t->ai_next) {*/ - /*sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);*/ - /*if (sockfd >= 0) {*/ - /*n = 1;*/ + for (t = res; t; t = t->ai_next) { + sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol); + if (sockfd >= 0) { + n = 1; - /*setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n);*/ + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n); - /*if (!bind(sockfd, t->ai_addr, t->ai_addrlen))*/ - /*break;*/ - /*close(sockfd);*/ - /*sockfd = -1;*/ - /*}*/ - /*}*/ + if (!bind(sockfd, t->ai_addr, t->ai_addrlen)) + break; + close(sockfd); + sockfd = -1; + } + } - /*freeaddrinfo(res);*/ - /*free(service);*/ + freeaddrinfo(res); + free(service); - /*if (sockfd < 0) {*/ - /*fprintf(stderr, "Couldn't listen to port %d\n", port);*/ - /*return NULL;*/ - /*}*/ + if (sockfd < 0) { + fprintf(stderr, "Couldn't listen to port %d\n", port); + return NULL; + } - /*listen(sockfd, 1);*/ - /*connfd = accept(sockfd, NULL, NULL);*/ - /*close(sockfd);*/ - /*if (connfd < 0) {*/ - /*fprintf(stderr, "accept() failed\n");*/ - /*return NULL;*/ - /*}*/ + listen(sockfd, 1); + connfd = accept(sockfd, NULL, NULL); + close(sockfd); + if (connfd < 0) { + fprintf(stderr, "accept() failed\n"); + return NULL; + } - /*n = read(connfd, msg, sizeof msg);*/ - /*if (n != sizeof msg) {*/ - /*perror("server read");*/ - /*fprintf(stderr, "%d/%d: Couldn't read remote address\n", n, (int) sizeof msg);*/ - /*goto out;*/ - /*}*/ + n = read(connfd, msg, sizeof msg); + if (n != sizeof msg) { + perror("server read"); + fprintf(stderr, "%d/%d: Couldn't read remote address\n", n, (int) sizeof msg); + goto out; + } - /*rem_dest = malloc(sizeof *rem_dest);*/ - /*if (!rem_dest)*/ - /*goto out;*/ + rem_dest = malloc(sizeof *rem_dest); + if (!rem_dest) + goto out; - /*sscanf(msg, "%x:%x:%x:%s", &rem_dest->lid, &rem_dest->qpn,*/ - /*&rem_dest->psn, gid);*/ - /*wire_gid_to_gid(gid, &rem_dest->gid);*/ + sscanf(msg, "%x:%x:%x:%s", &rem_dest->lid, &rem_dest->qpn, + &rem_dest->psn, gid); + wire_gid_to_gid(gid, &rem_dest->gid); - /*if (pp_connect_ctx(ctx, ib_port, my_dest->psn, sl, rem_dest,*/ - /*sgid_idx)) {*/ - /*fprintf(stderr, "Couldn't connect to remote QP\n");*/ - /*free(rem_dest);*/ - /*rem_dest = NULL;*/ - /*goto out;*/ - /*}*/ + if (pp_connect_ctx(ctx, ib_port, my_dest->psn, sl, rem_dest, + sgid_idx)) { + fprintf(stderr, "Couldn't connect to remote QP\n"); + free(rem_dest); + rem_dest = NULL; + goto out; + } - /*gid_to_wire_gid(&my_dest->gid, gid);*/ - /*sprintf(msg, "%04x:%06x:%06x:%s", my_dest->lid, my_dest->qpn,*/ - /*my_dest->psn, gid);*/ - /*if (write(connfd, msg, sizeof msg) != sizeof msg ||*/ - /*read(connfd, msg, sizeof msg) != sizeof "done") {*/ - /*fprintf(stderr, "Couldn't send/recv local address\n");*/ - /*free(rem_dest);*/ - /*rem_dest = NULL;*/ - /*goto out;*/ - /*}*/ -/*out:*/ - /*close(connfd);*/ - /*return rem_dest;*/ -/*}*/ + gid_to_wire_gid(&my_dest->gid, gid); + sprintf(msg, "%04x:%06x:%06x:%s", my_dest->lid, my_dest->qpn, + my_dest->psn, gid); + if (write(connfd, msg, sizeof msg) != sizeof msg || + read(connfd, msg, sizeof msg) != sizeof "done") { + fprintf(stderr, "Couldn't send/recv local address\n"); + free(rem_dest); + rem_dest = NULL; + goto out; + } +out: + close(connfd); + return rem_dest; +} static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size, int rx_depth, int port, int use_event) { - printf("LOG: PINGPONG - pp_init_ctx\n"); struct pingpong_context *ctx; - printf("LOG: PINGPONG - pp_init_ctx\n"); ctx = malloc(sizeof *ctx); if (!ctx) return NULL; @@ -322,7 +320,6 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size, ctx->send_flags = IBV_SEND_SIGNALED; ctx->rx_depth = rx_depth; - printf("LOG: PINGPONG - pp_init_ctx\n"); ctx->buf = memalign(page_size, size + 40); if (!ctx->buf) { fprintf(stderr, "Couldn't allocate work buf.\n"); @@ -332,7 +329,6 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size, /* FIXME memset(ctx->buf, 0, size + 40); */ memset(ctx->buf, 0x7b, size + 40); - printf("LOG: PINGPONG - pp_init_ctx\n"); ctx->context = ibv_open_device(ib_dev); if (!ctx->context) { fprintf(stderr, "Couldn't get context for %s\n", @@ -340,7 +336,6 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size, goto clean_buffer; } - printf("LOG: PINGPONG - pp_init_ctx\n"); { struct ibv_port_attr port_info = {}; int mtu; @@ -356,7 +351,6 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size, } } - printf("LOG: PINGPONG - pp_init_ctx\n"); if (use_event) { ctx->channel = ibv_create_comp_channel(ctx->context); if (!ctx->channel) { @@ -366,191 +360,206 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size, } else ctx->channel = NULL; - /*ctx->pd = ibv_alloc_pd(ctx->context);*/ - /*if (!ctx->pd) {*/ - /*fprintf(stderr, "Couldn't allocate PD\n");*/ - /*goto clean_comp_channel;*/ - /*}*/ + ctx->pd = ibv_alloc_pd(ctx->context); + if (!ctx->pd) { + fprintf(stderr, "Couldn't allocate PD\n"); + goto clean_comp_channel; + } - /*ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size + 40, IBV_ACCESS_LOCAL_WRITE);*/ - /*if (!ctx->mr) {*/ - /*fprintf(stderr, "Couldn't register MR\n");*/ - /*goto clean_pd;*/ - /*}*/ + ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size + 40, IBV_ACCESS_LOCAL_WRITE); + if (!ctx->mr) { + fprintf(stderr, "Couldn't register MR\n"); + goto clean_pd; + } - /*ctx->cq = ibv_create_cq(ctx->context, rx_depth + 1, NULL,*/ - /*ctx->channel, 0);*/ - /*if (!ctx->cq) {*/ - /*fprintf(stderr, "Couldn't create CQ\n");*/ - /*goto clean_mr;*/ - /*}*/ + ctx->cq = ibv_create_cq(ctx->context, rx_depth + 1, NULL, ctx->channel, 0); + if (!ctx->cq) { + fprintf(stderr, "Couldn't create CQ\n"); + goto clean_mr; + } - /*{*/ - /*struct ibv_qp_attr attr;*/ - /*struct ibv_qp_init_attr init_attr = {*/ - /*.send_cq = ctx->cq,*/ - /*.recv_cq = ctx->cq,*/ - /*.cap = {*/ - /*.max_send_wr = 1,*/ - /*.max_recv_wr = rx_depth,*/ - /*.max_send_sge = 1,*/ - /*.max_recv_sge = 1*/ - /*},*/ - /*.qp_type = IBV_QPT_UD,*/ - /*};*/ + { + struct ibv_qp_attr attr; + struct ibv_qp_init_attr init_attr = { + .send_cq = ctx->cq, + .recv_cq = ctx->cq, + .cap = { + .max_send_wr = 1, + .max_recv_wr = rx_depth, + .max_send_sge = 1, + .max_recv_sge = 1 + }, + .qp_type = IBV_QPT_UD, + }; - /*ctx->qp = ibv_create_qp(ctx->pd, &init_attr);*/ - /*if (!ctx->qp) {*/ - /*fprintf(stderr, "Couldn't create QP\n");*/ - /*goto clean_cq;*/ - /*}*/ + ctx->qp = ibv_create_qp(ctx->pd, &init_attr); + if (!ctx->qp) { + fprintf(stderr, "Couldn't create QP\n"); + goto clean_cq; + } - /*ibv_query_qp(ctx->qp, &attr, IBV_QP_CAP, &init_attr);*/ - /*if (init_attr.cap.max_inline_data >= size) {*/ - /*ctx->send_flags |= IBV_SEND_INLINE;*/ - /*}*/ - /*}*/ + ibv_query_qp(ctx->qp, &attr, IBV_QP_CAP, &init_attr); + if (init_attr.cap.max_inline_data >= size) { + ctx->send_flags |= IBV_SEND_INLINE; + } + } - /*{*/ - /*struct ibv_qp_attr attr = {*/ - /*.qp_state = IBV_QPS_INIT,*/ - /*.pkey_index = 0,*/ - /*.port_num = port,*/ - /*.qkey = 0x11111111*/ - /*};*/ + { + struct ibv_qp_attr attr = { + .qp_state = IBV_QPS_INIT, + .pkey_index = 0, + .port_num = port, + .qkey = 0x11111111 + }; - /*if (ibv_modify_qp(ctx->qp, &attr,*/ - /*IBV_QP_STATE |*/ - /*IBV_QP_PKEY_INDEX |*/ - /*IBV_QP_PORT |*/ - /*IBV_QP_QKEY)) {*/ - /*fprintf(stderr, "Failed to modify QP to INIT\n");*/ - /*goto clean_qp;*/ - /*}*/ - /*}*/ + if (ibv_modify_qp(ctx->qp, &attr, + IBV_QP_STATE | + IBV_QP_PKEY_INDEX | + IBV_QP_PORT | + IBV_QP_QKEY)) { + fprintf(stderr, "Failed to modify QP to INIT\n"); + goto clean_qp; + } + } - /*return ctx;*/ + return ctx; clean_qp: - /*ibv_destroy_qp(ctx->qp);*/ + ibv_destroy_qp(ctx->qp); clean_cq: - /*ibv_destroy_cq(ctx->cq);*/ + ibv_destroy_cq(ctx->cq); clean_mr: - /*ibv_dereg_mr(ctx->mr);*/ + ibv_dereg_mr(ctx->mr); clean_pd: - /*ibv_dealloc_pd(ctx->pd);*/ + ibv_dealloc_pd(ctx->pd); clean_comp_channel: - /*if (ctx->channel)*/ - /*ibv_destroy_comp_channel(ctx->channel);*/ + if (ctx->channel) + ibv_destroy_comp_channel(ctx->channel); clean_device: - /*ibv_close_device(ctx->context);*/ + ibv_close_device(ctx->context); clean_buffer: - /*free(ctx->buf);*/ + free(ctx->buf); clean_ctx: - /*free(ctx);*/ + free(ctx); return NULL; } -/*static int pp_close_ctx(struct pingpong_context *ctx)*/ -/*{*/ - /*if (ibv_destroy_qp(ctx->qp)) {*/ - /*fprintf(stderr, "Couldn't destroy QP\n");*/ - /*return 1;*/ - /*}*/ +static int pp_close_ctx(struct pingpong_context *ctx) +{ + if (ibv_destroy_qp(ctx->qp)) { + fprintf(stderr, "Couldn't destroy QP\n"); + return 1; + } - /*if (ibv_destroy_cq(ctx->cq)) {*/ - /*fprintf(stderr, "Couldn't destroy CQ\n");*/ - /*return 1;*/ - /*}*/ + if (ibv_destroy_cq(ctx->cq)) { + fprintf(stderr, "Couldn't destroy CQ\n"); + return 1; + } - /*if (ibv_dereg_mr(ctx->mr)) {*/ - /*fprintf(stderr, "Couldn't deregister MR\n");*/ - /*return 1;*/ - /*}*/ + if (ibv_dereg_mr(ctx->mr)) { + fprintf(stderr, "Couldn't deregister MR\n"); + return 1; + } - /*if (ibv_destroy_ah(ctx->ah)) {*/ - /*fprintf(stderr, "Couldn't destroy AH\n");*/ - /*return 1;*/ - /*}*/ + if (ibv_destroy_ah(ctx->ah)) { + fprintf(stderr, "Couldn't destroy AH\n"); + return 1; + } - /*if (ibv_dealloc_pd(ctx->pd)) {*/ - /*fprintf(stderr, "Couldn't deallocate PD\n");*/ - /*return 1;*/ - /*}*/ + if (ibv_dealloc_pd(ctx->pd)) { + fprintf(stderr, "Couldn't deallocate PD\n"); + return 1; + } - /*if (ctx->channel) {*/ - /*if (ibv_destroy_comp_channel(ctx->channel)) {*/ - /*fprintf(stderr, "Couldn't destroy completion channel\n");*/ - /*return 1;*/ - /*}*/ - /*}*/ + if (ctx->channel) { + if (ibv_destroy_comp_channel(ctx->channel)) { + fprintf(stderr, "Couldn't destroy completion channel\n"); + return 1; + } + } - /*if (ibv_close_device(ctx->context)) {*/ - /*fprintf(stderr, "Couldn't release context\n");*/ - /*return 1;*/ - /*}*/ + if (ibv_close_device(ctx->context)) { + fprintf(stderr, "Couldn't release context\n"); + return 1; + } - /*free(ctx->buf);*/ - /*free(ctx);*/ + free(ctx->buf); + free(ctx); - /*return 0;*/ -/*}*/ + return 0; +} -/*static int pp_post_recv(struct pingpong_context *ctx, int n)*/ -/*{*/ - /*struct ibv_sge list = {*/ - /*.addr = (uintptr_t) ctx->buf,*/ - /*.length = ctx->size + 40,*/ - /*.lkey = ctx->mr->lkey*/ - /*};*/ - /*struct ibv_recv_wr wr = {*/ - /*.wr_id = PINGPONG_RECV_WRID,*/ - /*.sg_list = &list,*/ - /*.num_sge = 1,*/ - /*};*/ - /*struct ibv_recv_wr *bad_wr;*/ - /*int i;*/ +// struct ibv_recv_wr { +// uint64_t wr_id; +// struct ibv_recv_wr *next; +// struct ibv_sge *sg_list; +// int num_sge; +// }; - /*for (i = 0; i < n; ++i)*/ - /*if (ibv_post_recv(ctx->qp, &wr, &bad_wr))*/ - /*break;*/ +// struct ibv_sge { // scatter/gather element +// uint64_t addr; // might have to be converted +// uint32_t length; +// uint32_t lkey; +// }; - /*return i;*/ -/*}*/ +static int pp_post_recv(struct pingpong_context *ctx, int n) +{ + struct ibv_sge list = { + .addr = (uintptr_t) ctx->buf, + .length = ctx->size + 40, + .lkey = ctx->mr->lkey + }; + struct ibv_recv_wr wr = { + .wr_id = PINGPONG_RECV_WRID, + .sg_list = &list, + .num_sge = 1, + }; + struct ibv_recv_wr *bad_wr; + int i; -/*static int pp_post_send(struct pingpong_context *ctx, uint32_t qpn)*/ -/*{*/ - /*struct ibv_sge list = {*/ - /*.addr = (uintptr_t) ctx->buf + 40,*/ - /*.length = ctx->size,*/ - /*.lkey = ctx->mr->lkey*/ - /*};*/ - /*struct ibv_send_wr wr = {*/ - /*.wr_id = PINGPONG_SEND_WRID,*/ - /*.sg_list = &list,*/ - /*.num_sge = 1,*/ - /*.opcode = IBV_WR_SEND,*/ - /*.send_flags = ctx->send_flags,*/ - /*.wr = {*/ - /*.ud = {*/ - /*.ah = ctx->ah,*/ - /*.remote_qpn = qpn,*/ - /*.remote_qkey = 0x11111111*/ - /*}*/ - /*}*/ - /*};*/ - /*struct ibv_send_wr *bad_wr;*/ + printf("before for loop calling ibv_post_recv().\n"); + for (i = 0; i < n; ++i) { + printf("loop.\n"); + if (ibv_post_recv(ctx->qp, &wr, &bad_wr)) + break; + } - /*return ibv_post_send(ctx->qp, &wr, &bad_wr);*/ -/*}*/ + return i; +} + +static int pp_post_send(struct pingpong_context *ctx, uint32_t qpn) +{ + struct ibv_sge list = { + .addr = (uintptr_t) ctx->buf + 40, + .length = ctx->size, + .lkey = ctx->mr->lkey + }; + struct ibv_send_wr wr = { + .wr_id = PINGPONG_SEND_WRID, + .sg_list = &list, + .num_sge = 1, + .opcode = IBV_WR_SEND, + .send_flags = ctx->send_flags, + .wr = { + .ud = { + .ah = ctx->ah, + .remote_qpn = qpn, + .remote_qkey = 0x11111111 + } + } + }; + struct ibv_send_wr *bad_wr; + + return ibv_post_send(ctx->qp, &wr, &bad_wr); +} static void usage(const char *argv0) { @@ -572,7 +581,6 @@ static void usage(const char *argv0) int main(int argc, char *argv[]) { - printf("LOG: PINGPONG - main\n"); struct ibv_device **dev_list; struct ibv_device *ib_dev; struct pingpong_context *ctx; @@ -584,7 +592,7 @@ int main(int argc, char *argv[]) unsigned int port = 18515; int ib_port = 1; unsigned int size = 2048; - unsigned int rx_depth = 500; + unsigned int rx_depth = 1; // TODO: set back to 500 unsigned int iters = 1000; int use_event = 0; int routs; @@ -594,14 +602,11 @@ int main(int argc, char *argv[]) int gidx = -1; char gid[33]; - printf("LOG: PINGPONG - main\n"); srand48(getpid() * time(NULL)); - printf("LOG: PINGPONG - main\n"); while (1) { int c; - printf("LOG: PINGPONG - main\n"); static struct option long_options[] = { { .name = "port", .has_arg = 1, .val = 'p' }, { .name = "ib-dev", .has_arg = 1, .val = 'd' }, @@ -708,178 +713,185 @@ int main(int argc, char *argv[]) if (!ctx) return 1; - /*routs = pp_post_recv(ctx, ctx->rx_depth);*/ - /*if (routs < ctx->rx_depth) {*/ - /*fprintf(stderr, "Couldn't post receive (%d)\n", routs);*/ - /*return 1;*/ - /*}*/ + /* printf("before pp_post_recv.\n"); */ + routs = pp_post_recv(ctx, ctx->rx_depth); + /* printf("after pp_post_recv.\n"); */ + if (routs < ctx->rx_depth) { + fprintf(stderr, "Couldn't post receive (%d)\n", routs); + return 1; + } - /*if (use_event)*/ - /*if (ibv_req_notify_cq(ctx->cq, 0)) {*/ - /*fprintf(stderr, "Couldn't request CQ notification\n");*/ - /*return 1;*/ - /*}*/ + if (use_event) + if (ibv_req_notify_cq(ctx->cq, 0)) { + fprintf(stderr, "Couldn't request CQ notification\n"); + return 1; + } - /*if (pp_get_port_info(ctx->context, ib_port, &ctx->portinfo)) {*/ - /*fprintf(stderr, "Couldn't get port info\n");*/ - /*return 1;*/ - /*}*/ - /*my_dest.lid = ctx->portinfo.lid;*/ + if (pp_get_port_info(ctx->context, ib_port, &ctx->portinfo)) { + fprintf(stderr, "Couldn't get port info\n"); + return 1; + } + printf("After pp_get_port_info()\n"); + my_dest.lid = ctx->portinfo.lid; - /*my_dest.qpn = ctx->qp->qp_num;*/ - /*my_dest.psn = lrand48() & 0xffffff;*/ + my_dest.qpn = ctx->qp->qp_num; + my_dest.psn = lrand48() & 0xffffff; - /*if (gidx >= 0) {*/ - /*if (ibv_query_gid(ctx->context, ib_port, gidx, &my_dest.gid)) {*/ - /*fprintf(stderr, "Could not get local gid for gid index "*/ - /*"%d\n", gidx);*/ - /*return 1;*/ - /*}*/ - /*} else*/ - /*memset(&my_dest.gid, 0, sizeof my_dest.gid);*/ + if (gidx >= 0) { + if (ibv_query_gid(ctx->context, ib_port, gidx, &my_dest.gid)) { + fprintf(stderr, "Could not get local gid for gid index " + "%d\n", gidx); + return 1; + } + } else + memset(&my_dest.gid, 0, sizeof my_dest.gid); - /*inet_ntop(AF_INET6, &my_dest.gid, gid, sizeof gid);*/ - /*printf(" local address: LID 0x%04x, QPN 0x%06x, PSN 0x%06x: GID %s\n",*/ - /*my_dest.lid, my_dest.qpn, my_dest.psn, gid);*/ + /* inet_ntop(AF_INET6, &my_dest.gid, gid, sizeof gid); */ + /* printf(" local address: LID 0x%04x, QPN 0x%06x, PSN 0x%06x: GID %s\n", */ + /* my_dest.lid, my_dest.qpn, my_dest.psn, gid); */ - /*if (servername)*/ - /*rem_dest = pp_client_exch_dest(servername, port, &my_dest);*/ - /*else*/ - /*rem_dest = pp_server_exch_dest(ctx, ib_port, port, sl,*/ - /*&my_dest, gidx);*/ + printf("if servername()\n"); + if (servername) + rem_dest = pp_client_exch_dest(servername, port, &my_dest); // no ibv calls + else + rem_dest = pp_server_exch_dest(ctx, ib_port, port, sl, // no ibv calls + &my_dest, gidx); - /*if (!rem_dest)*/ - /*return 1;*/ + if (!rem_dest) + return 1; - /*inet_ntop(AF_INET6, &rem_dest->gid, gid, sizeof gid);*/ - /*printf(" remote address: LID 0x%04x, QPN 0x%06x, PSN 0x%06x, GID %s\n",*/ - /*rem_dest->lid, rem_dest->qpn, rem_dest->psn, gid);*/ + /* inet_ntop(AF_INET6, &rem_dest->gid, gid, sizeof gid); */ + /* printf(" remote address: LID 0x%04x, QPN 0x%06x, PSN 0x%06x, GID %s\n", */ + /* rem_dest->lid, rem_dest->qpn, rem_dest->psn, gid); */ - /*if (servername)*/ - /*if (pp_connect_ctx(ctx, ib_port, my_dest.psn, sl, rem_dest,*/ - /*gidx))*/ - /*return 1;*/ + printf("if servername() 2\n"); + if (servername) + if (pp_connect_ctx(ctx, ib_port, my_dest.psn, sl, rem_dest, + gidx)) + return 1; - /*ctx->pending = PINGPONG_RECV_WRID;*/ + ctx->pending = PINGPONG_RECV_WRID; - /*if (servername) {*/ - /*if (pp_post_send(ctx, rem_dest->qpn)) {*/ - /*fprintf(stderr, "Couldn't post send\n");*/ - /*return 1;*/ - /*}*/ - /*ctx->pending |= PINGPONG_SEND_WRID;*/ - /*}*/ + printf("if servername() 3\n"); + if (servername) { + if (pp_post_send(ctx, rem_dest->qpn)) { + fprintf(stderr, "Couldn't post send\n"); + return 1; + } + ctx->pending |= PINGPONG_SEND_WRID; + } - /*if (gettimeofday(&start, NULL)) {*/ - /*perror("gettimeofday");*/ - /*return 1;*/ - /*}*/ + if (gettimeofday(&start, NULL)) { + perror("gettimeofday"); + return 1; + } - /*rcnt = scnt = 0;*/ - /*while (rcnt < iters || scnt < iters) {*/ - /*if (use_event) {*/ - /*struct ibv_cq *ev_cq;*/ - /*void *ev_ctx;*/ + rcnt = scnt = 0; + while (rcnt < iters || scnt < iters) { + if (use_event) { + struct ibv_cq *ev_cq; + void *ev_ctx; - /*if (ibv_get_cq_event(ctx->channel, &ev_cq, &ev_ctx)) {*/ - /*fprintf(stderr, "Failed to get cq_event\n");*/ - /*return 1;*/ - /*}*/ + if (ibv_get_cq_event(ctx->channel, &ev_cq, &ev_ctx)) { + fprintf(stderr, "Failed to get cq_event\n"); + return 1; + } - /*++num_cq_events;*/ + ++num_cq_events; - /*if (ev_cq != ctx->cq) {*/ - /*fprintf(stderr, "CQ event for unknown CQ %p\n", ev_cq);*/ - /*return 1;*/ - /*}*/ + if (ev_cq != ctx->cq) { + fprintf(stderr, "CQ event for unknown CQ %p\n", ev_cq); + return 1; + } - /*if (ibv_req_notify_cq(ctx->cq, 0)) {*/ - /*fprintf(stderr, "Couldn't request CQ notification\n");*/ - /*return 1;*/ - /*}*/ - /*}*/ + if (ibv_req_notify_cq(ctx->cq, 0)) { + fprintf(stderr, "Couldn't request CQ notification\n"); + return 1; + } + } - /*{*/ - /*struct ibv_wc wc[2];*/ - /*int ne, i;*/ + { + struct ibv_wc wc[2]; + int ne, i; - /*do {*/ - /*ne = ibv_poll_cq(ctx->cq, 2, wc);*/ - /*if (ne < 0) {*/ - /*fprintf(stderr, "poll CQ failed %d\n", ne);*/ - /*return 1;*/ - /*}*/ - /*} while (!use_event && ne < 1);*/ + do { + ne = ibv_poll_cq(ctx->cq, 2, wc); + if (ne < 0) { + fprintf(stderr, "poll CQ failed %d\n", ne); + return 1; + } + } while (!use_event && ne < 1); - /*for (i = 0; i < ne; ++i) {*/ - /*if (wc[i].status != IBV_WC_SUCCESS) {*/ - /*fprintf(stderr, "Failed status %s (%d) for wr_id %d\n",*/ - /*ibv_wc_status_str(wc[i].status),*/ - /*wc[i].status, (int) wc[i].wr_id);*/ - /*return 1;*/ - /*}*/ + for (i = 0; i < ne; ++i) { + if (wc[i].status != IBV_WC_SUCCESS) { + fprintf(stderr, "Failed status %s (%d) for wr_id %d\n", + ibv_wc_status_str(wc[i].status), + wc[i].status, (int) wc[i].wr_id); + return 1; + } - /*switch ((int) wc[i].wr_id) {*/ - /*case PINGPONG_SEND_WRID:*/ - /*++scnt;*/ - /*break;*/ + switch ((int) wc[i].wr_id) { + case PINGPONG_SEND_WRID: + ++scnt; + break; - /*case PINGPONG_RECV_WRID:*/ - /*if (--routs <= 1) {*/ - /*routs += pp_post_recv(ctx, ctx->rx_depth - routs);*/ - /*if (routs < ctx->rx_depth) {*/ - /*fprintf(stderr,*/ - /*"Couldn't post receive (%d)\n",*/ - /*routs);*/ - /*return 1;*/ - /*}*/ - /*}*/ + case PINGPONG_RECV_WRID: + if (--routs <= 1) { + routs += pp_post_recv(ctx, ctx->rx_depth - routs); + if (routs < ctx->rx_depth) { + fprintf(stderr, + "Couldn't post receive (%d)\n", + routs); + return 1; + } + } - /*++rcnt;*/ - /*break;*/ + ++rcnt; + break; - /*default:*/ - /*fprintf(stderr, "Completion for unknown wr_id %d\n",*/ - /*(int) wc[i].wr_id);*/ - /*return 1;*/ - /*}*/ + default: + fprintf(stderr, "Completion for unknown wr_id %d\n", + (int) wc[i].wr_id); + return 1; + } - /*ctx->pending &= ~(int) wc[i].wr_id;*/ - /*if (scnt < iters && !ctx->pending) {*/ - /*if (pp_post_send(ctx, rem_dest->qpn)) {*/ - /*fprintf(stderr, "Couldn't post send\n");*/ - /*return 1;*/ - /*}*/ - /*ctx->pending = PINGPONG_RECV_WRID |*/ - /*PINGPONG_SEND_WRID;*/ - /*}*/ - /*}*/ - /*}*/ - /*}*/ + ctx->pending &= ~(int) wc[i].wr_id; + if (scnt < iters && !ctx->pending) { + if (pp_post_send(ctx, rem_dest->qpn)) { + fprintf(stderr, "Couldn't post send\n"); + return 1; + } + ctx->pending = PINGPONG_RECV_WRID | + PINGPONG_SEND_WRID; + } + } + } + } - /*if (gettimeofday(&end, NULL)) {*/ - /*perror("gettimeofday");*/ - /*return 1;*/ - /*}*/ + if (gettimeofday(&end, NULL)) { + perror("gettimeofday"); + return 1; + } - /*{*/ - /*float usec = (end.tv_sec - start.tv_sec) * 1000000 +*/ - /*(end.tv_usec - start.tv_usec);*/ - /*long long bytes = (long long) size * iters * 2;*/ + { + float usec = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + long long bytes = (long long) size * iters * 2; - /*printf("%lld bytes in %.2f seconds = %.2f Mbit/sec\n",*/ - /*bytes, usec / 1000000., bytes * 8. / usec);*/ - /*printf("%d iters in %.2f seconds = %.2f usec/iter\n",*/ - /*iters, usec / 1000000., usec / iters);*/ - /*}*/ + printf("%lld bytes in %.2f seconds = %.2f Mbit/sec\n", + bytes, usec / 1000000., bytes * 8. / usec); + printf("%d iters in %.2f seconds = %.2f usec/iter\n", + iters, usec / 1000000., usec / iters); + } - /*ibv_ack_cq_events(ctx->cq, num_cq_events);*/ + ibv_ack_cq_events(ctx->cq, num_cq_events); - /*if (pp_close_ctx(ctx))*/ - /*return 1;*/ + if (pp_close_ctx(ctx)) + return 1; - /*ibv_free_device_list(dev_list);*/ - /*free(rem_dest);*/ + ibv_free_device_list(dev_list); + free(rem_dest); + printf("Reached end of ud pingpong."); return 0; } diff --git a/usr/tests/ib/pingpong.c b/usr/tests/ib/pingpong.c index fae8a78a3..31230ddec 100644 --- a/usr/tests/ib/pingpong.c +++ b/usr/tests/ib/pingpong.c @@ -33,10 +33,23 @@ #include "pingpong.h" /*#include // TODO*/ +#include #include #include #include +uint32_t htonl(uint32_t x) { +#if BYTE_ORDER == BIG_ENDIAN + return x; +#else + return __bswap_32 (x); +#endif +} + +uint32_t ntohl(uint32_t x) { + return htonl(x); +} + enum ibv_mtu pp_mtu_to_enum(int mtu) { switch (mtu) { @@ -55,27 +68,27 @@ int pp_get_port_info(struct ibv_context *context, int port, return ibv_query_port(context, port, attr); } -/* void wire_gid_to_gid(const char *wgid, union ibv_gid *gid) */ -/* { */ - /* char tmp[9]; */ - /* __be32 v32; */ - /* int i; */ - /* uint32_t tmp_gid[4]; */ +void wire_gid_to_gid(const char *wgid, union ibv_gid *gid) +{ + char tmp[9]; + __be32 v32; + int i; + uint32_t tmp_gid[4]; - /* for (tmp[8] = 0, i = 0; i < 4; ++i) { */ - /* memcpy(tmp, wgid + i * 8, 8); */ - /* sscanf(tmp, "%x", &v32); */ - /* tmp_gid[i] = be32toh(v32); */ - /* } */ - /* memcpy(gid, tmp_gid, sizeof(*gid)); */ -/* } */ + for (tmp[8] = 0, i = 0; i < 4; ++i) { + memcpy(tmp, wgid + i * 8, 8); + sscanf(tmp, "%x", &v32); + tmp_gid[i] = ntohl(v32); + } + memcpy(gid, tmp_gid, sizeof(*gid)); +} -/* void gid_to_wire_gid(const union ibv_gid *gid, char wgid[]) */ -/* { */ - /* uint32_t tmp_gid[4]; */ - /* int i; */ +void gid_to_wire_gid(const union ibv_gid *gid, char wgid[]) +{ + uint32_t tmp_gid[4]; + int i; - /* memcpy(tmp_gid, gid, sizeof(tmp_gid)); */ - /* for (i = 0; i < 4; ++i) */ - /* sprintf(&wgid[i * 8], "%08x", htobe32(tmp_gid[i])); */ -/* } */ + memcpy(tmp_gid, gid, sizeof(tmp_gid)); + for (i = 0; i < 4; ++i) + sprintf(&wgid[i * 8], "%08x", htonl(tmp_gid[i])); +} diff --git a/usr/tests/ib/pingpong.h b/usr/tests/ib/pingpong.h index 5749e8b07..1cdd81ff2 100644 --- a/usr/tests/ib/pingpong.h +++ b/usr/tests/ib/pingpong.h @@ -35,5 +35,5 @@ enum ibv_mtu pp_mtu_to_enum(int mtu); int pp_get_port_info(struct ibv_context *context, int port, struct ibv_port_attr *attr); -// void wire_gid_to_gid(const char *wgid, union ibv_gid *gid); -// void gid_to_wire_gid(const union ibv_gid *gid, char wgid[]); +void wire_gid_to_gid(const char *wgid, union ibv_gid *gid); +void gid_to_wire_gid(const union ibv_gid *gid, char wgid[]);