Use an argument structure instead of passing all arguments one by one.
This allows for a future expansion of the argument list without having
to change the library ABI.
Signed-off-by: Hannes Reinecke <hare@suse.de>
return nvme_submit_admin_passthru(args->fd, &cmd, NULL);
}
-int nvme_fw_download(int fd, __u32 offset, __u32 data_len, void *data,
- __u32 timeout, __u32 *result)
+int nvme_fw_download(struct nvme_fw_download_args *args)
{
- __u32 cdw10 = (data_len >> 2) - 1;
- __u32 cdw11 = offset >> 2;
+ __u32 cdw10 = (args->data_len >> 2) - 1;
+ __u32 cdw11 = args->offset >> 2;
struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_fw_download,
.cdw10 = cdw10,
.cdw11 = cdw11,
- .data_len = data_len,
- .addr = (__u64)(uintptr_t)data,
- .timeout_ms = timeout,
+ .data_len = args->data_len,
+ .addr = (__u64)(uintptr_t)args->data,
+ .timeout_ms = args->timeout,
};
- return nvme_submit_admin_passthru(fd, &cmd, result);
+ if (args->args_size < sizeof(*args))
+ return -EINVAL;
+ return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
}
int nvme_fw_commit(int fd, __u8 slot, enum nvme_fw_commit_ca action, bool bpid,
}
/**
- * nvme_fw_download() - Download part or all of a firmware image to the
- * controller
+ * nvme_fw_download_args - Arguments for the NVMe Firmware Download command
* @fd: File descriptor of nvme device
* @offset: Offset in the firmware data
* @data_len: Length of data in this command in bytes
* @data: Userspace address of the firmware data
* @timeout: Timeout in ms
* @result: The command completion result from CQE dword0
+ */
+struct nvme_fw_download_args {
+ int args_size;
+ int fd;
+ __u32 offset;
+ __u32 data_len;
+ void *data;
+ __u32 timeout;
+ __u32 *result;
+};
+
+/**
+ * nvme_fw_download() - Download part or all of a firmware image to the
+ * controller
+ * @args: &struct nvme_fw_download_args argument structure
*
* The Firmware Image Download command downloads all or a portion of an image
* for a future update to the controller. The Firmware Image Download command
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
-int nvme_fw_download(int fd, __u32 offset, __u32 data_len, void *data,
- __u32 timeout, __u32 *result);
+int nvme_fw_download(struct nvme_fw_download_args *args);
/**
* nvme_fw_commit() - Commit firmware using the specified action
void *buf)
{
int err = 0;
+ struct nvme_fw_download_args args = {
+ .args_size = sizeof(args),
+ .fd = fd,
+ .offset = offset,
+ .data_len = xfer,
+ .data = buf,
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .result = NULL,
+ };
while (size > 0) {
- xfer = MIN(xfer, size);
- err = nvme_fw_download(fd, offset, xfer, buf,
- NVME_DEFAULT_IOCTL_TIMEOUT, NULL);
+ args.data_len = MIN(xfer, size);
+ err = nvme_fw_download(&args);
if (err)
break;
- buf += xfer;
+ args.data += xfer;
size -= xfer;
- offset += xfer;
+ args.offset += xfer;
}
return err;