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