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