xref: /netbsd/sys/arch/powerpc/ibm4xx/dev/if_emac.c (revision bf9ec67e)
1 /*	$NetBSD: if_emac.c,v 1.2 2002/03/15 21:10:46 eeh Exp $	*/
2 
3 /*
4  * Copyright 2001 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Simon Burge and Eduardo Horvath for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed for the NetBSD Project by
20  *      Wasabi Systems, Inc.
21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22  *    or promote products derived from this software without specific prior
23  *    written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "rnd.h"
39 #include "bpfilter.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/callout.h>
44 #include <sys/mbuf.h>
45 #include <sys/malloc.h>
46 #include <sys/kernel.h>
47 #include <sys/socket.h>
48 #include <sys/ioctl.h>
49 #include <sys/errno.h>
50 #include <sys/device.h>
51 #include <sys/queue.h>
52 
53 #if NRND > 0
54 #include <sys/rnd.h>
55 #endif
56 
57 #include <net/if.h>
58 #include <net/if_dl.h>
59 #include <net/if_media.h>
60 #include <net/if_ether.h>
61 
62 #if NBPFILTER > 0
63 #include <net/bpf.h>
64 #endif
65 
66 #include <machine/autoconf.h>
67 #include <machine/bus.h>
68 #include <machine/walnut.h>								/* XXX - this file shouldn't depend on board-data */
69 
70 #include <dev/mii/mii.h>
71 #include <dev/mii/miivar.h>
72 
73 struct emac_softc {
74 	struct device sc_dev;		/* generic device information */
75 	bus_space_tag_t sc_st;		/* bus space tag */
76 	bus_space_handle_t sc_sh;	/* bus space handle */
77 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
78 	struct ethercom sc_ethercom;	/* ethernet common data */
79 	void *sc_sdhook;		/* shutdown hook */
80 };
81 
82 static int	emac_match(struct device *, struct cfdata *, void *);
83 static void	emac_attach(struct device *, struct device *, void *);
84 static int	emac_intr(void *);
85 
86 struct cfattach emac_ca = {
87 	sizeof(struct emac_softc), emac_match, emac_attach
88 };
89 
90 static int probe_done = 0;
91 
92 static int
93 emac_match(struct device *parent, struct cfdata *cf, void *aux)
94 {
95 
96 	/*
97 	 * XXX probe!
98 	 * This won't work on some of the NP family processors that have
99 	 * multiple EMACs
100 	 */
101 
102 	if (probe_done)
103 		return 0;
104 
105 	probe_done = 1;
106 	return 1;
107 }
108 
109 static void
110 emac_attach(struct device *parent, struct device *self, void *aux)
111 {
112 	struct mainbus_attach_args *maa = aux;
113 	struct emac_softc *sc = (struct emac_softc *)self;
114 
115 	sc->sc_st = galaxy_make_bus_space_tag(0, 0);
116 	sc->sc_sh = maa->mb_addr;
117 
118 	printf(": 405GP EMAC\n");
119 	printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
120 	    ether_sprintf(board_data.mac_address_local));
121 
122 	intr_establish(maa->mb_irq, IST_LEVEL, IPL_NET, emac_intr, sc);
123 	printf("%s: interrupting at irq %d\n", sc->sc_dev.dv_xname,
124 		maa->mb_irq);
125 }
126 
127 static int
128 emac_intr(void *arg)
129 {
130 
131 	printf("emac_intr: arg = %p\n", arg);	/* XXX */
132 	return 0;
133 }
134