if_ea.c revision 1.6
11.6Sbjh21/* $NetBSD: if_ea.c,v 1.6 2002/05/22 22:43:14 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.4Slukem#include <sys/cdefs.h>
401.6Sbjh21__KERNEL_RCSID(0, "$NetBSD: if_ea.c,v 1.6 2002/05/22 22:43:14 bjh21 Exp $");
411.4Slukem
421.1Sbjh21#include <sys/param.h>
431.1Sbjh21
441.1Sbjh21#include <sys/device.h>
451.1Sbjh21#include <sys/socket.h>
461.1Sbjh21#include <sys/systm.h>
471.1Sbjh21
481.1Sbjh21#include <machine/bus.h>
491.1Sbjh21#include <machine/intr.h>
501.1Sbjh21
511.1Sbjh21#include <net/if.h>
521.1Sbjh21#include <net/if_ether.h>
531.1Sbjh21
541.2Sbjh21#include <dev/podulebus/podulebus.h>
551.1Sbjh21#include <dev/podulebus/podules.h>
561.1Sbjh21
571.2Sbjh21#include <dev/podulebus/if_eareg.h>
581.1Sbjh21#include <dev/ic/seeq8005var.h>
591.1Sbjh21
601.1Sbjh21/*
611.1Sbjh21 * per-line info and status
621.1Sbjh21 */
631.1Sbjh21
641.1Sbjh21struct ea_softc {
651.1Sbjh21	struct seeq8005_softc	sc_8005;
661.1Sbjh21	void	*sc_ih;
671.1Sbjh21	struct evcnt sc_intrcnt;
681.1Sbjh21};
691.1Sbjh21
701.1Sbjh21/*
711.1Sbjh21 * prototypes
721.1Sbjh21 */
731.1Sbjh21
741.1Sbjh21int eaprobe(struct device *, struct cfdata *, void *);
751.1Sbjh21void eaattach(struct device *, struct device *, void *);
761.1Sbjh21
771.1Sbjh21/* driver structure for autoconf */
781.1Sbjh21
791.1Sbjh21struct cfattach ea_ca = {
801.1Sbjh21	sizeof(struct ea_softc), eaprobe, eaattach
811.1Sbjh21};
821.1Sbjh21
831.1Sbjh21/*
841.1Sbjh21 * Probe routine.
851.1Sbjh21 */
861.1Sbjh21
871.1Sbjh21/*
881.1Sbjh21 * Probe for the ether3 podule.
891.1Sbjh21 */
901.1Sbjh21
911.1Sbjh21int
921.1Sbjh21eaprobe(struct device *parent, struct cfdata *cf, void *aux)
931.1Sbjh21{
941.1Sbjh21	struct podulebus_attach_args *pa = aux;
951.1Sbjh21
961.6Sbjh21	return pa->pa_product == PODULE_ETHER3;
971.1Sbjh21}
981.1Sbjh21
991.1Sbjh21
1001.1Sbjh21/*
1011.1Sbjh21 * Attach podule.
1021.1Sbjh21 */
1031.1Sbjh21
1041.1Sbjh21void
1051.1Sbjh21eaattach(struct device *parent, struct device *self, void *aux)
1061.1Sbjh21{
1071.1Sbjh21	struct ea_softc *sc = (void *)self;
1081.1Sbjh21	struct podulebus_attach_args *pa = aux;
1091.1Sbjh21	u_int8_t myaddr[ETHER_ADDR_LEN];
1101.1Sbjh21	char *ptr;
1111.1Sbjh21	int i;
1121.1Sbjh21
1131.1Sbjh21/*	dprintf(("Attaching %s...\n", sc->sc_dev.dv_xname));*/
1141.1Sbjh21
1151.1Sbjh21	/* Set the address of the controller for easy access */
1161.1Sbjh21	podulebus_shift_tag(pa->pa_mod_t, EA_8005_SHIFT, &sc->sc_8005.sc_iot);
1171.1Sbjh21	bus_space_map(sc->sc_8005.sc_iot, pa->pa_mod_base, /* XXX */ 0, 0,
1181.1Sbjh21	    &sc->sc_8005.sc_ioh);
1191.1Sbjh21
1201.1Sbjh21	/* Get the Ethernet address from the device description string. */
1211.1Sbjh21	if (pa->pa_descr == NULL) {
1221.1Sbjh21		printf(": No description for Ethernet address\n");
1231.1Sbjh21		return;
1241.1Sbjh21	}
1251.1Sbjh21	ptr = strchr(pa->pa_descr, '(');
1261.1Sbjh21	if (ptr == NULL) {
1271.1Sbjh21		printf(": Ethernet address not found in description\n");
1281.1Sbjh21		return;
1291.1Sbjh21	}
1301.1Sbjh21	ptr++;
1311.1Sbjh21	for (i = 0; i < ETHER_ADDR_LEN; i++) {
1321.1Sbjh21		myaddr[i] = strtoul(ptr, &ptr, 16);
1331.1Sbjh21		if (*ptr++ != (i == ETHER_ADDR_LEN - 1 ? ')' : ':')) {
1341.1Sbjh21			printf(": Bad Ethernet address found in "
1351.1Sbjh21			       "description\n");
1361.1Sbjh21			return;
1371.1Sbjh21		}
1381.1Sbjh21	}
1391.1Sbjh21
1401.1Sbjh21	printf(":");
1411.3Sbjh21	seeq8005_attach(&sc->sc_8005, myaddr, NULL, 0, 0);
1421.1Sbjh21
1431.1Sbjh21	/* Claim a podule interrupt */
1441.1Sbjh21
1451.1Sbjh21	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
1461.1Sbjh21	    self->dv_xname, "intr");
1471.1Sbjh21	sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_NET, seeq8005intr,
1481.1Sbjh21	    sc, &sc->sc_intrcnt);
1491.1Sbjh21}
1501.1Sbjh21
1511.1Sbjh21/* End of if_ea.c */
152