unsigned long flags, timeout; 
unsigned long timeout; #if 0 unsigned long flags; #endif 
static int esp_do_data(struct NCR_ESP *esp, struct ESP_regs *eregs){	Scsi_Cmnd *SCptr = esp->current_SC;	int thisphase, hmuch;	ESPDATA(("esp_do_data: "));	esp_maybe_nop(esp, eregs);	thisphase = sreg_to_dataphase(esp->sreg);	esp_advance_phase(SCptr, thisphase);	ESPDATA(("newphase<%s> ", (thisphase == in_datain) ? "DATAIN" : "DATAOUT"));	hmuch = esp->dma_can_transfer(esp, SCptr);	/*	 * XXX MSch: cater for PIO transfer here; PIO used if hmuch == 0	 */	if (hmuch) {	/* DMA */		/*		 * DMA		 */		ESPDATA(("hmuch<%d> ", hmuch));		esp->current_transfer_size = hmuch;		esp_setcount(eregs, (esp->fas_premature_intr_workaround ?				     (hmuch + 0x40) : hmuch));		esp->dma_setup(esp, (__u32)((unsigned long)SCptr->SCp.ptr), 			       hmuch, (thisphase == in_datain));		ESPDATA(("DMA|TI --> do_intr_end\n"));		esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);		return do_intr_end;		/*		 * end DMA		 */	} else {		/*		 * PIO		 */		int oldphase, i = 0; /* or where we left off last time ?? esp->current_data ?? */		int fifocnt = 0;		oldphase = esp_read(eregs->esp_status) & ESP_STAT_PMASK;		/*		 * polled transfer; ugly, can we make this happen in a DRQ 		 * interrupt handler ??		 * requires keeping track of state information in host or 		 * command struct!		 * Problem: I've never seen a DRQ happen on Mac, not even		 * with ESP_CMD_DMA ...		 */		/* figure out how much needs to be transferred */		hmuch = SCptr->SCp.this_residual;		ESPDATA(("hmuch<%d> pio ", hmuch));		esp->current_transfer_size = hmuch;		/* tell the ESP ... */		esp_setcount(eregs, hmuch);		/* loop */		while (hmuch) {			int j, fifo_stuck = 0, newphase;			unsigned long flags, timeout;#if 0			if ( i % 10 )				ESPDATA(("\r"));			else				ESPDATA(( /*"\n"*/ "\r"));#endif#if 0			local_irq_save(flags);#endif			if(thisphase == in_datain) {				/* 'go' ... */ 				esp_cmd(esp, eregs, ESP_CMD_TI);				/* wait for data */				timeout = 1000000;				while (!((esp->sreg=esp_read(eregs->esp_status)) & ESP_STAT_INTR) && --timeout)					udelay(2);				if (timeout == 0)					printk("DRQ datain timeout! \n");				newphase = esp->sreg & ESP_STAT_PMASK;				/* see how much we got ... */				fifocnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);				if (!fifocnt)					fifo_stuck++;				else					fifo_stuck = 0;				ESPDATA(("\rgot %d st %x ph %x", fifocnt, esp->sreg, newphase));				/* read fifo */				for(j=0;j<fifocnt;j++)					SCptr->SCp.ptr[i++] = esp_read(eregs->esp_fdata);				ESPDATA(("(%d) ", i));				/* how many to go ?? */				hmuch -= fifocnt;				/* break if status phase !! */				if(newphase == ESP_STATP) {					/* clear int. */					esp->ireg = esp_read(eregs->esp_intrpt);					break;				}			} else {#define MAX_FIFO 8				/* how much will fit ? */				int this_count = MAX_FIFO - fifocnt;				if (this_count > hmuch)					this_count = hmuch;				/* fill fifo */				for(j=0;j<this_count;j++)					esp_write(eregs->esp_fdata, SCptr->SCp.ptr[i++]);				/* how many left if this goes out ?? */				hmuch -= this_count;				/* 'go' ... */ 				esp_cmd(esp, eregs, ESP_CMD_TI);				/* wait for 'got it' */				timeout = 1000000;				while (!((esp->sreg=esp_read(eregs->esp_status)) & ESP_STAT_INTR) && --timeout)					udelay(2);				if (timeout == 0)					printk("DRQ dataout timeout!  \n");				newphase = esp->sreg & ESP_STAT_PMASK;				/* need to check how much was sent ?? */				fifocnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);				ESPDATA(("\rsent %d st %x ph %x", this_count - fifocnt, esp->sreg, newphase));				ESPDATA(("(%d) ", i));				/* break if status phase !! */				if(newphase == ESP_STATP) {					/* clear int. */					esp->ireg = esp_read(eregs->esp_intrpt);					break;				}			}			/* clear int. */			esp->ireg = esp_read(eregs->esp_intrpt);			ESPDATA(("ir %x ... ", esp->ireg));			if (hmuch == 0)				ESPDATA(("done! \n"));#if 0			local_irq_restore(flags);#endif			/* check new bus phase */			if (newphase != oldphase && i < esp->current_transfer_size) {				/* something happened; disconnect ?? */				ESPDATA(("phase change, dropped out with %d done ... ", i));				break;			}			/* check int. status */			if (esp->ireg & ESP_INTR_DC) {				/* disconnect */				ESPDATA(("disconnect; %d transferred ... ", i));				break;			} else if (esp->ireg & ESP_INTR_FDONE) {				/* function done */				ESPDATA(("function done; %d transferred ... ", i));				break;			}			/* XXX fixme: bail out on stall */			if (fifo_stuck > 10) {				/* we're stuck */				ESPDATA(("fifo stall; %d transferred ... ", i));				break;			}		}		ESPDATA(("\n"));		/* check successful completion ?? */		if (thisphase == in_dataout)			hmuch += fifocnt; /* stuck?? adjust data pointer ...*/		/* tell do_data_finale how much was transferred */		esp->current_transfer_size -= hmuch;		/* still not completely sure on this one ... */				return /*do_intr_end*/ do_work_bus /*do_phase_determine*/ ;		/*		 * end PIO		 */	}	return do_intr_end;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/cad359c68455d6870d053184bbb0ae208e207eef/NCR53C9x.c/clean/drivers/scsi/NCR53C9x.c