2 * RDMA device: Definitions of Backend Device functions
4 * Copyright (C) 2018 Oracle
5 * Copyright (C) 2018 Red Hat Inc
8 * Yuval Shaia <yuval.shaia@oracle.com>
9 * Marcel Apfelbaum <marcel@redhat.com>
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.
16 #ifndef RDMA_BACKEND_H
17 #define RDMA_BACKEND_H
19 #include "qapi/error.h"
20 #include "chardev/char-fe.h"
22 #include "rdma_rm_defs.h"
23 #include "rdma_backend_defs.h"
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
37 /* Add definition for QP0 and QP1 as there is no userspace enums for them */
38 enum ibv_special_qp_type
{
43 static inline uint32_t rdma_backend_qpn(const RdmaBackendQP
*qp
)
45 return qp
->ibqp
? qp
->ibqp
->qp_num
: 1;
48 static inline uint32_t rdma_backend_mr_lkey(const RdmaBackendMR
*mr
)
50 return mr
->ibmr
? mr
->ibmr
->lkey
: 0;
53 static inline uint32_t rdma_backend_mr_rkey(const RdmaBackendMR
*mr
)
55 return mr
->ibmr
? mr
->ibmr
->rkey
: 0;
58 int 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
, CharBackend
*mad_chr_be
,
63 void rdma_backend_fini(RdmaBackendDev
*backend_dev
);
64 int rdma_backend_add_gid(RdmaBackendDev
*backend_dev
, const char *ifname
,
66 int rdma_backend_del_gid(RdmaBackendDev
*backend_dev
, const char *ifname
,
68 int rdma_backend_get_gid_index(RdmaBackendDev
*backend_dev
,
70 void rdma_backend_start(RdmaBackendDev
*backend_dev
);
71 void rdma_backend_stop(RdmaBackendDev
*backend_dev
);
72 void rdma_backend_register_comp_handler(void (*handler
)(void *ctx
,
74 void rdma_backend_unregister_comp_handler(void);
76 int rdma_backend_query_port(RdmaBackendDev
*backend_dev
,
77 struct ibv_port_attr
*port_attr
);
78 int rdma_backend_create_pd(RdmaBackendDev
*backend_dev
, RdmaBackendPD
*pd
);
79 void rdma_backend_destroy_pd(RdmaBackendPD
*pd
);
81 int rdma_backend_create_mr(RdmaBackendMR
*mr
, RdmaBackendPD
*pd
, void *addr
,
82 size_t length
, int access
);
83 void rdma_backend_destroy_mr(RdmaBackendMR
*mr
);
85 int rdma_backend_create_cq(RdmaBackendDev
*backend_dev
, RdmaBackendCQ
*cq
,
87 void rdma_backend_destroy_cq(RdmaBackendCQ
*cq
);
88 void rdma_backend_poll_cq(RdmaDeviceResources
*rdma_dev_res
, RdmaBackendCQ
*cq
);
90 int rdma_backend_create_qp(RdmaBackendQP
*qp
, uint8_t qp_type
,
91 RdmaBackendPD
*pd
, RdmaBackendCQ
*scq
,
92 RdmaBackendCQ
*rcq
, uint32_t max_send_wr
,
93 uint32_t max_recv_wr
, uint32_t max_send_sge
,
94 uint32_t max_recv_sge
);
95 int rdma_backend_qp_state_init(RdmaBackendDev
*backend_dev
, RdmaBackendQP
*qp
,
96 uint8_t qp_type
, uint32_t qkey
);
97 int 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
);
101 int rdma_backend_qp_state_rts(RdmaBackendQP
*qp
, uint8_t qp_type
,
102 uint32_t sq_psn
, uint32_t qkey
, bool use_qkey
);
103 int rdma_backend_query_qp(RdmaBackendQP
*qp
, struct ibv_qp_attr
*attr
,
104 int attr_mask
, struct ibv_qp_init_attr
*init_attr
);
105 void rdma_backend_destroy_qp(RdmaBackendQP
*qp
);
107 void 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
,
113 void rdma_backend_post_recv(RdmaBackendDev
*backend_dev
,
114 RdmaDeviceResources
*rdma_dev_res
,
115 RdmaBackendQP
*qp
, uint8_t qp_type
,
116 struct ibv_sge
*sge
, uint32_t num_sge
, void *ctx
);