sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg, scsi_to_pci_dma_dir(Cmnd->sc_data_direction)); 
sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg, Cmnd->sc_data_direction); 
static int isp2x00_queuecommand(Scsi_Cmnd * Cmnd, void (*done) (Scsi_Cmnd *)){	int i, sg_count, 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 isp2x00_hostdata *hostdata;	ENTER("isp2x00_queuecommand");	host = Cmnd->device->host;	hostdata = (struct isp2x00_hostdata *) host->hostdata;	Cmnd->scsi_done = done;	DEBUG(isp2x00_print_scsi_cmd(Cmnd));	if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {		isp2x00_make_portdb(host);		hostdata->adapter_state = AS_LOOP_GOOD;		printk("qlogicfc%d : Port Database\n", hostdata->host_id);		for (i = 0; hostdata->port_db[i].wwn != 0; i++) {			printk("wwn: %08x%08x  scsi_id: %x  loop_id: ", (u_int) (hostdata->port_db[i].wwn >> 32), (u_int) hostdata->port_db[i].wwn, i);			if (hostdata->port_db[i].loop_id != hostdata->port_db[0].loop_id || i == 0)			        printk("%x", hostdata->port_db[i].loop_id);			else			        printk("Not Available");			printk("\n");		}	}	if (hostdata->adapter_state == AS_FIRMWARE_DEAD) {		printk("qlogicfc%d : The firmware is dead, just return.\n", hostdata->host_id);		host->max_id = 0;		return 0;	}	out_ptr = inw(host->io_port + MBOX4);	in_ptr = hostdata->req_in_ptr;	DEBUG(printk("qlogicfc%d : request queue depth %d\n", hostdata->host_id,		     REQ_QUEUE_DEPTH(in_ptr, out_ptr)));	cmd = (struct Command_Entry *) &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];	in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;	if (in_ptr == out_ptr) {		DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata->host_id));		return 1;	}	if (hostdata->send_marker) {		struct Marker_Entry *marker;		TRACE("queue marker", in_ptr, 0);		DEBUG(printk("qlogicfc%d : adding marker entry\n", hostdata->host_id));		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) & QLOGICFC_REQ_QUEUE_LEN) == out_ptr) {			outw(in_ptr, host->io_port + MBOX4);			hostdata->req_in_ptr = in_ptr;			DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata->host_id));			return 1;		}		cmd = (struct Command_Entry *) &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];		in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;	}	TRACE("queue command", in_ptr, Cmnd);	memset(cmd, 0, sizeof(struct Command_Entry));	/* find a free handle mapping slot */	for (i = in_ptr; i != (in_ptr - 1) && hostdata->handle_ptrs[i]; i = ((i + 1) % (QLOGICFC_REQ_QUEUE_LEN + 1)));	if (!hostdata->handle_ptrs[i]) {		cmd->handle = cpu_to_le32(i);		hostdata->handle_ptrs[i] = Cmnd;		hostdata->handle_serials[i] = Cmnd->serial_number;	} else {		printk("qlogicfc%d : no handle slots, this should not happen.\n", hostdata->host_id);		printk("hostdata->queued is %x, in_ptr: %x\n", hostdata->queued, in_ptr);		for (i = 0; i <= QLOGICFC_REQ_QUEUE_LEN; i++){			if (!hostdata->handle_ptrs[i]){				printk("slot %d has %p\n", i, hostdata->handle_ptrs[i]);			}		}		return 1;	}	cmd->hdr.entry_type = ENTRY_COMMAND;	cmd->hdr.entry_cnt = 1;	cmd->target_lun = Cmnd->device->lun;	cmd->expanded_lun = cpu_to_le16(Cmnd->device->lun);#if ISP2x00_PORTDB	cmd->target_id = hostdata->port_db[Cmnd->device->id].loop_id;#else	cmd->target_id = Cmnd->target;#endif	cmd->total_byte_cnt = cpu_to_le32(Cmnd->request_bufflen);	cmd->time_out = 0;	memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);	if (Cmnd->use_sg) {		sg = (struct scatterlist *) Cmnd->request_buffer;		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);		ds = cmd->dataseg;		/* fill in first two sg entries: */		n = sg_count;		if (n > DATASEGS_PER_COMMAND)			n = DATASEGS_PER_COMMAND;		for (i = 0; i < n; i++) {			ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));			ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));			ds[i].d_count = cpu_to_le32(sg_dma_len(sg));			++sg;		}		sg_count -= DATASEGS_PER_COMMAND;		while (sg_count > 0) {			++cmd->hdr.entry_cnt;			cont = (struct Continuation_Entry *)			    &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];			memset(cont, 0, sizeof(struct Continuation_Entry));			in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;			if (in_ptr == out_ptr) {				DEBUG(printk("qlogicfc%d : unexpected request queue overflow\n", hostdata->host_id));				return 1;			}			TRACE("queue continuation", in_ptr, 0);			cont->hdr.entry_type = ENTRY_CONTINUATION;			ds = cont->dataseg;			n = sg_count;			if (n > DATASEGS_PER_CONT)				n = DATASEGS_PER_CONT;			for (i = 0; i < n; ++i) {				ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));				ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));				ds[i].d_count = cpu_to_le32(sg_dma_len(sg));				++sg;			}			sg_count -= n;		}	} else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE) {		struct page *page = virt_to_page(Cmnd->request_buffer);		unsigned long offset = offset_in_page(Cmnd->request_buffer);		dma_addr_t busaddr = pci_map_page(hostdata->pci_dev,						  page, offset,						  Cmnd->request_bufflen,						  scsi_to_pci_dma_dir(Cmnd->sc_data_direction));		Cmnd->SCp.dma_handle = busaddr;		cmd->dataseg[0].d_base = cpu_to_le32(pci64_dma_lo32(busaddr));		cmd->dataseg[0].d_base_hi = cpu_to_le32(pci64_dma_hi32(busaddr));		cmd->dataseg[0].d_count = cpu_to_le32(Cmnd->request_bufflen);		cmd->segment_cnt = cpu_to_le16(1);	} else {		cmd->dataseg[0].d_base = 0;		cmd->dataseg[0].d_base_hi = 0;		cmd->segment_cnt = cpu_to_le16(1); /* Shouldn't this be 0? */	}	if (Cmnd->sc_data_direction == SCSI_DATA_WRITE)		cmd->control_flags = cpu_to_le16(CFLAG_WRITE);	else 		cmd->control_flags = cpu_to_le16(CFLAG_READ);	if (Cmnd->device->tagged_supported) {		if ((jiffies - hostdata->tag_ages[Cmnd->device->id]) > (2 * ISP_TIMEOUT)) {			cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);			hostdata->tag_ages[Cmnd->device->id] = jiffies;		} else			switch (Cmnd->tag) {			case HEAD_OF_QUEUE_TAG:				cmd->control_flags |= cpu_to_le16(CFLAG_HEAD_TAG);				break;			case ORDERED_QUEUE_TAG:				cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);				break;			default:				cmd->control_flags |= cpu_to_le16(CFLAG_SIMPLE_TAG);				break;		}	}	/*	 * TEST_UNIT_READY commands from scsi_scan will fail due to "overlapped	 * commands attempted" unless we setup at least a simple queue (midlayer 	 * will embelish this once it can do an INQUIRY command to the device)	 */	else		cmd->control_flags |= cpu_to_le16(CFLAG_SIMPLE_TAG);	outw(in_ptr, host->io_port + MBOX4);	hostdata->req_in_ptr = in_ptr;	hostdata->queued++;	num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);	num_free = (num_free > 2) ? num_free - 2 : 0;       host->can_queue = host->host_busy + num_free;	if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)		host->can_queue = QLOGICFC_REQ_QUEUE_LEN;	host->sg_tablesize = QLOGICFC_MAX_SG(num_free);	LEAVE("isp2x00_queuecommand");	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/be7db055dd7261522557046370f49160728e3847/qlogicfc.c/clean/drivers/scsi/qlogicfc.c