2008-04-29 00:22:51 +04:00
|
|
|
/* $NetBSD: if_ate_mca.c,v 1.21 2008/04/28 20:23:53 martin Exp $ */
|
2001-03-31 04:43:05 +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 ATI AT1720X MCA cards based on Fujitsu MB8696xA controller.
|
|
|
|
*/
|
|
|
|
|
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_ate_mca.c,v 1.21 2008/04/28 20:23:53 martin Exp $");
|
2001-11-13 10:38:28 +03:00
|
|
|
|
2001-03-31 04:43:05 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
2001-03-31 04:43:05 +04:00
|
|
|
|
|
|
|
#include <dev/ic/mb86960reg.h>
|
|
|
|
#include <dev/ic/mb86960var.h>
|
|
|
|
|
|
|
|
#include <dev/mca/mcavar.h>
|
|
|
|
#include <dev/mca/mcadevs.h>
|
|
|
|
|
2008-04-12 10:27:01 +04:00
|
|
|
int ate_mca_match(device_t, cfdata_t, void *);
|
|
|
|
void ate_mca_attach(device_t, device_t, void *);
|
2005-02-04 05:10:35 +03:00
|
|
|
static void ate_mca_detect(bus_space_tag_t, bus_space_handle_t,
|
2008-04-12 10:27:01 +04:00
|
|
|
uint8_t enaddr[ETHER_ADDR_LEN]);
|
2001-03-31 04:43:05 +04:00
|
|
|
|
|
|
|
#define ATE_NPORTS 0x20
|
|
|
|
|
|
|
|
struct ate_softc {
|
|
|
|
struct mb86960_softc sc_mb86960; /* real "mb86960" softc */
|
|
|
|
|
|
|
|
/* MCA-specific goo. */
|
|
|
|
void *sc_ih; /* interrupt cookie */
|
|
|
|
};
|
|
|
|
|
2008-04-12 10:27:01 +04:00
|
|
|
CFATTACH_DECL_NEW(ate_mca, sizeof(struct ate_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
ate_mca_match, ate_mca_attach, NULL, NULL);
|
2001-03-31 04:43:05 +04:00
|
|
|
|
|
|
|
static const struct ate_mca_product {
|
2008-04-12 10:27:01 +04:00
|
|
|
uint32_t at_prodid; /* MCA product ID */
|
2001-03-31 04:43:05 +04:00
|
|
|
const char *at_name; /* device name */
|
|
|
|
int at_type; /* device type */
|
|
|
|
} ate_mca_products[] = {
|
|
|
|
{ MCA_PRODUCT_AT1720T, "ATI AT1720T", FE_TYPE_AT1700T },
|
|
|
|
{ MCA_PRODUCT_AT1720BT, "ATI AT1720BT", FE_TYPE_AT1700BT },
|
|
|
|
{ MCA_PRODUCT_AT1720AT, "ATI AT1720AT", FE_TYPE_AT1700AT },
|
|
|
|
{ MCA_PRODUCT_AT1720FT, "ATI AT1720FT", FE_TYPE_AT1700FT },
|
2006-08-30 20:38:23 +04:00
|
|
|
{ 0, NULL, 0 },
|
2001-03-31 04:43:05 +04:00
|
|
|
};
|
|
|
|
|
2008-04-12 10:27:01 +04:00
|
|
|
static const struct ate_mca_product *ate_mca_lookup(uint32_t);
|
2001-03-31 04:43:05 +04:00
|
|
|
|
|
|
|
static const struct ate_mca_product *
|
2008-04-12 10:27:01 +04:00
|
|
|
ate_mca_lookup(uint32_t id)
|
2001-03-31 04:43:05 +04:00
|
|
|
{
|
|
|
|
const struct ate_mca_product *atp;
|
|
|
|
|
|
|
|
for (atp = ate_mca_products; atp->at_name != NULL; atp++)
|
|
|
|
if (id == atp->at_prodid)
|
2008-04-12 10:27:01 +04:00
|
|
|
return atp;
|
2001-03-31 04:43:05 +04:00
|
|
|
|
2008-04-12 10:27:01 +04:00
|
|
|
return NULL;
|
2001-03-31 04:43:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-04-12 10:27:01 +04:00
|
|
|
ate_mca_match(device_t parent, cfdata_t cf, void *aux)
|
2001-03-31 04:43:05 +04:00
|
|
|
{
|
2008-04-12 10:27:01 +04:00
|
|
|
struct mca_attach_args *ma = aux;
|
2001-03-31 04:43:05 +04:00
|
|
|
|
|
|
|
if (ate_mca_lookup(ma->ma_id) != NULL)
|
2008-04-12 10:27:01 +04:00
|
|
|
return 1;
|
2001-03-31 04:43:05 +04:00
|
|
|
|
2008-04-12 10:27:01 +04:00
|
|
|
return 0;
|
2001-03-31 04:43:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* see POS diagrams below for explanation of these arrays' contents */
|
|
|
|
static const int ats_iobase[] = {
|
|
|
|
0x400, 0x2400, 0x4400, 0x6400, 0x1400, 0x3400, 0x5400, 0x7400
|
|
|
|
};
|
|
|
|
static const int ats_irq[] = {
|
|
|
|
3, 4, 5, 9, 10, 11, 12, 15
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2008-04-12 10:27:01 +04:00
|
|
|
ate_mca_attach(device_t parent, device_t self, void *aux)
|
2001-03-31 04:43:05 +04:00
|
|
|
{
|
2006-03-29 10:51:47 +04:00
|
|
|
struct ate_softc *isc = device_private(self);
|
2001-03-31 04:43:05 +04:00
|
|
|
struct mb86960_softc *sc = &isc->sc_mb86960;
|
|
|
|
struct mca_attach_args *ma = aux;
|
|
|
|
bus_space_tag_t iot = ma->ma_iot;
|
|
|
|
bus_space_handle_t ioh;
|
2008-04-12 10:27:01 +04:00
|
|
|
uint8_t myea[ETHER_ADDR_LEN];
|
2003-02-23 07:10:11 +03:00
|
|
|
int pos3, pos4;
|
2001-03-31 04:43:05 +04:00
|
|
|
int iobase, irq;
|
|
|
|
const struct ate_mca_product *atp;
|
|
|
|
|
2008-04-12 10:27:01 +04:00
|
|
|
sc->sc_dev = self;
|
|
|
|
|
2001-03-31 04:43:05 +04:00
|
|
|
pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
|
|
|
|
pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* POS register 2: (adf pos0)
|
|
|
|
* 7 6 5 4 3 2 1 0
|
|
|
|
* \__ enable: 0=adapter disabled, 1=adapter enabled
|
|
|
|
*
|
|
|
|
* POS register 3: (adf pos1)
|
2005-02-27 03:26:58 +03:00
|
|
|
*
|
2001-03-31 04:43:05 +04:00
|
|
|
* 7 6 5 4 3 2 1 0
|
|
|
|
* \_/ \___/ \___/
|
|
|
|
* \ \ \__ I/O Port Addresses: 000=0x400-0x4FF 100=0x1400-
|
|
|
|
* \ \ 001=0x2400 101=0x3400 010=0x4400 110=0x5400
|
|
|
|
* \ \ 011=0x6400 111=0x7400
|
|
|
|
* \ \_____ Boot ROM Memory Address
|
|
|
|
* \
|
|
|
|
* \_________ Lower 2 bit of Interrupt Request Number
|
|
|
|
*
|
|
|
|
* POS register 4: (adf pos2)
|
2005-02-27 03:26:58 +03:00
|
|
|
*
|
2001-03-31 04:43:05 +04:00
|
|
|
* 7 6 5 4 3 2 1 0
|
|
|
|
* \ \_______ Twisted Pair Type: 0=100 ohm, Unshielded
|
|
|
|
* \ 1=150 ohm, Shielded
|
|
|
|
* \____________ Higher 1 bit of Interrupt Request Number:
|
|
|
|
* 000=3 001=4 010=5 011=9 100=10 101=11 110=12 111=15
|
|
|
|
*/
|
|
|
|
|
|
|
|
atp = ate_mca_lookup(ma->ma_id);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (atp == NULL) {
|
2008-04-09 00:40:42 +04:00
|
|
|
aprint_normal("\n");
|
2008-04-12 10:27:01 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "where did the card go?\n");
|
2001-03-31 04:43:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
iobase = ats_iobase[pos3 & 0x7];
|
|
|
|
irq = ats_irq[((pos4 & 0x40) >> 4) | ((pos3 & 0xc0) >> 6)];
|
|
|
|
|
2008-04-12 10:27:01 +04:00
|
|
|
aprint_normal(" slot %d irq %d: %s\n",
|
|
|
|
ma->ma_slot + 1, irq, atp->at_name);
|
2001-04-23 10:10:08 +04:00
|
|
|
|
2001-03-31 04:43:05 +04:00
|
|
|
/* Map i/o space. */
|
|
|
|
if (bus_space_map(iot, iobase, ATE_NPORTS, 0, &ioh)) {
|
2008-04-12 10:27:01 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "can't map i/o space\n");
|
2001-03-31 04:43:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_bst = iot;
|
|
|
|
sc->sc_bsh = ioh;
|
|
|
|
|
2003-02-23 07:10:11 +03:00
|
|
|
/* Get ethernet address. */
|
2001-03-31 04:43:05 +04:00
|
|
|
ate_mca_detect(iot, ioh, myea);
|
|
|
|
|
|
|
|
/* This interface is always enabled. */
|
2002-11-30 17:15:10 +03:00
|
|
|
sc->sc_stat |= FE_STAT_ENABLED;
|
2001-03-31 04:43:05 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do generic MB86960 attach.
|
|
|
|
*/
|
2002-11-30 17:15:10 +03:00
|
|
|
mb86960_attach(sc, myea);
|
2001-03-31 04:43:05 +04:00
|
|
|
|
|
|
|
mb86960_config(sc, NULL, 0, 0);
|
|
|
|
|
|
|
|
/* Establish the interrupt handler. */
|
|
|
|
isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
|
2008-04-12 10:27:01 +04:00
|
|
|
mb86960_intr, sc);
|
2001-03-31 04:43:05 +04:00
|
|
|
if (isc->sc_ih == NULL) {
|
2008-04-12 10:27:01 +04:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"couldn't establish interrupt handler\n");
|
2001-03-31 04:43:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Very simplified ate_detect() from dev/isa/if_ate.c, only
|
|
|
|
* to determine ethernet address.
|
|
|
|
*/
|
|
|
|
static void
|
2008-04-12 10:27:01 +04:00
|
|
|
ate_mca_detect(bus_space_tag_t iot, bus_space_handle_t ioh,
|
|
|
|
uint8_t enaddr[ETHER_ADDR_LEN])
|
2001-03-31 04:43:05 +04:00
|
|
|
{
|
2008-04-12 10:27:01 +04:00
|
|
|
uint8_t eeprom[FE_EEPROM_SIZE];
|
2001-03-31 04:43:05 +04:00
|
|
|
|
|
|
|
/* Get our station address from EEPROM. */
|
2002-10-04 19:22:27 +04:00
|
|
|
mb86965_read_eeprom(iot, ioh, eeprom);
|
|
|
|
memcpy(enaddr, eeprom + FE_ATI_EEP_ADDR, ETHER_ADDR_LEN);
|
2001-03-31 04:43:05 +04:00
|
|
|
}
|