1 /* $NetBSD: if_le_mca.c,v 1.17 2008/04/04 12:25:07 tsutsui Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Driver for SKNET Personal and MC2+ cards, which are AMD Lance 7990 based
34 * cards made by Syskonnect, former Schneider & Koch Datensysteme GmbH.
36 * Syskonnect was very helpful and provided docs for these cards promptly.
37 * I wish all vendors would be like that!
38 * I'd like to thank to Alfred Arnold, author of the Linux driver, for
39 * giving me contact to The Right Syskonnect person, too :-)
42 * SKNET MC+ Technical Manual, version 1.1, July 21 1993
43 * SKNET personal Technisches Manual, version 1.2, April 14 1988
44 * SKNET junior Technisches Manual, version 1.0, July 14 1987
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: if_le_mca.c,v 1.17 2008/04/04 12:25:07 tsutsui Exp $");
50 #include <sys/param.h>
51 #include <sys/systm.h>
53 #include <sys/syslog.h>
54 #include <sys/socket.h>
55 #include <sys/device.h>
57 #include <uvm/uvm_extern.h>
60 #include <net/if_ether.h>
61 #include <net/if_media.h>
67 #include <dev/ic/lancereg.h>
68 #include <dev/ic/lancevar.h>
69 #include <dev/ic/am7990reg.h>
70 #include <dev/ic/am7990var.h>
72 #include <dev/mca/mcareg.h>
73 #include <dev/mca/mcavar.h>
74 #include <dev/mca/mcadevs.h>
76 #include <dev/mca/if_lereg.h>
78 int le_mca_match(device_t
, cfdata_t
, void *);
79 void le_mca_attach(device_t
, device_t
, void *);
82 struct am7990_softc sc_am7990
; /* glue to MI code */
85 bus_space_tag_t sc_memt
;
86 bus_space_handle_t sc_memh
;
89 static void le_mca_wrcsr(struct lance_softc
*, uint16_t, uint16_t);
90 static uint16_t le_mca_rdcsr(struct lance_softc
*, uint16_t);
91 static void le_mca_hwreset(struct lance_softc
*);
92 static int le_mca_intredge(void *);
94 static void le_mca_copytobuf(struct lance_softc
*, void *, int, int);
95 static void le_mca_copyfrombuf(struct lance_softc
*, void *, int, int);
96 static void le_mca_zerobuf(struct lance_softc
*, int, int);
98 static inline void le_mca_wrreg(struct le_mca_softc
*, int, int);
99 #define le_mca_set_RAP(sc, reg_number) \
100 le_mca_wrreg(sc, reg_number, RAP | REGWRITE)
102 CFATTACH_DECL_NEW(le_mca
, sizeof(struct le_mca_softc
),
103 le_mca_match
, le_mca_attach
, NULL
, NULL
);
105 /* SKNET MC+ POS mapping */
106 static const u_int8_t sknet_mcp_irq
[] = {
109 static const u_int8_t sknet_mcp_media
[] = {
117 le_mca_match(device_t parent
, cfdata_t cf
, void *aux
)
119 struct mca_attach_args
*ma
= aux
;
122 case MCA_PRODUCT_SKNETPER
:
123 case MCA_PRODUCT_SKNETG
:
131 le_mca_attach(device_t parent
, device_t self
, void *aux
)
133 struct le_mca_softc
*lesc
= device_private(self
);
134 struct lance_softc
*sc
= &lesc
->sc_am7990
.lsc
;
135 struct mca_attach_args
*ma
= aux
;
136 int i
, pos2
, pos3
, pos4
, irq
, membase
, supmedia
=0;
144 * POS register 2: (adf pos0)
147 * | \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
148 * \ \____ Memory: 0xC0000-0xC3FFF + XX*0x4000
149 * \________ IRQ: 0=10 1=11
153 * POS register 2: (adf pos0)
156 * \___/ \ \__ enable: 0=adapter disabled, 1=adapter enabled
157 * \ \___ BootEPROM disable
158 * \_____ BootEPROM start address: 0xC0000 + XX*0x4000
160 * POS register 3: (adf pos1)
164 * \__ RAM: 0xC0000 + XX*0x4000
166 * POS register 4: (adf pos2)
170 * \ \ \__ Need to be reset to 0 0 after boot
171 * \ \_____ IRQ: 00=3 01=5 10=10 11=11
172 * \____________ Medium: 00=BNC 01=UTP 10=AUI 11=not allowed
176 case MCA_PRODUCT_SKNETPER
:
177 typestr
= "Personal MC2";
179 pos2
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 2);
180 irq
= (pos2
& (1<<4)) ? 11 : 10;
181 membase
= 0xc0000 + ((pos2
& 0x0e) >> 1) * 0x4000;
183 case MCA_PRODUCT_SKNETG
:
187 * SKNET MC+ needs the driver to clear 0, 1 bits of pos4
188 * and explicitly set the enable bit. Somebody at Syskonnect
189 * was obviously misguided when the card was designed ...
191 pos3
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 3);
192 pos4
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 4);
193 if ((pos4
& 0x03) != 0) {
194 /* clear the bits 0, 1 */
195 mca_conf_write(ma
->ma_mc
, ma
->ma_slot
, 4,
199 pos2
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 2);
200 if ((pos2
& 0x01) == 0) {
201 /* enable the card */
202 mca_conf_write(ma
->ma_mc
, ma
->ma_slot
, 2, pos2
| 0x01);
205 /* get irq and memory base */
206 irq
= sknet_mcp_irq
[(pos4
& 0x0c) >> 2];
207 membase
= 0xc0000 + ((pos3
& 0x0f) * 0x4000);
209 /* Get configured media type */
210 supmedia
= sknet_mcp_media
[(pos4
& 0xc0) >> 6];
213 aprint_error(": unknown product %d\n", ma
->ma_id
);
217 lesc
->sc_memt
= ma
->ma_memt
;
219 if (bus_space_map(lesc
->sc_memt
, membase
, LE_MCA_MEMSIZE
,
220 0, &lesc
->sc_memh
)) {
221 aprint_error(": can't map memory\n");
225 aprint_normal(" slot %d irq %d: SKNET %s Ethernet\n",
226 ma
->ma_slot
+ 1, irq
, typestr
);
229 * Extract the physical MAC address from the ROM.
231 for (i
= 0; i
< ETHER_ADDR_LEN
; i
++)
232 sc
->sc_enaddr
[i
] = bus_space_read_1(lesc
->sc_memt
,
233 lesc
->sc_memh
, LE_PROMOFF
+ i
* 2);
235 sc
->sc_conf3
= LE_C3_ACON
;
237 sc
->sc_memsize
= LE_MCA_RAMSIZE
;
239 sc
->sc_copytodesc
= le_mca_copytobuf
;
240 sc
->sc_copyfromdesc
= le_mca_copyfrombuf
;
241 sc
->sc_copytobuf
= le_mca_copytobuf
;
242 sc
->sc_copyfrombuf
= le_mca_copyfrombuf
;
243 sc
->sc_zerobuf
= le_mca_zerobuf
;
245 sc
->sc_rdcsr
= le_mca_rdcsr
;
246 sc
->sc_wrcsr
= le_mca_wrcsr
;
247 sc
->sc_hwinit
= NULL
;
249 sc
->sc_hwreset
= le_mca_hwreset
;
252 * This is merely cosmetic since it's not possible to switch
253 * the media anyway, even for MC2+.
256 sc
->sc_supmedia
= &supmedia
;
257 sc
->sc_nsupmedia
= 1;
258 sc
->sc_defaultmedia
= supmedia
;
261 lesc
->sc_ih
= mca_intr_establish(ma
->ma_mc
, irq
, IPL_NET
,
262 le_mca_intredge
, sc
);
263 if (lesc
->sc_ih
== NULL
) {
264 aprint_error_dev(self
,
265 "couldn't establish interrupt handler\n");
269 aprint_normal("%s", device_xname(self
));
270 am7990_config(&lesc
->sc_am7990
);
274 * Controller interrupt.
277 le_mca_intredge(void *arg
)
281 * We could check the IRQ bit of LE_PORT, but it seems to be unset
282 * at this time anyway.
285 if (am7990_intr(arg
) == 0)
288 if (am7990_intr(arg
) == 0)
293 * Push a value to LANCE controller.
296 le_mca_wrreg(struct le_mca_softc
*sc
, int val
, int type
)
300 * This follows steps in SKNET Personal/MC2+ docs:
301 * 1. write reg. number to LANCE register
302 * 2. write value RESET | type to port
304 * 4. wait until REGREQ is cleared
306 if ((type
& REGREAD
) == 0)
307 bus_space_write_2(sc
->sc_memt
, sc
->sc_memh
, LE_LANCEREG
, val
);
308 bus_space_write_1(sc
->sc_memt
, sc
->sc_memh
, LE_PORT
,
310 bus_space_write_1(sc
->sc_memt
, sc
->sc_memh
, LE_REGIO
,
312 /* Delay here doesn't seem to be necessary */
314 while (bus_space_read_1(sc
->sc_memt
, sc
->sc_memh
, LE_PORT
) & REGREQ
)
319 le_mca_wrcsr(struct lance_softc
*sc
, uint16_t port
, uint16_t val
)
321 struct le_mca_softc
*lsc
= (struct le_mca_softc
*)sc
;
323 le_mca_set_RAP(lsc
, port
);
324 le_mca_wrreg(lsc
, val
, RDATA
| REGWRITE
);
328 le_mca_rdcsr(struct lance_softc
*sc
, uint16_t port
)
330 struct le_mca_softc
*lsc
= (struct le_mca_softc
*)sc
;
332 le_mca_set_RAP(lsc
, port
);
333 le_mca_wrreg(lsc
, 0, RDATA
| REGREAD
);
335 return (bus_space_read_2(lsc
->sc_memt
, lsc
->sc_memh
, LE_LANCEREG
));
339 le_mca_hwreset(struct lance_softc
*sc
)
341 struct le_mca_softc
*lsc
= (struct le_mca_softc
*)sc
;
343 bus_space_write_1(lsc
->sc_memt
, lsc
->sc_memh
, LE_PORT
, 0);
344 delay(5); /* Delay >= 5 microseconds */
345 bus_space_write_1(lsc
->sc_memt
, lsc
->sc_memh
, LE_PORT
, RESET
);
349 le_mca_copytobuf(struct lance_softc
*sc
, void *from
, int boff
, int len
)
351 struct le_mca_softc
*lsc
= (struct le_mca_softc
*)sc
;
353 bus_space_write_region_1(lsc
->sc_memt
, lsc
->sc_memh
, boff
,
358 le_mca_copyfrombuf(struct lance_softc
*sc
, void *to
, int boff
, int len
)
360 struct le_mca_softc
*lsc
= (struct le_mca_softc
*)sc
;
362 bus_space_read_region_1(lsc
->sc_memt
, lsc
->sc_memh
, boff
,
367 le_mca_zerobuf(struct lance_softc
*sc
, int boff
, int len
)
369 struct le_mca_softc
*lsc
= (struct le_mca_softc
*)sc
;
371 bus_space_set_region_1(lsc
->sc_memt
, lsc
->sc_memh
, boff
,