]> err.no Git - linux-2.6/blobdiff - drivers/scsi/aic7xxx/aic7xxx_osm.c
[SCSI] aic7xxx: fix U160 mode
[linux-2.6] / drivers / scsi / aic7xxx / aic7xxx_osm.c
index 717401b26b6f0b3b217cb822ab82bc7eba53d8ab..f90efa265ba276d8cdd47235822f3c55ee102705 100644 (file)
@@ -426,14 +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_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,
@@ -454,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;
@@ -489,60 +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;
-       int     with_errors;
-
-       with_errors = 0;
-       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);
-       }
-       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);
@@ -582,27 +523,11 @@ 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 *);
-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
-static int        ahc_linux_bus_reset(Scsi_Cmnd *);
-static int        ahc_linux_dev_reset(Scsi_Cmnd *);
-static int        ahc_linux_abort(Scsi_Cmnd *);
-
 /*
  * 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;
@@ -683,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;
@@ -705,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;
@@ -714,48 +639,106 @@ ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
 }
 
 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) {
+               targ = ahc_linux_alloc_target(ahc, starget->channel, starget->id);
+               struct seeprom_config *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;
 
        ahc = *((struct ahc_softc **)device->host->hostdata);
+
        if (bootverbose)
                printf("%s: Slave Configure %d\n", ahc_name(ahc), device->id);
-       /*
-        * 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);
-       }
+
+       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;
@@ -764,22 +747,11 @@ ahc_linux_slave_destroy(Scsi_Device *device)
        if (bootverbose)
                printf("%s: Slave Destroy %d\n", ahc_name(ahc), device->id);
        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);
-       }
+                                  device->id, device->lun);
+
+       BUG_ON(dev->active);
+
+       ahc_linux_free_device(ahc, dev);
 }
 
 #if defined(__i386__)
@@ -836,7 +808,7 @@ ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  * Abort the current SCSI command(s).
  */
 static int
-ahc_linux_abort(Scsi_Cmnd *cmd)
+ahc_linux_abort(struct scsi_cmnd *cmd)
 {
        int error;
 
@@ -850,7 +822,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;
 
@@ -864,7 +836,7 @@ 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;
        int    found;
@@ -872,7 +844,6 @@ ahc_linux_bus_reset(Scsi_Cmnd *cmd)
        ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
        found = ahc_reset_channel(ahc, cmd->device->channel + 'A',
                                  /*initiate reset*/TRUE);
-       ahc_linux_run_complete_queue(ahc);
 
        if (bootverbose)
                printf("%s: SCSI bus reset delivered. "
@@ -881,7 +852,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,
@@ -1189,7 +1160,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;
@@ -1347,14 +1318,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_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;
@@ -1372,7 +1337,6 @@ 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) {
                        scsi_remove_host(ahc->platform_data->host);
                        scsi_host_put(ahc->platform_data->host);
@@ -1434,7 +1398,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);
@@ -1521,18 +1485,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)
 {
@@ -1802,7 +1754,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);
 }
@@ -1811,8 +1762,6 @@ void
 ahc_platform_flushwork(struct ahc_softc *ahc)
 {
 
-       while (ahc_linux_run_complete_queue(ahc) != NULL)
-               ;
 }
 
 static struct ahc_linux_target*
@@ -1881,8 +1830,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;
 
@@ -1905,7 +1852,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;
 
@@ -1917,13 +1864,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)
@@ -2017,7 +1957,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);
@@ -2096,8 +2036,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
@@ -2119,15 +2057,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
@@ -2171,7 +2100,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
@@ -2266,51 +2195,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
@@ -2364,26 +2256,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 */
@@ -2394,17 +2267,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
@@ -2463,26 +2326,8 @@ 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;
@@ -2521,7 +2366,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) {
                /*
@@ -2768,7 +2613,6 @@ done:
                }
                spin_lock_irq(&ahc->platform_data->spin_lock);
        }
-       ahc_linux_run_complete_queue(ahc);
        return (retval);
 }
 
@@ -2835,6 +2679,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);
 
@@ -2920,6 +2769,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);