[Endpoint-commits] rev 7 - in trunk: . libsbp2 libscsidisk src

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Jul 4 10:15:16 CDT 2003


Author: manish
Date: 2003-07-04 04:15:09 -0500 (Fri, 04 Jul 2003)
New Revision: 7

Added:
   trunk/Config.make.in
   trunk/Makefile
   trunk/autogen.sh
   trunk/config.guess
   trunk/config.sub
   trunk/configure.in
   trunk/install-sh
   trunk/libsbp2/sbp2.c
   trunk/libsbp2/sbp2.h
   trunk/libsbp2/sbp2raw.c
   trunk/libsbp2/sbp2raw.h
   trunk/libscsidisk/Makefile
   trunk/libscsidisk/commands.h
   trunk/libscsidisk/libscsidisk.c
   trunk/libscsidisk/libscsidisk.h
   trunk/mkinstalldirs
   trunk/src/Makefile
   trunk/src/configrom.c
   trunk/src/configrom.h
   trunk/src/main.c
   trunk/src/raw1394util.c
   trunk/src/raw1394util.h
Log:
checkpoint


Added: trunk/Config.make.in
==============================================================================
--- trunk/Config.make.in	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/Config.make.in	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,43 @@
+PACKAGE = @PACKAGE@
+VERSION = @VERSION@
+
+DIST_VERSION = @DIST_VERSION@
+
+MAJOR_VERSION = @MAJOR_VERSION@
+MINOR_VERSION = @MINOR_VERSION@
+MICRO_VERSION = @MICRO_VERSION@
+
+SHELL = @SHELL@
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+mandir = @mandir@
+
+top_builddir = .
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+
+LN_S = @LN_S@
+
+CC = @CC@
+CPP = @CPP@
+AR = @AR@
+RANLIB = @RANLIB@
+
+CFLAGS = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+
+GLIB_CFLAGS = @GLIB_CFLAGS@
+GLIB_LIBS = @GLIB_LIBS@
+
+LIBRAW1394_CPPFLAGS = @LIBRAW1394_CPPFLAGS@
+LIBRAW1394_CFLAGS = @LIBRAW1394_CFLAGS@
+LIBRAW1394_LIBS = @LIBRAW1394_LIBS@

Added: trunk/Makefile
==============================================================================
--- trunk/Makefile	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/Makefile	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,7 @@
+TOPDIR = .
+
+include $(TOPDIR)/Preamble.make
+
+SUBDIRS = libscsitgt libsbp2 src
+
+include $(TOPDIR)/Postamble.make

Added: trunk/autogen.sh
==============================================================================
--- trunk/autogen.sh	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/autogen.sh	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+aclocal
+autoconf
+./configure "$@"

Added: trunk/config.guess
==============================================================================
--- trunk/config.guess	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/config.guess	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,1391 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+
+timestamp='2003-05-19'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Originally written by Per Bothner <per at bothner.com>.
+# Please send patches to <config-patches at gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# This script attempts to guess a canonical system name similar to
+# config.sub.  If it succeeds, it prints the system name on stdout, and
+# exits with 0.  Otherwise, it exits with 1.
+#
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit build system type.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches at gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit 0 ;;
+    --version | -v )
+       echo "$version" ; exit 0 ;;
+    --help | --h* | -h )
+       echo "$usage"; exit 0 ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+    * )
+       break ;;
+  esac
+done
+
+if test $# != 0; then
+  echo "$me: too many arguments$help" >&2
+  exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,)    echo "int x;" > $dummy.c ;
+	for c in cc gcc c89 c99 ; do
+	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+	     CC_FOR_BUILD="$c"; break ;
+	  fi ;
+	done ;
+	if test x"$CC_FOR_BUILD" = x ; then
+	  CC_FOR_BUILD=no_compiler_found ;
+	fi
+	;;
+ ,,*)   CC_FOR_BUILD=$CC ;;
+ ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi at noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+	PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+	# NetBSD (nbsd) targets should (where applicable) match one or
+	# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
+	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+	# switched to ELF, *-*-netbsd* would select the old
+	# object file format.  This provides both forward
+	# compatibility and a consistent mechanism for selecting the
+	# object file format.
+	#
+	# Note: NetBSD doesn't particularly care about the vendor
+	# portion of the name.  We always set it to "unknown".
+	sysctl="sysctl -n hw.machine_arch"
+	UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
+	    /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+	case "${UNAME_MACHINE_ARCH}" in
+	    armeb) machine=armeb-unknown ;;
+	    arm*) machine=arm-unknown ;;
+	    sh3el) machine=shl-unknown ;;
+	    sh3eb) machine=sh-unknown ;;
+	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+	esac
+	# The Operating System including object format, if it has switched
+	# to ELF recently, or will in the future.
+	case "${UNAME_MACHINE_ARCH}" in
+	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+		eval $set_cc_for_build
+		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+			| grep __ELF__ >/dev/null
+		then
+		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+		    # Return netbsd for either.  FIX?
+		    os=netbsd
+		else
+		    os=netbsdelf
+		fi
+		;;
+	    *)
+	        os=netbsd
+		;;
+	esac
+	# The OS release
+	# Debian GNU/NetBSD machines have a different userland, and
+	# thus, need a distinct triplet. However, they do not need
+	# kernel version information, so it can be replaced with a
+	# suitable tag, in the style of linux-gnu.
+	case "${UNAME_VERSION}" in
+	    Debian*)
+		release='-gnu'
+		;;
+	    *)
+		release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+		;;
+	esac
+	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+	# contains redundant information, the shorter form:
+	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+	echo "${machine}-${os}${release}"
+	exit 0 ;;
+    amiga:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    arc:OpenBSD:*:*)
+	echo mipsel-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    hp300:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    mac68k:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    macppc:OpenBSD:*:*)
+	echo powerpc-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    mvme68k:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    mvme88k:OpenBSD:*:*)
+	echo m88k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    mvmeppc:OpenBSD:*:*)
+	echo powerpc-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    pmax:OpenBSD:*:*)
+	echo mipsel-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    sgi:OpenBSD:*:*)
+	echo mipseb-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    sun3:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    wgrisc:OpenBSD:*:*)
+	echo mipsel-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    *:OpenBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    alpha:OSF1:*:*)
+	if test $UNAME_RELEASE = "V4.0"; then
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+	fi
+	# According to Compaq, /usr/sbin/psrinfo has been available on
+	# OSF/1 and Tru64 systems produced since 1995.  I hope that
+	# covers most systems running today.  This code pipes the CPU
+	# types through head -n 1, so we only detect the type of CPU 0.
+	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+	case "$ALPHA_CPU_TYPE" in
+	    "EV4 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV4.5 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "LCA4 (21066/21068)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV5 (21164)")
+		UNAME_MACHINE="alphaev5" ;;
+	    "EV5.6 (21164A)")
+		UNAME_MACHINE="alphaev56" ;;
+	    "EV5.6 (21164PC)")
+		UNAME_MACHINE="alphapca56" ;;
+	    "EV5.7 (21164PC)")
+		UNAME_MACHINE="alphapca57" ;;
+	    "EV6 (21264)")
+		UNAME_MACHINE="alphaev6" ;;
+	    "EV6.7 (21264A)")
+		UNAME_MACHINE="alphaev67" ;;
+	    "EV6.8CB (21264C)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8AL (21264B)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8CX (21264D)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.9A (21264/EV69A)")
+		UNAME_MACHINE="alphaev69" ;;
+	    "EV7 (21364)")
+		UNAME_MACHINE="alphaev7" ;;
+	    "EV7.9 (21364A)")
+		UNAME_MACHINE="alphaev79" ;;
+	esac
+	# A Vn.n version is a released version.
+	# A Tn.n version is a released field test version.
+	# A Xn.n version is an unreleased experimental baselevel.
+	# 1.2 uses "1.2" for uname -r.
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	exit 0 ;;
+    Alpha\ *:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# Should we change UNAME_MACHINE based on the output of uname instead
+	# of the specific Alpha model?
+	echo alpha-pc-interix
+	exit 0 ;;
+    21064:Windows_NT:50:3)
+	echo alpha-dec-winnt3.5
+	exit 0 ;;
+    Amiga*:UNIX_System_V:4.0:*)
+	echo m68k-unknown-sysv4
+	exit 0;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-amigaos
+	exit 0 ;;
+    *:[Mm]orph[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-morphos
+	exit 0 ;;
+    *:OS/390:*:*)
+	echo i370-ibm-openedition
+	exit 0 ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+	echo arm-acorn-riscix${UNAME_RELEASE}
+	exit 0;;
+    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+	echo hppa1.1-hitachi-hiuxmpp
+	exit 0;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+	# akee at wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+	if test "`(/bin/universe) 2>/dev/null`" = att ; then
+		echo pyramid-pyramid-sysv3
+	else
+		echo pyramid-pyramid-bsd
+	fi
+	exit 0 ;;
+    NILE*:*:*:dcosx)
+	echo pyramid-pyramid-svr4
+	exit 0 ;;
+    DRS?6000:UNIX_SV:4.2*:7*)
+	case `/usr/bin/uname -p` in
+	    sparc) echo sparc-icl-nx7 && exit 0 ;;
+	esac ;;
+    sun4H:SunOS:5.*:*)
+	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit 0 ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit 0 ;;
+    i86pc:SunOS:5.*:*)
+	echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit 0 ;;
+    sun4*:SunOS:6*:*)
+	# According to config.sub, this is the proper way to canonicalize
+	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+	# it's likely to be more like Solaris than SunOS4.
+	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit 0 ;;
+    sun4*:SunOS:*:*)
+	case "`/usr/bin/arch -k`" in
+	    Series*|S4*)
+		UNAME_RELEASE=`uname -v`
+		;;
+	esac
+	# Japanese Language versions have a version number like `4.1.3-JL'.
+	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+	exit 0 ;;
+    sun3*:SunOS:*:*)
+	echo m68k-sun-sunos${UNAME_RELEASE}
+	exit 0 ;;
+    sun*:*:4.2BSD:*)
+	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+	case "`/bin/arch`" in
+	    sun3)
+		echo m68k-sun-sunos${UNAME_RELEASE}
+		;;
+	    sun4)
+		echo sparc-sun-sunos${UNAME_RELEASE}
+		;;
+	esac
+	exit 0 ;;
+    aushp:SunOS:*:*)
+	echo sparc-auspex-sunos${UNAME_RELEASE}
+	exit 0 ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+	exit 0 ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+        exit 0 ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+	exit 0 ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+        echo m68k-milan-mint${UNAME_RELEASE}
+        exit 0 ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+        echo m68k-hades-mint${UNAME_RELEASE}
+        exit 0 ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+        echo m68k-unknown-mint${UNAME_RELEASE}
+        exit 0 ;;
+    powerpc:machten:*:*)
+	echo powerpc-apple-machten${UNAME_RELEASE}
+	exit 0 ;;
+    RISC*:Mach:*:*)
+	echo mips-dec-mach_bsd4.3
+	exit 0 ;;
+    RISC*:ULTRIX:*:*)
+	echo mips-dec-ultrix${UNAME_RELEASE}
+	exit 0 ;;
+    VAX*:ULTRIX*:*:*)
+	echo vax-dec-ultrix${UNAME_RELEASE}
+	exit 0 ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+	echo clipper-intergraph-clix${UNAME_RELEASE}
+	exit 0 ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+	int main (int argc, char *argv[]) {
+#else
+	int main (argc, argv) int argc; char *argv[]; {
+#endif
+	#if defined (host_mips) && defined (MIPSEB)
+	#if defined (SYSTYPE_SYSV)
+	  printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_SVR4)
+	  printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+	  printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+	#endif
+	#endif
+	  exit (-1);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c \
+	  && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
+	  && exit 0
+	echo mips-mips-riscos${UNAME_RELEASE}
+	exit 0 ;;
+    Motorola:PowerMAX_OS:*:*)
+	echo powerpc-motorola-powermax
+	exit 0 ;;
+    Motorola:*:4.3:PL8-*)
+	echo powerpc-harris-powermax
+	exit 0 ;;
+    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+	echo powerpc-harris-powermax
+	exit 0 ;;
+    Night_Hawk:Power_UNIX:*:*)
+	echo powerpc-harris-powerunix
+	exit 0 ;;
+    m88k:CX/UX:7*:*)
+	echo m88k-harris-cxux7
+	exit 0 ;;
+    m88k:*:4*:R4*)
+	echo m88k-motorola-sysv4
+	exit 0 ;;
+    m88k:*:3*:R3*)
+	echo m88k-motorola-sysv3
+	exit 0 ;;
+    AViiON:dgux:*:*)
+        # DG/UX returns AViiON for all architectures
+        UNAME_PROCESSOR=`/usr/bin/uname -p`
+	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+	then
+	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+	       [ ${TARGET_BINARY_INTERFACE}x = x ]
+	    then
+		echo m88k-dg-dgux${UNAME_RELEASE}
+	    else
+		echo m88k-dg-dguxbcs${UNAME_RELEASE}
+	    fi
+	else
+	    echo i586-dg-dgux${UNAME_RELEASE}
+	fi
+ 	exit 0 ;;
+    M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
+	echo m88k-dolphin-sysv3
+	exit 0 ;;
+    M88*:*:R3*:*)
+	# Delta 88k system running SVR3
+	echo m88k-motorola-sysv3
+	exit 0 ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+	echo m88k-tektronix-sysv3
+	exit 0 ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+	echo m68k-tektronix-bsd
+	exit 0 ;;
+    *:IRIX*:*:*)
+	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+	exit 0 ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+	echo romp-ibm-aix      # uname -m gives an 8 hex-code CPU id
+	exit 0 ;;              # Note that: echo "'`uname -s`'" gives 'AIX '
+    i*86:AIX:*:*)
+	echo i386-ibm-aix
+	exit 0 ;;
+    ia64:AIX:*:*)
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+	exit 0 ;;
+    *:AIX:2:3)
+	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+		eval $set_cc_for_build
+		sed 's/^		//' << EOF >$dummy.c
+		#include <sys/systemcfg.h>
+
+		main()
+			{
+			if (!__power_pc())
+				exit(1);
+			puts("powerpc-ibm-aix3.2.5");
+			exit(0);
+			}
+EOF
+		$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
+		echo rs6000-ibm-aix3.2.5
+	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+		echo rs6000-ibm-aix3.2.4
+	else
+		echo rs6000-ibm-aix3.2
+	fi
+	exit 0 ;;
+    *:AIX:*:[45])
+	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+		IBM_ARCH=rs6000
+	else
+		IBM_ARCH=powerpc
+	fi
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+	exit 0 ;;
+    *:AIX:*:*)
+	echo rs6000-ibm-aix
+	exit 0 ;;
+    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+	echo romp-ibm-bsd4.4
+	exit 0 ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+	exit 0 ;;                           # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+	echo rs6000-bull-bosx
+	exit 0 ;;
+    DPX/2?00:B.O.S.:*:*)
+	echo m68k-bull-sysv3
+	exit 0 ;;
+    9000/[34]??:4.3bsd:1.*:*)
+	echo m68k-hp-bsd
+	exit 0 ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+	echo m68k-hp-bsd4.4
+	exit 0 ;;
+    9000/[34678]??:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	case "${UNAME_MACHINE}" in
+	    9000/31? )            HP_ARCH=m68000 ;;
+	    9000/[34]?? )         HP_ARCH=m68k ;;
+	    9000/[678][0-9][0-9])
+		if [ -x /usr/bin/getconf ]; then
+		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+                    case "${sc_cpu_version}" in
+                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+                      532)                      # CPU_PA_RISC2_0
+                        case "${sc_kernel_bits}" in
+                          32) HP_ARCH="hppa2.0n" ;;
+                          64) HP_ARCH="hppa2.0w" ;;
+			  '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
+                        esac ;;
+                    esac
+		fi
+		if [ "${HP_ARCH}" = "" ]; then
+		    eval $set_cc_for_build
+		    sed 's/^              //' << EOF >$dummy.c
+
+              #define _HPUX_SOURCE
+              #include <stdlib.h>
+              #include <unistd.h>
+
+              int main ()
+              {
+              #if defined(_SC_KERNEL_BITS)
+                  long bits = sysconf(_SC_KERNEL_BITS);
+              #endif
+                  long cpu  = sysconf (_SC_CPU_VERSION);
+
+                  switch (cpu)
+              	{
+              	case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+              	case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+              	case CPU_PA_RISC2_0:
+              #if defined(_SC_KERNEL_BITS)
+              	    switch (bits)
+              		{
+              		case 64: puts ("hppa2.0w"); break;
+              		case 32: puts ("hppa2.0n"); break;
+              		default: puts ("hppa2.0"); break;
+              		} break;
+              #else  /* !defined(_SC_KERNEL_BITS) */
+              	    puts ("hppa2.0"); break;
+              #endif
+              	default: puts ("hppa1.0"); break;
+              	}
+                  exit (0);
+              }
+EOF
+		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+		    test -z "$HP_ARCH" && HP_ARCH=hppa
+		fi ;;
+	esac
+	if [ ${HP_ARCH} = "hppa2.0w" ]
+	then
+	    # avoid double evaluation of $set_cc_for_build
+	    test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
+	    then
+		HP_ARCH="hppa2.0w"
+	    else
+		HP_ARCH="hppa64"
+	    fi
+	fi
+	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+	exit 0 ;;
+    ia64:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	echo ia64-hp-hpux${HPUX_REV}
+	exit 0 ;;
+    3050*:HI-UX:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <unistd.h>
+	int
+	main ()
+	{
+	  long cpu = sysconf (_SC_CPU_VERSION);
+	  /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+	     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+	     results, however.  */
+	  if (CPU_IS_PA_RISC (cpu))
+	    {
+	      switch (cpu)
+		{
+		  case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+		  default: puts ("hppa-hitachi-hiuxwe2"); break;
+		}
+	    }
+	  else if (CPU_IS_HP_MC68K (cpu))
+	    puts ("m68k-hitachi-hiuxwe2");
+	  else puts ("unknown-hitachi-hiuxwe2");
+	  exit (0);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
+	echo unknown-hitachi-hiuxwe2
+	exit 0 ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+	echo hppa1.1-hp-bsd
+	exit 0 ;;
+    9000/8??:4.3bsd:*:*)
+	echo hppa1.0-hp-bsd
+	exit 0 ;;
+    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+	echo hppa1.0-hp-mpeix
+	exit 0 ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+	echo hppa1.1-hp-osf
+	exit 0 ;;
+    hp8??:OSF1:*:*)
+	echo hppa1.0-hp-osf
+	exit 0 ;;
+    i*86:OSF1:*:*)
+	if [ -x /usr/sbin/sysversion ] ; then
+	    echo ${UNAME_MACHINE}-unknown-osf1mk
+	else
+	    echo ${UNAME_MACHINE}-unknown-osf1
+	fi
+	exit 0 ;;
+    parisc*:Lites*:*:*)
+	echo hppa1.1-hp-lites
+	exit 0 ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+	echo c1-convex-bsd
+        exit 0 ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+        exit 0 ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+	echo c34-convex-bsd
+        exit 0 ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+	echo c38-convex-bsd
+        exit 0 ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+	echo c4-convex-bsd
+        exit 0 ;;
+    CRAY*Y-MP:*:*:*)
+	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit 0 ;;
+    CRAY*[A-Z]90:*:*:*)
+	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+	      -e 's/\.[^.]*$/.X/'
+	exit 0 ;;
+    CRAY*TS:*:*:*)
+	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit 0 ;;
+    CRAY*T3E:*:*:*)
+	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit 0 ;;
+    CRAY*SV1:*:*:*)
+	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit 0 ;;
+    *:UNICOS/mp:*:*)
+	echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 
+	exit 0 ;;
+    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+        exit 0 ;;
+    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+	exit 0 ;;
+    sparc*:BSD/OS:*:*)
+	echo sparc-unknown-bsdi${UNAME_RELEASE}
+	exit 0 ;;
+    *:BSD/OS:*:*)
+	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+	exit 0 ;;
+    *:FreeBSD:*:*|*:GNU/FreeBSD:*:*)
+	# Determine whether the default compiler uses glibc.
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <features.h>
+	#if __GLIBC__ >= 2
+	LIBC=gnu
+	#else
+	LIBC=
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
+	echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
+	exit 0 ;;
+    i*:CYGWIN*:*)
+	echo ${UNAME_MACHINE}-pc-cygwin
+	exit 0 ;;
+    i*:MINGW*:*)
+	echo ${UNAME_MACHINE}-pc-mingw32
+	exit 0 ;;
+    i*:PW*:*)
+	echo ${UNAME_MACHINE}-pc-pw32
+	exit 0 ;;
+    x86:Interix*:3*)
+	echo i586-pc-interix3
+	exit 0 ;;
+    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+	echo i${UNAME_MACHINE}-pc-mks
+	exit 0 ;;
+    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+	# UNAME_MACHINE based on the output of uname instead of i386?
+	echo i586-pc-interix
+	exit 0 ;;
+    i*:UWIN*:*)
+	echo ${UNAME_MACHINE}-pc-uwin
+	exit 0 ;;
+    p*:CYGWIN*:*)
+	echo powerpcle-unknown-cygwin
+	exit 0 ;;
+    prep*:SunOS:5.*:*)
+	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit 0 ;;
+    *:GNU:*:*)
+	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+	exit 0 ;;
+    i*86:Minix:*:*)
+	echo ${UNAME_MACHINE}-pc-minix
+	exit 0 ;;
+    arm*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
+    cris:Linux:*:*)
+	echo cris-axis-linux-gnu
+	exit 0 ;;
+    ia64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
+    m68*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
+    mips:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips
+	#undef mipsel
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mipsel
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
+	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	;;
+    mips64:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips64
+	#undef mips64el
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mips64el
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips64
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
+	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	;;
+    ppc:Linux:*:*)
+	echo powerpc-unknown-linux-gnu
+	exit 0 ;;
+    ppc64:Linux:*:*)
+	echo powerpc64-unknown-linux-gnu
+	exit 0 ;;
+    alpha:Linux:*:*)
+	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	  EV5)   UNAME_MACHINE=alphaev5 ;;
+	  EV56)  UNAME_MACHINE=alphaev56 ;;
+	  PCA56) UNAME_MACHINE=alphapca56 ;;
+	  PCA57) UNAME_MACHINE=alphapca56 ;;
+	  EV6)   UNAME_MACHINE=alphaev6 ;;
+	  EV67)  UNAME_MACHINE=alphaev67 ;;
+	  EV68*) UNAME_MACHINE=alphaev68 ;;
+        esac
+	objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
+	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
+	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
+	exit 0 ;;
+    parisc:Linux:*:* | hppa:Linux:*:*)
+	# Look for CPU level
+	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+	  PA7*) echo hppa1.1-unknown-linux-gnu ;;
+	  PA8*) echo hppa2.0-unknown-linux-gnu ;;
+	  *)    echo hppa-unknown-linux-gnu ;;
+	esac
+	exit 0 ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+	echo hppa64-unknown-linux-gnu
+	exit 0 ;;
+    s390:Linux:*:* | s390x:Linux:*:*)
+	echo ${UNAME_MACHINE}-ibm-linux
+	exit 0 ;;
+    sh*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
+    sparc:Linux:*:* | sparc64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
+    x86_64:Linux:*:*)
+	echo x86_64-unknown-linux-gnu
+	exit 0 ;;
+    i*86:Linux:*:*)
+	# The BFD linker knows what the default object file format is, so
+	# first see if it will tell us. cd to the root directory to prevent
+	# problems with other programs or directories called `ld' in the path.
+	# Set LC_ALL=C to ensure ld outputs messages in English.
+	ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
+			 | sed -ne '/supported targets:/!d
+				    s/[ 	][ 	]*/ /g
+				    s/.*supported targets: *//
+				    s/ .*//
+				    p'`
+        case "$ld_supported_targets" in
+	  elf32-i386)
+		TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
+		;;
+	  a.out-i386-linux)
+		echo "${UNAME_MACHINE}-pc-linux-gnuaout"
+		exit 0 ;;
+	  coff-i386)
+		echo "${UNAME_MACHINE}-pc-linux-gnucoff"
+		exit 0 ;;
+	  "")
+		# Either a pre-BFD a.out linker (linux-gnuoldld) or
+		# one that does not give us useful --help.
+		echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
+		exit 0 ;;
+	esac
+	# Determine whether the default compiler is a.out or elf
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <features.h>
+	#ifdef __ELF__
+	# ifdef __GLIBC__
+	#  if __GLIBC__ >= 2
+	LIBC=gnu
+	#  else
+	LIBC=gnulibc1
+	#  endif
+	# else
+	LIBC=gnulibc1
+	# endif
+	#else
+	#ifdef __INTEL_COMPILER
+	LIBC=gnu
+	#else
+	LIBC=gnuaout
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
+	test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
+	test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
+	;;
+    i*86:DYNIX/ptx:4*:*)
+	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+	# earlier versions are messed up and put the nodename in both
+	# sysname and nodename.
+	echo i386-sequent-sysv4
+	exit 0 ;;
+    i*86:UNIX_SV:4.2MP:2.*)
+        # Unixware is an offshoot of SVR4, but it has its own version
+        # number series starting with 2...
+        # I am not positive that other SVR4 systems won't match this,
+	# I just have to hope.  -- rms.
+        # Use sysv4.2uw... so that sysv4* matches it.
+	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+	exit 0 ;;
+    i*86:OS/2:*:*)
+	# If we were able to find `uname', then EMX Unix compatibility
+	# is probably installed.
+	echo ${UNAME_MACHINE}-pc-os2-emx
+	exit 0 ;;
+    i*86:XTS-300:*:STOP)
+	echo ${UNAME_MACHINE}-unknown-stop
+	exit 0 ;;
+    i*86:atheos:*:*)
+	echo ${UNAME_MACHINE}-unknown-atheos
+	exit 0 ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
+	echo i386-unknown-lynxos${UNAME_RELEASE}
+	exit 0 ;;
+    i*86:*DOS:*:*)
+	echo ${UNAME_MACHINE}-pc-msdosdjgpp
+	exit 0 ;;
+    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+		echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+	else
+		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+	fi
+	exit 0 ;;
+    i*86:*:5:[78]*)
+	case `/bin/uname -X | grep "^Machine"` in
+	    *486*)	     UNAME_MACHINE=i486 ;;
+	    *Pentium)	     UNAME_MACHINE=i586 ;;
+	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+	esac
+	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+	exit 0 ;;
+    i*86:*:3.2:*)
+	if test -f /usr/options/cb.name; then
+		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+		echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+	elif /bin/uname -X 2>/dev/null >/dev/null ; then
+		UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+		(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+		(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+			&& UNAME_MACHINE=i586
+		(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+	else
+		echo ${UNAME_MACHINE}-pc-sysv32
+	fi
+	exit 0 ;;
+    pc:*:*:*)
+	# Left here for compatibility:
+        # uname -m prints for DJGPP always 'pc', but it prints nothing about
+        # the processor, so we play safe by assuming i386.
+	echo i386-pc-msdosdjgpp
+        exit 0 ;;
+    Intel:Mach:3*:*)
+	echo i386-pc-mach3
+	exit 0 ;;
+    paragon:*:*:*)
+	echo i860-intel-osf1
+	exit 0 ;;
+    i860:*:4.*:*) # i860-SVR4
+	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+	else # Add other i860-SVR4 vendors below as they are discovered.
+	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+	fi
+	exit 0 ;;
+    mini*:CTIX:SYS*5:*)
+	# "miniframe"
+	echo m68010-convergent-sysv
+	exit 0 ;;
+    mc68k:UNIX:SYSTEM5:3.51m)
+	echo m68k-convergent-sysv
+	exit 0 ;;
+    M680?0:D-NIX:5.3:*)
+	echo m68k-diab-dnix
+	exit 0 ;;
+    M68*:*:R3V[567]*:*)
+	test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
+    3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
+	OS_REL=''
+	test -r /etc/.relid \
+	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && echo i486-ncr-sysv4.3${OS_REL} && exit 0
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	  && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+          && echo i486-ncr-sysv4 && exit 0 ;;
+    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+	echo m68k-unknown-lynxos${UNAME_RELEASE}
+	exit 0 ;;
+    mc68030:UNIX_System_V:4.*:*)
+	echo m68k-atari-sysv4
+	exit 0 ;;
+    TSUNAMI:LynxOS:2.*:*)
+	echo sparc-unknown-lynxos${UNAME_RELEASE}
+	exit 0 ;;
+    rs6000:LynxOS:2.*:*)
+	echo rs6000-unknown-lynxos${UNAME_RELEASE}
+	exit 0 ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
+	echo powerpc-unknown-lynxos${UNAME_RELEASE}
+	exit 0 ;;
+    SM[BE]S:UNIX_SV:*:*)
+	echo mips-dde-sysv${UNAME_RELEASE}
+	exit 0 ;;
+    RM*:ReliantUNIX-*:*:*)
+	echo mips-sni-sysv4
+	exit 0 ;;
+    RM*:SINIX-*:*:*)
+	echo mips-sni-sysv4
+	exit 0 ;;
+    *:SINIX-*:*:*)
+	if uname -p 2>/dev/null >/dev/null ; then
+		UNAME_MACHINE=`(uname -p) 2>/dev/null`
+		echo ${UNAME_MACHINE}-sni-sysv4
+	else
+		echo ns32k-sni-sysv
+	fi
+	exit 0 ;;
+    PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+                      # says <Richard.M.Bartel at ccMail.Census.GOV>
+        echo i586-unisys-sysv4
+        exit 0 ;;
+    *:UNIX_System_V:4*:FTX*)
+	# From Gerald Hewes <hewes at openmarket.com>.
+	# How about differentiating between stratus architectures? -djm
+	echo hppa1.1-stratus-sysv4
+	exit 0 ;;
+    *:*:*:FTX*)
+	# From seanf at swdc.stratus.com.
+	echo i860-stratus-sysv4
+	exit 0 ;;
+    *:VOS:*:*)
+	# From Paul.Green at stratus.com.
+	echo hppa1.1-stratus-vos
+	exit 0 ;;
+    mc68*:A/UX:*:*)
+	echo m68k-apple-aux${UNAME_RELEASE}
+	exit 0 ;;
+    news*:NEWS-OS:6*:*)
+	echo mips-sony-newsos6
+	exit 0 ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+	if [ -d /usr/nec ]; then
+	        echo mips-nec-sysv${UNAME_RELEASE}
+	else
+	        echo mips-unknown-sysv${UNAME_RELEASE}
+	fi
+        exit 0 ;;
+    BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
+	echo powerpc-be-beos
+	exit 0 ;;
+    BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
+	echo powerpc-apple-beos
+	exit 0 ;;
+    BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
+	echo i586-pc-beos
+	exit 0 ;;
+    SX-4:SUPER-UX:*:*)
+	echo sx4-nec-superux${UNAME_RELEASE}
+	exit 0 ;;
+    SX-5:SUPER-UX:*:*)
+	echo sx5-nec-superux${UNAME_RELEASE}
+	exit 0 ;;
+    SX-6:SUPER-UX:*:*)
+	echo sx6-nec-superux${UNAME_RELEASE}
+	exit 0 ;;
+    Power*:Rhapsody:*:*)
+	echo powerpc-apple-rhapsody${UNAME_RELEASE}
+	exit 0 ;;
+    *:Rhapsody:*:*)
+	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+	exit 0 ;;
+    *:Darwin:*:*)
+	case `uname -p` in
+	    *86) UNAME_PROCESSOR=i686 ;;
+	    powerpc) UNAME_PROCESSOR=powerpc ;;
+	esac
+	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+	exit 0 ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+	UNAME_PROCESSOR=`uname -p`
+	if test "$UNAME_PROCESSOR" = "x86"; then
+		UNAME_PROCESSOR=i386
+		UNAME_MACHINE=pc
+	fi
+	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+	exit 0 ;;
+    *:QNX:*:4*)
+	echo i386-pc-qnx
+	exit 0 ;;
+    NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*)
+	echo nsr-tandem-nsk${UNAME_RELEASE}
+	exit 0 ;;
+    *:NonStop-UX:*:*)
+	echo mips-compaq-nonstopux
+	exit 0 ;;
+    BS2000:POSIX*:*:*)
+	echo bs2000-siemens-sysv
+	exit 0 ;;
+    DS/*:UNIX_System_V:*:*)
+	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+	exit 0 ;;
+    *:Plan9:*:*)
+	# "uname -m" is not consistent, so use $cputype instead. 386
+	# is converted to i386 for consistency with other x86
+	# operating systems.
+	if test "$cputype" = "386"; then
+	    UNAME_MACHINE=i386
+	else
+	    UNAME_MACHINE="$cputype"
+	fi
+	echo ${UNAME_MACHINE}-unknown-plan9
+	exit 0 ;;
+    *:TOPS-10:*:*)
+	echo pdp10-unknown-tops10
+	exit 0 ;;
+    *:TENEX:*:*)
+	echo pdp10-unknown-tenex
+	exit 0 ;;
+    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+	echo pdp10-dec-tops20
+	exit 0 ;;
+    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+	echo pdp10-xkl-tops20
+	exit 0 ;;
+    *:TOPS-20:*:*)
+	echo pdp10-unknown-tops20
+	exit 0 ;;
+    *:ITS:*:*)
+	echo pdp10-unknown-its
+	exit 0 ;;
+esac
+
+#echo '(No uname command or uname output not recognized.)' 1>&2
+#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
+
+eval $set_cc_for_build
+cat >$dummy.c <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
+     I don't know....  */
+  printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+  printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+          "4"
+#else
+	  ""
+#endif
+         ); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+  printf ("arm-acorn-riscix"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+  printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+  int version;
+  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+  if (version < 4)
+    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+  else
+    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+  exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+  printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+  printf ("ns32k-encore-mach\n"); exit (0);
+#else
+  printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+  printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+  printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+  printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+    struct utsname un;
+
+    uname(&un);
+
+    if (strncmp(un.version, "V2", 2) == 0) {
+	printf ("i386-sequent-ptx2\n"); exit (0);
+    }
+    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+	printf ("i386-sequent-ptx1\n"); exit (0);
+    }
+    printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+# if !defined (ultrix)
+#  include <sys/param.h>
+#  if defined (BSD)
+#   if BSD == 43
+      printf ("vax-dec-bsd4.3\n"); exit (0);
+#   else
+#    if BSD == 199006
+      printf ("vax-dec-bsd4.3reno\n"); exit (0);
+#    else
+      printf ("vax-dec-bsd\n"); exit (0);
+#    endif
+#   endif
+#  else
+    printf ("vax-dec-bsd\n"); exit (0);
+#  endif
+# else
+    printf ("vax-dec-ultrix\n"); exit (0);
+# endif
+#endif
+
+#if defined (alliant) && defined (i860)
+  printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+  exit (1);
+}
+EOF
+
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+    case `getsysinfo -f cpu_type` in
+    c1*)
+	echo c1-convex-bsd
+	exit 0 ;;
+    c2*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+	exit 0 ;;
+    c34*)
+	echo c34-convex-bsd
+	exit 0 ;;
+    c38*)
+	echo c38-convex-bsd
+	exit 0 ;;
+    c4*)
+	echo c4-convex-bsd
+	exit 0 ;;
+    esac
+fi
+
+cat >&2 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+    ftp://ftp.gnu.org/pub/gnu/config/
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches at gnu.org> in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo               = `(hostinfo) 2>/dev/null`
+/bin/universe          = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch              = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM  = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:

Added: trunk/config.sub
==============================================================================
--- trunk/config.sub	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/config.sub	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,1492 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+
+timestamp='2003-05-09'
+
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine.  It does not imply ALL GNU software can.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Please send patches to <config-patches at gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+       $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches at gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit 0 ;;
+    --version | -v )
+       echo "$version" ; exit 0 ;;
+    --help | --h* | -h )
+       echo "$usage"; exit 0 ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit 0;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | freebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+	-sun*os*)
+		# Prevent following clause from handling this invalid input.
+		;;
+	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+	-apple | -axis)
+		os=
+		basic_machine=$1
+		;;
+	-sim | -cisco | -oki | -wec | -winbond)
+		os=
+		basic_machine=$1
+		;;
+	-scout)
+		;;
+	-wrs)
+		os=-vxworks
+		basic_machine=$1
+		;;
+	-chorusos*)
+		os=-chorusos
+		basic_machine=$1
+		;;
+ 	-chorusrdb)
+ 		os=-chorusrdb
+		basic_machine=$1
+ 		;;
+	-hiux*)
+		os=-hiuxwe2
+		;;
+	-sco5)
+		os=-sco3.2v5
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco4)
+		os=-sco3.2v4
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2.[4-9]*)
+		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2v[4-9]*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco*)
+		os=-sco3.2v2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-udk*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-isc)
+		os=-isc2.2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-clix*)
+		basic_machine=clipper-intergraph
+		;;
+	-isc*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-lynx*)
+		os=-lynxos
+		;;
+	-ptx*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+		;;
+	-windowsnt*)
+		os=`echo $os | sed -e 's/windowsnt/winnt/'`
+		;;
+	-psos*)
+		os=-psos
+		;;
+	-mint | -mint[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+	# Recognize the basic CPU types without company name.
+	# Some are omitted here because they have special meanings below.
+	1750a | 580 \
+	| a29k \
+	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
+	| clipper \
+	| d10v | d30v | dlx | dsp16xx \
+	| fr30 | frv \
+	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+	| i370 | i860 | i960 | ia64 \
+	| ip2k \
+	| m32r | m68000 | m68k | m88k | mcore \
+	| mips | mipsbe | mipseb | mipsel | mipsle \
+	| mips16 \
+	| mips64 | mips64el \
+	| mips64vr | mips64vrel \
+	| mips64orion | mips64orionel \
+	| mips64vr4100 | mips64vr4100el \
+	| mips64vr4300 | mips64vr4300el \
+	| mips64vr5000 | mips64vr5000el \
+	| mipsisa32 | mipsisa32el \
+	| mipsisa32r2 | mipsisa32r2el \
+	| mipsisa64 | mipsisa64el \
+	| mipsisa64sb1 | mipsisa64sb1el \
+	| mipsisa64sr71k | mipsisa64sr71kel \
+	| mipstx39 | mipstx39el \
+	| mn10200 | mn10300 \
+	| msp430 \
+	| ns16k | ns32k \
+	| openrisc | or32 \
+	| pdp10 | pdp11 | pj | pjl \
+	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
+	| pyramid \
+	| sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
+	| sh64 | sh64le \
+	| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \
+	| strongarm \
+	| tahoe | thumb | tic80 | tron \
+	| v850 | v850e \
+	| we32k \
+	| x86 | xscale | xstormy16 | xtensa \
+	| z8k)
+		basic_machine=$basic_machine-unknown
+		;;
+	m6811 | m68hc11 | m6812 | m68hc12)
+		# Motorola 68HC11/12.
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+		;;
+
+	# We use `pc' rather than `unknown'
+	# because (1) that's what they normally are, and
+	# (2) the word "unknown" tends to confuse beginning users.
+	i*86 | x86_64)
+	  basic_machine=$basic_machine-pc
+	  ;;
+	# Object if more than one company name word.
+	*-*-*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+	# Recognize the basic CPU types with company name.
+	580-* \
+	| a29k-* \
+	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
+	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
+	| avr-* \
+	| bs2000-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
+	| clipper-* | cydra-* \
+	| d10v-* | d30v-* | dlx-* \
+	| elxsi-* \
+	| f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
+	| h8300-* | h8500-* \
+	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+	| i*86-* | i860-* | i960-* | ia64-* \
+	| ip2k-* \
+	| m32r-* \
+	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+	| m88110-* | m88k-* | mcore-* \
+	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+	| mips16-* \
+	| mips64-* | mips64el-* \
+	| mips64vr-* | mips64vrel-* \
+	| mips64orion-* | mips64orionel-* \
+	| mips64vr4100-* | mips64vr4100el-* \
+	| mips64vr4300-* | mips64vr4300el-* \
+	| mips64vr5000-* | mips64vr5000el-* \
+	| mipsisa32-* | mipsisa32el-* \
+	| mipsisa32r2-* | mipsisa32r2el-* \
+	| mipsisa64-* | mipsisa64el-* \
+	| mipsisa64sb1-* | mipsisa64sb1el-* \
+	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipstx39-* | mipstx39el-* \
+	| msp430-* \
+	| none-* | np1-* | nv1-* | ns16k-* | ns32k-* \
+	| orion-* \
+	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
+	| pyramid-* \
+	| romp-* | rs6000-* \
+	| sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
+	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+	| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
+	| sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
+	| tahoe-* | thumb-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+	| tron-* \
+	| v850-* | v850e-* | vax-* \
+	| we32k-* \
+	| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
+	| xtensa-* \
+	| ymp-* \
+	| z8k-*)
+		;;
+	# Recognize the various machine names and aliases which stand
+	# for a CPU type and a company and sometimes even an OS.
+	386bsd)
+		basic_machine=i386-unknown
+		os=-bsd
+		;;
+	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+		basic_machine=m68000-att
+		;;
+	3b*)
+		basic_machine=we32k-att
+		;;
+	a29khif)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	adobe68k)
+		basic_machine=m68010-adobe
+		os=-scout
+		;;
+	alliant | fx80)
+		basic_machine=fx80-alliant
+		;;
+	altos | altos3068)
+		basic_machine=m68k-altos
+		;;
+	am29k)
+		basic_machine=a29k-none
+		os=-bsd
+		;;
+	amd64)
+		basic_machine=x86_64-pc
+		;;
+	amdahl)
+		basic_machine=580-amdahl
+		os=-sysv
+		;;
+	amiga | amiga-*)
+		basic_machine=m68k-unknown
+		;;
+	amigaos | amigados)
+		basic_machine=m68k-unknown
+		os=-amigaos
+		;;
+	amigaunix | amix)
+		basic_machine=m68k-unknown
+		os=-sysv4
+		;;
+	apollo68)
+		basic_machine=m68k-apollo
+		os=-sysv
+		;;
+	apollo68bsd)
+		basic_machine=m68k-apollo
+		os=-bsd
+		;;
+	aux)
+		basic_machine=m68k-apple
+		os=-aux
+		;;
+	balance)
+		basic_machine=ns32k-sequent
+		os=-dynix
+		;;
+	c90)
+		basic_machine=c90-cray
+		os=-unicos
+		;;
+	convex-c1)
+		basic_machine=c1-convex
+		os=-bsd
+		;;
+	convex-c2)
+		basic_machine=c2-convex
+		os=-bsd
+		;;
+	convex-c32)
+		basic_machine=c32-convex
+		os=-bsd
+		;;
+	convex-c34)
+		basic_machine=c34-convex
+		os=-bsd
+		;;
+	convex-c38)
+		basic_machine=c38-convex
+		os=-bsd
+		;;
+	cray | j90)
+		basic_machine=j90-cray
+		os=-unicos
+		;;
+	crds | unos)
+		basic_machine=m68k-crds
+		;;
+	cris | cris-* | etrax*)
+		basic_machine=cris-axis
+		;;
+	da30 | da30-*)
+		basic_machine=m68k-da30
+		;;
+	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+		basic_machine=mips-dec
+		;;
+	decsystem10* | dec10*)
+		basic_machine=pdp10-dec
+		os=-tops10
+		;;
+	decsystem20* | dec20*)
+		basic_machine=pdp10-dec
+		os=-tops20
+		;;
+	delta | 3300 | motorola-3300 | motorola-delta \
+	      | 3300-motorola | delta-motorola)
+		basic_machine=m68k-motorola
+		;;
+	delta88)
+		basic_machine=m88k-motorola
+		os=-sysv3
+		;;
+	dpx20 | dpx20-*)
+		basic_machine=rs6000-bull
+		os=-bosx
+		;;
+	dpx2* | dpx2*-bull)
+		basic_machine=m68k-bull
+		os=-sysv3
+		;;
+	ebmon29k)
+		basic_machine=a29k-amd
+		os=-ebmon
+		;;
+	elxsi)
+		basic_machine=elxsi-elxsi
+		os=-bsd
+		;;
+	encore | umax | mmax)
+		basic_machine=ns32k-encore
+		;;
+	es1800 | OSE68k | ose68k | ose | OSE)
+		basic_machine=m68k-ericsson
+		os=-ose
+		;;
+	fx2800)
+		basic_machine=i860-alliant
+		;;
+	genix)
+		basic_machine=ns32k-ns
+		;;
+	gmicro)
+		basic_machine=tron-gmicro
+		os=-sysv
+		;;
+	go32)
+		basic_machine=i386-pc
+		os=-go32
+		;;
+	h3050r* | hiux*)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	h8300hms)
+		basic_machine=h8300-hitachi
+		os=-hms
+		;;
+	h8300xray)
+		basic_machine=h8300-hitachi
+		os=-xray
+		;;
+	h8500hms)
+		basic_machine=h8500-hitachi
+		os=-hms
+		;;
+	harris)
+		basic_machine=m88k-harris
+		os=-sysv3
+		;;
+	hp300-*)
+		basic_machine=m68k-hp
+		;;
+	hp300bsd)
+		basic_machine=m68k-hp
+		os=-bsd
+		;;
+	hp300hpux)
+		basic_machine=m68k-hp
+		os=-hpux
+		;;
+	hp3k9[0-9][0-9] | hp9[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k2[0-9][0-9] | hp9k31[0-9])
+		basic_machine=m68000-hp
+		;;
+	hp9k3[2-9][0-9])
+		basic_machine=m68k-hp
+		;;
+	hp9k6[0-9][0-9] | hp6[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k7[0-79][0-9] | hp7[0-79][0-9])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k78[0-9] | hp78[0-9])
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][13679] | hp8[0-9][13679])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][0-9] | hp8[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hppa-next)
+		os=-nextstep3
+		;;
+	hppaosf)
+		basic_machine=hppa1.1-hp
+		os=-osf
+		;;
+	hppro)
+		basic_machine=hppa1.1-hp
+		os=-proelf
+		;;
+	i370-ibm* | ibm*)
+		basic_machine=i370-ibm
+		;;
+# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
+	i*86v32)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv32
+		;;
+	i*86v4*)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv4
+		;;
+	i*86v)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv
+		;;
+	i*86sol2)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-solaris2
+		;;
+	i386mach)
+		basic_machine=i386-mach
+		os=-mach
+		;;
+	i386-vsta | vsta)
+		basic_machine=i386-unknown
+		os=-vsta
+		;;
+	iris | iris4d)
+		basic_machine=mips-sgi
+		case $os in
+		    -irix*)
+			;;
+		    *)
+			os=-irix4
+			;;
+		esac
+		;;
+	isi68 | isi)
+		basic_machine=m68k-isi
+		os=-sysv
+		;;
+	m88k-omron*)
+		basic_machine=m88k-omron
+		;;
+	magnum | m3230)
+		basic_machine=mips-mips
+		os=-sysv
+		;;
+	merlin)
+		basic_machine=ns32k-utek
+		os=-sysv
+		;;
+	mingw32)
+		basic_machine=i386-pc
+		os=-mingw32
+		;;
+	miniframe)
+		basic_machine=m68000-convergent
+		;;
+	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+	mips3*-*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+		;;
+	mips3*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+		;;
+	mmix*)
+		basic_machine=mmix-knuth
+		os=-mmixware
+		;;
+	monitor)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	morphos)
+		basic_machine=powerpc-unknown
+		os=-morphos
+		;;
+	msdos)
+		basic_machine=i386-pc
+		os=-msdos
+		;;
+	mvs)
+		basic_machine=i370-ibm
+		os=-mvs
+		;;
+	ncr3000)
+		basic_machine=i486-ncr
+		os=-sysv4
+		;;
+	netbsd386)
+		basic_machine=i386-unknown
+		os=-netbsd
+		;;
+	netwinder)
+		basic_machine=armv4l-rebel
+		os=-linux
+		;;
+	news | news700 | news800 | news900)
+		basic_machine=m68k-sony
+		os=-newsos
+		;;
+	news1000)
+		basic_machine=m68030-sony
+		os=-newsos
+		;;
+	news-3600 | risc-news)
+		basic_machine=mips-sony
+		os=-newsos
+		;;
+	necv70)
+		basic_machine=v70-nec
+		os=-sysv
+		;;
+	next | m*-next )
+		basic_machine=m68k-next
+		case $os in
+		    -nextstep* )
+			;;
+		    -ns2*)
+		      os=-nextstep2
+			;;
+		    *)
+		      os=-nextstep3
+			;;
+		esac
+		;;
+	nh3000)
+		basic_machine=m68k-harris
+		os=-cxux
+		;;
+	nh[45]000)
+		basic_machine=m88k-harris
+		os=-cxux
+		;;
+	nindy960)
+		basic_machine=i960-intel
+		os=-nindy
+		;;
+	mon960)
+		basic_machine=i960-intel
+		os=-mon960
+		;;
+	nonstopux)
+		basic_machine=mips-compaq
+		os=-nonstopux
+		;;
+	np1)
+		basic_machine=np1-gould
+		;;
+	nv1)
+		basic_machine=nv1-cray
+		os=-unicosmp
+		;;
+	nsr-tandem)
+		basic_machine=nsr-tandem
+		;;
+	op50n-* | op60c-*)
+		basic_machine=hppa1.1-oki
+		os=-proelf
+		;;
+	or32 | or32-*)
+		basic_machine=or32-unknown
+		os=-coff
+		;;
+	OSE68000 | ose68000)
+		basic_machine=m68000-ericsson
+		os=-ose
+		;;
+	os68k)
+		basic_machine=m68k-none
+		os=-os68k
+		;;
+	pa-hitachi)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	paragon)
+		basic_machine=i860-intel
+		os=-osf
+		;;
+	pbd)
+		basic_machine=sparc-tti
+		;;
+	pbb)
+		basic_machine=m68k-tti
+		;;
+	pc532 | pc532-*)
+		basic_machine=ns32k-pc532
+		;;
+	pentium | p5 | k5 | k6 | nexgen | viac3)
+		basic_machine=i586-pc
+		;;
+	pentiumpro | p6 | 6x86 | athlon | athlon_*)
+		basic_machine=i686-pc
+		;;
+	pentiumii | pentium2)
+		basic_machine=i686-pc
+		;;
+	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumpro-* | p6-* | 6x86-* | athlon-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumii-* | pentium2-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pn)
+		basic_machine=pn-gould
+		;;
+	power)	basic_machine=power-ibm
+		;;
+	ppc)	basic_machine=powerpc-unknown
+		;;
+	ppc-*)	basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppcle | powerpclittle | ppc-le | powerpc-little)
+		basic_machine=powerpcle-unknown
+		;;
+	ppcle-* | powerpclittle-*)
+		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64)	basic_machine=powerpc64-unknown
+		;;
+	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+		basic_machine=powerpc64le-unknown
+		;;
+	ppc64le-* | powerpc64little-*)
+		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ps2)
+		basic_machine=i386-ibm
+		;;
+	pw32)
+		basic_machine=i586-unknown
+		os=-pw32
+		;;
+	rom68k)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	rm[46]00)
+		basic_machine=mips-siemens
+		;;
+	rtpc | rtpc-*)
+		basic_machine=romp-ibm
+		;;
+	s390 | s390-*)
+		basic_machine=s390-ibm
+		;;
+	s390x | s390x-*)
+		basic_machine=s390x-ibm
+		;;
+	sa29200)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	sb1)
+		basic_machine=mipsisa64sb1-unknown
+		;;
+	sb1el)
+		basic_machine=mipsisa64sb1el-unknown
+		;;
+	sequent)
+		basic_machine=i386-sequent
+		;;
+	sh)
+		basic_machine=sh-hitachi
+		os=-hms
+		;;
+	sparclite-wrs | simso-wrs)
+		basic_machine=sparclite-wrs
+		os=-vxworks
+		;;
+	sps7)
+		basic_machine=m68k-bull
+		os=-sysv2
+		;;
+	spur)
+		basic_machine=spur-unknown
+		;;
+	st2000)
+		basic_machine=m68k-tandem
+		;;
+	stratus)
+		basic_machine=i860-stratus
+		os=-sysv4
+		;;
+	sun2)
+		basic_machine=m68000-sun
+		;;
+	sun2os3)
+		basic_machine=m68000-sun
+		os=-sunos3
+		;;
+	sun2os4)
+		basic_machine=m68000-sun
+		os=-sunos4
+		;;
+	sun3os3)
+		basic_machine=m68k-sun
+		os=-sunos3
+		;;
+	sun3os4)
+		basic_machine=m68k-sun
+		os=-sunos4
+		;;
+	sun4os3)
+		basic_machine=sparc-sun
+		os=-sunos3
+		;;
+	sun4os4)
+		basic_machine=sparc-sun
+		os=-sunos4
+		;;
+	sun4sol2)
+		basic_machine=sparc-sun
+		os=-solaris2
+		;;
+	sun3 | sun3-*)
+		basic_machine=m68k-sun
+		;;
+	sun4)
+		basic_machine=sparc-sun
+		;;
+	sun386 | sun386i | roadrunner)
+		basic_machine=i386-sun
+		;;
+	sv1)
+		basic_machine=sv1-cray
+		os=-unicos
+		;;
+	symmetry)
+		basic_machine=i386-sequent
+		os=-dynix
+		;;
+	t3e)
+		basic_machine=alphaev5-cray
+		os=-unicos
+		;;
+	t90)
+		basic_machine=t90-cray
+		os=-unicos
+		;;
+        tic4x | c4x*)
+		basic_machine=tic4x-unknown
+		os=-coff
+		;;
+	tic54x | c54x*)
+		basic_machine=tic54x-unknown
+		os=-coff
+		;;
+	tic55x | c55x*)
+		basic_machine=tic55x-unknown
+		os=-coff
+		;;
+	tic6x | c6x*)
+		basic_machine=tic6x-unknown
+		os=-coff
+		;;
+	tx39)
+		basic_machine=mipstx39-unknown
+		;;
+	tx39el)
+		basic_machine=mipstx39el-unknown
+		;;
+	toad1)
+		basic_machine=pdp10-xkl
+		os=-tops20
+		;;
+	tower | tower-32)
+		basic_machine=m68k-ncr
+		;;
+	udi29k)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	ultra3)
+		basic_machine=a29k-nyu
+		os=-sym1
+		;;
+	v810 | necv810)
+		basic_machine=v810-nec
+		os=-none
+		;;
+	vaxv)
+		basic_machine=vax-dec
+		os=-sysv
+		;;
+	vms)
+		basic_machine=vax-dec
+		os=-vms
+		;;
+	vpp*|vx|vx-*)
+		basic_machine=f301-fujitsu
+		;;
+	vxworks960)
+		basic_machine=i960-wrs
+		os=-vxworks
+		;;
+	vxworks68)
+		basic_machine=m68k-wrs
+		os=-vxworks
+		;;
+	vxworks29k)
+		basic_machine=a29k-wrs
+		os=-vxworks
+		;;
+	w65*)
+		basic_machine=w65-wdc
+		os=-none
+		;;
+	w89k-*)
+		basic_machine=hppa1.1-winbond
+		os=-proelf
+		;;
+	xps | xps100)
+		basic_machine=xps100-honeywell
+		;;
+	ymp)
+		basic_machine=ymp-cray
+		os=-unicos
+		;;
+	z8k-*-coff)
+		basic_machine=z8k-unknown
+		os=-sim
+		;;
+	none)
+		basic_machine=none-none
+		os=-none
+		;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+	w89k)
+		basic_machine=hppa1.1-winbond
+		;;
+	op50n)
+		basic_machine=hppa1.1-oki
+		;;
+	op60c)
+		basic_machine=hppa1.1-oki
+		;;
+	romp)
+		basic_machine=romp-ibm
+		;;
+	rs6000)
+		basic_machine=rs6000-ibm
+		;;
+	vax)
+		basic_machine=vax-dec
+		;;
+	pdp10)
+		# there are many clones, so DEC is not a safe bet
+		basic_machine=pdp10-unknown
+		;;
+	pdp11)
+		basic_machine=pdp11-dec
+		;;
+	we32k)
+		basic_machine=we32k-att
+		;;
+	sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
+		basic_machine=sh-unknown
+		;;
+	sh64)
+		basic_machine=sh64-unknown
+		;;
+	sparc | sparcv9 | sparcv9b)
+		basic_machine=sparc-sun
+		;;
+	cydra)
+		basic_machine=cydra-cydrome
+		;;
+	orion)
+		basic_machine=orion-highlevel
+		;;
+	orion105)
+		basic_machine=clipper-highlevel
+		;;
+	mac | mpw | mac-mpw)
+		basic_machine=m68k-apple
+		;;
+	pmac | pmac-mpw)
+		basic_machine=powerpc-apple
+		;;
+	*-unknown)
+		# Make sure to match an already-canonicalized machine name.
+		;;
+	*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+	*-digital*)
+		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+		;;
+	*-commodore*)
+		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+		;;
+	*)
+		;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+        # First match some system type aliases
+        # that might get confused with valid system types.
+	# -solaris* is a basic system type, with this one exception.
+	-solaris1 | -solaris1.*)
+		os=`echo $os | sed -e 's|solaris1|sunos4|'`
+		;;
+	-solaris)
+		os=-solaris2
+		;;
+	-svr4*)
+		os=-sysv4
+		;;
+	-unixware*)
+		os=-sysv4.2uw
+		;;
+	-gnu/linux*)
+		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+		;;
+	# First accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST END IN A *, to match a version number.
+	# -sysv* is not here because it comes later, after sysvr4.
+	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+	      | -aos* \
+	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+	      | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
+	      | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+	      | -chorusos* | -chorusrdb* \
+	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -powermax* | -dnix*)
+	# Remember, each alternative MUST END IN *, to match a version number.
+		;;
+	-qnx*)
+		case $basic_machine in
+		    x86-* | i*86-*)
+			;;
+		    *)
+			os=-nto$os
+			;;
+		esac
+		;;
+	-nto-qnx*)
+		;;
+	-nto*)
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
+		;;
+	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
+	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+		;;
+	-mac*)
+		os=`echo $os | sed -e 's|mac|macos|'`
+		;;
+	-linux*)
+		os=`echo $os | sed -e 's|linux|linux-gnu|'`
+		;;
+	-sunos5*)
+		os=`echo $os | sed -e 's|sunos5|solaris2|'`
+		;;
+	-sunos6*)
+		os=`echo $os | sed -e 's|sunos6|solaris3|'`
+		;;
+	-opened*)
+		os=-openedition
+		;;
+	-wince*)
+		os=-wince
+		;;
+	-osfrose*)
+		os=-osfrose
+		;;
+	-osf*)
+		os=-osf
+		;;
+	-utek*)
+		os=-bsd
+		;;
+	-dynix*)
+		os=-bsd
+		;;
+	-acis*)
+		os=-aos
+		;;
+	-atheos*)
+		os=-atheos
+		;;
+	-386bsd)
+		os=-bsd
+		;;
+	-ctix* | -uts*)
+		os=-sysv
+		;;
+	-nova*)
+		os=-rtmk-nova
+		;;
+	-ns2 )
+		os=-nextstep2
+		;;
+	-nsk*)
+		os=-nsk
+		;;
+	# Preserve the version number of sinix5.
+	-sinix5.*)
+		os=`echo $os | sed -e 's|sinix|sysv|'`
+		;;
+	-sinix*)
+		os=-sysv4
+		;;
+	-triton*)
+		os=-sysv3
+		;;
+	-oss*)
+		os=-sysv3
+		;;
+	-svr4)
+		os=-sysv4
+		;;
+	-svr3)
+		os=-sysv3
+		;;
+	-sysvr4)
+		os=-sysv4
+		;;
+	# This must come after -sysvr4.
+	-sysv*)
+		;;
+	-ose*)
+		os=-ose
+		;;
+	-es1800*)
+		os=-ose
+		;;
+	-xenix)
+		os=-xenix
+		;;
+	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+		os=-mint
+		;;
+	-aros*)
+		os=-aros
+		;;
+	-kaos*)
+		os=-kaos
+		;;
+	-none)
+		;;
+	*)
+		# Get rid of the `-' at the beginning of $os.
+		os=`echo $os | sed 's/[^-]*-//'`
+		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+		exit 1
+		;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+	*-acorn)
+		os=-riscix1.2
+		;;
+	arm*-rebel)
+		os=-linux
+		;;
+	arm*-semi)
+		os=-aout
+		;;
+	# This must come before the *-dec entry.
+	pdp10-*)
+		os=-tops20
+		;;
+	pdp11-*)
+		os=-none
+		;;
+	*-dec | vax-*)
+		os=-ultrix4.2
+		;;
+	m68*-apollo)
+		os=-domain
+		;;
+	i386-sun)
+		os=-sunos4.0.2
+		;;
+	m68000-sun)
+		os=-sunos3
+		# This also exists in the configure program, but was not the
+		# default.
+		# os=-sunos4
+		;;
+	m68*-cisco)
+		os=-aout
+		;;
+	mips*-cisco)
+		os=-elf
+		;;
+	mips*-*)
+		os=-elf
+		;;
+	or32-*)
+		os=-coff
+		;;
+	*-tti)	# must be before sparc entry or we get the wrong os.
+		os=-sysv3
+		;;
+	sparc-* | *-sun)
+		os=-sunos4.1.1
+		;;
+	*-be)
+		os=-beos
+		;;
+	*-ibm)
+		os=-aix
+		;;
+	*-wec)
+		os=-proelf
+		;;
+	*-winbond)
+		os=-proelf
+		;;
+	*-oki)
+		os=-proelf
+		;;
+	*-hp)
+		os=-hpux
+		;;
+	*-hitachi)
+		os=-hiux
+		;;
+	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+		os=-sysv
+		;;
+	*-cbm)
+		os=-amigaos
+		;;
+	*-dg)
+		os=-dgux
+		;;
+	*-dolphin)
+		os=-sysv3
+		;;
+	m68k-ccur)
+		os=-rtu
+		;;
+	m88k-omron*)
+		os=-luna
+		;;
+	*-next )
+		os=-nextstep
+		;;
+	*-sequent)
+		os=-ptx
+		;;
+	*-crds)
+		os=-unos
+		;;
+	*-ns)
+		os=-genix
+		;;
+	i370-*)
+		os=-mvs
+		;;
+	*-next)
+		os=-nextstep3
+		;;
+	*-gould)
+		os=-sysv
+		;;
+	*-highlevel)
+		os=-bsd
+		;;
+	*-encore)
+		os=-bsd
+		;;
+	*-sgi)
+		os=-irix
+		;;
+	*-siemens)
+		os=-sysv4
+		;;
+	*-masscomp)
+		os=-rtu
+		;;
+	f30[01]-fujitsu | f700-fujitsu)
+		os=-uxpv
+		;;
+	*-rom68k)
+		os=-coff
+		;;
+	*-*bug)
+		os=-coff
+		;;
+	*-apple)
+		os=-macos
+		;;
+	*-atari*)
+		os=-mint
+		;;
+	*)
+		os=-none
+		;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+	*-unknown)
+		case $os in
+			-riscix*)
+				vendor=acorn
+				;;
+			-sunos*)
+				vendor=sun
+				;;
+			-aix*)
+				vendor=ibm
+				;;
+			-beos*)
+				vendor=be
+				;;
+			-hpux*)
+				vendor=hp
+				;;
+			-mpeix*)
+				vendor=hp
+				;;
+			-hiux*)
+				vendor=hitachi
+				;;
+			-unos*)
+				vendor=crds
+				;;
+			-dgux*)
+				vendor=dg
+				;;
+			-luna*)
+				vendor=omron
+				;;
+			-genix*)
+				vendor=ns
+				;;
+			-mvs* | -opened*)
+				vendor=ibm
+				;;
+			-ptx*)
+				vendor=sequent
+				;;
+			-vxsim* | -vxworks* | -windiss*)
+				vendor=wrs
+				;;
+			-aux*)
+				vendor=apple
+				;;
+			-hms*)
+				vendor=hitachi
+				;;
+			-mpw* | -macos*)
+				vendor=apple
+				;;
+			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+				vendor=atari
+				;;
+			-vos*)
+				vendor=stratus
+				;;
+		esac
+		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+		;;
+esac
+
+echo $basic_machine$os
+exit 0
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:

Added: trunk/configure.in
==============================================================================
--- trunk/configure.in	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/configure.in	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,48 @@
+AC_INIT(libscsidisk/Makefile)
+
+PACKAGE=endpoint
+AC_SUBST(PACKAGE)
+
+MAJOR_VERSION=0
+MINOR_VERSION=1
+MICRO_VERSION=0
+
+# Adjust this only to bump the RPM packaging version
+RPM_VERSION=1
+
+DIST_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
+VERSION=$DIST_VERSION
+
+AC_SUBST(MAJOR_VERSION)
+AC_SUBST(MINOR_VERSION)
+AC_SUBST(MICRO_VERSION)
+
+AC_SUBST(DIST_VERSION)
+AC_SUBST(VERSION)
+
+AC_CANONICAL_HOST
+
+AC_PROG_CC
+AC_PROG_CPP
+
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_RANLIB
+
+AC_PATH_PROG(AR, ar)
+
+AC_HEADER_STDC
+AC_C_CONST
+
+AC_LIB_RAW1394(0.9.0,,
+  AC_MSG_ERROR([Could not find libraw1394]))
+
+PKG_CHECK_MODULES(GLIB, glib-2.0,,
+  AC_MSG_ERROR([Could not find GLIB 2.x]))
+
+AC_SUBST(GLIB_CFLAGS)
+AC_SUBST(GLIB_LIBS)
+
+AC_OUTPUT([
+Config.make
+])

Added: trunk/install-sh
==============================================================================
--- trunk/install-sh	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/install-sh	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,294 @@
+#!/bin/sh
+#
+# install - install a program, script, or datafile
+#
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.  It can only install one file at a time, a restriction
+# shared with many OS's install programs.
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+transformbasename=""
+transform_arg=""
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+dir_arg=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+	-c) instcmd=$cpprog
+	    shift
+	    continue;;
+
+	-d) dir_arg=true
+	    shift
+	    continue;;
+
+	-m) chmodcmd="$chmodprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-o) chowncmd="$chownprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-g) chgrpcmd="$chgrpprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-s) stripcmd=$stripprog
+	    shift
+	    continue;;
+
+	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
+	    shift
+	    continue;;
+
+	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+	    shift
+	    continue;;
+
+	*)  if [ x"$src" = x ]
+	    then
+		src=$1
+	    else
+		# this colon is to work around a 386BSD /bin/sh bug
+		:
+		dst=$1
+	    fi
+	    shift
+	    continue;;
+    esac
+done
+
+if [ x"$src" = x ]
+then
+	echo "$0: no input file specified" >&2
+	exit 1
+else
+	:
+fi
+
+if [ x"$dir_arg" != x ]; then
+	dst=$src
+	src=""
+
+	if [ -d "$dst" ]; then
+		instcmd=:
+		chmodcmd=""
+	else
+		instcmd=$mkdirprog
+	fi
+else
+
+# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+# might cause directories to be created, which would be especially bad
+# if $src (and thus $dsttmp) contains '*'.
+
+	if [ -f "$src" ] || [ -d "$src" ]
+	then
+		:
+	else
+		echo "$0: $src does not exist" >&2
+		exit 1
+	fi
+
+	if [ x"$dst" = x ]
+	then
+		echo "$0: no destination specified" >&2
+		exit 1
+	else
+		:
+	fi
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+	if [ -d "$dst" ]
+	then
+		dst=$dst/`basename "$src"`
+	else
+		:
+	fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+#  this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='
+	'
+IFS="${IFS-$defaultIFS}"
+
+oIFS=$IFS
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS=$oIFS
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+	pathcomp=$pathcomp$1
+	shift
+
+	if [ ! -d "$pathcomp" ] ;
+        then
+		$mkdirprog "$pathcomp"
+	else
+		:
+	fi
+
+	pathcomp=$pathcomp/
+done
+fi
+
+if [ x"$dir_arg" != x ]
+then
+	$doit $instcmd "$dst" &&
+
+	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
+	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
+	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
+	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
+else
+
+# If we're going to rename the final executable, determine the name now.
+
+	if [ x"$transformarg" = x ]
+	then
+		dstfile=`basename "$dst"`
+	else
+		dstfile=`basename "$dst" $transformbasename |
+			sed $transformarg`$transformbasename
+	fi
+
+# don't allow the sed command to completely eliminate the filename
+
+	if [ x"$dstfile" = x ]
+	then
+		dstfile=`basename "$dst"`
+	else
+		:
+	fi
+
+# Make a couple of temp file names in the proper directory.
+
+	dsttmp=$dstdir/#inst.$$#
+	rmtmp=$dstdir/#rm.$$#
+
+# Trap to clean up temp files at exit.
+
+	trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
+	trap '(exit $?); exit' 1 2 13 15
+
+# Move or copy the file name to the temp name
+
+	$doit $instcmd "$src" "$dsttmp" &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing.  If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
+	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
+	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
+	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
+
+# Now remove or move aside any old file at destination location.  We try this
+# two ways since rm can't unlink itself on some systems and the destination
+# file might be busy for other reasons.  In this case, the final cleanup
+# might fail but the new file should still install successfully.
+
+{
+	if [ -f "$dstdir/$dstfile" ]
+	then
+		$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
+		$doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
+		{
+		  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
+		  (exit 1); exit
+		}
+	else
+		:
+	fi
+} &&
+
+# Now rename the file to the real destination.
+
+	$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+
+fi &&
+
+# The final little trick to "correctly" pass the exit status to the exit trap.
+
+{
+	(exit 0); exit
+}

Added: trunk/libsbp2/sbp2.c
==============================================================================
--- trunk/libsbp2/sbp2.c	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/libsbp2/sbp2.c	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,56 @@
+#include <glib.h>
+
+#include "sbp2.h"
+
+gboolean
+sbp2_handle_management_orb (SBP2Disk *disk,
+                            gpointer  orb,
+			    gpointer *response)
+{
+  SBP2ManagementORB *morb = orb;
+  gint               function;
+
+  function = (orb->misc >> 16) & 0xf;
+
+  switch (function)
+    {
+    case SBP2_LOGIN_REQUEST:
+      return handle_login (disk, orb, response);
+      break;
+
+    case SBP2_QUERY_LOGINS_REQUEST:
+      return handle_query_logins (disk, orb, response);
+      break;
+
+    case SBP2_RECONNECT_REQUEST:
+      return handle_reconnect (disk, orb, response);
+      break;
+
+    case SBP2_LOGOUT_REQUEST:
+      return handle_logout (disk, orb, response);
+      break;
+
+    case SBP2_SET_PASSWORD_REQUEST:
+    case SBP2_ABORT_TASK_REQUEST:
+    case SBP2_ABORT_TASK_SET:
+    case SBP2_LOGICAL_UNIT_RESET:
+    case SBP2_TARGET_RESET_REQUEST:
+      /* FIXME: unhandled */
+      return FALSE;
+      break;
+    
+    default:
+      /* Error here maybe? */
+      return FALSE;
+      break; 
+    }
+}
+
+gboolean
+handle_login (SBP2Disk *disk,
+              gpointer  orb,
+	      gpointer *response)
+{
+  SBP2LoginORB *lorb = orb;
+
+}

Added: trunk/libsbp2/sbp2.h
==============================================================================
--- trunk/libsbp2/sbp2.h	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/libsbp2/sbp2.h	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,17 @@
+#ifndef __SBP2_H__
+#define __SBP2_H__
+
+
+#include <glib.h>
+
+
+gboolean sbp2_handle_management_orb (SBP2Disk *disk,
+                                     gpointer  orb,
+				     gpointer *response);
+
+gboolean sbp2_handle_command_orb    (SBP2Disk *disk,
+                                     gpointer  orb,
+				     gpointer *response);
+
+
+#endif /* __SBP2_H__ */

Added: trunk/libsbp2/sbp2raw.c
==============================================================================
--- trunk/libsbp2/sbp2raw.c	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/libsbp2/sbp2raw.c	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,2980 @@
+/*
+ * sbp2.c - SBP-2 protocol driver for IEEE-1394
+ *
+ * Copyright (C) 2000 James Goodwin, Filanet Corporation (www.filanet.com)
+ * jamesg at filanet.com (JSG)
+ *
+ * Copyright (C) 2003 Ben Collins <bcollins at debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Brief Description:
+ *
+ * This driver implements the Serial Bus Protocol 2 (SBP-2) over IEEE-1394
+ * under Linux. The SBP-2 driver is implemented as an IEEE-1394 high-level
+ * driver. It also registers as a SCSI lower-level driver in order to accept
+ * SCSI commands for transport using SBP-2.
+ *
+ * You may access any attached SBP-2 storage devices as if they were SCSI
+ * devices (e.g. mount /dev/sda1,  fdisk, mkfs, etc.).
+ *
+ * Current Issues:
+ *
+ *	- Error Handling: SCSI aborts and bus reset requests are handled somewhat
+ *	  but the code needs additional debugging.
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/fs.h>
+#include <linux/poll.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/types.h>
+#include <linux/delay.h>
+#include <linux/sched.h>
+#include <linux/proc_fs.h>
+#include <linux/blk.h>
+#include <linux/smp_lock.h>
+#include <linux/init.h>
+#include <linux/version.h>
+#include <asm/current.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+#include <asm/byteorder.h>
+#include <asm/atomic.h>
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/scatterlist.h>
+
+#include "../scsi/scsi.h"
+#include "../scsi/hosts.h"
+
+#include "ieee1394.h"
+#include "ieee1394_types.h"
+#include "ieee1394_core.h"
+#include "nodemgr.h"
+#include "hosts.h"
+#include "nodemgr.h"
+#include "highlevel.h"
+#include "ieee1394_transactions.h"
+#include "sbp2.h"
+
+static char version[] __devinitdata =
+	"$Rev: 966 $ Ben Collins <bcollins at debian.org>";
+
+/*
+ * Module load parameter definitions
+ */
+
+/*
+ * Change max_speed on module load if you have a bad IEEE-1394
+ * controller that has trouble running 2KB packets at 400mb.
+ *
+ * NOTE: On certain OHCI parts I have seen short packets on async transmit
+ * (probably due to PCI latency/throughput issues with the part). You can
+ * bump down the speed if you are running into problems.
+ */
+static int max_speed = IEEE1394_SPEED_MAX;
+module_param(max_speed, int, 0644);
+MODULE_PARM_DESC(max_speed, "Force max speed (3 = 800mb, 2 = 400mb default, 1 = 200mb, 0 = 100mb)");
+
+/*
+ * Set serialize_io to 1 if you'd like only one scsi command sent
+ * down to us at a time (debugging). This might be necessary for very
+ * badly behaved sbp2 devices.
+ */
+static int serialize_io = 0;
+module_param(serialize_io, int, 0444);
+MODULE_PARM_DESC(serialize_io, "Serialize all I/O coming down from the scsi drivers (default = 0)");
+
+/*
+ * Bump up max_sectors if you'd like to support very large sized
+ * transfers. Please note that some older sbp2 bridge chips are broken for
+ * transfers greater or equal to 128KB.  Default is a value of 255
+ * sectors, or just under 128KB (at 512 byte sector size). I can note that
+ * the Oxsemi sbp2 chipsets have no problems supporting very large
+ * transfer sizes.
+ */
+static int max_sectors = SBP2_MAX_SECTORS;
+module_param(max_sectors, int, 0444);
+MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported (default = 255)");
+
+/*
+ * Exclusive login to sbp2 device? In most cases, the sbp2 driver should
+ * do an exclusive login, as it's generally unsafe to have two hosts
+ * talking to a single sbp2 device at the same time (filesystem coherency,
+ * etc.). If you're running an sbp2 device that supports multiple logins,
+ * and you're either running read-only filesystems or some sort of special
+ * filesystem supporting multiple hosts (one such filesystem is OpenGFS,
+ * see opengfs.sourceforge.net for more info), then set exclusive_login
+ * to zero. Note: The Oxsemi OXFW911 sbp2 chipset supports up to four
+ * concurrent logins.
+ */
+static int exclusive_login = 1;
+module_param(exclusive_login, int, 0644);
+MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device (default = 1)");
+
+/*
+ * SCSI inquiry hack for really badly behaved sbp2 devices. Turn this on
+ * if your sbp2 device is not properly handling the SCSI inquiry command.
+ * This hack makes the inquiry look more like a typical MS Windows
+ * inquiry.
+ * 
+ * If force_inquiry_hack=1 is required for your device to work,
+ * please submit the logged sbp2_firmware_revision value of this device to
+ * the linux1394-devel mailing list.
+ */
+static int force_inquiry_hack = 0;
+module_param(force_inquiry_hack, int, 0444);
+MODULE_PARM_DESC(force_inquiry_hack, "Force SCSI inquiry hack (default = 0)");
+
+
+/*
+ * Export information about protocols/devices supported by this driver.
+ */
+static struct ieee1394_device_id sbp2_id_table[] = {
+	{
+		.match_flags =IEEE1394_MATCH_SPECIFIER_ID |
+		              IEEE1394_MATCH_VERSION,
+		.specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
+		.version =    SBP2_SW_VERSION_ENTRY & 0xffffff
+	},
+	{ }
+};
+
+MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
+
+/*
+ * Debug levels, configured via kernel config, or enable here.
+ */
+
+/* #define CONFIG_IEEE1394_SBP2_DEBUG_ORBS */
+/* #define CONFIG_IEEE1394_SBP2_DEBUG_DMA */
+/* #define CONFIG_IEEE1394_SBP2_DEBUG 1 */
+/* #define CONFIG_IEEE1394_SBP2_DEBUG 2 */
+/* #define CONFIG_IEEE1394_SBP2_PACKET_DUMP */
+
+#ifdef CONFIG_IEEE1394_SBP2_DEBUG_ORBS
+#define SBP2_ORB_DEBUG(fmt, args...)	HPSB_ERR("sbp2(%s): "fmt, __FUNCTION__, ## args)
+static u32 global_outstanding_command_orbs = 0;
+#define outstanding_orb_incr global_outstanding_command_orbs++
+#define outstanding_orb_decr global_outstanding_command_orbs--
+#else
+#define SBP2_ORB_DEBUG(fmt, args...)
+#define outstanding_orb_incr
+#define outstanding_orb_decr
+#endif
+
+#ifdef CONFIG_IEEE1394_SBP2_DEBUG_DMA
+#define SBP2_DMA_ALLOC(fmt, args...) \
+	HPSB_ERR("sbp2(%s)alloc(%d): "fmt, __FUNCTION__, \
+		 ++global_outstanding_dmas, ## args)
+#define SBP2_DMA_FREE(fmt, args...) \
+	HPSB_ERR("sbp2(%s)free(%d): "fmt, __FUNCTION__, \
+		 --global_outstanding_dmas, ## args)
+static u32 global_outstanding_dmas = 0;
+#else
+#define SBP2_DMA_ALLOC(fmt, args...)
+#define SBP2_DMA_FREE(fmt, args...)
+#endif
+
+#if CONFIG_IEEE1394_SBP2_DEBUG >= 2
+#define SBP2_DEBUG(fmt, args...)	HPSB_ERR("sbp2: "fmt, ## args)
+#define SBP2_INFO(fmt, args...)		HPSB_ERR("sbp2: "fmt, ## args)
+#define SBP2_NOTICE(fmt, args...)	HPSB_ERR("sbp2: "fmt, ## args)
+#define SBP2_WARN(fmt, args...)		HPSB_ERR("sbp2: "fmt, ## args)
+#elif CONFIG_IEEE1394_SBP2_DEBUG == 1
+#define SBP2_DEBUG(fmt, args...)	HPSB_DEBUG("sbp2: "fmt, ## args)
+#define SBP2_INFO(fmt, args...)		HPSB_INFO("sbp2: "fmt, ## args)
+#define SBP2_NOTICE(fmt, args...)	HPSB_NOTICE("sbp2: "fmt, ## args)
+#define SBP2_WARN(fmt, args...)		HPSB_WARN("sbp2: "fmt, ## args)
+#else 
+#define SBP2_DEBUG(fmt, args...)
+#define SBP2_INFO(fmt, args...)		HPSB_INFO("sbp2: "fmt, ## args)
+#define SBP2_NOTICE(fmt, args...)       HPSB_NOTICE("sbp2: "fmt, ## args)
+#define SBP2_WARN(fmt, args...)         HPSB_WARN("sbp2: "fmt, ## args)
+#endif
+
+#define SBP2_ERR(fmt, args...)		HPSB_ERR("sbp2: "fmt, ## args)
+
+
+/*
+ * Globals
+ */
+
+static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id,
+					   u32 status);
+
+static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
+				      u32 scsi_status, Scsi_Cmnd *SCpnt,
+				      void (*done)(Scsi_Cmnd *));
+	
+static Scsi_Host_Template scsi_driver_template;
+
+const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC };
+
+static struct hpsb_highlevel sbp2_highlevel = {
+	.name =		SBP2_DEVICE_NAME,
+	.remove_host =	sbp2_remove_host,
+};
+
+static struct hpsb_address_ops sbp2_ops = {
+	.write = sbp2_handle_status_write
+};
+
+#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
+static struct hpsb_address_ops sbp2_physdma_ops = {
+        .read = sbp2_handle_physdma_read,
+        .write = sbp2_handle_physdma_write,
+};
+#endif
+
+static struct hpsb_protocol_driver sbp2_driver = {
+	.name		= "SBP2 Driver",
+	.id_table	= sbp2_id_table,
+	.update		= sbp2_update,
+	.driver		= {
+		.name		= SBP2_DEVICE_NAME,
+		.bus		= &ieee1394_bus_type,
+		.probe		= sbp2_probe,
+		.remove		= sbp2_remove,
+	},
+};
+
+
+/* List of device firmware's that require a forced 36 byte inquiry.  */
+static u32 sbp2_broken_inquiry_list[] = {
+	0x00002800,	/* Stefan Richter <richtest at bauwesen.tu-cottbus.de> */
+			/* DViCO Momobay CX-1 */
+	0x00000200	/* Andreas Plesch <plesch at fas.harvard.edu> */
+			/* QPS Fire DVDBurner */
+};
+
+#define NUM_BROKEN_INQUIRY_DEVS \
+	(sizeof(sbp2_broken_inquiry_list)/sizeof(*sbp2_broken_inquiry_list))
+
+/**************************************
+ * General utility functions
+ **************************************/
+
+
+#ifndef __BIG_ENDIAN
+/*
+ * Converts a buffer from be32 to cpu byte ordering. Length is in bytes.
+ */
+static __inline__ void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
+{
+	u32 *temp = buffer;
+
+	for (length = (length >> 2); length--; )
+		temp[length] = be32_to_cpu(temp[length]);
+
+	return;
+}
+
+/*
+ * Converts a buffer from cpu to be32 byte ordering. Length is in bytes.
+ */
+static __inline__ void sbp2util_cpu_to_be32_buffer(void *buffer, int length)
+{
+	u32 *temp = buffer;
+
+	for (length = (length >> 2); length--; )
+		temp[length] = cpu_to_be32(temp[length]);
+
+	return;
+}
+#else /* BIG_ENDIAN */
+/* Why waste the cpu cycles? */
+#define sbp2util_be32_to_cpu_buffer(x,y)
+#define sbp2util_cpu_to_be32_buffer(x,y)
+#endif
+
+#ifdef CONFIG_IEEE1394_SBP2_PACKET_DUMP
+/*
+ * Debug packet dump routine. Length is in bytes.
+ */
+static void sbp2util_packet_dump(void *buffer, int length, char *dump_name, u32 dump_phys_addr)
+{
+	int i;
+	unsigned char *dump = buffer;
+
+	if (!dump || !length || !dump_name)
+		return;
+
+	if (dump_phys_addr)
+		printk("[%s, 0x%x]", dump_name, dump_phys_addr);
+	else
+		printk("[%s]", dump_name);
+	for (i = 0; i < length; i++) {
+		if (i > 0x3f) {
+			printk("\n   ...");
+			break;
+		}
+		if ((i & 0x3) == 0)
+			printk("  ");
+		if ((i & 0xf) == 0)
+			printk("\n   ");
+		printk("%02x ", (int) dump[i]);
+	}
+	printk("\n");
+
+	return;
+}
+#else
+#define sbp2util_packet_dump(w,x,y,z)
+#endif
+
+/*
+ * Goofy routine that basically does a down_timeout function.
+ */
+static int sbp2util_down_timeout(atomic_t *done, int timeout)
+{
+	int i;
+
+	for (i = timeout; (i > 0 && atomic_read(done) == 0); i-= HZ/10) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		if (schedule_timeout(HZ/10))	/* 100ms */
+			return(1);
+	}
+	return ((i > 0) ? 0:1);
+}
+
+/* Free's an allocated packet */
+static void sbp2_free_packet(struct hpsb_packet *packet)
+{
+	hpsb_free_tlabel(packet);
+	free_hpsb_packet(packet);
+}
+
+/*
+ * This function is called to retrieve a block write packet from our
+ * packet pool. This function is used in place of calling
+ * alloc_hpsb_packet (which costs us three kmallocs). Instead we just pull
+ * out a free request packet and re-initialize values in it. I'm sure this
+ * can still stand some more optimization.
+ */
+static struct hpsb_packet *
+sbp2util_allocate_write_packet(struct sbp2scsi_host_info *hi,
+			       struct node_entry *ne, u64 addr,
+			       size_t data_size,
+			       quadlet_t *data)
+{
+	struct hpsb_packet *packet;
+
+	packet = hpsb_make_writepacket(hi->host, ne->nodeid,
+				       addr, data, data_size);
+
+        if (!packet)
+                return NULL;
+
+	hpsb_set_packet_complete_task(packet, (void (*)(void*))sbp2_free_packet,
+				      packet);
+
+	hpsb_node_fill_packet(ne, packet);
+
+	return packet;
+}
+
+
+/*
+ * This function is called to create a pool of command orbs used for
+ * command processing. It is called when a new sbp2 device is detected.
+ */
+static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_id)
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	int i;
+	unsigned long flags, orbs;
+	struct sbp2_command_info *command;
+
+	orbs = serialize_io ? 2 : SBP2_MAX_COMMAND_ORBS;
+        
+	spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
+	for (i = 0; i < orbs; i++) {
+		command = (struct sbp2_command_info *)
+		    kmalloc(sizeof(struct sbp2_command_info), GFP_ATOMIC);
+		if (!command) {
+			spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+			return(-ENOMEM);
+		}
+		memset(command, '\0', sizeof(struct sbp2_command_info));
+		command->command_orb_dma =
+			pci_map_single (hi->host->pdev, &command->command_orb,
+					sizeof(struct sbp2_command_orb),
+					PCI_DMA_BIDIRECTIONAL);
+		SBP2_DMA_ALLOC("single command orb DMA");
+		command->sge_dma =
+			pci_map_single (hi->host->pdev, &command->scatter_gather_element,
+					sizeof(command->scatter_gather_element),
+					PCI_DMA_BIDIRECTIONAL);
+		SBP2_DMA_ALLOC("scatter_gather_element");
+		INIT_LIST_HEAD(&command->list);
+		list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed);
+	}
+	spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+	return 0;
+}
+
+/*
+ * This function is called to delete a pool of command orbs.
+ */
+static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_id)
+{
+	struct hpsb_host *host = scsi_id->hi->host;
+	struct list_head *lh, *next;
+	struct sbp2_command_info *command;
+	unsigned long flags;
+        
+	spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
+	if (!list_empty(&scsi_id->sbp2_command_orb_completed)) {
+		list_for_each_safe(lh, next, &scsi_id->sbp2_command_orb_completed) {
+			command = list_entry(lh, struct sbp2_command_info, list);
+
+			/* Release our generic DMA's */
+			pci_unmap_single(host->pdev, command->command_orb_dma,
+					 sizeof(struct sbp2_command_orb),
+					 PCI_DMA_BIDIRECTIONAL);
+			SBP2_DMA_FREE("single command orb DMA");
+			pci_unmap_single(host->pdev, command->sge_dma,
+					 sizeof(command->scatter_gather_element),
+					 PCI_DMA_BIDIRECTIONAL);
+			SBP2_DMA_FREE("scatter_gather_element");
+
+			kfree(command);
+		}
+	}
+	spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+	return;
+}
+
+/* 
+ * This function finds the sbp2_command for a given outstanding command
+ * orb.Only looks at the inuse list.
+ */
+static struct sbp2_command_info *sbp2util_find_command_for_orb(
+		struct scsi_id_instance_data *scsi_id, dma_addr_t orb)
+{
+	struct list_head *lh;
+	struct sbp2_command_info *command;
+	unsigned long flags;
+
+	spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
+	if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) {
+		list_for_each(lh, &scsi_id->sbp2_command_orb_inuse) {
+			command = list_entry(lh, struct sbp2_command_info, list);
+			if (command->command_orb_dma == orb) {
+				spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+				return (command);
+			}
+		}
+	}
+	spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+
+	SBP2_ORB_DEBUG("could not match command orb %x", (unsigned int)orb);
+
+	return(NULL);
+}
+
+/* 
+ * This function finds the sbp2_command for a given outstanding SCpnt.
+ * Only looks at the inuse list.
+ */
+static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(struct scsi_id_instance_data *scsi_id, void *SCpnt)
+{
+	struct list_head *lh;
+	struct sbp2_command_info *command;
+	unsigned long flags;
+
+	spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
+	if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) {
+		list_for_each(lh, &scsi_id->sbp2_command_orb_inuse) {
+			command = list_entry(lh, struct sbp2_command_info, list);
+			if (command->Current_SCpnt == SCpnt) {
+				spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+				return (command);
+			}
+		}
+	}
+	spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+	return(NULL);
+}
+
+/*
+ * This function allocates a command orb used to send a scsi command.
+ */
+static struct sbp2_command_info *sbp2util_allocate_command_orb(
+		struct scsi_id_instance_data *scsi_id, 
+		Scsi_Cmnd *Current_SCpnt, 
+		void (*Current_done)(Scsi_Cmnd *))
+{
+	struct list_head *lh;
+	struct sbp2_command_info *command = NULL;
+	unsigned long flags;
+
+	spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
+	if (!list_empty(&scsi_id->sbp2_command_orb_completed)) {
+		lh = scsi_id->sbp2_command_orb_completed.next;
+		list_del(lh);
+		command = list_entry(lh, struct sbp2_command_info, list);
+		command->Current_done = Current_done;
+		command->Current_SCpnt = Current_SCpnt;
+		list_add_tail(&command->list, &scsi_id->sbp2_command_orb_inuse);
+	} else {
+		SBP2_ERR("sbp2util_allocate_command_orb - No orbs available!");
+	}
+	spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+	return (command);
+}
+
+/* Free our DMA's */
+static void sbp2util_free_command_dma(struct sbp2_command_info *command)
+{
+	struct hpsb_host *host;
+
+	host = hpsb_get_host_bykey(&sbp2_highlevel,
+			(unsigned long)command->Current_SCpnt->device->host);
+	if (!host) {
+		printk(KERN_ERR "%s: host == NULL\n", __FUNCTION__);
+		return;
+	}
+
+	if (command->cmd_dma) {
+		if (command->dma_type == CMD_DMA_SINGLE) {
+			pci_unmap_single(host->pdev, command->cmd_dma,
+					 command->dma_size, command->dma_dir);
+			SBP2_DMA_FREE("single bulk");
+		} else if (command->dma_type == CMD_DMA_PAGE) {
+			pci_unmap_page(host->pdev, command->cmd_dma,
+				       command->dma_size, command->dma_dir);
+			SBP2_DMA_FREE("single page");
+		} /* XXX: Check for CMD_DMA_NONE bug */
+		command->dma_type = CMD_DMA_NONE;
+		command->cmd_dma = 0;
+	}
+
+	if (command->sge_buffer) {
+		pci_unmap_sg(host->pdev, command->sge_buffer,
+			     command->dma_size, command->dma_dir);
+		SBP2_DMA_FREE("scatter list");
+		command->sge_buffer = NULL;
+	}
+}
+
+/*
+ * This function moves a command to the completed orb list.
+ */
+static void sbp2util_mark_command_completed(struct scsi_id_instance_data *scsi_id, struct sbp2_command_info *command)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
+	list_del(&command->list);
+	sbp2util_free_command_dma(command);
+	list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed);
+	spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
+}
+
+
+
+/*********************************************
+ * IEEE-1394 core driver stack related section
+ *********************************************/
+
+static int sbp2_probe(struct device *dev)
+{
+	struct unit_directory *ud;
+	struct sbp2scsi_host_info *hi;
+
+	SBP2_DEBUG(__FUNCTION__);
+
+	ud = container_of(dev, struct unit_directory, device);
+
+	/* This will only add it if it doesn't exist */
+	hi = sbp2_add_host(ud->ne->host);
+
+	if (!hi)
+		return -ENODEV;
+
+	return sbp2_start_ud(hi, ud);
+}
+
+static int sbp2_remove(struct device *dev)
+{
+	struct scsi_id_group *scsi_group;
+	struct list_head *lh, *next;
+	struct unit_directory *ud;
+	struct scsi_id_instance_data *scsi_id;
+
+	SBP2_DEBUG(__FUNCTION__);
+
+	ud = container_of(dev, struct unit_directory, device);
+	scsi_group = ud->device.driver_data;
+	ud->device.driver_data = NULL;
+
+	list_for_each_safe (lh, next, &scsi_group->scsi_id_list) {
+		scsi_id = list_entry(lh, struct scsi_id_instance_data, list);
+
+		if (scsi_id != NULL) {
+			sbp2_logout_device(scsi_id);
+ 			sbp2_remove_device(scsi_id);
+		}
+	}
+
+	kfree(scsi_group);
+
+	return 0;
+}
+
+static void sbp2_update(struct unit_directory *ud)
+{
+	struct sbp2scsi_host_info *hi;
+	struct scsi_id_group *scsi_group = ud->device.driver_data;
+	struct list_head *lh, *next;
+	struct scsi_id_instance_data *scsi_id;
+	unsigned long flags;
+
+	SBP2_DEBUG("sbp2_update");
+
+	list_for_each_safe (lh, next, &scsi_group->scsi_id_list) {
+		scsi_id = list_entry(lh, struct scsi_id_instance_data, list);
+
+		hi = scsi_id->hi;
+
+		if (sbp2_reconnect_device(scsi_id)) {
+		
+			/* 
+			 * Ok, reconnect has failed. Perhaps we didn't
+			 * reconnect fast enough. Try doing a regular login.
+			 */
+			if (sbp2_login_device(scsi_id)) {
+				/* Login failed too, just remove the device. */
+				SBP2_ERR("sbp2_reconnect_device failed!");
+				sbp2_remove_device(scsi_id);
+				return;
+			}
+		}
+
+		/* Set max retries to something large on the device. */
+		sbp2_set_busy_timeout(scsi_id);
+
+		/* Do a SBP-2 fetch agent reset. */
+		sbp2_agent_reset(scsi_id, 1);
+	
+		/* Get the max speed and packet size that we can use. */
+		sbp2_max_speed_and_size(scsi_id);
+
+		/* Complete any pending commands with busy (so they get
+		 * retried) and remove them from our queue
+		 */
+		spin_lock_irqsave(&hi->sbp2_command_lock, flags);
+		sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY);
+		spin_unlock_irqrestore(&hi->sbp2_command_lock, flags);
+	}
+}
+
+/* This functions is called by the sbp2_probe, for each new device. If the
+ * host_info already exists, it will return it. If not, it allocated a new
+ * host_info entry and a corresponding scsi_host. */
+static struct sbp2scsi_host_info *sbp2_add_host(struct hpsb_host *host)
+{
+	struct sbp2scsi_host_info *hi;
+	struct Scsi_Host *scsi_host;
+
+	SBP2_DEBUG("sbp2_add_host");
+
+	hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
+	if (hi)
+		return hi;
+
+	/* Register our host with the SCSI stack. */
+	scsi_host = scsi_register (&scsi_driver_template, 0);
+	if (!scsi_host) {
+		SBP2_ERR("failed to register scsi host");
+		return NULL;
+	}
+
+	hi = hpsb_create_hostinfo(&sbp2_highlevel, host, sizeof(*hi));
+	if (!hi) {
+		SBP2_ERR("failed to allocate hostinfo");
+		scsi_unregister(hi->scsi_host);
+	}
+
+	hpsb_set_hostinfo_key(&sbp2_highlevel, host, (unsigned long)scsi_host);
+
+	hi->scsi_host = scsi_host;
+	hi->host = host;
+	hi->sbp2_command_lock = SPIN_LOCK_UNLOCKED;
+	hi->scsi_host->max_id = SBP2SCSI_MAX_SCSI_IDS;
+
+	/* XXX We need a device to pass here as the scsi-host class. Can't
+	 * use the PCI device, since it is already bound to the ieee1394
+	 * host. Can't use the fw-host device since it is multi-class
+	 * enabled (scsi-host uses classdata member of the device). */
+	if (scsi_add_host(hi->scsi_host, NULL)) {
+		SBP2_ERR("failed to add scsi host");
+		scsi_unregister(hi->scsi_host);
+		hpsb_destroy_hostinfo(&sbp2_highlevel, host);
+	}
+
+	return hi;
+}
+
+
+/*
+ * This function is called when a host is removed.
+ */
+static void sbp2_remove_host(struct hpsb_host *host)
+{
+	struct sbp2scsi_host_info *hi;
+
+	SBP2_DEBUG("sbp2_remove_host");
+
+	hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
+
+	if (hi) {
+		scsi_remove_host(hi->scsi_host);
+		scsi_unregister(hi->scsi_host);
+	}
+}
+
+static int sbp2_start_ud(struct sbp2scsi_host_info *hi, struct unit_directory *ud)
+{
+	struct scsi_id_instance_data *scsi_id;
+	struct scsi_id_group *scsi_group;
+	struct list_head *lh, *next;
+
+	SBP2_DEBUG("sbp2_start_ud");
+
+	scsi_group = kmalloc(sizeof(*scsi_group), GFP_KERNEL);
+	if (!scsi_group) {
+		SBP2_ERR ("Could not allocate memory for scsi_group");
+		return -ENOMEM;
+	}
+
+	INIT_LIST_HEAD(&scsi_group->scsi_id_list);
+	ud->device.driver_data = scsi_group;
+	sbp2_parse_unit_directory(scsi_group, ud);
+
+	list_for_each_safe (lh, next, &scsi_group->scsi_id_list) {
+		scsi_id = list_entry(lh, struct scsi_id_instance_data, list);
+
+		scsi_id->ne = ud->ne;
+		scsi_id->hi = hi;
+		scsi_id->speed_code = IEEE1394_SPEED_100;
+		scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100];
+		atomic_set(&scsi_id->sbp2_login_complete, 0);
+		INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse);
+		INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed);
+		scsi_id->sbp2_command_orb_lock = SPIN_LOCK_UNLOCKED;
+
+		sbp2_start_device(scsi_id);
+	}
+
+	/* Check to see if any of our devices survived the ordeal */
+	if (list_empty(&scsi_group->scsi_id_list)) {
+		kfree(scsi_group);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+
+/*
+ * This function is where we first pull the node unique ids, and then
+ * allocate memory and register a SBP-2 device.
+ */
+static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	struct scsi_device *sdev;
+	int i;
+
+	SBP2_DEBUG("sbp2_start_device");
+
+	/* Login FIFO DMA */
+	scsi_id->login_response =
+		pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_login_response),
+				     &scsi_id->login_response_dma);
+	if (!scsi_id->login_response)
+		goto alloc_fail;
+	SBP2_DMA_ALLOC("consistent DMA region for login FIFO");
+
+	/* Query logins ORB DMA */
+	scsi_id->query_logins_orb =
+		pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_query_logins_orb),
+				     &scsi_id->query_logins_orb_dma);
+	if (!scsi_id->query_logins_orb)
+		goto alloc_fail;
+	SBP2_DMA_ALLOC("consistent DMA region for query logins ORB");
+
+	/* Query logins response DMA */
+	scsi_id->query_logins_response =
+		pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_query_logins_response),
+				     &scsi_id->query_logins_response_dma);
+	if (!scsi_id->query_logins_response)
+		goto alloc_fail;
+	SBP2_DMA_ALLOC("consistent DMA region for query logins response");
+
+	/* Reconnect ORB DMA */
+	scsi_id->reconnect_orb =
+		pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_reconnect_orb),
+				     &scsi_id->reconnect_orb_dma);
+	if (!scsi_id->reconnect_orb)
+		goto alloc_fail;
+	SBP2_DMA_ALLOC("consistent DMA region for reconnect ORB");
+
+	/* Logout ORB DMA */
+	scsi_id->logout_orb =
+		pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_logout_orb),
+				     &scsi_id->logout_orb_dma);
+	if (!scsi_id->logout_orb)
+		goto alloc_fail;
+	SBP2_DMA_ALLOC("consistent DMA region for logout ORB");
+
+	/* Login ORB DMA */
+	scsi_id->login_orb =
+		pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_login_orb),
+				     &scsi_id->login_orb_dma);
+	if (!scsi_id->login_orb) {
+alloc_fail:
+		if (scsi_id->query_logins_response) {
+			pci_free_consistent(hi->host->pdev,
+					    sizeof(struct sbp2_query_logins_response),
+					    scsi_id->query_logins_response,
+					    scsi_id->query_logins_response_dma);
+			SBP2_DMA_FREE("query logins response DMA");
+		}
+
+		if (scsi_id->query_logins_orb) {
+			pci_free_consistent(hi->host->pdev,
+					    sizeof(struct sbp2_query_logins_orb),
+					    scsi_id->query_logins_orb,
+					    scsi_id->query_logins_orb_dma);
+			SBP2_DMA_FREE("query logins ORB DMA");
+		}
+	
+		if (scsi_id->logout_orb) {
+			pci_free_consistent(hi->host->pdev,
+					sizeof(struct sbp2_logout_orb),
+					scsi_id->logout_orb,
+					scsi_id->logout_orb_dma);
+			SBP2_DMA_FREE("logout ORB DMA");
+		}
+
+		if (scsi_id->reconnect_orb) {
+			pci_free_consistent(hi->host->pdev,
+					sizeof(struct sbp2_reconnect_orb),
+					scsi_id->reconnect_orb,
+					scsi_id->reconnect_orb_dma);
+			SBP2_DMA_FREE("reconnect ORB DMA");
+		}
+
+		if (scsi_id->login_response) {
+			pci_free_consistent(hi->host->pdev,
+					sizeof(struct sbp2_login_response),
+					scsi_id->login_response,
+					scsi_id->login_response_dma);
+			SBP2_DMA_FREE("login FIFO DMA");
+		}
+
+		kfree(scsi_id);
+
+		list_del(&scsi_id->list);
+
+		SBP2_ERR ("Could not allocate memory for scsi_id");
+
+		return -ENOMEM;
+	}
+	SBP2_DMA_ALLOC("consistent DMA region for login ORB");
+
+	/*
+	 * Find an empty spot to stick our scsi id instance data. 
+	 */
+	for (i = 0; i < hi->scsi_host->max_id; i++) {
+		if (!hi->scsi_id[i]) {
+			hi->scsi_id[i] = scsi_id;
+			scsi_id->id = i;
+			SBP2_DEBUG("New SBP-2 device inserted, SCSI ID = %x", (unsigned int) i);
+			break;
+		}
+	}
+
+	/*
+	 * Create our command orb pool
+	 */
+	if (sbp2util_create_command_orb_pool(scsi_id)) {
+		SBP2_ERR("sbp2util_create_command_orb_pool failed!");
+		sbp2_remove_device(scsi_id);
+		return -ENOMEM;
+	}
+
+	/*
+	 * Make sure we are not out of space
+	 */
+	if (i == hi->scsi_host->max_id) {
+		SBP2_ERR("No slots left for SBP-2 device");
+		sbp2_remove_device(scsi_id);
+		return -EBUSY;
+	}
+
+	/*
+	 * Login to the sbp-2 device
+	 */
+	if (sbp2_login_device(scsi_id)) {
+		/* Login failed, just remove the device. */
+		sbp2_remove_device(scsi_id);
+		return -EBUSY;
+	}
+
+	/*
+	 * Set max retries to something large on the device
+	 */
+	sbp2_set_busy_timeout(scsi_id);
+	
+	/*
+	 * Do a SBP-2 fetch agent reset
+	 */
+	sbp2_agent_reset(scsi_id, 1);
+	
+	/*
+	 * Get the max speed and packet size that we can use
+	 */
+	sbp2_max_speed_and_size(scsi_id);
+
+	/* Add this device to the scsi layer now */
+	sdev = scsi_add_device(hi->scsi_host, 0, scsi_id->id, 0);
+	if (IS_ERR(sdev)) {
+		SBP2_ERR("scsi_add_device failed");
+		return PTR_ERR(sdev);
+	}
+
+	return 0;
+}
+
+/*
+ * This function removes an sbp2 device from the sbp2scsi_host_info struct.
+ */
+static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	struct scsi_device *sdev = scsi_find_device(hi->scsi_host, 0, scsi_id->id, 0);
+
+	SBP2_DEBUG("sbp2_remove_device");
+
+	/* Complete any pending commands with selection timeout */
+	sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT);
+
+	/* Remove it from the scsi layer now */
+	if (sdev && scsi_remove_device(sdev))
+		SBP2_ERR("scsi_remove_device failed");
+
+	sbp2util_remove_command_orb_pool(scsi_id);
+
+	hi->scsi_id[scsi_id->id] = NULL;
+
+	if (scsi_id->login_response) {
+		pci_free_consistent(hi->host->pdev,
+				    sizeof(struct sbp2_login_response),
+				    scsi_id->login_response,
+				    scsi_id->login_response_dma);
+		SBP2_DMA_FREE("single login FIFO");
+	}
+
+	if (scsi_id->login_orb) {
+		pci_free_consistent(hi->host->pdev,
+				    sizeof(struct sbp2_login_orb),
+				    scsi_id->login_orb,
+				    scsi_id->login_orb_dma);
+		SBP2_DMA_FREE("single login ORB");
+	}
+
+	if (scsi_id->reconnect_orb) {
+		pci_free_consistent(hi->host->pdev,
+				    sizeof(struct sbp2_reconnect_orb),
+				    scsi_id->reconnect_orb,
+				    scsi_id->reconnect_orb_dma);
+		SBP2_DMA_FREE("single reconnect orb");
+	}
+
+	if (scsi_id->logout_orb) {
+		pci_free_consistent(hi->host->pdev,
+				    sizeof(struct sbp2_logout_orb),
+				    scsi_id->logout_orb,
+				    scsi_id->logout_orb_dma);
+		SBP2_DMA_FREE("single logout orb");
+	}
+
+	if (scsi_id->query_logins_orb) {
+		pci_free_consistent(hi->host->pdev,
+				    sizeof(struct sbp2_query_logins_orb),
+				    scsi_id->query_logins_orb,
+				    scsi_id->query_logins_orb_dma);
+		SBP2_DMA_FREE("single query logins orb");
+	}
+
+	if (scsi_id->query_logins_response) {
+		pci_free_consistent(hi->host->pdev,
+				    sizeof(struct sbp2_query_logins_response),
+				    scsi_id->query_logins_response,
+				    scsi_id->query_logins_response_dma);
+		SBP2_DMA_FREE("single query logins data");
+	}
+
+	SBP2_DEBUG("SBP-2 device removed, SCSI ID = %d", scsi_id->id);
+
+	list_del(&scsi_id->list);
+
+	kfree(scsi_id);
+}
+
+#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
+/*
+ * This function deals with physical dma write requests (for adapters that do not support
+ * physical dma in hardware). Mostly just here for debugging...
+ */
+static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid, int destid, quadlet_t *data,
+                                     u64 addr, unsigned int length, u16 flags)
+{
+
+        /*
+         * Manually put the data in the right place.
+         */
+        memcpy(bus_to_virt((u32)addr), data, length);
+	sbp2util_packet_dump(data, length, "sbp2 phys dma write by device", (u32)addr);
+        return(RCODE_COMPLETE);
+}
+
+/*
+ * This function deals with physical dma read requests (for adapters that do not support
+ * physical dma in hardware). Mostly just here for debugging...
+ */
+static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, quadlet_t *data,
+                                    u64 addr, unsigned int length, u16 flags)
+{
+
+        /*
+         * Grab data from memory and send a read response.
+         */
+        memcpy(data, bus_to_virt((u32)addr), length);
+	sbp2util_packet_dump(data, length, "sbp2 phys dma read by device", (u32)addr);
+        return(RCODE_COMPLETE);
+}
+#endif
+
+
+/**************************************
+ * SBP-2 protocol related section
+ **************************************/
+
+/*
+ * This function determines if we should convert scsi commands for a particular sbp2 device type
+ */
+static __inline__ int sbp2_command_conversion_device_type(u8 device_type)
+{
+	return (((device_type == TYPE_DISK) ||
+		 (device_type == TYPE_SDAD) ||
+		 (device_type == TYPE_ROM)) ? 1:0);
+}
+
+/*
+ * This function queries the device for the maximum concurrent logins it
+ * supports.
+ */
+static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	quadlet_t data[2];
+	int max_logins;
+	int active_logins;
+
+	SBP2_DEBUG("sbp2_query_logins");
+
+	scsi_id->query_logins_orb->reserved1 = 0x0;
+	scsi_id->query_logins_orb->reserved2 = 0x0;
+
+	scsi_id->query_logins_orb->query_response_lo = scsi_id->query_logins_response_dma;
+	scsi_id->query_logins_orb->query_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
+	SBP2_DEBUG("sbp2_query_logins: query_response_hi/lo initialized");
+
+	scsi_id->query_logins_orb->lun_misc = ORB_SET_FUNCTION(QUERY_LOGINS_REQUEST);
+	scsi_id->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1);
+	if (scsi_id->sbp2_device_type_and_lun != SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) {
+		scsi_id->query_logins_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun);
+		SBP2_DEBUG("sbp2_query_logins: set lun to %d",
+			   ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun));
+	}
+	SBP2_DEBUG("sbp2_query_logins: lun_misc initialized");
+
+	scsi_id->query_logins_orb->reserved_resp_length =
+		ORB_SET_QUERY_LOGINS_RESP_LENGTH(sizeof(struct sbp2_query_logins_response));
+	SBP2_DEBUG("sbp2_query_logins: reserved_resp_length initialized");
+
+	scsi_id->query_logins_orb->status_FIFO_lo = SBP2_STATUS_FIFO_ADDRESS_LO +
+						    SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(scsi_id->id);
+	scsi_id->query_logins_orb->status_FIFO_hi = (ORB_SET_NODE_ID(hi->host->node_id) |
+						     SBP2_STATUS_FIFO_ADDRESS_HI);
+	SBP2_DEBUG("sbp2_query_logins: status FIFO initialized");
+
+	sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb));
+
+	SBP2_DEBUG("sbp2_query_logins: orb byte-swapped");
+
+	sbp2util_packet_dump(scsi_id->query_logins_orb, sizeof(stuct sbp2_query_logins_orb),
+			     "sbp2 query logins orb", scsi_id->query_logins_orb_dma);
+
+	memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response));
+	memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
+
+	SBP2_DEBUG("sbp2_query_logins: query_logins_response/status FIFO memset");
+
+	data[0] = ORB_SET_NODE_ID(hi->host->node_id);
+	data[1] = scsi_id->query_logins_orb_dma;
+	sbp2util_cpu_to_be32_buffer(data, 8);
+
+	atomic_set(&scsi_id->sbp2_login_complete, 0);
+
+	SBP2_DEBUG("sbp2_query_logins: prepared to write");
+	hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
+	SBP2_DEBUG("sbp2_query_logins: written");
+
+	if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 2*HZ)) {
+		SBP2_ERR("Error querying logins to SBP-2 device - timed out");
+		return(-EIO);
+	}
+
+	if (scsi_id->status_block.ORB_offset_lo != scsi_id->query_logins_orb_dma) {
+		SBP2_ERR("Error querying logins to SBP-2 device - timed out");
+		return(-EIO);
+	}
+
+	if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) ||
+	    STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) ||
+	    STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
+
+		SBP2_ERR("Error querying logins to SBP-2 device - timed out");
+		return(-EIO);
+	}
+
+	sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_response, sizeof(struct sbp2_query_logins_response));
+
+	SBP2_DEBUG("length_max_logins = %x",
+		   (unsigned int)scsi_id->query_logins_response->length_max_logins);
+
+	SBP2_INFO("Query logins to SBP-2 device successful");
+
+	max_logins = RESPONSE_GET_MAX_LOGINS(scsi_id->query_logins_response->length_max_logins);
+	SBP2_INFO("Maximum concurrent logins supported: %d", max_logins);
+                                                                                
+	active_logins = RESPONSE_GET_ACTIVE_LOGINS(scsi_id->query_logins_response->length_max_logins);
+	SBP2_INFO("Number of active logins: %d", active_logins);
+                                                                                
+	if (active_logins >= max_logins) {
+		return(-EIO);
+	}
+                                                                                
+	return 0;
+}
+
+/*
+ * This function is called in order to login to a particular SBP-2 device,
+ * after a bus reset.
+ */
+static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) 
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	quadlet_t data[2];
+
+	SBP2_DEBUG("sbp2_login_device");
+
+	if (!scsi_id->login_orb) {
+		SBP2_DEBUG("sbp2_login_device: login_orb not alloc'd!");
+		return(-EIO);
+	}
+
+	if (!exclusive_login) {
+		if (sbp2_query_logins(scsi_id)) {
+			SBP2_ERR("Device does not support any more concurrent logins");
+			return(-EIO);
+		}
+	}
+
+	/* Set-up login ORB, assume no password */
+	scsi_id->login_orb->password_hi = 0; 
+	scsi_id->login_orb->password_lo = 0;
+	SBP2_DEBUG("sbp2_login_device: password_hi/lo initialized");
+
+	scsi_id->login_orb->login_response_lo = scsi_id->login_response_dma;
+	scsi_id->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
+	SBP2_DEBUG("sbp2_login_device: login_response_hi/lo initialized");
+
+	scsi_id->login_orb->lun_misc = ORB_SET_FUNCTION(LOGIN_REQUEST);
+	scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0);	/* One second reconnect time */
+	scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login);	/* Exclusive access to device */
+	scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1);	/* Notify us of login complete */
+	/* Set the lun if we were able to pull it from the device's unit directory */
+	if (scsi_id->sbp2_device_type_and_lun != SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) {
+		scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun);
+		SBP2_DEBUG("sbp2_query_logins: set lun to %d",
+			   ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun));
+	}
+	SBP2_DEBUG("sbp2_login_device: lun_misc initialized");
+
+	scsi_id->login_orb->passwd_resp_lengths =
+		ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response));
+	SBP2_DEBUG("sbp2_login_device: passwd_resp_lengths initialized");
+
+	scsi_id->login_orb->status_FIFO_lo = SBP2_STATUS_FIFO_ADDRESS_LO + 
+					     SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(scsi_id->id);
+	scsi_id->login_orb->status_FIFO_hi = (ORB_SET_NODE_ID(hi->host->node_id) |
+					      SBP2_STATUS_FIFO_ADDRESS_HI);
+	SBP2_DEBUG("sbp2_login_device: status FIFO initialized");
+
+	/*
+	 * Byte swap ORB if necessary
+	 */
+	sbp2util_cpu_to_be32_buffer(scsi_id->login_orb, sizeof(struct sbp2_login_orb));
+
+	SBP2_DEBUG("sbp2_login_device: orb byte-swapped");
+
+	sbp2util_packet_dump(scsi_id->login_orb, sizeof(struct sbp2_login_orb), 
+			     "sbp2 login orb", scsi_id->login_orb_dma);
+
+	/*
+	 * Initialize login response and status fifo
+	 */
+	memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response));
+	memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
+
+	SBP2_DEBUG("sbp2_login_device: login_response/status FIFO memset");
+
+	/*
+	 * Ok, let's write to the target's management agent register
+	 */
+	data[0] = ORB_SET_NODE_ID(hi->host->node_id);
+	data[1] = scsi_id->login_orb_dma;
+	sbp2util_cpu_to_be32_buffer(data, 8);
+
+	atomic_set(&scsi_id->sbp2_login_complete, 0);
+
+	SBP2_DEBUG("sbp2_login_device: prepared to write to %08x",
+		   (unsigned int)scsi_id->sbp2_management_agent_addr);
+	hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
+	SBP2_DEBUG("sbp2_login_device: written");
+
+	/*
+	 * Wait for login status (up to 20 seconds)... 
+	 */
+	if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 20*HZ)) {
+		SBP2_ERR("Error logging into SBP-2 device - login timed-out");
+		return(-EIO);
+	}
+
+	/*
+	 * Sanity. Make sure status returned matches login orb.
+	 */
+	if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) {
+		SBP2_ERR("Error logging into SBP-2 device - login timed-out");
+		return(-EIO);
+	}
+
+	/*
+	 * Check status
+	 */
+	if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) ||
+	    STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) ||
+	    STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
+
+		SBP2_ERR("Error logging into SBP-2 device - login failed");
+		return(-EIO);
+	}
+
+	/*
+	 * Byte swap the login response, for use when reconnecting or
+	 * logging out.
+	 */
+	sbp2util_cpu_to_be32_buffer(scsi_id->login_response, sizeof(struct sbp2_login_response));
+
+	/*
+	 * Grab our command block agent address from the login response.
+	 */
+	SBP2_DEBUG("command_block_agent_hi = %x",
+		   (unsigned int)scsi_id->login_response->command_block_agent_hi);
+	SBP2_DEBUG("command_block_agent_lo = %x",
+		   (unsigned int)scsi_id->login_response->command_block_agent_lo);
+
+	scsi_id->sbp2_command_block_agent_addr =
+		((u64)scsi_id->login_response->command_block_agent_hi) << 32;
+	scsi_id->sbp2_command_block_agent_addr |= ((u64)scsi_id->login_response->command_block_agent_lo);
+	scsi_id->sbp2_command_block_agent_addr &= 0x0000ffffffffffffULL;
+
+	SBP2_INFO("Logged into SBP-2 device");
+
+	return(0);
+
+}
+
+/*
+ * This function is called in order to logout from a particular SBP-2
+ * device, usually called during driver unload.
+ */
+static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id) 
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	quadlet_t data[2];
+
+	SBP2_DEBUG("sbp2_logout_device");
+
+	/*
+	 * Set-up logout ORB
+	 */
+	scsi_id->logout_orb->reserved1 = 0x0;
+	scsi_id->logout_orb->reserved2 = 0x0;
+	scsi_id->logout_orb->reserved3 = 0x0;
+	scsi_id->logout_orb->reserved4 = 0x0;
+
+	scsi_id->logout_orb->login_ID_misc = ORB_SET_FUNCTION(LOGOUT_REQUEST);
+	scsi_id->logout_orb->login_ID_misc |= ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID);
+
+	/* Notify us when complete */
+	scsi_id->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
+
+	scsi_id->logout_orb->reserved5 = 0x0;
+	scsi_id->logout_orb->status_FIFO_lo = SBP2_STATUS_FIFO_ADDRESS_LO + 
+					      SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(scsi_id->id);
+	scsi_id->logout_orb->status_FIFO_hi = (ORB_SET_NODE_ID(hi->host->node_id) |
+					       SBP2_STATUS_FIFO_ADDRESS_HI);
+
+	/*
+	 * Byte swap ORB if necessary
+	 */
+	sbp2util_cpu_to_be32_buffer(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb));
+
+	sbp2util_packet_dump(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb), 
+			     "sbp2 logout orb", scsi_id->logout_orb_dma);
+
+	/*
+	 * Ok, let's write to the target's management agent register
+	 */
+	data[0] = ORB_SET_NODE_ID(hi->host->node_id);
+	data[1] = scsi_id->logout_orb_dma;
+	sbp2util_cpu_to_be32_buffer(data, 8);
+
+	atomic_set(&scsi_id->sbp2_login_complete, 0);
+
+	hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
+
+	/* Wait for device to logout...1 second. */
+	sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ);
+
+	SBP2_INFO("Logged out of SBP-2 device");
+
+	return(0);
+
+}
+
+/*
+ * This function is called in order to reconnect to a particular SBP-2
+ * device, after a bus reset.
+ */
+static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) 
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	quadlet_t data[2];
+
+	SBP2_DEBUG("sbp2_reconnect_device");
+
+	/*
+	 * Set-up reconnect ORB
+	 */
+	scsi_id->reconnect_orb->reserved1 = 0x0;
+	scsi_id->reconnect_orb->reserved2 = 0x0;
+	scsi_id->reconnect_orb->reserved3 = 0x0;
+	scsi_id->reconnect_orb->reserved4 = 0x0;
+
+	scsi_id->reconnect_orb->login_ID_misc = ORB_SET_FUNCTION(RECONNECT_REQUEST);
+	scsi_id->reconnect_orb->login_ID_misc |=
+		ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID);
+
+	/* Notify us when complete */
+	scsi_id->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
+
+	scsi_id->reconnect_orb->reserved5 = 0x0;
+	scsi_id->reconnect_orb->status_FIFO_lo = SBP2_STATUS_FIFO_ADDRESS_LO + 
+						 SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(scsi_id->id);
+	scsi_id->reconnect_orb->status_FIFO_hi =
+		(ORB_SET_NODE_ID(hi->host->node_id) | SBP2_STATUS_FIFO_ADDRESS_HI);
+
+	/*
+	 * Byte swap ORB if necessary
+	 */
+	sbp2util_cpu_to_be32_buffer(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb));
+
+	sbp2util_packet_dump(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb), 
+			     "sbp2 reconnect orb", scsi_id->reconnect_orb_dma);
+
+	/*
+	 * Initialize status fifo
+	 */
+	memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
+
+	/*
+	 * Ok, let's write to the target's management agent register
+	 */
+	data[0] = ORB_SET_NODE_ID(hi->host->node_id);
+	data[1] = scsi_id->reconnect_orb_dma;
+	sbp2util_cpu_to_be32_buffer(data, 8);
+
+	atomic_set(&scsi_id->sbp2_login_complete, 0);
+
+	hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
+
+	/*
+	 * Wait for reconnect status (up to 1 second)...
+	 */
+	if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ)) {
+		SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out");
+		return(-EIO);
+	}
+
+	/*
+	 * Sanity. Make sure status returned matches reconnect orb.
+	 */
+	if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) {
+		SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out");
+		return(-EIO);
+	}
+
+	/*
+	 * Check status
+	 */
+	if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) ||
+	    STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) ||
+	    STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
+
+		SBP2_ERR("Error reconnecting to SBP-2 device - reconnect failed");
+		return(-EIO);
+	}
+
+	SBP2_INFO("Reconnected to SBP-2 device");
+
+	return(0);
+
+}
+
+/*
+ * This function is called in order to set the busy timeout (number of
+ * retries to attempt) on the sbp2 device. 
+ */
+static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id)
+{
+	quadlet_t data;
+
+	SBP2_DEBUG("sbp2_set_busy_timeout");
+
+	/*
+	 * Ok, let's write to the target's busy timeout register
+	 */
+	data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE);
+
+	if (hpsb_node_write(scsi_id->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4)) {
+		SBP2_ERR("sbp2_set_busy_timeout error");
+	}
+
+	return(0);
+}
+
+/*
+ * This function is called to parse sbp2 device's config rom unit
+ * directory. Used to determine things like sbp2 management agent offset,
+ * and command set used (SCSI or RBC). 
+ */
+static void sbp2_parse_unit_directory(struct scsi_id_group *scsi_group,
+				      struct unit_directory *ud)
+{
+	struct scsi_id_instance_data *scsi_id;
+	struct list_head *lh;
+	u64 management_agent_addr;
+	u32 command_set_spec_id, command_set, unit_characteristics,
+		firmware_revision, workarounds;
+	int i;
+
+	SBP2_DEBUG("sbp2_parse_unit_directory");
+
+	management_agent_addr = 0x0;
+	command_set_spec_id = 0x0;
+	command_set = 0x0;
+	unit_characteristics = 0x0;
+	firmware_revision = 0x0;
+
+	/* Handle different fields in the unit directory, based on keys */
+	for (i = 0; i < ud->length; i++) {
+		switch (CONFIG_ROM_KEY(ud->quadlets[i])) {
+		case SBP2_CSR_OFFSET_KEY:
+			/* Save off the management agent address */
+			management_agent_addr =
+				CSR_REGISTER_BASE + 
+				(CONFIG_ROM_VALUE(ud->quadlets[i]) << 2);
+
+			SBP2_DEBUG("sbp2_management_agent_addr = %x",
+				   (unsigned int) management_agent_addr);
+			break;
+
+		case SBP2_COMMAND_SET_SPEC_ID_KEY:
+			/* Command spec organization */
+			command_set_spec_id
+				= CONFIG_ROM_VALUE(ud->quadlets[i]);
+			SBP2_DEBUG("sbp2_command_set_spec_id = %x",
+				   (unsigned int) command_set_spec_id);
+			break;
+
+		case SBP2_COMMAND_SET_KEY:
+			/* Command set used by sbp2 device */
+			command_set = CONFIG_ROM_VALUE(ud->quadlets[i]);
+			SBP2_DEBUG("sbp2_command_set = %x",
+				   (unsigned int) command_set);
+			break;
+
+		case SBP2_UNIT_CHARACTERISTICS_KEY:
+			/*
+			 * Unit characterisitcs (orb related stuff
+			 * that I'm not yet paying attention to)
+			 */
+			unit_characteristics
+				= CONFIG_ROM_VALUE(ud->quadlets[i]);
+			SBP2_DEBUG("sbp2_unit_characteristics = %x",
+				   (unsigned int) unit_characteristics);
+			break;
+
+		case SBP2_DEVICE_TYPE_AND_LUN_KEY:
+			/*
+			 * Device type and lun (used for
+			 * detemining type of sbp2 device)
+			 */
+			scsi_id = kmalloc(sizeof(*scsi_id), GFP_KERNEL);
+			if (!scsi_id) {
+				SBP2_ERR("Out of memory adding scsi_id, not all LUN's will be added");
+				break;
+			}
+			memset(scsi_id, 0, sizeof(*scsi_id));
+
+			scsi_id->sbp2_device_type_and_lun
+				= CONFIG_ROM_VALUE(ud->quadlets[i]);
+			SBP2_DEBUG("sbp2_device_type_and_lun = %x",
+				   (unsigned int) scsi_id->sbp2_device_type_and_lun);
+			list_add_tail(&scsi_id->list, &scsi_group->scsi_id_list);
+			break;
+
+		case SBP2_FIRMWARE_REVISION_KEY:
+			/* Firmware revision */
+			firmware_revision
+				= CONFIG_ROM_VALUE(ud->quadlets[i]);
+			if (force_inquiry_hack)
+				SBP2_INFO("sbp2_firmware_revision = %x",
+				   (unsigned int) firmware_revision);
+			else	SBP2_DEBUG("sbp2_firmware_revision = %x",
+				   (unsigned int) firmware_revision);
+			break;
+
+		default:
+			break;
+		}
+	}
+
+	/* This is the start of our broken device checking. We try to hack
+	 * around oddities and known defects.  */
+	workarounds = 0x0;
+
+	/* If the vendor id is 0xa0b8 (Symbios vendor id), then we have a
+	 * bridge with 128KB max transfer size limitation. For sanity, we
+	 * only voice this when the current max_sectors setting
+	 * exceeds the 128k limit. By default, that is not the case.
+	 *
+	 * It would be really nice if we could detect this before the scsi
+	 * host gets initialized. That way we can down-force the
+	 * max_sectors to account for it. That is not currently
+	 * possible.  */
+	if ((firmware_revision & 0xffff00) ==
+			SBP2_128KB_BROKEN_FIRMWARE &&
+			(max_sectors * 512) > (128*1024)) {
+		SBP2_WARN("Node " NODE_BUS_FMT ": Bridge only supports 128KB max transfer size.",
+				NODE_BUS_ARGS(ud->ne->nodeid));
+		SBP2_WARN("WARNING: Current max_sectors setting is larger than 128KB (%d sectors)!",
+				max_sectors);
+		workarounds |= SBP2_BREAKAGE_128K_MAX_TRANSFER;
+	}
+
+	/* Check for a blacklisted set of devices that require us to force
+	 * a 36 byte host inquiry. This can be overriden as a module param
+	 * (to force all hosts).  */
+	for (i = 0; i < NUM_BROKEN_INQUIRY_DEVS; i++) {
+		if ((firmware_revision & 0xffff00) ==
+				sbp2_broken_inquiry_list[i]) {
+			SBP2_WARN("Node " NODE_BUS_FMT ": Using 36byte inquiry workaround",
+					NODE_BUS_ARGS(ud->ne->nodeid));
+			workarounds |= SBP2_BREAKAGE_INQUIRY_HACK;
+			break; /* No need to continue. */
+		}
+	}
+
+	/* If our list is empty, add a base scsi_id (happens in a normal
+	 * case where there is no logical_unit_number entry */
+	if (list_empty(&scsi_group->scsi_id_list)) {
+		scsi_id = kmalloc(sizeof(*scsi_id), GFP_KERNEL);
+		if (!scsi_id) {
+			SBP2_ERR("Out of memory adding scsi_id");
+			return;
+		}
+		memset(scsi_id, 0, sizeof(*scsi_id));
+
+		scsi_id->sbp2_device_type_and_lun = SBP2_DEVICE_TYPE_LUN_UNINITIALIZED;
+		list_add_tail(&scsi_id->list, &scsi_group->scsi_id_list);
+	}
+
+	/* Update the generic fields in all the LUN's */
+	list_for_each (lh, &scsi_group->scsi_id_list) {
+		scsi_id = list_entry(lh, struct scsi_id_instance_data, list);
+
+		scsi_id->sbp2_management_agent_addr = management_agent_addr;
+		scsi_id->sbp2_command_set_spec_id = command_set_spec_id;
+		scsi_id->sbp2_command_set = command_set;
+		scsi_id->sbp2_unit_characteristics = unit_characteristics;
+		scsi_id->sbp2_firmware_revision = firmware_revision;
+		scsi_id->workarounds = workarounds;
+	}
+}
+
+/*
+ * This function is called in order to determine the max speed and packet
+ * size we can use in our ORBs. Note, that we (the driver and host) only
+ * initiate the transaction. The SBP-2 device actually transfers the data
+ * (by reading from the DMA area we tell it). This means that the SBP-2
+ * device decides the actual maximum data it can transfer. We just tell it
+ * the speed that it needs to use, and the max_rec the host supports, and
+ * it takes care of the rest.
+ */
+static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id)
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+
+	SBP2_DEBUG("sbp2_max_speed_and_size");
+
+	/* Initial setting comes from the hosts speed map */
+	scsi_id->speed_code = hi->host->speed_map[NODEID_TO_NODE(hi->host->node_id) * 64
+						  + NODEID_TO_NODE(scsi_id->ne->nodeid)];
+
+	/* Bump down our speed if the user requested it */
+	if (scsi_id->speed_code > max_speed) {
+		scsi_id->speed_code = max_speed;
+		SBP2_ERR("Forcing SBP-2 max speed down to %s",
+			 hpsb_speedto_str[scsi_id->speed_code]);
+	}
+
+	/* Payload size is the lesser of what our speed supports and what
+	 * our host supports.  */
+	scsi_id->max_payload_size = min(sbp2_speedto_max_payload[scsi_id->speed_code],
+					(u8)(((be32_to_cpu(hi->host->csr.rom[2]) >> 12) & 0xf) - 1));
+
+	SBP2_ERR("Node[" NODE_BUS_FMT "]: Max speed [%s] - Max payload [%u]",
+		 NODE_BUS_ARGS(scsi_id->ne->nodeid), hpsb_speedto_str[scsi_id->speed_code],
+		 1 << ((u32)scsi_id->max_payload_size + 2));
+
+	return(0);
+}
+
+/*
+ * This function is called in order to perform a SBP-2 agent reset. 
+ */
+static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) 
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	struct hpsb_packet *packet;
+	quadlet_t data;
+	
+	SBP2_DEBUG("sbp2_agent_reset");
+
+	/*
+	 * Ok, let's write to the target's management agent register
+	 */
+	data = ntohl(SBP2_AGENT_RESET_DATA);
+	packet = sbp2util_allocate_write_packet(hi, scsi_id->ne,
+						scsi_id->sbp2_command_block_agent_addr +
+						SBP2_AGENT_RESET_OFFSET,
+						4, &data);
+
+	if (!packet) {
+		SBP2_ERR("sbp2util_allocate_write_packet failed");
+		return(-ENOMEM);
+	}
+
+	if (!hpsb_send_packet(packet)) {
+		SBP2_ERR("hpsb_send_packet failed");
+		sbp2_free_packet(packet); 
+		return(-EIO);
+	}
+
+	if (wait) {
+		down(&packet->state_change);
+		down(&packet->state_change);
+	}
+
+	/*
+	 * Need to make sure orb pointer is written on next command
+	 */
+	scsi_id->last_orb = NULL;
+
+	return(0);
+}
+
+/*
+ * This function is called to create the actual command orb and s/g list
+ * out of the scsi command itself.
+ */
+static int sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id,
+				   struct sbp2_command_info *command,
+				   unchar *scsi_cmd,
+				   unsigned int scsi_use_sg,
+				   unsigned int scsi_request_bufflen,
+				   void *scsi_request_buffer, 
+				   unsigned char scsi_dir)
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	struct scatterlist *sgpnt = (struct scatterlist *) scsi_request_buffer;
+	struct sbp2_command_orb *command_orb = &command->command_orb;
+	struct sbp2_unrestricted_page_table *scatter_gather_element =
+		&command->scatter_gather_element[0];
+	int dma_dir = scsi_to_pci_dma_dir (scsi_dir);
+	u32 sg_count, sg_len, orb_direction;
+	dma_addr_t sg_addr;
+	int i;
+
+	/*
+	 * Set-up our command ORB..
+	 *
+	 * NOTE: We're doing unrestricted page tables (s/g), as this is
+	 * best performance (at least with the devices I have). This means
+	 * that data_size becomes the number of s/g elements, and
+	 * page_size should be zero (for unrestricted).
+	 */
+	command_orb->next_ORB_hi = ORB_SET_NULL_PTR(1);
+	command_orb->next_ORB_lo = 0x0;
+	command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size);
+	command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code);
+	command_orb->misc |= ORB_SET_NOTIFY(1);		/* Notify us when complete */
+
+	/*
+	 * Get the direction of the transfer. If the direction is unknown, then use our
+	 * goofy table as a back-up.
+	 */
+	switch (scsi_dir) {
+		case SCSI_DATA_NONE:
+			orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
+			break;
+		case SCSI_DATA_WRITE:
+			orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA;
+			break;
+		case SCSI_DATA_READ:
+			orb_direction = ORB_DIRECTION_READ_FROM_MEDIA;
+			break;
+		case SCSI_DATA_UNKNOWN:
+		default:
+			SBP2_ERR("SCSI data transfer direction not specified. "
+				 "Update the SBP2 direction table in sbp2.h if " 
+				 "necessary for your application");
+			print_command (scsi_cmd);
+			orb_direction = sbp2scsi_direction_table[*scsi_cmd];
+			break;
+	}
+
+	/*
+	 * Set-up our pagetable stuff... unfortunately, this has become
+	 * messier than I'd like. Need to clean this up a bit.   ;-)
+	 */
+	if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) {
+
+		SBP2_DEBUG("No data transfer");
+
+		/*
+		 * Handle no data transfer
+		 */
+		command_orb->data_descriptor_hi = 0x0;
+		command_orb->data_descriptor_lo = 0x0;
+		command_orb->misc |= ORB_SET_DIRECTION(1);
+
+	} else if (scsi_use_sg) {
+
+		SBP2_DEBUG("Use scatter/gather");
+
+		/*
+		 * Special case if only one element (and less than 64KB in size)
+		 */
+		if ((scsi_use_sg == 1) && (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) {
+
+			SBP2_DEBUG("Only one s/g element");
+			command->dma_dir = dma_dir;
+			command->dma_size = sgpnt[0].length;
+			command->dma_type = CMD_DMA_PAGE;
+			command->cmd_dma = pci_map_page(hi->host->pdev,
+							sgpnt[0].page,
+							sgpnt[0].offset,
+							command->dma_size,
+							command->dma_dir);
+			SBP2_DMA_ALLOC("single page scatter element");
+
+			command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
+			command_orb->data_descriptor_lo = command->cmd_dma;
+			command_orb->misc |= ORB_SET_DATA_SIZE(command->dma_size);
+			command_orb->misc |= ORB_SET_DIRECTION(orb_direction);
+
+		} else {
+			int count = pci_map_sg(hi->host->pdev, sgpnt, scsi_use_sg, dma_dir);
+			SBP2_DMA_ALLOC("scatter list");
+
+			command->dma_size = scsi_use_sg;
+			command->dma_dir = dma_dir;
+			command->sge_buffer = sgpnt;
+
+			/* use page tables (s/g) */
+			command_orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
+			command_orb->misc |= ORB_SET_DIRECTION(orb_direction);
+			command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
+			command_orb->data_descriptor_lo = command->sge_dma;
+
+			/*
+			 * Loop through and fill out our sbp-2 page tables
+			 * (and split up anything too large)
+			 */
+			for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) {
+				sg_len = sg_dma_len(sgpnt);
+				sg_addr = sg_dma_address(sgpnt);
+				while (sg_len) {
+					scatter_gather_element[sg_count].segment_base_lo = sg_addr;
+					if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) {
+						scatter_gather_element[sg_count].length_segment_base_hi =  
+							PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH);
+						sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH;
+						sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH;
+					} else {
+						scatter_gather_element[sg_count].length_segment_base_hi = 
+							PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len);
+						sg_len = 0;
+					}
+					sg_count++;
+				}
+			}
+
+			/* Number of page table (s/g) elements */
+			command_orb->misc |= ORB_SET_DATA_SIZE(sg_count);
+
+			sbp2util_packet_dump(scatter_gather_element, 
+					     (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, 
+					     "sbp2 s/g list", command->sge_dma);
+
+			/*
+			 * Byte swap page tables if necessary
+			 */
+			sbp2util_cpu_to_be32_buffer(scatter_gather_element, 
+						    (sizeof(struct sbp2_unrestricted_page_table)) *
+						    sg_count);
+
+		}
+
+	} else {
+
+		SBP2_DEBUG("No scatter/gather");
+
+		command->dma_dir = dma_dir;
+		command->dma_size = scsi_request_bufflen;
+		command->dma_type = CMD_DMA_SINGLE;
+		command->cmd_dma = pci_map_single (hi->host->pdev, scsi_request_buffer,
+						   command->dma_size,
+						   command->dma_dir);
+		SBP2_DMA_ALLOC("single bulk");
+
+		/*
+		 * Handle case where we get a command w/o s/g enabled (but
+		 * check for transfers larger than 64K)
+		 */
+		if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) {
+
+			command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
+			command_orb->data_descriptor_lo = command->cmd_dma;
+			command_orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen);
+			command_orb->misc |= ORB_SET_DIRECTION(orb_direction);
+
+			/*
+			 * Sanity, in case our direction table is not
+			 * up-to-date
+			 */
+			if (!scsi_request_bufflen) {
+				command_orb->data_descriptor_hi = 0x0;
+				command_orb->data_descriptor_lo = 0x0;
+				command_orb->misc |= ORB_SET_DIRECTION(1);
+			}
+
+		} else {
+			/*
+			 * Need to turn this into page tables, since the
+			 * buffer is too large.
+			 */                     
+			command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
+			command_orb->data_descriptor_lo = command->sge_dma;
+
+			/* Use page tables (s/g) */
+			command_orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
+			command_orb->misc |= ORB_SET_DIRECTION(orb_direction);
+
+			/*
+			 * fill out our sbp-2 page tables (and split up
+			 * the large buffer)
+			 */
+			sg_count = 0;
+			sg_len = scsi_request_bufflen;
+			sg_addr = command->cmd_dma;
+			while (sg_len) {
+				scatter_gather_element[sg_count].segment_base_lo = sg_addr;
+				if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) {
+					scatter_gather_element[sg_count].length_segment_base_hi = 
+						PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH);
+					sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH;
+					sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH;
+				} else {
+					scatter_gather_element[sg_count].length_segment_base_hi = 
+						PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len);
+					sg_len = 0;
+				}
+				sg_count++;
+			}
+
+			/* Number of page table (s/g) elements */
+			command_orb->misc |= ORB_SET_DATA_SIZE(sg_count);
+
+			sbp2util_packet_dump(scatter_gather_element, 
+					     (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, 
+					     "sbp2 s/g list", command->sge_dma);
+
+			/*
+			 * Byte swap page tables if necessary
+			 */
+			sbp2util_cpu_to_be32_buffer(scatter_gather_element, 
+						    (sizeof(struct sbp2_unrestricted_page_table)) *
+						     sg_count);
+
+		}
+
+	}
+
+	/*
+	 * Byte swap command ORB if necessary
+	 */
+	sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb));
+
+	/*
+	 * Put our scsi command in the command ORB
+	 */
+	memset(command_orb->cdb, 0, 12);
+	memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd));
+
+	return(0);
+}
+ 
+/*
+ * This function is called in order to begin a regular SBP-2 command. 
+ */
+static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
+				 struct sbp2_command_info *command)
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+        struct hpsb_packet *packet;
+	struct sbp2_command_orb *command_orb = &command->command_orb;
+
+	outstanding_orb_incr;
+	SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x",
+			command_orb, global_outstanding_command_orbs);
+
+	pci_dma_sync_single(hi->host->pdev, command->command_orb_dma,
+			    sizeof(struct sbp2_command_orb),
+			    PCI_DMA_BIDIRECTIONAL);
+	pci_dma_sync_single(hi->host->pdev, command->sge_dma,
+			    sizeof(command->scatter_gather_element),
+			    PCI_DMA_BIDIRECTIONAL);
+	/*
+	 * Check to see if there are any previous orbs to use
+	 */
+	if (scsi_id->last_orb == NULL) {
+	
+		/*
+		 * Ok, let's write to the target's management agent register
+		 */
+		if (hpsb_node_entry_valid(scsi_id->ne)) {
+
+			packet = sbp2util_allocate_write_packet(hi, scsi_id->ne,
+								scsi_id->sbp2_command_block_agent_addr +
+								SBP2_ORB_POINTER_OFFSET, 8, NULL);
+		
+			if (!packet) {
+				SBP2_ERR("sbp2util_allocate_write_packet failed");
+				return(-ENOMEM);
+			}
+		
+			packet->data[0] = ORB_SET_NODE_ID(hi->host->node_id);
+			packet->data[1] = command->command_orb_dma;
+			sbp2util_cpu_to_be32_buffer(packet->data, 8);
+		
+			SBP2_ORB_DEBUG("write command agent, command orb %p", command_orb);
+
+			if (!hpsb_send_packet(packet)) {
+				SBP2_ERR("hpsb_send_packet failed");
+				sbp2_free_packet(packet); 
+				return(-EIO);
+			}
+
+			SBP2_ORB_DEBUG("write command agent complete");
+		}
+
+		scsi_id->last_orb = command_orb;
+		scsi_id->last_orb_dma = command->command_orb_dma;
+
+	} else {
+
+		/*
+		 * We have an orb already sent (maybe or maybe not
+		 * processed) that we can append this orb to. So do so,
+		 * and ring the doorbell. Have to be very careful
+		 * modifying these next orb pointers, as they are accessed
+		 * both by the sbp2 device and us.
+		 */
+		scsi_id->last_orb->next_ORB_lo =
+			cpu_to_be32(command->command_orb_dma);
+		/* Tells hardware that this pointer is valid */
+		scsi_id->last_orb->next_ORB_hi = 0x0;
+		pci_dma_sync_single(hi->host->pdev, scsi_id->last_orb_dma,
+				    sizeof(struct sbp2_command_orb),
+				    PCI_DMA_BIDIRECTIONAL);
+
+		/*
+		 * Ring the doorbell
+		 */
+		if (hpsb_node_entry_valid(scsi_id->ne)) {
+			quadlet_t data = cpu_to_be32(command->command_orb_dma);
+
+			packet = sbp2util_allocate_write_packet(hi, scsi_id->ne,
+					scsi_id->sbp2_command_block_agent_addr +
+					SBP2_DOORBELL_OFFSET, 4, &data);
+	
+			if (!packet) {
+				SBP2_ERR("sbp2util_allocate_write_packet failed");
+				return(-ENOMEM);
+			}
+
+			SBP2_ORB_DEBUG("ring doorbell, command orb %p", command_orb);
+
+			if (!hpsb_send_packet(packet)) {
+				SBP2_ERR("hpsb_send_packet failed");
+				sbp2_free_packet(packet);
+				return(-EIO);
+			}
+		}
+
+		scsi_id->last_orb = command_orb;
+		scsi_id->last_orb_dma = command->command_orb_dma;
+
+	}
+       	return(0);
+}
+
+/*
+ * This function is called in order to begin a regular SBP-2 command. 
+ */
+static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
+			     Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
+{
+	unchar *cmd = (unchar *) SCpnt->cmnd;
+	unsigned int request_bufflen = SCpnt->request_bufflen;
+	struct sbp2_command_info *command;
+
+	SBP2_DEBUG("sbp2_send_command");
+#if (CONFIG_IEEE1394_SBP2_DEBUG >= 2) || defined(CONFIG_IEEE1394_SBP2_PACKET_DUMP)
+	printk("[scsi command]\n   ");
+	print_command (cmd);
+#endif
+	SBP2_DEBUG("SCSI transfer size = %x", request_bufflen);
+	SBP2_DEBUG("SCSI s/g elements = %x", (unsigned int)SCpnt->use_sg);
+
+	/*
+	 * Allocate a command orb and s/g structure
+	 */
+	command = sbp2util_allocate_command_orb(scsi_id, SCpnt, done);
+	if (!command) {
+		return(-EIO);
+	}
+
+	/*
+	 * The scsi stack sends down a request_bufflen which does not match the
+	 * length field in the scsi cdb. This causes some sbp2 devices to 
+	 * reject this inquiry command. Fix the request_bufflen. 
+	 */
+	if (*cmd == INQUIRY) {
+		if (force_inquiry_hack || scsi_id->workarounds & SBP2_BREAKAGE_INQUIRY_HACK)
+			request_bufflen = cmd[4] = 0x24;
+		else
+			request_bufflen = cmd[4];
+	}
+
+	/*
+	 * Now actually fill in the comamnd orb and sbp2 s/g list
+	 */
+	sbp2_create_command_orb(scsi_id, command, cmd, SCpnt->use_sg,
+				request_bufflen, SCpnt->request_buffer,
+				SCpnt->sc_data_direction); 
+	/*
+	 * Update our cdb if necessary (to handle sbp2 RBC command set
+	 * differences). This is where the command set hacks go!   =)
+	 */
+	sbp2_check_sbp2_command(scsi_id, command->command_orb.cdb);
+
+	sbp2util_packet_dump(&command->command_orb, sizeof(struct sbp2_command_orb), 
+			     "sbp2 command orb", command->command_orb_dma);
+
+	/*
+	 * Initialize status fifo
+	 */
+	memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
+
+	/*
+	 * Link up the orb, and ring the doorbell if needed
+	 */
+	sbp2_link_orb_command(scsi_id, command);
+	
+	return(0);
+}
+
+
+/*
+ * This function deals with command set differences between Linux scsi
+ * command set and sbp2 RBC command set.
+ */
+static void sbp2_check_sbp2_command(struct scsi_id_instance_data *scsi_id, unchar *cmd)
+{
+	unchar new_cmd[16];
+	u8 device_type = SBP2_DEVICE_TYPE (scsi_id->sbp2_device_type_and_lun);
+
+	SBP2_DEBUG("sbp2_check_sbp2_command");
+
+	switch (*cmd) {
+		
+		case READ_6:
+
+			if (sbp2_command_conversion_device_type(device_type)) {
+
+				SBP2_DEBUG("Convert READ_6 to READ_10");
+					    
+				/*
+				 * Need to turn read_6 into read_10
+				 */
+				new_cmd[0] = 0x28;
+				new_cmd[1] = (cmd[1] & 0xe0);
+				new_cmd[2] = 0x0;
+				new_cmd[3] = (cmd[1] & 0x1f);
+				new_cmd[4] = cmd[2];
+				new_cmd[5] = cmd[3];
+				new_cmd[6] = 0x0;
+				new_cmd[7] = 0x0;
+				new_cmd[8] = cmd[4];
+				new_cmd[9] = cmd[5];
+	
+				memcpy(cmd, new_cmd, 10);
+
+			}
+
+			break;
+
+		case WRITE_6:
+
+			if (sbp2_command_conversion_device_type(device_type)) {
+
+				SBP2_DEBUG("Convert WRITE_6 to WRITE_10");
+	
+				/*
+				 * Need to turn write_6 into write_10
+				 */
+				new_cmd[0] = 0x2a;
+				new_cmd[1] = (cmd[1] & 0xe0);
+				new_cmd[2] = 0x0;
+				new_cmd[3] = (cmd[1] & 0x1f);
+				new_cmd[4] = cmd[2];
+				new_cmd[5] = cmd[3];
+				new_cmd[6] = 0x0;
+				new_cmd[7] = 0x0;
+				new_cmd[8] = cmd[4];
+				new_cmd[9] = cmd[5];
+	
+				memcpy(cmd, new_cmd, 10);
+
+			}
+
+			break;
+
+		case MODE_SENSE:
+
+			if (sbp2_command_conversion_device_type(device_type)) {
+
+				SBP2_DEBUG("Convert MODE_SENSE_6 to MODE_SENSE_10");
+
+				/*
+				 * Need to turn mode_sense_6 into mode_sense_10
+				 */
+				new_cmd[0] = 0x5a;
+				new_cmd[1] = cmd[1];
+				new_cmd[2] = cmd[2];
+				new_cmd[3] = 0x0;
+				new_cmd[4] = 0x0;
+				new_cmd[5] = 0x0;
+				new_cmd[6] = 0x0;
+				new_cmd[7] = 0x0;
+				new_cmd[8] = cmd[4];
+				new_cmd[9] = cmd[5];
+	
+				memcpy(cmd, new_cmd, 10);
+
+			}
+
+			break;
+
+		case MODE_SELECT:
+
+			/*
+			 * TODO. Probably need to change mode select to 10 byte version
+			 */
+
+		default:
+			break;
+	}
+
+	return;
+}
+
+/*
+ * Translates SBP-2 status into SCSI sense data for check conditions
+ */
+static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data)
+{
+	SBP2_DEBUG("sbp2_status_to_sense_data");
+
+	/*
+	 * Ok, it's pretty ugly...   ;-)
+	 */
+	sense_data[0] = 0x70;
+	sense_data[1] = 0x0;
+	sense_data[2] = sbp2_status[9];
+	sense_data[3] = sbp2_status[12];
+	sense_data[4] = sbp2_status[13];
+	sense_data[5] = sbp2_status[14];
+	sense_data[6] = sbp2_status[15];
+	sense_data[7] = 10;
+	sense_data[8] = sbp2_status[16];
+	sense_data[9] = sbp2_status[17];
+	sense_data[10] = sbp2_status[18];
+	sense_data[11] = sbp2_status[19];
+	sense_data[12] = sbp2_status[10];
+	sense_data[13] = sbp2_status[11];
+	sense_data[14] = sbp2_status[20];
+	sense_data[15] = sbp2_status[21];
+
+	return(sbp2_status[8] & 0x3f);	/* return scsi status */
+}
+
+/*
+ * This function is called after a command is completed, in order to do any necessary SBP-2
+ * response data translations for the SCSI stack
+ */
+static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id, 
+				     Scsi_Cmnd *SCpnt)
+{
+	u8 *scsi_buf = SCpnt->request_buffer;
+	u8 device_type = SBP2_DEVICE_TYPE (scsi_id->sbp2_device_type_and_lun);
+
+	SBP2_DEBUG("sbp2_check_sbp2_response");
+
+	switch (SCpnt->cmnd[0]) {
+		
+		case INQUIRY:
+
+			/*
+			 * If scsi_id->sbp2_device_type_and_lun is uninitialized, then fill 
+			 * this information in from the inquiry response data. Lun is set to zero.
+			 */
+			if (scsi_id->sbp2_device_type_and_lun == SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) {
+				SBP2_DEBUG("Creating sbp2_device_type_and_lun from scsi inquiry data");
+				scsi_id->sbp2_device_type_and_lun = (scsi_buf[0] & 0x1f) << 16;
+			}
+
+			/*
+			 * Make sure data length is ok. Minimum length is 36 bytes
+			 */
+			if (scsi_buf[4] == 0) {
+				scsi_buf[4] = 36 - 5;
+			}
+
+			/*
+			 * Check for Simple Direct Access Device and change it to TYPE_DISK
+			 */
+			if ((scsi_buf[0] & 0x1f) == TYPE_SDAD) {
+				SBP2_DEBUG("Changing TYPE_SDAD to TYPE_DISK");
+				scsi_buf[0] &= 0xe0;
+			}
+
+			/*
+			 * Fix ansi revision and response data format
+			 */
+			scsi_buf[2] |= 2;
+			scsi_buf[3] = (scsi_buf[3] & 0xf0) | 2;
+
+			break;
+
+		case MODE_SENSE:
+
+			if (sbp2_command_conversion_device_type(device_type)) {
+			
+				SBP2_DEBUG("Modify mode sense response (10 byte version)");
+
+				scsi_buf[0] = scsi_buf[1];	/* Mode data length */
+				scsi_buf[1] = scsi_buf[2];	/* Medium type */
+				scsi_buf[2] = scsi_buf[3];	/* Device specific parameter */
+				scsi_buf[3] = scsi_buf[7];	/* Block descriptor length */
+				memcpy(scsi_buf + 4, scsi_buf + 8, scsi_buf[0]);
+	
+			}
+
+			break;
+
+		case MODE_SELECT:
+
+			/*
+			 * TODO. Probably need to change mode select to 10 byte version
+			 */
+
+		default:
+			break;
+	}
+	return;
+}
+
+/*
+ * This function deals with status writes from the SBP-2 device
+ */
+static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid,
+				    quadlet_t *data, u64 addr, unsigned int length, u16 fl)
+{
+	struct sbp2scsi_host_info *hi = NULL;
+	struct scsi_id_instance_data *scsi_id = NULL;
+	u32 id;
+	unsigned long flags;
+	Scsi_Cmnd *SCpnt = NULL;
+	u32 scsi_status = SBP2_SCSI_STATUS_GOOD;
+	struct sbp2_command_info *command;
+
+	SBP2_DEBUG("sbp2_handle_status_write");
+
+	sbp2util_packet_dump(data, length, "sbp2 status write by device", (u32)addr);
+
+	if (!host) {
+		SBP2_ERR("host is NULL - this is bad!");
+		return(RCODE_ADDRESS_ERROR);
+	}
+
+	hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
+
+	if (!hi) {
+		SBP2_ERR("host info is NULL - this is bad!");
+		return(RCODE_ADDRESS_ERROR);
+	}
+
+	spin_lock_irqsave(&hi->sbp2_command_lock, flags);
+
+	/*
+	 * Find our scsi_id structure by looking at the status fifo address written to by
+	 * the sbp2 device.
+	 */
+	id = SBP2_STATUS_FIFO_OFFSET_TO_ENTRY((u32)(addr - SBP2_STATUS_FIFO_ADDRESS)); 
+	scsi_id = hi->scsi_id[id];
+
+	if (!scsi_id) {
+		SBP2_ERR("scsi_id is NULL - device is gone?");
+		spin_unlock_irqrestore(&hi->sbp2_command_lock, flags);
+		return(RCODE_ADDRESS_ERROR);
+	}
+
+	/*
+	 * Put response into scsi_id status fifo... 
+	 */
+	memcpy(&scsi_id->status_block, data, length);
+
+	/*
+	 * Byte swap first two quadlets (8 bytes) of status for processing
+	 */
+	sbp2util_be32_to_cpu_buffer(&scsi_id->status_block, 8);
+
+	/*
+	 * Handle command ORB status here if necessary. First, need to match status with command.
+	 */
+	command = sbp2util_find_command_for_orb(scsi_id, scsi_id->status_block.ORB_offset_lo);
+	if (command) {
+
+		SBP2_DEBUG("Found status for command ORB");
+		pci_dma_sync_single(hi->host->pdev, command->command_orb_dma,
+				    sizeof(struct sbp2_command_orb),
+				    PCI_DMA_BIDIRECTIONAL);
+		pci_dma_sync_single(hi->host->pdev, command->sge_dma,
+				    sizeof(command->scatter_gather_element),
+				    PCI_DMA_BIDIRECTIONAL);
+
+		SBP2_ORB_DEBUG("matched command orb %p", &command->command_orb);
+		outstanding_orb_decr;
+
+		/*
+		 * Matched status with command, now grab scsi command pointers and check status
+		 */
+		SCpnt = command->Current_SCpnt;
+		sbp2util_mark_command_completed(scsi_id, command);
+
+		if (SCpnt) {
+
+			/*
+			 * See if the target stored any scsi status information
+			 */
+			if (STATUS_GET_LENGTH(scsi_id->status_block.ORB_offset_hi_misc) > 1) {
+				/*
+				 * Translate SBP-2 status to SCSI sense data
+				 */
+				SBP2_DEBUG("CHECK CONDITION");
+				scsi_status = sbp2_status_to_sense_data((unchar *)&scsi_id->status_block, SCpnt->sense_buffer);
+			}
+
+			/*
+			 * Check to see if the dead bit is set. If so, we'll have to initiate
+			 * a fetch agent reset.
+			 */
+			if (STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc)) {
+
+				/*
+				 * Initiate a fetch agent reset. 
+				 */
+				SBP2_DEBUG("Dead bit set - initiating fetch agent reset");
+                                sbp2_agent_reset(scsi_id, 0);
+			}
+
+			SBP2_ORB_DEBUG("completing command orb %p", &command->command_orb);
+		}
+
+		/*
+		 * Check here to see if there are no commands in-use. If there are none, we can
+		 * null out last orb so that next time around we write directly to the orb pointer... 
+		 * Quick start saves one 1394 bus transaction.
+		 */
+		if (list_empty(&scsi_id->sbp2_command_orb_inuse)) {
+			scsi_id->last_orb = NULL;
+		}
+
+	} else {
+		
+		/* 
+		 * It's probably a login/logout/reconnect status.
+		 */
+		if ((scsi_id->login_orb_dma == scsi_id->status_block.ORB_offset_lo) ||
+		    (scsi_id->query_logins_orb_dma == scsi_id->status_block.ORB_offset_lo) ||
+		    (scsi_id->reconnect_orb_dma == scsi_id->status_block.ORB_offset_lo) ||
+		    (scsi_id->logout_orb_dma == scsi_id->status_block.ORB_offset_lo)) {
+			atomic_set(&scsi_id->sbp2_login_complete, 1);
+		}
+	}
+
+	spin_unlock_irqrestore(&hi->sbp2_command_lock, flags);
+
+
+	if (SCpnt) {
+
+		/*
+		 * Complete the SCSI command.
+		 *
+		 * Only do it after we've released the sbp2_command_lock,
+		 * as it might otherwise deadlock with the 
+		 * io_request_lock (in sbp2scsi_queuecommand).
+		 */
+		SBP2_DEBUG("Completing SCSI command");
+		sbp2scsi_complete_command(scsi_id, scsi_status, SCpnt,
+					  command->Current_done);
+		SBP2_ORB_DEBUG("command orb completed");
+	}
+
+	return(RCODE_COMPLETE);
+}
+
+
+/**************************************
+ * SCSI interface related section
+ **************************************/
+
+/*
+ * This routine is the main request entry routine for doing I/O. It is 
+ * called from the scsi stack directly.
+ */
+static int sbp2scsi_queuecommand (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) 
+{
+	struct sbp2scsi_host_info *hi = NULL;
+	struct scsi_id_instance_data *scsi_id = NULL;
+	unsigned long flags;
+
+	SBP2_DEBUG("sbp2scsi_queuecommand");
+
+	/*
+	 * Pull our host info and scsi id instance data from the scsi command
+	 */
+	hi = hpsb_get_hostinfo_bykey(&sbp2_highlevel, (unsigned long)SCpnt->device->host);
+
+	if (!hi) {
+		SBP2_ERR("sbp2scsi_host_info is NULL - this is bad!");
+		SCpnt->result = DID_NO_CONNECT << 16;
+		done (SCpnt);
+		return(0);
+	}
+
+	scsi_id = hi->scsi_id[SCpnt->device->id];
+
+	/*
+	 * If scsi_id is null, it means there is no device in this slot,
+	 * so we should return selection timeout.
+	 */
+	if (!scsi_id) {
+		SCpnt->result = DID_NO_CONNECT << 16;
+		done (SCpnt);
+		return(0);
+	}
+
+	/*
+	 * Until we handle multiple luns, just return selection time-out
+	 * to any IO directed at non-zero LUNs
+	 */
+	if (SCpnt->device->lun) {
+		SCpnt->result = DID_NO_CONNECT << 16;
+		done (SCpnt);
+		return(0);
+	}
+
+	/*
+	 * Check for request sense command, and handle it here
+	 * (autorequest sense)
+	 */
+	if (SCpnt->cmnd[0] == REQUEST_SENSE) {
+		SBP2_DEBUG("REQUEST_SENSE");
+		memcpy(SCpnt->request_buffer, SCpnt->sense_buffer, SCpnt->request_bufflen);
+		memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer));
+		sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_GOOD, SCpnt, done);
+		return(0);
+	}
+
+	/*
+	 * Check to see if we are in the middle of a bus reset.
+	 */
+	if (!hpsb_node_entry_valid(scsi_id->ne)) {
+		SBP2_ERR("Bus reset in progress - rejecting command");
+		SCpnt->result = DID_BUS_BUSY << 16;
+		done (SCpnt);
+		return(0);
+	}
+
+	/*
+	 * Try and send our SCSI command
+	 */
+	spin_lock_irqsave(&hi->sbp2_command_lock, flags);
+	if (sbp2_send_command(scsi_id, SCpnt, done)) {
+		SBP2_ERR("Error sending SCSI command");
+		sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_SELECTION_TIMEOUT,
+					  SCpnt, done);
+	}
+	spin_unlock_irqrestore(&hi->sbp2_command_lock, flags);
+
+	return(0);
+}
+
+/*
+ * This function is called in order to complete all outstanding SBP-2
+ * commands (in case of resets, etc.).
+ */
+static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id, 
+					   u32 status)
+{
+	struct sbp2scsi_host_info *hi = scsi_id->hi;
+	struct list_head *lh;
+	struct sbp2_command_info *command;
+
+	SBP2_DEBUG("sbp2_complete_all_commands");
+
+	while (!list_empty(&scsi_id->sbp2_command_orb_inuse)) {
+		SBP2_DEBUG("Found pending command to complete");
+		lh = scsi_id->sbp2_command_orb_inuse.next;
+		command = list_entry(lh, struct sbp2_command_info, list);
+		pci_dma_sync_single(hi->host->pdev, command->command_orb_dma,
+				    sizeof(struct sbp2_command_orb),
+				    PCI_DMA_BIDIRECTIONAL);
+		pci_dma_sync_single(hi->host->pdev, command->sge_dma,
+				    sizeof(command->scatter_gather_element),
+				    PCI_DMA_BIDIRECTIONAL);
+		sbp2util_mark_command_completed(scsi_id, command);
+		if (command->Current_SCpnt) {
+			void (*done)(Scsi_Cmnd *) = command->Current_done;
+			command->Current_SCpnt->result = status << 16;
+			done (command->Current_SCpnt);
+		}
+	}
+
+	return;
+}
+
+/*
+ * This function is called in order to complete a regular SBP-2 command.
+ *
+ * This can be called in interrupt context.
+ */
+static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
+				      u32 scsi_status, Scsi_Cmnd *SCpnt,
+				      void (*done)(Scsi_Cmnd *))
+{
+	unsigned long flags;
+
+	SBP2_DEBUG("sbp2scsi_complete_command");
+
+	/*
+	 * Sanity
+	 */
+	if (!SCpnt) {
+		SBP2_ERR("SCpnt is NULL");
+		return;
+	}
+
+	/*
+	 * If a bus reset is in progress and there was an error, don't
+	 * complete the command, just let it get retried at the end of the
+	 * bus reset.
+	 */
+	if (!hpsb_node_entry_valid(scsi_id->ne) && (scsi_status != SBP2_SCSI_STATUS_GOOD)) {
+		SBP2_ERR("Bus reset in progress - retry command later");
+		return;
+	}
+        
+	/*
+	 * Switch on scsi status
+	 */
+	switch (scsi_status) {
+		case SBP2_SCSI_STATUS_GOOD:
+			SCpnt->result = DID_OK;
+			break;
+
+		case SBP2_SCSI_STATUS_BUSY:
+			SBP2_ERR("SBP2_SCSI_STATUS_BUSY");
+			SCpnt->result = DID_BUS_BUSY << 16;
+			break;
+
+		case SBP2_SCSI_STATUS_CHECK_CONDITION:
+			SBP2_DEBUG("SBP2_SCSI_STATUS_CHECK_CONDITION");
+			SCpnt->result = CHECK_CONDITION << 1;
+
+			/*
+			 * Debug stuff
+			 */
+#if CONFIG_IEEE1394_SBP2_DEBUG >= 1
+			print_command (SCpnt->cmnd);
+			print_sense("bh", SCpnt);
+#endif
+
+			break;
+
+		case SBP2_SCSI_STATUS_SELECTION_TIMEOUT:
+			SBP2_ERR("SBP2_SCSI_STATUS_SELECTION_TIMEOUT");
+			SCpnt->result = DID_NO_CONNECT << 16;
+			print_command (SCpnt->cmnd);
+			break;
+
+		case SBP2_SCSI_STATUS_CONDITION_MET:
+		case SBP2_SCSI_STATUS_RESERVATION_CONFLICT:
+		case SBP2_SCSI_STATUS_COMMAND_TERMINATED:
+			SBP2_ERR("Bad SCSI status = %x", scsi_status);
+			SCpnt->result = DID_ERROR << 16;
+			print_command (SCpnt->cmnd);
+			break;
+
+		default:
+			SBP2_ERR("Unsupported SCSI status = %x", scsi_status);
+			SCpnt->result = DID_ERROR << 16;
+	}
+
+	/*
+	 * Take care of any sbp2 response data mucking here (RBC stuff, etc.)
+	 */
+	if (SCpnt->result == DID_OK) {
+		sbp2_check_sbp2_response(scsi_id, SCpnt);
+	}
+
+	/*
+	 * If a bus reset is in progress and there was an error, complete
+	 * the command as busy so that it will get retried.
+	 */
+	if (!hpsb_node_entry_valid(scsi_id->ne) && (scsi_status != SBP2_SCSI_STATUS_GOOD)) {
+		SBP2_ERR("Completing command with busy (bus reset)");
+		SCpnt->result = DID_BUS_BUSY << 16;
+	}
+
+	/*
+	 * If a unit attention occurs, return busy status so it gets
+	 * retried... it could have happened because of a 1394 bus reset
+	 * or hot-plug...
+	 */
+#if 0
+	if ((scsi_status == SBP2_SCSI_STATUS_CHECK_CONDITION) && 
+	    (SCpnt->sense_buffer[2] == UNIT_ATTENTION)) {
+		SBP2_DEBUG("UNIT ATTENTION - return busy");
+		SCpnt->result = DID_BUS_BUSY << 16;
+	}
+#endif
+
+	/*
+	 * Tell scsi stack that we're done with this command
+	 */
+	spin_lock_irqsave(scsi_id->hi->scsi_host->host_lock,flags);
+	done (SCpnt);
+	spin_unlock_irqrestore(scsi_id->hi->scsi_host->host_lock,flags);
+
+	return;
+}
+
+/*
+ * Called by scsi stack when something has really gone wrong.  Usually
+ * called when a command has timed-out for some reason.
+ */
+static int sbp2scsi_abort (Scsi_Cmnd *SCpnt) 
+{
+	struct sbp2scsi_host_info *hi = hpsb_get_hostinfo_bykey(&sbp2_highlevel,
+								(unsigned long)SCpnt->device->host);
+	struct scsi_id_instance_data *scsi_id = hi->scsi_id[SCpnt->device->id];
+	struct sbp2_command_info *command;
+	unsigned long flags;
+
+	SBP2_ERR("aborting sbp2 command");
+	print_command (SCpnt->cmnd);
+        
+	if (scsi_id) {
+
+		/*
+		 * Right now, just return any matching command structures
+		 * to the free pool.
+		 */
+		spin_lock_irqsave(&hi->sbp2_command_lock, flags);
+		command = sbp2util_find_command_for_SCpnt(scsi_id, SCpnt);
+		if (command) {
+			SBP2_DEBUG("Found command to abort");
+			pci_dma_sync_single(hi->host->pdev,
+					    command->command_orb_dma,
+					    sizeof(struct sbp2_command_orb),
+					    PCI_DMA_BIDIRECTIONAL);
+			pci_dma_sync_single(hi->host->pdev,
+					    command->sge_dma,
+					    sizeof(command->scatter_gather_element),
+					    PCI_DMA_BIDIRECTIONAL);
+			sbp2util_mark_command_completed(scsi_id, command);
+			if (command->Current_SCpnt) {
+				void (*done)(Scsi_Cmnd *) = command->Current_done;
+				command->Current_SCpnt->result = DID_ABORT << 16;
+				done (command->Current_SCpnt);
+			}
+		}
+
+		/*
+		 * Initiate a fetch agent reset. 
+		 */
+		sbp2_agent_reset(scsi_id, 0);
+		sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY);		
+		spin_unlock_irqrestore(&hi->sbp2_command_lock, flags);
+	}
+
+	return(SUCCESS);
+}
+
+/*
+ * Called by scsi stack when something has really gone wrong.
+ */
+static int sbp2scsi_reset (Scsi_Cmnd *SCpnt) 
+{
+	struct sbp2scsi_host_info *hi = hpsb_get_hostinfo_bykey(&sbp2_highlevel,
+								(unsigned long)SCpnt->device->host);
+	struct scsi_id_instance_data *scsi_id = hi->scsi_id[SCpnt->device->id];
+
+	SBP2_ERR("reset requested");
+
+	if (scsi_id) {
+		SBP2_ERR("Generating sbp2 fetch agent reset");
+		sbp2_agent_reset(scsi_id, 0);
+	}
+
+	return(SUCCESS);
+}
+
+static const char *sbp2scsi_info (struct Scsi_Host *host)
+{
+        return "SCSI emulation for IEEE-1394 SBP-2 Devices";
+}
+
+/* Called for contents of procfs */
+#define SPRINTF(args...) \
+        do { if (pos < buffer+length) pos += sprintf(pos, ## args); } while (0)
+
+static int sbp2scsi_proc_info(struct Scsi_Host *scsi_host, char *buffer, char **start, off_t offset,
+			      int length, int inout)
+{
+	Scsi_Device *scd;
+	struct hpsb_host *host;
+	char *pos = buffer;
+
+	/* if someone is sending us data, just throw it away */
+	if (inout)
+		return length;
+
+	host = hpsb_get_host_bykey(&sbp2_highlevel, (unsigned long)scsi_host);
+	if (!host) /* shouldn't happen, but... */
+		return -ESRCH;
+
+	SPRINTF("Host scsi%d             : SBP-2 IEEE-1394 (%s)\n",
+		scsi_host->host_no, host->driver->name);
+	SPRINTF("Driver version         : %s\n", version);
+
+	SPRINTF("\nModule options         :\n");
+	SPRINTF("  max_speed            : %s\n", hpsb_speedto_str[max_speed]);
+	SPRINTF("  max_sectors          : %d\n", max_sectors);
+	SPRINTF("  serialize_io         : %s\n", serialize_io ? "yes" : "no");
+	SPRINTF("  exclusive_login      : %s\n", exclusive_login ? "yes" : "no");
+
+	SPRINTF("\nAttached devices       : %s\n", !list_empty(&scsi_host->my_devices) ?
+		"" : "none");
+
+	list_for_each_entry (scd, &scsi_host->my_devices, siblings) {
+		int i;
+
+		SPRINTF("  [Channel: %02d, Id: %02d, Lun: %02d]  ", scd->channel,
+			scd->id, scd->lun);
+		SPRINTF("%s ", (scd->type < MAX_SCSI_DEVICE_CODE) ?
+			scsi_device_types[(short) scd->type] : "Unknown device");
+
+		for (i = 0; (i < 8) && (scd->vendor[i] >= 0x20); i++)
+			SPRINTF("%c", scd->vendor[i]);
+
+		SPRINTF(" ");
+
+		for (i = 0; (i < 16) && (scd->model[i] >= 0x20); i++)
+			SPRINTF("%c", scd->model[i]);
+
+		SPRINTF("\n");
+	}
+
+	SPRINTF("\n");
+
+	/* Calculate start of next buffer, and return value. */
+	*start = buffer + offset;
+
+	if ((pos - buffer) < offset)
+		return (0);
+	else if ((pos - buffer - offset) < length)
+		return (pos - buffer - offset);
+	else
+		return (length);
+}
+
+MODULE_AUTHOR("Ben Collins <bcollins at debian.org>");
+MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
+MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
+MODULE_LICENSE("GPL");
+
+/* SCSI host template */
+static Scsi_Host_Template scsi_driver_template = {
+	.module =			THIS_MODULE,
+	.name =				"SBP-2 IEEE-1394",
+	.proc_name =			SBP2_DEVICE_NAME,
+	.info =				sbp2scsi_info,
+	.proc_info =			sbp2scsi_proc_info,
+	.queuecommand =			sbp2scsi_queuecommand,
+	.eh_abort_handler =		sbp2scsi_abort,
+	.eh_device_reset_handler =	sbp2scsi_reset,
+	.eh_bus_reset_handler =		sbp2scsi_reset,
+	.eh_host_reset_handler =	sbp2scsi_reset,
+	.this_id =			-1,
+	.sg_tablesize =			SG_ALL,
+	.use_clustering =		ENABLE_CLUSTERING,
+	.cmd_per_lun =			SBP2_MAX_CMDS_PER_LUN,
+	.can_queue = 			SBP2_MAX_SCSI_QUEUE,
+	.emulated =			1,
+	.highmem_io =			1,
+};
+
+static int sbp2_module_init(void)
+{
+	SBP2_DEBUG("sbp2_module_init");
+
+	/* Module load debug option to force one command at a time (serializing I/O) */
+	if (serialize_io) {
+		SBP2_ERR("Driver forced to serialize I/O (serialize_io = 1)");
+		scsi_driver_template.can_queue = 1;
+		scsi_driver_template.cmd_per_lun = 1;
+	}
+
+	/* Set max sectors (module load option). Default is 255 sectors. */
+	scsi_driver_template.max_sectors = max_sectors;
+
+
+	/* Register our high level driver with 1394 stack */
+	hpsb_register_highlevel(&sbp2_highlevel);
+
+	/* Register our sbp2 status address space... */
+	hpsb_register_addrspace(&sbp2_highlevel, &sbp2_ops, SBP2_STATUS_FIFO_ADDRESS,
+				SBP2_STATUS_FIFO_ADDRESS + 
+				SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(SBP2SCSI_MAX_SCSI_IDS+1));
+
+	/* Handle data movement if physical dma is not enabled/supported
+	 * on host controller */
+#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
+	hpsb_register_addrspace(&sbp2_highlevel, &sbp2_physdma_ops, 0x0ULL, 0xfffffffcULL);
+#endif
+
+	hpsb_register_protocol(&sbp2_driver);
+
+	return 0;
+}
+
+static void __exit sbp2_module_exit(void)
+{
+	SBP2_DEBUG("sbp2_module_exit");
+
+	hpsb_unregister_protocol(&sbp2_driver);
+
+	hpsb_unregister_highlevel(&sbp2_highlevel);
+}
+
+module_init(sbp2_module_init);
+module_exit(sbp2_module_exit);

Added: trunk/libsbp2/sbp2raw.h
==============================================================================
--- trunk/libsbp2/sbp2raw.h	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/libsbp2/sbp2raw.h	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,195 @@
+#ifndef __SBP2RAW_H__
+#define __SBP2RAW_H__
+
+
+#include <glib.h>
+
+
+#define SBP2_ORB_DIRECTION_WRITE_TO_MEDIA       0x0
+#define SBP2_ORB_DIRECTION_READ_FROM_MEDIA      0x1
+#define SBP2_ORB_DIRECTION_NO_DATA_TRANSFER     0x2
+
+#define SBP2_ORB_SET_NULL_PTR(value)            ((value & 0x1) << 31)
+#define SBP2_ORB_SET_NOTIFY(value)              ((value & 0x1) << 31)
+#define SBP2_ORB_SET_RQ_FMT(value)              ((value & 0x3) << 29)
+#define SBP2_ORB_SET_NODE_ID(value)             ((value & 0xffff) << 16)
+#define SBP2_ORB_SET_DATA_SIZE(value)           (value & 0xffff)
+#define SBP2_ORB_SET_PAGE_SIZE(value)           ((value & 0x7) << 16)
+#define SBP2_ORB_SET_PAGE_TABLE_PRESENT(value)  ((value & 0x1) << 19)
+#define SBP2_ORB_SET_MAX_PAYLOAD(value)         ((value & 0xf) << 20)
+#define SBP2_ORB_SET_SPEED(value)               ((value & 0x7) << 24)
+#define SBP2_ORB_SET_DIRECTION(value)           ((value & 0x1) << 27)
+#define SBP2_ORB_SET_LUN(value)                 (value & 0xffff)
+#define SBP2_ORB_SET_FUNCTION(value)            ((value & 0xf) << 16)
+#define SBP2_ORB_SET_RECONNECT(value)           ((value & 0xf) << 20)
+#define SBP2_ORB_SET_EXCLUSIVE(value)           ((value & 0x1) << 28)
+#define SBP2_ORB_SET_LOGIN_RESP_LENGTH(value)   (value & 0xffff)
+#define SBP2_ORB_SET_PASSWD_LENGTH(value)       ((value & 0xffff) << 16)
+
+#define SBP2_ORB_SET_LOGIN_ID(value)                 (value & 0xffff)
+#define SBP2_ORB_SET_QUERY_LOGINS_RESP_LENGTH(value) (value & 0xffff)
+
+#define SBP2_RESPONSE_GET_LOGIN_ID(value)       (value & 0xffff)
+#define SBP2_RESPONSE_GET_LENGTH(value)         ((value >> 16) & 0xffff)
+#define SBP2_RESPONSE_GET_RECONNECT_HOLD(value) (value & 0xffff)
+#define SBP2_RESPONSE_GET_MAX_LOGINS(value)     (value & 0xffff)
+#define SBP2_RESPONSE_GET_ACTIVE_LOGINS(value)  ((SBP2_RESPONSE_GET_LENGTH(value) - 4) / 12)
+
+#define SBP2_LOGIN_REQUEST              0x0
+#define SBP2_QUERY_LOGINS_REQUEST       0x1
+#define SBP2_RECONNECT_REQUEST          0x3
+#define SBP2_SET_PASSWORD_REQUEST       0x4
+#define SBP2_LOGOUT_REQUEST             0x7
+#define SBP2_ABORT_TASK_REQUEST         0xb
+#define SBP2_ABORT_TASK_SET             0xc
+#define SBP2_LOGICAL_UNIT_RESET         0xe
+#define SBP2_TARGET_RESET_REQUEST       0xf
+
+#define SBP2_RESP_STATUS_REQUEST_COMPLETE       0x0
+#define SBP2_RESP_STATUS_TRANSPORT_FAILURE      0x1
+#define SBP2_RESP_STATUS_ILLEGAL_REQUEST        0x2
+#define SBP2_RESP_STATUS_VENDOR_DEPENDENT       0x3
+
+#define SBP2_STATUS_NO_ADDITIONAL_INFO          0x0
+#define SBP2_STATUS_REQ_TYPE_NOT_SUPPORTED      0x1
+#define SBP2_STATUS_SPEED_NOT_SUPPORTED         0x2
+#define SBP2_STATUS_PAGE_SIZE_NOT_SUPPORTED     0x3
+#define SBP2_STATUS_ACCESS_DENIED               0x4
+#define SBP2_STATUS_LU_NOT_SUPPORTED            0x5
+#define SBP2_STATUS_MAX_PAYLOAD_TOO_SMALL       0x6
+#define SBP2_STATUS_RESOURCES_UNAVAILABLE       0x8
+#define SBP2_STATUS_FUNCTION_REJECTED           0x9
+#define SBP2_STATUS_LOGIN_ID_NOT_RECOGNIZED     0xa
+#define SBP2_STATUS_DUMMY_ORB_COMPLETED         0xb
+#define SBP2_STATUS_REQUEST_ABORTED             0xc
+#define SBP2_STATUS_UNSPECIFIED_ERROR           0xff
+
+#define SBP2_SCSI_STATUS_GOOD                   0x0
+#define SBP2_SCSI_STATUS_CHECK_CONDITION        0x2
+#define SBP2_SCSI_STATUS_CONDITION_MET          0x4
+#define SBP2_SCSI_STATUS_BUSY                   0x8
+#define SBP2_SCSI_STATUS_RESERVATION_CONFLICT   0x18
+#define SBP2_SCSI_STATUS_COMMAND_TERMINATED     0x22
+#define SBP2_SCSI_STATUS_SELECTION_TIMEOUT      0xff
+
+#define SBP2_STATUS_GET_ORB_OFFSET_HI(value)    (value & 0xffff)
+#define SBP2_STATUS_GET_SBP_STATUS(value)       ((value >> 16) & 0xff)
+#define SBP2_STATUS_GET_LENGTH(value)           ((value >> 24) & 0x7)
+#define SBP2_STATUS_GET_DEAD_BIT(value)         ((value >> 27) & 0x1)
+#define SBP2_STATUS_GET_RESP(value)             ((value >> 28) & 0x3)
+#define SBP2_STATUS_GET_SRC(value)              ((value >> 30) & 0x3)
+
+
+typedef struct _SBP2CommandORB SBP2CommandORB;
+
+struct _SBP2CommandORB
+{
+  guint32 next_ORB_hi;
+  guint32 next_ORB_lo;
+  guint32 data_descriptor_hi;
+  guint32 data_descriptor_lo;
+  guint32 misc;
+  guint8  cdb[12];
+};
+
+typedef struct _SBP2ManagementORB SBP2ManagementORB;
+
+struct _SBP2ManagementORB
+{
+  guint32 reserved1;
+  guint32 reserved2;
+  guint32 reserved3;
+  guint32 reserved4;
+  guint32 misc;
+  guint32 reserved5;
+  guint32 status_FIFO_hi;
+  guint32 status_FIFO_lo;
+};
+
+typedef struct _SBP2LoginORB SBP2LoginORB;
+
+struct _SBP2LoginORB
+{
+  guint32 password_hi;
+  guint32 password_lo;
+  guint32 login_response_hi;
+  guint32 login_response_lo;
+  guint32 lun_misc;
+  guint32 passwd_resp_lengths;
+  guint32 status_FIFO_hi;
+  guint32 status_FIFO_lo;
+};
+
+typedef struct _SBP2LoginResponse SBP2LoginResponse;
+
+struct _SBP2LoginResponse
+{
+  guint32 length_login_ID;
+  guint32 command_block_agent_hi;
+  guint32 command_block_agent_lo;
+  guint32 reconnect_hold;
+};
+
+typedef struct _SBP2QueryLoginsORB SBP2QueryLoginsORB;
+
+struct _SBP2QueryLoginsORB
+{
+  guint32 reserved1;
+  guint32 reserved2;
+  guint32 query_response_hi;
+  guint32 query_response_lo;
+  guint32 lun_misc;
+  guint32 reserved_resp_length;
+  guint32 status_FIFO_hi;
+  guint32 status_FIFO_lo;
+};
+
+typedef struct _SBP2QueryLoginsResponse SBP2QueryLoginsResponse;
+                                                                                
+struct _SBP2QueryLoginsResponse
+{
+  guint32 length_max_logins;
+  guint32 misc_IDs;
+  guint32 initiator_misc_hi;
+  guint32 initiator_misc_lo;
+};
+
+typedef struct _SBP2ReconnectORB SBP2ReconnectORB;
+
+struct _SBP2ReconnectORB
+{
+  guint32 reserved1;
+  guint32 reserved2;
+  guint32 reserved3;
+  guint32 reserved4;
+  guint32 login_ID_misc;
+  guint32 reserved5;
+  guint32 status_FIFO_hi;
+  guint32 status_FIFO_lo;
+};
+
+typedef struct _SBP2LogoutORB SBP2LogoutORB;
+
+struct _SBP2LogoutORB
+{
+  guint32 reserved1;
+  guint32 reserved2;
+  guint32 reserved3;
+  guint32 reserved4;
+  guint32 login_ID_misc;
+  guint32 reserved5;
+  guint32 status_FIFO_hi;
+  guint32 status_FIFO_lo;
+};
+
+typedef struct _SBP2StatusBlock SBP2StatusBlock;
+
+struct _SBP2StatusBlock
+{
+  guint32 ORB_offset_hi_misc;
+  guint32 ORB_offset_lo;
+  guint8  command_set_dependent[24];
+};
+
+
+#endif /* __SBP2RAW_H__ */

Added: trunk/libscsidisk/Makefile
==============================================================================
--- trunk/libscsidisk/Makefile	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/libscsidisk/Makefile	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,14 @@
+TOPDIR = ..
+
+include $(TOPDIR)/Preamble.make
+
+LIBRARIES = libscsidisk.a
+
+CFLAGS = -Wall -g -O2 -pipe `glib-config --cflags`
+
+libscsidisk.a: libscsidisk.o process.o partitions.o
+	rm -f $@
+	$(AR) r $@ $^
+	$(RANLIB) $@
+
+include $(TOPDIR)/Postamble.make

Added: trunk/libscsidisk/commands.h
==============================================================================
--- trunk/libscsidisk/commands.h	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/libscsidisk/commands.h	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,10 @@
+#define SCSI_CMD_INQUIRY                0x12
+#define SCSI_CMD_MODE_SELECT            0x15
+#define SCSI_CMD_MODE_SENSE             0x1a
+#define SCSI_CMD_READ                   0x28
+#define SCSI_CMD_READ_CAPACITY          0x25
+#define SCSI_CMD_START_STOP_UNIT        0x1b
+#define SCSI_CMD_TEST_UNIT_READY        0x00
+#define SCSI_CMD_VERIFY                 0x2f
+#define SCSI_CMD_WRITE                  0x2a
+#define SCSI_CMD_WRITE_BUFFER           0x3b

Added: trunk/libscsidisk/libscsidisk.c
==============================================================================
--- trunk/libscsidisk/libscsidisk.c	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/libscsidisk/libscsidisk.c	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,393 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include "libscsidisk.h"
+
+
+#define SECTOR_SIZE 512
+
+#define VENDOR_ID   "Linux   "
+#define PRODUCT_ID  "Endpoint        "
+#define PRODUCT_REV "0001"
+
+
+typedef struct _Partition Partition;
+
+struct _Partition
+{
+  gchar   *filename;
+  gint     fd;
+  gssize   size;
+};
+
+struct _ScsiDisk
+{
+  Partition *partitions[16];
+
+  gssize     size;
+};
+
+
+typedef gboolean CommandHandler (ScsiDisk      *disk,
+                                 ScsiDirection  direction,
+                                 guint          cmdlen,
+                                 gchar         *cmd,
+                                 guint          datalen,
+                                 gchar         *data);
+
+
+static gboolean process_inquiry         (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+static gboolean process_mode_select     (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd
+                                         ,guint          datalen
+                                         gchar         *data);
+static gboolean process_mode_sense      (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+static gboolean process_read            (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+static gboolean process_read_capacity   (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+static gboolean process_start_stop_unit (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+static gboolean process_test_unit_ready (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+static gboolean process_verify          (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+static gboolean process_write           (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+static gboolean process_write_buffer    (ScsiDisk      *disk,
+                                         ScsiDirection  direction,
+                                         guint          cmdlen,
+                                         gchar         *cmd,
+                                         guint          datalen,
+                                         gchar         *data);
+
+
+ScsiDisk *
+scsi_disk_create (void)
+{
+  ScsiDisk *disk;
+
+  disk = g_new0 (ScsiDisk, 1);
+
+  return disk;
+}
+
+gboolean
+scsi_register_partition (ScsiDisk *disk,
+                         gchar    *filename,
+                         gint      num);
+{
+  gint       fd;
+  Partition *part;
+  gulong     blocks;
+
+  if (num < 2 || num > 15)
+    return FALSE;
+
+  fd = open (filename, O_RDWR);
+
+  if (fd == -1)
+    {
+      return FALSE;
+    }
+
+  if (ioctl (fd, BLKGETSIZE, &blocks) < 0)
+    return FALSE;
+
+  part = g_new (Partition, 1);
+
+  part->filename = g_strdup (filename);
+  part->fd = fd;
+  part->size = blocks;
+
+  disk->partitions[num] = part;
+  disk->size = calc_disk_size (disk);
+
+  return TRUE;
+}
+
+gboolean
+scsi_command (ScsiDisk      *disk,
+              ScsiDirection  direction,
+              guint          cmdlen,
+              gchar         *cmd,
+              guint          datalen,
+              gchar         *data)
+{
+  CommandHandler handler;
+
+  switch (cmd[0])
+    {
+    case SCSI_CMD_INQUIRY:
+      handler = process_inquiry;
+      break;
+
+    case SCSI_CMD_MODE_SELECT:
+      handler = process_mode_select;
+      break;
+
+    case SCSI_CMD_MODE_SENSE:
+      handler = process_mode_sense;
+      break;
+
+    case SCSI_CMD_READ:
+      handler = process_read;
+      break;
+
+    case SCSI_CMD_READ_CAPACITY:
+      handler = process_read_capacity;
+      break;
+
+    case SCSI_CMD_START_STOP_UNIT:
+      handler = process_start_stop_unit;
+      break;
+
+    case SCSI_CMD_TEST_UNIT_READY:
+      handler = process_test_unit_ready;
+      break;
+   
+    case SCSI_CMD_VERIFY:
+      handler = scsi_cmd_verify; 
+      break;
+
+    case SCSI_CMD_WRITE:
+      handler = scsi_cmd_write;
+      break;
+
+    case SCSI_CMD_WRITE_BUFFER:
+      handler = scsi_cmd_write_buffer;
+      break;
+
+    default:
+      return FALSE;
+      break;
+    }
+
+  return handler (disk, direction, cmdlen, cmd, datalen, data);
+}
+
+gboolean
+process_inquiry (ScsiDisk      *disk,
+                 ScsiDirection  direction,
+                 guint          cmdlen,
+                 gchar         *cmd,
+                 guint          datalen,
+                 gchar         *data)
+{
+  memset (data, 0, datalen);
+
+  data[0] = 0xe;
+ 
+  if (cmd[1] & 0x01)
+    {
+      /* TODO: Implement */
+      return FALSE;
+    }
+  else if (cmd[1] & 0x02)
+    {
+      /* Unsupported, fail */
+      return FALSE;
+    }
+
+  data[1] = 0;
+  data[2] = 6;
+  data[4] = 53;
+  data[7] = 0x3a;
+
+  memcpy (&data[8], VENDOR_ID, 8);
+  memcpy (&data[16], PRODUCT_ID, 16);
+  memcpy (&data[32], PRODUCT_REV, 4);
+
+  return FALSE;
+}
+
+gboolean
+process_mode_select (ScsiDisk      *disk,
+                     ScsiDirection  direction,
+                     guint          cmdlen,
+                     gchar         *cmd,
+                     guint          datalen,
+                     gchar         *data)
+{
+  return FALSE;
+}
+
+gboolean
+process_mode_sense (ScsiDisk      *disk,
+                    ScsiDirection  direction,
+                    guint          cmdlen,
+                    gchar         *cmd,
+                    guint          datalen,
+                    gchar         *data)
+{
+  return FALSE;
+}
+
+gboolean
+process_read (ScsiDisk      *disk,
+              ScsiDirection  direction,
+              guint          cmdlen,
+              gchar         *cmd,
+              guint          datalen,
+              gchar         *data)
+{
+  gint block;
+  gint num;
+
+  g_return_val_if_fail (cmd[0] != SCSI_CMD_READ, FALSE);
+
+  block = cmd[5] + (cmd[4] << 8) + (cmd[3] << 16) + (cmd[2] << 24);
+  num = cmd[8] + (cmd[7] << 8);
+
+  if (block + num > disk->size)
+    return FALSE;
+
+  
+  return FALSE;
+}
+
+gboolean
+process_read_capacity (ScsiDisk      *disk,
+                       ScsiDirection  direction,
+                       guint          cmdlen,
+                       gchar         *cmd,
+                       guint          datalen,
+                       gchar         *data)
+{
+  gint capacity;
+
+  g_return_val_if_fail (cmd[0] != SCSI_CMD_READ_CAPACITY, FALSE);
+
+  memset (data, 0, datalen);
+
+  if (datalen > 7)
+    {
+      capacity = disk->capacity - 1;
+      data[0] = (capacity >> 24);
+      data[1] = (capacity >> 16) & 0xff;
+      data[2] = (capacity >> 8) & 0xff;
+      data[3] = capacity & 0xff;
+      data[6] = (SECTOR_SIZE >> 8) & 0xff;
+      data[7] = SECTOR_SIZE & 0xff;
+    }
+
+  return TRUE;
+}
+
+gboolean
+process_start_stop_unit (ScsiDisk      *disk,
+                         ScsiDirection  direction,
+                         guint          cmdlen,
+                         gchar         *cmd,
+                         guint          datalen,
+                         gchar         *data)
+{
+  g_return_val_if_fail (cmd[0] != SCSI_CMD_START_STOP_UNIT, FALSE);
+
+  /* Power condition requests are unsupported, ignore */
+  return TRUE;
+}
+
+gboolean
+process_test_unit_ready (ScsiDisk      *disk,
+                         ScsiDirection  direction,
+                         guint          cmdlen,
+                         gchar         *cmd,
+                         guint          datalen,
+                         gchar         *data)
+{
+  g_return_val_if_fail (cmd[0] != SCSI_CMD_TEST_UNIT_READY, FALSE);
+
+  /* We're always ready */
+  memset (data, 0, datalen);
+  return TRUE;
+}
+
+gboolean
+process_verify (ScsiDisk      *disk,
+                ScsiDirection  direction,
+                guint          cmdlen,
+                gchar         *cmd,
+                guint          datalen,
+                gchar         *data)
+{
+  return FALSE;
+}
+
+gboolean
+process_write (ScsiDisk      *disk,
+               ScsiDirection  direction,
+               guint          cmdlen,
+               gchar         *cmd,
+               guint          datalen,
+               gchar         *data)
+{
+  gint block;
+  gint num;
+
+  g_return_val_if_fail (cmd[0] != SCSI_CMD_WRITE, FALSE);
+
+  block = cmd[5] + (cmd[4] << 8) + (cmd[3] << 16) + (cmd[2] << 24);
+  num = cmd[8] + (cmd[7] << 8);
+
+  if (block + num > disk->size)
+    return FALSE;
+
+  return FALSE;
+}
+
+gboolean
+process_write_buffer (ScsiDisk      *disk,
+                      ScsiDirection  direction,
+                      guint          cmdlen,
+                      gchar         *cmd,
+                      guint          datalen,
+                      gchar         *data)
+{
+  g_return_val_if_fail (cmd[0] != SCSI_CMD_WRITE_BUFFER, FALSE);
+
+  /* Unsupported, always succeed */
+  return TRUE;
+}

Added: trunk/libscsidisk/libscsidisk.h
==============================================================================
--- trunk/libscsidisk/libscsidisk.h	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/libscsidisk/libscsidisk.h	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,34 @@
+#ifndef __LIBSCSIDISK_H__
+#define __LIBSCSIDISK_H__
+
+
+#include <glib.h>
+
+typedef enum
+{
+  SCSI_DIRECTION_UNKNOWN,
+  SCSI_DIRECTION_READ,
+  SCSI_DIRECTION_WRITE,
+  SCSI_DIRECTION_NONE
+} ScsiDirection;
+
+typedef struct _ScsiDisk ScsiDisk;
+
+
+ScsiDisk *scsi_disk_create        (void);
+
+void      scsi_disk_destroy       (ScsiDisk      *disk);
+
+gboolean  scsi_register_partition (ScsiDisk      *disk,
+                                   gchar         *filename,
+				   gint           num);
+
+gboolean  scsi_command            (ScsiDisk      *disk,
+                                   ScsiDirection  direction,
+				   guint          cmdlen,
+				   gchar         *cmd,
+				   guint          datalen,
+				   gchar         *data);
+
+
+#endif /* __LIBSCSITGT_H__ */

Added: trunk/mkinstalldirs
==============================================================================
--- trunk/mkinstalldirs	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/mkinstalldirs	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,111 @@
+#! /bin/sh
+# mkinstalldirs --- make directory hierarchy
+# Author: Noah Friedman <friedman at prep.ai.mit.edu>
+# Created: 1993-05-16
+# Public domain
+
+errstatus=0
+dirmode=""
+
+usage="\
+Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
+
+# process command line arguments
+while test $# -gt 0 ; do
+  case $1 in
+    -h | --help | --h*)         # -h for help
+      echo "$usage" 1>&2
+      exit 0
+      ;;
+    -m)                         # -m PERM arg
+      shift
+      test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
+      dirmode=$1
+      shift
+      ;;
+    --)                         # stop option processing
+      shift
+      break
+      ;;
+    -*)                         # unknown option
+      echo "$usage" 1>&2
+      exit 1
+      ;;
+    *)                          # first non-opt arg
+      break
+      ;;
+  esac
+done
+
+for file
+do
+  if test -d "$file"; then
+    shift
+  else
+    break
+  fi
+done
+
+case $# in
+  0) exit 0 ;;
+esac
+
+case $dirmode in
+  '')
+    if mkdir -p -- . 2>/dev/null; then
+      echo "mkdir -p -- $*"
+      exec mkdir -p -- "$@"
+    fi
+    ;;
+  *)
+    if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
+      echo "mkdir -m $dirmode -p -- $*"
+      exec mkdir -m "$dirmode" -p -- "$@"
+    fi
+    ;;
+esac
+
+for file
+do
+  set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+  shift
+
+  pathcomp=
+  for d
+  do
+    pathcomp="$pathcomp$d"
+    case $pathcomp in
+      -*) pathcomp=./$pathcomp ;;
+    esac
+
+    if test ! -d "$pathcomp"; then
+      echo "mkdir $pathcomp"
+
+      mkdir "$pathcomp" || lasterr=$?
+
+      if test ! -d "$pathcomp"; then
+  	errstatus=$lasterr
+      else
+  	if test ! -z "$dirmode"; then
+	  echo "chmod $dirmode $pathcomp"
+    	  lasterr=""
+  	  chmod "$dirmode" "$pathcomp" || lasterr=$?
+
+  	  if test ! -z "$lasterr"; then
+  	    errstatus=$lasterr
+  	  fi
+  	fi
+      fi
+    fi
+
+    pathcomp="$pathcomp/"
+  done
+done
+
+exit $errstatus
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# End:
+# mkinstalldirs ends here

Added: trunk/src/Makefile
==============================================================================
--- trunk/src/Makefile	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/src/Makefile	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,10 @@
+CFLAGS = -g -O0 -pipe -Wall `pkg-config --cflags glib-2.0` -DG_LOG_DOMAIN=\"Endpoint\"
+
+endpoint: main.o configrom.o raw1394util.o
+	gcc -g -O0 -pipe -Wall -o endpoint $^ `pkg-config --libs glib-2.0` -lraw1394
+
+endpoint_worker: worker.o raw1394util.o
+	gcc -g -O0 -pipe -Wall -o testit $^ `pkg-config --libs glib-2.0` -lraw1394
+
+clean:
+	rm -f *.o

Added: trunk/src/configrom.c
==============================================================================
--- trunk/src/configrom.c	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/src/configrom.c	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,88 @@
+#include <glib.h>
+
+#include <libraw1394/raw1394.h>
+
+#include "configrom.h"
+
+
+#define ROM_BUF_SIZE 256
+
+
+static guint16
+crc16 (guint32 *buf,
+       gint     length)
+{
+  gint    shift;
+  guint32 crc, sum, data;
+
+  crc = 0;
+
+  for (; length > 0; length--)
+    {
+      data = GUINT32_FROM_BE (*buf);
+
+      for (shift = 28; shift >= 0; shift -= 4)
+	{
+	  sum = ((crc >> 12) ^ (data >> shift)) & 0x000f;
+	  crc = (crc << 4) ^ (sum << 12) ^ (sum << 5) ^ sum;
+	}
+
+      crc &= 0xffff;
+
+      buf++;
+    }
+
+  return crc;
+}
+
+
+gboolean
+setup_config_rom (raw1394handle_t handle)
+{
+  quadlet_t rom[ROM_BUF_SIZE];
+  gsize     rom_size;
+  guchar    rom_version;
+  gint      ret, i;
+
+  ret = raw1394_get_config_rom (handle, rom, ROM_BUF_SIZE,
+                                &rom_size, &rom_version);
+
+  if (ret != 0)
+    return FALSE;
+
+  if (rom[5] == GUINT32_FROM_BE(0x0004980f))
+    return TRUE;
+
+  if (rom[5] != GUINT32_FROM_BE(0x00038480))
+    return FALSE;
+
+  for (i = 15; i > 8; i--)
+    rom[i + 1] = rom[i];
+
+  rom[7] = GUINT32_FROM_BE(0x81000003);
+  rom[9] = GUINT32_FROM_BE(0xd1000008);
+
+  rom[5] = GUINT32_FROM_BE(4 << 16 | crc16 (&rom[6], 4));
+
+  rom[18] = GUINT32_FROM_BE(0x1200609e);
+  rom[19] = GUINT32_FROM_BE(0x13010483);
+  rom[20] = GUINT32_FROM_BE(0x3800609e); /* IEEE/RAC */
+  rom[21] = GUINT32_FROM_BE(0x390104d8); /* IEEE/RAC */
+  rom[22] = GUINT32_FROM_BE(0x3b000000); /* IEEE/RAC */
+  rom[23] = GUINT32_FROM_BE(0x3c000001); /* IEEE/RAC */
+  rom[24] = GUINT32_FROM_BE(0x5400c000); /* management register */
+  rom[25] = GUINT32_FROM_BE(0x3a003c08); /* unit characteristics */
+  rom[26] = GUINT32_FROM_BE(0x3d000003); /* reconnect timeout */
+  rom[27] = GUINT32_FROM_BE(0x144e0000); /* logical unit number */
+
+  rom[17] = GUINT32_FROM_BE(10 << 16 | crc16 (&rom[18], 10));
+
+  rom_size += 12 * 4;
+
+  ret = raw1394_update_config_rom (handle, rom, rom_size, rom_version);
+
+  if (ret == -1)
+    return FALSE;
+
+  return TRUE;
+}

Added: trunk/src/configrom.h
==============================================================================
--- trunk/src/configrom.h	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/src/configrom.h	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,12 @@
+#ifndef __CONFIGROM_H__
+#define __CONFIGROM_H__
+
+
+#include <glib.h>
+
+#include <libraw1394/raw1394.h>
+
+gboolean setup_config_rom (raw1394handle_t handle);
+
+
+#endif /* __CONFIGROM_H__ */

Added: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/src/main.c	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,199 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <errno.h>
+
+#include <glib.h>
+
+#include <libraw1394/raw1394.h>
+#include <libraw1394/csr.h>
+
+#include "configrom.h"
+#include "raw1394util.h"
+
+
+#define CONFFILE "/usr/local/etc/endpoint.conf"
+
+#define MAXPORTS 8
+
+
+typedef struct _Port Port;
+                                                                                
+struct _Port
+{
+  raw1394handle_t              handle;
+  struct raw1394_arm_reqhandle management;
+
+  gint                         logins[4];
+};
+
+typedef struct _ORBTag ORBTag;
+
+struct _ORBTag
+{
+  Port      *port;
+  nodeid_t   nodeid;
+  quadlet_t  buffer[8];
+};
+
+
+static gboolean setup_port       (gint          num);
+static gboolean port_activity    (GIOChannel   *source,
+                                  GIOCondition  condition,
+				  gpointer      data);
+
+static gint     orb_tag_handler  (raw1394handle_t   handle,
+                                  gulong            tag,
+				  raw1394_errcode_t errcode);
+
+static gint     management_agent (raw1394handle_t              handle,
+                                  struct arm_request_response *arm_req_resp,
+				  guint                        requested_length,
+				  gpointer                     pcontext,
+				  guint8                       request_type);
+
+
+Port ports[MAXPORTS];
+
+
+int
+main (int   argc,
+      char *argv[])
+{
+  gchar           *conffile = CONFFILE;
+  gint             num_ports, i;
+  GMainLoop       *loop;
+
+  if (argc > 1)
+    conffile = argv[1];
+
+  for (i = 0; i < MAXPORTS; i++)
+    ports[i].handle = NULL;
+
+  num_ports = get_num_ports ();
+
+  if (num_ports == 0)
+    exit (1);
+
+  if (num_ports > MAXPORTS)
+    num_ports = MAXPORTS;
+
+  for (i = 0; i < num_ports; i++)
+    if (!setup_port (i))
+      exit (1);
+
+  loop = g_main_loop_new (NULL, TRUE);
+
+  g_main_loop_run (loop);
+
+  g_main_loop_unref (loop);
+
+  for (i = 0; i < MAXPORTS; i++)
+    if (ports[i].handle)
+      raw1394_destroy_handle (ports[i].handle);
+
+  return 0;
+}
+
+static gboolean
+setup_port (gint num)
+{
+  raw1394handle_t  handle;
+  gint             ret, fd;
+  GIOChannel      *channel;
+
+  handle = get_raw1394_handle ();
+
+  if (!handle)
+    return FALSE;
+
+  if (raw1394_set_port (handle, num) != 0)
+    {
+      raw1394_destroy_handle (handle);
+      return FALSE;
+    }
+
+  if (!setup_config_rom (handle))
+    {
+      raw1394_destroy_handle (handle);
+      return FALSE;
+    }
+
+  raw1394_set_tag_handler (handle, orb_tag_handler);
+
+  ports[num].management.arm_callback = management_agent;
+  ports[num].management.pcontext = &ports[num];
+
+  ret = raw1394_arm_register (handle, 0xfffff0030000UL, 8, NULL,
+			      (gulong) &ports[num].management,
+			      ARM_WRITE, ARM_WRITE, 0);
+
+  if (ret < 0)
+    {
+      raw1394_destroy_handle (handle);
+      return FALSE;
+    }
+
+  fd = raw1394_get_fd (handle);
+
+  channel = g_io_channel_unix_new (fd);
+  g_io_add_watch (channel, G_IO_IN | G_IO_PRI, port_activity, handle);
+  g_io_channel_unref (channel);
+
+  ports[num].handle = handle;
+
+  return TRUE;
+}
+
+static gboolean
+port_activity (GIOChannel   *source,
+               GIOCondition  condition,
+	       gpointer      data)
+{
+  raw1394handle_t handle = data;
+
+  raw1394_loop_iterate (handle);
+
+  return TRUE;
+}
+
+static gint
+management_agent (raw1394handle_t              handle,
+                  struct arm_request_response *arm_req_resp,
+		  guint                        requested_length,
+		  gpointer                     pcontext,
+		  guint8                       request_type)
+{
+  struct arm_request *request;
+  Port               *port = pcontext;
+  nodeaddr_t          orb_address;
+  ORBTag             *orb_tag;
+
+  request = arm_req_resp->request;
+
+  orb_address = (guint64) GUINT32_FROM_BE (request->buffer[1]) << 32;
+  orb_address |= GUINT32_FROM_BE (request->buffer[2]) << 16;
+  orb_address |= GUINT32_FROM_BE (request->buffer[3]);
+
+  orb_tag = g_new (ORBTag, 1);
+
+  orb_tag->port = port;
+  orb_tag->nodeid = request->source_nodeid;
+
+  raw1394_start_read (port->handle, orb_tag->nodeid, orb_address, 32,
+                      orb_tag->buffer, (gulong) orb_tag);
+
+  return 0;
+}
+
+static gint
+orb_tag_handler (raw1394handle_t   handle,
+                 gulong            tag,
+		 raw1394_errcode_t errcode)
+{
+  ORBTag *orb_tag = (gpointer) tag;
+
+  g_free (orb_tag);
+
+  return 0;
+}

Added: trunk/src/raw1394util.c
==============================================================================
--- trunk/src/raw1394util.c	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/src/raw1394util.c	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,59 @@
+#include <errno.h>
+
+#include <glib.h>
+
+#include <libraw1394/raw1394.h>
+
+#include "raw1394util.h"
+
+
+static const gchar *errmsg_not_compatible =
+"This libraw1394 does not work with your version of Linux. You need a "
+"different version that matches your kernel (see kernel help text for the "
+"raw1394 option to find out which is the correct version).";
+                                                                                
+static const gchar *errmsg_not_loaded =
+"This probably means that you don't have raw1394 support in the kernel or "
+"that you haven't loaded the raw1394 module.";
+
+
+struct raw1394_handle *
+get_raw1394_handle (void)
+{
+  raw1394handle_t handle;
+
+  handle = raw1394_new_handle ();
+
+  if (!handle)
+    {
+      if (!errno)
+	{
+	  g_critical (errmsg_not_compatible);
+	}
+      else
+	{
+	  g_critical ("Couldn't get handle");
+	  g_critical (errmsg_not_loaded);
+	}
+    }
+
+  return handle;
+}
+
+gint
+get_num_ports (void)
+{
+  raw1394handle_t handle;
+  gint            num_ports;
+
+  handle = get_raw1394_handle ();
+
+  if (!handle)
+    return 0;
+
+  num_ports = raw1394_get_port_info (handle, NULL, 0);
+
+  raw1394_destroy_handle (handle);
+
+  return num_ports;
+}

Added: trunk/src/raw1394util.h
==============================================================================
--- trunk/src/raw1394util.h	2003-07-04 09:02:25 UTC (rev 6)
+++ trunk/src/raw1394util.h	2003-07-04 09:15:09 UTC (rev 7)
@@ -0,0 +1,14 @@
+#ifndef __RAW1394UTIL_H__
+#define __RAW1394UTIL_H__
+
+
+#include <glib.h>
+
+#include <libraw1394/raw1394.h>
+
+struct raw1394_handle *get_raw1394_handle (void);
+
+gint                   get_num_ports      (void);
+
+
+#endif /* __RAW1394UTIL_H__ */



More information about the Endpoint-commits mailing list