Skip to content

Commit 66e8bcd

Browse files
committed
ioctl: rework nvme_dim_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 be36b9b commit 66e8bcd

6 files changed

Lines changed: 35 additions & 68 deletions

File tree

libnvme/src/libnvme.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ LIBNVME_2_0 {
6969
nvme_ctrls_filter;
7070
nvme_default_host;
7171
nvme_describe_key_serial;
72-
nvme_dim_send;
7372
nvme_disconnect_ctrl;
7473
nvme_dump_config;
7574
nvme_dump_tree;

libnvme/src/nvme/api-types.h

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

146-
/**
147-
* struct nvme_dim_args - Arguments for the Discovery Information Management (DIM) command
148-
* @result: Set on completion to the command's CQE DWORD 0 controller response.
149-
* @data: Pointer to the DIM data
150-
* @args_size: Length of the structure
151-
* @timeout: Timeout in ms
152-
* @data_len: Length of @data
153-
* @tas: Task field of the Command Dword 10 (cdw10)
154-
*/
155-
struct nvme_dim_args {
156-
__u32 *result;
157-
void *data;
158-
int args_size;
159-
__u32 timeout;
160-
__u32 data_len;
161-
__u8 tas;
162-
};
163-
164146
/**
165147
* struct nvme_lm_cdq_args - Arguments for Controller Data Queue (CDQ) command
166148
* @result: Set on completion to the command's CQE DWORD 0 controller response

libnvme/src/nvme/fabrics.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,18 +1596,13 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype,
15961596
{
15971597
struct nvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL;
15981598
_cleanup_free_ struct nvmf_dim_data *dim = NULL;
1599+
struct nvme_transport_handle *hdl = nvme_ctrl_get_transport_handle(c);
1600+
struct nvme_passthru_cmd cmd;
15991601
struct nvmf_ext_die *die;
16001602
__u32 tdl;
16011603
__u32 tel;
16021604
int ret;
16031605

1604-
struct nvme_dim_args args = {
1605-
.args_size = sizeof(args),
1606-
.result = result,
1607-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
1608-
.tas = tas
1609-
};
1610-
16111606
if (!c->s) {
16121607
nvme_msg(ctx, LOG_ERR,
16131608
"%s: failed to perform DIM. subsystem undefined.\n",
@@ -1673,9 +1668,8 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype,
16731668
die = &dim->die->extended;
16741669
nvmf_fill_die(die, c->s->h, tel, trtype, adrfam, reg_addr, tsas);
16751670

1676-
args.data_len = tdl;
1677-
args.data = dim;
1678-
return nvme_dim_send(nvme_ctrl_get_transport_handle(c), &args);
1671+
nvme_init_dim_send(&cmd, tas, dim, tdl);
1672+
return nvme_submit_admin_passthru(hdl, &cmd, NULL);
16791673
}
16801674

16811675
/**

libnvme/src/nvme/ioctl.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -772,25 +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_dim_send(struct nvme_transport_handle *hdl, struct nvme_dim_args *args)
776-
{
777-
__u32 cdw10 = NVME_SET(args->tas, DIM_TAS);
778-
779-
struct nvme_passthru_cmd cmd = {
780-
.opcode = nvme_admin_discovery_info_mgmt,
781-
.cdw10 = cdw10,
782-
.addr = (__u64)(uintptr_t)args->data,
783-
.data_len = args->data_len,
784-
.timeout_ms = args->timeout,
785-
};
786-
787-
if (args->args_size < sizeof(*args))
788-
return -EINVAL;
789-
790-
return nvme_submit_admin_passthru(hdl, &cmd, args->result);
791-
}
792-
793-
794775
int nvme_lm_cdq(struct nvme_transport_handle *hdl, struct nvme_lm_cdq_args *args)
795776
{
796777
__u32 cdw10 = NVME_SET(args->sel, LM_CDQ_SEL) |

libnvme/src/nvme/ioctl.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ enum nvme_cmd_dword_fields {
329329
NVME_ZNS_MGMT_RECV_ZRA_SHIFT = 0,
330330
NVME_ZNS_MGMT_RECV_ZRA_MASK = 0xff,
331331
NVME_DIM_TAS_SHIFT = 0,
332-
NVME_DIM_TAS_MASK = 0xF,
332+
NVME_DIM_TAS_MASK = 0xf,
333333
NVME_DSM_CDW10_NR_SHIFT = 0,
334334
NVME_DSM_CDW10_NR_MASK = 0xff,
335335
NVME_DSM_CDW11_IDR_SHIFT = 0,
@@ -5037,14 +5037,30 @@ nvme_init_zns_append(struct nvme_passthru_cmd64 *cmd, __u32 nsid,
50375037
}
50385038

50395039
/**
5040-
* nvme_dim_send - Send a Discovery Information Management (DIM) command
5041-
* @hdl: Transport handle
5042-
* @args: &struct nvme_dim_args argument structure
5040+
* nvme_init_dim_send() - Initialize passthru command for
5041+
* Discovery Information Management (DIM) Send
5042+
* @cmd: Passthru command to use
5043+
* @tas: Task field of the Command Dword 10 (cdw10)
5044+
* @data: Pointer to the DIM data buffer
5045+
* @len: Length of @data
50435046
*
5044-
* Return: 0 on success, the nvme command status if a response was
5045-
* received (see &enum nvme_status_field) or a negative error otherwise.
5047+
* Initializes the passthru command buffer for the Discovery Information
5048+
* Management Send command.
50465049
*/
5047-
int nvme_dim_send(struct nvme_transport_handle *hdl, struct nvme_dim_args *args);
5050+
static inline void
5051+
nvme_init_dim_send(struct nvme_passthru_cmd *cmd,
5052+
__u8 tas, void *data, __u32 len)
5053+
{
5054+
memset(cmd, 0, sizeof(*cmd));
5055+
5056+
cmd->opcode = nvme_admin_discovery_info_mgmt;
5057+
cmd->data_len = len;
5058+
cmd->addr = (__u64)(uintptr_t)data;
5059+
cmd->cdw10 = NVME_FIELD_ENCODE(tas,
5060+
NVME_DIM_TAS_SHIFT,
5061+
NVME_DIM_TAS_MASK);
5062+
5063+
}
50485064

50495065
/**
50505066
* nvme_lm_cdq() - Controller Data Queue - Controller Data Queue command

libnvme/test/ioctl/misc.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,29 +1321,24 @@ static void test_fdp_reclaim_unit_handle_update(void)
13211321

13221322
static void test_dim_send(void)
13231323
{
1324-
__u32 result = 0;
13251324
__u8 expected_data[8], data[8] = {};
1326-
struct nvme_dim_args args = {
1327-
.result = 0,
1328-
.data = &data,
1329-
.args_size = sizeof(args),
1330-
.data_len = sizeof(data),
1331-
.tas = 0xf,
1332-
};
1333-
1325+
__u32 data_len = sizeof(data);
1326+
__u32 result = 0;
1327+
__u8 tas = 0xf;
13341328
struct mock_cmd mock_admin_cmd = {
13351329
.opcode = nvme_admin_discovery_info_mgmt,
1336-
.cdw10 = args.tas,
1337-
.data_len = args.data_len,
1330+
.cdw10 = tas,
1331+
.data_len =data_len,
13381332
.in_data = &expected_data,
13391333
};
1340-
1334+
struct nvme_passthru_cmd cmd;
13411335
int err;
13421336

13431337
arbitrary(&expected_data, sizeof(expected_data));
13441338
memcpy(&data, &expected_data, sizeof(expected_data));
13451339
set_mock_admin_cmds(&mock_admin_cmd, 1);
1346-
err = nvme_dim_send(test_hdl, &args);
1340+
nvme_init_dim_send(&cmd, tas, data, data_len);
1341+
err = nvme_submit_admin_passthru(test_hdl, &cmd, &result);
13471342
end_mock_cmds();
13481343
check(err == 0, "returned error %d", err);
13491344
check(result == 0, "returned result %u", result);

0 commit comments

Comments
 (0)