xref: /openbsd-src/sys/dev/isa/if_ep_isapnp.c (revision ffccd32ba7f20be5cea89dc95473805a70af3b9d)
1 /*	$OpenBSD: if_ep_isapnp.c,v 1.18 2023/09/11 08:41:26 mvs Exp $	*/
2 /*	$NetBSD: if_ep_isapnp.c,v 1.5 1996/05/12 23:52:36 mycroft Exp $	*/
3 
4 /*
5  * Copyright (c) 1996 Jason R. Thorpe <thorpej@beer.org>
6  * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by Herb Peyerl.
20  * 4. The name of Herb Peyerl may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Note: Most of the code here was written by Theo de Raadt originally,
35  * ie. all the mechanics of probing for all cards on first call and then
36  * searching for matching devices on subsequent calls.
37  */
38 
39 #include "bpfilter.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/mbuf.h>
44 #include <sys/socket.h>
45 #include <sys/ioctl.h>
46 #include <sys/errno.h>
47 #include <sys/syslog.h>
48 #include <sys/device.h>
49 #include <sys/timeout.h>
50 #include <sys/queue.h>
51 
52 #include <net/if.h>
53 #include <net/if_media.h>
54 
55 #include <netinet/in.h>
56 #include <netinet/if_ether.h>
57 
58 #if NBPFILTER > 0
59 #include <net/bpf.h>
60 #endif
61 
62 #include <machine/cpu.h>
63 #include <machine/bus.h>
64 #include <machine/intr.h>
65 
66 #include <dev/mii/mii.h>
67 #include <dev/mii/miivar.h>
68 
69 #include <dev/ic/elink3var.h>
70 #include <dev/ic/elink3reg.h>
71 
72 #include <dev/isa/isavar.h>
73 #include <dev/isa/elink.h>
74 
75 int ep_isapnp_match(struct device *, void *, void *);
76 void ep_isapnp_attach(struct device *, struct device *, void *);
77 
78 const struct cfattach ep_isapnp_ca = {
79 	sizeof(struct ep_softc), ep_isapnp_match, ep_isapnp_attach
80 };
81 
82 /*
83  * 3c509 cards on the ISA bus are probed in ethernet address order.
84  * The probe sequence requires careful orchestration, and we'd like
85  * to allow the irq and base address to be wildcarded. So, we
86  * probe all the cards the first time epprobe() is called. On subsequent
87  * calls we look for matching cards.
88  */
89 int
ep_isapnp_match(struct device * parent,void * match,void * aux)90 ep_isapnp_match(struct device *parent, void *match, void *aux)
91 {
92 	/* XXX This should be more intelligent */
93 	return 1;
94 }
95 
96 void
ep_isapnp_attach(struct device * parent,struct device * self,void * aux)97 ep_isapnp_attach(struct device *parent, struct device *self, void *aux)
98 {
99 	struct ep_softc *sc = (void *)self;
100 	struct isa_attach_args *ia = aux;
101 	bus_space_tag_t iot = ia->ia_iot;
102 	bus_space_handle_t ioh;
103 
104 	sc->sc_iot = iot = ia->ia_iot;
105 	sc->sc_ioh = ioh = ia->ipa_io[0].h;
106 	sc->bustype = EP_BUS_ISA;
107 
108 	printf(":");
109 
110 	/* Should look at ia->ia_devident... */
111 	epconfig(sc, EP_CHIPSET_3C509, NULL);
112 
113 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
114 	    IPL_NET, epintr, sc, sc->sc_dev.dv_xname);
115 }
116