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 sig) {
604 probe_irq = sig;
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) {
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, transfersize;
1916 unsigned char *data;
1917 unsigned char phase, tmp, extended_msg[10], old_phase=0xff;
1918 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected;
1919 NCR5380_setup(instance);
1920
1921 while (1) {
1922 tmp = NCR5380_read(STATUS_REG);
1923
1924 if (tmp & SR_REQ) {
1925 phase = (tmp & PHASE_MASK);
1926 if (phase != old_phase) {
1927 old_phase = phase;
1928 #if (NDEBUG & NDEBUG_INFORMATION)
1929 NCR5380_print_phase(instance);
1930 #endif
1931 }
1932
1933 if (sink && (phase != PHASE_MSGOUT)) {
1934 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1935
1936 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1937 ICR_ASSERT_ACK);
1938 while (NCR5380_read(STATUS_REG) & SR_REQ);
1939 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1940 ICR_ASSERT_ATN);
1941 sink = 0;
1942 continue;
1943 }
1944
1945 switch (phase) {
1946 case PHASE_DATAIN:
1947 case PHASE_DATAOUT:
1948 #if (NDEBUG & NDEBUG_NO_DATAOUT)
1949 printk("scsi%d : NDEBUG_NO_DATAOUT set, attempted DATAOUT aborted\n",
1950 instance->host_no);
1951 sink = 1;
1952 msgout = ABORT;
1953 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1954 break;
1955 #endif
1956
1957
1958
1959
1960
1961 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1962 ++cmd->SCp.buffer;
1963 --cmd->SCp.buffers_residual;
1964 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1965 cmd->SCp.ptr = cmd->SCp.buffer->address;
1966 #if (NDEBUG & NDEBUG_INFORMATION)
1967 printk("scsi%d : %d bytes and %d buffers left\n",
1968 instance->host_no, cmd->SCp.this_residual,
1969 cmd->SCp.buffers_residual);
1970 #endif
1971 }
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983 #if defined(PSEUDO_DMA) || defined(REAL_DMA_POLL)
1984 #ifdef NCR5380_dma_xfer_len
1985 if (!cmd->device->borken &&
1986 (transfersize = NCR5380_dma_xfer_len(instance, cmd)) != 0) {
1987 #else
1988 transfersize = cmd->transfersize;
1989
1990 #ifdef LIMIT_TRANSFERSIZE
1991 if( transfersize > 512 )
1992 transfersize = 512;
1993 #endif
1994
1995 if (!cmd->device->borken && transfersize &&
1996 cmd->SCp.this_residual && !(cmd->SCp.this_residual %
1997 transfersize)) {
1998 #endif
1999 len = transfersize;
2000 if (NCR5380_transfer_dma(instance, &phase,
2001 &len, (unsigned char **) &cmd->SCp.ptr)) {
2002
2003
2004
2005
2006 printk("scsi%d : switching target %d lun %d to slow handshake\n",
2007 instance->host_no, cmd->target, cmd->lun);
2008 cmd->device->borken = 1;
2009 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2010 ICR_ASSERT_ATN);
2011 sink = 1;
2012 msgout = ABORT;
2013
2014 } else
2015 cmd->SCp.this_residual -= transfersize - len;
2016 } else
2017 #endif
2018 NCR5380_transfer_pio(instance, &phase,
2019 (int *) &cmd->SCp.this_residual, (unsigned char **)
2020 &cmd->SCp.ptr);
2021 break;
2022 case PHASE_MSGIN:
2023 len = 1;
2024 data = &tmp;
2025 NCR5380_transfer_pio(instance, &phase, &len, &data);
2026 cmd->SCp.Message = tmp;
2027
2028 switch (tmp) {
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039 #ifdef LINKED
2040 case LINKED_CMD_COMPLETE:
2041 case LINKED_FLG_CMD_COMPLETE:
2042
2043 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2044
2045 #if (NDEBUG & NDEBUG_LINKED)
2046 printk("scsi%d : target %d lun %d linked command complete.\n",
2047 instance->host_no, cmd->target, cmd->lun);
2048 #endif
2049
2050
2051
2052
2053
2054
2055 if (!cmd->next_link) {
2056 printk("scsi%d : target %d lun %d linked command complete, no next_link\n"
2057 instance->host_no, cmd->target, cmd->lun);
2058 sink = 1;
2059 msgout = ABORT;
2060 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2061 ICR_ASSERT_ATN);
2062 break;
2063 }
2064
2065 initialize_SCp(cmd->next_link);
2066
2067 cmd->next_link->tag = cmd->tag;
2068 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2069 #if (NDEBUG & NDEBUG_LINKED)
2070 printk("scsi%d : target %d lun %d linked request done, calling scsi_done().\n",
2071 instance->host_no, cmd->target, cmd->lun);
2072 #endif
2073 cmd->scsi_done(cmd);
2074 cmd = hostdata->connected;
2075 break;
2076 #endif
2077 case ABORT:
2078 case COMMAND_COMPLETE:
2079
2080 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2081 hostdata->connected = NULL;
2082 #if (NDEBUG & NDEBUG_QUEUES)
2083 printk("scsi%d : command for target %d, lun %d completed\n",
2084 instance->host_no, cmd->target, cmd->lun);
2085 #endif
2086 hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104 if (cmd->cmnd[0] != REQUEST_SENSE)
2105 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2106 else if (cmd->SCp.Status != GOOD)
2107 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
2108
2109 #ifdef AUTOSENSE
2110 if ((cmd->cmnd[0] != REQUEST_SENSE) &&
2111 (cmd->SCp.Status == CHECK_CONDITION)) {
2112 #if (NDEBUG & NDEBUG_AUTOSENSE)
2113 printk("scsi%d : performing request sense\n",
2114 instance->host_no);
2115 #endif
2116 cmd->cmnd[0] = REQUEST_SENSE;
2117 cmd->cmnd[1] &= 0xe0;
2118 cmd->cmnd[2] = 0;
2119 cmd->cmnd[3] = 0;
2120 cmd->cmnd[4] = sizeof(cmd->sense_buffer);
2121 cmd->cmnd[5] = 0;
2122
2123 cmd->SCp.buffer = NULL;
2124 cmd->SCp.buffers_residual = 0;
2125 cmd->SCp.ptr = (char *) cmd->sense_buffer;
2126 cmd->SCp.this_residual = sizeof(cmd->sense_buffer);
2127
2128 cli();
2129 cmd->host_scribble = (unsigned char *)
2130 hostdata->issue_queue;
2131 hostdata->issue_queue = (Scsi_Cmnd *) cmd;
2132 sti();
2133 #if (NDEBUG & NDEBUG_QUEUES)
2134 printk("scsi%d : REQUEST SENSE added to head of issue queue\n");
2135 #endif
2136 } else
2137 #endif
2138 cmd->scsi_done(cmd);
2139
2140 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2141
2142
2143
2144
2145 NCR5380_write(TARGET_COMMAND_REG, 0);
2146
2147 while ((NCR5380_read(STATUS_REG) & SR_BSY) &&
2148 !hostdata->connected);
2149 return;
2150 case MESSAGE_REJECT:
2151
2152 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2153 switch (hostdata->last_message) {
2154 case HEAD_OF_QUEUE_TAG:
2155 case ORDERED_QUEUE_TAG:
2156 case SIMPLE_QUEUE_TAG:
2157 cmd->device->tagged_queue = 0;
2158 hostdata->busy[cmd->target] |= (1 << cmd->lun);
2159 break;
2160 default:
2161 break;
2162 }
2163 case DISCONNECT:
2164
2165 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2166 cmd->device->disconnect = 1;
2167 cli();
2168 cmd->host_scribble = (unsigned char *)
2169 hostdata->disconnected_queue;
2170 hostdata->connected = NULL;
2171 hostdata->disconnected_queue = cmd;
2172 sti();
2173 #if (NDEBUG & NDEBUG_QUEUES)
2174 printk("scsi%d : command for target %d lun %d was moved from connected to"
2175 " the disconnected_queue\n", instance->host_no,
2176 cmd->target, cmd->lun);
2177 #endif
2178
2179
2180
2181
2182 NCR5380_write(TARGET_COMMAND_REG, 0);
2183
2184
2185 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2186
2187 while ((NCR5380_read(STATUS_REG) & SR_BSY) &&
2188 !hostdata->connected);
2189 return;
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200 case SAVE_POINTERS:
2201 case RESTORE_POINTERS:
2202
2203 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2204 break;
2205 case EXTENDED_MESSAGE:
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218 extended_msg[0] = EXTENDED_MESSAGE;
2219
2220 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2221
2222 #if (NDEBUG & NDEBUG_EXTENDED)
2223 printk("scsi%d : receiving extended message\n",
2224 instance->host_no);
2225 #endif
2226
2227 len = 2;
2228 data = extended_msg + 1;
2229 phase = PHASE_MSGIN;
2230 NCR5380_transfer_pio(instance, &phase, &len, &data);
2231
2232 #if (NDEBUG & NDEBUG_EXTENDED)
2233 printk("scsi%d : length=%d, code=0x%02x\n",
2234 instance->host_no, (int) extended_msg[1],
2235 (int) extended_msg[2]);
2236 #endif
2237
2238 if (!len && extended_msg[1] <=
2239 (sizeof (extended_msg) - 1)) {
2240
2241 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2242 len = extended_msg[1] - 1;
2243 data = extended_msg + 3;
2244 phase = PHASE_MSGIN;
2245
2246 NCR5380_transfer_pio(instance, &phase, &len, &data);
2247
2248 #if (NDEBUG & NDEBUG_EXTENDED)
2249 printk("scsi%d : message received, residual %d\n",
2250 instance->host_no, len);
2251 #endif
2252
2253 switch (extended_msg[2]) {
2254 case EXTENDED_SDTR:
2255 case EXTENDED_WDTR:
2256 case EXTENDED_MODIFY_DATA_POINTER:
2257 case EXTENDED_EXTENDED_IDENTIFY:
2258 tmp = 0;
2259 }
2260 } else if (len) {
2261 printk("scsi%d: error receiving extended message\n",
2262 instance->host_no);
2263 tmp = 0;
2264 } else {
2265 printk("scsi%d: extended message code %02x length %d is too long\n",
2266 instance->host_no, extended_msg[2], extended_msg[1]);
2267 tmp = 0;
2268 }
2269
2270
2271
2272
2273
2274
2275 default:
2276 if (!tmp) {
2277 printk("scsi%d: rejecting message ", instance->host_no);
2278 print_msg (extended_msg);
2279 printk("\n");
2280 } else if (tmp != EXTENDED_MESSAGE)
2281 printk("scsi%d: rejecting unknown message %02x from target %d, lun %d\n",
2282 instance->host_no, tmp, cmd->target, cmd->lun);
2283 else
2284 printk("scsi%d: rejecting unknown extended message code %02x, length %d from target %d, lun %d\n",
2285 instance->host_no, extended_msg[1], extended_msg[0], cmd->target, cmd->lun);
2286
2287 msgout = MESSAGE_REJECT;
2288 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2289 ICR_ASSERT_ATN);
2290 break;
2291 }
2292 break;
2293 case PHASE_MSGOUT:
2294 len = 1;
2295 data = &msgout;
2296 hostdata->last_message = msgout;
2297 NCR5380_transfer_pio(instance, &phase, &len, &data);
2298 if (msgout == ABORT) {
2299 hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
2300 hostdata->connected = NULL;
2301 cmd->result = DID_ERROR << 16;
2302 cmd->scsi_done(cmd);
2303 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2304 return;
2305 }
2306 msgout = NOP;
2307 break;
2308 case PHASE_CMDOUT:
2309 len = COMMAND_SIZE(cmd->cmnd[0]);
2310 data = cmd->cmnd;
2311
2312
2313
2314
2315
2316 NCR5380_transfer_pio(instance, &phase, &len,
2317 &data);
2318 #ifdef USLEEP
2319 if (!disconnect && should_disconnect(cmd->cmnd[0])) {
2320 hostdata->time_expires = jiffies + USLEEP_SLEEP;
2321 #if (NDEBUG & NDEBUG_USLEEP)
2322 printk("scsi%d : issued command, sleeping until %ul\n", instance->host_no,
2323 hostdata->time_expires);
2324 #endif
2325 NCR5380_set_timer (instance);
2326 return;
2327 }
2328 #endif
2329 break;
2330 case PHASE_STATIN:
2331 len = 1;
2332 data = &tmp;
2333 NCR5380_transfer_pio(instance, &phase, &len, &data);
2334 cmd->SCp.Status = tmp;
2335 break;
2336 default:
2337 printk("scsi%d : unknown phase\n", instance->host_no);
2338 #ifdef NDEBUG
2339 NCR5380_print(instance);
2340 #endif
2341 }
2342 }
2343 #ifdef USLEEP
2344 else {
2345 if (!disconnect && hostdata->time_expires && jiffies >
2346 hostdata->time_expires) {
2347 hostdata->time_expires = jiffies + USLEEP_SLEEP;
2348 #if (NDEBUG & NDEBUG_USLEEP)
2349 printk("scsi%d : poll timed out, sleeping until %ul\n", instance->host_no,
2350 hostdata->time_expires);
2351 #endif
2352 NCR5380_set_timer (instance);
2353 return;
2354 }
2355 }
2356 #endif
2357 }
2358 }
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372 static void NCR5380_reselect (struct Scsi_Host *instance) {
2373 NCR5380_local_declare();
2374 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
2375 instance->hostdata;
2376 unsigned char target_mask;
2377 unsigned char lun, phase;
2378 int len;
2379 #ifdef SCSI2
2380 unsigned char tag;
2381 #endif
2382 unsigned char msg[3];
2383 unsigned char *data;
2384 Scsi_Cmnd *tmp = NULL, *prev;
2385 int abort = 0;
2386 NCR5380_setup(instance);
2387
2388
2389
2390
2391
2392
2393 NCR5380_write(MODE_REG, MR_BASE);
2394 hostdata->restart_select = 1;
2395
2396 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask);
2397
2398 #if (NDEBUG & NDEBUG_RESELECTION)
2399 printk("scsi%d : reselect\n", instance->host_no);
2400 #endif
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
2412
2413 while (NCR5380_read(STATUS_REG) & SR_SEL);
2414 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2415
2416
2417
2418
2419
2420 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
2421
2422 len = 1;
2423 data = msg;
2424 phase = PHASE_MSGIN;
2425 NCR5380_transfer_pio(instance, &phase, &len, &data);
2426
2427
2428 if (!msg[0] & 0x80) {
2429 printk("scsi%d : expecting IDENTIFY message, got ",
2430 instance->host_no);
2431 print_msg(msg);
2432 abort = 1;
2433 } else {
2434
2435 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2436 lun = (msg[0] & 0x07);
2437
2438
2439
2440
2441
2442
2443
2444 #ifdef SCSI2
2445 #error "SCSI-II tagged queueing is not supported yet"
2446 #endif
2447
2448
2449
2450
2451
2452
2453
2454 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL;
2455 tmp; prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble)
2456 if ((target_mask == (1 << tmp->target)) && (lun == tmp->lun)
2457 #ifdef SCSI2
2458 && (tag == tmp->tag)
2459 #endif
2460 ) {
2461 if (prev)
2462 prev->host_scribble = tmp->host_scribble;
2463 else
2464 hostdata->disconnected_queue = (Scsi_Cmnd *) tmp->host_scribble;
2465 tmp->host_scribble = NULL;
2466 break;
2467 }
2468
2469 if (!tmp) {
2470 #ifdef SCSI2
2471 printk("scsi%d : warning : target bitmask %02x lun %d tag %d not in disconnect_queue.\n",
2472 instance->host_no, target_mask, lun, tag);
2473 #else
2474 printk("scsi%d : warning : target bitmask %02x lun %d not in disconnect_queue.\n",
2475 instance->host_no, target_mask, lun);
2476 #endif
2477
2478
2479
2480
2481 abort = 1;
2482 }
2483 }
2484
2485 if (abort) {
2486 msg[0] = ABORT;
2487 len = 1;
2488 data = msg;
2489 phase = PHASE_MSGOUT;
2490 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
2491 NCR5380_transfer_pio(instance, &phase, &len, &data);
2492 } else {
2493 hostdata->connected = tmp;
2494 #if (NDEBUG & NDEBUG_RESELECTION)
2495 printk"scsi%d : nexus established, target = %d, lun = %d, tag = %d\n",
2496 instance->host_no, tmp->target, tmp->lun, tmp->tag);
2497 #endif
2498 }
2499 }
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513 #ifdef REAL_DMA
2514 static void NCR5380_dma_complete (NCR5380_instance *instance) {
2515 NCR5380_local_declare();
2516 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *
2517 instance->hostdata);
2518 int transferred;
2519 NCR5380_setup(instance);
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530 while (NCR5380_read(BUS_AND_STATUS_REG) & BASR_ACK);
2531
2532 NCR5380_write(MODE_REG, MR_BASE);
2533 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2534
2535
2536
2537
2538
2539
2540
2541 if (!(hostdata->connected->SCp.phase & SR_CD)) {
2542 transferred = instance->dmalen - NCR5380_dma_residual();
2543 hostdata->connected->SCp.this_residual -= transferred;
2544 hostdata->connected->SCp.ptr += transferred;
2545 }
2546 }
2547 #endif
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566 #ifndef NCR5380_abort
2567 static
2568 #endif
2569 int NCR5380_abort (Scsi_Cmnd *cmd) {
2570 NCR5380_local_declare();
2571 struct Scsi_Host *instance = cmd->host;
2572 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *)
2573 instance->hostdata;
2574 Scsi_Cmnd *tmp, **prev;
2575 unsigned char msg, phase, *msgptr;
2576 int len;
2577
2578 printk("scsi%d : aborting command\n", instance->host_no);
2579 print_Scsi_Cmnd (cmd);
2580
2581 NCR5380_print_status (instance);
2582
2583 cli();
2584 NCR5380_setup(instance);
2585
2586 #if (NDEBUG & NDEBUG_ABORT)
2587 printk("scsi%d : abort called\n", instance->host_no);
2588 printk(" basr 0x%X, sr 0x%X\n",
2589 NCR5380_read(BUS_AND_STATUS_REG), NCR5380_read(STATUS_REG));
2590 #endif
2591
2592 #if 0
2593
2594
2595
2596
2597
2598
2599 if (hostdata->connected == cmd) {
2600 #if (NDEBUG & NDEBUG_ABORT)
2601 printk("scsi%d : aborting connected command\n", instance->host_no);
2602 #endif
2603 hostdata->aborted = 1;
2604
2605
2606
2607
2608
2609 NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN);
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621 return 0;
2622 }
2623 #endif
2624
2625
2626
2627
2628
2629 for (prev = (Scsi_Cmnd **) &(hostdata->issue_queue),
2630 tmp = (Scsi_Cmnd *) hostdata->issue_queue;
2631 tmp; prev = (Scsi_Cmnd **) &(tmp->host_scribble), tmp =
2632 (Scsi_Cmnd *) tmp->host_scribble)
2633 if (cmd == tmp) {
2634 (*prev) = (Scsi_Cmnd *) tmp->host_scribble;
2635 tmp->host_scribble = NULL;
2636 tmp->result = DID_ABORT << 16;
2637 sti();
2638 #if (NDEBUG & NDEBUG_ABORT)
2639 printk("scsi%d : abort removed command from issue queue.\n",
2640 instance->host_no);
2641 #endif
2642 tmp->done(tmp);
2643 return SCSI_ABORT_SUCCESS;
2644 }
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657 if (hostdata->connected) {
2658 sti();
2659 #if (NDEBUG & NDEBUG_ABORT)
2660 printk("scsi%d : abort failed, command connected.\n", instance->host_no);
2661 #endif
2662 return SCSI_ABORT_NOT_RUNNING;
2663 }
2664
2665
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 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp;
2691 tmp = (Scsi_Cmnd *) tmp->host_scribble)
2692 if (cmd == tmp) {
2693 sti();
2694 #if (NDEBUG & NDEBUG_ABORT)
2695 printk("scsi%d : aborting disconnected command.\n", instance->host_no);
2696 #endif
2697
2698 if (NCR5380_select (instance, cmd, (int) cmd->tag))
2699 return SCSI_ABORT_BUSY;
2700
2701 #if (NDEBUG & NDEBUG_ABORT)
2702 printk("scsi%d : nexus reestablished.\n", instance->host_no);
2703 #endif
2704
2705 msg = ABORT;
2706 msgptr = &msg;
2707 len = 1;
2708 phase = PHASE_MSGOUT;
2709 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
2710 NCR5380_transfer_pio (instance, &phase, &len, &msgptr);
2711
2712 cli();
2713 for (prev = (Scsi_Cmnd **) &(hostdata->disconnected_queue),
2714 tmp = (Scsi_Cmnd *) hostdata->disconnected_queue;
2715 tmp; prev = (Scsi_Cmnd **) &(tmp->host_scribble), tmp =
2716 (Scsi_Cmnd *) tmp->host_scribble)
2717 if (cmd == tmp) {
2718 *prev = (Scsi_Cmnd *) tmp->host_scribble;
2719 tmp->host_scribble = NULL;
2720 tmp->result = DID_ABORT << 16;
2721 sti();
2722 tmp->done(tmp);
2723 return SCSI_ABORT_SUCCESS;
2724 }
2725 }
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737 sti();
2738 printk("scsi%d : warning : SCSI command probably completed successfully\n"
2739 " before abortion\n", instance->host_no);
2740 return SCSI_ABORT_NOT_RUNNING;
2741 }
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753 #ifndef NCR5380_reset
2754 static
2755 #endif
2756 int NCR5380_reset (Scsi_Cmnd *cmd) {
2757 NCR5380_local_declare();
2758 NCR5380_setup(cmd->host);
2759
2760 NCR5380_print_status (cmd->host);
2761
2762 cli();
2763 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST);
2764 udelay(25);
2765 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2766 sti();
2767
2768 return SCSI_RESET_WAKEUP;
2769 }
2770