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

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