This source file includes following definitions.
- initialize_SCp
- NCR5380_print
- NCR5380_print_phase
- run_main
- should_disconnect
- NCR5380_set_timer
- NCR5380_timer_fn
- NCR5380_all_init
- probe_intr
- NCR5380_probe_irq
- NCR5380_print_options
- NCR5380_print_status
- NCR5380_init
- NCR5380_queue_command
- NCR5380_main
- NCR5380_intr
- NCR5380_select
- NCR5380_transfer_pio
- NCR5380_transfer_dma
- NCR5380_information_transfer
- NCR5380_reselect
- NCR5380_dma_complete
- NCR5380_abort
- NCR5380_reset
1 #define NDEBUG (NDEBUG_RESTART_SELECT)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 #ifndef notyet
70 #undef LINKED
71 #undef USLEEP
72 #undef REAL_DMA
73 #endif
74
75 #ifdef REAL_DMA_POLL
76 #undef READ_OVERRUNS
77 #define READ_OVERRUNS
78 #endif
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282 static struct Scsi_Host *first_instance = NULL;
283 static Scsi_Host_Template *the_template = NULL;
284
285
286
287
288
289
290
291
292
293
294 static __inline__ void initialize_SCp(Scsi_Cmnd *cmd) {
295
296
297
298
299
300 if (cmd->use_sg) {
301 cmd->SCp.buffer = (struct scatterlist *) cmd->buffer;
302 cmd->SCp.buffers_residual = cmd->use_sg - 1;
303 cmd->SCp.ptr = (char *) cmd->SCp.buffer->address;
304 cmd->SCp.this_residual = cmd->SCp.buffer->length;
305 } else {
306 cmd->SCp.buffer = NULL;
307 cmd->SCp.buffers_residual = 0;
308 cmd->SCp.ptr = (char *) cmd->request_buffer;
309 cmd->SCp.this_residual = cmd->request_bufflen;
310 }
311 }
312
313 #include <linux/delay.h>
314
315 #ifdef NDEBUG
316 static struct {
317 unsigned char mask;
318 char * name;}
319 signals[] = {{ SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" },
320 { SR_REQ, "REQ" }, { SR_MSG, "MSG" }, { SR_CD, "CD" }, { SR_IO, "IO" },
321 { SR_SEL, "SEL" }, {0, NULL}},
322 basrs[] = {{BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL}},
323 icrs[] = {{ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"},
324 {ICR_ASSERT_BSY, "ASSERT BSY"}, {ICR_ASSERT_SEL, "ASSERT SEL"},
325 {ICR_ASSERT_ATN, "ASSERT ATN"}, {ICR_ASSERT_DATA, "ASSERT DATA"},
326 {0, NULL}},
327 mrs[] = {{MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
328 {MR_ENABLE_PAR_CHECK, "MODE PARITY CHECK"}, {MR_ENABLE_PAR_INTR,
329 "MODE PARITY INTR"}, {MR_MONITOR_BSY, "MODE MONITOR BSY"},
330 {MR_DMA_MODE, "MODE DMA"}, {MR_ARBITRATE, "MODE ARBITRATION"},
331 {0, NULL}};
332
333
334
335
336
337
338
339
340
341 static void NCR5380_print(struct Scsi_Host *instance) {
342 NCR5380_local_declare();
343 unsigned char status, data, basr, mr, icr, i;
344 NCR5380_setup(instance);
345 cli();
346 data = NCR5380_read(CURRENT_SCSI_DATA_REG);
347 status = NCR5380_read(STATUS_REG);
348 mr = NCR5380_read(MODE_REG);
349 icr = NCR5380_read(INITIATOR_COMMAND_REG);
350 basr = NCR5380_read(BUS_AND_STATUS_REG);
351 sti();
352 for (i = 0; signals[i].mask ; ++i)
353 if (status & signals[i].mask)
354 printk(" %s", signals[i].name);
355 for (i = 0; basrs[i].mask ; ++i)
356 if (basr & basrs[i].mask)
357 printk(" %s", basrs[i].name);
358 for (i = 0; icrs[i].mask; ++i)
359 if (icr & icrs[i].mask)
360 printk(" %s", icrs[i].name);
361 for (i = 0; mrs[i].mask; ++i)
362 if (mr & mrs[i].mask)
363 printk(" %s", mrs[i].name);
364 printk("\n");
365 }
366
367 static struct {
368 unsigned char value;
369 char *name;
370 } phases[] = {
371 {PHASE_DATAOUT, "DATAOUT"}, {PHASE_DATAIN, "DATAIN"}, {PHASE_CMDOUT, "CMDOUT"},
372 {PHASE_STATIN, "STATIN"}, {PHASE_MSGOUT, "MSGOUT"}, {PHASE_MSGIN, "MSGIN"},
373 {PHASE_UNKNOWN, "UNKNOWN"}};
374
375
376
377
378
379
380
381
382
383 static void NCR5380_print_phase(struct Scsi_Host *instance) {
384 NCR5380_local_declare();
385 unsigned char status;
386 int i;
387 NCR5380_setup(instance);
388
389 status = NCR5380_read(STATUS_REG);
390 if (!(status & SR_REQ))
391 printk("scsi%d : REQ not asserted, phase unknown.\n",
392 instance->host_no);
393 else {
394 for (i = 0; (phases[i].value != PHASE_UNKNOWN) &&
395 (phases[i].value != (status & PHASE_MASK)); ++i);
396 printk("scsi%d : phase %s\n", instance->host_no, phases[i].name);
397 }
398 }
399 #endif
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420 static volatile int main_running = 0;
421
422
423
424
425
426
427
428
429
430
431
432 static __inline__ void run_main(void) {
433 cli();
434 if (!main_running) {
435 main_running = 1;
436 NCR5380_main();
437
438
439
440
441 sti();
442 } else
443 sti();
444 }
445
446 #ifdef USLEEP
447 #ifndef NCR5380_TIMER
448 #error "NCR5380_TIMER must be defined so that this type of NCR5380 driver gets a unique timer."
449 #endif
450
451
452
453
454
455
456
457
458
459
460
461 #ifndef USLEEP_SLEEP
462
463 #define USLEEP_SLEEP 2
464 #endif
465
466 #ifndef USLEEP_POLL
467 #define USLEEP_POLL 20
468 #endif
469
470 static struct Scsi_Host * expires_first = NULL;
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494 static int should_disconnect (unsigned char cmd) {
495 switch (cmd) {
496 case READ_6:
497 case WRITE_6:
498 case SEEK_6:
499 case READ_10:
500 case WRITE_10:
501 case SEEK_10:
502 return DISCONNECT_TIME_TO_DATA;
503 case FORMAT_UNIT:
504 case SEARCH_HIGH:
505 case SEARCH_LOW:
506 case SEARCH_EQUAL:
507 return DISCONNECT_LONG;
508 default:
509 return DISCONNECT_NONE;
510 }
511 }
512
513
514
515
516
517 static int NCR5380_set_timer (struct Scsi_Host *instance) {
518 struct Scsi_Host *tmp, **prev;
519
520 cli();
521 if (((struct NCR5380_hostdata *) (instance->host_data))->next_timer) {
522 sti();
523 return -1;
524 }
525
526 for (prev = &expires_first, tmp = expires_first; tmp;
527 prev = &(((struct NCR5380_hostdata *) tmp->host_data)->next_timer),
528 tmp = ((struct NCR5380_hostdata *) tmp->host_data)->next_timer)
529 if (instance->time_expires < tmp->time_expires)
530 break;
531
532 instance->next_timer = tmp;
533 *prev = instance;
534 timer_table[NCR5380_TIMER].expires = expires_first->time_expires;
535 timer_active |= 1 << NCR5380_TIMER;
536 sti;
537 return 0;
538 }
539
540
541 void NCR5380_timer_fn(void) {
542 struct Scsi_Host *instance;
543 cli();
544 for (; expires_first && expires_first->time_expires >= jiffies; ) {
545 instance = ((NCR5380_hostdata *) expires_first->host_data)->
546 expires_next;
547 ((NCR5380_hostdata *) expires_first->host_data)->expires_next =
548 NULL;
549 ((NCR5380_hostdata *) expires_first->host_data)->time_expires =
550 0;
551 expires_first = instance;
552 }
553
554 if (expires_first) {
555 timer_table[NCR5380_TIMER].expires = ((NCR5380_hostdata *)
556 expires_first->host_data)->time_expires;
557 timer_active |= (1 << NCR5380_TIMER);
558 } else {
559 timer_table[NCR5380_TIMER].expires = 0;
560 timer_active &= ~(1 << MCR5380_TIMER);
561 }
562 sti();
563
564 run_main();
565 }
566 #endif
567
568 static void NCR5380_all_init (void) {
569 static int done = 0;
570 if (!done) {
571 #if (NDEBUG & NDEBUG_INIT)
572 printk("scsi : NCR5380_all_init()\n");
573 #endif
574 done = 1;
575 #ifdef USLEEP
576 timer_table[NCR5380_TIMER].expires = 0;
577 timer_table[NCR5380_TIMER].fn = NCR5380_timer_fn;
578 #endif
579 }
580 }
581
582 #ifdef AUTOPROBE_IRQ
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597 static int probe_irq;
598 static void probe_intr (int sig) {
599 probe_irq = sig;
600 };
601 static struct sigaction probe_sigaction = { probe_intr, 0, SA_INTERRUPT,
602 NULL};
603
604 static int NCR5380_probe_irq (struct Scsi_Host *instance, int possible) {
605 NCR5380_local_declare();
606 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
607 instance->hostdata;
608 unsigned long timeout;
609 int trying_irqs, i, mask;
610 NCR5380_setup(instance);
611
612 for (trying_irqs = i = 0, mask = 1; i < 16; ++i, mask <<= 1)
613 if ((mask & possible) && (irqaction (i, &probe_sigaction)
614 == 0))
615 trying_irqs |= mask;
616
617 timeout = jiffies + 25;
618 probe_irq = IRQ_NONE;
619
620
621
622
623
624
625
626
627
628
629
630 NCR5380_write(TARGET_COMMAND_REG, 0);
631 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
632 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
633 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA |
634 ICR_ASSERT_SEL);
635
636 while (probe_irq == IRQ_NONE && jiffies < timeout);
637
638 NCR5380_write(SELECT_ENABLE_REG, 0);
639 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
640
641 for (i = 0, mask = 1; i < 16; ++i, mask <<= 1)
642 if (trying_irqs & mask)
643 free_irq(i);
644
645 return probe_irq;
646 }
647 #endif
648
649
650
651
652
653
654
655
656
657
658 static void NCR5380_print_options (struct Scsi_Host *instance) {
659 printk(" generic options"
660 #ifdef AUTOPROBE_IRQ
661 " AUTOPROBE_IRQ"
662 #endif
663 #ifdef AUTOSENSE
664 " AUTOSENSE"
665 #endif
666 #ifdef DIFFERENTIAL
667 " DIFFERENTIAL"
668 #endif
669 #ifdef REAL_DMA
670 " REAL DMA"
671 #endif
672 #ifdef REAL_DMA_POLL
673 " REAL DMA POLL"
674 #endif
675 #ifdef PARITY
676 " PARITY"
677 #endif
678 #ifdef PSEUDO_DMA
679 " PSEUDO DMA"
680 #endif
681 #ifdef SCSI2
682 " SCSI-2"
683 #endif
684 #ifdef UNSAFE
685 " UNSAFE "
686 #endif
687 );
688 #ifdef USLEEP
689 printk(" USLEEP, USLEEP_POLL=%d USLEEP_SLEEP=%d", USLEEP_POLL, USLEEP_SLEEP);
690 #endif
691 printk(" generic release=%d", NCR5380_PUBLIC_RELEASE);
692 #ifdef NCR53C400
693 if (hostdata->flags & FLAG_NCR53C400) {
694 printk(" ncr53c400 release=%d", NCR53C400_PUBLIC_RELEASE);
695 }
696 #endif
697 }
698
699
700
701
702
703
704
705
706
707
708 void NCR5380_print_status (struct Scsi_Host *instance) {
709 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
710 instance->hostdata;
711 Scsi_Cmnd *ptr;
712
713
714 printk("NCR5380 : coroutine is%s running.\n",
715 main_running ? "" : "n't");
716
717 #ifdef NDEBUG
718 NCR5380_print (instance);
719 NCR5380_print_phase (instance);
720 #endif
721
722 cli();
723 if (!hostdata->connected) {
724 printk ("scsi%d: no currently connected command\n",
725 instance->host_no);
726 } else {
727 print_Scsi_Cmnd ((Scsi_Cmnd *) hostdata->connected);
728 }
729
730 printk ("scsi%d: issue_queue\n", instance->host_no);
731
732 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr;
733 ptr = (Scsi_Cmnd *) ptr->host_scribble)
734 print_Scsi_Cmnd (ptr);
735
736 printk ("scsi%d: disconnected_queue\n", instance->host_no);
737
738 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
739 ptr = (Scsi_Cmnd *) ptr->host_scribble)
740 print_Scsi_Cmnd (ptr);
741
742 sti();
743 }
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759 static void NCR5380_init (struct Scsi_Host *instance, int flags) {
760 NCR5380_local_declare();
761 int i;
762 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
763 instance->hostdata;
764
765
766
767
768
769
770 if (flags & FLAG_NCR53C400)
771 instance->io_port += 8;
772
773 NCR5380_setup(instance);
774
775 NCR5380_all_init();
776
777 hostdata->aborted = 0;
778 hostdata->id_mask = 1 << instance->this_id;
779 for (i = hostdata->id_mask; i <= 0x80; i <<= 1)
780 if (i > hostdata->id_mask)
781 hostdata->id_higher_mask |= i;
782 for (i = 0; i < 8; ++i)
783 hostdata->busy[i] = 0;
784 #ifdef REAL_DMA
785 hostdata->dmalen = 0;
786 #endif
787 hostdata->targets_present = 0;
788 hostdata->connected = NULL;
789 hostdata->issue_queue = NULL;
790 hostdata->disconnected_queue = NULL;
791 hostdata->flags = FLAG_CHECK_LAST_BYTE_SENT | flags;
792
793 if (!the_template) {
794 the_template = instance->hostt;
795 first_instance = instance;
796 }
797
798
799 #ifdef USLEEP
800 hostdata->time_expires = 0;
801 hostdata->next_timer = NULL;
802 #endif
803
804 #ifndef AUTOSENSE
805 if ((instance->cmd_per_lun > 1) || instance->can_queue > 1))
806 printk("scsi%d : WARNING : support for multiple outstanding commands enabled\n"
807 " without AUTOSENSE option, contigent alligence conditions may\n"
808 " be incorrectly cleared.\n", instance->host_no);
809 #endif
810
811 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
812 NCR5380_write(MODE_REG, MR_BASE);
813 NCR5380_write(TARGET_COMMAND_REG, 0);
814 NCR5380_write(SELECT_ENABLE_REG, 0);
815 #ifdef NCR53C400
816 if (hostdata->flags & FLAG_NCR53C400) {
817 NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE);
818 }
819 #endif
820 }
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841 #ifndef NCR5380_queue_command
842 static
843 #endif
844 int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *)) {
845 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
846 cmd->host->hostdata;
847 Scsi_Cmnd *tmp;
848
849 #if (NDEBUG & NDEBUG_NO_WRITE)
850 switch (cmd->cmnd[0]) {
851 case WRITE:
852 case WRITE_10:
853 printk("scsi%d : WRITE attempted with NO_WRITE debugging flag set\n",
854 instance->host_no);
855 cmd->result = (DID_ERROR << 16);
856 done(cmd);
857 return 0;
858 }
859 #endif
860
861
862
863
864
865
866
867 cmd->host_scribble = NULL;
868 cmd->scsi_done = done;
869
870 cmd->result = 0;
871
872
873
874
875
876
877
878
879
880 cli();
881 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
882 cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
883 hostdata->issue_queue = cmd;
884 } else {
885 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue; tmp->host_scribble;
886 tmp = (Scsi_Cmnd *) tmp->host_scribble);
887 tmp->host_scribble = (unsigned char *) cmd;
888 }
889 #if (NDEBUG & NDEBUG_QUEUES)
890 printk("scsi%d : command added to %s of queue\n", instance->host_no,
891 (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail");
892 #endif
893
894
895 run_main();
896 return 0;
897 }
898
899
900
901
902
903
904
905
906
907
908
909
910
911 static void NCR5380_main (void) {
912 Scsi_Cmnd *tmp, *prev;
913 struct Scsi_Host *instance;
914 struct NCR5380_hostdata *hostdata;
915 int done;
916
917
918
919
920
921
922
923
924
925
926
927
928
929 do {
930 cli();
931 done = 1;
932 for (instance = first_instance; instance &&
933 instance->hostt == the_template; instance=instance->next) {
934 hostdata = (struct NCR5380_hostdata *) instance->hostdata;
935 cli();
936 if (!hostdata->connected) {
937 #if (NDEBUG & NDEBUG_MAIN)
938 printk("scsi%d : not connected\n", instance->host_no);
939 #endif
940
941
942
943
944 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue,
945 prev = NULL; tmp; prev = tmp, tmp = (Scsi_Cmnd *)
946 tmp->host_scribble)
947
948
949 if (!(hostdata->busy[tmp->target] & (1 << tmp->lun))) {
950 if (prev)
951 prev->host_scribble = tmp->host_scribble;
952 else
953 hostdata->issue_queue = (Scsi_Cmnd *) tmp->host_scribble;
954 tmp->host_scribble = NULL;
955
956
957 sti();
958
959
960
961
962
963
964
965 #if (NDEBUG & (NDEBUG_MAIN | NDEBUG_QUEUES))
966 printk("scsi%d : main() : command for target %d lun %d removed from issue_queue\n",
967 instance->host_no, tmp->target, tmp->lun);
968 #endif
969
970
971
972
973
974
975
976 if (!NCR5380_select(instance, tmp,
977 (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE :
978 TAG_NEXT)) {
979 break;
980 } else {
981 cli();
982 tmp->host_scribble = (unsigned char *)
983 hostdata->issue_queue;
984 hostdata->issue_queue = tmp;
985 sti();
986 #if (NDEBUG & (NDEBUG_MAIN | NDEBUG_QUEUES))
987 printk("scsi%d : main(): select() failed, returned to issue_queue\n",
988 instance->host_no);
989 #endif
990 }
991 }
992 }
993
994 if (hostdata->connected
995 #ifdef REAL_DMA
996 && !hostdata->dmalen
997 #endif
998 #ifdef USLEEP
999 && (!hostdata->time_expires || hostdata->time_expires >= jiffies)
1000 #endif
1001 ) {
1002 sti();
1003 #if (NDEBUG & NDEBUG_MAIN)
1004 printk("scsi%d : main() : performing information transfer\n",
1005 instance->host_no);
1006 #endif
1007 NCR5380_information_transfer(instance);
1008 #if (NDEBUG & NDEBUG_MAIN)
1009 printk("scsi%d : main() : done set false\n", instance->host_no);
1010 #endif
1011 done = 0;
1012 } else
1013 break;
1014 }
1015 } while (!done);
1016 main_running = 0;
1017 }
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030 static void NCR5380_intr (int irq) {
1031 NCR5380_local_declare();
1032 struct Scsi_Host *instance;
1033 int done;
1034 unsigned char basr;
1035 #if (NDEBUG & NDEBUG_INTR)
1036 printk("scsi : NCR5380 irq %d triggered\n", irq);
1037 #endif
1038 do {
1039 done = 1;
1040 for (instance = first_instance; instance && (instance->hostt ==
1041 the_template); instance = instance->next)
1042 if (instance->irq == irq) {
1043
1044
1045 NCR5380_setup(instance);
1046 basr = NCR5380_read(BUS_AND_STATUS_REG);
1047
1048 if (basr & BASR_IRQ) {
1049 #if (NDEBUG & NDEBUG_INTR)
1050 NCR5380_print(instance);
1051 #endif
1052 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) ==
1053 (SR_SEL | SR_IO)) {
1054 done = 0;
1055 sti();
1056 #if (NDEBUG & NDEBUG_INTR)
1057 printk("scsi%d : SEL interrupt\n", instance->host_no);
1058 #endif
1059 NCR5380_reselect(instance);
1060 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1061 } else if (basr & BASR_PARITY_ERROR) {
1062 #if (NDEBUG & NDEBUG_INTR)
1063 printk("scsi%d : PARITY interrupt\n", instance->host_no);
1064 #endif
1065 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1066 } else if ((NCR5380_read(STATUS_REG) & SR_RST) == SR_RST) {
1067 #if (NDEBUG & NDEBUG_INTR)
1068 printk("scsi%d : RESET interrupt\n", instance->host_no);
1069 #endif
1070 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1071 } else {
1072
1073
1074
1075
1076
1077 #if defined(REAL_DMA)
1078
1079
1080
1081
1082
1083
1084 if ((NCR5380_read(MODE_REG) & MR_DMA) && ((basr &
1085 BASR_END_DMA_TRANSFER) ||
1086 !(basr & BASR_PHASE_MATCH))) {
1087 int transfered;
1088
1089 if (!hostdata->connected)
1090 panic("scsi%d : recieved end of DMA interrupt with no connected cmd\n",
1091 instance->hostno);
1092
1093 transfered = (hostdata->dmalen - NCR5380_dma_residual(instance));
1094 hostdata->connected->SCp.this_residual -= transferred;
1095 hostdata->connected->SCp.ptr += transferred;
1096 hostdata->dmalen = 0;
1097
1098 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1099 #if NCR_TIMEOUT
1100 {
1101 unsigned long timeout = jiffies + NCR_TIMEOUT;
1102
1103 while (NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK
1104 && jiffies < timeout)
1105 ;
1106 if (jiffies >= timeout)
1107 printk("scsi: timeout at %d\n", __LINE__);
1108 }
1109 #else
1110 while (NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK);
1111 #endif
1112
1113 NCR5380_write(MODE_REG, MR_BASE);
1114 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1115 }
1116 #else
1117 #if (NDEBUG & NDEBUG_INTR)
1118 printk("scsi : unknown interrupt, BASR 0x%X, MR 0x%X, SR 0x%x\n", basr, NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG));
1119 #endif
1120 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1121 #endif
1122 }
1123 }
1124 if (!done)
1125 run_main();
1126 }
1127 } while (!done);
1128 }
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161 static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd,
1162 int tag) {
1163 NCR5380_local_declare();
1164 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata*)
1165 instance->hostdata;
1166 unsigned char tmp[3], phase;
1167 unsigned char *data;
1168 int len;
1169 unsigned long timeout;
1170 NCR5380_setup(instance);
1171
1172 hostdata->restart_select = 0;
1173 #if defined (NDEBUG) && (NDEBUG & NDEBUG_ARBITRATION)
1174 NCR5380_print(instance);
1175 printk("scsi%d : starting arbitration, id = %d\n", instance->host_no,
1176 instance->this_id);
1177 #endif
1178 cli();
1179
1180
1181
1182
1183
1184
1185 NCR5380_write(TARGET_COMMAND_REG, 0);
1186
1187
1188
1189
1190
1191
1192 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
1193 NCR5380_write(MODE_REG, MR_ARBITRATE);
1194
1195 sti();
1196
1197
1198 #if NCR_TIMEOUT
1199 {
1200 unsigned long timeout = jiffies + 2*NCR_TIMEOUT;
1201
1202 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
1203 && jiffies < timeout)
1204 ;
1205 if (jiffies >= timeout)
1206 {
1207 printk("scsi: arbitration timeout at %d\n", __LINE__);
1208 NCR5380_write(MODE_REG, MR_BASE);
1209 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1210 return -1;
1211 }
1212 }
1213 #else
1214 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS));
1215 #endif
1216
1217 #if (NDEBUG & NDEBUG_ARBITRATION)
1218 printk("scsi%d : arbitration complete\n", instance->host_no);
1219
1220 __asm__("nop");
1221 #endif
1222
1223
1224
1225
1226
1227
1228
1229
1230 udelay(3);
1231
1232
1233 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1234 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) ||
1235 (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST)) {
1236 NCR5380_write(MODE_REG, MR_BASE);
1237 #if (NDEBUG & NDEBUG_ARBITRATION)
1238 printk("scsi%d : lost arbitration, deasserting MR_ARBITRATE\n",
1239 instance->host_no);
1240 #endif
1241 return -1;
1242 }
1243
1244
1245
1246 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_SEL);
1247
1248 if (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) {
1249 NCR5380_write(MODE_REG, MR_BASE);
1250 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1251 #if (NDEBUG & NDEBUG_ARBITRATION)
1252 printk("scsi%d : lost arbitration, deasserting ICR_ASSERT_SEL\n",
1253 instance->host_no);
1254 #endif
1255 return -1;
1256 }
1257
1258
1259
1260
1261
1262
1263 udelay(2);
1264
1265 #if (NDEBUG & NDEBUG_ARBITRATION)
1266 printk("scsi%d : won arbitration\n", instance->host_no);
1267 #endif
1268
1269
1270
1271
1272
1273
1274
1275 NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->target)));
1276
1277
1278
1279
1280
1281
1282
1283 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY |
1284 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL ));
1285 NCR5380_write(MODE_REG, MR_BASE);
1286
1287
1288
1289
1290
1291 NCR5380_write(SELECT_ENABLE_REG, 0);
1292
1293
1294 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA |
1295 ICR_ASSERT_ATN | ICR_ASSERT_SEL));
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311 udelay(1);
1312
1313 #if (NDEBUG & NDEBUG_SELECTION)
1314 printk("scsi%d : selecting target %d\n", instance->host_no, cmd->target);
1315 #endif
1316
1317
1318
1319
1320
1321
1322 timeout = jiffies + 25;
1323
1324
1325
1326
1327
1328
1329
1330 while ((jiffies < timeout) && !(NCR5380_read(STATUS_REG) &
1331 (SR_BSY | SR_IO)));
1332
1333 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) ==
1334 (SR_SEL | SR_IO)) {
1335 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1336 NCR5380_reselect(instance);
1337 printk ("scsi%d : reselection after won arbitration?\n",
1338 instance->host_no);
1339 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1340 return -1;
1341 }
1342
1343 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1344
1345 if (!(NCR5380_read(STATUS_REG) & SR_BSY)) {
1346 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1347 if (hostdata->targets_present & (1 << cmd->target)) {
1348 printk("scsi%d : wierdness\n", instance->host_no);
1349 if (hostdata->restart_select)
1350 printk("\trestart select\n");
1351 #ifdef NDEBUG
1352 NCR5380_print (instance);
1353 #endif
1354 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1355 return -1;
1356 }
1357 cmd->result = DID_BAD_TARGET << 16;
1358 cmd->scsi_done(cmd);
1359 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1360 #if (NDEBUG & NDEBUG_SELECTION)
1361 printk("scsi%d : target did not respond within 250ms\n",
1362 instance->host_no);
1363 #endif
1364 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1365 return 0;
1366 }
1367
1368 hostdata->targets_present |= (1 << cmd->target);
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
1387
1388 #if (NDEBUG & NDEBUG_SELECTION)
1389 printk("scsi%d : target %d selected, going into MESSAGE OUT phase.\n",
1390 instance->host_no, cmd->target);
1391 #endif
1392 tmp[0] = IDENTIFY(((instance->irq == IRQ_NONE) ? 0 : 1), cmd->lun);
1393 #ifdef SCSI2
1394 if (cmd->device->tagged_queue && (tag != TAG_NONE)) {
1395 tmp[1] = SIMPLE_QUEUE_TAG;
1396 if (tag == TAG_NEXT) {
1397
1398 if (cmd->device->current_tag == 0)
1399 cmd->device->current_tag = 1;
1400
1401 cmd->tag = cmd->device->current_tag;
1402 cmd->device->current_tag++;
1403 } else
1404 cmd->tag = (unsigned char) tag;
1405
1406 tmp[2] = cmd->tag;
1407 hostdata->last_message = SIMPLE_QUEUE_TAG;
1408 len = 3;
1409 } else
1410 #endif
1411 {
1412 len = 1;
1413 cmd->tag=0;
1414 }
1415
1416
1417 data = tmp;
1418 phase = PHASE_MSGOUT;
1419 NCR5380_transfer_pio(instance, &phase, &len, &data);
1420 #if (NDEBUG & NDEBUG_SELECTION)
1421 printk("scsi%d : nexus established.\n", instance->host_no);
1422 #endif
1423
1424 hostdata->connected = cmd;
1425 #ifdef SCSI2
1426 if (!cmd->device->tagged_queue)
1427 #endif
1428 hostdata->busy[cmd->target] |= (1 << cmd->lun);
1429
1430 initialize_SCp(cmd);
1431
1432
1433 return 0;
1434 }
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461 static int NCR5380_transfer_pio (struct Scsi_Host *instance,
1462 unsigned char *phase, int *count, unsigned char **data) {
1463 NCR5380_local_declare();
1464 register unsigned char p = *phase, tmp;
1465 register int c = *count;
1466 register unsigned char *d = *data;
1467 NCR5380_setup(instance);
1468
1469
1470
1471
1472
1473
1474
1475 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1476
1477 do {
1478
1479
1480
1481
1482 while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ));
1483
1484 #if (NDEBUG & NDEBUG_HANDSHAKE)
1485 printk("scsi%d : REQ detected\n", instance->host_no);
1486 #endif
1487
1488
1489 if ((tmp & PHASE_MASK) != p) {
1490 #if (NDEBUG & NDEBUG_PIO)
1491 printk("scsi%d : phase mismatch\n", instance->host_no);
1492 NCR5380_print_phase(instance);
1493 #endif
1494 break;
1495 }
1496
1497
1498 if (!(p & SR_IO))
1499 NCR5380_write(OUTPUT_DATA_REG, *d);
1500 else
1501 *d = NCR5380_read(CURRENT_SCSI_DATA_REG);
1502
1503 ++d;
1504
1505
1506
1507
1508
1509
1510
1511
1512 if (!(p & SR_IO)) {
1513 if (!((p & SR_MSG) && c > 1)) {
1514 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1515 ICR_ASSERT_DATA);
1516 #if (NDEBUG & NDEBUG_PIO)
1517 NCR5380_print(instance);
1518 #endif
1519 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1520 ICR_ASSERT_DATA | ICR_ASSERT_ACK);
1521 } else {
1522 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1523 ICR_ASSERT_DATA | ICR_ASSERT_ATN);
1524 #if (NDEBUG & NDEBUG_PIO)
1525 NCR5380_print(instance);
1526 #endif
1527 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1528 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
1529 }
1530 } else {
1531 #if (NDEBUG & NDEBUG_PIO)
1532 NCR5380_print(instance);
1533 #endif
1534 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
1535 }
1536
1537 while (NCR5380_read(STATUS_REG) & SR_REQ);
1538
1539 #if (NDEBUG & NDEBUG_HANDSHAKE)
1540 printk("scsi%d : req false, handshake complete\n", instance->host_no);
1541 #endif
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554 if (!(p == PHASE_MSGIN && c == 1)) {
1555 if (p == PHASE_MSGOUT && c > 1)
1556 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1557 else
1558 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1559 }
1560 } while (--c);
1561
1562 #if (NDEBUG & NDEBUG_PIO)
1563 printk("scsi%d : residual %d\n", instance->host_no, c);
1564 #endif
1565
1566 *count = c;
1567 *data = d;
1568 tmp = NCR5380_read(STATUS_REG);
1569 if (tmp & SR_REQ)
1570 *phase = tmp & PHASE_MASK;
1571 else
1572 *phase = PHASE_UNKNOWN;
1573
1574 if (!c || (*phase == p))
1575 return 0;
1576 else
1577 return -1;
1578 }
1579
1580 #if defined(REAL_DMA) || defined(PSEUDO_DMA) || defined (REAL_DMA_POLL)
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601 static int NCR5380_transfer_dma (struct Scsi_Host *instance,
1602 unsigned char *phase, int *count, unsigned char **data) {
1603 NCR5380_local_declare();
1604 register int c = *count;
1605 register unsigned char p = *phase;
1606 register unsigned char *d = *data;
1607 unsigned char tmp;
1608 int foo;
1609 #if defined(REAL_DMA_POLL)
1610 int cnt, toPIO;
1611 unsigned char saved_data = 0, overrun = 0, residue;
1612 #endif
1613
1614 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
1615 instance->hostdata;
1616
1617 NCR5380_setup(instance);
1618
1619 if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) {
1620 *phase = tmp;
1621 return -1;
1622 }
1623 #if defined(REAL_DMA) || defined(REAL_DMA_POLL)
1624 #ifdef READ_OVERRUNS
1625 if (p & SR_IO) {
1626 c -= 2;
1627 }
1628 #endif
1629 #if (NDEBUG & NDEBUG_DMA)
1630 printk("scsi%d : initializing DMA channel %d for %s, %d bytes %s %0x\n",
1631 instance->host_no, instance->dma_channel, (p & SR_IO) ? "reading" :
1632 "writing", c, (p & SR_IO) ? "to" : "from", (unsigned) d);
1633 #endif
1634 hostdata->dma_len = (p & SR_IO) ?
1635 NCR5380_dma_read_setup(instance, d, c) :
1636 NCR5380_dma_write_setup(instance, d, c);
1637 #endif
1638
1639 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1640
1641 #ifdef REAL_DMA
1642 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_ENABLE_EOP_INTR | MR_MONITOR_BSY);
1643 #elif defined(REAL_DMA_POLL)
1644 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE);
1645 #else
1646
1647
1648
1649
1650
1651
1652 #if defined(PSEUDO_DMA) && !defined(UNSAFE)
1653 cli();
1654 #endif
1655 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE);
1656 #endif
1657
1658 #if (NDEBUG & NDEBUG_DMA) & 0
1659 printk("scsi%d : mode reg = 0x%X\n", instance->host_no, NCR5380_read(MODE_REG));
1660 #endif
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671 if (p & SR_IO) {
1672 #ifndef FOO
1673 udelay(1);
1674 #endif
1675 NCR5380_write(START_DMA_INITIATOR_RECIEVE_REG, 0);
1676 } else {
1677 #ifndef FOO
1678 udelay(1);
1679 #endif
1680 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA);
1681 #ifndef FOO
1682 udelay(1);
1683 #endif
1684 NCR5380_write(START_DMA_SEND_REG, 0);
1685 #ifndef FOO
1686 udelay(1);
1687 #endif
1688 }
1689
1690 #if defined(REAL_DMA_POLL)
1691 do {
1692 tmp = NCR5380_read(BUS_AND_STATUS_REG);
1693 } while ((tmp & BASR_PHASE_MATCH) && !(tmp & (BASR_BUSY_ERROR |
1694 BASR_END_DMA_TRANSFER)));
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732 if (p & SR_IO) {
1733 #ifdef READ_OVERRUNS
1734 udelay(10);
1735 if (((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH|BASR_ACK)) ==
1736 (BASR_PHASE_MATCH | BASR_ACK))) {
1737 saved_data = NCR5380_read(INPUT_DATA_REGISTER);
1738 overrun = 1;
1739 }
1740 #endif
1741 } else {
1742 int limit = 100;
1743 while (((tmp = NCR5380_read(BUS_AND_STATUS_REG)) & BASR_ACK) ||
1744 (NCR5380_read(STATUS_REG) & SR_REQ)) {
1745 if (!(tmp & BASR_PHASE_MATCH)) break;
1746 if (--limit < 0) break;
1747 }
1748 }
1749
1750
1751 #if (NDEBUG & NDEBUG_DMA)
1752 printk("scsi%d : polled DMA transfer complete, basr 0x%X, sr 0x%X\n",
1753 instance->host_no, tmp, NCR5380_read(STATUS_REG));
1754 #endif
1755
1756 NCR5380_write(MODE_REG, MR_BASE);
1757 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1758
1759 residue = NCR5380_dma_residual(instance);
1760 c -= residue;
1761 *count -= c;
1762 *data += c;
1763 *phase = NCR5380_read(STATUS_REG) & PHASE_MASK;
1764
1765 #ifdef READ_OVERRUNS
1766 if (*phase == p && (p & SR_IO) && residue == 0) {
1767 if (overrun) {
1768 #if (NDEBUG & NDEBUG_DMA)
1769 printk("Got an input overrun, using saved byte\n");
1770 #endif
1771 **data = saved_data;
1772 *data += 1;
1773 *count -= 1;
1774 cnt = toPIO = 1;
1775 } else {
1776 printk("No overrun??\n");
1777 cnt = toPIO = 2;
1778 }
1779 #if (NDEBUG & NDEBUG_DMA)
1780 printk("Doing %d-byte PIO to 0x%X\n", cnt, *data);
1781 #endif
1782 NCR5380_transfer_pio(instance, phase, &cnt, data);
1783 *count -= toPIO - cnt;
1784 }
1785 #endif
1786
1787 #if (NDEBUG & NDEBUG_DMA)
1788 printk("Return with data ptr = 0x%X, count %d, last 0x%X, next 0x%X\n",
1789 *data, *count, *(*data+*count-1), *(*data+*count));
1790 #endif
1791 return 0;
1792
1793 #elif defined(REAL_DMA)
1794 return 0;
1795 #else
1796 if (p & SR_IO) {
1797 if (!(foo = NCR5380_pread(instance, d, c - 1))) {
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ));
1821
1822 while (NCR5380_read(STATUS_REG) & SR_REQ);
1823 d[c - 1] = NCR5380_read(INPUT_DATA_REG);
1824 }
1825 } else {
1826 int timeout;
1827 if (!(foo = NCR5380_pwrite(instance, d, c))) {
1828
1829
1830
1831
1832 if (!(hostdata->flags & FLAG_HAS_LAST_BYTE_SENT)) {
1833 timeout = 20000;
1834 #if 1
1835 #if 1
1836 while (!(NCR5380_read(BUS_AND_STATUS_REG) &
1837 BASR_DRQ) && (NCR5380_read(BUS_AND_STATUS_REG) &
1838 BASR_PHASE_MATCH));
1839 #else
1840 if (NCR5380_read(STATUS_REG) & SR_REQ) {
1841 for (; timeout &&
1842 !(NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK);
1843 --timeout);
1844 for (; timeout && (NCR5380_read(STATUS_REG) & SR_REQ);
1845 --timeout);
1846 }
1847 #endif
1848
1849
1850 #if (NDEBUG & NDEBUG_LAST_BYTE_SENT)
1851 if (!timeout)
1852 printk("scsi%d : timed out on last byte\n",
1853 instance->host_no);
1854 #endif
1855
1856
1857 if (hostdata->flags & FLAG_CHECK_LAST_BYTE_SENT) {
1858 hostdata->flags &= ~FLAG_CHECK_LAST_BYTE_SENT;
1859 if (NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT) {
1860 hostdata->flags |= FLAG_HAS_LAST_BYTE_SENT;
1861 #if (NDEBUG & NDEBUG_LAST_BYTE_SENT)
1862 printk("scsi%d : last bit sent works\n",
1863 instance->host_no);
1864 #endif
1865 }
1866 }
1867 } else
1868 while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT));
1869 #else
1870 udelay (5);
1871 #endif
1872 }
1873 }
1874
1875 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1876 NCR5380_write(MODE_REG, MR_BASE);
1877
1878 *data = d + c;
1879 *count = 0;
1880 *phase = (NCR5380_read(STATUS_REG & PHASE_MASK));
1881 #if defined(PSEUDO_DMA) && !defined(UNSAFE)
1882 sti();
1883 #endif
1884 return foo;
1885 #endif
1886 }
1887 #endif
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906 static void NCR5380_information_transfer (struct Scsi_Host *instance) {
1907 NCR5380_local_declare();
1908 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
1909 instance->hostdata;
1910 unsigned char msgout = NOP;
1911 int sink = 0;
1912 int len, transfersize;
1913 unsigned char *data;
1914 unsigned char phase, tmp, extended_msg[10], old_phase=0xff;
1915 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected;
1916 NCR5380_setup(instance);
1917
1918 while (1) {
1919 tmp = NCR5380_read(STATUS_REG);
1920
1921 if (tmp & SR_REQ) {
1922 phase = (tmp & PHASE_MASK);
1923 if (phase != old_phase) {
1924 old_phase = phase;
1925 #if (NDEBUG & NDEBUG_INFORMATION)
1926 NCR5380_print_phase(instance);
1927 #endif
1928 }
1929
1930 if (sink && (phase != PHASE_MSGOUT)) {
1931 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1932
1933 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1934 ICR_ASSERT_ACK);
1935 while (NCR5380_read(STATUS_REG) & SR_REQ);
1936 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1937 ICR_ASSERT_ATN);
1938 sink = 0;
1939 continue;
1940 }
1941
1942 switch (phase) {
1943 case PHASE_DATAIN:
1944 case PHASE_DATAOUT:
1945 #if (NDEBUG & NDEBUG_NO_DATAOUT)
1946 printk("scsi%d : NDEBUG_NO_DATAOUT set, attempted DATAOUT aborted\n",
1947 instance->host_no);
1948 sink = 1;
1949 msgout = ABORT;
1950 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1951 break;
1952 #endif
1953
1954
1955
1956
1957
1958 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1959 ++cmd->SCp.buffer;
1960 --cmd->SCp.buffers_residual;
1961 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1962 cmd->SCp.ptr = cmd->SCp.buffer->address;
1963 #if (NDEBUG & NDEBUG_INFORMATION)
1964 printk("scsi%d : %d bytes and %d buffers left\n",
1965 instance->host_no, cmd->SCp.this_residual,
1966 cmd->SCp.buffers_residual);
1967 #endif
1968 }
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980 #if defined(PSEUDO_DMA) || defined(REAL_DMA_POLL)
1981 #ifdef NCR5380_dma_xfer_len
1982 if (!cmd->device->borken &&
1983 (transfersize = NCR5380_dma_xfer_len(instance, cmd)) != 0) {
1984 #else
1985 if (!cmd->device->borken &&
1986 (transfersize = cmd->transfersize) &&
1987 cmd->SCp.this_residual && !(cmd->SCp.this_residual %
1988 transfersize)) {
1989 #endif
1990 len = transfersize;
1991 if (NCR5380_transfer_dma(instance, &phase,
1992 &len, (unsigned char **) &cmd->SCp.ptr)) {
1993
1994
1995
1996
1997 printk("scsi%d : switching target %d lun %d to slow handshake\n",
1998 instance->host_no, cmd->target, cmd->lun);
1999 cmd->device->borken = 1;
2000 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2001 ICR_ASSERT_ATN);
2002 sink = 1;
2003 msgout = ABORT;
2004
2005 } else
2006 cmd->SCp.this_residual -= transfersize - len;
2007 } else
2008 #endif
2009 NCR5380_transfer_pio(instance, &phase,
2010 (int *) &cmd->SCp.this_residual, (unsigned char **)
2011 &cmd->SCp.ptr);
2012 break;
2013 case PHASE_MSGIN:
2014 len = 1;
2015 data = &tmp;
2016 NCR5380_transfer_pio(instance, &phase, &len, &data);
2017 cmd->SCp.Message = tmp;
2018
2019 switch (tmp) {
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030 #ifdef LINKED
2031 case LINKED_CMD_COMPLETE:
2032 case LINKED_FLG_CMD_COMPLETE:
2033
2034 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2035
2036 #if (NDEBUG & NDEBUG_LINKED)
2037 printk("scsi%d : target %d lun %d linked command complete.\n",
2038 instance->host_no, cmd->target, cmd->lun);
2039 #endif
2040
2041
2042
2043
2044
2045
2046 if (!cmd->next_link) {
2047 printk("scsi%d : target %d lun %d linked command complete, no next_link\n"
2048 instance->host_no, cmd->target, cmd->lun);
2049 sink = 1;
2050 msgout = ABORT;
2051 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2052 ICR_ASSERT_ATN);
2053 break;
2054 }
2055
2056 initialize_SCp(cmd->next_link);
2057
2058 cmd->next_link->tag = cmd->tag;
2059 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2060 #if (NDEBUG & NDEBUG_LINKED)
2061 printk("scsi%d : target %d lun %d linked request done, calling scsi_done().\n",
2062 instance->host_no, cmd->target, cmd->lun);
2063 #endif
2064 cmd->scsi_done(cmd);
2065 cmd = hostdata->connected;
2066 break;
2067 #endif
2068 case ABORT:
2069 case COMMAND_COMPLETE:
2070
2071 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2072 hostdata->connected = NULL;
2073 #if (NDEBUG & NDEBUG_QUEUES)
2074 printk("scsi%d : command for target %d, lun %d completed\n",
2075 instance->host_no, cmd->target, cmd->lun);
2076 #endif
2077 hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095 if (cmd->cmnd[0] != REQUEST_SENSE)
2096 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2097 else if (cmd->SCp.Status != GOOD)
2098 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
2099
2100 #ifdef AUTOSENSE
2101 if ((cmd->cmnd[0] != REQUEST_SENSE) &&
2102 (cmd->SCp.Status == CHECK_CONDITION)) {
2103 #if (NDEBUG & NDEBUG_AUTOSENSE)
2104 printk("scsi%d : performing request sense\n",
2105 instance->host_no);
2106 #endif
2107 cmd->cmnd[0] = REQUEST_SENSE;
2108 cmd->cmnd[1] &= 0xe0;
2109 cmd->cmnd[2] = 0;
2110 cmd->cmnd[3] = 0;
2111 cmd->cmnd[4] = sizeof(cmd->sense_buffer);
2112 cmd->cmnd[5] = 0;
2113
2114 cmd->SCp.buffer = NULL;
2115 cmd->SCp.buffers_residual = 0;
2116 cmd->SCp.ptr = (char *) cmd->sense_buffer;
2117 cmd->SCp.this_residual = sizeof(cmd->sense_buffer);
2118
2119 cli();
2120 cmd->host_scribble = (unsigned char *)
2121 hostdata->issue_queue;
2122 hostdata->issue_queue = (Scsi_Cmnd *) cmd;
2123 sti();
2124 #if (NDEBUG & NDEBUG_QUEUES)
2125 printk("scsi%d : REQUEST SENSE added to head of issue queue\n");
2126 #endif
2127 } else
2128 #endif
2129 cmd->scsi_done(cmd);
2130
2131 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2132
2133
2134
2135
2136 NCR5380_write(TARGET_COMMAND_REG, 0);
2137
2138 while ((NCR5380_read(STATUS_REG) & SR_BSY) &&
2139 !hostdata->connected);
2140 return;
2141 case MESSAGE_REJECT:
2142
2143 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2144 switch (hostdata->last_message) {
2145 case HEAD_OF_QUEUE_TAG:
2146 case ORDERED_QUEUE_TAG:
2147 case SIMPLE_QUEUE_TAG:
2148 cmd->device->tagged_queue = 0;
2149 hostdata->busy[cmd->target] |= (1 << cmd->lun);
2150 break;
2151 default:
2152 break;
2153 }
2154 case DISCONNECT:
2155
2156 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2157 cmd->device->disconnect = 1;
2158 cli();
2159 cmd->host_scribble = (unsigned char *)
2160 hostdata->disconnected_queue;
2161 hostdata->connected = NULL;
2162 hostdata->disconnected_queue = cmd;
2163 sti();
2164 #if (NDEBUG & NDEBUG_QUEUES)
2165 printk("scsi%d : command for target %d lun %d was moved from connected to"
2166 " the disconnected_queue\n", instance->host_no,
2167 cmd->target, cmd->lun);
2168 #endif
2169
2170
2171
2172
2173 NCR5380_write(TARGET_COMMAND_REG, 0);
2174
2175
2176 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2177
2178 while ((NCR5380_read(STATUS_REG) & SR_BSY) &&
2179 !hostdata->connected);
2180 return;
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191 case SAVE_POINTERS:
2192 case RESTORE_POINTERS:
2193
2194 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2195 break;
2196 case EXTENDED_MESSAGE:
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209 extended_msg[0] = EXTENDED_MESSAGE;
2210
2211 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2212
2213 #if (NDEBUG & NDEBUG_EXTENDED)
2214 printk("scsi%d : receiving extended message\n",
2215 instance->host_no);
2216 #endif
2217
2218 len = 2;
2219 data = extended_msg + 1;
2220 phase = PHASE_MSGIN;
2221 NCR5380_transfer_pio(instance, &phase, &len, &data);
2222
2223 #if (NDEBUG & NDEBUG_EXTENDED)
2224 printk("scsi%d : length=%d, code=0x%02x\n",
2225 instance->host_no, (int) extended_msg[1],
2226 (int) extended_msg[2]);
2227 #endif
2228
2229 if (!len && extended_msg[1] <=
2230 (sizeof (extended_msg) - 1)) {
2231
2232 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2233 len = extended_msg[1] - 1;
2234 data = extended_msg + 3;
2235 phase = PHASE_MSGIN;
2236
2237 NCR5380_transfer_pio(instance, &phase, &len, &data);
2238
2239 #if (NDEBUG & NDEBUG_EXTENDED)
2240 printk("scsi%d : message received, residual %d\n",
2241 instance->host_no, len);
2242 #endif
2243
2244 switch (extended_msg[2]) {
2245 case EXTENDED_SDTR:
2246 case EXTENDED_WDTR:
2247 case EXTENDED_MODIFY_DATA_POINTER:
2248 case EXTENDED_EXTENDED_IDENTIFY:
2249 tmp = 0;
2250 }
2251 } else if (len) {
2252 printk("scsi%d: error recieving extended message\n",
2253 instance->host_no);
2254 tmp = 0;
2255 } else {
2256 printk("scsi%d: extended message code %02x length %d is too long\n",
2257 instance->host_no, extended_msg[2], extended_msg[1]);
2258 tmp = 0;
2259 }
2260
2261
2262
2263
2264
2265
2266 default:
2267 if (!tmp) {
2268 printk("scsi%d: rejecting message ", instance->host_no);
2269 print_msg (extended_msg);
2270 printk("\n");
2271 } else if (tmp != EXTENDED_MESSAGE)
2272 printk("scsi%d: rejecting unknown message %02x from target %d, lun %d\n",
2273 instance->host_no, tmp, cmd->target, cmd->lun);
2274 else
2275 printk("scsi%d: rejecting unknown extended message code %02x, legnth %d from target %d, lun %d\n",
2276 instance->host_no, extended_msg[1], extended_msg[0], cmd->target, cmd->lun);
2277
2278 msgout = MESSAGE_REJECT;
2279 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2280 ICR_ASSERT_ATN);
2281 break;
2282 }
2283 break;
2284 case PHASE_MSGOUT:
2285 len = 1;
2286 data = &msgout;
2287 hostdata->last_message = msgout;
2288 NCR5380_transfer_pio(instance, &phase, &len, &data);
2289 if (msgout == ABORT) {
2290 hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
2291 hostdata->connected = NULL;
2292 cmd->result = DID_ERROR << 16;
2293 cmd->scsi_done(cmd);
2294 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2295 return;
2296 }
2297 msgout = NOP;
2298 break;
2299 case PHASE_CMDOUT:
2300 len = COMMAND_SIZE(cmd->cmnd[0]);
2301 data = cmd->cmnd;
2302
2303
2304
2305
2306
2307 NCR5380_transfer_pio(instance, &phase, &len,
2308 &data);
2309 #ifdef USLEEP
2310 if (!disconnect && should_disconnect(cmd->cmnd[0])) {
2311 hostdata->time_expires = jiffies + USLEEP_SLEEP;
2312 #if (NDEBUG & NDEBUG_USLEEP)
2313 printk("scsi%d : issued command, sleeping until %ul\n", instance->host_no,
2314 hostdata->time_expires);
2315 #endif
2316 NCR5380_set_timer (instance);
2317 return;
2318 }
2319 #endif
2320 break;
2321 case PHASE_STATIN:
2322 len = 1;
2323 data = &tmp;
2324 NCR5380_transfer_pio(instance, &phase, &len, &data);
2325 cmd->SCp.Status = tmp;
2326 break;
2327 default:
2328 printk("scsi%d : unknown phase\n", instance->host_no);
2329 #ifdef NDEBUG
2330 NCR5380_print(instance);
2331 #endif
2332 }
2333 }
2334 #ifdef USLEEP
2335 else {
2336 if (!disconnect && hostdata->time_expires && jiffies >
2337 hostdata->time_expires) {
2338 hostdata->time_expires = jiffies + USLEEP_SLEEP;
2339 #if (NDEBUG & NDEBUG_USLEEP)
2340 printk("scsi%d : poll timed out, sleeping until %ul\n", instance->host_no,
2341 hostdata->time_expires);
2342 #endif
2343 NCR5380_set_timer (instance);
2344 return;
2345 }
2346 }
2347 #endif
2348 }
2349 }
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363 static void NCR5380_reselect (struct Scsi_Host *instance) {
2364 NCR5380_local_declare();
2365 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
2366 instance->hostdata;
2367 unsigned char target_mask;
2368 unsigned char lun, phase;
2369 int len;
2370 #ifdef SCSI2
2371 unsigned char tag;
2372 #endif
2373 unsigned char msg[3];
2374 unsigned char *data;
2375 Scsi_Cmnd *tmp = NULL, *prev;
2376 int abort = 0;
2377 NCR5380_setup(instance);
2378
2379
2380
2381
2382
2383
2384 NCR5380_write(MODE_REG, MR_BASE);
2385 hostdata->restart_select = 1;
2386
2387 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask);
2388
2389 #if (NDEBUG & NDEBUG_RESELECTION)
2390 printk("scsi%d : reselect\n", instance->host_no);
2391 #endif
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
2403
2404 while (NCR5380_read(STATUS_REG) & SR_SEL);
2405 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2406
2407
2408
2409
2410
2411 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
2412
2413 len = 1;
2414 data = msg;
2415 phase = PHASE_MSGIN;
2416 NCR5380_transfer_pio(instance, &phase, &len, &data);
2417
2418
2419 if (!msg[0] & 0x80) {
2420 printk("scsi%d : expecting IDENTIFY message, got ",
2421 instance->host_no);
2422 print_msg(msg);
2423 abort = 1;
2424 } else {
2425
2426 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2427 lun = (msg[0] & 0x07);
2428
2429
2430
2431
2432
2433
2434
2435 #ifdef SCSI2
2436 #error "SCSI-II tagged queueing is not supported yet"
2437 #endif
2438
2439
2440
2441
2442
2443
2444
2445 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL;
2446 tmp; prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble)
2447 if ((target_mask == (1 << tmp->target)) && (lun == tmp->lun)
2448 #ifdef SCSI2
2449 && (tag == tmp->tag)
2450 #endif
2451 ) {
2452 if (prev)
2453 prev->host_scribble = tmp->host_scribble;
2454 else
2455 hostdata->disconnected_queue = (Scsi_Cmnd *) tmp->host_scribble;
2456 tmp->host_scribble = NULL;
2457 break;
2458 }
2459
2460 if (!tmp) {
2461 #ifdef SCSI2
2462 printk("scsi%d : warning : target bitmask %02x lun %d tag %d not in disconnect_queue.\n",
2463 instance->host_no, target_mask, lun, tag);
2464 #else
2465 printk("scsi%d : warning : target bitmask %02x lun %d not in disconnect_queue.\n",
2466 instance->host_no, target_mask, lun);
2467 #endif
2468
2469
2470
2471
2472 abort = 1;
2473 }
2474 }
2475
2476 if (abort) {
2477 msg[0] = ABORT;
2478 len = 1;
2479 data = msg;
2480 phase = PHASE_MSGOUT;
2481 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
2482 NCR5380_transfer_pio(instance, &phase, &len, &data);
2483 } else {
2484 hostdata->connected = tmp;
2485 #if (NDEBUG & NDEBUG_RESELECTION)
2486 printk"scsi%d : nexus established, target = %d, lun = %d, tag = %d\n",
2487 instance->host_no, tmp->target, tmp->lun, tmp->tag);
2488 #endif
2489 }
2490 }
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504 #ifdef REAL_DMA
2505 static void NCR5380_dma_complete (NCR5380_instance *instance) {
2506 NCR5380_local_declare();
2507 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *
2508 instance->hostdata);
2509 int transferred;
2510 NCR5380_setup(instance);
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521 while (NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK);
2522
2523 NCR5380_write(MODE_REG, MR_BASE);
2524 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2525
2526
2527
2528
2529
2530
2531
2532 if (!(hostdata->connected->SCp.phase & SR_CD)) {
2533 transferred = instance->dmalen - NCR5380_dma_residual();
2534 hostdata->connected->SCp.this_residual -= transferred;
2535 hostdata->connected->SCp.ptr += transferred;
2536 }
2537 }
2538 #endif
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557 #ifndef NCR5380_abort
2558 static
2559 #endif
2560 int NCR5380_abort (Scsi_Cmnd *cmd) {
2561 NCR5380_local_declare();
2562 struct Scsi_Host *instance = cmd->host;
2563 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
2564 instance->hostdata;
2565 Scsi_Cmnd *tmp, **prev;
2566 unsigned char msg, phase, *msgptr;
2567 int len;
2568
2569 printk("scsi%d : aborting command\n", instance->host_no);
2570 print_Scsi_Cmnd (cmd);
2571
2572 NCR5380_print_status (instance);
2573
2574 cli();
2575 NCR5380_setup(instance);
2576
2577 #if (NDEBUG & NDEBUG_ABORT)
2578 printk("scsi%d : abort called\n", instance->host_no);
2579 printk(" basr 0x%X, sr 0x%X\n",
2580 NCR5380_read(BUS_AND_STATUS_REG), NCR5380_read(STATUS_REG));
2581 #endif
2582
2583 #if 0
2584
2585
2586
2587
2588
2589
2590 if (hostdata->connected == cmd) {
2591 #if (NDEBUG & NDEBUG_ABORT)
2592 printk("scsi%d : aborting connected command\n", instance->host_no);
2593 #endif
2594 hostdata->aborted = 1;
2595
2596
2597
2598
2599
2600 NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN);
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612 return 0;
2613 }
2614 #endif
2615
2616
2617
2618
2619
2620 for (prev = (Scsi_Cmnd **) &(hostdata->issue_queue),
2621 tmp = (Scsi_Cmnd *) hostdata->issue_queue;
2622 tmp; prev = (Scsi_Cmnd **) &(tmp->host_scribble), tmp =
2623 (Scsi_Cmnd *) tmp->host_scribble)
2624 if (cmd == tmp) {
2625 (*prev) = (Scsi_Cmnd *) tmp->host_scribble;
2626 tmp->host_scribble = NULL;
2627 tmp->result = DID_ABORT << 16;
2628 sti();
2629 #if (NDEBUG & NDEBUG_ABORT)
2630 printk("scsi%d : abort removed command from issue queue.\n",
2631 instance->host_no);
2632 #endif
2633 tmp->done(tmp);
2634 return SCSI_ABORT_SUCCESS;
2635 }
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648 if (hostdata->connected) {
2649 sti();
2650 #if (NDEBUG & NDEBUG_ABORT)
2651 printk("scsi%d : abort failed, command connected.\n", instance->host_no);
2652 #endif
2653 return SCSI_ABORT_NOT_RUNNING;
2654 }
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp;
2682 tmp = (Scsi_Cmnd *) tmp->host_scribble)
2683 if (cmd == tmp) {
2684 sti();
2685 #if (NDEBUG & NDEBUG_ABORT)
2686 printk("scsi%d : aborting disconnected command.\n", instance->host_no);
2687 #endif
2688
2689 if (NCR5380_select (instance, cmd, (int) cmd->tag))
2690 return SCSI_ABORT_BUSY;
2691
2692 #if (NDEBUG & NDEBUG_ABORT)
2693 printk("scsi%d : nexus restablished.\n", instance->host_no);
2694 #endif
2695
2696 msg = ABORT;
2697 msgptr = &msg;
2698 len = 1;
2699 phase = PHASE_MSGOUT;
2700 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
2701 NCR5380_transfer_pio (instance, &phase, &len, &msgptr);
2702
2703 cli();
2704 for (prev = (Scsi_Cmnd **) &(hostdata->disconnected_queue),
2705 tmp = (Scsi_Cmnd *) hostdata->disconnected_queue;
2706 tmp; prev = (Scsi_Cmnd **) &(tmp->host_scribble), tmp =
2707 (Scsi_Cmnd *) tmp->host_scribble)
2708 if (cmd == tmp) {
2709 *prev = (Scsi_Cmnd *) tmp->host_scribble;
2710 tmp->host_scribble = NULL;
2711 tmp->result = DID_ABORT << 16;
2712 sti();
2713 tmp->done(tmp);
2714 return SCSI_ABORT_SUCCESS;
2715 }
2716 }
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728 sti();
2729 printk("scsi%d : warning : SCSI command probably completed successfully\n"
2730 " before abortion\n", instance->host_no);
2731 return SCSI_ABORT_NOT_RUNNING;
2732 }
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744 #ifndef NCR5380_reset
2745 static
2746 #endif
2747 int NCR5380_reset (Scsi_Cmnd *cmd) {
2748 NCR5380_local_declare();
2749 NCR5380_setup(cmd->host);
2750
2751 NCR5380_print_status (cmd->host);
2752
2753 cli();
2754 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST);
2755 udelay(25);
2756 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2757 sti();
2758
2759 return SCSI_RESET_WAKEUP;
2760 }
2761