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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
/* $OpenBSD: be.c,v 1.3 1998/07/05 06:50:20 deraadt Exp $ */
/*
* Copyright (c) 1998 Theo de Raadt. All rights reserved.
*
* 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.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/syslog.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/netisr.h>
#ifdef INET
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
#endif
#include "bpfilter.h"
#if NBPFILTER > 0
#include <net/bpf.h>
#include <net/bpfdesc.h>
#endif
#include <machine/autoconf.h>
#include <machine/cpu.h>
#include <sparc/dev/sbusvar.h>
#include <sparc/dev/dmareg.h>
#include <sparc/dev/dmavar.h>
#include <sparc/dev/qecvar.h>
#include <sparc/dev/qecreg.h>
#include <sparc/dev/bereg.h>
#include <sparc/dev/bevar.h>
int bematch __P((struct device *, void *, void *));
void beattach __P((struct device *, struct device *, void *));
void beinit __P((struct besoftc *));
void bestart __P((struct ifnet *));
void bestop __P((struct besoftc *));
void bewatchdog __P((struct ifnet *));
int beioctl __P((struct ifnet *, u_long, caddr_t));
int beintr __P((void *));
int betint __P((struct besoftc *));
int berint __P((struct besoftc *));
int beqint __P((struct besoftc *));
int beeint __P((struct besoftc *));
struct cfdriver be_cd = {
NULL, "be", DV_IFNET
};
struct cfattach be_ca = {
sizeof(struct besoftc), bematch, beattach
};
int
bematch(parent, vcf, aux)
struct device *parent;
void *vcf, *aux;
{
struct cfdata *cf = vcf;
struct confargs *ca = aux;
register struct romaux *ra = &ca->ca_ra;
if (strcmp(cf->cf_driver->cd_name, ra->ra_name))
return (0);
return (1);
}
void
beattach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct qec_softc *qec = (struct qec_softc *)parent;
struct besoftc *sc = (struct besoftc *)self;
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
struct confargs *ca = aux;
int pri;
/* XXX the following declarations should be elsewhere */
extern void myetheraddr __P((u_char *));
if (ca->ca_ra.ra_nintr != 1) {
printf(": expected 1 interrupt, got %d\n", ca->ca_ra.ra_nintr);
return;
}
pri = ca->ca_ra.ra_intr[0].int_pri;
printf(" pri %d", pri);
sc->sc_rev = getpropint(ca->ca_ra.ra_node, "board-version", -1);
printf(": rev %x", sc->sc_rev);
sc->sc_cr = mapiodev(ca->ca_ra.ra_reg, 0, sizeof(struct be_cregs));
sc->sc_br = mapiodev(&ca->ca_ra.ra_reg[1], 0, sizeof(struct be_bregs));
sc->sc_tr = mapiodev(&ca->ca_ra.ra_reg[2], 0, sizeof(struct be_tregs));
sc->sc_qr = qec->sc_regs;
bestop(sc);
sc->sc_mem = qec->sc_buffer;
sc->sc_memsize = qec->sc_bufsiz;
sc->sc_conf3 = getpropint(ca->ca_ra.ra_node, "busmaster-regval", 0);
sc->sc_ih.ih_fun = beintr;
sc->sc_ih.ih_arg = sc;
intr_establish(pri, &sc->sc_ih);
myetheraddr(sc->sc_arpcom.ac_enaddr);
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
ifp->if_softc = sc;
ifp->if_start = bestart;
ifp->if_ioctl = beioctl;
ifp->if_watchdog = bewatchdog;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS |
IFF_MULTICAST;
/* Attach the interface. */
if_attach(ifp);
ether_ifattach(ifp);
printf("\n");
}
/*
* Start output on interface.
* We make two assumptions here:
* 1) that the current priority is set to splnet _before_ this code
* is called *and* is returned to the appropriate priority after
* return
* 2) that the IFF_OACTIVE flag is checked before this code is called
* (i.e. that the output part of the interface is idle)
*/
void
bestart(ifp)
struct ifnet *ifp;
{
printf("start\n");
#if 0
struct besoftc *sc = ifp->if_softc;
struct mbuf *m;
int bix;
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
return;
bix = sc->sc_last_td;
for (;;) {
/* XXX TODO: Some magic */
IF_DEQUEUE(&ifp->if_snd, m);
if (m == 0)
break;
#if NBPFILTER > 0
/*
* If BPF is listening on this interface, let it see the
* packet before we commit it to the wire.
*/
if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, m);
#endif
/* XXX TODO
* Copy the mbuf chain into the transmit buffer.
*/
/* XXX TODO
* Initialize transmit registers and start transmission
*/
if (++bix == TX_RING_SIZE)
bix = 0;
if (++sc->sc_no_td == TX_RING_SIZE) {
ifp->if_flags |= IFF_OACTIVE;
break;
}
}
sc->sc_last_td = bix;
#endif
}
void
bestop(sc)
struct besoftc *sc;
{
int tries;
tries = 32;
sc->sc_br->tx_cfg = 0;
while (sc->sc_br->tx_cfg != 0 && --tries)
DELAY(20);
tries = 32;
sc->sc_br->rx_cfg = 0;
while (sc->sc_br->rx_cfg != 0 && --tries)
DELAY(20);
}
void
bewatchdog(ifp)
struct ifnet *ifp;
{
printf("watchdog\n");
#if 0
struct besoftc *sc = ifp->if_softc;
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
++sc->sc_arpcom.ac_if.if_oerrors;
bereset(sc);
#endif
}
int
beintr(v)
void *v;
{
int r = 0;
struct besoftc *sc = (struct besoftc *)v;
u_int32_t why;
#if 1
why = sc->sc_qr->stat;
if (why & QEC_STAT_TX)
r |= betint(sc);
if (why & QEC_STAT_RX)
r |= berint(sc);
if (why & QEC_STAT_BM)
r |= beqint(sc);
if (why & QEC_STAT_ER)
r |= beeint(sc);
if (r)
printf("%s: intr: why=%08x\n", sc->sc_dev.dv_xname, why);
#endif
return (r);
}
int
betint(sc)
struct besoftc *sc;
{
return (0);
}
int
berint(sc)
struct besoftc *sc;
{
return (0);
}
int
beqint(sc)
struct besoftc *sc;
{
return (0);
}
int
beeint(sc)
struct besoftc *sc;
{
return (0);
}
int
beioctl(ifp, cmd, data)
struct ifnet *ifp;
u_long cmd;
caddr_t data;
{
struct besoftc *sc = ifp->if_softc;
struct ifaddr *ifa = (struct ifaddr *)data;
struct ifreq *ifr = (struct ifreq *)data;
int s, error = 0;
s = splnet();
if ((error = ether_ioctl(ifp, &sc->sc_arpcom, cmd, data)) > 0) {
splx(s);
return error;
}
switch (cmd) {
case SIOCSIFADDR:
ifp->if_flags |= IFF_UP;
switch (ifa->ifa_addr->sa_family) {
#ifdef INET
case AF_INET:
beinit(sc);
arp_ifinit(&sc->sc_arpcom, ifa);
break;
#endif /* INET */
#ifdef NS
/* XXX - This code is probably wrong. */
case AF_NS:
{
struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
if (ns_nullhost(*ina))
ina->x_host = *(union ns_host *)
(sc->sc_arpcom.ac_enaddr);
else
bcopy(ina->x_host.c_host,
sc->sc_arpcom.ac_enaddr,
sizeof(sc->sc_arpcom.ac_enaddr));
/* Set new address. */
beinit(sc);
break;
}
#endif /* NS */
default:
beinit(sc);
break;
}
break;
case SIOCSIFFLAGS:
sc->sc_promisc = ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI);
if ((ifp->if_flags & IFF_UP) == 0 &&
(ifp->if_flags & IFF_RUNNING) != 0) {
/*
* If interface is marked down and it is running, then
* stop it.
*/
bestop(sc);
ifp->if_flags &= ~IFF_RUNNING;
} else if ((ifp->if_flags & IFF_UP) != 0 &&
(ifp->if_flags & IFF_RUNNING) == 0) {
/*
* If interface is marked up and it is stopped, then
* start it.
*/
beinit(sc);
} else {
/*
* Reset the interface to pick up changes in any other
* flags that affect hardware registers.
*/
bestop(sc);
beinit(sc);
}
#ifdef IEDEBUG
if (ifp->if_flags & IFF_DEBUG)
sc->sc_debug = IED_ALL;
else
sc->sc_debug = 0;
#endif
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_arpcom):
ether_delmulti(ifr, &sc->sc_arpcom);
if (error == ENETRESET) {
/*
* Multicast list has changed; set the hardware filter
* accordingly.
*/
#if 0
mc_reset(sc);
#endif
error = 0;
}
break;
default:
error = EINVAL;
}
splx(s);
return error;
}
void
beinit(sc)
struct besoftc *sc;
{
bestop(sc);
#if 0
sc->sc_qr->msize = sc->sc_memsize;
sc->sc_qr->rsize = sc->sc_memsize / 2;
sc->sc_qr->tsize = sc->sc_memsize / 2;
sc->sc_qr->psize = 2048;
/*sc->sc_qr->ctrl = QEC_CTRL_BMODE | QEC_CTRL_B32;*/
be_meminit(sc);
be_write32(&treg->int_mask, 0xffff);
c = be_read32(&treg->cfg);
if (sc->sc_flags & HFLAG_FENABLE)
be_write32(&treg->cfg, c & ~(TCV_CFG_BENABLE));
else
be_write32(&treg->cfg, c | TCV_CFG_BENABLE);
be_tcvr_check(sc);
switch (sc->tcvr_type) {
case none:
printf("%s: no transceiver type!\n", sc->sc_dev.dv_xname);
return;
case internal:
be_write32(&breg->xif_cfg, 0);
break;
case external:
be_write32(&breg->xif_cfg, BIGMAC_XCFG_MIIDISAB);
break;
}
be_tcvr_reset(sc);
be_reset_tx(sc);
be_reset_rx(sc);
be_write32(&breg->jsize, BE_DEFAULT_JSIZE);
be_write32(&breg->ipkt_gap1, BE_DEFAULT_IPKT_GAP1);
be_write32(&breg->ipkt_gap2, BE_DEFAULT_IPKT_GAP2);
be_write32(&breg->htable3, 0);
be_write32(&breg->htable2, 0);
be_write32(&breg->htable1, 0);
be_write32(&breg->htable0, 0);
be_write32(&erxreg->rx_ring,
sc->sc_block_addr +
((u_long) &sc->sc_block->be_rxd[0]) - ((u_long)sc->sc_block));
be_write32(&etxreg->tx_ring,
sc->sc_block_addr +
((u_long) &sc->sc_block->be_txd[0]) - ((u_long)sc->sc_block));
if (sc->sc_burst & SBUS_BURST_64)
be_write32(&greg->cfg, GREG_CFG_BURST64);
else if (sc->sc_burst & SBUS_BURST_32)
be_write32(&greg->cfg, GREG_CFG_BURST32);
else if (sc->sc_burst & SBUS_BURST_16)
be_write32(&greg->cfg, GREG_CFG_BURST16);
else {
printf("%s: burst size unknown\n", sc->sc_dev.dv_xname);
be_write32(&greg->cfg, 0);
}
/* XXX TODO: set interrupt mask: (GOTFRAME | RCNTEXP) */
be_write32(&greg->imask, GREG_IMASK_SENTFRAME | GREG_IMASK_TXPERR);
be_write32(&etxreg->tx_rsize, (TX_RING_SIZE >> ETX_RSIZE_SHIFT) - 1);
be_write32(&etxreg->cfg, be_read32(&etxreg->cfg) | ETX_CFG_DMAENABLE);
be_write32(&breg->rx_cfg, BIGMAC_RXCFG_HENABLE);
be_auto_negotiate(sc);
#endif
}
|