if_iy.c revision 1.17 1 /* $NetBSD: if_iy.c,v 1.17 1997/11/30 15:31:26 drochner Exp $ */
2 /* #define IYDEBUG */
3 /* #define IYMEMDEBUG */
4 /*-
5 * Copyright (c) 1996 Ignatios Souvatzis.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product contains software developed by Ignatios Souvatzis for
19 * the NetBSD project.
20 * 4. The names of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include "bpfilter.h"
37 #include "rnd.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/mbuf.h>
42 #include <sys/buf.h>
43 #include <sys/protosw.h>
44 #include <sys/socket.h>
45 #include <sys/ioctl.h>
46 #include <sys/errno.h>
47 #include <sys/syslog.h>
48 #include <sys/device.h>
49 #if NRND > 0
50 #include <sys/rnd.h>
51 #endif
52
53 #include <net/if.h>
54 #include <net/if_types.h>
55 #include <net/if_dl.h>
56
57 #include <net/if_ether.h>
58
59 #if NBPFILTER > 0
60 #include <net/bpf.h>
61 #include <net/bpfdesc.h>
62 #endif
63
64 #ifdef INET
65 #include <netinet/in.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/in_var.h>
68 #include <netinet/ip.h>
69 #include <netinet/if_inarp.h>
70 #endif
71
72 #ifdef NS
73 #include <netns/ns.h>
74 #include <netns/ns_if.h>
75 #endif
76
77 #include <vm/vm.h>
78
79 #include <machine/cpu.h>
80 #include <machine/bus.h>
81 #include <machine/intr.h>
82
83 #include <dev/isa/isareg.h>
84 #include <dev/isa/isavar.h>
85 #include <dev/ic/i82595reg.h>
86
87 #define ETHER_MIN_LEN (ETHERMIN + sizeof(struct ether_header) + 4)
88 #define ETHER_MAX_LEN (ETHERMTU + sizeof(struct ether_header) + 4)
89
90 /*
91 * Ethernet status, per interface.
92 */
93 struct iy_softc {
94 struct device sc_dev;
95 void *sc_ih;
96
97 bus_space_tag_t sc_iot;
98 bus_space_handle_t sc_ioh;
99
100 struct ethercom sc_ethercom;
101
102 int mappedirq;
103
104 int hard_vers;
105
106 int promisc;
107
108 int sram, tx_size, rx_size;
109
110 int tx_start, tx_end, tx_last;
111 int rx_start;
112
113 #ifdef IYDEBUG
114 int sc_debug;
115 #endif
116
117 #if NRND > 0
118 rndsource_element_t rnd_source;
119 #endif
120 };
121
122 void iywatchdog __P((struct ifnet *));
123 int iyioctl __P((struct ifnet *, u_long, caddr_t));
124 int iyintr __P((void *));
125 void iyinit __P((struct iy_softc *));
126 void iystop __P((struct iy_softc *));
127 void iystart __P((struct ifnet *));
128
129 void iy_intr_rx __P((struct iy_softc *));
130 void iy_intr_tx __P((struct iy_softc *));
131
132 void iyreset __P((struct iy_softc *));
133 void iy_readframe __P((struct iy_softc *, int));
134 void iy_drop_packet_buffer __P((struct iy_softc *));
135 void iy_find_mem_size __P((struct iy_softc *));
136 void iyrint __P((struct iy_softc *));
137 void iytint __P((struct iy_softc *));
138 void iyxmit __P((struct iy_softc *));
139 void iyget __P((struct iy_softc *, bus_space_tag_t, bus_space_handle_t, int));
140 void iyprobemem __P((struct iy_softc *));
141 static __inline void eepromwritebit __P((bus_space_tag_t, bus_space_handle_t,
142 int));
143 static __inline int eepromreadbit __P((bus_space_tag_t, bus_space_handle_t));
144 /*
145 * void iymeminit __P((void *, struct iy_softc *));
146 * static int iy_mc_setup __P((struct iy_softc *, void *));
147 * static void iy_mc_reset __P((struct iy_softc *));
148 */
149 #ifdef IYDEBUGX
150 void print_rbd __P((volatile struct iy_recv_buf_desc *));
151
152 int in_ifrint = 0;
153 int in_iftint = 0;
154 #endif
155
156 #ifdef __BROKEN_INDIRECT_CONFIG
157 int iyprobe __P((struct device *, void *, void *));
158 #else
159 int iyprobe __P((struct device *, struct cfdata *, void *));
160 #endif
161 void iyattach __P((struct device *, struct device *, void *));
162
163 static u_int16_t eepromread __P((bus_space_tag_t, bus_space_handle_t, int));
164
165 static int eepromreadall __P((bus_space_tag_t, bus_space_handle_t, u_int16_t *,
166 int));
167
168 struct cfattach iy_ca = {
169 sizeof(struct iy_softc), iyprobe, iyattach
170 };
171
172 struct cfdriver iy_cd = {
173 NULL, "iy", DV_IFNET
174 };
175
176 static u_int8_t eepro_irqmap[] = EEPP_INTMAP;
177 static u_int8_t eepro_revirqmap[] = EEPP_RINTMAP;
178
179 int
180 iyprobe(parent, match, aux)
181 struct device *parent;
182 #ifdef __BROKEN_INDIRECT_CONFIG
183 void *match;
184 #else
185 struct cfdata *match;
186 #endif
187 void *aux;
188 {
189 struct isa_attach_args *ia = aux;
190 u_int16_t eaddr[8];
191
192 bus_space_tag_t iot;
193 bus_space_handle_t ioh;
194
195 u_int8_t c, d;
196
197 iot = ia->ia_iot;
198
199 if (ia->ia_iobase == IOBASEUNK)
200 return 0;
201
202 if (bus_space_map(iot, ia->ia_iobase, 16, 0, &ioh))
203 return 0;
204
205 /* try to find the round robin sig: */
206
207 c = bus_space_read_1(iot, ioh, ID_REG);
208 if ((c & ID_REG_MASK) != ID_REG_SIG)
209 goto out;
210
211 d = bus_space_read_1(iot, ioh, ID_REG);
212 if ((d & ID_REG_MASK) != ID_REG_SIG)
213 goto out;
214
215 if (((d-c) & R_ROBIN_BITS) != 0x40)
216 goto out;
217
218 d = bus_space_read_1(iot, ioh, ID_REG);
219 if ((d & ID_REG_MASK) != ID_REG_SIG)
220 goto out;
221
222 if (((d-c) & R_ROBIN_BITS) != 0x80)
223 goto out;
224
225 d = bus_space_read_1(iot, ioh, ID_REG);
226 if ((d & ID_REG_MASK) != ID_REG_SIG)
227 goto out;
228
229 if (((d-c) & R_ROBIN_BITS) != 0xC0)
230 goto out;
231
232 d = bus_space_read_1(iot, ioh, ID_REG);
233 if ((d & ID_REG_MASK) != ID_REG_SIG)
234 goto out;
235
236 if (((d-c) & R_ROBIN_BITS) != 0x00)
237 goto out;
238
239 #ifdef IYDEBUG
240 printf("iyprobe verified working ID reg.\n");
241 #endif
242
243 if (eepromreadall(iot, ioh, eaddr, 8))
244 goto out;
245
246 if (ia->ia_irq == IRQUNK)
247 ia->ia_irq = eepro_irqmap[eaddr[EEPPW1] & EEPP_Int];
248
249 if (ia->ia_irq >= sizeof(eepro_revirqmap))
250 goto out;
251
252 if (eepro_revirqmap[ia->ia_irq] == 0xff)
253 goto out;
254
255 /* now lets reset the chip */
256
257 bus_space_write_1(iot, ioh, COMMAND_REG, RESET_CMD);
258 delay(200);
259
260 ia->ia_iosize = 16;
261
262 bus_space_unmap(iot, ioh, 16);
263 return 1; /* found */
264 out:
265 bus_space_unmap(iot, ioh, 16);
266 return 0;
267 }
268
269 void
270 iyattach(parent, self, aux)
271 struct device *parent, *self;
272 void *aux;
273 {
274 struct iy_softc *sc = (void *)self;
275 struct isa_attach_args *ia = aux;
276 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
277 bus_space_tag_t iot;
278 bus_space_handle_t ioh;
279 unsigned temp;
280 u_int16_t eaddr[8];
281 u_int8_t myaddr[ETHER_ADDR_LEN];
282 int eirq;
283
284 iot = ia->ia_iot;
285
286 if (bus_space_map(iot, ia->ia_iobase, 16, 0, &ioh)) {
287 printf(": can't map i/o space\n");
288 return;
289 }
290
291 sc->sc_iot = iot;
292 sc->sc_ioh = ioh;
293
294 sc->mappedirq = eepro_revirqmap[ia->ia_irq];
295
296 /* now let's reset the chip */
297
298 bus_space_write_1(iot, ioh, COMMAND_REG, RESET_CMD);
299 delay(200);
300
301 iyprobemem(sc);
302
303 bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
304 ifp->if_softc = sc;
305 ifp->if_start = iystart;
306 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
307 /* XXX todo: | IFF_MULTICAST */
308
309 ifp->if_ioctl = iyioctl;
310 ifp->if_watchdog = iywatchdog;
311
312 (void)eepromreadall(iot, ioh, eaddr, 8);
313 sc->hard_vers = eaddr[EEPW6] & EEPP_BoardRev;
314
315 #ifdef DIAGNOSTICS
316 if ((eaddr[EEPPEther0] !=
317 eepromread(iot, ioh, EEPPEther0a)) &&
318 (eaddr[EEPPEther1] !=
319 eepromread(iot, ioh, EEPPEther1a)) &&
320 (eaddr[EEPPEther2] !=
321 eepromread(iot, ioh, EEPPEther2a)))
322
323 printf("EEPROM Ethernet address differs from copy\n");
324 #endif
325
326 myaddr[1] = eaddr[EEPPEther0] & 0xFF;
327 myaddr[0] = eaddr[EEPPEther0] >> 8;
328 myaddr[3] = eaddr[EEPPEther1] & 0xFF;
329 myaddr[2] = eaddr[EEPPEther1] >> 8;
330 myaddr[5] = eaddr[EEPPEther2] & 0xFF;
331 myaddr[4] = eaddr[EEPPEther2] >> 8;
332
333 /* Attach the interface. */
334 if_attach(ifp);
335 ether_ifattach(ifp, myaddr);
336 printf(": address %s, rev. %d, %d kB\n",
337 ether_sprintf(myaddr),
338 sc->hard_vers, sc->sram/1024);
339
340 eirq = eepro_irqmap[eaddr[EEPPW1] & EEPP_Int];
341 if (eirq != ia->ia_irq)
342 printf("%s: EEPROM irq setting %d ignored\n",
343 sc->sc_dev.dv_xname, eirq);
344
345 #if NBPFILTER > 0
346 bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
347 #endif
348
349 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
350 IPL_NET, iyintr, sc);
351
352 #if NRND > 0
353 rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname, RND_TYPE_NET);
354 #endif
355
356 temp = bus_space_read_1(iot, ioh, INT_NO_REG);
357 bus_space_write_1(iot, ioh, INT_NO_REG, (temp & 0xf8) | sc->mappedirq);
358 }
359
360 void
361 iystop(sc)
362 struct iy_softc *sc;
363 {
364 bus_space_tag_t iot;
365 bus_space_handle_t ioh;
366 #ifdef IYDEBUG
367 u_int p, v;
368 #endif
369
370 iot = sc->sc_iot;
371 ioh = sc->sc_ioh;
372
373 bus_space_write_1(iot, ioh, COMMAND_REG, RCV_DISABLE_CMD);
374
375 bus_space_write_1(iot, ioh, INT_MASK_REG, ALL_INTS);
376 bus_space_write_1(iot, ioh, STATUS_REG, ALL_INTS);
377
378 bus_space_write_1(iot, ioh, COMMAND_REG, RESET_CMD);
379 delay(200);
380 #ifdef IYDEBUG
381 printf("%s: dumping tx chain (st 0x%x end 0x%x last 0x%x)\n",
382 sc->sc_dev.dv_xname, sc->tx_start, sc->tx_end, sc->tx_last);
383 p = sc->tx_last;
384 if (!p)
385 p = sc->tx_start;
386 do {
387 bus_space_write_2(iot, ioh, HOST_ADDR_REG, p);
388 v = bus_space_read_2(iot, ioh, MEM_PORT_REG);
389 printf("0x%04x: %b ", p, v, "\020\006Ab\010Dn");
390 v = bus_space_read_2(iot, ioh, MEM_PORT_REG);
391 printf("0x%b", v, "\020\6MAX_COL\7HRT_BEAT\010TX_DEF\011UND_RUN\012JERR\013LST_CRS\014LTCOL\016TX_OK\020COLL");
392 p = bus_space_read_2(iot, ioh, MEM_PORT_REG);
393 printf(" 0x%04x", p);
394 v = bus_space_read_2(iot, ioh, MEM_PORT_REG);
395 printf(" 0x%b\n", v, "\020\020Ch");
396
397 } while (v & 0x8000);
398 #endif
399 sc->tx_start = sc->tx_end = sc->rx_size;
400 sc->tx_last = 0;
401 sc->sc_ethercom.ec_if.if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
402 }
403
404 void
405 iyreset(sc)
406 struct iy_softc *sc;
407 {
408 int s;
409 s = splimp();
410 iystop(sc);
411 iyinit(sc);
412 splx(s);
413 }
414
415 void
416 iyinit(sc)
417 struct iy_softc *sc;
418 {
419 int i;
420 unsigned temp;
421 struct ifnet *ifp;
422 bus_space_tag_t iot;
423 bus_space_handle_t ioh;
424
425 iot = sc->sc_iot;
426 ioh = sc->sc_ioh;
427
428 ifp = &sc->sc_ethercom.ec_if;
429 #ifdef IYDEBUG
430 printf("ifp is %p\n", ifp);
431 #endif
432
433 bus_space_write_1(iot, ioh, 0, BANK_SEL(2));
434
435 temp = bus_space_read_1(iot, ioh, EEPROM_REG);
436 if (temp & 0x10)
437 bus_space_write_1(iot, ioh, EEPROM_REG, temp & ~0x10);
438
439 for (i=0; i<6; ++i) {
440 bus_space_write_1(iot, ioh, I_ADD(i), LLADDR(ifp->if_sadl)[i]);
441 }
442
443 temp = bus_space_read_1(iot, ioh, REG1);
444 bus_space_write_1(iot, ioh, REG1,
445 temp | XMT_CHAIN_INT | XMT_CHAIN_ERRSTOP | RCV_DISCARD_BAD);
446
447 temp = bus_space_read_1(iot, ioh, RECV_MODES_REG);
448 bus_space_write_1(iot, ioh, RECV_MODES_REG, temp | MATCH_BRDCST);
449 #ifdef IYDEBUG
450 printf("%s: RECV_MODES were %b set to %b\n",
451 sc->sc_dev.dv_xname,
452 temp, "\020\1PRMSC\2NOBRDST\3SEECRC\4LENGTH\5NOSaIns\6MultiIA",
453 temp|MATCH_BRDCST,
454 "\020\1PRMSC\2NOBRDST\3SEECRC\4LENGTH\5NOSaIns\6MultiIA");
455 #endif
456
457
458 delay(500000); /* for the hardware to test for the connector */
459
460 temp = bus_space_read_1(iot, ioh, MEDIA_SELECT);
461 #ifdef IYDEBUG
462 printf("%s: media select was 0x%b ", sc->sc_dev.dv_xname,
463 temp, "\020\1LnkInDis\2PolCor\3TPE\4JabberDis\5NoAport\6BNC");
464 #endif
465 temp = (temp & TEST_MODE_MASK);
466
467 switch(ifp->if_flags & (IFF_LINK0 | IFF_LINK1)) {
468 case IFF_LINK0:
469 temp &= ~ (BNC_BIT | TPE_BIT);
470 break;
471
472 case IFF_LINK1:
473 temp = (temp & ~TPE_BIT) | BNC_BIT;
474 break;
475
476 case IFF_LINK0|IFF_LINK1:
477 temp = (temp & ~BNC_BIT) | TPE_BIT;
478 break;
479 default:
480 /* nothing; leave as it is */
481 }
482
483
484 bus_space_write_1(iot, ioh, MEDIA_SELECT, temp);
485 #ifdef IYDEBUG
486 printf("changed to 0x%b\n",
487 temp, "\020\1LnkInDis\2PolCor\3TPE\4JabberDis\5NoAport\6BNC");
488 #endif
489
490 bus_space_write_1(iot, ioh, 0, BANK_SEL(0));
491 bus_space_write_1(iot, ioh, INT_MASK_REG, ALL_INTS);
492 bus_space_write_1(iot, ioh, 0, BANK_SEL(1));
493
494 temp = bus_space_read_1(iot, ioh, INT_NO_REG);
495 bus_space_write_1(iot, ioh, INT_NO_REG, (temp & 0xf8) | sc->mappedirq);
496
497 #ifdef IYDEBUG
498 printf("%s: int no was %b\n", sc->sc_dev.dv_xname,
499 temp, "\020\4bad_irq\010flash/boot present");
500 temp = bus_space_read_1(iot, ioh, INT_NO_REG);
501 printf("%s: int no now 0x%02x\n", sc->sc_dev.dv_xname,
502 temp, "\020\4BAD IRQ\010flash/boot present");
503 #endif
504
505
506 bus_space_write_1(iot, ioh, RCV_LOWER_LIMIT_REG, 0);
507 bus_space_write_1(iot, ioh, RCV_UPPER_LIMIT_REG, (sc->rx_size - 2) >> 8);
508 bus_space_write_1(iot, ioh, XMT_LOWER_LIMIT_REG, sc->rx_size >> 8);
509 bus_space_write_1(iot, ioh, XMT_UPPER_LIMIT_REG, sc->sram >> 8);
510
511 temp = bus_space_read_1(iot, ioh, REG1);
512 #ifdef IYDEBUG
513 printf("%s: HW access is %b\n", sc->sc_dev.dv_xname,
514 temp, "\020\2WORD_WIDTH\010INT_ENABLE");
515 #endif
516 bus_space_write_1(iot, ioh, REG1, temp | INT_ENABLE); /* XXX what about WORD_WIDTH? */
517
518 #ifdef IYDEBUG
519 temp = bus_space_read_1(iot, ioh, REG1);
520 printf("%s: HW access is %b\n", sc->sc_dev.dv_xname,
521 temp, "\020\2WORD_WIDTH\010INT_ENABLE");
522 #endif
523
524 bus_space_write_1(iot, ioh, 0, BANK_SEL(0));
525
526 bus_space_write_1(iot, ioh, INT_MASK_REG, ALL_INTS & ~(RX_BIT|TX_BIT));
527 bus_space_write_1(iot, ioh, STATUS_REG, ALL_INTS); /* clear ints */
528
529 bus_space_write_2(iot, ioh, RCV_START_LOW, 0);
530 bus_space_write_2(iot, ioh, RCV_STOP_LOW, sc->rx_size - 2);
531 sc->rx_start = 0;
532
533 bus_space_write_1(iot, ioh, 0, SEL_RESET_CMD);
534 delay(200);
535
536 bus_space_write_2(iot, ioh, XMT_ADDR_REG, sc->rx_size);
537
538 sc->tx_start = sc->tx_end = sc->rx_size;
539 sc->tx_last = 0;
540
541 bus_space_write_1(iot, ioh, 0, RCV_ENABLE_CMD);
542
543 ifp->if_flags |= IFF_RUNNING;
544 ifp->if_flags &= ~IFF_OACTIVE;
545 }
546
547 void
548 iystart(ifp)
549 struct ifnet *ifp;
550 {
551 struct iy_softc *sc;
552
553
554 struct mbuf *m0, *m;
555 u_int len, pad, last, end;
556 u_int llen, residual;
557 int avail;
558 caddr_t data;
559 u_int16_t resval, stat;
560 bus_space_tag_t iot;
561 bus_space_handle_t ioh;
562
563 #ifdef IYDEBUG
564 printf("iystart called\n");
565 #endif
566 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
567 return;
568
569 sc = ifp->if_softc;
570 iot = sc->sc_iot;
571 ioh = sc->sc_ioh;
572
573 while ((m0 = ifp->if_snd.ifq_head) != NULL) {
574 #ifdef IYDEBUG
575 printf("%s: trying to write another packet to the hardware\n",
576 sc->sc_dev.dv_xname);
577 #endif
578
579 /* We need to use m->m_pkthdr.len, so require the header */
580 if ((m0->m_flags & M_PKTHDR) == 0)
581 panic("iystart: no header mbuf");
582
583 len = m0->m_pkthdr.len;
584 pad = len & 1;
585
586 #ifdef IYDEBUG
587 printf("%s: length is %d.\n", sc->sc_dev.dv_xname, len);
588 #endif
589 if (len < ETHER_MIN_LEN) {
590 pad = ETHER_MIN_LEN - len;
591 }
592
593 if (len + pad > ETHER_MAX_LEN) {
594 /* packet is obviously too large: toss it */
595 ++ifp->if_oerrors;
596 IF_DEQUEUE(&ifp->if_snd, m0);
597 m_freem(m0);
598 continue;
599 }
600
601 #if NBPFILTER > 0
602 if (ifp->if_bpf)
603 bpf_mtap(ifp->if_bpf, m0);
604 #endif
605
606 avail = sc->tx_start - sc->tx_end;
607 if (avail <= 0)
608 avail += sc->tx_size;
609
610 #ifdef IYDEBUG
611 printf("%s: avail is %d.\n", sc->sc_dev.dv_xname, avail);
612 #endif
613 /*
614 * we MUST RUN at splnet here ---
615 * XXX todo: or even turn off the boards ints ??? hm...
616 */
617
618 /* See if there is room to put another packet in the buffer. */
619
620 if ((len+pad+2*I595_XMT_HDRLEN) > avail) {
621 printf("%s: len = %d, avail = %d, setting OACTIVE\n",
622 sc->sc_dev.dv_xname, len, avail);
623 ifp->if_flags |= IFF_OACTIVE;
624 return;
625 }
626
627 /* we know it fits in the hardware now, so dequeue it */
628 IF_DEQUEUE(&ifp->if_snd, m0);
629
630 last = sc->tx_end;
631 end = last + pad + len + I595_XMT_HDRLEN;
632
633 if (end >= sc->sram) {
634 if ((sc->sram - last) <= I595_XMT_HDRLEN) {
635 /* keep header in one piece */
636 last = sc->rx_size;
637 end = last + pad + len + I595_XMT_HDRLEN;
638 } else
639 end -= sc->tx_size;
640 }
641
642 bus_space_write_2(iot, ioh, HOST_ADDR_REG, last);
643 bus_space_write_2(iot, ioh, MEM_PORT_REG, XMT_CMD);
644 bus_space_write_2(iot, ioh, MEM_PORT_REG, 0);
645 bus_space_write_2(iot, ioh, MEM_PORT_REG, 0);
646 bus_space_write_2(iot, ioh, MEM_PORT_REG, len + pad);
647
648 residual = resval = 0;
649
650 while ((m = m0)!=0) {
651 data = mtod(m, caddr_t);
652 llen = m->m_len;
653 if (residual) {
654 #ifdef IYDEBUG
655 printf("%s: merging residual with next mbuf.\n",
656 sc->sc_dev.dv_xname);
657 #endif
658 resval |= *data << 8;
659 bus_space_write_2(iot, ioh, MEM_PORT_REG, resval);
660 --llen;
661 ++data;
662 }
663 if (llen > 1)
664 bus_space_write_multi_2(iot, ioh, MEM_PORT_REG,
665 data, llen>>1);
666 residual = llen & 1;
667 if (residual) {
668 resval = *(data + llen - 1);
669 #ifdef IYDEBUG
670 printf("%s: got odd mbuf to send.\n",
671 sc->sc_dev.dv_xname);
672 #endif
673 }
674
675 MFREE(m, m0);
676 }
677
678 if (residual)
679 bus_space_write_2(iot, ioh, MEM_PORT_REG, resval);
680
681 pad >>= 1;
682 while (pad-- > 0)
683 bus_space_write_2(iot, ioh, MEM_PORT_REG, 0);
684
685 #ifdef IYDEBUG
686 printf("%s: new last = 0x%x, end = 0x%x.\n",
687 sc->sc_dev.dv_xname, last, end);
688 printf("%s: old start = 0x%x, end = 0x%x, last = 0x%x\n",
689 sc->sc_dev.dv_xname, sc->tx_start, sc->tx_end, sc->tx_last);
690 #endif
691
692 if (sc->tx_start != sc->tx_end) {
693 bus_space_write_2(iot, ioh, HOST_ADDR_REG, sc->tx_last + XMT_COUNT);
694 stat = bus_space_read_2(iot, ioh, MEM_PORT_REG);
695
696 bus_space_write_2(iot, ioh, HOST_ADDR_REG, sc->tx_last + XMT_CHAIN);
697 bus_space_write_2(iot, ioh, MEM_PORT_REG, last);
698 bus_space_write_2(iot, ioh, MEM_PORT_REG, stat | CHAIN);
699 #ifdef IYDEBUG
700 printf("%s: setting 0x%x to 0x%x\n",
701 sc->sc_dev.dv_xname, sc->tx_last + XMT_COUNT,
702 stat | CHAIN);
703 #endif
704 }
705 stat = bus_space_read_2(iot, ioh, MEM_PORT_REG); /* dummy read */
706
707 /* XXX todo: enable ints here if disabled */
708
709 ++ifp->if_opackets;
710
711 if (sc->tx_start == sc->tx_end) {
712 bus_space_write_2(iot, ioh, XMT_ADDR_REG, last);
713 bus_space_write_1(iot, ioh, 0, XMT_CMD);
714 sc->tx_start = last;
715 #ifdef IYDEBUG
716 printf("%s: writing 0x%x to XAR and giving XCMD\n",
717 sc->sc_dev.dv_xname, last);
718 #endif
719 } else {
720 bus_space_write_1(iot, ioh, 0, RESUME_XMT_CMD);
721 #ifdef IYDEBUG
722 printf("%s: giving RESUME_XCMD\n",
723 sc->sc_dev.dv_xname);
724 #endif
725 }
726 sc->tx_last = last;
727 sc->tx_end = end;
728 }
729 }
730
731
732 static __inline void
733 eepromwritebit(iot, ioh, what)
734 bus_space_tag_t iot;
735 bus_space_handle_t ioh;
736 int what;
737 {
738 bus_space_write_1(iot, ioh, EEPROM_REG, what);
739 delay(1);
740 bus_space_write_1(iot, ioh, EEPROM_REG, what|EESK);
741 delay(1);
742 bus_space_write_1(iot, ioh, EEPROM_REG, what);
743 delay(1);
744 }
745
746 static __inline int
747 eepromreadbit(iot, ioh)
748 bus_space_tag_t iot;
749 bus_space_handle_t ioh;
750 {
751 int b;
752
753 bus_space_write_1(iot, ioh, EEPROM_REG, EECS|EESK);
754 delay(1);
755 b = bus_space_read_1(iot, ioh, EEPROM_REG);
756 bus_space_write_1(iot, ioh, EEPROM_REG, EECS);
757 delay(1);
758
759 return ((b & EEDO) != 0);
760 }
761
762 static u_int16_t
763 eepromread(iot, ioh, offset)
764 bus_space_tag_t iot;
765 bus_space_handle_t ioh;
766 int offset;
767 {
768 volatile int i;
769 volatile int j;
770 volatile u_int16_t readval;
771
772 bus_space_write_1(iot, ioh, 0, BANK_SEL(2));
773 delay(1);
774 bus_space_write_1(iot, ioh, EEPROM_REG, EECS); /* XXXX??? */
775 delay(1);
776
777 eepromwritebit(iot, ioh, EECS|EEDI);
778 eepromwritebit(iot, ioh, EECS|EEDI);
779 eepromwritebit(iot, ioh, EECS);
780
781 for (j=5; j>=0; --j) {
782 if ((offset>>j) & 1)
783 eepromwritebit(iot, ioh, EECS|EEDI);
784 else
785 eepromwritebit(iot, ioh, EECS);
786 }
787
788 for (readval=0, i=0; i<16; ++i) {
789 readval<<=1;
790 readval |= eepromreadbit(iot, ioh);
791 }
792
793 bus_space_write_1(iot, ioh, EEPROM_REG, 0|EESK);
794 delay(1);
795 bus_space_write_1(iot, ioh, EEPROM_REG, 0);
796
797 bus_space_write_1(iot, ioh, COMMAND_REG, BANK_SEL(0));
798
799 return readval;
800 }
801
802 /*
803 * Device timeout/watchdog routine. Entered if the device neglects to generate
804 * an interrupt after a transmit has been started on it.
805 */
806 void
807 iywatchdog(ifp)
808 struct ifnet *ifp;
809 {
810 struct iy_softc *sc = ifp->if_softc;
811
812 log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
813 ++sc->sc_ethercom.ec_if.if_oerrors;
814 iyreset(sc);
815 }
816
817 /*
818 * What to do upon receipt of an interrupt.
819 */
820 int
821 iyintr(arg)
822 void *arg;
823 {
824 struct iy_softc *sc = arg;
825 bus_space_tag_t iot;
826 bus_space_handle_t ioh;
827
828 register u_short status;
829
830 iot = sc->sc_iot;
831 ioh = sc->sc_ioh;
832
833 status = bus_space_read_1(iot, ioh, STATUS_REG);
834 #ifdef IYDEBUG
835 if (status & ALL_INTS) {
836 printf("%s: got interupt %b", sc->sc_dev.dv_xname, status,
837 "\020\1RX_STP\2RX\3TX\4EXEC");
838 if (status & EXEC_INT)
839 printf(" event %b\n", bus_space_read_1(iot, ioh, 0),
840 "\020\6ABORT");
841 else
842 printf("\n");
843 }
844 #endif
845 if (((status & (RX_INT | TX_INT)) == 0))
846 return 0;
847
848 if (status & RX_INT) {
849 iy_intr_rx(sc);
850 bus_space_write_1(iot, ioh, STATUS_REG, RX_INT);
851 } else if (status & TX_INT) {
852 iy_intr_tx(sc);
853 bus_space_write_1(iot, ioh, STATUS_REG, TX_INT);
854 }
855
856 #if NRND > 0
857 rnd_add_uint32(&sc->rnd_source, status);
858 #endif
859
860 return 1;
861 }
862
863 void
864 iyget(sc, iot, ioh, rxlen)
865 struct iy_softc *sc;
866 bus_space_tag_t iot;
867 bus_space_handle_t ioh;
868 int rxlen;
869 {
870 struct mbuf *m, *top, **mp;
871 struct ether_header *eh;
872 struct ifnet *ifp;
873 int len;
874
875 ifp = &sc->sc_ethercom.ec_if;
876
877 MGETHDR(m, M_DONTWAIT, MT_DATA);
878 if (m == 0)
879 goto dropped;
880 m->m_pkthdr.rcvif = ifp;
881 m->m_pkthdr.len = rxlen;
882 len = MHLEN;
883 top = 0;
884 mp = ⊤
885
886 while (rxlen > 0) {
887 if (top) {
888 MGET(m, M_DONTWAIT, MT_DATA);
889 if (m == 0) {
890 m_freem(top);
891 goto dropped;
892 }
893 len = MLEN;
894 }
895 if (rxlen >= MINCLSIZE) {
896 MCLGET(m, M_DONTWAIT);
897 if ((m->m_flags & M_EXT) == 0) {
898 m_free(m);
899 m_freem(top);
900 goto dropped;
901 }
902 len = MCLBYTES;
903 }
904 len = min(rxlen, len);
905 if (len > 1) {
906 len &= ~1;
907
908 bus_space_read_multi_2(iot, ioh, MEM_PORT_REG,
909 mtod(m, caddr_t), len/2);
910 } else {
911 #ifdef IYDEBUG
912 printf("%s: received odd mbuf\n", sc->sc_dev.dv_xname);
913 #endif
914 *(mtod(m, caddr_t)) = bus_space_read_2(iot, ioh,
915 MEM_PORT_REG);
916 }
917 m->m_len = len;
918 rxlen -= len;
919 *mp = m;
920 mp = &m->m_next;
921 }
922 /* XXX receive the top here */
923 ++ifp->if_ipackets;
924
925 eh = mtod(top, struct ether_header *);
926
927 #if NBPFILTER > 0
928 if (ifp->if_bpf) {
929 bpf_mtap(ifp->if_bpf, top);
930 if ((ifp->if_flags & IFF_PROMISC) &&
931 (eh->ether_dhost[0] & 1) == 0 &&
932 bcmp(eh->ether_dhost,
933 LLADDR(sc->sc_ethercom.ec_if.if_sadl),
934 sizeof(eh->ether_dhost)) != 0) {
935
936 m_freem(top);
937 return;
938 }
939 }
940 #endif
941 m_adj(top, sizeof(struct ether_header));
942 ether_input(ifp, eh, top);
943 return;
944
945 dropped:
946 ++ifp->if_ierrors;
947 return;
948 }
949 void
950 iy_intr_rx(sc)
951 struct iy_softc *sc;
952 {
953 struct ifnet *ifp;
954 bus_space_tag_t iot;
955 bus_space_handle_t ioh;
956
957 u_int rxadrs, rxevnt, rxstatus, rxnext, rxlen;
958
959 iot = sc->sc_iot;
960 ioh = sc->sc_ioh;
961 ifp = &sc->sc_ethercom.ec_if;
962
963 rxadrs = sc->rx_start;
964 bus_space_write_2(iot, ioh, HOST_ADDR_REG, rxadrs);
965 rxevnt = bus_space_read_2(iot, ioh, MEM_PORT_REG);
966 rxnext = 0;
967
968 while (rxevnt == RCV_DONE) {
969 rxstatus = bus_space_read_2(iot, ioh, MEM_PORT_REG);
970 rxnext = bus_space_read_2(iot, ioh, MEM_PORT_REG);
971 rxlen = bus_space_read_2(iot, ioh, MEM_PORT_REG);
972 #ifdef IYDEBUG
973 printf("%s: pck at 0x%04x stat %b next 0x%x len 0x%x\n",
974 sc->sc_dev.dv_xname, rxadrs, rxstatus,
975 "\020\1RCLD\2IA_MCH\010SHORT\011OVRN\013ALGERR"
976 "\014CRCERR\015LENERR\016RCVOK\020TYP",
977 rxnext, rxlen);
978 #endif
979 iyget(sc, iot, ioh, rxlen);
980
981 /* move stop address */
982 bus_space_write_2(iot, ioh, RCV_STOP_LOW,
983 rxnext == 0 ? sc->rx_size - 2 : rxnext - 2);
984
985 bus_space_write_2(iot, ioh, HOST_ADDR_REG, rxnext);
986 rxadrs = rxnext;
987 rxevnt = bus_space_read_2(iot, ioh, MEM_PORT_REG);
988 }
989 sc->rx_start = rxnext;
990 }
991
992 void
993 iy_intr_tx(sc)
994 struct iy_softc *sc;
995 {
996 bus_space_tag_t iot;
997 bus_space_handle_t ioh;
998 struct ifnet *ifp;
999 u_int txstatus, txstat2, txlen, txnext;
1000
1001 ifp = &sc->sc_ethercom.ec_if;
1002 iot = sc->sc_iot;
1003 ioh = sc->sc_ioh;
1004
1005 while (sc->tx_start != sc->tx_end) {
1006 bus_space_write_2(iot, ioh, HOST_ADDR_REG, sc->tx_start);
1007 txstatus = bus_space_read_2(iot, ioh, MEM_PORT_REG);
1008 if ((txstatus & (TX_DONE|CMD_MASK)) != (TX_DONE|XMT_CMD))
1009 break;
1010
1011 txstat2 = bus_space_read_2(iot, ioh, MEM_PORT_REG);
1012 txnext = bus_space_read_2(iot, ioh, MEM_PORT_REG);
1013 txlen = bus_space_read_2(iot, ioh, MEM_PORT_REG);
1014 #ifdef IYDEBUG
1015 printf("txstat 0x%x stat2 0x%b next 0x%x len 0x%x\n",
1016 txstatus, txstat2, "\020\6MAX_COL\7HRT_BEAT\010TX_DEF"
1017 "\011UND_RUN\012JERR\013LST_CRS\014LTCOL\016TX_OK\020COLL",
1018 txnext, txlen);
1019 #endif
1020 if (txlen & CHAIN)
1021 sc->tx_start = txnext;
1022 else
1023 sc->tx_start = sc->tx_end;
1024 ifp->if_flags &= ~IFF_OACTIVE;
1025
1026 if ((txstat2 & 0x2000) == 0)
1027 ++ifp->if_oerrors;
1028 if (txstat2 & 0x000f)
1029 ifp->if_oerrors += txstat2 & 0x000f;
1030 }
1031 ifp->if_flags &= ~IFF_OACTIVE;
1032 }
1033
1034 #if 0
1035 /*
1036 * Compare two Ether/802 addresses for equality, inlined and unrolled for
1037 * speed. I'd love to have an inline assembler version of this...
1038 */
1039 static inline int
1040 ether_equal(one, two)
1041 u_char *one, *two;
1042 {
1043
1044 if (one[0] != two[0] || one[1] != two[1] || one[2] != two[2] ||
1045 one[3] != two[3] || one[4] != two[4] || one[5] != two[5])
1046 return 0;
1047 return 1;
1048 }
1049
1050 /*
1051 * Check for a valid address. to_bpf is filled in with one of the following:
1052 * 0 -> BPF doesn't get this packet
1053 * 1 -> BPF does get this packet
1054 * 2 -> BPF does get this packet, but we don't
1055 * Return value is true if the packet is for us, and false otherwise.
1056 *
1057 * This routine is a mess, but it's also critical that it be as fast
1058 * as possible. It could be made cleaner if we can assume that the
1059 * only client which will fiddle with IFF_PROMISC is BPF. This is
1060 * probably a good assumption, but we do not make it here. (Yet.)
1061 */
1062 static inline int
1063 check_eh(sc, eh, to_bpf)
1064 struct iy_softc *sc;
1065 struct ether_header *eh;
1066 int *to_bpf;
1067 {
1068 int i;
1069
1070 switch (sc->promisc) {
1071 case IFF_ALLMULTI:
1072 /*
1073 * Receiving all multicasts, but no unicasts except those
1074 * destined for us.
1075 */
1076 #if NBPFILTER > 0
1077 *to_bpf = (sc->sc_ethercom.ec_if.iy_bpf != 0); /* BPF gets this packet if anybody cares */
1078 #endif
1079 if (eh->ether_dhost[0] & 1)
1080 return 1;
1081 if (ether_equal(eh->ether_dhost,
1082 LLADDR(sc->sc_ethercom.ec_if.if_sadl)))
1083 return 1;
1084 return 0;
1085
1086 case IFF_PROMISC:
1087 /*
1088 * Receiving all packets. These need to be passed on to BPF.
1089 */
1090 #if NBPFILTER > 0
1091 *to_bpf = (sc->sc_ethercom.ec_if.iy_bpf != 0);
1092 #endif
1093 /* If for us, accept and hand up to BPF */
1094 if (ether_equal(eh->ether_dhost, LLADDR(sc->sc_ethercom.ec_if.if_sadl)))
1095 return 1;
1096
1097 #if NBPFILTER > 0
1098 if (*to_bpf)
1099 *to_bpf = 2; /* we don't need to see it */
1100 #endif
1101
1102 /*
1103 * Not a multicast, so BPF wants to see it but we don't.
1104 */
1105 if (!(eh->ether_dhost[0] & 1))
1106 return 1;
1107
1108 /*
1109 * If it's one of our multicast groups, accept it and pass it
1110 * up.
1111 */
1112 for (i = 0; i < sc->mcast_count; i++) {
1113 if (ether_equal(eh->ether_dhost, (u_char *)&sc->mcast_addrs[i])) {
1114 #if NBPFILTER > 0
1115 if (*to_bpf)
1116 *to_bpf = 1;
1117 #endif
1118 return 1;
1119 }
1120 }
1121 return 1;
1122
1123 case IFF_ALLMULTI | IFF_PROMISC:
1124 /*
1125 * Acting as a multicast router, and BPF running at the same
1126 * time. Whew! (Hope this is a fast machine...)
1127 */
1128 #if NBPFILTER > 0
1129 *to_bpf = (sc->sc_ethercom.ec_if.iy_bpf != 0);
1130 #endif
1131 /* We want to see multicasts. */
1132 if (eh->ether_dhost[0] & 1)
1133 return 1;
1134
1135 /* We want to see our own packets */
1136 if (ether_equal(eh->ether_dhost, LLADDR(sc->sc_ethercom.ec_if.if_sadl)))
1137 return 1;
1138
1139 /* Anything else goes to BPF but nothing else. */
1140 #if NBPFILTER > 0
1141 if (*to_bpf)
1142 *to_bpf = 2;
1143 #endif
1144 return 1;
1145
1146 case 0:
1147 /*
1148 * Only accept unicast packets destined for us, or multicasts
1149 * for groups that we belong to. For now, we assume that the
1150 * '586 will only return packets that we asked it for. This
1151 * isn't strictly true (it uses hashing for the multicast
1152 * filter), but it will do in this case, and we want to get out
1153 * of here as quickly as possible.
1154 */
1155 #if NBPFILTER > 0
1156 *to_bpf = (sc->sc_ethercom.ec_if.iy_bpf != 0);
1157 #endif
1158 return 1;
1159 }
1160
1161 #ifdef DIAGNOSTIC
1162 panic("check_eh: impossible");
1163 #endif
1164 }
1165 #endif
1166
1167 int
1168 iyioctl(ifp, cmd, data)
1169 register struct ifnet *ifp;
1170 u_long cmd;
1171 caddr_t data;
1172 {
1173 struct iy_softc *sc;
1174 struct ifaddr *ifa;
1175 struct ifreq *ifr;
1176 int s, error = 0;
1177
1178 sc = ifp->if_softc;
1179 ifa = (struct ifaddr *)data;
1180 ifr = (struct ifreq *)data;
1181
1182 #ifdef IYDEBUG
1183 printf("iyioctl called with ifp 0x%p (%s) cmd 0x%x data 0x%p\n",
1184 ifp, ifp->if_xname, cmd, data);
1185 #endif
1186
1187 s = splimp();
1188
1189 switch (cmd) {
1190
1191 case SIOCSIFADDR:
1192 ifp->if_flags |= IFF_UP;
1193
1194 switch (ifa->ifa_addr->sa_family) {
1195 #ifdef INET
1196 case AF_INET:
1197 iyinit(sc);
1198 arp_ifinit(ifp, ifa);
1199 break;
1200 #endif
1201 #ifdef NS
1202 /* XXX - This code is probably wrong. */
1203 case AF_NS:
1204 {
1205 struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
1206
1207 if (ns_nullhost(*ina))
1208 ina->x_host = *(union ns_host *)
1209 LLADDR(sc->sc_ethercom.ec_if.if_sadl);
1210 else
1211 bcopy(ina->x_host.c_host,
1212 LLADDR(sc->sc_ethercom.ec_if.if_sadl),
1213 ETHER_ADDR_LEN);
1214 /* Set new address. */
1215 iyinit(sc);
1216 break;
1217 }
1218 #endif /* NS */
1219 default:
1220 iyinit(sc);
1221 break;
1222 }
1223 break;
1224
1225 case SIOCSIFFLAGS:
1226 sc->promisc = ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI);
1227 if ((ifp->if_flags & IFF_UP) == 0 &&
1228 (ifp->if_flags & IFF_RUNNING) != 0) {
1229 /*
1230 * If interface is marked down and it is running, then
1231 * stop it.
1232 */
1233 iystop(sc);
1234 ifp->if_flags &= ~IFF_RUNNING;
1235 } else if ((ifp->if_flags & IFF_UP) != 0 &&
1236 (ifp->if_flags & IFF_RUNNING) == 0) {
1237 /*
1238 * If interface is marked up and it is stopped, then
1239 * start it.
1240 */
1241 iyinit(sc);
1242 } else {
1243 /*
1244 * Reset the interface to pick up changes in any other
1245 * flags that affect hardware registers.
1246 */
1247 iystop(sc);
1248 iyinit(sc);
1249 }
1250 #ifdef IYDEBUGX
1251 if (ifp->if_flags & IFF_DEBUG)
1252 sc->sc_debug = IFY_ALL;
1253 else
1254 sc->sc_debug = 0;
1255 #endif
1256 break;
1257
1258 #if 0 /* XXX */
1259 case SIOCADDMULTI:
1260 case SIOCDELMULTI:
1261 error = (cmd == SIOCADDMULTI) ?
1262 ether_addmulti(ifr, &sc->sc_ethercom):
1263 ether_delmulti(ifr, &sc->sc_ethercom);
1264
1265 if (error == ENETRESET) {
1266 /*
1267 * Multicast list has changed; set the hardware filter
1268 * accordingly.
1269 */
1270 iy_mc_reset(sc); /* XXX */
1271 error = 0;
1272 }
1273 break;
1274 #endif
1275 default:
1276 error = EINVAL;
1277 }
1278 splx(s);
1279 return error;
1280 }
1281
1282 #if 0
1283 static void
1284 iy_mc_reset(sc)
1285 struct iy_softc *sc;
1286 {
1287 struct ether_multi *enm;
1288 struct ether_multistep step;
1289
1290 /*
1291 * Step through the list of addresses.
1292 */
1293 sc->mcast_count = 0;
1294 ETHER_FIRST_MULTI(step, &sc->sc_ethercom, enm);
1295 while (enm) {
1296 if (sc->mcast_count >= MAXMCAST ||
1297 bcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0) {
1298 sc->sc_ethercom.ec_if.if_flags |= IFF_ALLMULTI;
1299 iyioctl(&sc->sc_ethercom.ec_if, SIOCSIFFLAGS,
1300 (void *)0);
1301 goto setflag;
1302 }
1303
1304 bcopy(enm->enm_addrlo, &sc->mcast_addrs[sc->mcast_count], 6);
1305 sc->mcast_count++;
1306 ETHER_NEXT_MULTI(step, enm);
1307 }
1308 setflag:
1309 sc->want_mcsetup = 1;
1310 }
1311
1312 #ifdef IYDEBUG
1313 void
1314 print_rbd(rbd)
1315 volatile struct ie_recv_buf_desc *rbd;
1316 {
1317
1318 printf("RBD at %08lx:\nactual %04x, next %04x, buffer %08x\n"
1319 "length %04x, mbz %04x\n", (u_long)rbd, rbd->ie_rbd_actual,
1320 rbd->ie_rbd_next, rbd->ie_rbd_buffer, rbd->ie_rbd_length,
1321 rbd->mbz);
1322 }
1323 #endif
1324 #endif
1325
1326 void
1327 iyprobemem(sc)
1328 struct iy_softc *sc;
1329 {
1330 bus_space_tag_t iot;
1331 bus_space_handle_t ioh;
1332 int testing;
1333
1334 iot = sc->sc_iot;
1335 ioh = sc->sc_ioh;
1336
1337 bus_space_write_1(iot, ioh, COMMAND_REG, BANK_SEL(0));
1338 delay(1);
1339 bus_space_write_2(iot, ioh, HOST_ADDR_REG, 4096-2);
1340 bus_space_write_2(iot, ioh, MEM_PORT_REG, 0);
1341
1342 for (testing=65536; testing >= 4096; testing >>= 1) {
1343 bus_space_write_2(iot, ioh, HOST_ADDR_REG, testing-2);
1344 bus_space_write_2(iot, ioh, MEM_PORT_REG, 0xdead);
1345 bus_space_write_2(iot, ioh, HOST_ADDR_REG, testing-2);
1346 if (bus_space_read_2(iot, ioh, MEM_PORT_REG) != 0xdead) {
1347 #ifdef IYMEMDEBUG
1348 printf("%s: Didn't keep 0xdead at 0x%x\n",
1349 sc->sc_dev.dv_xname, testing-2);
1350 #endif
1351 continue;
1352 }
1353
1354 bus_space_write_2(iot, ioh, HOST_ADDR_REG, testing-2);
1355 bus_space_write_2(iot, ioh, MEM_PORT_REG, 0xbeef);
1356 bus_space_write_2(iot, ioh, HOST_ADDR_REG, testing-2);
1357 if (bus_space_read_2(iot, ioh, MEM_PORT_REG) != 0xbeef) {
1358 #ifdef IYMEMDEBUG
1359 printf("%s: Didn't keep 0xbeef at 0x%x\n",
1360 sc->sc_dev.dv_xname, testing-2);
1361 #endif
1362 continue;
1363 }
1364
1365 bus_space_write_2(iot, ioh, HOST_ADDR_REG, 0);
1366 bus_space_write_2(iot, ioh, MEM_PORT_REG, 0);
1367 bus_space_write_2(iot, ioh, HOST_ADDR_REG, testing >> 1);
1368 bus_space_write_2(iot, ioh, MEM_PORT_REG, testing >> 1);
1369 bus_space_write_2(iot, ioh, HOST_ADDR_REG, 0);
1370 if (bus_space_read_2(iot, ioh, MEM_PORT_REG) == (testing >> 1)) {
1371 #ifdef IYMEMDEBUG
1372 printf("%s: 0x%x alias of 0x0\n",
1373 sc->sc_dev.dv_xname, testing >> 1);
1374 #endif
1375 continue;
1376 }
1377
1378 break;
1379 }
1380
1381 sc->sram = testing;
1382
1383 switch(testing) {
1384 case 65536:
1385 /* 4 NFS packets + overhead RX, 2 NFS + overhead TX */
1386 sc->rx_size = 44*1024;
1387 break;
1388
1389 case 32768:
1390 /* 2 NFS packets + overhead RX, 1 NFS + overhead TX */
1391 sc->rx_size = 22*1024;
1392 break;
1393
1394 case 16384:
1395 /* 1 NFS packet + overhead RX, 4 big packets TX */
1396 sc->rx_size = 10*1024;
1397 break;
1398 default:
1399 sc->rx_size = testing/2;
1400 break;
1401 }
1402 sc->tx_size = testing - sc->rx_size;
1403 }
1404
1405 static int
1406 eepromreadall(iot, ioh, wordp, maxi)
1407 bus_space_tag_t iot;
1408 bus_space_handle_t ioh;
1409 u_int16_t *wordp;
1410 int maxi;
1411 {
1412 int i;
1413 u_int16_t checksum, tmp;
1414
1415 checksum = 0;
1416
1417 for (i=0; i<EEPP_LENGTH; ++i) {
1418 tmp = eepromread(iot, ioh, i);
1419 checksum += tmp;
1420 if (i<maxi)
1421 wordp[i] = tmp;
1422 }
1423
1424 if (checksum != EEPP_CHKSUM) {
1425 #ifdef IYDEBUG
1426 printf("wrong EEPROM checksum 0x%x should be 0x%x\n",
1427 checksum, EEPP_CHKSUM);
1428 #endif
1429 return 1;
1430 }
1431 return 0;
1432 }
1433