if_sm_isa.c revision 1.18 1 /* $NetBSD: if_sm_isa.c,v 1.18 2007/10/19 12:00:18 ad 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 <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: if_sm_isa.c,v 1.18 2007/10/19 12:00:18 ad Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/mbuf.h>
46 #include <sys/socket.h>
47 #include <sys/ioctl.h>
48 #include <sys/errno.h>
49 #include <sys/syslog.h>
50 #include <sys/select.h>
51 #include <sys/device.h>
52
53 #include <net/if.h>
54 #include <net/if_dl.h>
55 #include <net/if_ether.h>
56 #include <net/if_media.h>
57
58 #include <sys/intr.h>
59 #include <sys/bus.h>
60
61 #include <dev/mii/mii.h>
62 #include <dev/mii/miivar.h>
63
64 #include <dev/ic/smc91cxxreg.h>
65 #include <dev/ic/smc91cxxvar.h>
66
67 #include <dev/isa/isavar.h>
68
69 int sm_isa_match(struct device *, struct cfdata *, void *);
70 void sm_isa_attach(struct device *, struct device *, void *);
71
72 struct sm_isa_softc {
73 struct smc91cxx_softc sc_smc; /* real "smc" softc */
74
75 /* ISA-specific goo. */
76 void *sc_ih; /* interrupt cookie */
77 };
78
79 CFATTACH_DECL(sm_isa, sizeof(struct sm_isa_softc),
80 sm_isa_match, sm_isa_attach, NULL, NULL);
81
82 int
83 sm_isa_match(struct device *parent, struct cfdata *match,
84 void *aux)
85 {
86 struct isa_attach_args *ia = aux;
87 bus_space_tag_t iot = ia->ia_iot;
88 bus_space_handle_t ioh;
89 u_int16_t tmp;
90 int rv = 0;
91 extern const char *smc91cxx_idstrs[];
92
93 if (ia->ia_nio < 1)
94 return (0);
95 if (ia->ia_nirq < 1)
96 return (0);
97
98 if (ISA_DIRECT_CONFIG(ia))
99 return (0);
100
101 /* Disallow wildcarded values. */
102 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
103 return (0);
104 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
105 return (0);
106
107 /* Map i/o space. */
108 if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
109 return (0);
110
111 /* Check that high byte of BANK_SELECT is what we expect. */
112 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
113 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
114 goto out;
115
116 /*
117 * Switch to bank 0 and perform the test again.
118 * XXX INVASIVE!
119 */
120 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0);
121 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
122 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
123 goto out;
124
125 /*
126 * Switch to bank 1 and check the base address register.
127 * XXX INVASIVE!
128 */
129 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1);
130 tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W);
131 if (ia->ia_io[0].ir_addr != ((tmp >> 3) & 0x3e0))
132 goto out;
133
134 /*
135 * Check for a recognized chip id.
136 * XXX INVASIVE!
137 */
138 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3);
139 tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
140 if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
141 goto out;
142
143 /*
144 * Assume we have an SMC91Cxx.
145 */
146 ia->ia_nio = 1;
147 ia->ia_io[0].ir_size = SMC_IOSIZE;
148
149 ia->ia_nirq = 1;
150
151 ia->ia_niomem = 0;
152 ia->ia_ndrq = 0;
153
154 rv = 1;
155
156 out:
157 bus_space_unmap(iot, ioh, SMC_IOSIZE);
158 return (rv);
159 }
160
161 void
162 sm_isa_attach(struct device *parent, struct device *self, void *aux)
163 {
164 struct sm_isa_softc *isc = (struct sm_isa_softc *)self;
165 struct smc91cxx_softc *sc = &isc->sc_smc;
166 struct isa_attach_args *ia = aux;
167 bus_space_tag_t iot = ia->ia_iot;
168 bus_space_handle_t ioh;
169
170 printf("\n");
171
172 /* Map i/o space. */
173 if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
174 panic("sm_isa_attach: can't map i/o space");
175
176 sc->sc_bst = iot;
177 sc->sc_bsh = ioh;
178
179 /* should always be enabled */
180 sc->sc_flags |= SMC_FLAGS_ENABLED;
181
182 /* XXX Should get Ethernet address from EEPROM!! */
183
184 /* Perform generic intialization. */
185 smc91cxx_attach(sc, NULL);
186
187 /* Establish the interrupt handler. */
188 isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
189 IST_EDGE, IPL_NET, smc91cxx_intr, sc);
190 if (isc->sc_ih == NULL)
191 printf("%s: couldn't establish interrupt handler\n",
192 sc->sc_dev.dv_xname);
193 }
194