pci_unmap_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction)); 
pci_unmap_sg(p->pdev, sg, cmd->use_sg, cmd->sc_data_direction); 
aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb){  Scsi_Cmnd *cmd = scb->cmd;  struct aic_dev_data *aic_dev = cmd->device->hostdata;  int tindex = TARGET_INDEX(cmd);  struct aic7xxx_scb *scbp;  unsigned char queue_depth;  if (cmd->use_sg > 1)  {    struct scatterlist *sg;    sg = (struct scatterlist *)cmd->request_buffer;    pci_unmap_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction));  }  else if (cmd->request_bufflen)    pci_unmap_single(p->pdev, aic7xxx_mapping(cmd),		     cmd->request_bufflen,                     scsi_to_pci_dma_dir(cmd->sc_data_direction));  if (scb->flags & SCB_SENSE)  {    pci_unmap_single(p->pdev,                     le32_to_cpu(scb->sg_list[0].address),                     sizeof(cmd->sense_buffer),                     PCI_DMA_FROMDEVICE);  }  if (scb->flags & SCB_RECOVERY_SCB)  {    p->flags &= ~AHC_ABORT_PENDING;  }  if (scb->flags & (SCB_RESET|SCB_ABORT))  {    cmd->result |= (DID_RESET << 16);  }  if ((scb->flags & SCB_MSGOUT_BITS) != 0)  {    unsigned short mask;    int message_error = FALSE;    mask = 0x01 << tindex;     /*     * Check to see if we get an invalid message or a message error     * after failing to negotiate a wide or sync transfer message.     */    if ((scb->flags & SCB_SENSE) &&           ((scb->cmd->sense_buffer[12] == 0x43) ||  /* INVALID_MESSAGE */          (scb->cmd->sense_buffer[12] == 0x49))) /* MESSAGE_ERROR  */    {      message_error = TRUE;    }    if (scb->flags & SCB_MSGOUT_WDTR)    {      if (message_error)      {        if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&             (aic_dev->flags & DEVICE_PRINT_DTR) )        {          printk(INFO_LEAD "Device failed to complete Wide Negotiation "            "processing and\n", p->host_no, CTL_OF_SCB(scb));          printk(INFO_LEAD "returned a sense error code for invalid message, "            "disabling future\n", p->host_no, CTL_OF_SCB(scb));          printk(INFO_LEAD "Wide negotiation to this device.\n", p->host_no,            CTL_OF_SCB(scb));        }        aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;      }    }    if (scb->flags & SCB_MSGOUT_SDTR)    {      if (message_error)      {        if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&             (aic_dev->flags & DEVICE_PRINT_DTR) )        {          printk(INFO_LEAD "Device failed to complete Sync Negotiation "            "processing and\n", p->host_no, CTL_OF_SCB(scb));          printk(INFO_LEAD "returned a sense error code for invalid message, "            "disabling future\n", p->host_no, CTL_OF_SCB(scb));          printk(INFO_LEAD "Sync negotiation to this device.\n", p->host_no,            CTL_OF_SCB(scb));          aic_dev->flags &= ~DEVICE_PRINT_DTR;        }        aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;      }    }    if (scb->flags & SCB_MSGOUT_PPR)    {      if(message_error)      {        if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&             (aic_dev->flags & DEVICE_PRINT_DTR) )        {          printk(INFO_LEAD "Device failed to complete Parallel Protocol "            "Request processing and\n", p->host_no, CTL_OF_SCB(scb));          printk(INFO_LEAD "returned a sense error code for invalid message, "            "disabling future\n", p->host_no, CTL_OF_SCB(scb));          printk(INFO_LEAD "Parallel Protocol Request negotiation to this "            "device.\n", p->host_no, CTL_OF_SCB(scb));        }        /*         * Disable PPR negotiation and revert back to WDTR and SDTR setup         */        aic_dev->needppr = aic_dev->needppr_copy = 0;        aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;        aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;      }    }  }  queue_depth = aic_dev->temp_q_depth;  if (queue_depth >= aic_dev->active_cmds)  {    scbp = scbq_remove_head(&aic_dev->delayed_scbs);    if (scbp)    {      if (queue_depth == 1)      {        /*         * Give extra preference to untagged devices, such as CD-R devices         * This makes it more likely that a drive *won't* stuff up while         * waiting on data at a critical time, such as CD-R writing and         * audio CD ripping operations.  Should also benefit tape drives.         */        scbq_insert_head(&p->waiting_scbs, scbp);      }      else      {        scbq_insert_tail(&p->waiting_scbs, scbp);      }#ifdef AIC7XXX_VERBOSE_DEBUGGING      if (aic7xxx_verbose > 0xffff)        printk(INFO_LEAD "Moving SCB from delayed to waiting queue.\n",               p->host_no, CTL_OF_SCB(scbp));#endif      if (queue_depth > aic_dev->active_cmds)      {        scbp = scbq_remove_head(&aic_dev->delayed_scbs);        if (scbp)          scbq_insert_tail(&p->waiting_scbs, scbp);      }    }  }  if (!(scb->tag_action))  {    aic7xxx_index_busy_target(p, scb->hscb->target_channel_lun,                              /* unbusy */ TRUE);    if (cmd->device->simple_tags)    {      aic_dev->temp_q_depth = aic_dev->max_q_depth;    }  }  if(scb->flags & SCB_DTR_SCB)  {    aic_dev->dtr_pending = 0;  }  aic_dev->active_cmds--;  p->activescbs--;  if ((scb->sg_length >= 512) && (((cmd->result >> 16) & 0xf) == DID_OK))  {    long *ptr;    int x, i;    if (rq_data_dir(cmd->request) == WRITE)    {      aic_dev->w_total++;      ptr = aic_dev->w_bins;    }    else    {      aic_dev->r_total++;      ptr = aic_dev->r_bins;    }    if(cmd->device->simple_tags && cmd->request->flags & REQ_HARDBARRIER)    {      aic_dev->barrier_total++;      if(scb->tag_action == MSG_ORDERED_Q_TAG)        aic_dev->ordered_total++;    }    x = scb->sg_length;    x >>= 10;    for(i=0; i<6; i++)    {      x >>= 2;      if(!x) {        ptr[i]++;	break;      }    }    if(i == 6 && x)      ptr[5]++;  }  aic7xxx_free_scb(p, scb);  aic7xxx_queue_cmd_complete(p, cmd);}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/be7db055dd7261522557046370f49160728e3847/aic7xxx_old.c/clean/drivers/scsi/aic7xxx_old.c