Merge from vendor branch CVS:
[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 $
e9cb6d99 21 * $DragonFly: src/sys/dev/netif/ed/if_ed_pci.c,v 1.8 2005/05/24 20:59:01 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
MD
44
45static 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
b5101a88
RG
62static int ed_pci_probe (device_t);
63static int ed_pci_attach (device_t);
984263bc
MD
64
65static int
66ed_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
81static int
82ed_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,
e9cb6d99 99 edintr, sc, &sc->irq_handle, NULL);
984263bc
MD
100 if (error) {
101 ed_release_resources(dev);
102 return (error);
103 }
104
1f18ea8c 105 error = ed_attach(dev);
984263bc
MD
106
107 return (error);
108}
109
110static 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
118static driver_t ed_pci_driver = {
119 "ed",
120 ed_pci_methods,
121 sizeof(struct ed_softc),
122};
123
124static devclass_t ed_devclass;
125
1f18ea8c
JS
126DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
127MODULE_DEPEND(ed, pci, 1, 1, 1);