From: Minwoo Im Date: Sun, 5 May 2019 11:46:39 +0000 (+0900) Subject: property: Introduce inline function to check 64bit reg X-Git-Tag: v1.9~70^2~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=077bd5c382ff92449cd528bb2867049454bf1055;p=users%2Fsagi%2Fnvme-cli.git property: Introduce inline function to check 64bit reg 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 --- diff --git a/nvme-ioctl.c b/nvme-ioctl.c index 83740f22..e5a81dfa 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -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 71e2f4d2..a149005a 100644 --- 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 */