This source file includes following definitions.
- load_csrs
- lance_init_ring
- init_restart_lance
- lance_rx
- lance_tx
- lance_interrupt
- lance_open
- lance_close
- lance_reset
- lance_start_xmit
- lance_get_stats
- lance_set_multicast
- sparc_lance_init
- find_ledma
- sparc_lance_probe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #undef DEBUG_DRIVER
21 static char *version =
22 "sunlance.c:v1.6 19/Apr/96 Miguel de Icaza (miguel@nuclecu.unam.mx)\n";
23
24 static char *lancestr = "LANCE";
25 static char *lancedma = "LANCE DMA";
26
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/types.h>
30 #include <linux/fcntl.h>
31 #include <linux/interrupt.h>
32 #include <linux/ptrace.h>
33 #include <linux/ioport.h>
34 #include <linux/in.h>
35 #include <linux/malloc.h>
36 #include <linux/string.h>
37 #include <asm/system.h>
38 #include <asm/bitops.h>
39 #include <asm/io.h>
40 #include <asm/dma.h>
41 #include <linux/errno.h>
42 #include <asm/byteorder.h>
43
44
45 #include <linux/socket.h>
46 #include <linux/route.h>
47
48 #include <asm/idprom.h>
49 #include <asm/sbus.h>
50 #include <asm/openprom.h>
51 #include <asm/oplib.h>
52
53 #include <linux/netdevice.h>
54 #include <linux/etherdevice.h>
55 #include <linux/skbuff.h>
56
57
58 #ifndef LANCE_LOG_TX_BUFFERS
59 #define LANCE_LOG_TX_BUFFERS 4
60 #define LANCE_LOG_RX_BUFFERS 4
61 #endif
62
63 #define LE_CSR0 0
64 #define LE_CSR1 1
65 #define LE_CSR2 2
66 #define LE_CSR3 3
67
68 #define LE_MO_PROM 0x8000
69
70 #define LE_C0_ERR 0x8000
71 #define LE_C0_BABL 0x4000
72 #define LE_C0_CERR 0x2000
73 #define LE_C0_MISS 0x1000
74 #define LE_C0_MERR 0x0800
75 #define LE_C0_RINT 0x0400
76 #define LE_C0_TINT 0x0200
77 #define LE_C0_IDON 0x0100
78 #define LE_C0_INTR 0x0080
79 #define LE_C0_INEA 0x0040
80 #define LE_C0_RXON 0x0020
81 #define LE_C0_TXON 0x0010
82 #define LE_C0_TDMD 0x0008
83 #define LE_C0_STOP 0x0004
84 #define LE_C0_STRT 0x0002
85 #define LE_C0_INIT 0x0001
86
87 #define LE_C3_BSWP 0x4
88 #define LE_C3_ACON 0x2
89 #define LE_C3_BCON 0x1
90
91
92 #define LE_R1_OWN 0x80
93 #define LE_R1_ERR 0x40
94 #define LE_R1_FRA 0x20
95 #define LE_R1_OFL 0x10
96 #define LE_R1_CRC 0x08
97 #define LE_R1_BUF 0x04
98 #define LE_R1_SOP 0x02
99 #define LE_R1_EOP 0x01
100 #define LE_R1_POK 0x03
101
102 #define LE_T1_OWN 0x80
103 #define LE_T1_ERR 0x40
104 #define LE_T1_EMORE 0x10
105 #define LE_T1_EONE 0x08
106 #define LE_T1_EDEF 0x04
107 #define LE_T1_SOP 0x02
108 #define LE_T1_EOP 0x01
109 #define LE_T1_POK 0x03
110
111 #define LE_T3_BUF 0x8000
112 #define LE_T3_UFL 0x4000
113 #define LE_T3_LCOL 0x1000
114 #define LE_T3_CLOS 0x0800
115 #define LE_T3_RTY 0x0400
116 #define LE_T3_TDR 0x03ff
117
118 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
119 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
120 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29)
121
122 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
123 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
124 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
125
126 #define PKT_BUF_SZ 1544
127 #define RX_BUFF_SIZE PKT_BUF_SZ
128 #define TX_BUFF_SIZE PKT_BUF_SZ
129
130 struct lance_rx_desc {
131 unsigned short rmd0;
132 unsigned char rmd1_bits;
133 unsigned char rmd1_hadr;
134 short length;
135
136
137 unsigned short mblength;
138 };
139
140 struct lance_tx_desc {
141 unsigned short tmd0;
142 unsigned char tmd1_bits;
143 unsigned char tmd1_hadr;
144 short length;
145 unsigned short misc;
146 };
147
148
149
150 struct lance_init_block {
151 unsigned short mode;
152 unsigned char phys_addr[6];
153 unsigned filter[2];
154
155
156 unsigned short rx_ptr;
157 unsigned short rx_len;
158 unsigned short tx_ptr;
159 unsigned short tx_len;
160
161
162 struct lance_rx_desc brx_ring[RX_RING_SIZE];
163 struct lance_tx_desc btx_ring[TX_RING_SIZE];
164
165 char rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
166 char tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
167 };
168
169 struct lance_private {
170 char *name;
171 volatile struct lance_regs *ll;
172 volatile struct lance_init_block *init_block;
173
174 int rx_new, tx_new;
175 int rx_old, tx_old;
176
177 struct enet_statistics stats;
178 struct Linux_SBus_DMA *ledma;
179
180 int tpe;
181 int burst_sizes;
182 };
183
184 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
185 lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
186 lp->tx_old - lp->tx_new-1)
187
188
189 struct lance_regs {
190 unsigned short rdp;
191 unsigned short rap;
192 };
193
194 int sparc_lance_debug = 2;
195
196
197
198
199 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
200
201
202 static void load_csrs (struct lance_private *lp)
203 {
204 volatile struct lance_regs *ll = lp->ll;
205 volatile struct lance_init_block *ib = lp->init_block;
206 int leptr;
207
208 leptr = LANCE_ADDR (ib);
209 ll->rap = LE_CSR1;
210 ll->rdp = (leptr & 0xFFFF);
211 ll->rap = LE_CSR2;
212 ll->rdp = leptr >> 16;
213 ll->rap = LE_CSR3;
214 ll->rdp = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
215
216
217 ll->rap = LE_CSR0;
218 }
219
220 #define ZERO 0
221
222
223
224 static void lance_init_ring (struct device *dev)
225 {
226 struct lance_private *lp = (struct lance_private *) dev->priv;
227 volatile struct lance_init_block *ib = lp->init_block;
228 int leptr;
229 int i;
230
231
232 dev->tbusy = 1;
233 lp->rx_new = lp->tx_new = 0;
234 lp->rx_old = lp->tx_old = 0;
235
236 ib->mode = 0;
237
238
239
240
241 ib->phys_addr [0] = dev->dev_addr [1];
242 ib->phys_addr [1] = dev->dev_addr [0];
243 ib->phys_addr [2] = dev->dev_addr [3];
244 ib->phys_addr [3] = dev->dev_addr [2];
245 ib->phys_addr [4] = dev->dev_addr [5];
246 ib->phys_addr [5] = dev->dev_addr [4];
247
248 if (ZERO)
249 printk ("TX rings:\n");
250
251
252 for (i = 0; i <= TX_RING_SIZE; i++) {
253 leptr = LANCE_ADDR(&ib->tx_buf[i][0]);
254 ib->btx_ring [i].tmd0 = leptr;
255 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
256 ib->btx_ring [i].tmd1_bits = 0;
257 ib->btx_ring [i].length = 0xf000;
258 ib->btx_ring [i].misc = 0;
259 if (i < 3)
260 if (ZERO) printk ("%d: 0x%8.8x\n", i, leptr);
261 }
262
263
264 if (ZERO)
265 printk ("RX rings:\n");
266 for (i = 0; i < RX_RING_SIZE; i++) {
267 leptr = LANCE_ADDR(&ib->rx_buf[i][0]);
268
269 ib->brx_ring [i].rmd0 = leptr;
270 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
271 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
272 ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
273 ib->brx_ring [i].mblength = 0;
274 if (i < 3 && ZERO)
275 printk ("%d: 0x%8.8x\n", i, leptr);
276 }
277
278
279
280
281 leptr = LANCE_ADDR(&ib->brx_ring);
282 ib->rx_len = (LANCE_LOG_RX_BUFFERS << 13) | (leptr >> 16);
283 ib->rx_ptr = leptr;
284 if (ZERO)
285 printk ("RX ptr: %8.8x\n", leptr);
286
287
288 leptr = LANCE_ADDR(&ib->btx_ring);
289 ib->tx_len = (LANCE_LOG_TX_BUFFERS << 13) | (leptr >> 16);
290 ib->tx_ptr = leptr;
291 if (ZERO)
292 printk ("TX ptr: %8.8x\n", leptr);
293
294
295 ib->filter [0] = 0;
296 ib->filter [1] = 0;
297 }
298
299 static int init_restart_lance (struct lance_private *lp)
300 {
301 volatile struct lance_regs *ll = lp->ll;
302 int i;
303
304 if (lp->ledma) {
305 struct sparc_dma_registers *dregs = lp->ledma->regs;
306 unsigned long creg;
307
308 while (dregs->cond_reg & DMA_FIFO_ISDRAIN)
309 barrier();
310
311 creg = dregs->cond_reg;
312 if (lp->burst_sizes & DMA_BURST32)
313 creg |= DMA_E_BURST8;
314 else
315 creg &= ~DMA_E_BURST8;
316
317 creg |= (DMA_DSBL_RD_DRN | DMA_DSBL_WR_INV | DMA_FIFO_INV);
318
319 if (lp->tpe)
320 creg |= DMA_EN_ENETAUI;
321 else
322 creg &= ~DMA_EN_ENETAUI;
323 udelay(20);
324 dregs->cond_reg = creg;
325 udelay(200);
326 }
327
328 ll->rap = LE_CSR0;
329 ll->rdp = LE_C0_INIT;
330
331
332 for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
333 barrier();
334 if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
335 printk ("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, ll->rdp);
336 if (lp->ledma)
337 printk ("dcsr=%8.8x\n",
338 (unsigned int) lp->ledma->regs->cond_reg);
339 return -1;
340 }
341
342
343 ll->rdp = LE_C0_IDON;
344 ll->rdp = LE_C0_INEA | LE_C0_STRT;
345
346 if (lp->ledma)
347 lp->ledma->regs->cond_reg |= DMA_INT_ENAB;
348
349 return 0;
350 }
351
352 static int lance_rx (struct device *dev)
353 {
354 struct lance_private *lp = (struct lance_private *) dev->priv;
355 volatile struct lance_init_block *ib = lp->init_block;
356 volatile struct lance_regs *ll = lp->ll;
357 volatile struct lance_rx_desc *rd;
358 unsigned char bits;
359
360 #ifdef TEST_HITS
361 printk ("[");
362 for (i = 0; i < RX_RING_SIZE; i++) {
363 if (i == lp->rx_new)
364 printk ("%s",
365 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
366 else
367 printk ("%s",
368 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
369 }
370 printk ("]");
371 #endif
372
373 ll->rdp = LE_C0_RINT|LE_C0_INEA;
374 for (rd = &ib->brx_ring [lp->rx_new];
375 !((bits = rd->rmd1_bits) & LE_R1_OWN);
376 rd = &ib->brx_ring [lp->rx_new]) {
377 int pkt_len;
378 struct sk_buff *skb;
379
380
381 if ((bits & LE_R1_POK) != LE_R1_POK) {
382 lp->stats.rx_over_errors++;
383 lp->stats.rx_errors++;
384 continue;
385 } else if (bits & LE_R1_ERR) {
386
387 if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
388 if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
389 if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
390 if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
391 if (bits & LE_R1_EOP) lp->stats.rx_errors++;
392 } else {
393 pkt_len = rd->mblength;
394 skb = dev_alloc_skb (pkt_len+2);
395 if (skb == NULL) {
396 printk ("%s: Memory squeeze, deferring packet.\n",
397 dev->name);
398 lp->stats.rx_dropped++;
399 rd->mblength = 0;
400 rd->rmd1_bits = LE_R1_OWN;
401 lp->rx_new = (lp->rx_new + 1) & RX_RING_MOD_MASK;
402 return 0;
403 }
404
405 skb->dev = dev;
406 skb_reserve (skb, 2);
407 skb_put (skb, pkt_len);
408 eth_copy_and_sum(skb,
409 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
410 pkt_len, 0);
411 skb->protocol = eth_type_trans (skb,dev);
412 netif_rx (skb);
413 lp->stats.rx_packets++;
414 }
415
416
417 rd->mblength = 0;
418 rd->rmd1_bits = LE_R1_OWN;
419 lp->rx_new = (lp->rx_new + 1) & RX_RING_MOD_MASK;
420 }
421 return 0;
422 }
423
424 static int lance_tx (struct device *dev)
425 {
426 struct lance_private *lp = (struct lance_private *) dev->priv;
427 volatile struct lance_init_block *ib = lp->init_block;
428 volatile struct lance_regs *ll = lp->ll;
429 volatile struct lance_tx_desc *td;
430 int i, j;
431 int status;
432
433
434 ll->rdp = LE_C0_TINT | LE_C0_INEA;
435
436 j = lp->tx_old;
437 for (i = 0; i < TX_RING_SIZE; i++) {
438 td = &ib->btx_ring [j];
439
440 if (td->tmd1_bits & LE_T1_ERR) {
441 status = td->misc;
442
443 lp->stats.tx_errors++;
444 if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
445 if (status & LE_T3_CLOS) lp->stats.tx_carrier_errors++;
446 if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
447
448
449
450 if (status & (LE_T3_BUF|LE_T3_UFL)) {
451 lp->stats.tx_fifo_errors++;
452
453 printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
454 dev->name);
455
456 ll->rap = LE_CSR0;
457 ll->rdp = LE_C0_STOP;
458 lance_init_ring (dev);
459 load_csrs (lp);
460 init_restart_lance (lp);
461 return 0;
462 }
463 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
464
465
466
467 td->tmd1_bits &= ~(LE_T1_POK);
468
469
470 if (td->tmd1_bits & LE_T1_EONE)
471 lp->stats.collisions++;
472
473
474 if (td->tmd1_bits & LE_T1_EMORE)
475 lp->stats.collisions += 2;
476
477
478 if (td->tmd1_bits & LE_T1_EDEF)
479 ;
480
481 lp->stats.tx_packets++;
482 }
483
484 j = (j + 1) & TX_RING_MOD_MASK;
485 }
486 lp->tx_old = (lp->tx_old+1) & TX_RING_MOD_MASK;
487
488 ll->rdp = LE_C0_TINT | LE_C0_INEA;
489 return 0;
490 }
491
492 static void lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
493 {
494 struct device *dev;
495 struct lance_private *lp;
496 volatile struct lance_regs *ll;
497 int csr0;
498
499 #ifdef OLD_STYLE_IRQ
500 dev = (struct device *) (irq2dev_map [irq]);
501 #else
502 dev = (struct device *) dev_id;
503 #endif
504
505 lp = (struct lance_private *) dev->priv;
506 ll = lp->ll;
507
508 if (lp->ledma) {
509 if (lp->ledma->regs->cond_reg & DMA_HNDL_ERROR) {
510 printk ("%s: should reset my ledma (dmacsr=%8.8x, csr=%4.4x\n",
511 dev->name, (unsigned int) lp->ledma->regs->cond_reg,
512 ll->rdp);
513 printk ("send mail to miguel@nuclecu.unam.mx\n");
514 }
515 }
516 if (dev->interrupt)
517 printk ("%s: again", dev->name);
518
519 dev->interrupt = 1;
520
521 csr0 = ll->rdp;
522
523
524 ll->rdp = csr0 & 0x004f;
525
526 if ((csr0 & LE_C0_ERR)) {
527
528 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
529 }
530
531 if (csr0 & LE_C0_RINT)
532 lance_rx (dev);
533
534 if (csr0 & LE_C0_TINT)
535 lance_tx (dev);
536
537 if ((TX_BUFFS_AVAIL >= 0) && dev->tbusy) {
538 dev->tbusy = 0;
539 mark_bh (NET_BH);
540 }
541 ll->rap = LE_CSR0;
542 ll->rdp = 0x7940;
543
544 dev->interrupt = 0;
545 }
546
547 struct device *last_dev = 0;
548
549 static int lance_open (struct device *dev)
550 {
551 struct lance_private *lp = (struct lance_private *)dev->priv;
552 volatile struct lance_regs *ll = lp->ll;
553 int status = 0;
554
555 last_dev = dev;
556
557 if (request_irq (dev->irq, &lance_interrupt, 0, lancestr, (void *) dev)) {
558 printk ("Lance: Can't get irq %d\n", dev->irq);
559 return -EAGAIN;
560 }
561
562
563 ll->rap = LE_CSR0;
564 ll->rdp = LE_C0_STOP;
565
566 #ifdef OLD_STYLE_IRQ
567 irq2dev_map [dev->irq] = dev;
568 #endif
569
570
571 if (lp->ledma)
572 lp->ledma->regs->dma_test = ((unsigned int) lp->init_block) & 0xff000000;
573
574 lance_init_ring (dev);
575 load_csrs (lp);
576
577 dev->tbusy = 0;
578 dev->interrupt = 0;
579 dev->start = 1;
580
581 status = init_restart_lance (lp);
582 #if 0
583
584 rt_add (RTF_UP,
585 dev->pa_addr & ip_get_mask (dev->pa_addr),
586 ip_get_mask (dev->pa_addr),
587 0, dev, dev->mtu, 0, 0);
588 #endif
589 return status;
590 }
591
592 static int lance_close (struct device *dev)
593 {
594 struct lance_private *lp = (struct lance_private *) dev->priv;
595 volatile struct lance_regs *ll = lp->ll;
596
597 dev->start = 0;
598 dev->tbusy = 1;
599
600
601 ll->rap = LE_CSR0;
602 ll->rdp = LE_C0_STOP;
603
604 free_irq (dev->irq, NULL);
605 #ifdef OLD_STYLE_IRQ
606 irq2dev_map [dev->irq] = NULL;
607 #endif
608
609 return 0;
610 }
611
612 static inline int lance_reset (struct device *dev)
613 {
614 struct lance_private *lp = (struct lance_private *)dev->priv;
615 volatile struct lance_regs *ll = lp->ll;
616 int status;
617
618
619 ll->rap = LE_CSR0;
620 ll->rdp = LE_C0_STOP;
621
622
623 if (lp->ledma) {
624 printk ("resetting ledma\n");
625 lp->ledma->regs->cond_reg |= DMA_RST_ENET;
626 udelay (200);
627 lp->ledma->regs->cond_reg &= ~DMA_RST_ENET;
628 lp->ledma->regs->dma_test = ((unsigned int) lp->init_block) & 0xff000000;
629 }
630 lance_init_ring (dev);
631 load_csrs (lp);
632 dev->trans_start = jiffies;
633 dev->interrupt = 0;
634 dev->start = 1;
635 dev->tbusy = 0;
636 status = init_restart_lance (lp);
637 #ifdef DEBUG_DRIVER
638 printk ("Lance restart=%d\n", status);
639 #endif
640 return status;
641 }
642
643 static int lance_start_xmit (struct sk_buff *skb, struct device *dev)
644 {
645 struct lance_private *lp = (struct lance_private *)dev->priv;
646 volatile struct lance_regs *ll = lp->ll;
647 volatile struct lance_init_block *ib = lp->init_block;
648 volatile unsigned long flush;
649 int entry, skblen, len;
650 int status = 0;
651 static int outs;
652
653
654 if (dev->tbusy) {
655 int tickssofar = jiffies - dev->trans_start;
656
657 if (tickssofar < 100) {
658 status = -1;
659 } else {
660 printk ("%s: transmit timed out, status %04x, resetting\n",
661 dev->name, ll->rdp);
662 lance_reset (dev);
663 }
664 return status;
665 }
666
667 if (skb == NULL) {
668 dev_tint (dev);
669 printk ("skb is NULL\n");
670 return 0;
671 }
672
673 if (skb->len <= 0) {
674 printk ("skb len is %ld\n", skb->len);
675 return 0;
676 }
677
678 #ifdef OLD_METHOD
679 dev->tbusy = 1;
680 #else
681 if (set_bit (0, (void *) &dev->tbusy) != 0) {
682 printk ("Transmitter access conflict.\n");
683 return -1;
684 }
685 #endif
686 skblen = skb->len;
687
688 if (!TX_BUFFS_AVAIL)
689 return -1;
690
691 #ifdef DEBUG_DRIVER
692
693 {
694 int i;
695
696 for (i = 0; i < 64; i++) {
697 if ((i % 16) == 0)
698 printk ("\n");
699 printk ("%2.2x ", skb->data [i]);
700 }
701 }
702 #endif
703 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
704 entry = lp->tx_new & TX_RING_MOD_MASK;
705 ib->btx_ring [entry].length = (-len) | 0xf000;
706 ib->btx_ring [entry].misc = 0;
707
708 memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
709
710
711 if (len != skblen)
712 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
713
714
715 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
716 lp->tx_new = (lp->tx_new+1) & TX_RING_MOD_MASK;
717
718 outs++;
719
720 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
721 dev->trans_start = jiffies;
722 dev_kfree_skb (skb, FREE_WRITE);
723
724 if (TX_BUFFS_AVAIL)
725 dev->tbusy = 0;
726
727
728
729 if (lp->ledma)
730 flush = ll->rdp;
731
732 return status;
733 }
734
735 static struct enet_statistics *lance_get_stats (struct device *dev)
736 {
737 struct lance_private *lp = (struct lance_private *) dev->priv;
738
739 return &lp->stats;
740 }
741
742 static void lance_set_multicast (struct device *dev)
743 {
744 #ifdef NOT_YET
745 struct lance_private *lp = (struct lance_private *) dev->priv;
746 volatile struct lance_init_block *ib = lp->init_block;
747 volatile struct lance_regs *ll = lp->ll;
748
749 ll->rap = LE_CSR0;
750 ll->rdp = LE_C0_STOP;
751 lance_init_ring (dev);
752 ib->mode |= LE_MO_PROM;
753 lance_init_ring (dev);
754 load_csrs (lp);
755 init_restart_lance (lp);
756 dev->tbusy = 0;
757 #endif
758 }
759
760 int sparc_lance_init (struct device *dev, struct linux_sbus_device *sdev,
761 struct Linux_SBus_DMA *ledma,
762 struct linux_sbus_device *lebuffer)
763 {
764 static unsigned version_printed = 0;
765 int i;
766 struct lance_private *lp;
767 volatile struct lance_regs *ll;
768
769 if (dev == NULL) {
770 dev = init_etherdev (0, sizeof (struct lance_private));
771 } else {
772 dev->priv = kmalloc (sizeof (struct lance_private), GFP_KERNEL);
773 if (dev->priv == NULL)
774 return -ENOMEM;
775 }
776 if (sparc_lance_debug && version_printed++ == 0)
777 printk (version);
778
779 printk ("%s: LANCE ", dev->name);
780
781 dev->base_addr = (long) sdev;
782
783
784
785
786
787 for (i = 0; i < 6; i++)
788 printk ("%2.2x%c",
789 dev->dev_addr [i] = idprom->id_eaddr [i], i == 5 ? ' ': ':');
790 printk("\n");
791
792
793 prom_apply_sbus_ranges (&sdev->reg_addrs [0], sdev->num_registers);
794 ll = sparc_alloc_io (sdev->reg_addrs [0].phys_addr, 0,
795 sizeof (struct lance_regs), lancestr,
796 sdev->reg_addrs[0].which_io, 0x0);
797
798
799 dev->priv = (void *)(((int)dev->priv + 7) & ~7);
800 lp = (struct lance_private *) dev->priv;
801 memset ((char *)dev->priv, 0, sizeof (struct lance_private));
802
803 if (lebuffer){
804 prom_apply_sbus_ranges (&sdev->reg_addrs [0], sdev->num_registers);
805 lp->init_block = (void *)
806 sparc_alloc_io (lebuffer->reg_addrs [0].phys_addr, 0,
807 sizeof (struct lance_init_block), "lebuffer",
808 lebuffer->reg_addrs [0].which_io, 0);
809 } else {
810 lp->init_block = (void *)
811 sparc_dvma_malloc (sizeof (struct lance_init_block),
812 lancedma);
813 }
814
815 lp->ll = ll;
816 lp->name = lancestr;
817 lp->ledma = ledma;
818
819 lp->burst_sizes = 0;
820 if (lp->ledma) {
821 char cable_prop[4];
822 unsigned int sbmask;
823
824
825 lp->burst_sizes = prom_getintdefault(ledma->SBus_dev->prom_node,
826 "burst-sizes", 0);
827
828
829 sbmask = prom_getintdefault(ledma->SBus_dev->my_bus->prom_node,
830 "burst-sizes", DMA_BURSTBITS);
831 lp->burst_sizes &= sbmask;
832
833
834 prom_getstring(ledma->SBus_dev->prom_node, "cable-selection",
835 cable_prop, sizeof(cable_prop));
836 if (!strcmp(cable_prop, "aui"))
837 lp->tpe = 0;
838 else
839 lp->tpe = 1;
840
841
842 lp->ledma->regs->cond_reg |= DMA_RST_ENET;
843 udelay (200);
844 lp->ledma->regs->cond_reg &= ~DMA_RST_ENET;
845 }
846
847
848 if ((int)(lp->init_block->brx_ring) & 0x07) {
849 printk(" **ERROR** LANCE Rx and Tx rings not on even boundary.\n");
850 return ENODEV;
851 }
852
853 dev->open = &lance_open;
854 dev->stop = &lance_close;
855 dev->hard_start_xmit = &lance_start_xmit;
856 dev->get_stats = &lance_get_stats;
857 dev->set_multicast_list = &lance_set_multicast;
858
859 dev->irq = (unsigned char) sdev->irqs [0].pri;
860 dev->dma = 0;
861 ether_setup (dev);
862
863 return 0;
864 }
865
866
867 static struct Linux_SBus_DMA *
868 find_ledma (struct linux_sbus_device *dev)
869 {
870 struct Linux_SBus_DMA *p;
871
872 for (p = dma_chain; p; p = p->next)
873 if (p->SBus_dev == dev)
874 return p;
875 return 0;
876 }
877
878
879 int sparc_lance_probe (struct device *dev)
880 {
881 struct linux_sbus *bus;
882 struct linux_sbus_device *sdev = 0;
883 struct Linux_SBus_DMA *ledma = 0;
884 int cards = 0, v;
885
886 for_each_sbus (bus) {
887 for_each_sbusdev (sdev, bus) {
888 if (cards) dev = NULL;
889 if (strcmp (sdev->prom_name, "le") == 0) {
890 cards++;
891 if ((v = sparc_lance_init(dev, sdev, ledma,0)))
892 return v;
893 }
894 if (strcmp (sdev->prom_name, "ledma") == 0) {
895 cards++;
896 ledma = find_ledma (sdev);
897 sdev = sdev->child;
898 if ((v = sparc_lance_init(dev, sdev, ledma,0)))
899 return v;
900 break;
901 }
902 if (strcmp (sdev->prom_name, "lebuffer") == 0){
903 struct linux_sbus_device *le = sdev->child;
904 cards++;
905 if ((v = sparc_lance_init(dev, le, ledma,sdev)))
906 return v;
907 break;
908 }
909 }
910 }
911 if (!cards)
912 return ENODEV;
913 return 0;
914 }
915
916
917
918
919
920
921