Reduce ifnet.if_serializer contention on output path:
[dragonfly.git] / sys / dev / netif / vx / if_vx_pci.c
blobdf5d57232119f33d7f1f9829482b12a010a7084c
1 /*
2 * Copyright (C) 1996 Naoki Hamada <nao@tom-yam.or.jp>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * $FreeBSD: src/sys/dev/vx/if_vx_pci.c,v 1.21 2000/05/28 15:59:52 peter Exp $
30 * $DragonFly: src/sys/dev/netif/vx/if_vx_pci.c,v 1.16 2008/05/14 11:59:22 sephe Exp $
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/socket.h>
37 #include <sys/bus.h>
38 #include <sys/rman.h>
39 #include <sys/interrupt.h>
41 #include <net/if.h>
42 #include <net/if_arp.h>
44 #include <bus/pci/pcidevs.h>
45 #include <bus/pci/pcivar.h>
46 #include <bus/pci/pcireg.h>
48 #include "if_vxreg.h"
50 static const struct vx_pci_type {
51 uint16_t vx_vid;
52 uint16_t vx_did;
53 const char *vx_desc;
54 } vx_pci_types[] = {
55 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C590,
56 "3Com 3c590 PCI Ethernet Adapter" },
57 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C595TX,
58 "3Com 3c595-TX PCI Ethernet Adapter" },
59 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C595T4,
60 "3Com 3c595-T4 PCI Ethernet Adapter" },
61 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C595MII,
62 "3Com 3c595-MII PCI Ethernet Adapter" },
65 * The (Fast) Etherlink XL adapters are now supported by
66 * the xl driver, which uses bus master DMA and is much
67 * faster. (And which also supports the 3c905B.
69 #ifdef VORTEX_ETHERLINK_XL
70 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C900TPO,
71 "3Com 3c900-TPO Fast Etherlink XL" },
72 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C900COMBO,
73 "3Com 3c900-COMBO Fast Etherlink XL" },
74 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C905TX,
75 "3Com 3c905-TX Fast Etherlink XL" },
76 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C905T4,
77 "3Com 3c905-T4 Fast Etherlink XL" },
78 #endif
79 { 0, 0, NULL }
82 static void vx_pci_shutdown(device_t);
83 static int vx_pci_probe(device_t);
84 static int vx_pci_attach(device_t);
86 static device_method_t vx_methods[] = {
87 /* Device interface */
88 DEVMETHOD(device_probe, vx_pci_probe),
89 DEVMETHOD(device_attach, vx_pci_attach),
90 DEVMETHOD(device_shutdown, vx_pci_shutdown),
92 { 0, 0 }
95 static driver_t vx_driver = {
96 "vx",
97 vx_methods,
98 sizeof(struct vx_softc)
101 static devclass_t vx_devclass;
103 DRIVER_MODULE(if_vx, pci, vx_driver, vx_devclass, 0, 0);
105 static void
106 vx_pci_shutdown(device_t dev)
108 struct vx_softc *sc;
110 sc = device_get_softc(dev);
111 lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer);
112 vxstop(sc);
113 lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer);
116 static int
117 vx_pci_probe(device_t dev)
119 const struct vx_pci_type *t;
120 uint16_t vid, did;
122 vid = pci_get_vendor(dev);
123 did = pci_get_device(dev);
124 for (t = vx_pci_types; t->vx_desc != NULL; ++t) {
125 if (vid == t->vx_vid && did == t->vx_did) {
126 device_set_desc(dev, t->vx_desc);
127 return 0;
130 return ENXIO;
133 static int
134 vx_pci_attach(device_t dev)
136 struct vx_softc *sc = device_get_softc(dev);
137 struct ifnet *ifp = &sc->arpcom.ac_if;
138 int rid;
140 rid = PCIR_MAPS;
141 sc->vx_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
142 RF_ACTIVE);
144 if (sc->vx_res == NULL)
145 goto bad;
147 sc->vx_btag = rman_get_bustag(sc->vx_res);
148 sc->vx_bhandle = rman_get_bushandle(sc->vx_res);
150 rid = 0;
151 sc->vx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
152 RF_SHAREABLE | RF_ACTIVE);
154 if (sc->vx_irq == NULL)
155 goto bad;
157 if (vxattach(dev) == 0) {
158 goto bad;
161 /* defect check for 3C590 */
162 if (pci_get_device(dev) == PCI_PRODUCT_3COM_3C590) {
163 GO_WINDOW(0);
164 if (vxbusyeeprom(sc))
165 goto bad;
166 CSR_WRITE_2(sc, VX_W0_EEPROM_COMMAND,
167 EEPROM_CMD_RD | EEPROM_SOFT_INFO_2);
168 if (vxbusyeeprom(sc))
169 goto bad;
170 if (!(CSR_READ_2(sc, VX_W0_EEPROM_DATA) & NO_RX_OVN_ANOMALY)) {
171 kprintf("Warning! Defective early revision adapter!\n");
175 if (bus_setup_intr(dev, sc->vx_irq, INTR_NETSAFE,
176 vxintr, sc, &sc->vx_intrhand,
177 ifp->if_serializer)
179 ether_ifdetach(&sc->arpcom.ac_if);
180 goto bad;
183 ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->vx_irq));
184 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
186 return(0);
188 bad:
189 if (sc->vx_res != NULL)
190 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->vx_res);
191 if (sc->vx_irq != NULL)
192 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vx_irq);
193 return(ENXIO);