Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / eisa / depca_eisa.c
blob10c488cadd1c3aae66e527e286134664b5250eb1
1 /* $NetBSD: depca_eisa.c,v 1.11 2008/04/04 12:25:07 tsutsui Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * EISA bus front-end for the Digital DEPCA Ethernet controller.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: depca_eisa.c,v 1.11 2008/04/04 12:25:07 tsutsui Exp $");
39 #include "opt_inet.h"
40 #include "bpfilter.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/mbuf.h>
45 #include <sys/syslog.h>
46 #include <sys/socket.h>
47 #include <sys/device.h>
49 #include <net/if.h>
50 #include <net/if_media.h>
51 #include <net/if_ether.h>
53 #ifdef INET
54 #include <netinet/in.h>
55 #include <netinet/if_inarp.h>
56 #endif
58 #include <sys/bus.h>
59 #include <sys/intr.h>
61 #include <dev/eisa/eisareg.h>
62 #include <dev/eisa/eisavar.h>
63 #include <dev/eisa/eisadevs.h>
65 #include <dev/ic/lancereg.h>
66 #include <dev/ic/lancevar.h>
67 #include <dev/ic/am7990reg.h>
68 #include <dev/ic/am7990var.h>
69 #include <dev/ic/depcareg.h>
70 #include <dev/ic/depcavar.h>
72 static int depca_eisa_match(device_t, cfdata_t, void *);
73 static void depca_eisa_attach(device_t, device_t, void *);
75 struct depca_eisa_softc {
76 struct depca_softc sc_depca;
78 eisa_chipset_tag_t sc_ec;
79 int sc_irq;
80 int sc_ist;
83 CFATTACH_DECL_NEW(depca_eisa, sizeof(struct depca_eisa_softc),
84 depca_eisa_match, depca_eisa_attach, NULL, NULL);
86 static void *depca_eisa_intr_establish(struct depca_softc *,
87 struct lance_softc *);
89 static int
90 depca_eisa_match(device_t parent, cfdata_t cf, void *aux)
92 struct eisa_attach_args *ea = aux;
94 return (strcmp(ea->ea_idstring, "DEC4220") == 0);
97 #define DEPCA_ECU_FUNC_NETINTR 0
98 #define DEPCA_ECU_FUNC_NETBUF 1
100 static void
101 depca_eisa_attach(device_t parent, device_t self, void *aux)
103 struct depca_eisa_softc *esc = device_private(self);
104 struct depca_softc *sc = &esc->sc_depca;
105 struct eisa_attach_args *ea = aux;
106 struct eisa_cfg_mem ecm;
107 struct eisa_cfg_irq eci;
109 sc->sc_dev = self;
110 aprint_error(": DEC DE422 Ethernet\n");
112 sc->sc_iot = ea->ea_iot;
113 sc->sc_memt = ea->ea_memt;
115 esc->sc_ec = ea->ea_ec;
117 sc->sc_intr_establish = depca_eisa_intr_establish;
119 if (eisa_conf_read_mem(ea->ea_ec, ea->ea_slot,
120 DEPCA_ECU_FUNC_NETBUF, 0, &ecm) != 0) {
121 aprint_error_dev(self, "unable to find network buffer\n");
122 return;
125 aprint_normal_dev(self, "shared memory at 0x%lx-0x%lx\n",
126 ecm.ecm_addr, ecm.ecm_addr + ecm.ecm_size - 1);
128 sc->sc_memsize = ecm.ecm_size;
130 if (bus_space_map(sc->sc_iot, EISA_SLOT_ADDR(ea->ea_slot) + 0xc00, 16,
131 0, &sc->sc_ioh) != 0) {
132 aprint_error_dev(self, "unable to map i/o space\n");
133 return;
135 if (bus_space_map(sc->sc_memt, ecm.ecm_addr, sc->sc_memsize,
136 0, &sc->sc_memh) != 0) {
137 aprint_error_dev(self, "unable to map memory space\n");
138 return;
141 if (eisa_conf_read_irq(ea->ea_ec, ea->ea_slot,
142 DEPCA_ECU_FUNC_NETINTR, 0, &eci) != 0) {
143 aprint_error_dev(self, "unable to determine IRQ\n");
144 return;
147 esc->sc_irq = eci.eci_irq;
148 esc->sc_ist = eci.eci_ist;
150 depca_attach(sc);
153 static void *
154 depca_eisa_intr_establish(struct depca_softc *parent, struct lance_softc *child)
156 struct depca_eisa_softc *esc = (struct depca_eisa_softc *)parent;
157 eisa_intr_handle_t ih;
158 const char *intrstr;
159 void *rv;
161 if (eisa_intr_map(esc->sc_ec, esc->sc_irq, &ih)) {
162 aprint_error_dev(parent->sc_dev,
163 "unable to map interrupt (%d)\n", esc->sc_irq);
164 return (NULL);
166 intrstr = eisa_intr_string(esc->sc_ec, ih);
167 rv = eisa_intr_establish(esc->sc_ec, ih, esc->sc_ist, IPL_NET,
168 (esc->sc_ist == IST_LEVEL) ? am7990_intr : depca_intredge, child);
169 if (rv == NULL) {
170 aprint_error_dev(parent->sc_dev,
171 "unable to establish interrupt");
172 if (intrstr != NULL)
173 aprint_error(" at %s", intrstr);
174 aprint_error("\n");
175 return (NULL);
177 if (intrstr != NULL)
178 aprint_normal_dev(parent->sc_dev, "interrupting at %s\n",
179 intrstr);
181 return (rv);