if_ed_isa.c revision 67172
1/*
2 * Copyright (c) 1995, David Greenman
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 unmodified, this list of conditions, and the following
10 *    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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/dev/ed/if_ed_isa.c 67172 2000-10-15 20:23:27Z msmith $
28 */
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/socket.h>
33#include <sys/kernel.h>
34
35#include <sys/module.h>
36#include <sys/bus.h>
37#include <machine/bus.h>
38
39#include <net/ethernet.h>
40#include <net/if.h>
41#include <net/if_arp.h>
42#include <net/if_mib.h>
43
44#include <isa/isavar.h>
45#include <isa/pnpvar.h>
46
47#include <dev/ed/if_edvar.h>
48
49static int ed_isa_probe		__P((device_t));
50static int ed_isa_attach	__P((device_t));
51
52static struct isa_pnp_id ed_ids[] = {
53	{ 0x1684a34d,	NULL },		/* SMC8416 */
54	{ 0xd680d041,	NULL },		/* PNP80d6 */
55	{ 0x1980635e,	NULL },		/* WSC8019 */
56	{ 0x0131d805,	NULL },		/* ANX3101 */
57	{ 0x01200507,	NULL },		/* AXE2001 */
58	{ 0x19808c4a,	NULL },		/* RTL8019 */
59	{ 0x0090252a,	NULL },		/* JQE9000 */
60	{ 0x0020832e,	NULL },		/* KTC2000 */
61	{ 0,		NULL }
62};
63
64static int
65ed_isa_probe(dev)
66	device_t dev;
67{
68	struct ed_softc *sc = device_get_softc(dev);
69	int flags = device_get_flags(dev);
70	int error = 0;
71
72	bzero(sc, sizeof(struct ed_softc));
73
74	/* Check isapnp ids */
75	error = ISA_PNP_PROBE(device_get_parent(dev), dev, ed_ids);
76
77	/* If the card had a PnP ID that didn't match any we know about */
78	if (error == ENXIO) {
79		goto end;
80	}
81
82	/* If we had some other problem. */
83	if (!(error == 0 || error == ENOENT)) {
84		goto end;
85	}
86
87	/* Heuristic probes */
88
89	error = ed_probe_WD80x3(dev, 0, flags);
90	if (error == 0)
91		goto end;
92	ed_release_resources(dev);
93
94	error = ed_probe_3Com(dev, 0, flags);
95	if (error == 0)
96		goto end;
97	ed_release_resources(dev);
98
99	error = ed_probe_Novell(dev, 0, flags);
100	if (error == 0)
101		goto end;
102	ed_release_resources(dev);
103
104	error = ed_probe_HP_pclanp(dev, 0, flags);
105	if (error == 0)
106		goto end;
107	ed_release_resources(dev);
108
109end:
110	if (error == 0)
111		error = ed_alloc_irq(dev, 0, 0);
112
113	ed_release_resources(dev);
114	return (error);
115}
116
117static int
118ed_isa_attach(dev)
119	device_t dev;
120{
121	struct ed_softc *sc = device_get_softc(dev);
122	int flags = device_get_flags(dev);
123	int error;
124
125	if (sc->port_used > 0)
126		ed_alloc_port(dev, sc->port_rid, sc->port_used);
127	if (sc->mem_used)
128		ed_alloc_memory(dev, sc->mem_rid, sc->mem_used);
129
130	ed_alloc_irq(dev, sc->irq_rid, 0);
131
132	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
133			       edintr, sc, &sc->irq_handle);
134	if (error) {
135		ed_release_resources(dev);
136		return (error);
137	}
138
139	return ed_attach(sc, device_get_unit(dev), flags);
140}
141
142static device_method_t ed_isa_methods[] = {
143	/* Device interface */
144	DEVMETHOD(device_probe,		ed_isa_probe),
145	DEVMETHOD(device_attach,	ed_isa_attach),
146
147	{ 0, 0 }
148};
149
150static driver_t ed_isa_driver = {
151	"ed",
152	ed_isa_methods,
153	sizeof(struct ed_softc)
154};
155
156static devclass_t ed_isa_devclass;
157
158DRIVER_MODULE(if_ed, isa, ed_isa_driver, ed_isa_devclass, 0, 0);
159