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