if_sm_isa.c revision 1.6 1 /* $NetBSD: if_sm_isa.c,v 1.6 2000/07/30 21:34:48 briggs Exp $ */
2
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include "opt_inet.h"
41 #include "opt_ns.h"
42 #include "bpfilter.h"
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/mbuf.h>
47 #include <sys/socket.h>
48 #include <sys/ioctl.h>
49 #include <sys/errno.h>
50 #include <sys/syslog.h>
51 #include <sys/select.h>
52 #include <sys/device.h>
53
54 #include <net/if.h>
55 #include <net/if_dl.h>
56 #include <net/if_ether.h>
57 #include <net/if_media.h>
58
59 #ifdef INET
60 #include <netinet/in.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/in_var.h>
63 #include <netinet/ip.h>
64 #include <netinet/if_inarp.h>
65 #endif
66
67 #ifdef NS
68 #include <netns/ns.h>
69 #include <netns/ns_if.h>
70 #endif
71
72 #if NBPFILTER > 0
73 #include <net/bpf.h>
74 #include <net/bpfdesc.h>
75 #endif
76
77 #include <machine/intr.h>
78 #include <machine/bus.h>
79
80 #include <dev/mii/mii.h>
81 #include <dev/mii/miivar.h>
82
83 #include <dev/ic/smc91cxxreg.h>
84 #include <dev/ic/smc91cxxvar.h>
85
86 #include <dev/isa/isavar.h>
87
88 int sm_isa_match __P((struct device *, struct cfdata *, void *));
89 void sm_isa_attach __P((struct device *, struct device *, void *));
90
91 struct sm_isa_softc {
92 struct smc91cxx_softc sc_smc; /* real "smc" softc */
93
94 /* ISA-specific goo. */
95 void *sc_ih; /* interrupt cookie */
96 };
97
98 struct cfattach sm_isa_ca = {
99 sizeof(struct sm_isa_softc), sm_isa_match, sm_isa_attach
100 };
101
102 int
103 sm_isa_match(parent, match, aux)
104 struct device *parent;
105 struct cfdata *match;
106 void *aux;
107 {
108 struct isa_attach_args *ia = aux;
109 bus_space_tag_t iot = ia->ia_iot;
110 bus_space_handle_t ioh;
111 u_int16_t tmp;
112 int rv = 0;
113 extern const char *smc91cxx_idstrs[];
114
115 /* Disallow wildcarded values. */
116 if (ia->ia_irq == -1)
117 return (0);
118 if (ia->ia_iobase == -1)
119 return (0);
120
121 /* Map i/o space. */
122 if (bus_space_map(iot, ia->ia_iobase, SMC_IOSIZE, 0, &ioh))
123 return (0);
124
125 /* Check that high byte of BANK_SELECT is what we expect. */
126 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
127 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
128 goto out;
129
130 /*
131 * Switch to bank 0 and perform the test again.
132 * XXX INVASIVE!
133 */
134 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0);
135 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
136 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
137 goto out;
138
139 /*
140 * Switch to bank 1 and check the base address register.
141 * XXX INVASIVE!
142 */
143 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1);
144 tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W);
145 if (ia->ia_iobase != ((tmp >> 3) & 0x3e0))
146 goto out;
147
148 /*
149 * Check for a recognized chip id.
150 * XXX INVASIVE!
151 */
152 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3);
153 tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
154 if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
155 goto out;
156
157 /*
158 * Assume we have an SMC91Cxx.
159 */
160 ia->ia_iosize = SMC_IOSIZE;
161 rv = 1;
162
163 out:
164 bus_space_unmap(iot, ioh, SMC_IOSIZE);
165 return (rv);
166 }
167
168 void
169 sm_isa_attach(parent, self, aux)
170 struct device *parent, *self;
171 void *aux;
172 {
173 struct sm_isa_softc *isc = (struct sm_isa_softc *)self;
174 struct smc91cxx_softc *sc = &isc->sc_smc;
175 struct isa_attach_args *ia = aux;
176 bus_space_tag_t iot = ia->ia_iot;
177 bus_space_handle_t ioh;
178
179 printf("\n");
180
181 /* Map i/o space. */
182 if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh))
183 panic("sm_isa_attach: can't map i/o space");
184
185 sc->sc_bst = iot;
186 sc->sc_bsh = ioh;
187
188 /* should always be enabled */
189 sc->sc_flags |= SMC_FLAGS_ENABLED;
190
191 /* XXX Should get Ethernet address from EEPROM!! */
192
193 /* Perform generic intialization. */
194 smc91cxx_attach(sc, NULL);
195
196 /* Establish the interrupt handler. */
197 isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
198 IPL_NET, smc91cxx_intr, sc);
199 if (isc->sc_ih == NULL)
200 printf("%s: couldn't establish interrupt handler\n",
201 sc->sc_dev.dv_xname);
202 }
203