rdma_backend.h (5591B)
1/* 2 * RDMA device: Definitions of Backend Device functions 3 * 4 * Copyright (C) 2018 Oracle 5 * Copyright (C) 2018 Red Hat Inc 6 * 7 * Authors: 8 * Yuval Shaia <yuval.shaia@oracle.com> 9 * Marcel Apfelbaum <marcel@redhat.com> 10 * 11 * This work is licensed under the terms of the GNU GPL, version 2 or later. 12 * See the COPYING file in the top-level directory. 13 * 14 */ 15 16#ifndef RDMA_BACKEND_H 17#define RDMA_BACKEND_H 18 19#include "qapi/error.h" 20#include "chardev/char-fe.h" 21 22#include "rdma_rm_defs.h" 23#include "rdma_backend_defs.h" 24 25/* Vendor Errors */ 26#define VENDOR_ERR_FAIL_BACKEND 0x201 27#define VENDOR_ERR_TOO_MANY_SGES 0x202 28#define VENDOR_ERR_NOMEM 0x203 29#define VENDOR_ERR_QP0 0x204 30#define VENDOR_ERR_INV_NUM_SGE 0x205 31#define VENDOR_ERR_MAD_SEND 0x206 32#define VENDOR_ERR_INVLKEY 0x207 33#define VENDOR_ERR_MR_SMALL 0x208 34#define VENDOR_ERR_INV_MAD_BUFF 0x209 35#define VENDOR_ERR_INV_GID_IDX 0x210 36 37/* Add definition for QP0 and QP1 as there is no userspace enums for them */ 38enum ibv_special_qp_type { 39 IBV_QPT_SMI = 0, 40 IBV_QPT_GSI = 1, 41}; 42 43static inline uint32_t rdma_backend_qpn(const RdmaBackendQP *qp) 44{ 45 return qp->ibqp ? qp->ibqp->qp_num : 1; 46} 47 48static inline uint32_t rdma_backend_mr_lkey(const RdmaBackendMR *mr) 49{ 50 return mr->ibmr ? mr->ibmr->lkey : 0; 51} 52 53static inline uint32_t rdma_backend_mr_rkey(const RdmaBackendMR *mr) 54{ 55 return mr->ibmr ? mr->ibmr->rkey : 0; 56} 57 58int rdma_backend_init(RdmaBackendDev *backend_dev, PCIDevice *pdev, 59 RdmaDeviceResources *rdma_dev_res, 60 const char *backend_device_name, uint8_t port_num, 61 struct ibv_device_attr *dev_attr, 62 CharBackend *mad_chr_be); 63void rdma_backend_fini(RdmaBackendDev *backend_dev); 64int rdma_backend_add_gid(RdmaBackendDev *backend_dev, const char *ifname, 65 union ibv_gid *gid); 66int rdma_backend_del_gid(RdmaBackendDev *backend_dev, const char *ifname, 67 union ibv_gid *gid); 68int rdma_backend_get_gid_index(RdmaBackendDev *backend_dev, 69 union ibv_gid *gid); 70void rdma_backend_start(RdmaBackendDev *backend_dev); 71void rdma_backend_stop(RdmaBackendDev *backend_dev); 72void rdma_backend_register_comp_handler(void (*handler)(void *ctx, 73 struct ibv_wc *wc)); 74void rdma_backend_unregister_comp_handler(void); 75 76int rdma_backend_query_port(RdmaBackendDev *backend_dev, 77 struct ibv_port_attr *port_attr); 78int rdma_backend_create_pd(RdmaBackendDev *backend_dev, RdmaBackendPD *pd); 79void rdma_backend_destroy_pd(RdmaBackendPD *pd); 80 81int rdma_backend_create_mr(RdmaBackendMR *mr, RdmaBackendPD *pd, void *addr, 82 size_t length, uint64_t guest_start, int access); 83void rdma_backend_destroy_mr(RdmaBackendMR *mr); 84 85int rdma_backend_create_cq(RdmaBackendDev *backend_dev, RdmaBackendCQ *cq, 86 int cqe); 87void rdma_backend_destroy_cq(RdmaBackendCQ *cq); 88void rdma_backend_poll_cq(RdmaDeviceResources *rdma_dev_res, RdmaBackendCQ *cq); 89 90int rdma_backend_create_qp(RdmaBackendQP *qp, uint8_t qp_type, 91 RdmaBackendPD *pd, RdmaBackendCQ *scq, 92 RdmaBackendCQ *rcq, RdmaBackendSRQ *srq, 93 uint32_t max_send_wr, uint32_t max_recv_wr, 94 uint32_t max_send_sge, uint32_t max_recv_sge); 95int rdma_backend_qp_state_init(RdmaBackendDev *backend_dev, RdmaBackendQP *qp, 96 uint8_t qp_type, uint32_t qkey); 97int rdma_backend_qp_state_rtr(RdmaBackendDev *backend_dev, RdmaBackendQP *qp, 98 uint8_t qp_type, uint8_t sgid_idx, 99 union ibv_gid *dgid, uint32_t dqpn, 100 uint32_t rq_psn, uint32_t qkey, bool use_qkey); 101int rdma_backend_qp_state_rts(RdmaBackendQP *qp, uint8_t qp_type, 102 uint32_t sq_psn, uint32_t qkey, bool use_qkey); 103int rdma_backend_query_qp(RdmaBackendQP *qp, struct ibv_qp_attr *attr, 104 int attr_mask, struct ibv_qp_init_attr *init_attr); 105void rdma_backend_destroy_qp(RdmaBackendQP *qp, RdmaDeviceResources *dev_res); 106 107void rdma_backend_post_send(RdmaBackendDev *backend_dev, 108 RdmaBackendQP *qp, uint8_t qp_type, 109 struct ibv_sge *sge, uint32_t num_sge, 110 uint8_t sgid_idx, union ibv_gid *sgid, 111 union ibv_gid *dgid, uint32_t dqpn, uint32_t dqkey, 112 void *ctx); 113void rdma_backend_post_recv(RdmaBackendDev *backend_dev, 114 RdmaBackendQP *qp, uint8_t qp_type, 115 struct ibv_sge *sge, uint32_t num_sge, void *ctx); 116 117int rdma_backend_create_srq(RdmaBackendSRQ *srq, RdmaBackendPD *pd, 118 uint32_t max_wr, uint32_t max_sge, 119 uint32_t srq_limit); 120int rdma_backend_query_srq(RdmaBackendSRQ *srq, struct ibv_srq_attr *srq_attr); 121int rdma_backend_modify_srq(RdmaBackendSRQ *srq, struct ibv_srq_attr *srq_attr, 122 int srq_attr_mask); 123void rdma_backend_destroy_srq(RdmaBackendSRQ *srq, 124 RdmaDeviceResources *dev_res); 125void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev, 126 RdmaBackendSRQ *srq, struct ibv_sge *sge, 127 uint32_t num_sge, void *ctx); 128 129#endif