if_vx_eisa.c revision 127135
1/*
2 * Copyright (C) 1996 Naoki Hamada <nao@tom-yam.or.jp>
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, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/vx/if_vx_eisa.c 127135 2004-03-17 17:50:55Z njl $");
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>
37#include <sys/socket.h>
38#include <sys/module.h>
39#include <sys/bus.h>
40
41#include <machine/bus.h>
42#include <machine/resource.h>
43#include <sys/rman.h>
44
45#include <net/if.h>
46#include <net/if_arp.h>
47
48#include <dev/eisa/eisaconf.h>
49
50#include <dev/vx/if_vxreg.h>
51#include <dev/vx/if_vxvar.h>
52
53#define EISA_DEVICE_ID_3COM_3C592	0x506d5920
54#define EISA_DEVICE_ID_3COM_3C597_TX	0x506d5970
55#define EISA_DEVICE_ID_3COM_3C597_T4	0x506d5971
56#define EISA_DEVICE_ID_3COM_3C597_MII	0x506d5972
57
58
59#define	VX_EISA_SLOT_OFFSET		0x0c80
60#define	VX_EISA_IOSIZE			0x000a
61#define VX_RESOURCE_CONFIG		0x0008
62
63
64static const char *vx_match(eisa_id_t type);
65
66static const char*
67vx_match(eisa_id_t type)
68{
69    switch (type) {
70      case EISA_DEVICE_ID_3COM_3C592:
71	return "3Com 3C592 Network Adapter";
72      case EISA_DEVICE_ID_3COM_3C597_TX:
73	return "3Com 3C597-TX Network Adapter";
74      case EISA_DEVICE_ID_3COM_3C597_T4:
75	return "3Com 3C597-T4 Network Adapter";
76      case EISA_DEVICE_ID_3COM_3C597_MII:
77	return "3Com 3C597-MII Network Adapter";
78      default:
79	break;
80    }
81    return (NULL);
82}
83
84static int
85vx_eisa_probe(device_t dev)
86{
87    const char	   *desc;
88    u_long          iobase;
89    u_long          port;
90
91    desc = vx_match(eisa_get_id(dev));
92    if (!desc)
93	return (ENXIO);
94    device_set_desc(dev, desc);
95
96    port = eisa_get_slot(dev) * EISA_SLOT_SIZE;
97    iobase = port + VX_EISA_SLOT_OFFSET;
98
99    eisa_add_iospace(dev, iobase, VX_EISA_IOSIZE, RESVADDR_NONE);
100    eisa_add_iospace(dev, port, VX_IOSIZE, RESVADDR_NONE);
101
102    /* Set irq */
103    eisa_add_intr(dev, inw(iobase + VX_RESOURCE_CONFIG) >> 12,
104		  EISA_TRIGGER_EDGE);
105
106    return (0);
107}
108
109static int
110vx_eisa_attach(device_t dev)
111{
112    struct vx_softc *sc;
113    struct resource *io = 0;
114    struct resource *eisa_io = 0;
115    struct resource *irq = 0;
116    int		    rid;
117    void	    *ih;
118
119    /*
120     * The addresses are sorted in increasing order
121     * so we know the port to pass to the core ep
122     * driver comes first.
123     */
124    rid = 0;
125    io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
126    if (!io) {
127	device_printf(dev, "No I/O space?!\n");
128	goto bad;
129    }
130
131    rid = 1;
132    eisa_io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
133    if (!eisa_io) {
134	device_printf(dev, "No I/O space?!\n");
135	goto bad;
136    }
137
138    sc = device_get_softc(dev);
139
140    sc->vx_res = io;
141    sc->bst = rman_get_bustag(io);
142    sc->bsh = rman_get_bushandle(io);
143
144    rid = 0;
145    irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
146    if (!irq) {
147	device_printf(dev, "No irq?!\n");
148	goto bad;
149    }
150
151    sc->vx_irq = irq;
152
153    /* Now the registers are availible through the lower ioport */
154
155    vxattach(dev);
156
157    if (bus_setup_intr(dev, irq, INTR_TYPE_NET, vxintr, sc, &ih)) {
158	goto bad;
159    }
160
161    sc->vx_intrhand = ih;
162
163    return 0;
164
165 bad:
166    if (io)
167	bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
168    if (eisa_io)
169	bus_release_resource(dev, SYS_RES_IOPORT, 0, eisa_io);
170    if (irq)
171	bus_release_resource(dev, SYS_RES_IRQ, 0, irq);
172    return -1;
173}
174
175static device_method_t vx_eisa_methods[] = {
176	/* Device interface */
177	DEVMETHOD(device_probe,		vx_eisa_probe),
178	DEVMETHOD(device_attach,	vx_eisa_attach),
179
180	{ 0, 0 }
181};
182
183static driver_t vx_eisa_driver = {
184	"vx",
185	vx_eisa_methods,
186	1,			/* unused */
187};
188
189static devclass_t vx_devclass;
190
191DRIVER_MODULE(vx, eisa, vx_eisa_driver, vx_devclass, 0, 0);
192