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