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