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