1 /* $NetBSD: if_ie_sebuf.c,v 1.15 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,
34 * as found on the Sun3/E SCSI/Ethernet board.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: if_ie_sebuf.c,v 1.15 2008/04/28 20:23:37 martin Exp $");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/protosw.h>
46 #include <sys/socket.h>
48 #include <net/if_ether.h>
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/in_var.h>
54 #include <netinet/ip.h>
55 #include <netinet/if_inarp.h>
58 #include <machine/autoconf.h>
59 #include <machine/cpu.h>
60 #include <machine/dvma.h>
61 #include <machine/idprom.h>
62 #include <machine/vmparam.h>
70 static void ie_sebuf_reset(struct ie_softc
*);
71 static void ie_sebuf_attend(struct ie_softc
*);
72 static void ie_sebuf_run(struct ie_softc
*);
75 * zero/copy functions: OBIO can use the normal functions, but VME
76 * must do only byte or half-word (16 bit) accesses...
78 static void *wmemcpy(void *, const void *, size_t);
79 static void *wmemset(void *, int, size_t);
83 * New-style autoconfig attachment
86 static int ie_sebuf_match(device_t
, cfdata_t
, void *);
87 static void ie_sebuf_attach(device_t
, device_t
, void *);
89 CFATTACH_DECL_NEW(ie_sebuf
, sizeof(struct ie_softc
),
90 ie_sebuf_match
, ie_sebuf_attach
, NULL
, NULL
);
93 ie_sebuf_match(device_t parent
, cfdata_t cf
, void *args
)
95 struct sebuf_attach_args
*aa
= args
;
98 if (strcmp(aa
->name
, "ie"))
101 /* Anyting else to check? */
107 ie_sebuf_attach(device_t parent
, device_t self
, void *args
)
109 struct ie_softc
*sc
= device_private(self
);
110 struct sebuf_attach_args
*aa
= args
;
111 volatile struct ie_regs
*regs
;
115 sc
->hard_type
= IE_VME3E
;
116 sc
->reset_586
= ie_sebuf_reset
;
117 sc
->chan_attn
= ie_sebuf_attend
;
118 sc
->run_586
= ie_sebuf_run
;
119 sc
->sc_memcpy
= wmemcpy
;
120 sc
->sc_memset
= wmemset
;
122 /* Control regs mapped by parent. */
123 sc
->sc_reg
= aa
->regs
;
124 regs
= (struct ie_regs
*)sc
->sc_reg
;
127 * On this hardware, the i82586 address zero
128 * maps to the start of the board, which we
129 * happen to know is 128K below (XXX).
131 sc
->sc_iobase
= aa
->buf
- 0x20000;
134 * There is 128K of memory for the i82586 on
135 * the Sun3/E SCSI/Ethernet board, and the
136 * "sebuf" driver has mapped it in for us.
137 * (Fixed in hardware; NOT configurable!)
139 if (aa
->blen
< SE_IEBUFSIZE
)
140 panic("ie_sebuf: bad size");
141 sc
->sc_msize
= SE_IEBUFSIZE
;
142 sc
->sc_maddr
= aa
->buf
;
144 /* Clear the memory. */
145 (sc
->sc_memset
)(sc
->sc_maddr
, 0, sc
->sc_msize
);
148 * XXX: Unfortunately, the common driver code
149 * is not ready to deal with more than 64K of
150 * memory, so skip the first 64K. Too bad.
151 * Note: device needs the SCP at the end.
153 sc
->sc_msize
-= 0x10000;
154 sc
->sc_maddr
= (char *)sc
->sc_maddr
+ 0x10000;
157 * Set the System Configuration Pointer (SCP).
158 * Its location is system-dependent because the
159 * i82586 reads it from a fixed physical address.
160 * On this hardware, the i82586 address is just
161 * masked down to 17 bits, so the SCP is found
162 * at the end of the RAM on the VME board.
164 off
= IE_SCP_ADDR
& 0xFFFF;
165 sc
->scp
= (volatile void *)((char *)sc
->sc_maddr
+ off
);
168 * The rest of ram is used for buffers, etc.
170 sc
->buf_area
= sc
->sc_maddr
;
171 sc
->buf_area_sz
= off
;
173 /* Install interrupt handler. */
174 regs
->ie_ivec
= aa
->ca
.ca_intvec
;
175 isr_add_vectored(ie_intr
, sc
, aa
->ca
.ca_intpri
, aa
->ca
.ca_intvec
);
177 /* Set the ethernet address. */
178 idprom_etheraddr(sc
->sc_addr
);
180 /* Do machine-independent parts of attach. */
185 /* Whack the "channel attetion" line. */
187 ie_sebuf_attend(struct ie_softc
*sc
)
189 volatile struct ie_regs
*regs
= (struct ie_regs
*)sc
->sc_reg
;
191 regs
->ie_csr
|= IE_CSR_ATTEN
; /* flag! */
192 regs
->ie_csr
&= ~IE_CSR_ATTEN
; /* down. */
196 * This is called during driver attach.
197 * Reset and initialize.
200 ie_sebuf_reset(struct ie_softc
*sc
)
202 volatile struct ie_regs
*regs
= (struct ie_regs
*)sc
->sc_reg
;
203 regs
->ie_csr
= IE_CSR_RESET
;
205 regs
->ie_csr
= (IE_CSR_NOLOOP
| IE_CSR_IENAB
);
209 * This is called at the end of ieinit().
213 ie_sebuf_run(struct ie_softc
*sc
)
216 /* do it all in reset */
220 * wmemcpy/wmemset - like memcpy/memset but largest access is 16-bits,
221 * and also does byte swaps...
222 * XXX - Would be nice to have asm versions in some library...
226 wmemset(void *vb
, int val
, size_t l
)
240 if (b
!= be
&& ((uint32_t)be
& 1) != 0) {
247 while (sp
!= (uint16_t *)be
)
254 wmemcpy(void *dst
, const void *src
, size_t l
)
256 const uint8_t *b1e
, *b1
= src
;
265 if ((uint32_t)b1
& 1) {
271 sp
= (const uint16_t *)b1
;
275 bstore
= (uint32_t)b2
& 1;
277 while (sp
< (const uint16_t *)b1e
) {
282 *((uint16_t *)b2
) = *sp
;