2 * Intel(R) Matrix Storage Manager hardware and firmware support routines
4 * Copyright (C) 2008 Intel Corporation
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "platform-intel.h"
21 #include "probe_roms.h"
29 #include <sys/types.h>
33 #define NVME_SUBSYS_PATH "/sys/devices/virtual/nvme-subsystem/"
35 static int devpath_to_ll(const char *dev_path
, const char *entry
,
36 unsigned long long *val
);
38 static void free_sys_dev(struct sys_dev
**list
)
41 struct sys_dev
*next
= (*list
)->next
;
50 struct sys_dev
*find_driver_devices(const char *bus
, const char *driver
)
52 /* search sysfs for devices driven by 'driver' */
58 struct sys_dev
*head
= NULL
;
59 struct sys_dev
*list
= NULL
;
60 struct sys_dev
*vmd
= NULL
;
61 enum sys_dev_type type
;
62 unsigned long long dev_id
;
63 unsigned long long class;
65 if (strcmp(driver
, "isci") == 0)
67 else if (strcmp(driver
, "ahci") == 0) {
68 vmd
= find_driver_devices("pci", "vmd");
70 } else if (strcmp(driver
, "nvme") == 0) {
71 /* if looking for nvme devs, first look for vmd */
72 vmd
= find_driver_devices("pci", "vmd");
74 } else if (strcmp(driver
, "vmd") == 0)
77 type
= SYS_DEV_UNKNOWN
;
79 sprintf(path
, "/sys/bus/%s/drivers/%s", bus
, driver
);
80 driver_dir
= opendir(path
);
86 for (de
= readdir(driver_dir
); de
; de
= readdir(driver_dir
)) {
90 /* is 'de' a device? check that the 'subsystem' link exists and
91 * that its target matches 'bus'
93 sprintf(path
, "/sys/bus/%s/drivers/%s/%s/subsystem",
94 bus
, driver
, de
->d_name
);
95 n
= readlink(path
, link
, sizeof(link
));
96 if (n
< 0 || n
>= (int)sizeof(link
))
99 c
= strrchr(link
, '/');
102 if (strncmp(bus
, c
+1, strlen(bus
)) != 0)
105 sprintf(path
, "/sys/bus/%s/drivers/%s/%s",
106 bus
, driver
, de
->d_name
);
108 /* if searching for nvme - skip vmd connected one */
109 if (type
== SYS_DEV_NVME
) {
111 char *rp
= realpath(path
, NULL
);
112 for (dev
= vmd
; dev
; dev
= dev
->next
) {
113 if ((strncmp(dev
->path
, rp
, strlen(dev
->path
)) == 0))
119 /* change sata type if under a vmd controller */
120 if (type
== SYS_DEV_SATA
) {
122 char *rp
= realpath(path
, NULL
);
123 for (dev
= vmd
; dev
; dev
= dev
->next
) {
124 if ((strncmp(dev
->path
, rp
, strlen(dev
->path
)) == 0))
125 type
= SYS_DEV_SATA_VMD
;
130 /* if it's not Intel device or mark as VMD connected - skip it. */
131 if (devpath_to_vendor(path
) != 0x8086 || skip
== 1)
134 if (devpath_to_ll(path
, "device", &dev_id
) != 0)
137 if (devpath_to_ll(path
, "class", &class) != 0)
141 * Each VMD device (domain) adds separate PCI bus, it is better
142 * to store path as a path to that bus (easier further
143 * determination which NVMe dev is connected to this particular
146 if (type
== SYS_DEV_VMD
) {
147 sprintf(path
, "/sys/bus/%s/drivers/%s/%s/domain/device",
148 bus
, driver
, de
->d_name
);
150 p
= realpath(path
, NULL
);
152 pr_err("Unable to get real path for '%s'\n", path
);
156 /* start / add list entry */
158 head
= xmalloc(sizeof(*head
));
161 list
->next
= xmalloc(sizeof(*head
));
170 list
->dev_id
= (__u16
) dev_id
;
171 list
->class = (__u32
) class;
176 if ((list
->pci_id
= strrchr(list
->path
, '/')) != NULL
)
179 closedir(driver_dir
);
181 /* nvme vmd needs a list separate from sata vmd */
182 if (vmd
&& type
== SYS_DEV_NVME
) {
192 static struct sys_dev
*intel_devices
=NULL
;
193 static time_t valid_time
= 0;
195 struct sys_dev
*device_by_id(__u16 device_id
)
197 struct sys_dev
*iter
;
199 for (iter
= intel_devices
; iter
!= NULL
; iter
= iter
->next
)
200 if (iter
->dev_id
== device_id
)
205 struct sys_dev
*device_by_id_and_path(__u16 device_id
, const char *path
)
207 struct sys_dev
*iter
;
209 for (iter
= intel_devices
; iter
!= NULL
; iter
= iter
->next
)
210 if ((iter
->dev_id
== device_id
) && strstr(iter
->path
, path
))
215 static int devpath_to_ll(const char *dev_path
, const char *entry
, unsigned long long *val
)
217 char path
[strnlen(dev_path
, PATH_MAX
) + strnlen(entry
, PATH_MAX
) + 2];
221 sprintf(path
, "%s/%s", dev_path
, entry
);
223 fd
= open(path
, O_RDONLY
);
226 n
= sysfs_fd_get_ll(fd
, val
);
231 __u16
devpath_to_vendor(const char *dev_path
)
233 char path
[strlen(dev_path
) + strlen("/vendor") + 1];
239 sprintf(path
, "%s/vendor", dev_path
);
241 fd
= open(path
, O_RDONLY
);
245 n
= read(fd
, vendor
, sizeof(vendor
));
246 if (n
== sizeof(vendor
)) {
247 vendor
[n
- 1] = '\0';
248 id
= strtoul(vendor
, NULL
, 16);
255 /* Description: Read text value of dev_path/entry field
257 * dev_path - sysfs path to the device
258 * entry - entry to be read
259 * buf - buffer for read value
261 * verbose - error logging level
263 int devpath_to_char(const char *dev_path
, const char *entry
, char *buf
, int len
,
268 snprintf(path
, sizeof(path
), "%s/%s", dev_path
, entry
);
269 if (load_sys(path
, buf
, len
)) {
271 pr_err("Cannot read %s, aborting\n", path
);
278 struct sys_dev
*find_intel_devices(void)
280 struct sys_dev
*ahci
, *isci
, *nvme
;
282 if (valid_time
> time(0) - 10)
283 return intel_devices
;
286 free_sys_dev(&intel_devices
);
288 isci
= find_driver_devices("pci", "isci");
289 /* Searching for AHCI will return list of SATA and SATA VMD controllers */
290 ahci
= find_driver_devices("pci", "ahci");
291 /* Searching for NVMe will return list of NVMe and VMD controllers */
292 nvme
= find_driver_devices("pci", "nvme");
294 if (!isci
&& !ahci
) {
298 struct sys_dev
*elem
= ahci
;
303 struct sys_dev
*elem
= ahci
;
311 intel_devices
= ahci
;
312 valid_time
= time(0);
313 return intel_devices
;
317 * PCI Expansion ROM Data Structure Format */
318 struct pciExpDataStructFormat
{
323 __u16 pciDataStructLen
;
324 __u8 pciDataStructRev
;
325 } __attribute__ ((packed
));
327 struct orom_entry
*orom_entries
;
329 const struct orom_entry
*get_orom_entry_by_device_id(__u16 dev_id
)
331 struct orom_entry
*entry
;
332 struct devid_list
*devid
;
334 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
335 for (devid
= entry
->devid_list
; devid
; devid
= devid
->next
) {
336 if (devid
->devid
== dev_id
)
344 const struct imsm_orom
*get_orom_by_device_id(__u16 dev_id
)
346 const struct orom_entry
*entry
= get_orom_entry_by_device_id(dev_id
);
354 static struct orom_entry
*add_orom(const struct imsm_orom
*orom
)
356 struct orom_entry
*list
;
357 struct orom_entry
*prev
= NULL
;
359 for (list
= orom_entries
; list
; prev
= list
, list
= list
->next
)
362 list
= xmalloc(sizeof(struct orom_entry
));
364 list
->devid_list
= NULL
;
375 static void add_orom_device_id(struct orom_entry
*entry
, __u16 dev_id
)
377 struct devid_list
*list
;
378 struct devid_list
*prev
= NULL
;
380 for (list
= entry
->devid_list
; list
; prev
= list
, list
= list
->next
) {
381 if (list
->devid
== dev_id
)
384 list
= xmalloc(sizeof(struct devid_list
));
385 list
->devid
= dev_id
;
389 entry
->devid_list
= list
;
394 static int scan(const void *start
, const void *end
, const void *data
)
397 const struct imsm_orom
*imsm_mem
= NULL
;
398 int len
= (end
- start
);
399 struct pciExpDataStructFormat
*ptr
= (struct pciExpDataStructFormat
*)data
;
401 if (data
+ 0x18 > end
) {
402 dprintf("cannot find pciExpDataStruct \n");
406 dprintf("ptr->vendorID: %lx __le16_to_cpu(ptr->deviceID): %lx \n",
407 (ulong
) __le16_to_cpu(ptr
->vendorID
),
408 (ulong
) __le16_to_cpu(ptr
->deviceID
));
410 if (__le16_to_cpu(ptr
->vendorID
) != 0x8086)
413 if (get_orom_by_device_id(ptr
->deviceID
))
416 for (offset
= 0; offset
< len
; offset
+= 4) {
417 const void *mem
= start
+ offset
;
419 if ((memcmp(mem
, IMSM_OROM_SIGNATURE
, 4) == 0)) {
428 struct orom_entry
*orom
= add_orom(imsm_mem
);
430 /* only PciDataStructure with revision 3 and above supports devices list. */
431 if (ptr
->pciDataStructRev
>= 3 && ptr
->devListOffset
) {
432 const __u16
*dev_list
= (void *)ptr
+ ptr
->devListOffset
;
435 for (i
= 0; dev_list
[i
] != 0; i
++)
436 add_orom_device_id(orom
, dev_list
[i
]);
438 add_orom_device_id(orom
, __le16_to_cpu(ptr
->deviceID
));
444 const struct imsm_orom
*imsm_platform_test(struct sys_dev
*hba
)
446 struct imsm_orom orom
= {
447 .signature
= IMSM_OROM_SIGNATURE
,
448 .rlc
= IMSM_OROM_RLC_RAID0
| IMSM_OROM_RLC_RAID1
|
449 IMSM_OROM_RLC_RAID10
| IMSM_OROM_RLC_RAID5
,
450 .sss
= IMSM_OROM_SSS_4kB
| IMSM_OROM_SSS_8kB
|
451 IMSM_OROM_SSS_16kB
| IMSM_OROM_SSS_32kB
|
452 IMSM_OROM_SSS_64kB
| IMSM_OROM_SSS_128kB
|
453 IMSM_OROM_SSS_256kB
| IMSM_OROM_SSS_512kB
|
454 IMSM_OROM_SSS_1MB
| IMSM_OROM_SSS_2MB
,
455 .dpa
= IMSM_OROM_DISKS_PER_ARRAY
,
456 .tds
= IMSM_OROM_TOTAL_DISKS
,
457 .vpa
= IMSM_OROM_VOLUMES_PER_ARRAY
,
458 .vphba
= IMSM_OROM_VOLUMES_PER_HBA
460 orom
.attr
= orom
.rlc
| IMSM_OROM_ATTR_ChecksumVerify
;
462 if (check_env("IMSM_TEST_OROM_NORAID5")) {
463 orom
.rlc
= IMSM_OROM_RLC_RAID0
| IMSM_OROM_RLC_RAID1
|
464 IMSM_OROM_RLC_RAID10
;
466 if (check_env("IMSM_TEST_AHCI_EFI_NORAID5") && (hba
->type
== SYS_DEV_SAS
)) {
467 orom
.rlc
= IMSM_OROM_RLC_RAID0
| IMSM_OROM_RLC_RAID1
|
468 IMSM_OROM_RLC_RAID10
;
470 if (check_env("IMSM_TEST_SCU_EFI_NORAID5") && (hba
->type
== SYS_DEV_SATA
)) {
471 orom
.rlc
= IMSM_OROM_RLC_RAID0
| IMSM_OROM_RLC_RAID1
|
472 IMSM_OROM_RLC_RAID10
;
475 struct orom_entry
*ret
= add_orom(&orom
);
477 add_orom_device_id(ret
, hba
->dev_id
);
482 static const struct imsm_orom
*find_imsm_hba_orom(struct sys_dev
*hba
)
486 if (check_env("IMSM_TEST_OROM"))
487 return imsm_platform_test(hba
);
489 /* return empty OROM capabilities in EFI test mode */
490 if (check_env("IMSM_TEST_AHCI_EFI") || check_env("IMSM_TEST_SCU_EFI"))
493 find_intel_devices();
495 if (intel_devices
== NULL
)
498 /* scan option-rom memory looking for an imsm signature */
499 if (check_env("IMSM_SAFE_OROM_SCAN"))
503 if (probe_roms_init(align
) != 0)
506 /* ignore return value - True is returned if both adapater roms are found */
507 scan_adapter_roms(scan
);
510 return get_orom_by_device_id(hba
->dev_id
);
513 #define GUID_STR_MAX 37 /* according to GUID format:
514 * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" */
516 #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
518 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
519 (b) & 0xff, ((b) >> 8) & 0xff, \
520 (c) & 0xff, ((c) >> 8) & 0xff, \
521 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
523 #define SYS_EFI_VAR_PATH "/sys/firmware/efi/vars"
524 #define SYS_EFIVARS_PATH "/sys/firmware/efi/efivars"
525 #define SCU_PROP "RstScuV"
526 #define AHCI_PROP "RstSataV"
527 #define AHCI_SSATA_PROP "RstsSatV"
528 #define AHCI_TSATA_PROP "RsttSatV"
529 #define VROC_VMD_PROP "RstUefiV"
530 #define RST_VMD_PROP "RstVmdV"
532 #define VENDOR_GUID \
533 EFI_GUID(0x193dfefa, 0xa445, 0x4302, 0x99, 0xd8, 0xef, 0x3a, 0xad, 0x1a, 0x04, 0xc6)
535 #define PCI_CLASS_RAID_CNTRL 0x010400
537 static int read_efi_var(void *buffer
, ssize_t buf_size
,
538 const char *variable_name
, struct efi_guid guid
)
541 char buf
[GUID_STR_MAX
];
545 snprintf(path
, PATH_MAX
, "%s/%s-%s", SYS_EFIVARS_PATH
, variable_name
, guid_str(buf
, guid
));
547 fd
= open(path
, O_RDONLY
);
551 /* read the variable attributes and ignore it */
552 n
= read(fd
, buf
, sizeof(__u32
));
558 /* read the variable data */
559 n
= read(fd
, buffer
, buf_size
);
567 static int read_efi_variable(void *buffer
, ssize_t buf_size
,
568 const char *variable_name
, struct efi_guid guid
)
571 char buf
[GUID_STR_MAX
];
573 ssize_t n
, var_data_len
;
575 /* Try to read the variable using the new efivarfs interface first.
576 * If that fails, fall back to the old sysfs-efivars interface. */
577 if (!read_efi_var(buffer
, buf_size
, variable_name
, guid
))
580 snprintf(path
, PATH_MAX
, "%s/%s-%s/size", SYS_EFI_VAR_PATH
, variable_name
, guid_str(buf
, guid
));
582 dprintf("EFI VAR: path=%s\n", path
);
583 /* get size of variable data */
584 dfd
= open(path
, O_RDONLY
);
588 n
= read(dfd
, &buf
, sizeof(buf
));
595 var_data_len
= strtoul(buf
, NULL
, 16);
596 if ((errno
== ERANGE
&& (var_data_len
== LONG_MAX
)) ||
597 (errno
!= 0 && var_data_len
== 0))
601 snprintf(path
, PATH_MAX
, "%s/%s-%s/data", SYS_EFI_VAR_PATH
, variable_name
, guid_str(buf
, guid
));
603 dprintf("EFI VAR: path=%s\n", path
);
604 dfd
= open(path
, O_RDONLY
);
608 n
= read(dfd
, buffer
, buf_size
);
610 if (n
!= var_data_len
|| n
< buf_size
) {
617 const struct imsm_orom
*find_imsm_efi(struct sys_dev
*hba
)
619 struct imsm_orom orom
;
620 struct orom_entry
*ret
;
621 static const char * const sata_efivars
[] = {AHCI_PROP
, AHCI_SSATA_PROP
,
623 static const char * const vmd_efivars
[] = {VROC_VMD_PROP
, RST_VMD_PROP
};
626 if (check_env("IMSM_TEST_AHCI_EFI") || check_env("IMSM_TEST_SCU_EFI"))
627 return imsm_platform_test(hba
);
629 /* OROM test is set, return that there is no EFI capabilities */
630 if (check_env("IMSM_TEST_OROM"))
635 if (!read_efi_variable(&orom
, sizeof(orom
), SCU_PROP
,
641 if (hba
->class != PCI_CLASS_RAID_CNTRL
)
644 for (i
= 0; i
< ARRAY_SIZE(sata_efivars
); i
++) {
645 if (!read_efi_variable(&orom
, sizeof(orom
),
646 sata_efivars
[i
], VENDOR_GUID
))
650 if (i
== ARRAY_SIZE(sata_efivars
))
655 case SYS_DEV_SATA_VMD
:
656 for (i
= 0; i
< ARRAY_SIZE(vmd_efivars
); i
++) {
657 if (!read_efi_variable(&orom
, sizeof(orom
),
658 vmd_efivars
[i
], VENDOR_GUID
))
662 if (i
== ARRAY_SIZE(vmd_efivars
))
670 ret
= add_orom(&orom
);
671 add_orom_device_id(ret
, hba
->dev_id
);
672 ret
->type
= hba
->type
;
677 const struct imsm_orom
*find_imsm_nvme(struct sys_dev
*hba
)
679 static struct orom_entry
*nvme_orom
;
681 if (hba
->type
!= SYS_DEV_NVME
)
685 struct imsm_orom nvme_orom_compat
= {
686 .signature
= IMSM_NVME_OROM_COMPAT_SIGNATURE
,
687 .rlc
= IMSM_OROM_RLC_RAID0
| IMSM_OROM_RLC_RAID1
|
688 IMSM_OROM_RLC_RAID10
| IMSM_OROM_RLC_RAID5
,
689 .sss
= IMSM_OROM_SSS_4kB
| IMSM_OROM_SSS_8kB
|
690 IMSM_OROM_SSS_16kB
| IMSM_OROM_SSS_32kB
|
691 IMSM_OROM_SSS_64kB
| IMSM_OROM_SSS_128kB
,
692 .dpa
= IMSM_OROM_DISKS_PER_ARRAY_NVME
,
693 .tds
= IMSM_OROM_TOTAL_DISKS_NVME
,
694 .vpa
= IMSM_OROM_VOLUMES_PER_ARRAY
,
695 .vphba
= IMSM_OROM_TOTAL_DISKS_NVME
/ 2 * IMSM_OROM_VOLUMES_PER_ARRAY
,
696 .attr
= IMSM_OROM_ATTR_2TB
| IMSM_OROM_ATTR_2TB_DISK
,
697 .driver_features
= IMSM_OROM_CAPABILITIES_EnterpriseSystem
699 nvme_orom
= add_orom(&nvme_orom_compat
);
701 add_orom_device_id(nvme_orom
, hba
->dev_id
);
702 nvme_orom
->type
= SYS_DEV_NVME
;
703 return &nvme_orom
->orom
;
706 const struct imsm_orom
*find_imsm_capability(struct sys_dev
*hba
)
708 const struct imsm_orom
*cap
= get_orom_by_device_id(hba
->dev_id
);
713 if (hba
->type
== SYS_DEV_NVME
)
714 return find_imsm_nvme(hba
);
715 if ((cap
= find_imsm_efi(hba
)) != NULL
)
717 if ((cap
= find_imsm_hba_orom(hba
)) != NULL
)
723 /* Check whether the nvme device is represented by nvme subsytem,
724 * if yes virtual path should be changed to hardware device path,
725 * to allow IMSM capabilities detection.
727 * hardware path to device - if the device is represented via
728 * nvme virtual subsytem
729 * NULL - if the device is not represented via nvme virtual subsytem
731 char *get_nvme_multipath_dev_hw_path(const char *dev_path
)
737 if (strncmp(dev_path
, NVME_SUBSYS_PATH
, strlen(NVME_SUBSYS_PATH
)) != 0)
740 dir
= opendir(dev_path
);
744 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
745 char buf
[strlen(dev_path
) + strlen(ent
->d_name
) + 1];
747 /* Check if dir is a controller, ignore namespaces*/
748 if (!(strncmp(ent
->d_name
, "nvme", 4) == 0) ||
749 (strrchr(ent
->d_name
, 'n') != &ent
->d_name
[0]))
752 sprintf(buf
, "%s/%s", dev_path
, ent
->d_name
);
753 rp
= realpath(buf
, NULL
);
761 /* Description: Return part or whole realpath for the dev
763 * dev - the device to be quered
764 * dev_level - level of "/device" entries. It allows to caller to access
765 * virtual or physical devices which are on "path" to quered
767 * buf - optional, must be PATH_MAX size. If set, then will be used.
769 char *devt_to_devpath(dev_t dev
, int dev_level
, char *buf
)
771 char device
[PATH_MAX
];
774 unsigned long device_free_len
= sizeof(device
) - 1;
775 char dev_str
[] = "/device";
776 unsigned long dev_str_len
= strlen(dev_str
);
778 snprintf(device
, sizeof(device
), "/sys/dev/block/%d:%d", major(dev
),
781 /* If caller wants block device, return path to it even if it is exposed
785 return realpath(device
, buf
);
787 device_free_len
-= strlen(device
);
788 for (i
= 0; i
< dev_level
; i
++) {
789 if (device_free_len
< dev_str_len
)
792 strncat(device
, dev_str
, device_free_len
);
794 /* Resolve nvme-subsystem abstraction if needed
796 device_free_len
-= dev_str_len
;
800 if (!realpath(device
, rp
))
802 hw_path
= get_nvme_multipath_dev_hw_path(rp
);
804 strcpy(device
, hw_path
);
805 device_free_len
= sizeof(device
) -
812 return realpath(device
, buf
);
815 char *diskfd_to_devpath(int fd
, int dev_level
, char *buf
)
817 /* return the device path for a disk, return NULL on error or fd
818 * refers to a partition
822 if (fstat(fd
, &st
) != 0)
824 if (!S_ISBLK(st
.st_mode
))
827 return devt_to_devpath(st
.st_rdev
, dev_level
, buf
);
830 int path_attached_to_hba(const char *disk_path
, const char *hba_path
)
834 if (check_env("IMSM_TEST_AHCI_DEV") ||
835 check_env("IMSM_TEST_SCU_DEV")) {
839 if (!disk_path
|| !hba_path
)
841 dprintf("hba: %s - disk: %s\n", hba_path
, disk_path
);
842 if (strncmp(disk_path
, hba_path
, strlen(hba_path
)) == 0)
850 int devt_attached_to_hba(dev_t dev
, const char *hba_path
)
852 char *disk_path
= devt_to_devpath(dev
, 1, NULL
);
853 int rc
= path_attached_to_hba(disk_path
, hba_path
);
861 int disk_attached_to_hba(int fd
, const char *hba_path
)
863 char *disk_path
= diskfd_to_devpath(fd
, 1, NULL
);
864 int rc
= path_attached_to_hba(disk_path
, hba_path
);
872 char *vmd_domain_to_controller(struct sys_dev
*hba
, char *buf
)
881 if (hba
->type
!= SYS_DEV_VMD
)
884 dir
= opendir("/sys/bus/pci/drivers/vmd");
888 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
889 sprintf(path
, "/sys/bus/pci/drivers/vmd/%s/domain/device",
892 if (!realpath(path
, buf
))
895 if (strncmp(buf
, hba
->path
, strlen(buf
)) == 0) {
896 sprintf(path
, "/sys/bus/pci/drivers/vmd/%s", ent
->d_name
);
898 return realpath(path
, buf
);
906 /* Scan over all controller's namespaces and compare nsid value to verify if
907 * current one is supported. The routine doesn't check IMSM capabilities for
908 * namespace. Only one nvme namespace is supported by IMSM.
910 * fd - open descriptor to the nvme namespace
911 * verbose - error logging level
913 * 1 - if namespace is supported
916 int imsm_is_nvme_namespace_supported(int fd
, int verbose
)
920 char cntrl_path
[PATH_MAX
];
921 char ns_path
[PATH_MAX
];
922 unsigned long long lowest_nsid
= ULLONG_MAX
;
923 unsigned long long this_nsid
;
927 if (!diskfd_to_devpath(fd
, 1, cntrl_path
) ||
928 !diskfd_to_devpath(fd
, 0, ns_path
)) {
930 pr_err("Cannot get device paths\n");
935 if (devpath_to_ll(ns_path
, "nsid", &this_nsid
)) {
937 pr_err("Cannot read nsid value for %s",
942 dir
= opendir(cntrl_path
);
946 /* The lowest nvme namespace is supported */
947 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
948 unsigned long long curr_nsid
;
949 char curr_ns_path
[PATH_MAX
+ 256];
951 if (!strstr(ent
->d_name
, "nvme"))
954 snprintf(curr_ns_path
, sizeof(curr_ns_path
), "%s/%s",
955 cntrl_path
, ent
->d_name
);
957 if (devpath_to_ll(curr_ns_path
, "nsid", &curr_nsid
))
960 if (lowest_nsid
> curr_nsid
)
961 lowest_nsid
= curr_nsid
;
964 if (this_nsid
== lowest_nsid
)
967 pr_err("IMSM is supported on the lowest NVMe namespace\n");
976 /* Verify if multipath is supported by NVMe controller
981 int is_multipath_nvme(int disk_fd
)
983 char ns_path
[PATH_MAX
];
985 if (!diskfd_to_devpath(disk_fd
, 0, ns_path
))
988 if (strncmp(ns_path
, NVME_SUBSYS_PATH
, strlen(NVME_SUBSYS_PATH
)) == 0)