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
......@@ -77,13 +77,21 @@
#include <scsi/scsi_transport_spi.h>
#if (NDEBUG & NDEBUG_LISTS)
#define LIST(x,y) \
{ printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); \
if ((x)==(y)) udelay(5); }
#define REMOVE(w,x,y,z) \
{ printk("LINE:%d Removing: %p->%p %p->%p \n", __LINE__, \
(void*)(w), (void*)(x), (void*)(y), (void*)(z)); \
if ((x)==(y)) udelay(5); }
#define LIST(x, y) \
do { \
printk("LINE:%d Adding %p to %p\n", \
__LINE__, (void*)(x), (void*)(y)); \
if ((x) == (y)) \
udelay(5); \
} while (0)
#define REMOVE(w, x, y, z) \
do { \
printk("LINE:%d Removing: %p->%p %p->%p \n", \
__LINE__, (void*)(w), (void*)(x), \
(void*)(y), (void*)(z)); \
if ((x) == (y)) \
udelay(5); \
} while (0)
#else
#define LIST(x,y)
#define REMOVE(w,x,y,z)
......@@ -320,7 +328,7 @@ typedef struct {
static TAG_ALLOC TagAlloc[8][8]; /* 8 targets and 8 LUNs */
static void __init init_tags( void )
static void __init init_tags(void)
{
int target, lun;
TAG_ALLOC *ta;
......@@ -328,8 +336,8 @@ static void __init init_tags( void )
if (!setup_use_tagged_queuing)
return;
for( target = 0; target < 8; ++target ) {
for( lun = 0; lun < 8; ++lun ) {
for (target = 0; target < 8; ++target) {
for (lun = 0; lun < 8; ++lun) {
ta = &TagAlloc[target][lun];
bitmap_zero(ta->allocated, MAX_TAGS);
ta->nr_allocated = 0;
......@@ -350,22 +358,22 @@ static void __init init_tags( void )
* conditions.
*/
static int is_lun_busy( Scsi_Cmnd *cmd, int should_be_tagged )
static int is_lun_busy(Scsi_Cmnd *cmd, int should_be_tagged)
{
SETUP_HOSTDATA(cmd->device->host);
if (hostdata->busy[cmd->device->id] & (1 << cmd->device->lun))
return( 1 );
return 1;
if (!should_be_tagged ||
!setup_use_tagged_queuing || !cmd->device->tagged_supported)
return( 0 );
return 0;
if (TagAlloc[cmd->device->id][cmd->device->lun].nr_allocated >=
TagAlloc[cmd->device->id][cmd->device->lun].queue_size ) {
TAG_PRINTK( "scsi%d: target %d lun %d: no free tags\n",
H_NO(cmd), cmd->device->id, cmd->device->lun );
return( 1 );
TagAlloc[cmd->device->id][cmd->device->lun].queue_size) {
TAG_PRINTK("scsi%d: target %d lun %d: no free tags\n",
H_NO(cmd), cmd->device->id, cmd->device->lun);
return 1;
}
return( 0 );
return 0;
}
......@@ -374,7 +382,7 @@ static int is_lun_busy( Scsi_Cmnd *cmd, int should_be_tagged )
* untagged.
*/
static void cmd_get_tag( Scsi_Cmnd *cmd, int should_be_tagged )
static void cmd_get_tag(Scsi_Cmnd *cmd, int should_be_tagged)
{
SETUP_HOSTDATA(cmd->device->host);
......@@ -385,19 +393,18 @@ static void cmd_get_tag( Scsi_Cmnd *cmd, int should_be_tagged )
!setup_use_tagged_queuing || !cmd->device->tagged_supported) {
cmd->tag = TAG_NONE;
hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
TAG_PRINTK( "scsi%d: target %d lun %d now allocated by untagged "
"command\n", H_NO(cmd), cmd->device->id, cmd->device->lun );
}
else {
TAG_PRINTK("scsi%d: target %d lun %d now allocated by untagged "
"command\n", H_NO(cmd), cmd->device->id, cmd->device->lun);
} else {
TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
cmd->tag = find_first_zero_bit( ta->allocated, MAX_TAGS );
set_bit( cmd->tag, ta->allocated );
cmd->tag = find_first_zero_bit(ta->allocated, MAX_TAGS);
set_bit(cmd->tag, ta->allocated);
ta->nr_allocated++;
TAG_PRINTK( "scsi%d: using tag %d for target %d lun %d "
TAG_PRINTK("scsi%d: using tag %d for target %d lun %d "
"(now %d tags in use)\n",
H_NO(cmd), cmd->tag, cmd->device->id, cmd->device->lun,
ta->nr_allocated );
H_NO(cmd), cmd->tag, cmd->device->id,
cmd->device->lun, ta->nr_allocated);
}
}
......@@ -406,30 +413,28 @@ static void cmd_get_tag( Scsi_Cmnd *cmd, int should_be_tagged )
* unlock the LUN.
*/
static void cmd_free_tag( Scsi_Cmnd *cmd )
static void cmd_free_tag(Scsi_Cmnd *cmd)
{
SETUP_HOSTDATA(cmd->device->host);
if (cmd->tag == TAG_NONE) {
hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
TAG_PRINTK( "scsi%d: target %d lun %d untagged cmd finished\n",
H_NO(cmd), cmd->device->id, cmd->device->lun );
}
else if (cmd->tag >= MAX_TAGS) {
TAG_PRINTK("scsi%d: target %d lun %d untagged cmd finished\n",
H_NO(cmd), cmd->device->id, cmd->device->lun);
} else if (cmd->tag >= MAX_TAGS) {
printk(KERN_NOTICE "scsi%d: trying to free bad tag %d!\n",
H_NO(cmd), cmd->tag );
}
else {
H_NO(cmd), cmd->tag);
} else {
TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
clear_bit( cmd->tag, ta->allocated );
clear_bit(cmd->tag, ta->allocated);
ta->nr_allocated--;
TAG_PRINTK( "scsi%d: freed tag %d for target %d lun %d\n",
H_NO(cmd), cmd->tag, cmd->device->id, cmd->device->lun );
TAG_PRINTK("scsi%d: freed tag %d for target %d lun %d\n",
H_NO(cmd), cmd->tag, cmd->device->id, cmd->device->lun);
}
}
static void free_all_tags( void )
static void free_all_tags(void)
{
int target, lun;
TAG_ALLOC *ta;
......@@ -437,8 +442,8 @@ static void free_all_tags( void )
if (!setup_use_tagged_queuing)
return;
for( target = 0; target < 8; ++target ) {
for( lun = 0; lun < 8; ++lun ) {
for (target = 0; target < 8; ++target) {
for (lun = 0; lun < 8; ++lun) {
ta = &TagAlloc[target][lun];
bitmap_zero(ta->allocated, MAX_TAGS);
ta->nr_allocated = 0;
......@@ -461,7 +466,7 @@ static void free_all_tags( void )
* assumed to be already transfered into ptr/this_residual.
*/
static void merge_contiguous_buffers( Scsi_Cmnd *cmd )
static void merge_contiguous_buffers(Scsi_Cmnd *cmd)
{
unsigned long endaddr;
#if (NDEBUG & NDEBUG_MERGING)
......@@ -471,8 +476,8 @@ static void merge_contiguous_buffers( Scsi_Cmnd *cmd )
for (endaddr = virt_to_phys(cmd->SCp.ptr + cmd->SCp.this_residual - 1) + 1;
cmd->SCp.buffers_residual &&
virt_to_phys(page_address(cmd->SCp.buffer[1].page)+
cmd->SCp.buffer[1].offset) == endaddr; ) {
virt_to_phys(page_address(cmd->SCp.buffer[1].page) +
cmd->SCp.buffer[1].offset) == endaddr;) {
MER_PRINTK("VTOP(%p) == %08lx -> merging\n",
cmd->SCp.buffer[1].address, endaddr);
#if (NDEBUG & NDEBUG_MERGING)
......@@ -499,7 +504,7 @@ static void merge_contiguous_buffers( Scsi_Cmnd *cmd )
* Inputs : cmd - Scsi_Cmnd structure to have pointers reset.
*/
static __inline__ void initialize_SCp(Scsi_Cmnd *cmd)
static inline void initialize_SCp(Scsi_Cmnd *cmd)
{
/*
* Initialize the Scsi Pointer field so that all of the commands in the
......@@ -507,19 +512,19 @@ static __inline__ void initialize_SCp(Scsi_Cmnd *cmd)
*/
if (cmd->use_sg) {
cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
cmd->SCp.buffer = (struct scatterlist *)cmd->request_buffer;
cmd->SCp.buffers_residual = cmd->use_sg - 1;
cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page)+
cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page) +
cmd->SCp.buffer->offset;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
/* ++roman: Try to merge some scatter-buffers if they are at
* contiguous physical addresses.
*/
merge_contiguous_buffers( cmd );
merge_contiguous_buffers(cmd);
} else {
cmd->SCp.buffer = NULL;
cmd->SCp.buffers_residual = 0;
cmd->SCp.ptr = (char *) cmd->request_buffer;
cmd->SCp.ptr = (char *)cmd->request_buffer;
cmd->SCp.this_residual = cmd->request_bufflen;
}
}
......@@ -529,21 +534,26 @@ static __inline__ void initialize_SCp(Scsi_Cmnd *cmd)
#if NDEBUG
static struct {
unsigned char mask;
const char * name;}
signals[] = {{ SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" },
const char *name;
} signals[] = {
{ SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" },
{ SR_REQ, "REQ" }, { SR_MSG, "MSG" }, { SR_CD, "CD" }, { SR_IO, "IO" },
{ SR_SEL, "SEL" }, {0, NULL}},
basrs[] = {{BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL}},
icrs[] = {{ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"},
{ SR_SEL, "SEL" }, {0, NULL}
}, basrs[] = {
{BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL}
}, icrs[] = {
{ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"},
{ICR_ASSERT_BSY, "ASSERT BSY"}, {ICR_ASSERT_SEL, "ASSERT SEL"},
{ICR_ASSERT_ATN, "ASSERT ATN"}, {ICR_ASSERT_DATA, "ASSERT DATA"},
{0, NULL}},
mrs[] = {{MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
{0, NULL}
}, mrs[] = {
{MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
{MR_ENABLE_PAR_CHECK, "MODE PARITY CHECK"}, {MR_ENABLE_PAR_INTR,
"MODE PARITY INTR"}, {MR_ENABLE_EOP_INTR,"MODE EOP INTR"},
{MR_MONITOR_BSY, "MODE MONITOR BSY"},
{MR_DMA_MODE, "MODE DMA"}, {MR_ARBITRATE, "MODE ARBITRATION"},
{0, NULL}};
{0, NULL}
};
/*
* Function : void NCR5380_print(struct Scsi_Host *instance)
......@@ -553,7 +563,8 @@ mrs[] = {{MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
* Input : instance - which NCR5380
*/
static void NCR5380_print(struct Scsi_Host *instance) {
static void NCR5380_print(struct Scsi_Host *instance)
{
unsigned char status, data, basr, mr, icr, i;
unsigned long flags;
......@@ -565,11 +576,11 @@ static void NCR5380_print(struct Scsi_Host *instance) {
basr = NCR5380_read(BUS_AND_STATUS_REG);
local_irq_restore(flags);
printk("STATUS_REG: %02x ", status);
for (i = 0; signals[i].mask ; ++i)
for (i = 0; signals[i].mask; ++i)
if (status & signals[i].mask)
printk(",%s", signals[i].name);
printk("\nBASR: %02x ", basr);
for (i = 0; basrs[i].mask ; ++i)
for (i = 0; basrs[i].mask; ++i)
if (basr & basrs[i].mask)
printk(",%s", basrs[i].name);
printk("\nICR: %02x ", icr);
......@@ -589,7 +600,8 @@ static struct {
} phases[] = {
{PHASE_DATAOUT, "DATAOUT"}, {PHASE_DATAIN, "DATAIN"}, {PHASE_CMDOUT, "CMDOUT"},
{PHASE_STATIN, "STATIN"}, {PHASE_MSGOUT, "MSGOUT"}, {PHASE_MSGIN, "MSGIN"},
{PHASE_UNKNOWN, "UNKNOWN"}};
{PHASE_UNKNOWN, "UNKNOWN"}
};
/*
* Function : void NCR5380_print_phase(struct Scsi_Host *instance)
......@@ -609,7 +621,8 @@ static void NCR5380_print_phase(struct Scsi_Host *instance)
printk(KERN_DEBUG "scsi%d: REQ not asserted, phase unknown.\n", HOSTNO);
else {
for (i = 0; (phases[i].value != PHASE_UNKNOWN) &&
(phases[i].value != (status & PHASE_MASK)); ++i);
(phases[i].value != (status & PHASE_MASK)); ++i)
;
printk(KERN_DEBUG "scsi%d: phase %s\n", HOSTNO, phases[i].name);
}
}
......@@ -617,8 +630,12 @@ static void NCR5380_print_phase(struct Scsi_Host *instance)
#else /* !NDEBUG */
/* dummies... */
__inline__ void NCR5380_print(struct Scsi_Host *instance) { };
__inline__ void NCR5380_print_phase(struct Scsi_Host *instance) { };
static inline void NCR5380_print(struct Scsi_Host *instance)
{
};
static inline void NCR5380_print_phase(struct Scsi_Host *instance)
{
};
#endif
......@@ -638,10 +655,10 @@ __inline__ void NCR5380_print_phase(struct Scsi_Host *instance) { };
#include <linux/workqueue.h>
#include <linux/interrupt.h>
static volatile int main_running = 0;
static DECLARE_WORK(NCR5380_tqueue, (void (*)(void*))NCR5380_main, NULL);
static volatile int main_running;
static DECLARE_WORK(NCR5380_tqueue, (void (*)(void *))NCR5380_main, NULL);
static __inline__ void queue_main(void)
static inline void queue_main(void)
{
if (!main_running) {
/* If in interrupt and NCR5380_main() not already running,
......@@ -655,7 +672,7 @@ static __inline__ void queue_main(void)
}
static inline void NCR5380_all_init (void)
static inline void NCR5380_all_init(void)
{
static int done = 0;
if (!done) {
......@@ -674,7 +691,7 @@ static inline void NCR5380_all_init (void)
* Inputs : instance, pointer to this instance. Unused.
*/
static void __init NCR5380_print_options (struct Scsi_Host *instance)
static void __init NCR5380_print_options(struct Scsi_Host *instance)
{
printk(" generic options"
#ifdef AUTOSENSE
......@@ -702,7 +719,7 @@ static void __init NCR5380_print_options (struct Scsi_Host *instance)
* Inputs : instance, pointer to this instance.
*/
static void NCR5380_print_status (struct Scsi_Host *instance)
static void NCR5380_print_status(struct Scsi_Host *instance)
{
char *pr_bfr;
char *start;
......@@ -711,7 +728,7 @@ static void NCR5380_print_status (struct Scsi_Host *instance)
NCR_PRINT(NDEBUG_ANY);
NCR_PRINT_PHASE(NDEBUG_ANY);
pr_bfr = (char *) __get_free_page(GFP_ATOMIC);
pr_bfr = (char *)__get_free_page(GFP_ATOMIC);
if (!pr_bfr) {
printk("NCR5380_print_status: no memory for print buffer\n");
return;
......@@ -719,7 +736,7 @@ static void NCR5380_print_status (struct Scsi_Host *instance)
len = NCR5380_proc_info(instance, pr_bfr, &start, 0, PAGE_SIZE, 0);
pr_bfr[len] = 0;
printk("\n%s\n", pr_bfr);
free_page((unsigned long) pr_bfr);
free_page((unsigned long)pr_bfr);
}
......@@ -739,14 +756,14 @@ static void NCR5380_print_status (struct Scsi_Host *instance)
#undef SPRINTF
#define SPRINTF(fmt,args...) \
do { if (pos + strlen(fmt) + 20 /* slop */ < buffer + length) \
pos += sprintf(pos, fmt , ## args); } while(0)
static
char *lprint_Scsi_Cmnd (Scsi_Cmnd *cmd, char *pos, char *buffer, int length);
do { \
if (pos + strlen(fmt) + 20 /* slop */ < buffer + length) \
pos += sprintf(pos, fmt , ## args); \
} while(0)
static char *lprint_Scsi_Cmnd(Scsi_Cmnd *cmd, char *pos, char *buffer, int length);
static
int NCR5380_proc_info (struct Scsi_Host *instance, char *buffer, char **start, off_t offset,
int length, int inout)
static int NCR5380_proc_info(struct Scsi_Host *instance, char *buffer,
char **start, off_t offset, int length, int inout)
{
char *pos = buffer;
struct NCR5380_hostdata *hostdata;
......@@ -763,23 +780,23 @@ int NCR5380_proc_info (struct Scsi_Host *instance, char *buffer, char **start, o
hostdata = (struct NCR5380_hostdata *)instance->hostdata;
if (inout) { /* Has data been written to the file ? */
return(-ENOSYS); /* Currently this is a no-op */
}
if (inout) /* Has data been written to the file ? */
return -ENOSYS; /* Currently this is a no-op */
SPRINTF("NCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
check_offset();
local_irq_save(flags);
SPRINTF("NCR5380: coroutine is%s running.\n", main_running ? "" : "n't");
SPRINTF("NCR5380: coroutine is%s running.\n",
main_running ? "" : "n't");
check_offset();
if (!hostdata->connected)
SPRINTF("scsi%d: no currently connected command\n", HOSTNO);
else
pos = lprint_Scsi_Cmnd ((Scsi_Cmnd *) hostdata->connected,
pos = lprint_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected,
pos, buffer, length);
SPRINTF("scsi%d: issue_queue\n", HOSTNO);
check_offset();
for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr; ptr = NEXT(ptr)) {
pos = lprint_Scsi_Cmnd (ptr, pos, buffer, length);
for (ptr = (Scsi_Cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr)) {
pos = lprint_Scsi_Cmnd(ptr, pos, buffer, length);
check_offset();
}
......@@ -787,7 +804,7 @@ int NCR5380_proc_info (struct Scsi_Host *instance, char *buffer, char **start, o
check_offset();
for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
ptr = NEXT(ptr)) {
pos = lprint_Scsi_Cmnd (ptr, pos, buffer, length);
pos = lprint_Scsi_Cmnd(ptr, pos, buffer, length);
check_offset();
}
......@@ -800,8 +817,7 @@ int NCR5380_proc_info (struct Scsi_Host *instance, char *buffer, char **start, o
return length;
}
static char *
lprint_Scsi_Cmnd (Scsi_Cmnd *cmd, char *pos, char *buffer, int length)
static char *lprint_Scsi_Cmnd(Scsi_Cmnd *cmd, char *pos, char *buffer, int length)
{
int i, s;
unsigned char *command;
......@@ -829,7 +845,7 @@ lprint_Scsi_Cmnd (Scsi_Cmnd *cmd, char *pos, char *buffer, int length)
*
*/
static int NCR5380_init (struct Scsi_Host *instance, int flags)
static int NCR5380_init(struct Scsi_Host *instance, int flags)
{
int i;
SETUP_HOSTDATA(instance);
......@@ -861,7 +877,6 @@ static int NCR5380_init (struct Scsi_Host *instance, int flags)
first_instance = instance;
}
#ifndef AUTOSENSE
if ((instance->cmd_per_lun > 1) || (instance->can_queue > 1))
printk("scsi%d: WARNING : support for multiple outstanding commands enabled\n"
......@@ -897,20 +912,19 @@ int atari_scsi_update_timeout(Scsi_Cmnd * SCset, int timeout)
* timers for timeout.
*/
if (!timer_pending(&SCset->eh_timeout)) {
if (!timer_pending(&SCset->eh_timeout))
rtn = 0;
} else {
else
rtn = SCset->eh_timeout.expires - jiffies;
}
if (timeout == 0) {
del_timer(&SCset->eh_timeout);
SCset->eh_timeout.data = (unsigned long) NULL;
SCset->eh_timeout.data = (unsigned long)NULL;
SCset->eh_timeout.expires = 0;
} else {
if (SCset->eh_timeout.data != (unsigned long) NULL)
if (SCset->eh_timeout.data != (unsigned long)NULL)
del_timer(&SCset->eh_timeout);
SCset->eh_timeout.data = (unsigned long) SCset;
SCset->eh_timeout.data = (unsigned long)SCset;
SCset->eh_timeout.expires = jiffies + timeout;
add_timer(&SCset->eh_timeout);
}
......@@ -935,8 +949,7 @@ int atari_scsi_update_timeout(Scsi_Cmnd * SCset, int timeout)
*
*/
static
int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
{
SETUP_HOSTDATA(cmd->device->host);
Scsi_Cmnd *tmp;
......@@ -956,7 +969,6 @@ int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
}
#endif /* (NDEBUG & NDEBUG_NO_WRITE) */
#ifdef NCR5380_STATS
# if 0
if (!hostdata->connected && !hostdata->issue_queue &&
......@@ -967,8 +979,7 @@ int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
# ifdef NCR5380_STAT_LIMIT
if (cmd->request_bufflen > NCR5380_STAT_LIMIT)
# endif
switch (cmd->cmnd[0])
{
switch (cmd->cmnd[0]) {
case WRITE:
case WRITE_6:
case WRITE_10:
......@@ -996,7 +1007,6 @@ int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
cmd->result = 0;
/*
* Insert the cmd into the issue queue. Note that REQUEST SENSE
* commands are added to the head of the queue since any command will
......@@ -1064,7 +1074,7 @@ int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
* reenable them. This prevents reentrancy and kernel stack overflow.
*/
static void NCR5380_main (void *bl)
static void NCR5380_main(void *bl)
{
Scsi_Cmnd *tmp, *prev;
struct Scsi_Host *instance = first_instance;
......@@ -1103,7 +1113,7 @@ static void NCR5380_main (void *bl)
done = 1;
if (!hostdata->connected) {
MAIN_PRINTK( "scsi%d: not connected\n", HOSTNO );
MAIN_PRINTK("scsi%d: not connected\n", HOSTNO);
/*
* Search through the issue_queue for a command destined
* for a target that's not busy.
......@@ -1113,10 +1123,12 @@ static void NCR5380_main (void *bl)
tmp && (tmp != prev); prev = tmp, tmp = NEXT(tmp))
;
/*printk("%p ", tmp);*/
if ((tmp == prev) && tmp) printk(" LOOP\n");/* else printk("\n");*/
if ((tmp == prev) && tmp)
printk(" LOOP\n");
/* else printk("\n"); */
#endif
for (tmp = (Scsi_Cmnd *) hostdata->issue_queue,
prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp) ) {
prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp)) {
#if (NDEBUG & NDEBUG_LISTS)
if (prev != tmp)
......@@ -1168,14 +1180,14 @@ static void NCR5380_main (void *bl)
*/
#ifdef SUPPORT_TAGS
cmd_get_tag( tmp, tmp->cmnd[0] != REQUEST_SENSE );
cmd_get_tag(tmp, tmp->cmnd[0] != REQUEST_SENSE);
#endif
if (!NCR5380_select(instance, tmp,
(tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE :
TAG_NEXT)) {
falcon_dont_release--;
/* release if target did not response! */
falcon_release_lock_if_possible( hostdata );
falcon_release_lock_if_possible(hostdata);
break;
} else {
local_irq_disable();
......@@ -1183,7 +1195,7 @@ static void NCR5380_main (void *bl)
NEXT(tmp) = hostdata->issue_queue;
hostdata->issue_queue = tmp;
#ifdef SUPPORT_TAGS
cmd_free_tag( tmp );
cmd_free_tag(tmp);
#endif
falcon_dont_release--;
local_irq_restore(flags);
......@@ -1229,7 +1241,7 @@ static void NCR5380_main (void *bl)
*
*/
static void NCR5380_dma_complete( struct Scsi_Host *instance )
static void NCR5380_dma_complete(struct Scsi_Host *instance)
{
SETUP_HOSTDATA(instance);
int transfered, saved_data = 0, overrun = 0, cnt, toPIO;
......@@ -1246,9 +1258,9 @@ static void NCR5380_dma_complete( struct Scsi_Host *instance )
p = hostdata->connected->SCp.phase;
if (p & SR_IO) {
udelay(10);
if ((((NCR5380_read(BUS_AND_STATUS_REG)) &
if ((NCR5380_read(BUS_AND_STATUS_REG) &
(BASR_PHASE_MATCH|BASR_ACK)) ==
(BASR_PHASE_MATCH|BASR_ACK))) {
(BASR_PHASE_MATCH|BASR_ACK)) {
saved_data = NCR5380_read(INPUT_DATA_REG);
overrun = 1;
DMA_PRINTK("scsi%d: read overrun handled\n", HOSTNO);
......@@ -1260,15 +1272,15 @@ static void NCR5380_dma_complete( struct Scsi_Host *instance )
HOSTNO, NCR5380_read(BUS_AND_STATUS_REG),
NCR5380_read(STATUS_REG));
(void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
NCR5380_write(MODE_REG, MR_BASE);
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
transfered = hostdata->dma_len - NCR5380_dma_residual(instance);
hostdata->dma_len = 0;
data = (unsigned char **) &(hostdata->connected->SCp.ptr);
count = &(hostdata->connected->SCp.this_residual);
data = (unsigned char **)&hostdata->connected->SCp.ptr;
count = &hostdata->connected->SCp.this_residual;
*data += transfered;
*count -= transfered;
......@@ -1302,7 +1314,7 @@ static void NCR5380_dma_complete( struct Scsi_Host *instance )
*
*/
static irqreturn_t NCR5380_intr (int irq, void *dev_id)
static irqreturn_t NCR5380_intr(int irq, void *dev_id)
{
struct Scsi_Host *instance = first_instance;
int done = 1, handled = 0;
......@@ -1321,17 +1333,14 @@ static irqreturn_t NCR5380_intr (int irq, void *dev_id)
ENABLE_IRQ();
INT_PRINTK("scsi%d: SEL interrupt\n", HOSTNO);
NCR5380_reselect(instance);
(void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
}
else if (basr & BASR_PARITY_ERROR) {
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
} else if (basr & BASR_PARITY_ERROR) {
INT_PRINTK("scsi%d: PARITY interrupt\n", HOSTNO);
(void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
}
else if ((NCR5380_read(STATUS_REG) & SR_RST) == SR_RST) {
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
} else if ((NCR5380_read(STATUS_REG) & SR_RST) == SR_RST) {
INT_PRINTK("scsi%d: RESET interrupt\n", HOSTNO);
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
}
else {
} else {
/*
* The rest of the interrupt conditions can occur only during a
* DMA transfer
......@@ -1361,16 +1370,15 @@ static irqreturn_t NCR5380_intr (int irq, void *dev_id)
"BASR 0x%x, MR 0x%x, SR 0x%x\n",
HOSTNO, basr, NCR5380_read(MODE_REG),
NCR5380_read(STATUS_REG));
(void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
}
} /* if !(SELECTION || PARITY) */
handled = 1;
} /* BASR & IRQ */
else {
} /* BASR & IRQ */ else {
printk(KERN_NOTICE "scsi%d: interrupt without IRQ bit set in BASR, "
"BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr,
NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG));
(void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
}
if (!done) {
......@@ -1382,13 +1390,12 @@ static irqreturn_t NCR5380_intr (int irq, void *dev_id)
}
#ifdef NCR5380_STATS
static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd* cmd)
static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd *cmd)
{
# ifdef NCR5380_STAT_LIMIT
if (cmd->request_bufflen > NCR5380_STAT_LIMIT)
# endif
switch (cmd->cmnd[0])
{
switch (cmd->cmnd[0]) {
case WRITE:
case WRITE_6:
case WRITE_10:
......@@ -1438,7 +1445,7 @@ static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd* cmd)
* cmd->result host byte set to DID_BAD_TARGET.
*/
static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
{
SETUP_HOSTDATA(instance);
unsigned char tmp[3], phase;
......@@ -1464,7 +1471,6 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
}
NCR5380_write(TARGET_COMMAND_REG, 0);
/*
* Start arbitration.
*/
......@@ -1479,11 +1485,10 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
{
unsigned long timeout = jiffies + 2*NCR_TIMEOUT;
while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
&& time_before(jiffies, timeout) && !hostdata->connected)
while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS) &&
time_before(jiffies, timeout) && !hostdata->connected)
;
if (time_after_eq(jiffies, timeout))
{
if (time_after_eq(jiffies, timeout)) {
printk("scsi : arbitration timeout at %d\n", __LINE__);
NCR5380_write(MODE_REG, MR_BASE);
NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
......@@ -1491,8 +1496,9 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
}
}
#else /* NCR_TIMEOUT */
while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
&& !hostdata->connected);
while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS) &&
!hostdata->connected)
;
#endif
ARB_PRINTK("scsi%d: arbitration complete\n", HOSTNO);
......@@ -1524,8 +1530,8 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
/* after/during arbitration, BSY should be asserted.
IBM DPES-31080 Version S31Q works now */
/* Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) */
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_SEL |
ICR_ASSERT_BSY ) ;
NCR5380_write(INITIATOR_COMMAND_REG,
ICR_BASE | ICR_ASSERT_SEL | ICR_ASSERT_BSY);
if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
hostdata->connected) {
......@@ -1634,23 +1640,24 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
* IO while SEL is true. But again, there are some disks out the in the
* world that do that nevertheless. (Somebody claimed that this announces
* reselection capability of the target.) So we better skip that test and
* only wait for BSY... (Famous german words: Der Klügere gibt nach :-)
* only wait for BSY... (Famous german words: Der Klügere gibt nach :-)
*/
while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) &
(SR_BSY | SR_IO)));
while (time_before(jiffies, timeout) &&
!(NCR5380_read(STATUS_REG) & (SR_BSY | SR_IO)))
;
if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) ==
(SR_SEL | SR_IO)) {
if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) {
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_reselect(instance);
printk (KERN_ERR "scsi%d: reselection after won arbitration?\n",
printk(KERN_ERR "scsi%d: reselection after won arbitration?\n",
HOSTNO);
NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
return -1;
}
#else
while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) & SR_BSY));
while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) & SR_BSY))
;
#endif
/*
......@@ -1678,7 +1685,7 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
collect_stats(hostdata, cmd);
#endif
#ifdef SUPPORT_TAGS
cmd_free_tag( cmd );
cmd_free_tag(cmd);
#endif
cmd->scsi_done(cmd);
NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
......@@ -1705,7 +1712,8 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
*/
/* Wait for start of REQ/ACK handshake */
while (!(NCR5380_read(STATUS_REG) & SR_REQ));
while (!(NCR5380_read(STATUS_REG) & SR_REQ))
;
SEL_PRINTK("scsi%d: target %d selected, going into MESSAGE OUT phase.\n",
HOSTNO, cmd->device->id);
......@@ -1720,7 +1728,7 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
len = 1;
#else
len = 1;
cmd->tag=0;
cmd->tag = 0;
#endif /* SUPPORT_TAGS */
/* Send message(s) */
......@@ -1736,7 +1744,6 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
initialize_SCp(cmd);
return 0;
}
......@@ -1765,7 +1772,7 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
* counts, we will always do a pseudo DMA or DMA transfer.
*/
static int NCR5380_transfer_pio( struct Scsi_Host *instance,
static int NCR5380_transfer_pio(struct Scsi_Host *instance,
unsigned char *phase, int *count,
unsigned char **data)
{
......@@ -1786,7 +1793,8 @@ static int NCR5380_transfer_pio( struct Scsi_Host *instance,
* Wait for assertion of REQ, after which the phase bits will be
* valid
*/
while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ));
while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ))
;
HSH_PRINTK("scsi%d: REQ detected\n", HOSTNO);
......@@ -1814,8 +1822,7 @@ static int NCR5380_transfer_pio( struct Scsi_Host *instance,
if (!(p & SR_IO)) {
if (!((p & SR_MSG) && c > 1)) {
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
ICR_ASSERT_DATA);
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA);
NCR_PRINT(NDEBUG_PIO);
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
ICR_ASSERT_DATA | ICR_ASSERT_ACK);
......@@ -1831,11 +1838,12 @@ static int NCR5380_transfer_pio( struct Scsi_Host *instance,
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
}
while (NCR5380_read(STATUS_REG) & SR_REQ);
while (NCR5380_read(STATUS_REG) & SR_REQ)
;
HSH_PRINTK("scsi%d: req false, handshake complete\n", HOSTNO);
/*
/*
* We have several special cases to consider during REQ/ACK handshaking :
* 1. We were in MSGOUT phase, and we are on the last byte of the
* message. ATN must be dropped as ACK is dropped.
......@@ -1861,7 +1869,8 @@ static int NCR5380_transfer_pio( struct Scsi_Host *instance,
tmp = NCR5380_read(STATUS_REG);
/* The phase read from the bus is valid if either REQ is (already)
* asserted or if ACK hasn't been released yet. The latter is the case if
* we're in MSGIN and all wanted bytes have been received. */
* we're in MSGIN and all wanted bytes have been received.
*/
if ((tmp & SR_REQ) || (p == PHASE_MSGIN && c == 0))
*phase = tmp & PHASE_MASK;
else
......@@ -1882,7 +1891,7 @@ static int NCR5380_transfer_pio( struct Scsi_Host *instance,
* Returns : 0 on success, -1 on failure.
*/
static int do_abort (struct Scsi_Host *host)
static int do_abort(struct Scsi_Host *host)
{
unsigned char tmp, *msgptr, phase;
int len;
......@@ -1900,14 +1909,16 @@ static int do_abort (struct Scsi_Host *host)
* the target sees, so we just handshake.
*/
while (!(tmp = NCR5380_read(STATUS_REG)) & SR_REQ);
while (!(tmp = NCR5380_read(STATUS_REG)) & SR_REQ)
;
NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
if ((tmp & PHASE_MASK) != PHASE_MSGOUT) {
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
ICR_ASSERT_ACK);
while (NCR5380_read(STATUS_REG) & SR_REQ);
while (NCR5380_read(STATUS_REG) & SR_REQ)
;
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
}
......@@ -1915,7 +1926,7 @@ static int do_abort (struct Scsi_Host *host)
msgptr = &tmp;
len = 1;
phase = PHASE_MSGOUT;
NCR5380_transfer_pio (host, &phase, &len, &msgptr);
NCR5380_transfer_pio(host, &phase, &len, &msgptr);
/*
* If we got here, and the command completed successfully,
......@@ -1946,7 +1957,7 @@ static int do_abort (struct Scsi_Host *host)
*/
static int NCR5380_transfer_dma( struct Scsi_Host *instance,
static int NCR5380_transfer_dma(struct Scsi_Host *instance,
unsigned char *phase, int *count,
unsigned char **data)
{
......@@ -1962,9 +1973,8 @@ static int NCR5380_transfer_dma( struct Scsi_Host *instance,
return -1;
}
if (atari_read_overruns && (p & SR_IO)) {
if (atari_read_overruns && (p & SR_IO))
c -= atari_read_overruns;
}
DMA_PRINTK("scsi%d: initializing DMA for %s, %d bytes %s %p\n",
HOSTNO, (p & SR_IO) ? "reading" : "writing",
......@@ -2025,7 +2035,7 @@ static int NCR5380_transfer_dma( struct Scsi_Host *instance,
* to recover from an unexpected bus free condition.
*/
static void NCR5380_information_transfer (struct Scsi_Host *instance)
static void NCR5380_information_transfer(struct Scsi_Host *instance)
{
SETUP_HOSTDATA(instance);
unsigned long flags;
......@@ -2036,7 +2046,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
int transfersize;
#endif
unsigned char *data;
unsigned char phase, tmp, extended_msg[10], old_phase=0xff;
unsigned char phase, tmp, extended_msg[10], old_phase = 0xff;
Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected;
while (1) {
......@@ -2054,7 +2064,8 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
ICR_ASSERT_ACK);
while (NCR5380_read(STATUS_REG) & SR_REQ);
while (NCR5380_read(STATUS_REG) & SR_REQ)
;
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
ICR_ASSERT_ATN);
sink = 0;
......@@ -2082,12 +2093,12 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
++cmd->SCp.buffer;
--cmd->SCp.buffers_residual;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page)+
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
cmd->SCp.buffer->offset;
/* ++roman: Try to merge some scatter-buffers if
* they are at contiguous physical addresses.
*/
merge_contiguous_buffers( cmd );
merge_contiguous_buffers(cmd);
INF_PRINTK("scsi%d: %d bytes and %d buffers left\n",
HOSTNO, cmd->SCp.this_residual,
cmd->SCp.buffers_residual);
......@@ -2103,7 +2114,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
* in an unconditional loop.
*/
/* ++roman: I suggest, this should be
/* ++roman: I suggest, this should be
* #if def(REAL_DMA)
* instead of leaving REAL_DMA out.
*/
......@@ -2114,7 +2125,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
len = transfersize;
cmd->SCp.phase = phase;
if (NCR5380_transfer_dma(instance, &phase,
&len, (unsigned char **) &cmd->SCp.ptr)) {
&len, (unsigned char **)&cmd->SCp.ptr)) {
/*
* If the watchdog timer fires, all future
* accesses to this device will use the
......@@ -2145,8 +2156,8 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
} else
#endif /* defined(REAL_DMA) */
NCR5380_transfer_pio(instance, &phase,
(int *) &cmd->SCp.this_residual, (unsigned char **)
&cmd->SCp.ptr);
(int *)&cmd->SCp.this_residual,
(unsigned char **)&cmd->SCp.ptr);
break;
case PHASE_MSGIN:
len = 1;
......@@ -2188,7 +2199,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
"linked command complete, no next_link\n",
HOSTNO, cmd->device->id, cmd->device->lun);
sink = 1;
do_abort (instance);
do_abort(instance);
return;
}
......@@ -2217,7 +2228,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
QU_PRINTK("scsi%d: command for target %d, lun %d "
"completed\n", HOSTNO, cmd->device->id, cmd->device->lun);
#ifdef SUPPORT_TAGS
cmd_free_tag( cmd );
cmd_free_tag(cmd);
if (status_byte(cmd->SCp.Status) == QUEUE_FULL) {
/* Turn a QUEUE FULL status into BUSY, I think the
* mid level cannot handle QUEUE FULL :-( (The
......@@ -2265,8 +2276,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
#ifdef AUTOSENSE
if ((cmd->cmnd[0] != REQUEST_SENSE) &&
(status_byte(cmd->SCp.Status) == CHECK_CONDITION)) {
ASEN_PRINTK("scsi%d: performing request sense\n",
HOSTNO);
ASEN_PRINTK("scsi%d: performing request sense\n", HOSTNO);
cmd->cmnd[0] = REQUEST_SENSE;
cmd->cmnd[1] &= 0xe0;
cmd->cmnd[2] = 0;
......@@ -2314,7 +2324,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
* ST-DMA here if no other commands are waiting on the
* disconnected queue.
*/
falcon_release_lock_if_possible( hostdata );
falcon_release_lock_if_possible(hostdata);
return;
case MESSAGE_REJECT:
/* Accept message by clearing ACK */
......@@ -2385,7 +2395,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
break;
case EXTENDED_MESSAGE:
/*
/*
* Extended messages are sent in the following format :
* Byte
* 0 EXTENDED_MESSAGE == 1
......@@ -2411,7 +2421,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
(int)extended_msg[1], (int)extended_msg[2]);
if (!len && extended_msg[1] <=
(sizeof (extended_msg) - 1)) {
(sizeof(extended_msg) - 1)) {
/* Accept third byte by clearing ACK */
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
len = extended_msg[1] - 1;
......@@ -2463,8 +2473,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
msgout = MESSAGE_REJECT;
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
ICR_ASSERT_ATN);
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
break;
} /* switch (tmp) */
break;
......@@ -2475,7 +2484,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
NCR5380_transfer_pio(instance, &phase, &len, &data);
if (msgout == ABORT) {
#ifdef SUPPORT_TAGS
cmd_free_tag( cmd );
cmd_free_tag(cmd);
#else
hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
#endif
......@@ -2486,7 +2495,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
#endif
cmd->scsi_done(cmd);
NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
falcon_release_lock_if_possible( hostdata );
falcon_release_lock_if_possible(hostdata);
return;
}
msgout = NOP;
......@@ -2499,8 +2508,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
* PSEUDO-DMA architecture we should probably
* use the dma transfer function.
*/
NCR5380_transfer_pio(instance, &phase, &len,
&data);
NCR5380_transfer_pio(instance, &phase, &len, &data);
break;
case PHASE_STATIN:
len = 1;
......@@ -2528,7 +2536,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
*/
static void NCR5380_reselect (struct Scsi_Host *instance)
static void NCR5380_reselect(struct Scsi_Host *instance)
{
SETUP_HOSTDATA(instance);
unsigned char target_mask;
......@@ -2565,14 +2573,16 @@ static void NCR5380_reselect (struct Scsi_Host *instance)
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
while (NCR5380_read(STATUS_REG) & SR_SEL);
while (NCR5380_read(STATUS_REG) & SR_SEL)
;
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
/*
* Wait for target to go into MSGIN.
*/
while (!(NCR5380_read(STATUS_REG) & SR_REQ));
while (!(NCR5380_read(STATUS_REG) & SR_REQ))
;
len = 1;
data = msg;
......@@ -2595,9 +2605,9 @@ static void NCR5380_reselect (struct Scsi_Host *instance)
tag = TAG_NONE;
if (phase == PHASE_MSGIN && setup_use_tagged_queuing) {
/* Accept previous IDENTIFY message by clearing ACK */
NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
len = 2;
data = msg+1;
data = msg + 1;
if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
msg[1] == SIMPLE_QUEUE_TAG)
tag = msg[2];
......@@ -2612,7 +2622,7 @@ static void NCR5380_reselect (struct Scsi_Host *instance)
*/
for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL;
tmp; prev = tmp, tmp = NEXT(tmp) ) {
tmp; prev = tmp, tmp = NEXT(tmp)) {
if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun)
#ifdef SUPPORT_TAGS
&& (tag == tmp->tag)
......@@ -2679,7 +2689,7 @@ static void NCR5380_reselect (struct Scsi_Host *instance)
*/
static
int NCR5380_abort (Scsi_Cmnd *cmd)
int NCR5380_abort(Scsi_Cmnd *cmd)
{
struct Scsi_Host *instance = cmd->device->host;
SETUP_HOSTDATA(instance);
......@@ -2689,7 +2699,7 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
printk(KERN_NOTICE "scsi%d: aborting command\n", HOSTNO);
scsi_print_command(cmd);
NCR5380_print_status (instance);
NCR5380_print_status(instance);
local_irq_save(flags);
......@@ -2702,7 +2712,7 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
NCR5380_read(STATUS_REG));
#if 1
/*
/*
* Case 1 : If the command is the currently executing command,
* we'll set the aborted flag and return control so that
* information transfer routine can exit cleanly.
......@@ -2711,19 +2721,19 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
if (hostdata->connected == cmd) {
ABRT_PRINTK("scsi%d: aborting connected command\n", HOSTNO);
/*
/*
* We should perform BSY checking, and make sure we haven't slipped
* into BUS FREE.
*/
/* NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN); */
/*
/* NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN); */
/*
* Since we can't change phases until we've completed the current
* handshake, we have to source or sink a byte of data if the current
* phase is not MSGOUT.
*/
/*
/*
* Return control to the executing NCR drive so we can clear the
* aborted flag and get back into our main loop.
*/
......@@ -2733,13 +2743,13 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
hostdata->connected = NULL;
cmd->result = DID_ABORT << 16;
#ifdef SUPPORT_TAGS
cmd_free_tag( cmd );
cmd_free_tag(cmd);
#else
hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
#endif
local_irq_restore(flags);
cmd->scsi_done(cmd);
falcon_release_lock_if_possible( hostdata );
falcon_release_lock_if_possible(hostdata);
return SCSI_ABORT_SUCCESS;
} else {
/* local_irq_restore(flags); */
......@@ -2749,13 +2759,13 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
}
#endif
/*
/*
* Case 2 : If the command hasn't been issued yet, we simply remove it
* from the issue queue.
*/
for (prev = (Scsi_Cmnd **) &(hostdata->issue_queue),
tmp = (Scsi_Cmnd *) hostdata->issue_queue;
tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp) )
for (prev = (Scsi_Cmnd **)&(hostdata->issue_queue),
tmp = (Scsi_Cmnd *)hostdata->issue_queue;
tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) {
if (cmd == tmp) {
REMOVE(5, *prev, tmp, NEXT(tmp));
(*prev) = NEXT(tmp);
......@@ -2767,11 +2777,12 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
/* Tagged queuing note: no tag to free here, hasn't been assigned
* yet... */
tmp->scsi_done(tmp);
falcon_release_lock_if_possible( hostdata );
falcon_release_lock_if_possible(hostdata);
return SCSI_ABORT_SUCCESS;
}
}
/*
/*
* Case 3 : If any commands are connected, we're going to fail the abort
* and let the high level SCSI driver retry at a later time or
* issue a reset.
......@@ -2788,7 +2799,7 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
return SCSI_ABORT_SNOOZE;
}
/*
/*
* Case 4: If the command is currently disconnected from the bus, and
* there are no connected commands, we reconnect the I_T_L or
* I_T_L_Q nexus associated with it, go into message out, and send
......@@ -2814,22 +2825,22 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
*/
for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp;
tmp = NEXT(tmp))
tmp = NEXT(tmp)) {
if (cmd == tmp) {
local_irq_restore(flags);
ABRT_PRINTK("scsi%d: aborting disconnected command.\n", HOSTNO);
if (NCR5380_select (instance, cmd, (int) cmd->tag))
if (NCR5380_select(instance, cmd, (int)cmd->tag))
return SCSI_ABORT_BUSY;
ABRT_PRINTK("scsi%d: nexus reestablished.\n", HOSTNO);
do_abort (instance);
do_abort(instance);
local_irq_save(flags);
for (prev = (Scsi_Cmnd **) &(hostdata->disconnected_queue),
tmp = (Scsi_Cmnd *) hostdata->disconnected_queue;
tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp) )
for (prev = (Scsi_Cmnd **)&(hostdata->disconnected_queue),
tmp = (Scsi_Cmnd *)hostdata->disconnected_queue;
tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) {
if (cmd == tmp) {
REMOVE(5, *prev, tmp, NEXT(tmp));
*prev = NEXT(tmp);
......@@ -2840,18 +2851,20 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
* message (COMMAND_COMPLETE or the like)
*/
#ifdef SUPPORT_TAGS
cmd_free_tag( tmp );
cmd_free_tag(tmp);
#else
hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
#endif
local_irq_restore(flags);
tmp->scsi_done(tmp);
falcon_release_lock_if_possible( hostdata );
falcon_release_lock_if_possible(hostdata);
return SCSI_ABORT_SUCCESS;
}
}
}
}
/*
/*
* Case 5 : If we reached this point, the command was not found in any of
* the queues.
*
......@@ -2865,11 +2878,11 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully\n"
KERN_INFO " before abortion\n", HOSTNO);
/* Maybe it is sufficient just to release the ST-DMA lock... (if
/* Maybe it is sufficient just to release the ST-DMA lock... (if
* possible at all) At least, we should check if the lock could be
* released after the abort, in case it is kept due to some bug.
*/
falcon_release_lock_if_possible( hostdata );
falcon_release_lock_if_possible(hostdata);
return SCSI_ABORT_NOT_RUNNING;
}
......@@ -2884,7 +2897,7 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
*
*/
static int NCR5380_bus_reset( Scsi_Cmnd *cmd)
static int NCR5380_bus_reset(Scsi_Cmnd *cmd)
{
SETUP_HOSTDATA(cmd->device->host);
int i;
......@@ -2895,24 +2908,24 @@ static int NCR5380_bus_reset( Scsi_Cmnd *cmd)
if (!IS_A_TT() && !falcon_got_lock)
printk(KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_reset\n",
H_NO(cmd) );
H_NO(cmd));
NCR5380_print_status (cmd->device->host);
NCR5380_print_status(cmd->device->host);
/* get in phase */
NCR5380_write( TARGET_COMMAND_REG,
PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
NCR5380_write(TARGET_COMMAND_REG,
PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG)));
/* assert RST */
NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
udelay (40);
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST);
udelay(40);
/* reset NCR registers */
NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
NCR5380_write( MODE_REG, MR_BASE );
NCR5380_write( TARGET_COMMAND_REG, 0 );
NCR5380_write( SELECT_ENABLE_REG, 0 );
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_write(MODE_REG, MR_BASE);
NCR5380_write(TARGET_COMMAND_REG, 0);
NCR5380_write(SELECT_ENABLE_REG, 0);
/* ++roman: reset interrupt condition! otherwise no interrupts don't get
* through anymore ... */
(void)NCR5380_read( RESET_PARITY_INTERRUPT_REG );
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
#if 1 /* XXX Should now be done by midlevel code, but it's broken XXX */
/* XXX see below XXX */
......@@ -2932,7 +2945,7 @@ static int NCR5380_bus_reset( Scsi_Cmnd *cmd)
#ifdef SUPPORT_TAGS
free_all_tags();
#endif
for( i = 0; i < 8; ++i )
for (i = 0; i < 8; ++i)
hostdata->busy[i] = 0;
#ifdef REAL_DMA
hostdata->dma_len = 0;
......@@ -2947,21 +2960,21 @@ static int NCR5380_bus_reset( Scsi_Cmnd *cmd)
if ((cmd = connected)) {
ABRT_PRINTK("scsi%d: reset aborted a connected command\n", H_NO(cmd));
cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
cmd->scsi_done( cmd );
cmd->scsi_done(cmd);
}
for (i = 0; (cmd = disconnected_queue); ++i) {
disconnected_queue = NEXT(cmd);
NEXT(cmd) = NULL;
cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
cmd->scsi_done( cmd );
cmd->scsi_done(cmd);
}
if (i > 0)
ABRT_PRINTK("scsi: reset aborted %d disconnected command(s)\n", i);
/* The Falcon lock should be released after a reset...
/* The Falcon lock should be released after a reset...
*/
/* ++guenther: moved to atari_scsi_reset(), to prevent a race between
/* ++guenther: moved to atari_scsi_reset(), to prevent a race between
* unlocking and enabling dma interrupt.
*/
/* falcon_release_lock_if_possible( hostdata );*/
......@@ -3010,7 +3023,7 @@ static int NCR5380_bus_reset( Scsi_Cmnd *cmd)
#ifdef SUPPORT_TAGS
free_all_tags();
#endif
for( i = 0; i < 8; ++i )
for (i = 0; i < 8; ++i)
hostdata->busy[i] = 0;
#ifdef REAL_DMA
hostdata->dma_len = 0;
......@@ -3021,7 +3034,3 @@ static int NCR5380_bus_reset( Scsi_Cmnd *cmd)
return SCSI_RESET_WAKEUP | SCSI_RESET_BUS_RESET;
#endif /* 1 */
}
/* Local Variables: */
/* tab-width: 8 */
/* End: */
......@@ -186,38 +186,37 @@ static inline void DISABLE_IRQ(void)
/***************************** Prototypes *****************************/
#ifdef REAL_DMA
static int scsi_dma_is_ignored_buserr( unsigned char dma_stat );
static void atari_scsi_fetch_restbytes( void );
static long atari_scsi_dma_residual( struct Scsi_Host *instance );
static int falcon_classify_cmd( Scsi_Cmnd *cmd );
static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
Scsi_Cmnd *cmd, int write_flag );
static int scsi_dma_is_ignored_buserr(unsigned char dma_stat);
static void atari_scsi_fetch_restbytes(void);
static long atari_scsi_dma_residual(struct Scsi_Host *instance);
static int falcon_classify_cmd(Scsi_Cmnd *cmd);
static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
Scsi_Cmnd *cmd, int write_flag);
#endif
static irqreturn_t scsi_tt_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 *
hostdata );
static void falcon_get_lock( void );
static irqreturn_t scsi_tt_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 *hostdata);
static void falcon_get_lock(void);
#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
static void atari_scsi_reset_boot( void );
static void atari_scsi_reset_boot(void);
#endif
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 unsigned char atari_scsi_falcon_reg_read( unsigned char reg );
static void atari_scsi_falcon_reg_write( unsigned char reg, unsigned char value );
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 unsigned char atari_scsi_falcon_reg_read(unsigned char reg);
static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value);
/************************* End of Prototypes **************************/
static struct Scsi_Host *atari_scsi_host = NULL;
static unsigned char (*atari_scsi_reg_read)( unsigned char reg );
static void (*atari_scsi_reg_write)( unsigned char reg, unsigned char value );
static struct Scsi_Host *atari_scsi_host;
static unsigned char (*atari_scsi_reg_read)(unsigned char reg);
static void (*atari_scsi_reg_write)(unsigned char reg, unsigned char value);
#ifdef REAL_DMA
static unsigned long atari_dma_residual, atari_dma_startaddr;
static short atari_dma_active;
/* pointer to the dribble buffer */
static char *atari_dma_buffer = NULL;
static char *atari_dma_buffer;
/* precalculated physical address of the dribble buffer */
static unsigned long atari_dma_phys_buffer;
/* != 0 tells the Falcon int handler to copy data from the dribble buffer */
......@@ -233,7 +232,7 @@ static char *atari_dma_orig_addr;
static unsigned long atari_dma_stram_mask;
#define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0)
/* number of bytes to cut from a transfer to handle NCR overruns */
static int atari_read_overruns = 0;
static int atari_read_overruns;
#endif
static int setup_can_queue = -1;
......@@ -256,10 +255,10 @@ module_param(setup_hostid, int, 0);
#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;
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) {
......@@ -268,14 +267,13 @@ static int scsi_dma_is_ignored_buserr( unsigned char dma_stat )
* Check for this case:
*/
for( i = 0; i < m68k_num_memory; ++i ) {
end_addr = m68k_memory[i].addr +
m68k_memory[i].size;
for (i = 0; i < m68k_num_memory; ++i) {
end_addr = m68k_memory[i].addr + m68k_memory[i].size;
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 )
* 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.
*/
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;
/* Don't do anything if a NCR interrupt is pending. Probably it's just
* masked... */
if (atari_irq_pending( IRQ_TT_MFP_SCSI ))
if (atari_irq_pending(IRQ_TT_MFP_SCSI))
return;
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));
if (dma_stat & 0x80) {
if (!scsi_dma_is_ignored_buserr( dma_stat ))
printk( "SCSI DMA bus error -- bad DMA programming!\n" );
}
else {
if (!scsi_dma_is_ignored_buserr(dma_stat))
printk("SCSI DMA bus error -- bad DMA programming!\n");
} else {
/* Under normal circumstances we never should get to this point,
* since both interrupts are triggered simultaneously and the 5380
* int has higher priority. When this irq is handled, that DMA
* 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
......@@ -313,7 +310,7 @@ static void scsi_dma_buserr (int irq, void *dummy)
#endif
static irqreturn_t scsi_tt_intr (int irq, void *dummy)
static irqreturn_t scsi_tt_intr(int irq, void *dummy)
{
#ifdef REAL_DMA
int dma_stat;
......@@ -327,7 +324,7 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
* is that a bus error occurred...
*/
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",
SCSI_DMA_READ_P(dma_addr));
printk(KERN_CRIT "SCSI DMA bus error -- bad DMA programming!");
......@@ -344,8 +341,7 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
* data reg!
*/
if ((dma_stat & 0x02) && !(dma_stat & 0x40)) {
atari_dma_residual = HOSTDATA_DMALEN - (SCSI_DMA_READ_P( dma_addr ) -
atari_dma_startaddr);
atari_dma_residual = HOSTDATA_DMALEN - (SCSI_DMA_READ_P(dma_addr) - atari_dma_startaddr);
DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n",
atari_dma_residual);
......@@ -353,27 +349,29 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
if ((signed int)atari_dma_residual < 0)
atari_dma_residual = 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();
}
else {
/* There seems to be a nasty bug in some SCSI-DMA/NCR
combinations: If a target disconnects while a write
operation is going on, the address register of the
DMA may be a few bytes farer than it actually read.
This is probably due to DMA prefetching and a delay
between DMA and NCR. Experiments showed that the
dma_addr is 9 bytes to high, but this could vary.
The problem is, that the residual is thus calculated
wrong and the next transfer will start behind where
it should. So we round up the residual to the next
multiple of a sector size, if it isn't already a
multiple and the originally expected transfer size
was. The latter condition is there to ensure that
the correction is taken only for "real" data
transfers and not for, e.g., the parameters of some
other command. These shouldn't disconnect anyway.
} else {
/*
* There seems to be a nasty bug in some SCSI-DMA/NCR
* combinations: If a target disconnects while a write
* operation is going on, the address register of the
* DMA may be a few bytes farer than it actually read.
* This is probably due to DMA prefetching and a delay
* between DMA and NCR. Experiments showed that the
* dma_addr is 9 bytes to high, but this could vary.
* The problem is, that the residual is thus calculated
* wrong and the next transfer will start behind where
* it should. So we round up the residual to the next
* multiple of a sector size, if it isn't already a
* multiple and the originally expected transfer size
* was. The latter condition is there to ensure that
* the correction is taken only for "real" data
* transfers and not for, e.g., the parameters of some
* other command. These shouldn't disconnect anyway.
*/
if (atari_dma_residual & 0x1ff) {
DMA_PRINTK("SCSI DMA: DMA bug corrected, "
......@@ -399,13 +397,13 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
#if 0
/* To be sure the int is not masked */
atari_enable_irq( IRQ_TT_MFP_SCSI );
atari_enable_irq(IRQ_TT_MFP_SCSI);
#endif
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
int dma_stat;
......@@ -445,8 +443,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy)
atari_dma_residual = HOSTDATA_DMALEN - transferred;
DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n",
atari_dma_residual);
}
else
} else
atari_dma_residual = 0;
atari_dma_active = 0;
......@@ -467,7 +464,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy)
#ifdef REAL_DMA
static void atari_scsi_fetch_restbytes( void )
static void atari_scsi_fetch_restbytes(void)
{
int nr;
char *src, *dst;
......@@ -505,19 +502,17 @@ static int falcon_dont_release = 0;
* again (but others waiting longer more probably will win).
*/
static void
falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata)
{
unsigned long flags;
if (IS_A_TT()) return;
if (IS_A_TT())
return;
local_irq_save(flags);
if (falcon_got_lock &&
!hostdata->disconnected_queue &&
!hostdata->issue_queue &&
!hostdata->connected) {
if (falcon_got_lock && !hostdata->disconnected_queue &&
!hostdata->issue_queue && !hostdata->connected) {
if (falcon_dont_release) {
#if 0
......@@ -528,7 +523,7 @@ falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
}
falcon_got_lock = 0;
stdma_release();
wake_up( &falcon_fairness_wait );
wake_up(&falcon_fairness_wait);
}
local_irq_restore(flags);
......@@ -549,29 +544,29 @@ falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
* Complicated, complicated.... Sigh...
*/
static void falcon_get_lock( void )
static void falcon_get_lock(void)
{
unsigned long flags;
if (IS_A_TT()) return;
if (IS_A_TT())
return;
local_irq_save(flags);
while (!in_irq() && falcon_got_lock && stdma_others_waiting())
sleep_on( &falcon_fairness_wait );
sleep_on(&falcon_fairness_wait);
while (!falcon_got_lock) {
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) {
falcon_trying_lock = 1;
stdma_lock(scsi_falcon_intr, NULL);
falcon_got_lock = 1;
falcon_trying_lock = 0;
wake_up( &falcon_try_wait );
}
else {
sleep_on( &falcon_try_wait );
wake_up(&falcon_try_wait);
} else {
sleep_on(&falcon_try_wait);
}
}
......@@ -587,18 +582,18 @@ static void falcon_get_lock( void )
*/
#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();
* ++guenther: moved to NCR5380_queue_command() to prevent
* race condition, see there for an explanation.
*/
return( NCR5380_queue_command( cmd, done ) );
return NCR5380_queue_command(cmd, done);
}
#endif
int atari_scsi_detect (struct scsi_host_template *host)
int atari_scsi_detect(struct scsi_host_template *host)
{
static int called = 0;
struct Scsi_Host *instance;
......@@ -606,7 +601,7 @@ int atari_scsi_detect (struct scsi_host_template *host)
if (!MACH_IS_ATARI ||
(!ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(TT_SCSI)) ||
called)
return( 0 );
return 0;
host->proc_name = "Atari";
......@@ -655,32 +650,33 @@ int atari_scsi_detect (struct scsi_host_template *host)
!ATARIHW_PRESENT(EXTD_DMA) && m68k_num_memory > 1) {
atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI");
if (!atari_dma_buffer) {
printk( KERN_ERR "atari_scsi_detect: can't allocate ST-RAM "
"double buffer\n" );
return( 0 );
printk(KERN_ERR "atari_scsi_detect: can't allocate ST-RAM "
"double buffer\n");
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;
}
#endif
instance = scsi_register (host, sizeof (struct NCR5380_hostdata));
if(instance == NULL)
{
instance = scsi_register(host, sizeof(struct NCR5380_hostdata));
if (instance == NULL) {
atari_stram_free(atari_dma_buffer);
atari_dma_buffer = 0;
return 0;
}
atari_scsi_host = instance;
/* Set irq to 0, to avoid that the mid-level code disables our interrupt
/*
* Set irq to 0, to avoid that the mid-level code disables our interrupt
* during queue_command calls. This is completely unnecessary, and even
* worse causes bad problems on the Falcon, where the int is shared with
* IDE and floppy! */
* IDE and floppy!
*/
instance->irq = 0;
#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
atari_scsi_reset_boot();
#endif
NCR5380_init (instance, 0);
NCR5380_init(instance, 0);
if (IS_A_TT()) {
......@@ -729,8 +725,7 @@ int atari_scsi_detect (struct scsi_host_template *host)
atari_read_overruns = 4;
}
#endif /*REAL_DMA*/
}
else { /* ! IS_A_TT */
} else { /* ! IS_A_TT */
/* Nothing to do for the interrupt: the ST-DMA is initialized
* already by atari_init_INTS()
......@@ -756,19 +751,19 @@ int atari_scsi_detect (struct scsi_host_template *host)
setup_use_tagged_queuing ? "yes" : "no",
#endif
instance->hostt->this_id );
NCR5380_print_options (instance);
printk ("\n");
NCR5380_print_options(instance);
printk("\n");
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())
free_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr);
if (atari_dma_buffer)
atari_stram_free (atari_dma_buffer);
atari_stram_free(atari_dma_buffer);
return 1;
}
......@@ -781,7 +776,7 @@ void __init atari_scsi_setup(char *str, int *ints)
*/
if (ints[0] < 1) {
printk( "atari_scsi_setup: no arguments!\n" );
printk("atari_scsi_setup: no arguments!\n");
return;
}
......@@ -807,7 +802,7 @@ void __init atari_scsi_setup(char *str, int *ints)
if (ints[4] >= 0 && ints[4] <= 7)
setup_hostid = ints[4];
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
if (ints[0] >= 5) {
......@@ -829,13 +824,12 @@ int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
*/
/* And abort a maybe active DMA transfer */
if (IS_A_TT()) {
atari_turnoff_irq( IRQ_TT_MFP_SCSI );
atari_turnoff_irq(IRQ_TT_MFP_SCSI);
#ifdef REAL_DMA
tt_scsi_dma.dma_ctrl = 0;
#endif /* REAL_DMA */
}
else {
atari_turnoff_irq( IRQ_MFP_FSCSI );
} else {
atari_turnoff_irq(IRQ_MFP_FSCSI);
#ifdef REAL_DMA
st_dma.dma_mode_status = 0x90;
atari_dma_active = 0;
......@@ -847,15 +841,14 @@ int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
/* Re-enable ints */
if (IS_A_TT()) {
atari_turnon_irq( IRQ_TT_MFP_SCSI );
}
else {
atari_turnon_irq( IRQ_MFP_FSCSI );
atari_turnon_irq(IRQ_TT_MFP_SCSI);
} else {
atari_turnon_irq(IRQ_MFP_FSCSI);
}
if ((rv & SCSI_RESET_ACTION) == SCSI_RESET_SUCCESS)
falcon_release_lock_if_possible(hostdata);
return( rv );
return rv;
}
......@@ -869,30 +862,30 @@ static void __init atari_scsi_reset_boot(void)
* 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 */
NCR5380_write( TARGET_COMMAND_REG,
PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
NCR5380_write(TARGET_COMMAND_REG,
PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG)));
/* 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 */
udelay( 50 );
udelay(50);
/* reset RST and interrupt */
NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
NCR5380_read( RESET_PARITY_INTERRUPT_REG );
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_read(RESET_PARITY_INTERRUPT_REG);
end = jiffies + AFTER_RESET_DELAY;
while (time_before(jiffies, end))
barrier();
printk( " done\n" );
printk(" done\n");
}
#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... */
static const char string[] = "Atari native SCSI";
......@@ -902,10 +895,10 @@ const char * atari_scsi_info (struct Scsi_Host *host)
#if defined(REAL_DMA)
unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data,
unsigned long count, int dir )
unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance, void *data,
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, "
"dir = %d\n", instance->host_no, data, addr, count, dir);
......@@ -917,7 +910,7 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data,
* wanted address.
*/
if (dir)
memcpy( atari_dma_buffer, data, count );
memcpy(atari_dma_buffer, data, count);
else
atari_dma_orig_addr = data;
addr = atari_dma_phys_buffer;
......@@ -934,21 +927,20 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data,
* ++roman: For the Medusa, there's no need at all for that cache stuff,
* because the hardware does bus snooping (fine!).
*/
dma_cache_maintenance( addr, count, dir );
dma_cache_maintenance(addr, count, dir);
if (count == 0)
printk(KERN_NOTICE "SCSI warning: DMA programmed for 0 bytes !\n");
if (IS_A_TT()) {
tt_scsi_dma.dma_ctrl = dir;
SCSI_DMA_WRITE_P( dma_addr, addr );
SCSI_DMA_WRITE_P( dma_cnt, count );
SCSI_DMA_WRITE_P(dma_addr, addr);
SCSI_DMA_WRITE_P(dma_cnt, count);
tt_scsi_dma.dma_ctrl = dir | 2;
}
else { /* ! IS_A_TT */
} else { /* ! IS_A_TT */
/* set address */
SCSI_DMA_SETADR( addr );
SCSI_DMA_SETADR(addr);
/* toggle direction bit to clear FIFO and set DMA direction */
dir <<= 8;
......@@ -966,13 +958,13 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data,
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 )
#define CMD_SURELY_BYTE_MODE 1
#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];
if (opcode == READ_DEFECT_DATA || opcode == READ_LONG ||
opcode == READ_BUFFER)
return( CMD_SURELY_BYTE_MODE );
return CMD_SURELY_BYTE_MODE;
else if (opcode == READ_6 || opcode == READ_10 ||
opcode == 0xa8 /* READ_12 */ || opcode == READ_REVERSE ||
opcode == RECOVER_BUFFERED_DATA) {
......@@ -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
* set! */
if (cmd->device->type == TYPE_TAPE && !(cmd->cmnd[1] & 1))
return( CMD_SURELY_BYTE_MODE );
else
return( CMD_SURELY_BLOCK_MODE );
}
return CMD_SURELY_BYTE_MODE;
else
return( CMD_MODE_UNKNOWN );
return CMD_SURELY_BLOCK_MODE;
} else
return CMD_MODE_UNKNOWN;
}
......@@ -1012,19 +1003,18 @@ static int falcon_classify_cmd( Scsi_Cmnd *cmd )
* the overrun problem, so this question is academic :-)
*/
static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
Scsi_Cmnd *cmd,
int write_flag )
static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
Scsi_Cmnd *cmd, int write_flag)
{
unsigned long possible_len, limit;
#ifndef CONFIG_TT_DMA_EMUL
if (MACH_IS_HADES)
/* Hades has no SCSI DMA at all :-( Always force use of PIO */
return( 0 );
return 0;
#endif
if (IS_A_TT())
/* 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.
* 255*512 bytes, but this should be enough)
......@@ -1060,8 +1050,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
* this).
*/
possible_len = wanted_len;
}
else {
} else {
/* Read operations: if the wanted transfer length is not a multiple of
* 512, we cannot use DMA, since the ST-DMA cannot split transfers
* (no interrupt on DMA finished!)
......@@ -1071,7 +1060,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
else {
/* Now classify the command (see above) and decide whether it is
* allowed to do DMA at all */
switch( falcon_classify_cmd( cmd )) {
switch (falcon_classify_cmd(cmd)) {
case CMD_SURELY_BLOCK_MODE:
possible_len = wanted_len;
break;
......@@ -1089,7 +1078,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
}
/* 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;
if (possible_len > limit)
possible_len = limit;
......@@ -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 "
"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,
* 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;
}
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);
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.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