if_ea.c revision 1.3
11.3Sbjh21/* $NetBSD: if_ea.c,v 1.3 2001/03/24 23:37:34 bjh21 Exp $ */
21.1Sbjh21
31.1Sbjh21/*
41.1Sbjh21 * Copyright (c) 2000, 2001 Ben Harris
51.1Sbjh21 * Copyright (c) 1995 Mark Brinicombe
61.1Sbjh21 * All rights reserved.
71.1Sbjh21 *
81.1Sbjh21 * Redistribution and use in source and binary forms, with or without
91.1Sbjh21 * modification, are permitted provided that the following conditions
101.1Sbjh21 * are met:
111.1Sbjh21 * 1. Redistributions of source code must retain the above copyright
121.1Sbjh21 *    notice, this list of conditions and the following disclaimer.
131.1Sbjh21 * 2. Redistributions in binary form must reproduce the above copyright
141.1Sbjh21 *    notice, this list of conditions and the following disclaimer in the
151.1Sbjh21 *    documentation and/or other materials provided with the distribution.
161.1Sbjh21 * 3. All advertising materials mentioning features or use of this software
171.1Sbjh21 *    must display the following acknowledgement:
181.1Sbjh21 *	This product includes software developed by Mark Brinicombe.
191.1Sbjh21 * 4. The name of the company nor the name of the author may be used to
201.1Sbjh21 *    endorse or promote products derived from this software without specific
211.1Sbjh21 *    prior written permission.
221.1Sbjh21 *
231.1Sbjh21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
241.1Sbjh21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
251.1Sbjh21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
261.1Sbjh21 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
271.1Sbjh21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
281.1Sbjh21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
291.1Sbjh21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
301.1Sbjh21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
311.1Sbjh21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
321.1Sbjh21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
331.1Sbjh21 * SUCH DAMAGE.
341.1Sbjh21 */
351.1Sbjh21/*
361.1Sbjh21 * if_ea.c - Ether3 device driver
371.1Sbjh21 */
381.1Sbjh21
391.1Sbjh21#include <sys/param.h>
401.1Sbjh21
411.3Sbjh21__RCSID("$NetBSD: if_ea.c,v 1.3 2001/03/24 23:37:34 bjh21 Exp $");
421.1Sbjh21
431.1Sbjh21#include <sys/device.h>
441.1Sbjh21#include <sys/socket.h>
451.1Sbjh21#include <sys/systm.h>
461.1Sbjh21
471.1Sbjh21#include <machine/bus.h>
481.1Sbjh21#include <machine/intr.h>
491.1Sbjh21
501.1Sbjh21#include <net/if.h>
511.1Sbjh21#include <net/if_ether.h>
521.1Sbjh21
531.2Sbjh21#include <dev/podulebus/podulebus.h>
541.1Sbjh21#include <dev/podulebus/podules.h>
551.1Sbjh21
561.2Sbjh21#include <dev/podulebus/if_eareg.h>
571.1Sbjh21#include <dev/ic/seeq8005var.h>
581.1Sbjh21
591.1Sbjh21/*
601.1Sbjh21 * per-line info and status
611.1Sbjh21 */
621.1Sbjh21
631.1Sbjh21struct ea_softc {
641.1Sbjh21	struct seeq8005_softc	sc_8005;
651.1Sbjh21	void	*sc_ih;
661.1Sbjh21	struct evcnt sc_intrcnt;
671.1Sbjh21};
681.1Sbjh21
691.1Sbjh21/*
701.1Sbjh21 * prototypes
711.1Sbjh21 */
721.1Sbjh21
731.1Sbjh21int eaprobe(struct device *, struct cfdata *, void *);
741.1Sbjh21void eaattach(struct device *, struct device *, void *);
751.1Sbjh21
761.1Sbjh21/* driver structure for autoconf */
771.1Sbjh21
781.1Sbjh21struct cfattach ea_ca = {
791.1Sbjh21	sizeof(struct ea_softc), eaprobe, eaattach
801.1Sbjh21};
811.1Sbjh21
821.1Sbjh21/*
831.1Sbjh21 * Probe routine.
841.1Sbjh21 */
851.1Sbjh21
861.1Sbjh21/*
871.1Sbjh21 * Probe for the ether3 podule.
881.1Sbjh21 */
891.1Sbjh21
901.1Sbjh21int
911.1Sbjh21eaprobe(struct device *parent, struct cfdata *cf, void *aux)
921.1Sbjh21{
931.1Sbjh21	struct podulebus_attach_args *pa = aux;
941.1Sbjh21
951.1Sbjh21	if ((matchpodule(pa, MANUFACTURER_ATOMWIDE,
961.1Sbjh21			 PODULE_ATOMWIDE_ETHER3, -1) == 0)
971.1Sbjh21	    && (matchpodule(pa, MANUFACTURER_ACORN,
981.1Sbjh21			    PODULE_ACORN_ETHER3XXX, -1) == 0)
991.1Sbjh21	    && (matchpodule(pa, MANUFACTURER_ANT, PODULE_ANT_ETHER3, -1) == 0))
1001.1Sbjh21		return 0;
1011.1Sbjh21
1021.1Sbjh21	return 1;
1031.1Sbjh21}
1041.1Sbjh21
1051.1Sbjh21
1061.1Sbjh21/*
1071.1Sbjh21 * Attach podule.
1081.1Sbjh21 */
1091.1Sbjh21
1101.1Sbjh21void
1111.1Sbjh21eaattach(struct device *parent, struct device *self, void *aux)
1121.1Sbjh21{
1131.1Sbjh21	struct ea_softc *sc = (void *)self;
1141.1Sbjh21	struct podulebus_attach_args *pa = aux;
1151.1Sbjh21	u_int8_t myaddr[ETHER_ADDR_LEN];
1161.1Sbjh21	char *ptr;
1171.1Sbjh21	int i;
1181.1Sbjh21
1191.1Sbjh21/*	dprintf(("Attaching %s...\n", sc->sc_dev.dv_xname));*/
1201.1Sbjh21
1211.1Sbjh21	/* Set the address of the controller for easy access */
1221.1Sbjh21	podulebus_shift_tag(pa->pa_mod_t, EA_8005_SHIFT, &sc->sc_8005.sc_iot);
1231.1Sbjh21	bus_space_map(sc->sc_8005.sc_iot, pa->pa_mod_base, /* XXX */ 0, 0,
1241.1Sbjh21	    &sc->sc_8005.sc_ioh);
1251.1Sbjh21
1261.1Sbjh21	/* Get the Ethernet address from the device description string. */
1271.1Sbjh21	if (pa->pa_descr == NULL) {
1281.1Sbjh21		printf(": No description for Ethernet address\n");
1291.1Sbjh21		return;
1301.1Sbjh21	}
1311.1Sbjh21	ptr = strchr(pa->pa_descr, '(');
1321.1Sbjh21	if (ptr == NULL) {
1331.1Sbjh21		printf(": Ethernet address not found in description\n");
1341.1Sbjh21		return;
1351.1Sbjh21	}
1361.1Sbjh21	ptr++;
1371.1Sbjh21	for (i = 0; i < ETHER_ADDR_LEN; i++) {
1381.1Sbjh21		myaddr[i] = strtoul(ptr, &ptr, 16);
1391.1Sbjh21		if (*ptr++ != (i == ETHER_ADDR_LEN - 1 ? ')' : ':')) {
1401.1Sbjh21			printf(": Bad Ethernet address found in "
1411.1Sbjh21			       "description\n");
1421.1Sbjh21			return;
1431.1Sbjh21		}
1441.1Sbjh21	}
1451.1Sbjh21
1461.1Sbjh21	printf(":");
1471.3Sbjh21	seeq8005_attach(&sc->sc_8005, myaddr, NULL, 0, 0);
1481.1Sbjh21
1491.1Sbjh21	/* Claim a podule interrupt */
1501.1Sbjh21
1511.1Sbjh21	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
1521.1Sbjh21	    self->dv_xname, "intr");
1531.1Sbjh21	sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_NET, seeq8005intr,
1541.1Sbjh21	    sc, &sc->sc_intrcnt);
1551.1Sbjh21}
1561.1Sbjh21
1571.1Sbjh21/* End of if_ea.c */
158