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#include <linux/module.h>
62#include <linux/errno.h>
63#include <linux/delay.h>
64#include <linux/interrupt.h>
65#include <linux/pci.h>
66#include <linux/init.h>
67#include <linux/blkdev.h>
68#include <linux/spinlock.h>
69#include <linux/kernel.h>
70#include <linux/string.h>
71#include <linux/ioport.h>
72#include <linux/slab.h>
73#include <linux/dma-mapping.h>
74
75#include <asm/io.h>
76#include <asm/irq.h>
77
78#include <scsi/scsi.h>
79#include <scsi/scsi_cmnd.h>
80#include <scsi/scsi_device.h>
81#include <scsi/scsi_host.h>
82
83#include "a100u2w.h"
84
85
86static struct orc_scb *__orc_alloc_scb(struct orc_host * host);
87static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb);
88
89static struct orc_nvram nvram, *nvramp = &nvram;
90
91static u8 default_nvram[64] =
92{
93
94 0x01,
95 0x11,
96 0x60,
97 0x10,
98 0x00,
99 0x01,
100 0x11,
101 0x60,
102 0x10,
103 0x00,
104 0x00,
105 0x01,
106
107 0x01,
108 0x01,
109 0x00,
110 0x00,
111
112 0x07,
113 0x83,
114 0x20,
115 0x0A,
116 0x00,
117 0x00,
118
119
120 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
121 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
122
123 0x07,
124 0x83,
125 0x20,
126 0x0A,
127 0x00,
128 0x00,
129
130
131 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
132 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
133 0x00,
134 0x00,
135 0x00,
136 0x00
137};
138
139
140static u8 wait_chip_ready(struct orc_host * host)
141{
142 int i;
143
144 for (i = 0; i < 10; i++) {
145 if (inb(host->base + ORC_HCTRL) & HOSTSTOP)
146 return 1;
147 mdelay(100);
148 }
149 return 0;
150}
151
152static u8 wait_firmware_ready(struct orc_host * host)
153{
154 int i;
155
156 for (i = 0; i < 10; i++) {
157 if (inb(host->base + ORC_HSTUS) & RREADY)
158 return 1;
159 mdelay(100);
160 }
161 return 0;
162}
163
164
165static u8 wait_scsi_reset_done(struct orc_host * host)
166{
167 int i;
168
169 for (i = 0; i < 10; i++) {
170 if (!(inb(host->base + ORC_HCTRL) & SCSIRST))
171 return 1;
172 mdelay(100);
173 }
174 return 0;
175}
176
177
178static u8 wait_HDO_off(struct orc_host * host)
179{
180 int i;
181
182 for (i = 0; i < 10; i++) {
183 if (!(inb(host->base + ORC_HCTRL) & HDO))
184 return 1;
185 mdelay(100);
186 }
187 return 0;
188}
189
190
191static u8 wait_hdi_set(struct orc_host * host, u8 * data)
192{
193 int i;
194
195 for (i = 0; i < 10; i++) {
196 if ((*data = inb(host->base + ORC_HSTUS)) & HDI)
197 return 1;
198 mdelay(100);
199 }
200 return 0;
201}
202
203
204static unsigned short orc_read_fwrev(struct orc_host * host)
205{
206 u16 version;
207 u8 data;
208
209 outb(ORC_CMD_VERSION, host->base + ORC_HDATA);
210 outb(HDO, host->base + ORC_HCTRL);
211 if (wait_HDO_off(host) == 0)
212 return 0;
213
214 if (wait_hdi_set(host, &data) == 0)
215 return 0;
216 version = inb(host->base + ORC_HDATA);
217 outb(data, host->base + ORC_HSTUS);
218
219 if (wait_hdi_set(host, &data) == 0)
220 return 0;
221 version |= inb(host->base + ORC_HDATA) << 8;
222 outb(data, host->base + ORC_HSTUS);
223
224 return version;
225}
226
227
228static u8 orc_nv_write(struct orc_host * host, unsigned char address, unsigned char value)
229{
230 outb(ORC_CMD_SET_NVM, host->base + ORC_HDATA);
231 outb(HDO, host->base + ORC_HCTRL);
232 if (wait_HDO_off(host) == 0)
233 return 0;
234
235 outb(address, host->base + ORC_HDATA);
236 outb(HDO, host->base + ORC_HCTRL);
237 if (wait_HDO_off(host) == 0)
238 return 0;
239
240 outb(value, host->base + ORC_HDATA);
241 outb(HDO, host->base + ORC_HCTRL);
242 if (wait_HDO_off(host) == 0)
243 return 0;
244
245 return 1;
246}
247
248
249static u8 orc_nv_read(struct orc_host * host, u8 address, u8 *ptr)
250{
251 unsigned char data;
252
253 outb(ORC_CMD_GET_NVM, host->base + ORC_HDATA);
254 outb(HDO, host->base + ORC_HCTRL);
255 if (wait_HDO_off(host) == 0)
256 return 0;
257
258 outb(address, host->base + ORC_HDATA);
259 outb(HDO, host->base + ORC_HCTRL);
260 if (wait_HDO_off(host) == 0)
261 return 0;
262
263 if (wait_hdi_set(host, &data) == 0)
264 return 0;
265 *ptr = inb(host->base + ORC_HDATA);
266 outb(data, host->base + ORC_HSTUS);
267
268 return 1;
269
270}
271
272
273
274
275
276
277
278static void orc_exec_scb(struct orc_host * host, struct orc_scb * scb)
279{
280 scb->status = ORCSCB_POST;
281 outb(scb->scbidx, host->base + ORC_PQUEUE);
282}
283
284
285
286
287
288
289
290
291
292static int se2_rd_all(struct orc_host * host)
293{
294 int i;
295 u8 *np, chksum = 0;
296
297 np = (u8 *) nvramp;
298 for (i = 0; i < 64; i++, np++) {
299 if (orc_nv_read(host, (u8) i, np) == 0)
300 return -1;
301 }
302
303
304 np = (u8 *) nvramp;
305 for (i = 0; i < 63; i++)
306 chksum += *np++;
307
308 if (nvramp->CheckSum != (u8) chksum)
309 return -1;
310 return 1;
311}
312
313
314
315
316
317
318
319
320static void se2_update_all(struct orc_host * host)
321{
322 int i;
323 u8 *np, *np1, chksum = 0;
324
325
326 np = (u8 *) default_nvram;
327 for (i = 0; i < 63; i++)
328 chksum += *np++;
329 *np = chksum;
330
331 np = (u8 *) default_nvram;
332 np1 = (u8 *) nvramp;
333 for (i = 0; i < 64; i++, np++, np1++) {
334 if (*np != *np1)
335 orc_nv_write(host, (u8) i, *np);
336 }
337}
338
339
340
341
342
343
344
345
346
347static void read_eeprom(struct orc_host * host)
348{
349 if (se2_rd_all(host) != 1) {
350 se2_update_all(host);
351 se2_rd_all(host);
352 }
353}
354
355
356
357
358
359
360
361
362
363
364
365
366static u8 orc_load_firmware(struct orc_host * host)
367{
368 u32 data32;
369 u16 bios_addr;
370 u16 i;
371 u8 *data32_ptr, data;
372
373
374
375
376 data = inb(host->base + ORC_GCFG);
377 outb(data | EEPRG, host->base + ORC_GCFG);
378 outb(0x00, host->base + ORC_EBIOSADR2);
379 outw(0x0000, host->base + ORC_EBIOSADR0);
380 if (inb(host->base + ORC_EBIOSDATA) != 0x55) {
381 outb(data, host->base + ORC_GCFG);
382 return 0;
383 }
384 outw(0x0001, host->base + ORC_EBIOSADR0);
385 if (inb(host->base + ORC_EBIOSDATA) != 0xAA) {
386 outb(data, host->base + ORC_GCFG);
387 return 0;
388 }
389
390 outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL);
391 data32_ptr = (u8 *) & data32;
392 data32 = cpu_to_le32(0);
393 outw(0x0010, host->base + ORC_EBIOSADR0);
394 *data32_ptr = inb(host->base + ORC_EBIOSDATA);
395 outw(0x0011, host->base + ORC_EBIOSADR0);
396 *(data32_ptr + 1) = inb(host->base + ORC_EBIOSDATA);
397 outw(0x0012, host->base + ORC_EBIOSADR0);
398 *(data32_ptr + 2) = inb(host->base + ORC_EBIOSDATA);
399 outw(*(data32_ptr + 2), host->base + ORC_EBIOSADR2);
400 outl(le32_to_cpu(data32), host->base + ORC_FWBASEADR);
401
402
403
404 udelay(500);
405 bios_addr = (u16) le32_to_cpu(data32);
406 for (i = 0, data32_ptr = (u8 *) & data32;
407 i < 0x1000;
408 i++, bios_addr++) {
409 outw(bios_addr, host->base + ORC_EBIOSADR0);
410 *data32_ptr++ = inb(host->base + ORC_EBIOSDATA);
411 if ((i % 4) == 3) {
412 outl(le32_to_cpu(data32), host->base + ORC_RISCRAM);
413 data32_ptr = (u8 *) & data32;
414 }
415 }
416
417
418
419 outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL);
420 bios_addr -= 0x1000;
421 for (i = 0, data32_ptr = (u8 *) & data32;
422 i < 0x1000;
423 i++, bios_addr++) {
424 outw(bios_addr, host->base + ORC_EBIOSADR0);
425 *data32_ptr++ = inb(host->base + ORC_EBIOSDATA);
426 if ((i % 4) == 3) {
427 if (inl(host->base + ORC_RISCRAM) != le32_to_cpu(data32)) {
428 outb(PRGMRST, host->base + ORC_RISCCTL);
429 outb(data, host->base + ORC_GCFG);
430 return 0;
431 }
432 data32_ptr = (u8 *) & data32;
433 }
434 }
435
436
437 outb(PRGMRST, host->base + ORC_RISCCTL);
438 outb(data, host->base + ORC_GCFG);
439 return 1;
440}
441
442
443static void setup_SCBs(struct orc_host * host)
444{
445 struct orc_scb *scb;
446 int i;
447 struct orc_extended_scb *escb;
448 dma_addr_t escb_phys;
449
450
451 outb(ORC_MAXQUEUE, host->base + ORC_SCBSIZE);
452
453 outl(host->scb_phys, host->base + ORC_SCBBASE0);
454
455 outl(host->scb_phys, host->base + ORC_SCBBASE1);
456
457
458 scb = host->scb_virt;
459 escb = host->escb_virt;
460
461 for (i = 0; i < ORC_MAXQUEUE; i++) {
462 escb_phys = (host->escb_phys + (sizeof(struct orc_extended_scb) * i));
463 scb->sg_addr = cpu_to_le32((u32) escb_phys);
464 scb->sense_addr = cpu_to_le32((u32) escb_phys);
465 scb->escb = escb;
466 scb->scbidx = i;
467 scb++;
468 escb++;
469 }
470}
471
472
473
474
475
476
477
478
479
480static void init_alloc_map(struct orc_host * host)
481{
482 u8 i, j;
483
484 for (i = 0; i < MAX_CHANNELS; i++) {
485 for (j = 0; j < 8; j++) {
486 host->allocation_map[i][j] = 0xffffffff;
487 }
488 }
489}
490
491
492
493
494
495
496
497
498
499
500static int init_orchid(struct orc_host * host)
501{
502 u8 *ptr;
503 u16 revision;
504 u8 i;
505
506 init_alloc_map(host);
507 outb(0xFF, host->base + ORC_GIMSK);
508
509 if (inb(host->base + ORC_HSTUS) & RREADY) {
510 revision = orc_read_fwrev(host);
511 if (revision == 0xFFFF) {
512 outb(DEVRST, host->base + ORC_HCTRL);
513 if (wait_chip_ready(host) == 0)
514 return -1;
515 orc_load_firmware(host);
516 setup_SCBs(host);
517 outb(0x00, host->base + ORC_HCTRL);
518 if (wait_firmware_ready(host) == 0)
519 return -1;
520
521 } else {
522 setup_SCBs(host);
523 }
524 } else {
525 outb(DEVRST, host->base + ORC_HCTRL);
526 if (wait_chip_ready(host) == 0)
527 return -1;
528 orc_load_firmware(host);
529 setup_SCBs(host);
530 outb(HDO, host->base + ORC_HCTRL);
531
532
533 if (wait_firmware_ready(host) == 0)
534 return -1;
535 }
536
537
538
539 read_eeprom(host);
540
541 if (nvramp->revision != 1)
542 return -1;
543
544 host->scsi_id = nvramp->scsi_id;
545 host->BIOScfg = nvramp->BIOSConfig1;
546 host->max_targets = MAX_TARGETS;
547 ptr = (u8 *) & (nvramp->Target00Config);
548 for (i = 0; i < 16; ptr++, i++) {
549 host->target_flag[i] = *ptr;
550 host->max_tags[i] = ORC_MAXTAGS;
551 }
552
553 if (nvramp->SCSI0Config & NCC_BUSRESET)
554 host->flags |= HCF_SCSI_RESET;
555 outb(0xFB, host->base + ORC_GIMSK);
556 return 0;
557}
558
559
560
561
562
563
564
565
566static int orc_reset_scsi_bus(struct orc_host * host)
567{
568 unsigned long flags;
569
570 spin_lock_irqsave(&host->allocation_lock, flags);
571
572 init_alloc_map(host);
573
574 outb(SCSIRST, host->base + ORC_HCTRL);
575
576
577 if (wait_scsi_reset_done(host) == 0) {
578 spin_unlock_irqrestore(&host->allocation_lock, flags);
579 return FAILED;
580 } else {
581 spin_unlock_irqrestore(&host->allocation_lock, flags);
582 return SUCCESS;
583 }
584}
585
586
587
588
589
590
591
592
593
594
595
596static int orc_device_reset(struct orc_host * host, struct scsi_cmnd *cmd, unsigned int target)
597{
598 struct orc_scb *scb;
599 struct orc_extended_scb *escb;
600 struct orc_scb *host_scb;
601 u8 i;
602 unsigned long flags;
603
604 spin_lock_irqsave(&(host->allocation_lock), flags);
605 scb = (struct orc_scb *) NULL;
606 escb = (struct orc_extended_scb *) NULL;
607
608
609 host_scb = host->scb_virt;
610
611
612
613 init_alloc_map(host);
614
615
616 for (i = 0; i < ORC_MAXQUEUE; i++) {
617 escb = host_scb->escb;
618 if (host_scb->status && escb->srb == cmd)
619 break;
620 host_scb++;
621 }
622
623 if (i == ORC_MAXQUEUE) {
624 printk(KERN_ERR "Unable to Reset - No SCB Found\n");
625 spin_unlock_irqrestore(&(host->allocation_lock), flags);
626 return FAILED;
627 }
628
629
630 if ((scb = __orc_alloc_scb(host)) == NULL) {
631
632 spin_unlock_irqrestore(&(host->allocation_lock), flags);
633 return FAILED;
634 }
635
636
637
638 scb->opcode = ORC_BUSDEVRST;
639 scb->target = target;
640 scb->hastat = 0;
641 scb->tastat = 0;
642 scb->status = 0x0;
643 scb->link = 0xFF;
644 scb->reserved0 = 0;
645 scb->reserved1 = 0;
646 scb->xferlen = cpu_to_le32(0);
647 scb->sg_len = cpu_to_le32(0);
648
649 escb->srb = NULL;
650 escb->srb = cmd;
651 orc_exec_scb(host, scb);
652 spin_unlock_irqrestore(&host->allocation_lock, flags);
653 return SUCCESS;
654}
655
656
657
658
659
660
661
662
663
664
665
666static struct orc_scb *__orc_alloc_scb(struct orc_host * host)
667{
668 u8 channel;
669 unsigned long idx;
670 u8 index;
671 u8 i;
672
673 channel = host->index;
674 for (i = 0; i < 8; i++) {
675 for (index = 0; index < 32; index++) {
676 if ((host->allocation_map[channel][i] >> index) & 0x01) {
677 host->allocation_map[channel][i] &= ~(1 << index);
678 idx = index + 32 * i;
679
680
681
682 return host->scb_virt + idx;
683 }
684 }
685 }
686 return NULL;
687}
688
689
690
691
692
693
694
695
696
697static struct orc_scb *orc_alloc_scb(struct orc_host * host)
698{
699 struct orc_scb *scb;
700 unsigned long flags;
701
702 spin_lock_irqsave(&host->allocation_lock, flags);
703 scb = __orc_alloc_scb(host);
704 spin_unlock_irqrestore(&host->allocation_lock, flags);
705 return scb;
706}
707
708
709
710
711
712
713
714
715
716
717static void orc_release_scb(struct orc_host *host, struct orc_scb *scb)
718{
719 unsigned long flags;
720 u8 index, i, channel;
721
722 spin_lock_irqsave(&(host->allocation_lock), flags);
723 channel = host->index;
724 index = scb->scbidx;
725 i = index / 32;
726 index %= 32;
727 host->allocation_map[channel][i] |= (1 << index);
728 spin_unlock_irqrestore(&(host->allocation_lock), flags);
729}
730
731
732
733
734
735
736
737
738
739static int orchid_abort_scb(struct orc_host * host, struct orc_scb * scb)
740{
741 unsigned char data, status;
742
743 outb(ORC_CMD_ABORT_SCB, host->base + ORC_HDATA);
744 outb(HDO, host->base + ORC_HCTRL);
745 if (wait_HDO_off(host) == 0)
746 return 0;
747
748 outb(scb->scbidx, host->base + ORC_HDATA);
749 outb(HDO, host->base + ORC_HCTRL);
750 if (wait_HDO_off(host) == 0)
751 return 0;
752
753 if (wait_hdi_set(host, &data) == 0)
754 return 0;
755 status = inb(host->base + ORC_HDATA);
756 outb(data, host->base + ORC_HSTUS);
757
758 if (status == 1)
759 return 0;
760 return 1;
761}
762
763static int inia100_abort_cmd(struct orc_host * host, struct scsi_cmnd *cmd)
764{
765 struct orc_extended_scb *escb;
766 struct orc_scb *scb;
767 u8 i;
768 unsigned long flags;
769
770 spin_lock_irqsave(&(host->allocation_lock), flags);
771
772 scb = host->scb_virt;
773
774
775
776
777
778 for (i = 0; i < ORC_MAXQUEUE; i++, scb++) {
779 escb = scb->escb;
780 if (scb->status && escb->srb == cmd) {
781 if (scb->tag_msg == 0) {
782 goto out;
783 } else {
784
785 if (orchid_abort_scb(host, scb)) {
786 escb->srb = NULL;
787 spin_unlock_irqrestore(&host->allocation_lock, flags);
788 return SUCCESS;
789 } else
790 goto out;
791 }
792 }
793 }
794out:
795 spin_unlock_irqrestore(&host->allocation_lock, flags);
796 return FAILED;
797}
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812static irqreturn_t orc_interrupt(struct orc_host * host)
813{
814 u8 scb_index;
815 struct orc_scb *scb;
816
817
818 if (inb(host->base + ORC_RQUEUECNT) == 0)
819 return IRQ_NONE;
820
821 do {
822
823 scb_index = inb(host->base + ORC_RQUEUE);
824
825
826 scb = (struct orc_scb *) ((unsigned long) host->scb_virt + (unsigned long) (sizeof(struct orc_scb) * scb_index));
827 scb->status = 0x0;
828
829 inia100_scb_handler(host, scb);
830 } while (inb(host->base + ORC_RQUEUECNT));
831 return IRQ_HANDLED;
832}
833
834
835
836
837
838
839
840
841
842
843static int inia100_build_scb(struct orc_host * host, struct orc_scb * scb, struct scsi_cmnd * cmd)
844{
845 struct scatterlist *sg;
846 struct orc_sgent *sgent;
847 int i, count_sg;
848 struct orc_extended_scb *escb;
849
850
851 escb = scb->escb;
852 escb->srb = cmd;
853 sgent = NULL;
854
855
856 scb->opcode = ORC_EXECSCSI;
857 scb->flags = SCF_NO_DCHK;
858 scb->target = cmd->device->id;
859 scb->lun = cmd->device->lun;
860 scb->reserved0 = 0;
861 scb->reserved1 = 0;
862 scb->sg_len = cpu_to_le32(0);
863
864 scb->xferlen = cpu_to_le32((u32) scsi_bufflen(cmd));
865 sgent = (struct orc_sgent *) & escb->sglist[0];
866
867 count_sg = scsi_dma_map(cmd);
868 if (count_sg < 0)
869 return count_sg;
870 BUG_ON(count_sg > TOTAL_SG_ENTRY);
871
872
873 if (count_sg) {
874 scb->sg_len = cpu_to_le32((u32) (count_sg * 8));
875 scsi_for_each_sg(cmd, sg, count_sg, i) {
876 sgent->base = cpu_to_le32((u32) sg_dma_address(sg));
877 sgent->length = cpu_to_le32((u32) sg_dma_len(sg));
878 sgent++;
879 }
880 } else {
881 scb->sg_len = cpu_to_le32(0);
882 sgent->base = cpu_to_le32(0);
883 sgent->length = cpu_to_le32(0);
884 }
885 scb->sg_addr = (u32) scb->sense_addr;
886 scb->hastat = 0;
887 scb->tastat = 0;
888 scb->link = 0xFF;
889 scb->sense_len = SENSE_SIZE;
890 scb->cdb_len = cmd->cmd_len;
891 if (scb->cdb_len >= IMAX_CDB) {
892 printk("max cdb length= %x\b", cmd->cmd_len);
893 scb->cdb_len = IMAX_CDB;
894 }
895 scb->ident = cmd->device->lun | DISC_ALLOW;
896 if (cmd->device->tagged_supported) {
897 scb->tag_msg = SIMPLE_QUEUE_TAG;
898 } else {
899 scb->tag_msg = 0;
900 }
901 memcpy(scb->cdb, cmd->cmnd, scb->cdb_len);
902 return 0;
903}
904
905
906
907
908
909
910
911
912
913
914
915static int inia100_queue(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
916{
917 struct orc_scb *scb;
918 struct orc_host *host;
919
920 host = (struct orc_host *) cmd->device->host->hostdata;
921 cmd->scsi_done = done;
922
923 if ((scb = orc_alloc_scb(host)) == NULL)
924 return SCSI_MLQUEUE_HOST_BUSY;
925
926 if (inia100_build_scb(host, scb, cmd)) {
927 orc_release_scb(host, scb);
928 return SCSI_MLQUEUE_HOST_BUSY;
929 }
930 orc_exec_scb(host, scb);
931 return 0;
932}
933
934
935
936
937
938
939
940
941
942static int inia100_abort(struct scsi_cmnd * cmd)
943{
944 struct orc_host *host;
945
946 host = (struct orc_host *) cmd->device->host->hostdata;
947 return inia100_abort_cmd(host, cmd);
948}
949
950
951
952
953
954
955
956
957
958static int inia100_bus_reset(struct scsi_cmnd * cmd)
959{
960 struct orc_host *host;
961 host = (struct orc_host *) cmd->device->host->hostdata;
962 return orc_reset_scsi_bus(host);
963}
964
965
966
967
968
969
970
971
972static int inia100_device_reset(struct scsi_cmnd * cmd)
973{
974 struct orc_host *host;
975 host = (struct orc_host *) cmd->device->host->hostdata;
976 return orc_device_reset(host, cmd, scmd_id(cmd));
977
978}
979
980
981
982
983
984
985
986
987
988
989
990static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb)
991{
992 struct scsi_cmnd *cmd;
993 struct orc_extended_scb *escb;
994
995 escb = scb->escb;
996 if ((cmd = (struct scsi_cmnd *) escb->srb) == NULL) {
997 printk(KERN_ERR "inia100_scb_handler: SRB pointer is empty\n");
998 orc_release_scb(host, scb);
999 return;
1000 }
1001 escb->srb = NULL;
1002
1003 switch (scb->hastat) {
1004 case 0x0:
1005 case 0xa:
1006 case 0xb:
1007 scb->hastat = 0;
1008 break;
1009
1010 case 0x11:
1011
1012 scb->hastat = DID_TIME_OUT;
1013 break;
1014
1015 case 0x14:
1016
1017
1018
1019 scb->hastat = DID_RESET;
1020 break;
1021
1022 case 0x1a:
1023 scb->hastat = DID_ABORT;
1024 break;
1025
1026 case 0x12:
1027
1028
1029 case 0x13:
1030 case 0x16:
1031
1032 default:
1033 printk(KERN_DEBUG "inia100: %x %x\n", scb->hastat, scb->tastat);
1034 scb->hastat = DID_ERROR;
1035 break;
1036 }
1037
1038 if (scb->tastat == 2) {
1039 memcpy((unsigned char *) &cmd->sense_buffer[0],
1040 (unsigned char *) &escb->sglist[0], SENSE_SIZE);
1041 }
1042 cmd->result = scb->tastat | (scb->hastat << 16);
1043 scsi_dma_unmap(cmd);
1044 cmd->scsi_done(cmd);
1045 orc_release_scb(host, scb);
1046}
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056static irqreturn_t inia100_intr(int irqno, void *devid)
1057{
1058 struct Scsi_Host *shost = (struct Scsi_Host *)devid;
1059 struct orc_host *host = (struct orc_host *)shost->hostdata;
1060 unsigned long flags;
1061 irqreturn_t res;
1062
1063 spin_lock_irqsave(shost->host_lock, flags);
1064 res = orc_interrupt(host);
1065 spin_unlock_irqrestore(shost->host_lock, flags);
1066
1067 return res;
1068}
1069
1070static struct scsi_host_template inia100_template = {
1071 .proc_name = "inia100",
1072 .name = inia100_REVID,
1073 .queuecommand = inia100_queue,
1074 .eh_abort_handler = inia100_abort,
1075 .eh_bus_reset_handler = inia100_bus_reset,
1076 .eh_device_reset_handler = inia100_device_reset,
1077 .can_queue = 1,
1078 .this_id = 1,
1079 .sg_tablesize = SG_ALL,
1080 .cmd_per_lun = 1,
1081 .use_clustering = ENABLE_CLUSTERING,
1082};
1083
1084static int __devinit inia100_probe_one(struct pci_dev *pdev,
1085 const struct pci_device_id *id)
1086{
1087 struct Scsi_Host *shost;
1088 struct orc_host *host;
1089 unsigned long port, bios;
1090 int error = -ENODEV;
1091 u32 sz;
1092 unsigned long biosaddr;
1093 char *bios_phys;
1094
1095 if (pci_enable_device(pdev))
1096 goto out;
1097 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
1098 printk(KERN_WARNING "Unable to set 32bit DMA "
1099 "on inia100 adapter, ignoring.\n");
1100 goto out_disable_device;
1101 }
1102
1103 pci_set_master(pdev);
1104
1105 port = pci_resource_start(pdev, 0);
1106 if (!request_region(port, 256, "inia100")) {
1107 printk(KERN_WARNING "inia100: io port 0x%lx, is busy.\n", port);
1108 goto out_disable_device;
1109 }
1110
1111
1112 bios = inw(port + 0x50);
1113
1114
1115 shost = scsi_host_alloc(&inia100_template, sizeof(struct orc_host));
1116 if (!shost)
1117 goto out_release_region;
1118
1119 host = (struct orc_host *)shost->hostdata;
1120 host->pdev = pdev;
1121 host->base = port;
1122 host->BIOScfg = bios;
1123 spin_lock_init(&host->allocation_lock);
1124
1125
1126 sz = ORC_MAXQUEUE * sizeof(struct orc_scb);
1127 host->scb_virt = pci_alloc_consistent(pdev, sz,
1128 &host->scb_phys);
1129 if (!host->scb_virt) {
1130 printk("inia100: SCB memory allocation error\n");
1131 goto out_host_put;
1132 }
1133 memset(host->scb_virt, 0, sz);
1134
1135
1136 sz = ORC_MAXQUEUE * sizeof(struct orc_extended_scb);
1137 host->escb_virt = pci_alloc_consistent(pdev, sz,
1138 &host->escb_phys);
1139 if (!host->escb_virt) {
1140 printk("inia100: ESCB memory allocation error\n");
1141 goto out_free_scb_array;
1142 }
1143 memset(host->escb_virt, 0, sz);
1144
1145 biosaddr = host->BIOScfg;
1146 biosaddr = (biosaddr << 4);
1147 bios_phys = phys_to_virt(biosaddr);
1148 if (init_orchid(host)) {
1149 printk("inia100: initial orchid fail!!\n");
1150 goto out_free_escb_array;
1151 }
1152
1153 shost->io_port = host->base;
1154 shost->n_io_port = 0xff;
1155 shost->can_queue = ORC_MAXQUEUE;
1156 shost->unique_id = shost->io_port;
1157 shost->max_id = host->max_targets;
1158 shost->max_lun = 16;
1159 shost->irq = pdev->irq;
1160 shost->this_id = host->scsi_id;
1161 shost->sg_tablesize = TOTAL_SG_ENTRY;
1162
1163
1164 error = request_irq(pdev->irq, inia100_intr, IRQF_SHARED,
1165 "inia100", shost);
1166 if (error < 0) {
1167 printk(KERN_WARNING "inia100: unable to get irq %d\n",
1168 pdev->irq);
1169 goto out_free_escb_array;
1170 }
1171
1172 pci_set_drvdata(pdev, shost);
1173
1174 error = scsi_add_host(shost, &pdev->dev);
1175 if (error)
1176 goto out_free_irq;
1177
1178 scsi_scan_host(shost);
1179 return 0;
1180
1181out_free_irq:
1182 free_irq(shost->irq, shost);
1183out_free_escb_array:
1184 pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_extended_scb),
1185 host->escb_virt, host->escb_phys);
1186out_free_scb_array:
1187 pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_scb),
1188 host->scb_virt, host->scb_phys);
1189out_host_put:
1190 scsi_host_put(shost);
1191out_release_region:
1192 release_region(port, 256);
1193out_disable_device:
1194 pci_disable_device(pdev);
1195out:
1196 return error;
1197}
1198
1199static void __devexit inia100_remove_one(struct pci_dev *pdev)
1200{
1201 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1202 struct orc_host *host = (struct orc_host *)shost->hostdata;
1203
1204 scsi_remove_host(shost);
1205
1206 free_irq(shost->irq, shost);
1207 pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_extended_scb),
1208 host->escb_virt, host->escb_phys);
1209 pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_scb),
1210 host->scb_virt, host->scb_phys);
1211 release_region(shost->io_port, 256);
1212
1213 scsi_host_put(shost);
1214}
1215
1216static struct pci_device_id inia100_pci_tbl[] = {
1217 {PCI_VENDOR_ID_INIT, 0x1060, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1218 {0,}
1219};
1220MODULE_DEVICE_TABLE(pci, inia100_pci_tbl);
1221
1222static struct pci_driver inia100_pci_driver = {
1223 .name = "inia100",
1224 .id_table = inia100_pci_tbl,
1225 .probe = inia100_probe_one,
1226 .remove = __devexit_p(inia100_remove_one),
1227};
1228
1229static int __init inia100_init(void)
1230{
1231 return pci_register_driver(&inia100_pci_driver);
1232}
1233
1234static void __exit inia100_exit(void)
1235{
1236 pci_unregister_driver(&inia100_pci_driver);
1237}
1238
1239MODULE_DESCRIPTION("Initio A100U2W SCSI driver");
1240MODULE_AUTHOR("Initio Corporation");
1241MODULE_LICENSE("Dual BSD/GPL");
1242
1243module_init(inia100_init);
1244module_exit(inia100_exit);
1245