]> err.no Git - linux-2.6/blobdiff - drivers/scsi/aic7xxx/aic7xxx_osm.c
Automatic merge of rsync://www.parisc-linux.org/~jejb/git/scsi-for-linus-2.6
[linux-2.6] / drivers / scsi / aic7xxx / aic7xxx_osm.c
index 9017942407d84022cb1d387eb8d70f5a073c7af5..c13e56320010cc641f09db992e9cbb5599967ca7 100644 (file)
@@ -134,11 +134,6 @@ static struct scsi_transport_template *ahc_linux_transport_template = NULL;
 #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 */
@@ -148,11 +143,6 @@ static struct scsi_transport_template *ahc_linux_transport_template = NULL;
  */
 spinlock_t ahc_list_spinlock;
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-/* For dynamic sglist size calculation. */
-u_int ahc_linux_nseg;
-#endif
-
 /*
  * Set this to the delay in seconds after SCSI bus reset.
  * Note, we honor this only for the initial bus reset.
@@ -436,15 +426,12 @@ static void ahc_linux_handle_scsi_status(struct ahc_softc *,
                                         struct ahc_linux_device *,
                                         struct scb *);
 static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
-                                        Scsi_Cmnd *cmd);
+                                        struct scsi_cmnd *cmd);
 static void ahc_linux_sem_timeout(u_long arg);
 static void ahc_linux_freeze_simq(struct ahc_softc *ahc);
 static void ahc_linux_release_simq(u_long arg);
-static void ahc_linux_dev_timed_unfreeze(u_long arg);
-static int  ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag);
+static int  ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag);
 static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc);
-static void ahc_linux_size_nseg(void);
-static void ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc);
 static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc,
                                     struct ahc_devinfo *devinfo);
 static void ahc_linux_device_queue_depth(struct ahc_softc *ahc,
@@ -465,32 +452,20 @@ static void ahc_linux_setup_tag_info_global(char *p);
 static aic_option_callback_t ahc_linux_setup_tag_info;
 static int  aic7xxx_setup(char *s);
 static int  ahc_linux_next_unit(void);
-static struct ahc_cmd *ahc_linux_run_complete_queue(struct ahc_softc *ahc);
 
 /********************************* Inlines ************************************/
 static __inline struct ahc_linux_device*
                     ahc_linux_get_device(struct ahc_softc *ahc, u_int channel,
-                                         u_int target, u_int lun, int alloc);
-static __inline void ahc_schedule_completeq(struct ahc_softc *ahc);
+                                         u_int target, u_int lun);
 static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
 
 static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
                                      struct ahc_dma_seg *sg,
                                      dma_addr_t addr, bus_size_t len);
 
-static __inline void
-ahc_schedule_completeq(struct ahc_softc *ahc)
-{
-       if ((ahc->platform_data->flags & AHC_RUN_CMPLT_Q_TIMER) == 0) {
-               ahc->platform_data->flags |= AHC_RUN_CMPLT_Q_TIMER;
-               ahc->platform_data->completeq_timer.expires = jiffies;
-               add_timer(&ahc->platform_data->completeq_timer);
-       }
-}
-
 static __inline struct ahc_linux_device*
 ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
-                    u_int lun, int alloc)
+                    u_int lun)
 {
        struct ahc_linux_target *targ;
        struct ahc_linux_device *dev;
@@ -500,63 +475,15 @@ ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
        if (channel != 0)
                target_offset += 8;
        targ = ahc->platform_data->targets[target_offset];
-       if (targ == NULL) {
-               if (alloc != 0) {
-                       targ = ahc_linux_alloc_target(ahc, channel, target);
-                       if (targ == NULL)
-                               return (NULL);
-               } else
-                       return (NULL);
-       }
+       BUG_ON(targ == NULL);
        dev = targ->devices[lun];
-       if (dev == NULL && alloc != 0)
-               dev = ahc_linux_alloc_device(ahc, targ, lun);
-       return (dev);
-}
-
-#define AHC_LINUX_MAX_RETURNED_ERRORS 4
-static struct ahc_cmd *
-ahc_linux_run_complete_queue(struct ahc_softc *ahc)
-{
-       struct  ahc_cmd *acmd;
-       u_long  done_flags;
-       int     with_errors;
-
-       with_errors = 0;
-       ahc_done_lock(ahc, &done_flags);
-       while ((acmd = TAILQ_FIRST(&ahc->platform_data->completeq)) != NULL) {
-               Scsi_Cmnd *cmd;
-
-               if (with_errors > AHC_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"
-                        */
-                       ahc_schedule_completeq(ahc);
-                       break;
-               }
-               TAILQ_REMOVE(&ahc->platform_data->completeq,
-                            acmd, acmd_links.tqe);
-               cmd = &acmd_scsi_cmd(acmd);
-               cmd->host_scribble = NULL;
-               if (ahc_cmd_get_transaction_status(cmd) != DID_OK
-                || (cmd->result & 0xFF) != SCSI_STATUS_OK)
-                       with_errors++;
-
-               cmd->scsi_done(cmd);
-       }
-       ahc_done_unlock(ahc, &done_flags);
-       return (acmd);
+       return dev;
 }
 
 static __inline void
 ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
 {
-       Scsi_Cmnd *cmd;
+       struct scsi_cmnd *cmd;
 
        cmd = scb->io_ctx;
        ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE);
@@ -596,109 +523,15 @@ ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
        return (consumed);
 }
 
-/************************  Host template entry points *************************/
-static int        ahc_linux_detect(Scsi_Host_Template *);
-static int        ahc_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
-static const char *ahc_linux_info(struct Scsi_Host *);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-static int        ahc_linux_slave_alloc(Scsi_Device *);
-static int        ahc_linux_slave_configure(Scsi_Device *);
-static void       ahc_linux_slave_destroy(Scsi_Device *);
-#if defined(__i386__)
-static int        ahc_linux_biosparam(struct scsi_device*,
-                                      struct block_device*,
-                                      sector_t, int[]);
-#endif
-#else
-static int        ahc_linux_release(struct Scsi_Host *);
-static void       ahc_linux_select_queue_depth(struct Scsi_Host *host,
-                                               Scsi_Device *scsi_devs);
-#if defined(__i386__)
-static int        ahc_linux_biosparam(Disk *, kdev_t, int[]);
-#endif
-#endif
-static int        ahc_linux_bus_reset(Scsi_Cmnd *);
-static int        ahc_linux_dev_reset(Scsi_Cmnd *);
-static int        ahc_linux_abort(Scsi_Cmnd *);
-
-/*
- * Calculate a safe value for AHC_NSEG (as expressed through ahc_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 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
-ahc_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 < AHC_LINUX_MIN_NSEG)
-                       continue;
-
-               if (best_size == 0) {
-                       best_size = cur_size;
-                       ahc_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;
-                               ahc_linux_nseg = nseg;
-                       }
-               }
-       }
-#endif
-}
-
 /*
  * Try to detect an Adaptec 7XXX controller.
  */
 static int
-ahc_linux_detect(Scsi_Host_Template *template)
+ahc_linux_detect(struct scsi_host_template *template)
 {
        struct  ahc_softc *ahc;
        int     found = 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
@@ -710,7 +543,6 @@ ahc_linux_detect(Scsi_Host_Template *template)
                printf("ahc_linux_detect: Unable to attach\n");
                return (0);
        }
-       ahc_linux_size_nseg();
        /*
         * If we've been passed any parameters, process them now.
         */
@@ -739,48 +571,11 @@ ahc_linux_detect(Scsi_Host_Template *template)
                        found++;
        }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-       spin_lock_irq(&io_request_lock);
-#endif
        aic7xxx_detect_complete++;
 
        return (found);
 }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-/*
- * Free the passed in Scsi_Host memory structures prior to unloading the
- * module.
- */
-int
-ahc_linux_release(struct Scsi_Host * host)
-{
-       struct ahc_softc *ahc;
-       u_long l;
-
-       ahc_list_lock(&l);
-       if (host != NULL) {
-
-               /*
-                * We should be able to just perform
-                * the free directly, but check our
-                * list for extra sanity.
-                */
-               ahc = ahc_find_softc(*(struct ahc_softc **)host->hostdata);
-               if (ahc != NULL) {
-                       u_long s;
-
-                       ahc_lock(ahc, &s);
-                       ahc_intr_enable(ahc, FALSE);
-                       ahc_unlock(ahc, &s);
-                       ahc_free(ahc);
-               }
-       }
-       ahc_list_unlock(&l);
-       return (0);
-}
-#endif
-
 /*
  * Return a string describing the driver.
  */
@@ -813,7 +608,7 @@ ahc_linux_info(struct Scsi_Host *host)
  * Queue an SCB to the controller.
  */
 static int
-ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
+ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
 {
        struct   ahc_softc *ahc;
        struct   ahc_linux_device *dev;
@@ -835,7 +630,7 @@ ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
                return SCSI_MLQUEUE_HOST_BUSY;
 
        dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id,
-                                  cmd->device->lun, /*alloc*/TRUE);
+                                  cmd->device->lun);
        BUG_ON(dev == NULL);
 
        cmd->result = CAM_REQ_INPROG << 16;
@@ -843,166 +638,134 @@ ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
        return ahc_linux_run_command(ahc, dev, cmd);
 }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
 static int
-ahc_linux_slave_alloc(Scsi_Device *device)
+ahc_linux_slave_alloc(struct scsi_device *device)
 {
        struct  ahc_softc *ahc;
+       struct ahc_linux_target *targ;
+       struct scsi_target *starget = device->sdev_target;
+       struct ahc_linux_device *dev;
+       unsigned int target_offset;
+       unsigned long flags;
+       int retval = -ENOMEM;
+
+       target_offset = starget->id;
+       if (starget->channel != 0)
+               target_offset += 8;
 
        ahc = *((struct ahc_softc **)device->host->hostdata);
        if (bootverbose)
                printf("%s: Slave Alloc %d\n", ahc_name(ahc), device->id);
-       return (0);
+       ahc_lock(ahc, &flags);
+       targ = ahc->platform_data->targets[target_offset];
+       if (targ == NULL) {
+               struct seeprom_config *sc;
+
+               targ = ahc_linux_alloc_target(ahc, starget->channel,
+                                               starget->id);
+               sc = ahc->seep_config;
+               if (targ == NULL)
+                       goto out;
+
+               if (sc) {
+                       unsigned short scsirate;
+                       struct ahc_devinfo devinfo;
+                       struct ahc_initiator_tinfo *tinfo;
+                       struct ahc_tmode_tstate *tstate;
+                       char channel = starget->channel + 'A';
+                       unsigned int our_id = ahc->our_id;
+
+                       if (starget->channel)
+                               our_id = ahc->our_id_b;
+
+                       if ((ahc->features & AHC_ULTRA2) != 0) {
+                               scsirate = sc->device_flags[target_offset] & CFXFER;
+                       } else {
+                               scsirate = (sc->device_flags[target_offset] & CFXFER) << 4;
+                               if (sc->device_flags[target_offset] & CFSYNCH)
+                                       scsirate |= SOFS;
+                       }
+                       if (sc->device_flags[target_offset] & CFWIDEB) {
+                               scsirate |= WIDEXFER;
+                               spi_max_width(starget) = 1;
+                       } else
+                               spi_max_width(starget) = 0;
+                       spi_min_period(starget) = 
+                               ahc_find_period(ahc, scsirate, AHC_SYNCRATE_DT);
+                       tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id,
+                                                   targ->target, &tstate);
+                       ahc_compile_devinfo(&devinfo, our_id, targ->target,
+                                           CAM_LUN_WILDCARD, channel,
+                                           ROLE_INITIATOR);
+                       ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
+                                        AHC_TRANS_GOAL, /*paused*/FALSE);
+                       ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+                                     AHC_TRANS_GOAL, /*paused*/FALSE);
+               }
+                       
+       }
+       dev = targ->devices[device->lun];
+       if (dev == NULL) {
+               dev = ahc_linux_alloc_device(ahc, targ, device->lun);
+               if (dev == NULL)
+                       goto out;
+       }
+       retval = 0;
+
+ out:
+       ahc_unlock(ahc, &flags);
+       return retval;
 }
 
 static int
-ahc_linux_slave_configure(Scsi_Device *device)
+ahc_linux_slave_configure(struct scsi_device *device)
 {
        struct  ahc_softc *ahc;
        struct  ahc_linux_device *dev;
-       u_long  flags;
 
        ahc = *((struct ahc_softc **)device->host->hostdata);
+
        if (bootverbose)
                printf("%s: Slave Configure %d\n", ahc_name(ahc), device->id);
-       ahc_midlayer_entrypoint_lock(ahc, &flags);
-       /*
-        * Since Linux has attached to the device, configure
-        * it so we don't free and allocate the device
-        * structure on every command.
-        */
-       dev = ahc_linux_get_device(ahc, device->channel,
-                                  device->id, device->lun,
-                                  /*alloc*/TRUE);
-       if (dev != NULL) {
-               dev->flags &= ~AHC_DEV_UNCONFIGURED;
-               dev->scsi_device = device;
-               ahc_linux_device_queue_depth(ahc, dev);
-       }
-       ahc_midlayer_entrypoint_unlock(ahc, &flags);
+
+       dev = ahc_linux_get_device(ahc, device->channel, device->id,
+                                  device->lun);
+       dev->scsi_device = device;
+       ahc_linux_device_queue_depth(ahc, dev);
 
        /* Initial Domain Validation */
        if (!spi_initial_dv(device->sdev_target))
                spi_dv_device(device);
 
-       return (0);
+       return 0;
 }
 
 static void
-ahc_linux_slave_destroy(Scsi_Device *device)
+ahc_linux_slave_destroy(struct scsi_device *device)
 {
        struct  ahc_softc *ahc;
        struct  ahc_linux_device *dev;
-       u_long  flags;
 
        ahc = *((struct ahc_softc **)device->host->hostdata);
        if (bootverbose)
                printf("%s: Slave Destroy %d\n", ahc_name(ahc), device->id);
-       ahc_midlayer_entrypoint_lock(ahc, &flags);
        dev = ahc_linux_get_device(ahc, device->channel,
-                                  device->id, device->lun,
-                                          /*alloc*/FALSE);
-       /*
-        * 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.
-        */
-       if (dev != NULL
-        && (dev->flags & AHC_DEV_SLAVE_CONFIGURED) != 0) {
-               dev->flags |= AHC_DEV_UNCONFIGURED;
-               if (dev->active == 0
-                && (dev->flags & AHC_DEV_TIMER_ACTIVE) == 0)
-                       ahc_linux_free_device(ahc, dev);
-       }
-       ahc_midlayer_entrypoint_unlock(ahc, &flags);
-}
-#else
-/*
- * Sets the queue depth for each SCSI device hanging
- * off the input host adapter.
- */
-static void
-ahc_linux_select_queue_depth(struct Scsi_Host *host, Scsi_Device *scsi_devs)
-{
-       Scsi_Device *device;
-       Scsi_Device *ldev;
-       struct  ahc_softc *ahc;
-       u_long  flags;
-
-       ahc = *((struct ahc_softc **)host->hostdata);
-       ahc_lock(ahc, &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;
+                                  device->id, device->lun);
 
-               if (device->host == host) {
-                       struct   ahc_linux_device *dev;
+       BUG_ON(dev->active);
 
-                       /*
-                        * Since Linux has attached to the device, configure
-                        * it so we don't free and allocate the device
-                        * structure on every command.
-                        */
-                       dev = ahc_linux_get_device(ahc, device->channel,
-                                                  device->id, device->lun,
-                                                  /*alloc*/TRUE);
-                       if (dev != NULL) {
-                               dev->flags &= ~AHC_DEV_UNCONFIGURED;
-                               dev->scsi_device = device;
-                               ahc_linux_device_queue_depth(ahc, dev);
-                               device->queue_depth = dev->openings
-                                                   + dev->active;
-                               if ((dev->flags & (AHC_DEV_Q_BASIC
-                                               | AHC_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;
-                               }
-                       }
-               }
-       }
-       ahc_unlock(ahc, &flags);
+       ahc_linux_free_device(ahc, dev);
 }
-#endif
 
 #if defined(__i386__)
 /*
  * Return the disk geometry for the given SCSI device.
  */
 static int
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
 ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
                    sector_t capacity, int geom[])
 {
        uint8_t *bh;
-#else
-ahc_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;
@@ -1014,22 +777,11 @@ ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
        ahc = *((struct ahc_softc **)sdev->host->hostdata);
        channel = sdev->channel;
 
-#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);
        }
@@ -1059,7 +811,7 @@ ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
  * Abort the current SCSI command(s).
  */
 static int
-ahc_linux_abort(Scsi_Cmnd *cmd)
+ahc_linux_abort(struct scsi_cmnd *cmd)
 {
        int error;
 
@@ -1073,7 +825,7 @@ ahc_linux_abort(Scsi_Cmnd *cmd)
  * Attempt to send a target reset message to the device that timed out.
  */
 static int
-ahc_linux_dev_reset(Scsi_Cmnd *cmd)
+ahc_linux_dev_reset(struct scsi_cmnd *cmd)
 {
        int error;
 
@@ -1087,18 +839,14 @@ ahc_linux_dev_reset(Scsi_Cmnd *cmd)
  * Reset the SCSI bus.
  */
 static int
-ahc_linux_bus_reset(Scsi_Cmnd *cmd)
+ahc_linux_bus_reset(struct scsi_cmnd *cmd)
 {
        struct ahc_softc *ahc;
-       u_long s;
        int    found;
 
        ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
-       ahc_midlayer_entrypoint_lock(ahc, &s);
        found = ahc_reset_channel(ahc, cmd->device->channel + 'A',
                                  /*initiate reset*/TRUE);
-       ahc_linux_run_complete_queue(ahc);
-       ahc_midlayer_entrypoint_unlock(ahc, &s);
 
        if (bootverbose)
                printf("%s: SCSI bus reset delivered. "
@@ -1107,7 +855,7 @@ ahc_linux_bus_reset(Scsi_Cmnd *cmd)
        return SUCCESS;
 }
 
-Scsi_Host_Template aic7xxx_driver_template = {
+struct scsi_host_template aic7xxx_driver_template = {
        .module                 = THIS_MODULE,
        .name                   = "aic7xxx",
        .proc_info              = ahc_linux_proc_info,
@@ -1175,37 +923,11 @@ int
 ahc_dmamem_alloc(struct ahc_softc *ahc, 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 (ahc->dev_softc != NULL)
-               if (pci_set_dma_mask(ahc->dev_softc, 0xFFFFFFFF)) {
-                       printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n");
-                       kfree(map);
-                       return (ENODEV);
-               }
        *vaddr = pci_alloc_consistent(ahc->dev_softc,
-                                     dmat->maxsize, &map->bus_addr);
-       if (ahc->dev_softc != NULL)
-               if (pci_set_dma_mask(ahc->dev_softc,
-                                    ahc->platform_data->hw_dma_mask)) {
-                       printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n");
-                       kfree(map);
-                       return (ENODEV);
-               }
+                                     dmat->maxsize, mapp);
        if (*vaddr == NULL)
-               return (ENOMEM);
-       *mapp = map;
-       return(0);
+               return ENOMEM;
+       return 0;
 }
 
 void
@@ -1213,7 +935,7 @@ ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
                void* vaddr, bus_dmamap_t map)
 {
        pci_free_consistent(ahc->dev_softc, dmat->maxsize,
-                           vaddr, map->bus_addr);
+                           vaddr, map);
 }
 
 int
@@ -1227,7 +949,7 @@ ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
         */
        bus_dma_segment_t stack_sg;
 
-       stack_sg.ds_addr = map->bus_addr;
+       stack_sg.ds_addr = map;
        stack_sg.ds_len = dmat->maxsize;
        cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
        return (0);
@@ -1236,12 +958,6 @@ ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
 void
 ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
 {
-       /*
-        * The map may is NULL in our < 2.3.X implementation.
-        * Now it's 2.6.5, but just in case...
-        */
-       BUG_ON(map == NULL);
-       free(map, M_DEVBUF);
 }
 
 int
@@ -1447,7 +1163,7 @@ __setup("aic7xxx=", aic7xxx_setup);
 uint32_t aic7xxx_verbose;
 
 int
-ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
+ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template)
 {
        char     buf[80];
        struct   Scsi_Host *host;
@@ -1461,11 +1177,7 @@ ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
 
        *((struct ahc_softc **)host->hostdata) = ahc;
        ahc_lock(ahc, &s);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
        scsi_assign_lock(host, &ahc->platform_data->spin_lock);
-#elif AHC_SCSI_HAS_HOST_LOCK != 0
-       host->lock = &ahc->platform_data->spin_lock;
-#endif
        ahc->platform_data->host = host;
        host->can_queue = AHC_MAX_QUEUE;
        host->cmd_per_lun = 2;
@@ -1484,19 +1196,14 @@ ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
                ahc_set_name(ahc, new_name);
        }
        host->unique_id = ahc->unit;
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-       scsi_set_pci_device(host, ahc->dev_softc);
-#endif
        ahc_linux_initialize_scsi_bus(ahc);
        ahc_intr_enable(ahc, TRUE);
        ahc_unlock(ahc, &s);
 
        host->transportt = ahc_linux_transport_template;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
        scsi_add_host(host, (ahc->dev_softc ? &ahc->dev_softc->dev : NULL)); /* XXX handle failure */
        scsi_scan_host(host);
-#endif
        return (0);
 }
 
@@ -1614,16 +1321,8 @@ ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
        if (ahc->platform_data == NULL)
                return (ENOMEM);
        memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
-       TAILQ_INIT(&ahc->platform_data->completeq);
-       TAILQ_INIT(&ahc->platform_data->device_runq);
        ahc->platform_data->irq = AHC_LINUX_NOIRQ;
-       ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
        ahc_lockinit(ahc);
-       ahc_done_lockinit(ahc);
-       init_timer(&ahc->platform_data->completeq_timer);
-       ahc->platform_data->completeq_timer.data = (u_long)ahc;
-       ahc->platform_data->completeq_timer.function =
-           (ahc_linux_callback_t *)ahc_linux_thread_run_complete_queue;
        init_MUTEX_LOCKED(&ahc->platform_data->eh_sem);
        ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
        ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
@@ -1641,11 +1340,8 @@ ahc_platform_free(struct ahc_softc *ahc)
        int i, j;
 
        if (ahc->platform_data != NULL) {
-               del_timer_sync(&ahc->platform_data->completeq_timer);
                if (ahc->platform_data->host != NULL) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
                        scsi_remove_host(ahc->platform_data->host);
-#endif
                        scsi_host_put(ahc->platform_data->host);
                }
 
@@ -1681,16 +1377,7 @@ ahc_platform_free(struct ahc_softc *ahc)
                        release_mem_region(ahc->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 (ahc->dev_softc != NULL)
-                       ahc->dev_softc->driver = NULL;
-#endif
+
                free(ahc->platform_data, M_DEVBUF);
        }
 }
@@ -1714,7 +1401,7 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
 
        dev = ahc_linux_get_device(ahc, devinfo->channel - 'A',
                                   devinfo->target,
-                                  devinfo->lun, /*alloc*/FALSE);
+                                  devinfo->lun);
        if (dev == NULL)
                return;
        was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
@@ -1767,7 +1454,6 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
                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 & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
                case AHC_DEV_Q_BASIC:
@@ -1793,7 +1479,6 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
                        break;
                }
        }
-#endif
 }
 
 int
@@ -1803,18 +1488,6 @@ ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel,
        return 0;
 }
 
-static void
-ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc)
-{
-       u_long flags;
-
-       ahc_lock(ahc, &flags);
-       del_timer(&ahc->platform_data->completeq_timer);
-       ahc->platform_data->flags &= ~AHC_RUN_CMPLT_Q_TIMER;
-       ahc_linux_run_complete_queue(ahc);
-       ahc_unlock(ahc, &flags);
-}
-
 static u_int
 ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
 {
@@ -1948,7 +1621,6 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
        }
 
        if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
                int     msg_bytes;
                uint8_t tag_msgs[2];
                
@@ -1957,10 +1629,8 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
                        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 == AHC_OTAG_THRESH
-                   && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
+               } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
+                               && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
                        hscb->control |= MSG_ORDERED_TASK;
                        dev->commands_since_idle_or_otag = 0;
                } else {
@@ -2087,7 +1757,6 @@ ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
        ahc = (struct ahc_softc *) dev_id;
        ahc_lock(ahc, &flags); 
        ours = ahc_intr(ahc);
-       ahc_linux_run_complete_queue(ahc);
        ahc_unlock(ahc, &flags);
        return IRQ_RETVAL(ours);
 }
@@ -2096,8 +1765,6 @@ void
 ahc_platform_flushwork(struct ahc_softc *ahc)
 {
 
-       while (ahc_linux_run_complete_queue(ahc) != NULL)
-               ;
 }
 
 static struct ahc_linux_target*
@@ -2166,8 +1833,6 @@ ahc_linux_alloc_device(struct ahc_softc *ahc,
        if (dev == NULL)
                return (NULL);
        memset(dev, 0, sizeof(*dev));
-       init_timer(&dev->timer);
-       dev->flags = AHC_DEV_UNCONFIGURED;
        dev->lun = lun;
        dev->target = targ;
 
@@ -2190,7 +1855,7 @@ ahc_linux_alloc_device(struct ahc_softc *ahc,
 }
 
 static void
-__ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
+ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
 {
        struct ahc_linux_target *targ;
 
@@ -2202,13 +1867,6 @@ __ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
                ahc_linux_free_target(ahc, targ);
 }
 
-static void
-ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
-{
-       del_timer_sync(&dev->timer);
-       __ahc_linux_free_device(ahc, dev);
-}
-
 void
 ahc_send_async(struct ahc_softc *ahc, char channel,
               u_int target, u_int lun, ac_code code, void *arg)
@@ -2280,28 +1938,9 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
        }
         case AC_SENT_BDR:
        {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
                WARN_ON(lun != CAM_LUN_WILDCARD);
                scsi_report_device_reset(ahc->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 = ahc->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:
@@ -2321,7 +1960,7 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
 void
 ahc_done(struct ahc_softc *ahc, struct scb *scb)
 {
-       Scsi_Cmnd *cmd;
+       struct scsi_cmnd *cmd;
        struct     ahc_linux_device *dev;
 
        LIST_REMOVE(scb, pending_links);
@@ -2400,8 +2039,6 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
                }
        } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
                ahc_linux_handle_scsi_status(ahc, dev, scb);
-       } else if (ahc_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
-               dev->flags |= AHC_DEV_UNCONFIGURED;
        }
 
        if (dev->openings == 1
@@ -2423,15 +2060,6 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
        if (dev->active == 0)
                dev->commands_since_idle_or_otag = 0;
 
-       if ((dev->flags & AHC_DEV_UNCONFIGURED) != 0
-           && dev->active == 0
-           && (dev->flags & AHC_DEV_TIMER_ACTIVE) == 0)
-               ahc_linux_free_device(ahc, dev);
-       else if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
-               TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
-               dev->flags |= AHC_DEV_ON_RUN_LIST;
-       }
-
        if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
                printf("Recovery SCB completes\n");
                if (ahc_get_transaction_status(scb) == CAM_BDR_SENT
@@ -2475,7 +2103,7 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
        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
@@ -2570,51 +2198,14 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
                ahc_platform_set_tags(ahc, &devinfo,
                             (dev->flags & AHC_DEV_Q_BASIC)
                           ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
-               /* 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 & AHC_DEV_TIMER_ACTIVE) != 0) {
-                       printf("%s:%c:%d: Device Timer still active during "
-                              "busy processing\n", ahc_name(ahc),
-                               dev->target->channel, dev->target->target);
-                       break;
-               }
-               dev->flags |= AHC_DEV_TIMER_ACTIVE;
-               dev->qfrozen++;
-               init_timer(&dev->timer);
-               dev->timer.data = (u_long)dev;
-               dev->timer.expires = jiffies + (HZ/2);
-               dev->timer.function = ahc_linux_dev_timed_unfreeze;
-               add_timer(&dev->timer);
                break;
        }
        }
 }
 
 static void
-ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
+ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd)
 {
-       /*
-        * Typically, the complete queue has very few entries
-        * queued to it before the queue is emptied by
-        * ahc_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 ahc routines do
-        * not guarantee the order that aborted commands will be
-        * returned to us.
-        */
-       struct ahc_completeq *completeq;
-       struct ahc_cmd *list_cmd;
-       struct ahc_cmd *acmd;
-
        /*
         * Map CAM error codes into Linux Error codes.  We
         * avoid the conversion so that the DV code has the
@@ -2668,26 +2259,7 @@ ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
                        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;
-                       ahc_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 */
@@ -2698,17 +2270,7 @@ ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
                ahc_cmd_set_transaction_status(cmd, new_status);
        }
 
-       completeq = &ahc->platform_data->completeq;
-       list_cmd = TAILQ_FIRST(completeq);
-       acmd = (struct ahc_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
@@ -2767,31 +2329,12 @@ ahc_linux_release_simq(u_long arg)
                scsi_unblock_requests(ahc->platform_data->host);
 }
 
-static void
-ahc_linux_dev_timed_unfreeze(u_long arg)
-{
-       struct ahc_linux_device *dev;
-       struct ahc_softc *ahc;
-       u_long s;
-
-       dev = (struct ahc_linux_device *)arg;
-       ahc = dev->target->ahc;
-       ahc_lock(ahc, &s);
-       dev->flags &= ~AHC_DEV_TIMER_ACTIVE;
-       if (dev->qfrozen > 0)
-               dev->qfrozen--;
-       if (dev->active == 0)
-               __ahc_linux_free_device(ahc, dev);
-       ahc_unlock(ahc, &s);
-}
-
 static int
-ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
+ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
 {
        struct ahc_softc *ahc;
        struct ahc_linux_device *dev;
        struct scb *pending_scb;
-       u_long s;
        u_int  saved_scbptr;
        u_int  active_scb_index;
        u_int  last_phase;
@@ -2818,22 +2361,6 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
                printf(" 0x%x", cmd->cmnd[cdb_byte]);
        printf("\n");
 
-       /*
-        * 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.
-        */
-       ahc_midlayer_entrypoint_lock(ahc, &s);
-
        /*
         * First determine if we currently own this command.
         * Start by searching the device queue.  If not found
@@ -2842,7 +2369,7 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
         * command, return success.
         */
        dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id,
-                                  cmd->device->lun, /*alloc*/FALSE);
+                                  cmd->device->lun);
 
        if (dev == NULL) {
                /*
@@ -3089,8 +2616,6 @@ done:
                }
                spin_lock_irq(&ahc->platform_data->spin_lock);
        }
-       ahc_linux_run_complete_queue(ahc);
-       ahc_midlayer_entrypoint_unlock(ahc, &s);
        return (retval);
 }
 
@@ -3157,6 +2682,11 @@ static void ahc_linux_set_period(struct scsi_target *starget, int period)
        if (offset == 0)
                offset = MAX_OFFSET;
 
+       if (period < 9)
+               period = 9;     /* 12.5ns is our minimum */
+       if (period == 9)
+               ppr_options |= MSG_EXT_PPR_DT_REQ;
+
        ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
                            starget->channel + 'A', ROLE_INITIATOR);
 
@@ -3242,6 +2772,12 @@ static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
        unsigned long flags;
        struct ahc_syncrate *syncrate;
 
+       if (dt) {
+               period = 9;     /* 12.5ns is the only period valid for DT */
+               ppr_options |= MSG_EXT_PPR_DT_REQ;
+       } else if (period == 9)
+               period = 10;    /* if resetting DT, period must be >= 25ns */
+
        ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
                            starget->channel + 'A', ROLE_INITIATOR);
        syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT);
@@ -3357,7 +2893,6 @@ static struct spi_function_template ahc_linux_transport_functions = {
 static int __init
 ahc_linux_init(void)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
        ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions);
        if (!ahc_linux_transport_template)
                return -ENODEV;
@@ -3366,29 +2901,11 @@ ahc_linux_init(void)
        spi_release_transport(ahc_linux_transport_template);
        ahc_linux_exit();
        return -ENODEV;
-#else
-       scsi_register_module(MODULE_SCSI_HA, &aic7xxx_driver_template);
-       if (aic7xxx_driver_template.present == 0) {
-               scsi_unregister_module(MODULE_SCSI_HA,
-                                      &aic7xxx_driver_template);
-               return (-ENODEV);
-       }
-
-       return (0);
-#endif
 }
 
 static void
 ahc_linux_exit(void)
 {
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-       /*
-        * In 2.4 we have to unregister from the PCI core _after_
-        * unregistering from the scsi midlayer to avoid dangling
-        * references.
-        */
-       scsi_unregister_module(MODULE_SCSI_HA, &aic7xxx_driver_template);
-#endif
        ahc_linux_pci_exit();
        ahc_linux_eisa_exit();
        spi_release_transport(ahc_linux_transport_template);