Home | History | Annotate | Line # | Download | only in podulebus
asc.c revision 1.7
      1 /*	$NetBSD: asc.c,v 1.7 2002/08/05 23:30:04 bjh21 Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001 Richard Earnshaw
      5  * All rights reserved.
      6  *
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  * 3. The name of the company nor the name of the author may be used to
     13  *    endorse or promote products derived from this software without specific
     14  *    prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  *
     28  *
     29  * Copyright (c) 1996 Mark Brinicombe
     30  * Copyright (c) 1982, 1990 The Regents of the University of California.
     31  * All rights reserved.
     32  *
     33  * Redistribution and use in source and binary forms, with or without
     34  * modification, are permitted provided that the following conditions
     35  * are met:
     36  * 1. Redistributions of source code must retain the above copyright
     37  *    notice, this list of conditions and the following disclaimer.
     38  * 2. Redistributions in binary form must reproduce the above copyright
     39  *    notice, this list of conditions and the following disclaimer in the
     40  *    documentation and/or other materials provided with the distribution.
     41  * 3. All advertising materials mentioning features or use of this software
     42  *    must display the following acknowledgement:
     43  *	This product includes software developed by the University of
     44  *	California, Berkeley and its contributors.
     45  * 4. Neither the name of the University nor the names of its contributors
     46  *    may be used to endorse or promote products derived from this software
     47  *    without specific prior written permission.
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  * SUCH DAMAGE.
     60  *
     61  *	from:ahsc.c
     62  */
     63 
     64 /*
     65  * Driver for the Acorn SCSI card using the SBIC (WD33C93A) generic driver
     66  *
     67  * Thanks to Acorn for supplying programming information on this card.
     68  */
     69 
     70 /* #define ASC_DMAMAP_DEBUG */
     71 /* #define DEBUG */
     72 
     73 #include "opt_ddb.h"
     74 
     75 #include <sys/param.h>
     76 
     77 __KERNEL_RCSID(0, "$NetBSD: asc.c,v 1.7 2002/08/05 23:30:04 bjh21 Exp $");
     78 
     79 #include <sys/systm.h>
     80 #include <sys/kernel.h>
     81 #include <sys/device.h>
     82 #include <sys/buf.h>
     83 
     84 #include <uvm/uvm_extern.h>
     85 
     86 #include <machine/bus.h>
     87 #include <machine/intr.h>
     88 #include <machine/bootconfig.h>		/* asc_poll */
     89 
     90 #include <dev/scsipi/scsi_all.h>
     91 #include <dev/scsipi/scsipi_all.h>
     92 #include <dev/scsipi/scsiconf.h>
     93 
     94 #include <arm/arm32/katelib.h>
     95 
     96 #include <dev/podulebus/podules.h>
     97 #include <dev/podulebus/powerromreg.h>
     98 
     99 #include <acorn32/podulebus/podulebus.h>
    100 #include <acorn32/podulebus/sbicreg.h>
    101 #include <acorn32/podulebus/sbicvar.h>
    102 #include <acorn32/podulebus/ascreg.h>
    103 #include <acorn32/podulebus/ascvar.h>
    104 
    105 void ascattach		(struct device *, struct device *, void *);
    106 int  ascmatch		(struct device *, struct cfdata *, void *);
    107 
    108 void asc_enintr		(struct sbic_softc *);
    109 
    110 int  asc_dmaok		(void *, bus_dma_tag_t, struct sbic_acb *);
    111 int  asc_dmasetup	(void *, bus_dma_tag_t, struct sbic_acb *, int);
    112 int  asc_dmanext	(void *, bus_dma_tag_t, struct sbic_acb *, int);
    113 void asc_dmastop	(void *, bus_dma_tag_t, struct sbic_acb *);
    114 void asc_dmafinish	(void *, bus_dma_tag_t, struct sbic_acb *);
    115 
    116 int  asc_intr		(void *);
    117 void asc_minphys	(struct buf *);
    118 
    119 void asc_dump		(void);
    120 
    121 #ifdef DEBUG
    122 int	asc_dmadebug = 0;
    123 #endif
    124 
    125 struct cfattach asc_ca = {
    126 	sizeof(struct asc_softc), ascmatch, ascattach
    127 };
    128 
    129 extern struct cfdriver asc_cd;
    130 
    131 u_long scsi_nosync;
    132 int shift_nosync;
    133 
    134 #if ASC_POLL > 0
    135 int asc_poll = 0;
    136 
    137 #endif
    138 
    139 int
    140 ascmatch(struct device *pdp, struct cfdata *cf, void *auxp)
    141 {
    142 	struct podule_attach_args *pa = (struct podule_attach_args *)auxp;
    143 
    144 	/* Look for the card */
    145 
    146 	/* Standard ROM, skipping the MCS card that used the same ID. */
    147 	if (pa->pa_product == PODULE_ACORN_SCSI &&
    148 	    strncmp(pa->pa_podule->description, "MCS", 3) != 0)
    149 		return 1;
    150 
    151 	/* PowerROM */
    152         if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
    153             podulebus_initloader(pa) == 0 &&
    154             podloader_callloader(pa, 0, 0) == PRID_ACORN_SCSI1)
    155                 return 1;
    156 
    157 	return 0;
    158 }
    159 
    160 void
    161 ascattach(struct device *pdp, struct device *dp, void *auxp)
    162 {
    163 	/* volatile struct sdmac *rp;*/
    164 	struct asc_softc *sc;
    165 	struct sbic_softc *sbic;
    166 	struct podule_attach_args *pa;
    167 
    168 	sc = (struct asc_softc *)dp;
    169 	pa = (struct podule_attach_args *)auxp;
    170 
    171 	if (pa->pa_podule_number == -1)
    172 		panic("Podule has disappeared !");
    173 
    174 	sc->sc_podule_number = pa->pa_podule_number;
    175 	sc->sc_podule = pa->pa_podule;
    176 	podules[sc->sc_podule_number].attached = 1;
    177 
    178 	sbic = &sc->sc_softc;
    179 
    180 	sbic->sc_enintr = asc_enintr;
    181 	sbic->sc_dmaok = asc_dmaok;
    182 	sbic->sc_dmasetup = asc_dmasetup;
    183 	sbic->sc_dmanext = asc_dmanext;
    184 	sbic->sc_dmastop = asc_dmastop;
    185 	sbic->sc_dmafinish = asc_dmafinish;
    186 
    187 	/* Map sbic */
    188 	sbic->sc_sbicp.sc_sbiciot = pa->pa_iot;
    189 	if (bus_space_map (sbic->sc_sbicp.sc_sbiciot,
    190 	    sc->sc_podule->mod_base + ASC_SBIC, ASC_SBIC_SPACE, 0,
    191 	    &sbic->sc_sbicp.sc_sbicioh))
    192 		panic("%s: Cannot map SBIC\n", dp->dv_xname);
    193 
    194 	sbic->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 143;
    195 
    196 	sbic->sc_adapter.adapt_dev = &sbic->sc_dev;
    197 	sbic->sc_adapter.adapt_nchannels = 1;
    198 	sbic->sc_adapter.adapt_openings = 7;
    199 	sbic->sc_adapter.adapt_max_periph = 1;
    200 	sbic->sc_adapter.adapt_ioctl = NULL;
    201 	sbic->sc_adapter.adapt_minphys = asc_minphys;
    202 	sbic->sc_adapter.adapt_request = sbic_scsi_request;
    203 
    204 	sbic->sc_channel.chan_adapter = &sbic->sc_adapter;
    205 	sbic->sc_channel.chan_bustype = &scsi_bustype;
    206 	sbic->sc_channel.chan_channel = 0;
    207 	sbic->sc_channel.chan_ntargets = 8;
    208 	sbic->sc_channel.chan_nluns = 8;
    209 	sbic->sc_channel.chan_id = 7;
    210 
    211 	/* Provide an override for the host id */
    212 	(void)get_bootconf_option(boot_args, "asc.hostid",
    213 	    BOOTOPT_TYPE_INT, &sbic->sc_channel.chan_id);
    214 
    215 	printf(": hostid=%d", sbic->sc_channel.chan_id);
    216 
    217 #if ASC_POLL > 0
    218         if (boot_args)
    219 		get_bootconf_option(boot_args, "ascpoll", BOOTOPT_TYPE_BOOLEAN,
    220 		    &asc_poll);
    221 
    222 	if (asc_poll) {
    223 		sbic->sc_adapter.adapt_flags |= SCSIPI_ADAPT_POLL_ONLY;
    224 		printf(" polling");
    225 	}
    226 #endif
    227 	printf("\n");
    228 
    229 	sc->sc_pagereg = sc->sc_podule->fast_base + ASC_PAGEREG;
    230         sc->sc_intstat = sc->sc_podule->fast_base + ASC_INTSTATUS;
    231 
    232 	/* Reset the card */
    233 
    234 	WriteByte(sc->sc_pagereg, 0x80);
    235 	DELAY(500000);
    236 	WriteByte(sc->sc_pagereg, 0x00);
    237 	DELAY(250000);
    238 
    239 	sbicinit(sbic);
    240 
    241 	/* If we are polling only, we don't need a interrupt handler.  */
    242 
    243 #ifdef ASC_POLL
    244 	if (!asc_poll)
    245 #endif
    246 	{
    247 		evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    248 		    dp->dv_xname, "intr");
    249 		sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO,
    250 		    asc_intr, sc, &sc->sc_intrcnt);
    251 		if (sc->sc_ih == NULL)
    252 			panic("%s: Cannot claim podule IRQ\n", dp->dv_xname);
    253 	}
    254 
    255 	/*
    256 	 * attach all scsi units on us
    257 	 */
    258 	config_found(dp, &sbic->sc_channel, scsiprint);
    259 }
    260 
    261 
    262 void
    263 asc_enintr(struct sbic_softc *sbicsc)
    264 {
    265 	struct asc_softc *sc = (struct asc_softc *)sbicsc;
    266 
    267 	sbicsc->sc_flags |= SBICF_INTR;
    268 	WriteByte(sc->sc_pagereg, 0x40);
    269 }
    270 
    271 int
    272 asc_dmaok (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb)
    273 {
    274 	return 0;
    275 }
    276 
    277 int
    278 asc_dmasetup (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb, int dir)
    279 {
    280 	printf("asc_dmasetup()");
    281 #ifdef DDB
    282 	Debugger();
    283 #else
    284 	panic("Hit a brick wall\n");
    285 #endif
    286 	return 0;
    287 }
    288 
    289 int
    290 asc_dmanext (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb, int dir)
    291 {
    292 	printf("asc_dmanext()");
    293 #ifdef DDB
    294 	Debugger();
    295 #else
    296 	panic("Hit a brick wall\n");
    297 #endif
    298 	return 0;
    299 }
    300 
    301 void
    302 asc_dmastop (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb)
    303 {
    304 	printf("asc_dmastop\n");
    305 }
    306 
    307 void
    308 asc_dmafinish (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb)
    309 {
    310 	printf("asc_dmafinish\n");
    311 }
    312 
    313 void
    314 asc_dump(void)
    315 {
    316 	int i;
    317 
    318 	for (i = 0; i < asc_cd.cd_ndevs; ++i)
    319 		if (asc_cd.cd_devs[i])
    320 			sbic_dump(asc_cd.cd_devs[i]);
    321 }
    322 
    323 int
    324 asc_intr(void *arg)
    325 {
    326 	struct asc_softc *sc = arg;
    327 	int intr;
    328 
    329 	/* printf("ascintr:");*/
    330        	intr = ReadByte(sc->sc_intstat);
    331 	/* printf("%02x\n", intr);*/
    332 
    333 	if (intr & IS_SBIC_IRQ)
    334 		sbicintr((struct sbic_softc *)sc);
    335 
    336 	return 0;	/* Pass interrupt on down the chain */
    337 }
    338 
    339 /*
    340  * limit the transfer as required.
    341  */
    342 void
    343 asc_minphys(struct buf *bp)
    344 {
    345 #if 0
    346 	/*
    347 	 * We must limit the DMA xfer size
    348 	 */
    349 	if (bp->b_bcount > MAX_DMA_LEN) {
    350 		printf("asc: Reducing dma length\n");
    351 		bp->b_bcount = MAX_DMA_LEN;
    352 	}
    353 #endif
    354 	minphys(bp);
    355 }
    356 
    357