From: Denis Mukhin <[email protected]> Implement the NVM flush command (opcode 0x00) to allow callers to synchronize any buffered data with the backing NVMe storage.
Signed-off-by: Denis Mukhin <[email protected]> --- Changes since v1: - moved generic disk_blk_flush() to a separate patch --- drivers/nvme/nvme.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c index c3c44e50f19a..d9f099a11593 100644 --- a/drivers/nvme/nvme.c +++ b/drivers/nvme/nvme.c @@ -819,9 +819,29 @@ static ulong nvme_blk_write(struct udevice *udev, lbaint_t blknr, return nvme_blk_rw(udev, blknr, blkcnt, (void *)buffer, false); } +/* + * NVM Flush command (opcode 0x00). + * + * Applies to a single namespace; the controller must commit all dirty + * data for that namespace to storage before completing the command. + */ +static ulong nvme_blk_flush(struct udevice *udev) +{ + struct nvme_ns *ns = dev_get_priv(udev); + struct nvme_dev *dev = ns->dev; + struct nvme_command c; + + memset(&c, 0, sizeof(c)); + c.common.opcode = nvme_cmd_flush; + c.common.nsid = cpu_to_le32(ns->ns_id); + + return nvme_submit_sync_cmd(dev->queues[NVME_IO_Q], &c, NULL, IO_TIMEOUT); +} + static const struct blk_ops nvme_blk_ops = { .read = nvme_blk_read, .write = nvme_blk_write, + .flush = nvme_blk_flush, }; U_BOOT_DRIVER(nvme_blk) = { -- 2.54.0

