if_ne_mca.c revision 1.2.4.3 1 1.2.4.3 nathanw /* $NetBSD: if_ne_mca.c,v 1.2.4.3 2001/11/14 19:15:00 nathanw Exp $ */
2 1.2.4.2 nathanw
3 1.2.4.2 nathanw /*-
4 1.2.4.2 nathanw * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.2.4.2 nathanw * All rights reserved.
6 1.2.4.2 nathanw *
7 1.2.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.2.4.2 nathanw * by Jaromir Dolecek.
9 1.2.4.2 nathanw *
10 1.2.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.2.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.2.4.2 nathanw * are met:
13 1.2.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.2.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.2.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.2.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.2.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.2.4.2 nathanw * must display the following acknowledgement:
20 1.2.4.2 nathanw * This product includes software developed by the NetBSD
21 1.2.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.2.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.2.4.2 nathanw * from this software without specific prior written permission.
25 1.2.4.2 nathanw *
26 1.2.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.2.4.2 nathanw */
38 1.2.4.2 nathanw
39 1.2.4.2 nathanw /*
40 1.2.4.2 nathanw * Driver for Novell NE/2 Ethernet Adapter (and clones).
41 1.2.4.2 nathanw *
42 1.2.4.2 nathanw * According to Linux ne2 driver, Arco and Compex card should be also
43 1.2.4.2 nathanw * supported by this driver. However, NetBSD driver was only tested
44 1.2.4.2 nathanw * with the Novell adapter so far.
45 1.2.4.2 nathanw */
46 1.2.4.2 nathanw
47 1.2.4.3 nathanw #include <sys/cdefs.h>
48 1.2.4.3 nathanw __KERNEL_RCSID(0, "$NetBSD: if_ne_mca.c,v 1.2.4.3 2001/11/14 19:15:00 nathanw Exp $");
49 1.2.4.3 nathanw
50 1.2.4.2 nathanw #include <sys/param.h>
51 1.2.4.2 nathanw #include <sys/systm.h>
52 1.2.4.2 nathanw #include <sys/mbuf.h>
53 1.2.4.2 nathanw #include <sys/errno.h>
54 1.2.4.2 nathanw #include <sys/device.h>
55 1.2.4.2 nathanw #include <sys/protosw.h>
56 1.2.4.2 nathanw #include <sys/socket.h>
57 1.2.4.2 nathanw
58 1.2.4.2 nathanw #include <net/if.h>
59 1.2.4.2 nathanw #include <net/if_types.h>
60 1.2.4.2 nathanw #include <net/if_media.h>
61 1.2.4.2 nathanw #include <net/if_ether.h>
62 1.2.4.2 nathanw
63 1.2.4.2 nathanw #include <machine/bus.h>
64 1.2.4.2 nathanw
65 1.2.4.2 nathanw #include <dev/ic/dp8390reg.h>
66 1.2.4.2 nathanw #include <dev/ic/dp8390var.h>
67 1.2.4.2 nathanw
68 1.2.4.2 nathanw #include <dev/ic/ne2000reg.h>
69 1.2.4.2 nathanw #include <dev/ic/ne2000var.h>
70 1.2.4.2 nathanw
71 1.2.4.2 nathanw #include <dev/ic/rtl80x9reg.h>
72 1.2.4.2 nathanw #include <dev/ic/rtl80x9var.h>
73 1.2.4.2 nathanw
74 1.2.4.2 nathanw #include <dev/mca/mcadevs.h>
75 1.2.4.2 nathanw #include <dev/mca/mcavar.h>
76 1.2.4.2 nathanw
77 1.2.4.2 nathanw #define NE2_NPORTS 0x30
78 1.2.4.2 nathanw
79 1.2.4.2 nathanw struct ne_mca_softc {
80 1.2.4.2 nathanw struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
81 1.2.4.2 nathanw
82 1.2.4.2 nathanw /* MCA-specific goo */
83 1.2.4.2 nathanw void *sc_ih; /* interrupt handle */
84 1.2.4.2 nathanw };
85 1.2.4.2 nathanw
86 1.2.4.2 nathanw int ne_mca_match __P((struct device *, struct cfdata *, void *));
87 1.2.4.2 nathanw void ne_mca_attach __P((struct device *, struct device *, void *));
88 1.2.4.2 nathanw
89 1.2.4.2 nathanw struct cfattach ne_mca_ca = {
90 1.2.4.2 nathanw sizeof(struct ne_mca_softc), ne_mca_match, ne_mca_attach
91 1.2.4.2 nathanw };
92 1.2.4.2 nathanw
93 1.2.4.2 nathanw static const struct ne_mca_products {
94 1.2.4.2 nathanw u_int32_t ne_id;
95 1.2.4.2 nathanw const char *ne_name;
96 1.2.4.2 nathanw } ne_mca_products[] = {
97 1.2.4.2 nathanw { MCA_PRODUCT_ARCOAE, "Arco Electronics AE/2 Ethernet Adapter" },
98 1.2.4.2 nathanw { MCA_PRODUCT_NE2, "Novell NE/2 Ethernet Adapter" },
99 1.2.4.2 nathanw { MCA_PRODUCT_CENET16, "Compex Inc. PS/2 ENET16-MC/P Microchannel Ad."},
100 1.2.4.2 nathanw { 0, NULL }
101 1.2.4.2 nathanw };
102 1.2.4.2 nathanw
103 1.2.4.2 nathanw static const struct ne_mca_products *ne_mca_lookup __P((int id));
104 1.2.4.2 nathanw
105 1.2.4.2 nathanw static const struct ne_mca_products *
106 1.2.4.2 nathanw ne_mca_lookup(int id)
107 1.2.4.2 nathanw {
108 1.2.4.2 nathanw const struct ne_mca_products *np;
109 1.2.4.2 nathanw
110 1.2.4.2 nathanw for(np = ne_mca_products; np->ne_name; np++)
111 1.2.4.2 nathanw if (id == np->ne_id)
112 1.2.4.2 nathanw return (np);
113 1.2.4.2 nathanw
114 1.2.4.2 nathanw return (NULL);
115 1.2.4.2 nathanw }
116 1.2.4.2 nathanw
117 1.2.4.2 nathanw int
118 1.2.4.2 nathanw ne_mca_match(struct device *parent, struct cfdata *cf, void *aux)
119 1.2.4.2 nathanw {
120 1.2.4.2 nathanw struct mca_attach_args *ma = aux;
121 1.2.4.2 nathanw
122 1.2.4.2 nathanw if (ne_mca_lookup(ma->ma_id))
123 1.2.4.2 nathanw return (1);
124 1.2.4.2 nathanw
125 1.2.4.2 nathanw return (0);
126 1.2.4.2 nathanw }
127 1.2.4.2 nathanw
128 1.2.4.2 nathanw /* These values were taken from NE/2 ADF file */
129 1.2.4.2 nathanw static const int ne_mca_irq[] = {
130 1.2.4.2 nathanw 3, 4, 5, 9
131 1.2.4.2 nathanw };
132 1.2.4.2 nathanw static const int ne_mca_iobase[] = {
133 1.2.4.2 nathanw 0, 0x1000, 0x2020, 0x8020, 0xa0a0, 0xb0b0, 0xc0c0, 0xc3d0
134 1.2.4.2 nathanw };
135 1.2.4.2 nathanw
136 1.2.4.2 nathanw void
137 1.2.4.2 nathanw ne_mca_attach(struct device *parent, struct device *self, void *aux)
138 1.2.4.2 nathanw {
139 1.2.4.2 nathanw struct ne_mca_softc *psc = (struct ne_mca_softc *)self;
140 1.2.4.2 nathanw struct ne2000_softc *nsc = &psc->sc_ne2000;
141 1.2.4.2 nathanw struct dp8390_softc *dsc = &nsc->sc_dp8390;
142 1.2.4.2 nathanw struct mca_attach_args *ma = aux;
143 1.2.4.2 nathanw bus_space_tag_t nict;
144 1.2.4.2 nathanw bus_space_handle_t nich;
145 1.2.4.2 nathanw bus_space_tag_t asict;
146 1.2.4.2 nathanw bus_space_handle_t asich;
147 1.2.4.2 nathanw int pos2, iobase, irq;
148 1.2.4.2 nathanw const struct ne_mca_products *np;
149 1.2.4.2 nathanw
150 1.2.4.2 nathanw pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
151 1.2.4.2 nathanw
152 1.2.4.2 nathanw /*
153 1.2.4.2 nathanw * POS register 2: (adf pos0)
154 1.2.4.2 nathanw *
155 1.2.4.2 nathanw * 7 6 5 4 3 2 1 0
156 1.2.4.2 nathanw * \_/ | \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
157 1.2.4.2 nathanw * | | \____ I/O, Mem: 001=0x1000-0x102f 010=0x2020-0x204f
158 1.2.4.2 nathanw * | | 011=0x8020-0x804f 100=0xa0a0-0xa0cf
159 1.2.4.2 nathanw * | | 101=0xb0b0-0xb0df 110=0xc0c0-0xc0ef
160 1.2.4.2 nathanw * \ \ 111=0xc3d0-0xc3ff
161 1.2.4.2 nathanw * \ \________ Boot Rom: 1=disabled 0=enabled
162 1.2.4.2 nathanw * \__________ Interrupt level: 00=3 01=4 10=5 11=9
163 1.2.4.2 nathanw */
164 1.2.4.2 nathanw
165 1.2.4.2 nathanw np = ne_mca_lookup(ma->ma_id);
166 1.2.4.2 nathanw
167 1.2.4.2 nathanw iobase = ne_mca_iobase[(pos2 & 0x0e) >> 1];
168 1.2.4.2 nathanw irq = ne_mca_irq[(pos2 & 0x60) >> 5];
169 1.2.4.2 nathanw
170 1.2.4.2 nathanw printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, np->ne_name);
171 1.2.4.2 nathanw
172 1.2.4.2 nathanw nict = ma->ma_iot;
173 1.2.4.2 nathanw
174 1.2.4.2 nathanw /* Map the device. */
175 1.2.4.2 nathanw if (bus_space_map(nict, iobase, NE2_NPORTS, 0, &nich)) {
176 1.2.4.2 nathanw printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
177 1.2.4.2 nathanw return;
178 1.2.4.2 nathanw }
179 1.2.4.2 nathanw
180 1.2.4.2 nathanw asict = nict;
181 1.2.4.2 nathanw if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
182 1.2.4.2 nathanw NE2000_ASIC_NPORTS, &asich)) {
183 1.2.4.2 nathanw printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
184 1.2.4.2 nathanw return;
185 1.2.4.2 nathanw }
186 1.2.4.2 nathanw
187 1.2.4.2 nathanw dsc->sc_regt = nict;
188 1.2.4.2 nathanw dsc->sc_regh = nich;
189 1.2.4.2 nathanw
190 1.2.4.2 nathanw nsc->sc_asict = asict;
191 1.2.4.2 nathanw nsc->sc_asich = asich;
192 1.2.4.2 nathanw
193 1.2.4.2 nathanw /* This interface is always enabled. */
194 1.2.4.2 nathanw dsc->sc_enabled = 1;
195 1.2.4.2 nathanw
196 1.2.4.2 nathanw dsc->sc_mediachange = NULL;
197 1.2.4.2 nathanw dsc->sc_mediastatus = NULL;
198 1.2.4.2 nathanw dsc->sc_media_init = NULL;
199 1.2.4.2 nathanw dsc->init_card = NULL;
200 1.2.4.2 nathanw
201 1.2.4.2 nathanw /*
202 1.2.4.2 nathanw * This is necessary for NE/2. Hopefully the other clones also work
203 1.2.4.2 nathanw * this way.
204 1.2.4.2 nathanw */
205 1.2.4.2 nathanw nsc->sc_type = NE2000_TYPE_AX88190;
206 1.2.4.2 nathanw
207 1.2.4.2 nathanw /*
208 1.2.4.2 nathanw * Do generic NE2000 attach. This will read the station address
209 1.2.4.2 nathanw * from the EEPROM.
210 1.2.4.2 nathanw */
211 1.2.4.2 nathanw if (ne2000_attach(nsc, NULL))
212 1.2.4.2 nathanw return;
213 1.2.4.2 nathanw
214 1.2.4.2 nathanw /* establish interrupt handler */
215 1.2.4.2 nathanw psc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, dp8390_intr,
216 1.2.4.2 nathanw dsc);
217 1.2.4.2 nathanw if (psc->sc_ih == NULL) {
218 1.2.4.2 nathanw printf("%s: couldn't establish interrupt handler\n",
219 1.2.4.2 nathanw dsc->sc_dev.dv_xname);
220 1.2.4.2 nathanw return;
221 1.2.4.2 nathanw }
222 1.2.4.2 nathanw }
223