]> git.proxmox.com Git - mirror_qemu.git/blob - hw/rdma/rdma_backend.h
hw/rdma: Implementation of generic rdma device layers
[mirror_qemu.git] / hw / rdma / rdma_backend.h
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 "rdma_rm_defs.h"
21 #include "rdma_backend_defs.h"
22
23 /* Add definition for QP0 and QP1 as there is no userspace enums for them */
24 enum ibv_special_qp_type {
25 IBV_QPT_SMI = 0,
26 IBV_QPT_GSI = 1,
27 };
28
29 static inline union ibv_gid *rdma_backend_gid(RdmaBackendDev *dev)
30 {
31 return &dev->gid;
32 }
33
34 static inline uint32_t rdma_backend_qpn(const RdmaBackendQP *qp)
35 {
36 return qp->ibqp ? qp->ibqp->qp_num : 0;
37 }
38
39 static inline uint32_t rdma_backend_mr_lkey(const RdmaBackendMR *mr)
40 {
41 return mr->ibmr ? mr->ibmr->lkey : 0;
42 }
43
44 static inline uint32_t rdma_backend_mr_rkey(const RdmaBackendMR *mr)
45 {
46 return mr->ibmr ? mr->ibmr->rkey : 0;
47 }
48
49 int rdma_backend_init(RdmaBackendDev *backend_dev,
50 RdmaDeviceResources *rdma_dev_res,
51 const char *backend_device_name, uint8_t port_num,
52 uint8_t backend_gid_idx, struct ibv_device_attr *dev_attr,
53 Error **errp);
54 void rdma_backend_fini(RdmaBackendDev *backend_dev);
55 void rdma_backend_register_comp_handler(void (*handler)(int status,
56 unsigned int vendor_err, void *ctx));
57 void rdma_backend_unregister_comp_handler(void);
58
59 int rdma_backend_query_port(RdmaBackendDev *backend_dev,
60 struct ibv_port_attr *port_attr);
61 int rdma_backend_create_pd(RdmaBackendDev *backend_dev, RdmaBackendPD *pd);
62 void rdma_backend_destroy_pd(RdmaBackendPD *pd);
63
64 int rdma_backend_create_mr(RdmaBackendMR *mr, RdmaBackendPD *pd, uint64_t addr,
65 size_t length, int access);
66 void rdma_backend_destroy_mr(RdmaBackendMR *mr);
67
68 int rdma_backend_create_cq(RdmaBackendDev *backend_dev, RdmaBackendCQ *cq,
69 int cqe);
70 void rdma_backend_destroy_cq(RdmaBackendCQ *cq);
71 void rdma_backend_poll_cq(RdmaDeviceResources *rdma_dev_res, RdmaBackendCQ *cq);
72
73 int rdma_backend_create_qp(RdmaBackendQP *qp, uint8_t qp_type,
74 RdmaBackendPD *pd, RdmaBackendCQ *scq,
75 RdmaBackendCQ *rcq, uint32_t max_send_wr,
76 uint32_t max_recv_wr, uint32_t max_send_sge,
77 uint32_t max_recv_sge);
78 int rdma_backend_qp_state_init(RdmaBackendDev *backend_dev, RdmaBackendQP *qp,
79 uint8_t qp_type, uint32_t qkey);
80 int rdma_backend_qp_state_rtr(RdmaBackendDev *backend_dev, RdmaBackendQP *qp,
81 uint8_t qp_type, union ibv_gid *dgid,
82 uint32_t dqpn, uint32_t rq_psn, uint32_t qkey,
83 bool use_qkey);
84 int rdma_backend_qp_state_rts(RdmaBackendQP *qp, uint8_t qp_type,
85 uint32_t sq_psn, uint32_t qkey, bool use_qkey);
86 void rdma_backend_destroy_qp(RdmaBackendQP *qp);
87
88 void rdma_backend_post_send(RdmaBackendDev *backend_dev,
89 RdmaBackendQP *qp, uint8_t qp_type,
90 struct ibv_sge *sge, uint32_t num_sge,
91 union ibv_gid *dgid, uint32_t dqpn, uint32_t dqkey,
92 void *ctx);
93 void rdma_backend_post_recv(RdmaBackendDev *backend_dev,
94 RdmaDeviceResources *rdma_dev_res,
95 RdmaBackendQP *qp, uint8_t qp_type,
96 struct ibv_sge *sge, uint32_t num_sge, void *ctx);
97
98 #endif