74 #if (NDEBUG & NDEBUG_LISTS)
76 { printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); \
77 if ((x)==(y)) udelay(5); }
78 #define REMOVE(w,x,y,z) \
79 { printk("LINE:%d Removing: %p->%p %p->%p \n", __LINE__, \
80 (void*)(w), (void*)(x), (void*)(y), (void*)(z)); \
81 if ((x)==(y)) udelay(5); }
84 #define REMOVE(w,x,y,z)
257 #define SETUP_HOSTDATA(in) \
258 struct NCR5380_hostdata *hostdata = \
259 (struct NCR5380_hostdata *)(in)->hostdata
260 #define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
262 #define NEXT(cmd) ((struct scsi_cmnd *)(cmd)->host_scribble)
263 #define SET_NEXT(cmd, next) ((cmd)->host_scribble = (void *)(next))
264 #define NEXTADDR(cmd) ((struct scsi_cmnd **)&((cmd)->host_scribble))
266 #define HOSTNO instance->host_no
267 #define H_NO(cmd) (cmd)->device->host->host_no
269 #define SGADDR(buffer) (void *)(((unsigned long)sg_virt(((buffer)))))
310 #define TAG_NONE 0xff
313 #if (MAX_TAGS % 32) != 0
314 #error "MAX_TAGS must be a multiple of 32!"
323 static TAG_ALLOC TagAlloc[8][8];
326 static void __init init_tags(
void )
331 if (!setup_use_tagged_queuing)
334 for( target = 0; target < 8; ++
target ) {
335 for( lun = 0; lun < 8; ++
lun ) {
338 ta->nr_allocated = 0;
356 static int is_lun_busy(
struct scsi_cmnd *
cmd,
int should_be_tagged)
362 if (!should_be_tagged ||
363 !setup_use_tagged_queuing || !cmd->
device->tagged_supported)
365 if (TagAlloc[cmd->
device->id][cmd->
device->lun].nr_allocated >=
366 TagAlloc[cmd->
device->id][cmd->
device->lun].queue_size ) {
367 TAG_PRINTK(
"scsi%d: target %d lun %d: no free tags\n",
380 static void cmd_get_tag(
struct scsi_cmnd *cmd,
int should_be_tagged)
387 if (!should_be_tagged ||
388 !setup_use_tagged_queuing || !cmd->
device->tagged_supported) {
391 TAG_PRINTK(
"scsi%d: target %d lun %d now allocated by untagged "
395 TAG_ALLOC *ta = &TagAlloc[cmd->
device->id][cmd->
device->lun];
400 TAG_PRINTK(
"scsi%d: using tag %d for target %d lun %d "
401 "(now %d tags in use)\n",
412 static void cmd_free_tag(
struct scsi_cmnd *cmd)
418 TAG_PRINTK(
"scsi%d: target %d lun %d untagged cmd finished\n",
426 TAG_ALLOC *ta = &TagAlloc[cmd->
device->id][cmd->
device->lun];
429 TAG_PRINTK(
"scsi%d: freed tag %d for target %d lun %d\n",
435 static void free_all_tags(
void )
440 if (!setup_use_tagged_queuing)
443 for( target = 0; target < 8; ++
target ) {
444 for( lun = 0; lun < 8; ++
lun ) {
447 ta->nr_allocated = 0;
471 if (scsi_bufflen(cmd)) {
472 cmd->
SCp.buffer = scsi_sglist(cmd);
473 cmd->
SCp.buffers_residual = scsi_sg_count(cmd) - 1;
475 cmd->
SCp.this_residual = cmd->
SCp.buffer->length;
478 cmd->
SCp.buffers_residual = 0;
480 cmd->
SCp.this_residual = 0;
514 static void NCR5380_print(
struct Scsi_Host *instance) {
525 printk(
"STATUS_REG: %02x ", status);
529 printk(
"\nBASR: %02x ", basr);
530 for (i = 0; basrs[
i].mask ; ++
i)
531 if (basr & basrs[i].mask)
533 printk(
"\nICR: %02x ", icr);
534 for (i = 0; icrs[
i].mask; ++
i)
535 if (icr & icrs[i].mask)
537 printk(
"\nMODE: %02x ", mr);
538 for (i = 0; mrs[
i].mask; ++
i)
539 if (mr & mrs[i].mask)
560 static void NCR5380_print_phase(
struct Scsi_Host *instance)
600 static volatile int main_running = 0;
617 static inline void NCR5380_all_init (
void)
649 " SCSI-2 TAGGED QUEUING"
664 static void NCR5380_print_status (
struct Scsi_Host *instance)
675 printk(
"NCR5380_print_status: no memory for print buffer\n");
700 #define SPRINTF(fmt,args...) \
701 do { if (pos + strlen(fmt) + 20 < buffer + length) \
702 pos += sprintf(pos, fmt , ## args); } while(0)
715 #define check_offset() \
717 if (pos - buffer < offset - begin) { \
718 begin += pos - buffer; \
731 SPRINTF(
"NCR5380: coroutine is%s running.\n", main_running ?
"" :
"n't");
737 pos, buffer, length);
742 pos = lprint_Scsi_Cmnd (ptr, pos, buffer, length);
750 pos = lprint_Scsi_Cmnd (ptr, pos, buffer, length);
755 *start = buffer + (offset - begin);
756 if (pos - buffer < offset - begin)
758 else if (pos - buffer - (offset - begin) <
length)
759 return pos - buffer - (offset - begin);
763 static char *lprint_Scsi_Cmnd(
struct scsi_cmnd *cmd,
char *pos,
char *buffer,
768 SPRINTF(
"scsi%d: destination target %d, lun %d\n",
772 SPRINTF(
"%2d (0x%02x)", command[0], command[0]);
802 for (i = hostdata->
id_mask; i <= 0x80; i <<= 1)
805 for (i = 0; i < 8; ++
i)
806 hostdata->
busy[i] = 0;
810 #if defined (REAL_DMA)
811 hostdata->dma_len = 0;
820 the_template = instance->
hostt;
821 first_instance = instance;
827 printk(
"scsi%d: WARNING : support for multiple outstanding commands enabled\n"
828 " without AUTOSENSE option, contingent allegiance conditions may\n"
829 " be incorrectly cleared.\n",
HOSTNO);
840 static void NCR5380_exit(
struct Scsi_Host *instance)
864 static int NCR5380_queue_command_lck(
struct scsi_cmnd *cmd,
871 #if (NDEBUG & NDEBUG_NO_WRITE)
872 switch (cmd->
cmnd[0]) {
891 # ifdef NCR5380_STAT_LIMIT
892 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
894 switch (cmd->
cmnd[0])
899 hostdata->time_write[cmd->
device->id] -= (
jiffies - hostdata->timebase);
900 hostdata->bytes_write[cmd->
device->id] += scsi_bufflen(cmd);
901 hostdata->pendingw++;
906 hostdata->time_read[cmd->
device->id] -= (
jiffies - hostdata->timebase);
907 hostdata->bytes_read[cmd->
device->id] += scsi_bufflen(cmd);
908 hostdata->pendingr++;
958 QU_PRINTK(
"scsi%d: command added to %s of queue\n",
H_NO(cmd),
992 struct Scsi_Host *instance = first_instance;
1033 #if (NDEBUG & NDEBUG_LISTS)
1035 tmp && (tmp != prev); prev = tmp, tmp =
NEXT(tmp))
1037 if ((tmp == prev) && tmp)
printk(
" LOOP\n");
1040 prev =
NULL; tmp; prev = tmp, tmp =
NEXT(tmp) ) {
1042 #if (NDEBUG & NDEBUG_LISTS)
1044 printk(
"MAIN tmp=%p target=%d busy=%d lun=%d\n",
1045 tmp, tmp->target, hostdata->
busy[tmp->target],
1077 MAIN_PRINTK(
"scsi%d: main(): command for target %d "
1078 "lun %d removed from issue_queue\n",
1079 HOSTNO, tmp->target, tmp->lun);
1093 if (!NCR5380_select(instance, tmp,
1103 cmd_free_tag( tmp );
1107 "returned to issue_queue\n",
HOSTNO);
1116 && !hostdata->dma_len
1120 MAIN_PRINTK(
"scsi%d: main: performing information transfer\n",
1122 NCR5380_information_transfer(instance);
1147 static void NCR5380_dma_complete(
struct Scsi_Host *instance )
1151 unsigned char **
data;
1152 volatile int *
count;
1156 "no connected cmd\n",
HOSTNO);
1160 DMA_PRINTK(
"scsi%d: real DMA transfer complete, basr 0x%X, sr 0x%X\n",
1165 printk(
"scsi%d: overrun in UDC counter -- not prepared to deal with this!\n",
HOSTNO);
1167 printk(
"error was produced.\n");
1176 printk(
"scsi%d: bus stuck in data phase -- probably a single byte "
1178 printk(
"not prepared for this error!\n");
1180 printk(
"error was produced.\n");
1191 hostdata->dma_len = 0;
1193 data = (
unsigned char **) &(hostdata->
connected->
SCp.ptr);
1195 *data += transfered;
1196 *count -= transfered;
1215 struct Scsi_Host *instance = first_instance;
1216 int done = 1, handled = 0;
1231 NCR5380_reselect(instance);
1248 #if defined(REAL_DMA)
1260 NCR5380_dma_complete( instance );
1267 if (basr & BASR_PHASE_MATCH)
1269 "BASR 0x%x, MR 0x%x, SR 0x%x\n",
1273 #ifdef SUN3_SCSI_VME
1283 "BASR 0x%X, MR 0x%X, SR 0x%x\n",
HOSTNO, basr,
1286 #ifdef SUN3_SCSI_VME
1299 #ifdef NCR5380_STATS
1303 # ifdef NCR5380_STAT_LIMIT
1304 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
1306 switch (cmd->
cmnd[0])
1311 hostdata->time_write[cmd->
device->id] += (
jiffies - hostdata->timebase);
1313 hostdata->pendingw--;
1318 hostdata->time_read[cmd->
device->id] += (
jiffies - hostdata->timebase);
1320 hostdata->pendingr--;
1361 unsigned char tmp[3],
phase;
1362 unsigned char *
data;
1365 unsigned long flags;
1397 unsigned long timeout =
jiffies + 2*NCR_TIMEOUT;
1404 printk(
"scsi : arbitration timeout at %d\n", __LINE__);
1436 ARB_PRINTK(
"scsi%d: lost arbitration, deasserting MR_ARBITRATE\n",
1451 ARB_PRINTK(
"scsi%d: lost arbitration, deasserting ICR_ASSERT_SEL\n",
1461 #ifdef CONFIG_ATARI_SCSI_TOSHIBA_DELAY
1563 NCR5380_reselect(instance);
1594 #ifdef NCR5380_STATS
1595 collect_stats(hostdata, cmd);
1598 cmd_free_tag( cmd );
1627 SEL_PRINTK(
"scsi%d: target %d selected, going into MESSAGE OUT phase.\n",
1646 NCR5380_transfer_pio(instance, &phase, &len, &data);
1650 #ifndef SUPPORT_TAGS
1653 #ifdef SUN3_SCSI_VME
1656 initialize_SCp(cmd);
1687 static int NCR5380_transfer_pio(
struct Scsi_Host *instance,
1688 unsigned char *phase,
int *count,
1689 unsigned char **data)
1693 register unsigned char *
d = *
data;
1735 if (!((p &
SR_MSG) && c > 1)) {
1784 if ((tmp & SR_REQ) || (p ==
PHASE_MSGIN && c == 0))
1789 if (!c || (*phase == p))
1837 NCR5380_transfer_pio (host, &phase, &len, &msgptr);
1844 return len ? -1 : 0;
1847 #if defined(REAL_DMA)
1868 static int NCR5380_transfer_dma(
struct Scsi_Host *instance,
1869 unsigned char *phase,
int *count,
1870 unsigned char **data)
1873 register int c = *
count;
1874 register unsigned char p = *
phase;
1875 unsigned long flags;
1878 if(!sun3_dma_setup_done) {
1879 printk(
"scsi%d: transfer_dma without setup!\n",
HOSTNO);
1882 hostdata->dma_len =
c;
1884 DMA_PRINTK(
"scsi%d: initializing DMA for %s, %d bytes %s %p\n",
1885 HOSTNO, (p & SR_IO) ?
"reading" :
"writing",
1886 c, (p & SR_IO) ?
"to" :
"from", *data);
1892 sun3scsi_dma_start(c, *data);
1908 #ifdef SUN3_SCSI_VME
1914 sun3_dma_active = 1;
1936 static void NCR5380_information_transfer (
struct Scsi_Host *instance)
1939 unsigned long flags;
1943 #if defined(REAL_DMA)
1946 unsigned char *
data;
1947 unsigned char phase,
tmp, extended_msg[10], old_phase=0xff;
1959 if (phase != old_phase) {
1966 unsigned long count;
1968 if (!cmd->
SCp.this_residual && cmd->
SCp.buffers_residual) {
1969 count = cmd->
SCp.buffer->length;
1972 count = cmd->
SCp.this_residual;
1980 if (cmd->
request->cmd_type == REQ_TYPE_FS) {
1981 sun3scsi_dma_setup(d, count,
1983 sun3_dma_setup_done =
cmd;
1987 #ifdef SUN3_SCSI_VME
2007 #if (NDEBUG & NDEBUG_NO_DATAOUT)
2008 printk(
"scsi%d: NDEBUG_NO_DATAOUT set, attempted DATAOUT "
2021 if (!cmd->
SCp.this_residual && cmd->
SCp.buffers_residual) {
2023 --cmd->
SCp.buffers_residual;
2024 cmd->
SCp.this_residual = cmd->
SCp.buffer->length;
2026 INF_PRINTK(
"scsi%d: %d bytes and %d buffers left\n",
2028 cmd->
SCp.buffers_residual);
2046 #if defined(REAL_DMA)
2053 if (NCR5380_transfer_dma(instance, &phase,
2054 &len, (
unsigned char **) &cmd->
SCp.ptr)) {
2060 "lun %d to slow handshake\n",
HOSTNO,
2079 cmd->
SCp.this_residual -= transfersize - len;
2084 NCR5380_transfer_pio(instance, &phase,
2085 (
int *) &cmd->
SCp.this_residual, (
unsigned char **)
2089 if(sun3_dma_setup_done == cmd)
2090 sun3_dma_setup_done =
NULL;
2098 NCR5380_transfer_pio(instance, &phase, &len, &data);
2118 LNK_PRINTK(
"scsi%d: target %d lun %d linked command "
2129 if (!cmd->next_link) {
2131 "linked command complete, no next_link\n",
2134 do_abort (instance);
2138 initialize_SCp(cmd->next_link);
2141 cmd->next_link->
tag = cmd->
tag;
2142 cmd->
result = cmd->
SCp.Status | (cmd->
SCp.Message << 8);
2143 LNK_PRINTK(
"scsi%d: target %d lun %d linked request "
2144 "done, calling scsi_done().\n",
2146 #ifdef NCR5380_STATS
2147 collect_stats(hostdata, cmd);
2158 QU_PRINTK(
"scsi%d: command for target %d, lun %d "
2161 cmd_free_tag( cmd );
2171 TAG_ALLOC *ta = &TagAlloc[cmd->
device->id][cmd->
device->lun];
2172 TAG_PRINTK(
"scsi%d: target %d lun %d returned "
2173 "QUEUE_FULL after %d commands\n",
2176 if (ta->queue_size > ta->nr_allocated)
2177 ta->nr_allocated = ta->queue_size;
2202 cmd->
result = cmd->
SCp.Status | (cmd->
SCp.Message << 8);
2208 hostdata->ses.cmd_len) {
2210 hostdata->ses.cmd_len = 0 ;
2228 QU_PRINTK(
"scsi%d: REQUEST SENSE added to head of "
2229 "issue queue\n",
H_NO(cmd));
2233 #ifdef NCR5380_STATS
2234 collect_stats(hostdata, cmd);
2265 cmd->
device->tagged_supported = 0;
2268 TAG_PRINTK(
"scsi%d: target %d lun %d rejected "
2269 "QUEUE_TAG message; tagged queuing "
2279 cmd->
device->disconnect = 1;
2285 QU_PRINTK(
"scsi%d: command for target %d lun %d was "
2286 "moved from connected to the "
2287 "disconnected_queue\n",
HOSTNO,
2300 #ifdef SUN3_SCSI_VME
2341 data = extended_msg + 1;
2343 NCR5380_transfer_pio(instance, &phase, &len, &data);
2345 (
int)extended_msg[1], (
int)extended_msg[2]);
2347 if (!len && extended_msg[1] <=
2348 (
sizeof (extended_msg) - 1)) {
2351 len = extended_msg[1] - 1;
2352 data = extended_msg + 3;
2355 NCR5380_transfer_pio(instance, &phase, &len, &data);
2356 EXT_PRINTK(
"scsi%d: message received, residual %d\n",
2359 switch (extended_msg[2]) {
2368 "extended message\n",
HOSTNO);
2372 "code %02x length %d is too long\n",
2373 HOSTNO, extended_msg[2], extended_msg[1]);
2389 "message %02x from target %d, lun %d\n",
2394 "code %02x, length %d from target %d, lun %d\n",
2395 HOSTNO, extended_msg[1], extended_msg[0],
2409 NCR5380_transfer_pio(instance, &phase, &len, &data);
2410 if (msgout ==
ABORT) {
2412 cmd_free_tag( cmd );
2418 #ifdef NCR5380_STATS
2419 collect_stats(hostdata, cmd);
2435 NCR5380_transfer_pio(instance, &phase, &len,
2441 NCR5380_transfer_pio(instance, &phase, &len, &data);
2466 static void NCR5380_reselect (
struct Scsi_Host *instance)
2469 unsigned char target_mask;
2474 unsigned char msg[3];
2518 if (!(msg[0] & 0x80)) {
2524 lun = (msg[0] & 0x07);
2533 if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun)
2535 && (tag == tmp->tag)
2555 "not in disconnected_queue.\n",
2572 unsigned long count;
2574 if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
2575 count = tmp->SCp.buffer->length;
2576 d =
SGADDR(tmp->SCp.buffer);
2578 count = tmp->SCp.this_residual;
2585 sun3scsi_dma_setup(d, count, rq_data_dir(tmp->request));
2586 sun3_dma_setup_done =
tmp;
2602 if (phase ==
PHASE_MSGIN && setup_use_tagged_queuing) {
2607 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
2610 TAG_PRINTK(
"scsi%d: target mask %02x, lun %d sent tag %d at "
2611 "reselection\n",
HOSTNO, target_mask, lun, tag);
2616 RSL_PRINTK(
"scsi%d: nexus established, target = %d, lun = %d, tag = %d\n",
2617 HOSTNO, tmp->target, tmp->lun, tmp->tag);
2643 unsigned long flags;
2648 NCR5380_print_status (instance);
2683 if (do_abort(instance) == 0) {
2688 cmd_free_tag( cmd );
2697 printk(
"scsi%d: abort of connected command failed!\n",
HOSTNO);
2712 (*prev) =
NEXT(tmp);
2716 ABRT_PRINTK(
"scsi%d: abort removed command from issue queue.\n",
2772 if (NCR5380_select (instance, cmd, (
int) cmd->
tag))
2777 do_abort (instance);
2793 cmd_free_tag( tmp );
2814 printk(
KERN_INFO "scsi%d: warning : SCSI command probably completed successfully before abortion\n",
HOSTNO);
2833 unsigned long flags;
2835 struct scsi_cmnd *connected, *disconnected_queue;
2839 NCR5380_print_status (cmd->
device->host);
2874 for( i = 0; i < 8; ++
i )
2875 hostdata->
busy[i] = 0;
2877 hostdata->dma_len = 0;
2886 if ((cmd = connected)) {
2887 ABRT_PRINTK(
"scsi%d: reset aborted a connected command\n",
H_NO(cmd));
2892 for (i = 0; (cmd = disconnected_queue); ++
i) {
2893 disconnected_queue =
NEXT(cmd);
2899 ABRT_PRINTK(
"scsi: reset aborted %d disconnected command(s)\n", i);
2935 ABRT_PRINTK(
"scsi%d: reset aborted a connected command\n",
H_NO(cmd));
2937 ABRT_PRINTK(
"scsi%d: reset aborted disconnected command(s)\n",
H_NO(cmd));
2946 for( i = 0; i < 8; ++
i )
2947 hostdata->
busy[i] = 0;
2949 hostdata->dma_len = 0;