Home | History | Annotate | Line # | Download | only in dev
wdsc.c revision 1.16
      1  1.16       scw /*	$NetBSD: wdsc.c,v 1.16 2000/02/26 14:31:35 scw Exp $	*/
      2   1.1     chuck 
      3   1.1     chuck /*
      4   1.1     chuck  * Copyright (c) 1996 Steve Woodford
      5   1.1     chuck  * Copyright (c) 1982, 1990 The Regents of the University of California.
      6   1.1     chuck  * All rights reserved.
      7   1.1     chuck  *
      8   1.1     chuck  * Redistribution and use in source and binary forms, with or without
      9   1.1     chuck  * modification, are permitted provided that the following conditions
     10   1.1     chuck  * are met:
     11   1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     12   1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     13   1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     15   1.1     chuck  *    documentation and/or other materials provided with the distribution.
     16   1.1     chuck  * 3. All advertising materials mentioning features or use of this software
     17   1.1     chuck  *    must display the following acknowledgement:
     18   1.1     chuck  *  This product includes software developed by the University of
     19   1.1     chuck  *  California, Berkeley and its contributors.
     20   1.1     chuck  * 4. Neither the name of the University nor the names of its contributors
     21   1.1     chuck  *    may be used to endorse or promote products derived from this software
     22   1.1     chuck  *    without specific prior written permission.
     23   1.1     chuck  *
     24   1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25   1.1     chuck  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26   1.1     chuck  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27   1.1     chuck  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28   1.1     chuck  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29   1.1     chuck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30   1.1     chuck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31   1.1     chuck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32   1.1     chuck  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33   1.1     chuck  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34   1.1     chuck  * SUCH DAMAGE.
     35   1.1     chuck  *
     36   1.1     chuck  *  @(#)wdsc.c
     37   1.1     chuck  */
     38   1.2     chuck 
     39   1.1     chuck #include <sys/param.h>
     40   1.1     chuck #include <sys/systm.h>
     41   1.1     chuck #include <sys/kernel.h>
     42   1.1     chuck #include <sys/device.h>
     43   1.2     chuck 
     44  1.10    bouyer #include <dev/scsipi/scsi_all.h>
     45  1.10    bouyer #include <dev/scsipi/scsipi_all.h>
     46  1.10    bouyer #include <dev/scsipi/scsiconf.h>
     47   1.2     chuck 
     48  1.16       scw #include <machine/cpu.h>
     49   1.3     chuck #include <machine/autoconf.h>
     50   1.3     chuck 
     51   1.2     chuck #include <mvme68k/dev/dmavar.h>
     52   1.1     chuck #include <mvme68k/dev/pccreg.h>
     53   1.2     chuck #include <mvme68k/dev/pccvar.h>
     54   1.1     chuck #include <mvme68k/dev/sbicreg.h>
     55   1.1     chuck #include <mvme68k/dev/sbicvar.h>
     56   1.1     chuck #include <mvme68k/dev/wdscreg.h>
     57   1.1     chuck 
     58   1.2     chuck void    wdsc_pcc_attach __P((struct device *, struct device *, void *));
     59   1.9       gwr int     wdsc_pcc_match  __P((struct device *, struct cfdata *, void *));
     60   1.1     chuck 
     61   1.1     chuck void    wdsc_enintr     __P((struct sbic_softc *));
     62   1.1     chuck int     wdsc_dmago      __P((struct sbic_softc *, char *, int, int));
     63   1.1     chuck int     wdsc_dmanext    __P((struct sbic_softc *));
     64   1.1     chuck void    wdsc_dmastop    __P((struct sbic_softc *));
     65   1.2     chuck int     wdsc_dmaintr    __P((void *));
     66   1.2     chuck int     wdsc_scsiintr   __P((void *));
     67   1.1     chuck 
     68  1.10    bouyer struct scsipi_device wdsc_scsidev = {
     69   1.1     chuck     NULL,       /* use default error handler */
     70   1.1     chuck     NULL,       /* do not have a start functio */
     71   1.1     chuck     NULL,       /* have no async handler */
     72   1.1     chuck     NULL,       /* Use default done routine */
     73   1.1     chuck };
     74   1.1     chuck 
     75   1.2     chuck struct cfattach wdsc_pcc_ca = {
     76   1.2     chuck 	sizeof(struct sbic_softc), wdsc_pcc_match, wdsc_pcc_attach
     77   1.1     chuck };
     78   1.1     chuck 
     79  1.11   thorpej extern struct cfdriver wdsc_cd;
     80   1.1     chuck 
     81   1.1     chuck 
     82   1.1     chuck /*
     83   1.1     chuck  * Match for SCSI devices on the onboard WD33C93 chip
     84   1.1     chuck  */
     85   1.1     chuck int
     86   1.9       gwr wdsc_pcc_match(pdp, cf, auxp)
     87   1.1     chuck     struct device *pdp;
     88   1.9       gwr 	struct cfdata *cf;
     89   1.9       gwr     void *auxp;
     90   1.1     chuck {
     91   1.2     chuck     struct pcc_attach_args *pa = auxp;
     92   1.2     chuck 
     93   1.2     chuck     if (strcmp(pa->pa_name, wdsc_cd.cd_name))
     94   1.2     chuck 	return (0);
     95   1.2     chuck 
     96   1.2     chuck     pa->pa_ipl = cf->pcccf_ipl;
     97   1.2     chuck     return (1);
     98   1.1     chuck }
     99   1.1     chuck 
    100   1.1     chuck /*
    101   1.1     chuck  * Attach the wdsc driver
    102   1.1     chuck  */
    103   1.1     chuck void
    104   1.2     chuck wdsc_pcc_attach(pdp, dp, auxp)
    105   1.1     chuck     struct device *pdp, *dp;
    106   1.1     chuck     void *auxp;
    107   1.1     chuck {
    108   1.1     chuck     struct sbic_softc   *sc = (struct sbic_softc *)dp;
    109   1.2     chuck     struct pcc_attach_args *pa = auxp;
    110   1.1     chuck     static int          attached = 0;
    111   1.3     chuck     int tmp;
    112   1.1     chuck 
    113   1.1     chuck     if ( attached )
    114   1.1     chuck         panic("wdsc: Driver already attached!");
    115   1.1     chuck 
    116   1.1     chuck     attached = 1;
    117   1.1     chuck 
    118   1.1     chuck     sc->sc_enintr  = wdsc_enintr;
    119   1.1     chuck     sc->sc_dmago   = wdsc_dmago;
    120   1.1     chuck     sc->sc_dmanext = wdsc_dmanext;
    121   1.1     chuck     sc->sc_dmastop = wdsc_dmastop;
    122   1.1     chuck     sc->sc_dmacmd  = 0;
    123   1.1     chuck 
    124  1.13   thorpej     sc->sc_adapter.scsipi_cmd = sbic_scsicmd;
    125  1.13   thorpej     sc->sc_adapter.scsipi_minphys = sbic_minphys;
    126  1.13   thorpej 
    127  1.10    bouyer     sc->sc_link.scsipi_scsi.channel        = SCSI_CHANNEL_ONLY_ONE;
    128   1.1     chuck     sc->sc_link.adapter_softc  = sc;
    129  1.10    bouyer     sc->sc_link.scsipi_scsi.adapter_target = 7;
    130  1.13   thorpej     sc->sc_link.adapter        = &sc->sc_adapter;
    131   1.1     chuck     sc->sc_link.device         = &wdsc_scsidev;
    132   1.1     chuck     sc->sc_link.openings       = 2;
    133  1.10    bouyer     sc->sc_link.scsipi_scsi.max_target     = 7;
    134  1.14    mjacob     sc->sc_link.scsipi_scsi.max_lun = 7;
    135  1.14    mjacob     sc->sc_link.type = BUS_SCSI;
    136   1.1     chuck 
    137  1.10    bouyer     printf(": WD33C93 SCSI, target %d\n",
    138  1.10    bouyer 		sc->sc_link.scsipi_scsi.adapter_target);
    139   1.1     chuck 
    140   1.1     chuck     sc->sc_cregs = (volatile void *)sys_pcc;
    141   1.2     chuck     sc->sc_sbicp = (sbic_regmap_p) PCC_VADDR(pa->pa_offset);
    142   1.1     chuck 
    143   1.1     chuck     /*
    144   1.1     chuck      * Eveything is a valid dma address.
    145   1.1     chuck      */
    146   1.1     chuck     sc->sc_dmamask = 0;
    147   1.1     chuck 
    148   1.1     chuck     /*
    149   1.1     chuck      * The onboard WD33C93 of the '147 is usually clocked at 10MHz...
    150   1.1     chuck      * (We use 10 times this for accuracy in later calculations)
    151   1.1     chuck      */
    152   1.1     chuck     sc->sc_clkfreq = 100;
    153   1.1     chuck 
    154   1.1     chuck     /*
    155   1.1     chuck      * Initialise the hardware
    156   1.1     chuck      */
    157   1.1     chuck     sbicinit(sc);
    158   1.1     chuck 
    159   1.1     chuck     /*
    160   1.1     chuck      * Fix up the interrupts
    161   1.1     chuck      */
    162   1.2     chuck     sc->sc_ipl = pa->pa_ipl & PCC_IMASK;
    163   1.1     chuck 
    164   1.1     chuck     sys_pcc->scsi_int = sc->sc_ipl | PCC_ICLEAR;
    165   1.1     chuck     sys_pcc->dma_int  = sc->sc_ipl | PCC_ICLEAR;
    166   1.1     chuck     sys_pcc->dma_csr  = 0;
    167   1.1     chuck 
    168   1.1     chuck     pccintr_establish(PCCV_SCSID, wdsc_dmaintr,  sc->sc_ipl, sc);
    169   1.1     chuck     pccintr_establish(PCCV_SCSIP, wdsc_scsiintr, sc->sc_ipl, sc);
    170   1.1     chuck 
    171   1.1     chuck     sys_pcc->scsi_int = sc->sc_ipl | PCC_IENABLE | PCC_ICLEAR;
    172   1.1     chuck 
    173   1.1     chuck     /*
    174   1.3     chuck      * Attach all scsi units on us, watching for boot device
    175   1.3     chuck      * (see dk_establish).
    176   1.1     chuck      */
    177   1.3     chuck     tmp = bootpart;
    178   1.3     chuck     if (PCC_PADDR(pa->pa_offset) != bootaddr)
    179   1.3     chuck 	bootpart = -1;		/* invalid flag to dk_establish */
    180   1.5       cgd     (void)config_found(dp, &sc->sc_link, scsiprint);
    181   1.3     chuck     bootpart = tmp;		/* restore old value */
    182   1.1     chuck }
    183   1.1     chuck 
    184   1.1     chuck /*
    185   1.1     chuck  * Enable DMA interrupts
    186   1.1     chuck  */
    187   1.1     chuck void
    188   1.1     chuck wdsc_enintr(dev)
    189   1.1     chuck     struct sbic_softc *dev;
    190   1.1     chuck {
    191   1.1     chuck     volatile struct pcc *pc = dev->sc_cregs;
    192   1.1     chuck 
    193   1.1     chuck     dev->sc_flags |= SBICF_INTR;
    194   1.1     chuck 
    195   1.1     chuck     pc->dma_int = dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR;
    196   1.1     chuck }
    197   1.1     chuck 
    198   1.1     chuck /*
    199   1.1     chuck  * Prime the hardware for a DMA transfer
    200   1.1     chuck  */
    201   1.1     chuck int
    202   1.1     chuck wdsc_dmago(dev, addr, count, flags)
    203   1.1     chuck     struct sbic_softc *dev;
    204   1.1     chuck     char *addr;
    205   1.1     chuck     int count, flags;
    206   1.1     chuck {
    207   1.1     chuck     volatile struct pcc *pc = dev->sc_cregs;
    208   1.1     chuck 
    209   1.1     chuck     /*
    210   1.1     chuck      * Set up the command word based on flags
    211   1.1     chuck      */
    212   1.1     chuck     if ( (flags & DMAGO_READ) == 0 )
    213   1.1     chuck         dev->sc_dmacmd = DMAC_CSR_ENABLE | DMAC_CSR_WRITE;
    214   1.1     chuck     else
    215   1.1     chuck         dev->sc_dmacmd = DMAC_CSR_ENABLE;
    216   1.1     chuck 
    217   1.1     chuck     dev->sc_flags |= SBICF_INTR;
    218   1.1     chuck     dev->sc_tcnt   = dev->sc_cur->dc_count << 1;
    219   1.1     chuck 
    220   1.1     chuck     /*
    221   1.1     chuck      * Prime the hardware.
    222   1.1     chuck      * Note, it's probably not necessary to do this here, since dmanext
    223   1.1     chuck      * is called just prior to the actual transfer.
    224   1.1     chuck      */
    225   1.1     chuck     pc->dma_csr   = 0;
    226   1.1     chuck     pc->dma_int   = dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR;
    227   1.1     chuck     pc->dma_daddr = (unsigned long)dev->sc_cur->dc_addr;
    228   1.1     chuck     pc->dma_bcnt  = (unsigned long)dev->sc_tcnt | (1 << 24);
    229   1.1     chuck     pc->dma_csr   = dev->sc_dmacmd;
    230   1.1     chuck 
    231   1.1     chuck     return(dev->sc_tcnt);
    232   1.1     chuck }
    233   1.1     chuck 
    234   1.1     chuck /*
    235   1.1     chuck  * Prime the hardware for the next DMA transfer
    236   1.1     chuck  */
    237   1.1     chuck int
    238   1.1     chuck wdsc_dmanext(dev)
    239   1.1     chuck     struct sbic_softc *dev;
    240   1.1     chuck {
    241   1.1     chuck     volatile struct pcc *pc = dev->sc_cregs;
    242   1.1     chuck 
    243   1.1     chuck     if ( dev->sc_cur > dev->sc_last ) {
    244   1.1     chuck         /*
    245   1.1     chuck          * Shouldn't happen !!
    246   1.1     chuck          */
    247   1.7  christos         printf("wdsc_dmanext at end !!!\n");
    248   1.1     chuck         wdsc_dmastop(dev);
    249   1.1     chuck         return(0);
    250   1.1     chuck     }
    251   1.1     chuck 
    252   1.1     chuck     dev->sc_tcnt = dev->sc_cur->dc_count << 1;
    253   1.1     chuck 
    254   1.1     chuck     /*
    255   1.1     chuck      * Load the next DMA address
    256   1.1     chuck      */
    257   1.1     chuck     pc->dma_csr   = 0;
    258   1.1     chuck     pc->dma_int   = dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR;
    259   1.1     chuck     pc->dma_daddr = (unsigned long)dev->sc_cur->dc_addr;
    260   1.1     chuck     pc->dma_bcnt  = (unsigned long)dev->sc_tcnt | (1 << 24);
    261   1.1     chuck     pc->dma_csr   = dev->sc_dmacmd;
    262   1.1     chuck 
    263   1.1     chuck     return(dev->sc_tcnt);
    264   1.1     chuck }
    265   1.1     chuck 
    266   1.1     chuck /*
    267   1.1     chuck  * Stop DMA, and disable interrupts
    268   1.1     chuck  */
    269   1.1     chuck void
    270   1.1     chuck wdsc_dmastop(dev)
    271   1.1     chuck     struct sbic_softc *dev;
    272   1.1     chuck {
    273   1.1     chuck     volatile struct pcc *pc = dev->sc_cregs;
    274   1.1     chuck     int                 s;
    275   1.1     chuck 
    276   1.1     chuck     s = splbio();
    277   1.1     chuck 
    278   1.1     chuck     pc->dma_csr    = 0;
    279   1.1     chuck     pc->dma_int    = dev->sc_ipl | PCC_ICLEAR;
    280   1.1     chuck 
    281   1.1     chuck     splx(s);
    282   1.1     chuck }
    283   1.1     chuck 
    284   1.1     chuck /*
    285   1.1     chuck  * Come here following a DMA interrupt
    286   1.1     chuck  */
    287   1.1     chuck int
    288   1.2     chuck wdsc_dmaintr(arg)
    289   1.2     chuck     void *arg;
    290   1.1     chuck {
    291   1.2     chuck     struct sbic_softc *dev = arg;
    292   1.1     chuck     volatile struct pcc *pc = dev->sc_cregs;
    293   1.1     chuck     int                 found = 0;
    294   1.1     chuck 
    295   1.1     chuck     /*
    296   1.1     chuck      * Really a DMA interrupt?
    297   1.1     chuck      */
    298   1.1     chuck     if ( (pc->dma_int & 0x80) == 0 )
    299   1.1     chuck         return(0);
    300   1.1     chuck 
    301   1.1     chuck     /*
    302   1.1     chuck      * Was it a completion interrupt?
    303   1.1     chuck      * XXXSCW Note: Support for other DMA interrupts is required, eg. buserr
    304   1.1     chuck      */
    305   1.1     chuck     if ( pc->dma_csr & DMAC_CSR_DONE ) {
    306   1.1     chuck         ++found;
    307   1.1     chuck 
    308   1.1     chuck         pc->dma_int = dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR;
    309   1.1     chuck     }
    310   1.1     chuck 
    311   1.1     chuck     return(found);
    312   1.1     chuck }
    313   1.1     chuck 
    314   1.1     chuck /*
    315   1.1     chuck  * Come here for SCSI interrupts
    316   1.1     chuck  */
    317   1.1     chuck int
    318   1.2     chuck wdsc_scsiintr(arg)
    319   1.2     chuck     void *arg;
    320   1.1     chuck {
    321   1.2     chuck     struct sbic_softc *dev = arg;
    322   1.1     chuck     volatile struct pcc *pc = dev->sc_cregs;
    323   1.1     chuck     int                 found;
    324   1.1     chuck 
    325   1.1     chuck     /*
    326   1.1     chuck      * Really a SCSI interrupt?
    327   1.1     chuck      */
    328   1.1     chuck     if ( (pc->scsi_int & 0x80) == 0 )
    329   1.1     chuck         return(0);
    330   1.1     chuck 
    331   1.1     chuck     /*
    332   1.1     chuck      * Go handle it
    333   1.1     chuck      */
    334   1.1     chuck     found = sbicintr(dev);
    335   1.1     chuck 
    336   1.1     chuck     /*
    337   1.1     chuck      * Acknowledge and clear the interrupt
    338   1.1     chuck      */
    339   1.1     chuck     pc->scsi_int = dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR;
    340   1.1     chuck 
    341   1.1     chuck     return(found);
    342   1.1     chuck }
    343