]> git.proxmox.com Git - mirror_qemu.git/blob - hw/rdma/rdma_backend.h
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[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, PCIDevice *pdev,
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_start(RdmaBackendDev *backend_dev);
56 void rdma_backend_stop(RdmaBackendDev *backend_dev);
57 void rdma_backend_register_comp_handler(void (*handler)(int status,
58 unsigned int vendor_err, void *ctx));
59 void rdma_backend_unregister_comp_handler(void);
60
61 int rdma_backend_query_port(RdmaBackendDev *backend_dev,
62 struct ibv_port_attr *port_attr);
63 int rdma_backend_create_pd(RdmaBackendDev *backend_dev, RdmaBackendPD *pd);
64 void rdma_backend_destroy_pd(RdmaBackendPD *pd);
65
66 int rdma_backend_create_mr(RdmaBackendMR *mr, RdmaBackendPD *pd, void *addr,
67 size_t length, int access);
68 void rdma_backend_destroy_mr(RdmaBackendMR *mr);
69
70 int rdma_backend_create_cq(RdmaBackendDev *backend_dev, RdmaBackendCQ *cq,
71 int cqe);
72 void rdma_backend_destroy_cq(RdmaBackendCQ *cq);
73 void rdma_backend_poll_cq(RdmaDeviceResources *rdma_dev_res, RdmaBackendCQ *cq);
74
75 int rdma_backend_create_qp(RdmaBackendQP *qp, uint8_t qp_type,
76 RdmaBackendPD *pd, RdmaBackendCQ *scq,
77 RdmaBackendCQ *rcq, uint32_t max_send_wr,
78 uint32_t max_recv_wr, uint32_t max_send_sge,
79 uint32_t max_recv_sge);
80 int rdma_backend_qp_state_init(RdmaBackendDev *backend_dev, RdmaBackendQP *qp,
81 uint8_t qp_type, uint32_t qkey);
82 int rdma_backend_qp_state_rtr(RdmaBackendDev *backend_dev, RdmaBackendQP *qp,
83 uint8_t qp_type, union ibv_gid *dgid,
84 uint32_t dqpn, uint32_t rq_psn, uint32_t qkey,
85 bool use_qkey);
86 int rdma_backend_qp_state_rts(RdmaBackendQP *qp, uint8_t qp_type,
87 uint32_t sq_psn, uint32_t qkey, bool use_qkey);
88 int rdma_backend_query_qp(RdmaBackendQP *qp, struct ibv_qp_attr *attr,
89 int attr_mask, struct ibv_qp_init_attr *init_attr);
90 void rdma_backend_destroy_qp(RdmaBackendQP *qp);
91
92 void rdma_backend_post_send(RdmaBackendDev *backend_dev,
93 RdmaBackendQP *qp, uint8_t qp_type,
94 struct ibv_sge *sge, uint32_t num_sge,
95 union ibv_gid *dgid, uint32_t dqpn, uint32_t dqkey,
96 void *ctx);
97 void rdma_backend_post_recv(RdmaBackendDev *backend_dev,
98 RdmaDeviceResources *rdma_dev_res,
99 RdmaBackendQP *qp, uint8_t qp_type,
100 struct ibv_sge *sge, uint32_t num_sge, void *ctx);
101
102 #endif