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);
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();
}
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;
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 */