Skip to contentSkip to conversation

sparc64: fix OF path names for sun4v systems

PATCH In review Eric Snowberg 3 participants 10 messages Jan 31, 2018 – Feb 14, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sparc64: fix OF path names for sun4v systems

Fix the Open Firmware (OF) path property for sun4v SPARC systems. These platforms do not have a /sas/ within their path. Over time different OF addressing schemes have been supported. There is no generic addressing scheme that works across every HBA.

---
V2:
- Requested coding style changes

---
 grub-core/osdep/linux/ofpath.c |  148 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 145 insertions(+), 3 deletions(-)
grub-core/osdep/linux/ofpath.c +145 -3
index dce4e59..5369508 100644
@@ -38,6 +38,46 @@
 #include <errno.h>
 #include <ctype.h>
 
+#ifdef __sparc__
+typedef enum
+  {
+    GRUB_OFPATH_SPARC_WWN_ADDR = 1,
+    GRUB_OFPATH_SPARC_TGT_LUN,
+  } ofpath_sparc_addressing;
+
+struct ofpath_sparc_hba
+{
+  grub_uint32_t device_id;
+  ofpath_sparc_addressing addressing;
+};
+
+static struct ofpath_sparc_hba sparc_lsi_hba[] = {
+  /* Rhea, Jasper 320, LSI53C1020/1030. */
+  {0x30, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1068E. */
+  {0x50, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1064E. */
+  {0x56, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Pandora SAS-1068E. */
+  {0x58, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Aspen, Invader, LSI SAS-3108. */
+  {0x5d, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Niwot, SAS 2108. */
+  {0x79, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Erie, Falcon, LSI SAS 2008. */
+  {0x72, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI WarpDrive 6203. */
+  {0x7e, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 2308. */
+  {0x87, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 3008. */
+  {0x97, GRUB_OFPATH_SPARC_WWN_ADDR},
+  {0, 0}
+};
+
+static const int LSI_VENDOR_ID = 0x1000;
+#endif
+
 #ifdef OFPATH_STANDALONE
 #define xmalloc malloc
 void
@@ -338,6 +378,67 @@ vendor_is_ATA(const char *path)
   return (memcmp(bufcont, "ATA", 3) == 0);
 }
 
+#ifdef __sparc__
+static void
+check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
+{
+  char *ed = strstr (sysfs_path, "host");
+  size_t path_size;
+  char *p, *path;
+  char buf[8];
+  int fd;
+
+  if (!ed)
+    return;
+
+  p = xstrdup (sysfs_path);
+  ed = strstr (p, "host");
+
+  if (!ed)
+    goto out;
+
+  *ed = '\0';
+
+  path_size = (strlen (p) + sizeof ("vendor"));
+  path = xmalloc (path_size);
+
+  if (!path)
+    goto out;
+
+  snprintf (path, path_size, "%svendor", p);
+  fd = open (path, O_RDONLY);
+
+  if (fd < 0)
+    goto out;
+
+  memset (buf, 0, sizeof (buf));
+
+  if (read (fd, buf, sizeof (buf) - 1) < 0)
+    goto out;
+
+  close (fd);
+  sscanf (buf, "%x", vendor);
+
+  snprintf (path, path_size, "%sdevice", p);
+  fd = open (path, O_RDONLY);
+
+  if (fd < 0)
+    goto out;
+
+  memset (buf, 0, sizeof (buf));
+
+  if (read (fd, buf, sizeof (buf) - 1) < 0)
+    goto out;
+
+  close (fd);
+  sscanf (buf, "%x", device_id);
+
+ out:
+  free (path);
+  free (p);
+}
+#endif
+
 static void
 check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
 {
@@ -399,7 +500,7 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
 {
   const char *p, *digit_string, *disk_name;
   int host, bus, tgt, lun;
-  unsigned long int sas_address;
+  unsigned long int sas_address = 0;
   char *sysfs_path, disk[MAX_DISK_CAT - sizeof ("/fp@0,0")];
   char *of_path;
 
@@ -416,9 +517,8 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
     }
 
   of_path = find_obppath(sysfs_path);
-  free (sysfs_path);
   if (!of_path)
-    return NULL;
+    goto out;
 
   if (strstr (of_path, "qlc"))
     strcat (of_path, "/fp@0,0");
@@ -447,6 +547,44 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
     }
   else
     {
+#ifdef __sparc__
+      ofpath_sparc_addressing addressing = GRUB_OFPATH_SPARC_TGT_LUN;
+      int vendor = 0, device_id = 0;
+      char *optr = disk;
+
+      check_hba_identifiers (sysfs_path, &vendor, &device_id);
+
+      if (vendor == LSI_VENDOR_ID)
+        {
+          struct ofpath_sparc_hba *lsi_hba;
+
+          /* Over time different OF addressing schemes have been supported.
+             There is no generic addressing scheme that works across
+             every HBA. */
+          for (lsi_hba = sparc_lsi_hba; lsi_hba->device_id; lsi_hba++)
+            if (lsi_hba->device_id == device_id)
+              {
+                addressing = lsi_hba->addressing;
+                break;
+              }
+        }
+
+      if (addressing == GRUB_OFPATH_SPARC_WWN_ADDR)
+        optr += snprintf (disk, sizeof (disk), "/%s@w%lx,%x", disk_name,
+                          sas_address, lun);
+      else
+        optr += snprintf (disk, sizeof (disk), "/%s@%x,%x", disk_name, tgt,
+                          lun);
+
+      if (*digit_string != '\0')
+        {
+          int part;
+
+          sscanf (digit_string, "%d", &part);
+          snprintf (optr, sizeof (disk) - (optr - disk - 1), ":%c", 'a'
+                    + (part - 1));
+        }
+#else
       if (lun == 0)
         {
           int sas_id = 0;
@@ -494,8 +632,12 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
             }
 	  free (lunstr);
         }
+#endif
     }
   strcat(of_path, disk);
+
+ out:
+  free (sysfs_path);
   return of_path;
 }
 
Signature · 1 line
1.7.1
#1 lore raw
Quoted 6 lines · Eric Snowberg

Fix the Open Firmware (OF) path property for sun4v SPARC systems. These platforms do not have a /sas/ within their path. Over time different OF addressing schemes have been supported. There is no generic addressing scheme that works across every HBA.

In general Reviewed-by: Daniel Kiper <[email protected]>...

Just a few comments below...

Quoted 12 lines

---
V2:
- Requested coding style changes

---
 grub-core/osdep/linux/ofpath.c |  148 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 145 insertions(+), 3 deletions(-)
grub-core/osdep/linux/ofpath.c +0 -0
index dce4e59..5369508 100644

grub-core/osdep/linux/ofpath.c line 41

Quoted 4 lines
grub-core/osdep/linux/ofpath.c +1 -0
@@ -38,6 +38,46 @@
 #include <errno.h>
 #include <ctype.h>
 
+#ifdef __sparc__

I have discussed this with Vladimir. It looks that this will not work if you try to cross-install SPARC GRUB2 binary using e.g. x86 grub-install. By default it should work. However, we will also have other issues here, like lack of access to OF firmware/paths, which make such configs unusable anyway. So, I would leave this patch as is for time being. If somebody cares then he/she should fix it.

Anyway, I will add something like that into the commit message before committing.

Quoted 54 lines
grub-core/osdep/linux/ofpath.c +47 -0
+typedef enum
+  {
+    GRUB_OFPATH_SPARC_WWN_ADDR = 1,
+    GRUB_OFPATH_SPARC_TGT_LUN,
+  } ofpath_sparc_addressing;
+
+struct ofpath_sparc_hba
+{
+  grub_uint32_t device_id;
+  ofpath_sparc_addressing addressing;
+};
+
+static struct ofpath_sparc_hba sparc_lsi_hba[] = {
+  /* Rhea, Jasper 320, LSI53C1020/1030. */
+  {0x30, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1068E. */
+  {0x50, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1064E. */
+  {0x56, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Pandora SAS-1068E. */
+  {0x58, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Aspen, Invader, LSI SAS-3108. */
+  {0x5d, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Niwot, SAS 2108. */
+  {0x79, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Erie, Falcon, LSI SAS 2008. */
+  {0x72, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI WarpDrive 6203. */
+  {0x7e, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 2308. */
+  {0x87, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 3008. */
+  {0x97, GRUB_OFPATH_SPARC_WWN_ADDR},
+  {0, 0}
+};
+
+static const int LSI_VENDOR_ID = 0x1000;
+#endif
+
 #ifdef OFPATH_STANDALONE
 #define xmalloc malloc
 void
@@ -338,6 +378,67 @@ vendor_is_ATA(const char *path)
   return (memcmp(bufcont, "ATA", 3) == 0);
 }
 
+#ifdef __sparc__
+static void
+check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
+{
+  char *ed = strstr (sysfs_path, "host");
+  size_t path_size;
+  char *p, *path;
+  char buf[8];

grub-core/osdep/linux/ofpath.c vendor_is_ATA(const char *path) · line 398

Quoted 10 lines
grub-core/osdep/linux/ofpath.c +10 -0
+  int fd;
+
+  if (!ed)
+    return;
+
+  p = xstrdup (sysfs_path);
+  ed = strstr (p, "host");
+
+  if (!ed)
+    goto out;

In normal circumstances this will never ever fail. If you are OK I will drop this "if" before committing.

If there are no objections I will commit this patch in a week or so.

Daniel

#2 lore raw
Quoted 39 lines · Daniel Kiper
Quoted 6 lines · Eric Snowberg

Fix the Open Firmware (OF) path property for sun4v SPARC systems. These platforms do not have a /sas/ within their path. Over time different OF addressing schemes have been supported. There is no generic addressing scheme that works across every HBA.

In general Reviewed-by: Daniel Kiper <[email protected]>...

Just a few comments below...

Quoted 12 lines

---
V2:
- Requested coding style changes
---
grub-core/osdep/linux/ofpath.c | 148 +++++++++++++++++++++++++++++++++++++++-

1 files changed, 145 insertions(+), 3 deletions(-)
grub-core/osdep/linux/ofpath.c +0 -0
index dce4e59..5369508 100644

grub-core/osdep/linux/ofpath.c line 41

Quoted 4 lines
grub-core/osdep/linux/ofpath.c +1 -0
@@ -38,6 +38,46 @@
 #include <errno.h>
 #include <ctype.h>
 
+#ifdef __sparc__

I have discussed this with Vladimir. It looks that this will not work if you try to cross-install SPARC GRUB2 binary using e.g. x86 grub-install. By default it should work. However, we will also have other issues here, like lack of access to OF firmware/paths, which make such configs unusable anyway. So, I would leave this patch as is for time being. If somebody cares then he/she should fix it.

Quoted 1 line

Anyway, I will add something like that into the commit message before committing.

That is fine with me.

Quoted 60 lines
Quoted 60 lines
grub-core/osdep/linux/ofpath.c +39 -0
+typedef enum
+  {
+    GRUB_OFPATH_SPARC_WWN_ADDR = 1,
+    GRUB_OFPATH_SPARC_TGT_LUN,
+  } ofpath_sparc_addressing;
+
+struct ofpath_sparc_hba
+{
+  grub_uint32_t device_id;
+  ofpath_sparc_addressing addressing;
+};
+
+static struct ofpath_sparc_hba sparc_lsi_hba[] = {
+  /* Rhea, Jasper 320, LSI53C1020/1030. */
+  {0x30, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1068E. */
+  {0x50, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1064E. */
+  {0x56, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Pandora SAS-1068E. */
+  {0x58, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Aspen, Invader, LSI SAS-3108. */
+  {0x5d, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Niwot, SAS 2108. */
+  {0x79, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Erie, Falcon, LSI SAS 2008. */
+  {0x72, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI WarpDrive 6203. */
+  {0x7e, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 2308. */
+  {0x87, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 3008. */
+  {0x97, GRUB_OFPATH_SPARC_WWN_ADDR},
+  {0, 0}
+};
+
+static const int LSI_VENDOR_ID = 0x1000;
+#endif
+
 #ifdef OFPATH_STANDALONE
 #define xmalloc malloc

void

grub-core/osdep/linux/ofpath.c +13 -0
@@ -338,6 +378,67 @@ vendor_is_ATA(const char *path)
  return (memcmp(bufcont, "ATA", 3) == 0);
 }
 
+#ifdef __sparc__
+static void
+check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
+{
+  char *ed = strstr (sysfs_path, "host");
+  size_t path_size;
+  char *p, *path;
+  char buf[8];
+  int fd;
+
+  if (!ed)
+    return;
+
Quoted 8 lines

grub-core/osdep/linux/ofpath.c vendor_is_ATA(const char *path) · line 398

Quoted 5 lines
grub-core/osdep/linux/ofpath.c +5 -0
+  p = xstrdup (sysfs_path);
+  ed = strstr (p, "host");
+
+  if (!ed)
+    goto out;

In normal circumstances this will never ever fail. If you are OK I will drop this "if" before committing.

I put that in for the case if the xstrdup above can not allocate memory. Then p will be null, the strstr will fail and then we should jump to out.

Quoted 2 lines

If there are no objections I will commit this patch in a week or so.

Thanks…

Is there some reason this patch is being held up too?

http://lists.gnu.org/archive/html/grub-devel/2017-05/msg00045.html

This is where things last left off:

http://lists.gnu.org/archive/html/grub-devel/2017-10/msg00046.html

We really need minimal GPT support in there for many of the follow on patches in my queue.

#3 lore raw
Quoted 9 lines · Eric Snowberg

Is there some reason this patch is being held up too?

http://lists.gnu.org/archive/html/grub-devel/2017-05/msg00045.html

This is where things last left off:

http://lists.gnu.org/archive/html/grub-devel/2017-10/msg00046.html

We really need minimal GPT support in there for many of the follow on patches in my queue.

FWIW, we have received lots of positive feedback from Debian users on sparc64 with Eric's patches applied to the Debian GRUB package:

Quoted 5 lines

https://lists.debian.org/debian-sparc/2018/02/msg00015.html
https://lists.debian.org/debian-sparc/2017/12/msg00027.html
https://lists.debian.org/debian-sparc/2017/12/msg00050.html
https://lists.debian.org/debian-sparc/2017/12/msg00053.html
https://lists.debian.org/debian-sparc/2017/12/msg00074.html

Even machines reported as old as the Ultra10 are reported to work fine.

I am mentioning this because I talked to Vladimir and Daniel at FOSDEM and there was concern whether this patch series would break GRUB on old SPARC machines.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#4 lore raw
In reply to Eric Snowberg
Quoted 37 lines · Eric Snowberg
Quoted 37 lines · Daniel Kiper
Quoted 6 lines · Eric Snowberg

Fix the Open Firmware (OF) path property for sun4v SPARC systems. These platforms do not have a /sas/ within their path. Over time different OF addressing schemes have been supported. There is no generic addressing scheme that works across every HBA.

In general Reviewed-by: Daniel Kiper <[email protected]>...

Just a few comments below...

Quoted 12 lines

---
V2:
- Requested coding style changes
---
grub-core/osdep/linux/ofpath.c | 148 +++++++++++++++++++++++++++++++++++++++-

1 files changed, 145 insertions(+), 3 deletions(-)
grub-core/osdep/linux/ofpath.c +0 -0
index dce4e59..5369508 100644

grub-core/osdep/linux/ofpath.c line 41

Quoted 4 lines
grub-core/osdep/linux/ofpath.c +1 -0
@@ -38,6 +38,46 @@
 #include <errno.h>
 #include <ctype.h>
 
+#ifdef __sparc__

I have discussed this with Vladimir. It looks that this will not work if you try to cross-install SPARC GRUB2 binary using e.g. x86 grub-install. By default it should work. However, we will also have other issues here, like lack of access to OF firmware/paths, which make such configs unusable anyway. So, I would leave this patch as is for time being. If somebody cares then he/she should fix it.

Quoted 3 lines
Quoted 1 line

Anyway, I will add something like that into the commit message before committing.

That is fine with me.

Great! Thanks!

Quoted 68 lines
Quoted 59 lines
Quoted 59 lines
grub-core/osdep/linux/ofpath.c +39 -0
+typedef enum
+  {
+    GRUB_OFPATH_SPARC_WWN_ADDR = 1,
+    GRUB_OFPATH_SPARC_TGT_LUN,
+  } ofpath_sparc_addressing;
+
+struct ofpath_sparc_hba
+{
+  grub_uint32_t device_id;
+  ofpath_sparc_addressing addressing;
+};
+
+static struct ofpath_sparc_hba sparc_lsi_hba[] = {
+  /* Rhea, Jasper 320, LSI53C1020/1030. */
+  {0x30, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1068E. */
+  {0x50, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1064E. */
+  {0x56, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Pandora SAS-1068E. */
+  {0x58, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Aspen, Invader, LSI SAS-3108. */
+  {0x5d, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Niwot, SAS 2108. */
+  {0x79, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Erie, Falcon, LSI SAS 2008. */
+  {0x72, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI WarpDrive 6203. */
+  {0x7e, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 2308. */
+  {0x87, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 3008. */
+  {0x97, GRUB_OFPATH_SPARC_WWN_ADDR},
+  {0, 0}
+};
+
+static const int LSI_VENDOR_ID = 0x1000;
+#endif
+
 #ifdef OFPATH_STANDALONE
 #define xmalloc malloc

void

grub-core/osdep/linux/ofpath.c +13 -0
@@ -338,6 +378,67 @@ vendor_is_ATA(const char *path)
  return (memcmp(bufcont, "ATA", 3) == 0);
 }
 
+#ifdef __sparc__
+static void
+check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
+{
+  char *ed = strstr (sysfs_path, "host");
+  size_t path_size;
+  char *p, *path;
+  char buf[8];
+  int fd;
+
+  if (!ed)
+    return;
+
Quoted 8 lines

grub-core/osdep/linux/ofpath.c vendor_is_ATA(const char *path) · line 398

Quoted 5 lines
grub-core/osdep/linux/ofpath.c +5 -0
+  p = xstrdup (sysfs_path);
+  ed = strstr (p, "host");
+
+  if (!ed)
+    goto out;

In normal circumstances this will never ever fail. If you are OK I will drop this "if" before committing.

Quoted 2 lines

I put that in for the case if the xstrdup above can not allocate memory. Then p will be null, the strstr will fail and then we should jump to out.

If this would be the case then you should check p for NULL before strstr() call. AIUI its behavior is not well defined if one of arguments is NULL. Anyway, xstrdup() does not return if it fails. So, we do not have such problem here.

Quoted 6 lines
Quoted 1 line

If there are no objections I will commit this patch in a week or so.

Thanks…

Is there some reason this patch is being held up too?

Quoted 7 lines

http://lists.gnu.org/archive/html/grub-devel/2017-05/msg00045.html

This is where things last left off:

http://lists.gnu.org/archive/html/grub-devel/2017-10/msg00046.html

We really need minimal GPT support in there for many of the follow on patches in my queue.

Oh, sorry, I have simply forgotten about that patch. I will commit it with this one.

Daniel

#5 lore raw
Quoted 115 lines · Daniel Kiper
Quoted 37 lines · Eric Snowberg
Quoted 37 lines · Daniel Kiper
Quoted 6 lines · Eric Snowberg

Fix the Open Firmware (OF) path property for sun4v SPARC systems. These platforms do not have a /sas/ within their path. Over time different OF addressing schemes have been supported. There is no generic addressing scheme that works across every HBA.

In general Reviewed-by: Daniel Kiper <[email protected]>...

Just a few comments below...

Quoted 12 lines

---
V2:
- Requested coding style changes
---
grub-core/osdep/linux/ofpath.c | 148 +++++++++++++++++++++++++++++++++++++++-

1 files changed, 145 insertions(+), 3 deletions(-)
grub-core/osdep/linux/ofpath.c +0 -0
index dce4e59..5369508 100644

grub-core/osdep/linux/ofpath.c line 41

Quoted 4 lines
grub-core/osdep/linux/ofpath.c +1 -0
@@ -38,6 +38,46 @@
 #include <errno.h>
 #include <ctype.h>
 
+#ifdef __sparc__

I have discussed this with Vladimir. It looks that this will not work if you try to cross-install SPARC GRUB2 binary using e.g. x86 grub-install. By default it should work. However, we will also have other issues here, like lack of access to OF firmware/paths, which make such configs unusable anyway. So, I would leave this patch as is for time being. If somebody cares then he/she should fix it.

Quoted 3 lines
Quoted 1 line

Anyway, I will add something like that into the commit message before committing.

That is fine with me.

Great! Thanks!

Quoted 68 lines
Quoted 67 lines
Quoted 54 lines
grub-core/osdep/linux/ofpath.c +39 -0
+typedef enum
+  {
+    GRUB_OFPATH_SPARC_WWN_ADDR = 1,
+    GRUB_OFPATH_SPARC_TGT_LUN,
+  } ofpath_sparc_addressing;
+
+struct ofpath_sparc_hba
+{
+  grub_uint32_t device_id;
+  ofpath_sparc_addressing addressing;
+};
+
+static struct ofpath_sparc_hba sparc_lsi_hba[] = {
+  /* Rhea, Jasper 320, LSI53C1020/1030. */
+  {0x30, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1068E. */
+  {0x50, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1064E. */
+  {0x56, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Pandora SAS-1068E. */
+  {0x58, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Aspen, Invader, LSI SAS-3108. */
+  {0x5d, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Niwot, SAS 2108. */
+  {0x79, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Erie, Falcon, LSI SAS 2008. */
+  {0x72, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI WarpDrive 6203. */
+  {0x7e, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 2308. */
+  {0x87, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 3008. */
+  {0x97, GRUB_OFPATH_SPARC_WWN_ADDR},
+  {0, 0}
+};
+
+static const int LSI_VENDOR_ID = 0x1000;
+#endif
+
 #ifdef OFPATH_STANDALONE
 #define xmalloc malloc

void

grub-core/osdep/linux/ofpath.c +8 -0
@@ -338,6 +378,67 @@ vendor_is_ATA(const char *path)
 return (memcmp(bufcont, "ATA", 3) == 0);
 }
 
+#ifdef __sparc__
+static void
+check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
+{
+  char *ed = strstr (sysfs_path, "host");
+  size_t path_size;
+  char *p, *path;
+  char buf[8];

grub-core/osdep/linux/ofpath.c vendor_is_ATA(const char *path) · line 398

Quoted 10 lines
grub-core/osdep/linux/ofpath.c +10 -0
+  int fd;
+
+  if (!ed)
+    return;
+
+  p = xstrdup (sysfs_path);
+  ed = strstr (p, "host");
+
+  if (!ed)
+    goto out;

In normal circumstances this will never ever fail. If you are OK I will drop this "if" before committing.

Quoted 7 lines
Quoted 2 lines

I put that in for the case if the xstrdup above can not allocate memory. Then p will be null, the strstr will fail and then we should jump to out.

If this would be the case then you should check p for NULL before strstr() call. AIUI its behavior is not well defined if one of arguments is NULL. Anyway, xstrdup() does not return if it fails. So, we do not have such problem here.

Ok, do you want to remove it? Or should I send out an updated patch?

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

If there are no objections I will commit this patch in a week or so.

Thanks…

Is there some reason this patch is being held up too?

http://lists.gnu.org/archive/html/grub-devel/2017-05/msg00045.html

Quoted 8 lines
Quoted 5 lines

This is where things last left off:

http://lists.gnu.org/archive/html/grub-devel/2017-10/msg00046.html

We really need minimal GPT support in there for many of the follow on patches in my queue.

Oh, sorry, I have simply forgotten about that patch. I will commit it with this one.

Thanks

#6 lore raw
Quoted 116 lines · Eric Snowberg
Quoted 116 lines · Daniel Kiper
Quoted 37 lines · Eric Snowberg
Quoted 37 lines · Daniel Kiper
Quoted 6 lines · Eric Snowberg

Fix the Open Firmware (OF) path property for sun4v SPARC systems. These platforms do not have a /sas/ within their path. Over time different OF addressing schemes have been supported. There is no generic addressing scheme that works across every HBA.

In general Reviewed-by: Daniel Kiper <[email protected]>...

Just a few comments below...

Quoted 12 lines

---
V2:
- Requested coding style changes
---
grub-core/osdep/linux/ofpath.c | 148 +++++++++++++++++++++++++++++++++++++++-

1 files changed, 145 insertions(+), 3 deletions(-)
grub-core/osdep/linux/ofpath.c +0 -0
index dce4e59..5369508 100644

grub-core/osdep/linux/ofpath.c line 41

Quoted 4 lines
grub-core/osdep/linux/ofpath.c +1 -0
@@ -38,6 +38,46 @@
 #include <errno.h>
 #include <ctype.h>
 
+#ifdef __sparc__

I have discussed this with Vladimir. It looks that this will not work if you try to cross-install SPARC GRUB2 binary using e.g. x86 grub-install. By default it should work. However, we will also have other issues here, like lack of access to OF firmware/paths, which make such configs unusable anyway. So, I would leave this patch as is for time being. If somebody cares then he/she should fix it.

Quoted 3 lines
Quoted 1 line

Anyway, I will add something like that into the commit message before committing.

That is fine with me.

Great! Thanks!

Quoted 70 lines
Quoted 59 lines
Quoted 59 lines
grub-core/osdep/linux/ofpath.c +39 -0
+typedef enum
+  {
+    GRUB_OFPATH_SPARC_WWN_ADDR = 1,
+    GRUB_OFPATH_SPARC_TGT_LUN,
+  } ofpath_sparc_addressing;
+
+struct ofpath_sparc_hba
+{
+  grub_uint32_t device_id;
+  ofpath_sparc_addressing addressing;
+};
+
+static struct ofpath_sparc_hba sparc_lsi_hba[] = {
+  /* Rhea, Jasper 320, LSI53C1020/1030. */
+  {0x30, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1068E. */
+  {0x50, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1064E. */
+  {0x56, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Pandora SAS-1068E. */
+  {0x58, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Aspen, Invader, LSI SAS-3108. */
+  {0x5d, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Niwot, SAS 2108. */
+  {0x79, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Erie, Falcon, LSI SAS 2008. */
+  {0x72, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI WarpDrive 6203. */
+  {0x7e, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 2308. */
+  {0x87, GRUB_OFPATH_SPARC_WWN_ADDR},
+  /* LSI SAS 3008. */
+  {0x97, GRUB_OFPATH_SPARC_WWN_ADDR},
+  {0, 0}
+};
+
+static const int LSI_VENDOR_ID = 0x1000;
+#endif
+
 #ifdef OFPATH_STANDALONE
 #define xmalloc malloc

void

grub-core/osdep/linux/ofpath.c +13 -0
@@ -338,6 +378,67 @@ vendor_is_ATA(const char *path)
 return (memcmp(bufcont, "ATA", 3) == 0);
 }
 
+#ifdef __sparc__
+static void
+check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
+{
+  char *ed = strstr (sysfs_path, "host");
+  size_t path_size;
+  char *p, *path;
+  char buf[8];
+  int fd;
+
+  if (!ed)
+    return;
+
Quoted 8 lines

grub-core/osdep/linux/ofpath.c vendor_is_ATA(const char *path) · line 398

Quoted 5 lines
grub-core/osdep/linux/ofpath.c +5 -0
+  p = xstrdup (sysfs_path);
+  ed = strstr (p, "host");
+
+  if (!ed)
+    goto out;

In normal circumstances this will never ever fail. If you are OK I will drop this "if" before committing.

I put that in for the case if the xstrdup above can not allocate memory. Then p will be null, the strstr will fail and then we should jump to out.

Quoted 6 lines
Quoted 4 lines

If this would be the case then you should check p for NULL before strstr() call. AIUI its behavior is not well defined if one of arguments is NULL. Anyway, xstrdup() does not return if it fails. So, we do not have such problem here.

Ok, do you want to remove it? Or should I send out an updated patch?

I will remove it before commit.

Daniel

#7 lore raw
Quoted 3 lines · Daniel Kiper
Quoted 1 line

Ok, do you want to remove it? Or should I send out an updated patch?

I will remove it before commit.

Is it going in today? ;-)

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#8 lore raw
Quoted 6 lines · John Paul Adrian Glaubitz
Quoted 3 lines · Daniel Kiper
Quoted 1 line

Ok, do you want to remove it? Or should I send out an updated patch?

I will remove it before commit.

Is it going in today? ;-)

Sadly no. I am busy with other stuff. I will apply this and other outstanding patches next week.

Daniel

#9 lore raw
Quoted 10 lines · Daniel Kiper
Quoted 6 lines · John Paul Adrian Glaubitz
Quoted 3 lines · Daniel Kiper
Quoted 1 line

Ok, do you want to remove it? Or should I send out an updated patch?

I will remove it before commit.

Is it going in today? ;-)

Sadly no. I am busy with other stuff. I will apply this and other outstanding patches next week.

Done!

Daniel