if_lc_isa.c revision 1.2 1 1.2 matt /* $NetBSD: if_lc_isa.c,v 1.2 1997/10/15 21:26:51 matt Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 1994, 1995, 1997 Matt Thomas <matt (at) 3am-software.com>
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * Redistribution and use in source and binary forms, with or without
8 1.1 matt * modification, are permitted provided that the following conditions
9 1.1 matt * are met:
10 1.1 matt * 1. Redistributions of source code must retain the above copyright
11 1.1 matt * notice, this list of conditions and the following disclaimer.
12 1.1 matt * 2. The name of the author may not be used to endorse or promote products
13 1.1 matt * derived from this software withough specific prior written permission
14 1.1 matt *
15 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1 matt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 matt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 matt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 matt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 matt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 matt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 matt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 matt */
26 1.1 matt
27 1.1 matt /*
28 1.1 matt * DEC EtherWORKS 3 Ethernet Controllers
29 1.1 matt *
30 1.1 matt * Written by Matt Thomas
31 1.1 matt *
32 1.1 matt * This driver supports the LEMAC (DE203, DE204, and DE205) cards.
33 1.1 matt */
34 1.1 matt
35 1.1 matt #include "bpfilter.h"
36 1.1 matt
37 1.1 matt #include <sys/param.h>
38 1.1 matt #include <sys/systm.h>
39 1.1 matt #include <sys/mbuf.h>
40 1.1 matt #include <sys/socket.h>
41 1.1 matt #include <sys/ioctl.h>
42 1.1 matt #include <sys/errno.h>
43 1.1 matt #include <sys/syslog.h>
44 1.1 matt #include <sys/select.h>
45 1.1 matt #include <sys/device.h>
46 1.1 matt #include <sys/queue.h>
47 1.1 matt
48 1.1 matt #include <net/if.h>
49 1.1 matt #include <net/if_dl.h>
50 1.1 matt #include <net/if_ether.h>
51 1.1 matt #include <net/if_media.h>
52 1.1 matt
53 1.1 matt
54 1.1 matt #ifdef INET
55 1.1 matt #include <netinet/in.h>
56 1.1 matt #include <netinet/in_systm.h>
57 1.1 matt #include <netinet/in_var.h>
58 1.1 matt #include <netinet/ip.h>
59 1.1 matt #include <netinet/if_inarp.h>
60 1.1 matt #endif
61 1.1 matt
62 1.1 matt #ifdef NS
63 1.1 matt #include <netns/ns.h>
64 1.1 matt #include <netns/ns_if.h>
65 1.1 matt #endif
66 1.1 matt
67 1.1 matt #if NBPFILTER > 0
68 1.1 matt #include <net/bpf.h>
69 1.1 matt #include <net/bpfdesc.h>
70 1.1 matt #endif
71 1.1 matt
72 1.1 matt #include <machine/cpu.h>
73 1.1 matt #include <machine/bus.h>
74 1.1 matt #include <machine/intr.h>
75 1.1 matt
76 1.1 matt #include <dev/ic/lemacreg.h>
77 1.1 matt #include <dev/ic/lemacvar.h>
78 1.1 matt
79 1.1 matt #include <dev/isa/isavar.h>
80 1.1 matt
81 1.1 matt static int
82 1.1 matt lemac_isa_probe(
83 1.1 matt struct device *parent,
84 1.1 matt #ifdef __BROKEN_INDIRECT_CONFIG
85 1.1 matt void *match,
86 1.1 matt #else
87 1.1 matt struct cfdata *match,
88 1.1 matt #endif
89 1.1 matt void *aux)
90 1.1 matt {
91 1.1 matt struct isa_attach_args * const ia = aux;
92 1.2 matt int irq;
93 1.2 matt bus_addr_t iobase;
94 1.2 matt bus_addr_t iolimit;
95 1.2 matt bus_addr_t maddr;
96 1.2 matt bus_addr_t msize;
97 1.2 matt bus_space_handle_t memh;
98 1.2 matt bus_space_handle_t ioh;
99 1.1 matt
100 1.1 matt /*
101 1.2 matt * Determine if we are probing for any card or a specific card.
102 1.1 matt */
103 1.2 matt if (ia->ia_iobase == IOBASEUNK) {
104 1.2 matt iobase = LEMAC_IOBASE_LOW;
105 1.2 matt iolimit = LEMAC_IOBASE_HIGH;
106 1.2 matt } else if (ia->ia_iobase & (LEMAC_IOSIZE-1)) {
107 1.2 matt return 0;
108 1.2 matt } else {
109 1.2 matt iobase = ia->ia_iobase;
110 1.2 matt iolimit = ia->ia_iobase + LEMAC_IOSIZE;
111 1.1 matt }
112 1.1 matt
113 1.2 matt for (; iobase < iolimit; iobase += LEMAC_IOSIZE) {
114 1.2 matt /*
115 1.2 matt * Map the LEMACs port-space for the probe sequence.
116 1.2 matt */
117 1.2 matt if (bus_space_map(ia->ia_iot, iobase, LEMAC_IOSIZE, 0, &ioh))
118 1.2 matt continue;
119 1.2 matt
120 1.1 matt /*
121 1.2 matt * Read the Ethernet address from the EEPROM.
122 1.2 matt * It must start with on the DEC OUIs and pass the
123 1.2 matt * DEC ethernet checksum test.
124 1.1 matt */
125 1.2 matt
126 1.2 matt if (lemac_port_check(ia->ia_iot, ioh)) {
127 1.2 matt lemac_info_get(ia->ia_iot, ioh, &maddr, &msize, &irq);
128 1.2 matt if (!bus_space_map(ia->ia_memt, maddr, msize, 0, &memh)) {
129 1.2 matt bus_space_unmap(ia->ia_memt, memh, msize);
130 1.2 matt if ((ia->ia_maddr == MADDRUNK || ia->ia_maddr == maddr)
131 1.2 matt && (ia->ia_irq == IRQUNK || ia->ia_irq == irq)) {
132 1.2 matt ia->ia_iobase = iobase;
133 1.2 matt ia->ia_irq = irq;
134 1.2 matt ia->ia_iosize = LEMAC_IOSIZE;
135 1.2 matt ia->ia_maddr = maddr;
136 1.2 matt ia->ia_msize = msize;
137 1.2 matt return 1;
138 1.1 matt }
139 1.1 matt }
140 1.1 matt }
141 1.1 matt
142 1.2 matt bus_space_unmap(ia->ia_iot, ioh, LEMAC_IOSIZE);
143 1.1 matt }
144 1.1 matt
145 1.2 matt return 0;
146 1.1 matt }
147 1.1 matt
148 1.1 matt static void
149 1.1 matt lemac_isa_attach(
150 1.1 matt struct device *parent,
151 1.1 matt struct device *self,
152 1.1 matt void *aux)
153 1.1 matt {
154 1.1 matt lemac_softc_t *sc = (void *)self;
155 1.1 matt struct isa_attach_args *ia = aux;
156 1.1 matt
157 1.1 matt /* Map i/o space. */
158 1.1 matt sc->sc_iot = ia->ia_iot;
159 1.1 matt if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0, &sc->sc_ioh))
160 1.1 matt panic("\n%s: can't map i/o space 0x%x-0x%x\n",
161 1.1 matt sc->sc_dv.dv_xname,
162 1.1 matt ia->ia_iobase, ia->ia_iobase + ia->ia_iosize - 1);
163 1.1 matt
164 1.1 matt if (ia->ia_msize && ia->ia_maddr) {
165 1.1 matt sc->sc_memt = ia->ia_memt;
166 1.1 matt /* Map memory space. */
167 1.1 matt if (bus_space_map(sc->sc_memt, ia->ia_maddr, ia->ia_msize, 0, &sc->sc_memh))
168 1.1 matt panic("\n%s: can't map iomem space 0x%x-0x%x\n",
169 1.1 matt sc->sc_dv.dv_xname,
170 1.1 matt ia->ia_maddr, ia->ia_maddr + ia->ia_msize - 1);
171 1.1 matt }
172 1.1 matt
173 1.1 matt sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc);
174 1.1 matt if (sc->sc_ats == NULL)
175 1.1 matt printf("\n%s: warning: couldn't establish shutdown hook\n",
176 1.1 matt sc->sc_dv.dv_xname);
177 1.1 matt
178 1.1 matt lemac_ifattach(sc);
179 1.1 matt
180 1.1 matt sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
181 1.1 matt IPL_NET, lemac_intr, sc);
182 1.1 matt }
183 1.1 matt
184 1.1 matt struct cfattach lc_isa_ca = {
185 1.1 matt sizeof(lemac_softc_t), lemac_isa_probe, lemac_isa_attach
186 1.1 matt };
187