if_ex_pci.c revision 1.15.2.1 1 1.15.2.1 nathanw /* $NetBSD: if_ex_pci.c,v 1.15.2.1 2001/06/21 20:04:42 nathanw Exp $ */
2 1.1 fvdl
3 1.1 fvdl /*-
4 1.1 fvdl * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 fvdl * All rights reserved.
6 1.1 fvdl *
7 1.1 fvdl * This code is derived from software contributed to The NetBSD Foundation
8 1.3 thorpej * by Frank van der Linden; Jason R. Thorpe of the Numerical Aerospace
9 1.3 thorpej * Simulation Facility, NASA Ames Research Center.
10 1.1 fvdl *
11 1.1 fvdl * Redistribution and use in source and binary forms, with or without
12 1.1 fvdl * modification, are permitted provided that the following conditions
13 1.1 fvdl * are met:
14 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
15 1.1 fvdl * notice, this list of conditions and the following disclaimer.
16 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
18 1.1 fvdl * documentation and/or other materials provided with the distribution.
19 1.1 fvdl * 3. All advertising materials mentioning features or use of this software
20 1.1 fvdl * must display the following acknowledgement:
21 1.1 fvdl * This product includes software developed by the NetBSD
22 1.1 fvdl * Foundation, Inc. and its contributors.
23 1.1 fvdl * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 fvdl * contributors may be used to endorse or promote products derived
25 1.1 fvdl * from this software without specific prior written permission.
26 1.1 fvdl *
27 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 fvdl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 fvdl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 fvdl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 fvdl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 fvdl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 fvdl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 fvdl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 fvdl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 fvdl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 fvdl * POSSIBILITY OF SUCH DAMAGE.
38 1.1 fvdl */
39 1.1 fvdl
40 1.1 fvdl #include "bpfilter.h"
41 1.1 fvdl
42 1.1 fvdl #include <sys/param.h>
43 1.1 fvdl #include <sys/systm.h>
44 1.1 fvdl #include <sys/mbuf.h>
45 1.1 fvdl #include <sys/socket.h>
46 1.1 fvdl #include <sys/ioctl.h>
47 1.1 fvdl #include <sys/errno.h>
48 1.1 fvdl #include <sys/syslog.h>
49 1.1 fvdl #include <sys/select.h>
50 1.1 fvdl #include <sys/device.h>
51 1.1 fvdl
52 1.1 fvdl #include <net/if.h>
53 1.1 fvdl #include <net/if_dl.h>
54 1.1 fvdl #include <net/if_ether.h>
55 1.1 fvdl #include <net/if_media.h>
56 1.1 fvdl
57 1.1 fvdl #if NBPFILTER > 0
58 1.1 fvdl #include <net/bpf.h>
59 1.1 fvdl #include <net/bpfdesc.h>
60 1.1 fvdl #endif
61 1.1 fvdl
62 1.1 fvdl #include <machine/cpu.h>
63 1.1 fvdl #include <machine/bus.h>
64 1.1 fvdl #include <machine/intr.h>
65 1.1 fvdl
66 1.1 fvdl #include <dev/mii/miivar.h>
67 1.1 fvdl #include <dev/mii/mii.h>
68 1.1 fvdl
69 1.1 fvdl #include <dev/ic/elink3var.h>
70 1.1 fvdl #include <dev/ic/elink3reg.h>
71 1.1 fvdl #include <dev/ic/elinkxlreg.h>
72 1.1 fvdl #include <dev/ic/elinkxlvar.h>
73 1.1 fvdl
74 1.1 fvdl #include <dev/pci/pcivar.h>
75 1.1 fvdl #include <dev/pci/pcireg.h>
76 1.1 fvdl #include <dev/pci/pcidevs.h>
77 1.1 fvdl
78 1.14 fvdl struct ex_pci_softc {
79 1.14 fvdl struct ex_softc sc_ex;
80 1.14 fvdl pci_chipset_tag_t sc_chiptag;
81 1.14 fvdl pcitag_t sc_pcitag;
82 1.14 fvdl };
83 1.14 fvdl
84 1.1 fvdl /*
85 1.1 fvdl * PCI constants.
86 1.1 fvdl * XXX These should be in a common file!
87 1.1 fvdl */
88 1.1 fvdl #define PCI_CONN 0x48 /* Connector type */
89 1.1 fvdl #define PCI_CBIO 0x10 /* Configuration Base IO Address */
90 1.1 fvdl #define PCI_POWERCTL 0xe0
91 1.14 fvdl #define PCI_FUNCMEM 0x18
92 1.14 fvdl
93 1.14 fvdl #define PCI_INTRACK 0x00008000
94 1.1 fvdl
95 1.1 fvdl int ex_pci_match __P((struct device *, struct cfdata *, void *));
96 1.1 fvdl void ex_pci_attach __P((struct device *, struct device *, void *));
97 1.14 fvdl void ex_pci_intr_ack __P((struct ex_softc *));
98 1.1 fvdl
99 1.1 fvdl struct cfattach ex_pci_ca = {
100 1.14 fvdl sizeof(struct ex_pci_softc), ex_pci_match, ex_pci_attach
101 1.1 fvdl };
102 1.1 fvdl
103 1.3 thorpej const struct ex_pci_product {
104 1.3 thorpej u_int32_t epp_prodid; /* PCI product ID */
105 1.3 thorpej int epp_flags; /* initial softc flags */
106 1.3 thorpej const char *epp_name; /* device name */
107 1.3 thorpej } ex_pci_products[] = {
108 1.3 thorpej { PCI_PRODUCT_3COM_3C900TPO, 0,
109 1.4 thorpej "3c900-TPO Ethernet" },
110 1.3 thorpej { PCI_PRODUCT_3COM_3C900COMBO, 0,
111 1.4 thorpej "3c900-COMBO Ethernet" },
112 1.3 thorpej
113 1.3 thorpej { PCI_PRODUCT_3COM_3C905TX, EX_CONF_MII,
114 1.4 thorpej "3c905-TX 10/100 Ethernet" },
115 1.3 thorpej { PCI_PRODUCT_3COM_3C905T4, EX_CONF_MII,
116 1.4 thorpej "3c905-T4 10/100 Ethernet" },
117 1.3 thorpej
118 1.3 thorpej { PCI_PRODUCT_3COM_3C900BTPO, EX_CONF_90XB,
119 1.4 thorpej "3c900B-TPO Ethernet" },
120 1.3 thorpej { PCI_PRODUCT_3COM_3C900BCOMBO, EX_CONF_90XB,
121 1.4 thorpej "3c900B-COMBO Ethernet" },
122 1.6 fvdl { PCI_PRODUCT_3COM_3C900BTPC, EX_CONF_90XB,
123 1.6 fvdl "3c900B-TPC Ethernet" },
124 1.3 thorpej
125 1.3 thorpej { PCI_PRODUCT_3COM_3C905BTX, EX_CONF_90XB|EX_CONF_MII|EX_CONF_INTPHY,
126 1.4 thorpej "3c905B-TX 10/100 Ethernet" },
127 1.3 thorpej { PCI_PRODUCT_3COM_3C905BT4, EX_CONF_90XB|EX_CONF_MII,
128 1.4 thorpej "3c905B-T4 10/100 Ethernet" },
129 1.9 drochner { PCI_PRODUCT_3COM_3C905BCOMBO, EX_CONF_90XB/*|EX_CONF_MII|EX_CONF_INTPHY*/,
130 1.9 drochner "3c905B-COMBO 10/100 Ethernet" },
131 1.8 fvdl { PCI_PRODUCT_3COM_3C905BFX, EX_CONF_90XB,
132 1.4 thorpej "3c905B-FX 10/100 Ethernet" },
133 1.4 thorpej
134 1.4 thorpej /* XXX Internal PHY? */
135 1.10 mycroft { PCI_PRODUCT_3COM_3C980SRV, EX_CONF_90XB,
136 1.4 thorpej "3c980 Server Adapter 10/100 Ethernet" },
137 1.12 thorpej { PCI_PRODUCT_3COM_3C980CTXM, EX_CONF_90XB,
138 1.12 thorpej "3c980C-TXM 10/100 Ethernet" },
139 1.12 thorpej
140 1.7 ross { PCI_PRODUCT_3COM_3C905CTX, EX_CONF_90XB|EX_CONF_MII,
141 1.7 ross "3c905C-TX 10/100 Ethernet with mngmt" },
142 1.13 billc
143 1.13 billc { PCI_PRODUCT_3COM_3C450TX, EX_CONF_90XB,
144 1.13 billc "3c450-TX 10/100 Ethernet" },
145 1.13 billc
146 1.13 billc { PCI_PRODUCT_3COM_3CSOHO100TX, EX_CONF_90XB,
147 1.13 billc "3cSOHO100-TX 10/100 Ethernet" },
148 1.3 thorpej
149 1.14 fvdl { PCI_PRODUCT_3COM_3C555,
150 1.14 fvdl EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
151 1.14 fvdl EX_CONF_EEPROM_8BIT,
152 1.14 fvdl "3c555 MiniPCI 10/100 Ethernet" },
153 1.14 fvdl
154 1.14 fvdl { PCI_PRODUCT_3COM_3C556,
155 1.14 fvdl EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
156 1.14 fvdl EX_CONF_PCI_FUNCREG | EX_CONF_RESETHACK | EX_CONF_INV_LED_POLARITY |
157 1.14 fvdl EX_CONF_PHY_POWER | EX_CONF_EEPROM_8BIT,
158 1.14 fvdl "3c556 MiniPCI 10/100 Ethernet" },
159 1.14 fvdl
160 1.14 fvdl { PCI_PRODUCT_3COM_3C556B,
161 1.14 fvdl EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
162 1.14 fvdl EX_CONF_PCI_FUNCREG | EX_CONF_RESETHACK | EX_CONF_INV_LED_POLARITY |
163 1.14 fvdl EX_CONF_PHY_POWER,
164 1.14 fvdl "3c556B MiniPCI 10/100 Ethernet" },
165 1.14 fvdl
166 1.3 thorpej { 0, 0,
167 1.3 thorpej NULL },
168 1.3 thorpej };
169 1.3 thorpej
170 1.3 thorpej const struct ex_pci_product *ex_pci_lookup
171 1.3 thorpej __P((const struct pci_attach_args *));
172 1.3 thorpej
173 1.3 thorpej const struct ex_pci_product *
174 1.3 thorpej ex_pci_lookup(pa)
175 1.3 thorpej const struct pci_attach_args *pa;
176 1.3 thorpej {
177 1.3 thorpej const struct ex_pci_product *epp;
178 1.3 thorpej
179 1.3 thorpej if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
180 1.3 thorpej return (NULL);
181 1.3 thorpej
182 1.3 thorpej for (epp = ex_pci_products; epp->epp_name != NULL; epp++)
183 1.3 thorpej if (PCI_PRODUCT(pa->pa_id) == epp->epp_prodid)
184 1.3 thorpej return (epp);
185 1.3 thorpej return (NULL);
186 1.3 thorpej }
187 1.3 thorpej
188 1.1 fvdl int
189 1.1 fvdl ex_pci_match(parent, match, aux)
190 1.1 fvdl struct device *parent;
191 1.1 fvdl struct cfdata *match;
192 1.1 fvdl void *aux;
193 1.1 fvdl {
194 1.1 fvdl struct pci_attach_args *pa = (struct pci_attach_args *) aux;
195 1.1 fvdl
196 1.3 thorpej if (ex_pci_lookup(pa) != NULL)
197 1.3 thorpej return (2); /* beat ep_pci */
198 1.1 fvdl
199 1.3 thorpej return (0);
200 1.1 fvdl }
201 1.1 fvdl
202 1.1 fvdl void
203 1.1 fvdl ex_pci_attach(parent, self, aux)
204 1.1 fvdl struct device *parent, *self;
205 1.1 fvdl void *aux;
206 1.1 fvdl {
207 1.1 fvdl struct ex_softc *sc = (void *)self;
208 1.14 fvdl struct ex_pci_softc *psc = (void *)self;
209 1.1 fvdl struct pci_attach_args *pa = aux;
210 1.1 fvdl pci_chipset_tag_t pc = pa->pa_pc;
211 1.1 fvdl pci_intr_handle_t ih;
212 1.3 thorpej const struct ex_pci_product *epp;
213 1.1 fvdl const char *intrstr = NULL;
214 1.11 mycroft int rev, pmreg;
215 1.11 mycroft pcireg_t reg;
216 1.1 fvdl
217 1.1 fvdl if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
218 1.1 fvdl &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
219 1.1 fvdl printf(": can't map i/o space\n");
220 1.1 fvdl return;
221 1.1 fvdl }
222 1.1 fvdl
223 1.3 thorpej epp = ex_pci_lookup(pa);
224 1.3 thorpej if (epp == NULL) {
225 1.3 thorpej printf("\n");
226 1.3 thorpej panic("ex_pci_attach: impossible");
227 1.1 fvdl }
228 1.1 fvdl
229 1.9 drochner rev = PCI_REVISION(pci_conf_read(pc, pa->pa_tag, PCI_CLASS_REG));
230 1.9 drochner printf(": 3Com %s (rev. 0x%x)\n", epp->epp_name, rev);
231 1.1 fvdl
232 1.1 fvdl sc->enable = NULL;
233 1.1 fvdl sc->disable = NULL;
234 1.1 fvdl sc->enabled = 1;
235 1.1 fvdl
236 1.3 thorpej sc->sc_dmat = pa->pa_dmat;
237 1.3 thorpej
238 1.3 thorpej sc->ex_bustype = EX_BUS_PCI;
239 1.3 thorpej sc->ex_conf = epp->epp_flags;
240 1.3 thorpej
241 1.1 fvdl /* Enable the card. */
242 1.1 fvdl pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
243 1.1 fvdl pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
244 1.1 fvdl PCI_COMMAND_MASTER_ENABLE);
245 1.1 fvdl
246 1.1 fvdl /* Get it out of power save mode if needed (BIOS bugs) */
247 1.11 mycroft if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, &pmreg, 0)) {
248 1.11 mycroft reg = pci_conf_read(pc, pa->pa_tag, pmreg + 4) & 0x3;
249 1.11 mycroft if (reg == 3) {
250 1.1 fvdl /*
251 1.1 fvdl * The card has lost all configuration data in
252 1.1 fvdl * this state, so punt.
253 1.1 fvdl */
254 1.1 fvdl printf("%s: unable to wake up from power state D3\n",
255 1.1 fvdl sc->sc_dev.dv_xname);
256 1.1 fvdl return;
257 1.1 fvdl }
258 1.11 mycroft if (reg != 0) {
259 1.1 fvdl printf("%s: waking up from power state D%d\n",
260 1.11 mycroft sc->sc_dev.dv_xname, reg);
261 1.11 mycroft pci_conf_write(pc, pa->pa_tag, pmreg + 4, 0);
262 1.1 fvdl }
263 1.1 fvdl }
264 1.1 fvdl
265 1.1 fvdl /* Map and establish the interrupt. */
266 1.15 sommerfe if (pci_intr_map(pa, &ih)) {
267 1.1 fvdl printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
268 1.1 fvdl return;
269 1.1 fvdl }
270 1.14 fvdl
271 1.14 fvdl if (sc->ex_conf & EX_CONF_PCI_FUNCREG) {
272 1.14 fvdl sc->intr_ack = ex_pci_intr_ack;
273 1.14 fvdl psc->sc_chiptag = pa->pa_pc;
274 1.14 fvdl psc->sc_pcitag = pa->pa_tag;
275 1.14 fvdl }
276 1.14 fvdl
277 1.1 fvdl intrstr = pci_intr_string(pc, ih);
278 1.1 fvdl sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ex_intr, sc);
279 1.1 fvdl if (sc->sc_ih == NULL) {
280 1.1 fvdl printf("%s: couldn't establish interrupt",
281 1.1 fvdl sc->sc_dev.dv_xname);
282 1.1 fvdl if (intrstr != NULL)
283 1.1 fvdl printf(" at %s", intrstr);
284 1.1 fvdl printf("\n");
285 1.1 fvdl return;
286 1.1 fvdl }
287 1.1 fvdl printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
288 1.1 fvdl
289 1.1 fvdl ex_config(sc);
290 1.14 fvdl }
291 1.14 fvdl
292 1.14 fvdl void
293 1.14 fvdl ex_pci_intr_ack(sc)
294 1.14 fvdl struct ex_softc *sc;
295 1.14 fvdl {
296 1.14 fvdl struct ex_pci_softc *psc = (struct ex_pci_softc *)sc;
297 1.14 fvdl
298 1.14 fvdl pci_conf_write(psc->sc_chiptag, psc->sc_pcitag, PCI_FUNCMEM + 4,
299 1.14 fvdl PCI_INTRACK);
300 1.1 fvdl }
301