]>
Commit | Line | Data |
---|---|---|
dcbf469a YS |
1 | /* |
2 | * QEMU paravirtual RDMA - Generic RDMA backend | |
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 | ||
b7d89466 | 16 | #include "qemu/osdep.h" |
edf5ca5d | 17 | #include "hw/pci/pci_device.h" |
4d71b38a | 18 | #include "trace.h" |
dcbf469a YS |
19 | #include "rdma_utils.h" |
20 | ||
ce0a7982 | 21 | void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t len) |
dcbf469a YS |
22 | { |
23 | void *p; | |
bfa30f39 | 24 | dma_addr_t pci_len = len; |
dcbf469a YS |
25 | |
26 | if (!addr) { | |
4d71b38a | 27 | rdma_error_report("addr is NULL"); |
dcbf469a YS |
28 | return NULL; |
29 | } | |
30 | ||
ce0a7982 | 31 | p = pci_dma_map(dev, addr, &pci_len, DMA_DIRECTION_TO_DEVICE); |
dcbf469a | 32 | if (!p) { |
4d71b38a | 33 | rdma_error_report("pci_dma_map fail, addr=0x%"PRIx64", len=%"PRId64, |
ce0a7982 | 34 | addr, pci_len); |
dcbf469a YS |
35 | return NULL; |
36 | } | |
37 | ||
ce0a7982 PMD |
38 | if (pci_len != len) { |
39 | rdma_pci_dma_unmap(dev, p, pci_len); | |
dcbf469a YS |
40 | return NULL; |
41 | } | |
42 | ||
ce0a7982 | 43 | trace_rdma_pci_dma_map(addr, p, pci_len); |
dcbf469a YS |
44 | |
45 | return p; | |
46 | } | |
47 | ||
48 | void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len) | |
49 | { | |
4d71b38a | 50 | trace_rdma_pci_dma_unmap(buffer); |
dcbf469a YS |
51 | if (buffer) { |
52 | pci_dma_unmap(dev, buffer, len, DMA_DIRECTION_TO_DEVICE, 0); | |
53 | } | |
54 | } | |
b20fc795 | 55 | |
bce80086 | 56 | void rdma_protected_gqueue_init(RdmaProtectedGQueue *list) |
b20fc795 YS |
57 | { |
58 | qemu_mutex_init(&list->lock); | |
bce80086 | 59 | list->list = g_queue_new(); |
b20fc795 YS |
60 | } |
61 | ||
bce80086 | 62 | void rdma_protected_gqueue_destroy(RdmaProtectedGQueue *list) |
b20fc795 YS |
63 | { |
64 | if (list->list) { | |
bce80086 | 65 | g_queue_free_full(list->list, g_free); |
b20fc795 YS |
66 | qemu_mutex_destroy(&list->lock); |
67 | list->list = NULL; | |
68 | } | |
69 | } | |
70 | ||
bce80086 MA |
71 | void rdma_protected_gqueue_append_int64(RdmaProtectedGQueue *list, |
72 | int64_t value) | |
b20fc795 YS |
73 | { |
74 | qemu_mutex_lock(&list->lock); | |
bce80086 | 75 | g_queue_push_tail(list->list, g_memdup(&value, sizeof(value))); |
b20fc795 YS |
76 | qemu_mutex_unlock(&list->lock); |
77 | } | |
78 | ||
bce80086 | 79 | int64_t rdma_protected_gqueue_pop_int64(RdmaProtectedGQueue *list) |
b20fc795 | 80 | { |
bce80086 MA |
81 | int64_t *valp; |
82 | int64_t val; | |
b20fc795 YS |
83 | |
84 | qemu_mutex_lock(&list->lock); | |
bce80086 MA |
85 | |
86 | valp = g_queue_pop_head(list->list); | |
b20fc795 YS |
87 | qemu_mutex_unlock(&list->lock); |
88 | ||
bce80086 | 89 | if (!valp) { |
b20fc795 YS |
90 | return -ENOENT; |
91 | } | |
92 | ||
bce80086 MA |
93 | val = *valp; |
94 | g_free(valp); | |
95 | return val; | |
b20fc795 | 96 | } |
bf441451 YS |
97 | |
98 | void rdma_protected_gslist_init(RdmaProtectedGSList *list) | |
99 | { | |
100 | qemu_mutex_init(&list->lock); | |
101 | } | |
102 | ||
103 | void rdma_protected_gslist_destroy(RdmaProtectedGSList *list) | |
104 | { | |
105 | if (list->list) { | |
106 | g_slist_free(list->list); | |
a5cde048 | 107 | qemu_mutex_destroy(&list->lock); |
bf441451 YS |
108 | list->list = NULL; |
109 | } | |
110 | } | |
111 | ||
112 | void rdma_protected_gslist_append_int32(RdmaProtectedGSList *list, | |
113 | int32_t value) | |
114 | { | |
115 | qemu_mutex_lock(&list->lock); | |
116 | list->list = g_slist_prepend(list->list, GINT_TO_POINTER(value)); | |
117 | qemu_mutex_unlock(&list->lock); | |
118 | } | |
119 | ||
120 | void rdma_protected_gslist_remove_int32(RdmaProtectedGSList *list, | |
121 | int32_t value) | |
122 | { | |
123 | qemu_mutex_lock(&list->lock); | |
124 | list->list = g_slist_remove(list->list, GINT_TO_POINTER(value)); | |
125 | qemu_mutex_unlock(&list->lock); | |
126 | } |