nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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