if_ep.c revision 33108
1/*
2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by Herb Peyerl.
16 * 4. The name of Herb Peyerl may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 *	if_ep.c,v 1.19 1995/01/24 20:53:45 davidg Exp
31 */
32
33/*
34 *	Modified from the FreeBSD 1.1.5.1 version by:
35 *		 	Andres Vega Garcia
36 *			INRIA - Sophia Antipolis, France
37 *			avega@sophia.inria.fr
38 */
39
40/*
41 *  $Id: if_ep.c,v 1.70 1998/01/08 23:40:50 eivind Exp $
42 *
43 *  Promiscuous mode added and interrupt logic slightly changed
44 *  to reduce the number of adapter failures. Transceiver select
45 *  logic changed to use value from EEPROM. Autoconfiguration
46 *  features added.
47 *  Done by:
48 *          Serge Babkin
49 *          Chelindbank (Chelyabinsk, Russia)
50 *          babkin@hq.icb.chel.su
51 */
52
53/*
54 * Pccard support for 3C589 by:
55 *		HAMADA Naoki
56 *		nao@tom-yam.or.jp
57 */
58
59#include "ep.h"
60#if NEP > 0
61
62#include "bpfilter.h"
63#include "opt_diagnostic.h"
64#include "opt_inet.h"
65#include "opt_ipx.h"
66
67#include <sys/param.h>
68#if defined(__FreeBSD__)
69#include <sys/kernel.h>
70#include <sys/systm.h>
71#include <sys/conf.h>
72#endif
73#include <sys/malloc.h>
74#include <sys/mbuf.h>
75#include <sys/socket.h>
76#include <sys/sockio.h>
77#if defined(__NetBSD__)
78#include <sys/select.h>
79#endif
80
81#include <net/if.h>
82
83#if defined(__FreeBSD__)
84#include <net/ethernet.h>
85#include <net/if_arp.h>
86#endif
87
88#ifdef INET
89#include <netinet/in.h>
90#include <netinet/if_ether.h>
91#endif
92
93#ifdef IPX
94#include <netipx/ipx.h>
95#include <netipx/ipx_if.h>
96#endif
97
98#ifdef NS
99#include <netns/ns.h>
100#include <netns/ns_if.h>
101#endif
102
103#if NBPFILTER > 0
104#include <net/bpf.h>
105#endif
106
107#if defined(__FreeBSD__)
108#include <machine/clock.h>
109#endif
110
111#include <i386/isa/isa_device.h>
112#include <i386/isa/if_epreg.h>
113#include <i386/isa/elink.h>
114
115/* Exported variables */
116u_long	ep_unit;
117int	ep_boards;
118struct	ep_board ep_board[EP_MAX_BOARDS + 1];
119
120static	int eeprom_rdy __P((struct ep_softc *sc));
121
122static	int ep_isa_probe __P((struct isa_device *));
123static struct ep_board * ep_look_for_board_at __P((struct isa_device *is));
124static	int ep_isa_attach __P((struct isa_device *));
125static	int epioctl __P((struct ifnet * ifp, int, caddr_t));
126
127static	void epinit __P((struct ep_softc *));
128static	void epread __P((struct ep_softc *));
129void	epreset __P((int));
130static	void epstart __P((struct ifnet *));
131static	void epstop __P((struct ep_softc *));
132static	void epwatchdog __P((struct ifnet *));
133
134#if 0
135static	int send_ID_sequence __P((int));
136#endif
137static	int get_eeprom_data __P((int, int));
138
139static	struct ep_softc* ep_softc[NEP];
140static	int ep_current_tag = EP_LAST_TAG + 1;
141static	char *ep_conn_type[] = {"UTP", "AUI", "???", "BNC"};
142
143#define ep_ftst(f) (sc->stat&(f))
144#define ep_fset(f) (sc->stat|=(f))
145#define ep_frst(f) (sc->stat&=~(f))
146
147struct isa_driver epdriver = {
148    ep_isa_probe,
149    ep_isa_attach,
150    "ep",
151    0
152};
153
154#include "card.h"
155
156#if NCARD > 0
157#include <sys/select.h>
158#include <pccard/cardinfo.h>
159#include <pccard/driver.h>
160#include <pccard/slot.h>
161
162/*
163 * PC-Card (PCMCIA) specific code.
164 */
165static int ep_pccard_init __P((struct pccard_devinfo *));
166static int ep_pccard_attach  __P((struct pccard_devinfo *));
167static void ep_unload __P((struct pccard_devinfo *));
168static int card_intr __P((struct pccard_devinfo *));
169
170static struct pccard_device ep_info = {
171    "ep",
172    ep_pccard_init,
173    ep_unload,
174    card_intr,
175    0,                      /* Attributes - presently unused */
176    &net_imask
177};
178
179DATA_SET(pccarddrv_set, ep_info);
180
181/*
182 * Initialize the device - called from Slot manager.
183 */
184static int
185ep_pccard_init(devi)
186    struct pccard_devinfo *devi;
187{
188    struct isa_device *is = &devi->isahd;
189    struct ep_softc *sc = ep_softc[is->id_unit];
190    struct ep_board *epb;
191    int i;
192
193    epb = &ep_board[is->id_unit];
194
195    if (sc == 0) {
196	if ((sc = ep_alloc(is->id_unit, epb)) == 0) {
197	    return (ENXIO);
198	}
199	ep_unit++;
200    }
201
202    /* get_e() requires these. */
203    sc->ep_io_addr = is->id_iobase;
204    sc->unit = is->id_unit;
205
206    epb->epb_addr = is->id_iobase;
207    epb->epb_used = 1;
208    epb->prod_id = get_e(sc, EEPROM_PROD_ID);
209
210    /* 3C589's product id? */
211    if (epb->prod_id != 0x9058) {
212	printf("ep%d: failed to come ready.\n", is->id_unit);
213	return (ENXIO);
214    }
215
216    epb->res_cfg = get_e(sc, EEPROM_RESOURCE_CFG);
217    for (i = 0; i < 3; i++)
218	sc->epb->eth_addr[i] = get_e(sc, EEPROM_NODE_ADDR_0 + i);
219
220    if (ep_pccard_attach(devi) == 0)
221	return (ENXIO);
222
223    sc->arpcom.ac_if.if_snd.ifq_maxlen = ifqmaxlen;
224    return (0);
225}
226
227static int
228ep_pccard_attach(devi)
229    struct pccard_devinfo *devi;
230{
231    struct isa_device *is = &devi->isahd;
232    struct ep_softc *sc = ep_softc[is->id_unit];
233    u_short config;
234
235    sc->ep_connectors = 0;
236    config = inw(IS_BASE + EP_W0_CONFIG_CTRL);
237    if (config & IS_BNC) {
238	sc->ep_connectors |= BNC;
239    }
240    if (config & IS_UTP) {
241	sc->ep_connectors |= UTP;
242    }
243    if (!(sc->ep_connectors & 7))
244	printf("no connectors!");
245    sc->ep_connector = inw(BASE + EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
246
247    /* ROM size = 0, ROM base = 0 */
248    /* For now, ignore AUTO SELECT feature of 3C589B and later. */
249    outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000);
250
251    /* Fake IRQ must be 3 */
252    outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb->res_cfg & 0x0fff) | 0x3000);
253
254    outw(BASE + EP_W0_PRODUCT_ID, sc->epb->prod_id);
255
256    ep_attach(sc);
257
258    return 1;
259}
260
261static void
262ep_unload(devi)
263    struct pccard_devinfo *devi;
264{
265    struct ep_softc *sc = ep_softc[devi->isahd.id_unit];
266
267    if (sc->gone) {
268        printf("ep%d: already unloaded\n", devi->isahd.id_unit);
269	return;
270    }
271    sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING;
272    sc->gone = 1;
273    printf("ep%d: unload\n", devi->isahd.id_unit);
274}
275
276/*
277 * card_intr - Shared interrupt called from
278 * front end of PC-Card handler.
279 */
280static int
281card_intr(devi)
282    struct pccard_devinfo *devi;
283{
284    epintr(devi->isahd.id_unit);
285    return(1);
286}
287#endif /* NCARD > 0 */
288
289static int
290eeprom_rdy(sc)
291    struct ep_softc *sc;
292{
293    int i;
294
295    for (i = 0; is_eeprom_busy(BASE) && i < MAX_EEPROMBUSY; i++)
296	continue;
297    if (i >= MAX_EEPROMBUSY) {
298	printf("ep%d: eeprom failed to come ready.\n", sc->unit);
299	return (0);
300    }
301    return (1);
302}
303
304static struct ep_board *
305ep_look_for_board_at(is)
306    struct isa_device *is;
307{
308    int data, i, j, id_port = ELINK_ID_PORT;
309    int count = 0;
310
311    if (ep_current_tag == (EP_LAST_TAG + 1)) {
312	/* Come here just one time */
313
314	ep_current_tag--;
315
316        /* Look for the ISA boards. Init and leave them actived */
317	outb(id_port, 0);
318	outb(id_port, 0);
319
320	elink_idseq(0xCF);
321
322	elink_reset();
323	DELAY(10000);
324	for (i = 0; i < EP_MAX_BOARDS; i++) {
325	    outb(id_port, 0);
326	    outb(id_port, 0);
327	    elink_idseq(0xCF);
328
329	    data = get_eeprom_data(id_port, EEPROM_MFG_ID);
330	    if (data != MFG_ID)
331		break;
332
333	    /* resolve contention using the Ethernet address */
334
335	    for (j = 0; j < 3; j++)
336		 get_eeprom_data(id_port, j);
337
338	    /* and save this address for later use */
339
340	    for (j = 0; j < 3; j++)
341		 ep_board[ep_boards].eth_addr[j] = get_eeprom_data(id_port, j);
342
343	    ep_board[ep_boards].res_cfg =
344		get_eeprom_data(id_port, EEPROM_RESOURCE_CFG);
345
346	    ep_board[ep_boards].prod_id =
347		get_eeprom_data(id_port, EEPROM_PROD_ID);
348
349	    ep_board[ep_boards].epb_used = 0;
350#ifdef PC98
351	    ep_board[ep_boards].epb_addr =
352			(get_eeprom_data(id_port, EEPROM_ADDR_CFG) & 0x1f) * 0x100 + 0x40d0;
353#else
354	    ep_board[ep_boards].epb_addr =
355			(get_eeprom_data(id_port, EEPROM_ADDR_CFG) & 0x1f) * 0x10 + 0x200;
356
357	    if (ep_board[ep_boards].epb_addr > 0x3E0)
358		/* Board in EISA configuration mode */
359		continue;
360#endif /* PC98 */
361
362	    outb(id_port, ep_current_tag);	/* tags board */
363	    outb(id_port, ACTIVATE_ADAPTER_TO_CONFIG);
364	    ep_boards++;
365	    count++;
366	    ep_current_tag--;
367	}
368
369	ep_board[ep_boards].epb_addr = 0;
370	if (count) {
371	    printf("%d 3C5x9 board(s) on ISA found at", count);
372	    for (j = 0; ep_board[j].epb_addr; j++)
373		if (ep_board[j].epb_addr <= 0x3E0)
374		    printf(" 0x%x", ep_board[j].epb_addr);
375	    printf("\n");
376	}
377    }
378
379    /* we have two cases:
380     *
381     *  1. Device was configured with 'port ?'
382     *      In this case we search for the first unused card in list
383     *
384     *  2. Device was configured with 'port xxx'
385     *      In this case we search for the unused card with that address
386     *
387     */
388
389    if (IS_BASE == -1) { /* port? */
390	for (i = 0; ep_board[i].epb_addr && ep_board[i].epb_used; i++)
391	    ;
392	if (ep_board[i].epb_addr == 0)
393	    return 0;
394
395	IS_BASE = ep_board[i].epb_addr;
396	ep_board[i].epb_used = 1;
397
398	return &ep_board[i];
399    } else {
400	for (i = 0;
401	     ep_board[i].epb_addr && ep_board[i].epb_addr != IS_BASE;
402	     i++)
403	    ;
404
405	if (ep_board[i].epb_used || ep_board[i].epb_addr != IS_BASE)
406	    return 0;
407
408	if (inw(IS_BASE + EP_W0_EEPROM_COMMAND) & EEPROM_TST_MODE) {
409	    printf("ep%d: 3c5x9 at 0x%x in PnP mode. Disable PnP mode!\n",
410		   is->id_unit, IS_BASE);
411	}
412	ep_board[i].epb_used = 1;
413
414	return &ep_board[i];
415    }
416}
417
418/*
419 * get_e: gets a 16 bits word from the EEPROM. we must have set the window
420 * before
421 */
422u_int16_t
423get_e(sc, offset)
424    struct ep_softc *sc;
425    int offset;
426{
427    if (!eeprom_rdy(sc))
428	return (0xffff);
429    outw(BASE + EP_W0_EEPROM_COMMAND, EEPROM_CMD_RD | offset);
430    if (!eeprom_rdy(sc))
431	return (0xffff);
432    return (inw(BASE + EP_W0_EEPROM_DATA));
433}
434
435struct ep_softc *
436ep_alloc(unit, epb)
437    int	unit;
438    struct	ep_board *epb;
439{
440    struct	ep_softc *sc;
441
442    if (unit >= NEP) {
443	printf("ep: unit number (%d) too high\n", unit);
444	return NULL;
445    }
446
447    /*
448     * Allocate a storage area for us
449     */
450    if (ep_softc[unit]) {
451	printf("ep%d: unit number already allocated to another "
452	       "adaptor\n", unit);
453	return NULL;
454    }
455
456    sc = malloc(sizeof(struct ep_softc), M_DEVBUF, M_NOWAIT);
457    if (!sc) {
458	printf("ep%d: cannot malloc!\n", unit);
459	return NULL;
460    }
461    bzero(sc, sizeof(struct ep_softc));
462    ep_softc[unit] = sc;
463    sc->unit = unit;
464    sc->ep_io_addr = epb->epb_addr;
465    sc->epb = epb;
466
467    return(sc);
468}
469
470void
471ep_free(sc)
472    struct ep_softc *sc;
473{
474    ep_softc[sc->unit] = NULL;
475    free(sc, M_DEVBUF);
476    return;
477}
478
479int
480ep_isa_probe(is)
481    struct isa_device *is;
482{
483    struct ep_softc *sc;
484    struct ep_board *epb;
485    u_short k;
486
487    if ((epb = ep_look_for_board_at(is)) == 0)
488	return (0);
489
490    /*
491     * Allocate a storage area for us
492     */
493    sc = ep_alloc(ep_unit, epb);
494    if (!sc)
495	return (0);
496
497    is->id_unit = ep_unit++;
498
499    /*
500     * The iobase was found and MFG_ID was 0x6d50. PROD_ID should be
501     * 0x9[0-f]50	(IBM-PC)
502     * 0x9[0-f]5[0-f]	(PC-98)
503     */
504    GO_WINDOW(0);
505    k = sc->epb->prod_id;
506#ifdef PC98
507    if ((k & 0xf0f0) != (PROD_ID & 0xf0f0)) {
508#else
509    if ((k & 0xf0ff) != (PROD_ID & 0xf0ff)) {
510#endif
511	printf("ep_isa_probe: ignoring model %04x\n", k);
512	ep_free(sc);
513	return (0);
514    }
515
516    k = sc->epb->res_cfg;
517
518    k >>= 12;
519
520    /* Now we have two cases again:
521     *
522     *  1. Device was configured with 'irq?'
523     *      In this case we use irq read from the board
524     *
525     *  2. Device was configured with 'irq xxx'
526     *      In this case we set up the board to use specified interrupt
527     *
528     */
529
530    if (is->id_irq == 0) { /* irq? */
531	is->id_irq = 1 << ((k == 2) ? 9 : k);
532    }
533
534    sc->stat = 0;	/* 16 bit access */
535
536    /* By now, the adapter is already activated */
537
538    return (EP_IOSIZE);		/* 16 bytes of I/O space used. */
539}
540
541static int
542ep_isa_attach(is)
543    struct isa_device *is;
544{
545    struct ep_softc *sc = ep_softc[is->id_unit];
546    u_short config;
547    int irq;
548
549    sc->ep_connectors = 0;
550    config = inw(IS_BASE + EP_W0_CONFIG_CTRL);
551    if (config & IS_AUI) {
552	sc->ep_connectors |= AUI;
553    }
554    if (config & IS_BNC) {
555	sc->ep_connectors |= BNC;
556    }
557    if (config & IS_UTP) {
558	sc->ep_connectors |= UTP;
559    }
560    if (!(sc->ep_connectors & 7))
561	printf("no connectors!");
562    sc->ep_connector = inw(BASE + EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
563    /*
564     * Write IRQ value to board
565     */
566
567    irq = ffs(is->id_irq) - 1;
568    if (irq == -1) {
569	printf(" invalid irq... cannot attach\n");
570	return 0;
571    }
572
573    GO_WINDOW(0);
574    SET_IRQ(BASE, irq);
575
576    ep_attach(sc);
577    return 1;
578}
579
580int
581ep_attach(sc)
582    struct ep_softc *sc;
583{
584    struct ifnet *ifp = &sc->arpcom.ac_if;
585    u_short *p;
586    int i;
587    int attached;
588
589    sc->gone = 0;
590    attached = (ifp->if_softc != 0);
591
592    printf("ep%d: ", sc->unit);
593    /*
594     * Current media type
595     */
596    if (sc->ep_connectors & AUI) {
597	printf("aui");
598	if (sc->ep_connectors & ~AUI)
599		printf("/");
600    }
601    if (sc->ep_connectors & UTP) {
602	printf("utp");
603	if (sc->ep_connectors & BNC)
604		printf("/");
605    }
606    if (sc->ep_connectors & BNC) {
607	printf("bnc");
608    }
609
610    printf("[*%s*]", ep_conn_type[sc->ep_connector]);
611
612    /*
613     * Setup the station address
614     */
615    p = (u_short *) & sc->arpcom.ac_enaddr;
616    GO_WINDOW(2);
617    for (i = 0; i < 3; i++) {
618	p[i] = htons(sc->epb->eth_addr[i]);
619	outw(BASE + EP_W2_ADDR_0 + (i * 2), ntohs(p[i]));
620    }
621    printf(" address %6D\n", sc->arpcom.ac_enaddr, ":");
622
623    ifp->if_softc = sc;
624    ifp->if_unit = sc->unit;
625    ifp->if_name = "ep";
626    ifp->if_mtu = ETHERMTU;
627    ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
628    ifp->if_output = ether_output;
629    ifp->if_start = epstart;
630    ifp->if_ioctl = epioctl;
631    ifp->if_watchdog = epwatchdog;
632
633    if (!attached) {
634	if_attach(ifp);
635	ether_ifattach(ifp);
636    }
637
638#ifdef EP_LOCAL_STATS
639    sc->rx_no_first = sc->rx_no_mbuf =
640	sc->rx_bpf_disc = sc->rx_overrunf = sc->rx_overrunl =
641	sc->tx_underrun = 0;
642#endif
643    ep_fset(F_RX_FIRST);
644    sc->top = sc->mcur = 0;
645
646#if NBPFILTER > 0
647    if (!attached) {
648	bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
649    }
650#endif
651    return 0;
652}
653
654
655/*
656 * The order in here seems important. Otherwise we may not receive
657 * interrupts. ?!
658 */
659static void
660epinit(sc)
661    struct ep_softc *sc;
662{
663    register struct ifnet *ifp = &sc->arpcom.ac_if;
664    int s, i, j;
665
666    if (sc->gone)
667	return;
668
669	/*
670    if (ifp->if_addrlist == (struct ifaddr *) 0)
671	return;
672	*/
673
674    s = splimp();
675    while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
676
677    GO_WINDOW(0);
678    outw(BASE + EP_COMMAND, STOP_TRANSCEIVER);
679    GO_WINDOW(4);
680    outw(BASE + EP_W4_MEDIA_TYPE, DISABLE_UTP);
681    GO_WINDOW(0);
682
683    /* Disable the card */
684    outw(BASE + EP_W0_CONFIG_CTRL, 0);
685
686    /* Enable the card */
687    outw(BASE + EP_W0_CONFIG_CTRL, ENABLE_DRQ_IRQ);
688
689    GO_WINDOW(2);
690
691    /* Reload the ether_addr. */
692    for (i = 0; i < 6; i++)
693	outb(BASE + EP_W2_ADDR_0 + i, sc->arpcom.ac_enaddr[i]);
694
695    outw(BASE + EP_COMMAND, RX_RESET);
696    outw(BASE + EP_COMMAND, TX_RESET);
697    while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
698
699    /* Window 1 is operating window */
700    GO_WINDOW(1);
701    for (i = 0; i < 31; i++)
702	inb(BASE + EP_W1_TX_STATUS);
703
704    /* get rid of stray intr's */
705    outw(BASE + EP_COMMAND, ACK_INTR | 0xff);
706
707    outw(BASE + EP_COMMAND, SET_RD_0_MASK | S_5_INTS);
708
709    outw(BASE + EP_COMMAND, SET_INTR_MASK | S_5_INTS);
710
711    if (ifp->if_flags & IFF_PROMISC)
712	outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
713	 FIL_GROUP | FIL_BRDCST | FIL_ALL);
714    else
715	outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
716	 FIL_GROUP | FIL_BRDCST);
717
718     /*
719      * S.B.
720      *
721      * Now behavior was slightly changed:
722      *
723      * if any of flags link[0-2] is used and its connector is
724      * physically present the following connectors are used:
725      *
726      *   link0 - AUI * highest precedence
727      *   link1 - BNC
728      *   link2 - UTP * lowest precedence
729      *
730      * If none of them is specified then
731      * connector specified in the EEPROM is used
732      * (if present on card or AUI if not).
733      *
734      */
735
736    /* Set the xcvr. */
737    if (ifp->if_flags & IFF_LINK0 && sc->ep_connectors & AUI) {
738	i = ACF_CONNECTOR_AUI;
739    } else if (ifp->if_flags & IFF_LINK1 && sc->ep_connectors & BNC) {
740	i = ACF_CONNECTOR_BNC;
741    } else if (ifp->if_flags & IFF_LINK2 && sc->ep_connectors & UTP) {
742	i = ACF_CONNECTOR_UTP;
743    } else {
744	i = sc->ep_connector;
745    }
746    GO_WINDOW(0);
747    j = inw(BASE + EP_W0_ADDRESS_CFG) & 0x3fff;
748    outw(BASE + EP_W0_ADDRESS_CFG, j | (i << ACF_CONNECTOR_BITS));
749
750    switch(i) {
751      case ACF_CONNECTOR_UTP:
752	if (sc->ep_connectors & UTP) {
753	    GO_WINDOW(4);
754	    outw(BASE + EP_W4_MEDIA_TYPE, ENABLE_UTP);
755	}
756	break;
757      case ACF_CONNECTOR_BNC:
758	if (sc->ep_connectors & BNC) {
759	    outw(BASE + EP_COMMAND, START_TRANSCEIVER);
760	    DELAY(1000);
761	}
762	break;
763      case ACF_CONNECTOR_AUI:
764	/* nothing to do */
765	break;
766      default:
767	printf("ep%d: strange connector type in EEPROM: assuming AUI\n",
768	       sc->unit);
769	break;
770    }
771
772    outw(BASE + EP_COMMAND, RX_ENABLE);
773    outw(BASE + EP_COMMAND, TX_ENABLE);
774
775    ifp->if_flags |= IFF_RUNNING;
776    ifp->if_flags &= ~IFF_OACTIVE;	/* just in case */
777
778#ifdef EP_LOCAL_STATS
779    sc->rx_no_first = sc->rx_no_mbuf =
780	sc->rx_bpf_disc = sc->rx_overrunf = sc->rx_overrunl =
781	sc->tx_underrun = 0;
782#endif
783    ep_fset(F_RX_FIRST);
784    if (sc->top) {
785	m_freem(sc->top);
786	sc->top = sc->mcur = 0;
787    }
788    outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
789    outw(BASE + EP_COMMAND, SET_TX_START_THRESH | 16);
790
791    /*
792     * Store up a bunch of mbuf's for use later. (MAX_MBS). First we free up
793     * any that we had in case we're being called from intr or somewhere
794     * else.
795     */
796
797    GO_WINDOW(1);
798    epstart(ifp);
799
800    splx(s);
801}
802
803static const char padmap[] = {0, 3, 2, 1};
804
805static void
806epstart(ifp)
807    struct ifnet *ifp;
808{
809    register struct ep_softc *sc = ifp->if_softc;
810    register u_int len;
811    register struct mbuf *m;
812    struct mbuf *top;
813    int s, pad;
814
815    if (sc->gone) {
816	return;
817    }
818
819    s = splimp();
820    while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
821    if (ifp->if_flags & IFF_OACTIVE) {
822	splx(s);
823	return;
824    }
825startagain:
826    /* Sneak a peek at the next packet */
827    m = ifp->if_snd.ifq_head;
828    if (m == 0) {
829	splx(s);
830	return;
831    }
832    for (len = 0, top = m; m; m = m->m_next)
833	len += m->m_len;
834
835    pad = padmap[len & 3];
836
837    /*
838     * The 3c509 automatically pads short packets to minimum ethernet length,
839     * but we drop packets that are too large. Perhaps we should truncate
840     * them instead?
841     */
842    if (len + pad > ETHER_MAX_LEN) {
843	/* packet is obviously too large: toss it */
844	++ifp->if_oerrors;
845	IF_DEQUEUE(&ifp->if_snd, m);
846	m_freem(m);
847	goto readcheck;
848    }
849    if (inw(BASE + EP_W1_FREE_TX) < len + pad + 4) {
850	/* no room in FIFO */
851	outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
852	/* make sure */
853	if (inw(BASE + EP_W1_FREE_TX) < len + pad + 4) {
854	    ifp->if_flags |= IFF_OACTIVE;
855	    splx(s);
856	    return;
857	}
858    }
859    IF_DEQUEUE(&ifp->if_snd, m);
860
861    outw(BASE + EP_W1_TX_PIO_WR_1, len);
862    outw(BASE + EP_W1_TX_PIO_WR_1, 0x0);	/* Second dword meaningless */
863
864    for (top = m; m != 0; m = m->m_next)
865	if (ep_ftst(F_ACCESS_32_BITS)) {
866	    outsl(BASE + EP_W1_TX_PIO_WR_1, mtod(m, caddr_t),
867		  m->m_len / 4);
868	    if (m->m_len & 3)
869		outsb(BASE + EP_W1_TX_PIO_WR_1,
870		      mtod(m, caddr_t) + (m->m_len & (~3)),
871		      m->m_len & 3);
872	} else {
873	    outsw(BASE + EP_W1_TX_PIO_WR_1, mtod(m, caddr_t), m->m_len / 2);
874	    if (m->m_len & 1)
875		outb(BASE + EP_W1_TX_PIO_WR_1,
876		     *(mtod(m, caddr_t) + m->m_len - 1));
877	}
878
879    while (pad--)
880	outb(BASE + EP_W1_TX_PIO_WR_1, 0);	/* Padding */
881
882#if NBPFILTER > 0
883    if (ifp->if_bpf) {
884	bpf_mtap(ifp, top);
885    }
886#endif
887
888    ifp->if_timer = 2;
889    ifp->if_opackets++;
890    m_freem(top);
891
892    /*
893     * Is another packet coming in? We don't want to overflow the tiny RX
894     * fifo.
895     */
896readcheck:
897    if (inw(BASE + EP_W1_RX_STATUS) & RX_BYTES_MASK) {
898	/*
899	 * we check if we have packets left, in that case we prepare to come
900	 * back later
901	 */
902	if (ifp->if_snd.ifq_head) {
903	    outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
904	}
905	splx(s);
906	return;
907    }
908    goto startagain;
909}
910
911void
912epintr(unit)
913    int unit;
914{
915    register struct ep_softc *sc = ep_softc[unit];
916
917    if (sc->gone) {
918	return;
919    }
920
921    ep_intr(sc);
922}
923
924void
925ep_intr(arg)
926    void *arg;
927{
928    struct ep_softc *sc;
929    register int status;
930    struct ifnet *ifp;
931    int x;
932
933    x = splbio();
934
935    sc = (struct ep_softc *)arg;
936
937    ifp = &sc->arpcom.ac_if;
938
939    outw(BASE + EP_COMMAND, SET_INTR_MASK); /* disable all Ints */
940
941rescan:
942
943    while ((status = inw(BASE + EP_STATUS)) & S_5_INTS) {
944
945	/* first acknowledge all interrupt sources */
946	outw(BASE + EP_COMMAND, ACK_INTR | (status & S_MASK));
947
948	if (status & (S_RX_COMPLETE | S_RX_EARLY)) {
949	    epread(sc);
950	    continue;
951	}
952	if (status & S_TX_AVAIL) {
953	    /* we need ACK */
954	    ifp->if_timer = 0;
955	    ifp->if_flags &= ~IFF_OACTIVE;
956	    GO_WINDOW(1);
957	    inw(BASE + EP_W1_FREE_TX);
958	    epstart(ifp);
959	}
960	if (status & S_CARD_FAILURE) {
961	    ifp->if_timer = 0;
962#ifdef EP_LOCAL_STATS
963	    printf("\nep%d:\n\tStatus: %x\n", sc->unit, status);
964	    GO_WINDOW(4);
965	    printf("\tFIFO Diagnostic: %x\n", inw(BASE + EP_W4_FIFO_DIAG));
966	    printf("\tStat: %x\n", sc->stat);
967	    printf("\tIpackets=%d, Opackets=%d\n",
968		ifp->if_ipackets, ifp->if_opackets);
969	    printf("\tNOF=%d, NOMB=%d, BPFD=%d, RXOF=%d, RXOL=%d, TXU=%d\n",
970		   sc->rx_no_first, sc->rx_no_mbuf, sc->rx_bpf_disc, sc->rx_overrunf,
971		   sc->rx_overrunl, sc->tx_underrun);
972#else
973
974#ifdef DIAGNOSTIC
975	    printf("ep%d: Status: %x (input buffer overflow)\n", sc->unit, status);
976#else
977	    ++ifp->if_ierrors;
978#endif
979
980#endif
981	    epinit(sc);
982	    splx(x);
983	    return;
984	}
985	if (status & S_TX_COMPLETE) {
986	    ifp->if_timer = 0;
987	    /* we  need ACK. we do it at the end */
988	    /*
989	     * We need to read TX_STATUS until we get a 0 status in order to
990	     * turn off the interrupt flag.
991	     */
992	    while ((status = inb(BASE + EP_W1_TX_STATUS)) & TXS_COMPLETE) {
993		if (status & TXS_SUCCES_INTR_REQ);
994		else if (status & (TXS_UNDERRUN | TXS_JABBER | TXS_MAX_COLLISION)) {
995		    outw(BASE + EP_COMMAND, TX_RESET);
996		    if (status & TXS_UNDERRUN) {
997#ifdef EP_LOCAL_STATS
998			sc->tx_underrun++;
999#endif
1000		    } else {
1001			if (status & TXS_JABBER);
1002			else	/* TXS_MAX_COLLISION - we shouldn't get here */
1003			    ++ifp->if_collisions;
1004		    }
1005		    ++ifp->if_oerrors;
1006		    outw(BASE + EP_COMMAND, TX_ENABLE);
1007		    /*
1008		     * To have a tx_avail_int but giving the chance to the
1009		     * Reception
1010		     */
1011		    if (ifp->if_snd.ifq_head) {
1012			outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
1013		    }
1014		}
1015		outb(BASE + EP_W1_TX_STATUS, 0x0);	/* pops up the next
1016							 * status */
1017	    }			/* while */
1018	    ifp->if_flags &= ~IFF_OACTIVE;
1019	    GO_WINDOW(1);
1020	    inw(BASE + EP_W1_FREE_TX);
1021	    epstart(ifp);
1022	}			/* end TX_COMPLETE */
1023    }
1024
1025    outw(BASE + EP_COMMAND, C_INTR_LATCH);	/* ACK int Latch */
1026
1027    if ((status = inw(BASE + EP_STATUS)) & S_5_INTS)
1028	goto rescan;
1029
1030    /* re-enable Ints */
1031    outw(BASE + EP_COMMAND, SET_INTR_MASK | S_5_INTS);
1032
1033    splx(x);
1034}
1035
1036static void
1037epread(sc)
1038    register struct ep_softc *sc;
1039{
1040    struct ether_header *eh;
1041    struct mbuf *top, *mcur, *m;
1042    struct ifnet *ifp;
1043    int lenthisone;
1044
1045    short rx_fifo2, status;
1046    register short rx_fifo;
1047
1048    ifp = &sc->arpcom.ac_if;
1049    status = inw(BASE + EP_W1_RX_STATUS);
1050
1051read_again:
1052
1053    if (status & ERR_RX) {
1054	++ifp->if_ierrors;
1055	if (status & ERR_RX_OVERRUN) {
1056	    /*
1057	     * we can think the rx latency is actually greather than we
1058	     * expect
1059	     */
1060#ifdef EP_LOCAL_STATS
1061	    if (ep_ftst(F_RX_FIRST))
1062		sc->rx_overrunf++;
1063	    else
1064		sc->rx_overrunl++;
1065#endif
1066	}
1067	goto out;
1068    }
1069    rx_fifo = rx_fifo2 = status & RX_BYTES_MASK;
1070
1071    if (ep_ftst(F_RX_FIRST)) {
1072	MGETHDR(m, M_DONTWAIT, MT_DATA);
1073	if (!m)
1074	    goto out;
1075	if (rx_fifo >= MINCLSIZE)
1076	    MCLGET(m, M_DONTWAIT);
1077	sc->top = sc->mcur = top = m;
1078#define EROUND  ((sizeof(struct ether_header) + 3) & ~3)
1079#define EOFF    (EROUND - sizeof(struct ether_header))
1080	top->m_data += EOFF;
1081
1082	/* Read what should be the header. */
1083	insw(BASE + EP_W1_RX_PIO_RD_1,
1084	     mtod(top, caddr_t), sizeof(struct ether_header) / 2);
1085	top->m_len = sizeof(struct ether_header);
1086	rx_fifo -= sizeof(struct ether_header);
1087	sc->cur_len = rx_fifo2;
1088    } else {
1089	/* come here if we didn't have a complete packet last time */
1090	top = sc->top;
1091	m = sc->mcur;
1092	sc->cur_len += rx_fifo2;
1093    }
1094
1095    /* Reads what is left in the RX FIFO */
1096    while (rx_fifo > 0) {
1097	lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
1098	if (lenthisone == 0) {	/* no room in this one */
1099	    mcur = m;
1100	    MGET(m, M_DONTWAIT, MT_DATA);
1101	    if (!m)
1102		goto out;
1103	    if (rx_fifo >= MINCLSIZE)
1104		MCLGET(m, M_DONTWAIT);
1105	    m->m_len = 0;
1106	    mcur->m_next = m;
1107	    lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
1108	}
1109	if (ep_ftst(F_ACCESS_32_BITS)) { /* default for EISA configured cards*/
1110	    insl(BASE + EP_W1_RX_PIO_RD_1, mtod(m, caddr_t) + m->m_len,
1111		 lenthisone / 4);
1112	    m->m_len += (lenthisone & ~3);
1113	    if (lenthisone & 3)
1114		insb(BASE + EP_W1_RX_PIO_RD_1,
1115		     mtod(m, caddr_t) + m->m_len,
1116		     lenthisone & 3);
1117	    m->m_len += (lenthisone & 3);
1118	} else {
1119	    insw(BASE + EP_W1_RX_PIO_RD_1, mtod(m, caddr_t) + m->m_len,
1120		 lenthisone / 2);
1121	    m->m_len += lenthisone;
1122	    if (lenthisone & 1)
1123		*(mtod(m, caddr_t) + m->m_len - 1) = inb(BASE + EP_W1_RX_PIO_RD_1);
1124	}
1125	rx_fifo -= lenthisone;
1126    }
1127
1128    if (status & ERR_RX_INCOMPLETE) {	/* we haven't received the complete
1129					 * packet */
1130	sc->mcur = m;
1131#ifdef EP_LOCAL_STATS
1132	sc->rx_no_first++;	/* to know how often we come here */
1133#endif
1134	ep_frst(F_RX_FIRST);
1135	if (!((status = inw(BASE + EP_W1_RX_STATUS)) & ERR_RX_INCOMPLETE)) {
1136	    /* we see if by now, the packet has completly arrived */
1137	    goto read_again;
1138	}
1139	outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_NEXT_EARLY_THRESH);
1140	return;
1141    }
1142    outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
1143    ++ifp->if_ipackets;
1144    ep_fset(F_RX_FIRST);
1145    top->m_pkthdr.rcvif = &sc->arpcom.ac_if;
1146    top->m_pkthdr.len = sc->cur_len;
1147
1148#if NBPFILTER > 0
1149    if (ifp->if_bpf) {
1150	bpf_mtap(ifp, top);
1151
1152	/*
1153	 * Note that the interface cannot be in promiscuous mode if there are
1154	 * no BPF listeners.  And if we are in promiscuous mode, we have to
1155	 * check if this packet is really ours.
1156	 */
1157	eh = mtod(top, struct ether_header *);
1158	if ((ifp->if_flags & IFF_PROMISC) &&
1159	    (eh->ether_dhost[0] & 1) == 0 &&
1160	    bcmp(eh->ether_dhost, sc->arpcom.ac_enaddr,
1161		 sizeof(eh->ether_dhost)) != 0 &&
1162	    bcmp(eh->ether_dhost, etherbroadcastaddr,
1163		 sizeof(eh->ether_dhost)) != 0) {
1164	    if (sc->top) {
1165		m_freem(sc->top);
1166		sc->top = 0;
1167	    }
1168	    ep_fset(F_RX_FIRST);
1169#ifdef EP_LOCAL_STATS
1170	    sc->rx_bpf_disc++;
1171#endif
1172	    while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
1173	    outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
1174	    return;
1175	}
1176    }
1177#endif
1178
1179    eh = mtod(top, struct ether_header *);
1180    m_adj(top, sizeof(struct ether_header));
1181    ether_input(ifp, eh, top);
1182    sc->top = 0;
1183    while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
1184    outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
1185    return;
1186
1187out:
1188    outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
1189    if (sc->top) {
1190	m_freem(sc->top);
1191	sc->top = 0;
1192#ifdef EP_LOCAL_STATS
1193	sc->rx_no_mbuf++;
1194#endif
1195    }
1196    ep_fset(F_RX_FIRST);
1197    while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
1198    outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
1199}
1200
1201/*
1202 * Look familiar?
1203 */
1204static int
1205epioctl(ifp, cmd, data)
1206    register struct ifnet *ifp;
1207    int cmd;
1208    caddr_t data;
1209{
1210    register struct ifaddr *ifa = (struct ifaddr *) data;
1211    struct ep_softc *sc = ifp->if_softc;
1212    struct ifreq *ifr = (struct ifreq *) data;
1213    int s, error = 0;
1214
1215    s = splimp();
1216
1217    switch (cmd) {
1218      case SIOCSIFADDR:
1219	ifp->if_flags |= IFF_UP;
1220
1221	/* netifs are BUSY when UP */
1222
1223	switch (ifa->ifa_addr->sa_family) {
1224#ifdef INET
1225	  case AF_INET:
1226	    epinit(sc);	/* before arpwhohas */
1227	    arp_ifinit((struct arpcom *)ifp, ifa);
1228	    break;
1229#endif
1230#ifdef IPX
1231	  case AF_IPX:
1232	    {
1233		register struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
1234
1235		if (ipx_nullhost(*ina))
1236		    ina->x_host =
1237			*(union ipx_host *) (sc->arpcom.ac_enaddr);
1238		else {
1239		    ifp->if_flags &= ~IFF_RUNNING;
1240		    bcopy((caddr_t) ina->x_host.c_host,
1241			  (caddr_t) sc->arpcom.ac_enaddr,
1242			  sizeof(sc->arpcom.ac_enaddr));
1243		}
1244		epinit(sc);
1245		break;
1246	    }
1247#endif
1248#ifdef NS
1249	  case AF_NS:
1250	    {
1251		register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
1252
1253		if (ns_nullhost(*ina))
1254		    ina->x_host =
1255			*(union ns_host *) (sc->arpcom.ac_enaddr);
1256		else {
1257		    ifp->if_flags &= ~IFF_RUNNING;
1258		    bcopy((caddr_t) ina->x_host.c_host,
1259			  (caddr_t) sc->arpcom.ac_enaddr,
1260			  sizeof(sc->arpcom.ac_enaddr));
1261		}
1262		epinit(sc);
1263		break;
1264	    }
1265#endif
1266	  default:
1267	    epinit(sc);
1268	    break;
1269	}
1270	break;
1271      case SIOCGIFADDR:
1272	{
1273	  struct sockaddr *sa;
1274
1275	  sa = (struct sockaddr *) & ifr->ifr_data;
1276	  bcopy((caddr_t) sc->arpcom.ac_enaddr,
1277		(caddr_t) sa->sa_data, ETHER_ADDR_LEN);
1278	}
1279	break;
1280      case SIOCSIFFLAGS:
1281
1282	if ((ifp->if_flags & IFF_UP) == 0 && ifp->if_flags & IFF_RUNNING) {
1283	    ifp->if_flags &= ~IFF_RUNNING;
1284	    epstop(sc);
1285	    break;
1286	} else {
1287	    /* reinitialize card on any parameter change */
1288	    epinit(sc);
1289	    break;
1290	}
1291
1292	/* NOTREACHED */
1293	break;
1294#ifdef notdef
1295      case SIOCGHWADDR:
1296	bcopy((caddr_t) sc->sc_addr, (caddr_t) & ifr->ifr_data,
1297	      sizeof(sc->sc_addr));
1298	break;
1299#endif
1300	case SIOCSIFMTU:
1301
1302		/*
1303		 * Set the interface MTU.
1304		 */
1305		if (ifr->ifr_mtu > ETHERMTU) {
1306			error = EINVAL;
1307		} else {
1308			ifp->if_mtu = ifr->ifr_mtu;
1309		}
1310		break;
1311	case SIOCADDMULTI:
1312	case SIOCDELMULTI:
1313	    /*
1314	     * The Etherlink III has no programmable multicast
1315	     * filter.  We always initialize the card to be
1316	     * promiscuous to multicast, since we're always a
1317	     * member of the ALL-SYSTEMS group, so there's no
1318	     * need to process SIOC*MULTI requests.
1319	     */
1320	    error = 0;
1321	    break;
1322      default:
1323		error = EINVAL;
1324    }
1325
1326    splx(s);
1327
1328    return (error);
1329}
1330
1331static void
1332epwatchdog(ifp)
1333    struct ifnet *ifp;
1334{
1335    struct ep_softc *sc = ifp->if_softc;
1336
1337    /*
1338    printf("ep: watchdog\n");
1339
1340    log(LOG_ERR, "ep%d: watchdog\n", ifp->if_unit);
1341    ifp->if_oerrors++;
1342    */
1343
1344    if (sc->gone) {
1345	return;
1346    }
1347
1348    ifp->if_flags &= ~IFF_OACTIVE;
1349    epstart(ifp);
1350    ep_intr(ifp->if_softc);
1351}
1352
1353static void
1354epstop(sc)
1355    struct ep_softc *sc;
1356{
1357    if (sc->gone) {
1358	return;
1359    }
1360
1361    outw(BASE + EP_COMMAND, RX_DISABLE);
1362    outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
1363    while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
1364    outw(BASE + EP_COMMAND, TX_DISABLE);
1365    outw(BASE + EP_COMMAND, STOP_TRANSCEIVER);
1366    outw(BASE + EP_COMMAND, RX_RESET);
1367    outw(BASE + EP_COMMAND, TX_RESET);
1368    while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
1369    outw(BASE + EP_COMMAND, C_INTR_LATCH);
1370    outw(BASE + EP_COMMAND, SET_RD_0_MASK);
1371    outw(BASE + EP_COMMAND, SET_INTR_MASK);
1372    outw(BASE + EP_COMMAND, SET_RX_FILTER);
1373}
1374
1375
1376#if 0
1377static int
1378send_ID_sequence(port)
1379    int port;
1380{
1381    int cx, al;
1382
1383    for (al = 0xff, cx = 0; cx < 255; cx++) {
1384	outb(port, al);
1385	al <<= 1;
1386	if (al & 0x100)
1387	    al ^= 0xcf;
1388    }
1389    return (1);
1390}
1391#endif
1392
1393
1394/*
1395 * We get eeprom data from the id_port given an offset into the eeprom.
1396 * Basically; after the ID_sequence is sent to all of the cards; they enter
1397 * the ID_CMD state where they will accept command requests. 0x80-0xbf loads
1398 * the eeprom data.  We then read the port 16 times and with every read; the
1399 * cards check for contention (ie: if one card writes a 0 bit and another
1400 * writes a 1 bit then the host sees a 0. At the end of the cycle; each card
1401 * compares the data on the bus; if there is a difference then that card goes
1402 * into ID_WAIT state again). In the meantime; one bit of data is returned in
1403 * the AX register which is conveniently returned to us by inb().  Hence; we
1404 * read 16 times getting one bit of data with each read.
1405 */
1406static int
1407get_eeprom_data(id_port, offset)
1408    int id_port;
1409    int offset;
1410{
1411    int i, data = 0;
1412    outb(id_port, 0x80 + offset);
1413    DELAY(1000);
1414    for (i = 0; i < 16; i++)
1415	data = (data << 1) | (inw(id_port) & 1);
1416    return (data);
1417}
1418
1419#endif				/* NEP > 0 */
1420