if_qe.c revision 1.36 1 1.35 ragge /* $NetBSD: if_qe.c,v 1.36 1999/06/06 19:26:44 ragge Exp $ */
2 1.6 jtc
3 1.1 ragge /*
4 1.1 ragge * Copyright (c) 1988 Regents of the University of California.
5 1.1 ragge * All rights reserved.
6 1.1 ragge *
7 1.1 ragge * This code is derived from software contributed to Berkeley by
8 1.1 ragge * Digital Equipment Corp.
9 1.1 ragge *
10 1.1 ragge * Redistribution and use in source and binary forms, with or without
11 1.1 ragge * modification, are permitted provided that the following conditions
12 1.1 ragge * are met:
13 1.1 ragge * 1. Redistributions of source code must retain the above copyright
14 1.1 ragge * notice, this list of conditions and the following disclaimer.
15 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ragge * notice, this list of conditions and the following disclaimer in the
17 1.1 ragge * documentation and/or other materials provided with the distribution.
18 1.1 ragge * 3. All advertising materials mentioning features or use of this software
19 1.1 ragge * must display the following acknowledgement:
20 1.1 ragge * This product includes software developed by the University of
21 1.1 ragge * California, Berkeley and its contributors.
22 1.1 ragge * 4. Neither the name of the University nor the names of its contributors
23 1.1 ragge * may be used to endorse or promote products derived from this software
24 1.1 ragge * without specific prior written permission.
25 1.1 ragge *
26 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 ragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 ragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 ragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 ragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 ragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 ragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 ragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 ragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 ragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 ragge * SUCH DAMAGE.
37 1.1 ragge *
38 1.1 ragge * @(#)if_qe.c 7.20 (Berkeley) 3/28/91
39 1.1 ragge */
40 1.1 ragge
41 1.21 ragge /* from @(#)if_qe.c 1.15 (ULTRIX) 4/16/86 */
42 1.1 ragge
43 1.1 ragge /****************************************************************
44 1.1 ragge * *
45 1.21 ragge * Licensed from Digital Equipment Corporation *
46 1.21 ragge * Copyright (c) *
47 1.21 ragge * Digital Equipment Corporation *
48 1.21 ragge * Maynard, Massachusetts *
49 1.21 ragge * 1985, 1986 *
50 1.21 ragge * All rights reserved. *
51 1.1 ragge * *
52 1.21 ragge * The Information in this software is subject to change *
53 1.1 ragge * without notice and should not be construed as a commitment *
54 1.21 ragge * by Digital Equipment Corporation. Digital makes no *
55 1.1 ragge * representations about the suitability of this software for *
56 1.1 ragge * any purpose. It is supplied "As Is" without expressed or *
57 1.21 ragge * implied warranty. *
58 1.1 ragge * *
59 1.21 ragge * If the Regents of the University of California or its *
60 1.21 ragge * licensees modify the software in a manner creating *
61 1.21 ragge * derivative copyright rights, appropriate copyright *
62 1.21 ragge * legends may be placed on the derivative work in addition *
63 1.21 ragge * to that set forth above. *
64 1.1 ragge * *
65 1.1 ragge ****************************************************************/
66 1.1 ragge /* ---------------------------------------------------------------------
67 1.1 ragge * Modification History
68 1.1 ragge *
69 1.1 ragge * 15-Apr-86 -- afd
70 1.1 ragge * Rename "unused_multi" to "qunused_multi" for extending Generic
71 1.1 ragge * kernel to MicroVAXen.
72 1.1 ragge *
73 1.21 ragge * 18-mar-86 -- jaw br/cvec changed to NOT use registers.
74 1.1 ragge *
75 1.1 ragge * 12 March 86 -- Jeff Chase
76 1.1 ragge * Modified to handle the new MCLGET macro
77 1.1 ragge * Changed if_qe_data.c to use more receive buffers
78 1.1 ragge * Added a flag to poke with adb to log qe_restarts on console
79 1.1 ragge *
80 1.1 ragge * 19 Oct 85 -- rjl
81 1.1 ragge * Changed the watch dog timer from 30 seconds to 3. VMS is using
82 1.21 ragge * less than 1 second in their's. Also turned the printf into an
83 1.1 ragge * mprintf.
84 1.1 ragge *
85 1.1 ragge * 09/16/85 -- Larry Cohen
86 1.21 ragge * Add 43bsd alpha tape changes for subnet routing
87 1.1 ragge *
88 1.1 ragge * 1 Aug 85 -- rjl
89 1.1 ragge * Panic on a non-existent memory interrupt and the case where a packet
90 1.1 ragge * was chained. The first should never happen because non-existant
91 1.1 ragge * memory interrupts cause a bus reset. The second should never happen
92 1.1 ragge * because we hang 2k input buffers on the device.
93 1.1 ragge *
94 1.1 ragge * 1 Aug 85 -- rich
95 1.21 ragge * Fixed the broadcast loopback code to handle Clusters without
96 1.21 ragge * wedging the system.
97 1.1 ragge *
98 1.1 ragge * 27 Feb. 85 -- ejf
99 1.1 ragge * Return default hardware address on ioctl request.
100 1.1 ragge *
101 1.1 ragge * 12 Feb. 85 -- ejf
102 1.1 ragge * Added internal extended loopback capability.
103 1.1 ragge *
104 1.1 ragge * 27 Dec. 84 -- rjl
105 1.1 ragge * Fixed bug that caused every other transmit descriptor to be used
106 1.1 ragge * instead of every descriptor.
107 1.1 ragge *
108 1.1 ragge * 21 Dec. 84 -- rjl
109 1.1 ragge * Added watchdog timer to mask hardware bug that causes device lockup.
110 1.1 ragge *
111 1.1 ragge * 18 Dec. 84 -- rjl
112 1.21 ragge * Reworked driver to use q-bus mapping routines. MicroVAX-I now does
113 1.1 ragge * copying instead of m-buf shuffleing.
114 1.1 ragge * A number of deficencies in the hardware/firmware were compensated
115 1.1 ragge * for. See comments in qestart and qerint.
116 1.1 ragge *
117 1.1 ragge * 14 Nov. 84 -- jf
118 1.1 ragge * Added usage counts for multicast addresses.
119 1.1 ragge * Updated general protocol support to allow access to the Ethernet
120 1.1 ragge * header.
121 1.1 ragge *
122 1.1 ragge * 04 Oct. 84 -- jf
123 1.1 ragge * Added support for new ioctls to add and delete multicast addresses
124 1.1 ragge * and set the physical address.
125 1.1 ragge * Add support for general protocols.
126 1.1 ragge *
127 1.1 ragge * 14 Aug. 84 -- rjl
128 1.1 ragge * Integrated Shannon changes. (allow arp above 1024 and ? )
129 1.1 ragge *
130 1.1 ragge * 13 Feb. 84 -- rjl
131 1.1 ragge *
132 1.1 ragge * Initial version of driver. derived from IL driver.
133 1.1 ragge *
134 1.1 ragge * ---------------------------------------------------------------------
135 1.1 ragge */
136 1.1 ragge
137 1.1 ragge /*
138 1.1 ragge * Digital Q-BUS to NI Adapter
139 1.22 ragge * supports DEQNA and DELQA in DEQNA-mode.
140 1.1 ragge */
141 1.22 ragge
142 1.27 jonathan #include "opt_inet.h"
143 1.28 jonathan #include "opt_ccitt.h"
144 1.29 jonathan #include "opt_llc.h"
145 1.30 jonathan #include "opt_iso.h"
146 1.31 jonathan #include "opt_ns.h"
147 1.22 ragge #include "bpfilter.h"
148 1.22 ragge
149 1.9 mycroft #include <sys/param.h>
150 1.9 mycroft #include <sys/systm.h>
151 1.9 mycroft #include <sys/mbuf.h>
152 1.9 mycroft #include <sys/buf.h>
153 1.9 mycroft #include <sys/protosw.h>
154 1.9 mycroft #include <sys/socket.h>
155 1.9 mycroft #include <sys/ioctl.h>
156 1.9 mycroft #include <sys/errno.h>
157 1.9 mycroft #include <sys/syslog.h>
158 1.9 mycroft #include <sys/device.h>
159 1.9 mycroft #include <sys/time.h>
160 1.9 mycroft #include <sys/kernel.h>
161 1.25 ragge #include <sys/reboot.h>
162 1.9 mycroft
163 1.9 mycroft #include <net/if.h>
164 1.20 is #include <net/if_ether.h>
165 1.21 ragge #include <net/if_dl.h>
166 1.1 ragge
167 1.1 ragge #ifdef INET
168 1.9 mycroft #include <netinet/in.h>
169 1.9 mycroft #include <netinet/in_systm.h>
170 1.9 mycroft #include <netinet/in_var.h>
171 1.9 mycroft #include <netinet/ip.h>
172 1.20 is #include <netinet/if_inarp.h>
173 1.1 ragge #endif
174 1.1 ragge
175 1.1 ragge #ifdef NS
176 1.9 mycroft #include <netns/ns.h>
177 1.9 mycroft #include <netns/ns_if.h>
178 1.1 ragge #endif
179 1.1 ragge
180 1.1 ragge #ifdef ISO
181 1.9 mycroft #include <netiso/iso.h>
182 1.9 mycroft #include <netiso/iso_var.h>
183 1.1 ragge extern char all_es_snpa[], all_is_snpa[], all_l1is_snpa[], all_l2is_snpa[];
184 1.1 ragge #endif
185 1.1 ragge
186 1.22 ragge #if defined(CCITT) && defined(LLC)
187 1.22 ragge #include <sys/socketvar.h>
188 1.22 ragge #include <netccitt/x25.h>
189 1.22 ragge #include <netccitt/pk.h>
190 1.22 ragge #include <netccitt/pk_var.h>
191 1.22 ragge #include <netccitt/pk_extern.h>
192 1.22 ragge #endif
193 1.22 ragge
194 1.22 ragge #if NBPFILTER > 0
195 1.22 ragge #include <net/bpf.h>
196 1.22 ragge #include <net/bpfdesc.h>
197 1.22 ragge #endif
198 1.22 ragge
199 1.9 mycroft #include <machine/pte.h>
200 1.9 mycroft #include <machine/cpu.h>
201 1.25 ragge #include <machine/rpb.h>
202 1.10 mycroft
203 1.10 mycroft #include <vax/if/if_qereg.h>
204 1.10 mycroft #include <vax/if/if_uba.h>
205 1.9 mycroft #include <vax/uba/ubareg.h>
206 1.9 mycroft #include <vax/uba/ubavar.h>
207 1.1 ragge
208 1.21 ragge #define NRCV 15 /* Receive descriptors */
209 1.21 ragge #define NXMT 5 /* Transmit descriptors */
210 1.1 ragge #define NTOT (NXMT + NRCV)
211 1.1 ragge
212 1.21 ragge #define QETIMEOUT 2 /* transmit timeout, must be > 1 */
213 1.1 ragge #define QESLOWTIMEOUT 40 /* timeout when no xmits in progress */
214 1.1 ragge
215 1.1 ragge #define MINDATA 60
216 1.6 jtc
217 1.1 ragge /*
218 1.1 ragge * Ethernet software status per interface.
219 1.1 ragge *
220 1.1 ragge * Each interface is referenced by a network interface structure,
221 1.1 ragge * qe_if, which the routing code uses to locate the interface.
222 1.1 ragge * This structure contains the output queue for the interface, its address, ...
223 1.1 ragge */
224 1.1 ragge struct qe_softc {
225 1.13 ragge struct device qe_dev; /* Configuration common part */
226 1.21 ragge struct ethercom qe_ec; /* Ethernet common part */
227 1.21 ragge #define qe_if qe_ec.ec_if /* network-visible interface */
228 1.21 ragge struct ifubinfo qe_uba; /* Q-bus resources */
229 1.22 ragge struct ifrw qe_ifr[NRCV]; /* for receive buffers; */
230 1.22 ragge struct ifxmt qe_ifw[NXMT]; /* for xmit buffers; */
231 1.7 ragge struct qedevice *qe_vaddr;
232 1.1 ragge int qe_flags; /* software state */
233 1.21 ragge #define QEF_RUNNING 0x01
234 1.21 ragge #define QEF_SETADDR 0x02
235 1.1 ragge #define QEF_FASTTIMEO 0x04
236 1.21 ragge int setupaddr; /* mapping info for setup pkts */
237 1.1 ragge int ipl; /* interrupt priority */
238 1.1 ragge struct qe_ring *rringaddr; /* mapping info for rings */
239 1.21 ragge struct qe_ring *tringaddr; /* "" */
240 1.22 ragge struct qe_ring rring[NRCV+1]; /* Receive ring descriptors */
241 1.22 ragge struct qe_ring tring[NXMT+1]; /* Xmit ring descriptors */
242 1.1 ragge u_char setup_pkt[16][8]; /* Setup packet */
243 1.1 ragge int rindex; /* Receive index */
244 1.1 ragge int tindex; /* Transmit index */
245 1.1 ragge int otindex; /* Old transmit index */
246 1.21 ragge int qe_intvec; /* Interrupt vector */
247 1.22 ragge struct qedevice *addr; /* device addr */
248 1.21 ragge int setupqueued; /* setup packet queued */
249 1.22 ragge int setuplength; /* length of setup packet */
250 1.1 ragge int nxmit; /* Transmits in progress */
251 1.1 ragge int qe_restarts; /* timeouts */
252 1.7 ragge };
253 1.1 ragge
254 1.24 ragge int qematch __P((struct device *, struct cfdata *, void *));
255 1.7 ragge void qeattach __P((struct device *, struct device *, void *));
256 1.13 ragge void qereset __P((int));
257 1.14 thorpej void qeinit __P((struct qe_softc *));
258 1.7 ragge void qestart __P((struct ifnet *));
259 1.7 ragge void qeintr __P((int));
260 1.7 ragge void qetint __P((int));
261 1.7 ragge void qerint __P((int));
262 1.7 ragge int qeioctl __P((struct ifnet *, u_long, caddr_t));
263 1.14 thorpej void qe_setaddr __P((u_char *, struct qe_softc *));
264 1.7 ragge void qeinitdesc __P((struct qe_ring *, caddr_t, int));
265 1.7 ragge void qesetup __P((struct qe_softc *));
266 1.7 ragge void qeread __P((struct qe_softc *, struct ifrw *, int));
267 1.14 thorpej void qetimeout __P((struct ifnet *));
268 1.7 ragge void qerestart __P((struct qe_softc *));
269 1.1 ragge
270 1.12 ragge struct cfattach qe_ca = {
271 1.12 ragge sizeof(struct qe_softc), qematch, qeattach
272 1.12 ragge };
273 1.23 thorpej
274 1.23 thorpej extern struct cfdriver qe_cd;
275 1.1 ragge
276 1.21 ragge #define QEUNIT(x) minor(x)
277 1.1 ragge /*
278 1.1 ragge * The deqna shouldn't receive more than ETHERMTU + sizeof(struct ether_header)
279 1.1 ragge * but will actually take in up to 2048 bytes. To guard against the receiver
280 1.1 ragge * chaining buffers (which we aren't prepared to handle) we allocate 2kb
281 1.1 ragge * size buffers.
282 1.1 ragge */
283 1.1 ragge #define MAXPACKETSIZE 2048 /* Should really be ETHERMTU */
284 1.7 ragge
285 1.1 ragge /*
286 1.1 ragge * Probe the QNA to see if it's there
287 1.1 ragge */
288 1.7 ragge int
289 1.24 ragge qematch(parent, cf, aux)
290 1.7 ragge struct device *parent;
291 1.24 ragge struct cfdata *cf;
292 1.24 ragge void *aux;
293 1.7 ragge {
294 1.24 ragge struct qe_softc sc;
295 1.7 ragge struct uba_attach_args *ua = aux;
296 1.7 ragge struct uba_softc *ubasc = (struct uba_softc *)parent;
297 1.21 ragge struct qe_ring *rp;
298 1.21 ragge struct qe_ring *prp; /* physical rp */
299 1.7 ragge volatile struct qedevice *addr = (struct qedevice *)ua->ua_addr;
300 1.5 ragge int i;
301 1.1 ragge
302 1.1 ragge /*
303 1.1 ragge * The QNA interrupts on i/o operations. To do an I/O operation
304 1.1 ragge * we have to setup the interface by transmitting a setup packet.
305 1.1 ragge */
306 1.7 ragge
307 1.1 ragge addr->qe_csr = QE_RESET;
308 1.1 ragge addr->qe_csr &= ~QE_RESET;
309 1.5 ragge addr->qe_vector = (ubasc->uh_lastiv -= 4);
310 1.1 ragge
311 1.24 ragge bzero(&sc, sizeof(struct qe_softc));
312 1.1 ragge /*
313 1.1 ragge * Map the communications area and the setup packet.
314 1.1 ragge */
315 1.24 ragge sc.setupaddr =
316 1.24 ragge uballoc(ubasc, (caddr_t)sc.setup_pkt, sizeof(sc.setup_pkt), 0);
317 1.24 ragge sc.rringaddr = (struct qe_ring *) uballoc(ubasc, (caddr_t)sc.rring,
318 1.7 ragge sizeof(struct qe_ring) * (NTOT+2), 0);
319 1.24 ragge prp = (struct qe_ring *)UBAI_ADDR((int)sc.rringaddr);
320 1.1 ragge
321 1.1 ragge /*
322 1.1 ragge * The QNA will loop the setup packet back to the receive ring
323 1.1 ragge * for verification, therefore we initialize the first
324 1.1 ragge * receive & transmit ring descriptors and link the setup packet
325 1.1 ragge * to them.
326 1.1 ragge */
327 1.24 ragge qeinitdesc(sc.tring, (caddr_t)UBAI_ADDR(sc.setupaddr),
328 1.24 ragge sizeof(sc.setup_pkt));
329 1.24 ragge qeinitdesc(sc.rring, (caddr_t)UBAI_ADDR(sc.setupaddr),
330 1.24 ragge sizeof(sc.setup_pkt));
331 1.1 ragge
332 1.24 ragge rp = (struct qe_ring *)sc.tring;
333 1.1 ragge rp->qe_setup = 1;
334 1.1 ragge rp->qe_eomsg = 1;
335 1.1 ragge rp->qe_flag = rp->qe_status1 = QE_NOTYET;
336 1.1 ragge rp->qe_valid = 1;
337 1.1 ragge
338 1.24 ragge rp = (struct qe_ring *)sc.rring;
339 1.1 ragge rp->qe_flag = rp->qe_status1 = QE_NOTYET;
340 1.1 ragge rp->qe_valid = 1;
341 1.1 ragge
342 1.1 ragge /*
343 1.1 ragge * Get the addr off of the interface and place it into the setup
344 1.1 ragge * packet. This code looks strange due to the fact that the address
345 1.1 ragge * is placed in the setup packet in col. major order.
346 1.1 ragge */
347 1.7 ragge for (i = 0; i < 6; i++)
348 1.24 ragge sc.setup_pkt[i][1] = addr->qe_sta_addr[i];
349 1.1 ragge
350 1.24 ragge qesetup(&sc);
351 1.1 ragge /*
352 1.1 ragge * Start the interface and wait for the packet.
353 1.1 ragge */
354 1.1 ragge addr->qe_csr = QE_INT_ENABLE | QE_XMIT_INT | QE_RCV_INT;
355 1.1 ragge addr->qe_rcvlist_lo = (short)((int)prp);
356 1.1 ragge addr->qe_rcvlist_hi = (short)((int)prp >> 16);
357 1.1 ragge prp += NRCV+1;
358 1.1 ragge addr->qe_xmtlist_lo = (short)((int)prp);
359 1.1 ragge addr->qe_xmtlist_hi = (short)((int)prp >> 16);
360 1.1 ragge DELAY(10000);
361 1.1 ragge /*
362 1.1 ragge * All done with the bus resources.
363 1.1 ragge */
364 1.24 ragge ubarelse(ubasc, &sc.setupaddr);
365 1.24 ragge ubarelse(ubasc, (int *)&sc.rringaddr);
366 1.7 ragge ua->ua_ivec = qeintr;
367 1.7 ragge return 1;
368 1.1 ragge }
369 1.1 ragge
370 1.1 ragge /*
371 1.1 ragge * Interface exists: make available by filling in network interface
372 1.1 ragge * record. System will initialize the interface when it is ready
373 1.1 ragge * to accept packets.
374 1.1 ragge */
375 1.7 ragge void
376 1.7 ragge qeattach(parent, self, aux)
377 1.7 ragge struct device *parent, *self;
378 1.7 ragge void *aux;
379 1.7 ragge {
380 1.7 ragge struct uba_attach_args *ua = aux;
381 1.7 ragge struct qe_softc *sc = (struct qe_softc *)self;
382 1.7 ragge struct ifnet *ifp = (struct ifnet *)&sc->qe_if;
383 1.7 ragge struct qedevice *addr =(struct qedevice *)ua->ua_addr;
384 1.4 ragge int i;
385 1.20 is u_int8_t myaddr[ETHER_ADDR_LEN];
386 1.1 ragge
387 1.18 christos printf("\n");
388 1.24 ragge sc->ipl = 0x15;
389 1.7 ragge sc->qe_vaddr = addr;
390 1.15 ragge bcopy(sc->qe_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
391 1.14 thorpej ifp->if_softc = sc;
392 1.1 ragge /*
393 1.1 ragge * The Deqna is cable of transmitting broadcasts, but
394 1.1 ragge * doesn't listen to its own.
395 1.1 ragge */
396 1.22 ragge ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS |
397 1.22 ragge IFF_MULTICAST;
398 1.1 ragge
399 1.1 ragge /*
400 1.1 ragge * Read the address from the prom and save it.
401 1.1 ragge */
402 1.7 ragge for (i = 0; i < 6; i++)
403 1.20 is sc->setup_pkt[i][1] = myaddr[i] =
404 1.7 ragge addr->qe_sta_addr[i] & 0xff;
405 1.1 ragge addr->qe_vector |= 1;
406 1.18 christos printf("qe%d: %s, hardware address %s\n", sc->qe_dev.dv_unit,
407 1.1 ragge addr->qe_vector&01 ? "delqa":"deqna",
408 1.20 is ether_sprintf(myaddr));
409 1.1 ragge addr->qe_vector &= ~1;
410 1.1 ragge
411 1.1 ragge /*
412 1.1 ragge * Save the vector for initialization at reset time.
413 1.1 ragge */
414 1.1 ragge sc->qe_intvec = addr->qe_vector;
415 1.1 ragge
416 1.1 ragge ifp->if_start = qestart;
417 1.1 ragge ifp->if_ioctl = qeioctl;
418 1.1 ragge ifp->if_watchdog = qetimeout;
419 1.1 ragge sc->qe_uba.iff_flags = UBA_CANTWAIT;
420 1.1 ragge if_attach(ifp);
421 1.20 is ether_ifattach(ifp, myaddr);
422 1.22 ragge
423 1.22 ragge #if NBPFILTER > 0
424 1.22 ragge bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
425 1.22 ragge #endif
426 1.25 ragge if (B_TYPE(bootdev) == BDEV_QE)
427 1.25 ragge booted_from = self;
428 1.1 ragge }
429 1.1 ragge
430 1.1 ragge /*
431 1.1 ragge * Reset of interface after UNIBUS reset.
432 1.1 ragge */
433 1.13 ragge void
434 1.7 ragge qereset(unit)
435 1.7 ragge int unit;
436 1.1 ragge {
437 1.13 ragge struct qe_softc *sc = qe_cd.cd_devs[unit];
438 1.1 ragge
439 1.18 christos printf(" %s", sc->qe_dev.dv_xname);
440 1.13 ragge sc->qe_if.if_flags &= ~IFF_RUNNING;
441 1.14 thorpej qeinit(sc);
442 1.1 ragge }
443 1.1 ragge
444 1.1 ragge /*
445 1.1 ragge * Initialization of interface.
446 1.1 ragge */
447 1.7 ragge void
448 1.14 thorpej qeinit(sc)
449 1.14 thorpej struct qe_softc *sc;
450 1.1 ragge {
451 1.7 ragge struct qedevice *addr = sc->qe_vaddr;
452 1.16 ragge struct uba_softc *ubasc = (void *)sc->qe_dev.dv_parent;
453 1.4 ragge struct ifnet *ifp = (struct ifnet *)&sc->qe_if;
454 1.4 ragge int i;
455 1.1 ragge int s;
456 1.1 ragge
457 1.1 ragge /* address not known */
458 1.4 ragge if (ifp->if_addrlist.tqh_first == (struct ifaddr *)0)
459 1.1 ragge return;
460 1.1 ragge if (sc->qe_flags & QEF_RUNNING)
461 1.1 ragge return;
462 1.1 ragge
463 1.1 ragge if ((ifp->if_flags & IFF_RUNNING) == 0) {
464 1.1 ragge /*
465 1.1 ragge * map the communications area onto the device
466 1.1 ragge */
467 1.16 ragge i = uballoc(ubasc, (caddr_t)sc->rring,
468 1.1 ragge sizeof(struct qe_ring) * (NTOT+2), 0);
469 1.1 ragge if (i == 0)
470 1.1 ragge goto fail;
471 1.1 ragge sc->rringaddr = (struct qe_ring *)UBAI_ADDR(i);
472 1.1 ragge sc->tringaddr = sc->rringaddr + NRCV + 1;
473 1.16 ragge i = uballoc(ubasc, (caddr_t)sc->setup_pkt,
474 1.1 ragge sizeof(sc->setup_pkt), 0);
475 1.1 ragge if (i == 0)
476 1.1 ragge goto fail;
477 1.21 ragge sc->setupaddr = UBAI_ADDR(i);
478 1.1 ragge /*
479 1.1 ragge * init buffers and maps
480 1.1 ragge */
481 1.16 ragge if (if_ubaminit(&sc->qe_uba, (void *)sc->qe_dev.dv_parent,
482 1.33 ragge sizeof (struct ether_header), (int)vax_btoc(MAXPACKETSIZE),
483 1.1 ragge sc->qe_ifr, NRCV, sc->qe_ifw, NXMT) == 0) {
484 1.1 ragge fail:
485 1.18 christos printf("%s: can't allocate uba resources\n",
486 1.15 ragge sc->qe_dev.dv_xname);
487 1.1 ragge sc->qe_if.if_flags &= ~IFF_UP;
488 1.1 ragge return;
489 1.1 ragge }
490 1.1 ragge }
491 1.1 ragge /*
492 1.1 ragge * Init the buffer descriptors and indexes for each of the lists and
493 1.1 ragge * loop them back to form a ring.
494 1.1 ragge */
495 1.1 ragge for (i = 0; i < NRCV; i++) {
496 1.1 ragge qeinitdesc( &sc->rring[i],
497 1.1 ragge (caddr_t)UBAI_ADDR(sc->qe_ifr[i].ifrw_info), MAXPACKETSIZE);
498 1.1 ragge sc->rring[i].qe_flag = sc->rring[i].qe_status1 = QE_NOTYET;
499 1.1 ragge sc->rring[i].qe_valid = 1;
500 1.1 ragge }
501 1.1 ragge qeinitdesc(&sc->rring[i], (caddr_t)NULL, 0);
502 1.1 ragge
503 1.1 ragge sc->rring[i].qe_addr_lo = (short)((int)sc->rringaddr);
504 1.1 ragge sc->rring[i].qe_addr_hi = (short)((int)sc->rringaddr >> 16);
505 1.1 ragge sc->rring[i].qe_chain = 1;
506 1.1 ragge sc->rring[i].qe_flag = sc->rring[i].qe_status1 = QE_NOTYET;
507 1.1 ragge sc->rring[i].qe_valid = 1;
508 1.1 ragge
509 1.1 ragge for( i = 0 ; i <= NXMT ; i++ )
510 1.1 ragge qeinitdesc(&sc->tring[i], (caddr_t)NULL, 0);
511 1.1 ragge i--;
512 1.1 ragge
513 1.1 ragge sc->tring[i].qe_addr_lo = (short)((int)sc->tringaddr);
514 1.1 ragge sc->tring[i].qe_addr_hi = (short)((int)sc->tringaddr >> 16);
515 1.1 ragge sc->tring[i].qe_chain = 1;
516 1.1 ragge sc->tring[i].qe_flag = sc->tring[i].qe_status1 = QE_NOTYET;
517 1.1 ragge sc->tring[i].qe_valid = 1;
518 1.1 ragge
519 1.1 ragge sc->nxmit = sc->otindex = sc->tindex = sc->rindex = 0;
520 1.1 ragge
521 1.1 ragge /*
522 1.1 ragge * Take the interface out of reset, program the vector,
523 1.1 ragge * enable interrupts, and tell the world we are up.
524 1.1 ragge */
525 1.8 mycroft s = splnet();
526 1.1 ragge addr->qe_vector = sc->qe_intvec;
527 1.1 ragge sc->addr = addr;
528 1.1 ragge addr->qe_csr = QE_RCV_ENABLE | QE_INT_ENABLE | QE_XMIT_INT |
529 1.1 ragge QE_RCV_INT | QE_ILOOP;
530 1.1 ragge addr->qe_rcvlist_lo = (short)((int)sc->rringaddr);
531 1.1 ragge addr->qe_rcvlist_hi = (short)((int)sc->rringaddr >> 16);
532 1.1 ragge ifp->if_flags |= IFF_UP | IFF_RUNNING;
533 1.1 ragge sc->qe_flags |= QEF_RUNNING;
534 1.1 ragge qesetup( sc );
535 1.2 mycroft qestart( ifp );
536 1.1 ragge sc->qe_if.if_timer = QESLOWTIMEOUT; /* Start watchdog */
537 1.1 ragge splx( s );
538 1.1 ragge }
539 1.1 ragge
540 1.1 ragge /*
541 1.1 ragge * Start output on interface.
542 1.1 ragge *
543 1.1 ragge */
544 1.2 mycroft void
545 1.1 ragge qestart(ifp)
546 1.1 ragge struct ifnet *ifp;
547 1.1 ragge {
548 1.14 thorpej register struct qe_softc *sc = ifp->if_softc;
549 1.7 ragge volatile struct qedevice *addr = sc->qe_vaddr;
550 1.7 ragge register struct qe_ring *rp;
551 1.32 ragge register int index;
552 1.1 ragge struct mbuf *m;
553 1.1 ragge int buf_addr, len, s;
554 1.1 ragge
555 1.1 ragge
556 1.8 mycroft s = splnet();
557 1.1 ragge /*
558 1.1 ragge * The deqna doesn't look at anything but the valid bit
559 1.1 ragge * to determine if it should transmit this packet. If you have
560 1.1 ragge * a ring and fill it the device will loop indefinately on the
561 1.1 ragge * packet and continue to flood the net with packets until you
562 1.1 ragge * break the ring. For this reason we never queue more than n-1
563 1.1 ragge * packets in the transmit ring.
564 1.1 ragge *
565 1.1 ragge * The microcoders should have obeyed their own defination of the
566 1.1 ragge * flag and status words, but instead we have to compensate.
567 1.1 ragge */
568 1.1 ragge for( index = sc->tindex;
569 1.1 ragge sc->tring[index].qe_valid == 0 && sc->nxmit < (NXMT-1) ;
570 1.1 ragge sc->tindex = index = ++index % NXMT){
571 1.1 ragge rp = &sc->tring[index];
572 1.1 ragge if( sc->setupqueued ) {
573 1.1 ragge buf_addr = sc->setupaddr;
574 1.22 ragge len = sc->setuplength;
575 1.1 ragge rp->qe_setup = 1;
576 1.1 ragge sc->setupqueued = 0;
577 1.1 ragge } else {
578 1.1 ragge IF_DEQUEUE(&sc->qe_if.if_snd, m);
579 1.7 ragge if (m == 0) {
580 1.1 ragge splx(s);
581 1.4 ragge return;
582 1.1 ragge }
583 1.22 ragge #if NBPFILTER > 0
584 1.22 ragge if (ifp->if_bpf)
585 1.22 ragge bpf_mtap(ifp->if_bpf, m);
586 1.22 ragge #endif
587 1.1 ragge buf_addr = sc->qe_ifw[index].ifw_info;
588 1.1 ragge len = if_ubaput(&sc->qe_uba, &sc->qe_ifw[index], m);
589 1.1 ragge }
590 1.1 ragge if( len < MINDATA )
591 1.1 ragge len = MINDATA;
592 1.1 ragge /*
593 1.1 ragge * Does buffer end on odd byte ?
594 1.1 ragge */
595 1.1 ragge if( len & 1 ) {
596 1.1 ragge len++;
597 1.1 ragge rp->qe_odd_end = 1;
598 1.1 ragge }
599 1.1 ragge rp->qe_buf_len = -(len/2);
600 1.1 ragge buf_addr = UBAI_ADDR(buf_addr);
601 1.1 ragge rp->qe_flag = rp->qe_status1 = QE_NOTYET;
602 1.1 ragge rp->qe_addr_lo = (short)buf_addr;
603 1.1 ragge rp->qe_addr_hi = (short)(buf_addr >> 16);
604 1.1 ragge rp->qe_eomsg = 1;
605 1.1 ragge rp->qe_flag = rp->qe_status1 = QE_NOTYET;
606 1.1 ragge rp->qe_valid = 1;
607 1.1 ragge if (sc->nxmit++ == 0) {
608 1.1 ragge sc->qe_flags |= QEF_FASTTIMEO;
609 1.1 ragge sc->qe_if.if_timer = QETIMEOUT;
610 1.1 ragge }
611 1.1 ragge
612 1.1 ragge /*
613 1.1 ragge * See if the xmit list is invalid.
614 1.1 ragge */
615 1.1 ragge if( addr->qe_csr & QE_XL_INVALID ) {
616 1.1 ragge buf_addr = (int)(sc->tringaddr+index);
617 1.1 ragge addr->qe_xmtlist_lo = (short)buf_addr;
618 1.1 ragge addr->qe_xmtlist_hi = (short)(buf_addr >> 16);
619 1.1 ragge }
620 1.1 ragge }
621 1.4 ragge splx(s);
622 1.4 ragge return;
623 1.1 ragge }
624 1.1 ragge
625 1.1 ragge /*
626 1.1 ragge * Ethernet interface interrupt processor
627 1.1 ragge */
628 1.7 ragge void
629 1.5 ragge qeintr(unit)
630 1.7 ragge int unit;
631 1.1 ragge {
632 1.7 ragge register struct qe_softc *sc;
633 1.7 ragge volatile struct qedevice *addr;
634 1.1 ragge int buf_addr, csr;
635 1.1 ragge
636 1.12 ragge sc = qe_cd.cd_devs[unit];
637 1.7 ragge addr = sc->qe_vaddr;
638 1.1 ragge splx(sc->ipl);
639 1.1 ragge if (!(sc->qe_flags & QEF_FASTTIMEO))
640 1.1 ragge sc->qe_if.if_timer = QESLOWTIMEOUT; /* Restart timer clock */
641 1.1 ragge csr = addr->qe_csr;
642 1.7 ragge addr->qe_csr = QE_RCV_ENABLE | QE_INT_ENABLE |
643 1.7 ragge QE_XMIT_INT | QE_RCV_INT | QE_ILOOP;
644 1.7 ragge if (csr & QE_RCV_INT)
645 1.7 ragge qerint(unit);
646 1.7 ragge if (csr & QE_XMIT_INT)
647 1.7 ragge qetint(unit );
648 1.7 ragge if (csr & QE_NEX_MEM_INT)
649 1.18 christos printf("qe%d: Nonexistent memory interrupt\n", unit);
650 1.1 ragge
651 1.7 ragge if (addr->qe_csr & QE_RL_INVALID && sc->rring[sc->rindex].qe_status1 ==
652 1.7 ragge QE_NOTYET) {
653 1.1 ragge buf_addr = (int)&sc->rringaddr[sc->rindex];
654 1.1 ragge addr->qe_rcvlist_lo = (short)buf_addr;
655 1.1 ragge addr->qe_rcvlist_hi = (short)(buf_addr >> 16);
656 1.1 ragge }
657 1.1 ragge }
658 1.1 ragge
659 1.1 ragge /*
660 1.1 ragge * Ethernet interface transmit interrupt.
661 1.1 ragge */
662 1.7 ragge void
663 1.1 ragge qetint(unit)
664 1.1 ragge int unit;
665 1.1 ragge {
666 1.12 ragge register struct qe_softc *sc = qe_cd.cd_devs[unit];
667 1.7 ragge register struct qe_ring *rp;
668 1.7 ragge register struct ifxmt *ifxp;
669 1.1 ragge int status1, setupflag;
670 1.1 ragge short len;
671 1.1 ragge
672 1.1 ragge
673 1.7 ragge while (sc->otindex != sc->tindex && sc->tring[sc->otindex].qe_status1
674 1.7 ragge != QE_NOTYET && sc->nxmit > 0) {
675 1.1 ragge /*
676 1.1 ragge * Save the status words from the descriptor so that it can
677 1.1 ragge * be released.
678 1.1 ragge */
679 1.1 ragge rp = &sc->tring[sc->otindex];
680 1.1 ragge status1 = rp->qe_status1;
681 1.1 ragge setupflag = rp->qe_setup;
682 1.1 ragge len = (-rp->qe_buf_len) * 2;
683 1.1 ragge if( rp->qe_odd_end )
684 1.1 ragge len++;
685 1.1 ragge /*
686 1.1 ragge * Init the buffer descriptor
687 1.1 ragge */
688 1.1 ragge bzero((caddr_t)rp, sizeof(struct qe_ring));
689 1.1 ragge if( --sc->nxmit == 0 ) {
690 1.1 ragge sc->qe_flags &= ~QEF_FASTTIMEO;
691 1.1 ragge sc->qe_if.if_timer = QESLOWTIMEOUT;
692 1.1 ragge }
693 1.1 ragge if( !setupflag ) {
694 1.1 ragge /*
695 1.1 ragge * Do some statistics.
696 1.1 ragge */
697 1.1 ragge sc->qe_if.if_opackets++;
698 1.1 ragge sc->qe_if.if_collisions += ( status1 & QE_CCNT ) >> 4;
699 1.1 ragge if (status1 & QE_ERROR)
700 1.1 ragge sc->qe_if.if_oerrors++;
701 1.1 ragge ifxp = &sc->qe_ifw[sc->otindex];
702 1.1 ragge if (ifxp->ifw_xtofree) {
703 1.1 ragge m_freem(ifxp->ifw_xtofree);
704 1.1 ragge ifxp->ifw_xtofree = 0;
705 1.1 ragge }
706 1.1 ragge }
707 1.1 ragge sc->otindex = ++sc->otindex % NXMT;
708 1.1 ragge }
709 1.7 ragge qestart(&sc->qe_if);
710 1.1 ragge }
711 1.1 ragge
712 1.1 ragge /*
713 1.1 ragge * Ethernet interface receiver interrupt.
714 1.1 ragge * If can't determine length from type, then have to drop packet.
715 1.1 ragge * Othewise decapsulate packet based on type and pass to type specific
716 1.1 ragge * higher-level input routine.
717 1.1 ragge */
718 1.7 ragge void
719 1.1 ragge qerint(unit)
720 1.1 ragge int unit;
721 1.1 ragge {
722 1.12 ragge register struct qe_softc *sc = qe_cd.cd_devs[unit];
723 1.7 ragge register struct qe_ring *rp;
724 1.1 ragge register int nrcv = 0;
725 1.1 ragge int len, status1, status2;
726 1.1 ragge int bufaddr;
727 1.1 ragge
728 1.1 ragge /*
729 1.1 ragge * Traverse the receive ring looking for packets to pass back.
730 1.1 ragge * The search is complete when we find a descriptor not in use.
731 1.1 ragge *
732 1.1 ragge * As in the transmit case the deqna doesn't honor it's own protocols
733 1.1 ragge * so there exists the possibility that the device can beat us around
734 1.1 ragge * the ring. The proper way to guard against this is to insure that
735 1.1 ragge * there is always at least one invalid descriptor. We chose instead
736 1.1 ragge * to make the ring large enough to minimize the problem. With a ring
737 1.1 ragge * size of 4 we haven't been able to see the problem. To be safe we
738 1.1 ragge * doubled that to 8.
739 1.1 ragge *
740 1.1 ragge */
741 1.1 ragge while (sc->rring[sc->rindex].qe_status1 == QE_NOTYET && nrcv < NRCV) {
742 1.1 ragge /*
743 1.1 ragge * We got an interrupt but did not find an input packet
744 1.1 ragge * where we expected one to be, probably because the ring
745 1.1 ragge * was overrun.
746 1.1 ragge * We search forward to find a valid packet and start
747 1.1 ragge * processing from there. If no valid packet is found it
748 1.1 ragge * means we processed all the packets during a previous
749 1.1 ragge * interrupt and that the QE_RCV_INT bit was set while
750 1.1 ragge * we were processing one of these earlier packets. In
751 1.1 ragge * this case we can safely ignore the interrupt (by dropping
752 1.1 ragge * through the code below).
753 1.1 ragge */
754 1.1 ragge sc->rindex = (sc->rindex + 1) % NRCV;
755 1.1 ragge nrcv++;
756 1.1 ragge }
757 1.26 ragge #ifndef QE_NO_OVERRUN_WARNINGS
758 1.1 ragge if (nrcv && nrcv < NRCV)
759 1.1 ragge log(LOG_ERR, "qe%d: ring overrun, resync'd by skipping %d\n",
760 1.1 ragge unit, nrcv);
761 1.26 ragge #endif
762 1.1 ragge
763 1.7 ragge for (; sc->rring[sc->rindex].qe_status1 != QE_NOTYET;
764 1.7 ragge sc->rindex = ++sc->rindex % NRCV) {
765 1.1 ragge rp = &sc->rring[sc->rindex];
766 1.1 ragge status1 = rp->qe_status1;
767 1.1 ragge status2 = rp->qe_status2;
768 1.1 ragge bzero((caddr_t)rp, sizeof(struct qe_ring));
769 1.1 ragge if( (status1 & QE_MASK) == QE_MASK )
770 1.1 ragge panic("qe: chained packet");
771 1.1 ragge len = ((status1 & QE_RBL_HI) | (status2 & QE_RBL_LO)) + 60;
772 1.1 ragge sc->qe_if.if_ipackets++;
773 1.1 ragge
774 1.1 ragge if (status1 & QE_ERROR) {
775 1.1 ragge if ((status1 & QE_RUNT) == 0)
776 1.1 ragge sc->qe_if.if_ierrors++;
777 1.1 ragge } else {
778 1.1 ragge /*
779 1.1 ragge * We don't process setup packets.
780 1.1 ragge */
781 1.7 ragge if (!(status1 & QE_ESETUP))
782 1.1 ragge qeread(sc, &sc->qe_ifr[sc->rindex],
783 1.1 ragge len - sizeof(struct ether_header));
784 1.1 ragge }
785 1.1 ragge /*
786 1.1 ragge * Return the buffer to the ring
787 1.1 ragge */
788 1.1 ragge bufaddr = (int)UBAI_ADDR(sc->qe_ifr[sc->rindex].ifrw_info);
789 1.1 ragge rp->qe_buf_len = -((MAXPACKETSIZE)/2);
790 1.1 ragge rp->qe_addr_lo = (short)bufaddr;
791 1.1 ragge rp->qe_addr_hi = (short)((int)bufaddr >> 16);
792 1.1 ragge rp->qe_flag = rp->qe_status1 = QE_NOTYET;
793 1.1 ragge rp->qe_valid = 1;
794 1.1 ragge }
795 1.1 ragge }
796 1.1 ragge
797 1.1 ragge /*
798 1.1 ragge * Process an ioctl request.
799 1.1 ragge */
800 1.7 ragge int
801 1.1 ragge qeioctl(ifp, cmd, data)
802 1.1 ragge register struct ifnet *ifp;
803 1.7 ragge u_long cmd;
804 1.1 ragge caddr_t data;
805 1.1 ragge {
806 1.14 thorpej struct qe_softc *sc = ifp->if_softc;
807 1.1 ragge struct ifaddr *ifa = (struct ifaddr *)data;
808 1.22 ragge struct ifreq *ifr = (struct ifreq *)data;
809 1.8 mycroft int s = splnet(), error = 0;
810 1.1 ragge
811 1.1 ragge switch (cmd) {
812 1.1 ragge
813 1.1 ragge case SIOCSIFADDR:
814 1.1 ragge ifp->if_flags |= IFF_UP;
815 1.14 thorpej qeinit(sc);
816 1.1 ragge switch(ifa->ifa_addr->sa_family) {
817 1.1 ragge #ifdef INET
818 1.1 ragge case AF_INET:
819 1.20 is arp_ifinit(ifp, ifa);
820 1.1 ragge break;
821 1.1 ragge #endif
822 1.1 ragge #ifdef NS
823 1.1 ragge case AF_NS:
824 1.1 ragge {
825 1.1 ragge register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
826 1.1 ragge
827 1.1 ragge if (ns_nullhost(*ina))
828 1.20 is ina->x_host =
829 1.20 is *(union ns_host *)LLADDR(ifp->if_sadl);
830 1.1 ragge else
831 1.14 thorpej qe_setaddr(ina->x_host.c_host, sc);
832 1.1 ragge break;
833 1.1 ragge }
834 1.1 ragge #endif
835 1.1 ragge }
836 1.1 ragge break;
837 1.1 ragge
838 1.1 ragge case SIOCSIFFLAGS:
839 1.1 ragge if ((ifp->if_flags & IFF_UP) == 0 &&
840 1.1 ragge sc->qe_flags & QEF_RUNNING) {
841 1.7 ragge sc->qe_vaddr->qe_csr = QE_RESET;
842 1.1 ragge sc->qe_flags &= ~QEF_RUNNING;
843 1.1 ragge } else if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) ==
844 1.1 ragge IFF_RUNNING && (sc->qe_flags & QEF_RUNNING) == 0)
845 1.1 ragge qerestart(sc);
846 1.19 ragge else
847 1.19 ragge qeinit(sc);
848 1.19 ragge
849 1.1 ragge break;
850 1.1 ragge
851 1.22 ragge case SIOCADDMULTI:
852 1.22 ragge case SIOCDELMULTI:
853 1.22 ragge /*
854 1.22 ragge * Update our multicast list.
855 1.22 ragge */
856 1.22 ragge error = (cmd == SIOCADDMULTI) ?
857 1.22 ragge ether_addmulti(ifr, &sc->qe_ec):
858 1.22 ragge ether_delmulti(ifr, &sc->qe_ec);
859 1.22 ragge
860 1.22 ragge if (error == ENETRESET) {
861 1.22 ragge /*
862 1.22 ragge * Multicast list has changed; set the hardware filter
863 1.22 ragge * accordingly.
864 1.22 ragge */
865 1.22 ragge qeinit(sc);
866 1.22 ragge error = 0;
867 1.22 ragge }
868 1.22 ragge break;
869 1.22 ragge
870 1.1 ragge default:
871 1.1 ragge error = EINVAL;
872 1.1 ragge
873 1.1 ragge }
874 1.1 ragge splx(s);
875 1.1 ragge return (error);
876 1.1 ragge }
877 1.1 ragge
878 1.1 ragge /*
879 1.1 ragge * set ethernet address for unit
880 1.1 ragge */
881 1.7 ragge void
882 1.14 thorpej qe_setaddr(physaddr, sc)
883 1.1 ragge u_char *physaddr;
884 1.14 thorpej struct qe_softc *sc;
885 1.1 ragge {
886 1.1 ragge register int i;
887 1.1 ragge
888 1.1 ragge for (i = 0; i < 6; i++)
889 1.20 is sc->setup_pkt[i][1] = LLADDR(sc->qe_if.if_sadl)[i]
890 1.20 is = physaddr[i];
891 1.1 ragge sc->qe_flags |= QEF_SETADDR;
892 1.1 ragge if (sc->qe_if.if_flags & IFF_RUNNING)
893 1.1 ragge qesetup(sc);
894 1.14 thorpej qeinit(sc);
895 1.1 ragge }
896 1.1 ragge
897 1.1 ragge
898 1.1 ragge /*
899 1.1 ragge * Initialize a ring descriptor with mbuf allocation side effects
900 1.1 ragge */
901 1.7 ragge void
902 1.1 ragge qeinitdesc(rp, addr, len)
903 1.7 ragge register struct qe_ring *rp;
904 1.21 ragge caddr_t addr; /* mapped address */
905 1.1 ragge int len;
906 1.1 ragge {
907 1.1 ragge /*
908 1.1 ragge * clear the entire descriptor
909 1.1 ragge */
910 1.1 ragge bzero((caddr_t)rp, sizeof(struct qe_ring));
911 1.1 ragge
912 1.7 ragge if (len) {
913 1.1 ragge rp->qe_buf_len = -(len/2);
914 1.1 ragge rp->qe_addr_lo = (short)((int)addr);
915 1.1 ragge rp->qe_addr_hi = (short)((int)addr >> 16);
916 1.1 ragge }
917 1.1 ragge }
918 1.1 ragge /*
919 1.1 ragge * Build a setup packet - the physical address will already be present
920 1.1 ragge * in first column.
921 1.1 ragge */
922 1.7 ragge void
923 1.7 ragge qesetup(sc)
924 1.7 ragge struct qe_softc *sc;
925 1.1 ragge {
926 1.32 ragge register int i, j;
927 1.1 ragge
928 1.1 ragge /*
929 1.1 ragge * Copy the target address to the rest of the entries in this row.
930 1.1 ragge */
931 1.7 ragge for (j = 0; j < 6; j++)
932 1.7 ragge for (i = 2; i < 8; i++)
933 1.1 ragge sc->setup_pkt[j][i] = sc->setup_pkt[j][1];
934 1.1 ragge /*
935 1.1 ragge * Duplicate the first half.
936 1.1 ragge */
937 1.1 ragge bcopy((caddr_t)sc->setup_pkt[0], (caddr_t)sc->setup_pkt[8], 64);
938 1.1 ragge /*
939 1.1 ragge * Fill in the broadcast (and ISO multicast) address(es).
940 1.1 ragge */
941 1.7 ragge for (i = 0; i < 6; i++) {
942 1.1 ragge sc->setup_pkt[i][2] = 0xff;
943 1.1 ragge #ifdef ISO
944 1.22 ragge /*
945 1.22 ragge * XXX layer violation, should use SIOCADDMULTI.
946 1.22 ragge * Will definitely break with IPmulticast.
947 1.22 ragge */
948 1.22 ragge
949 1.1 ragge sc->setup_pkt[i][3] = all_es_snpa[i];
950 1.1 ragge sc->setup_pkt[i][4] = all_is_snpa[i];
951 1.1 ragge sc->setup_pkt[i][5] = all_l1is_snpa[i];
952 1.1 ragge sc->setup_pkt[i][6] = all_l2is_snpa[i];
953 1.1 ragge #endif
954 1.1 ragge }
955 1.22 ragge if (sc->qe_if.if_flags & IFF_PROMISC) {
956 1.22 ragge sc->setuplength = QE_PROMISC;
957 1.22 ragge /* XXX no IFF_ALLMULTI support in 4.4bsd */
958 1.22 ragge } else if (sc->qe_if.if_flags & IFF_ALLMULTI) {
959 1.22 ragge sc->setuplength = QE_ALLMULTI;
960 1.22 ragge } else {
961 1.32 ragge register int k;
962 1.22 ragge struct ether_multi *enm;
963 1.22 ragge struct ether_multistep step;
964 1.22 ragge /*
965 1.22 ragge * Step through our list of multicast addresses, putting them
966 1.22 ragge * in the third through fourteenth address slots of the setup
967 1.22 ragge * packet. (See the DEQNA manual to understand the peculiar
968 1.22 ragge * layout of the bytes within the setup packet.) If we have
969 1.22 ragge * too many multicast addresses, or if we have to listen to
970 1.22 ragge * a range of multicast addresses, turn on reception of all
971 1.22 ragge * multicasts.
972 1.22 ragge */
973 1.22 ragge sc->setuplength = QE_SOMEMULTI;
974 1.22 ragge i = 2;
975 1.22 ragge k = 0;
976 1.22 ragge ETHER_FIRST_MULTI(step, &sc->qe_ec, enm);
977 1.22 ragge while (enm != NULL) {
978 1.22 ragge if ((++i > 7 && k != 0) ||
979 1.22 ragge bcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0) {
980 1.22 ragge sc->setuplength = QE_ALLMULTI;
981 1.22 ragge break;
982 1.22 ragge }
983 1.22 ragge if (i > 7) {
984 1.22 ragge i = 1;
985 1.22 ragge k = 8;
986 1.22 ragge }
987 1.22 ragge for (j = 0; j < 6; j++)
988 1.22 ragge sc->setup_pkt[j+k][i] = enm->enm_addrlo[j];
989 1.22 ragge ETHER_NEXT_MULTI(step, enm);
990 1.22 ragge }
991 1.22 ragge }
992 1.1 ragge sc->setupqueued++;
993 1.1 ragge }
994 1.1 ragge
995 1.1 ragge /*
996 1.1 ragge * Pass a packet to the higher levels.
997 1.1 ragge * We deal with the trailer protocol here.
998 1.1 ragge */
999 1.7 ragge void
1000 1.1 ragge qeread(sc, ifrw, len)
1001 1.7 ragge register struct qe_softc *sc;
1002 1.7 ragge struct ifrw *ifrw;
1003 1.1 ragge int len;
1004 1.1 ragge {
1005 1.1 ragge struct ether_header *eh;
1006 1.21 ragge struct mbuf *m;
1007 1.1 ragge
1008 1.1 ragge /*
1009 1.1 ragge * Deal with trailer protocol: if type is INET trailer
1010 1.1 ragge * get true type from first 16-bit word past data.
1011 1.1 ragge * Remember that type was trailer by setting off.
1012 1.1 ragge */
1013 1.1 ragge
1014 1.1 ragge eh = (struct ether_header *)ifrw->ifrw_addr;
1015 1.1 ragge if (len == 0)
1016 1.1 ragge return;
1017 1.1 ragge
1018 1.1 ragge /*
1019 1.1 ragge * Pull packet off interface. Off is nonzero if packet
1020 1.1 ragge * has trailing header; qeget will then force this header
1021 1.1 ragge * information to be at the front, but we still have to drop
1022 1.1 ragge * the type and length which are at the front of any trailer data.
1023 1.1 ragge */
1024 1.2 mycroft m = if_ubaget(&sc->qe_uba, ifrw, len, &sc->qe_if);
1025 1.1 ragge #ifdef notdef
1026 1.1 ragge if (m) {
1027 1.1 ragge *(((u_long *)m->m_data)+0),
1028 1.1 ragge *(((u_long *)m->m_data)+1),
1029 1.1 ragge *(((u_long *)m->m_data)+2),
1030 1.1 ragge *(((u_long *)m->m_data)+3)
1031 1.22 ragge ; }
1032 1.1 ragge #endif
1033 1.34 thorpej if (m == NULL)
1034 1.34 thorpej return;
1035 1.34 thorpej
1036 1.34 thorpej /*
1037 1.34 thorpej * XXX I'll let ragge make this sane. I'm not entirely
1038 1.34 thorpej * XXX sure what's going on in if_ubaget().
1039 1.34 thorpej */
1040 1.35 ragge M_PREPEND(m, sizeof(struct ether_header), M_DONTWAIT);
1041 1.34 thorpej if (m == NULL)
1042 1.34 thorpej return;
1043 1.35 ragge bcopy(eh, mtod(m, caddr_t), sizeof(struct ether_header));
1044 1.22 ragge
1045 1.22 ragge #if NBPFILTER > 0
1046 1.22 ragge /*
1047 1.22 ragge * Check for a BPF filter; if so, hand it up.
1048 1.22 ragge * Note that we have to stick an extra mbuf up front, because
1049 1.22 ragge * bpf_mtap expects to have the ether header at the front.
1050 1.22 ragge * It doesn't matter that this results in an ill-formatted mbuf chain,
1051 1.22 ragge * since BPF just looks at the data. (It doesn't try to free the mbuf,
1052 1.22 ragge * tho' it will make a copy for tcpdump.)
1053 1.22 ragge */
1054 1.22 ragge if (sc->qe_if.if_bpf) {
1055 1.22 ragge /* Pass it up */
1056 1.34 thorpej bpf_mtap(sc->qe_if.if_bpf, m);
1057 1.22 ragge
1058 1.22 ragge /*
1059 1.22 ragge * Note that the interface cannot be in promiscuous mode if
1060 1.22 ragge * there are no BPF listeners. And if we are in promiscuous
1061 1.22 ragge * mode, we have to check if this packet is really ours.
1062 1.22 ragge */
1063 1.26 ragge if ((sc->qe_if.if_flags & IFF_PROMISC) &&
1064 1.22 ragge (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
1065 1.22 ragge bcmp(eh->ether_dhost, LLADDR(sc->qe_if.if_sadl),
1066 1.22 ragge sizeof(eh->ether_dhost)) != 0) {
1067 1.22 ragge m_freem(m);
1068 1.22 ragge return;
1069 1.22 ragge }
1070 1.22 ragge }
1071 1.22 ragge #endif /* NBPFILTER > 0 */
1072 1.1 ragge
1073 1.34 thorpej (*sc->qe_if.if_input)(&sc->qe_if, m);
1074 1.1 ragge }
1075 1.1 ragge
1076 1.1 ragge /*
1077 1.1 ragge * Watchdog timeout routine. There is a condition in the hardware that
1078 1.1 ragge * causes the board to lock up under heavy load. This routine detects
1079 1.1 ragge * the hang up and restarts the device.
1080 1.1 ragge */
1081 1.5 ragge void
1082 1.14 thorpej qetimeout(ifp)
1083 1.14 thorpej struct ifnet *ifp;
1084 1.1 ragge {
1085 1.14 thorpej register struct qe_softc *sc = ifp->if_softc;
1086 1.1 ragge
1087 1.1 ragge #ifdef notdef
1088 1.14 thorpej log(LOG_ERR, "%s: transmit timeout, restarted %d\n",
1089 1.14 thorpej sc->sc_dev.dv_xname, sc->qe_restarts++);
1090 1.1 ragge #endif
1091 1.1 ragge qerestart(sc);
1092 1.1 ragge }
1093 1.1 ragge /*
1094 1.1 ragge * Restart for board lockup problem.
1095 1.1 ragge */
1096 1.7 ragge void
1097 1.1 ragge qerestart(sc)
1098 1.7 ragge struct qe_softc *sc;
1099 1.1 ragge {
1100 1.1 ragge register struct ifnet *ifp = (struct ifnet *)&sc->qe_if;
1101 1.7 ragge register struct qedevice *addr = sc->addr;
1102 1.7 ragge register struct qe_ring *rp;
1103 1.32 ragge register int i;
1104 1.1 ragge
1105 1.1 ragge addr->qe_csr = QE_RESET;
1106 1.1 ragge addr->qe_csr &= ~QE_RESET;
1107 1.7 ragge qesetup(sc);
1108 1.1 ragge for (i = 0, rp = sc->tring; i < NXMT; rp++, i++) {
1109 1.1 ragge rp->qe_flag = rp->qe_status1 = QE_NOTYET;
1110 1.1 ragge rp->qe_valid = 0;
1111 1.1 ragge }
1112 1.1 ragge sc->nxmit = sc->otindex = sc->tindex = sc->rindex = 0;
1113 1.1 ragge addr->qe_csr = QE_RCV_ENABLE | QE_INT_ENABLE | QE_XMIT_INT |
1114 1.1 ragge QE_RCV_INT | QE_ILOOP;
1115 1.1 ragge addr->qe_rcvlist_lo = (short)((int)sc->rringaddr);
1116 1.1 ragge addr->qe_rcvlist_hi = (short)((int)sc->rringaddr >> 16);
1117 1.1 ragge sc->qe_flags |= QEF_RUNNING;
1118 1.2 mycroft qestart(ifp);
1119 1.1 ragge }
1120