Home | History | Annotate | Line # | Download | only in eisa
      1 /*	$NetBSD: if_ep_eisa.c,v 1.44 2021/01/27 04:35:15 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
     35  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
     36  * All rights reserved.
     37  *
     38  * Redistribution and use in source and binary forms, with or without
     39  * modification, are permitted provided that the following conditions
     40  * are met:
     41  * 1. Redistributions of source code must retain the above copyright
     42  *    notice, this list of conditions and the following disclaimer.
     43  * 2. Redistributions in binary form must reproduce the above copyright
     44  *    notice, this list of conditions and the following disclaimer in the
     45  *    documentation and/or other materials provided with the distribution.
     46  * 3. All advertising materials mentioning features or use of this software
     47  *    must display the following acknowledgement:
     48  *      This product includes software developed by Herb Peyerl.
     49  *      This product includes software developed by Jonathan Stone.
     50  * 4. The name of Herb Peyerl or Jonathan Stone may not be used to endorse
     51  *    or promote products derived from this software without specific
     52  *    prior written permission.
     53  *
     54  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     55  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     56  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     57  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     58  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     59  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     60  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     61  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     62  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     63  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     64  */
     65 
     66 #include <sys/cdefs.h>
     67 __KERNEL_RCSID(0, "$NetBSD: if_ep_eisa.c,v 1.44 2021/01/27 04:35:15 thorpej Exp $");
     68 
     69 #include "opt_inet.h"
     70 
     71 #include <sys/param.h>
     72 #include <sys/systm.h>
     73 #include <sys/mbuf.h>
     74 #include <sys/socket.h>
     75 #include <sys/ioctl.h>
     76 #include <sys/errno.h>
     77 #include <sys/syslog.h>
     78 #include <sys/select.h>
     79 #include <sys/device.h>
     80 
     81 #include <net/if.h>
     82 #include <net/if_dl.h>
     83 #include <net/if_ether.h>
     84 #include <net/if_media.h>
     85 
     86 #ifdef INET
     87 #include <netinet/in.h>
     88 #include <netinet/in_systm.h>
     89 #include <netinet/in_var.h>
     90 #include <netinet/ip.h>
     91 #include <netinet/if_inarp.h>
     92 #endif
     93 
     94 #include <sys/cpu.h>
     95 #include <sys/bus.h>
     96 #include <sys/intr.h>
     97 
     98 #include <dev/mii/miivar.h>
     99 
    100 #include <dev/ic/elink3var.h>
    101 #include <dev/ic/elink3reg.h>
    102 
    103 #include <dev/eisa/eisareg.h>
    104 #include <dev/eisa/eisavar.h>
    105 #include <dev/eisa/eisadevs.h>
    106 
    107 static int	ep_eisa_match(device_t , cfdata_t , void *);
    108 static void	ep_eisa_attach(device_t , device_t , void *);
    109 
    110 CFATTACH_DECL_NEW(ep_eisa, sizeof(struct ep_softc),
    111     ep_eisa_match, ep_eisa_attach, NULL, NULL);
    112 
    113 /* XXX move these somewhere else */
    114 /* While attaching we need a few special EISA registers of the card,
    115    these are mapped at slotbase+EP_EISA_CFG_BASE with len EP_EISA_CFG_SIZE */
    116 #define EP_EISA_CFG_BASE	0x0c80
    117 #define	EP_EISA_CFG_CONTROL	0x0004	/* 1 byte */
    118 #define	EP_EISA_CFG_RESOURCE	0x0008	/* 2 byte */
    119 #define	EP_EISA_CFG_SIZE	0x000a
    120 
    121 /* The generic driver backend only needs access to the standard ports,
    122    mapped at the beginning of the eisa slot space */
    123 #define	EP_IOPORT_OFFSET	0x0000
    124 #define	EP_IOPORT_SIZE		0x0020
    125 
    126 /* Bits for the eisa control register */
    127 #define EISA_RESET	0x04
    128 #define EISA_ERROR	0x02
    129 #define EISA_ENABLE	0x01
    130 
    131 struct ep_eisa_product {
    132 	u_short		chipset;	/* 3Com chipset used */
    133 	int		flags;		/* initial softc flags */
    134 	const char	*name;		/* device name */
    135 };
    136 
    137 static const struct ep_eisa_product tcm5090 = {
    138 	.chipset = ELINK_CHIPSET_3C509,
    139 	.flags = 0,
    140 	.name = EISA_PRODUCT_TCM5090
    141 };
    142 
    143 static const struct ep_eisa_product tcm5091 = {
    144 	.chipset = ELINK_CHIPSET_3C509,
    145 	.flags = 0,
    146 	.name = EISA_PRODUCT_TCM5091
    147 };
    148 
    149 static const struct ep_eisa_product tcm5092 = {
    150 	.chipset = ELINK_CHIPSET_3C509,
    151 	.flags = 0,
    152 	.name = EISA_PRODUCT_TCM5092
    153 };
    154 
    155 static const struct ep_eisa_product tcm5093 = {
    156 	.chipset = ELINK_CHIPSET_3C509,
    157 	.flags = 0,
    158 	.name = EISA_PRODUCT_TCM5093
    159 };
    160 
    161 static const struct ep_eisa_product tcm5094 = {
    162 	.chipset = ELINK_CHIPSET_3C509,
    163 	.flags = 0,
    164 	.name = EISA_PRODUCT_TCM5094
    165 };
    166 
    167 static const struct ep_eisa_product tcm5095 = {
    168 	.chipset = ELINK_CHIPSET_3C509,
    169 	.flags = 0,
    170 	.name = EISA_PRODUCT_TCM5095
    171 };
    172 
    173 static const struct ep_eisa_product tcm5098 = {
    174 	.chipset = ELINK_CHIPSET_3C509,
    175 	.flags = 0,
    176 	.name = EISA_PRODUCT_TCM5098
    177 };
    178 
    179 static const struct ep_eisa_product tcm5920 = {
    180 	.chipset = ELINK_CHIPSET_VORTEX,
    181 	.flags = 0,
    182 	.name = EISA_PRODUCT_TCM5920
    183 };
    184 
    185 static const struct ep_eisa_product tcm5970 = {
    186 	.chipset = ELINK_CHIPSET_VORTEX,
    187 	.flags = 0,
    188 	.name = EISA_PRODUCT_TCM5970
    189 };
    190 
    191 static const struct ep_eisa_product tcm5971 = {
    192 	.chipset = ELINK_CHIPSET_VORTEX,
    193 	.flags = 0,
    194 	.name = EISA_PRODUCT_TCM5971
    195 };
    196 
    197 /*
    198  * Note: The 3c597 Fast Etherlink MII (TCM5972) is an
    199  * MII connector for an external PHY.  We treat it as
    200  * `manual' in the core driver.
    201  */
    202 static const struct ep_eisa_product tcm5972 = {
    203 	.chipset = ELINK_CHIPSET_VORTEX,
    204 	.flags = 0,
    205 	.name = EISA_PRODUCT_TCM5972
    206 };
    207 
    208 static const struct device_compatible_entry compat_data[] = {
    209 	{ .compat = "TCM5090",	.data = &tcm5090 },
    210 	{ .compat = "TCM5091",	.data = &tcm5091 },
    211 	{ .compat = "TCM5092",	.data = &tcm5092 },
    212 	{ .compat = "TCM5093",	.data = &tcm5093 },
    213 	{ .compat = "TCM5094",	.data = &tcm5094 },
    214 	{ .compat = "TCM5095",	.data = &tcm5095 },
    215 	{ .compat = "TCM5098",	.data = &tcm5098 },
    216 	{ .compat = "TCM5920",	.data = &tcm5920 },
    217 	{ .compat = "TCM5970",	.data = &tcm5970 },
    218 	{ .compat = "TCM5971",	.data = &tcm5971 },
    219 	{ .compat = "TCM5972",	.data = &tcm5972 },
    220 	DEVICE_COMPAT_EOL
    221 };
    222 
    223 static int
    224 ep_eisa_match(device_t parent, cfdata_t match, void *aux)
    225 {
    226 	struct eisa_attach_args *ea = aux;
    227 
    228 	return (eisa_compatible_match(ea, compat_data));
    229 }
    230 
    231 static void
    232 ep_eisa_attach(device_t parent, device_t self, void *aux)
    233 {
    234 	struct ep_softc *sc = device_private(self);
    235 	struct eisa_attach_args *ea = aux;
    236 	const struct device_compatible_entry *dce;
    237 	bus_space_tag_t iot = ea->ea_iot;
    238 	bus_space_handle_t ioh, ioh_cfg;
    239 	eisa_chipset_tag_t ec = ea->ea_ec;
    240 	eisa_intr_handle_t ih;
    241 	const char *intrstr;
    242 	const struct ep_eisa_product *eep;
    243 	u_int irq;
    244 	char intrbuf[EISA_INTRSTR_LEN];
    245 
    246 	/* Map i/o space. */
    247 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_EISA_CFG_BASE,
    248 	    EP_EISA_CFG_SIZE, 0, &ioh_cfg)) {
    249 		printf("\n");
    250 		panic("ep_eisa_attach: can't map eisa cfg i/o space");
    251 	}
    252 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_IOPORT_OFFSET,
    253 	    EP_IOPORT_SIZE, 0, &ioh)) {
    254 		printf("\n");
    255 		panic("ep_eisa_attach: can't map i/o space");
    256 	}
    257 
    258 	sc->sc_dev = self;
    259 	sc->sc_ioh = ioh;
    260 	sc->sc_iot = iot;
    261 
    262 	bus_space_write_1(iot, ioh_cfg, EP_EISA_CFG_CONTROL, EISA_ENABLE);
    263 	delay(4000);
    264 
    265 	/* Read the IRQ from the card. */
    266 	irq = bus_space_read_2(iot, ioh_cfg, EP_EISA_CFG_RESOURCE) >> 12;
    267 
    268 	dce = eisa_compatible_lookup(ea, compat_data);
    269 	KASSERT(dce != NULL);
    270 	eep = dce->data;
    271 
    272 	/* we don't need access to the config registers any more, but
    273 	   noone else should be able to map this space, so keep it
    274 	   reserved? */
    275 #if 0
    276 	bus_space_unmap(iot, ioh_cfg, EP_EISA_CFG_SIZE);
    277 #endif
    278 
    279 	printf(": %s\n", eep->name);
    280 
    281 	sc->enable = NULL;
    282 	sc->disable = NULL;
    283 	sc->enabled = 1;
    284 
    285 	sc->bustype = ELINK_BUS_EISA;
    286 	sc->ep_flags = eep->flags;
    287 
    288 	if (eisa_intr_map(ec, irq, &ih)) {
    289 		aprint_error_dev(sc->sc_dev, "couldn't map interrupt (%u)\n",
    290 		    irq);
    291 		return;
    292 	}
    293 	intrstr = eisa_intr_string(ec, ih, intrbuf, sizeof(intrbuf));
    294 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
    295 	    epintr, sc);
    296 	if (sc->sc_ih == NULL) {
    297 		aprint_error_dev(sc->sc_dev, "couldn't establish interrupt");
    298 		if (intrstr != NULL)
    299 			aprint_error(" at %s", intrstr);
    300 		aprint_error("\n");
    301 		return;
    302 	}
    303 	if (intrstr != NULL)
    304 		aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
    305 
    306 	epconfig(sc, eep->chipset, NULL);
    307 }
    308