No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / sun3 / dev / if_ie_sebuf.c
blob2005e6feccf4d25f3cc948880b84861532c8019a
1 /* $NetBSD: if_ie_sebuf.c,v 1.15 2008/04/28 20:23:37 martin Exp $ */
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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 $");
40 #include "opt_inet.h"
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>
47 #include <net/if.h>
48 #include <net/if_ether.h>
50 #ifdef INET
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>
56 #endif
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>
64 #include "i82586.h"
65 #include "if_iereg.h"
66 #include "if_ievar.h"
67 #include "sereg.h"
68 #include "sevar.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);
92 static int
93 ie_sebuf_match(device_t parent, cfdata_t cf, void *args)
95 struct sebuf_attach_args *aa = args;
97 /* Match by name. */
98 if (strcmp(aa->name, "ie"))
99 return 0;
101 /* Anyting else to check? */
103 return 1;
106 static void
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;
112 int off;
114 sc->sc_dev = self;
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. */
181 ie_attach(sc);
185 /* Whack the "channel attetion" line. */
186 void
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.
199 void
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;
204 delay(20);
205 regs->ie_csr = (IE_CSR_NOLOOP | IE_CSR_IENAB);
209 * This is called at the end of ieinit().
210 * optional.
212 void
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...
225 static void *
226 wmemset(void *vb, int val, size_t l)
228 uint8_t *b = vb;
229 uint8_t *be = b + l;
230 uint16_t *sp;
232 if (l == 0)
233 return vb;
235 /* front, */
236 if ((uint32_t)b & 1)
237 *b++ = val;
239 /* back, */
240 if (b != be && ((uint32_t)be & 1) != 0) {
241 be--;
242 *be = val;
245 /* and middle. */
246 sp = (uint16_t *)b;
247 while (sp != (uint16_t *)be)
248 *sp++ = val;
250 return vb;
253 static void *
254 wmemcpy(void *dst, const void *src, size_t l)
256 const uint8_t *b1e, *b1 = src;
257 uint8_t *b2 = dst;
258 const uint16_t *sp;
259 int bstore = 0;
261 if (l == 0)
262 return dst;
264 /* front, */
265 if ((uint32_t)b1 & 1) {
266 *b2++ = *b1++;
267 l--;
270 /* middle, */
271 sp = (const uint16_t *)b1;
272 b1e = b1 + l;
273 if (l & 1)
274 b1e--;
275 bstore = (uint32_t)b2 & 1;
277 while (sp < (const uint16_t *)b1e) {
278 if (bstore) {
279 b2[1] = *sp & 0xff;
280 b2[0] = *sp >> 8;
281 } else
282 *((uint16_t *)b2) = *sp;
283 sp++;
284 b2 += 2;
287 /* and back. */
288 if (l & 1)
289 *b2 = *b1e;
291 return dst;