[ewg] [PATCH] [REPOST] ofed_scripts: Add location code fix for older ppc64 kernels

Joachim Fenkes fenkes at de.ibm.com
Fri Nov 2 05:59:12 PDT 2007


Kernels prior to 2.6.24 have problems with multiple devices sharing the same
location code on ppc64 systems -- only one of these devices would be usable
by ibmebus. This will be a problem on systems with multiple eHCA chips on a
single hardware location.

For older kernels, this problem can be circumvented by, prior to loading the
eHCA driver, changing the location codes of the offending devices so that
they're not the same anymore. This patch adds that circumvention to openibd,
with an additional check to make sure we're on the right architecture and
kernel version.

Signed-off-by: Joachim Fenkes <fenkes at de.ibm.com>
---

This is a repost of my previous patch, with the changes suggested by
Vladimir included.

 ofed_scripts/openibd |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/ofed_scripts/openibd b/ofed_scripts/openibd
index cf4aee1..2cca88a 100755
--- a/ofed_scripts/openibd
+++ b/ofed_scripts/openibd
@@ -538,6 +538,74 @@ if test -x /sbin/lspci && test -x /sbin/setpci; then
 fi
 }
 
+need_location_code_fix()
+{
+	local sub ARCH KVERSION
+	ARCH=$(uname -m)
+	KVERSION=$(uname -r)
+
+	if [ "$ARCH" != "ppc64" ]; then
+		return 1;
+	fi
+
+	case $KVERSION in
+	2.6.9-*.EL*)
+		sub=$(echo $KVERSION | cut -d"-" -f2 | cut -d"." -f1)
+		if [ $sub -lt 62 ]; then
+			return 0;
+		fi
+	;;
+	2.6.16.*-*-*)
+		sub=$(echo $KVERSION | cut -d"." -f4 | cut -d"-" -f1)
+		if [ $sub -lt 53 ]; then
+			return 0;
+		fi
+	;;
+	2.6.18-*.el5*)
+		sub=$(echo $KVERSION | cut -d"-" -f2 | cut -d"." -f1)
+		if [ $sub -lt 54 ]; then
+			return 0;
+		fi
+	;;
+	2.6.*)
+		sub=$(echo $KVERSION | cut -d"." -f3 | cut -d"-" -f1 | tr -d [:alpha:][:punct:])
+		if [ $sub -lt 24 ]; then
+			return 0;
+		fi
+	;;
+	esac
+
+	return 1;
+}
+
+fix_location_codes()
+{
+	# ppc64 only:
+	# Fix duplicate location codes on kernels where ibmebus can't handle them
+
+	if ! need_location_code_fix; then return 0; fi
+	if ! [ -d /proc/device-tree -a -f /proc/ppc64/ofdt ]; then return 0; fi
+
+	local i=1 phandle lcode len
+	# output all duplicate location codes and their devices
+	for attr in $(find /proc/device-tree -wholename "*lhca\@*/ibm,loc-code"); do
+		echo -e $(dirname $attr)"\t"$(cat $attr)
+	done | sort -k2 | uniq -f1 --all-repeated=separate | cut -f1 | while read dev; do
+		if [ -n "$dev" ]; then
+			# append an instance counter to the location code
+			phandle=$(hexdump -e '8 "%u"' $dev/ibm,phandle)
+			lcode=$(cat $dev/ibm,loc-code)-I$i
+			len=$(echo -n "$lcode" | wc -c)
+			# echo "$dev -> $lcode"
+			echo -n "update_property $phandle ibm,loc-code $len $lcode" > /proc/ppc64/ofdt
+			i=$(($i + 1))
+		else
+			# empty line means new group -- reset i
+			i=1
+		fi
+	done
+}
+
 rotate_log()
 {
         local log=$1
@@ -694,6 +762,7 @@ start()
 
     # Load eHCA driver
     if [ "X${EHCA_LOAD}" == "Xyes" ]; then
+        fix_location_codes
         /sbin/modprobe ib_ehca > /dev/null 2>&1
         my_rc=$?
         if [ $my_rc -ne 0 ]; then
-- 
1.5.2






More information about the ewg mailing list