scsi_to_pci_dma_dir(cmd->sc_data_direction)); 
cmd->sc_data_direction); 
aic7xxx_buildscb(struct aic7xxx_host *p, Scsi_Cmnd *cmd,    struct aic7xxx_scb *scb){  unsigned short mask;  struct aic7xxx_hwscb *hscb;  struct aic_dev_data *aic_dev = cmd->device->hostdata;  struct scsi_device *sdptr = cmd->device;  unsigned char tindex = TARGET_INDEX(cmd);  struct request *req = cmd->request;  mask = (0x01 << tindex);  hscb = scb->hscb;  /*   * Setup the control byte if we need negotiation and have not   * already requested it.   */  hscb->control = 0;  scb->tag_action = 0;  if (p->discenable & mask)  {    hscb->control |= DISCENB;    /* We always force TEST_UNIT_READY to untagged */    if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags)    {      if (req->flags & REQ_HARDBARRIER)      {	if(sdptr->ordered_tags)	{          hscb->control |= MSG_ORDERED_Q_TAG;          scb->tag_action = MSG_ORDERED_Q_TAG;	}      }      else      {        hscb->control |= MSG_SIMPLE_Q_TAG;        scb->tag_action = MSG_SIMPLE_Q_TAG;      }    }  }  if ( !(aic_dev->dtr_pending) &&        (aic_dev->needppr || aic_dev->needwdtr || aic_dev->needsdtr) &&        (aic_dev->flags & DEVICE_DTR_SCANNED) )  {    aic_dev->dtr_pending = 1;    scb->tag_action = 0;    hscb->control &= DISCENB;    hscb->control |= MK_MESSAGE;    if(aic_dev->needppr)    {      scb->flags |= SCB_MSGOUT_PPR;    }    else if(aic_dev->needwdtr)    {      scb->flags |= SCB_MSGOUT_WDTR;    }    else if(aic_dev->needsdtr)    {      scb->flags |= SCB_MSGOUT_SDTR;    }    scb->flags |= SCB_DTR_SCB;  }  hscb->target_channel_lun = ((cmd->device->id << 4) & 0xF0) |        ((cmd->device->channel & 0x01) << 3) | (cmd->device->lun & 0x07);  /*   * The interpretation of request_buffer and request_bufflen   * changes depending on whether or not use_sg is zero; a   * non-zero use_sg indicates the number of elements in the   * scatter-gather array.   */  /*   * XXX - this relies on the host data being stored in a   *       little-endian format.   */  hscb->SCSI_cmd_length = cmd->cmd_len;  memcpy(scb->cmnd, cmd->cmnd, cmd->cmd_len);  hscb->SCSI_cmd_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, scb->cmnd));  if (cmd->use_sg)  {    struct scatterlist *sg;  /* Must be mid-level SCSI code scatterlist */    /*     * We must build an SG list in adapter format, as the kernel's SG list     * cannot be used directly because of data field size (__alpha__)     * differences and the kernel SG list uses virtual addresses where     * we need physical addresses.     */    int i, use_sg;    sg = (struct scatterlist *)cmd->request_buffer;    scb->sg_length = 0;    use_sg = pci_map_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction));    /*     * Copy the segments into the SG array.  NOTE!!! - We used to     * have the first entry both in the data_pointer area and the first     * SG element.  That has changed somewhat.  We still have the first     * entry in both places, but now we download the address of     * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.     */    for (i = 0; i < use_sg; i++)    {      unsigned int len = sg_dma_len(sg+i);      scb->sg_list[i].address = cpu_to_le32(sg_dma_address(sg+i));      scb->sg_list[i].length = cpu_to_le32(len);      scb->sg_length += len;    }    /* Copy the first SG into the data pointer area. */    hscb->data_pointer = scb->sg_list[0].address;    hscb->data_count = scb->sg_list[0].length;    scb->sg_count = i;    hscb->SG_segment_count = i;    hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[1]));  }  else  {    if (cmd->request_bufflen)    {      unsigned int address = pci_map_single(p->pdev, cmd->request_buffer,					    cmd->request_bufflen,                                            scsi_to_pci_dma_dir(cmd->sc_data_direction));      aic7xxx_mapping(cmd) = address;      scb->sg_list[0].address = cpu_to_le32(address);      scb->sg_list[0].length = cpu_to_le32(cmd->request_bufflen);      scb->sg_count = 1;      scb->sg_length = cmd->request_bufflen;      hscb->SG_segment_count = 1;      hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[0]));      hscb->data_count = scb->sg_list[0].length;      hscb->data_pointer = scb->sg_list[0].address;    }    else    {      scb->sg_count = 0;      scb->sg_length = 0;      hscb->SG_segment_count = 0;      hscb->SG_list_pointer = 0;      hscb->data_count = 0;      hscb->data_pointer = 0;    }  }}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/be7db055dd7261522557046370f49160728e3847/aic7xxx_old.c/clean/drivers/scsi/aic7xxx_old.c