Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion libnvme/src/nvme/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
/**
* struct nvme_passthru_cmd - nvme passthrough command structure
* @opcode: Operation code, see &enum nvme_io_opcodes and &enum nvme_admin_opcodes
* @flags: Not supported: intended for command flags (eg: SGL, FUSE)
* @flags: Supported only for NVMe-MI
* @rsvd1: Reserved for future use
* @nsid: Namespace Identifier, or Fabrics type
* @cdw2: Command Dword 2 (no spec defined use)
Expand Down Expand Up @@ -440,6 +440,8 @@ enum nvme_cmd_dword_fields {
NVME_COPY_CDW15_LBAT_MASK = 0xffff,
NVME_COPY_CDW15_LBATM_SHIFT = 16,
NVME_COPY_CDW15_LBATM_MASK = 0xffff,
NVME_MI_ADMIN_CFLAGS_ISH_SHIFT = 2,
NVME_MI_ADMIN_CFLAGS_ISH_MASK = 0x1,
};

#define NVME_FIELD_ENCODE(value, shift, mask) \
Expand Down Expand Up @@ -7082,4 +7084,20 @@ nvme_get_features_simple(struct nvme_transport_handle *hdl, __u8 fid,
*result = cmd.result;
return err;
}

/**
* nvme_init_mi_cmd_flags() - Initialize command flags for NVMe-MI
* @cmd: Passthru command to use
* @ish: Ignore Shutdown (for NVMe-MI command)
*
* Initializes the passthru command flags
*/
static inline void
nvme_init_mi_cmd_flags(struct nvme_passthru_cmd *cmd, bool ish)
{
cmd->flags = NVME_FIELD_ENCODE(ish,
NVME_MI_ADMIN_CFLAGS_ISH_SHIFT,
NVME_MI_ADMIN_CFLAGS_ISH_MASK);
}

#endif /* _LIBNVME_IOCTL_H */
27 changes: 17 additions & 10 deletions libnvme/src/nvme/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,17 @@ bool nvme_transport_handle_is_mi(struct nvme_transport_handle *hdl)
return hdl->type == NVME_TRANSPORT_HANDLE_TYPE_MI;
}

int nvme_fw_download_seq(struct nvme_transport_handle *hdl, __u32 size,
__u32 xfer, __u32 offset, void *buf)
int nvme_fw_download_seq(struct nvme_transport_handle *hdl, bool ish,
__u32 size, __u32 xfer, __u32 offset, void *buf)
{
struct nvme_passthru_cmd cmd;
void *data = buf;
int err = 0;

if (ish && nvme_transport_handle_is_mi(hdl)) {
nvme_init_mi_cmd_flags(&cmd, ish);
}

while (size > 0) {
err = nvme_init_fw_download(&cmd, data, MIN(xfer, size), offset);
if (err)
Expand Down Expand Up @@ -525,13 +529,16 @@ int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae, struct
return 0;
}

static int nvme_ns_attachment(struct nvme_transport_handle *hdl, __u32 nsid,
__u16 num_ctrls, __u16 *ctrlist, bool attach)
static int nvme_ns_attachment(struct nvme_transport_handle *hdl, bool ish,
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist, bool attach)
{
struct nvme_ctrl_list cntlist = { 0 };
struct nvme_passthru_cmd cmd;

nvme_init_ctrl_list(&cntlist, num_ctrls, ctrlist);
if (ish && nvme_transport_handle_is_mi(hdl))
nvme_init_mi_cmd_flags(&cmd, ish);

if (attach)
nvme_init_ns_attach_ctrls(&cmd, nsid, &cntlist);
else
Expand All @@ -540,16 +547,16 @@ static int nvme_ns_attachment(struct nvme_transport_handle *hdl, __u32 nsid,
return nvme_submit_admin_passthru(hdl, &cmd);
}

int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, __u32 nsid,
__u16 num_ctrls, __u16 *ctrlist)
int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, bool ish,
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist)
{
return nvme_ns_attachment(hdl, nsid, num_ctrls, ctrlist, true);
return nvme_ns_attachment(hdl, ish, nsid, num_ctrls, ctrlist, true);
}

int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, __u32 nsid,
__u16 num_ctrls, __u16 *ctrlist)
int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, bool ish,
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist)
{
return nvme_ns_attachment(hdl, nsid, num_ctrls, ctrlist, false);
return nvme_ns_attachment(hdl, ish, nsid, num_ctrls, ctrlist, false);
}

size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl,
Expand Down
13 changes: 9 additions & 4 deletions libnvme/src/nvme/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* nvme_fw_download_seq() - Firmware download sequence
* @hdl: Transport handle
* @ish: Ignore Shutdown (for NVMe-MI command)
* @size: Total size of the firmware image to transfer
* @xfer: Maximum size to send with each partial transfer
* @offset: Starting offset to send with this firmware download
Expand All @@ -32,8 +33,8 @@
* Return: 0 on success, the nvme command status if a response was
* received (see &enum nvme_status_field) or a negative error otherwise.
*/
int nvme_fw_download_seq(struct nvme_transport_handle *hdl, __u32 size, __u32 xfer, __u32 offset,
void *buf);
int nvme_fw_download_seq(struct nvme_transport_handle *hdl, bool ish,
__u32 size, __u32 xfer, __u32 offset, void *buf);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see we still have to modify the linux.h API for this, because this is API is wrapping the command initialization and the command submission into one function. There are more of these function left in the code base. Ideally we could convert them somehow into the other style (splitting command initialization and submission). Though this is a different task. So for this here it's fine. I am glad we don't have to update all the ioctl.h APIs with this approach :)


/**
* nvme_set_etdas() - Set the Extended Telemetry Data Area 4 Supported bit
Expand Down Expand Up @@ -193,26 +194,30 @@ int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae, struct
/**
* nvme_namespace_attach_ctrls() - Attach namespace to controller(s)
* @hdl: Transport handle
* @ish: Ignore Shutdown (for NVMe-MI command)
* @nsid: Namespace ID to attach
* @num_ctrls: Number of controllers in ctrlist
* @ctrlist: List of controller IDs to perform the attach action
*
* Return: 0 on success, the nvme command status if a response was
* received (see &enum nvme_status_field) or a negative error otherwise.
*/
int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist);
int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, bool ish,
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist);

/**
* nvme_namespace_detach_ctrls() - Detach namespace from controller(s)
* @hdl: Transport handle
* @ish: Ignore Shutdown (for NVMe-MI command)
* @nsid: Namespace ID to detach
* @num_ctrls: Number of controllers in ctrlist
* @ctrlist: List of controller IDs to perform the detach action
*
* Return: 0 on success, the nvme command status if a response was
* received (see &enum nvme_status_field) or a negative error otherwise.
*/
int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist);
int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, bool ish,
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist);

/**
* nvme_open() - Open an nvme controller or namespace device
Expand Down
3 changes: 2 additions & 1 deletion libnvme/src/nvme/mi.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl,
}

nvme_mi_admin_init_req(hdl->ep, &req, &req_hdr, hdl->id, cmd->opcode);
req_hdr.flags = cmd->flags;
req_hdr.cdw1 = cpu_to_le32(cmd->nsid);
req_hdr.cdw2 = cpu_to_le32(cmd->cdw2);
req_hdr.cdw3 = cpu_to_le32(cmd->cdw3);
Expand All @@ -909,7 +910,7 @@ int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl,
if (cmd->data_len != 0) {
req_hdr.dlen = cpu_to_le32(cmd->data_len);
/* Bit 0 set to 1 means DLEN contains a value */
req_hdr.flags = 0x1;
req_hdr.flags |= 0x1;
}

if (has_write_data) {
Expand Down
Loading