xref: /openbsd/sys/dev/isa/if_ne_isapnp.c (revision ffccd32b)
1*ffccd32bSmvs /*	$OpenBSD: if_ne_isapnp.c,v 1.18 2023/09/11 08:41:26 mvs Exp $	*/
223c939fcSfgsch /*	$NetBSD: if_ne_isapnp.c,v 1.7 1998/07/23 19:30:45 christos Exp $	*/
323c939fcSfgsch 
423c939fcSfgsch /*-
523c939fcSfgsch  * Copyright (c) 1997 The NetBSD Foundation, Inc.
623c939fcSfgsch  * All rights reserved.
723c939fcSfgsch  *
823c939fcSfgsch  * This code is derived from software contributed to The NetBSD Foundation
923c939fcSfgsch  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
1023c939fcSfgsch  * NASA Ames Research Center and Matt Thomas of the 3am Software Foundry.
1123c939fcSfgsch  *
1223c939fcSfgsch  * Redistribution and use in source and binary forms, with or without
1323c939fcSfgsch  * modification, are permitted provided that the following conditions
1423c939fcSfgsch  * are met:
1523c939fcSfgsch  * 1. Redistributions of source code must retain the above copyright
1623c939fcSfgsch  *    notice, this list of conditions and the following disclaimer.
1723c939fcSfgsch  * 2. Redistributions in binary form must reproduce the above copyright
1823c939fcSfgsch  *    notice, this list of conditions and the following disclaimer in the
1923c939fcSfgsch  *    documentation and/or other materials provided with the distribution.
2023c939fcSfgsch  *
2123c939fcSfgsch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2223c939fcSfgsch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2323c939fcSfgsch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2423c939fcSfgsch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2523c939fcSfgsch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2623c939fcSfgsch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2723c939fcSfgsch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2823c939fcSfgsch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2923c939fcSfgsch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3023c939fcSfgsch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3123c939fcSfgsch  * POSSIBILITY OF SUCH DAMAGE.
3223c939fcSfgsch  */
3323c939fcSfgsch 
3423c939fcSfgsch #include "bpfilter.h"
3523c939fcSfgsch 
3623c939fcSfgsch #include <sys/param.h>
3723c939fcSfgsch #include <sys/systm.h>
3823c939fcSfgsch #include <sys/mbuf.h>
3923c939fcSfgsch #include <sys/socket.h>
4023c939fcSfgsch #include <sys/ioctl.h>
4123c939fcSfgsch #include <sys/errno.h>
4223c939fcSfgsch #include <sys/syslog.h>
4323c939fcSfgsch #include <sys/device.h>
4423c939fcSfgsch 
4523c939fcSfgsch #include <net/if.h>
4623c939fcSfgsch #include <net/if_media.h>
4723c939fcSfgsch 
4823c939fcSfgsch #include <netinet/in.h>
4923c939fcSfgsch #include <netinet/if_ether.h>
5023c939fcSfgsch 
5123c939fcSfgsch #if NBPFILTER > 0
5223c939fcSfgsch #include <net/bpf.h>
5323c939fcSfgsch #endif
5423c939fcSfgsch 
5523c939fcSfgsch #include <machine/intr.h>
5623c939fcSfgsch #include <machine/bus.h>
5723c939fcSfgsch 
5823c939fcSfgsch #include <dev/ic/dp8390reg.h>
5923c939fcSfgsch #include <dev/ic/dp8390var.h>
6023c939fcSfgsch 
6123c939fcSfgsch #include <dev/ic/ne2000reg.h>
6223c939fcSfgsch #include <dev/ic/ne2000var.h>
6323c939fcSfgsch 
64e370c91bSfgsch #include <dev/ic/rtl80x9reg.h>
65e370c91bSfgsch #include <dev/ic/rtl80x9var.h>
66e370c91bSfgsch 
6723c939fcSfgsch #include <dev/isa/isavar.h>
6823c939fcSfgsch 
6923c939fcSfgsch #include <dev/isa/isapnpreg.h>
7023c939fcSfgsch 
71c4071fd1Smillert static int ne_isapnp_match(struct device *, void *, void *);
72c4071fd1Smillert static void ne_isapnp_attach(struct device *, struct device *, void *);
7323c939fcSfgsch 
7423c939fcSfgsch struct ne_isapnp_softc {
7523c939fcSfgsch 	struct	ne2000_softc sc_ne2000;		/* real "ne2000" softc */
7623c939fcSfgsch 
7723c939fcSfgsch 	/* ISA-specific goo. */
7823c939fcSfgsch 	void	*sc_ih;				/* interrupt cookie */
7923c939fcSfgsch };
8023c939fcSfgsch 
81471aeecfSnaddy const struct cfattach ne_isapnp_ca = {
8223c939fcSfgsch 	sizeof(struct ne_isapnp_softc), ne_isapnp_match, ne_isapnp_attach
8323c939fcSfgsch };
8423c939fcSfgsch 
8523c939fcSfgsch static int
ne_isapnp_match(struct device * parent,void * match,void * aux)86cf96b6e2Sbrad ne_isapnp_match(struct device *parent, void *match, void *aux)
8723c939fcSfgsch {
88cf96b6e2Sbrad 	return (1);
8923c939fcSfgsch }
9023c939fcSfgsch 
9123c939fcSfgsch static void
ne_isapnp_attach(struct device * parent,struct device * self,void * aux)92cf96b6e2Sbrad ne_isapnp_attach(struct device *parent, struct device *self, void *aux)
9323c939fcSfgsch {
9423c939fcSfgsch 	struct ne_isapnp_softc * const isc = (struct ne_isapnp_softc *)self;
9523c939fcSfgsch 	struct ne2000_softc * const nsc = &isc->sc_ne2000;
9623c939fcSfgsch 	struct dp8390_softc * const dsc = &nsc->sc_dp8390;
9723c939fcSfgsch 	struct isa_attach_args * const ipa = aux;
9823c939fcSfgsch 	bus_space_tag_t nict;
9923c939fcSfgsch 	bus_space_handle_t nich;
10023c939fcSfgsch 	bus_space_tag_t asict;
10123c939fcSfgsch 	bus_space_handle_t asich;
10223c939fcSfgsch 	const char *typestr;
103e370c91bSfgsch 	int netype;
10423c939fcSfgsch 
10523c939fcSfgsch 	nict = ipa->ia_iot;
10623c939fcSfgsch 	nich = ipa->ipa_io[0].h;
10723c939fcSfgsch 
10823c939fcSfgsch 	asict = nict;
10923c939fcSfgsch 
11023c939fcSfgsch 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
11123c939fcSfgsch 	    NE2000_ASIC_NPORTS, &asich)) {
11223c939fcSfgsch 		printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
11323c939fcSfgsch 		return;
11423c939fcSfgsch 	}
11523c939fcSfgsch 
11623c939fcSfgsch 	dsc->sc_regt = nict;
11723c939fcSfgsch 	dsc->sc_regh = nich;
11823c939fcSfgsch 
11923c939fcSfgsch 	nsc->sc_asict = asict;
12023c939fcSfgsch 	nsc->sc_asich = asich;
12123c939fcSfgsch 
12223c939fcSfgsch 	/*
12323c939fcSfgsch 	 * Detect it again, so we can print some information about the
12423c939fcSfgsch 	 * interface.
12523c939fcSfgsch 	 */
126498e462dSfgsch 	netype = ne2000_detect(nsc);
127e370c91bSfgsch 	switch (netype) {
12823c939fcSfgsch 	case NE2000_TYPE_NE1000:
12923c939fcSfgsch 		typestr = "NE1000";
13023c939fcSfgsch 		break;
13123c939fcSfgsch 
13223c939fcSfgsch 	case NE2000_TYPE_NE2000:
13323c939fcSfgsch 		typestr = "NE2000";
134e370c91bSfgsch 		/*
1350499a7f2Sbrad 		 * Check for a Realtek 8019.
136e370c91bSfgsch 		 */
137e370c91bSfgsch 		bus_space_write_1(nict, nich, ED_P0_CR,
138e370c91bSfgsch 		    ED_CR_PAGE_0 | ED_CR_STP);
139e370c91bSfgsch 		if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) ==
140e370c91bSfgsch 								RTL0_8019ID0 &&
141e370c91bSfgsch 		    bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) ==
142e370c91bSfgsch 								RTL0_8019ID1) {
143e370c91bSfgsch 			typestr = "NE2000 (RTL8019)";
144e370c91bSfgsch 			dsc->sc_mediachange = rtl80x9_mediachange;
145e370c91bSfgsch 			dsc->sc_mediastatus = rtl80x9_mediastatus;
146e370c91bSfgsch 			dsc->init_card = rtl80x9_init_card;
147c4bae10aSaaron 			dsc->sc_media_init = rtl80x9_media_init;
148e370c91bSfgsch 		}
14923c939fcSfgsch 		break;
15023c939fcSfgsch 
15123c939fcSfgsch 	default:
1527c59cc70Sbrad 		printf(": where did the card go?!\n");
15323c939fcSfgsch 		return;
15423c939fcSfgsch 	}
15523c939fcSfgsch 
1567c59cc70Sbrad 	printf(": %s", typestr);
15723c939fcSfgsch 
15823c939fcSfgsch 	/* This interface is always enabled. */
15923c939fcSfgsch 	dsc->sc_enabled = 1;
16023c939fcSfgsch 
16123c939fcSfgsch 	/*
16223c939fcSfgsch 	 * Do generic NE2000 attach.  This will read the station address
16323c939fcSfgsch 	 * from the EEPROM.
16423c939fcSfgsch 	 */
165c4bae10aSaaron 	ne2000_attach(nsc, NULL);
16623c939fcSfgsch 
16723c939fcSfgsch 	/* Establish the interrupt handler. */
16823c939fcSfgsch 	isc->sc_ih = isa_intr_establish(ipa->ia_ic, ipa->ipa_irq[0].num,
16923c939fcSfgsch 	    IST_EDGE, IPL_NET, dp8390_intr, dsc,
17023c939fcSfgsch 	    dsc->sc_dev.dv_xname);
17123c939fcSfgsch 	if (isc->sc_ih == NULL)
1727c59cc70Sbrad 		printf(": couldn't establish interrupt handler\n");
17323c939fcSfgsch }
174