Home | History | Annotate | Line # | Download | only in mca
if_ate_mca.c revision 1.20.4.1
      1  1.20.4.1      yamt /*	$NetBSD: if_ate_mca.c,v 1.20.4.1 2008/05/16 02:24:33 yamt Exp $	*/
      2       1.1  jdolecek 
      3       1.1  jdolecek /*-
      4       1.1  jdolecek  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5       1.1  jdolecek  * All rights reserved.
      6       1.1  jdolecek  *
      7       1.1  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1  jdolecek  * by Jaromir Dolecek.
      9       1.1  jdolecek  *
     10       1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     11       1.1  jdolecek  * modification, are permitted provided that the following conditions
     12       1.1  jdolecek  * are met:
     13       1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14       1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15       1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17       1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     18       1.1  jdolecek  *
     19       1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1  jdolecek  */
     31       1.1  jdolecek 
     32       1.1  jdolecek /*
     33       1.1  jdolecek  * Driver for ATI AT1720X MCA cards based on Fujitsu MB8696xA controller.
     34       1.1  jdolecek  */
     35       1.3     lukem 
     36       1.3     lukem #include <sys/cdefs.h>
     37  1.20.4.1      yamt __KERNEL_RCSID(0, "$NetBSD: if_ate_mca.c,v 1.20.4.1 2008/05/16 02:24:33 yamt Exp $");
     38       1.1  jdolecek 
     39       1.1  jdolecek #include <sys/param.h>
     40       1.1  jdolecek #include <sys/systm.h>
     41       1.1  jdolecek #include <sys/device.h>
     42       1.1  jdolecek #include <sys/socket.h>
     43       1.1  jdolecek #include <sys/syslog.h>
     44       1.1  jdolecek 
     45       1.1  jdolecek #include <net/if.h>
     46       1.1  jdolecek #include <net/if_ether.h>
     47       1.1  jdolecek #include <net/if_media.h>
     48       1.1  jdolecek 
     49      1.18        ad #include <sys/bus.h>
     50      1.18        ad #include <sys/intr.h>
     51       1.1  jdolecek 
     52       1.1  jdolecek #include <dev/ic/mb86960reg.h>
     53       1.1  jdolecek #include <dev/ic/mb86960var.h>
     54       1.1  jdolecek 
     55       1.1  jdolecek #include <dev/mca/mcavar.h>
     56       1.1  jdolecek #include <dev/mca/mcadevs.h>
     57       1.1  jdolecek 
     58      1.20   tsutsui int	ate_mca_match(device_t, cfdata_t, void *);
     59      1.20   tsutsui void	ate_mca_attach(device_t, device_t, void *);
     60      1.11     perry static void ate_mca_detect(bus_space_tag_t, bus_space_handle_t,
     61      1.20   tsutsui     uint8_t enaddr[ETHER_ADDR_LEN]);
     62       1.1  jdolecek 
     63       1.1  jdolecek #define ATE_NPORTS 0x20
     64       1.1  jdolecek 
     65       1.1  jdolecek struct ate_softc {
     66       1.1  jdolecek 	struct	mb86960_softc sc_mb86960;	/* real "mb86960" softc */
     67       1.1  jdolecek 
     68       1.1  jdolecek 	/* MCA-specific goo. */
     69       1.1  jdolecek 	void	*sc_ih;				/* interrupt cookie */
     70       1.1  jdolecek };
     71       1.1  jdolecek 
     72      1.20   tsutsui CFATTACH_DECL_NEW(ate_mca, sizeof(struct ate_softc),
     73       1.7   thorpej     ate_mca_match, ate_mca_attach, NULL, NULL);
     74       1.1  jdolecek 
     75       1.1  jdolecek static const struct ate_mca_product {
     76      1.20   tsutsui 	uint32_t	at_prodid;	/* MCA product ID */
     77       1.1  jdolecek 	const char	*at_name;	/* device name */
     78       1.1  jdolecek 	int		at_type;	/* device type */
     79       1.1  jdolecek } ate_mca_products[] = {
     80       1.1  jdolecek 	{ MCA_PRODUCT_AT1720T,	"ATI AT1720T",	FE_TYPE_AT1700T		},
     81       1.1  jdolecek 	{ MCA_PRODUCT_AT1720BT,	"ATI AT1720BT",	FE_TYPE_AT1700BT	},
     82       1.1  jdolecek 	{ MCA_PRODUCT_AT1720AT, "ATI AT1720AT",	FE_TYPE_AT1700AT	},
     83       1.1  jdolecek 	{ MCA_PRODUCT_AT1720FT, "ATI AT1720FT",	FE_TYPE_AT1700FT	},
     84      1.15  christos 	{ 0,			NULL,		0			},
     85       1.1  jdolecek };
     86       1.1  jdolecek 
     87      1.20   tsutsui static const struct ate_mca_product *ate_mca_lookup(uint32_t);
     88       1.1  jdolecek 
     89       1.1  jdolecek static const struct ate_mca_product *
     90      1.20   tsutsui ate_mca_lookup(uint32_t id)
     91       1.1  jdolecek {
     92       1.1  jdolecek 	const struct ate_mca_product *atp;
     93       1.1  jdolecek 
     94       1.1  jdolecek 	for (atp = ate_mca_products; atp->at_name != NULL; atp++)
     95       1.1  jdolecek 		if (id == atp->at_prodid)
     96      1.20   tsutsui 			return atp;
     97       1.1  jdolecek 
     98      1.20   tsutsui 	return NULL;
     99       1.1  jdolecek }
    100       1.1  jdolecek 
    101       1.1  jdolecek int
    102      1.20   tsutsui ate_mca_match(device_t parent, cfdata_t cf, void *aux)
    103       1.1  jdolecek {
    104      1.20   tsutsui 	struct mca_attach_args *ma = aux;
    105       1.1  jdolecek 
    106       1.1  jdolecek 	if (ate_mca_lookup(ma->ma_id) != NULL)
    107      1.20   tsutsui 		return 1;
    108       1.1  jdolecek 
    109      1.20   tsutsui 	return 0;
    110       1.1  jdolecek }
    111       1.1  jdolecek 
    112       1.1  jdolecek /* see POS diagrams below for explanation of these arrays' contents */
    113       1.1  jdolecek static const int ats_iobase[] = {
    114       1.1  jdolecek 	0x400, 0x2400, 0x4400, 0x6400, 0x1400, 0x3400, 0x5400, 0x7400
    115       1.1  jdolecek };
    116       1.1  jdolecek static const int ats_irq[] = {
    117       1.1  jdolecek 	3, 4, 5, 9, 10, 11, 12, 15
    118       1.1  jdolecek };
    119       1.1  jdolecek 
    120       1.1  jdolecek void
    121      1.20   tsutsui ate_mca_attach(device_t parent, device_t self, void *aux)
    122       1.1  jdolecek {
    123      1.14   thorpej 	struct ate_softc *isc = device_private(self);
    124       1.1  jdolecek 	struct mb86960_softc *sc = &isc->sc_mb86960;
    125       1.1  jdolecek 	struct mca_attach_args *ma = aux;
    126       1.1  jdolecek 	bus_space_tag_t iot = ma->ma_iot;
    127       1.1  jdolecek 	bus_space_handle_t ioh;
    128      1.20   tsutsui 	uint8_t myea[ETHER_ADDR_LEN];
    129      1.10    simonb 	int pos3, pos4;
    130       1.1  jdolecek 	int iobase, irq;
    131       1.1  jdolecek 	const struct ate_mca_product *atp;
    132       1.1  jdolecek 
    133      1.20   tsutsui 	sc->sc_dev = self;
    134      1.20   tsutsui 
    135       1.1  jdolecek 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    136       1.1  jdolecek 	pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
    137       1.1  jdolecek 
    138       1.1  jdolecek 	/*
    139       1.1  jdolecek 	 * POS register 2: (adf pos0)
    140       1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    141       1.1  jdolecek 	 *               \__ enable: 0=adapter disabled, 1=adapter enabled
    142       1.1  jdolecek 	 *
    143       1.1  jdolecek 	 * POS register 3: (adf pos1)
    144      1.12     perry 	 *
    145       1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    146       1.1  jdolecek 	 * \_/ \___/ \___/
    147       1.1  jdolecek 	 *   \     \     \__ I/O Port Addresses: 000=0x400-0x4FF 100=0x1400-
    148       1.1  jdolecek 	 *    \     \          001=0x2400 101=0x3400 010=0x4400 110=0x5400
    149       1.1  jdolecek 	 *     \     \         011=0x6400 111=0x7400
    150       1.1  jdolecek 	 *      \     \_____ Boot ROM Memory Address
    151       1.1  jdolecek 	 *       \
    152       1.1  jdolecek 	 *        \_________ Lower 2 bit of Interrupt Request Number
    153       1.1  jdolecek 	 *
    154       1.1  jdolecek 	 * POS register 4: (adf pos2)
    155      1.12     perry 	 *
    156       1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    157       1.1  jdolecek 	 *   \      \_______ Twisted Pair Type: 0=100 ohm, Unshielded
    158       1.1  jdolecek 	 *    \                1=150 ohm, Shielded
    159       1.1  jdolecek 	 *     \____________ Higher 1 bit of Interrupt Request Number:
    160       1.1  jdolecek 	 *                   000=3 001=4 010=5 011=9 100=10 101=11 110=12 111=15
    161       1.1  jdolecek 	 */
    162       1.1  jdolecek 
    163       1.1  jdolecek 	atp = ate_mca_lookup(ma->ma_id);
    164       1.1  jdolecek #ifdef DIAGNOSTIC
    165       1.1  jdolecek 	if (atp == NULL) {
    166      1.19    cegger 		aprint_normal("\n");
    167      1.20   tsutsui 		aprint_error_dev(sc->sc_dev, "where did the card go?\n");
    168       1.1  jdolecek 		return;
    169       1.1  jdolecek 	}
    170       1.1  jdolecek #endif
    171       1.1  jdolecek 
    172       1.1  jdolecek 	iobase = ats_iobase[pos3 & 0x7];
    173       1.1  jdolecek 	irq = ats_irq[((pos4 & 0x40) >> 4) | ((pos3 & 0xc0) >> 6)];
    174       1.1  jdolecek 
    175      1.20   tsutsui 	aprint_normal(" slot %d irq %d: %s\n",
    176      1.20   tsutsui 	    ma->ma_slot + 1, irq, atp->at_name);
    177       1.2  jdolecek 
    178       1.1  jdolecek 	/* Map i/o space. */
    179       1.1  jdolecek 	if (bus_space_map(iot, iobase, ATE_NPORTS, 0, &ioh)) {
    180      1.20   tsutsui 		aprint_error_dev(sc->sc_dev, "can't map i/o space\n");
    181       1.1  jdolecek 		return;
    182       1.1  jdolecek 	}
    183       1.1  jdolecek 
    184       1.1  jdolecek 	sc->sc_bst = iot;
    185       1.1  jdolecek 	sc->sc_bsh = ioh;
    186       1.1  jdolecek 
    187      1.10    simonb 	/* Get ethernet address. */
    188       1.1  jdolecek 	ate_mca_detect(iot, ioh, myea);
    189       1.1  jdolecek 
    190       1.1  jdolecek 	/* This interface is always enabled. */
    191       1.9   tsutsui 	sc->sc_stat |= FE_STAT_ENABLED;
    192       1.1  jdolecek 
    193       1.1  jdolecek 	/*
    194       1.1  jdolecek 	 * Do generic MB86960 attach.
    195       1.1  jdolecek 	 */
    196       1.9   tsutsui 	mb86960_attach(sc, myea);
    197       1.1  jdolecek 
    198       1.1  jdolecek 	mb86960_config(sc, NULL, 0, 0);
    199       1.1  jdolecek 
    200       1.1  jdolecek 	/* Establish the interrupt handler. */
    201       1.1  jdolecek 	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
    202      1.20   tsutsui 	    mb86960_intr, sc);
    203       1.1  jdolecek 	if (isc->sc_ih == NULL) {
    204      1.20   tsutsui 		aprint_error_dev(sc->sc_dev,
    205      1.20   tsutsui 		    "couldn't establish interrupt handler\n");
    206       1.1  jdolecek 		return;
    207       1.1  jdolecek 	}
    208       1.1  jdolecek }
    209       1.1  jdolecek 
    210       1.1  jdolecek /*
    211       1.1  jdolecek  * Very simplified ate_detect() from dev/isa/if_ate.c, only
    212       1.1  jdolecek  * to determine ethernet address.
    213       1.1  jdolecek  */
    214       1.1  jdolecek static void
    215      1.20   tsutsui ate_mca_detect(bus_space_tag_t iot, bus_space_handle_t ioh,
    216      1.20   tsutsui     uint8_t enaddr[ETHER_ADDR_LEN])
    217       1.1  jdolecek {
    218      1.20   tsutsui 	uint8_t eeprom[FE_EEPROM_SIZE];
    219       1.1  jdolecek 
    220       1.1  jdolecek 	/* Get our station address from EEPROM. */
    221       1.8   tsutsui 	mb86965_read_eeprom(iot, ioh, eeprom);
    222       1.8   tsutsui 	memcpy(enaddr, eeprom + FE_ATI_EEP_ADDR, ETHER_ADDR_LEN);
    223       1.1  jdolecek }
    224