Skip to content

Commit 3e2d050

Browse files
committed
ioctl: rework nvme_lm_cqd command
Replace the struct args approach by providing init function for initializing the passthru commands. This reduces the dependency between callside and library. Signed-off-by: Daniel Wagner <[email protected]>
1 parent d932dee commit 3e2d050

6 files changed

Lines changed: 87 additions & 93 deletions

File tree

libnvme/src/libnvme.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ LIBNVME_2_0 {
137137
nvme_io_passthru64;
138138
nvme_io_passthru;
139139
nvme_ipaddrs_eq;
140-
nvme_lm_cdq;
141140
nvme_lm_get_features_ctrl_data_queue;
142141
nvme_lm_migration_recv;
143142
nvme_lm_migration_send;

libnvme/src/nvme/api-types.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -143,36 +143,6 @@ struct nvme_copy_args {
143143
__u64 ilbrt_u64;
144144
};
145145

146-
/**
147-
* struct nvme_lm_cdq_args - Arguments for Controller Data Queue (CDQ) command
148-
* @result: Set on completion to the command's CQE DWORD 0 controller response
149-
* @data: Pointer to data
150-
* @args_size: Length of structure
151-
* @timeout: Timeout in ms
152-
* @mos: Management Operation Specific (MOS): This field is specific to the SEL type
153-
* @cntlid: Controller ID: For Create CDQ, specifies the target migratable controller
154-
* @cdqid: Controller Data Queue ID (CDQID): For Create CDQ, this field is the CDQID created
155-
* by the controller if no error is present. For Delete CDQ, this field is the CDQID
156-
* to delete.
157-
* @sel: Select (SEL): This field specifies the type of management operation to perform.
158-
* @sz_u8: For Create CDQ, specifies the size of CDQ, in dwords - 1 byte
159-
* @rsvd1: Reserved
160-
* @sz: For Create CDQ, specifies the size of CDQ, in dwords - 4 byte
161-
*/
162-
struct nvme_lm_cdq_args {
163-
__u32 *result;
164-
void *data;
165-
int args_size;
166-
__u32 timeout;
167-
__u16 mos;
168-
__u16 cntlid;
169-
__u16 cdqid;
170-
__u8 sel;
171-
__u8 sz_u8;
172-
__u8 rsvd1[4];
173-
__u32 sz;
174-
};
175-
176146
/**
177147
* struct nvme_lm_track_send_args - Arguments for the Track Send command
178148
* @result: Set on completion to the command's CQE DWORD 0 controller response

libnvme/src/nvme/ioctl.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -772,44 +772,6 @@ int nvme_copy(struct nvme_transport_handle *hdl, struct nvme_copy_args *args)
772772
return nvme_submit_io_passthru(hdl, &cmd, args->result);
773773
}
774774

775-
int nvme_lm_cdq(struct nvme_transport_handle *hdl, struct nvme_lm_cdq_args *args)
776-
{
777-
__u32 cdw10 = NVME_SET(args->sel, LM_CDQ_SEL) |
778-
NVME_SET(args->mos, LM_CDQ_MOS);
779-
__u32 cdw11 = 0, data_len = 0, sz = 0;
780-
int err;
781-
782-
sz = args->sz;
783-
784-
if (args->sel == NVME_LM_SEL_CREATE_CDQ) {
785-
cdw11 = NVME_SET(NVME_SET(args->cntlid, LM_CREATE_CDQ_CNTLID), LM_CQS) |
786-
NVME_LM_CREATE_CDQ_PC;
787-
data_len = sz << 2;
788-
} else if (args->sel == NVME_LM_SEL_DELETE_CDQ) {
789-
cdw11 = NVME_SET(args->cdqid, LM_DELETE_CDQ_CDQID);
790-
}
791-
792-
struct nvme_passthru_cmd cmd = {
793-
.opcode = nvme_admin_ctrl_data_queue,
794-
.cdw10 = cdw10,
795-
.cdw11 = cdw11,
796-
.cdw12 = sz,
797-
.addr = (__u64)(uintptr_t)args->data,
798-
.data_len = data_len,
799-
.timeout_ms = args->timeout,
800-
};
801-
802-
if (args->args_size < sizeof(*args))
803-
return -EINVAL;
804-
805-
err = nvme_submit_admin_passthru(hdl, &cmd, args->result);
806-
807-
if (!err)
808-
args->cdqid = NVME_GET(cmd.result, LM_CREATE_CDQ_CDQID);
809-
810-
return err;
811-
}
812-
813775
int nvme_lm_track_send(struct nvme_transport_handle *hdl, struct nvme_lm_track_send_args *args)
814776
{
815777
__u32 cdw10 = NVME_SET(args->sel, LM_TRACK_SEND_SEL) |

libnvme/src/nvme/ioctl.h

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5063,14 +5063,79 @@ nvme_init_dim_send(struct nvme_passthru_cmd *cmd,
50635063
}
50645064

50655065
/**
5066-
* nvme_lm_cdq() - Controller Data Queue - Controller Data Queue command
5067-
* @hdl: Transport handle
5068-
* @args: &struct nvme_lm_cdq_args argument structure
5066+
* nvme_init_lm_cdq_create() - Initialize passthru command for
5067+
* Controller Data Queue create - Controller Data Queue command
5068+
* @cmd: Passthru command to use
5069+
* @mos: Management Operation Specific (MOS): This field is
5070+
* specific to the SEL type
5071+
* @cntlid: Controller ID: For Create CDQ, specifies the target
5072+
* migratable controller
5073+
* @cdqsize: For Create CDQ, specifies the size of CDQ, in dwords - 4 byte
5074+
* @data: Pointer to data buffer
50695075
*
5070-
* Return: The nvme command status if a response was received (see
5071-
* &enum nvme_status_field) or -1 with errno set otherwise.)
5076+
* Initializes the passthru command buffer for the Controller Data Queue
5077+
* command. Note: The result CDQID is returned in the CQE dword0, which the
5078+
* submission function must handle.
5079+
*/
5080+
static inline void
5081+
nvme_init_lm_cdq_create(struct nvme_passthru_cmd *cmd,
5082+
__u16 mos, __u16 cntlid, __u32 cdqsize, void *data)
5083+
{
5084+
__u16 cqs;
5085+
5086+
memset(cmd, 0, sizeof(*cmd));
5087+
5088+
cqs = NVME_FIELD_ENCODE(cntlid,
5089+
NVME_LM_CREATE_CDQ_CNTLID_SHIFT,
5090+
NVME_LM_CREATE_CDQ_CNTLID_MASK);
5091+
5092+
cmd->opcode = nvme_admin_ctrl_data_queue;
5093+
cmd->data_len = cdqsize << 2;
5094+
cmd->addr = (__u64)(uintptr_t)data;
5095+
cmd->cdw10 = NVME_FIELD_ENCODE(NVME_LM_SEL_CREATE_CDQ,
5096+
NVME_LM_CDQ_SEL_SHIFT,
5097+
NVME_LM_CDQ_SEL_MASK) |
5098+
NVME_FIELD_ENCODE(mos,
5099+
NVME_LM_CDQ_MOS_SHIFT,
5100+
NVME_LM_CDQ_MOS_MASK);
5101+
cmd->cdw11 = NVME_FIELD_ENCODE(NVME_LM_CREATE_CDQ_PC,
5102+
NVME_LM_CREATE_CDQ_PC_SHIFT,
5103+
NVME_LM_CREATE_CDQ_PC_MASK) |
5104+
NVME_FIELD_ENCODE(cqs,
5105+
NVME_LM_CQS_SHIFT,
5106+
NVME_LM_CQS_MASK);
5107+
cmd->cdw12 = cdqsize;
5108+
}
5109+
5110+
/**
5111+
* nvme_init_lm_cdq_delete() - Initialize passthru command for
5112+
* Controller Data Queue delete - Controller Data Queue command
5113+
* @cmd: Passthru command to use
5114+
* @mos: Management Operation Specific (MOS): This field is
5115+
* specific to the SEL type
5116+
* @cdqid: Controller Data Queue ID (CDQID): For Delete CDQ, this
5117+
* field is the CDQID to delete.
5118+
*
5119+
* Initializes the passthru command buffer for the Controller Data Queue delete
5120+
* command.
50725121
*/
5073-
int nvme_lm_cdq(struct nvme_transport_handle *hdl, struct nvme_lm_cdq_args *args);
5122+
static inline void
5123+
nvme_init_lm_cdq_delete(struct nvme_passthru_cmd *cmd,
5124+
__u16 mos, __u16 cdqid)
5125+
{
5126+
memset(cmd, 0, sizeof(*cmd));
5127+
5128+
cmd->opcode = nvme_admin_ctrl_data_queue;
5129+
cmd->cdw10 = NVME_FIELD_ENCODE(NVME_LM_SEL_DELETE_CDQ,
5130+
NVME_LM_CDQ_SEL_SHIFT,
5131+
NVME_LM_CDQ_SEL_MASK) |
5132+
NVME_FIELD_ENCODE(mos,
5133+
NVME_LM_CDQ_MOS_SHIFT,
5134+
NVME_LM_CDQ_MOS_MASK);
5135+
cmd->cdw11 = NVME_FIELD_ENCODE(cdqid,
5136+
NVME_LM_DELETE_CDQ_CDQID_SHIFT,
5137+
NVME_LM_DELETE_CDQ_CDQID_MASK);
5138+
}
50745139

50755140
/**
50765141
* nvme_lm_track_send() - Track Send command

libnvme/src/nvme/types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10016,6 +10016,8 @@ struct nvme_ns_mgmt_host_sw_specified {
1001610016
* @NVME_LM_CQS_SHIFT: Shift amount for Create Queue Specific (CQS) field
1001710017
* @NVME_LM_CQS_MASK: Mask to set CQS field
1001810018
* @NVME_LM_CREATE_CDQ_PC: Physically Contiguous (PC)
10019+
* @NVME_LM_CREATE_CDQ_PC_SHIFT: Shift amount to set the PC field
10020+
* @NVME_LM_CREATE_CDQ_PC_MASK: Mask to set PC field
1001910021
* @NVME_LM_CREATE_CDQ_CNTLID_SHIFT: Shift amount to set CNTLID field relative to MOS
1002010022
* @NVME_LM_CREATE_CDQ_CNTLID_MASK: Mask to set CNTLID field relative to MOS
1002110023
* @NVME_LM_DELETE_CDQ_CDQID_SHIFT: Shift amount to set CDQID field for deletion
@@ -10040,6 +10042,8 @@ enum nvme_lm_cdq_fields {
1004010042
NVME_LM_CQS_MASK = 0xffff,
1004110043
NVME_LM_QT_USER_DATA_MIGRATION_QUEUE = 0,
1004210044
NVME_LM_CREATE_CDQ_PC = 1,
10045+
NVME_LM_CREATE_CDQ_PC_SHIFT = 0,
10046+
NVME_LM_CREATE_CDQ_PC_MASK = 0x1,
1004310047
NVME_LM_CREATE_CDQ_CNTLID_SHIFT = 0,
1004410048
NVME_LM_CREATE_CDQ_CNTLID_MASK = 0xffff,
1004510049

libnvme/test/ioctl/misc.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,36 +1345,30 @@ static void test_dim_send(void)
13451345
cmp(&data, &expected_data, sizeof(data), "incorrect data");
13461346
}
13471347

1348-
static void test_lm_cdq(void)
1348+
static void test_lm_cdq_delete(void)
13491349
{
13501350
__u32 result = 0;
13511351
__u8 expected_data[8], data[8] = {};
1352-
struct nvme_lm_cdq_args args = {
1353-
.result = 0,
1354-
.data = &data,
1355-
.args_size = sizeof(args),
1356-
.mos = 0x1,
1357-
.cntlid = 0x2,
1358-
.cdqid = 0x3,
1359-
.sel = NVME_LM_SEL_DELETE_CDQ,
1360-
.sz = 0x4,
1361-
};
1362-
1352+
__u16 mos = 0x1;
1353+
__u16 cdqid = 0x3;
1354+
__u8 sel = NVME_LM_SEL_DELETE_CDQ;
1355+
__u32 sz = 0;
13631356
struct mock_cmd mock_admin_cmd = {
13641357
.opcode = nvme_admin_ctrl_data_queue,
1365-
.cdw10 = args.sel | (args.mos << 16),
1366-
.cdw11 = args.cdqid,
1367-
.cdw12 = args.sz,
1358+
.cdw10 = sel | (mos << 16),
1359+
.cdw11 = cdqid,
1360+
.cdw12 = sz,
13681361
.data_len = 0,
13691362
.in_data = &expected_data,
13701363
};
1371-
1364+
struct nvme_passthru_cmd cmd;
13721365
int err;
13731366

13741367
arbitrary(&expected_data, sizeof(expected_data));
13751368
memcpy(&data, &expected_data, sizeof(expected_data));
13761369
set_mock_admin_cmds(&mock_admin_cmd, 1);
1377-
err = nvme_lm_cdq(test_hdl, &args);
1370+
nvme_init_lm_cdq_delete(&cmd, mos, cdqid);
1371+
err = nvme_submit_admin_passthru(test_hdl, &cmd, &result);
13781372
end_mock_cmds();
13791373
check(err == 0, "returned error %d", err);
13801374
check(result == 0, "returned result %u", result);
@@ -1559,7 +1553,7 @@ int main(void)
15591553
RUN_TEST(fdp_reclaim_unit_handle_status);
15601554
RUN_TEST(fdp_reclaim_unit_handle_update);
15611555
RUN_TEST(dim_send);
1562-
RUN_TEST(lm_cdq);
1556+
RUN_TEST(lm_cdq_delete);
15631557
RUN_TEST(lm_track_send);
15641558
RUN_TEST(lm_migration_send);
15651559
RUN_TEST(lm_migration_recv);

0 commit comments

Comments
 (0)