xref: /openbsd-src/sys/dev/eisa/if_ep_eisa.c (revision f1dd7b858388b4a23f4f67a4957ec5ff656ebbe8)
1 /*	$OpenBSD: if_ep_eisa.c,v 1.27 2021/03/07 06:18:48 jsg Exp $	*/
2 /*	$NetBSD: if_ep_eisa.c,v 1.13 1997/04/18 00:50:33 cgd Exp $	*/
3 
4 /*
5  * Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.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 
35 #include "bpfilter.h"
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/mbuf.h>
40 #include <sys/socket.h>
41 #include <sys/ioctl.h>
42 #include <sys/errno.h>
43 #include <sys/syslog.h>
44 #include <sys/selinfo.h>
45 #include <sys/timeout.h>
46 #include <sys/device.h>
47 
48 #include <net/if.h>
49 #include <net/if_media.h>
50 
51 #include <netinet/in.h>
52 #include <netinet/if_ether.h>
53 
54 #if NBPFILTER > 0
55 #include <net/bpf.h>
56 #endif
57 
58 #include <machine/cpu.h>
59 #include <machine/bus.h>
60 #include <machine/intr.h>
61 
62 #include <dev/mii/mii.h>
63 #include <dev/mii/miivar.h>
64 
65 #include <dev/ic/elink3var.h>
66 #include <dev/ic/elink3reg.h>
67 
68 #include <dev/eisa/eisareg.h>
69 #include <dev/eisa/eisavar.h>
70 #include <dev/eisa/eisadevs.h>
71 
72 int ep_eisa_match(struct device *, void *, void *);
73 void ep_eisa_attach(struct device *, struct device *, void *);
74 
75 struct cfattach ep_eisa_ca = {
76 	sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
77 };
78 
79 /* XXX move these somewhere else */
80 #define EISA_CONTROL	0x0c84
81 #define EISA_RESET	0x04
82 #define EISA_ERROR	0x02
83 #define EISA_ENABLE	0x01
84 
85 int
86 ep_eisa_match(struct device *parent, void *match, void *aux)
87 {
88 	struct eisa_attach_args *ea = aux;
89 
90 	/* must match one of our known ID strings */
91 	if (strcmp(ea->ea_idstring, "TCM5090") &&
92 	    strcmp(ea->ea_idstring, "TCM5091") &&
93 	    strcmp(ea->ea_idstring, "TCM5092") &&
94 	    strcmp(ea->ea_idstring, "TCM5093") &&
95 	    strcmp(ea->ea_idstring, "TCM5094") &&
96 	    strcmp(ea->ea_idstring, "TCM5095") &&
97 	    strcmp(ea->ea_idstring, "TCM5098") &&
98 	    strcmp(ea->ea_idstring, "TCM5920") &&
99 	    strcmp(ea->ea_idstring, "TCM5970") &&
100 	    strcmp(ea->ea_idstring, "TCM5971") &&
101 	    strcmp(ea->ea_idstring, "TCM5972"))
102 		return (0);
103 
104 	return (1);
105 }
106 
107 void
108 ep_eisa_attach(struct device *parent, struct device *self, void *aux)
109 {
110 	struct ep_softc *sc = (void *)self;
111 	struct eisa_attach_args *ea = aux;
112 	bus_space_tag_t iot = ea->ea_iot;
113 	bus_space_handle_t ioh;
114 	u_int16_t k;
115 	eisa_chipset_tag_t ec = ea->ea_ec;
116 	eisa_intr_handle_t ih;
117 	const char *model, *intrstr;
118 	int chipset;
119 	u_int irq;
120 
121 	/* Map i/o space. */
122 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
123 	    EISA_SLOT_SIZE, 0, &ioh))
124 		panic(": can't map i/o space");
125 
126 	sc->bustype = EP_BUS_EISA;
127 	sc->sc_ioh = ioh;
128 	sc->sc_iot = iot;
129 
130 	bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE);
131 	delay(4000);
132 
133 	/* XXX What is this doing?!  Reading the i/o address? */
134 	k = bus_space_read_2(iot, ioh, EP_W0_ADDRESS_CFG);
135 	k = (k & 0x1f) * 0x10 + 0x200;
136 
137 	/* Read the IRQ from the card. */
138 	irq = bus_space_read_2(iot, ioh, EP_W0_RESOURCE_CFG) >> 12;
139 
140 	chipset = EP_CHIPSET_3C509;	/* assume dumb chipset */
141 	if (strcmp(ea->ea_idstring, "TCM5090") == 0)
142 		model = EISA_PRODUCT_TCM5090;
143 	else if (strcmp(ea->ea_idstring, "TCM5091") == 0)
144 		model = EISA_PRODUCT_TCM5091;
145 	else if (strcmp(ea->ea_idstring, "TCM5092") == 0)
146 		model = EISA_PRODUCT_TCM5092;
147 	else if (strcmp(ea->ea_idstring, "TCM5093") == 0)
148 		model = EISA_PRODUCT_TCM5093;
149 	else if (strcmp(ea->ea_idstring, "TCM5094") == 0)
150 		model = EISA_PRODUCT_TCM5094;
151 	else if (strcmp(ea->ea_idstring, "TCM5095") == 0)
152 		model = EISA_PRODUCT_TCM5095;
153 	else if (strcmp(ea->ea_idstring, "TCM5098") == 0)
154 		model = EISA_PRODUCT_TCM5098;
155 	else if (strcmp(ea->ea_idstring, "TCM5920") == 0) {
156 		model = EISA_PRODUCT_TCM5920;
157 		chipset = EP_CHIPSET_VORTEX;
158 	} else if (strcmp(ea->ea_idstring, "TCM5970") == 0) {
159 		model = EISA_PRODUCT_TCM5970;
160 		chipset = EP_CHIPSET_VORTEX;
161 	} else if (strcmp(ea->ea_idstring, "TCM5971") == 0) {
162 		model = EISA_PRODUCT_TCM5971;
163 		chipset = EP_CHIPSET_VORTEX;
164 	} else if (strcmp(ea->ea_idstring, "TCM5972") == 0) {
165 		model = EISA_PRODUCT_TCM5972;
166 		chipset = EP_CHIPSET_VORTEX;
167 	} else
168 		model = "unknown model!";
169 
170 	if (eisa_intr_map(ec, irq, &ih)) {
171 		printf(": couldn't map interrupt (%u)\n", irq);
172 		bus_space_unmap(iot, ioh, EISA_SLOT_SIZE);
173 		return;
174 	}
175 	intrstr = eisa_intr_string(ec, ih);
176 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
177 	    epintr, sc, sc->sc_dev.dv_xname);
178 	if (sc->sc_ih == NULL) {
179 		printf(": couldn't establish interrupt");
180 		if (intrstr != NULL)
181 			printf(" at %s", intrstr);
182 		printf("\n");
183 		bus_space_unmap(iot, ioh, EISA_SLOT_SIZE);
184 		return;
185 	}
186 
187 	printf(": %s,", model);
188 	if (intrstr != NULL)
189 		printf(" %s,", intrstr);
190 
191 	epconfig(sc, chipset, NULL);
192 	/* XXX because epconfig() will not print a newline for vortex chips */
193 	if (chipset == EP_CHIPSET_VORTEX)
194 		printf("\n");
195 }
196