if_le.c revision 1.2 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1982, 1990 The Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd *
33 1.2 cgd * from: @(#)if_le.c 7.6 (Berkeley) 5/8/91
34 1.2 cgd * $Id: if_le.c,v 1.2 1993/05/22 07:56:23 cgd Exp $
35 1.1 cgd */
36 1.1 cgd
37 1.1 cgd #include "le.h"
38 1.1 cgd #if NLE > 0
39 1.1 cgd
40 1.1 cgd #include "bpfilter.h"
41 1.1 cgd
42 1.1 cgd /*
43 1.1 cgd * AMD 7990 LANCE
44 1.1 cgd *
45 1.1 cgd * This driver will generate and accept tailer encapsulated packets even
46 1.1 cgd * though it buys us nothing. The motivation was to avoid incompatibilities
47 1.1 cgd * with VAXen, SUNs, and others that handle and benefit from them.
48 1.1 cgd * This reasoning is dubious.
49 1.1 cgd */
50 1.1 cgd #include "sys/param.h"
51 1.1 cgd #include "sys/systm.h"
52 1.1 cgd #include "sys/mbuf.h"
53 1.1 cgd #include "sys/buf.h"
54 1.1 cgd #include "sys/protosw.h"
55 1.1 cgd #include "sys/socket.h"
56 1.1 cgd #include "sys/syslog.h"
57 1.1 cgd #include "sys/ioctl.h"
58 1.1 cgd #include "sys/errno.h"
59 1.1 cgd
60 1.1 cgd #include "net/if.h"
61 1.1 cgd #include "net/netisr.h"
62 1.1 cgd #include "net/route.h"
63 1.1 cgd
64 1.1 cgd #ifdef INET
65 1.1 cgd #include "netinet/in.h"
66 1.1 cgd #include "netinet/in_systm.h"
67 1.1 cgd #include "netinet/in_var.h"
68 1.1 cgd #include "netinet/ip.h"
69 1.1 cgd #include "netinet/if_ether.h"
70 1.1 cgd #endif
71 1.1 cgd
72 1.1 cgd #ifdef NS
73 1.1 cgd #include "netns/ns.h"
74 1.1 cgd #include "netns/ns_if.h"
75 1.1 cgd #endif
76 1.1 cgd
77 1.1 cgd #ifdef RMP
78 1.1 cgd #include "netrmp/rmp.h"
79 1.1 cgd #include "netrmp/rmp_var.h"
80 1.1 cgd #endif
81 1.1 cgd
82 1.1 cgd #include "../include/cpu.h"
83 1.1 cgd #include "../hp300/isr.h"
84 1.1 cgd #include "../include/mtpr.h"
85 1.1 cgd #include "device.h"
86 1.1 cgd #include "if_lereg.h"
87 1.1 cgd
88 1.1 cgd #if NBPFILTER > 0
89 1.1 cgd #include "../net/bpf.h"
90 1.1 cgd #include "../net/bpfdesc.h"
91 1.1 cgd #endif
92 1.1 cgd
93 1.1 cgd /* offsets for: ID, REGS, MEM, NVRAM */
94 1.1 cgd int lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
95 1.1 cgd
96 1.1 cgd int leattach();
97 1.1 cgd struct driver ledriver = {
98 1.1 cgd leattach, "le",
99 1.1 cgd };
100 1.1 cgd
101 1.1 cgd struct isr le_isr[NLE];
102 1.1 cgd int ledebug = 0; /* console error messages */
103 1.1 cgd
104 1.1 cgd int leintr(), leinit(), leioctl(), lestart(), ether_output();
105 1.1 cgd struct mbuf *leget();
106 1.1 cgd extern struct ifnet loif;
107 1.1 cgd
108 1.1 cgd /*
109 1.1 cgd * Ethernet software status per interface.
110 1.1 cgd *
111 1.1 cgd * Each interface is referenced by a network interface structure,
112 1.1 cgd * le_if, which the routing code uses to locate the interface.
113 1.1 cgd * This structure contains the output queue for the interface, its address, ...
114 1.1 cgd */
115 1.1 cgd struct le_softc {
116 1.1 cgd struct arpcom sc_ac; /* common Ethernet structures */
117 1.1 cgd #define sc_if sc_ac.ac_if /* network-visible interface */
118 1.1 cgd #define sc_addr sc_ac.ac_enaddr /* hardware Ethernet address */
119 1.1 cgd struct lereg0 *sc_r0; /* DIO registers */
120 1.1 cgd struct lereg1 *sc_r1; /* LANCE registers */
121 1.1 cgd struct lereg2 *sc_r2; /* dual-port RAM */
122 1.1 cgd int sc_rmd; /* predicted next rmd to process */
123 1.1 cgd int sc_runt;
124 1.1 cgd int sc_jab;
125 1.1 cgd int sc_merr;
126 1.1 cgd int sc_babl;
127 1.1 cgd int sc_cerr;
128 1.1 cgd int sc_miss;
129 1.1 cgd int sc_xint;
130 1.1 cgd int sc_xown;
131 1.1 cgd int sc_uflo;
132 1.1 cgd int sc_rxlen;
133 1.1 cgd int sc_rxoff;
134 1.1 cgd int sc_txoff;
135 1.1 cgd int sc_busy;
136 1.1 cgd short sc_iflags;
137 1.1 cgd #if NBPFILTER > 0
138 1.1 cgd caddr_t sc_bpf;
139 1.1 cgd #endif
140 1.1 cgd } le_softc[NLE];
141 1.1 cgd
142 1.1 cgd /* access LANCE registers */
143 1.1 cgd #define LERDWR(cntl, src, dst) \
144 1.1 cgd do { \
145 1.1 cgd (dst) = (src); \
146 1.1 cgd } while (((cntl)->ler0_status & LE_ACK) == 0);
147 1.1 cgd
148 1.1 cgd /*
149 1.1 cgd * Interface exists: make available by filling in network interface
150 1.1 cgd * record. System will initialize the interface when it is ready
151 1.1 cgd * to accept packets.
152 1.1 cgd */
153 1.1 cgd leattach(hd)
154 1.1 cgd struct hp_device *hd;
155 1.1 cgd {
156 1.1 cgd register struct lereg0 *ler0;
157 1.1 cgd register struct lereg2 *ler2;
158 1.1 cgd struct lereg2 *lemem = 0;
159 1.1 cgd struct le_softc *le = &le_softc[hd->hp_unit];
160 1.1 cgd struct ifnet *ifp = &le->sc_if;
161 1.1 cgd char *cp;
162 1.1 cgd int i;
163 1.1 cgd
164 1.1 cgd ler0 = le->sc_r0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
165 1.1 cgd le->sc_r1 = (struct lereg1 *)(lestd[1] + (int)hd->hp_addr);
166 1.1 cgd ler2 = le->sc_r2 = (struct lereg2 *)(lestd[2] + (int)hd->hp_addr);
167 1.1 cgd if (ler0->ler0_id != LEID)
168 1.1 cgd return(0);
169 1.1 cgd le_isr[hd->hp_unit].isr_intr = leintr;
170 1.1 cgd hd->hp_ipl = le_isr[hd->hp_unit].isr_ipl = LE_IPL(ler0->ler0_status);
171 1.1 cgd le_isr[hd->hp_unit].isr_arg = hd->hp_unit;
172 1.1 cgd ler0->ler0_id = 0xFF;
173 1.1 cgd DELAY(100);
174 1.1 cgd
175 1.1 cgd /*
176 1.1 cgd * Read the ethernet address off the board, one nibble at a time.
177 1.1 cgd */
178 1.1 cgd cp = (char *)(lestd[3] + (int)hd->hp_addr);
179 1.1 cgd for (i = 0; i < sizeof(le->sc_addr); i++) {
180 1.1 cgd le->sc_addr[i] = (*++cp & 0xF) << 4;
181 1.1 cgd cp++;
182 1.1 cgd le->sc_addr[i] |= *++cp & 0xF;
183 1.1 cgd cp++;
184 1.1 cgd }
185 1.1 cgd printf("le%d: hardware address %s\n", hd->hp_unit,
186 1.1 cgd ether_sprintf(le->sc_addr));
187 1.1 cgd
188 1.1 cgd /*
189 1.1 cgd * Setup for transmit/receive
190 1.1 cgd */
191 1.1 cgd ler2->ler2_mode = LE_MODE;
192 1.1 cgd ler2->ler2_padr[0] = le->sc_addr[1];
193 1.1 cgd ler2->ler2_padr[1] = le->sc_addr[0];
194 1.1 cgd ler2->ler2_padr[2] = le->sc_addr[3];
195 1.1 cgd ler2->ler2_padr[3] = le->sc_addr[2];
196 1.1 cgd ler2->ler2_padr[4] = le->sc_addr[5];
197 1.1 cgd ler2->ler2_padr[5] = le->sc_addr[4];
198 1.1 cgd #ifdef RMP
199 1.1 cgd /*
200 1.1 cgd * Set up logical addr filter to accept multicast 9:0:9:0:0:4
201 1.1 cgd * This should be an ioctl() to the driver. (XXX)
202 1.1 cgd */
203 1.1 cgd ler2->ler2_ladrf0 = 0x00100000;
204 1.1 cgd ler2->ler2_ladrf1 = 0x0;
205 1.1 cgd #else
206 1.1 cgd ler2->ler2_ladrf0 = 0;
207 1.1 cgd ler2->ler2_ladrf1 = 0;
208 1.1 cgd #endif
209 1.1 cgd ler2->ler2_rlen = LE_RLEN;
210 1.1 cgd ler2->ler2_rdra = (int)lemem->ler2_rmd;
211 1.1 cgd ler2->ler2_tlen = LE_TLEN;
212 1.1 cgd ler2->ler2_tdra = (int)lemem->ler2_tmd;
213 1.1 cgd isrlink(&le_isr[hd->hp_unit]);
214 1.1 cgd ler0->ler0_status = LE_IE;
215 1.1 cgd
216 1.1 cgd ifp->if_unit = hd->hp_unit;
217 1.1 cgd ifp->if_name = "le";
218 1.1 cgd ifp->if_mtu = ETHERMTU;
219 1.1 cgd ifp->if_init = leinit;
220 1.1 cgd ifp->if_ioctl = leioctl;
221 1.1 cgd ifp->if_output = ether_output;
222 1.1 cgd ifp->if_start = lestart;
223 1.1 cgd ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
224 1.1 cgd #if NBPFILTER > 0
225 1.1 cgd bpfattach(&le->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
226 1.1 cgd #endif
227 1.1 cgd if_attach(ifp);
228 1.1 cgd return (1);
229 1.1 cgd }
230 1.1 cgd
231 1.1 cgd ledrinit(ler2)
232 1.1 cgd register struct lereg2 *ler2;
233 1.1 cgd {
234 1.1 cgd register struct lereg2 *lemem = 0;
235 1.1 cgd register int i;
236 1.1 cgd
237 1.1 cgd for (i = 0; i < LERBUF; i++) {
238 1.1 cgd ler2->ler2_rmd[i].rmd0 = (int)lemem->ler2_rbuf[i];
239 1.1 cgd ler2->ler2_rmd[i].rmd1 = LE_OWN;
240 1.1 cgd ler2->ler2_rmd[i].rmd2 = -LEMTU;
241 1.1 cgd ler2->ler2_rmd[i].rmd3 = 0;
242 1.1 cgd }
243 1.1 cgd for (i = 0; i < LETBUF; i++) {
244 1.1 cgd ler2->ler2_tmd[i].tmd0 = (int)lemem->ler2_tbuf[i];
245 1.1 cgd ler2->ler2_tmd[i].tmd1 = 0;
246 1.1 cgd ler2->ler2_tmd[i].tmd2 = 0;
247 1.1 cgd ler2->ler2_tmd[i].tmd3 = 0;
248 1.1 cgd }
249 1.1 cgd }
250 1.1 cgd
251 1.1 cgd lereset(unit)
252 1.1 cgd register int unit;
253 1.1 cgd {
254 1.1 cgd register struct le_softc *le = &le_softc[unit];
255 1.1 cgd register struct lereg0 *ler0 = le->sc_r0;
256 1.1 cgd register struct lereg1 *ler1 = le->sc_r1;
257 1.1 cgd register struct lereg2 *lemem = 0;
258 1.1 cgd register int timo = 100000;
259 1.1 cgd register int stat;
260 1.1 cgd
261 1.1 cgd #ifdef lint
262 1.1 cgd stat = unit;
263 1.1 cgd #endif
264 1.1 cgd #if NBPFILTER > 0
265 1.1 cgd if (le->sc_if.if_flags & IFF_PROMISC)
266 1.1 cgd /* set the promiscuous bit */
267 1.1 cgd le->sc_r2->ler2_mode = LE_MODE|0x8000;
268 1.1 cgd else
269 1.1 cgd le->sc_r2->ler2_mode = LE_MODE;
270 1.1 cgd #endif
271 1.1 cgd LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
272 1.1 cgd LERDWR(ler0, LE_STOP, ler1->ler1_rdp);
273 1.1 cgd ledrinit(le->sc_r2);
274 1.1 cgd le->sc_rmd = 0;
275 1.1 cgd LERDWR(ler0, LE_CSR1, ler1->ler1_rap);
276 1.1 cgd LERDWR(ler0, (int)&lemem->ler2_mode, ler1->ler1_rdp);
277 1.1 cgd LERDWR(ler0, LE_CSR2, ler1->ler1_rap);
278 1.1 cgd LERDWR(ler0, 0, ler1->ler1_rdp);
279 1.1 cgd LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
280 1.1 cgd LERDWR(ler0, LE_INIT, ler1->ler1_rdp);
281 1.1 cgd do {
282 1.1 cgd if (--timo == 0) {
283 1.1 cgd printf("le%d: init timeout, stat = 0x%x\n",
284 1.1 cgd unit, stat);
285 1.1 cgd break;
286 1.1 cgd }
287 1.1 cgd LERDWR(ler0, ler1->ler1_rdp, stat);
288 1.1 cgd } while ((stat & LE_IDON) == 0);
289 1.1 cgd LERDWR(ler0, LE_STOP, ler1->ler1_rdp);
290 1.1 cgd LERDWR(ler0, LE_CSR3, ler1->ler1_rap);
291 1.1 cgd LERDWR(ler0, LE_BSWP, ler1->ler1_rdp);
292 1.1 cgd LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
293 1.1 cgd LERDWR(ler0, LE_STRT | LE_INEA, ler1->ler1_rdp);
294 1.1 cgd le->sc_if.if_flags &= ~IFF_OACTIVE;
295 1.1 cgd }
296 1.1 cgd
297 1.1 cgd /*
298 1.1 cgd * Initialization of interface
299 1.1 cgd */
300 1.1 cgd leinit(unit)
301 1.1 cgd int unit;
302 1.1 cgd {
303 1.1 cgd struct le_softc *le = &le_softc[unit];
304 1.1 cgd register struct ifnet *ifp = &le->sc_if;
305 1.1 cgd int s;
306 1.1 cgd
307 1.1 cgd /* not yet, if address still unknown */
308 1.1 cgd if (ifp->if_addrlist == (struct ifaddr *)0)
309 1.1 cgd return;
310 1.1 cgd if ((ifp->if_flags & IFF_RUNNING) == 0) {
311 1.1 cgd s = splimp();
312 1.1 cgd ifp->if_flags |= IFF_RUNNING;
313 1.1 cgd lereset(unit);
314 1.1 cgd (void) lestart(ifp);
315 1.1 cgd splx(s);
316 1.1 cgd }
317 1.1 cgd }
318 1.1 cgd
319 1.1 cgd /*
320 1.1 cgd * Start output on interface. Get another datagram to send
321 1.1 cgd * off of the interface queue, and copy it to the interface
322 1.1 cgd * before starting the output.
323 1.1 cgd */
324 1.1 cgd lestart(ifp)
325 1.1 cgd struct ifnet *ifp;
326 1.1 cgd {
327 1.1 cgd register struct le_softc *le = &le_softc[ifp->if_unit];
328 1.1 cgd register struct letmd *tmd;
329 1.1 cgd register struct mbuf *m;
330 1.1 cgd int len;
331 1.1 cgd
332 1.1 cgd if ((le->sc_if.if_flags & IFF_RUNNING) == 0)
333 1.1 cgd return (0);
334 1.1 cgd IF_DEQUEUE(&le->sc_if.if_snd, m);
335 1.1 cgd if (m == 0)
336 1.1 cgd return (0);
337 1.1 cgd len = leput(le->sc_r2->ler2_tbuf[0], m);
338 1.1 cgd #if NBPFILTER > 0
339 1.1 cgd /*
340 1.1 cgd * If bpf is listening on this interface, let it
341 1.1 cgd * see the packet before we commit it to the wire.
342 1.1 cgd */
343 1.1 cgd if (le->sc_bpf)
344 1.1 cgd bpf_tap(le->sc_bpf, le->sc_r2->ler2_tbuf[0], len);
345 1.1 cgd #endif
346 1.1 cgd tmd = le->sc_r2->ler2_tmd;
347 1.1 cgd tmd->tmd3 = 0;
348 1.1 cgd tmd->tmd2 = -len;
349 1.1 cgd tmd->tmd1 = LE_OWN | LE_STP | LE_ENP;
350 1.1 cgd le->sc_if.if_flags |= IFF_OACTIVE;
351 1.1 cgd return (0);
352 1.1 cgd }
353 1.1 cgd
354 1.1 cgd leintr(unit)
355 1.1 cgd register int unit;
356 1.1 cgd {
357 1.1 cgd register struct le_softc *le = &le_softc[unit];
358 1.1 cgd register struct lereg0 *ler0 = le->sc_r0;
359 1.1 cgd register struct lereg1 *ler1;
360 1.1 cgd register int stat;
361 1.1 cgd
362 1.1 cgd if ((ler0->ler0_status & LE_IR) == 0)
363 1.1 cgd return(0);
364 1.1 cgd if (ler0->ler0_status & LE_JAB) {
365 1.1 cgd le->sc_jab++;
366 1.1 cgd lereset(unit);
367 1.1 cgd return(1);
368 1.1 cgd }
369 1.1 cgd ler1 = le->sc_r1;
370 1.1 cgd LERDWR(ler0, ler1->ler1_rdp, stat);
371 1.1 cgd if (stat & LE_SERR) {
372 1.1 cgd leerror(unit, stat);
373 1.1 cgd if (stat & LE_MERR) {
374 1.1 cgd le->sc_merr++;
375 1.1 cgd lereset(unit);
376 1.1 cgd return(1);
377 1.1 cgd }
378 1.1 cgd if (stat & LE_BABL)
379 1.1 cgd le->sc_babl++;
380 1.1 cgd if (stat & LE_CERR)
381 1.1 cgd le->sc_cerr++;
382 1.1 cgd if (stat & LE_MISS)
383 1.1 cgd le->sc_miss++;
384 1.1 cgd LERDWR(ler0, LE_BABL|LE_CERR|LE_MISS|LE_INEA, ler1->ler1_rdp);
385 1.1 cgd }
386 1.1 cgd if ((stat & LE_RXON) == 0) {
387 1.1 cgd le->sc_rxoff++;
388 1.1 cgd lereset(unit);
389 1.1 cgd return(1);
390 1.1 cgd }
391 1.1 cgd if ((stat & LE_TXON) == 0) {
392 1.1 cgd le->sc_txoff++;
393 1.1 cgd lereset(unit);
394 1.1 cgd return(1);
395 1.1 cgd }
396 1.1 cgd if (stat & LE_RINT) {
397 1.1 cgd /* interrupt is cleared in lerint */
398 1.1 cgd lerint(unit);
399 1.1 cgd }
400 1.1 cgd if (stat & LE_TINT) {
401 1.1 cgd LERDWR(ler0, LE_TINT|LE_INEA, ler1->ler1_rdp);
402 1.1 cgd lexint(unit);
403 1.1 cgd }
404 1.1 cgd return(1);
405 1.1 cgd }
406 1.1 cgd
407 1.1 cgd /*
408 1.1 cgd * Ethernet interface transmitter interrupt.
409 1.1 cgd * Start another output if more data to send.
410 1.1 cgd */
411 1.1 cgd lexint(unit)
412 1.1 cgd register int unit;
413 1.1 cgd {
414 1.1 cgd register struct le_softc *le = &le_softc[unit];
415 1.1 cgd register struct letmd *tmd = le->sc_r2->ler2_tmd;
416 1.1 cgd
417 1.1 cgd if ((le->sc_if.if_flags & IFF_OACTIVE) == 0) {
418 1.1 cgd le->sc_xint++;
419 1.1 cgd return;
420 1.1 cgd }
421 1.1 cgd if (tmd->tmd1 & LE_OWN) {
422 1.1 cgd le->sc_xown++;
423 1.1 cgd return;
424 1.1 cgd }
425 1.1 cgd if (tmd->tmd1 & LE_ERR) {
426 1.1 cgd err:
427 1.1 cgd lexerror(unit);
428 1.1 cgd le->sc_if.if_oerrors++;
429 1.1 cgd if (tmd->tmd3 & (LE_TBUFF|LE_UFLO)) {
430 1.1 cgd le->sc_uflo++;
431 1.1 cgd lereset(unit);
432 1.1 cgd }
433 1.1 cgd else if (tmd->tmd3 & LE_LCOL)
434 1.1 cgd le->sc_if.if_collisions++;
435 1.1 cgd else if (tmd->tmd3 & LE_RTRY)
436 1.1 cgd le->sc_if.if_collisions += 16;
437 1.1 cgd }
438 1.1 cgd else if (tmd->tmd3 & LE_TBUFF)
439 1.1 cgd /* XXX documentation says BUFF not included in ERR */
440 1.1 cgd goto err;
441 1.1 cgd else if (tmd->tmd1 & LE_ONE)
442 1.1 cgd le->sc_if.if_collisions++;
443 1.1 cgd else if (tmd->tmd1 & LE_MORE)
444 1.1 cgd /* what is the real number? */
445 1.1 cgd le->sc_if.if_collisions += 2;
446 1.1 cgd else
447 1.1 cgd le->sc_if.if_opackets++;
448 1.1 cgd le->sc_if.if_flags &= ~IFF_OACTIVE;
449 1.1 cgd (void) lestart(&le->sc_if);
450 1.1 cgd }
451 1.1 cgd
452 1.1 cgd #define LENEXTRMP \
453 1.1 cgd if (++bix == LERBUF) bix = 0, rmd = le->sc_r2->ler2_rmd; else ++rmd
454 1.1 cgd
455 1.1 cgd /*
456 1.1 cgd * Ethernet interface receiver interrupt.
457 1.1 cgd * If input error just drop packet.
458 1.1 cgd * Decapsulate packet based on type and pass to type specific
459 1.1 cgd * higher-level input routine.
460 1.1 cgd */
461 1.1 cgd lerint(unit)
462 1.1 cgd int unit;
463 1.1 cgd {
464 1.1 cgd register struct le_softc *le = &le_softc[unit];
465 1.1 cgd register int bix = le->sc_rmd;
466 1.1 cgd register struct lermd *rmd = &le->sc_r2->ler2_rmd[bix];
467 1.1 cgd
468 1.1 cgd /*
469 1.1 cgd * Out of sync with hardware, should never happen?
470 1.1 cgd */
471 1.1 cgd if (rmd->rmd1 & LE_OWN) {
472 1.1 cgd LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp);
473 1.1 cgd return;
474 1.1 cgd }
475 1.1 cgd
476 1.1 cgd /*
477 1.1 cgd * Process all buffers with valid data
478 1.1 cgd */
479 1.1 cgd while ((rmd->rmd1 & LE_OWN) == 0) {
480 1.1 cgd int len = rmd->rmd3;
481 1.1 cgd
482 1.1 cgd /* Clear interrupt to avoid race condition */
483 1.1 cgd LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp);
484 1.1 cgd
485 1.1 cgd if (rmd->rmd1 & LE_ERR) {
486 1.1 cgd le->sc_rmd = bix;
487 1.1 cgd lererror(unit, "bad packet");
488 1.1 cgd le->sc_if.if_ierrors++;
489 1.1 cgd } else if ((rmd->rmd1 & (LE_STP|LE_ENP)) != (LE_STP|LE_ENP)) {
490 1.1 cgd /*
491 1.1 cgd * Find the end of the packet so we can see how long
492 1.1 cgd * it was. We still throw it away.
493 1.1 cgd */
494 1.1 cgd do {
495 1.1 cgd LERDWR(le->sc_r0, LE_RINT|LE_INEA,
496 1.1 cgd le->sc_r1->ler1_rdp);
497 1.1 cgd rmd->rmd3 = 0;
498 1.1 cgd rmd->rmd1 = LE_OWN;
499 1.1 cgd LENEXTRMP;
500 1.1 cgd } while (!(rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)));
501 1.1 cgd le->sc_rmd = bix;
502 1.1 cgd lererror(unit, "chained buffer");
503 1.1 cgd le->sc_rxlen++;
504 1.1 cgd /*
505 1.1 cgd * If search terminated without successful completion
506 1.1 cgd * we reset the hardware (conservative).
507 1.1 cgd */
508 1.1 cgd if ((rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)) !=
509 1.1 cgd LE_ENP) {
510 1.1 cgd lereset(unit);
511 1.1 cgd return;
512 1.1 cgd }
513 1.1 cgd } else
514 1.1 cgd leread(unit, le->sc_r2->ler2_rbuf[bix], len);
515 1.1 cgd rmd->rmd3 = 0;
516 1.1 cgd rmd->rmd1 = LE_OWN;
517 1.1 cgd LENEXTRMP;
518 1.1 cgd }
519 1.1 cgd le->sc_rmd = bix;
520 1.1 cgd }
521 1.1 cgd
522 1.1 cgd leread(unit, buf, len)
523 1.1 cgd int unit;
524 1.1 cgd char *buf;
525 1.1 cgd int len;
526 1.1 cgd {
527 1.1 cgd register struct le_softc *le = &le_softc[unit];
528 1.1 cgd register struct ether_header *et;
529 1.1 cgd struct mbuf *m;
530 1.1 cgd int off, resid;
531 1.1 cgd
532 1.1 cgd le->sc_if.if_ipackets++;
533 1.1 cgd et = (struct ether_header *)buf;
534 1.1 cgd et->ether_type = ntohs((u_short)et->ether_type);
535 1.1 cgd /* adjust input length to account for header and CRC */
536 1.1 cgd len = len - sizeof(struct ether_header) - 4;
537 1.1 cgd
538 1.1 cgd #ifdef RMP
539 1.1 cgd /* (XXX)
540 1.1 cgd *
541 1.1 cgd * If Ethernet Type field is < MaxPacketSize, we probably have
542 1.1 cgd * a IEEE802 packet here. Make sure that the size is at least
543 1.1 cgd * that of the HP LLC. Also do sanity checks on length of LLC
544 1.1 cgd * (old Ethernet Type field) and packet length.
545 1.1 cgd *
546 1.1 cgd * Provided the above checks succeed, change `len' to reflect
547 1.1 cgd * the length of the LLC (i.e. et->ether_type) and change the
548 1.1 cgd * type field to ETHERTYPE_IEEE so we can switch() on it later.
549 1.1 cgd * Yes, this is a hack and will eventually be done "right".
550 1.1 cgd */
551 1.1 cgd if (et->ether_type <= IEEE802LEN_MAX && len >= sizeof(struct hp_llc) &&
552 1.1 cgd len >= et->ether_type && len >= IEEE802LEN_MIN) {
553 1.1 cgd len = et->ether_type;
554 1.1 cgd et->ether_type = ETHERTYPE_IEEE; /* hack! */
555 1.1 cgd }
556 1.1 cgd #endif
557 1.1 cgd
558 1.1 cgd #define ledataaddr(et, off, type) ((type)(((caddr_t)((et)+1)+(off))))
559 1.1 cgd if (et->ether_type >= ETHERTYPE_TRAIL &&
560 1.1 cgd et->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
561 1.1 cgd off = (et->ether_type - ETHERTYPE_TRAIL) * 512;
562 1.1 cgd if (off >= ETHERMTU)
563 1.1 cgd return; /* sanity */
564 1.1 cgd et->ether_type = ntohs(*ledataaddr(et, off, u_short *));
565 1.1 cgd resid = ntohs(*(ledataaddr(et, off+2, u_short *)));
566 1.1 cgd if (off + resid > len)
567 1.1 cgd return; /* sanity */
568 1.1 cgd len = off + resid;
569 1.1 cgd } else
570 1.1 cgd off = 0;
571 1.1 cgd
572 1.1 cgd if (len <= 0) {
573 1.1 cgd if (ledebug)
574 1.1 cgd log(LOG_WARNING,
575 1.1 cgd "le%d: ierror(runt packet): from %s: len=%d\n",
576 1.1 cgd unit, ether_sprintf(et->ether_shost), len);
577 1.1 cgd le->sc_runt++;
578 1.1 cgd le->sc_if.if_ierrors++;
579 1.1 cgd return;
580 1.1 cgd }
581 1.1 cgd #if NBPFILTER > 0
582 1.1 cgd /*
583 1.1 cgd * Check if there's a bpf filter listening on this interface.
584 1.1 cgd * If so, hand off the raw packet to bpf, which must deal with
585 1.1 cgd * trailers in its own way.
586 1.1 cgd */
587 1.1 cgd if (le->sc_bpf) {
588 1.1 cgd bpf_tap(le->sc_bpf, buf, len + sizeof(struct ether_header));
589 1.1 cgd
590 1.1 cgd /*
591 1.1 cgd * Note that the interface cannot be in promiscuous mode if
592 1.1 cgd * there are no bpf listeners. And if we are in promiscuous
593 1.1 cgd * mode, we have to check if this packet is really ours.
594 1.1 cgd *
595 1.1 cgd * XXX This test does not support multicasts.
596 1.1 cgd */
597 1.1 cgd if ((le->sc_if.if_flags & IFF_PROMISC)
598 1.1 cgd && bcmp(et->ether_dhost, le->sc_addr,
599 1.1 cgd sizeof(et->ether_dhost)) != 0
600 1.1 cgd && bcmp(et->ether_dhost, etherbroadcastaddr,
601 1.1 cgd sizeof(et->ether_dhost)) != 0)
602 1.1 cgd return;
603 1.1 cgd }
604 1.1 cgd #endif
605 1.1 cgd /*
606 1.1 cgd * Pull packet off interface. Off is nonzero if packet
607 1.1 cgd * has trailing header; leget will then force this header
608 1.1 cgd * information to be at the front, but we still have to drop
609 1.1 cgd * the type and length which are at the front of any trailer data.
610 1.1 cgd */
611 1.1 cgd m = leget(buf, len, off, &le->sc_if);
612 1.1 cgd if (m == 0)
613 1.1 cgd return;
614 1.1 cgd #ifdef RMP
615 1.1 cgd /*
616 1.1 cgd * (XXX)
617 1.1 cgd * This needs to be integrated with the ISO stuff in ether_input()
618 1.1 cgd */
619 1.1 cgd if (et->ether_type == ETHERTYPE_IEEE) {
620 1.1 cgd /*
621 1.1 cgd * Snag the Logical Link Control header (IEEE 802.2).
622 1.1 cgd */
623 1.1 cgd struct hp_llc *llc = &(mtod(m, struct rmp_packet *)->hp_llc);
624 1.1 cgd
625 1.1 cgd /*
626 1.1 cgd * If the DSAP (and HP's extended DXSAP) indicate this
627 1.1 cgd * is an RMP packet, hand it to the raw input routine.
628 1.1 cgd */
629 1.1 cgd if (llc->dsap == IEEE_DSAP_HP && llc->dxsap == HPEXT_DXSAP) {
630 1.1 cgd static struct sockproto rmp_sp = {AF_RMP,RMPPROTO_BOOT};
631 1.1 cgd static struct sockaddr rmp_src = {AF_RMP};
632 1.1 cgd static struct sockaddr rmp_dst = {AF_RMP};
633 1.1 cgd
634 1.1 cgd bcopy(et->ether_shost, rmp_src.sa_data,
635 1.1 cgd sizeof(et->ether_shost));
636 1.1 cgd bcopy(et->ether_dhost, rmp_dst.sa_data,
637 1.1 cgd sizeof(et->ether_dhost));
638 1.1 cgd
639 1.1 cgd raw_input(m, &rmp_sp, &rmp_src, &rmp_dst);
640 1.1 cgd return;
641 1.1 cgd }
642 1.1 cgd }
643 1.1 cgd #endif
644 1.1 cgd ether_input(&le->sc_if, et, m);
645 1.1 cgd }
646 1.1 cgd
647 1.1 cgd /*
648 1.1 cgd * Routine to copy from mbuf chain to transmit
649 1.1 cgd * buffer in board local memory.
650 1.1 cgd */
651 1.1 cgd leput(lebuf, m)
652 1.1 cgd register char *lebuf;
653 1.1 cgd register struct mbuf *m;
654 1.1 cgd {
655 1.1 cgd register struct mbuf *mp;
656 1.1 cgd register int len, tlen = 0;
657 1.1 cgd
658 1.1 cgd for (mp = m; mp; mp = mp->m_next) {
659 1.1 cgd len = mp->m_len;
660 1.1 cgd if (len == 0)
661 1.1 cgd continue;
662 1.1 cgd tlen += len;
663 1.1 cgd bcopy(mtod(mp, char *), lebuf, len);
664 1.1 cgd lebuf += len;
665 1.1 cgd }
666 1.1 cgd m_freem(m);
667 1.1 cgd if (tlen < LEMINSIZE) {
668 1.1 cgd bzero(lebuf, LEMINSIZE - tlen);
669 1.1 cgd tlen = LEMINSIZE;
670 1.1 cgd }
671 1.1 cgd return(tlen);
672 1.1 cgd }
673 1.1 cgd
674 1.1 cgd /*
675 1.1 cgd * Routine to copy from board local memory into mbufs.
676 1.1 cgd */
677 1.1 cgd struct mbuf *
678 1.1 cgd leget(lebuf, totlen, off0, ifp)
679 1.1 cgd char *lebuf;
680 1.1 cgd int totlen, off0;
681 1.1 cgd struct ifnet *ifp;
682 1.1 cgd {
683 1.1 cgd register struct mbuf *m;
684 1.1 cgd struct mbuf *top = 0, **mp = ⊤
685 1.1 cgd register int off = off0, len;
686 1.1 cgd register char *cp;
687 1.1 cgd char *epkt;
688 1.1 cgd
689 1.1 cgd lebuf += sizeof (struct ether_header);
690 1.1 cgd cp = lebuf;
691 1.1 cgd epkt = cp + totlen;
692 1.1 cgd if (off) {
693 1.1 cgd cp += off + 2 * sizeof(u_short);
694 1.1 cgd totlen -= 2 * sizeof(u_short);
695 1.1 cgd }
696 1.1 cgd
697 1.1 cgd MGETHDR(m, M_DONTWAIT, MT_DATA);
698 1.1 cgd if (m == 0)
699 1.1 cgd return (0);
700 1.1 cgd m->m_pkthdr.rcvif = ifp;
701 1.1 cgd m->m_pkthdr.len = totlen;
702 1.1 cgd m->m_len = MHLEN;
703 1.1 cgd
704 1.1 cgd while (totlen > 0) {
705 1.1 cgd if (top) {
706 1.1 cgd MGET(m, M_DONTWAIT, MT_DATA);
707 1.1 cgd if (m == 0) {
708 1.1 cgd m_freem(top);
709 1.1 cgd return (0);
710 1.1 cgd }
711 1.1 cgd m->m_len = MLEN;
712 1.1 cgd }
713 1.1 cgd len = min(totlen, epkt - cp);
714 1.1 cgd if (len >= MINCLSIZE) {
715 1.1 cgd MCLGET(m, M_DONTWAIT);
716 1.1 cgd if (m->m_flags & M_EXT)
717 1.1 cgd m->m_len = len = min(len, MCLBYTES);
718 1.1 cgd else
719 1.1 cgd len = m->m_len;
720 1.1 cgd } else {
721 1.1 cgd /*
722 1.1 cgd * Place initial small packet/header at end of mbuf.
723 1.1 cgd */
724 1.1 cgd if (len < m->m_len) {
725 1.1 cgd if (top == 0 && len + max_linkhdr <= m->m_len)
726 1.1 cgd m->m_data += max_linkhdr;
727 1.1 cgd m->m_len = len;
728 1.1 cgd } else
729 1.1 cgd len = m->m_len;
730 1.1 cgd }
731 1.1 cgd bcopy(cp, mtod(m, caddr_t), (unsigned)len);
732 1.1 cgd cp += len;
733 1.1 cgd *mp = m;
734 1.1 cgd mp = &m->m_next;
735 1.1 cgd totlen -= len;
736 1.1 cgd if (cp == epkt)
737 1.1 cgd cp = lebuf;
738 1.1 cgd }
739 1.1 cgd return (top);
740 1.1 cgd }
741 1.1 cgd
742 1.1 cgd /*
743 1.1 cgd * Process an ioctl request.
744 1.1 cgd */
745 1.1 cgd leioctl(ifp, cmd, data)
746 1.1 cgd register struct ifnet *ifp;
747 1.1 cgd int cmd;
748 1.1 cgd caddr_t data;
749 1.1 cgd {
750 1.1 cgd register struct ifaddr *ifa = (struct ifaddr *)data;
751 1.1 cgd struct le_softc *le = &le_softc[ifp->if_unit];
752 1.1 cgd struct lereg1 *ler1 = le->sc_r1;
753 1.1 cgd int s = splimp(), error = 0;
754 1.1 cgd
755 1.1 cgd switch (cmd) {
756 1.1 cgd
757 1.1 cgd case SIOCSIFADDR:
758 1.1 cgd ifp->if_flags |= IFF_UP;
759 1.1 cgd switch (ifa->ifa_addr->sa_family) {
760 1.1 cgd #ifdef INET
761 1.1 cgd case AF_INET:
762 1.1 cgd leinit(ifp->if_unit); /* before arpwhohas */
763 1.1 cgd ((struct arpcom *)ifp)->ac_ipaddr =
764 1.1 cgd IA_SIN(ifa)->sin_addr;
765 1.1 cgd arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
766 1.1 cgd break;
767 1.1 cgd #endif
768 1.1 cgd #ifdef NS
769 1.1 cgd case AF_NS:
770 1.1 cgd {
771 1.1 cgd register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
772 1.1 cgd
773 1.1 cgd if (ns_nullhost(*ina))
774 1.1 cgd ina->x_host = *(union ns_host *)(le->sc_addr);
775 1.1 cgd else {
776 1.1 cgd /*
777 1.1 cgd * The manual says we can't change the address
778 1.1 cgd * while the receiver is armed,
779 1.1 cgd * so reset everything
780 1.1 cgd */
781 1.1 cgd ifp->if_flags &= ~IFF_RUNNING;
782 1.1 cgd bcopy((caddr_t)ina->x_host.c_host,
783 1.1 cgd (caddr_t)le->sc_addr, sizeof(le->sc_addr));
784 1.1 cgd }
785 1.1 cgd leinit(ifp->if_unit); /* does le_setaddr() */
786 1.1 cgd break;
787 1.1 cgd }
788 1.1 cgd #endif
789 1.1 cgd default:
790 1.1 cgd leinit(ifp->if_unit);
791 1.1 cgd break;
792 1.1 cgd }
793 1.1 cgd break;
794 1.1 cgd
795 1.1 cgd case SIOCSIFFLAGS:
796 1.1 cgd if ((ifp->if_flags & IFF_UP) == 0 &&
797 1.1 cgd ifp->if_flags & IFF_RUNNING) {
798 1.1 cgd LERDWR(le->sc_r0, LE_STOP, ler1->ler1_rdp);
799 1.1 cgd ifp->if_flags &= ~IFF_RUNNING;
800 1.1 cgd } else if (ifp->if_flags & IFF_UP &&
801 1.1 cgd (ifp->if_flags & IFF_RUNNING) == 0)
802 1.1 cgd leinit(ifp->if_unit);
803 1.1 cgd /*
804 1.1 cgd * If the state of the promiscuous bit changes, the interface
805 1.1 cgd * must be reset to effect the change.
806 1.1 cgd */
807 1.1 cgd if (((ifp->if_flags ^ le->sc_iflags) & IFF_PROMISC) &&
808 1.1 cgd (ifp->if_flags & IFF_RUNNING)) {
809 1.1 cgd le->sc_iflags = ifp->if_flags;
810 1.1 cgd lereset(ifp->if_unit);
811 1.1 cgd lestart(ifp);
812 1.1 cgd }
813 1.1 cgd break;
814 1.1 cgd
815 1.1 cgd default:
816 1.1 cgd error = EINVAL;
817 1.1 cgd }
818 1.1 cgd splx(s);
819 1.1 cgd return (error);
820 1.1 cgd }
821 1.1 cgd
822 1.1 cgd leerror(unit, stat)
823 1.1 cgd int unit;
824 1.1 cgd int stat;
825 1.1 cgd {
826 1.1 cgd if (!ledebug)
827 1.1 cgd return;
828 1.1 cgd
829 1.1 cgd /*
830 1.1 cgd * Not all transceivers implement heartbeat
831 1.1 cgd * so we only log CERR once.
832 1.1 cgd */
833 1.1 cgd if ((stat & LE_CERR) && le_softc[unit].sc_cerr)
834 1.1 cgd return;
835 1.1 cgd log(LOG_WARNING,
836 1.1 cgd "le%d: error: stat=%b\n", unit,
837 1.1 cgd stat,
838 1.1 cgd "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\12TINT\11IDON\10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT");
839 1.1 cgd }
840 1.1 cgd
841 1.1 cgd lererror(unit, msg)
842 1.1 cgd int unit;
843 1.1 cgd char *msg;
844 1.1 cgd {
845 1.1 cgd register struct le_softc *le = &le_softc[unit];
846 1.1 cgd register struct lermd *rmd;
847 1.1 cgd int len;
848 1.1 cgd
849 1.1 cgd if (!ledebug)
850 1.1 cgd return;
851 1.1 cgd
852 1.1 cgd rmd = &le->sc_r2->ler2_rmd[le->sc_rmd];
853 1.1 cgd len = rmd->rmd3;
854 1.1 cgd log(LOG_WARNING,
855 1.1 cgd "le%d: ierror(%s): from %s: buf=%d, len=%d, rmd1=%b\n",
856 1.1 cgd unit, msg,
857 1.1 cgd len > 11 ? ether_sprintf(&le->sc_r2->ler2_rbuf[le->sc_rmd][6]) : "unknown",
858 1.1 cgd le->sc_rmd, len,
859 1.1 cgd rmd->rmd1,
860 1.1 cgd "\20\20OWN\17ERR\16FRAM\15OFLO\14CRC\13RBUF\12STP\11ENP");
861 1.1 cgd }
862 1.1 cgd
863 1.1 cgd lexerror(unit)
864 1.1 cgd int unit;
865 1.1 cgd {
866 1.1 cgd register struct le_softc *le = &le_softc[unit];
867 1.1 cgd register struct letmd *tmd;
868 1.1 cgd int len;
869 1.1 cgd
870 1.1 cgd if (!ledebug)
871 1.1 cgd return;
872 1.1 cgd
873 1.1 cgd tmd = le->sc_r2->ler2_tmd;
874 1.1 cgd len = -tmd->tmd2;
875 1.1 cgd log(LOG_WARNING,
876 1.1 cgd "le%d: oerror: to %s: buf=%d, len=%d, tmd1=%b, tmd3=%b\n",
877 1.1 cgd unit,
878 1.1 cgd len > 5 ? ether_sprintf(&le->sc_r2->ler2_tbuf[0][0]) : "unknown",
879 1.1 cgd 0, len,
880 1.1 cgd tmd->tmd1,
881 1.1 cgd "\20\20OWN\17ERR\16RES\15MORE\14ONE\13DEF\12STP\11ENP",
882 1.1 cgd tmd->tmd3,
883 1.1 cgd "\20\20BUFF\17UFLO\16RES\15LCOL\14LCAR\13RTRY");
884 1.1 cgd }
885 1.1 cgd #endif
886