NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->device->id))); 
NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << scmd_id(cmd)))); 
static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd * cmd, int tag) {	NCR5380_local_declare();	struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata;	unsigned char tmp[3], phase;	unsigned char *data;	int len;	unsigned long timeout;	unsigned char value;	int err;	NCR5380_setup(instance);	if (hostdata->selecting)		goto part2;	hostdata->restart_select = 0;	NCR5380_dprint(NDEBUG_ARBITRATION, instance);	dprintk(NDEBUG_ARBITRATION, ("scsi%d : starting arbitration, id = %d\n", instance->host_no, instance->this_id));	/* 	 * Set the phase bits to 0, otherwise the NCR5380 won't drive the 	 * data bus during SELECTION.	 */	NCR5380_write(TARGET_COMMAND_REG, 0);	/* 	 * Start arbitration.	 */	NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);	NCR5380_write(MODE_REG, MR_ARBITRATE);	/* We can be relaxed here, interrupts are on, we are	   in workqueue context, the birds are singing in the trees */	spin_unlock_irq(instance->host_lock);	err = NCR5380_poll_politely(instance, INITIATOR_COMMAND_REG, ICR_ARBITRATION_PROGRESS, ICR_ARBITRATION_PROGRESS, 5*HZ);	spin_lock_irq(instance->host_lock);	if (err < 0) {		printk(KERN_DEBUG "scsi: arbitration timeout at %d\n", __LINE__);		NCR5380_write(MODE_REG, MR_BASE);		NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);		goto failed;	}	dprintk(NDEBUG_ARBITRATION, ("scsi%d : arbitration complete\n", instance->host_no));	/* 	 * The arbitration delay is 2.2us, but this is a minimum and there is 	 * no maximum so we can safely sleep for ceil(2.2) usecs to accommodate	 * the integral nature of udelay().	 *	 */	udelay(3);	/* Check for lost arbitration */	if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) || (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) || (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST)) {		NCR5380_write(MODE_REG, MR_BASE);		dprintk(NDEBUG_ARBITRATION, ("scsi%d : lost arbitration, deasserting MR_ARBITRATE\n", instance->host_no));		goto failed;	}	NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_SEL);	if (!(hostdata->flags & FLAG_DTC3181E) &&	    /* RvC: DTC3181E has some trouble with this	     *      so we simply removed it. Seems to work with	     *      only Mustek scanner attached	     */	    (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST)) {		NCR5380_write(MODE_REG, MR_BASE);		NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);		dprintk(NDEBUG_ARBITRATION, ("scsi%d : lost arbitration, deasserting ICR_ASSERT_SEL\n", instance->host_no));		goto failed;	}	/* 	 * Again, bus clear + bus settle time is 1.2us, however, this is 	 * a minimum so we'll udelay ceil(1.2)	 */	udelay(2);	dprintk(NDEBUG_ARBITRATION, ("scsi%d : won arbitration\n", instance->host_no));	/* 	 * Now that we have won arbitration, start Selection process, asserting 	 * the host and target ID's on the SCSI bus.	 */	NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->device->id)));	/* 	 * Raise ATN while SEL is true before BSY goes false from arbitration,	 * since this is the only way to guarantee that we'll get a MESSAGE OUT	 * phase immediately after selection.	 */	NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY | ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL));	NCR5380_write(MODE_REG, MR_BASE);	/* 	 * Reselect interrupts must be turned off prior to the dropping of BSY,	 * otherwise we will trigger an interrupt.	 */	NCR5380_write(SELECT_ENABLE_REG, 0);	/*	 * The initiator shall then wait at least two deskew delays and release 	 * the BSY signal.	 */	udelay(1);		/* wingel -- wait two bus deskew delay >2*45ns */	/* Reset BSY */	NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL));	/* 	 * Something weird happens when we cease to drive BSY - looks	 * like the board/chip is letting us do another read before the 	 * appropriate propagation delay has expired, and we're confusing	 * a BSY signal from ourselves as the target's response to SELECTION.	 *	 * A small delay (the 'C++' frontend breaks the pipeline with an	 * unnecessary jump, making it work on my 386-33/Trantor T128, the	 * tighter 'C' code breaks and requires this) solves the problem - 	 * the 1 us delay is arbitrary, and only used because this delay will 	 * be the same on other platforms and since it works here, it should 	 * work there.	 *	 * wingel suggests that this could be due to failing to wait	 * one deskew delay.	 */	udelay(1);	dprintk(NDEBUG_SELECTION, ("scsi%d : selecting target %d\n", instance->host_no, cmd->device->id));	/* 	 * The SCSI specification calls for a 250 ms timeout for the actual 	 * selection.	 */	timeout = jiffies + (250 * HZ / 1000);	/* 	 * XXX very interesting - we're seeing a bounce where the BSY we 	 * asserted is being reflected / still asserted (propagation delay?)	 * and it's detecting as true.  Sigh.	 */	hostdata->select_time = 0;	/* we count the clock ticks at which we polled */	hostdata->selecting = cmd;part2:	/* RvC: here we enter after a sleeping period, or immediately after	   execution of part 1	   we poll only once ech clock tick */	value = NCR5380_read(STATUS_REG) & (SR_BSY | SR_IO);	if (!value && (hostdata->select_time < HZ/4)) {		/* RvC: we still must wait for a device response */		hostdata->select_time++;	/* after 25 ticks the device has failed */		NCR5380_set_timer(hostdata, 1);		return 0;	/* RvC: we return here with hostdata->selecting set,				   to go to sleep */	}	hostdata->selecting = NULL;/* clear this pointer, because we passed the					   waiting period */	if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) {		NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);		NCR5380_reselect(instance);		printk("scsi%d : reselection after won arbitration?\n", instance->host_no);		NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);		return -1;	}	/* 	 * No less than two deskew delays after the initiator detects the 	 * BSY signal is true, it shall release the SEL signal and may 	 * change the DATA BUS.                                     -wingel	 */	udelay(1);	NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);	if (!(NCR5380_read(STATUS_REG) & SR_BSY)) {		NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);		if (hostdata->targets_present & (1 << cmd->device->id)) {			printk(KERN_DEBUG "scsi%d : weirdness\n", instance->host_no);			if (hostdata->restart_select)				printk(KERN_DEBUG "\trestart select\n");			NCR5380_dprint(NDEBUG_SELECTION, instance);			NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);			return -1;		}		cmd->result = DID_BAD_TARGET << 16;		collect_stats(hostdata, cmd);		cmd->scsi_done(cmd);		NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);		dprintk(NDEBUG_SELECTION, ("scsi%d : target did not respond within 250ms\n", instance->host_no));		NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);		return 0;	}	hostdata->targets_present |= (1 << cmd->device->id);	/*	 * Since we followed the SCSI spec, and raised ATN while SEL 	 * was true but before BSY was false during selection, the information	 * transfer phase should be a MESSAGE OUT phase so that we can send the	 * IDENTIFY message.	 * 	 * If SCSI-II tagged queuing is enabled, we also send a SIMPLE_QUEUE_TAG	 * message (2 bytes) with a tag ID that we increment with every command	 * until it wraps back to 0.	 *	 * XXX - it turns out that there are some broken SCSI-II devices,	 *       which claim to support tagged queuing but fail when more than	 *       some number of commands are issued at once.	 */	/* Wait for start of REQ/ACK handshake */	spin_unlock_irq(instance->host_lock);	err = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ);	spin_lock_irq(instance->host_lock);		if(err) {		printk(KERN_ERR "scsi%d: timeout at NCR5380.c:%d\n", instance->host_no, __LINE__);		NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);		goto failed;	}	dprintk(NDEBUG_SELECTION, ("scsi%d : target %d selected, going into MESSAGE OUT phase.\n", instance->host_no, cmd->device->id));	tmp[0] = IDENTIFY(((instance->irq == SCSI_IRQ_NONE) ? 0 : 1), cmd->device->lun);	len = 1;	cmd->tag = 0;	/* Send message(s) */	data = tmp;	phase = PHASE_MSGOUT;	NCR5380_transfer_pio(instance, &phase, &len, &data);	dprintk(NDEBUG_SELECTION, ("scsi%d : nexus established.\n", instance->host_no));	/* XXX need to handle errors here */	hostdata->connected = cmd;	hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);	if (cmd->SCp.ptr != (char *)cmd->sense_buffer) {		initialize_SCp(cmd);	}	return 0;	/* Selection failed */failed:	return -1;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/422c0d61d591cbfb70f029e13505fb437e169d68/NCR5380.c/clean/drivers/scsi/NCR5380.c