From 5f728ab8a54544c47c541bf785a93915551eda68 Mon Sep 17 00:00:00 2001 From: chendong76 <1209756284@qq.com> Date: Fri, 27 Oct 2023 15:46:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86nvme?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cm_utils/protocol/cm_nvme.c | 58 ++++----- src/cm_utils/protocol/cm_nvme.h | 119 ++++++++---------- .../service/ddes_perctrl_server.c | 2 +- 3 files changed, 83 insertions(+), 96 deletions(-) diff --git a/src/cm_utils/protocol/cm_nvme.c b/src/cm_utils/protocol/cm_nvme.c index 2c04219..60295e0 100644 --- a/src/cm_utils/protocol/cm_nvme.c +++ b/src/cm_utils/protocol/cm_nvme.c @@ -57,33 +57,33 @@ int cm_nvme_get_nsid(int fd, int32 *nsid) return CM_ERROR; } - *nsid = ioctl(fd, NVME_IOCTL_ID); + *nsid = ioctl(fd, CM_NVME_IOCTL_ID); if (*nsid == -1) { LOG_DEBUG_INF("ioctl get nsid error : %s\n", strerror(errno)); } return CM_SUCCESS; } -int cm_nvme_submit_passthru(int fd, unsigned long ioctl_cmd, struct nvme_passthru_cmd *cmd) +int cm_nvme_submit_passthru(int fd, unsigned long ioctl_cmd, struct cm_nvme_passthru_cmd *cmd) { return ioctl(fd, ioctl_cmd, cmd); } -int cm_nvme_submit_admin_passthru(int fd, struct nvme_passthru_cmd *cmd) +int cm_nvme_submit_admin_passthru(int fd, struct cm_nvme_passthru_cmd *cmd) { - return ioctl(fd, NVME_IOCTL_ADMIN_CMD, cmd); + return ioctl(fd, CM_NVME_IOCTL_ADMIN_CMD, cmd); } -int cm_nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd) +int cm_nvme_submit_io_passthru(int fd, struct cm_nvme_passthru_cmd *cmd) { - return ioctl(fd, NVME_IOCTL_IO_CMD, cmd); + return ioctl(fd, CM_NVME_IOCTL_IO_CMD, cmd); } int cm_nvme_io(int fd, uint8 opcode, uint8 flags, uint64 slba, uint16 nblocks, uint16 control, uint32 dsmgmt, uint32 reftag, uint16 apptag, uint16 appmask, void *data, void *metadata) { - struct nvme_user_io io = { + struct cm_nvme_user_io io = { .opcode = opcode, .flags = flags, .control = control, @@ -97,7 +97,7 @@ int cm_nvme_io(int fd, uint8 opcode, uint8 flags, uint64 slba, uint16 nblocks, u .appmask = appmask, .apptag = apptag, }; - return ioctl(fd, NVME_IOCTL_SUBMIT_IO, &io); + return ioctl(fd, CM_NVME_IOCTL_SUBMIT_IO, &io); } bool32 cm_nvme_is_rkey_exist(const int64 *reg_keys, int32 key_count, int64 rkey) @@ -128,8 +128,8 @@ int32 cm_nvme_register(int32 fd, int64 nrkey) __le64 payload[2] = { cpu_to_le64(crkey), cpu_to_le64(nrkey) }; uint32 cdw10 = (rrega & 0x7) | (iekey ? 1 << 3 : 0) | (cptpl << 30); - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_register, + struct cm_nvme_passthru_cmd cmd = { + .opcode = cm_nvme_cmd_resv_register, .nsid = nsid, .cdw10 = cdw10, .addr = (uint64)(uintptr_t) (payload), @@ -169,8 +169,8 @@ int32 cm_nvme_unregister(int32 fd, int64 crkey) __le64 payload[2] = { cpu_to_le64(crkey), cpu_to_le64(nrkey) }; uint32 cdw10 = (rrega & 0x7) | (iekey ? 1 << 3 : 0) | (cptpl << 30); - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_register, + struct cm_nvme_passthru_cmd cmd = { + .opcode = cm_nvme_cmd_resv_register, .nsid = nsid, .cdw10 = cdw10, .addr = (uint64)(uintptr_t) (payload), @@ -211,8 +211,8 @@ int32 cm_nvme_reserve(int32 fd, int64 nrkey) __le64 payload[2] = { cpu_to_le64(crkey), cpu_to_le64(nrkey) }; uint32 cdw10 = (rrega & 0x7) | (iekey ? 1 << 3 : 0) | (cptpl << 30); - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_register, + struct cm_nvme_passthru_cmd cmd = { + .opcode = cm_nvme_cmd_resv_register, .nsid = nsid, .cdw10 = cdw10, .addr = (uint64)(uintptr_t) (payload), @@ -251,8 +251,8 @@ int32 cm_nvme_release(int32 fd, int64 crkey) __le64 payload[1] = { cpu_to_le64(crkey) }; uint32 cdw10 = (rrela & 0x7) | (iekey ? 1 << 3 : 0) | (rtype << 8); - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_release, + struct cm_nvme_passthru_cmd cmd = { + .opcode = cm_nvme_cmd_resv_release, .nsid = nsid, .cdw10 = cdw10, .addr = (uint64)(uintptr_t) (payload), @@ -289,8 +289,8 @@ int32 cm_nvme_clear(int32 fd, int64 crkey) __le64 payload[1] = { cpu_to_le64(crkey) }; uint32 cdw10 = (rrela & 0x7) | (iekey ? 1 << 3 : 0) | (rtype << 8); - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_release, + struct cm_nvme_passthru_cmd cmd = { + .opcode = cm_nvme_cmd_resv_release, .nsid = nsid, .cdw10 = cdw10, .addr = (uint64)(uintptr_t) (payload), @@ -325,8 +325,8 @@ int32 cm_nvme_preempt(int32 fd, int64 crkey, int64 nrkey) __le64 payload[2] = { cpu_to_le64(crkey), cpu_to_le64(nrkey) }; uint32 cdw10 = (racqa & 0x7) | (iekey ? 1 << 3 : 0) | (rtype << 8); - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_acquire, + struct cm_nvme_passthru_cmd cmd = { + .opcode = cm_nvme_cmd_resv_acquire, .nsid = nsid, .cdw10 = cdw10, .addr = (uint64)(uintptr_t) (payload), @@ -351,8 +351,8 @@ int32 cm_nvme_preempt(int32 fd, int64 crkey, int64 nrkey) int32 cm_nvme_resv_report(int fd, uint32 nsid, uint32 numd, uint32 cdw11, void *data) { - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_report, + struct cm_nvme_passthru_cmd cmd = { + .opcode = cm_nvme_cmd_resv_report, .nsid = nsid, .cdw10 = numd, .cdw11 = cdw11, @@ -485,7 +485,7 @@ int32 cm_nvme_rres(int32 fd, int64 *crkey, uint32 *generation) int32 cm_nvme_read(int32 fd, uint64 block_addr, uint16 block_count, char *buff, int32 buff_len) { int32 status; - uint8 opcode = nvme_cmd_read; + uint8 opcode = cm_nvme_cmd_read; uint8 flags = 0; uint64 slba = block_addr; uint16 nblocks = block_count - 1; @@ -514,7 +514,7 @@ int32 cm_nvme_read(int32 fd, uint64 block_addr, uint16 block_count, char *buff, int32 cm_nvme_write(int32 fd, uint64 block_addr, uint16 block_count, char *buff, int32 buff_len) { int32 status; - uint8 opcode = nvme_cmd_write; + uint8 opcode = cm_nvme_cmd_write; uint8 flags = 0; uint64 slba = block_addr; uint16 nblocks = block_count - 1; @@ -543,7 +543,7 @@ int32 cm_nvme_write(int32 fd, uint64 block_addr, uint16 block_count, char *buff, int32 cm_nvme_caw(int32 fd, uint64 block_addr, uint16 block_count, char *buff, int32 buff_len) { int32 status; - uint8 opcode = nvme_cmd_compare; + uint8 opcode = cm_nvme_cmd_compare; uint8 flags = 0; uint64 slba = block_addr; uint16 nblocks = (block_count / 2) - 1; @@ -569,7 +569,7 @@ int32 cm_nvme_caw(int32 fd, uint64 block_addr, uint16 block_count, char *buff, i return CM_ERROR; } - opcode = nvme_cmd_write; + opcode = cm_nvme_cmd_write; data = buff + (buff_len / 2); status = cm_nvme_io(fd, opcode, flags, slba, nblocks, control, dsmgmt, reftag, apptag, appmask, data, metadata); if (status != CM_NVME_SC_SUCCESS) { @@ -599,11 +599,11 @@ int32 cm_nvme_inql(int32 fd, inquiry_data_t *inquiry_data) CM_RETURN_IFERR(cm_nvme_get_nsid(fd, (int32*)(&nsid))); securec_check_ret(memset_sp(&ctrl, sizeof(struct nvme_id_ctrl), 0, sizeof(struct nvme_id_ctrl))); - struct nvme_admin_cmd cmd = { - .opcode = nvme_admin_identify, + struct cm_nvme_admin_cmd cmd = { + .opcode = cm_nvme_admin_identify, .nsid = nsid, .addr = (uint64)(uintptr_t) &ctrl, - .data_len = NVME_IDENTIFY_DATA_SIZE, + .data_len = CM_NVME_IDENTIFY_DATA_SIZE, .cdw10 = cdw10, .cdw11 = cdw11, }; diff --git a/src/cm_utils/protocol/cm_nvme.h b/src/cm_utils/protocol/cm_nvme.h index 23e76b7..97a6a7a 100644 --- a/src/cm_utils/protocol/cm_nvme.h +++ b/src/cm_utils/protocol/cm_nvme.h @@ -39,23 +39,10 @@ #endif #endif -static inline __le16 cpu_to_le16(uint16 x) -{ - return (FORCE_CONVERT __le16)htole16(x); -} -static inline __le32 cpu_to_le32(uint32 x) -{ - return (FORCE_CONVERT __le32)htole32(x); -} static inline __le64 cpu_to_le64(uint64 x) { return (FORCE_CONVERT __le64)htole64(x); } - -static inline uint16 le16_to_cpu(__le16 x) -{ - return le16toh((FORCE_CONVERT __u16)x); -} static inline uint32 le32_to_cpu(__le32 x) { return le32toh((FORCE_CONVERT __u32)x); @@ -203,7 +190,7 @@ enum { CM_NVME_SC_DNR = 0x4000, }; -struct nvme_user_io { +struct cm_nvme_user_io { uint8 opcode; uint8 flags; uint16 control; @@ -218,7 +205,7 @@ struct nvme_user_io { uint16 appmask; }; -struct nvme_passthru_cmd { +struct cm_nvme_passthru_cmd { uint8 opcode; uint8 flags; uint16 rsvd1; @@ -276,50 +263,50 @@ struct nvme_reservation_status_ext { /* I/O commands */ enum nvme_opcode { - nvme_cmd_flush = 0x00, - nvme_cmd_write = 0x01, - nvme_cmd_read = 0x02, - nvme_cmd_write_uncor = 0x04, - nvme_cmd_compare = 0x05, - nvme_cmd_write_zeroes = 0x08, - nvme_cmd_dsm = 0x09, - nvme_cmd_verify = 0x0c, - nvme_cmd_resv_register = 0x0d, - nvme_cmd_resv_report = 0x0e, - nvme_cmd_resv_acquire = 0x11, - nvme_cmd_resv_release = 0x15, + cm_nvme_cmd_flush = 0x00, + cm_nvme_cmd_write = 0x01, + cm_nvme_cmd_read = 0x02, + cm_nvme_cmd_write_uncor = 0x04, + cm_nvme_cmd_compare = 0x05, + cm_nvme_cmd_write_zeroes = 0x08, + cm_nvme_cmd_dsm = 0x09, + cm_nvme_cmd_verify = 0x0c, + cm_nvme_cmd_resv_register = 0x0d, + cm_nvme_cmd_resv_report = 0x0e, + cm_nvme_cmd_resv_acquire = 0x11, + cm_nvme_cmd_resv_release = 0x15, }; /* Admin commands */ -enum nvme_admin_opcode { - nvme_admin_delete_sq = 0x00, - nvme_admin_create_sq = 0x01, - nvme_admin_get_log_page = 0x02, - nvme_admin_delete_cq = 0x04, - nvme_admin_create_cq = 0x05, - nvme_admin_identify = 0x06, - nvme_admin_abort_cmd = 0x08, - nvme_admin_set_features = 0x09, - nvme_admin_get_features = 0x0a, - nvme_admin_async_event = 0x0c, - nvme_admin_ns_mgmt = 0x0d, - nvme_admin_activate_fw = 0x10, - nvme_admin_download_fw = 0x11, - nvme_admin_dev_self_test = 0x14, - nvme_admin_ns_attach = 0x15, - nvme_admin_keep_alive = 0x18, - nvme_admin_directive_send = 0x19, - nvme_admin_directive_recv = 0x1a, - nvme_admin_virtual_mgmt = 0x1c, - nvme_admin_nvme_mi_send = 0x1d, - nvme_admin_nvme_mi_recv = 0x1e, - nvme_admin_dbbuf = 0x7C, - nvme_admin_format_nvm = 0x80, - nvme_admin_security_send = 0x81, - nvme_admin_compare = 0x81, - nvme_admin_security_recv = 0x82, - nvme_admin_sanitize_nvm = 0x84, - nvme_admin_get_lba_status = 0x86, +enum cm_nvme_admin_opcode { + cm_nvme_admin_delete_sq = 0x00, + cm_nvme_admin_create_sq = 0x01, + cm_nvme_admin_get_log_page = 0x02, + cm_nvme_admin_delete_cq = 0x04, + cm_nvme_admin_create_cq = 0x05, + cm_nvme_admin_identify = 0x06, + cm_nvme_admin_abort_cmd = 0x08, + cm_nvme_admin_set_features = 0x09, + cm_nvme_admin_get_features = 0x0a, + cm_nvme_admin_async_event = 0x0c, + cm_nvme_admin_ns_mgmt = 0x0d, + cm_nvme_admin_activate_fw = 0x10, + cm_nvme_admin_download_fw = 0x11, + cm_nvme_admin_dev_self_test = 0x14, + cm_nvme_admin_ns_attach = 0x15, + cm_nvme_admin_keep_alive = 0x18, + cm_nvme_admin_directive_send = 0x19, + cm_nvme_admin_directive_recv = 0x1a, + cm_nvme_admin_virtual_mgmt = 0x1c, + cm_nvme_admin_nvme_mi_send = 0x1d, + cm_nvme_admin_nvme_mi_recv = 0x1e, + cm_nvme_admin_dbbuf = 0x7C, + cm_nvme_admin_format_nvm = 0x80, + cm_nvme_admin_security_send = 0x81, + cm_nvme_admin_compare = 0x81, + cm_nvme_admin_security_recv = 0x82, + cm_nvme_admin_sanitize_nvm = 0x84, + cm_nvme_admin_get_lba_status = 0x86, }; struct nvme_lbaf { @@ -505,19 +492,19 @@ enum { CM_NVME_VENDOR_GOOGLE = 0x8649, }; -#define nvme_admin_cmd nvme_passthru_cmd +#define cm_nvme_admin_cmd cm_nvme_passthru_cmd #define CM_NVME_TIMEOUT 60 // secs -#define NVME_IDENTIFY_DATA_SIZE 4096 - -#define NVME_IOCTL_ID _IO('N', 0x40) -#define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd) -#define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io) -#define NVME_IOCTL_IO_CMD _IOWR('N', 0x43, struct nvme_passthru_cmd) -#define NVME_IOCTL_RESET _IO('N', 0x44) -#define NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45) -#define NVME_IOCTL_RESCAN _IO('N', 0x46) +#define CM_NVME_IDENTIFY_DATA_SIZE 4096 + +#define CM_NVME_IOCTL_ID _IO('N', 0x40) +#define CM_NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct cm_nvme_admin_cmd) +#define CM_NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct cm_nvme_user_io) +#define CM_NVME_IOCTL_IO_CMD _IOWR('N', 0x43, struct cm_nvme_passthru_cmd) +#define CM_NVME_IOCTL_RESET _IO('N', 0x44) +#define CM_NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45) +#define CM_NVME_IOCTL_RESCAN _IO('N', 0x46) int32 cm_nvme_register(int32 fd, int64 nrkey); int32 cm_nvme_unregister(int32 fd, int64 crkey); diff --git a/src/ddes_perctrl/service/ddes_perctrl_server.c b/src/ddes_perctrl/service/ddes_perctrl_server.c index a5d44d4..29edac8 100644 --- a/src/ddes_perctrl/service/ddes_perctrl_server.c +++ b/src/ddes_perctrl/service/ddes_perctrl_server.c @@ -721,7 +721,7 @@ static int32 get_io_protocol(char *iof_dev) return io_protocol; } - nsid = ioctl(fd, NVME_IOCTL_ID); + nsid = ioctl(fd, CM_NVME_IOCTL_ID); if (nsid == -1) { LOG_DEBUG_INF("ioctl get nsid error : %s\n", strerror(errno)); io_protocol = PERCTRL_IO_PROTOCOL_SCSI3; -- Gitee