if_ed_pci.c revision 52247
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: head/sys/dev/ed/if_ed_pci.c 52247 1999-10-15 03:12:48Z mdodd $
21 */
22
23#include "card.h"
24#if NCARD == 0
25
26#include <sys/param.h>
27#include <sys/systm.h>
28#include <sys/socket.h>
29#include <sys/kernel.h>
30
31#include <sys/module.h>
32#include <sys/bus.h>
33
34#include <machine/bus.h>
35#include <sys/rman.h>
36#include <machine/resource.h>
37
38#include <net/if.h>
39#include <net/if_arp.h>
40#include <net/if_mib.h>
41
42#include <pci/pcireg.h>
43#include <pci/pcivar.h>
44
45#include <dev/ed/if_edvar.h>
46
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
64static int	ed_pci_probe	__P((device_t));
65static int	ed_pci_attach	__P((device_t));
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_generic(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
100        error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
101                               edintr, sc, &sc->irq_handle);
102        if (error) {
103                ed_release_resources(dev);
104                return (error);
105        }
106
107	error = ed_attach(sc, device_get_unit(dev), flags);
108
109	return (error);
110}
111
112static device_method_t ed_pci_methods[] = {
113	/* Device interface */
114	DEVMETHOD(device_probe,		ed_pci_probe),
115	DEVMETHOD(device_attach,	ed_pci_attach),
116
117	{ 0, 0 }
118};
119
120static driver_t ed_pci_driver = {
121	"ed",
122	ed_pci_methods,
123	sizeof(struct ed_softc),
124};
125
126static devclass_t ed_devclass;
127
128DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
129#endif
130