1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480#include <linux/string.h>
481#include <linux/kernel.h>
482#include <linux/ioport.h>
483#include <linux/delay.h>
484#include <linux/proc_fs.h>
485#include <linux/blkdev.h>
486#include <linux/interrupt.h>
487#include <linux/stat.h>
488#include <linux/pci.h>
489#include <linux/init.h>
490#include <linux/ctype.h>
491#include <linux/spinlock.h>
492#include <linux/dma-mapping.h>
493#include <asm/byteorder.h>
494#include <asm/dma.h>
495#include <asm/io.h>
496#include <asm/irq.h>
497
498#include <scsi/scsi.h>
499#include <scsi/scsi_cmnd.h>
500#include <scsi/scsi_device.h>
501#include <scsi/scsi_host.h>
502#include <scsi/scsi_tcq.h>
503#include <scsi/scsicam.h>
504
505static int eata2x_detect(struct scsi_host_template *);
506static int eata2x_release(struct Scsi_Host *);
507static int eata2x_queuecommand(struct scsi_cmnd *,
508 void (*done) (struct scsi_cmnd *));
509static int eata2x_eh_abort(struct scsi_cmnd *);
510static int eata2x_eh_host_reset(struct scsi_cmnd *);
511static int eata2x_bios_param(struct scsi_device *, struct block_device *,
512 sector_t, int *);
513static int eata2x_slave_configure(struct scsi_device *);
514
515static struct scsi_host_template driver_template = {
516 .name = "EATA/DMA 2.0x rev. 8.10.00 ",
517 .detect = eata2x_detect,
518 .release = eata2x_release,
519 .queuecommand = eata2x_queuecommand,
520 .eh_abort_handler = eata2x_eh_abort,
521 .eh_host_reset_handler = eata2x_eh_host_reset,
522 .bios_param = eata2x_bios_param,
523 .slave_configure = eata2x_slave_configure,
524 .this_id = 7,
525 .unchecked_isa_dma = 1,
526 .use_clustering = ENABLE_CLUSTERING,
527};
528
529#if !defined(__BIG_ENDIAN_BITFIELD) && !defined(__LITTLE_ENDIAN_BITFIELD)
530#error "Adjust your <asm/byteorder.h> defines"
531#endif
532
533
534#define ISA 0
535#define ESA 1
536
537#undef FORCE_CONFIG
538
539#undef DEBUG_LINKED_COMMANDS
540#undef DEBUG_DETECT
541#undef DEBUG_PCI_DETECT
542#undef DEBUG_INTERRUPT
543#undef DEBUG_RESET
544#undef DEBUG_GENERATE_ERRORS
545#undef DEBUG_GENERATE_ABORTS
546#undef DEBUG_GEOMETRY
547
548#define MAX_ISA 4
549#define MAX_VESA 0
550#define MAX_EISA 15
551#define MAX_PCI 16
552#define MAX_BOARDS (MAX_ISA + MAX_VESA + MAX_EISA + MAX_PCI)
553#define MAX_CHANNEL 4
554#define MAX_LUN 32
555#define MAX_TARGET 32
556#define MAX_MAILBOXES 64
557#define MAX_SGLIST 64
558#define MAX_LARGE_SGLIST 122
559#define MAX_INTERNAL_RETRIES 64
560#define MAX_CMD_PER_LUN 2
561#define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES - MAX_CMD_PER_LUN)
562
563#define SKIP ULONG_MAX
564#define FREE 0
565#define IN_USE 1
566#define LOCKED 2
567#define IN_RESET 3
568#define IGNORE 4
569#define READY 5
570#define ABORTING 6
571#define NO_DMA 0xff
572#define MAXLOOP 10000
573#define TAG_DISABLED 0
574#define TAG_SIMPLE 1
575#define TAG_ORDERED 2
576
577#define REG_CMD 7
578#define REG_STATUS 7
579#define REG_AUX_STATUS 8
580#define REG_DATA 0
581#define REG_DATA2 1
582#define REG_SEE 6
583#define REG_LOW 2
584#define REG_LM 3
585#define REG_MID 4
586#define REG_MSB 5
587#define REGION_SIZE 9UL
588#define MAX_ISA_ADDR 0x03ff
589#define MIN_EISA_ADDR 0x1c88
590#define MAX_EISA_ADDR 0xfc88
591#define BSY_ASSERTED 0x80
592#define DRQ_ASSERTED 0x08
593#define ABSY_ASSERTED 0x01
594#define IRQ_ASSERTED 0x02
595#define READ_CONFIG_PIO 0xf0
596#define SET_CONFIG_PIO 0xf1
597#define SEND_CP_PIO 0xf2
598#define RECEIVE_SP_PIO 0xf3
599#define TRUNCATE_XFR_PIO 0xf4
600#define RESET_PIO 0xf9
601#define READ_CONFIG_DMA 0xfd
602#define SET_CONFIG_DMA 0xfe
603#define SEND_CP_DMA 0xff
604#define ASOK 0x00
605#define ASST 0x01
606
607#define YESNO(a) ((a) ? 'y' : 'n')
608#define TLDEV(type) ((type) == TYPE_DISK || (type) == TYPE_ROM)
609
610
611#define EATA_SIG_BE 0x45415441
612
613
614#define EATA_2_0A_SIZE 28
615#define EATA_2_0B_SIZE 30
616#define EATA_2_0C_SIZE 34
617
618
619struct eata_info {
620 u_int32_t data_len;
621 u_int32_t sign;
622
623#if defined(__BIG_ENDIAN_BITFIELD)
624 unchar version : 4,
625 : 4;
626 unchar haaval : 1,
627 ata : 1,
628 drqvld : 1,
629 dmasup : 1,
630 morsup : 1,
631 trnxfr : 1,
632 tarsup : 1,
633 ocsena : 1;
634#else
635 unchar : 4,
636 version : 4;
637 unchar ocsena : 1,
638 tarsup : 1,
639 trnxfr : 1,
640 morsup : 1,
641 dmasup : 1,
642 drqvld : 1,
643 ata : 1,
644 haaval : 1;
645#endif
646
647 ushort cp_pad_len;
648 unchar host_addr[4];
649 u_int32_t cp_len;
650 u_int32_t sp_len;
651 ushort queue_size;
652 ushort unused;
653 ushort scatt_size;
654
655#if defined(__BIG_ENDIAN_BITFIELD)
656 unchar drqx : 2,
657 second : 1,
658 irq_tr : 1,
659 irq : 4;
660 unchar sync;
661 unchar : 4,
662 res1 : 1,
663 large_sg : 1,
664 forcaddr : 1,
665 isaena : 1;
666 unchar max_chan : 3,
667 max_id : 5;
668 unchar max_lun;
669 unchar eisa : 1,
670 pci : 1,
671 idquest : 1,
672 m1 : 1,
673 : 4;
674#else
675 unchar irq : 4,
676 irq_tr : 1,
677 second : 1,
678 drqx : 2;
679 unchar sync;
680
681
682 unchar isaena : 1,
683 forcaddr : 1,
684 large_sg : 1,
685 res1 : 1,
686 : 4;
687 unchar max_id : 5,
688 max_chan : 3;
689
690
691 unchar max_lun;
692 unchar
693 : 4,
694 m1 : 1,
695 idquest : 1,
696 pci : 1,
697 eisa : 1;
698#endif
699
700 unchar raidnum;
701 unchar notused;
702
703 ushort ipad[247];
704};
705
706
707struct eata_config {
708 ushort len;
709
710#if defined(__BIG_ENDIAN_BITFIELD)
711 unchar : 4,
712 tarena : 1,
713 mdpena : 1,
714 ocena : 1,
715 edis : 1;
716#else
717 unchar edis : 1,
718 ocena : 1,
719 mdpena : 1,
720 tarena : 1,
721 : 4;
722#endif
723 unchar cpad[511];
724};
725
726
727struct mssp {
728#if defined(__BIG_ENDIAN_BITFIELD)
729 unchar eoc : 1,
730 adapter_status : 7;
731#else
732 unchar adapter_status : 7,
733 eoc : 1;
734#endif
735 unchar target_status;
736 unchar unused[2];
737 u_int32_t inv_res_len;
738 u_int32_t cpp_index;
739 char mess[12];
740};
741
742struct sg_list {
743 unsigned int address;
744 unsigned int num_bytes;
745};
746
747
748struct mscp {
749#if defined(__BIG_ENDIAN_BITFIELD)
750 unchar din : 1,
751 dout : 1,
752 interp : 1,
753 : 1,
754 sg : 1,
755 reqsen :1,
756 init : 1,
757 sreset : 1;
758 unchar sense_len;
759 unchar unused[3];
760 unchar : 7,
761 fwnest : 1;
762 unchar : 5,
763 hbaci : 1,
764 iat : 1,
765 phsunit : 1;
766 unchar channel : 3,
767 target : 5;
768 unchar one : 1,
769 dispri : 1,
770 luntar : 1,
771 lun : 5;
772#else
773 unchar sreset :1,
774 init :1,
775 reqsen :1,
776 sg :1,
777 :1,
778 interp :1,
779 dout :1,
780 din :1;
781 unchar sense_len;
782 unchar unused[3];
783 unchar fwnest : 1,
784 : 7;
785 unchar phsunit : 1,
786 iat : 1,
787 hbaci : 1,
788 : 5;
789 unchar target : 5,
790 channel : 3;
791 unchar lun : 5,
792 luntar : 1,
793 dispri : 1,
794 one : 1;
795#endif
796
797 unchar mess[3];
798 unchar cdb[12];
799 u_int32_t data_len;
800 u_int32_t cpp_index;
801 u_int32_t data_address;
802 u_int32_t sp_dma_addr;
803 u_int32_t sense_addr;
804
805
806 struct scsi_cmnd *SCpnt;
807
808
809
810 dma_addr_t cp_dma_addr;
811 struct sg_list *sglist;
812};
813
814#define CP_TAIL_SIZE (sizeof(struct sglist *) + sizeof(dma_addr_t))
815
816struct hostdata {
817 struct mscp cp[MAX_MAILBOXES];
818 unsigned int cp_stat[MAX_MAILBOXES];
819 unsigned int last_cp_used;
820 unsigned int iocount;
821 int board_number;
822 char board_name[16];
823 int in_reset;
824 int target_to[MAX_TARGET][MAX_CHANNEL];
825 int target_redo[MAX_TARGET][MAX_CHANNEL];
826 unsigned int retries;
827 unsigned long last_retried_pid;
828 unsigned char subversion;
829 unsigned char protocol_rev;
830 unsigned char is_pci;
831 struct pci_dev *pdev;
832 struct mssp *sp_cpu_addr;
833 dma_addr_t sp_dma_addr;
834 struct mssp sp;
835};
836
837static struct Scsi_Host *sh[MAX_BOARDS];
838static const char *driver_name = "EATA";
839static char sha[MAX_BOARDS];
840static DEFINE_SPINLOCK(driver_lock);
841
842
843static unsigned int num_boards = MAX_BOARDS;
844
845static unsigned long io_port[] = {
846
847
848 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
849 SKIP, SKIP,
850
851
852 0x1f0,
853
854
855 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
856 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
857
858
859 0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88, 0x6c88, 0x7c88, 0x8c88,
860 0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88, 0xec88, 0xfc88,
861
862
863 0x170, 0x230, 0x330,
864
865
866 0x0
867};
868
869
870#define H2DEV(x) cpu_to_be32(x)
871#define DEV2H(x) be32_to_cpu(x)
872#define H2DEV16(x) cpu_to_be16(x)
873#define DEV2H16(x) be16_to_cpu(x)
874
875
876#define REG2H(x) le16_to_cpu(x)
877
878static irqreturn_t do_interrupt_handler(int, void *);
879static void flush_dev(struct scsi_device *, unsigned long, struct hostdata *,
880 unsigned int);
881static int do_trace = 0;
882static int setup_done = 0;
883static int link_statistics;
884static int ext_tran = 0;
885static int rev_scan = 1;
886
887#if defined(CONFIG_SCSI_EATA_TAGGED_QUEUE)
888static int tag_mode = TAG_SIMPLE;
889#else
890static int tag_mode = TAG_DISABLED;
891#endif
892
893#if defined(CONFIG_SCSI_EATA_LINKED_COMMANDS)
894static int linked_comm = 1;
895#else
896static int linked_comm = 0;
897#endif
898
899#if defined(CONFIG_SCSI_EATA_MAX_TAGS)
900static int max_queue_depth = CONFIG_SCSI_EATA_MAX_TAGS;
901#else
902static int max_queue_depth = MAX_CMD_PER_LUN;
903#endif
904
905#if defined(CONFIG_ISA)
906static int isa_probe = 1;
907#else
908static int isa_probe = 0;
909#endif
910
911#if defined(CONFIG_EISA)
912static int eisa_probe = 1;
913#else
914static int eisa_probe = 0;
915#endif
916
917#if defined(CONFIG_PCI)
918static int pci_probe = 1;
919#else
920static int pci_probe = 0;
921#endif
922
923#define MAX_INT_PARAM 10
924#define MAX_BOOT_OPTIONS_SIZE 256
925static char boot_options[MAX_BOOT_OPTIONS_SIZE];
926
927#if defined(MODULE)
928#include <linux/module.h>
929#include <linux/moduleparam.h>
930
931module_param_string(eata, boot_options, MAX_BOOT_OPTIONS_SIZE, 0);
932MODULE_PARM_DESC(eata, " equivalent to the \"eata=...\" kernel boot option."
933 " Example: modprobe eata \"eata=0x7410,0x230,lc:y,tm:0,mq:4,ep:n\"");
934MODULE_AUTHOR("Dario Ballabio");
935MODULE_LICENSE("GPL");
936MODULE_DESCRIPTION("EATA/DMA SCSI Driver");
937
938#endif
939
940static int eata2x_slave_configure(struct scsi_device *dev)
941{
942 int tqd, utqd;
943 char *tag_suffix, *link_suffix;
944
945 utqd = MAX_CMD_PER_LUN;
946 tqd = max_queue_depth;
947
948 if (TLDEV(dev->type) && dev->tagged_supported) {
949 if (tag_mode == TAG_SIMPLE) {
950 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, tqd);
951 tag_suffix = ", simple tags";
952 } else if (tag_mode == TAG_ORDERED) {
953 scsi_adjust_queue_depth(dev, MSG_ORDERED_TAG, tqd);
954 tag_suffix = ", ordered tags";
955 } else {
956 scsi_adjust_queue_depth(dev, 0, tqd);
957 tag_suffix = ", no tags";
958 }
959 } else if (TLDEV(dev->type) && linked_comm) {
960 scsi_adjust_queue_depth(dev, 0, tqd);
961 tag_suffix = ", untagged";
962 } else {
963 scsi_adjust_queue_depth(dev, 0, utqd);
964 tag_suffix = "";
965 }
966
967 if (TLDEV(dev->type) && linked_comm && dev->queue_depth > 2)
968 link_suffix = ", sorted";
969 else if (TLDEV(dev->type))
970 link_suffix = ", unsorted";
971 else
972 link_suffix = "";
973
974 sdev_printk(KERN_INFO, dev,
975 "cmds/lun %d%s%s.\n",
976 dev->queue_depth, link_suffix, tag_suffix);
977
978 return 0;
979}
980
981static int wait_on_busy(unsigned long iobase, unsigned int loop)
982{
983 while (inb(iobase + REG_AUX_STATUS) & ABSY_ASSERTED) {
984 udelay(1L);
985 if (--loop == 0)
986 return 1;
987 }
988 return 0;
989}
990
991static int do_dma(unsigned long iobase, unsigned long addr, unchar cmd)
992{
993 unsigned char *byaddr;
994 unsigned long devaddr;
995
996 if (wait_on_busy(iobase, (addr ? MAXLOOP * 100 : MAXLOOP)))
997 return 1;
998
999 if (addr) {
1000 devaddr = H2DEV(addr);
1001 byaddr = (unsigned char *)&devaddr;
1002 outb(byaddr[3], iobase + REG_LOW);
1003 outb(byaddr[2], iobase + REG_LM);
1004 outb(byaddr[1], iobase + REG_MID);
1005 outb(byaddr[0], iobase + REG_MSB);
1006 }
1007
1008 outb(cmd, iobase + REG_CMD);
1009 return 0;
1010}
1011
1012static int read_pio(unsigned long iobase, ushort * start, ushort * end)
1013{
1014 unsigned int loop = MAXLOOP;
1015 ushort *p;
1016
1017 for (p = start; p <= end; p++) {
1018 while (!(inb(iobase + REG_STATUS) & DRQ_ASSERTED)) {
1019 udelay(1L);
1020 if (--loop == 0)
1021 return 1;
1022 }
1023 loop = MAXLOOP;
1024 *p = REG2H(inw(iobase));
1025 }
1026
1027 return 0;
1028}
1029
1030static struct pci_dev *get_pci_dev(unsigned long port_base)
1031{
1032#if defined(CONFIG_PCI)
1033 unsigned int addr;
1034 struct pci_dev *dev = NULL;
1035
1036 while ((dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {
1037 addr = pci_resource_start(dev, 0);
1038
1039#if defined(DEBUG_PCI_DETECT)
1040 printk("%s: get_pci_dev, bus %d, devfn 0x%x, addr 0x%x.\n",
1041 driver_name, dev->bus->number, dev->devfn, addr);
1042#endif
1043
1044
1045
1046
1047
1048 pci_dev_put(dev);
1049 if (addr + PCI_BASE_ADDRESS_0 == port_base)
1050 return dev;
1051 }
1052#endif
1053 return NULL;
1054}
1055
1056static void enable_pci_ports(void)
1057{
1058#if defined(CONFIG_PCI)
1059 struct pci_dev *dev = NULL;
1060
1061 while ((dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {
1062#if defined(DEBUG_PCI_DETECT)
1063 printk("%s: enable_pci_ports, bus %d, devfn 0x%x.\n",
1064 driver_name, dev->bus->number, dev->devfn);
1065#endif
1066
1067 if (pci_enable_device(dev))
1068 printk
1069 ("%s: warning, pci_enable_device failed, bus %d devfn 0x%x.\n",
1070 driver_name, dev->bus->number, dev->devfn);
1071 }
1072
1073#endif
1074}
1075
1076static int port_detect(unsigned long port_base, unsigned int j,
1077 struct scsi_host_template *tpnt)
1078{
1079 unsigned char irq, dma_channel, subversion, i, is_pci = 0;
1080 unsigned char protocol_rev;
1081 struct eata_info info;
1082 char *bus_type, dma_name[16];
1083 struct pci_dev *pdev;
1084
1085 unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
1086 struct Scsi_Host *shost;
1087 struct hostdata *ha;
1088 char name[16];
1089
1090 sprintf(name, "%s%d", driver_name, j);
1091
1092 if (!request_region(port_base, REGION_SIZE, driver_name)) {
1093#if defined(DEBUG_DETECT)
1094 printk("%s: address 0x%03lx in use, skipping probe.\n", name,
1095 port_base);
1096#endif
1097 goto fail;
1098 }
1099
1100 spin_lock_irq(&driver_lock);
1101
1102 if (do_dma(port_base, 0, READ_CONFIG_PIO)) {
1103#if defined(DEBUG_DETECT)
1104 printk("%s: detect, do_dma failed at 0x%03lx.\n", name,
1105 port_base);
1106#endif
1107 goto freelock;
1108 }
1109
1110
1111 if (read_pio(port_base, (ushort *) & info, (ushort *) & info.ipad[0])) {
1112#if defined(DEBUG_DETECT)
1113 printk("%s: detect, read_pio failed at 0x%03lx.\n", name,
1114 port_base);
1115#endif
1116 goto freelock;
1117 }
1118
1119 info.data_len = DEV2H(info.data_len);
1120 info.sign = DEV2H(info.sign);
1121 info.cp_pad_len = DEV2H16(info.cp_pad_len);
1122 info.cp_len = DEV2H(info.cp_len);
1123 info.sp_len = DEV2H(info.sp_len);
1124 info.scatt_size = DEV2H16(info.scatt_size);
1125 info.queue_size = DEV2H16(info.queue_size);
1126
1127
1128 if (info.sign != EATA_SIG_BE) {
1129#if defined(DEBUG_DETECT)
1130 printk("%s: signature 0x%04x discarded.\n", name, info.sign);
1131#endif
1132 goto freelock;
1133 }
1134
1135 if (info.data_len < EATA_2_0A_SIZE) {
1136 printk
1137 ("%s: config structure size (%d bytes) too short, detaching.\n",
1138 name, info.data_len);
1139 goto freelock;
1140 } else if (info.data_len == EATA_2_0A_SIZE)
1141 protocol_rev = 'A';
1142 else if (info.data_len == EATA_2_0B_SIZE)
1143 protocol_rev = 'B';
1144 else
1145 protocol_rev = 'C';
1146
1147 if (protocol_rev != 'A' && info.forcaddr) {
1148 printk("%s: warning, port address has been forced.\n", name);
1149 bus_type = "PCI";
1150 is_pci = 1;
1151 subversion = ESA;
1152 } else if (port_base > MAX_EISA_ADDR
1153 || (protocol_rev == 'C' && info.pci)) {
1154 bus_type = "PCI";
1155 is_pci = 1;
1156 subversion = ESA;
1157 } else if (port_base >= MIN_EISA_ADDR
1158 || (protocol_rev == 'C' && info.eisa)) {
1159 bus_type = "EISA";
1160 subversion = ESA;
1161 } else if (protocol_rev == 'C' && !info.eisa && !info.pci) {
1162 bus_type = "ISA";
1163 subversion = ISA;
1164 } else if (port_base > MAX_ISA_ADDR) {
1165 bus_type = "PCI";
1166 is_pci = 1;
1167 subversion = ESA;
1168 } else {
1169 bus_type = "ISA";
1170 subversion = ISA;
1171 }
1172
1173 if (!info.haaval || info.ata) {
1174 printk
1175 ("%s: address 0x%03lx, unusable %s board (%d%d), detaching.\n",
1176 name, port_base, bus_type, info.haaval, info.ata);
1177 goto freelock;
1178 }
1179
1180 if (info.drqvld) {
1181 if (subversion == ESA)
1182 printk("%s: warning, weird %s board using DMA.\n", name,
1183 bus_type);
1184
1185 subversion = ISA;
1186 dma_channel = dma_channel_table[3 - info.drqx];
1187 } else {
1188 if (subversion == ISA)
1189 printk("%s: warning, weird %s board not using DMA.\n",
1190 name, bus_type);
1191
1192 subversion = ESA;
1193 dma_channel = NO_DMA;
1194 }
1195
1196 if (!info.dmasup)
1197 printk("%s: warning, DMA protocol support not asserted.\n",
1198 name);
1199
1200 irq = info.irq;
1201
1202 if (subversion == ESA && !info.irq_tr)
1203 printk
1204 ("%s: warning, LEVEL triggering is suggested for IRQ %u.\n",
1205 name, irq);
1206
1207 if (is_pci) {
1208 pdev = get_pci_dev(port_base);
1209 if (!pdev)
1210 printk
1211 ("%s: warning, failed to get pci_dev structure.\n",
1212 name);
1213 } else
1214 pdev = NULL;
1215
1216 if (pdev && (irq != pdev->irq)) {
1217 printk("%s: IRQ %u mapped to IO-APIC IRQ %u.\n", name, irq,
1218 pdev->irq);
1219 irq = pdev->irq;
1220 }
1221
1222
1223 if (request_irq(irq, do_interrupt_handler,
1224 IRQF_DISABLED | ((subversion == ESA) ? IRQF_SHARED : 0),
1225 driver_name, (void *)&sha[j])) {
1226 printk("%s: unable to allocate IRQ %u, detaching.\n", name,
1227 irq);
1228 goto freelock;
1229 }
1230
1231 if (subversion == ISA && request_dma(dma_channel, driver_name)) {
1232 printk("%s: unable to allocate DMA channel %u, detaching.\n",
1233 name, dma_channel);
1234 goto freeirq;
1235 }
1236#if defined(FORCE_CONFIG)
1237 {
1238 struct eata_config *cf;
1239 dma_addr_t cf_dma_addr;
1240
1241 cf = pci_alloc_consistent(pdev, sizeof(struct eata_config),
1242 &cf_dma_addr);
1243
1244 if (!cf) {
1245 printk
1246 ("%s: config, pci_alloc_consistent failed, detaching.\n",
1247 name);
1248 goto freedma;
1249 }
1250
1251
1252 memset((char *)cf, 0, sizeof(struct eata_config));
1253 cf->len = (ushort) H2DEV16((ushort) 510);
1254 cf->ocena = 1;
1255
1256 if (do_dma(port_base, cf_dma_addr, SET_CONFIG_DMA)) {
1257 printk
1258 ("%s: busy timeout sending configuration, detaching.\n",
1259 name);
1260 pci_free_consistent(pdev, sizeof(struct eata_config),
1261 cf, cf_dma_addr);
1262 goto freedma;
1263 }
1264
1265 }
1266#endif
1267
1268 spin_unlock_irq(&driver_lock);
1269 sh[j] = shost = scsi_register(tpnt, sizeof(struct hostdata));
1270 spin_lock_irq(&driver_lock);
1271
1272 if (shost == NULL) {
1273 printk("%s: unable to register host, detaching.\n", name);
1274 goto freedma;
1275 }
1276
1277 shost->io_port = port_base;
1278 shost->unique_id = port_base;
1279 shost->n_io_port = REGION_SIZE;
1280 shost->dma_channel = dma_channel;
1281 shost->irq = irq;
1282 shost->sg_tablesize = (ushort) info.scatt_size;
1283 shost->this_id = (ushort) info.host_addr[3];
1284 shost->can_queue = (ushort) info.queue_size;
1285 shost->cmd_per_lun = MAX_CMD_PER_LUN;
1286
1287 ha = (struct hostdata *)shost->hostdata;
1288
1289 memset(ha, 0, sizeof(struct hostdata));
1290 ha->subversion = subversion;
1291 ha->protocol_rev = protocol_rev;
1292 ha->is_pci = is_pci;
1293 ha->pdev = pdev;
1294 ha->board_number = j;
1295
1296 if (ha->subversion == ESA)
1297 shost->unchecked_isa_dma = 0;
1298 else {
1299 unsigned long flags;
1300 shost->unchecked_isa_dma = 1;
1301
1302 flags = claim_dma_lock();
1303 disable_dma(dma_channel);
1304 clear_dma_ff(dma_channel);
1305 set_dma_mode(dma_channel, DMA_MODE_CASCADE);
1306 enable_dma(dma_channel);
1307 release_dma_lock(flags);
1308
1309 }
1310
1311 strcpy(ha->board_name, name);
1312
1313
1314 if (shost->sg_tablesize > MAX_SGLIST || shost->sg_tablesize < 2) {
1315 printk("%s: detect, wrong n. of SG lists %d, fixed.\n",
1316 ha->board_name, shost->sg_tablesize);
1317 shost->sg_tablesize = MAX_SGLIST;
1318 }
1319
1320
1321 if (shost->can_queue > MAX_MAILBOXES || shost->can_queue < 2) {
1322 printk("%s: detect, wrong n. of mbox %d, fixed.\n",
1323 ha->board_name, shost->can_queue);
1324 shost->can_queue = MAX_MAILBOXES;
1325 }
1326
1327 if (protocol_rev != 'A') {
1328 if (info.max_chan > 0 && info.max_chan < MAX_CHANNEL)
1329 shost->max_channel = info.max_chan;
1330
1331 if (info.max_id > 7 && info.max_id < MAX_TARGET)
1332 shost->max_id = info.max_id + 1;
1333
1334 if (info.large_sg && shost->sg_tablesize == MAX_SGLIST)
1335 shost->sg_tablesize = MAX_LARGE_SGLIST;
1336 }
1337
1338 if (protocol_rev == 'C') {
1339 if (info.max_lun > 7 && info.max_lun < MAX_LUN)
1340 shost->max_lun = info.max_lun + 1;
1341 }
1342
1343 if (dma_channel == NO_DMA)
1344 sprintf(dma_name, "%s", "BMST");
1345 else
1346 sprintf(dma_name, "DMA %u", dma_channel);
1347
1348 spin_unlock_irq(&driver_lock);
1349
1350 for (i = 0; i < shost->can_queue; i++)
1351 ha->cp[i].cp_dma_addr = pci_map_single(ha->pdev,
1352 &ha->cp[i],
1353 sizeof(struct mscp),
1354 PCI_DMA_BIDIRECTIONAL);
1355
1356 for (i = 0; i < shost->can_queue; i++) {
1357 size_t sz = shost->sg_tablesize *sizeof(struct sg_list);
1358 gfp_t gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC;
1359 ha->cp[i].sglist = kmalloc(sz, gfp_mask);
1360 if (!ha->cp[i].sglist) {
1361 printk
1362 ("%s: kmalloc SGlist failed, mbox %d, detaching.\n",
1363 ha->board_name, i);
1364 goto release;
1365 }
1366 }
1367
1368 if (!(ha->sp_cpu_addr = pci_alloc_consistent(ha->pdev,
1369 sizeof(struct mssp),
1370 &ha->sp_dma_addr))) {
1371 printk("%s: pci_alloc_consistent failed, detaching.\n", ha->board_name);
1372 goto release;
1373 }
1374
1375 if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN)
1376 max_queue_depth = MAX_TAGGED_CMD_PER_LUN;
1377
1378 if (max_queue_depth < MAX_CMD_PER_LUN)
1379 max_queue_depth = MAX_CMD_PER_LUN;
1380
1381 if (tag_mode != TAG_DISABLED && tag_mode != TAG_SIMPLE)
1382 tag_mode = TAG_ORDERED;
1383
1384 if (j == 0) {
1385 printk
1386 ("EATA/DMA 2.0x: Copyright (C) 1994-2003 Dario Ballabio.\n");
1387 printk
1388 ("%s config options -> tm:%d, lc:%c, mq:%d, rs:%c, et:%c, "
1389 "ip:%c, ep:%c, pp:%c.\n", driver_name, tag_mode,
1390 YESNO(linked_comm), max_queue_depth, YESNO(rev_scan),
1391 YESNO(ext_tran), YESNO(isa_probe), YESNO(eisa_probe),
1392 YESNO(pci_probe));
1393 }
1394
1395 printk("%s: 2.0%c, %s 0x%03lx, IRQ %u, %s, SG %d, MB %d.\n",
1396 ha->board_name, ha->protocol_rev, bus_type,
1397 (unsigned long)shost->io_port, shost->irq, dma_name,
1398 shost->sg_tablesize, shost->can_queue);
1399
1400 if (shost->max_id > 8 || shost->max_lun > 8)
1401 printk
1402 ("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n",
1403 ha->board_name, shost->max_id, shost->max_lun);
1404
1405 for (i = 0; i <= shost->max_channel; i++)
1406 printk("%s: SCSI channel %u enabled, host target ID %d.\n",
1407 ha->board_name, i, info.host_addr[3 - i]);
1408
1409#if defined(DEBUG_DETECT)
1410 printk("%s: Vers. 0x%x, ocs %u, tar %u, trnxfr %u, more %u, SYNC 0x%x, "
1411 "sec. %u, infol %d, cpl %d spl %d.\n", name, info.version,
1412 info.ocsena, info.tarsup, info.trnxfr, info.morsup, info.sync,
1413 info.second, info.data_len, info.cp_len, info.sp_len);
1414
1415 if (protocol_rev == 'B' || protocol_rev == 'C')
1416 printk("%s: isaena %u, forcaddr %u, max_id %u, max_chan %u, "
1417 "large_sg %u, res1 %u.\n", name, info.isaena,
1418 info.forcaddr, info.max_id, info.max_chan, info.large_sg,
1419 info.res1);
1420
1421 if (protocol_rev == 'C')
1422 printk("%s: max_lun %u, m1 %u, idquest %u, pci %u, eisa %u, "
1423 "raidnum %u.\n", name, info.max_lun, info.m1,
1424 info.idquest, info.pci, info.eisa, info.raidnum);
1425#endif
1426
1427 if (ha->pdev) {
1428 pci_set_master(ha->pdev);
1429 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)))
1430 printk("%s: warning, pci_set_dma_mask failed.\n",
1431 ha->board_name);
1432 }
1433
1434 return 1;
1435
1436 freedma:
1437 if (subversion == ISA)
1438 free_dma(dma_channel);
1439 freeirq:
1440 free_irq(irq, &sha[j]);
1441 freelock:
1442 spin_unlock_irq(&driver_lock);
1443 release_region(port_base, REGION_SIZE);
1444 fail:
1445 return 0;
1446
1447 release:
1448 eata2x_release(shost);
1449 return 0;
1450}
1451
1452static void internal_setup(char *str, int *ints)
1453{
1454 int i, argc = ints[0];
1455 char *cur = str, *pc;
1456
1457 if (argc > 0) {
1458 if (argc > MAX_INT_PARAM)
1459 argc = MAX_INT_PARAM;
1460
1461 for (i = 0; i < argc; i++)
1462 io_port[i] = ints[i + 1];
1463
1464 io_port[i] = 0;
1465 setup_done = 1;
1466 }
1467
1468 while (cur && (pc = strchr(cur, ':'))) {
1469 int val = 0, c = *++pc;
1470
1471 if (c == 'n' || c == 'N')
1472 val = 0;
1473 else if (c == 'y' || c == 'Y')
1474 val = 1;
1475 else
1476 val = (int)simple_strtoul(pc, NULL, 0);
1477
1478 if (!strncmp(cur, "lc:", 3))
1479 linked_comm = val;
1480 else if (!strncmp(cur, "tm:", 3))
1481 tag_mode = val;
1482 else if (!strncmp(cur, "tc:", 3))
1483 tag_mode = val;
1484 else if (!strncmp(cur, "mq:", 3))
1485 max_queue_depth = val;
1486 else if (!strncmp(cur, "ls:", 3))
1487 link_statistics = val;
1488 else if (!strncmp(cur, "et:", 3))
1489 ext_tran = val;
1490 else if (!strncmp(cur, "rs:", 3))
1491 rev_scan = val;
1492 else if (!strncmp(cur, "ip:", 3))
1493 isa_probe = val;
1494 else if (!strncmp(cur, "ep:", 3))
1495 eisa_probe = val;
1496 else if (!strncmp(cur, "pp:", 3))
1497 pci_probe = val;
1498
1499 if ((cur = strchr(cur, ',')))
1500 ++cur;
1501 }
1502
1503 return;
1504}
1505
1506static int option_setup(char *str)
1507{
1508 int ints[MAX_INT_PARAM];
1509 char *cur = str;
1510 int i = 1;
1511
1512 while (cur && isdigit(*cur) && i <= MAX_INT_PARAM) {
1513 ints[i++] = simple_strtoul(cur, NULL, 0);
1514
1515 if ((cur = strchr(cur, ',')) != NULL)
1516 cur++;
1517 }
1518
1519 ints[0] = i - 1;
1520 internal_setup(cur, ints);
1521 return 1;
1522}
1523
1524static void add_pci_ports(void)
1525{
1526#if defined(CONFIG_PCI)
1527 unsigned int addr, k;
1528 struct pci_dev *dev = NULL;
1529
1530 for (k = 0; k < MAX_PCI; k++) {
1531
1532 if (!(dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev)))
1533 break;
1534
1535 if (pci_enable_device(dev)) {
1536#if defined(DEBUG_PCI_DETECT)
1537 printk
1538 ("%s: detect, bus %d, devfn 0x%x, pci_enable_device failed.\n",
1539 driver_name, dev->bus->number, dev->devfn);
1540#endif
1541
1542 continue;
1543 }
1544
1545 addr = pci_resource_start(dev, 0);
1546
1547#if defined(DEBUG_PCI_DETECT)
1548 printk("%s: detect, seq. %d, bus %d, devfn 0x%x, addr 0x%x.\n",
1549 driver_name, k, dev->bus->number, dev->devfn, addr);
1550#endif
1551
1552
1553 io_port[MAX_INT_PARAM + (rev_scan ? (MAX_PCI - k) : (1 + k))] =
1554 addr + PCI_BASE_ADDRESS_0;
1555 }
1556
1557 pci_dev_put(dev);
1558#endif
1559}
1560
1561static int eata2x_detect(struct scsi_host_template *tpnt)
1562{
1563 unsigned int j = 0, k;
1564
1565 tpnt->proc_name = "eata2x";
1566
1567 if (strlen(boot_options))
1568 option_setup(boot_options);
1569
1570#if defined(MODULE)
1571
1572 if (io_port[0] != SKIP) {
1573 setup_done = 1;
1574 io_port[MAX_INT_PARAM] = 0;
1575 }
1576#endif
1577
1578 for (k = MAX_INT_PARAM; io_port[k]; k++)
1579 if (io_port[k] == SKIP)
1580 continue;
1581 else if (io_port[k] <= MAX_ISA_ADDR) {
1582 if (!isa_probe)
1583 io_port[k] = SKIP;
1584 } else if (io_port[k] >= MIN_EISA_ADDR
1585 && io_port[k] <= MAX_EISA_ADDR) {
1586 if (!eisa_probe)
1587 io_port[k] = SKIP;
1588 }
1589
1590 if (pci_probe) {
1591 if (!setup_done)
1592 add_pci_ports();
1593 else
1594 enable_pci_ports();
1595 }
1596
1597 for (k = 0; io_port[k]; k++) {
1598
1599 if (io_port[k] == SKIP)
1600 continue;
1601
1602 if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt))
1603 j++;
1604 }
1605
1606 num_boards = j;
1607 return j;
1608}
1609
1610static void map_dma(unsigned int i, struct hostdata *ha)
1611{
1612 unsigned int k, pci_dir;
1613 int count;
1614 struct scatterlist *sg;
1615 struct mscp *cpp;
1616 struct scsi_cmnd *SCpnt;
1617
1618 cpp = &ha->cp[i];
1619 SCpnt = cpp->SCpnt;
1620 pci_dir = SCpnt->sc_data_direction;
1621
1622 if (SCpnt->sense_buffer)
1623 cpp->sense_addr =
1624 H2DEV(pci_map_single(ha->pdev, SCpnt->sense_buffer,
1625 SCSI_SENSE_BUFFERSIZE, PCI_DMA_FROMDEVICE));
1626
1627 cpp->sense_len = SCSI_SENSE_BUFFERSIZE;
1628
1629 if (!scsi_sg_count(SCpnt)) {
1630 cpp->data_len = 0;
1631 return;
1632 }
1633
1634 count = pci_map_sg(ha->pdev, scsi_sglist(SCpnt), scsi_sg_count(SCpnt),
1635 pci_dir);
1636 BUG_ON(!count);
1637
1638 scsi_for_each_sg(SCpnt, sg, count, k) {
1639 cpp->sglist[k].address = H2DEV(sg_dma_address(sg));
1640 cpp->sglist[k].num_bytes = H2DEV(sg_dma_len(sg));
1641 }
1642
1643 cpp->sg = 1;
1644 cpp->data_address = H2DEV(pci_map_single(ha->pdev, cpp->sglist,
1645 scsi_sg_count(SCpnt) *
1646 sizeof(struct sg_list),
1647 pci_dir));
1648 cpp->data_len = H2DEV((scsi_sg_count(SCpnt) * sizeof(struct sg_list)));
1649}
1650
1651static void unmap_dma(unsigned int i, struct hostdata *ha)
1652{
1653 unsigned int pci_dir;
1654 struct mscp *cpp;
1655 struct scsi_cmnd *SCpnt;
1656
1657 cpp = &ha->cp[i];
1658 SCpnt = cpp->SCpnt;
1659 pci_dir = SCpnt->sc_data_direction;
1660
1661 if (DEV2H(cpp->sense_addr))
1662 pci_unmap_single(ha->pdev, DEV2H(cpp->sense_addr),
1663 DEV2H(cpp->sense_len), PCI_DMA_FROMDEVICE);
1664
1665 if (scsi_sg_count(SCpnt))
1666 pci_unmap_sg(ha->pdev, scsi_sglist(SCpnt), scsi_sg_count(SCpnt),
1667 pci_dir);
1668
1669 if (!DEV2H(cpp->data_len))
1670 pci_dir = PCI_DMA_BIDIRECTIONAL;
1671
1672 if (DEV2H(cpp->data_address))
1673 pci_unmap_single(ha->pdev, DEV2H(cpp->data_address),
1674 DEV2H(cpp->data_len), pci_dir);
1675}
1676
1677static void sync_dma(unsigned int i, struct hostdata *ha)
1678{
1679 unsigned int pci_dir;
1680 struct mscp *cpp;
1681 struct scsi_cmnd *SCpnt;
1682
1683 cpp = &ha->cp[i];
1684 SCpnt = cpp->SCpnt;
1685 pci_dir = SCpnt->sc_data_direction;
1686
1687 if (DEV2H(cpp->sense_addr))
1688 pci_dma_sync_single_for_cpu(ha->pdev, DEV2H(cpp->sense_addr),
1689 DEV2H(cpp->sense_len),
1690 PCI_DMA_FROMDEVICE);
1691
1692 if (scsi_sg_count(SCpnt))
1693 pci_dma_sync_sg_for_cpu(ha->pdev, scsi_sglist(SCpnt),
1694 scsi_sg_count(SCpnt), pci_dir);
1695
1696 if (!DEV2H(cpp->data_len))
1697 pci_dir = PCI_DMA_BIDIRECTIONAL;
1698
1699 if (DEV2H(cpp->data_address))
1700 pci_dma_sync_single_for_cpu(ha->pdev,
1701 DEV2H(cpp->data_address),
1702 DEV2H(cpp->data_len), pci_dir);
1703}
1704
1705static void scsi_to_dev_dir(unsigned int i, struct hostdata *ha)
1706{
1707 unsigned int k;
1708
1709 static const unsigned char data_out_cmds[] = {
1710 0x0a, 0x2a, 0x15, 0x55, 0x04, 0x07, 0x18, 0x1d, 0x24, 0x2e,
1711 0x30, 0x31, 0x32, 0x38, 0x39, 0x3a, 0x3b, 0x3d, 0x3f, 0x40,
1712 0x41, 0x4c, 0xaa, 0xae, 0xb0, 0xb1, 0xb2, 0xb6, 0xea, 0x1b, 0x5d
1713 };
1714
1715 static const unsigned char data_none_cmds[] = {
1716 0x01, 0x0b, 0x10, 0x11, 0x13, 0x16, 0x17, 0x19, 0x2b, 0x1e,
1717 0x2c, 0xac, 0x2f, 0xaf, 0x33, 0xb3, 0x35, 0x36, 0x45, 0x47,
1718 0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5, 0x00
1719 };
1720
1721 struct mscp *cpp;
1722 struct scsi_cmnd *SCpnt;
1723
1724 cpp = &ha->cp[i];
1725 SCpnt = cpp->SCpnt;
1726
1727 if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
1728 cpp->din = 1;
1729 cpp->dout = 0;
1730 return;
1731 } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
1732 cpp->din = 0;
1733 cpp->dout = 1;
1734 return;
1735 } else if (SCpnt->sc_data_direction == DMA_NONE) {
1736 cpp->din = 0;
1737 cpp->dout = 0;
1738 return;
1739 }
1740
1741 if (SCpnt->sc_data_direction != DMA_BIDIRECTIONAL)
1742 panic("%s: qcomm, invalid SCpnt->sc_data_direction.\n",
1743 ha->board_name);
1744
1745 for (k = 0; k < ARRAY_SIZE(data_out_cmds); k++)
1746 if (SCpnt->cmnd[0] == data_out_cmds[k]) {
1747 cpp->dout = 1;
1748 break;
1749 }
1750
1751 if ((cpp->din = !cpp->dout))
1752 for (k = 0; k < ARRAY_SIZE(data_none_cmds); k++)
1753 if (SCpnt->cmnd[0] == data_none_cmds[k]) {
1754 cpp->din = 0;
1755 break;
1756 }
1757
1758}
1759
1760static int eata2x_queuecommand(struct scsi_cmnd *SCpnt,
1761 void (*done) (struct scsi_cmnd *))
1762{
1763 struct Scsi_Host *shost = SCpnt->device->host;
1764 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1765 unsigned int i, k;
1766 struct mscp *cpp;
1767
1768 if (SCpnt->host_scribble)
1769 panic("%s: qcomm, pid %ld, SCpnt %p already active.\n",
1770 ha->board_name, SCpnt->serial_number, SCpnt);
1771
1772
1773
1774 i = ha->last_cp_used + 1;
1775
1776 for (k = 0; k < shost->can_queue; k++, i++) {
1777 if (i >= shost->can_queue)
1778 i = 0;
1779 if (ha->cp_stat[i] == FREE) {
1780 ha->last_cp_used = i;
1781 break;
1782 }
1783 }
1784
1785 if (k == shost->can_queue) {
1786 printk("%s: qcomm, no free mailbox.\n", ha->board_name);
1787 return 1;
1788 }
1789
1790
1791 cpp = &ha->cp[i];
1792
1793 memset(cpp, 0, sizeof(struct mscp) - CP_TAIL_SIZE);
1794
1795
1796 cpp->sp_dma_addr = H2DEV(ha->sp_dma_addr);
1797
1798 SCpnt->scsi_done = done;
1799 cpp->cpp_index = i;
1800 SCpnt->host_scribble = (unsigned char *)&cpp->cpp_index;
1801
1802 if (do_trace)
1803 scmd_printk(KERN_INFO, SCpnt,
1804 "qcomm, mbox %d, pid %ld.\n", i, SCpnt->serial_number);
1805
1806 cpp->reqsen = 1;
1807 cpp->dispri = 1;
1808#if 0
1809 if (SCpnt->device->type == TYPE_TAPE)
1810 cpp->hbaci = 1;
1811#endif
1812 cpp->one = 1;
1813 cpp->channel = SCpnt->device->channel;
1814 cpp->target = SCpnt->device->id;
1815 cpp->lun = SCpnt->device->lun;
1816 cpp->SCpnt = SCpnt;
1817 memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len);
1818
1819
1820 scsi_to_dev_dir(i, ha);
1821
1822
1823 map_dma(i, ha);
1824
1825 if (linked_comm && SCpnt->device->queue_depth > 2
1826 && TLDEV(SCpnt->device->type)) {
1827 ha->cp_stat[i] = READY;
1828 flush_dev(SCpnt->device, SCpnt->request->sector, ha, 0);
1829 return 0;
1830 }
1831
1832
1833 if (do_dma(shost->io_port, cpp->cp_dma_addr, SEND_CP_DMA)) {
1834 unmap_dma(i, ha);
1835 SCpnt->host_scribble = NULL;
1836 scmd_printk(KERN_INFO, SCpnt,
1837 "qcomm, pid %ld, adapter busy.\n", SCpnt->serial_number);
1838 return 1;
1839 }
1840
1841 ha->cp_stat[i] = IN_USE;
1842 return 0;
1843}
1844
1845static int eata2x_eh_abort(struct scsi_cmnd *SCarg)
1846{
1847 struct Scsi_Host *shost = SCarg->device->host;
1848 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1849 unsigned int i;
1850
1851 if (SCarg->host_scribble == NULL) {
1852 scmd_printk(KERN_INFO, SCarg,
1853 "abort, pid %ld inactive.\n", SCarg->serial_number);
1854 return SUCCESS;
1855 }
1856
1857 i = *(unsigned int *)SCarg->host_scribble;
1858 scmd_printk(KERN_WARNING, SCarg,
1859 "abort, mbox %d, pid %ld.\n", i, SCarg->serial_number);
1860
1861 if (i >= shost->can_queue)
1862 panic("%s: abort, invalid SCarg->host_scribble.\n", ha->board_name);
1863
1864 if (wait_on_busy(shost->io_port, MAXLOOP)) {
1865 printk("%s: abort, timeout error.\n", ha->board_name);
1866 return FAILED;
1867 }
1868
1869 if (ha->cp_stat[i] == FREE) {
1870 printk("%s: abort, mbox %d is free.\n", ha->board_name, i);
1871 return SUCCESS;
1872 }
1873
1874 if (ha->cp_stat[i] == IN_USE) {
1875 printk("%s: abort, mbox %d is in use.\n", ha->board_name, i);
1876
1877 if (SCarg != ha->cp[i].SCpnt)
1878 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1879 ha->board_name, i, SCarg, ha->cp[i].SCpnt);
1880
1881 if (inb(shost->io_port + REG_AUX_STATUS) & IRQ_ASSERTED)
1882 printk("%s: abort, mbox %d, interrupt pending.\n",
1883 ha->board_name, i);
1884
1885 return FAILED;
1886 }
1887
1888 if (ha->cp_stat[i] == IN_RESET) {
1889 printk("%s: abort, mbox %d is in reset.\n", ha->board_name, i);
1890 return FAILED;
1891 }
1892
1893 if (ha->cp_stat[i] == LOCKED) {
1894 printk("%s: abort, mbox %d is locked.\n", ha->board_name, i);
1895 return SUCCESS;
1896 }
1897
1898 if (ha->cp_stat[i] == READY || ha->cp_stat[i] == ABORTING) {
1899 unmap_dma(i, ha);
1900 SCarg->result = DID_ABORT << 16;
1901 SCarg->host_scribble = NULL;
1902 ha->cp_stat[i] = FREE;
1903 printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
1904 ha->board_name, i, SCarg->serial_number);
1905 SCarg->scsi_done(SCarg);
1906 return SUCCESS;
1907 }
1908
1909 panic("%s: abort, mbox %d, invalid cp_stat.\n", ha->board_name, i);
1910}
1911
1912static int eata2x_eh_host_reset(struct scsi_cmnd *SCarg)
1913{
1914 unsigned int i, time, k, c, limit = 0;
1915 int arg_done = 0;
1916 struct scsi_cmnd *SCpnt;
1917 struct Scsi_Host *shost = SCarg->device->host;
1918 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1919
1920 scmd_printk(KERN_INFO, SCarg,
1921 "reset, enter, pid %ld.\n", SCarg->serial_number);
1922
1923 spin_lock_irq(shost->host_lock);
1924
1925 if (SCarg->host_scribble == NULL)
1926 printk("%s: reset, pid %ld inactive.\n", ha->board_name, SCarg->serial_number);
1927
1928 if (ha->in_reset) {
1929 printk("%s: reset, exit, already in reset.\n", ha->board_name);
1930 spin_unlock_irq(shost->host_lock);
1931 return FAILED;
1932 }
1933
1934 if (wait_on_busy(shost->io_port, MAXLOOP)) {
1935 printk("%s: reset, exit, timeout error.\n", ha->board_name);
1936 spin_unlock_irq(shost->host_lock);
1937 return FAILED;
1938 }
1939
1940 ha->retries = 0;
1941
1942 for (c = 0; c <= shost->max_channel; c++)
1943 for (k = 0; k < shost->max_id; k++) {
1944 ha->target_redo[k][c] = 1;
1945 ha->target_to[k][c] = 0;
1946 }
1947
1948 for (i = 0; i < shost->can_queue; i++) {
1949
1950 if (ha->cp_stat[i] == FREE)
1951 continue;
1952
1953 if (ha->cp_stat[i] == LOCKED) {
1954 ha->cp_stat[i] = FREE;
1955 printk("%s: reset, locked mbox %d forced free.\n",
1956 ha->board_name, i);
1957 continue;
1958 }
1959
1960 if (!(SCpnt = ha->cp[i].SCpnt))
1961 panic("%s: reset, mbox %d, SCpnt == NULL.\n", ha->board_name, i);
1962
1963 if (ha->cp_stat[i] == READY || ha->cp_stat[i] == ABORTING) {
1964 ha->cp_stat[i] = ABORTING;
1965 printk("%s: reset, mbox %d aborting, pid %ld.\n",
1966 ha->board_name, i, SCpnt->serial_number);
1967 }
1968
1969 else {
1970 ha->cp_stat[i] = IN_RESET;
1971 printk("%s: reset, mbox %d in reset, pid %ld.\n",
1972 ha->board_name, i, SCpnt->serial_number);
1973 }
1974
1975 if (SCpnt->host_scribble == NULL)
1976 panic("%s: reset, mbox %d, garbled SCpnt.\n", ha->board_name, i);
1977
1978 if (*(unsigned int *)SCpnt->host_scribble != i)
1979 panic("%s: reset, mbox %d, index mismatch.\n", ha->board_name, i);
1980
1981 if (SCpnt->scsi_done == NULL)
1982 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n",
1983 ha->board_name, i);
1984
1985 if (SCpnt == SCarg)
1986 arg_done = 1;
1987 }
1988
1989 if (do_dma(shost->io_port, 0, RESET_PIO)) {
1990 printk("%s: reset, cannot reset, timeout error.\n", ha->board_name);
1991 spin_unlock_irq(shost->host_lock);
1992 return FAILED;
1993 }
1994
1995 printk("%s: reset, board reset done, enabling interrupts.\n", ha->board_name);
1996
1997#if defined(DEBUG_RESET)
1998 do_trace = 1;
1999#endif
2000
2001 ha->in_reset = 1;
2002
2003 spin_unlock_irq(shost->host_lock);
2004
2005
2006 time = jiffies;
2007 while ((jiffies - time) < (10 * HZ) && limit++ < 200000)
2008 udelay(100L);
2009
2010 spin_lock_irq(shost->host_lock);
2011
2012 printk("%s: reset, interrupts disabled, loops %d.\n", ha->board_name, limit);
2013
2014 for (i = 0; i < shost->can_queue; i++) {
2015
2016 if (ha->cp_stat[i] == IN_RESET) {
2017 SCpnt = ha->cp[i].SCpnt;
2018 unmap_dma(i, ha);
2019 SCpnt->result = DID_RESET << 16;
2020 SCpnt->host_scribble = NULL;
2021
2022
2023 ha->cp_stat[i] = LOCKED;
2024
2025 printk
2026 ("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
2027 ha->board_name, i, SCpnt->serial_number);
2028 }
2029
2030 else if (ha->cp_stat[i] == ABORTING) {
2031 SCpnt = ha->cp[i].SCpnt;
2032 unmap_dma(i, ha);
2033 SCpnt->result = DID_RESET << 16;
2034 SCpnt->host_scribble = NULL;
2035
2036
2037 ha->cp_stat[i] = FREE;
2038
2039 printk
2040 ("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
2041 ha->board_name, i, SCpnt->serial_number);
2042 }
2043
2044 else
2045
2046 continue;
2047
2048 SCpnt->scsi_done(SCpnt);
2049 }
2050
2051 ha->in_reset = 0;
2052 do_trace = 0;
2053
2054 if (arg_done)
2055 printk("%s: reset, exit, pid %ld done.\n", ha->board_name, SCarg->serial_number);
2056 else
2057 printk("%s: reset, exit.\n", ha->board_name);
2058
2059 spin_unlock_irq(shost->host_lock);
2060 return SUCCESS;
2061}
2062
2063int eata2x_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2064 sector_t capacity, int *dkinfo)
2065{
2066 unsigned int size = capacity;
2067
2068 if (ext_tran || (scsicam_bios_param(bdev, capacity, dkinfo) < 0)) {
2069 dkinfo[0] = 255;
2070 dkinfo[1] = 63;
2071 dkinfo[2] = size / (dkinfo[0] * dkinfo[1]);
2072 }
2073#if defined (DEBUG_GEOMETRY)
2074 printk("%s: bios_param, head=%d, sec=%d, cyl=%d.\n", driver_name,
2075 dkinfo[0], dkinfo[1], dkinfo[2]);
2076#endif
2077
2078 return 0;
2079}
2080
2081static void sort(unsigned long sk[], unsigned int da[], unsigned int n,
2082 unsigned int rev)
2083{
2084 unsigned int i, j, k, y;
2085 unsigned long x;
2086
2087 for (i = 0; i < n - 1; i++) {
2088 k = i;
2089
2090 for (j = k + 1; j < n; j++)
2091 if (rev) {
2092 if (sk[j] > sk[k])
2093 k = j;
2094 } else {
2095 if (sk[j] < sk[k])
2096 k = j;
2097 }
2098
2099 if (k != i) {
2100 x = sk[k];
2101 sk[k] = sk[i];
2102 sk[i] = x;
2103 y = da[k];
2104 da[k] = da[i];
2105 da[i] = y;
2106 }
2107 }
2108
2109 return;
2110}
2111
2112static int reorder(struct hostdata *ha, unsigned long cursec,
2113 unsigned int ihdlr, unsigned int il[], unsigned int n_ready)
2114{
2115 struct scsi_cmnd *SCpnt;
2116 struct mscp *cpp;
2117 unsigned int k, n;
2118 unsigned int rev = 0, s = 1, r = 1;
2119 unsigned int input_only = 1, overlap = 0;
2120 unsigned long sl[n_ready], pl[n_ready], ll[n_ready];
2121 unsigned long maxsec = 0, minsec = ULONG_MAX, seek = 0, iseek = 0;
2122 unsigned long ioseek = 0;
2123
2124 static unsigned int flushcount = 0, batchcount = 0, sortcount = 0;
2125 static unsigned int readycount = 0, ovlcount = 0, inputcount = 0;
2126 static unsigned int readysorted = 0, revcount = 0;
2127 static unsigned long seeksorted = 0, seeknosort = 0;
2128
2129 if (link_statistics && !(++flushcount % link_statistics))
2130 printk("fc %d bc %d ic %d oc %d rc %d rs %d sc %d re %d"
2131 " av %ldK as %ldK.\n", flushcount, batchcount,
2132 inputcount, ovlcount, readycount, readysorted, sortcount,
2133 revcount, seeknosort / (readycount + 1),
2134 seeksorted / (readycount + 1));
2135
2136 if (n_ready <= 1)
2137 return 0;
2138
2139 for (n = 0; n < n_ready; n++) {
2140 k = il[n];
2141 cpp = &ha->cp[k];
2142 SCpnt = cpp->SCpnt;
2143
2144 if (!cpp->din)
2145 input_only = 0;
2146
2147 if (SCpnt->request->sector < minsec)
2148 minsec = SCpnt->request->sector;
2149 if (SCpnt->request->sector > maxsec)
2150 maxsec = SCpnt->request->sector;
2151
2152 sl[n] = SCpnt->request->sector;
2153 ioseek += SCpnt->request->nr_sectors;
2154
2155 if (!n)
2156 continue;
2157
2158 if (sl[n] < sl[n - 1])
2159 s = 0;
2160 if (sl[n] > sl[n - 1])
2161 r = 0;
2162
2163 if (link_statistics) {
2164 if (sl[n] > sl[n - 1])
2165 seek += sl[n] - sl[n - 1];
2166 else
2167 seek += sl[n - 1] - sl[n];
2168 }
2169
2170 }
2171
2172 if (link_statistics) {
2173 if (cursec > sl[0])
2174 seek += cursec - sl[0];
2175 else
2176 seek += sl[0] - cursec;
2177 }
2178
2179 if (cursec > ((maxsec + minsec) / 2))
2180 rev = 1;
2181
2182 if (ioseek > ((maxsec - minsec) / 2))
2183 rev = 0;
2184
2185 if (!((rev && r) || (!rev && s)))
2186 sort(sl, il, n_ready, rev);
2187
2188 if (!input_only)
2189 for (n = 0; n < n_ready; n++) {
2190 k = il[n];
2191 cpp = &ha->cp[k];
2192 SCpnt = cpp->SCpnt;
2193 ll[n] = SCpnt->request->nr_sectors;
2194 pl[n] = SCpnt->serial_number;
2195
2196 if (!n)
2197 continue;
2198
2199 if ((sl[n] == sl[n - 1])
2200 || (!rev && ((sl[n - 1] + ll[n - 1]) > sl[n]))
2201 || (rev && ((sl[n] + ll[n]) > sl[n - 1])))
2202 overlap = 1;
2203 }
2204
2205 if (overlap)
2206 sort(pl, il, n_ready, 0);
2207
2208 if (link_statistics) {
2209 if (cursec > sl[0])
2210 iseek = cursec - sl[0];
2211 else
2212 iseek = sl[0] - cursec;
2213 batchcount++;
2214 readycount += n_ready;
2215 seeknosort += seek / 1024;
2216 if (input_only)
2217 inputcount++;
2218 if (overlap) {
2219 ovlcount++;
2220 seeksorted += iseek / 1024;
2221 } else
2222 seeksorted += (iseek + maxsec - minsec) / 1024;
2223 if (rev && !r) {
2224 revcount++;
2225 readysorted += n_ready;
2226 }
2227 if (!rev && !s) {
2228 sortcount++;
2229 readysorted += n_ready;
2230 }
2231 }
2232#if defined(DEBUG_LINKED_COMMANDS)
2233 if (link_statistics && (overlap || !(flushcount % link_statistics)))
2234 for (n = 0; n < n_ready; n++) {
2235 k = il[n];
2236 cpp = &ha->cp[k];
2237 SCpnt = cpp->SCpnt;
2238 scmd_printk(KERN_INFO, SCpnt,
2239 "%s pid %ld mb %d fc %d nr %d sec %ld ns %ld"
2240 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
2241 (ihdlr ? "ihdlr" : "qcomm"),
2242 SCpnt->serial_number, k, flushcount,
2243 n_ready, SCpnt->request->sector,
2244 SCpnt->request->nr_sectors, cursec, YESNO(s),
2245 YESNO(r), YESNO(rev), YESNO(input_only),
2246 YESNO(overlap), cpp->din);
2247 }
2248#endif
2249 return overlap;
2250}
2251
2252static void flush_dev(struct scsi_device *dev, unsigned long cursec,
2253 struct hostdata *ha, unsigned int ihdlr)
2254{
2255 struct scsi_cmnd *SCpnt;
2256 struct mscp *cpp;
2257 unsigned int k, n, n_ready = 0, il[MAX_MAILBOXES];
2258
2259 for (k = 0; k < dev->host->can_queue; k++) {
2260
2261 if (ha->cp_stat[k] != READY && ha->cp_stat[k] != IN_USE)
2262 continue;
2263
2264 cpp = &ha->cp[k];
2265 SCpnt = cpp->SCpnt;
2266
2267 if (SCpnt->device != dev)
2268 continue;
2269
2270 if (ha->cp_stat[k] == IN_USE)
2271 return;
2272
2273 il[n_ready++] = k;
2274 }
2275
2276 if (reorder(ha, cursec, ihdlr, il, n_ready))
2277 n_ready = 1;
2278
2279 for (n = 0; n < n_ready; n++) {
2280 k = il[n];
2281 cpp = &ha->cp[k];
2282 SCpnt = cpp->SCpnt;
2283
2284 if (do_dma(dev->host->io_port, cpp->cp_dma_addr, SEND_CP_DMA)) {
2285 scmd_printk(KERN_INFO, SCpnt,
2286 "%s, pid %ld, mbox %d, adapter"
2287 " busy, will abort.\n",
2288 (ihdlr ? "ihdlr" : "qcomm"),
2289 SCpnt->serial_number, k);
2290 ha->cp_stat[k] = ABORTING;
2291 continue;
2292 }
2293
2294 ha->cp_stat[k] = IN_USE;
2295 }
2296}
2297
2298static irqreturn_t ihdlr(struct Scsi_Host *shost)
2299{
2300 struct scsi_cmnd *SCpnt;
2301 unsigned int i, k, c, status, tstatus, reg;
2302 struct mssp *spp;
2303 struct mscp *cpp;
2304 struct hostdata *ha = (struct hostdata *)shost->hostdata;
2305 int irq = shost->irq;
2306
2307
2308 if (!(inb(shost->io_port + REG_AUX_STATUS) & IRQ_ASSERTED))
2309 goto none;
2310
2311 ha->iocount++;
2312
2313 if (do_trace)
2314 printk("%s: ihdlr, enter, irq %d, count %d.\n", ha->board_name, irq,
2315 ha->iocount);
2316
2317
2318 if (wait_on_busy(shost->io_port, 20 * MAXLOOP)) {
2319 reg = inb(shost->io_port + REG_STATUS);
2320 printk
2321 ("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n",
2322 ha->board_name, irq, reg, ha->iocount);
2323 goto none;
2324 }
2325
2326 spp = &ha->sp;
2327
2328
2329 memcpy(spp, ha->sp_cpu_addr, sizeof(struct mssp));
2330
2331
2332 memset(ha->sp_cpu_addr, 0, sizeof(struct mssp));
2333
2334
2335 reg = inb(shost->io_port + REG_STATUS);
2336
2337#if defined (DEBUG_INTERRUPT)
2338 {
2339 unsigned char *bytesp;
2340 int cnt;
2341 bytesp = (unsigned char *)spp;
2342 if (ha->iocount < 200) {
2343 printk("sp[] =");
2344 for (cnt = 0; cnt < 15; cnt++)
2345 printk(" 0x%x", bytesp[cnt]);
2346 printk("\n");
2347 }
2348 }
2349#endif
2350
2351
2352 if (spp->eoc == 0 && ha->iocount > 1)
2353 printk
2354 ("%s: ihdlr, spp->eoc == 0, irq %d, reg 0x%x, count %d.\n",
2355 ha->board_name, irq, reg, ha->iocount);
2356 if (spp->cpp_index < 0 || spp->cpp_index >= shost->can_queue)
2357 printk
2358 ("%s: ihdlr, bad spp->cpp_index %d, irq %d, reg 0x%x, count %d.\n",
2359 ha->board_name, spp->cpp_index, irq, reg, ha->iocount);
2360 if (spp->eoc == 0 || spp->cpp_index < 0
2361 || spp->cpp_index >= shost->can_queue)
2362 goto handled;
2363
2364
2365 i = spp->cpp_index;
2366
2367 cpp = &(ha->cp[i]);
2368
2369#if defined(DEBUG_GENERATE_ABORTS)
2370 if ((ha->iocount > 500) && ((ha->iocount % 500) < 3))
2371 goto handled;
2372#endif
2373
2374 if (ha->cp_stat[i] == IGNORE) {
2375 ha->cp_stat[i] = FREE;
2376 goto handled;
2377 } else if (ha->cp_stat[i] == LOCKED) {
2378 ha->cp_stat[i] = FREE;
2379 printk("%s: ihdlr, mbox %d unlocked, count %d.\n", ha->board_name, i,
2380 ha->iocount);
2381 goto handled;
2382 } else if (ha->cp_stat[i] == FREE) {
2383 printk("%s: ihdlr, mbox %d is free, count %d.\n", ha->board_name, i,
2384 ha->iocount);
2385 goto handled;
2386 } else if (ha->cp_stat[i] == IN_RESET)
2387 printk("%s: ihdlr, mbox %d is in reset.\n", ha->board_name, i);
2388 else if (ha->cp_stat[i] != IN_USE)
2389 panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n",
2390 ha->board_name, i, ha->cp_stat[i]);
2391
2392 ha->cp_stat[i] = FREE;
2393 SCpnt = cpp->SCpnt;
2394
2395 if (SCpnt == NULL)
2396 panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", ha->board_name, i);
2397
2398 if (SCpnt->host_scribble == NULL)
2399 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n", ha->board_name,
2400 i, SCpnt->serial_number, SCpnt);
2401
2402 if (*(unsigned int *)SCpnt->host_scribble != i)
2403 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d.\n",
2404 ha->board_name, i, SCpnt->serial_number,
2405 *(unsigned int *)SCpnt->host_scribble);
2406
2407 sync_dma(i, ha);
2408
2409 if (linked_comm && SCpnt->device->queue_depth > 2
2410 && TLDEV(SCpnt->device->type))
2411 flush_dev(SCpnt->device, SCpnt->request->sector, ha, 1);
2412
2413 tstatus = status_byte(spp->target_status);
2414
2415#if defined(DEBUG_GENERATE_ERRORS)
2416 if ((ha->iocount > 500) && ((ha->iocount % 200) < 2))
2417 spp->adapter_status = 0x01;
2418#endif
2419
2420 switch (spp->adapter_status) {
2421 case ASOK:
2422
2423
2424 if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)
2425 status = DID_ERROR << 16;
2426
2427
2428 else if (tstatus != GOOD && SCpnt->device->type == TYPE_DISK
2429 && ha->target_redo[SCpnt->device->id][SCpnt->
2430 device->
2431 channel])
2432 status = DID_BUS_BUSY << 16;
2433
2434
2435 else if (tstatus == CHECK_CONDITION
2436 && SCpnt->device->type == TYPE_DISK
2437 && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
2438 status = DID_BUS_BUSY << 16;
2439
2440 else
2441 status = DID_OK << 16;
2442
2443 if (tstatus == GOOD)
2444 ha->target_redo[SCpnt->device->id][SCpnt->device->
2445 channel] = 0;
2446
2447 if (spp->target_status && SCpnt->device->type == TYPE_DISK &&
2448 (!(tstatus == CHECK_CONDITION && ha->iocount <= 1000 &&
2449 (SCpnt->sense_buffer[2] & 0xf) == NOT_READY)))
2450 printk("%s: ihdlr, target %d.%d:%d, pid %ld, "
2451 "target_status 0x%x, sense key 0x%x.\n",
2452 ha->board_name,
2453 SCpnt->device->channel, SCpnt->device->id,
2454 SCpnt->device->lun, SCpnt->serial_number,
2455 spp->target_status, SCpnt->sense_buffer[2]);
2456
2457 ha->target_to[SCpnt->device->id][SCpnt->device->channel] = 0;
2458
2459 if (ha->last_retried_pid == SCpnt->serial_number)
2460 ha->retries = 0;
2461
2462 break;
2463 case ASST:
2464 case 0x02:
2465
2466 if (ha->target_to[SCpnt->device->id][SCpnt->device->channel] > 1)
2467 status = DID_ERROR << 16;
2468 else {
2469 status = DID_TIME_OUT << 16;
2470 ha->target_to[SCpnt->device->id][SCpnt->device->
2471 channel]++;
2472 }
2473
2474 break;
2475
2476
2477 case 0x03:
2478 case 0x04:
2479
2480 for (c = 0; c <= shost->max_channel; c++)
2481 for (k = 0; k < shost->max_id; k++)
2482 ha->target_redo[k][c] = 1;
2483
2484 if (SCpnt->device->type != TYPE_TAPE
2485 && ha->retries < MAX_INTERNAL_RETRIES) {
2486
2487#if defined(DID_SOFT_ERROR)
2488 status = DID_SOFT_ERROR << 16;
2489#else
2490 status = DID_BUS_BUSY << 16;
2491#endif
2492
2493 ha->retries++;
2494 ha->last_retried_pid = SCpnt->serial_number;
2495 } else
2496 status = DID_ERROR << 16;
2497
2498 break;
2499 case 0x05:
2500 case 0x06:
2501 case 0x07:
2502 case 0x08:
2503 case 0x09:
2504 case 0x0a:
2505 case 0x0b:
2506 case 0x0c:
2507 default:
2508 status = DID_ERROR << 16;
2509 break;
2510 }
2511
2512 SCpnt->result = status | spp->target_status;
2513
2514#if defined(DEBUG_INTERRUPT)
2515 if (SCpnt->result || do_trace)
2516#else
2517 if ((spp->adapter_status != ASOK && ha->iocount > 1000) ||
2518 (spp->adapter_status != ASOK &&
2519 spp->adapter_status != ASST && ha->iocount <= 1000) ||
2520 do_trace || msg_byte(spp->target_status))
2521#endif
2522 scmd_printk(KERN_INFO, SCpnt, "ihdlr, mbox %2d, err 0x%x:%x,"
2523 " pid %ld, reg 0x%x, count %d.\n",
2524 i, spp->adapter_status, spp->target_status,
2525 SCpnt->serial_number, reg, ha->iocount);
2526
2527 unmap_dma(i, ha);
2528
2529
2530 SCpnt->host_scribble = NULL;
2531
2532 SCpnt->scsi_done(SCpnt);
2533
2534 if (do_trace)
2535 printk("%s: ihdlr, exit, irq %d, count %d.\n", ha->board_name,
2536 irq, ha->iocount);
2537
2538 handled:
2539 return IRQ_HANDLED;
2540 none:
2541 return IRQ_NONE;
2542}
2543
2544static irqreturn_t do_interrupt_handler(int dummy, void *shap)
2545{
2546 struct Scsi_Host *shost;
2547 unsigned int j;
2548 unsigned long spin_flags;
2549 irqreturn_t ret;
2550
2551
2552 if ((j = (unsigned int)((char *)shap - sha)) >= num_boards)
2553 return IRQ_NONE;
2554 shost = sh[j];
2555
2556 spin_lock_irqsave(shost->host_lock, spin_flags);
2557 ret = ihdlr(shost);
2558 spin_unlock_irqrestore(shost->host_lock, spin_flags);
2559 return ret;
2560}
2561
2562static int eata2x_release(struct Scsi_Host *shost)
2563{
2564 struct hostdata *ha = (struct hostdata *)shost->hostdata;
2565 unsigned int i;
2566
2567 for (i = 0; i < shost->can_queue; i++)
2568 kfree((&ha->cp[i])->sglist);
2569
2570 for (i = 0; i < shost->can_queue; i++)
2571 pci_unmap_single(ha->pdev, ha->cp[i].cp_dma_addr,
2572 sizeof(struct mscp), PCI_DMA_BIDIRECTIONAL);
2573
2574 if (ha->sp_cpu_addr)
2575 pci_free_consistent(ha->pdev, sizeof(struct mssp),
2576 ha->sp_cpu_addr, ha->sp_dma_addr);
2577
2578 free_irq(shost->irq, &sha[ha->board_number]);
2579
2580 if (shost->dma_channel != NO_DMA)
2581 free_dma(shost->dma_channel);
2582
2583 release_region(shost->io_port, shost->n_io_port);
2584 scsi_unregister(shost);
2585 return 0;
2586}
2587
2588#include "scsi_module.c"
2589
2590#ifndef MODULE
2591__setup("eata=", option_setup);
2592#endif
2593