Merge HEAD from ../scsi-misc-2.6-tmp
authorJames Bottomley <jejb@titanic.(none)>
Sun, 28 Aug 2005 16:18:35 +0000 (11:18 -0500)
committerJames Bottomley <jejb@titanic.(none)>
Sun, 28 Aug 2005 16:18:35 +0000 (11:18 -0500)
72 files changed:
Documentation/scsi/aic7xxx.txt
MAINTAINERS
drivers/base/attribute_container.c
drivers/base/transport_class.c
drivers/scsi/aacraid/aachba.c
drivers/scsi/aacraid/aacraid.h
drivers/scsi/aacraid/commctrl.c
drivers/scsi/aacraid/comminit.c
drivers/scsi/aacraid/commsup.c
drivers/scsi/aacraid/linit.c
drivers/scsi/aacraid/rkt.c
drivers/scsi/aacraid/rx.c
drivers/scsi/aacraid/sa.c
drivers/scsi/advansys.c
drivers/scsi/aic7xxx/Kconfig.aic79xx
drivers/scsi/aic7xxx/aic7770.c
drivers/scsi/aic7xxx/aic79xx.h
drivers/scsi/aic7xxx/aic79xx_core.c
drivers/scsi/aic7xxx/aic79xx_osm.c
drivers/scsi/aic7xxx/aic79xx_osm.h
drivers/scsi/aic7xxx/aic79xx_osm_pci.c
drivers/scsi/aic7xxx/aic79xx_pci.c
drivers/scsi/aic7xxx/aic79xx_proc.c
drivers/scsi/aic7xxx/aic7xxx.h
drivers/scsi/aic7xxx/aic7xxx.reg
drivers/scsi/aic7xxx/aic7xxx.seq
drivers/scsi/aic7xxx/aic7xxx_93cx6.c
drivers/scsi/aic7xxx/aic7xxx_core.c
drivers/scsi/aic7xxx/aic7xxx_osm.c
drivers/scsi/aic7xxx/aic7xxx_osm.h
drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped
drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped
drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped
drivers/scsi/aic7xxx/aiclib.c
drivers/scsi/aic7xxx/aiclib.h
drivers/scsi/ch.c
drivers/scsi/constants.c
drivers/scsi/hosts.c
drivers/scsi/ibmvscsi/ibmvscsi.c
drivers/scsi/lpfc/lpfc.h
drivers/scsi/lpfc/lpfc_attr.c
drivers/scsi/lpfc/lpfc_ct.c
drivers/scsi/lpfc/lpfc_els.c
drivers/scsi/lpfc/lpfc_hbadisc.c
drivers/scsi/lpfc/lpfc_init.c
drivers/scsi/lpfc/lpfc_mbox.c
drivers/scsi/lpfc/lpfc_mem.c
drivers/scsi/lpfc/lpfc_nportdisc.c
drivers/scsi/lpfc/lpfc_scsi.c
drivers/scsi/lpfc/lpfc_scsi.h
drivers/scsi/lpfc/lpfc_sli.c
drivers/scsi/lpfc/lpfc_version.h
drivers/scsi/qla1280.c
drivers/scsi/qla1280.h
drivers/scsi/scsi.c
drivers/scsi/scsi_devinfo.c
drivers/scsi/scsi_error.c
drivers/scsi/scsi_ioctl.c
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_scan.c
drivers/scsi/scsi_sysfs.c
drivers/scsi/scsi_transport_fc.c
drivers/scsi/scsi_transport_spi.c
drivers/scsi/sg.c
drivers/scsi/st.c
drivers/scsi/st.h
include/linux/attribute_container.h
include/linux/transport_class.h
include/scsi/scsi_cmnd.h
include/scsi/scsi_host.h
include/scsi/scsi_transport_spi.h

index 160e7354cd1e88dcb4b93cb9209d1c07f0284097..47e74ddc4bc9509b5856b2b8fef0067d6f4eb9d7 100644 (file)
@@ -1,5 +1,5 @@
 ====================================================================
-=    Adaptec Aic7xxx Fast -> Ultra160 Family Manager Set v6.2.28   =
+=    Adaptec Aic7xxx Fast -> Ultra160 Family Manager Set v7.0      =
 =                            README for                            =
 =                     The Linux Operating System                   =
 ====================================================================
@@ -131,6 +131,10 @@ The following information is available in this file:
       SCSI "stub" effects.
 
 2. Version History
+   7.0   (4th August, 2005)
+       - Updated driver to use SCSI transport class infrastructure
+       - Upported sequencer and core fixes from last adaptec released
+         version of the driver.
    6.2.36 (June 3rd, 2003)
         - Correct code that disables PCI parity error checking.
         - Correct and simplify handling of the ignore wide residue
index 564a03e61a0c4b2322136ab9d96b3f121391ee83..fb0da63621cd0f087bad4ed4cdf27f775291204f 100644 (file)
@@ -824,6 +824,13 @@ L: emu10k1-devel@lists.sourceforge.net
 W:     http://sourceforge.net/projects/emu10k1/
 S:     Maintained
 
+EMULEX LPFC FC SCSI DRIVER
+P:      James Smart
+M:      james.smart@emulex.com
+L:      linux-scsi@vger.kernel.org
+W:      http://sourceforge.net/projects/lpfcxxxx
+S:      Supported
+
 EPSON 1355 FRAMEBUFFER DRIVER
 P:     Christopher Hoover
 M:     ch@murgatroid.com, ch@hpl.hp.com
index ec615d854be9710b10fccfc02a4f40bf6dd68632..ebcae5c34133d42796b01aab26f130bd53557472 100644 (file)
@@ -58,6 +58,7 @@ attribute_container_register(struct attribute_container *cont)
 {
        INIT_LIST_HEAD(&cont->node);
        INIT_LIST_HEAD(&cont->containers);
+       spin_lock_init(&cont->containers_lock);
                
        down(&attribute_container_mutex);
        list_add_tail(&cont->node, &attribute_container_list);
@@ -77,11 +78,13 @@ attribute_container_unregister(struct attribute_container *cont)
 {
        int retval = -EBUSY;
        down(&attribute_container_mutex);
+       spin_lock(&cont->containers_lock);
        if (!list_empty(&cont->containers))
                goto out;
        retval = 0;
        list_del(&cont->node);
  out:
+       spin_unlock(&cont->containers_lock);
        up(&attribute_container_mutex);
        return retval;
                
@@ -151,7 +154,9 @@ attribute_container_add_device(struct device *dev,
                        fn(cont, dev, &ic->classdev);
                else
                        attribute_container_add_class_device(&ic->classdev);
+               spin_lock(&cont->containers_lock);
                list_add_tail(&ic->node, &cont->containers);
+               spin_unlock(&cont->containers_lock);
        }
        up(&attribute_container_mutex);
 }
@@ -189,6 +194,7 @@ attribute_container_remove_device(struct device *dev,
 
                if (!cont->match(cont, dev))
                        continue;
+               spin_lock(&cont->containers_lock);
                list_for_each_entry_safe(ic, tmp, &cont->containers, node) {
                        if (dev != ic->classdev.dev)
                                continue;
@@ -200,6 +206,7 @@ attribute_container_remove_device(struct device *dev,
                                class_device_unregister(&ic->classdev);
                        }
                }
+               spin_unlock(&cont->containers_lock);
        }
        up(&attribute_container_mutex);
 }
@@ -230,10 +237,17 @@ attribute_container_device_trigger(struct device *dev,
                if (!cont->match(cont, dev))
                        continue;
 
+               if (attribute_container_no_classdevs(cont)) {
+                       fn(cont, dev, NULL);
+                       continue;
+               }
+
+               spin_lock(&cont->containers_lock);
                list_for_each_entry_safe(ic, tmp, &cont->containers, node) {
                        if (dev == ic->classdev.dev)
                                fn(cont, dev, &ic->classdev);
                }
+               spin_unlock(&cont->containers_lock);
        }
        up(&attribute_container_mutex);
 }
@@ -368,6 +382,35 @@ attribute_container_class_device_del(struct class_device *classdev)
 }
 EXPORT_SYMBOL_GPL(attribute_container_class_device_del);
 
+/**
+ * attribute_container_find_class_device - find the corresponding class_device
+ *
+ * @cont:      the container
+ * @dev:       the generic device
+ *
+ * Looks up the device in the container's list of class devices and returns
+ * the corresponding class_device.
+ */
+struct class_device *
+attribute_container_find_class_device(struct attribute_container *cont,
+                                     struct device *dev)
+{
+       struct class_device *cdev = NULL;
+       struct internal_container *ic;
+
+       spin_lock(&cont->containers_lock);
+       list_for_each_entry(ic, &cont->containers, node) {
+               if (ic->classdev.dev == dev) {
+                       cdev = &ic->classdev;
+                       break;
+               }
+       }
+       spin_unlock(&cont->containers_lock);
+
+       return cdev;
+}
+EXPORT_SYMBOL_GPL(attribute_container_find_class_device);
+
 int __init
 attribute_container_init(void)
 {
index 6c2b447a333657133336187b0a7c77e14377d920..f25e7c6b2d27301990eb6bc133015b5889a754e9 100644 (file)
@@ -7,7 +7,7 @@
  * This file is licensed under GPLv2
  *
  * The basic idea here is to allow any "device controller" (which
- * would most often be a Host Bus Adapter" to use the services of one
+ * would most often be a Host Bus Adapter to use the services of one
  * or more tranport classes for performing transport specific
  * services.  Transport specific services are things that the generic
  * command layer doesn't want to know about (speed settings, line
@@ -64,7 +64,9 @@ void transport_class_unregister(struct transport_class *tclass)
 }
 EXPORT_SYMBOL_GPL(transport_class_unregister);
 
-static int anon_transport_dummy_function(struct device *dev)
+static int anon_transport_dummy_function(struct transport_container *tc,
+                                        struct device *dev,
+                                        struct class_device *cdev)
 {
        /* do nothing */
        return 0;
@@ -115,9 +117,10 @@ static int transport_setup_classdev(struct attribute_container *cont,
                                    struct class_device *classdev)
 {
        struct transport_class *tclass = class_to_transport_class(cont->class);
+       struct transport_container *tcont = attribute_container_to_transport_container(cont);
 
        if (tclass->setup)
-               tclass->setup(dev);
+               tclass->setup(tcont, dev, classdev);
 
        return 0;
 }
@@ -178,12 +181,14 @@ void transport_add_device(struct device *dev)
 EXPORT_SYMBOL_GPL(transport_add_device);
 
 static int transport_configure(struct attribute_container *cont,
-                              struct device *dev)
+                              struct device *dev,
+                              struct class_device *cdev)
 {
        struct transport_class *tclass = class_to_transport_class(cont->class);
+       struct transport_container *tcont = attribute_container_to_transport_container(cont);
 
        if (tclass->configure)
-               tclass->configure(dev);
+               tclass->configure(tcont, dev, cdev);
 
        return 0;
 }
@@ -202,7 +207,7 @@ static int transport_configure(struct attribute_container *cont,
  */
 void transport_configure_device(struct device *dev)
 {
-       attribute_container_trigger(dev, transport_configure);
+       attribute_container_device_trigger(dev, transport_configure);
 }
 EXPORT_SYMBOL_GPL(transport_configure_device);
 
@@ -215,7 +220,7 @@ static int transport_remove_classdev(struct attribute_container *cont,
        struct transport_class *tclass = class_to_transport_class(cont->class);
 
        if (tclass->remove)
-               tclass->remove(dev);
+               tclass->remove(tcont, dev, classdev);
 
        if (tclass->remove != anon_transport_dummy_function) {
                if (tcont->statistics)
index ccdf440021fbe23c8997fc48f4e4928857b906a3..83bfab73ff65cd2deb2205ae75f7d3c067562e8f 100644 (file)
@@ -133,6 +133,7 @@ struct inquiry_data {
  
 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
+static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
 #ifdef AAC_DETAILED_STATUS_INFO
 static char *aac_get_status_string(u32 status);
@@ -348,6 +349,27 @@ static void aac_io_done(struct scsi_cmnd * scsicmd)
        spin_unlock_irqrestore(host->host_lock, cpu_flags);
 }
 
+static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
+{
+       void *buf;
+       unsigned int transfer_len;
+       struct scatterlist *sg = scsicmd->request_buffer;
+
+       if (scsicmd->use_sg) {
+               buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
+               transfer_len = min(sg->length, len + offset);
+       } else {
+               buf = scsicmd->request_buffer;
+               transfer_len = min(scsicmd->request_bufflen, len + offset);
+       }
+
+       memcpy(buf + offset, data, transfer_len - offset);
+
+       if (scsicmd->use_sg) 
+               kunmap_atomic(buf - sg->offset, KM_IRQ0);
+
+}
+
 static void get_container_name_callback(void *context, struct fib * fibptr)
 {
        struct aac_get_name_resp * get_name_reply;
@@ -363,18 +385,22 @@ static void get_container_name_callback(void *context, struct fib * fibptr)
        /* Failure is irrelevant, using default value instead */
        if ((le32_to_cpu(get_name_reply->status) == CT_OK)
         && (get_name_reply->data[0] != '\0')) {
-               int    count;
-               char * dp;
-               char * sp = get_name_reply->data;
+               char *sp = get_name_reply->data;
                sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
                while (*sp == ' ')
                        ++sp;
-               count = sizeof(((struct inquiry_data *)NULL)->inqd_pid);
-               dp = ((struct inquiry_data *)scsicmd->request_buffer)->inqd_pid;
-               if (*sp) do {
-                       *dp++ = (*sp) ? *sp++ : ' ';
-               } while (--count > 0);
+               if (*sp) {
+                       char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
+                       int count = sizeof(d);
+                       char *dp = d;
+                       do {
+                               *dp++ = (*sp) ? *sp++ : ' ';
+                       } while (--count > 0);
+                       aac_internal_transfer(scsicmd, d, 
+                         offsetof(struct inquiry_data, inqd_pid), sizeof(d));
+               }
        }
+
        scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
 
        fib_complete(fibptr);
@@ -777,34 +803,36 @@ int aac_get_adapter_info(struct aac_dev* dev)
        /* 
         * 57 scatter gather elements 
         */
-       dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
-               sizeof(struct aac_fibhdr) -
-               sizeof(struct aac_write) + sizeof(struct sgmap)) /
-                       sizeof(struct sgmap);
-       if (dev->dac_support) {
-               /* 
-                * 38 scatter gather elements 
-                */
-               dev->scsi_host_ptr->sg_tablesize =
-                       (dev->max_fib_size -
+       if (!(dev->raw_io_interface)) {
+               dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
                        sizeof(struct aac_fibhdr) -
-                       sizeof(struct aac_write64) +
-                       sizeof(struct sgmap64)) /
-                               sizeof(struct sgmap64);
-       }
-       dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
-       if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
-               /*
-                * Worst case size that could cause sg overflow when
-                * we break up SG elements that are larger than 64KB.
-                * Would be nice if we could tell the SCSI layer what
-                * the maximum SG element size can be. Worst case is
-                * (sg_tablesize-1) 4KB elements with one 64KB
-                * element.
-                *      32bit -> 468 or 238KB   64bit -> 424 or 212KB
-                */
-               dev->scsi_host_ptr->max_sectors =
-                 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
+                       sizeof(struct aac_write) + sizeof(struct sgmap)) /
+                               sizeof(struct sgmap);
+               if (dev->dac_support) {
+                       /* 
+                        * 38 scatter gather elements 
+                        */
+                       dev->scsi_host_ptr->sg_tablesize =
+                               (dev->max_fib_size -
+                               sizeof(struct aac_fibhdr) -
+                               sizeof(struct aac_write64) +
+                               sizeof(struct sgmap64)) /
+                                       sizeof(struct sgmap64);
+               }
+               dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
+               if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
+                       /*
+                        * Worst case size that could cause sg overflow when
+                        * we break up SG elements that are larger than 64KB.
+                        * Would be nice if we could tell the SCSI layer what
+                        * the maximum SG element size can be. Worst case is
+                        * (sg_tablesize-1) 4KB elements with one 64KB
+                        * element.
+                        *      32bit -> 468 or 238KB   64bit -> 424 or 212KB
+                        */
+                       dev->scsi_host_ptr->max_sectors =
+                         (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
+               }
        }
 
        fib_complete(fibptr);
@@ -814,12 +842,11 @@ int aac_get_adapter_info(struct aac_dev* dev)
 }
 
 
-static void read_callback(void *context, struct fib * fibptr)
+static void io_callback(void *context, struct fib * fibptr)
 {
        struct aac_dev *dev;
        struct aac_read_reply *readreply;
        struct scsi_cmnd *scsicmd;
-       u32 lba;
        u32 cid;
 
        scsicmd = (struct scsi_cmnd *) context;
@@ -827,8 +854,7 @@ static void read_callback(void *context, struct fib * fibptr)
        dev = (struct aac_dev *)scsicmd->device->host->hostdata;
        cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
 
-       lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
-       dprintk((KERN_DEBUG "read_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
+       dprintk((KERN_DEBUG "io_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3], jiffies));
 
        if (fibptr == NULL)
                BUG();
@@ -847,7 +873,7 @@ static void read_callback(void *context, struct fib * fibptr)
                scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
        else {
 #ifdef AAC_DETAILED_STATUS_INFO
-               printk(KERN_WARNING "read_callback: io failed, status = %d\n",
+               printk(KERN_WARNING "io_callback: io failed, status = %d\n",
                  le32_to_cpu(readreply->status));
 #endif
                scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
@@ -867,53 +893,6 @@ static void read_callback(void *context, struct fib * fibptr)
        aac_io_done(scsicmd);
 }
 
-static void write_callback(void *context, struct fib * fibptr)
-{
-       struct aac_dev *dev;
-       struct aac_write_reply *writereply;
-       struct scsi_cmnd *scsicmd;
-       u32 lba;
-       u32 cid;
-
-       scsicmd = (struct scsi_cmnd *) context;
-       dev = (struct aac_dev *)scsicmd->device->host->hostdata;
-       cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
-
-       lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
-       dprintk((KERN_DEBUG "write_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
-       if (fibptr == NULL)
-               BUG();
-
-       if(scsicmd->use_sg)
-               pci_unmap_sg(dev->pdev, 
-                       (struct scatterlist *)scsicmd->buffer,
-                       scsicmd->use_sg,
-                       scsicmd->sc_data_direction);
-       else if(scsicmd->request_bufflen)
-               pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
-                                scsicmd->request_bufflen,
-                                scsicmd->sc_data_direction);
-
-       writereply = (struct aac_write_reply *) fib_data(fibptr);
-       if (le32_to_cpu(writereply->status) == ST_OK)
-               scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
-       else {
-               printk(KERN_WARNING "write_callback: write failed, status = %d\n", writereply->status);
-               scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-               set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
-                                   HARDWARE_ERROR,
-                                   SENCODE_INTERNAL_TARGET_FAILURE,
-                                   ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
-                                   0, 0);
-               memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 
-                               sizeof(struct sense_data));
-       }
-
-       fib_complete(fibptr);
-       fib_free(fibptr);
-       aac_io_done(scsicmd);
-}
-
 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
 {
        u32 lba;
@@ -954,7 +933,32 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
 
        fib_init(cmd_fibcontext);
 
-       if (dev->dac_support == 1) {
+       if (dev->raw_io_interface) {
+               struct aac_raw_io *readcmd;
+               readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
+               readcmd->block[0] = cpu_to_le32(lba);
+               readcmd->block[1] = 0;
+               readcmd->count = cpu_to_le32(count<<9);
+               readcmd->cid = cpu_to_le16(cid);
+               readcmd->flags = cpu_to_le16(1);
+               readcmd->bpTotal = 0;
+               readcmd->bpComplete = 0;
+               
+               aac_build_sgraw(scsicmd, &readcmd->sg);
+               fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
+               if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
+                       BUG();
+               /*
+                *      Now send the Fib to the adapter
+                */
+               status = fib_send(ContainerRawIo,
+                         cmd_fibcontext, 
+                         fibsize, 
+                         FsaNormal, 
+                         0, 1, 
+                         (fib_callback) io_callback, 
+                         (void *) scsicmd);
+       } else if (dev->dac_support == 1) {
                struct aac_read64 *readcmd;
                readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
                readcmd->command = cpu_to_le32(VM_CtHostRead64);
@@ -978,7 +982,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
                          fibsize, 
                          FsaNormal, 
                          0, 1, 
-                         (fib_callback) read_callback, 
+                         (fib_callback) io_callback, 
                          (void *) scsicmd);
        } else {
                struct aac_read *readcmd;
@@ -1002,7 +1006,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
                          fibsize, 
                          FsaNormal, 
                          0, 1, 
-                         (fib_callback) read_callback, 
+                         (fib_callback) io_callback, 
                          (void *) scsicmd);
        }
 
@@ -1061,7 +1065,32 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
        }
        fib_init(cmd_fibcontext);
 
-       if(dev->dac_support == 1) {
+       if (dev->raw_io_interface) {
+               struct aac_raw_io *writecmd;
+               writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
+               writecmd->block[0] = cpu_to_le32(lba);
+               writecmd->block[1] = 0;
+               writecmd->count = cpu_to_le32(count<<9);
+               writecmd->cid = cpu_to_le16(cid);
+               writecmd->flags = 0; 
+               writecmd->bpTotal = 0;
+               writecmd->bpComplete = 0;
+               
+               aac_build_sgraw(scsicmd, &writecmd->sg);
+               fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
+               if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
+                       BUG();
+               /*
+                *      Now send the Fib to the adapter
+                */
+               status = fib_send(ContainerRawIo,
+                         cmd_fibcontext, 
+                         fibsize, 
+                         FsaNormal, 
+                         0, 1, 
+                         (fib_callback) io_callback, 
+                         (void *) scsicmd);
+       } else if (dev->dac_support == 1) {
                struct aac_write64 *writecmd;
                writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
                writecmd->command = cpu_to_le32(VM_CtHostWrite64);
@@ -1085,7 +1114,7 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
                          fibsize, 
                          FsaNormal, 
                          0, 1, 
-                         (fib_callback) write_callback, 
+                         (fib_callback) io_callback, 
                          (void *) scsicmd);
        } else {
                struct aac_write *writecmd;
@@ -1111,7 +1140,7 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
                          fibsize, 
                          FsaNormal, 
                          0, 1, 
-                         (fib_callback) write_callback, 
+                         (fib_callback) io_callback, 
                          (void *) scsicmd);
        }
 
@@ -1340,44 +1369,45 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
        switch (scsicmd->cmnd[0]) {
        case INQUIRY:
        {
-               struct inquiry_data *inq_data_ptr;
+               struct inquiry_data inq_data;
 
                dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
-               inq_data_ptr = (struct inquiry_data *)scsicmd->request_buffer;
-               memset(inq_data_ptr, 0, sizeof (struct inquiry_data));
+               memset(&inq_data, 0, sizeof (struct inquiry_data));
 
-               inq_data_ptr->inqd_ver = 2;     /* claim compliance to SCSI-2 */
-               inq_data_ptr->inqd_dtq = 0x80;  /* set RMB bit to one indicating that the medium is removable */
-               inq_data_ptr->inqd_rdf = 2;     /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
-               inq_data_ptr->inqd_len = 31;
+               inq_data.inqd_ver = 2;  /* claim compliance to SCSI-2 */
+               inq_data.inqd_dtq = 0x80;       /* set RMB bit to one indicating that the medium is removable */
+               inq_data.inqd_rdf = 2;  /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
+               inq_data.inqd_len = 31;
                /*Format for "pad2" is  RelAdr | WBus32 | WBus16 |  Sync  | Linked |Reserved| CmdQue | SftRe */
-               inq_data_ptr->inqd_pad2= 0x32 ;  /*WBus16|Sync|CmdQue */
+               inq_data.inqd_pad2= 0x32 ;       /*WBus16|Sync|CmdQue */
                /*
                 *      Set the Vendor, Product, and Revision Level
                 *      see: <vendor>.c i.e. aac.c
                 */
                if (scsicmd->device->id == host->this_id) {
-                       setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), (sizeof(container_types)/sizeof(char *)));
-                       inq_data_ptr->inqd_pdt = INQD_PDT_PROC; /* Processor device */
+                       setinqstr(cardtype, (void *) (inq_data.inqd_vid), (sizeof(container_types)/sizeof(char *)));
+                       inq_data.inqd_pdt = INQD_PDT_PROC;      /* Processor device */
+                       aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
                        scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
                        scsicmd->scsi_done(scsicmd);
                        return 0;
                }
-               setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr[cid].type);
-               inq_data_ptr->inqd_pdt = INQD_PDT_DA;   /* Direct/random access device */
+               setinqstr(cardtype, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
+               inq_data.inqd_pdt = INQD_PDT_DA;        /* Direct/random access device */
+               aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
                return aac_get_container_name(scsicmd, cid);
        }
        case READ_CAPACITY:
        {
                u32 capacity;
-               char *cp;
+               char cp[8];
 
                dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
                if (fsa_dev_ptr[cid].size <= 0x100000000LL)
                        capacity = fsa_dev_ptr[cid].size - 1;
                else
                        capacity = (u32)-1;
-               cp = scsicmd->request_buffer;
+
                cp[0] = (capacity >> 24) & 0xff;
                cp[1] = (capacity >> 16) & 0xff;
                cp[2] = (capacity >> 8) & 0xff;
@@ -1386,6 +1416,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
                cp[5] = 0;
                cp[6] = 2;
                cp[7] = 0;
+               aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
 
                scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
                scsicmd->scsi_done(scsicmd);
@@ -1395,15 +1426,15 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 
        case MODE_SENSE:
        {
-               char *mode_buf;
+               char mode_buf[4];
 
                dprintk((KERN_DEBUG "MODE SENSE command.\n"));
-               mode_buf = scsicmd->request_buffer;
                mode_buf[0] = 3;        /* Mode data length */
                mode_buf[1] = 0;        /* Medium type - default */
                mode_buf[2] = 0;        /* Device-specific param, bit 8: 0/1 = write enabled/protected */
                mode_buf[3] = 0;        /* Block descriptor length */
 
+               aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
                scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
                scsicmd->scsi_done(scsicmd);
 
@@ -1411,10 +1442,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
        }
        case MODE_SENSE_10:
        {
-               char *mode_buf;
+               char mode_buf[8];
 
                dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
-               mode_buf = scsicmd->request_buffer;
                mode_buf[0] = 0;        /* Mode data length (MSB) */
                mode_buf[1] = 6;        /* Mode data length (LSB) */
                mode_buf[2] = 0;        /* Medium type - default */
@@ -1423,6 +1453,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
                mode_buf[5] = 0;        /* reserved */
                mode_buf[6] = 0;        /* Block descriptor length (MSB) */
                mode_buf[7] = 0;        /* Block descriptor length (LSB) */
+               aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
 
                scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
                scsicmd->scsi_done(scsicmd);
@@ -1894,7 +1925,7 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
        srbcmd->id   = cpu_to_le32(scsicmd->device->id);
        srbcmd->lun      = cpu_to_le32(scsicmd->device->lun);
        srbcmd->flags    = cpu_to_le32(flag);
-       timeout = (scsicmd->timeout-jiffies)/HZ;
+       timeout = scsicmd->timeout_per_command/HZ;
        if(timeout == 0){
                timeout = 1;
        }
@@ -2077,6 +2108,76 @@ static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* p
        return byte_count;
 }
 
+static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
+{
+       struct Scsi_Host *host = scsicmd->device->host;
+       struct aac_dev *dev = (struct aac_dev *)host->hostdata;
+       unsigned long byte_count = 0;
+
+       // Get rid of old data
+       psg->count = 0;
+       psg->sg[0].next = 0;
+       psg->sg[0].prev = 0;
+       psg->sg[0].addr[0] = 0;
+       psg->sg[0].addr[1] = 0;
+       psg->sg[0].count = 0;
+       psg->sg[0].flags = 0;
+       if (scsicmd->use_sg) {
+               struct scatterlist *sg;
+               int i;
+               int sg_count;
+               sg = (struct scatterlist *) scsicmd->request_buffer;
+
+               sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
+                       scsicmd->sc_data_direction);
+
+               for (i = 0; i < sg_count; i++) {
+                       int count = sg_dma_len(sg);
+                       u64 addr = sg_dma_address(sg);
+                       psg->sg[i].next = 0;
+                       psg->sg[i].prev = 0;
+                       psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
+                       psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
+                       psg->sg[i].count = cpu_to_le32(count);
+                       psg->sg[i].flags = 0;
+                       byte_count += count;
+                       sg++;
+               }
+               psg->count = cpu_to_le32(sg_count);
+               /* hba wants the size to be exact */
+               if(byte_count > scsicmd->request_bufflen){
+                       u32 temp = le32_to_cpu(psg->sg[i-1].count) - 
+                               (byte_count - scsicmd->request_bufflen);
+                       psg->sg[i-1].count = cpu_to_le32(temp);
+                       byte_count = scsicmd->request_bufflen;
+               }
+               /* Check for command underflow */
+               if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
+                       printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
+                                       byte_count, scsicmd->underflow);
+               }
+       }
+       else if(scsicmd->request_bufflen) {
+               int count;
+               u64 addr;
+               scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
+                               scsicmd->request_buffer,
+                               scsicmd->request_bufflen,
+                               scsicmd->sc_data_direction);
+               addr = scsicmd->SCp.dma_handle;
+               count = scsicmd->request_bufflen;
+               psg->count = cpu_to_le32(1);
+               psg->sg[0].next = 0;
+               psg->sg[0].prev = 0;
+               psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
+               psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
+               psg->sg[0].count = cpu_to_le32(count);
+               psg->sg[0].flags = 0;
+               byte_count = scsicmd->request_bufflen;
+       }
+       return byte_count;
+}
+
 #ifdef AAC_DETAILED_STATUS_INFO
 
 struct aac_srb_status_info {
index 4ab07861b457fd80c1af736cb17dd633119228e6..e40528185d48fab70a6d5011ed1a4f6773073cef 100644 (file)
@@ -110,6 +110,22 @@ struct user_sgentry64 {
        u32     count;  /* Length. */
 };
 
+struct sgentryraw {
+       __le32          next;   /* reserved for F/W use */
+       __le32          prev;   /* reserved for F/W use */
+       __le32          addr[2];
+       __le32          count;
+       __le32          flags;  /* reserved for F/W use */
+};
+
+struct user_sgentryraw {
+       u32             next;   /* reserved for F/W use */
+       u32             prev;   /* reserved for F/W use */
+       u32             addr[2];
+       u32             count;
+       u32             flags;  /* reserved for F/W use */
+};
+
 /*
  *     SGMAP
  *
@@ -137,6 +153,16 @@ struct user_sgmap64 {
        struct user_sgentry64 sg[1];
 };
 
+struct sgmapraw {
+       __le32            count;
+       struct sgentryraw sg[1];
+};
+
+struct user_sgmapraw {
+       u32               count;
+       struct user_sgentryraw sg[1];
+};
+
 struct creation_info
 {
        u8              buildnum;               /* e.g., 588 */
@@ -351,6 +377,7 @@ struct hw_fib {
  */
 #define                ContainerCommand                500
 #define                ContainerCommand64              501
+#define                ContainerRawIo                  502
 /*
  *     Cluster Commands
  */
@@ -456,6 +483,7 @@ struct adapter_ops
 {
        void (*adapter_interrupt)(struct aac_dev *dev);
        void (*adapter_notify)(struct aac_dev *dev, u32 event);
+       void (*adapter_disable_int)(struct aac_dev *dev);
        int  (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4);
        int  (*adapter_check_health)(struct aac_dev *dev);
 };
@@ -981,6 +1009,9 @@ struct aac_dev
        u8                      nondasd_support; 
        u8                      dac_support;
        u8                      raid_scsi_mode;
+       /* macro side-effects BEWARE */
+#      define                  raw_io_interface \
+         init->InitStructRevision==cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4)
        u8                      printf_enabled;
 };
 
@@ -990,6 +1021,9 @@ struct aac_dev
 #define aac_adapter_notify(dev, event) \
        (dev)->a_ops.adapter_notify(dev, event)
 
+#define aac_adapter_disable_int(dev) \
+       (dev)->a_ops.adapter_disable_int(dev)
+
 #define aac_adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) \
        (dev)->a_ops.adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4)
 
@@ -1156,6 +1190,17 @@ struct aac_write_reply
        __le32          committed;
 };
 
+struct aac_raw_io
+{
+       __le32          block[2];
+       __le32          count;
+       __le16          cid;
+       __le16          flags;          /* 00 W, 01 R */
+       __le16          bpTotal;        /* reserved for F/W use */
+       __le16          bpComplete;     /* reserved for F/W use */
+       struct sgmapraw sg;
+};
+
 #define CT_FLUSH_CACHE 129
 struct aac_synchronize {
        __le32          command;        /* VM_ContainerConfig */
@@ -1196,7 +1241,7 @@ struct aac_srb
 };
 
 /*
- * This and assocated data structs are used by the 
+ * This and associated data structs are used by the
  * ioctl caller and are in cpu order.
  */
 struct user_aac_srb
@@ -1508,11 +1553,12 @@ struct fib_ioctl
 
 struct revision
 {
-       u32 compat;
-       u32 version;
-       u32 build;
+       __le32 compat;
+       __le32 version;
+       __le32 build;
 };
        
+
 /*
  *     Ugly - non Linux like ioctl coding for back compat.
  */
@@ -1733,3 +1779,4 @@ int aac_get_adapter_info(struct aac_dev* dev);
 int aac_send_shutdown(struct aac_dev *dev);
 extern int numacb;
 extern int acbsize;
+extern char aac_driver_version[];
index 85387099aab238db175a7b53a238a819f597ba3e..71f1cad9b5f077bf8e5ad1bb3024135e5875c3c7 100644 (file)
@@ -287,7 +287,6 @@ return_fib:
                kfree(fib->hw_fib);
                kfree(fib);
                status = 0;
-               fibctx->jiffies = jiffies/HZ;
        } else {
                spin_unlock_irqrestore(&dev->fib_lock, flags);
                if (f.wait) {
@@ -302,6 +301,7 @@ return_fib:
                        status = -EAGAIN;
                }       
        }
+       fibctx->jiffies = jiffies/HZ;
        return status;
 }
 
@@ -405,10 +405,20 @@ static int close_getadapter_fib(struct aac_dev * dev, void __user *arg)
 static int check_revision(struct aac_dev *dev, void __user *arg)
 {
        struct revision response;
-
-       response.compat = 1;
-       response.version = le32_to_cpu(dev->adapter_info.kernelrev);
-       response.build = le32_to_cpu(dev->adapter_info.kernelbuild);
+       char *driver_version = aac_driver_version;
+       u32 version;
+
+       response.compat = cpu_to_le32(1);
+       version = (simple_strtol(driver_version, 
+                               &driver_version, 10) << 24) | 0x00000400;
+       version += simple_strtol(driver_version + 1, &driver_version, 10) << 16;
+       version += simple_strtol(driver_version + 1, NULL, 10);
+       response.version = cpu_to_le32(version);
+#      if (defined(AAC_DRIVER_BUILD))
+               response.build = cpu_to_le32(AAC_DRIVER_BUILD);
+#      else
+               response.build = cpu_to_le32(9999);
+#      endif
 
        if (copy_to_user(arg, &response, sizeof(response)))
                return -EFAULT;
index 43557bf661f63098a2754c3fa255b693d02979c2..75abd04532890de2c7855e39bb1551c7886a0468 100644 (file)
@@ -44,7 +44,9 @@
 
 #include "aacraid.h"
 
-struct aac_common aac_config;
+struct aac_common aac_config = {
+       .irq_mod = 1
+};
 
 static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign)
 {
index 5322865942e28b1a3911d83a8d2d6104263dd869..a1d303f034808f3e31a2f44860355f1e240d7ee4 100644 (file)
@@ -254,6 +254,7 @@ static void fib_dealloc(struct fib * fibptr)
 static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify)
 {
        struct aac_queue * q;
+       unsigned long idx;
 
        /*
         *      All of the queues wrap when they reach the end, so we check
@@ -263,10 +264,23 @@ static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entr
         */
 
        q = &dev->queues->queue[qid];
-       
-       *index = le32_to_cpu(*(q->headers.producer));
-       if ((*index - 2) == le32_to_cpu(*(q->headers.consumer)))
+
+       idx = *index = le32_to_cpu(*(q->headers.producer));
+       /* Interrupt Moderation, only interrupt for first two entries */
+       if (idx != le32_to_cpu(*(q->headers.consumer))) {
+               if (--idx == 0) {
+                       if (qid == AdapHighCmdQueue)
+                               idx = ADAP_HIGH_CMD_ENTRIES;
+                       else if (qid == AdapNormCmdQueue)
+                               idx = ADAP_NORM_CMD_ENTRIES;
+                       else if (qid == AdapHighRespQueue) 
+                               idx = ADAP_HIGH_RESP_ENTRIES;
+                       else if (qid == AdapNormRespQueue) 
+                               idx = ADAP_NORM_RESP_ENTRIES;
+               }
+               if (idx != le32_to_cpu(*(q->headers.consumer)))
                        *nonotify = 1; 
+       }
 
        if (qid == AdapHighCmdQueue) {
                if (*index >= ADAP_HIGH_CMD_ENTRIES)
index 562da90480a1426346ceba19efe54108e4043826..4ff29d7f58252cb6b5fabb309aa84ad25eea64be 100644 (file)
  * Abstract: Linux Driver entry module for Adaptec RAID Array Controller
  */
 
-#define AAC_DRIVER_VERSION             "1.1.2-lk2"
-#define AAC_DRIVER_BUILD_DATE          __DATE__
+#define AAC_DRIVER_VERSION             "1.1-4"
+#ifndef AAC_DRIVER_BRANCH
+#define AAC_DRIVER_BRANCH              ""
+#endif
+#define AAC_DRIVER_BUILD_DATE          __DATE__ " " __TIME__
 #define AAC_DRIVERNAME                 "aacraid"
 
 #include <linux/compat.h>
 
 #include "aacraid.h"
 
+#ifdef AAC_DRIVER_BUILD
+#define _str(x) #x
+#define str(x) _str(x)
+#define AAC_DRIVER_FULL_VERSION        AAC_DRIVER_VERSION "[" str(AAC_DRIVER_BUILD) "]" AAC_DRIVER_BRANCH
+#else
+#define AAC_DRIVER_FULL_VERSION        AAC_DRIVER_VERSION AAC_DRIVER_BRANCH " " AAC_DRIVER_BUILD_DATE
+#endif
 
 MODULE_AUTHOR("Red Hat Inc and Adaptec");
 MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, "
                   "Adaptec Advanced Raid Products, "
                   "and HP NetRAID-4M SCSI driver");
 MODULE_LICENSE("GPL");
-MODULE_VERSION(AAC_DRIVER_VERSION);
+MODULE_VERSION(AAC_DRIVER_FULL_VERSION);
 
 static LIST_HEAD(aac_devices);
 static int aac_cfg_major = -1;
+char aac_driver_version[] = AAC_DRIVER_FULL_VERSION;
 
 /*
  * Because of the way Linux names scsi devices, the order in this table has
@@ -109,36 +120,39 @@ static struct pci_device_id aac_pci_tbl[] = {
        { 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5085AU (Hurricane) */
        { 0x9005, 0x0285, 0x9005, 0x02a4, 0, 0, 30 }, /* ICP9085LI (Marauder-X) */
        { 0x9005, 0x0285, 0x9005, 0x02a5, 0, 0, 31 }, /* ICP5085BR (Marauder-E) */
-       { 0x9005, 0x0287, 0x9005, 0x0800, 0, 0, 32 }, /* Themisto Jupiter Platform */
-       { 0x9005, 0x0200, 0x9005, 0x0200, 0, 0, 32 }, /* Themisto Jupiter Platform */
-       { 0x9005, 0x0286, 0x9005, 0x0800, 0, 0, 33 }, /* Callisto Jupiter Platform */
-       { 0x9005, 0x0285, 0x9005, 0x028e, 0, 0, 34 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
-       { 0x9005, 0x0285, 0x9005, 0x028f, 0, 0, 35 }, /* ASR-2025SA SATA SO-DIMM PCI-X ZCR (Terminator) */
-       { 0x9005, 0x0285, 0x9005, 0x0290, 0, 0, 36 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II) */
-       { 0x9005, 0x0285, 0x1028, 0x0291, 0, 0, 37 }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */
-       { 0x9005, 0x0285, 0x9005, 0x0292, 0, 0, 38 }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */
-       { 0x9005, 0x0285, 0x9005, 0x0293, 0, 0, 39 }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */
-       { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 40 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
-       { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 41 }, /* AAR-2610SA PCI SATA 6ch */
-       { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 42 }, /* ASR-2240S (SabreExpress) */
-       { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 43 }, /* ASR-4005SAS */
-       { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 44 }, /* IBM 8i (AvonPark) */
-       { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 44 }, /* IBM 8i (AvonPark Lite) */
-       { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 45 }, /* ASR-4000SAS (BlackBird) */
-       { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 46 }, /* ASR-4800SAS (Marauder-X) */
-       { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 47 }, /* ASR-4805SAS (Marauder-E) */
-       { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 48 }, /* ASR-4810SAS (Hurricane */
-
-       { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 49 }, /* Perc 320/DC*/
-       { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 50 }, /* Adaptec 5400S (Mustang)*/
-       { 0x1011, 0x0046, 0x9005, 0x0364, 0, 0, 51 }, /* Adaptec 5400S (Mustang)*/
-       { 0x1011, 0x0046, 0x9005, 0x1364, 0, 0, 52 }, /* Dell PERC2/QC */
-       { 0x1011, 0x0046, 0x103c, 0x10c2, 0, 0, 53 }, /* HP NetRAID-4M */
-
-       { 0x9005, 0x0285, 0x1028, PCI_ANY_ID, 0, 0, 54 }, /* Dell Catchall */
-       { 0x9005, 0x0285, 0x17aa, PCI_ANY_ID, 0, 0, 55 }, /* Legend Catchall */
-       { 0x9005, 0x0285, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 56 }, /* Adaptec Catch All */
-       { 0x9005, 0x0286, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 57 }, /* Adaptec Rocket Catch All */
+       { 0x9005, 0x0286, 0x9005, 0x02a6, 0, 0, 32 }, /* ICP9067MA (Intruder-6) */
+       { 0x9005, 0x0287, 0x9005, 0x0800, 0, 0, 33 }, /* Themisto Jupiter Platform */
+       { 0x9005, 0x0200, 0x9005, 0x0200, 0, 0, 33 }, /* Themisto Jupiter Platform */
+       { 0x9005, 0x0286, 0x9005, 0x0800, 0, 0, 34 }, /* Callisto Jupiter Platform */
+       { 0x9005, 0x0285, 0x9005, 0x028e, 0, 0, 35 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
+       { 0x9005, 0x0285, 0x9005, 0x028f, 0, 0, 36 }, /* ASR-2025SA SATA SO-DIMM PCI-X ZCR (Terminator) */
+       { 0x9005, 0x0285, 0x9005, 0x0290, 0, 0, 37 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II) */
+       { 0x9005, 0x0285, 0x1028, 0x0291, 0, 0, 38 }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */
+       { 0x9005, 0x0285, 0x9005, 0x0292, 0, 0, 39 }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */
+       { 0x9005, 0x0285, 0x9005, 0x0293, 0, 0, 40 }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */
+       { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 41 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
+       { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 42 }, /* AAR-2610SA PCI SATA 6ch */
+       { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 43 }, /* ASR-2240S (SabreExpress) */
+       { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 44 }, /* ASR-4005SAS */
+       { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 45 }, /* IBM 8i (AvonPark) */
+       { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 45 }, /* IBM 8i (AvonPark Lite) */
+       { 0x9005, 0x0286, 0x1014, 0x9580, 0, 0, 46 }, /* IBM 8k/8k-l8 (Aurora) */
+       { 0x9005, 0x0286, 0x1014, 0x9540, 0, 0, 47 }, /* IBM 8k/8k-l4 (Aurora Lite) */
+       { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 48 }, /* ASR-4000SAS (BlackBird) */
+       { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 49 }, /* ASR-4800SAS (Marauder-X) */
+       { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 50 }, /* ASR-4805SAS (Marauder-E) */
+       { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 51 }, /* ASR-4810SAS (Hurricane */
+
+       { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 52 }, /* Perc 320/DC*/
+       { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 53 }, /* Adaptec 5400S (Mustang)*/
+       { 0x1011, 0x0046, 0x9005, 0x0364, 0, 0, 54 }, /* Adaptec 5400S (Mustang)*/
+       { 0x1011, 0x0046, 0x9005, 0x1364, 0, 0, 55 }, /* Dell PERC2/QC */
+       { 0x1011, 0x0046, 0x103c, 0x10c2, 0, 0, 56 }, /* HP NetRAID-4M */
+
+       { 0x9005, 0x0285, 0x1028, PCI_ANY_ID, 0, 0, 57 }, /* Dell Catchall */
+       { 0x9005, 0x0285, 0x17aa, PCI_ANY_ID, 0, 0, 58 }, /* Legend Catchall */
+       { 0x9005, 0x0285, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 59 }, /* Adaptec Catch All */
+       { 0x9005, 0x0286, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 60 }, /* Adaptec Rocket Catch All */
        { 0,}
 };
 MODULE_DEVICE_TABLE(pci, aac_pci_tbl);
@@ -180,8 +194,9 @@ static struct aac_driver_ident aac_drivers[] = {
        { aac_rkt_init, "aacraid",  "ICP     ", "ICP9047MA       ", 1 }, /* ICP9047MA (Lancer) */
        { aac_rkt_init, "aacraid",  "ICP     ", "ICP9087MA       ", 1 }, /* ICP9087MA (Lancer) */
        { aac_rkt_init, "aacraid",  "ICP     ", "ICP5085AU       ", 1 }, /* ICP5085AU (Hurricane) */
-       { aac_rkt_init, "aacraid",  "ICP     ", "ICP9085LI       ", 1 }, /* ICP9085LI (Marauder-X) */
-       { aac_rkt_init, "aacraid",  "ICP     ", "ICP5085BR       ", 1 }, /* ICP5085BR (Marauder-E) */
+       { aac_rx_init, "aacraid",  "ICP     ", "ICP9085LI       ", 1 }, /* ICP9085LI (Marauder-X) */
+       { aac_rx_init, "aacraid",  "ICP     ", "ICP5085BR       ", 1 }, /* ICP5085BR (Marauder-E) */
+       { aac_rkt_init, "aacraid",  "ICP     ", "ICP9067MA       ", 1 }, /* ICP9067MA (Intruder-6) */
        { NULL        , "aacraid",  "ADAPTEC ", "Themisto        ", 0, AAC_QUIRK_SLAVE }, /* Jupiter Platform */
        { aac_rkt_init, "aacraid",  "ADAPTEC ", "Callisto        ", 2, AAC_QUIRK_MASTER }, /* Jupiter Platform */
        { aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2020SA       ", 1 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
@@ -195,10 +210,12 @@ static struct aac_driver_ident aac_drivers[] = {
        { aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2240S       ", 1 }, /* ASR-2240S (SabreExpress) */
        { aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4005SAS     ", 1 }, /* ASR-4005SAS */
        { aac_rx_init, "ServeRAID","IBM     ", "ServeRAID 8i    ", 1 }, /* IBM 8i (AvonPark) */
+       { aac_rkt_init, "ServeRAID","IBM     ", "ServeRAID 8k-l8 ", 1 }, /* IBM 8k/8k-l8 (Aurora) */
+       { aac_rkt_init, "ServeRAID","IBM     ", "ServeRAID 8k-l4 ", 1 }, /* IBM 8k/8k-l4 (Aurora Lite) */
        { aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4000SAS     ", 1 }, /* ASR-4000SAS (BlackBird & AvonPark) */
        { aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4800SAS     ", 1 }, /* ASR-4800SAS (Marauder-X) */
        { aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4805SAS     ", 1 }, /* ASR-4805SAS (Marauder-E) */
-       { aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4810SAS     ", 1 }, /* ASR-4810SAS (Hurricane) */
+       { aac_rkt_init, "aacraid",  "ADAPTEC ", "ASR-4810SAS     ", 1 }, /* ASR-4810SAS (Hurricane) */
 
        { aac_rx_init, "percraid", "DELL    ", "PERC 320/DC     ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/
        { aac_sa_init, "aacraid",  "ADAPTEC ", "Adaptec 5400S   ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/
@@ -839,11 +856,12 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
 
        return 0;
 
-out_deinit:
+ out_deinit:
        kill_proc(aac->thread_pid, SIGKILL, 0);
        wait_for_completion(&aac->aif_completion);
 
        aac_send_shutdown(aac);
+       aac_adapter_disable_int(aac);
        fib_map_free(aac);
        pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys);
        kfree(aac->queues);
@@ -860,6 +878,13 @@ out_deinit:
        return error;
 }
 
+static void aac_shutdown(struct pci_dev *dev)
+{
+       struct Scsi_Host *shost = pci_get_drvdata(dev);
+       struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
+       aac_send_shutdown(aac);
+}
+
 static void __devexit aac_remove_one(struct pci_dev *pdev)
 {
        struct Scsi_Host *shost = pci_get_drvdata(pdev);
@@ -871,6 +896,7 @@ static void __devexit aac_remove_one(struct pci_dev *pdev)
        wait_for_completion(&aac->aif_completion);
 
        aac_send_shutdown(aac);
+       aac_adapter_disable_int(aac);
        fib_map_free(aac);
        pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr,
                        aac->comm_phys);
@@ -891,14 +917,15 @@ static struct pci_driver aac_pci_driver = {
        .id_table       = aac_pci_tbl,
        .probe          = aac_probe_one,
        .remove         = __devexit_p(aac_remove_one),
+       .shutdown       = aac_shutdown,
 };
 
 static int __init aac_init(void)
 {
        int error;
        
-       printk(KERN_INFO "Red Hat/Adaptec aacraid driver (%s %s)\n",
-                       AAC_DRIVER_VERSION, AAC_DRIVER_BUILD_DATE);
+       printk(KERN_INFO "Adaptec %s driver (%s)\n",
+         AAC_DRIVERNAME, aac_driver_version);
 
        error = pci_module_init(&aac_pci_driver);
        if (error)
@@ -909,6 +936,7 @@ static int __init aac_init(void)
                printk(KERN_WARNING
                       "aacraid: unable to register \"aac\" device.\n");
        }
+
        return 0;
 }
 
index 7d68b7825137506b07af8a83e52f4302f11e31ff..557287a0b80bdbfde17a349efb9aa7666cd7d7ca 100644 (file)
@@ -87,6 +87,16 @@ static irqreturn_t aac_rkt_intr(int irq, void *dev_id, struct pt_regs *regs)
        return IRQ_NONE;
 }
 
+/**
+ *     aac_rkt_disable_interrupt       -       Disable interrupts
+ *     @dev: Adapter
+ */
+
+static void aac_rkt_disable_interrupt(struct aac_dev *dev)
+{
+       rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
+}
+
 /**
  *     rkt_sync_cmd    -       send a command and wait
  *     @dev: Adapter
@@ -412,10 +422,19 @@ int aac_rkt_init(struct aac_dev *dev)
         *      Fill in the function dispatch table.
         */
        dev->a_ops.adapter_interrupt = aac_rkt_interrupt_adapter;
+       dev->a_ops.adapter_disable_int = aac_rkt_disable_interrupt;
        dev->a_ops.adapter_notify = aac_rkt_notify_adapter;
        dev->a_ops.adapter_sync_cmd = rkt_sync_cmd;
        dev->a_ops.adapter_check_health = aac_rkt_check_health;
 
+       /*
+        *      First clear out all interrupts.  Then enable the one's that we
+        *      can handle.
+        */
+       rkt_writeb(dev, MUnit.OIMR, 0xff);
+       rkt_writel(dev, MUnit.ODR, 0xffffffff);
+       rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
+
        if (aac_init_adapter(dev) == NULL)
                goto error_irq;
        /*
@@ -438,6 +457,7 @@ error_kfree:
        kfree(dev->queues);
 
 error_irq:
+       rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
        free_irq(dev->scsi_host_ptr->irq, (void *)dev);
 
 error_iounmap:
index 1ff25f49fadace646d6a1c19073527a222087f61..a8459faf87caf88facabe65a6dee10982ac481f6 100644 (file)
@@ -87,6 +87,16 @@ static irqreturn_t aac_rx_intr(int irq, void *dev_id, struct pt_regs *regs)
        return IRQ_NONE;
 }
 
+/**
+ *     aac_rx_disable_interrupt        -       Disable interrupts
+ *     @dev: Adapter
+ */
+
+static void aac_rx_disable_interrupt(struct aac_dev *dev)
+{
+       rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
+}
+
 /**
  *     rx_sync_cmd     -       send a command and wait
  *     @dev: Adapter
@@ -412,10 +422,19 @@ int aac_rx_init(struct aac_dev *dev)
         *      Fill in the function dispatch table.
         */
        dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter;
+       dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt;
        dev->a_ops.adapter_notify = aac_rx_notify_adapter;
        dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
        dev->a_ops.adapter_check_health = aac_rx_check_health;
 
+       /*
+        *      First clear out all interrupts.  Then enable the one's that we
+        *      can handle.
+        */
+       rx_writeb(dev, MUnit.OIMR, 0xff);
+       rx_writel(dev, MUnit.ODR, 0xffffffff);
+       rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
+
        if (aac_init_adapter(dev) == NULL)
                goto error_irq;
        /*
@@ -438,6 +457,7 @@ error_kfree:
        kfree(dev->queues);
 
 error_irq:
+       rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
        free_irq(dev->scsi_host_ptr->irq, (void *)dev);
 
 error_iounmap:
index 0680249ab861600702d536bf92309e65ac23002d..3900abc5850d35e9d731f1c19840c912f63c98fe 100644 (file)
@@ -81,6 +81,16 @@ static irqreturn_t aac_sa_intr(int irq, void *dev_id, struct pt_regs *regs)
        return IRQ_NONE;
 }
 
+/**
+ *     aac_sa_disable_interrupt        -       disable interrupt
+ *     @dev: Which adapter to enable.
+ */
+
+static void aac_sa_disable_interrupt (struct aac_dev *dev)
+{
+       sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
+}
+
 /**
  *     aac_sa_notify_adapter           -       handle adapter notification
  *     @dev:   Adapter that notification is for
@@ -214,9 +224,8 @@ static int sa_sync_cmd(struct aac_dev *dev, u32 command,
  
 static void aac_sa_interrupt_adapter (struct aac_dev *dev)
 {
-       u32 ret;
        sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
-                       &ret, NULL, NULL, NULL, NULL);
+                       NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -352,10 +361,18 @@ int aac_sa_init(struct aac_dev *dev)
         */
 
        dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter;
+       dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt;
        dev->a_ops.adapter_notify = aac_sa_notify_adapter;
        dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
        dev->a_ops.adapter_check_health = aac_sa_check_health;
 
+       /*
+        *      First clear out all interrupts.  Then enable the one's that 
+        *      we can handle.
+        */
+       sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
+       sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 | 
+                               DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
 
        if(aac_init_adapter(dev) == NULL)
                goto error_irq;
@@ -381,6 +398,7 @@ error_kfree:
        kfree(dev->queues);
 
 error_irq:
+       sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
        free_irq(dev->scsi_host_ptr->irq, (void *)dev);
 
 error_iounmap:
index 0fb93363eb2236ba53f701972d317a23b334e97b..37ec5411e325578ff572429e4868efa44884789d 100644 (file)
@@ -9200,8 +9200,8 @@ asc_prt_scsi_cmnd(struct scsi_cmnd *s)
         (unsigned) s->serial_number, s->retries, s->allowed);
 
     printk(
-" timeout_per_command %d, timeout_total %d, timeout %d\n",
-        s->timeout_per_command, s->timeout_total, s->timeout);
+" timeout_per_command %d\n",
+        s->timeout_per_command);
 
     printk(
 " scsi_done 0x%lx, done 0x%lx, host_scribble 0x%lx, result 0x%x\n",
index c2523a30a7f5a7485ad710604bd2d0f00703de33..69ed77fcb71f9076213761b2a18025a16408d406 100644 (file)
@@ -5,6 +5,7 @@
 config SCSI_AIC79XX
        tristate "Adaptec AIC79xx U320 support"
        depends on PCI && SCSI
+       select SCSI_SPI_ATTRS
        help
        This driver supports all of Adaptec's Ultra 320 PCI-X
        based SCSI controllers.
index 00f3bd1e181e7bba9514583f4b2e45b8ab752a03..527efd36f5c18c2a373872e25840fadc178b855c 100644 (file)
@@ -126,7 +126,6 @@ aic7770_find_device(uint32_t id)
 int
 aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io)
 {
-       u_long  l;
        int     error;
        int     have_seeprom;
        u_int   hostconf;
index fd4b2f3eb0c2098df7dcf3fe81a8fd8278df1699..653fb0b42aeac3283a0796336588560b81c5a173 100644 (file)
@@ -1247,9 +1247,6 @@ struct ahd_softc {
        uint16_t                  user_tagenable;/* Tagged Queuing allowed */
 };
 
-TAILQ_HEAD(ahd_softc_tailq, ahd_softc);
-extern struct ahd_softc_tailq ahd_tailq;
-
 /*************************** IO Cell Configuration ****************************/
 #define        AHD_PRECOMP_SLEW_INDEX                                          \
     (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
@@ -1374,8 +1371,6 @@ void                       ahd_enable_coalescing(struct ahd_softc *ahd,
 void                    ahd_pause_and_flushwork(struct ahd_softc *ahd);
 int                     ahd_suspend(struct ahd_softc *ahd); 
 int                     ahd_resume(struct ahd_softc *ahd);
-void                    ahd_softc_insert(struct ahd_softc *);
-struct ahd_softc       *ahd_find_softc(struct ahd_softc *ahd);
 void                    ahd_set_unit(struct ahd_softc *, int);
 void                    ahd_set_name(struct ahd_softc *, char *);
 struct scb             *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
@@ -1524,7 +1519,6 @@ void                      ahd_print_scb(struct scb *scb);
 void                   ahd_print_devinfo(struct ahd_softc *ahd,
                                          struct ahd_devinfo *devinfo);
 void                   ahd_dump_sglist(struct scb *scb);
-void                   ahd_dump_all_cards_state(void);
 void                   ahd_dump_card_state(struct ahd_softc *ahd);
 int                    ahd_print_register(ahd_reg_parse_entry_t *table,
                                           u_int num_entries,
index 137fb1a37dd172c3f64bade86779689fdf3639fc..4e8f00df978dab2ad226e1566f118b7108165081 100644 (file)
@@ -52,8 +52,6 @@
 #include <dev/aic7xxx/aicasm/aicasm_insformat.h>
 #endif
 
-/******************************** Globals *************************************/
-struct ahd_softc_tailq ahd_tailq = TAILQ_HEAD_INITIALIZER(ahd_tailq);
 
 /***************************** Lookup Tables **********************************/
 char *ahd_chip_names[] =
@@ -5179,74 +5177,6 @@ ahd_softc_init(struct ahd_softc *ahd)
        return (0);
 }
 
-void
-ahd_softc_insert(struct ahd_softc *ahd)
-{
-       struct ahd_softc *list_ahd;
-
-#if AHD_PCI_CONFIG > 0
-       /*
-        * Second Function PCI devices need to inherit some
-        * settings from function 0.
-        */
-       if ((ahd->features & AHD_MULTI_FUNC) != 0) {
-               TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
-                       ahd_dev_softc_t list_pci;
-                       ahd_dev_softc_t pci;
-
-                       list_pci = list_ahd->dev_softc;
-                       pci = ahd->dev_softc;
-                       if (ahd_get_pci_slot(list_pci) == ahd_get_pci_slot(pci)
-                        && ahd_get_pci_bus(list_pci) == ahd_get_pci_bus(pci)) {
-                               struct ahd_softc *master;
-                               struct ahd_softc *slave;
-
-                               if (ahd_get_pci_function(list_pci) == 0) {
-                                       master = list_ahd;
-                                       slave = ahd;
-                               } else {
-                                       master = ahd;
-                                       slave = list_ahd;
-                               }
-                               slave->flags &= ~AHD_BIOS_ENABLED; 
-                               slave->flags |=
-                                   master->flags & AHD_BIOS_ENABLED;
-                               break;
-                       }
-               }
-       }
-#endif
-
-       /*
-        * Insertion sort into our list of softcs.
-        */
-       list_ahd = TAILQ_FIRST(&ahd_tailq);
-       while (list_ahd != NULL
-           && ahd_softc_comp(ahd, list_ahd) <= 0)
-               list_ahd = TAILQ_NEXT(list_ahd, links);
-       if (list_ahd != NULL)
-               TAILQ_INSERT_BEFORE(list_ahd, ahd, links);
-       else
-               TAILQ_INSERT_TAIL(&ahd_tailq, ahd, links);
-       ahd->init_level++;
-}
-
-/*
- * Verify that the passed in softc pointer is for a
- * controller that is still configured.
- */
-struct ahd_softc *
-ahd_find_softc(struct ahd_softc *ahd)
-{
-       struct ahd_softc *list_ahd;
-
-       TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
-               if (list_ahd == ahd)
-                       return (ahd);
-       }
-       return (NULL);
-}
-
 void
 ahd_set_unit(struct ahd_softc *ahd, int unit)
 {
@@ -7902,18 +7832,10 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
 static void
 ahd_reset_poll(void *arg)
 {
-       struct  ahd_softc *ahd;
+       struct  ahd_softc *ahd = arg;
        u_int   scsiseq1;
-       u_long  l;
        u_long  s;
        
-       ahd_list_lock(&l);
-       ahd = ahd_find_softc((struct ahd_softc *)arg);
-       if (ahd == NULL) {
-               printf("ahd_reset_poll: Instance %p no longer exists\n", arg);
-               ahd_list_unlock(&l);
-               return;
-       }
        ahd_lock(ahd, &s);
        ahd_pause(ahd);
        ahd_update_modes(ahd);
@@ -7924,7 +7846,6 @@ ahd_reset_poll(void *arg)
                                ahd_reset_poll, ahd);
                ahd_unpause(ahd);
                ahd_unlock(ahd, &s);
-               ahd_list_unlock(&l);
                return;
        }
 
@@ -7936,25 +7857,16 @@ ahd_reset_poll(void *arg)
        ahd->flags &= ~AHD_RESET_POLL_ACTIVE;
        ahd_unlock(ahd, &s);
        ahd_release_simq(ahd);
-       ahd_list_unlock(&l);
 }
 
 /**************************** Statistics Processing ***************************/
 static void
 ahd_stat_timer(void *arg)
 {
-       struct  ahd_softc *ahd;
-       u_long  l;
+       struct  ahd_softc *ahd = arg;
        u_long  s;
        int     enint_coal;
        
-       ahd_list_lock(&l);
-       ahd = ahd_find_softc((struct ahd_softc *)arg);
-       if (ahd == NULL) {
-               printf("ahd_stat_timer: Instance %p no longer exists\n", arg);
-               ahd_list_unlock(&l);
-               return;
-       }
        ahd_lock(ahd, &s);
 
        enint_coal = ahd->hs_mailbox & ENINT_COALESCE;
@@ -7981,7 +7893,6 @@ ahd_stat_timer(void *arg)
        ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
                        ahd_stat_timer, ahd);
        ahd_unlock(ahd, &s);
-       ahd_list_unlock(&l);
 }
 
 /****************************** Status Processing *****************************/
@@ -8745,16 +8656,6 @@ sized:
        return (last_probe);
 }
 
-void
-ahd_dump_all_cards_state(void)
-{
-       struct ahd_softc *list_ahd;
-
-       TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
-               ahd_dump_card_state(list_ahd);
-       }
-}
-
 int
 ahd_print_register(ahd_reg_parse_entry_t *table, u_int num_entries,
                   const char *name, u_int address, u_int value,
@@ -9039,7 +8940,6 @@ ahd_dump_card_state(struct ahd_softc *ahd)
                ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF);
        }
        printf("\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
-       ahd_platform_dump_card_state(ahd);
        ahd_restore_modes(ahd, saved_modes);
        if (paused == 0)
                ahd_unpause(ahd);
index 329cb233133958ceddc71107daddda65ec57d3ed..3feb739cd5548d4d535a5f47a75568d5ea8457c8 100644 (file)
@@ -46,6 +46,8 @@
 #include "aic79xx_inline.h"
 #include <scsi/scsicam.h>
 
+static struct scsi_transport_template *ahd_linux_transport_template = NULL;
+
 /*
  * Include aiclib.c as part of our
  * "module dependencies are hard" work around.
 #include "aiclib.c"
 
 #include <linux/init.h>                /* __setup */
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-#include "sd.h"                        /* For geometry detection */
-#endif
-
 #include <linux/mm.h>          /* For fetching system memory size */
+#include <linux/blkdev.h>              /* For block_size() */
 #include <linux/delay.h>       /* For ssleep/msleep */
 
-/*
- * Lock protecting manipulation of the ahd softc list.
- */
-spinlock_t ahd_list_spinlock;
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-/* For dynamic sglist size calculation. */
-u_int ahd_linux_nseg;
-#endif
-
 /*
  * Bucket size for counting good commands in between bad ones.
  */
@@ -187,71 +175,6 @@ static adapter_tag_info_t aic79xx_tag_info[] =
        {AIC79XX_CONFIGED_TAG_COMMANDS}
 };
 
-/*
- * By default, read streaming is disabled.  In theory,
- * read streaming should enhance performance, but early
- * U320 drive firmware actually performs slower with
- * read streaming enabled.
- */
-#ifdef CONFIG_AIC79XX_ENABLE_RD_STRM
-#define AIC79XX_CONFIGED_RD_STRM 0xFFFF
-#else
-#define AIC79XX_CONFIGED_RD_STRM 0
-#endif
-
-static uint16_t aic79xx_rd_strm_info[] =
-{
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM,
-       AIC79XX_CONFIGED_RD_STRM
-};
-
-/*
- * DV option:
- *
- * positive value = DV Enabled
- * zero                  = DV Disabled
- * negative value = DV Default for adapter type/seeprom
- */
-#ifdef CONFIG_AIC79XX_DV_SETTING
-#define AIC79XX_CONFIGED_DV CONFIG_AIC79XX_DV_SETTING
-#else
-#define AIC79XX_CONFIGED_DV -1
-#endif
-
-static int8_t aic79xx_dv_settings[] =
-{
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV,
-       AIC79XX_CONFIGED_DV
-};
-
 /*
  * The I/O cell on the chip is very configurable in respect to its analog
  * characteristics.  Set the defaults here; they can be overriden with
@@ -374,13 +297,6 @@ static uint32_t aic79xx_pci_parity = ~0;
  */
 uint32_t aic79xx_allow_memio = ~0;
 
-/*
- * aic79xx_detect() has been run, so register all device arrivals
- * immediately with the system rather than deferring to the sorted
- * attachment performed by aic79xx_detect().
- */
-int aic79xx_detect_complete;
-
 /*
  * So that we can set how long each device is given as a selection timeout.
  * The table of values goes like this:
@@ -412,7 +328,7 @@ MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
 MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver");
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_VERSION(AIC79XX_DRIVER_VERSION);
-module_param(aic79xx, charp, 0);
+module_param(aic79xx, charp, 0444);
 MODULE_PARM_DESC(aic79xx,
 "period delimited, options string.\n"
 "      verbose                 Enable verbose/diagnostic logging\n"
@@ -427,8 +343,6 @@ MODULE_PARM_DESC(aic79xx,
 "      reverse_scan            Sort PCI devices highest Bus/Slot to lowest\n"
 "      tag_info:<tag_str>      Set per-target tag depth\n"
 "      global_tag_depth:<int>  Global tag depth for all targets on all buses\n"
-"      rd_strm:<rd_strm_masks> Set per-target read streaming setting.\n"
-"      dv:<dv_settings>        Set per-controller Domain Validation Setting.\n"
 "      slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
 "      precomp:<pcomp_list>    Set the signal precompensation (0-7).\n"
 "      amplitude:<int>         Set the signal amplitude (0-7).\n"
@@ -441,249 +355,37 @@ MODULE_PARM_DESC(aic79xx,
 "              Shorten the selection timeout to 128ms\n"
 "\n"
 "      options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n"
-"\n"
-"      Sample /etc/modprobe.conf line:\n"
-"              Change Read Streaming for Controller's 2 and 3\n"
-"\n"
-"      options aic79xx 'aic79xx=rd_strm:{..0xFFF0.0xC0F0}'");
+"\n");
 
 static void ahd_linux_handle_scsi_status(struct ahd_softc *,
-                                        struct ahd_linux_device *,
+                                        struct scsi_device *,
                                         struct scb *);
 static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
-                                        Scsi_Cmnd *cmd);
-static void ahd_linux_filter_inquiry(struct ahd_softc *ahd,
-                                    struct ahd_devinfo *devinfo);
-static void ahd_linux_dev_timed_unfreeze(u_long arg);
+                                        struct scsi_cmnd *cmd);
 static void ahd_linux_sem_timeout(u_long arg);
+static int  ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag);
 static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);
-static void ahd_linux_size_nseg(void);
-static void ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd);
-static void ahd_linux_start_dv(struct ahd_softc *ahd);
-static void ahd_linux_dv_timeout(struct scsi_cmnd *cmd);
-static int  ahd_linux_dv_thread(void *data);
-static void ahd_linux_kill_dv_thread(struct ahd_softc *ahd);
-static void ahd_linux_dv_target(struct ahd_softc *ahd, u_int target);
-static void ahd_linux_dv_transition(struct ahd_softc *ahd,
-                                   struct scsi_cmnd *cmd,
-                                   struct ahd_devinfo *devinfo,
-                                   struct ahd_linux_target *targ);
-static void ahd_linux_dv_fill_cmd(struct ahd_softc *ahd,
-                                 struct scsi_cmnd *cmd,
-                                 struct ahd_devinfo *devinfo);
-static void ahd_linux_dv_inq(struct ahd_softc *ahd,
-                            struct scsi_cmnd *cmd,
-                            struct ahd_devinfo *devinfo,
-                            struct ahd_linux_target *targ,
-                            u_int request_length);
-static void ahd_linux_dv_tur(struct ahd_softc *ahd,
-                            struct scsi_cmnd *cmd,
-                            struct ahd_devinfo *devinfo);
-static void ahd_linux_dv_rebd(struct ahd_softc *ahd,
-                             struct scsi_cmnd *cmd,
-                             struct ahd_devinfo *devinfo,
-                             struct ahd_linux_target *targ);
-static void ahd_linux_dv_web(struct ahd_softc *ahd,
-                            struct scsi_cmnd *cmd,
-                            struct ahd_devinfo *devinfo,
-                            struct ahd_linux_target *targ);
-static void ahd_linux_dv_reb(struct ahd_softc *ahd,
-                            struct scsi_cmnd *cmd,
-                            struct ahd_devinfo *devinfo,
-                            struct ahd_linux_target *targ);
-static void ahd_linux_dv_su(struct ahd_softc *ahd,
-                           struct scsi_cmnd *cmd,
-                           struct ahd_devinfo *devinfo,
-                           struct ahd_linux_target *targ);
-static int ahd_linux_fallback(struct ahd_softc *ahd,
-                             struct ahd_devinfo *devinfo);
-static __inline int ahd_linux_dv_fallback(struct ahd_softc *ahd,
-                                         struct ahd_devinfo *devinfo);
-static void ahd_linux_dv_complete(Scsi_Cmnd *cmd);
-static void ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ);
 static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
                                     struct ahd_devinfo *devinfo);
-static u_int ahd_linux_user_dv_setting(struct ahd_softc *ahd);
-static void ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd);
-static void ahd_linux_device_queue_depth(struct ahd_softc *ahd,
-                                        struct ahd_linux_device *dev);
-static struct ahd_linux_target*        ahd_linux_alloc_target(struct ahd_softc*,
-                                                      u_int, u_int);
-static void                    ahd_linux_free_target(struct ahd_softc*,
-                                                     struct ahd_linux_target*);
-static struct ahd_linux_device*        ahd_linux_alloc_device(struct ahd_softc*,
-                                                      struct ahd_linux_target*,
-                                                      u_int);
-static void                    ahd_linux_free_device(struct ahd_softc*,
-                                                     struct ahd_linux_device*);
-static void ahd_linux_run_device_queue(struct ahd_softc*,
-                                      struct ahd_linux_device*);
+static void ahd_linux_device_queue_depth(struct scsi_device *);
+static int ahd_linux_run_command(struct ahd_softc*,
+                                struct ahd_linux_device *,
+                                struct scsi_cmnd *);
 static void ahd_linux_setup_tag_info_global(char *p);
 static aic_option_callback_t ahd_linux_setup_tag_info;
-static aic_option_callback_t ahd_linux_setup_rd_strm_info;
-static aic_option_callback_t ahd_linux_setup_dv;
 static aic_option_callback_t ahd_linux_setup_iocell_info;
-static int ahd_linux_next_unit(void);
-static void ahd_runq_tasklet(unsigned long data);
-static int aic79xx_setup(char *c);
-
-/****************************** Inlines ***************************************/
-static __inline void ahd_schedule_completeq(struct ahd_softc *ahd);
-static __inline void ahd_schedule_runq(struct ahd_softc *ahd);
-static __inline void ahd_setup_runq_tasklet(struct ahd_softc *ahd);
-static __inline void ahd_teardown_runq_tasklet(struct ahd_softc *ahd);
-static __inline struct ahd_linux_device*
-                    ahd_linux_get_device(struct ahd_softc *ahd, u_int channel,
-                                         u_int target, u_int lun, int alloc);
-static struct ahd_cmd *ahd_linux_run_complete_queue(struct ahd_softc *ahd);
-static __inline void ahd_linux_check_device_queue(struct ahd_softc *ahd,
-                                                 struct ahd_linux_device *dev);
-static __inline struct ahd_linux_device *
-                    ahd_linux_next_device_to_run(struct ahd_softc *ahd);
-static __inline void ahd_linux_run_device_queues(struct ahd_softc *ahd);
-static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
-
-static __inline void
-ahd_schedule_completeq(struct ahd_softc *ahd)
-{
-       if ((ahd->platform_data->flags & AHD_RUN_CMPLT_Q_TIMER) == 0) {
-               ahd->platform_data->flags |= AHD_RUN_CMPLT_Q_TIMER;
-               ahd->platform_data->completeq_timer.expires = jiffies;
-               add_timer(&ahd->platform_data->completeq_timer);
-       }
-}
-
-/*
- * Must be called with our lock held.
- */
-static __inline void
-ahd_schedule_runq(struct ahd_softc *ahd)
-{
-       tasklet_schedule(&ahd->platform_data->runq_tasklet);
-}
-
-static __inline
-void ahd_setup_runq_tasklet(struct ahd_softc *ahd)
-{
-       tasklet_init(&ahd->platform_data->runq_tasklet, ahd_runq_tasklet,
-                    (unsigned long)ahd);
-}
-
-static __inline void
-ahd_teardown_runq_tasklet(struct ahd_softc *ahd)
-{
-       tasklet_kill(&ahd->platform_data->runq_tasklet);
-}
-
-static __inline struct ahd_linux_device*
-ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target,
-                    u_int lun, int alloc)
-{
-       struct ahd_linux_target *targ;
-       struct ahd_linux_device *dev;
-       u_int target_offset;
-
-       target_offset = target;
-       if (channel != 0)
-               target_offset += 8;
-       targ = ahd->platform_data->targets[target_offset];
-       if (targ == NULL) {
-               if (alloc != 0) {
-                       targ = ahd_linux_alloc_target(ahd, channel, target);
-                       if (targ == NULL)
-                               return (NULL);
-               } else
-                       return (NULL);
-       }
-       dev = targ->devices[lun];
-       if (dev == NULL && alloc != 0)
-               dev = ahd_linux_alloc_device(ahd, targ, lun);
-       return (dev);
-}
-
-#define AHD_LINUX_MAX_RETURNED_ERRORS 4
-static struct ahd_cmd *
-ahd_linux_run_complete_queue(struct ahd_softc *ahd)
-{      
-       struct  ahd_cmd *acmd;
-       u_long  done_flags;
-       int     with_errors;
+static int  aic79xx_setup(char *c);
 
-       with_errors = 0;
-       ahd_done_lock(ahd, &done_flags);
-       while ((acmd = TAILQ_FIRST(&ahd->platform_data->completeq)) != NULL) {
-               Scsi_Cmnd *cmd;
+static int ahd_linux_unit;
 
-               if (with_errors > AHD_LINUX_MAX_RETURNED_ERRORS) {
-                       /*
-                        * Linux uses stack recursion to requeue
-                        * commands that need to be retried.  Avoid
-                        * blowing out the stack by "spoon feeding"
-                        * commands that completed with error back
-                        * the operating system in case they are going
-                        * to be retried. "ick"
-                        */
-                       ahd_schedule_completeq(ahd);
-                       break;
-               }
-               TAILQ_REMOVE(&ahd->platform_data->completeq,
-                            acmd, acmd_links.tqe);
-               cmd = &acmd_scsi_cmd(acmd);
-               cmd->host_scribble = NULL;
-               if (ahd_cmd_get_transaction_status(cmd) != DID_OK
-                || (cmd->result & 0xFF) != SCSI_STATUS_OK)
-                       with_errors++;
-
-               cmd->scsi_done(cmd);
-       }
-       ahd_done_unlock(ahd, &done_flags);
-       return (acmd);
-}
-
-static __inline void
-ahd_linux_check_device_queue(struct ahd_softc *ahd,
-                            struct ahd_linux_device *dev)
-{
-       if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) != 0
-        && dev->active == 0) {
-               dev->flags &= ~AHD_DEV_FREEZE_TIL_EMPTY;
-               dev->qfrozen--;
-       }
-
-       if (TAILQ_FIRST(&dev->busyq) == NULL
-        || dev->openings == 0 || dev->qfrozen != 0)
-               return;
-
-       ahd_linux_run_device_queue(ahd, dev);
-}
-
-static __inline struct ahd_linux_device *
-ahd_linux_next_device_to_run(struct ahd_softc *ahd)
-{
-       
-       if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0
-        || (ahd->platform_data->qfrozen != 0
-         && AHD_DV_SIMQ_FROZEN(ahd) == 0))
-               return (NULL);
-       return (TAILQ_FIRST(&ahd->platform_data->device_runq));
-}
-
-static __inline void
-ahd_linux_run_device_queues(struct ahd_softc *ahd)
-{
-       struct ahd_linux_device *dev;
 
-       while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
-               TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
-               dev->flags &= ~AHD_DEV_ON_RUN_LIST;
-               ahd_linux_check_device_queue(ahd, dev);
-       }
-}
+/****************************** Inlines ***************************************/
+static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
 
 static __inline void
 ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
 {
-       Scsi_Cmnd *cmd;
+       struct scsi_cmnd *cmd;
        int direction;
 
        cmd = scb->io_ctx;
@@ -705,197 +407,6 @@ ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
 #define BUILD_SCSIID(ahd, cmd)                                         \
        ((((cmd)->device->id << TID_SHIFT) & TID) | (ahd)->our_id)
 
-/************************  Host template entry points *************************/
-static int        ahd_linux_detect(Scsi_Host_Template *);
-static const char *ahd_linux_info(struct Scsi_Host *);
-static int        ahd_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-static int        ahd_linux_slave_alloc(Scsi_Device *);
-static int        ahd_linux_slave_configure(Scsi_Device *);
-static void       ahd_linux_slave_destroy(Scsi_Device *);
-#if defined(__i386__)
-static int        ahd_linux_biosparam(struct scsi_device*,
-                                      struct block_device*, sector_t, int[]);
-#endif
-#else
-static int        ahd_linux_release(struct Scsi_Host *);
-static void       ahd_linux_select_queue_depth(struct Scsi_Host *host,
-                                               Scsi_Device *scsi_devs);
-#if defined(__i386__)
-static int        ahd_linux_biosparam(Disk *, kdev_t, int[]);
-#endif
-#endif
-static int        ahd_linux_bus_reset(Scsi_Cmnd *);
-static int        ahd_linux_dev_reset(Scsi_Cmnd *);
-static int        ahd_linux_abort(Scsi_Cmnd *);
-
-/*
- * Calculate a safe value for AHD_NSEG (as expressed through ahd_linux_nseg).
- *
- * In pre-2.5.X...
- * The midlayer allocates an S/G array dynamically when a command is issued
- * using SCSI malloc.  This array, which is in an OS dependent format that
- * must later be copied to our private S/G list, is sized to house just the
- * number of segments needed for the current transfer.  Since the code that
- * sizes the SCSI malloc pool does not take into consideration fragmentation
- * of the pool, executing transactions numbering just a fraction of our
- * concurrent transaction limit with SG list lengths aproaching AHC_NSEG will
- * quickly depleat the SCSI malloc pool of usable space.  Unfortunately, the
- * mid-layer does not properly handle this scsi malloc failures for the S/G
- * array and the result can be a lockup of the I/O subsystem.  We try to size
- * our S/G list so that it satisfies our drivers allocation requirements in
- * addition to avoiding fragmentation of the SCSI malloc pool.
- */
-static void
-ahd_linux_size_nseg(void)
-{
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-       u_int cur_size;
-       u_int best_size;
-
-       /*
-        * The SCSI allocator rounds to the nearest 512 bytes
-        * an cannot allocate across a page boundary.  Our algorithm
-        * is to start at 1K of scsi malloc space per-command and
-        * loop through all factors of the PAGE_SIZE and pick the best.
-        */
-       best_size = 0;
-       for (cur_size = 1024; cur_size <= PAGE_SIZE; cur_size *= 2) {
-               u_int nseg;
-
-               nseg = cur_size / sizeof(struct scatterlist);
-               if (nseg < AHD_LINUX_MIN_NSEG)
-                       continue;
-
-               if (best_size == 0) {
-                       best_size = cur_size;
-                       ahd_linux_nseg = nseg;
-               } else {
-                       u_int best_rem;
-                       u_int cur_rem;
-
-                       /*
-                        * Compare the traits of the current "best_size"
-                        * with the current size to determine if the
-                        * current size is a better size.
-                        */
-                       best_rem = best_size % sizeof(struct scatterlist);
-                       cur_rem = cur_size % sizeof(struct scatterlist);
-                       if (cur_rem < best_rem) {
-                               best_size = cur_size;
-                               ahd_linux_nseg = nseg;
-                       }
-               }
-       }
-#endif
-}
-
-/*
- * Try to detect an Adaptec 79XX controller.
- */
-static int
-ahd_linux_detect(Scsi_Host_Template *template)
-{
-       struct  ahd_softc *ahd;
-       int     found;
-       int     error = 0;
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-       /*
-        * It is a bug that the upper layer takes
-        * this lock just prior to calling us.
-        */
-       spin_unlock_irq(&io_request_lock);
-#endif
-
-       /*
-        * Sanity checking of Linux SCSI data structures so
-        * that some of our hacks^H^H^H^H^Hassumptions aren't
-        * violated.
-        */
-       if (offsetof(struct ahd_cmd_internal, end)
-         > offsetof(struct scsi_cmnd, host_scribble)) {
-               printf("ahd_linux_detect: SCSI data structures changed.\n");
-               printf("ahd_linux_detect: Unable to attach\n");
-               return (0);
-       }
-       /*
-        * Determine an appropriate size for our Scatter Gatther lists.
-        */
-       ahd_linux_size_nseg();
-#ifdef MODULE
-       /*
-        * If we've been passed any parameters, process them now.
-        */
-       if (aic79xx)
-               aic79xx_setup(aic79xx);
-#endif
-
-       template->proc_name = "aic79xx";
-
-       /*
-        * Initialize our softc list lock prior to
-        * probing for any adapters.
-        */
-       ahd_list_lockinit();
-
-#ifdef CONFIG_PCI
-       error = ahd_linux_pci_init();
-       if (error)
-               return error;
-#endif
-
-       /*
-        * Register with the SCSI layer all
-        * controllers we've found.
-        */
-       found = 0;
-       TAILQ_FOREACH(ahd, &ahd_tailq, links) {
-
-               if (ahd_linux_register_host(ahd, template) == 0)
-                       found++;
-       }
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-       spin_lock_irq(&io_request_lock);
-#endif
-       aic79xx_detect_complete++;
-       return 0;
-}
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-/*
- * Free the passed in Scsi_Host memory structures prior to unloading the
- * module.
- */
-static int
-ahd_linux_release(struct Scsi_Host * host)
-{
-       struct ahd_softc *ahd;
-       u_long l;
-
-       ahd_list_lock(&l);
-       if (host != NULL) {
-
-               /*
-                * We should be able to just perform
-                * the free directly, but check our
-                * list for extra sanity.
-                */
-               ahd = ahd_find_softc(*(struct ahd_softc **)host->hostdata);
-               if (ahd != NULL) {
-                       u_long s;
-
-                       ahd_lock(ahd, &s);
-                       ahd_intr_enable(ahd, FALSE);
-                       ahd_unlock(ahd, &s);
-                       ahd_free(ahd);
-               }
-       }
-       ahd_list_unlock(&l);
-       return (0);
-}
-#endif
-
 /*
  * Return a string describing the driver.
  */
@@ -928,220 +439,177 @@ ahd_linux_info(struct Scsi_Host *host)
  * Queue an SCB to the controller.
  */
 static int
-ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
+ahd_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
 {
        struct   ahd_softc *ahd;
-       struct   ahd_linux_device *dev;
-       u_long   flags;
+       struct   ahd_linux_device *dev = scsi_transport_device_data(cmd->device);
 
        ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
 
-       /*
-        * Save the callback on completion function.
-        */
-       cmd->scsi_done = scsi_done;
-
-       ahd_midlayer_entrypoint_lock(ahd, &flags);
-
        /*
         * Close the race of a command that was in the process of
         * being queued to us just as our simq was frozen.  Let
         * DV commands through so long as we are only frozen to
         * perform DV.
         */
-       if (ahd->platform_data->qfrozen != 0
-        && AHD_DV_CMD(cmd) == 0) {
-
-               ahd_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
-               ahd_linux_queue_cmd_complete(ahd, cmd);
-               ahd_schedule_completeq(ahd);
-               ahd_midlayer_entrypoint_unlock(ahd, &flags);
-               return (0);
-       }
-       dev = ahd_linux_get_device(ahd, cmd->device->channel,
-                                  cmd->device->id, cmd->device->lun,
-                                  /*alloc*/TRUE);
-       if (dev == NULL) {
-               ahd_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
-               ahd_linux_queue_cmd_complete(ahd, cmd);
-               ahd_schedule_completeq(ahd);
-               ahd_midlayer_entrypoint_unlock(ahd, &flags);
-               printf("%s: aic79xx_linux_queue - Unable to allocate device!\n",
-                      ahd_name(ahd));
-               return (0);
+       if (ahd->platform_data->qfrozen != 0) {
+               printf("%s: queue frozen\n", ahd_name(ahd));
+
+               return SCSI_MLQUEUE_HOST_BUSY;
        }
-       if (cmd->cmd_len > MAX_CDB_LEN)
-               return (-EINVAL);
+
+       /*
+        * Save the callback on completion function.
+        */
+       cmd->scsi_done = scsi_done;
+
        cmd->result = CAM_REQ_INPROG << 16;
-       TAILQ_INSERT_TAIL(&dev->busyq, (struct ahd_cmd *)cmd, acmd_links.tqe);
-       if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) {
-               TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links);
-               dev->flags |= AHD_DEV_ON_RUN_LIST;
-               ahd_linux_run_device_queues(ahd);
-       }
-       ahd_midlayer_entrypoint_unlock(ahd, &flags);
-       return (0);
+
+       return ahd_linux_run_command(ahd, dev, cmd);
 }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-static int
-ahd_linux_slave_alloc(Scsi_Device *device)
+static inline struct scsi_target **
+ahd_linux_target_in_softc(struct scsi_target *starget)
 {
-       struct  ahd_softc *ahd;
+       struct  ahd_softc *ahd =
+               *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
+       unsigned int target_offset;
 
-       ahd = *((struct ahd_softc **)device->host->hostdata);
-       if (bootverbose)
-               printf("%s: Slave Alloc %d\n", ahd_name(ahd), device->id);
-       return (0);
+       target_offset = starget->id;
+       if (starget->channel != 0)
+               target_offset += 8;
+
+       return &ahd->platform_data->starget[target_offset];
 }
 
 static int
-ahd_linux_slave_configure(Scsi_Device *device)
+ahd_linux_target_alloc(struct scsi_target *starget)
 {
-       struct  ahd_softc *ahd;
-       struct  ahd_linux_device *dev;
-       u_long  flags;
+       struct  ahd_softc *ahd =
+               *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
+       unsigned long flags;
+       struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
+       struct ahd_linux_target *targ = scsi_transport_target_data(starget);
+       struct ahd_devinfo devinfo;
+       struct ahd_initiator_tinfo *tinfo;
+       struct ahd_tmode_tstate *tstate;
+       char channel = starget->channel + 'A';
 
-       ahd = *((struct ahd_softc **)device->host->hostdata);
-       if (bootverbose)
-               printf("%s: Slave Configure %d\n", ahd_name(ahd), device->id);
-       ahd_midlayer_entrypoint_lock(ahd, &flags);
-       /*
-        * Since Linux has attached to the device, configure
-        * it so we don't free and allocate the device
-        * structure on every command.
-        */
-       dev = ahd_linux_get_device(ahd, device->channel,
-                                  device->id, device->lun,
-                                  /*alloc*/TRUE);
-       if (dev != NULL) {
-               dev->flags &= ~AHD_DEV_UNCONFIGURED;
-               dev->flags |= AHD_DEV_SLAVE_CONFIGURED;
-               dev->scsi_device = device;
-               ahd_linux_device_queue_depth(ahd, dev);
-       }
-       ahd_midlayer_entrypoint_unlock(ahd, &flags);
-       return (0);
+       ahd_lock(ahd, &flags);
+
+       BUG_ON(*ahd_targp != NULL);
+
+       *ahd_targp = starget;
+       memset(targ, 0, sizeof(*targ));
+
+       tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
+                                   starget->id, &tstate);
+       ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id,
+                           CAM_LUN_WILDCARD, channel,
+                           ROLE_INITIATOR);
+       spi_min_period(starget) = AHD_SYNCRATE_MAX; /* We can do U320 */
+       if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0)
+               spi_max_offset(starget) = MAX_OFFSET_PACED_BUG;
+       else
+               spi_max_offset(starget) = MAX_OFFSET_PACED;
+       spi_max_width(starget) = ahd->features & AHD_WIDE;
+
+       ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
+                        AHD_TRANS_GOAL, /*paused*/FALSE);
+       ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+                     AHD_TRANS_GOAL, /*paused*/FALSE);
+       ahd_unlock(ahd, &flags);
+
+       return 0;
 }
 
 static void
-ahd_linux_slave_destroy(Scsi_Device *device)
+ahd_linux_target_destroy(struct scsi_target *starget)
 {
-       struct  ahd_softc *ahd;
-       struct  ahd_linux_device *dev;
-       u_long  flags;
+       struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
+
+       *ahd_targp = NULL;
+}
+
+static int
+ahd_linux_slave_alloc(struct scsi_device *sdev)
+{
+       struct  ahd_softc *ahd =
+               *((struct ahd_softc **)sdev->host->hostdata);
+       struct scsi_target *starget = sdev->sdev_target;
+       struct ahd_linux_target *targ = scsi_transport_target_data(starget);
+       struct ahd_linux_device *dev;
 
-       ahd = *((struct ahd_softc **)device->host->hostdata);
        if (bootverbose)
-               printf("%s: Slave Destroy %d\n", ahd_name(ahd), device->id);
-       ahd_midlayer_entrypoint_lock(ahd, &flags);
-       dev = ahd_linux_get_device(ahd, device->channel,
-                                  device->id, device->lun,
-                                          /*alloc*/FALSE);
+               printf("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
+
+       BUG_ON(targ->sdev[sdev->lun] != NULL);
+
+       dev = scsi_transport_device_data(sdev);
+       memset(dev, 0, sizeof(*dev));
 
        /*
-        * Filter out "silly" deletions of real devices by only
-        * deleting devices that have had slave_configure()
-        * called on them.  All other devices that have not
-        * been configured will automatically be deleted by
-        * the refcounting process.
+        * We start out life using untagged
+        * transactions of which we allow one.
         */
-       if (dev != NULL
-        && (dev->flags & AHD_DEV_SLAVE_CONFIGURED) != 0) {
-               dev->flags |= AHD_DEV_UNCONFIGURED;
-               if (TAILQ_EMPTY(&dev->busyq)
-                && dev->active == 0
-                && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0)
-                       ahd_linux_free_device(ahd, dev);
-       }
-       ahd_midlayer_entrypoint_unlock(ahd, &flags);
+       dev->openings = 1;
+
+       /*
+        * Set maxtags to 0.  This will be changed if we
+        * later determine that we are dealing with
+        * a tagged queuing capable device.
+        */
+       dev->maxtags = 0;
+       
+       targ->sdev[sdev->lun] = sdev;
+
+       return (0);
 }
-#else
-/*
- * Sets the queue depth for each SCSI device hanging
- * off the input host adapter.
- */
-static void
-ahd_linux_select_queue_depth(struct Scsi_Host * host,
-                            Scsi_Device * scsi_devs)
+
+static int
+ahd_linux_slave_configure(struct scsi_device *sdev)
 {
-       Scsi_Device *device;
-       Scsi_Device *ldev;
        struct  ahd_softc *ahd;
-       u_long  flags;
-
-       ahd = *((struct ahd_softc **)host->hostdata);
-       ahd_lock(ahd, &flags);
-       for (device = scsi_devs; device != NULL; device = device->next) {
 
-               /*
-                * Watch out for duplicate devices.  This works around
-                * some quirks in how the SCSI scanning code does its
-                * device management.
-                */
-               for (ldev = scsi_devs; ldev != device; ldev = ldev->next) {
-                       if (ldev->host == device->host
-                        && ldev->channel == device->channel
-                        && ldev->id == device->id
-                        && ldev->lun == device->lun)
-                               break;
-               }
-               /* Skip duplicate. */
-               if (ldev != device)
-                       continue;
+       ahd = *((struct ahd_softc **)sdev->host->hostdata);
+       if (bootverbose)
+               printf("%s: Slave Configure %d\n", ahd_name(ahd), sdev->id);
 
-               if (device->host == host) {
-                       struct   ahd_linux_device *dev;
+       ahd_linux_device_queue_depth(sdev);
+
+       /* Initial Domain Validation */
+       if (!spi_initial_dv(sdev->sdev_target))
+               spi_dv_device(sdev);
+
+       return 0;
+}
+
+static void
+ahd_linux_slave_destroy(struct scsi_device *sdev)
+{
+       struct  ahd_softc *ahd;
+       struct  ahd_linux_device *dev = scsi_transport_device_data(sdev);
+       struct  ahd_linux_target *targ = scsi_transport_target_data(sdev->sdev_target);
+
+       ahd = *((struct ahd_softc **)sdev->host->hostdata);
+       if (bootverbose)
+               printf("%s: Slave Destroy %d\n", ahd_name(ahd), sdev->id);
+
+       BUG_ON(dev->active);
+
+       targ->sdev[sdev->lun] = NULL;
 
-                       /*
-                        * Since Linux has attached to the device, configure
-                        * it so we don't free and allocate the device
-                        * structure on every command.
-                        */
-                       dev = ahd_linux_get_device(ahd, device->channel,
-                                                  device->id, device->lun,
-                                                  /*alloc*/TRUE);
-                       if (dev != NULL) {
-                               dev->flags &= ~AHD_DEV_UNCONFIGURED;
-                               dev->scsi_device = device;
-                               ahd_linux_device_queue_depth(ahd, dev);
-                               device->queue_depth = dev->openings
-                                                   + dev->active;
-                               if ((dev->flags & (AHD_DEV_Q_BASIC
-                                               | AHD_DEV_Q_TAGGED)) == 0) {
-                                       /*
-                                        * We allow the OS to queue 2 untagged
-                                        * transactions to us at any time even
-                                        * though we can only execute them
-                                        * serially on the controller/device.
-                                        * This should remove some latency.
-                                        */
-                                       device->queue_depth = 2;
-                               }
-                       }
-               }
-       }
-       ahd_unlock(ahd, &flags);
 }
-#endif
 
 #if defined(__i386__)
 /*
  * Return the disk geometry for the given SCSI device.
  */
 static int
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
 ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
                    sector_t capacity, int geom[])
 {
        uint8_t *bh;
-#else
-ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
-{
-       struct  scsi_device *sdev = disk->device;
-       u_long  capacity = disk->capacity;
-       struct  buffer_head *bh;
-#endif
        int      heads;
        int      sectors;
        int      cylinders;
@@ -1151,22 +619,11 @@ ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
 
        ahd = *((struct ahd_softc **)sdev->host->hostdata);
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
        bh = scsi_bios_ptable(bdev);
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
-       bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, block_size(dev));
-#else
-       bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, 1024);
-#endif
-
        if (bh) {
                ret = scsi_partsize(bh, capacity,
                                    &geom[2], &geom[0], &geom[1]);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
                kfree(bh);
-#else
-               brelse(bh);
-#endif
                if (ret != -1)
                        return (ret);
        }
@@ -1194,2581 +651,647 @@ ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
  * Abort the current SCSI command(s).
  */
 static int
-ahd_linux_abort(Scsi_Cmnd *cmd)
+ahd_linux_abort(struct scsi_cmnd *cmd)
+{
+       int error;
+
+       error = ahd_linux_queue_recovery_cmd(cmd, SCB_ABORT);
+       if (error != 0)
+               printf("aic79xx_abort returns 0x%x\n", error);
+       return error;
+}
+
+/*
+ * Attempt to send a target reset message to the device that timed out.
+ */
+static int
+ahd_linux_dev_reset(struct scsi_cmnd *cmd)
+{
+       int error;
+
+       error = ahd_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
+       if (error != 0)
+               printf("aic79xx_dev_reset returns 0x%x\n", error);
+       return error;
+}
+
+/*
+ * Reset the SCSI bus.
+ */
+static int
+ahd_linux_bus_reset(struct scsi_cmnd *cmd)
 {
        struct ahd_softc *ahd;
-       struct ahd_cmd *acmd;
-       struct ahd_cmd *list_acmd;
-       struct ahd_linux_device *dev;
-       struct scb *pending_scb;
        u_long s;
-       u_int  saved_scbptr;
-       u_int  active_scbptr;
-       u_int  last_phase;
-       u_int  cdb_byte;
-       int    retval;
-       int    was_paused;
-       int    paused;
-       int    wait;
-       int    disconnected;
-       ahd_mode_state saved_modes;
+       int    found;
 
-       pending_scb = NULL;
-       paused = FALSE;
-       wait = FALSE;
        ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
-       acmd = (struct ahd_cmd *)cmd;
-
-       printf("%s:%d:%d:%d: Attempting to abort cmd %p:",
-              ahd_name(ahd), cmd->device->channel, cmd->device->id,
-              cmd->device->lun, cmd);
-       for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
-               printf(" 0x%x", cmd->cmnd[cdb_byte]);
-       printf("\n");
+#ifdef AHD_DEBUG
+       if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
+               printf("%s: Bus reset called for cmd %p\n",
+                      ahd_name(ahd), cmd);
+#endif
+       ahd_lock(ahd, &s);
+       found = ahd_reset_channel(ahd, cmd->device->channel + 'A',
+                                 /*initiate reset*/TRUE);
+       ahd_unlock(ahd, &s);
 
-       /*
-        * In all versions of Linux, we have to work around
-        * a major flaw in how the mid-layer is locked down
-        * if we are to sleep successfully in our error handler
-        * while allowing our interrupt handler to run.  Since
-        * the midlayer acquires either the io_request_lock or
-        * our lock prior to calling us, we must use the
-        * spin_unlock_irq() method for unlocking our lock.
-        * This will force interrupts to be enabled on the
-        * current CPU.  Since the EH thread should not have
-        * been running with CPU interrupts disabled other than
-        * by acquiring either the io_request_lock or our own
-        * lock, this *should* be safe.
-        */
-       ahd_midlayer_entrypoint_lock(ahd, &s);
+       if (bootverbose)
+               printf("%s: SCSI bus reset delivered. "
+                      "%d SCBs aborted.\n", ahd_name(ahd), found);
 
-       /*
-        * First determine if we currently own this command.
-        * Start by searching the device queue.  If not found
-        * there, check the pending_scb list.  If not found
-        * at all, and the system wanted us to just abort the
-        * command, return success.
-        */
-       dev = ahd_linux_get_device(ahd, cmd->device->channel,
-                                  cmd->device->id, cmd->device->lun,
-                                  /*alloc*/FALSE);
+       return (SUCCESS);
+}
 
-       if (dev == NULL) {
-               /*
-                * No target device for this command exists,
-                * so we must not still own the command.
-                */
-               printf("%s:%d:%d:%d: Is not an active device\n",
-                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
-                      cmd->device->lun);
-               retval = SUCCESS;
-               goto no_cmd;
-       }
+struct scsi_host_template aic79xx_driver_template = {
+       .module                 = THIS_MODULE,
+       .name                   = "aic79xx",
+       .proc_name              = "aic79xx",
+       .proc_info              = ahd_linux_proc_info,
+       .info                   = ahd_linux_info,
+       .queuecommand           = ahd_linux_queue,
+       .eh_abort_handler       = ahd_linux_abort,
+       .eh_device_reset_handler = ahd_linux_dev_reset,
+       .eh_bus_reset_handler   = ahd_linux_bus_reset,
+#if defined(__i386__)
+       .bios_param             = ahd_linux_biosparam,
+#endif
+       .can_queue              = AHD_MAX_QUEUE,
+       .this_id                = -1,
+       .cmd_per_lun            = 2,
+       .use_clustering         = ENABLE_CLUSTERING,
+       .slave_alloc            = ahd_linux_slave_alloc,
+       .slave_configure        = ahd_linux_slave_configure,
+       .slave_destroy          = ahd_linux_slave_destroy,
+       .target_alloc           = ahd_linux_target_alloc,
+       .target_destroy         = ahd_linux_target_destroy,
+};
 
-       TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) {
-               if (list_acmd == acmd)
-                       break;
-       }
+/******************************** Bus DMA *************************************/
+int
+ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
+                  bus_size_t alignment, bus_size_t boundary,
+                  dma_addr_t lowaddr, dma_addr_t highaddr,
+                  bus_dma_filter_t *filter, void *filterarg,
+                  bus_size_t maxsize, int nsegments,
+                  bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
+{
+       bus_dma_tag_t dmat;
 
-       if (list_acmd != NULL) {
-               printf("%s:%d:%d:%d: Command found on device queue\n",
-                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
-                      cmd->device->lun);
-               TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
-               cmd->result = DID_ABORT << 16;
-               ahd_linux_queue_cmd_complete(ahd, cmd);
-               retval = SUCCESS;
-               goto done;
-       }
+       dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
+       if (dmat == NULL)
+               return (ENOMEM);
 
        /*
-        * See if we can find a matching cmd in the pending list.
+        * Linux is very simplistic about DMA memory.  For now don't
+        * maintain all specification information.  Once Linux supplies
+        * better facilities for doing these operations, or the
+        * needs of this particular driver change, we might need to do
+        * more here.
         */
-       LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
-               if (pending_scb->io_ctx == cmd)
-                       break;
-       }
+       dmat->alignment = alignment;
+       dmat->boundary = boundary;
+       dmat->maxsize = maxsize;
+       *ret_tag = dmat;
+       return (0);
+}
 
-       if (pending_scb == NULL) {
-               printf("%s:%d:%d:%d: Command not found\n",
-                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
-                      cmd->device->lun);
-               goto no_cmd;
-       }
+void
+ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
+{
+       free(dmat, M_DEVBUF);
+}
 
-       if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
-               /*
-                * We can't queue two recovery actions using the same SCB
-                */
-               retval = FAILED;
-               goto  done;
-       }
+int
+ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
+                int flags, bus_dmamap_t *mapp)
+{
+       *vaddr = pci_alloc_consistent(ahd->dev_softc,
+                                     dmat->maxsize, mapp);
+       if (*vaddr == NULL)
+               return (ENOMEM);
+       return(0);
+}
+
+void
+ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
+               void* vaddr, bus_dmamap_t map)
+{
+       pci_free_consistent(ahd->dev_softc, dmat->maxsize,
+                           vaddr, map);
+}
 
+int
+ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
+               void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
+               void *cb_arg, int flags)
+{
        /*
-        * Ensure that the card doesn't do anything
-        * behind our back.  Also make sure that we
-        * didn't "just" miss an interrupt that would
-        * affect this cmd.
+        * Assume for now that this will only be used during
+        * initialization and not for per-transaction buffer mapping.
         */
-       was_paused = ahd_is_paused(ahd);
-       ahd_pause_and_flushwork(ahd);
-       paused = TRUE;
+       bus_dma_segment_t stack_sg;
 
-       if ((pending_scb->flags & SCB_ACTIVE) == 0) {
-               printf("%s:%d:%d:%d: Command already completed\n",
-                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
-                      cmd->device->lun);
-               goto no_cmd;
-       }
+       stack_sg.ds_addr = map;
+       stack_sg.ds_len = dmat->maxsize;
+       cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
+       return (0);
+}
 
-       printf("%s: At time of recovery, card was %spaused\n",
-              ahd_name(ahd), was_paused ? "" : "not ");
-       ahd_dump_card_state(ahd);
+void
+ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
+{
+}
 
-       disconnected = TRUE;
-       if (ahd_search_qinfifo(ahd, cmd->device->id, cmd->device->channel + 'A',
-                              cmd->device->lun, SCB_GET_TAG(pending_scb),
-                              ROLE_INITIATOR, CAM_REQ_ABORTED,
-                              SEARCH_COMPLETE) > 0) {
-               printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
-                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
-                               cmd->device->lun);
-               retval = SUCCESS;
-               goto done;
-       }
+int
+ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
+{
+       /* Nothing to do */
+       return (0);
+}
 
-       saved_modes = ahd_save_modes(ahd);
-       ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
-       last_phase = ahd_inb(ahd, LASTPHASE);
-       saved_scbptr = ahd_get_scbptr(ahd);
-       active_scbptr = saved_scbptr;
-       if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
-               struct scb *bus_scb;
-
-               bus_scb = ahd_lookup_scb(ahd, active_scbptr);
-               if (bus_scb == pending_scb)
-                       disconnected = FALSE;
-       }
+/********************* Platform Dependent Functions ***************************/
+/*
+ * Compare "left hand" softc with "right hand" softc, returning:
+ * < 0 - lahd has a lower priority than rahd
+ *   0 - Softcs are equal
+ * > 0 - lahd has a higher priority than rahd
+ */
+int
+ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd)
+{
+       int     value;
 
        /*
-        * At this point, pending_scb is the scb associated with the
-        * passed in command.  That command is currently active on the
-        * bus or is in the disconnected state.
+        * Under Linux, cards are ordered as follows:
+        *      1) PCI devices that are marked as the boot controller.
+        *      2) PCI devices with BIOS enabled sorted by bus/slot/func.
+        *      3) All remaining PCI devices sorted by bus/slot/func.
         */
-       if (last_phase != P_BUSFREE
-        && SCB_GET_TAG(pending_scb) == active_scbptr) {
+#if 0
+       value = (lahd->flags & AHD_BOOT_CHANNEL)
+             - (rahd->flags & AHD_BOOT_CHANNEL);
+       if (value != 0)
+               /* Controllers set for boot have a *higher* priority */
+               return (value);
+#endif
 
-               /*
-                * We're active on the bus, so assert ATN
-                * and hope that the target responds.
-                */
-               pending_scb = ahd_lookup_scb(ahd, active_scbptr);
-               pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
-               ahd_outb(ahd, MSG_OUT, HOST_MSG);
-               ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
-               printf("%s:%d:%d:%d: Device is active, asserting ATN\n",
-                      ahd_name(ahd), cmd->device->channel,
-                      cmd->device->id, cmd->device->lun);
-               wait = TRUE;
-       } else if (disconnected) {
+       value = (lahd->flags & AHD_BIOS_ENABLED)
+             - (rahd->flags & AHD_BIOS_ENABLED);
+       if (value != 0)
+               /* Controllers with BIOS enabled have a *higher* priority */
+               return (value);
 
-               /*
-                * Actually re-queue this SCB in an attempt
-                * to select the device before it reconnects.
-                */
-               pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
-               ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
-               pending_scb->hscb->cdb_len = 0;
-               pending_scb->hscb->task_attribute = 0;
-               pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
+       /* Still equal.  Sort by bus/slot/func. */
+       if (aic79xx_reverse_scan != 0)
+               value = ahd_get_pci_bus(lahd->dev_softc)
+                     - ahd_get_pci_bus(rahd->dev_softc);
+       else
+               value = ahd_get_pci_bus(rahd->dev_softc)
+                     - ahd_get_pci_bus(lahd->dev_softc);
+       if (value != 0)
+               return (value);
+       if (aic79xx_reverse_scan != 0)
+               value = ahd_get_pci_slot(lahd->dev_softc)
+                     - ahd_get_pci_slot(rahd->dev_softc);
+       else
+               value = ahd_get_pci_slot(rahd->dev_softc)
+                     - ahd_get_pci_slot(lahd->dev_softc);
+       if (value != 0)
+               return (value);
 
-               if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
-                       /*
-                        * Mark the SCB has having an outstanding
-                        * task management function.  Should the command
-                        * complete normally before the task management
-                        * function can be sent, the host will be notified
-                        * to abort our requeued SCB.
-                        */
-                       ahd_outb(ahd, SCB_TASK_MANAGEMENT,
-                                pending_scb->hscb->task_management);
-               } else {
-                       /*
-                        * If non-packetized, set the MK_MESSAGE control
-                        * bit indicating that we desire to send a message.
-                        * We also set the disconnected flag since there is
-                        * no guarantee that our SCB control byte matches
-                        * the version on the card.  We don't want the
-                        * sequencer to abort the command thinking an
-                        * unsolicited reselection occurred.
-                        */
-                       pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
+       value = rahd->channel - lahd->channel;
+       return (value);
+}
 
-                       /*
-                        * The sequencer will never re-reference the
-                        * in-core SCB.  To make sure we are notified
-                        * during reslection, set the MK_MESSAGE flag in
-                        * the card's copy of the SCB.
-                        */
-                       ahd_outb(ahd, SCB_CONTROL,
-                                ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
-               }
+static void
+ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
+{
 
-               /*
-                * Clear out any entries in the QINFIFO first
-                * so we are the next SCB for this target
-                * to run.
-                */
-               ahd_search_qinfifo(ahd, cmd->device->id,
-                                  cmd->device->channel + 'A', cmd->device->lun,
-                                  SCB_LIST_NULL, ROLE_INITIATOR,
-                                  CAM_REQUEUE_REQ, SEARCH_COMPLETE);
-               ahd_qinfifo_requeue_tail(ahd, pending_scb);
-               ahd_set_scbptr(ahd, saved_scbptr);
-               ahd_print_path(ahd, pending_scb);
-               printf("Device is disconnected, re-queuing SCB\n");
-               wait = TRUE;
-       } else {
-               printf("%s:%d:%d:%d: Unable to deliver message\n",
-                      ahd_name(ahd), cmd->device->channel,
-                      cmd->device->id, cmd->device->lun);
-               retval = FAILED;
-               goto done;
+       if ((instance >= 0)
+        && (instance < NUM_ELEMENTS(aic79xx_iocell_info))) {
+               uint8_t *iocell_info;
+
+               iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
+               iocell_info[index] = value & 0xFFFF;
+               if (bootverbose)
+                       printf("iocell[%d:%ld] = %d\n", instance, index, value);
        }
+}
 
-no_cmd:
-       /*
-        * Our assumption is that if we don't have the command, no
-        * recovery action was required, so we return success.  Again,
-        * the semantics of the mid-layer recovery engine are not
-        * well defined, so this may change in time.
-        */
-       retval = SUCCESS;
-done:
-       if (paused)
-               ahd_unpause(ahd);
-       if (wait) {
-               struct timer_list timer;
-               int ret;
+static void
+ahd_linux_setup_tag_info_global(char *p)
+{
+       int tags, i, j;
 
-               pending_scb->platform_data->flags |= AHD_SCB_UP_EH_SEM;
-               spin_unlock_irq(&ahd->platform_data->spin_lock);
-               init_timer(&timer);
-               timer.data = (u_long)pending_scb;
-               timer.expires = jiffies + (5 * HZ);
-               timer.function = ahd_linux_sem_timeout;
-               add_timer(&timer);
-               printf("Recovery code sleeping\n");
-               down(&ahd->platform_data->eh_sem);
-               printf("Recovery code awake\n");
-               ret = del_timer_sync(&timer);
-               if (ret == 0) {
-                       printf("Timer Expired\n");
-                       retval = FAILED;
+       tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
+       printf("Setting Global Tags= %d\n", tags);
+
+       for (i = 0; i < NUM_ELEMENTS(aic79xx_tag_info); i++) {
+               for (j = 0; j < AHD_NUM_TARGETS; j++) {
+                       aic79xx_tag_info[i].tag_commands[j] = tags;
                }
-               spin_lock_irq(&ahd->platform_data->spin_lock);
        }
-       ahd_schedule_runq(ahd);
-       ahd_linux_run_complete_queue(ahd);
-       ahd_midlayer_entrypoint_unlock(ahd, &s);
-       return (retval);
 }
 
-
 static void
-ahd_linux_dev_reset_complete(Scsi_Cmnd *cmd)
+ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
 {
-       free(cmd, M_DEVBUF);
+
+       if ((instance >= 0) && (targ >= 0)
+        && (instance < NUM_ELEMENTS(aic79xx_tag_info))
+        && (targ < AHD_NUM_TARGETS)) {
+               aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
+               if (bootverbose)
+                       printf("tag_info[%d:%d] = %d\n", instance, targ, value);
+       }
 }
 
 /*
- * Attempt to send a target reset message to the device that timed out.
+ * Handle Linux boot parameters. This routine allows for assigning a value
+ * to a parameter with a ':' between the parameter and the value.
+ * ie. aic79xx=stpwlev:1,extended
  */
 static int
-ahd_linux_dev_reset(Scsi_Cmnd *cmd)
+aic79xx_setup(char *s)
 {
-       struct  ahd_softc *ahd;
-       struct  scsi_cmnd *recovery_cmd;
-       struct  ahd_linux_device *dev;
-       struct  ahd_initiator_tinfo *tinfo;
-       struct  ahd_tmode_tstate *tstate;
-       struct  scb *scb;
-       struct  hardware_scb *hscb;
-       u_long  s;
-       struct  timer_list timer;
-       int     retval;
+       int     i, n;
+       char   *p;
+       char   *end;
 
-       ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
-       recovery_cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
-       if (!recovery_cmd)
-               return (FAILED);
-       memset(recovery_cmd, 0, sizeof(struct scsi_cmnd));
-       recovery_cmd->device = cmd->device;
-       recovery_cmd->scsi_done = ahd_linux_dev_reset_complete;
+       static struct {
+               const char *name;
+               uint32_t *flag;
+       } options[] = {
+               { "extended", &aic79xx_extended },
+               { "no_reset", &aic79xx_no_reset },
+               { "verbose", &aic79xx_verbose },
+               { "allow_memio", &aic79xx_allow_memio},
 #ifdef AHD_DEBUG
-       if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
-               printf("%s:%d:%d:%d: Device reset called for cmd %p\n",
-                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
-                      cmd->device->lun, cmd);
+               { "debug", &ahd_debug },
 #endif
-       ahd_lock(ahd, &s);
-
-       dev = ahd_linux_get_device(ahd, cmd->device->channel, cmd->device->id,
-                                  cmd->device->lun, /*alloc*/FALSE);
-       if (dev == NULL) {
-               ahd_unlock(ahd, &s);
-               kfree(recovery_cmd);
-               return (FAILED);
-       }
-       if ((scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX)) == NULL) {
-               ahd_unlock(ahd, &s);
-               kfree(recovery_cmd);
-               return (FAILED);
-       }
-       tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
-                                   cmd->device->id, &tstate);
-       recovery_cmd->result = CAM_REQ_INPROG << 16;
-       recovery_cmd->host_scribble = (char *)scb;
-       scb->io_ctx = recovery_cmd;
-       scb->platform_data->dev = dev;
-       scb->sg_count = 0;
-       ahd_set_residual(scb, 0);
-       ahd_set_sense_residual(scb, 0);
-       hscb = scb->hscb;
-       hscb->control = 0;
-       hscb->scsiid = BUILD_SCSIID(ahd, cmd);
-       hscb->lun = cmd->device->lun;
-       hscb->cdb_len = 0;
-       hscb->task_management = SIU_TASKMGMT_LUN_RESET;
-       scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE;
-       if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
-               scb->flags |= SCB_PACKETIZED;
-       } else {
-               hscb->control |= MK_MESSAGE;
-       }
-       dev->openings--;
-       dev->active++;
-       dev->commands_issued++;
-       LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
-       ahd_queue_scb(ahd, scb);
+               { "reverse_scan", &aic79xx_reverse_scan },
+               { "periodic_otag", &aic79xx_periodic_otag },
+               { "pci_parity", &aic79xx_pci_parity },
+               { "seltime", &aic79xx_seltime },
+               { "tag_info", NULL },
+               { "global_tag_depth", NULL},
+               { "slewrate", NULL },
+               { "precomp", NULL },
+               { "amplitude", NULL },
+       };
 
-       scb->platform_data->flags |= AHD_SCB_UP_EH_SEM;
-       ahd_unlock(ahd, &s);
-       init_timer(&timer);
-       timer.data = (u_long)scb;
-       timer.expires = jiffies + (5 * HZ);
-       timer.function = ahd_linux_sem_timeout;
-       add_timer(&timer);
-       printf("Recovery code sleeping\n");
-       down(&ahd->platform_data->eh_sem);
-       printf("Recovery code awake\n");
-       retval = SUCCESS;
-       if (del_timer_sync(&timer) == 0) {
-               printf("Timer Expired\n");
-               retval = FAILED;
-       }
-       ahd_lock(ahd, &s);
-       ahd_schedule_runq(ahd);
-       ahd_linux_run_complete_queue(ahd);
-       ahd_unlock(ahd, &s);
-       printf("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
-       return (retval);
-}
+       end = strchr(s, '\0');
 
-/*
- * Reset the SCSI bus.
- */
-static int
-ahd_linux_bus_reset(Scsi_Cmnd *cmd)
-{
-       struct ahd_softc *ahd;
-       u_long s;
-       int    found;
+       /*
+        * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS
+        * will never be 0 in this case.
+        */      
+       n = 0;  
 
-       ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
-#ifdef AHD_DEBUG
-       if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
-               printf("%s: Bus reset called for cmd %p\n",
-                      ahd_name(ahd), cmd);
-#endif
-       ahd_lock(ahd, &s);
-       found = ahd_reset_channel(ahd, cmd->device->channel + 'A',
-                                 /*initiate reset*/TRUE);
-       ahd_linux_run_complete_queue(ahd);
-       ahd_unlock(ahd, &s);
-
-       if (bootverbose)
-               printf("%s: SCSI bus reset delivered. "
-                      "%d SCBs aborted.\n", ahd_name(ahd), found);
-
-       return (SUCCESS);
-}
-
-Scsi_Host_Template aic79xx_driver_template = {
-       .module                 = THIS_MODULE,
-       .name                   = "aic79xx",
-       .proc_info              = ahd_linux_proc_info,
-       .info                   = ahd_linux_info,
-       .queuecommand           = ahd_linux_queue,
-       .eh_abort_handler       = ahd_linux_abort,
-       .eh_device_reset_handler = ahd_linux_dev_reset,
-       .eh_bus_reset_handler   = ahd_linux_bus_reset,
-#if defined(__i386__)
-       .bios_param             = ahd_linux_biosparam,
-#endif
-       .can_queue              = AHD_MAX_QUEUE,
-       .this_id                = -1,
-       .cmd_per_lun            = 2,
-       .use_clustering         = ENABLE_CLUSTERING,
-       .slave_alloc            = ahd_linux_slave_alloc,
-       .slave_configure        = ahd_linux_slave_configure,
-       .slave_destroy          = ahd_linux_slave_destroy,
-};
-
-/**************************** Tasklet Handler *********************************/
-
-/*
- * In 2.4.X and above, this routine is called from a tasklet,
- * so we must re-acquire our lock prior to executing this code.
- * In all prior kernels, ahd_schedule_runq() calls this routine
- * directly and ahd_schedule_runq() is called with our lock held.
- */
-static void
-ahd_runq_tasklet(unsigned long data)
-{
-       struct ahd_softc* ahd;
-       struct ahd_linux_device *dev;
-       u_long flags;
-
-       ahd = (struct ahd_softc *)data;
-       ahd_lock(ahd, &flags);
-       while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
-       
-               TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
-               dev->flags &= ~AHD_DEV_ON_RUN_LIST;
-               ahd_linux_check_device_queue(ahd, dev);
-               /* Yeild to our interrupt handler */
-               ahd_unlock(ahd, &flags);
-               ahd_lock(ahd, &flags);
-       }
-       ahd_unlock(ahd, &flags);
-}
-
-/******************************** Bus DMA *************************************/
-int
-ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
-                  bus_size_t alignment, bus_size_t boundary,
-                  dma_addr_t lowaddr, dma_addr_t highaddr,
-                  bus_dma_filter_t *filter, void *filterarg,
-                  bus_size_t maxsize, int nsegments,
-                  bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
-{
-       bus_dma_tag_t dmat;
-
-       dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
-       if (dmat == NULL)
-               return (ENOMEM);
-
-       /*
-        * Linux is very simplistic about DMA memory.  For now don't
-        * maintain all specification information.  Once Linux supplies
-        * better facilities for doing these operations, or the
-        * needs of this particular driver change, we might need to do
-        * more here.
-        */
-       dmat->alignment = alignment;
-       dmat->boundary = boundary;
-       dmat->maxsize = maxsize;
-       *ret_tag = dmat;
-       return (0);
-}
-
-void
-ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
-{
-       free(dmat, M_DEVBUF);
-}
-
-int
-ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
-                int flags, bus_dmamap_t *mapp)
-{
-       bus_dmamap_t map;
-
-       map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
-       if (map == NULL)
-               return (ENOMEM);
-       /*
-        * Although we can dma data above 4GB, our
-        * "consistent" memory is below 4GB for
-        * space efficiency reasons (only need a 4byte
-        * address).  For this reason, we have to reset
-        * our dma mask when doing allocations.
-        */
-       if (ahd->dev_softc != NULL)
-               if (pci_set_dma_mask(ahd->dev_softc, 0xFFFFFFFF)) {
-                       printk(KERN_WARNING "aic79xx: No suitable DMA available.\n");
-                       kfree(map);
-                       return (ENODEV);
-               }
-       *vaddr = pci_alloc_consistent(ahd->dev_softc,
-                                     dmat->maxsize, &map->bus_addr);
-       if (ahd->dev_softc != NULL)
-               if (pci_set_dma_mask(ahd->dev_softc,
-                                    ahd->platform_data->hw_dma_mask)) {
-                       printk(KERN_WARNING "aic79xx: No suitable DMA available.\n");
-                       kfree(map);
-                       return (ENODEV);
-               }
-       if (*vaddr == NULL)
-               return (ENOMEM);
-       *mapp = map;
-       return(0);
-}
-
-void
-ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
-               void* vaddr, bus_dmamap_t map)
-{
-       pci_free_consistent(ahd->dev_softc, dmat->maxsize,
-                           vaddr, map->bus_addr);
-}
-
-int
-ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
-               void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
-               void *cb_arg, int flags)
-{
-       /*
-        * Assume for now that this will only be used during
-        * initialization and not for per-transaction buffer mapping.
-        */
-       bus_dma_segment_t stack_sg;
-
-       stack_sg.ds_addr = map->bus_addr;
-       stack_sg.ds_len = dmat->maxsize;
-       cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
-       return (0);
-}
-
-void
-ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
-{
-       /*
-        * The map may is NULL in our < 2.3.X implementation.
-        */
-       if (map != NULL)
-               free(map, M_DEVBUF);
-}
-
-int
-ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
-{
-       /* Nothing to do */
-       return (0);
-}
-
-/********************* Platform Dependent Functions ***************************/
-/*
- * Compare "left hand" softc with "right hand" softc, returning:
- * < 0 - lahd has a lower priority than rahd
- *   0 - Softcs are equal
- * > 0 - lahd has a higher priority than rahd
- */
-int
-ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd)
-{
-       int     value;
-
-       /*
-        * Under Linux, cards are ordered as follows:
-        *      1) PCI devices that are marked as the boot controller.
-        *      2) PCI devices with BIOS enabled sorted by bus/slot/func.
-        *      3) All remaining PCI devices sorted by bus/slot/func.
-        */
-#if 0
-       value = (lahd->flags & AHD_BOOT_CHANNEL)
-             - (rahd->flags & AHD_BOOT_CHANNEL);
-       if (value != 0)
-               /* Controllers set for boot have a *higher* priority */
-               return (value);
-#endif
-
-       value = (lahd->flags & AHD_BIOS_ENABLED)
-             - (rahd->flags & AHD_BIOS_ENABLED);
-       if (value != 0)
-               /* Controllers with BIOS enabled have a *higher* priority */
-               return (value);
-
-       /* Still equal.  Sort by bus/slot/func. */
-       if (aic79xx_reverse_scan != 0)
-               value = ahd_get_pci_bus(lahd->dev_softc)
-                     - ahd_get_pci_bus(rahd->dev_softc);
-       else
-               value = ahd_get_pci_bus(rahd->dev_softc)
-                     - ahd_get_pci_bus(lahd->dev_softc);
-       if (value != 0)
-               return (value);
-       if (aic79xx_reverse_scan != 0)
-               value = ahd_get_pci_slot(lahd->dev_softc)
-                     - ahd_get_pci_slot(rahd->dev_softc);
-       else
-               value = ahd_get_pci_slot(rahd->dev_softc)
-                     - ahd_get_pci_slot(lahd->dev_softc);
-       if (value != 0)
-               return (value);
-
-       value = rahd->channel - lahd->channel;
-       return (value);
-}
-
-static void
-ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
-{
-
-       if ((instance >= 0) && (targ >= 0)
-        && (instance < NUM_ELEMENTS(aic79xx_tag_info))
-        && (targ < AHD_NUM_TARGETS)) {
-               aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
-               if (bootverbose)
-                       printf("tag_info[%d:%d] = %d\n", instance, targ, value);
-       }
-}
-
-static void
-ahd_linux_setup_rd_strm_info(u_long arg, int instance, int targ, int32_t value)
-{
-       if ((instance >= 0)
-        && (instance < NUM_ELEMENTS(aic79xx_rd_strm_info))) {
-               aic79xx_rd_strm_info[instance] = value & 0xFFFF;
-               if (bootverbose)
-                       printf("rd_strm[%d] = 0x%x\n", instance, value);
-       }
-}
-
-static void
-ahd_linux_setup_dv(u_long arg, int instance, int targ, int32_t value)
-{
-       if ((instance >= 0)
-        && (instance < NUM_ELEMENTS(aic79xx_dv_settings))) {
-               aic79xx_dv_settings[instance] = value;
-               if (bootverbose)
-                       printf("dv[%d] = %d\n", instance, value);
-       }
-}
-
-static void
-ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
-{
-
-       if ((instance >= 0)
-        && (instance < NUM_ELEMENTS(aic79xx_iocell_info))) {
-               uint8_t *iocell_info;
-
-               iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
-               iocell_info[index] = value & 0xFFFF;
-               if (bootverbose)
-                       printf("iocell[%d:%ld] = %d\n", instance, index, value);
-       }
-}
-
-static void
-ahd_linux_setup_tag_info_global(char *p)
-{
-       int tags, i, j;
-
-       tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
-       printf("Setting Global Tags= %d\n", tags);
-
-       for (i = 0; i < NUM_ELEMENTS(aic79xx_tag_info); i++) {
-               for (j = 0; j < AHD_NUM_TARGETS; j++) {
-                       aic79xx_tag_info[i].tag_commands[j] = tags;
-               }
-       }
-}
-
-/*
- * Handle Linux boot parameters. This routine allows for assigning a value
- * to a parameter with a ':' between the parameter and the value.
- * ie. aic79xx=stpwlev:1,extended
- */
-static int
-aic79xx_setup(char *s)
-{
-       int     i, n;
-       char   *p;
-       char   *end;
-
-       static struct {
-               const char *name;
-               uint32_t *flag;
-       } options[] = {
-               { "extended", &aic79xx_extended },
-               { "no_reset", &aic79xx_no_reset },
-               { "verbose", &aic79xx_verbose },
-               { "allow_memio", &aic79xx_allow_memio},
-#ifdef AHD_DEBUG
-               { "debug", &ahd_debug },
-#endif
-               { "reverse_scan", &aic79xx_reverse_scan },
-               { "periodic_otag", &aic79xx_periodic_otag },
-               { "pci_parity", &aic79xx_pci_parity },
-               { "seltime", &aic79xx_seltime },
-               { "tag_info", NULL },
-               { "global_tag_depth", NULL},
-               { "rd_strm", NULL },
-               { "dv", NULL },
-               { "slewrate", NULL },
-               { "precomp", NULL },
-               { "amplitude", NULL },
-       };
-
-       end = strchr(s, '\0');
-
-       /*
-        * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS
-        * will never be 0 in this case.
-        */      
-       n = 0;  
-
-       while ((p = strsep(&s, ",.")) != NULL) {
-               if (*p == '\0')
-                       continue;
-               for (i = 0; i < NUM_ELEMENTS(options); i++) {
-
-                       n = strlen(options[i].name);
-                       if (strncmp(options[i].name, p, n) == 0)
-                               break;
-               }
-               if (i == NUM_ELEMENTS(options))
-                       continue;
-
-               if (strncmp(p, "global_tag_depth", n) == 0) {
-                       ahd_linux_setup_tag_info_global(p + n);
-               } else if (strncmp(p, "tag_info", n) == 0) {
-                       s = aic_parse_brace_option("tag_info", p + n, end,
-                           2, ahd_linux_setup_tag_info, 0);
-               } else if (strncmp(p, "rd_strm", n) == 0) {
-                       s = aic_parse_brace_option("rd_strm", p + n, end,
-                           1, ahd_linux_setup_rd_strm_info, 0);
-               } else if (strncmp(p, "dv", n) == 0) {
-                       s = aic_parse_brace_option("dv", p + n, end, 1,
-                           ahd_linux_setup_dv, 0);
-               } else if (strncmp(p, "slewrate", n) == 0) {
-                       s = aic_parse_brace_option("slewrate",
-                           p + n, end, 1, ahd_linux_setup_iocell_info,
-                           AIC79XX_SLEWRATE_INDEX);
-               } else if (strncmp(p, "precomp", n) == 0) {
-                       s = aic_parse_brace_option("precomp",
-                           p + n, end, 1, ahd_linux_setup_iocell_info,
-                           AIC79XX_PRECOMP_INDEX);
-               } else if (strncmp(p, "amplitude", n) == 0) {
-                       s = aic_parse_brace_option("amplitude",
-                           p + n, end, 1, ahd_linux_setup_iocell_info,
-                           AIC79XX_AMPLITUDE_INDEX);
-               } else if (p[n] == ':') {
-                       *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
-               } else if (!strncmp(p, "verbose", n)) {
-                       *(options[i].flag) = 1;
-               } else {
-                       *(options[i].flag) ^= 0xFFFFFFFF;
-               }
-       }
-       return 1;
-}
-
-__setup("aic79xx=", aic79xx_setup);
-
-uint32_t aic79xx_verbose;
-
-int
-ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template)
-{
-       char    buf[80];
-       struct  Scsi_Host *host;
-       char    *new_name;
-       u_long  s;
-       u_long  target;
-
-       template->name = ahd->description;
-       host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
-       if (host == NULL)
-               return (ENOMEM);
-
-       *((struct ahd_softc **)host->hostdata) = ahd;
-       ahd_lock(ahd, &s);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-       scsi_assign_lock(host, &ahd->platform_data->spin_lock);
-#elif AHD_SCSI_HAS_HOST_LOCK != 0
-       host->lock = &ahd->platform_data->spin_lock;
-#endif
-       ahd->platform_data->host = host;
-       host->can_queue = AHD_MAX_QUEUE;
-       host->cmd_per_lun = 2;
-       host->sg_tablesize = AHD_NSEG;
-       host->this_id = ahd->our_id;
-       host->irq = ahd->platform_data->irq;
-       host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
-       host->max_lun = AHD_NUM_LUNS;
-       host->max_channel = 0;
-       host->sg_tablesize = AHD_NSEG;
-       ahd_set_unit(ahd, ahd_linux_next_unit());
-       sprintf(buf, "scsi%d", host->host_no);
-       new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
-       if (new_name != NULL) {
-               strcpy(new_name, buf);
-               ahd_set_name(ahd, new_name);
-       }
-       host->unique_id = ahd->unit;
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-       scsi_set_pci_device(host, ahd->dev_softc);
-#endif
-       ahd_linux_setup_user_rd_strm_settings(ahd);
-       ahd_linux_initialize_scsi_bus(ahd);
-       ahd_unlock(ahd, &s);
-       ahd->platform_data->dv_pid = kernel_thread(ahd_linux_dv_thread, ahd, 0);
-       ahd_lock(ahd, &s);
-       if (ahd->platform_data->dv_pid < 0) {
-               printf("%s: Failed to create DV thread, error= %d\n",
-                      ahd_name(ahd), ahd->platform_data->dv_pid);
-               return (-ahd->platform_data->dv_pid);
-       }
-       /*
-        * Initially allocate *all* of our linux target objects
-        * so that the DV thread will scan them all in parallel
-        * just after driver initialization.  Any device that
-        * does not exist will have its target object destroyed
-        * by the selection timeout handler.  In the case of a
-        * device that appears after the initial DV scan, async
-        * negotiation will occur for the first command, and DV
-        * will comence should that first command be successful.
-        */
-       for (target = 0; target < host->max_id; target++) {
-
-               /*
-                * Skip our own ID.  Some Compaq/HP storage devices
-                * have enclosure management devices that respond to
-                * single bit selection (i.e. selecting ourselves).
-                * It is expected that either an external application
-                * or a modified kernel will be used to probe this
-                * ID if it is appropriate.  To accommodate these
-                * installations, ahc_linux_alloc_target() will allocate
-                * for our ID if asked to do so.
-                */
-               if (target == ahd->our_id) 
-                       continue;
-
-               ahd_linux_alloc_target(ahd, 0, target);
-       }
-       ahd_intr_enable(ahd, TRUE);
-       ahd_linux_start_dv(ahd);
-       ahd_unlock(ahd, &s);
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-       scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */
-       scsi_scan_host(host);
-#endif
-       return (0);
-}
-
-uint64_t
-ahd_linux_get_memsize(void)
-{
-       struct sysinfo si;
-
-       si_meminfo(&si);
-       return ((uint64_t)si.totalram << PAGE_SHIFT);
-}
-
-/*
- * Find the smallest available unit number to use
- * for a new device.  We don't just use a static
- * count to handle the "repeated hot-(un)plug"
- * scenario.
- */
-static int
-ahd_linux_next_unit(void)
-{
-       struct ahd_softc *ahd;
-       int unit;
-
-       unit = 0;
-retry:
-       TAILQ_FOREACH(ahd, &ahd_tailq, links) {
-               if (ahd->unit == unit) {
-                       unit++;
-                       goto retry;
-               }
-       }
-       return (unit);
-}
-
-/*
- * Place the SCSI bus into a known state by either resetting it,
- * or forcing transfer negotiations on the next command to any
- * target.
- */
-static void
-ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
-{
-       u_int target_id;
-       u_int numtarg;
-
-       target_id = 0;
-       numtarg = 0;
-
-       if (aic79xx_no_reset != 0)
-               ahd->flags &= ~AHD_RESET_BUS_A;
-
-       if ((ahd->flags & AHD_RESET_BUS_A) != 0)
-               ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
-       else
-               numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
-
-       /*
-        * Force negotiation to async for all targets that
-        * will not see an initial bus reset.
-        */
-       for (; target_id < numtarg; target_id++) {
-               struct ahd_devinfo devinfo;
-               struct ahd_initiator_tinfo *tinfo;
-               struct ahd_tmode_tstate *tstate;
-
-               tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
-                                           target_id, &tstate);
-               ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
-                                   CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
-               ahd_update_neg_request(ahd, &devinfo, tstate,
-                                      tinfo, AHD_NEG_ALWAYS);
-       }
-       /* Give the bus some time to recover */
-       if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
-               ahd_freeze_simq(ahd);
-               init_timer(&ahd->platform_data->reset_timer);
-               ahd->platform_data->reset_timer.data = (u_long)ahd;
-               ahd->platform_data->reset_timer.expires =
-                   jiffies + (AIC79XX_RESET_DELAY * HZ)/1000;
-               ahd->platform_data->reset_timer.function =
-                   (ahd_linux_callback_t *)ahd_release_simq;
-               add_timer(&ahd->platform_data->reset_timer);
-       }
-}
-
-int
-ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
-{
-       ahd->platform_data =
-           malloc(sizeof(struct ahd_platform_data), M_DEVBUF, M_NOWAIT);
-       if (ahd->platform_data == NULL)
-               return (ENOMEM);
-       memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
-       TAILQ_INIT(&ahd->platform_data->completeq);
-       TAILQ_INIT(&ahd->platform_data->device_runq);
-       ahd->platform_data->irq = AHD_LINUX_NOIRQ;
-       ahd->platform_data->hw_dma_mask = 0xFFFFFFFF;
-       ahd_lockinit(ahd);
-       ahd_done_lockinit(ahd);
-       init_timer(&ahd->platform_data->completeq_timer);
-       ahd->platform_data->completeq_timer.data = (u_long)ahd;
-       ahd->platform_data->completeq_timer.function =
-           (ahd_linux_callback_t *)ahd_linux_thread_run_complete_queue;
-       init_MUTEX_LOCKED(&ahd->platform_data->eh_sem);
-       init_MUTEX_LOCKED(&ahd->platform_data->dv_sem);
-       init_MUTEX_LOCKED(&ahd->platform_data->dv_cmd_sem);
-       ahd_setup_runq_tasklet(ahd);
-       ahd->seltime = (aic79xx_seltime & 0x3) << 4;
-       return (0);
-}
-
-void
-ahd_platform_free(struct ahd_softc *ahd)
-{
-       struct ahd_linux_target *targ;
-       struct ahd_linux_device *dev;
-       int i, j;
-
-       if (ahd->platform_data != NULL) {
-               del_timer_sync(&ahd->platform_data->completeq_timer);
-               ahd_linux_kill_dv_thread(ahd);
-               ahd_teardown_runq_tasklet(ahd);
-               if (ahd->platform_data->host != NULL) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-                       scsi_remove_host(ahd->platform_data->host);
-#endif
-                       scsi_host_put(ahd->platform_data->host);
-               }
-
-               /* destroy all of the device and target objects */
-               for (i = 0; i < AHD_NUM_TARGETS; i++) {
-                       targ = ahd->platform_data->targets[i];
-                       if (targ != NULL) {
-                               /* Keep target around through the loop. */
-                               targ->refcount++;
-                               for (j = 0; j < AHD_NUM_LUNS; j++) {
-
-                                       if (targ->devices[j] == NULL)
-                                               continue;
-                                       dev = targ->devices[j];
-                                       ahd_linux_free_device(ahd, dev);
-                               }
-                               /*
-                                * Forcibly free the target now that
-                                * all devices are gone.
-                                */
-                               ahd_linux_free_target(ahd, targ);
-                       }
-               }
-
-               if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
-                       free_irq(ahd->platform_data->irq, ahd);
-               if (ahd->tags[0] == BUS_SPACE_PIO
-                && ahd->bshs[0].ioport != 0)
-                       release_region(ahd->bshs[0].ioport, 256);
-               if (ahd->tags[1] == BUS_SPACE_PIO
-                && ahd->bshs[1].ioport != 0)
-                       release_region(ahd->bshs[1].ioport, 256);
-               if (ahd->tags[0] == BUS_SPACE_MEMIO
-                && ahd->bshs[0].maddr != NULL) {
-                       iounmap(ahd->bshs[0].maddr);
-                       release_mem_region(ahd->platform_data->mem_busaddr,
-                                          0x1000);
-               }
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-               /*
-                * In 2.4 we detach from the scsi midlayer before the PCI
-                * layer invokes our remove callback.  No per-instance
-                * detach is provided, so we must reach inside the PCI
-                * subsystem's internals and detach our driver manually.
-                */
-               if (ahd->dev_softc != NULL)
-                       ahd->dev_softc->driver = NULL;
-#endif
-               free(ahd->platform_data, M_DEVBUF);
-       }
-}
-
-void
-ahd_platform_init(struct ahd_softc *ahd)
-{
-       /*
-        * Lookup and commit any modified IO Cell options.
-        */
-       if (ahd->unit < NUM_ELEMENTS(aic79xx_iocell_info)) {
-               struct ahd_linux_iocell_opts *iocell_opts;
-
-               iocell_opts = &aic79xx_iocell_info[ahd->unit];
-               if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
-                       AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
-               if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
-                       AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
-               if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
-                       AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
-       }
-
-}
-
-void
-ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
-{
-       ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
-                               SCB_GET_CHANNEL(ahd, scb),
-                               SCB_GET_LUN(scb), SCB_LIST_NULL,
-                               ROLE_UNKNOWN, CAM_REQUEUE_REQ);
-}
-
-void
-ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
-                     ahd_queue_alg alg)
-{
-       struct ahd_linux_device *dev;
-       int was_queuing;
-       int now_queuing;
-
-       dev = ahd_linux_get_device(ahd, devinfo->channel - 'A',
-                                  devinfo->target,
-                                  devinfo->lun, /*alloc*/FALSE);
-       if (dev == NULL)
-               return;
-       was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
-       switch (alg) {
-       default:
-       case AHD_QUEUE_NONE:
-               now_queuing = 0;
-               break; 
-       case AHD_QUEUE_BASIC:
-               now_queuing = AHD_DEV_Q_BASIC;
-               break;
-       case AHD_QUEUE_TAGGED:
-               now_queuing = AHD_DEV_Q_TAGGED;
-               break;
-       }
-       if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
-        && (was_queuing != now_queuing)
-        && (dev->active != 0)) {
-               dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
-               dev->qfrozen++;
-       }
-
-       dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
-       if (now_queuing) {
-               u_int usertags;
-
-               usertags = ahd_linux_user_tagdepth(ahd, devinfo);
-               if (!was_queuing) {
-                       /*
-                        * Start out agressively and allow our
-                        * dynamic queue depth algorithm to take
-                        * care of the rest.
-                        */
-                       dev->maxtags = usertags;
-                       dev->openings = dev->maxtags - dev->active;
-               }
-               if (dev->maxtags == 0) {
-                       /*
-                        * Queueing is disabled by the user.
-                        */
-                       dev->openings = 1;
-               } else if (alg == AHD_QUEUE_TAGGED) {
-                       dev->flags |= AHD_DEV_Q_TAGGED;
-                       if (aic79xx_periodic_otag != 0)
-                               dev->flags |= AHD_DEV_PERIODIC_OTAG;
-               } else
-                       dev->flags |= AHD_DEV_Q_BASIC;
-       } else {
-               /* We can only have one opening. */
-               dev->maxtags = 0;
-               dev->openings =  1 - dev->active;
-       }
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-       if (dev->scsi_device != NULL) {
-               switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
-               case AHD_DEV_Q_BASIC:
-                       scsi_adjust_queue_depth(dev->scsi_device,
-                                               MSG_SIMPLE_TASK,
-                                               dev->openings + dev->active);
-                       break;
-               case AHD_DEV_Q_TAGGED:
-                       scsi_adjust_queue_depth(dev->scsi_device,
-                                               MSG_ORDERED_TASK,
-                                               dev->openings + dev->active);
-                       break;
-               default:
-                       /*
-                        * We allow the OS to queue 2 untagged transactions to
-                        * us at any time even though we can only execute them
-                        * serially on the controller/device.  This should
-                        * remove some latency.
-                        */
-                       scsi_adjust_queue_depth(dev->scsi_device,
-                                               /*NON-TAGGED*/0,
-                                               /*queue depth*/2);
-                       break;
-               }
-       }
-#endif
-}
-
-int
-ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
-                       int lun, u_int tag, role_t role, uint32_t status)
-{
-       int targ;
-       int maxtarg;
-       int maxlun;
-       int clun;
-       int count;
-
-       if (tag != SCB_LIST_NULL)
-               return (0);
-
-       targ = 0;
-       if (target != CAM_TARGET_WILDCARD) {
-               targ = target;
-               maxtarg = targ + 1;
-       } else {
-               maxtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
-       }
-       clun = 0;
-       if (lun != CAM_LUN_WILDCARD) {
-               clun = lun;
-               maxlun = clun + 1;
-       } else {
-               maxlun = AHD_NUM_LUNS;
-       }
-
-       count = 0;
-       for (; targ < maxtarg; targ++) {
-
-               for (; clun < maxlun; clun++) {
-                       struct ahd_linux_device *dev;
-                       struct ahd_busyq *busyq;
-                       struct ahd_cmd *acmd;
-
-                       dev = ahd_linux_get_device(ahd, /*chan*/0, targ,
-                                                  clun, /*alloc*/FALSE);
-                       if (dev == NULL)
-                               continue;
-
-                       busyq = &dev->busyq;
-                       while ((acmd = TAILQ_FIRST(busyq)) != NULL) {
-                               Scsi_Cmnd *cmd;
-
-                               cmd = &acmd_scsi_cmd(acmd);
-                               TAILQ_REMOVE(busyq, acmd,
-                                            acmd_links.tqe);
-                               count++;
-                               cmd->result = status << 16;
-                               ahd_linux_queue_cmd_complete(ahd, cmd);
-                       }
-               }
-       }
-
-       return (count);
-}
-
-static void
-ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd)
-{
-       u_long flags;
-
-       ahd_lock(ahd, &flags);
-       del_timer(&ahd->platform_data->completeq_timer);
-       ahd->platform_data->flags &= ~AHD_RUN_CMPLT_Q_TIMER;
-       ahd_linux_run_complete_queue(ahd);
-       ahd_unlock(ahd, &flags);
-}
-
-static void
-ahd_linux_start_dv(struct ahd_softc *ahd)
-{
-
-       /*
-        * Freeze the simq and signal ahd_linux_queue to not let any
-        * more commands through
-        */
-       if ((ahd->platform_data->flags & AHD_DV_ACTIVE) == 0) {
-#ifdef AHD_DEBUG
-               if (ahd_debug & AHD_SHOW_DV)
-                       printf("%s: Starting DV\n", ahd_name(ahd));
-#endif
-
-               ahd->platform_data->flags |= AHD_DV_ACTIVE;
-               ahd_freeze_simq(ahd);
-
-               /* Wake up the DV kthread */
-               up(&ahd->platform_data->dv_sem);
-       }
-}
-
-static int
-ahd_linux_dv_thread(void *data)
-{
-       struct  ahd_softc *ahd;
-       int     target;
-       u_long  s;
-
-       ahd = (struct ahd_softc *)data;
-
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV)
-               printf("In DV Thread\n");
-#endif
-
-       /*
-        * Complete thread creation.
-        */
-       lock_kernel();
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60)
-       /*
-        * Don't care about any signals.
-        */
-       siginitsetinv(&current->blocked, 0);
-
-       daemonize();
-       sprintf(current->comm, "ahd_dv_%d", ahd->unit);
-#else
-       daemonize("ahd_dv_%d", ahd->unit);
-       current->flags |= PF_NOFREEZE;
-#endif
-       unlock_kernel();
-
-       while (1) {
-               /*
-                * Use down_interruptible() rather than down() to
-                * avoid inclusion in the load average.
-                */
-               down_interruptible(&ahd->platform_data->dv_sem);
-
-               /* Check to see if we've been signaled to exit */
-               ahd_lock(ahd, &s);
-               if ((ahd->platform_data->flags & AHD_DV_SHUTDOWN) != 0) {
-                       ahd_unlock(ahd, &s);
-                       break;
-               }
-               ahd_unlock(ahd, &s);
-
-#ifdef AHD_DEBUG
-               if (ahd_debug & AHD_SHOW_DV)
-                       printf("%s: Beginning Domain Validation\n",
-                              ahd_name(ahd));
-#endif
-
-               /*
-                * Wait for any pending commands to drain before proceeding.
-                */
-               ahd_lock(ahd, &s);
-               while (LIST_FIRST(&ahd->pending_scbs) != NULL) {
-                       ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_EMPTY;
-                       ahd_unlock(ahd, &s);
-                       down_interruptible(&ahd->platform_data->dv_sem);
-                       ahd_lock(ahd, &s);
-               }
-
-               /*
-                * Wait for the SIMQ to be released so that DV is the
-                * only reason the queue is frozen.
-                */
-               while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
-                       ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
-                       ahd_unlock(ahd, &s);
-                       down_interruptible(&ahd->platform_data->dv_sem);
-                       ahd_lock(ahd, &s);
-               }
-               ahd_unlock(ahd, &s);
-
-               for (target = 0; target < AHD_NUM_TARGETS; target++)
-                       ahd_linux_dv_target(ahd, target);
-
-               ahd_lock(ahd, &s);
-               ahd->platform_data->flags &= ~AHD_DV_ACTIVE;
-               ahd_unlock(ahd, &s);
-
-               /*
-                * Release the SIMQ so that normal commands are
-                * allowed to continue on the bus.
-                */
-               ahd_release_simq(ahd);
-       }
-       up(&ahd->platform_data->eh_sem);
-       return (0);
-}
-
-static void
-ahd_linux_kill_dv_thread(struct ahd_softc *ahd)
-{
-       u_long s;
-
-       ahd_lock(ahd, &s);
-       if (ahd->platform_data->dv_pid != 0) {
-               ahd->platform_data->flags |= AHD_DV_SHUTDOWN;
-               ahd_unlock(ahd, &s);
-               up(&ahd->platform_data->dv_sem);
-
-               /*
-                * Use the eh_sem as an indicator that the
-                * dv thread is exiting.  Note that the dv
-                * thread must still return after performing
-                * the up on our semaphore before it has
-                * completely exited this module.  Unfortunately,
-                * there seems to be no easy way to wait for the
-                * exit of a thread for which you are not the
-                * parent (dv threads are parented by init).
-                * Cross your fingers...
-                */
-               down(&ahd->platform_data->eh_sem);
-
-               /*
-                * Mark the dv thread as already dead.  This
-                * avoids attempting to kill it a second time.
-                * This is necessary because we must kill the
-                * DV thread before calling ahd_free() in the
-                * module shutdown case to avoid bogus locking
-                * in the SCSI mid-layer, but we ahd_free() is
-                * called without killing the DV thread in the
-                * instance detach case, so ahd_platform_free()
-                * calls us again to verify that the DV thread
-                * is dead.
-                */
-               ahd->platform_data->dv_pid = 0;
-       } else {
-               ahd_unlock(ahd, &s);
-       }
-}
-
-#define AHD_LINUX_DV_INQ_SHORT_LEN     36
-#define AHD_LINUX_DV_INQ_LEN           256
-#define AHD_LINUX_DV_TIMEOUT           (HZ / 4)
-
-#define AHD_SET_DV_STATE(ahd, targ, newstate) \
-       ahd_set_dv_state(ahd, targ, newstate, __LINE__)
-
-static __inline void
-ahd_set_dv_state(struct ahd_softc *ahd, struct ahd_linux_target *targ,
-                ahd_dv_state newstate, u_int line)
-{
-       ahd_dv_state oldstate;
-
-       oldstate = targ->dv_state;
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV)
-               printf("%s:%d: Going from state %d to state %d\n",
-                      ahd_name(ahd), line, oldstate, newstate);
-#endif
-
-       if (oldstate == newstate)
-               targ->dv_state_retry++;
-       else
-               targ->dv_state_retry = 0;
-       targ->dv_state = newstate;
-}
-
-static void
-ahd_linux_dv_target(struct ahd_softc *ahd, u_int target_offset)
-{
-       struct   ahd_devinfo devinfo;
-       struct   ahd_linux_target *targ;
-       struct   scsi_cmnd *cmd;
-       struct   scsi_device *scsi_dev;
-       struct   scsi_sense_data *sense;
-       uint8_t *buffer;
-       u_long   s;
-       u_int    timeout;
-       int      echo_size;
-
-       sense = NULL;
-       buffer = NULL;
-       echo_size = 0;
-       ahd_lock(ahd, &s);
-       targ = ahd->platform_data->targets[target_offset];
-       if (targ == NULL || (targ->flags & AHD_DV_REQUIRED) == 0) {
-               ahd_unlock(ahd, &s);
-               return;
-       }
-       ahd_compile_devinfo(&devinfo, ahd->our_id, targ->target, /*lun*/0,
-                           targ->channel + 'A', ROLE_INITIATOR);
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, &devinfo);
-               printf("Performing DV\n");
-       }
-#endif
-
-       ahd_unlock(ahd, &s);
-
-       cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
-       scsi_dev = malloc(sizeof(struct scsi_device), M_DEVBUF, M_WAITOK);
-       scsi_dev->host = ahd->platform_data->host;
-       scsi_dev->id = devinfo.target;
-       scsi_dev->lun = devinfo.lun;
-       scsi_dev->channel = devinfo.channel - 'A';
-       ahd->platform_data->dv_scsi_dev = scsi_dev;
-
-       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_SHORT_ASYNC);
-
-       while (targ->dv_state != AHD_DV_STATE_EXIT) {
-               timeout = AHD_LINUX_DV_TIMEOUT;
-               switch (targ->dv_state) {
-               case AHD_DV_STATE_INQ_SHORT_ASYNC:
-               case AHD_DV_STATE_INQ_ASYNC:
-               case AHD_DV_STATE_INQ_ASYNC_VERIFY:
-                       /*
-                        * Set things to async narrow to reduce the
-                        * chance that the INQ will fail.
-                        */
-                       ahd_lock(ahd, &s);
-                       ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
-                                        AHD_TRANS_GOAL, /*paused*/FALSE);
-                       ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
-                                     AHD_TRANS_GOAL, /*paused*/FALSE);
-                       ahd_unlock(ahd, &s);
-                       timeout = 10 * HZ;
-                       targ->flags &= ~AHD_INQ_VALID;
-                       /* FALLTHROUGH */
-               case AHD_DV_STATE_INQ_VERIFY:
-               {
-                       u_int inq_len;
-
-                       if (targ->dv_state == AHD_DV_STATE_INQ_SHORT_ASYNC)
-                               inq_len = AHD_LINUX_DV_INQ_SHORT_LEN;
-                       else
-                               inq_len = targ->inq_data->additional_length + 5;
-                       ahd_linux_dv_inq(ahd, cmd, &devinfo, targ, inq_len);
-                       break;
-               }
-               case AHD_DV_STATE_TUR:
-               case AHD_DV_STATE_BUSY:
-                       timeout = 5 * HZ;
-                       ahd_linux_dv_tur(ahd, cmd, &devinfo);
-                       break;
-               case AHD_DV_STATE_REBD:
-                       ahd_linux_dv_rebd(ahd, cmd, &devinfo, targ);
-                       break;
-               case AHD_DV_STATE_WEB:
-                       ahd_linux_dv_web(ahd, cmd, &devinfo, targ);
-                       break;
-
-               case AHD_DV_STATE_REB:
-                       ahd_linux_dv_reb(ahd, cmd, &devinfo, targ);
-                       break;
-
-               case AHD_DV_STATE_SU:
-                       ahd_linux_dv_su(ahd, cmd, &devinfo, targ);
-                       timeout = 50 * HZ;
-                       break;
-
-               default:
-                       ahd_print_devinfo(ahd, &devinfo);
-                       printf("Unknown DV state %d\n", targ->dv_state);
-                       goto out;
-               }
-
-               /* Queue the command and wait for it to complete */
-               /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
-               init_timer(&cmd->eh_timeout);
-#ifdef AHD_DEBUG
-               if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
-                       /*
-                        * All of the printfs during negotiation
-                        * really slow down the negotiation.
-                        * Add a bit of time just to be safe.
-                        */
-                       timeout += HZ;
-#endif
-               scsi_add_timer(cmd, timeout, ahd_linux_dv_timeout);
-               /*
-                * In 2.5.X, it is assumed that all calls from the
-                * "midlayer" (which we are emulating) will have the
-                * ahd host lock held.  For other kernels, the
-                * io_request_lock must be held.
-                */
-#if AHD_SCSI_HAS_HOST_LOCK != 0
-               ahd_lock(ahd, &s);
-#else
-               spin_lock_irqsave(&io_request_lock, s);
-#endif
-               ahd_linux_queue(cmd, ahd_linux_dv_complete);
-#if AHD_SCSI_HAS_HOST_LOCK != 0
-               ahd_unlock(ahd, &s);
-#else
-               spin_unlock_irqrestore(&io_request_lock, s);
-#endif
-               down_interruptible(&ahd->platform_data->dv_cmd_sem);
-               /*
-                * Wait for the SIMQ to be released so that DV is the
-                * only reason the queue is frozen.
-                */
-               ahd_lock(ahd, &s);
-               while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
-                       ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
-                       ahd_unlock(ahd, &s);
-                       down_interruptible(&ahd->platform_data->dv_sem);
-                       ahd_lock(ahd, &s);
-               }
-               ahd_unlock(ahd, &s);
-
-               ahd_linux_dv_transition(ahd, cmd, &devinfo, targ);
-       }
-
-out:
-       if ((targ->flags & AHD_INQ_VALID) != 0
-        && ahd_linux_get_device(ahd, devinfo.channel - 'A',
-                                devinfo.target, devinfo.lun,
-                                /*alloc*/FALSE) == NULL) {
-               /*
-                * The DV state machine failed to configure this device.  
-                * This is normal if DV is disabled.  Since we have inquiry
-                * data, filter it and use the "optimistic" negotiation
-                * parameters found in the inquiry string.
-                */
-               ahd_linux_filter_inquiry(ahd, &devinfo);
-               if ((targ->flags & (AHD_BASIC_DV|AHD_ENHANCED_DV)) != 0) {
-                       ahd_print_devinfo(ahd, &devinfo);
-                       printf("DV failed to configure device.  "
-                              "Please file a bug report against "
-                              "this driver.\n");
-               }
-       }
-
-       if (cmd != NULL)
-               free(cmd, M_DEVBUF);
-
-       if (ahd->platform_data->dv_scsi_dev != NULL) {
-               free(ahd->platform_data->dv_scsi_dev, M_DEVBUF);
-               ahd->platform_data->dv_scsi_dev = NULL;
-       }
-
-       ahd_lock(ahd, &s);
-       if (targ->dv_buffer != NULL) {
-               free(targ->dv_buffer, M_DEVBUF);
-               targ->dv_buffer = NULL;
-       }
-       if (targ->dv_buffer1 != NULL) {
-               free(targ->dv_buffer1, M_DEVBUF);
-               targ->dv_buffer1 = NULL;
-       }
-       targ->flags &= ~AHD_DV_REQUIRED;
-       if (targ->refcount == 0)
-               ahd_linux_free_target(ahd, targ);
-       ahd_unlock(ahd, &s);
-}
-
-static __inline int
-ahd_linux_dv_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
-{
-       u_long s;
-       int retval;
-
-       ahd_lock(ahd, &s);
-       retval = ahd_linux_fallback(ahd, devinfo);
-       ahd_unlock(ahd, &s);
-
-       return (retval);
-}
-
-static void
-ahd_linux_dv_transition(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
-                       struct ahd_devinfo *devinfo,
-                       struct ahd_linux_target *targ)
-{
-       u_int32_t status;
-
-       status = aic_error_action(cmd, targ->inq_data,
-                                 ahd_cmd_get_transaction_status(cmd),
-                                 ahd_cmd_get_scsi_status(cmd));
-
-       
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, devinfo);
-               printf("Entering ahd_linux_dv_transition, state= %d, "
-                      "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state,
-                      status, cmd->result);
-       }
-#endif
-
-       switch (targ->dv_state) {
-       case AHD_DV_STATE_INQ_SHORT_ASYNC:
-       case AHD_DV_STATE_INQ_ASYNC:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-               {
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1);
-                       break;
-               }
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               case SS_TUR:
-               case SS_RETRY:
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       if (ahd_cmd_get_transaction_status(cmd)
-                        == CAM_REQUEUE_REQ)
-                               targ->dv_state_retry--;
-                       if ((status & SS_ERRMASK) == EBUSY)
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
-                       if (targ->dv_state_retry < 10)
-                               break;
-                       /* FALLTHROUGH */
-               default:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-#ifdef AHD_DEBUG
-                       if (ahd_debug & AHD_SHOW_DV) {
-                               ahd_print_devinfo(ahd, devinfo);
-                               printf("Failed DV inquiry, skipping\n");
-                       }
-#endif
-                       break;
-               }
-               break;
-       case AHD_DV_STATE_INQ_ASYNC_VERIFY:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-               {
-                       u_int xportflags;
-                       u_int spi3data;
-
-                       if (memcmp(targ->inq_data, targ->dv_buffer,
-                                  AHD_LINUX_DV_INQ_LEN) != 0) {
-                               /*
-                                * Inquiry data must have changed.
-                                * Try from the top again.
-                                */
-                               AHD_SET_DV_STATE(ahd, targ,
-                                                AHD_DV_STATE_INQ_SHORT_ASYNC);
-                               break;
-                       }
-
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1);
-                       targ->flags |= AHD_INQ_VALID;
-                       if (ahd_linux_user_dv_setting(ahd) == 0)
-                               break;
-
-                       xportflags = targ->inq_data->flags;
-                       if ((xportflags & (SID_Sync|SID_WBus16)) == 0)
-                               break;
-
-                       spi3data = targ->inq_data->spi3data;
-                       switch (spi3data & SID_SPI_CLOCK_DT_ST) {
-                       default:
-                       case SID_SPI_CLOCK_ST:
-                               /* Assume only basic DV is supported. */
-                               targ->flags |= AHD_BASIC_DV;
-                               break;
-                       case SID_SPI_CLOCK_DT:
-                       case SID_SPI_CLOCK_DT_ST:
-                               targ->flags |= AHD_ENHANCED_DV;
-                               break;
-                       }
-                       break;
-               }
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               case SS_TUR:
-               case SS_RETRY:
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       if (ahd_cmd_get_transaction_status(cmd)
-                        == CAM_REQUEUE_REQ)
-                               targ->dv_state_retry--;
-
-                       if ((status & SS_ERRMASK) == EBUSY)
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
-                       if (targ->dv_state_retry < 10)
-                               break;
-                       /* FALLTHROUGH */
-               default:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-#ifdef AHD_DEBUG
-                       if (ahd_debug & AHD_SHOW_DV) {
-                               ahd_print_devinfo(ahd, devinfo);
-                               printf("Failed DV inquiry, skipping\n");
-                       }
-#endif
-                       break;
-               }
-               break;
-       case AHD_DV_STATE_INQ_VERIFY:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-               {
-
-                       if (memcmp(targ->inq_data, targ->dv_buffer,
-                                  AHD_LINUX_DV_INQ_LEN) == 0) {
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                               break;
-                       }
-
-#ifdef AHD_DEBUG
-                       if (ahd_debug & AHD_SHOW_DV) {
-                               int i;
-
-                               ahd_print_devinfo(ahd, devinfo);
-                               printf("Inquiry buffer mismatch:");
-                               for (i = 0; i < AHD_LINUX_DV_INQ_LEN; i++) {
-                                       if ((i & 0xF) == 0)
-                                               printf("\n        ");
-                                       printf("0x%x:0x0%x ",
-                                              ((uint8_t *)targ->inq_data)[i], 
-                                              targ->dv_buffer[i]);
-                               }
-                               printf("\n");
-                       }
-#endif
-
-                       if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                               break;
-                       }
-                       /*
-                        * Do not count "falling back"
-                        * against our retries.
-                        */
-                       targ->dv_state_retry = 0;
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       break;
-               }
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               case SS_TUR:
-               case SS_RETRY:
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       if (ahd_cmd_get_transaction_status(cmd)
-                        == CAM_REQUEUE_REQ) {
-                               targ->dv_state_retry--;
-                       } else if ((status & SSQ_FALLBACK) != 0) {
-                               if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
-                                       AHD_SET_DV_STATE(ahd, targ,
-                                                        AHD_DV_STATE_EXIT);
-                                       break;
-                               }
-                               /*
-                                * Do not count "falling back"
-                                * against our retries.
-                                */
-                               targ->dv_state_retry = 0;
-                       } else if ((status & SS_ERRMASK) == EBUSY)
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
-                       if (targ->dv_state_retry < 10)
-                               break;
-                       /* FALLTHROUGH */
-               default:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-#ifdef AHD_DEBUG
-                       if (ahd_debug & AHD_SHOW_DV) {
-                               ahd_print_devinfo(ahd, devinfo);
-                               printf("Failed DV inquiry, skipping\n");
-                       }
-#endif
-                       break;
-               }
-               break;
-
-       case AHD_DV_STATE_TUR:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-                       if ((targ->flags & AHD_BASIC_DV) != 0) {
-                               ahd_linux_filter_inquiry(ahd, devinfo);
-                               AHD_SET_DV_STATE(ahd, targ,
-                                                AHD_DV_STATE_INQ_VERIFY);
-                       } else if ((targ->flags & AHD_ENHANCED_DV) != 0) {
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REBD);
-                       } else {
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                       }
-                       break;
-               case SS_RETRY:
-               case SS_TUR:
-                       if ((status & SS_ERRMASK) == EBUSY) {
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
-                               break;
-                       }
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       if (ahd_cmd_get_transaction_status(cmd)
-                        == CAM_REQUEUE_REQ) {
-                               targ->dv_state_retry--;
-                       } else if ((status & SSQ_FALLBACK) != 0) {
-                               if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
-                                       AHD_SET_DV_STATE(ahd, targ,
-                                                        AHD_DV_STATE_EXIT);
-                                       break;
-                               }
-                               /*
-                                * Do not count "falling back"
-                                * against our retries.
-                                */
-                               targ->dv_state_retry = 0;
-                       }
-                       if (targ->dv_state_retry >= 10) {
-#ifdef AHD_DEBUG
-                               if (ahd_debug & AHD_SHOW_DV) {
-                                       ahd_print_devinfo(ahd, devinfo);
-                                       printf("DV TUR reties exhausted\n");
-                               }
-#endif
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                               break;
-                       }
-                       if (status & SSQ_DELAY)
-                               ssleep(1);
-
-                       break;
-               case SS_START:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_SU);
-                       break;
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               default:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                       break;
-               }
-               break;
-
-       case AHD_DV_STATE_REBD:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-               {
-                       uint32_t echo_size;
-
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB);
-                       echo_size = scsi_3btoul(&targ->dv_buffer[1]);
-                       echo_size &= 0x1FFF;
-#ifdef AHD_DEBUG
-                       if (ahd_debug & AHD_SHOW_DV) {
-                               ahd_print_devinfo(ahd, devinfo);
-                               printf("Echo buffer size= %d\n", echo_size);
-                       }
-#endif
-                       if (echo_size == 0) {
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                               break;
-                       }
-
-                       /* Generate the buffer pattern */
-                       targ->dv_echo_size = echo_size;
-                       ahd_linux_generate_dv_pattern(targ);
-                       /*
-                        * Setup initial negotiation values.
-                        */
-                       ahd_linux_filter_inquiry(ahd, devinfo);
-                       break;
-               }
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               case SS_RETRY:
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       if (ahd_cmd_get_transaction_status(cmd)
-                        == CAM_REQUEUE_REQ)
-                               targ->dv_state_retry--;
-                       if (targ->dv_state_retry <= 10)
-                               break;
-#ifdef AHD_DEBUG
-                       if (ahd_debug & AHD_SHOW_DV) {
-                               ahd_print_devinfo(ahd, devinfo);
-                               printf("DV REBD reties exhausted\n");
-                       }
-#endif
-                       /* FALLTHROUGH */
-               case SS_FATAL:
-               default:
-                       /*
-                        * Setup initial negotiation values
-                        * and try level 1 DV.
-                        */
-                       ahd_linux_filter_inquiry(ahd, devinfo);
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_VERIFY);
-                       targ->dv_echo_size = 0;
-                       break;
-               }
-               break;
-
-       case AHD_DV_STATE_WEB:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REB);
-                       break;
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               case SS_RETRY:
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       if (ahd_cmd_get_transaction_status(cmd)
-                        == CAM_REQUEUE_REQ) {
-                               targ->dv_state_retry--;
-                       } else if ((status & SSQ_FALLBACK) != 0) {
-                               if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
-                                       AHD_SET_DV_STATE(ahd, targ,
-                                                        AHD_DV_STATE_EXIT);
-                                       break;
-                               }
-                               /*
-                                * Do not count "falling back"
-                                * against our retries.
-                                */
-                               targ->dv_state_retry = 0;
-                       }
-                       if (targ->dv_state_retry <= 10)
-                               break;
-                       /* FALLTHROUGH */
-#ifdef AHD_DEBUG
-                       if (ahd_debug & AHD_SHOW_DV) {
-                               ahd_print_devinfo(ahd, devinfo);
-                               printf("DV WEB reties exhausted\n");
-                       }
-#endif
-               default:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                       break;
-               }
-               break;
-
-       case AHD_DV_STATE_REB:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-                       if (memcmp(targ->dv_buffer, targ->dv_buffer1,
-                                  targ->dv_echo_size) != 0) {
-                               if (ahd_linux_dv_fallback(ahd, devinfo) != 0)
-                                       AHD_SET_DV_STATE(ahd, targ,
-                                                        AHD_DV_STATE_EXIT);
-                               else
-                                       AHD_SET_DV_STATE(ahd, targ,
-                                                        AHD_DV_STATE_WEB);
-                               break;
-                       }
-                       
-                       if (targ->dv_buffer != NULL) {
-                               free(targ->dv_buffer, M_DEVBUF);
-                               targ->dv_buffer = NULL;
-                       }
-                       if (targ->dv_buffer1 != NULL) {
-                               free(targ->dv_buffer1, M_DEVBUF);
-                               targ->dv_buffer1 = NULL;
-                       }
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                       break;
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               case SS_RETRY:
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       if (ahd_cmd_get_transaction_status(cmd)
-                        == CAM_REQUEUE_REQ) {
-                               targ->dv_state_retry--;
-                       } else if ((status & SSQ_FALLBACK) != 0) {
-                               if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
-                                       AHD_SET_DV_STATE(ahd, targ,
-                                                        AHD_DV_STATE_EXIT);
-                                       break;
-                               }
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB);
-                       }
-                       if (targ->dv_state_retry <= 10) {
-                               if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0)
-                                       msleep(ahd->our_id*1000/10);
-                               break;
-                       }
-#ifdef AHD_DEBUG
-                       if (ahd_debug & AHD_SHOW_DV) {
-                               ahd_print_devinfo(ahd, devinfo);
-                               printf("DV REB reties exhausted\n");
-                       }
-#endif
-                       /* FALLTHROUGH */
-               default:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                       break;
-               }
-               break;
+       while ((p = strsep(&s, ",.")) != NULL) {
+               if (*p == '\0')
+                       continue;
+               for (i = 0; i < NUM_ELEMENTS(options); i++) {
 
-       case AHD_DV_STATE_SU:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               default:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                       break;
+                       n = strlen(options[i].name);
+                       if (strncmp(options[i].name, p, n) == 0)
+                               break;
                }
-               break;
+               if (i == NUM_ELEMENTS(options))
+                       continue;
 
-       case AHD_DV_STATE_BUSY:
-               switch (status & SS_MASK) {
-               case SS_NOP:
-               case SS_INQ_REFRESH:
-                       AHD_SET_DV_STATE(ahd, targ,
-                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
-                       break;
-               case SS_TUR:
-               case SS_RETRY:
-                       AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
-                       if (ahd_cmd_get_transaction_status(cmd)
-                        == CAM_REQUEUE_REQ) {
-                               targ->dv_state_retry--;
-                       } else if (targ->dv_state_retry < 60) {
-                               if ((status & SSQ_DELAY) != 0)
-                                       ssleep(1);
-                       } else {
-#ifdef AHD_DEBUG
-                               if (ahd_debug & AHD_SHOW_DV) {
-                                       ahd_print_devinfo(ahd, devinfo);
-                                       printf("DV BUSY reties exhausted\n");
-                               }
-#endif
-                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                       }
-                       break;
-               default:
-                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-                       break;
+               if (strncmp(p, "global_tag_depth", n) == 0) {
+                       ahd_linux_setup_tag_info_global(p + n);
+               } else if (strncmp(p, "tag_info", n) == 0) {
+                       s = aic_parse_brace_option("tag_info", p + n, end,
+                           2, ahd_linux_setup_tag_info, 0);
+               } else if (strncmp(p, "slewrate", n) == 0) {
+                       s = aic_parse_brace_option("slewrate",
+                           p + n, end, 1, ahd_linux_setup_iocell_info,
+                           AIC79XX_SLEWRATE_INDEX);
+               } else if (strncmp(p, "precomp", n) == 0) {
+                       s = aic_parse_brace_option("precomp",
+                           p + n, end, 1, ahd_linux_setup_iocell_info,
+                           AIC79XX_PRECOMP_INDEX);
+               } else if (strncmp(p, "amplitude", n) == 0) {
+                       s = aic_parse_brace_option("amplitude",
+                           p + n, end, 1, ahd_linux_setup_iocell_info,
+                           AIC79XX_AMPLITUDE_INDEX);
+               } else if (p[n] == ':') {
+                       *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
+               } else if (!strncmp(p, "verbose", n)) {
+                       *(options[i].flag) = 1;
+               } else {
+                       *(options[i].flag) ^= 0xFFFFFFFF;
                }
-               break;
-
-       default:
-               printf("%s: Invalid DV completion state %d\n", ahd_name(ahd),
-                      targ->dv_state);
-               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
-               break;
        }
+       return 1;
 }
 
-static void
-ahd_linux_dv_fill_cmd(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
-                     struct ahd_devinfo *devinfo)
-{
-       memset(cmd, 0, sizeof(struct scsi_cmnd));
-       cmd->device = ahd->platform_data->dv_scsi_dev;
-       cmd->scsi_done = ahd_linux_dv_complete;
-}
+__setup("aic79xx=", aic79xx_setup);
 
-/*
- * Synthesize an inquiry command.  On the return trip, it'll be
- * sniffed and the device transfer settings set for us.
- */
-static void
-ahd_linux_dv_inq(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
-                struct ahd_devinfo *devinfo, struct ahd_linux_target *targ,
-                u_int request_length)
+uint32_t aic79xx_verbose;
+
+int
+ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template)
 {
+       char    buf[80];
+       struct  Scsi_Host *host;
+       char    *new_name;
+       u_long  s;
 
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, devinfo);
-               printf("Sending INQ\n");
-       }
-#endif
-       if (targ->inq_data == NULL)
-               targ->inq_data = malloc(AHD_LINUX_DV_INQ_LEN,
-                                       M_DEVBUF, M_WAITOK);
-       if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC) {
-               if (targ->dv_buffer != NULL)
-                       free(targ->dv_buffer, M_DEVBUF);
-               targ->dv_buffer = malloc(AHD_LINUX_DV_INQ_LEN,
-                                        M_DEVBUF, M_WAITOK);
+       template->name = ahd->description;
+       host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
+       if (host == NULL)
+               return (ENOMEM);
+
+       *((struct ahd_softc **)host->hostdata) = ahd;
+       ahd_lock(ahd, &s);
+       scsi_assign_lock(host, &ahd->platform_data->spin_lock);
+       ahd->platform_data->host = host;
+       host->can_queue = AHD_MAX_QUEUE;
+       host->cmd_per_lun = 2;
+       host->sg_tablesize = AHD_NSEG;
+       host->this_id = ahd->our_id;
+       host->irq = ahd->platform_data->irq;
+       host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
+       host->max_lun = AHD_NUM_LUNS;
+       host->max_channel = 0;
+       host->sg_tablesize = AHD_NSEG;
+       ahd_set_unit(ahd, ahd_linux_unit++);
+       sprintf(buf, "scsi%d", host->host_no);
+       new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
+       if (new_name != NULL) {
+               strcpy(new_name, buf);
+               ahd_set_name(ahd, new_name);
        }
+       host->unique_id = ahd->unit;
+       ahd_linux_initialize_scsi_bus(ahd);
+       ahd_intr_enable(ahd, TRUE);
+       ahd_unlock(ahd, &s);
 
-       ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
-       cmd->sc_data_direction = DMA_FROM_DEVICE;
-       cmd->cmd_len = 6;
-       cmd->cmnd[0] = INQUIRY;
-       cmd->cmnd[4] = request_length;
-       cmd->request_bufflen = request_length;
-       if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC)
-               cmd->request_buffer = targ->dv_buffer;
-       else
-               cmd->request_buffer = targ->inq_data;
-       memset(cmd->request_buffer, 0, AHD_LINUX_DV_INQ_LEN);
+       host->transportt = ahd_linux_transport_template;
+
+       scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */
+       scsi_scan_host(host);
+       return (0);
 }
 
-static void
-ahd_linux_dv_tur(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
-                struct ahd_devinfo *devinfo)
+uint64_t
+ahd_linux_get_memsize(void)
 {
+       struct sysinfo si;
 
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, devinfo);
-               printf("Sending TUR\n");
-       }
-#endif
-       /* Do a TUR to clear out any non-fatal transitional state */
-       ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
-       cmd->sc_data_direction = DMA_NONE;
-       cmd->cmd_len = 6;
-       cmd->cmnd[0] = TEST_UNIT_READY;
+       si_meminfo(&si);
+       return ((uint64_t)si.totalram << PAGE_SHIFT);
 }
 
-#define AHD_REBD_LEN 4
-
+/*
+ * Place the SCSI bus into a known state by either resetting it,
+ * or forcing transfer negotiations on the next command to any
+ * target.
+ */
 static void
-ahd_linux_dv_rebd(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
-                struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
+ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
 {
+       u_int target_id;
+       u_int numtarg;
 
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, devinfo);
-               printf("Sending REBD\n");
-       }
-#endif
-       if (targ->dv_buffer != NULL)
-               free(targ->dv_buffer, M_DEVBUF);
-       targ->dv_buffer = malloc(AHD_REBD_LEN, M_DEVBUF, M_WAITOK);
-       ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
-       cmd->sc_data_direction = DMA_FROM_DEVICE;
-       cmd->cmd_len = 10;
-       cmd->cmnd[0] = READ_BUFFER;
-       cmd->cmnd[1] = 0x0b;
-       scsi_ulto3b(AHD_REBD_LEN, &cmd->cmnd[6]);
-       cmd->request_bufflen = AHD_REBD_LEN;
-       cmd->underflow = cmd->request_bufflen;
-       cmd->request_buffer = targ->dv_buffer;
-}
+       target_id = 0;
+       numtarg = 0;
 
-static void
-ahd_linux_dv_web(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
-                struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
-{
+       if (aic79xx_no_reset != 0)
+               ahd->flags &= ~AHD_RESET_BUS_A;
 
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, devinfo);
-               printf("Sending WEB\n");
-       }
-#endif
-       ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
-       cmd->sc_data_direction = DMA_TO_DEVICE;
-       cmd->cmd_len = 10;
-       cmd->cmnd[0] = WRITE_BUFFER;
-       cmd->cmnd[1] = 0x0a;
-       scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
-       cmd->request_bufflen = targ->dv_echo_size;
-       cmd->underflow = cmd->request_bufflen;
-       cmd->request_buffer = targ->dv_buffer;
-}
+       if ((ahd->flags & AHD_RESET_BUS_A) != 0)
+               ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
+       else
+               numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
 
-static void
-ahd_linux_dv_reb(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
-                struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
-{
+       /*
+        * Force negotiation to async for all targets that
+        * will not see an initial bus reset.
+        */
+       for (; target_id < numtarg; target_id++) {
+               struct ahd_devinfo devinfo;
+               struct ahd_initiator_tinfo *tinfo;
+               struct ahd_tmode_tstate *tstate;
 
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, devinfo);
-               printf("Sending REB\n");
+               tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
+                                           target_id, &tstate);
+               ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
+                                   CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
+               ahd_update_neg_request(ahd, &devinfo, tstate,
+                                      tinfo, AHD_NEG_ALWAYS);
+       }
+       /* Give the bus some time to recover */
+       if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
+               ahd_freeze_simq(ahd);
+               init_timer(&ahd->platform_data->reset_timer);
+               ahd->platform_data->reset_timer.data = (u_long)ahd;
+               ahd->platform_data->reset_timer.expires =
+                   jiffies + (AIC79XX_RESET_DELAY * HZ)/1000;
+               ahd->platform_data->reset_timer.function =
+                   (ahd_linux_callback_t *)ahd_release_simq;
+               add_timer(&ahd->platform_data->reset_timer);
        }
-#endif
-       ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
-       cmd->sc_data_direction = DMA_FROM_DEVICE;
-       cmd->cmd_len = 10;
-       cmd->cmnd[0] = READ_BUFFER;
-       cmd->cmnd[1] = 0x0a;
-       scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
-       cmd->request_bufflen = targ->dv_echo_size;
-       cmd->underflow = cmd->request_bufflen;
-       cmd->request_buffer = targ->dv_buffer1;
 }
 
-static void
-ahd_linux_dv_su(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
-               struct ahd_devinfo *devinfo,
-               struct ahd_linux_target *targ)
+int
+ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
 {
-       u_int le;
-
-       le = SID_IS_REMOVABLE(targ->inq_data) ? SSS_LOEJ : 0;
-
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, devinfo);
-               printf("Sending SU\n");
-       }
-#endif
-       ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
-       cmd->sc_data_direction = DMA_NONE;
-       cmd->cmd_len = 6;
-       cmd->cmnd[0] = START_STOP_UNIT;
-       cmd->cmnd[4] = le | SSS_START;
+       ahd->platform_data =
+           malloc(sizeof(struct ahd_platform_data), M_DEVBUF, M_NOWAIT);
+       if (ahd->platform_data == NULL)
+               return (ENOMEM);
+       memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
+       ahd->platform_data->irq = AHD_LINUX_NOIRQ;
+       ahd_lockinit(ahd);
+       init_MUTEX_LOCKED(&ahd->platform_data->eh_sem);
+       ahd->seltime = (aic79xx_seltime & 0x3) << 4;
+       return (0);
 }
 
-static int
-ahd_linux_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+void
+ahd_platform_free(struct ahd_softc *ahd)
 {
-       struct  ahd_linux_target *targ;
-       struct  ahd_initiator_tinfo *tinfo;
-       struct  ahd_transinfo *goal;
-       struct  ahd_tmode_tstate *tstate;
-       u_int   width;
-       u_int   period;
-       u_int   offset;
-       u_int   ppr_options;
-       u_int   cur_speed;
-       u_int   wide_speed;
-       u_int   narrow_speed;
-       u_int   fallback_speed;
-
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               ahd_print_devinfo(ahd, devinfo);
-               printf("Trying to fallback\n");
-       }
-#endif
-       targ = ahd->platform_data->targets[devinfo->target_offset];
-       tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
-                                   devinfo->our_scsiid,
-                                   devinfo->target, &tstate);
-       goal = &tinfo->goal;
-       width = goal->width;
-       period = goal->period;
-       offset = goal->offset;
-       ppr_options = goal->ppr_options;
-       if (offset == 0)
-               period = AHD_ASYNC_XFER_PERIOD;
-       if (targ->dv_next_narrow_period == 0)
-               targ->dv_next_narrow_period = MAX(period, AHD_SYNCRATE_ULTRA2);
-       if (targ->dv_next_wide_period == 0)
-               targ->dv_next_wide_period = period;
-       if (targ->dv_max_width == 0)
-               targ->dv_max_width = width;
-       if (targ->dv_max_ppr_options == 0)
-               targ->dv_max_ppr_options = ppr_options;
-       if (targ->dv_last_ppr_options == 0)
-               targ->dv_last_ppr_options = ppr_options;
-
-       cur_speed = aic_calc_speed(width, period, offset, AHD_SYNCRATE_MIN);
-       wide_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_16_BIT,
-                                         targ->dv_next_wide_period,
-                                         MAX_OFFSET, AHD_SYNCRATE_MIN);
-       narrow_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_8_BIT,
-                                           targ->dv_next_narrow_period,
-                                           MAX_OFFSET, AHD_SYNCRATE_MIN);
-       fallback_speed = aic_calc_speed(width, period+1, offset,
-                                             AHD_SYNCRATE_MIN);
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, "
-                      "fallback_speed= %d\n", cur_speed, wide_speed,
-                      narrow_speed, fallback_speed);
-       }
-#endif
+       struct scsi_target *starget;
+       int i, j;
 
-       if (cur_speed > 160000) {
-               /*
-                * Paced/DT/IU_REQ only transfer speeds.  All we
-                * can do is fallback in terms of syncrate.
-                */
-               period++;
-       } else if (cur_speed > 80000) {
-               if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
-                       /*
-                        * Try without IU_REQ as it may be confusing
-                        * an expander.
-                        */
-                       ppr_options &= ~MSG_EXT_PPR_IU_REQ;
-               } else {
-                       /*
-                        * Paced/DT only transfer speeds.  All we
-                        * can do is fallback in terms of syncrate.
-                        */
-                       period++;
-                       ppr_options = targ->dv_max_ppr_options;
+       if (ahd->platform_data != NULL) {
+               if (ahd->platform_data->host != NULL) {
+                       scsi_remove_host(ahd->platform_data->host);
+                       scsi_host_put(ahd->platform_data->host);
                }
-       } else if (cur_speed > 3300) {
-
-               /*
-                * In this range we the following
-                * options ordered from highest to
-                * lowest desireability:
-                *
-                * o Wide/DT
-                * o Wide/non-DT
-                * o Narrow at a potentally higher sync rate.
-                *
-                * All modes are tested with and without IU_REQ
-                * set since using IUs may confuse an expander.
-                */
-               if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
 
-                       ppr_options &= ~MSG_EXT_PPR_IU_REQ;
-               } else if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
-                       /*
-                        * Try going non-DT.
-                        */
-                       ppr_options = targ->dv_max_ppr_options;
-                       ppr_options &= ~MSG_EXT_PPR_DT_REQ;
-               } else if (targ->dv_last_ppr_options != 0) {
-                       /*
-                        * Try without QAS or any other PPR options.
-                        * We may need a non-PPR message to work with
-                        * an expander.  We look at the "last PPR options"
-                        * so we will perform this fallback even if the
-                        * target responded to our PPR negotiation with
-                        * no option bits set.
-                        */
-                       ppr_options = 0;
-               } else if (width == MSG_EXT_WDTR_BUS_16_BIT) {
-                       /*
-                        * If the next narrow speed is greater than
-                        * the next wide speed, fallback to narrow.
-                        * Otherwise fallback to the next DT/Wide setting.
-                        * The narrow async speed will always be smaller
-                        * than the wide async speed, so handle this case
-                        * specifically.
-                        */
-                       ppr_options = targ->dv_max_ppr_options;
-                       if (narrow_speed > fallback_speed
-                        || period >= AHD_ASYNC_XFER_PERIOD) {
-                               targ->dv_next_wide_period = period+1;
-                               width = MSG_EXT_WDTR_BUS_8_BIT;
-                               period = targ->dv_next_narrow_period;
-                       } else {
-                               period++;
+               /* destroy all of the device and target objects */
+               for (i = 0; i < AHD_NUM_TARGETS; i++) {
+                       starget = ahd->platform_data->starget[i];
+                       if (starget != NULL) {
+                               for (j = 0; j < AHD_NUM_LUNS; j++) {
+                                       struct ahd_linux_target *targ =
+                                               scsi_transport_target_data(starget);
+                                       if (targ->sdev[j] == NULL)
+                                               continue;
+                                       targ->sdev[j] = NULL;
+                               }
+                               ahd->platform_data->starget[i] = NULL;
                        }
-               } else if ((ahd->features & AHD_WIDE) != 0
-                       && targ->dv_max_width != 0
-                       && wide_speed >= fallback_speed
-                       && (targ->dv_next_wide_period <= AHD_ASYNC_XFER_PERIOD
-                        || period >= AHD_ASYNC_XFER_PERIOD)) {
+               }
 
-                       /*
-                        * We are narrow.  Try falling back
-                        * to the next wide speed with 
-                        * all supported ppr options set.
-                        */
-                       targ->dv_next_narrow_period = period+1;
-                       width = MSG_EXT_WDTR_BUS_16_BIT;
-                       period = targ->dv_next_wide_period;
-                       ppr_options = targ->dv_max_ppr_options;
-               } else {
-                       /* Only narrow fallback is allowed. */
-                       period++;
-                       ppr_options = targ->dv_max_ppr_options;
+               if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
+                       free_irq(ahd->platform_data->irq, ahd);
+               if (ahd->tags[0] == BUS_SPACE_PIO
+                && ahd->bshs[0].ioport != 0)
+                       release_region(ahd->bshs[0].ioport, 256);
+               if (ahd->tags[1] == BUS_SPACE_PIO
+                && ahd->bshs[1].ioport != 0)
+                       release_region(ahd->bshs[1].ioport, 256);
+               if (ahd->tags[0] == BUS_SPACE_MEMIO
+                && ahd->bshs[0].maddr != NULL) {
+                       iounmap(ahd->bshs[0].maddr);
+                       release_mem_region(ahd->platform_data->mem_busaddr,
+                                          0x1000);
                }
-       } else {
-               return (-1);
-       }
-       offset = MAX_OFFSET;
-       ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_PACED);
-       ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, FALSE);
-       if (period == 0) {
-               period = 0;
-               offset = 0;
-               ppr_options = 0;
-               if (width == MSG_EXT_WDTR_BUS_8_BIT)
-                       targ->dv_next_narrow_period = AHD_ASYNC_XFER_PERIOD;
-               else
-                       targ->dv_next_wide_period = AHD_ASYNC_XFER_PERIOD;
+               free(ahd->platform_data, M_DEVBUF);
        }
-       ahd_set_syncrate(ahd, devinfo, period, offset,
-                        ppr_options, AHD_TRANS_GOAL, FALSE);
-       targ->dv_last_ppr_options = ppr_options;
-       return (0);
 }
 
-static void
-ahd_linux_dv_timeout(struct scsi_cmnd *cmd)
+void
+ahd_platform_init(struct ahd_softc *ahd)
 {
-       struct  ahd_softc *ahd;
-       struct  scb *scb;
-       u_long  flags;
-
-       ahd = *((struct ahd_softc **)cmd->device->host->hostdata);
-       ahd_lock(ahd, &flags);
-
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV) {
-               printf("%s: Timeout while doing DV command %x.\n",
-                      ahd_name(ahd), cmd->cmnd[0]);
-               ahd_dump_card_state(ahd);
-       }
-#endif
-       
        /*
-        * Guard against "done race".  No action is
-        * required if we just completed.
+        * Lookup and commit any modified IO Cell options.
         */
-       if ((scb = (struct scb *)cmd->host_scribble) == NULL) {
-               ahd_unlock(ahd, &flags);
-               return;
+       if (ahd->unit < NUM_ELEMENTS(aic79xx_iocell_info)) {
+               struct ahd_linux_iocell_opts *iocell_opts;
+
+               iocell_opts = &aic79xx_iocell_info[ahd->unit];
+               if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
+                       AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
+               if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
+                       AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
+               if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
+                       AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
        }
 
-       /*
-        * Command has not completed.  Mark this
-        * SCB as having failing status prior to
-        * resetting the bus, so we get the correct
-        * error code.
-        */
-       if ((scb->flags & SCB_SENSE) != 0)
-               ahd_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
-       else
-               ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
-       ahd_reset_channel(ahd, cmd->device->channel + 'A', /*initiate*/TRUE);
+}
 
-       /*
-        * Add a minimal bus settle delay for devices that are slow to
-        * respond after bus resets.
-        */
-       ahd_freeze_simq(ahd);
-       init_timer(&ahd->platform_data->reset_timer);
-       ahd->platform_data->reset_timer.data = (u_long)ahd;
-       ahd->platform_data->reset_timer.expires = jiffies + HZ / 2;
-       ahd->platform_data->reset_timer.function =
-           (ahd_linux_callback_t *)ahd_release_simq;
-       add_timer(&ahd->platform_data->reset_timer);
-       if (ahd_linux_next_device_to_run(ahd) != NULL)
-               ahd_schedule_runq(ahd);
-       ahd_linux_run_complete_queue(ahd);
-       ahd_unlock(ahd, &flags);
+void
+ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
+{
+       ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
+                               SCB_GET_CHANNEL(ahd, scb),
+                               SCB_GET_LUN(scb), SCB_LIST_NULL,
+                               ROLE_UNKNOWN, CAM_REQUEUE_REQ);
 }
 
-static void
-ahd_linux_dv_complete(struct scsi_cmnd *cmd)
+void
+ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+                     ahd_queue_alg alg)
 {
-       struct ahd_softc *ahd;
+       struct scsi_target *starget;
+       struct ahd_linux_target *targ;
+       struct ahd_linux_device *dev;
+       struct scsi_device *sdev;
+       int was_queuing;
+       int now_queuing;
 
-       ahd = *((struct ahd_softc **)cmd->device->host->hostdata);
+       starget = ahd->platform_data->starget[devinfo->target];
+       targ = scsi_transport_target_data(starget);
+       BUG_ON(targ == NULL);
+       sdev = targ->sdev[devinfo->lun];
+       if (sdev == NULL)
+               return;
 
-       /* Delete the DV timer before it goes off! */
-       scsi_delete_timer(cmd);
+       dev = scsi_transport_device_data(sdev);
 
-#ifdef AHD_DEBUG
-       if (ahd_debug & AHD_SHOW_DV)
-               printf("%s:%c:%d: Command completed, status= 0x%x\n",
-                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
-                      cmd->result);
-#endif
+       if (dev == NULL)
+               return;
+       was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
+       switch (alg) {
+       default:
+       case AHD_QUEUE_NONE:
+               now_queuing = 0;
+               break; 
+       case AHD_QUEUE_BASIC:
+               now_queuing = AHD_DEV_Q_BASIC;
+               break;
+       case AHD_QUEUE_TAGGED:
+               now_queuing = AHD_DEV_Q_TAGGED;
+               break;
+       }
+       if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
+        && (was_queuing != now_queuing)
+        && (dev->active != 0)) {
+               dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
+               dev->qfrozen++;
+       }
 
-       /* Wake up the state machine */
-       up(&ahd->platform_data->dv_cmd_sem);
-}
+       dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
+       if (now_queuing) {
+               u_int usertags;
 
-static void
-ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ)
-{
-       uint16_t b;
-       u_int    i;
-       u_int    j;
-
-       if (targ->dv_buffer != NULL)
-               free(targ->dv_buffer, M_DEVBUF);
-       targ->dv_buffer = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK);
-       if (targ->dv_buffer1 != NULL)
-               free(targ->dv_buffer1, M_DEVBUF);
-       targ->dv_buffer1 = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK);
-
-       i = 0;
-
-       b = 0x0001;
-       for (j = 0 ; i < targ->dv_echo_size; j++) {
-               if (j < 32) {
-                       /*
-                        * 32bytes of sequential numbers.
-                        */
-                       targ->dv_buffer[i++] = j & 0xff;
-               } else if (j < 48) {
-                       /*
-                        * 32bytes of repeating 0x0000, 0xffff.
-                        */
-                       targ->dv_buffer[i++] = (j & 0x02) ? 0xff : 0x00;
-               } else if (j < 64) {
+               usertags = ahd_linux_user_tagdepth(ahd, devinfo);
+               if (!was_queuing) {
                        /*
-                        * 32bytes of repeating 0x5555, 0xaaaa.
+                        * Start out agressively and allow our
+                        * dynamic queue depth algorithm to take
+                        * care of the rest.
                         */
-                       targ->dv_buffer[i++] = (j & 0x02) ? 0xaa : 0x55;
-               } else {
+                       dev->maxtags = usertags;
+                       dev->openings = dev->maxtags - dev->active;
+               }
+               if (dev->maxtags == 0) {
                        /*
-                        * Remaining buffer is filled with a repeating
-                        * patter of:
-                        *
-                        *       0xffff
-                        *      ~0x0001 << shifted once in each loop.
+                        * Queueing is disabled by the user.
                         */
-                       if (j & 0x02) {
-                               if (j & 0x01) {
-                                       targ->dv_buffer[i++] = ~(b >> 8) & 0xff;
-                                       b <<= 1;
-                                       if (b == 0x0000)
-                                               b = 0x0001;
-                               } else {
-                                       targ->dv_buffer[i++] = (~b & 0xff);
-                               }
-                       } else {
-                               targ->dv_buffer[i++] = 0xff;
-                       }
-               }
+                       dev->openings = 1;
+               } else if (alg == AHD_QUEUE_TAGGED) {
+                       dev->flags |= AHD_DEV_Q_TAGGED;
+                       if (aic79xx_periodic_otag != 0)
+                               dev->flags |= AHD_DEV_PERIODIC_OTAG;
+               } else
+                       dev->flags |= AHD_DEV_Q_BASIC;
+       } else {
+               /* We can only have one opening. */
+               dev->maxtags = 0;
+               dev->openings =  1 - dev->active;
+       }
+
+       switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
+       case AHD_DEV_Q_BASIC:
+               scsi_adjust_queue_depth(sdev,
+                                       MSG_SIMPLE_TASK,
+                                       dev->openings + dev->active);
+               break;
+       case AHD_DEV_Q_TAGGED:
+               scsi_adjust_queue_depth(sdev,
+                                       MSG_ORDERED_TASK,
+                                       dev->openings + dev->active);
+               break;
+       default:
+               /*
+                * We allow the OS to queue 2 untagged transactions to
+                * us at any time even though we can only execute them
+                * serially on the controller/device.  This should
+                * remove some latency.
+                */
+               scsi_adjust_queue_depth(sdev,
+                                       /*NON-TAGGED*/0,
+                                       /*queue depth*/2);
+               break;
        }
 }
 
+int
+ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
+                       int lun, u_int tag, role_t role, uint32_t status)
+{
+       return 0;
+}
+
 static u_int
 ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
 {
@@ -3800,100 +1323,23 @@ ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
        return (tags);
 }
 
-static u_int
-ahd_linux_user_dv_setting(struct ahd_softc *ahd)
-{
-       static int warned_user;
-       int dv;
-
-       if (ahd->unit >= NUM_ELEMENTS(aic79xx_dv_settings)) {
-
-               if (warned_user == 0) {
-                       printf(KERN_WARNING
-"aic79xx: WARNING: Insufficient dv settings instances\n"
-"aic79xx: for installed controllers. Using defaults\n"
-"aic79xx: Please update the aic79xx_dv_settings array in"
-"aic79xx: the aic79xx_osm.c source file.\n");
-                       warned_user++;
-               }
-               dv = -1;
-       } else {
-
-               dv = aic79xx_dv_settings[ahd->unit];
-       }
-
-       if (dv < 0) {
-               /*
-                * Apply the default.
-                */
-               dv = 1;
-               if (ahd->seep_config != 0)
-                       dv = (ahd->seep_config->bios_control & CFENABLEDV);
-       }
-       return (dv);
-}
-
-static void
-ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd)
-{
-       static  int warned_user;
-       u_int   rd_strm_mask;
-       u_int   target_id;
-
-       /*
-        * If we have specific read streaming info for this controller,
-        * apply it.  Otherwise use the defaults.
-        */
-        if (ahd->unit >= NUM_ELEMENTS(aic79xx_rd_strm_info)) {
-
-               if (warned_user == 0) {
-
-                       printf(KERN_WARNING
-"aic79xx: WARNING: Insufficient rd_strm instances\n"
-"aic79xx: for installed controllers. Using defaults\n"
-"aic79xx: Please update the aic79xx_rd_strm_info array\n"
-"aic79xx: in the aic79xx_osm.c source file.\n");
-                       warned_user++;
-               }
-               rd_strm_mask = AIC79XX_CONFIGED_RD_STRM;
-       } else {
-
-               rd_strm_mask = aic79xx_rd_strm_info[ahd->unit];
-       }
-       for (target_id = 0; target_id < 16; target_id++) {
-               struct ahd_devinfo devinfo;
-               struct ahd_initiator_tinfo *tinfo;
-               struct ahd_tmode_tstate *tstate;
-
-               tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
-                                           target_id, &tstate);
-               ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
-                                   CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
-               tinfo->user.ppr_options &= ~MSG_EXT_PPR_RD_STRM;
-               if ((rd_strm_mask & devinfo.target_mask) != 0)
-                       tinfo->user.ppr_options |= MSG_EXT_PPR_RD_STRM;
-       }
-}
-
 /*
  * Determines the queue depth for a given device.
  */
 static void
-ahd_linux_device_queue_depth(struct ahd_softc *ahd,
-                            struct ahd_linux_device *dev)
+ahd_linux_device_queue_depth(struct scsi_device *sdev)
 {
        struct  ahd_devinfo devinfo;
        u_int   tags;
+       struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata);
 
        ahd_compile_devinfo(&devinfo,
                            ahd->our_id,
-                           dev->target->target, dev->lun,
-                           dev->target->channel == 0 ? 'A' : 'B',
+                           sdev->sdev_target->id, sdev->lun,
+                           sdev->sdev_target->channel == 0 ? 'A' : 'B',
                            ROLE_INITIATOR);
        tags = ahd_linux_user_tagdepth(ahd, &devinfo);
-       if (tags != 0
-        && dev->scsi_device != NULL
-        && dev->scsi_device->tagged_supported != 0) {
+       if (tags != 0 && sdev->tagged_supported != 0) {
 
                ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED);
                ahd_print_devinfo(ahd, &devinfo);
@@ -3903,11 +1349,10 @@ ahd_linux_device_queue_depth(struct ahd_softc *ahd,
        }
 }
 
-static void
-ahd_linux_run_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev)
+static int
+ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
+                     struct scsi_cmnd *cmd)
 {
-       struct   ahd_cmd *acmd;
-       struct   scsi_cmnd *cmd;
        struct   scb *scb;
        struct   hardware_scb *hscb;
        struct   ahd_initiator_tinfo *tinfo;
@@ -3915,157 +1360,122 @@ ahd_linux_run_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev)
        u_int    col_idx;
        uint16_t mask;
 
-       if ((dev->flags & AHD_DEV_ON_RUN_LIST) != 0)
-               panic("running device on run list");
-
-       while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL
-           && dev->openings > 0 && dev->qfrozen == 0) {
-
-               /*
-                * Schedule us to run later.  The only reason we are not
-                * running is because the whole controller Q is frozen.
-                */
-               if (ahd->platform_data->qfrozen != 0
-                && AHD_DV_SIMQ_FROZEN(ahd) == 0) {
-
-                       TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq,
-                                         dev, links);
-                       dev->flags |= AHD_DEV_ON_RUN_LIST;
-                       return;
-               }
-
-               cmd = &acmd_scsi_cmd(acmd);
+       /*
+        * Get an scb to use.
+        */
+       tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
+                                   cmd->device->id, &tstate);
+       if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
+        || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
+               col_idx = AHD_NEVER_COL_IDX;
+       } else {
+               col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
+                                           cmd->device->lun);
+       }
+       if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
+               ahd->flags |= AHD_RESOURCE_SHORTAGE;
+               return SCSI_MLQUEUE_HOST_BUSY;
+       }
 
-               /*
-                * Get an scb to use.
-                */
-               tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
-                                           cmd->device->id, &tstate);
-               if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
-                || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
-                       col_idx = AHD_NEVER_COL_IDX;
-               } else {
-                       col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
-                                                   cmd->device->lun);
-               }
-               if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
-                       TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq,
-                                        dev, links);
-                       dev->flags |= AHD_DEV_ON_RUN_LIST;
-                       ahd->flags |= AHD_RESOURCE_SHORTAGE;
-                       return;
-               }
-               TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe);
-               scb->io_ctx = cmd;
-               scb->platform_data->dev = dev;
-               hscb = scb->hscb;
-               cmd->host_scribble = (char *)scb;
+       scb->io_ctx = cmd;
+       scb->platform_data->dev = dev;
+       hscb = scb->hscb;
+       cmd->host_scribble = (char *)scb;
 
-               /*
-                * Fill out basics of the HSCB.
-                */
-               hscb->control = 0;
-               hscb->scsiid = BUILD_SCSIID(ahd, cmd);
-               hscb->lun = cmd->device->lun;
-               scb->hscb->task_management = 0;
-               mask = SCB_GET_TARGET_MASK(ahd, scb);
+       /*
+        * Fill out basics of the HSCB.
+        */
+       hscb->control = 0;
+       hscb->scsiid = BUILD_SCSIID(ahd, cmd);
+       hscb->lun = cmd->device->lun;
+       scb->hscb->task_management = 0;
+       mask = SCB_GET_TARGET_MASK(ahd, scb);
 
-               if ((ahd->user_discenable & mask) != 0)
-                       hscb->control |= DISCENB;
+       if ((ahd->user_discenable & mask) != 0)
+               hscb->control |= DISCENB;
 
-               if (AHD_DV_CMD(cmd) != 0)
-                       scb->flags |= SCB_SILENT;
+       if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
+               scb->flags |= SCB_PACKETIZED;
 
-               if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
-                       scb->flags |= SCB_PACKETIZED;
+       if ((tstate->auto_negotiate & mask) != 0) {
+               scb->flags |= SCB_AUTO_NEGOTIATE;
+               scb->hscb->control |= MK_MESSAGE;
+       }
 
-               if ((tstate->auto_negotiate & mask) != 0) {
-                       scb->flags |= SCB_AUTO_NEGOTIATE;
-                       scb->hscb->control |= MK_MESSAGE;
-               }
+       if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
+               int     msg_bytes;
+               uint8_t tag_msgs[2];
 
-               if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-                       int     msg_bytes;
-                       uint8_t tag_msgs[2];
-
-                       msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
-                       if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
-                               hscb->control |= tag_msgs[0];
-                               if (tag_msgs[0] == MSG_ORDERED_TASK)
-                                       dev->commands_since_idle_or_otag = 0;
-                       } else
-#endif
-                       if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
-                        && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
-                               hscb->control |= MSG_ORDERED_TASK;
+               msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
+               if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
+                       hscb->control |= tag_msgs[0];
+                       if (tag_msgs[0] == MSG_ORDERED_TASK)
                                dev->commands_since_idle_or_otag = 0;
-                       } else {
-                               hscb->control |= MSG_SIMPLE_TASK;
-                       }
+               } else
+               if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
+                && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
+                       hscb->control |= MSG_ORDERED_TASK;
+                       dev->commands_since_idle_or_otag = 0;
+               } else {
+                       hscb->control |= MSG_SIMPLE_TASK;
                }
+       }
 
-               hscb->cdb_len = cmd->cmd_len;
-               memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
-
-               scb->sg_count = 0;
-               ahd_set_residual(scb, 0);
-               ahd_set_sense_residual(scb, 0);
-               if (cmd->use_sg != 0) {
-                       void    *sg;
-                       struct   scatterlist *cur_seg;
-                       u_int    nseg;
-                       int      dir;
-
-                       cur_seg = (struct scatterlist *)cmd->request_buffer;
-                       dir = cmd->sc_data_direction;
-                       nseg = pci_map_sg(ahd->dev_softc, cur_seg,
-                                         cmd->use_sg, dir);
-                       scb->platform_data->xfer_len = 0;
-                       for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) {
-                               dma_addr_t addr;
-                               bus_size_t len;
-
-                               addr = sg_dma_address(cur_seg);
-                               len = sg_dma_len(cur_seg);
-                               scb->platform_data->xfer_len += len;
-                               sg = ahd_sg_setup(ahd, scb, sg, addr, len,
-                                                 /*last*/nseg == 1);
-                       }
-               } else if (cmd->request_bufflen != 0) {
-                       void *sg;
+       hscb->cdb_len = cmd->cmd_len;
+       memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
+
+       scb->platform_data->xfer_len = 0;
+       ahd_set_residual(scb, 0);
+       ahd_set_sense_residual(scb, 0);
+       scb->sg_count = 0;
+       if (cmd->use_sg != 0) {
+               void    *sg;
+               struct   scatterlist *cur_seg;
+               u_int    nseg;
+               int      dir;
+
+               cur_seg = (struct scatterlist *)cmd->request_buffer;
+               dir = cmd->sc_data_direction;
+               nseg = pci_map_sg(ahd->dev_softc, cur_seg,
+                                 cmd->use_sg, dir);
+               scb->platform_data->xfer_len = 0;
+               for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) {
                        dma_addr_t addr;
-                       int dir;
-
-                       sg = scb->sg_list;
-                       dir = cmd->sc_data_direction;
-                       addr = pci_map_single(ahd->dev_softc,
-                                             cmd->request_buffer,
-                                             cmd->request_bufflen, dir);
-                       scb->platform_data->xfer_len = cmd->request_bufflen;
-                       scb->platform_data->buf_busaddr = addr;
-                       sg = ahd_sg_setup(ahd, scb, sg, addr,
-                                         cmd->request_bufflen, /*last*/TRUE);
-               }
+                       bus_size_t len;
 
-               LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
-               dev->openings--;
-               dev->active++;
-               dev->commands_issued++;
-
-               /* Update the error counting bucket and dump if needed */
-               if (dev->target->cmds_since_error) {
-                       dev->target->cmds_since_error++;
-                       if (dev->target->cmds_since_error >
-                           AHD_LINUX_ERR_THRESH)
-                               dev->target->cmds_since_error = 0;
+                       addr = sg_dma_address(cur_seg);
+                       len = sg_dma_len(cur_seg);
+                       scb->platform_data->xfer_len += len;
+                       sg = ahd_sg_setup(ahd, scb, sg, addr, len,
+                                         /*last*/nseg == 1);
                }
+       } else if (cmd->request_bufflen != 0) {
+               void *sg;
+               dma_addr_t addr;
+               int dir;
 
-               if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
-                       dev->commands_since_idle_or_otag++;
-               scb->flags |= SCB_ACTIVE;
-               ahd_queue_scb(ahd, scb);
+               sg = scb->sg_list;
+               dir = cmd->sc_data_direction;
+               addr = pci_map_single(ahd->dev_softc,
+                                     cmd->request_buffer,
+                                     cmd->request_bufflen, dir);
+               scb->platform_data->xfer_len = cmd->request_bufflen;
+               scb->platform_data->buf_busaddr = addr;
+               sg = ahd_sg_setup(ahd, scb, sg, addr,
+                                 cmd->request_bufflen, /*last*/TRUE);
        }
+
+       LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
+       dev->openings--;
+       dev->active++;
+       dev->commands_issued++;
+
+       if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
+               dev->commands_since_idle_or_otag++;
+       scb->flags |= SCB_ACTIVE;
+       ahd_queue_scb(ahd, scb);
+
+       return 0;
 }
 
 /*
@@ -4081,9 +1491,6 @@ ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
        ahd = (struct ahd_softc *) dev_id;
        ahd_lock(ahd, &flags); 
        ours = ahd_intr(ahd);
-       if (ahd_linux_next_device_to_run(ahd) != NULL)
-               ahd_schedule_runq(ahd);
-       ahd_linux_run_complete_queue(ahd);
        ahd_unlock(ahd, &flags);
        return IRQ_RETVAL(ours);
 }
@@ -4092,111 +1499,6 @@ void
 ahd_platform_flushwork(struct ahd_softc *ahd)
 {
 
-       while (ahd_linux_run_complete_queue(ahd) != NULL)
-               ;
-}
-
-static struct ahd_linux_target*
-ahd_linux_alloc_target(struct ahd_softc *ahd, u_int channel, u_int target)
-{
-       struct ahd_linux_target *targ;
-
-       targ = malloc(sizeof(*targ), M_DEVBUF, M_NOWAIT);
-       if (targ == NULL)
-               return (NULL);
-       memset(targ, 0, sizeof(*targ));
-       targ->channel = channel;
-       targ->target = target;
-       targ->ahd = ahd;
-       targ->flags = AHD_DV_REQUIRED;
-       ahd->platform_data->targets[target] = targ;
-       return (targ);
-}
-
-static void
-ahd_linux_free_target(struct ahd_softc *ahd, struct ahd_linux_target *targ)
-{
-       struct ahd_devinfo devinfo;
-       struct ahd_initiator_tinfo *tinfo;
-       struct ahd_tmode_tstate *tstate;
-       u_int our_id;
-       u_int target_offset;
-       char channel;
-
-       /*
-        * Force a negotiation to async/narrow on any
-        * future command to this device unless a bus
-        * reset occurs between now and that command.
-        */
-       channel = 'A' + targ->channel;
-       our_id = ahd->our_id;
-       target_offset = targ->target;
-       tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
-                                   targ->target, &tstate);
-       ahd_compile_devinfo(&devinfo, our_id, targ->target, CAM_LUN_WILDCARD,
-                           channel, ROLE_INITIATOR);
-       ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
-                        AHD_TRANS_GOAL, /*paused*/FALSE);
-       ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
-                     AHD_TRANS_GOAL, /*paused*/FALSE);
-       ahd_update_neg_request(ahd, &devinfo, tstate, tinfo, AHD_NEG_ALWAYS);
-       ahd->platform_data->targets[target_offset] = NULL;
-       if (targ->inq_data != NULL)
-               free(targ->inq_data, M_DEVBUF);
-       if (targ->dv_buffer != NULL)
-               free(targ->dv_buffer, M_DEVBUF);
-       if (targ->dv_buffer1 != NULL)
-               free(targ->dv_buffer1, M_DEVBUF);
-       free(targ, M_DEVBUF);
-}
-
-static struct ahd_linux_device*
-ahd_linux_alloc_device(struct ahd_softc *ahd,
-                struct ahd_linux_target *targ, u_int lun)
-{
-       struct ahd_linux_device *dev;
-
-       dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
-       if (dev == NULL)
-               return (NULL);
-       memset(dev, 0, sizeof(*dev));
-       init_timer(&dev->timer);
-       TAILQ_INIT(&dev->busyq);
-       dev->flags = AHD_DEV_UNCONFIGURED;
-       dev->lun = lun;
-       dev->target = targ;
-
-       /*
-        * We start out life using untagged
-        * transactions of which we allow one.
-        */
-       dev->openings = 1;
-
-       /*
-        * Set maxtags to 0.  This will be changed if we
-        * later determine that we are dealing with
-        * a tagged queuing capable device.
-        */
-       dev->maxtags = 0;
-       
-       targ->refcount++;
-       targ->devices[lun] = dev;
-       return (dev);
-}
-
-static void
-ahd_linux_free_device(struct ahd_softc *ahd, struct ahd_linux_device *dev)
-{
-       struct ahd_linux_target *targ;
-
-       del_timer(&dev->timer);
-       targ = dev->target;
-       targ->devices[dev->lun] = NULL;
-       free(dev, M_DEVBUF);
-       targ->refcount--;
-       if (targ->refcount == 0
-        && (targ->flags & AHD_DV_REQUIRED) == 0)
-               ahd_linux_free_target(ahd, targ);
 }
 
 void
@@ -4207,10 +1509,14 @@ ahd_send_async(struct ahd_softc *ahd, char channel,
        case AC_TRANSFER_NEG:
        {
                char    buf[80];
+               struct  scsi_target *starget;
                struct  ahd_linux_target *targ;
                struct  info_str info;
                struct  ahd_initiator_tinfo *tinfo;
                struct  ahd_tmode_tstate *tstate;
+               unsigned int target_ppr_options;
+
+               BUG_ON(target == CAM_TARGET_WILDCARD);
 
                info.buffer = buf;
                info.length = sizeof(buf);
@@ -4234,58 +1540,47 @@ ahd_send_async(struct ahd_softc *ahd, char channel,
                 * Don't bother reporting results that
                 * are identical to those last reported.
                 */
-               targ = ahd->platform_data->targets[target];
-               if (targ == NULL)
+               starget = ahd->platform_data->starget[target];
+               if (starget == NULL)
                        break;
-               if (tinfo->curr.period == targ->last_tinfo.period
-                && tinfo->curr.width == targ->last_tinfo.width
-                && tinfo->curr.offset == targ->last_tinfo.offset
-                && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options)
+               targ = scsi_transport_target_data(starget);
+
+               target_ppr_options =
+                       (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
+                       + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
+                       + (spi_iu(starget) ?  MSG_EXT_PPR_IU_REQ : 0)
+                       + (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0)
+                       + (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0)
+                       + (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0)
+                       + (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0)
+                       + (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0);
+
+               if (tinfo->curr.period == spi_period(starget)
+                   && tinfo->curr.width == spi_width(starget)
+                   && tinfo->curr.offset == spi_offset(starget)
+                && tinfo->curr.ppr_options == target_ppr_options)
                        if (bootverbose == 0)
                                break;
 
-               targ->last_tinfo.period = tinfo->curr.period;
-               targ->last_tinfo.width = tinfo->curr.width;
-               targ->last_tinfo.offset = tinfo->curr.offset;
-               targ->last_tinfo.ppr_options = tinfo->curr.ppr_options;
-
-               printf("(%s:%c:", ahd_name(ahd), channel);
-               if (target == CAM_TARGET_WILDCARD)
-                       printf("*): ");
-               else
-                       printf("%d): ", target);
-               ahd_format_transinfo(&info, &tinfo->curr);
-               if (info.pos < info.length)
-                       *info.buffer = '\0';
-               else
-                       buf[info.length - 1] = '\0';
-               printf("%s", buf);
+               spi_period(starget) = tinfo->curr.period;
+               spi_width(starget) = tinfo->curr.width;
+               spi_offset(starget) = tinfo->curr.offset;
+               spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
+               spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
+               spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
+               spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0;
+               spi_pcomp_en(starget) =  tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0;
+               spi_rti(starget) =  tinfo->curr.ppr_options &  MSG_EXT_PPR_RTI ? 1 : 0;
+               spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0;
+               spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0;
+               spi_display_xfer_agreement(starget);
                break;
        }
         case AC_SENT_BDR:
        {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
                WARN_ON(lun != CAM_LUN_WILDCARD);
                scsi_report_device_reset(ahd->platform_data->host,
                                         channel - 'A', target);
-#else
-               Scsi_Device *scsi_dev;
-
-               /*
-                * Find the SCSI device associated with this
-                * request and indicate that a UA is expected.
-                */
-               for (scsi_dev = ahd->platform_data->host->host_queue;
-                    scsi_dev != NULL; scsi_dev = scsi_dev->next) {
-                       if (channel - 'A' == scsi_dev->channel
-                        && target == scsi_dev->id
-                        && (lun == CAM_LUN_WILDCARD
-                         || lun == scsi_dev->lun)) {
-                               scsi_dev->was_reset = 1;
-                               scsi_dev->expecting_cc_ua = 1;
-                       }
-               }
-#endif
                break;
        }
         case AC_BUS_RESET:
@@ -4305,7 +1600,7 @@ ahd_send_async(struct ahd_softc *ahd, char channel,
 void
 ahd_done(struct ahd_softc *ahd, struct scb *scb)
 {
-       Scsi_Cmnd *cmd;
+       struct scsi_cmnd *cmd;
        struct    ahd_linux_device *dev;
 
        if ((scb->flags & SCB_ACTIVE) == 0) {
@@ -4373,19 +1668,8 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb)
                        ahd_set_transaction_status(scb, CAM_REQ_CMP);
                }
        } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
-               ahd_linux_handle_scsi_status(ahd, dev, scb);
-       } else if (ahd_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
-               dev->flags |= AHD_DEV_UNCONFIGURED;
-               if (AHD_DV_CMD(cmd) == FALSE)
-                       dev->target->flags &= ~AHD_DV_REQUIRED;
+               ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
        }
-       /*
-        * Start DV for devices that require it assuming the first command
-        * sent does not result in a selection timeout.
-        */
-       if (ahd_get_transaction_status(scb) != CAM_SEL_TIMEOUT
-        && (dev->target->flags & AHD_DV_REQUIRED) != 0)
-               ahd_linux_start_dv(ahd);
 
        if (dev->openings == 1
         && ahd_get_transaction_status(scb) == CAM_REQ_CMP
@@ -4406,47 +1690,32 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb)
        if (dev->active == 0)
                dev->commands_since_idle_or_otag = 0;
 
-       if (TAILQ_EMPTY(&dev->busyq)) {
-               if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0
-                && dev->active == 0
-                && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0)
-                       ahd_linux_free_device(ahd, dev);
-       } else if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) {
-               TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links);
-               dev->flags |= AHD_DEV_ON_RUN_LIST;
-       }
-
        if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
                printf("Recovery SCB completes\n");
                if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
                 || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
                        ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
-               if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
-                       scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
+               if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
+                       ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
                        up(&ahd->platform_data->eh_sem);
                }
        }
 
        ahd_free_scb(ahd, scb);
        ahd_linux_queue_cmd_complete(ahd, cmd);
-
-       if ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_EMPTY) != 0
-        && LIST_FIRST(&ahd->pending_scbs) == NULL) {
-               ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_EMPTY;
-               up(&ahd->platform_data->dv_sem);
-       }
 }
 
 static void
 ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
-                            struct ahd_linux_device *dev, struct scb *scb)
+                            struct scsi_device *sdev, struct scb *scb)
 {
        struct  ahd_devinfo devinfo;
+       struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
 
        ahd_compile_devinfo(&devinfo,
                            ahd->our_id,
-                           dev->target->target, dev->lun,
-                           dev->target->channel == 0 ? 'A' : 'B',
+                           sdev->sdev_target->id, sdev->lun,
+                           sdev->sdev_target->channel == 0 ? 'A' : 'B',
                            ROLE_INITIATOR);
        
        /*
@@ -4465,7 +1734,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
        case SCSI_STATUS_CHECK_COND:
        case SCSI_STATUS_CMD_TERMINATED:
        {
-               Scsi_Cmnd *cmd;
+               struct scsi_cmnd *cmd;
 
                /*
                 * Copy sense information to the OS's cmd
@@ -4518,7 +1787,6 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
                break;
        }
        case SCSI_STATUS_QUEUE_FULL:
-       {
                /*
                 * By the time the core driver has returned this
                 * command, all other commands that were queued
@@ -4579,98 +1847,23 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
                             (dev->flags & AHD_DEV_Q_BASIC)
                           ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
                ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
-               /* FALLTHROUGH */
-       }
-       case SCSI_STATUS_BUSY:
-               /*
-                * Set a short timer to defer sending commands for
-                * a bit since Linux will not delay in this case.
-                */
-               if ((dev->flags & AHD_DEV_TIMER_ACTIVE) != 0) {
-                       printf("%s:%c:%d: Device Timer still active during "
-                              "busy processing\n", ahd_name(ahd),
-                               dev->target->channel, dev->target->target);
-                       break;
-               }
-               dev->flags |= AHD_DEV_TIMER_ACTIVE;
-               dev->qfrozen++;
-               init_timer(&dev->timer);
-               dev->timer.data = (u_long)dev;
-               dev->timer.expires = jiffies + (HZ/2);
-               dev->timer.function = ahd_linux_dev_timed_unfreeze;
-               add_timer(&dev->timer);
-               break;
        }
 }
 
 static void
-ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, Scsi_Cmnd *cmd)
+ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
 {
-       /*
-        * Typically, the complete queue has very few entries
-        * queued to it before the queue is emptied by
-        * ahd_linux_run_complete_queue, so sorting the entries
-        * by generation number should be inexpensive.
-        * We perform the sort so that commands that complete
-        * with an error are retuned in the order origionally
-        * queued to the controller so that any subsequent retries
-        * are performed in order.  The underlying ahd routines do
-        * not guarantee the order that aborted commands will be
-        * returned to us.
-        */
-       struct ahd_completeq *completeq;
-       struct ahd_cmd *list_cmd;
-       struct ahd_cmd *acmd;
-
        /*
         * Map CAM error codes into Linux Error codes.  We
         * avoid the conversion so that the DV code has the
         * full error information available when making
         * state change decisions.
         */
-       if (AHD_DV_CMD(cmd) == FALSE) {
+       {
                uint32_t status;
                u_int new_status;
 
                status = ahd_cmd_get_transaction_status(cmd);
-               if (status != CAM_REQ_CMP) {
-                       struct ahd_linux_device *dev;
-                       struct ahd_devinfo devinfo;
-                       cam_status cam_status;
-                       uint32_t action;
-                       u_int scsi_status;
-
-                       dev = ahd_linux_get_device(ahd, cmd->device->channel,
-                                                  cmd->device->id,
-                                                  cmd->device->lun,
-                                                  /*alloc*/FALSE);
-
-                       if (dev == NULL)
-                               goto no_fallback;
-
-                       ahd_compile_devinfo(&devinfo,
-                                           ahd->our_id,
-                                           dev->target->target, dev->lun,
-                                           dev->target->channel == 0 ? 'A':'B',
-                                           ROLE_INITIATOR);
-
-                       scsi_status = ahd_cmd_get_scsi_status(cmd);
-                       cam_status = ahd_cmd_get_transaction_status(cmd);
-                       action = aic_error_action(cmd, dev->target->inq_data,
-                                                 cam_status, scsi_status);
-                       if ((action & SSQ_FALLBACK) != 0) {
-
-                               /* Update stats */
-                               dev->target->errors_detected++;
-                               if (dev->target->cmds_since_error == 0)
-                                       dev->target->cmds_since_error++;
-                               else {
-                                       dev->target->cmds_since_error = 0;
-                                       ahd_linux_fallback(ahd, &devinfo);
-                               }
-                       }
-               }
-no_fallback:
                switch (status) {
                case CAM_REQ_INPROG:
                case CAM_REQ_CMP:
@@ -4715,26 +1908,7 @@ no_fallback:
                        new_status = DID_ERROR;
                        break;
                case CAM_REQUEUE_REQ:
-                       /*
-                        * If we want the request requeued, make sure there
-                        * are sufficent retries.  In the old scsi error code,
-                        * we used to be able to specify a result code that
-                        * bypassed the retry count.  Now we must use this
-                        * hack.  We also "fake" a check condition with
-                        * a sense code of ABORTED COMMAND.  This seems to
-                        * evoke a retry even if this command is being sent
-                        * via the eh thread.  Ick!  Ick!  Ick!
-                        */
-                       if (cmd->retries > 0)
-                               cmd->retries--;
-                       new_status = DID_OK;
-                       ahd_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
-                       cmd->result |= (DRIVER_SENSE << 24);
-                       memset(cmd->sense_buffer, 0,
-                              sizeof(cmd->sense_buffer));
-                       cmd->sense_buffer[0] = SSD_ERRCODE_VALID
-                                            | SSD_CURRENT_ERROR;
-                       cmd->sense_buffer[2] = SSD_KEY_ABORTED_COMMAND;
+                       new_status = DID_REQUEUE;
                        break;
                default:
                        /* We should never get here */
@@ -4745,272 +1919,798 @@ no_fallback:
                ahd_cmd_set_transaction_status(cmd, new_status);
        }
 
-       completeq = &ahd->platform_data->completeq;
-       list_cmd = TAILQ_FIRST(completeq);
-       acmd = (struct ahd_cmd *)cmd;
-       while (list_cmd != NULL
-           && acmd_scsi_cmd(list_cmd).serial_number
-            < acmd_scsi_cmd(acmd).serial_number)
-               list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
-       if (list_cmd != NULL)
-               TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
-       else
-               TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
+       cmd->scsi_done(cmd);
+}
+
+static void
+ahd_linux_sem_timeout(u_long arg)
+{
+       struct  ahd_softc *ahd;
+       u_long  s;
+
+       ahd = (struct ahd_softc *)arg;
+
+       ahd_lock(ahd, &s);
+       if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
+               ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
+               up(&ahd->platform_data->eh_sem);
+       }
+       ahd_unlock(ahd, &s);
+}
+
+void
+ahd_freeze_simq(struct ahd_softc *ahd)
+{
+       ahd->platform_data->qfrozen++;
+       if (ahd->platform_data->qfrozen == 1) {
+               scsi_block_requests(ahd->platform_data->host);
+               ahd_platform_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
+                                       CAM_LUN_WILDCARD, SCB_LIST_NULL,
+                                       ROLE_INITIATOR, CAM_REQUEUE_REQ);
+       }
+}
+
+void
+ahd_release_simq(struct ahd_softc *ahd)
+{
+       u_long s;
+       int    unblock_reqs;
+
+       unblock_reqs = 0;
+       ahd_lock(ahd, &s);
+       if (ahd->platform_data->qfrozen > 0)
+               ahd->platform_data->qfrozen--;
+       if (ahd->platform_data->qfrozen == 0) {
+               unblock_reqs = 1;
+       }
+       ahd_unlock(ahd, &s);
+       /*
+        * There is still a race here.  The mid-layer
+        * should keep its own freeze count and use
+        * a bottom half handler to run the queues
+        * so we can unblock with our own lock held.
+        */
+       if (unblock_reqs)
+               scsi_unblock_requests(ahd->platform_data->host);
+}
+
+static int
+ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
+{
+       struct ahd_softc *ahd;
+       struct ahd_linux_device *dev;
+       struct scb *pending_scb;
+       u_int  saved_scbptr;
+       u_int  active_scbptr;
+       u_int  last_phase;
+       u_int  saved_scsiid;
+       u_int  cdb_byte;
+       int    retval;
+       int    was_paused;
+       int    paused;
+       int    wait;
+       int    disconnected;
+       ahd_mode_state saved_modes;
+
+       pending_scb = NULL;
+       paused = FALSE;
+       wait = FALSE;
+       ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
+
+       printf("%s:%d:%d:%d: Attempting to queue a%s message:",
+              ahd_name(ahd), cmd->device->channel,
+              cmd->device->id, cmd->device->lun,
+              flag == SCB_ABORT ? "n ABORT" : " TARGET RESET");
+
+       printf("CDB:");
+       for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
+               printf(" 0x%x", cmd->cmnd[cdb_byte]);
+       printf("\n");
+
+       spin_lock_irq(&ahd->platform_data->spin_lock);
+
+       /*
+        * First determine if we currently own this command.
+        * Start by searching the device queue.  If not found
+        * there, check the pending_scb list.  If not found
+        * at all, and the system wanted us to just abort the
+        * command, return success.
+        */
+       dev = scsi_transport_device_data(cmd->device);
+
+       if (dev == NULL) {
+               /*
+                * No target device for this command exists,
+                * so we must not still own the command.
+                */
+               printf("%s:%d:%d:%d: Is not an active device\n",
+                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
+                      cmd->device->lun);
+               retval = SUCCESS;
+               goto no_cmd;
+       }
+
+       /*
+        * See if we can find a matching cmd in the pending list.
+        */
+       LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
+               if (pending_scb->io_ctx == cmd)
+                       break;
+       }
+
+       if (pending_scb == NULL && flag == SCB_DEVICE_RESET) {
+
+               /* Any SCB for this device will do for a target reset */
+               LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
+                       if (ahd_match_scb(ahd, pending_scb, cmd->device->id,
+                                         cmd->device->channel + 'A',
+                                         CAM_LUN_WILDCARD,
+                                         SCB_LIST_NULL, ROLE_INITIATOR) == 0)
+                               break;
+               }
+       }
+
+       if (pending_scb == NULL) {
+               printf("%s:%d:%d:%d: Command not found\n",
+                      ahd_name(ahd), cmd->device->channel, cmd->device->id,
+                      cmd->device->lun);
+               goto no_cmd;
+       }
+
+       if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
+               /*
+                * We can't queue two recovery actions using the same SCB
+                */
+               retval = FAILED;
+               goto  done;
+       }
+
+       /*
+        * Ensure that the card doesn't do anything
+        * behind our back.  Also make sure that we
+        * didn't "just" miss an interrupt that would
+        * affect this cmd.
+        */
+       was_paused = ahd_is_paused(ahd);
+       ahd_pause_and_flushwork(ahd);