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