Blame SOURCES/0326-ieee1275-powerpc-implements-fibre-channel-discovery-.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Diego Domingos <diegodo@br.ibm.com>
80913e
Date: Mon, 14 Dec 2020 17:45:28 +0100
80913e
Subject: [PATCH] ieee1275/powerpc: implements fibre channel discovery for
80913e
 ofpathname
80913e
80913e
grub-ofpathname doesn't work with fibre channel because there is no
80913e
function currently implemented for it.
80913e
This patch enables it by prividing a function that looks for the port
80913e
name, building the entire path for OF devices.
80913e
80913e
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
80913e
---
80913e
 grub-core/osdep/linux/ofpath.c | 49 ++++++++++++++++++++++++++++++++++++++++++
80913e
 1 file changed, 49 insertions(+)
80913e
80913e
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
80913e
index a6153d35954..0f5d54e9f2d 100644
80913e
--- a/grub-core/osdep/linux/ofpath.c
80913e
+++ b/grub-core/osdep/linux/ofpath.c
80913e
@@ -350,6 +350,38 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
80913e
   return ret;
80913e
 }
80913e
 
80913e
+
80913e
+static void
80913e
+of_fc_port_name(const char *path, const char *subpath, char *port_name)
80913e
+{
80913e
+  char *bname, *basepath, *p;
80913e
+  int fd;
80913e
+
80913e
+  bname = xmalloc(sizeof(char)*150);
80913e
+  basepath = xmalloc(strlen(path));
80913e
+
80913e
+  /* Generate the path to get port name information from the drive */
80913e
+  strncpy(basepath,path,subpath-path);
80913e
+  basepath[subpath-path-1] = '\0';
80913e
+  p = get_basename(basepath);
80913e
+  snprintf(bname,sizeof(char)*150,"%s/fc_transport/%s/port_name",basepath,p);
80913e
+
80913e
+  /* Read the information from the port name */
80913e
+  fd = open (bname, O_RDONLY);
80913e
+  if (fd < 0)
80913e
+    grub_util_error (_("cannot open `%s': %s"), bname, strerror (errno));
80913e
+
80913e
+  if (read(fd,port_name,sizeof(char)*19) < 0)
80913e
+    grub_util_error (_("cannot read `%s': %s"), bname, strerror (errno));
80913e
+
80913e
+  sscanf(port_name,"0x%s",port_name);
80913e
+  
80913e
+  close(fd);
80913e
+
80913e
+  free(bname);
80913e
+  free(basepath);
80913e
+}
80913e
+
80913e
 #ifdef __sparc__
80913e
 static char *
80913e
 of_path_of_nvme(const char *sys_devname __attribute__((unused)),
80913e
@@ -577,6 +609,16 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
80913e
   digit_string = trailing_digits (device);
80913e
   if (strncmp (of_path, "/vdevice/", sizeof ("/vdevice/") - 1) == 0)
80913e
     {
80913e
+      if(strstr(of_path,"vfc-client"))
80913e
+      {
80913e
+	char * port_name = xmalloc(sizeof(char)*17);
80913e
+	of_fc_port_name(sysfs_path, p, port_name);
80913e
+	
80913e
+	snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
80913e
+	free(port_name);
80913e
+      }
80913e
+      else
80913e
+      {
80913e
       unsigned long id = 0x8000 | (tgt << 8) | (bus << 5) | lun;
80913e
       if (*digit_string == '\0')
80913e
 	{
80913e
@@ -590,6 +632,13 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
80913e
 	  snprintf(disk, sizeof (disk),
80913e
 		   "/%s@%04lx000000000000:%c", disk_name, id, 'a' + (part - 1));
80913e
 	}
80913e
+	}
80913e
+    } else if (strstr(of_path,"fibre-channel")||(strstr(of_path,"vfc-client"))){
80913e
+	char * port_name = xmalloc(sizeof(char)*17);
80913e
+	of_fc_port_name(sysfs_path, p, port_name);
80913e
+	
80913e
+	snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
80913e
+	free(port_name);
80913e
     }
80913e
   else
80913e
     {