Home | History | Annotate | Line # | Download | only in if
if_ze.c revision 1.15
      1  1.15  jkunz /*      $NetBSD: if_ze.c,v 1.15 2008/03/14 21:35:01 jkunz Exp $ */
      2   1.1  ragge /*
      3   1.1  ragge  * Copyright (c) 1999 Ludd, University of Lule}, Sweden. All rights reserved.
      4   1.1  ragge  *
      5   1.1  ragge  * Redistribution and use in source and binary forms, with or without
      6   1.1  ragge  * modification, are permitted provided that the following conditions
      7   1.1  ragge  * are met:
      8   1.1  ragge  * 1. Redistributions of source code must retain the above copyright
      9   1.1  ragge  *    notice, this list of conditions and the following disclaimer.
     10   1.1  ragge  * 2. Redistributions in binary form must reproduce the above copyright
     11   1.1  ragge  *    notice, this list of conditions and the following disclaimer in the
     12   1.1  ragge  *    documentation and/or other materials provided with the distribution.
     13   1.1  ragge  * 3. All advertising materials mentioning features or use of this software
     14   1.1  ragge  *    must display the following acknowledgement:
     15   1.1  ragge  *      This product includes software developed at Ludd, University of
     16   1.1  ragge  *      Lule}, Sweden and its contributors.
     17   1.1  ragge  * 4. The name of the author may not be used to endorse or promote products
     18   1.1  ragge  *    derived from this software without specific prior written permission
     19   1.1  ragge  *
     20   1.1  ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21   1.1  ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22   1.1  ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23   1.1  ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24   1.1  ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25   1.1  ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26   1.1  ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27   1.1  ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28   1.1  ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29   1.1  ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30   1.1  ragge  */
     31  1.10  lukem 
     32  1.10  lukem #include <sys/cdefs.h>
     33  1.15  jkunz __KERNEL_RCSID(0, "$NetBSD: if_ze.c,v 1.15 2008/03/14 21:35:01 jkunz Exp $");
     34   1.1  ragge 
     35   1.6  ragge #include "opt_cputype.h"
     36   1.6  ragge 
     37   1.1  ragge #include <sys/param.h>
     38   1.1  ragge #include <sys/socket.h>
     39   1.1  ragge #include <sys/device.h>
     40   1.1  ragge #include <sys/systm.h>
     41   1.1  ragge #include <sys/sockio.h>
     42   1.1  ragge 
     43   1.1  ragge #include <net/if.h>
     44   1.1  ragge #include <net/if_ether.h>
     45   1.1  ragge #include <net/if_dl.h>
     46   1.1  ragge 
     47   1.1  ragge #include <netinet/in.h>
     48   1.1  ragge #include <netinet/if_inarp.h>
     49   1.1  ragge 
     50   1.1  ragge #if NBPFILTER > 0
     51   1.1  ragge #include <net/bpf.h>
     52   1.1  ragge #include <net/bpfdesc.h>
     53   1.1  ragge #endif
     54   1.1  ragge 
     55   1.1  ragge #include <machine/bus.h>
     56   1.1  ragge #include <machine/nexus.h>
     57   1.1  ragge #include <machine/cpu.h>
     58   1.1  ragge #include <machine/scb.h>
     59   1.4  ragge #include <machine/sid.h>
     60  1.13   matt #include <machine/mainbus.h>
     61   1.1  ragge 
     62   1.1  ragge #include <dev/ic/sgecreg.h>
     63   1.1  ragge #include <dev/ic/sgecvar.h>
     64   1.1  ragge 
     65   1.1  ragge #include "ioconf.h"
     66  1.13   matt 
     67   1.1  ragge /*
     68  1.11    wiz  * Addresses.
     69   1.1  ragge  */
     70   1.1  ragge #define SGECADDR        0x20008000
     71   1.1  ragge #define NISA_ROM        0x20084000
     72   1.6  ragge #define NISA_ROM_VXT    0x200c4000
     73  1.13   matt #define	NISA_ROM_VSBUS	0x27800000
     74   1.1  ragge #define	SGECVEC		0x108
     75   1.1  ragge 
     76  1.13   matt static int	ze_mainbus_match(device_t, cfdata_t, void *);
     77  1.13   matt static void	ze_mainbus_attach(device_t, device_t, void *);
     78  1.13   matt 
     79  1.13   matt static const struct sgec_data {
     80  1.13   matt 	uint32_t sd_boardtype;
     81  1.13   matt 	bus_addr_t sd_addr;
     82  1.13   matt 	bus_addr_t sd_rom;
     83  1.13   matt 	uint16_t sd_intvec;
     84  1.13   matt 	uint8_t sd_romshift;
     85  1.13   matt } sgec_data[] = {
     86  1.13   matt 	{ VAX_BTYP_660, SGECADDR, NISA_ROM, SGECVEC, 24, },
     87  1.13   matt #if VXT2000 || VAXANY
     88  1.13   matt 	{ VAX_BTYP_VXT, SGECADDR, NISA_ROM_VXT, 0x200, 0, },
     89  1.13   matt #endif
     90  1.15  jkunz 	{ VAX_BTYP_670, SGECADDR, NISA_ROM, SGECVEC, 8, },
     91  1.15  jkunz 	{ VAX_BTYP_680, SGECADDR, NISA_ROM, SGECVEC, 8, },
     92  1.15  jkunz 	{ VAX_BTYP_681, SGECADDR, NISA_ROM, SGECVEC, 8, },
     93  1.13   matt 	{ VAX_BTYP_48, SGECADDR, NISA_ROM_VSBUS, SGECVEC, 0, },
     94  1.13   matt 	{ VAX_BTYP_49, SGECADDR, NISA_ROM_VSBUS, SGECVEC, 0, },
     95  1.14  jkunz 	{ VAX_BTYP_53, SGECADDR, NISA_ROM, SGECVEC, 8, },
     96  1.13   matt };
     97  1.13   matt 
     98  1.13   matt static const struct sgec_data *
     99  1.13   matt ze_find(void)
    100  1.13   matt {
    101  1.13   matt 	size_t i;
    102  1.13   matt 	const struct sgec_data *sd;
    103  1.13   matt 	for (i = 0, sd = sgec_data; i < __arraycount(sgec_data); i++, sd++) {
    104  1.13   matt 		if (vax_boardtype == sd->sd_boardtype)
    105  1.13   matt 			return sd;
    106  1.13   matt 	}
    107  1.13   matt 
    108  1.13   matt 	return NULL;
    109  1.13   matt }
    110   1.1  ragge 
    111  1.13   matt CFATTACH_DECL_NEW(ze_mainbus, sizeof(struct ze_softc),
    112  1.13   matt     ze_mainbus_match, ze_mainbus_attach, NULL, NULL);
    113   1.1  ragge 
    114   1.1  ragge /*
    115   1.1  ragge  * Check for present SGEC.
    116   1.1  ragge  */
    117   1.1  ragge int
    118  1.13   matt ze_mainbus_match(device_t parent, cfdata_t cf, void *aux)
    119   1.1  ragge {
    120  1.13   matt 	struct mainbus_attach_args * const ma = aux;
    121   1.1  ragge 
    122   1.1  ragge 	/*
    123   1.1  ragge 	 * Should some more intelligent checking be done???
    124   1.1  ragge 	 */
    125  1.13   matt 	if (strcmp(ma->ma_type, "sgec"))
    126  1.13   matt 		return 0;
    127  1.13   matt 
    128  1.13   matt 	return ze_find() != NULL;
    129   1.1  ragge }
    130   1.1  ragge 
    131   1.1  ragge /*
    132   1.1  ragge  * Interface exists: make available by filling in network interface
    133   1.1  ragge  * record.  System will initialize the interface when it is ready
    134   1.1  ragge  * to accept packets.
    135   1.1  ragge  */
    136   1.1  ragge void
    137  1.13   matt ze_mainbus_attach(device_t parent, device_t self, void *aux)
    138   1.1  ragge {
    139  1.13   matt 	struct mainbus_attach_args * const ma = aux;
    140  1.13   matt 	struct ze_softc * const sc = device_private(self);
    141  1.13   matt 	const struct sgec_data * const sd = ze_find();
    142  1.13   matt 	const uint32_t *ea;
    143  1.13   matt 	size_t i;
    144  1.13   matt 	int error;
    145  1.13   matt 
    146  1.13   matt 	sc->sc_dev = self;
    147   1.1  ragge 
    148   1.1  ragge 	/*
    149   1.1  ragge 	 * Map in SGEC registers.
    150   1.1  ragge 	 */
    151  1.13   matt 	sc->sc_dmat = ma->ma_dmat;
    152  1.13   matt 	sc->sc_iot = ma->ma_iot;
    153  1.13   matt 	sc->sc_intvec = sd->sd_intvec;
    154  1.13   matt 	error = bus_space_map(sc->sc_iot, sd->sd_addr, PAGE_SIZE, 0,
    155  1.13   matt 	    &sc->sc_ioh);
    156  1.13   matt 	if (error) {
    157  1.13   matt 		aprint_error(": failed to map %#lx: %d\n", sd->sd_addr, error);
    158  1.13   matt 		return;
    159  1.13   matt 	}
    160   1.1  ragge 
    161   1.1  ragge 	/*
    162   1.1  ragge 	 * Map in, read and release ethernet rom address.
    163   1.1  ragge 	 */
    164  1.13   matt 	ea = (uint32_t *)vax_map_physmem(sd->sd_rom, 1);
    165  1.13   matt 	for (i = 0; i < ETHER_ADDR_LEN; i++)
    166  1.13   matt 		sc->sc_enaddr[i] = (ea[i] >> sd->sd_romshift) & 0377;
    167   1.1  ragge 	vax_unmap_physmem((vaddr_t)ea, 1);
    168   1.1  ragge 
    169  1.13   matt 	scb_vecalloc(sc->sc_intvec, (void (*)(void *)) sgec_intr, sc,
    170  1.13   matt 	    SCB_ISTACK, &sc->sc_intrcnt);
    171   1.1  ragge 
    172   1.1  ragge 	sgec_attach(sc);
    173   1.1  ragge }
    174