2 * QEMU VMWARE paravirtual RDMA device definitions
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 PVRDMA_PVRDMA_H
17 #define PVRDMA_PVRDMA_H
19 #include "qemu/units.h"
20 #include "qemu/notify.h"
21 #include "hw/pci/pci.h"
22 #include "hw/pci/msix.h"
23 #include "chardev/char-fe.h"
24 #include "hw/net/vmxnet3_defs.h"
26 #include "../rdma_backend_defs.h"
27 #include "../rdma_rm_defs.h"
29 #include "standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h"
30 #include "pvrdma_dev_ring.h"
31 #include "qom/object.h"
34 #define RDMA_MSIX_BAR_IDX 0
35 #define RDMA_REG_BAR_IDX 1
36 #define RDMA_UAR_BAR_IDX 2
37 #define RDMA_BAR0_MSIX_SIZE (16 * KiB)
38 #define RDMA_BAR1_REGS_SIZE 64
39 #define RDMA_BAR2_UAR_SIZE (0x1000 * MAX_UCS) /* each uc gets page */
42 #define RDMA_MAX_INTRS 3
43 #define RDMA_MSIX_TABLE 0x0000
44 #define RDMA_MSIX_PBA 0x2000
46 /* Interrupts Vectors */
47 #define INTR_VEC_CMD_RING 0
48 #define INTR_VEC_CMD_ASYNC_EVENTS 1
49 #define INTR_VEC_CMD_COMPLETION_Q 2
52 #define PVRDMA_HW_NAME "pvrdma"
53 #define PVRDMA_HW_VERSION 17
54 #define PVRDMA_FW_VERSION 14
57 #define PVRDMA_PKEY 0xFFFF
59 typedef struct DSRInfo
{
61 struct pvrdma_device_shared_region
*dsr
;
63 union pvrdma_cmd_req
*req
;
64 union pvrdma_cmd_resp
*rsp
;
66 PvrdmaRingState
*async_ring_state
;
69 PvrdmaRingState
*cq_ring_state
;
73 typedef struct PVRDMADevStats
{
85 uint32_t regs_data
[RDMA_BAR1_REGS_SIZE
];
87 uint32_t uar_data
[RDMA_BAR2_UAR_SIZE
];
90 struct ibv_device_attr dev_attr
;
92 char *backend_eth_device_name
;
93 char *backend_device_name
;
94 uint8_t backend_port_num
;
95 RdmaBackendDev backend_dev
;
96 RdmaDeviceResources rdma_dev_res
;
99 Notifier shutdown_notifier
;
100 PVRDMADevStats stats
;
102 typedef struct PVRDMADev PVRDMADev
;
103 DECLARE_INSTANCE_CHECKER(PVRDMADev
, PVRDMA_DEV
,
106 static inline int get_reg_val(PVRDMADev
*dev
, hwaddr addr
, uint32_t *val
)
110 if (idx
>= RDMA_BAR1_REGS_SIZE
) {
114 *val
= dev
->regs_data
[idx
];
119 static inline int set_reg_val(PVRDMADev
*dev
, hwaddr addr
, uint32_t val
)
123 if (idx
>= RDMA_BAR1_REGS_SIZE
) {
127 dev
->regs_data
[idx
] = val
;
132 static inline void post_interrupt(PVRDMADev
*dev
, unsigned vector
)
134 PCIDevice
*pci_dev
= PCI_DEVICE(dev
);
136 if (likely(!dev
->interrupt_mask
)) {
137 dev
->stats
.interrupts
++;
138 msix_notify(pci_dev
, vector
);
142 int pvrdma_exec_cmd(PVRDMADev
*dev
);