kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / dev / netif / ed / if_ed_pci.c
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  *
20  * $FreeBSD: src/sys/dev/ed/if_ed_pci.c,v 1.23.2.1 2000/09/10 08:45:11 nyan Exp $
21  * $DragonFly: src/sys/dev/netif/ed/if_ed_pci.c,v 1.3 2003/08/07 21:17:01 dillon Exp $
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
40 #include <bus/pci/pcireg.h>
41 #include <bus/pci/pcivar.h>
42
43 #include "if_edvar.h"
44
45 static struct _pcsid
46 {
47         u_int32_t       type;
48         const char      *desc;
49 } pci_ids[] =
50 {
51         { 0x802910ec,   "NE2000 PCI Ethernet (RealTek 8029)"    },
52         { 0x50004a14,   "NE2000 PCI Ethernet (NetVin 5000)"     },
53         { 0x09401050,   "NE2000 PCI Ethernet (ProLAN)"          },
54         { 0x140111f6,   "NE2000 PCI Ethernet (Compex)"          },
55         { 0x30008e2e,   "NE2000 PCI Ethernet (KTI)"             },
56         { 0x19808c4a,   "NE2000 PCI Ethernet (Winbond W89C940)" },
57         { 0x0e3410bd,   "NE2000 PCI Ethernet (Surecom NE-34)"   },
58         { 0x09261106,   "NE2000 PCI Ethernet (VIA VT86C926)"    },
59         { 0x00000000,   NULL                                    }
60 };
61
62 static int      ed_pci_probe    __P((device_t));
63 static int      ed_pci_attach   __P((device_t));
64
65 static int
66 ed_pci_probe (device_t dev)
67 {
68         u_int32_t       type = pci_get_devid(dev);
69         struct _pcsid   *ep =pci_ids;
70
71         while (ep->type && ep->type != type)
72                 ++ep;
73         if (ep->desc) {
74                 device_set_desc(dev, ep->desc);
75                 return 0;
76         } else {
77                 return ENXIO;
78         }
79 }
80
81 static int
82 ed_pci_attach(device_t dev)
83 {
84         struct  ed_softc *sc = device_get_softc(dev);
85         int     flags = 0;
86         int     error;
87
88         error = ed_probe_Novell(dev, PCIR_MAPS, flags);
89         if (error)
90                 return (error);
91
92         error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
93         if (error) {
94                 ed_release_resources(dev);
95                 return (error);
96         }
97
98         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
99                                edintr, sc, &sc->irq_handle);
100         if (error) {
101                 ed_release_resources(dev);
102                 return (error);
103         }
104
105         error = ed_attach(sc, device_get_unit(dev), flags);
106
107         return (error);
108 }
109
110 static device_method_t ed_pci_methods[] = {
111         /* Device interface */
112         DEVMETHOD(device_probe,         ed_pci_probe),
113         DEVMETHOD(device_attach,        ed_pci_attach),
114
115         { 0, 0 }
116 };
117
118 static driver_t ed_pci_driver = {
119         "ed",
120         ed_pci_methods,
121         sizeof(struct ed_softc),
122 };
123
124 static devclass_t ed_devclass;
125
126 DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);