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