if_ze.c revision 1.16.4.1 1 /* $NetBSD: if_ze.c,v 1.16.4.1 2011/03/05 20:52:16 rmind 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.16.4.1 2011/03/05 20:52:16 rmind Exp $");
34
35 #include "opt_cputype.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/bus.h>
40 #include <sys/cpu.h>
41 #include <sys/device.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 #include <machine/nexus.h>
51 #include <machine/scb.h>
52 #include <machine/sid.h>
53 #include <machine/mainbus.h>
54
55 #include <dev/ic/sgecreg.h>
56 #include <dev/ic/sgecvar.h>
57
58 #include "ioconf.h"
59
60 /*
61 * Addresses.
62 */
63 #define SGECADDR 0x20008000
64 #define NISA_ROM 0x20084000
65 #define NISA_ROM_VXT 0x200c4000
66 #define NISA_ROM_VSBUS 0x27800000
67 #define SGECVEC 0x108
68
69 static int ze_mainbus_match(device_t, cfdata_t, void *);
70 static void ze_mainbus_attach(device_t, device_t, void *);
71
72 static const struct sgec_data {
73 uint32_t sd_boardtype;
74 bus_addr_t sd_addr;
75 bus_addr_t sd_rom;
76 uint16_t sd_intvec;
77 uint8_t sd_romshift;
78 } sgec_data[] = {
79 { VAX_BTYP_660, SGECADDR, NISA_ROM, SGECVEC, 24, },
80 #if VXT2000 || VAXANY
81 { VAX_BTYP_VXT, SGECADDR, NISA_ROM_VXT, 0x200, 0, },
82 #endif
83 { VAX_BTYP_670, SGECADDR, NISA_ROM, SGECVEC, 8, },
84 { VAX_BTYP_680, SGECADDR, NISA_ROM, SGECVEC, 8, },
85 { VAX_BTYP_681, SGECADDR, NISA_ROM, SGECVEC, 8, },
86 { VAX_BTYP_48, SGECADDR, NISA_ROM_VSBUS, SGECVEC, 0, },
87 { VAX_BTYP_49, SGECADDR, NISA_ROM_VSBUS, SGECVEC, 0, },
88 { VAX_BTYP_53, SGECADDR, NISA_ROM, SGECVEC, 8, },
89 };
90
91 static const struct sgec_data *
92 ze_find(void)
93 {
94 size_t i;
95 const struct sgec_data *sd;
96 for (i = 0, sd = sgec_data; i < __arraycount(sgec_data); i++, sd++) {
97 if (vax_boardtype == sd->sd_boardtype)
98 return sd;
99 }
100
101 return NULL;
102 }
103
104 CFATTACH_DECL_NEW(ze_mainbus, sizeof(struct ze_softc),
105 ze_mainbus_match, ze_mainbus_attach, NULL, NULL);
106
107 /*
108 * Check for present SGEC.
109 */
110 int
111 ze_mainbus_match(device_t parent, cfdata_t cf, void *aux)
112 {
113 struct mainbus_attach_args * const ma = aux;
114
115 /*
116 * Should some more intelligent checking be done???
117 */
118 if (strcmp(ma->ma_type, "sgec"))
119 return 0;
120
121 return ze_find() != NULL;
122 }
123
124 /*
125 * Interface exists: make available by filling in network interface
126 * record. System will initialize the interface when it is ready
127 * to accept packets.
128 */
129 void
130 ze_mainbus_attach(device_t parent, device_t self, void *aux)
131 {
132 struct mainbus_attach_args * const ma = aux;
133 struct ze_softc * const sc = device_private(self);
134 const struct sgec_data * const sd = ze_find();
135 const uint32_t *ea;
136 size_t i;
137 int error;
138
139 sc->sc_dev = self;
140
141 /*
142 * Map in SGEC registers.
143 */
144 sc->sc_dmat = ma->ma_dmat;
145 sc->sc_iot = ma->ma_iot;
146 sc->sc_intvec = sd->sd_intvec;
147 error = bus_space_map(sc->sc_iot, sd->sd_addr, PAGE_SIZE, 0,
148 &sc->sc_ioh);
149 if (error) {
150 aprint_error(": failed to map %#lx: %d\n", sd->sd_addr, error);
151 return;
152 }
153
154 /*
155 * Map in, read and release ethernet rom address.
156 */
157 ea = (uint32_t *)vax_map_physmem(sd->sd_rom, 1);
158 for (i = 0; i < ETHER_ADDR_LEN; i++)
159 sc->sc_enaddr[i] = (ea[i] >> sd->sd_romshift) & 0377;
160 vax_unmap_physmem((vaddr_t)ea, 1);
161
162 scb_vecalloc(sc->sc_intvec, (void (*)(void *)) sgec_intr, sc,
163 SCB_ISTACK, &sc->sc_intrcnt);
164
165 sgec_attach(sc);
166 }
167