Skip to content

Commit 9a0deb4

Browse files
committed
ioctl: rework nvme_lm_migration_send 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 2542994 commit 9a0deb4

5 files changed

Lines changed: 98 additions & 120 deletions

File tree

libnvme/src/libnvme.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ LIBNVME_2_0 {
139139
nvme_ipaddrs_eq;
140140
nvme_lm_get_features_ctrl_data_queue;
141141
nvme_lm_migration_recv;
142-
nvme_lm_migration_send;
143142
nvme_lm_set_features_ctrl_data_queue;
144143
nvme_lookup_ctrl;
145144
nvme_lookup_host;

libnvme/src/nvme/api-types.h

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

146-
/**
147-
* struct nvme_lm_migration_send_args - Arguments for the Migration Send command
148-
* @offset: Offset: This field specifies the offset, in bytes, within the data available to be
149-
* returned and specifies the starting point for that data for what is actually
150-
* returned to the host.
151-
* @result: Set on completion to the command's CQE DWORD 0 controller response
152-
* @data: Pointer to data
153-
* @args_size: Length of structure
154-
* @timeout: Timeout in ms
155-
* @numd: Number of Dwords (NUMD): This field specifies the number of dwords being transferred
156-
* @mos: Management Operation Specific (MOS): This field is specific to the SEL type
157-
* @cntlid: Controller ID: This field specifies the identifier of the controller to which the
158-
* operation is performed.
159-
* @csuuidi: Controller State UUID Index (CSUUIDI): A non-zero value in this field specifies the
160-
* index to a specific entry in the Vendor Specific Controller State UUID Supported.
161-
* list of the Supported Controller State Formats data structure.
162-
* @sel: Select (SEL): This field specifies the type of management operation to perform.
163-
* @uidx: UUID Index (UIDX): If this field is set to a non-zero value, then the value of this
164-
* field is the index of a UUID in the UUID List (refer to Figure 320) that is used by
165-
* the command.
166-
* @stype: Suspend Type (STYPE): This field specifies the type of suspend.
167-
* @seqind: Sequence Identifier (SEQIND): This field identified the sequences of this Migration
168-
* Send command in relation to other Migration Send commands.
169-
* @csvi: Controller State Version Index (CSVI): A non-zero value in this field specifies the
170-
* index to a specific entry in the NVMe Controller State Version list of the Supported
171-
* Controller State Formats data structure.
172-
* @dudmq: Delete User Data Migration Queue (DUDMQ): If set, the migration queue is deleted
173-
* is deleted as part of the Suspend operation. If cleared, it is retained.
174-
*/
175-
struct nvme_lm_migration_send_args {
176-
__u64 offset;
177-
__u32 *result;
178-
void *data;
179-
int args_size;
180-
__u32 timeout;
181-
__u32 numd;
182-
__u16 mos;
183-
__u16 cntlid;
184-
__u16 csuuidi;
185-
__u8 sel;
186-
__u8 uidx;
187-
__u8 stype;
188-
__u8 seqind;
189-
__u8 csvi;
190-
bool dudmq;
191-
};
192-
193146
/**
194147
* struct nvme_lm_migration_recv_args - Arguments for the Migration Receive command
195148
* @offset: Offset: This field specifies the offset, in bytes, within the data available to be

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_migration_send(struct nvme_transport_handle *hdl, struct nvme_lm_migration_send_args *args)
776-
{
777-
__u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_SEND_SEL) |
778-
NVME_SET(args->mos, LM_MIGRATION_SEND_MOS);
779-
__u32 cdw11 = 0;
780-
781-
if (args->sel == NVME_LM_SEL_SUSPEND) {
782-
cdw11 = NVME_SET(args->stype, LM_STYPE) |
783-
NVME_SET(args->cntlid, LM_SUSPEND_CNTLID);
784-
if (args->dudmq)
785-
cdw11 |= NVME_LM_DUDMQ;
786-
} else if (args->sel == NVME_LM_SEL_RESUME) {
787-
cdw11 = NVME_SET(args->cntlid, LM_RESUME_CNTLID);
788-
} else if (args->sel == NVME_LM_SEL_SET_CONTROLLER_STATE) {
789-
cdw11 = NVME_SET(args->csuuidi, LM_SET_CONTROLLER_STATE_CSUUIDI) |
790-
NVME_SET(args->csvi, LM_SET_CONTROLLER_STATE_CSVI) |
791-
NVME_SET(args->cntlid, LM_SET_CONTROLLER_STATE_CNTLID);
792-
}
793-
794-
struct nvme_passthru_cmd cmd = {
795-
.opcode = nvme_admin_migration_send,
796-
.cdw10 = cdw10,
797-
.cdw11 = cdw11,
798-
.cdw12 = (__u32)args->offset,
799-
.cdw13 = (__u32)(args->offset >> 32),
800-
.cdw14 = NVME_SET(args->uidx, LM_MIGRATION_SEND_UIDX),
801-
.cdw15 = args->numd,
802-
.addr = (__u64)(uintptr_t)args->data,
803-
.data_len = args->numd << 2,
804-
.timeout_ms = args->timeout,
805-
};
806-
807-
if (args->args_size < sizeof(*args))
808-
return -EINVAL;
809-
810-
return nvme_submit_admin_passthru(hdl, &cmd, args->result);
811-
}
812-
813775
int nvme_lm_migration_recv(struct nvme_transport_handle *hdl, struct nvme_lm_migration_recv_args *args)
814776
{
815777
__u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_RECV_SEL) |

libnvme/src/nvme/ioctl.h

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5166,14 +5166,83 @@ nvme_init_lm_track_send(struct nvme_passthru_cmd *cmd,
51665166
}
51675167

51685168
/**
5169-
* nvme_lm_migration_send() - Migration Send command
5170-
* @hdl: Transport handle
5171-
* @args: &struct nvme_lm_migration_send_args argument structure
5169+
* nvme_init_lm_migration_send() - Initialize passthru command for
5170+
* Migration Send command
5171+
* @cmd: Passthru command to use
5172+
* @sel: Select (SEL): This field specifies the type of management
5173+
* operation to perform.
5174+
* @mos: Management Operation Specific (MOS): This field is specific
5175+
* to the SEL type
5176+
* @cntlid: Controller ID: This field specifies the identifier of the
5177+
* controller to which the operation is performed.
5178+
* @stype: Suspend Type (STYPE): This field specifies the type of suspend.
5179+
* @dudmq: Delete User Data Migration Queue (DUDMQ): If set, the migration
5180+
* queue is deleted is deleted as part of the Suspend operation.
5181+
* @csvi: Controller State Version Index (CSVI)
5182+
* @csuuidi: Controller State UUID Index (CSUUIDI)
5183+
* @cso: Offset: This field specifies the offset, in bytes, within
5184+
* the data available to be returned and specifies the starting
5185+
* point for that data for what is actually returned to the host.
5186+
* @uidx: UUID Index (UIDX)
5187+
* @data: Pointer to data buffer
5188+
* @len: Length of @data
51725189
*
5173-
* Return: 0 on success, the nvme command status if a response was
5174-
* received (see &enum nvme_status_field) or a negative error otherwise.
5190+
* Initializes the passthru command buffer for the Migration Send command.
51755191
*/
5176-
int nvme_lm_migration_send(struct nvme_transport_handle *hdl, struct nvme_lm_migration_send_args *args);
5192+
static inline void
5193+
nvme_init_lm_migration_send(struct nvme_passthru_cmd *cmd,
5194+
__u16 sel, __u16 mos, __u16 cntlid, __u8 stype, bool dudmq,
5195+
__u8 csvi, __u16 csuuidi, __u64 cso, __u8 uidx,
5196+
void *data, __u32 len)
5197+
{
5198+
__u32 cdw10 = NVME_FIELD_ENCODE(sel,
5199+
NVME_LM_MIGRATION_SEND_SEL_SHIFT,
5200+
NVME_LM_MIGRATION_SEND_SEL_MASK) |
5201+
NVME_FIELD_ENCODE(mos,
5202+
NVME_LM_MIGRATION_SEND_MOS_SHIFT,
5203+
NVME_LM_MIGRATION_SEND_MOS_MASK);
5204+
__u32 cdw11 = 0;
5205+
__u32 cdw14 = NVME_FIELD_ENCODE(uidx,
5206+
NVME_LM_MIGRATION_SEND_UIDX_SHIFT,
5207+
NVME_LM_MIGRATION_SEND_UIDX_MASK);
5208+
5209+
if (sel == NVME_LM_SEL_SUSPEND) {
5210+
cdw11 = NVME_FIELD_ENCODE(stype,
5211+
NVME_LM_STYPE_SHIFT,
5212+
NVME_LM_STYPE_MASK) |
5213+
NVME_FIELD_ENCODE(cntlid,
5214+
NVME_LM_SUSPEND_CNTLID_SHIFT,
5215+
NVME_LM_SUSPEND_CNTLID_MASK);
5216+
if (dudmq)
5217+
cdw11 |= NVME_LM_DUDMQ;
5218+
} else if (sel == NVME_LM_SEL_RESUME) {
5219+
cdw11 = NVME_FIELD_ENCODE(cntlid,
5220+
NVME_LM_RESUME_CNTLID_SHIFT,
5221+
NVME_LM_RESUME_CNTLID_MASK);
5222+
} else if (sel == NVME_LM_SEL_SET_CONTROLLER_STATE) {
5223+
cdw11 = NVME_FIELD_ENCODE(csuuidi,
5224+
NVME_LM_SET_CONTROLLER_STATE_CSUUIDI_SHIFT,
5225+
NVME_LM_SET_CONTROLLER_STATE_CSUUIDI_MASK) |
5226+
NVME_FIELD_ENCODE(csvi,
5227+
NVME_LM_SET_CONTROLLER_STATE_CSVI_SHIFT,
5228+
NVME_LM_SET_CONTROLLER_STATE_CSVI_MASK) |
5229+
NVME_FIELD_ENCODE(cntlid,
5230+
NVME_LM_SET_CONTROLLER_STATE_CNTLID_SHIFT,
5231+
NVME_LM_SET_CONTROLLER_STATE_CNTLID_MASK);
5232+
}
5233+
5234+
memset(cmd, 0, sizeof(*cmd));
5235+
5236+
cmd->opcode = nvme_admin_migration_send;
5237+
cmd->data_len = len;
5238+
cmd->addr = (__u64)(uintptr_t)data;
5239+
cmd->cdw10 = cdw10;
5240+
cmd->cdw11 = cdw11;
5241+
cmd->cdw12 = (__u32)cso;
5242+
cmd->cdw13 = (__u32)(cso >> 32);
5243+
cmd->cdw14 = cdw14;
5244+
cmd->cdw15 = len / sizeof(__u32);
5245+
}
51775246

51785247
/**
51795248
* nvme_lm_migration_recv - Migration Receive command

libnvme/test/ioctl/misc.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,43 +1399,38 @@ static void test_lm_track_send(void)
13991399

14001400
static void test_lm_migration_send(void)
14011401
{
1402-
__u32 result = 0;
14031402
__u32 expected_data[8], data[8] = {};
1404-
struct nvme_lm_migration_send_args args = {
1405-
.offset = 0xffffffffff,
1406-
.result = 0,
1407-
.data = &expected_data,
1408-
.args_size = sizeof(args),
1409-
.numd = 8 - 1,
1410-
.mos = 0x1,
1411-
.cntlid = 0x2,
1412-
.csuuidi = 0x3,
1413-
.sel = NVME_LM_SEL_RESUME,
1414-
.uidx = 0x4,
1415-
.stype = 0x5,
1416-
.seqind = 0x6,
1417-
.csvi = 0x7,
1418-
.dudmq = true,
1419-
};
1420-
1403+
__u8 sel = NVME_LM_SEL_RESUME;
1404+
__u64 offset = 0xffffffffff;
1405+
__u32 numd = 8;
1406+
__u16 cntlid = 0x2;
1407+
__u32 result = 0;
1408+
__u16 mos = 0x1;
1409+
__u8 uidx = 0x4;
1410+
__u8 stype = 0x1;
1411+
__u8 csvi = 0x2;
1412+
__u16 csuuidi = 0x13;
1413+
bool dudmq = false;
14211414
struct mock_cmd mock_admin_cmd = {
14221415
.opcode = nvme_admin_migration_send,
1423-
.cdw10 = args.sel | (args.mos << 16),
1424-
.cdw11 = args.cntlid,
1425-
.cdw12 = (__u32)args.offset,
1426-
.cdw13 = (__u32)(args.offset >> 32),
1427-
.cdw14 = args.uidx,
1428-
.cdw15 = args.numd,
1429-
.data_len = args.numd << 2,
1430-
.in_data = &data,
1416+
.cdw10 = sel | (mos << 16),
1417+
.cdw11 = cntlid,
1418+
.cdw12 = (__u32)offset,
1419+
.cdw13 = (__u32)(offset >> 32),
1420+
.cdw14 = uidx,
1421+
.cdw15 = numd,
1422+
.data_len = numd << 2,
1423+
.in_data = &expected_data,
14311424
};
1432-
1425+
struct nvme_passthru_cmd cmd;
14331426
int err;
14341427

14351428
arbitrary(&expected_data, sizeof(expected_data));
14361429
memcpy(&data, &expected_data, sizeof(expected_data));
14371430
set_mock_admin_cmds(&mock_admin_cmd, 1);
1438-
err = nvme_lm_migration_send(test_hdl, &args);
1431+
nvme_init_lm_migration_send(&cmd, sel, mos, cntlid, stype, dudmq,
1432+
csvi, csuuidi, offset, uidx, &data, sizeof(data));
1433+
err = nvme_submit_admin_passthru(test_hdl, &cmd, &result);
14391434
end_mock_cmds();
14401435
check(err == 0, "returned error %d", err);
14411436
check(result == 0, "returned result %u", result);

0 commit comments

Comments
 (0)