Skip to content

Commit 126c2a8

Browse files
committed
ioctl: rework nvme_io commands
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 5f9db44 commit 126c2a8

6 files changed

Lines changed: 420 additions & 523 deletions

File tree

libnvme/src/libnvme.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ LIBNVME_2_0 {
133133
nvme_init_logging;
134134
nvme_insert_tls_key;
135135
nvme_insert_tls_key_versioned;
136-
nvme_io;
137136
nvme_io_passthru64;
138137
nvme_io_passthru;
139138
nvme_ipaddrs_eq;

libnvme/src/nvme/api-types.h

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -38,68 +38,6 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level);
3838
*/
3939
void nvme_free_global_ctx(struct nvme_global_ctx *ctx);
4040

41-
/**
42-
* struct nvme_io_args - Arguments for NVMe I/O commands
43-
* @slba: Starting logical block
44-
* @storage_tag: This filed specifies Variable Sized Expected Logical Block
45-
* Storage Tag (ELBST) or Logical Block Storage Tag (LBST)
46-
* @result: The command completion result from CQE dword0
47-
* @data: Pointer to user address of the data buffer
48-
* @metadata: Pointer to user address of the metadata buffer
49-
* @args_size: Size of &struct nvme_io_args
50-
* @timeout: Timeout in ms
51-
* @nsid: Namespace ID
52-
* @data_len: Length of user buffer, @data, in bytes
53-
* @metadata_len:Length of user buffer, @metadata, in bytes
54-
* @nlb: Number of logical blocks to send (0's based value)
55-
* @control: Command control flags, see &enum nvme_io_control_flags.
56-
* @apptag: This field specifies the Application Tag Mask expected value.
57-
* Used only if the namespace is formatted to use end-to-end
58-
* protection information.
59-
* @appmask: This field specifies the Application Tag expected value. Used
60-
* only if the namespace is formatted to use end-to-end protection
61-
* information.
62-
* @reftag: This field specifies the variable sized Expected Initial
63-
* Logical Block Reference Tag (EILBRT) or Initial Logical Block
64-
* Reference Tag (ILBRT). Used only if the namespace is formatted
65-
* to use end-to-end protection information.
66-
* @dspec: Directive specific value
67-
* @dsm: Data set management attributes, see &enum nvme_io_dsm_flags
68-
* @rsvd1: Reserved
69-
* @reftag_u64: This field specifies the variable sized Expected Initial
70-
* Logical Block Reference Tag (EILBRT) or Initial Logical Block
71-
* Reference Tag (ILBRT). It is the 8 byte version required for
72-
* enhanced protection information. Used only if the namespace is
73-
* formatted to use end-to-end protection information.
74-
* @sts: Storage tag size in bits, set by namespace Extended LBA Format
75-
* @pif: Protection information format, determines how variable sized
76-
* storage_tag and reftag are put into dwords 2, 3, and 14. Set by
77-
* namespace Extended LBA Format.
78-
*/
79-
struct nvme_io_args {
80-
__u64 slba;
81-
__u64 storage_tag;
82-
__u32 *result;
83-
void *data;
84-
void *metadata;
85-
int args_size;
86-
__u32 timeout;
87-
__u32 nsid;
88-
__u32 reftag;
89-
__u32 data_len;
90-
__u32 metadata_len;
91-
__u16 nlb;
92-
__u16 control;
93-
__u16 apptag;
94-
__u16 appmask;
95-
__u16 dspec;
96-
__u8 dsm;
97-
__u8 rsvd1[1];
98-
__u64 reftag_u64;
99-
__u8 sts;
100-
__u8 pif;
101-
};
102-
10341
/**
10442
* struct nvme_copy_args - Arguments for the NVMe Copy command
10543
* @sdlba: Start destination LBA

libnvme/src/nvme/ioctl.c

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -656,84 +656,6 @@ int nvme_io_passthru(struct nvme_transport_handle *hdl, __u8 opcode, __u8 flags,
656656
timeout_ms, result);
657657
}
658658

659-
static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw14,
660-
__u8 pif, __u8 sts, __u64 reftag, __u64 storage_tag)
661-
{
662-
__u32 cdw2 = 0, cdw3 = 0, cdw14;
663-
664-
switch (pif) {
665-
case NVME_NVM_PIF_16B_GUARD:
666-
cdw14 = reftag & 0xffffffff;
667-
cdw14 |= ((storage_tag << (32 - sts)) & 0xffffffff);
668-
break;
669-
case NVME_NVM_PIF_32B_GUARD:
670-
cdw14 = reftag & 0xffffffff;
671-
cdw3 = reftag >> 32;
672-
cdw14 |= ((storage_tag << (80 - sts)) & 0xffff0000);
673-
if (sts >= 48)
674-
cdw3 |= ((storage_tag >> (sts - 48)) & 0xffffffff);
675-
else
676-
cdw3 |= ((storage_tag << (48 - sts)) & 0xffffffff);
677-
cdw2 = (storage_tag >> (sts - 16)) & 0xffff;
678-
break;
679-
case NVME_NVM_PIF_64B_GUARD:
680-
cdw14 = reftag & 0xffffffff;
681-
cdw3 = (reftag >> 32) & 0xffff;
682-
cdw14 |= ((storage_tag << (48 - sts)) & 0xffffffff);
683-
if (sts >= 16)
684-
cdw3 |= ((storage_tag >> (sts - 16)) & 0xffff);
685-
else
686-
cdw3 |= ((storage_tag << (16 - sts)) & 0xffff);
687-
break;
688-
default:
689-
perror("Unsupported Protection Information Format");
690-
return -EINVAL;
691-
}
692-
693-
*cmd_dw2 = cdw2;
694-
*cmd_dw3 = cdw3;
695-
*cmd_dw14 = cdw14;
696-
return 0;
697-
}
698-
699-
int nvme_io(struct nvme_transport_handle *hdl, struct nvme_io_args *args, __u8 opcode)
700-
{
701-
__u32 cdw2, cdw3, cdw10, cdw11, cdw12, cdw13, cdw14, cdw15;
702-
703-
cdw10 = args->slba & 0xffffffff;
704-
cdw11 = args->slba >> 32;
705-
cdw12 = args->nlb | (args->control << 16);
706-
cdw13 = args->dsm | (args->dspec << 16);
707-
cdw15 = args->apptag | (args->appmask << 16);
708-
709-
if (nvme_set_var_size_tags(&cdw2, &cdw3, &cdw14,
710-
args->pif,
711-
args->sts,
712-
args->reftag_u64,
713-
args->storage_tag))
714-
return -EINVAL;
715-
716-
struct nvme_passthru_cmd cmd = {
717-
.opcode = opcode,
718-
.nsid = args->nsid,
719-
.cdw2 = cdw2,
720-
.cdw3 = cdw3,
721-
.cdw10 = cdw10,
722-
.cdw11 = cdw11,
723-
.cdw12 = cdw12,
724-
.cdw13 = cdw13,
725-
.cdw14 = cdw14,
726-
.cdw15 = cdw15,
727-
.data_len = args->data_len,
728-
.metadata_len = args->metadata_len,
729-
.addr = (__u64)(uintptr_t)args->data,
730-
.metadata = (__u64)(uintptr_t)args->metadata,
731-
.timeout_ms = args->timeout,
732-
};
733-
734-
return nvme_submit_io_passthru(hdl, &cmd, args->result);
735-
}
736-
737659
int nvme_copy(struct nvme_transport_handle *hdl, struct nvme_copy_args *args)
738660
{
739661
__u32 cdw3, cdw12, cdw14, data_len;

0 commit comments

Comments
 (0)