typedef struct BackendCtx {
void *up_ctx;
struct ibv_sge sge; /* Used to save MAD recv buffer */
+ RdmaBackendQP *backend_qp; /* To maintain recv buffers */
} BackendCtx;
struct backend_umad {
bctx = rdma_rm_get_cqe_ctx(rdma_dev_res, cqe_ctx_id);
if (bctx) {
rdma_rm_dealloc_cqe_ctx(rdma_dev_res, cqe_ctx_id);
+ atomic_dec(&rdma_dev_res->stats.missing_cqe);
}
g_free(bctx);
}
cqe_ctx_id = rdma_protected_qlist_pop_int64(&backend_dev->
recv_mads_list);
if (cqe_ctx_id != -ENOENT) {
+ atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
free_cqe_ctx(GINT_TO_POINTER(cqe_ctx_id),
backend_dev->rdma_dev_res);
}
} while (cqe_ctx_id != -ENOENT);
}
-static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq *ibcq)
+static int rdma_poll_cq(RdmaBackendDev *backend_dev,
+ RdmaDeviceResources *rdma_dev_res, struct ibv_cq *ibcq)
{
int i, ne, total_ne = 0;
BackendCtx *bctx;
comp_handler(bctx->up_ctx, &wc[i]);
+ rdma_protected_gslist_remove_int32(&bctx->backend_qp->cqe_ctx_list,
+ wc[i].wr_id);
rdma_rm_dealloc_cqe_ctx(rdma_dev_res, wc[i].wr_id);
g_free(bctx);
}
}
backend_dev->rdma_dev_res->stats.poll_cq_from_bk++;
- rdma_poll_cq(backend_dev->rdma_dev_res, ev_cq);
+ rdma_poll_cq(backend_dev, backend_dev->rdma_dev_res, ev_cq);
ibv_ack_cq_events(ev_cq, 1);
}
}
- /* TODO: Post cqe for all remaining buffs that were posted */
-
backend_dev->comp_thread.is_running = false;
qemu_thread_exit(0);
int polled;
rdma_dev_res->stats.poll_cq_from_guest++;
- polled = rdma_poll_cq(rdma_dev_res, cq->ibcq);
+ polled = rdma_poll_cq(cq->backend_dev, rdma_dev_res, cq->ibcq);
if (!polled) {
rdma_dev_res->stats.poll_cq_from_guest_empty++;
}
bctx = g_malloc0(sizeof(*bctx));
bctx->up_ctx = ctx;
+ bctx->backend_qp = qp;
rc = rdma_rm_alloc_cqe_ctx(backend_dev->rdma_dev_res, &bctx_id, bctx);
if (unlikely(rc)) {
goto err_free_bctx;
}
+ rdma_protected_gslist_append_int32(&qp->cqe_ctx_list, bctx_id);
+
rc = build_host_sge_array(backend_dev->rdma_dev_res, new_sge, sge, num_sge,
&backend_dev->rdma_dev_res->stats.tx_len);
if (rc) {
bctx = g_malloc0(sizeof(*bctx));
bctx->up_ctx = ctx;
+ bctx->backend_qp = qp;
rc = rdma_rm_alloc_cqe_ctx(rdma_dev_res, &bctx_id, bctx);
if (unlikely(rc)) {
goto err_free_bctx;
}
+ rdma_protected_gslist_append_int32(&qp->cqe_ctx_list, bctx_id);
+
rc = build_host_sge_array(rdma_dev_res, new_sge, sge, num_sge,
&backend_dev->rdma_dev_res->stats.rx_bufs_len);
if (rc) {
return -EIO;
}
+ rdma_protected_gslist_init(&qp->cqe_ctx_list);
+
qp->ibpd = pd->ibpd;
/* TODO: Query QP to get max_inline_data and save it to be used in send */
return ibv_query_qp(qp->ibqp, attr, attr_mask, init_attr);
}
-void rdma_backend_destroy_qp(RdmaBackendQP *qp)
+void rdma_backend_destroy_qp(RdmaBackendQP *qp, RdmaDeviceResources *dev_res)
{
if (qp->ibqp) {
ibv_destroy_qp(qp->ibqp);
}
+ g_slist_foreach(qp->cqe_ctx_list.list, free_cqe_ctx, dev_res);
+ rdma_protected_gslist_destroy(&qp->cqe_ctx_list);
}
#define CHK_ATTR(req, dev, member, fmt) ({ \
return qnum_get_uint(qobject_to(QNum, obj));
}
+
+void rdma_protected_gslist_init(RdmaProtectedGSList *list)
+{
+ qemu_mutex_init(&list->lock);
+}
+
+void rdma_protected_gslist_destroy(RdmaProtectedGSList *list)
+{
+ if (list->list) {
+ g_slist_free(list->list);
+ list->list = NULL;
+ }
+}
+
+void rdma_protected_gslist_append_int32(RdmaProtectedGSList *list,
+ int32_t value)
+{
+ qemu_mutex_lock(&list->lock);
+ list->list = g_slist_prepend(list->list, GINT_TO_POINTER(value));
+ qemu_mutex_unlock(&list->lock);
+}
+
+void rdma_protected_gslist_remove_int32(RdmaProtectedGSList *list,
+ int32_t value)
+{
+ qemu_mutex_lock(&list->lock);
+ list->list = g_slist_remove(list->list, GINT_TO_POINTER(value));
+ qemu_mutex_unlock(&list->lock);
+}
QList *list;
} RdmaProtectedQList;
+typedef struct RdmaProtectedGSList {
+ QemuMutex lock;
+ GSList *list;
+} RdmaProtectedGSList;
+
void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t plen);
void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len);
void rdma_protected_qlist_init(RdmaProtectedQList *list);
void rdma_protected_qlist_destroy(RdmaProtectedQList *list);
void rdma_protected_qlist_append_int64(RdmaProtectedQList *list, int64_t value);
int64_t rdma_protected_qlist_pop_int64(RdmaProtectedQList *list);
+void rdma_protected_gslist_init(RdmaProtectedGSList *list);
+void rdma_protected_gslist_destroy(RdmaProtectedGSList *list);
+void rdma_protected_gslist_append_int32(RdmaProtectedGSList *list,
+ int32_t value);
+void rdma_protected_gslist_remove_int32(RdmaProtectedGSList *list,
+ int32_t value);
static inline void addrconf_addr_eui48(uint8_t *eui, const char *addr)
{