Initial commit of the Connect32 SCSI driver. This driver uses the esc

generic driver.
Currently this is only a polling driver.
This commit is contained in:
mark 1996-10-15 00:08:43 +00:00
parent b4c38ce254
commit c544086b51
3 changed files with 607 additions and 0 deletions

View File

@ -0,0 +1,452 @@
/* $NetBSD: cosc.c,v 1.1 1996/10/15 00:08:43 mark Exp $ */
/*
* Copyright (c) 1996 Mark Brinicombe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Mark Brinicombe
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* from: asc.c,v 1.8 1996/06/12 20:46:58 mark Exp
*/
/*
* Driver for the MCS Connect 32 SCSI 2 card with AM53C94 SCSI controller.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <scsi/scsi_all.h>
#include <scsi/scsiconf.h>
#include <machine/bootconfig.h>
#include <machine/io.h>
#include <machine/irqhandler.h>
#include <machine/katelib.h>
#include <arm32/podulebus/podulebus.h>
#include <arm32/podulebus/escreg.h>
#include <arm32/podulebus/escvar.h>
#include <arm32/podulebus/coscreg.h>
#include <arm32/podulebus/coscvar.h>
#include <arm32/podulebus/podules.h>
void coscattach __P((struct device *, struct device *, void *));
int coscmatch __P((struct device *, void *, void *));
int cosc_scsicmd __P((struct scsi_xfer *));
struct scsi_adapter cosc_scsiswitch = {
cosc_scsicmd, /* Eventually call esc_scsicmd directly */
esc_minphys,
0, /* no lun support */
0, /* no lun support */
};
struct scsi_device cosc_scsidev = {
NULL, /* use default error handler */
NULL, /* do not have a start function */
NULL, /* have no async handler */
NULL, /* Use default done routine */
};
struct cfattach cosc_ca = {
sizeof(struct cosc_softc), coscmatch, coscattach
};
struct cfdriver cosc_cd = {
NULL, "cosc", DV_DULL, NULL, 0
};
int cosc_intr __P((struct esc_softc *dev));
int cosc_setup_dma __P((struct esc_softc *sc, void *ptr, int len,
int mode));
int cosc_build_dma_chain __P((struct esc_softc *sc,
struct esc_dma_chain *chain, void *p, int l));
int cosc_need_bump __P((struct esc_softc *sc, void *ptr, int len));
void cosc_led __P((struct esc_softc *sc, int mode));
#if COSC_POLL > 0
int cosc_poll = 1;
#endif
int
coscmatch(pdp, match, auxp)
struct device *pdp;
void *match, *auxp;
{
struct podule_attach_args *pa = (struct podule_attach_args *)auxp;
/* Look for the card */
if (matchpodule(pa, MANUFACTURER_MCS, PODULE_MCS_SCSI, -1) != 0)
return(1);
/* Old versions of the ROM on this card could have the wrong ID */
if (matchpodule(pa, MANUFACTURER_ACORN, PODULE_ACORN_SCSI, -1) == 0)
return(0);
if (strncmp(pa->pa_podule->description, "MCS", 3) != 0)
return(0);
return(1);
}
static int dummy[6];
void
coscattach(pdp, dp, auxp)
struct device *pdp, *dp;
void *auxp;
{
struct cosc_softc *sc = (struct cosc_softc *)dp;
struct podule_attach_args *pa;
cosc_regmap_p rp = &sc->sc_regmap;
vu_char *esc;
pa = (struct podule_attach_args *)auxp;
if (pa->pa_podule_number == -1)
panic("Podule has disappeared !");
sc->sc_podule_number = pa->pa_podule_number;
sc->sc_podule = pa->pa_podule;
podules[sc->sc_podule_number].attached = 1;
if (pa->pa_podule->manufacturer == MANUFACTURER_ACORN
&& pa->pa_podule->product == PODULE_ACORN_SCSI)
printf(" Faulty expansion card identity\n");
sc->sc_iobase = (vu_char *)sc->sc_podule->fast_base;
/* Select page zero (so we can see the config info) */
sc->sc_iobase[COSC_PAGE_REGISTER] = 0;
rp->chipreset = (vu_char *)&dummy[0];
rp->inten = (vu_char *)&dummy[1];
rp->status = (vu_char *)&dummy[2];
rp->term = &sc->sc_iobase[COSC_TERMINATION_CONTROL];
rp->led = (vu_char *)&dummy[4];
esc = &sc->sc_iobase[COSC_ESCOFFSET_BASE];
rp->esc.esc_tc_low = &esc[COSC_ESCOFFSET_TCL];
rp->esc.esc_tc_mid = &esc[COSC_ESCOFFSET_TCM];
rp->esc.esc_fifo = &esc[COSC_ESCOFFSET_FIFO];
rp->esc.esc_command = &esc[COSC_ESCOFFSET_COMMAND];
rp->esc.esc_dest_id = &esc[COSC_ESCOFFSET_DESTID];
rp->esc.esc_timeout = &esc[COSC_ESCOFFSET_TIMEOUT];
rp->esc.esc_syncper = &esc[COSC_ESCOFFSET_PERIOD];
rp->esc.esc_syncoff = &esc[COSC_ESCOFFSET_OFFSET];
rp->esc.esc_config1 = &esc[COSC_ESCOFFSET_CONFIG1];
rp->esc.esc_clkconv = &esc[COSC_ESCOFFSET_CLOCKCONV];
rp->esc.esc_test = &esc[COSC_ESCOFFSET_TEST];
rp->esc.esc_config2 = &esc[COSC_ESCOFFSET_CONFIG2];
rp->esc.esc_config3 = &esc[COSC_ESCOFFSET_CONFIG3];
rp->esc.esc_config4 = &esc[COSC_ESCOFFSET_CONFIG4];
rp->esc.esc_tc_high = &esc[COSC_ESCOFFSET_TCH];
rp->esc.esc_fifo_bot = &esc[COSC_ESCOFFSET_FIFOBOTTOM];
*rp->esc.esc_command = ESC_CMD_RESET_CHIP;
delay(1000);
*rp->esc.esc_command = ESC_CMD_NOP;
/* See if we recognise the controller */
switch (*rp->esc.esc_tc_high) {
case 0x12:
printf(" AM53CF94");
break;
default:
printf(" Unknown controller (%02x)", *rp->esc.esc_tc_high);
break;
}
/* Set termination power */
if (sc->sc_iobase[COSC_CONFIG_TERMINATION] & COSC_CONFIG_TERMINATION_ON) {
printf(" termpwr on");
sc->sc_iobase[COSC_TERMINATION_CONTROL] = COSC_TERMINATION_ON;
} else {
printf(" termpwr off");
sc->sc_iobase[COSC_TERMINATION_CONTROL] = COSC_TERMINATION_OFF;
}
/* Don't know what this is for */
{
int byte;
int loop;
byte = sc->sc_iobase[COSC_REGISTER_01];
byte = 0;
for (loop = 0; loop < 8; ++loop) {
if (sc->sc_iobase[COSC_REGISTER_00] & 0x01)
byte |= (1 << loop);
}
printf(" byte=%02x", byte);
}
/*
* Control register 4 is an AMD special (not on FAS216)
*
* The powerdown and glitch eater facilities could be useful
* Use the podule configuration for this register
*/
sc->sc_softc.sc_config4 = sc->sc_iobase[COSC_CONFIG_CONTROL_REG4];
sc->sc_softc.sc_esc = (esc_regmap_p)rp;
/* sc->sc_softc.sc_spec = &sc->sc_specific;*/
sc->sc_softc.sc_led = cosc_led;
sc->sc_softc.sc_setup_dma = cosc_setup_dma;
sc->sc_softc.sc_build_dma_chain = cosc_build_dma_chain;
sc->sc_softc.sc_need_bump = cosc_need_bump;
sc->sc_softc.sc_clock_freq = 40; /* Connect32 runs at 40MHz */
sc->sc_softc.sc_timeout = 250; /* Set default timeout to 250ms */
sc->sc_softc.sc_config_flags = ESC_NO_DMA;
sc->sc_softc.sc_host_id = sc->sc_iobase[COSC_CONFIG_CONTROL_REG1] & ESC_DEST_ID_MASK;
printf(" hostid=%d", sc->sc_softc.sc_host_id);
#if COSC_POLL > 0
if (boot_args) {
char *ptr;
ptr = strstr(boot_args, "nocoscpoll");
if (ptr)
cosc_poll = 0;
}
if (cosc_poll)
printf(" polling");
#endif
sc->sc_softc.sc_bump_sz = NBPG;
sc->sc_softc.sc_bump_pa = 0x0;
escinitialize((struct esc_softc *)sc);
sc->sc_softc.sc_link.channel = SCSI_CHANNEL_ONLY_ONE;
sc->sc_softc.sc_link.adapter_softc = sc;
sc->sc_softc.sc_link.adapter_target = sc->sc_softc.sc_host_id;
sc->sc_softc.sc_link.adapter = &cosc_scsiswitch;
sc->sc_softc.sc_link.device = &cosc_scsidev;
sc->sc_softc.sc_link.openings = 1;
/* initialise the card */
#if 0
*rp->inten = (COSC_POLL?0:1);
*rp->led = 0;
#endif
sc->sc_softc.sc_ih.ih_func = cosc_intr;
sc->sc_softc.sc_ih.ih_arg = &sc->sc_softc;
sc->sc_softc.sc_ih.ih_level = IPL_BIO;
sc->sc_softc.sc_ih.ih_name = "scsi: cosc";
sc->sc_softc.sc_ih.ih_maskaddr = sc->sc_podule->irq_addr;
sc->sc_softc.sc_ih.ih_maskbits = sc->sc_podule->irq_mask;
#if COSC_POLL > 0
if (!cosc_poll)
#endif
if (irq_claim(IRQ_PODULE, &sc->sc_softc.sc_ih))
panic("%s: Cannot install IRQ handler\n", dp->dv_xname);
printf("\n");
/* attach all scsi units on us */
config_found(dp, &sc->sc_softc.sc_link, scsiprint);
}
/* Turn on/off led */
void
cosc_led(sc, mode)
struct esc_softc *sc;
int mode;
{
cosc_regmap_p rp;
rp = (cosc_regmap_p)sc->sc_esc;
if (mode) {
sc->sc_led_status++;
} else {
if (sc->sc_led_status)
sc->sc_led_status--;
}
/* *rp->led = (sc->sc_led_status?1:0);*/
}
int
cosc_intr(dev)
struct esc_softc *dev;
{
cosc_regmap_p rp;
int quickints;
rp = (cosc_regmap_p)dev->sc_esc;
printf("cosc_intr:%08x %02x\n", (u_int)rp->esc.esc_status, *rp->esc.esc_status);
if (*rp->esc.esc_status & ESC_STAT_INTERRUPT_PENDING) {
quickints = 16;
do {
dev->sc_status = *rp->esc.esc_status;
dev->sc_interrupt = *rp->esc.esc_interrupt;
if (dev->sc_interrupt & ESC_INT_RESELECTED) {
dev->sc_resel[0] = *rp->esc.esc_fifo;
dev->sc_resel[1] = *rp->esc.esc_fifo;
}
escintr(dev);
} while((*rp->esc.esc_status & ESC_STAT_INTERRUPT_PENDING)
&& --quickints);
}
return(0); /* Pass interrupt on down the chain */
}
/* Load transfer address into dma register */
void
cosc_set_dma_adr(sc, ptr)
struct esc_softc *sc;
void *ptr;
{
printf("cosc_set_dma_adr(sc = 0x%08x, ptr = 0x%08x)\n", (u_int)sc, (u_int)ptr);
return;
}
/* Set DMA transfer counter */
void
cosc_set_dma_tc(sc, len)
struct esc_softc *sc;
unsigned int len;
{
printf("cosc_set_dma_tc(sc, len = 0x%08x)", len);
/* Set the transfer size on the SCSI controller */
*sc->sc_esc->esc_tc_low = len; len >>= 8;
*sc->sc_esc->esc_tc_mid = len; len >>= 8;
*sc->sc_esc->esc_tc_high = len;
}
/* Set DMA mode */
void
cosc_set_dma_mode(sc, mode)
struct esc_softc *sc;
int mode;
{
printf("cosc_set_dma_mode(sc, mode = %d)", mode);
}
/* Initialize DMA for transfer */
int
cosc_setup_dma(sc, ptr, len, mode)
struct esc_softc *sc;
void *ptr;
int len;
int mode;
{
/* printf("cosc_setup_dma(sc, ptr = 0x%08x, len = 0x%08x, mode = 0x%08x)\n", (u_int)ptr, len, mode);*/
return(0);
}
/* Check if address and len is ok for DMA transfer */
int
cosc_need_bump(sc, ptr, len)
struct esc_softc *sc;
void *ptr;
int len;
{
int p;
p = (int)ptr & 0x03;
if (p) {
p = 4-p;
if (len < 256)
p = len;
}
return(p);
}
/* Interrupt driven routines */
int
cosc_build_dma_chain(sc, chain, p, l)
struct esc_softc *sc;
struct esc_dma_chain *chain;
void *p;
int l;
{
printf("cosc_build_dma_chain()\n");
return(0);
}
int
cosc_scsicmd(xs)
struct scsi_xfer *xs;
{
/* struct scsi_link *sc_link = xs->sc_link;*/
#if COSC_POLL > 0
if (cosc_poll)
xs->flags |= SCSI_POLL;
#endif
#if 0
if (sc_link->lun == 0)
printf("id=%d lun=%d cmdlen=%d datalen=%d opcode=%02x flags=%08x status=%02x blk=%02x %02x\n",
sc_link->target, sc_link->lun, xs->cmdlen, xs->datalen, xs->cmd->opcode,
xs->flags, xs->status, xs->cmd->bytes[0], xs->cmd->bytes[1]);
#endif
return(esc_scsicmd(xs));
}

View File

@ -0,0 +1,105 @@
/* $NetBSD: coscreg.h,v 1.1 1996/10/15 00:08:44 mark Exp $ */
/*
* Copyright (c) 1996 Mark Brinicombe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Mark Brinicombe
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _COSCREG_H_
#define _COSCREG_H_
#include <arm32/podulebus/escvar.h>
typedef volatile unsigned short vu_short;
typedef struct cosc_regmap {
esc_regmap_t esc;
vu_char *chipreset;
vu_char *inten;
vu_char *status;
vu_char *term;
vu_char *led;
} cosc_regmap_t;
typedef cosc_regmap_t *cosc_regmap_p;
/*
#define COSC_CONTROL_CHIPRESET
#define COSC_CONTROL_INTEN
#define COSC_STATUS
#define COSC_CONTROL_LED
*/
#define COSC_CONFIG_CONTROL_REG1 0x0ff0
#define COSC_CONFIG_CONTROL_REG1_MASK 0x97
#define COSC_CONFIG_CONTROL_REG2 0x0ff4
#define COSC_CONFIG_CONTROL_REG2_MASK 0x07
#define COSC_CONFIG_CONTROL_REG3 0x0ff8
#define COSC_CONFIG_CONTROL_REG3_MASK 0x83
#define COSC_CONFIG_CONTROL_REG4 0x0ffc
#define COSC_CONFIG_CONTROL_REG4_MASK 0xec
#define COSC_CONFIG_TERMINATION 0x1000
#define COSC_CONFIG_TERMINATION_ON 0x01
#define COSC_CONFIG_FIRST_SCANNED 0x1040 /* Used by RiscOS */
#define COSC_CONFIG_INC_FURTHER_PARTS 0x1048 /* Used by RiscOS */
#define COSC_CONFIG_SYNCH_MODE 0x1050
#define COSC_CONFIG_SYNCH_MODE_ON 0x01
#define COSC_CONFIG_SHUTDOWN 0x1054 /* Used by RiscOS */
#define COSC_CONFIG_SHUTDOWN_SPINDOWN 0x01 /* Used by RiscOS */
#define COSC_CONFIG_SHUTDOWN_EJECT 0x02 /* Used by RiscOS */
#define COSC_CONFIG_DELAY_REMOVABLE 0x105c /* Used by RiscOS */
#define COSC_CONFIG_DELAY_HARDDISC 0x1060 /* Used by RiscOS */
#define COSC_CONFIG_DELAY_BOOT 0x1064 /* Used by RiscOS */
#define COSC_CONFIG_CDROM 0x1068 /* Used by RiscOS */
#define COSC_TERMINATION_CONTROL 0x2600
#define COSC_TERMINATION_ON 0x00
#define COSC_TERMINATION_OFF 0x01
#define COSC_REGISTER_00 0x2800
#define COSC_REGISTER_01 0x2a00
#define COSC_PAGE_REGISTER 0x3000
#define COSC_ESCOFFSET_BASE 0x3c00
#define COSC_ESCOFFSET_TCL 0x0000
#define COSC_ESCOFFSET_TCM 0x0004
#define COSC_ESCOFFSET_FIFO 0x0008
#define COSC_ESCOFFSET_COMMAND 0x000c
#define COSC_ESCOFFSET_DESTID 0x0010
#define COSC_ESCOFFSET_TIMEOUT 0x0014
#define COSC_ESCOFFSET_PERIOD 0x0018
#define COSC_ESCOFFSET_OFFSET 0x001c
#define COSC_ESCOFFSET_CONFIG1 0x0020
#define COSC_ESCOFFSET_CLOCKCONV 0x0024
#define COSC_ESCOFFSET_TEST 0x0028
#define COSC_ESCOFFSET_CONFIG2 0x002c
#define COSC_ESCOFFSET_CONFIG3 0x0030
#define COSC_ESCOFFSET_CONFIG4 0x0034
#define COSC_ESCOFFSET_TCH 0x0038
#define COSC_ESCOFFSET_FIFOBOTTOM 0x003c
#endif /* _COSCREG_H_ */

View File

@ -0,0 +1,50 @@
/* $NetBSD: coscvar.h,v 1.1 1996/10/15 00:08:44 mark Exp $ */
/*
* Copyright (c) 1996 Mark Brinicombe
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Mark Brinicombe
* for the NetBSD Project.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _COSCVAR_H_
#define _COSCVAR_H_
#include <arm32/podulebus/escvar.h>
#include <arm32/podulebus/coscreg.h>
#define COSC_POLL 1
struct cosc_softc {
struct esc_softc sc_softc;
cosc_regmap_t sc_regmap;
vu_char *sc_iobase;
podule_t *sc_podule;
int sc_podule_number;
irqhandler_t sc_ih;
};
#endif /* _COCVAR_H_ */