xref: /netbsd-src/sys/dev/mca/if_tra_mca.c (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: if_tra_mca.c,v 1.3 2005/12/11 12:22:18 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jaromir Dolecek.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Driver for Tiara LANCard/E II and friends adapted from if_ate_mca.c
41  * by Dave J. Barnes 2004.
42  */
43 
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: if_tra_mca.c,v 1.3 2005/12/11 12:22:18 christos Exp $");
46 
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50 #include <sys/socket.h>
51 #include <sys/syslog.h>
52 
53 #include <net/if.h>
54 #include <net/if_ether.h>
55 #include <net/if_media.h>
56 
57 #include <machine/bus.h>
58 #include <machine/intr.h>
59 
60 #include <dev/ic/mb86950reg.h>
61 #include <dev/ic/mb86950var.h>
62 
63 #include <dev/mca/mcavar.h>
64 #include <dev/mca/mcadevs.h>
65 
66 int	tiara_mca_match __P((struct device *, struct cfdata *, void *));
67 void	tiara_mca_attach __P((struct device *, struct device *, void *));
68 
69 #define TIARA_NPORTS 0x20 /* 32 */
70 #define TIARA_PROM_ID 24 /* offset to mac addr stored in prom */
71 
72 struct tiara_softc {
73 	struct	mb86950_softc sc_mb86950;	/* real "mb86950" softc */
74 
75 	/* MCA-specific goo. */
76 	void	*sc_ih;				/* interrupt cookie */
77 };
78 
79 CFATTACH_DECL(tra_mca, sizeof(struct tiara_softc),
80     tiara_mca_match, tiara_mca_attach, NULL, NULL);
81 
82 static const struct tiara_mca_product {
83 	u_int32_t	tra_prodid;	/* MCA product ID */
84 	const char	*tra_name;	/* device name */
85 } tiara_mca_products[] = {
86 	{ MCA_PRODUCT_TIARA,	"Tiara LANCard/E2"},
87 	{ MCA_PRODUCT_TIARA_TP,	"Tiara LANCard/E2 TP"},
88 	{ MCA_PRODUCT_SMC3016,  "SMC 3016/MC"},
89 	{ 0	}
90 };
91 
92 static const struct tiara_mca_product *tiara_mca_lookup __P((u_int32_t));
93 
94 static const struct tiara_mca_product *
95 tiara_mca_lookup(id)
96 	u_int32_t id;
97 {
98 	const struct tiara_mca_product *tra_p;
99 
100 	for (tra_p = tiara_mca_products; tra_p->tra_name != NULL; tra_p++)
101 		if (id == tra_p->tra_prodid)
102 			return (tra_p);
103 
104 	return (NULL);
105 }
106 
107 int
108 tiara_mca_match(parent, match, aux)
109 	struct device *parent;
110 	struct cfdata *match;
111 	void *aux;
112 {
113 	struct mca_attach_args *ma = (struct mca_attach_args *) aux;
114 
115 	if (tiara_mca_lookup(ma->ma_id) != NULL)
116 		return (1);
117 
118 	return (0);
119 }
120 
121 /* see POS diagrams below for explanation */
122 static const int tiara_irq[] = {
123 	3, 4, 7, 9
124 };
125 static const int smc_iobase[] = {
126 	0x300, 0x340, 0x360, 0x1980, 0x2000, 0x5680, 0x5900, 0x8080
127 };
128 static const int smc_irq[] = {
129 	9, 10, 11, 15, 3, 5, 7, 4
130 };
131 
132 void
133 tiara_mca_attach(parent, self, aux)
134 	struct device *parent, *self;
135 	void *aux;
136 {
137 	struct tiara_softc *isc = (struct tiara_softc *)self;
138 	struct mb86950_softc *sc = &isc->sc_mb86950;
139 	struct mca_attach_args *ma = aux;
140 	bus_space_tag_t iot = ma->ma_iot;
141 	bus_space_handle_t ioh;
142 	u_int8_t myea[ETHER_ADDR_LEN];
143 	int pos2;
144 	int iobase = 0, irq = 0;
145 	const struct tiara_mca_product *tra_p;
146 
147 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
148 
149 	tra_p = tiara_mca_lookup(ma->ma_id);
150 
151 	switch (tra_p->tra_prodid) {
152 
153 	case MCA_PRODUCT_TIARA:
154 	case MCA_PRODUCT_TIARA_TP:
155 		/*
156 		 * POS register 2: (adf pos0)
157 		 * 7 6 5 4 3 2 1 0
158 		 * \_____/ \_/  \ \__ enable: 0=disabled, 1=enabled
159 		 *       \   \   \___ boot rom: 0=disabled, 1=enabled
160 		 *        \   \______ IRQ 00=3 01=4 10=7 11=9
161 		 *         \_________ Base I/O Port
162 		 *			0000=0x1200 0001=0x1220 ... 1110=0x13c0 1111=0x13e0
163 		 *
164 		 * POS register 3: (adf pos1) not used
165 		 * POS register 4: (adf pos2) not used
166 		 *
167 		 * POS register 5: (adf pos3) ignored
168 		 *
169 		 * 7 6 5 4 3 2 1 0
170 		 * 1 1 0 X \____/
171 		 *              \____EPROM Address
172 		 */
173 		iobase = 0x1200 + ((pos2 & 0xf0) << 1);
174 		irq = tiara_irq[((pos2 & 0x0c) >> 2)];
175 
176 		/* XXX SWAG for number pkts. */
177 		/* My Tiara LANCard has 128K memory ?!? */
178 		sc->txb_num_pkt = 4;
179 		sc->rxb_num_pkt = (65535 - 8192 - 4) / 64;
180 		/* XXX                       */
181 
182 		break;
183 
184 	case MCA_PRODUCT_SMC3016:
185 		/*
186 		 * POS register 2: (adf pos0)
187 		 * 7 6 5 4 3 2 1 0
188 		 * \_____/ \___/  \__ enable: 0=disabled, 1=enabled
189 		 *       \     \_____ I/O Address (see ioaddr table)
190 		 *        \__________ IRQ (see irq table)
191 		 *
192 		 * POS register 3: (adf pos1) ignored
193 		 * 7 6 5 4 3 2 1 0
194 		 * X X X X \____/
195 		 *              \____EPROM Address (0000 = not used)
196 		 */
197 		iobase = smc_iobase[((pos2 & 0x0e) >> 1)];
198 		if ((pos2 & 0x80) != 0)
199 			irq = smc_irq[((pos2 & 0x70) >> 4)];
200 		else {
201 			printf("%s: unsupported irq selected\n",
202 			    sc->sc_dev.dv_xname);
203 			return;
204 		}
205 
206 		/* XXX SWAG for number pkts. */
207 		/* The SMC3016 has a 12K rx buffer and a 4k tx buffer */
208 		sc->txb_num_pkt = 2;
209 		sc->rxb_num_pkt = (12288 - 4) / 64;
210 		/* XXX                       */
211 
212 		break;
213 	}
214 
215 
216 #ifdef DIAGNOSTIC
217 	tra_p = tiara_mca_lookup(ma->ma_id);
218 	if (tra_p == NULL) {
219 		printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
220 		return;
221 	}
222 #endif
223 
224 	printf(" slot %d ports %#x-%#x irq %d: %s\n", ma->ma_slot + 1,iobase, iobase + TIARA_NPORTS, irq, tra_p->tra_name);
225 
226 	/* Map i/o space. */
227 	if (bus_space_map(iot, iobase, TIARA_NPORTS, 0, &ioh)) {
228 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
229 		return;
230 	}
231 
232 	sc->sc_bst = iot;
233 	sc->sc_bsh = ioh;
234 
235 	/* Get ethernet address from PROM */
236 	bus_space_read_region_1(iot, ioh, TIARA_PROM_ID, myea, ETHER_ADDR_LEN);
237 
238 	/* This interface is always enabled. */
239 	/* XXX
240 	sc->sc_stat |= NIC_STAT_ENABLED;
241 	*/
242 
243 	/*
244 	 * Do generic MB86950 attach.
245 	 */
246 	mb86950_attach(sc, myea);
247 
248 
249 	mb86950_config(sc, NULL, 0, 0);
250 
251 	/* Establish the interrupt handler. */
252 	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
253 			mb86950_intr, sc);
254 	if (isc->sc_ih == NULL) {
255 		printf("%s: couldn't establish interrupt handler\n",
256 		    sc->sc_dev.dv_xname);
257 		return;
258 	}
259 }
260