[openib-general] [PATCH] mstflint not working on ppc64 and when driver is not loaded on AMD

Tseng-Hui (Frank) Lin thlin at us.ibm.com
Wed Oct 4 09:26:41 PDT 2006


mmap() does not work on ppc64. The 64-bit machines with 32-bit I/O need
ioremap in device driver to allow mmap access to the I/O memory. This
patch checks the above situations and try to use PCI config to do the
firmware update when mmap() failed.

Signed-off-by: Tseng-Hui (Frank) Lin <thlin at us.ibm.com>

=======

-------------- next part --------------
diff -uPr mstflint.ofed-1.1r6/mtcr.h mstflint/mtcr.h
--- mstflint.ofed-1.1r6/mtcr.h	2006-09-17 10:46:21.000000000 -0500
+++ mstflint/mtcr.h	2006-10-03 10:29:38.000000000 -0500
@@ -294,6 +294,9 @@
   int err;
   char buf[]="0000:00:00.0";
   char path[]="/sys/bus/pci/devices/0000:00:00.0/resource0";
+  unsigned domain, bus, dev, func;
+  struct stat dummybuf;
+  char file_name[]="/proc/bus/pci/0000:00/00.0";
 
   mf=(mfile*)malloc(sizeof(mfile));
   if (!mf) return 0;
@@ -338,13 +341,14 @@
     mf->ptr = mmap(NULL, 0x100000, PROT_READ | PROT_WRITE,
         MAP_SHARED, mf->fd, 0);
 
-    if ( (! mf->ptr) || (mf->ptr == MAP_FAILED) ) goto map_failed;
+    if ( (! mf->ptr) || (mf->ptr == MAP_FAILED) || 
+        (__be32_to_cpu(*((u_int32_t *) ((char *) mf->ptr + 0xF0014))) == 0xFFFFFFFF) )
+        goto map_failed_try_pciconf;
   }
 #endif
   else
   {
 #if CONFIG_ENABLE_MMAP
-    unsigned bus, dev, func;
     if (mfind(name,&offset,&bus,&dev,&func)) goto find_failed;
 
 #if CONFIG_USE_DEV_MEM
@@ -352,8 +356,6 @@
     if (mf->fd<0) goto open_failed;
 #else
     {
-	    struct stat dummybuf;
-	    char file_name[]="/proc/bus/pci/0000:00/00.0";
 	    sprintf(file_name,"/proc/bus/pci/%2.2x/%2.2x.%1.1x",
 			    bus,dev,func);
 	    if (stat(file_name,&dummybuf))
@@ -369,7 +371,9 @@
     mf->ptr = mmap(NULL, 0x100000, PROT_READ | PROT_WRITE,
         MAP_SHARED, mf->fd, offset);
 
-    if ( (! mf->ptr) || (mf->ptr == MAP_FAILED) ) goto map_failed;
+    if ( (! mf->ptr) || (mf->ptr == MAP_FAILED) || 
+        (__be32_to_cpu(*((u_int32_t *) ((char *) mf->ptr + 0xF0014))) == 0xFFFFFFFF) )
+        goto map_failed_try_pciconf;
 
 #else
     goto open_failed;
@@ -379,6 +383,20 @@
 
 
 #if CONFIG_ENABLE_MMAP
+map_failed_try_pciconf:
+#if CONFIG_ENABLE_PCICONF
+	mf->ptr = NULL;
+	close(mf->fd);
+	if (sscanf(name, "%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) {
+		domain = 0;
+		if (sscanf(name, "%x:%x.%x", &bus, &dev, &func) != 3) goto map_failed;
+	}
+	snprintf(file_name, sizeof file_name, "/proc/bus/pci/%2.2x/%2.2x.%1.1x", bus, dev, func);
+	if (stat(file_name,&dummybuf))
+		snprintf(file_name, sizeof file_name, "/proc/bus/pci/%4.4x:%2.2x/%2.2x.%1.1x", domain, bus,dev,func);
+	if ((mf->fd = open(file_name, O_RDWR | O_SYNC)) >= 0) return mf;
+#endif
+
 map_failed:
 #if !CONFIG_USE_DEV_MEM
 ioctl_failed:


More information about the general mailing list