Commit c28bda25 authored by Roman Zippel's avatar Roman Zippel Committed by Linus Torvalds

m68k: Reformat the Atari SCSI driver

Reformat the Atari SCSI driver
Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent fb810d12
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -186,38 +186,37 @@ static inline void DISABLE_IRQ(void) ...@@ -186,38 +186,37 @@ static inline void DISABLE_IRQ(void)
/***************************** Prototypes *****************************/ /***************************** Prototypes *****************************/
#ifdef REAL_DMA #ifdef REAL_DMA
static int scsi_dma_is_ignored_buserr( unsigned char dma_stat ); static int scsi_dma_is_ignored_buserr(unsigned char dma_stat);
static void atari_scsi_fetch_restbytes( void ); static void atari_scsi_fetch_restbytes(void);
static long atari_scsi_dma_residual( struct Scsi_Host *instance ); static long atari_scsi_dma_residual(struct Scsi_Host *instance);
static int falcon_classify_cmd( Scsi_Cmnd *cmd ); static int falcon_classify_cmd(Scsi_Cmnd *cmd);
static unsigned long atari_dma_xfer_len( unsigned long wanted_len, static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
Scsi_Cmnd *cmd, int write_flag ); Scsi_Cmnd *cmd, int write_flag);
#endif #endif
static irqreturn_t scsi_tt_intr( int irq, void *dummy); static irqreturn_t scsi_tt_intr(int irq, void *dummy);
static irqreturn_t scsi_falcon_intr( int irq, void *dummy); static irqreturn_t scsi_falcon_intr(int irq, void *dummy);
static void falcon_release_lock_if_possible( struct NCR5380_hostdata * static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata);
hostdata ); static void falcon_get_lock(void);
static void falcon_get_lock( void );
#ifdef CONFIG_ATARI_SCSI_RESET_BOOT #ifdef CONFIG_ATARI_SCSI_RESET_BOOT
static void atari_scsi_reset_boot( void ); static void atari_scsi_reset_boot(void);
#endif #endif
static unsigned char atari_scsi_tt_reg_read( unsigned char reg ); static unsigned char atari_scsi_tt_reg_read(unsigned char reg);
static void atari_scsi_tt_reg_write( unsigned char reg, unsigned char value); static void atari_scsi_tt_reg_write(unsigned char reg, unsigned char value);
static unsigned char atari_scsi_falcon_reg_read( unsigned char reg ); static unsigned char atari_scsi_falcon_reg_read(unsigned char reg);
static void atari_scsi_falcon_reg_write( unsigned char reg, unsigned char value ); static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value);
/************************* End of Prototypes **************************/ /************************* End of Prototypes **************************/
static struct Scsi_Host *atari_scsi_host = NULL; static struct Scsi_Host *atari_scsi_host;
static unsigned char (*atari_scsi_reg_read)( unsigned char reg ); static unsigned char (*atari_scsi_reg_read)(unsigned char reg);
static void (*atari_scsi_reg_write)( unsigned char reg, unsigned char value ); static void (*atari_scsi_reg_write)(unsigned char reg, unsigned char value);
#ifdef REAL_DMA #ifdef REAL_DMA
static unsigned long atari_dma_residual, atari_dma_startaddr; static unsigned long atari_dma_residual, atari_dma_startaddr;
static short atari_dma_active; static short atari_dma_active;
/* pointer to the dribble buffer */ /* pointer to the dribble buffer */
static char *atari_dma_buffer = NULL; static char *atari_dma_buffer;
/* precalculated physical address of the dribble buffer */ /* precalculated physical address of the dribble buffer */
static unsigned long atari_dma_phys_buffer; static unsigned long atari_dma_phys_buffer;
/* != 0 tells the Falcon int handler to copy data from the dribble buffer */ /* != 0 tells the Falcon int handler to copy data from the dribble buffer */
...@@ -233,7 +232,7 @@ static char *atari_dma_orig_addr; ...@@ -233,7 +232,7 @@ static char *atari_dma_orig_addr;
static unsigned long atari_dma_stram_mask; static unsigned long atari_dma_stram_mask;
#define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0) #define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0)
/* number of bytes to cut from a transfer to handle NCR overruns */ /* number of bytes to cut from a transfer to handle NCR overruns */
static int atari_read_overruns = 0; static int atari_read_overruns;
#endif #endif
static int setup_can_queue = -1; static int setup_can_queue = -1;
...@@ -256,10 +255,10 @@ module_param(setup_hostid, int, 0); ...@@ -256,10 +255,10 @@ module_param(setup_hostid, int, 0);
#if defined(REAL_DMA) #if defined(REAL_DMA)
static int scsi_dma_is_ignored_buserr( unsigned char dma_stat ) static int scsi_dma_is_ignored_buserr(unsigned char dma_stat)
{ {
int i; int i;
unsigned long addr = SCSI_DMA_READ_P( dma_addr ), end_addr; unsigned long addr = SCSI_DMA_READ_P(dma_addr), end_addr;
if (dma_stat & 0x01) { if (dma_stat & 0x01) {
...@@ -267,15 +266,14 @@ static int scsi_dma_is_ignored_buserr( unsigned char dma_stat ) ...@@ -267,15 +266,14 @@ static int scsi_dma_is_ignored_buserr( unsigned char dma_stat )
* physical memory chunk (DMA prefetch!), but that doesn't hurt. * physical memory chunk (DMA prefetch!), but that doesn't hurt.
* Check for this case: * Check for this case:
*/ */
for( i = 0; i < m68k_num_memory; ++i ) { for (i = 0; i < m68k_num_memory; ++i) {
end_addr = m68k_memory[i].addr + end_addr = m68k_memory[i].addr + m68k_memory[i].size;
m68k_memory[i].size;
if (end_addr <= addr && addr <= end_addr + 4) if (end_addr <= addr && addr <= end_addr + 4)
return( 1 ); return 1;
} }
} }
return( 0 ); return 0;
} }
...@@ -284,28 +282,27 @@ static int scsi_dma_is_ignored_buserr( unsigned char dma_stat ) ...@@ -284,28 +282,27 @@ static int scsi_dma_is_ignored_buserr( unsigned char dma_stat )
* end-of-DMA, both SCSI ints are triggered simultaneously, so the NCR int has * end-of-DMA, both SCSI ints are triggered simultaneously, so the NCR int has
* to clear the DMA int pending bit before it allows other level 6 interrupts. * to clear the DMA int pending bit before it allows other level 6 interrupts.
*/ */
static void scsi_dma_buserr (int irq, void *dummy) static void scsi_dma_buserr(int irq, void *dummy)
{ {
unsigned char dma_stat = tt_scsi_dma.dma_ctrl; unsigned char dma_stat = tt_scsi_dma.dma_ctrl;
/* Don't do anything if a NCR interrupt is pending. Probably it's just /* Don't do anything if a NCR interrupt is pending. Probably it's just
* masked... */ * masked... */
if (atari_irq_pending( IRQ_TT_MFP_SCSI )) if (atari_irq_pending(IRQ_TT_MFP_SCSI))
return; return;
printk("Bad SCSI DMA interrupt! dma_addr=0x%08lx dma_stat=%02x dma_cnt=%08lx\n", printk("Bad SCSI DMA interrupt! dma_addr=0x%08lx dma_stat=%02x dma_cnt=%08lx\n",
SCSI_DMA_READ_P(dma_addr), dma_stat, SCSI_DMA_READ_P(dma_cnt)); SCSI_DMA_READ_P(dma_addr), dma_stat, SCSI_DMA_READ_P(dma_cnt));
if (dma_stat & 0x80) { if (dma_stat & 0x80) {
if (!scsi_dma_is_ignored_buserr( dma_stat )) if (!scsi_dma_is_ignored_buserr(dma_stat))
printk( "SCSI DMA bus error -- bad DMA programming!\n" ); printk("SCSI DMA bus error -- bad DMA programming!\n");
} } else {
else {
/* Under normal circumstances we never should get to this point, /* Under normal circumstances we never should get to this point,
* since both interrupts are triggered simultaneously and the 5380 * since both interrupts are triggered simultaneously and the 5380
* int has higher priority. When this irq is handled, that DMA * int has higher priority. When this irq is handled, that DMA
* interrupt is cleared. So a warning message is printed here. * interrupt is cleared. So a warning message is printed here.
*/ */
printk( "SCSI DMA intr ?? -- this shouldn't happen!\n" ); printk("SCSI DMA intr ?? -- this shouldn't happen!\n");
} }
} }
#endif #endif
...@@ -313,7 +310,7 @@ static void scsi_dma_buserr (int irq, void *dummy) ...@@ -313,7 +310,7 @@ static void scsi_dma_buserr (int irq, void *dummy)
#endif #endif
static irqreturn_t scsi_tt_intr (int irq, void *dummy) static irqreturn_t scsi_tt_intr(int irq, void *dummy)
{ {
#ifdef REAL_DMA #ifdef REAL_DMA
int dma_stat; int dma_stat;
...@@ -327,7 +324,7 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy) ...@@ -327,7 +324,7 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
* is that a bus error occurred... * is that a bus error occurred...
*/ */
if (dma_stat & 0x80) { if (dma_stat & 0x80) {
if (!scsi_dma_is_ignored_buserr( dma_stat )) { if (!scsi_dma_is_ignored_buserr(dma_stat)) {
printk(KERN_ERR "SCSI DMA caused bus error near 0x%08lx\n", printk(KERN_ERR "SCSI DMA caused bus error near 0x%08lx\n",
SCSI_DMA_READ_P(dma_addr)); SCSI_DMA_READ_P(dma_addr));
printk(KERN_CRIT "SCSI DMA bus error -- bad DMA programming!"); printk(KERN_CRIT "SCSI DMA bus error -- bad DMA programming!");
...@@ -344,8 +341,7 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy) ...@@ -344,8 +341,7 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
* data reg! * data reg!
*/ */
if ((dma_stat & 0x02) && !(dma_stat & 0x40)) { if ((dma_stat & 0x02) && !(dma_stat & 0x40)) {
atari_dma_residual = HOSTDATA_DMALEN - (SCSI_DMA_READ_P( dma_addr ) - atari_dma_residual = HOSTDATA_DMALEN - (SCSI_DMA_READ_P(dma_addr) - atari_dma_startaddr);
atari_dma_startaddr);
DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n", DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n",
atari_dma_residual); atari_dma_residual);
...@@ -353,28 +349,30 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy) ...@@ -353,28 +349,30 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
if ((signed int)atari_dma_residual < 0) if ((signed int)atari_dma_residual < 0)
atari_dma_residual = 0; atari_dma_residual = 0;
if ((dma_stat & 1) == 0) { if ((dma_stat & 1) == 0) {
/* After read operations, we maybe have to /*
transport some rest bytes */ * After read operations, we maybe have to
* transport some rest bytes
*/
atari_scsi_fetch_restbytes(); atari_scsi_fetch_restbytes();
} } else {
else { /*
/* There seems to be a nasty bug in some SCSI-DMA/NCR * There seems to be a nasty bug in some SCSI-DMA/NCR
combinations: If a target disconnects while a write * combinations: If a target disconnects while a write
operation is going on, the address register of the * operation is going on, the address register of the
DMA may be a few bytes farer than it actually read. * DMA may be a few bytes farer than it actually read.
This is probably due to DMA prefetching and a delay * This is probably due to DMA prefetching and a delay
between DMA and NCR. Experiments showed that the * between DMA and NCR. Experiments showed that the
dma_addr is 9 bytes to high, but this could vary. * dma_addr is 9 bytes to high, but this could vary.
The problem is, that the residual is thus calculated * The problem is, that the residual is thus calculated
wrong and the next transfer will start behind where * wrong and the next transfer will start behind where
it should. So we round up the residual to the next * it should. So we round up the residual to the next
multiple of a sector size, if it isn't already a * multiple of a sector size, if it isn't already a
multiple and the originally expected transfer size * multiple and the originally expected transfer size
was. The latter condition is there to ensure that * was. The latter condition is there to ensure that
the correction is taken only for "real" data * the correction is taken only for "real" data
transfers and not for, e.g., the parameters of some * transfers and not for, e.g., the parameters of some
other command. These shouldn't disconnect anyway. * other command. These shouldn't disconnect anyway.
*/ */
if (atari_dma_residual & 0x1ff) { if (atari_dma_residual & 0x1ff) {
DMA_PRINTK("SCSI DMA: DMA bug corrected, " DMA_PRINTK("SCSI DMA: DMA bug corrected, "
"difference %ld bytes\n", "difference %ld bytes\n",
...@@ -394,18 +392,18 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy) ...@@ -394,18 +392,18 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
} }
#endif /* REAL_DMA */ #endif /* REAL_DMA */
NCR5380_intr(0, 0); NCR5380_intr(0, 0);
#if 0 #if 0
/* To be sure the int is not masked */ /* To be sure the int is not masked */
atari_enable_irq( IRQ_TT_MFP_SCSI ); atari_enable_irq(IRQ_TT_MFP_SCSI);
#endif #endif
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static irqreturn_t scsi_falcon_intr (int irq, void *dummy) static irqreturn_t scsi_falcon_intr(int irq, void *dummy)
{ {
#ifdef REAL_DMA #ifdef REAL_DMA
int dma_stat; int dma_stat;
...@@ -430,7 +428,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy) ...@@ -430,7 +428,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy)
* bytes are stuck in the ST-DMA fifo (there's no way to reach them!) * bytes are stuck in the ST-DMA fifo (there's no way to reach them!)
*/ */
if (atari_dma_active && (dma_stat & 0x02)) { if (atari_dma_active && (dma_stat & 0x02)) {
unsigned long transferred; unsigned long transferred;
transferred = SCSI_DMA_GETADR() - atari_dma_startaddr; transferred = SCSI_DMA_GETADR() - atari_dma_startaddr;
/* The ST-DMA address is incremented in 2-byte steps, but the /* The ST-DMA address is incremented in 2-byte steps, but the
...@@ -445,8 +443,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy) ...@@ -445,8 +443,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy)
atari_dma_residual = HOSTDATA_DMALEN - transferred; atari_dma_residual = HOSTDATA_DMALEN - transferred;
DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n", DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n",
atari_dma_residual); atari_dma_residual);
} } else
else
atari_dma_residual = 0; atari_dma_residual = 0;
atari_dma_active = 0; atari_dma_active = 0;
...@@ -467,7 +464,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy) ...@@ -467,7 +464,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy)
#ifdef REAL_DMA #ifdef REAL_DMA
static void atari_scsi_fetch_restbytes( void ) static void atari_scsi_fetch_restbytes(void)
{ {
int nr; int nr;
char *src, *dst; char *src, *dst;
...@@ -505,19 +502,17 @@ static int falcon_dont_release = 0; ...@@ -505,19 +502,17 @@ static int falcon_dont_release = 0;
* again (but others waiting longer more probably will win). * again (but others waiting longer more probably will win).
*/ */
static void static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata)
falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
{ {
unsigned long flags; unsigned long flags;
if (IS_A_TT()) return; if (IS_A_TT())
return;
local_irq_save(flags); local_irq_save(flags);
if (falcon_got_lock && if (falcon_got_lock && !hostdata->disconnected_queue &&
!hostdata->disconnected_queue && !hostdata->issue_queue && !hostdata->connected) {
!hostdata->issue_queue &&
!hostdata->connected) {
if (falcon_dont_release) { if (falcon_dont_release) {
#if 0 #if 0
...@@ -528,7 +523,7 @@ falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata ) ...@@ -528,7 +523,7 @@ falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
} }
falcon_got_lock = 0; falcon_got_lock = 0;
stdma_release(); stdma_release();
wake_up( &falcon_fairness_wait ); wake_up(&falcon_fairness_wait);
} }
local_irq_restore(flags); local_irq_restore(flags);
...@@ -549,31 +544,31 @@ falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata ) ...@@ -549,31 +544,31 @@ falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
* Complicated, complicated.... Sigh... * Complicated, complicated.... Sigh...
*/ */
static void falcon_get_lock( void ) static void falcon_get_lock(void)
{ {
unsigned long flags; unsigned long flags;
if (IS_A_TT()) return; if (IS_A_TT())
return;
local_irq_save(flags); local_irq_save(flags);
while (!in_irq() && falcon_got_lock && stdma_others_waiting()) while (!in_irq() && falcon_got_lock && stdma_others_waiting())
sleep_on( &falcon_fairness_wait ); sleep_on(&falcon_fairness_wait);
while (!falcon_got_lock) { while (!falcon_got_lock) {
if (in_irq()) if (in_irq())
panic( "Falcon SCSI hasn't ST-DMA lock in interrupt" ); panic("Falcon SCSI hasn't ST-DMA lock in interrupt");
if (!falcon_trying_lock) { if (!falcon_trying_lock) {
falcon_trying_lock = 1; falcon_trying_lock = 1;
stdma_lock(scsi_falcon_intr, NULL); stdma_lock(scsi_falcon_intr, NULL);
falcon_got_lock = 1; falcon_got_lock = 1;
falcon_trying_lock = 0; falcon_trying_lock = 0;
wake_up( &falcon_try_wait ); wake_up(&falcon_try_wait);
} } else {
else { sleep_on(&falcon_try_wait);
sleep_on( &falcon_try_wait );
} }
} }
local_irq_restore(flags); local_irq_restore(flags);
if (!falcon_got_lock) if (!falcon_got_lock)
...@@ -587,18 +582,18 @@ static void falcon_get_lock( void ) ...@@ -587,18 +582,18 @@ static void falcon_get_lock( void )
*/ */
#if 0 #if 0
int atari_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *)) int atari_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
{ {
/* falcon_get_lock(); /* falcon_get_lock();
* ++guenther: moved to NCR5380_queue_command() to prevent * ++guenther: moved to NCR5380_queue_command() to prevent
* race condition, see there for an explanation. * race condition, see there for an explanation.
*/ */
return( NCR5380_queue_command( cmd, done ) ); return NCR5380_queue_command(cmd, done);
} }
#endif #endif
int atari_scsi_detect (struct scsi_host_template *host) int atari_scsi_detect(struct scsi_host_template *host)
{ {
static int called = 0; static int called = 0;
struct Scsi_Host *instance; struct Scsi_Host *instance;
...@@ -606,7 +601,7 @@ int atari_scsi_detect (struct scsi_host_template *host) ...@@ -606,7 +601,7 @@ int atari_scsi_detect (struct scsi_host_template *host)
if (!MACH_IS_ATARI || if (!MACH_IS_ATARI ||
(!ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(TT_SCSI)) || (!ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(TT_SCSI)) ||
called) called)
return( 0 ); return 0;
host->proc_name = "Atari"; host->proc_name = "Atari";
...@@ -655,32 +650,33 @@ int atari_scsi_detect (struct scsi_host_template *host) ...@@ -655,32 +650,33 @@ int atari_scsi_detect (struct scsi_host_template *host)
!ATARIHW_PRESENT(EXTD_DMA) && m68k_num_memory > 1) { !ATARIHW_PRESENT(EXTD_DMA) && m68k_num_memory > 1) {
atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI"); atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI");
if (!atari_dma_buffer) { if (!atari_dma_buffer) {
printk( KERN_ERR "atari_scsi_detect: can't allocate ST-RAM " printk(KERN_ERR "atari_scsi_detect: can't allocate ST-RAM "
"double buffer\n" ); "double buffer\n");
return( 0 ); return 0;
} }
atari_dma_phys_buffer = virt_to_phys( atari_dma_buffer ); atari_dma_phys_buffer = virt_to_phys(atari_dma_buffer);
atari_dma_orig_addr = 0; atari_dma_orig_addr = 0;
} }
#endif #endif
instance = scsi_register (host, sizeof (struct NCR5380_hostdata)); instance = scsi_register(host, sizeof(struct NCR5380_hostdata));
if(instance == NULL) if (instance == NULL) {
{
atari_stram_free(atari_dma_buffer); atari_stram_free(atari_dma_buffer);
atari_dma_buffer = 0; atari_dma_buffer = 0;
return 0; return 0;
} }
atari_scsi_host = instance; atari_scsi_host = instance;
/* Set irq to 0, to avoid that the mid-level code disables our interrupt /*
* during queue_command calls. This is completely unnecessary, and even * Set irq to 0, to avoid that the mid-level code disables our interrupt
* worse causes bad problems on the Falcon, where the int is shared with * during queue_command calls. This is completely unnecessary, and even
* IDE and floppy! */ * worse causes bad problems on the Falcon, where the int is shared with
* IDE and floppy!
*/
instance->irq = 0; instance->irq = 0;
#ifdef CONFIG_ATARI_SCSI_RESET_BOOT #ifdef CONFIG_ATARI_SCSI_RESET_BOOT
atari_scsi_reset_boot(); atari_scsi_reset_boot();
#endif #endif
NCR5380_init (instance, 0); NCR5380_init(instance, 0);
if (IS_A_TT()) { if (IS_A_TT()) {
...@@ -727,11 +723,10 @@ int atari_scsi_detect (struct scsi_host_template *host) ...@@ -727,11 +723,10 @@ int atari_scsi_detect (struct scsi_host_template *host)
* the rest data bug is fixed, this can be lowered to 1. * the rest data bug is fixed, this can be lowered to 1.
*/ */
atari_read_overruns = 4; atari_read_overruns = 4;
} }
#endif /*REAL_DMA*/ #endif /*REAL_DMA*/
} } else { /* ! IS_A_TT */
else { /* ! IS_A_TT */
/* Nothing to do for the interrupt: the ST-DMA is initialized /* Nothing to do for the interrupt: the ST-DMA is initialized
* already by atari_init_INTS() * already by atari_init_INTS()
*/ */
...@@ -756,19 +751,19 @@ int atari_scsi_detect (struct scsi_host_template *host) ...@@ -756,19 +751,19 @@ int atari_scsi_detect (struct scsi_host_template *host)
setup_use_tagged_queuing ? "yes" : "no", setup_use_tagged_queuing ? "yes" : "no",
#endif #endif
instance->hostt->this_id ); instance->hostt->this_id );
NCR5380_print_options (instance); NCR5380_print_options(instance);
printk ("\n"); printk("\n");
called = 1; called = 1;
return( 1 ); return 1;
} }
int atari_scsi_release (struct Scsi_Host *sh) int atari_scsi_release(struct Scsi_Host *sh)
{ {
if (IS_A_TT()) if (IS_A_TT())
free_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr); free_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr);
if (atari_dma_buffer) if (atari_dma_buffer)
atari_stram_free (atari_dma_buffer); atari_stram_free(atari_dma_buffer);
return 1; return 1;
} }
...@@ -779,9 +774,9 @@ void __init atari_scsi_setup(char *str, int *ints) ...@@ -779,9 +774,9 @@ void __init atari_scsi_setup(char *str, int *ints)
* Defaults depend on TT or Falcon, hostid determined at run time. * Defaults depend on TT or Falcon, hostid determined at run time.
* Negative values mean don't change. * Negative values mean don't change.
*/ */
if (ints[0] < 1) { if (ints[0] < 1) {
printk( "atari_scsi_setup: no arguments!\n" ); printk("atari_scsi_setup: no arguments!\n");
return; return;
} }
...@@ -807,7 +802,7 @@ void __init atari_scsi_setup(char *str, int *ints) ...@@ -807,7 +802,7 @@ void __init atari_scsi_setup(char *str, int *ints)
if (ints[4] >= 0 && ints[4] <= 7) if (ints[4] >= 0 && ints[4] <= 7)
setup_hostid = ints[4]; setup_hostid = ints[4];
else if (ints[4] > 7) else if (ints[4] > 7)
printk( "atari_scsi_setup: invalid host ID %d !\n", ints[4] ); printk("atari_scsi_setup: invalid host ID %d !\n", ints[4]);
} }
#ifdef SUPPORT_TAGS #ifdef SUPPORT_TAGS
if (ints[0] >= 5) { if (ints[0] >= 5) {
...@@ -819,7 +814,7 @@ void __init atari_scsi_setup(char *str, int *ints) ...@@ -819,7 +814,7 @@ void __init atari_scsi_setup(char *str, int *ints)
int atari_scsi_bus_reset(Scsi_Cmnd *cmd) int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
{ {
int rv; int rv;
struct NCR5380_hostdata *hostdata = struct NCR5380_hostdata *hostdata =
(struct NCR5380_hostdata *)cmd->device->host->hostdata; (struct NCR5380_hostdata *)cmd->device->host->hostdata;
...@@ -829,13 +824,12 @@ int atari_scsi_bus_reset(Scsi_Cmnd *cmd) ...@@ -829,13 +824,12 @@ int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
*/ */
/* And abort a maybe active DMA transfer */ /* And abort a maybe active DMA transfer */
if (IS_A_TT()) { if (IS_A_TT()) {
atari_turnoff_irq( IRQ_TT_MFP_SCSI ); atari_turnoff_irq(IRQ_TT_MFP_SCSI);
#ifdef REAL_DMA #ifdef REAL_DMA
tt_scsi_dma.dma_ctrl = 0; tt_scsi_dma.dma_ctrl = 0;
#endif /* REAL_DMA */ #endif /* REAL_DMA */
} } else {
else { atari_turnoff_irq(IRQ_MFP_FSCSI);
atari_turnoff_irq( IRQ_MFP_FSCSI );
#ifdef REAL_DMA #ifdef REAL_DMA
st_dma.dma_mode_status = 0x90; st_dma.dma_mode_status = 0x90;
atari_dma_active = 0; atari_dma_active = 0;
...@@ -847,52 +841,51 @@ int atari_scsi_bus_reset(Scsi_Cmnd *cmd) ...@@ -847,52 +841,51 @@ int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
/* Re-enable ints */ /* Re-enable ints */
if (IS_A_TT()) { if (IS_A_TT()) {
atari_turnon_irq( IRQ_TT_MFP_SCSI ); atari_turnon_irq(IRQ_TT_MFP_SCSI);
} } else {
else { atari_turnon_irq(IRQ_MFP_FSCSI);
atari_turnon_irq( IRQ_MFP_FSCSI );
} }
if ((rv & SCSI_RESET_ACTION) == SCSI_RESET_SUCCESS) if ((rv & SCSI_RESET_ACTION) == SCSI_RESET_SUCCESS)
falcon_release_lock_if_possible(hostdata); falcon_release_lock_if_possible(hostdata);
return( rv ); return rv;
} }
#ifdef CONFIG_ATARI_SCSI_RESET_BOOT #ifdef CONFIG_ATARI_SCSI_RESET_BOOT
static void __init atari_scsi_reset_boot(void) static void __init atari_scsi_reset_boot(void)
{ {
unsigned long end; unsigned long end;
/* /*
* Do a SCSI reset to clean up the bus during initialization. No messing * Do a SCSI reset to clean up the bus during initialization. No messing
* with the queues, interrupts, or locks necessary here. * with the queues, interrupts, or locks necessary here.
*/ */
printk( "Atari SCSI: resetting the SCSI bus..." ); printk("Atari SCSI: resetting the SCSI bus...");
/* get in phase */ /* get in phase */
NCR5380_write( TARGET_COMMAND_REG, NCR5380_write(TARGET_COMMAND_REG,
PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) )); PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG)));
/* assert RST */ /* assert RST */
NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST ); NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST);
/* The min. reset hold time is 25us, so 40us should be enough */ /* The min. reset hold time is 25us, so 40us should be enough */
udelay( 50 ); udelay(50);
/* reset RST and interrupt */ /* reset RST and interrupt */
NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE ); NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_read( RESET_PARITY_INTERRUPT_REG ); NCR5380_read(RESET_PARITY_INTERRUPT_REG);
end = jiffies + AFTER_RESET_DELAY; end = jiffies + AFTER_RESET_DELAY;
while (time_before(jiffies, end)) while (time_before(jiffies, end))
barrier(); barrier();
printk( " done\n" ); printk(" done\n");
} }
#endif #endif
const char * atari_scsi_info (struct Scsi_Host *host) const char *atari_scsi_info(struct Scsi_Host *host)
{ {
/* atari_scsi_detect() is verbose enough... */ /* atari_scsi_detect() is verbose enough... */
static const char string[] = "Atari native SCSI"; static const char string[] = "Atari native SCSI";
...@@ -902,10 +895,10 @@ const char * atari_scsi_info (struct Scsi_Host *host) ...@@ -902,10 +895,10 @@ const char * atari_scsi_info (struct Scsi_Host *host)
#if defined(REAL_DMA) #if defined(REAL_DMA)
unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data, unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance, void *data,
unsigned long count, int dir ) unsigned long count, int dir)
{ {
unsigned long addr = virt_to_phys( data ); unsigned long addr = virt_to_phys(data);
DMA_PRINTK("scsi%d: setting up dma, data = %p, phys = %lx, count = %ld, " DMA_PRINTK("scsi%d: setting up dma, data = %p, phys = %lx, count = %ld, "
"dir = %d\n", instance->host_no, data, addr, count, dir); "dir = %d\n", instance->host_no, data, addr, count, dir);
...@@ -917,38 +910,37 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data, ...@@ -917,38 +910,37 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data,
* wanted address. * wanted address.
*/ */
if (dir) if (dir)
memcpy( atari_dma_buffer, data, count ); memcpy(atari_dma_buffer, data, count);
else else
atari_dma_orig_addr = data; atari_dma_orig_addr = data;
addr = atari_dma_phys_buffer; addr = atari_dma_phys_buffer;
} }
atari_dma_startaddr = addr; /* Needed for calculating residual later. */ atari_dma_startaddr = addr; /* Needed for calculating residual later. */
/* Cache cleanup stuff: On writes, push any dirty cache out before sending /* Cache cleanup stuff: On writes, push any dirty cache out before sending
* it to the peripheral. (Must be done before DMA setup, since at least * it to the peripheral. (Must be done before DMA setup, since at least
* the ST-DMA begins to fill internal buffers right after setup. For * the ST-DMA begins to fill internal buffers right after setup. For
* reads, invalidate any cache, may be altered after DMA without CPU * reads, invalidate any cache, may be altered after DMA without CPU
* knowledge. * knowledge.
* *
* ++roman: For the Medusa, there's no need at all for that cache stuff, * ++roman: For the Medusa, there's no need at all for that cache stuff,
* because the hardware does bus snooping (fine!). * because the hardware does bus snooping (fine!).
*/ */
dma_cache_maintenance( addr, count, dir ); dma_cache_maintenance(addr, count, dir);
if (count == 0) if (count == 0)
printk(KERN_NOTICE "SCSI warning: DMA programmed for 0 bytes !\n"); printk(KERN_NOTICE "SCSI warning: DMA programmed for 0 bytes !\n");
if (IS_A_TT()) { if (IS_A_TT()) {
tt_scsi_dma.dma_ctrl = dir; tt_scsi_dma.dma_ctrl = dir;
SCSI_DMA_WRITE_P( dma_addr, addr ); SCSI_DMA_WRITE_P(dma_addr, addr);
SCSI_DMA_WRITE_P( dma_cnt, count ); SCSI_DMA_WRITE_P(dma_cnt, count);
tt_scsi_dma.dma_ctrl = dir | 2; tt_scsi_dma.dma_ctrl = dir | 2;
} } else { /* ! IS_A_TT */
else { /* ! IS_A_TT */
/* set address */ /* set address */
SCSI_DMA_SETADR( addr ); SCSI_DMA_SETADR(addr);
/* toggle direction bit to clear FIFO and set DMA direction */ /* toggle direction bit to clear FIFO and set DMA direction */
dir <<= 8; dir <<= 8;
...@@ -966,13 +958,13 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data, ...@@ -966,13 +958,13 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data,
atari_dma_active = 1; atari_dma_active = 1;
} }
return( count ); return count;
} }
static long atari_scsi_dma_residual( struct Scsi_Host *instance ) static long atari_scsi_dma_residual(struct Scsi_Host *instance)
{ {
return( atari_dma_residual ); return atari_dma_residual;
} }
...@@ -980,13 +972,13 @@ static long atari_scsi_dma_residual( struct Scsi_Host *instance ) ...@@ -980,13 +972,13 @@ static long atari_scsi_dma_residual( struct Scsi_Host *instance )
#define CMD_SURELY_BYTE_MODE 1 #define CMD_SURELY_BYTE_MODE 1
#define CMD_MODE_UNKNOWN 2 #define CMD_MODE_UNKNOWN 2
static int falcon_classify_cmd( Scsi_Cmnd *cmd ) static int falcon_classify_cmd(Scsi_Cmnd *cmd)
{ {
unsigned char opcode = cmd->cmnd[0]; unsigned char opcode = cmd->cmnd[0];
if (opcode == READ_DEFECT_DATA || opcode == READ_LONG || if (opcode == READ_DEFECT_DATA || opcode == READ_LONG ||
opcode == READ_BUFFER) opcode == READ_BUFFER)
return( CMD_SURELY_BYTE_MODE ); return CMD_SURELY_BYTE_MODE;
else if (opcode == READ_6 || opcode == READ_10 || else if (opcode == READ_6 || opcode == READ_10 ||
opcode == 0xa8 /* READ_12 */ || opcode == READ_REVERSE || opcode == 0xa8 /* READ_12 */ || opcode == READ_REVERSE ||
opcode == RECOVER_BUFFERED_DATA) { opcode == RECOVER_BUFFERED_DATA) {
...@@ -994,12 +986,11 @@ static int falcon_classify_cmd( Scsi_Cmnd *cmd ) ...@@ -994,12 +986,11 @@ static int falcon_classify_cmd( Scsi_Cmnd *cmd )
* needed here: The transfer is block-mode only if the 'fixed' bit is * needed here: The transfer is block-mode only if the 'fixed' bit is
* set! */ * set! */
if (cmd->device->type == TYPE_TAPE && !(cmd->cmnd[1] & 1)) if (cmd->device->type == TYPE_TAPE && !(cmd->cmnd[1] & 1))
return( CMD_SURELY_BYTE_MODE ); return CMD_SURELY_BYTE_MODE;
else else
return( CMD_SURELY_BLOCK_MODE ); return CMD_SURELY_BLOCK_MODE;
} } else
else return CMD_MODE_UNKNOWN;
return( CMD_MODE_UNKNOWN );
} }
...@@ -1012,19 +1003,18 @@ static int falcon_classify_cmd( Scsi_Cmnd *cmd ) ...@@ -1012,19 +1003,18 @@ static int falcon_classify_cmd( Scsi_Cmnd *cmd )
* the overrun problem, so this question is academic :-) * the overrun problem, so this question is academic :-)
*/ */
static unsigned long atari_dma_xfer_len( unsigned long wanted_len, static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
Scsi_Cmnd *cmd, Scsi_Cmnd *cmd, int write_flag)
int write_flag )
{ {
unsigned long possible_len, limit; unsigned long possible_len, limit;
#ifndef CONFIG_TT_DMA_EMUL #ifndef CONFIG_TT_DMA_EMUL
if (MACH_IS_HADES) if (MACH_IS_HADES)
/* Hades has no SCSI DMA at all :-( Always force use of PIO */ /* Hades has no SCSI DMA at all :-( Always force use of PIO */
return( 0 ); return 0;
#endif #endif
if (IS_A_TT()) if (IS_A_TT())
/* TT SCSI DMA can transfer arbitrary #bytes */ /* TT SCSI DMA can transfer arbitrary #bytes */
return( wanted_len ); return wanted_len;
/* ST DMA chip is stupid -- only multiples of 512 bytes! (and max. /* ST DMA chip is stupid -- only multiples of 512 bytes! (and max.
* 255*512 bytes, but this should be enough) * 255*512 bytes, but this should be enough)
...@@ -1060,8 +1050,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len, ...@@ -1060,8 +1050,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
* this). * this).
*/ */
possible_len = wanted_len; possible_len = wanted_len;
} } else {
else {
/* Read operations: if the wanted transfer length is not a multiple of /* Read operations: if the wanted transfer length is not a multiple of
* 512, we cannot use DMA, since the ST-DMA cannot split transfers * 512, we cannot use DMA, since the ST-DMA cannot split transfers
* (no interrupt on DMA finished!) * (no interrupt on DMA finished!)
...@@ -1071,15 +1060,15 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len, ...@@ -1071,15 +1060,15 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
else { else {
/* Now classify the command (see above) and decide whether it is /* Now classify the command (see above) and decide whether it is
* allowed to do DMA at all */ * allowed to do DMA at all */
switch( falcon_classify_cmd( cmd )) { switch (falcon_classify_cmd(cmd)) {
case CMD_SURELY_BLOCK_MODE: case CMD_SURELY_BLOCK_MODE:
possible_len = wanted_len; possible_len = wanted_len;
break; break;
case CMD_SURELY_BYTE_MODE: case CMD_SURELY_BYTE_MODE:
possible_len = 0; /* DMA prohibited */ possible_len = 0; /* DMA prohibited */
break; break;
case CMD_MODE_UNKNOWN: case CMD_MODE_UNKNOWN:
default: default:
/* For unknown commands assume block transfers if the transfer /* For unknown commands assume block transfers if the transfer
* size/allocation length is >= 1024 */ * size/allocation length is >= 1024 */
possible_len = (wanted_len < 1024) ? 0 : wanted_len; possible_len = (wanted_len < 1024) ? 0 : wanted_len;
...@@ -1087,9 +1076,9 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len, ...@@ -1087,9 +1076,9 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
} }
} }
} }
/* Last step: apply the hard limit on DMA transfers */ /* Last step: apply the hard limit on DMA transfers */
limit = (atari_dma_buffer && !STRAM_ADDR( virt_to_phys(cmd->SCp.ptr) )) ? limit = (atari_dma_buffer && !STRAM_ADDR(virt_to_phys(cmd->SCp.ptr))) ?
STRAM_BUFFER_SIZE : 255*512; STRAM_BUFFER_SIZE : 255*512;
if (possible_len > limit) if (possible_len > limit)
possible_len = limit; possible_len = limit;
...@@ -1098,7 +1087,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len, ...@@ -1098,7 +1087,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
DMA_PRINTK("Sorry, must cut DMA transfer size to %ld bytes " DMA_PRINTK("Sorry, must cut DMA transfer size to %ld bytes "
"instead of %ld\n", possible_len, wanted_len); "instead of %ld\n", possible_len, wanted_len);
return( possible_len ); return possible_len;
} }
...@@ -1112,23 +1101,23 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len, ...@@ -1112,23 +1101,23 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
* NCR5380_write call these functions via function pointers. * NCR5380_write call these functions via function pointers.
*/ */
static unsigned char atari_scsi_tt_reg_read( unsigned char reg ) static unsigned char atari_scsi_tt_reg_read(unsigned char reg)
{ {
return( tt_scsi_regp[reg * 2] ); return tt_scsi_regp[reg * 2];
} }
static void atari_scsi_tt_reg_write( unsigned char reg, unsigned char value ) static void atari_scsi_tt_reg_write(unsigned char reg, unsigned char value)
{ {
tt_scsi_regp[reg * 2] = value; tt_scsi_regp[reg * 2] = value;
} }
static unsigned char atari_scsi_falcon_reg_read( unsigned char reg ) static unsigned char atari_scsi_falcon_reg_read(unsigned char reg)
{ {
dma_wd.dma_mode_status= (u_short)(0x88 + reg); dma_wd.dma_mode_status= (u_short)(0x88 + reg);
return( (u_char)dma_wd.fdc_acces_seccount ); return (u_char)dma_wd.fdc_acces_seccount;
} }
static void atari_scsi_falcon_reg_write( unsigned char reg, unsigned char value ) static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value)
{ {
dma_wd.dma_mode_status = (u_short)(0x88 + reg); dma_wd.dma_mode_status = (u_short)(0x88 + reg);
dma_wd.fdc_acces_seccount = (u_short)value; dma_wd.fdc_acces_seccount = (u_short)value;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment