if_vx_eisa.c revision 46743
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 "eisa.h"
32#if NEISA > 0
33
34#include "vx.h"
35#if NVX > 0
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/socket.h>
41#include <sys/module.h>
42#include <sys/bus.h>
43
44#include <machine/bus.h>
45#include <machine/resource.h>
46#include <sys/rman.h>
47
48#include <net/if.h>
49#include <net/if_arp.h>
50
51#include <i386/eisa/eisaconf.h>
52
53#include <dev/vx/if_vxreg.h>
54
55#define EISA_DEVICE_ID_3COM_3C592	0x506d5920
56#define EISA_DEVICE_ID_3COM_3C597_TX	0x506d5970
57#define EISA_DEVICE_ID_3COM_3C597_T4	0x506d5971
58#define EISA_DEVICE_ID_3COM_3C597_MII	0x506d5972
59
60
61#define	VX_EISA_SLOT_OFFSET		0x0c80
62#define	VX_EISA_IOSIZE			0x000a
63#define VX_RESOURCE_CONFIG		0x0008
64
65
66static const char *vx_match __P((eisa_id_t type));
67
68static const char*
69vx_match(eisa_id_t type)
70{
71    switch (type) {
72      case EISA_DEVICE_ID_3COM_3C592:
73	return "3Com 3C592 Network Adapter";
74	break;
75      case EISA_DEVICE_ID_3COM_3C597_TX:
76	return "3Com 3C597-TX Network Adapter";
77	break;
78      case EISA_DEVICE_ID_3COM_3C597_T4:
79	return "3Com 3C597-T4 Network Adapter";
80	break;
81      case EISA_DEVICE_ID_3COM_3C597_MII:
82	return "3Com 3C597-MII Network Adapter";
83	break;
84      default:
85	break;
86    }
87    return (NULL);
88}
89
90static int
91vx_eisa_probe(device_t dev)
92{
93    const char	   *desc;
94    u_long          iobase;
95    u_long          port;
96
97    desc = vx_match(eisa_get_id(dev));
98    if (!desc)
99	return (ENXIO);
100    device_set_desc(dev, desc);
101
102    port = eisa_get_slot(dev) * EISA_SLOT_SIZE;
103    iobase = port + VX_EISA_SLOT_OFFSET;
104
105    eisa_add_iospace(dev, iobase, VX_EISA_IOSIZE, RESVADDR_NONE);
106    eisa_add_iospace(dev, port, VX_IOSIZE, RESVADDR_NONE);
107
108    /* Set irq */
109    eisa_add_intr(dev, inw(iobase + VX_RESOURCE_CONFIG) >> 12);
110
111    return (0);
112}
113
114static int
115vx_eisa_attach(device_t dev)
116{
117    struct vx_softc *sc;
118    int             unit = device_get_unit(dev);
119    struct resource *io = 0;
120    struct resource *eisa_io = 0;
121    struct resource *irq = 0;
122    u_char          level_intr;
123    int		    rid;
124    void	    *ih;
125
126    /*
127     * The addresses are sorted in increasing order
128     * so we know the port to pass to the core ep
129     * driver comes first.
130     */
131    rid = 0;
132    io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
133			    0, ~0, 1, RF_ACTIVE);
134    if (!io) {
135	device_printf(dev, "No I/O space?!\n");
136	goto bad;
137    }
138
139    rid = 1;
140    eisa_io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
141				 0, ~0, 1, RF_ACTIVE);
142    if (!eisa_io) {
143	device_printf(dev, "No I/O space?!\n");
144	goto bad;
145    }
146
147    if ((sc = vxalloc(unit)) == NULL)
148	goto bad;
149
150    sc->vx_io_addr = rman_get_start(io);
151
152    level_intr = FALSE;
153
154    rid = 0;
155    irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
156			     0, ~0, 1, RF_ACTIVE);
157    if (!irq) {
158	device_printf(dev, "No irq?!\n");
159	vxfree(sc);
160	goto bad;
161    }
162
163    /* Now the registers are availible through the lower ioport */
164
165    vxattach(sc);
166
167    if (bus_setup_intr(dev, irq, INTR_TYPE_NET, vxintr, sc, &ih)) {
168	vxfree(sc);
169	goto bad;
170    }
171
172    return 0;
173
174 bad:
175    if (io)
176	bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
177    if (eisa_io)
178	bus_release_resource(dev, SYS_RES_IOPORT, 0, eisa_io);
179    if (irq)
180	bus_release_resource(dev, SYS_RES_IRQ, 0, irq);
181    return -1;
182}
183
184static device_method_t vx_eisa_methods[] = {
185	/* Device interface */
186	DEVMETHOD(device_probe,		vx_eisa_probe),
187	DEVMETHOD(device_attach,	vx_eisa_attach),
188
189	{ 0, 0 }
190};
191
192static driver_t vx_eisa_driver = {
193	"vx",
194	vx_eisa_methods,
195	1,			/* unused */
196};
197
198static devclass_t vx_devclass;
199
200DRIVER_MODULE(vx, eisa, vx_eisa_driver, vx_devclass, 0, 0);
201
202#endif	/* NVX > 0 */
203#endif	/* NEISA > 0 */
204