]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
property: Introduce inline function to check 64bit reg
authorMinwoo Im <minwoo.im@samsung.com>
Sun, 5 May 2019 11:46:39 +0000 (20:46 +0900)
committerMinwoo Im <minwoo.im@samsung.com>
Sun, 5 May 2019 12:05:41 +0000 (13:05 +0100)
This patch removes 'advance' argument used in get_property_helper() to tell
the register of the given offset is whether 64bit or not, instead introduce a
inline function to check it simply.

This kind of check might be needed at the print module to figure out if given
register should be printed out in 32bit format or 64bit format.

Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
nvme-ioctl.c
nvme.h

index 83740f225af8effb64cf82c95a89790ac4f4041b..e5a81dfa0f001d4d9e4cb03acaaf5183421206e4 100644 (file)
@@ -577,29 +577,19 @@ static int nvme_property(int fd, __u8 fctype, __le32 off, __le64 *value, __u8 at
        return err;
 }
 
-static int get_property_helper(int fd, int offset, void *value, int *advance)
+static int get_property_helper(int fd, int offset, void *value)
 {
        __le64 value64;
        int err = -EINVAL;
 
-       switch (offset) {
-       case NVME_REG_CAP:
-       case NVME_REG_ASQ:
-       case NVME_REG_ACQ:
-               *advance = 8;
-               break;
-       default:
-               *advance = 4;
-       }
-
        if (!value)
                return err;
 
        err = nvme_property(fd, nvme_fabrics_type_property_get,
-                       cpu_to_le32(offset), &value64, (*advance == 8));
+                       cpu_to_le32(offset), &value64, is_64bit_reg(offset));
 
        if (!err) {
-               if (*advance == 8)
+               if (is_64bit_reg(offset))
                        *((uint64_t *)value) = le64_to_cpu(value64);
                else
                        *((uint32_t *)value) = le32_to_cpu(value64);
@@ -610,13 +600,12 @@ static int get_property_helper(int fd, int offset, void *value, int *advance)
 
 int nvme_get_property(int fd, int offset, uint64_t *value)
 {
-       int advance;
-       return get_property_helper(fd, offset, value, &advance);
+       return get_property_helper(fd, offset, value);
 }
 
 int nvme_get_properties(int fd, void **pbar)
 {
-       int offset, advance;
+       int offset;
        int err;
        int size = getpagesize();
 
@@ -627,12 +616,14 @@ int nvme_get_properties(int fd, void **pbar)
        }
 
        memset(*pbar, 0xff, size);
-       for (offset = NVME_REG_CAP; offset <= NVME_REG_CMBSZ; offset += advance) {
-               err = get_property_helper(fd, offset, *pbar + offset, &advance);
+       for (offset = NVME_REG_CAP; offset <= NVME_REG_CMBSZ;) {
+               err = get_property_helper(fd, offset, *pbar + offset);
                if (err) {
                        free(*pbar);
                        break;
                }
+
+               offset += is_64bit_reg(offset) ? 8 : 4;
        }
 
        return err;
diff --git a/nvme.h b/nvme.h
index 71e2f4d2bbf00f95480301a2a7a40a9f8e89a8d3..a149005a04259de8aa22d46ac41ed7ad5f3de724 100644 (file)
--- a/nvme.h
+++ b/nvme.h
@@ -177,4 +177,28 @@ int        validate_output_format(char *format);
 struct subsys_list_item *get_subsys_list(int *subcnt, char *subsysnqn, __u32 nsid);
 void free_subsys_list(struct subsys_list_item *slist, int n);
 char *nvme_char_from_block(char *block);
+
+/*
+ * is_64bit_reg - It checks whether given offset of the controller register is
+ *                64bit or not.
+ * @offset: offset of controller register field in bytes
+ *
+ * It gives true if given offset is 64bit register, otherwise it returns false.
+ *
+ * Notes:  This function does not care about transport so that the offset is
+ * not going to be checked inside of this function for the unsupported fields
+ * in a specific transport.  For example, BPMBL(Boot Partition Memory Buffer
+ * Location) register is not supported by fabrics, but it can be chcked here.
+ */
+static inline bool is_64bit_reg(__u32 offset)
+{
+       if (offset == NVME_REG_CAP ||
+                       offset == NVME_REG_ASQ ||
+                       offset == NVME_REG_ACQ ||
+                       offset == NVME_REG_BPMBL)
+               return true;
+
+       return false;
+}
+
 #endif /* _NVME_H */