From eecc6dc8e6645d889a1f8466e7903ced1a048c70 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Mon, 7 Jan 2019 13:05:17 +0100 Subject: [PATCH] memory: replace all hardcoded 0x200000 with a define Makes the code slightly more readable. Change-Id: Iebf8fb07bceacf433d4bdad0a30419a3faab7eee Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/439370 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- lib/ioat/ioat.c | 6 +++--- lib/nvme/nvme_internal.h | 3 ++- lib/nvme/nvme_pcie.c | 11 ++++------- lib/vhost/vhost.c | 4 ++-- lib/virtio/virtio_pci.c | 5 +++-- test/nvme/e2edp/nvme_dp.c | 6 ++++-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/ioat/ioat.c b/lib/ioat/ioat.c index 1d0fe4541..29f2d7ef2 100644 --- a/lib/ioat/ioat.c +++ b/lib/ioat/ioat.c @@ -617,8 +617,8 @@ spdk_ioat_submit_copy(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_c pdst_page = spdk_vtophys((void *)vdst_page, NULL); } op_size = remaining; - op_size = spdk_min(op_size, (0x200000 - _2MB_OFFSET(vsrc))); - op_size = spdk_min(op_size, (0x200000 - _2MB_OFFSET(vdst))); + op_size = spdk_min(op_size, (VALUE_2MB - _2MB_OFFSET(vsrc))); + op_size = spdk_min(op_size, (VALUE_2MB - _2MB_OFFSET(vdst))); op_size = spdk_min(op_size, ioat->max_xfer_size); remaining -= op_size; @@ -681,7 +681,7 @@ spdk_ioat_submit_fill(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_c while (remaining) { op_size = remaining; - op_size = spdk_min(op_size, (0x200000 - _2MB_OFFSET(vdst))); + op_size = spdk_min(op_size, (VALUE_2MB - _2MB_OFFSET(vdst))); op_size = spdk_min(op_size, ioat->max_xfer_size); remaining -= op_size; diff --git a/lib/nvme/nvme_internal.h b/lib/nvme/nvme_internal.h index d4c76a225..41522948a 100644 --- a/lib/nvme/nvme_internal.h +++ b/lib/nvme/nvme_internal.h @@ -56,6 +56,7 @@ #include "spdk_internal/assert.h" #include "spdk_internal/log.h" +#include "spdk_internal/memory.h" extern pid_t g_spdk_nvme_pid; @@ -137,7 +138,7 @@ extern pid_t g_spdk_nvme_pid; /* We want to fit submission and completion rings each in a single 2MB * hugepage to ensure physical address contiguity. */ -#define MAX_IO_QUEUE_ENTRIES (0x200000 / spdk_max( \ +#define MAX_IO_QUEUE_ENTRIES (VALUE_2MB / spdk_max( \ sizeof(struct spdk_nvme_cmd), \ sizeof(struct spdk_nvme_cpl))) diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index 6c31613d1..2d56d371b 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -42,8 +42,6 @@ #include "nvme_internal.h" #include "nvme_uevent.h" -#include "spdk_internal/memory.h" - /* * Number of completion queue entries to process before ringing the * completion queue doorbell. @@ -516,9 +514,8 @@ nvme_pcie_ctrlr_map_cmb(struct nvme_pcie_ctrlr *pctrlr) goto exit; } - mem_register_start = (((uintptr_t)pctrlr->cmb_bar_virt_addr + offset + 0x1fffff) & ~(0x200000 - 1)); - mem_register_end = ((uintptr_t)pctrlr->cmb_bar_virt_addr + offset + pctrlr->cmb_size); - mem_register_end &= ~(uint64_t)(0x200000 - 1); + mem_register_start = _2MB_PAGE((uintptr_t)pctrlr->cmb_bar_virt_addr + offset + VALUE_2MB - 1); + mem_register_end = _2MB_PAGE((uintptr_t)pctrlr->cmb_bar_virt_addr + offset + pctrlr->cmb_size); pctrlr->cmb_mem_register_addr = (void *)mem_register_start; pctrlr->cmb_mem_register_size = mem_register_end - mem_register_start; @@ -977,7 +974,7 @@ nvme_pcie_qpair_construct(struct spdk_nvme_qpair *qpair) volatile uint32_t *doorbell_base; uint64_t offset; uint16_t num_trackers; - size_t page_align = 0x200000; + size_t page_align = VALUE_2MB; uint32_t flags = SPDK_MALLOC_DMA; /* @@ -1827,7 +1824,7 @@ nvme_pcie_qpair_build_hw_sgl_request(struct spdk_nvme_qpair *qpair, struct nvme_ return -1; } - length = spdk_min(remaining_user_sge_len, 0x200000 - _2MB_OFFSET(virt_addr)); + length = spdk_min(remaining_user_sge_len, VALUE_2MB - _2MB_OFFSET(virt_addr)); remaining_user_sge_len -= length; virt_addr += length; diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 718ddfb36..055e5309a 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -479,7 +479,7 @@ spdk_vhost_vring_desc_to_iov(struct spdk_vhost_session *vsession, struct iovec * SPDK_ERRLOG("gpa_to_vva(%p) == NULL\n", (void *)payload); return -1; } - to_boundary = 0x200000 - _2MB_OFFSET(payload); + to_boundary = VALUE_2MB - _2MB_OFFSET(payload); if (spdk_likely(remaining <= to_boundary)) { len = remaining; } else { @@ -496,7 +496,7 @@ spdk_vhost_vring_desc_to_iov(struct spdk_vhost_session *vsession, struct iovec * if (vva + len != (uintptr_t)rte_vhost_gpa_to_vva(vsession->mem, payload + len)) { break; } - len += spdk_min(remaining - len, 0x200000); + len += spdk_min(remaining - len, VALUE_2MB); } } iov[*iov_index].iov_base = (void *)vva; diff --git a/lib/virtio/virtio_pci.c b/lib/virtio/virtio_pci.c index 9afb88293..62d53c0ce 100644 --- a/lib/virtio/virtio_pci.c +++ b/lib/virtio/virtio_pci.c @@ -38,6 +38,7 @@ #include "spdk/env.h" #include "spdk_internal/virtio.h" +#include "spdk_internal/memory.h" struct virtio_hw { uint8_t use_msix; @@ -268,11 +269,11 @@ modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq) * only a single hugepage (2MB). As of Virtio 1.0, the queue size * always falls within this limit. */ - if (vq->vq_ring_size > 0x200000) { + if (vq->vq_ring_size > VALUE_2MB) { return -ENOMEM; } - queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, 0x200000, &queue_mem_phys_addr); + queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, VALUE_2MB, &queue_mem_phys_addr); if (queue_mem == NULL) { return -ENOMEM; } diff --git a/test/nvme/e2edp/nvme_dp.c b/test/nvme/e2edp/nvme_dp.c index 3666eff24..9afe19000 100644 --- a/test/nvme/e2edp/nvme_dp.c +++ b/test/nvme/e2edp/nvme_dp.c @@ -42,6 +42,8 @@ #include "spdk/crc16.h" #include "spdk/endian.h" +#include "spdk_internal/memory.h" + #define MAX_DEVS 64 #define DATA_PATTERN 0x5A @@ -146,7 +148,7 @@ static uint32_t dp_guard_check_extended_lba_test(struct spdk_nvme_ns *ns, struct return 0; } - req->lba = 0x200000; + req->lba = VALUE_2MB; req->use_extended_lba = true; req->use_sgl = true; req->buf_size = (sector_size + md_size) * req->lba_count; @@ -232,7 +234,7 @@ static uint32_t dp_without_pract_extended_lba_test(struct spdk_nvme_ns *ns, stru return 0; } - req->lba = 0x200000; + req->lba = VALUE_2MB; req->use_extended_lba = true; req->metadata = NULL; pi = (struct spdk_nvme_protection_info *)(req->contig + sector_size + md_size - 8);