Skip to content

Commit aef4b82

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for nvme_fw_download()
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 <[email protected]>
1 parent bbab30b commit aef4b82

3 files changed

Lines changed: 39 additions & 17 deletions

File tree

src/nvme/ioctl.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,22 +1206,23 @@ int nvme_ns_attach(struct nvme_ns_attach_args *args)
12061206
return nvme_submit_admin_passthru(args->fd, &cmd, NULL);
12071207
}
12081208

1209-
int nvme_fw_download(int fd, __u32 offset, __u32 data_len, void *data,
1210-
__u32 timeout, __u32 *result)
1209+
int nvme_fw_download(struct nvme_fw_download_args *args)
12111210
{
1212-
__u32 cdw10 = (data_len >> 2) - 1;
1213-
__u32 cdw11 = offset >> 2;
1211+
__u32 cdw10 = (args->data_len >> 2) - 1;
1212+
__u32 cdw11 = args->offset >> 2;
12141213

12151214
struct nvme_passthru_cmd cmd = {
12161215
.opcode = nvme_admin_fw_download,
12171216
.cdw10 = cdw10,
12181217
.cdw11 = cdw11,
1219-
.data_len = data_len,
1220-
.addr = (__u64)(uintptr_t)data,
1221-
.timeout_ms = timeout,
1218+
.data_len = args->data_len,
1219+
.addr = (__u64)(uintptr_t)args->data,
1220+
.timeout_ms = args->timeout,
12221221
};
12231222

1224-
return nvme_submit_admin_passthru(fd, &cmd, result);
1223+
if (args->args_size < sizeof(*args))
1224+
return -EINVAL;
1225+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
12251226
}
12261227

12271228
int nvme_fw_commit(int fd, __u8 slot, enum nvme_fw_commit_ca action, bool bpid,

src/nvme/ioctl.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,14 +2859,28 @@ static inline int nvme_ns_detach_ctrls(int fd, __u32 nsid,
28592859
}
28602860

28612861
/**
2862-
* nvme_fw_download() - Download part or all of a firmware image to the
2863-
* controller
2862+
* nvme_fw_download_args - Arguments for the NVMe Firmware Download command
28642863
* @fd: File descriptor of nvme device
28652864
* @offset: Offset in the firmware data
28662865
* @data_len: Length of data in this command in bytes
28672866
* @data: Userspace address of the firmware data
28682867
* @timeout: Timeout in ms
28692868
* @result: The command completion result from CQE dword0
2869+
*/
2870+
struct nvme_fw_download_args {
2871+
int args_size;
2872+
int fd;
2873+
__u32 offset;
2874+
__u32 data_len;
2875+
void *data;
2876+
__u32 timeout;
2877+
__u32 *result;
2878+
};
2879+
2880+
/**
2881+
* nvme_fw_download() - Download part or all of a firmware image to the
2882+
* controller
2883+
* @args: &struct nvme_fw_download_args argument structure
28702884
*
28712885
* The Firmware Image Download command downloads all or a portion of an image
28722886
* for a future update to the controller. The Firmware Image Download command
@@ -2884,8 +2898,7 @@ static inline int nvme_ns_detach_ctrls(int fd, __u32 nsid,
28842898
* Return: The nvme command status if a response was received (see
28852899
* &enum nvme_status_field) or -1 with errno set otherwise.
28862900
*/
2887-
int nvme_fw_download(int fd, __u32 offset, __u32 data_len, void *data,
2888-
__u32 timeout, __u32 *result);
2901+
int nvme_fw_download(struct nvme_fw_download_args *args);
28892902

28902903
/**
28912904
* nvme_fw_commit() - Commit firmware using the specified action

src/nvme/linux.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,25 @@ int nvme_fw_download_seq(int fd, __u32 size, __u32 xfer, __u32 offset,
9292
void *buf)
9393
{
9494
int err = 0;
95+
struct nvme_fw_download_args args = {
96+
.args_size = sizeof(args),
97+
.fd = fd,
98+
.offset = offset,
99+
.data_len = xfer,
100+
.data = buf,
101+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
102+
.result = NULL,
103+
};
95104

96105
while (size > 0) {
97-
xfer = MIN(xfer, size);
98-
err = nvme_fw_download(fd, offset, xfer, buf,
99-
NVME_DEFAULT_IOCTL_TIMEOUT, NULL);
106+
args.data_len = MIN(xfer, size);
107+
err = nvme_fw_download(&args);
100108
if (err)
101109
break;
102110

103-
buf += xfer;
111+
args.data += xfer;
104112
size -= xfer;
105-
offset += xfer;
113+
args.offset += xfer;
106114
}
107115

108116
return err;

0 commit comments

Comments
 (0)