aboutsummaryrefslogtreecommitdiff
path: root/hw/nvme/dif.c
diff options
context:
space:
mode:
authorKlaus Jensen <k.jensen@samsung.com>2022-02-14 09:29:01 +0100
committerKlaus Jensen <k.jensen@samsung.com>2022-03-03 09:28:49 +0100
commitac0b34c58d0de09ce692af0a6c9a00a4eed0f3cd (patch)
tree1ad169841ceda161510d8f0a0a5577553b1031b3 /hw/nvme/dif.c
parent763c05dfb08c5fff86275788de7f11e899167167 (diff)
downloadqemu-ac0b34c58d0de09ce692af0a6c9a00a4eed0f3cd.zip
qemu-ac0b34c58d0de09ce692af0a6c9a00a4eed0f3cd.tar.gz
qemu-ac0b34c58d0de09ce692af0a6c9a00a4eed0f3cd.tar.bz2
hw/nvme: add pi tuple size helper
A subsequent patch will introduce a new tuple size; so add a helper and use that instead of sizeof() and magic numbers. Reviewed-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Diffstat (limited to 'hw/nvme/dif.c')
-rw-r--r--hw/nvme/dif.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/hw/nvme/dif.c b/hw/nvme/dif.c
index cd0cea2..891385f 100644
--- a/hw/nvme/dif.c
+++ b/hw/nvme/dif.c
@@ -48,7 +48,7 @@ void nvme_dif_pract_generate_dif(NvmeNamespace *ns, uint8_t *buf, size_t len,
int16_t pil = 0;
if (!(ns->id_ns.dps & NVME_ID_NS_DPS_FIRST_EIGHT)) {
- pil = ns->lbaf.ms - sizeof(NvmeDifTuple);
+ pil = ns->lbaf.ms - nvme_pi_tuple_size(ns);
}
trace_pci_nvme_dif_pract_generate_dif(len, ns->lbasz, ns->lbasz + pil,
@@ -145,7 +145,7 @@ uint16_t nvme_dif_check(NvmeNamespace *ns, uint8_t *buf, size_t len,
}
if (!(ns->id_ns.dps & NVME_ID_NS_DPS_FIRST_EIGHT)) {
- pil = ns->lbaf.ms - sizeof(NvmeDifTuple);
+ pil = ns->lbaf.ms - nvme_pi_tuple_size(ns);
}
trace_pci_nvme_dif_check(prinfo, ns->lbasz + pil);
@@ -184,7 +184,7 @@ uint16_t nvme_dif_mangle_mdata(NvmeNamespace *ns, uint8_t *mbuf, size_t mlen,
if (!(ns->id_ns.dps & NVME_ID_NS_DPS_FIRST_EIGHT)) {
- pil = ns->lbaf.ms - sizeof(NvmeDifTuple);
+ pil = ns->lbaf.ms - nvme_pi_tuple_size(ns);
}
do {
@@ -210,7 +210,7 @@ uint16_t nvme_dif_mangle_mdata(NvmeNamespace *ns, uint8_t *mbuf, size_t mlen,
end = mbufp + mlen;
for (; mbufp < end; mbufp += ns->lbaf.ms) {
- memset(mbufp + pil, 0xff, sizeof(NvmeDifTuple));
+ memset(mbufp + pil, 0xff, nvme_pi_tuple_size(ns));
}
}
@@ -284,7 +284,7 @@ static void nvme_dif_rw_check_cb(void *opaque, int ret)
goto out;
}
- if (prinfo & NVME_PRINFO_PRACT && ns->lbaf.ms == 8) {
+ if (prinfo & NVME_PRINFO_PRACT && ns->lbaf.ms == nvme_pi_tuple_size(ns)) {
goto out;
}
@@ -388,7 +388,7 @@ uint16_t nvme_dif_rw(NvmeCtrl *n, NvmeRequest *req)
if (pract) {
uint8_t *mbuf, *end;
- int16_t pil = ns->lbaf.ms - sizeof(NvmeDifTuple);
+ int16_t pil = ns->lbaf.ms - nvme_pi_tuple_size(ns);
status = nvme_check_prinfo(ns, prinfo, slba, reftag);
if (status) {
@@ -428,7 +428,7 @@ uint16_t nvme_dif_rw(NvmeCtrl *n, NvmeRequest *req)
return NVME_NO_COMPLETE;
}
- if (nvme_ns_ext(ns) && !(pract && ns->lbaf.ms == 8)) {
+ if (nvme_ns_ext(ns) && !(pract && ns->lbaf.ms == nvme_pi_tuple_size(ns))) {
mapped_len += mlen;
}
@@ -462,7 +462,7 @@ uint16_t nvme_dif_rw(NvmeCtrl *n, NvmeRequest *req)
qemu_iovec_init(&ctx->mdata.iov, 1);
qemu_iovec_add(&ctx->mdata.iov, ctx->mdata.bounce, mlen);
- if (!(pract && ns->lbaf.ms == 8)) {
+ if (!(pract && ns->lbaf.ms == nvme_pi_tuple_size(ns))) {
status = nvme_bounce_mdata(n, ctx->mdata.bounce, ctx->mdata.iov.size,
NVME_TX_DIRECTION_TO_DEVICE, req);
if (status) {