* nvme-cli: add endianess annotations
@ 2016-09-23 3:22 Christoph Hellwig
2016-09-23 3:22 ` [PATCH 01/18] import linux/nvme.h Christoph Hellwig
` (18 more replies)
0 siblings, 19 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
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.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.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 01/18] import linux/nvme.h
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
@ 2016-09-23 3:22 ` Christoph Hellwig
2016-09-23 20:53 ` Sagi Grimberg
2016-09-23 3:22 ` [PATCH 02/18] fix linux/nvme.h for use with nvme-cli Christoph Hellwig
` (17 subsequent siblings)
18 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
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.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
linux/nvme.h | 965 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 965 insertions(+)
create mode 100644 linux/nvme.h
diff --git a/linux/nvme.h b/linux/nvme.h
new file mode 100644
index 0000000..7676557
--- /dev/null
+++ b/linux/nvme.h
@@ -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 */
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 02/18] fix linux/nvme.h for use with nvme-cli
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
2016-09-23 3:22 ` [PATCH 01/18] import linux/nvme.h Christoph Hellwig
@ 2016-09-23 3:22 ` Christoph Hellwig
2016-09-23 3:22 ` [PATCH 03/18] use nvme.h from Linux Christoph Hellwig
` (16 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
Rename a few fields or constants to be closer to the standards and a few more.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
linux/nvme.h | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/linux/nvme.h b/linux/nvme.h
index 7676557..c3ed1df 100644
--- a/linux/nvme.h
+++ b/linux/nvme.h
@@ -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,
};
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 03/18] use nvme.h from Linux
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
2016-09-23 3:22 ` [PATCH 01/18] import linux/nvme.h Christoph Hellwig
2016-09-23 3:22 ` [PATCH 02/18] fix linux/nvme.h for use with nvme-cli Christoph Hellwig
@ 2016-09-23 3:22 ` Christoph Hellwig
2016-09-23 3:22 ` [PATCH 04/18] dynamically allocate log page buffers Christoph Hellwig
` (15 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
We still need various defintions of our own, but this cuts down the number
significantly.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme.h | 471 +----------------------------------------------------------------
1 file changed, 3 insertions(+), 468 deletions(-)
diff --git a/nvme.h b/nvme.h
index e9e4433..76b7576 100644
--- a/nvme.h
+++ b/nvme.h
@@ -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"
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 04/18] dynamically allocate log page buffers
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (2 preceding siblings ...)
2016-09-23 3:22 ` [PATCH 03/18] use nvme.h from Linux Christoph Hellwig
@ 2016-09-23 3:22 ` Christoph Hellwig
2016-09-23 3:22 ` [PATCH 05/18] use abort() instead of __builtin_abort Christoph Hellwig
` (14 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
A device can report large logs. Better dynamically allocate the buffer we
pass to the kernel instead of doing a gigantic stack allocation.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/nvme.c b/nvme.c
index e7b50b8..dac9d7d 100644
--- a/nvme.c
+++ b/nvme.c
@@ -299,7 +299,13 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug
fprintf(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 plug
else 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 *pl
fprintf(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;
}
}
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 05/18] use abort() instead of __builtin_abort
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (3 preceding siblings ...)
2016-09-23 3:22 ` [PATCH 04/18] dynamically allocate log page buffers Christoph Hellwig
@ 2016-09-23 3:22 ` Christoph Hellwig
2016-09-23 3:22 ` [PATCH 06/18] various trivial sparse fixes Christoph Hellwig
` (13 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
This is more portable to different compilers, but should otherwise have
the same effect.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
json.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/json.c b/json.c
index e9fcf07..e127aa2 100644
--- a/json.c
+++ b/json.c
@@ -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)
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 06/18] various trivial sparse fixes
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (4 preceding siblings ...)
2016-09-23 3:22 ` [PATCH 05/18] use abort() instead of __builtin_abort Christoph Hellwig
@ 2016-09-23 3:22 ` Christoph Hellwig
2016-09-23 3:22 ` [PATCH 07/18] add support for checking endianess annotations using sparse Christoph Hellwig
` (12 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
Use NULL instead of 0 for pointers, mark symbols static as needed
and provide proper ANSI C prototypes for all functions.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
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(-)
diff --git a/Makefile b/Makefile
index 39597dc..1d68d76 100644
--- a/Makefile
+++ b/Makefile
@@ -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 =
diff --git a/argconfig.c b/argconfig.c
index 41bb6d9..e2bb7ab 100644
--- a/argconfig.c
+++ b/argconfig.c
@@ -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;
diff --git a/cmd_handler.h b/cmd_handler.h
index e5979b0..b2e3e9d 100644
--- a/cmd_handler.h
+++ b/cmd_handler.h
@@ -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); \
}
diff --git a/fabrics.c b/fabrics.c
index dff5d6a..ad06392 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -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,
diff --git a/intel-nvme.c b/intel-nvme.c
index 31b664d..e824a2e 100644
--- a/intel-nvme.c
+++ b/intel-nvme.c
@@ -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 plu
const 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, struct
const 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, struct
const 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));
diff --git a/lnvm-nvme.c b/lnvm-nvme.c
index eabdf37..d12ac3e 100644
--- a/lnvm-nvme.c
+++ b/lnvm-nvme.c
@@ -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 pl
const 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));
diff --git a/memblaze-nvme.c b/memblaze-nvme.c
index 3dc8c03..50f11bd 100644
--- a/memblaze-nvme.c
+++ b/memblaze-nvme.c
@@ -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));
diff --git a/nvme-ioctl.c b/nvme-ioctl.c
index 188f080..f2c72f5 100644
--- a/nvme-ioctl.c
+++ b/nvme-ioctl.c
@@ -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);
}
diff --git a/nvme-lightnvm.c b/nvme-lightnvm.c
index 03fcd70..970976b 100644
--- a/nvme-lightnvm.c
+++ b/nvme-lightnvm.c
@@ -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,
diff --git a/nvme-print.c b/nvme-print.c
index 4d2c9b6..89413e0 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -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";
diff --git a/nvme-print.h b/nvme-print.h
index b62a241..eec3b05 100644
--- a/nvme-print.h
+++ b/nvme-print.h
@@ -37,13 +37,13 @@ void json_error_log(struct nvme_error_log_page *err_log, int entries, const char
void 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
diff --git a/nvme.c b/nvme.c
index dac9d7d..66ce668 100644
--- a/nvme.c
+++ b/nvme.c
@@ -138,7 +138,7 @@ int parse_and_open(int argc, char **argv, const char *desc,
return fd;
}
-const char *output_format = "Output format: normal|json|binary";
+static const char *output_format = "Output format: normal|json|binary";
enum {
NORMAL,
@@ -184,7 +184,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
{"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace},
{"output-format", 'o', "FMT", CFG_STRING, &cfg.output_format, required_argument, output_format },
{"raw-binary", 'b', "", CFG_NONE, &cfg.raw_binary, no_argument, raw},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -230,7 +230,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}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -277,7 +277,7 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug
{"log-entries", 'e', "NUM", CFG_POSITIVE, &cfg.log_entries, required_argument, log_entries},
{"raw-binary", 'b', "", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary},
{"output-format", 'o', "FMT", CFG_STRING, &cfg.output_format, required_argument, output_format },
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -344,7 +344,7 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin
const struct argconfig_commandline_options command_line_options[] = {
{"raw-binary", 'b', "", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary},
{"output-format", 'o', "FMT", CFG_STRING, &cfg.output_format, required_argument, output_format },
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -401,7 +401,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl
{"log-id", 'i', "NUM", CFG_POSITIVE, &cfg.log_id, required_argument, log_id},
{"log-len", 'l', "NUM", CFG_POSITIVE, &cfg.log_len, required_argument, log_len},
{"raw-binary", 'b', "", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -456,7 +456,7 @@ static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin *
const struct argconfig_commandline_options command_line_options[] = {
{"cntid", 'c', "NUM", CFG_SHORT, &cfg.cntid, required_argument, controller},
{"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -498,7 +498,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl
const struct argconfig_commandline_options command_line_options[] = {
{"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id},
{"all", 'a', "", CFG_NONE, &cfg.all, no_argument, all},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -536,7 +536,7 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *
const struct argconfig_commandline_options command_line_options[] = {
{"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -579,7 +579,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s
const struct argconfig_commandline_options command_line_options[] = {
{"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id},
{"controllers", 'c', "LIST", CFG_STRING, &cfg.cntlist, required_argument, cont},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -662,7 +662,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
{"flbas", 'f', "NUM", CFG_BYTE, &cfg.flbas, required_argument, flbas},
{"dps", 'd', "NUM", CFG_BYTE, &cfg.dps, required_argument, dps},
{"nmic", 'm', "NUM", CFG_BYTE, &cfg.nmic, required_argument, nmic},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -711,7 +711,7 @@ static void get_registers(struct nvme_bar **bar)
exit(ENODEV);
}
- membase = mmap(0, getpagesize(), PROT_READ, MAP_SHARED, pci_fd, 0);
+ membase = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, pci_fd, 0);
if (membase == MAP_FAILED) {
fprintf(stderr, "%s failed to map\n", base);
exit(ENODEV);
@@ -845,7 +845,7 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
return 0;
}
-static int get_nsid()
+static int get_nsid(void)
{
int nsid = nvme_get_nsid(fd);
@@ -888,7 +888,7 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin,
{"raw-binary", 'b', "", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary},
{"human-readable", 'H', "", CFG_NONE, &cfg.human_readable, no_argument, human_readable},
{"output-format", 'o', "FMT", CFG_STRING, &cfg.output_format, required_argument, output_format },
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -963,7 +963,7 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug
{"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},
{"output-format", 'o', "FMT", CFG_STRING, &cfg.output_format, required_argument, output_format },
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1060,7 +1060,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct plugin
{"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}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1154,7 +1154,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin
{"fw", 'f', "FILE", CFG_STRING, &cfg.fw, required_argument, fw},
{"xfer", 'x', "NUM", CFG_POSITIVE, &cfg.xfer, required_argument, xfer},
{"offset", 'o', "NUM", CFG_POSITIVE, &cfg.offset, required_argument, offset},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1240,7 +1240,7 @@ static int fw_activate(int argc, char **argv, struct command *cmd, struct plugin
const struct argconfig_commandline_options command_line_options[] = {
{"slot", 's', "NUM", CFG_BYTE, &cfg.slot, required_argument, slot},
{"action", 'a', "NUM", CFG_BYTE, &cfg.action, required_argument, action},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1330,7 +1330,7 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu
const struct argconfig_commandline_options command_line_options[] = {
{"human-readable", 'H', "", CFG_NONE, &cfg.human_readable, no_argument, human_readable},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1340,7 +1340,7 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu
if (cfg.human_readable) {
printf("cap : ");
print_lo_hi_64((uint32_t *)&bar->cap);
- show_registers_cap(&bar->cap);
+ show_registers_cap((struct nvme_bar_cap *)&bar->cap);
printf("version : %x\n", bar->vs);
show_registers_version(bar->vs);
@@ -1450,7 +1450,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
{"pil", 'p', "NUM", CFG_BYTE, &cfg.pil, required_argument, pil},
{"ms", 'm', "NUM", CFG_BYTE, &cfg.ms, required_argument, ms},
{"reset", 'r', "FLAG", CFG_NONE, &cfg.reset, no_argument, reset},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1542,7 +1542,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
{"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}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1640,7 +1640,7 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p
{"secp", 'p', "NUM", CFG_BYTE, &cfg.secp, required_argument, secp},
{"spsp", 's', "NUM", CFG_SHORT, &cfg.spsp, required_argument, spsp},
{"tl", 't', "NUM", CFG_POSITIVE, &cfg.tl, required_argument, tl},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1699,7 +1699,7 @@ static int write_uncor(int argc, char **argv, struct command *cmd, struct plugin
{"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id},
{"start-block", 's', "NUM", CFG_LONG_SUFFIX, &cfg.start_block, required_argument, start_block},
{"block-count", 'c', "NUM", CFG_SHORT, &cfg.block_count, required_argument, block_count},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1766,7 +1766,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
{"ref-tag", 'r', "NUM", CFG_POSITIVE, &cfg.ref_tag, required_argument, ref_tag},
{"app-tag-mask", 'm', "NUM", CFG_BYTE, &cfg.app_tag_mask, required_argument, app_tag_mask},
{"app-tag", 'a', "NUM", CFG_POSITIVE, &cfg.app_tag, required_argument, app_tag},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1847,7 +1847,7 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin
{"idw", 'w', "FLAG", CFG_NONE, &cfg.idw, no_argument, idw},
{"idr", 'r', "FLAG", CFG_NONE, &cfg.idr, no_argument, idr},
{"cdw11", 'c', "NUM", CFG_POSITIVE, &cfg.cdw11, required_argument, cdw11},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1900,7 +1900,7 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plug
const struct argconfig_commandline_options command_line_options[] = {
{"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -1956,7 +1956,7 @@ static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugi
{"rtype", 't', "NUM", CFG_BYTE, &cfg.rtype, required_argument, rtype},
{"racqa", 'a', "NUM", CFG_BYTE, &cfg.racqa, required_argument, racqa},
{"iekey", 'i', "", CFG_NONE, &cfg.iekey, no_argument, iekey},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -2016,7 +2016,7 @@ static int resv_register(int argc, char **argv, struct command *cmd, struct plug
{"rrega", 'r', "NUM", CFG_BYTE, &cfg.rrega, required_argument, rrega},
{"cptpl", 'p', "NUM", CFG_BYTE, &cfg.cptpl, required_argument, cptpl},
{"iekey", 'i', "", CFG_NONE, &cfg.iekey, no_argument, iekey},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -2078,7 +2078,7 @@ static int resv_release(int argc, char **argv, struct command *cmd, struct plugi
{"rtype", 't', "NUM", CFG_BYTE, &cfg.rtype, required_argument, rtype},
{"rrela", 'a', "NUM", CFG_BYTE, &cfg.rrela, required_argument, rrela},
{"iekey", 'i', "NUM", CFG_BYTE, &cfg.iekey, required_argument, iekey},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -2137,7 +2137,7 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct plugin
{"numd", 'd', "NUM", CFG_POSITIVE, &cfg.numd, required_argument, numd},
{"raw-binary", 'b', "", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary},
{"output-format", 'o', "FMT", CFG_STRING, &cfg.output_format, required_argument, output_format },
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -2252,7 +2252,7 @@ static int submit_io(int opcode, char *command, const char *desc,
{"show-command", 'v', "", CFG_NONE, &cfg.show, no_argument, show},
{"dry-run", 'w', "", CFG_NONE, &cfg.dry_run, no_argument, dry},
{"latency", 't', "", CFG_NONE, &cfg.latency, no_argument, latency},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -2437,7 +2437,7 @@ static int sec_recv(int argc, char **argv, struct command *cmd, struct plugin *p
{"spsp", 's', "NUM", CFG_SHORT, &cfg.spsp, required_argument, spsp},
{"al", 't', "NUM", CFG_POSITIVE, &cfg.al, required_argument, al},
{"raw-binary", 'b', "", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
@@ -2565,7 +2565,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
{"dry-run", 'd', "", CFG_NONE, &cfg.dry_run, no_argument, dry},
{"read", 'r', "", CFG_NONE, &cfg.read, no_argument, re},
{"write", 'w', "", CFG_NONE, &cfg.write, no_argument, wr},
- {0}
+ {NULL}
};
parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 07/18] add support for checking endianess annotations using sparse
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (5 preceding siblings ...)
2016-09-23 3:22 ` [PATCH 06/18] various trivial sparse fixes Christoph Hellwig
@ 2016-09-23 3:22 ` Christoph Hellwig
2016-09-23 3:22 ` [PATCH 08/18] add missing endianess annoations for lightnvm data structures Christoph Hellwig
` (11 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
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(-)
diff --git a/fabrics.c b/fabrics.c
index ad06392..935f2d0 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -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;
}
diff --git a/memblaze-nvme.c b/memblaze-nvme.c
index 50f11bd..0f73e81 100644
--- a/memblaze-nvme.c
+++ b/memblaze-nvme.c
@@ -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;
}
diff --git a/nvme-ioctl.c b/nvme-ioctl.c
index f2c72f5..db9c332 100644
--- a/nvme-ioctl.c
+++ b/nvme-ioctl.c
@@ -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);
}
diff --git a/nvme-lightnvm.c b/nvme-lightnvm.c
index 970976b..ddb8a3e 100644
--- a/nvme-lightnvm.c
+++ b/nvme-lightnvm.c
@@ -224,20 +224,20 @@ static void show_lnvm_id_grp(struct nvme_nvm_id_group *grp)
printf(" chnls : %d\n", grp->num_ch);
printf(" luns : %d\n", grp->num_lun);
printf(" plns : %d\n", grp->num_pln);
- printf(" blks : %d\n", (uint16_t)le16toh(grp->num_blk));
- printf(" pgs : %d\n", (uint16_t)le16toh(grp->num_pg));
- printf(" fpg_sz : %d\n", (uint16_t)le16toh(grp->fpg_sz));
- printf(" csecs : %d\n", (uint16_t)le16toh(grp->csecs));
- printf(" sos : %d\n", (uint16_t)le16toh(grp->sos));
- printf(" trdt : %d\n", (uint32_t)le32toh(grp->trdt));
- printf(" trdm : %d\n", (uint32_t)le32toh(grp->trdm));
- printf(" tprt : %d\n", (uint32_t)le32toh(grp->tprt));
- printf(" tprm : %d\n", (uint32_t)le32toh(grp->tprm));
- printf(" tbet : %d\n", (uint32_t)le32toh(grp->tbet));
- printf(" tbem : %d\n", (uint32_t)le32toh(grp->tbem));
- printf(" mpos : %#x\n", (uint32_t)le32toh(grp->mpos));
- printf(" mccap : %#x\n", (uint32_t)le32toh(grp->mccap));
- printf(" cpar : %#x\n", (uint16_t)le16toh(grp->cpar));
+ printf(" blks : %d\n", (uint16_t)le16_to_cpu(grp->num_blk));
+ printf(" pgs : %d\n", (uint16_t)le16_to_cpu(grp->num_pg));
+ printf(" fpg_sz : %d\n", (uint16_t)le16_to_cpu(grp->fpg_sz));
+ printf(" csecs : %d\n", (uint16_t)le16_to_cpu(grp->csecs));
+ printf(" sos : %d\n", (uint16_t)le16_to_cpu(grp->sos));
+ printf(" trdt : %d\n", (uint32_t)le32_to_cpu(grp->trdt));
+ printf(" trdm : %d\n", (uint32_t)le32_to_cpu(grp->trdm));
+ printf(" tprt : %d\n", (uint32_t)le32_to_cpu(grp->tprt));
+ printf(" tprm : %d\n", (uint32_t)le32_to_cpu(grp->tprm));
+ printf(" tbet : %d\n", (uint32_t)le32_to_cpu(grp->tbet));
+ printf(" tbem : %d\n", (uint32_t)le32_to_cpu(grp->tbem));
+ printf(" mpos : %#x\n", (uint32_t)le32_to_cpu(grp->mpos));
+ printf(" mccap : %#x\n", (uint32_t)le32_to_cpu(grp->mccap));
+ printf(" cpar : %#x\n", (uint16_t)le16_to_cpu(grp->cpar));
}
static void show_lnvm_ppaf(struct nvme_nvm_addr_format *ppaf)
@@ -269,8 +269,8 @@ static void show_lnvm_id_ns(struct nvme_nvm_id *id)
printf("verid : %#x\n", id->ver_id);
printf("vmnt : %#x\n", id->vmnt);
printf("cgrps : %d\n", id->cgrps);
- printf("cap : %#x\n", (uint32_t)le32toh(id->cap));
- printf("dom : %#x\n", (uint32_t)le32toh(id->dom));
+ printf("cap : %#x\n", (uint32_t)le32_to_cpu(id->cap));
+ printf("dom : %#x\n", (uint32_t)le32_to_cpu(id->dom));
show_lnvm_ppaf(&id->ppaf);
for (i = 0; i < id->cgrps; i++) {
@@ -313,12 +313,12 @@ int lnvm_do_id_ns(int fd, int nsid, unsigned int flags)
static void show_lnvm_bbtbl(struct nvme_nvm_bb_tbl *tbl)
{
- printf("verid : %#x\n", (uint16_t)le16toh(tbl->verid));
- printf("tblks : %d\n", (uint32_t)le32toh(tbl->tblks));
- printf("tfact : %d\n", (uint32_t)le32toh(tbl->tfact));
- printf("tgrown : %d\n", (uint32_t)le32toh(tbl->tgrown));
- printf("tdresv : %d\n", (uint32_t)le32toh(tbl->tdresv));
- printf("thresv : %d\n", (uint32_t)le32toh(tbl->thresv));
+ printf("verid : %#x\n", (uint16_t)le16_to_cpu(tbl->verid));
+ printf("tblks : %d\n", (uint32_t)le32_to_cpu(tbl->tblks));
+ printf("tfact : %d\n", (uint32_t)le32_to_cpu(tbl->tfact));
+ printf("tgrown : %d\n", (uint32_t)le32_to_cpu(tbl->tgrown));
+ printf("tdresv : %d\n", (uint32_t)le32_to_cpu(tbl->tdresv));
+ printf("thresv : %d\n", (uint32_t)le32_to_cpu(tbl->thresv));
printf("Use raw output to retrieve table.\n");
}
@@ -327,7 +327,7 @@ static int __lnvm_do_get_bbtbl(int fd, struct nvme_nvm_id *id,
unsigned int flags)
{
struct nvme_nvm_id_group *grp = &id->groups[0];
- int bbtblsz = ((uint16_t)le16toh(grp->num_blk) * grp->num_pln);
+ int bbtblsz = ((uint16_t)le16_to_cpu(grp->num_blk) * grp->num_pln);
int bufsz = bbtblsz + sizeof(struct nvme_nvm_bb_tbl);
struct nvme_nvm_bb_tbl *bbtbl;
int err;
@@ -341,7 +341,7 @@ static int __lnvm_do_get_bbtbl(int fd, struct nvme_nvm_id *id,
.nsid = 1,
.addr = (__u64)(uintptr_t)bbtbl,
.data_len = bufsz,
- .ppa = htole64(ppa.ppa),
+ .ppa = cpu_to_le64(ppa.ppa),
};
err = nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD,
@@ -399,8 +399,8 @@ 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,
- .ppa = htole64(ppa.ppa),
- .nlb = htole16(0),
+ .ppa = cpu_to_le64(ppa.ppa),
+ .nlb = cpu_to_le16(0),
.value = value,
};
diff --git a/nvme-print.c b/nvme-print.c
index 89413e0..95afdf9 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -76,7 +76,7 @@ static void show_nvme_id_ctrl_cmic(__u8 cmic)
static void show_nvme_id_ctrl_oaes(__le32 ctrl_oaes)
{
- __u32 oaes = le32toh(ctrl_oaes);
+ __u32 oaes = le32_to_cpu(ctrl_oaes);
__u32 rsvd0 = (oaes & 0xFFFFFE00) >> 9;
__u32 nace = (oaes & 0x100) >> 8;
__u32 rsvd1 = oaes & 0xFF;
@@ -92,7 +92,7 @@ static void show_nvme_id_ctrl_oaes(__le32 ctrl_oaes)
static void show_nvme_id_ctrl_oacs(__le16 ctrl_oacs)
{
- __u16 oacs = le16toh(ctrl_oacs);
+ __u16 oacs = le16_to_cpu(ctrl_oacs);
__u16 rsvd = (oacs & 0xFFF0) >> 4;
__u16 nsm = (oacs & 0x8) >> 3;
__u16 fwc = (oacs & 0x4) >> 2;
@@ -166,7 +166,7 @@ static void show_nvme_id_ctrl_apsta(__u8 apsta)
static void show_nvme_id_ctrl_rpmbs(__le32 ctrl_rpmbs)
{
- __u32 rpmbs = le32toh(ctrl_rpmbs);
+ __u32 rpmbs = le32_to_cpu(ctrl_rpmbs);
__u32 asz = (rpmbs & 0xFF000000) >> 24;
__u32 tsz = (rpmbs & 0xFF0000) >> 16;
__u32 rsvd = (rpmbs & 0xFFC0) >> 6;
@@ -202,7 +202,7 @@ static void show_nvme_id_ctrl_cqes(__u8 cqes)
static void show_nvme_id_ctrl_oncs(__le16 ctrl_oncs)
{
- __u16 oncs = le16toh(ctrl_oncs);
+ __u16 oncs = le16_to_cpu(ctrl_oncs);
__u16 rsvd = (oncs & 0xFFC0) >> 6;
__u16 resv = (oncs & 0x20) >> 5;
__u16 save = (oncs & 0x10) >> 4;
@@ -230,7 +230,7 @@ static void show_nvme_id_ctrl_oncs(__le16 ctrl_oncs)
static void show_nvme_id_ctrl_fuses(__le16 ctrl_fuses)
{
- __u16 fuses = le16toh(ctrl_fuses);
+ __u16 fuses = le16_to_cpu(ctrl_fuses);
__u16 rsvd = (fuses & 0xFE) >> 1;
__u16 cmpw = fuses & 0x1;
@@ -282,7 +282,7 @@ static void show_nvme_id_ctrl_nvscc(__u8 nvscc)
static void show_nvme_id_ctrl_sgls(__le32 ctrl_sgls)
{
- __u32 sgls = le32toh(ctrl_sgls);
+ __u32 sgls = le32_to_cpu(ctrl_sgls);
__u32 rsvd0 = (sgls & 0xFFF80000) >> 19;
__u32 sglltb = (sgls & 0x40000) >> 18;
__u32 bacmdb = (sgls & 0x20000) >> 17;
@@ -450,9 +450,9 @@ void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
int human = mode&HUMAN,
vs = mode&VS;
- printf("nsze : %#"PRIx64"\n", (uint64_t)le64toh(ns->nsze));
- printf("ncap : %#"PRIx64"\n", (uint64_t)le64toh(ns->ncap));
- printf("nuse : %#"PRIx64"\n", (uint64_t)le64toh(ns->nuse));
+ printf("nsze : %#"PRIx64"\n", (uint64_t)le64_to_cpu(ns->nsze));
+ printf("ncap : %#"PRIx64"\n", (uint64_t)le64_to_cpu(ns->ncap));
+ printf("nuse : %#"PRIx64"\n", (uint64_t)le64_to_cpu(ns->nuse));
printf("nsfeat : %#x\n", ns->nsfeat);
if (human)
show_nvme_id_ns_nsfeat(ns->nsfeat);
@@ -478,12 +478,12 @@ void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
printf("fpi : %#x\n", ns->fpi);
if (human)
show_nvme_id_ns_fpi(ns->fpi);
- printf("nawun : %d\n", le16toh(ns->nawun));
- printf("nawupf : %d\n", le16toh(ns->nawupf));
- printf("nacwu : %d\n", le16toh(ns->nacwu));
- printf("nabsn : %d\n", le16toh(ns->nabsn));
- printf("nabo : %d\n", le16toh(ns->nabo));
- printf("nabspf : %d\n", le16toh(ns->nabspf));
+ printf("nawun : %d\n", le16_to_cpu(ns->nawun));
+ printf("nawupf : %d\n", le16_to_cpu(ns->nawupf));
+ printf("nacwu : %d\n", le16_to_cpu(ns->nacwu));
+ printf("nabsn : %d\n", le16_to_cpu(ns->nabsn));
+ printf("nabo : %d\n", le16_to_cpu(ns->nabo));
+ printf("nabspf : %d\n", le16_to_cpu(ns->nabspf));
printf("nvmcap : %.0Lf\n", int128_to_double(ns->nvmcap));
printf("nguid : ");
@@ -500,14 +500,14 @@ void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
if (human)
printf("LBA Format %2d : Metadata Size: %-3d bytes - "
"Data Size: %-2d bytes - Relative Performance: %#x %s %s\n", i,
- le16toh(ns->lbaf[i].ms), 1 << ns->lbaf[i].ds, ns->lbaf[i].rp,
+ le16_to_cpu(ns->lbaf[i].ms), 1 << ns->lbaf[i].ds, ns->lbaf[i].rp,
ns->lbaf[i].rp == 3 ? "Degraded" :
ns->lbaf[i].rp == 2 ? "Good" :
ns->lbaf[i].rp == 1 ? "Better" : "Best",
i == (ns->flbas & 0xf) ? "(in use)" : "");
else
printf("lbaf %2d : ms:%-3d lbads:%-2d rp:%#x %s\n", i,
- le16toh(ns->lbaf[i].ms), ns->lbaf[i].ds, ns->lbaf[i].rp,
+ le16_to_cpu(ns->lbaf[i].ms), ns->lbaf[i].ds, ns->lbaf[i].rp,
i == (ns->flbas & 0xf) ? "(in use)" : "");
}
if (vs) {
@@ -518,7 +518,7 @@ void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
static void print_ps_power_and_scale(__le16 ctr_power, __u8 scale)
{
- __u16 power = le16toh(ctr_power);
+ __u16 power = le16_to_cpu(ctr_power);
switch (scale & 0x3) {
case 0:
@@ -547,7 +547,7 @@ static void show_nvme_id_ctrl_power(struct nvme_id_ctrl *ctrl)
for (i = 0; i <= ctrl->npss; i++) {
- __u16 max_power = le16toh(ctrl->psd[i].max_power);
+ __u16 max_power = le16_to_cpu(ctrl->psd[i].max_power);
printf("ps %4d : mp:", i);
@@ -561,7 +561,7 @@ static void show_nvme_id_ctrl_power(struct nvme_id_ctrl *ctrl)
printf("operational enlat:%d exlat:%d rrt:%d rrl:%d\n"
" rwt:%d rwl:%d idle_power:",
- le32toh(ctrl->psd[i].entry_lat), le32toh(ctrl->psd[i].exit_lat),
+ le32_to_cpu(ctrl->psd[i].entry_lat), le32_to_cpu(ctrl->psd[i].exit_lat),
ctrl->psd[i].read_tput, ctrl->psd[i].read_lat,
ctrl->psd[i].write_tput, ctrl->psd[i].write_lat);
print_ps_power_and_scale(ctrl->psd[i].idle_power,
@@ -578,8 +578,8 @@ void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*ve
{
int human = mode & HUMAN, vs = mode & VS;
- printf("vid : %#x\n", le16toh(ctrl->vid));
- printf("ssvid : %#x\n", le16toh(ctrl->ssvid));
+ printf("vid : %#x\n", le16_to_cpu(ctrl->vid));
+ printf("ssvid : %#x\n", le16_to_cpu(ctrl->ssvid));
printf("sn : %-.*s\n", (int)sizeof(ctrl->sn), ctrl->sn);
printf("mn : %-.*s\n", (int)sizeof(ctrl->mn), ctrl->mn);
printf("fr : %-.*s\n", (int)sizeof(ctrl->fr), ctrl->fr);
@@ -590,14 +590,14 @@ void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*ve
if (human)
show_nvme_id_ctrl_cmic(ctrl->cmic);
printf("mdts : %d\n", ctrl->mdts);
- printf("cntlid : %x\n", le16toh(ctrl->cntlid));
- printf("ver : %x\n", le32toh(ctrl->ver));
- printf("rtd3r : %x\n", le32toh(ctrl->rtd3r));
- printf("rtd3e : %x\n", le32toh(ctrl->rtd3e));
- printf("oaes : %#x\n", le32toh(ctrl->oaes));
+ printf("cntlid : %x\n", le16_to_cpu(ctrl->cntlid));
+ printf("ver : %x\n", le32_to_cpu(ctrl->ver));
+ printf("rtd3r : %x\n", le32_to_cpu(ctrl->rtd3r));
+ printf("rtd3e : %x\n", le32_to_cpu(ctrl->rtd3e));
+ printf("oaes : %#x\n", le32_to_cpu(ctrl->oaes));
if (human)
show_nvme_id_ctrl_oaes(ctrl->oaes);
- printf("oacs : %#x\n", le16toh(ctrl->oacs));
+ printf("oacs : %#x\n", le16_to_cpu(ctrl->oacs));
if (human)
show_nvme_id_ctrl_oacs(ctrl->oacs);
printf("acl : %d\n", ctrl->acl);
@@ -616,14 +616,14 @@ void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*ve
printf("apsta : %#x\n", ctrl->apsta);
if (human)
show_nvme_id_ctrl_apsta(ctrl->apsta);
- printf("wctemp : %d\n", le16toh(ctrl->wctemp));
- printf("cctemp : %d\n", le16toh(ctrl->cctemp));
- printf("mtfa : %d\n", le16toh(ctrl->mtfa));
- printf("hmpre : %d\n", le32toh(ctrl->hmpre));
- printf("hmmin : %d\n", le32toh(ctrl->hmmin));
+ printf("wctemp : %d\n", le16_to_cpu(ctrl->wctemp));
+ printf("cctemp : %d\n", le16_to_cpu(ctrl->cctemp));
+ printf("mtfa : %d\n", le16_to_cpu(ctrl->mtfa));
+ printf("hmpre : %d\n", le32_to_cpu(ctrl->hmpre));
+ printf("hmmin : %d\n", le32_to_cpu(ctrl->hmmin));
printf("tnvmcap : %.0Lf\n", int128_to_double(ctrl->tnvmcap));
printf("unvmcap : %.0Lf\n", int128_to_double(ctrl->unvmcap));
- printf("rpmbs : %#x\n", le32toh(ctrl->rpmbs));
+ printf("rpmbs : %#x\n", le32_to_cpu(ctrl->rpmbs));
if (human)
show_nvme_id_ctrl_rpmbs(ctrl->rpmbs);
printf("sqes : %#x\n", ctrl->sqes);
@@ -632,11 +632,11 @@ void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*ve
printf("cqes : %#x\n", ctrl->cqes);
if (human)
show_nvme_id_ctrl_cqes(ctrl->cqes);
- printf("nn : %d\n", le32toh(ctrl->nn));
- printf("oncs : %#x\n", le16toh(ctrl->oncs));
+ printf("nn : %d\n", le32_to_cpu(ctrl->nn));
+ printf("oncs : %#x\n", le16_to_cpu(ctrl->oncs));
if (human)
show_nvme_id_ctrl_oncs(ctrl->oncs);
- printf("fuses : %#x\n", le16toh(ctrl->fuses));
+ printf("fuses : %#x\n", le16_to_cpu(ctrl->fuses));
if (human)
show_nvme_id_ctrl_fuses(ctrl->fuses);
printf("fna : %#x\n", ctrl->fna);
@@ -645,13 +645,13 @@ void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*ve
printf("vwc : %#x\n", ctrl->vwc);
if (human)
show_nvme_id_ctrl_vwc(ctrl->vwc);
- printf("awun : %d\n", le16toh(ctrl->awun));
- printf("awupf : %d\n", le16toh(ctrl->awupf));
+ printf("awun : %d\n", le16_to_cpu(ctrl->awun));
+ printf("awupf : %d\n", le16_to_cpu(ctrl->awupf));
printf("nvscc : %d\n", ctrl->nvscc);
if (human)
show_nvme_id_ctrl_nvscc(ctrl->nvscc);
- printf("acwu : %d\n", le16toh(ctrl->acwu));
- printf("sgls : %x\n", le32toh(ctrl->sgls));
+ printf("acwu : %d\n", le16_to_cpu(ctrl->acwu));
+ printf("sgls : %x\n", le32_to_cpu(ctrl->sgls));
if (human)
show_nvme_id_ctrl_sgls(ctrl->sgls);
@@ -679,13 +679,13 @@ void show_error_log(struct nvme_error_log_page *err_log, int entries, const char
for (i = 0; i < entries; i++) {
printf(" Entry[%2d] \n", i);
printf(".................\n");
- printf("error_count : %"PRIu64"\n", (uint64_t)le64toh(err_log[i].error_count));
+ printf("error_count : %"PRIu64"\n", (uint64_t)le64_to_cpu(err_log[i].error_count));
printf("sqid : %d\n", err_log[i].sqid);
printf("cmdid : %#x\n", err_log[i].cmdid);
printf("status_field : %#x(%s)\n", err_log[i].status_field,
nvme_status_to_string(err_log[i].status_field >> 1));
printf("parm_err_loc : %#x\n", err_log[i].parm_error_location);
- printf("lba : %#"PRIx64"\n",(uint64_t)le64toh(err_log[i].lba));
+ printf("lba : %#"PRIx64"\n",(uint64_t)le64_to_cpu(err_log[i].lba));
printf("nsid : %#x\n", err_log[i].nsid);
printf("vs : %d\n", err_log[i].vs);
printf(".................\n");
@@ -699,17 +699,17 @@ void show_nvme_resv_report(struct nvme_reservation_status *status)
regctl = status->regctl[0] | (status->regctl[1] << 8);
printf("\nNVME Reservation status:\n\n");
- printf("gen : %d\n", le32toh(status->gen));
+ printf("gen : %d\n", le32_to_cpu(status->gen));
printf("regctl : %d\n", regctl);
printf("rtype : %d\n", status->rtype);
printf("ptpls : %d\n", status->ptpls);
for (i = 0; i < regctl; i++) {
printf("regctl[%d] :\n", i);
- printf(" cntlid : %x\n", le16toh(status->regctl_ds[i].cntlid));
+ printf(" cntlid : %x\n", le16_to_cpu(status->regctl_ds[i].cntlid));
printf(" rcsts : %x\n", status->regctl_ds[i].rcsts);
- printf(" hostid : %"PRIx64"\n", (uint64_t)le64toh(status->regctl_ds[i].hostid));
- printf(" rkey : %"PRIx64"\n", (uint64_t)le64toh(status->regctl_ds[i].rkey));
+ printf(" hostid : %"PRIx64"\n", (uint64_t)le64_to_cpu(status->regctl_ds[i].hostid));
+ printf(" rkey : %"PRIx64"\n", (uint64_t)le64_to_cpu(status->regctl_ds[i].rkey));
}
printf("\n");
}
@@ -784,10 +784,10 @@ void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char
int128_to_double(smart->media_errors));
printf("num_err_log_entries : %'.0Lf\n",
int128_to_double(smart->num_err_log_entries));
- printf("Warning Temperature Time : %u\n", le32toh(smart->warning_temp_time));
- printf("Critical Composite Temperature Time : %u\n", le32toh(smart->critical_comp_time));
+ printf("Warning Temperature Time : %u\n", le32_to_cpu(smart->warning_temp_time));
+ printf("Critical Composite Temperature Time : %u\n", le32_to_cpu(smart->critical_comp_time));
for (c=0; c < 8; c++) {
- __u16 temp = le16toh(smart->temp_sensor[c]);
+ __u16 temp = le16_to_cpu(smart->temp_sensor[c]);
printf("Temperature Sensor %d : %u C\n", c + 1,
temp ? temp - 273 : 0);
}
@@ -805,9 +805,9 @@ void show_intel_smart_log(struct nvme_additional_smart_log *smart, unsigned int
int48_to_long(smart->erase_fail_cnt.raw));
printf("wear_leveling : %3d%% min: %u, max: %u, avg: %u\n",
smart->wear_leveling_cnt.norm,
- le16toh(smart->wear_leveling_cnt.wear_level.min),
- le16toh(smart->wear_leveling_cnt.wear_level.max),
- le16toh(smart->wear_leveling_cnt.wear_level.avg));
+ le16_to_cpu(smart->wear_leveling_cnt.wear_level.min),
+ le16_to_cpu(smart->wear_leveling_cnt.wear_level.max),
+ le16_to_cpu(smart->wear_leveling_cnt.wear_level.avg));
printf("end_to_end_error_detection_count: %3d%% %lu\n",
smart->e2e_err_cnt.norm,
int48_to_long(smart->e2e_err_cnt.raw));
@@ -1306,7 +1306,7 @@ void json_nvme_resv_report(struct nvme_reservation_status *status)
root = json_create_object();
- json_object_add_value_int(root, "gen", le32toh(status->gen));
+ json_object_add_value_int(root, "gen", le32_to_cpu(status->gen));
json_object_add_value_int(root, "regctl", regctl);
json_object_add_value_int(root, "rtype", status->rtype);
json_object_add_value_int(root, "ptpls", status->ptpls);
@@ -1317,10 +1317,10 @@ void json_nvme_resv_report(struct nvme_reservation_status *status)
for (i = 0; i < regctl; i++) {
struct json_object *rc = json_create_object();
- json_object_add_value_int(rc, "cntlid", le16toh(status->regctl_ds[i].cntlid));
+ json_object_add_value_int(rc, "cntlid", le16_to_cpu(status->regctl_ds[i].cntlid));
json_object_add_value_int(rc, "rcsts", status->regctl_ds[i].rcsts);
- json_object_add_value_int(rc, "hostid", (uint64_t)le64toh(status->regctl_ds[i].hostid));
- json_object_add_value_int(rc, "rkey", (uint64_t)le64toh(status->regctl_ds[i].rkey));
+ json_object_add_value_int(rc, "hostid", (uint64_t)le64_to_cpu(status->regctl_ds[i].hostid));
+ json_object_add_value_int(rc, "rkey", (uint64_t)le64_to_cpu(status->regctl_ds[i].rkey));
json_array_add_value_object(rcs, rc);
}
diff --git a/nvme.c b/nvme.c
index 66ce668..f263e50 100644
--- a/nvme.c
+++ b/nvme.c
@@ -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",
diff --git a/nvme.h b/nvme.h
index 76b7576..2250e56 100644
--- a/nvme.h
+++ b/nvme.h
@@ -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"
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 08/18] add missing endianess annoations for lightnvm data structures
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (6 preceding siblings ...)
2016-09-23 3:22 ` [PATCH 07/18] add support for checking endianess annotations using sparse Christoph Hellwig
@ 2016-09-23 3:22 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 09/18] fabrics: use correct endianess helper in print_discovery_log Christoph Hellwig
` (10 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:22 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme-lightnvm.h | 136 ++++++++++++++++++++++++++++----------------------------
1 file changed, 68 insertions(+), 68 deletions(-)
diff --git a/nvme-lightnvm.h b/nvme-lightnvm.h
index 78b9f8a..19a2202 100644
--- a/nvme-lightnvm.h
+++ b/nvme-lightnvm.h
@@ -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 886
struct 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];
};
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 09/18] fabrics: use correct endianess helper in print_discovery_log
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (7 preceding siblings ...)
2016-09-23 3:22 ` [PATCH 08/18] add missing endianess annoations for lightnvm data structures Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 10/18] intel: use correct endianess helpers in show_temp_stats Christoph Hellwig
` (9 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
fabrics.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fabrics.c b/fabrics.c
index 935f2d0..b8068ba 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -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];
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 10/18] intel: use correct endianess helpers in show_temp_stats
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (8 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 09/18] fabrics: use correct endianess helper in print_discovery_log Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 11/18] fix num_ctrls endianess in nvme_ns_attachment Christoph Hellwig
` (8 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
intel-nvme.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/intel-nvme.c b/intel-nvme.c
index e824a2e..a8a5041 100644
--- a/intel-nvme.c
+++ b/intel-nvme.c
@@ -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)
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 11/18] fix num_ctrls endianess in nvme_ns_attachment
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (9 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 10/18] intel: use correct endianess helpers in show_temp_stats Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 12/18] add missing endianess conversions in print_list_item Christoph Hellwig
` (7 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme-ioctl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/nvme-ioctl.c b/nvme-ioctl.c
index db9c332..9df04ae 100644
--- a/nvme-ioctl.c
+++ b/nvme-ioctl.c
@@ -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);
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 12/18] add missing endianess conversions in print_list_item
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (10 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 11/18] fix num_ctrls endianess in nvme_ns_attachment Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 13/18] add missing endianess conversions in json_nvme_id_ns Christoph Hellwig
` (6 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/nvme.c b/nvme.c
index f263e50..ab782d0 100644
--- a/nvme.c
+++ b/nvme.c
@@ -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);
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 13/18] add missing endianess conversions in json_nvme_id_ns
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (11 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 12/18] add missing endianess conversions in print_list_item Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 14/18] add missing endianess conversions in json_nvme_id_ctrl Christoph Hellwig
` (5 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme-print.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/nvme-print.c b/nvme-print.c
index 95afdf9..5320951 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -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);
}
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 14/18] add missing endianess conversions in json_nvme_id_ctrl
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (12 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 13/18] add missing endianess conversions in json_nvme_id_ns Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 15/18] add missing endianess conversions in json_smart_log Christoph Hellwig
` (4 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme-print.c | 57 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 31 insertions(+), 26 deletions(-)
diff --git a/nvme-print.c b/nvme-print.c
index 5320951..f9a8ff6 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -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);
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 15/18] add missing endianess conversions in json_smart_log
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (13 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 14/18] add missing endianess conversions in json_nvme_id_ctrl Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 16/18] add missing endianess conversions in __lnvm_do_get_bbtbl Christoph Hellwig
` (3 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme-print.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/nvme-print.c b/nvme-print.c
index f9a8ff6..ac56fce 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -1395,8 +1395,10 @@ void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char
json_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");
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 16/18] add missing endianess conversions in __lnvm_do_get_bbtbl
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (14 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 15/18] add missing endianess conversions in json_smart_log Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 17/18] add missing endianess conversions in __lnvm_do_set_bbtbl Christoph Hellwig
` (2 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme-lightnvm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/nvme-lightnvm.c b/nvme-lightnvm.c
index ddb8a3e..2454e01 100644
--- a/nvme-lightnvm.c
+++ b/nvme-lightnvm.c
@@ -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),
};
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 17/18] add missing endianess conversions in __lnvm_do_set_bbtbl
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (15 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 16/18] add missing endianess conversions in __lnvm_do_get_bbtbl Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 3:23 ` [PATCH 18/18] add missing endianess conversions in lnvm_do_set_bbtbl Christoph Hellwig
2016-09-23 14:45 ` nvme-cli: add endianess annotations Keith Busch
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme-lightnvm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nvme-lightnvm.c b/nvme-lightnvm.c
index 2454e01..1575366 100644
--- a/nvme-lightnvm.c
+++ b/nvme-lightnvm.c
@@ -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,
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 18/18] add missing endianess conversions in lnvm_do_set_bbtbl
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (16 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 17/18] add missing endianess conversions in __lnvm_do_set_bbtbl Christoph Hellwig
@ 2016-09-23 3:23 ` Christoph Hellwig
2016-09-23 14:45 ` nvme-cli: add endianess annotations Keith Busch
18 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-23 3:23 UTC (permalink / raw)
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
nvme-lightnvm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nvme-lightnvm.c b/nvme-lightnvm.c
index 1575366..2c6b5d2 100644
--- a/nvme-lightnvm.c
+++ b/nvme-lightnvm.c
@@ -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;
--
2.1.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* nvme-cli: add endianess annotations
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
` (17 preceding siblings ...)
2016-09-23 3:23 ` [PATCH 18/18] add missing endianess conversions in lnvm_do_set_bbtbl Christoph Hellwig
@ 2016-09-23 14:45 ` Keith Busch
18 siblings, 0 replies; 21+ messages in thread
From: Keith Busch @ 2016-09-23 14:45 UTC (permalink / raw)
On Thu, Sep 22, 2016@08:22:51PM -0700, Christoph Hellwig wrote:
> 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.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.
Thanks for all the fixes. I ran some sanity tests successfully, and have
applied all the patches to master.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 01/18] import linux/nvme.h
2016-09-23 3:22 ` [PATCH 01/18] import linux/nvme.h Christoph Hellwig
@ 2016-09-23 20:53 ` Sagi Grimberg
0 siblings, 0 replies; 21+ messages in thread
From: Sagi Grimberg @ 2016-09-23 20:53 UTC (permalink / raw)
Series looks good,
Reviewed-by: Sagi Grimberg <sagi at grimberg.me>
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2016-09-23 20:53 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-23 3:22 nvme-cli: add endianess annotations Christoph Hellwig
2016-09-23 3:22 ` [PATCH 01/18] import linux/nvme.h Christoph Hellwig
2016-09-23 20:53 ` Sagi Grimberg
2016-09-23 3:22 ` [PATCH 02/18] fix linux/nvme.h for use with nvme-cli Christoph Hellwig
2016-09-23 3:22 ` [PATCH 03/18] use nvme.h from Linux Christoph Hellwig
2016-09-23 3:22 ` [PATCH 04/18] dynamically allocate log page buffers Christoph Hellwig
2016-09-23 3:22 ` [PATCH 05/18] use abort() instead of __builtin_abort Christoph Hellwig
2016-09-23 3:22 ` [PATCH 06/18] various trivial sparse fixes Christoph Hellwig
2016-09-23 3:22 ` [PATCH 07/18] add support for checking endianess annotations using sparse Christoph Hellwig
2016-09-23 3:22 ` [PATCH 08/18] add missing endianess annoations for lightnvm data structures Christoph Hellwig
2016-09-23 3:23 ` [PATCH 09/18] fabrics: use correct endianess helper in print_discovery_log Christoph Hellwig
2016-09-23 3:23 ` [PATCH 10/18] intel: use correct endianess helpers in show_temp_stats Christoph Hellwig
2016-09-23 3:23 ` [PATCH 11/18] fix num_ctrls endianess in nvme_ns_attachment Christoph Hellwig
2016-09-23 3:23 ` [PATCH 12/18] add missing endianess conversions in print_list_item Christoph Hellwig
2016-09-23 3:23 ` [PATCH 13/18] add missing endianess conversions in json_nvme_id_ns Christoph Hellwig
2016-09-23 3:23 ` [PATCH 14/18] add missing endianess conversions in json_nvme_id_ctrl Christoph Hellwig
2016-09-23 3:23 ` [PATCH 15/18] add missing endianess conversions in json_smart_log Christoph Hellwig
2016-09-23 3:23 ` [PATCH 16/18] add missing endianess conversions in __lnvm_do_get_bbtbl Christoph Hellwig
2016-09-23 3:23 ` [PATCH 17/18] add missing endianess conversions in __lnvm_do_set_bbtbl Christoph Hellwig
2016-09-23 3:23 ` [PATCH 18/18] add missing endianess conversions in lnvm_do_set_bbtbl Christoph Hellwig
2016-09-23 14:45 ` nvme-cli: add endianess annotations Keith Busch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.