[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/30] hw/block/nvme: add a lba to bytes helper
From: |
Klaus Jensen |
Subject: |
[PULL 06/30] hw/block/nvme: add a lba to bytes helper |
Date: |
Tue, 27 Oct 2020 11:49:08 +0100 |
From: Klaus Jensen <k.jensen@samsung.com>
Add the nvme_l2b helper and use it for converting NLB and SLBA to byte
counts and offsets.
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
---
hw/block/nvme.h | 6 ++++++
hw/block/nvme.c | 12 ++++--------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
index 52ba794f2e9a..1675c1e0755c 100644
--- a/hw/block/nvme.h
+++ b/hw/block/nvme.h
@@ -77,6 +77,12 @@ static inline uint8_t nvme_ns_lbads(NvmeNamespace *ns)
return nvme_ns_lbaf(ns)->ds;
}
+/* convert an LBA to the equivalent in bytes */
+static inline size_t nvme_l2b(NvmeNamespace *ns, uint64_t lba)
+{
+ return lba << nvme_ns_lbads(ns);
+}
+
#define TYPE_NVME "nvme"
#define NVME(obj) \
OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index d6d8324fa1de..59338b42328b 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -644,12 +644,10 @@ static uint16_t nvme_write_zeroes(NvmeCtrl *n,
NvmeRequest *req)
{
NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;
NvmeNamespace *ns = req->ns;
- const uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
- const uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds;
uint64_t slba = le64_to_cpu(rw->slba);
uint32_t nlb = le16_to_cpu(rw->nlb) + 1;
- uint64_t offset = slba << data_shift;
- uint32_t count = nlb << data_shift;
+ uint64_t offset = nvme_l2b(ns, slba);
+ uint32_t count = nvme_l2b(ns, nlb);
uint16_t status;
trace_pci_nvme_write_zeroes(nvme_cid(req), slba, nlb);
@@ -674,10 +672,8 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeRequest *req)
uint32_t nlb = le32_to_cpu(rw->nlb) + 1;
uint64_t slba = le64_to_cpu(rw->slba);
- uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
- uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds;
- uint64_t data_size = (uint64_t)nlb << data_shift;
- uint64_t data_offset = slba << data_shift;
+ uint64_t data_size = nvme_l2b(ns, nlb);
+ uint64_t data_offset = nvme_l2b(ns, slba);
int is_write = rw->opcode == NVME_CMD_WRITE ? 1 : 0;
enum BlockAcctType acct = is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ;
uint16_t status;
--
2.29.1
- [PULL 00/30] nvme emulation patches for 5.2, Klaus Jensen, 2020/10/27
- [PULL 01/30] hw/block/nvme: fix typo in trace event, Klaus Jensen, 2020/10/27
- [PULL 02/30] pci: pass along the return value of dma_memory_rw, Klaus Jensen, 2020/10/27
- [PULL 03/30] hw/block/nvme: handle dma errors, Klaus Jensen, 2020/10/27
- [PULL 07/30] hw/block/nvme: fix endian conversion, Klaus Jensen, 2020/10/27
- [PULL 06/30] hw/block/nvme: add a lba to bytes helper,
Klaus Jensen <=
- [PULL 08/30] hw/block/nvme: add symbolic command name to trace events, Klaus Jensen, 2020/10/27
- [PULL 09/30] hw/block/nvme: refactor aio submission, Klaus Jensen, 2020/10/27
- [PULL 04/30] hw/block/nvme: commonize nvme_rw error handling, Klaus Jensen, 2020/10/27
- [PULL 05/30] hw/block/nvme: alignment style fixes, Klaus Jensen, 2020/10/27
- [PULL 11/30] hw/block/nvme: harden cmb access, Klaus Jensen, 2020/10/27
- [PULL 10/30] hw/block/nvme: default request status to success, Klaus Jensen, 2020/10/27
- [PULL 13/30] hw/block/nvme: add support for sgl bit bucket descriptor, Klaus Jensen, 2020/10/27
- [PULL 14/30] hw/block/nvme: refactor identify active namespace id list, Klaus Jensen, 2020/10/27
- [PULL 12/30] hw/block/nvme: add support for scatter gather lists, Klaus Jensen, 2020/10/27
- [PULL 16/30] pci: allocate pci id for nvme, Klaus Jensen, 2020/10/27