Skip to contentSkip to conversation

imsm: support for Intel(R) SAS controller.

PATCH New Artur Wojcik 1 participant 1 message Feb 16, 2010 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 imsm: support for Intel(R) SAS controller.

This patch adds support for SAS controller(s) built in Intel(R) Patsburg chipset. The patch is for IMSM metadata only.

The patch maintains compatibility between Linux and Windows IMSM RAID stacks - Windows IMSM does not allow arrays to span on devices attached to different storage controllers.

---
 platform-intel.c |   89 ++++++++--------
 platform-intel.h |   12 ++
 super-intel.c    |  296 ++++++++++++++++++++++++++++++++++++++++++------------
 3 files changed, 287 insertions(+), 110 deletions(-)
platform-intel.c +45 -44
index 30f7914..31639c3 100644
@@ -41,7 +41,7 @@ void free_sys_dev(struct sys_dev **list)
        }
 }
 
-struct sys_dev *find_driver_devices(const char *bus, const char *driver)
+static struct sys_dev *find_driver_devices(const char *bus, const char *driver)
 {
        /* search sysfs for devices driven by 'driver' */
        char path[292];
@@ -51,6 +51,14 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
        struct dirent *de;
        struct sys_dev *head = NULL;
        struct sys_dev *list = NULL;
+       enum sys_dev_type type;
+
+       if (strcmp(driver, "isci_mod") == 0)
+               type = SYS_DEV_SAS;
+       else if (strcmp(driver, "ahci") == 0)
+               type = SYS_DEV_SATA;
+       else
+               type = SYS_DEV_UNKNOWN;
 
        sprintf(path, "/sys/bus/%s/drivers/%s", bus, driver);
        driver_dir = opendir(path);
@@ -74,6 +82,13 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
                if (strncmp(bus, c+1, strlen(bus)) != 0)
                        continue;
 
+               sprintf(path, "/sys/bus/%s/drivers/%s/%s",
+                       bus, driver, de->d_name);
+
+               /* if it's not Intel device skip it. */
+               if (devpath_to_vendor(path) != 0x8086)
+                       continue;
+
                /* start / add list entry */
                if (!head) {
                        head = malloc(sizeof(*head));
@@ -88,11 +103,11 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
                        break;
                }
 
-               /* generate canonical path name for the device */
-               sprintf(path, "/sys/bus/%s/drivers/%s/%s",
-                       bus, driver, de->d_name);
+               list->type = type;
                list->path = canonicalize_file_name(path);
                list->next = NULL;
+               if ((list->pci_id = strrchr(list->path, '/')) != NULL)
+                       list->pci_id++;
        }
        closedir(driver_dir);
        return head;
@@ -122,23 +137,34 @@ __u16 devpath_to_vendor(const char *dev_path)
        return id;
 }
 
-static int platform_has_intel_ahci(void)
+struct sys_dev *find_intel_devices(void)
 {
-       struct sys_dev *devices = find_driver_devices("pci", "ahci");
-       struct sys_dev *dev;
-       int ret = 0;
-
-       for (dev = devices; dev; dev = dev->next)
-               if (devpath_to_vendor(dev->path) == 0x8086) {
-                       ret = 1;
-                       break;
-               }
-
-       free_sys_dev(&devices);
-
-       return ret;
+       struct sys_dev *ahci, *isci;
+
+       isci = find_driver_devices("pci", "isci_mod");
+       ahci = find_driver_devices("pci", "ahci");
+
+       if (!ahci) {
+               ahci = isci;
+       } else {
+               struct sys_dev *elem = ahci;
+               while (elem->next)
+                       elem = elem->next;
+               elem->next = isci;
+       }
+       return ahci;
 }
 
+static int platform_has_intel_devices(void)
+{
+       struct sys_dev *devices;
+       devices = find_intel_devices();
+       if (devices) {
+               free_sys_dev(&devices);
+               return 1;
+       }
+       return 0;
+}
 
 static struct imsm_orom imsm_orom;
 static int scan(const void *start, const void *end)
@@ -185,7 +211,7 @@ const struct imsm_orom *find_imsm_orom(void)
                return &imsm_orom;
        }
 
-       if (!platform_has_intel_ahci())
+       if (!platform_has_intel_devices())
                return NULL;
 
        /* scan option-rom memory looking for an imsm signature */
@@ -212,20 +238,6 @@ char *devt_to_devpath(dev_t dev)
        return canonicalize_file_name(device);
 }
 
-static char *diskfd_to_devpath(int fd)
-{
-       /* return the device path for a disk, return NULL on error or fd
-        * refers to a partition
-        */
-       struct stat st;
-
-       if (fstat(fd, &st) != 0)
-               return NULL;
-       if (!S_ISBLK(st.st_mode))
-               return NULL;
-
-       return devt_to_devpath(st.st_rdev);
-}
 
 int path_attached_to_hba(const char *disk_path, const char *hba_path)
 {
@@ -253,14 +265,3 @@ int devt_attached_to_hba(dev_t dev, const char *hba_path)
        return rc;
 }
 
-int disk_attached_to_hba(int fd, const char *hba_path)
-{
-       char *disk_path = diskfd_to_devpath(fd);
-       int rc = path_attached_to_hba(disk_path, hba_path);
-
-       if (disk_path)
-               free(disk_path);
-
-       return rc;
-}
-
platform-intel.h +10 -2
index bbdc9f9..df6c78f 100644
@@ -115,15 +115,23 @@ static inline int imsm_orom_has_chunk(const struct imsm_orom *orom, int chunk)
        return !!(orom->sss & (1 << (fs - 1)));
 }
 
+enum sys_dev_type {
+       SYS_DEV_UNKNOWN = 0,
+       SYS_DEV_SAS,
+       SYS_DEV_SATA
+};
+
 struct sys_dev {
+       enum sys_dev_type type;
        char *path;
+       char *pci_id;
        struct sys_dev *next;
 };
 
-struct sys_dev *find_driver_devices(const char *bus, const char *driver);
+struct sys_dev *find_intel_devices(void);
 __u16 devpath_to_vendor(const char *dev_path);
 void free_sys_dev(struct sys_dev **list);
 const struct imsm_orom *find_imsm_orom(void);
-int disk_attached_to_hba(int fd, const char *hba_path);
 char *devt_to_devpath(dev_t dev);
 int path_attached_to_hba(const char *disk_path, const char *hba_path);
+const char *get_sys_dev_type(enum sys_dev_type);
super-intel.c +232 -64

383 lines not on this page · raw message