unchar target = SCpnt->device->id; 
unchar target = scmd_id(SCpnt); 
static int aha1740_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *)){	unchar direction;	unchar *cmd = (unchar *) SCpnt->cmnd;	unchar target = SCpnt->device->id;	struct aha1740_hostdata *host = HOSTDATA(SCpnt->device->host);	unsigned long flags;	void *buff = SCpnt->request_buffer;	int bufflen = SCpnt->request_bufflen;	dma_addr_t sg_dma;	struct aha1740_sg *sgptr;	int ecbno;	DEB(int i);	if(*cmd == REQUEST_SENSE) {		SCpnt->result = 0;		done(SCpnt); 		return 0;	}#ifdef DEBUG	if (*cmd == READ_10 || *cmd == WRITE_10)		i = xscsi2int(cmd+2);	else if (*cmd == READ_6 || *cmd == WRITE_6)		i = scsi2int(cmd+2);	else		i = -1;	printk("aha1740_queuecommand: dev %d cmd %02x pos %d len %d ",	       target, *cmd, i, bufflen);	printk("scsi cmd:");	for (i = 0; i < SCpnt->cmd_len; i++) printk("%02x ", cmd[i]);	printk("\n");#endif	/* locate an available ecb */	spin_lock_irqsave(SCpnt->device->host->host_lock, flags);	ecbno = host->last_ecb_used + 1; /* An optimization */	if (ecbno >= AHA1740_ECBS)		ecbno = 0;	do {		if (!host->ecb[ecbno].cmdw)			break;		ecbno++;		if (ecbno >= AHA1740_ECBS)			ecbno = 0;	} while (ecbno != host->last_ecb_used);	if (host->ecb[ecbno].cmdw)		panic("Unable to find empty ecb for aha1740.\n");	host->ecb[ecbno].cmdw = AHA1740CMD_INIT; /* SCSI Initiator Command						    doubles as reserved flag */	host->last_ecb_used = ecbno;    	spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);#ifdef DEBUG	printk("Sending command (%d %x)...", ecbno, done);#endif	host->ecb[ecbno].cdblen = SCpnt->cmd_len; /* SCSI Command						   * Descriptor Block						   * Length */	direction = 0;	if (*cmd == READ_10 || *cmd == READ_6)		direction = 1;	else if (*cmd == WRITE_10 || *cmd == WRITE_6)		direction = 0;	memcpy(host->ecb[ecbno].cdb, cmd, SCpnt->cmd_len);	SCpnt->host_scribble = dma_alloc_coherent (&host->edev->dev,						   sizeof (struct aha1740_sg),						   &sg_dma, GFP_ATOMIC);	if(SCpnt->host_scribble == NULL) {		printk(KERN_WARNING "aha1740: out of memory in queuecommand!\n");		return 1;	}	sgptr = (struct aha1740_sg *) SCpnt->host_scribble;	sgptr->sg_dma_addr = sg_dma;    	if (SCpnt->use_sg) {		struct scatterlist * sgpnt;		struct aha1740_chain * cptr;		int i, count;		DEB(unsigned char * ptr);		host->ecb[ecbno].sg = 1;  /* SCSI Initiator Command					   * w/scatter-gather*/		sgpnt = (struct scatterlist *) SCpnt->request_buffer;		cptr = sgptr->sg_chain;		count = dma_map_sg (&host->edev->dev, sgpnt, SCpnt->use_sg,				    SCpnt->sc_data_direction);		for(i=0; i < count; i++) {			cptr[i].datalen = sg_dma_len (sgpnt + i);			cptr[i].dataptr = sg_dma_address (sgpnt + i);		}		host->ecb[ecbno].datalen = count*sizeof(struct aha1740_chain);		host->ecb[ecbno].dataptr = sg_dma;#ifdef DEBUG		printk("cptr %x: ",cptr);		ptr = (unsigned char *) cptr;		for(i=0;i<24;i++) printk("%02x ", ptr[i]);#endif	} else {		host->ecb[ecbno].datalen = bufflen;		sgptr->buf_dma_addr =  dma_map_single (&host->edev->dev,						       buff, bufflen,						       DMA_BIDIRECTIONAL);		host->ecb[ecbno].dataptr = sgptr->buf_dma_addr;	}	host->ecb[ecbno].lun = SCpnt->device->lun;	host->ecb[ecbno].ses = 1; /* Suppress underrun errors */	host->ecb[ecbno].dir = direction;	host->ecb[ecbno].ars = 1; /* Yes, get the sense on an error */	host->ecb[ecbno].senselen = 12;	host->ecb[ecbno].senseptr = ecb_cpu_to_dma (SCpnt->device->host,						    host->ecb[ecbno].sense);	host->ecb[ecbno].statusptr = ecb_cpu_to_dma (SCpnt->device->host,						     host->ecb[ecbno].status);	host->ecb[ecbno].done = done;	host->ecb[ecbno].SCpnt = SCpnt;#ifdef DEBUG	{		int i;		printk("aha1740_command: sending.. ");		for (i = 0; i < sizeof(host->ecb[ecbno]) - 10; i++)			printk("%02x ", ((unchar *)&host->ecb[ecbno])[i]);	}	printk("\n");#endif	if (done) {	/* The Adaptec Spec says the card is so fast that the loops           will only be executed once in the code below. Even if this           was true with the fastest processors when the spec was           written, it doesn't seem to be true with todays fast           processors. We print a warning if the code is executed more           often than LOOPCNT_WARN. If this happens, it should be           investigated. If the count reaches LOOPCNT_MAX, we assume           something is broken; since there is no way to return an           error (the return value is ignored by the mid-level scsi           layer) we have to panic (and maybe that's the best thing we           can do then anyhow). */#define LOOPCNT_WARN 10		/* excessive mbxout wait -> syslog-msg */#define LOOPCNT_MAX 1000000	/* mbxout deadlock -> panic() after ~ 2 sec. */		int loopcnt;		unsigned int base = SCpnt->device->host->io_port;		DEB(printk("aha1740[%d] critical section\n",ecbno));		spin_lock_irqsave(SCpnt->device->host->host_lock, flags);		for (loopcnt = 0; ; loopcnt++) {			if (inb(G2STAT(base)) & G2STAT_MBXOUT) break;			if (loopcnt == LOOPCNT_WARN) {				printk("aha1740[%d]_mbxout wait!\n",ecbno);			}			if (loopcnt == LOOPCNT_MAX)				panic("aha1740.c: mbxout busy!\n");		}		outl (ecb_cpu_to_dma (SCpnt->device->host, host->ecb + ecbno),		      MBOXOUT0(base));		for (loopcnt = 0; ; loopcnt++) {			if (! (inb(G2STAT(base)) & G2STAT_BUSY)) break;			if (loopcnt == LOOPCNT_WARN) {				printk("aha1740[%d]_attn wait!\n",ecbno);			}			if (loopcnt == LOOPCNT_MAX)				panic("aha1740.c: attn wait failed!\n");		}		outb(ATTN_START | (target & 7), ATTN(base)); /* Start it up */		spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);		DEB(printk("aha1740[%d] request queued.\n",ecbno));	} else		printk(KERN_ALERT "aha1740_queuecommand: done can't be NULL\n");	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/422c0d61d591cbfb70f029e13505fb437e169d68/aha1740.c/clean/drivers/scsi/aha1740.c