scsi_to_pci_dma_dir(Cmnd->sc_data_direction)); 
Cmnd->sc_data_direction); 
static int isp1020_queuecommand(Scsi_Cmnd *Cmnd, void (*done)(Scsi_Cmnd *)){	int i, n, num_free;	u_int in_ptr, out_ptr;	struct dataseg * ds;	struct scatterlist *sg;	struct Command_Entry *cmd;	struct Continuation_Entry *cont;	struct Scsi_Host *host;	struct isp1020_hostdata *hostdata;	dma_addr_t	dma_addr;	ENTER("isp1020_queuecommand");	host = Cmnd->device->host;	hostdata = (struct isp1020_hostdata *) host->hostdata;	Cmnd->scsi_done = done;	DEBUG(isp1020_print_scsi_cmd(Cmnd));	out_ptr = isp_inw(host, + MBOX4);	in_ptr  = hostdata->req_in_ptr;	DEBUG(printk("qlogicisp : request queue depth %d\n",		     REQ_QUEUE_DEPTH(in_ptr, out_ptr)));	cmd = (struct Command_Entry *) &hostdata->req_cpu[in_ptr];	in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;	if (in_ptr == out_ptr) {		printk("qlogicisp : request queue overflow\n");		return 1;	}	if (hostdata->send_marker) {		struct Marker_Entry *marker;		TRACE("queue marker", in_ptr, 0);		DEBUG(printk("qlogicisp : adding marker entry\n"));		marker = (struct Marker_Entry *) cmd;		memset(marker, 0, sizeof(struct Marker_Entry));		marker->hdr.entry_type = ENTRY_MARKER;		marker->hdr.entry_cnt = 1;		marker->modifier = SYNC_ALL;		hostdata->send_marker = 0;		if (((in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN) == out_ptr) {			isp_outw(in_ptr, host, MBOX4);			hostdata->req_in_ptr = in_ptr;			printk("qlogicisp : request queue overflow\n");			return 1;		}		cmd = (struct Command_Entry *) &hostdata->req_cpu[in_ptr];		in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;	}	TRACE("queue command", in_ptr, Cmnd);	memset(cmd, 0, sizeof(struct Command_Entry));	cmd->hdr.entry_type = ENTRY_COMMAND;	cmd->hdr.entry_cnt = 1;	cmd->target_lun = Cmnd->device->lun;	cmd->target_id = Cmnd->device->id;	cmd->cdb_length = cpu_to_le16(Cmnd->cmd_len);	cmd->control_flags = cpu_to_le16(CFLAG_READ | CFLAG_WRITE);	cmd->time_out = cpu_to_le16(30);	memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);	if (Cmnd->use_sg) {		int sg_count;		sg = (struct scatterlist *) Cmnd->request_buffer;		ds = cmd->dataseg;		sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg,				      scsi_to_pci_dma_dir(Cmnd->sc_data_direction));		cmd->segment_cnt = cpu_to_le16(sg_count);		/* fill in first four sg entries: */		n = sg_count;		if (n > IOCB_SEGS)			n = IOCB_SEGS;		for (i = 0; i < n; i++) {			dma_addr = sg_dma_address(sg);			ds[i].d_base  = cpu_to_le32((u32) dma_addr);#ifdef CONFIG_QL_ISP_A64			ds[i].d_base_hi = cpu_to_le32((u32) (dma_addr>>32));#endif /* CONFIG_QL_ISP_A64 */			ds[i].d_count = cpu_to_le32(sg_dma_len(sg));			++sg;		}		sg_count -= IOCB_SEGS;		while (sg_count > 0) {			++cmd->hdr.entry_cnt;			cont = (struct Continuation_Entry *)				&hostdata->req_cpu[in_ptr];			in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;			if (in_ptr == out_ptr) {				printk("isp1020: unexpected request queue "				       "overflow\n");				return 1;			}			TRACE("queue continuation", in_ptr, 0);			cont->hdr.entry_type = ENTRY_CONTINUATION;			cont->hdr.entry_cnt  = 0;			cont->hdr.sys_def_1  = 0;			cont->hdr.flags      = 0;#ifndef CONFIG_QL_ISP_A64			cont->reserved = 0;#endif			ds = cont->dataseg;			n = sg_count;			if (n > CONTINUATION_SEGS)				n = CONTINUATION_SEGS;			for (i = 0; i < n; ++i) {				dma_addr = sg_dma_address(sg);				ds[i].d_base = cpu_to_le32((u32) dma_addr);#ifdef CONFIG_QL_ISP_A64				ds[i].d_base_hi = cpu_to_le32((u32)(dma_addr>>32));#endif /* CONFIG_QL_ISP_A64 */				ds[i].d_count = cpu_to_le32(sg_dma_len(sg));				++sg;			}			sg_count -= n;		}	} else if (Cmnd->request_bufflen) {		/*Cmnd->SCp.ptr = (char *)(unsigned long)*/		dma_addr = pci_map_single(hostdata->pci_dev,				       Cmnd->request_buffer,				       Cmnd->request_bufflen,				       scsi_to_pci_dma_dir(Cmnd->sc_data_direction));		Cmnd->SCp.ptr = (char *)(unsigned long) dma_addr;		cmd->dataseg[0].d_base =			cpu_to_le32((u32) dma_addr);#ifdef CONFIG_QL_ISP_A64		cmd->dataseg[0].d_base_hi =			cpu_to_le32((u32) (dma_addr>>32));#endif /* CONFIG_QL_ISP_A64 */		cmd->dataseg[0].d_count =			cpu_to_le32((u32)Cmnd->request_bufflen);		cmd->segment_cnt = cpu_to_le16(1);	} else {		cmd->dataseg[0].d_base = 0;#ifdef CONFIG_QL_ISP_A64		cmd->dataseg[0].d_base_hi = 0;#endif /* CONFIG_QL_ISP_A64 */		cmd->dataseg[0].d_count = 0;		cmd->segment_cnt = cpu_to_le16(1); /* Shouldn't this be 0? */	}	/* Committed, record Scsi_Cmd so we can find it later. */	cmd->handle = in_ptr;	hostdata->cmd_slots[in_ptr] = Cmnd;	isp_outw(in_ptr, host, MBOX4);	hostdata->req_in_ptr = in_ptr;	num_free = QLOGICISP_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);	host->can_queue = host->host_busy + num_free;	host->sg_tablesize = QLOGICISP_MAX_SG(num_free);	LEAVE("isp1020_queuecommand");	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/be7db055dd7261522557046370f49160728e3847/qlogicisp.c/clean/drivers/scsi/qlogicisp.c