Home | History | Annotate | Line # | Download | only in podulebus
csc.c revision 1.12
      1 /*	$NetBSD: csc.c,v 1.12 2003/07/14 22:48:26 lukem Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Scott Stevens.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Cumana SCSI-2 driver uses the SFAS216 generic driver
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: csc.c,v 1.12 2003/07/14 22:48:26 lukem Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/kernel.h>
     49 #include <sys/device.h>
     50 
     51 #include <uvm/uvm_extern.h>
     52 
     53 #include <dev/scsipi/scsi_all.h>
     54 #include <dev/scsipi/scsipi_all.h>
     55 #include <dev/scsipi/scsiconf.h>
     56 #include <machine/io.h>
     57 #include <machine/intr.h>
     58 #include <machine/bootconfig.h>
     59 #include <acorn32/podulebus/podulebus.h>
     60 #include <acorn32/podulebus/sfasreg.h>
     61 #include <acorn32/podulebus/sfasvar.h>
     62 #include <acorn32/podulebus/cscreg.h>
     63 #include <acorn32/podulebus/cscvar.h>
     64 #include <dev/podulebus/podules.h>
     65 #include <dev/podulebus/powerromreg.h>
     66 
     67 int  cscmatch(struct device *, struct cfdata *, void *);
     68 void cscattach(struct device *, struct device *, void *);
     69 
     70 CFATTACH_DECL(csc, sizeof(struct csc_softc),
     71     cscmatch, cscattach, NULL, NULL);
     72 
     73 int csc_intr(void *);
     74 int csc_setup_dma(void *, void *, int, int);
     75 int csc_build_dma_chain(void *, void *, void *, int);
     76 int csc_need_bump(void *, void *, int);
     77 void csc_led(void *, int);
     78 
     79 void csc_set_dma_adr(struct sfas_softc *, void *);
     80 void csc_set_dma_tc(struct sfas_softc *, unsigned int);
     81 void csc_set_dma_mode(struct sfas_softc *, int);
     82 
     83 /*
     84  * if we are a Cumana SCSI-2 card
     85  */
     86 int
     87 cscmatch(pdp, cf, auxp)
     88 	struct device	*pdp;
     89 	struct cfdata	*cf;
     90 	void		*auxp;
     91 {
     92 	struct podule_attach_args *pa = (struct podule_attach_args *)auxp;
     93 
     94 	/* Look for the card */
     95 	if (pa->pa_product == PODULE_CUMANA_SCSI2)
     96 		return 1;
     97 
     98 	/* PowerROM */
     99         if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
    100             podulebus_initloader(pa) == 0 &&
    101             podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI2)
    102                 return 1;
    103 
    104 	return 0;
    105 }
    106 
    107 void
    108 cscattach(pdp, dp, auxp)
    109 	struct device	*pdp;
    110 	struct device	*dp;
    111 	void		*auxp;
    112 {
    113 	struct csc_softc *sc = (struct csc_softc *)dp;
    114 	struct podule_attach_args  *pa;
    115 	csc_regmap_p	   rp = &sc->sc_regmap;
    116 	vu_char		  *fas;
    117 	int loop;
    118 
    119 	pa = (struct podule_attach_args *)auxp;
    120 
    121 	if (pa->pa_podule_number == -1)
    122 		panic("Podule has disappeared !");
    123 
    124 	sc->sc_specific.sc_podule_number = pa->pa_podule_number;
    125 	sc->sc_specific.sc_podule = pa->pa_podule;
    126 	sc->sc_specific.sc_iobase =
    127 	    (vu_char *)sc->sc_specific.sc_podule->mod_base;
    128 
    129 	rp->status0 = &sc->sc_specific.sc_iobase[CSC_STATUS0];
    130 	rp->alatch = &sc->sc_specific.sc_iobase[CSC_ALATCH];
    131 	rp->dack = (vu_short *)&sc->sc_specific.sc_iobase[CSC_DACK];
    132 	fas = &sc->sc_specific.sc_iobase[CSC_FAS_OFFSET_BASE];
    133 
    134 	rp->FAS216.sfas_tc_low	= &fas[CSC_FAS_OFFSET_TCL];
    135 	rp->FAS216.sfas_tc_mid	= &fas[CSC_FAS_OFFSET_TCM];
    136 	rp->FAS216.sfas_fifo	= &fas[CSC_FAS_OFFSET_FIFO];
    137 	rp->FAS216.sfas_command	= &fas[CSC_FAS_OFFSET_COMMAND];
    138 	rp->FAS216.sfas_dest_id	= &fas[CSC_FAS_OFFSET_DESTID];
    139 	rp->FAS216.sfas_timeout	= &fas[CSC_FAS_OFFSET_TIMEOUT];
    140 	rp->FAS216.sfas_syncper	= &fas[CSC_FAS_OFFSET_PERIOD];
    141 	rp->FAS216.sfas_syncoff	= &fas[CSC_FAS_OFFSET_OFFSET];
    142 	rp->FAS216.sfas_config1	= &fas[CSC_FAS_OFFSET_CONFIG1];
    143 	rp->FAS216.sfas_clkconv	= &fas[CSC_FAS_OFFSET_CLKCONV];
    144 	rp->FAS216.sfas_test	= &fas[CSC_FAS_OFFSET_TEST];
    145 	rp->FAS216.sfas_config2	= &fas[CSC_FAS_OFFSET_CONFIG2];
    146 	rp->FAS216.sfas_config3	= &fas[CSC_FAS_OFFSET_CONFIG3];
    147 	rp->FAS216.sfas_tc_high	= &fas[CSC_FAS_OFFSET_TCH];
    148 	rp->FAS216.sfas_fifo_bot = &fas[CSC_FAS_OFFSET_FIFOBOT];
    149 
    150 	sc->sc_softc.sc_fas	= (sfas_regmap_p)rp;
    151 	sc->sc_softc.sc_spec	= &sc->sc_specific;
    152 
    153 	sc->sc_softc.sc_led	= csc_led;
    154 
    155 	sc->sc_softc.sc_setup_dma	= csc_setup_dma;
    156 	sc->sc_softc.sc_build_dma_chain = csc_build_dma_chain;
    157 	sc->sc_softc.sc_need_bump	= csc_need_bump;
    158 
    159 	sc->sc_softc.sc_clock_freq   = 8;   /* Cumana runs at 8MHz */
    160 	sc->sc_softc.sc_timeout      = 250;  /* Set default timeout to 250ms */
    161 	sc->sc_softc.sc_config_flags = SFAS_NO_DMA /*| SFAS_NF_DEBUG*/;
    162 	sc->sc_softc.sc_host_id      = 7;    /* Should check the jumpers */
    163 
    164 	sc->sc_softc.sc_bump_sz = PAGE_SIZE;
    165 	sc->sc_softc.sc_bump_pa = 0x0;
    166 
    167 	sfasinitialize((struct sfas_softc *)sc);
    168 
    169 	sc->sc_softc.sc_adapter.adapt_dev = &sc->sc_softc.sc_dev;
    170 	sc->sc_softc.sc_adapter.adapt_nchannels = 1;
    171 	sc->sc_softc.sc_adapter.adapt_openings = 7;
    172 	sc->sc_softc.sc_adapter.adapt_max_periph = 1;
    173 	sc->sc_softc.sc_adapter.adapt_ioctl = NULL;
    174 	sc->sc_softc.sc_adapter.adapt_minphys = sfas_minphys;
    175 	sc->sc_softc.sc_adapter.adapt_request = sfas_scsi_request;
    176 
    177 	sc->sc_softc.sc_channel.chan_adapter = &sc->sc_softc.sc_adapter;
    178 	sc->sc_softc.sc_channel.chan_bustype = &scsi_bustype;
    179 	sc->sc_softc.sc_channel.chan_channel = 0;
    180 	sc->sc_softc.sc_channel.chan_ntargets = 8;
    181 	sc->sc_softc.sc_channel.chan_nluns = 8;
    182 	sc->sc_softc.sc_channel.chan_id = sc->sc_softc.sc_host_id;
    183 
    184 	/* Provide an override for the host id */
    185 	(void)get_bootconf_option(boot_args, "csc.hostid",
    186 	    BOOTOPT_TYPE_INT, &sc->sc_softc.sc_channel.chan_id);
    187 
    188 	printf(": host=%d", sc->sc_softc.sc_channel.chan_id);
    189 
    190 	/* initialise the alatch */
    191 	sc->sc_specific.sc_alatch_defs = (CSC_POLL?0:CSC_ALATCH_DEFS_INTEN);
    192 	for (loop = 0; loop < 8; loop ++) {
    193 	    if(loop != 3)
    194 		*rp->alatch = (loop << 1) |
    195 		    ((sc->sc_specific.sc_alatch_defs & (1 << loop))?1:0);
    196 	}
    197 
    198 #if CSC_POLL == 0
    199 	evcnt_attach_dynamic(&sc->sc_softc.sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    200 	    dp->dv_xname, "intr");
    201 	sc->sc_softc.sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO,
    202 	    csc_intr, &sc->sc_softc, &sc->sc_softc.sc_intrcnt);
    203 	if (sc->sc_softc.sc_ih == NULL)
    204 	    panic("%s: Cannot install IRQ handler", dp->dv_xname);
    205 #else
    206 	printf(" polling");
    207 	sc->sc_softc.sc_adapter.adapt_flags |= SCSIPI_ADAPT_POLL_ONLY;
    208 #endif
    209 	printf("\n");
    210 
    211 	/* attach all scsi units on us */
    212 	config_found(dp, &sc->sc_softc.sc_channel, scsiprint);
    213 }
    214 
    215 
    216 int
    217 csc_intr(arg)
    218 	void *arg;
    219 {
    220 	struct sfas_softc *dev = arg;
    221 	csc_regmap_p	      rp;
    222 	int		      quickints;
    223 
    224 	rp = (csc_regmap_p)dev->sc_fas;
    225 
    226 	if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) {
    227 		quickints = 16;
    228 		do {
    229 			dev->sc_status = *rp->FAS216.sfas_status;
    230 			dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
    231 
    232 			if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
    233 				dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
    234 				dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
    235 			}
    236 			sfasintr(dev);
    237 
    238 		} while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)
    239 			&& --quickints);
    240 	}
    241 
    242 	return(0);	/* Pass interrupt on down the chain */
    243 }
    244 
    245 /* Load transfer address into DMA register */
    246 void
    247 csc_set_dma_adr(sc, ptr)
    248 	struct sfas_softc *sc;
    249 	void		 *ptr;
    250 {
    251 	return;
    252 }
    253 
    254 /* Set DMA transfer counter */
    255 void
    256 csc_set_dma_tc(sc, len)
    257 	struct sfas_softc *sc;
    258 	unsigned int	  len;
    259 {
    260 	*sc->sc_fas->sfas_tc_low  = len; len >>= 8;
    261 	*sc->sc_fas->sfas_tc_mid  = len; len >>= 8;
    262 	*sc->sc_fas->sfas_tc_high = len;
    263 }
    264 
    265 /* Set DMA mode */
    266 void
    267 csc_set_dma_mode(sc, mode)
    268 	struct sfas_softc *sc;
    269 	int		  mode;
    270 {
    271 }
    272 
    273 /* Initialize DMA for transfer */
    274 int
    275 csc_setup_dma(sc, ptr, len, mode)
    276 	void	 *sc;
    277 	void	 *ptr;
    278 	int	  len;
    279 	int	  mode;
    280 {
    281 
    282 	return (0);
    283 }
    284 
    285 /* Check if address and len is ok for DMA transfer */
    286 int
    287 csc_need_bump(sc, ptr, len)
    288 	void	 *sc;
    289 	void	 *ptr;
    290 	int	  len;
    291 {
    292 	int	p;
    293 
    294 	p = (int)ptr & 0x03;
    295 
    296 	if (p) {
    297 		p = 4-p;
    298 
    299 		if (len < 256)
    300 			p = len;
    301 	}
    302 
    303 	return(p);
    304 }
    305 
    306 /* Interrupt driven routines */
    307 int
    308 csc_build_dma_chain(sc, chain, p, l)
    309 	void	*sc;
    310 	void	*chain;
    311 	void	*p;
    312 	int	 l;
    313 {
    314 	return(0);
    315 }
    316 
    317 /* Turn on/off led */
    318 void
    319 csc_led(v, mode)
    320 	void	 *v;
    321 	int	  mode;
    322 {
    323 	struct sfas_softc *sc = v;
    324 	csc_regmap_p		rp;
    325 
    326 	rp = (csc_regmap_p)sc->sc_fas;
    327 
    328 	if (mode) {
    329 		sc->sc_led_status++;
    330 	} else {
    331 		if (sc->sc_led_status)
    332 			sc->sc_led_status--;
    333 	}
    334 }
    335