if_ex_pci.c revision 1.1 1 1.1 fvdl /* $NetBSD: if_ex_pci.c,v 1.1 1998/11/04 00:31:05 fvdl 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.1 fvdl * by Frank van der Linden.
9 1.1 fvdl *
10 1.1 fvdl * Redistribution and use in source and binary forms, with or without
11 1.1 fvdl * modification, are permitted provided that the following conditions
12 1.1 fvdl * are met:
13 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
14 1.1 fvdl * notice, this list of conditions and the following disclaimer.
15 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
17 1.1 fvdl * documentation and/or other materials provided with the distribution.
18 1.1 fvdl * 3. All advertising materials mentioning features or use of this software
19 1.1 fvdl * must display the following acknowledgement:
20 1.1 fvdl * This product includes software developed by the NetBSD
21 1.1 fvdl * Foundation, Inc. and its contributors.
22 1.1 fvdl * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 fvdl * contributors may be used to endorse or promote products derived
24 1.1 fvdl * from this software without specific prior written permission.
25 1.1 fvdl *
26 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 fvdl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 fvdl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 fvdl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 fvdl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 fvdl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 fvdl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 fvdl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 fvdl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 fvdl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 fvdl * POSSIBILITY OF SUCH DAMAGE.
37 1.1 fvdl */
38 1.1 fvdl
39 1.1 fvdl #include "opt_inet.h"
40 1.1 fvdl #include "opt_ns.h"
41 1.1 fvdl #include "bpfilter.h"
42 1.1 fvdl
43 1.1 fvdl #include <sys/param.h>
44 1.1 fvdl #include <sys/systm.h>
45 1.1 fvdl #include <sys/mbuf.h>
46 1.1 fvdl #include <sys/socket.h>
47 1.1 fvdl #include <sys/ioctl.h>
48 1.1 fvdl #include <sys/errno.h>
49 1.1 fvdl #include <sys/syslog.h>
50 1.1 fvdl #include <sys/select.h>
51 1.1 fvdl #include <sys/device.h>
52 1.1 fvdl
53 1.1 fvdl #include <net/if.h>
54 1.1 fvdl #include <net/if_dl.h>
55 1.1 fvdl #include <net/if_ether.h>
56 1.1 fvdl #include <net/if_media.h>
57 1.1 fvdl
58 1.1 fvdl #ifdef INET
59 1.1 fvdl #include <netinet/in.h>
60 1.1 fvdl #include <netinet/in_systm.h>
61 1.1 fvdl #include <netinet/in_var.h>
62 1.1 fvdl #include <netinet/ip.h>
63 1.1 fvdl #include <netinet/if_inarp.h>
64 1.1 fvdl #endif
65 1.1 fvdl
66 1.1 fvdl #ifdef NS
67 1.1 fvdl #include <netns/ns.h>
68 1.1 fvdl #include <netns/ns_if.h>
69 1.1 fvdl #endif
70 1.1 fvdl
71 1.1 fvdl #if NBPFILTER > 0
72 1.1 fvdl #include <net/bpf.h>
73 1.1 fvdl #include <net/bpfdesc.h>
74 1.1 fvdl #endif
75 1.1 fvdl
76 1.1 fvdl #include <machine/cpu.h>
77 1.1 fvdl #include <machine/bus.h>
78 1.1 fvdl #include <machine/intr.h>
79 1.1 fvdl
80 1.1 fvdl #include <dev/mii/miivar.h>
81 1.1 fvdl #include <dev/mii/mii.h>
82 1.1 fvdl
83 1.1 fvdl #include <dev/ic/elink3var.h>
84 1.1 fvdl #include <dev/ic/elink3reg.h>
85 1.1 fvdl #include <dev/ic/elinkxlreg.h>
86 1.1 fvdl #include <dev/ic/elinkxlvar.h>
87 1.1 fvdl
88 1.1 fvdl #include <dev/pci/pcivar.h>
89 1.1 fvdl #include <dev/pci/pcireg.h>
90 1.1 fvdl #include <dev/pci/pcidevs.h>
91 1.1 fvdl
92 1.1 fvdl /*
93 1.1 fvdl * PCI constants.
94 1.1 fvdl * XXX These should be in a common file!
95 1.1 fvdl */
96 1.1 fvdl #define PCI_CONN 0x48 /* Connector type */
97 1.1 fvdl #define PCI_CBIO 0x10 /* Configuration Base IO Address */
98 1.1 fvdl #define PCI_CAPPTR 0x34
99 1.1 fvdl #define PCI_CAPID 0xdc
100 1.1 fvdl #define PCI_POWERCAP 0xde
101 1.1 fvdl #define PCI_POWERCTL 0xe0
102 1.1 fvdl
103 1.1 fvdl int ex_pci_match __P((struct device *, struct cfdata *, void *));
104 1.1 fvdl void ex_pci_attach __P((struct device *, struct device *, void *));
105 1.1 fvdl
106 1.1 fvdl struct cfattach ex_pci_ca = {
107 1.1 fvdl sizeof(struct ex_softc), ex_pci_match, ex_pci_attach
108 1.1 fvdl };
109 1.1 fvdl
110 1.1 fvdl int
111 1.1 fvdl ex_pci_match(parent, match, aux)
112 1.1 fvdl struct device *parent;
113 1.1 fvdl struct cfdata *match;
114 1.1 fvdl void *aux;
115 1.1 fvdl {
116 1.1 fvdl struct pci_attach_args *pa = (struct pci_attach_args *) aux;
117 1.1 fvdl
118 1.1 fvdl if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
119 1.1 fvdl return 0;
120 1.1 fvdl
121 1.1 fvdl switch (PCI_PRODUCT(pa->pa_id)) {
122 1.1 fvdl case PCI_PRODUCT_3COM_3C900TPO:
123 1.1 fvdl case PCI_PRODUCT_3COM_3C900COMBO:
124 1.1 fvdl case PCI_PRODUCT_3COM_3C905TX:
125 1.1 fvdl case PCI_PRODUCT_3COM_3C905T4:
126 1.1 fvdl case PCI_PRODUCT_3COM_3C900BTPO:
127 1.1 fvdl case PCI_PRODUCT_3COM_3C900BCOMBO:
128 1.1 fvdl case PCI_PRODUCT_3COM_3C905BT4:
129 1.1 fvdl case PCI_PRODUCT_3COM_3C905BTX:
130 1.1 fvdl break;
131 1.1 fvdl default:
132 1.1 fvdl return 0;
133 1.1 fvdl }
134 1.1 fvdl
135 1.1 fvdl return 1;
136 1.1 fvdl }
137 1.1 fvdl
138 1.1 fvdl void
139 1.1 fvdl ex_pci_attach(parent, self, aux)
140 1.1 fvdl struct device *parent, *self;
141 1.1 fvdl void *aux;
142 1.1 fvdl {
143 1.1 fvdl struct ex_softc *sc = (void *)self;
144 1.1 fvdl struct pci_attach_args *pa = aux;
145 1.1 fvdl pci_chipset_tag_t pc = pa->pa_pc;
146 1.1 fvdl pci_intr_handle_t ih;
147 1.1 fvdl char *model;
148 1.1 fvdl const char *intrstr = NULL;
149 1.1 fvdl int pmode;
150 1.1 fvdl
151 1.1 fvdl if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
152 1.1 fvdl &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
153 1.1 fvdl printf(": can't map i/o space\n");
154 1.1 fvdl return;
155 1.1 fvdl }
156 1.1 fvdl
157 1.1 fvdl sc->sc_dmat = pa->pa_dmat;
158 1.1 fvdl
159 1.1 fvdl sc->ex_bustype = EX_BUS_PCI;
160 1.1 fvdl sc->ex_conf = 0;
161 1.1 fvdl
162 1.1 fvdl switch (PCI_PRODUCT(pa->pa_id)) {
163 1.1 fvdl case PCI_PRODUCT_3COM_3C900TPO:
164 1.1 fvdl case PCI_PRODUCT_3COM_3C900COMBO:
165 1.1 fvdl model = "3Com 3C900 Ethernet";
166 1.1 fvdl break;
167 1.1 fvdl case PCI_PRODUCT_3COM_3C905TX:
168 1.1 fvdl case PCI_PRODUCT_3COM_3C905T4:
169 1.1 fvdl sc->ex_conf = EX_CONF_MII;
170 1.1 fvdl model = "3Com 3C905 Ethernet";
171 1.1 fvdl break;
172 1.1 fvdl case PCI_PRODUCT_3COM_3C900BTPO:
173 1.1 fvdl case PCI_PRODUCT_3COM_3C900BCOMBO:
174 1.1 fvdl sc->ex_conf = EX_CONF_90XB;
175 1.1 fvdl model = "3Com 3C900B Ethernet";
176 1.1 fvdl break;
177 1.1 fvdl case PCI_PRODUCT_3COM_3C905BTX:
178 1.1 fvdl case PCI_PRODUCT_3COM_3C905BT4:
179 1.1 fvdl sc->ex_conf = (EX_CONF_MII | EX_CONF_90XB);
180 1.1 fvdl if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3COM_3C905BTX)
181 1.1 fvdl sc->ex_conf |= EX_CONF_INTPHY;
182 1.1 fvdl model = "3Com 3C905B Ethernet";
183 1.1 fvdl break;
184 1.1 fvdl default:
185 1.1 fvdl model = "unknown model!";
186 1.1 fvdl break;
187 1.1 fvdl }
188 1.1 fvdl
189 1.1 fvdl printf(": %s\n", model);
190 1.1 fvdl
191 1.1 fvdl sc->enable = NULL;
192 1.1 fvdl sc->disable = NULL;
193 1.1 fvdl sc->enabled = 1;
194 1.1 fvdl
195 1.1 fvdl /* Enable the card. */
196 1.1 fvdl pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
197 1.1 fvdl pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
198 1.1 fvdl PCI_COMMAND_MASTER_ENABLE);
199 1.1 fvdl
200 1.1 fvdl /* Get it out of power save mode if needed (BIOS bugs) */
201 1.1 fvdl if ((pci_conf_read(pc, pa->pa_tag, PCI_CAPPTR) & 0xff) == PCI_CAPID &&
202 1.1 fvdl (pci_conf_read(pc, pa->pa_tag, PCI_CAPID) & 0xff) == 0x01) {
203 1.1 fvdl pmode = pci_conf_read(pc, pa->pa_tag, PCI_POWERCTL) & 0x3;
204 1.1 fvdl if (pmode == 3) {
205 1.1 fvdl /*
206 1.1 fvdl * The card has lost all configuration data in
207 1.1 fvdl * this state, so punt.
208 1.1 fvdl */
209 1.1 fvdl printf("%s: unable to wake up from power state D3\n",
210 1.1 fvdl sc->sc_dev.dv_xname);
211 1.1 fvdl return;
212 1.1 fvdl }
213 1.1 fvdl if (pmode != 0) {
214 1.1 fvdl printf("%s: waking up from power state D%d\n",
215 1.1 fvdl sc->sc_dev.dv_xname, pmode);
216 1.1 fvdl pci_conf_write(pc, pa->pa_tag, PCI_POWERCTL, 0);
217 1.1 fvdl }
218 1.1 fvdl }
219 1.1 fvdl
220 1.1 fvdl /* Map and establish the interrupt. */
221 1.1 fvdl if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
222 1.1 fvdl pa->pa_intrline, &ih)) {
223 1.1 fvdl printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
224 1.1 fvdl return;
225 1.1 fvdl }
226 1.1 fvdl intrstr = pci_intr_string(pc, ih);
227 1.1 fvdl sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ex_intr, sc);
228 1.1 fvdl if (sc->sc_ih == NULL) {
229 1.1 fvdl printf("%s: couldn't establish interrupt",
230 1.1 fvdl sc->sc_dev.dv_xname);
231 1.1 fvdl if (intrstr != NULL)
232 1.1 fvdl printf(" at %s", intrstr);
233 1.1 fvdl printf("\n");
234 1.1 fvdl return;
235 1.1 fvdl }
236 1.1 fvdl printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
237 1.1 fvdl
238 1.1 fvdl ex_config(sc);
239 1.1 fvdl
240 1.1 fvdl }
241