if_ne_pci.c revision 1.15 1 /* $NetBSD: if_ne_pci.c,v 1.15 2000/03/06 03:07:08 mark Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998 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 "bpfilter.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/mbuf.h>
46 #include <sys/syslog.h>
47 #include <sys/socket.h>
48 #include <sys/device.h>
49
50 #include <net/if.h>
51 #include <net/if_ether.h>
52 #include <net/if_media.h>
53
54 #ifdef INET
55 #include <netinet/in.h>
56 #include <netinet/if_inarp.h>
57 #endif
58
59 #include <machine/bus.h>
60 #include <machine/intr.h>
61
62 #include <dev/pci/pcireg.h>
63 #include <dev/pci/pcivar.h>
64 #include <dev/pci/pcidevs.h>
65
66 #include <dev/ic/dp8390reg.h>
67 #include <dev/ic/dp8390var.h>
68
69 #include <dev/ic/ne2000reg.h>
70 #include <dev/ic/ne2000var.h>
71
72 #include <dev/ic/rtl80x9reg.h>
73 #include <dev/ic/rtl80x9var.h>
74
75 struct ne_pci_softc {
76 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
77
78 /* PCI-specific goo */
79 void *sc_ih; /* interrupt handle */
80 };
81
82 int ne_pci_match __P((struct device *, struct cfdata *, void *));
83 void ne_pci_attach __P((struct device *, struct device *, void *));
84
85 struct cfattach ne_pci_ca = {
86 sizeof(struct ne_pci_softc), ne_pci_match, ne_pci_attach
87 };
88
89 const struct ne_pci_product {
90 pci_vendor_id_t npp_vendor;
91 pci_product_id_t npp_product;
92 int (*npp_mediachange) __P((struct dp8390_softc *));
93 void (*npp_mediastatus) __P((struct dp8390_softc *,
94 struct ifmediareq *));
95 void (*npp_init_card) __P((struct dp8390_softc *));
96 void (*npp_init_media) __P((struct dp8390_softc *, int **,
97 int *, int *));
98 const char *npp_name;
99 } ne_pci_products[] = {
100 { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8029,
101 rtl80x9_mediachange, rtl80x9_mediastatus,
102 rtl80x9_init_card, rtl80x9_init_media,
103 "RealTek 8029" },
104
105 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C940F,
106 NULL, NULL,
107 NULL, NULL,
108 "Winbond 89C940F" },
109
110 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C940F_1,
111 NULL, NULL,
112 NULL, NULL,
113 "Winbond 89C940F" },
114
115 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT86C926,
116 NULL, NULL,
117 NULL, NULL,
118 "VIA Technologies VT86C926" },
119
120 { PCI_VENDOR_SURECOM, PCI_PRODUCT_SURECOM_NE34,
121 NULL, NULL,
122 NULL, NULL,
123 "Surecom NE-34" },
124
125 { PCI_VENDOR_NETVIN, PCI_PRODUCT_NETVIN_5000,
126 NULL, NULL,
127 NULL, NULL,
128 "NetVin 5000" },
129
130 /* XXX The following entries need sanity checking in pcidevs */
131 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_NE2KETHER,
132 NULL, NULL,
133 NULL, NULL,
134 "Compex" },
135
136 { PCI_VENDOR_PROLAN, PCI_PRODUCT_PROLAN_NE2KETHER,
137 NULL, NULL,
138 NULL, NULL,
139 "ProLAN" },
140
141 { PCI_VENDOR_KTI, PCI_PRODUCT_KTI_NE2KETHER,
142 NULL, NULL,
143 NULL, NULL,
144 "KTI" },
145
146 { 0, 0,
147 NULL, NULL,
148 NULL, NULL,
149 NULL },
150 };
151
152 const struct ne_pci_product *ne_pci_lookup
153 __P((const struct pci_attach_args *));
154
155 const struct ne_pci_product *
156 ne_pci_lookup(pa)
157 const struct pci_attach_args *pa;
158 {
159 const struct ne_pci_product *npp;
160
161 for (npp = ne_pci_products; npp->npp_name != NULL; npp++) {
162 if (PCI_VENDOR(pa->pa_id) == npp->npp_vendor &&
163 PCI_PRODUCT(pa->pa_id) == npp->npp_product)
164 return (npp);
165 }
166 return (NULL);
167 }
168
169 /*
170 * PCI constants.
171 * XXX These should be in a common file!
172 */
173 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
174
175 int
176 ne_pci_match(parent, match, aux)
177 struct device *parent;
178 struct cfdata *match;
179 void *aux;
180 {
181 struct pci_attach_args *pa = aux;
182
183 if (ne_pci_lookup(pa) != NULL)
184 return (1);
185
186 return (0);
187 }
188
189 void
190 ne_pci_attach(parent, self, aux)
191 struct device *parent, *self;
192 void *aux;
193 {
194 struct ne_pci_softc *psc = (struct ne_pci_softc *)self;
195 struct ne2000_softc *nsc = &psc->sc_ne2000;
196 struct dp8390_softc *dsc = &nsc->sc_dp8390;
197 struct pci_attach_args *pa = aux;
198 pci_chipset_tag_t pc = pa->pa_pc;
199 bus_space_tag_t nict;
200 bus_space_handle_t nich;
201 bus_space_tag_t asict;
202 bus_space_handle_t asich;
203 const char *intrstr;
204 const struct ne_pci_product *npp;
205 pci_intr_handle_t ih;
206 pcireg_t csr;
207 int *media, nmedia, defmedia;
208
209 npp = ne_pci_lookup(pa);
210 if (npp == NULL) {
211 printf("\n");
212 panic("ne_pci_attach: impossible");
213 }
214
215 printf(": %s Ethernet\n", npp->npp_name);
216
217 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
218 &nict, &nich, NULL, NULL)) {
219 printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
220 return;
221 }
222
223 asict = nict;
224 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
225 NE2000_ASIC_NPORTS, &asich)) {
226 printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
227 return;
228 }
229
230 dsc->sc_regt = nict;
231 dsc->sc_regh = nich;
232
233 nsc->sc_asict = asict;
234 nsc->sc_asich = asich;
235
236 /* Enable the card. */
237 csr = pci_conf_read(pc, pa->pa_tag,
238 PCI_COMMAND_STATUS_REG);
239 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
240 csr | PCI_COMMAND_MASTER_ENABLE);
241
242 /* This interface is always enabled. */
243 dsc->sc_enabled = 1;
244
245 if (npp->npp_init_media != NULL) {
246 (*npp->npp_init_media)(dsc, &media, &nmedia, &defmedia);
247 dsc->sc_mediachange = npp->npp_mediachange;
248 dsc->sc_mediastatus = npp->npp_mediastatus;
249 } else {
250 media = NULL;
251 nmedia = 0;
252 defmedia = 0;
253 }
254
255 /* Always fill in init_card; it might be used for non-media stuff. */
256 dsc->init_card = npp->npp_init_card;
257
258 /*
259 * Do generic NE2000 attach. This will read the station address
260 * from the EEPROM.
261 */
262 ne2000_attach(nsc, NULL, media, nmedia, defmedia);
263
264 /* Map and establish the interrupt. */
265 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
266 pa->pa_intrline, &ih)) {
267 printf("%s: couldn't map interrupt\n", dsc->sc_dev.dv_xname);
268 return;
269 }
270 intrstr = pci_intr_string(pc, ih);
271 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, dp8390_intr, dsc);
272 if (psc->sc_ih == NULL) {
273 printf("%s: couldn't establish interrupt",
274 dsc->sc_dev.dv_xname);
275 if (intrstr != NULL)
276 printf(" at %s", intrstr);
277 printf("\n");
278 return;
279 }
280 printf("%s: interrupting at %s\n", dsc->sc_dev.dv_xname, intrstr);
281 }
282