if_ep_pci.c revision 1.30 1 /* $NetBSD: if_ep_pci.c,v 1.30 1998/11/07 23:06:26 fvdl Exp $ */
2
3 /*-
4 * Copyright (c) 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 /*
41 * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
42 * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
43 * All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by Herb Peyerl.
56 * 4. The name of Herb Peyerl may not be used to endorse or promote products
57 * derived from this software without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
64 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
68 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 */
70
71 #include "opt_inet.h"
72 #include "opt_ns.h"
73 #include "bpfilter.h"
74
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/mbuf.h>
78 #include <sys/socket.h>
79 #include <sys/ioctl.h>
80 #include <sys/errno.h>
81 #include <sys/syslog.h>
82 #include <sys/select.h>
83 #include <sys/device.h>
84
85 #include <net/if.h>
86 #include <net/if_dl.h>
87 #include <net/if_ether.h>
88 #include <net/if_media.h>
89
90 #ifdef INET
91 #include <netinet/in.h>
92 #include <netinet/in_systm.h>
93 #include <netinet/in_var.h>
94 #include <netinet/ip.h>
95 #include <netinet/if_inarp.h>
96 #endif
97
98 #ifdef NS
99 #include <netns/ns.h>
100 #include <netns/ns_if.h>
101 #endif
102
103 #if NBPFILTER > 0
104 #include <net/bpf.h>
105 #include <net/bpfdesc.h>
106 #endif
107
108 #include <machine/cpu.h>
109 #include <machine/bus.h>
110 #include <machine/intr.h>
111
112 #include <dev/mii/miivar.h>
113
114 #include <dev/ic/elink3var.h>
115 #include <dev/ic/elink3reg.h>
116
117 #include <dev/pci/pcivar.h>
118 #include <dev/pci/pcireg.h>
119 #include <dev/pci/pcidevs.h>
120
121 /*
122 * PCI constants.
123 */
124 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
125
126 int ep_pci_match __P((struct device *, struct cfdata *, void *));
127 void ep_pci_attach __P((struct device *, struct device *, void *));
128
129 struct cfattach ep_pci_ca = {
130 sizeof(struct ep_softc), ep_pci_match, ep_pci_attach
131 };
132
133 struct ep_pci_product {
134 u_int32_t epp_prodid; /* PCI product ID */
135 u_short epp_chipset; /* 3Com chipset used */
136 int epp_flags; /* initial softc flags */
137 const char *epp_name; /* device name */
138 } ep_pci_products[] = {
139 { PCI_PRODUCT_3COM_3C590, ELINK_CHIPSET_VORTEX,
140 0, "3c590" },
141
142 /*
143 * Note: The 3c595-MII is an MII connector for an
144 * external PHY. We treat it as `manual' in the
145 * core driver.
146 */
147 { PCI_PRODUCT_3COM_3C595TX, ELINK_CHIPSET_VORTEX,
148 0, "3c595-TX" },
149 { PCI_PRODUCT_3COM_3C595T4, ELINK_CHIPSET_VORTEX,
150 0, "3c595-T4" },
151 { PCI_PRODUCT_3COM_3C595MII, ELINK_CHIPSET_VORTEX,
152 0, "3c595-MII" },
153 { PCI_PRODUCT_3COM_3C900TPO, ELINK_CHIPSET_BOOMERANG,
154 0, "3c900-TPO" },
155 { PCI_PRODUCT_3COM_3C900COMBO, ELINK_CHIPSET_BOOMERANG,
156 0, "3c900-COMBO" },
157 { PCI_PRODUCT_3COM_3C905TX, ELINK_CHIPSET_BOOMERANG,
158 ELINK_FLAGS_MII, "3c905-TX" },
159 { PCI_PRODUCT_3COM_3C905T4, ELINK_CHIPSET_BOOMERANG,
160 ELINK_FLAGS_MII, "3c905-T4" },
161
162 { 0, 0,
163 0, NULL },
164 };
165
166 struct ep_pci_product *ep_pci_lookup __P((struct pci_attach_args *));
167
168 struct ep_pci_product *
169 ep_pci_lookup(pa)
170 struct pci_attach_args *pa;
171 {
172 struct ep_pci_product *epp;
173
174 for (epp = ep_pci_products; epp->epp_name != NULL; epp++)
175 if (PCI_PRODUCT(pa->pa_id) == epp->epp_prodid)
176 return (epp);
177
178 return (NULL);
179 }
180
181 int
182 ep_pci_match(parent, match, aux)
183 struct device *parent;
184 struct cfdata *match;
185 void *aux;
186 {
187 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
188
189 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
190 return (0);
191
192 if (ep_pci_lookup(pa) != NULL)
193 return (1);
194
195 return (0);
196 }
197
198 void
199 ep_pci_attach(parent, self, aux)
200 struct device *parent, *self;
201 void *aux;
202 {
203 struct ep_softc *sc = (void *)self;
204 struct pci_attach_args *pa = aux;
205 pci_chipset_tag_t pc = pa->pa_pc;
206 pci_intr_handle_t ih;
207 struct ep_pci_product *epp;
208 const char *intrstr = NULL;
209
210 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
211 &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
212 printf(": can't map i/o space\n");
213 return;
214 }
215
216 epp = ep_pci_lookup(pa);
217 if (epp == NULL) {
218 printf("\n");
219 panic("ep_pci_attach: impossible");
220 }
221
222 printf(": 3Com %s Ethernet\n", epp->epp_name);
223
224 sc->enable = NULL;
225 sc->disable = NULL;
226 sc->enabled = 1;
227
228 sc->bustype = ELINK_BUS_PCI;
229 sc->ep_flags = epp->epp_flags;
230
231 /* Enable the card. */
232 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
233 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
234 PCI_COMMAND_MASTER_ENABLE);
235
236 /* Map and establish the interrupt. */
237 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
238 pa->pa_intrline, &ih)) {
239 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
240 return;
241 }
242 intrstr = pci_intr_string(pc, ih);
243 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
244 if (sc->sc_ih == NULL) {
245 printf("%s: couldn't establish interrupt",
246 sc->sc_dev.dv_xname);
247 if (intrstr != NULL)
248 printf(" at %s", intrstr);
249 printf("\n");
250 return;
251 }
252 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
253
254 epconfig(sc, epp->epp_chipset, NULL);
255 }
256