xref: /csrg-svn/sys/vax/if/if_ec.c (revision 24789)
123558Ssklower /*
223558Ssklower  * Copyright (c) 1982 Regents of the University of California.
323558Ssklower  * All rights reserved.  The Berkeley software License Agreement
423558Ssklower  * specifies the terms and conditions for redistribution.
523558Ssklower  *
6*24789Skarels  *	@(#)if_ec.c	6.12 (Berkeley) 09/16/85
723558Ssklower  */
86520Sfeldman 
96520Sfeldman #include "ec.h"
106520Sfeldman 
116520Sfeldman /*
126520Sfeldman  * 3Com Ethernet Controller interface
136520Sfeldman  */
149795Ssam #include "../machine/pte.h"
156520Sfeldman 
1617112Sbloom #include "param.h"
1717112Sbloom #include "systm.h"
1817112Sbloom #include "mbuf.h"
1917112Sbloom #include "buf.h"
2017112Sbloom #include "protosw.h"
2117112Sbloom #include "socket.h"
2217112Sbloom #include "vmmac.h"
2317112Sbloom #include "ioctl.h"
2417112Sbloom #include "errno.h"
258461Sroot 
268461Sroot #include "../net/if.h"
278461Sroot #include "../net/netisr.h"
288461Sroot #include "../net/route.h"
2923558Ssklower 
30*24789Skarels #ifdef	BBNNET
31*24789Skarels #define	INET
32*24789Skarels #endif
3323558Ssklower #ifdef INET
348417Swnj #include "../netinet/in.h"
358417Swnj #include "../netinet/in_systm.h"
3619863Skarels #include "../netinet/in_var.h"
378417Swnj #include "../netinet/ip.h"
3811574Ssam #include "../netinet/if_ether.h"
3923558Ssklower #endif
4023558Ssklower 
4119951Sbloom #ifdef PUP
428417Swnj #include "../netpup/pup.h"
4323558Ssklower #endif PUP
4423558Ssklower 
4523558Ssklower #ifdef NS
4623558Ssklower #include "../netns/ns.h"
4723558Ssklower #include "../netns/ns_if.h"
4819951Sbloom #endif
496520Sfeldman 
508461Sroot #include "../vax/cpu.h"
518461Sroot #include "../vax/mtpr.h"
5217112Sbloom #include "if_ecreg.h"
5317112Sbloom #include "if_uba.h"
548461Sroot #include "../vaxuba/ubareg.h"
558461Sroot #include "../vaxuba/ubavar.h"
568461Sroot 
5717995Skarels #if CLSIZE == 2
5817995Skarels #define ECBUFSIZE	32		/* on-board memory, clusters */
5916749Sbloom #endif
6016749Sbloom 
6117995Skarels int	ecubamem(), ecprobe(), ecattach(), ecrint(), ecxint(), eccollide();
626520Sfeldman struct	uba_device *ecinfo[NEC];
636520Sfeldman u_short ecstd[] = { 0 };
646520Sfeldman struct	uba_driver ecdriver =
6517995Skarels 	{ ecprobe, 0, ecattach, 0, ecstd, "ec", ecinfo, 0, 0, 0, ecubamem };
666520Sfeldman 
6713055Ssam int	ecinit(),ecioctl(),ecoutput(),ecreset();
688773Sroot struct	mbuf *ecget();
696520Sfeldman 
706545Sfeldman extern struct ifnet loif;
716545Sfeldman 
726520Sfeldman /*
736520Sfeldman  * Ethernet software status per interface.
746520Sfeldman  *
756520Sfeldman  * Each interface is referenced by a network interface structure,
766520Sfeldman  * es_if, which the routing code uses to locate the interface.
776520Sfeldman  * This structure contains the output queue for the interface, its address, ...
786520Sfeldman  * We also have, for each interface, a UBA interface structure, which
796520Sfeldman  * contains information about the UNIBUS resources held by the interface:
806520Sfeldman  * map registers, buffered data paths, etc.  Information is cached in this
816520Sfeldman  * structure for use by the if_uba.c routines in running the interface
826520Sfeldman  * efficiently.
836520Sfeldman  */
846520Sfeldman struct	ec_softc {
8511574Ssam 	struct	arpcom es_ac;		/* common Ethernet structures */
8611574Ssam #define	es_if	es_ac.ac_if		/* network-visible interface */
8711574Ssam #define	es_addr	es_ac.ac_enaddr		/* hardware Ethernet address */
886520Sfeldman 	struct	ifuba es_ifuba;		/* UNIBUS resources */
896520Sfeldman 	short	es_mask;		/* mask for current output delay */
906520Sfeldman 	short	es_oactive;		/* is output active? */
918773Sroot 	u_char	*es_buf[16];		/* virtual addresses of buffers */
926520Sfeldman } ec_softc[NEC];
936520Sfeldman 
9424227Ssklower #ifdef DEBUG
9524227Ssklower ether_addr(s)
9624227Ssklower char *s;
9724227Ssklower {
9824227Ssklower 
9924227Ssklower 	printf("%x:%x:%x:%x:%x:%x\n",
10024227Ssklower 		s[0]&0xff, s[1]&0xff, s[2]&0xff,
10124227Ssklower 		s[3]&0xff, s[4]&0xff, s[5]&0xff);
10224227Ssklower }
10324227Ssklower #endif
10424227Ssklower 
1056520Sfeldman /*
10617995Skarels  * Configure on-board memory for an interface.
10717995Skarels  * Called from autoconfig and after a uba reset.
10817995Skarels  * The address of the memory on the uba is supplied in the device flags.
1096520Sfeldman  */
11017995Skarels ecubamem(ui, uban)
11117995Skarels 	register struct uba_device *ui;
1126520Sfeldman {
11317995Skarels 	register caddr_t ecbuf = (caddr_t) &umem[uban][ui->ui_flags];
11417995Skarels 	register struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
1156520Sfeldman 
11617995Skarels 	/*
11717995Skarels 	 * Make sure csr is there (we run before ecprobe).
11817995Skarels 	 */
11917995Skarels 	if (badaddr((caddr_t)addr, 2))
12017995Skarels 		return (-1);
12117995Skarels #if VAX780
12217995Skarels 	if (cpu == VAX_780 && uba_hd[uban].uh_uba->uba_sr) {
12317995Skarels 		uba_hd[uban].uh_uba->uba_sr = uba_hd[uban].uh_uba->uba_sr;
12417995Skarels 		return (-1);
12517995Skarels 	}
1266520Sfeldman #endif
1276520Sfeldman 	/*
1286637Sfeldman 	 * Make sure memory is turned on
1296637Sfeldman 	 */
1306637Sfeldman 	addr->ec_rcr = EC_AROM;
1316637Sfeldman 	/*
13217995Skarels 	 * Tell the system that the board has memory here, so it won't
13317995Skarels 	 * attempt to allocate the addresses later.
1347470Sfeldman 	 */
13517995Skarels 	if (ubamem(uban, ui->ui_flags, ECBUFSIZE*CLSIZE, 1) == 0) {
13617995Skarels 		printf("ec%d: cannot reserve uba addresses\n", ui->ui_unit);
13717995Skarels 		addr->ec_rcr = EC_MDISAB;	/* disable memory */
13817995Skarels 		return (-1);
13917995Skarels 	}
1407470Sfeldman 	/*
1416520Sfeldman 	 * Check for existence of buffers on Unibus.
1426520Sfeldman 	 */
1438773Sroot 	if (badaddr((caddr_t)ecbuf, 2)) {
14417995Skarels bad:
14517995Skarels 		printf("ec%d: buffer mem not found\n", ui->ui_unit);
14617995Skarels 		(void) ubamem(uban, ui->ui_flags, ECBUFSIZE*2, 0);
1477470Sfeldman 		addr->ec_rcr = EC_MDISAB;	/* disable memory */
14817995Skarels 		return (-1);
1496520Sfeldman 	}
1507470Sfeldman #if VAX780
15117995Skarels 	if (cpu == VAX_780 && uba_hd[uban].uh_uba->uba_sr) {
15217995Skarels 		uba_hd[uban].uh_uba->uba_sr = uba_hd[uban].uh_uba->uba_sr;
15317995Skarels 		goto bad;
1547470Sfeldman 	}
1557470Sfeldman #endif
15617995Skarels 	if (ui->ui_alive == 0)		/* Only printf from autoconfig */
15717995Skarels 		printf("ec%d: mem %x-%x\n", ui->ui_unit,
15817995Skarels 			ui->ui_flags, ui->ui_flags + ECBUFSIZE*CLBYTES - 1);
15917995Skarels 	ui->ui_type = 1;		/* Memory on, allocated */
16017995Skarels 	return (0);
16117995Skarels }
1626520Sfeldman 
16317995Skarels /*
16417995Skarels  * Do output DMA to determine interface presence and
16517995Skarels  * interrupt vector.  DMA is too short to disturb other hosts.
16617995Skarels  */
16717995Skarels ecprobe(reg, ui)
16817995Skarels 	caddr_t reg;
16917995Skarels 	struct uba_device *ui;
17017995Skarels {
17117995Skarels 	register int br, cvec;		/* r11, r10 value-result */
17217995Skarels 	register struct ecdevice *addr = (struct ecdevice *)reg;
17317995Skarels 	register caddr_t ecbuf = (caddr_t) &umem[ui->ui_ubanum][ui->ui_flags];
17417995Skarels 
17517995Skarels #ifdef lint
17617995Skarels 	br = 0; cvec = br; br = cvec;
17717995Skarels 	ecrint(0); ecxint(0); eccollide(0);
17817995Skarels #endif
17917995Skarels 
1806520Sfeldman 	/*
18117995Skarels 	 * Check that buffer memory was found and enabled.
1826520Sfeldman 	 */
18317995Skarels 	if (ui->ui_type == 0)
18417995Skarels 		return(0);
1856520Sfeldman 	/*
1866520Sfeldman 	 * Make a one byte packet in what should be buffer #0.
18717995Skarels 	 * Submit it for sending.  This should cause an xmit interrupt.
1886520Sfeldman 	 * The xmit interrupt vector is 8 bytes after the receive vector,
1896520Sfeldman 	 * so adjust for this before returning.
1906520Sfeldman 	 */
1916520Sfeldman 	*(u_short *)ecbuf = (u_short) 03777;
1926520Sfeldman 	ecbuf[03777] = '\0';
1936520Sfeldman 	addr->ec_xcr = EC_XINTEN|EC_XWBN;
1946520Sfeldman 	DELAY(100000);
1956520Sfeldman 	addr->ec_xcr = EC_XCLR;
1967216Ssam 	if (cvec > 0 && cvec != 0x200) {
1977470Sfeldman 		if (cvec & 04) {	/* collision interrupt */
1987470Sfeldman 			cvec -= 04;
1997470Sfeldman 			br += 1;		/* rcv is collision + 1 */
2007470Sfeldman 		} else {		/* xmit interrupt */
2017470Sfeldman 			cvec -= 010;
2027470Sfeldman 			br += 2;		/* rcv is xmit + 2 */
2037470Sfeldman 		}
2047216Ssam 	}
2056520Sfeldman 	return (1);
2066520Sfeldman }
2076520Sfeldman 
2086520Sfeldman /*
2096520Sfeldman  * Interface exists: make available by filling in network interface
2106520Sfeldman  * record.  System will initialize the interface when it is ready
2116520Sfeldman  * to accept packets.
2126520Sfeldman  */
2136520Sfeldman ecattach(ui)
2146520Sfeldman 	struct uba_device *ui;
2156520Sfeldman {
2167216Ssam 	struct ec_softc *es = &ec_softc[ui->ui_unit];
2177216Ssam 	register struct ifnet *ifp = &es->es_if;
2186520Sfeldman 	register struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
2197216Ssam 	int i, j;
2207216Ssam 	u_char *cp;
2216520Sfeldman 
2227216Ssam 	ifp->if_unit = ui->ui_unit;
2237216Ssam 	ifp->if_name = "ec";
2249745Ssam 	ifp->if_mtu = ETHERMTU;
2256520Sfeldman 
2266520Sfeldman 	/*
2277216Ssam 	 * Read the ethernet address off the board, one nibble at a time.
2286520Sfeldman 	 */
22924227Ssklower 	addr->ec_xcr = EC_UECLR; /* zero address pointer */
2306520Sfeldman 	addr->ec_rcr = EC_AROM;
23119863Skarels 	cp = es->es_addr;
2327216Ssam #define	NEXTBIT	addr->ec_rcr = EC_AROM|EC_ASTEP; addr->ec_rcr = EC_AROM
23316217Skarels 	for (i=0; i < sizeof (es->es_addr); i++) {
2346520Sfeldman 		*cp = 0;
2356520Sfeldman 		for (j=0; j<=4; j+=4) {
2366520Sfeldman 			*cp |= ((addr->ec_rcr >> 8) & 0xf) << j;
2377216Ssam 			NEXTBIT; NEXTBIT; NEXTBIT; NEXTBIT;
2386520Sfeldman 		}
2396520Sfeldman 		cp++;
2406520Sfeldman 	}
24124227Ssklower #ifdef DEBUG
24224227Ssklower 	printf("ecattach %d: addr=",ui->ui_unit);
24324227Ssklower 	ether_addr(es->es_addr);
24424227Ssklower #endif
2457216Ssam 	ifp->if_init = ecinit;
24613055Ssam 	ifp->if_ioctl = ecioctl;
2477216Ssam 	ifp->if_output = ecoutput;
2488977Sroot 	ifp->if_reset = ecreset;
24919863Skarels 	ifp->if_flags = IFF_BROADCAST;
2506520Sfeldman 	for (i=0; i<16; i++)
25116749Sbloom 		es->es_buf[i]
25217995Skarels 		    = (u_char *)&umem[ui->ui_ubanum][ui->ui_flags + 2048*i];
2537216Ssam 	if_attach(ifp);
2546520Sfeldman }
2556520Sfeldman 
2566520Sfeldman /*
2576520Sfeldman  * Reset of interface after UNIBUS reset.
2586520Sfeldman  * If interface is on specified uba, reset its state.
2596520Sfeldman  */
2606520Sfeldman ecreset(unit, uban)
2616520Sfeldman 	int unit, uban;
2626520Sfeldman {
2636520Sfeldman 	register struct uba_device *ui;
2646520Sfeldman 
2656520Sfeldman 	if (unit >= NEC || (ui = ecinfo[unit]) == 0 || ui->ui_alive == 0 ||
2666520Sfeldman 	    ui->ui_ubanum != uban)
2676520Sfeldman 		return;
2686520Sfeldman 	printf(" ec%d", unit);
26916207Skarels 	ec_softc[unit].es_if.if_flags &= ~IFF_RUNNING;
2706520Sfeldman 	ecinit(unit);
2716520Sfeldman }
2726520Sfeldman 
2736520Sfeldman /*
2746520Sfeldman  * Initialization of interface; clear recorded pending
2756520Sfeldman  * operations, and reinitialize UNIBUS usage.
2766520Sfeldman  */
2776520Sfeldman ecinit(unit)
2786520Sfeldman 	int unit;
2796520Sfeldman {
2807216Ssam 	struct ec_softc *es = &ec_softc[unit];
2817216Ssam 	struct ecdevice *addr;
28211574Ssam 	register struct ifnet *ifp = &es->es_if;
28313055Ssam 	int i, s;
2846520Sfeldman 
28519863Skarels 	/* not yet, if address still unknown */
28619863Skarels 	if (ifp->if_addrlist == (struct ifaddr *)0)
28711574Ssam 		return;
28811574Ssam 
2896520Sfeldman 	/*
2907217Sfeldman 	 * Hang receive buffers and start any pending writes.
2916637Sfeldman 	 * Writing into the rcr also makes sure the memory
2926637Sfeldman 	 * is turned on.
2936520Sfeldman 	 */
29419863Skarels 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
29513055Ssam 		addr = (struct ecdevice *)ecinfo[unit]->ui_addr;
29613055Ssam 		s = splimp();
29724227Ssklower 		/*
29824227Ssklower 		 * write our ethernet address into the address recognition ROM
29924227Ssklower 		 * so we can always use the same EC_READ bits (referencing ROM),
30024227Ssklower 		 * in case we change the address sometime.
30124227Ssklower 		 * Note that this is safe here as the reciever is NOT armed.
30224227Ssklower 		 */
30324227Ssklower 		ec_setaddr(es->es_addr, unit);
30424227Ssklower 		/*
30524227Ssklower 		 * Arm the reciever
30624227Ssklower 		 */
30713055Ssam 		for (i = ECRHBF; i >= ECRLBF; i--)
30813055Ssam 			addr->ec_rcr = EC_READ | i;
30913055Ssam 		es->es_oactive = 0;
31013055Ssam 		es->es_mask = ~0;
31119863Skarels 		es->es_if.if_flags |= IFF_RUNNING;
31213055Ssam 		if (es->es_if.if_snd.ifq_head)
31313055Ssam 			ecstart(unit);
31413055Ssam 		splx(s);
31513055Ssam 	}
3166520Sfeldman }
3176520Sfeldman 
3186520Sfeldman /*
3196520Sfeldman  * Start or restart output on interface.
3206520Sfeldman  * If interface is already active, then this is a retransmit
3216545Sfeldman  * after a collision, and just restuff registers.
3226520Sfeldman  * If interface is not already active, get another datagram
3236520Sfeldman  * to send off of the interface queue, and map it to the interface
3246520Sfeldman  * before starting the output.
3256520Sfeldman  */
32617995Skarels ecstart(unit)
3276520Sfeldman {
3287216Ssam 	struct ec_softc *es = &ec_softc[unit];
3297216Ssam 	struct ecdevice *addr;
3306520Sfeldman 	struct mbuf *m;
3316520Sfeldman 
3326520Sfeldman 	if (es->es_oactive)
3336520Sfeldman 		goto restart;
3346520Sfeldman 
3356520Sfeldman 	IF_DEQUEUE(&es->es_if.if_snd, m);
3366520Sfeldman 	if (m == 0) {
3376520Sfeldman 		es->es_oactive = 0;
3386520Sfeldman 		return;
3396520Sfeldman 	}
3406520Sfeldman 	ecput(es->es_buf[ECTBF], m);
3416520Sfeldman 
3426520Sfeldman restart:
3437216Ssam 	addr = (struct ecdevice *)ecinfo[unit]->ui_addr;
3446520Sfeldman 	addr->ec_xcr = EC_WRITE|ECTBF;
3456520Sfeldman 	es->es_oactive = 1;
3466520Sfeldman }
3476520Sfeldman 
3486520Sfeldman /*
3496520Sfeldman  * Ethernet interface transmitter interrupt.
3506520Sfeldman  * Start another output if more data to send.
3516520Sfeldman  */
3526520Sfeldman ecxint(unit)
3536520Sfeldman 	int unit;
3546520Sfeldman {
3556520Sfeldman 	register struct ec_softc *es = &ec_softc[unit];
3567216Ssam 	register struct ecdevice *addr =
3577216Ssam 		(struct ecdevice *)ecinfo[unit]->ui_addr;
3586520Sfeldman 
3596520Sfeldman 	if (es->es_oactive == 0)
3606520Sfeldman 		return;
3617216Ssam 	if ((addr->ec_xcr&EC_XDONE) == 0 || (addr->ec_xcr&EC_XBN) != ECTBF) {
3627216Ssam 		printf("ec%d: stray xmit interrupt, xcr=%b\n", unit,
3637216Ssam 			addr->ec_xcr, EC_XBITS);
3647216Ssam 		es->es_oactive = 0;
3657216Ssam 		addr->ec_xcr = EC_XCLR;
3667216Ssam 		return;
3677216Ssam 	}
3686520Sfeldman 	es->es_if.if_opackets++;
3696520Sfeldman 	es->es_oactive = 0;
3706520Sfeldman 	es->es_mask = ~0;
3716520Sfeldman 	addr->ec_xcr = EC_XCLR;
3727216Ssam 	if (es->es_if.if_snd.ifq_head)
3737216Ssam 		ecstart(unit);
3746520Sfeldman }
3756520Sfeldman 
3766520Sfeldman /*
3776520Sfeldman  * Collision on ethernet interface.  Do exponential
3786520Sfeldman  * backoff, and retransmit.  If have backed off all
3796520Sfeldman  * the way print warning diagnostic, and drop packet.
3806520Sfeldman  */
3816520Sfeldman eccollide(unit)
3826520Sfeldman 	int unit;
3836520Sfeldman {
3846520Sfeldman 	struct ec_softc *es = &ec_softc[unit];
3856520Sfeldman 
3866520Sfeldman 	es->es_if.if_collisions++;
3877216Ssam 	if (es->es_oactive)
3887216Ssam 		ecdocoll(unit);
3896520Sfeldman }
3906520Sfeldman 
3916520Sfeldman ecdocoll(unit)
3926520Sfeldman 	int unit;
3936520Sfeldman {
3946520Sfeldman 	register struct ec_softc *es = &ec_softc[unit];
3956545Sfeldman 	register struct ecdevice *addr =
3966545Sfeldman 	    (struct ecdevice *)ecinfo[unit]->ui_addr;
3976545Sfeldman 	register i;
3986545Sfeldman 	int delay;
3996520Sfeldman 
4006520Sfeldman 	/*
4016520Sfeldman 	 * Es_mask is a 16 bit number with n low zero bits, with
4026520Sfeldman 	 * n the number of backoffs.  When es_mask is 0 we have
4036520Sfeldman 	 * backed off 16 times, and give up.
4046520Sfeldman 	 */
4056520Sfeldman 	if (es->es_mask == 0) {
4066545Sfeldman 		es->es_if.if_oerrors++;
4076520Sfeldman 		printf("ec%d: send error\n", unit);
4086520Sfeldman 		/*
4096545Sfeldman 		 * Reset interface, then requeue rcv buffers.
4106545Sfeldman 		 * Some incoming packets may be lost, but that
4116545Sfeldman 		 * can't be helped.
4126520Sfeldman 		 */
4136545Sfeldman 		addr->ec_xcr = EC_UECLR;
4146545Sfeldman 		for (i=ECRHBF; i>=ECRLBF; i--)
4156545Sfeldman 			addr->ec_rcr = EC_READ|i;
4166545Sfeldman 		/*
4176545Sfeldman 		 * Reset and transmit next packet (if any).
4186545Sfeldman 		 */
4196545Sfeldman 		es->es_oactive = 0;
4206545Sfeldman 		es->es_mask = ~0;
4216545Sfeldman 		if (es->es_if.if_snd.ifq_head)
4226545Sfeldman 			ecstart(unit);
4236520Sfeldman 		return;
4246520Sfeldman 	}
4256520Sfeldman 	/*
4266545Sfeldman 	 * Do exponential backoff.  Compute delay based on low bits
4276545Sfeldman 	 * of the interval timer.  Then delay for that number of
4286545Sfeldman 	 * slot times.  A slot time is 51.2 microseconds (rounded to 51).
4296545Sfeldman 	 * This does not take into account the time already used to
4306545Sfeldman 	 * process the interrupt.
4316520Sfeldman 	 */
4326520Sfeldman 	es->es_mask <<= 1;
4336545Sfeldman 	delay = mfpr(ICR) &~ es->es_mask;
4346545Sfeldman 	DELAY(delay * 51);
4356520Sfeldman 	/*
4366545Sfeldman 	 * Clear the controller's collision flag, thus enabling retransmit.
4376520Sfeldman 	 */
4387470Sfeldman 	addr->ec_xcr = EC_CLEAR;
4396520Sfeldman }
4406520Sfeldman 
4416520Sfeldman /*
4426520Sfeldman  * Ethernet interface receiver interrupt.
4436520Sfeldman  * If input error just drop packet.
44424227Ssklower  * Otherwise examine
4456520Sfeldman  * packet to determine type.  If can't determine length
4466520Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
4476520Sfeldman  * packet based on type and pass to type specific higher-level
4486520Sfeldman  * input routine.
4496520Sfeldman  */
4506520Sfeldman ecrint(unit)
4516520Sfeldman 	int unit;
4526520Sfeldman {
4536520Sfeldman 	struct ecdevice *addr = (struct ecdevice *)ecinfo[unit]->ui_addr;
4546520Sfeldman 
4556520Sfeldman 	while (addr->ec_rcr & EC_RDONE)
4566520Sfeldman 		ecread(unit);
4576520Sfeldman }
4586520Sfeldman 
4596520Sfeldman ecread(unit)
4606520Sfeldman 	int unit;
4616520Sfeldman {
4626520Sfeldman 	register struct ec_softc *es = &ec_softc[unit];
4636520Sfeldman 	struct ecdevice *addr = (struct ecdevice *)ecinfo[unit]->ui_addr;
4649745Ssam 	register struct ether_header *ec;
4656520Sfeldman     	struct mbuf *m;
4668773Sroot 	int len, off, resid, ecoff, rbuf;
4676520Sfeldman 	register struct ifqueue *inq;
4688773Sroot 	u_char *ecbuf;
4696520Sfeldman 
4706520Sfeldman 	es->es_if.if_ipackets++;
4718773Sroot 	rbuf = addr->ec_rcr & EC_RBN;
4728773Sroot 	if (rbuf < ECRLBF || rbuf > ECRHBF)
4736520Sfeldman 		panic("ecrint");
4748773Sroot 	ecbuf = es->es_buf[rbuf];
4756520Sfeldman 	ecoff = *(short *)ecbuf;
4766545Sfeldman 	if (ecoff <= ECRDOFF || ecoff > 2046) {
4776520Sfeldman 		es->es_if.if_ierrors++;
4786520Sfeldman #ifdef notdef
4796520Sfeldman 		if (es->es_if.if_ierrors % 100 == 0)
4806520Sfeldman 			printf("ec%d: += 100 input errors\n", unit);
4816520Sfeldman #endif
4826520Sfeldman 		goto setup;
4836520Sfeldman 	}
4846520Sfeldman 
4856520Sfeldman 	/*
4866520Sfeldman 	 * Get input data length.
4876520Sfeldman 	 * Get pointer to ethernet header (in input buffer).
48819863Skarels 	 * Deal with trailer protocol: if type is trailer type
4896520Sfeldman 	 * get true type from first 16-bit word past data.
4906520Sfeldman 	 * Remember that type was trailer by setting off.
4916520Sfeldman 	 */
4929745Ssam 	len = ecoff - ECRDOFF - sizeof (struct ether_header);
4939745Ssam 	ec = (struct ether_header *)(ecbuf + ECRDOFF);
4949745Ssam 	ec->ether_type = ntohs((u_short)ec->ether_type);
4956520Sfeldman #define	ecdataaddr(ec, off, type)	((type)(((caddr_t)((ec)+1)+(off))))
49619863Skarels 	if (ec->ether_type >= ETHERTYPE_TRAIL &&
49719863Skarels 	    ec->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
49819863Skarels 		off = (ec->ether_type - ETHERTYPE_TRAIL) * 512;
4999745Ssam 		if (off >= ETHERMTU)
5006520Sfeldman 			goto setup;		/* sanity */
5019745Ssam 		ec->ether_type = ntohs(*ecdataaddr(ec, off, u_short *));
5029745Ssam 		resid = ntohs(*(ecdataaddr(ec, off+2, u_short *)));
5036520Sfeldman 		if (off + resid > len)
5046520Sfeldman 			goto setup;		/* sanity */
5056520Sfeldman 		len = off + resid;
5066520Sfeldman 	} else
5076520Sfeldman 		off = 0;
5086520Sfeldman 	if (len == 0)
5096520Sfeldman 		goto setup;
5106520Sfeldman 
5116520Sfeldman 	/*
5126520Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
5136520Sfeldman 	 * has trailing header; ecget will then force this header
5146520Sfeldman 	 * information to be at the front, but we still have to drop
5156520Sfeldman 	 * the type and length which are at the front of any trailer data.
5166520Sfeldman 	 */
517*24789Skarels 	m = ecget(ecbuf, len, off, &es->es_if);
5186520Sfeldman 	if (m == 0)
5196520Sfeldman 		goto setup;
5206520Sfeldman 	if (off) {
521*24789Skarels 		struct ifnet *ifp;
522*24789Skarels 
523*24789Skarels 		ifp = *(mtod(m, struct ifnet **));
5246520Sfeldman 		m->m_off += 2 * sizeof (u_short);
5256520Sfeldman 		m->m_len -= 2 * sizeof (u_short);
526*24789Skarels 		*(mtod(m, struct ifnet **)) = ifp;
5276520Sfeldman 	}
5289745Ssam 	switch (ec->ether_type) {
5296520Sfeldman 
5306520Sfeldman #ifdef INET
53119863Skarels 	case ETHERTYPE_IP:
5326520Sfeldman 		schednetisr(NETISR_IP);
5336520Sfeldman 		inq = &ipintrq;
5346520Sfeldman 		break;
53511574Ssam 
53619863Skarels 	case ETHERTYPE_ARP:
53711574Ssam 		arpinput(&es->es_ac, m);
53813987Ssam 		goto setup;
5396520Sfeldman #endif
54023558Ssklower #ifdef NS
54123558Ssklower 	case ETHERTYPE_NS:
54223558Ssklower 		schednetisr(NETISR_NS);
54323558Ssklower 		inq = &nsintrq;
54423558Ssklower 		break;
54523558Ssklower 
54623558Ssklower #endif
5476520Sfeldman 	default:
5486520Sfeldman 		m_freem(m);
5496520Sfeldman 		goto setup;
5506520Sfeldman 	}
5516520Sfeldman 
5526520Sfeldman 	if (IF_QFULL(inq)) {
5536520Sfeldman 		IF_DROP(inq);
5546520Sfeldman 		m_freem(m);
5557216Ssam 		goto setup;
5567216Ssam 	}
5577216Ssam 	IF_ENQUEUE(inq, m);
5586520Sfeldman 
5596520Sfeldman setup:
5606520Sfeldman 	/*
5616520Sfeldman 	 * Reset for next packet.
5626520Sfeldman 	 */
5638773Sroot 	addr->ec_rcr = EC_READ|EC_RCLR|rbuf;
5646520Sfeldman }
5656520Sfeldman 
5666520Sfeldman /*
5676520Sfeldman  * Ethernet output routine.
5686520Sfeldman  * Encapsulate a packet of type family for the local net.
5696520Sfeldman  * Use trailer local net encapsulation if enough data in first
5706520Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
5716545Sfeldman  * If destination is this address or broadcast, send packet to
5726545Sfeldman  * loop device to kludge around the fact that 3com interfaces can't
5736545Sfeldman  * talk to themselves.
5746520Sfeldman  */
5756520Sfeldman ecoutput(ifp, m0, dst)
5766520Sfeldman 	struct ifnet *ifp;
5776520Sfeldman 	struct mbuf *m0;
5786520Sfeldman 	struct sockaddr *dst;
5796520Sfeldman {
58011574Ssam 	int type, s, error;
58119863Skarels  	u_char edst[6];
58211574Ssam 	struct in_addr idst;
5836520Sfeldman 	register struct ec_softc *es = &ec_softc[ifp->if_unit];
5846520Sfeldman 	register struct mbuf *m = m0;
5859745Ssam 	register struct ether_header *ec;
58612771Ssam 	register int off;
58711574Ssam 	struct mbuf *mcopy = (struct mbuf *)0;
5886520Sfeldman 
5896520Sfeldman 	switch (dst->sa_family) {
5906520Sfeldman 
5916520Sfeldman #ifdef INET
5926520Sfeldman 	case AF_INET:
59311574Ssam 		idst = ((struct sockaddr_in *)dst)->sin_addr;
59419863Skarels 		if (!arpresolve(&es->es_ac, m, &idst, edst))
59511574Ssam 			return (0);	/* if not yet resolved */
59619863Skarels 		if (!bcmp((caddr_t)edst, (caddr_t)etherbroadcastaddr,
59719863Skarels 		    sizeof(edst)))
5988838Sroot 			mcopy = m_copy(m, 0, (int)M_COPYALL);
5996520Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
60013055Ssam 		/* need per host negotiation */
60113055Ssam 		if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
6026520Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
6036520Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
60419863Skarels 			type = ETHERTYPE_TRAIL + (off>>9);
6056520Sfeldman 			m->m_off -= 2 * sizeof (u_short);
6066520Sfeldman 			m->m_len += 2 * sizeof (u_short);
60719863Skarels 			*mtod(m, u_short *) = ntohs((u_short)ETHERTYPE_IP);
6089745Ssam 			*(mtod(m, u_short *) + 1) = ntohs((u_short)m->m_len);
6096520Sfeldman 			goto gottrailertype;
6106520Sfeldman 		}
61119863Skarels 		type = ETHERTYPE_IP;
6126520Sfeldman 		off = 0;
6136520Sfeldman 		goto gottype;
6146520Sfeldman #endif
61523558Ssklower #ifdef NS
61623558Ssklower 	case AF_NS:
61723558Ssklower  		bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
61823558Ssklower 		    (caddr_t)edst, sizeof (edst));
6196520Sfeldman 
62023558Ssklower 		if (!bcmp((caddr_t)edst, (caddr_t)&ns_broadhost,
62123558Ssklower 			sizeof(edst))) {
62223558Ssklower 
62323558Ssklower 				mcopy = m_copy(m, 0, (int)M_COPYALL);
62423558Ssklower 		} else if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost,
62523558Ssklower 			sizeof(edst))) {
62623558Ssklower 
62723558Ssklower 				return(looutput(&loif, m, dst));
62823558Ssklower 		}
62923558Ssklower 		type = ETHERTYPE_NS;
63023558Ssklower 		off = 0;
63123558Ssklower 		goto gottype;
63223558Ssklower #endif
63323558Ssklower 
63411574Ssam 	case AF_UNSPEC:
63511574Ssam 		ec = (struct ether_header *)dst->sa_data;
63619863Skarels  		bcopy((caddr_t)ec->ether_dhost, (caddr_t)edst, sizeof (edst));
63711574Ssam 		type = ec->ether_type;
63811574Ssam 		goto gottype;
63911574Ssam 
6406520Sfeldman 	default:
6416520Sfeldman 		printf("ec%d: can't handle af%d\n", ifp->if_unit,
6426520Sfeldman 			dst->sa_family);
6436520Sfeldman 		error = EAFNOSUPPORT;
6446520Sfeldman 		goto bad;
6456520Sfeldman 	}
6466520Sfeldman 
6476520Sfeldman gottrailertype:
6486520Sfeldman 	/*
6496520Sfeldman 	 * Packet to be sent as trailer: move first packet
6506520Sfeldman 	 * (control information) to end of chain.
6516520Sfeldman 	 */
6526520Sfeldman 	while (m->m_next)
6536520Sfeldman 		m = m->m_next;
6546520Sfeldman 	m->m_next = m0;
6556520Sfeldman 	m = m0->m_next;
6566520Sfeldman 	m0->m_next = 0;
6576520Sfeldman 	m0 = m;
6586520Sfeldman 
6596520Sfeldman gottype:
6606520Sfeldman 	/*
6616520Sfeldman 	 * Add local net header.  If no space in first mbuf,
6626520Sfeldman 	 * allocate another.
6636520Sfeldman 	 */
6646520Sfeldman 	if (m->m_off > MMAXOFF ||
6659745Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
6669648Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
6676520Sfeldman 		if (m == 0) {
6686520Sfeldman 			error = ENOBUFS;
6696520Sfeldman 			goto bad;
6706520Sfeldman 		}
6716520Sfeldman 		m->m_next = m0;
6726520Sfeldman 		m->m_off = MMINOFF;
6739745Ssam 		m->m_len = sizeof (struct ether_header);
6746520Sfeldman 	} else {
6759745Ssam 		m->m_off -= sizeof (struct ether_header);
6769745Ssam 		m->m_len += sizeof (struct ether_header);
6776520Sfeldman 	}
6789745Ssam 	ec = mtod(m, struct ether_header *);
67919863Skarels  	bcopy((caddr_t)edst, (caddr_t)ec->ether_dhost, sizeof (edst));
68019863Skarels 	bcopy((caddr_t)es->es_addr, (caddr_t)ec->ether_shost,
68119863Skarels 	    sizeof(ec->ether_shost));
6829745Ssam 	ec->ether_type = htons((u_short)type);
6836520Sfeldman 
6846520Sfeldman 	/*
6856520Sfeldman 	 * Queue message on interface, and start output if interface
6866520Sfeldman 	 * not yet active.
6876520Sfeldman 	 */
6886520Sfeldman 	s = splimp();
6896520Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
6906520Sfeldman 		IF_DROP(&ifp->if_snd);
6916520Sfeldman 		error = ENOBUFS;
6926520Sfeldman 		goto qfull;
6936520Sfeldman 	}
6946520Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
6956520Sfeldman 	if (es->es_oactive == 0)
6966520Sfeldman 		ecstart(ifp->if_unit);
6976520Sfeldman 	splx(s);
69812771Ssam 	return (mcopy ? looutput(&loif, mcopy, dst) : 0);
6997216Ssam 
7006520Sfeldman qfull:
7016520Sfeldman 	m0 = m;
7026520Sfeldman 	splx(s);
7036520Sfeldman bad:
7046520Sfeldman 	m_freem(m0);
70516207Skarels 	if (mcopy)
70616207Skarels 		m_freem(mcopy);
70712771Ssam 	return (error);
7086520Sfeldman }
7096520Sfeldman 
7106520Sfeldman /*
7119177Ssam  * Routine to copy from mbuf chain to transmit
7127216Ssam  * buffer in UNIBUS memory.
7139177Ssam  * If packet size is less than the minimum legal size,
7149177Ssam  * the buffer is expanded.  We probably should zero out the extra
7159177Ssam  * bytes for security, but that would slow things down.
7166520Sfeldman  */
7176520Sfeldman ecput(ecbuf, m)
7187216Ssam 	u_char *ecbuf;
7196520Sfeldman 	struct mbuf *m;
7206520Sfeldman {
7216520Sfeldman 	register struct mbuf *mp;
7227216Ssam 	register int off;
7237263Ssam 	u_char *bp;
7246520Sfeldman 
7257216Ssam 	for (off = 2048, mp = m; mp; mp = mp->m_next)
7267216Ssam 		off -= mp->m_len;
7279745Ssam 	if (2048 - off < ETHERMIN + sizeof (struct ether_header))
7289745Ssam 		off = 2048 - ETHERMIN - sizeof (struct ether_header);
7297216Ssam 	*(u_short *)ecbuf = off;
7307216Ssam 	bp = (u_char *)(ecbuf + off);
7317263Ssam 	for (mp = m; mp; mp = mp->m_next) {
7327263Ssam 		register unsigned len = mp->m_len;
7337263Ssam 		u_char *mcp;
7347216Ssam 
7357216Ssam 		if (len == 0)
7367216Ssam 			continue;
7377216Ssam 		mcp = mtod(mp, u_char *);
7387216Ssam 		if ((unsigned)bp & 01) {
7397032Swnj 			*bp++ = *mcp++;
7407216Ssam 			len--;
7417032Swnj 		}
7427263Ssam 		if (off = (len >> 1)) {
7437263Ssam 			register u_short *to, *from;
7447263Ssam 
7457263Ssam 			to = (u_short *)bp;
7467263Ssam 			from = (u_short *)mcp;
7477263Ssam 			do
7487263Ssam 				*to++ = *from++;
7497263Ssam 			while (--off > 0);
7507263Ssam 			bp = (u_char *)to,
7517263Ssam 			mcp = (u_char *)from;
7527032Swnj 		}
7537263Ssam 		if (len & 01)
7546520Sfeldman 			*bp++ = *mcp++;
7556520Sfeldman 	}
7567263Ssam 	m_freem(m);
7576520Sfeldman }
7586520Sfeldman 
7596520Sfeldman /*
7606520Sfeldman  * Routine to copy from UNIBUS memory into mbufs.
7616520Sfeldman  * Similar in spirit to if_rubaget.
7627032Swnj  *
7637032Swnj  * Warning: This makes the fairly safe assumption that
7647032Swnj  * mbufs have even lengths.
7656520Sfeldman  */
7666520Sfeldman struct mbuf *
767*24789Skarels ecget(ecbuf, totlen, off0, ifp)
7687263Ssam 	u_char *ecbuf;
7696520Sfeldman 	int totlen, off0;
770*24789Skarels 	struct ifnet *ifp;
7716520Sfeldman {
7727263Ssam 	register struct mbuf *m;
7737263Ssam 	struct mbuf *top = 0, **mp = &top;
7747263Ssam 	register int off = off0, len;
7757263Ssam 	u_char *cp;
7766520Sfeldman 
7779745Ssam 	cp = ecbuf + ECRDOFF + sizeof (struct ether_header);
7786520Sfeldman 	while (totlen > 0) {
7797263Ssam 		register int words;
7807263Ssam 		u_char *mcp;
7817263Ssam 
7829648Ssam 		MGET(m, M_DONTWAIT, MT_DATA);
7836520Sfeldman 		if (m == 0)
7846520Sfeldman 			goto bad;
7856520Sfeldman 		if (off) {
7866520Sfeldman 			len = totlen - off;
7879745Ssam 			cp = ecbuf + ECRDOFF +
7889745Ssam 				sizeof (struct ether_header) + off;
7896520Sfeldman 		} else
7906520Sfeldman 			len = totlen;
791*24789Skarels 		if (ifp)
792*24789Skarels 			len += sizeof(ifp);
793*24789Skarels 		if (len >= NBPG) {
7946520Sfeldman 			struct mbuf *p;
7956520Sfeldman 
7966520Sfeldman 			MCLGET(p, 1);
7976520Sfeldman 			if (p != 0) {
798*24789Skarels 				m->m_len = len = MIN(len, CLBYTES);
7996520Sfeldman 				m->m_off = (int)p - (int)m;
8006520Sfeldman 			} else {
8016520Sfeldman 				m->m_len = len = MIN(MLEN, len);
8026520Sfeldman 				m->m_off = MMINOFF;
8036520Sfeldman 			}
8046520Sfeldman 		} else {
8056520Sfeldman 			m->m_len = len = MIN(MLEN, len);
8066520Sfeldman 			m->m_off = MMINOFF;
8076520Sfeldman 		}
8087263Ssam 		mcp = mtod(m, u_char *);
809*24789Skarels 		if (ifp) {
810*24789Skarels 			/*
811*24789Skarels 			 * Prepend interface pointer to first mbuf.
812*24789Skarels 			 */
813*24789Skarels 			*(mtod(m, struct ifnet **)) = ifp;
814*24789Skarels 			mcp += sizeof(ifp);
815*24789Skarels 			len -= sizeof(ifp);
816*24789Skarels 			ifp = (struct ifnet *)0;
817*24789Skarels 		}
8187263Ssam 		if (words = (len >> 1)) {
8197263Ssam 			register u_short *to, *from;
8207263Ssam 
8217263Ssam 			to = (u_short *)mcp;
8227263Ssam 			from = (u_short *)cp;
8237263Ssam 			do
8247263Ssam 				*to++ = *from++;
8257263Ssam 			while (--words > 0);
8267263Ssam 			mcp = (u_char *)to;
8277263Ssam 			cp = (u_char *)from;
8287032Swnj 		}
8297216Ssam 		if (len & 01)
8306520Sfeldman 			*mcp++ = *cp++;
8316520Sfeldman 		*mp = m;
8326520Sfeldman 		mp = &m->m_next;
8337263Ssam 		if (off == 0) {
8346520Sfeldman 			totlen -= len;
8357263Ssam 			continue;
8367263Ssam 		}
8377263Ssam 		off += len;
8387263Ssam 		if (off == totlen) {
8399745Ssam 			cp = ecbuf + ECRDOFF + sizeof (struct ether_header);
8407263Ssam 			off = 0;
8417263Ssam 			totlen = off0;
8427263Ssam 		}
8436520Sfeldman 	}
8446520Sfeldman 	return (top);
8456520Sfeldman bad:
8466520Sfeldman 	m_freem(top);
8476520Sfeldman 	return (0);
8486520Sfeldman }
84913055Ssam 
85013055Ssam /*
85113055Ssam  * Process an ioctl request.
85213055Ssam  */
85313055Ssam ecioctl(ifp, cmd, data)
85413055Ssam 	register struct ifnet *ifp;
85513055Ssam 	int cmd;
85613055Ssam 	caddr_t data;
85713055Ssam {
85819863Skarels 	register struct ifaddr *ifa = (struct ifaddr *)data;
85913055Ssam 	int s = splimp(), error = 0;
86013055Ssam 
86113055Ssam 	switch (cmd) {
86213055Ssam 
86313055Ssam 	case SIOCSIFADDR:
86419863Skarels 		ifp->if_flags |= IFF_UP;
86519863Skarels 
86619863Skarels 		switch (ifa->ifa_addr.sa_family) {
86723558Ssklower #ifdef INET
86819863Skarels 		case AF_INET:
86924227Ssklower 			ecinit(ifp->if_unit); /* before, so we can send the ARP packet */
87019863Skarels 			((struct arpcom *)ifp)->ac_ipaddr =
87119863Skarels 				IA_SIN(ifa)->sin_addr;
87219863Skarels 			arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
87319863Skarels 			break;
87423558Ssklower #endif
87523558Ssklower #ifdef NS
87623558Ssklower 		case AF_NS:
87723558Ssklower 		    {
87823558Ssklower 			register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
87923558Ssklower 
88023558Ssklower 			if (ns_nullhost(*ina)) {
88123558Ssklower 				ina->x_host = * (union ns_host *)
88223558Ssklower 				     (ec_softc[ifp->if_unit].es_addr);
88323558Ssklower 			} else {
88424227Ssklower 				/*
88524227Ssklower 				 * The manual says we can't change the address
88624227Ssklower 				 * while the reciever is armed so reset everything
88724227Ssklower 				 */
88824227Ssklower 				struct ec_softc *es = &ec_softc[ifp->if_unit];
88924227Ssklower 				struct uba_device *ui = ecinfo[ifp->if_unit];
89024227Ssklower 				struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
89124227Ssklower 
89224227Ssklower 				es->es_if.if_flags &= ~IFF_RUNNING;
89324227Ssklower 				bcopy(ina->x_host.c_host, es->es_addr, sizeof(es->es_addr));
89423558Ssklower 			}
89524227Ssklower 			ecinit(ifp->if_unit); /* does ec_setaddr() */
89623558Ssklower 			break;
89723558Ssklower 		    }
89823558Ssklower #endif
89919863Skarels 		}
90013055Ssam 		break;
90113055Ssam 
90213055Ssam 	default:
90313055Ssam 		error = EINVAL;
90413055Ssam 	}
90513055Ssam 	splx(s);
90613055Ssam 	return (error);
90713055Ssam }
90823558Ssklower 
90923558Ssklower ec_setaddr(physaddr,unit)
91023558Ssklower u_char *physaddr;
91123558Ssklower int unit;
91223558Ssklower {
91323558Ssklower 	struct ec_softc *es = &ec_softc[unit];
91423558Ssklower 	struct uba_device *ui = ecinfo[unit];
91523558Ssklower 	register struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
91623558Ssklower 	register char nibble;
91723558Ssklower 	register int i, j;
918*24789Skarels 
91923558Ssklower 	/*
92023558Ssklower 	 * Use the ethernet address supplied
92124227Ssklower 	 * NOte that we do a UECLR here, so the recieve buffers
92224227Ssklower 	 * must be requeued.
92323558Ssklower 	 */
92423558Ssklower 
92524227Ssklower #ifdef DEBUG
92624227Ssklower 	printf("ec_setaddr: setting address for unit %d = ",
92724227Ssklower 		unit);
92824227Ssklower 	ether_addr(physaddr);
92924227Ssklower #endif
93024227Ssklower 	addr->ec_xcr = EC_UECLR;
93123558Ssklower 	addr->ec_rcr = 0;
93224227Ssklower 	/* load requested address */
93323558Ssklower 	for (i = 0; i < 6; i++) { /* 6 bytes of address */
93423558Ssklower 	    es->es_addr[i] = physaddr[i];
93523558Ssklower 	    nibble = physaddr[i] & 0xf; /* lower nibble */
93623558Ssklower 	    addr->ec_rcr = (nibble << 8);
93724227Ssklower 	    addr->ec_rcr = (nibble << 8) + EC_AWCLK; /* latch nibble */
93823558Ssklower 	    addr->ec_rcr = (nibble << 8);
93923558Ssklower 	    for (j=0; j < 4; j++) {
94023558Ssklower 		addr->ec_rcr = 0;
94123558Ssklower 		addr->ec_rcr = EC_ASTEP; /* step counter */
94223558Ssklower 		addr->ec_rcr = 0;
94323558Ssklower 	    }
94423558Ssklower 	    nibble = (physaddr[i] >> 4) & 0xf; /* upper nibble */
94523558Ssklower 	    addr->ec_rcr = (nibble << 8);
94624227Ssklower 	    addr->ec_rcr = (nibble << 8) + EC_AWCLK; /* latch nibble */
94723558Ssklower 	    addr->ec_rcr = (nibble << 8);
94823558Ssklower 	    for (j=0; j < 4; j++) {
94923558Ssklower 		addr->ec_rcr = 0;
95023558Ssklower 		addr->ec_rcr = EC_ASTEP; /* step counter */
95123558Ssklower 		addr->ec_rcr = 0;
95223558Ssklower 	    }
95323558Ssklower 	}
95424227Ssklower #ifdef DEBUG
95524227Ssklower 	/*
95624227Ssklower 	 * Read the ethernet address off the board, one nibble at a time.
95724227Ssklower 	 */
95824227Ssklower 	addr->ec_xcr = EC_UECLR;
95924227Ssklower 	addr->ec_rcr = 0; /* read RAM */
96024227Ssklower 	cp = es->es_addr;
96124227Ssklower #undef NEXTBIT
96224227Ssklower #define	NEXTBIT	addr->ec_rcr = EC_ASTEP; addr->ec_rcr = 0
96324227Ssklower 	for (i=0; i < sizeof (es->es_addr); i++) {
96424227Ssklower 		*cp = 0;
96524227Ssklower 		for (j=0; j<=4; j+=4) {
96624227Ssklower 			*cp |= ((addr->ec_rcr >> 8) & 0xf) << j;
96724227Ssklower 			NEXTBIT; NEXTBIT; NEXTBIT; NEXTBIT;
96824227Ssklower 		}
96924227Ssklower 		cp++;
97024227Ssklower 	}
97124227Ssklower 	printf("ec_setaddr %d: ROM addr=",ui->ui_unit);
97224227Ssklower 	ether_addr(es->es_addr);
97324227Ssklower #endif
97423558Ssklower }
975