This source file includes following definitions.
- internal_setup
- setup_wrapper
- normal_init
- ncr_pci_init
- NCR53c7xx_detect
- NCR53c8x0_init_fixup
- NCR53c8xx_run_tests
- NCR53c8xx_dsa_fixup
- abnormal_finished
- intr_break
- asynchronous
- synchronous
- NCR53c8x0_dstat_sir_intr
- debugger_fn_bc
- debugger_fn_bl
- debugger_fn_bs
- debugger_user_write
- debugger_user_read
- debugger_kernel_write
- NCR53c8x0_soft_reset
- create_cmd
- NCR53c7xx_queue_command
- fix_pointers
- intr_scsi
- NCR53c7x0_intr
- abort_connected
- intr_phase_mismatch
- intr_dma
- print_insn
- NCR53c7xx_abort
- NCR53c7xx_reset
- print_dsa
- shutdown
- ncr_halt
- NCR53c7x0_release
1
2
3
4
5
6
7
8
9 #define PERM_OPTIONS (OPTION_IO_MAPPED|OPTION_DEBUG_TEST1)
10
11
12
13
14
15
16 #define SCSI_MALLOC
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
70
71
72
73
74
75
76
77
78
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 #ifdef MODULE
159 #include <linux/module.h>
160 #endif
161
162 #include <asm/dma.h>
163 #include <asm/io.h>
164 #include <asm/system.h>
165 #include <linux/delay.h>
166 #include <linux/signal.h>
167 #include <linux/sched.h>
168 #include <linux/errno.h>
169 #include <linux/bios32.h>
170 #include <linux/pci.h>
171 #include <linux/string.h>
172 #include <linux/mm.h>
173 #include "../block/blk.h"
174 #include "scsi.h"
175 #include "hosts.h"
176 #include "53c7,8xx.h"
177 #include "constants.h"
178 #include "sd.h"
179
180 static void abnormal_finished (struct NCR53c7x0_cmd *cmd, int result);
181 static int NCR53c8xx_run_tests (struct Scsi_Host *host);
182 static int NCR53c8xx_script_len;
183 static int NCR53c8xx_dsa_len;
184 static void NCR53c7x0_intr(int irq, struct pt_regs * regs);
185 static int ncr_halt (struct Scsi_Host *host);
186 static void intr_phase_mismatch (struct Scsi_Host *host, struct NCR53c7x0_cmd
187 *cmd);
188 static void intr_dma (struct Scsi_Host *host, struct NCR53c7x0_cmd *cmd);
189 static void print_dsa (struct Scsi_Host *host, u32 *dsa);
190 static int print_insn (struct Scsi_Host *host, u32 *insn,
191 char *prefix, int kernel);
192
193 static void NCR53c8xx_dsa_fixup (struct NCR53c7x0_cmd *cmd);
194 static void NCR53c8x0_init_fixup (struct Scsi_Host *host);
195 static int NCR53c8x0_dstat_sir_intr (struct Scsi_Host *host, struct
196 NCR53c7x0_cmd *cmd);
197 static void NCR53c8x0_soft_reset (struct Scsi_Host *host);
198
199 static int perm_options = PERM_OPTIONS;
200
201 static struct Scsi_Host *first_host = NULL;
202 static Scsi_Host_Template *the_template = NULL;
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 struct pci_chip {
273 unsigned short pci_device_id;
274 int chip;
275 int min_revision;
276 int max_revision;
277 };
278
279 static struct pci_chip pci_chip_ids[] = {
280 {PCI_DEVICE_ID_NCR_53C810, 810, 1, 1},
281 {PCI_DEVICE_ID_NCR_53C815, 815, 2, 3},
282 {PCI_DEVICE_ID_NCR_53C820, 820, -1, -1},
283 {PCI_DEVICE_ID_NCR_53C825, 825, -1, -1}
284 };
285
286 #define NPCI_CHIP_IDS (sizeof (pci_chip_ids) / sizeof(pci_chip_ids[0]))
287
288
289
290
291 static struct override {
292 int chip;
293 int board;
294 unsigned pci:1;
295 union {
296 struct {
297 int base;
298 int io_port;
299 int irq;
300 int dma;
301 } normal;
302 struct {
303 int bus;
304 int device;
305 int function;
306 } pci;
307 } data;
308 int options;
309 } overrides [4] = {{0,},};
310 static int commandline_current = 0;
311 static int no_overrides = 0;
312
313 #if 0
314 #define OVERRIDE_LIMIT (sizeof(overrides) / sizeof(struct override))
315 #else
316 #define OVERRIDE_LIMIT commandline_current
317 #endif
318
319
320
321
322
323
324
325
326
327
328
329
330 static void internal_setup(int board, int chip, char *str, int *ints) {
331 unsigned char pci;
332
333
334 pci = (str && !strcmp (str, "pci")) ? 1 : 0;
335
336
337
338
339
340
341
342 if (commandline_current < OVERRIDE_LIMIT) {
343 overrides[commandline_current].pci = pci ? 1 : 0;
344 if (!pci) {
345 overrides[commandline_current].data.normal.base = ints[1];
346 overrides[commandline_current].data.normal.io_port = ints[2];
347 overrides[commandline_current].data.normal.irq = ints[3];
348 overrides[commandline_current].data.normal.dma = (ints[0] >= 4) ?
349 ints[4] : DMA_NONE;
350 overrides[commandline_current].options = (ints[0] >= 5) ?
351 ints[5] : 0;
352 } else {
353 overrides[commandline_current].data.pci.bus = ints[1];
354 overrides[commandline_current].data.pci.device = ints[2];
355 overrides[commandline_current].data.pci.function = ints[3];
356 overrides[commandline_current].options = (ints[0] >= 4) ?
357 ints[4] : 0;
358 }
359 overrides[commandline_current].board = board;
360 overrides[commandline_current].chip = chip;
361 ++commandline_current;
362 ++no_overrides;
363 } else {
364 printk ("53c7,7x0.c:internal_setup() : too many overrides\n");
365 }
366 }
367
368
369
370
371
372
373
374 #define setup_wrapper(x) \
375 void ncr53c##x##_setup (char *str, int *ints) { \
376 internal_setup (BOARD_GENERIC, x, str, ints); \
377 }
378
379 setup_wrapper(700)
380 setup_wrapper(70066)
381 setup_wrapper(710)
382 setup_wrapper(720)
383 setup_wrapper(810)
384 setup_wrapper(815)
385 setup_wrapper(820)
386 setup_wrapper(825)
387
388
389
390
391
392
393
394
395
396
397
398
399 static int
400 NCR53c7x0_init (struct Scsi_Host *host) {
401 NCR53c7x0_local_declare();
402
403 int i, j, ccf;
404 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
405 host->hostdata;
406 struct Scsi_Host *search;
407 NCR53c7x0_local_setup(host);
408
409 switch (hostdata->chip) {
410 case 810:
411 case 815:
412 case 820:
413 case 825:
414 hostdata->dstat_sir_intr = NCR53c8x0_dstat_sir_intr;
415 hostdata->init_save_regs = NULL;
416 hostdata->dsa_fixup = NCR53c8xx_dsa_fixup;
417 hostdata->init_fixup = NCR53c8x0_init_fixup;
418 hostdata->soft_reset = NCR53c8x0_soft_reset;
419 hostdata->run_tests = NCR53c8xx_run_tests;
420
421 hostdata->scsi_clock = 40000000;
422 break;
423 default:
424 printk ("scsi%d : chip type of %d is not supported yet, detaching.\n",
425 host->host_no, hostdata->chip);
426 scsi_unregister (host);
427 return -1;
428 }
429
430
431 hostdata->NCR53c7xx_zero = 0;
432 hostdata->NCR53c7xx_msg_reject = MESSAGE_REJECT;
433 hostdata->NCR53c7xx_msg_abort = ABORT;
434 hostdata->NCR53c7xx_msg_nop = NOP;
435
436
437
438
439
440
441 for (search = first_host; search && ((search->hostt != the_template) ||
442 (search->irq != host->irq)); search=search->next);
443
444 if (!search) {
445 if (request_irq(host->irq, NCR53c7x0_intr, SA_INTERRUPT, "53c7,8xx")) {
446 printk("scsi%d : IRQ%d not free, detaching\n",
447 host->host_no, host->irq);
448 scsi_unregister (host);
449 return -1;
450 }
451 } else {
452 printk("scsi%d : using interrupt handler previously installed for scsi%d\n",
453 host->host_no, search->host_no);
454 }
455
456 printk ("scsi%d : using %s mapped access\n", host->host_no,
457 (hostdata->options & OPTION_MEMORY_MAPPED) ? "memory" :
458 "io");
459
460 hostdata->dmode = (hostdata->chip == 700 || hostdata->chip == 70066) ?
461 DMODE_REG_00 : DMODE_REG_10;
462 hostdata->istat = ((hostdata->chip / 100) == 8) ?
463 ISTAT_REG_800 : ISTAT_REG_700;
464
465
466
467 ncr_halt(host);
468
469
470
471
472
473
474
475
476
477 #if 0
478 tmp = hostdata->this_id_mask = NCR53c7x0_read8(SCID_REG);
479 for (host->this_id = 0; tmp != 1; tmp >>=1, ++host->this_id);
480 #else
481 host->this_id = NCR53c7x0_read8(SCID_REG) & 7;
482 hostdata->this_id_mask = 1 << host->this_id;
483 #endif
484
485 printk("scsi%d : using initiator ID %d\n", host->host_no,
486 host->this_id);
487
488
489
490
491
492 if ((hostdata->chip / 100) == 8) {
493
494
495
496 hostdata->saved_ctest4 = NCR53c7x0_read8(CTEST4_REG_800) &
497 CTEST4_800_SAVE;
498 } else {
499
500
501
502
503 hostdata->saved_ctest7 = NCR53c7x0_read8(CTEST7_REG) & CTEST7_SAVE;
504 }
505
506
507
508
509
510 hostdata->saved_dcntl = NCR53c7x0_read8(DCNTL_REG);
511
512 if ((hostdata->chip / 100) == 8)
513 printk ("scsi%d : using %s interrupts\n", host->host_no,
514 (hostdata->saved_dcntl & DCNTL_800_IRQM) ? "edge triggered" :
515 "level active");
516
517
518
519
520
521 hostdata->saved_dmode = NCR53c7x0_read8(hostdata->dmode);
522
523
524
525
526
527
528 if ((hostdata->chip / 100) == 8) {
529 if (hostdata->saved_ctest4 & CTEST4_800_BDIS) {
530 printk ("scsi%d : burst mode disabled\n", host->host_no);
531 } else {
532 switch (hostdata->saved_dmode & DMODE_BL_MASK) {
533 case DMODE_BL_2: i = 2; break;
534 case DMODE_BL_4: i = 4; break;
535 case DMODE_BL_8: i = 8; break;
536 case DMODE_BL_16: i = 16; break;
537 default: i = 0;
538 }
539 printk ("scsi%d : burst length %d\n", host->host_no, i);
540 }
541 }
542
543
544
545
546
547 if (hostdata->chip / 100 == 8) {
548 hostdata->saved_scntl3 = NCR53c7x0_read8(SCNTL3_REG_800);
549 ccf = hostdata->saved_scntl3 & SCNTL3_800_CCF_MASK;
550 } else
551 ccf = 0;
552
553
554
555
556
557
558
559
560 if (!hostdata->scsi_clock)
561 switch(ccf) {
562 case 1: hostdata->scsi_clock = 25000000; break;
563 case 2: hostdata->scsi_clock = 37500000; break;
564 case 3: hostdata->scsi_clock = 50000000; break;
565 case 0:
566 case 4: hostdata->scsi_clock = 66000000; break;
567 default:
568 printk ("scsi%d : clock conversion factor %d unknown.\n"
569 " synchronous transfers disabled\n",
570 host->host_no, ccf);
571 hostdata->options &= ~OPTION_SYNCHRONOUS;
572 hostdata->scsi_clock = 0;
573 }
574
575 printk ("scsi%d : using %dMHz SCSI clock\n", host->host_no,
576 hostdata->scsi_clock / 1000000);
577
578
579
580
581
582 for (i = 0; i < 8; ++i) {
583 hostdata->cmd_allocated[i] = 0;
584 for (j = 0; j < 8; ++j)
585 hostdata->busy[i][j] = 0;
586
587
588
589
590
591 if (hostdata->chip != 700 && hostdata->chip != 70066) {
592 hostdata->sync[i].select_indirect |= (i << 16);
593
594 hostdata->sync[i].script[0] = (DCMD_TYPE_TCI|DCMD_TCI_OP_RETURN) << 24 |
595 DBC_TCI_TRUE;
596 switch (hostdata->chip) {
597
598 case 825:
599 case 820:
600
601 case 815:
602 case 810:
603 hostdata->sync[i].select_indirect |= (hostdata->saved_scntl3) << 24;
604 break;
605 default:
606 }
607 }
608 }
609
610 hostdata->issue_queue = hostdata->running_list =
611 hostdata->finished_queue = NULL;
612 hostdata->issue_dsa_head = 0;
613 hostdata->issue_dsa_tail = NULL;
614
615 if (hostdata->init_save_regs)
616 hostdata->init_save_regs (host);
617 if (hostdata->init_fixup)
618 hostdata->init_fixup (host);
619
620 if (!the_template) {
621 the_template = host->hostt;
622 first_host = host;
623 }
624
625 hostdata->idle = 1;
626
627
628
629
630
631
632
633
634
635
636
637 hostdata->soft_reset (host);
638
639 hostdata->debug_count_limit = -1;
640 hostdata->intrs = -1;
641 hostdata->expecting_iid = 0;
642 hostdata->expecting_sto = 0;
643
644 if ((hostdata->run_tests && hostdata->run_tests(host) == -1) ||
645 (hostdata->options & OPTION_DEBUG_TESTS_ONLY)) {
646
647 scsi_unregister (host);
648 return -1;
649 } else
650 return 0;
651 }
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674 static int normal_init (Scsi_Host_Template *tpnt, int board, int chip,
675 u32 base, int io_port, int irq, int dma, int pci_valid,
676 unsigned char pci_bus, unsigned char pci_device_fn, int options) {
677 struct Scsi_Host *instance;
678 struct NCR53c7x0_hostdata *hostdata;
679 char chip_str[80];
680 int script_len = 0, dsa_len = 0, size = 0, max_cmd_size = 0;
681 int ok = 0;
682
683
684 options |= perm_options;
685
686 switch (chip) {
687 case 825:
688 case 820:
689 case 815:
690 case 810:
691 script_len = NCR53c8xx_script_len;
692 dsa_len = NCR53c8xx_dsa_len;
693 options |= OPTION_INTFLY;
694 sprintf (chip_str, "NCR53c%d", chip);
695 break;
696 default:
697 printk("scsi-ncr53c7,8xx : unsupported SCSI chip %d\n", chip);
698 return -1;
699 }
700
701 printk("scsi-ncr53c7,8xx : %s at memory 0x%x, io 0x%x, irq %d",
702 chip_str, base, io_port, irq);
703 if (dma == DMA_NONE)
704 printk("\n");
705 else
706 printk(", dma %d\n", dma);
707
708 if ((chip / 100 == 8) && !pci_valid)
709 printk ("scsi-ncr53c7,8xx : for better reliability and performance, please use the\n"
710 " PCI override instead.\n"
711 " Syntax : ncr53c8{10,15,20,25}=pci,<bus>,<device>,<function>\n"
712 " <bus> and <device> are usually 0.\n");
713
714 if (options & OPTION_DEBUG_PROBE_ONLY) {
715 printk ("scsi-ncr53c7,8xx : probe only enabled, aborting initialization\n");
716 return -1;
717 }
718
719 max_cmd_size = sizeof(struct NCR53c7x0_cmd) + dsa_len +
720
721 2 *
722 ( 2 *
723 tpnt->sg_tablesize +
724 3
725 ) *
726 8 ;
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752 size = sizeof(struct NCR53c7x0_hostdata) + script_len + max_cmd_size;
753
754 instance = scsi_register (tpnt, size);
755 if (!instance)
756 return -1;
757
758
759
760
761
762
763 hostdata = (struct NCR53c7x0_hostdata *)
764 instance->hostdata;
765 hostdata->size = size;
766 hostdata->script_count = script_len / sizeof(u32);
767 hostdata = (struct NCR53c7x0_hostdata *) instance->hostdata;
768 hostdata->board = board;
769 hostdata->chip = chip;
770 if ((hostdata->pci_valid = pci_valid)) {
771 hostdata->pci_bus = pci_bus;
772 hostdata->pci_device_fn = pci_device_fn;
773 }
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789 if (base) {
790 instance->base = (unsigned char*) (unsigned long) base;
791
792 if (!(options & OPTION_IO_MAPPED)) {
793 options |= OPTION_MEMORY_MAPPED;
794 ok = 1;
795 }
796 } else {
797 options &= ~OPTION_MEMORY_MAPPED;
798 }
799
800 if (io_port) {
801 instance->io_port = io_port;
802 options |= OPTION_IO_MAPPED;
803 ok = 1;
804 } else {
805 options &= ~OPTION_IO_MAPPED;
806 }
807
808 if (!ok) {
809 printk ("scsi%d : not initializing, no I/O or memory mapping known \n",
810 instance->host_no);
811 scsi_unregister (instance);
812 return -1;
813 }
814 instance->irq = irq;
815 instance->dma_channel = dma;
816
817 hostdata->options = options;
818 hostdata->dsa_size = dsa_len;
819 hostdata->max_cmd_size = max_cmd_size;
820 hostdata->num_cmds = 1;
821
822 hostdata->free = (struct NCR53c7x0_cmd *)
823 (hostdata->script + hostdata->script_count);
824 hostdata->free->real = (void *) hostdata->free;
825 hostdata->free->size = max_cmd_size;
826 hostdata->free->free = NULL;
827 hostdata->free->next = NULL;
828
829
830 return NCR53c7x0_init(instance);
831 }
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855 static int ncr_pci_init (Scsi_Host_Template *tpnt, int board, int chip,
856 unsigned char bus, unsigned char device_fn, int options) {
857 unsigned short vendor_id, device_id, command;
858 u32 base;
859 int io_port;
860 unsigned char irq, revision;
861 int error, expected_chip;
862 int expected_id = -1, max_revision = -1, min_revision = -1;
863 int i;
864
865 printk("scsi-ncr53c7,8xx : at PCI bus %d, device %d, function %d\n",
866 bus, (int) (device_fn & 0xf8) >> 3,
867 (int) device_fn & 7);
868
869 if (!pcibios_present) {
870 printk("scsi-ncr53c7,8xx : not initializing due to lack of PCI BIOS,\n"
871 " try using memory, port, irq override instead.\n");
872 return -1;
873 }
874
875 if ((error = pcibios_read_config_word (bus, device_fn, PCI_VENDOR_ID,
876 &vendor_id)) ||
877 (error = pcibios_read_config_word (bus, device_fn, PCI_DEVICE_ID,
878 &device_id)) ||
879 (error = pcibios_read_config_word (bus, device_fn, PCI_COMMAND,
880 &command)) ||
881 (error = pcibios_read_config_dword (bus, device_fn,
882 PCI_BASE_ADDRESS_0, &io_port)) ||
883 (error = pcibios_read_config_dword (bus, device_fn,
884 PCI_BASE_ADDRESS_1, &base)) ||
885 (error = pcibios_read_config_byte (bus, device_fn, PCI_CLASS_REVISION,
886 &revision)) ||
887 (error = pcibios_read_config_byte (bus, device_fn, PCI_INTERRUPT_LINE,
888 &irq))) {
889 printk ("scsi-ncr53c7,8xx : error %s not initializing due to error reading configuration space\n"
890 " perhaps you specified an incorrect PCI bus, device, or function.\n"
891 , pci_strbioserr(error));
892 return -1;
893 }
894
895
896
897 if (vendor_id != PCI_VENDOR_ID_NCR) {
898 printk ("scsi-ncr53c7,8xx : not initializing, 0x%04x is not NCR vendor ID\n",
899 (int) vendor_id);
900 return -1;
901 }
902
903
904
905
906
907
908
909
910 if (command & PCI_COMMAND_IO) {
911 if ((io_port & 3) != 1) {
912 printk ("scsi-ncr53c7,8xx : disabling I/O mapping since base address 0 (0x%x)\n"
913 " bits 0..1 indicate a non-IO mapping\n", io_port);
914 io_port = 0;
915 } else
916 io_port &= PCI_BASE_ADDRESS_IO_MASK;
917 } else {
918 io_port = 0;
919 }
920
921 if (command & PCI_COMMAND_MEMORY) {
922 if ((base & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_MEMORY) {
923 printk("scsi-ncr53c7,8xx : disabling memory mapping since base address 1\n"
924 " contains a non-memory mapping\n");
925 base = 0;
926 } else
927 base &= PCI_BASE_ADDRESS_MEM_MASK;
928 } else {
929 base = 0;
930 }
931
932 if (!io_port && !base) {
933 printk ("scsi-ncr53c7,8xx : not initializing, both I/O and memory mappings disabled\n");
934 return -1;
935 }
936
937 if (!(command & PCI_COMMAND_MASTER)) {
938 printk ("scsi-ncr53c7,8xx : not initializing, BUS MASTERING was disabled\n");
939 return -1;
940 }
941
942 for (i = 0; i < NPCI_CHIP_IDS; ++i) {
943 if (device_id == pci_chip_ids[i].pci_device_id) {
944 max_revision = pci_chip_ids[i].max_revision;
945 min_revision = pci_chip_ids[i].min_revision;
946 expected_chip = pci_chip_ids[i].chip;
947 }
948 if (chip == pci_chip_ids[i].chip)
949 expected_id = pci_chip_ids[i].pci_device_id;
950 }
951
952 if (chip && device_id != expected_id)
953 printk ("scsi-ncr53c7,8xx : warning : device id of 0x%04x doesn't\n"
954 " match expected 0x%04x\n",
955 (unsigned int) device_id, (unsigned int) expected_id );
956
957 if (max_revision != -1 && revision > max_revision)
958 printk ("scsi-ncr53c7,8xx : warning : revision of %d is greater than %d.\n",
959 (int) revision, max_revision);
960 else if (min_revision != -1 && revision < min_revision)
961 printk ("scsi-ncr53c7,8xx : warning : revision of %d is less than %d.\n",
962 (int) revision, min_revision);
963
964 return normal_init (tpnt, board, chip, (int) base, io_port,
965 (int) irq, DMA_NONE, 1, bus, device_fn, options);
966 }
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982 int NCR53c7xx_detect(Scsi_Host_Template *tpnt) {
983 int i;
984 int current_override;
985 int count;
986 unsigned char pci_bus, pci_device_fn;
987 static short pci_index=0;
988
989
990 for (current_override = count = 0; current_override < OVERRIDE_LIMIT;
991 ++current_override) {
992 if (overrides[current_override].pci ?
993 !ncr_pci_init (tpnt, overrides[current_override].board,
994 overrides[current_override].chip,
995 (unsigned char) overrides[current_override].data.pci.bus,
996 (((overrides[current_override].data.pci.device
997 << 3) & 0xf8)|(overrides[current_override].data.pci.function &
998 7)), overrides[current_override].options):
999 !normal_init (tpnt, overrides[current_override].board,
1000 overrides[current_override].chip,
1001 overrides[current_override].data.normal.base,
1002 overrides[current_override].data.normal.io_port,
1003 overrides[current_override].data.normal.irq,
1004 overrides[current_override].data.normal.dma,
1005 0 , 0 ,
1006 0 ,
1007 overrides[current_override].options)) {
1008 ++count;
1009 }
1010 }
1011
1012 if (pcibios_present()) {
1013 for (i = 0; i < NPCI_CHIP_IDS; ++i)
1014 for (pci_index = 0;
1015 !pcibios_find_device (PCI_VENDOR_ID_NCR,
1016 pci_chip_ids[i].pci_device_id, pci_index, &pci_bus,
1017 &pci_device_fn) &&
1018 !ncr_pci_init (tpnt, BOARD_GENERIC, pci_chip_ids[i].chip,
1019 pci_bus, pci_device_fn, 0);
1020 ++count, ++pci_index);
1021 }
1022 return count;
1023 }
1024
1025
1026
1027 #include "53c8xx_d.h"
1028 static int NCR53c8xx_script_len = sizeof (SCRIPT);
1029 static int NCR53c8xx_dsa_len = A_dsa_end + Ent_dsa_zero - Ent_dsa_code_template;
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040 static void
1041 NCR53c8x0_init_fixup (struct Scsi_Host *host) {
1042 NCR53c7x0_local_declare();
1043 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
1044 host->hostdata;
1045 unsigned char tmp;
1046 int i, ncr_to_memory, memory_to_ncr, ncr_to_ncr;
1047 u32 base;
1048 NCR53c7x0_local_setup(host);
1049
1050
1051
1052
1053
1054 memcpy ((void *) hostdata->script, (void *) SCRIPT,
1055 sizeof(SCRIPT));
1056
1057 for (i = 0; i < PATCHES; ++i)
1058 hostdata->script[LABELPATCHES[i]] +=
1059 virt_to_bus(hostdata->script);
1060
1061
1062 patch_abs_32 (hostdata->script, 0, NCR53c7xx_msg_abort,
1063 virt_to_bus(&hostdata->NCR53c7xx_msg_abort));
1064 patch_abs_32 (hostdata->script, 0, NCR53c7xx_msg_reject,
1065 virt_to_bus(&hostdata->NCR53c7xx_msg_reject));
1066 patch_abs_32 (hostdata->script, 0, NCR53c7xx_zero,
1067 virt_to_bus(&hostdata->NCR53c7xx_zero));
1068 patch_abs_32 (hostdata->script, 0, NCR53c7xx_sink,
1069 virt_to_bus(&hostdata->NCR53c7xx_sink));
1070
1071
1072 for (i = 0; i < EXTERNAL_PATCHES_LEN; ++i)
1073 hostdata->script[EXTERNAL_PATCHES[i].offset] +=
1074 virt_to_bus(EXTERNAL_PATCHES[i].address);
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091 tmp = NCR53c7x0_read8(DMODE_REG_10);
1092 tmp &= (DMODE_800_ERL | DMODE_BL_MASK);
1093
1094 if (!(hostdata->options & OPTION_MEMORY_MAPPED)) {
1095 base = (u32) host->io_port;
1096 memory_to_ncr = tmp|DMODE_800_DIOM;
1097 ncr_to_memory = tmp|DMODE_800_SIOM;
1098 ncr_to_ncr = tmp|DMODE_800_DIOM|DMODE_800_SIOM;
1099 } else {
1100 base = virt_to_phys(host->base);
1101 ncr_to_ncr = memory_to_ncr = ncr_to_memory = tmp;
1102 }
1103
1104 patch_abs_32 (hostdata->script, 0, addr_scratch, base + SCRATCHA_REG_800);
1105 patch_abs_32 (hostdata->script, 0, addr_sfbr, base + SFBR_REG);
1106 patch_abs_32 (hostdata->script, 0, addr_temp, base + TEMP_REG);
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117 patch_abs_rwri_data (hostdata->script, 0, dmode_memory_to_memory, tmp);
1118 patch_abs_rwri_data (hostdata->script, 0, dmode_memory_to_ncr, memory_to_ncr);
1119 patch_abs_rwri_data (hostdata->script, 0, dmode_ncr_to_memory, ncr_to_memory);
1120 patch_abs_rwri_data (hostdata->script, 0, dmode_ncr_to_ncr, ncr_to_ncr);
1121
1122 patch_abs_32 (hostdata->script, 0, issue_dsa_head,
1123 virt_to_bus((void*)&hostdata->issue_dsa_head));
1124 patch_abs_32 (hostdata->script, 0, msg_buf,
1125 virt_to_bus((void*)&hostdata->msg_buf));
1126 patch_abs_32 (hostdata->script, 0, reconnect_dsa_head,
1127 virt_to_bus((void*)&hostdata->reconnect_dsa_head));
1128 patch_abs_32 (hostdata->script, 0, reselected_identify,
1129 virt_to_bus((void*)&hostdata->reselected_identify));
1130 patch_abs_32 (hostdata->script, 0, reselected_tag,
1131 virt_to_bus((void*)&hostdata->reselected_tag));
1132
1133 patch_abs_32 (hostdata->script, 0, test_dest,
1134 virt_to_bus((void*)&hostdata->test_dest));
1135 patch_abs_32 (hostdata->script, 0, test_src, virt_to_bus(&hostdata->test_source));
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147 hostdata->E_accept_message = Ent_accept_message;
1148 hostdata->E_command_complete = Ent_command_complete;
1149 hostdata->E_debug_break = Ent_debug_break;
1150 hostdata->E_dsa_code_template = Ent_dsa_code_template;
1151 hostdata->E_dsa_code_template_end = Ent_dsa_code_template_end;
1152 hostdata->E_initiator_abort = Ent_initiator_abort;
1153 hostdata->E_msg_in = Ent_msg_in;
1154 hostdata->E_other_transfer = Ent_other_transfer;
1155 hostdata->E_reject_message = Ent_reject_message;
1156 hostdata->E_respond_message = Ent_respond_message;
1157 hostdata->E_schedule = Ent_schedule;
1158 hostdata->E_select = Ent_select;
1159 hostdata->E_select_msgout = Ent_select_msgout;
1160 hostdata->E_target_abort = Ent_target_abort;
1161 #ifdef Ent_test_0
1162 hostdata->E_test_0 = Ent_test_0;
1163 #endif
1164 hostdata->E_test_1 = Ent_test_1;
1165 hostdata->E_test_2 = Ent_test_2;
1166 #ifdef Ent_test_3
1167 hostdata->E_test_3 = Ent_test_3;
1168 #endif
1169
1170 hostdata->dsa_cmdout = A_dsa_cmdout;
1171 hostdata->dsa_cmnd = A_dsa_cmnd;
1172 hostdata->dsa_datain = A_dsa_datain;
1173 hostdata->dsa_dataout = A_dsa_dataout;
1174 hostdata->dsa_end = A_dsa_end;
1175 hostdata->dsa_msgin = A_dsa_msgin;
1176 hostdata->dsa_msgout = A_dsa_msgout;
1177 hostdata->dsa_msgout_other = A_dsa_msgout_other;
1178 hostdata->dsa_next = A_dsa_next;
1179 hostdata->dsa_select = A_dsa_select;
1180 hostdata->dsa_start = Ent_dsa_code_template - Ent_dsa_zero;
1181 hostdata->dsa_status = A_dsa_status;
1182
1183
1184 if (A_dsa_fields_start != Ent_dsa_code_template_end -
1185 Ent_dsa_zero)
1186 printk("scsi%d : NCR dsa_fields start is %d not %d\n",
1187 host->host_no, A_dsa_fields_start, Ent_dsa_code_template_end -
1188 Ent_dsa_zero);
1189
1190 printk("scsi%d : NCR code relocated to 0x%p\n", host->host_no,
1191 hostdata->script);
1192 }
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209 static int NCR53c8xx_run_tests (struct Scsi_Host *host) {
1210 NCR53c7x0_local_declare();
1211 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
1212 host->hostdata;
1213 unsigned long timeout;
1214 u32 start;
1215 int failed, i;
1216 unsigned long flags;
1217 NCR53c7x0_local_setup(host);
1218
1219
1220
1221 save_flags(flags);
1222 cli();
1223 if (!hostdata->idle) {
1224 printk ("scsi%d : chip not idle, aborting tests\n", host->host_no);
1225 restore_flags(flags);
1226 return -1;
1227 }
1228
1229
1230
1231
1232
1233
1234 if (hostdata->issue_dsa_head) {
1235 printk ("scsi%d : hostdata->issue_dsa_head corrupt before test 1\n",
1236 host->host_no);
1237 hostdata->issue_dsa_head = 0;
1238 }
1239
1240 if (hostdata->options & OPTION_DEBUG_TEST1) {
1241 hostdata->idle = 0;
1242 hostdata->test_running = 1;
1243 hostdata->test_completed = -1;
1244 hostdata->test_dest = 0;
1245 hostdata->test_source = 0xdeadbeef;
1246 start = virt_to_bus(hostdata->script) + hostdata->E_test_1;
1247 hostdata->state = STATE_RUNNING;
1248 printk ("scsi%d : test 1", host->host_no);
1249 NCR53c7x0_write32 (DSP_REG, start);
1250 mb();
1251 printk (" started\n");
1252 sti();
1253
1254 timeout = jiffies + 5 * HZ / 10;
1255 while ((hostdata->test_completed == -1) && jiffies < timeout)
1256 barrier();
1257
1258 failed = 1;
1259 if (hostdata->test_completed == -1)
1260 printk ("scsi%d : driver test 1 timed out%s\n",host->host_no ,
1261 (hostdata->test_dest == 0xdeadbeef) ?
1262 " due to lost interrupt.\n"
1263 " Please verify that the correct IRQ is being used for your board,\n"
1264 " and that the motherboard IRQ jumpering matches the PCI setup on\n"
1265 " PCI systems.\n"
1266 " If you are using a NCR53c810 board in a PCI system, you should\n"
1267 " also verify that the board is jumpered to use PCI INTA, since\n"
1268 " most PCI motherboards lack support for INTB, INTC, and INTD.\n"
1269 : "");
1270 else if (hostdata->test_completed != 1)
1271 printk ("scsi%d : test 1 bad interrupt value (%d)\n", host->host_no,
1272 hostdata->test_completed);
1273 else
1274 failed = (hostdata->test_dest != 0xdeadbeef);
1275
1276 if (hostdata->test_dest != 0xdeadbeef) {
1277 printk ("scsi%d : driver test 1 read 0x%x instead of 0xdeadbeef indicating a\n"
1278 " probable cache invalidation problem. Please configure caching\n"
1279 " as write-through or disabled\n",
1280 host->host_no, hostdata->test_dest);
1281 }
1282
1283 if (failed) {
1284 printk ("scsi%d : DSP = 0x%x (script at 0x%p, start at 0x%x)\n",
1285 host->host_no, NCR53c7x0_read32(DSP_REG),
1286 hostdata->script, start);
1287 printk ("scsi%d : DSPS = 0x%x\n", host->host_no,
1288 NCR53c7x0_read32(DSPS_REG));
1289 restore_flags(flags);
1290 return -1;
1291 }
1292 hostdata->test_running = 0;
1293 }
1294
1295 if (hostdata->issue_dsa_head) {
1296 printk ("scsi%d : hostdata->issue_dsa_head corrupt after test 1\n",
1297 host->host_no);
1298 hostdata->issue_dsa_head = 0;
1299 }
1300
1301 if (hostdata->options & OPTION_DEBUG_TEST2) {
1302 u32 dsa[48];
1303 unsigned char identify = IDENTIFY(0, 0);
1304 unsigned char cmd[6];
1305 unsigned char data[36];
1306 unsigned char status = 0xff;
1307 unsigned char msg = 0xff;
1308
1309 cmd[0] = INQUIRY;
1310 cmd[1] = cmd[2] = cmd[3] = cmd[5] = 0;
1311 cmd[4] = sizeof(data);
1312
1313 dsa[2] = 1;
1314 dsa[3] = virt_to_bus(&identify);
1315 dsa[4] = 6;
1316 dsa[5] = virt_to_bus(&cmd);
1317 dsa[6] = sizeof(data);
1318 dsa[7] = virt_to_bus(&data);
1319 dsa[8] = 1;
1320 dsa[9] = virt_to_bus(&status);
1321 dsa[10] = 1;
1322 dsa[11] = virt_to_bus(&msg);
1323
1324 for (i = 0; i < 3; ++i) {
1325 cli();
1326 if (!hostdata->idle) {
1327 printk ("scsi%d : chip not idle, aborting tests\n", host->host_no);
1328 restore_flags(flags);
1329 return -1;
1330 }
1331
1332
1333 dsa[0] = (0x33 << 24) | (i << 16) ;
1334 hostdata->idle = 0;
1335 hostdata->test_running = 2;
1336 hostdata->test_completed = -1;
1337 start = virt_to_bus(hostdata->script) + hostdata->E_test_2;
1338 hostdata->state = STATE_RUNNING;
1339 NCR53c7x0_write32 (DSA_REG, virt_to_bus(dsa));
1340 NCR53c7x0_write32 (DSP_REG, start);
1341 mb();
1342 sti();
1343
1344 timeout = jiffies + 5 * HZ;
1345 while ((hostdata->test_completed == -1) && jiffies < timeout)
1346 barrier();
1347 NCR53c7x0_write32 (DSA_REG, 0);
1348 mb();
1349
1350 if (hostdata->test_completed == 2) {
1351 data[35] = 0;
1352 printk ("scsi%d : test 2 INQUIRY to target %d, lun 0 : %s\n",
1353 host->host_no, i, data + 8);
1354 printk ("scsi%d : status ", host->host_no);
1355 print_status (status);
1356 printk ("\nscsi%d : message ", host->host_no);
1357 print_msg (&msg);
1358 printk ("\n");
1359 } else if (hostdata->test_completed == 3) {
1360 printk("scsi%d : test 2 no connection with target %d\n",
1361 host->host_no, i);
1362 if (!hostdata->idle) {
1363 printk("scsi%d : not idle\n", host->host_no);
1364 restore_flags(flags);
1365 return -1;
1366 }
1367 } else if (hostdata->test_completed == -1) {
1368 printk ("scsi%d : test 2 timed out\n", host->host_no);
1369 restore_flags(flags);
1370 return -1;
1371 }
1372 hostdata->test_running = 0;
1373 if (hostdata->issue_dsa_head) {
1374 printk ("scsi%d : hostdata->issue_dsa_head corrupt after test 2 id %d\n",
1375 host->host_no, i);
1376 hostdata->issue_dsa_head = 0;
1377 }
1378 }
1379 }
1380
1381 restore_flags(flags);
1382 return 0;
1383 }
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395 static void NCR53c8xx_dsa_fixup (struct NCR53c7x0_cmd *cmd) {
1396 Scsi_Cmnd *c = cmd->cmd;
1397 struct Scsi_Host *host = c->host;
1398 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
1399 host->hostdata;
1400 int i;
1401
1402 memcpy (cmd->dsa, hostdata->script + (hostdata->E_dsa_code_template / 4),
1403 hostdata->E_dsa_code_template_end - hostdata->E_dsa_code_template);
1404
1405 patch_abs_32 (cmd->dsa, Ent_dsa_code_template / sizeof(u32),
1406 dsa_temp_jump_resume, virt_to_bus(cmd->dsa) +
1407 Ent_dsa_jump_resume - Ent_dsa_zero);
1408 patch_abs_rwri_data (cmd->dsa, Ent_dsa_code_template / sizeof(u32),
1409 dsa_temp_lun, c->lun);
1410 patch_abs_32 (cmd->dsa, Ent_dsa_code_template / sizeof(u32),
1411 dsa_temp_dsa_next, virt_to_bus(cmd->dsa) + A_dsa_next);
1412 patch_abs_32 (cmd->dsa, Ent_dsa_code_template / sizeof(u32),
1413 dsa_temp_sync, hostdata->sync[c->target].select_indirect);
1414 patch_abs_rwri_data (cmd->dsa, Ent_dsa_code_template / sizeof(u32),
1415 dsa_temp_target, c->target);
1416 }
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433 static void abnormal_finished (struct NCR53c7x0_cmd *cmd, int result) {
1434 Scsi_Cmnd *c = cmd->cmd;
1435 struct Scsi_Host *host = c->host;
1436 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
1437 host->hostdata;
1438 unsigned long flags;
1439 volatile u32 *prev, search;
1440 int i;
1441
1442 save_flags(flags);
1443 cli();
1444 for (i = 0; i < 2; ++i) {
1445 for (search = (i ? hostdata->issue_dsa_head :
1446 hostdata->reconnect_dsa_head), prev = (i ?
1447 &hostdata->issue_dsa_head : &hostdata->reconnect_dsa_head);
1448 search && ((char*)bus_to_virt(search) + hostdata->dsa_start) != (char *) cmd->dsa;
1449 prev = (u32*) ((char*)bus_to_virt(search) + hostdata->dsa_next),
1450 search = *prev);
1451
1452 if (search)
1453 *prev = *(u32*) ((char*)bus_to_virt(search) + hostdata->dsa_next);
1454 }
1455
1456 if (cmd->prev)
1457 cmd->prev->next = cmd->next;
1458
1459 if (cmd->next)
1460 cmd->next->prev = cmd->prev;
1461
1462 if (hostdata->running_list == cmd)
1463 hostdata->running_list = cmd->next;
1464
1465 cmd->next = hostdata->free;
1466 hostdata->free = cmd;
1467
1468 c->host_scribble = NULL;
1469 c->result = result;
1470 c->scsi_done(c);
1471
1472 restore_flags(flags);
1473 }
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487 static void intr_break (struct Scsi_Host *host, struct
1488 NCR53c7x0_cmd *cmd) {
1489 NCR53c7x0_local_declare();
1490 struct NCR53c7x0_break *bp;
1491 #if 0
1492 Scsi_Cmnd *c = cmd ? cmd->cmd : NULL;
1493 #endif
1494 u32 *dsp;
1495 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
1496 host->hostdata;
1497 unsigned long flags;
1498 NCR53c7x0_local_setup(host);
1499
1500
1501
1502
1503
1504
1505
1506 save_flags(flags);
1507 cli();
1508 dsp = (u32 *) bus_to_virt(NCR53c7x0_read32(DSP_REG));
1509 for (bp = hostdata->breakpoints; bp && bp->address != dsp;
1510 bp = bp->next);
1511 if (!bp)
1512 panic("scsi%d : break point interrupt from %p with no breakpoint!",
1513 host->host_no, dsp);
1514
1515
1516
1517
1518
1519
1520
1521 NCR53c7x0_write8 (hostdata->dmode,
1522 NCR53c7x0_read8(hostdata->dmode)|DMODE_MAN);
1523 mb();
1524
1525
1526
1527
1528
1529
1530 restore_flags(flags);
1531 }
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544 static int asynchronous (struct Scsi_Host *host, int target) {
1545 NCR53c7x0_local_declare();
1546 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
1547 host->hostdata;
1548 NCR53c7x0_local_setup(host);
1549
1550 if ((hostdata->chip / 100) == 8) {
1551 hostdata->sync[target].select_indirect = (hostdata->saved_scntl3 << 24)
1552 | (target << 16);
1553
1554 } else if ((hostdata->chip != 700) && (hostdata->chip != 70066)) {
1555 hostdata->sync[target].select_indirect = (1 << (target & 7)) << 16;
1556 }
1557
1558
1559
1560
1561
1562
1563 if (hostdata->state == STATE_HALTED) {
1564 if ((hostdata->chip / 100) == 8) {
1565 NCR53c7x0_write8 (SCNTL3_REG_800, hostdata->saved_scntl3);
1566 }
1567
1568 NCR53c7x0_write8 (SXFER_REG, 0);
1569 mb();
1570 }
1571 return 0;
1572 }
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582 static const struct {
1583 int div;
1584 unsigned char scf;
1585 unsigned char tp;
1586 } syncs[] = {
1587
1588 { 40, 1, 0}, { 50, 1, 1}, { 60, 1, 2},
1589 { 70, 1, 3}, { 75, 2, 1}, { 80, 1, 4},
1590 { 90, 1, 5}, { 100, 1, 6}, { 105, 2, 3},
1591 { 110, 1, 7}, { 120, 2, 4}, { 135, 2, 5},
1592 { 140, 3, 3}, { 150, 2, 6}, { 160, 3, 4},
1593 { 165, 2, 7}, { 180, 3, 5}, { 200, 3, 6},
1594 { 210, 4, 3}, { 220, 3, 7}, { 240, 4, 4},
1595 { 270, 4, 5}, { 300, 4, 6}, { 330, 4, 7}
1596 };
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613 static void synchronous (struct Scsi_Host *host, int target, char *msg) {
1614 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
1615 host->hostdata;
1616 int desire, divisor, i, limit;
1617 u32 *script;
1618 unsigned char scntl3, sxfer;
1619
1620
1621 desire = 1000000000L / (msg[3] * 4);
1622 divisor = desire / (hostdata->scsi_clock / 10);
1623
1624 if (msg[4] > 8)
1625 msg[4] = 8;
1626
1627 printk("scsi%d : optimal synchronous divisor of %d.%01d\n", host->host_no,
1628 divisor / 10, divisor % 10);
1629
1630 limit = (sizeof(syncs) / sizeof(syncs[0])) - 1;
1631 for (i = 0; (i < limit) && (divisor < syncs[i + 1].div); ++i);
1632
1633 printk("scsi%d : selected synchronous divisor of %d.%01d\n", host->host_no,
1634 syncs[i].div / 10, syncs[i].div % 10);
1635
1636 msg[3] = (1000000000 / divisor / 10 / 4);
1637
1638 scntl3 = (hostdata->chip / 100 == 8) ? ((hostdata->saved_scntl3 &
1639 ~SCNTL3_800_SCF_MASK) | (syncs[i].scf << SCNTL3_800_SCF_SHIFT)) : 0;
1640 sxfer = (msg[4] << SXFER_MO_SHIFT) | ((syncs[i].tp) << SXFER_TP_SHIFT);
1641
1642 if ((hostdata->chip != 700) && (hostdata->chip != 70066)) {
1643 hostdata->sync[target].select_indirect = (scntl3 << 24) | (target << 16) |
1644 (sxfer << 8);
1645
1646 script = (u32*) hostdata->sync[target].script;
1647
1648
1649 if ((hostdata->chip / 100) == 8) {
1650 script[0] = ((DCMD_TYPE_RWRI | DCMD_RWRI_OPC_MODIFY |
1651 DCMD_RWRI_OP_MOVE) << 24) |
1652 (SCNTL3_REG_800 << 16) | (scntl3 << 8);
1653 script[1] = 0;
1654 script += 2;
1655 }
1656
1657 script[0] = ((DCMD_TYPE_RWRI | DCMD_RWRI_OPC_MODIFY |
1658 DCMD_RWRI_OP_MOVE) << 24) |
1659 (SXFER_REG << 16) | (sxfer << 8);
1660 script[1] = 0;
1661 script += 2;
1662
1663 script[0] = ((DCMD_TYPE_TCI|DCMD_TCI_OP_RETURN) << 24) | DBC_TCI_TRUE;
1664 script[1] = 0;
1665 script += 2;
1666 }
1667 }
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682 static int NCR53c8x0_dstat_sir_intr (struct Scsi_Host *host, struct
1683 NCR53c7x0_cmd *cmd) {
1684 NCR53c7x0_local_declare();
1685 Scsi_Cmnd *c = cmd ? cmd->cmd : NULL;
1686 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
1687 host->hostdata;
1688 u32 dsps,*dsp;
1689 NCR53c7x0_local_setup(host);
1690 dsps = NCR53c7x0_read32(DSPS_REG);
1691 dsp = bus_to_virt(NCR53c7x0_read32(DSP_REG));
1692
1693 if (hostdata->options & OPTION_DEBUG_INTR)
1694 printk ("scsi%d : DSPS = 0x%x\n", host->host_no, dsps);
1695
1696 switch (dsps) {
1697 case A_int_msg_1:
1698 printk ("scsi%d : message", host->host_no);
1699 if (cmd)
1700 printk (" from target %d lun %d", c->target, c->lun);
1701 print_msg ((unsigned char *) hostdata->msg_buf);
1702 printk("\n");
1703 switch (hostdata->msg_buf[0]) {
1704
1705
1706
1707
1708 case MESSAGE_REJECT:
1709 hostdata->dsp = hostdata->script + hostdata->E_accept_message /
1710 sizeof(u32);
1711 hostdata->dsp_changed = 1;
1712 break;
1713 case INITIATE_RECOVERY:
1714 printk ("scsi%d : extended contingent allegiance not supported yet, rejecting\n",
1715 host->host_no);
1716 hostdata->dsp = hostdata->script + hostdata->E_reject_message /
1717 sizeof(u32);
1718 hostdata->dsp_changed = 1;
1719 }
1720 return SPECIFIC_INT_NOTHING;
1721 case A_int_msg_sdtr:
1722 if (cmd) {
1723 printk ("scsi%d : target %d %s synchronous transfer period %dns, offset%d\n",
1724 host->host_no, c->target, (cmd->flags & CMD_FLAG_SDTR) ? "accepting" :
1725 "requesting", hostdata->msg_buf[3] * 4, hostdata->msg_buf[4]);
1726
1727
1728
1729
1730
1731
1732
1733
1734 if (cmd->flags & CMD_FLAG_SDTR) {
1735 cmd->flags &= ~CMD_FLAG_SDTR;
1736 synchronous (host, c->target, (unsigned char *)
1737 hostdata->msg_buf);
1738 hostdata->dsp = hostdata->script + hostdata->E_accept_message /
1739 sizeof(u32);
1740 hostdata->dsp_changed = 1;
1741 return SPECIFIC_INT_NOTHING;
1742 } else {
1743 if (hostdata->options & OPTION_SYNCHRONOUS) {
1744 cmd->flags |= CMD_FLAG_DID_SDTR;
1745 synchronous (host, c->target, (unsigned char *)
1746 hostdata->msg_buf);
1747 } else {
1748 hostdata->msg_buf[4] = 0;
1749 }
1750
1751 patch_dsa_32 (cmd->dsa, dsa_msgout_other, 0, 5);
1752 patch_dsa_32 (cmd->dsa, dsa_msgout_other, 1,
1753 virt_to_bus((void*)hostdata->msg_buf));
1754 hostdata->dsp = hostdata->script +
1755 hostdata->E_respond_message / sizeof(u32);
1756 hostdata->dsp_changed = 1;
1757 }
1758
1759 if (hostdata->msg_buf[4]) {
1760 int Hz = 1000000000 / (hostdata->msg_buf[3] * 4);
1761 printk ("scsi%d : setting target %d to %d.%02dMhz %s SCSI%s\n"
1762 " period = %dns, max offset = %d\n",
1763 host->host_no, c->target, Hz / 1000000, Hz % 1000000,
1764 ((hostdata->msg_buf[3] < 200) ? "FAST " :
1765 "synchronous") ,
1766 ((hostdata->msg_buf[3] < 200) ? "-II" : ""),
1767 (int) hostdata->msg_buf[3] * 4, (int)
1768 hostdata->msg_buf[4]);
1769 } else {
1770 printk ("scsi%d : setting target %d to asynchronous SCSI\n",
1771 host->host_no, c->target);
1772 }
1773 return SPECIFIC_INT_NOTHING;
1774 }
1775
1776 case A_int_msg_wdtr:
1777 hostdata->dsp = hostdata->script + hostdata->E_reject_message /
1778 sizeof(u32);
1779 hostdata->dsp_changed = 1;
1780 return SPECIFIC_INT_NOTHING;
1781 case A_int_err_unexpected_phase:
1782 if (hostdata->options & OPTION_DEBUG_INTR)
1783 printk ("scsi%d : unexpected phase\n", host->host_no);
1784 return SPECIFIC_INT_ABORT;
1785 case A_int_err_selected:
1786 printk ("scsi%d : selected by target %d\n", host->host_no,
1787 (int) NCR53c7x0_read8(SSID_REG_800) &7);
1788 hostdata->dsp = hostdata->script + hostdata->E_target_abort /
1789 sizeof(u32);
1790 hostdata->dsp_changed = 1;
1791 return SPECIFIC_INT_NOTHING;
1792 case A_int_err_unexpected_reselect:
1793 printk ("scsi%d : unexpected reselect by target %d\n", host->host_no,
1794 (int) NCR53c7x0_read8(SSID_REG_800));
1795 hostdata->dsp = hostdata->script + hostdata->E_initiator_abort /
1796 sizeof(u32);
1797 hostdata->dsp_changed = 1;
1798 return SPECIFIC_INT_NOTHING;
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808 case A_int_err_check_condition:
1809 #if 0
1810 if (hostdata->options & OPTION_DEBUG_INTR)
1811 #endif
1812 printk ("scsi%d : CHECK CONDITION\n", host->host_no);
1813 if (!c) {
1814 printk("scsi%d : CHECK CONDITION with no SCSI command\n",
1815 host->host_no);
1816 return SPECIFIC_INT_PANIC;
1817 }
1818
1819
1820
1821
1822
1823
1824 asynchronous (host, c->target);
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836 patch_dsa_32 (cmd->dsa, dsa_msgout, 0, 1);
1837
1838
1839
1840
1841
1842
1843 patch_dsa_32 (cmd->dsa, dsa_cmdout, 0, 6);
1844
1845 c->cmnd[0] = REQUEST_SENSE;
1846 c->cmnd[1] &= 0xe0;
1847 c->cmnd[2] = 0;
1848 c->cmnd[3] = 0;
1849 c->cmnd[4] = sizeof(c->sense_buffer);
1850 c->cmnd[5] = 0;
1851
1852
1853
1854
1855
1856
1857
1858 patch_dsa_32 (cmd->dsa, dsa_dataout, 0, hostdata->E_other_transfer);
1859 patch_dsa_32 (cmd->dsa, dsa_datain, 0, virt_to_bus(cmd->data_transfer_start));
1860 cmd->data_transfer_start[0] = (((DCMD_TYPE_BMI | DCMD_BMI_OP_MOVE_I |
1861 DCMD_BMI_IO)) << 24) | sizeof(c->sense_buffer);
1862 cmd->data_transfer_start[1] = virt_to_bus(c->sense_buffer);
1863
1864 cmd->data_transfer_start[2] = ((DCMD_TYPE_TCI | DCMD_TCI_OP_JUMP)
1865 << 24) | DBC_TCI_TRUE;
1866 cmd->data_transfer_start[3] = hostdata->E_other_transfer;
1867
1868
1869
1870
1871
1872
1873
1874
1875 cmd->cmd->result = 0xffff;
1876
1877
1878
1879
1880 hostdata->dsp = hostdata->script + hostdata->E_select /
1881 sizeof(u32);
1882 hostdata->dsp_changed = 1;
1883 return SPECIFIC_INT_NOTHING;
1884 case A_int_debug_break:
1885 return SPECIFIC_INT_BREAK;
1886 case A_int_norm_aborted:
1887 hostdata->dsp = hostdata->script + hostdata->E_schedule /
1888 sizeof(u32);
1889 hostdata->dsp_changed = 1;
1890 if (cmd)
1891 abnormal_finished (cmd, DID_ERROR << 16);
1892 return SPECIFIC_INT_NOTHING;
1893 case A_int_test_1:
1894 case A_int_test_2:
1895 hostdata->idle = 1;
1896 hostdata->test_completed = (dsps - A_int_test_1) / 0x00010000 + 1;
1897 if (hostdata->options & OPTION_DEBUG_INTR)
1898 printk("scsi%d : test %d complete\n", host->host_no,
1899 hostdata->test_completed);
1900 return SPECIFIC_INT_NOTHING;
1901 #ifdef A_int_debug_scheduled
1902 case A_int_debug_scheduled:
1903 if (hostdata->options & (OPTION_DEBUG_SCRIPT|OPTION_DEBUG_INTR)) {
1904 printk("scsi%d : new I/O 0x%x scheduled\n", host->host_no,
1905 NCR53c7x0_read32(DSA_REG));
1906 }
1907 return SPECIFIC_INT_RESTART;
1908 #endif
1909 #ifdef A_int_debug_idle
1910 case A_int_debug_idle:
1911 if (hostdata->options & (OPTION_DEBUG_SCRIPT|OPTION_DEBUG_INTR)) {
1912 printk("scsi%d : idle\n", host->host_no);
1913 }
1914 return SPECIFIC_INT_RESTART;
1915 #endif
1916 #ifdef A_int_debug_cmd
1917 case A_int_debug_cmd:
1918 if (hostdata->options & (OPTION_DEBUG_SCRIPT|OPTION_DEBUG_INTR)) {
1919 printk("scsi%d : command sent\n");
1920 }
1921 return SPECIFIC_INT_RESTART;
1922 #endif
1923 #ifdef A_int_debug_dsa_loaded
1924 case A_int_debug_dsa_loaded:
1925 if (hostdata->options & (OPTION_DEBUG_SCRIPT|OPTION_DEBUG_INTR)) {
1926 printk("scsi%d : DSA loaded with 0x%x\n", host->host_no,
1927 NCR53c7x0_read32(DSA_REG));
1928 }
1929 return SPECIFIC_INT_RESTART;
1930 #endif
1931 #ifdef A_int_debug_reselected
1932 case A_int_debug_reselected:
1933 if (hostdata->options & (OPTION_DEBUG_SCRIPT|OPTION_DEBUG_INTR)) {
1934 printk("scsi%d : reselected by target %d lun %d\n",
1935 host->host_no, (int) NCR53c7x0_read8(SSID_REG_800),
1936 (int) hostdata->reselected_identify & 7);
1937 }
1938 return SPECIFIC_INT_RESTART;
1939 #endif
1940 #ifdef A_int_debug_head
1941 case A_int_debug_head:
1942 if (hostdata->options & (OPTION_DEBUG_SCRIPT|OPTION_DEBUG_INTR)) {
1943 printk("scsi%d : issue_dsa_head now 0x%x\n",
1944 host->host_no, hostdata->issue_dsa_head);
1945 }
1946 return SPECIFIC_INT_RESTART;
1947 #endif
1948 default:
1949 if ((dsps & 0xff000000) == 0x03000000) {
1950 printk ("scsi%d : misc debug interrupt 0x%x\n",
1951 host->host_no, dsps);
1952 return SPECIFIC_INT_RESTART;
1953 }
1954
1955 printk ("scsi%d : unknown user interrupt 0x%x\n",
1956 host->host_no, (unsigned) dsps);
1957 return SPECIFIC_INT_PANIC;
1958 }
1959 }
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975 #include "53c8xx_u.h"
1976
1977
1978
1979
1980 #ifdef NCR_DEBUG
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995 static const char debugger_help =
1996 "bc <addr> - clear breakpoint\n"
1997 "bl - list breakpoints\n"
1998 "bs <addr> - set breakpoint\n"
1999 "g - start\n"
2000 "h - halt\n"
2001 "? - this message\n"
2002 "i - info\n"
2003 "mp <addr> <size> - print memory\n"
2004 "ms <addr> <size> <value> - store memory\n"
2005 "rp <num> <size> - print register\n"
2006 "rs <num> <size> <value> - store register\n"
2007 "s - single step\n"
2008 "tb - begin trace \n"
2009 "te - end trace\n";
2010
2011
2012
2013
2014
2015
2016 static int debugger_fn_bc (struct Scsi_Host *host, struct debugger_token *token,
2017 u32 args[]) {
2018 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
2019 instance->hostdata;
2020 struct NCR53c7x0_break *bp, **prev;
2021 unsigned long flags;
2022 save_flags(flags);
2023 cli();
2024 for (bp = (struct NCR53c7x0_break *) instance->breakpoints,
2025 prev = (struct NCR53c7x0_break **) &instance->breakpoints;
2026 bp; prev = (struct NCR53c7x0_break **) &(bp->next),
2027 bp = (struct NCR53c7x0_break *) bp->next);
2028
2029 if (!bp) {
2030 restore_flags(flags);
2031 return -EIO;
2032 }
2033
2034
2035
2036
2037
2038
2039 memcpy ((void *) bp->addr, (void *) bp->old, sizeof(bp->old));
2040 if (prev)
2041 *prev = bp->next;
2042
2043 restore_flags(flags);
2044 return 0;
2045 }
2046
2047
2048 static int debugger_fn_bl (struct Scsi_Host *host, struct debugger_token *token,
2049 u32 args[]) {
2050 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
2051 host->hostdata;
2052 struct NCR53c7x0_break *bp;
2053 char buf[80];
2054 size_t len;
2055 unsigned long flags;
2056
2057
2058
2059
2060
2061
2062 sprintf (buf, "scsi%d : bp : warning : processor not halted\b",
2063 host->host_no);
2064 debugger_kernel_write (host, buf, strlen(buf));
2065
2066 save_flags(flags);
2067 cli();
2068 for (bp = (struct NCR53c7x0_break *) host->breakpoints;
2069 bp; bp = (struct NCR53c7x0_break *) bp->next); {
2070 sprintf (buf, "scsi%d : bp : success : at %08x, replaces %08x %08x",
2071 bp->addr, bp->old[0], bp->old[1]);
2072 len = strlen(buf);
2073 if ((bp->old[0] & (DCMD_TYPE_MASK << 24)) ==
2074 (DCMD_TYPE_MMI << 24)) {
2075 sprintf(buf + len, "%08x\n", * (u32 *) bp->addr);
2076 } else {
2077 sprintf(buf + len, "\n");
2078 }
2079 len = strlen(buf);
2080 debugger_kernel_write (host, buf, len);
2081 }
2082 restore_flags(flags);
2083 return 0;
2084 }
2085
2086 static int debugger_fn_bs (struct Scsi_Host *host, struct debugger_token *token,
2087 u32 args[]) {
2088 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
2089 host->hostdata;
2090 struct NCR53c7x0_break *bp;
2091 char buf[80];
2092 size_t len;
2093 unsigned long flags;
2094
2095 save_flags(flags);
2096 cli();
2097
2098 if (hostdata->state != STATE_HALTED) {
2099 sprintf (buf, "scsi%d : bs : failure : NCR not halted\n", host->host_no);
2100 debugger_kernel_write (host, buf, strlen(buf));
2101 restore_flags(flags);
2102 return -1;
2103 }
2104
2105 if (!(bp = kmalloc (sizeof (struct NCR53c7x0_break)))) {
2106 printk ("scsi%d : kmalloc(%d) of breakpoint structure failed, try again\n",
2107 host->host_no, sizeof(struct NCR53c7x0_break));
2108 restore_flags(flags);
2109 return -1;
2110 }
2111
2112 bp->address = (u32 *) args[0];
2113 memcpy ((void *) bp->old_instruction, (void *) bp->address, 8);
2114 bp->old_size = (((bp->old_instruction[0] >> 24) & DCMD_TYPE_MASK) ==
2115 DCMD_TYPE_MMI ? 3 : 2);
2116 bp->next = hostdata->breakpoints;
2117 hostdata->breakpoints = bp->next;
2118 memcpy ((void *) bp->address, (void *) hostdata->E_debug_break, 8);
2119
2120 restore_flags(flags);
2121 return 0;
2122 }
2123
2124 #define TOKEN(name,nargs) {#name, nargs, debugger_fn_##name}
2125 static const struct debugger_token {
2126 char *name;
2127 int numargs;
2128 int (*fn)(struct debugger_token *token, u32 args[]);
2129 } debugger_tokens[] = {
2130 TOKEN(bc,1), TOKEN(bl,0), TOKEN(bs,1), TOKEN(g,0), TOKEN(halt,0),
2131 {DT_help, "?", 0} , TOKEN(h,0), TOKEN(i,0), TOKEN(mp,2),
2132 TOKEN(ms,3), TOKEN(rp,2), TOKEN(rs,2), TOKEN(s,0), TOKEN(tb,0), TOKEN(te,0)
2133 };
2134
2135 #define NDT sizeof(debugger_tokens / sizeof(struct debugger_token))
2136
2137 static struct Scsi_Host * inode_to_host (struct inode *inode) {$
2138 int dev;
2139 struct Scsi_Host *tmp;
2140 for (dev = MINOR(inode->rdev), host = first_host;
2141 (host->hostt == the_template); --dev, host = host->next)
2142 if (!dev) return host;
2143 return NULL;
2144 }
2145
2146
2147 static debugger_user_write (struct inode *inode,struct file *filp,
2148 char *buf,int count) {
2149 struct Scsi_Host *host;
2150 struct NCR53c7x0_hostadata *hostdata;
2151 char input_buf[80],
2152 *ptr;
2153 u32 args[3];
2154 int i, j, error, len;
2155
2156 if (!(host = inode_to_host(inode)))
2157 return -ENXIO;
2158
2159 hostdata = (struct NCR53c7x0_hostdata *) host->hostdata;
2160
2161 if (error = verify_area(VERIFY_READ,buf,count))
2162 return error;
2163
2164 if (count > 80)
2165 return -EIO;
2166
2167 memcpy_from_fs(input_buf, buf, count);
2168
2169 if (input_buf[count - 1] != '\n')
2170 return -EIO;
2171
2172 input_buf[count - 1]=0;
2173
2174 for (i = 0; i < NDT; ++i) {
2175 len = strlen (debugger_tokens[i].name);
2176 if (!strncmp(input_buf, debugger_tokens[i].name, len))
2177 break;
2178 };
2179
2180 if (i == NDT)
2181 return -EIO;
2182
2183 for (ptr = input_buf + len, j = 0; j < debugger_tokens[i].nargs && *ptr;) {
2184 if (*ptr == ' ' || *ptr == '\t') {
2185 ++ptr;
2186 } else if (isdigit(*ptr)) {
2187 args[j++] = simple_strtoul (ptr, &ptr, 0);
2188 } else {
2189 return -EIO;
2190 }
2191 }
2192
2193 if (j != debugger_tokens[i].nargs)
2194 return -EIO;
2195
2196 return count;
2197 }
2198
2199 static debugger_user_read (struct inode *inode,struct file *filp,
2200 char *buf,int count) {
2201 struct Scsi_Host *instance;
2202
2203 }
2204
2205 static debugger_kernel_write (struct Scsi_Host *host, char *buf, size_t
2206 buflen) {
2207 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
2208 host->hostdata;
2209 int copy, left;
2210 unsigned long flags;
2211
2212 save_flags(flags);
2213 cli();
2214 while (buflen) {
2215 left = (hostdata->debug_buf + hostdata->debug_size - 1) -
2216 hostdata->debug_write;
2217 copy = (buflen <= left) ? buflen : left;
2218 memcpy (hostdata->debug_write, buf, copy);
2219 buf += copy;
2220 buflen -= copy;
2221 hostdata->debug_count += copy;
2222 if ((hostdata->debug_write += copy) ==
2223 (hostdata->debug_buf + hostdata->debug_size))
2224 hosdata->debug_write = hostdata->debug_buf;
2225 }
2226 restore_flags(flags);
2227 }
2228
2229 #endif
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243 static void
2244 NCR53c8x0_soft_reset (struct Scsi_Host *host) {
2245 NCR53c7x0_local_declare();
2246 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
2247 host->hostdata;
2248 NCR53c7x0_local_setup(host);
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261 NCR53c7x0_write8(ISTAT_REG_800, ISTAT_10_SRST);
2262 mb();
2263 NCR53c7x0_write8(ISTAT_REG_800, 0);
2264 mb();
2265 NCR53c7x0_write8(hostdata->dmode, hostdata->saved_dmode & ~DMODE_MAN);
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276 #ifdef notyet
2277 NCR53c7x0_write8(SCID_REG, (host->this_id & 7)|SCID_800_RRE|SCID_800_SRE);
2278 #else
2279 NCR53c7x0_write8(SCID_REG, (host->this_id & 7)|SCID_800_RRE);
2280 #endif
2281 NCR53c7x0_write8(RESPID_REG_800, hostdata->this_id_mask);
2282
2283
2284
2285
2286
2287
2288 NCR53c7x0_write8(STIME0_REG_800,
2289 ((14 << STIME0_800_SEL_SHIFT) & STIME0_800_SEL_MASK)
2290
2291 #if 0
2292 | ((15 << STIME0_800_HTH_SHIFT) & STIME0_800_HTH_MASK)
2293 #endif
2294 );
2295
2296
2297
2298
2299
2300
2301
2302
2303 NCR53c7x0_write8(DIEN_REG, DIEN_800_MDPE | DIEN_800_BF |
2304 DIEN_ABRT | DIEN_SSI | DIEN_SIR | DIEN_800_IID);
2305
2306
2307 NCR53c7x0_write8(SIEN0_REG_800, ((hostdata->options & OPTION_PARITY) ?
2308 SIEN_PAR : 0) | SIEN_RST | SIEN_UDC | SIEN_SGE | SIEN_MA);
2309 NCR53c7x0_write8(SIEN1_REG_800, SIEN1_800_STO | SIEN1_800_HTH);
2310
2311
2312
2313
2314
2315
2316 NCR53c7x0_write8(DCNTL_REG, hostdata->saved_dcntl);
2317 NCR53c7x0_write8(CTEST4_REG_800, hostdata->saved_ctest4);
2318
2319
2320 NCR53c7x0_write8(STEST3_REG_800, STEST3_800_TE);
2321
2322 mb();
2323 }
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342 static struct NCR53c7x0_cmd *
2343 create_cmd (Scsi_Cmnd *cmd) {
2344 NCR53c7x0_local_declare();
2345 struct Scsi_Host *host = cmd->host;
2346 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
2347 host->hostdata;
2348 struct NCR53c7x0_cmd *tmp = NULL;
2349 int datain,
2350 dataout;
2351 int data_transfer_instructions,
2352 i;
2353 u32 *cmd_datain,
2354 *cmd_dataout;
2355 #ifdef notyet
2356 void *real;
2357 int size;
2358 int alignment;
2359 #endif
2360 unsigned long flags;
2361 NCR53c7x0_local_setup(cmd->host);
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372 #ifdef notyet
2373
2374 if (hostdata->num_commands < host->can_queue &&
2375 !in_scan_scsis &&
2376 !(hostdata->cmd_allocated[cmd->target] & (1 << cmd->lun))) {
2377 for (i = host->hostt->cmd_per_lun - 1; i >= 0 --i) {
2378 #ifdef SCSI_MALLOC
2379
2380
2381 size = (hostdata->max_cmd_size + 511) / 512 * 512;
2382 tmp = (struct NCR53c7x0_cmd *) scsi_malloc (size);
2383 if (!tmp)
2384 break;
2385 tmp->real = (void *) tmp;
2386 #else
2387
2388
2389 size = hostdata->max_cmd_size + sizeof(void*);
2390 real = kmalloc (size, GFP_ATOMIC);
2391 alignment = sizeof(void*) - (((unsigned) real) & (sizeof(void*)-1));
2392 tmp = (struct NCR53c7x0_cmd *) (((char *) real) + alignment);
2393 if (!tmp)
2394 break;
2395 tmp->real = real;
2396 #endif
2397 tmp->size = size;
2398
2399 if (i > 0) {
2400 tmp->next = hostdata->free;
2401 hostdata->free = tmp;
2402 }
2403 }
2404 }
2405 #endif
2406 if (!tmp) {
2407 save_flags(flags);
2408 cli();
2409 tmp = (struct NCR53c7x0_cmd *) hostdata->free;
2410 if (tmp) {
2411 hostdata->free = tmp->next;
2412 restore_flags(flags);
2413 } else {
2414 restore_flags(flags);
2415 return NULL;
2416 }
2417 }
2418
2419
2420
2421
2422
2423
2424 switch (cmd->cmnd[0]) {
2425
2426 case INQUIRY:
2427 case MODE_SENSE:
2428 case READ_6:
2429 case READ_10:
2430 case READ_CAPACITY:
2431 case REQUEST_SENSE:
2432 datain = 2 * (cmd->use_sg ? cmd->use_sg : 1) + 3;
2433 dataout = 0;
2434 break;
2435
2436 case MODE_SELECT:
2437 case WRITE_6:
2438 case WRITE_10:
2439 #if 0
2440 printk("scsi%d : command is ", host->host_no);
2441 print_command(cmd->cmnd);
2442 #endif
2443 #if 0
2444 printk ("scsi%d : %d scatter/gather segments\n", host->host_no,
2445 cmd->use_sg);
2446 #endif
2447 datain = 0;
2448 dataout = 2 * (cmd->use_sg ? cmd->use_sg : 1) + 3;
2449 #if 0
2450 hostdata->options |= OPTION_DEBUG_INTR;
2451 #endif
2452 break;
2453
2454
2455
2456
2457 case START_STOP:
2458 case TEST_UNIT_READY:
2459 datain = dataout = 0;
2460 break;
2461
2462
2463
2464
2465 default:
2466 datain = dataout = 2 * (cmd->use_sg ? cmd->use_sg : 1) + 3;
2467 }
2468
2469
2470
2471
2472
2473
2474
2475 data_transfer_instructions = datain + dataout;
2476
2477
2478
2479
2480
2481
2482
2483 if (data_transfer_instructions < 2)
2484 data_transfer_instructions = 2;
2485
2486
2487
2488
2489
2490 tmp->cmd = cmd;
2491 tmp->next = NULL;
2492 tmp->prev = NULL;
2493
2494
2495
2496
2497
2498 tmp->data_transfer_start = tmp->dsa + (hostdata->dsa_end -
2499 hostdata->dsa_start) / sizeof(u32);
2500 tmp->data_transfer_end = tmp->data_transfer_start +
2501 2 * data_transfer_instructions;
2502
2503 cmd_datain = datain ? tmp->data_transfer_start : NULL;
2504 cmd_dataout = dataout ? (datain ? cmd_datain + 2 * datain : tmp->
2505 data_transfer_start) : NULL;
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515 if (hostdata->dsa_fixup)
2516 hostdata->dsa_fixup(tmp);
2517
2518 patch_dsa_32(tmp->dsa, dsa_next, 0, 0);
2519 patch_dsa_32(tmp->dsa, dsa_cmnd, 0, virt_to_bus(cmd));
2520 patch_dsa_32(tmp->dsa, dsa_select, 0, hostdata->sync[cmd->target].
2521 select_indirect);
2522
2523
2524
2525
2526 patch_dsa_32(tmp->dsa, dsa_msgout, 0, 1);
2527 #if 0
2528 tmp->select[0] = IDENTIFY (1, cmd->lun);
2529 #else
2530 tmp->select[0] = IDENTIFY (0, cmd->lun);
2531 #endif
2532 patch_dsa_32(tmp->dsa, dsa_msgout, 1, virt_to_bus(tmp->select));
2533 patch_dsa_32(tmp->dsa, dsa_cmdout, 0, cmd->cmd_len);
2534 patch_dsa_32(tmp->dsa, dsa_cmdout, 1, virt_to_bus(cmd->cmnd));
2535 patch_dsa_32(tmp->dsa, dsa_dataout, 0, cmd_dataout ?
2536 virt_to_bus(cmd_dataout) : virt_to_bus(hostdata->script) + hostdata->E_other_transfer);
2537 patch_dsa_32(tmp->dsa, dsa_datain, 0, cmd_datain ?
2538 virt_to_bus(cmd_datain) : virt_to_bus(hostdata->script) + hostdata->E_other_transfer);
2539
2540
2541
2542
2543 patch_dsa_32(tmp->dsa, dsa_msgin, 0, 1);
2544 patch_dsa_32(tmp->dsa, dsa_msgin, 1, virt_to_bus(&cmd->result) + 1);
2545 patch_dsa_32(tmp->dsa, dsa_status, 0, 1);
2546 patch_dsa_32(tmp->dsa, dsa_status, 1, virt_to_bus(&cmd->result));
2547 patch_dsa_32(tmp->dsa, dsa_msgout_other, 0, 1);
2548 patch_dsa_32(tmp->dsa, dsa_msgout_other, 1,
2549 virt_to_bus(&hostdata->NCR53c7xx_msg_nop));
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564 #if 0
2565 if (datain) {
2566 cmd_datain[0] = 0x98080000;
2567 cmd_datain[1] = 0x03ffd00d;
2568 cmd_datain += 2;
2569 }
2570 #endif
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587 for (i = 0; cmd->use_sg ? (i < cmd->use_sg) : !i; cmd_datain += 4,
2588 cmd_dataout += 4, ++i) {
2589 u32 buf = cmd->use_sg ?
2590 virt_to_bus(((struct scatterlist *)cmd->buffer)[i].address) :
2591 virt_to_bus(cmd->request_buffer);
2592 u32 count = cmd->use_sg ?
2593 ((struct scatterlist *)cmd->buffer)[i].length :
2594 cmd->request_bufflen;
2595
2596 if (datain) {
2597 cmd_datain[0] = ((DCMD_TYPE_BMI | DCMD_BMI_OP_MOVE_I | DCMD_BMI_IO)
2598 << 24) | count;
2599 cmd_datain[1] = buf;
2600 cmd_datain[2] = ((DCMD_TYPE_TCI | DCMD_TCI_OP_CALL |
2601 DCMD_TCI_CD | DCMD_TCI_IO | DCMD_TCI_MSG) << 24) |
2602 DBC_TCI_WAIT_FOR_VALID | DBC_TCI_COMPARE_PHASE | DBC_TCI_TRUE;
2603 cmd_datain[3] = virt_to_bus(hostdata->script) +
2604 hostdata->E_msg_in;
2605 #if 0
2606 print_insn (host, cmd_datain, "dynamic ", 1);
2607 print_insn (host, cmd_datain + 2, "dynamic ", 1);
2608 #endif
2609 }
2610 if (dataout) {
2611 cmd_dataout[0] = ((DCMD_TYPE_BMI | DCMD_BMI_OP_MOVE_I) << 24)
2612 | count;
2613 cmd_dataout[1] = buf;
2614 cmd_dataout[2] = ((DCMD_TYPE_TCI | DCMD_TCI_OP_CALL |
2615 DCMD_TCI_CD | DCMD_TCI_IO | DCMD_TCI_MSG) << 24) |
2616 DBC_TCI_WAIT_FOR_VALID | DBC_TCI_COMPARE_PHASE | DBC_TCI_TRUE;
2617 cmd_dataout[3] = virt_to_bus(hostdata->script) +
2618 hostdata->E_msg_in;
2619 #if 0
2620 print_insn (host, cmd_dataout, "dynamic ", 1);
2621 print_insn (host, cmd_dataout + 2, "dynamic ", 1);
2622 #endif
2623 }
2624 }
2625
2626
2627
2628
2629
2630
2631
2632 if (datain) {
2633 cmd_datain[0] = ((DCMD_TYPE_TCI | DCMD_TCI_OP_JUMP) << 24) |
2634 DBC_TCI_TRUE;
2635 cmd_datain[1] = virt_to_bus(hostdata->script) +
2636 hostdata->E_other_transfer;
2637 #if 0
2638 print_insn (host, cmd_datain, "dynamic jump ", 1);
2639 #endif
2640 cmd_datain += 2;
2641 }
2642 #if 0
2643 if (datain) {
2644 cmd_datain[0] = 0x98080000;
2645 cmd_datain[1] = 0x03ffdeed;
2646 cmd_datain += 2;
2647 }
2648 #endif
2649
2650
2651 if (dataout) {
2652 cmd_dataout[0] = ((DCMD_TYPE_TCI | DCMD_TCI_OP_JUMP) << 24) |
2653 DBC_TCI_TRUE;
2654 cmd_dataout[1] = virt_to_bus(hostdata->script) +
2655 hostdata->E_other_transfer;
2656 #if 0
2657 print_insn (host, cmd_dataout, "dynamic jump ", 1);
2658 #endif
2659 cmd_dataout += 2;
2660 }
2661
2662
2663 return tmp;
2664 }
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684 int NCR53c7xx_queue_command (Scsi_Cmnd *cmd, void (* done)(Scsi_Cmnd *)) {
2685 NCR53c7x0_local_declare();
2686 struct NCR53c7x0_cmd *tmp;
2687 struct Scsi_Host *host = cmd->host;
2688 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
2689 host->hostdata;
2690 unsigned long flags;
2691 unsigned char target_was_busy;
2692 NCR53c7x0_local_setup(host);
2693
2694 if (((hostdata->options & (OPTION_DEBUG_INIT_ONLY|OPTION_DEBUG_PROBE_ONLY)) ||
2695 ((hostdata->options & OPTION_DEBUG_TARGET_LIMIT) &&
2696 !(hostdata->debug_lun_limit[cmd->target] & (1 << cmd->lun)))) ||
2697 cmd->target > 7) {
2698 printk("scsi%d : disabled target %d lun %d\n", host->host_no,
2699 cmd->target, cmd->lun);
2700 cmd->result = (DID_BAD_TARGET << 16);
2701 done(cmd);
2702 return 0;
2703 }
2704
2705 if (hostdata->options & OPTION_DEBUG_NCOMMANDS_LIMIT) {
2706 if (hostdata->debug_count_limit == 0) {
2707 printk("scsi%d : maximum commands exceeded\n", host->host_no);
2708 cmd->result = (DID_BAD_TARGET << 16);
2709 done(cmd);
2710 return 0;
2711 } else if (hostdata->debug_count_limit != -1)
2712 --hostdata->debug_count_limit;
2713 }
2714
2715 if (hostdata->options & OPTION_DEBUG_READ_ONLY) {
2716 switch (cmd->cmnd[0]) {
2717 case WRITE_6:
2718 case WRITE_10:
2719 printk("scsi%d : WRITE attempted with NO_WRITE debugging flag set\n",
2720 host->host_no);
2721 cmd->result = (DID_BAD_TARGET << 16);
2722 done(cmd);
2723 return 0;
2724 }
2725 }
2726
2727 cmd->scsi_done = done;
2728 cmd->result = 0xffff;
2729
2730
2731 cmd->host_scribble = (unsigned char *) tmp = create_cmd (cmd);
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758 save_flags(flags);
2759 cli();
2760
2761
2762
2763
2764
2765
2766
2767
2768 target_was_busy = hostdata->busy[cmd->target][cmd->lun]
2769 #ifdef LUN_BUSY
2770 ++
2771 #endif
2772 ;
2773
2774 if (!(hostdata->options & OPTION_700) &&
2775 !target_was_busy) {
2776 unsigned char *dsa = ((unsigned char *) tmp->dsa)
2777 - hostdata->dsa_start;
2778
2779 #if 0
2780 printk("scsi%d : new dsa is 0x%p\n", host->host_no, dsa);
2781 #endif
2782
2783 if (hostdata->running_list)
2784 hostdata->running_list->prev = tmp;
2785
2786 tmp->next = (struct NCR53c7x0_cmd*) hostdata->running_list;
2787
2788 if (!hostdata->running_list)
2789 hostdata->running_list = (struct NCR53c7x0_cmd*) tmp;
2790
2791
2792 if (hostdata->idle) {
2793 hostdata->idle = 0;
2794 hostdata->state = STATE_RUNNING;
2795 NCR53c7x0_write32 (DSP_REG, virt_to_bus(hostdata->script) +
2796 hostdata->E_schedule);
2797 mb();
2798 }
2799
2800
2801 for (;;) {
2802
2803
2804
2805
2806
2807
2808 if (!hostdata->issue_dsa_head) {
2809 #if 0
2810 printk ("scsi%d : no issue queue\n", host->host_no);
2811 #endif
2812 hostdata->issue_dsa_tail = (u32 *) dsa;
2813 hostdata->issue_dsa_head = virt_to_bus(dsa);
2814 NCR53c7x0_write8(hostdata->istat,
2815 NCR53c7x0_read8(hostdata->istat) | ISTAT_10_SIGP);
2816 mb();
2817 break;
2818
2819
2820
2821
2822
2823
2824
2825 } else {
2826 printk ("scsi%d : existing issue queue\n", host->host_no);
2827 hostdata->issue_dsa_tail[hostdata->dsa_next/sizeof(u32)]
2828 = virt_to_bus(dsa);
2829 hostdata->issue_dsa_tail = (u32 *) dsa;
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841 if (hostdata->issue_dsa_head)
2842 break;
2843 }
2844 }
2845
2846 } else {
2847 #if 1
2848 printk ("scsi%d : using issue_queue instead of issue_dsa_head!\n",
2849 host->host_no);
2850 #endif
2851 for (tmp = (struct NCR53c7x0_cmd *) hostdata->issue_queue;
2852 tmp->next; tmp = (struct NCR53c7x0_cmd *) tmp->next);
2853 tmp->next = tmp;
2854 }
2855 restore_flags(flags);
2856 return 0;
2857 }
2858
2859
2860 int fix_pointers (u32 dsa) {
2861 return 0;
2862 }
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875 static void intr_scsi (struct Scsi_Host *host, struct NCR53c7x0_cmd *cmd) {
2876 NCR53c7x0_local_declare();
2877 struct NCR53c7x0_hostdata *hostdata =
2878 (struct NCR53c7x0_hostdata *) host->hostdata;
2879 unsigned char sstat0_sist0, sist1,
2880 fatal;
2881
2882 int is_8xx_chip;
2883 NCR53c7x0_local_setup(host);
2884
2885 fatal = 0;
2886
2887 is_8xx_chip = ((unsigned) (hostdata->chip - 800)) < 100;
2888 if (is_8xx_chip) {
2889 sstat0_sist0 = NCR53c7x0_read8(SIST0_REG_800);
2890 udelay(1);
2891 sist1 = NCR53c7x0_read8(SIST1_REG_800);
2892 } else {
2893 sstat0_sist0 = NCR53c7x0_read8(SSTAT0_REG);
2894 sist1 = 0;
2895 }
2896
2897 if (hostdata->options & OPTION_DEBUG_INTR)
2898 printk ("scsi%d : SIST0 0x%0x, SIST1 0x%0x\n", host->host_no,
2899 sstat0_sist0, sist1);
2900
2901
2902 if ((is_8xx_chip && (sist1 & SIST1_800_STO)) ||
2903 (!is_8xx_chip && (sstat0_sist0 & SSTAT0_700_STO))) {
2904 fatal = 1;
2905 if (hostdata->options & OPTION_DEBUG_INTR) {
2906 printk ("scsi%d : Selection Timeout\n", host->host_no);
2907 if (cmd) {
2908 printk("scsi%d : target %d, lun %d, command ",
2909 host->host_no, cmd->cmd->target, cmd->cmd->lun);
2910 print_command (cmd->cmd->cmnd);
2911 printk("scsi%d : dsp = 0x%x\n", host->host_no,
2912 (unsigned) NCR53c7x0_read32(DSP_REG));
2913 } else {
2914 printk("scsi%d : no command\n", host->host_no);
2915 }
2916 }
2917
2918
2919
2920
2921
2922
2923 if (1) {
2924 hostdata->idle = 1;
2925 hostdata->expecting_sto = 0;
2926
2927 if (hostdata->test_running) {
2928 hostdata->test_running = 0;
2929 hostdata->test_completed = 3;
2930 } else if (cmd) {
2931 abnormal_finished(cmd, DID_BAD_TARGET << 16);
2932 }
2933 #if 0
2934 hostdata->intrs = 0;
2935 #endif
2936 }
2937 }
2938
2939 if (sstat0_sist0 & SSTAT0_UDC) {
2940 fatal = 1;
2941 if (cmd) {
2942 printk("scsi%d : target %d lun %d unexpected disconnect\n",
2943 host->host_no, cmd->cmd->target, cmd->cmd->lun);
2944 abnormal_finished(cmd, DID_ERROR << 16);
2945 }
2946 hostdata->dsp = hostdata->script + hostdata->E_schedule /
2947 sizeof(u32);
2948 hostdata->dsp_changed = 1;
2949
2950 }
2951
2952 if (sstat0_sist0 & SSTAT0_PAR) {
2953 fatal = 1;
2954 if (cmd && cmd->cmd) {
2955 printk("scsi%d : target %d lun %d parity error.\n",
2956 host->host_no, cmd->cmd->target, cmd->cmd->lun);
2957 abnormal_finished (cmd, DID_PARITY << 16);
2958 } else
2959 printk("scsi%d : parity error\n", host->host_no);
2960
2961
2962
2963 hostdata->dsp = hostdata->script + hostdata->E_initiator_abort /
2964 sizeof(u32);
2965 hostdata->dsp_changed = 1;
2966
2967 }
2968
2969 if (sstat0_sist0 & SSTAT0_SGE) {
2970 fatal = 1;
2971 printk("scsi%d : gross error\n", host->host_no);
2972
2973 hostdata->dsp = hostdata->script + hostdata->E_initiator_abort /
2974 sizeof(u32);
2975 hostdata->dsp_changed = 1;
2976
2977 }
2978
2979 if (sstat0_sist0 & SSTAT0_MA) {
2980 fatal = 1;
2981 if (hostdata->options & OPTION_DEBUG_INTR)
2982 printk ("scsi%d : SSTAT0_MA\n", host->host_no);
2983 intr_phase_mismatch (host, cmd);
2984 }
2985
2986 #if 1
2987
2988
2989
2990
2991
2992 if (fatal) {
2993 if (!hostdata->dstat_valid) {
2994 hostdata->dstat = NCR53c7x0_read8(DSTAT_REG);
2995 hostdata->dstat_valid = 1;
2996 }
2997
2998
2999 if (!(hostdata->dstat & DSTAT_DFE)) {
3000 printk ("scsi%d : DMA FIFO not empty\n", host->host_no);
3001 #if 0
3002 if (NCR53c7x0_read8 (CTEST2_REG_800) & CTEST2_800_DDIR) {
3003 NCR53c7x0_write8 (CTEST3_REG_800, CTEST3_800_FLF);
3004 mb();
3005 while (!((hostdata->dstat = NCR53c7x0_read8(DSTAT_REG)) &
3006 DSTAT_DFE));
3007 } else
3008 #endif
3009 {
3010 NCR53c7x0_write8 (CTEST3_REG_800, CTEST3_800_CLF);
3011 mb();
3012 while (NCR53c7x0_read8 (CTEST3_REG_800) & CTEST3_800_CLF);
3013 }
3014 }
3015
3016 NCR53c7x0_write8 (STEST3_REG_800, STEST3_800_CSF);
3017 mb();
3018 while (NCR53c7x0_read8 (STEST3_REG_800) & STEST3_800_CSF);
3019 }
3020 #endif
3021 }
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034 static void NCR53c7x0_intr (int irq, struct pt_regs * regs) {
3035 NCR53c7x0_local_declare();
3036 struct Scsi_Host *host;
3037 unsigned char istat;
3038 struct NCR53c7x0_hostdata *hostdata;
3039 struct NCR53c7x0_cmd *cmd,
3040 **cmd_prev_ptr;
3041 u32 *dsa;
3042 int done = 1;
3043
3044 int interrupted = 0;
3045
3046 unsigned long flags;
3047
3048 #ifdef NCR_DEBUG
3049 char buf[80];
3050 size_t buflen;
3051 #endif
3052
3053 #if 0
3054 printk("interrupt %d received\n", irq);
3055 #endif
3056
3057 do {
3058 done = 1;
3059 for (host = first_host; host; host = hostdata->next) {
3060 NCR53c7x0_local_setup(host);
3061
3062 hostdata = (struct NCR53c7x0_hostdata *) host->hostdata;
3063 hostdata->dsp_changed = 0;
3064 interrupted = 0;
3065
3066
3067 do {
3068 int is_8xx_chip;
3069
3070 hostdata->dstat_valid = 0;
3071 interrupted = 0;
3072
3073
3074
3075
3076 istat = NCR53c7x0_read8(hostdata->istat);
3077
3078
3079
3080
3081
3082
3083
3084
3085 is_8xx_chip = ((unsigned) (hostdata->chip - 800)) < 100;
3086 if ((hostdata->options & OPTION_INTFLY) &&
3087 (is_8xx_chip && (istat & ISTAT_800_INTF))) {
3088 char search_found = 0;
3089 done = 0;
3090 interrupted = 1;
3091
3092
3093
3094
3095
3096 NCR53c7x0_write8(hostdata->istat, istat|ISTAT_800_INTF);
3097 mb();
3098
3099 if (hostdata->options & OPTION_DEBUG_INTR)
3100 printk ("scsi%d : INTFLY\n", host->host_no);
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110 save_flags(flags);
3111 cli();
3112 restart:
3113 for (cmd_prev_ptr = (struct NCR53c7x0_cmd **)
3114 &(hostdata->running_list), cmd =
3115 (struct NCR53c7x0_cmd *) hostdata->running_list; cmd ;
3116 cmd_prev_ptr = (struct NCR53c7x0_cmd **) &(cmd->next),
3117 cmd = (struct NCR53c7x0_cmd *) cmd->next) {
3118 Scsi_Cmnd *tmp;
3119
3120 if (!cmd) {
3121 printk("scsi%d : very weird.\n", host->host_no);
3122 break;
3123 }
3124
3125 if (!(tmp = cmd->cmd)) {
3126 printk("scsi%d : weird. NCR53c7x0_cmd has no Scsi_Cmnd\n",
3127 host->host_no);
3128 continue;
3129 }
3130 #if 0
3131 printk ("scsi%d : looking at result of 0x%x\n",
3132 host->host_no, cmd->cmd->result);
3133 #endif
3134
3135 if (((tmp->result & 0xff) == 0xff) ||
3136 ((tmp->result & 0xff00) == 0xff00))
3137 continue;
3138
3139 search_found = 1;
3140
3141
3142
3143 if (cmd->prev)
3144 cmd->prev->next = cmd->next;
3145 if (cmd_prev_ptr)
3146 *cmd_prev_ptr = (struct NCR53c7x0_cmd *) cmd->next;
3147
3148 #ifdef LUN_BUSY
3149
3150 if (--hostdata->busy[tmp->target][tmp->lun]) {
3151 }
3152 #endif
3153
3154
3155 cmd->next = hostdata->free;
3156 hostdata->free = cmd;
3157
3158 tmp->host_scribble = NULL;
3159
3160 if (hostdata->options & OPTION_DEBUG_INTR) {
3161 printk ("scsi%d : command complete : pid %lu, id %d,lun %d result 0x%x ",
3162 host->host_no, tmp->pid, tmp->target, tmp->lun, tmp->result);
3163 print_command (tmp->cmnd);
3164 }
3165
3166
3167 #if 0
3168 hostdata->options &= ~OPTION_DEBUG_INTR;
3169 #endif
3170 tmp->scsi_done(tmp);
3171 goto restart;
3172
3173 }
3174 restore_flags(flags);
3175
3176 if (!search_found) {
3177 printk ("scsi%d : WARNING : INTFLY with no completed commands.\n",
3178 host->host_no);
3179 }
3180 }
3181
3182 if (istat & (ISTAT_SIP|ISTAT_DIP)) {
3183 done = 0;
3184 interrupted = 1;
3185 hostdata->state = STATE_HALTED;
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196 if (hostdata->options & OPTION_700) {
3197 cmd = (struct NCR53c7x0_cmd *) hostdata->current;
3198 } else {
3199 dsa = bus_to_virt(NCR53c7x0_read32(DSA_REG));
3200 for (cmd = (struct NCR53c7x0_cmd *)
3201 hostdata->running_list; cmd &&
3202 (dsa + (hostdata->dsa_start / sizeof(u32))) !=
3203 cmd->dsa;
3204 cmd = (struct NCR53c7x0_cmd *)(cmd->next));
3205 }
3206 if (hostdata->options & OPTION_DEBUG_INTR) {
3207 if (cmd) {
3208 printk("scsi%d : interrupt for pid %lu, id %d, lun %d ",
3209 host->host_no, cmd->cmd->pid, (int) cmd->cmd->target,
3210 (int) cmd->cmd->lun);
3211 print_command (cmd->cmd->cmnd);
3212 } else {
3213 printk("scsi%d : no active command\n", host->host_no);
3214 }
3215 }
3216
3217 if (istat & ISTAT_SIP) {
3218 if (hostdata->options & OPTION_DEBUG_INTR)
3219 printk ("scsi%d : ISTAT_SIP\n", host->host_no);
3220 intr_scsi (host, cmd);
3221 }
3222
3223 if (istat & ISTAT_DIP) {
3224 if (hostdata->options & OPTION_DEBUG_INTR)
3225 printk ("scsi%d : ISTAT_DIP\n", host->host_no);
3226 intr_dma (host, cmd);
3227 }
3228
3229 if (!hostdata->dstat_valid) {
3230 hostdata->dstat = NCR53c7x0_read8(DSTAT_REG);
3231 hostdata->dstat_valid = 1;
3232 }
3233
3234 #if 1
3235
3236 if (!(hostdata->dstat & DSTAT_DFE)) {
3237 printk ("scsi%d : DMA FIFO not empty\n", host->host_no);
3238 #if 0
3239 if (NCR53c7x0_read8 (CTEST2_REG_800) & CTEST2_800_DDIR) {
3240 NCR53c7x0_write8 (CTEST3_REG_800, CTEST3_800_FLF);
3241 mb();
3242 while (!((hostdata->dstat = NCR53c7x0_read8(DSTAT_REG)) &
3243 DSTAT_DFE));
3244 } else
3245 #endif
3246 {
3247 NCR53c7x0_write8 (CTEST3_REG_800, CTEST3_800_CLF);
3248 mb();
3249 while (NCR53c7x0_read8 (CTEST3_REG_800) & CTEST3_800_CLF);
3250 }
3251 }
3252 #endif
3253 }
3254 } while (interrupted);
3255
3256
3257
3258 if (hostdata->intrs != -1)
3259 hostdata->intrs++;
3260 #if 0
3261 if (hostdata->intrs > 4) {
3262 printk("scsi%d : too many interrupts, halting", host->host_no);
3263 hostdata->idle = 1;
3264 hostdata->options |= OPTION_DEBUG_INIT_ONLY;
3265 panic("dying...\n");
3266 }
3267 #endif
3268
3269 if (!hostdata->idle && hostdata->state == STATE_HALTED) {
3270 if (!hostdata->dsp_changed) {
3271 hostdata->dsp = bus_to_virt(NCR53c7x0_read32(DSP_REG));
3272 }
3273
3274 #if 0
3275 printk("scsi%d : new dsp is 0x%p\n", host->host_no,
3276 hostdata->dsp);
3277 #endif
3278
3279 hostdata->state = STATE_RUNNING;
3280 NCR53c7x0_write32 (DSP_REG, virt_to_bus(hostdata->dsp));
3281 mb();
3282 }
3283 }
3284 } while (!done);
3285 }
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300 static int
3301 abort_connected (struct Scsi_Host *host) {
3302 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
3303 host->hostdata;
3304
3305 hostdata->dsp = hostdata->script + hostdata->E_initiator_abort /
3306 sizeof(u32);
3307 hostdata->dsp_changed = 1;
3308 printk ("scsi%d : DANGER : abort_connected() called \n",
3309 host->host_no);
3310
3311
3312
3313 return 0;
3314 }
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333 static void intr_phase_mismatch (struct Scsi_Host *host, struct NCR53c7x0_cmd
3334 *cmd) {
3335 NCR53c7x0_local_declare();
3336 u32 dbc_dcmd, *dsp, *dsp_next;
3337 unsigned char dcmd, sbcl;
3338 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
3339 host->hostdata;
3340 char *phase;
3341 NCR53c7x0_local_setup(host);
3342
3343 if (!cmd) {
3344 printk ("scsi%d : phase mismatch interrupt occurred with no current command.\n",
3345 host->host_no);
3346 abort_connected(host);
3347 return;
3348 }
3349
3350
3351
3352
3353
3354
3355 dsp_next = bus_to_virt(NCR53c7x0_read32(DSP_REG));
3356
3357
3358
3359
3360
3361
3362
3363 dbc_dcmd = NCR53c7x0_read32(DBC_REG);
3364 dcmd = (dbc_dcmd & 0xff000000) >> 24;
3365 dsp = dsp_next - NCR53c7x0_insn_size(dcmd);
3366
3367
3368
3369
3370
3371
3372
3373 sbcl = NCR53c7x0_read8(SBCL_REG);
3374 switch (sbcl) {
3375 case SBCL_PHASE_DATAIN:
3376 phase = "DATAIN";
3377 break;
3378 case SBCL_PHASE_DATAOUT:
3379 phase = "DATAOUT";
3380 break;
3381 case SBCL_PHASE_MSGIN:
3382 phase = "MSGIN";
3383 break;
3384 case SBCL_PHASE_MSGOUT:
3385 phase = "MSGOUT";
3386 break;
3387 case SBCL_PHASE_CMDOUT:
3388 phase = "CMDOUT";
3389 break;
3390 case SBCL_PHASE_STATIN:
3391 phase = "STATUSIN";
3392 break;
3393 default:
3394 phase = "unknown";
3395 break;
3396 }
3397
3398
3399
3400
3401
3402
3403
3404 if (dsp >= cmd->data_transfer_start && dsp < cmd->data_transfer_end) {
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414 switch (sbcl & SBCL_PHASE_MASK) {
3415
3416
3417
3418
3419 case SBCL_PHASE_STATIN:
3420 if (hostdata->options & OPTION_DEBUG_INTR)
3421 printk ("scsi%d : new phase = STATIN\n", host->host_no);
3422 hostdata->dsp = hostdata->script + hostdata->E_command_complete /
3423 sizeof(u32);
3424 hostdata->dsp_changed = 1;
3425 return;
3426
3427
3428
3429
3430
3431
3432
3433 case SBCL_PHASE_MSGIN:
3434 if (hostdata->options & OPTION_DEBUG_INTR)
3435 printk ("scsi%d : new phase = MSGIN\n", host->host_no);
3436 if ((dcmd & (DCMD_TYPE_MASK|DCMD_BMI_OP_MASK|DCMD_BMI_INDIRECT|
3437 DCMD_BMI_MSG|DCMD_BMI_CD)) == (DCMD_TYPE_BMI|
3438 DCMD_BMI_OP_MOVE_I)) {
3439 dsp[0] = dbc_dcmd;
3440 dsp[1] = NCR53c7x0_read32(DNAD_REG);
3441 NCR53c7x0_write32(TEMP_REG, virt_to_bus(dsp));
3442 mb();
3443 hostdata->dsp = hostdata->script + hostdata->E_msg_in /
3444 sizeof(u32);
3445 hostdata->dsp_changed = 1;
3446 } else {
3447 printk("scsi%d : unexpected MSGIN in dynamic NCR code, dcmd=0x%x.\n",
3448 host->host_no, dcmd);
3449 print_insn (host, dsp, "", 1);
3450 print_insn (host, dsp_next, "", 1);
3451 abort_connected (host);
3452 }
3453 return;
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464 default:
3465 printk ("scsi%d : unexpected phase %s in data routine\n",
3466 host->host_no, phase);
3467 abort_connected(host);
3468 }
3469
3470
3471
3472 } else {
3473 printk ("scsi%d : unexpected phase %s at dsp = 0x%p\n",
3474 host->host_no, phase, dsp);
3475 print_insn (host, dsp, "", 1);
3476 print_insn (host, dsp_next, "", 1);
3477 abort_connected(host);
3478 }
3479 }
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492 static void intr_dma (struct Scsi_Host *host, struct NCR53c7x0_cmd *cmd) {
3493 NCR53c7x0_local_declare();
3494 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
3495 host->hostdata;
3496 unsigned char dstat;
3497 u32 *dsp,
3498 *next_dsp,
3499 *dsa,
3500 dbc_dcmd;
3501 int tmp;
3502 unsigned long flags;
3503 NCR53c7x0_local_setup(host);
3504
3505 if (!hostdata->dstat_valid) {
3506 hostdata->dstat = NCR53c7x0_read8(DSTAT_REG);
3507 hostdata->dstat_valid = 1;
3508 }
3509
3510 dstat = hostdata->dstat;
3511
3512 if (hostdata->options & OPTION_DEBUG_INTR)
3513 printk("scsi%d : DSTAT=0x%x\n", host->host_no, (int) dstat);
3514
3515 dbc_dcmd = NCR53c7x0_read32 (DBC_REG);
3516 next_dsp = bus_to_virt(NCR53c7x0_read32(DSP_REG));
3517 dsp = next_dsp - NCR53c7x0_insn_size ((dbc_dcmd >> 24) & 0xff);
3518
3519 dsa = bus_to_virt(NCR53c7x0_read32(DSA_REG));
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532 if (dstat & DSTAT_ABRT) {
3533 #if 0
3534
3535 if ((hostdata->options & OPTION_700) && (hostdata->state ==
3536 STATE_ABORTING) {
3537 } else
3538 #endif
3539 {
3540 printk("scsi%d : unexpected abort interrupt at\n"
3541 " ", host->host_no);
3542 print_insn (host, dsp, "s ", 1);
3543 panic(" ");
3544 }
3545 }
3546
3547
3548
3549
3550
3551
3552 if (dstat & DSTAT_SSI) {
3553 if (hostdata->options & OPTION_DEBUG_TRACE) {
3554 } else if (hostdata->options & OPTION_DEBUG_SINGLE) {
3555 print_insn (host, dsp, "s ", 0);
3556 save_flags(flags);
3557 cli();
3558
3559
3560 NCR53c7x0_write8 (DCNTL_REG, (NCR53c7x0_read8(DCNTL_REG) &
3561 ~DCNTL_SSM) | DCNTL_STD);
3562 mb();
3563 restore_flags(flags);
3564 } else {
3565 printk("scsi%d : unexpected single step interrupt at\n"
3566 " ", host->host_no);
3567 print_insn (host, dsp, "", 1);
3568 panic(" mail drew@colorad.edu\n");
3569 }
3570 }
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582 if (dstat & DSTAT_OPC) {
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595 if (((dsp >= (hostdata->script + hostdata->E_select / sizeof(u32))) &&
3596 (dsp <= (hostdata->script + hostdata->E_select_msgout /
3597 sizeof(u32) + 8))) || (hostdata->test_running == 2)) {
3598 if (hostdata->options & OPTION_DEBUG_INTR)
3599 printk ("scsi%d : ignoring DSTAT_IID for SSTAT_STO\n",
3600 host->host_no);
3601 if (hostdata->expecting_iid) {
3602 hostdata->expecting_iid = 0;
3603 hostdata->idle = 1;
3604 if (hostdata->test_running == 2) {
3605 hostdata->test_running = 0;
3606 hostdata->test_completed = 3;
3607 } else if (cmd)
3608 abnormal_finished (cmd, DID_BAD_TARGET << 16);
3609 } else {
3610 hostdata->expecting_sto = 1;
3611 }
3612 } else {
3613 printk("scsi%d : illegal instruction ", host->host_no);
3614 print_insn (host, dsp, "", 1);
3615 printk("scsi%d : DSP=0x%p, DCMD|DBC=0x%x, DSA=0x%p\n"
3616 " DSPS=0x%x, TEMP=0x%x, DMODE=0x%x,\n"
3617 " DNAD=0x%x\n",
3618 host->host_no, dsp, dbc_dcmd,
3619 dsa, NCR53c7x0_read32(DSPS_REG),
3620 NCR53c7x0_read32(TEMP_REG), NCR53c7x0_read8(hostdata->dmode),
3621 NCR53c7x0_read32(DNAD_REG));
3622 panic(" mail drew@Colorado.EDU\n");
3623 }
3624 }
3625
3626
3627
3628
3629
3630
3631 if (dstat & DSTAT_800_BF) {
3632 printk("scsi%d : BUS FAULT, DSP=0x%p, DCMD|DBC=0x%x, DSA=0x%p\n"
3633 " DSPS=0x%x, TEMP=0x%x, DMODE=0x%x\n",
3634 host->host_no, dsp, NCR53c7x0_read32(DBC_REG),
3635 dsa, NCR53c7x0_read32(DSPS_REG),
3636 NCR53c7x0_read32(TEMP_REG), NCR53c7x0_read8(hostdata->dmode));
3637 print_dsa (host, dsa);
3638 printk("scsi%d : DSP->\n", host->host_no);
3639 print_insn(host, dsp, "", 1);
3640 print_insn(host, next_dsp, "", 1);
3641 #if 0
3642 panic(" mail drew@Colorado.EDU\n");
3643 #else
3644 hostdata->idle = 1;
3645 hostdata->options |= OPTION_DEBUG_INIT_ONLY;
3646 #endif
3647 }
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658 if (dstat & DSTAT_SIR) {
3659 if (hostdata->options & OPTION_DEBUG_INTR)
3660 printk ("scsi%d : DSTAT_SIR\n", host->host_no);
3661 switch ((tmp = hostdata->dstat_sir_intr (host, cmd))) {
3662 case SPECIFIC_INT_NOTHING:
3663 case SPECIFIC_INT_RESTART:
3664 break;
3665 case SPECIFIC_INT_ABORT:
3666 abort_connected(host);
3667 break;
3668 case SPECIFIC_INT_PANIC:
3669 printk("scsi%d : failure at ", host->host_no);
3670 print_insn (host, dsp, "", 1);
3671 panic(" dstat_sir_intr() returned SPECIFIC_INT_PANIC\n");
3672 break;
3673 case SPECIFIC_INT_BREAK:
3674 intr_break (host, cmd);
3675 break;
3676 default:
3677 printk("scsi%d : failure at ", host->host_no);
3678 print_insn (host, dsp, "", 1);
3679 panic(" dstat_sir_intr() returned unknown value %d\n",
3680 tmp);
3681 }
3682 }
3683
3684
3685 NCR53c7x0_write8 (STEST3_REG_800, STEST3_800_CSF);
3686 mb();
3687 while (NCR53c7x0_read8 (STEST3_REG_800) & STEST3_800_CSF);
3688 }
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707 static int print_insn (struct Scsi_Host *host, u32 *insn,
3708 char *prefix, int kernel) {
3709 char buf[80],
3710 *tmp;
3711 unsigned char dcmd;
3712 int size;
3713
3714 dcmd = (insn[0] >> 24) & 0xff;
3715 sprintf(buf, "%s%p : 0x%08x 0x%08x", (prefix ? prefix : ""),
3716 insn, insn[0], insn[1]);
3717 tmp = buf + strlen(buf);
3718 if ((dcmd & DCMD_TYPE_MASK) == DCMD_TYPE_MMI) {
3719 sprintf (tmp, " 0x%08x\n", insn[2]);
3720 size = 3;
3721 } else {
3722 sprintf (tmp, "\n");
3723 size = 2;
3724 }
3725
3726 if (kernel)
3727 printk ("%s", buf);
3728 #ifdef NCR_DEBUG
3729 else {
3730 size_t len = strlen(buf);
3731 debugger_kernel_write(host, buf, len);
3732 }
3733 #endif
3734 return size;
3735 }
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749 int NCR53c7xx_abort (Scsi_Cmnd *cmd) {
3750 struct Scsi_Host *host = cmd->host;
3751 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
3752 host->hostdata;
3753 unsigned long flags;
3754 volatile struct NCR53c7x0_cmd *curr, **prev;
3755 save_flags(flags);
3756 cli();
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768 for (curr = (volatile struct NCR53c7x0_cmd *) hostdata->issue_queue,
3769 prev = (volatile struct NCR53c7x0_cmd **) &(hostdata->issue_queue);
3770 curr && curr->cmd != cmd; prev = (volatile struct NCR53c7x0_cmd **)
3771 &(curr->next), curr = (volatile struct NCR53c7x0_cmd *) curr->next);
3772
3773 if (curr) {
3774 *prev = (struct NCR53c7x0_cmd *) curr->next;
3775
3776 if (curr->prev)
3777 curr->prev->next = curr->next;
3778
3779 curr->next = hostdata->free;
3780 hostdata->free = curr;
3781
3782 cmd->result = 0;
3783 cmd->scsi_done(cmd);
3784 restore_flags(flags);
3785 return SCSI_ABORT_SUCCESS;
3786 }
3787
3788
3789
3790
3791
3792
3793 for (curr = (volatile struct NCR53c7x0_cmd *) hostdata->running_list,
3794 prev = (volatile struct NCR53c7x0_cmd **) &(hostdata->running_list);
3795 curr && curr->cmd != cmd; prev = (volatile struct NCR53c7x0_cmd **)
3796 &(curr->next), curr = (volatile struct NCR53c7x0_cmd *) curr->next);
3797
3798 if (curr) {
3799 restore_flags(flags);
3800 printk ("scsi%d : DANGER : command in running list, can not abort.\n",
3801 cmd->host->host_no);
3802 return SCSI_ABORT_SNOOZE;
3803 }
3804
3805
3806
3807
3808
3809
3810
3811 curr = (struct NCR53c7x0_cmd *) cmd->host_scribble;
3812 curr->next = hostdata->free;
3813 hostdata->free = curr;
3814
3815 if (((cmd->result & 0xff00) == 0xff00) ||
3816 ((cmd->result & 0xff) == 0xff)) {
3817 printk ("scsi%d : did this command ever run?\n", host->host_no);
3818 } else {
3819 printk ("scsi%d : probably lost INTFLY, normal completion\n",
3820 host->host_no);
3821 }
3822 cmd->scsi_done(cmd);
3823 restore_flags(flags);
3824 return SCSI_ABORT_SNOOZE;
3825 }
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838 int
3839 NCR53c7xx_reset (Scsi_Cmnd *cmd) {
3840 NCR53c7x0_local_declare();
3841 unsigned long flags;
3842 int found;
3843 struct NCR53c7x0_cmd * c;
3844 Scsi_Cmnd *tmp;
3845 struct Scsi_Host *host = cmd->host;
3846 struct NCR53c7x0_hostdata *hostdata = host ?
3847 (struct NCR53c7x0_hostdata *) host->hostdata : NULL;
3848 NCR53c7x0_local_setup(host);
3849
3850 save_flags(flags);
3851 ncr_halt (host);
3852 NCR53c7x0_write8(SCNTL1_REG, SCNTL1_RST);
3853 udelay(25);
3854 NCR53c7x0_write8(SCNTL1_REG, SCNTL1_RST);
3855 for (c = (struct NCR53c7x0_cmd *) hostdata->running_list, found = 0; c;
3856 c = (struct NCR53c7x0_cmd *) c->next) {
3857 tmp = c->cmd;
3858 c->next = hostdata->free;
3859 hostdata->free = c;
3860
3861 if (tmp == cmd)
3862 found = 1;
3863 tmp->result = DID_RESET << 16;
3864 tmp->scsi_done(tmp);
3865 }
3866 if (!found) {
3867 c = (struct NCR53c7x0_cmd *) cmd->host_scribble;
3868 if (c) {
3869 c->next = hostdata->free;
3870 hostdata->free = c;
3871 }
3872 cmd->result = DID_RESET << 16;
3873 cmd->scsi_done(cmd);
3874 }
3875 restore_flags(flags);
3876 return SCSI_RESET_SUCCESS;
3877 }
3878
3879
3880
3881
3882
3883
3884 static void print_dsa (struct Scsi_Host *host, u32 *dsa) {
3885 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
3886 host->hostdata;
3887 int i, len;
3888 char *ptr;
3889
3890 printk("scsi%d : dsa at 0x%p\n"
3891 " + %d : dsa_msgout length = %d, data = 0x%x\n" ,
3892 host->host_no, dsa, hostdata->dsa_msgout,
3893 dsa[hostdata->dsa_msgout / sizeof(u32)],
3894 dsa[hostdata->dsa_msgout / sizeof(u32) + 1]);
3895
3896 for (i = dsa[hostdata->dsa_msgout / sizeof(u32)],
3897 ptr = bus_to_virt(dsa[hostdata->dsa_msgout / sizeof(u32) + 1]); i > 0;
3898 ptr += len, i -= len) {
3899 printk(" ");
3900 len = print_msg (ptr);
3901 printk("\n");
3902 }
3903 }
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914 #ifdef MODULE
3915 static int
3916 shutdown (struct Scsi_Host *host) {
3917 NCR53c7x0_local_declare();
3918 unsigned long flags;
3919 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
3920 host->hostdata;
3921 NCR53c7x0_local_setup(host);
3922 save_flags (flags);
3923 cli();
3924 ncr_halt (host);
3925 hostdata->soft_reset(host);
3926
3927
3928
3929
3930
3931
3932
3933 NCR53c7x0_write8(SCNTL1_REG, SCNTL1_RST);
3934 udelay(25);
3935 NCR53c7x0_write8(SCNTL1_REG, SCNTL1_RST);
3936 restore_flags (flags);
3937 return 0;
3938 }
3939 #endif
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952 static int
3953 ncr_halt (struct Scsi_Host *host) {
3954 NCR53c7x0_local_declare();
3955 unsigned long flags;
3956 unsigned char istat, tmp;
3957 struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
3958 host->hostdata;
3959 NCR53c7x0_local_setup(host);
3960
3961 save_flags(flags);
3962 cli();
3963 NCR53c7x0_write8(hostdata->istat, ISTAT_ABRT);
3964
3965 for (;;) {
3966 istat = NCR53c7x0_read8 (hostdata->istat);
3967 if (istat & ISTAT_SIP) {
3968 if ((hostdata->chip / 100) == 8) {
3969 tmp = NCR53c7x0_read8(SIST0_REG_800);
3970 udelay(1);
3971 tmp = NCR53c7x0_read8(SIST1_REG_800);
3972 } else {
3973 tmp = NCR53c7x0_read8(SSTAT0_REG);
3974 }
3975 } else if (istat & ISTAT_DIP) {
3976 NCR53c7x0_write8(hostdata->istat, 0);
3977 tmp = NCR53c7x0_read8(DSTAT_REG);
3978 if (tmp & DSTAT_ABRT)
3979 break;
3980 else
3981 panic("scsi%d: could not halt NCR chip\n", host->host_no);
3982 }
3983 }
3984 hostdata->state = STATE_HALTED;
3985 restore_flags(flags);
3986 return 0;
3987 }
3988
3989 #ifdef MODULE
3990 int NCR53c7x0_release(struct Scsi_Host *host) {
3991 shutdown (host);
3992
3993 if (host->irq != IRQ_NONE)
3994 {
3995 int irq_count;
3996 struct Scsi_Host *tmp;
3997 for (irq_count = 0, tmp = first_host; tmp; tmp = tmp->next)
3998 if (tmp->hostt == the_template && tmp->irq == host->irq)
3999 ++irq_count;
4000 if (irq_count == 1)
4001 free_irq(host->irq);
4002 }
4003 if (host->dma_channel != DMA_NONE)
4004 free_dma(host->dma_channel);
4005 return 1;
4006 }
4007 Scsi_Host_Template driver_template = NCR53c7xx;
4008 #include "scsi_module.c"
4009 #endif