Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / if_ep_pci.c
blob6d0973c15df45c7039e3f1378e76331e5e114eb0
1 /* $NetBSD: if_ep_pci.c,v 1.50 2009/05/06 09:25:15 cegger Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
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.
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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.org>
35 * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org>
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by Herb Peyerl.
49 * 4. The name of Herb Peyerl may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
65 __KERNEL_RCSID(0, "$NetBSD: if_ep_pci.c,v 1.50 2009/05/06 09:25:15 cegger Exp $");
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/mbuf.h>
70 #include <sys/socket.h>
71 #include <sys/ioctl.h>
72 #include <sys/errno.h>
73 #include <sys/syslog.h>
74 #include <sys/select.h>
75 #include <sys/device.h>
77 #include <net/if.h>
78 #include <net/if_dl.h>
79 #include <net/if_ether.h>
80 #include <net/if_media.h>
82 #include <sys/cpu.h>
83 #include <sys/bus.h>
84 #include <sys/intr.h>
86 #include <dev/mii/miivar.h>
88 #include <dev/ic/elink3var.h>
89 #include <dev/ic/elink3reg.h>
91 #include <dev/pci/pcivar.h>
92 #include <dev/pci/pcireg.h>
93 #include <dev/pci/pcidevs.h>
96 * PCI constants.
98 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
100 static int ep_pci_match(device_t , cfdata_t, void *);
101 static void ep_pci_attach(device_t , device_t , void *);
103 CFATTACH_DECL_NEW(ep_pci, sizeof(struct ep_softc),
104 ep_pci_match, ep_pci_attach, NULL, NULL);
106 static struct ep_pci_product {
107 u_int32_t epp_prodid; /* PCI product ID */
108 u_short epp_chipset; /* 3Com chipset used */
109 int epp_flags; /* initial softc flags */
110 const char *epp_name; /* device name */
111 } ep_pci_products[] = {
112 { PCI_PRODUCT_3COM_3C590, ELINK_CHIPSET_VORTEX,
114 "3c590 Ethernet" },
117 * Note: The 3c595-MII is an MII connector for an
118 * external PHY. We treat it as `manual' in the
119 * core driver.
121 { PCI_PRODUCT_3COM_3C595TX, ELINK_CHIPSET_VORTEX,
123 "3c595-TX 10/100 Ethernet" },
124 { PCI_PRODUCT_3COM_3C595T4, ELINK_CHIPSET_VORTEX,
126 "3c595-T4 10/100 Ethernet" },
127 { PCI_PRODUCT_3COM_3C595MII, ELINK_CHIPSET_VORTEX,
129 "3c595-MII 10/100 Ethernet" },
131 { PCI_PRODUCT_3COM_3C900TPO, ELINK_CHIPSET_BOOMERANG,
133 "3c900-TPO Ethernet" },
134 { PCI_PRODUCT_3COM_3C900COMBO, ELINK_CHIPSET_BOOMERANG,
136 "3c900-COMBO Ethernet" },
138 { PCI_PRODUCT_3COM_3C905TX, ELINK_CHIPSET_BOOMERANG,
139 ELINK_FLAGS_MII,
140 "3c905-TX 10/100 Ethernet" },
141 { PCI_PRODUCT_3COM_3C905T4, ELINK_CHIPSET_BOOMERANG,
142 ELINK_FLAGS_MII,
143 "3c905-T4 10/100 Ethernet" },
145 { 0, 0,
146 0, NULL },
149 static const struct ep_pci_product *
150 ep_pci_lookup(const struct pci_attach_args *pa)
152 struct ep_pci_product *epp;
154 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
155 return (NULL);
157 for (epp = ep_pci_products; epp->epp_name != NULL; epp++)
158 if (PCI_PRODUCT(pa->pa_id) == epp->epp_prodid)
159 return (epp);
161 return (NULL);
164 static int
165 ep_pci_match(device_t parent, cfdata_t match, void *aux)
167 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
169 if (ep_pci_lookup(pa) != NULL)
170 return (1);
172 return (0);
175 static void
176 ep_pci_attach(device_t parent, device_t self, void *aux)
178 struct ep_softc *sc = device_private(self);
179 struct pci_attach_args *pa = aux;
180 pci_chipset_tag_t pc = pa->pa_pc;
181 pci_intr_handle_t ih;
182 const struct ep_pci_product *epp;
183 const char *intrstr = NULL;
185 aprint_naive(": Ethernet controller\n");
187 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
188 &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
189 aprint_error(": can't map i/o space\n");
190 return;
193 epp = ep_pci_lookup(pa);
194 if (epp == NULL) {
195 printf("\n");
196 panic("ep_pci_attach: impossible");
199 aprint_normal(": 3Com %s\n", epp->epp_name);
201 sc->sc_dev = self;
202 sc->enable = NULL;
203 sc->disable = NULL;
204 sc->enabled = 1;
206 sc->bustype = ELINK_BUS_PCI;
207 sc->ep_flags = epp->epp_flags;
209 /* Enable the card. */
210 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
211 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
212 PCI_COMMAND_MASTER_ENABLE);
214 /* Map and establish the interrupt. */
215 if (pci_intr_map(pa, &ih)) {
216 aprint_error_dev(sc->sc_dev, "couldn't map interrupt\n");
217 return;
219 intrstr = pci_intr_string(pc, ih);
220 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
221 if (sc->sc_ih == NULL) {
222 aprint_error_dev(sc->sc_dev, "couldn't establish interrupt");
223 if (intrstr != NULL)
224 aprint_error(" at %s", intrstr);
225 aprint_error("\n");
226 return;
228 aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
230 epconfig(sc, epp->epp_chipset, NULL);