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
602 static int NCR5380_probe_irq (struct Scsi_Host *instance, int possible) {
603 NCR5380_local_declare();
604 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
605 instance->hostdata;
606 unsigned long timeout;
607 int trying_irqs, i, mask;
608 NCR5380_setup(instance);
609
610 for (trying_irqs = i = 0, mask = 1; i < 16; ++i, mask <<= 1)
611 if ((mask & possible) && (request_irq(i, &probe_intr, SA_INTERRUPT, "NCR-probe")
612 == 0))
613 trying_irqs |= mask;
614
615 timeout = jiffies + 25;
616 probe_irq = IRQ_NONE;
617
618
619
620
621
622
623
624
625
626
627
628 NCR5380_write(TARGET_COMMAND_REG, 0);
629 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
630 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
631 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA |
632 ICR_ASSERT_SEL);
633
634 while (probe_irq == IRQ_NONE && jiffies < timeout);
635
636 NCR5380_write(SELECT_ENABLE_REG, 0);
637 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
638
639 for (i = 0, mask = 1; i < 16; ++i, mask <<= 1)
640 if (trying_irqs & mask)
641 free_irq(i);
642
643 return probe_irq;
644 }
645 #endif
646
647
648
649
650
651
652
653
654
655
656 static void NCR5380_print_options (struct Scsi_Host *instance) {
657 printk(" generic options"
658 #ifdef AUTOPROBE_IRQ
659 " AUTOPROBE_IRQ"
660 #endif
661 #ifdef AUTOSENSE
662 " AUTOSENSE"
663 #endif
664 #ifdef DIFFERENTIAL
665 " DIFFERENTIAL"
666 #endif
667 #ifdef REAL_DMA
668 " REAL DMA"
669 #endif
670 #ifdef REAL_DMA_POLL
671 " REAL DMA POLL"
672 #endif
673 #ifdef PARITY
674 " PARITY"
675 #endif
676 #ifdef PSEUDO_DMA
677 " PSEUDO DMA"
678 #endif
679 #ifdef SCSI2
680 " SCSI-2"
681 #endif
682 #ifdef UNSAFE
683 " UNSAFE "
684 #endif
685 );
686 #ifdef USLEEP
687 printk(" USLEEP, USLEEP_POLL=%d USLEEP_SLEEP=%d", USLEEP_POLL, USLEEP_SLEEP);
688 #endif
689 printk(" generic release=%d", NCR5380_PUBLIC_RELEASE);
690 #ifdef NCR53C400
691 if (hostdata->flags & FLAG_NCR53C400) {
692 printk(" ncr53c400 release=%d", NCR53C400_PUBLIC_RELEASE);
693 }
694 #endif
695 }
696
697
698
699
700
701
702
703
704
705
706 static void NCR5380_print_status (struct Scsi_Host *instance) {
707 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
708 instance->hostdata;
709 Scsi_Cmnd *ptr;
710
711
712 printk("NCR5380 : coroutine is%s running.\n",
713 main_running ? "" : "n't");
714
715 #ifdef NDEBUG
716 NCR5380_print (instance);
717 NCR5380_print_phase (instance);
718 #endif
719
720 cli();
721 if (!hostdata->connected) {
722 printk ("scsi%d: no currently connected command\n",
723 instance->host_no);
724 } else {
725 print_Scsi_Cmnd ((Scsi_Cmnd *) hostdata->connected);
726 }
727
728 printk ("scsi%d: issue_queue\n", instance->host_no);
729
730 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr;
731 ptr = (Scsi_Cmnd *) ptr->host_scribble)
732 print_Scsi_Cmnd (ptr);
733
734 printk ("scsi%d: disconnected_queue\n", instance->host_no);
735
736 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
737 ptr = (Scsi_Cmnd *) ptr->host_scribble)
738 print_Scsi_Cmnd (ptr);
739
740 sti();
741 }
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757 static void NCR5380_init (struct Scsi_Host *instance, int flags) {
758 NCR5380_local_declare();
759 int i;
760 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
761 instance->hostdata;
762
763
764
765
766
767
768 if (flags & FLAG_NCR53C400)
769 instance->io_port += 8;
770
771 NCR5380_setup(instance);
772
773 NCR5380_all_init();
774
775 hostdata->aborted = 0;
776 hostdata->id_mask = 1 << instance->this_id;
777 for (i = hostdata->id_mask; i <= 0x80; i <<= 1)
778 if (i > hostdata->id_mask)
779 hostdata->id_higher_mask |= i;
780 for (i = 0; i < 8; ++i)
781 hostdata->busy[i] = 0;
782 #ifdef REAL_DMA
783 hostdata->dmalen = 0;
784 #endif
785 hostdata->targets_present = 0;
786 hostdata->connected = NULL;
787 hostdata->issue_queue = NULL;
788 hostdata->disconnected_queue = NULL;
789 hostdata->flags = FLAG_CHECK_LAST_BYTE_SENT | flags;
790
791 if (!the_template) {
792 the_template = instance->hostt;
793 first_instance = instance;
794 }
795
796
797 #ifdef USLEEP
798 hostdata->time_expires = 0;
799 hostdata->next_timer = NULL;
800 #endif
801
802 #ifndef AUTOSENSE
803 if ((instance->cmd_per_lun > 1) || instance->can_queue > 1))
804 printk("scsi%d : WARNING : support for multiple outstanding commands enabled\n"
805 " without AUTOSENSE option, contingent allegiance conditions may\n"
806 " be incorrectly cleared.\n", instance->host_no);
807 #endif
808
809 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
810 NCR5380_write(MODE_REG, MR_BASE);
811 NCR5380_write(TARGET_COMMAND_REG, 0);
812 NCR5380_write(SELECT_ENABLE_REG, 0);
813 #ifdef NCR53C400
814 if (hostdata->flags & FLAG_NCR53C400) {
815 NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE);
816 }
817 #endif
818 }
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839 #ifndef NCR5380_queue_command
840 static
841 #endif
842 int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *)) {
843 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
844 cmd->host->hostdata;
845 Scsi_Cmnd *tmp;
846
847 #if (NDEBUG & NDEBUG_NO_WRITE)
848 switch (cmd->cmnd[0]) {
849 case WRITE:
850 case WRITE_10:
851 printk("scsi%d : WRITE attempted with NO_WRITE debugging flag set\n",
852 instance->host_no);
853 cmd->result = (DID_ERROR << 16);
854 done(cmd);
855 return 0;
856 }
857 #endif
858
859
860
861
862
863
864
865 cmd->host_scribble = NULL;
866 cmd->scsi_done = done;
867
868 cmd->result = 0;
869
870
871
872
873
874
875
876
877
878 cli();
879 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
880 cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
881 hostdata->issue_queue = cmd;
882 } else {
883 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue; tmp->host_scribble;
884 tmp = (Scsi_Cmnd *) tmp->host_scribble);
885 tmp->host_scribble = (unsigned char *) cmd;
886 }
887 #if (NDEBUG & NDEBUG_QUEUES)
888 printk("scsi%d : command added to %s of queue\n", instance->host_no,
889 (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail");
890 #endif
891
892
893 run_main();
894 return 0;
895 }
896
897
898
899
900
901
902
903
904
905
906
907
908
909 static void NCR5380_main (void) {
910 Scsi_Cmnd *tmp, *prev;
911 struct Scsi_Host *instance;
912 struct NCR5380_hostdata *hostdata;
913 int done;
914
915
916
917
918
919
920
921
922
923
924
925
926
927 do {
928 cli();
929 done = 1;
930 for (instance = first_instance; instance &&
931 instance->hostt == the_template; instance=instance->next) {
932 hostdata = (struct NCR5380_hostdata *) instance->hostdata;
933 cli();
934 if (!hostdata->connected) {
935 #if (NDEBUG & NDEBUG_MAIN)
936 printk("scsi%d : not connected\n", instance->host_no);
937 #endif
938
939
940
941
942 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue,
943 prev = NULL; tmp; prev = tmp, tmp = (Scsi_Cmnd *)
944 tmp->host_scribble)
945
946
947 if (!(hostdata->busy[tmp->target] & (1 << tmp->lun))) {
948 if (prev)
949 prev->host_scribble = tmp->host_scribble;
950 else
951 hostdata->issue_queue = (Scsi_Cmnd *) tmp->host_scribble;
952 tmp->host_scribble = NULL;
953
954
955 sti();
956
957
958
959
960
961
962
963 #if (NDEBUG & (NDEBUG_MAIN | NDEBUG_QUEUES))
964 printk("scsi%d : main() : command for target %d lun %d removed from issue_queue\n",
965 instance->host_no, tmp->target, tmp->lun);
966 #endif
967
968
969
970
971
972
973
974 if (!NCR5380_select(instance, tmp,
975 (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE :
976 TAG_NEXT)) {
977 break;
978 } else {
979 cli();
980 tmp->host_scribble = (unsigned char *)
981 hostdata->issue_queue;
982 hostdata->issue_queue = tmp;
983 sti();
984 #if (NDEBUG & (NDEBUG_MAIN | NDEBUG_QUEUES))
985 printk("scsi%d : main(): select() failed, returned to issue_queue\n",
986 instance->host_no);
987 #endif
988 }
989 }
990 }
991
992 if (hostdata->connected
993 #ifdef REAL_DMA
994 && !hostdata->dmalen
995 #endif
996 #ifdef USLEEP
997 && (!hostdata->time_expires || hostdata->time_expires >= jiffies)
998 #endif
999 ) {
1000 sti();
1001 #if (NDEBUG & NDEBUG_MAIN)
1002 printk("scsi%d : main() : performing information transfer\n",
1003 instance->host_no);
1004 #endif
1005 NCR5380_information_transfer(instance);
1006 #if (NDEBUG & NDEBUG_MAIN)
1007 printk("scsi%d : main() : done set false\n", instance->host_no);
1008 #endif
1009 done = 0;
1010 } else
1011 break;
1012 }
1013 } while (!done);
1014 main_running = 0;
1015 }
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028 static void NCR5380_intr (int irq) {
1029 NCR5380_local_declare();
1030 struct Scsi_Host *instance;
1031 int done;
1032 unsigned char basr;
1033 #if (NDEBUG & NDEBUG_INTR)
1034 printk("scsi : NCR5380 irq %d triggered\n", irq);
1035 #endif
1036 do {
1037 done = 1;
1038 for (instance = first_instance; instance && (instance->hostt ==
1039 the_template); instance = instance->next)
1040 if (instance->irq == irq) {
1041
1042
1043 NCR5380_setup(instance);
1044 basr = NCR5380_read(BUS_AND_STATUS_REG);
1045
1046 if (basr & BASR_IRQ) {
1047 #if (NDEBUG & NDEBUG_INTR)
1048 NCR5380_print(instance);
1049 #endif
1050 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) ==
1051 (SR_SEL | SR_IO)) {
1052 done = 0;
1053 sti();
1054 #if (NDEBUG & NDEBUG_INTR)
1055 printk("scsi%d : SEL interrupt\n", instance->host_no);
1056 #endif
1057 NCR5380_reselect(instance);
1058 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1059 } else if (basr & BASR_PARITY_ERROR) {
1060 #if (NDEBUG & NDEBUG_INTR)
1061 printk("scsi%d : PARITY interrupt\n", instance->host_no);
1062 #endif
1063 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1064 } else if ((NCR5380_read(STATUS_REG) & SR_RST) == SR_RST) {
1065 #if (NDEBUG & NDEBUG_INTR)
1066 printk("scsi%d : RESET interrupt\n", instance->host_no);
1067 #endif
1068 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1069 } else {
1070
1071
1072
1073
1074
1075 #if defined(REAL_DMA)
1076
1077
1078
1079
1080
1081
1082 if ((NCR5380_read(MODE_REG) & MR_DMA) && ((basr &
1083 BASR_END_DMA_TRANSFER) ||
1084 !(basr & BASR_PHASE_MATCH))) {
1085 int transfered;
1086
1087 if (!hostdata->connected)
1088 panic("scsi%d : received end of DMA interrupt with no connected cmd\n",
1089 instance->hostno);
1090
1091 transfered = (hostdata->dmalen - NCR5380_dma_residual(instance));
1092 hostdata->connected->SCp.this_residual -= transferred;
1093 hostdata->connected->SCp.ptr += transferred;
1094 hostdata->dmalen = 0;
1095
1096 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1097 #if NCR_TIMEOUT
1098 {
1099 unsigned long timeout = jiffies + NCR_TIMEOUT;
1100
1101 while (NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK
1102 && jiffies < timeout)
1103 ;
1104 if (jiffies >= timeout)
1105 printk("scsi: timeout at %d\n", __LINE__);
1106 }
1107 #else
1108 while (NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK);
1109 #endif
1110
1111 NCR5380_write(MODE_REG, MR_BASE);
1112 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1113 }
1114 #else
1115 #if (NDEBUG & NDEBUG_INTR)
1116 printk("scsi : unknown interrupt, BASR 0x%X, MR 0x%X, SR 0x%x\n", basr, NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG));
1117 #endif
1118 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1119 #endif
1120 }
1121 }
1122 if (!done)
1123 run_main();
1124 }
1125 } while (!done);
1126 }
1127
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 static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd,
1160 int tag) {
1161 NCR5380_local_declare();
1162 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata*)
1163 instance->hostdata;
1164 unsigned char tmp[3], phase;
1165 unsigned char *data;
1166 int len;
1167 unsigned long timeout;
1168 NCR5380_setup(instance);
1169
1170 hostdata->restart_select = 0;
1171 #if defined (NDEBUG) && (NDEBUG & NDEBUG_ARBITRATION)
1172 NCR5380_print(instance);
1173 printk("scsi%d : starting arbitration, id = %d\n", instance->host_no,
1174 instance->this_id);
1175 #endif
1176 cli();
1177
1178
1179
1180
1181
1182
1183 NCR5380_write(TARGET_COMMAND_REG, 0);
1184
1185
1186
1187
1188
1189
1190 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
1191 NCR5380_write(MODE_REG, MR_ARBITRATE);
1192
1193 sti();
1194
1195
1196 #if NCR_TIMEOUT
1197 {
1198 unsigned long timeout = jiffies + 2*NCR_TIMEOUT;
1199
1200 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
1201 && jiffies < timeout)
1202 ;
1203 if (jiffies >= timeout)
1204 {
1205 printk("scsi: arbitration timeout at %d\n", __LINE__);
1206 NCR5380_write(MODE_REG, MR_BASE);
1207 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1208 return -1;
1209 }
1210 }
1211 #else
1212 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS));
1213 #endif
1214
1215 #if (NDEBUG & NDEBUG_ARBITRATION)
1216 printk("scsi%d : arbitration complete\n", instance->host_no);
1217
1218 __asm__("nop");
1219 #endif
1220
1221
1222
1223
1224
1225
1226
1227
1228 udelay(3);
1229
1230
1231 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1232 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) ||
1233 (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST)) {
1234 NCR5380_write(MODE_REG, MR_BASE);
1235 #if (NDEBUG & NDEBUG_ARBITRATION)
1236 printk("scsi%d : lost arbitration, deasserting MR_ARBITRATE\n",
1237 instance->host_no);
1238 #endif
1239 return -1;
1240 }
1241
1242
1243
1244 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_SEL);
1245
1246 if (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) {
1247 NCR5380_write(MODE_REG, MR_BASE);
1248 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1249 #if (NDEBUG & NDEBUG_ARBITRATION)
1250 printk("scsi%d : lost arbitration, deasserting ICR_ASSERT_SEL\n",
1251 instance->host_no);
1252 #endif
1253 return -1;
1254 }
1255
1256
1257
1258
1259
1260
1261 udelay(2);
1262
1263 #if (NDEBUG & NDEBUG_ARBITRATION)
1264 printk("scsi%d : won arbitration\n", instance->host_no);
1265 #endif
1266
1267
1268
1269
1270
1271
1272
1273 NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->target)));
1274
1275
1276
1277
1278
1279
1280
1281 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY |
1282 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL ));
1283 NCR5380_write(MODE_REG, MR_BASE);
1284
1285
1286
1287
1288
1289 NCR5380_write(SELECT_ENABLE_REG, 0);
1290
1291
1292 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA |
1293 ICR_ASSERT_ATN | ICR_ASSERT_SEL));
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309 udelay(1);
1310
1311 #if (NDEBUG & NDEBUG_SELECTION)
1312 printk("scsi%d : selecting target %d\n", instance->host_no, cmd->target);
1313 #endif
1314
1315
1316
1317
1318
1319
1320 timeout = jiffies + 25;
1321
1322
1323
1324
1325
1326
1327
1328 while ((jiffies < timeout) && !(NCR5380_read(STATUS_REG) &
1329 (SR_BSY | SR_IO)));
1330
1331 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) ==
1332 (SR_SEL | SR_IO)) {
1333 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1334 NCR5380_reselect(instance);
1335 printk ("scsi%d : reselection after won arbitration?\n",
1336 instance->host_no);
1337 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1338 return -1;
1339 }
1340
1341 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1342
1343 if (!(NCR5380_read(STATUS_REG) & SR_BSY)) {
1344 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1345 if (hostdata->targets_present & (1 << cmd->target)) {
1346 printk("scsi%d : weirdness\n", instance->host_no);
1347 if (hostdata->restart_select)
1348 printk("\trestart select\n");
1349 #ifdef NDEBUG
1350 NCR5380_print (instance);
1351 #endif
1352 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1353 return -1;
1354 }
1355 cmd->result = DID_BAD_TARGET << 16;
1356 cmd->scsi_done(cmd);
1357 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1358 #if (NDEBUG & NDEBUG_SELECTION)
1359 printk("scsi%d : target did not respond within 250ms\n",
1360 instance->host_no);
1361 #endif
1362 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1363 return 0;
1364 }
1365
1366 hostdata->targets_present |= (1 << cmd->target);
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
1385
1386 #if (NDEBUG & NDEBUG_SELECTION)
1387 printk("scsi%d : target %d selected, going into MESSAGE OUT phase.\n",
1388 instance->host_no, cmd->target);
1389 #endif
1390 tmp[0] = IDENTIFY(((instance->irq == IRQ_NONE) ? 0 : 1), cmd->lun);
1391 #ifdef SCSI2
1392 if (cmd->device->tagged_queue && (tag != TAG_NONE)) {
1393 tmp[1] = SIMPLE_QUEUE_TAG;
1394 if (tag == TAG_NEXT) {
1395
1396 if (cmd->device->current_tag == 0)
1397 cmd->device->current_tag = 1;
1398
1399 cmd->tag = cmd->device->current_tag;
1400 cmd->device->current_tag++;
1401 } else
1402 cmd->tag = (unsigned char) tag;
1403
1404 tmp[2] = cmd->tag;
1405 hostdata->last_message = SIMPLE_QUEUE_TAG;
1406 len = 3;
1407 } else
1408 #endif
1409 {
1410 len = 1;
1411 cmd->tag=0;
1412 }
1413
1414
1415 data = tmp;
1416 phase = PHASE_MSGOUT;
1417 NCR5380_transfer_pio(instance, &phase, &len, &data);
1418 #if (NDEBUG & NDEBUG_SELECTION)
1419 printk("scsi%d : nexus established.\n", instance->host_no);
1420 #endif
1421
1422 hostdata->connected = cmd;
1423 #ifdef SCSI2
1424 if (!cmd->device->tagged_queue)
1425 #endif
1426 hostdata->busy[cmd->target] |= (1 << cmd->lun);
1427
1428 initialize_SCp(cmd);
1429
1430
1431 return 0;
1432 }
1433
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 static int NCR5380_transfer_pio (struct Scsi_Host *instance,
1460 unsigned char *phase, int *count, unsigned char **data) {
1461 NCR5380_local_declare();
1462 register unsigned char p = *phase, tmp;
1463 register int c = *count;
1464 register unsigned char *d = *data;
1465 NCR5380_setup(instance);
1466
1467
1468
1469
1470
1471
1472
1473 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1474
1475 do {
1476
1477
1478
1479
1480 while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ));
1481
1482 #if (NDEBUG & NDEBUG_HANDSHAKE)
1483 printk("scsi%d : REQ detected\n", instance->host_no);
1484 #endif
1485
1486
1487 if ((tmp & PHASE_MASK) != p) {
1488 #if (NDEBUG & NDEBUG_PIO)
1489 printk("scsi%d : phase mismatch\n", instance->host_no);
1490 NCR5380_print_phase(instance);
1491 #endif
1492 break;
1493 }
1494
1495
1496 if (!(p & SR_IO))
1497 NCR5380_write(OUTPUT_DATA_REG, *d);
1498 else
1499 *d = NCR5380_read(CURRENT_SCSI_DATA_REG);
1500
1501 ++d;
1502
1503
1504
1505
1506
1507
1508
1509
1510 if (!(p & SR_IO)) {
1511 if (!((p & SR_MSG) && c > 1)) {
1512 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1513 ICR_ASSERT_DATA);
1514 #if (NDEBUG & NDEBUG_PIO)
1515 NCR5380_print(instance);
1516 #endif
1517 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1518 ICR_ASSERT_DATA | ICR_ASSERT_ACK);
1519 } else {
1520 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1521 ICR_ASSERT_DATA | ICR_ASSERT_ATN);
1522 #if (NDEBUG & NDEBUG_PIO)
1523 NCR5380_print(instance);
1524 #endif
1525 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1526 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
1527 }
1528 } else {
1529 #if (NDEBUG & NDEBUG_PIO)
1530 NCR5380_print(instance);
1531 #endif
1532 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
1533 }
1534
1535 while (NCR5380_read(STATUS_REG) & SR_REQ);
1536
1537 #if (NDEBUG & NDEBUG_HANDSHAKE)
1538 printk("scsi%d : req false, handshake complete\n", instance->host_no);
1539 #endif
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552 if (!(p == PHASE_MSGIN && c == 1)) {
1553 if (p == PHASE_MSGOUT && c > 1)
1554 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1555 else
1556 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1557 }
1558 } while (--c);
1559
1560 #if (NDEBUG & NDEBUG_PIO)
1561 printk("scsi%d : residual %d\n", instance->host_no, c);
1562 #endif
1563
1564 *count = c;
1565 *data = d;
1566 tmp = NCR5380_read(STATUS_REG);
1567 if (tmp & SR_REQ)
1568 *phase = tmp & PHASE_MASK;
1569 else
1570 *phase = PHASE_UNKNOWN;
1571
1572 if (!c || (*phase == p))
1573 return 0;
1574 else
1575 return -1;
1576 }
1577
1578 #if defined(REAL_DMA) || defined(PSEUDO_DMA) || defined (REAL_DMA_POLL)
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599 static int NCR5380_transfer_dma (struct Scsi_Host *instance,
1600 unsigned char *phase, int *count, unsigned char **data) {
1601 NCR5380_local_declare();
1602 register int c = *count;
1603 register unsigned char p = *phase;
1604 register unsigned char *d = *data;
1605 unsigned char tmp;
1606 int foo;
1607 #if defined(REAL_DMA_POLL)
1608 int cnt, toPIO;
1609 unsigned char saved_data = 0, overrun = 0, residue;
1610 #endif
1611
1612 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
1613 instance->hostdata;
1614
1615 NCR5380_setup(instance);
1616
1617 if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) {
1618 *phase = tmp;
1619 return -1;
1620 }
1621 #if defined(REAL_DMA) || defined(REAL_DMA_POLL)
1622 #ifdef READ_OVERRUNS
1623 if (p & SR_IO) {
1624 c -= 2;
1625 }
1626 #endif
1627 #if (NDEBUG & NDEBUG_DMA)
1628 printk("scsi%d : initializing DMA channel %d for %s, %d bytes %s %0x\n",
1629 instance->host_no, instance->dma_channel, (p & SR_IO) ? "reading" :
1630 "writing", c, (p & SR_IO) ? "to" : "from", (unsigned) d);
1631 #endif
1632 hostdata->dma_len = (p & SR_IO) ?
1633 NCR5380_dma_read_setup(instance, d, c) :
1634 NCR5380_dma_write_setup(instance, d, c);
1635 #endif
1636
1637 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1638
1639 #ifdef REAL_DMA
1640 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_ENABLE_EOP_INTR | MR_MONITOR_BSY);
1641 #elif defined(REAL_DMA_POLL)
1642 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE);
1643 #else
1644
1645
1646
1647
1648
1649
1650 #if defined(PSEUDO_DMA) && !defined(UNSAFE)
1651 cli();
1652 #endif
1653 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE);
1654 #endif
1655
1656 #if (NDEBUG & NDEBUG_DMA) & 0
1657 printk("scsi%d : mode reg = 0x%X\n", instance->host_no, NCR5380_read(MODE_REG));
1658 #endif
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669 if (p & SR_IO) {
1670 #ifndef FOO
1671 udelay(1);
1672 #endif
1673 NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0);
1674 } else {
1675 #ifndef FOO
1676 udelay(1);
1677 #endif
1678 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA);
1679 #ifndef FOO
1680 udelay(1);
1681 #endif
1682 NCR5380_write(START_DMA_SEND_REG, 0);
1683 #ifndef FOO
1684 udelay(1);
1685 #endif
1686 }
1687
1688 #if defined(REAL_DMA_POLL)
1689 do {
1690 tmp = NCR5380_read(BUS_AND_STATUS_REG);
1691 } while ((tmp & BASR_PHASE_MATCH) && !(tmp & (BASR_BUSY_ERROR |
1692 BASR_END_DMA_TRANSFER)));
1693
1694
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 if (p & SR_IO) {
1731 #ifdef READ_OVERRUNS
1732 udelay(10);
1733 if (((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH|BASR_ACK)) ==
1734 (BASR_PHASE_MATCH | BASR_ACK))) {
1735 saved_data = NCR5380_read(INPUT_DATA_REGISTER);
1736 overrun = 1;
1737 }
1738 #endif
1739 } else {
1740 int limit = 100;
1741 while (((tmp = NCR5380_read(BUS_AND_STATUS_REG)) & BASR_ACK) ||
1742 (NCR5380_read(STATUS_REG) & SR_REQ)) {
1743 if (!(tmp & BASR_PHASE_MATCH)) break;
1744 if (--limit < 0) break;
1745 }
1746 }
1747
1748
1749 #if (NDEBUG & NDEBUG_DMA)
1750 printk("scsi%d : polled DMA transfer complete, basr 0x%X, sr 0x%X\n",
1751 instance->host_no, tmp, NCR5380_read(STATUS_REG));
1752 #endif
1753
1754 NCR5380_write(MODE_REG, MR_BASE);
1755 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1756
1757 residue = NCR5380_dma_residual(instance);
1758 c -= residue;
1759 *count -= c;
1760 *data += c;
1761 *phase = NCR5380_read(STATUS_REG) & PHASE_MASK;
1762
1763 #ifdef READ_OVERRUNS
1764 if (*phase == p && (p & SR_IO) && residue == 0) {
1765 if (overrun) {
1766 #if (NDEBUG & NDEBUG_DMA)
1767 printk("Got an input overrun, using saved byte\n");
1768 #endif
1769 **data = saved_data;
1770 *data += 1;
1771 *count -= 1;
1772 cnt = toPIO = 1;
1773 } else {
1774 printk("No overrun??\n");
1775 cnt = toPIO = 2;
1776 }
1777 #if (NDEBUG & NDEBUG_DMA)
1778 printk("Doing %d-byte PIO to 0x%X\n", cnt, *data);
1779 #endif
1780 NCR5380_transfer_pio(instance, phase, &cnt, data);
1781 *count -= toPIO - cnt;
1782 }
1783 #endif
1784
1785 #if (NDEBUG & NDEBUG_DMA)
1786 printk("Return with data ptr = 0x%X, count %d, last 0x%X, next 0x%X\n",
1787 *data, *count, *(*data+*count-1), *(*data+*count));
1788 #endif
1789 return 0;
1790
1791 #elif defined(REAL_DMA)
1792 return 0;
1793 #else
1794 if (p & SR_IO) {
1795 if (!(foo = NCR5380_pread(instance, d, c - 1))) {
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ));
1819
1820 while (NCR5380_read(STATUS_REG) & SR_REQ);
1821 d[c - 1] = NCR5380_read(INPUT_DATA_REG);
1822 }
1823 } else {
1824 int timeout;
1825 if (!(foo = NCR5380_pwrite(instance, d, c))) {
1826
1827
1828
1829
1830 if (!(hostdata->flags & FLAG_HAS_LAST_BYTE_SENT)) {
1831 timeout = 20000;
1832 #if 1
1833 #if 1
1834 while (!(NCR5380_read(BUS_AND_STATUS_REG) &
1835 BASR_DRQ) && (NCR5380_read(BUS_AND_STATUS_REG) &
1836 BASR_PHASE_MATCH));
1837 #else
1838 if (NCR5380_read(STATUS_REG) & SR_REQ) {
1839 for (; timeout &&
1840 !(NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK);
1841 --timeout);
1842 for (; timeout && (NCR5380_read(STATUS_REG) & SR_REQ);
1843 --timeout);
1844 }
1845 #endif
1846
1847
1848 #if (NDEBUG & NDEBUG_LAST_BYTE_SENT)
1849 if (!timeout)
1850 printk("scsi%d : timed out on last byte\n",
1851 instance->host_no);
1852 #endif
1853
1854
1855 if (hostdata->flags & FLAG_CHECK_LAST_BYTE_SENT) {
1856 hostdata->flags &= ~FLAG_CHECK_LAST_BYTE_SENT;
1857 if (NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT) {
1858 hostdata->flags |= FLAG_HAS_LAST_BYTE_SENT;
1859 #if (NDEBUG & NDEBUG_LAST_BYTE_SENT)
1860 printk("scsi%d : last bit sent works\n",
1861 instance->host_no);
1862 #endif
1863 }
1864 }
1865 } else
1866 while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT));
1867 #else
1868 udelay (5);
1869 #endif
1870 }
1871 }
1872
1873 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1874 NCR5380_write(MODE_REG, MR_BASE);
1875
1876 *data = d + c;
1877 *count = 0;
1878 *phase = (NCR5380_read(STATUS_REG & PHASE_MASK));
1879 #if defined(PSEUDO_DMA) && !defined(UNSAFE)
1880 sti();
1881 #endif
1882 return foo;
1883 #endif
1884 }
1885 #endif
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904 static void NCR5380_information_transfer (struct Scsi_Host *instance) {
1905 NCR5380_local_declare();
1906 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
1907 instance->hostdata;
1908 unsigned char msgout = NOP;
1909 int sink = 0;
1910 int len, transfersize;
1911 unsigned char *data;
1912 unsigned char phase, tmp, extended_msg[10], old_phase=0xff;
1913 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected;
1914 NCR5380_setup(instance);
1915
1916 while (1) {
1917 tmp = NCR5380_read(STATUS_REG);
1918
1919 if (tmp & SR_REQ) {
1920 phase = (tmp & PHASE_MASK);
1921 if (phase != old_phase) {
1922 old_phase = phase;
1923 #if (NDEBUG & NDEBUG_INFORMATION)
1924 NCR5380_print_phase(instance);
1925 #endif
1926 }
1927
1928 if (sink && (phase != PHASE_MSGOUT)) {
1929 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1930
1931 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1932 ICR_ASSERT_ACK);
1933 while (NCR5380_read(STATUS_REG) & SR_REQ);
1934 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1935 ICR_ASSERT_ATN);
1936 sink = 0;
1937 continue;
1938 }
1939
1940 switch (phase) {
1941 case PHASE_DATAIN:
1942 case PHASE_DATAOUT:
1943 #if (NDEBUG & NDEBUG_NO_DATAOUT)
1944 printk("scsi%d : NDEBUG_NO_DATAOUT set, attempted DATAOUT aborted\n",
1945 instance->host_no);
1946 sink = 1;
1947 msgout = ABORT;
1948 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1949 break;
1950 #endif
1951
1952
1953
1954
1955
1956 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1957 ++cmd->SCp.buffer;
1958 --cmd->SCp.buffers_residual;
1959 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1960 cmd->SCp.ptr = cmd->SCp.buffer->address;
1961 #if (NDEBUG & NDEBUG_INFORMATION)
1962 printk("scsi%d : %d bytes and %d buffers left\n",
1963 instance->host_no, cmd->SCp.this_residual,
1964 cmd->SCp.buffers_residual);
1965 #endif
1966 }
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978 #if defined(PSEUDO_DMA) || defined(REAL_DMA_POLL)
1979 #ifdef NCR5380_dma_xfer_len
1980 if (!cmd->device->borken &&
1981 (transfersize = NCR5380_dma_xfer_len(instance, cmd)) != 0) {
1982 #else
1983 if (!cmd->device->borken &&
1984 (transfersize = cmd->transfersize) &&
1985 cmd->SCp.this_residual && !(cmd->SCp.this_residual %
1986 transfersize)) {
1987 #endif
1988 len = transfersize;
1989 if (NCR5380_transfer_dma(instance, &phase,
1990 &len, (unsigned char **) &cmd->SCp.ptr)) {
1991
1992
1993
1994
1995 printk("scsi%d : switching target %d lun %d to slow handshake\n",
1996 instance->host_no, cmd->target, cmd->lun);
1997 cmd->device->borken = 1;
1998 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1999 ICR_ASSERT_ATN);
2000 sink = 1;
2001 msgout = ABORT;
2002
2003 } else
2004 cmd->SCp.this_residual -= transfersize - len;
2005 } else
2006 #endif
2007 NCR5380_transfer_pio(instance, &phase,
2008 (int *) &cmd->SCp.this_residual, (unsigned char **)
2009 &cmd->SCp.ptr);
2010 break;
2011 case PHASE_MSGIN:
2012 len = 1;
2013 data = &tmp;
2014 NCR5380_transfer_pio(instance, &phase, &len, &data);
2015 cmd->SCp.Message = tmp;
2016
2017 switch (tmp) {
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028 #ifdef LINKED
2029 case LINKED_CMD_COMPLETE:
2030 case LINKED_FLG_CMD_COMPLETE:
2031
2032 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2033
2034 #if (NDEBUG & NDEBUG_LINKED)
2035 printk("scsi%d : target %d lun %d linked command complete.\n",
2036 instance->host_no, cmd->target, cmd->lun);
2037 #endif
2038
2039
2040
2041
2042
2043
2044 if (!cmd->next_link) {
2045 printk("scsi%d : target %d lun %d linked command complete, no next_link\n"
2046 instance->host_no, cmd->target, cmd->lun);
2047 sink = 1;
2048 msgout = ABORT;
2049 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2050 ICR_ASSERT_ATN);
2051 break;
2052 }
2053
2054 initialize_SCp(cmd->next_link);
2055
2056 cmd->next_link->tag = cmd->tag;
2057 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2058 #if (NDEBUG & NDEBUG_LINKED)
2059 printk("scsi%d : target %d lun %d linked request done, calling scsi_done().\n",
2060 instance->host_no, cmd->target, cmd->lun);
2061 #endif
2062 cmd->scsi_done(cmd);
2063 cmd = hostdata->connected;
2064 break;
2065 #endif
2066 case ABORT:
2067 case COMMAND_COMPLETE:
2068
2069 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2070 hostdata->connected = NULL;
2071 #if (NDEBUG & NDEBUG_QUEUES)
2072 printk("scsi%d : command for target %d, lun %d completed\n",
2073 instance->host_no, cmd->target, cmd->lun);
2074 #endif
2075 hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093 if (cmd->cmnd[0] != REQUEST_SENSE)
2094 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2095 else if (cmd->SCp.Status != GOOD)
2096 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
2097
2098 #ifdef AUTOSENSE
2099 if ((cmd->cmnd[0] != REQUEST_SENSE) &&
2100 (cmd->SCp.Status == CHECK_CONDITION)) {
2101 #if (NDEBUG & NDEBUG_AUTOSENSE)
2102 printk("scsi%d : performing request sense\n",
2103 instance->host_no);
2104 #endif
2105 cmd->cmnd[0] = REQUEST_SENSE;
2106 cmd->cmnd[1] &= 0xe0;
2107 cmd->cmnd[2] = 0;
2108 cmd->cmnd[3] = 0;
2109 cmd->cmnd[4] = sizeof(cmd->sense_buffer);
2110 cmd->cmnd[5] = 0;
2111
2112 cmd->SCp.buffer = NULL;
2113 cmd->SCp.buffers_residual = 0;
2114 cmd->SCp.ptr = (char *) cmd->sense_buffer;
2115 cmd->SCp.this_residual = sizeof(cmd->sense_buffer);
2116
2117 cli();
2118 cmd->host_scribble = (unsigned char *)
2119 hostdata->issue_queue;
2120 hostdata->issue_queue = (Scsi_Cmnd *) cmd;
2121 sti();
2122 #if (NDEBUG & NDEBUG_QUEUES)
2123 printk("scsi%d : REQUEST SENSE added to head of issue queue\n");
2124 #endif
2125 } else
2126 #endif
2127 cmd->scsi_done(cmd);
2128
2129 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2130
2131
2132
2133
2134 NCR5380_write(TARGET_COMMAND_REG, 0);
2135
2136 while ((NCR5380_read(STATUS_REG) & SR_BSY) &&
2137 !hostdata->connected);
2138 return;
2139 case MESSAGE_REJECT:
2140
2141 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2142 switch (hostdata->last_message) {
2143 case HEAD_OF_QUEUE_TAG:
2144 case ORDERED_QUEUE_TAG:
2145 case SIMPLE_QUEUE_TAG:
2146 cmd->device->tagged_queue = 0;
2147 hostdata->busy[cmd->target] |= (1 << cmd->lun);
2148 break;
2149 default:
2150 break;
2151 }
2152 case DISCONNECT:
2153
2154 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2155 cmd->device->disconnect = 1;
2156 cli();
2157 cmd->host_scribble = (unsigned char *)
2158 hostdata->disconnected_queue;
2159 hostdata->connected = NULL;
2160 hostdata->disconnected_queue = cmd;
2161 sti();
2162 #if (NDEBUG & NDEBUG_QUEUES)
2163 printk("scsi%d : command for target %d lun %d was moved from connected to"
2164 " the disconnected_queue\n", instance->host_no,
2165 cmd->target, cmd->lun);
2166 #endif
2167
2168
2169
2170
2171 NCR5380_write(TARGET_COMMAND_REG, 0);
2172
2173
2174 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2175
2176 while ((NCR5380_read(STATUS_REG) & SR_BSY) &&
2177 !hostdata->connected);
2178 return;
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189 case SAVE_POINTERS:
2190 case RESTORE_POINTERS:
2191
2192 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2193 break;
2194 case EXTENDED_MESSAGE:
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207 extended_msg[0] = EXTENDED_MESSAGE;
2208
2209 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2210
2211 #if (NDEBUG & NDEBUG_EXTENDED)
2212 printk("scsi%d : receiving extended message\n",
2213 instance->host_no);
2214 #endif
2215
2216 len = 2;
2217 data = extended_msg + 1;
2218 phase = PHASE_MSGIN;
2219 NCR5380_transfer_pio(instance, &phase, &len, &data);
2220
2221 #if (NDEBUG & NDEBUG_EXTENDED)
2222 printk("scsi%d : length=%d, code=0x%02x\n",
2223 instance->host_no, (int) extended_msg[1],
2224 (int) extended_msg[2]);
2225 #endif
2226
2227 if (!len && extended_msg[1] <=
2228 (sizeof (extended_msg) - 1)) {
2229
2230 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2231 len = extended_msg[1] - 1;
2232 data = extended_msg + 3;
2233 phase = PHASE_MSGIN;
2234
2235 NCR5380_transfer_pio(instance, &phase, &len, &data);
2236
2237 #if (NDEBUG & NDEBUG_EXTENDED)
2238 printk("scsi%d : message received, residual %d\n",
2239 instance->host_no, len);
2240 #endif
2241
2242 switch (extended_msg[2]) {
2243 case EXTENDED_SDTR:
2244 case EXTENDED_WDTR:
2245 case EXTENDED_MODIFY_DATA_POINTER:
2246 case EXTENDED_EXTENDED_IDENTIFY:
2247 tmp = 0;
2248 }
2249 } else if (len) {
2250 printk("scsi%d: error receiving extended message\n",
2251 instance->host_no);
2252 tmp = 0;
2253 } else {
2254 printk("scsi%d: extended message code %02x length %d is too long\n",
2255 instance->host_no, extended_msg[2], extended_msg[1]);
2256 tmp = 0;
2257 }
2258
2259
2260
2261
2262
2263
2264 default:
2265 if (!tmp) {
2266 printk("scsi%d: rejecting message ", instance->host_no);
2267 print_msg (extended_msg);
2268 printk("\n");
2269 } else if (tmp != EXTENDED_MESSAGE)
2270 printk("scsi%d: rejecting unknown message %02x from target %d, lun %d\n",
2271 instance->host_no, tmp, cmd->target, cmd->lun);
2272 else
2273 printk("scsi%d: rejecting unknown extended message code %02x, length %d from target %d, lun %d\n",
2274 instance->host_no, extended_msg[1], extended_msg[0], cmd->target, cmd->lun);
2275
2276 msgout = MESSAGE_REJECT;
2277 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2278 ICR_ASSERT_ATN);
2279 break;
2280 }
2281 break;
2282 case PHASE_MSGOUT:
2283 len = 1;
2284 data = &msgout;
2285 hostdata->last_message = msgout;
2286 NCR5380_transfer_pio(instance, &phase, &len, &data);
2287 if (msgout == ABORT) {
2288 hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
2289 hostdata->connected = NULL;
2290 cmd->result = DID_ERROR << 16;
2291 cmd->scsi_done(cmd);
2292 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2293 return;
2294 }
2295 msgout = NOP;
2296 break;
2297 case PHASE_CMDOUT:
2298 len = COMMAND_SIZE(cmd->cmnd[0]);
2299 data = cmd->cmnd;
2300
2301
2302
2303
2304
2305 NCR5380_transfer_pio(instance, &phase, &len,
2306 &data);
2307 #ifdef USLEEP
2308 if (!disconnect && should_disconnect(cmd->cmnd[0])) {
2309 hostdata->time_expires = jiffies + USLEEP_SLEEP;
2310 #if (NDEBUG & NDEBUG_USLEEP)
2311 printk("scsi%d : issued command, sleeping until %ul\n", instance->host_no,
2312 hostdata->time_expires);
2313 #endif
2314 NCR5380_set_timer (instance);
2315 return;
2316 }
2317 #endif
2318 break;
2319 case PHASE_STATIN:
2320 len = 1;
2321 data = &tmp;
2322 NCR5380_transfer_pio(instance, &phase, &len, &data);
2323 cmd->SCp.Status = tmp;
2324 break;
2325 default:
2326 printk("scsi%d : unknown phase\n", instance->host_no);
2327 #ifdef NDEBUG
2328 NCR5380_print(instance);
2329 #endif
2330 }
2331 }
2332 #ifdef USLEEP
2333 else {
2334 if (!disconnect && hostdata->time_expires && jiffies >
2335 hostdata->time_expires) {
2336 hostdata->time_expires = jiffies + USLEEP_SLEEP;
2337 #if (NDEBUG & NDEBUG_USLEEP)
2338 printk("scsi%d : poll timed out, sleeping until %ul\n", instance->host_no,
2339 hostdata->time_expires);
2340 #endif
2341 NCR5380_set_timer (instance);
2342 return;
2343 }
2344 }
2345 #endif
2346 }
2347 }
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361 static void NCR5380_reselect (struct Scsi_Host *instance) {
2362 NCR5380_local_declare();
2363 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
2364 instance->hostdata;
2365 unsigned char target_mask;
2366 unsigned char lun, phase;
2367 int len;
2368 #ifdef SCSI2
2369 unsigned char tag;
2370 #endif
2371 unsigned char msg[3];
2372 unsigned char *data;
2373 Scsi_Cmnd *tmp = NULL, *prev;
2374 int abort = 0;
2375 NCR5380_setup(instance);
2376
2377
2378
2379
2380
2381
2382 NCR5380_write(MODE_REG, MR_BASE);
2383 hostdata->restart_select = 1;
2384
2385 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask);
2386
2387 #if (NDEBUG & NDEBUG_RESELECTION)
2388 printk("scsi%d : reselect\n", instance->host_no);
2389 #endif
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
2401
2402 while (NCR5380_read(STATUS_REG) & SR_SEL);
2403 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2404
2405
2406
2407
2408
2409 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
2410
2411 len = 1;
2412 data = msg;
2413 phase = PHASE_MSGIN;
2414 NCR5380_transfer_pio(instance, &phase, &len, &data);
2415
2416
2417 if (!msg[0] & 0x80) {
2418 printk("scsi%d : expecting IDENTIFY message, got ",
2419 instance->host_no);
2420 print_msg(msg);
2421 abort = 1;
2422 } else {
2423
2424 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2425 lun = (msg[0] & 0x07);
2426
2427
2428
2429
2430
2431
2432
2433 #ifdef SCSI2
2434 #error "SCSI-II tagged queueing is not supported yet"
2435 #endif
2436
2437
2438
2439
2440
2441
2442
2443 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL;
2444 tmp; prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble)
2445 if ((target_mask == (1 << tmp->target)) && (lun == tmp->lun)
2446 #ifdef SCSI2
2447 && (tag == tmp->tag)
2448 #endif
2449 ) {
2450 if (prev)
2451 prev->host_scribble = tmp->host_scribble;
2452 else
2453 hostdata->disconnected_queue = (Scsi_Cmnd *) tmp->host_scribble;
2454 tmp->host_scribble = NULL;
2455 break;
2456 }
2457
2458 if (!tmp) {
2459 #ifdef SCSI2
2460 printk("scsi%d : warning : target bitmask %02x lun %d tag %d not in disconnect_queue.\n",
2461 instance->host_no, target_mask, lun, tag);
2462 #else
2463 printk("scsi%d : warning : target bitmask %02x lun %d not in disconnect_queue.\n",
2464 instance->host_no, target_mask, lun);
2465 #endif
2466
2467
2468
2469
2470 abort = 1;
2471 }
2472 }
2473
2474 if (abort) {
2475 msg[0] = ABORT;
2476 len = 1;
2477 data = msg;
2478 phase = PHASE_MSGOUT;
2479 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
2480 NCR5380_transfer_pio(instance, &phase, &len, &data);
2481 } else {
2482 hostdata->connected = tmp;
2483 #if (NDEBUG & NDEBUG_RESELECTION)
2484 printk"scsi%d : nexus established, target = %d, lun = %d, tag = %d\n",
2485 instance->host_no, tmp->target, tmp->lun, tmp->tag);
2486 #endif
2487 }
2488 }
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502 #ifdef REAL_DMA
2503 static void NCR5380_dma_complete (NCR5380_instance *instance) {
2504 NCR5380_local_declare();
2505 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *
2506 instance->hostdata);
2507 int transferred;
2508 NCR5380_setup(instance);
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519 while (NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK);
2520
2521 NCR5380_write(MODE_REG, MR_BASE);
2522 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2523
2524
2525
2526
2527
2528
2529
2530 if (!(hostdata->connected->SCp.phase & SR_CD)) {
2531 transferred = instance->dmalen - NCR5380_dma_residual();
2532 hostdata->connected->SCp.this_residual -= transferred;
2533 hostdata->connected->SCp.ptr += transferred;
2534 }
2535 }
2536 #endif
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555 #ifndef NCR5380_abort
2556 static
2557 #endif
2558 int NCR5380_abort (Scsi_Cmnd *cmd) {
2559 NCR5380_local_declare();
2560 struct Scsi_Host *instance = cmd->host;
2561 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
2562 instance->hostdata;
2563 Scsi_Cmnd *tmp, **prev;
2564 unsigned char msg, phase, *msgptr;
2565 int len;
2566
2567 printk("scsi%d : aborting command\n", instance->host_no);
2568 print_Scsi_Cmnd (cmd);
2569
2570 NCR5380_print_status (instance);
2571
2572 cli();
2573 NCR5380_setup(instance);
2574
2575 #if (NDEBUG & NDEBUG_ABORT)
2576 printk("scsi%d : abort called\n", instance->host_no);
2577 printk(" basr 0x%X, sr 0x%X\n",
2578 NCR5380_read(BUS_AND_STATUS_REG), NCR5380_read(STATUS_REG));
2579 #endif
2580
2581 #if 0
2582
2583
2584
2585
2586
2587
2588 if (hostdata->connected == cmd) {
2589 #if (NDEBUG & NDEBUG_ABORT)
2590 printk("scsi%d : aborting connected command\n", instance->host_no);
2591 #endif
2592 hostdata->aborted = 1;
2593
2594
2595
2596
2597
2598 NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN);
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610 return 0;
2611 }
2612 #endif
2613
2614
2615
2616
2617
2618 for (prev = (Scsi_Cmnd **) &(hostdata->issue_queue),
2619 tmp = (Scsi_Cmnd *) hostdata->issue_queue;
2620 tmp; prev = (Scsi_Cmnd **) &(tmp->host_scribble), tmp =
2621 (Scsi_Cmnd *) tmp->host_scribble)
2622 if (cmd == tmp) {
2623 (*prev) = (Scsi_Cmnd *) tmp->host_scribble;
2624 tmp->host_scribble = NULL;
2625 tmp->result = DID_ABORT << 16;
2626 sti();
2627 #if (NDEBUG & NDEBUG_ABORT)
2628 printk("scsi%d : abort removed command from issue queue.\n",
2629 instance->host_no);
2630 #endif
2631 tmp->done(tmp);
2632 return SCSI_ABORT_SUCCESS;
2633 }
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646 if (hostdata->connected) {
2647 sti();
2648 #if (NDEBUG & NDEBUG_ABORT)
2649 printk("scsi%d : abort failed, command connected.\n", instance->host_no);
2650 #endif
2651 return SCSI_ABORT_NOT_RUNNING;
2652 }
2653
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 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp;
2680 tmp = (Scsi_Cmnd *) tmp->host_scribble)
2681 if (cmd == tmp) {
2682 sti();
2683 #if (NDEBUG & NDEBUG_ABORT)
2684 printk("scsi%d : aborting disconnected command.\n", instance->host_no);
2685 #endif
2686
2687 if (NCR5380_select (instance, cmd, (int) cmd->tag))
2688 return SCSI_ABORT_BUSY;
2689
2690 #if (NDEBUG & NDEBUG_ABORT)
2691 printk("scsi%d : nexus reestablished.\n", instance->host_no);
2692 #endif
2693
2694 msg = ABORT;
2695 msgptr = &msg;
2696 len = 1;
2697 phase = PHASE_MSGOUT;
2698 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
2699 NCR5380_transfer_pio (instance, &phase, &len, &msgptr);
2700
2701 cli();
2702 for (prev = (Scsi_Cmnd **) &(hostdata->disconnected_queue),
2703 tmp = (Scsi_Cmnd *) hostdata->disconnected_queue;
2704 tmp; prev = (Scsi_Cmnd **) &(tmp->host_scribble), tmp =
2705 (Scsi_Cmnd *) tmp->host_scribble)
2706 if (cmd == tmp) {
2707 *prev = (Scsi_Cmnd *) tmp->host_scribble;
2708 tmp->host_scribble = NULL;
2709 tmp->result = DID_ABORT << 16;
2710 sti();
2711 tmp->done(tmp);
2712 return SCSI_ABORT_SUCCESS;
2713 }
2714 }
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726 sti();
2727 printk("scsi%d : warning : SCSI command probably completed successfully\n"
2728 " before abortion\n", instance->host_no);
2729 return SCSI_ABORT_NOT_RUNNING;
2730 }
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742 #ifndef NCR5380_reset
2743 static
2744 #endif
2745 int NCR5380_reset (Scsi_Cmnd *cmd) {
2746 NCR5380_local_declare();
2747 NCR5380_setup(cmd->host);
2748
2749 NCR5380_print_status (cmd->host);
2750
2751 cli();
2752 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST);
2753 udelay(25);
2754 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2755 sti();
2756
2757 return SCSI_RESET_WAKEUP;
2758 }
2759