Home | History | Annotate | Line # | Download | only in eisa
uha_eisa.c revision 1.10
      1  1.10   thorpej /*	$NetBSD: uha_eisa.c,v 1.10 1998/02/17 03:02:56 thorpej Exp $	*/
      2   1.2   mycroft 
      3   1.2   mycroft /*
      4   1.7   mycroft  * Copyright (c) 1994, 1996, 1997 Charles M. Hannum.  All rights reserved.
      5   1.2   mycroft  *
      6   1.2   mycroft  * Redistribution and use in source and binary forms, with or without
      7   1.2   mycroft  * modification, are permitted provided that the following conditions
      8   1.2   mycroft  * are met:
      9   1.2   mycroft  * 1. Redistributions of source code must retain the above copyright
     10   1.2   mycroft  *    notice, this list of conditions and the following disclaimer.
     11   1.2   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.2   mycroft  *    notice, this list of conditions and the following disclaimer in the
     13   1.2   mycroft  *    documentation and/or other materials provided with the distribution.
     14   1.2   mycroft  * 3. All advertising materials mentioning features or use of this software
     15   1.2   mycroft  *    must display the following acknowledgement:
     16   1.2   mycroft  *	This product includes software developed by Charles M. Hannum.
     17   1.2   mycroft  * 4. The name of the author may not be used to endorse or promote products
     18   1.2   mycroft  *    derived from this software without specific prior written permission.
     19   1.2   mycroft  *
     20   1.2   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21   1.2   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22   1.2   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23   1.2   mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24   1.2   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25   1.2   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26   1.2   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27   1.2   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28   1.2   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29   1.2   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30   1.2   mycroft  */
     31   1.2   mycroft 
     32   1.1   mycroft #include <sys/types.h>
     33   1.1   mycroft #include <sys/param.h>
     34   1.3  christos #include <sys/systm.h>
     35   1.1   mycroft #include <sys/device.h>
     36   1.1   mycroft #include <sys/kernel.h>
     37   1.1   mycroft #include <sys/proc.h>
     38   1.1   mycroft #include <sys/user.h>
     39   1.1   mycroft 
     40   1.1   mycroft #include <machine/bus.h>
     41   1.1   mycroft #include <machine/intr.h>
     42   1.1   mycroft 
     43   1.9    bouyer #include <dev/scsipi/scsi_all.h>
     44   1.9    bouyer #include <dev/scsipi/scsipi_all.h>
     45   1.9    bouyer #include <dev/scsipi/scsiconf.h>
     46   1.1   mycroft 
     47   1.1   mycroft #include <dev/eisa/eisavar.h>
     48   1.1   mycroft #include <dev/eisa/eisadevs.h>
     49   1.1   mycroft 
     50   1.1   mycroft #include <dev/ic/uhareg.h>
     51   1.1   mycroft #include <dev/ic/uhavar.h>
     52   1.1   mycroft 
     53   1.1   mycroft #define	UHA_EISA_SLOT_OFFSET	0xc80
     54   1.1   mycroft #define	UHA_EISA_IOSIZE		0x020
     55   1.1   mycroft 
     56   1.8   thorpej #ifdef __BROKEN_INDIRECT_CONFIG
     57   1.1   mycroft int	uha_eisa_match __P((struct device *, void *, void *));
     58   1.8   thorpej #else
     59   1.8   thorpej int	uha_eisa_match __P((struct device *, struct cfdata *, void *));
     60   1.8   thorpej #endif
     61   1.1   mycroft void	uha_eisa_attach __P((struct device *, struct device *, void *));
     62   1.1   mycroft 
     63   1.1   mycroft struct cfattach uha_eisa_ca = {
     64   1.1   mycroft 	sizeof(struct uha_softc), uha_eisa_match, uha_eisa_attach
     65   1.1   mycroft };
     66   1.1   mycroft 
     67   1.6  jonathan #ifndef	DDB
     68   1.6  jonathan #define Debugger() panic("should call debugger here (uha_eisa.c)")
     69   1.6  jonathan #endif /* ! DDB */
     70   1.1   mycroft 
     71   1.7   mycroft int	u24_find __P((bus_space_tag_t, bus_space_handle_t,
     72   1.7   mycroft 	    struct uha_probe_data *));
     73   1.7   mycroft void	u24_start_mbox __P((struct uha_softc *, struct uha_mscp *));
     74   1.9    bouyer int	u24_poll __P((struct uha_softc *, struct scsipi_xfer *, int));
     75   1.7   mycroft int	u24_intr __P((void *));
     76   1.7   mycroft void	u24_init __P((struct uha_softc *));
     77   1.1   mycroft 
     78   1.1   mycroft /*
     79   1.1   mycroft  * Check the slots looking for a board we recognise
     80   1.1   mycroft  * If we find one, note it's address (slot) and call
     81   1.1   mycroft  * the actual probe routine to check it out.
     82   1.1   mycroft  */
     83   1.1   mycroft int
     84   1.1   mycroft uha_eisa_match(parent, match, aux)
     85   1.1   mycroft 	struct device *parent;
     86   1.8   thorpej #ifdef __BROKEN_INDIRECT_CONFIG
     87   1.8   thorpej 	void *match;
     88   1.8   thorpej #else
     89   1.8   thorpej 	struct cfdata *match;
     90   1.8   thorpej #endif
     91   1.8   thorpej 	void *aux;
     92   1.1   mycroft {
     93   1.1   mycroft 	struct eisa_attach_args *ea = aux;
     94   1.5   thorpej 	bus_space_tag_t iot = ea->ea_iot;
     95   1.5   thorpej 	bus_space_handle_t ioh;
     96   1.1   mycroft 	int rv;
     97   1.1   mycroft 
     98   1.1   mycroft 	/* must match one of our known ID strings */
     99   1.1   mycroft 	if (strncmp(ea->ea_idstring, "USC024", 6))
    100   1.1   mycroft 		return (0);
    101   1.1   mycroft 
    102   1.5   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    103   1.5   thorpej 	    UHA_EISA_SLOT_OFFSET, UHA_EISA_IOSIZE, 0, &ioh))
    104   1.1   mycroft 		return (0);
    105   1.1   mycroft 
    106   1.5   thorpej 	rv = u24_find(iot, ioh, NULL);
    107   1.1   mycroft 
    108   1.5   thorpej 	bus_space_unmap(iot, ioh, UHA_EISA_IOSIZE);
    109   1.1   mycroft 
    110   1.1   mycroft 	return (rv);
    111   1.1   mycroft }
    112   1.1   mycroft 
    113   1.1   mycroft /*
    114   1.1   mycroft  * Attach all the sub-devices we can find
    115   1.1   mycroft  */
    116   1.1   mycroft void
    117   1.1   mycroft uha_eisa_attach(parent, self, aux)
    118   1.1   mycroft 	struct device *parent, *self;
    119   1.1   mycroft 	void *aux;
    120   1.1   mycroft {
    121   1.1   mycroft 	struct eisa_attach_args *ea = aux;
    122   1.1   mycroft 	struct uha_softc *sc = (void *)self;
    123   1.5   thorpej 	bus_space_tag_t iot = ea->ea_iot;
    124   1.8   thorpej 	bus_dma_tag_t dmat = ea->ea_dmat;
    125   1.5   thorpej 	bus_space_handle_t ioh;
    126   1.7   mycroft 	struct uha_probe_data upd;
    127   1.1   mycroft 	eisa_chipset_tag_t ec = ea->ea_ec;
    128   1.1   mycroft 	eisa_intr_handle_t ih;
    129   1.1   mycroft 	const char *model, *intrstr;
    130   1.1   mycroft 
    131   1.1   mycroft 	if (!strncmp(ea->ea_idstring, "USC024", 6))
    132   1.1   mycroft 		model = EISA_PRODUCT_USC0240;
    133   1.1   mycroft 	else
    134   1.1   mycroft 		model = "unknown model!";
    135   1.4  christos 	printf(": %s\n", model);
    136   1.1   mycroft 
    137   1.5   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    138   1.5   thorpej 	    UHA_EISA_SLOT_OFFSET, UHA_EISA_IOSIZE, 0, &ioh))
    139   1.7   mycroft 		panic("uha_eisa_attach: could not map I/O addresses");
    140   1.1   mycroft 
    141   1.5   thorpej 	sc->sc_iot = iot;
    142   1.1   mycroft 	sc->sc_ioh = ioh;
    143   1.8   thorpej 	sc->sc_dmat = dmat;
    144   1.7   mycroft 	if (!u24_find(iot, ioh, &upd))
    145   1.7   mycroft 		panic("uha_eisa_attach: u24_find failed!");
    146   1.1   mycroft 
    147   1.8   thorpej 	sc->sc_dmaflags = 0;
    148   1.8   thorpej 
    149   1.7   mycroft 	if (eisa_intr_map(ec, upd.sc_irq, &ih)) {
    150   1.4  christos 		printf("%s: couldn't map interrupt (%d)\n",
    151   1.7   mycroft 		    sc->sc_dev.dv_xname, upd.sc_irq);
    152   1.1   mycroft 		return;
    153   1.1   mycroft 	}
    154   1.1   mycroft 	intrstr = eisa_intr_string(ec, ih);
    155   1.1   mycroft 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    156   1.1   mycroft 	    u24_intr, sc);
    157   1.1   mycroft 	if (sc->sc_ih == NULL) {
    158   1.4  christos 		printf("%s: couldn't establish interrupt",
    159   1.1   mycroft 		    sc->sc_dev.dv_xname);
    160   1.1   mycroft 		if (intrstr != NULL)
    161   1.4  christos 			printf(" at %s", intrstr);
    162   1.4  christos 		printf("\n");
    163   1.1   mycroft 		return;
    164   1.1   mycroft 	}
    165   1.4  christos 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    166   1.1   mycroft 
    167   1.1   mycroft 	/* Save function pointers for later use. */
    168   1.1   mycroft 	sc->start_mbox = u24_start_mbox;
    169   1.1   mycroft 	sc->poll = u24_poll;
    170   1.1   mycroft 	sc->init = u24_init;
    171   1.1   mycroft 
    172   1.7   mycroft 	uha_attach(sc, &upd);
    173   1.1   mycroft }
    174   1.1   mycroft 
    175   1.1   mycroft int
    176   1.5   thorpej u24_find(iot, ioh, sc)
    177   1.5   thorpej 	bus_space_tag_t iot;
    178   1.5   thorpej 	bus_space_handle_t ioh;
    179   1.7   mycroft 	struct uha_probe_data *sc;
    180   1.1   mycroft {
    181   1.1   mycroft 	u_int8_t config0, config1, config2;
    182   1.1   mycroft 	int irq, drq;
    183   1.1   mycroft 	int resetcount = 4000;	/* 4 secs? */
    184   1.1   mycroft 
    185   1.5   thorpej 	config0 = bus_space_read_1(iot, ioh, U24_CONFIG + 0);
    186   1.5   thorpej 	config1 = bus_space_read_1(iot, ioh, U24_CONFIG + 1);
    187   1.5   thorpej 	config2 = bus_space_read_1(iot, ioh, U24_CONFIG + 2);
    188   1.1   mycroft 	if ((config0 & U24_MAGIC1) == 0 ||
    189   1.1   mycroft 	    (config1 & U24_MAGIC2) == 0)
    190   1.1   mycroft 		return (0);
    191   1.1   mycroft 
    192   1.1   mycroft 	drq = -1;
    193   1.1   mycroft 
    194   1.1   mycroft 	switch (config0 & U24_IRQ_MASK) {
    195   1.1   mycroft 	case U24_IRQ10:
    196   1.1   mycroft 		irq = 10;
    197   1.1   mycroft 		break;
    198   1.1   mycroft 	case U24_IRQ11:
    199   1.1   mycroft 		irq = 11;
    200   1.1   mycroft 		break;
    201   1.1   mycroft 	case U24_IRQ14:
    202   1.1   mycroft 		irq = 14;
    203   1.1   mycroft 		break;
    204   1.1   mycroft 	case U24_IRQ15:
    205   1.1   mycroft 		irq = 15;
    206   1.1   mycroft 		break;
    207   1.1   mycroft 	default:
    208   1.4  christos 		printf("u24_find: illegal irq setting %x\n",
    209   1.1   mycroft 		    config0 & U24_IRQ_MASK);
    210   1.1   mycroft 		return (0);
    211   1.1   mycroft 	}
    212   1.1   mycroft 
    213   1.5   thorpej 	bus_space_write_1(iot, ioh, U24_LINT, UHA_ASRST);
    214   1.1   mycroft 
    215   1.1   mycroft 	while (--resetcount) {
    216   1.5   thorpej 		if (bus_space_read_1(iot, ioh, U24_LINT))
    217   1.1   mycroft 			break;
    218   1.1   mycroft 		delay(1000);	/* 1 mSec per loop */
    219   1.1   mycroft 	}
    220   1.1   mycroft 	if (!resetcount) {
    221   1.4  christos 		printf("u24_find: board timed out during reset\n");
    222   1.1   mycroft 		return (0);
    223   1.1   mycroft 	}
    224   1.1   mycroft 
    225   1.1   mycroft 	/* if we want to fill in softc, do so now */
    226   1.7   mycroft 	if (sc) {
    227   1.1   mycroft 		sc->sc_irq = irq;
    228   1.1   mycroft 		sc->sc_drq = drq;
    229   1.1   mycroft 		sc->sc_scsi_dev = config2 & U24_HOSTID_MASK;
    230   1.1   mycroft 	}
    231   1.1   mycroft 
    232   1.1   mycroft 	return (1);
    233   1.1   mycroft }
    234   1.1   mycroft 
    235   1.1   mycroft void
    236   1.1   mycroft u24_start_mbox(sc, mscp)
    237   1.1   mycroft 	struct uha_softc *sc;
    238   1.1   mycroft 	struct uha_mscp *mscp;
    239   1.1   mycroft {
    240   1.5   thorpej 	bus_space_tag_t iot = sc->sc_iot;
    241   1.5   thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    242   1.1   mycroft 	int spincount = 100000;	/* 1s should be enough */
    243   1.1   mycroft 
    244   1.1   mycroft 	while (--spincount) {
    245   1.5   thorpej 		if ((bus_space_read_1(iot, ioh, U24_LINT) & U24_LDIP) == 0)
    246   1.1   mycroft 			break;
    247   1.1   mycroft 		delay(100);
    248   1.1   mycroft 	}
    249   1.1   mycroft 	if (!spincount) {
    250   1.4  christos 		printf("%s: uha_start_mbox, board not responding\n",
    251   1.1   mycroft 		    sc->sc_dev.dv_xname);
    252   1.1   mycroft 		Debugger();
    253   1.1   mycroft 	}
    254   1.1   mycroft 
    255   1.8   thorpej 	bus_space_write_4(iot, ioh, U24_OGMPTR,
    256  1.10   thorpej 	    sc->sc_dmamap_mscp->dm_segs[0].ds_addr + UHA_MSCP_OFF(mscp));
    257   1.1   mycroft 	if (mscp->flags & MSCP_ABORT)
    258   1.5   thorpej 		bus_space_write_1(iot, ioh, U24_OGMCMD, 0x80);
    259   1.1   mycroft 	else
    260   1.5   thorpej 		bus_space_write_1(iot, ioh, U24_OGMCMD, 0x01);
    261   1.5   thorpej 	bus_space_write_1(iot, ioh, U24_LINT, U24_OGMFULL);
    262   1.1   mycroft 
    263   1.1   mycroft 	if ((mscp->xs->flags & SCSI_POLL) == 0)
    264   1.1   mycroft 		timeout(uha_timeout, mscp, (mscp->timeout * hz) / 1000);
    265   1.1   mycroft }
    266   1.1   mycroft 
    267   1.1   mycroft int
    268   1.1   mycroft u24_poll(sc, xs, count)
    269   1.1   mycroft 	struct uha_softc *sc;
    270   1.9    bouyer 	struct scsipi_xfer *xs;
    271   1.1   mycroft 	int count;
    272   1.1   mycroft {
    273   1.5   thorpej 	bus_space_tag_t iot = sc->sc_iot;
    274   1.5   thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    275   1.1   mycroft 
    276   1.1   mycroft 	while (count) {
    277   1.1   mycroft 		/*
    278   1.1   mycroft 		 * If we had interrupts enabled, would we
    279   1.1   mycroft 		 * have got an interrupt?
    280   1.1   mycroft 		 */
    281   1.5   thorpej 		if (bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP)
    282   1.1   mycroft 			u24_intr(sc);
    283   1.1   mycroft 		if (xs->flags & ITSDONE)
    284   1.1   mycroft 			return (0);
    285   1.1   mycroft 		delay(1000);
    286   1.1   mycroft 		count--;
    287   1.1   mycroft 	}
    288   1.1   mycroft 	return (1);
    289   1.1   mycroft }
    290   1.1   mycroft 
    291   1.1   mycroft int
    292   1.1   mycroft u24_intr(arg)
    293   1.1   mycroft 	void *arg;
    294   1.1   mycroft {
    295   1.1   mycroft 	struct uha_softc *sc = arg;
    296   1.5   thorpej 	bus_space_tag_t iot = sc->sc_iot;
    297   1.5   thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    298   1.1   mycroft 	struct uha_mscp *mscp;
    299   1.1   mycroft 	u_char uhastat;
    300   1.1   mycroft 	u_long mboxval;
    301   1.1   mycroft 
    302   1.1   mycroft #ifdef	UHADEBUG
    303   1.4  christos 	printf("%s: uhaintr ", sc->sc_dev.dv_xname);
    304   1.1   mycroft #endif /*UHADEBUG */
    305   1.1   mycroft 
    306   1.5   thorpej 	if ((bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP) == 0)
    307   1.1   mycroft 		return (0);
    308   1.1   mycroft 
    309   1.1   mycroft 	for (;;) {
    310   1.1   mycroft 		/*
    311   1.1   mycroft 		 * First get all the information and then
    312   1.1   mycroft 		 * acknowledge the interrupt
    313   1.1   mycroft 		 */
    314   1.5   thorpej 		uhastat = bus_space_read_1(iot, ioh, U24_SINT);
    315   1.5   thorpej 		mboxval = bus_space_read_4(iot, ioh, U24_ICMPTR);
    316   1.5   thorpej 		bus_space_write_1(iot, ioh, U24_SINT, U24_ICM_ACK);
    317   1.5   thorpej 		bus_space_write_1(iot, ioh, U24_ICMCMD, 0);
    318   1.1   mycroft 
    319   1.1   mycroft #ifdef	UHADEBUG
    320   1.4  christos 		printf("status = 0x%x ", uhastat);
    321   1.1   mycroft #endif /*UHADEBUG*/
    322   1.1   mycroft 
    323   1.1   mycroft 		/*
    324   1.1   mycroft 		 * Process the completed operation
    325   1.1   mycroft 		 */
    326   1.1   mycroft 		mscp = uha_mscp_phys_kv(sc, mboxval);
    327   1.1   mycroft 		if (!mscp) {
    328   1.4  christos 			printf("%s: BAD MSCP RETURNED!\n",
    329   1.1   mycroft 			    sc->sc_dev.dv_xname);
    330   1.1   mycroft 			continue;	/* whatever it was, it'll timeout */
    331   1.1   mycroft 		}
    332   1.1   mycroft 		untimeout(uha_timeout, mscp);
    333   1.1   mycroft 		uha_done(sc, mscp);
    334   1.1   mycroft 
    335   1.5   thorpej 		if ((bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP) == 0)
    336   1.1   mycroft 			return (1);
    337   1.1   mycroft 	}
    338   1.1   mycroft }
    339   1.1   mycroft 
    340   1.1   mycroft void
    341   1.1   mycroft u24_init(sc)
    342   1.1   mycroft 	struct uha_softc *sc;
    343   1.1   mycroft {
    344   1.5   thorpej 	bus_space_tag_t iot = sc->sc_iot;
    345   1.5   thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    346   1.1   mycroft 
    347   1.1   mycroft 	/* free OGM and ICM */
    348   1.5   thorpej 	bus_space_write_1(iot, ioh, U24_OGMCMD, 0);
    349   1.5   thorpej 	bus_space_write_1(iot, ioh, U24_ICMCMD, 0);
    350   1.1   mycroft 	/* make sure interrupts are enabled */
    351   1.1   mycroft #ifdef UHADEBUG
    352   1.4  christos 	printf("u24_init: lmask=%02x, smask=%02x\n",
    353   1.5   thorpej 	    bus_space_read_1(iot, ioh, U24_LMASK),
    354   1.5   thorpej 	    bus_space_read_1(iot, ioh, U24_SMASK));
    355   1.1   mycroft #endif
    356   1.5   thorpej 	bus_space_write_1(iot, ioh, U24_LMASK, 0xd2);	/* XXX */
    357   1.5   thorpej 	bus_space_write_1(iot, ioh, U24_SMASK, 0x92);	/* XXX */
    358   1.1   mycroft }
    359