2018-02-09 16:15:00 +03:00
|
|
|
/*
|
|
|
|
* QEMU paravirtual RDMA - Generic RDMA backend
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Oracle
|
|
|
|
* Copyright (C) 2018 Red Hat Inc
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Yuval Shaia <yuval.shaia@oracle.com>
|
|
|
|
* Marcel Apfelbaum <marcel@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-12-04 20:25:35 +03:00
|
|
|
#include "qemu/osdep.h"
|
2019-03-11 13:29:05 +03:00
|
|
|
#include "trace.h"
|
2018-02-09 16:15:00 +03:00
|
|
|
#include "rdma_utils.h"
|
|
|
|
|
|
|
|
void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t plen)
|
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
hwaddr len = plen;
|
|
|
|
|
|
|
|
if (!addr) {
|
2019-03-11 13:29:05 +03:00
|
|
|
rdma_error_report("addr is NULL");
|
2018-02-09 16:15:00 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = pci_dma_map(dev, addr, &len, DMA_DIRECTION_TO_DEVICE);
|
|
|
|
if (!p) {
|
2019-03-11 13:29:05 +03:00
|
|
|
rdma_error_report("pci_dma_map fail, addr=0x%"PRIx64", len=%"PRId64,
|
|
|
|
addr, len);
|
2018-02-09 16:15:00 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != plen) {
|
|
|
|
rdma_pci_dma_unmap(dev, p, len);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-03-11 13:29:05 +03:00
|
|
|
trace_rdma_pci_dma_map(addr, p, len);
|
2018-02-09 16:15:00 +03:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len)
|
|
|
|
{
|
2019-03-11 13:29:05 +03:00
|
|
|
trace_rdma_pci_dma_unmap(buffer);
|
2018-02-09 16:15:00 +03:00
|
|
|
if (buffer) {
|
|
|
|
pci_dma_unmap(dev, buffer, len, DMA_DIRECTION_TO_DEVICE, 0);
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 13:29:06 +03:00
|
|
|
|
2020-12-11 20:11:39 +03:00
|
|
|
void rdma_protected_gqueue_init(RdmaProtectedGQueue *list)
|
2019-03-11 13:29:06 +03:00
|
|
|
{
|
|
|
|
qemu_mutex_init(&list->lock);
|
2020-12-11 20:11:39 +03:00
|
|
|
list->list = g_queue_new();
|
2019-03-11 13:29:06 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 20:11:39 +03:00
|
|
|
void rdma_protected_gqueue_destroy(RdmaProtectedGQueue *list)
|
2019-03-11 13:29:06 +03:00
|
|
|
{
|
|
|
|
if (list->list) {
|
2020-12-11 20:11:39 +03:00
|
|
|
g_queue_free_full(list->list, g_free);
|
2019-03-11 13:29:06 +03:00
|
|
|
qemu_mutex_destroy(&list->lock);
|
|
|
|
list->list = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 20:11:39 +03:00
|
|
|
void rdma_protected_gqueue_append_int64(RdmaProtectedGQueue *list,
|
|
|
|
int64_t value)
|
2019-03-11 13:29:06 +03:00
|
|
|
{
|
|
|
|
qemu_mutex_lock(&list->lock);
|
2020-12-11 20:11:39 +03:00
|
|
|
g_queue_push_tail(list->list, g_memdup(&value, sizeof(value)));
|
2019-03-11 13:29:06 +03:00
|
|
|
qemu_mutex_unlock(&list->lock);
|
|
|
|
}
|
|
|
|
|
2020-12-11 20:11:39 +03:00
|
|
|
int64_t rdma_protected_gqueue_pop_int64(RdmaProtectedGQueue *list)
|
2019-03-11 13:29:06 +03:00
|
|
|
{
|
2020-12-11 20:11:39 +03:00
|
|
|
int64_t *valp;
|
|
|
|
int64_t val;
|
2019-03-11 13:29:06 +03:00
|
|
|
|
|
|
|
qemu_mutex_lock(&list->lock);
|
2020-12-11 20:11:39 +03:00
|
|
|
|
|
|
|
valp = g_queue_pop_head(list->list);
|
2019-03-11 13:29:06 +03:00
|
|
|
qemu_mutex_unlock(&list->lock);
|
|
|
|
|
2020-12-11 20:11:39 +03:00
|
|
|
if (!valp) {
|
2019-03-11 13:29:06 +03:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-12-11 20:11:39 +03:00
|
|
|
val = *valp;
|
|
|
|
g_free(valp);
|
|
|
|
return val;
|
2019-03-11 13:29:06 +03:00
|
|
|
}
|
2019-03-11 13:29:11 +03:00
|
|
|
|
|
|
|
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);
|
2020-04-13 11:57:38 +03:00
|
|
|
qemu_mutex_destroy(&list->lock);
|
2019-03-11 13:29:11 +03:00
|
|
|
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);
|
|
|
|
}
|