xref: /csrg-svn/sys/vax/if/if_ec.c (revision 25271)
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*25271Sbloom  *	@(#)if_ec.c	6.13 (Berkeley) 10/24/85
723558Ssklower  */
86520Sfeldman 
96520Sfeldman #include "ec.h"
10*25271Sbloom #if NEC > 0
116520Sfeldman 
126520Sfeldman /*
136520Sfeldman  * 3Com Ethernet Controller interface
146520Sfeldman  */
159795Ssam #include "../machine/pte.h"
166520Sfeldman 
1717112Sbloom #include "param.h"
1817112Sbloom #include "systm.h"
1917112Sbloom #include "mbuf.h"
2017112Sbloom #include "buf.h"
2117112Sbloom #include "protosw.h"
2217112Sbloom #include "socket.h"
2317112Sbloom #include "vmmac.h"
2417112Sbloom #include "ioctl.h"
2517112Sbloom #include "errno.h"
268461Sroot 
278461Sroot #include "../net/if.h"
288461Sroot #include "../net/netisr.h"
298461Sroot #include "../net/route.h"
3023558Ssklower 
3124789Skarels #ifdef	BBNNET
3224789Skarels #define	INET
3324789Skarels #endif
3423558Ssklower #ifdef INET
358417Swnj #include "../netinet/in.h"
368417Swnj #include "../netinet/in_systm.h"
3719863Skarels #include "../netinet/in_var.h"
388417Swnj #include "../netinet/ip.h"
3911574Ssam #include "../netinet/if_ether.h"
4023558Ssklower #endif
4123558Ssklower 
4219951Sbloom #ifdef PUP
438417Swnj #include "../netpup/pup.h"
4423558Ssklower #endif PUP
4523558Ssklower 
4623558Ssklower #ifdef NS
4723558Ssklower #include "../netns/ns.h"
4823558Ssklower #include "../netns/ns_if.h"
4919951Sbloom #endif
506520Sfeldman 
518461Sroot #include "../vax/cpu.h"
528461Sroot #include "../vax/mtpr.h"
5317112Sbloom #include "if_ecreg.h"
5417112Sbloom #include "if_uba.h"
558461Sroot #include "../vaxuba/ubareg.h"
568461Sroot #include "../vaxuba/ubavar.h"
578461Sroot 
5817995Skarels #if CLSIZE == 2
5917995Skarels #define ECBUFSIZE	32		/* on-board memory, clusters */
6016749Sbloom #endif
6116749Sbloom 
6217995Skarels int	ecubamem(), ecprobe(), ecattach(), ecrint(), ecxint(), eccollide();
636520Sfeldman struct	uba_device *ecinfo[NEC];
646520Sfeldman u_short ecstd[] = { 0 };
656520Sfeldman struct	uba_driver ecdriver =
6617995Skarels 	{ ecprobe, 0, ecattach, 0, ecstd, "ec", ecinfo, 0, 0, 0, ecubamem };
676520Sfeldman 
6813055Ssam int	ecinit(),ecioctl(),ecoutput(),ecreset();
698773Sroot struct	mbuf *ecget();
706520Sfeldman 
716545Sfeldman extern struct ifnet loif;
726545Sfeldman 
736520Sfeldman /*
746520Sfeldman  * Ethernet software status per interface.
756520Sfeldman  *
766520Sfeldman  * Each interface is referenced by a network interface structure,
776520Sfeldman  * es_if, which the routing code uses to locate the interface.
786520Sfeldman  * This structure contains the output queue for the interface, its address, ...
796520Sfeldman  * We also have, for each interface, a UBA interface structure, which
806520Sfeldman  * contains information about the UNIBUS resources held by the interface:
816520Sfeldman  * map registers, buffered data paths, etc.  Information is cached in this
826520Sfeldman  * structure for use by the if_uba.c routines in running the interface
836520Sfeldman  * efficiently.
846520Sfeldman  */
856520Sfeldman struct	ec_softc {
8611574Ssam 	struct	arpcom es_ac;		/* common Ethernet structures */
8711574Ssam #define	es_if	es_ac.ac_if		/* network-visible interface */
8811574Ssam #define	es_addr	es_ac.ac_enaddr		/* hardware Ethernet address */
896520Sfeldman 	struct	ifuba es_ifuba;		/* UNIBUS resources */
906520Sfeldman 	short	es_mask;		/* mask for current output delay */
916520Sfeldman 	short	es_oactive;		/* is output active? */
928773Sroot 	u_char	*es_buf[16];		/* virtual addresses of buffers */
936520Sfeldman } ec_softc[NEC];
946520Sfeldman 
9524227Ssklower #ifdef DEBUG
9624227Ssklower ether_addr(s)
9724227Ssklower char *s;
9824227Ssklower {
9924227Ssklower 
10024227Ssklower 	printf("%x:%x:%x:%x:%x:%x\n",
10124227Ssklower 		s[0]&0xff, s[1]&0xff, s[2]&0xff,
10224227Ssklower 		s[3]&0xff, s[4]&0xff, s[5]&0xff);
10324227Ssklower }
10424227Ssklower #endif
10524227Ssklower 
1066520Sfeldman /*
10717995Skarels  * Configure on-board memory for an interface.
10817995Skarels  * Called from autoconfig and after a uba reset.
10917995Skarels  * The address of the memory on the uba is supplied in the device flags.
1106520Sfeldman  */
11117995Skarels ecubamem(ui, uban)
11217995Skarels 	register struct uba_device *ui;
1136520Sfeldman {
11417995Skarels 	register caddr_t ecbuf = (caddr_t) &umem[uban][ui->ui_flags];
11517995Skarels 	register struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
1166520Sfeldman 
11717995Skarels 	/*
11817995Skarels 	 * Make sure csr is there (we run before ecprobe).
11917995Skarels 	 */
12017995Skarels 	if (badaddr((caddr_t)addr, 2))
12117995Skarels 		return (-1);
12217995Skarels #if VAX780
12317995Skarels 	if (cpu == VAX_780 && uba_hd[uban].uh_uba->uba_sr) {
12417995Skarels 		uba_hd[uban].uh_uba->uba_sr = uba_hd[uban].uh_uba->uba_sr;
12517995Skarels 		return (-1);
12617995Skarels 	}
1276520Sfeldman #endif
1286520Sfeldman 	/*
1296637Sfeldman 	 * Make sure memory is turned on
1306637Sfeldman 	 */
1316637Sfeldman 	addr->ec_rcr = EC_AROM;
1326637Sfeldman 	/*
13317995Skarels 	 * Tell the system that the board has memory here, so it won't
13417995Skarels 	 * attempt to allocate the addresses later.
1357470Sfeldman 	 */
13617995Skarels 	if (ubamem(uban, ui->ui_flags, ECBUFSIZE*CLSIZE, 1) == 0) {
13717995Skarels 		printf("ec%d: cannot reserve uba addresses\n", ui->ui_unit);
13817995Skarels 		addr->ec_rcr = EC_MDISAB;	/* disable memory */
13917995Skarels 		return (-1);
14017995Skarels 	}
1417470Sfeldman 	/*
1426520Sfeldman 	 * Check for existence of buffers on Unibus.
1436520Sfeldman 	 */
1448773Sroot 	if (badaddr((caddr_t)ecbuf, 2)) {
14517995Skarels bad:
14617995Skarels 		printf("ec%d: buffer mem not found\n", ui->ui_unit);
14717995Skarels 		(void) ubamem(uban, ui->ui_flags, ECBUFSIZE*2, 0);
1487470Sfeldman 		addr->ec_rcr = EC_MDISAB;	/* disable memory */
14917995Skarels 		return (-1);
1506520Sfeldman 	}
1517470Sfeldman #if VAX780
15217995Skarels 	if (cpu == VAX_780 && uba_hd[uban].uh_uba->uba_sr) {
15317995Skarels 		uba_hd[uban].uh_uba->uba_sr = uba_hd[uban].uh_uba->uba_sr;
15417995Skarels 		goto bad;
1557470Sfeldman 	}
1567470Sfeldman #endif
15717995Skarels 	if (ui->ui_alive == 0)		/* Only printf from autoconfig */
15817995Skarels 		printf("ec%d: mem %x-%x\n", ui->ui_unit,
15917995Skarels 			ui->ui_flags, ui->ui_flags + ECBUFSIZE*CLBYTES - 1);
16017995Skarels 	ui->ui_type = 1;		/* Memory on, allocated */
16117995Skarels 	return (0);
16217995Skarels }
1636520Sfeldman 
16417995Skarels /*
16517995Skarels  * Do output DMA to determine interface presence and
16617995Skarels  * interrupt vector.  DMA is too short to disturb other hosts.
16717995Skarels  */
16817995Skarels ecprobe(reg, ui)
16917995Skarels 	caddr_t reg;
17017995Skarels 	struct uba_device *ui;
17117995Skarels {
17217995Skarels 	register int br, cvec;		/* r11, r10 value-result */
17317995Skarels 	register struct ecdevice *addr = (struct ecdevice *)reg;
17417995Skarels 	register caddr_t ecbuf = (caddr_t) &umem[ui->ui_ubanum][ui->ui_flags];
17517995Skarels 
17617995Skarels #ifdef lint
17717995Skarels 	br = 0; cvec = br; br = cvec;
17817995Skarels 	ecrint(0); ecxint(0); eccollide(0);
17917995Skarels #endif
18017995Skarels 
1816520Sfeldman 	/*
18217995Skarels 	 * Check that buffer memory was found and enabled.
1836520Sfeldman 	 */
18417995Skarels 	if (ui->ui_type == 0)
18517995Skarels 		return(0);
1866520Sfeldman 	/*
1876520Sfeldman 	 * Make a one byte packet in what should be buffer #0.
18817995Skarels 	 * Submit it for sending.  This should cause an xmit interrupt.
1896520Sfeldman 	 * The xmit interrupt vector is 8 bytes after the receive vector,
1906520Sfeldman 	 * so adjust for this before returning.
1916520Sfeldman 	 */
1926520Sfeldman 	*(u_short *)ecbuf = (u_short) 03777;
1936520Sfeldman 	ecbuf[03777] = '\0';
1946520Sfeldman 	addr->ec_xcr = EC_XINTEN|EC_XWBN;
1956520Sfeldman 	DELAY(100000);
1966520Sfeldman 	addr->ec_xcr = EC_XCLR;
1977216Ssam 	if (cvec > 0 && cvec != 0x200) {
1987470Sfeldman 		if (cvec & 04) {	/* collision interrupt */
1997470Sfeldman 			cvec -= 04;
2007470Sfeldman 			br += 1;		/* rcv is collision + 1 */
2017470Sfeldman 		} else {		/* xmit interrupt */
2027470Sfeldman 			cvec -= 010;
2037470Sfeldman 			br += 2;		/* rcv is xmit + 2 */
2047470Sfeldman 		}
2057216Ssam 	}
2066520Sfeldman 	return (1);
2076520Sfeldman }
2086520Sfeldman 
2096520Sfeldman /*
2106520Sfeldman  * Interface exists: make available by filling in network interface
2116520Sfeldman  * record.  System will initialize the interface when it is ready
2126520Sfeldman  * to accept packets.
2136520Sfeldman  */
2146520Sfeldman ecattach(ui)
2156520Sfeldman 	struct uba_device *ui;
2166520Sfeldman {
2177216Ssam 	struct ec_softc *es = &ec_softc[ui->ui_unit];
2187216Ssam 	register struct ifnet *ifp = &es->es_if;
2196520Sfeldman 	register struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
2207216Ssam 	int i, j;
2217216Ssam 	u_char *cp;
2226520Sfeldman 
2237216Ssam 	ifp->if_unit = ui->ui_unit;
2247216Ssam 	ifp->if_name = "ec";
2259745Ssam 	ifp->if_mtu = ETHERMTU;
2266520Sfeldman 
2276520Sfeldman 	/*
2287216Ssam 	 * Read the ethernet address off the board, one nibble at a time.
2296520Sfeldman 	 */
23024227Ssklower 	addr->ec_xcr = EC_UECLR; /* zero address pointer */
2316520Sfeldman 	addr->ec_rcr = EC_AROM;
23219863Skarels 	cp = es->es_addr;
2337216Ssam #define	NEXTBIT	addr->ec_rcr = EC_AROM|EC_ASTEP; addr->ec_rcr = EC_AROM
23416217Skarels 	for (i=0; i < sizeof (es->es_addr); i++) {
2356520Sfeldman 		*cp = 0;
2366520Sfeldman 		for (j=0; j<=4; j+=4) {
2376520Sfeldman 			*cp |= ((addr->ec_rcr >> 8) & 0xf) << j;
2387216Ssam 			NEXTBIT; NEXTBIT; NEXTBIT; NEXTBIT;
2396520Sfeldman 		}
2406520Sfeldman 		cp++;
2416520Sfeldman 	}
24224227Ssklower #ifdef DEBUG
24324227Ssklower 	printf("ecattach %d: addr=",ui->ui_unit);
24424227Ssklower 	ether_addr(es->es_addr);
24524227Ssklower #endif
2467216Ssam 	ifp->if_init = ecinit;
24713055Ssam 	ifp->if_ioctl = ecioctl;
2487216Ssam 	ifp->if_output = ecoutput;
2498977Sroot 	ifp->if_reset = ecreset;
25019863Skarels 	ifp->if_flags = IFF_BROADCAST;
2516520Sfeldman 	for (i=0; i<16; i++)
25216749Sbloom 		es->es_buf[i]
25317995Skarels 		    = (u_char *)&umem[ui->ui_ubanum][ui->ui_flags + 2048*i];
2547216Ssam 	if_attach(ifp);
2556520Sfeldman }
2566520Sfeldman 
2576520Sfeldman /*
2586520Sfeldman  * Reset of interface after UNIBUS reset.
2596520Sfeldman  * If interface is on specified uba, reset its state.
2606520Sfeldman  */
2616520Sfeldman ecreset(unit, uban)
2626520Sfeldman 	int unit, uban;
2636520Sfeldman {
2646520Sfeldman 	register struct uba_device *ui;
2656520Sfeldman 
2666520Sfeldman 	if (unit >= NEC || (ui = ecinfo[unit]) == 0 || ui->ui_alive == 0 ||
2676520Sfeldman 	    ui->ui_ubanum != uban)
2686520Sfeldman 		return;
2696520Sfeldman 	printf(" ec%d", unit);
27016207Skarels 	ec_softc[unit].es_if.if_flags &= ~IFF_RUNNING;
2716520Sfeldman 	ecinit(unit);
2726520Sfeldman }
2736520Sfeldman 
2746520Sfeldman /*
2756520Sfeldman  * Initialization of interface; clear recorded pending
2766520Sfeldman  * operations, and reinitialize UNIBUS usage.
2776520Sfeldman  */
2786520Sfeldman ecinit(unit)
2796520Sfeldman 	int unit;
2806520Sfeldman {
2817216Ssam 	struct ec_softc *es = &ec_softc[unit];
2827216Ssam 	struct ecdevice *addr;
28311574Ssam 	register struct ifnet *ifp = &es->es_if;
28413055Ssam 	int i, s;
2856520Sfeldman 
28619863Skarels 	/* not yet, if address still unknown */
28719863Skarels 	if (ifp->if_addrlist == (struct ifaddr *)0)
28811574Ssam 		return;
28911574Ssam 
2906520Sfeldman 	/*
2917217Sfeldman 	 * Hang receive buffers and start any pending writes.
2926637Sfeldman 	 * Writing into the rcr also makes sure the memory
2936637Sfeldman 	 * is turned on.
2946520Sfeldman 	 */
29519863Skarels 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
29613055Ssam 		addr = (struct ecdevice *)ecinfo[unit]->ui_addr;
29713055Ssam 		s = splimp();
29824227Ssklower 		/*
29924227Ssklower 		 * write our ethernet address into the address recognition ROM
30024227Ssklower 		 * so we can always use the same EC_READ bits (referencing ROM),
30124227Ssklower 		 * in case we change the address sometime.
30224227Ssklower 		 * Note that this is safe here as the reciever is NOT armed.
30324227Ssklower 		 */
30424227Ssklower 		ec_setaddr(es->es_addr, unit);
30524227Ssklower 		/*
30624227Ssklower 		 * Arm the reciever
30724227Ssklower 		 */
30813055Ssam 		for (i = ECRHBF; i >= ECRLBF; i--)
30913055Ssam 			addr->ec_rcr = EC_READ | i;
31013055Ssam 		es->es_oactive = 0;
31113055Ssam 		es->es_mask = ~0;
31219863Skarels 		es->es_if.if_flags |= IFF_RUNNING;
31313055Ssam 		if (es->es_if.if_snd.ifq_head)
31413055Ssam 			ecstart(unit);
31513055Ssam 		splx(s);
31613055Ssam 	}
3176520Sfeldman }
3186520Sfeldman 
3196520Sfeldman /*
3206520Sfeldman  * Start or restart output on interface.
3216520Sfeldman  * If interface is already active, then this is a retransmit
3226545Sfeldman  * after a collision, and just restuff registers.
3236520Sfeldman  * If interface is not already active, get another datagram
3246520Sfeldman  * to send off of the interface queue, and map it to the interface
3256520Sfeldman  * before starting the output.
3266520Sfeldman  */
32717995Skarels ecstart(unit)
3286520Sfeldman {
3297216Ssam 	struct ec_softc *es = &ec_softc[unit];
3307216Ssam 	struct ecdevice *addr;
3316520Sfeldman 	struct mbuf *m;
3326520Sfeldman 
3336520Sfeldman 	if (es->es_oactive)
3346520Sfeldman 		goto restart;
3356520Sfeldman 
3366520Sfeldman 	IF_DEQUEUE(&es->es_if.if_snd, m);
3376520Sfeldman 	if (m == 0) {
3386520Sfeldman 		es->es_oactive = 0;
3396520Sfeldman 		return;
3406520Sfeldman 	}
3416520Sfeldman 	ecput(es->es_buf[ECTBF], m);
3426520Sfeldman 
3436520Sfeldman restart:
3447216Ssam 	addr = (struct ecdevice *)ecinfo[unit]->ui_addr;
3456520Sfeldman 	addr->ec_xcr = EC_WRITE|ECTBF;
3466520Sfeldman 	es->es_oactive = 1;
3476520Sfeldman }
3486520Sfeldman 
3496520Sfeldman /*
3506520Sfeldman  * Ethernet interface transmitter interrupt.
3516520Sfeldman  * Start another output if more data to send.
3526520Sfeldman  */
3536520Sfeldman ecxint(unit)
3546520Sfeldman 	int unit;
3556520Sfeldman {
3566520Sfeldman 	register struct ec_softc *es = &ec_softc[unit];
3577216Ssam 	register struct ecdevice *addr =
3587216Ssam 		(struct ecdevice *)ecinfo[unit]->ui_addr;
3596520Sfeldman 
3606520Sfeldman 	if (es->es_oactive == 0)
3616520Sfeldman 		return;
3627216Ssam 	if ((addr->ec_xcr&EC_XDONE) == 0 || (addr->ec_xcr&EC_XBN) != ECTBF) {
3637216Ssam 		printf("ec%d: stray xmit interrupt, xcr=%b\n", unit,
3647216Ssam 			addr->ec_xcr, EC_XBITS);
3657216Ssam 		es->es_oactive = 0;
3667216Ssam 		addr->ec_xcr = EC_XCLR;
3677216Ssam 		return;
3687216Ssam 	}
3696520Sfeldman 	es->es_if.if_opackets++;
3706520Sfeldman 	es->es_oactive = 0;
3716520Sfeldman 	es->es_mask = ~0;
3726520Sfeldman 	addr->ec_xcr = EC_XCLR;
3737216Ssam 	if (es->es_if.if_snd.ifq_head)
3747216Ssam 		ecstart(unit);
3756520Sfeldman }
3766520Sfeldman 
3776520Sfeldman /*
3786520Sfeldman  * Collision on ethernet interface.  Do exponential
3796520Sfeldman  * backoff, and retransmit.  If have backed off all
3806520Sfeldman  * the way print warning diagnostic, and drop packet.
3816520Sfeldman  */
3826520Sfeldman eccollide(unit)
3836520Sfeldman 	int unit;
3846520Sfeldman {
3856520Sfeldman 	struct ec_softc *es = &ec_softc[unit];
3866520Sfeldman 
3876520Sfeldman 	es->es_if.if_collisions++;
3887216Ssam 	if (es->es_oactive)
3897216Ssam 		ecdocoll(unit);
3906520Sfeldman }
3916520Sfeldman 
3926520Sfeldman ecdocoll(unit)
3936520Sfeldman 	int unit;
3946520Sfeldman {
3956520Sfeldman 	register struct ec_softc *es = &ec_softc[unit];
3966545Sfeldman 	register struct ecdevice *addr =
3976545Sfeldman 	    (struct ecdevice *)ecinfo[unit]->ui_addr;
3986545Sfeldman 	register i;
3996545Sfeldman 	int delay;
4006520Sfeldman 
4016520Sfeldman 	/*
4026520Sfeldman 	 * Es_mask is a 16 bit number with n low zero bits, with
4036520Sfeldman 	 * n the number of backoffs.  When es_mask is 0 we have
4046520Sfeldman 	 * backed off 16 times, and give up.
4056520Sfeldman 	 */
4066520Sfeldman 	if (es->es_mask == 0) {
4076545Sfeldman 		es->es_if.if_oerrors++;
4086520Sfeldman 		printf("ec%d: send error\n", unit);
4096520Sfeldman 		/*
4106545Sfeldman 		 * Reset interface, then requeue rcv buffers.
4116545Sfeldman 		 * Some incoming packets may be lost, but that
4126545Sfeldman 		 * can't be helped.
4136520Sfeldman 		 */
4146545Sfeldman 		addr->ec_xcr = EC_UECLR;
4156545Sfeldman 		for (i=ECRHBF; i>=ECRLBF; i--)
4166545Sfeldman 			addr->ec_rcr = EC_READ|i;
4176545Sfeldman 		/*
4186545Sfeldman 		 * Reset and transmit next packet (if any).
4196545Sfeldman 		 */
4206545Sfeldman 		es->es_oactive = 0;
4216545Sfeldman 		es->es_mask = ~0;
4226545Sfeldman 		if (es->es_if.if_snd.ifq_head)
4236545Sfeldman 			ecstart(unit);
4246520Sfeldman 		return;
4256520Sfeldman 	}
4266520Sfeldman 	/*
4276545Sfeldman 	 * Do exponential backoff.  Compute delay based on low bits
4286545Sfeldman 	 * of the interval timer.  Then delay for that number of
4296545Sfeldman 	 * slot times.  A slot time is 51.2 microseconds (rounded to 51).
4306545Sfeldman 	 * This does not take into account the time already used to
4316545Sfeldman 	 * process the interrupt.
4326520Sfeldman 	 */
4336520Sfeldman 	es->es_mask <<= 1;
4346545Sfeldman 	delay = mfpr(ICR) &~ es->es_mask;
4356545Sfeldman 	DELAY(delay * 51);
4366520Sfeldman 	/*
4376545Sfeldman 	 * Clear the controller's collision flag, thus enabling retransmit.
4386520Sfeldman 	 */
4397470Sfeldman 	addr->ec_xcr = EC_CLEAR;
4406520Sfeldman }
4416520Sfeldman 
4426520Sfeldman /*
4436520Sfeldman  * Ethernet interface receiver interrupt.
4446520Sfeldman  * If input error just drop packet.
44524227Ssklower  * Otherwise examine
4466520Sfeldman  * packet to determine type.  If can't determine length
4476520Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
4486520Sfeldman  * packet based on type and pass to type specific higher-level
4496520Sfeldman  * input routine.
4506520Sfeldman  */
4516520Sfeldman ecrint(unit)
4526520Sfeldman 	int unit;
4536520Sfeldman {
4546520Sfeldman 	struct ecdevice *addr = (struct ecdevice *)ecinfo[unit]->ui_addr;
4556520Sfeldman 
4566520Sfeldman 	while (addr->ec_rcr & EC_RDONE)
4576520Sfeldman 		ecread(unit);
4586520Sfeldman }
4596520Sfeldman 
4606520Sfeldman ecread(unit)
4616520Sfeldman 	int unit;
4626520Sfeldman {
4636520Sfeldman 	register struct ec_softc *es = &ec_softc[unit];
4646520Sfeldman 	struct ecdevice *addr = (struct ecdevice *)ecinfo[unit]->ui_addr;
4659745Ssam 	register struct ether_header *ec;
4666520Sfeldman     	struct mbuf *m;
4678773Sroot 	int len, off, resid, ecoff, rbuf;
4686520Sfeldman 	register struct ifqueue *inq;
4698773Sroot 	u_char *ecbuf;
4706520Sfeldman 
4716520Sfeldman 	es->es_if.if_ipackets++;
4728773Sroot 	rbuf = addr->ec_rcr & EC_RBN;
4738773Sroot 	if (rbuf < ECRLBF || rbuf > ECRHBF)
4746520Sfeldman 		panic("ecrint");
4758773Sroot 	ecbuf = es->es_buf[rbuf];
4766520Sfeldman 	ecoff = *(short *)ecbuf;
4776545Sfeldman 	if (ecoff <= ECRDOFF || ecoff > 2046) {
4786520Sfeldman 		es->es_if.if_ierrors++;
4796520Sfeldman #ifdef notdef
4806520Sfeldman 		if (es->es_if.if_ierrors % 100 == 0)
4816520Sfeldman 			printf("ec%d: += 100 input errors\n", unit);
4826520Sfeldman #endif
4836520Sfeldman 		goto setup;
4846520Sfeldman 	}
4856520Sfeldman 
4866520Sfeldman 	/*
4876520Sfeldman 	 * Get input data length.
4886520Sfeldman 	 * Get pointer to ethernet header (in input buffer).
48919863Skarels 	 * Deal with trailer protocol: if type is trailer type
4906520Sfeldman 	 * get true type from first 16-bit word past data.
4916520Sfeldman 	 * Remember that type was trailer by setting off.
4926520Sfeldman 	 */
4939745Ssam 	len = ecoff - ECRDOFF - sizeof (struct ether_header);
4949745Ssam 	ec = (struct ether_header *)(ecbuf + ECRDOFF);
4959745Ssam 	ec->ether_type = ntohs((u_short)ec->ether_type);
4966520Sfeldman #define	ecdataaddr(ec, off, type)	((type)(((caddr_t)((ec)+1)+(off))))
49719863Skarels 	if (ec->ether_type >= ETHERTYPE_TRAIL &&
49819863Skarels 	    ec->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
49919863Skarels 		off = (ec->ether_type - ETHERTYPE_TRAIL) * 512;
5009745Ssam 		if (off >= ETHERMTU)
5016520Sfeldman 			goto setup;		/* sanity */
5029745Ssam 		ec->ether_type = ntohs(*ecdataaddr(ec, off, u_short *));
5039745Ssam 		resid = ntohs(*(ecdataaddr(ec, off+2, u_short *)));
5046520Sfeldman 		if (off + resid > len)
5056520Sfeldman 			goto setup;		/* sanity */
5066520Sfeldman 		len = off + resid;
5076520Sfeldman 	} else
5086520Sfeldman 		off = 0;
5096520Sfeldman 	if (len == 0)
5106520Sfeldman 		goto setup;
5116520Sfeldman 
5126520Sfeldman 	/*
5136520Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
5146520Sfeldman 	 * has trailing header; ecget will then force this header
5156520Sfeldman 	 * information to be at the front, but we still have to drop
5166520Sfeldman 	 * the type and length which are at the front of any trailer data.
5176520Sfeldman 	 */
51824789Skarels 	m = ecget(ecbuf, len, off, &es->es_if);
5196520Sfeldman 	if (m == 0)
5206520Sfeldman 		goto setup;
5216520Sfeldman 	if (off) {
52224789Skarels 		struct ifnet *ifp;
52324789Skarels 
52424789Skarels 		ifp = *(mtod(m, struct ifnet **));
5256520Sfeldman 		m->m_off += 2 * sizeof (u_short);
5266520Sfeldman 		m->m_len -= 2 * sizeof (u_short);
52724789Skarels 		*(mtod(m, struct ifnet **)) = ifp;
5286520Sfeldman 	}
5299745Ssam 	switch (ec->ether_type) {
5306520Sfeldman 
5316520Sfeldman #ifdef INET
53219863Skarels 	case ETHERTYPE_IP:
5336520Sfeldman 		schednetisr(NETISR_IP);
5346520Sfeldman 		inq = &ipintrq;
5356520Sfeldman 		break;
53611574Ssam 
53719863Skarels 	case ETHERTYPE_ARP:
53811574Ssam 		arpinput(&es->es_ac, m);
53913987Ssam 		goto setup;
5406520Sfeldman #endif
54123558Ssklower #ifdef NS
54223558Ssklower 	case ETHERTYPE_NS:
54323558Ssklower 		schednetisr(NETISR_NS);
54423558Ssklower 		inq = &nsintrq;
54523558Ssklower 		break;
54623558Ssklower 
54723558Ssklower #endif
5486520Sfeldman 	default:
5496520Sfeldman 		m_freem(m);
5506520Sfeldman 		goto setup;
5516520Sfeldman 	}
5526520Sfeldman 
5536520Sfeldman 	if (IF_QFULL(inq)) {
5546520Sfeldman 		IF_DROP(inq);
5556520Sfeldman 		m_freem(m);
5567216Ssam 		goto setup;
5577216Ssam 	}
5587216Ssam 	IF_ENQUEUE(inq, m);
5596520Sfeldman 
5606520Sfeldman setup:
5616520Sfeldman 	/*
5626520Sfeldman 	 * Reset for next packet.
5636520Sfeldman 	 */
5648773Sroot 	addr->ec_rcr = EC_READ|EC_RCLR|rbuf;
5656520Sfeldman }
5666520Sfeldman 
5676520Sfeldman /*
5686520Sfeldman  * Ethernet output routine.
5696520Sfeldman  * Encapsulate a packet of type family for the local net.
5706520Sfeldman  * Use trailer local net encapsulation if enough data in first
5716520Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
5726545Sfeldman  * If destination is this address or broadcast, send packet to
5736545Sfeldman  * loop device to kludge around the fact that 3com interfaces can't
5746545Sfeldman  * talk to themselves.
5756520Sfeldman  */
5766520Sfeldman ecoutput(ifp, m0, dst)
5776520Sfeldman 	struct ifnet *ifp;
5786520Sfeldman 	struct mbuf *m0;
5796520Sfeldman 	struct sockaddr *dst;
5806520Sfeldman {
58111574Ssam 	int type, s, error;
58219863Skarels  	u_char edst[6];
58311574Ssam 	struct in_addr idst;
5846520Sfeldman 	register struct ec_softc *es = &ec_softc[ifp->if_unit];
5856520Sfeldman 	register struct mbuf *m = m0;
5869745Ssam 	register struct ether_header *ec;
58712771Ssam 	register int off;
58811574Ssam 	struct mbuf *mcopy = (struct mbuf *)0;
5896520Sfeldman 
5906520Sfeldman 	switch (dst->sa_family) {
5916520Sfeldman 
5926520Sfeldman #ifdef INET
5936520Sfeldman 	case AF_INET:
59411574Ssam 		idst = ((struct sockaddr_in *)dst)->sin_addr;
59519863Skarels 		if (!arpresolve(&es->es_ac, m, &idst, edst))
59611574Ssam 			return (0);	/* if not yet resolved */
59719863Skarels 		if (!bcmp((caddr_t)edst, (caddr_t)etherbroadcastaddr,
59819863Skarels 		    sizeof(edst)))
5998838Sroot 			mcopy = m_copy(m, 0, (int)M_COPYALL);
6006520Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
60113055Ssam 		/* need per host negotiation */
60213055Ssam 		if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
6036520Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
6046520Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
60519863Skarels 			type = ETHERTYPE_TRAIL + (off>>9);
6066520Sfeldman 			m->m_off -= 2 * sizeof (u_short);
6076520Sfeldman 			m->m_len += 2 * sizeof (u_short);
60819863Skarels 			*mtod(m, u_short *) = ntohs((u_short)ETHERTYPE_IP);
6099745Ssam 			*(mtod(m, u_short *) + 1) = ntohs((u_short)m->m_len);
6106520Sfeldman 			goto gottrailertype;
6116520Sfeldman 		}
61219863Skarels 		type = ETHERTYPE_IP;
6136520Sfeldman 		off = 0;
6146520Sfeldman 		goto gottype;
6156520Sfeldman #endif
61623558Ssklower #ifdef NS
61723558Ssklower 	case AF_NS:
61823558Ssklower  		bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
61923558Ssklower 		    (caddr_t)edst, sizeof (edst));
6206520Sfeldman 
62123558Ssklower 		if (!bcmp((caddr_t)edst, (caddr_t)&ns_broadhost,
62223558Ssklower 			sizeof(edst))) {
62323558Ssklower 
62423558Ssklower 				mcopy = m_copy(m, 0, (int)M_COPYALL);
62523558Ssklower 		} else if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost,
62623558Ssklower 			sizeof(edst))) {
62723558Ssklower 
62823558Ssklower 				return(looutput(&loif, m, dst));
62923558Ssklower 		}
63023558Ssklower 		type = ETHERTYPE_NS;
63123558Ssklower 		off = 0;
63223558Ssklower 		goto gottype;
63323558Ssklower #endif
63423558Ssklower 
63511574Ssam 	case AF_UNSPEC:
63611574Ssam 		ec = (struct ether_header *)dst->sa_data;
63719863Skarels  		bcopy((caddr_t)ec->ether_dhost, (caddr_t)edst, sizeof (edst));
63811574Ssam 		type = ec->ether_type;
63911574Ssam 		goto gottype;
64011574Ssam 
6416520Sfeldman 	default:
6426520Sfeldman 		printf("ec%d: can't handle af%d\n", ifp->if_unit,
6436520Sfeldman 			dst->sa_family);
6446520Sfeldman 		error = EAFNOSUPPORT;
6456520Sfeldman 		goto bad;
6466520Sfeldman 	}
6476520Sfeldman 
6486520Sfeldman gottrailertype:
6496520Sfeldman 	/*
6506520Sfeldman 	 * Packet to be sent as trailer: move first packet
6516520Sfeldman 	 * (control information) to end of chain.
6526520Sfeldman 	 */
6536520Sfeldman 	while (m->m_next)
6546520Sfeldman 		m = m->m_next;
6556520Sfeldman 	m->m_next = m0;
6566520Sfeldman 	m = m0->m_next;
6576520Sfeldman 	m0->m_next = 0;
6586520Sfeldman 	m0 = m;
6596520Sfeldman 
6606520Sfeldman gottype:
6616520Sfeldman 	/*
6626520Sfeldman 	 * Add local net header.  If no space in first mbuf,
6636520Sfeldman 	 * allocate another.
6646520Sfeldman 	 */
6656520Sfeldman 	if (m->m_off > MMAXOFF ||
6669745Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
6679648Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
6686520Sfeldman 		if (m == 0) {
6696520Sfeldman 			error = ENOBUFS;
6706520Sfeldman 			goto bad;
6716520Sfeldman 		}
6726520Sfeldman 		m->m_next = m0;
6736520Sfeldman 		m->m_off = MMINOFF;
6749745Ssam 		m->m_len = sizeof (struct ether_header);
6756520Sfeldman 	} else {
6769745Ssam 		m->m_off -= sizeof (struct ether_header);
6779745Ssam 		m->m_len += sizeof (struct ether_header);
6786520Sfeldman 	}
6799745Ssam 	ec = mtod(m, struct ether_header *);
68019863Skarels  	bcopy((caddr_t)edst, (caddr_t)ec->ether_dhost, sizeof (edst));
68119863Skarels 	bcopy((caddr_t)es->es_addr, (caddr_t)ec->ether_shost,
68219863Skarels 	    sizeof(ec->ether_shost));
6839745Ssam 	ec->ether_type = htons((u_short)type);
6846520Sfeldman 
6856520Sfeldman 	/*
6866520Sfeldman 	 * Queue message on interface, and start output if interface
6876520Sfeldman 	 * not yet active.
6886520Sfeldman 	 */
6896520Sfeldman 	s = splimp();
6906520Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
6916520Sfeldman 		IF_DROP(&ifp->if_snd);
6926520Sfeldman 		error = ENOBUFS;
6936520Sfeldman 		goto qfull;
6946520Sfeldman 	}
6956520Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
6966520Sfeldman 	if (es->es_oactive == 0)
6976520Sfeldman 		ecstart(ifp->if_unit);
6986520Sfeldman 	splx(s);
69912771Ssam 	return (mcopy ? looutput(&loif, mcopy, dst) : 0);
7007216Ssam 
7016520Sfeldman qfull:
7026520Sfeldman 	m0 = m;
7036520Sfeldman 	splx(s);
7046520Sfeldman bad:
7056520Sfeldman 	m_freem(m0);
70616207Skarels 	if (mcopy)
70716207Skarels 		m_freem(mcopy);
70812771Ssam 	return (error);
7096520Sfeldman }
7106520Sfeldman 
7116520Sfeldman /*
7129177Ssam  * Routine to copy from mbuf chain to transmit
7137216Ssam  * buffer in UNIBUS memory.
7149177Ssam  * If packet size is less than the minimum legal size,
7159177Ssam  * the buffer is expanded.  We probably should zero out the extra
7169177Ssam  * bytes for security, but that would slow things down.
7176520Sfeldman  */
7186520Sfeldman ecput(ecbuf, m)
7197216Ssam 	u_char *ecbuf;
7206520Sfeldman 	struct mbuf *m;
7216520Sfeldman {
7226520Sfeldman 	register struct mbuf *mp;
7237216Ssam 	register int off;
7247263Ssam 	u_char *bp;
7256520Sfeldman 
7267216Ssam 	for (off = 2048, mp = m; mp; mp = mp->m_next)
7277216Ssam 		off -= mp->m_len;
7289745Ssam 	if (2048 - off < ETHERMIN + sizeof (struct ether_header))
7299745Ssam 		off = 2048 - ETHERMIN - sizeof (struct ether_header);
7307216Ssam 	*(u_short *)ecbuf = off;
7317216Ssam 	bp = (u_char *)(ecbuf + off);
7327263Ssam 	for (mp = m; mp; mp = mp->m_next) {
7337263Ssam 		register unsigned len = mp->m_len;
7347263Ssam 		u_char *mcp;
7357216Ssam 
7367216Ssam 		if (len == 0)
7377216Ssam 			continue;
7387216Ssam 		mcp = mtod(mp, u_char *);
7397216Ssam 		if ((unsigned)bp & 01) {
7407032Swnj 			*bp++ = *mcp++;
7417216Ssam 			len--;
7427032Swnj 		}
7437263Ssam 		if (off = (len >> 1)) {
7447263Ssam 			register u_short *to, *from;
7457263Ssam 
7467263Ssam 			to = (u_short *)bp;
7477263Ssam 			from = (u_short *)mcp;
7487263Ssam 			do
7497263Ssam 				*to++ = *from++;
7507263Ssam 			while (--off > 0);
7517263Ssam 			bp = (u_char *)to,
7527263Ssam 			mcp = (u_char *)from;
7537032Swnj 		}
7547263Ssam 		if (len & 01)
7556520Sfeldman 			*bp++ = *mcp++;
7566520Sfeldman 	}
7577263Ssam 	m_freem(m);
7586520Sfeldman }
7596520Sfeldman 
7606520Sfeldman /*
7616520Sfeldman  * Routine to copy from UNIBUS memory into mbufs.
7626520Sfeldman  * Similar in spirit to if_rubaget.
7637032Swnj  *
7647032Swnj  * Warning: This makes the fairly safe assumption that
7657032Swnj  * mbufs have even lengths.
7666520Sfeldman  */
7676520Sfeldman struct mbuf *
76824789Skarels ecget(ecbuf, totlen, off0, ifp)
7697263Ssam 	u_char *ecbuf;
7706520Sfeldman 	int totlen, off0;
77124789Skarels 	struct ifnet *ifp;
7726520Sfeldman {
7737263Ssam 	register struct mbuf *m;
7747263Ssam 	struct mbuf *top = 0, **mp = &top;
7757263Ssam 	register int off = off0, len;
7767263Ssam 	u_char *cp;
7776520Sfeldman 
7789745Ssam 	cp = ecbuf + ECRDOFF + sizeof (struct ether_header);
7796520Sfeldman 	while (totlen > 0) {
7807263Ssam 		register int words;
7817263Ssam 		u_char *mcp;
7827263Ssam 
7839648Ssam 		MGET(m, M_DONTWAIT, MT_DATA);
7846520Sfeldman 		if (m == 0)
7856520Sfeldman 			goto bad;
7866520Sfeldman 		if (off) {
7876520Sfeldman 			len = totlen - off;
7889745Ssam 			cp = ecbuf + ECRDOFF +
7899745Ssam 				sizeof (struct ether_header) + off;
7906520Sfeldman 		} else
7916520Sfeldman 			len = totlen;
79224789Skarels 		if (ifp)
79324789Skarels 			len += sizeof(ifp);
79424789Skarels 		if (len >= NBPG) {
7956520Sfeldman 			struct mbuf *p;
7966520Sfeldman 
7976520Sfeldman 			MCLGET(p, 1);
7986520Sfeldman 			if (p != 0) {
79924789Skarels 				m->m_len = len = MIN(len, CLBYTES);
8006520Sfeldman 				m->m_off = (int)p - (int)m;
8016520Sfeldman 			} else {
8026520Sfeldman 				m->m_len = len = MIN(MLEN, len);
8036520Sfeldman 				m->m_off = MMINOFF;
8046520Sfeldman 			}
8056520Sfeldman 		} else {
8066520Sfeldman 			m->m_len = len = MIN(MLEN, len);
8076520Sfeldman 			m->m_off = MMINOFF;
8086520Sfeldman 		}
8097263Ssam 		mcp = mtod(m, u_char *);
81024789Skarels 		if (ifp) {
81124789Skarels 			/*
81224789Skarels 			 * Prepend interface pointer to first mbuf.
81324789Skarels 			 */
81424789Skarels 			*(mtod(m, struct ifnet **)) = ifp;
81524789Skarels 			mcp += sizeof(ifp);
81624789Skarels 			len -= sizeof(ifp);
81724789Skarels 			ifp = (struct ifnet *)0;
81824789Skarels 		}
8197263Ssam 		if (words = (len >> 1)) {
8207263Ssam 			register u_short *to, *from;
8217263Ssam 
8227263Ssam 			to = (u_short *)mcp;
8237263Ssam 			from = (u_short *)cp;
8247263Ssam 			do
8257263Ssam 				*to++ = *from++;
8267263Ssam 			while (--words > 0);
8277263Ssam 			mcp = (u_char *)to;
8287263Ssam 			cp = (u_char *)from;
8297032Swnj 		}
8307216Ssam 		if (len & 01)
8316520Sfeldman 			*mcp++ = *cp++;
8326520Sfeldman 		*mp = m;
8336520Sfeldman 		mp = &m->m_next;
8347263Ssam 		if (off == 0) {
8356520Sfeldman 			totlen -= len;
8367263Ssam 			continue;
8377263Ssam 		}
8387263Ssam 		off += len;
8397263Ssam 		if (off == totlen) {
8409745Ssam 			cp = ecbuf + ECRDOFF + sizeof (struct ether_header);
8417263Ssam 			off = 0;
8427263Ssam 			totlen = off0;
8437263Ssam 		}
8446520Sfeldman 	}
8456520Sfeldman 	return (top);
8466520Sfeldman bad:
8476520Sfeldman 	m_freem(top);
8486520Sfeldman 	return (0);
8496520Sfeldman }
85013055Ssam 
85113055Ssam /*
85213055Ssam  * Process an ioctl request.
85313055Ssam  */
85413055Ssam ecioctl(ifp, cmd, data)
85513055Ssam 	register struct ifnet *ifp;
85613055Ssam 	int cmd;
85713055Ssam 	caddr_t data;
85813055Ssam {
85919863Skarels 	register struct ifaddr *ifa = (struct ifaddr *)data;
86013055Ssam 	int s = splimp(), error = 0;
86113055Ssam 
86213055Ssam 	switch (cmd) {
86313055Ssam 
86413055Ssam 	case SIOCSIFADDR:
86519863Skarels 		ifp->if_flags |= IFF_UP;
86619863Skarels 
86719863Skarels 		switch (ifa->ifa_addr.sa_family) {
86823558Ssklower #ifdef INET
86919863Skarels 		case AF_INET:
87024227Ssklower 			ecinit(ifp->if_unit); /* before, so we can send the ARP packet */
87119863Skarels 			((struct arpcom *)ifp)->ac_ipaddr =
87219863Skarels 				IA_SIN(ifa)->sin_addr;
87319863Skarels 			arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
87419863Skarels 			break;
87523558Ssklower #endif
87623558Ssklower #ifdef NS
87723558Ssklower 		case AF_NS:
87823558Ssklower 		    {
87923558Ssklower 			register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
88023558Ssklower 
88123558Ssklower 			if (ns_nullhost(*ina)) {
88223558Ssklower 				ina->x_host = * (union ns_host *)
88323558Ssklower 				     (ec_softc[ifp->if_unit].es_addr);
88423558Ssklower 			} else {
88524227Ssklower 				/*
88624227Ssklower 				 * The manual says we can't change the address
88724227Ssklower 				 * while the reciever is armed so reset everything
88824227Ssklower 				 */
88924227Ssklower 				struct ec_softc *es = &ec_softc[ifp->if_unit];
89024227Ssklower 				struct uba_device *ui = ecinfo[ifp->if_unit];
89124227Ssklower 				struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
89224227Ssklower 
89324227Ssklower 				es->es_if.if_flags &= ~IFF_RUNNING;
89424227Ssklower 				bcopy(ina->x_host.c_host, es->es_addr, sizeof(es->es_addr));
89523558Ssklower 			}
89624227Ssklower 			ecinit(ifp->if_unit); /* does ec_setaddr() */
89723558Ssklower 			break;
89823558Ssklower 		    }
89923558Ssklower #endif
90019863Skarels 		}
90113055Ssam 		break;
90213055Ssam 
90313055Ssam 	default:
90413055Ssam 		error = EINVAL;
90513055Ssam 	}
90613055Ssam 	splx(s);
90713055Ssam 	return (error);
90813055Ssam }
90923558Ssklower 
91023558Ssklower ec_setaddr(physaddr,unit)
91123558Ssklower u_char *physaddr;
91223558Ssklower int unit;
91323558Ssklower {
91423558Ssklower 	struct ec_softc *es = &ec_softc[unit];
91523558Ssklower 	struct uba_device *ui = ecinfo[unit];
91623558Ssklower 	register struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
91723558Ssklower 	register char nibble;
91823558Ssklower 	register int i, j;
91924789Skarels 
92023558Ssklower 	/*
92123558Ssklower 	 * Use the ethernet address supplied
92224227Ssklower 	 * NOte that we do a UECLR here, so the recieve buffers
92324227Ssklower 	 * must be requeued.
92423558Ssklower 	 */
92523558Ssklower 
92624227Ssklower #ifdef DEBUG
92724227Ssklower 	printf("ec_setaddr: setting address for unit %d = ",
92824227Ssklower 		unit);
92924227Ssklower 	ether_addr(physaddr);
93024227Ssklower #endif
93124227Ssklower 	addr->ec_xcr = EC_UECLR;
93223558Ssklower 	addr->ec_rcr = 0;
93324227Ssklower 	/* load requested address */
93423558Ssklower 	for (i = 0; i < 6; i++) { /* 6 bytes of address */
93523558Ssklower 	    es->es_addr[i] = physaddr[i];
93623558Ssklower 	    nibble = physaddr[i] & 0xf; /* lower nibble */
93723558Ssklower 	    addr->ec_rcr = (nibble << 8);
93824227Ssklower 	    addr->ec_rcr = (nibble << 8) + EC_AWCLK; /* latch nibble */
93923558Ssklower 	    addr->ec_rcr = (nibble << 8);
94023558Ssklower 	    for (j=0; j < 4; j++) {
94123558Ssklower 		addr->ec_rcr = 0;
94223558Ssklower 		addr->ec_rcr = EC_ASTEP; /* step counter */
94323558Ssklower 		addr->ec_rcr = 0;
94423558Ssklower 	    }
94523558Ssklower 	    nibble = (physaddr[i] >> 4) & 0xf; /* upper nibble */
94623558Ssklower 	    addr->ec_rcr = (nibble << 8);
94724227Ssklower 	    addr->ec_rcr = (nibble << 8) + EC_AWCLK; /* latch nibble */
94823558Ssklower 	    addr->ec_rcr = (nibble << 8);
94923558Ssklower 	    for (j=0; j < 4; j++) {
95023558Ssklower 		addr->ec_rcr = 0;
95123558Ssklower 		addr->ec_rcr = EC_ASTEP; /* step counter */
95223558Ssklower 		addr->ec_rcr = 0;
95323558Ssklower 	    }
95423558Ssklower 	}
95524227Ssklower #ifdef DEBUG
95624227Ssklower 	/*
95724227Ssklower 	 * Read the ethernet address off the board, one nibble at a time.
95824227Ssklower 	 */
95924227Ssklower 	addr->ec_xcr = EC_UECLR;
96024227Ssklower 	addr->ec_rcr = 0; /* read RAM */
96124227Ssklower 	cp = es->es_addr;
96224227Ssklower #undef NEXTBIT
96324227Ssklower #define	NEXTBIT	addr->ec_rcr = EC_ASTEP; addr->ec_rcr = 0
96424227Ssklower 	for (i=0; i < sizeof (es->es_addr); i++) {
96524227Ssklower 		*cp = 0;
96624227Ssklower 		for (j=0; j<=4; j+=4) {
96724227Ssklower 			*cp |= ((addr->ec_rcr >> 8) & 0xf) << j;
96824227Ssklower 			NEXTBIT; NEXTBIT; NEXTBIT; NEXTBIT;
96924227Ssklower 		}
97024227Ssklower 		cp++;
97124227Ssklower 	}
97224227Ssklower 	printf("ec_setaddr %d: ROM addr=",ui->ui_unit);
97324227Ssklower 	ether_addr(es->es_addr);
97424227Ssklower #endif
97523558Ssklower }
976*25271Sbloom #endif
977