ofpath: Add support for ethernet and HFI devices
authorBrian King <brking@linux.vnet.ibm.com>
Tue, 23 Aug 2011 04:45:14 +0000 (04:45 +0000)
committerTony Breeds <tony@bakeyournoodle.com>
Tue, 18 Oct 2011 04:38:09 +0000 (15:38 +1100)
Adds support for HFI and ethernet devices to ofpath for
IBM Power Systems.

Signed-off-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
ybin/ofpath

index 1bb33babff635a3731a5157860fb83330c9b3212..1a601bbc4a6532576a698726dcfcfb593991c122 100755 (executable)
@@ -880,6 +880,29 @@ oldworld()
     return 0
 }
 
+eth_ofpath()
+{
+        read_attr devspec /sys/class/net/$DEVICE/device
+}
+
+hfi_ofpath()
+{
+        local hfnum=${DEVICE##hf}
+        local hfpath
+
+        if [[ $hfnum = "0" || $hfnum = "2" ]]; then
+                hfpath=$(find /proc/device-tree -name hfi-ethernet* | sort | head -n 1)
+        elif [[ $hfnum = "1" || $hfnum = "3" ]]; then
+                hfpath=$(find /proc/device-tree -name hfi-ethernet* | sort | tail -n 1)
+        else
+               echo 1>&2 "$PRG: Unsupported device: $DEVICE"
+               return 1
+        fi
+
+        hfpath=${hfpath##/proc/device-tree}
+        echo "$hfpath"
+}
+
 ## find OpenFirmware device path for IBM CHRP hardware (scsi only)
 chrp()
 {
@@ -893,6 +916,12 @@ chrp()
            ## find the actual OF path.
            scsi_ofpath || return 1
            ;;
+       eth*)
+           eth_ofpath || return 1
+           ;;
+       hfi*)
+           hfi_ofpath || return 1
+           ;;
        *)
            echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
            return 1
@@ -1084,15 +1113,6 @@ else
     exit 1
 fi
 
-## check that FILE is a block device and exists.
-if [ ! -e "$device" ] ; then
-    echo 1>&2 "$PRG: $device: No such file or directory"
-    exit 1
-elif [ ! -b "$device" ] ; then
-    echo 1>&2 "$PRG: $device is not a block device"
-    exit 1
-fi
-
 ## check that we are running on a GNU/Linux system, OSX/BSD does not
 ## have the same /proc stuff
 if [ `uname -s` != Linux ] ; then