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 <linux/slab.h>
494#include <asm/byteorder.h>
495#include <asm/dma.h>
496#include <asm/io.h>
497#include <asm/irq.h>
498
499#include <scsi/scsi.h>
500#include <scsi/scsi_cmnd.h>
501#include <scsi/scsi_device.h>
502#include <scsi/scsi_host.h>
503#include <scsi/scsi_tcq.h>
504#include <scsi/scsicam.h>
505
506static int eata2x_detect(struct scsi_host_template *);
507static int eata2x_release(struct Scsi_Host *);
508static int eata2x_queuecommand(struct Scsi_Host *, 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];
840
841
842static unsigned int num_boards = MAX_BOARDS;
843
844static unsigned long io_port[] = {
845
846
847 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
848 SKIP, SKIP,
849
850
851 0x1f0,
852
853
854 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
855 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
856
857
858 0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88, 0x6c88, 0x7c88, 0x8c88,
859 0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88, 0xec88, 0xfc88,
860
861
862 0x170, 0x230, 0x330,
863
864
865 0x0
866};
867
868
869#define H2DEV(x) cpu_to_be32(x)
870#define DEV2H(x) be32_to_cpu(x)
871#define H2DEV16(x) cpu_to_be16(x)
872#define DEV2H16(x) be16_to_cpu(x)
873
874
875#define REG2H(x) le16_to_cpu(x)
876
877static irqreturn_t do_interrupt_handler(int, void *);
878static void flush_dev(struct scsi_device *, unsigned long, struct hostdata *,
879 unsigned int);
880static int do_trace = 0;
881static int setup_done = 0;
882static int link_statistics;
883static int ext_tran = 0;
884static int rev_scan = 1;
885
886#if defined(CONFIG_SCSI_EATA_TAGGED_QUEUE)
887static int tag_mode = TAG_SIMPLE;
888#else
889static int tag_mode = TAG_DISABLED;
890#endif
891
892#if defined(CONFIG_SCSI_EATA_LINKED_COMMANDS)
893static int linked_comm = 1;
894#else
895static int linked_comm = 0;
896#endif
897
898#if defined(CONFIG_SCSI_EATA_MAX_TAGS)
899static int max_queue_depth = CONFIG_SCSI_EATA_MAX_TAGS;
900#else
901static int max_queue_depth = MAX_CMD_PER_LUN;
902#endif
903
904#if defined(CONFIG_ISA)
905static int isa_probe = 1;
906#else
907static int isa_probe = 0;
908#endif
909
910#if defined(CONFIG_EISA)
911static int eisa_probe = 1;
912#else
913static int eisa_probe = 0;
914#endif
915
916#if defined(CONFIG_PCI)
917static int pci_probe = 1;
918#else
919static int pci_probe = 0;
920#endif
921
922#define MAX_INT_PARAM 10
923#define MAX_BOOT_OPTIONS_SIZE 256
924static char boot_options[MAX_BOOT_OPTIONS_SIZE];
925
926#if defined(MODULE)
927#include <linux/module.h>
928#include <linux/moduleparam.h>
929
930module_param_string(eata, boot_options, MAX_BOOT_OPTIONS_SIZE, 0);
931MODULE_PARM_DESC(eata, " equivalent to the \"eata=...\" kernel boot option."
932 " Example: modprobe eata \"eata=0x7410,0x230,lc:y,tm:0,mq:4,ep:n\"");
933MODULE_AUTHOR("Dario Ballabio");
934MODULE_LICENSE("GPL");
935MODULE_DESCRIPTION("EATA/DMA SCSI Driver");
936
937#endif
938
939static int eata2x_slave_configure(struct scsi_device *dev)
940{
941 int tqd, utqd;
942 char *tag_suffix, *link_suffix;
943
944 utqd = MAX_CMD_PER_LUN;
945 tqd = max_queue_depth;
946
947 if (TLDEV(dev->type) && dev->tagged_supported) {
948 if (tag_mode == TAG_SIMPLE) {
949 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, tqd);
950 tag_suffix = ", simple tags";
951 } else if (tag_mode == TAG_ORDERED) {
952 scsi_adjust_queue_depth(dev, MSG_ORDERED_TAG, tqd);
953 tag_suffix = ", ordered tags";
954 } else {
955 scsi_adjust_queue_depth(dev, 0, tqd);
956 tag_suffix = ", no tags";
957 }
958 } else if (TLDEV(dev->type) && linked_comm) {
959 scsi_adjust_queue_depth(dev, 0, tqd);
960 tag_suffix = ", untagged";
961 } else {
962 scsi_adjust_queue_depth(dev, 0, utqd);
963 tag_suffix = "";
964 }
965
966 if (TLDEV(dev->type) && linked_comm && dev->queue_depth > 2)
967 link_suffix = ", sorted";
968 else if (TLDEV(dev->type))
969 link_suffix = ", unsorted";
970 else
971 link_suffix = "";
972
973 sdev_printk(KERN_INFO, dev,
974 "cmds/lun %d%s%s.\n",
975 dev->queue_depth, link_suffix, tag_suffix);
976
977 return 0;
978}
979
980static int wait_on_busy(unsigned long iobase, unsigned int loop)
981{
982 while (inb(iobase + REG_AUX_STATUS) & ABSY_ASSERTED) {
983 udelay(1L);
984 if (--loop == 0)
985 return 1;
986 }
987 return 0;
988}
989
990static int do_dma(unsigned long iobase, unsigned long addr, unchar cmd)
991{
992 unsigned char *byaddr;
993 unsigned long devaddr;
994
995 if (wait_on_busy(iobase, (addr ? MAXLOOP * 100 : MAXLOOP)))
996 return 1;
997
998 if (addr) {
999 devaddr = H2DEV(addr);
1000 byaddr = (unsigned char *)&devaddr;
1001 outb(byaddr[3], iobase + REG_LOW);
1002 outb(byaddr[2], iobase + REG_LM);
1003 outb(byaddr[1], iobase + REG_MID);
1004 outb(byaddr[0], iobase + REG_MSB);
1005 }
1006
1007 outb(cmd, iobase + REG_CMD);
1008 return 0;
1009}
1010
1011static int read_pio(unsigned long iobase, ushort * start, ushort * end)
1012{
1013 unsigned int loop = MAXLOOP;
1014 ushort *p;
1015
1016 for (p = start; p <= end; p++) {
1017 while (!(inb(iobase + REG_STATUS) & DRQ_ASSERTED)) {
1018 udelay(1L);
1019 if (--loop == 0)
1020 return 1;
1021 }
1022 loop = MAXLOOP;
1023 *p = REG2H(inw(iobase));
1024 }
1025
1026 return 0;
1027}
1028
1029static struct pci_dev *get_pci_dev(unsigned long port_base)
1030{
1031#if defined(CONFIG_PCI)
1032 unsigned int addr;
1033 struct pci_dev *dev = NULL;
1034
1035 while ((dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {
1036 addr = pci_resource_start(dev, 0);
1037
1038#if defined(DEBUG_PCI_DETECT)
1039 printk("%s: get_pci_dev, bus %d, devfn 0x%x, addr 0x%x.\n",
1040 driver_name, dev->bus->number, dev->devfn, addr);
1041#endif
1042
1043
1044
1045
1046
1047 pci_dev_put(dev);
1048 if (addr + PCI_BASE_ADDRESS_0 == port_base)
1049 return dev;
1050 }
1051#endif
1052 return NULL;
1053}
1054
1055static void enable_pci_ports(void)
1056{
1057#if defined(CONFIG_PCI)
1058 struct pci_dev *dev = NULL;
1059
1060 while ((dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {
1061#if defined(DEBUG_PCI_DETECT)
1062 printk("%s: enable_pci_ports, bus %d, devfn 0x%x.\n",
1063 driver_name, dev->bus->number, dev->devfn);
1064#endif
1065
1066 if (pci_enable_device(dev))
1067 printk
1068 ("%s: warning, pci_enable_device failed, bus %d devfn 0x%x.\n",
1069 driver_name, dev->bus->number, dev->devfn);
1070 }
1071
1072#endif
1073}
1074
1075static int port_detect(unsigned long port_base, unsigned int j,
1076 struct scsi_host_template *tpnt)
1077{
1078 unsigned char irq, dma_channel, subversion, i, is_pci = 0;
1079 unsigned char protocol_rev;
1080 struct eata_info info;
1081 char *bus_type, dma_name[16];
1082 struct pci_dev *pdev;
1083
1084 unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
1085 struct Scsi_Host *shost;
1086 struct hostdata *ha;
1087 char name[16];
1088
1089 sprintf(name, "%s%d", driver_name, j);
1090
1091 if (!request_region(port_base, REGION_SIZE, driver_name)) {
1092#if defined(DEBUG_DETECT)
1093 printk("%s: address 0x%03lx in use, skipping probe.\n", name,
1094 port_base);
1095#endif
1096 goto fail;
1097 }
1098
1099 if (do_dma(port_base, 0, READ_CONFIG_PIO)) {
1100#if defined(DEBUG_DETECT)
1101 printk("%s: detect, do_dma failed at 0x%03lx.\n", name,
1102 port_base);
1103#endif
1104 goto freelock;
1105 }
1106
1107
1108 if (read_pio(port_base, (ushort *) & info, (ushort *) & info.ipad[0])) {
1109#if defined(DEBUG_DETECT)
1110 printk("%s: detect, read_pio failed at 0x%03lx.\n", name,
1111 port_base);
1112#endif
1113 goto freelock;
1114 }
1115
1116 info.data_len = DEV2H(info.data_len);
1117 info.sign = DEV2H(info.sign);
1118 info.cp_pad_len = DEV2H16(info.cp_pad_len);
1119 info.cp_len = DEV2H(info.cp_len);
1120 info.sp_len = DEV2H(info.sp_len);
1121 info.scatt_size = DEV2H16(info.scatt_size);
1122 info.queue_size = DEV2H16(info.queue_size);
1123
1124
1125 if (info.sign != EATA_SIG_BE) {
1126#if defined(DEBUG_DETECT)
1127 printk("%s: signature 0x%04x discarded.\n", name, info.sign);
1128#endif
1129 goto freelock;
1130 }
1131
1132 if (info.data_len < EATA_2_0A_SIZE) {
1133 printk
1134 ("%s: config structure size (%d bytes) too short, detaching.\n",
1135 name, info.data_len);
1136 goto freelock;
1137 } else if (info.data_len == EATA_2_0A_SIZE)
1138 protocol_rev = 'A';
1139 else if (info.data_len == EATA_2_0B_SIZE)
1140 protocol_rev = 'B';
1141 else
1142 protocol_rev = 'C';
1143
1144 if (protocol_rev != 'A' && info.forcaddr) {
1145 printk("%s: warning, port address has been forced.\n", name);
1146 bus_type = "PCI";
1147 is_pci = 1;
1148 subversion = ESA;
1149 } else if (port_base > MAX_EISA_ADDR
1150 || (protocol_rev == 'C' && info.pci)) {
1151 bus_type = "PCI";
1152 is_pci = 1;
1153 subversion = ESA;
1154 } else if (port_base >= MIN_EISA_ADDR
1155 || (protocol_rev == 'C' && info.eisa)) {
1156 bus_type = "EISA";
1157 subversion = ESA;
1158 } else if (protocol_rev == 'C' && !info.eisa && !info.pci) {
1159 bus_type = "ISA";
1160 subversion = ISA;
1161 } else if (port_base > MAX_ISA_ADDR) {
1162 bus_type = "PCI";
1163 is_pci = 1;
1164 subversion = ESA;
1165 } else {
1166 bus_type = "ISA";
1167 subversion = ISA;
1168 }
1169
1170 if (!info.haaval || info.ata) {
1171 printk
1172 ("%s: address 0x%03lx, unusable %s board (%d%d), detaching.\n",
1173 name, port_base, bus_type, info.haaval, info.ata);
1174 goto freelock;
1175 }
1176
1177 if (info.drqvld) {
1178 if (subversion == ESA)
1179 printk("%s: warning, weird %s board using DMA.\n", name,
1180 bus_type);
1181
1182 subversion = ISA;
1183 dma_channel = dma_channel_table[3 - info.drqx];
1184 } else {
1185 if (subversion == ISA)
1186 printk("%s: warning, weird %s board not using DMA.\n",
1187 name, bus_type);
1188
1189 subversion = ESA;
1190 dma_channel = NO_DMA;
1191 }
1192
1193 if (!info.dmasup)
1194 printk("%s: warning, DMA protocol support not asserted.\n",
1195 name);
1196
1197 irq = info.irq;
1198
1199 if (subversion == ESA && !info.irq_tr)
1200 printk
1201 ("%s: warning, LEVEL triggering is suggested for IRQ %u.\n",
1202 name, irq);
1203
1204 if (is_pci) {
1205 pdev = get_pci_dev(port_base);
1206 if (!pdev)
1207 printk
1208 ("%s: warning, failed to get pci_dev structure.\n",
1209 name);
1210 } else
1211 pdev = NULL;
1212
1213 if (pdev && (irq != pdev->irq)) {
1214 printk("%s: IRQ %u mapped to IO-APIC IRQ %u.\n", name, irq,
1215 pdev->irq);
1216 irq = pdev->irq;
1217 }
1218
1219
1220 if (request_irq(irq, do_interrupt_handler,
1221 (subversion == ESA) ? IRQF_SHARED : 0,
1222 driver_name, (void *)&sha[j])) {
1223 printk("%s: unable to allocate IRQ %u, detaching.\n", name,
1224 irq);
1225 goto freelock;
1226 }
1227
1228 if (subversion == ISA && request_dma(dma_channel, driver_name)) {
1229 printk("%s: unable to allocate DMA channel %u, detaching.\n",
1230 name, dma_channel);
1231 goto freeirq;
1232 }
1233#if defined(FORCE_CONFIG)
1234 {
1235 struct eata_config *cf;
1236 dma_addr_t cf_dma_addr;
1237
1238 cf = pci_zalloc_consistent(pdev, sizeof(struct eata_config),
1239 &cf_dma_addr);
1240
1241 if (!cf) {
1242 printk
1243 ("%s: config, pci_alloc_consistent failed, detaching.\n",
1244 name);
1245 goto freedma;
1246 }
1247
1248
1249 cf->len = (ushort) H2DEV16((ushort) 510);
1250 cf->ocena = 1;
1251
1252 if (do_dma(port_base, cf_dma_addr, SET_CONFIG_DMA)) {
1253 printk
1254 ("%s: busy timeout sending configuration, detaching.\n",
1255 name);
1256 pci_free_consistent(pdev, sizeof(struct eata_config),
1257 cf, cf_dma_addr);
1258 goto freedma;
1259 }
1260
1261 }
1262#endif
1263
1264 sh[j] = shost = scsi_register(tpnt, sizeof(struct hostdata));
1265 if (shost == NULL) {
1266 printk("%s: unable to register host, detaching.\n", name);
1267 goto freedma;
1268 }
1269
1270 shost->io_port = port_base;
1271 shost->unique_id = port_base;
1272 shost->n_io_port = REGION_SIZE;
1273 shost->dma_channel = dma_channel;
1274 shost->irq = irq;
1275 shost->sg_tablesize = (ushort) info.scatt_size;
1276 shost->this_id = (ushort) info.host_addr[3];
1277 shost->can_queue = (ushort) info.queue_size;
1278 shost->cmd_per_lun = MAX_CMD_PER_LUN;
1279
1280 ha = (struct hostdata *)shost->hostdata;
1281
1282 memset(ha, 0, sizeof(struct hostdata));
1283 ha->subversion = subversion;
1284 ha->protocol_rev = protocol_rev;
1285 ha->is_pci = is_pci;
1286 ha->pdev = pdev;
1287 ha->board_number = j;
1288
1289 if (ha->subversion == ESA)
1290 shost->unchecked_isa_dma = 0;
1291 else {
1292 unsigned long flags;
1293 shost->unchecked_isa_dma = 1;
1294
1295 flags = claim_dma_lock();
1296 disable_dma(dma_channel);
1297 clear_dma_ff(dma_channel);
1298 set_dma_mode(dma_channel, DMA_MODE_CASCADE);
1299 enable_dma(dma_channel);
1300 release_dma_lock(flags);
1301
1302 }
1303
1304 strcpy(ha->board_name, name);
1305
1306
1307 if (shost->sg_tablesize > MAX_SGLIST || shost->sg_tablesize < 2) {
1308 printk("%s: detect, wrong n. of SG lists %d, fixed.\n",
1309 ha->board_name, shost->sg_tablesize);
1310 shost->sg_tablesize = MAX_SGLIST;
1311 }
1312
1313
1314 if (shost->can_queue > MAX_MAILBOXES || shost->can_queue < 2) {
1315 printk("%s: detect, wrong n. of mbox %d, fixed.\n",
1316 ha->board_name, shost->can_queue);
1317 shost->can_queue = MAX_MAILBOXES;
1318 }
1319
1320 if (protocol_rev != 'A') {
1321 if (info.max_chan > 0 && info.max_chan < MAX_CHANNEL)
1322 shost->max_channel = info.max_chan;
1323
1324 if (info.max_id > 7 && info.max_id < MAX_TARGET)
1325 shost->max_id = info.max_id + 1;
1326
1327 if (info.large_sg && shost->sg_tablesize == MAX_SGLIST)
1328 shost->sg_tablesize = MAX_LARGE_SGLIST;
1329 }
1330
1331 if (protocol_rev == 'C') {
1332 if (info.max_lun > 7 && info.max_lun < MAX_LUN)
1333 shost->max_lun = info.max_lun + 1;
1334 }
1335
1336 if (dma_channel == NO_DMA)
1337 sprintf(dma_name, "%s", "BMST");
1338 else
1339 sprintf(dma_name, "DMA %u", dma_channel);
1340
1341 for (i = 0; i < shost->can_queue; i++)
1342 ha->cp[i].cp_dma_addr = pci_map_single(ha->pdev,
1343 &ha->cp[i],
1344 sizeof(struct mscp),
1345 PCI_DMA_BIDIRECTIONAL);
1346
1347 for (i = 0; i < shost->can_queue; i++) {
1348 size_t sz = shost->sg_tablesize *sizeof(struct sg_list);
1349 gfp_t gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC;
1350 ha->cp[i].sglist = kmalloc(sz, gfp_mask);
1351 if (!ha->cp[i].sglist) {
1352 printk
1353 ("%s: kmalloc SGlist failed, mbox %d, detaching.\n",
1354 ha->board_name, i);
1355 goto release;
1356 }
1357 }
1358
1359 if (!(ha->sp_cpu_addr = pci_alloc_consistent(ha->pdev,
1360 sizeof(struct mssp),
1361 &ha->sp_dma_addr))) {
1362 printk("%s: pci_alloc_consistent failed, detaching.\n", ha->board_name);
1363 goto release;
1364 }
1365
1366 if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN)
1367 max_queue_depth = MAX_TAGGED_CMD_PER_LUN;
1368
1369 if (max_queue_depth < MAX_CMD_PER_LUN)
1370 max_queue_depth = MAX_CMD_PER_LUN;
1371
1372 if (tag_mode != TAG_DISABLED && tag_mode != TAG_SIMPLE)
1373 tag_mode = TAG_ORDERED;
1374
1375 if (j == 0) {
1376 printk
1377 ("EATA/DMA 2.0x: Copyright (C) 1994-2003 Dario Ballabio.\n");
1378 printk
1379 ("%s config options -> tm:%d, lc:%c, mq:%d, rs:%c, et:%c, "
1380 "ip:%c, ep:%c, pp:%c.\n", driver_name, tag_mode,
1381 YESNO(linked_comm), max_queue_depth, YESNO(rev_scan),
1382 YESNO(ext_tran), YESNO(isa_probe), YESNO(eisa_probe),
1383 YESNO(pci_probe));
1384 }
1385
1386 printk("%s: 2.0%c, %s 0x%03lx, IRQ %u, %s, SG %d, MB %d.\n",
1387 ha->board_name, ha->protocol_rev, bus_type,
1388 (unsigned long)shost->io_port, shost->irq, dma_name,
1389 shost->sg_tablesize, shost->can_queue);
1390
1391 if (shost->max_id > 8 || shost->max_lun > 8)
1392 printk
1393 ("%s: wide SCSI support enabled, max_id %u, max_lun %llu.\n",
1394 ha->board_name, shost->max_id, shost->max_lun);
1395
1396 for (i = 0; i <= shost->max_channel; i++)
1397 printk("%s: SCSI channel %u enabled, host target ID %d.\n",
1398 ha->board_name, i, info.host_addr[3 - i]);
1399
1400#if defined(DEBUG_DETECT)
1401 printk("%s: Vers. 0x%x, ocs %u, tar %u, trnxfr %u, more %u, SYNC 0x%x, "
1402 "sec. %u, infol %d, cpl %d spl %d.\n", name, info.version,
1403 info.ocsena, info.tarsup, info.trnxfr, info.morsup, info.sync,
1404 info.second, info.data_len, info.cp_len, info.sp_len);
1405
1406 if (protocol_rev == 'B' || protocol_rev == 'C')
1407 printk("%s: isaena %u, forcaddr %u, max_id %u, max_chan %u, "
1408 "large_sg %u, res1 %u.\n", name, info.isaena,
1409 info.forcaddr, info.max_id, info.max_chan, info.large_sg,
1410 info.res1);
1411
1412 if (protocol_rev == 'C')
1413 printk("%s: max_lun %u, m1 %u, idquest %u, pci %u, eisa %u, "
1414 "raidnum %u.\n", name, info.max_lun, info.m1,
1415 info.idquest, info.pci, info.eisa, info.raidnum);
1416#endif
1417
1418 if (ha->pdev) {
1419 pci_set_master(ha->pdev);
1420 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)))
1421 printk("%s: warning, pci_set_dma_mask failed.\n",
1422 ha->board_name);
1423 }
1424
1425 return 1;
1426
1427 freedma:
1428 if (subversion == ISA)
1429 free_dma(dma_channel);
1430 freeirq:
1431 free_irq(irq, &sha[j]);
1432 freelock:
1433 release_region(port_base, REGION_SIZE);
1434 fail:
1435 return 0;
1436
1437 release:
1438 eata2x_release(shost);
1439 return 0;
1440}
1441
1442static void internal_setup(char *str, int *ints)
1443{
1444 int i, argc = ints[0];
1445 char *cur = str, *pc;
1446
1447 if (argc > 0) {
1448 if (argc > MAX_INT_PARAM)
1449 argc = MAX_INT_PARAM;
1450
1451 for (i = 0; i < argc; i++)
1452 io_port[i] = ints[i + 1];
1453
1454 io_port[i] = 0;
1455 setup_done = 1;
1456 }
1457
1458 while (cur && (pc = strchr(cur, ':'))) {
1459 int val = 0, c = *++pc;
1460
1461 if (c == 'n' || c == 'N')
1462 val = 0;
1463 else if (c == 'y' || c == 'Y')
1464 val = 1;
1465 else
1466 val = (int)simple_strtoul(pc, NULL, 0);
1467
1468 if (!strncmp(cur, "lc:", 3))
1469 linked_comm = val;
1470 else if (!strncmp(cur, "tm:", 3))
1471 tag_mode = val;
1472 else if (!strncmp(cur, "tc:", 3))
1473 tag_mode = val;
1474 else if (!strncmp(cur, "mq:", 3))
1475 max_queue_depth = val;
1476 else if (!strncmp(cur, "ls:", 3))
1477 link_statistics = val;
1478 else if (!strncmp(cur, "et:", 3))
1479 ext_tran = val;
1480 else if (!strncmp(cur, "rs:", 3))
1481 rev_scan = val;
1482 else if (!strncmp(cur, "ip:", 3))
1483 isa_probe = val;
1484 else if (!strncmp(cur, "ep:", 3))
1485 eisa_probe = val;
1486 else if (!strncmp(cur, "pp:", 3))
1487 pci_probe = val;
1488
1489 if ((cur = strchr(cur, ',')))
1490 ++cur;
1491 }
1492
1493 return;
1494}
1495
1496static int option_setup(char *str)
1497{
1498 int ints[MAX_INT_PARAM];
1499 char *cur = str;
1500 int i = 1;
1501
1502 while (cur && isdigit(*cur) && i < MAX_INT_PARAM) {
1503 ints[i++] = simple_strtoul(cur, NULL, 0);
1504
1505 if ((cur = strchr(cur, ',')) != NULL)
1506 cur++;
1507 }
1508
1509 ints[0] = i - 1;
1510 internal_setup(cur, ints);
1511 return 1;
1512}
1513
1514static void add_pci_ports(void)
1515{
1516#if defined(CONFIG_PCI)
1517 unsigned int addr, k;
1518 struct pci_dev *dev = NULL;
1519
1520 for (k = 0; k < MAX_PCI; k++) {
1521
1522 if (!(dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev)))
1523 break;
1524
1525 if (pci_enable_device(dev)) {
1526#if defined(DEBUG_PCI_DETECT)
1527 printk
1528 ("%s: detect, bus %d, devfn 0x%x, pci_enable_device failed.\n",
1529 driver_name, dev->bus->number, dev->devfn);
1530#endif
1531
1532 continue;
1533 }
1534
1535 addr = pci_resource_start(dev, 0);
1536
1537#if defined(DEBUG_PCI_DETECT)
1538 printk("%s: detect, seq. %d, bus %d, devfn 0x%x, addr 0x%x.\n",
1539 driver_name, k, dev->bus->number, dev->devfn, addr);
1540#endif
1541
1542
1543 io_port[MAX_INT_PARAM + (rev_scan ? (MAX_PCI - k) : (1 + k))] =
1544 addr + PCI_BASE_ADDRESS_0;
1545 }
1546
1547 pci_dev_put(dev);
1548#endif
1549}
1550
1551static int eata2x_detect(struct scsi_host_template *tpnt)
1552{
1553 unsigned int j = 0, k;
1554
1555 tpnt->proc_name = "eata2x";
1556
1557 if (strlen(boot_options))
1558 option_setup(boot_options);
1559
1560#if defined(MODULE)
1561
1562 if (io_port[0] != SKIP) {
1563 setup_done = 1;
1564 io_port[MAX_INT_PARAM] = 0;
1565 }
1566#endif
1567
1568 for (k = MAX_INT_PARAM; io_port[k]; k++)
1569 if (io_port[k] == SKIP)
1570 continue;
1571 else if (io_port[k] <= MAX_ISA_ADDR) {
1572 if (!isa_probe)
1573 io_port[k] = SKIP;
1574 } else if (io_port[k] >= MIN_EISA_ADDR
1575 && io_port[k] <= MAX_EISA_ADDR) {
1576 if (!eisa_probe)
1577 io_port[k] = SKIP;
1578 }
1579
1580 if (pci_probe) {
1581 if (!setup_done)
1582 add_pci_ports();
1583 else
1584 enable_pci_ports();
1585 }
1586
1587 for (k = 0; io_port[k]; k++) {
1588
1589 if (io_port[k] == SKIP)
1590 continue;
1591
1592 if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt))
1593 j++;
1594 }
1595
1596 num_boards = j;
1597 return j;
1598}
1599
1600static void map_dma(unsigned int i, struct hostdata *ha)
1601{
1602 unsigned int k, pci_dir;
1603 int count;
1604 struct scatterlist *sg;
1605 struct mscp *cpp;
1606 struct scsi_cmnd *SCpnt;
1607
1608 cpp = &ha->cp[i];
1609 SCpnt = cpp->SCpnt;
1610 pci_dir = SCpnt->sc_data_direction;
1611
1612 if (SCpnt->sense_buffer)
1613 cpp->sense_addr =
1614 H2DEV(pci_map_single(ha->pdev, SCpnt->sense_buffer,
1615 SCSI_SENSE_BUFFERSIZE, PCI_DMA_FROMDEVICE));
1616
1617 cpp->sense_len = SCSI_SENSE_BUFFERSIZE;
1618
1619 if (!scsi_sg_count(SCpnt)) {
1620 cpp->data_len = 0;
1621 return;
1622 }
1623
1624 count = pci_map_sg(ha->pdev, scsi_sglist(SCpnt), scsi_sg_count(SCpnt),
1625 pci_dir);
1626 BUG_ON(!count);
1627
1628 scsi_for_each_sg(SCpnt, sg, count, k) {
1629 cpp->sglist[k].address = H2DEV(sg_dma_address(sg));
1630 cpp->sglist[k].num_bytes = H2DEV(sg_dma_len(sg));
1631 }
1632
1633 cpp->sg = 1;
1634 cpp->data_address = H2DEV(pci_map_single(ha->pdev, cpp->sglist,
1635 scsi_sg_count(SCpnt) *
1636 sizeof(struct sg_list),
1637 pci_dir));
1638 cpp->data_len = H2DEV((scsi_sg_count(SCpnt) * sizeof(struct sg_list)));
1639}
1640
1641static void unmap_dma(unsigned int i, struct hostdata *ha)
1642{
1643 unsigned int pci_dir;
1644 struct mscp *cpp;
1645 struct scsi_cmnd *SCpnt;
1646
1647 cpp = &ha->cp[i];
1648 SCpnt = cpp->SCpnt;
1649 pci_dir = SCpnt->sc_data_direction;
1650
1651 if (DEV2H(cpp->sense_addr))
1652 pci_unmap_single(ha->pdev, DEV2H(cpp->sense_addr),
1653 DEV2H(cpp->sense_len), PCI_DMA_FROMDEVICE);
1654
1655 if (scsi_sg_count(SCpnt))
1656 pci_unmap_sg(ha->pdev, scsi_sglist(SCpnt), scsi_sg_count(SCpnt),
1657 pci_dir);
1658
1659 if (!DEV2H(cpp->data_len))
1660 pci_dir = PCI_DMA_BIDIRECTIONAL;
1661
1662 if (DEV2H(cpp->data_address))
1663 pci_unmap_single(ha->pdev, DEV2H(cpp->data_address),
1664 DEV2H(cpp->data_len), pci_dir);
1665}
1666
1667static void sync_dma(unsigned int i, struct hostdata *ha)
1668{
1669 unsigned int pci_dir;
1670 struct mscp *cpp;
1671 struct scsi_cmnd *SCpnt;
1672
1673 cpp = &ha->cp[i];
1674 SCpnt = cpp->SCpnt;
1675 pci_dir = SCpnt->sc_data_direction;
1676
1677 if (DEV2H(cpp->sense_addr))
1678 pci_dma_sync_single_for_cpu(ha->pdev, DEV2H(cpp->sense_addr),
1679 DEV2H(cpp->sense_len),
1680 PCI_DMA_FROMDEVICE);
1681
1682 if (scsi_sg_count(SCpnt))
1683 pci_dma_sync_sg_for_cpu(ha->pdev, scsi_sglist(SCpnt),
1684 scsi_sg_count(SCpnt), pci_dir);
1685
1686 if (!DEV2H(cpp->data_len))
1687 pci_dir = PCI_DMA_BIDIRECTIONAL;
1688
1689 if (DEV2H(cpp->data_address))
1690 pci_dma_sync_single_for_cpu(ha->pdev,
1691 DEV2H(cpp->data_address),
1692 DEV2H(cpp->data_len), pci_dir);
1693}
1694
1695static void scsi_to_dev_dir(unsigned int i, struct hostdata *ha)
1696{
1697 unsigned int k;
1698
1699 static const unsigned char data_out_cmds[] = {
1700 0x0a, 0x2a, 0x15, 0x55, 0x04, 0x07, 0x18, 0x1d, 0x24, 0x2e,
1701 0x30, 0x31, 0x32, 0x38, 0x39, 0x3a, 0x3b, 0x3d, 0x3f, 0x40,
1702 0x41, 0x4c, 0xaa, 0xae, 0xb0, 0xb1, 0xb2, 0xb6, 0xea, 0x1b, 0x5d
1703 };
1704
1705 static const unsigned char data_none_cmds[] = {
1706 0x01, 0x0b, 0x10, 0x11, 0x13, 0x16, 0x17, 0x19, 0x2b, 0x1e,
1707 0x2c, 0xac, 0x2f, 0xaf, 0x33, 0xb3, 0x35, 0x36, 0x45, 0x47,
1708 0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5, 0x00
1709 };
1710
1711 struct mscp *cpp;
1712 struct scsi_cmnd *SCpnt;
1713
1714 cpp = &ha->cp[i];
1715 SCpnt = cpp->SCpnt;
1716
1717 if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
1718 cpp->din = 1;
1719 cpp->dout = 0;
1720 return;
1721 } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
1722 cpp->din = 0;
1723 cpp->dout = 1;
1724 return;
1725 } else if (SCpnt->sc_data_direction == DMA_NONE) {
1726 cpp->din = 0;
1727 cpp->dout = 0;
1728 return;
1729 }
1730
1731 if (SCpnt->sc_data_direction != DMA_BIDIRECTIONAL)
1732 panic("%s: qcomm, invalid SCpnt->sc_data_direction.\n",
1733 ha->board_name);
1734
1735 for (k = 0; k < ARRAY_SIZE(data_out_cmds); k++)
1736 if (SCpnt->cmnd[0] == data_out_cmds[k]) {
1737 cpp->dout = 1;
1738 break;
1739 }
1740
1741 if ((cpp->din = !cpp->dout))
1742 for (k = 0; k < ARRAY_SIZE(data_none_cmds); k++)
1743 if (SCpnt->cmnd[0] == data_none_cmds[k]) {
1744 cpp->din = 0;
1745 break;
1746 }
1747
1748}
1749
1750static int eata2x_queuecommand_lck(struct scsi_cmnd *SCpnt,
1751 void (*done) (struct scsi_cmnd *))
1752{
1753 struct Scsi_Host *shost = SCpnt->device->host;
1754 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1755 unsigned int i, k;
1756 struct mscp *cpp;
1757
1758 if (SCpnt->host_scribble)
1759 panic("%s: qcomm, SCpnt %p already active.\n",
1760 ha->board_name, SCpnt);
1761
1762
1763
1764 i = ha->last_cp_used + 1;
1765
1766 for (k = 0; k < shost->can_queue; k++, i++) {
1767 if (i >= shost->can_queue)
1768 i = 0;
1769 if (ha->cp_stat[i] == FREE) {
1770 ha->last_cp_used = i;
1771 break;
1772 }
1773 }
1774
1775 if (k == shost->can_queue) {
1776 printk("%s: qcomm, no free mailbox.\n", ha->board_name);
1777 return 1;
1778 }
1779
1780
1781 cpp = &ha->cp[i];
1782
1783 memset(cpp, 0, sizeof(struct mscp) - CP_TAIL_SIZE);
1784
1785
1786 cpp->sp_dma_addr = H2DEV(ha->sp_dma_addr);
1787
1788 SCpnt->scsi_done = done;
1789 cpp->cpp_index = i;
1790 SCpnt->host_scribble = (unsigned char *)&cpp->cpp_index;
1791
1792 if (do_trace)
1793 scmd_printk(KERN_INFO, SCpnt,
1794 "qcomm, mbox %d.\n", i);
1795
1796 cpp->reqsen = 1;
1797 cpp->dispri = 1;
1798#if 0
1799 if (SCpnt->device->type == TYPE_TAPE)
1800 cpp->hbaci = 1;
1801#endif
1802 cpp->one = 1;
1803 cpp->channel = SCpnt->device->channel;
1804 cpp->target = SCpnt->device->id;
1805 cpp->lun = SCpnt->device->lun;
1806 cpp->SCpnt = SCpnt;
1807 memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len);
1808
1809
1810 scsi_to_dev_dir(i, ha);
1811
1812
1813 map_dma(i, ha);
1814
1815 if (linked_comm && SCpnt->device->queue_depth > 2
1816 && TLDEV(SCpnt->device->type)) {
1817 ha->cp_stat[i] = READY;
1818 flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), ha, 0);
1819 return 0;
1820 }
1821
1822
1823 if (do_dma(shost->io_port, cpp->cp_dma_addr, SEND_CP_DMA)) {
1824 unmap_dma(i, ha);
1825 SCpnt->host_scribble = NULL;
1826 scmd_printk(KERN_INFO, SCpnt, "qcomm, adapter busy.\n");
1827 return 1;
1828 }
1829
1830 ha->cp_stat[i] = IN_USE;
1831 return 0;
1832}
1833
1834static DEF_SCSI_QCMD(eata2x_queuecommand)
1835
1836static int eata2x_eh_abort(struct scsi_cmnd *SCarg)
1837{
1838 struct Scsi_Host *shost = SCarg->device->host;
1839 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1840 unsigned int i;
1841
1842 if (SCarg->host_scribble == NULL) {
1843 scmd_printk(KERN_INFO, SCarg, "abort, cmd inactive.\n");
1844 return SUCCESS;
1845 }
1846
1847 i = *(unsigned int *)SCarg->host_scribble;
1848 scmd_printk(KERN_WARNING, SCarg, "abort, mbox %d.\n", i);
1849
1850 if (i >= shost->can_queue)
1851 panic("%s: abort, invalid SCarg->host_scribble.\n", ha->board_name);
1852
1853 if (wait_on_busy(shost->io_port, MAXLOOP)) {
1854 printk("%s: abort, timeout error.\n", ha->board_name);
1855 return FAILED;
1856 }
1857
1858 if (ha->cp_stat[i] == FREE) {
1859 printk("%s: abort, mbox %d is free.\n", ha->board_name, i);
1860 return SUCCESS;
1861 }
1862
1863 if (ha->cp_stat[i] == IN_USE) {
1864 printk("%s: abort, mbox %d is in use.\n", ha->board_name, i);
1865
1866 if (SCarg != ha->cp[i].SCpnt)
1867 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1868 ha->board_name, i, SCarg, ha->cp[i].SCpnt);
1869
1870 if (inb(shost->io_port + REG_AUX_STATUS) & IRQ_ASSERTED)
1871 printk("%s: abort, mbox %d, interrupt pending.\n",
1872 ha->board_name, i);
1873
1874 return FAILED;
1875 }
1876
1877 if (ha->cp_stat[i] == IN_RESET) {
1878 printk("%s: abort, mbox %d is in reset.\n", ha->board_name, i);
1879 return FAILED;
1880 }
1881
1882 if (ha->cp_stat[i] == LOCKED) {
1883 printk("%s: abort, mbox %d is locked.\n", ha->board_name, i);
1884 return SUCCESS;
1885 }
1886
1887 if (ha->cp_stat[i] == READY || ha->cp_stat[i] == ABORTING) {
1888 unmap_dma(i, ha);
1889 SCarg->result = DID_ABORT << 16;
1890 SCarg->host_scribble = NULL;
1891 ha->cp_stat[i] = FREE;
1892 printk("%s, abort, mbox %d ready, DID_ABORT, done.\n",
1893 ha->board_name, i);
1894 SCarg->scsi_done(SCarg);
1895 return SUCCESS;
1896 }
1897
1898 panic("%s: abort, mbox %d, invalid cp_stat.\n", ha->board_name, i);
1899}
1900
1901static int eata2x_eh_host_reset(struct scsi_cmnd *SCarg)
1902{
1903 unsigned int i, time, k, c, limit = 0;
1904 int arg_done = 0;
1905 struct scsi_cmnd *SCpnt;
1906 struct Scsi_Host *shost = SCarg->device->host;
1907 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1908
1909 scmd_printk(KERN_INFO, SCarg, "reset, enter.\n");
1910
1911 spin_lock_irq(shost->host_lock);
1912
1913 if (SCarg->host_scribble == NULL)
1914 printk("%s: reset, inactive.\n", ha->board_name);
1915
1916 if (ha->in_reset) {
1917 printk("%s: reset, exit, already in reset.\n", ha->board_name);
1918 spin_unlock_irq(shost->host_lock);
1919 return FAILED;
1920 }
1921
1922 if (wait_on_busy(shost->io_port, MAXLOOP)) {
1923 printk("%s: reset, exit, timeout error.\n", ha->board_name);
1924 spin_unlock_irq(shost->host_lock);
1925 return FAILED;
1926 }
1927
1928 ha->retries = 0;
1929
1930 for (c = 0; c <= shost->max_channel; c++)
1931 for (k = 0; k < shost->max_id; k++) {
1932 ha->target_redo[k][c] = 1;
1933 ha->target_to[k][c] = 0;
1934 }
1935
1936 for (i = 0; i < shost->can_queue; i++) {
1937
1938 if (ha->cp_stat[i] == FREE)
1939 continue;
1940
1941 if (ha->cp_stat[i] == LOCKED) {
1942 ha->cp_stat[i] = FREE;
1943 printk("%s: reset, locked mbox %d forced free.\n",
1944 ha->board_name, i);
1945 continue;
1946 }
1947
1948 if (!(SCpnt = ha->cp[i].SCpnt))
1949 panic("%s: reset, mbox %d, SCpnt == NULL.\n", ha->board_name, i);
1950
1951 if (ha->cp_stat[i] == READY || ha->cp_stat[i] == ABORTING) {
1952 ha->cp_stat[i] = ABORTING;
1953 printk("%s: reset, mbox %d aborting.\n",
1954 ha->board_name, i);
1955 }
1956
1957 else {
1958 ha->cp_stat[i] = IN_RESET;
1959 printk("%s: reset, mbox %d in reset.\n",
1960 ha->board_name, i);
1961 }
1962
1963 if (SCpnt->host_scribble == NULL)
1964 panic("%s: reset, mbox %d, garbled SCpnt.\n", ha->board_name, i);
1965
1966 if (*(unsigned int *)SCpnt->host_scribble != i)
1967 panic("%s: reset, mbox %d, index mismatch.\n", ha->board_name, i);
1968
1969 if (SCpnt->scsi_done == NULL)
1970 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n",
1971 ha->board_name, i);
1972
1973 if (SCpnt == SCarg)
1974 arg_done = 1;
1975 }
1976
1977 if (do_dma(shost->io_port, 0, RESET_PIO)) {
1978 printk("%s: reset, cannot reset, timeout error.\n", ha->board_name);
1979 spin_unlock_irq(shost->host_lock);
1980 return FAILED;
1981 }
1982
1983 printk("%s: reset, board reset done, enabling interrupts.\n", ha->board_name);
1984
1985#if defined(DEBUG_RESET)
1986 do_trace = 1;
1987#endif
1988
1989 ha->in_reset = 1;
1990
1991 spin_unlock_irq(shost->host_lock);
1992
1993
1994 time = jiffies;
1995 while ((jiffies - time) < (10 * HZ) && limit++ < 200000)
1996 udelay(100L);
1997
1998 spin_lock_irq(shost->host_lock);
1999
2000 printk("%s: reset, interrupts disabled, loops %d.\n", ha->board_name, limit);
2001
2002 for (i = 0; i < shost->can_queue; i++) {
2003
2004 if (ha->cp_stat[i] == IN_RESET) {
2005 SCpnt = ha->cp[i].SCpnt;
2006 unmap_dma(i, ha);
2007 SCpnt->result = DID_RESET << 16;
2008 SCpnt->host_scribble = NULL;
2009
2010
2011 ha->cp_stat[i] = LOCKED;
2012
2013 printk
2014 ("%s, reset, mbox %d locked, DID_RESET, done.\n",
2015 ha->board_name, i);
2016 }
2017
2018 else if (ha->cp_stat[i] == ABORTING) {
2019 SCpnt = ha->cp[i].SCpnt;
2020 unmap_dma(i, ha);
2021 SCpnt->result = DID_RESET << 16;
2022 SCpnt->host_scribble = NULL;
2023
2024
2025 ha->cp_stat[i] = FREE;
2026
2027 printk
2028 ("%s, reset, mbox %d aborting, DID_RESET, done.\n",
2029 ha->board_name, i);
2030 }
2031
2032 else
2033
2034 continue;
2035
2036 SCpnt->scsi_done(SCpnt);
2037 }
2038
2039 ha->in_reset = 0;
2040 do_trace = 0;
2041
2042 if (arg_done)
2043 printk("%s: reset, exit, done.\n", ha->board_name);
2044 else
2045 printk("%s: reset, exit.\n", ha->board_name);
2046
2047 spin_unlock_irq(shost->host_lock);
2048 return SUCCESS;
2049}
2050
2051int eata2x_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2052 sector_t capacity, int *dkinfo)
2053{
2054 unsigned int size = capacity;
2055
2056 if (ext_tran || (scsicam_bios_param(bdev, capacity, dkinfo) < 0)) {
2057 dkinfo[0] = 255;
2058 dkinfo[1] = 63;
2059 dkinfo[2] = size / (dkinfo[0] * dkinfo[1]);
2060 }
2061#if defined (DEBUG_GEOMETRY)
2062 printk("%s: bios_param, head=%d, sec=%d, cyl=%d.\n", driver_name,
2063 dkinfo[0], dkinfo[1], dkinfo[2]);
2064#endif
2065
2066 return 0;
2067}
2068
2069static void sort(unsigned long sk[], unsigned int da[], unsigned int n,
2070 unsigned int rev)
2071{
2072 unsigned int i, j, k, y;
2073 unsigned long x;
2074
2075 for (i = 0; i < n - 1; i++) {
2076 k = i;
2077
2078 for (j = k + 1; j < n; j++)
2079 if (rev) {
2080 if (sk[j] > sk[k])
2081 k = j;
2082 } else {
2083 if (sk[j] < sk[k])
2084 k = j;
2085 }
2086
2087 if (k != i) {
2088 x = sk[k];
2089 sk[k] = sk[i];
2090 sk[i] = x;
2091 y = da[k];
2092 da[k] = da[i];
2093 da[i] = y;
2094 }
2095 }
2096
2097 return;
2098}
2099
2100static int reorder(struct hostdata *ha, unsigned long cursec,
2101 unsigned int ihdlr, unsigned int il[], unsigned int n_ready)
2102{
2103 struct scsi_cmnd *SCpnt;
2104 struct mscp *cpp;
2105 unsigned int k, n;
2106 unsigned int rev = 0, s = 1, r = 1;
2107 unsigned int input_only = 1, overlap = 0;
2108 unsigned long sl[n_ready], pl[n_ready], ll[n_ready];
2109 unsigned long maxsec = 0, minsec = ULONG_MAX, seek = 0, iseek = 0;
2110 unsigned long ioseek = 0;
2111
2112 static unsigned int flushcount = 0, batchcount = 0, sortcount = 0;
2113 static unsigned int readycount = 0, ovlcount = 0, inputcount = 0;
2114 static unsigned int readysorted = 0, revcount = 0;
2115 static unsigned long seeksorted = 0, seeknosort = 0;
2116
2117 if (link_statistics && !(++flushcount % link_statistics))
2118 printk("fc %d bc %d ic %d oc %d rc %d rs %d sc %d re %d"
2119 " av %ldK as %ldK.\n", flushcount, batchcount,
2120 inputcount, ovlcount, readycount, readysorted, sortcount,
2121 revcount, seeknosort / (readycount + 1),
2122 seeksorted / (readycount + 1));
2123
2124 if (n_ready <= 1)
2125 return 0;
2126
2127 for (n = 0; n < n_ready; n++) {
2128 k = il[n];
2129 cpp = &ha->cp[k];
2130 SCpnt = cpp->SCpnt;
2131
2132 if (!cpp->din)
2133 input_only = 0;
2134
2135 if (blk_rq_pos(SCpnt->request) < minsec)
2136 minsec = blk_rq_pos(SCpnt->request);
2137 if (blk_rq_pos(SCpnt->request) > maxsec)
2138 maxsec = blk_rq_pos(SCpnt->request);
2139
2140 sl[n] = blk_rq_pos(SCpnt->request);
2141 ioseek += blk_rq_sectors(SCpnt->request);
2142
2143 if (!n)
2144 continue;
2145
2146 if (sl[n] < sl[n - 1])
2147 s = 0;
2148 if (sl[n] > sl[n - 1])
2149 r = 0;
2150
2151 if (link_statistics) {
2152 if (sl[n] > sl[n - 1])
2153 seek += sl[n] - sl[n - 1];
2154 else
2155 seek += sl[n - 1] - sl[n];
2156 }
2157
2158 }
2159
2160 if (link_statistics) {
2161 if (cursec > sl[0])
2162 seek += cursec - sl[0];
2163 else
2164 seek += sl[0] - cursec;
2165 }
2166
2167 if (cursec > ((maxsec + minsec) / 2))
2168 rev = 1;
2169
2170 if (ioseek > ((maxsec - minsec) / 2))
2171 rev = 0;
2172
2173 if (!((rev && r) || (!rev && s)))
2174 sort(sl, il, n_ready, rev);
2175
2176 if (!input_only)
2177 for (n = 0; n < n_ready; n++) {
2178 k = il[n];
2179 cpp = &ha->cp[k];
2180 SCpnt = cpp->SCpnt;
2181 ll[n] = blk_rq_sectors(SCpnt->request);
2182 pl[n] = SCpnt->serial_number;
2183
2184 if (!n)
2185 continue;
2186
2187 if ((sl[n] == sl[n - 1])
2188 || (!rev && ((sl[n - 1] + ll[n - 1]) > sl[n]))
2189 || (rev && ((sl[n] + ll[n]) > sl[n - 1])))
2190 overlap = 1;
2191 }
2192
2193 if (overlap)
2194 sort(pl, il, n_ready, 0);
2195
2196 if (link_statistics) {
2197 if (cursec > sl[0])
2198 iseek = cursec - sl[0];
2199 else
2200 iseek = sl[0] - cursec;
2201 batchcount++;
2202 readycount += n_ready;
2203 seeknosort += seek / 1024;
2204 if (input_only)
2205 inputcount++;
2206 if (overlap) {
2207 ovlcount++;
2208 seeksorted += iseek / 1024;
2209 } else
2210 seeksorted += (iseek + maxsec - minsec) / 1024;
2211 if (rev && !r) {
2212 revcount++;
2213 readysorted += n_ready;
2214 }
2215 if (!rev && !s) {
2216 sortcount++;
2217 readysorted += n_ready;
2218 }
2219 }
2220#if defined(DEBUG_LINKED_COMMANDS)
2221 if (link_statistics && (overlap || !(flushcount % link_statistics)))
2222 for (n = 0; n < n_ready; n++) {
2223 k = il[n];
2224 cpp = &ha->cp[k];
2225 SCpnt = cpp->SCpnt;
2226 scmd_printk(KERN_INFO, SCpnt,
2227 "%s mb %d fc %d nr %d sec %ld ns %u"
2228 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
2229 (ihdlr ? "ihdlr" : "qcomm"),
2230 k, flushcount,
2231 n_ready, blk_rq_pos(SCpnt->request),
2232 blk_rq_sectors(SCpnt->request), cursec, YESNO(s),
2233 YESNO(r), YESNO(rev), YESNO(input_only),
2234 YESNO(overlap), cpp->din);
2235 }
2236#endif
2237 return overlap;
2238}
2239
2240static void flush_dev(struct scsi_device *dev, unsigned long cursec,
2241 struct hostdata *ha, unsigned int ihdlr)
2242{
2243 struct scsi_cmnd *SCpnt;
2244 struct mscp *cpp;
2245 unsigned int k, n, n_ready = 0, il[MAX_MAILBOXES];
2246
2247 for (k = 0; k < dev->host->can_queue; k++) {
2248
2249 if (ha->cp_stat[k] != READY && ha->cp_stat[k] != IN_USE)
2250 continue;
2251
2252 cpp = &ha->cp[k];
2253 SCpnt = cpp->SCpnt;
2254
2255 if (SCpnt->device != dev)
2256 continue;
2257
2258 if (ha->cp_stat[k] == IN_USE)
2259 return;
2260
2261 il[n_ready++] = k;
2262 }
2263
2264 if (reorder(ha, cursec, ihdlr, il, n_ready))
2265 n_ready = 1;
2266
2267 for (n = 0; n < n_ready; n++) {
2268 k = il[n];
2269 cpp = &ha->cp[k];
2270 SCpnt = cpp->SCpnt;
2271
2272 if (do_dma(dev->host->io_port, cpp->cp_dma_addr, SEND_CP_DMA)) {
2273 scmd_printk(KERN_INFO, SCpnt,
2274 "%s, mbox %d, adapter"
2275 " busy, will abort.\n",
2276 (ihdlr ? "ihdlr" : "qcomm"),
2277 k);
2278 ha->cp_stat[k] = ABORTING;
2279 continue;
2280 }
2281
2282 ha->cp_stat[k] = IN_USE;
2283 }
2284}
2285
2286static irqreturn_t ihdlr(struct Scsi_Host *shost)
2287{
2288 struct scsi_cmnd *SCpnt;
2289 unsigned int i, k, c, status, tstatus, reg;
2290 struct mssp *spp;
2291 struct mscp *cpp;
2292 struct hostdata *ha = (struct hostdata *)shost->hostdata;
2293 int irq = shost->irq;
2294
2295
2296 if (!(inb(shost->io_port + REG_AUX_STATUS) & IRQ_ASSERTED))
2297 goto none;
2298
2299 ha->iocount++;
2300
2301 if (do_trace)
2302 printk("%s: ihdlr, enter, irq %d, count %d.\n", ha->board_name, irq,
2303 ha->iocount);
2304
2305
2306 if (wait_on_busy(shost->io_port, 20 * MAXLOOP)) {
2307 reg = inb(shost->io_port + REG_STATUS);
2308 printk
2309 ("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n",
2310 ha->board_name, irq, reg, ha->iocount);
2311 goto none;
2312 }
2313
2314 spp = &ha->sp;
2315
2316
2317 memcpy(spp, ha->sp_cpu_addr, sizeof(struct mssp));
2318
2319
2320 memset(ha->sp_cpu_addr, 0, sizeof(struct mssp));
2321
2322
2323 reg = inb(shost->io_port + REG_STATUS);
2324
2325#if defined (DEBUG_INTERRUPT)
2326 {
2327 unsigned char *bytesp;
2328 int cnt;
2329 bytesp = (unsigned char *)spp;
2330 if (ha->iocount < 200) {
2331 printk("sp[] =");
2332 for (cnt = 0; cnt < 15; cnt++)
2333 printk(" 0x%x", bytesp[cnt]);
2334 printk("\n");
2335 }
2336 }
2337#endif
2338
2339
2340 if (spp->eoc == 0 && ha->iocount > 1)
2341 printk
2342 ("%s: ihdlr, spp->eoc == 0, irq %d, reg 0x%x, count %d.\n",
2343 ha->board_name, irq, reg, ha->iocount);
2344 if (spp->cpp_index < 0 || spp->cpp_index >= shost->can_queue)
2345 printk
2346 ("%s: ihdlr, bad spp->cpp_index %d, irq %d, reg 0x%x, count %d.\n",
2347 ha->board_name, spp->cpp_index, irq, reg, ha->iocount);
2348 if (spp->eoc == 0 || spp->cpp_index < 0
2349 || spp->cpp_index >= shost->can_queue)
2350 goto handled;
2351
2352
2353 i = spp->cpp_index;
2354
2355 cpp = &(ha->cp[i]);
2356
2357#if defined(DEBUG_GENERATE_ABORTS)
2358 if ((ha->iocount > 500) && ((ha->iocount % 500) < 3))
2359 goto handled;
2360#endif
2361
2362 if (ha->cp_stat[i] == IGNORE) {
2363 ha->cp_stat[i] = FREE;
2364 goto handled;
2365 } else if (ha->cp_stat[i] == LOCKED) {
2366 ha->cp_stat[i] = FREE;
2367 printk("%s: ihdlr, mbox %d unlocked, count %d.\n", ha->board_name, i,
2368 ha->iocount);
2369 goto handled;
2370 } else if (ha->cp_stat[i] == FREE) {
2371 printk("%s: ihdlr, mbox %d is free, count %d.\n", ha->board_name, i,
2372 ha->iocount);
2373 goto handled;
2374 } else if (ha->cp_stat[i] == IN_RESET)
2375 printk("%s: ihdlr, mbox %d is in reset.\n", ha->board_name, i);
2376 else if (ha->cp_stat[i] != IN_USE)
2377 panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n",
2378 ha->board_name, i, ha->cp_stat[i]);
2379
2380 ha->cp_stat[i] = FREE;
2381 SCpnt = cpp->SCpnt;
2382
2383 if (SCpnt == NULL)
2384 panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", ha->board_name, i);
2385
2386 if (SCpnt->host_scribble == NULL)
2387 panic("%s: ihdlr, mbox %d, SCpnt %p garbled.\n", ha->board_name,
2388 i, SCpnt);
2389
2390 if (*(unsigned int *)SCpnt->host_scribble != i)
2391 panic("%s: ihdlr, mbox %d, index mismatch %d.\n",
2392 ha->board_name, i,
2393 *(unsigned int *)SCpnt->host_scribble);
2394
2395 sync_dma(i, ha);
2396
2397 if (linked_comm && SCpnt->device->queue_depth > 2
2398 && TLDEV(SCpnt->device->type))
2399 flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), ha, 1);
2400
2401 tstatus = status_byte(spp->target_status);
2402
2403#if defined(DEBUG_GENERATE_ERRORS)
2404 if ((ha->iocount > 500) && ((ha->iocount % 200) < 2))
2405 spp->adapter_status = 0x01;
2406#endif
2407
2408 switch (spp->adapter_status) {
2409 case ASOK:
2410
2411
2412 if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)
2413 status = DID_ERROR << 16;
2414
2415
2416 else if (tstatus != GOOD && SCpnt->device->type == TYPE_DISK
2417 && ha->target_redo[SCpnt->device->id][SCpnt->
2418 device->
2419 channel])
2420 status = DID_BUS_BUSY << 16;
2421
2422
2423 else if (tstatus == CHECK_CONDITION
2424 && SCpnt->device->type == TYPE_DISK
2425 && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
2426 status = DID_BUS_BUSY << 16;
2427
2428 else
2429 status = DID_OK << 16;
2430
2431 if (tstatus == GOOD)
2432 ha->target_redo[SCpnt->device->id][SCpnt->device->
2433 channel] = 0;
2434
2435 if (spp->target_status && SCpnt->device->type == TYPE_DISK &&
2436 (!(tstatus == CHECK_CONDITION && ha->iocount <= 1000 &&
2437 (SCpnt->sense_buffer[2] & 0xf) == NOT_READY)))
2438 printk("%s: ihdlr, target %d.%d:%d, "
2439 "target_status 0x%x, sense key 0x%x.\n",
2440 ha->board_name,
2441 SCpnt->device->channel, SCpnt->device->id,
2442 (u8)SCpnt->device->lun,
2443 spp->target_status, SCpnt->sense_buffer[2]);
2444
2445 ha->target_to[SCpnt->device->id][SCpnt->device->channel] = 0;
2446
2447 if (ha->last_retried_pid == SCpnt->serial_number)
2448 ha->retries = 0;
2449
2450 break;
2451 case ASST:
2452 case 0x02:
2453
2454 if (ha->target_to[SCpnt->device->id][SCpnt->device->channel] > 1)
2455 status = DID_ERROR << 16;
2456 else {
2457 status = DID_TIME_OUT << 16;
2458 ha->target_to[SCpnt->device->id][SCpnt->device->
2459 channel]++;
2460 }
2461
2462 break;
2463
2464
2465 case 0x03:
2466 case 0x04:
2467
2468 for (c = 0; c <= shost->max_channel; c++)
2469 for (k = 0; k < shost->max_id; k++)
2470 ha->target_redo[k][c] = 1;
2471
2472 if (SCpnt->device->type != TYPE_TAPE
2473 && ha->retries < MAX_INTERNAL_RETRIES) {
2474
2475#if defined(DID_SOFT_ERROR)
2476 status = DID_SOFT_ERROR << 16;
2477#else
2478 status = DID_BUS_BUSY << 16;
2479#endif
2480
2481 ha->retries++;
2482 ha->last_retried_pid = SCpnt->serial_number;
2483 } else
2484 status = DID_ERROR << 16;
2485
2486 break;
2487 case 0x05:
2488 case 0x06:
2489 case 0x07:
2490 case 0x08:
2491 case 0x09:
2492 case 0x0a:
2493 case 0x0b:
2494 case 0x0c:
2495 default:
2496 status = DID_ERROR << 16;
2497 break;
2498 }
2499
2500 SCpnt->result = status | spp->target_status;
2501
2502#if defined(DEBUG_INTERRUPT)
2503 if (SCpnt->result || do_trace)
2504#else
2505 if ((spp->adapter_status != ASOK && ha->iocount > 1000) ||
2506 (spp->adapter_status != ASOK &&
2507 spp->adapter_status != ASST && ha->iocount <= 1000) ||
2508 do_trace || msg_byte(spp->target_status))
2509#endif
2510 scmd_printk(KERN_INFO, SCpnt, "ihdlr, mbox %2d, err 0x%x:%x,"
2511 " reg 0x%x, count %d.\n",
2512 i, spp->adapter_status, spp->target_status,
2513 reg, ha->iocount);
2514
2515 unmap_dma(i, ha);
2516
2517
2518 SCpnt->host_scribble = NULL;
2519
2520 SCpnt->scsi_done(SCpnt);
2521
2522 if (do_trace)
2523 printk("%s: ihdlr, exit, irq %d, count %d.\n", ha->board_name,
2524 irq, ha->iocount);
2525
2526 handled:
2527 return IRQ_HANDLED;
2528 none:
2529 return IRQ_NONE;
2530}
2531
2532static irqreturn_t do_interrupt_handler(int dummy, void *shap)
2533{
2534 struct Scsi_Host *shost;
2535 unsigned int j;
2536 unsigned long spin_flags;
2537 irqreturn_t ret;
2538
2539
2540 if ((j = (unsigned int)((char *)shap - sha)) >= num_boards)
2541 return IRQ_NONE;
2542 shost = sh[j];
2543
2544 spin_lock_irqsave(shost->host_lock, spin_flags);
2545 ret = ihdlr(shost);
2546 spin_unlock_irqrestore(shost->host_lock, spin_flags);
2547 return ret;
2548}
2549
2550static int eata2x_release(struct Scsi_Host *shost)
2551{
2552 struct hostdata *ha = (struct hostdata *)shost->hostdata;
2553 unsigned int i;
2554
2555 for (i = 0; i < shost->can_queue; i++)
2556 kfree((&ha->cp[i])->sglist);
2557
2558 for (i = 0; i < shost->can_queue; i++)
2559 pci_unmap_single(ha->pdev, ha->cp[i].cp_dma_addr,
2560 sizeof(struct mscp), PCI_DMA_BIDIRECTIONAL);
2561
2562 if (ha->sp_cpu_addr)
2563 pci_free_consistent(ha->pdev, sizeof(struct mssp),
2564 ha->sp_cpu_addr, ha->sp_dma_addr);
2565
2566 free_irq(shost->irq, &sha[ha->board_number]);
2567
2568 if (shost->dma_channel != NO_DMA)
2569 free_dma(shost->dma_channel);
2570
2571 release_region(shost->io_port, shost->n_io_port);
2572 scsi_unregister(shost);
2573 return 0;
2574}
2575
2576#include "scsi_module.c"
2577
2578#ifndef MODULE
2579__setup("eata=", option_setup);
2580#endif
2581