40 #define SYM53C500_DEBUG 0
41 #define VERBOSE_SYM53C500_DEBUG 0
47 #define USE_FAST_PIO 1
51 #include <linux/module.h>
53 #include <linux/errno.h>
56 #include <linux/kernel.h>
57 #include <linux/slab.h>
58 #include <linux/string.h>
62 #include <linux/bitops.h>
71 #include <scsi/scsi.h>
96 #define SCSI_FIFO 0x02
101 #define SRTIMOUT 0x05
104 #define FIFO_FLAGS 0x07
119 #define PIO_FIFO 0x04
123 #define PIO_STATUS 0x08
126 #define PIO_FLAG 0x0B
133 #define REG0(x) (outb(C4_IMG, (x) + CONFIG4))
135 #define REG1(x) outb(C7_IMG, (x) + CONFIG7); outb(C5_IMG, (x) + CONFIG5)
143 #if VERBOSE_SYM53C500_DEBUG
149 #define LOAD_DMA_COUNT(x, count) \
150 outb(count & 0xff, (x) + TC_LSB); \
151 outb((count >> 8) & 0xff, (x) + TC_MSB); \
152 outb((count >> 16) & 0xff, (x) + TC_HIGH);
157 #define SCSI_NOP 0x00
158 #define FLUSH_FIFO 0x01
159 #define CHIP_RESET 0x02
160 #define SCSI_RESET 0x03
161 #define RESELECT 0x40
162 #define SELECT_NO_ATN 0x41
163 #define SELECT_ATN 0x42
164 #define SELECT_ATN_STOP 0x43
165 #define ENABLE_SEL 0x44
166 #define DISABLE_SEL 0x45
167 #define SELECT_ATN3 0x46
168 #define RESELECT3 0x47
169 #define TRANSFER_INFO 0x10
170 #define INIT_CMD_COMPLETE 0x11
171 #define MSG_ACCEPT 0x12
172 #define TRANSFER_PAD 0x18
174 #define RESET_ATN 0x1b
175 #define SEND_MSG 0x20
176 #define SEND_STATUS 0x21
177 #define SEND_DATA 0x22
178 #define DISCONN_SEQ 0x23
179 #define TERMINATE_SEQ 0x24
180 #define TARG_CMD_COMPLETE 0x25
182 #define RECV_MSG 0x28
183 #define RECV_CMD 0x29
184 #define RECV_DATA 0x2a
185 #define RECV_CMD_SEQ 0x2b
186 #define TARGET_ABORT_DMA 0x04
191 struct pcmcia_device *
p_dev;
235 SYM53C500_int_host_reset(
int io_port)
245 SYM53C500_pio_read(
int fast_pio,
int base,
unsigned char *
request,
unsigned int reqlen)
276 if ((i & 0x40) && len == 0) {
284 if (fast_pio && len > 3) {
286 request += len & 0xfc;
287 reqlen -= len & 0xfc;
300 SYM53C500_pio_write(
int fast_pio,
int base,
unsigned char *request,
unsigned int reqlen)
306 while (reqlen && !(i & 0x40)) {
335 if (fast_pio && len > 3) {
337 request += len & 0xfc;
338 reqlen -= len & 0xfc;
351 SYM53C500_intr(
int irq,
void *
dev_id)
356 DEB(
unsigned char seq_reg;)
357 unsigned char status, int_reg;
358 unsigned char pio_status;
378 printk(
"status=%02x, seq_reg=%02x, int_reg=%02x, fifo_size=%02x",
380 printk(
", pio=%02x\n", pio_status);
383 if (int_reg & 0x80) {
384 DEB(
printk(
"SYM53C500: reset intr received\n"));
389 if (pio_status & 0x80) {
390 printk(
"SYM53C500: Warning: PIO error!\n");
396 printk(
"SYM53C500: Warning: parity error!\n");
402 printk(
"SYM53C500: Warning: gross error!\n");
407 if (int_reg & 0x20) {
408 DEB(
printk(
"SYM53C500: disconnect intr received\n"));
412 curSC->result = (curSC->SCp.Status & 0xff)
413 | ((curSC->SCp.Message & 0xff) << 8) | (
DID_OK << 16);
418 switch (status & 0x07) {
420 if (int_reg & 0x10) {
431 SYM53C500_pio_write(fast_pio, port_base,
439 if (int_reg & 0x10) {
450 SYM53C500_pio_read(fast_pio, port_base,
459 printk(
"SYM53C500: Warning: Unknown interrupt occurred in command phase!\n");
471 printk(
"SYM53C500: WARNING: Reserved phase!!!\n");
475 DEB(
printk(
"SYM53C500: Message-Out phase\n"));
482 VDEB(
printk(
"SYM53C500: Message-In phase\n"));
489 DEB(
printk(
"Status = %02x Message = %02x\n", curSC->SCp.Status, curSC->SCp.Message));
493 DEB(
printk(
"Discarding SAVE_POINTERS message\n"));
499 spin_unlock_irqrestore(dev->
host_lock, flags);
503 curSC->SCp.phase =
idle;
504 curSC->scsi_done(curSC);
509 SYM53C500_release(
struct pcmcia_device *
link)
514 dev_dbg(&link->dev,
"SYM53C500_release\n");
538 static char info_msg[256];
544 "SYM53C500 at 0x%lx, IRQ %d, %s PIO mode.",
553 int port_base = SCpnt->
device->host->io_port;
559 DEB(
printk(
"cmd=%02x, cmd_len=%02x, target=%02x, lun=%02x, bufflen=%d\n",
561 SCpnt->
device->lun, scsi_bufflen(SCpnt)));
578 for (i = 0; i < SCpnt->
cmd_len; i++) {
591 int port_base = SCpnt->device->host->io_port;
593 DEB(
printk(
"SYM53C500_host_reset called\n"));
594 spin_lock_irq(SCpnt->device->host->host_lock);
595 SYM53C500_int_host_reset(port_base);
596 spin_unlock_irq(SCpnt->device->host->host_lock);
608 DEB(
printk(
"SYM53C500_biosparm called\n"));
613 info_array[2] = size >> 11;
614 if (info_array[2] > 1024) {
617 info_array[2] = size / (255 * 63);
635 const char *buf,
size_t count)
643 if (pio == 0 || pio == 1) {
660 .
show = SYM53C500_show_pio,
661 .
store = SYM53C500_store_pio,
675 .info = SYM53C500_info,
676 .queuecommand = SYM53C500_queue,
677 .eh_host_reset_handler = SYM53C500_host_reset,
678 .bios_param = SYM53C500_biosparm,
679 .proc_name =
"SYM53C500",
685 .shost_attrs = SYM53C500_shost_attrs
688 static int SYM53C500_config_check(
struct pcmcia_device *p_dev,
void *priv_data)
690 p_dev->io_lines = 10;
691 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
692 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
694 if (p_dev->resource[0]->start == 0)
701 SYM53C500_config(
struct pcmcia_device *link)
705 int irq_level, port_base;
710 dev_dbg(&link->dev,
"SYM53C500_config\n");
714 ret = pcmcia_loop_config(link, SYM53C500_config_check,
NULL);
734 outb(0xb4, link->resource[0]->start + 0xd);
735 outb(0x24, link->resource[0]->start + 0x9);
736 outb(0x04, link->resource[0]->start + 0xd);
749 port_base = link->resource[0]->start;
750 irq_level = link->irq;
752 DEB(
printk(
"SYM53C500: port_base=0x%x, irq=%d, fast_pio=%d\n",
755 chip_init(port_base);
759 printk(
"SYM53C500: Unable to register host, giving up.\n");
767 printk(
"SYM53C500: unable to allocate IRQ %d\n", irq_level);
770 DEB(
printk(
"SYM53C500: allocated IRQ %d\n", irq_level));
771 }
else if (irq_level == 0) {
772 DEB(
printk(
"SYM53C500: No interrupts detected\n"));
775 DEB(
printk(
"SYM53C500: Shouldn't get here!\n"));
780 host->
irq = irq_level;
793 if (scsi_add_host(host,
NULL))
810 SYM53C500_release(link);
814 static int sym53c500_resume(
struct pcmcia_device *link)
822 outb(0x80, link->resource[0]->start + 0xd);
823 outb(0x24, link->resource[0]->start + 0x9);
824 outb(0x04, link->resource[0]->start + 0xd);
830 SYM53C500_int_host_reset(link->resource[0]->start);
836 SYM53C500_detach(
struct pcmcia_device *link)
838 dev_dbg(&link->dev,
"SYM53C500_detach\n");
840 SYM53C500_release(link);
847 SYM53C500_probe(
struct pcmcia_device *link)
851 dev_dbg(&link->dev,
"SYM53C500_attach()\n");
859 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
861 return SYM53C500_config(link);
869 PCMCIA_DEVICE_PROD_ID12(
"BASICS by New Media Corporation",
"SCSI Sym53C500", 0x23c78a9d, 0x0099e7f7),
870 PCMCIA_DEVICE_PROD_ID12(
"New Media Corporation",
"SCSI Bus Toaster Sym53C500", 0x085a850b, 0x45432eb8),
871 PCMCIA_DEVICE_PROD_ID2(
"SCSI9000", 0x21648f44),
876 static struct pcmcia_driver sym53c500_cs_driver = {
878 .name =
"sym53c500_cs",
879 .probe = SYM53C500_probe,
880 .remove = SYM53C500_detach,
881 .id_table = sym53c500_ids,
882 .resume = sym53c500_resume,
886 init_sym53c500_cs(
void)
892 exit_sym53c500_cs(
void)