if_qt.c revision 1.1 1 1.1 ragge /* $NetBSD: if_qt.c,v 1.1 2003/08/28 10:03:32 ragge Exp $ */
2 1.1 ragge /*
3 1.1 ragge * Copyright (c) 1992 Steven M. Schultz
4 1.1 ragge * All rights reserved.
5 1.1 ragge *
6 1.1 ragge * Redistribution and use in source and binary forms, with or without
7 1.1 ragge * modification, are permitted provided that the following conditions
8 1.1 ragge * are met:
9 1.1 ragge * 1. Redistributions of source code must retain the above copyright
10 1.1 ragge * notice, this list of conditions and the following disclaimer.
11 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 ragge * notice, this list of conditions and the following disclaimer in the
13 1.1 ragge * documentation and/or other materials provided with the distribution.
14 1.1 ragge * 3. The name of the author may not be used to endorse or promote products
15 1.1 ragge * derived from this software without specific prior written permission
16 1.1 ragge *
17 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 ragge *
28 1.1 ragge * @(#)if_qt.c 1.2 (2.11BSD) 2/20/93
29 1.1 ragge */
30 1.1 ragge /*
31 1.1 ragge *
32 1.1 ragge * Modification History
33 1.1 ragge * 23-Feb-92 -- sms
34 1.1 ragge * Rewrite the buffer handling so that fewer than the maximum number of
35 1.1 ragge * buffers may be used (32 receive and 12 transmit buffers consume 66+kb
36 1.1 ragge * of main system memory in addition to the internal structures in the
37 1.1 ragge * networking code). A freelist of available buffers is maintained now.
38 1.1 ragge * When I/O operations complete the associated buffer is placed on the
39 1.1 ragge * freelist (a single linked list for simplicity) and when an I/O is
40 1.1 ragge * started a buffer is pulled off the list.
41 1.1 ragge *
42 1.1 ragge * 20-Feb-92 -- sms
43 1.1 ragge * It works! Darned board couldn't handle "short" rings - those rings
44 1.1 ragge * where only half the entries were made available to the board (the
45 1.1 ragge * ring descriptors were the full size, merely half the entries were
46 1.1 ragge * flagged as belonging always to the driver). Grrrr. Would have thought
47 1.1 ragge * the board could skip over those entries reserved by the driver.
48 1.1 ragge * Now to find a way not to have to allocated 32+12 times 1.5kb worth of
49 1.1 ragge * buffers...
50 1.1 ragge *
51 1.1 ragge * 03-Feb-92 -- sms
52 1.1 ragge * Released but still not working. The driver now responds to arp and
53 1.1 ragge * ping requests. The board is apparently not returning ring descriptors
54 1.1 ragge * to the driver so eventually we run out of buffers. Back to the
55 1.1 ragge * drawing board.
56 1.1 ragge *
57 1.1 ragge * 28-Dec-92 -- sms
58 1.1 ragge * Still not released. Hiatus in finding free time and thin-netting
59 1.1 ragge * the systems (many thanks Terry!).
60 1.1 ragge * Added logic to dynamically allocate a vector and initialize it.
61 1.1 ragge *
62 1.1 ragge * 23-Oct-92 -- sms
63 1.1 ragge * The INIT block must (apparently) be quadword aligned [no thanks to
64 1.1 ragge * the manual for not mentioning that fact]. The necessary alignment
65 1.1 ragge * is achieved by allocating the INIT block from main memory ('malloc'
66 1.1 ragge * guarantees click alignment) and mapping it as needed (which is _very_
67 1.1 ragge * infrequently). A check for quadword alignment of the ring descriptors
68 1.1 ragge * was added - at present the descriptors are properly aligned, if this
69 1.1 ragge * should change then something will have to be done (like do it "right").
70 1.1 ragge * Darned alignment restrictions!
71 1.1 ragge *
72 1.1 ragge * A couple of typos were corrected (missing parentheses, reversed
73 1.1 ragge * arguments to printf calls, etc).
74 1.1 ragge *
75 1.1 ragge * 13-Oct-92 -- sms (at) wlv.iipo.gtegsc.com
76 1.1 ragge * Created based on the DELQA-PLUS addendum to DELQA User's Guide.
77 1.1 ragge * This driver ('qt') is selected at system configuration time. If the
78 1.1 ragge * board * is not a DELQA-YM an error message will be printed and the
79 1.1 ragge * interface will not be attached.
80 1.1 ragge */
81 1.1 ragge
82 1.1 ragge #include "qt.h"
83 1.1 ragge #if NQT > 0
84 1.1 ragge
85 1.1 ragge #include "param.h"
86 1.1 ragge #include "pdp/psl.h"
87 1.1 ragge #include "pdp/seg.h"
88 1.1 ragge #include "map.h"
89 1.1 ragge #include "systm.h"
90 1.1 ragge #include "mbuf.h"
91 1.1 ragge #include "buf.h"
92 1.1 ragge #include "protosw.h"
93 1.1 ragge #include "socket.h"
94 1.1 ragge #include "ioctl.h"
95 1.1 ragge #include "errno.h"
96 1.1 ragge #include "syslog.h"
97 1.1 ragge #include "time.h"
98 1.1 ragge #include "kernel.h"
99 1.1 ragge
100 1.1 ragge #include "../net/if.h"
101 1.1 ragge #include "../net/netisr.h"
102 1.1 ragge #include "../net/route.h"
103 1.1 ragge
104 1.1 ragge #ifdef INET
105 1.1 ragge #include "domain.h"
106 1.1 ragge #include "../netinet/in.h"
107 1.1 ragge #include "../netinet/in_systm.h"
108 1.1 ragge #include "../netinet/in_var.h"
109 1.1 ragge #include "../netinet/ip.h"
110 1.1 ragge #include "../netinet/if_ether.h"
111 1.1 ragge #endif
112 1.1 ragge
113 1.1 ragge #ifdef NS
114 1.1 ragge #include "../netns/ns.h"
115 1.1 ragge #include "../netns/ns_if.h"
116 1.1 ragge #endif
117 1.1 ragge
118 1.1 ragge #include "if_qtreg.h"
119 1.1 ragge #include "if_uba.h"
120 1.1 ragge #include "../pdpuba/ubavar.h"
121 1.1 ragge
122 1.1 ragge #define NRCV 16 /* Receive descriptors (must be <= 32) */
123 1.1 ragge #define NXMT 6 /* Transmit descriptors (must be <= 12) */
124 1.1 ragge #if NRCV > 32 || NXMT > 12
125 1.1 ragge generate an error
126 1.1 ragge #endif
127 1.1 ragge
128 1.1 ragge struct qt_uba
129 1.1 ragge {
130 1.1 ragge struct qt_uba *next; /* link to next buffer in list or
131 1.1 ragge * NULL if the last buffer
132 1.1 ragge */
133 1.1 ragge struct ifuba ubabuf; /* buffer descriptor */
134 1.1 ragge };
135 1.1 ragge
136 1.1 ragge struct qt_softc {
137 1.1 ragge struct arpcom is_ac; /* common part - must be first */
138 1.1 ragge #define is_if is_ac.ac_if /* network-visible interface */
139 1.1 ragge #define is_addr is_ac.ac_enaddr /* hardware Ethernet address */
140 1.1 ragge struct qt_uba *freelist; /* list of available buffers */
141 1.1 ragge struct qt_uba ifrw[NRCV + NXMT];
142 1.1 ragge u_short initclick; /* click addr of the INIT block */
143 1.1 ragge struct qt_rring *rring; /* Receive ring address */
144 1.1 ragge struct qt_tring *tring; /* Transmit ring address */
145 1.1 ragge char r_align[QT_MAX_RCV * sizeof (struct qt_rring) + 8];
146 1.1 ragge char t_align[QT_MAX_XMT * sizeof (struct qt_tring) + 8];
147 1.1 ragge short qt_flags; /* software state */
148 1.1 ragge #define QTF_RUNNING 0x1
149 1.1 ragge #define QTF_STARTUP 0x2 /* Waiting for start interrupt */
150 1.1 ragge char rindex; /* Receive Completed Index */
151 1.1 ragge char nxtrcv; /* Next Receive Index */
152 1.1 ragge char nrcv; /* Number of Receives active */
153 1.1 ragge char tindex; /* Transmit index */
154 1.1 ragge char otindex; /* Old transmit index */
155 1.1 ragge char nxmit; /* # of xmits in progress */
156 1.1 ragge struct qtdevice *addr; /* device CSR addr */
157 1.1 ragge } qt_softc[NQT];
158 1.1 ragge
159 1.1 ragge struct uba_device *qtinfo[NQT];
160 1.1 ragge
161 1.1 ragge int qtattach(), qtintr(), qtinit(), qtoutput(), qtioctl();
162 1.1 ragge
163 1.1 ragge extern struct ifnet loif;
164 1.1 ragge
165 1.1 ragge u_short qtstd[] = { 0 };
166 1.1 ragge
167 1.1 ragge struct uba_driver qtdriver =
168 1.1 ragge { 0, 0, qtattach, 0, qtstd, "qe", qtinfo };
169 1.1 ragge
170 1.1 ragge /*
171 1.1 ragge * Maximum packet size needs to include 4 bytes for the CRC
172 1.1 ragge * on received packets.
173 1.1 ragge */
174 1.1 ragge #define MAXPACKETSIZE (ETHERMTU + sizeof (struct ether_header) + 4)
175 1.1 ragge #define MINPACKETSIZE 64
176 1.1 ragge
177 1.1 ragge /*
178 1.1 ragge * The C compiler's propensity for prepending '_'s to names is the reason
179 1.1 ragge * for the hack below. We need the "handler" address (the code which
180 1.1 ragge * sets up the interrupt stack frame) in order to initialize the vector.
181 1.1 ragge */
182 1.1 ragge
183 1.1 ragge static int qtfoo()
184 1.1 ragge {
185 1.1 ragge asm("mov $qtintr, r0"); /* return value is in r0 */
186 1.1 ragge }
187 1.1 ragge
188 1.1 ragge /*
189 1.1 ragge * Interface exists. More accurately, something exists at the CSR (see
190 1.1 ragge * sys/sys_net.c) -- there's no guarantee it's a DELQA-YM.
191 1.1 ragge *
192 1.1 ragge * The ring descriptors are initialized, the buffers allocated using first the
193 1.1 ragge * DMA region allocated at network load time and then later main memory. The
194 1.1 ragge * INIT block is filled in and the device is poked/probed to see if it really
195 1.1 ragge * is a DELQA-YM. If the device is not a -YM then a message is printed and
196 1.1 ragge * the 'if_attach' call is skipped. For a -YM the START command is issued,
197 1.1 ragge * but the device is not marked as running|up - that happens at interrupt level
198 1.1 ragge * when the device interrupts to say it has started.
199 1.1 ragge */
200 1.1 ragge
201 1.1 ragge qtattach(ui)
202 1.1 ragge struct uba_device *ui;
203 1.1 ragge {
204 1.1 ragge register struct qt_softc *sc = &qt_softc[ui->ui_unit];
205 1.1 ragge register struct ifnet *ifp = &sc->is_if;
206 1.1 ragge register struct qt_init *iniblk = (struct qt_init *)SEG5;
207 1.1 ragge segm seg5;
208 1.1 ragge long bufaddr;
209 1.1 ragge extern int nextiv();
210 1.1 ragge
211 1.1 ragge ifp->if_unit = ui->ui_unit;
212 1.1 ragge ifp->if_name = "qe";
213 1.1 ragge ifp->if_mtu = ETHERMTU;
214 1.1 ragge ifp->if_flags = IFF_BROADCAST;
215 1.1 ragge
216 1.1 ragge /*
217 1.1 ragge * Fill in most of the INIT block: vector, options (interrupt enable), ring
218 1.1 ragge * locations. The physical address is copied from the ROMs as part of the
219 1.1 ragge * -YM testing proceedure. The CSR is saved here rather than in qtinit()
220 1.1 ragge * because the qtturbo() routine needs it.
221 1.1 ragge *
222 1.1 ragge * The INIT block must be quadword aligned. Using malloc() guarantees click
223 1.1 ragge * (64 byte) alignment. Since the only time the INIT block is referenced is
224 1.1 ragge * at 'startup' or 'reset' time there is really no time penalty (and a modest
225 1.1 ragge * D space savings) involved.
226 1.1 ragge */
227 1.1 ragge sc->addr = (struct qtdevice *)ui->ui_addr;
228 1.1 ragge sc->initclick = MALLOC(coremap, btoc(sizeof (struct qt_init)));
229 1.1 ragge saveseg5(seg5);
230 1.1 ragge mapseg5(sc->initclick, 077406);
231 1.1 ragge bzero(iniblk, sizeof (struct qt_init));
232 1.1 ragge sc->rring = (struct qt_rring *)(((int)sc->r_align + 7) & ~7);
233 1.1 ragge sc->tring = (struct qt_tring *)(((int)sc->t_align + 7) & ~7);
234 1.1 ragge
235 1.1 ragge /*
236 1.1 ragge * Fetch the next available interrupt vector. The routine is in the kernel
237 1.1 ragge * (for several reasons) so use SKcall. Then initialize the vector with
238 1.1 ragge * the address of our 'handler' and PSW of supervisor, priority 4 and unit
239 1.1 ragge */
240 1.1 ragge iniblk->vector = SKcall(nextiv, 0);
241 1.1 ragge mtkd(iniblk->vector, qtfoo());
242 1.1 ragge mtkd(iniblk->vector + 2, PSL_CURSUP | PSL_BR4 | ifp->if_unit);
243 1.1 ragge
244 1.1 ragge iniblk->options = INIT_OPTIONS_INT;
245 1.1 ragge bufaddr = startnet + (long)sc->rring;
246 1.1 ragge iniblk->rx_lo = loint(bufaddr);
247 1.1 ragge iniblk->rx_hi = hiint(bufaddr);
248 1.1 ragge bufaddr = startnet + (long)sc->tring;
249 1.1 ragge iniblk->tx_lo = loint(bufaddr);
250 1.1 ragge iniblk->tx_hi = hiint(bufaddr);
251 1.1 ragge restorseg5(seg5);
252 1.1 ragge
253 1.1 ragge /*
254 1.1 ragge * Now allocate the buffers and initialize the buffers. This should _never_
255 1.1 ragge * fail because main memory is allocated after the DMA pool is used up.
256 1.1 ragge */
257 1.1 ragge
258 1.1 ragge if (!qbaini(sc, NRCV + NXMT))
259 1.1 ragge return; /* XXX */
260 1.1 ragge
261 1.1 ragge ifp->if_init = qtinit;
262 1.1 ragge ifp->if_output = qtoutput;
263 1.1 ragge ifp->if_ioctl = qtioctl;
264 1.1 ragge ifp->if_reset = 0;
265 1.1 ragge if (qtturbo(sc))
266 1.1 ragge if_attach(ifp);
267 1.1 ragge }
268 1.1 ragge
269 1.1 ragge qtturbo(sc)
270 1.1 ragge register struct qt_softc *sc;
271 1.1 ragge {
272 1.1 ragge register int i;
273 1.1 ragge register struct qtdevice *addr = sc->addr;
274 1.1 ragge struct qt_init *iniblk = (struct qt_init *)SEG5;
275 1.1 ragge segm seg5;
276 1.1 ragge
277 1.1 ragge /*
278 1.1 ragge * Issue the software reset. Delay 150us. The board should now be in
279 1.1 ragge * DELQA-Normal mode. Set ITB and DEQTA select. If both bits do not
280 1.1 ragge * stay turned on then the board is not a DELQA-YM.
281 1.1 ragge */
282 1.1 ragge addr->arqr = ARQR_SR;
283 1.1 ragge addr->arqr = 0;
284 1.1 ragge delay(150L);
285 1.1 ragge
286 1.1 ragge addr->srr = 0x8001; /* MS | ITB */
287 1.1 ragge i = addr->srr;
288 1.1 ragge addr->srr = 0x8000; /* Turn off ITB, set DELQA select */
289 1.1 ragge if (i != 0x8001)
290 1.1 ragge {
291 1.1 ragge printf("qt@%o !-YM\n", addr);
292 1.1 ragge return(0);
293 1.1 ragge }
294 1.1 ragge /*
295 1.1 ragge * Board is a DELQA-YM. Send the commands to enable Turbo mode. Delay
296 1.1 ragge * 1 second, testing the SRR register every millisecond to see if the
297 1.1 ragge * board has shifted to Turbo mode.
298 1.1 ragge */
299 1.1 ragge addr->xcr0 = 0x0baf;
300 1.1 ragge addr->xcr1 = 0xff00;
301 1.1 ragge for (i = 0; i < 1000; i++)
302 1.1 ragge {
303 1.1 ragge if ((addr->srr & SRR_RESP) == 1)
304 1.1 ragge break;
305 1.1 ragge delay(1000L);
306 1.1 ragge }
307 1.1 ragge if (i >= 1000)
308 1.1 ragge {
309 1.1 ragge printf("qt@%o !Turbo\n", addr);
310 1.1 ragge return(0);
311 1.1 ragge }
312 1.1 ragge /*
313 1.1 ragge * Board has entered Turbo mode. Now copy the physical address from the
314 1.1 ragge * ROMs to the INIT block. Fill in the address in the part of the structure
315 1.1 ragge * "visible" to the rest of the system.
316 1.1 ragge */
317 1.1 ragge saveseg5(seg5);
318 1.1 ragge mapseg5(sc->initclick, 077406);
319 1.1 ragge sc->is_addr[0] = addr->sarom[0];
320 1.1 ragge sc->is_addr[1] = addr->sarom[2];
321 1.1 ragge sc->is_addr[2] = addr->sarom[4];
322 1.1 ragge sc->is_addr[3] = addr->sarom[6];
323 1.1 ragge sc->is_addr[4] = addr->sarom[8];
324 1.1 ragge sc->is_addr[5] = addr->sarom[10];
325 1.1 ragge bcopy(sc->is_addr, iniblk->paddr, 6);
326 1.1 ragge restorseg5(seg5);
327 1.1 ragge return(1);
328 1.1 ragge }
329 1.1 ragge
330 1.1 ragge qtinit(unit)
331 1.1 ragge int unit;
332 1.1 ragge {
333 1.1 ragge int s;
334 1.1 ragge register struct qt_softc *sc = &qt_softc[unit];
335 1.1 ragge struct qtdevice *addr = sc->addr;
336 1.1 ragge struct ifnet *ifp = &sc->is_if;
337 1.1 ragge struct qt_rring *rp;
338 1.1 ragge struct qt_tring *tp;
339 1.1 ragge register struct qt_uba *xp;
340 1.1 ragge register int i;
341 1.1 ragge long buf_adr;
342 1.1 ragge
343 1.1 ragge if (!ifp->if_addrlist) /* oops! */
344 1.1 ragge return;
345 1.1 ragge /*
346 1.1 ragge * Now initialize the receive ring descriptors. Because this routine can be
347 1.1 ragge * called with outstanding I/O operations we check the ring descriptors for
348 1.1 ragge * a non-zero 'rhost0' (or 'thost0') word and place those buffers back on
349 1.1 ragge * the free list.
350 1.1 ragge */
351 1.1 ragge for (i = 0, rp = sc->rring; i < QT_MAX_RCV; i++, rp++)
352 1.1 ragge {
353 1.1 ragge rp->rmd3 = RMD3_OWN;
354 1.1 ragge if (xp = rp->rhost0)
355 1.1 ragge {
356 1.1 ragge rp->rhost0 = 0;
357 1.1 ragge xp->next = sc->freelist;
358 1.1 ragge sc->freelist = xp;
359 1.1 ragge }
360 1.1 ragge }
361 1.1 ragge for (i = 0, tp = sc->tring ; i < QT_MAX_XMT; i++, tp++)
362 1.1 ragge {
363 1.1 ragge sc->tring[i].tmd3 = TMD3_OWN;
364 1.1 ragge if (xp = tp->thost0)
365 1.1 ragge {
366 1.1 ragge tp->thost0 = 0;
367 1.1 ragge xp->next = sc->freelist;
368 1.1 ragge sc->freelist = xp;
369 1.1 ragge }
370 1.1 ragge }
371 1.1 ragge
372 1.1 ragge sc->nxmit = 0;
373 1.1 ragge sc->otindex = 0;
374 1.1 ragge sc->tindex = 0;
375 1.1 ragge sc->rindex = 0;
376 1.1 ragge sc->nxtrcv = 0;
377 1.1 ragge sc->nrcv = 0;
378 1.1 ragge
379 1.1 ragge s = splimp();
380 1.1 ragge /*
381 1.1 ragge * Now we tell the device the address of the INIT block. The device
382 1.1 ragge * _must_ be in the Turbo mode at this time. The "START" command is
383 1.1 ragge * then issued to the device. A 1 second timeout is then started.
384 1.1 ragge * When the interrupt occurs the IFF_UP|IFF_RUNNING state is entered and
385 1.1 ragge * full operations will proceed. If the timeout expires without an interrupt
386 1.1 ragge * being received an error is printed, the flags cleared and the device left
387 1.1 ragge * marked down.
388 1.1 ragge */
389 1.1 ragge buf_adr = ctob((long)sc->initclick);
390 1.1 ragge addr->ibal = loint(buf_adr);
391 1.1 ragge addr->ibah = hiint(buf_adr);
392 1.1 ragge addr->srqr = 2;
393 1.1 ragge /*
394 1.1 ragge * set internal state to 'startup' and start a one second timer. the interrupt
395 1.1 ragge * service routine will be entered either 1) when the device posts the 'start'
396 1.1 ragge * interrupt or 2) when the timer expires. The interrupt routine will fill
397 1.1 ragge * the receive rings, etc.
398 1.1 ragge */
399 1.1 ragge sc->qt_flags = QTF_STARTUP;
400 1.1 ragge TIMEOUT(qtintr, unit, 60);
401 1.1 ragge splx(s);
402 1.1 ragge }
403 1.1 ragge
404 1.1 ragge /*
405 1.1 ragge * Start output on interface.
406 1.1 ragge */
407 1.1 ragge
408 1.1 ragge qtstart(unit)
409 1.1 ragge int unit;
410 1.1 ragge {
411 1.1 ragge int len, s;
412 1.1 ragge register struct qt_softc *sc = &qt_softc[unit];
413 1.1 ragge register struct qt_tring *rp;
414 1.1 ragge struct mbuf *m;
415 1.1 ragge long buf_addr;
416 1.1 ragge register struct qt_uba *xp;
417 1.1 ragge
418 1.1 ragge s = splimp();
419 1.1 ragge while (sc->nxmit < NXMT)
420 1.1 ragge {
421 1.1 ragge IF_DEQUEUE(&sc->is_if.if_snd, m);
422 1.1 ragge if (m == 0)
423 1.1 ragge break;
424 1.1 ragge rp = &sc->tring[sc->tindex];
425 1.1 ragge #ifdef QTDEBUG
426 1.1 ragge if ((rp->tmd3 & TMD3_OWN) == 0)
427 1.1 ragge printf("qt xmit in progress\n");
428 1.1 ragge #endif
429 1.1 ragge /*
430 1.1 ragge * Now pull a buffer off of the freelist. Guaranteed to be a buffer
431 1.1 ragge * because both the receive and transmit sides limit themselves to
432 1.1 ragge * NRCV and NXMT buffers respectively.
433 1.1 ragge */
434 1.1 ragge xp = sc->freelist;
435 1.1 ragge sc->freelist = xp->next;
436 1.1 ragge
437 1.1 ragge buf_addr = xp->ubabuf.ifu_w.ifrw_info;
438 1.1 ragge len = if_wubaput(&xp->ubabuf, m);
439 1.1 ragge if (len < MINPACKETSIZE)
440 1.1 ragge len = MINPACKETSIZE;
441 1.1 ragge rp->tmd4 = loint(buf_addr);
442 1.1 ragge rp->tmd5 = hiint(buf_addr) & TMD5_HADR;
443 1.1 ragge rp->tmd3 = len & TMD3_BCT; /* set length,clear ownership */
444 1.1 ragge rp->thost0 = xp; /* set entry active */
445 1.1 ragge sc->addr->arqr = ARQR_TRQ; /* tell device it has buffer */
446 1.1 ragge sc->nxmit++;
447 1.1 ragge if (++sc->tindex >= QT_MAX_XMT)
448 1.1 ragge sc->tindex = 0;
449 1.1 ragge }
450 1.1 ragge splx(s);
451 1.1 ragge }
452 1.1 ragge
453 1.1 ragge /*
454 1.1 ragge * General interrupt service routine. Receive, transmit, device start
455 1.1 ragge * interrupts and timeouts come here. Check for hard device errors and print a
456 1.1 ragge * message if any errors are found. If we are waiting for the device to
457 1.1 ragge * START then check if the device is now running.
458 1.1 ragge */
459 1.1 ragge
460 1.1 ragge qtintr(unit)
461 1.1 ragge int unit;
462 1.1 ragge {
463 1.1 ragge register struct qt_softc *sc = &qt_softc[unit];
464 1.1 ragge register int status;
465 1.1 ragge int s;
466 1.1 ragge
467 1.1 ragge status = sc->addr->srr;
468 1.1 ragge if (status < 0)
469 1.1 ragge /* should we reset the device after a bunch of these errs? */
470 1.1 ragge qtsrr(unit, status);
471 1.1 ragge if (sc->qt_flags == QTF_STARTUP)
472 1.1 ragge {
473 1.1 ragge if ((status & SRR_RESP) == 2)
474 1.1 ragge {
475 1.1 ragge sc->qt_flags = QTF_RUNNING;
476 1.1 ragge sc->is_if.if_flags |= (IFF_UP | IFF_RUNNING);
477 1.1 ragge }
478 1.1 ragge else
479 1.1 ragge printf("qt%d !start\n", unit);
480 1.1 ragge }
481 1.1 ragge s = splimp();
482 1.1 ragge qtrint(unit);
483 1.1 ragge if (sc->nxmit)
484 1.1 ragge qttint(unit);
485 1.1 ragge qtstart(unit);
486 1.1 ragge splx(s);
487 1.1 ragge }
488 1.1 ragge
489 1.1 ragge /*
490 1.1 ragge * Transmit interrupt service. Only called if there are outstanding transmit
491 1.1 ragge * requests which could have completed. The DELQA-YM doesn't provide the
492 1.1 ragge * status bits telling the kind (receive, transmit) of interrupt.
493 1.1 ragge */
494 1.1 ragge
495 1.1 ragge #define BBLMIS (TMD2_BBL|TMD2_MIS)
496 1.1 ragge
497 1.1 ragge qttint(unit)
498 1.1 ragge int unit;
499 1.1 ragge {
500 1.1 ragge register struct qt_softc *sc = &qt_softc[unit];
501 1.1 ragge register struct qt_tring *rp;
502 1.1 ragge register struct qt_uba *xp;
503 1.1 ragge
504 1.1 ragge while (sc->nxmit > 0)
505 1.1 ragge {
506 1.1 ragge rp = &sc->tring[sc->otindex];
507 1.1 ragge if ((rp->tmd3 & TMD3_OWN) == 0)
508 1.1 ragge break;
509 1.1 ragge /*
510 1.1 ragge * Now check the buffer address (the first word in the ring descriptor
511 1.1 ragge * available for the host's use). If it is NULL then we have already seen
512 1.1 ragge * and processed (or never presented to the board in the first place) this
513 1.1 ragge * entry and the ring descriptor should not be counted.
514 1.1 ragge */
515 1.1 ragge xp = rp->thost0;
516 1.1 ragge if (xp == 0)
517 1.1 ragge break;
518 1.1 ragge /*
519 1.1 ragge * Clear the buffer address from the ring descriptor and put the
520 1.1 ragge * buffer back on the freelist for future use.
521 1.1 ragge */
522 1.1 ragge rp->thost0 = 0;
523 1.1 ragge xp->next = sc->freelist;
524 1.1 ragge sc->freelist = xp;
525 1.1 ragge
526 1.1 ragge sc->nxmit--;
527 1.1 ragge sc->is_if.if_opackets++;
528 1.1 ragge /*
529 1.1 ragge * Collisions don't count as output errors, but babbling and missing packets
530 1.1 ragge * do count as output errors.
531 1.1 ragge */
532 1.1 ragge if (rp->tmd2 & TMD2_CER)
533 1.1 ragge sc->is_if.if_collisions++;
534 1.1 ragge if ((rp->tmd0 & TMD0_ERR1) ||
535 1.1 ragge ((rp->tmd2 & TMD2_ERR2) && (rp->tmd2 & BBLMIS)))
536 1.1 ragge {
537 1.1 ragge #ifdef QTDEBUG
538 1.1 ragge printf("qt%d tmd2 %b\n", unit, rp->tmd2, TMD2_BITS);
539 1.1 ragge #endif
540 1.1 ragge sc->is_if.if_oerrors++;
541 1.1 ragge }
542 1.1 ragge if (++sc->otindex >= QT_MAX_XMT)
543 1.1 ragge sc->otindex = 0;
544 1.1 ragge }
545 1.1 ragge }
546 1.1 ragge
547 1.1 ragge /*
548 1.1 ragge * Receive interrupt service. Pull packet off the interface and put into
549 1.1 ragge * a mbuf chain for processing later.
550 1.1 ragge */
551 1.1 ragge
552 1.1 ragge qtrint(unit)
553 1.1 ragge int unit;
554 1.1 ragge {
555 1.1 ragge register struct qt_softc *sc = &qt_softc[unit];
556 1.1 ragge register struct qt_rring *rp;
557 1.1 ragge register struct qt_uba *xp;
558 1.1 ragge int len;
559 1.1 ragge long bufaddr;
560 1.1 ragge
561 1.1 ragge while (sc->rring[sc->rindex].rmd3 & RMD3_OWN)
562 1.1 ragge {
563 1.1 ragge rp = &sc->rring[sc->rindex];
564 1.1 ragge /*
565 1.1 ragge * If the host word is 0 then this is a buffer either already seen or not
566 1.1 ragge * presented to the device in the first place.
567 1.1 ragge */
568 1.1 ragge xp = rp->rhost0;
569 1.1 ragge if (xp == 0)
570 1.1 ragge break;
571 1.1 ragge
572 1.1 ragge if ((rp->rmd0 & (RMD0_STP|RMD0_ENP)) != (RMD0_STP|RMD0_ENP))
573 1.1 ragge {
574 1.1 ragge printf("qt%d chained packet\n", unit);
575 1.1 ragge sc->is_if.if_ierrors++;
576 1.1 ragge goto rnext;
577 1.1 ragge }
578 1.1 ragge len = (rp->rmd1 & RMD1_MCNT) - 4; /* -4 for CRC */
579 1.1 ragge sc->is_if.if_ipackets++;
580 1.1 ragge
581 1.1 ragge if ((rp->rmd0 & RMD0_ERR3) || (rp->rmd2 & RMD2_ERR4))
582 1.1 ragge {
583 1.1 ragge sc->is_if.if_ierrors++;
584 1.1 ragge #ifdef QTDEBUG
585 1.1 ragge printf("qt%d rmd0 %b\n", unit, rp->rmd0, RMD0_BITS);
586 1.1 ragge printf("qt%d rmd2 %b\n", unit, rp->rmd2, RMD2_BITS);
587 1.1 ragge #endif
588 1.1 ragge }
589 1.1 ragge else
590 1.1 ragge qtread(sc, &xp->ubabuf,
591 1.1 ragge len - sizeof (struct ether_header));
592 1.1 ragge rnext:
593 1.1 ragge --sc->nrcv;
594 1.1 ragge if (++sc->rindex >= QT_MAX_RCV)
595 1.1 ragge sc->rindex = 0;
596 1.1 ragge /*
597 1.1 ragge * put the buffer back on the free list and clear the first host word
598 1.1 ragge * in the ring descriptor so we don't process this one again.
599 1.1 ragge */
600 1.1 ragge xp->next = sc->freelist;
601 1.1 ragge sc->freelist = xp;
602 1.1 ragge rp->rhost0 = 0;
603 1.1 ragge }
604 1.1 ragge while (sc->nrcv < NRCV)
605 1.1 ragge {
606 1.1 ragge rp = &sc->rring[sc->nxtrcv];
607 1.1 ragge #ifdef QTDEBUG
608 1.1 ragge if ((rp->rmd3 & RMD3_OWN) == 0)
609 1.1 ragge printf("qtrint: !OWN\n");
610 1.1 ragge #endif
611 1.1 ragge xp = sc->freelist;
612 1.1 ragge sc->freelist = xp->next;
613 1.1 ragge bufaddr = xp->ubabuf.ifu_r.ifrw_info;
614 1.1 ragge rp->rmd1 = MAXPACKETSIZE;
615 1.1 ragge rp->rmd4 = loint(bufaddr);
616 1.1 ragge rp->rmd5 = hiint(bufaddr);
617 1.1 ragge rp->rhost0 = xp;
618 1.1 ragge rp->rmd3 = 0; /* clear RMD3_OWN */
619 1.1 ragge ++sc->nrcv;
620 1.1 ragge sc->addr->arqr = ARQR_RRQ; /* tell device it has buffer */
621 1.1 ragge if (++sc->nxtrcv >= QT_MAX_RCV)
622 1.1 ragge sc->nxtrcv = 0;
623 1.1 ragge }
624 1.1 ragge }
625 1.1 ragge
626 1.1 ragge /*
627 1.1 ragge * Place data on the appropriate queue and call the start routine to
628 1.1 ragge * send the data to the device.
629 1.1 ragge */
630 1.1 ragge
631 1.1 ragge qtoutput(ifp, m0, dst)
632 1.1 ragge struct ifnet *ifp;
633 1.1 ragge struct mbuf *m0;
634 1.1 ragge struct sockaddr *dst;
635 1.1 ragge {
636 1.1 ragge int type, s, trail;
637 1.1 ragge u_char edst[6];
638 1.1 ragge struct in_addr idst;
639 1.1 ragge register struct ether_header *eh;
640 1.1 ragge register struct qt_softc *is = &qt_softc[ifp->if_unit];
641 1.1 ragge register struct mbuf *m = m0;
642 1.1 ragge struct mbuf *mcopy = (struct mbuf *)0;
643 1.1 ragge
644 1.1 ragge if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
645 1.1 ragge {
646 1.1 ragge m_freem(m0);
647 1.1 ragge return(ENETDOWN);
648 1.1 ragge }
649 1.1 ragge switch (dst->sa_family)
650 1.1 ragge {
651 1.1 ragge #ifdef INET
652 1.1 ragge case AF_INET:
653 1.1 ragge idst = ((struct sockaddr_in *)dst)->sin_addr;
654 1.1 ragge if (!arpresolve(&is->is_ac, m, &idst, edst,&trail))
655 1.1 ragge return(0); /* wait for arp to finish */
656 1.1 ragge if (!bcmp(edst, etherbroadcastaddr,sizeof (edst)))
657 1.1 ragge mcopy = m_copy(m, 0, (int)M_COPYALL);
658 1.1 ragge type = ETHERTYPE_IP;
659 1.1 ragge break;
660 1.1 ragge #endif
661 1.1 ragge #ifdef NS
662 1.1 ragge case AF_NS:
663 1.1 ragge type = ETHERTYPE_NS;
664 1.1 ragge bcopy(&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
665 1.1 ragge edst, sizeof (edst));
666 1.1 ragge if (!bcmp(edst, &ns_broadcast, sizeof (edst)))
667 1.1 ragge return(looutput(&loif, m, dst));
668 1.1 ragge break;
669 1.1 ragge #endif
670 1.1 ragge case AF_UNSPEC:
671 1.1 ragge eh = (struct ether_header *)dst->sa_data;
672 1.1 ragge bcopy(eh->ether_dhost, (caddr_t)edst, sizeof (edst));
673 1.1 ragge type = eh->ether_type;
674 1.1 ragge break;
675 1.1 ragge default:
676 1.1 ragge printf("qt%d can't handle af%d\n", ifp->if_unit,
677 1.1 ragge dst->sa_family);
678 1.1 ragge m_freem(m);
679 1.1 ragge return(EAFNOSUPPORT);
680 1.1 ragge }
681 1.1 ragge /*
682 1.1 ragge * Add local net header. If no space in first mbuf, allocate another.
683 1.1 ragge */
684 1.1 ragge if (m->m_off > MMAXOFF ||
685 1.1 ragge MMINOFF + sizeof (struct ether_header) > m->m_off)
686 1.1 ragge {
687 1.1 ragge m = m_get(M_DONTWAIT, MT_HEADER);
688 1.1 ragge if (m == 0)
689 1.1 ragge {
690 1.1 ragge m_freem(m0);
691 1.1 ragge nobufs: if (mcopy)
692 1.1 ragge m_freem(mcopy);
693 1.1 ragge return(ENOBUFS);
694 1.1 ragge }
695 1.1 ragge m->m_next = m0;
696 1.1 ragge m->m_off = MMINOFF;
697 1.1 ragge m->m_len = sizeof (struct ether_header);
698 1.1 ragge }
699 1.1 ragge else
700 1.1 ragge {
701 1.1 ragge m->m_off -= sizeof (struct ether_header);
702 1.1 ragge m->m_len += sizeof (struct ether_header);
703 1.1 ragge }
704 1.1 ragge eh = mtod(m, struct ether_header *);
705 1.1 ragge eh->ether_type = htons((u_short)type);
706 1.1 ragge bcopy(edst, (caddr_t)eh->ether_dhost, sizeof (edst));
707 1.1 ragge bcopy(is->is_addr, (caddr_t)eh->ether_shost, sizeof (is->is_addr));
708 1.1 ragge
709 1.1 ragge s = splimp();
710 1.1 ragge if (IF_QFULL(&ifp->if_snd))
711 1.1 ragge {
712 1.1 ragge IF_DROP(&ifp->if_snd);
713 1.1 ragge m_freem(m);
714 1.1 ragge splx(s);
715 1.1 ragge goto nobufs;
716 1.1 ragge }
717 1.1 ragge IF_ENQUEUE(&ifp->if_snd, m);
718 1.1 ragge qtstart(ifp->if_unit);
719 1.1 ragge splx(s);
720 1.1 ragge return(mcopy ? looutput(&loif, mcopy, dst) : 0);
721 1.1 ragge }
722 1.1 ragge
723 1.1 ragge qtioctl(ifp, cmd, data)
724 1.1 ragge register struct ifnet *ifp;
725 1.1 ragge int cmd;
726 1.1 ragge caddr_t data;
727 1.1 ragge {
728 1.1 ragge struct qt_softc *sc = &qt_softc[ifp->if_unit];
729 1.1 ragge struct ifaddr *ifa = (struct ifaddr *)data;
730 1.1 ragge int s = splimp(), error = 0;
731 1.1 ragge #ifdef NS
732 1.1 ragge register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
733 1.1 ragge #endif
734 1.1 ragge
735 1.1 ragge switch (cmd)
736 1.1 ragge {
737 1.1 ragge case SIOCSIFADDR:
738 1.1 ragge /*
739 1.1 ragge * Resetting the board is probably overkill, but then again this is only
740 1.1 ragge * done when the system comes up or possibly when a reset is needed after a
741 1.1 ragge * major network fault (open wire, etc).
742 1.1 ragge */
743 1.1 ragge qtrestart(sc);
744 1.1 ragge switch (ifa->ifa_addr.sa_family)
745 1.1 ragge {
746 1.1 ragge #ifdef INET
747 1.1 ragge case AF_INET:
748 1.1 ragge ((struct arpcom *)ifp)->ac_ipaddr =
749 1.1 ragge IA_SIN(ifa)->sin_addr;
750 1.1 ragge arpwhohas(ifp, &IA_SIN(ifa)->sin_addr);
751 1.1 ragge break;
752 1.1 ragge #endif
753 1.1 ragge #ifdef NS
754 1.1 ragge case AF_NS:
755 1.1 ragge if (ns_nullhost(*ina))
756 1.1 ragge ina->x_host =
757 1.1 ragge *(union ns_host *)(sc->is_addr);
758 1.1 ragge else
759 1.1 ragge {
760 1.1 ragge qt_ns(ina->x_host.c_host);
761 1.1 ragge qtrestart(sc);
762 1.1 ragge }
763 1.1 ragge break;
764 1.1 ragge #endif
765 1.1 ragge }
766 1.1 ragge break;
767 1.1 ragge case SIOCSIFFLAGS:
768 1.1 ragge if ((ifp->if_flags & IFF_UP) == 0 &&
769 1.1 ragge sc->qt_flags & QTF_RUNNING)
770 1.1 ragge {
771 1.1 ragge /*
772 1.1 ragge * We've been asked to stop the board and leave it that way. qtturbo()
773 1.1 ragge * does this with the side effect of placing the device back in Turbo mode.
774 1.1 ragge */
775 1.1 ragge qtturbo(sc);
776 1.1 ragge sc->qt_flags &= ~QTF_RUNNING;
777 1.1 ragge }
778 1.1 ragge else if (ifp->if_flags & IFF_UP &&
779 1.1 ragge !(sc->qt_flags & QTF_RUNNING))
780 1.1 ragge qtrestart(sc);
781 1.1 ragge break;
782 1.1 ragge default:
783 1.1 ragge error = EINVAL;
784 1.1 ragge }
785 1.1 ragge splx(s);
786 1.1 ragge return(error);
787 1.1 ragge }
788 1.1 ragge
789 1.1 ragge #ifdef NS
790 1.1 ragge qt_ns(cp)
791 1.1 ragge register char *cp;
792 1.1 ragge {
793 1.1 ragge segm seg5;
794 1.1 ragge register struct qt_init *iniblk = (struct qt_init *)SEG5;
795 1.1 ragge
796 1.1 ragge saveseg5(seg5);
797 1.1 ragge mapseg5(sc->initclick, 077406);
798 1.1 ragge bcopy(cp, sc->is_addr, 6);
799 1.1 ragge bcopy(cp, iniblk->paddr, 6);
800 1.1 ragge restorseg5(seg5);
801 1.1 ragge }
802 1.1 ragge #endif
803 1.1 ragge
804 1.1 ragge /*
805 1.1 ragge * Pull the data off of the board and pass back to the upper layers of
806 1.1 ragge * the networking code. Trailers are counted as errors and the packet
807 1.1 ragge * dropped. SEG5 is saved and restored (used to peek at the packet type).
808 1.1 ragge */
809 1.1 ragge
810 1.1 ragge qtread(sc, ifuba, len)
811 1.1 ragge register struct qt_softc *sc;
812 1.1 ragge struct ifuba *ifuba;
813 1.1 ragge int len;
814 1.1 ragge {
815 1.1 ragge struct ether_header *eh;
816 1.1 ragge register struct mbuf *m;
817 1.1 ragge struct ifqueue *inq;
818 1.1 ragge int type;
819 1.1 ragge segm seg5;
820 1.1 ragge
821 1.1 ragge saveseg5(seg5);
822 1.1 ragge mapseg5(ifuba->ifu_r.ifrw_click, 077406);
823 1.1 ragge eh = (struct ether_header *)SEG5;
824 1.1 ragge eh->ether_type = ntohs((u_short)eh->ether_type);
825 1.1 ragge type = eh->ether_type;
826 1.1 ragge restorseg5(seg5);
827 1.1 ragge if (len == 0 || type >= ETHERTYPE_TRAIL &&
828 1.1 ragge type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER)
829 1.1 ragge {
830 1.1 ragge sc->is_if.if_ierrors++;
831 1.1 ragge return;
832 1.1 ragge }
833 1.1 ragge
834 1.1 ragge m = if_rubaget(ifuba, len, 0, &sc->is_if);
835 1.1 ragge if (m == 0)
836 1.1 ragge return;
837 1.1 ragge
838 1.1 ragge switch (type)
839 1.1 ragge {
840 1.1 ragge #ifdef INET
841 1.1 ragge case ETHERTYPE_IP:
842 1.1 ragge schednetisr(NETISR_IP);
843 1.1 ragge inq = &ipintrq;
844 1.1 ragge break;
845 1.1 ragge case ETHERTYPE_ARP:
846 1.1 ragge arpinput(&sc->is_ac, m);
847 1.1 ragge return;
848 1.1 ragge #endif
849 1.1 ragge #ifdef NS
850 1.1 ragge case ETHERTYPE_NS:
851 1.1 ragge schednetisr(NETISR_NS);
852 1.1 ragge inq = &nsintrq;
853 1.1 ragge break;
854 1.1 ragge #endif
855 1.1 ragge default:
856 1.1 ragge m_freem(m);
857 1.1 ragge return;
858 1.1 ragge }
859 1.1 ragge
860 1.1 ragge if (IF_QFULL(inq))
861 1.1 ragge {
862 1.1 ragge IF_DROP(inq);
863 1.1 ragge m_freem(m);
864 1.1 ragge return;
865 1.1 ragge }
866 1.1 ragge IF_ENQUEUE(inq, m);
867 1.1 ragge }
868 1.1 ragge
869 1.1 ragge
870 1.1 ragge qtsrr(unit, srrbits)
871 1.1 ragge int unit, srrbits;
872 1.1 ragge {
873 1.1 ragge printf("qt%d srr=%b\n", unit, srrbits, SRR_BITS);
874 1.1 ragge }
875 1.1 ragge
876 1.1 ragge /*
877 1.1 ragge * Reset the device. This moves it from DELQA-T mode to DELQA-Normal mode.
878 1.1 ragge * After the reset put the device back in -T mode. Then call qtinit() to
879 1.1 ragge * reinitialize the ring structures and issue the 'timeout' for the "device
880 1.1 ragge * started interrupt".
881 1.1 ragge */
882 1.1 ragge
883 1.1 ragge qtrestart(sc)
884 1.1 ragge register struct qt_softc *sc;
885 1.1 ragge {
886 1.1 ragge
887 1.1 ragge qtturbo(sc);
888 1.1 ragge qtinit(sc - qt_softc);
889 1.1 ragge }
890 1.1 ragge
891 1.1 ragge qbaini(sc, num)
892 1.1 ragge struct qt_softc *sc;
893 1.1 ragge int num;
894 1.1 ragge {
895 1.1 ragge register int i;
896 1.1 ragge register memaddr click;
897 1.1 ragge struct qt_uba *xp;
898 1.1 ragge register struct ifuba *ifuba;
899 1.1 ragge
900 1.1 ragge for (i = 0; i < num; i++)
901 1.1 ragge {
902 1.1 ragge xp = &sc->ifrw[i];
903 1.1 ragge ifuba = &xp->ubabuf;
904 1.1 ragge click = m_ioget(MAXPACKETSIZE);
905 1.1 ragge if (click == 0)
906 1.1 ragge {
907 1.1 ragge click = MALLOC(coremap, btoc(MAXPACKETSIZE));
908 1.1 ragge if (click == 0)
909 1.1 ragge return(0); /* _can't_ happen */
910 1.1 ragge }
911 1.1 ragge ifuba->ifu_hlen = sizeof (struct ether_header);
912 1.1 ragge ifuba->ifu_w.ifrw_click = ifuba->ifu_r.ifrw_click = click;
913 1.1 ragge ifuba->ifu_w.ifrw_info = ifuba->ifu_r.ifrw_info =
914 1.1 ragge ctob((long)click);
915 1.1 ragge xp->next = sc->freelist;
916 1.1 ragge sc->freelist = xp;
917 1.1 ragge }
918 1.1 ragge return(1);
919 1.1 ragge }
920 1.1 ragge #endif
921