1 /* $NetBSD: if_ie_vme.c,v 1.22 2008/04/28 20:23:37 martin Exp $ */
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
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 * Machine-dependent glue for the Intel Ethernet (ie) driver.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: if_ie_vme.c,v 1.22 2008/04/28 20:23:37 martin Exp $");
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44 #include <sys/protosw.h>
45 #include <sys/socket.h>
47 #include <net/if_ether.h>
50 #include <netinet/in.h>
51 #include <netinet/in_systm.h>
52 #include <netinet/in_var.h>
53 #include <netinet/ip.h>
54 #include <netinet/if_inarp.h>
57 #include <machine/autoconf.h>
58 #include <machine/cpu.h>
59 #include <machine/dvma.h>
60 #include <machine/idprom.h>
61 #include <machine/vmparam.h>
67 static void ie_vmereset(struct ie_softc
*);
68 static void ie_vmeattend(struct ie_softc
*);
69 static void ie_vmerun(struct ie_softc
*);
72 * zero/copy functions: OBIO can use the normal functions, but VME
73 * must do only byte or half-word (16 bit) accesses...
75 static void *wmemcpy(void *, const void *, size_t);
76 static void *wmemset(void *, int, size_t);
80 * New-style autoconfig attachment
83 static int ie_vme_match(device_t
, cfdata_t
, void *);
84 static void ie_vme_attach(device_t
, device_t
, void *);
86 CFATTACH_DECL_NEW(ie_vme
, sizeof(struct ie_softc
),
87 ie_vme_match
, ie_vme_attach
, NULL
, NULL
);
90 ie_vme_match(device_t parent
, cfdata_t cf
, void *args
)
92 struct confargs
*ca
= args
;
94 /* No default VME address. */
95 if (ca
->ca_paddr
== -1)
98 /* Make sure something is there... */
99 if (bus_peek(ca
->ca_bustype
, ca
->ca_paddr
, 2) == -1)
102 /* Default interrupt priority. */
103 if (ca
->ca_intpri
== -1)
110 * *note*: we don't detect the difference between a VME3E and
111 * a multibus/vme card. if you want to use a 3E you'll have
115 ie_vme_attach(device_t parent
, device_t self
, void *args
)
117 struct ie_softc
*sc
= device_private(self
);
118 struct confargs
*ca
= args
;
119 volatile struct ievme
*iev
;
124 sc
->hard_type
= IE_VME
;
125 sc
->reset_586
= ie_vmereset
;
126 sc
->chan_attn
= ie_vmeattend
;
127 sc
->run_586
= ie_vmerun
;
128 sc
->sc_memcpy
= wmemcpy
;
129 sc
->sc_memset
= wmemset
;
132 * There is 64K of memory on the VME board.
133 * (determined by hardware - NOT configurable!)
135 sc
->sc_msize
= 0x10000; /* MEMSIZE 64K */
137 /* Map in the board control regs. */
138 sc
->sc_reg
= bus_mapin(ca
->ca_bustype
, ca
->ca_paddr
,
139 sizeof(struct ievme
));
140 iev
= (volatile struct ievme
*) sc
->sc_reg
;
143 * Find and map in the board memory.
146 rampaddr
= ca
->ca_paddr
& 0xfff00000;
148 rampaddr
|= ((iev
->status
& IEVME_HADDR
) << 16);
149 sc
->sc_maddr
= bus_mapin(ca
->ca_bustype
, rampaddr
, sc
->sc_msize
);
152 * On this hardware, the i82586 address is just
153 * masked to 16 bits, so sc_iobase == sc_maddr
155 sc
->sc_iobase
= sc
->sc_maddr
;
158 * Set up on-board mapping registers for linear map.
160 iev
->pectrl
|= IEVME_PARACK
; /* clear to start */
161 for (lcv
= 0; lcv
< IEVME_MAPSZ
; lcv
++)
162 iev
->pgmap
[lcv
] = IEVME_SBORDR
| IEVME_OBMEM
| lcv
;
163 (sc
->sc_memset
)(sc
->sc_maddr
, 0, sc
->sc_msize
);
166 * Set the System Configuration Pointer (SCP).
167 * Its location is system-dependent because the
168 * i82586 reads it from a fixed physical address.
169 * On this hardware, the i82586 address is just
170 * masked down to 16 bits, so the SCP is found
171 * at the end of the RAM on the VME board.
173 off
= IE_SCP_ADDR
& 0xFFFF;
174 sc
->scp
= (volatile void *)((char *)sc
->sc_maddr
+ off
);
177 * The rest of ram is used for buffers, etc.
179 sc
->buf_area
= sc
->sc_maddr
;
180 sc
->buf_area_sz
= off
;
182 /* Set the ethernet address. */
183 idprom_etheraddr(sc
->sc_addr
);
185 /* Do machine-independent parts of attach. */
188 /* Install interrupt handler. */
189 isr_add_vectored(ie_intr
, sc
, ca
->ca_intpri
, ca
->ca_intvec
);
194 * MULTIBUS/VME support
198 ie_vmeattend(struct ie_softc
*sc
)
200 volatile struct ievme
*iev
= (struct ievme
*)sc
->sc_reg
;
202 iev
->status
|= IEVME_ATTEN
; /* flag! */
203 iev
->status
&= ~IEVME_ATTEN
; /* down. */
207 ie_vmereset(struct ie_softc
*sc
)
209 volatile struct ievme
*iev
= (struct ievme
*)sc
->sc_reg
;
211 iev
->status
= IEVME_RESET
;
213 iev
->status
= (IEVME_ONAIR
| IEVME_IENAB
| IEVME_PEINT
);
217 ie_vmerun(struct ie_softc
*sc
)
220 /* do it all in reset */
224 * wmemcpy/wmemset - like memcpy/memset but largest access is 16-bits,
225 * and also does byte swaps...
226 * XXX - Would be nice to have asm versions in some library...
230 wmemset(void *vb
, int val
, size_t l
)
244 if (b
!= be
&& ((uint32_t)be
& 1) != 0) {
251 while (sp
!= (uint16_t *)be
)
258 wmemcpy(void *dst
, const void *src
, size_t l
)
260 const uint8_t *b1e
, *b1
= src
;
269 if ((uint32_t)b1
& 1) {
275 sp
= (const uint16_t *)b1
;
279 bstore
= (uint32_t)b2
& 1;
281 while (sp
< (const uint16_t *)b1e
) {
286 *((uint16_t *)b2
) = *sp
;