Home | History | Annotate | Line # | Download | only in eisa
mlx_eisa.c revision 1.3.4.3
      1  1.3.4.3  jdolecek /*	$NetBSD: mlx_eisa.c,v 1.3.4.3 2002/10/10 18:38:38 jdolecek Exp $	*/
      2      1.1        ad 
      3      1.1        ad /*-
      4      1.1        ad  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5      1.1        ad  * All rights reserved.
      6      1.1        ad  *
      7      1.1        ad  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1        ad  * by Andrew Doran.
      9      1.1        ad  *
     10      1.1        ad  * Redistribution and use in source and binary forms, with or without
     11      1.1        ad  * modification, are permitted provided that the following conditions
     12      1.1        ad  * are met:
     13      1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14      1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15      1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17      1.1        ad  *    documentation and/or other materials provided with the distribution.
     18      1.1        ad  * 3. All advertising materials mentioning features or use of this software
     19      1.1        ad  *    must display the following acknowledgement:
     20      1.1        ad  *        This product includes software developed by the NetBSD
     21      1.1        ad  *        Foundation, Inc. and its contributors.
     22      1.1        ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1        ad  *    contributors may be used to endorse or promote products derived
     24      1.1        ad  *    from this software without specific prior written permission.
     25      1.1        ad  *
     26      1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1        ad  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1        ad  */
     38      1.1        ad 
     39      1.1        ad /*
     40      1.1        ad  * EISA front-end for mlx(4) driver.
     41      1.1        ad  */
     42      1.1        ad 
     43  1.3.4.1   thorpej #include <sys/cdefs.h>
     44  1.3.4.3  jdolecek __KERNEL_RCSID(0, "$NetBSD: mlx_eisa.c,v 1.3.4.3 2002/10/10 18:38:38 jdolecek Exp $");
     45  1.3.4.1   thorpej 
     46      1.1        ad #include <sys/param.h>
     47      1.1        ad #include <sys/systm.h>
     48      1.1        ad #include <sys/device.h>
     49      1.1        ad 
     50      1.1        ad #include <machine/bus.h>
     51      1.1        ad #include <machine/intr.h>
     52      1.1        ad 
     53      1.1        ad #include <dev/eisa/eisavar.h>
     54      1.1        ad #include <dev/eisa/eisadevs.h>
     55      1.1        ad 
     56      1.1        ad #include <dev/ic/mlxreg.h>
     57      1.1        ad #include <dev/ic/mlxio.h>
     58      1.1        ad #include <dev/ic/mlxvar.h>
     59      1.1        ad 
     60  1.3.4.1   thorpej #define MLX_EISA_SLOT_OFFSET		0x0c80
     61      1.1        ad #define MLX_EISA_IOSIZE			(0x0ce0 - MLX_EISA_SLOT_OFFSET)
     62      1.2        ad #define MLX_EISA_IOCONF1		(0x0cc1 - MLX_EISA_SLOT_OFFSET)
     63      1.2        ad #define MLX_EISA_IOCONF2		(0x0cc3 - MLX_EISA_SLOT_OFFSET)
     64      1.1        ad 
     65      1.1        ad static void	mlx_eisa_attach(struct device *, struct device *, void *);
     66      1.1        ad static int	mlx_eisa_match(struct device *, struct cfdata *, void *);
     67      1.1        ad 
     68      1.1        ad static int	mlx_v1_submit(struct mlx_softc *, struct mlx_ccb *);
     69      1.1        ad static int	mlx_v1_findcomplete(struct mlx_softc *, u_int *, u_int *);
     70      1.1        ad static void	mlx_v1_intaction(struct mlx_softc *, int);
     71      1.1        ad static int	mlx_v1_fw_handshake(struct mlx_softc *, int *, int *, int *);
     72      1.1        ad #ifdef MLX_RESET
     73      1.1        ad static int	mlx_v1_reset(struct mlx_softc *);
     74      1.1        ad #endif
     75      1.1        ad 
     76  1.3.4.3  jdolecek CFATTACH_DECL(mlx_eisa, sizeof(struct mlx_softc),
     77  1.3.4.3  jdolecek     mlx_eisa_match, mlx_eisa_attach, NULL, NULL);
     78      1.1        ad 
     79  1.3.4.2  jdolecek struct mlx_eisa_prod {
     80  1.3.4.2  jdolecek 	const char	*mp_idstr;
     81  1.3.4.2  jdolecek 	int		mp_nchan;
     82  1.3.4.2  jdolecek } static const mlx_eisa_prod[] = {
     83  1.3.4.2  jdolecek 	{ "MLX0070", 1 },
     84  1.3.4.2  jdolecek 	{ "MLX0071", 3 },
     85  1.3.4.2  jdolecek 	{ "MLX0072", 3 },
     86  1.3.4.2  jdolecek 	{ "MLX0073", 2 },
     87  1.3.4.2  jdolecek 	{ "MLX0074", 1 },
     88  1.3.4.2  jdolecek 	{ "MLX0075", 3 },
     89  1.3.4.2  jdolecek 	{ "MLX0076", 2 },
     90  1.3.4.2  jdolecek 	{ "MLX0077", 1 },
     91      1.1        ad };
     92      1.1        ad 
     93      1.1        ad static int
     94      1.1        ad mlx_eisa_match(struct device *parent, struct cfdata *match, void *aux)
     95      1.1        ad {
     96      1.1        ad 	struct eisa_attach_args *ea;
     97      1.1        ad 	int i;
     98      1.1        ad 
     99      1.1        ad 	ea = aux;
    100      1.1        ad 
    101      1.1        ad 	for (i = 0; i < sizeof(mlx_eisa_prod) / sizeof(mlx_eisa_prod[0]); i++)
    102  1.3.4.2  jdolecek 		if (strcmp(ea->ea_idstring, mlx_eisa_prod[i].mp_idstr) == 0)
    103      1.1        ad 			return (1);
    104      1.1        ad 
    105      1.1        ad 	return (0);
    106      1.1        ad }
    107      1.1        ad 
    108      1.1        ad static void
    109      1.1        ad mlx_eisa_attach(struct device *parent, struct device *self, void *aux)
    110      1.1        ad {
    111      1.1        ad 	struct eisa_attach_args *ea;
    112      1.1        ad 	bus_space_handle_t ioh;
    113      1.1        ad 	eisa_chipset_tag_t ec;
    114      1.1        ad 	eisa_intr_handle_t ih;
    115      1.1        ad 	struct mlx_softc *mlx;
    116      1.1        ad 	bus_space_tag_t iot;
    117      1.1        ad 	const char *intrstr;
    118  1.3.4.2  jdolecek 	int irq, le, i;
    119      1.1        ad 
    120      1.1        ad 	ea = aux;
    121      1.1        ad 	mlx = (struct mlx_softc *)self;
    122      1.1        ad 	iot = ea->ea_iot;
    123      1.1        ad 	ec = ea->ea_ec;
    124      1.1        ad 
    125      1.1        ad 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    126      1.1        ad 	    MLX_EISA_SLOT_OFFSET, MLX_EISA_IOSIZE, 0, &ioh)) {
    127      1.1        ad 		printf("can't map i/o space\n");
    128      1.1        ad 		return;
    129      1.1        ad 	}
    130      1.1        ad 
    131      1.1        ad 	mlx->mlx_iot = iot;
    132      1.1        ad 	mlx->mlx_ioh = ioh;
    133      1.1        ad 	mlx->mlx_dmat = ea->ea_dmat;
    134      1.1        ad 
    135      1.1        ad 	/*
    136      1.1        ad 	 * Map and establish the interrupt.
    137      1.1        ad 	 */
    138      1.1        ad 	switch (bus_space_read_1(iot, ioh, MLX_EISA_IOCONF1) & 0xf0) {
    139      1.1        ad 	case 0xa0:
    140      1.1        ad 		irq = 11;
    141      1.1        ad 		break;
    142      1.1        ad 	case 0xc0:
    143      1.1        ad 		irq = 12;
    144      1.1        ad 		break;
    145      1.1        ad 	case 0xe0:
    146      1.1        ad 		irq = 14;
    147      1.1        ad 		break;
    148      1.1        ad 	case 0x80:
    149      1.1        ad 		irq = 15;
    150      1.1        ad 		break;
    151      1.1        ad 	default:
    152      1.1        ad 		printf("controller on invalid IRQ\n");
    153      1.1        ad 		return;
    154      1.1        ad 	}
    155      1.1        ad 
    156      1.1        ad 	if (eisa_intr_map(ec, irq, &ih)) {
    157      1.1        ad 		printf("can't map interrupt (%d)\n", irq);
    158      1.1        ad 		return;
    159      1.1        ad 	}
    160      1.1        ad 
    161      1.1        ad 	if ((bus_space_read_1(iot, ioh, MLX_EISA_IOCONF1) & 0x08) != 0)
    162      1.1        ad 		le = IST_LEVEL;
    163      1.1        ad 	else
    164      1.1        ad 		le = IST_EDGE;
    165      1.1        ad 
    166      1.1        ad 	intrstr = eisa_intr_string(ec, ih);
    167      1.1        ad 	mlx->mlx_ih = eisa_intr_establish(ec, ih, le, IPL_BIO, mlx_intr, mlx);
    168      1.1        ad 	if (mlx->mlx_ih == NULL) {
    169      1.1        ad 		printf("can't establish interrupt");
    170      1.1        ad 		if (intrstr != NULL)
    171      1.1        ad 			printf(" at %s", intrstr);
    172      1.1        ad 		printf("\n");
    173      1.1        ad 		return;
    174      1.1        ad 	}
    175      1.1        ad 
    176  1.3.4.2  jdolecek 	for (i = 0; i < sizeof(mlx_eisa_prod) / sizeof(mlx_eisa_prod[0]); i++)
    177  1.3.4.2  jdolecek 		if (strcmp(ea->ea_idstring, mlx_eisa_prod[i].mp_idstr) == 0) {
    178  1.3.4.2  jdolecek 			mlx->mlx_ci.ci_nchan = mlx_eisa_prod[i].mp_nchan;
    179  1.3.4.2  jdolecek 			break;
    180  1.3.4.2  jdolecek 		}
    181  1.3.4.2  jdolecek 	mlx->mlx_ci.ci_iftype = 1;
    182      1.1        ad 
    183      1.1        ad 	mlx->mlx_submit = mlx_v1_submit;
    184      1.1        ad 	mlx->mlx_findcomplete = mlx_v1_findcomplete;
    185      1.1        ad 	mlx->mlx_intaction = mlx_v1_intaction;
    186      1.1        ad 	mlx->mlx_fw_handshake = mlx_v1_fw_handshake;
    187      1.1        ad #ifdef MLX_RESET
    188      1.1        ad 	mlx->mlx_reset = mlx_v1_reset;
    189      1.1        ad #endif
    190      1.1        ad 
    191      1.3        ad 	printf(": Mylex RAID\n");
    192      1.1        ad 	mlx_init(mlx, intrstr);
    193      1.1        ad }
    194      1.1        ad 
    195      1.1        ad /*
    196      1.1        ad  * ================= V1 interface linkage =================
    197      1.1        ad  */
    198      1.1        ad 
    199      1.1        ad /*
    200      1.1        ad  * Try to give (mc) to the controller.  Returns 1 if successful, 0 on
    201      1.1        ad  * failure (the controller is not ready to take a command).
    202      1.1        ad  *
    203      1.1        ad  * Must be called at splbio or in a fashion that prevents reentry.
    204      1.1        ad  */
    205      1.1        ad static int
    206      1.1        ad mlx_v1_submit(struct mlx_softc *mlx, struct mlx_ccb *mc)
    207      1.1        ad {
    208      1.1        ad 
    209      1.1        ad 	/* Ready for our command? */
    210      1.1        ad 	if ((mlx_inb(mlx, MLX_V1REG_IDB) & MLX_V1_IDB_FULL) == 0) {
    211      1.1        ad 		/* Copy mailbox data to window. */
    212      1.1        ad 		bus_space_write_region_1(mlx->mlx_iot, mlx->mlx_ioh,
    213  1.3.4.2  jdolecek 		    MLX_V1REG_MAILBOX, mc->mc_mbox, 13);
    214      1.1        ad 		bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh,
    215  1.3.4.2  jdolecek 		    MLX_V1REG_MAILBOX, 13,
    216      1.1        ad 		    BUS_SPACE_BARRIER_WRITE);
    217      1.1        ad 
    218      1.1        ad 		/* Post command. */
    219  1.3.4.2  jdolecek 		mlx_outb(mlx, MLX_V1REG_IDB, MLX_V1_IDB_FULL);
    220      1.1        ad 		return (1);
    221      1.1        ad 	}
    222      1.1        ad 
    223      1.1        ad 	return (0);
    224      1.1        ad }
    225      1.1        ad 
    226      1.1        ad /*
    227      1.1        ad  * See if a command has been completed, if so acknowledge its completion and
    228      1.1        ad  * recover the slot number and status code.
    229      1.1        ad  *
    230      1.1        ad  * Must be called at splbio or in a fashion that prevents reentry.
    231      1.1        ad  */
    232      1.1        ad static int
    233      1.1        ad mlx_v1_findcomplete(struct mlx_softc *mlx, u_int *slot, u_int *status)
    234      1.1        ad {
    235      1.1        ad 
    236      1.1        ad 	/* Status available? */
    237  1.3.4.2  jdolecek 	if ((mlx_inb(mlx, MLX_V1REG_ODB) & MLX_V1_ODB_SAVAIL) != 0) {
    238      1.1        ad 		*slot = mlx_inb(mlx, MLX_V1REG_MAILBOX + 0x0d);
    239      1.1        ad 		*status = mlx_inw(mlx, MLX_V1REG_MAILBOX + 0x0e);
    240      1.1        ad 
    241      1.1        ad 		/* Acknowledge completion. */
    242      1.1        ad 		mlx_outb(mlx, MLX_V1REG_ODB, MLX_V1_ODB_SAVAIL);
    243      1.1        ad 		mlx_outb(mlx, MLX_V1REG_IDB, MLX_V1_IDB_SACK);
    244      1.1        ad 		return (1);
    245      1.1        ad 	}
    246      1.1        ad 
    247      1.1        ad 	return (0);
    248      1.1        ad }
    249      1.1        ad 
    250      1.1        ad /*
    251      1.1        ad  * Enable/disable interrupts as requested. (No acknowledge required)
    252      1.1        ad  *
    253      1.1        ad  * Must be called at splbio or in a fashion that prevents reentry.
    254      1.1        ad  */
    255      1.1        ad static void
    256      1.1        ad mlx_v1_intaction(struct mlx_softc *mlx, int action)
    257      1.1        ad {
    258      1.1        ad 
    259      1.1        ad 	mlx_outb(mlx, MLX_V1REG_IE, action ? 1 : 0);
    260      1.1        ad }
    261      1.1        ad 
    262      1.1        ad /*
    263      1.1        ad  * Poll for firmware error codes during controller initialisation.
    264      1.1        ad  *
    265      1.1        ad  * Returns 0 if initialisation is complete, 1 if still in progress but no
    266      1.1        ad  * error has been fetched, 2 if an error has been retrieved.
    267      1.1        ad  */
    268      1.1        ad static int
    269      1.1        ad mlx_v1_fw_handshake(struct mlx_softc *mlx, int *error, int *param1, int *param2)
    270      1.1        ad {
    271      1.1        ad 	u_int8_t fwerror;
    272      1.1        ad 
    273      1.1        ad 	/*
    274      1.1        ad 	 * First time around, enable the IDB interrupt and clear any
    275      1.1        ad 	 * hardware completion status.
    276      1.1        ad 	 */
    277      1.1        ad 	if ((mlx->mlx_flags & MLXF_FW_INITTED) == 0) {
    278      1.1        ad 		mlx_outb(mlx, MLX_V1REG_ODB_EN, 1);
    279  1.3.4.1   thorpej 		DELAY(1000);
    280  1.3.4.1   thorpej 		mlx_outb(mlx, MLX_V1REG_ODB, 1);
    281      1.1        ad 		DELAY(1000);
    282      1.1        ad 		mlx_outb(mlx, MLX_V1REG_IDB, MLX_V1_IDB_SACK);
    283      1.1        ad 		DELAY(1000);
    284      1.1        ad 		mlx->mlx_flags |= MLXF_FW_INITTED;
    285      1.1        ad 	}
    286      1.1        ad 
    287      1.1        ad 	/* Init in progress? */
    288      1.1        ad 	if ((mlx_inb(mlx, MLX_V1REG_IDB) & MLX_V1_IDB_INIT_BUSY) == 0)
    289      1.1        ad 		return (0);
    290      1.1        ad 
    291      1.1        ad 	/* Test error value. */
    292      1.1        ad 	fwerror = mlx_inb(mlx, MLX_V1REG_ODB);
    293      1.1        ad 
    294      1.1        ad 	if ((fwerror & MLX_V1_FWERROR_PEND) == 0)
    295      1.1        ad 		return (1);
    296      1.1        ad 
    297      1.1        ad 	/* XXX Fetch status. */
    298      1.1        ad 	*error = fwerror & 0xf0;
    299      1.1        ad 	*param1 = -1;
    300      1.1        ad 	*param2 = -1;
    301      1.1        ad 
    302      1.1        ad 	/* Acknowledge. */
    303      1.1        ad 	mlx_outb(mlx, MLX_V1REG_ODB, fwerror);
    304      1.1        ad 
    305      1.1        ad 	return (2);
    306      1.1        ad }
    307      1.1        ad 
    308      1.1        ad #ifdef MLX_RESET
    309      1.1        ad /*
    310      1.1        ad  * Reset the controller.  Return non-zero on failure.
    311      1.1        ad  */
    312      1.1        ad static int
    313      1.1        ad mlx_v1_reset(struct mlx_softc *mlx)
    314      1.1        ad {
    315      1.1        ad 	int i;
    316      1.1        ad 
    317      1.1        ad 	mlx_outb(mlx, MLX_V1REG_IDB, MLX_V1_IDB_SACK);
    318      1.1        ad 	delay(1000000);
    319      1.1        ad 
    320      1.1        ad 	/* Wait up to 2 minutes for the bit to clear. */
    321      1.1        ad 	for (i = 120; i != 0; i--) {
    322      1.1        ad 		delay(1000000);
    323      1.1        ad 		if ((mlx_inb(mlx, MLX_V1REG_IDB) & MLX_V1_IDB_SACK) == 0)
    324      1.1        ad 			break;
    325      1.1        ad 	}
    326      1.1        ad 	if (i == 0)
    327      1.1        ad 		return (-1);
    328      1.1        ad 
    329      1.1        ad 	mlx_outb(mlx, MLX_V1REG_ODB, MLX_V1_ODB_RESET);
    330      1.1        ad 	mlx_outb(mlx, MLX_V1REG_IDB, MLX_V1_IDB_RESET);
    331      1.1        ad 
    332      1.1        ad 	/* Wait up to 5 seconds for the bit to clear... */
    333      1.1        ad 	for (i = 5; i != 0; i--) {
    334      1.1        ad 		delay(1000000);
    335      1.1        ad 		if ((mlx_inb(mlx, MLX_V1REG_IDB) & MLX_V1_IDB_RESET) == 0)
    336      1.1        ad 			break;
    337      1.1        ad 	}
    338      1.1        ad 	if (i == 0)
    339      1.1        ad 		return (-1);
    340      1.1        ad 
    341      1.1        ad 	/* Wait up to 3 seconds for the other bit to clear... */
    342      1.1        ad 	for (i = 5; i != 0; i--) {
    343      1.1        ad 		delay(1000000);
    344      1.1        ad 		if ((mlx_inb(mlx, MLX_V1REG_ODB) & MLX_V1_ODB_RESET) == 0)
    345      1.1        ad 			break;
    346      1.1        ad 	}
    347      1.1        ad 	if (i == 0)
    348      1.1        ad 		return (-1);
    349      1.1        ad 
    350      1.1        ad 	return (0);
    351      1.1        ad }
    352      1.1        ad #endif	/* MLX_RESET */
    353