79 #if (NDEBUG & NDEBUG_LISTS)
82 printk("LINE:%d Adding %p to %p\n", \
83 __LINE__, (void*)(x), (void*)(y)); \
87 #define REMOVE(w, x, y, z) \
89 printk("LINE:%d Removing: %p->%p %p->%p \n", \
90 __LINE__, (void*)(w), (void*)(x), \
91 (void*)(y), (void*)(z)); \
97 #define REMOVE(w,x,y,z)
270 #define SETUP_HOSTDATA(in) \
271 struct NCR5380_hostdata *hostdata = \
272 (struct NCR5380_hostdata *)(in)->hostdata
273 #define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
275 #define NEXT(cmd) ((Scsi_Cmnd *)(cmd)->host_scribble)
276 #define SET_NEXT(cmd,next) ((cmd)->host_scribble = (void *)(next))
277 #define NEXTADDR(cmd) ((Scsi_Cmnd **)&(cmd)->host_scribble)
279 #define HOSTNO instance->host_no
280 #define H_NO(cmd) (cmd)->device->host->host_no
321 #define TAG_NONE 0xff
329 static TAG_ALLOC TagAlloc[8][8];
332 static void __init init_tags(
void)
337 if (!setup_use_tagged_queuing)
340 for (target = 0; target < 8; ++
target) {
341 for (lun = 0; lun < 8; ++
lun) {
343 bitmap_zero(ta->allocated,
MAX_TAGS);
344 ta->nr_allocated = 0;
362 static int is_lun_busy(
Scsi_Cmnd *
cmd,
int should_be_tagged)
368 if (!should_be_tagged ||
369 !setup_use_tagged_queuing || !cmd->
device->tagged_supported)
371 if (TagAlloc[cmd->
device->id][cmd->
device->lun].nr_allocated >=
372 TagAlloc[cmd->
device->id][cmd->
device->lun].queue_size) {
373 TAG_PRINTK(
"scsi%d: target %d lun %d: no free tags\n",
386 static void cmd_get_tag(
Scsi_Cmnd *cmd,
int should_be_tagged)
393 if (!should_be_tagged ||
394 !setup_use_tagged_queuing || !cmd->
device->tagged_supported) {
397 TAG_PRINTK(
"scsi%d: target %d lun %d now allocated by untagged "
400 TAG_ALLOC *ta = &TagAlloc[cmd->
device->id][cmd->
device->lun];
405 TAG_PRINTK(
"scsi%d: using tag %d for target %d lun %d "
406 "(now %d tags in use)\n",
408 cmd->
device->lun, ta->nr_allocated);
423 TAG_PRINTK(
"scsi%d: target %d lun %d untagged cmd finished\n",
429 TAG_ALLOC *ta = &TagAlloc[cmd->
device->id][cmd->
device->lun];
432 TAG_PRINTK(
"scsi%d: freed tag %d for target %d lun %d\n",
438 static void free_all_tags(
void)
443 if (!setup_use_tagged_queuing)
446 for (target = 0; target < 8; ++
target) {
447 for (lun = 0; lun < 8; ++
lun) {
449 bitmap_zero(ta->allocated,
MAX_TAGS);
450 ta->nr_allocated = 0;
470 static void merge_contiguous_buffers(
Scsi_Cmnd *cmd)
472 unsigned long endaddr;
473 #if (NDEBUG & NDEBUG_MERGING)
474 unsigned long oldlen = cmd->
SCp.this_residual;
479 cmd->
SCp.buffers_residual &&
483 #if (NDEBUG & NDEBUG_MERGING)
487 --cmd->
SCp.buffers_residual;
488 cmd->
SCp.this_residual += cmd->
SCp.buffer->length;
489 endaddr += cmd->
SCp.buffer->length;
491 #if (NDEBUG & NDEBUG_MERGING)
492 if (oldlen != cmd->
SCp.this_residual)
493 MER_PRINTK(
"merged %d buffers from %p, new length %08x\n",
494 cnt, cmd->
SCp.ptr, cmd->
SCp.this_residual);
507 static inline void initialize_SCp(
Scsi_Cmnd *cmd)
514 if (scsi_bufflen(cmd)) {
515 cmd->
SCp.buffer = scsi_sglist(cmd);
516 cmd->
SCp.buffers_residual = scsi_sg_count(cmd) - 1;
517 cmd->
SCp.ptr = sg_virt(cmd->
SCp.buffer);
518 cmd->
SCp.this_residual = cmd->
SCp.buffer->length;
522 merge_contiguous_buffers(cmd);
525 cmd->
SCp.buffers_residual = 0;
527 cmd->
SCp.this_residual = 0;
565 static void NCR5380_print(
struct Scsi_Host *instance)
577 printk(
"STATUS_REG: %02x ", status);
581 printk(
"\nBASR: %02x ", basr);
582 for (i = 0; basrs[
i].mask; ++
i)
583 if (basr & basrs[i].mask)
585 printk(
"\nICR: %02x ", icr);
586 for (i = 0; icrs[
i].mask; ++
i)
587 if (icr & icrs[i].mask)
589 printk(
"\nMODE: %02x ", mr);
590 for (i = 0; mrs[
i].mask; ++
i)
591 if (mr & mrs[i].mask)
613 static void NCR5380_print_phase(
struct Scsi_Host *instance)
632 static inline void NCR5380_print(
struct Scsi_Host *instance)
635 static inline void NCR5380_print_phase(
struct Scsi_Host *instance)
658 static volatile int main_running;
661 static inline void queue_main(
void)
675 static inline void NCR5380_all_init(
void)
707 " SCSI-2 TAGGED QUEUING"
722 static void NCR5380_print_status(
struct Scsi_Host *instance)
733 printk(
"NCR5380_print_status: no memory for print buffer\n");
758 #define SPRINTF(fmt,args...) \
760 if (pos + strlen(fmt) + 20 < buffer + length) \
761 pos += sprintf(pos, fmt , ## args); \
773 #define check_offset() \
775 if (pos - buffer < offset - begin) { \
776 begin += pos - buffer; \
788 SPRINTF(
"NCR5380: coroutine is%s running.\n",
789 main_running ?
"" :
"n't");
795 pos, buffer, length);
799 pos = lprint_Scsi_Cmnd(ptr, pos, buffer, length);
807 pos = lprint_Scsi_Cmnd(ptr, pos, buffer, length);
812 *start = buffer + (offset - begin);
813 if (pos - buffer < offset - begin)
815 else if (pos - buffer - (offset - begin) <
length)
816 return pos - buffer - (offset - begin);
820 static char *lprint_Scsi_Cmnd(
Scsi_Cmnd *cmd,
char *pos,
char *buffer,
int length)
824 SPRINTF(
"scsi%d: destination target %d, lun %d\n",
828 SPRINTF(
"%2d (0x%02x)", command[0], command[0]);
858 for (i = hostdata->
id_mask; i <= 0x80; i <<= 1)
861 for (i = 0; i < 8; ++
i)
862 hostdata->
busy[i] = 0;
866 #if defined (REAL_DMA)
867 hostdata->dma_len = 0;
876 the_template = instance->
hostt;
877 first_instance = instance;
882 printk(
"scsi%d: WARNING : support for multiple outstanding commands enabled\n"
883 " without AUTOSENSE option, contingent allegiance conditions may\n"
884 " be incorrectly cleared.\n",
HOSTNO);
895 static void NCR5380_exit(
struct Scsi_Host *instance)
924 #if (NDEBUG & NDEBUG_NO_WRITE)
925 switch (cmd->
cmnd[0]) {
943 # ifdef NCR5380_STAT_LIMIT
944 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
946 switch (cmd->
cmnd[0]) {
950 hostdata->time_write[cmd->
device->id] -= (
jiffies - hostdata->timebase);
951 hostdata->bytes_write[cmd->
device->id] += scsi_bufflen(cmd);
952 hostdata->pendingw++;
957 hostdata->time_read[cmd->
device->id] -= (
jiffies - hostdata->timebase);
958 hostdata->bytes_read[cmd->
device->id] += scsi_bufflen(cmd);
959 hostdata->pendingr++;
1012 QU_PRINTK(
"scsi%d: command added to %s of queue\n",
H_NO(cmd),
1046 struct Scsi_Host *instance = first_instance;
1049 unsigned long flags;
1087 #if (NDEBUG & NDEBUG_LISTS)
1089 tmp && (tmp != prev); prev = tmp, tmp =
NEXT(tmp))
1092 if ((tmp == prev) && tmp)
1097 prev =
NULL; tmp; prev = tmp, tmp =
NEXT(tmp)) {
1099 #if (NDEBUG & NDEBUG_LISTS)
1101 printk(
"MAIN tmp=%p target=%d busy=%d lun=%d\n",
1124 falcon_dont_release++;
1135 MAIN_PRINTK(
"scsi%d: main(): command for target %d "
1136 "lun %d removed from issue_queue\n",
1151 if (!NCR5380_select(instance, tmp,
1154 falcon_dont_release--;
1156 falcon_release_lock_if_possible(hostdata);
1166 falcon_dont_release--;
1169 "returned to issue_queue\n",
HOSTNO);
1179 && !hostdata->dma_len
1183 MAIN_PRINTK(
"scsi%d: main: performing information transfer\n",
1185 NCR5380_information_transfer(instance);
1210 static void NCR5380_dma_complete(
struct Scsi_Host *instance)
1213 int transfered, saved_data = 0,
overrun = 0,
cnt, toPIO;
1214 unsigned char **
data,
p;
1215 volatile int *
count;
1219 "no connected cmd\n",
HOSTNO);
1223 if (atari_read_overruns) {
1237 DMA_PRINTK(
"scsi%d: real DMA transfer complete, basr 0x%X, sr 0x%X\n",
1246 hostdata->dma_len = 0;
1248 data = (
unsigned char **)&hostdata->
connected->
SCp.ptr;
1250 *data += transfered;
1251 *count -= transfered;
1253 if (atari_read_overruns) {
1255 cnt = toPIO = atari_read_overruns;
1257 DMA_PRINTK(
"Got an input overrun, using saved byte\n");
1258 *(*data)++ = saved_data;
1263 DMA_PRINTK(
"Doing %d-byte PIO to 0x%08lx\n", cnt, (
long)*data);
1264 NCR5380_transfer_pio(instance, &p, &cnt, data);
1265 *count -= toPIO -
cnt;
1285 struct Scsi_Host *instance = first_instance;
1286 int done = 1, handled = 0;
1301 NCR5380_reselect(instance);
1315 #if defined(REAL_DMA)
1327 NCR5380_dma_complete( instance );
1334 if (basr & BASR_PHASE_MATCH)
1336 "BASR 0x%x, MR 0x%x, SR 0x%x\n",
1345 "BASR 0x%X, MR 0x%X, SR 0x%x\n",
HOSTNO, basr,
1358 #ifdef NCR5380_STATS
1361 # ifdef NCR5380_STAT_LIMIT
1362 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
1364 switch (cmd->
cmnd[0]) {
1368 hostdata->time_write[cmd->
device->id] += (
jiffies - hostdata->timebase);
1370 hostdata->pendingw--;
1375 hostdata->time_read[cmd->
device->id] += (
jiffies - hostdata->timebase);
1377 hostdata->pendingr--;
1417 unsigned char tmp[3],
phase;
1418 unsigned char *
data;
1421 unsigned long flags;
1450 #if defined(NCR_TIMEOUT)
1452 unsigned long timeout =
jiffies + 2*NCR_TIMEOUT;
1458 printk(
"scsi : arbitration timeout at %d\n", __LINE__);
1491 ARB_PRINTK(
"scsi%d: lost arbitration, deasserting MR_ARBITRATE\n",
1506 ARB_PRINTK(
"scsi%d: lost arbitration, deasserting ICR_ASSERT_SEL\n",
1516 #ifdef CONFIG_ATARI_SCSI_TOSHIBA_DELAY
1618 NCR5380_reselect(instance);
1650 #ifdef NCR5380_STATS
1651 collect_stats(hostdata, cmd);
1684 SEL_PRINTK(
"scsi%d: target %d selected, going into MESSAGE OUT phase.\n",
1703 NCR5380_transfer_pio(instance, &phase, &len, &data);
1707 #ifndef SUPPORT_TAGS
1711 initialize_SCp(cmd);
1741 static int NCR5380_transfer_pio(
struct Scsi_Host *instance,
1742 unsigned char *phase,
int *count,
1743 unsigned char **data)
1745 register unsigned char p = *
phase,
tmp;
1747 register unsigned char *
d = *
data;
1768 if ((tmp & PHASE_MASK) != p) {
1790 if (!((p &
SR_MSG) && c > 1)) {
1840 if ((tmp & SR_REQ) || (p ==
PHASE_MSGIN && c == 0))
1845 if (!c || (*phase == p))
1895 NCR5380_transfer_pio(host, &phase, &len, &msgptr);
1902 return len ? -1 : 0;
1905 #if defined(REAL_DMA)
1926 static int NCR5380_transfer_dma(
struct Scsi_Host *instance,
1927 unsigned char *phase,
int *count,
1928 unsigned char **data)
1931 register int c = *
count;
1932 register unsigned char p = *
phase;
1933 register unsigned char *d = *
data;
1935 unsigned long flags;
1942 if (atari_read_overruns && (p & SR_IO))
1943 c -= atari_read_overruns;
1945 DMA_PRINTK(
"scsi%d: initializing DMA for %s, %d bytes %s %p\n",
1946 HOSTNO, (p & SR_IO) ?
"reading" :
"writing",
1947 c, (p & SR_IO) ?
"to" :
"from", d);
1960 hostdata->dma_len = (p &
SR_IO) ?
1978 hostdata->dma_len = (p &
SR_IO) ?
2004 static void NCR5380_information_transfer(
struct Scsi_Host *instance)
2007 unsigned long flags;
2011 #if defined(REAL_DMA)
2014 unsigned char *
data;
2015 unsigned char phase,
tmp, extended_msg[10], old_phase = 0xff;
2023 if (phase != old_phase) {
2043 #if (NDEBUG & NDEBUG_NO_DATAOUT)
2044 printk(
"scsi%d: NDEBUG_NO_DATAOUT set, attempted DATAOUT "
2058 if (!cmd->
SCp.this_residual && cmd->
SCp.buffers_residual) {
2060 --cmd->
SCp.buffers_residual;
2061 cmd->
SCp.this_residual = cmd->
SCp.buffer->length;
2062 cmd->
SCp.ptr = sg_virt(cmd->
SCp.buffer);
2066 merge_contiguous_buffers(cmd);
2067 INF_PRINTK(
"scsi%d: %d bytes and %d buffers left\n",
2069 cmd->
SCp.buffers_residual);
2087 #if defined(REAL_DMA)
2088 if (!cmd->
device->borken &&
2092 if (NCR5380_transfer_dma(instance, &phase,
2093 &len, (
unsigned char **)&cmd->
SCp.ptr)) {
2099 "lun %d to slow handshake\n",
HOSTNO,
2118 cmd->
SCp.this_residual -= transfersize - len;
2123 NCR5380_transfer_pio(instance, &phase,
2124 (
int *)&cmd->
SCp.this_residual,
2125 (
unsigned char **)&cmd->
SCp.ptr);
2131 NCR5380_transfer_pio(instance, &phase, &len, &data);
2151 LNK_PRINTK(
"scsi%d: target %d lun %d linked command "
2162 if (!cmd->next_link) {
2164 "linked command complete, no next_link\n",
2171 initialize_SCp(cmd->next_link);
2174 cmd->next_link->
tag = cmd->
tag;
2175 cmd->
result = cmd->
SCp.Status | (cmd->
SCp.Message << 8);
2176 LNK_PRINTK(
"scsi%d: target %d lun %d linked request "
2177 "done, calling scsi_done().\n",
2179 #ifdef NCR5380_STATS
2180 collect_stats(hostdata, cmd);
2191 falcon_dont_release++;
2193 QU_PRINTK(
"scsi%d: command for target %d, lun %d "
2206 TAG_ALLOC *ta = &TagAlloc[cmd->
device->id][cmd->
device->lun];
2207 TAG_PRINTK(
"scsi%d: target %d lun %d returned "
2208 "QUEUE_FULL after %d commands\n",
2211 if (ta->queue_size > ta->nr_allocated)
2212 ta->nr_allocated = ta->queue_size;
2237 cmd->
result = cmd->
SCp.Status | (cmd->
SCp.Message << 8);
2243 hostdata->ses.cmd_len) {
2245 hostdata->ses.cmd_len = 0 ;
2259 QU_PRINTK(
"scsi%d: REQUEST SENSE added to head of "
2260 "issue queue\n",
H_NO(cmd));
2264 #ifdef NCR5380_STATS
2265 collect_stats(hostdata, cmd);
2280 falcon_dont_release--;
2285 falcon_release_lock_if_possible(hostdata);
2302 cmd->
device->tagged_supported = 0;
2305 TAG_PRINTK(
"scsi%d: target %d lun %d rejected "
2306 "QUEUE_TAG message; tagged queuing "
2316 cmd->
device->disconnect = 1;
2322 QU_PRINTK(
"scsi%d: command for target %d lun %d was "
2323 "moved from connected to the "
2324 "disconnected_queue\n",
HOSTNO,
2375 data = extended_msg + 1;
2377 NCR5380_transfer_pio(instance, &phase, &len, &data);
2379 (
int)extended_msg[1], (
int)extended_msg[2]);
2381 if (!len && extended_msg[1] <=
2382 (
sizeof(extended_msg) - 1)) {
2385 len = extended_msg[1] - 1;
2386 data = extended_msg + 3;
2389 NCR5380_transfer_pio(instance, &phase, &len, &data);
2390 EXT_PRINTK(
"scsi%d: message received, residual %d\n",
2393 switch (extended_msg[2]) {
2402 "extended message\n",
HOSTNO);
2406 "code %02x length %d is too long\n",
2407 HOSTNO, extended_msg[2], extended_msg[1]);
2423 "message %02x from target %d, lun %d\n",
2428 "code %02x, length %d from target %d, lun %d\n",
2429 HOSTNO, extended_msg[1], extended_msg[0],
2442 NCR5380_transfer_pio(instance, &phase, &len, &data);
2443 if (msgout ==
ABORT) {
2451 #ifdef NCR5380_STATS
2452 collect_stats(hostdata, cmd);
2456 falcon_release_lock_if_possible(hostdata);
2469 NCR5380_transfer_pio(instance, &phase, &len, &data);
2474 NCR5380_transfer_pio(instance, &phase, &len, &data);
2497 static void NCR5380_reselect(
struct Scsi_Host *instance)
2500 unsigned char target_mask;
2506 unsigned char msg[3];
2507 unsigned char *
data;
2548 NCR5380_transfer_pio(instance, &phase, &len, &data);
2550 if (!(msg[0] & 0x80)) {
2556 lun = (msg[0] & 0x07);
2564 if (phase ==
PHASE_MSGIN && setup_use_tagged_queuing) {
2569 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
2572 TAG_PRINTK(
"scsi%d: target mask %02x, lun %d sent tag %d at "
2573 "reselection\n",
HOSTNO, target_mask, lun, tag);
2583 tmp; prev = tmp, tmp =
NEXT(tmp)) {
2584 if ((target_mask == (1 << tmp->
device->id)) && (lun == tmp->
device->lun)
2586 && (tag == tmp->
tag)
2590 falcon_dont_release++;
2608 "not in disconnected_queue.\n",
2626 RSL_PRINTK(
"scsi%d: nexus established, target = %d, lun = %d, tag = %d\n",
2628 falcon_dont_release--;
2655 unsigned long flags;
2660 NCR5380_print_status(instance);
2664 if (!
IS_A_TT() && !falcon_got_lock)
2665 printk(
KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_abort\n",
2699 if (do_abort(instance) == 0) {
2710 falcon_release_lock_if_possible(hostdata);
2714 printk(
"scsi%d: abort of connected command failed!\n",
HOSTNO);
2729 (*prev) =
NEXT(tmp);
2733 ABRT_PRINTK(
"scsi%d: abort removed command from issue queue.\n",
2738 falcon_release_lock_if_possible(hostdata);
2791 if (NCR5380_select(instance, cmd, (
int)cmd->
tag))
2818 falcon_release_lock_if_possible(hostdata);
2836 printk(
KERN_INFO "scsi%d: warning : SCSI command probably completed successfully before abortion\n",
HOSTNO);
2842 falcon_release_lock_if_possible(hostdata);
2861 unsigned long flags;
2863 Scsi_Cmnd *connected, *disconnected_queue;
2866 if (!
IS_A_TT() && !falcon_got_lock)
2867 printk(
KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_reset\n",
2870 NCR5380_print_status(cmd->
device->host);
2905 for (i = 0; i < 8; ++
i)
2906 hostdata->
busy[i] = 0;
2908 hostdata->dma_len = 0;
2917 if ((cmd = connected)) {
2918 ABRT_PRINTK(
"scsi%d: reset aborted a connected command\n",
H_NO(cmd));
2923 for (i = 0; (cmd = disconnected_queue); ++
i) {
2924 disconnected_queue =
NEXT(cmd);
2930 ABRT_PRINTK(
"scsi: reset aborted %d disconnected command(s)\n", i);
2972 ABRT_PRINTK(
"scsi%d: reset aborted a connected command\n",
H_NO(cmd));
2974 ABRT_PRINTK(
"scsi%d: reset aborted disconnected command(s)\n",
H_NO(cmd));
2983 for (i = 0; i < 8; ++
i)
2984 hostdata->
busy[i] = 0;
2986 hostdata->dma_len = 0;