linprocfs - Introduce /proc/mounts
[dragonfly.git] / sys / dev / netif / ed / if_ed_pci.c
blob1df5291cde60797422960c568c3ad67425efdfd8
1 /*
3 * Copyright (c) 1996 Stefan Esser <se@freebsd.org>
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice immediately at the beginning of the file, without modification,
11 * this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Absolutely no warranty of function or purpose is made by the author
16 * Stefan Esser.
17 * 4. Modifications may be freely made to this file if the above conditions
18 * are met.
20 * $FreeBSD: src/sys/dev/ed/if_ed_pci.c,v 1.34 2003/10/31 18:31:58 brooks Exp $
21 * $DragonFly: src/sys/dev/netif/ed/if_ed_pci.c,v 1.16 2008/08/17 04:32:33 sephe Exp $
24 #include <sys/param.h>
25 #include <sys/systm.h>
26 #include <sys/socket.h>
27 #include <sys/kernel.h>
28 #include <sys/module.h>
29 #include <sys/interrupt.h>
30 #include <sys/bus.h>
31 #include <sys/rman.h>
33 #include <net/if.h>
34 #include <net/if_arp.h>
35 #include <net/if_mib.h>
37 #include <bus/pci/pcidevs.h>
38 #include <bus/pci/pcireg.h>
39 #include <bus/pci/pcivar.h>
41 #include "if_edvar.h"
43 static int ed_pci_detach(device_t dev);
45 static struct ed_type {
46 uint16_t ed_vid;
47 uint16_t ed_did;
48 const char *ed_name;
49 } ed_devs[] = {
50 { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8029,
51 "NE2000 PCI Ethernet (RealTek 8029)" },
52 { PCI_VENDOR_NETVIN, PCI_PRODUCT_NETVIN_5000,
53 "NE2000 PCI Ethernet (NetVin 5000)" },
54 { PCI_VENDOR_PROLAN, PCI_PRODUCT_PROLAN_NE2KETHER,
55 "NE2000 PCI Ethernet (ProLAN)" },
56 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_NE2KETHER,
57 "NE2000 PCI Ethernet (Compex)" },
58 { PCI_VENDOR_KTI, PCI_PRODUCT_KTI_NE2KETHER,
59 "NE2000 PCI Ethernet (KTI)" },
60 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C940F,
61 "NE2000 PCI Ethernet (Winbond W89C940)" },
62 { PCI_VENDOR_SURECOM, PCI_PRODUCT_SURECOM_NE34,
63 "NE2000 PCI Ethernet (Surecom NE-34)" },
64 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT86C926,
65 "NE2000 PCI Ethernet (VIA VT86C926)" },
66 { 0, 0, NULL }
69 static int ed_pci_probe (device_t);
70 static int ed_pci_attach (device_t);
72 static int
73 ed_pci_probe(device_t dev)
75 struct ed_type *t;
76 uint16_t product = pci_get_device(dev);
77 uint16_t vendor = pci_get_vendor(dev);
79 for (t = ed_devs; t->ed_name != NULL; t++) {
80 if (vendor == t->ed_vid && product == t->ed_did) {
81 device_set_desc(dev, t->ed_name);
82 return 0;
85 return ENXIO;
88 static int
89 ed_pci_attach(device_t dev)
91 struct ed_softc *sc = device_get_softc(dev);
92 int flags = 0;
93 int error;
95 error = ed_probe_Novell(dev, PCIR_MAPS, flags);
96 if (error)
97 return (error);
99 error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
100 if (error) {
101 ed_release_resources(dev);
102 return (error);
105 error = ed_attach(dev);
106 if (error == 0) {
107 struct ifnet *ifp = &sc->arpcom.ac_if;
109 error = bus_setup_intr(dev, sc->irq_res, INTR_MPSAFE,
110 edintr, sc, &sc->irq_handle,
111 ifp->if_serializer);
112 if (error) {
113 ed_pci_detach(dev);
114 } else {
115 ifp->if_cpuid =
116 ithread_cpuid(rman_get_start(sc->irq_res));
117 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
119 } else {
120 ed_release_resources(dev);
122 return (error);
125 static int
126 ed_pci_detach(device_t dev)
128 struct ed_softc *sc = device_get_softc(dev);
129 struct ifnet *ifp = &sc->arpcom.ac_if;
131 lwkt_serialize_enter(ifp->if_serializer);
133 if (sc->gone) {
134 device_printf(dev, "already unloaded\n");
135 lwkt_serialize_exit(ifp->if_serializer);
136 return (0);
138 ed_stop(sc);
139 ifp->if_flags &= ~IFF_RUNNING;
140 sc->gone = 1;
141 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
143 lwkt_serialize_exit(ifp->if_serializer);
145 ether_ifdetach(ifp);
146 ed_release_resources(dev);
147 return (0);
150 static device_method_t ed_pci_methods[] = {
151 /* Device interface */
152 DEVMETHOD(device_probe, ed_pci_probe),
153 DEVMETHOD(device_attach, ed_pci_attach),
154 DEVMETHOD(device_attach, ed_pci_detach),
156 { 0, 0 }
159 static driver_t ed_pci_driver = {
160 "ed",
161 ed_pci_methods,
162 sizeof(struct ed_softc),
165 DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
166 MODULE_DEPEND(ed, pci, 1, 1, 1);