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