From 493d64d3632edc642ab74593c587d729b17668b8 Mon Sep 17 00:00:00 2001 From: Steven Seungcheol Lee Date: Fri, 3 Mar 2023 16:44:55 +0900 Subject: [PATCH] nvme.c: Check Firmware Update Granularity in fwdl FWUG indicates the granularity and alignment requirement of the firmware image being updated by the Firmware Image Download command FWUG is reported in 4 KiB units 0h indicates that no information on granularity is provided FFh indicates there is no restriction so when this is 0 value, use 4 KiB split as a default Do not override when xfer is given by user -> Support for ignore fwug in (fwug>mdts) case Reviewed-by: Keith Busch Reported-by: Minsik Jeon Signed-off-by: Steven Seungcheol Lee --- nvme.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nvme.c b/nvme.c index 92261605..c844d2c2 100644 --- a/nvme.c +++ b/nvme.c @@ -4842,6 +4842,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin struct stat sb; void *fw_buf; bool huge; + struct nvme_id_ctrl ctrl; struct config { char *fw; @@ -4894,7 +4895,18 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin goto close_fw_fd; } - if (cfg.xfer == 0 || cfg.xfer % 4096) + if (cfg.xfer == 0) { + err = nvme_cli_identify_ctrl(dev, &ctrl); + if (err) { + fprintf(stderr, "identify-ctrl: %s\n", nvme_strerror(errno)); + goto close_fw_fd; + } + if (ctrl.fwug == 0 || ctrl.fwug == 0xff) + cfg.xfer = 4096; + else + cfg.xfer = ctrl.fwug * 4096; + } + else if (cfg.xfer % 4096) cfg.xfer = 4096; if (cfg.xfer < HUGE_MIN) -- 2.50.1