]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme.c: Check Firmware Update Granularity in fwdl
authorSteven Seungcheol Lee <sc108.lee@samsung.com>
Fri, 3 Mar 2023 07:44:55 +0000 (16:44 +0900)
committerDaniel Wagner <wagi@monom.org>
Mon, 6 Mar 2023 10:21:35 +0000 (11:21 +0100)
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 <keith.busch@gmail.com>
Reported-by: Minsik Jeon <hmi.jeon@samsung.com>
Signed-off-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 922616051affb3ec4cd245411c57f4a122ebd189..c844d2c235f1751522d45458a7827968c2db2b78 100644 (file)
--- 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)