diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/Documentation/Configure.help linux.13p4/Documentation/Configure.help
--- linux.vanilla/Documentation/Configure.help	Sat Aug 28 20:00:52 1999
+++ linux.13p4/Documentation/Configure.help	Fri Sep  3 14:15:06 1999
@@ -3843,6 +3843,15 @@
   kernel. The default value has been reduced to 5 seconds. If this
   doesn't work with your hardware, try increasing this value.
 
+IBM ServeRAID Support
+CONFIG_SCSI_IPS
+  This is support for the IBM ServeRAID hardware RAID controllers.
+  Consult the SCSI-HOWTO, available via anonymous FTP from
+  ftp://metalab.unc.edu/pub/Linux/docs/HOWTO, and the file
+  README.ips in drivers/scsi for more information.  If this driver
+  does not work correctly without modification please contact the
+  author by email at ipslinux@us.ibm.com.
+
 BusLogic SCSI support
 CONFIG_SCSI_BUSLOGIC
   This is support for BusLogic MultiMaster and FlashPoint SCSI Host
@@ -9008,11 +9017,12 @@
   your computer. For details, read Documentation/watchdog.txt in the
   kernel source.
 
-  The watchdog is usually used together with the watchdog daemon 
-  which is available via FTP (user: anonymous) from
-  ftp://tsx-11.mit.edu/pub/linux/sources/sbin/. This daemon can also
-  monitor NFS connections and can reboot the machine when the process
-  table is full.
+  The watchdog is usually used together with the watchdog daemon which is
+  available via FTP (user: anonymous) from
+  ftp://metalab.unc.edu/pub/linux/system/daemons/watchdog. This daemon can
+  check a larger part of the system. For instance it can monitor NFS
+  connections and reboot the machine when the process table is full or the
+  workload exceeds a predefined value.
 
   If unsure, say N.
 
@@ -9539,6 +9549,11 @@
   See also Documentation/sound/Opti and Documentation/sound/MAD16 for
   more information on setting these cards up as modules.
 
+VIA 82Cxxx audio support
+CONFIG_SOUND_VIA82CXXX
+  Answer Y if you have a VIA82C686 chip, typically found built
+  onto a motherboard.
+
 Full support for Turtle Beach WaveFront synth/sound cards
 CONFIG_SOUND_WAVEFRONT
   Answer Y or M if you have a Tropez Plus, Tropez or Maui sound card
@@ -11146,6 +11161,25 @@
 CONFIG_RADIO_GEMTEK_PORT
   Enter either 0x20c, 0x30c, 0x24c or 0x34c here. The card default is
   0x34c, if you haven't changed the jumper setting on the card.
+
+Trust FM Radio Card
+CONFIG_RADIO_TRUST
+  Choose Y here if you have this FM radio card, and then fill in the 
+  port address below.
+
+  In order to control your radio card, you will need to use programs
+  that are compatible with the Video for Linux API. Information on
+  this API and pointers to "v4l" programs may be found at
+  http://roadrunner.swansea.uk.linux.org/v4l.shtml.
+
+  If you want to compile this driver as a module ( = code which can be
+  inserted in and removed from the running kernel whenever you want),
+  say M here and read Documentation/modules.txt. The module will be
+  called radio-trust.o.
+
+Trust FM Radio I/O port
+CONFIG_RADIO_TRUST_PORT
+  Enter the I/O port of your card (usually 0x350 or 0x358).
 
 BT848 Video For Linux
 CONFIG_VIDEO_BT848
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/Documentation/networking/README.sb1000 linux.13p4/Documentation/networking/README.sb1000
--- linux.vanilla/Documentation/networking/README.sb1000	Sat Aug 14 02:27:12 1999
+++ linux.13p4/Documentation/networking/README.sb1000	Wed Sep  1 13:53:56 1999
@@ -1,133 +1,207 @@
-This is the new release of a module network device driver for General
-Instruments (also known as NextLevel) SB1000 cable modem board (also
-called internal SURFboard).
-I have tested and I am running this module on kernel 2.0.33.
-Steven N. Hirsch <shirsch@adelphia.net> gave me a diff patch
-(sb1000-1.1.2_127.patch to be applied with 'patch -p') that allows
-you to compile and run the driver with kernel versions 2.1.x.
-Thanks very much Steve!
-
-Here you'll the following files:
-
-- README
-- Makefile
-- sb1000.c      the actual device driver
-- cmconfig.c    an ifconfig-like program to correctly set the SB1000
-- cmping.c      a ping-like program to test your connection
-- ftptest.c     a small program to test your connection speed with FTP
-                (requires ftplib version >= 3.0)
-
-The directory ppp/ contains the files I am using to connect to MediaOne
-here in Jacksonville, to show how you can use the driver and the cmconfig
-program.
-
-Clemmitt Sigler wrote a very good and useful web page and installation
-script (for Adelphia PowerLink users but easy to port to other ISPs)
-about this SB1000 driver for Linux.
-You can find it here:
-     http://home.adelphia.net/~siglercm/sb1000.html
-Thanks very much Clemmitt!
-
-To install and run it:
-- cd sb1000-1.1.2
-- make
-- make install
-- configure the SB1000 card using the isapnp tools setting the correct
-  I/O's and IRQ. You can find more info about the isapnp tools at:
-     http://www.roestock.demon.co.uk/isapnptools/
-  (once you're happy with it, you may want to set the configuration
-   at boot time in one of the /etc/init.d/ scripts)
-  IMPORTANT NOTICE: after configuring isapnp, please look in the file
-  /etc/isapnp.conf for the line beginning with:
-     (READPORT
-  if it says: '(READPORT 0x0203)' (which should be the default), then
-  go to the next step. If instead it says something like:
-  '(READPORT 0x020b)' or '(READPORT 0x<another number>)', then please
-  follow the instructions at the end of this README file before going
-  to the next step.
-- install the PPP configuration files in the /etc/ppp directory; you
-  definitely have to change the file ppp@gi-on (the start up file),
-  setting the correct login name, the phone number for the PPP connection
-  and the frequency (k stands for kHz, M for MHz) for the cablemodem.
-  You'll also have to change the last line in the pap-secrets file
-  writing your login and password there (read the whole file for more
-  site specific configurations).
-  You may have to change the firewall file to suit your needs (IPs and
-  ports allowed to connect).
-- start the PPP connection with ppp@gi-on and see what happens; you may
-  want to set 'pppd' (the last command in the ppp@gi-on file) to debug
-  mode adding 'debug' at the end of the command ('pppd' prints its info in
-  the file /var/log/messages and/or /var/log/ppp.log). To make sure 'chat'
-  s not having problems you may want to add a '-v' (verbose) after the 'chat'
-  command in 'ppp-on-dialer' and check the results in /var/log/messages)
-- if everything is working fine you should see after a few seconds a message
-  likes this:
-            cm0: sb1000 at (0x120,0x310), csn 1, S/N 0x2a0d16d8, IRQ 9. 
-            sb1000.c:v1.1.2 6/01/98 (fventuri@mediaone.net) 
-  and ifconfig -a should show you two new interfaces: ppp0 and cm0.
-  Typing 'cmconfig cm0' will show you more info about the cablemodem interface.
-- please let me know if you see any other message coming from 'cm0' in
-  your '/var/log/messages' or '/var/log/debug' file, to help me debug the
-  code
-- also let me know if you have any problem; if everything works (hopefully),
-  let me know which speed you can reach downloading the 5Mb test file using
-  this driver.
-- if everything seems to work fine but your computer locks up after a while
-  (and typically during a lengthy download through the cablemodem), you may
-  need to add a short delay in the driver to 'slow down' the SURFboard
-  because your PC might not be able to keep up with the transfer rate of
-  the SB1000. To do this, edit the 'Makefile' and look for the 'SB1000_DELAY'
-  define: uncomment those 'CFLAGS' lines (and comment the default ones)
-  and try setting the delay to something like 60 microseconds with:
-  '-DSB1000_DELAY=60'; if it still doesn't work or you like playing with
-  the driver, you may try other numbers: remember though that the higher
-  the delay, the slower the driver (which slows down the rest of the PC
-  too when it is actively used). Thanks to Ed Daiga for this tip!
-
-This release has a few things fixed and a better handling of the frame errors.
-
-I also have slightly modified the 'cablemodem' script in the 'ppp' so
-you may interested in having a look at it: I basically have added filtering
-out broadcast messages (you shouldn't get them with a point-to-point
-interface and so far the ones I have received were from hosts trying to
-attack my system) and lower debug levels for the driver to avoid seeing
-the 'frame error' messages (so far noone has noticed any problem with the
-driver even with those messages).
-
-For questions, infos, etc, feel free to email me at:
-		fventuri@mediaone.net
-
-Good luck,
-Franco Venturi
-
-Thanks to Edge for his useful comments and to Steven N. Hirsch
-for his patch to run the driver with 2.1.x kernels.
-Thanks also to Ed Daiga for his help in finding that adding a delay
-in the driver fixes some lock up problems with some slow PCs.
-Many thanks to Clemmitt Sigler for his (much needed) web page about the
-SB1000 driver for Linux.
-An interesting URL for Linux + MediaOne (although with an external modem)
-is: http://rlz.ne.mediaone.net/linux/home.shtml
-Today, Sep 22 1998, I finished writing a short utility (ftptest.c) to
-'measure' your cablemodem speed connection in Linux, downloading to
-memory the same file several times. To compile it you need ftplib, version
-3 or above. To run it, type:
-  ftptest URL n
-where URL is in the form: ftp://ftp.site.local.isp/pub/testfile
-and n is the number of simultaneous FTP connections that you want to run
-
----------------------------------------------------------------------------
-IMPORTANT NOTICE: if in your file /etc/isapnp.conf, you found something
-like '(READPORT 0x020b)' or '(READPORT 0x<another number>)', (anything
-different from the default 0x0203), you have to change the READ_DATA_PORT
-parameter in the sb1000.c file as follows.
-  - edit the sb1000.c file, look for:
-       READ_DATA_PORT
-    (it should be around line 127 in version 1.1.2)
-  - change the value of READ_DATA_PORT to the same value found in
-    /etc/isapnp.conf; for instance, if you found a: '(READPORT 0x020b)',
-    then in sb1000.c you should have:
-          static const int READ_DATA_PORT = 0x20b; 
-  - save sb1000.c
-  - compile and install again the driver
-    (i.e. do a 'make' and a 'make install').
+sb1000 is a module network device driver for the General Instrument (also known
+as NextLevel) SURFboard1000 internal cable modem board.  This is an ISA card
+which is used by a number of cable TV companies to provide cable modem access.
+It's a one-way downstream-only cable modem, meaning that your upstream net link
+is provided by your regular phone modem.
+
+This driver was written by Franco Venturi <fventuri@mediaone.net>.  He deserves
+a great deal of thanks for this wonderful piece of code!
+
+-----------------------------------------------------------------------------
+
+Support for this device is now a part of the standard Linux kernel.  The
+driver source code file is drivers/net/sb1000.c.  In addition to this
+you will need:
+
+1.) The "cmconfig" program.  This is a utility which supplements "ifconfig"
+to configure the cable modem and network interface (usually called "cm0");
+and
+
+2.) Several PPP scripts which live in /etc/ppp to make connecting via your
+cable modem easy.
+
+   These utilities can be obtained from:
+
+      http://www.jacksonville.net/~fventuri/
+
+   in Franco's original source code distribution .tar.gz file.  Support for
+   the sb1000 driver can be found at:
+
+      http://home.adelphia.net/~siglercm/sb1000.html
+      http://linuxpower.cx/~cable/
+
+   along with these utilties.
+
+3.) The standard isapnp tools.  These are necessary to configure your SB1000
+card at boot time (or afterwards by hand) since it's a PnP card.
+
+   If you don't have these installed as a standard part of your Linux
+   distribution, you can find them at:
+
+      http://www.roestock.demon.co.uk/isapnptools/
+
+   or check your Linux distribution binary CD or their web site.  For help with
+   isapnp, pnpdump, or /etc/isapnp.conf, go to:
+
+      http://www.roestock.demon.co.uk/isapnptools/isapnpfaq.html
+
+-----------------------------------------------------------------------------
+
+To make the SB1000 card work, follow these steps:
+
+1.) Run `make config', or `make menuconfig', or `make xconfig', whichever
+you prefer, in the top kernel tree directory to set up your kernel
+configuration.  Make sure to say "Y" to "Prompt for development drivers"
+and to say "M" to the sb1000 driver.  Also say "Y" or "M" to all the standard
+networking questions to get TCP/IP and PPP networking support.
+
+2.) *BEFORE* you build the kernel, edit drivers/net/sb1000.c.  Make sure
+to redefine the value of READ_DATA_PORT to match the I/O address used
+by isapnp to access your PnP cards.  This is the value of READPORT in
+/etc/isapnp.conf or given by the output of pnpdump.
+
+3.) Build and install the kernel and modules as usual.
+
+4.) Boot your new kernel following the usual procedures.
+
+5.) Set up to configure the new SB1000 PnP card by capturing the output
+of "pnpdump" to a file and editing this file to set the correct I/O ports,
+IRQ, and DMA settings for all your PnP cards.  Make sure none of the settings
+conflict with one another.  Then test this configuration by running the
+"isapnp" command with your new config file as the input.  Check for
+errors and fix as necessary.  (As an aside, I use I/O ports 0x110 and
+0x310 and IRQ 11 for my SB1000 card and these work well for me.  YMMV.)
+Then save the finished config file as /etc/isapnp.conf for proper configuration
+on subsequent reboots.
+
+6.) Download the original file sb1000-1.1.2.tar.gz from Franco's site or one of
+the others referenced above.  As root, unpack it into a temporary directory and
+do a `make cmconfig' and then `install -c cmconfig /usr/local/sbin'.  Don't do
+`make install' because it expects to find all the utilities built and ready for
+installation, not just cmconfig.
+
+7.) As root, copy all the files under the ppp/ subdirectory in Franco's
+tar file into /etc/ppp, being careful not to overwrite any files that are
+already in there.  Then modify ppp@gi-on to set the correct login name,
+phone number, and frequency for the cable modem.  Also edit pap-secrets
+to specify your login name and password and any site-specific information
+you need.
+
+8.) Be sure to modify /etc/ppp/firewall to use ipchains instead of
+the older ipfwadm commands from the 2.0.x kernels.  There's a neat utility to
+convert ipfwadm commands to ipchains commands:
+
+   http://users.dhp.com/~whisper/ipfwadm2ipchains/
+
+You may also wish to modify the firewall script to implement a different
+firewalling scheme.
+
+9.) Start the PPP connection via the script /etc/ppp/ppp@gi-on.  You must be
+root to do this.  It's better to use a utility like sudo to execute
+frequently used commands like this with root permissions if possible.  If you
+connect successfully the cable modem interface will come up and you'll see a
+driver message like this at the console:
+
+         cm0: sb1000 at (0x110,0x310), csn 1, S/N 0x2a0d16d8, IRQ 11.
+         sb1000.c:v1.1.2 6/01/98 (fventuri@mediaone.net)
+
+The "ifconfig" command should show two new interfaces, ppp0 and cm0.
+The command "cmconfig cm0" will give you information about the cable modem
+interface.
+
+10.) Try pinging a site via `ping -c 5 www.yahoo.com', for example.  You should
+see packets received.
+
+11.) If you can't get site names (like www.yahoo.com) to resolve into
+IP addresses (like 204.71.200.67), be sure your /etc/resolv.conf file
+has no syntax errors and has the right nameserver IP addresses in it.
+If this doesn't help, try something like `ping -c 5 204.71.200.67' to
+see if the networking is running but the DNS resolution is where the
+problem lies.
+
+12.) If you still have problems, go to the support web sites mentioned above
+and read the information and documentation there.
+
+-----------------------------------------------------------------------------
+
+Common problems:
+
+1.) Packets go out on the ppp0 interface but don't come back on the cm0
+interface.  It looks like I'm connected but I can't even ping any
+numerical IP addresses.  (This happens predominantly on Debian systems due
+to a default boot-time configuration script.)
+
+Solution -- As root `echo 0 > /proc/sys/net/ipv4/conf/cm0/rp_filter' so it
+can share the same IP address as the ppp0 interface.  Note that this
+command should probably be added to the /etc/ppp/cablemodem script
+*right*between* the "/sbin/ifconfig" and "/sbin/cmconfig" commands.
+You may need to do this to /proc/sys/net/ipv4/conf/ppp0/rp_filter as well.
+If you do this to /proc/sys/net/ipv4/conf/default/rp_filter on each reboot
+(in rc.local or some such) then any interfaces can share the same IP
+addresses.
+
+2.) I get "unresolved symbol" error messages on executing `insmod sb1000.o'.
+
+Solution -- You probably have a non-matching kernel source tree and
+/usr/include/linux and /usr/include/asm header files.  Make sure you
+install the correct versions of the header files in these two directories.
+Then rebuild and reinstall the kernel.
+
+3.) When isapnp runs it reports an error, and my SB1000 card isn't working.
+
+Solution -- There's a problem with later versions of isapnp using the "(CHECK)"
+option in the lines that allocate the two I/O addresses for the SB1000 card.
+This first popped up on RH 6.0.  Delete "(CHECK)" for the SB1000 I/O addresses.
+Make sure they don't conflict with any other pieces of hardware first!  Then
+rerun isapnp and go from there.
+
+4.) I can't execute the /etc/ppp/ppp@gi-on file.
+
+Solution -- As root do `chmod ug+x /etc/ppp/ppp@gi-on'.
+
+5.) The firewall script isn't working (with 2.2.x and higher kernels).
+
+Solution -- Use the ipfwadm2ipchains script referenced above to convert the
+/etc/ppp/firewall script from the deprecated ipfwadm commands to ipchains.
+
+6.) I'm getting *tons* of firewall deny messages in the /var/kern.log,
+/var/messages, and/or /var/syslog files, and they're filling up my /var
+partition!!!
+
+Solution -- First, tell your ISP that you're receiving DoS (Denial of Service)
+and/or portscanning (UDP connection attempts) attacks!  Look over the deny
+messages to figure out what the attack is and where it's coming from.  Next,
+edit /etc/ppp/cablemodem and make sure the ",nobroadcast" option is turned on
+to the "cmconfig" command (uncomment that line).  If you're not receiving these
+denied packets on your broadcast interface (IP address xxx.yyy.zzz.255
+typically), then someone is attacking your machine in particular.  Be careful
+out there....
+
+7.) Everything seems to work fine but my computer locks up after a while
+(and typically during a lengthy download through the cable modem)!
+
+Solution -- You may need to add a short delay in the driver to 'slow down' the
+SURFboard because your PC might not be able to keep up with the transfer rate
+of the SB1000. To do this, it's probably best to download Franco's
+sb1000-1.1.2.tar.gz archive and build and install sb1000.o manually.  You'll
+want to edit the 'Makefile' and look for the 'SB1000_DELAY'
+define.  Uncomment those 'CFLAGS' lines (and comment out the default ones)
+and try setting the delay to something like 60 microseconds with:
+'-DSB1000_DELAY=60'.  Then do `make' and as root `make install' and try
+it out.  If it still doesn't work or you like playing with the driver, you may
+try other numbers.  Remember though that the higher the delay, the slower the
+driver (which slows down the rest of the PC too when it is actively
+used). Thanks to Ed Daiga for this tip!
+
+-----------------------------------------------------------------------------
+
+Credits:  This README came from Franco Venturi's original README file which is
+still supplied with his driver .tar.gz archive.  I and all other sb1000 users
+owe Franco a tremendous "Thank you!"  Additional thanks goes to Carl Patten
+and Ralph Bonnell who are now managing the Linux SB1000 web site, and to
+the SB1000 users who reported and helped debug the common problems listed
+above.
+
+
+					Clemmitt Sigler
+					csigler@vt.edu
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/Documentation/sound/CMI8338 linux.13p4/Documentation/sound/CMI8338
--- linux.vanilla/Documentation/sound/CMI8338	Thu Jan  1 01:00:00 1970
+++ linux.13p4/Documentation/sound/CMI8338	Sat May  8 03:32:53 1999
@@ -0,0 +1,24 @@
+Audio driver for CM8338/CM8738 chips by Chen-Li Tien
+
+Steps to build cmpci driver
+
+1. Backup the Config.in and Makefile in the sound driver directory
+	(/usr/src/linux/driver/sound).
+
+2. Extract the tar file by tar xvzf source.tar.gz in the above directory.
+
+3. Change directory to /usr/src/linux
+
+4. Config cm8338 driver by 'make menuconfig' or 'make config' command.
+
+5. Please select Sound Card (CONFIG_SOUND=m) support and CMPCI driver (CONFIG_SOUND_CMPCI=m) as modules. Resident mode not tested.
+
+6. Compile the kernel if necessary.
+
+7. Compile the modules by 'make modules'.
+
+8. Install the modules by 'make modules_install'
+
+9. Before first time to run the driver, create module dependency by 'depmod -a'
+
+10. To install the driver, enter 'modprobe cmpci'.
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/MAINTAINERS linux.13p4/MAINTAINERS
--- linux.vanilla/MAINTAINERS	Sat Aug 28 20:00:53 1999
+++ linux.13p4/MAINTAINERS	Fri Sep  3 14:15:06 1999
@@ -388,6 +388,12 @@
 W:	http://www.uni-mainz.de/~langm000/linux.html
 S:	Maintained
 
+IBM ServeRAID RAID DRIVER
+P:      Keith Mitchell
+M:      ipslinux@us.ibm.com
+W:      http://www.developer.ibm.com/welcome/netfinity/serveraid_beta.html
+S:      Supported 
+
 IDE DRIVER [GENERAL]
 P:	Andre Hedrick
 M:	hedrick@astro.dyer.vanderbilt.edu
@@ -839,6 +845,11 @@
 M:	chaffee@cs.berkeley.edu
 L:	linux-kernel@vger.rutgers.edu
 W:	http://bmrc.berkeley.edu/people/chaffee
+S:	Maintained
+
+VIA 82Cxxx AUDIO DRIVER
+P:	Jeff Garzik
+M:	jgarzik@pobox.com
 S:	Maintained
 
 VIDEO FOR LINUX
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/Makefile linux.13p4/Makefile
--- linux.vanilla/Makefile	Sat Aug 28 20:00:53 1999
+++ linux.13p4/Makefile	Fri Sep  3 15:22:38 1999
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 2
-SUBLEVEL = 12
-EXTRAVERSION =
+SUBLEVEL = 13
+EXTRAVERSION = pre4
 
 ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
 
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/Rules.make linux.13p4/Rules.make
--- linux.vanilla/Rules.make	Fri Dec 18 22:01:48 1998
+++ linux.13p4/Rules.make	Wed Sep  1 13:52:39 1999
@@ -203,6 +203,18 @@
 	genksyms_smp_prefix := 
 endif
 
+#
+#	Differ 1 and 2Gig kernels to avoid module misload errors
+#
+
+ifdef CONFIG_2GB
+ifdef CONFIG_SMP
+	genksyms_smp_prefix := -p smp2gig_
+else
+	genksyms_smp_prefix := -p 2gig_
+endif
+endif
+
 $(MODINCL)/%.ver: %.c
 	@if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
 		echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<'; \
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/i386/Makefile linux.13p4/arch/i386/Makefile
--- linux.vanilla/arch/i386/Makefile	Sat Aug 14 02:27:13 1999
+++ linux.13p4/arch/i386/Makefile	Wed Sep  1 13:53:38 1999
@@ -96,6 +96,7 @@
 	@$(MAKEBOOT) clean
 
 archmrproper:
+	rm -f arch/i386/vmlinux.lds
 
 archdep:
 	@$(MAKEBOOT) dep
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/i386/boot/Makefile linux.13p4/arch/i386/boot/Makefile
--- linux.vanilla/arch/i386/boot/Makefile	Sat Jan  2 18:27:52 1999
+++ linux.13p4/arch/i386/boot/Makefile	Wed Sep  1 13:53:36 1999
@@ -51,7 +51,7 @@
 setup.o: setup.s
 	$(AS86) -o $@ $<
 
-setup.s: setup.S video.S Makefile $(BOOT_INCL) $(TOPDIR)/include/linux/version.h
+setup.s: setup.S video.S Makefile $(BOOT_INCL) $(TOPDIR)/include/linux/version.h $(TOPDIR)/include/linux/compile.h
 	$(CPP) -traditional $(SVGA_MODE) $(RAMDISK) $< -o $@
 
 bsetup: bsetup.o
@@ -60,7 +60,7 @@
 bsetup.o: bsetup.s
 	$(AS86) -o $@ $<
 
-bsetup.s: setup.S video.S Makefile $(BOOT_INCL) $(TOPDIR)/include/linux/version.h
+bsetup.s: setup.S video.S Makefile $(BOOT_INCL) $(TOPDIR)/include/linux/version.h $(TOPDIR)/include/linux/compile.h
 	$(CPP) -D__BIG_KERNEL__ -traditional $(SVGA_MODE) $(RAMDISK) $< -o $@
 
 bootsect: bootsect.o
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/i386/kernel/apm.c linux.13p4/arch/i386/kernel/apm.c
--- linux.vanilla/arch/i386/kernel/apm.c	Fri Jan 15 06:57:25 1999
+++ linux.13p4/arch/i386/kernel/apm.c	Wed Sep  1 13:53:41 1999
@@ -289,7 +289,7 @@
 /*
  * Local variables
  */
-static asmlinkage struct {
+static struct {
 	unsigned long	offset;
 	unsigned short	segment;
 }				apm_bios_entry;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/ppc/chrpboot/Makefile linux.13p4/arch/ppc/chrpboot/Makefile
--- linux.vanilla/arch/ppc/chrpboot/Makefile	Sat Aug 14 02:26:46 1999
+++ linux.13p4/arch/ppc/chrpboot/Makefile	Wed Sep  1 13:53:45 1999
@@ -57,7 +57,10 @@
 	mcopy zImage a:zImage
 
 piggyback: piggyback.c
-	$(HOSTCC) -DKERNELBASE=$(KERNELBASE) -o piggyback piggyback.c
+	$(HOSTCC) $(HOSTCFLAGS) -DKERNELBASE=$(KERNELBASE) -o piggyback piggyback.c
+
+mknote: mknote.c
+	$(HOSTCC) $(HOSTCFLAGS) -o mknote mknote.c
 
 image.o: piggyback ../coffboot/vmlinux.gz
 	./piggyback image < ../coffboot/vmlinux.gz | $(AS) -o image.o
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/ppc/kernel/prom.c linux.13p4/arch/ppc/kernel/prom.c
--- linux.vanilla/arch/ppc/kernel/prom.c	Sat Aug 28 20:00:54 1999
+++ linux.13p4/arch/ppc/kernel/prom.c	Wed Sep  1 13:53:45 1999
@@ -1,5 +1,5 @@
 /*
- * $Id: prom.c,v 1.54.2.7 1999/08/16 01:48:43 paulus Exp $
+ * $Id: prom.c,v 1.54.2.11 1999/08/30 19:29:19 cort Exp $
  *
  * Procedures for interfacing to the Open Firmware PROM on
  * Power Macintosh computers.
@@ -82,7 +82,7 @@
 #ifndef FB_MAX			/* avoid pulling in all of the fb stuff */
 #define FB_MAX	8
 #endif
-char *prom_display_paths[FB_MAX] __initdata = { 0, };
+char *prom_display_paths[FB_MAX] __pmacdata = { 0, };
 unsigned int prom_num_displays = 0;
 char *of_stdout_device = 0;
 
@@ -378,7 +378,7 @@
 #endif
 		return;
 	}
-
+	
 	/* check if we're prep, return if we are */
 	if ( *(unsigned long *)(0) == 0xdeadc0de )
 		return;
@@ -1219,22 +1219,6 @@
 }
 
 /*
- * Indicates whether the root node has a given value in its
- * compatible property.
- */
-__openfirmware
-int
-machine_is_compatible(const char *compat)
-{
-	struct device_node *root;
-
-	root = find_path_device("/");
-	if (root == 0)
-		return 0;
-	return device_is_compatible(root, compat);
-}
-
-/*
  * Find the device_node with a given phandle.
  */
 __openfirmware
@@ -2005,5 +1989,20 @@
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 0x00, 0x00, 0x00, 0x00, 
 };
+
+/* Indicates whether the root node has a given value in its
+ * compatible property.
+ */
+__openfirmware
+int
+machine_is_compatible(const char *compat)
+{
+	struct device_node *root;
+	
+	root = find_path_device("/");
+	if (root == 0)
+		return 0;
+	return device_is_compatible(root, compat);
+}
 
 #endif /* CONFIG_BOOTX_TEXT */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/ppc/kernel/setup.c linux.13p4/arch/ppc/kernel/setup.c
--- linux.vanilla/arch/ppc/kernel/setup.c	Sat Aug 28 20:00:54 1999
+++ linux.13p4/arch/ppc/kernel/setup.c	Wed Sep  1 13:53:45 1999
@@ -1,5 +1,5 @@
 /*
- * $Id: setup.c,v 1.132.2.2 1999/07/20 05:04:47 paulus Exp $
+ * $Id: setup.c,v 1.132.2.3 1999/08/24 21:13:51 cort Exp $
  * Common prep/pmac/chrp boot and setup code.
  */
 
@@ -272,7 +272,17 @@
 			
 			cpu_node = find_type_devices("cpu");
 			if ( !cpu_node ) break;
+			{
+				int s;
+				for ( s = 0; (s < i) && cpu_node->next ;
+				      s++, cpu_node = cpu_node->next )
+					/* nothing */ ;
+				if ( s != i )
+					printk("get_cpuinfo(): ran out of "
+					       "cpu nodes.\n");
+			}
 			fp = (int *) get_property(cpu_node, "clock-frequency", NULL);
+			
 			if ( !fp ) break;
 			len += sprintf(len+buffer, "clock\t\t: %dMHz\n",
 				       *fp / 1000000);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/ppc/kernel/time.c linux.13p4/arch/ppc/kernel/time.c
--- linux.vanilla/arch/ppc/kernel/time.c	Sat Aug 28 20:00:54 1999
+++ linux.13p4/arch/ppc/kernel/time.c	Wed Sep  1 13:53:45 1999
@@ -1,5 +1,5 @@
 /*
- * $Id: time.c,v 1.47.2.2 1999/08/14 21:45:49 cort Exp $
+ * $Id: time.c,v 1.47.2.4 1999/08/27 04:20:32 cort Exp $
  * Common time routines among all ppc machines.
  *
  * Written by Cort Dougan (cort@cs.nmt.edu) to merge
@@ -41,7 +41,6 @@
 #include <asm/processor.h>
 #include <asm/nvram.h>
 #include <asm/cache.h>
-/* Fixme - Why is this here? - Corey */
 #ifdef CONFIG_8xx
 #include <asm/8xx_immap.h>
 #endif
@@ -52,7 +51,7 @@
 void smp_local_timer_interrupt(struct pt_regs *);
 
 /* keep track of when we need to update the rtc */
-unsigned long last_rtc_update = 0;
+time_t last_rtc_update = 0;
 
 /* The decrementer counts down by 128 every 128ns on a 601. */
 #define DECREMENTER_COUNT_601	(1000000000 / HZ)
@@ -111,13 +110,14 @@
 			 * update the rtc when needed
 			 */
 			if ( (time_status & STA_UNSYNC) &&
-			     (xtime.tv_sec > last_rtc_update + 660) )
+			     ((xtime.tv_sec > last_rtc_update + 60) ||
+			      (xtime.tv_sec < last_rtc_update)) )
 			{
 				if (ppc_md.set_rtc_time(xtime.tv_sec) == 0)
 					last_rtc_update = xtime.tv_sec;
 				else
 					/* do it again in 60 s */
-					last_rtc_update = xtime.tv_sec - 60;
+					last_rtc_update = xtime.tv_sec;
 			}
 		}
 	}
@@ -202,10 +202,8 @@
         xtime.tv_usec = 0;
 
 	set_dec(decrementer_count);
-	/* mark the rtc/on-chip timer as in sync
-	 * so we don't update right away
-	 */
-	last_rtc_update = xtime.tv_sec;
+	/* allow updates right away */
+	last_rtc_update = 0;
 }
 
 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/ppc/kernel/time.h linux.13p4/arch/ppc/kernel/time.h
--- linux.vanilla/arch/ppc/kernel/time.h	Sat Aug 14 02:26:14 1999
+++ linux.13p4/arch/ppc/kernel/time.h	Wed Sep  1 13:53:45 1999
@@ -1,5 +1,5 @@
 /*
- * $Id: time.h,v 1.11 1999/03/18 04:16:34 cort Exp $
+ * $Id: time.h,v 1.11.2.1 1999/08/27 04:20:35 cort Exp $
  * Common time prototypes and such for all ppc machines.
  *
  * Written by Cort Dougan (cort@cs.nmt.edu) to merge
@@ -15,7 +15,7 @@
 extern unsigned long mktime(unsigned int, unsigned int, unsigned int,
 			    unsigned int, unsigned int, unsigned int);
 extern void to_tm(int tim, struct rtc_time * tm);
-extern unsigned long last_rtc_update;
+extern time_t last_rtc_update;
 
 int via_calibrate_decr(void);
 
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/sparc64/kernel/cpu.c linux.13p4/arch/sparc64/kernel/cpu.c
--- linux.vanilla/arch/sparc64/kernel/cpu.c	Sat Aug 14 02:26:14 1999
+++ linux.13p4/arch/sparc64/kernel/cpu.c	Wed Sep  1 13:53:51 1999
@@ -33,7 +33,7 @@
   { 0x22, 0x10, 0, "UltraSparc II integrated FPU"},
   { 0x17, 0x11, 0, "UltraSparc II integrated FPU"},
   { 0x17, 0x12, 0, "UltraSparc IIi integrated FPU"},
-  { 0x17, 0x13, 0, "UltraSparc III integrated FPU"},
+  { 0x17, 0x14, 0, "UltraSparc III integrated FPU"},
 };
 
 #define NSPARCFPU  (sizeof(linux_sparc_fpu)/sizeof(struct cpu_fp_info))
@@ -43,7 +43,7 @@
   { 0x22, 0x10, "TI UltraSparc II  (BlackBird)"},
   { 0x17, 0x11, "TI UltraSparc II  (BlackBird)"},
   { 0x17, 0x12, "TI UltraSparc IIi"},
-  { 0x17, 0x13, "TI UltraSparc III (Cheetah)"},  /* A guess... */
+  { 0x17, 0x14, "TI UltraSparc III (Cheetah)"},  /* A guess... */
 };
 
 #define NSPARCCHIPS  (sizeof(linux_sparc_chips)/sizeof(struct cpu_iu_info))
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/sparc64/kernel/entry.S linux.13p4/arch/sparc64/kernel/entry.S
--- linux.vanilla/arch/sparc64/kernel/entry.S	Sat Aug 14 02:26:14 1999
+++ linux.13p4/arch/sparc64/kernel/entry.S	Wed Sep  1 13:53:51 1999
@@ -1,4 +1,4 @@
-/* $Id: entry.S,v 1.103 1999/05/08 03:00:21 davem Exp $
+/* $Id: entry.S,v 1.103.2.1 1999/08/19 01:11:15 davem Exp $
  * arch/sparc64/kernel/entry.S:  Sparc64 trap low-level entry points.
  *
  * Copyright (C) 1995,1997 David S. Miller (davem@caip.rutgers.edu)
@@ -477,6 +477,97 @@
 	 add		%sp, STACK_BIAS + REGWIN_SZ, %o0
 	ba,pt		%xcc, rtrap
 	 clr		%l6
+
+	/* This is the trap handler entry point for ECC correctable
+	 * errors.  They are corrected, but we listen for the trap
+	 * so that the event can be logged.
+	 *
+	 * Disrupting errors are either:
+	 * 1) single-bit ECC errors during UDB reads to system
+	 *    memory
+	 * 2) data parity errors during write-back events
+	 *
+	 * As far as I can make out from the manual, the CEE trap
+	 * is only for correctable errors during memory read
+	 * accesses by the front-end of the processor.
+	 *
+	 * The code below is only for trap level 1 CEE events,
+	 * as it is the only situation where we can safely record
+	 * and log.  For trap level >1 we just clear the CE bit
+	 * in the AFSR and return.
+	 */
+
+	/* Our trap handling infrastructure allows us to preserve
+	 * two 64-bit values during etrap for arguments to
+	 * subsequent C code.  Therefore we encode the information
+	 * as follows:
+	 *
+	 * value 1) Full 64-bits of AFAR
+	 * value 2) Low 33-bits of AFSR, then bits 33-->42
+	 *          are UDBL error status and bits 43-->52
+	 *          are UDBH error status
+	 */
+	.align	64
+	.globl	cee_trap
+cee_trap:
+	ldxa	[%g0] ASI_AFSR, %g1		! Read AFSR
+	ldxa	[%g0] ASI_AFAR, %g2		! Read AFAR
+	sllx	%g1, 31, %g1			! Clear reserved bits
+	srlx	%g1, 31, %g1			! in AFSR
+
+	/* NOTE: UltraSparc-I/II have high and low UDB error
+	 *       registers, corresponding to the two UDB units
+	 *       present on those chips.  UltraSparc-IIi only
+	 *       has a single UDB, called "SDB" in the manual.
+	 *       For IIi the upper UDB register always reads
+	 *       as zero so for our purposes things will just
+	 *       work with the checks below.
+	 */
+	ldxa	[%g0] ASI_UDBL_ERROR_R, %g3	! Read UDB-Low error status
+	andcc	%g3, (1 << 8), %g4		! Check CE bit
+	sllx	%g3, (64 - 10), %g3		! Clear reserved bits
+	srlx	%g3, (64 - 10), %g3		! in UDB-Low error status
+
+	sllx	%g3, (33 + 0), %g3		! Shift up to encoding area
+	or	%g1, %g3, %g1			! Or it in
+	be,pn	%xcc, 1f			! Branch if CE bit was clear
+	 nop
+	stxa	%g4, [%g0] ASI_UDB_ERROR_W	! Clear CE sticky bit in UDBL
+	membar	#Sync				! Synchronize ASI stores
+1:	mov	0x18, %g5			! Addr of UDB-High error status
+	ldxa	[%g5] ASI_UDBH_ERROR_R, %g3	! Read it
+
+	andcc	%g3, (1 << 8), %g4		! Check CE bit
+	sllx	%g3, (64 - 10), %g3		! Clear reserved bits
+	srlx	%g3, (64 - 10), %g3		! in UDB-High error status
+	sllx	%g3, (33 + 10), %g3		! Shift up to encoding area
+	or	%g1, %g3, %g1			! Or it in
+	be,pn	%xcc, 1f			! Branch if CE bit was clear
+	 nop
+	nop
+
+	stxa	%g4, [%g5] ASI_UDB_ERROR_W	! Clear CE sticky bit in UDBH
+	membar	#Sync				! Synchronize ASI stores
+1:	mov	1, %g5				! AFSR CE bit is
+	sllx	%g5, 20, %g5			! bit 20
+	stxa	%g5, [%g0] ASI_AFSR		! Clear CE sticky bit in AFSR
+	membar	#Sync				! Synchronize ASI stores
+	sllx	%g2, (64 - 41), %g2		! Clear reserved bits
+	srlx	%g2, (64 - 41), %g2		! in latched AFAR
+
+	andn	%g2, 0x0f, %g2			! Finish resv bit clearing
+	mov	%g1, %g4			! Move AFSR+UDB* into save reg
+	mov	%g2, %g5			! Move AFAR into save reg
+	rdpr	%pil, %g2
+	wrpr	%g0, 15, %pil
+	ba,pt	%xcc, etrap_irq
+	 rd	%pc, %g7
+	mov	%l4, %o0
+
+	mov	%l5, %o1
+	call	cee_log
+	 add	%sp, STACK_BIAS + REGWIN_SZ, %o2
+	ba,a,pt	%xcc, rtrap_clr_l6
 
 	.globl		__do_privact
 __do_privact:
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/sparc64/kernel/head.S linux.13p4/arch/sparc64/kernel/head.S
--- linux.vanilla/arch/sparc64/kernel/head.S	Sat Aug 14 02:27:15 1999
+++ linux.13p4/arch/sparc64/kernel/head.S	Wed Sep  1 13:53:51 1999
@@ -1,4 +1,4 @@
-/* $Id: head.S,v 1.60.2.1 1999/08/09 13:00:25 davem Exp $
+/* $Id: head.S,v 1.60.2.2 1999/08/19 01:11:12 davem Exp $
  * head.S: Initial boot code for the Sparc64 port of Linux.
  *
  * Copyright (C) 1996,1997 David S. Miller (davem@caip.rutgers.edu)
@@ -75,16 +75,6 @@
 	 * PROM entry point is on %o4
 	 */
 sparc64_boot:
-#if 1
-	/* XXX Disable reception of correctable memory errors until
-	 * XXX we code up the proper handler... -DaveM
-	 */
-	ldxa	[%g0] ASI_ESTATE_ERROR_EN, %g1
-	andn	%g1, 0x1, %g1
-	stxa	%g1, [%g0] ASI_ESTATE_ERROR_EN
-	membar	#Sync
-#endif
-
 	/* Typically PROM has already enabled both MMU's and both on-chip
 	 * caches, but we do it here anyway just to be paranoid.
 	 */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/sparc64/kernel/trampoline.S linux.13p4/arch/sparc64/kernel/trampoline.S
--- linux.vanilla/arch/sparc64/kernel/trampoline.S	Sat Aug 14 02:27:15 1999
+++ linux.13p4/arch/sparc64/kernel/trampoline.S	Wed Sep  1 13:53:52 1999
@@ -1,4 +1,4 @@
-/* $Id: trampoline.S,v 1.8.2.1 1999/08/09 13:00:27 davem Exp $
+/* $Id: trampoline.S,v 1.8.2.2 1999/08/19 01:11:14 davem Exp $
  * trampoline.S: Jump start slave processors on sparc64.
  *
  * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
@@ -23,15 +23,6 @@
 	.globl		sparc64_cpu_startup, sparc64_cpu_startup_end
 sparc64_cpu_startup:
 	flushw
-#if 1
-	/* XXX Disable reception of correctable memory errors until
-	 * XXX we code up the proper handler... -DaveM
-	 */
-	ldxa	[%g0] ASI_ESTATE_ERROR_EN, %g1
-	andn	%g1, 0x1, %g1
-	stxa	%g1, [%g0] ASI_ESTATE_ERROR_EN
-	membar	#Sync
-#endif
 	mov	(LSU_CONTROL_IC | LSU_CONTROL_DC | LSU_CONTROL_IM | LSU_CONTROL_DM), %g1
 	stxa	%g1, [%g0] ASI_LSU_CONTROL
 	membar	#Sync
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/sparc64/kernel/traps.c linux.13p4/arch/sparc64/kernel/traps.c
--- linux.vanilla/arch/sparc64/kernel/traps.c	Sat Aug 14 02:25:55 1999
+++ linux.13p4/arch/sparc64/kernel/traps.c	Wed Sep  1 13:53:51 1999
@@ -1,4 +1,4 @@
-/* $Id: traps.c,v 1.58 1999/03/29 12:38:10 jj Exp $
+/* $Id: traps.c,v 1.58.2.1 1999/08/19 01:11:16 davem Exp $
  * arch/sparc64/kernel/traps.c
  *
  * Copyright (C) 1995,1997 David S. Miller (davem@caip.rutgers.edu)
@@ -389,6 +389,124 @@
 	lock_kernel();
 	force_sig(SIGSEGV, current);
 	unlock_kernel();
+}
+
+static char ecc_syndrome_table[] = {
+	0x4c, 0x40, 0x41, 0x48, 0x42, 0x48, 0x48, 0x49,
+	0x43, 0x48, 0x48, 0x49, 0x48, 0x49, 0x49, 0x4a,
+	0x44, 0x48, 0x48, 0x20, 0x48, 0x39, 0x4b, 0x48,
+	0x48, 0x25, 0x31, 0x48, 0x28, 0x48, 0x48, 0x2c,
+	0x45, 0x48, 0x48, 0x21, 0x48, 0x3d, 0x04, 0x48,
+	0x48, 0x4b, 0x35, 0x48, 0x2d, 0x48, 0x48, 0x29,
+	0x48, 0x00, 0x01, 0x48, 0x0a, 0x48, 0x48, 0x4b,
+	0x0f, 0x48, 0x48, 0x4b, 0x48, 0x49, 0x49, 0x48,
+	0x46, 0x48, 0x48, 0x2a, 0x48, 0x3b, 0x27, 0x48,
+	0x48, 0x4b, 0x33, 0x48, 0x22, 0x48, 0x48, 0x2e,
+	0x48, 0x19, 0x1d, 0x48, 0x1b, 0x4a, 0x48, 0x4b,
+	0x1f, 0x48, 0x4a, 0x4b, 0x48, 0x4b, 0x4b, 0x48,
+	0x48, 0x4b, 0x24, 0x48, 0x07, 0x48, 0x48, 0x36,
+	0x4b, 0x48, 0x48, 0x3e, 0x48, 0x30, 0x38, 0x48,
+	0x49, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x16, 0x48,
+	0x48, 0x12, 0x4b, 0x48, 0x49, 0x48, 0x48, 0x4b,
+	0x47, 0x48, 0x48, 0x2f, 0x48, 0x3f, 0x4b, 0x48,
+	0x48, 0x06, 0x37, 0x48, 0x23, 0x48, 0x48, 0x2b,
+	0x48, 0x05, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x32,
+	0x26, 0x48, 0x48, 0x3a, 0x48, 0x34, 0x3c, 0x48,
+	0x48, 0x11, 0x15, 0x48, 0x13, 0x4a, 0x48, 0x4b,
+	0x17, 0x48, 0x4a, 0x4b, 0x48, 0x4b, 0x4b, 0x48,
+	0x49, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x1e, 0x48,
+	0x48, 0x1a, 0x4b, 0x48, 0x49, 0x48, 0x48, 0x4b,
+	0x48, 0x08, 0x0d, 0x48, 0x02, 0x48, 0x48, 0x49,
+	0x03, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x4b, 0x48,
+	0x49, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x10, 0x48,
+	0x48, 0x14, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x4b,
+	0x49, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x18, 0x48,
+	0x48, 0x1c, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x4b,
+	0x4a, 0x0c, 0x09, 0x48, 0x0e, 0x48, 0x48, 0x4b,
+	0x0b, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x4b, 0x4a
+};
+
+/* cee_trap in entry.S encodes AFSR/UDBH/UDBL error status
+ * in the following format.  The AFAR is left as is, with
+ * reserved bits cleared, and is a raw 40-bit physical
+ * address.
+ */
+#define CE_STATUS_UDBH_UE		(1UL << (43 + 9))
+#define CE_STATUS_UDBH_CE		(1UL << (43 + 8))
+#define CE_STATUS_UDBH_ESYNDR		(0xffUL << 43)
+#define CE_STATUS_UDBH_SHIFT		43
+#define CE_STATUS_UDBL_UE		(1UL << (33 + 9))
+#define CE_STATUS_UDBL_CE		(1UL << (33 + 8))
+#define CE_STATUS_UDBL_ESYNDR		(0xffUL << 33)
+#define CE_STATUS_UDBL_SHIFT		33
+#define CE_STATUS_AFSR_MASK		(0x1ffffffffUL)
+#define CE_STATUS_AFSR_ME		(1UL << 32)
+#define CE_STATUS_AFSR_PRIV		(1UL << 31)
+#define CE_STATUS_AFSR_ISAP		(1UL << 30)
+#define CE_STATUS_AFSR_ETP		(1UL << 29)
+#define CE_STATUS_AFSR_IVUE		(1UL << 28)
+#define CE_STATUS_AFSR_TO		(1UL << 27)
+#define CE_STATUS_AFSR_BERR		(1UL << 26)
+#define CE_STATUS_AFSR_LDP		(1UL << 25)
+#define CE_STATUS_AFSR_CP		(1UL << 24)
+#define CE_STATUS_AFSR_WP		(1UL << 23)
+#define CE_STATUS_AFSR_EDP		(1UL << 22)
+#define CE_STATUS_AFSR_UE		(1UL << 21)
+#define CE_STATUS_AFSR_CE		(1UL << 20)
+#define CE_STATUS_AFSR_ETS		(0xfUL << 16)
+#define CE_STATUS_AFSR_ETS_SHIFT	16
+#define CE_STATUS_AFSR_PSYND		(0xffffUL << 0)
+#define CE_STATUS_AFSR_PSYND_SHIFT	0
+
+/* Layout of Ecache TAG Parity Syndrome of AFSR */
+#define AFSR_ETSYNDROME_7_0		0x1UL /* E$-tag bus bits  <7:0> */
+#define AFSR_ETSYNDROME_15_8		0x2UL /* E$-tag bus bits <15:8> */
+#define AFSR_ETSYNDROME_21_16		0x4UL /* E$-tag bus bits <21:16> */
+#define AFSR_ETSYNDROME_24_22		0x8UL /* E$-tag bus bits <24:22> */
+
+static char *syndrome_unknown = "<Unknown>";
+
+asmlinkage void cee_log(unsigned long ce_status,
+			unsigned long afar,
+			struct pt_regs *regs)
+{
+	char memmod_str[64];
+	char *p;
+	unsigned short scode, udb_reg;
+
+	printk(KERN_WARNING "CPU[%d]: Correctable ECC Error "
+	       "AFSR[%lx] AFAR[%016lx] UDBL[%lx] UDBH[%lx]\n",
+	       smp_processor_id(),
+	       (ce_status & CE_STATUS_AFSR_MASK),
+	       afar,
+	       ((ce_status >> CE_STATUS_UDBL_SHIFT) & 0x3ffUL),
+	       ((ce_status >> CE_STATUS_UDBH_SHIFT) & 0x3ffUL));
+
+	udb_reg = ((ce_status >> CE_STATUS_UDBL_SHIFT) & 0x3ffUL);
+	if (udb_reg & (1 << 8)) {
+		scode = ecc_syndrome_table[udb_reg & 0xff];
+		if (prom_getunumber(scode, afar,
+				    memmod_str, sizeof(memmod_str)) == -1)
+			p = syndrome_unknown;
+		else
+			p = memmod_str;
+		printk(KERN_WARNING "CPU[%d]: UDBL Syndrome[%x] "
+		       "Memory Module \"%s\"\n",
+		       smp_processor_id(), scode, p);
+	}
+
+	udb_reg = ((ce_status >> CE_STATUS_UDBH_SHIFT) & 0x3ffUL);
+	if (udb_reg & (1 << 8)) {
+		scode = ecc_syndrome_table[udb_reg & 0xff];
+		if (prom_getunumber(scode, afar,
+				    memmod_str, sizeof(memmod_str)) == -1)
+			p = syndrome_unknown;
+		else
+			p = memmod_str;
+		printk(KERN_WARNING "CPU[%d]: UDBH Syndrome[%x] "
+		       "Memory Module \"%s\"\n",
+		       smp_processor_id(), scode, p);
+	}
 }
 
 void do_fpe_common(struct pt_regs *regs)
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/sparc64/kernel/ttable.S linux.13p4/arch/sparc64/kernel/ttable.S
--- linux.vanilla/arch/sparc64/kernel/ttable.S	Sat Aug 14 02:25:55 1999
+++ linux.13p4/arch/sparc64/kernel/ttable.S	Wed Sep  1 13:53:51 1999
@@ -1,4 +1,4 @@
-/* $Id: ttable.S,v 1.28 1999/03/29 12:38:10 jj Exp $
+/* $Id: ttable.S,v 1.28.2.1 1999/08/19 01:11:14 davem Exp $
  * ttable.S: Sparc V9 Trap Table(s) with SpitFire extensions.
  *
  * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
@@ -57,7 +57,7 @@
 tl0_ivec:	TRAP_IVEC
 tl0_paw:	TRAP(do_paw)
 tl0_vaw:	TRAP(do_vaw)
-tl0_cee:	TRAP(do_cee)
+tl0_cee:	TRAP_NOSAVE(cee_trap)
 tl0_iamiss:
 #include	"itlb_base.S"
 tl0_damiss:
@@ -202,7 +202,7 @@
 tl1_ivec:	TRAP_IVEC
 tl1_paw:	TRAPTL1(do_paw_tl1)
 tl1_vaw:	TRAPTL1(do_vaw_tl1)
-tl1_cee:	TRAPTL1(do_cee_tl1)
+tl1_cee:	TRAPTL1_CEE
 tl1_iamiss:	BTRAPTL1(0x64) BTRAPTL1(0x65) BTRAPTL1(0x66) BTRAPTL1(0x67)
 tl1_damiss:
 #include	"dtlb_backend.S"
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/sparc64/prom/misc.c linux.13p4/arch/sparc64/prom/misc.c
--- linux.vanilla/arch/sparc64/prom/misc.c	Thu Mar 11 00:53:37 1999
+++ linux.13p4/arch/sparc64/prom/misc.c	Wed Sep  1 13:53:53 1999
@@ -1,4 +1,4 @@
-/* $Id: misc.c,v 1.14 1998/12/18 10:01:59 davem Exp $
+/* $Id: misc.c,v 1.14.2.1 1999/08/19 01:11:18 davem Exp $
  * misc.c:  Miscellaneous prom functions that don't belong
  *          anywhere else.
  *
@@ -125,15 +125,37 @@
 /* This is only used internally below. */
 static int prom_get_mmu_ihandle(void)
 {
-	int node;
-	int ret;
+	static int mmu_ihandle_cache = 0;
+	int node, ret;
+
+	if (mmu_ihandle_cache != 0)
+		return mmu_ihandle_cache;
 
 	node = prom_finddevice("/chosen");
 	ret = prom_getint(node, "mmu");
-	if(ret == -1 || ret == 0) {
-		prom_printf("PROMLIB: Fatal error, cannot get mmu ihandle.\n");
-		prom_halt();
-	}
+	if(ret == -1 || ret == 0)
+		mmu_ihandle_cache = -1;
+	else
+		mmu_ihandle_cache = ret;
+
+	return ret;
+}
+
+static int prom_get_memory_ihandle(void)
+{
+	static int memory_ihandle_cache = 0;
+	int node, ret;
+
+	if (memory_ihandle_cache != 0)
+		return memory_ihandle_cache;
+
+	node = prom_finddevice("/chosen");
+	ret = prom_getint(node, "memory");
+	if (ret == -1 || ret == 0)
+		memory_ihandle_cache = -1;
+	else
+		memory_ihandle_cache = ret;
+
 	return ret;
 }
 
@@ -197,12 +219,18 @@
  * etched into the motherboard next to the SIMM slot
  * in question.
  */
-int prom_getunumber(unsigned long phys_lo, unsigned long phys_hi,
+int prom_getunumber(int syndrome_code,
+		    unsigned long phys_addr,
 		    char *buf, int buflen)
 {
-	return p1275_cmd("SUNW,get-unumber",
-			 (P1275_ARG(2, P1275_ARG_OUT_BUF) | P1275_INOUT(4, 1)),
-			 phys_lo, phys_hi, buf, buflen);
+	return p1275_cmd("call-method",
+			 (P1275_ARG(0, P1275_ARG_IN_STRING)	|
+			  P1275_ARG(3, P1275_ARG_OUT_BUF)	|
+			  P1275_ARG(5, P1275_ARG_IN_64B)	|
+			  P1275_INOUT(8, 2)),
+			 "SUNW,get-unumber", prom_get_memory_ihandle(),
+			 buflen, buf, P1275_SIZE(buflen),
+			 0, phys_addr, syndrome_code);
 }
 
 /* Power management extensions. */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/arch/sparc64/prom/p1275.c linux.13p4/arch/sparc64/prom/p1275.c
--- linux.vanilla/arch/sparc64/prom/p1275.c	Tue Oct 27 17:52:21 1998
+++ linux.13p4/arch/sparc64/prom/p1275.c	Wed Sep  1 13:53:53 1999
@@ -1,4 +1,4 @@
-/* $Id: p1275.c,v 1.15 1998/10/13 14:03:47 davem Exp $
+/* $Id: p1275.c,v 1.15.2.1 1999/08/19 01:11:19 davem Exp $
  * p1275.c: Sun IEEE 1275 PROM low level interface routines
  *
  * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
@@ -320,6 +320,10 @@
 		case P1275_ARG_NUMBER:
 			p1275buf.prom_args[i + 3] =
 						(unsigned)va_arg(list, long);
+			break;
+		case P1275_ARG_IN_64B:
+			p1275buf.prom_args[i + 3] =
+				va_arg(list, unsigned long);
 			break;
 		case P1275_ARG_IN_STRING:
 			strcpy (p, va_arg(list, char *));
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/Config.in linux.13p4/drivers/char/Config.in
--- linux.vanilla/drivers/char/Config.in	Sat Aug 28 20:00:54 1999
+++ linux.13p4/drivers/char/Config.in	Fri Sep  3 13:49:11 1999
@@ -134,6 +134,10 @@
   if [ "$CONFIG_RADIO_GEMTEK" = "y" ]; then
     hex '  GemTek i/o port (0x20c, 0x30c, 0x24c or 0x34c)' CONFIG_RADIO_GEMTEK_PORT 34c
   fi
+  dep_tristate 'Trust FM Radio' CONFIG_RADIO_TRUST $CONFIG_VIDEO_DEV
+  if [ "$CONFIG_RADIO_TRUST" = "y" ]; then
+    hex '  Trust FM Radio I/O port (0x350 or 0x358)' CONFIG_RADIO_TRUST_PORT 350
+  fi
   if [ "$CONFIG_PCI" != "n" ]; then
     dep_tristate 'BT848 Video For Linux' CONFIG_VIDEO_BT848 $CONFIG_VIDEO_DEV
   fi
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/Makefile linux.13p4/drivers/char/Makefile
--- linux.vanilla/drivers/char/Makefile	Sat Aug 28 20:00:54 1999
+++ linux.13p4/drivers/char/Makefile	Fri Sep  3 13:49:11 1999
@@ -498,6 +498,14 @@
   endif
 endif                                             
 
+ifeq ($(CONFIG_RADIO_TRUST),y)
+L_OBJS += radio-trust.o
+else
+  ifeq ($(CONFIG_RADIO_TRUST),m)
+  M_OBJS += radio-trust.o
+  endif
+endif                                             
+
 ifeq ($(CONFIG_QIC02_TAPE),y)
 L_OBJS += tpqic02.o
 else
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/bttv.c linux.13p4/drivers/char/bttv.c
--- linux.vanilla/drivers/char/bttv.c	Sat Aug 28 20:00:54 1999
+++ linux.13p4/drivers/char/bttv.c	Wed Sep  1 13:53:05 1999
@@ -1288,7 +1288,7 @@
 }
 
 
-static void bt848_set_geo(struct bttv *btv, u16 width, u16 height, u16 fmt)
+static void bt848_set_geo(struct bttv *btv, u16 width, u16 height, u16 fmt, int pll)
 {
         u16 vscale, hscale;
 	u32 xsf, sr;
@@ -1297,9 +1297,13 @@
 	u16 inter;
 	u8 crop, vtc;  
 	struct tvnorm *tvn;
+	unsigned long flags;
  	
 	if (!width || !height)
 	        return;
+	        
+	save_flags(flags);
+	cli();
 
 	tvn=&tvnorms[btv->win.norm];
 	
@@ -1324,7 +1328,8 @@
 	btwrite(1, BT848_VBI_PACK_DEL);
 
         btv->pll.pll_ofreq = tvn->Fsc;
-        set_pll(btv);
+        if(pll)
+        	set_pll(btv);
 
 	btwrite(fmt, BT848_COLOR_FMT);
 #ifdef __sparc__
@@ -1372,6 +1377,7 @@
 			hdelay, vdelay, crop);
 	bt848_set_eogeo(btv, 1, vtc, hscale, vscale, hactive, vactive,
 			hdelay, vdelay, crop);
+	restore_flags(flags);
 }
 
 
@@ -1400,7 +1406,7 @@
 	else
 	        btor(BT848_CAP_CTL_DITH_FRAME, BT848_CAP_CTL);
 
-        bt848_set_geo(btv, btv->win.width, btv->win.height, format);
+        bt848_set_geo(btv, btv->win.width, btv->win.height, format, 1);
 }
 
 /*
@@ -3436,14 +3442,14 @@
 					btv->risc_jmp[11]=cpu_to_le32(btv->gre);
 					bt848_set_geo(btv, btv->gwidth,
 						      btv->gheight,
-						      btv->gfmt);
+						      btv->gfmt, 0);
 				} else {
 					bt848_set_risc_jmps(btv);
 					btand(~BT848_VSCALE_COMB, BT848_E_VSCALE_HI);
 					btand(~BT848_VSCALE_COMB, BT848_O_VSCALE_HI);
                                         bt848_set_geo(btv, btv->win.width, 
 						      btv->win.height,
-						      btv->win.color_fmt);
+						      btv->win.color_fmt, 0);
 				}
 				wake_up_interruptible(&btv->capq);
 				break;
@@ -3454,7 +3460,7 @@
 				btv->risc_jmp[11]=cpu_to_le32(btv->gre);
 				btv->risc_jmp[12]=cpu_to_le32(BT848_RISC_JUMP);
 				bt848_set_geo(btv, btv->gwidth, btv->gheight,
-					      btv->gfmt);
+					      btv->gfmt, 0);
 			}
 		}
 		if (astat&BT848_INT_OCERR) 
@@ -3557,7 +3563,7 @@
                 remap[bttv_num]|=btv->bt848_adr&(~PCI_BASE_ADDRESS_MEM_MASK);
                 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, remap[bttv_num]);
                 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &dw);
-                btv->dev->base_address[0] = btv->bt848_adr;
+                btv->dev->base_address[0] = btv->bt848_adr = dw;
         }					
         btv->bt848_adr&=PCI_BASE_ADDRESS_MEM_MASK;
         pci_read_config_byte(dev, PCI_CLASS_REVISION, &btv->revision);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/buz.c linux.13p4/drivers/char/buz.c
--- linux.vanilla/drivers/char/buz.c	Sat Aug 28 20:00:55 1999
+++ linux.13p4/drivers/char/buz.c	Fri Sep  3 12:30:54 1999
@@ -2901,7 +2901,6 @@
 		{
 			struct zoran_status bs;
 			int norm, input, status;
-			unsigned long timeout;
 
 			if (zr->codec_mode != BUZ_MODE_IDLE) {
 				return -EINVAL;
@@ -3317,7 +3316,6 @@
 	unsigned char latency;
 	struct zoran *zr;
 	struct pci_dev *dev = NULL;
-	int result;
 
 	zoran_num = 0;
 
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/console.c linux.13p4/drivers/char/console.c
--- linux.vanilla/drivers/char/console.c	Thu Mar 11 00:51:35 1999
+++ linux.13p4/drivers/char/console.c	Wed Sep  1 13:53:04 1999
@@ -1984,7 +1984,7 @@
 	static unsigned long printing = 0;
 	const ushort *start;
 	ushort cnt = 0;
-	ushort myx = x;
+	ushort myx;
 
 	/* console busy or not yet initialized */
 	if (!printable || test_and_set_bit(0, &printing))
@@ -1992,6 +1992,10 @@
 
 	if (kmsg_redirect && vc_cons_allocated(kmsg_redirect - 1))
 		currcons = kmsg_redirect - 1;
+
+	/* read `x' only after setting currecons properly (otherwise
+	   the `x' macro will read the x of the foreground console). */
+	myx = x;
 
 	if (!vc_cons_allocated(currcons)) {
 		/* impossible */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/lp.c linux.13p4/drivers/char/lp.c
--- linux.vanilla/drivers/char/lp.c	Sat Aug 14 02:26:15 1999
+++ linux.13p4/drivers/char/lp.c	Wed Sep  1 13:53:04 1999
@@ -249,7 +249,8 @@
 		lp_table[minor].irq_missed = 1;
 		schedule_timeout(timeout);
 		lp_parport_claim(minor);
-	} else
+	} 
+	else
 		schedule_timeout(timeout);
 }
 
@@ -412,6 +413,7 @@
 	if (LP_POLLED(minor) || LP_PREEMPTED(minor)) {
 		current->state = TASK_INTERRUPTIBLE;
 		lp_parport_release(minor);
+		current->state = TASK_INTERRUPTIBLE;
 		schedule_timeout(LP_TIMEOUT_POLLED);
 		lp_parport_claim(minor);
 		lp_table[minor].irq_missed = 1;
@@ -641,6 +643,7 @@
 		/* Data available. */
 
 		/* Hack: Wait 10ms (between events 6 and 7) */
+		current->state = TASK_INTERRUPTIBLE;
                 schedule_timeout((HZ+99)/100);
                 break;
 	}
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/n_tty.c linux.13p4/drivers/char/n_tty.c
--- linux.vanilla/drivers/char/n_tty.c	Sat Aug 14 02:25:55 1999
+++ linux.13p4/drivers/char/n_tty.c	Wed Sep  1 13:53:04 1999
@@ -854,6 +854,7 @@
 	retval = 0;
 	n = MIN(*nr, MIN(tty->read_cnt, N_TTY_BUF_SIZE - tty->read_tail));
 	if (n) {
+		mb();
 		retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n);
 		n -= retval;
 		tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/pms.c linux.13p4/drivers/char/pms.c
--- linux.vanilla/drivers/char/pms.c	Sat Aug 14 02:26:48 1999
+++ linux.13p4/drivers/char/pms.c	Wed Sep  1 13:53:07 1999
@@ -1024,12 +1024,6 @@
 	return 0;
 }
 
-static void shutdown_mediavision(void)
-{
-	release_region(io_port,3);
-	release_region(0x9A01, 1);
-}
-
 /*
  *	Module stuff
  */
@@ -1061,6 +1055,12 @@
 
 MODULE_PARM(io_port,"i");
 MODULE_PARM(mem_base,"i");
+
+static void shutdown_mediavision(void)
+{
+	release_region(io_port,3);
+	release_region(0x9A01, 1);
+}
 
 void cleanup_module(void)
 {
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/radio-trust.c linux.13p4/drivers/char/radio-trust.c
--- linux.vanilla/drivers/char/radio-trust.c	Thu Jan  1 01:00:00 1970
+++ linux.13p4/drivers/char/radio-trust.c	Fri Sep  3 13:51:20 1999
@@ -0,0 +1,356 @@
+/* radio-trust.c - Trust FM Radio card driver for Linux 2.2 
+ * by Eric Lammerts <eric@scintilla.utwente.nl>
+ *
+ * Based on radio-aztech.c. Original notes:
+ *
+ * Adapted to support the Video for Linux API by 
+ * Russell Kroll <rkroll@exploits.org>.  Based on original tuner code by:
+ *
+ * Quay Ly
+ * Donald Song
+ * Jason Lewis      (jlewis@twilight.vtc.vsc.edu) 
+ * Scott McGrath    (smcgrath@twilight.vtc.vsc.edu)
+ * William McGrath  (wmcgrath@twilight.vtc.vsc.edu)
+ *
+ * The basis for this code may be found at http://bigbang.vtc.vsc.edu/fmradio/
+ */
+
+#include <stdarg.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <linux/videodev.h>
+#include <linux/config.h>	/* CONFIG_RADIO_TRUST_PORT 	*/
+
+/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
+
+#ifndef CONFIG_RADIO_TRUST_PORT
+#define CONFIG_RADIO_TRUST_PORT -1
+#endif
+
+static int io = CONFIG_RADIO_TRUST_PORT; 
+static int ioval = 0xf;
+static int users = 0;
+static __u16 curvol;
+static __u16 curbass;
+static __u16 curtreble;
+static unsigned long curfreq;
+static int curstereo;
+static int curmute;
+
+/* i2c addresses */
+#define TDA7318_ADDR 0x88
+#define TSA6060T_ADDR 0xc4
+
+#define TR_DELAY do { inb(io); inb(io); inb(io); } while(0)
+#define TR_SET_SCL outb(ioval |= 2, io)
+#define TR_CLR_SCL outb(ioval &= 0xfd, io)
+#define TR_SET_SDA outb(ioval |= 1, io)
+#define TR_CLR_SDA outb(ioval &= 0xfe, io)
+
+static void write_i2c(int n, ...)
+{
+	unsigned char val, mask;
+	va_list args;
+
+	va_start(args, n);
+
+	/* start condition */
+	TR_SET_SDA;
+	TR_SET_SCL;
+	TR_DELAY;
+	TR_CLR_SDA;
+	TR_CLR_SCL;
+	TR_DELAY;
+
+	for(; n; n--) {
+		val = va_arg(args, unsigned);
+		for(mask = 0x80; mask; mask >>= 1) {
+			if(val & mask)
+				TR_SET_SDA;
+			else
+				TR_CLR_SDA;
+			TR_SET_SCL;
+			TR_DELAY;
+			TR_CLR_SCL;
+			TR_DELAY;
+		}
+		/* acknowledge bit */
+		TR_SET_SDA;
+		TR_SET_SCL;
+		TR_DELAY;
+		TR_CLR_SCL;
+		TR_DELAY;
+	}
+
+	/* stop condition */
+	TR_CLR_SDA;
+	TR_DELAY;
+	TR_SET_SCL;
+	TR_DELAY;
+	TR_SET_SDA;
+	TR_DELAY;
+
+	va_end(args);
+}
+
+static void tr_setvol(__u16 vol)
+{
+	curvol = vol / 2048;
+	write_i2c(2, TDA7318_ADDR, curvol ^ 0x1f);
+}
+
+static int basstreble2chip[15] = {
+	0, 1, 2, 3, 4, 5, 6, 7, 14, 13, 12, 11, 10, 9, 8
+};
+
+static void tr_setbass(__u16 bass)
+{
+	curbass = bass / 4370;
+	write_i2c(2, TDA7318_ADDR, 0x60 | basstreble2chip[curbass]);
+}
+
+static void tr_settreble(__u16 treble)
+{
+	curtreble = treble / 4370;
+	write_i2c(2, TDA7318_ADDR, 0x70 | basstreble2chip[curtreble]);
+}
+
+static void tr_setstereo(int stereo)
+{
+	curstereo = !!stereo;
+	ioval = (ioval & 0xfb) | (!curstereo << 2);
+	outb(ioval, io);
+}
+
+static void tr_setmute(int mute)
+{
+	curmute = !!mute;
+	ioval = (ioval & 0xf7) | (curmute << 3);
+	outb(ioval, io);
+}
+
+static int tr_getsigstr(void)
+{
+	int i, v;
+	
+	for(i = 0, v = 0; i < 100; i++) v |= inb(io);
+	return (v & 1)? 0 : 0xffff;
+}
+
+static int tr_getstereo(void)
+{
+	/* don't know how to determine it, just return the setting */
+	return curstereo;
+}
+
+static void tr_setfreq(unsigned long f)
+{
+	f /= 160;	/* Convert to 10 kHz units	*/
+	f += 1070;	/* Add 10.7 MHz IF			*/
+
+	write_i2c(5, TSA6060T_ADDR, (f << 1) | 1, f >> 7, 0x60 | ((f >> 15) & 1), 0);
+}
+
+static int tr_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
+{
+	switch(cmd)
+	{
+		case VIDIOCGCAP:
+		{
+			struct video_capability v;
+
+			v.type=VID_TYPE_TUNER;
+			v.channels=1;
+			v.audios=1;
+
+			/* No we don't do pictures */
+			v.maxwidth=0;
+			v.maxheight=0;
+			v.minwidth=0;
+			v.minheight=0;
+
+			strcpy(v.name, "Trust FM Radio");
+
+			if(copy_to_user(arg,&v,sizeof(v)))
+				return -EFAULT;
+
+			return 0;
+		}
+		case VIDIOCGTUNER:
+		{
+			struct video_tuner v;
+
+			if(copy_from_user(&v, arg,sizeof(v))!=0) 
+				return -EFAULT;
+
+			if(v.tuner)	/* Only 1 tuner */ 
+				return -EINVAL;
+
+			v.rangelow = 87500 * 16;
+			v.rangehigh = 108000 * 16;
+			v.flags = VIDEO_TUNER_LOW;
+			v.mode = VIDEO_MODE_AUTO;
+
+			v.signal = tr_getsigstr();
+			if(tr_getstereo())
+				v.flags |= VIDEO_TUNER_STEREO_ON;
+
+			strcpy(v.name, "FM");
+
+			if(copy_to_user(arg,&v, sizeof(v)))
+				return -EFAULT;
+
+			return 0;
+		}
+		case VIDIOCSTUNER:
+		{
+			struct video_tuner v;
+
+			if(copy_from_user(&v, arg, sizeof(v)))
+				return -EFAULT;
+			if(v.tuner != 0)
+				return -EINVAL;
+
+			return 0;
+		}
+		case VIDIOCGFREQ:
+			if(copy_to_user(arg, &curfreq, sizeof(curfreq)))
+				return -EFAULT;
+			return 0;
+
+		case VIDIOCSFREQ:
+		{
+			unsigned long f;
+
+			if(copy_from_user(&f, arg, sizeof(curfreq)))
+				return -EFAULT;
+			tr_setfreq(f);
+			return 0;
+		}
+		case VIDIOCGAUDIO:
+		{	
+			struct video_audio v;
+
+			memset(&v,0, sizeof(v));
+			v.flags = VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME |
+			          VIDEO_AUDIO_BASS | VIDEO_AUDIO_TREBLE;
+			v.mode = curstereo? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
+			v.volume = curvol * 2048;
+			v.step = 2048;
+			v.bass = curbass * 4370;
+			v.treble = curtreble * 4370;
+			
+			strcpy(v.name, "Trust FM Radio");
+			if(copy_to_user(arg,&v, sizeof(v)))
+				return -EFAULT;
+			return 0;			
+		}
+		case VIDIOCSAUDIO:
+		{
+			struct video_audio v;
+
+			if(copy_from_user(&v, arg, sizeof(v))) 
+				return -EFAULT;	
+			if(v.audio) 
+				return -EINVAL;
+
+			tr_setvol(v.volume);					
+			tr_setbass(v.bass);
+			tr_settreble(v.treble);
+			tr_setstereo(v.mode & VIDEO_SOUND_STEREO);
+			tr_setmute(v.flags & VIDEO_AUDIO_MUTE);
+			return 0;
+		}
+		default:
+			return -ENOIOCTLCMD;
+	}
+}
+
+static int tr_open(struct video_device *dev, int flags)
+{
+	if(users)
+		return -EBUSY;
+	users++;
+	MOD_INC_USE_COUNT;
+	return 0;
+}
+
+static void tr_close(struct video_device *dev)
+{
+	users--;
+	MOD_DEC_USE_COUNT;
+}
+
+static struct video_device trust_radio=
+{
+	"Trust FM Radio",
+	VID_TYPE_TUNER,
+	VID_HARDWARE_TRUST,
+	tr_open,
+	tr_close,
+	NULL,	/* Can't read  (no capture ability) */
+	NULL,	/* Can't write */
+	NULL,	/* No poll */
+	tr_ioctl,
+	NULL,
+	NULL
+};
+
+__initfunc(int trust_init(struct video_init *v))
+{
+	if(check_region(io, 2)) {
+		printk(KERN_ERR "trust: port 0x%x already in use\n", io);
+		return -EBUSY;
+	}
+	if(video_register_device(&trust_radio, VFL_TYPE_RADIO)==-1)
+		return -EINVAL;
+		
+	request_region(io, 2, "Trust FM Radio");
+
+	printk(KERN_INFO "Trust FM Radio card driver v1.0.\n");
+
+	write_i2c(2, TDA7318_ADDR, 0x80);	/* speaker att. LF = 0 dB */
+	write_i2c(2, TDA7318_ADDR, 0xa0);	/* speaker att. RF = 0 dB */
+	write_i2c(2, TDA7318_ADDR, 0xc0);	/* speaker att. LR = 0 dB */
+	write_i2c(2, TDA7318_ADDR, 0xe0);	/* speaker att. RR = 0 dB */
+	write_i2c(2, TDA7318_ADDR, 0x40);	/* stereo 1 input, gain = 18.75 dB */
+
+	tr_setvol(0x8000);					
+	tr_setbass(0x8000);
+	tr_settreble(0x8000);
+	tr_setstereo(1);
+
+	/* mute card - prevents noisy bootups */
+	tr_setmute(1);
+
+	return 0;
+}
+
+#ifdef MODULE
+
+MODULE_AUTHOR("Eric Lammerts, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
+MODULE_DESCRIPTION("A driver for the Trust FM Radio card.");
+MODULE_PARM(io, "i");
+MODULE_PARM_DESC(io, "I/O address of the Trust FM Radio card (0x350 or 0x358)");
+
+EXPORT_NO_SYMBOLS;
+
+int init_module(void)
+{
+	if(io == -1) {
+		printk(KERN_ERR "You must set an I/O address with io=0x???\n");
+		return -EINVAL;
+	}
+	return trust_init(NULL);
+}
+
+void cleanup_module(void)
+{
+	video_unregister_device(&trust_radio);
+	release_region(io, 2);
+}
+
+#endif
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/serial.c linux.13p4/drivers/char/serial.c
--- linux.vanilla/drivers/char/serial.c	Sat Aug 14 02:27:17 1999
+++ linux.13p4/drivers/char/serial.c	Wed Sep  1 13:53:04 1999
@@ -3289,6 +3289,7 @@
 	unsigned long flags;
 	int e1, e2;
 	int i;
+	struct async_struct *info;
 
 	/* printk("Unloading %s: version %s\n", serial_name, serial_version); */
 	save_flags(flags);
@@ -3308,6 +3309,11 @@
 	for (i = 0; i < NR_PORTS; i++) {
 		if (rs_table[i].type != PORT_UNKNOWN)
 			release_region(rs_table[i].port, 8);
+		info = rs_table[i].info;
+		if (info) {
+			rs_table[i].info = NULL;
+			kfree_s(info, sizeof(struct async_struct));
+		}
 	}
 	if (tmp_buf) {
 		free_page((unsigned long) tmp_buf);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/tty_io.c linux.13p4/drivers/char/tty_io.c
--- linux.vanilla/drivers/char/tty_io.c	Sat Aug 28 20:00:55 1999
+++ linux.13p4/drivers/char/tty_io.c	Fri Sep  3 13:44:53 1999
@@ -1492,10 +1492,11 @@
 	return 0;
 }
 
-static int tioccons(struct tty_struct *tty, struct tty_struct *real_tty)
+static int tioccons(struct inode *inode,
+	struct tty_struct *tty, struct tty_struct *real_tty)
 {
-	if (tty->driver.type == TTY_DRIVER_TYPE_CONSOLE ||
-	    tty->driver.type == TTY_DRIVER_TYPE_SYSCONS) {
+	if (inode->i_rdev == SYSCONS_DEV ||
+	    inode->i_rdev == CONSOLE_DEV) {
 		if (!suser())
 			return -EPERM;
 		redirect = NULL;
@@ -1705,7 +1706,7 @@
 		case TIOCSWINSZ:
 			return tiocswinsz(tty, real_tty, (struct winsize *) arg);
 		case TIOCCONS:
-			return tioccons(tty, real_tty);
+			return tioccons(inode, tty, real_tty);
 		case FIONBIO:
 			return fionbio(file, (int *) arg);
 		case TIOCEXCL:
@@ -1979,7 +1980,8 @@
 {
 	int	retval;
 	struct tty_driver *p;
-	int	found = 0;
+	int	i, found = 0;
+	struct termios *tp;
 	const char *othername = NULL;
 	
 	if (*driver->refcount)
@@ -2010,6 +2012,23 @@
 	if (driver->next)
 		driver->next->prev = driver->prev;
 
+	/*
+	 * Free the termios and termios_locked structures because
+	 * we don't want to get memory leaks when modular tty
+	 * drivers are removed from the kernel.
+	 */
+	for (i = 0; i < driver->num; i++) {
+		tp = driver->termios[i];
+		if (tp) {
+			driver->termios[i] = NULL;
+			kfree_s(tp, sizeof(struct termios));
+		}
+		tp = driver->termios_locked[i];
+		if (tp) {
+			driver->termios_locked[i] = NULL;
+			kfree_s(tp, sizeof(struct termios));
+		}
+	}
 	proc_tty_unregister_driver(driver);
 	return 0;
 }
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/tuner.c linux.13p4/drivers/char/tuner.c
--- linux.vanilla/drivers/char/tuner.c	Sat Aug 14 02:26:48 1999
+++ linux.13p4/drivers/char/tuner.c	Wed Sep  1 13:53:06 1999
@@ -84,9 +84,11 @@
 	      //  16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,0xc2,623},
 	        16*170.00,16*450.00,0x02,0x04,0x01,0x8e,0xc2,623},
 	{"Temic 4036 FY5 NTSC", TEMIC, NTSC,
-	        16*157.25,16*463.25,0xa0,0x90,0x30,0x8e,0xc2,732},
-        {"Alps HSBH1", TEMIC, NTSC,
-                16*137.25,16*385.25,0x01,0x02,0x08,0x8e,0xc2,732},
+		16*157.25,16*463.25,0xa0,0x90,0x30,0x8e,0xc2,732},
+	{"Alps TSBH1",TEMIC,NTSC,
+		16*137.25,16*385.25,0x01,0x02,0x08,0x8e,0xc2,732},
+	{"Alps TSBE1",TEMIC,PAL,
+		16*137.25,16*385.25,0x01,0x02,0x08,0x8e,0xc2,732},
 };
 
 /* ---------------------------------------------------------------------- */
@@ -192,12 +194,13 @@
 
 	/*
 	 *	For now we only try and attach these tuners to the BT848
-	 *	bus. This same module will however work different species
-	 *	of card using these chips. Just change the constraints
+	 *	or ZORAN bus. This same module will however work different
+	 *	species	of card using these chips. Just change the constraints
 	 *	(i2c doesn't have a totally clash free 'address' space)
 	 */
 	 
-	if(device->bus->id!=I2C_BUSID_BT848)
+	if(device->bus->id!=I2C_BUSID_BT848 &&
+	   device->bus->id!=I2C_BUSID_ZORAN)
 		return -EINVAL;
 		
 	device->data = t = kmalloc(sizeof(struct tuner),GFP_KERNEL);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/char/videodev.c linux.13p4/drivers/char/videodev.c
--- linux.vanilla/drivers/char/videodev.c	Sat Aug 14 02:27:18 1999
+++ linux.13p4/drivers/char/videodev.c	Fri Sep  3 13:49:11 1999
@@ -81,6 +81,9 @@
 #ifdef CONFIG_RADIO_CADET
 extern int cadet_init(struct video_init *);
 #endif
+#ifdef CONFIG_RADIO_TRUST
+extern int trust_init(struct video_init *);
+#endif
 #ifdef CONFIG_VIDEO_PMS
 extern int init_pms_cards(struct video_init *);
 #endif
@@ -134,6 +137,9 @@
 #endif
 #ifdef CONFIG_VIDEO_ZORAN
 	{"zoran", init_zoran_cards},
+#endif	
+#ifdef CONFIG_RADIO_TRUST
+	{"Trust", trust_init}, 
 #endif	
 	{"end", NULL}
 };
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/3c509.c linux.13p4/drivers/net/3c509.c
--- linux.vanilla/drivers/net/3c509.c	Sat Aug 14 02:26:15 1999
+++ linux.13p4/drivers/net/3c509.c	Wed Sep  1 13:52:50 1999
@@ -226,9 +226,6 @@
 				 * detected and is enabled
 				 */
 
-				printk("3c509: found %s at slot %d\n",
-					el3_mca_adapters[j].name, slot + 1 );
-
 				pos4 = mca_read_stored_pos( slot, 4 );
 				pos5 = mca_read_stored_pos( slot, 5 );
 
@@ -241,6 +238,9 @@
 					slot++;         /* probing next slot */
 					continue;
 				}
+
+				printk("3c509: found %s at slot %d\n",
+					el3_mca_adapters[j].name, slot + 1 );
 
 				/* claim the slot */
 				mca_set_adapter_name(slot, el3_mca_adapters[j].name);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/arcnet.c linux.13p4/drivers/net/arcnet.c
--- linux.vanilla/drivers/net/arcnet.c	Sat Aug 14 02:27:28 1999
+++ linux.13p4/drivers/net/arcnet.c	Wed Sep  1 13:52:50 1999
@@ -472,7 +472,7 @@
 #ifdef CONFIG_ARCNET_1051
   /* Initialize the RFC1051-encap protocol driver */
   lp->sdev=(struct device *)kmalloc(sizeof(struct device)+10,GFP_KERNEL);
-  if(lp->sdev = NULL)
+  if(lp->sdev == NULL)
   {
   	if(lp->edev)
   		kfree(lp->edev);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/atp.c linux.13p4/drivers/net/atp.c
--- linux.vanilla/drivers/net/atp.c	Fri Nov 20 16:44:06 1998
+++ linux.13p4/drivers/net/atp.c	Fri Sep  3 12:30:12 1999
@@ -184,7 +184,7 @@
 	/* IRQEN=0, SLCTB=high INITB=high, AUTOFDB=high, STBB=high. */
 	outb(0x04, ioaddr + PAR_CONTROL);
 	write_reg_high(ioaddr, CMR1, CMR1h_RESET);
-	eeprom_delay(2048);
+	udelay(100);
 	status = read_nibble(ioaddr, CMR1);
 
 	if ((status & 0x78) != 0x08) {
@@ -299,12 +299,12 @@
 	while (--num_bits >= 0) {
 		char outval = test_bit(num_bits, &cmd) ? EE_DATA_WRITE : 0;
 		write_reg_high(ioaddr, PROM_CMD, outval | EE_CLK_LOW);
-		eeprom_delay(5);
+		udelay(5);
 		write_reg_high(ioaddr, PROM_CMD, outval | EE_CLK_HIGH);
 		eedata_out <<= 1;
 		if (read_nibble(ioaddr, PROM_DATA) & EE_DATA_READ)
 			eedata_out++;
-		eeprom_delay(5);
+		udelay(5);
 	}
 	write_reg_high(ioaddr, PROM_CMD, EE_CLK_LOW & ~EE_CS);
 	return eedata_out;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/atp.h linux.13p4/drivers/net/atp.h
--- linux.vanilla/drivers/net/atp.h	Sun Feb  2 13:18:36 1997
+++ linux.13p4/drivers/net/atp.h	Fri Sep  3 12:29:20 1999
@@ -261,10 +261,6 @@
 #define EE_DATA_WRITE	0x01	/* EEPROM chip data in. */
 #define EE_DATA_READ	0x08	/* EEPROM chip data out. */
 
-/* Delay between EEPROM clock transitions. */
-#define eeprom_delay(ticks) \
-do { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
-
 /* The EEPROM commands include the alway-set leading bit. */
 #define EE_WRITE_CMD(offset)	(((5 << 6) + (offset)) << 17)
 #define EE_READ(offset) 	(((6 << 6) + (offset)) << 17)
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/e2100.c linux.13p4/drivers/net/e2100.c
--- linux.vanilla/drivers/net/e2100.c	Wed Dec 16 21:35:49 1998
+++ linux.13p4/drivers/net/e2100.c	Wed Sep  1 13:52:50 1999
@@ -75,7 +75,7 @@
 {
 	/* This is a little weird: set the shared memory window by doing a
 	   read.  The low address bits specify the starting page. */
-	mem_base[start_page];
+	readb(mem_base+start_page);
 	inb(port + E21_MEM_ENABLE);
 	outb(E21_MEM_ON, port + E21_MEM_ENABLE + E21_MEM_ON);
 }
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/eepro.c linux.13p4/drivers/net/eepro.c
--- linux.vanilla/drivers/net/eepro.c	Thu Jan  7 16:47:54 1999
+++ linux.13p4/drivers/net/eepro.c	Wed Sep  1 13:52:50 1999
@@ -23,6 +23,7 @@
 	This is a compatibility hardware problem.
 
 	Versions:
+	0.11e   some tweaks about multiple cards support (PdP, jul/aug 1999)
 	0.11d	added __initdata, __initfunc stuff; call spin_lock_init
 	        in eepro_probe1. Replaced "eepro" by dev->name. Augmented 
 		the code protected by spin_lock in interrupt routine 
@@ -1663,17 +1664,10 @@
 #else
   0x200,  /* Why? */
 #endif
-  -1, -1, -1, -1, -1, -1, -1};
-static int irq[MAX_EEPRO] = {0, 0, 0, 0, 0, 0, 0, 0};
+  [1 ... MAX_EEPRO - 1] = -1 };
+static int irq[MAX_EEPRO] = { [0 ... MAX_EEPRO-1] = 0 };
 static int mem[MAX_EEPRO] = {	/* Size of the rx buffer in KB */
-  (RCV_RAM/1024),
-  (RCV_RAM/1024),
-  (RCV_RAM/1024),
-  (RCV_RAM/1024),
-  (RCV_RAM/1024),
-  (RCV_RAM/1024),
-  (RCV_RAM/1024),
-  (RCV_RAM/1024)
+  [0 ... MAX_EEPRO-1] = RCV_RAM/1024
 };
 
 static int n_eepro = 0;
@@ -1681,9 +1675,9 @@
 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
 MODULE_AUTHOR("Pascal Dupuis <dupuis@lei.ucl.ac.be> for the 2.1 stuff (locking,...)");
 MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
-MODULE_PARM(io, "i");
-MODULE_PARM(irq, "i");
-MODULE_PARM(mem, "i");
+MODULE_PARM(io, "1-" __MODULE_STRING(MAX_EEPRO) "i");
+MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_EEPRO) "i");
+MODULE_PARM(mem, "1-" __MODULE_STRING(MAX_EEPRO) "i");
 #endif 
 
 int 
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/sb1000.c linux.13p4/drivers/net/sb1000.c
--- linux.vanilla/drivers/net/sb1000.c	Sat Aug 28 20:00:57 1999
+++ linux.13p4/drivers/net/sb1000.c	Wed Sep  1 13:52:59 1999
@@ -913,6 +913,7 @@
 	/* datagram completed: send to upper level */
 	skb_trim(skb, dlen);
 	netif_rx(skb);
+	stats->rx_bytes+=dlen;
 	stats->rx_packets++;
 	lp->rx_bytes += dlen;
 	lp->rx_skb[ns] = 0;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/sis900.c linux.13p4/drivers/net/sis900.c
--- linux.vanilla/drivers/net/sis900.c	Sat Aug 28 20:00:57 1999
+++ linux.13p4/drivers/net/sis900.c	Fri Sep  3 12:32:23 1999
@@ -585,7 +585,7 @@
         tp = kmalloc(sizeof(*tp), GFP_KERNEL | GFP_DMA);
         if(tp==NULL)
         {
-        	releaseregion(ioaddr, pci_tbl[chip_idx].io_size);
+        	release_region(ioaddr, pci_tbl[chip_idx].io_size);
         	return NULL;
         }
         memset(tp, 0, sizeof(*tp));
@@ -969,6 +969,7 @@
         outl(TxATP | (TX_DMA_BURST << 20) | (TX_FIFO_THRESH<<8) | TxDRNT_10,
                                                 ioaddr + txcfg);
         if (sis900_debug > 1)
+        {
         	if (tp->LinkOn) {
         		printk(KERN_INFO"%s: Media Type %s%s-duplex.\n",
                                 dev->name,
@@ -976,8 +977,11 @@
 					"100mbps " : "10mbps ",
                                 tp->full_duplex== FDX_CAPABLE_FULL_SELECTED ?
 					"full" : "half");
-		} else {
+		}
+		else
+		{
 			printk(KERN_INFO"%s: Media Link Off\n", dev->name);
+		}
 	}
         set_rx_mode(dev);
 
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/tlan.c linux.13p4/drivers/net/tlan.c
--- linux.vanilla/drivers/net/tlan.c	Sat Aug 14 02:25:40 1999
+++ linux.13p4/drivers/net/tlan.c	Wed Sep  1 13:52:50 1999
@@ -2528,13 +2528,13 @@
 
 	for ( i = ( 0x1 << ( num_bits - 1 ) ); i; i >>= 1 ) {
 		TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
-		TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
+		(void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
 		if ( data & i )
 			TLan_SetBit( TLAN_NET_SIO_MDATA, sio );
 		else
 			TLan_ClearBit( TLAN_NET_SIO_MDATA, sio );
 		TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
-		TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
+		(void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
 	}
 
 } /* TLan_MiiSendData */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/net/via-rhine.c linux.13p4/drivers/net/via-rhine.c
--- linux.vanilla/drivers/net/via-rhine.c	Sat Aug 14 02:27:30 1999
+++ linux.13p4/drivers/net/via-rhine.c	Wed Sep  1 13:52:59 1999
@@ -1056,6 +1056,7 @@
 				np->rx_skbuff[entry] = NULL;
 			}
 			skb->protocol = eth_type_trans(skb, dev);
+			np->stats.rx_bytes+=skb->len;
 			netif_rx(skb);
 			dev->last_rx = jiffies;
 			np->stats.rx_packets++;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/pci/pci.c linux.13p4/drivers/pci/pci.c
--- linux.vanilla/drivers/pci/pci.c	Sat Aug 14 02:27:30 1999
+++ linux.13p4/drivers/pci/pci.c	Wed Sep  1 13:53:28 1999
@@ -178,10 +178,8 @@
 
 		if (pcibios_read_config_dword(bus->number, devfn, PCI_VENDOR_ID, &l) ||
 		    /* some broken boards return 0 if a slot is empty: */
-		    l == 0xffffffff || l == 0x00000000 || l == 0x0000ffff || l == 0xffff0000) {
-			is_multi = 0;
+		    l == 0xffffffff || l == 0x00000000 || l == 0x0000ffff || l == 0xffff0000)
 			continue;
-		}
 
 		dev = kmalloc(sizeof(*dev), GFP_ATOMIC);
 		if(dev==NULL)
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/scsi/ChangeLog.ips linux.13p4/drivers/scsi/ChangeLog.ips
--- linux.vanilla/drivers/scsi/ChangeLog.ips	Thu Jan  1 01:00:00 1970
+++ linux.13p4/drivers/scsi/ChangeLog.ips	Thu Aug 19 04:07:25 1999
@@ -0,0 +1,25 @@
+Change Log
+~~~~~~~~~~
+
+	1.00.00 - Initial Public Release
+		- Functionally equivalent to 0.99.05
+
+        0.99.05 - Fix an oops on certain passthru commands
+
+	0.99.04 - Fix race condition in the passthru mechanism
+                  -- this required the interface to the utilities to change
+		- Fix error recovery code
+
+	0.99.03 - Make interrupt routine handle all completed request on the
+		  adapter not just the first one
+		- Make sure passthru commands get woken up if we run out of
+		  SCBs
+		- Send all of the commands on the queue at once rather than
+		  one at a time since the card will support it.
+
+	0.99.02 - Added some additional debug statements to print out
+                  errors if an error occurs while trying to read/write
+                  to a logical drive (IPS_DEBUG).
+
+                  Fixed read/write errors when the adapter is using an
+                  8K stripe size.
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/scsi/Config.in linux.13p4/drivers/scsi/Config.in
--- linux.vanilla/drivers/scsi/Config.in	Sat Aug 28 20:00:57 1999
+++ linux.13p4/drivers/scsi/Config.in	Fri Sep  3 14:15:06 1999
@@ -30,6 +30,7 @@
     bool '   Collect statistics to report in /proc' CONFIG_AIC7XXX_PROC_STATS N
     int  '   Delay in seconds after SCSI bus reset' CONFIG_AIC7XXX_RESET_DELAY 5
 fi
+dep_tristate 'IBM ServeRAID support' CONFIG_SCSI_IPS $CONFIG_SCSI
 dep_tristate 'AdvanSys SCSI support' CONFIG_SCSI_ADVANSYS $CONFIG_SCSI
 dep_tristate 'Always IN2000 SCSI support' CONFIG_SCSI_IN2000 $CONFIG_SCSI
 dep_tristate 'AM53/79C974 PCI SCSI support' CONFIG_SCSI_AM53C974 $CONFIG_SCSI
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/scsi/Makefile linux.13p4/drivers/scsi/Makefile
--- linux.vanilla/drivers/scsi/Makefile	Sat Aug 14 02:26:16 1999
+++ linux.13p4/drivers/scsi/Makefile	Fri Sep  3 14:15:06 1999
@@ -346,6 +346,14 @@
   endif
 endif
 
+ifeq ($(CONFIG_SCSI_IPS),y)
+L_OBJS += ips.o
+else
+  ifeq ($(CONFIG_SCSI_IPS),m)
+  M_OBJS += ips.o
+  endif
+endif
+
 ifeq ($(CONFIG_SCSI_DC390T),y)
 L_OBJS += tmscsim.o
 else
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/scsi/hosts.c linux.13p4/drivers/scsi/hosts.c
--- linux.vanilla/drivers/scsi/hosts.c	Sat Aug 28 20:00:57 1999
+++ linux.13p4/drivers/scsi/hosts.c	Fri Sep  3 14:15:06 1999
@@ -131,6 +131,10 @@
 #include "aic7xxx.h"
 #endif
 
+#ifdef CONFIG_SCSI_IPS
+#include "ips.h"
+#endif
+
 #ifdef CONFIG_SCSI_BUSLOGIC
 #include "BusLogic.h"
 #endif
@@ -467,6 +471,9 @@
 #endif
 #ifdef CONFIG_SCSI_AIC7XXX
     AIC7XXX,
+#endif
+#ifdef CONFIG_SCSI_IPS
+    IPS,
 #endif
 #ifdef CONFIG_SCSI_FD_MCS
    FD_MCS,
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/scsi/ips.c linux.13p4/drivers/scsi/ips.c
--- linux.vanilla/drivers/scsi/ips.c	Thu Jan  1 01:00:00 1970
+++ linux.13p4/drivers/scsi/ips.c	Fri Sep  3 14:15:06 1999
@@ -0,0 +1,3940 @@
+/*****************************************************************************/
+/* ips.c -- driver for the IBM ServeRAID controller                          */
+/*                                                                           */
+/* Written By: Keith Mitchell, IBM Corporation                               */
+/*                                                                           */
+/* Copyright (C) 1999 IBM Corporation                                        */
+/*                                                                           */
+/* 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.                              */
+/*                                                                           */
+/* NO WARRANTY                                                               */
+/* THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR        */
+/* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT      */
+/* LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,      */
+/* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is    */
+/* solely responsible for determining the appropriateness of using and       */
+/* distributing the Program and assumes all risks associated with its        */
+/* exercise of rights under this Agreement, including but not limited to     */
+/* the risks and costs of program errors, damage to or loss of data,         */
+/* programs or equipment, and unavailability or interruption of operations.  */
+/*                                                                           */
+/* DISCLAIMER OF LIABILITY                                                   */
+/* NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY   */
+/* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL        */
+/* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND   */
+/* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR     */
+/* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE    */
+/* USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED  */
+/* HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES             */
+/*                                                                           */
+/* 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 */
+/*                                                                           */
+/* Bugs/Comments/Suggestions should be mailed to:                            */
+/*      ipslinux@us.ibm.com                                                  */
+/*                                                                           */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* Change Log                                                                */
+/*                                                                           */
+/* 0.99.02  - Breakup commands that are bigger than 8 * the stripe size      */
+/* 0.99.03  - Make interrupt routine handle all completed request on the     */
+/*            adapter not just the first one                                 */
+/*          - Make sure passthru commands get woken up if we run out of      */
+/*            SCBs                                                           */
+/*          - Send all of the commands on the queue at once rather than      */
+/*            one at a time since the card will support it.                  */
+/* 0.99.04  - Fix race condition in the passthru mechanism -- this required  */
+/*            the interface to the utilities to change                       */
+/*          - Fix error recovery code                                        */
+/* 0.99.05  - Fix an oops when we get certain passthru commands              */
+/* 1.00.00  - Initial Public Release                                         */
+/*            Functionally equivalent to 0.99.05                             */
+/*                                                                           */
+/*****************************************************************************/
+
+/*
+ * Conditional Compilation directives for this driver:
+ *
+ * NO_IPS_RESET         - Don't reset the controller (no matter what)
+ * IPS_DEBUG            - More verbose error messages
+ * IPS_PCI_PROBE_DEBUG  - Print out more detail on the PCI probe
+ *
+ */
+
+#if defined (MODULE)
+   #include <linux/module.h>
+#endif /* MODULE */
+
+#include <asm/io.h>
+#include <asm/byteorder.h>
+#include <linux/stddef.h>
+#include <linux/version.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/ioport.h>
+#include <linux/malloc.h>
+#include <linux/delay.h>
+#include <linux/sched.h>
+#include <linux/pci.h>
+#include <linux/proc_fs.h>
+
+#include <linux/blk.h>
+#include <linux/types.h>
+
+#ifndef NO_IPS_CMDLINE
+#include <scsi/sg.h>
+#endif
+
+#include "sd.h"
+#include "scsi.h"
+#include "hosts.h"
+#include "ips.h"
+
+#include <linux/stat.h>
+#include <linux/malloc.h>
+#include <linux/config.h>
+#include <asm/spinlock.h>
+#include <linux/smp.h>
+
+/*
+ * DRIVER_VER
+ */
+#define IPS_VERSION_HIGH        "1.00"  /* MUST be 4 chars */
+#define IPS_VERSION_LOW         ".00 "  /* MUST be 4 chars */
+
+struct proc_dir_entry proc_scsi_ips = {
+#if !defined(PROC_SCSI_IPS)
+   0,                                /* Use dynamic inode allocation */
+#else
+   PROC_SCSI_IPS,
+#endif
+   3, "ips",
+   S_IFDIR | S_IRUGO | S_IXUGO, 2
+};
+
+#if LINUX_VERSION_CODE < LinuxVersionCode(2,1,93)
+   #include <linux/bios32.h>
+#endif
+
+#if !defined(__i386__)
+   #error "This driver has only been tested on the x86 platform"
+#endif
+
+#if LINUX_VERSION_CODE < LinuxVersionCode(2,2,0)
+   #error "This driver only works with kernel 2.2.0 and later"
+#endif
+
+#if !defined(NO_IPS_CMDLINE) && ((SG_BIG_BUFF < 8192) || !defined(SG_BIG_BUFF))
+   #error "To use the command-line interface you need to define SG_BIG_BUFF"
+#endif
+
+#if IPS_DEBUG >= 12
+   #define DBG(s)       printk(KERN_NOTICE s "\n"); MDELAY(2*ONE_SEC)
+#elif IPS_DEBUG >= 11
+   #define DBG(s)       printk(KERN_NOTICE s "\n")
+#else
+   #define DBG(s)
+#endif
+
+/*
+ * global variables
+ */
+static const char * ips_name = "ips";
+static struct Scsi_Host * ips_sh[IPS_MAX_ADAPTERS];  /* Array of host controller structures */
+static ips_ha_t * ips_ha[IPS_MAX_ADAPTERS];          /* Array of HA structures */
+static unsigned int ips_num_controllers = 0;
+static int          ips_cmd_timeout = 60;
+static int          ips_reset_timeout = 60 * 5;
+
+#define MAX_ADAPTER_NAME 6
+
+static char ips_adapter_name[][30] = {
+   "ServeRAID",
+   "ServeRAID II",
+   "ServeRAID on motherboard",
+   "ServeRAID on motherboard",
+   "ServeRAID 3H",
+   "ServeRAID 3L"
+};
+
+/*
+ * Function prototypes
+ */
+int ips_detect(Scsi_Host_Template *);
+int ips_release(struct Scsi_Host *);
+int ips_abort(Scsi_Cmnd *);
+int ips_reset(Scsi_Cmnd *, unsigned int);
+int ips_eh_abort(Scsi_Cmnd *);
+int ips_eh_reset(Scsi_Cmnd *);
+int ips_queue(Scsi_Cmnd *, void (*) (Scsi_Cmnd *));
+int ips_biosparam(Disk *, kdev_t, int *);
+const char * ips_info(struct Scsi_Host *);
+void do_ipsintr(int, void *, struct pt_regs *);
+static int ips_hainit(ips_ha_t *);
+static int ips_map_status(ips_scb_t *, ips_stat_t *);
+static int ips_send(ips_ha_t *, ips_scb_t *, scb_callback);
+static int ips_send_wait(ips_ha_t *, ips_scb_t *, int);
+static int ips_send_cmd(ips_ha_t *, ips_scb_t *);
+static int ips_chkstatus(ips_ha_t *);
+static int ips_online(ips_ha_t *, ips_scb_t *);
+static int ips_inquiry(ips_ha_t *, ips_scb_t *);
+static int ips_rdcap(ips_ha_t *, ips_scb_t *);
+static int ips_msense(ips_ha_t *, ips_scb_t *);
+static int ips_reqsen(ips_ha_t *, ips_scb_t *);
+static int ips_allocatescbs(ips_ha_t *);
+static int ips_reset_adapter(ips_ha_t *);
+static int ips_statupd(ips_ha_t *);
+static int ips_issue(ips_ha_t *, ips_scb_t *);
+static int ips_isintr(ips_ha_t *);
+static int ips_wait(ips_ha_t *, int, int);
+static int ips_write_driver_status(ips_ha_t *);
+static int ips_read_adapter_status(ips_ha_t *);
+static int ips_read_subsystem_parameters(ips_ha_t *);
+static int ips_read_config(ips_ha_t *);
+static int ips_clear_adapter(ips_ha_t *);
+static int ips_readwrite_page5(ips_ha_t *, int);
+static void ips_intr(ips_ha_t *);
+static void ips_next(ips_ha_t *);
+static void ipsintr_blocking(ips_ha_t *, struct ips_scb *);
+static void ipsintr_done(ips_ha_t *, struct ips_scb *);
+static void ips_done(ips_ha_t *, ips_scb_t *);
+static void ips_free(ips_ha_t *);
+static void ips_init_scb(ips_ha_t *, ips_scb_t *);
+static void ips_freescb(ips_ha_t *, ips_scb_t *);
+static void ips_statinit(ips_ha_t *);
+static ips_scb_t * ips_getscb(ips_ha_t *);
+static inline void ips_putq_scb_head(ips_scb_queue_t *, ips_scb_t *);
+static inline void ips_putq_scb_tail(ips_scb_queue_t *, ips_scb_t *);
+static inline ips_scb_t * ips_removeq_scb_head(ips_scb_queue_t *);
+static inline ips_scb_t * ips_removeq_scb(ips_scb_queue_t *, ips_scb_t *);
+static inline void ips_putq_wait_head(ips_wait_queue_t *, Scsi_Cmnd *);
+static inline void ips_putq_wait_tail(ips_wait_queue_t *, Scsi_Cmnd *);
+static inline Scsi_Cmnd * ips_removeq_wait_head(ips_wait_queue_t *);
+static inline Scsi_Cmnd * ips_removeq_wait(ips_wait_queue_t *, Scsi_Cmnd *);
+
+#ifndef NO_IPS_CMDLINE
+static int ips_is_passthru(Scsi_Cmnd *);
+static int ips_make_passthru(ips_ha_t *, Scsi_Cmnd *, ips_scb_t *);
+static int ips_usrcmd(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
+#endif
+
+int  ips_proc_info(char *, char **, off_t, int, int, int);
+static int ips_host_info(ips_ha_t *, char *, off_t, int);
+static void copy_mem_info(INFOSTR *, char *, int);
+static int copy_info(INFOSTR *, char *, ...);
+
+/*--------------------------------------------------------------------------*/
+/* Exported Functions                                                       */
+/*--------------------------------------------------------------------------*/
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_detect                                                 */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Detect and initialize the driver                                       */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_detect(Scsi_Host_Template *SHT) {
+   struct Scsi_Host *sh;
+   ips_ha_t         *ha;
+   u32               io_addr;
+   u16               planer;
+   u8                bus;
+   u8                func;
+   u8                irq;
+   int               index;
+   struct pci_dev   *dev = NULL;
+
+   DBG("ips_detect");
+
+   SHT->proc_info = ips_proc_info;
+   SHT->proc_dir = &proc_scsi_ips;
+
+#if defined(CONFIG_PCI)
+
+   /* initalize number of controllers */
+   ips_num_controllers = 0;
+
+   if (!pci_present())
+      return (0);
+
+   for (index = 0; index < IPS_MAX_ADAPTERS; index++) {
+
+      if (!(dev = pci_find_device(IPS_VENDORID, IPS_DEVICEID, dev)))
+         break;
+
+      /* stuff that we get in dev */
+      irq = dev->irq;
+      bus = dev->bus->number;
+      func = dev->devfn;
+      io_addr = dev->base_address[0];
+
+      /* get planer status */
+      if (pci_read_config_word(dev, 0x04, &planer)) {
+         printk(KERN_WARNING "(%s%d) can't get planer status.\n",
+                ips_name, index);
+
+         continue;
+      }
+
+      /* check I/O address */
+      if ((io_addr & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_IO)
+         continue;
+
+      /* check to see if an onboard planer controller is disabled */
+      if (!(planer & 0x000C)) {
+
+   #ifdef IPS_PCI_PROBE_DEBUG
+         printk(KERN_NOTICE "(%s%d) detect, Onboard ServeRAID disabled by BIOS\n",
+                ips_name, index);
+   #endif
+
+         continue;
+      }
+
+      /* get the BASE IO Address */
+      io_addr &= PCI_BASE_ADDRESS_IO_MASK;
+
+   #ifdef IPS_PCI_PROBE_DEBUG
+      printk(KERN_NOTICE "(%s%d) detect bus %d, func %x, irq %d, io %x\n",
+             ips_name, index, bus, func, irq, io_addr);
+   #endif
+
+      /* found a controller */
+      sh = scsi_register(SHT, sizeof(ips_ha_t));
+
+      if (sh == NULL) {
+         printk(KERN_WARNING "(%s%d) Unable to register controller with SCSI subsystem - skipping controller\n",
+                ips_name, index);
+
+         continue;
+      }
+
+      ha = HA(sh);
+      memset(ha, 0, sizeof(ips_ha_t));
+
+      /* Initialize spin lock */
+      spin_lock_init(&ha->scb_lock);
+      spin_lock_init(&ha->copp_lock);
+
+      ips_sh[ips_num_controllers] = sh;
+      ips_ha[ips_num_controllers] = ha;
+      ips_num_controllers++;
+      ha->active = 1;
+
+      ha->enq = kmalloc(sizeof(ENQCMD), GFP_KERNEL|GFP_DMA);
+
+      if (!ha->enq) {
+         printk(KERN_WARNING "(%s%d) Unable to allocate host inquiry structure - skipping contoller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      ha->adapt = kmalloc(sizeof(ADAPTER_AREA), GFP_KERNEL|GFP_DMA);
+
+      if (!ha->adapt) {
+         printk(KERN_WARNING "(%s%d) Unable to allocate host adapt structure - skipping controller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      ha->conf = kmalloc(sizeof(CONFCMD), GFP_KERNEL|GFP_DMA);
+
+      if (!ha->conf) {
+         printk(KERN_WARNING "(%s%d) Unable to allocate host conf structure - skipping controller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      ha->nvram = kmalloc(sizeof(NVRAM_PAGE5), GFP_KERNEL|GFP_DMA);
+
+      if (!ha->nvram) {
+         printk(KERN_WARNING "(%s%d) Unable to allocate host nvram structure - skipping controller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      ha->subsys = kmalloc(sizeof(SUBSYS_PARAM), GFP_KERNEL|GFP_DMA);
+
+      if (!ha->subsys) {
+         printk(KERN_WARNING "(%s%d) Unable to allocate host subsystem structure - skipping controller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      ha->dummy = kmalloc(sizeof(BASIC_IO_CMD), GFP_KERNEL|GFP_DMA);
+
+      if (!ha->dummy) {
+         printk(KERN_WARNING "(%s%d) Unable to allocate host dummy structure - skipping controller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      /* Store away needed values for later use */
+      sh->io_port = io_addr;
+      sh->n_io_port = 255;
+      sh->unique_id = io_addr;
+      sh->irq = irq;
+      sh->select_queue_depths = NULL;
+      sh->sg_tablesize = sh->hostt->sg_tablesize;
+      sh->can_queue = sh->hostt->can_queue;
+      sh->cmd_per_lun = sh->hostt->cmd_per_lun;
+      sh->unchecked_isa_dma = sh->hostt->unchecked_isa_dma;
+      sh->use_clustering = sh->hostt->use_clustering;
+      sh->wish_block = FALSE;
+
+      /* Store info in HA structure */
+      ha->io_addr = io_addr;
+      ha->irq = irq;
+      ha->host_num = index;
+
+      /* install the interrupt handler */
+      if (request_irq(irq, do_ipsintr, SA_SHIRQ, ips_name, ha)) {
+         printk(KERN_WARNING "(%s%d) unable to install interrupt handler - skipping controller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      /*
+       * Allocate a temporary SCB for initialization
+       */
+      ha->scbs = (ips_scb_t *) kmalloc(sizeof(ips_scb_t), GFP_KERNEL|GFP_DMA);
+      if (!ha->scbs) {
+         /* couldn't allocate a temp SCB */
+         printk(KERN_WARNING "(%s%d) unable to allocate CCBs - skipping contoller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      memset(ha->scbs, 0, sizeof(ips_scb_t));
+      ha->scbs->sg_list = (SG_LIST *) kmalloc(sizeof(SG_LIST) * MAX_SG_ELEMENTS, GFP_KERNEL|GFP_DMA);
+      if (!ha->scbs->sg_list) {
+         /* couldn't allocate a temp SCB S/G list */
+         printk(KERN_WARNING "(%s%d) unable to allocate CCBs - skipping contoller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      ha->max_cmds = 1;
+
+      if (!ips_hainit(ha)) {
+         printk(KERN_WARNING "(%s%d) unable to initialize controller - skipping\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      /*
+       * Free the temporary SCB
+       */
+      kfree(ha->scbs->sg_list);
+      kfree(ha->scbs);
+      ha->scbs = NULL;
+
+      /* allocate CCBs */
+      if (!ips_allocatescbs(ha)) {
+         printk(KERN_WARNING "(%s%d) unable to allocate CCBs - skipping contoller\n",
+                ips_name, index);
+
+         ha->active = 0;
+
+         continue;
+      }
+
+      /* finish setting values */
+      sh->max_id = ha->ntargets;
+      sh->max_lun = ha->nlun;
+      sh->max_channel = ha->nbus;
+      sh->can_queue = ha->max_cmds-1;
+   } /* end for */
+
+   return (ips_num_controllers);
+
+#else
+
+   /* No PCI -- No ServeRAID */
+   return (0);
+#endif /* CONFIG_PCI */
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_release                                                */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Remove a driver                                                        */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_release(struct Scsi_Host *sh) {
+   ips_scb_t *scb;
+   ips_ha_t  *ha;
+   int        i;
+
+   DBG("ips_release");
+
+   for (i = 0; i < IPS_MAX_ADAPTERS && ips_sh[i] != sh; i++);
+
+   if (i == IPS_MAX_ADAPTERS)
+      panic("(%s) release, invalid Scsi_Host pointer.\n",
+            ips_name);
+
+   ha = HA(sh);
+
+   if (!ha)
+      return (FALSE);
+
+   /* flush the cache on the controller */
+   scb = &ha->scbs[ha->max_cmds-1];
+
+   ips_init_scb(ha, scb);
+
+   scb->timeout = ips_cmd_timeout;
+   scb->cdb[0] = FLUSH_CACHE;
+
+   scb->cmd.flush_cache.op_code = FLUSH_CACHE;
+   scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
+   scb->cmd.flush_cache.state = NORM_STATE;
+   scb->cmd.flush_cache.reserved = 0;
+   scb->cmd.flush_cache.reserved2 = 0;
+   scb->cmd.flush_cache.reserved3 = 0;
+   scb->cmd.flush_cache.reserved4 = 0;
+
+   printk("(%s%d) Flushing Cache.\n", ips_name, ha->host_num);
+
+   /* send command */
+   if (ips_send_wait(ha, scb, ips_cmd_timeout) == IPS_FAILURE)
+      printk("(%s%d) Incomplete Flush.\n", ips_name, ha->host_num);
+
+   printk("(%s%d) Flushing Complete.\n", ips_name, ha->host_num);
+
+   ips_sh[i] = NULL;
+   ips_ha[i] = NULL;
+
+   /* free extra memory */
+   ips_free(ha);
+
+   /* free IRQ */
+   free_irq(ha->irq, ha);
+
+   /* unregister with SCSI sub system */
+   scsi_unregister(sh);
+
+   return (FALSE);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_eh_abort                                               */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Abort a command (using the new error code stuff)                       */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_eh_abort(Scsi_Cmnd *SC) {
+   ips_ha_t         *ha;
+
+   DBG("ips_eh_abort");
+
+   if (!SC)
+      return (FAILED);
+
+   ha = (ips_ha_t *) SC->host->hostdata;
+
+   if (!ha)
+      return (FAILED);
+
+   if (!ha->active)
+      return (FAILED);
+
+   if (SC->serial_number != SC->serial_number_at_timeout) {
+      /* HMM, looks like a bogus command */
+#if IPS_DEBUG >= 1
+      printk(KERN_NOTICE "Abort called with bogus scsi command\n");
+#endif
+
+      return (FAILED);
+   }
+
+   if (test_and_set_bit(IPS_IN_ABORT, &ha->flags))
+      return (FAILED);
+
+   /* See if the command is on the wait queue */
+   if (ips_removeq_wait(&ha->scb_waitlist, SC) ||
+       ips_removeq_wait(&ha->copp_waitlist, SC)) {
+      /* command not sent yet */
+      clear_bit(IPS_IN_ABORT, &ha->flags);
+
+      return (SUCCESS);
+   } else {
+      /* command must have already been sent */
+      clear_bit(IPS_IN_ABORT, &ha->flags);
+
+      return (FAILED);
+   }
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_abort                                                  */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Abort a command                                                        */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_abort(Scsi_Cmnd *SC) {
+   ips_ha_t         *ha;
+
+   DBG("ips_abort");
+
+   if (!SC)
+      return (SCSI_ABORT_SNOOZE);
+
+   ha = (ips_ha_t *) SC->host->hostdata;
+
+   if (!ha)
+      return (SCSI_ABORT_SNOOZE);
+
+   if (!ha->active)
+      return (SCSI_ABORT_SNOOZE);
+
+   if (SC->serial_number != SC->serial_number_at_timeout) {
+      /* HMM, looks like a bogus command */
+#if IPS_DEBUG >= 1
+      printk(KERN_NOTICE "Abort called with bogus scsi command\n");
+#endif
+
+      return (SCSI_ABORT_NOT_RUNNING);
+   }
+
+   if (test_and_set_bit(IPS_IN_ABORT, &ha->flags))
+      return (SCSI_ABORT_SNOOZE);
+
+   /* See if the command is on the wait queue */
+   if (ips_removeq_wait(&ha->scb_waitlist, SC) ||
+       ips_removeq_wait(&ha->copp_waitlist, SC)) {
+      /* command not sent yet */
+      clear_bit(IPS_IN_ABORT, &ha->flags);
+
+      return (SCSI_ABORT_PENDING);
+   } else {
+      /* command must have already been sent */
+      clear_bit(IPS_IN_ABORT, &ha->flags);
+
+      return (SCSI_ABORT_SNOOZE);
+   }
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_eh_reset                                               */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Reset the controller (with new eh error code)                          */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_eh_reset(Scsi_Cmnd *SC) {
+   ips_ha_t         *ha;
+   ips_scb_t        *scb;
+
+   DBG("ips_eh_reset");
+
+#ifdef NO_IPS_RESET
+   return (FAILED);
+#else
+
+   if (!SC) {
+
+#if IPS_DEBUG >= 1
+      printk(KERN_NOTICE "Reset called with NULL scsi command\n");
+#endif
+
+      return (FAILED);
+   }
+
+   ha = (ips_ha_t *) SC->host->hostdata;
+
+   if (!ha) {
+
+#if IPS_DEBUG >= 1
+      printk(KERN_NOTICE "Reset called with NULL ha struct\n");
+#endif
+
+      return (FAILED);
+   }
+
+   if (!ha->active)
+      return (FAILED);
+
+   if (test_and_set_bit(IPS_IN_RESET, &ha->flags))
+      return (FAILED);
+
+   /* See if the command is on the waiting queue */
+   if (ips_removeq_wait(&ha->scb_waitlist, SC) ||
+       ips_removeq_wait(&ha->copp_waitlist, SC)) {
+      /* command not sent yet */
+      clear_bit(IPS_IN_ABORT, &ha->flags);
+
+      return (SUCCESS);
+   }
+
+   /*
+    * command must have already been sent
+    * reset the controller
+    */
+   if (!ips_reset_adapter(ha)) {
+      clear_bit(IPS_IN_RESET, &ha->flags);
+
+      return (FAILED);
+   }
+
+   if (!ips_clear_adapter(ha)) {
+      clear_bit(IPS_IN_RESET, &ha->flags);
+
+      return (FAILED);
+   }
+
+   /* Now fail all of the active commands */
+#if IPS_DEBUG >= 1
+   printk(KERN_WARNING "(%s%d) Failing active commands\n",
+          ips_name, ha->host_num);
+#endif
+   while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
+      scb->scsi_cmd->result = DID_RESET << 16;
+      scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+      ips_freescb(ha, scb);
+   }
+
+   /* Reset the number of active IOCTLs */
+   ha->num_ioctl = 0;
+
+   clear_bit(IPS_IN_RESET, &ha->flags);
+
+   if (!test_bit(IPS_IN_INTR, &ha->flags)) {
+      /*
+       * Only execute the next command when
+       * we are not being called from the
+       * interrupt handler.  The interrupt
+       * handler wants to do this and since
+       * interrupts are turned off here....
+       */
+      ips_next(ha);
+   }
+
+   return (SUCCESS);
+
+#endif /* NO_IPS_RESET */
+
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_reset                                                  */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Reset the controller                                                   */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_reset(Scsi_Cmnd *SC, unsigned int flags) {
+   ips_ha_t         *ha;
+   ips_scb_t        *scb;
+
+   DBG("ips_reset");
+
+#ifdef NO_IPS_RESET
+   return (SCSI_RESET_SNOOZE);
+#else
+
+   if (!SC) {
+
+#if IPS_DEBUG >= 1
+      printk(KERN_NOTICE "Reset called with NULL scsi command\n");
+#endif
+
+      return (SCSI_RESET_SNOOZE);
+   }
+
+   ha = (ips_ha_t *) SC->host->hostdata;
+
+   if (!ha) {
+
+#if IPS_DEBUG >= 1
+      printk(KERN_NOTICE "Reset called with NULL ha struct\n");
+#endif
+
+      return (SCSI_RESET_SNOOZE);
+   }
+
+   if (!ha->active)
+      return (SCSI_RESET_SNOOZE);
+
+   if (test_and_set_bit(IPS_IN_RESET, &ha->flags))
+      return (SCSI_RESET_SNOOZE);
+
+   /* See if the command is on the waiting queue */
+   if (ips_removeq_wait(&ha->scb_waitlist, SC) ||
+       ips_removeq_wait(&ha->copp_waitlist, SC)) {
+      /* command not sent yet */
+      clear_bit(IPS_IN_ABORT, &ha->flags);
+
+      return (SCSI_RESET_SNOOZE);
+   }
+
+   /* reset the controller */
+   if (!ips_reset_adapter(ha)) {
+      clear_bit(IPS_IN_RESET, &ha->flags);
+
+      return (SCSI_RESET_ERROR);
+   }
+
+   if (!ips_clear_adapter(ha)) {
+      clear_bit(IPS_IN_RESET, &ha->flags);
+
+      return (SCSI_RESET_ERROR);
+   }
+
+   /* Now fail all of the active commands */
+#if IPS_DEBUG >= 1
+   printk(KERN_WARNING "(%s%d) Failing active commands\n",
+          ips_name, ha->host_num);
+#endif
+   while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
+      scb->scsi_cmd->result = DID_RESET << 16;
+      scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+      ips_freescb(ha, scb);
+   }
+
+   /* Reset the number of active IOCTLs */
+   ha->num_ioctl = 0;
+
+   clear_bit(IPS_IN_RESET, &ha->flags);
+
+   if (!test_bit(IPS_IN_INTR, &ha->flags)) {
+      /*
+       * Only execute the next command when
+       * we are not being called from the
+       * interrupt handler.  The interrupt
+       * handler wants to do this and since
+       * interrupts are turned off here....
+       */
+      ips_next(ha);
+   }
+
+   return (SCSI_RESET_SUCCESS);
+
+#endif /* NO_IPS_RESET */
+
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_queue                                                  */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Send a command to the controller                                       */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_queue(Scsi_Cmnd *SC, void (*done) (Scsi_Cmnd *)) {
+   ips_ha_t         *ha;
+
+   DBG("ips_queue");
+
+   ha = (ips_ha_t *) SC->host->hostdata;
+
+   if (!ha)
+      return (1);
+
+   if (!ha->active)
+      return (1);
+
+#ifndef NO_IPS_CMDLINE
+   if (ips_is_passthru(SC)) {
+      if (ha->copp_waitlist.count == IPS_MAX_IOCTL_QUEUE) {
+         SC->result = DID_BUS_BUSY << 16;
+         done(SC);
+
+         return (0);
+      }
+   } else {
+#endif
+      if (ha->scb_waitlist.count == IPS_MAX_QUEUE) {
+         SC->result = DID_BUS_BUSY << 16;
+         done(SC);
+
+         return (0);
+      }
+
+#ifndef NO_IPS_CMDLINE
+   }
+#endif
+
+   SC->scsi_done = done;
+
+#if IPS_DEBUG >= 10
+   printk(KERN_NOTICE "%s: ips_queue: cmd 0x%X (%d %d %d)\n",
+          ips_name,
+          SC->cmnd[0],
+          SC->channel,
+          SC->target,
+          SC->lun);
+#if IPS_DEBUG >= 11
+        MDELAY(2*ONE_SEC);
+#endif
+#endif
+
+#ifndef NO_IPS_CMDLINE
+   if (ips_is_passthru(SC))
+      ips_putq_wait_tail(&ha->copp_waitlist, SC);
+   else
+#endif
+      ips_putq_wait_tail(&ha->scb_waitlist, SC);
+
+   if ((!test_bit(IPS_IN_INTR, &ha->flags)) &&
+       (!test_bit(IPS_IN_ABORT, &ha->flags)) &&
+       (!test_bit(IPS_IN_RESET, &ha->flags)))
+      ips_next(ha);
+
+   return (0);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_biosparam                                              */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Set bios geometry for the controller                                   */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_biosparam(Disk *disk, kdev_t dev, int geom[]) {
+   ips_ha_t         *ha;
+   int               heads;
+   int               sectors;
+   int               cylinders;
+
+   DBG("ips_biosparam");
+
+   ha = (ips_ha_t *) disk->device->host->hostdata;
+
+   if (!ha)
+      /* ?!?! host adater info invalid */
+      return (0);
+
+   if (!ha->active)
+      return (0);
+
+   if (!ips_read_adapter_status(ha))
+      /* ?!?! Enquiry command failed */
+      return (0);
+
+   if ((disk->capacity > 0x400000) &&
+       ((ha->enq->ucMiscFlag & 0x8) == 0)) {
+      heads = NORM_MODE_HEADS;
+      sectors = NORM_MODE_SECTORS;
+   } else {
+      heads = COMP_MODE_HEADS;
+      sectors = COMP_MODE_SECTORS;
+   }
+
+   cylinders = disk->capacity / (heads * sectors);
+
+#if IPS_DEBUG >= 2
+   printk(KERN_NOTICE "Geometry: heads: %d, sectors: %d, cylinders: %d\n",
+          heads, sectors, cylinders);
+#endif
+
+   geom[0] = heads;
+   geom[1] = sectors;
+   geom[2] = cylinders;
+
+   return (0);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: do_ipsintr                                                 */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Wrapper for the interrupt handler                                      */
+/*                                                                          */
+/****************************************************************************/
+void
+do_ipsintr(int irq, void *dev_id, struct pt_regs *regs) {
+   ips_ha_t         *ha;
+   unsigned int      cpu_flags;
+
+   DBG("do_ipsintr");
+
+   ha = (ips_ha_t *) dev_id;
+
+   spin_lock_irqsave(&io_request_lock, cpu_flags);
+
+   if (test_and_set_bit(IPS_IN_INTR, &ha->flags)) {
+      spin_unlock_irqrestore(&io_request_lock, cpu_flags);
+
+      return ;
+   }
+
+   if (!ha) {
+      clear_bit(IPS_IN_INTR, &ha->flags);
+      spin_unlock_irqrestore(&io_request_lock, cpu_flags);
+
+      return;
+   }
+
+   if (!ha->active) {
+      clear_bit(IPS_IN_INTR, &ha->flags);
+      spin_unlock_irqrestore(&io_request_lock, cpu_flags);
+
+      return;
+   }
+
+   ips_intr(ha);
+
+   clear_bit(IPS_IN_INTR, &ha->flags);
+
+   spin_unlock_irqrestore(&io_request_lock, cpu_flags);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_intr                                                   */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Polling interrupt handler                                              */
+/*                                                                          */
+/*   ASSUMES interrupts are disabled                                        */
+/*                                                                          */
+/****************************************************************************/
+void
+ips_intr(ips_ha_t *ha) {
+   ips_stat_t       *sp;
+   ips_scb_t        *scb;
+   int               status;
+
+   DBG("ips_intr");
+
+   if (!ha)
+      return;
+
+   if (!ha->active)
+      return;
+
+   while (ips_isintr(ha)) {
+      sp = &ha->sp;
+
+      if ((status = ips_chkstatus(ha)) < 0) {
+         /* unexpected interrupt - no ccb */
+         printk(KERN_WARNING "(%s%d) Spurious interrupt; no ccb.\n",
+                ips_name, ha->host_num);
+         continue ;
+      }
+
+      scb = (ips_scb_t *) sp->scb_addr;
+
+      /*
+       * use the callback function to finish things up
+       * NOTE: interrupts are OFF for this
+       */
+      (*scb->callback) (ha, scb);
+   }
+
+   clear_bit(IPS_IN_INTR, &ha->flags);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_info                                                   */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Return info about the driver                                           */
+/*                                                                          */
+/****************************************************************************/
+const char *
+ips_info(struct Scsi_Host *SH) {
+   static char  buffer[256];
+   char        *bp;
+   ips_ha_t    *ha;
+
+   DBG("ips_info");
+
+   ha = HA(SH);
+
+   if (!ha)
+      return (NULL);
+
+   bp = &buffer[0];
+   memset(bp, 0, sizeof(buffer));
+
+   strcpy(bp, "IBM PCI ServeRAID ");
+   strcat(bp, IPS_VERSION_HIGH);
+   strcat(bp, IPS_VERSION_LOW);
+
+   if (ha->ad_type > 0 &&
+       ha->ad_type <= MAX_ADAPTER_NAME) {
+      strcat(bp, " <");
+      strcat(bp, ips_adapter_name[ha->ad_type-1]);
+      strcat(bp, ">");
+   }
+
+   return (bp);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_proc_info                                              */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   The passthru interface for the driver                                  */
+/*                                                                          */
+/****************************************************************************/
+int
+ips_proc_info(char *buffer, char **start, off_t offset,
+              int length, int hostno, int func) {
+   int           i;
+   int           ret;
+   ips_ha_t     *ha = NULL;
+
+   DBG("ips_proc_info");
+
+   /* Find our host structure */
+   for (i = 0; i < ips_num_controllers; i++) {
+      if (ips_sh[i] && ips_sh[i]->host_no == hostno) {
+         ha = (ips_ha_t *) ips_sh[i]->hostdata;
+
+         break;
+      }
+   }
+
+   if (!ha)
+      return (-EINVAL);
+
+   if (func) {
+      /* write */
+      return (0);
+   } else {
+      /* read */
+      if (start)
+         *start = buffer;
+
+      ret = ips_host_info(ha, buffer, offset, length);
+
+      return (ret);
+   }
+}
+
+/*--------------------------------------------------------------------------*/
+/* Helper Functions                                                         */
+/*--------------------------------------------------------------------------*/
+
+#ifndef NO_IPS_CMDLINE
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_is_passthru                                            */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Determine if the specified SCSI command is really a passthru command   */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_is_passthru(Scsi_Cmnd *SC) {
+   DBG("ips_is_passthru");
+
+   if (!SC)
+      return (0);
+
+   if ((SC->channel == 0) &&
+       (SC->target == IPS_ADAPTER_ID) &&
+       (SC->lun == 0) &&
+       (SC->cmnd[0] == 0x0d) &&
+       (SC->request_bufflen) &&
+       (!SC->use_sg) &&
+       (((char *) SC->request_buffer)[0] == 'C') &&
+       (((char *) SC->request_buffer)[1] == 'O') &&
+       (((char *) SC->request_buffer)[2] == 'P') &&
+       (((char *) SC->request_buffer)[3] == 'P')) {
+      return (1);
+   } else {
+      return (0);
+   }
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_is_passthru                                            */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Make a passthru command out of the info in the Scsi block              */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_make_passthru(ips_ha_t *ha, Scsi_Cmnd *SC, ips_scb_t *scb) {
+   ips_passthru_t *pt;
+
+   DBG("ips_make_passthru");
+
+   if (!SC->request_bufflen || !SC->request_buffer) {
+      /* no data */
+#if IPS_DEBUG_PT >= 1
+      printk(KERN_NOTICE "(%s%d) No passthru structure\n",
+             ips_name, ha->host_num);
+#endif
+
+      return (IPS_FAILURE);
+   }
+
+   if (SC->request_bufflen < sizeof(ips_passthru_t)) {
+      /* wrong size */
+#if IPS_DEBUG_PT >= 1
+      printk(KERN_NOTICE "(%s%d) Passthru structure wrong size\n",
+             ips_name, ha->host_num);
+#endif
+
+      return (IPS_FAILURE);
+   }
+
+   if ((((char *) SC->request_buffer)[0] != 'C') ||
+       (((char *) SC->request_buffer)[1] != 'O') ||
+       (((char *) SC->request_buffer)[2] != 'P') ||
+       (((char *) SC->request_buffer)[3] != 'P')) {
+      /* signature doesn't match */
+#if IPS_DEBUG_PT >= 1
+      printk(KERN_NOTICE "(%s%d) Wrong signature on passthru structure.\n",
+             ips_name, ha->host_num);
+#endif
+
+      return (IPS_FAILURE);
+   }
+
+   pt = (ips_passthru_t *) SC->request_buffer;
+   scb->scsi_cmd = SC;
+
+   if (SC->request_bufflen < (sizeof(ips_passthru_t) + pt->CmdBSize)) {
+      /* wrong size */
+#if IPS_DEBUG_PT >= 1
+      printk(KERN_NOTICE "(%s%d) Passthru structure wrong size\n",
+             ips_name, ha->host_num);
+#endif
+
+      return (IPS_FAILURE);
+   }
+
+   switch (pt->CoppCmd) {
+   case IPS_NUMCTRLS:
+      memcpy(SC->request_buffer + sizeof(ips_passthru_t),
+             &ips_num_controllers, sizeof(int));
+      SC->result = DID_OK << 16;
+
+      return (IPS_SUCCESS_IMM);
+   case IPS_CTRLINFO:
+      memcpy(SC->request_buffer + sizeof(ips_passthru_t),
+             ha, sizeof(ips_ha_t));
+      SC->result = DID_OK << 16;
+
+      return (IPS_SUCCESS_IMM);
+   case COPPUSRCMD:
+      if (ips_usrcmd(ha, pt, scb))
+         return (IPS_SUCCESS);
+      else
+         return (IPS_FAILURE);
+      break;
+   }
+
+   return (IPS_FAILURE);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_usrcmd                                                 */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Process a user command and make it ready to send                       */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_usrcmd(ips_ha_t *ha, ips_passthru_t *pt, ips_scb_t *scb) {
+   SG_LIST        *sg_list;
+
+   DBG("ips_usrcmd");
+
+   if ((!scb) || (!pt) || (!ha))
+      return (0);
+
+   /* Save the S/G list pointer so it doesn't get clobbered */
+   sg_list = scb->sg_list;
+
+   /* copy in the CP */
+   memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof(IOCTL_INFO));
+   memcpy(&scb->dcdb, &pt->CoppCP.dcdb, sizeof(DCDB_TABLE));
+
+   /* FIX stuff that might be wrong */
+   scb->sg_list = sg_list;
+   scb->scb_busaddr = VIRT_TO_BUS(scb);
+   scb->bus = 0;
+   scb->target_id = 0;
+   scb->lun = 0;
+   scb->sg_len = 0;
+   scb->data_len = 0;
+   scb->flags = 0;
+   scb->op_code = 0;
+   scb->callback = ipsintr_done;
+   scb->timeout = ips_cmd_timeout;
+   scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
+
+   /* we don't support DCDB/READ/WRITE Scatter Gather */
+   if ((scb->cmd.basic_io.op_code == READ_SCATTER_GATHER) ||
+       (scb->cmd.basic_io.op_code == WRITE_SCATTER_GATHER) ||
+       (scb->cmd.basic_io.op_code == DIRECT_CDB_SCATTER_GATHER))
+      return (0);
+
+   if (pt->CmdBSize && pt->CmdBuffer) {
+      scb->data_busaddr = VIRT_TO_BUS(scb->scsi_cmd->request_buffer + sizeof(ips_passthru_t));
+   } else {
+      scb->data_busaddr = 0L;
+   }
+
+   if (pt->CmdBSize) {
+      if (scb->cmd.dcdb.op_code == DIRECT_CDB) {
+         scb->cmd.dcdb.dcdb_address = VIRT_TO_BUS(&scb->dcdb);
+         scb->dcdb.buffer_pointer = scb->data_busaddr;
+      } else {
+         scb->cmd.basic_io.sg_addr = scb->data_busaddr;
+      }
+   }
+
+   /* set timeouts */
+   if (pt->TimeOut) {
+      scb->timeout = pt->TimeOut;
+
+      if (pt->TimeOut <= 10)
+         scb->dcdb.cmd_attribute |= TIMEOUT_10;
+      else if (pt->TimeOut <= 60)
+         scb->dcdb.cmd_attribute |= TIMEOUT_60;
+      else
+         scb->dcdb.cmd_attribute |= TIMEOUT_20M;
+   }
+
+   /* assume error */
+   scb->scsi_cmd->result = DID_ERROR << 16;
+
+   /* success */
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_cleanup_passthru                                       */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Cleanup after a passthru command                                       */
+/*                                                                          */
+/****************************************************************************/
+static void
+ips_cleanup_passthru(ips_scb_t *scb) {
+   ips_passthru_t *pt;
+
+   DBG("ips_cleanup_passthru");
+
+   if ((!scb) || (!scb->scsi_cmd) || (!scb->scsi_cmd->request_buffer)) {
+#if IPS_DEBUG_PT >= 1
+      printk(KERN_NOTICE "IPS couldn't cleanup\n");
+#endif
+
+      return ;
+   }
+
+   pt = (ips_passthru_t *) scb->scsi_cmd->request_buffer;
+
+   /* Copy data back to the user */
+   pt->BasicStatus = scb->basic_status;
+   pt->ExtendedStatus = scb->extended_status;
+
+   scb->scsi_cmd->result = DID_OK << 16;
+}
+
+#endif
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_host_info                                              */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   The passthru interface for the driver                                  */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_host_info(ips_ha_t *ha, char *ptr, off_t offset, int len) {
+   INFOSTR info;
+
+   DBG("ips_host_info");
+
+   info.buffer = ptr;
+   info.length = len;
+   info.offset = offset;
+   info.pos = 0;
+
+   copy_info(&info, "\nIBM ServeRAID General Information:\n\n");
+
+   if ((ha->nvram->signature == NVRAM_PAGE5_SIGNATURE) &&
+       (ha->nvram->adapter_type != 0))
+      copy_info(&info, "\tController Type                   : %s\n", ips_adapter_name[ha->ad_type-1]);
+   else
+      copy_info(&info, "\tController Type                   : Unknown\n");
+
+   copy_info(&info, "\tIO port address                   : 0x%lx\n", ha->io_addr);
+   copy_info(&info, "\tIRQ number                        : %d\n", ha->irq);
+
+   if (ha->nvram->signature == NVRAM_PAGE5_SIGNATURE)
+      copy_info(&info, "\tBIOS Version                      : %c%c%c%c%c%c%c%c\n",
+                ha->nvram->bios_high[0], ha->nvram->bios_high[1],
+                ha->nvram->bios_high[2], ha->nvram->bios_high[3],
+                ha->nvram->bios_low[0], ha->nvram->bios_low[1],
+                ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
+
+   copy_info(&info, "\tFirmware Version                  : %c%c%c%c%c%c%c%c\n",
+             ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
+             ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
+             ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
+             ha->enq->CodeBlkVersion[6], ha->enq->CodeBlkVersion[7]);
+
+   copy_info(&info, "\tBoot Block Version                : %c%c%c%c%c%c%c%c\n",
+             ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
+             ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
+             ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
+             ha->enq->BootBlkVersion[6], ha->enq->BootBlkVersion[7]);
+
+   copy_info(&info, "\tDriver Version                    : %s%s\n",
+             IPS_VERSION_HIGH, IPS_VERSION_LOW);
+
+   copy_info(&info, "\tMax Physical Devices              : %d\n",
+             ha->enq->ucMaxPhysicalDevices);
+   copy_info(&info, "\tMax Active Commands               : %d\n",
+             ha->max_cmds);
+   copy_info(&info, "\tCurrent Queued Commands           : %d\n",
+             ha->scb_waitlist.count);
+   copy_info(&info, "\tCurrent Active Commands           : %d\n",
+             ha->scb_activelist.count - ha->num_ioctl);
+   copy_info(&info, "\tCurrent Queued PT Commands        : %d\n",
+             ha->copp_waitlist.count);
+   copy_info(&info, "\tCurrent Active PT Commands        : %d\n",
+             ha->num_ioctl);
+
+   copy_info(&info, "\n");
+
+   return (info.pos > info.offset ? info.pos - info.offset : 0);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: copy_mem_info                                              */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Copy data into an INFOSTR structure                                    */
+/*                                                                          */
+/****************************************************************************/
+static void
+copy_mem_info(INFOSTR *info, char *data, int len) {
+   DBG("copy_mem_info");
+
+   if (info->pos + len > info->length)
+      len = info->length - info->pos;
+
+   if (info->pos + len < info->offset) {
+      info->pos += len;
+      return;
+   }
+
+   if (info->pos < info->offset) {
+      data += (info->offset - info->pos);
+      len  -= (info->offset - info->pos);
+   }
+
+   if (len > 0) {
+      memcpy(info->buffer + info->pos, data, len);
+      info->pos += len;
+   }
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: copy_info                                                  */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   printf style wrapper for an info structure                             */
+/*                                                                          */
+/****************************************************************************/
+static int
+copy_info(INFOSTR *info, char *fmt, ...) {
+   va_list args;
+   char buf[81];
+   int len;
+
+   DBG("copy_info");
+
+   va_start(args, fmt);
+   len = vsprintf(buf, fmt, args);
+   va_end(args);
+
+   copy_mem_info(info, buf, len);
+
+   return (len);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_hainit                                                 */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Initialize the controller                                              */
+/*                                                                          */
+/* NOTE: Assumes to be called from with a lock                              */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_hainit(ips_ha_t *ha) {
+   int       i;
+
+   DBG("ips_hainit");
+
+   if (!ha)
+      return (0);
+
+   /* initialize status queue */
+   ips_statinit(ha);
+
+   /* Setup HBA ID's */
+   if (!ips_read_config(ha)) {
+
+#ifndef NO_IPS_RESET
+
+      /* Try to reset the controller and try again */
+      if (!ips_reset_adapter(ha)) {
+         printk(KERN_WARNING "(%s%d) unable to reset controller.\n",
+                ips_name, ha->host_num);
+
+         return (0);
+      }
+
+      if (!ips_clear_adapter(ha)) {
+         printk(KERN_WARNING "(%s%d) unable to initialize controller.\n",
+                ips_name, ha->host_num);
+
+         return (0);
+      }
+
+#endif
+
+      if (!ips_read_config(ha)) {
+         printk(KERN_WARNING "(%s%d) unable to read config from controller.\n",
+                ips_name, ha->host_num);
+
+         return (0);
+      }
+   } /* end if */
+
+   /* write driver version */
+   if (!ips_write_driver_status(ha)) {
+      printk(KERN_WARNING "(%s%d) unable to write driver info to controller.\n",
+             ips_name, ha->host_num);
+
+      return (0);
+   }
+
+   if (!ips_read_adapter_status(ha)) {
+      printk(KERN_WARNING "(%s%d) unable to read controller status.\n",
+             ips_name, ha->host_num);
+
+      return (0);
+   }
+
+   if (!ips_read_subsystem_parameters(ha)) {
+      printk(KERN_WARNING "(%s%d) unable to read subsystem parameters.\n",
+             ips_name, ha->host_num);
+
+      return (0);
+   }
+
+   /* set limits on SID, LUN, BUS */
+   ha->ntargets = MAX_TARGETS + 1;
+   ha->nlun = 1;
+   ha->nbus = (ha->enq->ucMaxPhysicalDevices / MAX_TARGETS);
+
+   switch (ha->conf->logical_drive[0].ucStripeSize) {
+   case 4:
+      ha->max_xfer = 0x10000;
+      break;
+
+   case 5:
+      ha->max_xfer = 0x20000;
+      break;
+
+   case 6:
+      ha->max_xfer = 0x40000;
+      break;
+
+   case 7:
+   default:
+      ha->max_xfer = 0x80000;
+      break;
+   }
+
+   /* setup max concurrent commands */
+   if (ha->subsys->param[4] & 0x1) {
+      /* Use the new method */
+      ha->max_cmds = ha->enq->ucConcurrentCmdCount;
+   } else {
+      /* use the old method */
+      switch (ha->conf->logical_drive[0].ucStripeSize) {
+      case 4:
+         ha->max_cmds = 32;
+         break;
+
+      case 5:
+         ha->max_cmds = 16;
+         break;
+
+      case 6:
+         ha->max_cmds = 8;
+         break;
+
+      case 7:
+      default:
+         ha->max_cmds = 4;
+         break;
+      }
+   }
+
+   /* set controller IDs */
+   ha->ha_id[0] = IPS_ADAPTER_ID;
+   for (i = 1; i < ha->nbus; i++)
+      ha->ha_id[i] = ha->conf->init_id[i-1] & 0x1f;
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_next                                                   */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Take the next command off the queue and send it to the controller      */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static void
+ips_next(ips_ha_t *ha) {
+   ips_scb_t    *scb;
+   Scsi_Cmnd    *SC;
+   int           ret;
+
+   DBG("ips_next");
+
+   if (!ha)
+      return ;
+
+#ifndef NO_IPS_CMDLINE
+   /*
+    * Send passthru commands
+    * These have priority over normal I/O
+    * but shouldn't affect performance too much
+    * since we limit the number that can be active
+    * on the card at any one time
+    */
+   while ((ha->num_ioctl < IPS_MAX_IOCTL) &&
+          (ha->copp_waitlist.head) &&
+          (scb = ips_getscb(ha))) {
+      SC = ips_removeq_wait_head(&ha->copp_waitlist);
+
+      ret = ips_make_passthru(ha, SC, scb);
+
+      switch (ret) {
+      case IPS_FAILURE:
+         if (scb->scsi_cmd) {
+            scb->scsi_cmd->result = DID_ERROR << 16;
+            scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+         }
+         ips_freescb(ha, scb);
+         break;
+      case IPS_SUCCESS_IMM:
+         if (scb->scsi_cmd)
+            scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+         ips_freescb(ha, scb);
+         break;
+      default:
+         break;
+      } /* end case */
+
+      if (ret != IPS_SUCCESS)
+         continue;
+
+      ret = ips_send_cmd(ha, scb);
+
+      if (ret == IPS_SUCCESS) {
+         ips_putq_scb_head(&ha->scb_activelist, scb);
+         ha->num_ioctl++;
+      }
+
+      switch(ret) {
+      case IPS_FAILURE:
+         if (scb->scsi_cmd) {
+            scb->scsi_cmd->result = DID_ERROR << 16;
+            scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+         }
+
+         ips_freescb(ha, scb);
+         break;
+      case IPS_SUCCESS_IMM:
+         if (scb->scsi_cmd)
+            scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+         ips_freescb(ha, scb);
+         break;
+      default:
+         break;
+      } /* end case */
+   }
+#endif
+
+   /*
+    * Send "Normal" I/O commands
+    */
+   while ((ha->scb_waitlist.head) &&
+          (scb = ips_getscb(ha))) {
+      SC = ips_removeq_wait_head(&ha->scb_waitlist);
+
+      SC->result = DID_OK;
+      SC->host_scribble = NULL;
+
+      memset(SC->sense_buffer, 0, sizeof(SC->sense_buffer));
+
+      scb->target_id = SC->target;
+      scb->lun = SC->lun;
+      scb->bus = SC->channel;
+      scb->scsi_cmd = SC;
+      scb->breakup = 0;
+      scb->data_len = 0;
+      scb->callback = ipsintr_done;
+      scb->timeout = ips_cmd_timeout;
+      memset(&scb->cmd, 0, 4);
+
+      /* copy in the CDB */
+      memcpy(scb->cdb, SC->cmnd, SC->cmd_len);
+
+      /* Now handle the data buffer */
+      if (SC->use_sg) {
+         struct scatterlist *sg;
+         int                 i;
+
+         sg = SC->request_buffer;
+
+         for (i = 0; i < SC->use_sg; i++) {
+            scb->sg_list[i].address = VIRT_TO_BUS(sg[i].address);
+            scb->sg_list[i].length = sg[i].length;
+
+            if (scb->data_len + sg[i].length > ha->max_xfer) {
+               /*
+                * Data Breakup required
+                */
+               scb->breakup = i;
+               break;
+            }
+
+            scb->data_len += sg[i].length;
+         }
+
+         if (!scb->breakup)
+            scb->sg_len = SC->use_sg;
+         else
+            scb->sg_len = scb->breakup;
+
+         scb->dcdb.transfer_length = scb->data_len;
+         scb->data_busaddr = VIRT_TO_BUS(scb->sg_list);
+      } else {
+         if (SC->request_bufflen) {
+            if (SC->request_bufflen > ha->max_xfer) {
+               /*
+                * Data breakup required
+                */
+               scb->breakup = 1;
+               scb->data_len = ha->max_xfer;
+            } else {
+               scb->data_len = SC->request_bufflen;
+            }
+
+            scb->dcdb.transfer_length = scb->data_len;
+            scb->data_busaddr = VIRT_TO_BUS(SC->request_buffer);
+            scb->sg_len = 0;
+         } else {
+            scb->data_busaddr = 0L;
+            scb->sg_len = 0;
+            scb->data_len = 0;
+            scb->dcdb.transfer_length = 0;
+         }
+
+      }
+
+      if ((scb->scsi_cmd->request.cmd == READ) && (SC->request_bufflen))
+         scb->dcdb.cmd_attribute |= DATA_IN;
+
+      if ((scb->scsi_cmd->request.cmd == WRITE) && (SC->request_bufflen))
+         scb->dcdb.cmd_attribute |= DATA_OUT;
+
+      if (scb->data_len >= IPS_MAX_XFER) {
+         scb->dcdb.cmd_attribute |= TRANSFER_64K;
+         scb->dcdb.transfer_length = 0;
+      }
+
+      ret = ips_send_cmd(ha, scb);
+
+      if (ret == IPS_SUCCESS)
+         ips_putq_scb_head(&ha->scb_activelist, scb);
+
+      switch(ret) {
+      case IPS_FAILURE:
+         if (scb->scsi_cmd) {
+            scb->scsi_cmd->result = DID_ERROR << 16;
+            scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+         }
+
+         ips_freescb(ha, scb);
+         break;
+      case IPS_SUCCESS_IMM:
+         if (scb->scsi_cmd)
+            scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+         ips_freescb(ha, scb);
+         break;
+      default:
+         break;
+      } /* end case */
+   } /* end while */
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_putq_scb_head                                          */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Add an item to the head of the queue                                   */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static inline void
+ips_putq_scb_head(ips_scb_queue_t *queue, ips_scb_t *item) {
+   DBG("ips_putq_scb_head");
+
+   if (!item)
+      return ;
+
+   item->q_next = queue->head;
+   queue->head = item;
+
+   if (!queue->tail)
+      queue->tail = item;
+
+   queue->count++;
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_putq_scb_tail                                          */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Add an item to the tail of the queue                                   */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static inline void
+ips_putq_scb_tail(ips_scb_queue_t *queue, ips_scb_t *item) {
+   DBG("ips_putq_scb_tail");
+
+   if (!item)
+      return ;
+
+   item->q_next = NULL;
+
+   if (queue->tail)
+      queue->tail->q_next = item;
+
+   queue->tail = item;
+
+   if (!queue->head)
+      queue->head = item;
+
+   queue->count++;
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_removeq_scb_head                                       */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Remove the head of the queue                                           */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static inline ips_scb_t *
+ips_removeq_scb_head(ips_scb_queue_t *queue) {
+   ips_scb_t  *item;
+
+   DBG("ips_removeq_scb_head");
+
+   item = queue->head;
+
+   if (!item)
+      return (NULL);
+
+   queue->head = item->q_next;
+   item->q_next = NULL;
+
+   if (queue->tail == item)
+      queue->tail = NULL;
+
+   queue->count--;
+
+   return (item);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_removeq_scb                                            */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Remove an item from a queue                                            */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static inline ips_scb_t *
+ips_removeq_scb(ips_scb_queue_t *queue, ips_scb_t *item) {
+   ips_scb_t  *p;
+
+   DBG("ips_removeq_scb");
+
+   if (!item)
+      return (NULL);
+
+   if (item == queue->head)
+      return (ips_removeq_scb_head(queue));
+
+   p = queue->head;
+
+   while ((p) && (item != p->q_next))
+      p = p->q_next;
+
+   if (p) {
+      /* found a match */
+      p->q_next = item->q_next;
+
+      if (!item->q_next)
+         queue->tail = p;
+
+      item->q_next = NULL;
+      queue->count--;
+
+      return (item);
+   }
+
+   return (NULL);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_putq_wait_head                                         */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Add an item to the head of the queue                                   */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static inline void
+ips_putq_wait_head(ips_wait_queue_t *queue, Scsi_Cmnd *item) {
+   DBG("ips_putq_wait_head");
+
+   if (!item)
+      return ;
+
+   item->host_scribble = (char *) queue->head;
+   queue->head = item;
+
+   if (!queue->tail)
+      queue->tail = item;
+
+   queue->count++;
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_putq_wait_tail                                         */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Add an item to the tail of the queue                                   */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static inline void
+ips_putq_wait_tail(ips_wait_queue_t *queue, Scsi_Cmnd *item) {
+   DBG("ips_putq_wait_tail");
+
+   if (!item)
+      return ;
+
+   item->host_scribble = NULL;
+
+   if (queue->tail)
+      queue->tail->host_scribble = (char *)item;
+
+   queue->tail = item;
+
+   if (!queue->head)
+      queue->head = item;
+
+   queue->count++;
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_removeq_wait_head                                      */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Remove the head of the queue                                           */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static inline Scsi_Cmnd *
+ips_removeq_wait_head(ips_wait_queue_t *queue) {
+   Scsi_Cmnd  *item;
+
+   DBG("ips_removeq_wait_head");
+
+   item = queue->head;
+
+   if (!item)
+      return (NULL);
+
+   queue->head = (Scsi_Cmnd *) item->host_scribble;
+   item->host_scribble = NULL;
+
+   if (queue->tail == item)
+      queue->tail = NULL;
+
+   queue->count--;
+
+   return (item);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_removeq_wait                                           */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Remove an item from a queue                                            */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static inline Scsi_Cmnd *
+ips_removeq_wait(ips_wait_queue_t *queue, Scsi_Cmnd *item) {
+   Scsi_Cmnd  *p;
+
+   DBG("ips_removeq_wait");
+
+   if (!item)
+      return (NULL);
+
+   if (item == queue->head)
+      return (ips_removeq_wait_head(queue));
+
+   p = queue->head;
+
+   while ((p) && (item != (Scsi_Cmnd *) p->host_scribble))
+      p = (Scsi_Cmnd *) p->host_scribble;
+
+   if (p) {
+      /* found a match */
+      p->host_scribble = item->host_scribble;
+
+      if (!item->host_scribble)
+         queue->tail = p;
+
+      item->host_scribble = NULL;
+      queue->count--;
+
+      return (item);
+   }
+
+   return (NULL);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ipsintr_blocking                                           */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Finalize an interrupt for internal commands                            */
+/*                                                                          */
+/****************************************************************************/
+static void
+ipsintr_blocking(ips_ha_t *ha, ips_scb_t *scb) {
+   DBG("ipsintr_blocking");
+
+   if ((ha->waitflag == TRUE) &&
+       (ha->cmd_in_progress == scb->cdb[0])) {
+      ha->waitflag = FALSE;
+
+      return ;
+   }
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ipsintr_done                                               */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Finalize an interrupt for non-internal commands                        */
+/*                                                                          */
+/****************************************************************************/
+static void
+ipsintr_done(ips_ha_t *ha, ips_scb_t *scb) {
+   DBG("ipsintr_done");
+
+   if (scb->scsi_cmd == NULL) {
+      /* unexpected interrupt */
+      printk(KERN_WARNING "(%s%d) Spurious interrupt; scsi_cmd not set.\n",
+             ips_name, ha->host_num);
+
+      return;
+   }
+
+   ips_done(ha, scb);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_done                                                   */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Do housekeeping on completed commands                                  */
+/*                                                                          */
+/****************************************************************************/
+static void
+ips_done(ips_ha_t *ha, ips_scb_t *scb) {
+   int ret;
+
+   DBG("ips_done");
+
+   if (!scb)
+      return ;
+
+#ifndef NO_IPS_CMDLINE
+   if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd))) {
+      ips_cleanup_passthru(scb);
+      ha->num_ioctl--;
+   } else {
+#endif
+      /*
+       * Check to see if this command had too much
+       * data and had to be broke up.  If so, queue
+       * the rest of the data and continue.
+       */
+      if (scb->breakup) {
+         /* we had a data breakup */
+         u16 bk_save;
+
+         bk_save = scb->breakup;
+         scb->breakup = 0;
+
+         if (scb->scsi_cmd->use_sg) {
+            /* S/G request */
+            struct scatterlist *sg;
+            int                 i;
+
+            sg = scb->scsi_cmd->request_buffer;
+
+            scb->data_len = 0;
+
+            for (i = bk_save; i < scb->scsi_cmd->use_sg; i++) {
+               scb->sg_list[i - bk_save].address = VIRT_TO_BUS(sg[i].address);
+               scb->sg_list[i - bk_save].length = sg[i].length;
+
+               if (scb->data_len + sg[i].length > ha->max_xfer) {
+                  /*
+                   * Data Breakup required
+                   */
+                  scb->breakup = i;
+                  break;
+               }
+
+               scb->data_len += sg[i].length;
+            }
+
+            if (!scb->breakup)
+               scb->sg_len = scb->scsi_cmd->use_sg - bk_save;
+            else
+               scb->sg_len = scb->breakup - bk_save;
+
+            scb->dcdb.transfer_length = scb->data_len;
+            scb->data_busaddr = VIRT_TO_BUS(scb->sg_list);
+         } else {
+            /* Non S/G Request */
+            if (scb->scsi_cmd->request_bufflen - (bk_save * ha->max_xfer)) {
+               /* Further breakup required */
+               scb->data_len = ha->max_xfer;
+               scb->data_busaddr = VIRT_TO_BUS(scb->scsi_cmd->request_buffer + (bk_save * ha->max_xfer));
+               scb->breakup = bk_save + 1;
+            } else {
+               scb->data_len = scb->scsi_cmd->request_bufflen - (bk_save * ha->max_xfer);
+               scb->data_busaddr = VIRT_TO_BUS(scb->scsi_cmd->request_buffer + (bk_save * ha->max_xfer));
+            }
+
+            scb->dcdb.transfer_length = scb->data_len;
+            scb->sg_len = 0;
+         }
+
+         if ((scb->scsi_cmd->request.cmd == READ) && (scb->data_len))
+            scb->dcdb.cmd_attribute |= DATA_IN;
+
+         if ((scb->scsi_cmd->request.cmd == WRITE) && (scb->data_len))
+            scb->dcdb.cmd_attribute |= DATA_OUT;
+
+         if (scb->data_len >= IPS_MAX_XFER) {
+            scb->dcdb.cmd_attribute |= TRANSFER_64K;
+            scb->dcdb.transfer_length = 0;
+         }
+
+         ret = ips_send_cmd(ha, scb);
+
+         switch(ret) {
+         case IPS_FAILURE:
+            if (scb->scsi_cmd) {
+               scb->scsi_cmd->result = DID_ERROR << 16;
+               scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+            }
+
+            ips_freescb(ha, scb);
+            break;
+         case IPS_SUCCESS_IMM:
+            if (scb->scsi_cmd) {
+               scb->scsi_cmd->result = DID_ERROR << 16;
+               scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+            }
+
+            ips_freescb(ha, scb);
+            break;
+         default:
+            break;
+         } /* end case */
+
+         return ;
+      }
+#ifndef NO_IPS_CMDLINE
+   } /* end if passthru */
+#endif
+
+   /* call back to SCSI layer */
+   scb->scsi_cmd->scsi_done(scb->scsi_cmd);
+   ips_freescb(ha, scb);
+
+   /* do the next command */
+   ips_next(ha);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_map_status                                             */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Map ServeRAID error codes to Linux Error Codes                         */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_map_status(ips_scb_t *scb, ips_stat_t *sp) {
+   int       errcode;
+
+   DBG("ips_map_status");
+
+   if (scb->bus) {
+      /* copy SCSI status and sense data for DCDB commands */
+      memcpy(scb->scsi_cmd->sense_buffer, scb->dcdb.sense_info,
+             sizeof(scb->scsi_cmd->sense_buffer));
+      scb->scsi_cmd->result = scb->dcdb.scsi_status;
+   } else
+      scb->scsi_cmd->result = 0;
+
+   /* default driver error */
+   errcode = DID_ERROR;
+
+   switch (scb->basic_status & GSC_STATUS_MASK) {
+   case CMD_TIMEOUT:
+      errcode = DID_TIME_OUT;
+      break;
+
+   case INVAL_OPCO:
+   case INVAL_CMD_BLK:
+   case INVAL_PARM_BLK:
+   case LOG_DRV_ERROR:
+   case CMD_CMPLT_WERROR:
+      break;
+
+   case PHYS_DRV_ERROR:
+      /*
+       * For physical drive errors that
+       * are not on a logical drive should
+       * be DID_OK.  The SCSI errcode will
+       * show what the real error is.
+       */
+      if (scb->bus)
+         errcode = DID_OK;
+
+      switch (scb->extended_status) {
+      case SELECTION_TIMEOUT:
+         if (scb->bus) {
+            scb->scsi_cmd->result |= DID_TIME_OUT << 16;
+
+            return (0);
+         }
+         break;
+      case DATA_OVER_UNDER_RUN:
+         if ((scb->bus) && (scb->dcdb.transfer_length < scb->data_len)) {
+            if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
+                ((((char *) scb->scsi_cmd->buffer)[0] & 0x1f) == TYPE_DISK)) {
+               /* underflow -- no error               */
+               /* restrict access to physical DASD    */
+               errcode = DID_TIME_OUT;
+               break;
+            }
+
+            /* normal underflow Occured */
+            if (scb->dcdb.transfer_length >= scb->scsi_cmd->underflow) {
+               scb->scsi_cmd->result |= DID_OK << 16;
+
+               return (0);
+            }
+         }
+
+         break;
+      case EXT_RECOVERY:
+         /* don't fail recovered errors */
+         if (scb->bus) {
+            scb->scsi_cmd->result |= DID_OK << 16;
+
+            return (0);
+         }
+         break;
+
+      case EXT_HOST_RESET:
+      case EXT_DEVICE_RESET:
+         errcode = DID_RESET;
+         break;
+
+      case EXT_CHECK_CONDITION:
+         break;
+      } /* end switch */
+   } /* end switch */
+
+   scb->scsi_cmd->result |= (errcode << 16);
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_send                                                   */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Wrapper for ips_send_cmd                                               */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_send(ips_ha_t *ha, ips_scb_t *scb, scb_callback callback) {
+   int ret;
+
+   DBG("ips_send");
+
+   scb->callback = callback;
+
+   ret = ips_send_cmd(ha, scb);
+
+   return (ret);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_send_wait                                              */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Send a command to the controller and wait for it to return             */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_send_wait(ips_ha_t *ha, ips_scb_t *scb, int timeout) {
+   int       ret;
+
+   DBG("ips_send_wait");
+
+   ha->waitflag = TRUE;
+   ha->cmd_in_progress = scb->cdb[0];
+
+   ret = ips_send(ha, scb, ipsintr_blocking);
+
+   if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
+      return (ret);
+
+   ret = ips_wait(ha, timeout, IPS_INTR_OFF);
+
+   return (ret);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_send_cmd                                               */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Map SCSI commands to ServeRAID commands for logical drives             */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_send_cmd(ips_ha_t *ha, ips_scb_t *scb) {
+   int       ret;
+
+   DBG("ips_send_cmd");
+
+   ret = IPS_SUCCESS;
+
+   if (!scb->scsi_cmd) {
+      /* internal command */
+
+      if (scb->bus > 0) {
+         /* ServeRAID commands can't be issued */
+         /* to real devices -- fail them       */
+         if ((ha->waitflag == TRUE) &&
+             (ha->cmd_in_progress == scb->cdb[0])) {
+            ha->waitflag = FALSE;
+         }
+
+         return (1);
+      }
+#ifndef NO_IPS_CMDLINE
+   } else if ((scb->bus == 0) && (!ips_is_passthru(scb->scsi_cmd))) {
+#else
+   } else if (scb->bus == 0) {
+#endif
+      /* command to logical bus -- interpret */
+      ret = IPS_SUCCESS_IMM;
+
+      switch (scb->scsi_cmd->cmnd[0]) {
+      case ALLOW_MEDIUM_REMOVAL:
+      case REZERO_UNIT:
+      case ERASE:
+      case WRITE_FILEMARKS:
+      case SPACE:
+         scb->scsi_cmd->result = DID_ERROR << 16;
+         break;
+
+      case START_STOP:
+         scb->scsi_cmd->result = DID_OK << 16;
+
+      case TEST_UNIT_READY:
+      case INQUIRY:
+         if (scb->target_id == IPS_ADAPTER_ID) {
+            /*
+             * Either we have a TUR
+             * or we have a SCSI inquiry
+             */
+            if (scb->scsi_cmd->cmnd[0] == TEST_UNIT_READY)
+               scb->scsi_cmd->result = DID_OK << 16;
+
+            if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
+               INQUIRYDATA inq;
+
+               memset(&inq, 0, sizeof(INQUIRYDATA));
+
+               inq.DeviceType = TYPE_PROCESSOR;
+               inq.DeviceTypeQualifier = 0;
+               inq.RemoveableMedia = 0;
+               inq.Versions = 0x1;  /* SCSI I */
+               inq.AdditionalLength = 31;
+               strncpy(inq.VendorId, "IBM     ", 8);
+               strncpy(inq.ProductId, "SERVERAID       ", 16);
+               strncpy(inq.ProductRevisionLevel, "1.00", 4);
+
+               memcpy(scb->scsi_cmd->request_buffer, &inq, scb->scsi_cmd->request_bufflen);
+
+               scb->scsi_cmd->result = DID_OK << 16;
+            }
+         } else {
+            scb->cmd.logical_info.op_code = GET_LOGICAL_DRIVE_INFO;
+            scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
+            scb->cmd.logical_info.buffer_addr = VIRT_TO_BUS(&ha->adapt->logical_drive_info);
+            scb->cmd.logical_info.reserved = 0;
+            scb->cmd.logical_info.reserved2 = 0;
+            ret = IPS_SUCCESS;
+         }
+
+         break;
+
+      case REQUEST_SENSE:
+         ips_reqsen(ha, scb);
+         scb->scsi_cmd->result = DID_OK << 16;
+         break;
+
+      case READ_6:
+      case WRITE_6:
+         if (!scb->sg_len) {
+            scb->cmd.basic_io.op_code =
+            (scb->scsi_cmd->cmnd[0] == READ_6) ? IPS_READ : IPS_WRITE;
+         } else {
+            scb->cmd.basic_io.op_code =
+            (scb->scsi_cmd->cmnd[0] == READ_6) ? READ_SCATTER_GATHER : WRITE_SCATTER_GATHER;
+         }
+
+         scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
+         scb->cmd.basic_io.log_drv = scb->target_id;
+         scb->cmd.basic_io.sg_count = scb->sg_len;
+         scb->cmd.basic_io.sg_addr = scb->data_busaddr;
+
+         if (scb->cmd.basic_io.lba)
+            scb->cmd.basic_io.lba += scb->cmd.basic_io.sector_count;
+         else
+            scb->cmd.basic_io.lba = (((scb->scsi_cmd->cmnd[1] & 0x1f) << 16) |
+                                     (scb->scsi_cmd->cmnd[2] << 8) |
+                                     (scb->scsi_cmd->cmnd[3]));
+
+         scb->cmd.basic_io.sector_count = scb->data_len / IPS_BLKSIZE;
+
+         if (scb->cmd.basic_io.sector_count == 0)
+            scb->cmd.basic_io.sector_count = 256;
+
+         scb->cmd.basic_io.reserved = 0;
+         ret = IPS_SUCCESS;
+         break;
+
+      case READ_10:
+      case WRITE_10:
+         if (!scb->sg_len) {
+            scb->cmd.basic_io.op_code =
+            (scb->scsi_cmd->cmnd[0] == READ_10) ? IPS_READ : IPS_WRITE;
+         } else {
+            scb->cmd.basic_io.op_code =
+            (scb->scsi_cmd->cmnd[0] == READ_10) ? READ_SCATTER_GATHER : WRITE_SCATTER_GATHER;
+         }
+
+         scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
+         scb->cmd.basic_io.log_drv = scb->target_id;
+         scb->cmd.basic_io.sg_count = scb->sg_len;
+         scb->cmd.basic_io.sg_addr = scb->data_busaddr;
+
+         if (scb->cmd.basic_io.lba)
+            scb->cmd.basic_io.lba += scb->cmd.basic_io.sector_count;
+         else
+            scb->cmd.basic_io.lba = ((scb->scsi_cmd->cmnd[2] << 24) |
+                                     (scb->scsi_cmd->cmnd[3] << 16) |
+                                     (scb->scsi_cmd->cmnd[4] << 8) |
+                                     scb->scsi_cmd->cmnd[5]);
+
+         scb->cmd.basic_io.sector_count = scb->data_len / IPS_BLKSIZE;
+
+         scb->cmd.basic_io.reserved = 0;
+
+         if (scb->cmd.basic_io.sector_count == 0) {
+            /*
+             * This is a null condition
+             * we don't have to do anything
+             * so just return
+             */
+            scb->scsi_cmd->result = DID_OK << 16;
+         } else
+            ret = IPS_SUCCESS;
+
+         break;
+
+      case RESERVE:
+      case RELEASE:
+         scb->scsi_cmd->result = DID_OK << 16;
+         break;
+
+      case MODE_SENSE:
+         scb->cmd.basic_io.op_code = ENQUIRY;
+         scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
+         scb->cmd.basic_io.sg_addr = VIRT_TO_BUS(ha->enq);
+         ret = IPS_SUCCESS;
+         break;
+
+      case READ_CAPACITY:
+         scb->cmd.logical_info.op_code = GET_LOGICAL_DRIVE_INFO;
+         scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
+         scb->cmd.logical_info.buffer_addr = VIRT_TO_BUS(&ha->adapt->logical_drive_info);
+         scb->cmd.logical_info.reserved = 0;
+         scb->cmd.logical_info.reserved2 = 0;
+         scb->cmd.logical_info.reserved3 = 0;
+         ret = IPS_SUCCESS;
+         break;
+
+      case SEND_DIAGNOSTIC:
+      case REASSIGN_BLOCKS:
+      case FORMAT_UNIT:
+      case SEEK_10:
+      case VERIFY:
+      case READ_DEFECT_DATA:
+      case READ_BUFFER:
+      case WRITE_BUFFER:
+         scb->scsi_cmd->result = DID_OK << 16;
+         break;
+
+      default:
+         scb->scsi_cmd->result = DID_ERROR << 16;
+         break;
+      } /* end switch */
+   } /* end if */
+
+   if (ret == IPS_SUCCESS_IMM)
+      return (ret);
+
+   /* setup DCDB */
+   if (scb->bus > 0) {
+      if (!scb->sg_len)
+         scb->cmd.dcdb.op_code = DIRECT_CDB;
+      else
+         scb->cmd.dcdb.op_code = DIRECT_CDB_SCATTER_GATHER;
+
+      scb->cmd.dcdb.command_id = IPS_COMMAND_ID(ha, scb);
+      scb->cmd.dcdb.dcdb_address = VIRT_TO_BUS(&scb->dcdb);
+      scb->cmd.dcdb.reserved = 0;
+      scb->cmd.dcdb.reserved2 = 0;
+      scb->cmd.dcdb.reserved3 = 0;
+
+      scb->dcdb.device_address = ((scb->bus - 1) << 4) | scb->target_id;
+      scb->dcdb.cmd_attribute |= DISCONNECT_ALLOWED;
+
+      if (scb->timeout) {
+         if (scb->timeout <= 10)
+            scb->dcdb.cmd_attribute |= TIMEOUT_10;
+         else if (scb->timeout <= 60)
+            scb->dcdb.cmd_attribute |= TIMEOUT_60;
+         else
+            scb->dcdb.cmd_attribute |= TIMEOUT_20M;
+      }
+
+      if (!(scb->dcdb.cmd_attribute & TIMEOUT_20M))
+         scb->dcdb.cmd_attribute |= TIMEOUT_20M;
+
+      scb->dcdb.sense_length = sizeof(scb->scsi_cmd->sense_buffer);
+      scb->dcdb.buffer_pointer = scb->data_busaddr;
+      scb->dcdb.sg_count = scb->sg_len;
+      scb->dcdb.cdb_length = scb->scsi_cmd->cmd_len;
+      memcpy(scb->dcdb.scsi_cdb, scb->scsi_cmd->cmnd, scb->scsi_cmd->cmd_len);
+   }
+
+   return (ips_issue(ha, scb));
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_chk_status                                             */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Check the status of commands to logical drives                         */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_chkstatus(ips_ha_t *ha) {
+   ips_scb_t  *scb;
+   ips_stat_t *sp = &ha->sp;
+   u8          basic_status;
+   u8          ext_status;
+   int         command_id;
+   int         errcode;
+   int         ret;
+
+   DBG("ips_chkstatus");
+
+   command_id = ips_statupd(ha);
+
+   if (command_id > (MAX_CMDS-1)) {
+      printk(KERN_NOTICE "(%s%d) invalid command id received: %d\n",
+             ips_name, ha->host_num, command_id);
+
+      return (-1);
+   }
+
+   scb = &ha->scbs[command_id];
+   sp->scb_addr = (u32) scb;
+   sp->residue_len = 0;
+   scb->basic_status = basic_status = ha->adapt->p_status_tail->basic_status & BASIC_STATUS_MASK;
+   scb->extended_status = ext_status = ha->adapt->p_status_tail->extended_status;
+
+   /* Remove the item from the active queue */
+   ips_removeq_scb(&ha->scb_activelist, scb);
+
+   if (!scb->scsi_cmd)
+      /* internal commands are handled in do_ipsintr */
+      return (0);
+
+#ifndef NO_IPS_CMDLINE
+   if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))
+      /* passthru - just returns the raw result */
+      return (0);
+#endif
+
+   errcode = DID_OK;
+   ret = 0;
+
+   if (((basic_status & GSC_STATUS_MASK) == SSUCCESS) ||
+       ((basic_status & GSC_STATUS_MASK) == RECOVERED_ERROR)) {
+
+      if (scb->bus == 0) {
+#if IPS_DEBUG >= 1
+         if ((basic_status & GSC_STATUS_MASK) == RECOVERED_ERROR) {
+            printk(KERN_NOTICE "(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x\n",
+                   ips_name, ha->host_num,
+                   scb->cmd.basic_io.op_code, basic_status, ext_status);
+         }
+#endif
+
+         switch (scb->scsi_cmd->cmnd[0]) {
+         case ALLOW_MEDIUM_REMOVAL:
+         case REZERO_UNIT:
+         case ERASE:
+         case WRITE_FILEMARKS:
+         case SPACE:
+            errcode = DID_ERROR;
+            ret = 1;
+            break;
+
+         case START_STOP:
+            break;
+
+         case TEST_UNIT_READY:
+            if (!ips_online(ha, scb)) {
+               errcode = DID_TIME_OUT;
+               ret = 1;
+            }
+            break;
+
+         case INQUIRY:
+            if (ips_online(ha, scb)) {
+               ips_inquiry(ha, scb);
+            } else {
+               errcode = DID_TIME_OUT;
+               ret = 1;
+            }
+            break;
+
+         case REQUEST_SENSE:
+            ips_reqsen(ha, scb);
+            break;
+
+         case READ_6:
+         case WRITE_6:
+         case READ_10:
+         case WRITE_10:
+         case RESERVE:
+         case RELEASE:
+            break;
+
+         case MODE_SENSE:
+            if (!ips_online(ha, scb) || !ips_msense(ha, scb)) {
+               errcode = DID_ERROR;
+               ret = 1;
+            }
+            break;
+
+         case READ_CAPACITY:
+            if (ips_online(ha, scb))
+               ips_rdcap(ha, scb);
+            else {
+               errcode = DID_TIME_OUT;
+               ret = 1;
+            }
+            break;
+
+         case SEND_DIAGNOSTIC:
+         case REASSIGN_BLOCKS:
+            break;
+
+         case FORMAT_UNIT:
+            errcode = DID_ERROR;
+            ret = 1;
+            break;
+
+         case SEEK_10:
+         case VERIFY:
+         case READ_DEFECT_DATA:
+         case READ_BUFFER:
+         case WRITE_BUFFER:
+            break;
+
+         default:
+            errcode = DID_ERROR;
+            ret = 1;
+         } /* end switch */
+
+         scb->scsi_cmd->result = errcode << 16;
+      } else { /* bus == 0 */
+         /* restrict access to physical drives */
+         if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
+             ((((char *) scb->scsi_cmd->buffer)[0] & 0x1f) == TYPE_DISK)) {
+
+            scb->scsi_cmd->result = DID_TIME_OUT << 16;
+
+            ret = 1;
+         }
+      } /* else */
+   } else { /* recovered error / success */
+#if IPS_DEBUG >= 1
+      if (scb->bus == 0) {
+         printk(KERN_NOTICE "(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x\n",
+                ips_name, ha->host_num,
+                scb->cmd.basic_io.op_code, basic_status, ext_status);
+      }
+#endif
+
+      ret = ips_map_status(scb, sp);
+   } /* else */
+
+   return (ret);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_online                                                 */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Determine if a logical drive is online                                 */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_online(ips_ha_t *ha, ips_scb_t *scb) {
+   DBG("ips_online");
+
+   if (scb->target_id >= MAX_LOGICAL_DRIVES)
+      return (0);
+
+   if ((scb->basic_status & GSC_STATUS_MASK) > 1) {
+      memset(&ha->adapt->logical_drive_info, 0, sizeof(ha->adapt->logical_drive_info));
+
+      return (0);
+   }
+
+   if (scb->target_id < ha->adapt->logical_drive_info.no_of_log_drive &&
+       ha->adapt->logical_drive_info.drive_info[scb->target_id].state != OFF_LINE &&
+       ha->adapt->logical_drive_info.drive_info[scb->target_id].state != FREE &&
+       ha->adapt->logical_drive_info.drive_info[scb->target_id].state != CRS &&
+       ha->adapt->logical_drive_info.drive_info[scb->target_id].state != SYS)
+      return (1);
+   else
+      return (0);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_inquiry                                                */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Simulate an inquiry command to a logical drive                         */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_inquiry(ips_ha_t *ha, ips_scb_t *scb) {
+   INQUIRYDATA inq;
+
+   DBG("ips_inquiry");
+
+   memset(&inq, 0, sizeof(INQUIRYDATA));
+
+   inq.DeviceType = TYPE_DISK;
+   inq.DeviceTypeQualifier = 0;
+   inq.RemoveableMedia = 0;
+   inq.Versions = 0x1;  /* SCSI I */
+   inq.AdditionalLength = 31;
+   strncpy(inq.VendorId, "IBM     ", 8);
+   strncpy(inq.ProductId, "SERVERAID       ", 16);
+   strncpy(inq.ProductRevisionLevel, "1.00", 4);
+
+   memcpy(scb->scsi_cmd->request_buffer, &inq, scb->scsi_cmd->request_bufflen);
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_rdcap                                                  */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Simulate a read capacity command to a logical drive                    */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_rdcap(ips_ha_t *ha, ips_scb_t *scb) {
+   CAPACITY_T *cap;
+
+   DBG("ips_rdcap");
+
+   if (scb->scsi_cmd->bufflen < 8)
+      return (0);
+
+   cap = (CAPACITY_T *) scb->scsi_cmd->request_buffer;
+
+   cap->lba = htonl(ha->adapt->logical_drive_info.drive_info[scb->target_id].sector_count - 1);
+   cap->len = htonl((u32) IPS_BLKSIZE);
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_msense                                                 */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Simulate a mode sense command to a logical drive                       */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_msense(ips_ha_t *ha, ips_scb_t *scb) {
+   u16          heads;
+   u16          sectors;
+   u32          cylinders;
+   ips_mdata_t  mdata;
+
+   DBG("ips_msense");
+
+   if (ha->enq->ulDriveSize[scb->target_id] > 0x400000 &&
+       (ha->enq->ucMiscFlag & 0x8) == 0) {
+      heads = NORM_MODE_HEADS;
+      sectors = NORM_MODE_SECTORS;
+   } else {
+      heads = COMP_MODE_HEADS;
+      sectors = COMP_MODE_SECTORS;
+   }
+
+   cylinders = ha->enq->ulDriveSize[scb->target_id] / (heads * sectors);
+
+   mdata.plh.plh_type = 0;
+   mdata.plh.plh_wp = 0;
+   mdata.plh.plh_bdl = 8;
+
+   switch (scb->scsi_cmd->cmnd[2] & 0x3f) {
+   case 0x03: /* page 3 */
+      mdata.pdata.pg3.pg_pc = 0x3;
+      mdata.pdata.pg3.pg_res1 = 0;
+      mdata.pdata.pg3.pg_len = sizeof(DADF_T);
+      mdata.plh.plh_len = 3 + mdata.plh.plh_bdl + mdata.pdata.pg3.pg_len;
+      mdata.pdata.pg3.pg_trk_z = 0;
+      mdata.pdata.pg3.pg_asec_z = 0;
+      mdata.pdata.pg3.pg_atrk_z = 0;
+      mdata.pdata.pg3.pg_atrk_v = 0;
+      mdata.pdata.pg3.pg_sec_t = htons(sectors);
+      mdata.pdata.pg3.pg_bytes_s = htons(IPS_BLKSIZE);
+      mdata.pdata.pg3.pg_intl = htons(1);
+      mdata.pdata.pg3.pg_trkskew = 0;
+      mdata.pdata.pg3.pg_cylskew = 0;
+      mdata.pdata.pg3.pg_res2 = 0;
+      mdata.pdata.pg3.pg_ins = 0;
+      mdata.pdata.pg3.pg_surf = 0;
+      mdata.pdata.pg3.pg_rmb = 0;
+      mdata.pdata.pg3.pg_hsec = 0;
+      mdata.pdata.pg3.pg_ssec = 1;
+      break;
+
+   case 0x4:
+      mdata.pdata.pg4.pg_pc = 0x4;
+      mdata.pdata.pg4.pg_res1 = 0;
+      mdata.pdata.pg4.pg_len = sizeof(RDDG_T);
+      mdata.plh.plh_len = 3 + mdata.plh.plh_bdl + mdata.pdata.pg4.pg_len;
+      mdata.pdata.pg4.pg_cylu = (cylinders >> 8) & 0xffff;
+      mdata.pdata.pg4.pg_cyll = cylinders & 0xff;
+      mdata.pdata.pg4.pg_head = heads;
+      mdata.pdata.pg4.pg_wrpcompu = 0;
+      mdata.pdata.pg4.pg_wrpcompl = 0;
+      mdata.pdata.pg4.pg_redwrcur = 0;
+      mdata.pdata.pg4.pg_drstep = htons(1);
+      mdata.pdata.pg4.pg_landu = 0;
+      mdata.pdata.pg4.pg_landl = 0;
+      mdata.pdata.pg4.pg_res2 = 0;
+      break;
+   default:
+      return (0);
+   } /* end switch */
+
+   memcpy(scb->scsi_cmd->request_buffer, &mdata, scb->scsi_cmd->request_bufflen);
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_reqsen                                                 */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Simulate a request sense command to a logical drive                    */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_reqsen(ips_ha_t *ha, ips_scb_t *scb) {
+   char *sp;
+
+   DBG("ips_reqsen");
+
+   sp = (char *) scb->scsi_cmd->sense_buffer;
+   memset(sp, 0, sizeof(scb->scsi_cmd->sense_buffer));
+
+   sp[0] = 0x70;
+   sp[3] = NO_SENSE;
+   sp[7] = 0xe;
+   sp[12] = NO_SENSE;
+
+   return (0);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_free                                                   */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Free any allocated space for this controller                           */
+/*                                                                          */
+/****************************************************************************/
+static void
+ips_free(ips_ha_t *ha) {
+   int i;
+
+   DBG("ips_free");
+
+   if (ha) {
+      if (ha->enq) {
+         kfree(ha->enq);
+         ha->enq = NULL;
+      }
+
+      if (ha->conf) {
+         kfree(ha->conf);
+         ha->conf = NULL;
+      }
+
+      if (ha->adapt) {
+         kfree(ha->adapt);
+         ha->adapt = NULL;
+      }
+
+      if (ha->nvram) {
+         kfree(ha->nvram);
+         ha->nvram = NULL;
+      }
+
+      if (ha->subsys) {
+         kfree(ha->subsys);
+         ha->subsys = NULL;
+      }
+
+      if (ha->dummy) {
+         kfree(ha->dummy);
+         ha->dummy = NULL;
+      }
+
+      if (ha->scbs) {
+         for (i = 0; i < ha->max_cmds; i++) {
+            if (ha->scbs[i].sg_list)
+               kfree(ha->scbs[i].sg_list);
+         }
+
+         kfree(ha->scbs);
+         ha->scbs = NULL;
+      } /* end if */
+   }
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_allocatescbs                                           */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Allocate the command blocks                                            */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_allocatescbs(ips_ha_t *ha) {
+   ips_scb_t *scb_p;
+   int        i;
+
+   DBG("ips_allocatescbs");
+
+   /* Allocate memory for the CCBs */
+   ha->scbs = (ips_scb_t *) kmalloc(ha->max_cmds * sizeof(ips_scb_t), GFP_KERNEL|GFP_DMA);
+
+   memset(ha->scbs, 0, ha->max_cmds * sizeof(ips_scb_t));
+
+   for (i = 0; i < ha->max_cmds; i++) {
+      scb_p = &ha->scbs[i];
+
+      /* allocate S/G list */
+      scb_p->sg_list = (SG_LIST *) kmalloc(sizeof(SG_LIST) * MAX_SG_ELEMENTS, GFP_KERNEL|GFP_DMA);
+
+      if (! scb_p->sg_list)
+         return (0);
+
+      /* add to the free list */
+      if (i < ha->max_cmds - 1) {
+         scb_p->q_next = ha->scb_freelist;
+         ha->scb_freelist = scb_p;
+      }
+   }
+
+   /* success */
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_init_scb                                               */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Initialize a CCB to default values                                     */
+/*                                                                          */
+/****************************************************************************/
+static void
+ips_init_scb(ips_ha_t *ha, ips_scb_t *scb) {
+   SG_LIST *sg_list;
+
+   DBG("ips_init_scb");
+
+   if (scb == NULL)
+      return ;
+
+   sg_list = scb->sg_list;
+
+   /* zero fill */
+   memset(scb, 0, sizeof(ips_scb_t));
+   memset(ha->dummy, 0, sizeof(BASIC_IO_CMD));
+
+   /* Initialize dummy command bucket */
+   ha->dummy->op_code = 0xFF;
+   ha->dummy->ccsar = VIRT_TO_BUS(ha->dummy);
+   ha->dummy->command_id = MAX_CMDS;
+
+   /* set bus address of scb */
+   scb->scb_busaddr = VIRT_TO_BUS(scb);
+   scb->sg_list = sg_list;
+
+   /* Neptune Fix */
+   scb->cmd.basic_io.cccr = ILE;
+   scb->cmd.basic_io.ccsar = VIRT_TO_BUS(ha->dummy);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_get_scb                                                */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Initialize a CCB to default values                                     */
+/*                                                                          */
+/* ASSUMED to be callled from within a lock                                 */
+/*                                                                          */
+/****************************************************************************/
+static ips_scb_t *
+ips_getscb(ips_ha_t *ha) {
+   ips_scb_t     *scb;
+   unsigned int   cpu_flags;
+
+   DBG("ips_getscb");
+
+   spin_lock_irqsave(&ha->scb_lock, cpu_flags);
+   if ((scb = ha->scb_freelist) == NULL) {
+      spin_unlock_irqrestore(&ha->scb_lock, cpu_flags);
+
+      return (NULL);
+   }
+
+   ha->scb_freelist = scb->q_next;
+   scb->q_next = NULL;
+
+   spin_unlock_irqrestore(&ha->scb_lock, cpu_flags);
+
+   ips_init_scb(ha, scb);
+
+   return (scb);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_free_scb                                               */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Return an unused CCB back to the free list                             */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static void
+ips_freescb(ips_ha_t *ha, ips_scb_t *scb) {
+   unsigned int cpu_flags;
+
+   DBG("ips_freescb");
+
+   /* check to make sure this is not our "special" scb */
+   if (IPS_COMMAND_ID(ha, scb) < (ha->max_cmds - 1)) {
+      spin_lock_irqsave(&ha->scb_lock, cpu_flags);
+      scb->q_next = ha->scb_freelist;
+      ha->scb_freelist = scb;
+      spin_unlock_irqrestore(&ha->scb_lock, cpu_flags);
+   }
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_reset_adapter                                          */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Reset the controller                                                   */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_reset_adapter(ips_ha_t *ha) {
+   u8  Isr;
+   u8  Cbsp;
+   u8  PostByte[MAX_POST_BYTES];
+   u8  ConfigByte[MAX_CONFIG_BYTES];
+   int i, j;
+   int reset_counter;
+
+   DBG("ips_reset_adapter");
+
+#if IPS_DEBUG >= 1
+   printk(KERN_WARNING "ips_reset_adapter: io addr: %x, irq: %d\n",
+          ha->io_addr, ha->irq);
+#endif
+
+   reset_counter = 0;
+
+   while (reset_counter < 2) {
+      reset_counter++;
+
+      outb(RST, ha->io_addr + SCPR);
+      MDELAY(ONE_SEC);
+      outb(0, ha->io_addr + SCPR);
+      MDELAY(ONE_SEC);
+
+      for (i = 0; i < MAX_POST_BYTES; i++) {
+         for (j = 0; j < 45; j++) {
+            Isr = inb(ha->io_addr + HISR);
+            if (Isr & GHI)
+               break;
+
+            MDELAY(ONE_SEC);
+         }
+
+         if (j >= 45) {
+            /* error occured */
+            if (reset_counter < 2)
+               continue;
+            else
+               /* reset failed */
+               return (0);
+         }
+
+         PostByte[i] = inb(ha->io_addr + ISPR);
+         outb(Isr, ha->io_addr + HISR);
+      }
+
+      if (PostByte[0] < GOOD_POST_BASIC_STATUS) {
+         printk("(%s%d) reset controller fails (post status %x %x).\n",
+                ips_name, ha->host_num, PostByte[0], PostByte[1]);
+
+         return (0);
+      }
+
+      for (i = 0; i < MAX_CONFIG_BYTES; i++) {
+         for (j = 0; j < 240; j++) {
+            Isr = inb(ha->io_addr + HISR);
+            if (Isr & GHI)
+               break;
+
+            MDELAY(ONE_SEC); /* 100 msec */
+         }
+
+         if (j >= 240) {
+            /* error occured */
+            if (reset_counter < 2)
+               continue;
+            else
+               /* reset failed */
+               return (0);
+         }
+
+         ConfigByte[i] = inb(ha->io_addr + ISPR);
+         outb(Isr, ha->io_addr + HISR);
+      }
+
+      if (ConfigByte[0] == 0 && ConfigByte[1] == 2) {
+         printk("(%s%d) reset controller fails (status %x %x).\n",
+                ips_name, ha->host_num, ConfigByte[0], ConfigByte[1]);
+
+         return (0);
+      }
+
+      for (i = 0; i < 240; i++) {
+         Cbsp = inb(ha->io_addr + CBSP);
+
+         if ((Cbsp & OP) == 0)
+            break;
+
+         MDELAY(ONE_SEC);
+      }
+
+      if (i >= 240) {
+         /* error occured */
+         if (reset_counter < 2)
+            continue;
+         else
+            /* reset failed */
+            return (0);
+      }
+
+      /* setup CCCR */
+      outw(0x1010, ha->io_addr + CCCR);
+
+      /* Enable busmastering */
+      outb(EBM, ha->io_addr + SCPR);
+
+      /* setup status queues */
+      ips_statinit(ha);
+
+      /* Enable interrupts */
+      outb(EI, ha->io_addr + HISR);
+
+      /* if we get here then everything went OK */
+      break;
+   }
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_statinit                                               */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Initialize the status queues on the controller                         */
+/*                                                                          */
+/****************************************************************************/
+static void
+ips_statinit(ips_ha_t *ha) {
+   u32        phys_status_start;
+
+   DBG("ips_statinit");
+
+   ha->adapt->p_status_start = ha->adapt->status;
+   ha->adapt->p_status_end = ha->adapt->status + MAX_CMDS;
+   ha->adapt->p_status_tail = ha->adapt->status;
+
+   phys_status_start = VIRT_TO_BUS(ha->adapt->status);
+   outl(phys_status_start, ha->io_addr + SQSR);
+   outl(phys_status_start + STATUS_Q_SIZE, ha->io_addr + SQER);
+   outl(phys_status_start + STATUS_SIZE, ha->io_addr + SQHR);
+   outl(phys_status_start, ha->io_addr + SQTR);
+
+   ha->adapt->hw_status_start = phys_status_start;
+   ha->adapt->hw_status_tail = phys_status_start;
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_statupd                                                */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Remove an element from the status queue                                */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_statupd(ips_ha_t *ha) {
+   int       command_id;
+
+   DBG("ips_statupd");
+
+   if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
+      ha->adapt->p_status_tail++;
+      ha->adapt->hw_status_tail += sizeof(STATUS);
+   } else {
+      ha->adapt->p_status_tail = ha->adapt->p_status_start;
+      ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
+   }
+
+   outl(ha->adapt->hw_status_tail, ha->io_addr + SQTR);
+
+   command_id = ha->adapt->p_status_tail->command_id;
+
+   return (command_id);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_issue                                                  */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Send a command down to the controller                                  */
+/*                                                                          */
+/* ASSUMED to be called from within a lock                                  */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_issue(ips_ha_t *ha, ips_scb_t *scb) {
+   u32       TimeOut;
+   u16       val;
+
+   DBG("ips_issue");
+
+#if IPS_DEBUG >= 10
+   if (scb->scsi_cmd)
+      printk(KERN_NOTICE "%s: ips_issue: cmd 0x%X id %d (%d %d %d)\n",
+             ips_name,
+             scb->cdb[0],
+             scb->cmd.basic_io.command_id,
+             scb->bus,
+             scb->target_id,
+             scb->lun);
+   else
+      printk(KERN_NOTICE "%s: ips_issue: logical cmd id %d\n",
+             ips_name,
+             scb->cmd.basic_io.command_id);
+#if IPS_DEBUG >= 11
+      MDELAY(ONE_SEC);
+#endif
+#endif
+
+   TimeOut = 0;
+
+   while ((val = inw(ha->io_addr + CCCR)) & SEMAPHORE) {
+      UDELAY(1000);
+
+      if (++TimeOut >= SEMAPHORE_TIMEOUT) {
+         if (!(val & START_STOP_BIT))
+            break;
+
+         printk(KERN_WARNING "(%s%d) ips_issue val [0x%x].\n",
+                ips_name, ha->host_num, val);
+         printk(KERN_WARNING "(%s%d) ips_issue semaphore chk timeout.\n",
+                ips_name, ha->host_num);
+
+         return (IPS_FAILURE);
+      } /* end if */
+   } /* end while */
+
+   outl(scb->scb_busaddr, ha->io_addr + CCSAR);
+   outw(START_COMMAND, ha->io_addr + CCCR);
+
+   return (IPS_SUCCESS);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_isintr                                                 */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Test to see if an interrupt is for us                                  */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_isintr(ips_ha_t *ha) {
+   u8 Isr;
+
+   DBG("ips_isintr");
+
+   Isr = inb(ha->io_addr + HISR);
+
+   if (Isr == 0xFF)
+      /* ?!?! Nothing really there */
+      return (0);
+
+   if (Isr & SCE)
+      return (1);
+   else if (Isr & (SQO | GHI)) {
+      /* status queue overflow or GHI */
+      /* just clear the interrupt */
+      outb(Isr, ha->io_addr + HISR);
+   }
+
+   return (0);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_wait                                                   */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Wait for a command to complete                                         */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_wait(ips_ha_t *ha, int time, int intr) {
+   int        ret;
+
+   DBG("ips_wait");
+
+   ret = IPS_FAILURE;
+
+   time *= ONE_SEC; /* convert seconds to milliseconds */
+
+   while (time > 0) {
+      if (intr == IPS_INTR_OFF) {
+         if (ha->waitflag == FALSE) {
+            /*
+             * controller generated an interupt to
+             * acknowledge completion of the command
+             * and ips_intr() has serviced the interrupt.
+             */
+            ret = IPS_SUCCESS;
+            break;
+         }
+
+         /*
+          * NOTE: Interrupts are disabled here
+          * On an SMP system interrupts will only
+          * be disabled on one processor.
+          * So, ultimately we still need to set the
+          * "I'm in the interrupt handler flag"
+          */
+         while (test_and_set_bit(IPS_IN_INTR, &ha->flags))
+            UDELAY(1000);
+
+         ips_intr(ha);
+
+         clear_bit(IPS_IN_INTR, &ha->flags);
+
+      } else {
+         if (ha->waitflag == FALSE) {
+            ret = IPS_SUCCESS;
+            break;
+         }
+      }
+
+      UDELAY(1000); /* 1 milisecond */
+      time--;
+   }
+
+   return (ret);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_write_driver_status                                    */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Write OS/Driver version to Page 5 of the nvram on the controller       */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_write_driver_status(ips_ha_t *ha) {
+   DBG("ips_write_driver_status");
+
+   if (!ips_readwrite_page5(ha, FALSE)) {
+      printk(KERN_WARNING "(%s%d) unable to read NVRAM page 5.\n",
+             ips_name, ha->host_num);
+
+      return (0);
+   }
+
+   /* check to make sure the page has a valid */
+   /* signature */
+   if (ha->nvram->signature != NVRAM_PAGE5_SIGNATURE) {
+#if IPS_DEBUG >= 1
+      printk("(%s%d) NVRAM page 5 has an invalid signature: %X.\n",
+             ips_name, ha->host_num, ha->nvram->signature);
+#endif
+      return (1);
+   }
+
+#if IPS_DEBUG >= 2
+   printk("(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.\n",
+          ips_name, ha->host_num, ha->nvram->adapter_type, ha->nvram->adapter_slot,
+          ha->nvram->bios_high[0], ha->nvram->bios_high[1],
+          ha->nvram->bios_high[2], ha->nvram->bios_high[3],
+          ha->nvram->bios_low[0], ha->nvram->bios_low[1],
+          ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
+#endif
+
+   /* save controller type */
+   ha->ad_type = ha->nvram->adapter_type;
+
+   /* change values (as needed) */
+   ha->nvram->operating_system = OS_LINUX;
+   strncpy((char *) ha->nvram->driver_high, IPS_VERSION_HIGH, 4);
+   strncpy((char *) ha->nvram->driver_low, IPS_VERSION_LOW, 4);
+
+   /* now update the page */
+   if (!ips_readwrite_page5(ha, TRUE)) {
+      printk(KERN_WARNING "(%s%d) unable to write NVRAM page 5.\n",
+             ips_name, ha->host_num);
+
+      return (0);
+   }
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_read_adapter_status                                    */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Do an Inquiry command to the adapter                                   */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_read_adapter_status(ips_ha_t *ha) {
+   ips_scb_t *scb;
+   int        ret;
+
+   DBG("ips_read_adapter_status");
+
+   scb = &ha->scbs[ha->max_cmds-1];
+
+   ips_init_scb(ha, scb);
+
+   scb->timeout = ips_cmd_timeout;
+   scb->cdb[0] = ENQUIRY;
+
+   scb->cmd.basic_io.op_code = ENQUIRY;
+   scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
+   scb->cmd.basic_io.sg_count = 0;
+   scb->cmd.basic_io.sg_addr = VIRT_TO_BUS(ha->enq);
+   scb->cmd.basic_io.lba = 0;
+   scb->cmd.basic_io.sector_count = 0;
+   scb->cmd.basic_io.log_drv = 0;
+   scb->cmd.basic_io.reserved = 0;
+
+   /* send command */
+   ret = ips_send_wait(ha, scb, ips_cmd_timeout);
+   if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
+      return (0);
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_read_subsystem_parameters                              */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Read subsystem parameters from the adapter                             */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_read_subsystem_parameters(ips_ha_t *ha) {
+   ips_scb_t *scb;
+   int        ret;
+
+   DBG("ips_read_subsystem_parameters");
+
+   scb = &ha->scbs[ha->max_cmds-1];
+
+   ips_init_scb(ha, scb);
+
+   scb->timeout = ips_cmd_timeout;
+   scb->cdb[0] = GET_SUBSYS_PARAM;
+
+   scb->cmd.basic_io.op_code = GET_SUBSYS_PARAM;
+   scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
+   scb->cmd.basic_io.sg_count = 0;
+   scb->cmd.basic_io.sg_addr = VIRT_TO_BUS(ha->subsys);
+   scb->cmd.basic_io.lba = 0;
+   scb->cmd.basic_io.sector_count = 0;
+   scb->cmd.basic_io.log_drv = 0;
+   scb->cmd.basic_io.reserved = 0;
+
+   /* send command */
+   ret = ips_send_wait(ha, scb, ips_cmd_timeout);
+   if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
+      return (0);
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_read_config                                            */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Read the configuration on the adapter                                  */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_read_config(ips_ha_t *ha) {
+   ips_scb_t *scb;
+   int        i;
+   int        ret;
+
+   DBG("ips_read_config");
+
+   /* set defaults for initiator IDs */
+   ha->conf->init_id[0] = IPS_ADAPTER_ID;
+   for (i = 1; i < 4; i++)
+      ha->conf->init_id[i] = 7;
+
+   scb = &ha->scbs[ha->max_cmds-1];
+
+   ips_init_scb(ha, scb);
+
+   scb->timeout = ips_cmd_timeout;
+   scb->cdb[0] = READ_NVRAM_CONFIGURATION;
+
+   scb->cmd.basic_io.op_code = READ_NVRAM_CONFIGURATION;
+   scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
+   scb->cmd.basic_io.sg_addr = VIRT_TO_BUS(ha->conf);
+
+   /* send command */
+   if (((ret = ips_send_wait(ha, scb, ips_cmd_timeout)) == IPS_FAILURE) ||
+       (ret == IPS_SUCCESS_IMM) ||
+       ((scb->basic_status & GSC_STATUS_MASK) > 1)) {
+
+      memset(ha->conf, 0, sizeof(CONFCMD));
+
+      /* reset initiator IDs */
+      ha->conf->init_id[0] = IPS_ADAPTER_ID;
+      for (i = 1; i < 4; i++)
+         ha->conf->init_id[i] = 7;
+
+      return (0);
+   }
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_readwrite_page5                                        */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Read the configuration on the adapter                                  */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_readwrite_page5(ips_ha_t *ha, int write) {
+   ips_scb_t *scb;
+   int        ret;
+
+   DBG("ips_readwrite_page5");
+
+   scb = &ha->scbs[ha->max_cmds-1];
+
+   ips_init_scb(ha, scb);
+
+   scb->timeout = ips_cmd_timeout;
+   scb->cdb[0] = RW_NVRAM_PAGE;
+
+   scb->cmd.nvram.op_code = RW_NVRAM_PAGE;
+   scb->cmd.nvram.command_id = IPS_COMMAND_ID(ha, scb);
+   scb->cmd.nvram.page = 5;
+   scb->cmd.nvram.write = write;
+   scb->cmd.nvram.buffer_addr = VIRT_TO_BUS(ha->nvram);
+   scb->cmd.nvram.reserved = 0;
+   scb->cmd.nvram.reserved2 = 0;
+
+   /* issue the command */
+   if (((ret = ips_send_wait(ha, scb, ips_cmd_timeout)) == IPS_FAILURE) ||
+       (ret == IPS_SUCCESS_IMM) ||
+       ((scb->basic_status & GSC_STATUS_MASK) > 1)) {
+
+      memset(ha->nvram, 0, sizeof(NVRAM_PAGE5));
+
+      return (0);
+   }
+
+   return (1);
+}
+
+/****************************************************************************/
+/*                                                                          */
+/* Routine Name: ips_clear_adapter                                          */
+/*                                                                          */
+/* Routine Description:                                                     */
+/*                                                                          */
+/*   Clear the stripe lock tables                                           */
+/*                                                                          */
+/****************************************************************************/
+static int
+ips_clear_adapter(ips_ha_t *ha) {
+   ips_scb_t *scb;
+   int        ret;
+
+   DBG("ips_clear_adapter");
+
+   scb = &ha->scbs[ha->max_cmds-1];
+
+   ips_init_scb(ha, scb);
+
+   scb->timeout = ips_reset_timeout;
+   scb->cdb[0] = CONFIG_SYNC;
+
+   scb->cmd.config_sync.op_code = CONFIG_SYNC;
+   scb->cmd.config_sync.command_id = IPS_COMMAND_ID(ha, scb);
+   scb->cmd.config_sync.channel = 0;
+   scb->cmd.config_sync.source_target = POCL;
+   scb->cmd.config_sync.reserved = 0;
+   scb->cmd.config_sync.reserved2 = 0;
+   scb->cmd.config_sync.reserved3 = 0;
+
+   /* issue command */
+   ret = ips_send_wait(ha, scb, ips_reset_timeout);
+   if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
+      return (0);
+
+   /* send unlock stripe command */
+   ips_init_scb(ha, scb);
+
+   scb->cdb[0] = GET_ERASE_ERROR_TABLE;
+   scb->timeout = ips_reset_timeout;
+
+   scb->cmd.unlock_stripe.op_code = GET_ERASE_ERROR_TABLE;
+   scb->cmd.unlock_stripe.command_id = IPS_COMMAND_ID(ha, scb);
+   scb->cmd.unlock_stripe.log_drv = 0;
+   scb->cmd.unlock_stripe.control = CSL;
+   scb->cmd.unlock_stripe.reserved = 0;
+   scb->cmd.unlock_stripe.reserved2 = 0;
+   scb->cmd.unlock_stripe.reserved3 = 0;
+
+   /* issue command */
+   ret = ips_send_wait(ha, scb, ips_reset_timeout);
+   if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
+      return (0);
+
+   return (1);
+}
+
+#if defined (MODULE)
+
+Scsi_Host_Template driver_template = IPS;
+
+   #include "scsi_module.c"
+
+#endif
+
+
+/*
+ * Overrides for Emacs so that we almost follow Linus's tabbing style.
+ * Emacs will notice this stuff at the end of the file and automatically
+ * adjust the settings for this buffer only.  This must remain at the end
+ * of the file.
+ * ---------------------------------------------------------------------------
+ * Local variables:
+ * c-indent-level: 2
+ * c-brace-imaginary-offset: 0
+ * c-brace-offset: -2
+ * c-argdecl-indent: 2
+ * c-label-offset: -2
+ * c-continued-statement-offset: 2
+ * c-continued-brace-offset: 0
+ * indent-tabs-mode: nil
+ * tab-width: 8
+ * End:
+ */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/scsi/ips.h linux.13p4/drivers/scsi/ips.h
--- linux.vanilla/drivers/scsi/ips.h	Thu Jan  1 01:00:00 1970
+++ linux.13p4/drivers/scsi/ips.h	Fri Sep  3 14:15:06 1999
@@ -0,0 +1,837 @@
+/*****************************************************************************/
+/* ips.h -- driver for the IBM ServeRAID adapter                             */
+/*                                                                           */
+/* Written By: Keith Mitchell, IBM Corporation                               */
+/*                                                                           */
+/* Copyright (C) 1999 IBM Corporation                                        */
+/*                                                                           */
+/* 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.                              */
+/*                                                                           */
+/* NO WARRANTY                                                               */
+/* THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR        */
+/* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT      */
+/* LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,      */
+/* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is    */
+/* solely responsible for determining the appropriateness of using and       */
+/* distributing the Program and assumes all risks associated with its        */
+/* exercise of rights under this Agreement, including but not limited to     */
+/* the risks and costs of program errors, damage to or loss of data,         */
+/* programs or equipment, and unavailability or interruption of operations.  */
+/*                                                                           */
+/* DISCLAIMER OF LIABILITY                                                   */
+/* NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY   */
+/* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL        */
+/* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND   */
+/* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR     */
+/* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE    */
+/* USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED  */
+/* HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES             */
+/*                                                                           */
+/* 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 */
+/*                                                                           */
+/* Bugs/Comments/Suggestions should be mailed to:                            */
+/*      ipslinux@us.ibm.com                                                  */
+/*                                                                           */
+/*****************************************************************************/
+
+#ifndef _IPS_H_
+   #define _IPS_H_
+
+   #include <asm/uaccess.h>
+   #include <asm/io.h>
+
+   /* Prototypes */
+   extern int ips_detect(Scsi_Host_Template *);
+   extern int ips_release(struct Scsi_Host *);
+   extern int ips_abort(Scsi_Cmnd *);
+   extern int ips_reset(Scsi_Cmnd *, unsigned int);
+   extern int ips_eh_abort(Scsi_Cmnd *);
+   extern int ips_eh_reset(Scsi_Cmnd *);
+   extern int ips_queue(Scsi_Cmnd *, void (*) (Scsi_Cmnd *));
+   extern int ips_biosparam(Disk *, kdev_t, int *);
+   extern const char * ips_info(struct Scsi_Host *);
+   extern void do_ipsintr(int, void *, struct pt_regs *);
+
+   /*
+    * Some handy macros
+    */
+   #ifndef LinuxVersionCode
+      #define LinuxVersionCode(x,y,z)   (((x)<<16)+((y)<<8)+(z))
+   #endif
+
+   #define HA(x)                       ((ips_ha_t *) x->hostdata)
+   #define IPS_COMMAND_ID(ha, scb)     (int) (scb - ha->scbs)
+   #define VIRT_TO_BUS(x)              (unsigned int)virt_to_bus((void *) x)
+
+   #define UDELAY udelay
+   #define MDELAY mdelay
+
+   #define verify_area_20(t,a,sz)               (0) /* success */
+   #define PUT_USER                             put_user
+   #define __PUT_USER                           __put_user
+   #define PUT_USER_RET                         put_user_ret
+   #define GET_USER                             get_user
+   #define __GET_USER                           __get_user
+   #define GET_USER_RET                         get_user_ret
+
+/*
+ * Adapter address map equates
+ */
+   #define HISR                 0x08    /* Host Interrupt Status Reg   */
+   #define CCSAR                0x10    /* Cmd Channel System Addr Reg */
+   #define CCCR                 0x14    /* Cmd Channel Control Reg     */
+   #define SQHR                 0x20    /* Status Q Head Reg           */
+   #define SQTR                 0x24    /* Status Q Tail Reg           */
+   #define SQER                 0x28    /* Status Q End Reg            */
+   #define SQSR                 0x2C    /* Status Q Start Reg          */
+   #define SCPR                 0x05    /* Subsystem control port reg  */
+   #define ISPR                 0x06    /* interrupt status port reg   */
+   #define CBSP                 0x07    /* CBSP register               */
+
+/*
+ * Adapter register bit equates
+ */
+   #define GHI                  0x04    /* HISR General Host Interrupt */
+   #define SQO                  0x02    /* HISR Status Q Overflow      */
+   #define SCE                  0x01    /* HISR Status Channel Enqueue */
+   #define SEMAPHORE            0x08    /* CCCR Semaphore Bit          */
+   #define ILE                  0x10    /* CCCR ILE Bit                */
+   #define START_COMMAND        0x101A  /* CCCR Start Command Channel  */
+   #define START_STOP_BIT       0x0002  /* CCCR Start/Stop Bit         */
+   #define RST                  0x80    /* SCPR Reset Bit              */
+   #define EBM                  0x02    /* SCPR Enable Bus Master      */
+   #define EI                   0x80    /* HISR Enable Interrupts      */
+   #define OP                   0x01    /* OP bit in CBSP              */
+
+/*
+ * Adapter Command ID Equates
+ */
+   #define GET_LOGICAL_DRIVE_INFO               0x19
+   #define GET_SUBSYS_PARAM                     0x40
+   #define READ_NVRAM_CONFIGURATION             0x38
+   #define RW_NVRAM_PAGE                        0xBC
+   #define IPS_READ                             0x02
+   #define IPS_WRITE                            0x03
+   #define ENQUIRY                              0x05
+   #define FLUSH_CACHE                          0x0A
+   #define NORM_STATE                           0x00
+   #define READ_SCATTER_GATHER                  0x82
+   #define WRITE_SCATTER_GATHER                 0x83
+   #define DIRECT_CDB                           0x04
+   #define DIRECT_CDB_SCATTER_GATHER            0x84
+   #define CONFIG_SYNC                          0x58
+   #define POCL                                 0x30
+   #define GET_ERASE_ERROR_TABLE                0x17
+   #define RESET_CHANNEL                        0x1A
+   #define CSL                                  0xFF
+   #define ADAPT_RESET                          0xFF
+
+/*
+ * Adapter Equates
+ */
+   #define IPS_MAX_ADAPTERS                     16
+   #define IPS_MAX_IOCTL                        1
+   #define IPS_MAX_IOCTL_QUEUE                  8
+   #define IPS_MAX_QUEUE                        128
+   #define IPS_BLKSIZE                          512
+   #define MAX_SG_ELEMENTS                      17
+   #define MAX_LOGICAL_DRIVES                   8
+   #define MAX_CHANNELS                         3
+   #define MAX_TARGETS                          15
+   #define MAX_CHUNKS                           16
+   #define MAX_CMDS                             64
+   #define IPS_MAX_XFER                         0x10000
+   #define COMP_MODE_HEADS                      128
+   #define COMP_MODE_SECTORS                    32
+   #define NORM_MODE_HEADS                      254
+   #define NORM_MODE_SECTORS                    63
+   #define NVRAM_PAGE5_SIGNATURE                0xFFDDBB99
+   #define MAX_POST_BYTES                       0x02
+   #define MAX_CONFIG_BYTES                     0x02
+   #define GOOD_POST_BASIC_STATUS               0x80
+   #define SEMAPHORE_TIMEOUT                    2000
+   #define IPS_INTR_OFF                         0
+   #define IPS_INTR_ON                          1
+   #define IPS_ADAPTER_ID                       0xF
+   #define IPS_VENDORID                         0x1014
+   #define IPS_DEVICEID                         0x002E
+   #define TIMEOUT_10                           0x10
+   #define TIMEOUT_60                           0x20
+   #define TIMEOUT_20M                          0x30
+   #define STATUS_SIZE                          4
+   #define STATUS_Q_SIZE                        (MAX_CMDS+1) * STATUS_SIZE
+   #define ONE_MSEC                             1
+   #define ONE_SEC                              1000
+
+/*
+ * Adapter Basic Status Codes
+ */
+   #define BASIC_STATUS_MASK            0xFF
+   #define GSC_STATUS_MASK              0x0F
+   #define SSUCCESS                     0x00
+   #define RECOVERED_ERROR              0x01
+   #define IPS_CHECK_CONDITION          0x02
+   #define INVAL_OPCO                   0x03
+   #define INVAL_CMD_BLK                0x04
+   #define INVAL_PARM_BLK               0x05
+   #define IPS_BUSY                     0x08
+   #define ADAPT_HARDWARE_ERROR         0x09
+   #define ADAPT_FIRMWARE_ERROR         0x0A
+   #define CMD_CMPLT_WERROR             0x0C
+   #define LOG_DRV_ERROR                0x0D
+   #define CMD_TIMEOUT                  0x0E
+   #define PHYS_DRV_ERROR               0x0F
+
+/*
+ * Adapter Extended Status Equates
+ */
+   #define SELECTION_TIMEOUT                    0xF0
+   #define DATA_OVER_UNDER_RUN                  0xF2
+   #define EXT_HOST_RESET                       0xF7
+   #define EXT_DEVICE_RESET                     0xF8
+   #define EXT_RECOVERY                         0xFC
+   #define EXT_CHECK_CONDITION                  0xFF
+
+/*
+ * Operating System Defines
+ */
+   #define OS_WINDOWS_NT                        0x01
+   #define OS_NETWARE                           0x02
+   #define OS_OPENSERVER                        0x03
+   #define OS_UNIXWARE                          0x04
+   #define OS_SOLARIS                           0x05
+   #define OS_OS2                               0x06
+   #define OS_LINUX                             0x07
+   #define OS_FREEBSD                           0x08
+
+/*
+ * Adapter Command/Status Packet Definitions
+ */
+   #define IPS_SUCCESS                  0x01 /* Successfully completed       */
+   #define IPS_SUCCESS_IMM              0x02 /* Success - Immediately        */
+   #define IPS_FAILURE                  0x04 /* Completed with Error         */
+
+/*
+ * Logical Drive Equates
+ */
+   #define OFF_LINE             0x02
+   #define OKAY                 0x03
+   #define FREE                 0x00
+   #define SYS                  0x06
+   #define CRS                  0x24
+
+/*
+ * DCDB Table Equates
+ */
+   #define NO_DISCONNECT                0x00
+   #define DISCONNECT_ALLOWED           0x80
+   #define NO_AUTO_REQUEST_SENSE        0x40
+   #define DATA_IN                      0x01
+   #define DATA_OUT                     0x02
+   #define TRANSFER_64K                 0x08
+   #define NOTIMEOUT                    0x00
+   #define TIMEOUT10                    0x10
+   #define TIMEOUT60                    0x20
+   #define TIMEOUT20M                   0x30
+
+/*
+ * Host adapter Flags (bit numbers)
+ */
+   #define IPS_IN_INTR                  0
+   #define IPS_IN_ABORT                 1
+   #define IPS_IN_RESET                 2
+
+/*
+ * SCB Flags
+ */
+   #define SCB_ACTIVE                   0x00001
+   #define SCB_WAITING                  0x00002
+
+/*
+ * Passthru stuff
+ */
+   #define COPPUSRCMD                  (('C'<<8) | 65)
+   #define IPS_NUMCTRLS                (('C'<<8) | 68)
+   #define IPS_CTRLINFO                (('C'<<8) | 69)
+
+/*
+ * Scsi_Host Template
+ */
+ #define IPS {                            \
+    next : NULL,                          \
+    module : NULL,                        \
+    proc_dir : NULL,                      \
+    proc_info : NULL,                     \
+    name : NULL,                          \
+    detect : ips_detect,                  \
+    release : ips_release,                \
+    info : ips_info,                      \
+    command : NULL,                       \
+    queuecommand : ips_queue,             \
+    eh_strategy_handler : NULL,           \
+    eh_abort_handler : ips_eh_abort,      \
+    eh_device_reset_handler : NULL,       \
+    eh_bus_reset_handler : NULL,          \
+    eh_host_reset_handler : ips_eh_reset, \
+    abort : ips_abort,                    \
+    reset : ips_reset,                    \
+    slave_attach : NULL,                  \
+    bios_param : ips_biosparam,           \
+    can_queue : 0,                        \
+    this_id: -1,                          \
+    sg_tablesize : MAX_SG_ELEMENTS,       \
+    cmd_per_lun: 16,                      \
+    present : 0,                          \
+    unchecked_isa_dma : 0,                \
+    use_clustering : ENABLE_CLUSTERING,   \
+    use_new_eh_code : 1                   \
+ }
+
+/*
+ * IBM PCI Raid Command Formats
+ */
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u8        log_drv;
+   u8        sg_count;
+   u32       lba;
+   u32       sg_addr;
+   u16       sector_count;
+   u16       reserved;
+   u32       ccsar;
+   u32       cccr;
+} BASIC_IO_CMD, *PBASIC_IO_CMD;
+
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u16       reserved;
+   u32       reserved2;
+   u32       buffer_addr;
+   u32       reserved3;
+   u32       ccsar;
+   u32       cccr;
+} LOGICAL_INFO, *PLOGICAL_INFO;
+
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u8        reserved;
+   u8        reserved2;
+   u32       reserved3;
+   u32       buffer_addr;
+   u32       reserved4;
+} IOCTL_INFO, *PIOCTL_INFO;
+
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u16       reserved;
+   u32       reserved2;
+   u32       dcdb_address;
+   u32       reserved3;
+   u32       ccsar;
+   u32       cccr;
+} DCDB_CMD, *PDCDB_CMD;
+
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u8        channel;
+   u8        source_target;
+   u32       reserved;
+   u32       reserved2;
+   u32       reserved3;
+   u32       ccsar;
+   u32       cccr;
+} CONFIG_SYNC_CMD, *PCONFIG_SYNC_CMD;
+
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u8        log_drv;
+   u8        control;
+   u32       reserved;
+   u32       reserved2;
+   u32       reserved3;
+   u32       ccsar;
+   u32       cccr;
+} UNLOCK_STRIPE_CMD, *PUNLOCK_STRIPE_CMD;
+
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u8        reserved;
+   u8        state;
+   u32       reserved2;
+   u32       reserved3;
+   u32       reserved4;
+   u32       ccsar;
+   u32       cccr;
+} FLUSH_CACHE_CMD, *PFLUSH_CACHE_CMD;
+
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u8        reserved;
+   u8        desc;
+   u32       reserved2;
+   u32       buffer_addr;
+   u32       reserved3;
+   u32       ccsar;
+   u32       cccr;
+} STATUS_CMD, *PSTATUS_CMD;
+
+typedef struct {
+   u8        op_code;
+   u8        command_id;
+   u8        page;
+   u8        write;
+   u32       reserved;
+   u32       buffer_addr;
+   u32       reserved2;
+   u32       ccsar;
+   u32       cccr;
+} NVRAM_CMD, *PNVRAM_CMD;
+
+typedef union {
+   BASIC_IO_CMD      basic_io;
+   LOGICAL_INFO      logical_info;
+   IOCTL_INFO        ioctl_info;
+   DCDB_CMD          dcdb;
+   CONFIG_SYNC_CMD   config_sync;
+   UNLOCK_STRIPE_CMD unlock_stripe;
+   FLUSH_CACHE_CMD   flush_cache;
+   STATUS_CMD        status;
+   NVRAM_CMD         nvram;
+} HOST_COMMAND, *PHOST_COMMAND;
+
+typedef struct {
+   u8         logical_id;
+   u8         reserved;
+   u8         raid_level;
+   u8         state;
+   u32        sector_count;
+} DRIVE_INFO, *PDRIVE_INFO;
+
+typedef struct {
+   u8         no_of_log_drive;
+   u8         reserved[3];
+   DRIVE_INFO drive_info[MAX_LOGICAL_DRIVES];
+} LOGICAL_DRIVE_INFO, *PLOGICAL_DRIVE_INFO;
+
+typedef struct {
+   u8        ha_num;
+   u8        bus_num;
+   u8        id;
+   u8        device_type;
+   u32       data_len;
+   u32       data_ptr;
+   u8        scsi_cdb[12];
+   u32       data_counter;
+   u32       block_size;
+} NON_DISK_DEVICE_INFO, *PNON_DISK_DEVICE_INFO;
+
+typedef struct {
+   u8         device_address;
+   u8         cmd_attribute;
+   u16        transfer_length;
+   u32        buffer_pointer;
+   u8         cdb_length;
+   u8         sense_length;
+   u8         sg_count;
+   u8         reserved;
+   u8         scsi_cdb[12];
+   u8         sense_info[64];
+   u8         scsi_status;
+   u8         reserved2[3];
+} DCDB_TABLE, *PDCDB_TABLE;
+
+typedef struct {
+   volatile u8      reserved;
+   volatile u8      command_id;
+   volatile u8      basic_status;
+   volatile u8      extended_status;
+} STATUS, *PSTATUS;
+
+typedef struct {
+   STATUS               status[MAX_CMDS + 1];
+   volatile PSTATUS     p_status_start;
+   volatile PSTATUS     p_status_end;
+   volatile PSTATUS     p_status_tail;
+   volatile u32         hw_status_start;
+   volatile u32         hw_status_tail;
+   LOGICAL_DRIVE_INFO   logical_drive_info;
+} ADAPTER_AREA, *PADAPTER_AREA;
+
+typedef struct {
+   u8        ucLogDriveCount;
+   u8        ucMiscFlag;
+   u8        ucSLTFlag;
+   u8        ucBSTFlag;
+   u8        ucPwrChgCnt;
+   u8        ucWrongAdrCnt;
+   u8        ucUnidentCnt;
+   u8        ucNVramDevChgCnt;
+   u8        CodeBlkVersion[8];
+   u8        BootBlkVersion[8];
+   u32       ulDriveSize[MAX_LOGICAL_DRIVES];
+   u8        ucConcurrentCmdCount;
+   u8        ucMaxPhysicalDevices;
+   u16       usFlashRepgmCount;
+   u8        ucDefunctDiskCount;
+   u8        ucRebuildFlag;
+   u8        ucOfflineLogDrvCount;
+   u8        ucCriticalDrvCount;
+   u16       usConfigUpdateCount;
+   u8        ucBlkFlag;
+   u8        reserved;
+   u16       usAddrDeadDisk[MAX_CHANNELS * MAX_TARGETS];
+} ENQCMD, *PENQCMD;
+
+typedef struct {
+   u8        ucInitiator;
+   u8        ucParameters;
+   u8        ucMiscFlag;
+   u8        ucState;
+   u32       ulBlockCount;
+   u8        ucDeviceId[28];
+} DEVSTATE, *PDEVSTATE;
+
+typedef struct {
+   u8        ucChn;
+   u8        ucTgt;
+   u16       ucReserved;
+   u32       ulStartSect;
+   u32       ulNoOfSects;
+} CHUNK, *PCHUNK;
+
+typedef struct {
+   u16       ucUserField;
+   u8        ucState;
+   u8        ucRaidCacheParam;
+   u8        ucNoOfChunkUnits;
+   u8        ucStripeSize;
+   u8        ucParams;
+   u8        ucReserved;
+   u32       ulLogDrvSize;
+   CHUNK     chunk[MAX_CHUNKS];
+} LOGICAL_DRIVE, *PLOGICAL_DRIVE;
+
+typedef struct {
+   u8        board_disc[8];
+   u8        processor[8];
+   u8        ucNoChanType;
+   u8        ucNoHostIntType;
+   u8        ucCompression;
+   u8        ucNvramType;
+   u32       ulNvramSize;
+} HARDWARE_DISC, *PHARDWARE_DISC;
+
+typedef struct {
+   u8             ucLogDriveCount;
+   u8             ucDateD;
+   u8             ucDateM;
+   u8             ucDateY;
+   u8             init_id[4];
+   u8             host_id[12];
+   u8             time_sign[8];
+
+   struct {
+      u32         usCfgDrvUpdateCnt:16;
+      u32         ConcurDrvStartCnt:4;
+      u32         StartupDelay:4;
+      u32         auto_rearrange:1;
+      u32         cd_boot:1;
+      u32         cluster:1;
+      u32         reserved:5;
+   } UserOpt;
+
+   u16            user_field;
+   u8             ucRebuildRate;
+   u8             ucReserve;
+   HARDWARE_DISC  hardware_disc;
+   LOGICAL_DRIVE  logical_drive[MAX_LOGICAL_DRIVES];
+   DEVSTATE       dev[MAX_CHANNELS][MAX_TARGETS+1];
+   u8             reserved[512];
+
+} CONFCMD, *PCONFCMD;
+
+typedef struct {
+   u32        signature;
+   u8         reserved;
+   u8         adapter_slot;
+   u16        adapter_type;
+   u8         bios_high[4];
+   u8         bios_low[4];
+   u16        reserved2;
+   u8         reserved3;
+   u8         operating_system;
+   u8         driver_high[4];
+   u8         driver_low[4];
+   u8         reserved4[100];
+} NVRAM_PAGE5, *PNVRAM_PAGE5;
+
+typedef struct _SUBSYS_PARAM {
+   u32        param[128];
+} SUBSYS_PARAM, *PSUBSYS_PARAM;
+
+/*
+ * Inquiry Data Format
+ */
+typedef struct {
+   u8        DeviceType:5;
+   u8        DeviceTypeQualifier:3;
+   u8        DeviceTypeModifier:7;
+   u8        RemoveableMedia:1;
+   u8        Versions;
+   u8        ResponseDataFormat;
+   u8        AdditionalLength;
+   u16       Reserved;
+   u8        SoftReset:1;
+   u8        CommandQueue:1;
+   u8        Reserved2:1;
+   u8        LinkedCommands:1;
+   u8        Synchronous:1;
+   u8        Wide16Bit:1;
+   u8        Wide32Bit:1;
+   u8        RelativeAddressing:1;
+   u8        VendorId[8];
+   u8        ProductId[16];
+   u8        ProductRevisionLevel[4];
+   u8        VendorSpecific[20];
+   u8        Reserved3[40];
+} INQUIRYDATA, *PINQUIRYDATA;
+
+/*
+ * Read Capacity Data Format
+ */
+typedef struct {
+   u32       lba;
+   u32       len;
+} CAPACITY_T;
+
+/*
+ * Sense Data Format
+ */
+typedef struct {
+   u8        pg_pc:6;       /* Page Code                    */
+   u8        pg_res1:2;     /* Reserved                     */
+   u8        pg_len;        /* Page Length                  */
+   u16       pg_trk_z;      /* Tracks per zone              */
+   u16       pg_asec_z;     /* Alternate sectors per zone   */
+   u16       pg_atrk_z;     /* Alternate tracks per zone    */
+   u16       pg_atrk_v;     /* Alternate tracks per volume  */
+   u16       pg_sec_t;      /* Sectors per track            */
+   u16       pg_bytes_s;    /* Bytes per physical sectors   */
+   u16       pg_intl;       /* Interleave                   */
+   u16       pg_trkskew;    /* Track skew factor            */
+   u16       pg_cylskew;    /* Cylinder Skew Factor         */
+   u32       pg_res2:27;    /* Reserved                     */
+   u32       pg_ins:1;      /* Inhibit Slave                */
+   u32       pg_surf:1;     /* Allocate Surface Sectors     */
+   u32       pg_rmb:1;      /* Removeable                   */
+   u32       pg_hsec:1;     /* Hard sector formatting       */
+   u32       pg_ssec:1;     /* Soft sector formatting       */
+} DADF_T;
+
+typedef struct {
+   u8        pg_pc:6;        /* Page Code                     */
+   u8        pg_res1:2;      /* Reserved                      */
+   u8        pg_len;         /* Page Length                   */
+   u16       pg_cylu;        /* Number of cylinders (upper)   */
+   u8        pg_cyll;        /* Number of cylinders (lower)   */
+   u8        pg_head;        /* Number of heads               */
+   u16       pg_wrpcompu;    /* Write precomp (upper)         */
+   u32       pg_wrpcompl:8;  /* Write precomp (lower)         */
+   u32       pg_redwrcur:24; /* Reduced write current         */
+   u32       pg_drstep:16;   /* Drive step rate               */
+   u32       pg_landu:16;    /* Landing zone cylinder (upper) */
+   u32       pg_landl:8;     /* Landing zone cylinder (lower) */
+   u32       pg_res2:24;     /* Reserved                      */
+} RDDG_T;
+
+struct blk_desc {
+   u8       bd_dencode;
+   u8       bd_nblks1;
+   u8       bd_nblks2;
+   u8       bd_nblks3;
+   u8       bd_res;
+   u8       bd_blen1;
+   u8       bd_blen2;
+   u8       bd_blen3;
+};
+
+typedef struct {
+   u8       plh_len;   /* Data length             */
+   u8       plh_type;  /* Medium type             */
+   u8       plh_res:7; /* Reserved                */
+   u8       plh_wp:1;  /* Write protect           */
+   u8       plh_bdl;   /* Block descriptor length */
+} SENSE_PLH_T;
+
+typedef struct {
+   SENSE_PLH_T     plh;
+   struct blk_desc blk_desc;
+
+   union {
+      DADF_T        pg3;
+      RDDG_T        pg4;
+   } pdata;
+} ips_mdata_t;
+
+/*
+ * Scatter Gather list format
+ */
+typedef struct ips_sglist {
+   u32       address;
+   u32       length;
+} SG_LIST, *PSG_LIST;
+
+typedef struct _INFOSTR {
+   char *buffer;
+   int   length;
+   int   offset;
+   int   pos;
+} INFOSTR;
+
+/*
+ * Status Info
+ */
+typedef struct ips_stat {
+   u32       residue_len;
+   u32       scb_addr;
+} ips_stat_t;
+
+/*
+ * SCB Queue Format
+ */
+typedef struct ips_scb_queue {
+   struct ips_scb *head;
+   struct ips_scb *tail;
+   unsigned int    count;
+} ips_scb_queue_t;
+
+/*
+ * Wait queue_format
+ */
+typedef struct ips_wait_queue {
+   Scsi_Cmnd      *head;
+   Scsi_Cmnd      *tail;
+   unsigned int    count;
+} ips_wait_queue_t;
+
+typedef struct ips_ha {
+   u8                 ha_id[MAX_CHANNELS+1];
+   u32                io_addr;            /* Base I/O address           */
+   u8                 irq;                /* IRQ for adapter            */
+   u8                 ntargets;           /* Number of targets          */
+   u8                 nbus;               /* Number of buses            */
+   u8                 nlun;               /* Number of Luns             */
+   u16                ad_type;            /* Adapter type               */
+   u16                host_num;           /* Adapter number             */
+   u32                max_xfer;           /* Maximum Xfer size          */
+   u32                max_cmds;           /* Max concurrent commands    */
+   u32                num_ioctl;          /* Number of Ioctls           */
+   ips_stat_t         sp;                 /* Status packer pointer      */
+   struct ips_scb    *scbs;               /* Array of all CCBS          */
+   struct ips_scb    *scb_freelist;       /* SCB free list              */
+   ips_wait_queue_t   scb_waitlist;       /* Pending SCB list           */
+   ips_wait_queue_t   copp_waitlist;      /* Pending PT list            */
+   ips_scb_queue_t    scb_activelist;     /* Active SCB list            */
+   BASIC_IO_CMD      *dummy;              /* dummy command              */
+   ADAPTER_AREA      *adapt;              /* Adapter status area        */
+   ENQCMD            *enq;                /* Adapter Enquiry data       */
+   CONFCMD           *conf;               /* Adapter config data        */
+   NVRAM_PAGE5       *nvram;              /* NVRAM page 5 data          */
+   SUBSYS_PARAM      *subsys;             /* Subsystem parameters       */
+   u32                cmd_in_progress;    /* Current command in progress*/
+   u32                flags;              /* HA flags                   */
+   u8                 waitflag;           /* are we waiting for cmd     */
+   u8                 active;
+   u32                reserved:16;        /* reserved space             */
+   struct wait_queue *copp_queue;         /* passthru sync queue        */
+
+   #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,0)
+   spinlock_t         scb_lock;
+   spinlock_t         copp_lock;
+   #endif
+} ips_ha_t;
+
+typedef void (*scb_callback) (ips_ha_t *, struct ips_scb *);
+
+/*
+ * SCB Format
+ */
+typedef struct ips_scb {
+   HOST_COMMAND      cmd;
+   DCDB_TABLE        dcdb;
+   u8                target_id;
+   u8                bus;
+   u8                lun;
+   u8                cdb[12];
+   u32               scb_busaddr;
+   u32               data_busaddr;
+   u32               timeout;
+   u8                basic_status;
+   u8                extended_status;
+   u16               breakup;
+   u32               data_len;
+   u32               sg_len;
+   u32               flags;
+   u32               op_code;
+   SG_LIST          *sg_list;
+   Scsi_Cmnd        *scsi_cmd;
+   struct ips_scb   *q_next;
+   scb_callback      callback;
+} ips_scb_t;
+
+/*
+ * Passthru Command Format
+ */
+typedef struct {
+   u8         CoppID[4];
+   u32        CoppCmd;
+   u32        PtBuffer;
+   u8        *CmdBuffer;
+   u32        CmdBSize;
+   ips_scb_t  CoppCP;
+   u32        TimeOut;
+   u8         BasicStatus;
+   u8         ExtendedStatus;
+   u16        reserved;
+} ips_passthru_t;
+
+#endif
+
+
+
+/*
+ * Overrides for Emacs so that we almost follow Linus's tabbing style.
+ * Emacs will notice this stuff at the end of the file and automatically
+ * adjust the settings for this buffer only.  This must remain at the end
+ * of the file.
+ * ---------------------------------------------------------------------------
+ * Local variables:
+ * c-indent-level: 2
+ * c-brace-imaginary-offset: 0
+ * c-brace-offset: -2
+ * c-argdecl-indent: 2
+ * c-label-offset: -2
+ * c-continued-statement-offset: 2
+ * c-continued-brace-offset: 0
+ * indent-tabs-mode: nil
+ * tab-width: 8
+ * End:
+ */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/scsi/qlogicfc.c linux.13p4/drivers/scsi/qlogicfc.c
--- linux.vanilla/drivers/scsi/qlogicfc.c	Sat Aug 14 02:27:32 1999
+++ linux.13p4/drivers/scsi/qlogicfc.c	Wed Sep  1 13:53:19 1999
@@ -635,7 +635,8 @@
 #define AS_FIRMWARE_DEAD      -1
 #define AS_LOOP_DOWN           0
 #define AS_LOOP_GOOD           1
-#define AS_REDO_PORTDB         2
+#define AS_REDO_FABRIC_PORTDB  2
+#define AS_REDO_LOOP_PORTDB    4
 
 struct isp2x00_hostdata {
 	u_char revision;
@@ -965,30 +966,31 @@
 	}
 	printk("qlogicfc%d : Fabric found.\n", hostdata->host_id);
 
-
-	memset(&req, 0, sizeof(req));
-	
-	req.len = 8;
-	req.response_low = virt_to_bus_low32(sns_response);
-	req.response_high = virt_to_bus_high32(sns_response);
-	req.sub_len = 22;
-	req.data[0] = 0x17;
-	req.data[1] = 0x02;
-	req.data[8] = (u_char) (hostdata->port_id & 0xff);
-	req.data[9] = (u_char) (hostdata->port_id >> 8 & 0xff);
-	req.data[10] = (u_char) (hostdata->port_id >> 16 & 0xff);
-	req.data[13] = 0x01;
-	param[0] = MBOX_SEND_SNS;
-	param[1] = 30;
-	param[2] = virt_to_bus_low32(&req) >> 16;
-	param[3] = virt_to_bus_low32(&req);
-	param[6] = virt_to_bus_high32(&req) >> 16;
-	param[7] = virt_to_bus_high32(&req);
+	if (hostdata->adapter_state & AS_REDO_LOOP_PORTDB){
+	        memset(&req, 0, sizeof(req));
 	
-	isp2x00_mbox_command(host, param);
+		req.len = 8;
+		req.response_low = virt_to_bus_low32(sns_response);
+		req.response_high = virt_to_bus_high32(sns_response);
+		req.sub_len = 22;
+		req.data[0] = 0x17;
+		req.data[1] = 0x02;
+		req.data[8] = (u_char) (hostdata->port_id & 0xff);
+		req.data[9] = (u_char) (hostdata->port_id >> 8 & 0xff);
+		req.data[10] = (u_char) (hostdata->port_id >> 16 & 0xff);
+		req.data[13] = 0x01;
+		param[0] = MBOX_SEND_SNS;
+		param[1] = 30;
+		param[2] = virt_to_bus_low32(&req) >> 16;
+		param[3] = virt_to_bus_low32(&req);
+		param[6] = virt_to_bus_high32(&req) >> 16;
+		param[7] = virt_to_bus_high32(&req);
+		
+		isp2x00_mbox_command(host, param);
 	
-	if (param[0] != MBOX_COMMAND_COMPLETE)
-	        printk("qlogicfc%d : error sending RFC-4\n", hostdata->host_id);	       
+		if (param[0] != MBOX_COMMAND_COMPLETE)
+		        printk("qlogicfc%d : error sending RFC-4\n", hostdata->host_id);	       
+	}
 
 	port_id = hostdata->port_id;
 	while (!done) {
@@ -1131,9 +1133,9 @@
 
 	DEBUG(isp2x00_print_scsi_cmd(Cmnd));
 
-	if (hostdata->adapter_state == AS_REDO_PORTDB) {
-		hostdata->adapter_state = AS_LOOP_GOOD;
+	if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {
 		isp2x00_make_portdb(host);
+		hostdata->adapter_state = AS_LOOP_GOOD;
 		printk("qlogicfc%d : Port Database\n", hostdata->host_id);
 		for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
 			printk("wwn: %08x%08x  scsi_id: %x  loop_id: %x\n", (u_int) (hostdata->port_db[i].wwn >> 32), (u_int) hostdata->port_db[i].wwn, i, hostdata->port_db[i].loop_id);
@@ -1270,6 +1272,9 @@
 	}
 
 	switch (Cmnd->cmnd[0]) {
+	case TEST_UNIT_READY:
+	case START_STOP:
+	        break;
 	case WRITE_10:
 	case WRITE_6:
 	case WRITE_BUFFER:
@@ -1378,7 +1383,7 @@
 		case LOOP_UP:
 		case POINT_TO_POINT_UP:
 		        printk("qlogicfc%d : link is up\n", hostdata->host_id);
-			hostdata->adapter_state = AS_REDO_PORTDB;
+			hostdata->adapter_state = AS_REDO_FABRIC_PORTDB | AS_REDO_LOOP_PORTDB;
 			break;
 		case LOOP_DOWN:
 		        printk("qlogicfc%d : link is down\n", hostdata->host_id);
@@ -1387,12 +1392,15 @@
 		case CONNECTION_MODE:
 		        printk("received CONNECTION_MODE irq %x\n", inw(host->io_port + MBOX1));
 			break;
-		case LIP_OCCURED:
 		case CHANGE_NOTIFICATION:
+			if (hostdata->adapter_state == AS_LOOP_GOOD)
+				hostdata->adapter_state = AS_REDO_FABRIC_PORTDB;
+			break;		        
+		case LIP_OCCURED:
 		case PORT_DB_CHANGED:
 		case LIP_RECEIVED:
 			if (hostdata->adapter_state == AS_LOOP_GOOD)
-				hostdata->adapter_state = AS_REDO_PORTDB;
+				hostdata->adapter_state = AS_REDO_LOOP_PORTDB;
 			break;
 		case SYSTEM_ERROR:
 			printk("qlogicfc%d : The firmware just choked.\n", hostdata->host_id);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/scsi/sd.c linux.13p4/drivers/scsi/sd.c
--- linux.vanilla/drivers/scsi/sd.c	Sat Aug 14 02:27:33 1999
+++ linux.13p4/drivers/scsi/sd.c	Wed Sep  1 13:53:15 1999
@@ -1358,14 +1358,15 @@
 		rscsi_disks[i].capacity = 0;
 	    } else {
 		printk ("scsi : deleting disk entry.\n");
+		sd_detach(rscsi_disks[i].device);
 		rscsi_disks[i].device = NULL;
-		sd_template.nr_dev--;
-		SD_GENDISK(i).nr_real--;
 
                 /* Wake up a process waiting for device */
                 wake_up(&SCpnt->device->device_wait);
                 scsi_release_command(SCpnt);
                 SCpnt = NULL;
+		scsi_free(buffer, 512);
+		spin_unlock_irq(&io_request_lock);
                 
 		return i;
 	    }
@@ -1715,6 +1716,7 @@
 #endif
 
     sd_gendisks->part[start].nr_sects = CAPACITY;
+    if (!rscsi_disks[target].device) return -EBUSY;
     resetup_one_dev(&SD_GENDISK(target),
 		    target % SCSI_DISKS_PER_MAJOR);
 
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/sound/Config.in linux.13p4/drivers/sound/Config.in
--- linux.vanilla/drivers/sound/Config.in	Sat Aug 28 20:00:57 1999
+++ linux.13p4/drivers/sound/Config.in	Fri Sep  3 14:10:33 1999
@@ -9,9 +9,14 @@
 
 # Prompt user for primary drivers.
 
-if [ "$CONFIG_VISWS" = "y" ]; then
-    dep_tristate 'SGI Visual Workstation Sound' CONFIG_SOUND_VWSND $CONFIG_SOUND
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+  dep_tristate 'Support for C-Media PCI audio chips (Experimental)' CONFIG_SOUND_CMPCI $CONFIG_SOUND
+  if [ "$CONFIG_SOUND_CMPCI" = "y" -o "$CONFIG_SOUND_CMPCI" = "m" ]; then
+     bool 'Enable legacy FM' CONFIG_SOUND_CMPCI_FM
+     bool 'Enable legacy MPU-401' CONFIG_SOUND_CMPCI_MIDI
+  fi
 fi
+
 dep_tristate 'Ensoniq AudioPCI (ES1370)' CONFIG_SOUND_ES1370 $CONFIG_SOUND
 if [ "$CONFIG_SOUND_ES1370" = "y" ]; then
    bool 'Joystick support at boot time' CONFIG_SOUND_ES1370_JOYPORT_BOOT
@@ -29,6 +34,10 @@
 
 dep_tristate 'S3 SonicVibes' CONFIG_SOUND_SONICVIBES $CONFIG_SOUND
 
+if [ "$CONFIG_VISWS" = "y" ]; then
+    dep_tristate 'SGI Visual Workstation Sound' CONFIG_SOUND_VWSND $CONFIG_SOUND
+fi
+
 dep_tristate 'Support for Turtle Beach MultiSound Classic, Tahiti, Monterey' CONFIG_SOUND_MSNDCLAS $CONFIG_SOUND
 if [ "$CONFIG_SOUND_MSNDCLAS" = "y" -o "$CONFIG_SOUND_MSNDCLAS" = "m" ]; then
    if [ "$CONFIG_SOUND_MSNDCLAS" = "y" ]; then
@@ -79,6 +88,7 @@
    int 'MSND buffer size (kB)' CONFIG_MSND_FIFOSIZE 128
 fi
 
+
 dep_tristate 'OSS sound modules' CONFIG_SOUND_OSS $CONFIG_SOUND
 
 if [ "$CONFIG_SOUND_OSS" = "y" -o "$CONFIG_SOUND_OSS" = "m" ]; then
@@ -182,6 +192,8 @@
       fi
   fi
   
+  dep_tristate 'VIA 82C686 Audio Codec' CONFIG_SOUND_VIA82CXXX $CONFIG_SOUND_OSS
+
   dep_tristate 'Support for OPTi MAD16 and/or Mozart based cards' CONFIG_SOUND_MAD16 $CONFIG_SOUND_OSS
   if [ "$CONFIG_SOUND_MAD16" = "y" -o "$CONFIG_SOUND_MAD16" = "m" ]; then
     bool 'Support MIDI in older MAD16 based cards (requires SB)' CONFIG_MAD16_OLDCARD
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/sound/Makefile linux.13p4/drivers/sound/Makefile
--- linux.vanilla/drivers/sound/Makefile	Sat Aug 28 20:00:57 1999
+++ linux.13p4/drivers/sound/Makefile	Fri Sep  3 14:07:32 1999
@@ -53,6 +53,7 @@
 obj-$(CONFIG_SOUND_CS4232)	+= uart401.o
 obj-$(CONFIG_SOUND_GUS)		+= gus.o ad1848.o
 obj-$(CONFIG_SOUND_MAD16)	+= mad16.o ad1848.o sb.o uart401.o
+obj-$(CONFIG_SOUND_VIA82CXXX)	+= via82cxxx.o sb.o uart401.o
 obj-$(CONFIG_SOUND_MAUI)	+= maui.o mpu401.o
 obj-$(CONFIG_SOUND_MPU401)	+= mpu401.o
 obj-$(CONFIG_SOUND_MSNDCLAS)	+= msnd.o msnd_classic.o
@@ -77,6 +78,7 @@
 obj-$(CONFIG_SOUND_WAVEFRONT)   += wavefront.o
 
 #jnx
+obj-$(CONFIG_SOUND_CMPCI)	+= cmpci.o
 obj-$(CONFIG_SOUND_ES1370)	+= es1370.o
 obj-$(CONFIG_SOUND_ES1371)	+= es1371.o
 obj-$(CONFIG_SOUND_ESSSOLO1)	+= esssolo1.o
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/sound/ad1848.c linux.13p4/drivers/sound/ad1848.c
--- linux.vanilla/drivers/sound/ad1848.c	Sat Aug 14 02:25:43 1999
+++ linux.13p4/drivers/sound/ad1848.c	Wed Sep  1 13:53:21 1999
@@ -106,7 +106,7 @@
 int soundpro = 0;
 #endif
 
-static volatile char irq2dev[17] = {
+static volatile signed char irq2dev[17] = {
 	-1, -1, -1, -1, -1, -1, -1, -1,
 	-1, -1, -1, -1, -1, -1, -1, -1, -1
 };
@@ -2434,11 +2434,12 @@
 
 void attach_ms_sound(struct address_info *hw_config)
 {
-	static char     interrupt_bits[12] =
+	static signed char interrupt_bits[12] =
 	{
 		-1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20
 	};
-	char            bits, dma2_bit = 0;
+	signed char     bits;
+	char            dma2_bit = 0;
 
 	static char     dma_bits[4] =
 	{
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/sound/cmpci.c linux.13p4/drivers/sound/cmpci.c
--- linux.vanilla/drivers/sound/cmpci.c	Thu Jan  1 01:00:00 1970
+++ linux.13p4/drivers/sound/cmpci.c	Fri Sep  3 14:48:13 1999
@@ -0,0 +1,2392 @@
+/*****************************************************************************/
+
+/*
+ *      cmpci.c  --  C-Media PCI audio driver.
+ *
+ *      Copyright (C) 1999  ChenLi Tien (cltien@home.com)
+ *
+ *	Based on the PCI drivers by Thomas Sailer (sailer@ife.ee.ethz.ch)
+ *
+ *      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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Special thanks to David C. Niemi
+ *
+ *
+ * Module command line parameters:
+ *   none so far
+ *
+ *
+ *  Supported devices:
+ *  /dev/dsp    standard /dev/dsp device, (mostly) OSS compatible
+ *  /dev/mixer  standard /dev/mixer device, (mostly) OSS compatible
+ *  /dev/midi   simple MIDI UART interface, no ioctl
+ *
+ *  The card has both an FM and a Wavetable synth, but I have to figure
+ *  out first how to drive them...
+ *
+ *  Revision history
+ *    06.05.98   0.1   Initial release
+ *    10.05.98   0.2   Fixed many bugs, esp. ADC rate calculation
+ *                     First stab at a simple midi interface (no bells&whistles)
+ *    13.05.98   0.3   Fix stupid cut&paste error: set_adc_rate was called instead of
+ *                     set_dac_rate in the FMODE_WRITE case in cm_open
+ *                     Fix hwptr out of bounds (now mpg123 works)
+ *    14.05.98   0.4   Don't allow excessive interrupt rates
+ *    08.06.98   0.5   First release using Alan Cox' soundcore instead of miscdevice
+ *    03.08.98   0.6   Do not include modversions.h
+ *                     Now mixer behaviour can basically be selected between
+ *                     "OSS documented" and "OSS actual" behaviour
+ *    31.08.98   0.7   Fix realplayer problems - dac.count issues
+ *    10.12.98   0.8   Fix drain_dac trying to wait on not yet initialized DMA
+ *    16.12.98   0.9   Fix a few f_file & FMODE_ bugs
+ *    06.01.99   0.10  remove the silly SA_INTERRUPT flag.
+ *                     hopefully killed the egcs section type conflict
+ *    12.03.99   0.11  cinfo.blocks should be reset after GETxPTR ioctl.
+ *                     reported by Johan Maes <joma@telindus.be>
+ *    22.03.99   0.12  return EAGAIN instead of EBUSY when O_NONBLOCK
+ *                     read/write cannot be executed
+ *
+ */
+
+/*****************************************************************************/
+      
+#include <linux/config.h>
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/ioport.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/sound.h>
+#include <linux/malloc.h>
+#include <linux/soundcard.h>
+#include <linux/pci.h>
+#include <asm/io.h>
+#include <asm/dma.h>
+#include <linux/init.h>
+#include <linux/poll.h>
+#include <asm/spinlock.h>
+#include <asm/uaccess.h>
+#include <asm/hardirq.h>
+
+#include "dm.h"
+
+/* --------------------------------------------------------------------- */
+
+#undef OSS_DOCUMENTED_MIXER_SEMANTICS
+
+/* --------------------------------------------------------------------- */
+
+#ifndef PCI_VENDOR_ID_CMEDIA
+#define PCI_VENDOR_ID_CMEDIA         0x13F6
+#endif
+#ifndef PCI_DEVICE_ID_CMEDIA_CM8338A
+#define PCI_DEVICE_ID_CMEDIA_CM8338A 0x0100
+#endif
+#ifndef PCI_DEVICE_ID_CMEDIA_CM8338B
+#define PCI_DEVICE_ID_CMEDIA_CM8338B 0x0101
+#endif
+#ifndef PCI_DEVICE_ID_CMEDIA_CM8738
+#define PCI_DEVICE_ID_CMEDIA_CM8738  0x0111
+#endif
+
+#define CM_MAGIC  ((PCI_VENDOR_ID_CMEDIA<<16)|PCI_DEVICE_ID_CMEDIA_CM8338A)
+
+/*
+ * CM8338 registers definition
+ */
+
+#define CODEC_CMI_FUNCTRL0      (0x00)
+#define CODEC_CMI_FUNCTRL1      (0x04)
+#define CODEC_CMI_CHFORMAT      (0x08)
+#define CODEC_CMI_INT_HLDCLR    (0x0C)
+#define CODEC_CMI_INT_STATUS    (0x10)
+#define CODEC_CMI_LEGACY_CTRL   (0x14)
+#define CODEC_CMI_MISC_CTRL     (0x18)
+#define CODEC_CMI_TDMA_POS      (0x1C)
+#define CODEC_CMI_MIXER         (0x20)
+#define CODEC_SB16_DATA         (0x22)
+#define CODEC_SB16_ADDR         (0x23)
+#define CODEC_CMI_MIXER1        (0x24)
+#define CODEC_CMI_MIXER2        (0x25)
+#define CODEC_CMI_AUX_VOL       (0x26)
+#define CODEC_CMI_MISC          (0x27)
+#define CODEC_CMI_AC97          (0x28)
+
+#define CODEC_CMI_CH0_FRAME1    (0x80)
+#define CODEC_CMI_CH0_FRAME2    (0x84)
+#define CODEC_CMI_CH1_FRAME1    (0x88)
+#define CODEC_CMI_CH1_FRAME2    (0x8C)
+
+#define CODEC_CMI_EXT_REG       (0xF0)
+#define UCHAR	unsigned char
+/*
+**  Mixer registers for SB16
+*/
+
+#define DSP_MIX_DATARESETIDX    ((UCHAR)(0x00))
+
+#define DSP_MIX_MASTERVOLIDX_L  ((UCHAR)(0x30))
+#define DSP_MIX_MASTERVOLIDX_R  ((UCHAR)(0x31))
+#define DSP_MIX_VOICEVOLIDX_L   ((UCHAR)(0x32))
+#define DSP_MIX_VOICEVOLIDX_R   ((UCHAR)(0x33))
+#define DSP_MIX_FMVOLIDX_L      ((UCHAR)(0x34))
+#define DSP_MIX_FMVOLIDX_R      ((UCHAR)(0x35))
+#define DSP_MIX_CDVOLIDX_L      ((UCHAR)(0x36))
+#define DSP_MIX_CDVOLIDX_R      ((UCHAR)(0x37))
+#define DSP_MIX_LINEVOLIDX_L    ((UCHAR)(0x38))
+#define DSP_MIX_LINEVOLIDX_R    ((UCHAR)(0x39))
+
+#define DSP_MIX_MICVOLIDX       ((UCHAR)(0x3A))
+#define DSP_MIX_SPKRVOLIDX      ((UCHAR)(0x3B))
+
+#define DSP_MIX_OUTMIXIDX       ((UCHAR)(0x3C))
+
+#define DSP_MIX_ADCMIXIDX_L     ((UCHAR)(0x3D))
+#define DSP_MIX_ADCMIXIDX_R     ((UCHAR)(0x3E))
+
+#define DSP_MIX_INGAINIDX_L     ((UCHAR)(0x3F))
+#define DSP_MIX_INGAINIDX_R     ((UCHAR)(0x40))
+#define DSP_MIX_OUTGAINIDX_L    ((UCHAR)(0x41))
+#define DSP_MIX_OUTGAINIDX_R    ((UCHAR)(0x42))
+
+#define DSP_MIX_AGCIDX          ((UCHAR)(0x43))
+
+#define DSP_MIX_TREBLEIDX_L     ((UCHAR)(0x44))
+#define DSP_MIX_TREBLEIDX_R     ((UCHAR)(0x45))
+#define DSP_MIX_BASSIDX_L       ((UCHAR)(0x46))
+#define DSP_MIX_BASSIDX_R       ((UCHAR)(0x47))
+#define CM_CH0_RESET	  0x04
+#define CM_CH1_RESET	  0x08
+#define CM_EXTENT_CODEC	  0x100
+#define CM_EXTENT_MIDI	  0x2
+#define CM_EXTENT_SYNTH	  0x4
+#define CM_INT_CH0	  1
+#define CM_INT_CH1	  2
+
+#define CM_CFMT_STEREO     0x01
+#define CM_CFMT_16BIT      0x02
+#define CM_CFMT_MASK       0x03
+#define CM_CFMT_DACSHIFT   0   
+#define CM_CFMT_ADCSHIFT   2
+
+static const unsigned sample_size[] = { 1, 2, 2, 4 };
+static const unsigned sample_shift[] = { 0, 1, 1, 2 };
+
+#define CM_CENABLE_RE      0x2
+#define CM_CENABLE_PE      0x1
+
+
+/* MIDI buffer sizes */
+
+#define MIDIINBUF  256
+#define MIDIOUTBUF 256
+
+#define FMODE_MIDI_SHIFT 2
+#define FMODE_MIDI_READ  (FMODE_READ << FMODE_MIDI_SHIFT)
+#define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
+
+#define FMODE_DMFM 0x10
+
+#define SND_DEV_DSP16   5 
+
+/* --------------------------------------------------------------------- */
+
+struct cm_state {
+	/* magic */
+	unsigned int magic;
+
+	/* we keep cm cards in a linked list */
+	struct cm_state *next;
+
+	/* soundcore stuff */
+	int dev_audio;
+	int dev_mixer;
+	int dev_midi;
+	int dev_dmfm;
+
+	/* hardware resources */
+	unsigned int iosb, iobase, iosynth, iomidi, iogame, irq;
+
+        /* mixer stuff */
+        struct {
+                unsigned int modcnt;
+#ifndef OSS_DOCUMENTED_MIXER_SEMANTICS
+		unsigned short vol[13];
+#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
+        } mix;
+
+	/* wave stuff */
+	unsigned int rateadc, ratedac;
+	unsigned char fmt, enable;
+
+	spinlock_t lock;
+	struct semaphore open_sem;
+	mode_t open_mode;
+	struct wait_queue *open_wait;
+
+	struct dmabuf {
+		void *rawbuf;
+		unsigned buforder;
+		unsigned numfrag;
+		unsigned fragshift;
+		unsigned hwptr, swptr;
+		unsigned total_bytes;
+		int count;
+		unsigned error; /* over/underrun */
+		struct wait_queue *wait;
+		/* redundant, but makes calculations easier */
+		unsigned fragsize;
+		unsigned dmasize;
+		unsigned fragsamples;
+		/* OSS stuff */
+		unsigned mapped:1;
+		unsigned ready:1;
+		unsigned endcleared:1;
+		unsigned ossfragshift;
+		int ossmaxfrags;
+		unsigned subdivision;
+	} dma_dac, dma_adc;
+
+	/* midi stuff */
+	struct {
+		unsigned ird, iwr, icnt;
+		unsigned ord, owr, ocnt;
+		struct wait_queue *iwait;
+		struct wait_queue *owait;
+		struct timer_list timer;
+		unsigned char ibuf[MIDIINBUF];
+		unsigned char obuf[MIDIOUTBUF];
+	} midi;
+};
+
+/* --------------------------------------------------------------------- */
+
+static struct cm_state *devs = NULL;
+static unsigned long wavetable_mem = 0;
+
+/* --------------------------------------------------------------------- */
+
+extern __inline__ unsigned ld2(unsigned int x)
+{
+	unsigned r = 0;
+	
+	if (x >= 0x10000) {
+		x >>= 16;
+		r += 16;
+	}
+	if (x >= 0x100) {
+		x >>= 8;
+		r += 8;
+	}
+	if (x >= 0x10) {
+		x >>= 4;
+		r += 4;
+	}
+	if (x >= 4) {
+		x >>= 2;
+		r += 2;
+	}
+	if (x >= 2)
+		r++;
+	return r;
+}
+
+/*
+ * hweightN: returns the hamming weight (i.e. the number
+ * of bits set) of a N-bit word
+ */
+
+#ifdef hweight32
+#undef hweight32
+#endif
+
+extern __inline__ unsigned int hweight32(unsigned int w)
+{
+        unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
+        res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+        res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
+        res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
+        return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
+}
+
+/* --------------------------------------------------------------------- */
+
+static void set_dmadac(struct cm_state *s, unsigned int addr, unsigned int count)
+{
+	count--;
+	outl(addr, s->iobase + CODEC_CMI_CH0_FRAME1);
+	outw(count, s->iobase + CODEC_CMI_CH0_FRAME2);
+	outb(inb(s->iobase + CODEC_CMI_FUNCTRL0) & ~1, s->iobase + CODEC_CMI_FUNCTRL0);
+	outb(inb(s->iobase + CODEC_CMI_FUNCTRL0 + 2) | 1, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+}
+
+static void set_dmaadc(struct cm_state *s, unsigned int addr, unsigned int count)
+{
+	count--;
+	outl(addr, s->iobase + CODEC_CMI_CH1_FRAME1);
+	outw(count, s->iobase + CODEC_CMI_CH1_FRAME2);
+	outb(inb(s->iobase + CODEC_CMI_FUNCTRL0) | 2, s->iobase + CODEC_CMI_FUNCTRL0);
+	outb(inb(s->iobase + CODEC_CMI_FUNCTRL0 + 2) | 2, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+}
+
+extern __inline__ unsigned get_dmadac(struct cm_state *s)
+{
+	unsigned int curr_addr;
+
+	curr_addr = inl(s->iobase + CODEC_CMI_CH0_FRAME1);
+	curr_addr -= virt_to_bus(s->dma_dac.rawbuf);
+	curr_addr = s->dma_dac.dmasize - curr_addr;
+	curr_addr &= ~(sample_size[(s->fmt >> CM_CFMT_DACSHIFT) & CM_CFMT_MASK]-1);
+	return curr_addr;
+}
+
+extern __inline__ unsigned get_dmaadc(struct cm_state *s)
+{
+	unsigned int curr_addr;
+
+	curr_addr = inl(s->iobase + CODEC_CMI_CH1_FRAME1);
+	curr_addr -= virt_to_bus(s->dma_adc.rawbuf);
+	curr_addr = s->dma_adc.dmasize - curr_addr;
+	curr_addr &= ~(sample_size[(s->fmt >> CM_CFMT_ADCSHIFT) & CM_CFMT_MASK]-1);
+	return curr_addr;
+}
+
+static void wrmixer(struct cm_state *s, unsigned char idx, unsigned char data)
+{
+	outb(idx, s->iobase + CODEC_SB16_ADDR);
+	udelay(10);
+	outb(data, s->iobase + CODEC_SB16_DATA);
+	udelay(10);
+}
+
+static unsigned char rdmixer(struct cm_state *s, unsigned char idx)
+{
+	unsigned char v;
+
+	outb(idx, s->iobase + CODEC_SB16_ADDR);
+	udelay(10);
+	v = inb(s->iobase + CODEC_SB16_DATA);
+	udelay(10);
+	return v;
+}
+
+static void set_fmt(struct cm_state *s, unsigned char mask, unsigned char data)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&s->lock, flags);
+	if (mask) {
+		s->fmt = inb(s->iobase + CODEC_CMI_CHFORMAT);
+		udelay(10);
+	}
+	s->fmt = (s->fmt & mask) | data;
+	outb(s->fmt, s->iobase + CODEC_CMI_CHFORMAT);
+	spin_unlock_irqrestore(&s->lock, flags);
+	udelay(10);
+}
+
+static void frobindir(struct cm_state *s, unsigned char idx, unsigned char mask, unsigned char data)
+{
+	outb(idx, s->iobase + CODEC_SB16_ADDR);
+	udelay(10);
+	outb((inb(s->iobase + CODEC_SB16_DATA) & mask) | data, s->iobase + CODEC_SB16_DATA);
+	udelay(10);
+}
+
+static struct {
+	unsigned	rate;
+	unsigned	lower;
+	unsigned	upper;
+	unsigned char	freq;
+} rate_lookup[] =
+{
+	{ 5512,		(0 + 5512) / 2,		(5512 + 8000) / 2,	0 },
+	{ 8000,		(5512 + 8000) / 2,	(8000 + 11025) / 2,	4 },
+	{ 11025,	(8000 + 11025) / 2,	(11025 + 16000) / 2,	1 },
+	{ 16000,	(11025 + 16000) / 2,	(16000 + 22050) / 2,	5 },
+	{ 22050,	(16000 + 22050) / 2,	(22050 + 32000) / 2,	2 },
+	{ 32000,	(22050 + 32000) / 2,	(32000 + 44100) / 2,	6 },
+	{ 44100,	(32000 + 44100) / 2,	(44100 + 48000) / 2,	3 },
+	{ 48000,	48000,			48000,			7 }
+};
+
+static void set_dac_rate(struct cm_state *s, unsigned rate)
+{
+	unsigned long flags;
+	unsigned char freq = 4, val;
+	int	i;
+
+	if (rate > 48000)
+		rate = 48000;
+	if (rate < 5512)
+		rate = 5512;
+	for (i = 0; i < sizeof(rate_lookup) / sizeof(rate_lookup[0]); i++)
+	{
+		if (rate > rate_lookup[i].lower && rate <= rate_lookup[i].upper)
+		{
+			rate = rate_lookup[i].rate;
+			freq = rate_lookup[i].freq;
+			break;
+	    	}
+	}
+	s->ratedac = rate;
+	freq <<= 2;
+	spin_lock_irqsave(&s->lock, flags);
+	val = inb(s->iobase + CODEC_CMI_FUNCTRL1 + 1) & ~0x1c; 
+	outb(val | freq, s->iobase + CODEC_CMI_FUNCTRL1 + 1);
+	spin_unlock_irqrestore(&s->lock, flags);
+}
+
+static void set_adc_rate(struct cm_state *s, unsigned rate)
+{
+	unsigned long flags;
+	unsigned char freq = 4, val;
+	int	i;
+
+	if (rate > 48000)
+		rate = 48000;
+	if (rate < 5512)
+		rate = 5512;
+	for (i = 0; i < sizeof(rate_lookup) / sizeof(rate_lookup[0]); i++)
+	{
+		if (rate > rate_lookup[i].lower && rate <= rate_lookup[i].upper)
+		{
+			rate = rate_lookup[i].rate;
+			freq = rate_lookup[i].freq;
+			break;
+	    	}
+	}
+	s->rateadc = rate;
+	freq <<= 5;
+	spin_lock_irqsave(&s->lock, flags);
+	val = inb(s->iobase + CODEC_CMI_FUNCTRL1 + 1) & ~0xe0; 
+	outb(val | freq, s->iobase + CODEC_CMI_FUNCTRL1 + 1);
+	spin_unlock_irqrestore(&s->lock, flags);
+}
+
+/* --------------------------------------------------------------------- */
+
+extern inline void stop_adc(struct cm_state *s)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&s->lock, flags);
+	s->enable &= ~CM_CENABLE_RE;
+	/* disable interrupt */
+	outb(inb(s->iobase + CODEC_CMI_INT_HLDCLR + 2) & ~2, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	/* disable channel and reset */
+	outb(s->enable | CM_CH1_RESET, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+	udelay(10);
+	outb(s->enable & ~CM_CH1_RESET, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+	spin_unlock_irqrestore(&s->lock, flags);
+}	
+
+extern inline void stop_dac(struct cm_state *s)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&s->lock, flags);
+	s->enable &= ~CM_CENABLE_PE;
+	/* disable interrupt */
+	outb(inb(s->iobase + CODEC_CMI_INT_HLDCLR + 2) & ~1, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	/* disable channel and reset */
+	outb(s->enable | CM_CH0_RESET, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+	udelay(10);
+	outb(s->enable & ~CM_CH0_RESET, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+	spin_unlock_irqrestore(&s->lock, flags);
+}	
+
+static void start_dac(struct cm_state *s)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&s->lock, flags);
+	if ((s->dma_dac.mapped || s->dma_dac.count > 0) && s->dma_dac.ready) {
+		s->enable |= CM_CENABLE_PE;
+		outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+	}
+	outb(inb(s->iobase + CODEC_CMI_INT_HLDCLR + 2) | 1, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	spin_unlock_irqrestore(&s->lock, flags);
+}	
+
+static void start_adc(struct cm_state *s)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&s->lock, flags);
+	if ((s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize)) 
+	    && s->dma_adc.ready) {
+		s->enable |= CM_CENABLE_RE;
+		outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+	}
+	outb(inb(s->iobase + CODEC_CMI_INT_HLDCLR + 2) | 2, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	spin_unlock_irqrestore(&s->lock, flags);
+}	
+
+/* --------------------------------------------------------------------- */
+
+#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
+#define DMABUF_MINORDER 1
+
+static void dealloc_dmabuf(struct dmabuf *db)
+{
+	unsigned long map, mapend;
+
+	if (db->rawbuf) {
+		/* undo marking the pages as reserved */
+		mapend = MAP_NR(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
+		for (map = MAP_NR(db->rawbuf); map <= mapend; map++)
+			clear_bit(PG_reserved, &mem_map[map].flags);	
+		free_pages((unsigned long)db->rawbuf, db->buforder);
+	}
+	db->rawbuf = NULL;
+	db->mapped = db->ready = 0;
+}
+
+
+/* Ch0 is used for playback, Ch1 is used for recording */
+
+static int prog_dmabuf(struct cm_state *s, unsigned rec)
+{
+	struct dmabuf *db = rec ? &s->dma_adc : &s->dma_dac;
+	unsigned rate = rec ? s->rateadc : s->ratedac;
+	int order;
+	unsigned bytepersec;
+	unsigned bufs;
+	unsigned long map, mapend;
+	unsigned char fmt;
+	unsigned long flags;
+
+	spin_lock_irqsave(&s->lock, flags);
+	fmt = s->fmt;
+	if (rec) {
+		s->enable &= ~CM_CENABLE_RE;
+		fmt >>= CM_CFMT_ADCSHIFT;
+	} else {
+		s->enable &= ~CM_CENABLE_PE;
+		fmt >>= CM_CFMT_DACSHIFT;
+	}
+	outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+	spin_unlock_irqrestore(&s->lock, flags);
+	fmt &= CM_CFMT_MASK;
+	db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
+	if (!db->rawbuf) {
+		db->ready = db->mapped = 0;
+		for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER && !db->rawbuf; order--)
+			db->rawbuf = (void *)__get_free_pages(GFP_KERNEL | GFP_DMA, order);
+		if (!db->rawbuf)
+			return -ENOMEM;
+		db->buforder = order;
+		if ((virt_to_bus(db->rawbuf) ^ (virt_to_bus(db->rawbuf) + (PAGE_SIZE << db->buforder) - 1)) & ~0xffff)
+			printk(KERN_DEBUG "cm: DMA buffer crosses 64k boundary: busaddr 0x%lx  size %ld\n", 
+			       virt_to_bus(db->rawbuf), PAGE_SIZE << db->buforder);
+		if ((virt_to_bus(db->rawbuf) + (PAGE_SIZE << db->buforder) - 1) & ~0xffffff)
+			printk(KERN_DEBUG "cm: DMA buffer beyond 16MB: busaddr 0x%lx  size %ld\n", 
+			       virt_to_bus(db->rawbuf), PAGE_SIZE << db->buforder);
+		/* now mark the pages as reserved; otherwise remap_page_range doesn't do what we want */
+		mapend = MAP_NR(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
+		for (map = MAP_NR(db->rawbuf); map <= mapend; map++)
+			set_bit(PG_reserved, &mem_map[map].flags);
+	}
+	bytepersec = rate << sample_shift[fmt];
+	bufs = PAGE_SIZE << db->buforder;
+	if (db->ossfragshift) {
+		if ((1000 << db->ossfragshift) < bytepersec)
+			db->fragshift = ld2(bytepersec/1000);
+		else
+			db->fragshift = db->ossfragshift;
+	} else {
+		db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
+		if (db->fragshift < 3)
+			db->fragshift = 3;
+	}
+	db->numfrag = bufs >> db->fragshift;
+	while (db->numfrag < 4 && db->fragshift > 3) {
+		db->fragshift--;
+		db->numfrag = bufs >> db->fragshift;
+	}
+	db->fragsize = 1 << db->fragshift;
+	if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
+		db->numfrag = db->ossmaxfrags;
+#if 1
+	/* to make fragsize >= 4096 */
+	while (db->fragsize < 4096 && db->numfrag >= 4)
+	{
+		db->fragsize *= 2;
+		db->fragshift++;
+		db->numfrag /= 2;
+	}
+#endif
+	db->fragsamples = db->fragsize >> sample_shift[fmt];
+	db->dmasize = db->numfrag << db->fragshift;
+	memset(db->rawbuf, (fmt & CM_CFMT_16BIT) ? 0 : 0x80, db->dmasize);
+	spin_lock_irqsave(&s->lock, flags);
+	if (rec) {
+		set_dmaadc(s, virt_to_bus(db->rawbuf), db->dmasize >> sample_shift[fmt]);
+		/* program sample counts */
+		outw(db->fragsamples-1, s->iobase + CODEC_CMI_CH1_FRAME2 + 2);
+	} else {
+		set_dmadac(s, virt_to_bus(db->rawbuf), db->dmasize >> sample_shift[fmt]);
+		/* program sample counts */
+		outw(db->fragsamples-1, s->iobase + CODEC_CMI_CH0_FRAME2 + 2);
+	}
+	spin_unlock_irqrestore(&s->lock, flags);
+	db->ready = 1;
+	return 0;
+}
+
+extern __inline__ void clear_advance(struct cm_state *s)
+{
+	unsigned char c = (s->fmt & (CM_CFMT_16BIT << CM_CFMT_DACSHIFT)) ? 0 : 0x80;
+	unsigned char *buf = s->dma_dac.rawbuf;
+	unsigned bsize = s->dma_dac.dmasize;
+	unsigned bptr = s->dma_dac.swptr;
+	unsigned len = s->dma_dac.fragsize;
+
+	if (bptr + len > bsize) {
+		unsigned x = bsize - bptr;
+		memset(buf + bptr, c, x);
+		bptr = 0;
+		len -= x;
+	}
+	memset(buf + bptr, c, len);
+}
+
+/* call with spinlock held! */
+static void cm_update_ptr(struct cm_state *s)
+{
+	unsigned hwptr;
+	int diff;
+
+	/* update ADC pointer */
+	if (s->dma_adc.ready) {
+		hwptr = (s->dma_adc.dmasize - get_dmaadc(s)) % s->dma_adc.dmasize;
+		diff = (s->dma_adc.dmasize + hwptr - s->dma_adc.hwptr) % s->dma_adc.dmasize;
+		s->dma_adc.hwptr = hwptr;
+		s->dma_adc.total_bytes += diff;
+		s->dma_adc.count += diff;
+		if (s->dma_adc.count >= (signed)s->dma_adc.fragsize) 
+			wake_up(&s->dma_adc.wait);
+		if (!s->dma_adc.mapped) {
+			if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
+				s->enable &= ~CM_CENABLE_RE;
+				outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+				s->dma_adc.error++;
+			}
+		}
+	}
+	/* update DAC pointer */
+	if (s->dma_dac.ready) {
+		hwptr = (s->dma_dac.dmasize - get_dmadac(s)) % s->dma_dac.dmasize;
+		diff = (s->dma_dac.dmasize + hwptr - s->dma_dac.hwptr) % s->dma_dac.dmasize;
+		s->dma_dac.hwptr = hwptr;
+		s->dma_dac.total_bytes += diff;
+		if (s->dma_dac.mapped) {
+			s->dma_dac.count += diff;
+			if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
+				wake_up(&s->dma_dac.wait);
+		} else {
+			s->dma_dac.count -= diff;
+			if (s->dma_dac.count <= 0) {
+				s->enable &= ~CM_CENABLE_PE;
+				outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
+				s->dma_dac.error++;
+			} else if (s->dma_dac.count <= (signed)s->dma_dac.fragsize && !s->dma_dac.endcleared) {
+				clear_advance(s);
+				s->dma_dac.endcleared = 1;
+			}
+			if (s->dma_dac.count + (signed)s->dma_dac.fragsize <= (signed)s->dma_dac.dmasize)
+				wake_up(&s->dma_dac.wait);
+		}
+	}
+}
+
+/* hold spinlock for the following! */
+static void cm_handle_midi(struct cm_state *s)
+{
+	unsigned char ch;
+	int wake;
+
+	wake = 0;
+	while (!(inb(s->iomidi+1) & 0x80)) {
+		ch = inb(s->iomidi);
+		if (s->midi.icnt < MIDIINBUF) {
+			s->midi.ibuf[s->midi.iwr] = ch;
+			s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF;
+			s->midi.icnt++;
+		}
+		wake = 1;
+	}
+	if (wake)
+		wake_up(&s->midi.iwait);
+	wake = 0;
+	while (!(inb(s->iomidi+1) & 0x40) && s->midi.ocnt > 0) {
+		outb(s->midi.obuf[s->midi.ord], s->iomidi);
+		s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF;
+		s->midi.ocnt--;
+		if (s->midi.ocnt < MIDIOUTBUF-16)
+			wake = 1;
+	}
+	if (wake)
+		wake_up(&s->midi.owait);
+}
+
+static void cm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+        struct cm_state *s = (struct cm_state *)dev_id;
+	unsigned int intsrc, intstat;
+	
+	/* fastpath out, to ease interrupt sharing */
+	intsrc = inb(s->iobase + CODEC_CMI_INT_STATUS);
+	if (!(intsrc & (CM_INT_CH0 | CM_INT_CH1)))
+		return;
+	spin_lock(&s->lock);
+	intstat = inb(s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	/* disable interrupt */
+	if (intsrc & CM_INT_CH0)
+		outb(intstat & ~1, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	if (intsrc & CM_INT_CH1)
+		outb(intstat & ~2, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	cm_update_ptr(s);
+#ifdef SOUND_CONFIG_CMPCI_MIDI
+	cm_handle_midi(s);
+#endif
+	/* enable interrupt */
+	if (intsrc & CM_INT_CH0)
+		outb(intstat | 1, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	if (intsrc & CM_INT_CH1)
+		outb(intstat | 2, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
+	spin_unlock(&s->lock);
+}
+
+static void cm_midi_timer(unsigned long data)
+{
+	struct cm_state *s = (struct cm_state *)data;
+	unsigned long flags;
+	
+	spin_lock_irqsave(&s->lock, flags);
+	cm_handle_midi(s);
+	spin_unlock_irqrestore(&s->lock, flags);
+	s->midi.timer.expires = jiffies+1;
+	add_timer(&s->midi.timer);
+}
+
+/* --------------------------------------------------------------------- */
+
+static const char invalid_magic[] = KERN_CRIT "cm: invalid magic value\n";
+
+#ifdef CONFIG_SOUND_CMPCI	/* support multiple chips */
+#define VALIDATE_STATE(s)
+#else
+#define VALIDATE_STATE(s)                         \
+({                                                \
+	if (!(s) || (s)->magic != CM_MAGIC) { \
+		printk(invalid_magic);            \
+		return -ENXIO;                    \
+	}                                         \
+})
+#endif
+
+/* --------------------------------------------------------------------- */
+
+#define MT_4          1
+#define MT_5MUTE      2
+#define MT_4MUTEMONO  3
+#define MT_6MUTE      4
+
+static const struct {
+	unsigned left;
+	unsigned right;
+	unsigned type;
+	unsigned rec;
+	unsigned play;
+} mixtable[SOUND_MIXER_NRDEVICES] = {
+	[SOUND_MIXER_CD]     = { DSP_MIX_CDVOLIDX_L,     DSP_MIX_CDVOLIDX_R,     MT_5MUTE,     0x04, 0x02 },
+	[SOUND_MIXER_LINE]   = { DSP_MIX_LINEVOLIDX_L,   DSP_MIX_LINEVOLIDX_R,   MT_5MUTE,     0x10, 0x08 },
+	[SOUND_MIXER_MIC]    = { DSP_MIX_MICVOLIDX,      CODEC_CMI_MIXER2,       MT_4MUTEMONO, 0x01, 0x01 },
+	[SOUND_MIXER_SYNTH]  = { DSP_MIX_FMVOLIDX_L,  	 DSP_MIX_FMVOLIDX_R,     MT_5MUTE,     0x40, 0x00 },
+	[SOUND_MIXER_VOLUME] = { DSP_MIX_MASTERVOLIDX_L, DSP_MIX_MASTERVOLIDX_R, MT_5MUTE,     0x00, 0x00 },
+	[SOUND_MIXER_PCM]    = { DSP_MIX_VOICEVOLIDX_L,  DSP_MIX_VOICEVOLIDX_R,  MT_5MUTE,     0x00, 0x00 }
+};
+
+#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
+
+static int return_mixval(struct cm_state *s, unsigned i, int *arg)
+{
+	unsigned long flags;
+	unsigned char l, r, rl, rr;
+
+	spin_lock_irqsave(&s->lock, flags);
+	l = rdmixer(s, mixtable[i].left);
+	r = rdmixer(s, mixtable[i].right);
+	spin_unlock_irqrestore(&s->lock, flags);
+	switch (mixtable[i].type) {
+	case MT_4:
+		r &= 0xf;
+		l &= 0xf;
+		rl = 10 + 6 * (l & 15);
+		rr = 10 + 6 * (r & 15);
+		break;
+
+	case MT_4MUTEMONO:
+		rl = 55 - 3 * (l & 15);
+		if (r & 0x10)
+			rl += 45;
+		rr = rl;
+		r = l;
+		break;
+
+	case MT_5MUTE:
+	default:
+		rl = 100 - 3 * (l & 31);
+		rr = 100 - 3 * (r & 31);
+		break;
+				
+	case MT_6MUTE:
+		rl = 100 - 3 * (l & 63) / 2;
+		rr = 100 - 3 * (r & 63) / 2;
+		break;
+	}
+	if (l & 0x80)
+		rl = 0;
+	if (r & 0x80)
+		rr = 0;
+	return put_user((rr << 8) | rl, arg);
+}
+
+#else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
+
+static const unsigned char volidx[SOUND_MIXER_NRDEVICES] = 
+{
+	[SOUND_MIXER_CD]     = 1,
+	[SOUND_MIXER_LINE]   = 2,
+	[SOUND_MIXER_MIC]    = 3,
+	[SOUND_MIXER_SYNTH]  = 4,
+	[SOUND_MIXER_VOLUME] = 5,
+	[SOUND_MIXER_PCM]    = 6
+};
+
+#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
+
+static unsigned mixer_recmask(struct cm_state *s)
+{
+	unsigned long flags;
+	int i, j, k;
+
+	spin_lock_irqsave(&s->lock, flags);
+	j = rdmixer(s, DSP_MIX_ADCMIXIDX_L);
+	spin_unlock_irqrestore(&s->lock, flags);
+	j &= 0x7f;
+	for (k = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
+		if (j & mixtable[i].rec)
+			k |= 1 << i;
+	return k;
+}
+
+static int mixer_ioctl(struct cm_state *s, unsigned int cmd, unsigned long arg)
+{
+	unsigned long flags;
+	int i, val, j;
+	unsigned char l, r, rl, rr;
+
+	VALIDATE_STATE(s);
+        if (cmd == SOUND_MIXER_INFO) {
+		mixer_info info;
+		strncpy(info.id, "cmpci", sizeof(info.id));
+		strncpy(info.name, "C-Media PCI", sizeof(info.name));
+		info.modify_counter = s->mix.modcnt;
+		if (copy_to_user((void *)arg, &info, sizeof(info)))
+			return -EFAULT;
+		return 0;
+	}
+	if (cmd == SOUND_OLD_MIXER_INFO) {
+		_old_mixer_info info;
+		strncpy(info.id, "cmpci", sizeof(info.id));
+		strncpy(info.name, "C-Media cmpci", sizeof(info.name));
+		if (copy_to_user((void *)arg, &info, sizeof(info)))
+			return -EFAULT;
+		return 0;
+	}
+	if (cmd == OSS_GETVERSION)
+		return put_user(SOUND_VERSION, (int *)arg);
+	if (_IOC_TYPE(cmd) != 'M' || _IOC_SIZE(cmd) != sizeof(int))
+                return -EINVAL;
+        if (_IOC_DIR(cmd) == _IOC_READ) {
+                switch (_IOC_NR(cmd)) {
+                case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
+			return put_user(mixer_recmask(s), (int *)arg);
+			
+                case SOUND_MIXER_OUTSRC: /* Arg contains a bit for each recording source */
+			return put_user(mixer_recmask(s), (int *)arg);//need fix
+			
+                case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
+			for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
+				if (mixtable[i].type)
+					val |= 1 << i;
+			return put_user(val, (int *)arg);
+
+                case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
+			for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
+				if (mixtable[i].rec)
+					val |= 1 << i;
+			return put_user(val, (int *)arg);
+			
+                case SOUND_MIXER_OUTMASK: /* Arg contains a bit for each supported recording source */
+			for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
+				if (mixtable[i].play)
+					val |= 1 << i;
+			return put_user(val, (int *)arg);
+			
+                 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
+			for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
+				if (mixtable[i].type && mixtable[i].type != MT_4MUTEMONO)
+					val |= 1 << i;
+			return put_user(val, (int *)arg);
+			
+                case SOUND_MIXER_CAPS:
+			return put_user(0, (int *)arg);
+
+		default:
+			i = _IOC_NR(cmd);
+                        if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
+                                return -EINVAL;
+#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
+			return return_mixval(s, i, (int *)arg);
+#else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
+			if (!volidx[i])
+				return -EINVAL;
+			return put_user(s->mix.vol[volidx[i]-1], (int *)arg);
+#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
+		}
+	}
+        if (_IOC_DIR(cmd) != (_IOC_READ|_IOC_WRITE)) 
+		return -EINVAL;
+	s->mix.modcnt++;
+	switch (_IOC_NR(cmd)) {
+	case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
+		get_user_ret(val, (int *)arg, -EFAULT);
+		i = hweight32(val);
+		for (j = i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
+			if (!(val & (1 << i)))
+				continue;
+			if (!mixtable[i].rec) {
+				val &= ~(1 << i);
+				continue;
+			}
+			j |= mixtable[i].rec;
+		}
+		spin_lock_irqsave(&s->lock, flags);
+		wrmixer(s, DSP_MIX_ADCMIXIDX_L, j);
+		wrmixer(s, DSP_MIX_ADCMIXIDX_R, (j & 1) | j>>1);
+		spin_unlock_irqrestore(&s->lock, flags);
+		return 0;
+
+	case SOUND_MIXER_OUTSRC: /* Arg contains a bit for each recording source */
+		get_user_ret(val, (int *)arg, -EFAULT);
+		for (j = i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
+			if (!(val & (1 << i)))
+				continue;
+			if (!mixtable[i].play) {
+				val &= ~(1 << i);
+				continue;
+			}
+			j |= mixtable[i].play;
+		}
+		spin_lock_irqsave(&s->lock, flags);
+		frobindir(s, DSP_MIX_OUTMIXIDX, 0x1f, j);
+		spin_unlock_irqrestore(&s->lock, flags);
+		return 0;
+
+		default:
+		i = _IOC_NR(cmd);
+		if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
+			return -EINVAL;
+		get_user_ret(val, (int *)arg, -EFAULT);
+		l = val & 0xff;
+		r = (val >> 8) & 0xff;
+		if (l > 100)
+			l = 100;
+		if (r > 100)
+			r = 100;
+		spin_lock_irqsave(&s->lock, flags);
+		switch (mixtable[i].type) {
+		case MT_4:
+			if (l >= 10)
+				l -= 10;
+			if (r >= 10)
+				r -= 10;
+			frobindir(s, mixtable[i].left, 0xf0, l / 6);
+			frobindir(s, mixtable[i].right, 0xf0, l / 6);
+			break;
+
+		case MT_4MUTEMONO:
+			rl = (l < 4 ? 0 : (l - 5) / 3) & 31;
+			rr = (rl >> 2) & 7;
+			wrmixer(s, mixtable[i].left, rl<<3);
+			outb((inb(s->iobase + CODEC_CMI_MIXER2) & ~0x0e) | rr<<1, s->iobase + CODEC_CMI_MIXER2);
+			break;
+			
+		case MT_5MUTE:
+			rl = l < 4 ? 0 : (l - 5) / 3;
+			rr = r < 4 ? 0 : (r - 5) / 3;
+ 			wrmixer(s, mixtable[i].left, rl<<3);
+			wrmixer(s, mixtable[i].right, rr<<3);
+			break;
+				
+		case MT_6MUTE:
+			if (l < 6)
+				rl = 0x00;
+			else
+				rl = l * 2 / 3;
+			if (r < 6)
+				rr = 0x00;
+			else
+				rr = r * 2 / 3;
+			wrmixer(s, mixtable[i].left, rl);
+			wrmixer(s, mixtable[i].right, rr);
+			break;
+		}
+		spin_unlock_irqrestore(&s->lock, flags);
+#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
+                return return_mixval(s, i, (int *)arg);
+#else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
+		if (!volidx[i])
+			return -EINVAL;
+		s->mix.vol[volidx[i]-1] = val;
+		return put_user(s->mix.vol[volidx[i]-1], (int *)arg);
+#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
+	}
+}
+
+/* --------------------------------------------------------------------- */
+
+static loff_t cm_llseek(struct file *file, loff_t offset, int origin)
+{
+	return -ESPIPE;
+}
+
+/* --------------------------------------------------------------------- */
+
+static int cm_open_mixdev(struct inode *inode, struct file *file)
+{
+	int minor = MINOR(inode->i_rdev);
+	struct cm_state *s = devs;
+
+	while (s && s->dev_mixer != minor)
+		s = s->next;
+	if (!s)
+		return -ENODEV;
+       	VALIDATE_STATE(s);
+	file->private_data = s;
+	MOD_INC_USE_COUNT;
+	return 0;
+}
+
+static int cm_release_mixdev(struct inode *inode, struct file *file)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	
+	VALIDATE_STATE(s);
+	MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+static int cm_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+	return mixer_ioctl((struct cm_state *)file->private_data, cmd, arg);
+}
+
+static /*const*/ struct file_operations cm_mixer_fops = {
+	&cm_llseek,
+	NULL,  /* read */
+	NULL,  /* write */
+	NULL,  /* readdir */
+	NULL,  /* poll */
+	&cm_ioctl_mixdev,
+	NULL,  /* mmap */
+	&cm_open_mixdev,
+	NULL,	/* flush */
+	&cm_release_mixdev,
+	NULL,  /* fsync */
+	NULL,  /* fasync */
+	NULL,  /* check_media_change */
+	NULL,  /* revalidate */
+	NULL,  /* lock */
+};
+
+/* --------------------------------------------------------------------- */
+
+static int drain_dac(struct cm_state *s, int nonblock)
+{
+        struct wait_queue wait = { current, NULL };
+	unsigned long flags;
+	int count, tmo;
+
+	if (s->dma_dac.mapped || !s->dma_dac.ready)
+		return 0;
+        current->state = TASK_INTERRUPTIBLE;
+        add_wait_queue(&s->dma_dac.wait, &wait);
+        for (;;) {
+                spin_lock_irqsave(&s->lock, flags);
+		count = s->dma_dac.count;
+                spin_unlock_irqrestore(&s->lock, flags);
+		if (count <= 0)
+			break;
+		if (signal_pending(current))
+                        break;
+                if (nonblock) {
+                        remove_wait_queue(&s->dma_dac.wait, &wait);
+                        current->state = TASK_RUNNING;
+                        return -EBUSY;
+                }
+		tmo = (count * HZ) / s->ratedac;
+		tmo >>= sample_shift[(s->fmt >> CM_CFMT_DACSHIFT) & CM_CFMT_MASK];
+		if (!schedule_timeout(tmo ? : 1) && tmo)
+			printk(KERN_DEBUG "cm: dma timed out??\n");
+        }
+        remove_wait_queue(&s->dma_dac.wait, &wait);
+        current->state = TASK_RUNNING;
+        if (signal_pending(current))
+                return -ERESTARTSYS;
+        return 0;
+}
+
+/* --------------------------------------------------------------------- */
+
+static ssize_t cm_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	ssize_t ret;
+	unsigned long flags;
+	unsigned swptr;
+	int cnt;
+
+	VALIDATE_STATE(s);
+	if (ppos != &file->f_pos)
+		return -ESPIPE;
+	if (s->dma_adc.mapped)
+		return -ENXIO;
+	if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
+		return ret;
+	if (!access_ok(VERIFY_WRITE, buffer, count))
+		return -EFAULT;
+	ret = 0;
+#if 0
+   spin_lock_irqsave(&s->lock, flags);
+   cm_update_ptr(s);
+   spin_unlock_irqrestore(&s->lock, flags);
+#endif
+	while (count > 0) {
+		spin_lock_irqsave(&s->lock, flags);
+		swptr = s->dma_adc.swptr;
+		cnt = s->dma_adc.dmasize-swptr;
+		if (s->dma_adc.count < cnt)
+			cnt = s->dma_adc.count;
+		spin_unlock_irqrestore(&s->lock, flags);
+		if (cnt > count)
+			cnt = count;
+		if (cnt <= 0) {
+			start_adc(s);
+			if (file->f_flags & O_NONBLOCK)
+				return ret ? ret : -EAGAIN;
+			interruptible_sleep_on(&s->dma_adc.wait);
+			if (signal_pending(current))
+				return ret ? ret : -ERESTARTSYS;
+			continue;
+		}
+		if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt))
+			return ret ? ret : -EFAULT;
+		swptr = (swptr + cnt) % s->dma_adc.dmasize;
+		spin_lock_irqsave(&s->lock, flags);
+		s->dma_adc.swptr = swptr;
+		s->dma_adc.count -= cnt;
+		spin_unlock_irqrestore(&s->lock, flags);
+		count -= cnt;
+		buffer += cnt;
+		ret += cnt;
+		start_adc(s);
+	}
+	return ret;
+}
+
+static ssize_t cm_write(struct file *file, const char *buffer, size_t count, loff_t *ppos)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	ssize_t ret;
+	unsigned long flags;
+	unsigned swptr;
+	int cnt;
+
+	VALIDATE_STATE(s);
+	if (ppos != &file->f_pos)
+		return -ESPIPE;
+	if (s->dma_dac.mapped)
+		return -ENXIO;
+	if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
+		return ret;
+	if (!access_ok(VERIFY_READ, buffer, count))
+		return -EFAULT;
+	ret = 0;
+#if 0
+   spin_lock_irqsave(&s->lock, flags);
+   cm_update_ptr(s);
+   spin_unlock_irqrestore(&s->lock, flags);
+#endif
+	while (count > 0) {
+		spin_lock_irqsave(&s->lock, flags);
+		if (s->dma_dac.count < 0) {
+			s->dma_dac.count = 0;
+			s->dma_dac.swptr = s->dma_dac.hwptr;
+		}
+		swptr = s->dma_dac.swptr;
+		cnt = s->dma_dac.dmasize-swptr;
+		if (s->dma_dac.count + cnt > s->dma_dac.dmasize)
+			cnt = s->dma_dac.dmasize - s->dma_dac.count;
+		spin_unlock_irqrestore(&s->lock, flags);
+		if (cnt > count)
+			cnt = count;
+		if (cnt <= 0) {
+			start_dac(s);
+			if (file->f_flags & O_NONBLOCK)
+				return ret ? ret : -EAGAIN;
+			interruptible_sleep_on(&s->dma_dac.wait);
+			if (signal_pending(current))
+				return ret ? ret : -ERESTARTSYS;
+			continue;
+		}
+		if (copy_from_user(s->dma_dac.rawbuf + swptr, buffer, cnt))
+			return ret ? ret : -EFAULT;
+		swptr = (swptr + cnt) % s->dma_dac.dmasize;
+		spin_lock_irqsave(&s->lock, flags);
+		s->dma_dac.swptr = swptr;
+		s->dma_dac.count += cnt;
+		s->dma_dac.endcleared = 0;
+		spin_unlock_irqrestore(&s->lock, flags);
+		count -= cnt;
+		buffer += cnt;
+		ret += cnt;
+		start_dac(s);
+	}
+	return ret;
+}
+
+static unsigned int cm_poll(struct file *file, struct poll_table_struct *wait)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	unsigned long flags;
+	unsigned int mask = 0;
+
+	VALIDATE_STATE(s);
+	if (file->f_mode & FMODE_WRITE)
+		poll_wait(file, &s->dma_dac.wait, wait);
+	if (file->f_mode & FMODE_READ)
+		poll_wait(file, &s->dma_adc.wait, wait);
+	spin_lock_irqsave(&s->lock, flags);
+	cm_update_ptr(s);
+	if (file->f_mode & FMODE_READ) {
+		if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
+			mask |= POLLIN | POLLRDNORM;
+	}
+	if (file->f_mode & FMODE_WRITE) {
+		if (s->dma_dac.mapped) {
+			if (s->dma_dac.count >= (signed)s->dma_dac.fragsize) 
+				mask |= POLLOUT | POLLWRNORM;
+		} else {
+			if ((signed)s->dma_dac.dmasize >= s->dma_dac.count + (signed)s->dma_dac.fragsize)
+				mask |= POLLOUT | POLLWRNORM;
+		}
+	}
+	spin_unlock_irqrestore(&s->lock, flags);
+	return mask;
+}
+
+static int cm_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	struct dmabuf *db;
+	int ret;
+	unsigned long size;
+
+	VALIDATE_STATE(s);
+	if (vma->vm_flags & VM_WRITE) {
+		if ((ret = prog_dmabuf(s, 1)) != 0)
+			return ret;
+		db = &s->dma_dac;
+	} else if (vma->vm_flags & VM_READ) {
+		if ((ret = prog_dmabuf(s, 0)) != 0)
+			return ret;
+		db = &s->dma_adc;
+	} else 
+		return -EINVAL;
+	if (vma->vm_offset != 0)
+		return -EINVAL;
+	size = vma->vm_end - vma->vm_start;
+	if (size > (PAGE_SIZE << db->buforder))
+		return -EINVAL;
+	if (remap_page_range(vma->vm_start, virt_to_phys(db->rawbuf), size, vma->vm_page_prot))
+		return -EAGAIN;
+	db->mapped = 1;
+	return 0;
+}
+
+static int cm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	unsigned long flags;
+        audio_buf_info abinfo;
+        count_info cinfo;
+	int val, mapped, ret;
+	unsigned char fmtm, fmtd;
+
+	VALIDATE_STATE(s);
+        mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
+		((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
+	switch (cmd) {
+	case OSS_GETVERSION:
+		return put_user(SOUND_VERSION, (int *)arg);
+
+	case SNDCTL_DSP_SYNC:
+		if (file->f_mode & FMODE_WRITE)
+			return drain_dac(s, 0/*file->f_flags & O_NONBLOCK*/);
+		return 0;
+		
+	case SNDCTL_DSP_SETDUPLEX:
+		return 0;
+
+	case SNDCTL_DSP_GETCAPS:
+		return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg);
+		
+        case SNDCTL_DSP_RESET:
+		if (file->f_mode & FMODE_WRITE) {
+			stop_dac(s);
+			synchronize_irq();
+			s->dma_dac.swptr = s->dma_dac.hwptr = s->dma_dac.count = s->dma_dac.total_bytes = 0;
+		}
+		if (file->f_mode & FMODE_READ) {
+			stop_adc(s);
+			synchronize_irq();
+			s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
+		}
+		return 0;
+
+        case SNDCTL_DSP_SPEED:
+                get_user_ret(val, (int *)arg, -EFAULT);
+		if (val >= 0) {
+			if (file->f_mode & FMODE_READ) {
+				stop_adc(s);
+				s->dma_adc.ready = 0;
+				set_adc_rate(s, val);
+			}
+			if (file->f_mode & FMODE_WRITE) {
+				stop_dac(s);
+				s->dma_dac.ready = 0;
+				set_dac_rate(s, val);
+			}
+		}
+		return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, (int *)arg);
+		
+        case SNDCTL_DSP_STEREO:
+                get_user_ret(val, (int *)arg, -EFAULT);
+		fmtd = 0;
+		fmtm = ~0;
+		if (file->f_mode & FMODE_READ) {
+			stop_adc(s);
+			s->dma_adc.ready = 0;
+			if (val)
+				fmtd |= CM_CFMT_STEREO << CM_CFMT_ADCSHIFT;
+			else
+				fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_ADCSHIFT);
+		}
+		if (file->f_mode & FMODE_WRITE) {
+			stop_dac(s);
+			s->dma_dac.ready = 0;
+			if (val)
+				fmtd |= CM_CFMT_STEREO << CM_CFMT_DACSHIFT;
+			else
+				fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_DACSHIFT);
+		}
+		set_fmt(s, fmtm, fmtd);
+		return 0;
+
+        case SNDCTL_DSP_CHANNELS:
+                get_user_ret(val, (int *)arg, -EFAULT);
+		if (val != 0) {
+			fmtd = 0;
+			fmtm = ~0;
+			if (file->f_mode & FMODE_READ) {
+				stop_adc(s);
+				s->dma_adc.ready = 0;
+				if (val >= 2)
+					fmtd |= CM_CFMT_STEREO << CM_CFMT_ADCSHIFT;
+				else
+					fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_ADCSHIFT);
+			}
+			if (file->f_mode & FMODE_WRITE) {
+				stop_dac(s);
+				s->dma_dac.ready = 0;
+				if (val >= 2)
+					fmtd |= CM_CFMT_STEREO << CM_CFMT_DACSHIFT;
+				else
+					fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_DACSHIFT);
+			}
+			set_fmt(s, fmtm, fmtd);
+		}
+		return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_STEREO << CM_CFMT_ADCSHIFT) 
+					   : (CM_CFMT_STEREO << CM_CFMT_DACSHIFT))) ? 2 : 1, (int *)arg);
+		
+	case SNDCTL_DSP_GETFMTS: /* Returns a mask */
+                return put_user(AFMT_S16_LE|AFMT_U8, (int *)arg);
+		
+	case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
+		get_user_ret(val, (int *)arg, -EFAULT);
+		if (val != AFMT_QUERY) {
+			fmtd = 0;
+			fmtm = ~0;
+			if (file->f_mode & FMODE_READ) {
+				stop_adc(s);
+				s->dma_adc.ready = 0;
+				if (val == AFMT_S16_LE)
+					fmtd |= CM_CFMT_16BIT << CM_CFMT_ADCSHIFT;
+				else
+					fmtm &= ~(CM_CFMT_16BIT << CM_CFMT_ADCSHIFT);
+			}
+			if (file->f_mode & FMODE_WRITE) {
+				stop_dac(s);
+				s->dma_dac.ready = 0;
+				if (val == AFMT_S16_LE)
+					fmtd |= CM_CFMT_16BIT << CM_CFMT_DACSHIFT;
+				else
+					fmtm &= ~(CM_CFMT_16BIT << CM_CFMT_DACSHIFT);
+			}
+			set_fmt(s, fmtm, fmtd);
+		}
+		return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_16BIT << CM_CFMT_ADCSHIFT) 
+					   : (CM_CFMT_16BIT << CM_CFMT_DACSHIFT))) ? AFMT_S16_LE : AFMT_U8, (int *)arg);
+		
+	case SNDCTL_DSP_POST:
+                return 0;
+
+        case SNDCTL_DSP_GETTRIGGER:
+		val = 0;
+		if (file->f_mode & FMODE_READ && s->enable & CM_CENABLE_RE) 
+			val |= PCM_ENABLE_INPUT;
+		if (file->f_mode & FMODE_WRITE && s->enable & CM_CENABLE_PE) 
+			val |= PCM_ENABLE_OUTPUT;
+		return put_user(val, (int *)arg);
+		
+	case SNDCTL_DSP_SETTRIGGER:
+		get_user_ret(val, (int *)arg, -EFAULT);
+		if (file->f_mode & FMODE_READ) {
+			if (val & PCM_ENABLE_INPUT) {
+				if (!s->dma_adc.ready && (ret =  prog_dmabuf(s, 1)))
+					return ret;
+				start_adc(s);
+			} else
+				stop_adc(s);
+		}
+		if (file->f_mode & FMODE_WRITE) {
+			if (val & PCM_ENABLE_OUTPUT) {
+				if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
+					return ret;
+				start_dac(s);
+			} else
+				stop_dac(s);
+		}
+		return 0;
+
+	case SNDCTL_DSP_GETOSPACE:
+		if (!(file->f_mode & FMODE_WRITE))
+			return -EINVAL;
+		if (!(s->enable & CM_CENABLE_PE) && (val = prog_dmabuf(s, 0)) != 0)
+			return val;
+		spin_lock_irqsave(&s->lock, flags);
+		cm_update_ptr(s);
+		abinfo.fragsize = s->dma_dac.fragsize;
+                abinfo.bytes = s->dma_dac.dmasize - s->dma_dac.count;
+                abinfo.fragstotal = s->dma_dac.numfrag;
+                abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;      
+		spin_unlock_irqrestore(&s->lock, flags);
+		return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
+
+	case SNDCTL_DSP_GETISPACE:
+		if (!(file->f_mode & FMODE_READ))
+			return -EINVAL;
+		if (!(s->enable & CM_CENABLE_RE) && (val = prog_dmabuf(s, 1)) != 0)
+			return val;
+		spin_lock_irqsave(&s->lock, flags);
+		cm_update_ptr(s);
+		abinfo.fragsize = s->dma_adc.fragsize;
+                abinfo.bytes = s->dma_adc.count;
+                abinfo.fragstotal = s->dma_adc.numfrag;
+                abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;      
+		spin_unlock_irqrestore(&s->lock, flags);
+		return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
+		
+        case SNDCTL_DSP_NONBLOCK:
+                file->f_flags |= O_NONBLOCK;
+                return 0;
+
+        case SNDCTL_DSP_GETODELAY:
+		if (!(file->f_mode & FMODE_WRITE))
+			return -EINVAL;
+		spin_lock_irqsave(&s->lock, flags);
+		cm_update_ptr(s);
+                val = s->dma_dac.count;
+		spin_unlock_irqrestore(&s->lock, flags);
+		return put_user(val, (int *)arg);
+
+        case SNDCTL_DSP_GETIPTR:
+		if (!(file->f_mode & FMODE_READ))
+			return -EINVAL;
+		spin_lock_irqsave(&s->lock, flags);
+		cm_update_ptr(s);
+                cinfo.bytes = s->dma_adc.total_bytes;
+                cinfo.blocks = s->dma_adc.count >> s->dma_adc.fragshift;
+                cinfo.ptr = s->dma_adc.hwptr;
+		if (s->dma_adc.mapped)
+			s->dma_adc.count &= s->dma_adc.fragsize-1;
+		spin_unlock_irqrestore(&s->lock, flags);
+                return copy_to_user((void *)arg, &cinfo, sizeof(cinfo));
+
+        case SNDCTL_DSP_GETOPTR:
+		if (!(file->f_mode & FMODE_WRITE))
+			return -EINVAL;
+		spin_lock_irqsave(&s->lock, flags);
+		cm_update_ptr(s);
+                cinfo.bytes = s->dma_dac.total_bytes;
+                cinfo.blocks = s->dma_dac.count >> s->dma_dac.fragshift;
+                cinfo.ptr = s->dma_dac.hwptr;
+		if (s->dma_dac.mapped)
+			s->dma_dac.count &= s->dma_dac.fragsize-1;
+		spin_unlock_irqrestore(&s->lock, flags);
+                return copy_to_user((void *)arg, &cinfo, sizeof(cinfo));
+
+        case SNDCTL_DSP_GETBLKSIZE:
+		if (file->f_mode & FMODE_WRITE) {
+			if ((val = prog_dmabuf(s, 0)))
+				return val;
+			return put_user(s->dma_dac.fragsize, (int *)arg);
+		}
+		if ((val = prog_dmabuf(s, 1)))
+			return val;
+		return put_user(s->dma_adc.fragsize, (int *)arg);
+
+        case SNDCTL_DSP_SETFRAGMENT:
+                get_user_ret(val, (int *)arg, -EFAULT);
+		if (file->f_mode & FMODE_READ) {
+			s->dma_adc.ossfragshift = val & 0xffff;
+			s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
+			if (s->dma_adc.ossfragshift < 4)
+				s->dma_adc.ossfragshift = 4;
+			if (s->dma_adc.ossfragshift > 15)
+				s->dma_adc.ossfragshift = 15;
+			if (s->dma_adc.ossmaxfrags < 4)
+				s->dma_adc.ossmaxfrags = 4;
+		}
+		if (file->f_mode & FMODE_WRITE) {
+			s->dma_dac.ossfragshift = val & 0xffff;
+			s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
+			if (s->dma_dac.ossfragshift < 4)
+				s->dma_dac.ossfragshift = 4;
+			if (s->dma_dac.ossfragshift > 15)
+				s->dma_dac.ossfragshift = 15;
+			if (s->dma_dac.ossmaxfrags < 4)
+				s->dma_dac.ossmaxfrags = 4;
+		}
+		return 0;
+
+        case SNDCTL_DSP_SUBDIVIDE:
+		if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
+		    (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
+			return -EINVAL;
+                get_user_ret(val, (int *)arg, -EFAULT);
+		if (val != 1 && val != 2 && val != 4)
+			return -EINVAL;
+		if (file->f_mode & FMODE_READ)
+			s->dma_adc.subdivision = val;
+		if (file->f_mode & FMODE_WRITE)
+			s->dma_dac.subdivision = val;
+		return 0;
+
+        case SOUND_PCM_READ_RATE:
+		return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, (int *)arg);
+
+        case SOUND_PCM_READ_CHANNELS:
+		return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_STEREO << CM_CFMT_ADCSHIFT) : (CM_CFMT_STEREO << CM_CFMT_DACSHIFT))) ? 2 : 1, (int *)arg);
+
+        case SOUND_PCM_READ_BITS:
+		return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_16BIT << CM_CFMT_ADCSHIFT) : (CM_CFMT_16BIT << CM_CFMT_DACSHIFT))) ? 16 : 8, (int *)arg);
+
+        case SOUND_PCM_WRITE_FILTER:
+        case SNDCTL_DSP_SETSYNCRO:
+        case SOUND_PCM_READ_FILTER:
+                return -EINVAL;
+		
+	}
+	return mixer_ioctl(s, cmd, arg);
+}
+
+static int cm_open(struct inode *inode, struct file *file)
+{
+	int minor = MINOR(inode->i_rdev);
+	struct cm_state *s = devs;
+	unsigned char fmtm = ~0, fmts = 0;
+
+	while (s && ((s->dev_audio ^ minor) & ~0xf))
+		s = s->next;
+	if (!s)
+		return -ENODEV;
+       	VALIDATE_STATE(s);
+	file->private_data = s;
+	/* wait for device to become free */
+	down(&s->open_sem);
+	while (s->open_mode & file->f_mode) {
+		if (file->f_flags & O_NONBLOCK) {
+			up(&s->open_sem);
+			return -EBUSY;
+		}
+		up(&s->open_sem);
+		interruptible_sleep_on(&s->open_wait);
+		if (signal_pending(current))
+			return -ERESTARTSYS;
+		down(&s->open_sem);
+	}
+	if (file->f_mode & FMODE_READ) {
+		fmtm &= ~((CM_CFMT_STEREO | CM_CFMT_16BIT) << CM_CFMT_ADCSHIFT);
+		if ((minor & 0xf) == SND_DEV_DSP16)
+			fmts |= CM_CFMT_16BIT << CM_CFMT_ADCSHIFT;
+		s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
+		set_adc_rate(s, 8000);
+	}
+	if (file->f_mode & FMODE_WRITE) {
+		fmtm &= ~((CM_CFMT_STEREO | CM_CFMT_16BIT) << CM_CFMT_DACSHIFT);
+		if ((minor & 0xf) == SND_DEV_DSP16)
+			fmts |= CM_CFMT_16BIT << CM_CFMT_DACSHIFT;
+		s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = s->dma_dac.subdivision = 0;
+		set_dac_rate(s, 8000);
+	}
+	set_fmt(s, fmtm, fmts);
+	s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
+	up(&s->open_sem);
+	MOD_INC_USE_COUNT;
+	return 0;
+}
+
+static int cm_release(struct inode *inode, struct file *file)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+
+	VALIDATE_STATE(s);
+	if (file->f_mode & FMODE_WRITE)
+		drain_dac(s, file->f_flags & O_NONBLOCK);
+	down(&s->open_sem);
+	if (file->f_mode & FMODE_WRITE) {
+		stop_dac(s);
+		dealloc_dmabuf(&s->dma_dac);
+	}
+	if (file->f_mode & FMODE_READ) {
+		stop_adc(s);
+		dealloc_dmabuf(&s->dma_adc);
+	}
+	s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
+	up(&s->open_sem);
+	wake_up(&s->open_wait);
+	MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+static /*const*/ struct file_operations cm_audio_fops = {
+	&cm_llseek,
+	&cm_read,
+	&cm_write,
+	NULL,  /* readdir */
+	&cm_poll,
+	&cm_ioctl,
+	&cm_mmap,
+	&cm_open,
+	NULL,	/* flush */
+	&cm_release,
+	NULL,  /* fsync */
+	NULL,  /* fasync */
+	NULL,  /* check_media_change */
+	NULL,  /* revalidate */
+	NULL,  /* lock */
+};
+
+#ifdef CONFIG_SOUND_CMPCI_MIDI
+/* --------------------------------------------------------------------- */
+
+static ssize_t cm_midi_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	ssize_t ret;
+	unsigned long flags;
+	unsigned ptr;
+	int cnt;
+
+	VALIDATE_STATE(s);
+	if (ppos != &file->f_pos)
+		return -ESPIPE;
+	if (!access_ok(VERIFY_WRITE, buffer, count))
+		return -EFAULT;
+	ret = 0;
+	while (count > 0) {
+		spin_lock_irqsave(&s->lock, flags);
+		ptr = s->midi.ird;
+		cnt = MIDIINBUF - ptr;
+		if (s->midi.icnt < cnt)
+			cnt = s->midi.icnt;
+		spin_unlock_irqrestore(&s->lock, flags);
+		if (cnt > count)
+			cnt = count;
+		if (cnt <= 0) {
+			if (file->f_flags & O_NONBLOCK)
+				return ret ? ret : -EAGAIN;
+			interruptible_sleep_on(&s->midi.iwait);
+			if (signal_pending(current))
+				return ret ? ret : -ERESTARTSYS;
+			continue;
+		}
+		if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt))
+			return ret ? ret : -EFAULT;
+		ptr = (ptr + cnt) % MIDIINBUF;
+		spin_lock_irqsave(&s->lock, flags);
+		s->midi.ird = ptr;
+		s->midi.icnt -= cnt;
+		spin_unlock_irqrestore(&s->lock, flags);
+		count -= cnt;
+		buffer += cnt;
+		ret += cnt;
+	}
+	return ret;
+}
+
+static ssize_t cm_midi_write(struct file *file, const char *buffer, size_t count, loff_t *ppos)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	ssize_t ret;
+	unsigned long flags;
+	unsigned ptr;
+	int cnt;
+
+	VALIDATE_STATE(s);
+	if (ppos != &file->f_pos)
+		return -ESPIPE;
+	if (!access_ok(VERIFY_READ, buffer, count))
+		return -EFAULT;
+	ret = 0;
+	while (count > 0) {
+		spin_lock_irqsave(&s->lock, flags);
+		ptr = s->midi.owr;
+		cnt = MIDIOUTBUF - ptr;
+		if (s->midi.ocnt + cnt > MIDIOUTBUF)
+			cnt = MIDIOUTBUF - s->midi.ocnt;
+		if (cnt <= 0)
+			cm_handle_midi(s);
+		spin_unlock_irqrestore(&s->lock, flags);
+		if (cnt > count)
+			cnt = count;
+		if (cnt <= 0) {
+			if (file->f_flags & O_NONBLOCK)
+				return ret ? ret : -EAGAIN;
+			interruptible_sleep_on(&s->midi.owait);
+			if (signal_pending(current))
+				return ret ? ret : -ERESTARTSYS;
+			continue;
+		}
+		if (copy_from_user(s->midi.obuf + ptr, buffer, cnt))
+			return ret ? ret : -EFAULT;
+		ptr = (ptr + cnt) % MIDIOUTBUF;
+		spin_lock_irqsave(&s->lock, flags);
+		s->midi.owr = ptr;
+		s->midi.ocnt += cnt;
+		spin_unlock_irqrestore(&s->lock, flags);
+		count -= cnt;
+		buffer += cnt;
+		ret += cnt;
+		spin_lock_irqsave(&s->lock, flags);
+		cm_handle_midi(s);
+		spin_unlock_irqrestore(&s->lock, flags);
+	}
+	return ret;
+}
+
+static unsigned int cm_midi_poll(struct file *file, struct poll_table_struct *wait)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	unsigned long flags;
+	unsigned int mask = 0;
+
+	VALIDATE_STATE(s);
+	if (file->f_mode & FMODE_WRITE)
+		poll_wait(file, &s->midi.owait, wait);
+	if (file->f_mode & FMODE_READ)
+		poll_wait(file, &s->midi.iwait, wait);
+	spin_lock_irqsave(&s->lock, flags);
+	if (file->f_mode & FMODE_READ) {
+		if (s->midi.icnt > 0)
+			mask |= POLLIN | POLLRDNORM;
+	}
+	if (file->f_mode & FMODE_WRITE) {
+		if (s->midi.ocnt < MIDIOUTBUF)
+			mask |= POLLOUT | POLLWRNORM;
+	}
+	spin_unlock_irqrestore(&s->lock, flags);
+	return mask;
+}
+
+static int cm_midi_open(struct inode *inode, struct file *file)
+{
+	int minor = MINOR(inode->i_rdev);
+	struct cm_state *s = devs;
+	unsigned long flags;
+
+	while (s && s->dev_midi != minor)
+		s = s->next;
+	if (!s)
+		return -ENODEV;
+       	VALIDATE_STATE(s);
+	file->private_data = s;
+	/* wait for device to become free */
+	down(&s->open_sem);
+	while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
+		if (file->f_flags & O_NONBLOCK) {
+			up(&s->open_sem);
+			return -EBUSY;
+		}
+		up(&s->open_sem);
+		interruptible_sleep_on(&s->open_wait);
+		if (signal_pending(current))
+			return -ERESTARTSYS;
+		down(&s->open_sem);
+	}
+	spin_lock_irqsave(&s->lock, flags);
+	if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
+		s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
+		s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
+		/* enable MPU-401 */
+		outb(inb(s->iobase + CODEC_CMI_FUNCTRL1) | 4, s->iobase + CODEC_CMI_FUNCTRL1);
+		outb(0xff, s->iomidi+1); /* reset command */
+		if (!(inb(s->iomidi+1) & 0x80))
+			inb(s->iomidi);
+		outb(0x3f, s->iomidi+1); /* uart command */
+		if (!(inb(s->iomidi+1) & 0x80))
+			inb(s->iomidi);
+		s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
+		init_timer(&s->midi.timer);
+		s->midi.timer.expires = jiffies+1;
+		s->midi.timer.data = (unsigned long)s;
+		s->midi.timer.function = cm_midi_timer;
+		add_timer(&s->midi.timer);
+	}
+	if (file->f_mode & FMODE_READ) {
+		s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
+	}
+	if (file->f_mode & FMODE_WRITE) {
+		s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
+	}
+	spin_unlock_irqrestore(&s->lock, flags);
+	s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
+	up(&s->open_sem);
+	MOD_INC_USE_COUNT;
+	return 0;
+}
+
+static int cm_midi_release(struct inode *inode, struct file *file)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+        struct wait_queue wait = { current, NULL };
+	unsigned long flags;
+	unsigned count, tmo;
+
+	VALIDATE_STATE(s);
+
+	if (file->f_mode & FMODE_WRITE) {
+		current->state = TASK_INTERRUPTIBLE;
+		add_wait_queue(&s->midi.owait, &wait);
+		for (;;) {
+			spin_lock_irqsave(&s->lock, flags);
+			count = s->midi.ocnt;
+			spin_unlock_irqrestore(&s->lock, flags);
+			if (count <= 0)
+				break;
+			if (signal_pending(current))
+				break;
+			if (file->f_flags & O_NONBLOCK) {
+				remove_wait_queue(&s->midi.owait, &wait);
+				current->state = TASK_RUNNING;
+				return -EBUSY;
+			}
+			tmo = (count * HZ) / 3100;
+			if (!schedule_timeout(tmo ? : 1) && tmo)
+				printk(KERN_DEBUG "cm: midi timed out??\n");
+		}
+		remove_wait_queue(&s->midi.owait, &wait);
+		current->state = TASK_RUNNING;
+	}
+	down(&s->open_sem);
+	s->open_mode &= (~(file->f_mode << FMODE_MIDI_SHIFT)) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE);
+	spin_lock_irqsave(&s->lock, flags);
+	if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
+		del_timer(&s->midi.timer);		
+		outb(0xff, s->iomidi+1); /* reset command */
+		if (!(inb(s->iomidi+1) & 0x80))
+			inb(s->iomidi);
+		/* disable MPU-401 */
+		outb(inb(s->iobase + CODEC_CMI_FUNCTRL1) & ~4, s->iobase + CODEC_CMI_FUNCTRL1);
+	}
+	spin_unlock_irqrestore(&s->lock, flags);
+	up(&s->open_sem);
+	wake_up(&s->open_wait);
+	MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+static /*const*/ struct file_operations cm_midi_fops = {
+	&cm_llseek,
+	&cm_midi_read,
+	&cm_midi_write,
+	NULL,  /* readdir */
+	&cm_midi_poll,
+	NULL,  /* ioctl */
+	NULL,  /* mmap */
+	&cm_midi_open,
+	NULL,	/* flush */
+	&cm_midi_release,
+	NULL,  /* fsync */
+	NULL,  /* fasync */
+	NULL,  /* check_media_change */
+	NULL,  /* revalidate */
+	NULL,  /* lock */
+};
+#endif
+
+/* --------------------------------------------------------------------- */
+
+#ifdef CONFIG_SOUND_CMPCI_FM
+static int cm_dmfm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+	static const unsigned char op_offset[18] = {
+		0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
+		0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
+		0x10, 0x11, 0x12, 0x13, 0x14, 0x15
+	};
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	struct dm_fm_voice v;
+	struct dm_fm_note n;
+	struct dm_fm_params p;
+	unsigned int io;
+	unsigned int regb;
+
+	switch (cmd) {		
+	case FM_IOCTL_RESET:
+		for (regb = 0xb0; regb < 0xb9; regb++) {
+			outb(regb, s->iosynth);
+			outb(0, s->iosynth+1);
+			outb(regb, s->iosynth+2);
+			outb(0, s->iosynth+3);
+		}
+		return 0;
+
+	case FM_IOCTL_PLAY_NOTE:
+		if (copy_from_user(&n, (void *)arg, sizeof(n)))
+			return -EFAULT;
+		if (n.voice >= 18)
+			return -EINVAL;
+		if (n.voice >= 9) {
+			regb = n.voice - 9;
+			io = s->iosynth+2;
+		} else {
+			regb = n.voice;
+			io = s->iosynth;
+		}
+		outb(0xa0 + regb, io);
+		outb(n.fnum & 0xff, io+1);
+		outb(0xb0 + regb, io);
+		outb(((n.fnum >> 8) & 3) | ((n.octave & 7) << 2) | ((n.key_on & 1) << 5), io+1);
+		return 0;
+
+	case FM_IOCTL_SET_VOICE:
+		if (copy_from_user(&v, (void *)arg, sizeof(v)))
+			return -EFAULT;
+		if (v.voice >= 18)
+			return -EINVAL;
+		regb = op_offset[v.voice];
+		io = s->iosynth + ((v.op & 1) << 1);
+		outb(0x20 + regb, io);
+		outb(((v.am & 1) << 7) | ((v.vibrato & 1) << 6) | ((v.do_sustain & 1) << 5) | 
+		     ((v.kbd_scale & 1) << 4) | (v.harmonic & 0xf), io+1);
+		outb(0x40 + regb, io);
+		outb(((v.scale_level & 0x3) << 6) | (v.volume & 0x3f), io+1);
+		outb(0x60 + regb, io);
+		outb(((v.attack & 0xf) << 4) | (v.decay & 0xf), io+1);
+		outb(0x80 + regb, io);
+		outb(((v.sustain & 0xf) << 4) | (v.release & 0xf), io+1);
+		outb(0xe0 + regb, io);
+		outb(v.waveform & 0x7, io+1);
+		if (n.voice >= 9) {
+			regb = n.voice - 9;
+			io = s->iosynth+2;
+		} else {
+			regb = n.voice;
+			io = s->iosynth;
+		}
+		outb(0xc0 + regb, io);
+		outb(((v.right & 1) << 5) | ((v.left & 1) << 4) | ((v.feedback & 7) << 1) |
+		     (v.connection & 1), io+1);
+		return 0;
+		
+	case FM_IOCTL_SET_PARAMS:
+		if (copy_from_user(&p, (void *)arg, sizeof(p)))
+			return -EFAULT;
+		outb(0x08, s->iosynth);
+		outb((p.kbd_split & 1) << 6, s->iosynth+1);
+		outb(0xbd, s->iosynth);
+		outb(((p.am_depth & 1) << 7) | ((p.vib_depth & 1) << 6) | ((p.rhythm & 1) << 5) | ((p.bass & 1) << 4) |
+		     ((p.snare & 1) << 3) | ((p.tomtom & 1) << 2) | ((p.cymbal & 1) << 1) | (p.hihat & 1), s->iosynth+1);
+		return 0;
+
+	case FM_IOCTL_SET_OPL:
+		outb(4, s->iosynth+2);
+		outb(arg, s->iosynth+3);
+		return 0;
+
+	case FM_IOCTL_SET_MODE:
+		outb(5, s->iosynth+2);
+		outb(arg & 1, s->iosynth+3);
+		return 0;
+
+	default:
+		return -EINVAL;
+	}
+}
+
+static int cm_dmfm_open(struct inode *inode, struct file *file)
+{
+	int minor = MINOR(inode->i_rdev);
+	struct cm_state *s = devs;
+
+	while (s && s->dev_dmfm != minor)
+		s = s->next;
+	if (!s)
+		return -ENODEV;
+       	VALIDATE_STATE(s);
+	file->private_data = s;
+	/* wait for device to become free */
+	down(&s->open_sem);
+	while (s->open_mode & FMODE_DMFM) {
+		if (file->f_flags & O_NONBLOCK) {
+			up(&s->open_sem);
+			return -EBUSY;
+		}
+		up(&s->open_sem);
+		interruptible_sleep_on(&s->open_wait);
+		if (signal_pending(current))
+			return -ERESTARTSYS;
+		down(&s->open_sem);
+	}
+	/* init the stuff */
+	outb(1, s->iosynth);
+	outb(0x20, s->iosynth+1); /* enable waveforms */
+	outb(4, s->iosynth+2);
+	outb(0, s->iosynth+3);  /* no 4op enabled */
+	outb(5, s->iosynth+2);
+	outb(1, s->iosynth+3);  /* enable OPL3 */
+	s->open_mode |= FMODE_DMFM;
+	up(&s->open_sem);
+	MOD_INC_USE_COUNT;
+	return 0;
+}
+
+static int cm_dmfm_release(struct inode *inode, struct file *file)
+{
+	struct cm_state *s = (struct cm_state *)file->private_data;
+	unsigned int regb;
+
+	VALIDATE_STATE(s);
+	down(&s->open_sem);
+	s->open_mode &= ~FMODE_DMFM;
+	for (regb = 0xb0; regb < 0xb9; regb++) {
+		outb(regb, s->iosynth);
+		outb(0, s->iosynth+1);
+		outb(regb, s->iosynth+2);
+		outb(0, s->iosynth+3);
+	}
+	up(&s->open_sem);
+	wake_up(&s->open_wait);
+	MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+static /*const*/ struct file_operations cm_dmfm_fops = {
+	&cm_llseek,
+	NULL,  /* read */
+	NULL,  /* write */
+	NULL,  /* readdir */
+	NULL,  /* poll */
+	&cm_dmfm_ioctl,
+	NULL,  /* mmap */
+	&cm_dmfm_open,
+	NULL,	/* flush */
+	&cm_dmfm_release,
+	NULL,  /* fsync */
+	NULL,  /* fasync */
+	NULL,  /* check_media_change */
+	NULL,  /* revalidate */
+	NULL,  /* lock */
+};
+#endif /* CONFIG_SOUND_CMPCI_FM */
+
+/* --------------------------------------------------------------------- */
+
+/* maximum number of devices */
+#define NR_DEVICE 5
+
+#if 0
+static int reverb[NR_DEVICE] = { 0, };
+
+static int wavetable[NR_DEVICE] = { 0, };
+#endif
+
+/* --------------------------------------------------------------------- */
+
+static struct initvol {
+	int mixch;
+	int vol;
+} initvol[] __initdata = {
+	{ SOUND_MIXER_WRITE_CD, 0x4040 },
+	{ SOUND_MIXER_WRITE_LINE, 0x4040 },
+	{ SOUND_MIXER_WRITE_MIC, 0x4040 },
+	{ SOUND_MIXER_WRITE_SYNTH, 0x4040 },
+	{ SOUND_MIXER_WRITE_VOLUME, 0x4040 },
+	{ SOUND_MIXER_WRITE_PCM, 0x4040 }
+};
+
+#ifdef MODULE
+__initfunc(int init_module(void))
+#else
+__initfunc(int init_cmpci(void))
+#endif
+{
+	struct cm_state *s;
+	struct pci_dev *pcidev = NULL;
+	mm_segment_t fs;
+	int i, val, index = 0;
+	struct {
+		unsigned short	deviceid;
+		char		*devicename;
+	} devicetable[] =
+	{
+		{ PCI_DEVICE_ID_CMEDIA_CM8338A, "CM8338A" },
+		{ PCI_DEVICE_ID_CMEDIA_CM8338B, "CM8338B" },
+		{ PCI_DEVICE_ID_CMEDIA_CM8738,  "CM8738" },
+	};
+	char	*devicename = "unknown";
+
+#ifdef CONFIG_PCI
+	if (!pci_present())   /* No PCI bus in this machine! */
+#endif
+		return -ENODEV;
+	printk(KERN_INFO "cm: version v1.1 time " __TIME__ " " __DATE__ "\n");
+#if 0
+	if (!(wavetable_mem = __get_free_pages(GFP_KERNEL, 20-PAGE_SHIFT)))
+		printk(KERN_INFO "cm: cannot allocate 1MB of contiguous nonpageable memory for wavetable data\n");
+#endif
+	while (index < NR_DEVICE && pcidev == NULL && (
+ 	       (pcidev = pci_find_device(PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A, pcidev)) ||
+	       (pcidev = pci_find_device(PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B, pcidev)) ||
+	       (pcidev = pci_find_device(PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738, pcidev)))) {
+		if (pcidev->irq == 0)
+			continue;
+		if (!(s = kmalloc(sizeof(struct cm_state), GFP_KERNEL))) {
+			printk(KERN_WARNING "cm: out of memory\n");
+			continue;
+		}
+		/* search device name */
+		for (i = 0; i < sizeof(devicetable) / sizeof(devicetable[0]); i++)
+		{
+			if (devicetable[i].deviceid == pcidev->device)
+			{
+				devicename = devicetable[i].devicename;
+				break;
+			}
+		}
+		memset(s, 0, sizeof(struct cm_state));
+		init_waitqueue(&s->dma_adc.wait);
+		init_waitqueue(&s->dma_dac.wait);
+		init_waitqueue(&s->open_wait);
+		init_waitqueue(&s->midi.iwait);
+		init_waitqueue(&s->midi.owait);
+		s->open_sem = MUTEX;
+		s->magic = CM_MAGIC;
+		s->iobase = pcidev->base_address[0] & PCI_BASE_ADDRESS_IO_MASK;
+#ifdef CONFIG_SOUND_CMPCI_FM
+		s->iosynth = 0x388;
+#endif
+#ifdef CONFIG_SOUND_CMPCI_MIDI
+		s->iomidi = 0x330;
+#endif
+		if (s->iobase == 0)
+			continue;
+		s->irq = pcidev->irq;
+
+		if (check_region(s->iobase, CM_EXTENT_CODEC)) {
+			printk(KERN_ERR "cm: io ports %#x-%#x in use\n", s->iobase, s->iobase+CM_EXTENT_CODEC-1);
+			goto err_region5;
+		}
+		request_region(s->iobase, CM_EXTENT_CODEC, "cmpci");
+#ifdef CONFIG_SOUND_CMPCI_MIDI
+		if (check_region(s->iomidi, CM_EXTENT_MIDI)) {
+			printk(KERN_ERR "cm: io ports %#x-%#x in use\n", s->iomidi, s->iomidi+CM_EXTENT_MIDI-1);
+			goto err_region4;
+		}
+		request_region(s->iomidi, CM_EXTENT_MIDI, "cmpci Midi");
+		/* set IO based at 0x330 */
+		outb(inb(s->iobase + CODEC_CMI_LEGACY_CTRL + 3) & ~0x60, s->iobase + CODEC_CMI_LEGACY_CTRL + 3);
+#endif
+#ifdef CONFIG_SOUND_CMPCI_FM
+		if (check_region(s->iosynth, CM_EXTENT_SYNTH)) {
+			printk(KERN_ERR "cm: io ports %#x-%#x in use\n", s->iosynth, s->iosynth+CM_EXTENT_SYNTH-1);
+			goto err_region1;
+		}
+		request_region(s->iosynth, CM_EXTENT_SYNTH, "cmpci FM");
+		/* enable FM */
+		outb(inb(s->iobase + CODEC_CMI_MISC_CTRL + 2) | 8, s->iobase + CODEC_CMI_MISC_CTRL);
+#endif
+		/* initialize codec registers */
+		outb(0, s->iobase + CODEC_CMI_INT_HLDCLR + 2);  /* disable ints */
+		outb(0, s->iobase + CODEC_CMI_FUNCTRL0 + 2); /* reset channels */
+		/* reset mixer */
+		wrmixer(s, DSP_MIX_DATARESETIDX, 0);
+
+		/* request irq */
+		if (request_irq(s->irq, cm_interrupt, SA_SHIRQ, "cmpci", s)) {
+			printk(KERN_ERR "cm: irq %u in use\n", s->irq);
+			goto err_irq;
+		}
+		printk(KERN_INFO "cm: found %s adapter at io %#06x irq %u\n",
+		       devicename, s->iobase, s->irq);
+		/* register devices */
+		if ((s->dev_audio = register_sound_dsp(&cm_audio_fops, -1)) < 0)
+			goto err_dev1;
+		if ((s->dev_mixer = register_sound_mixer(&cm_mixer_fops, -1)) < 0)
+			goto err_dev2;
+#ifdef CONFIG_SOUND_CMPCI_MIDI
+		if ((s->dev_midi = register_sound_midi(&cm_midi_fops, -1)) < 0)
+			goto err_dev3;
+#endif
+#ifdef CONFIG_SOUND_CMPCI_FM
+		if ((s->dev_dmfm = register_sound_special(&cm_dmfm_fops, 15 /* ?? */)) < 0)
+			goto err_dev4;
+#endif
+		/* initialize the chips */
+		fs = get_fs();
+		set_fs(KERNEL_DS);
+		/* set mixer output */
+		frobindir(s, DSP_MIX_OUTMIXIDX, 0x1f, 0x1f);
+		/* set mixer input */
+		val = SOUND_MASK_LINE|SOUND_MASK_SYNTH|SOUND_MASK_CD|SOUND_MASK_MIC;
+		mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
+		for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
+			val = initvol[i].vol;
+			mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val);
+		}
+		set_fs(fs);
+		/* queue it for later freeing */
+		s->next = devs;
+		devs = s;
+		index++;
+		continue;
+
+	err_dev4:
+		unregister_sound_midi(s->dev_midi);
+	err_dev3:
+		unregister_sound_mixer(s->dev_mixer);
+	err_dev2:
+		unregister_sound_dsp(s->dev_audio);
+	err_dev1:
+		printk(KERN_ERR "cm: cannot register misc device\n");
+		free_irq(s->irq, s);
+	err_irq:
+#ifdef CONFIG_SOUND_CMPCI_FM
+		release_region(s->iosynth, CM_EXTENT_SYNTH);
+	err_region1:
+#endif
+#ifdef CONFIG_SOUND_CMPCI_MIDI
+		release_region(s->iomidi, CM_EXTENT_MIDI);
+#endif
+	err_region4:
+		release_region(s->iobase, CM_EXTENT_CODEC);
+	err_region5:
+		kfree_s(s, sizeof(struct cm_state));
+	}
+	if (!devs) {
+		if (wavetable_mem)
+			free_pages(wavetable_mem, 20-PAGE_SHIFT);
+		return -ENODEV;
+	}
+	return 0;
+}
+
+/* --------------------------------------------------------------------- */
+
+#ifdef MODULE
+
+#if 0
+MODULE_PARM(wavetable, "1-" __MODULE_STRING(NR_DEVICE) "i");
+MODULE_PARM_DESC(wavetable, "if 1 the wavetable synth is enabled");
+#endif
+
+MODULE_AUTHOR("ChenLi Tien, cltien@home.com");
+MODULE_DESCRIPTION("CMPCI Audio Driver");
+
+void cleanup_module(void)
+{
+	struct cm_state *s;
+
+	while ((s = devs)) {
+		devs = devs->next;
+		outb(0, s->iobase + CODEC_CMI_INT_HLDCLR + 2);  /* disable ints */
+		synchronize_irq();
+		outb(0, s->iobase + CODEC_CMI_FUNCTRL0 + 2); /* reset channels */
+		free_irq(s->irq, s);
+
+		/* reset mixer */
+		wrmixer(s, DSP_MIX_DATARESETIDX, 0);
+
+		release_region(s->iobase, CM_EXTENT_CODEC);
+#ifdef CONFIG_SOUND_CMPCI_MIDI
+		release_region(s->iomidi, CM_EXTENT_MIDI);
+#endif
+#ifdef CONFIG_SOUND_CMPCI_FM
+		release_region(s->iosynth, CM_EXTENT_SYNTH);
+#endif
+		unregister_sound_dsp(s->dev_audio);
+		unregister_sound_mixer(s->dev_mixer);
+#ifdef CONFIG_SOUND_CMPCI_MIDI
+		unregister_sound_midi(s->dev_midi);
+#endif
+#ifdef CONFIG_SOUND_CMPCI_FM
+		unregister_sound_special(s->dev_dmfm);
+#endif
+		kfree_s(s, sizeof(struct cm_state));
+	}
+	if (wavetable_mem)
+		free_pages(wavetable_mem, 20-PAGE_SHIFT);
+	printk(KERN_INFO "cm: unloading\n");
+}
+
+#endif /* MODULE */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/sound/dmabuf.c linux.13p4/drivers/sound/dmabuf.c
--- linux.vanilla/drivers/sound/dmabuf.c	Sat Aug 14 02:25:43 1999
+++ linux.13p4/drivers/sound/dmabuf.c	Wed Sep  1 13:53:21 1999
@@ -187,7 +187,7 @@
 		printk(KERN_WARNING "Sound: DMA buffers not available\n");
 		return -ENOSPC;	/* Memory allocation failed during boot */
 	}
-	if (sound_open_dma(dmap->dma, adev->name)) {
+	if (dmap->dma >= 0 && sound_open_dma(dmap->dma, adev->name)) {
 		printk(KERN_WARNING "Unable to grab(2) DMA%d for the audio driver\n", dmap->dma);
 		return -EBUSY;
 	}
@@ -209,14 +209,15 @@
 {
 	unsigned long flags;
 	
-	sound_close_dma(dmap->dma);
+	if (dmap->dma >= 0) {
+		sound_close_dma(dmap->dma);
+		flags=claim_dma_lock();
+		disable_dma(dmap->dma);
+		release_dma_lock(flags);
+	}
 	if (dmap->flags & DMA_BUSY)
 		dmap->dma_mode = DMODE_NONE;
 	dmap->flags &= ~DMA_BUSY;
-	
-	flags=claim_dma_lock();
-	disable_dma(dmap->dma);
-	release_dma_lock(flags);
 	
 	if (sound_dmap_flag == DMAP_FREE_ON_CLOSE)
 		sound_free_dmap(dmap);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/sound/opl3sa.c linux.13p4/drivers/sound/opl3sa.c
--- linux.vanilla/drivers/sound/opl3sa.c	Mon Jan  4 19:37:30 1999
+++ linux.13p4/drivers/sound/opl3sa.c	Wed Sep  1 13:53:22 1999
@@ -187,7 +187,7 @@
 {
 #if defined(CONFIG_UART401) && defined(CONFIG_MIDI)
 	unsigned char conf;
-	static char irq_bits[] = {
+	static signed char irq_bits[] = {
 		-1, -1, -1, -1, -1, 1, -1, 2, -1, 3, 4
 	};
 
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/sound/sonicvibes.c linux.13p4/drivers/sound/sonicvibes.c
--- linux.vanilla/drivers/sound/sonicvibes.c	Sat Aug 14 02:27:34 1999
+++ linux.13p4/drivers/sound/sonicvibes.c	Wed Sep  1 13:53:22 1999
@@ -504,9 +504,8 @@
 static unsigned setpll(struct sv_state *s, unsigned char reg, unsigned rate)
 {
 	unsigned long flags;
-	unsigned char r, m, n;
+	unsigned char r, m=0, n=0;
 	unsigned xm, xn, xr, xd, metric = ~0U;
-	/* the warnings about m and n used uninitialized are bogus and may safely be ignored */
 
 	if (rate < 625000/ADCMULT)
 		rate = 625000/ADCMULT;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/drivers/sound/via82cxxx.c linux.13p4/drivers/sound/via82cxxx.c
--- linux.vanilla/drivers/sound/via82cxxx.c	Thu Jan  1 01:00:00 1970
+++ linux.13p4/drivers/sound/via82cxxx.c	Fri Sep  3 14:55:23 1999
@@ -0,0 +1,266 @@
+/*
+ * Support for VIA 82Cxxx Audio Codecs
+ * Copyright 1999 Jeff Garzik <jgarzik@pobox.com>
+ *
+ * Distributed under the GNU GENERAL PUBLIC LICENSE (GPL) Version 2.
+ * See the "COPYING" file distributed with this software for more info.
+ *
+ ********************************************************************
+ *
+ * TODO:
+ *
+ *	- Integrate AC'97 support, when AC'97 interface released
+ *
+ */
+ 
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+
+#include <asm/io.h>
+
+#include "sound_config.h"
+#include "soundmodule.h"
+#include "sb.h"
+
+#ifndef SOUND_LOCK
+#define SOUND_LOCK do {} while (0)
+#define SOUND_LOCK_END do {} while (0)
+#endif
+
+#define MAX_CARDS	2
+
+#define PFX		"via82cxxx: "
+
+#define VIA_VERSION	"1.0.0"
+#define VIA_CARD_NAME	"VIA 82Cxxx Audio driver " VIA_VERSION
+
+#define VIA_FUNC_ENABLE		0x42
+#define VIA_PNP_CONTROL		0x43
+
+#define VIA_CR42_SB_ENABLE	0x01
+#define VIA_CR42_MIDI_ENABLE	0x02
+#define VIA_CR42_FM_ENABLE	0x04
+
+#define via_probe_midi probe_uart401
+#define via_attach_midi attach_uart401
+#define via_unload_midi unload_uart401
+
+static struct address_info	sb_data[MAX_CARDS];
+static struct address_info	opl3_data[MAX_CARDS];
+static unsigned			cards = 0;
+
+
+static void __init via_attach_sb(struct address_info *hw_config)
+{
+	if(!sb_dsp_init(hw_config))
+		hw_config->slots[0] = -1;
+}
+
+
+static int __init via_probe_sb(struct address_info *hw_config)
+{
+	if (check_region(hw_config->io_base, 16))
+	{
+		printk(KERN_DEBUG PFX "SBPro port 0x%x is already in use\n",
+		       hw_config->io_base);
+		return 0;
+	}
+	return sb_dsp_detect(hw_config, 0, 0);
+}
+
+
+static void via_unload_sb(struct address_info *hw_config, int unload_mpu)
+{
+	if(hw_config->slots[0]!=-1)
+		sb_dsp_unload(hw_config, unload_mpu);
+}
+
+
+static int __init via82cxxx_install (struct pci_dev *pcidev)
+{
+	int sb_io_base = 0;
+	int sb_irq = 0;
+	int sb_dma = 0;
+	int midi_base = 0;
+	u8 tmp8;
+	
+	memset (&sb_data[cards], 0, sizeof (struct address_info));
+	memset (&opl3_data[cards], 0, sizeof (struct address_info));
+
+	sb_data[cards].name = opl3_data[cards].name = VIA_CARD_NAME;
+	opl3_data[cards].irq = -1;
+
+	/* turn on features, if not already */
+	pci_read_config_byte (pcidev, VIA_FUNC_ENABLE, &tmp8);
+	tmp8 |= VIA_CR42_SB_ENABLE | VIA_CR42_MIDI_ENABLE |
+		VIA_CR42_FM_ENABLE;
+	pci_write_config_byte (pcidev, VIA_FUNC_ENABLE, tmp8);
+
+	/* read legacy PNP info byte */
+	pci_read_config_byte (pcidev, VIA_PNP_CONTROL, &tmp8);
+	pci_write_config_byte (pcidev, VIA_PNP_CONTROL, tmp8);
+	
+	switch ((tmp8 >> 6) & 0x03) {
+		case 0: sb_irq = 5; break;
+		case 1: sb_irq = 7; break;
+		case 2: sb_irq = 9; break;
+		case 3: sb_irq = 10; break;
+		default: /* do nothing */ break;
+	}
+	switch ((tmp8 >> 4) & 0x03) {
+		case 0: sb_dma = 0; break;
+		case 1: sb_dma = 1; break;
+		case 2: sb_dma = 2; break;
+		case 3: sb_dma = 3; break;
+		default: /* do nothing */ break;
+	}
+	switch ((tmp8 >> 2) & 0x03) {
+		case 0: midi_base = 0x300; break;
+		case 1: midi_base = 0x310; break;
+		case 2: midi_base = 0x320; break;
+		case 3: midi_base = 0x330; break;
+		default: /* do nothing */ break;
+	}
+	switch (tmp8 & 0x03) {
+		case 0: sb_io_base = 0x220; break;
+		case 1: sb_io_base = 0x240; break;
+		case 2: sb_io_base = 0x260; break;
+		case 3: sb_io_base = 0x280; break;
+		default: /* do nothing */ break;
+	}
+
+	udelay(100);
+	
+	printk(KERN_INFO PFX "legacy "
+	       "MIDI: 0x%X, SB: 0x%X / %d IRQ / %d DMA\n",
+		midi_base, sb_io_base, sb_irq, sb_dma);
+		
+	sb_data[cards].card_subtype = MDL_SBPRO;
+	sb_data[cards].io_base = sb_io_base;
+	sb_data[cards].irq = sb_irq;
+	sb_data[cards].dma = sb_dma;
+	
+	opl3_data[cards].io_base = midi_base;
+	
+	/* register legacy SoundBlaster Pro */
+	if (!via_probe_sb (&sb_data[cards])) {
+		printk (KERN_ERR PFX
+			"SB probe @ 0x%X failed, aborting\n",
+			sb_io_base);
+		return -1;
+	}
+	via_attach_sb (&sb_data[cards]);
+
+	/* register legacy MIDI */
+	if (!via_probe_midi (&opl3_data[cards])) {
+		printk (KERN_ERR PFX
+			"MIDI probe @ 0x%X failed, aborting\n",
+			midi_base);
+		via_unload_sb (&sb_data[cards], 0);
+		return -1;
+	}
+	via_attach_midi (&opl3_data[cards]);
+
+	cards++;	
+	return 0;
+}
+
+
+/*
+ * 	This loop walks the PCI configuration database and finds where
+ *	the sound cards are.
+ */
+ 
+static int __init probe_via82cxxx (void)
+{
+	struct pci_dev *pcidev = NULL;
+
+	while ((pcidev = pci_find_device (PCI_VENDOR_ID_VIA,
+					  PCI_DEVICE_ID_VIA_82C686_5,
+					  pcidev)) != NULL) {
+
+		  if (via82cxxx_install (pcidev) != 0) {
+			  printk (KERN_ERR PFX "audio init failed\n");
+			  return -1;
+		  }
+
+		  if (cards == MAX_CARDS) {
+		  	  printk (KERN_DEBUG PFX "maximum number of cards reached\n");
+			  break;
+		  }
+	}
+
+	return 0;
+}
+
+
+/*
+ *	This function is called when the user or kernel loads the 
+ *	module into memory.
+ */
+
+
+static int __init init_via82cxxx_module(void)
+{
+	if (!pci_present ()) {
+		printk (KERN_DEBUG PFX "PCI not present, exiting\n");
+		return -ENODEV;
+	}
+
+	if (probe_via82cxxx() != 0) {
+		printk(KERN_ERR PFX "probe failed, aborting\n");
+		/* XXX unload cards registered so far, if any */
+		return -ENODEV;
+	}
+
+	if (cards == 0) {
+		printk(KERN_DEBUG PFX "No chips found, aborting\n");
+		return -ENODEV;
+	}
+
+	printk (KERN_INFO PFX VIA_CARD_NAME " loaded\n");
+	
+	/*
+	 *	Binds us to the sound subsystem	
+	 */
+	SOUND_LOCK;
+	return 0;
+}
+
+/*
+ *	This is called when it is removed. It will only be removed 
+ *	when its use count is 0. For sound the SOUND_LOCK/SOUND_UNLOCK
+ *	macros hide the entire work for this.
+ */
+ 
+static void cleanup_via82cxxx_module(void)
+{
+	int i;
+	
+	for (i = 0; i < cards; i++)
+		via_unload_sb (&sb_data[i], 1);
+
+	/*
+	 *	Final clean up with the sound layer
+	 */
+	SOUND_LOCK_END;
+}
+
+#ifdef MODULE
+
+int init_module(void)
+{
+	return init_via82cxxx_module();
+}
+
+void cleanup_module(void)
+{
+	cleanup_via82cxxx_module();
+}
+
+#endif
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/fs/binfmt_aout.c linux.13p4/fs/binfmt_aout.c
--- linux.vanilla/fs/binfmt_aout.c	Sat Aug 14 02:26:17 1999
+++ linux.13p4/fs/binfmt_aout.c	Wed Sep  1 13:52:10 1999
@@ -311,6 +311,7 @@
 	unsigned long fd_offset;
 	unsigned long rlim;
 	int retval;
+	static unsigned long error_time=0;
 
 	ex = *((struct exec *) bprm->buf);		/* exec-header */
 	if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
@@ -324,7 +325,11 @@
 
 #ifdef __i386__
 	if (N_MAGIC(ex) == ZMAGIC && fd_offset != BLOCK_SIZE) {
-		printk(KERN_NOTICE "N_TXTOFF != BLOCK_SIZE. See a.out.h.\n");
+		if((jiffies-error_time) >5)
+		{
+			printk(KERN_NOTICE "N_TXTOFF != BLOCK_SIZE. See a.out.h.\n");
+			error_time=jiffies;
+		}
 		return -ENOEXEC;
 	}
 
@@ -332,7 +337,11 @@
 	    bprm->dentry->d_inode->i_op &&
 	    bprm->dentry->d_inode->i_op->bmap &&
 	    (fd_offset < bprm->dentry->d_inode->i_sb->s_blocksize)) {
-		printk(KERN_NOTICE "N_TXTOFF < BLOCK_SIZE. Please convert binary.\n");
+		if((jiffies-error_time) >5)
+		{
+			printk(KERN_NOTICE "N_TXTOFF < BLOCK_SIZE. Please convert binary.\n");
+			error_time=jiffies;
+		}
 		return -ENOEXEC;
 	}
 #endif
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/fs/exec.c linux.13p4/fs/exec.c
--- linux.vanilla/fs/exec.c	Sat Aug 28 20:00:58 1999
+++ linux.13p4/fs/exec.c	Wed Sep  1 13:52:08 1999
@@ -200,7 +200,7 @@
 /*
  * count() counts the number of arguments/envelopes
  */
-static int count(char ** argv)
+static int count(char ** argv, int max)
 {
 	int i = 0;
 
@@ -215,7 +215,7 @@
 			if (!p)
 				break;
 			argv++;
-			i++;
+			if (++i > max) return -E2BIG;
 		}
 	}
 	return i;
@@ -265,13 +265,13 @@
 		if (from_kmem == 1)
 			set_fs(old_fs);
 		len = strlen_user(str);	/* includes the '\0' */
-		if (p < len) {	/* this shouldn't happen - 128kB */
+		if (!len || p < len) {	/* strlen_user() returns 0 on error */
 			set_fs(old_fs);
 			return 0;
 		}
 		p -= len;
 		pos = p;
-		while (len) {
+		while (len>0) {
 			char *pag;
 			int offset, bytes_to_copy;
 
@@ -823,12 +823,12 @@
 	bprm.java = 0;
 	bprm.loader = 0;
 	bprm.exec = 0;
-	if ((bprm.argc = count(argv)) < 0) {
+	if ((bprm.argc = count(argv, bprm.p / sizeof(void *))) < 0) {
 		dput(dentry);
 		return bprm.argc;
 	}
 
-	if ((bprm.envc = count(envp)) < 0) {
+	if ((bprm.envc = count(envp, bprm.p / sizeof(void *))) < 0) {
 		dput(dentry);
 		return bprm.envc;
 	}
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/fs/ext2/file.c linux.13p4/fs/ext2/file.c
--- linux.vanilla/fs/ext2/file.c	Sat Aug 14 02:27:37 1999
+++ linux.13p4/fs/ext2/file.c	Wed Sep  1 13:52:09 1999
@@ -324,7 +324,8 @@
 			break;
 		}
 		mark_buffer_dirty(bh, 0);
-		update_vm_cache(inode, pos, bh->b_data + offset, c);
+		update_vm_cache_conditional(inode, pos, bh->b_data + offset, c,
+					    (unsigned long) buf);
 		pos += c;
 		written += c;
 		buf += c;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/fs/ext2/inode.c linux.13p4/fs/ext2/inode.c
--- linux.vanilla/fs/ext2/inode.c	Sat Aug 14 02:27:37 1999
+++ linux.13p4/fs/ext2/inode.c	Wed Sep  1 13:52:09 1999
@@ -761,28 +761,28 @@
 		flags = iattr->ia_attr_flags;
 		if (flags & ATTR_FLAG_SYNCRONOUS) {
 			inode->i_flags |= MS_SYNCHRONOUS;
-			inode->u.ext2_i.i_flags = EXT2_SYNC_FL;
+			inode->u.ext2_i.i_flags |= EXT2_SYNC_FL;
 		} else {
 			inode->i_flags &= ~MS_SYNCHRONOUS;
 			inode->u.ext2_i.i_flags &= ~EXT2_SYNC_FL;
 		}
 		if (flags & ATTR_FLAG_NOATIME) {
 			inode->i_flags |= MS_NOATIME;
-			inode->u.ext2_i.i_flags = EXT2_NOATIME_FL;
+			inode->u.ext2_i.i_flags |= EXT2_NOATIME_FL;
 		} else {
 			inode->i_flags &= ~MS_NOATIME;
 			inode->u.ext2_i.i_flags &= ~EXT2_NOATIME_FL;
 		}
 		if (flags & ATTR_FLAG_APPEND) {
 			inode->i_flags |= S_APPEND;
-			inode->u.ext2_i.i_flags = EXT2_APPEND_FL;
+			inode->u.ext2_i.i_flags |= EXT2_APPEND_FL;
 		} else {
 			inode->i_flags &= ~S_APPEND;
 			inode->u.ext2_i.i_flags &= ~EXT2_APPEND_FL;
 		}
 		if (flags & ATTR_FLAG_IMMUTABLE) {
 			inode->i_flags |= S_IMMUTABLE;
-			inode->u.ext2_i.i_flags = EXT2_IMMUTABLE_FL;
+			inode->u.ext2_i.i_flags |= EXT2_IMMUTABLE_FL;
 		} else {
 			inode->i_flags &= ~S_IMMUTABLE;
 			inode->u.ext2_i.i_flags &= ~EXT2_IMMUTABLE_FL;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/fs/nfs/inode.c linux.13p4/fs/nfs/inode.c
--- linux.vanilla/fs/nfs/inode.c	Sat Aug 14 02:26:18 1999
+++ linux.13p4/fs/nfs/inode.c	Wed Sep  1 13:52:09 1999
@@ -408,6 +408,8 @@
 	unhashed = 0;
 	while ((tmp = tmp->next) != head) {
 		struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
+		if (!list_empty(&dentry->d_subdirs))
+			shrink_dcache_parent(dentry);
 		dprintk("nfs_free_dentries: found %s/%s, d_count=%d, hashed=%d\n",
 			dentry->d_parent->d_name.name, dentry->d_name.name,
 			dentry->d_count, !list_empty(&dentry->d_hash));
@@ -417,7 +419,7 @@
 			dput(dentry);
 			goto restart;
 		}
-		if (!list_empty(&dentry->d_hash))
+		if (list_empty(&dentry->d_hash))
 			unhashed++;
 	}
 	return unhashed;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/fs/open.c linux.13p4/fs/open.c
--- linux.vanilla/fs/open.c	Sat Aug 28 20:00:58 1999
+++ linux.13p4/fs/open.c	Wed Sep  1 13:52:08 1999
@@ -535,10 +535,13 @@
 	 * non-root user, remove the setuid bit.
 	 * 19981026	David C Niemi <niemi@tux.org>
 	 *
+	 * Changed this to apply to all users, including root, to avoid
+	 * some races. This is the behavior we had in 2.0. The check for
+	 * non-root was definitely wrong for 2.2 anyway, as it should
+	 * have been using CAP_FSETID rather than fsuid -- 19990830 SD.
 	 */
 	if ((inode->i_mode & S_ISUID) == S_ISUID &&
-		!S_ISDIR(inode->i_mode)
-		&& current->fsuid) 
+		!S_ISDIR(inode->i_mode))
 	{
 		newattrs.ia_mode &= ~S_ISUID;
 		newattrs.ia_valid |= ATTR_MODE;
@@ -548,9 +551,11 @@
 	 * by a non-root user, remove the setgid bit UNLESS there is no group
 	 * execute bit (this would be a file marked for mandatory locking).
 	 * 19981026	David C Niemi <niemi@tux.org>
+	 *
+	 * Removed the fsuid check (see the comment above) -- 19990830 SD.
 	 */
 	if (((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) 
-		&& !S_ISDIR(inode->i_mode) && current->fsuid) 
+		&& !S_ISDIR(inode->i_mode))
 	{
 		newattrs.ia_mode &= ~S_ISGID;
 		newattrs.ia_valid |= ATTR_MODE;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/fs/proc/fd.c linux.13p4/fs/proc/fd.c
--- linux.vanilla/fs/proc/fd.c	Sat Aug 14 02:25:59 1999
+++ linux.13p4/fs/proc/fd.c	Wed Sep  1 13:52:08 1999
@@ -87,6 +87,7 @@
 	fd = 0;
 	len = dentry->d_name.len;
 	name = dentry->d_name.name;
+	if (len > 1 && *name == '0') goto out;
 	while (len-- > 0) {
 		c = *name - '0';
 		name++;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/asm-i386/spinlock.h linux.13p4/include/asm-i386/spinlock.h
--- linux.vanilla/include/asm-i386/spinlock.h	Sun Mar 28 19:03:25 1999
+++ linux.13p4/include/asm-i386/spinlock.h	Wed Sep  1 13:58:58 1999
@@ -21,7 +21,7 @@
 #endif
 
 #define spin_lock_init(lock)	do { } while(0)
-#define spin_lock(lock)		do { } while(0)
+#define spin_lock(lock)		(void)(lock) /* Not "unused variable". */
 #define spin_trylock(lock)	(1)
 #define spin_unlock_wait(lock)	do { } while(0)
 #define spin_unlock(lock)	do { } while(0)
@@ -99,9 +99,9 @@
   #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
 #endif
 
-#define read_lock(lock)		do { } while(0)
+#define read_lock(lock)		(void)(lock) /* Not "unused variable." */
 #define read_unlock(lock)	do { } while(0)
-#define write_lock(lock)	do { } while(0)
+#define write_lock(lock)	(void)(lock) /* Not "unused variable." */
 #define write_unlock(lock)	do { } while(0)
 #define read_lock_irq(lock)	cli()
 #define read_unlock_irq(lock)	sti()
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/asm-ppc/md.h linux.13p4/include/asm-ppc/md.h
--- linux.vanilla/include/asm-ppc/md.h	Mon Jan 12 23:18:13 1998
+++ linux.13p4/include/asm-ppc/md.h	Thu Jan  1 01:00:00 1970
@@ -1,13 +0,0 @@
-/* $Id: md.h,v 1.1 1997/12/15 15:12:15 jj Exp $
- * md.h: High speed xor_block operation for RAID4/5 
- *
- */
- 
-#ifndef __ASM_MD_H
-#define __ASM_MD_H
-
-/* #define HAVE_ARCH_XORBLOCK */
-
-#define MD_XORBLOCK_ALIGNMENT	sizeof(long)
-
-#endif /* __ASM_MD_H */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/asm-ppc/pmu.h linux.13p4/include/asm-ppc/pmu.h
--- linux.vanilla/include/asm-ppc/pmu.h	Sat Aug 28 20:00:58 1999
+++ linux.13p4/include/asm-ppc/pmu.h	Wed Sep  1 13:52:21 1999
@@ -6,6 +6,7 @@
  * Copyright (C) 1998 Paul Mackerras.
  */
 
+#include <linux/config.h>
 /*
  * PMU commands
  */
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/asm-sparc64/oplib.h linux.13p4/include/asm-sparc64/oplib.h
--- linux.vanilla/include/asm-sparc64/oplib.h	Thu Mar 11 00:53:38 1999
+++ linux.13p4/include/asm-sparc64/oplib.h	Wed Sep  1 13:52:21 1999
@@ -1,4 +1,4 @@
-/* $Id: oplib.h,v 1.10 1998/12/18 10:02:03 davem Exp $
+/* $Id: oplib.h,v 1.10.2.1 1999/08/19 01:11:21 davem Exp $
  * oplib.h:  Describes the interface and available routines in the
  *           Linux Prom library.
  *
@@ -205,7 +205,8 @@
 /* MMU and memory related OBP interfaces. */
 
 /* Get unique string identifying SIMM at given physical address. */
-extern int prom_getunumber(unsigned long phys_lo, unsigned long phys_hi,
+extern int prom_getunumber(int syndrome_code,
+			   unsigned long phys_addr,
 			   char *buf, int buflen);
 
 /* Retain physical memory to the caller across soft resets. */
@@ -336,6 +337,7 @@
 #define P1275_ARG_OUT_32B		3
 #define P1275_ARG_IN_FUNCTION		4
 #define P1275_ARG_IN_BUF		5
+#define P1275_ARG_IN_64B		6
 
 #define P1275_IN(x) ((x) & 0xf)
 #define P1275_OUT(x) (((x) << 4) & 0xf0)
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/asm-sparc64/ttable.h linux.13p4/include/asm-sparc64/ttable.h
--- linux.vanilla/include/asm-sparc64/ttable.h	Sat Aug 14 02:26:00 1999
+++ linux.13p4/include/asm-sparc64/ttable.h	Wed Sep  1 13:52:22 1999
@@ -1,4 +1,4 @@
-/* $Id: ttable.h,v 1.11 1999/03/29 12:38:12 jj Exp $ */
+/* $Id: ttable.h,v 1.11.2.1 1999/08/19 01:11:20 davem Exp $ */
 #ifndef _SPARC64_TTABLE_H
 #define _SPARC64_TTABLE_H
 
@@ -54,6 +54,13 @@
 	 clr	%l6;					\
 	nop;
 	
+#define TRAPTL1_CEE			\
+	ldxa	[%g0] ASI_AFSR, %g1;	\
+	membar	#Sync;			\
+	stxa	%g1, [%g0] ASI_AFSR;	\
+	membar	#Sync;			\
+	retry; nop; nop; nop;
+
 #define TRAP_ARG(routine, arg)				\
 	sethi	%hi(109f), %g7;				\
 	ba,pt	%xcc, etrap;				\
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/linux/fs.h linux.13p4/include/linux/fs.h
--- linux.vanilla/include/linux/fs.h	Sat Aug 28 20:00:59 1999
+++ linux.13p4/include/linux/fs.h	Wed Sep  1 13:58:58 1999
@@ -184,7 +184,6 @@
 #define BH_Lock		2	/* 1 if the buffer is locked */
 #define BH_Req		3	/* 0 if the buffer has been invalidated */
 #define BH_Protected	6	/* 1 if the buffer is protected */
-#define BH_LowPrio	7	/* 1 if the buffer is lowprio */
 
 /*
  * Try to keep the most commonly used fields in single cache lines (16
@@ -755,7 +754,6 @@
 extern void refile_buffer(struct buffer_head * buf);
 extern void set_writetime(struct buffer_head * buf, int flag);
 extern int try_to_free_buffers(struct page *);
-extern void cache_drop_behind(struct buffer_head *bh);
 
 extern int nr_buffers;
 extern int buffermem;
@@ -776,25 +774,6 @@
 	}
 }
 
-extern inline void mark_buffer_highprio(struct buffer_head * bh)
-{
-	clear_bit(BH_LowPrio, &bh->b_state);
-}
-
-extern inline void mark_buffer_lowprio(struct buffer_head * bh)
-{
-	/*
-	 * dirty buffers cannot be marked lowprio.
-	 */
-	if (!buffer_dirty(bh))
-		set_bit(BH_LowPrio, &bh->b_state);
-}
-
-static inline int buffer_lowprio(struct buffer_head * bh)
-{
-	return test_bit(BH_LowPrio, &bh->b_state);
-}
-
 extern inline void mark_buffer_dirty(struct buffer_head * bh, int flag)
 {
 	if (!test_and_set_bit(BH_Dirty, &bh->b_state)) {
@@ -802,23 +781,6 @@
 		if (bh->b_list != BUF_DIRTY)
 			refile_buffer(bh);
 	}
-	/*
-	 * if a buffer gets marked dirty then it has to lose
-	 * it's lowprio state.
-	 */
-	mark_buffer_highprio(bh);
-}
-
-extern inline void mark_buffer_dirty_lowprio(struct buffer_head * bh)
-{
-	if (!test_and_set_bit(BH_Dirty, &bh->b_state)) {
-		if (bh->b_list != BUF_DIRTY)
-			refile_buffer(bh);
-		/*
-		 * Mark it lowprio only if it was not dirty before!
-		 */
-		set_bit(BH_LowPrio, &bh->b_state);
-	}
 }
 
 extern int check_disk_change(kdev_t dev);
@@ -889,7 +851,6 @@
 extern struct buffer_head * find_buffer(kdev_t dev, int block, int size);
 extern void ll_rw_block(int, int, struct buffer_head * bh[]);
 extern int is_read_only(kdev_t);
-extern int is_device_idle(kdev_t);
 extern void __brelse(struct buffer_head *);
 extern inline void brelse(struct buffer_head *buf)
 {
@@ -905,12 +866,8 @@
 extern void set_blocksize(kdev_t dev, int size);
 extern unsigned int get_hardblocksize(kdev_t dev);
 extern struct buffer_head * bread(kdev_t dev, int block, int size);
-extern struct buffer_head * buffer_ready (kdev_t dev, int block, int size);
-extern void bread_ahead (kdev_t dev, int block, int size);
 extern struct buffer_head * breada(kdev_t dev,int block, int size, 
 				   unsigned int pos, unsigned int filesize);
-extern struct buffer_head * breada_blocks(kdev_t dev,int block,
-						int size, int blocks);
 
 extern int brw_page(int, struct page *, kdev_t, int [], int, int);
 
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/linux/i2c.h linux.13p4/include/linux/i2c.h
--- linux.vanilla/include/linux/i2c.h	Sat Aug 28 20:00:59 1999
+++ linux.13p4/include/linux/i2c.h	Fri Sep  3 14:32:48 1999
@@ -39,6 +39,7 @@
 #define I2C_BUSID_BT848		1	/* I2C bus on a BT848 */
 	/* 2 is used in 2.3.x */
 #define I2C_BUSID_BUZ		3	/* I2C bus on a BUZ */
+#define I2C_BUSID_ZORAN		4	/* I2C bus on a Zoran */
 
 /*
  * struct for a driver for a i2c chip (tuner, soundprocessor,
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/linux/pagemap.h linux.13p4/include/linux/pagemap.h
--- linux.vanilla/include/linux/pagemap.h	Sat Aug 14 02:26:21 1999
+++ linux.13p4/include/linux/pagemap.h	Wed Sep  1 13:58:59 1999
@@ -148,6 +148,7 @@
 		__wait_on_page(page);
 }
 
+extern void update_vm_cache_conditional(struct inode *, unsigned long, const char *, int, unsigned long);
 extern void update_vm_cache(struct inode *, unsigned long, const char *, int);
 
 #endif
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/linux/pci.h linux.13p4/include/linux/pci.h
--- linux.vanilla/include/linux/pci.h	Sat Aug 28 20:00:59 1999
+++ linux.13p4/include/linux/pci.h	Fri Sep  3 14:55:57 1999
@@ -762,6 +762,7 @@
 #define PCI_DEVICE_ID_VIA_82C595_97	0x1595
 #define PCI_DEVICE_ID_VIA_82C586_2	0x3038
 #define PCI_DEVICE_ID_VIA_82C586_3	0x3040
+#define PCI_DEVICE_ID_VIA_82C686_5	0x3058
 #define PCI_DEVICE_ID_VIA_86C100A	0x6100
 #define PCI_DEVICE_ID_VIA_82C597_1	0x8597
 #define PCI_DEVICE_ID_VIA_82C598_1      0x8598
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/include/linux/videodev.h linux.13p4/include/linux/videodev.h
--- linux.vanilla/include/linux/videodev.h	Sat Aug 14 02:26:21 1999
+++ linux.13p4/include/linux/videodev.h	Fri Sep  3 14:35:53 1999
@@ -278,6 +278,7 @@
 #define VID_HARDWARE_TYPHOON	19
 #define VID_HARDWARE_VINO	20	/* Reserved for SGI Indy Vino */
 #define VID_HARDWARE_CADET	21	/* Cadet radio */
+#define VID_HARDWARE_TRUST	22	/* Trust FM Radio */
 
 /*
  *	Initialiser list
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/kernel/fork.c linux.13p4/kernel/fork.c
--- linux.vanilla/kernel/fork.c	Sat Aug 28 20:00:59 1999
+++ linux.13p4/kernel/fork.c	Wed Sep  1 13:52:15 1999
@@ -575,6 +575,13 @@
 	struct task_struct *p;
 	struct semaphore sem = MUTEX_LOCKED;
 
+	if(clone_flags & CLONE_PID)
+	{
+		/* This is only allowed from the boot up thread */
+		if(current->pid)
+			return -EPERM;
+	}
+	
 	current->vfork_sem = &sem;
 
 	p = alloc_task_struct();
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/kernel/ksyms.c linux.13p4/kernel/ksyms.c
--- linux.vanilla/kernel/ksyms.c	Sat Aug 14 02:27:40 1999
+++ linux.13p4/kernel/ksyms.c	Wed Sep  1 13:52:15 1999
@@ -106,6 +106,7 @@
 EXPORT_SYMBOL(max_mapnr);
 EXPORT_SYMBOL(high_memory);
 EXPORT_SYMBOL(update_vm_cache);
+EXPORT_SYMBOL(update_vm_cache_conditional);
 EXPORT_SYMBOL(vmtruncate);
 EXPORT_SYMBOL(find_vma);
 EXPORT_SYMBOL(get_unmapped_area);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/kernel/printk.c linux.13p4/kernel/printk.c
--- linux.vanilla/kernel/printk.c	Sat Mar  6 22:37:10 1999
+++ linux.13p4/kernel/printk.c	Wed Sep  1 13:52:15 1999
@@ -10,6 +10,8 @@
  * elsewhere, in preparation for a serial line console (someday).
  * Ted Ts'o, 2/11/93.
  * Modified for sysctl support, 1/8/97, Chris Horn.
+ * Fixed SMP synchronization, 08/08/99, Manfred Spraul 
+ *     manfreds@colorfullife.com
  */
 
 #include <linux/mm.h>
@@ -21,6 +23,7 @@
 #include <asm/uaccess.h>
 
 #define LOG_BUF_LEN	(16384)
+#define LOG_BUF_MASK	(LOG_BUF_LEN-1)
 
 static char buf[1024];
 
@@ -40,6 +43,8 @@
 int minimum_console_loglevel = MINIMUM_CONSOLE_LOGLEVEL;
 int default_console_loglevel = DEFAULT_CONSOLE_LOGLEVEL;
 
+spinlock_t console_lock = SPIN_LOCK_UNLOCKED;
+
 struct console *console_drivers = NULL;
 static char log_buf[LOG_BUF_LEN];
 static unsigned long log_start = 0;
@@ -115,12 +120,11 @@
  */
 int do_syslog(int type, char * buf, int len)
 {
-	unsigned long i, j, count, flags;
+	unsigned long i, j, limit, count;
 	int do_clear = 0;
 	char c;
 	int error = -EPERM;
 
-	lock_kernel();
 	error = 0;
 	switch (type) {
 	case 0:		/* Close log */
@@ -141,18 +145,18 @@
 		if (error)
 			goto out;
 		i = 0;
+		spin_lock_irq(&console_lock);
 		while (log_size && i < len) {
-			c = *((char *) log_buf+log_start);
+			c = log_buf[log_start & LOG_BUF_MASK];
 			log_start++;
 			log_size--;
-			log_start &= LOG_BUF_LEN-1;
-			sti();
+			spin_unlock_irq(&console_lock);
 			__put_user(c,buf);
 			buf++;
 			i++;
-			cli();
+			spin_lock_irq(&console_lock);
 		}
-		sti();
+		spin_unlock_irq(&console_lock);
 		error = i;
 		break;
 	case 4:		/* Read/clear last kernel messages */
@@ -168,35 +172,56 @@
 		error = verify_area(VERIFY_WRITE,buf,len);
 		if (error)
 			goto out;
-		/*
-		 * The logged_chars, log_start, and log_size values may
-		 * change from an interrupt, so we disable interrupts.
-		 */
-		__save_flags(flags);
-		__cli();
+		spin_lock_irq(&console_lock);
 		count = len;
 		if (count > LOG_BUF_LEN)
 			count = LOG_BUF_LEN;
 		if (count > logged_chars)
 			count = logged_chars;
-		j = log_start + log_size - count;
-		__restore_flags(flags);
-		for (i = 0; i < count; i++) {
-			c = *((char *) log_buf+(j++ & (LOG_BUF_LEN-1)));
-			__put_user(c, buf++);
-		}
 		if (do_clear)
 			logged_chars = 0;
+		limit = log_start + log_size;
+		/*
+		 * __put_user() could sleep, and while we sleep
+		 * printk() could overwrite the messages 
+		 * we try to copy to user space. Therefore
+		 * the messages are copied in reverse. <manfreds>
+		 */
+		for(i=0;i < count;i++) {
+			j = limit-1-i;
+			if (j+LOG_BUF_LEN < log_start+log_size)
+				break;
+			c = log_buf[ j  & LOG_BUF_MASK ];
+			spin_unlock_irq(&console_lock);
+			__put_user(c,&buf[count-1-i]);
+			spin_lock_irq(&console_lock);
+		}
+		spin_unlock_irq(&console_lock);
 		error = i;
+		if(i != count) {
+			int offset = count-error;
+			/* buffer overflow during copy, correct user buffer. */
+			for(i=0;i<error;i++) {
+				__get_user(c,&buf[i+offset]);
+				__put_user(c,&buf[i]);
+			}
+		}
+
 		break;
 	case 5:		/* Clear ring buffer */
+		spin_lock_irq(&console_lock);
 		logged_chars = 0;
+		spin_unlock_irq(&console_lock);
 		break;
 	case 6:		/* Disable logging to console */
+		spin_lock_irq(&console_lock);
 		console_loglevel = minimum_console_loglevel;
+		spin_unlock_irq(&console_lock);
 		break;
 	case 7:		/* Enable logging to console */
+		spin_lock_irq(&console_lock);
 		console_loglevel = default_console_loglevel;
+		spin_unlock_irq(&console_lock);
 		break;
 	case 8:
 		error = -EINVAL;
@@ -204,7 +229,9 @@
 			goto out;
 		if (len < minimum_console_loglevel)
 			len = minimum_console_loglevel;
+		spin_lock_irq(&console_lock);
 		console_loglevel = len;
+		spin_unlock_irq(&console_lock);
 		error = 0;
 		break;
 	default:
@@ -212,7 +239,6 @@
 		break;
 	}
 out:
-	unlock_kernel();
 	return error;
 }
 
@@ -223,9 +249,6 @@
 	return do_syslog(type, buf, len);
 }
 
-
-spinlock_t console_lock;
-
 asmlinkage int printk(const char *fmt, ...)
 {
 	va_list args;
@@ -259,13 +282,12 @@
 		}
 		line_feed = 0;
 		for (; p < buf_end; p++) {
-			log_buf[(log_start+log_size) & (LOG_BUF_LEN-1)] = *p;
+			log_buf[(log_start+log_size) & LOG_BUF_MASK] = *p;
 			if (log_size < LOG_BUF_LEN)
 				log_size++;
-			else {
+			else
 				log_start++;
-				log_start &= LOG_BUF_LEN-1;
-			}
+
 			logged_chars++;
 			if (*p == '\n') {
 				line_feed = 1;
@@ -290,24 +312,33 @@
 
 void console_print(const char *s)
 {
-	struct console *c = console_drivers;
+	struct console *c;
+	unsigned long flags;
 	int len = strlen(s);
 
+	spin_lock_irqsave(&console_lock,flags);
+	c = console_drivers;
 	while(c) {
 		if ((c->flags & CON_ENABLED) && c->write)
 			c->write(c, s, len);
 		c = c->next;
 	}
+	spin_unlock_irqrestore(&console_lock,flags);
 }
 
 void unblank_console(void)
 {
-	struct console *c = console_drivers;
+	struct console *c;
+	unsigned long flags;
+	
+	spin_lock_irqsave(&console_lock,flags);
+	c = console_drivers;
 	while(c) {
 		if ((c->flags & CON_ENABLED) && c->unblank)
 			c->unblank();
 		c = c->next;
 	}
+	spin_unlock_irqrestore(&console_lock,flags);
 }
 
 /*
@@ -318,11 +349,12 @@
  */
 void register_console(struct console * console)
 {
-	int	i,j,len;
-	int	p = log_start;
+	int     i, j,len;
+	int	p;
 	char	buf[16];
 	signed char msg_level = -1;
 	char	*q;
+	unsigned long flags;
 
 	/*
 	 *	See if we want to use this console driver. If we
@@ -368,6 +400,7 @@
 	 *	Put this console in the list - keep the
 	 *	preferred driver at the head of the list.
 	 */
+	spin_lock_irqsave(&console_lock,flags);
 	if ((console->flags & CON_CONSDEV) || console_drivers == NULL) {
 		console->next = console_drivers;
 		console_drivers = console;
@@ -375,23 +408,33 @@
 		console->next = console_drivers->next;
 		console_drivers->next = console;
 	}
-	if ((console->flags & CON_PRINTBUFFER) == 0) return;
-
+	if ((console->flags & CON_PRINTBUFFER) == 0)
+		goto done;
 	/*
 	 *	Print out buffered log messages.
 	 */
+	p = log_start & LOG_BUF_MASK;
+
 	for (i=0,j=0; i < log_size; i++) {
 		buf[j++] = log_buf[p];
-		p++; p &= LOG_BUF_LEN-1;
+		p = (p+1) & LOG_BUF_MASK;
 		if (buf[j-1] != '\n' && i < log_size - 1 && j < sizeof(buf)-1)
 			continue;
 		buf[j] = 0;
 		q = buf;
 		len = j;
 		if (msg_level < 0) {
-			msg_level = buf[1] - '0';
-			q = buf + 3;
-			len -= 3;
+			if(buf[0] == '<' &&
+				buf[1] >= '0' &&
+				buf[1] <= '7' &&
+				buf[2] == '>') {
+				msg_level = buf[1] - '0';
+				q = buf + 3;
+				len -= 3;
+			} else
+			{
+				msg_level = default_message_loglevel; 
+			}
 		}
 		if (msg_level < console_loglevel)
 			console->write(console, q, len);
@@ -399,26 +442,35 @@
 			msg_level = -1;
 		j = 0;
 	}
+done:
+	spin_unlock_irqrestore(&console_lock,flags);
 }
 
 
 int unregister_console(struct console * console)
 {
         struct console *a,*b;
-	
+	unsigned long flags;
+	int res = 1;
+
+	spin_lock_irqsave(&console_lock,flags);
 	if (console_drivers == console) {
 		console_drivers=console->next;
-		return (0);
-	}
-	for (a=console_drivers->next, b=console_drivers ;
-	     a; b=a, a=b->next) {
-		if (a == console) {
-			b->next = a->next;
-			return 0;
-		}  
+		res = 0;
+	} else
+	{
+		for (a=console_drivers->next, b=console_drivers ;
+		     a; b=a, a=b->next) {
+			if (a == console) {
+				b->next = a->next;
+				res = 0;
+				break;
+			}  
+		}
 	}
 	
-	return (1);
+	spin_unlock_irqrestore(&console_lock,flags);
+	return res;
 }
 	
 /*
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/mm/filemap.c linux.13p4/mm/filemap.c
--- linux.vanilla/mm/filemap.c	Sat Aug 14 02:26:21 1999
+++ linux.13p4/mm/filemap.c	Wed Sep  1 13:52:18 1999
@@ -215,8 +215,25 @@
 /*
  * Update a page cache copy, when we're doing a "write()" system call
  * See also "update_vm_cache()".
+ *
+ * This function is conditional in that it checks whether the original
+ * source of the data is the same as the ultimate destination, and
+ * aborts the update if so.  
+ *
+ * The "source_address" is the virtual address of the original location
+ * of the data we are injecting.  For writes from user mode, it is the
+ * user VA.  However, for filemap_sync writes, "source_address", it is
+ * the page cache address.  In both cases, "buf" points to the copy we
+ * have already made in kernel space and we use that pointer for the
+ * transfer.  source_address just allows us to detect an update_vm_cache
+ * which is being sourced from the copy of the data already in the page
+ * cache.  
+ * 
+ * This prevents munmap() and msync() from stomping all over shared
+ * memory maps.  --sct
  */
-void update_vm_cache(struct inode * inode, unsigned long pos, const char * buf, int count)
+
+void update_vm_cache_conditional(struct inode * inode, unsigned long pos, const char * buf, int count, unsigned long source_address)
 {
 	unsigned long offset, len;
 
@@ -230,8 +247,12 @@
 			len = count;
 		page = find_page(inode, pos);
 		if (page) {
-			wait_on_page(page);
-			memcpy((void *) (offset + page_address(page)), buf, len);
+			char *dest = (char*) (offset + page_address(page));
+
+			if ((unsigned long)dest != source_address) {
+				wait_on_page(page);
+				memcpy(dest, buf, len);
+			}
 			page_cache_release(page);
 		}
 		count -= len;
@@ -242,6 +263,12 @@
 	} while (count);
 }
 
+void update_vm_cache(struct inode * inode, unsigned long pos, const char * buf, int count)
+{
+	update_vm_cache_conditional(inode, pos, buf, count, 0);
+}
+
+
 static inline void add_to_page_cache(struct page * page,
 	struct inode * inode, unsigned long offset,
 	struct page **hash)
@@ -1482,6 +1509,8 @@
 
 	while (count) {
 		unsigned long bytes, pgpos, offset;
+		char * dest;
+
 		/*
 		 * Try to find the page in the cache. If it isn't there,
 		 * allocate a free page.
@@ -1516,7 +1545,9 @@
 		 * the writer needs to increment the page use counts until he
 		 * is done with the page.
 		 */
-		bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
+		dest = (char *) page_address(page) + offset;
+		if (dest != buf) /* See comment in update_vm_cache_cond. */
+			bytes -= copy_from_user(dest, buf, bytes);
 		status = -EFAULT;
 		if (bytes)
 			status = inode->i_op->updatepage(file, page, offset, bytes, sync);
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/mm/mmap.c linux.13p4/mm/mmap.c
--- linux.vanilla/mm/mmap.c	Sat Aug 28 20:00:59 1999
+++ linux.13p4/mm/mmap.c	Wed Sep  1 13:52:18 1999
@@ -361,11 +361,8 @@
 
 	if (len > TASK_SIZE)
 		return 0;
-	if (!addr) {
-		addr = current->rlim[RLIMIT_DATA].rlim_cur;
-		if (addr >= RLIM_INFINITY)
-			addr = TASK_UNMAPPED_BASE;
-	}
+	if (!addr)
+		addr = TASK_UNMAPPED_BASE;
 	addr = PAGE_ALIGN(addr);
 
 	for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/net/ipv4/ip_masq_mfw.c linux.13p4/net/ipv4/ip_masq_mfw.c
--- linux.vanilla/net/ipv4/ip_masq_mfw.c	Sat Aug 14 02:27:41 1999
+++ linux.13p4/net/ipv4/ip_masq_mfw.c	Wed Sep  1 13:52:44 1999
@@ -687,7 +687,7 @@
 			/* 	
 			 *	Only open TCP tunnel if SYN+!ACK packet
 			 */
-			if (!tph.th->syn && tph.th->ack)
+			if (!tph.th->syn || tph.th->ack)
 				return NULL;
 		case IPPROTO_UDP:
 			break;
diff -u --new-file --recursive --exclude-from ../exclude linux.vanilla/net/ipx/af_ipx.c linux.13p4/net/ipx/af_ipx.c
--- linux.vanilla/net/ipx/af_ipx.c	Sat Aug 14 02:27:45 1999
+++ linux.13p4/net/ipx/af_ipx.c	Wed Sep  1 13:52:45 1999
@@ -775,6 +775,7 @@
 		{ 
 			/* < 8 hops && input itfc not in list */
 			*l = intrfc->if_netnum; /* insert recvd netnum into list */
+			ipx->ipx_tctrl++;
 			/* xmit on all other interfaces... */
 			for(ifcs = ipx_interfaces; ifcs != NULL; ifcs = ifcs->if_next) 
 			{
