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