[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 05/21] nvme: allow completion queues in the cmb
From: |
Klaus Jensen |
Subject: |
[PATCH v3 05/21] nvme: allow completion queues in the cmb |
Date: |
Mon, 11 Nov 2019 13:25:29 +0100 |
Allow completion queues in the controller memory buffer.
This also inlines the nvme_addr_{read,write} functions and adds an
nvme_addr_is_cmb helper.
Signed-off-by: Klaus Jensen <address@hidden>
---
hw/block/nvme.c | 38 +++++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 16f0fba10b08..daa2367b0863 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -52,14 +52,34 @@
static void nvme_process_sq(void *opaque);
-static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size)
+static inline bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr)
{
- if (n->cmbsz && addr >= n->ctrl_mem.addr &&
- addr < (n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size))) {
- memcpy(buf, (void *)&n->cmbuf[addr - n->ctrl_mem.addr], size);
- } else {
- pci_dma_read(&n->parent_obj, addr, buf, size);
+ hwaddr low = n->ctrl_mem.addr;
+ hwaddr hi = n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size);
+
+ return addr >= low && addr < hi;
+}
+
+static inline void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf,
+ int size)
+{
+ if (n->cmbsz && nvme_addr_is_cmb(n, addr)) {
+ memcpy(buf, (void *) &n->cmbuf[addr - n->ctrl_mem.addr], size);
+ return;
}
+
+ pci_dma_read(&n->parent_obj, addr, buf, size);
+}
+
+static inline void nvme_addr_write(NvmeCtrl *n, hwaddr addr, void *buf,
+ int size)
+{
+ if (n->cmbsz && nvme_addr_is_cmb(n, addr)) {
+ memcpy((void *) &n->cmbuf[addr - n->ctrl_mem.addr], buf, size);
+ return;
+ }
+
+ pci_dma_write(&n->parent_obj, addr, buf, size);
}
static int nvme_check_sqid(NvmeCtrl *n, uint16_t sqid)
@@ -281,6 +301,7 @@ static void nvme_post_cqes(void *opaque)
QTAILQ_FOREACH_SAFE(req, &cq->req_list, entry, next) {
NvmeSQueue *sq;
+ NvmeCqe *cqe = &req->cqe;
hwaddr addr;
if (nvme_cq_full(cq)) {
@@ -294,8 +315,7 @@ static void nvme_post_cqes(void *opaque)
req->cqe.sq_head = cpu_to_le16(sq->head);
addr = cq->dma_addr + cq->tail * n->cqe_size;
nvme_inc_cq_tail(cq);
- pci_dma_write(&n->parent_obj, addr, (void *)&req->cqe,
- sizeof(req->cqe));
+ nvme_addr_write(n, addr, (void *) cqe, sizeof(*cqe));
QTAILQ_INSERT_TAIL(&sq->req_list, req, entry);
}
if (cq->tail != cq->head) {
@@ -1401,7 +1421,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
NVME_CMBLOC_SET_OFST(n->bar.cmbloc, 0);
NVME_CMBSZ_SET_SQS(n->bar.cmbsz, 1);
- NVME_CMBSZ_SET_CQS(n->bar.cmbsz, 0);
+ NVME_CMBSZ_SET_CQS(n->bar.cmbsz, 1);
NVME_CMBSZ_SET_LISTS(n->bar.cmbsz, 0);
NVME_CMBSZ_SET_RDS(n->bar.cmbsz, 1);
NVME_CMBSZ_SET_WDS(n->bar.cmbsz, 1);
--
2.24.0
- [PATCH v3 00/20] nvme: support NVMe v1.3d, SGLs and multiple namespaces, Klaus Jensen, 2019/11/11
- [PATCH v3 06/21] nvme: add support for the abort command, Klaus Jensen, 2019/11/11
- [PATCH v3 01/21] nvme: remove superfluous breaks, Klaus Jensen, 2019/11/11
- [PATCH v3 03/21] nvme: add missing fields in the identify controller data structure, Klaus Jensen, 2019/11/11
- [PATCH v3 10/21] nvme: add logging to error information log page, Klaus Jensen, 2019/11/11
- [PATCH v3 05/21] nvme: allow completion queues in the cmb,
Klaus Jensen <=
- [PATCH v3 04/21] nvme: populate the mandatory subnqn and ver fields, Klaus Jensen, 2019/11/11
- [PATCH v3 02/21] nvme: move device parameters to separate struct, Klaus Jensen, 2019/11/11
- [PATCH v3 08/21] nvme: add support for the get log page command, Klaus Jensen, 2019/11/11
- [PATCH v3 07/21] nvme: refactor device realization, Klaus Jensen, 2019/11/11
- [PATCH v3 09/21] nvme: add support for the asynchronous event request command, Klaus Jensen, 2019/11/11
- [PATCH v3 11/21] nvme: add missing mandatory features, Klaus Jensen, 2019/11/11
- [PATCH v3 17/21] nvme: bump controller pci device id, Klaus Jensen, 2019/11/11
- [PATCH v3 21/21] nvme: handle dma errors, Klaus Jensen, 2019/11/11
- [PATCH v3 19/21] nvme: make lba data size configurable, Klaus Jensen, 2019/11/11
- [PATCH v3 20/21] pci: pass along the return value of dma_memory_rw, Klaus Jensen, 2019/11/11