Make all network interrupt service routines MPSAFE part 1/3.
[dragonfly.git] / sys / dev / netif / ed / if_ed_pci.c
CommitLineData
984263bc
MD
1/*
2 *
3 * Copyright (c) 1996 Stefan Esser <se@freebsd.org>
4 * All rights reserved.
5 *
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.
19 *
1f18ea8c 20 * $FreeBSD: src/sys/dev/ed/if_ed_pci.c,v 1.34 2003/10/31 18:31:58 brooks Exp $
78195a76 21 * $DragonFly: src/sys/dev/netif/ed/if_ed_pci.c,v 1.10 2005/11/28 17:13:42 dillon Exp $
984263bc
MD
22 */
23
24#include <sys/param.h>
25#include <sys/systm.h>
26#include <sys/socket.h>
27#include <sys/kernel.h>
28
29#include <sys/module.h>
30#include <sys/bus.h>
31
32#include <machine/bus.h>
33#include <sys/rman.h>
34#include <machine/resource.h>
35
36#include <net/if.h>
37#include <net/if_arp.h>
38#include <net/if_mib.h>
39
1f2de5d4
MD
40#include <bus/pci/pcireg.h>
41#include <bus/pci/pcivar.h>
984263bc 42
1f2de5d4 43#include "if_edvar.h"
984263bc 44
78195a76
MD
45static int ed_pci_detach(device_t dev);
46
984263bc
MD
47static struct _pcsid
48{
49 u_int32_t type;
50 const char *desc;
51} pci_ids[] =
52{
53 { 0x802910ec, "NE2000 PCI Ethernet (RealTek 8029)" },
54 { 0x50004a14, "NE2000 PCI Ethernet (NetVin 5000)" },
55 { 0x09401050, "NE2000 PCI Ethernet (ProLAN)" },
56 { 0x140111f6, "NE2000 PCI Ethernet (Compex)" },
57 { 0x30008e2e, "NE2000 PCI Ethernet (KTI)" },
58 { 0x19808c4a, "NE2000 PCI Ethernet (Winbond W89C940)" },
59 { 0x0e3410bd, "NE2000 PCI Ethernet (Surecom NE-34)" },
60 { 0x09261106, "NE2000 PCI Ethernet (VIA VT86C926)" },
61 { 0x00000000, NULL }
62};
63
b5101a88
RG
64static int ed_pci_probe (device_t);
65static int ed_pci_attach (device_t);
984263bc
MD
66
67static int
68ed_pci_probe (device_t dev)
69{
70 u_int32_t type = pci_get_devid(dev);
71 struct _pcsid *ep =pci_ids;
72
73 while (ep->type && ep->type != type)
74 ++ep;
75 if (ep->desc) {
76 device_set_desc(dev, ep->desc);
77 return 0;
78 } else {
79 return ENXIO;
80 }
81}
82
83static int
84ed_pci_attach(device_t dev)
85{
86 struct ed_softc *sc = device_get_softc(dev);
87 int flags = 0;
88 int error;
89
90 error = ed_probe_Novell(dev, PCIR_MAPS, flags);
91 if (error)
92 return (error);
93
94 error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
95 if (error) {
96 ed_release_resources(dev);
97 return (error);
98 }
99
78195a76
MD
100 error = ed_attach(dev);
101 if (error == 0) {
102 error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE,
103 edintr, sc, &sc->irq_handle,
104 sc->arpcom.ac_if.if_serializer);
105 if (error)
106 ed_pci_detach(dev);
107 } else {
984263bc 108 ed_release_resources(dev);
78195a76
MD
109 }
110 return (error);
111}
984263bc 112
78195a76
MD
113static int
114ed_pci_detach(device_t dev)
115{
116 struct ed_softc *sc = device_get_softc(dev);
117 struct ifnet *ifp = &sc->arpcom.ac_if;
984263bc 118
78195a76
MD
119 lwkt_serialize_enter(ifp->if_serializer);
120 if (sc->gone) {
121 device_printf(dev, "already unloaded\n");
122 return (0);
123 }
124 ed_stop(sc);
125 ifp->if_flags &= ~IFF_RUNNING;
126 ether_ifdetach(ifp);
127 sc->gone = 1;
128 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
129 ed_release_resources(dev);
130 lwkt_serialize_exit(ifp->if_serializer);
131 return (0);
984263bc
MD
132}
133
134static device_method_t ed_pci_methods[] = {
135 /* Device interface */
136 DEVMETHOD(device_probe, ed_pci_probe),
137 DEVMETHOD(device_attach, ed_pci_attach),
78195a76 138 DEVMETHOD(device_attach, ed_pci_detach),
984263bc
MD
139
140 { 0, 0 }
141};
142
143static driver_t ed_pci_driver = {
144 "ed",
145 ed_pci_methods,
146 sizeof(struct ed_softc),
147};
148
149static devclass_t ed_devclass;
150
1f18ea8c
JS
151DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
152MODULE_DEPEND(ed, pci, 1, 1, 1);