xref: /netbsd/sys/dev/mca/if_ate_mca.c (revision bf9ec67e)
1 /*	$NetBSD: if_ate_mca.c,v 1.3 2001/11/13 07:46:25 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 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 ATI AT1720X MCA cards based on Fujitsu MB8696xA controller.
41  */
42 
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: if_ate_mca.c,v 1.3 2001/11/13 07:46:25 lukem Exp $");
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/device.h>
49 #include <sys/socket.h>
50 #include <sys/syslog.h>
51 
52 #include <net/if.h>
53 #include <net/if_ether.h>
54 #include <net/if_media.h>
55 
56 #include <machine/bus.h>
57 #include <machine/intr.h>
58 
59 #include <dev/ic/mb86960reg.h>
60 #include <dev/ic/mb86960var.h>
61 #include <dev/ic/ate_subr.h>
62 
63 #include <dev/mca/mcavar.h>
64 #include <dev/mca/mcadevs.h>
65 #include <dev/isa/if_fereg.h>	/* XXX */
66 
67 int	ate_mca_match __P((struct device *, struct cfdata *, void *));
68 void	ate_mca_attach __P((struct device *, struct device *, void *));
69 static void ate_mca_detect __P((bus_space_tag_t, bus_space_handle_t,
70     u_int8_t enaddr[ETHER_ADDR_LEN]));
71 
72 #define ATE_NPORTS 0x20
73 
74 struct ate_softc {
75 	struct	mb86960_softc sc_mb86960;	/* real "mb86960" softc */
76 
77 	/* MCA-specific goo. */
78 	void	*sc_ih;				/* interrupt cookie */
79 };
80 
81 struct cfattach ate_mca_ca = {
82 	sizeof(struct ate_softc), ate_mca_match, ate_mca_attach
83 };
84 
85 static const struct ate_mca_product {
86 	u_int32_t	at_prodid;	/* MCA product ID */
87 	const char	*at_name;	/* device name */
88 	int		at_type;	/* device type */
89 } ate_mca_products[] = {
90 	{ MCA_PRODUCT_AT1720T,	"ATI AT1720T",	FE_TYPE_AT1700T		},
91 	{ MCA_PRODUCT_AT1720BT,	"ATI AT1720BT",	FE_TYPE_AT1700BT	},
92 	{ MCA_PRODUCT_AT1720AT, "ATI AT1720AT",	FE_TYPE_AT1700AT	},
93 	{ MCA_PRODUCT_AT1720FT, "ATI AT1720FT",	FE_TYPE_AT1700FT	},
94 	{ 0, 	},
95 };
96 
97 static const struct ate_mca_product *ate_mca_lookup __P((u_int32_t));
98 
99 static const struct ate_mca_product *
100 ate_mca_lookup(id)
101 	u_int32_t id;
102 {
103 	const struct ate_mca_product *atp;
104 
105 	for (atp = ate_mca_products; atp->at_name != NULL; atp++)
106 		if (id == atp->at_prodid)
107 			return (atp);
108 
109 	return (NULL);
110 }
111 
112 int
113 ate_mca_match(parent, match, aux)
114 	struct device *parent;
115 	struct cfdata *match;
116 	void *aux;
117 {
118 	struct mca_attach_args *ma = (struct mca_attach_args *) aux;
119 
120 	if (ate_mca_lookup(ma->ma_id) != NULL)
121 		return (1);
122 
123 	return (0);
124 }
125 
126 /* see POS diagrams below for explanation of these arrays' contents */
127 static const int ats_iobase[] = {
128 	0x400, 0x2400, 0x4400, 0x6400, 0x1400, 0x3400, 0x5400, 0x7400
129 };
130 static const int ats_irq[] = {
131 	3, 4, 5, 9, 10, 11, 12, 15
132 };
133 
134 void
135 ate_mca_attach(parent, self, aux)
136 	struct device *parent, *self;
137 	void *aux;
138 {
139 	struct ate_softc *isc = (struct ate_softc *)self;
140 	struct mb86960_softc *sc = &isc->sc_mb86960;
141 	struct mca_attach_args *ma = aux;
142 	bus_space_tag_t iot = ma->ma_iot;
143 	bus_space_handle_t ioh;
144 	u_int8_t myea[ETHER_ADDR_LEN];
145 	int type, pos3, pos4;
146 	int iobase, irq;
147 	const struct ate_mca_product *atp;
148 
149 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
150 	pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
151 
152 	/*
153 	 * POS register 2: (adf pos0)
154 	 * 7 6 5 4 3 2 1 0
155 	 *               \__ enable: 0=adapter disabled, 1=adapter enabled
156 	 *
157 	 * POS register 3: (adf pos1)
158 	 *
159 	 * 7 6 5 4 3 2 1 0
160 	 * \_/ \___/ \___/
161 	 *   \     \     \__ I/O Port Addresses: 000=0x400-0x4FF 100=0x1400-
162 	 *    \     \          001=0x2400 101=0x3400 010=0x4400 110=0x5400
163 	 *     \     \         011=0x6400 111=0x7400
164 	 *      \     \_____ Boot ROM Memory Address
165 	 *       \
166 	 *        \_________ Lower 2 bit of Interrupt Request Number
167 	 *
168 	 * POS register 4: (adf pos2)
169 	 *
170 	 * 7 6 5 4 3 2 1 0
171 	 *   \      \_______ Twisted Pair Type: 0=100 ohm, Unshielded
172 	 *    \                1=150 ohm, Shielded
173 	 *     \____________ Higher 1 bit of Interrupt Request Number:
174 	 *                   000=3 001=4 010=5 011=9 100=10 101=11 110=12 111=15
175 	 */
176 
177 	atp = ate_mca_lookup(ma->ma_id);
178 #ifdef DIAGNOSTIC
179 	if (atp == NULL) {
180 		printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
181 		return;
182 	}
183 #endif
184 
185 	iobase = ats_iobase[pos3 & 0x7];
186 	irq = ats_irq[((pos4 & 0x40) >> 4) | ((pos3 & 0xc0) >> 6)];
187 
188 	printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, atp->at_name);
189 
190 	/* Map i/o space. */
191 	if (bus_space_map(iot, iobase, ATE_NPORTS, 0, &ioh)) {
192 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
193 		return;
194 	}
195 
196 	sc->sc_bst = iot;
197 	sc->sc_bsh = ioh;
198 
199 	/* Determine the card type and get ethernet address. */
200 	ate_mca_detect(iot, ioh, myea);
201 	type = atp->at_type;
202 
203 	/* This interface is always enabled. */
204 	sc->sc_flags |= FE_FLAGS_ENABLED;
205 
206 	/*
207 	 * Do generic MB86960 attach.
208 	 */
209 	mb86960_attach(sc, MB86960_TYPE_86965, myea);
210 
211 	mb86960_config(sc, NULL, 0, 0);
212 
213 	/* Establish the interrupt handler. */
214 	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
215 			mb86960_intr, sc);
216 	if (isc->sc_ih == NULL) {
217 		printf("%s: couldn't establish interrupt handler\n",
218 		    sc->sc_dev.dv_xname);
219 		return;
220 	}
221 }
222 
223 /*
224  * Very simplified ate_detect() from dev/isa/if_ate.c, only
225  * to determine ethernet address.
226  */
227 static void
228 ate_mca_detect(iot, ioh, enaddr)
229 	bus_space_tag_t iot;
230 	bus_space_handle_t ioh;
231 	u_int8_t enaddr[ETHER_ADDR_LEN];
232 {
233 	u_char eeprom[FE_EEPROM_SIZE];
234 
235 	/* Get our station address from EEPROM. */
236 	ate_read_eeprom(iot, ioh, eeprom);
237 	bcopy(eeprom + FE_ATI_EEP_ADDR, enaddr, ETHER_ADDR_LEN);
238 }
239