0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 #include <linux/module.h>
0062 #include <linux/errno.h>
0063 #include <linux/delay.h>
0064 #include <linux/interrupt.h>
0065 #include <linux/pci.h>
0066 #include <linux/init.h>
0067 #include <linux/blkdev.h>
0068 #include <linux/spinlock.h>
0069 #include <linux/kernel.h>
0070 #include <linux/string.h>
0071 #include <linux/ioport.h>
0072 #include <linux/dma-mapping.h>
0073
0074 #include <asm/io.h>
0075 #include <asm/irq.h>
0076
0077 #include <scsi/scsi.h>
0078 #include <scsi/scsi_cmnd.h>
0079 #include <scsi/scsi_device.h>
0080 #include <scsi/scsi_host.h>
0081
0082 #include "a100u2w.h"
0083
0084
0085 static struct orc_scb *__orc_alloc_scb(struct orc_host * host);
0086 static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb);
0087
0088 static struct orc_nvram nvram, *nvramp = &nvram;
0089
0090 static u8 default_nvram[64] =
0091 {
0092
0093 0x01,
0094 0x11,
0095 0x60,
0096 0x10,
0097 0x00,
0098 0x01,
0099 0x11,
0100 0x60,
0101 0x10,
0102 0x00,
0103 0x00,
0104 0x01,
0105
0106 0x01,
0107 0x01,
0108 0x00,
0109 0x00,
0110
0111 0x07,
0112 0x83,
0113 0x20,
0114 0x0A,
0115 0x00,
0116 0x00,
0117
0118
0119 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
0120 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
0121
0122 0x07,
0123 0x83,
0124 0x20,
0125 0x0A,
0126 0x00,
0127 0x00,
0128
0129
0130 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
0131 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
0132 0x00,
0133 0x00,
0134 0x00,
0135 0x00
0136 };
0137
0138
0139 static u8 wait_chip_ready(struct orc_host * host)
0140 {
0141 int i;
0142
0143 for (i = 0; i < 10; i++) {
0144 if (inb(host->base + ORC_HCTRL) & HOSTSTOP)
0145 return 1;
0146 msleep(100);
0147 }
0148 return 0;
0149 }
0150
0151 static u8 wait_firmware_ready(struct orc_host * host)
0152 {
0153 int i;
0154
0155 for (i = 0; i < 10; i++) {
0156 if (inb(host->base + ORC_HSTUS) & RREADY)
0157 return 1;
0158 msleep(100);
0159 }
0160 return 0;
0161 }
0162
0163
0164 static u8 wait_scsi_reset_done(struct orc_host * host)
0165 {
0166 int i;
0167
0168 for (i = 0; i < 10; i++) {
0169 if (!(inb(host->base + ORC_HCTRL) & SCSIRST))
0170 return 1;
0171 mdelay(100);
0172 }
0173 return 0;
0174 }
0175
0176
0177 static u8 wait_HDO_off(struct orc_host * host)
0178 {
0179 int i;
0180
0181 for (i = 0; i < 10; i++) {
0182 if (!(inb(host->base + ORC_HCTRL) & HDO))
0183 return 1;
0184 mdelay(100);
0185 }
0186 return 0;
0187 }
0188
0189
0190 static u8 wait_hdi_set(struct orc_host * host, u8 * data)
0191 {
0192 int i;
0193
0194 for (i = 0; i < 10; i++) {
0195 if ((*data = inb(host->base + ORC_HSTUS)) & HDI)
0196 return 1;
0197 mdelay(100);
0198 }
0199 return 0;
0200 }
0201
0202
0203 static unsigned short orc_read_fwrev(struct orc_host * host)
0204 {
0205 u16 version;
0206 u8 data;
0207
0208 outb(ORC_CMD_VERSION, host->base + ORC_HDATA);
0209 outb(HDO, host->base + ORC_HCTRL);
0210 if (wait_HDO_off(host) == 0)
0211 return 0;
0212
0213 if (wait_hdi_set(host, &data) == 0)
0214 return 0;
0215 version = inb(host->base + ORC_HDATA);
0216 outb(data, host->base + ORC_HSTUS);
0217
0218 if (wait_hdi_set(host, &data) == 0)
0219 return 0;
0220 version |= inb(host->base + ORC_HDATA) << 8;
0221 outb(data, host->base + ORC_HSTUS);
0222
0223 return version;
0224 }
0225
0226
0227 static u8 orc_nv_write(struct orc_host * host, unsigned char address, unsigned char value)
0228 {
0229 outb(ORC_CMD_SET_NVM, host->base + ORC_HDATA);
0230 outb(HDO, host->base + ORC_HCTRL);
0231 if (wait_HDO_off(host) == 0)
0232 return 0;
0233
0234 outb(address, host->base + ORC_HDATA);
0235 outb(HDO, host->base + ORC_HCTRL);
0236 if (wait_HDO_off(host) == 0)
0237 return 0;
0238
0239 outb(value, host->base + ORC_HDATA);
0240 outb(HDO, host->base + ORC_HCTRL);
0241 if (wait_HDO_off(host) == 0)
0242 return 0;
0243
0244 return 1;
0245 }
0246
0247
0248 static u8 orc_nv_read(struct orc_host * host, u8 address, u8 *ptr)
0249 {
0250 unsigned char data;
0251
0252 outb(ORC_CMD_GET_NVM, host->base + ORC_HDATA);
0253 outb(HDO, host->base + ORC_HCTRL);
0254 if (wait_HDO_off(host) == 0)
0255 return 0;
0256
0257 outb(address, host->base + ORC_HDATA);
0258 outb(HDO, host->base + ORC_HCTRL);
0259 if (wait_HDO_off(host) == 0)
0260 return 0;
0261
0262 if (wait_hdi_set(host, &data) == 0)
0263 return 0;
0264 *ptr = inb(host->base + ORC_HDATA);
0265 outb(data, host->base + ORC_HSTUS);
0266
0267 return 1;
0268
0269 }
0270
0271
0272
0273
0274
0275
0276
0277 static void orc_exec_scb(struct orc_host * host, struct orc_scb * scb)
0278 {
0279 scb->status = ORCSCB_POST;
0280 outb(scb->scbidx, host->base + ORC_PQUEUE);
0281 }
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291 static int se2_rd_all(struct orc_host * host)
0292 {
0293 int i;
0294 u8 *np, chksum = 0;
0295
0296 np = (u8 *) nvramp;
0297 for (i = 0; i < 64; i++, np++) {
0298 if (orc_nv_read(host, (u8) i, np) == 0)
0299 return -1;
0300 }
0301
0302
0303 np = (u8 *) nvramp;
0304 for (i = 0; i < 63; i++)
0305 chksum += *np++;
0306
0307 if (nvramp->CheckSum != (u8) chksum)
0308 return -1;
0309 return 1;
0310 }
0311
0312
0313
0314
0315
0316
0317
0318
0319 static void se2_update_all(struct orc_host * host)
0320 {
0321 int i;
0322 u8 *np, *np1, chksum = 0;
0323
0324
0325 np = (u8 *) default_nvram;
0326 for (i = 0; i < 63; i++)
0327 chksum += *np++;
0328 *np = chksum;
0329
0330 np = (u8 *) default_nvram;
0331 np1 = (u8 *) nvramp;
0332 for (i = 0; i < 64; i++, np++, np1++) {
0333 if (*np != *np1)
0334 orc_nv_write(host, (u8) i, *np);
0335 }
0336 }
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346 static void read_eeprom(struct orc_host * host)
0347 {
0348 if (se2_rd_all(host) != 1) {
0349 se2_update_all(host);
0350 se2_rd_all(host);
0351 }
0352 }
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365 static u8 orc_load_firmware(struct orc_host * host)
0366 {
0367 u32 data32;
0368 u16 bios_addr;
0369 u16 i;
0370 u8 *data32_ptr, data;
0371
0372
0373
0374
0375 data = inb(host->base + ORC_GCFG);
0376 outb(data | EEPRG, host->base + ORC_GCFG);
0377 outb(0x00, host->base + ORC_EBIOSADR2);
0378 outw(0x0000, host->base + ORC_EBIOSADR0);
0379 if (inb(host->base + ORC_EBIOSDATA) != 0x55) {
0380 outb(data, host->base + ORC_GCFG);
0381 return 0;
0382 }
0383 outw(0x0001, host->base + ORC_EBIOSADR0);
0384 if (inb(host->base + ORC_EBIOSDATA) != 0xAA) {
0385 outb(data, host->base + ORC_GCFG);
0386 return 0;
0387 }
0388
0389 outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL);
0390 data32_ptr = (u8 *) & data32;
0391 data32 = cpu_to_le32(0);
0392 outw(0x0010, host->base + ORC_EBIOSADR0);
0393 *data32_ptr = inb(host->base + ORC_EBIOSDATA);
0394 outw(0x0011, host->base + ORC_EBIOSADR0);
0395 *(data32_ptr + 1) = inb(host->base + ORC_EBIOSDATA);
0396 outw(0x0012, host->base + ORC_EBIOSADR0);
0397 *(data32_ptr + 2) = inb(host->base + ORC_EBIOSDATA);
0398 outw(*(data32_ptr + 2), host->base + ORC_EBIOSADR2);
0399 outl(le32_to_cpu(data32), host->base + ORC_FWBASEADR);
0400
0401
0402
0403 udelay(500);
0404 bios_addr = (u16) le32_to_cpu(data32);
0405 for (i = 0, data32_ptr = (u8 *) & data32;
0406 i < 0x1000;
0407 i++, bios_addr++) {
0408 outw(bios_addr, host->base + ORC_EBIOSADR0);
0409 *data32_ptr++ = inb(host->base + ORC_EBIOSDATA);
0410 if ((i % 4) == 3) {
0411 outl(le32_to_cpu(data32), host->base + ORC_RISCRAM);
0412 data32_ptr = (u8 *) & data32;
0413 }
0414 }
0415
0416
0417
0418 outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL);
0419 bios_addr -= 0x1000;
0420 for (i = 0, data32_ptr = (u8 *) & data32;
0421 i < 0x1000;
0422 i++, bios_addr++) {
0423 outw(bios_addr, host->base + ORC_EBIOSADR0);
0424 *data32_ptr++ = inb(host->base + ORC_EBIOSDATA);
0425 if ((i % 4) == 3) {
0426 if (inl(host->base + ORC_RISCRAM) != le32_to_cpu(data32)) {
0427 outb(PRGMRST, host->base + ORC_RISCCTL);
0428 outb(data, host->base + ORC_GCFG);
0429 return 0;
0430 }
0431 data32_ptr = (u8 *) & data32;
0432 }
0433 }
0434
0435
0436 outb(PRGMRST, host->base + ORC_RISCCTL);
0437 outb(data, host->base + ORC_GCFG);
0438 return 1;
0439 }
0440
0441
0442 static void setup_SCBs(struct orc_host * host)
0443 {
0444 struct orc_scb *scb;
0445 int i;
0446 struct orc_extended_scb *escb;
0447 dma_addr_t escb_phys;
0448
0449
0450 outb(ORC_MAXQUEUE, host->base + ORC_SCBSIZE);
0451
0452 outl(host->scb_phys, host->base + ORC_SCBBASE0);
0453
0454 outl(host->scb_phys, host->base + ORC_SCBBASE1);
0455
0456
0457 scb = host->scb_virt;
0458 escb = host->escb_virt;
0459
0460 for (i = 0; i < ORC_MAXQUEUE; i++) {
0461 escb_phys = (host->escb_phys + (sizeof(struct orc_extended_scb) * i));
0462 scb->sg_addr = cpu_to_le32((u32) escb_phys);
0463 scb->sense_addr = cpu_to_le32((u32) escb_phys);
0464 scb->escb = escb;
0465 scb->scbidx = i;
0466 scb++;
0467 escb++;
0468 }
0469 }
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479 static void init_alloc_map(struct orc_host * host)
0480 {
0481 u8 i, j;
0482
0483 for (i = 0; i < MAX_CHANNELS; i++) {
0484 for (j = 0; j < 8; j++) {
0485 host->allocation_map[i][j] = 0xffffffff;
0486 }
0487 }
0488 }
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499 static int init_orchid(struct orc_host * host)
0500 {
0501 u8 *ptr;
0502 u16 revision;
0503 u8 i;
0504
0505 init_alloc_map(host);
0506 outb(0xFF, host->base + ORC_GIMSK);
0507
0508 if (inb(host->base + ORC_HSTUS) & RREADY) {
0509 revision = orc_read_fwrev(host);
0510 if (revision == 0xFFFF) {
0511 outb(DEVRST, host->base + ORC_HCTRL);
0512 if (wait_chip_ready(host) == 0)
0513 return -1;
0514 orc_load_firmware(host);
0515 setup_SCBs(host);
0516 outb(0x00, host->base + ORC_HCTRL);
0517 if (wait_firmware_ready(host) == 0)
0518 return -1;
0519
0520 } else {
0521 setup_SCBs(host);
0522 }
0523 } else {
0524 outb(DEVRST, host->base + ORC_HCTRL);
0525 if (wait_chip_ready(host) == 0)
0526 return -1;
0527 orc_load_firmware(host);
0528 setup_SCBs(host);
0529 outb(HDO, host->base + ORC_HCTRL);
0530
0531
0532 if (wait_firmware_ready(host) == 0)
0533 return -1;
0534 }
0535
0536
0537
0538 read_eeprom(host);
0539
0540 if (nvramp->revision != 1)
0541 return -1;
0542
0543 host->scsi_id = nvramp->scsi_id;
0544 host->BIOScfg = nvramp->BIOSConfig1;
0545 host->max_targets = MAX_TARGETS;
0546 ptr = (u8 *) & (nvramp->Target00Config);
0547 for (i = 0; i < 16; ptr++, i++) {
0548 host->target_flag[i] = *ptr;
0549 host->max_tags[i] = ORC_MAXTAGS;
0550 }
0551
0552 if (nvramp->SCSI0Config & NCC_BUSRESET)
0553 host->flags |= HCF_SCSI_RESET;
0554 outb(0xFB, host->base + ORC_GIMSK);
0555 return 0;
0556 }
0557
0558
0559
0560
0561
0562
0563
0564
0565 static int orc_reset_scsi_bus(struct orc_host * host)
0566 {
0567 unsigned long flags;
0568
0569 spin_lock_irqsave(&host->allocation_lock, flags);
0570
0571 init_alloc_map(host);
0572
0573 outb(SCSIRST, host->base + ORC_HCTRL);
0574
0575
0576 if (wait_scsi_reset_done(host) == 0) {
0577 spin_unlock_irqrestore(&host->allocation_lock, flags);
0578 return FAILED;
0579 } else {
0580 spin_unlock_irqrestore(&host->allocation_lock, flags);
0581 return SUCCESS;
0582 }
0583 }
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595 static int orc_device_reset(struct orc_host * host, struct scsi_cmnd *cmd, unsigned int target)
0596 {
0597 struct orc_scb *scb;
0598 struct orc_extended_scb *escb;
0599 struct orc_scb *host_scb;
0600 u8 i;
0601 unsigned long flags;
0602
0603 spin_lock_irqsave(&(host->allocation_lock), flags);
0604 scb = (struct orc_scb *) NULL;
0605 escb = (struct orc_extended_scb *) NULL;
0606
0607
0608 host_scb = host->scb_virt;
0609
0610
0611
0612 init_alloc_map(host);
0613
0614
0615 for (i = 0; i < ORC_MAXQUEUE; i++) {
0616 escb = host_scb->escb;
0617 if (host_scb->status && escb->srb == cmd)
0618 break;
0619 host_scb++;
0620 }
0621
0622 if (i == ORC_MAXQUEUE) {
0623 printk(KERN_ERR "Unable to Reset - No SCB Found\n");
0624 spin_unlock_irqrestore(&(host->allocation_lock), flags);
0625 return FAILED;
0626 }
0627
0628
0629 if ((scb = __orc_alloc_scb(host)) == NULL) {
0630
0631 spin_unlock_irqrestore(&(host->allocation_lock), flags);
0632 return FAILED;
0633 }
0634
0635
0636
0637 scb->opcode = ORC_BUSDEVRST;
0638 scb->target = target;
0639 scb->hastat = 0;
0640 scb->tastat = 0;
0641 scb->status = 0x0;
0642 scb->link = 0xFF;
0643 scb->reserved0 = 0;
0644 scb->reserved1 = 0;
0645 scb->xferlen = cpu_to_le32(0);
0646 scb->sg_len = cpu_to_le32(0);
0647
0648 escb->srb = NULL;
0649 escb->srb = cmd;
0650 orc_exec_scb(host, scb);
0651 spin_unlock_irqrestore(&host->allocation_lock, flags);
0652 return SUCCESS;
0653 }
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664
0665 static struct orc_scb *__orc_alloc_scb(struct orc_host * host)
0666 {
0667 u8 channel;
0668 unsigned long idx;
0669 u8 index;
0670 u8 i;
0671
0672 channel = host->index;
0673 for (i = 0; i < 8; i++) {
0674 for (index = 0; index < 32; index++) {
0675 if ((host->allocation_map[channel][i] >> index) & 0x01) {
0676 host->allocation_map[channel][i] &= ~(1 << index);
0677 idx = index + 32 * i;
0678
0679
0680
0681 return host->scb_virt + idx;
0682 }
0683 }
0684 }
0685 return NULL;
0686 }
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696 static struct orc_scb *orc_alloc_scb(struct orc_host * host)
0697 {
0698 struct orc_scb *scb;
0699 unsigned long flags;
0700
0701 spin_lock_irqsave(&host->allocation_lock, flags);
0702 scb = __orc_alloc_scb(host);
0703 spin_unlock_irqrestore(&host->allocation_lock, flags);
0704 return scb;
0705 }
0706
0707
0708
0709
0710
0711
0712
0713
0714
0715
0716 static void orc_release_scb(struct orc_host *host, struct orc_scb *scb)
0717 {
0718 unsigned long flags;
0719 u8 index, i, channel;
0720
0721 spin_lock_irqsave(&(host->allocation_lock), flags);
0722 channel = host->index;
0723 index = scb->scbidx;
0724 i = index / 32;
0725 index %= 32;
0726 host->allocation_map[channel][i] |= (1 << index);
0727 spin_unlock_irqrestore(&(host->allocation_lock), flags);
0728 }
0729
0730
0731
0732
0733
0734
0735
0736
0737
0738 static int orchid_abort_scb(struct orc_host * host, struct orc_scb * scb)
0739 {
0740 unsigned char data, status;
0741
0742 outb(ORC_CMD_ABORT_SCB, host->base + ORC_HDATA);
0743 outb(HDO, host->base + ORC_HCTRL);
0744 if (wait_HDO_off(host) == 0)
0745 return 0;
0746
0747 outb(scb->scbidx, host->base + ORC_HDATA);
0748 outb(HDO, host->base + ORC_HCTRL);
0749 if (wait_HDO_off(host) == 0)
0750 return 0;
0751
0752 if (wait_hdi_set(host, &data) == 0)
0753 return 0;
0754 status = inb(host->base + ORC_HDATA);
0755 outb(data, host->base + ORC_HSTUS);
0756
0757 if (status == 1)
0758 return 0;
0759 return 1;
0760 }
0761
0762 static int inia100_abort_cmd(struct orc_host * host, struct scsi_cmnd *cmd)
0763 {
0764 struct orc_extended_scb *escb;
0765 struct orc_scb *scb;
0766 u8 i;
0767 unsigned long flags;
0768
0769 spin_lock_irqsave(&(host->allocation_lock), flags);
0770
0771 scb = host->scb_virt;
0772
0773
0774
0775
0776
0777 for (i = 0; i < ORC_MAXQUEUE; i++, scb++) {
0778 escb = scb->escb;
0779 if (scb->status && escb->srb == cmd) {
0780 if (scb->tag_msg == 0) {
0781 goto out;
0782 } else {
0783
0784 if (orchid_abort_scb(host, scb)) {
0785 escb->srb = NULL;
0786 spin_unlock_irqrestore(&host->allocation_lock, flags);
0787 return SUCCESS;
0788 } else
0789 goto out;
0790 }
0791 }
0792 }
0793 out:
0794 spin_unlock_irqrestore(&host->allocation_lock, flags);
0795 return FAILED;
0796 }
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811 static irqreturn_t orc_interrupt(struct orc_host * host)
0812 {
0813 u8 scb_index;
0814 struct orc_scb *scb;
0815
0816
0817 if (inb(host->base + ORC_RQUEUECNT) == 0)
0818 return IRQ_NONE;
0819
0820 do {
0821
0822 scb_index = inb(host->base + ORC_RQUEUE);
0823
0824
0825 scb = (struct orc_scb *) ((unsigned long) host->scb_virt + (unsigned long) (sizeof(struct orc_scb) * scb_index));
0826 scb->status = 0x0;
0827
0828 inia100_scb_handler(host, scb);
0829 } while (inb(host->base + ORC_RQUEUECNT));
0830 return IRQ_HANDLED;
0831 }
0832
0833
0834
0835
0836
0837
0838
0839
0840
0841
0842 static int inia100_build_scb(struct orc_host * host, struct orc_scb * scb, struct scsi_cmnd * cmd)
0843 {
0844 struct scatterlist *sg;
0845 struct orc_sgent *sgent;
0846 int i, count_sg;
0847 struct orc_extended_scb *escb;
0848
0849
0850 escb = scb->escb;
0851 escb->srb = cmd;
0852 sgent = NULL;
0853
0854
0855 scb->opcode = ORC_EXECSCSI;
0856 scb->flags = SCF_NO_DCHK;
0857 scb->target = cmd->device->id;
0858 scb->lun = cmd->device->lun;
0859 scb->reserved0 = 0;
0860 scb->reserved1 = 0;
0861 scb->sg_len = cpu_to_le32(0);
0862
0863 scb->xferlen = cpu_to_le32((u32) scsi_bufflen(cmd));
0864 sgent = (struct orc_sgent *) & escb->sglist[0];
0865
0866 count_sg = scsi_dma_map(cmd);
0867 if (count_sg < 0)
0868 return count_sg;
0869 BUG_ON(count_sg > TOTAL_SG_ENTRY);
0870
0871
0872 if (count_sg) {
0873 scb->sg_len = cpu_to_le32((u32) (count_sg * 8));
0874 scsi_for_each_sg(cmd, sg, count_sg, i) {
0875 sgent->base = cpu_to_le32((u32) sg_dma_address(sg));
0876 sgent->length = cpu_to_le32((u32) sg_dma_len(sg));
0877 sgent++;
0878 }
0879 } else {
0880 scb->sg_len = cpu_to_le32(0);
0881 sgent->base = cpu_to_le32(0);
0882 sgent->length = cpu_to_le32(0);
0883 }
0884 scb->sg_addr = (u32) scb->sense_addr;
0885 scb->hastat = 0;
0886 scb->tastat = 0;
0887 scb->link = 0xFF;
0888 scb->sense_len = SENSE_SIZE;
0889 scb->cdb_len = cmd->cmd_len;
0890 if (scb->cdb_len >= IMAX_CDB) {
0891 printk("max cdb length= %x\n", cmd->cmd_len);
0892 scb->cdb_len = IMAX_CDB;
0893 }
0894 scb->ident = (u8)(cmd->device->lun & 0xff) | DISC_ALLOW;
0895 if (cmd->device->tagged_supported) {
0896 scb->tag_msg = SIMPLE_QUEUE_TAG;
0897 } else {
0898 scb->tag_msg = 0;
0899 }
0900 memcpy(scb->cdb, cmd->cmnd, scb->cdb_len);
0901 return 0;
0902 }
0903
0904
0905
0906
0907
0908
0909
0910
0911
0912 static int inia100_queue_lck(struct scsi_cmnd *cmd)
0913 {
0914 struct orc_scb *scb;
0915 struct orc_host *host;
0916
0917 host = (struct orc_host *) cmd->device->host->hostdata;
0918
0919 if ((scb = orc_alloc_scb(host)) == NULL)
0920 return SCSI_MLQUEUE_HOST_BUSY;
0921
0922 if (inia100_build_scb(host, scb, cmd)) {
0923 orc_release_scb(host, scb);
0924 return SCSI_MLQUEUE_HOST_BUSY;
0925 }
0926 orc_exec_scb(host, scb);
0927 return 0;
0928 }
0929
0930 static DEF_SCSI_QCMD(inia100_queue)
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940 static int inia100_abort(struct scsi_cmnd * cmd)
0941 {
0942 struct orc_host *host;
0943
0944 host = (struct orc_host *) cmd->device->host->hostdata;
0945 return inia100_abort_cmd(host, cmd);
0946 }
0947
0948
0949
0950
0951
0952
0953
0954
0955
0956 static int inia100_bus_reset(struct scsi_cmnd * cmd)
0957 {
0958 struct orc_host *host;
0959 host = (struct orc_host *) cmd->device->host->hostdata;
0960 return orc_reset_scsi_bus(host);
0961 }
0962
0963
0964
0965
0966
0967
0968
0969
0970 static int inia100_device_reset(struct scsi_cmnd * cmd)
0971 {
0972 struct orc_host *host;
0973 host = (struct orc_host *) cmd->device->host->hostdata;
0974 return orc_device_reset(host, cmd, scmd_id(cmd));
0975
0976 }
0977
0978
0979
0980
0981
0982
0983
0984
0985
0986
0987
0988 static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb)
0989 {
0990 struct scsi_cmnd *cmd;
0991 struct orc_extended_scb *escb;
0992
0993 escb = scb->escb;
0994 if ((cmd = (struct scsi_cmnd *) escb->srb) == NULL) {
0995 printk(KERN_ERR "inia100_scb_handler: SRB pointer is empty\n");
0996 orc_release_scb(host, scb);
0997 return;
0998 }
0999 escb->srb = NULL;
1000
1001 switch (scb->hastat) {
1002 case 0x0:
1003 case 0xa:
1004 case 0xb:
1005 scb->hastat = 0;
1006 break;
1007
1008 case 0x11:
1009
1010 scb->hastat = DID_TIME_OUT;
1011 break;
1012
1013 case 0x14:
1014
1015
1016
1017 scb->hastat = DID_RESET;
1018 break;
1019
1020 case 0x1a:
1021 scb->hastat = DID_ABORT;
1022 break;
1023
1024 case 0x12:
1025
1026
1027 case 0x13:
1028 case 0x16:
1029
1030 default:
1031 printk(KERN_DEBUG "inia100: %x %x\n", scb->hastat, scb->tastat);
1032 scb->hastat = DID_ERROR;
1033 break;
1034 }
1035
1036 if (scb->tastat == 2) {
1037 memcpy((unsigned char *) &cmd->sense_buffer[0],
1038 (unsigned char *) &escb->sglist[0], SENSE_SIZE);
1039 }
1040 cmd->result = scb->tastat | (scb->hastat << 16);
1041 scsi_dma_unmap(cmd);
1042 scsi_done(cmd);
1043 orc_release_scb(host, scb);
1044 }
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054 static irqreturn_t inia100_intr(int irqno, void *devid)
1055 {
1056 struct Scsi_Host *shost = (struct Scsi_Host *)devid;
1057 struct orc_host *host = (struct orc_host *)shost->hostdata;
1058 unsigned long flags;
1059 irqreturn_t res;
1060
1061 spin_lock_irqsave(shost->host_lock, flags);
1062 res = orc_interrupt(host);
1063 spin_unlock_irqrestore(shost->host_lock, flags);
1064
1065 return res;
1066 }
1067
1068 static struct scsi_host_template inia100_template = {
1069 .proc_name = "inia100",
1070 .name = inia100_REVID,
1071 .queuecommand = inia100_queue,
1072 .eh_abort_handler = inia100_abort,
1073 .eh_bus_reset_handler = inia100_bus_reset,
1074 .eh_device_reset_handler = inia100_device_reset,
1075 .can_queue = 1,
1076 .this_id = 1,
1077 .sg_tablesize = SG_ALL,
1078 };
1079
1080 static int inia100_probe_one(struct pci_dev *pdev,
1081 const struct pci_device_id *id)
1082 {
1083 struct Scsi_Host *shost;
1084 struct orc_host *host;
1085 unsigned long port, bios;
1086 int error = -ENODEV;
1087 u32 sz;
1088
1089 if (pci_enable_device(pdev))
1090 goto out;
1091 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
1092 printk(KERN_WARNING "Unable to set 32bit DMA "
1093 "on inia100 adapter, ignoring.\n");
1094 goto out_disable_device;
1095 }
1096
1097 pci_set_master(pdev);
1098
1099 port = pci_resource_start(pdev, 0);
1100 if (!request_region(port, 256, "inia100")) {
1101 printk(KERN_WARNING "inia100: io port 0x%lx, is busy.\n", port);
1102 goto out_disable_device;
1103 }
1104
1105
1106 bios = inw(port + 0x50);
1107
1108
1109 shost = scsi_host_alloc(&inia100_template, sizeof(struct orc_host));
1110 if (!shost)
1111 goto out_release_region;
1112
1113 host = (struct orc_host *)shost->hostdata;
1114 host->pdev = pdev;
1115 host->base = port;
1116 host->BIOScfg = bios;
1117 spin_lock_init(&host->allocation_lock);
1118
1119
1120 sz = ORC_MAXQUEUE * sizeof(struct orc_scb);
1121 host->scb_virt = dma_alloc_coherent(&pdev->dev, sz, &host->scb_phys,
1122 GFP_KERNEL);
1123 if (!host->scb_virt) {
1124 printk("inia100: SCB memory allocation error\n");
1125 goto out_host_put;
1126 }
1127
1128
1129 sz = ORC_MAXQUEUE * sizeof(struct orc_extended_scb);
1130 host->escb_virt = dma_alloc_coherent(&pdev->dev, sz, &host->escb_phys,
1131 GFP_KERNEL);
1132 if (!host->escb_virt) {
1133 printk("inia100: ESCB memory allocation error\n");
1134 goto out_free_scb_array;
1135 }
1136
1137 if (init_orchid(host)) {
1138 printk("inia100: initial orchid fail!!\n");
1139 goto out_free_escb_array;
1140 }
1141
1142 shost->io_port = host->base;
1143 shost->n_io_port = 0xff;
1144 shost->can_queue = ORC_MAXQUEUE;
1145 shost->unique_id = shost->io_port;
1146 shost->max_id = host->max_targets;
1147 shost->max_lun = 16;
1148 shost->irq = pdev->irq;
1149 shost->this_id = host->scsi_id;
1150 shost->sg_tablesize = TOTAL_SG_ENTRY;
1151
1152
1153 error = request_irq(pdev->irq, inia100_intr, IRQF_SHARED,
1154 "inia100", shost);
1155 if (error < 0) {
1156 printk(KERN_WARNING "inia100: unable to get irq %d\n",
1157 pdev->irq);
1158 goto out_free_escb_array;
1159 }
1160
1161 pci_set_drvdata(pdev, shost);
1162
1163 error = scsi_add_host(shost, &pdev->dev);
1164 if (error)
1165 goto out_free_irq;
1166
1167 scsi_scan_host(shost);
1168 return 0;
1169
1170 out_free_irq:
1171 free_irq(shost->irq, shost);
1172 out_free_escb_array:
1173 dma_free_coherent(&pdev->dev,
1174 ORC_MAXQUEUE * sizeof(struct orc_extended_scb),
1175 host->escb_virt, host->escb_phys);
1176 out_free_scb_array:
1177 dma_free_coherent(&pdev->dev,
1178 ORC_MAXQUEUE * sizeof(struct orc_scb),
1179 host->scb_virt, host->scb_phys);
1180 out_host_put:
1181 scsi_host_put(shost);
1182 out_release_region:
1183 release_region(port, 256);
1184 out_disable_device:
1185 pci_disable_device(pdev);
1186 out:
1187 return error;
1188 }
1189
1190 static void inia100_remove_one(struct pci_dev *pdev)
1191 {
1192 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1193 struct orc_host *host = (struct orc_host *)shost->hostdata;
1194
1195 scsi_remove_host(shost);
1196
1197 free_irq(shost->irq, shost);
1198 dma_free_coherent(&pdev->dev,
1199 ORC_MAXQUEUE * sizeof(struct orc_extended_scb),
1200 host->escb_virt, host->escb_phys);
1201 dma_free_coherent(&pdev->dev,
1202 ORC_MAXQUEUE * sizeof(struct orc_scb),
1203 host->scb_virt, host->scb_phys);
1204 release_region(shost->io_port, 256);
1205
1206 scsi_host_put(shost);
1207 }
1208
1209 static struct pci_device_id inia100_pci_tbl[] = {
1210 {PCI_VENDOR_ID_INIT, 0x1060, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1211 {0,}
1212 };
1213 MODULE_DEVICE_TABLE(pci, inia100_pci_tbl);
1214
1215 static struct pci_driver inia100_pci_driver = {
1216 .name = "inia100",
1217 .id_table = inia100_pci_tbl,
1218 .probe = inia100_probe_one,
1219 .remove = inia100_remove_one,
1220 };
1221
1222 module_pci_driver(inia100_pci_driver);
1223
1224 MODULE_DESCRIPTION("Initio A100U2W SCSI driver");
1225 MODULE_AUTHOR("Initio Corporation");
1226 MODULE_LICENSE("Dual BSD/GPL");