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