Commit 0e1cb392 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Linus Torvalds

[PATCH] Sun-3 VME support

Add Sun-3 VME support (by Sam Creasey):
  - Added VME version of the Sun-3 NCR5380 scsi driver.
  - Modified the Sun-3 dvma routines to support VME.
  - Added sun3_map_test() -- uses the ex_table to trap faults on VME mappings
    in order to determine if a card is present.  This seems a little hackish to
    be, but:
      1) All changes are entirely within Sun3-only code paths,
      2) netbsd, sunos, and mach all use this mechanism for VME probes anyway.
parent 9d0f75b8
...@@ -1125,8 +1125,8 @@ config SUN3_SCSI ...@@ -1125,8 +1125,8 @@ config SUN3_SCSI
depends on SUN3 && SCSI depends on SUN3 && SCSI
help help
This option will enable support for the OBIO (onboard io) NCR5380 This option will enable support for the OBIO (onboard io) NCR5380
SCSI controller found in the Sun 3/50 and 3/60. Note that this SCSI controller found in the Sun 3/50 and 3/60, as well as for
driver does not provide support for VME SCSI boards. "Sun3" type VME scsi controllers also based on the NCR5380.
General Linux information on the Sun 3 series (now discontinued) General Linux information on the Sun 3 series (now discontinued)
is at <http://www.angelfire.com/ca2/tech68k/sun3.html>. is at <http://www.angelfire.com/ca2/tech68k/sun3.html>.
......
...@@ -117,3 +117,40 @@ void iounmap(void *addr) ...@@ -117,3 +117,40 @@ void iounmap(void *addr)
{ {
vfree((void *)(PAGE_MASK & (unsigned long)addr)); vfree((void *)(PAGE_MASK & (unsigned long)addr));
} }
/* sun3_map_test(addr, val) -- Reads a byte from addr, storing to val,
* trapping the potential read fault. Returns 0 if the access faulted,
* 1 on success.
*
* This function is primarily used to check addresses on the VME bus.
*
* Mucking with the page fault handler seems a little hackish to me, but
* SunOS, NetBSD, and Mach all implemented this check in such a manner,
* so I figure we're allowed.
*/
int sun3_map_test(unsigned long addr, char *val)
{
int ret = 0;
__asm__ __volatile__
(".globl _sun3_map_test_start\n"
"_sun3_map_test_start:\n"
"1: moveb (%2), (%0)\n"
" moveq #1, %1\n"
"2:\n"
".section .fixup,\"ax\"\n"
".even\n"
"3: moveq #0, %1\n"
" jmp 2b\n"
".previous\n"
".section __ex_table,\"a\"\n"
".align 4\n"
".long 1b,3b\n"
".previous\n"
".globl _sun3_map_test_end\n"
"_sun3_map_test_end:\n"
: "=a"(val), "=r"(ret)
: "a"(addr));
return ret;
}
...@@ -240,8 +240,14 @@ inline unsigned long dvma_map_align(unsigned long kaddr, int len, int align) ...@@ -240,8 +240,14 @@ inline unsigned long dvma_map_align(unsigned long kaddr, int len, int align)
void dvma_unmap(void *baddr) void dvma_unmap(void *baddr)
{ {
unsigned long addr;
free_baddr((unsigned long)baddr); addr = (unsigned long)baddr;
/* check if this is a vme mapping */
if(!(addr & 0x00f00000))
addr |= 0xf00000;
free_baddr(addr);
return; return;
......
...@@ -42,7 +42,7 @@ obj-$(CONFIG_OKTAGON_SCSI) += NCR53C9x.o oktagon_esp.o oktagon_io.o ...@@ -42,7 +42,7 @@ obj-$(CONFIG_OKTAGON_SCSI) += NCR53C9x.o oktagon_esp.o oktagon_io.o
obj-$(CONFIG_ATARI_SCSI) += atari_scsi.o obj-$(CONFIG_ATARI_SCSI) += atari_scsi.o
obj-$(CONFIG_MAC_SCSI) += mac_scsi.o obj-$(CONFIG_MAC_SCSI) += mac_scsi.o
obj-$(CONFIG_SCSI_MAC_ESP) += mac_esp.o NCR53C9x.o obj-$(CONFIG_SCSI_MAC_ESP) += mac_esp.o NCR53C9x.o
obj-$(CONFIG_SUN3_SCSI) += sun3_scsi.o obj-$(CONFIG_SUN3_SCSI) += sun3_scsi.o sun3_scsi_vme.o
obj-$(CONFIG_MVME16x_SCSI) += mvme16x.o 53c7xx.o obj-$(CONFIG_MVME16x_SCSI) += mvme16x.o 53c7xx.o
obj-$(CONFIG_BVME6000_SCSI) += bvme6000.o 53c7xx.o obj-$(CONFIG_BVME6000_SCSI) += bvme6000.o 53c7xx.o
obj-$(CONFIG_SCSI_SIM710) += sim710.o obj-$(CONFIG_SCSI_SIM710) += sim710.o
......
...@@ -617,11 +617,11 @@ static void NCR5380_print_phase(struct Scsi_Host *instance) ...@@ -617,11 +617,11 @@ static void NCR5380_print_phase(struct Scsi_Host *instance)
status = NCR5380_read(STATUS_REG); status = NCR5380_read(STATUS_REG);
if (!(status & SR_REQ)) if (!(status & SR_REQ))
printk(KERN_DEBUG "scsi%d: REQ not asserted, phase unknown.\n", HOSTNO); printk("scsi%d: REQ not asserted, phase unknown.\n", HOSTNO);
else { else {
for (i = 0; (phases[i].value != PHASE_UNKNOWN) && 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); printk("scsi%d: phase %s\n", HOSTNO, phases[i].name);
} }
} }
...@@ -755,10 +755,7 @@ static void NCR5380_print_status (struct Scsi_Host *instance) ...@@ -755,10 +755,7 @@ static void NCR5380_print_status (struct Scsi_Host *instance)
static static
char *lprint_Scsi_Cmnd (Scsi_Cmnd *cmd, char *pos, char *buffer, int length); char *lprint_Scsi_Cmnd (Scsi_Cmnd *cmd, char *pos, char *buffer, int length);
#ifndef NCR5380_proc_info static int NCR5380_proc_info (char *buffer, char **start, off_t offset,
static
#endif
int NCR5380_proc_info (char *buffer, char **start, off_t offset,
int length, int hostno, int inout) int length, int hostno, int inout)
{ {
char *pos = buffer; char *pos = buffer;
...@@ -914,10 +911,7 @@ static void __init NCR5380_init (struct Scsi_Host *instance, int flags) ...@@ -914,10 +911,7 @@ static void __init NCR5380_init (struct Scsi_Host *instance, int flags)
*/ */
/* Only make static if a wrapper function is used */ /* Only make static if a wrapper function is used */
#ifndef NCR5380_queue_command static int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
static
#endif
int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
{ {
SETUP_HOSTDATA(cmd->host); SETUP_HOSTDATA(cmd->host);
Scsi_Cmnd *tmp; Scsi_Cmnd *tmp;
...@@ -1319,11 +1313,14 @@ static void NCR5380_intr (int irq, void *dev_id, struct pt_regs *regs) ...@@ -1319,11 +1313,14 @@ static void NCR5380_intr (int irq, void *dev_id, struct pt_regs *regs)
{ {
/* MS: Ignore unknown phase mismatch interrupts (caused by EOP interrupt) */ /* MS: Ignore unknown phase mismatch interrupts (caused by EOP interrupt) */
if (basr & BASR_PHASE_MATCH) if (basr & BASR_PHASE_MATCH)
printk(KERN_NOTICE "scsi%d: unknown interrupt, " INT_PRINTK("scsi%d: unknown interrupt, "
"BASR 0x%x, MR 0x%x, SR 0x%x\n", "BASR 0x%x, MR 0x%x, SR 0x%x\n",
HOSTNO, basr, NCR5380_read(MODE_REG), HOSTNO, basr, NCR5380_read(MODE_REG),
NCR5380_read(STATUS_REG)); NCR5380_read(STATUS_REG));
(void) NCR5380_read(RESET_PARITY_INTERRUPT_REG); (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
#ifdef SUN3_SCSI_VME
dregs->csr |= CSR_DMA_ENABLE;
#endif
} }
} /* if !(SELECTION || PARITY) */ } /* if !(SELECTION || PARITY) */
} /* BASR & IRQ */ } /* BASR & IRQ */
...@@ -1333,6 +1330,9 @@ static void NCR5380_intr (int irq, void *dev_id, struct pt_regs *regs) ...@@ -1333,6 +1330,9 @@ static void NCR5380_intr (int irq, void *dev_id, struct pt_regs *regs)
"BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr, "BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr,
NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG)); NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG));
(void) NCR5380_read(RESET_PARITY_INTERRUPT_REG); (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
#ifdef SUN3_SCSI_VME
dregs->csr |= CSR_DMA_ENABLE;
#endif
} }
if (!done) { if (!done) {
...@@ -1695,7 +1695,9 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag) ...@@ -1695,7 +1695,9 @@ static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
#ifndef SUPPORT_TAGS #ifndef SUPPORT_TAGS
hostdata->busy[cmd->target] |= (1 << cmd->lun); hostdata->busy[cmd->target] |= (1 << cmd->lun);
#endif #endif
#ifdef SUN3_SCSI_VME
dregs->csr |= CSR_INTR;
#endif
initialize_SCp(cmd); initialize_SCp(cmd);
...@@ -1922,19 +1924,18 @@ static int NCR5380_transfer_dma( struct Scsi_Host *instance, ...@@ -1922,19 +1924,18 @@ static int NCR5380_transfer_dma( struct Scsi_Host *instance,
printk("scsi%d: transfer_dma without setup!\n", HOSTNO); printk("scsi%d: transfer_dma without setup!\n", HOSTNO);
BUG(); BUG();
} }
hostdata->dma_len = c; hostdata->dma_len = c;
DMA_PRINTK("scsi%d: initializing DMA for %s, %d bytes %s %p\n", DMA_PRINTK("scsi%d: initializing DMA for %s, %d bytes %s %p\n",
HOSTNO, (p & SR_IO) ? "reading" : "writing", HOSTNO, (p & SR_IO) ? "reading" : "writing",
c, (p & SR_IO) ? "to" : "from", d); c, (p & SR_IO) ? "to" : "from", *data);
/* netbsd turns off ints here, why not be safe and do it too */ /* netbsd turns off ints here, why not be safe and do it too */
save_flags(flags); save_flags(flags);
cli(); cli();
/* send start chain */ /* send start chain */
sun3_udc_write(UDC_CHN_START, UDC_CSR); sun3scsi_dma_start(c, *data);
if (p & SR_IO) { if (p & SR_IO) {
NCR5380_write(TARGET_COMMAND_REG, 1); NCR5380_write(TARGET_COMMAND_REG, 1);
...@@ -1950,6 +1951,10 @@ static int NCR5380_transfer_dma( struct Scsi_Host *instance, ...@@ -1950,6 +1951,10 @@ static int NCR5380_transfer_dma( struct Scsi_Host *instance,
NCR5380_write(START_DMA_SEND_REG, 0); NCR5380_write(START_DMA_SEND_REG, 0);
} }
#ifdef SUN3_SCSI_VME
dregs->csr |= CSR_DMA_ENABLE;
#endif
restore_flags(flags); restore_flags(flags);
sun3_dma_active = 1; sun3_dma_active = 1;
...@@ -1988,6 +1993,10 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance) ...@@ -1988,6 +1993,10 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
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; Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected;
#ifdef SUN3_SCSI_VME
dregs->csr |= CSR_INTR;
#endif
while (1) { while (1) {
tmp = NCR5380_read(STATUS_REG); tmp = NCR5380_read(STATUS_REG);
/* We only have a valid SCSI phase when REQ is asserted */ /* We only have a valid SCSI phase when REQ is asserted */
...@@ -2020,6 +2029,9 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance) ...@@ -2020,6 +2029,9 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
sun3_dma_setup_done = cmd; sun3_dma_setup_done = cmd;
} }
} }
#endif
#ifdef SUN3_SCSI_VME
dregs->csr |= CSR_INTR;
#endif #endif
} }
...@@ -2342,6 +2354,9 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance) ...@@ -2342,6 +2354,9 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
/* Wait for bus free to avoid nasty timeouts */ /* Wait for bus free to avoid nasty timeouts */
while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected) while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
barrier(); barrier();
#ifdef SUN3_SCSI_VME
dregs->csr |= CSR_DMA_ENABLE;
#endif
return; return;
/* /*
* The SCSI data pointer is *IMPLICITLY* saved on a disconnect * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
...@@ -2677,10 +2692,7 @@ static void NCR5380_reselect (struct Scsi_Host *instance) ...@@ -2677,10 +2692,7 @@ static void NCR5380_reselect (struct Scsi_Host *instance)
* called where the loop started in NCR5380_main(). * called where the loop started in NCR5380_main().
*/ */
#ifndef NCR5380_abort static int NCR5380_abort (Scsi_Cmnd *cmd)
static
#endif
int NCR5380_abort (Scsi_Cmnd *cmd)
{ {
struct Scsi_Host *instance = cmd->host; struct Scsi_Host *instance = cmd->host;
SETUP_HOSTDATA(instance); SETUP_HOSTDATA(instance);
...@@ -2874,7 +2886,7 @@ int NCR5380_abort (Scsi_Cmnd *cmd) ...@@ -2874,7 +2886,7 @@ int NCR5380_abort (Scsi_Cmnd *cmd)
* *
*/ */
int NCR5380_reset( Scsi_Cmnd *cmd, unsigned int reset_flags) static int NCR5380_reset( Scsi_Cmnd *cmd, unsigned int reset_flags)
{ {
SETUP_HOSTDATA(cmd->host); SETUP_HOSTDATA(cmd->host);
int i; int i;
......
...@@ -525,6 +525,14 @@ static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted, Scsi_Cmn ...@@ -525,6 +525,14 @@ static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted, Scsi_Cmn
return 0; return 0;
} }
static inline int sun3scsi_dma_start(unsigned long count, unsigned char *data)
{
sun3_udc_write(UDC_CHN_START, UDC_CSR);
return 0;
}
/* clean up after our dma is done */ /* clean up after our dma is done */
static int sun3scsi_dma_finish(int write_flag) static int sun3scsi_dma_finish(int write_flag)
{ {
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
#ifndef SUN3_NCR5380_H #ifndef SUN3_NCR5380_H
#define SUN3_NCR5380_H #define SUN3_NCR5380_H
#ifndef NULL
#define NULL 0
#endif
#define SUN3SCSI_PUBLIC_RELEASE 1 #define SUN3SCSI_PUBLIC_RELEASE 1
/* /*
...@@ -45,17 +50,19 @@ ...@@ -45,17 +50,19 @@
#define IRQ_SUN3_SCSI 2 #define IRQ_SUN3_SCSI 2
#define IOBASE_SUN3_SCSI 0x00140000 #define IOBASE_SUN3_SCSI 0x00140000
int sun3scsi_abort (Scsi_Cmnd *); #define IOBASE_SUN3_VMESCSI 0xff200000
int sun3scsi_detect (Scsi_Host_Template *);
int sun3scsi_release (struct Scsi_Host *);
const char *sun3scsi_info (struct Scsi_Host *);
int sun3scsi_reset(Scsi_Cmnd *, unsigned int);
int sun3scsi_queue_command (Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
int sun3scsi_proc_info (char *buffer, char **start, off_t offset,
int length, int hostno, int inout);
#ifndef NULL static int sun3scsi_abort (Scsi_Cmnd *);
#define NULL 0 static int sun3scsi_detect (Scsi_Host_Template *);
static const char *sun3scsi_info (struct Scsi_Host *);
static int sun3scsi_reset(Scsi_Cmnd *, unsigned int);
static int sun3scsi_queue_command (Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
static int sun3scsi_proc_info (char *buffer, char **start, off_t offset,
int length, int hostno, int inout);
#ifdef MODULE
static int sun3scsi_release (struct Scsi_Host *);
#else
#define sun3scsi_release NULL
#endif #endif
#ifndef CMD_PER_LUN #ifndef CMD_PER_LUN
...@@ -70,26 +77,36 @@ int sun3scsi_proc_info (char *buffer, char **start, off_t offset, ...@@ -70,26 +77,36 @@ int sun3scsi_proc_info (char *buffer, char **start, off_t offset,
#define SG_TABLESIZE SG_NONE #define SG_TABLESIZE SG_NONE
#endif #endif
#ifndef MAX_TAGS
#define MAX_TAGS 32
#endif
#ifndef USE_TAGGED_QUEUING #ifndef USE_TAGGED_QUEUING
#define USE_TAGGED_QUEUING 0 #define USE_TAGGED_QUEUING 1
#endif #endif
#include <scsi/scsicam.h> #include <scsi/scsicam.h>
#ifdef SUN3_SCSI_VME
#define SUN3_SCSI_NAME "Sun3 NCR5380 VME SCSI"
#else
#define SUN3_SCSI_NAME "Sun3 NCR5380 SCSI"
#endif
#define SUN3_NCR5380 { \ #define SUN3_NCR5380 { \
name: "Sun3 NCR5380 SCSI", \ .name = SUN3_SCSI_NAME, \
detect: sun3scsi_detect, \ .detect = sun3scsi_detect, \
release: sun3scsi_release, /* Release */ \ .release = sun3scsi_release, /* Release */ \
info: sun3scsi_info, \ .info = sun3scsi_info, \
queuecommand: sun3scsi_queue_command, \ .queuecommand = sun3scsi_queue_command, \
abort: sun3scsi_abort, \ .abort = sun3scsi_abort, \
reset: sun3scsi_reset, \ .reset = sun3scsi_reset, \
can_queue: CAN_QUEUE, /* can queue */ \ .can_queue = CAN_QUEUE, /* can queue */ \
this_id: 7, /* id */ \ .this_id = 7, /* id */ \
sg_tablesize: SG_ALL, /* sg_tablesize */ \ .sg_tablesize = SG_TABLESIZE, /* sg_tablesize */ \
cmd_per_lun: CMD_PER_LUN, /* cmd per lun */ \ .cmd_per_lun = CMD_PER_LUN, /* cmd per lun */ \
unchecked_isa_dma: 0, /* unchecked_isa_dma */ \ .unchecked_isa_dma = 0, /* unchecked_isa_dma */ \
use_clustering: DISABLE_CLUSTERING \ .use_clustering = DISABLE_CLUSTERING \
} }
#ifndef HOSTS_C #ifndef HOSTS_C
...@@ -124,13 +141,20 @@ use_clustering: DISABLE_CLUSTERING \ ...@@ -124,13 +141,20 @@ use_clustering: DISABLE_CLUSTERING \
/* additional registers - mainly DMA control regs */ /* additional registers - mainly DMA control regs */
/* these start at regbase + 8 -- directly after the NCR regs */ /* these start at regbase + 8 -- directly after the NCR regs */
struct sun3_dma_regs { struct sun3_dma_regs {
unsigned short vmeregs[4]; /* unimpl vme stuff */ unsigned short dma_addr_hi; /* vme only */
unsigned short udc_data; /* udc dma data reg */ unsigned short dma_addr_lo; /* vme only */
unsigned short udc_addr; /* uda dma addr reg */ unsigned short dma_count_hi; /* vme only */
unsigned short dma_count_lo; /* vme only */
unsigned short udc_data; /* udc dma data reg (obio only) */
unsigned short udc_addr; /* uda dma addr reg (obio only) */
unsigned short fifo_data; /* fifo data reg, holds extra byte on unsigned short fifo_data; /* fifo data reg, holds extra byte on
odd dma reads */ odd dma reads */
unsigned short fifo_count; unsigned short fifo_count;
unsigned short csr; /* control/status reg */ unsigned short csr; /* control/status reg */
unsigned short bpack_hi; /* vme only */
unsigned short bpack_lo; /* vme only */
unsigned short ivect; /* vme only */
unsigned short fifo_count_hi; /* vme only */
}; };
/* ucd chip specific regs - live in dvma space */ /* ucd chip specific regs - live in dvma space */
...@@ -179,11 +203,21 @@ struct sun3_udc_regs { ...@@ -179,11 +203,21 @@ struct sun3_udc_regs {
#define CSR_SDB_INT 0x200 /* sbc interrupt pending */ #define CSR_SDB_INT 0x200 /* sbc interrupt pending */
#define CSR_DMA_INT 0x100 /* dma interrupt pending */ #define CSR_DMA_INT 0x100 /* dma interrupt pending */
#define CSR_LEFT 0xc0
#define CSR_LEFT_3 0xc0
#define CSR_LEFT_2 0x80
#define CSR_LEFT_1 0x40
#define CSR_PACK_ENABLE 0x20
#define CSR_DMA_ENABLE 0x10
#define CSR_SEND 0x8 /* 1 = send 0 = recv */ #define CSR_SEND 0x8 /* 1 = send 0 = recv */
#define CSR_FIFO 0x2 /* reset fifo */ #define CSR_FIFO 0x2 /* reset fifo */
#define CSR_INTR 0x4 /* interrupt enable */ #define CSR_INTR 0x4 /* interrupt enable */
#define CSR_SCSI 0x1 #define CSR_SCSI 0x1
#define VME_DATA24 0x3d00
// debugging printk's, taken from atari_scsi.h // debugging printk's, taken from atari_scsi.h
/* Debugging printk definitions: /* Debugging printk definitions:
* *
...@@ -365,8 +399,6 @@ struct sun3_udc_regs { ...@@ -365,8 +399,6 @@ struct sun3_udc_regs {
#define NCR_PRINT_STATUS(mask) \ #define NCR_PRINT_STATUS(mask) \
((NDEBUG & (mask)) ? NCR5380_print_status(instance) : (void)0) ((NDEBUG & (mask)) ? NCR5380_print_status(instance) : (void)0)
#define NDEBUG_ANY 0xffffffff
#endif /* ndef HOSTS_C */ #endif /* ndef HOSTS_C */
......
/*
* Sun3 SCSI stuff by Erik Verbruggen (erik@bigmama.xtdnet.nl)
*
* Sun3 DMA routines added by Sam Creasey (sammy@sammy.net)
*
* VME support added by Sam Creasey
*
* Adapted from sun3_scsi.c -- see there for other headers
*
* TODO: modify this driver to support multiple Sun3 SCSI VME boards
*
*/
#define AUTOSENSE
#include <linux/types.h>
#include <linux/stddef.h>
#include <linux/ctype.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#include <linux/init.h>
#include <linux/blk.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/sun3ints.h>
#include <asm/dvma.h>
#include <asm/idprom.h>
#include <asm/machines.h>
#define SUN3_SCSI_VME
#undef SUN3_SCSI_DEBUG
/* dma on! */
#define REAL_DMA
#include "scsi.h"
#include "hosts.h"
#include "sun3_scsi.h"
#include "NCR5380.h"
extern int sun3_map_test(unsigned long, char *);
#define USE_WRAPPER
/*#define RESET_BOOT */
#define DRIVER_SETUP
#define NDEBUG 0
/*
* BUG can be used to trigger a strange code-size related hang on 2.1 kernels
*/
#ifdef BUG
#undef RESET_BOOT
#undef DRIVER_SETUP
#endif
/* #define SUPPORT_TAGS */
//#define ENABLE_IRQ() enable_irq( SUN3_VEC_VMESCSI0 );
#define ENABLE_IRQ()
static void scsi_sun3_intr(int irq, void *dummy, struct pt_regs *fp);
static inline unsigned char sun3scsi_read(int reg);
static inline void sun3scsi_write(int reg, int value);
static int setup_can_queue = -1;
MODULE_PARM(setup_can_queue, "i");
static int setup_cmd_per_lun = -1;
MODULE_PARM(setup_cmd_per_lun, "i");
static int setup_sg_tablesize = -1;
MODULE_PARM(setup_sg_tablesize, "i");
#ifdef SUPPORT_TAGS
static int setup_use_tagged_queuing = -1;
MODULE_PARM(setup_use_tagged_queuing, "i");
#endif
static int setup_hostid = -1;
MODULE_PARM(setup_hostid, "i");
static Scsi_Cmnd *sun3_dma_setup_done = NULL;
#define AFTER_RESET_DELAY (HZ/2)
/* ms to wait after hitting dma regs */
#define SUN3_DMA_DELAY 10
/* dvma buffer to allocate -- 32k should hopefully be more than sufficient */
#define SUN3_DVMA_BUFSIZE 0xe000
/* minimum number of bytes to do dma on */
#define SUN3_DMA_MINSIZE 128
static volatile unsigned char *sun3_scsi_regp;
static volatile struct sun3_dma_regs *dregs;
#ifdef OLDDMA
static unsigned char *dmabuf = NULL; /* dma memory buffer */
#endif
static unsigned char *sun3_dma_orig_addr = NULL;
static unsigned long sun3_dma_orig_count = 0;
static int sun3_dma_active = 0;
static unsigned long last_residual = 0;
/*
* NCR 5380 register access functions
*/
static inline unsigned char sun3scsi_read(int reg)
{
return( sun3_scsi_regp[reg] );
}
static inline void sun3scsi_write(int reg, int value)
{
sun3_scsi_regp[reg] = value;
}
/*
* XXX: status debug
*/
static struct Scsi_Host *default_instance;
/*
* Function : int sun3scsi_detect(Scsi_Host_Template * tpnt)
*
* Purpose : initializes mac NCR5380 driver based on the
* command line / compile time port and irq definitions.
*
* Inputs : tpnt - template for this SCSI adapter.
*
* Returns : 1 if a host adapter was found, 0 if not.
*
*/
static int sun3scsi_detect(Scsi_Host_Template * tpnt)
{
unsigned long ioaddr, irq;
static int called = 0;
struct Scsi_Host *instance;
int i;
unsigned long addrs[3] = { IOBASE_SUN3_VMESCSI,
IOBASE_SUN3_VMESCSI + 0x4000,
0 };
unsigned long vecs[3] = { SUN3_VEC_VMESCSI0,
SUN3_VEC_VMESCSI1,
0 };
/* check that this machine has an onboard 5380 */
switch(idprom->id_machtype) {
case SM_SUN3|SM_3_160:
case SM_SUN3|SM_3_260:
break;
default:
return 0;
}
if(called)
return 0;
tpnt->proc_name = "Sun3 5380 VME SCSI";
/* setup variables */
tpnt->can_queue =
(setup_can_queue > 0) ? setup_can_queue : CAN_QUEUE;
tpnt->cmd_per_lun =
(setup_cmd_per_lun > 0) ? setup_cmd_per_lun : CMD_PER_LUN;
tpnt->sg_tablesize =
(setup_sg_tablesize >= 0) ? setup_sg_tablesize : SG_TABLESIZE;
if (setup_hostid >= 0)
tpnt->this_id = setup_hostid;
else {
/* use 7 as default */
tpnt->this_id = 7;
}
ioaddr = 0;
for(i = 0; addrs[i] != 0; i++) {
unsigned char x;
ioaddr = (unsigned long)sun3_ioremap(addrs[i], PAGE_SIZE,
SUN3_PAGE_TYPE_VME16);
irq = vecs[i];
sun3_scsi_regp = (unsigned char *)ioaddr;
dregs = (struct sun3_dma_regs *)(((unsigned char *)ioaddr) + 8);
if(sun3_map_test((unsigned long)dregs, &x)) {
unsigned short oldcsr;
oldcsr = dregs->csr;
dregs->csr = 0;
udelay(SUN3_DMA_DELAY);
if(dregs->csr == 0x1400)
break;
dregs->csr = oldcsr;
}
iounmap((void *)ioaddr);
ioaddr = 0;
}
if(!ioaddr)
return 0;
#ifdef SUPPORT_TAGS
if (setup_use_tagged_queuing < 0)
setup_use_tagged_queuing = USE_TAGGED_QUEUING;
#endif
instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
if(instance == NULL)
return 0;
default_instance = instance;
instance->io_port = (unsigned long) ioaddr;
instance->irq = irq;
NCR5380_init(instance, 0);
instance->n_io_port = 32;
((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0;
if (request_irq(instance->irq, scsi_sun3_intr,
0, "Sun3SCSI-5380VME", NULL)) {
#ifndef REAL_DMA
printk("scsi%d: IRQ%d not free, interrupts disabled\n",
instance->host_no, instance->irq);
instance->irq = IRQ_NONE;
#else
printk("scsi%d: IRQ%d not free, bailing out\n",
instance->host_no, instance->irq);
return 0;
#endif
}
printk("scsi%d: Sun3 5380 VME at port %lX irq", instance->host_no, instance->io_port);
if (instance->irq == IRQ_NONE)
printk ("s disabled");
else
printk (" %d", instance->irq);
printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
instance->can_queue, instance->cmd_per_lun,
SUN3SCSI_PUBLIC_RELEASE);
printk("\nscsi%d:", instance->host_no);
NCR5380_print_options(instance);
printk("\n");
dregs->csr = 0;
udelay(SUN3_DMA_DELAY);
dregs->csr = CSR_SCSI | CSR_FIFO | CSR_INTR;
udelay(SUN3_DMA_DELAY);
dregs->fifo_count = 0;
dregs->fifo_count_hi = 0;
dregs->dma_addr_hi = 0;
dregs->dma_addr_lo = 0;
dregs->dma_count_hi = 0;
dregs->dma_count_lo = 0;
dregs->ivect = VME_DATA24 | (instance->irq & 0xff);
called = 1;
#ifdef RESET_BOOT
sun3_scsi_reset_boot(instance);
#endif
return 1;
}
#ifdef MODULE
int sun3scsi_release (struct Scsi_Host *shpnt)
{
if (shpnt->irq != IRQ_NONE)
free_irq (shpnt->irq, NULL);
iounmap(sun3_scsi_regp);
return 0;
}
#endif
#ifdef RESET_BOOT
/*
* Our 'bus reset on boot' function
*/
static void sun3_scsi_reset_boot(struct Scsi_Host *instance)
{
unsigned long end;
NCR5380_local_declare();
NCR5380_setup(instance);
/*
* Do a SCSI reset to clean up the bus during initialization. No
* messing with the queues, interrupts, or locks necessary here.
*/
printk( "Sun3 SCSI: resetting the SCSI bus..." );
/* switch off SCSI IRQ - catch an interrupt without IRQ bit set else */
// sun3_disable_irq( IRQ_SUN3_SCSI );
/* get in phase */
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 );
/* The min. reset hold time is 25us, so 40us should be enough */
udelay( 50 );
/* reset RST and interrupt */
NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
NCR5380_read( RESET_PARITY_INTERRUPT_REG );
for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); )
barrier();
/* switch on SCSI IRQ again */
// sun3_enable_irq( IRQ_SUN3_SCSI );
printk( " done\n" );
}
#endif
static const char * sun3scsi_info (struct Scsi_Host *spnt) {
return "";
}
// safe bits for the CSR
#define CSR_GOOD 0x060f
static void scsi_sun3_intr(int irq, void *dummy, struct pt_regs *fp)
{
unsigned short csr = dregs->csr;
dregs->csr &= ~CSR_DMA_ENABLE;
#ifdef SUN3_SCSI_DEBUG
printk("scsi_intr csr %x\n", csr);
#endif
if(csr & ~CSR_GOOD) {
if(csr & CSR_DMA_BUSERR) {
printk("scsi%d: bus error in dma\n", default_instance->host_no);
#ifdef SUN3_SCSI_DEBUG
printk("scsi: residual %x count %x addr %p dmaaddr %x\n",
dregs->fifo_count,
dregs->dma_count_lo | (dregs->dma_count_hi << 16),
sun3_dma_orig_addr,
dregs->dma_addr_lo | (dregs->dma_addr_hi << 16));
#endif
}
if(csr & CSR_DMA_CONFLICT) {
printk("scsi%d: dma conflict\n", default_instance->host_no);
}
}
if(csr & (CSR_SDB_INT | CSR_DMA_INT))
NCR5380_intr(irq, dummy, fp);
}
/*
* Debug stuff - to be called on NMI, or sysrq key. Use at your own risk;
* reentering NCR5380_print_status seems to have ugly side effects
*/
/* this doesn't seem to get used at all -- sam */
#if 0
void sun3_sun3_debug (void)
{
unsigned long flags;
NCR5380_local_declare();
if (default_instance) {
save_flags(flags);
cli();
NCR5380_print_status(default_instance);
restore_flags(flags);
}
}
#endif
/* sun3scsi_dma_setup() -- initialize the dma controller for a read/write */
static unsigned long sun3scsi_dma_setup(void *data, unsigned long count, int write_flag)
{
void *addr;
if(sun3_dma_orig_addr != NULL)
dvma_unmap(sun3_dma_orig_addr);
// addr = sun3_dvma_page((unsigned long)data, (unsigned long)dmabuf);
addr = (void *)dvma_map_vme((unsigned long) data, count);
sun3_dma_orig_addr = addr;
sun3_dma_orig_count = count;
#ifdef SUN3_SCSI_DEBUG
printk("scsi: dma_setup addr %p count %x\n", addr, count);
#endif
// dregs->fifo_count = 0;
#if 0
/* reset fifo */
dregs->csr &= ~CSR_FIFO;
dregs->csr |= CSR_FIFO;
#endif
/* set direction */
if(write_flag)
dregs->csr |= CSR_SEND;
else
dregs->csr &= ~CSR_SEND;
/* reset fifo */
// dregs->csr &= ~CSR_FIFO;
// dregs->csr |= CSR_FIFO;
dregs->csr |= CSR_PACK_ENABLE;
dregs->dma_addr_hi = ((unsigned long)addr >> 16);
dregs->dma_addr_lo = ((unsigned long)addr & 0xffff);
dregs->dma_count_hi = 0;
dregs->dma_count_lo = 0;
dregs->fifo_count_hi = 0;
dregs->fifo_count = 0;
#ifdef SUN3_SCSI_DEBUG
printk("scsi: dma_setup done csr %x\n", dregs->csr);
#endif
return count;
}
static inline unsigned long sun3scsi_dma_residual(struct Scsi_Host *instance)
{
return last_residual;
}
static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted, Scsi_Cmnd *cmd,
int write_flag)
{
if(cmd->request->flags & REQ_CMD)
return wanted;
else
return 0;
}
static int sun3scsi_dma_start(unsigned long count, char *data)
{
unsigned short csr;
csr = dregs->csr;
#ifdef SUN3_SCSI_DEBUG
printk("scsi: dma_start data %p count %x csr %x fifo %x\n", data, count, csr, dregs->fifo_count);
#endif
dregs->dma_count_hi = (sun3_dma_orig_count >> 16);
dregs->dma_count_lo = (sun3_dma_orig_count & 0xffff);
dregs->fifo_count_hi = (sun3_dma_orig_count >> 16);
dregs->fifo_count = (sun3_dma_orig_count & 0xffff);
// if(!(csr & CSR_DMA_ENABLE))
// dregs->csr |= CSR_DMA_ENABLE;
return 0;
}
/* clean up after our dma is done */
static int sun3scsi_dma_finish(int write_flag)
{
unsigned short fifo;
int ret = 0;
sun3_dma_active = 0;
dregs->csr &= ~CSR_DMA_ENABLE;
fifo = dregs->fifo_count;
if(write_flag) {
if((fifo > 0) && (fifo < sun3_dma_orig_count))
fifo++;
}
last_residual = fifo;
#ifdef SUN3_SCSI_DEBUG
printk("scsi: residual %x total %x\n", fifo, sun3_dma_orig_count);
#endif
/* empty bytes from the fifo which didn't make it */
if((!write_flag) && (dregs->csr & CSR_LEFT)) {
unsigned char *vaddr;
#ifdef SUN3_SCSI_DEBUG
printk("scsi: got left over bytes\n");
#endif
vaddr = (unsigned char *)dvma_vmetov(sun3_dma_orig_addr);
vaddr += (sun3_dma_orig_count - fifo);
vaddr--;
switch(dregs->csr & CSR_LEFT) {
case CSR_LEFT_3:
*vaddr = (dregs->bpack_lo & 0xff00) >> 8;
vaddr--;
case CSR_LEFT_2:
*vaddr = (dregs->bpack_hi & 0x00ff);
vaddr--;
case CSR_LEFT_1:
*vaddr = (dregs->bpack_hi & 0xff00) >> 8;
break;
}
}
dvma_unmap(sun3_dma_orig_addr);
sun3_dma_orig_addr = NULL;
dregs->dma_addr_hi = 0;
dregs->dma_addr_lo = 0;
dregs->dma_count_hi = 0;
dregs->dma_count_lo = 0;
dregs->fifo_count = 0;
dregs->fifo_count_hi = 0;
dregs->csr &= ~CSR_SEND;
// dregs->csr |= CSR_DMA_ENABLE;
#if 0
/* reset fifo */
dregs->csr &= ~CSR_FIFO;
dregs->csr |= CSR_FIFO;
#endif
sun3_dma_setup_done = NULL;
return ret;
}
#include "sun3_NCR5380.c"
static Scsi_Host_Template driver_template = SUN3_NCR5380;
#include "scsi_module.c"
...@@ -22,7 +22,8 @@ extern int dvma_map_iommu(unsigned long kaddr, unsigned long baddr, ...@@ -22,7 +22,8 @@ extern int dvma_map_iommu(unsigned long kaddr, unsigned long baddr,
#define dvma_malloc(x) dvma_malloc_align(x, 0) #define dvma_malloc(x) dvma_malloc_align(x, 0)
#define dvma_map(x, y) dvma_map_align(x, y, 0) #define dvma_map(x, y) dvma_map_align(x, y, 0)
#define dvma_map_vme(x, y) (dvma_map(x, y) & 0xfffff)
#define dvma_map_align_vme(x, y, z) (dvma_map_align (x, y, z) & 0xfffff)
extern unsigned long dvma_map_align(unsigned long kaddr, int len, extern unsigned long dvma_map_align(unsigned long kaddr, int len,
int align); int align);
extern void *dvma_malloc_align(unsigned long len, unsigned long align); extern void *dvma_malloc_align(unsigned long len, unsigned long align);
...@@ -52,6 +53,8 @@ extern void dvma_free(void *vaddr); ...@@ -52,6 +53,8 @@ extern void dvma_free(void *vaddr);
/* virt <-> phys conversions */ /* virt <-> phys conversions */
#define dvma_vtop(x) ((unsigned long)(x) & 0xffffff) #define dvma_vtop(x) ((unsigned long)(x) & 0xffffff)
#define dvma_ptov(x) ((unsigned long)(x) | 0xf000000) #define dvma_ptov(x) ((unsigned long)(x) | 0xf000000)
#define dvma_vtovme(x) ((unsigned long)(x) & 0x00fffff)
#define dvma_vmetov(x) ((unsigned long)(x) | 0xff00000)
#define dvma_vtob(x) dvma_vtop(x) #define dvma_vtob(x) dvma_vtop(x)
#define dvma_btov(x) dvma_ptov(x) #define dvma_btov(x) dvma_ptov(x)
......
...@@ -39,5 +39,11 @@ extern int show_sun3_interrupts(struct seq_file *, void *); ...@@ -39,5 +39,11 @@ extern int show_sun3_interrupts(struct seq_file *, void *);
extern void sun3_process_int(int, struct pt_regs *); extern void sun3_process_int(int, struct pt_regs *);
extern volatile unsigned char* sun3_intreg; extern volatile unsigned char* sun3_intreg;
/* master list of VME vectors -- don't fuck with this */
#define SUN3_VEC_FLOPPY 0x40
#define SUN3_VEC_VMESCSI0 0x40
#define SUN3_VEC_VMESCSI1 0x41
#define SUN3_VEC_CG 0xA8
#endif /* SUN3INTS_H */ #endif /* SUN3INTS_H */
...@@ -164,6 +164,7 @@ extern __inline__ void sun3_put_context(unsigned char c) ...@@ -164,6 +164,7 @@ extern __inline__ void sun3_put_context(unsigned char c)
extern void *sun3_ioremap(unsigned long phys, unsigned long size, extern void *sun3_ioremap(unsigned long phys, unsigned long size,
unsigned long type); unsigned long type);
extern int sun3_map_test(unsigned long addr, char *val);
#endif /* !__ASSEMBLY__ */ #endif /* !__ASSEMBLY__ */
......
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