if_vx_eisa.c revision 29674
119410Sguido/*
219410Sguido * Copyright (C) 1996 Naoki Hamada <nao@tom-yam.or.jp>
319410Sguido * All rights reserved.
419410Sguido *
519410Sguido * Redistribution and use in source and binary forms, with or without
619410Sguido * modification, are permitted provided that the following conditions
719410Sguido * are met:
819410Sguido * 1. Redistributions of source code must retain the above copyright
919410Sguido *    notice, this list of conditions and the following disclaimer.
1019410Sguido * 2. Redistributions in binary form must reproduce the above copyright
1119410Sguido *    notice, this list of conditions and the following disclaimer in the
1219410Sguido *    documentation and/or other materials provided with the distribution.
1319410Sguido * 3. Neither the name of the author nor the names of any co-contributors
1419410Sguido *    may be used to endorse or promote products derived from this software
1519410Sguido *    without specific prior written permission.
1619410Sguido *
1719410Sguido * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1819410Sguido * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919410Sguido * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2019410Sguido * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2119410Sguido * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2219410Sguido * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2319410Sguido * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2419410Sguido * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2519410Sguido * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2619410Sguido * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2719410Sguido * SUCH DAMAGE.
2819410Sguido *
2919410Sguido */
3019410Sguido
3119410Sguido#include "eisa.h"
3219410Sguido#if NEISA > 0
3319410Sguido
3419410Sguido#include "vx.h"
3519410Sguido#if NVX > 0
3619410Sguido
3719410Sguido#include <sys/param.h>
3819410Sguido#include <sys/systm.h>
3919410Sguido#include <sys/kernel.h>
4019410Sguido#include <sys/socket.h>
4119410Sguido
4219410Sguido#include <net/if.h>
4319410Sguido
4419410Sguido#ifdef INET
4519410Sguido#include <netinet/in.h>
4619410Sguido#include <netinet/if_ether.h>
4719410Sguido#endif
4819410Sguido
4919410Sguido#ifdef NS
5019410Sguido#include <netns/ns.h>
5119410Sguido#include <netns/ns_if.h>
5219410Sguido#endif
5319410Sguido
5419410Sguido#include <i386/eisa/eisaconf.h>
5519410Sguido
5619410Sguido#include <dev/vx/if_vxreg.h>
5719410Sguido
5819410Sguido#define EISA_DEVICE_ID_3COM_3C592	0x506d5920
5919410Sguido#define EISA_DEVICE_ID_3COM_3C597_TX	0x506d5970
6019410Sguido#define EISA_DEVICE_ID_3COM_3C597_T4	0x506d5971
6119410Sguido#define EISA_DEVICE_ID_3COM_3C597_MII	0x506d5972
6219410Sguido
6319410Sguido
6419410Sguido#define	VX_EISA_SLOT_OFFSET		0x0c80
6519410Sguido#define	VX_EISA_IOSIZE			0x000a
6619410Sguido#define VX_RESOURCE_CONFIG		0x0008
6719410Sguido
6819410Sguido
6929674Sgibbsstatic const char *vx_match __P((eisa_id_t type));
7019410Sguidostatic int vx_eisa_probe __P((void));
7119410Sguidostatic int vx_eisa_attach __P((struct eisa_device *));
7219410Sguido
7319410Sguidostruct eisa_driver vx_eisa_driver = {
7419410Sguido    "vx",
7519410Sguido    vx_eisa_probe,
7619410Sguido    vx_eisa_attach,
7719410Sguido     /* shutdown */ NULL,
7819410Sguido    &vx_count
7919410Sguido};
8019410Sguido
8119410SguidoDATA_SET(eisadriver_set, vx_eisa_driver);
8219410Sguido
8329674Sgibbsstatic const char*
8419410Sguidovx_match(type)
8519410Sguido    eisa_id_t       type;
8619410Sguido{
8719410Sguido    switch (type) {
8819410Sguido      case EISA_DEVICE_ID_3COM_3C592:
8919410Sguido	return "3Com 3C592 Network Adapter";
9019410Sguido	break;
9119410Sguido      case EISA_DEVICE_ID_3COM_3C597_TX:
9219410Sguido	return "3Com 3C597-TX Network Adapter";
9319410Sguido	break;
9419410Sguido      case EISA_DEVICE_ID_3COM_3C597_T4:
9519410Sguido	return "3Com 3C597-T4 Network Adapter";
9619410Sguido	break;
9719410Sguido      case EISA_DEVICE_ID_3COM_3C597_MII:
9819410Sguido	return "3Com 3C597-MII Network Adapter";
9919410Sguido	break;
10019410Sguido      default:
10119410Sguido	break;
10219410Sguido    }
10319410Sguido    return (NULL);
10419410Sguido}
10519410Sguido
10619410Sguidostatic int
10719410Sguidovx_eisa_probe(void)
10819410Sguido{
10919410Sguido    u_long          iobase;
11019410Sguido    struct eisa_device *e_dev = NULL;
11119410Sguido    int             count;
11219410Sguido
11319410Sguido    count = 0;
11419410Sguido    while ((e_dev = eisa_match_dev(e_dev, vx_match))) {
11519410Sguido	u_long          port;
11619410Sguido
11719410Sguido	port = e_dev->ioconf.slot * EISA_SLOT_SIZE;
11819410Sguido	iobase = port + VX_EISA_SLOT_OFFSET;
11919410Sguido
12019410Sguido	eisa_add_iospace(e_dev, iobase, VX_EISA_IOSIZE, RESVADDR_NONE);
12119410Sguido	eisa_add_iospace(e_dev, port, VX_IOSIZE, RESVADDR_NONE);
12219410Sguido
12319410Sguido	/* Set irq */
12419410Sguido	eisa_add_intr(e_dev, inw(iobase + VX_RESOURCE_CONFIG) >> 12);
12519410Sguido	eisa_registerdev(e_dev, &vx_eisa_driver);
12619410Sguido	count++;
12719410Sguido    }
12819410Sguido    return count;
12919410Sguido}
13019410Sguido
13119410Sguidostatic int
13219410Sguidovx_eisa_attach(e_dev)
13319410Sguido    struct eisa_device *e_dev;
13419410Sguido{
13519410Sguido    struct vx_softc *sc;
13619410Sguido    int             unit = e_dev->unit;
13729674Sgibbs    int             irq;
13819410Sguido    resvaddr_t     *ioport;
13919410Sguido    resvaddr_t     *eisa_ioport;
14019410Sguido    u_char          level_intr;
14119410Sguido
14229674Sgibbs    if (TAILQ_FIRST(&e_dev->ioconf.irqs) == NULL)
14329674Sgibbs	return (-1);
14429674Sgibbs
14529674Sgibbs    irq = TAILQ_FIRST(&e_dev->ioconf.irqs)->irq_no;
14629674Sgibbs
14719410Sguido    ioport = e_dev->ioconf.ioaddrs.lh_first;
14819410Sguido
14919410Sguido    if (!ioport)
15019410Sguido	return -1;
15119410Sguido
15219410Sguido    eisa_ioport = ioport->links.le_next;
15319410Sguido
15419410Sguido    if (!eisa_ioport)
15519410Sguido	return -1;
15619410Sguido
15719410Sguido    eisa_reg_start(e_dev);
15819410Sguido    if (eisa_reg_iospace(e_dev, ioport))
15919410Sguido	return -1;
16019410Sguido
16119410Sguido    if (eisa_reg_iospace(e_dev, eisa_ioport))
16219410Sguido	return -1;
16319410Sguido
16419410Sguido    if ((sc = vxalloc(unit)) == NULL)
16519410Sguido	return -1;
16619410Sguido
16719410Sguido    sc->vx_io_addr = ioport->addr;
16819410Sguido
16919410Sguido    level_intr = FALSE;
17019410Sguido
17128509Sfsmp    if (eisa_reg_intr(e_dev, irq, (void (*)(void *)) vxintr, (void *) sc, &net_imask,
17219410Sguido		       /* shared == */ level_intr)) {
17319410Sguido	vxfree(sc);
17419410Sguido	return -1;
17519410Sguido    }
17619410Sguido    eisa_reg_end(e_dev);
17719410Sguido
17819410Sguido    /* Now the registers are availible through the lower ioport */
17919410Sguido
18019410Sguido    vxattach(sc);
18119410Sguido
18219410Sguido    if (eisa_enable_intr(e_dev, irq)) {
18319410Sguido	vxfree(sc);
18428509Sfsmp	eisa_release_intr(e_dev, irq, (void (*)(void *)) vxintr);
18519410Sguido	return -1;
18619410Sguido    }
18719410Sguido    return 0;
18819410Sguido}
18919410Sguido
19019410Sguido#endif	/* NVX > 0 */
19119410Sguido#endif	/* NEISA > 0 */
192