if_le.c revision 1.1 1 1.1 chuck /* $NetBSD: if_le.c,v 1.1 1996/05/17 21:18:34 chuck Exp $ */
2 1.1 chuck
3 1.1 chuck /*
4 1.1 chuck * Copyright (c) 1995 Theo de Raadt
5 1.1 chuck *
6 1.1 chuck * Redistribution and use in source and binary forms, with or without
7 1.1 chuck * modification, are permitted provided that the following conditions
8 1.1 chuck * are met:
9 1.1 chuck * 1. Redistributions of source code must retain the above copyright
10 1.1 chuck * notice, this list of conditions and the following disclaimer.
11 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 chuck * notice, this list of conditions and the following disclaimer in the
13 1.1 chuck * documentation and/or other materials provided with the distribution.
14 1.1 chuck * 3. All advertising materials mentioning features or use of this software
15 1.1 chuck * must display the following acknowledgement:
16 1.1 chuck * This product includes software developed under OpenBSD by
17 1.1 chuck * Theo de Raadt for Willowglen Singapore.
18 1.1 chuck * 4. The name of the author may not be used to endorse or promote products
19 1.1 chuck * derived from this software without specific prior written permission.
20 1.1 chuck *
21 1.1 chuck * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 1.1 chuck * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 1.1 chuck * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 chuck * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 1.1 chuck * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 chuck * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 chuck * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 chuck * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 chuck * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 chuck * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 chuck * SUCH DAMAGE.
32 1.1 chuck *
33 1.1 chuck * Copyright (c) 1993 Adam Glass
34 1.1 chuck * All rights reserved.
35 1.1 chuck *
36 1.1 chuck * Redistribution and use in source and binary forms, with or without
37 1.1 chuck * modification, are permitted provided that the following conditions
38 1.1 chuck * are met:
39 1.1 chuck * 1. Redistributions of source code must retain the above copyright
40 1.1 chuck * notice, this list of conditions and the following disclaimer.
41 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 chuck * notice, this list of conditions and the following disclaimer in the
43 1.1 chuck * documentation and/or other materials provided with the distribution.
44 1.1 chuck * 3. All advertising materials mentioning features or use of this software
45 1.1 chuck * must display the following acknowledgement:
46 1.1 chuck * This product includes software developed by Adam Glass.
47 1.1 chuck * 4. The name of the Author may not be used to endorse or promote products
48 1.1 chuck * derived from this software without specific prior written permission.
49 1.1 chuck *
50 1.1 chuck * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
51 1.1 chuck * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 1.1 chuck * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 1.1 chuck * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 1.1 chuck * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 1.1 chuck * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 1.1 chuck * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 1.1 chuck * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 1.1 chuck * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 1.1 chuck * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 1.1 chuck * SUCH DAMAGE.
61 1.1 chuck */
62 1.1 chuck
63 1.1 chuck #include <sys/param.h>
64 1.1 chuck #include <sys/types.h>
65 1.1 chuck
66 1.1 chuck #include <netinet/in.h>
67 1.1 chuck #include <netinet/in_systm.h>
68 1.1 chuck
69 1.1 chuck #include <machine/prom.h>
70 1.1 chuck
71 1.1 chuck #include "stand.h"
72 1.1 chuck #include "libsa.h"
73 1.1 chuck #include "netif.h"
74 1.1 chuck #include "config.h"
75 1.1 chuck
76 1.1 chuck #include "if_lereg.h"
77 1.1 chuck
78 1.1 chuck int le_debug = 0;
79 1.1 chuck
80 1.1 chuck void le_end __P((struct netif *));
81 1.1 chuck void le_error __P((struct netif *, char *, volatile struct lereg1 *));
82 1.1 chuck int le_get __P((struct iodesc *, void *, size_t, time_t));
83 1.1 chuck void le_init __P((struct iodesc *, void *));
84 1.1 chuck int le_match __P((struct netif *, void *));
85 1.1 chuck int le_poll __P((struct iodesc *, void *, int));
86 1.1 chuck int le_probe __P((struct netif *, void *));
87 1.1 chuck int le_put __P((struct iodesc *, void *, size_t));
88 1.1 chuck void le_reset __P((struct netif *, u_char *));
89 1.1 chuck
90 1.1 chuck struct netif_stats le_stats;
91 1.1 chuck
92 1.1 chuck struct netif_dif le0_dif = {
93 1.1 chuck 0, /* unit */
94 1.1 chuck 1, /* nsel */
95 1.1 chuck &le_stats,
96 1.1 chuck 0,
97 1.1 chuck 0,
98 1.1 chuck };
99 1.1 chuck
100 1.1 chuck struct netif_driver le_driver = {
101 1.1 chuck "le", /* netif_bname */
102 1.1 chuck le_match, /* match */
103 1.1 chuck le_probe, /* probe */
104 1.1 chuck le_init, /* init */
105 1.1 chuck le_get, /* get */
106 1.1 chuck le_put, /* put */
107 1.1 chuck le_end, /* end */
108 1.1 chuck &le0_dif, /* netif_ifs */
109 1.1 chuck 1, /* netif_nifs */
110 1.1 chuck };
111 1.1 chuck
112 1.1 chuck struct le_configuration {
113 1.1 chuck unsigned int phys_addr;
114 1.1 chuck int used;
115 1.1 chuck } le_config[] = {
116 1.1 chuck { LANCE_REG_ADDR, 0 }
117 1.1 chuck };
118 1.1 chuck
119 1.1 chuck int nle_config = sizeof(le_config) / (sizeof(le_config[0]));
120 1.1 chuck
121 1.1 chuck struct {
122 1.1 chuck struct lereg1 *sc_r1; /* LANCE registers */
123 1.1 chuck struct lereg2 *sc_r2; /* RAM */
124 1.1 chuck int next_rmd;
125 1.1 chuck int next_tmd;
126 1.1 chuck } le_softc;
127 1.1 chuck
128 1.1 chuck int
129 1.1 chuck le_match(nif, machdep_hint)
130 1.1 chuck struct netif *nif;
131 1.1 chuck void *machdep_hint;
132 1.1 chuck {
133 1.1 chuck char *name;
134 1.1 chuck int i, val = 0;
135 1.1 chuck
136 1.1 chuck if (bugargs.cputyp != CPU_147)
137 1.1 chuck return (0);
138 1.1 chuck name = machdep_hint;
139 1.1 chuck if (name && !bcmp(le_driver.netif_bname, name, 2))
140 1.1 chuck val += 10;
141 1.1 chuck for (i = 0; i < nle_config; i++) {
142 1.1 chuck if (le_config[i].used)
143 1.1 chuck continue;
144 1.1 chuck if (le_debug)
145 1.1 chuck printf("le%d: le_match --> %d\n", i, val + 1);
146 1.1 chuck le_config[i].used++;
147 1.1 chuck return val + 1;
148 1.1 chuck }
149 1.1 chuck if (le_debug)
150 1.1 chuck printf("le%d: le_match --> 0\n", i);
151 1.1 chuck return 0;
152 1.1 chuck }
153 1.1 chuck
154 1.1 chuck int
155 1.1 chuck le_probe(nif, machdep_hint)
156 1.1 chuck struct netif *nif;
157 1.1 chuck void *machdep_hint;
158 1.1 chuck {
159 1.1 chuck
160 1.1 chuck /* the set unit is the current unit */
161 1.1 chuck if (le_debug)
162 1.1 chuck printf("le%d: le_probe called\n", nif->nif_unit);
163 1.1 chuck
164 1.1 chuck if (bugargs.cputyp == CPU_147)
165 1.1 chuck return 0;
166 1.1 chuck return 1;
167 1.1 chuck }
168 1.1 chuck
169 1.1 chuck void
170 1.1 chuck le_error(nif, str, ler1)
171 1.1 chuck struct netif *nif;
172 1.1 chuck char *str;
173 1.1 chuck volatile struct lereg1 *ler1;
174 1.1 chuck {
175 1.1 chuck /* ler1->ler1_rap = LE_CSRO done in caller */
176 1.1 chuck if (ler1->ler1_rdp & LE_C0_BABL)
177 1.1 chuck panic("le%d: been babbling, found by '%s'\n", nif->nif_unit, str);
178 1.1 chuck if (ler1->ler1_rdp & LE_C0_CERR) {
179 1.1 chuck le_stats.collision_error++;
180 1.1 chuck ler1->ler1_rdp = LE_C0_CERR;
181 1.1 chuck }
182 1.1 chuck if (ler1->ler1_rdp & LE_C0_MISS) {
183 1.1 chuck le_stats.missed++;
184 1.1 chuck ler1->ler1_rdp = LE_C0_MISS;
185 1.1 chuck }
186 1.1 chuck if (ler1->ler1_rdp & LE_C0_MERR) {
187 1.1 chuck printf("le%d: memory error in '%s'\n", nif->nif_unit, str);
188 1.1 chuck panic("memory error");
189 1.1 chuck }
190 1.1 chuck }
191 1.1 chuck
192 1.1 chuck void
193 1.1 chuck le_reset(nif, myea)
194 1.1 chuck struct netif *nif;
195 1.1 chuck u_char *myea;
196 1.1 chuck {
197 1.1 chuck struct lereg1 *ler1 = le_softc.sc_r1;
198 1.1 chuck struct lereg2 *ler2 = le_softc.sc_r2;
199 1.1 chuck unsigned int a;
200 1.1 chuck int timo = 100000, stat, i;
201 1.1 chuck
202 1.1 chuck if (le_debug)
203 1.1 chuck printf("le%d: le_reset called\n", nif->nif_unit);
204 1.1 chuck ler1->ler1_rap = LE_CSR0;
205 1.1 chuck ler1->ler1_rdp = LE_C0_STOP; /* do nothing until we are finished */
206 1.1 chuck
207 1.1 chuck bzero(ler2, sizeof(*ler2));
208 1.1 chuck
209 1.1 chuck ler2->ler2_mode = LE_MODE_NORMAL;
210 1.1 chuck ler2->ler2_padr[0] = myea[1];
211 1.1 chuck ler2->ler2_padr[1] = myea[0];
212 1.1 chuck ler2->ler2_padr[2] = myea[3];
213 1.1 chuck ler2->ler2_padr[3] = myea[2];
214 1.1 chuck ler2->ler2_padr[4] = myea[5];
215 1.1 chuck ler2->ler2_padr[5] = myea[4];
216 1.1 chuck
217 1.1 chuck
218 1.1 chuck ler2->ler2_ladrf0 = 0;
219 1.1 chuck ler2->ler2_ladrf1 = 0;
220 1.1 chuck
221 1.1 chuck a = (u_int) ler2->ler2_rmd;
222 1.1 chuck ler2->ler2_rlen = LE_RLEN | (a >> 16);
223 1.1 chuck ler2->ler2_rdra = a & LE_ADDR_LOW_MASK;
224 1.1 chuck
225 1.1 chuck a = (u_int) ler2->ler2_tmd;
226 1.1 chuck ler2->ler2_tlen = LE_TLEN | (a >> 16);
227 1.1 chuck ler2->ler2_tdra = a & LE_ADDR_LOW_MASK;
228 1.1 chuck
229 1.1 chuck ler1->ler1_rap = LE_CSR1;
230 1.1 chuck a = (u_int) ler2;
231 1.1 chuck ler1->ler1_rdp = a & LE_ADDR_LOW_MASK;
232 1.1 chuck ler1->ler1_rap = LE_CSR2;
233 1.1 chuck ler1->ler1_rdp = a >> 16;
234 1.1 chuck
235 1.1 chuck for (i = 0; i < LERBUF; i++) {
236 1.1 chuck a = (u_int) & ler2->ler2_rbuf[i];
237 1.1 chuck ler2->ler2_rmd[i].rmd0 = a & LE_ADDR_LOW_MASK;
238 1.1 chuck ler2->ler2_rmd[i].rmd1_bits = LE_R1_OWN;
239 1.1 chuck ler2->ler2_rmd[i].rmd1_hadr = a >> 16;
240 1.1 chuck ler2->ler2_rmd[i].rmd2 = -LEMTU;
241 1.1 chuck ler2->ler2_rmd[i].rmd3 = 0;
242 1.1 chuck }
243 1.1 chuck for (i = 0; i < LETBUF; i++) {
244 1.1 chuck a = (u_int) & ler2->ler2_tbuf[i];
245 1.1 chuck ler2->ler2_tmd[i].tmd0 = a & LE_ADDR_LOW_MASK;
246 1.1 chuck ler2->ler2_tmd[i].tmd1_bits = 0;
247 1.1 chuck ler2->ler2_tmd[i].tmd1_hadr = a >> 16;
248 1.1 chuck ler2->ler2_tmd[i].tmd2 = 0;
249 1.1 chuck ler2->ler2_tmd[i].tmd3 = 0;
250 1.1 chuck }
251 1.1 chuck
252 1.1 chuck ler1->ler1_rap = LE_CSR3;
253 1.1 chuck ler1->ler1_rdp = LE_C3_BSWP;
254 1.1 chuck
255 1.1 chuck ler1->ler1_rap = LE_CSR0;
256 1.1 chuck ler1->ler1_rdp = LE_C0_INIT;
257 1.1 chuck do {
258 1.1 chuck if (--timo == 0) {
259 1.1 chuck printf("le%d: init timeout, stat = 0x%x\n",
260 1.1 chuck nif->nif_unit, stat);
261 1.1 chuck break;
262 1.1 chuck }
263 1.1 chuck stat = ler1->ler1_rdp;
264 1.1 chuck } while ((stat & LE_C0_IDON) == 0);
265 1.1 chuck
266 1.1 chuck ler1->ler1_rdp = LE_C0_IDON;
267 1.1 chuck le_softc.next_rmd = 0;
268 1.1 chuck le_softc.next_tmd = 0;
269 1.1 chuck ler1->ler1_rap = LE_CSR0;
270 1.1 chuck ler1->ler1_rdp = LE_C0_STRT;
271 1.1 chuck }
272 1.1 chuck
273 1.1 chuck int
274 1.1 chuck le_poll(desc, pkt, len)
275 1.1 chuck struct iodesc *desc;
276 1.1 chuck void *pkt;
277 1.1 chuck int len;
278 1.1 chuck {
279 1.1 chuck struct lereg1 *ler1 = le_softc.sc_r1;
280 1.1 chuck struct lereg2 *ler2 = le_softc.sc_r2;
281 1.1 chuck unsigned int a;
282 1.1 chuck int length;
283 1.1 chuck struct lermd *rmd;
284 1.1 chuck
285 1.1 chuck
286 1.1 chuck ler1->ler1_rap = LE_CSR0;
287 1.1 chuck if ((ler1->ler1_rdp & LE_C0_RINT) != 0)
288 1.1 chuck ler1->ler1_rdp = LE_C0_RINT;
289 1.1 chuck rmd = &ler2->ler2_rmd[le_softc.next_rmd];
290 1.1 chuck if (rmd->rmd1_bits & LE_R1_OWN) {
291 1.1 chuck return (0);
292 1.1 chuck }
293 1.1 chuck if (ler1->ler1_rdp & LE_C0_ERR)
294 1.1 chuck le_error(desc->io_netif, "le_poll", ler1);
295 1.1 chuck if (rmd->rmd1_bits & LE_R1_ERR) {
296 1.1 chuck printf("le%d_poll: rmd status 0x%x\n", desc->io_netif->nif_unit,
297 1.1 chuck rmd->rmd1_bits);
298 1.1 chuck length = 0;
299 1.1 chuck goto cleanup;
300 1.1 chuck }
301 1.1 chuck if ((rmd->rmd1_bits & (LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP))
302 1.1 chuck panic("le_poll: chained packet\n");
303 1.1 chuck
304 1.1 chuck length = rmd->rmd3;
305 1.1 chuck if (length >= LEMTU) {
306 1.1 chuck length = 0;
307 1.1 chuck panic("csr0 when bad things happen: %x\n", ler1->ler1_rdp);
308 1.1 chuck goto cleanup;
309 1.1 chuck }
310 1.1 chuck if (!length)
311 1.1 chuck goto cleanup;
312 1.1 chuck length -= 4;
313 1.1 chuck if (length > 0) {
314 1.1 chuck
315 1.1 chuck /*
316 1.1 chuck * if buffer is smaller than the packet truncate it.
317 1.1 chuck * (is this wise?)
318 1.1 chuck */
319 1.1 chuck if (length > len)
320 1.1 chuck length = len;
321 1.1 chuck
322 1.1 chuck bcopy((void *)&ler2->ler2_rbuf[le_softc.next_rmd], pkt, length);
323 1.1 chuck }
324 1.1 chuck cleanup:
325 1.1 chuck a = (u_int) & ler2->ler2_rbuf[le_softc.next_rmd];
326 1.1 chuck rmd->rmd0 = a & LE_ADDR_LOW_MASK;
327 1.1 chuck rmd->rmd1_hadr = a >> 16;
328 1.1 chuck rmd->rmd2 = -LEMTU;
329 1.1 chuck le_softc.next_rmd =
330 1.1 chuck (le_softc.next_rmd == (LERBUF - 1)) ? 0 : (le_softc.next_rmd + 1);
331 1.1 chuck rmd->rmd1_bits = LE_R1_OWN;
332 1.1 chuck return length;
333 1.1 chuck }
334 1.1 chuck
335 1.1 chuck int
336 1.1 chuck le_put(desc, pkt, len)
337 1.1 chuck struct iodesc *desc;
338 1.1 chuck void *pkt;
339 1.1 chuck size_t len;
340 1.1 chuck {
341 1.1 chuck volatile struct lereg1 *ler1 = le_softc.sc_r1;
342 1.1 chuck volatile struct lereg2 *ler2 = le_softc.sc_r2;
343 1.1 chuck volatile struct letmd *tmd;
344 1.1 chuck int timo = 100000, stat, i;
345 1.1 chuck unsigned int a;
346 1.1 chuck
347 1.1 chuck ler1->ler1_rap = LE_CSR0;
348 1.1 chuck if (ler1->ler1_rdp & LE_C0_ERR)
349 1.1 chuck le_error(desc->io_netif, "le_put(way before xmit)", ler1);
350 1.1 chuck tmd = &ler2->ler2_tmd[le_softc.next_tmd];
351 1.1 chuck while (tmd->tmd1_bits & LE_T1_OWN) {
352 1.1 chuck printf("le%d: output buffer busy\n", desc->io_netif->nif_unit);
353 1.1 chuck }
354 1.1 chuck bcopy(pkt, (void *)ler2->ler2_tbuf[le_softc.next_tmd], len);
355 1.1 chuck if (len < 64)
356 1.1 chuck tmd->tmd2 = -64;
357 1.1 chuck else
358 1.1 chuck tmd->tmd2 = -len;
359 1.1 chuck tmd->tmd3 = 0;
360 1.1 chuck if (ler1->ler1_rdp & LE_C0_ERR)
361 1.1 chuck le_error(desc->io_netif, "le_put(before xmit)", ler1);
362 1.1 chuck tmd->tmd1_bits = LE_T1_STP | LE_T1_ENP | LE_T1_OWN;
363 1.1 chuck a = (u_int) & ler2->ler2_tbuf[le_softc.next_tmd];
364 1.1 chuck tmd->tmd0 = a & LE_ADDR_LOW_MASK;
365 1.1 chuck tmd->tmd1_hadr = a >> 16;
366 1.1 chuck ler1->ler1_rdp = LE_C0_TDMD;
367 1.1 chuck if (ler1->ler1_rdp & LE_C0_ERR)
368 1.1 chuck le_error(desc->io_netif, "le_put(after xmit)", ler1);
369 1.1 chuck do {
370 1.1 chuck if (--timo == 0) {
371 1.1 chuck printf("le%d: transmit timeout, stat = 0x%x\n",
372 1.1 chuck desc->io_netif->nif_unit, stat);
373 1.1 chuck if (ler1->ler1_rdp & LE_C0_ERR)
374 1.1 chuck le_error(desc->io_netif, "le_put(timeout)", ler1);
375 1.1 chuck break;
376 1.1 chuck }
377 1.1 chuck stat = ler1->ler1_rdp;
378 1.1 chuck } while ((stat & LE_C0_TINT) == 0);
379 1.1 chuck ler1->ler1_rdp = LE_C0_TINT;
380 1.1 chuck if (ler1->ler1_rdp & LE_C0_ERR) {
381 1.1 chuck if ((ler1->ler1_rdp & (LE_C0_BABL | LE_C0_CERR | LE_C0_MISS |
382 1.1 chuck LE_C0_MERR)) !=
383 1.1 chuck LE_C0_CERR)
384 1.1 chuck printf("le_put: xmit error, buf %d\n", le_softc.next_tmd);
385 1.1 chuck le_error(desc->io_netif, "le_put(xmit error)", ler1);
386 1.1 chuck }
387 1.1 chuck le_softc.next_tmd = 0;
388 1.1 chuck /* (le_softc.next_tmd == (LETBUF - 1)) ? 0 : le_softc.next_tmd + 1;*/
389 1.1 chuck if (tmd->tmd1_bits & LE_T1_DEF)
390 1.1 chuck le_stats.deferred++;
391 1.1 chuck if (tmd->tmd1_bits & LE_T1_ONE)
392 1.1 chuck le_stats.collisions++;
393 1.1 chuck if (tmd->tmd1_bits & LE_T1_MORE)
394 1.1 chuck le_stats.collisions += 2;
395 1.1 chuck if (tmd->tmd1_bits & LE_T1_ERR) {
396 1.1 chuck printf("le%d: transmit error, error = 0x%x\n", desc->io_netif->nif_unit,
397 1.1 chuck tmd->tmd3);
398 1.1 chuck return -1;
399 1.1 chuck }
400 1.1 chuck if (le_debug) {
401 1.1 chuck printf("le%d: le_put() successful: sent %d\n",
402 1.1 chuck desc->io_netif->nif_unit, len);
403 1.1 chuck printf("le%d: le_put(): tmd1_bits: %x tmd3: %x\n",
404 1.1 chuck desc->io_netif->nif_unit,
405 1.1 chuck (unsigned int) tmd->tmd1_bits,
406 1.1 chuck (unsigned int) tmd->tmd3);
407 1.1 chuck }
408 1.1 chuck return len;
409 1.1 chuck }
410 1.1 chuck
411 1.1 chuck int
412 1.1 chuck le_get(desc, pkt, len, timeout)
413 1.1 chuck struct iodesc *desc;
414 1.1 chuck void *pkt;
415 1.1 chuck size_t len;
416 1.1 chuck time_t timeout;
417 1.1 chuck {
418 1.1 chuck time_t t;
419 1.1 chuck int cc;
420 1.1 chuck
421 1.1 chuck t = getsecs();
422 1.1 chuck cc = 0;
423 1.1 chuck while (((getsecs() - t) < timeout) && !cc) {
424 1.1 chuck cc = le_poll(desc, pkt, len);
425 1.1 chuck }
426 1.1 chuck return cc;
427 1.1 chuck }
428 1.1 chuck /*
429 1.1 chuck * init le device. return 0 on failure, 1 if ok.
430 1.1 chuck */
431 1.1 chuck void
432 1.1 chuck le_init(desc, machdep_hint)
433 1.1 chuck struct iodesc *desc;
434 1.1 chuck void *machdep_hint;
435 1.1 chuck {
436 1.1 chuck u_long eram = 4*1024*1024;
437 1.1 chuck struct netif *nif = desc->io_netif;
438 1.1 chuck
439 1.1 chuck if (le_debug)
440 1.1 chuck printf("le%d: le_init called\n", desc->io_netif->nif_unit);
441 1.1 chuck machdep_common_ether(desc->myea);
442 1.1 chuck bzero(&le_softc, sizeof(le_softc));
443 1.1 chuck le_softc.sc_r1 =
444 1.1 chuck (struct lereg1 *) le_config[desc->io_netif->nif_unit].phys_addr;
445 1.1 chuck le_softc.sc_r2 = (struct lereg2 *) (eram - (1024 * 1024));
446 1.1 chuck le_reset(desc->io_netif, desc->myea);
447 1.1 chuck printf("device: %s%d attached to %s\n", nif->nif_driver->netif_bname,
448 1.1 chuck nif->nif_unit, ether_sprintf(desc->myea));
449 1.1 chuck }
450 1.1 chuck
451 1.1 chuck void
452 1.1 chuck le_end(nif)
453 1.1 chuck struct netif *nif;
454 1.1 chuck {
455 1.1 chuck struct lereg1 *ler1 = le_softc.sc_r1;
456 1.1 chuck
457 1.1 chuck if (le_debug)
458 1.1 chuck printf("le%d: le_end called\n", nif->nif_unit);
459 1.1 chuck ler1->ler1_rap = LE_CSR0;
460 1.1 chuck ler1->ler1_rdp = LE_C0_STOP;
461 1.1 chuck }
462