1 /* $NetBSD: if_le_vsbus.c,v 1.25 2009/03/18 17:06:47 cegger Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1992, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * Ralph Campbell and Rick Macklem.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
66 #include <sys/cdefs.h>
67 __KERNEL_RCSID(0, "$NetBSD: if_le_vsbus.c,v 1.25 2009/03/18 17:06:47 cegger Exp $");
72 #include <sys/param.h>
73 #include <sys/syslog.h>
74 #include <sys/socket.h>
75 #include <sys/device.h>
76 #include <sys/reboot.h>
78 #include <uvm/uvm_extern.h>
81 #include <net/if_ether.h>
82 #include <net/if_media.h>
85 #include <netinet/in.h>
86 #include <netinet/if_inarp.h>
89 #include <machine/cpu.h>
90 #include <machine/sid.h>
91 #include <machine/scb.h>
92 #include <machine/bus.h>
93 #include <machine/vsbus.h>
95 #include <dev/ic/lancereg.h>
96 #include <dev/ic/lancevar.h>
97 #include <dev/ic/am7990reg.h>
98 #include <dev/ic/am7990var.h>
103 struct am7990_softc sc_am7990
; /* Must be first */
104 struct evcnt sc_intrcnt
;
106 volatile uint16_t *sc_rap
;
107 volatile uint16_t *sc_rdp
;
110 static int le_vsbus_match(device_t
, cfdata_t
, void *);
111 static void le_vsbus_attach(device_t
, device_t
, void *);
112 static void lewrcsr(struct lance_softc
*, uint16_t, uint16_t);
113 static uint16_t lerdcsr(struct lance_softc
*, uint16_t);
115 CFATTACH_DECL_NEW(le_vsbus
, sizeof(struct le_softc
),
116 le_vsbus_match
, le_vsbus_attach
, NULL
, NULL
);
119 lewrcsr(struct lance_softc
*ls
, uint16_t port
, uint16_t val
)
121 struct le_softc
* const sc
= (void *)ls
;
128 lerdcsr(struct lance_softc
*ls
, uint16_t port
)
130 struct le_softc
* const sc
= (void *)ls
;
137 le_vsbus_match(device_t parent
, cfdata_t cf
, void *aux
)
139 struct vsbus_attach_args
* const va
= aux
;
140 volatile uint16_t *rdp
, *rap
;
141 struct leinit initblock
;
147 if (vax_boardtype
== VAX_BTYP_49
|| vax_boardtype
== VAX_BTYP_53
)
150 error
= bus_dmamap_create(va
->va_dmat
, sizeof(initblock
), 1,
151 sizeof(initblock
), 0, BUS_DMA_NOWAIT
, &map
);
156 error
= bus_dmamap_load(va
->va_dmat
, map
, &initblock
,
157 sizeof(initblock
), NULL
, BUS_DMA_NOWAIT
|BUS_DMA_COHERENT
);
159 bus_dmamap_destroy(va
->va_dmat
, map
);
163 memset(&initblock
, 0, sizeof(initblock
));
165 rdp
= (uint16_t *)va
->va_addr
;
168 /* Make sure the chip is stopped. */
173 *rdp
= map
->dm_segs
->ds_addr
& 0xffff;
175 *rdp
= (map
->dm_segs
->ds_addr
>> 16) & 0xffff;
177 *rdp
= LE_C0_INIT
|LE_C0_INEA
;
179 /* Wait for initialization to finish. */
180 for (i
= 100; i
>= 0; i
--) {
182 /* Should have interrupted by now */
183 if (*rdp
& LE_C0_IDON
)
189 bus_dmamap_unload(va
->va_dmat
, map
);
190 bus_dmamap_destroy(va
->va_dmat
, map
);
195 le_vsbus_attach(device_t parent
, device_t self
, void *aux
)
197 struct vsbus_attach_args
* const va
= aux
;
198 struct le_softc
* const sc
= device_private(self
);
199 bus_dma_segment_t seg
;
203 sc
->sc_am7990
.lsc
.sc_dev
= self
;
204 sc
->sc_rdp
= (uint16_t *) vax_map_physmem(NI_BASE
, 1);
205 sc
->sc_rap
= sc
->sc_rdp
+ 2;
210 sc
->sc_am7990
.lsc
.sc_rdcsr
= lerdcsr
;
211 sc
->sc_am7990
.lsc
.sc_wrcsr
= lewrcsr
;
212 sc
->sc_am7990
.lsc
.sc_nocarrier
= NULL
;
214 scb_vecalloc(va
->va_cvec
, (void (*)(void *)) am7990_intr
, sc
,
215 SCB_ISTACK
, &sc
->sc_intrcnt
);
216 evcnt_attach_dynamic(&sc
->sc_intrcnt
, EVCNT_TYPE_INTR
, NULL
,
217 device_xname(self
), "intr");
220 * Allocate a (DMA-safe) block for all descriptors and buffers.
223 #define ALLOCSIZ (64 * 1024)
224 err
= bus_dmamem_alloc(va
->va_dmat
, ALLOCSIZ
, PAGE_SIZE
, 0,
225 &seg
, 1, &rseg
, BUS_DMA_NOWAIT
);
227 aprint_error(": unable to alloc buffer block: err %d\n", err
);
230 err
= bus_dmamem_map(va
->va_dmat
, &seg
, rseg
, ALLOCSIZ
,
231 (void **)&sc
->sc_am7990
.lsc
.sc_mem
,
232 BUS_DMA_NOWAIT
|BUS_DMA_COHERENT
);
234 aprint_error(": unable to map buffer block: err %d\n", err
);
235 bus_dmamem_free(va
->va_dmat
, &seg
, rseg
);
238 bus_dmamap_create(va
->va_dmat
, ALLOCSIZ
, rseg
, ALLOCSIZ
,
239 0, BUS_DMA_NOWAIT
, &sc
->sc_dm
);
241 aprint_error(": unable to create DMA map: err %d\n", err
);
242 bus_dmamem_free(va
->va_dmat
, &seg
, rseg
);
245 err
= bus_dmamap_load(va
->va_dmat
, sc
->sc_dm
, sc
->sc_am7990
.lsc
.sc_mem
,
246 ALLOCSIZ
, NULL
, BUS_DMA_NOWAIT
);
248 aprint_error(": unable to load DMA map: err %d\n", err
);
249 bus_dmamap_destroy(va
->va_dmat
, sc
->sc_dm
);
250 bus_dmamem_free(va
->va_dmat
, &seg
, rseg
);
253 aprint_normal(" buf 0x%lx-0x%lx", sc
->sc_dm
->dm_segs
->ds_addr
,
254 sc
->sc_dm
->dm_segs
->ds_addr
+ sc
->sc_dm
->dm_segs
->ds_len
- 1);
255 sc
->sc_am7990
.lsc
.sc_addr
= sc
->sc_dm
->dm_segs
->ds_addr
& 0xffffff;
256 sc
->sc_am7990
.lsc
.sc_memsize
= sc
->sc_dm
->dm_segs
->ds_len
;
258 sc
->sc_am7990
.lsc
.sc_copytodesc
= lance_copytobuf_contig
;
259 sc
->sc_am7990
.lsc
.sc_copyfromdesc
= lance_copyfrombuf_contig
;
260 sc
->sc_am7990
.lsc
.sc_copytobuf
= lance_copytobuf_contig
;
261 sc
->sc_am7990
.lsc
.sc_copyfrombuf
= lance_copyfrombuf_contig
;
262 sc
->sc_am7990
.lsc
.sc_zerobuf
= lance_zerobuf_contig
;
265 sc
->sc_am7990
.lsc
.sc_debug
= 1;
268 * Get the ethernet address out of rom
270 lance_addr
= (int *)vax_map_physmem(NI_ADDR
, 1);
271 for (i
= 0; i
< ETHER_ADDR_LEN
; i
++)
272 sc
->sc_am7990
.lsc
.sc_enaddr
[i
] = (u_char
)lance_addr
[i
];
273 vax_unmap_physmem((vaddr_t
)lance_addr
, 1);
275 memcpy(sc
->sc_am7990
.lsc
.sc_ethercom
.ec_if
.if_xname
, device_xname(self
),
278 /* Prettier printout */
279 aprint_normal("\n%s", device_xname(self
));
281 am7990_config(&sc
->sc_am7990
);