68 #include <linux/module.h>
72 #define NDEBUG_ABORT 0x00100000
73 #define NDEBUG_TAGS 0x00200000
74 #define NDEBUG_MERGING 0x00400000
83 #include <linux/types.h>
84 #include <linux/stddef.h>
85 #include <linux/ctype.h>
91 #include <linux/nvram.h>
92 #include <linux/bitops.h>
94 #include <asm/setup.h>
98 #include <asm/pgtable.h>
100 #include <asm/traps.h>
110 #include <linux/stat.h>
112 #define IS_A_TT() ATARIHW_PRESENT(TT_SCSI)
114 #define SCSI_DMA_WRITE_P(elt,val) \
116 unsigned long v = val; \
117 tt_scsi_dma.elt##_lo = v & 0xff; \
119 tt_scsi_dma.elt##_lmd = v & 0xff; \
121 tt_scsi_dma.elt##_hmd = v & 0xff; \
123 tt_scsi_dma.elt##_hi = v & 0xff; \
126 #define SCSI_DMA_READ_P(elt) \
127 (((((((unsigned long)tt_scsi_dma.elt##_hi << 8) | \
128 (unsigned long)tt_scsi_dma.elt##_hmd) << 8) | \
129 (unsigned long)tt_scsi_dma.elt##_lmd) << 8) | \
130 (unsigned long)tt_scsi_dma.elt##_lo)
133 static inline void SCSI_DMA_SETADR(
unsigned long adr)
145 static inline unsigned long SCSI_DMA_GETADR(
void)
150 adr |= (
st_dma.dma_md & 0xff) << 8;
152 adr |= (
st_dma.dma_hi & 0xff) << 16;
165 static inline void DISABLE_IRQ(
void)
174 #define HOSTDATA_DMALEN (((struct NCR5380_hostdata *) \
175 (atari_scsi_host->hostdata))->dma_len)
180 #ifndef CONFIG_ATARI_SCSI_TOSHIBA_DELAY
181 #define AFTER_RESET_DELAY (HZ/2)
183 #define AFTER_RESET_DELAY (5*HZ/2)
189 static int scsi_dma_is_ignored_buserr(
unsigned char dma_stat);
190 static void atari_scsi_fetch_restbytes(
void);
191 static long atari_scsi_dma_residual(
struct Scsi_Host *instance);
193 static unsigned long atari_dma_xfer_len(
unsigned long wanted_len,
199 static void falcon_get_lock(
void);
200 #ifdef CONFIG_ATARI_SCSI_RESET_BOOT
201 static void atari_scsi_reset_boot(
void);
203 static unsigned char atari_scsi_tt_reg_read(
unsigned char reg);
204 static void atari_scsi_tt_reg_write(
unsigned char reg,
unsigned char value);
205 static unsigned char atari_scsi_falcon_reg_read(
unsigned char reg);
206 static void atari_scsi_falcon_reg_write(
unsigned char reg,
unsigned char value);
211 static struct Scsi_Host *atari_scsi_host;
212 static unsigned char (*atari_scsi_reg_read)(
unsigned char reg);
213 static void (*atari_scsi_reg_write)(
unsigned char reg,
unsigned char value);
216 static unsigned long atari_dma_residual, atari_dma_startaddr;
217 static short atari_dma_active;
219 static char *atari_dma_buffer;
221 static unsigned long atari_dma_phys_buffer;
223 static char *atari_dma_orig_addr;
230 #define STRAM_BUFFER_SIZE (4096)
232 static unsigned long atari_dma_stram_mask;
233 #define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0)
235 static int atari_read_overruns;
238 static int setup_can_queue = -1;
240 static int setup_cmd_per_lun = -1;
242 static int setup_sg_tablesize = -1;
245 static int setup_use_tagged_queuing = -1;
248 static int setup_hostid = -1;
252 #if defined(REAL_DMA)
254 static int scsi_dma_is_ignored_buserr(
unsigned char dma_stat)
259 if (dma_stat & 0x01) {
268 if (end_addr <= addr && addr <= end_addr + 4)
281 static void scsi_dma_buserr(
int irq,
void *
dummy)
290 printk(
"Bad SCSI DMA interrupt! dma_addr=0x%08lx dma_stat=%02x dma_cnt=%08lx\n",
292 if (dma_stat & 0x80) {
293 if (!scsi_dma_is_ignored_buserr(dma_stat))
294 printk(
"SCSI DMA bus error -- bad DMA programming!\n");
301 printk(
"SCSI DMA intr ?? -- this shouldn't happen!\n");
309 static irqreturn_t scsi_tt_intr(
int irq,
void *dummy)
316 INT_PRINTK(
"scsi%d: NCR5380 interrupt, DMA status = %02x\n",
317 atari_scsi_host->
host_no, dma_stat & 0xff);
322 if (dma_stat & 0x80) {
323 if (!scsi_dma_is_ignored_buserr(dma_stat)) {
339 if ((dma_stat & 0x02) && !(dma_stat & 0x40)) {
342 DMA_PRINTK(
"SCSI DMA: There are %ld residual bytes.\n",
345 if ((
signed int)atari_dma_residual < 0)
346 atari_dma_residual = 0;
347 if ((dma_stat & 1) == 0) {
352 atari_scsi_fetch_restbytes();
372 if (atari_dma_residual & 0x1ff) {
374 "difference %ld bytes\n",
375 512 - (atari_dma_residual & 0x1ff));
376 atari_dma_residual = (atari_dma_residual + 511) & ~0x1ff;
383 if (dma_stat & 0x40) {
384 atari_dma_residual = 0;
385 if ((dma_stat & 1) == 0)
386 atari_scsi_fetch_restbytes();
402 static irqreturn_t scsi_falcon_intr(
int irq,
void *dummy)
410 st_dma.dma_mode_status = 0x90;
411 dma_stat =
st_dma.dma_mode_status;
416 if (!(dma_stat & 0x01)) {
426 if (atari_dma_active && (dma_stat & 0x02)) {
427 unsigned long transferred;
429 transferred = SCSI_DMA_GETADR() - atari_dma_startaddr;
435 if (transferred & 15)
437 "ST-DMA fifo\n", transferred & 15);
440 DMA_PRINTK(
"SCSI DMA: There are %ld residual bytes.\n",
443 atari_dma_residual = 0;
444 atari_dma_active = 0;
446 if (atari_dma_orig_addr) {
452 atari_dma_orig_addr =
NULL;
463 static void atari_scsi_fetch_restbytes(
void)
467 unsigned long phys_dst;
476 DMA_PRINTK(
"SCSI DMA: there are %d rest bytes for phys addr 0x%08lx",
481 for (src = (
char *)&
tt_scsi_dma.dma_restdata; nr != 0; --nr)
488 static int falcon_got_lock = 0;
490 static int falcon_trying_lock = 0;
492 static int falcon_dont_release = 0;
513 if (falcon_dont_release) {
515 printk(
"WARNING: Lock release not allowed. Ignored\n");
522 wake_up(&falcon_fairness_wait);
543 static void falcon_get_lock(
void)
555 while (!falcon_got_lock) {
557 panic(
"Falcon SCSI hasn't ST-DMA lock in interrupt");
558 if (!falcon_trying_lock) {
559 falcon_trying_lock = 1;
562 falcon_trying_lock = 0;
570 if (!falcon_got_lock)
571 panic(
"Falcon SCSI: someone stole the lock :-(\n");
577 static int called = 0;
587 atari_scsi_reg_read =
IS_A_TT() ? atari_scsi_tt_reg_read :
588 atari_scsi_falcon_reg_read;
589 atari_scsi_reg_write =
IS_A_TT() ? atari_scsi_tt_reg_write :
590 atari_scsi_falcon_reg_write;
594 (setup_can_queue > 0) ? setup_can_queue :
597 (setup_cmd_per_lun > 0) ? setup_cmd_per_lun :
604 if (setup_hostid >= 0)
619 if (setup_use_tagged_queuing < 0)
631 if (!atari_dma_buffer) {
637 atari_dma_orig_addr = 0;
641 if (instance ==
NULL) {
643 atari_dma_buffer = 0;
646 atari_scsi_host = instance;
655 #ifdef CONFIG_ATARI_SCSI_RESET_BOOT
656 atari_scsi_reset_boot();
658 NCR5380_init(instance, 0);
666 "SCSI NCR5380", instance)) {
670 atari_dma_buffer = 0;
673 tt_mfp.active_edge |= 0x80;
676 atari_dma_residual = 0;
691 atari_read_overruns = 4;
701 atari_dma_residual = 0;
702 atari_dma_active = 0;
708 printk(
KERN_INFO "scsi%d: options CAN_QUEUE=%d CMD_PER_LUN=%d SCAT-GAT=%d "
714 instance->
hostt->cmd_per_lun,
715 instance->
hostt->sg_tablesize,
717 setup_use_tagged_queuing ?
"yes" :
"no",
719 instance->
hostt->this_id );
720 NCR5380_print_options(instance);
727 static int atari_scsi_release(
struct Scsi_Host *sh)
731 if (atari_dma_buffer)
738 static int __init atari_scsi_setup(
char *
str)
750 printk(
"atari_scsi_setup: no arguments!\n");
757 setup_can_queue = ints[1];
761 setup_cmd_per_lun = ints[2];
765 setup_sg_tablesize = ints[3];
767 if (setup_sg_tablesize >
SG_ALL)
768 setup_sg_tablesize =
SG_ALL;
773 if (ints[4] >= 0 && ints[4] <= 7)
774 setup_hostid = ints[4];
775 else if (ints[4] > 7)
776 printk(
"atari_scsi_setup: invalid host ID %d !\n", ints[4]);
781 setup_use_tagged_queuing = !!ints[5];
788 __setup(
"atascsi=", atari_scsi_setup);
810 st_dma.dma_mode_status = 0x90;
811 atari_dma_active = 0;
812 atari_dma_orig_addr =
NULL;
825 falcon_release_lock_if_possible(hostdata);
831 #ifdef CONFIG_ATARI_SCSI_RESET_BOOT
832 static void __init atari_scsi_reset_boot(
void)
841 printk(
"Atari SCSI: resetting the SCSI bus...");
864 static const char *atari_scsi_info(
struct Scsi_Host *host)
867 static const char string[] =
"Atari native SCSI";
872 #if defined(REAL_DMA)
874 static unsigned long atari_scsi_dma_setup(
struct Scsi_Host *instance,
880 DMA_PRINTK(
"scsi%d: setting up dma, data = %p, phys = %lx, count = %ld, "
881 "dir = %d\n", instance->
host_no, data, addr, count, dir);
890 memcpy(atari_dma_buffer, data, count);
892 atari_dma_orig_addr =
data;
893 addr = atari_dma_phys_buffer;
896 atari_dma_startaddr =
addr;
907 dma_cache_maintenance(addr, count, dir);
920 SCSI_DMA_SETADR(addr);
924 st_dma.dma_mode_status = 0x90 | dir;
925 st_dma.dma_mode_status = 0x90 | (dir ^ 0x100);
926 st_dma.dma_mode_status = 0x90 | dir;
930 st_dma.fdc_acces_seccount = (count + (dir ? 511 : 0)) >> 9;
932 st_dma.dma_mode_status = 0x10 | dir;
935 atari_dma_active = 1;
942 static long atari_scsi_dma_residual(
struct Scsi_Host *instance)
944 return atari_dma_residual;
948 #define CMD_SURELY_BLOCK_MODE 0
949 #define CMD_SURELY_BYTE_MODE 1
950 #define CMD_MODE_UNKNOWN 2
952 static int falcon_classify_cmd(
Scsi_Cmnd *cmd)
983 static unsigned long atari_dma_xfer_len(
unsigned long wanted_len,
986 unsigned long possible_len,
limit;
1025 possible_len = wanted_len;
1031 if (wanted_len & 0x1ff)
1036 switch (falcon_classify_cmd(cmd)) {
1038 possible_len = wanted_len;
1047 possible_len = (wanted_len < 1024) ? 0 : wanted_len;
1056 if (possible_len > limit)
1057 possible_len =
limit;
1059 if (possible_len != wanted_len)
1060 DMA_PRINTK(
"Sorry, must cut DMA transfer size to %ld bytes "
1061 "instead of %ld\n", possible_len, wanted_len);
1063 return possible_len;
1077 static unsigned char atari_scsi_tt_reg_read(
unsigned char reg)
1082 static void atari_scsi_tt_reg_write(
unsigned char reg,
unsigned char value)
1087 static unsigned char atari_scsi_falcon_reg_read(
unsigned char reg)
1093 static void atari_scsi_falcon_reg_write(
unsigned char reg,
unsigned char value)
1103 .proc_info = atari_scsi_proc_info,
1104 .name =
"Atari native SCSI",
1105 .detect = atari_scsi_detect,
1106 .release = atari_scsi_release,
1107 .info = atari_scsi_info,
1108 .queuecommand = atari_scsi_queue_command,
1109 .eh_abort_handler = atari_scsi_abort,
1110 .eh_bus_reset_handler = atari_scsi_bus_reset,