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