Move bounce buffer processing to a new helper function.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
---
src/hw/nvme.c | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/src/hw/nvme.c b/src/hw/nvme.c
index a97501b..fd7c1d0 100644
--- a/src/hw/nvme.c
+++ b/src/hw/nvme.c
@@ -465,6 +465,25 @@ nvme_io_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count,
return count;
}
+// Transfer up to one page of data using the internal dma bounce buffer
+static int
+nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count,
+ int write)
+{
+ u16 const max_blocks = NVME_PAGE_SIZE / ns->block_size;
+ u16 blocks = count < max_blocks ? count : max_blocks;
+
+ if (write)
+ memcpy(ns->dma_buffer, buf, blocks * ns->block_size);
+
+ int res = nvme_io_xfer(ns, lba, ns->dma_buffer, blocks, write);
+
+ if (!write && res >= 0)
+ memcpy(buf, ns->dma_buffer, res * ns->block_size);
+
+ return res;
+}
+
static void nvme_reset_prpl(struct nvme_namespace *ns)
{
ns->prpl_len = 0;
@@ -718,7 +737,6 @@ nvme_scan(void)
static int
nvme_cmd_readwrite(struct nvme_namespace *ns, struct disk_op_s *op, int write)
{
- u16 const max_blocks = NVME_PAGE_SIZE / ns->block_size;
u16 i, blocks;
for (i = 0; i < op->count;) {
@@ -731,21 +749,10 @@ nvme_cmd_readwrite(struct nvme_namespace *ns, struct disk_op_s *op, int write)
if (res < 0)
return DISK_RET_EBADTRACK;
} else {
- blocks = blocks_remaining < max_blocks ? blocks_remaining
- : max_blocks;
-
- if (write) {
- memcpy(ns->dma_buffer, op_buf, blocks * ns->block_size);
- }
-
- int res = nvme_io_xfer(ns, op->lba + i, ns->dma_buffer,
- blocks, write);
+ int res = nvme_bounce_xfer(ns, op->lba + i, op_buf, blocks, write);
if (res < 0)
return DISK_RET_EBADTRACK;
-
- if (!write) {
- memcpy(op_buf, ns->dma_buffer, blocks * ns->block_size);
- }
+ blocks = res;
}
i += blocks;
--
2.31.1
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
On 19.01.22 19:45, Kevin O'Connor wrote: > Move bounce buffer processing to a new helper function. > > Signed-off-by: Kevin O'Connor <kevin@koconnor.net> Reviewed-by: Alexander Graf <graf@amazon.com> Alex > --- > src/hw/nvme.c | 35 +++++++++++++++++++++-------------- > 1 file changed, 21 insertions(+), 14 deletions(-) > > diff --git a/src/hw/nvme.c b/src/hw/nvme.c > index a97501b..fd7c1d0 100644 > --- a/src/hw/nvme.c > +++ b/src/hw/nvme.c > @@ -465,6 +465,25 @@ nvme_io_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, > return count; > } > > +// Transfer up to one page of data using the internal dma bounce buffer > +static int > +nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, > + int write) > +{ > + u16 const max_blocks = NVME_PAGE_SIZE / ns->block_size; > + u16 blocks = count < max_blocks ? count : max_blocks; > + > + if (write) > + memcpy(ns->dma_buffer, buf, blocks * ns->block_size); > + > + int res = nvme_io_xfer(ns, lba, ns->dma_buffer, blocks, write); > + > + if (!write && res >= 0) > + memcpy(buf, ns->dma_buffer, res * ns->block_size); > + > + return res; > +} > + > static void nvme_reset_prpl(struct nvme_namespace *ns) > { > ns->prpl_len = 0; > @@ -718,7 +737,6 @@ nvme_scan(void) > static int > nvme_cmd_readwrite(struct nvme_namespace *ns, struct disk_op_s *op, int write) > { > - u16 const max_blocks = NVME_PAGE_SIZE / ns->block_size; > u16 i, blocks; > > for (i = 0; i < op->count;) { > @@ -731,21 +749,10 @@ nvme_cmd_readwrite(struct nvme_namespace *ns, struct disk_op_s *op, int write) > if (res < 0) > return DISK_RET_EBADTRACK; > } else { > - blocks = blocks_remaining < max_blocks ? blocks_remaining > - : max_blocks; > - > - if (write) { > - memcpy(ns->dma_buffer, op_buf, blocks * ns->block_size); > - } > - > - int res = nvme_io_xfer(ns, op->lba + i, ns->dma_buffer, > - blocks, write); > + int res = nvme_bounce_xfer(ns, op->lba + i, op_buf, blocks, write); > if (res < 0) > return DISK_RET_EBADTRACK; > - > - if (!write) { > - memcpy(op_buf, ns->dma_buffer, blocks * ns->block_size); > - } > + blocks = res; > } > > i += blocks; > -- > 2.31.1 > > _______________________________________________ > SeaBIOS mailing list -- seabios@seabios.org > To unsubscribe send an email to seabios-leave@seabios.org Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org
© 2016 - 2024 Red Hat, Inc.