scsi_to_pci_dma_dir(cmd->sc_data_direction)); 
cmd->sc_data_direction); 
ahc_linux_run_device_queue(struct ahc_softc *ahc, struct ahc_linux_device *dev){	struct	 ahc_cmd *acmd;	struct	 scsi_cmnd *cmd;	struct	 scb *scb;	struct	 hardware_scb *hscb;	struct	 ahc_initiator_tinfo *tinfo;	struct	 ahc_tmode_tstate *tstate;	uint16_t mask;	if ((dev->flags & AHC_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 (ahc->platform_data->qfrozen != 0	 	 && AHC_DV_SIMQ_FROZEN(ahc) == 0) {			TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,					  dev, links);			dev->flags |= AHC_DEV_ON_RUN_LIST;			return;		}		/*		 * Get an scb to use.		 */		if ((scb = ahc_get_scb(ahc)) == NULL) {			TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,					 dev, links);			dev->flags |= AHC_DEV_ON_RUN_LIST;			ahc->flags |= AHC_RESOURCE_SHORTAGE;			return;		}		TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe);		cmd = &acmd_scsi_cmd(acmd);		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(ahc, cmd);		hscb->lun = cmd->device->lun;		mask = SCB_GET_TARGET_MASK(ahc, scb);		tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb),					    SCB_GET_OUR_ID(scb),					    SCB_GET_TARGET(ahc, scb), &tstate);		hscb->scsirate = tinfo->scsirate;		hscb->scsioffset = tinfo->curr.offset;		if ((tstate->ultraenb & mask) != 0)			hscb->control |= ULTRAENB;		if ((ahc->user_discenable & mask) != 0)			hscb->control |= DISCENB;	 	if (AHC_DV_CMD(cmd) != 0)			scb->flags |= SCB_SILENT;		if ((tstate->auto_negotiate & mask) != 0) {			scb->flags |= SCB_AUTO_NEGOTIATE;			scb->hscb->control |= MK_MESSAGE;		}		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];			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 == AHC_OTAG_THRESH			 && (dev->flags & AHC_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;		if (hscb->cdb_len <= 12) {			memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len);		} else {			memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len);			scb->flags |= SCB_CDB32_PTR;		}		scb->platform_data->xfer_len = 0;		ahc_set_residual(scb, 0);		ahc_set_sense_residual(scb, 0);		scb->sg_count = 0;		if (cmd->use_sg != 0) {			struct	ahc_dma_seg *sg;			struct	scatterlist *cur_seg;			struct	scatterlist *end_seg;			int	nseg;			cur_seg = (struct scatterlist *)cmd->request_buffer;			nseg = pci_map_sg(ahc->dev_softc, cur_seg, cmd->use_sg,			    scsi_to_pci_dma_dir(cmd->sc_data_direction));			end_seg = cur_seg + nseg;			/* Copy the segments into the SG list. */			sg = scb->sg_list;			/*			 * The sg_count may be larger than nseg if			 * a transfer crosses a 32bit page.			 */ 			while (cur_seg < end_seg) {				dma_addr_t addr;				bus_size_t len;				int consumed;				addr = sg_dma_address(cur_seg);				len = sg_dma_len(cur_seg);				consumed = ahc_linux_map_seg(ahc, scb,							     sg, addr, len);				sg += consumed;				scb->sg_count += consumed;				cur_seg++;			}			sg--;			sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);			/*			 * Reset the sg list pointer.			 */			scb->hscb->sgptr =			    ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);			/*			 * Copy the first SG into the "current"			 * data pointer area.			 */			scb->hscb->dataptr = scb->sg_list->addr;			scb->hscb->datacnt = scb->sg_list->len;		} else if (cmd->request_bufflen != 0) {			struct	 ahc_dma_seg *sg;			dma_addr_t addr;			sg = scb->sg_list;			addr = pci_map_single(ahc->dev_softc,			       cmd->request_buffer,			       cmd->request_bufflen,			       scsi_to_pci_dma_dir(cmd->sc_data_direction));			scb->platform_data->buf_busaddr = addr;			scb->sg_count = ahc_linux_map_seg(ahc, scb,							  sg, addr,							  cmd->request_bufflen);			sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);			/*			 * Reset the sg list pointer.			 */			scb->hscb->sgptr =			    ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);			/*			 * Copy the first SG into the "current"			 * data pointer area.			 */			scb->hscb->dataptr = sg->addr;			scb->hscb->datacnt = sg->len;		} else {			scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);			scb->hscb->dataptr = 0;			scb->hscb->datacnt = 0;			scb->sg_count = 0;		}		ahc_sync_sglist(ahc, scb, BUS_DMASYNC_PREWRITE);		LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links);		dev->openings--;		dev->active++;		dev->commands_issued++;		if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)			dev->commands_since_idle_or_otag++;		/*		 * We only allow one untagged transaction		 * per target in the initiator role unless		 * we are storing a full busy target *lun*		 * table in SCB space.		 */		if ((scb->hscb->control & (TARGET_SCB|TAG_ENB)) == 0		 && (ahc->features & AHC_SCB_BTT) == 0) {			struct scb_tailq *untagged_q;			int target_offset;			target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);			untagged_q = &(ahc->untagged_queues[target_offset]);			TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);			scb->flags |= SCB_UNTAGGEDQ;			if (TAILQ_FIRST(untagged_q) != scb)				continue;		}		scb->flags |= SCB_ACTIVE;		ahc_queue_scb(ahc, scb);	}}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/be7db055dd7261522557046370f49160728e3847/aic7xxx_osm.c/buggy/drivers/scsi/aic7xxx/aic7xxx_osm.c