nvme-cli: add endianess annotations
Christoph Hellwig
maintainerThe intent of this series is to provide static type checking for the little endian NVMe data structures using the sparse tool, similar to the kernel.
To make my life easier I first converted nvme-cli to use a copy of the kernel nvme.h header that defines the NVMe data structures. The next set of patches fixes various issues found by sparse as-is, followed by adding support for checking the __le{16,32,64} annotations and using the kernel cpu_to_le*/le*_to_cpu helpers, as well as fixing up various missing endianess conversion uncovered by sparse.
To use sparse make sure both sparse and the cgcc wrapper are installed and build nvme-cli using:
make CC=cgcc
At least with my version of sparse there are a few warnings left that aren't really nvme-clis faults during the build, and sparse will finally crash after compiling nvme.c because it misparses the command line and tries to interpret argconfig.o as a source file. I'll plan to look into that on the sparse side and hope to be able to provide a fix for that issue to the sparse maintainers.
Christoph Hellwig
maintainerPATCH 1/18 import linux/nvme.h
We'll want to use this for structures as much as possible in the future to keep a single header file for defintions from the NVMe specification.
--- linux/nvme.h | 965 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 965 insertions(+) create mode 100644 linux/nvme.h
linux/nvme.h new file +965 -0
@@ -0,0 +1,965 @@ +/* +* Definitions for the NVM Express interface +* Copyright (c) 2011-2014, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*/ + +#ifndef _LINUX_NVME_H +#define _LINUX_NVME_H + +#include <linux/types.h> +#include <linux/uuid.h> + +/* NQN names in commands fields specified one size */ +#define NVMF_NQN_FIELD_LEN 256 + +/* However the max length of a qualified name is another size */ +#define NVMF_NQN_SIZE 223 + +#define NVMF_TRSVCID_SIZE 32 +#define NVMF_TRADDR_SIZE 256 +#define NVMF_TSAS_SIZE 256 + +#define NVME_DISC_SUBSYS_NAME "nqn.2014-08.org.nvmexpress.discovery" + +#define NVME_RDMA_IP_PORT 4420 + +enum nvme_subsys_type { +NVME_NQN_DISC =1 ,/* Discovery type target subsystem */ +NVME_NQN_NVME =2 ,/* NVME type target subsystem */ +}; + +/* Address Family codes for Discovery Log Page entry ADRFAM field */ +enum { +NVMF_ADDR_FAMILY_PCI =0 ,/* PCIe */ +NVMF_ADDR_FAMILY_IP4 =1 ,/* IP4 */ +NVMF_ADDR_FAMILY_IP6 =2 ,/* IP6 */ +NVMF_ADDR_FAMILY_IB =3 ,/* InfiniBand */ +NVMF_ADDR_FAMILY_FC =4 ,/* Fibre Channel */ +}; + +/* Transport Type codes for Discovery Log Page entry TRTYPE field */ +enum { +NVMF_TRTYPE_RDMA =1 ,/* RDMA */ +NVMF_TRTYPE_FC =2 ,/* Fibre Channel */ +NVMF_TRTYPE_LOOP =254 ,/* Reserved for host usage */ +NVMF_TRTYPE_MAX , +}; + +/* Transport Requirements codes for Discovery Log Page entry TREQ field */ +enum { +NVMF_TREQ_NOT_SPECIFIED =0 ,/* Not specified */ +NVMF_TREQ_REQUIRED =1 ,/* Required */ +NVMF_TREQ_NOT_REQUIRED =2 ,/* Not Required */ +}; + +/* RDMA QP Service Type codes for Discovery Log Page entry TSAS +* RDMA_QPTYPE field +*/ +enum { +NVMF_RDMA_QPTYPE_CONNECTED =0 ,/* Reliable Connected */ +NVMF_RDMA_QPTYPE_DATAGRAM =1 ,/* Reliable Datagram */ +}; + +/* RDMA QP Service Type codes for Discovery Log Page entry TSAS +* RDMA_QPTYPE field +*/ +enum { +NVMF_RDMA_PRTYPE_NOT_SPECIFIED =0 ,/* No Provider Specified */ +NVMF_RDMA_PRTYPE_IB =1 ,/* InfiniBand */ +NVMF_RDMA_PRTYPE_ROCE =2 ,/* InfiniBand RoCE */ +NVMF_RDMA_PRTYPE_ROCEV2 =3 ,/* InfiniBand RoCEV2 */ +NVMF_RDMA_PRTYPE_IWARP =4 ,/* IWARP */ +}; + +/* RDMA Connection Management Service Type codes for Discovery Log Page +* entry TSAS RDMA_CMS field +*/ +enum { +NVMF_RDMA_CMS_RDMA_CM =0 ,/* Sockets based enpoint addressing */ +}; + +#define NVMF_AQ_DEPTH 32 + +enum { +NVME_REG_CAP =0x0000 ,/* Controller Capabilities */ +NVME_REG_VS =0x0008 ,/* Version */ +NVME_REG_INTMS =0x000c ,/* Interrupt Mask Set */ +NVME_REG_INTMC =0x0010 ,/* Interrupt Mask Clear */ +NVME_REG_CC =0x0014 ,/* Controller Configuration */ +NVME_REG_CSTS =0x001c ,/* Controller Status */ +NVME_REG_NSSR =0x0020 ,/* NVM Subsystem Reset */ +NVME_REG_AQA =0x0024 ,/* Admin Queue Attributes */ +NVME_REG_ASQ =0x0028 ,/* Admin SQ Base Address */ +NVME_REG_ACQ =0x0030 ,/* Admin CQ Base Address */ +NVME_REG_CMBLOC =0x0038 ,/* Controller Memory Buffer Location */ +NVME_REG_CMBSZ =0x003c ,/* Controller Memory Buffer Size */ +}; + +#define NVME_CAP_MQES (cap) ((cap) & 0xffff) +#define NVME_CAP_TIMEOUT (cap) (((cap) >> 24) & 0xff) +#define NVME_CAP_STRIDE (cap) (((cap) >> 32) & 0xf) +#define NVME_CAP_NSSRC (cap) (((cap) >> 36) & 0x1) +#define NVME_CAP_MPSMIN (cap) (((cap) >> 48) & 0xf) +#define NVME_CAP_MPSMAX (cap) (((cap) >> 52) & 0xf) + +#define NVME_CMB_BIR (cmbloc) ((cmbloc) & 0x7) +#define NVME_CMB_OFST (cmbloc) (((cmbloc) >> 12) & 0xfffff) +#define NVME_CMB_SZ (cmbsz) (((cmbsz) >> 12) & 0xfffff) +#define NVME_CMB_SZU (cmbsz) (((cmbsz) >> 8) & 0xf) + +#define NVME_CMB_WDS (cmbsz) ((cmbsz) & 0x10) +#define NVME_CMB_RDS (cmbsz) ((cmbsz) & 0x8) +#define NVME_CMB_LISTS (cmbsz) ((cmbsz) & 0x4) +#define NVME_CMB_CQS (cmbsz) ((cmbsz) & 0x2) +#define NVME_CMB_SQS (cmbsz) ((cmbsz) & 0x1) + +/* +* Submission and Completion Queue Entry Sizes for the NVM command set. +* (In bytes and specified as a power of two (2^n)). +*/ +#define NVME_NVM_IOSQES 6 +#define NVME_NVM_IOCQES 4 + +enum { +NVME_CC_ENABLE =1 <<0 , +NVME_CC_CSS_NVM =0 <<4 , +NVME_CC_MPS_SHIFT =7 , +NVME_CC_ARB_RR =0 <<11 , +NVME_CC_ARB_WRRU =1 <<11 , +NVME_CC_ARB_VS =7 <<11 , +NVME_CC_SHN_NONE =0 <<14 , +NVME_CC_SHN_NORMAL =1 <<14 , +NVME_CC_SHN_ABRUPT =2 <<14 , +NVME_CC_SHN_MASK =3 <<14 , +NVME_CC_IOSQES =NVME_NVM_IOSQES <<16 , +NVME_CC_IOCQES =NVME_NVM_IOCQES <<20 , +NVME_CSTS_RDY =1 <<0 , +NVME_CSTS_CFS =1 <<1 , +NVME_CSTS_NSSRO =1 <<4 , +NVME_CSTS_SHST_NORMAL =0 <<2 , +NVME_CSTS_SHST_OCCUR =1 <<2 , +NVME_CSTS_SHST_CMPLT =2 <<2 , +NVME_CSTS_SHST_MASK =3 <<2 , +}; + +struct nvme_id_power_state { +__le16 max_power;/* centiwatts */ +__u8 rsvd2; +__u8 flags; +__le32 entry_lat;/* microseconds */ +__le32 exit_lat;/* microseconds */ +__u8 read_tput; +__u8 read_lat; +__u8 write_tput; +__u8 write_lat; +__le16 idle_power; +__u8 idle_scale; +__u8 rsvd19; +__le16 active_power; +__u8 active_work_scale; +__u8 rsvd23[9 ]; +}; + +enum { +NVME_PS_FLAGS_MAX_POWER_SCALE =1 <<0 , +NVME_PS_FLAGS_NON_OP_STATE =1 <<1 , +}; + +struct nvme_id_ctrl { +__le16 vid; +__le16 ssvid; +char sn[20 ]; +char mn[40 ]; +char fr[8 ]; +__u8 rab; +__u8 ieee[3 ]; +__u8 mic; +__u8 mdts; +__le16 cntlid; +__le32 ver; +__le32 rtd3r; +__le32 rtd3e; +__le32 oaes; +__le32 ctratt; +__u8 rsvd100[156 ]; +__le16 oacs; +__u8 acl; +__u8 aerl; +__u8 frmw; +__u8 lpa; +__u8 elpe; +__u8 npss; +__u8 avscc; +__u8 apsta; +__le16 wctemp; +__le16 cctemp; +__u8 rsvd270[50 ]; +__le16 kas; +__u8 rsvd322[190 ]; +__u8 sqes; +__u8 cqes; +__le16 maxcmd; +__le32 nn; +__le16 oncs; +__le16 fuses; +__u8 fna; +__u8 vwc; +__le16 awun; +__le16 awupf; +__u8 nvscc; +__u8 rsvd531; +__le16 acwu; +__u8 rsvd534[2 ]; +__le32 sgls; +__u8 rsvd540[228 ]; +char subnqn[256 ]; +__u8 rsvd1024[768 ]; +__le32 ioccsz; +__le32 iorcsz; +__le16 icdoff; +__u8 ctrattr; +__u8 msdbd; +__u8 rsvd1804[244 ]; +struct nvme_id_power_state psd[32 ]; +__u8 vs[1024 ]; +}; + +enum { +NVME_CTRL_ONCS_COMPARE =1 <<0 , +NVME_CTRL_ONCS_WRITE_UNCORRECTABLE =1 <<1 , +NVME_CTRL_ONCS_DSM =1 <<2 , +NVME_CTRL_VWC_PRESENT =1 <<0 , +}; + +struct nvme_lbaf { +__le16 ms; +__u8 ds; +__u8 rp; +}; + +struct nvme_id_ns { +__le64 nsze; +__le64 ncap; +__le64 nuse; +__u8 nsfeat; +__u8 nlbaf; +__u8 flbas; +__u8 mc; +__u8 dpc; +__u8 dps; +__u8 nmic; +__u8 rescap; +__u8 fpi; +__u8 rsvd33; +__le16 nawun; +__le16 nawupf; +__le16 nacwu; +__le16 nabsn; +__le16 nabo; +__le16 nabspf; +__u16 rsvd46; +__le64 nvmcap[2 ]; +__u8 rsvd64[40 ]; +__u8 nguid[16 ]; +__u8 eui64[8 ]; +struct nvme_lbaf lbaf[16 ]; +__u8 rsvd192[192 ]; +__u8 vs[3712 ]; +}; + +enum { +NVME_NS_FEAT_THIN =1 <<0 , +NVME_NS_FLBAS_LBA_MASK =0xf , +NVME_NS_FLBAS_META_EXT =0x10 , +NVME_LBAF_RP_BEST =0 , +NVME_LBAF_RP_BETTER =1 , +NVME_LBAF_RP_GOOD =2 , +NVME_LBAF_RP_DEGRADED =3 , +NVME_NS_DPC_PI_LAST =1 <<4 , +NVME_NS_DPC_PI_FIRST =1 <<3 , +NVME_NS_DPC_PI_TYPE3 =1 <<2 , +NVME_NS_DPC_PI_TYPE2 =1 <<1 , +NVME_NS_DPC_PI_TYPE1 =1 <<0 , +NVME_NS_DPS_PI_FIRST =1 <<3 , +NVME_NS_DPS_PI_MASK =0x7 , +NVME_NS_DPS_PI_TYPE1 =1 , +NVME_NS_DPS_PI_TYPE2 =2 , +NVME_NS_DPS_PI_TYPE3 =3 , +}; + +struct nvme_smart_log { +__u8 critical_warning; +__u8 temperature[2 ]; +__u8 avail_spare; +__u8 spare_thresh; +__u8 percent_used; +__u8 rsvd6[26 ]; +__u8 data_units_read[16 ]; +__u8 data_units_written[16 ]; +__u8 host_reads[16 ]; +__u8 host_writes[16 ]; +__u8 ctrl_busy_time[16 ]; +__u8 power_cycles[16 ]; +__u8 power_on_hours[16 ]; +__u8 unsafe_shutdowns[16 ]; +__u8 media_errors[16 ]; +__u8 num_err_log_entries[16 ]; +__le32 warning_temp_time; +__le32 critical_comp_time; +__le16 temp_sensor[8 ]; +__u8 rsvd216[296 ]; +}; + +enum { +NVME_SMART_CRIT_SPARE =1 <<0 , +NVME_SMART_CRIT_TEMPERATURE =1 <<1 , +NVME_SMART_CRIT_RELIABILITY =1 <<2 , +NVME_SMART_CRIT_MEDIA =1 <<3 , +NVME_SMART_CRIT_VOLATILE_MEMORY =1 <<4 , +}; + +enum { +NVME_AER_NOTICE_NS_CHANGED =0x0002 , +}; + +struct nvme_lba_range_type { +__u8 type; +__u8 attributes; +__u8 rsvd2[14 ]; +__u64 slba; +__u64 nlb; +__u8 guid[16 ]; +__u8 rsvd48[16 ]; +}; + +enum { +NVME_LBART_TYPE_FS =0x01 , +NVME_LBART_TYPE_RAID =0x02 , +NVME_LBART_TYPE_CACHE =0x03 , +NVME_LBART_TYPE_SWAP =0x04 , + +NVME_LBART_ATTRIB_TEMP =1 <<0 , +NVME_LBART_ATTRIB_HIDE =1 <<1 , +}; + +struct nvme_reservation_status { +__le32 gen; +__u8 rtype; +__u8 regctl[2 ]; +__u8 resv5[2 ]; +__u8 ptpls; +__u8 resv10[13 ]; +struct { +__le16 cntlid; +__u8 rcsts; +__u8 resv3[5 ]; +__le64 hostid; +__le64 rkey; + } regctl_ds[]; +}; + +enum nvme_async_event_type { +NVME_AER_TYPE_ERROR =0 , +NVME_AER_TYPE_SMART =1 , +NVME_AER_TYPE_NOTICE =2 , +}; + +/* 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_resv_register =0x0d , + nvme_cmd_resv_report =0x0e , + nvme_cmd_resv_acquire =0x11 , + nvme_cmd_resv_release =0x15 , +}; + +/* +* Descriptor subtype - lower 4 bits of nvme_(keyed_)sgl_desc identifier +* +* @NVME_SGL_FMT_ADDRESS: absolute address of the data block +* @NVME_SGL_FMT_OFFSET: relative offset of the in-capsule data block +* @NVME_SGL_FMT_INVALIDATE: RDMA transport specific remote invalidation +* request subtype +*/ +enum { +NVME_SGL_FMT_ADDRESS =0x00 , +NVME_SGL_FMT_OFFSET =0x01 , +NVME_SGL_FMT_INVALIDATE =0x0f , +}; + +/* +* Descriptor type - upper 4 bits of nvme_(keyed_)sgl_desc identifier +* +* For struct nvme_sgl_desc: +* @NVME_SGL_FMT_DATA_DESC: data block descriptor +* @NVME_SGL_FMT_SEG_DESC: sgl segment descriptor +* @NVME_SGL_FMT_LAST_SEG_DESC: last sgl segment descriptor +* +* For struct nvme_keyed_sgl_desc: +* @NVME_KEY_SGL_FMT_DATA_DESC: keyed data block descriptor +*/ +enum { +NVME_SGL_FMT_DATA_DESC =0x00 , +NVME_SGL_FMT_SEG_DESC =0x02 , +NVME_SGL_FMT_LAST_SEG_DESC =0x03 , +NVME_KEY_SGL_FMT_DATA_DESC =0x04 , +}; + +struct nvme_sgl_desc { +__le64 addr; +__le32 length; +__u8 rsvd[3 ]; +__u8 type; +}; + +struct nvme_keyed_sgl_desc { +__le64 addr; +__u8 length[3 ]; +__u8 key[4 ]; +__u8 type; +}; + +union nvme_data_ptr { +struct { +__le64 prp1; +__le64 prp2; + }; +struct nvme_sgl_desc sgl; +struct nvme_keyed_sgl_desc ksgl; +}; + +/* +* Lowest two bits of our flags field (FUSE field in the spec): +* +* @NVME_CMD_FUSE_FIRST: Fused Operation, first command +* @NVME_CMD_FUSE_SECOND: Fused Operation, second command +* +* Highest two bits in our flags field (PSDT field in the spec): +* +* @NVME_CMD_PSDT_SGL_METABUF: Use SGLS for this transfer, +* If used, MPTR contains addr of single physical buffer (byte aligned). +* @NVME_CMD_PSDT_SGL_METASEG: Use SGLS for this transfer, +* If used, MPTR contains an address of an SGL segment containing +* exactly 1 SGL descriptor (qword aligned). +*/ +enum { +NVME_CMD_FUSE_FIRST = (1 <<0 ), +NVME_CMD_FUSE_SECOND = (1 <<1 ), + +NVME_CMD_SGL_METABUF = (1 <<6 ), +NVME_CMD_SGL_METASEG = (1 <<7 ), +NVME_CMD_SGL_ALL =NVME_CMD_SGL_METABUF |NVME_CMD_SGL_METASEG , +}; + +struct nvme_common_command { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__le32 cdw2[2 ]; +__le64 metadata; +union nvme_data_ptr dptr; +__le32 cdw10[6 ]; +}; + +struct nvme_rw_command { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd2; +__le64 metadata; +union nvme_data_ptr dptr; +__le64 slba; +__le16 length; +__le16 control; +__le32 dsmgmt; +__le32 reftag; +__le16 apptag; +__le16 appmask; +}; + +enum { +NVME_RW_LR =1 <<15 , +NVME_RW_FUA =1 <<14 , +NVME_RW_DSM_FREQ_UNSPEC =0 , +NVME_RW_DSM_FREQ_TYPICAL =1 , +NVME_RW_DSM_FREQ_RARE =2 , +NVME_RW_DSM_FREQ_READS =3 , +NVME_RW_DSM_FREQ_WRITES =4 , +NVME_RW_DSM_FREQ_RW =5 , +NVME_RW_DSM_FREQ_ONCE =6 , +NVME_RW_DSM_FREQ_PREFETCH =7 , +NVME_RW_DSM_FREQ_TEMP =8 , +NVME_RW_DSM_LATENCY_NONE =0 <<4 , +NVME_RW_DSM_LATENCY_IDLE =1 <<4 , +NVME_RW_DSM_LATENCY_NORM =2 <<4 , +NVME_RW_DSM_LATENCY_LOW =3 <<4 , +NVME_RW_DSM_SEQ_REQ =1 <<6 , +NVME_RW_DSM_COMPRESSED =1 <<7 , +NVME_RW_PRINFO_PRCHK_REF =1 <<10 , +NVME_RW_PRINFO_PRCHK_APP =1 <<11 , +NVME_RW_PRINFO_PRCHK_GUARD =1 <<12 , +NVME_RW_PRINFO_PRACT =1 <<13 , +}; + +struct nvme_dsm_cmd { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd2[2 ]; +union nvme_data_ptr dptr; +__le32 nr; +__le32 attributes; +__u32 rsvd12[4 ]; +}; + +enum { +NVME_DSMGMT_IDR =1 <<0 , +NVME_DSMGMT_IDW =1 <<1 , +NVME_DSMGMT_AD =1 <<2 , +}; + +struct nvme_dsm_range { +__le32 cattr; +__le32 nlb; +__le64 slba; +}; + +/* 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_activate_fw =0x10 , + nvme_admin_download_fw =0x11 , + nvme_admin_keep_alive =0x18 , + nvme_admin_format_nvm =0x80 , + nvme_admin_security_send =0x81 , + nvme_admin_security_recv =0x82 , +}; + +enum { +NVME_QUEUE_PHYS_CONTIG = (1 <<0 ), +NVME_CQ_IRQ_ENABLED = (1 <<1 ), +NVME_SQ_PRIO_URGENT = (0 <<1 ), +NVME_SQ_PRIO_HIGH = (1 <<1 ), +NVME_SQ_PRIO_MEDIUM = (2 <<1 ), +NVME_SQ_PRIO_LOW = (3 <<1 ), +NVME_FEAT_ARBITRATION =0x01 , +NVME_FEAT_POWER_MGMT =0x02 , +NVME_FEAT_LBA_RANGE =0x03 , +NVME_FEAT_TEMP_THRESH =0x04 , +NVME_FEAT_ERR_RECOVERY =0x05 , +NVME_FEAT_VOLATILE_WC =0x06 , +NVME_FEAT_NUM_QUEUES =0x07 , +NVME_FEAT_IRQ_COALESCE =0x08 , +NVME_FEAT_IRQ_CONFIG =0x09 , +NVME_FEAT_WRITE_ATOMIC =0x0a , +NVME_FEAT_ASYNC_EVENT =0x0b , +NVME_FEAT_AUTO_PST =0x0c , +NVME_FEAT_KATO =0x0f , +NVME_FEAT_SW_PROGRESS =0x80 , +NVME_FEAT_HOST_ID =0x81 , +NVME_FEAT_RESV_MASK =0x82 , +NVME_FEAT_RESV_PERSIST =0x83 , +NVME_LOG_ERROR =0x01 , +NVME_LOG_SMART =0x02 , +NVME_LOG_FW_SLOT =0x03 , +NVME_LOG_DISC =0x70 , +NVME_LOG_RESERVATION =0x80 , +NVME_FWACT_REPL = (0 <<3 ), +NVME_FWACT_REPL_ACTV = (1 <<3 ), +NVME_FWACT_ACTV = (2 <<3 ), +}; + +struct nvme_identify { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd2[2 ]; +union nvme_data_ptr dptr; +__le32 cns; +__u32 rsvd11[5 ]; +}; + +struct nvme_features { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd2[2 ]; +union nvme_data_ptr dptr; +__le32 fid; +__le32 dword11; +__u32 rsvd12[4 ]; +}; + +struct nvme_create_cq { +__u8 opcode; +__u8 flags; +__u16 command_id; +__u32 rsvd1[5 ]; +__le64 prp1; +__u64 rsvd8; +__le16 cqid; +__le16 qsize; +__le16 cq_flags; +__le16 irq_vector; +__u32 rsvd12[4 ]; +}; + +struct nvme_create_sq { +__u8 opcode; +__u8 flags; +__u16 command_id; +__u32 rsvd1[5 ]; +__le64 prp1; +__u64 rsvd8; +__le16 sqid; +__le16 qsize; +__le16 sq_flags; +__le16 cqid; +__u32 rsvd12[4 ]; +}; + +struct nvme_delete_queue { +__u8 opcode; +__u8 flags; +__u16 command_id; +__u32 rsvd1[9 ]; +__le16 qid; +__u16 rsvd10; +__u32 rsvd11[5 ]; +}; + +struct nvme_abort_cmd { +__u8 opcode; +__u8 flags; +__u16 command_id; +__u32 rsvd1[9 ]; +__le16 sqid; +__u16 cid; +__u32 rsvd11[5 ]; +}; + +struct nvme_download_firmware { +__u8 opcode; +__u8 flags; +__u16 command_id; +__u32 rsvd1[5 ]; +union nvme_data_ptr dptr; +__le32 numd; +__le32 offset; +__u32 rsvd12[4 ]; +}; + +struct nvme_format_cmd { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd2[4 ]; +__le32 cdw10; +__u32 rsvd11[5 ]; +}; + +struct nvme_get_log_page_command { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd2[2 ]; +union nvme_data_ptr dptr; +__u8 lid; +__u8 rsvd10; +__le16 numdl; +__le16 numdu; +__u16 rsvd11; +__le32 lpol; +__le32 lpou; +__u32 rsvd14[2 ]; +}; + +/* +* Fabrics subcommands. +*/ +enum nvmf_fabrics_opcode { + nvme_fabrics_command =0x7f , +}; + +enum nvmf_capsule_command { + nvme_fabrics_type_property_set =0x00 , + nvme_fabrics_type_connect =0x01 , + nvme_fabrics_type_property_get =0x04 , +}; + +struct nvmf_common_command { +__u8 opcode; +__u8 resv1; +__u16 command_id; +__u8 fctype; +__u8 resv2[35 ]; +__u8 ts[24 ]; +}; + +/* +* The legal cntlid range a NVMe Target will provide. +* Note that cntlid of value 0 is considered illegal in the fabrics world. +* Devices based on earlier specs did not have the subsystem concept; +* therefore, those devices had their cntlid value set to 0 as a result. +*/ +#define NVME_CNTLID_MIN 1 +#define NVME_CNTLID_MAX 0xffef +#define NVME_CNTLID_DYNAMIC 0xffff + +#define MAX_DISC_LOGS 255 + +/* Discovery log page entry */ +struct nvmf_disc_rsp_page_entry { +__u8 trtype; +__u8 adrfam; +__u8 nqntype; +__u8 treq; +__le16 portid; +__le16 cntlid; +__le16 asqsz; +__u8 resv8[22 ]; +char trsvcid[NVMF_TRSVCID_SIZE ]; +__u8 resv64[192 ]; +char subnqn[NVMF_NQN_FIELD_LEN ]; +char traddr[NVMF_TRADDR_SIZE ]; +union tsas { +char common[NVMF_TSAS_SIZE ]; +struct rdma { +__u8 qptype; +__u8 prtype; +__u8 cms; +__u8 resv3[5 ]; +__u16 pkey; +__u8 resv10[246 ]; + } rdma; + } tsas; +}; + +/* Discovery log page header */ +struct nvmf_disc_rsp_page_hdr { +__le64 genctr; +__le64 numrec; +__le16 recfmt; +__u8 resv14[1006 ]; +struct nvmf_disc_rsp_page_entry entries[0 ]; +}; + +struct nvmf_connect_command { +__u8 opcode; +__u8 resv1; +__u16 command_id; +__u8 fctype; +__u8 resv2[19 ]; +union nvme_data_ptr dptr; +__le16 recfmt; +__le16 qid; +__le16 sqsize; +__u8 cattr; +__u8 resv3; +__le32 kato; +__u8 resv4[12 ]; +}; + +struct nvmf_connect_data { +uuid_be hostid; +__le16 cntlid; +char resv4[238 ]; +char subsysnqn[NVMF_NQN_FIELD_LEN ]; +char hostnqn[NVMF_NQN_FIELD_LEN ]; +char resv5[256 ]; +}; + +struct nvmf_property_set_command { +__u8 opcode; +__u8 resv1; +__u16 command_id; +__u8 fctype; +__u8 resv2[35 ]; +__u8 attrib; +__u8 resv3[3 ]; +__le32 offset; +__le64 value; +__u8 resv4[8 ]; +}; + +struct nvmf_property_get_command { +__u8 opcode; +__u8 resv1; +__u16 command_id; +__u8 fctype; +__u8 resv2[35 ]; +__u8 attrib; +__u8 resv3[3 ]; +__le32 offset; +__u8 resv4[16 ]; +}; + +struct nvme_command { +union { +struct nvme_common_command common; +struct nvme_rw_command rw; +struct nvme_identify identify; +struct nvme_features features; +struct nvme_create_cq create_cq; +struct nvme_create_sq create_sq; +struct nvme_delete_queue delete_queue; +struct nvme_download_firmware dlfw; +struct nvme_format_cmd format; +struct nvme_dsm_cmd dsm; +struct nvme_abort_cmd abort; +struct nvme_get_log_page_command get_log_page; +struct nvmf_common_command fabrics; +struct nvmf_connect_command connect; +struct nvmf_property_set_command prop_set; +struct nvmf_property_get_command prop_get; + }; +}; + +static inline bool nvme_is_write (struct nvme_command *cmd) +{ +/* +* What a mess... +* +* Why can't we simply have a Fabrics In and Fabrics out command? +*/ +if (unlikely (cmd->common.opcode == nvme_fabrics_command)) +return cmd->fabrics.opcode &1 ; +return cmd->common.opcode &1 ; +} + +enum { +/* +* Generic Command Status: +*/ +NVME_SC_SUCCESS =0x0 , +NVME_SC_INVALID_OPCODE =0x1 , +NVME_SC_INVALID_FIELD =0x2 , +NVME_SC_CMDID_CONFLICT =0x3 , +NVME_SC_DATA_XFER_ERROR =0x4 , +NVME_SC_POWER_LOSS =0x5 , +NVME_SC_INTERNAL =0x6 , +NVME_SC_ABORT_REQ =0x7 , +NVME_SC_ABORT_QUEUE =0x8 , +NVME_SC_FUSED_FAIL =0x9 , +NVME_SC_FUSED_MISSING =0xa , +NVME_SC_INVALID_NS =0xb , +NVME_SC_CMD_SEQ_ERROR =0xc , +NVME_SC_SGL_INVALID_LAST =0xd , +NVME_SC_SGL_INVALID_COUNT =0xe , +NVME_SC_SGL_INVALID_DATA =0xf , +NVME_SC_SGL_INVALID_METADATA =0x10 , +NVME_SC_SGL_INVALID_TYPE =0x11 , + +NVME_SC_SGL_INVALID_OFFSET =0x16 , +NVME_SC_SGL_INVALID_SUBTYPE =0x17 , + +NVME_SC_LBA_RANGE =0x80 , +NVME_SC_CAP_EXCEEDED =0x81 , +NVME_SC_NS_NOT_READY =0x82 , +NVME_SC_RESERVATION_CONFLICT =0x83 , + +/* +* Command Specific Status: +*/ +NVME_SC_CQ_INVALID =0x100 , +NVME_SC_QID_INVALID =0x101 , +NVME_SC_QUEUE_SIZE =0x102 , +NVME_SC_ABORT_LIMIT =0x103 , +NVME_SC_ABORT_MISSING =0x104 , +NVME_SC_ASYNC_LIMIT =0x105 , +NVME_SC_FIRMWARE_SLOT =0x106 , +NVME_SC_FIRMWARE_IMAGE =0x107 , +NVME_SC_INVALID_VECTOR =0x108 , +NVME_SC_INVALID_LOG_PAGE =0x109 , +NVME_SC_INVALID_FORMAT =0x10a , +NVME_SC_FIRMWARE_NEEDS_RESET =0x10b , +NVME_SC_INVALID_QUEUE =0x10c , +NVME_SC_FEATURE_NOT_SAVEABLE =0x10d , +NVME_SC_FEATURE_NOT_CHANGEABLE =0x10e , +NVME_SC_FEATURE_NOT_PER_NS =0x10f , +NVME_SC_FW_NEEDS_RESET_SUBSYS =0x110 , + +/* +* I/O Command Set Specific - NVM commands: +*/ +NVME_SC_BAD_ATTRIBUTES =0x180 , +NVME_SC_INVALID_PI =0x181 , +NVME_SC_READ_ONLY =0x182 , + +/* +* I/O Command Set Specific - Fabrics commands: +*/ +NVME_SC_CONNECT_FORMAT =0x180 , +NVME_SC_CONNECT_CTRL_BUSY =0x181 , +NVME_SC_CONNECT_INVALID_PARAM =0x182 , +NVME_SC_CONNECT_RESTART_DISC =0x183 , +NVME_SC_CONNECT_INVALID_HOST =0x184 , + +NVME_SC_DISCOVERY_RESTART =0x190 , +NVME_SC_AUTH_REQUIRED =0x191 , + +/* +* Media and Data Integrity Errors: +*/ +NVME_SC_WRITE_FAULT =0x280 , +NVME_SC_READ_ERROR =0x281 , +NVME_SC_GUARD_CHECK =0x282 , +NVME_SC_APPTAG_CHECK =0x283 , +NVME_SC_REFTAG_CHECK =0x284 , +NVME_SC_COMPARE_FAILED =0x285 , +NVME_SC_ACCESS_DENIED =0x286 , + +NVME_SC_DNR =0x4000 , +}; + +struct nvme_completion { +/* +* Used by Admin and Fabrics commands to return data: +*/ +union { +__le16 result16; +__le32 result; +__le64 result64; + }; +__le16 sq_head;/* how much of this queue may be reclaimed */ +__le16 sq_id;/* submission queue that generated this entry */ +__u16 command_id;/* of the command which completed */ +__le16 status;/* did the command fail, and if so, why? */ +}; + +#define NVME_VS (major, minor) (((major) << 16) | ((minor) << 8)) + +#endif /* _LINUX_NVME_H */
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 2/18 fix linux/nvme.h for use with nvme-cli
In reply to Christoph HellwigRename a few fields or constants to be closer to the standards and a few more.
--- linux/nvme.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-)
linux/nvme.h +27 -6
@@ -182,7 +182,7 @@ struct nvme_id_ctrl {char fr[8 ];__u8 rab;__u8 ieee[3 ]; -__u8 mic; +__u8 cmic;__u8 mdts;__le16 cntlid;__le32 ver;
@@ -202,7 +202,13 @@ struct nvme_id_ctrl {__u8 apsta;__le16 wctemp;__le16 cctemp; -__u8 rsvd270[50 ]; +__le16 mtfa; +__le32 hmpre; +__le32 hmmin; +__u8 tnvmcap[16 ]; +__u8 unvmcap[16 ]; +__le32 rpmbs; +__u8 rsvd316[4 ];__le16 kas;__u8 rsvd322[190 ];__u8 sqes;
@@ -267,7 +273,7 @@ struct nvme_id_ns {__le16 nabo;__le16 nabspf;__u16 rsvd46; -__le64 nvmcap[2 ]; +__u8 nvmcap[16 ];__u8 rsvd64[40 ];__u8 nguid[16 ];__u8 eui64[8 ];
@@ -556,8 +562,10 @@ enum nvme_admin_opcode { 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_ns_attach =0x15 , nvme_admin_keep_alive =0x18 , nvme_admin_format_nvm =0x80 , nvme_admin_security_send = 0x81,
@@ -583,6 +591,7 @@ enum {NVME_FEAT_WRITE_ATOMIC =0x0a ,NVME_FEAT_ASYNC_EVENT =0x0b ,NVME_FEAT_AUTO_PST =0x0c , +NVME_FEAT_HOST_MEM_BUF =0x0d ,NVME_FEAT_KATO =0x0f ,NVME_FEAT_SW_PROGRESS =0x80 , NVME_FEAT_HOST_ID = 0x81,
@@ -745,7 +754,7 @@ struct nvmf_common_command {struct nvmf_disc_rsp_page_entry {__u8 trtype;__u8 adrfam; -__u8 nqntype; +__u8 subtype;__u8 treq;__le16 portid;__le16 cntlid;
@@ -905,12 +914,23 @@ enum {NVME_SC_INVALID_VECTOR =0x108 ,NVME_SC_INVALID_LOG_PAGE =0x109 ,NVME_SC_INVALID_FORMAT =0x10a , -NVME_SC_FIRMWARE_NEEDS_RESET =0x10b , +NVME_SC_FW_NEEDS_CONV_RESET =0x10b ,NVME_SC_INVALID_QUEUE =0x10c ,NVME_SC_FEATURE_NOT_SAVEABLE =0x10d ,NVME_SC_FEATURE_NOT_CHANGEABLE =0x10e ,NVME_SC_FEATURE_NOT_PER_NS =0x10f , -NVME_SC_FW_NEEDS_RESET_SUBSYS =0x110 , +NVME_SC_FW_NEEDS_SUBSYS_RESET =0x110 , +NVME_SC_FW_NEEDS_RESET =0x111 , +NVME_SC_FW_NEEDS_MAX_TIME =0x112 , +NVME_SC_FW_ACIVATE_PROHIBITED =0x113 , +NVME_SC_OVERLAPPING_RANGE =0x114 , +NVME_SC_NS_INSUFFICENT_CAP =0x115 , +NVME_SC_NS_ID_UNAVAILABLE =0x116 , +NVME_SC_NS_ALREADY_ATTACHED =0x118 , +NVME_SC_NS_IS_PRIVATE =0x119 , +NVME_SC_NS_NOT_ATTACHED =0x11a , +NVME_SC_THIN_PROV_NOT_SUPP =0x11b , +NVME_SC_CTRL_LIST_INVALID =0x11c ,/* * I/O Command Set Specific - NVM commands:
@@ -941,6 +961,7 @@ enum {NVME_SC_REFTAG_CHECK =0x284 ,NVME_SC_COMPARE_FAILED =0x285 ,NVME_SC_ACCESS_DENIED =0x286 , +NVME_SC_UNWRITTEN_BLOCK =0x287 , NVME_SC_DNR = 0x4000, };
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 3/18 use nvme.h from Linux
In reply to Christoph HellwigWe still need various defintions of our own, but this cuts down the number significantly.
--- nvme.h | 471 +---------------------------------------------------------------- 1 file changed, 3 insertions(+), 468 deletions(-)
nvme.h +3 -468
@@ -15,73 +15,11 @@ #ifndef _NVME_H #define _NVME_H -#include <linux/types.h> +#include <stdbool.h> #include "plugin.h" -/* NQN names in commands fields specified one size */ -#define NVMF_NQN_FIELD_LEN 256 - -/* However the max length of a qualified name is another size */ -#define NVMF_NQN_SIZE 223 -#define NVMF_TRSVCID_SIZE 32 -#define NVMF_TRADDR_SIZE 256 -#define NVMF_TSAS_SIZE 256 - -#define NVME_DISC_SUBSYS_NAME "nqn.2014-08.org.nvmexpress.discovery" - -enum nvme_subsys_type { - NVME_NQN_DISC = 1, /* Discovery type target subsystem */ - NVME_NQN_NVME = 2, /* NVME type target subsystem */ -}; - -/* Transport Type codes for Discovery Log Page entry TRTYPE field */ -enum { - NVMF_TRTYPE_RDMA = 1, /* RDMA */ - NVMF_TRTYPE_FC = 2, /* Fibre Channel */ - NVMF_TRTYPE_LOOP = 254, /* Reserved for host usage */ -}; - -/* Transport Requirements codes for Discovery Log Page entry TREQ field */ -enum { - NVMF_TREQ_NOT_SPECIFIED = 0, /* Not specified */ - NVMF_TREQ_REQUIRED = 1, /* Required */ - NVMF_TREQ_NOT_REQUIRED = 2, /* Not Required */ -}; - -/* RDMA QP Service Type codes for Discovery Log Page entry TSAS - * RDMA_QPTYPE field - */ -enum { - NVMF_RDMA_QPTYPE_CONNECTED = 0, /* Reliable Connected */ - NVMF_RDMA_QPTYPE_DATAGRAM = 1, /* Reliable Datagram */ -}; - -/* RDMA QP Service Type codes for Discovery Log Page entry TSAS - * RDMA_QPTYPE field - */ -enum { - NVMF_RDMA_PRTYPE_NOT_SPECIFIED = 0, /* No Provider Specified */ - NVMF_RDMA_PRTYPE_IB = 1, /* InfiniBand */ - NVMF_RDMA_PRTYPE_ROCE = 2, /* InfiniBand RoCE */ - NVMF_RDMA_PRTYPE_ROCEV2 = 3, /* InfiniBand RoCEV2 */ - NVMF_RDMA_PRTYPE_IWARP = 4, /* IWARP */ -}; - -/* RDMA Connection Management Service Type codes for Discovery Log Page - * entry TSAS RDMA_CMS field - */ -enum { - NVMF_RDMA_CMS_RDMA_CM = 0, /* Sockets based enpoint addressing */ -}; - -/* Address Family codes for Discovery Log Page entry ADRFAM field */ -enum { - NVMF_ADDR_FAMILY_PCI = 0, /* PCIe */ - NVMF_ADDR_FAMILY_IP4 = 1, /* IP4 */ - NVMF_ADDR_FAMILY_IP6 = 2, /* IP6 */ - NVMF_ADDR_FAMILY_IB = 3, /* InfiniBand */ - NVMF_ADDR_FAMILY_FC = 4, /* Fibre Channel */ -}; +#define unlikely(x) x +#include "linux/nvme.h" struct nvme_error_log_page { __u64 error_count;
@@ -102,94 +40,10 @@ struct nvme_firmware_log_page {__u8 resv2[448 ]; }; -struct nvme_id_power_state { -__le16 max_power;/* centiwatts */ -__u8 rsvd2; -__u8 flags; -__le32 entry_lat;/* microseconds */ -__le32 exit_lat;/* microseconds */ -__u8 read_tput; -__u8 read_lat; -__u8 write_tput; -__u8 write_lat; -__le16 idle_power; -__u8 idle_scale; -__u8 rsvd19; -__le16 active_power; -__u8 active_work_scale; -__u8 rsvd23[9 ]; -}; -/* idle and active power scales occupy the last 2 bits of the field */ #define POWER_SCALE (s) ((s) >> 6)enum { -NVME_PS_FLAGS_MAX_POWER_SCALE =1 <<0 , -NVME_PS_FLAGS_NON_OP_STATE =1 <<1 , -}; - -struct nvme_id_ctrl { -__le16 vid; -__le16 ssvid; -char sn[20 ]; -char mn[40 ]; -char fr[8 ]; -__u8 rab; -__u8 ieee[3 ]; -__u8 cmic; -__u8 mdts; -__le16 cntlid; -__le32 ver; -__le32 rtd3r; -__le32 rtd3e; -__le32 oaes; -__u8 rsvd96[160 ]; -__le16 oacs; -__u8 acl; -__u8 aerl; -__u8 frmw; -__u8 lpa; -__u8 elpe; -__u8 npss; -__u8 avscc; -__u8 apsta; -__le16 wctemp; -__le16 cctemp; -__le16 mtfa; -__le32 hmpre; -__le32 hmmin; -__u8 tnvmcap[16 ]; -__u8 unvmcap[16 ]; -__le32 rpmbs; -__u8 rsvd316[196 ]; -__u8 sqes; -__u8 cqes; -__u8 rsvd514[2 ]; -__le32 nn; -__le16 oncs; -__le16 fuses; -__u8 fna; -__u8 vwc; -__le16 awun; -__le16 awupf; -__u8 nvscc; -__u8 rsvd531; -__le16 acwu; -__u8 rsvd534[2 ]; -__le32 sgls; -__u8 rsvd540[1508 ]; -struct nvme_id_power_state psd[32 ]; -__u8 vs[1024 ]; -}; - -enum { -NVME_CTRL_ONCS_COMPARE =1 <<0 , -NVME_CTRL_ONCS_WRITE_UNCORRECTABLE =1 <<1 , -NVME_CTRL_ONCS_DSM =1 <<2 , -NVME_CTRL_VWC_PRESENT =1 <<0 , -}; - -enum {NVME_ID_CNS_NS =0x00 ,NVME_ID_CNS_CTRL =0x01 ,NVME_ID_CNS_NS_ACTIVE_LIST =0x02 ,
@@ -199,81 +53,6 @@ enum { NVME_ID_CNS_CTRL_LIST = 0x13, }; -struct nvme_lbaf { -__le16 ms; -__u8 ds; -__u8 rp; -}; - -struct nvme_id_ns { -__le64 nsze; -__le64 ncap; -__le64 nuse; -__u8 nsfeat; -__u8 nlbaf; -__u8 flbas; -__u8 mc; -__u8 dpc; -__u8 dps; -__u8 nmic; -__u8 rescap; -__u8 fpi; -__u8 rsvd33; -__le16 nawun; -__le16 nawupf; -__le16 nacwu; -__le16 nabsn; -__le16 nabo; -__le16 nabspf; -__u16 rsvd46; -__u8 nvmcap[16 ]; -__u8 rsvd64[40 ]; -__u8 nguid[16 ]; -__u8 eui64[8 ]; -struct nvme_lbaf lbaf[16 ]; -__u8 rsvd192[192 ]; -__u8 vs[3712 ]; -}; - -enum { -NVME_NS_FEAT_THIN =1 <<0 , -NVME_LBAF_RP_BEST =0 , -NVME_LBAF_RP_BETTER =1 , -NVME_LBAF_RP_GOOD =2 , -NVME_LBAF_RP_DEGRADED =3 , -}; - -struct nvme_smart_log { -__u8 critical_warning; -__u8 temperature[2 ]; -__u8 avail_spare; -__u8 spare_thresh; -__u8 percent_used; -__u8 rsvd6[26 ]; -__u8 data_units_read[16 ]; -__u8 data_units_written[16 ]; -__u8 host_reads[16 ]; -__u8 host_writes[16 ]; -__u8 ctrl_busy_time[16 ]; -__u8 power_cycles[16 ]; -__u8 power_on_hours[16 ]; -__u8 unsafe_shutdowns[16 ]; -__u8 media_errors[16 ]; -__u8 num_err_log_entries[16 ]; -__le32 warning_temp_time; -__le32 critical_comp_time; -__le16 temp_sensor[8 ]; -__u8 rsvd216[296 ]; -}; - -enum { -NVME_SMART_CRIT_SPARE =1 <<0 , -NVME_SMART_CRIT_TEMPERATURE =1 <<1 , -NVME_SMART_CRIT_RELIABILITY =1 <<2 , -NVME_SMART_CRIT_MEDIA =1 <<3 , -NVME_SMART_CRIT_VOLATILE_MEMORY =1 <<4 , -}; -#pragma pack(push,1)struct nvme_additional_smart_log_item {__u8 key;
@@ -312,16 +91,6 @@ struct nvme_additional_smart_log {struct nvme_additional_smart_log_item host_bytes_written; }; -struct nvme_lba_range_type { -__u8 type; -__u8 attributes; -__u8 rsvd2[14 ]; -__u64 slba; -__u64 nlb; -__u8 guid[16 ]; -__u8 rsvd48[16 ]; -}; -struct nvme_host_mem_buffer {__u32 hsize;__u32 hmdlal;
@@ -335,206 +104,11 @@ struct nvme_auto_pst {__u32 rsvd32; }; -enum { -NVME_LBART_TYPE_FS =0x01 , -NVME_LBART_TYPE_RAID =0x02 , -NVME_LBART_TYPE_CACHE =0x03 , -NVME_LBART_TYPE_SWAP =0x04 , - -NVME_LBART_ATTRIB_TEMP =1 <<0 , -NVME_LBART_ATTRIB_HIDE =1 <<1 , -}; - -struct nvme_reservation_status { -__le32 gen; -__u8 rtype; -__u8 regctl[2 ]; -__u8 resv5[2 ]; -__u8 ptpls; -__u8 resv10[14 ]; -struct { -__le16 cntlid; -__u8 rcsts; -__u8 resv3[5 ]; -__le64 hostid; -__le64 rkey; - } regctl_ds[]; -}; - -/* 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_resv_register =0x0d , - nvme_cmd_resv_report =0x0e , - nvme_cmd_resv_acquire =0x11 , - nvme_cmd_resv_release =0x15 , -}; - -enum { -NVME_RW_LR =1 <<15 , -NVME_RW_FUA =1 <<14 , -NVME_RW_DSM_FREQ_UNSPEC =0 , -NVME_RW_DSM_FREQ_TYPICAL =1 , -NVME_RW_DSM_FREQ_RARE =2 , -NVME_RW_DSM_FREQ_READS =3 , -NVME_RW_DSM_FREQ_WRITES =4 , -NVME_RW_DSM_FREQ_RW =5 , -NVME_RW_DSM_FREQ_ONCE =6 , -NVME_RW_DSM_FREQ_PREFETCH =7 , -NVME_RW_DSM_FREQ_TEMP =8 , -NVME_RW_DSM_LATENCY_NONE =0 <<4 , -NVME_RW_DSM_LATENCY_IDLE =1 <<4 , -NVME_RW_DSM_LATENCY_NORM =2 <<4 , -NVME_RW_DSM_LATENCY_LOW =3 <<4 , -NVME_RW_DSM_SEQ_REQ =1 <<6 , -NVME_RW_DSM_COMPRESSED =1 <<7 , -}; - -enum { -NVME_DSMGMT_IDR =1 <<0 , -NVME_DSMGMT_IDW =1 <<1 , -NVME_DSMGMT_AD =1 <<2 , -}; - -struct nvme_dsm_range { -__le32 cattr; -__le32 nlb; -__le64 slba; -}; -struct nvme_controller_list {__le16 num;__le16 identifier[]; }; -/* 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_ns_attach =0x15 , - nvme_admin_format_nvm =0x80 , - nvme_admin_security_send =0x81 , - nvme_admin_security_recv =0x82 , -}; - -enum { -NVME_QUEUE_PHYS_CONTIG = (1 <<0 ), -NVME_CQ_IRQ_ENABLED = (1 <<1 ), -NVME_SQ_PRIO_URGENT = (0 <<1 ), -NVME_SQ_PRIO_HIGH = (1 <<1 ), -NVME_SQ_PRIO_MEDIUM = (2 <<1 ), -NVME_SQ_PRIO_LOW = (3 <<1 ), -NVME_FEAT_ARBITRATION =0x01 , -NVME_FEAT_POWER_MGMT =0x02 , -NVME_FEAT_LBA_RANGE =0x03 , -NVME_FEAT_TEMP_THRESH =0x04 , -NVME_FEAT_ERR_RECOVERY =0x05 , -NVME_FEAT_VOLATILE_WC =0x06 , -NVME_FEAT_NUM_QUEUES =0x07 , -NVME_FEAT_IRQ_COALESCE =0x08 , -NVME_FEAT_IRQ_CONFIG =0x09 , -NVME_FEAT_WRITE_ATOMIC =0x0a , -NVME_FEAT_ASYNC_EVENT =0x0b , -NVME_FEAT_AUTO_PST =0x0c , -NVME_FEAT_HOST_MEM_BUF =0x0d , -NVME_FEAT_SW_PROGRESS =0x80 , -NVME_FEAT_HOST_ID =0x81 , -NVME_FEAT_RESV_MASK =0x82 , -NVME_FEAT_RESV_PERSIST =0x83 , -NVME_LOG_ERROR =0x01 , -NVME_LOG_SMART =0x02 , -NVME_LOG_FW_SLOT =0x03 , -NVME_LOG_DISC =0x70 , -NVME_LOG_RESERVATION =0x80 , -NVME_FWACT_REPL = (0 <<3 ), -NVME_FWACT_REPL_ACTV = (1 <<3 ), -NVME_FWACT_ACTV = (2 <<3 ), -}; - -enum { -NVME_SC_SUCCESS =0x0 , -NVME_SC_INVALID_OPCODE =0x1 , -NVME_SC_INVALID_FIELD =0x2 , -NVME_SC_CMDID_CONFLICT =0x3 , -NVME_SC_DATA_XFER_ERROR =0x4 , -NVME_SC_POWER_LOSS =0x5 , -NVME_SC_INTERNAL =0x6 , -NVME_SC_ABORT_REQ =0x7 , -NVME_SC_ABORT_QUEUE =0x8 , -NVME_SC_FUSED_FAIL =0x9 , -NVME_SC_FUSED_MISSING =0xa , -NVME_SC_INVALID_NS =0xb , -NVME_SC_CMD_SEQ_ERROR =0xc , -NVME_SC_SGL_INVALID_LAST =0xd , -NVME_SC_SGL_INVALID_COUNT =0xe , -NVME_SC_SGL_INVALID_DATA =0xf , -NVME_SC_SGL_INVALID_METADATA =0x10 , -NVME_SC_SGL_INVALID_TYPE =0x11 , -NVME_SC_LBA_RANGE =0x80 , -NVME_SC_CAP_EXCEEDED =0x81 , -NVME_SC_NS_NOT_READY =0x82 , -NVME_SC_RESERVATION_CONFLICT =0x83 , -NVME_SC_CQ_INVALID =0x100 , -NVME_SC_QID_INVALID =0x101 , -NVME_SC_QUEUE_SIZE =0x102 , -NVME_SC_ABORT_LIMIT =0x103 , -NVME_SC_ABORT_MISSING =0x104 , -NVME_SC_ASYNC_LIMIT =0x105 , -NVME_SC_FIRMWARE_SLOT =0x106 , -NVME_SC_FIRMWARE_IMAGE =0x107 , -NVME_SC_INVALID_VECTOR =0x108 , -NVME_SC_INVALID_LOG_PAGE =0x109 , -NVME_SC_INVALID_FORMAT =0x10a , -NVME_SC_FW_NEEDS_CONV_RESET =0x10b , -NVME_SC_INVALID_QUEUE =0x10c , -NVME_SC_FEATURE_NOT_SAVEABLE =0x10d , -NVME_SC_FEATURE_NOT_CHANGEABLE =0x10e , -NVME_SC_FEATURE_NOT_PER_NS =0x10f , -NVME_SC_FW_NEEDS_SUBSYS_RESET =0x110 , -NVME_SC_FW_NEEDS_RESET =0x111 , -NVME_SC_FW_NEEDS_MAX_TIME =0x112 , -NVME_SC_FW_ACIVATE_PROHIBITED =0x113 , -NVME_SC_OVERLAPPING_RANGE =0x114 , -NVME_SC_NS_INSUFFICENT_CAP =0x115 , -NVME_SC_NS_ID_UNAVAILABLE =0x116 , -NVME_SC_NS_ALREADY_ATTACHED =0x118 , -NVME_SC_NS_IS_PRIVATE =0x119 , -NVME_SC_NS_NOT_ATTACHED =0x11a , -NVME_SC_THIN_PROV_NOT_SUPP =0x11b , -NVME_SC_CTRL_LIST_INVALID =0x11c , -NVME_SC_BAD_ATTRIBUTES =0x180 , -NVME_SC_INVALID_PI =0x181 , -NVME_SC_READ_ONLY =0x182 , -NVME_SC_WRITE_FAULT =0x280 , -NVME_SC_READ_ERROR =0x281 , -NVME_SC_GUARD_CHECK =0x282 , -NVME_SC_APPTAG_CHECK =0x283 , -NVME_SC_REFTAG_CHECK =0x284 , -NVME_SC_COMPARE_FAILED =0x285 , -NVME_SC_ACCESS_DENIED =0x286 , -NVME_SC_UNWRITTEN_BLOCK =0x287 , -NVME_SC_DNR =0x4000 , -}; -struct nvme_bar {__u64 cap;/* Controller Capabilities */ __u32 vs;/* Version */
@@ -560,45 +134,6 @@ struct nvme_bar_cap {__u8 reserved; }; -#define NVME_CNTLID_DYNAMIC 0xFFFF - -/* Discovery log page entry */ -struct nvmf_disc_rsp_page_entry { -__u8 trtype; -__u8 adrfam; -__u8 subtype; -__u8 treq; -__le16 portid; -__le16 cntlid; -__u8 resv8[24 ]; -char trsvcid[NVMF_TRSVCID_SIZE ]; -__u8 resv64[192 ]; -char subnqn[NVMF_NQN_FIELD_LEN ]; -char traddr[NVMF_TRADDR_SIZE ]; -union tsas { -char common[NVMF_TSAS_SIZE ]; -struct rdma { -__u8 qptype; -__u8 prtype; -__u8 cms; -__u8 resv3[5 ]; -__u16 pkey; -__u8 resv10[246 ]; - } rdma; - } tsas; -}; - -/* Discovery log page header */ -struct nvmf_disc_rsp_page_hdr { -__le64 genctr; -__le64 numrec; -__le16 recfmt; -__u8 resv14[1006 ]; -struct nvmf_disc_rsp_page_entry entries[0 ]; -}; - -#define NVME_VS (major, minor) (((major) << 16) | ((minor) << 8)) -void register_extension (struct plugin *plugin);#include "argconfig.h"
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 4/18 dynamically allocate log page buffers
In reply to Christoph HellwigA device can report large logs. Better dynamically allocate the buffer we pass to the kernel instead of doing a gigantic stack allocation.
--- nvme.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
nvme.c +16 -2
@@ -299,7 +299,13 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plugfprintf (stderr,"could not identify controller\n" );return ENODEV ; }else { -struct nvme_error_log_page err_log[cfg.log_entries]; +struct nvme_error_log_page *err_log; + + err_log =calloc (cfg.log_entries,sizeof (struct nvme_error_log_page )); +if (!err_log) { +fprintf (stderr,"could not alloc buffer for error log\n" ); +return ENOMEM ; + } err =nvme_error_log (fd, cfg.namespace_id, cfg.log_entries, err_log);if (!err) {
@@ -313,6 +319,7 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plugelse if (err >0 )fprintf (stderr,"NVMe Status:%s(%x)\n" ,nvme_status_to_string (err), err); +free (err_log); }return err; }
@@ -403,7 +410,13 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *plfprintf (stderr,"non-zero log-len is required param\n" );return EINVAL ; }else { -unsigned char log[cfg.log_len]; +unsigned char *log; + + log =malloc (cfg.log_len); +if (!log) { +fprintf (stderr,"could not alloc buffer for log\n" ); +return EINVAL ; + } err =nvme_get_log (fd, cfg.namespace_id, cfg.log_id, cfg.log_len, log);if (!err) {
@@ -417,6 +430,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl }else if (err >0 )fprintf (stderr,"NVMe Status:%s(%x)\n" ,nvme_status_to_string (err), err); +free (log);return err; } }
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 5/18 use abort() instead of __builtin_abort
In reply to Christoph HellwigThis is more portable to different compilers, but should otherwise have the same effect.
--- json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
json.c +1 -1
@@ -8,7 +8,7 @@static inline void fail_and_notify (void ) {fprintf (stderr,"Allocation of memory for json object failed, aborting.\n" ); -__builtin_abort (); +abort (); }struct json_object *json_create_object (void )
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 6/18 various trivial sparse fixes
In reply to Christoph HellwigUse NULL instead of 0 for pointers, mark symbols static as needed and provide proper ANSI C prototypes for all functions.
--- Makefile | 2 +- argconfig.c | 10 ++++----- cmd_handler.h | 4 ++-- fabrics.c | 10 ++++----- intel-nvme.c | 10 ++++----- lnvm-nvme.c | 18 +++++++-------- memblaze-nvme.c | 6 ++--- nvme-ioctl.c | 6 ++--- nvme-lightnvm.c | 8 +++---- nvme-print.c | 8 +++---- nvme-print.h | 14 ++++++------ nvme.c | 68 ++++++++++++++++++++++++++++----------------------------- 12 files changed, 82 insertions(+), 82 deletions(-)
Makefile +1 -1
@@ -1,5 +1,5 @@ CFLAGS += -std=gnu99 -O2 -g -Wall -Werror -CPPFLAGS += -D_GNU_SOURCE +CPPFLAGS += -D_GNU_SOURCE -D__CHECK_ENDIAN__ NVME = nvme INSTALL ?= install DESTDIR =
argconfig.c +5 -5
@@ -42,9 +42,9 @@static argconfig_help_func *help_funcs[MAX_HELP_FUNC ] = {NULL }; -char END_DEFAULT [] ="__end_default__" ; +static char END_DEFAULT [] ="__end_default__" ; -const char *append_usage_str ="" ; +static const char *append_usage_str ="" ;void argconfig_append_usage (const char *str) {
@@ -130,7 +130,7 @@ static void argconfig_print_help(const char *program_desc,print_word_wrapped (program_desc,0 ,0 );printf ("\n\n\033[1mOptions:\033[0m\n" ); -for (s = options; (s->option !=0 ) && (s !=NULL ); s++) +for (s = options; (s->option !=NULL ) && (s !=NULL ); s++)show_option (s); }
@@ -146,13 +146,13 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc,void *value_addr; errno =0 ; -for (s = options; s->option !=0 ; s++) +for (s = options; s->option !=NULL ; s++) options_count++; long_opts =malloc (sizeof (struct option ) * (options_count +2 )); short_opts =malloc (sizeof (*short_opts) * (options_count *3 +4 )); -for (s = options; (s->option !=0 ) && (option_index < options_count); +for (s = options; (s->option !=NULL ) && (option_index < options_count); s++) {if (s->short_option !=0 ) { short_opts[short_index++] = s->short_option;
cmd_handler.h +2 -2
@@ -87,8 +87,8 @@ static struct plugin plugin = { \ .commands = commands \ }; \ \ -static void init () __attribute__((constructor)); \ -static void init () \ +static void init (void ) __attribute__((constructor)); \ +static void init (void ) \ { \register_extension (&plugin); \ }
fabrics.c +5 -5
@@ -44,7 +44,7 @@#include "common.h" -struct config { +static struct config { char *nqn; char *transport; char *traddr;
@@ -55,7 +55,7 @@ struct config {char *reconnect_delay;char *raw;char *device; -} cfg = { 0 }; +} cfg = { NULL };#define BUF_SIZE 4096#define PATH_NVME_FABRICS "/dev/nvme-fabrics"
@@ -718,7 +718,7 @@ int discover(const char *desc, int argc, char **argv, bool connect) "user-defined hostnqn (if default not used)" }, {"raw", 'r', "LIST", CFG_STRING, &cfg.raw, required_argument, "raw output file" }, - {0}, + {NULL}, }; argconfig_parse(argc, argv, desc, command_line_options, &cfg,
@@ -761,7 +761,7 @@ int connect(const char *desc, int argc, char **argv) "keep alive timeout period in seconds" }, {"reconnect-delay", 'r', "LIST", CFG_STRING, &cfg.reconnect_delay, required_argument, "reconnect timeout period in seconds" }, - {0}, + {NULL}, }; argconfig_parse(argc, argv, desc, command_line_options, &cfg,
@@ -885,7 +885,7 @@ int disconnect(const char *desc, int argc, char **argv) required_argument, nqn}, {"device", 'd', "LIST", CFG_STRING, &cfg.device, required_argument, device}, - {0}, + {NULL}, }; argconfig_parse(argc, argv, desc, command_line_options, &cfg,
intel-nvme.c +5 -5
@@ -61,7 +61,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd,const struct argconfig_commandline_options command_line_options[] = { {"namespace-id" ,'n' ,"NUM" ,CFG_POSITIVE , &cfg.namespace_id, required_argument, namespace}, {"raw-binary" ,'b' ,"" ,CFG_NONE , &cfg.raw_binary, no_argument, raw}, - {0 } + {NULL } }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -95,7 +95,7 @@ static int get_market_log(int argc, char **argv, struct command *cmd, struct pluconst struct argconfig_commandline_options command_line_options[] = { {"raw-binary" ,'b' ,"" ,CFG_NONE , &cfg.raw_binary, no_argument, raw}, - {0 } + {NULL } }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -155,7 +155,7 @@ static int get_temp_stats_log(int argc, char **argv, struct command *cmd, structconst struct argconfig_commandline_options command_line_options[] = { {"raw-binary" ,'b' ,"" ,CFG_NONE , &cfg.raw_binary, no_argument, raw}, - {0 } + {NULL } }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -221,7 +221,7 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, structconst struct argconfig_commandline_options command_line_options[] = { {"write" ,'w' ,"" ,CFG_NONE , &cfg.write, no_argument, write}, {"raw-binary" ,'b' ,"" ,CFG_NONE , &cfg.raw_binary, no_argument, raw}, - {0 } + {NULL } }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -275,7 +275,7 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru {"log", 'l', "NUM", CFG_POSITIVE, &cfg.log, required_argument, log}, {"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id}, {"output-file", 'o', "FILE", CFG_STRING, &cfg.file, required_argument, file}, - {0} + {NULL} }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
lnvm-nvme.c +9 -9
@@ -39,7 +39,7 @@ static int lnvm_init(int argc, char **argv, struct command *cmd, struct plugin *const struct argconfig_commandline_options command_line_options[] = { {"device-name" ,'d' ,"DEVICE" ,CFG_STRING , &cfg.devname, required_argument, devname}, {"mediamgr-name" ,'m' ,"MM" ,CFG_STRING , &cfg.mmtype, required_argument, mmtype}, - {0 } + {NULL } };argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -57,7 +57,7 @@ static int lnvm_list(int argc, char **argv, struct command *cmd, struct plugin *const char *desc ="List all devices registered with LightNVM." ;const struct argconfig_commandline_options command_line_options[] = { - {0 } + {NULL } };argconfig_parse (argc, argv, desc, command_line_options,NULL ,0 );
@@ -70,7 +70,7 @@ static int lnvm_info(int argc, char **argv, struct command *cmd, struct plugin *const char *desc ="Show general information and registered target types with LightNVM" ;const struct argconfig_commandline_options command_line_options[] = { - {0 } + {NULL } };argconfig_parse (argc, argv, desc, command_line_options,NULL ,0 );
@@ -105,7 +105,7 @@ static int lnvm_id_ns(int argc, char **argv, struct command *cmd, struct plugin {"force", 'f', "FLAG", CFG_NONE, &cfg.force, no_argument, force}, {"raw-binary", 'b', "FLAG", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary}, {"human-readable", 'H', "FLAG", CFG_NONE, &cfg.human_readable, no_argument, human_readable}, - {0} + {NULL} }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -151,7 +151,7 @@ static int lnvm_create_tgt(int argc, char **argv, struct command *cmd, struct pl {"target-type", 't', "TARGETTYPE", CFG_STRING, &cfg.tgttype, required_argument, tgttype}, {"lun-begin", 'b', "NUM", CFG_POSITIVE, &cfg.lun_begin, required_argument, lun_begin}, {"lun-end", 'e', "NUM", CFG_POSITIVE, &cfg.lun_end, required_argument, lun_end}, - {0} + {NULL} };argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -188,7 +188,7 @@ static int lnvm_remove_tgt(int argc, char **argv, struct command *cmd, struct plconst struct argconfig_commandline_options command_line_options[] = { {"target-name" ,'n' ,"TARGET" ,CFG_STRING , &cfg.tgtname, required_argument, tgtname}, - {0 } + {NULL } };argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -226,7 +226,7 @@ static int lnvm_factory_init(int argc, char **argv, struct command *cmd, struct {"erase-only-marked", 'e', "", CFG_NONE, &cfg.erase_only_marked, no_argument, erase_only_marked}, {"clear-host-side-blks", 's', "", CFG_NONE, &cfg.clear_host_marks, no_argument, host_marks}, {"clear-bb-blks", 'b', "", CFG_NONE, &cfg.clear_bb_marks, no_argument, bb_marks}, - {0} + {NULL} }; argconfig_parse(argc, argv, desc, command_line_options, &cfg,
@@ -270,7 +270,7 @@ static int lnvm_get_bbtbl(int argc, char **argv, struct command *cmd, struct plu {"channel-id", 'c', "", CFG_SHORT, &cfg.chid, required_argument, ch}, {"lun-id", 'l', "", CFG_SHORT, &cfg.lunid, required_argument, lun}, {"raw-binary", 'b', "FLAG", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary}, - {0} + {NULL} }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -320,7 +320,7 @@ static int lnvm_set_bbtbl(int argc, char **argv, struct command *cmd, struct plu {"plane-id", 'p', "NUM", CFG_SHORT, &cfg.plnid, required_argument, pln}, {"block-id", 'b', "NUM", CFG_SHORT, &cfg.blkid, required_argument, blk}, {"value", 'v', "NUM", CFG_SHORT, &cfg.value, required_argument, value}, - {0} + {NULL} }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
memblaze-nvme.c +3 -3
@@ -157,7 +157,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd,const struct argconfig_commandline_options command_line_options[] = { {"namespace-id" ,'n' ,"NUM" ,CFG_POSITIVE , &cfg.namespace_id, required_argument, namespace}, {"raw-binary" ,'b' ,"" ,CFG_NONE , &cfg.raw_binary, no_argument, raw}, - {0 } + {NULL } }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -234,7 +234,7 @@ static int get_additional_feature(int argc, char **argv, struct command *cmd, st {"raw-binary", 'b', "FLAG", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary}, {"cdw11", 'c', "NUM", CFG_POSITIVE, &cfg.cdw11, required_argument, cdw11}, {"human-readable", 'H', "FLAG", CFG_NONE, &cfg.human_readable, no_argument, human_readable}, - {0} + {NULL} }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
@@ -327,7 +327,7 @@ static int set_additional_feature(int argc, char **argv, struct command *cmd, st {"data-len", 'l', "NUM", CFG_POSITIVE, &cfg.data_len, required_argument, data_len}, {"data", 'd', "FILE", CFG_STRING, &cfg.file, required_argument, data}, {"save", 's', "FLAG", CFG_NONE, &cfg.save, no_argument, save}, - {0} + {NULL} }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));
nvme-ioctl.c +3 -3
@@ -21,7 +21,7 @@#include "nvme-ioctl.h" -void nvme_verify_chr (int fd) +static void nvme_verify_chr (int fd) {static struct stat nvme_stat;int err =fstat (fd, &nvme_stat);
@@ -70,12 +70,12 @@ int nvme_submit_passthru(int fd, int ioctl_cmd, struct nvme_passthru_cmd *cmd)return ioctl (fd, ioctl_cmd, cmd); } -int nvme_submit_admin_passthru (int fd,struct nvme_passthru_cmd *cmd) +static int nvme_submit_admin_passthru (int fd,struct nvme_passthru_cmd *cmd) {return ioctl (fd,NVME_IOCTL_ADMIN_CMD , cmd); } -int nvme_submit_io_passthru (int fd,struct nvme_passthru_cmd *cmd) +static int nvme_submit_io_passthru (int fd,struct nvme_passthru_cmd *cmd) {return ioctl (fd,NVME_IOCTL_IO_CMD , cmd); }
nvme-lightnvm.c +4 -4
@@ -217,7 +217,7 @@ int lnvm_do_factory_init(char *devname, int erase_only_marked,return ret; } -void show_lnvm_id_grp (struct nvme_nvm_id_group *grp) +static void show_lnvm_id_grp (struct nvme_nvm_id_group *grp) {printf (" mtype : %d\n" , grp->mtype);printf (" fmtype : %d\n" , grp->fmtype);
@@ -240,7 +240,7 @@ void show_lnvm_id_grp(struct nvme_nvm_id_group *grp)printf (" cpar : %#x\n" , (uint16_t )le16toh (grp->cpar)); } -void show_lnvm_ppaf (struct nvme_nvm_addr_format *ppaf) +static void show_lnvm_ppaf (struct nvme_nvm_addr_format *ppaf) {printf ("ppaf :\n" ); printf(" ch offs : %d ch bits : %d\n",
@@ -257,7 +257,7 @@ void show_lnvm_ppaf(struct nvme_nvm_addr_format *ppaf) ppaf->sect_offset, ppaf->sect_len); } -void show_lnvm_id_ns (struct nvme_nvm_id *id) +static void show_lnvm_id_ns (struct nvme_nvm_id *id) {int i;
@@ -279,7 +279,7 @@ void show_lnvm_id_ns(struct nvme_nvm_id *id) } } -int lnvm_get_identity (int fd,int nsid,struct nvme_nvm_id *nvm_id) +static int lnvm_get_identity (int fd,int nsid,struct nvme_nvm_id *nvm_id) {struct nvme_admin_cmd cmd = { .opcode = nvme_nvm_admin_identity,
nvme-print.c +4 -4
@@ -1417,7 +1417,7 @@ void show_registers_version(__u32 vs)printf ("\tNVMe specification %d.%d\n\n" , (vs &0xffff0000 ) >>16 , (vs &0x0000ff00 ) >>8 ); } -void show_registers_cc_ams (__u8 ams) +static void show_registers_cc_ams (__u8 ams) {printf ("\tArbitration Mechanism Selected (AMS): " );switch (ams) {
@@ -1435,7 +1435,7 @@ void show_registers_cc_ams (__u8 ams) } } -void show_registers_cc_shn (__u8 shn) +static void show_registers_cc_shn (__u8 shn) {printf ("\tShutdown Notification (SHN): " );switch (shn) {
@@ -1464,7 +1464,7 @@ void show_registers_cc (__u32 cc)printf ("\tEnable (EN): %s\n\n" , (cc &0x00000001 ) ?"Yes" :"No" ); } -void show_registers_csts_shst (__u8 shst) +static void show_registers_csts_shst (__u8 shst) {printf ("\tShutdown Status (SHST): " );switch (shst) {
@@ -1510,7 +1510,7 @@ void show_registers_cmbloc(__u32 cmbloc, __u32 cmbsz) } } -char *nvme_register_szu_to_string (__u8 szu) +static char *nvme_register_szu_to_string (__u8 szu) {switch (szu) {case 0 :return "4 KB" ;
nvme-print.h +7 -7
@@ -37,13 +37,13 @@ void json_error_log(struct nvme_error_log_page *err_log, int entries, const charvoid json_smart_log (struct nvme_smart_log *smart,unsigned int nsid,const char *devname);void json_fw_log (struct nvme_firmware_log_page *fw_log,const char *devname); -void show_registers_version (); -void show_registers_cap (); -void show_registers_cc (); -void show_registers_csts (); -void show_registers_aqa (); -void show_registers_cmbloc (); -void show_registers_cmbsz (); +void show_registers_version (__u32 vs); +void show_registers_cap (struct nvme_bar_cap *cap); +void show_registers_cc (__u32 cc); +void show_registers_csts (__u32 csts); +void show_registers_aqa (__u32 aqa); +void show_registers_cmbloc (__u32 cmbloc,__u32 cmbsz); +void show_registers_cmbsz (__u32 cmbsz);#endif
nvme.c +34 -34
272 lines not on this page · raw message
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 7/18 add support for checking endianess annotations using sparse
In reply to Christoph Hellwig--- fabrics.c | 6 +-- memblaze-nvme.c | 16 ++++---- nvme-ioctl.c | 18 ++++----- nvme-lightnvm.c | 52 +++++++++++++------------- nvme-print.c | 114 ++++++++++++++++++++++++++++---------------------------- nvme.c | 4 +- nvme.h | 20 ++++++++++ 7 files changed, 125 insertions(+), 105 deletions(-)
fabrics.c +3 -3
@@ -304,8 +304,8 @@ static int nvmf_get_log_page_discovery(const char *dev_path, }/* check numrec limits */ - *numrec =le64toh (log->numrec); - genctr =le64toh (log->genctr); + *numrec =le64_to_cpu (log->numrec); + genctr =le64_to_cpu (log->genctr);free (log);if (*numrec ==0 ) {
@@ -338,7 +338,7 @@ static int nvmf_get_log_page_discovery(const char *dev_path, goto out_free_log; } -if (*numrec !=le32toh (log->numrec) || genctr !=le64toh (log->genctr)) { +if (*numrec !=le32_to_cpu (log->numrec) || genctr !=le64_to_cpu (log->genctr)) { error =DISC_NOT_EQUAL ; goto out_free_log; }
memblaze-nvme.c +8 -8
@@ -115,24 +115,24 @@ static int show_memblaze_smart_log(int fd, __u32 nsid, const char *devname, smart->items[THERMAL_THROTTLE].thermal_throttle.count);printf ("Maximum temperature in Kelvin since last factory reset : %u\n" , -le16toh (smart->items[TEMPT_SINCE_RESET ].temperature.max)); +le16_to_cpu (smart->items[TEMPT_SINCE_RESET ].temperature.max));printf ("Minimum temperature in Kelvin since last factory reset : %u\n" , -le16toh (smart->items[TEMPT_SINCE_RESET ].temperature.min)); +le16_to_cpu (smart->items[TEMPT_SINCE_RESET ].temperature.min));if (compare_fw_version (fw_ver,"0.09.0300" ) !=0 ) {printf ("Maximum temperature in Kelvin since power on : %u\n" , -le16toh (smart->items[TEMPT_SINCE_BOOTUP ].temperature_p.max)); +le16_to_cpu (smart->items[TEMPT_SINCE_BOOTUP ].temperature_p.max));printf ("Minimum temperature in Kelvin since power on : %u\n" , -le16toh (smart->items[TEMPT_SINCE_BOOTUP ].temperature_p.min)); +le16_to_cpu (smart->items[TEMPT_SINCE_BOOTUP ].temperature_p.min)); }printf ("Current temperature in Kelvin : %u\n" , -le16toh (smart->items[TEMPT_SINCE_RESET ].temperature.curr)); +le16_to_cpu (smart->items[TEMPT_SINCE_RESET ].temperature.curr));printf ("Maximum power in watt since power on : %u\n" , -le16toh (smart->items[POWER_CONSUMPTION ].power.max)); +le16_to_cpu (smart->items[POWER_CONSUMPTION ].power.max));printf ("Minimum power in watt since power on : %u\n" , -le16toh (smart->items[POWER_CONSUMPTION ].power.min)); +le16_to_cpu (smart->items[POWER_CONSUMPTION ].power.min));printf ("Current power in watt : %u\n" , -le16toh (smart->items[POWER_CONSUMPTION ].power.curr)); +le16_to_cpu (smart->items[POWER_CONSUMPTION ].power.curr));return err; }
nvme-ioctl.c +9 -9
@@ -234,9 +234,9 @@ struct nvme_dsm_range *nvme_setup_dsm_range(__u32 *ctx_attrs, __u32 *llbas,if (!dsm)exit (ENOMEM );for (i =0 ; i < nr_ranges; i++) { - dsm[i].cattr =htole32 (ctx_attrs[i]); - dsm[i].nlb =htole32 (llbas[i]); - dsm[i].slba =htole64 (slbas[i]); + dsm[i].cattr =cpu_to_le32 (ctx_attrs[i]); + dsm[i].nlb =cpu_to_le32 (llbas[i]); + dsm[i].slba =cpu_to_le64 (slbas[i]); }return dsm; }
@@ -244,7 +244,7 @@ struct nvme_dsm_range *nvme_setup_dsm_range(__u32 *ctx_attrs, __u32 *llbas,int nvme_resv_acquire (int fd,__u32 nsid,__u8 rtype,__u8 racqa,bool iekey,__u64 crkey,__u64 nrkey) { -__le64 payload[2 ] = {htole64 (crkey),htole64 (nrkey) }; +__le64 payload[2 ] = {cpu_to_le64 (crkey),cpu_to_le64 (nrkey) };__u32 cdw10 = racqa | (iekey ?1 <<3 :0 ) | rtype <<8 ;struct nvme_passthru_cmd cmd = { .opcode = nvme_cmd_resv_acquire,
@@ -260,7 +260,7 @@ int nvme_resv_acquire(int fd, __u32 nsid, __u8 rtype, __u8 racqa,int nvme_resv_register (int fd,__u32 nsid,__u8 rrega,__u8 cptpl,bool iekey,__u64 crkey,__u64 nrkey) { -__le64 payload[2 ] = {htole64 (crkey),htole64 (nrkey) }; +__le64 payload[2 ] = {cpu_to_le64 (crkey),cpu_to_le64 (nrkey) };__u32 cdw10 = rrega | (iekey ?1 <<3 :0 ) | cptpl <<30 ;struct nvme_passthru_cmd cmd = {
@@ -277,7 +277,7 @@ int nvme_resv_register(int fd, __u32 nsid, __u8 rrega, __u8 cptpl,int nvme_resv_release (int fd,__u32 nsid,__u8 rtype,__u8 rrela,bool iekey,__u64 crkey) { -__le64 payload[1 ] = {htole64 (crkey) }; +__le64 payload[1 ] = {cpu_to_le64 (crkey) };__u32 cdw10 = rrela | (iekey ?1 <<3 :0 ) | rtype <<8 ;struct nvme_passthru_cmd cmd = {
@@ -455,8 +455,8 @@ int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas, __u8 dps, __u8 nmic, __u32 *result) { struct nvme_id_ns ns = { - .nsze = htole64(nsze), - .ncap = htole64(ncap), + .nsze = cpu_to_le64(nsze), + .ncap = cpu_to_le64(ncap), .flbas = flbas, .dps = dps, .nmic = nmic,
@@ -504,7 +504,7 @@ int nvme_ns_attachment(int fd, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist,memset (buf,0 ,sizeof (buf)); cntlist->num = num_ctrls;for (i =0 ; i < cntlist->num; i++) - cntlist->identifier[i] =htole16 ((__u16 ) ctrlist[i]); + cntlist->identifier[i] =cpu_to_le16 (ctrlist[i]);return nvme_submit_admin_passthru (fd, &cmd); }
nvme-lightnvm.c +26 -26
88 lines not on this page · raw message
nvme-print.c +57 -57
281 lines not on this page · raw message
nvme.c +2 -2
@@ -466,10 +466,10 @@ static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin * err =nvme_identify_ctrl_list (fd, cfg.namespace_id, cfg.cntid, cntlist);if (!err) { -__u16 num =le16toh (cntlist->num); +__u16 num =le16_to_cpu (cntlist->num);for (i =0 ; i < (min (num,2048 )); i++) -printf ("[%4u]:%#x\n" , i,le16toh (cntlist->identifier[i])); +printf ("[%4u]:%#x\n" , i,le16_to_cpu (cntlist->identifier[i])); }else if (err >0 ) fprintf(stderr, "NVMe Status:%s(%x) cntid:%d\n",
nvme.h +20 -0
@@ -134,6 +134,26 @@ struct nvme_bar_cap {__u8 reserved; }; +#ifdef __CHECKER__ +#define __force __attribute__((force)) +#else +#define __force +#endif + +#define cpu_to_le16 (x) \ + ((__force __le16)htole16(x)) +#define cpu_to_le32 (x) \ + ((__force __le32)htole32(x)) +#define cpu_to_le64 (x) \ + ((__force __le64)htole64(x)) + +#define le16_to_cpu (x) \ + le16toh((__force __u16)(x)) +#define le32_to_cpu (x) \ + le32toh((__force __u32)(x)) +#define le64_to_cpu (x) \ + le64toh((__force __u64)(x)) +void register_extension (struct plugin *plugin);#include "argconfig.h"
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 8/18 add missing endianess annoations for lightnvm data structures
In reply to Christoph Hellwig--- nvme-lightnvm.h | 136 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 68 insertions(+), 68 deletions(-)
nvme-lightnvm.h +68 -68
@@ -32,55 +32,55 @@ enum nvme_nvm_admin_opcode {struct nvme_nvm_identity {__u8 opcode;__u8 flags; -__u16 command_id; -__u32 nsid; -__u64 rsvd[2 ]; -__u64 prp1; -__u64 prp2; -__u32 chnl_off; -__u32 rsvd11[5 ]; +__le16 command_id; +__le32 nsid; +__le64 rsvd[2 ]; +__le64 prp1; +__le64 prp2; +__le32 chnl_off; +__le32 rsvd11[5 ]; };struct nvme_nvm_setbbtbl {__u8 opcode;__u8 flags; -__u16 rsvd1; -__u32 nsid; -__u32 cdw2; -__u32 cdw3; -__u64 metadata; +__le16 rsvd1; +__le32 nsid; +__le32 cdw2; +__le32 cdw3; +__le64 metadata;__u64 addr; -__u32 metadata_len; -__u32 data_len; -__u64 ppa; -__u16 nlb; +__le32 metadata_len; +__le32 data_len; +__le64 ppa; +__le16 nlb;__u8 value;__u8 rsvd2; -__u32 cdw14; -__u32 cdw15; -__u32 timeout_ms; -__u32 result; +__le32 cdw14; +__le32 cdw15; +__le32 timeout_ms; +__le32 result; };struct nvme_nvm_getbbtbl {__u8 opcode;__u8 flags; -__u16 rsvd1; -__u32 nsid; -__u32 cdw2; -__u32 cdw3; -__u64 metadata; +__le16 rsvd1; +__le32 nsid; +__le32 cdw2; +__le32 cdw3; +__le64 metadata;__u64 addr; -__u32 metadata_len; -__u32 data_len; -__u64 ppa; -__u32 cdw11; -__u32 cdw12; -__u32 cdw13; -__u32 cdw14; -__u32 cdw15; -__u32 timeout_ms; -__u32 result; +__le32 metadata_len; +__le32 data_len; +__le64 ppa; +__le32 cdw11; +__le32 cdw12; +__le32 cdw13; +__le32 cdw14; +__le32 cdw15; +__le32 timeout_ms; +__le32 result; };struct nvme_nvm_command {
@@ -91,16 +91,16 @@ struct nvme_nvm_command { };struct nvme_nvm_completion { -__u64 result;/* Used by LightNVM to return ppa completions */ -__u16 sq_head;/* how much of this queue may be reclaimed */ -__u16 sq_id;/* submission queue that generated this entry */ -__u16 command_id;/* of the command which completed */ -__u16 status;/* did the command fail, and if so, why? */ +__le64 result;/* Used by LightNVM to return ppa completions */ +__le16 sq_head;/* how much of this queue may be reclaimed */ +__le16 sq_id;/* submission queue that generated this entry */ +__le16 command_id;/* of the command which completed */ +__le16 status;/* did the command fail, and if so, why? */ };#define NVME_NVM_LP_MLC_PAIRS 886struct nvme_nvm_lp_mlc { -__u16 num_pairs; +__le16 num_pairs;__u8 pairs[NVME_NVM_LP_MLC_PAIRS ]; };
@@ -112,26 +112,26 @@ struct nvme_nvm_lp_tbl {struct nvme_nvm_id_group {__u8 mtype;__u8 fmtype; -__u16 res16; +__le16 res16;__u8 num_ch;__u8 num_lun;__u8 num_pln;__u8 rsvd1; -__u16 num_blk; -__u16 num_pg; -__u16 fpg_sz; -__u16 csecs; -__u16 sos; -__u16 rsvd2; -__u32 trdt; -__u32 trdm; -__u32 tprt; -__u32 tprm; -__u32 tbet; -__u32 tbem; -__u32 mpos; -__u32 mccap; -__u16 cpar; +__le16 num_blk; +__le16 num_pg; +__le16 fpg_sz; +__le16 csecs; +__le16 sos; +__le16 rsvd2; +__le32 trdt; +__le32 trdm; +__le32 tprt; +__le32 tprm; +__le32 tbet; +__le32 tbem; +__le32 mpos; +__le32 mccap; +__le16 cpar;__u8 reserved[10 ];struct nvme_nvm_lp_tbl lptbl; } __attribute__((packed));
@@ -157,8 +157,8 @@ struct nvme_nvm_id {__u8 vmnt;__u8 cgrps;__u8 res; -__u32 cap; -__u32 dom; +__le32 cap; +__le32 dom;struct nvme_nvm_addr_format ppaf;__u8 resv[228 ];struct nvme_nvm_id_group groups[4 ];
@@ -166,15 +166,15 @@ struct nvme_nvm_id {struct nvme_nvm_bb_tbl {__u8 tblid[4 ]; -__u16 verid; -__u16 revid; -__u32 rvsd1; -__u32 tblks; -__u32 tfact; -__u32 tgrown; -__u32 tdresv; -__u32 thresv; -__u32 rsvd2[8 ]; +__le16 verid; +__le16 revid; +__le32 rvsd1; +__le32 tblks; +__le32 tfact; +__le32 tgrown; +__le32 tdresv; +__le32 thresv; +__le32 rsvd2[8 ];__u8 blk[0 ]; };
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 9/18 fabrics: use correct endianess helper in print_discovery_log
In reply to Christoph Hellwig--- fabrics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fabrics.c +1 -1
@@ -362,7 +362,7 @@ static void print_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec)printf ("\nDiscovery Log Number of Records %d, " "Generation counter %" PRIu64"\n" , - numrec, (uint64_t )__le64_to_cpu (log->genctr)); + numrec, (uint64_t )le64_to_cpu (log->genctr));for (i =0 ; i < numrec; i++) {struct nvmf_disc_rsp_page_entry *e = &log->entries[i];
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 10/18 intel: use correct endianess helpers in show_temp_stats
In reply to Christoph Hellwig--- intel-nvme.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
intel-nvme.c +8 -8
@@ -129,14 +129,14 @@ static void show_temp_stats(struct intel_temp_stats *stats) {printf (" Intel Temperature Statistics\n" );printf ("--------------------------------\n" ); -printf ("Current temperature : %" PRIu64"\n" , (uint64_t )__le64_to_cpu (stats->curr)); -printf ("Last critical overtemp flag : %" PRIu64"\n" , (uint64_t )__le64_to_cpu (stats->last_overtemp)); -printf ("Life critical overtemp flag : %" PRIu64"\n" , (uint64_t )__le64_to_cpu (stats->life_overtemp)); -printf ("Highest temperature : %" PRIu64"\n" , (uint64_t )__le64_to_cpu (stats->highest_temp)); -printf ("Lowest temperature : %" PRIu64"\n" , (uint64_t )__le64_to_cpu (stats->lowest_temp)); -printf ("Max operating temperature : %" PRIu64"\n" , (uint64_t )__le64_to_cpu (stats->max_operating_temp)); -printf ("Min operating temperature : %" PRIu64"\n" , (uint64_t )__le64_to_cpu (stats->min_operating_temp)); -printf ("Estimated offset : %" PRIu64"\n" , (uint64_t )__le64_to_cpu (stats->est_offset)); +printf ("Current temperature : %" PRIu64"\n" , (uint64_t )le64_to_cpu (stats->curr)); +printf ("Last critical overtemp flag : %" PRIu64"\n" , (uint64_t )le64_to_cpu (stats->last_overtemp)); +printf ("Life critical overtemp flag : %" PRIu64"\n" , (uint64_t )le64_to_cpu (stats->life_overtemp)); +printf ("Highest temperature : %" PRIu64"\n" , (uint64_t )le64_to_cpu (stats->highest_temp)); +printf ("Lowest temperature : %" PRIu64"\n" , (uint64_t )le64_to_cpu (stats->lowest_temp)); +printf ("Max operating temperature : %" PRIu64"\n" , (uint64_t )le64_to_cpu (stats->max_operating_temp)); +printf ("Min operating temperature : %" PRIu64"\n" , (uint64_t )le64_to_cpu (stats->min_operating_temp)); +printf ("Estimated offset : %" PRIu64"\n" , (uint64_t )le64_to_cpu (stats->est_offset)); }static int get_temp_stats_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 11/18 fix num_ctrls endianess in nvme_ns_attachment
In reply to Christoph Hellwig--- nvme-ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
nvme-ioctl.c +2 -2
@@ -502,8 +502,8 @@ int nvme_ns_attachment(int fd, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist, };memset (buf,0 ,sizeof (buf)); - cntlist->num = num_ctrls; -for (i =0 ; i < cntlist->num; i++) + cntlist->num =cpu_to_le16 (num_ctrls); +for (i =0 ; i < num_ctrls; i++) cntlist->identifier[i] =cpu_to_le16 (ctrlist[i]);return nvme_submit_admin_passthru (fd, &cmd);
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 12/18 add missing endianess conversions in print_list_item
In reply to Christoph Hellwig--- nvme.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
nvme.c +2 -2
@@ -731,8 +731,8 @@ struct list_item {static void print_list_item (struct list_item list_item) { -double nsze = list_item.ns.nsze; -double nuse = list_item.ns.nuse; +double nsze =le64_to_cpu (list_item.ns.nsze); +double nuse =le64_to_cpu (list_item.ns.nuse);long long int lba = list_item.ns.lbaf[(list_item.ns.flbas &0x0f )].ds; lba = (1 << lba);
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 13/18 add missing endianess conversions in json_nvme_id_ns
In reply to Christoph Hellwig--- nvme-print.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
nvme-print.c +12 -12
@@ -1131,9 +1131,9 @@ void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode) root =json_create_object (); -json_object_add_value_int (root,"nsze" , ns->nsze); -json_object_add_value_int (root,"ncap" , ns->ncap); -json_object_add_value_int (root,"nuse" , ns->nuse); +json_object_add_value_int (root,"nsze" ,le64_to_cpu (ns->nsze)); +json_object_add_value_int (root,"ncap" ,le64_to_cpu (ns->ncap)); +json_object_add_value_int (root,"nuse" ,le64_to_cpu (ns->nuse));json_object_add_value_int (root,"nsfeat" , ns->nsfeat);json_object_add_value_int (root,"nlbaf" , ns->nlbaf);json_object_add_value_int (root,"flbas" , ns->flbas);
@@ -1143,12 +1143,12 @@ void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)json_object_add_value_int (root,"nmic" , ns->nmic);json_object_add_value_int (root,"rescap" , ns->rescap);json_object_add_value_int (root,"fpi" , ns->fpi); -json_object_add_value_int (root,"nawun" , ns->nawun); -json_object_add_value_int (root,"nawupf" , ns->nawupf); -json_object_add_value_int (root,"nacwu" , ns->nacwu); -json_object_add_value_int (root,"nabsn" , ns->nabsn); -json_object_add_value_int (root,"nabo" , ns->nabo); -json_object_add_value_int (root,"nabspf" , ns->nabspf); +json_object_add_value_int (root,"nawun" ,le16_to_cpu (ns->nawun)); +json_object_add_value_int (root,"nawupf" ,le16_to_cpu (ns->nawupf)); +json_object_add_value_int (root,"nacwu" ,le16_to_cpu (ns->nacwu)); +json_object_add_value_int (root,"nabsn" ,le16_to_cpu (ns->nabsn)); +json_object_add_value_int (root,"nabo" ,le16_to_cpu (ns->nabo)); +json_object_add_value_int (root,"nabspf" ,le16_to_cpu (ns->nabspf));json_object_add_value_float (root,"nvmcap" , nvmcap);memset (eui64,0 ,sizeof (eui64_buf));
@@ -1168,9 +1168,9 @@ void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)for (i =0 ; i <= ns->nlbaf; i++) {struct json_object *lbaf =json_create_object (); -json_object_add_value_int (lbaf,"ms" , ns->lbaf[i].ms); -json_object_add_value_int (lbaf,"ds" , ns->lbaf[i].ds); -json_object_add_value_int (lbaf,"rp" , ns->lbaf[i].rp); +json_object_add_value_int (lbaf,"ms" ,le16_to_cpu (ns->lbaf[i].ms)); +json_object_add_value_int (lbaf,"ds" ,le16_to_cpu (ns->lbaf[i].ds)); +json_object_add_value_int (lbaf,"rp" ,le16_to_cpu (ns->lbaf[i].rp));json_array_add_value_object (lbafs, lbaf); }
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 14/18 add missing endianess conversions in json_nvme_id_ctrl
In reply to Christoph Hellwig--- nvme-print.c | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-)
nvme-print.c +31 -26
@@ -1198,18 +1198,18 @@ void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode) root =json_create_object (); -json_object_add_value_int (root,"vid" , ctrl->vid); -json_object_add_value_int (root,"ssvid" , ctrl->ssvid); +json_object_add_value_int (root,"vid" ,le16_to_cpu (ctrl->vid)); +json_object_add_value_int (root,"ssvid" ,le16_to_cpu (ctrl->ssvid));json_object_add_value_int (root,"rab" , ctrl->rab);json_object_add_value_int (root,"ieee" , ieee);json_object_add_value_int (root,"cmic" , ctrl->cmic);json_object_add_value_int (root,"mdts" , ctrl->mdts); -json_object_add_value_int (root,"cntlid" , ctrl->cntlid); -json_object_add_value_int (root,"ver" , ctrl->ver); -json_object_add_value_int (root,"rtd3r" , ctrl->rtd3r); -json_object_add_value_int (root,"rtd3e" , ctrl->rtd3e); -json_object_add_value_int (root,"oaes" , ctrl->oaes); -json_object_add_value_int (root,"oacs" , ctrl->oacs); +json_object_add_value_int (root,"cntlid" ,le16_to_cpu (ctrl->cntlid)); +json_object_add_value_int (root,"ver" ,le32_to_cpu (ctrl->ver)); +json_object_add_value_int (root,"rtd3r" ,le32_to_cpu (ctrl->rtd3r)); +json_object_add_value_int (root,"rtd3e" ,le32_to_cpu (ctrl->rtd3e)); +json_object_add_value_int (root,"oaes" ,le32_to_cpu (ctrl->oaes)); +json_object_add_value_int (root,"oacs" ,le16_to_cpu (ctrl->oacs));json_object_add_value_int (root,"acl" , ctrl->acl);json_object_add_value_int (root,"aerl" , ctrl->aerl);json_object_add_value_int (root,"frmw" , ctrl->frmw);
@@ -1218,26 +1218,26 @@ void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode)json_object_add_value_int (root,"npss" , ctrl->npss);json_object_add_value_int (root,"avscc" , ctrl->avscc);json_object_add_value_int (root,"apsta" , ctrl->apsta); -json_object_add_value_int (root,"wctemp" , ctrl->wctemp); -json_object_add_value_int (root,"cctemp" , ctrl->cctemp); -json_object_add_value_int (root,"mtfa" , ctrl->mtfa); -json_object_add_value_int (root,"hmpre" , ctrl->hmpre); -json_object_add_value_int (root,"hmmin" , ctrl->hmmin); +json_object_add_value_int (root,"wctemp" ,le16_to_cpu (ctrl->wctemp)); +json_object_add_value_int (root,"cctemp" ,le16_to_cpu (ctrl->cctemp)); +json_object_add_value_int (root,"mtfa" ,le16_to_cpu (ctrl->mtfa)); +json_object_add_value_int (root,"hmpre" ,le32_to_cpu (ctrl->hmpre)); +json_object_add_value_int (root,"hmmin" ,le32_to_cpu (ctrl->hmmin));json_object_add_value_float (root,"tnvmcap" , tnvmcap);json_object_add_value_float (root,"unvmcap" , unvmcap); -json_object_add_value_int (root,"rpmbs" , ctrl->rpmbs); +json_object_add_value_int (root,"rpmbs" ,le32_to_cpu (ctrl->rpmbs));json_object_add_value_int (root,"sqes" , ctrl->sqes);json_object_add_value_int (root,"cqes" , ctrl->cqes); -json_object_add_value_int (root,"nn" , ctrl->nn); -json_object_add_value_int (root,"oncs" , ctrl->oncs); -json_object_add_value_int (root,"fuses" , ctrl->fuses); +json_object_add_value_int (root,"nn" ,le32_to_cpu (ctrl->nn)); +json_object_add_value_int (root,"oncs" ,le16_to_cpu (ctrl->oncs)); +json_object_add_value_int (root,"fuses" ,le16_to_cpu (ctrl->fuses));json_object_add_value_int (root,"fna" , ctrl->fna);json_object_add_value_int (root,"vwc" , ctrl->vwc); -json_object_add_value_int (root,"awun" , ctrl->awun); -json_object_add_value_int (root,"awupf" , ctrl->awupf); +json_object_add_value_int (root,"awun" ,le16_to_cpu (ctrl->awun)); +json_object_add_value_int (root,"awupf" ,le16_to_cpu (ctrl->awupf));json_object_add_value_int (root,"nvscc" , ctrl->nvscc); -json_object_add_value_int (root,"acwu" , ctrl->acwu); -json_object_add_value_int (root,"sgls" , ctrl->sgls); +json_object_add_value_int (root,"acwu" ,le16_to_cpu (ctrl->acwu)); +json_object_add_value_int (root,"sgls" ,le32_to_cpu (ctrl->sgls)); psds =json_create_array ();json_object_add_value_array (root,"psds" , psds);
@@ -1245,17 +1245,22 @@ void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode)for (i =0 ; i <= ctrl->npss; i++) {struct json_object *psd =json_create_object (); -json_object_add_value_int (psd,"max_power" , ctrl->psd[i].max_power); +json_object_add_value_int (psd,"max_power" , +le16_to_cpu (ctrl->psd[i].max_power));json_object_add_value_int (psd,"flags" , ctrl->psd[i].flags); -json_object_add_value_int (psd,"entry_lat" , ctrl->psd[i].entry_lat); -json_object_add_value_int (psd,"exit_lat" , ctrl->psd[i].exit_lat); +json_object_add_value_int (psd,"entry_lat" , +le32_to_cpu (ctrl->psd[i].entry_lat)); +json_object_add_value_int (psd,"exit_lat" , +le32_to_cpu (ctrl->psd[i].exit_lat));json_object_add_value_int (psd,"read_tput" , ctrl->psd[i].read_tput);json_object_add_value_int (psd,"read_lat" , ctrl->psd[i].read_lat);json_object_add_value_int (psd,"write_tput" , ctrl->psd[i].write_tput);json_object_add_value_int (psd,"write_lat" , ctrl->psd[i].write_lat); -json_object_add_value_int (psd,"idle_power" , ctrl->psd[i].idle_power); +json_object_add_value_int (psd,"idle_power" , +le16_to_cpu (ctrl->psd[i].idle_power));json_object_add_value_int (psd,"idle_scale" , ctrl->psd[i].idle_scale); -json_object_add_value_int (psd,"active_power" , ctrl->psd[i].active_power); +json_object_add_value_int (psd,"active_power" , +le16_to_cpu (ctrl->psd[i].active_power));json_object_add_value_int (psd,"active_work_scale" , ctrl->psd[i].active_work_scale);json_array_add_value_object (psds, psd);
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 15/18 add missing endianess conversions in json_smart_log
In reply to Christoph Hellwig--- nvme-print.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
nvme-print.c +4 -2
@@ -1395,8 +1395,10 @@ void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const charjson_object_add_value_float (root,"unsafe_shutdowns" , unsafe_shutdowns);json_object_add_value_float (root,"media_errors" , media_errors);json_object_add_value_float (root,"num_err_log_entries" , num_err_log_entries); -json_object_add_value_int (root,"warning_temp_time" , smart->warning_temp_time); -json_object_add_value_int (root,"critical_comp_time" , smart->critical_comp_time); +json_object_add_value_int (root,"warning_temp_time" , +le32_to_cpu (smart->warning_temp_time)); +json_object_add_value_int (root,"critical_comp_time" , +le32_to_cpu (smart->critical_comp_time));json_print_object (root,NULL );printf ("\n" );
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 16/18 add missing endianess conversions in __lnvm_do_get_bbtbl
In reply to Christoph Hellwig--- nvme-lightnvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
nvme-lightnvm.c +2 -2
@@ -338,9 +338,9 @@ static int __lnvm_do_get_bbtbl(int fd, struct nvme_nvm_id *id,struct nvme_nvm_getbbtbl cmd = { .opcode = nvme_nvm_admin_get_bb_tbl, - .nsid =1 , + .nsid =cpu_to_le32 (1 ), .addr = (__u64 )(uintptr_t )bbtbl, - .data_len = bufsz, + .data_len =cpu_to_le32 (bufsz), .ppa =cpu_to_le64 (ppa.ppa), };
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 17/18 add missing endianess conversions in __lnvm_do_set_bbtbl
In reply to Christoph Hellwig--- nvme-lightnvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
nvme-lightnvm.c +1 -1
@@ -398,7 +398,7 @@ static int __lnvm_do_set_bbtbl(int fd, struct ppa_addr ppa, __u8 value)struct nvme_nvm_setbbtbl cmd = { .opcode = nvme_nvm_admin_set_bb_tbl, - .nsid =1 , + .nsid =cpu_to_le32 (1 ), .ppa =cpu_to_le64 (ppa.ppa), .nlb =cpu_to_le16 (0 ), .value = value,
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 18/18 add missing endianess conversions in lnvm_do_set_bbtbl
In reply to Christoph Hellwig--- nvme-lightnvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
nvme-lightnvm.c +1 -1
@@ -432,7 +432,7 @@ int lnvm_do_set_bbtbl(int fd, int nsid,if (chid >= nvm_id.groups[0 ].num_ch || lunid >= nvm_id.groups[0 ].num_lun || plnid >= nvm_id.groups[0 ].num_pln || - blkid >= nvm_id.groups[0 ].num_blk) { + blkid >=le16_to_cpu (nvm_id.groups[0 ].num_blk)) {fprintf (stderr,"Out of bound channel id, LUN id, plane id, or" \"block id\n" );return -EINVAL ;
Signature · 1 line
2.1.4
Quoted 14 lines · Christoph Hellwig
The intent of this series is to provide static type checking for the little endian NVMe data structures using the sparse tool, similar to the kernel.
To make my life easier I first converted nvme-cli to use a copy of the kernel
nvme.hheader that defines the NVMe data structures. The next set of patches fixes various issues found by sparse as-is, followed by adding support for checking the __le{16,32,64} annotations and using the kernel cpu_to_le*/le*_to_cpu helpers, as well as fixing up various missing endianess conversion uncovered by sparse.To use sparse make sure both sparse and the cgcc wrapper are installed and build nvme-cli using:
Quoted 8 lines
make CC=cgcc
At least with my version of sparse there are a few warnings left that aren't really nvme-clis faults during the build, and sparse will finally crash after compiling
nvme.cbecause it misparses the command line and tries to interpret argconfig.o as a source file. I'll plan to look into that on the sparse side and hope to be able to provide a fix for that issue to the sparse maintainers.
Thanks for all the fixes. I ran some sanity tests successfully, and have applied all the patches to master.
Sagi Grimberg
maintainerPATCH 1/18 import linux/nvme.h
In reply to Christoph HellwigSeries looks good,