Skip to content

Commit 4303b8a

Browse files
committed
ioctl: rework nvme_lm_migration_recv 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 9a2cd4f commit 4303b8a

5 files changed

Lines changed: 79 additions & 104 deletions

File tree

libnvme/src/libnvme.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ LIBNVME_2_0 {
138138
nvme_io_passthru;
139139
nvme_ipaddrs_eq;
140140
nvme_lm_get_features_ctrl_data_queue;
141-
nvme_lm_migration_recv;
142141
nvme_lm_set_features_ctrl_data_queue;
143142
nvme_lookup_ctrl;
144143
nvme_lookup_host;

libnvme/src/nvme/api-types.h

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

146-
/**
147-
* struct nvme_lm_migration_recv_args - Arguments for the Migration Receive 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-
* @fd: File descriptor of nvme device
155-
* @timeout: Timeout in ms
156-
* @numd: Number of Dwords (NUMD): This field specifies the number of dwords to return. This
157-
* is a 0's based value.
158-
* @mos: Management Operation Specific (MOS): This field is specific to the SEL type
159-
* @cntlid: Controller ID: This field specifies the identifier of the controller to which the
160-
* operation is performed.
161-
* @csuuidi: Controller State UUID Index (CSUUIDI): A non-zero value in this field specifies the
162-
* index to a specific entry in the Vendor Specific Controller State UUID Supported.
163-
* list of the Supported Controller State Formats data structure.
164-
* @sel: Select (SEL): This field specifies the type of management operation to perform
165-
* @uidx: UUID Index (UIDX): If this field is set to a non-zero value, then the value of this
166-
* field is the index of a UUID in the UUID List (refer to Figure 320) that is used by
167-
* the command.
168-
* @csuidxp: Controller State UUID Index Parameter (CSUIDXP): This field is vendor specific.
169-
*/
170-
struct nvme_lm_migration_recv_args {
171-
__u64 offset;
172-
__u32 *result;
173-
void *data;
174-
int args_size;
175-
int fd;
176-
__u32 timeout;
177-
__u32 numd;
178-
__u16 mos;
179-
__u16 cntlid;
180-
__u16 csuuidi;
181-
__u8 sel;
182-
__u8 uidx;
183-
__u8 csuidxp;
184-
};
185-
186146
#endif /* _LIBNVME_API_TYPES_H */

libnvme/src/nvme/ioctl.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -772,38 +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_recv(struct nvme_transport_handle *hdl, struct nvme_lm_migration_recv_args *args)
776-
{
777-
__u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_RECV_SEL) |
778-
NVME_SET(args->mos, LM_MIGRATION_RECV_MOS);
779-
__u32 cdw11 = 0, data_len = 0;
780-
781-
if (args->sel == NVME_LM_SEL_GET_CONTROLLER_STATE) {
782-
cdw11 = NVME_SET(args->csuidxp, LM_GET_CONTROLLER_STATE_CSUIDXP) |
783-
NVME_SET(args->csuuidi, LM_GET_CONTROLLER_STATE_CSUUIDI) |
784-
NVME_SET(args->cntlid, LM_GET_CONTROLLER_STATE_CNTLID);
785-
data_len = (args->numd + 1 /*0's based*/) << 2;
786-
}
787-
788-
struct nvme_passthru_cmd cmd = {
789-
.opcode = nvme_admin_migration_receive,
790-
.cdw10 = cdw10,
791-
.cdw11 = cdw11,
792-
.cdw12 = (__u32)args->offset,
793-
.cdw13 = (__u32)(args->offset >> 32),
794-
.cdw14 = NVME_SET(args->uidx, LM_MIGRATION_RECV_UIDX),
795-
.cdw15 = args->numd,
796-
.addr = (__u64)(uintptr_t)args->data,
797-
.data_len = data_len,
798-
.timeout_ms = args->timeout,
799-
};
800-
801-
if (args->args_size < sizeof(*args))
802-
return -EINVAL;
803-
804-
return nvme_submit_admin_passthru(hdl, &cmd, args->result);
805-
}
806-
807775
int nvme_lm_set_features_ctrl_data_queue(struct nvme_transport_handle *hdl, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt,
808776
__u32 *result)
809777
{

libnvme/src/nvme/ioctl.h

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5245,14 +5245,66 @@ nvme_init_lm_migration_send(struct nvme_passthru_cmd *cmd,
52455245
}
52465246

52475247
/**
5248-
* nvme_lm_migration_recv - Migration Receive command
5249-
* @hdl: Transport handle
5250-
* @args: &struct nvme_lm_migration_rev_args argument structure
5248+
* nvme_init_lm_migration_recv() - Initialize passthru command for
5249+
* Migration Receive command
5250+
* @cmd: Passthru command to use
5251+
* @offset: Offset: This field specifies the offset, in bytes, within
5252+
* the data available to be returned and specifies the starting
5253+
* point for that data for what is actually returned to the host.
5254+
* @mos: Management Operation Specific (MOS): This field is specific to
5255+
* the SEL type
5256+
* @cntlid: Controller ID: This field specifies the identifier of the
5257+
* controller to which the operation is performed.
5258+
* @csuuidi: Controller State UUID Index (CSUUIDI)
5259+
* @sel: Select (SEL): This field specifies the type of management
5260+
* operation to perform
5261+
* @uidx: UUID Index (UIDX)
5262+
* @csuidxp: Controller State UUID Index Parameter (CSUIDXP)
5263+
* @data: Pointer to data buffer
5264+
* @len: Length of @data
52515265
*
5252-
* Return: 0 on success, the nvme command status if a response was
5253-
* received (see &enum nvme_status_field) or a negative error otherwise.
5266+
* Initializes the passthru command buffer for the Migration Receive command.
52545267
*/
5255-
int nvme_lm_migration_recv(struct nvme_transport_handle *hdl, struct nvme_lm_migration_recv_args *args);
5268+
static inline void
5269+
nvme_init_lm_migration_recv(struct nvme_passthru_cmd *cmd,
5270+
__u64 offset, __u16 mos, __u16 cntlid, __u16 csuuidi, __u8 sel,
5271+
__u8 uidx, __u8 csuidxp, void *data, __u32 len)
5272+
{
5273+
__u32 cdw11 = 0;
5274+
__u32 data_len = 0;
5275+
5276+
if (sel == NVME_LM_SEL_GET_CONTROLLER_STATE) {
5277+
cdw11 = NVME_FIELD_ENCODE(csuidxp,
5278+
NVME_LM_GET_CONTROLLER_STATE_CSUIDXP_SHIFT,
5279+
NVME_LM_GET_CONTROLLER_STATE_CSUIDXP_MASK) |
5280+
NVME_FIELD_ENCODE(csuuidi,
5281+
NVME_LM_GET_CONTROLLER_STATE_CSUUIDI_SHIFT,
5282+
NVME_LM_GET_CONTROLLER_STATE_CSUUIDI_MASK) |
5283+
NVME_FIELD_ENCODE(cntlid,
5284+
NVME_LM_GET_CONTROLLER_STATE_CNTLID_SHIFT,
5285+
NVME_LM_GET_CONTROLLER_STATE_CNTLID_MASK);
5286+
data_len = len;
5287+
}
5288+
5289+
memset(cmd, 0, sizeof(*cmd));
5290+
5291+
cmd->opcode = nvme_admin_migration_receive;
5292+
cmd->data_len = data_len;
5293+
cmd->addr = (__u64)(uintptr_t)data;
5294+
cmd->cdw10 = NVME_FIELD_ENCODE(sel,
5295+
NVME_LM_MIGRATION_RECV_SEL_SHIFT,
5296+
NVME_LM_MIGRATION_RECV_SEL_MASK) |
5297+
NVME_FIELD_ENCODE(mos,
5298+
NVME_LM_MIGRATION_RECV_MOS_SHIFT,
5299+
NVME_LM_MIGRATION_RECV_MOS_MASK);
5300+
cmd->cdw11 = cdw11;
5301+
cmd->cdw12 = (__u32)offset;
5302+
cmd->cdw13 = (__u32)(offset >> 32);
5303+
cmd->cdw14 = NVME_FIELD_ENCODE(uidx,
5304+
NVME_LM_MIGRATION_RECV_UIDX_SHIFT,
5305+
NVME_LM_MIGRATION_RECV_UIDX_MASK);
5306+
cmd->cdw15 = len ? (__u32)((len - 1) / sizeof(__u32)) : 0;
5307+
}
52565308

52575309
/**
52585310
* nvme_lm_set_features_ctrl_data_queue - Set Controller Datea Queue feature

libnvme/test/ioctl/misc.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,40 +1439,36 @@ static void test_lm_migration_send(void)
14391439

14401440
static void test_lm_migration_recv(void)
14411441
{
1442-
__u32 result = 0;
1442+
__u8 sel = NVME_LM_SEL_GET_CONTROLLER_STATE;
14431443
__u32 expected_data[8], data[8] = {};
1444-
struct nvme_lm_migration_recv_args args = {
1445-
.offset = 0xffffffffff,
1446-
.result = 0,
1447-
.data = &data,
1448-
.args_size = sizeof(args),
1449-
.numd = 8 - 1,
1450-
.mos = 0x1,
1451-
.cntlid = 0x2,
1452-
.csuuidi = 0x3,
1453-
.sel = NVME_LM_SEL_GET_CONTROLLER_STATE,
1454-
.uidx = 0x4,
1455-
.csuidxp = 0x5,
1456-
};
1457-
1444+
__u64 offset = 0xffffffffff;
1445+
__u16 csuuidi = 0x3;
1446+
__u32 numd = 8 - 1;
1447+
__u16 cntlid = 0x2;
1448+
__u8 csuidxp = 0x5;
1449+
__u32 result = 0;
1450+
__u16 mos = 0x1;
1451+
__u8 uidx = 0x4;
14581452
struct mock_cmd mock_admin_cmd = {
14591453
.opcode = nvme_admin_migration_receive,
1460-
.cdw10 = args.sel | (args.mos << 16),
1461-
.cdw11 = args.cntlid | (args.csuuidi << 16) |
1462-
(args.csuidxp << 24),
1463-
.cdw12 = (__u32)args.offset,
1464-
.cdw13 = (__u32)(args.offset >> 32),
1465-
.cdw14 = args.uidx,
1466-
.cdw15 = args.numd,
1467-
.data_len = (args.numd + 1) << 2,
1454+
.cdw10 = sel | (mos << 16),
1455+
.cdw11 = cntlid | (csuuidi << 16) |
1456+
(csuidxp << 24),
1457+
.cdw12 = (__u32)offset,
1458+
.cdw13 = (__u32)(offset >> 32),
1459+
.cdw14 = uidx,
1460+
.cdw15 = numd,
1461+
.data_len = (numd + 1) << 2,
14681462
.out_data = &expected_data,
14691463
};
1470-
1464+
struct nvme_passthru_cmd cmd;
14711465
int err;
14721466

14731467
arbitrary(&expected_data, sizeof(expected_data));
14741468
set_mock_admin_cmds(&mock_admin_cmd, 1);
1475-
err = nvme_lm_migration_recv(test_hdl, &args);
1469+
nvme_init_lm_migration_recv(&cmd, offset, mos, cntlid, csuuidi, sel,
1470+
uidx, csuidxp, data, sizeof(data));
1471+
err = nvme_submit_admin_passthru(test_hdl, &cmd, &result);
14761472
end_mock_cmds();
14771473
check(err == 0, "returned error %d", err);
14781474
check(result == 0, "returned result %u", result);

0 commit comments

Comments
 (0)