2008-04-29 00:22:51 +04:00
|
|
|
/* $NetBSD: if_ne_mca.c,v 1.15 2008/04/28 20:23:53 martin Exp $ */
|
2001-04-20 11:37:42 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jaromir Dolecek.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver for Novell NE/2 Ethernet Adapter (and clones).
|
|
|
|
*
|
|
|
|
* According to Linux ne2 driver, Arco and Compex card should be also
|
|
|
|
* supported by this driver. However, NetBSD driver was only tested
|
|
|
|
* with the Novell adapter so far.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:38:28 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-04-29 00:22:51 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_ne_mca.c,v 1.15 2008/04/28 20:23:53 martin Exp $");
|
2001-11-13 10:38:28 +03:00
|
|
|
|
2001-04-20 11:37:42 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
2001-04-20 11:37:42 +04:00
|
|
|
|
|
|
|
#include <dev/ic/dp8390reg.h>
|
|
|
|
#include <dev/ic/dp8390var.h>
|
|
|
|
|
|
|
|
#include <dev/ic/ne2000reg.h>
|
|
|
|
#include <dev/ic/ne2000var.h>
|
|
|
|
|
|
|
|
#include <dev/ic/rtl80x9reg.h>
|
|
|
|
#include <dev/ic/rtl80x9var.h>
|
|
|
|
|
|
|
|
#include <dev/mca/mcadevs.h>
|
|
|
|
#include <dev/mca/mcavar.h>
|
|
|
|
|
|
|
|
#define NE2_NPORTS 0x30
|
|
|
|
|
|
|
|
struct ne_mca_softc {
|
|
|
|
struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
|
|
|
|
|
|
|
|
/* MCA-specific goo */
|
|
|
|
void *sc_ih; /* interrupt handle */
|
|
|
|
};
|
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
int ne_mca_match(device_t, cfdata_t , void *);
|
|
|
|
void ne_mca_attach(device_t, device_t, void *);
|
2001-04-20 11:37:42 +04:00
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
CFATTACH_DECL_NEW(ne_mca, sizeof(struct ne_mca_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
ne_mca_match, ne_mca_attach, NULL, NULL);
|
2001-04-20 11:37:42 +04:00
|
|
|
|
|
|
|
static const struct ne_mca_products {
|
|
|
|
u_int32_t ne_id;
|
|
|
|
const char *ne_name;
|
|
|
|
} ne_mca_products[] = {
|
|
|
|
{ MCA_PRODUCT_ARCOAE, "Arco Electronics AE/2 Ethernet Adapter" },
|
|
|
|
{ MCA_PRODUCT_NE2, "Novell NE/2 Ethernet Adapter" },
|
|
|
|
{ MCA_PRODUCT_CENET16, "Compex Inc. PS/2 ENET16-MC/P Microchannel Ad."},
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
static const struct ne_mca_products *ne_mca_lookup(int id);
|
2001-04-20 11:37:42 +04:00
|
|
|
|
|
|
|
static const struct ne_mca_products *
|
|
|
|
ne_mca_lookup(int id)
|
|
|
|
{
|
|
|
|
const struct ne_mca_products *np;
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
for(np = ne_mca_products; np->ne_name; np++)
|
2001-04-20 11:37:42 +04:00
|
|
|
if (id == np->ne_id)
|
|
|
|
return (np);
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-12 17:31:11 +03:00
|
|
|
ne_mca_match(device_t parent, cfdata_t cf, void *aux)
|
2001-04-20 11:37:42 +04:00
|
|
|
{
|
|
|
|
struct mca_attach_args *ma = aux;
|
|
|
|
|
|
|
|
if (ne_mca_lookup(ma->ma_id))
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These values were taken from NE/2 ADF file */
|
|
|
|
static const int ne_mca_irq[] = {
|
|
|
|
3, 4, 5, 9
|
|
|
|
};
|
|
|
|
static const int ne_mca_iobase[] = {
|
|
|
|
0, 0x1000, 0x2020, 0x8020, 0xa0a0, 0xb0b0, 0xc0c0, 0xc3d0
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2008-03-12 17:31:11 +03:00
|
|
|
ne_mca_attach(device_t parent, device_t self, void *aux)
|
2001-04-20 11:37:42 +04:00
|
|
|
{
|
2006-03-29 10:51:47 +04:00
|
|
|
struct ne_mca_softc *psc = device_private(self);
|
2001-04-20 11:37:42 +04:00
|
|
|
struct ne2000_softc *nsc = &psc->sc_ne2000;
|
|
|
|
struct dp8390_softc *dsc = &nsc->sc_dp8390;
|
|
|
|
struct mca_attach_args *ma = aux;
|
|
|
|
bus_space_tag_t nict;
|
|
|
|
bus_space_handle_t nich;
|
|
|
|
bus_space_tag_t asict;
|
|
|
|
bus_space_handle_t asich;
|
|
|
|
int pos2, iobase, irq;
|
|
|
|
const struct ne_mca_products *np;
|
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
dsc->sc_dev = self;
|
|
|
|
|
2001-04-20 11:37:42 +04:00
|
|
|
pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* POS register 2: (adf pos0)
|
2005-02-27 03:26:58 +03:00
|
|
|
*
|
2001-04-20 11:37:42 +04:00
|
|
|
* 7 6 5 4 3 2 1 0
|
|
|
|
* \_/ | \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
|
|
|
|
* | | \____ I/O, Mem: 001=0x1000-0x102f 010=0x2020-0x204f
|
|
|
|
* | | 011=0x8020-0x804f 100=0xa0a0-0xa0cf
|
|
|
|
* | | 101=0xb0b0-0xb0df 110=0xc0c0-0xc0ef
|
|
|
|
* \ \ 111=0xc3d0-0xc3ff
|
|
|
|
* \ \________ Boot Rom: 1=disabled 0=enabled
|
|
|
|
* \__________ Interrupt level: 00=3 01=4 10=5 11=9
|
|
|
|
*/
|
|
|
|
|
|
|
|
np = ne_mca_lookup(ma->ma_id);
|
|
|
|
|
|
|
|
iobase = ne_mca_iobase[(pos2 & 0x0e) >> 1];
|
|
|
|
irq = ne_mca_irq[(pos2 & 0x60) >> 5];
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_normal(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq,
|
|
|
|
np->ne_name);
|
2001-04-23 10:10:08 +04:00
|
|
|
|
2001-04-20 11:37:42 +04:00
|
|
|
nict = ma->ma_iot;
|
|
|
|
|
|
|
|
/* Map the device. */
|
|
|
|
if (bus_space_map(nict, iobase, NE2_NPORTS, 0, &nich)) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(self, "can't map i/o space\n");
|
2001-04-20 11:37:42 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
asict = nict;
|
|
|
|
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
|
|
|
|
NE2000_ASIC_NPORTS, &asich)) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(self, "can't subregion i/o space\n");
|
2001-04-20 11:37:42 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsc->sc_regt = nict;
|
|
|
|
dsc->sc_regh = nich;
|
|
|
|
|
|
|
|
nsc->sc_asict = asict;
|
|
|
|
nsc->sc_asich = asich;
|
|
|
|
|
|
|
|
/* This interface is always enabled. */
|
|
|
|
dsc->sc_enabled = 1;
|
|
|
|
|
|
|
|
dsc->sc_mediachange = NULL;
|
|
|
|
dsc->sc_mediastatus = NULL;
|
|
|
|
dsc->sc_media_init = NULL;
|
|
|
|
dsc->init_card = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is necessary for NE/2. Hopefully the other clones also work
|
|
|
|
* this way.
|
|
|
|
*/
|
|
|
|
nsc->sc_type = NE2000_TYPE_AX88190;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do generic NE2000 attach. This will read the station address
|
|
|
|
* from the EEPROM.
|
|
|
|
*/
|
|
|
|
if (ne2000_attach(nsc, NULL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* establish interrupt handler */
|
|
|
|
psc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, dp8390_intr,
|
|
|
|
dsc);
|
|
|
|
if (psc->sc_ih == NULL) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"couldn't establish interrupt handler\n");
|
2001-04-20 11:37:42 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|