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