]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/ed/if_ed_pci.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / dev / ed / if_ed_pci.c
1 /*-
2  * Copyright (c) 1996 Stefan Esser <se@freebsd.org>
3  * All rights reserved.
4  *
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 immediately at the beginning of the file, without modification,
10  *    this list of conditions, and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Absolutely no warranty of function or purpose is made by the author
15  *    Stefan Esser.
16  * 4. Modifications may be freely made to this file if the above conditions
17  *    are met.
18  */
19
20 #include <sys/cdefs.h>
21 __FBSDID("$FreeBSD$");
22
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/socket.h>
26 #include <sys/kernel.h>
27
28 #include <sys/module.h>
29 #include <sys/bus.h>
30
31 #include <machine/bus.h>
32 #include <sys/rman.h>
33 #include <machine/resource.h>
34
35 #include <net/if.h>
36 #include <net/if_arp.h>
37 #include <net/if_media.h>
38 #include <net/if_mib.h>
39
40 #include <dev/pci/pcireg.h>
41 #include <dev/pci/pcivar.h>
42
43 #include <dev/ed/if_edvar.h>
44 #include <dev/ed/rtl80x9reg.h>
45
46 static struct _pcsid
47 {
48         uint32_t        type;
49         const char      *desc;
50 } pci_ids[] =
51 {
52         { ED_RTL8029_PCI_ID, "RealTek 8029" },
53         { 0x50004a14, "NetVin 5000" },
54         { 0x09401050, "ProLAN" },
55         { 0x140111f6, "Compex" },
56         { 0x30008e2e, "KTI" },
57         { 0x19808c4a, "Winbond W89C940" },
58         { 0x0e3410bd, "Surecom NE-34" },
59         { 0x09261106, "VIA VT86C926" },
60         { 0x00000000, NULL }
61 };
62
63 static int      ed_pci_probe(device_t);
64 static int      ed_pci_attach(device_t);
65
66 static int
67 ed_pci_probe(device_t dev)
68 {
69         uint32_t        type = pci_get_devid(dev);
70         struct _pcsid   *ep =pci_ids;
71
72         while (ep->type && ep->type != type)
73                 ++ep;
74         if (ep->desc == NULL)
75                 return (ENXIO);
76         device_set_desc(dev, ep->desc);
77         return (BUS_PROBE_DEFAULT);
78 }
79
80 static int
81 ed_pci_attach(device_t dev)
82 {
83         struct  ed_softc *sc = device_get_softc(dev);
84         int     flags = 0;
85         int     error = ENXIO;
86
87         /*
88          * If this card claims to be a RTL8029, probe it as such.
89          * However, allow that probe to fail.  Some versions of qemu
90          * claim to be a 8029 in the PCI register, but it doesn't
91          * implement the 8029 specific registers.  In that case, fall
92          * back to a normal NE2000.
93          */
94         if (pci_get_devid(dev) == ED_RTL8029_PCI_ID)
95                 error = ed_probe_RTL80x9(dev, PCIR_BAR(0), flags);
96         if (error)
97                 error = ed_probe_Novell(dev, PCIR_BAR(0), flags);
98         if (error) {
99                 ed_release_resources(dev);
100                 return (error);
101         }
102         ed_Novell_read_mac(sc);
103
104         error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
105         if (error) {
106                 ed_release_resources(dev);
107                 return (error);
108         }
109         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
110             NULL, edintr, sc, &sc->irq_handle);
111         if (error) {
112                 ed_release_resources(dev);
113                 return (error);
114         }
115
116         error = ed_attach(dev);
117         if (error)
118                 ed_release_resources(dev);
119         return (error);
120 }
121
122 static device_method_t ed_pci_methods[] = {
123         /* Device interface */
124         DEVMETHOD(device_probe,         ed_pci_probe),
125         DEVMETHOD(device_attach,        ed_pci_attach),
126         DEVMETHOD(device_detach,        ed_detach),
127
128         { 0, 0 }
129 };
130
131 static driver_t ed_pci_driver = {
132         "ed",
133         ed_pci_methods,
134         sizeof(struct ed_softc),
135 };
136
137 DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
138 MODULE_DEPEND(ed, pci, 1, 1, 1);
139 MODULE_DEPEND(ed, ether, 1, 1, 1);