if_ea.c revision 1.13
11.13Sad/* $NetBSD: if_ea.c,v 1.13 2007/10/19 12:01:07 ad 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.13Sad__KERNEL_RCSID(0, "$NetBSD: if_ea.c,v 1.13 2007/10/19 12:01:07 ad 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.13Sad#include <sys/bus.h>
491.13Sad#include <sys/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.8SthorpejCFATTACH_DECL(ea, sizeof(struct ea_softc),
801.9Sthorpej    eaprobe, eaattach, NULL, NULL);
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.10Sperry
951.6Sbjh21	return pa->pa_product == PODULE_ETHER3;
961.1Sbjh21}
971.1Sbjh21
981.1Sbjh21
991.1Sbjh21/*
1001.1Sbjh21 * Attach podule.
1011.1Sbjh21 */
1021.1Sbjh21
1031.1Sbjh21void
1041.1Sbjh21eaattach(struct device *parent, struct device *self, void *aux)
1051.1Sbjh21{
1061.12Sthorpej	struct ea_softc *sc = device_private(self);
1071.1Sbjh21	struct podulebus_attach_args *pa = aux;
1081.1Sbjh21	u_int8_t myaddr[ETHER_ADDR_LEN];
1091.1Sbjh21	char *ptr;
1101.1Sbjh21	int i;
1111.10Sperry
1121.1Sbjh21/*	dprintf(("Attaching %s...\n", sc->sc_dev.dv_xname));*/
1131.1Sbjh21
1141.1Sbjh21	/* Set the address of the controller for easy access */
1151.1Sbjh21	podulebus_shift_tag(pa->pa_mod_t, EA_8005_SHIFT, &sc->sc_8005.sc_iot);
1161.1Sbjh21	bus_space_map(sc->sc_8005.sc_iot, pa->pa_mod_base, /* XXX */ 0, 0,
1171.1Sbjh21	    &sc->sc_8005.sc_ioh);
1181.1Sbjh21
1191.1Sbjh21	/* Get the Ethernet address from the device description string. */
1201.1Sbjh21	if (pa->pa_descr == NULL) {
1211.1Sbjh21		printf(": No description for Ethernet address\n");
1221.1Sbjh21		return;
1231.1Sbjh21	}
1241.1Sbjh21	ptr = strchr(pa->pa_descr, '(');
1251.1Sbjh21	if (ptr == NULL) {
1261.1Sbjh21		printf(": Ethernet address not found in description\n");
1271.1Sbjh21		return;
1281.1Sbjh21	}
1291.1Sbjh21	ptr++;
1301.1Sbjh21	for (i = 0; i < ETHER_ADDR_LEN; i++) {
1311.1Sbjh21		myaddr[i] = strtoul(ptr, &ptr, 16);
1321.1Sbjh21		if (*ptr++ != (i == ETHER_ADDR_LEN - 1 ? ')' : ':')) {
1331.1Sbjh21			printf(": Bad Ethernet address found in "
1341.1Sbjh21			       "description\n");
1351.1Sbjh21			return;
1361.1Sbjh21		}
1371.1Sbjh21	}
1381.1Sbjh21
1391.1Sbjh21	printf(":");
1401.3Sbjh21	seeq8005_attach(&sc->sc_8005, myaddr, NULL, 0, 0);
1411.1Sbjh21
1421.1Sbjh21	/* Claim a podule interrupt */
1431.1Sbjh21
1441.1Sbjh21	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
1451.1Sbjh21	    self->dv_xname, "intr");
1461.1Sbjh21	sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_NET, seeq8005intr,
1471.1Sbjh21	    sc, &sc->sc_intrcnt);
1481.1Sbjh21}
1491.1Sbjh21
1501.1Sbjh21/* End of if_ea.c */
151