Skip to content

Commit 48ce0ca

Browse files
DanceDanceigaw
authored andcommitted
types: Change LM CDQ sz argument from u8 to u32.
To maintain backwards compatibility, the old sz renamed to sz_u8. According to NVMe 2.1 Base Specificaiton, Controller Data Queue Size (CDQSIZE) occupies bits 31:00 of CDW12, so it should be using u32. Signed-off-by: Dmitry Sherstoboev <sdmitry@google.com>
1 parent 9851832 commit 48ce0ca

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/nvme/api-types.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,9 @@ struct nvme_dim_args {
976976
* by the controller if no error is present. For Delete CDQ, this field is the CDQID
977977
* to delete.
978978
* @sel: Select (SEL): This field specifies the type of management operation to perform.
979-
* @sz: For Create CDQ, specifies the size of CDQ, in dwords
979+
* @sz_u8: For Create CDQ, specifies the size of CDQ, in dwords - 1 byte
980+
* @rsvd1: Reserved
981+
* @sz: For Create CDQ, specifies the size of CDQ, in dwords - 4 byte
980982
*/
981983
struct nvme_lm_cdq_args {
982984
__u32 *result;
@@ -988,7 +990,9 @@ struct nvme_lm_cdq_args {
988990
__u16 cntlid;
989991
__u16 cdqid;
990992
__u8 sel;
991-
__u8 sz;
993+
__u8 sz_u8;
994+
__u8 rsvd1[4];
995+
__u32 sz;
992996
};
993997

994998
/**

src/nvme/ioctl.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,15 +2353,27 @@ int nvme_dim_send(struct nvme_dim_args *args)
23532353

23542354
int nvme_lm_cdq(struct nvme_lm_cdq_args *args)
23552355
{
2356+
const size_t size_v1 = sizeof_args(struct nvme_lm_cdq_args, sz_u8, __u64);
2357+
const size_t size_v2 = sizeof_args(struct nvme_lm_cdq_args, sz, __u64);
23562358
__u32 cdw10 = NVME_SET(args->sel, LM_CDQ_SEL) |
23572359
NVME_SET(args->mos, LM_CDQ_MOS);
2358-
__u32 cdw11 = 0, data_len = 0;
2360+
__u32 cdw11 = 0, data_len = 0, sz = 0;
23592361
int err;
23602362

2363+
if (args->args_size < size_v1 || args->args_size > size_v2) {
2364+
errno = EINVAL;
2365+
return -1;
2366+
}
2367+
2368+
if (args->args_size == size_v1)
2369+
sz = args->sz_u8;
2370+
else
2371+
sz = args->sz;
2372+
23612373
if (args->sel == NVME_LM_SEL_CREATE_CDQ) {
23622374
cdw11 = NVME_SET(args->cntlid, LM_CREATE_CDQ_CNTLID) |
23632375
NVME_LM_CREATE_CDQ_PC;
2364-
data_len = args->sz << 2;
2376+
data_len = sz << 2;
23652377
} else if (args->sel == NVME_LM_SEL_DELETE_CDQ) {
23662378
cdw11 = NVME_SET(args->cdqid, LM_DELETE_CDQ_CDQID);
23672379
}
@@ -2370,7 +2382,7 @@ int nvme_lm_cdq(struct nvme_lm_cdq_args *args)
23702382
.opcode = nvme_admin_ctrl_data_queue,
23712383
.cdw10 = cdw10,
23722384
.cdw11 = cdw11,
2373-
.cdw12 = args->sz,
2385+
.cdw12 = sz,
23742386
.addr = (__u64)(uintptr_t)args->data,
23752387
.data_len = data_len,
23762388
.timeout_ms = args->timeout,

0 commit comments

Comments
 (0)