1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
/* $NetBSD: if_le_mca.c,v 1.21 2019/04/09 04:04:04 msaitoh Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jaromir Dolecek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Driver for SKNET Personal and MC2+ cards, which are AMD Lance 7990 based
* cards made by Syskonnect, former Schneider & Koch Datensysteme GmbH.
*
* Syskonnect was very helpful and provided docs for these cards promptly.
* I wish all vendors would be like that!
* I'd like to thank to Alfred Arnold, author of the Linux driver, for
* giving me contact to The Right Syskonnect person, too :-)
*
* Sources:
* SKNET MC+ Technical Manual, version 1.1, July 21 1993
* SKNET personal Technisches Manual, version 1.2, April 14 1988
* SKNET junior Technisches Manual, version 1.0, July 14 1987
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_le_mca.c,v 1.21 2019/04/09 04:04:04 msaitoh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/syslog.h>
#include <sys/socket.h>
#include <sys/device.h>
#include <net/if.h>
#include <net/if_ether.h>
#include <net/if_media.h>
#include <sys/cpu.h>
#include <sys/intr.h>
#include <sys/bus.h>
#include <dev/ic/lancereg.h>
#include <dev/ic/lancevar.h>
#include <dev/ic/am7990reg.h>
#include <dev/ic/am7990var.h>
#include <dev/mca/mcareg.h>
#include <dev/mca/mcavar.h>
#include <dev/mca/mcadevs.h>
#include <dev/mca/if_lereg.h>
struct le_mca_softc {
struct am7990_softc sc_am7990; /* glue to MI code */
void *sc_ih;
bus_space_tag_t sc_memt;
bus_space_handle_t sc_memh;
};
static int le_mca_match(device_t, cfdata_t, void *);
static void le_mca_attach(device_t, device_t, void *);
static void le_mca_wrcsr(struct lance_softc *, uint16_t, uint16_t);
static uint16_t le_mca_rdcsr(struct lance_softc *, uint16_t);
static void le_mca_hwreset(struct lance_softc *);
static int le_mca_intredge(void *);
static void le_mca_copytobuf(struct lance_softc *, void *, int, int);
static void le_mca_copyfrombuf(struct lance_softc *, void *, int, int);
static void le_mca_zerobuf(struct lance_softc *, int, int);
static inline void le_mca_wrreg(struct le_mca_softc *, int, int);
#define le_mca_set_RAP(sc, reg_number) \
le_mca_wrreg(sc, reg_number, RAP | REGWRITE)
CFATTACH_DECL_NEW(le_mca, sizeof(struct le_mca_softc),
le_mca_match, le_mca_attach, NULL, NULL);
/* SKNET MC+ POS mapping */
static const uint8_t sknet_mcp_irq[] = {
3, 5, 10, 11
};
static const int sknet_mcp_media[] = {
IFM_ETHER | IFM_10_2,
IFM_ETHER | IFM_10_T,
IFM_ETHER | IFM_10_5,
0
};
int
le_mca_match(device_t parent, cfdata_t cf, void *aux)
{
struct mca_attach_args *ma = aux;
switch(ma->ma_id) {
case MCA_PRODUCT_SKNETPER:
case MCA_PRODUCT_SKNETG:
return 1;
}
return 0;
}
void
le_mca_attach(device_t parent, device_t self, void *aux)
{
struct le_mca_softc *lesc = device_private(self);
struct lance_softc *sc = &lesc->sc_am7990.lsc;
struct mca_attach_args *ma = aux;
int i, pos2, pos3, pos4, irq, membase;
const int *supmedia = NULL;
const char *typestr;
sc->sc_dev = self;
/*
* SKNET Personal:
*
* POS register 2: (adf pos0)
*
* 7 6 5 4 3 2 1 0
* | \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
* \ \____ Memory: 0xC0000-0xC3FFF + XX*0x4000
* \________ IRQ: 0=10 1=11
*
*
* SKNET MC+:
* POS register 2: (adf pos0)
*
* 7 6 5 4 3 2 1 0
* \___/ \ \__ enable: 0=adapter disabled, 1=adapter enabled
* \ \___ BootEPROM disable
* \_____ BootEPROM start address: 0xC0000 + XX*0x4000
*
* POS register 3: (adf pos1)
*
* 7 6 5 4 3 2 1 0
* 0 0 1 1 \_____/
* \__ RAM: 0xC0000 + XX*0x4000
*
* POS register 4: (adf pos2)
*
* 7 6 5 4 3 2 1 0
* \_/ \_/ \_/
* \ \ \__ Need to be reset to 0 0 after boot
* \ \_____ IRQ: 00=3 01=5 10=10 11=11
* \____________ Medium: 00=BNC 01=UTP 10=AUI 11=not allowed
*/
switch (ma->ma_id) {
case MCA_PRODUCT_SKNETPER:
typestr = "Personal MC2";
pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
irq = (pos2 & (1<<4)) ? 11 : 10;
membase = 0xc0000 + ((pos2 & 0x0e) >> 1) * 0x4000;
break;
case MCA_PRODUCT_SKNETG:
typestr = "MC2+";
/*
* SKNET MC+ needs the driver to clear 0, 1 bits of pos4
* and explicitly set the enable bit. Somebody at Syskonnect
* was obviously misguided when the card was designed ...
*/
pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
if ((pos4 & 0x03) != 0) {
/* clear the bits 0, 1 */
mca_conf_write(ma->ma_mc, ma->ma_slot, 4,
pos4 & ~0x03);
}
pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
if ((pos2 & 0x01) == 0) {
/* enable the card */
mca_conf_write(ma->ma_mc, ma->ma_slot, 2, pos2 | 0x01);
}
/* get irq and memory base */
irq = sknet_mcp_irq[(pos4 & 0x0c) >> 2];
membase = 0xc0000 + ((pos3 & 0x0f) * 0x4000);
/* Get configured media type */
supmedia = &sknet_mcp_media[(pos4 & 0xc0) >> 6];
break;
default:
aprint_error(": unknown product %d\n", ma->ma_id);
return;
}
lesc->sc_memt = ma->ma_memt;
if (bus_space_map(lesc->sc_memt, membase, LE_MCA_MEMSIZE,
0, &lesc->sc_memh)) {
aprint_error(": can't map memory\n");
return;
}
aprint_normal(" slot %d irq %d: SKNET %s Ethernet\n",
ma->ma_slot + 1, irq, typestr);
/*
* Extract the physical MAC address from the ROM.
*/
for (i = 0; i < ETHER_ADDR_LEN; i++)
sc->sc_enaddr[i] = bus_space_read_1(lesc->sc_memt,
lesc->sc_memh, LE_PROMOFF + i * 2);
sc->sc_conf3 = LE_C3_ACON;
sc->sc_addr = 0;
sc->sc_memsize = LE_MCA_RAMSIZE;
sc->sc_copytodesc = le_mca_copytobuf;
sc->sc_copyfromdesc = le_mca_copyfrombuf;
sc->sc_copytobuf = le_mca_copytobuf;
sc->sc_copyfrombuf = le_mca_copyfrombuf;
sc->sc_zerobuf = le_mca_zerobuf;
sc->sc_rdcsr = le_mca_rdcsr;
sc->sc_wrcsr = le_mca_wrcsr;
sc->sc_hwinit = NULL;
sc->sc_hwreset = le_mca_hwreset;
/*
* This is merely cosmetic since it's not possible to switch
* the media anyway, even for MC2+.
*/
if (supmedia != NULL) {
sc->sc_supmedia = supmedia;
sc->sc_nsupmedia = 1;
sc->sc_defaultmedia = *supmedia;
}
lesc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
le_mca_intredge, sc);
if (lesc->sc_ih == NULL) {
aprint_error_dev(self,
"couldn't establish interrupt handler\n");
return;
}
aprint_normal("%s", device_xname(self));
am7990_config(&lesc->sc_am7990);
}
/*
* Controller interrupt.
*/
int
le_mca_intredge(void *arg)
{
/*
* We could check the IRQ bit of LE_PORT, but it seems to be unset
* at this time anyway.
*/
if (am7990_intr(arg) == 0)
return 0;
for(;;)
if (am7990_intr(arg) == 0)
return 1;
}
/*
* Push a value to LANCE controller.
*/
static inline void
le_mca_wrreg(struct le_mca_softc *sc, int val, int type)
{
/*
* This follows steps in SKNET Personal/MC2+ docs:
* 1. write reg. number to LANCE register
* 2. write value RESET | type to port
* 3. flag REGDO
* 4. wait until REGREQ is cleared
*/
if ((type & REGREAD) == 0)
bus_space_write_2(sc->sc_memt, sc->sc_memh, LE_LANCEREG, val);
bus_space_write_1(sc->sc_memt, sc->sc_memh, LE_PORT,
RESET | type);
bus_space_write_1(sc->sc_memt, sc->sc_memh, LE_REGIO,
REGDO);
/* Delay here doesn't seem to be necessary */
/* delay(1); */
while (bus_space_read_1(sc->sc_memt, sc->sc_memh, LE_PORT) & REGREQ)
;
}
static void
le_mca_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
{
struct le_mca_softc *lsc = (struct le_mca_softc *)sc;
le_mca_set_RAP(lsc, port);
le_mca_wrreg(lsc, val, RDATA | REGWRITE);
}
static uint16_t
le_mca_rdcsr(struct lance_softc *sc, uint16_t port)
{
struct le_mca_softc *lsc = (struct le_mca_softc *)sc;
le_mca_set_RAP(lsc, port);
le_mca_wrreg(lsc, 0, RDATA | REGREAD);
return (bus_space_read_2(lsc->sc_memt, lsc->sc_memh, LE_LANCEREG));
}
static void
le_mca_hwreset(struct lance_softc *sc)
{
struct le_mca_softc *lsc = (struct le_mca_softc *)sc;
bus_space_write_1(lsc->sc_memt, lsc->sc_memh, LE_PORT, 0);
delay(5); /* Delay >= 5 microseconds */
bus_space_write_1(lsc->sc_memt, lsc->sc_memh, LE_PORT, RESET);
}
static void
le_mca_copytobuf(struct lance_softc *sc, void *from, int boff, int len)
{
struct le_mca_softc *lsc = (struct le_mca_softc *)sc;
bus_space_write_region_1(lsc->sc_memt, lsc->sc_memh, boff, from, len);
}
static void
le_mca_copyfrombuf(struct lance_softc *sc, void *to, int boff, int len)
{
struct le_mca_softc *lsc = (struct le_mca_softc *)sc;
bus_space_read_region_1(lsc->sc_memt, lsc->sc_memh, boff, to, len);
}
static void
le_mca_zerobuf(struct lance_softc *sc, int boff, int len)
{
struct le_mca_softc *lsc = (struct le_mca_softc *)sc;
bus_space_set_region_1(lsc->sc_memt, lsc->sc_memh, boff, 0x00, len);
}
|