if_ate_mca.c revision 1.1.2.2 1 1.1.2.2 nathanw /* $NetBSD: if_ate_mca.c,v 1.1.2.2 2001/04/09 01:56:46 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*-
4 1.1.2.2 nathanw * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1.2.2 nathanw * All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 nathanw * by Jaromir Dolecek.
9 1.1.2.2 nathanw *
10 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.2.2 nathanw * are met:
13 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 nathanw * must display the following acknowledgement:
20 1.1.2.2 nathanw * This product includes software developed by the NetBSD
21 1.1.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.2.2 nathanw * from this software without specific prior written permission.
25 1.1.2.2 nathanw *
26 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 nathanw */
38 1.1.2.2 nathanw
39 1.1.2.2 nathanw /*
40 1.1.2.2 nathanw * Driver for ATI AT1720X MCA cards based on Fujitsu MB8696xA controller.
41 1.1.2.2 nathanw */
42 1.1.2.2 nathanw
43 1.1.2.2 nathanw #include <sys/param.h>
44 1.1.2.2 nathanw #include <sys/systm.h>
45 1.1.2.2 nathanw #include <sys/device.h>
46 1.1.2.2 nathanw #include <sys/socket.h>
47 1.1.2.2 nathanw #include <sys/syslog.h>
48 1.1.2.2 nathanw
49 1.1.2.2 nathanw #include <net/if.h>
50 1.1.2.2 nathanw #include <net/if_ether.h>
51 1.1.2.2 nathanw #include <net/if_media.h>
52 1.1.2.2 nathanw
53 1.1.2.2 nathanw #include <machine/bus.h>
54 1.1.2.2 nathanw #include <machine/intr.h>
55 1.1.2.2 nathanw
56 1.1.2.2 nathanw #include <dev/ic/mb86960reg.h>
57 1.1.2.2 nathanw #include <dev/ic/mb86960var.h>
58 1.1.2.2 nathanw #include <dev/ic/ate_subr.h>
59 1.1.2.2 nathanw
60 1.1.2.2 nathanw #include <dev/mca/mcavar.h>
61 1.1.2.2 nathanw #include <dev/mca/mcadevs.h>
62 1.1.2.2 nathanw #include <dev/isa/if_fereg.h> /* XXX */
63 1.1.2.2 nathanw
64 1.1.2.2 nathanw int ate_mca_match __P((struct device *, struct cfdata *, void *));
65 1.1.2.2 nathanw void ate_mca_attach __P((struct device *, struct device *, void *));
66 1.1.2.2 nathanw static void ate_mca_detect __P((bus_space_tag_t, bus_space_handle_t,
67 1.1.2.2 nathanw u_int8_t enaddr[ETHER_ADDR_LEN]));
68 1.1.2.2 nathanw
69 1.1.2.2 nathanw #define ATE_NPORTS 0x20
70 1.1.2.2 nathanw
71 1.1.2.2 nathanw struct ate_softc {
72 1.1.2.2 nathanw struct mb86960_softc sc_mb86960; /* real "mb86960" softc */
73 1.1.2.2 nathanw
74 1.1.2.2 nathanw /* MCA-specific goo. */
75 1.1.2.2 nathanw void *sc_ih; /* interrupt cookie */
76 1.1.2.2 nathanw };
77 1.1.2.2 nathanw
78 1.1.2.2 nathanw struct cfattach ate_mca_ca = {
79 1.1.2.2 nathanw sizeof(struct ate_softc), ate_mca_match, ate_mca_attach
80 1.1.2.2 nathanw };
81 1.1.2.2 nathanw
82 1.1.2.2 nathanw static const struct ate_mca_product {
83 1.1.2.2 nathanw u_int32_t at_prodid; /* MCA product ID */
84 1.1.2.2 nathanw const char *at_name; /* device name */
85 1.1.2.2 nathanw int at_type; /* device type */
86 1.1.2.2 nathanw } ate_mca_products[] = {
87 1.1.2.2 nathanw { MCA_PRODUCT_AT1720T, "ATI AT1720T", FE_TYPE_AT1700T },
88 1.1.2.2 nathanw { MCA_PRODUCT_AT1720BT, "ATI AT1720BT", FE_TYPE_AT1700BT },
89 1.1.2.2 nathanw { MCA_PRODUCT_AT1720AT, "ATI AT1720AT", FE_TYPE_AT1700AT },
90 1.1.2.2 nathanw { MCA_PRODUCT_AT1720FT, "ATI AT1720FT", FE_TYPE_AT1700FT },
91 1.1.2.2 nathanw { 0, },
92 1.1.2.2 nathanw };
93 1.1.2.2 nathanw
94 1.1.2.2 nathanw static const struct ate_mca_product *ate_mca_lookup __P((u_int32_t));
95 1.1.2.2 nathanw
96 1.1.2.2 nathanw static const struct ate_mca_product *
97 1.1.2.2 nathanw ate_mca_lookup(id)
98 1.1.2.2 nathanw u_int32_t id;
99 1.1.2.2 nathanw {
100 1.1.2.2 nathanw const struct ate_mca_product *atp;
101 1.1.2.2 nathanw
102 1.1.2.2 nathanw for (atp = ate_mca_products; atp->at_name != NULL; atp++)
103 1.1.2.2 nathanw if (id == atp->at_prodid)
104 1.1.2.2 nathanw return (atp);
105 1.1.2.2 nathanw
106 1.1.2.2 nathanw return (NULL);
107 1.1.2.2 nathanw }
108 1.1.2.2 nathanw
109 1.1.2.2 nathanw int
110 1.1.2.2 nathanw ate_mca_match(parent, match, aux)
111 1.1.2.2 nathanw struct device *parent;
112 1.1.2.2 nathanw struct cfdata *match;
113 1.1.2.2 nathanw void *aux;
114 1.1.2.2 nathanw {
115 1.1.2.2 nathanw struct mca_attach_args *ma = (struct mca_attach_args *) aux;
116 1.1.2.2 nathanw
117 1.1.2.2 nathanw if (ate_mca_lookup(ma->ma_id) != NULL)
118 1.1.2.2 nathanw return (1);
119 1.1.2.2 nathanw
120 1.1.2.2 nathanw return (0);
121 1.1.2.2 nathanw }
122 1.1.2.2 nathanw
123 1.1.2.2 nathanw /* see POS diagrams below for explanation of these arrays' contents */
124 1.1.2.2 nathanw static const int ats_iobase[] = {
125 1.1.2.2 nathanw 0x400, 0x2400, 0x4400, 0x6400, 0x1400, 0x3400, 0x5400, 0x7400
126 1.1.2.2 nathanw };
127 1.1.2.2 nathanw static const int ats_irq[] = {
128 1.1.2.2 nathanw 3, 4, 5, 9, 10, 11, 12, 15
129 1.1.2.2 nathanw };
130 1.1.2.2 nathanw
131 1.1.2.2 nathanw void
132 1.1.2.2 nathanw ate_mca_attach(parent, self, aux)
133 1.1.2.2 nathanw struct device *parent, *self;
134 1.1.2.2 nathanw void *aux;
135 1.1.2.2 nathanw {
136 1.1.2.2 nathanw struct ate_softc *isc = (struct ate_softc *)self;
137 1.1.2.2 nathanw struct mb86960_softc *sc = &isc->sc_mb86960;
138 1.1.2.2 nathanw struct mca_attach_args *ma = aux;
139 1.1.2.2 nathanw bus_space_tag_t iot = ma->ma_iot;
140 1.1.2.2 nathanw bus_space_handle_t ioh;
141 1.1.2.2 nathanw u_int8_t myea[ETHER_ADDR_LEN];
142 1.1.2.2 nathanw int type, pos3, pos4;
143 1.1.2.2 nathanw int iobase, irq;
144 1.1.2.2 nathanw const struct ate_mca_product *atp;
145 1.1.2.2 nathanw
146 1.1.2.2 nathanw pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
147 1.1.2.2 nathanw pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
148 1.1.2.2 nathanw
149 1.1.2.2 nathanw /*
150 1.1.2.2 nathanw * POS register 2: (adf pos0)
151 1.1.2.2 nathanw * 7 6 5 4 3 2 1 0
152 1.1.2.2 nathanw * \__ enable: 0=adapter disabled, 1=adapter enabled
153 1.1.2.2 nathanw *
154 1.1.2.2 nathanw * POS register 3: (adf pos1)
155 1.1.2.2 nathanw *
156 1.1.2.2 nathanw * 7 6 5 4 3 2 1 0
157 1.1.2.2 nathanw * \_/ \___/ \___/
158 1.1.2.2 nathanw * \ \ \__ I/O Port Addresses: 000=0x400-0x4FF 100=0x1400-
159 1.1.2.2 nathanw * \ \ 001=0x2400 101=0x3400 010=0x4400 110=0x5400
160 1.1.2.2 nathanw * \ \ 011=0x6400 111=0x7400
161 1.1.2.2 nathanw * \ \_____ Boot ROM Memory Address
162 1.1.2.2 nathanw * \
163 1.1.2.2 nathanw * \_________ Lower 2 bit of Interrupt Request Number
164 1.1.2.2 nathanw *
165 1.1.2.2 nathanw * POS register 4: (adf pos2)
166 1.1.2.2 nathanw *
167 1.1.2.2 nathanw * 7 6 5 4 3 2 1 0
168 1.1.2.2 nathanw * \ \_______ Twisted Pair Type: 0=100 ohm, Unshielded
169 1.1.2.2 nathanw * \ 1=150 ohm, Shielded
170 1.1.2.2 nathanw * \____________ Higher 1 bit of Interrupt Request Number:
171 1.1.2.2 nathanw * 000=3 001=4 010=5 011=9 100=10 101=11 110=12 111=15
172 1.1.2.2 nathanw */
173 1.1.2.2 nathanw
174 1.1.2.2 nathanw atp = ate_mca_lookup(ma->ma_id);
175 1.1.2.2 nathanw #ifdef DIAGNOSTIC
176 1.1.2.2 nathanw if (atp == NULL) {
177 1.1.2.2 nathanw printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
178 1.1.2.2 nathanw return;
179 1.1.2.2 nathanw }
180 1.1.2.2 nathanw #endif
181 1.1.2.2 nathanw
182 1.1.2.2 nathanw printf(" slot %d: %s\n", ma->ma_slot + 1, atp->at_name);
183 1.1.2.2 nathanw
184 1.1.2.2 nathanw iobase = ats_iobase[pos3 & 0x7];
185 1.1.2.2 nathanw irq = ats_irq[((pos4 & 0x40) >> 4) | ((pos3 & 0xc0) >> 6)];
186 1.1.2.2 nathanw
187 1.1.2.2 nathanw /* Map i/o space. */
188 1.1.2.2 nathanw if (bus_space_map(iot, iobase, ATE_NPORTS, 0, &ioh)) {
189 1.1.2.2 nathanw printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
190 1.1.2.2 nathanw return;
191 1.1.2.2 nathanw }
192 1.1.2.2 nathanw
193 1.1.2.2 nathanw sc->sc_bst = iot;
194 1.1.2.2 nathanw sc->sc_bsh = ioh;
195 1.1.2.2 nathanw
196 1.1.2.2 nathanw /* Determine the card type and get ethernet address. */
197 1.1.2.2 nathanw ate_mca_detect(iot, ioh, myea);
198 1.1.2.2 nathanw type = atp->at_type;
199 1.1.2.2 nathanw
200 1.1.2.2 nathanw /* This interface is always enabled. */
201 1.1.2.2 nathanw sc->sc_flags |= FE_FLAGS_ENABLED;
202 1.1.2.2 nathanw
203 1.1.2.2 nathanw /*
204 1.1.2.2 nathanw * Do generic MB86960 attach.
205 1.1.2.2 nathanw */
206 1.1.2.2 nathanw mb86960_attach(sc, MB86960_TYPE_86965, myea);
207 1.1.2.2 nathanw
208 1.1.2.2 nathanw mb86960_config(sc, NULL, 0, 0);
209 1.1.2.2 nathanw
210 1.1.2.2 nathanw /* Establish the interrupt handler. */
211 1.1.2.2 nathanw isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
212 1.1.2.2 nathanw mb86960_intr, sc);
213 1.1.2.2 nathanw if (isc->sc_ih == NULL) {
214 1.1.2.2 nathanw printf("%s: couldn't establish interrupt handler\n",
215 1.1.2.2 nathanw sc->sc_dev.dv_xname);
216 1.1.2.2 nathanw return;
217 1.1.2.2 nathanw }
218 1.1.2.2 nathanw
219 1.1.2.2 nathanw printf("%s: interrupting at irq %d\n", sc->sc_dev.dv_xname, irq);
220 1.1.2.2 nathanw }
221 1.1.2.2 nathanw
222 1.1.2.2 nathanw /*
223 1.1.2.2 nathanw * Very simplified ate_detect() from dev/isa/if_ate.c, only
224 1.1.2.2 nathanw * to determine ethernet address.
225 1.1.2.2 nathanw */
226 1.1.2.2 nathanw static void
227 1.1.2.2 nathanw ate_mca_detect(iot, ioh, enaddr)
228 1.1.2.2 nathanw bus_space_tag_t iot;
229 1.1.2.2 nathanw bus_space_handle_t ioh;
230 1.1.2.2 nathanw u_int8_t enaddr[ETHER_ADDR_LEN];
231 1.1.2.2 nathanw {
232 1.1.2.2 nathanw u_char eeprom[FE_EEPROM_SIZE];
233 1.1.2.2 nathanw
234 1.1.2.2 nathanw /* Get our station address from EEPROM. */
235 1.1.2.2 nathanw ate_read_eeprom(iot, ioh, eeprom);
236 1.1.2.2 nathanw bcopy(eeprom + FE_ATI_EEP_ADDR, enaddr, ETHER_ADDR_LEN);
237 1.1.2.2 nathanw }
238