if_ie_gsc.c revision 1.1.4.2 1 1.1.4.2 rmind /* $NetBSD: if_ie_gsc.c,v 1.1.4.2 2014/05/18 17:45:11 rmind Exp $ */
2 1.1.4.2 rmind
3 1.1.4.2 rmind /* $OpenBSD: if_ie_gsc.c,v 1.6 2001/01/12 22:57:04 mickey Exp $ */
4 1.1.4.2 rmind
5 1.1.4.2 rmind /*
6 1.1.4.2 rmind * Copyright (c) 1998-2004 Michael Shalayeff
7 1.1.4.2 rmind * All rights reserved.
8 1.1.4.2 rmind *
9 1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
10 1.1.4.2 rmind * modification, are permitted provided that the following conditions
11 1.1.4.2 rmind * are met:
12 1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
13 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer.
14 1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
16 1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
17 1.1.4.2 rmind *
18 1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1.4.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1.4.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1.4.2 rmind * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 1.1.4.2 rmind * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 1.1.4.2 rmind * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 1.1.4.2 rmind * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.1.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 1.1.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 1.1.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 1.1.4.2 rmind * THE POSSIBILITY OF SUCH DAMAGE.
29 1.1.4.2 rmind */
30 1.1.4.2 rmind
31 1.1.4.2 rmind /*
32 1.1.4.2 rmind * Referencies:
33 1.1.4.2 rmind * 1. 82596DX and 82596SX High-Perfomance 32-bit Local Area Network Coprocessor
34 1.1.4.2 rmind * Intel Corporation, November 1996, Order Number: 290219-006
35 1.1.4.2 rmind *
36 1.1.4.2 rmind * 2. 712 I/O Subsystem ERS Rev 1.0
37 1.1.4.2 rmind * Hewlett-Packard, June 17 1992, Dwg No. A-A2263-66510-31
38 1.1.4.2 rmind */
39 1.1.4.2 rmind
40 1.1.4.2 rmind #include <sys/cdefs.h>
41 1.1.4.2 rmind __KERNEL_RCSID(0, "$NetBSD: if_ie_gsc.c,v 1.1.4.2 2014/05/18 17:45:11 rmind Exp $");
42 1.1.4.2 rmind
43 1.1.4.2 rmind #include <sys/param.h>
44 1.1.4.2 rmind #include <sys/systm.h>
45 1.1.4.2 rmind #include <sys/device.h>
46 1.1.4.2 rmind #include <sys/socket.h>
47 1.1.4.2 rmind #include <sys/sockio.h>
48 1.1.4.2 rmind
49 1.1.4.2 rmind #include <uvm/uvm_extern.h>
50 1.1.4.2 rmind
51 1.1.4.2 rmind #include <net/if.h>
52 1.1.4.2 rmind #include <net/if_dl.h>
53 1.1.4.2 rmind #include <net/if_ether.h>
54 1.1.4.2 rmind #include <net/if_types.h>
55 1.1.4.2 rmind #include <net/if_media.h>
56 1.1.4.2 rmind
57 1.1.4.2 rmind #include <netinet/in.h>
58 1.1.4.2 rmind
59 1.1.4.2 rmind #include <sys/bus.h>
60 1.1.4.2 rmind #include <machine/intr.h>
61 1.1.4.2 rmind #include <machine/iomod.h>
62 1.1.4.2 rmind #include <machine/autoconf.h>
63 1.1.4.2 rmind
64 1.1.4.2 rmind #include <hppa/dev/cpudevs.h>
65 1.1.4.2 rmind #include <hppa/gsc/gscbusvar.h>
66 1.1.4.2 rmind #include <hppa/hppa/machdep.h>
67 1.1.4.2 rmind
68 1.1.4.2 rmind #include <dev/ic/i82586reg.h>
69 1.1.4.2 rmind #include <dev/ic/i82586var.h>
70 1.1.4.2 rmind
71 1.1.4.2 rmind #define I82596_DEBUG I82586_DEBUG
72 1.1.4.2 rmind
73 1.1.4.2 rmind #ifdef __for_reference_only
74 1.1.4.2 rmind struct ie_gsc_regs {
75 1.1.4.2 rmind uint32_t ie_reset;
76 1.1.4.2 rmind uint32_t ie_port;
77 1.1.4.2 rmind uint32_t ie_attn;
78 1.1.4.2 rmind };
79 1.1.4.2 rmind #endif
80 1.1.4.2 rmind
81 1.1.4.2 rmind #define IE_GSC_BANK_SZ (12)
82 1.1.4.2 rmind #define IE_GSC_REG_RESET (0)
83 1.1.4.2 rmind #define IE_GSC_REG_PORT (4)
84 1.1.4.2 rmind #define IE_GSC_REG_ATTN (8)
85 1.1.4.2 rmind
86 1.1.4.2 rmind #define IE_GSC_ALIGN(v) ((((u_int) (v)) + 0xf) & ~0xf)
87 1.1.4.2 rmind
88 1.1.4.2 rmind #define IE_GSC_SYSBUS (IE_SYSBUS_596_RSVD_SET | \
89 1.1.4.2 rmind IE_SYSBUS_596_82586 | \
90 1.1.4.2 rmind IE_SYSBUS_596_INTLOW | \
91 1.1.4.2 rmind IE_SYSBUS_596_TRGEXT | \
92 1.1.4.2 rmind IE_SYSBUS_596_BE)
93 1.1.4.2 rmind
94 1.1.4.2 rmind #define IE_SIZE 0x8000
95 1.1.4.2 rmind
96 1.1.4.2 rmind struct ie_gsc_softc {
97 1.1.4.2 rmind struct ie_softc ie;
98 1.1.4.2 rmind
99 1.1.4.2 rmind /* tag and handle to hppa-specific adapter registers. */
100 1.1.4.2 rmind bus_space_tag_t iot;
101 1.1.4.2 rmind bus_space_handle_t ioh;
102 1.1.4.2 rmind
103 1.1.4.2 rmind /* bus_dma_tag_t for the memory used by the adapter. */
104 1.1.4.2 rmind bus_dma_tag_t iemt;
105 1.1.4.2 rmind
106 1.1.4.2 rmind /* interrupt handle. */
107 1.1.4.2 rmind void *sc_ih;
108 1.1.4.2 rmind
109 1.1.4.2 rmind /* miscellaneous flags. */
110 1.1.4.2 rmind int flags;
111 1.1.4.2 rmind #define IEGSC_GECKO (1 << 0)
112 1.1.4.2 rmind };
113 1.1.4.2 rmind
114 1.1.4.2 rmind int ie_gsc_probe(device_t, cfdata_t, void *);
115 1.1.4.2 rmind void ie_gsc_attach(device_t, device_t, void *);
116 1.1.4.2 rmind
117 1.1.4.2 rmind CFATTACH_DECL_NEW(ie_gsc, sizeof(struct ie_gsc_softc),
118 1.1.4.2 rmind ie_gsc_probe, ie_gsc_attach, NULL, NULL);
119 1.1.4.2 rmind
120 1.1.4.2 rmind static int ie_gsc_media[] = {
121 1.1.4.2 rmind IFM_ETHER | IFM_10_2,
122 1.1.4.2 rmind };
123 1.1.4.2 rmind #define IE_NMEDIA (sizeof(ie_gsc_media) / sizeof(ie_gsc_media[0]))
124 1.1.4.2 rmind
125 1.1.4.2 rmind void ie_gsc_reset(struct ie_softc *, int);
126 1.1.4.2 rmind void ie_gsc_attend(struct ie_softc *, int);
127 1.1.4.2 rmind void ie_gsc_run(struct ie_softc *);
128 1.1.4.2 rmind void ie_gsc_port(struct ie_softc *, u_int);
129 1.1.4.2 rmind uint16_t ie_gsc_read16(struct ie_softc *, int);
130 1.1.4.2 rmind void ie_gsc_write16(struct ie_softc *, int, uint16_t);
131 1.1.4.2 rmind void ie_gsc_write24(struct ie_softc *, int, int);
132 1.1.4.2 rmind void ie_gsc_memcopyin(struct ie_softc *, void *, int, size_t);
133 1.1.4.2 rmind void ie_gsc_memcopyout(struct ie_softc *, const void *, int, size_t);
134 1.1.4.2 rmind
135 1.1.4.2 rmind
136 1.1.4.2 rmind /* Reset the adapter. */
137 1.1.4.2 rmind void
138 1.1.4.2 rmind ie_gsc_reset(struct ie_softc *sc, int what)
139 1.1.4.2 rmind {
140 1.1.4.2 rmind struct ie_gsc_softc *gsc = (struct ie_gsc_softc *) sc;
141 1.1.4.2 rmind int i;
142 1.1.4.2 rmind
143 1.1.4.2 rmind switch (what) {
144 1.1.4.2 rmind case CHIP_PROBE:
145 1.1.4.2 rmind bus_space_write_4(gsc->iot, gsc->ioh, IE_GSC_REG_RESET, 0);
146 1.1.4.2 rmind break;
147 1.1.4.2 rmind
148 1.1.4.2 rmind case CARD_RESET:
149 1.1.4.2 rmind bus_space_write_4(gsc->iot, gsc->ioh, IE_GSC_REG_RESET, 0);
150 1.1.4.2 rmind
151 1.1.4.2 rmind /*
152 1.1.4.2 rmind * per [2] 4.6.2.1
153 1.1.4.2 rmind * delay for 10 system clocks + 5 transmit clocks,
154 1.1.4.2 rmind * NB: works for system clocks over 10MHz
155 1.1.4.2 rmind */
156 1.1.4.2 rmind DELAY(1000);
157 1.1.4.2 rmind
158 1.1.4.2 rmind /*
159 1.1.4.2 rmind * after the hardware reset:
160 1.1.4.2 rmind * inform i825[89]6 about new SCP address,
161 1.1.4.2 rmind * which must be at least 16-byte aligned
162 1.1.4.2 rmind */
163 1.1.4.2 rmind ie_gsc_port(sc, IE_PORT_ALT_SCP);
164 1.1.4.2 rmind ie_gsc_attend(sc, what);
165 1.1.4.2 rmind
166 1.1.4.2 rmind for (i = 9000; i-- && ie_gsc_read16(sc, IE_ISCP_BUSY(sc->iscp));
167 1.1.4.2 rmind DELAY(100))
168 1.1.4.2 rmind pdcache(0, (vaddr_t)sc->sc_maddr + sc->iscp, IE_ISCP_SZ);
169 1.1.4.2 rmind
170 1.1.4.2 rmind #if I82596_DEBUG
171 1.1.4.2 rmind if (i < 0) {
172 1.1.4.2 rmind printf("timeout for PORT command (%x)%s\n",
173 1.1.4.2 rmind ie_gsc_read16(sc, IE_ISCP_BUSY(sc->iscp)),
174 1.1.4.2 rmind (gsc->flags & IEGSC_GECKO)? " on gecko":"");
175 1.1.4.2 rmind return;
176 1.1.4.2 rmind }
177 1.1.4.2 rmind #endif
178 1.1.4.2 rmind break;
179 1.1.4.2 rmind }
180 1.1.4.2 rmind }
181 1.1.4.2 rmind
182 1.1.4.2 rmind /* Do a channel attention on the adapter. */
183 1.1.4.2 rmind void
184 1.1.4.2 rmind ie_gsc_attend(struct ie_softc *sc, int why)
185 1.1.4.2 rmind {
186 1.1.4.2 rmind struct ie_gsc_softc *gsc = (struct ie_gsc_softc *) sc;
187 1.1.4.2 rmind
188 1.1.4.2 rmind bus_space_write_4(gsc->iot, gsc->ioh, IE_GSC_REG_ATTN, 0);
189 1.1.4.2 rmind }
190 1.1.4.2 rmind
191 1.1.4.2 rmind /* Enable the adapter. */
192 1.1.4.2 rmind void
193 1.1.4.2 rmind ie_gsc_run(struct ie_softc *sc)
194 1.1.4.2 rmind {
195 1.1.4.2 rmind }
196 1.1.4.2 rmind
197 1.1.4.2 rmind /* Run an i82596 PORT command on the adapter. */
198 1.1.4.2 rmind void
199 1.1.4.2 rmind ie_gsc_port(struct ie_softc *sc, u_int cmd)
200 1.1.4.2 rmind {
201 1.1.4.2 rmind struct ie_gsc_softc *gsc = (struct ie_gsc_softc *) sc;
202 1.1.4.2 rmind
203 1.1.4.2 rmind switch (cmd) {
204 1.1.4.2 rmind case IE_PORT_RESET:
205 1.1.4.2 rmind case IE_PORT_DUMP:
206 1.1.4.2 rmind break;
207 1.1.4.2 rmind case IE_PORT_SELF_TEST:
208 1.1.4.2 rmind cmd |= (sc->sc_dmamap->dm_segs[0].ds_addr + 0);
209 1.1.4.2 rmind break;
210 1.1.4.2 rmind case IE_PORT_ALT_SCP:
211 1.1.4.2 rmind cmd |= (sc->sc_dmamap->dm_segs[0].ds_addr + sc->scp);
212 1.1.4.2 rmind break;
213 1.1.4.2 rmind }
214 1.1.4.2 rmind
215 1.1.4.2 rmind if (gsc->flags & IEGSC_GECKO) {
216 1.1.4.2 rmind bus_space_write_4(gsc->iot, gsc->ioh,
217 1.1.4.2 rmind IE_GSC_REG_PORT, (cmd & 0xffff));
218 1.1.4.2 rmind DELAY(1000);
219 1.1.4.2 rmind bus_space_write_4(gsc->iot, gsc->ioh,
220 1.1.4.2 rmind IE_GSC_REG_PORT, (cmd >> 16));
221 1.1.4.2 rmind DELAY(1000);
222 1.1.4.2 rmind } else {
223 1.1.4.2 rmind bus_space_write_4(gsc->iot, gsc->ioh,
224 1.1.4.2 rmind IE_GSC_REG_PORT, (cmd >> 16));
225 1.1.4.2 rmind DELAY(1000);
226 1.1.4.2 rmind bus_space_write_4(gsc->iot, gsc->ioh,
227 1.1.4.2 rmind IE_GSC_REG_PORT, (cmd & 0xffff));
228 1.1.4.2 rmind DELAY(1000);
229 1.1.4.2 rmind }
230 1.1.4.2 rmind }
231 1.1.4.2 rmind
232 1.1.4.2 rmind uint16_t
233 1.1.4.2 rmind ie_gsc_read16(struct ie_softc *sc, int offset)
234 1.1.4.2 rmind {
235 1.1.4.2 rmind uint16_t val;
236 1.1.4.2 rmind
237 1.1.4.2 rmind __asm volatile(
238 1.1.4.2 rmind " ldh 0(%1), %0 \n"
239 1.1.4.2 rmind " fdc %%r0(%1) \n"
240 1.1.4.2 rmind : "=&r" (val)
241 1.1.4.2 rmind : "r" ((char *)sc->sc_maddr + offset));
242 1.1.4.2 rmind return (val);
243 1.1.4.2 rmind }
244 1.1.4.2 rmind
245 1.1.4.2 rmind void
246 1.1.4.2 rmind ie_gsc_write16(struct ie_softc *sc, int offset, uint16_t v)
247 1.1.4.2 rmind {
248 1.1.4.2 rmind
249 1.1.4.2 rmind __asm volatile(
250 1.1.4.2 rmind " sth %0, 0(%1) \n"
251 1.1.4.2 rmind " fdc %%r0(%1) \n"
252 1.1.4.2 rmind : /* no outputs */
253 1.1.4.2 rmind : "r" (v), "r" ((char *)sc->sc_maddr + offset));
254 1.1.4.2 rmind }
255 1.1.4.2 rmind
256 1.1.4.2 rmind void
257 1.1.4.2 rmind ie_gsc_write24(struct ie_softc *sc, int offset, int addr)
258 1.1.4.2 rmind {
259 1.1.4.2 rmind
260 1.1.4.2 rmind /*
261 1.1.4.2 rmind * i82586.c assumes that the chip address space starts at
262 1.1.4.2 rmind * zero, so we have to add in the appropriate offset here.
263 1.1.4.2 rmind */
264 1.1.4.2 rmind addr += sc->sc_dmamap->dm_segs[0].ds_addr;
265 1.1.4.2 rmind __asm volatile(
266 1.1.4.2 rmind " ldi 2, %%r21 \n"
267 1.1.4.2 rmind " extru %0, 15, 16, %%r22 \n"
268 1.1.4.2 rmind " sth %0, 0(%1) \n"
269 1.1.4.2 rmind " sth %%r22, 2(%1) \n"
270 1.1.4.2 rmind " fdc %%r0(%1) \n"
271 1.1.4.2 rmind " fdc %%r21(%1) \n"
272 1.1.4.2 rmind : /* No outputs */
273 1.1.4.2 rmind : "r" (addr), "r" ((char *)sc->sc_maddr + offset)
274 1.1.4.2 rmind : "r21", "r22");
275 1.1.4.2 rmind }
276 1.1.4.2 rmind
277 1.1.4.2 rmind void
278 1.1.4.2 rmind ie_gsc_memcopyin(struct ie_softc *sc, void *p, int offset, size_t size)
279 1.1.4.2 rmind {
280 1.1.4.2 rmind struct ie_gsc_softc *gsc = (struct ie_gsc_softc *) sc;
281 1.1.4.2 rmind
282 1.1.4.2 rmind if (size == 0)
283 1.1.4.2 rmind return;
284 1.1.4.2 rmind
285 1.1.4.2 rmind memcpy(p, (char *)sc->sc_maddr + offset, size);
286 1.1.4.2 rmind bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, offset, size,
287 1.1.4.2 rmind BUS_DMASYNC_PREREAD);
288 1.1.4.2 rmind hppa_led_blink(HPPA_LED_NETRCV);
289 1.1.4.2 rmind }
290 1.1.4.2 rmind
291 1.1.4.2 rmind void
292 1.1.4.2 rmind ie_gsc_memcopyout(struct ie_softc *sc, const void *p, int offset, size_t size)
293 1.1.4.2 rmind {
294 1.1.4.2 rmind struct ie_gsc_softc *gsc = (struct ie_gsc_softc *) sc;
295 1.1.4.2 rmind
296 1.1.4.2 rmind if (size == 0)
297 1.1.4.2 rmind return;
298 1.1.4.2 rmind
299 1.1.4.2 rmind memcpy((char *)sc->sc_maddr + offset, p, size);
300 1.1.4.2 rmind bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, offset, size,
301 1.1.4.2 rmind BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
302 1.1.4.2 rmind hppa_led_blink(HPPA_LED_NETSND);
303 1.1.4.2 rmind }
304 1.1.4.2 rmind
305 1.1.4.2 rmind /*
306 1.1.4.2 rmind * i82596 probe routine
307 1.1.4.2 rmind */
308 1.1.4.2 rmind int i82596_probe(struct ie_softc *);
309 1.1.4.2 rmind int
310 1.1.4.2 rmind i82596_probe(struct ie_softc *sc)
311 1.1.4.2 rmind {
312 1.1.4.2 rmind struct ie_gsc_softc *gsc = (struct ie_gsc_softc *) sc;
313 1.1.4.2 rmind int i;
314 1.1.4.2 rmind
315 1.1.4.2 rmind /* Set up the SCP. */
316 1.1.4.2 rmind sc->ie_bus_write16(sc, IE_SCP_BUS_USE(sc->scp), IE_GSC_SYSBUS);
317 1.1.4.2 rmind sc->ie_bus_write24(sc, IE_SCP_ISCP(sc->scp), sc->iscp);
318 1.1.4.2 rmind
319 1.1.4.2 rmind /* Set up the ISCP. */
320 1.1.4.2 rmind sc->ie_bus_write16(sc, IE_ISCP_SCB(sc->iscp), sc->scb);
321 1.1.4.2 rmind sc->ie_bus_write24(sc, IE_ISCP_BASE(sc->iscp), 0);
322 1.1.4.2 rmind
323 1.1.4.2 rmind /* Set BUSY in the ISCP. */
324 1.1.4.2 rmind sc->ie_bus_write16(sc, IE_ISCP_BUSY(sc->iscp), 1);
325 1.1.4.2 rmind
326 1.1.4.2 rmind /* Reset the adapter. */
327 1.1.4.2 rmind bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
328 1.1.4.2 rmind BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
329 1.1.4.2 rmind sc->hwreset(sc, CARD_RESET);
330 1.1.4.2 rmind
331 1.1.4.2 rmind /* Make sure that BUSY got cleared. */
332 1.1.4.2 rmind if (sc->ie_bus_read16(sc, IE_ISCP_BUSY(sc->iscp))) {
333 1.1.4.2 rmind #if I82596_DEBUG
334 1.1.4.2 rmind printf ("%s: ISCP set failed\n", device_xname(sc->sc_dev));
335 1.1.4.2 rmind #endif
336 1.1.4.2 rmind return 0;
337 1.1.4.2 rmind }
338 1.1.4.2 rmind
339 1.1.4.2 rmind /* Run the chip self-test. */
340 1.1.4.2 rmind sc->ie_bus_write24(sc, 0, -sc->sc_dmamap->dm_segs[0].ds_addr);
341 1.1.4.2 rmind sc->ie_bus_write24(sc, 4, -(sc->sc_dmamap->dm_segs[0].ds_addr + 1));
342 1.1.4.2 rmind bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
343 1.1.4.2 rmind BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
344 1.1.4.2 rmind ie_gsc_port(sc, IE_PORT_SELF_TEST);
345 1.1.4.2 rmind for (i = 9000; i-- &&
346 1.1.4.2 rmind sc->ie_bus_read16(sc, 4);
347 1.1.4.2 rmind DELAY(100))
348 1.1.4.2 rmind pdcache(0, (vaddr_t)sc->sc_maddr, sc->sc_msize);
349 1.1.4.2 rmind
350 1.1.4.2 rmind #if I82596_DEBUG
351 1.1.4.2 rmind printf (": test %x:%x\n%s",
352 1.1.4.2 rmind *((volatile int32_t *)((char *)sc->sc_maddr + 0)),
353 1.1.4.2 rmind *((volatile int32_t *)((char *)sc->sc_maddr + 4)),
354 1.1.4.2 rmind device_xname(sc->sc_dev));
355 1.1.4.2 rmind #endif
356 1.1.4.2 rmind return 1;
357 1.1.4.2 rmind }
358 1.1.4.2 rmind
359 1.1.4.2 rmind int
360 1.1.4.2 rmind ie_gsc_probe(device_t parent, cfdata_t match, void *aux)
361 1.1.4.2 rmind {
362 1.1.4.2 rmind struct gsc_attach_args *ga = aux;
363 1.1.4.2 rmind
364 1.1.4.2 rmind if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
365 1.1.4.2 rmind (ga->ga_type.iodc_sv_model != HPPA_FIO_LAN &&
366 1.1.4.2 rmind ga->ga_type.iodc_sv_model != HPPA_FIO_GLAN))
367 1.1.4.2 rmind return 0;
368 1.1.4.2 rmind
369 1.1.4.2 rmind return 1;
370 1.1.4.2 rmind }
371 1.1.4.2 rmind
372 1.1.4.2 rmind void
373 1.1.4.2 rmind ie_gsc_attach(device_t parent, device_t self, void *aux)
374 1.1.4.2 rmind {
375 1.1.4.2 rmind struct ie_gsc_softc *gsc = device_private(self);
376 1.1.4.2 rmind struct ie_softc *sc = &gsc->ie;
377 1.1.4.2 rmind struct gsc_attach_args *ga = aux;
378 1.1.4.2 rmind bus_dma_segment_t seg;
379 1.1.4.2 rmind int rseg;
380 1.1.4.2 rmind int rv;
381 1.1.4.2 rmind uint8_t myaddr[ETHER_ADDR_LEN];
382 1.1.4.2 rmind #ifdef PMAPDEBUG
383 1.1.4.2 rmind extern int pmapdebug;
384 1.1.4.2 rmind int opmapdebug = pmapdebug;
385 1.1.4.2 rmind pmapdebug = 0;
386 1.1.4.2 rmind #endif
387 1.1.4.2 rmind
388 1.1.4.2 rmind if (ga->ga_type.iodc_sv_model == HPPA_FIO_GLAN)
389 1.1.4.2 rmind gsc->flags |= IEGSC_GECKO;
390 1.1.4.2 rmind
391 1.1.4.2 rmind /*
392 1.1.4.2 rmind * Map the GSC registers.
393 1.1.4.2 rmind */
394 1.1.4.2 rmind if (bus_space_map(ga->ga_iot, ga->ga_hpa,
395 1.1.4.2 rmind IE_GSC_BANK_SZ, 0, &gsc->ioh)) {
396 1.1.4.2 rmind printf(": can't map i/o space\n");
397 1.1.4.2 rmind return;
398 1.1.4.2 rmind }
399 1.1.4.2 rmind
400 1.1.4.2 rmind /* Set up some initial glue. */
401 1.1.4.2 rmind sc->sc_dev = self;
402 1.1.4.2 rmind gsc->iot = ga->ga_iot;
403 1.1.4.2 rmind gsc->iemt = ga->ga_dmatag;
404 1.1.4.2 rmind sc->bt = ga->ga_iot;
405 1.1.4.2 rmind sc->sc_msize = IE_SIZE;
406 1.1.4.2 rmind
407 1.1.4.2 rmind /*
408 1.1.4.2 rmind * Allocate one contiguous segment of physical memory
409 1.1.4.2 rmind * to be used with the i82596. Since we're running the
410 1.1.4.2 rmind * chip in i82586 mode, we're restricted to 24-bit
411 1.1.4.2 rmind * physical addresses.
412 1.1.4.2 rmind */
413 1.1.4.2 rmind if (bus_dmamem_alloc(gsc->iemt, sc->sc_msize, PAGE_SIZE, 0,
414 1.1.4.2 rmind &seg, 1, &rseg, BUS_DMA_NOWAIT | BUS_DMA_24BIT)) {
415 1.1.4.2 rmind printf (": can't allocate %d bytes of DMA memory\n",
416 1.1.4.2 rmind sc->sc_msize);
417 1.1.4.2 rmind return;
418 1.1.4.2 rmind }
419 1.1.4.2 rmind
420 1.1.4.2 rmind /*
421 1.1.4.2 rmind * Map that physical memory into kernel virtual space.
422 1.1.4.2 rmind */
423 1.1.4.2 rmind if (bus_dmamem_map(gsc->iemt, &seg, rseg, sc->sc_msize,
424 1.1.4.2 rmind (void **)&sc->sc_maddr, BUS_DMA_NOWAIT)) {
425 1.1.4.2 rmind printf (": can't map DMA memory\n");
426 1.1.4.2 rmind bus_dmamem_free(gsc->iemt, &seg, rseg);
427 1.1.4.2 rmind return;
428 1.1.4.2 rmind }
429 1.1.4.2 rmind
430 1.1.4.2 rmind /*
431 1.1.4.2 rmind * Create a DMA map for the memory.
432 1.1.4.2 rmind */
433 1.1.4.2 rmind if (bus_dmamap_create(gsc->iemt, sc->sc_msize, rseg, sc->sc_msize,
434 1.1.4.2 rmind 0, BUS_DMA_NOWAIT, &sc->sc_dmamap)) {
435 1.1.4.2 rmind printf(": can't create DMA map\n");
436 1.1.4.2 rmind bus_dmamem_unmap(gsc->iemt,
437 1.1.4.2 rmind (void *)sc->sc_maddr, sc->sc_msize);
438 1.1.4.2 rmind bus_dmamem_free(gsc->iemt, &seg, rseg);
439 1.1.4.2 rmind return;
440 1.1.4.2 rmind }
441 1.1.4.2 rmind
442 1.1.4.2 rmind /*
443 1.1.4.2 rmind * Load the mapped DMA memory into the DMA map.
444 1.1.4.2 rmind */
445 1.1.4.2 rmind if (bus_dmamap_load(gsc->iemt, sc->sc_dmamap,
446 1.1.4.2 rmind sc->sc_maddr, sc->sc_msize,
447 1.1.4.2 rmind NULL, BUS_DMA_NOWAIT)) {
448 1.1.4.2 rmind printf(": can't load DMA map\n");
449 1.1.4.2 rmind bus_dmamap_destroy(gsc->iemt, sc->sc_dmamap);
450 1.1.4.2 rmind bus_dmamem_unmap(gsc->iemt,
451 1.1.4.2 rmind (void *)sc->sc_maddr, sc->sc_msize);
452 1.1.4.2 rmind bus_dmamem_free(gsc->iemt, &seg, rseg);
453 1.1.4.2 rmind return;
454 1.1.4.2 rmind }
455 1.1.4.2 rmind
456 1.1.4.2 rmind #if 1
457 1.1.4.2 rmind /* XXX - this should go away. */
458 1.1.4.2 rmind sc->bh = (bus_space_handle_t) sc->sc_maddr;
459 1.1.4.2 rmind #endif
460 1.1.4.2 rmind
461 1.1.4.2 rmind #if I82596_DEBUG
462 1.1.4.2 rmind printf(" mem %x[%p]/%x\n%s",
463 1.1.4.2 rmind (u_int)sc->sc_dmamap->dm_segs[0].ds_addr,
464 1.1.4.2 rmind sc->sc_maddr,
465 1.1.4.2 rmind sc->sc_msize,
466 1.1.4.2 rmind device_xname(self));
467 1.1.4.2 rmind sc->sc_debug = IED_ALL;
468 1.1.4.2 rmind #endif
469 1.1.4.2 rmind
470 1.1.4.2 rmind /* Initialize our bus glue. */
471 1.1.4.2 rmind sc->hwreset = ie_gsc_reset;
472 1.1.4.2 rmind sc->chan_attn = ie_gsc_attend;
473 1.1.4.2 rmind sc->hwinit = ie_gsc_run;
474 1.1.4.2 rmind sc->memcopyout = ie_gsc_memcopyout;
475 1.1.4.2 rmind sc->memcopyin = ie_gsc_memcopyin;
476 1.1.4.2 rmind sc->ie_bus_read16 = ie_gsc_read16;
477 1.1.4.2 rmind sc->ie_bus_write16 = ie_gsc_write16;
478 1.1.4.2 rmind sc->ie_bus_write24 = ie_gsc_write24;
479 1.1.4.2 rmind sc->intrhook = NULL;
480 1.1.4.2 rmind
481 1.1.4.2 rmind /* Clear all RAM. */
482 1.1.4.2 rmind memset(sc->sc_maddr, 0, sc->sc_msize);
483 1.1.4.2 rmind bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
484 1.1.4.2 rmind BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
485 1.1.4.2 rmind
486 1.1.4.2 rmind /*
487 1.1.4.2 rmind * We use low memory to set up SCP, ICSP and SCB data
488 1.1.4.2 rmind * structures. The remaining pages become the buffer area
489 1.1.4.2 rmind * (managed in i82586.c).
490 1.1.4.2 rmind */
491 1.1.4.2 rmind
492 1.1.4.2 rmind /*
493 1.1.4.2 rmind * Since we have an i82596, we can control where where
494 1.1.4.2 rmind * the chip looks for SCP. We plan to use the first
495 1.1.4.2 rmind * two 32-bit words of memory for the self-test, so the
496 1.1.4.2 rmind * SCP can go after that.
497 1.1.4.2 rmind */
498 1.1.4.2 rmind sc->scp = IE_GSC_ALIGN(8);
499 1.1.4.2 rmind
500 1.1.4.2 rmind /* ISCP follows SCP */
501 1.1.4.2 rmind sc->iscp = IE_GSC_ALIGN(sc->scp + IE_SCP_SZ);
502 1.1.4.2 rmind
503 1.1.4.2 rmind /* SCB follows ISCP */
504 1.1.4.2 rmind sc->scb = IE_GSC_ALIGN(sc->iscp + IE_ISCP_SZ);
505 1.1.4.2 rmind
506 1.1.4.2 rmind /* The remainder of the memory is for buffers. */
507 1.1.4.2 rmind sc->buf_area = IE_GSC_ALIGN(sc->scb + IE_SCB_SZ);
508 1.1.4.2 rmind sc->buf_area_sz = sc->sc_msize - sc->buf_area;
509 1.1.4.2 rmind
510 1.1.4.2 rmind /* Finally, we can probe the chip. */
511 1.1.4.2 rmind rv = i82596_probe(sc);
512 1.1.4.2 rmind if (!rv) {
513 1.1.4.2 rmind bus_dmamap_destroy(gsc->iemt, sc->sc_dmamap);
514 1.1.4.2 rmind bus_dmamem_unmap(gsc->iemt,
515 1.1.4.2 rmind (void *)sc->sc_maddr, sc->sc_msize);
516 1.1.4.2 rmind bus_dmamem_free(gsc->iemt, &seg, rseg);
517 1.1.4.2 rmind return;
518 1.1.4.2 rmind }
519 1.1.4.2 rmind #ifdef PMAPDEBUG
520 1.1.4.2 rmind pmapdebug = opmapdebug;
521 1.1.4.2 rmind #endif
522 1.1.4.2 rmind if (!rv)
523 1.1.4.2 rmind return;
524 1.1.4.2 rmind
525 1.1.4.2 rmind /* Get our Ethernet address. */
526 1.1.4.2 rmind memcpy(myaddr, ga->ga_ether_address, ETHER_ADDR_LEN);
527 1.1.4.2 rmind
528 1.1.4.2 rmind /* Set up the SCP. */
529 1.1.4.2 rmind sc->ie_bus_write16(sc, IE_SCP_BUS_USE(sc->scp), IE_GSC_SYSBUS);
530 1.1.4.2 rmind sc->ie_bus_write24(sc, IE_SCP_ISCP(sc->scp), sc->iscp);
531 1.1.4.2 rmind
532 1.1.4.2 rmind /* Set up the ISCP. */
533 1.1.4.2 rmind sc->ie_bus_write16(sc, IE_ISCP_SCB(sc->iscp), sc->scb);
534 1.1.4.2 rmind sc->ie_bus_write24(sc, IE_ISCP_BASE(sc->iscp), 0);
535 1.1.4.2 rmind
536 1.1.4.2 rmind /* Set BUSY in the ISCP. */
537 1.1.4.2 rmind sc->ie_bus_write16(sc, IE_ISCP_BUSY(sc->iscp), 1);
538 1.1.4.2 rmind
539 1.1.4.2 rmind /* Reset the adapter. */
540 1.1.4.2 rmind bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
541 1.1.4.2 rmind BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
542 1.1.4.2 rmind sc->hwreset(sc, CARD_RESET);
543 1.1.4.2 rmind bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
544 1.1.4.2 rmind BUS_DMASYNC_PREREAD);
545 1.1.4.2 rmind
546 1.1.4.2 rmind /* Now call the MI attachment. */
547 1.1.4.2 rmind printf(": v%d.%d", ga->ga_type.iodc_model, ga->ga_type.iodc_sv_rev);
548 1.1.4.2 rmind i82586_attach(sc,
549 1.1.4.2 rmind (gsc->flags & IEGSC_GECKO) ?
550 1.1.4.2 rmind "LASI/i82596CA" :
551 1.1.4.2 rmind "i82596DX",
552 1.1.4.2 rmind myaddr, ie_gsc_media, IE_NMEDIA, ie_gsc_media[0]);
553 1.1.4.2 rmind gsc->sc_ih = hppa_intr_establish(IPL_NET, i82586_intr, sc,
554 1.1.4.2 rmind ga->ga_ir, ga->ga_irq);
555 1.1.4.2 rmind }
556