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
36static unsigned int version_printed;
37
38static int sonic_debug = -1;
39module_param(sonic_debug, int, 0);
40MODULE_PARM_DESC(sonic_debug, "debug message level");
41
42static void sonic_msg_init(struct net_device *dev)
43{
44 struct sonic_local *lp = netdev_priv(dev);
45
46 lp->msg_enable = netif_msg_init(sonic_debug, 0);
47
48 if (version_printed++ == 0)
49 netif_dbg(lp, drv, dev, "%s", version);
50}
51
52
53
54
55
56
57
58
59static int sonic_open(struct net_device *dev)
60{
61 struct sonic_local *lp = netdev_priv(dev);
62 int i;
63
64 netif_dbg(lp, ifup, dev, "%s: initializing sonic driver\n", __func__);
65
66 for (i = 0; i < SONIC_NUM_RRS; i++) {
67 struct sk_buff *skb = netdev_alloc_skb(dev, SONIC_RBSIZE + 2);
68 if (skb == NULL) {
69 while(i > 0) {
70 i--;
71 dev_kfree_skb(lp->rx_skb[i]);
72 lp->rx_skb[i] = NULL;
73 }
74 printk(KERN_ERR "%s: couldn't allocate receive buffers\n",
75 dev->name);
76 return -ENOMEM;
77 }
78
79 if (SONIC_BUS_SCALE(lp->dma_bitmode) == 2)
80 skb_reserve(skb, 2);
81 lp->rx_skb[i] = skb;
82 }
83
84 for (i = 0; i < SONIC_NUM_RRS; i++) {
85 dma_addr_t laddr = dma_map_single(lp->device, skb_put(lp->rx_skb[i], SONIC_RBSIZE),
86 SONIC_RBSIZE, DMA_FROM_DEVICE);
87 if (dma_mapping_error(lp->device, laddr)) {
88 while(i > 0) {
89 i--;
90 dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE);
91 lp->rx_laddr[i] = (dma_addr_t)0;
92 }
93 for (i = 0; i < SONIC_NUM_RRS; i++) {
94 dev_kfree_skb(lp->rx_skb[i]);
95 lp->rx_skb[i] = NULL;
96 }
97 printk(KERN_ERR "%s: couldn't map rx DMA buffers\n",
98 dev->name);
99 return -ENOMEM;
100 }
101 lp->rx_laddr[i] = laddr;
102 }
103
104
105
106
107 sonic_init(dev);
108
109 netif_start_queue(dev);
110
111 netif_dbg(lp, ifup, dev, "%s: Initialization done\n", __func__);
112
113 return 0;
114}
115
116
117
118
119
120static int sonic_close(struct net_device *dev)
121{
122 struct sonic_local *lp = netdev_priv(dev);
123 int i;
124
125 netif_dbg(lp, ifdown, dev, "%s\n", __func__);
126
127 netif_stop_queue(dev);
128
129
130
131
132 SONIC_WRITE(SONIC_IMR, 0);
133 SONIC_WRITE(SONIC_ISR, 0x7fff);
134 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
135
136
137 for (i = 0; i < SONIC_NUM_TDS; i++) {
138 if(lp->tx_laddr[i]) {
139 dma_unmap_single(lp->device, lp->tx_laddr[i], lp->tx_len[i], DMA_TO_DEVICE);
140 lp->tx_laddr[i] = (dma_addr_t)0;
141 }
142 if(lp->tx_skb[i]) {
143 dev_kfree_skb(lp->tx_skb[i]);
144 lp->tx_skb[i] = NULL;
145 }
146 }
147
148
149 for (i = 0; i < SONIC_NUM_RRS; i++) {
150 if(lp->rx_laddr[i]) {
151 dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE);
152 lp->rx_laddr[i] = (dma_addr_t)0;
153 }
154 if(lp->rx_skb[i]) {
155 dev_kfree_skb(lp->rx_skb[i]);
156 lp->rx_skb[i] = NULL;
157 }
158 }
159
160 return 0;
161}
162
163static void sonic_tx_timeout(struct net_device *dev)
164{
165 struct sonic_local *lp = netdev_priv(dev);
166 int i;
167
168
169
170
171 SONIC_WRITE(SONIC_IMR, 0);
172 SONIC_WRITE(SONIC_ISR, 0x7fff);
173 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
174
175 for (i = 0; i < SONIC_NUM_TDS; i++) {
176 if(lp->tx_laddr[i]) {
177 dma_unmap_single(lp->device, lp->tx_laddr[i], lp->tx_len[i], DMA_TO_DEVICE);
178 lp->tx_laddr[i] = (dma_addr_t)0;
179 }
180 if(lp->tx_skb[i]) {
181 dev_kfree_skb(lp->tx_skb[i]);
182 lp->tx_skb[i] = NULL;
183 }
184 }
185
186 sonic_init(dev);
187 lp->stats.tx_errors++;
188 netif_trans_update(dev);
189 netif_wake_queue(dev);
190}
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)
213{
214 struct sonic_local *lp = netdev_priv(dev);
215 dma_addr_t laddr;
216 int length;
217 int entry = lp->next_tx;
218
219 netif_dbg(lp, tx_queued, dev, "%s: skb=%p\n", __func__, skb);
220
221 length = skb->len;
222 if (length < ETH_ZLEN) {
223 if (skb_padto(skb, ETH_ZLEN))
224 return NETDEV_TX_OK;
225 length = ETH_ZLEN;
226 }
227
228
229
230
231
232 laddr = dma_map_single(lp->device, skb->data, length, DMA_TO_DEVICE);
233 if (!laddr) {
234 printk(KERN_ERR "%s: failed to map tx DMA buffer.\n", dev->name);
235 dev_kfree_skb(skb);
236 return NETDEV_TX_BUSY;
237 }
238
239 sonic_tda_put(dev, entry, SONIC_TD_STATUS, 0);
240 sonic_tda_put(dev, entry, SONIC_TD_FRAG_COUNT, 1);
241 sonic_tda_put(dev, entry, SONIC_TD_PKTSIZE, length);
242 sonic_tda_put(dev, entry, SONIC_TD_FRAG_PTR_L, laddr & 0xffff);
243 sonic_tda_put(dev, entry, SONIC_TD_FRAG_PTR_H, laddr >> 16);
244 sonic_tda_put(dev, entry, SONIC_TD_FRAG_SIZE, length);
245 sonic_tda_put(dev, entry, SONIC_TD_LINK,
246 sonic_tda_get(dev, entry, SONIC_TD_LINK) | SONIC_EOL);
247
248
249
250
251
252 wmb();
253 lp->tx_len[entry] = length;
254 lp->tx_laddr[entry] = laddr;
255 lp->tx_skb[entry] = skb;
256
257 wmb();
258 sonic_tda_put(dev, lp->eol_tx, SONIC_TD_LINK,
259 sonic_tda_get(dev, lp->eol_tx, SONIC_TD_LINK) & ~SONIC_EOL);
260 lp->eol_tx = entry;
261
262 lp->next_tx = (entry + 1) & SONIC_TDS_MASK;
263 if (lp->tx_skb[lp->next_tx] != NULL) {
264
265 netif_dbg(lp, tx_queued, dev, "%s: stopping queue\n", __func__);
266 netif_stop_queue(dev);
267
268 } else netif_start_queue(dev);
269
270 netif_dbg(lp, tx_queued, dev, "%s: issuing Tx command\n", __func__);
271
272 SONIC_WRITE(SONIC_CMD, SONIC_CR_TXP);
273
274 return NETDEV_TX_OK;
275}
276
277
278
279
280
281static irqreturn_t sonic_interrupt(int irq, void *dev_id)
282{
283 struct net_device *dev = dev_id;
284 struct sonic_local *lp = netdev_priv(dev);
285 int status;
286
287 if (!(status = SONIC_READ(SONIC_ISR) & SONIC_IMR_DEFAULT))
288 return IRQ_NONE;
289
290 do {
291 if (status & SONIC_INT_PKTRX) {
292 netif_dbg(lp, intr, dev, "%s: packet rx\n", __func__);
293 sonic_rx(dev);
294 SONIC_WRITE(SONIC_ISR, SONIC_INT_PKTRX);
295 }
296
297 if (status & SONIC_INT_TXDN) {
298 int entry = lp->cur_tx;
299 int td_status;
300 int freed_some = 0;
301
302
303
304
305
306
307
308
309 netif_dbg(lp, intr, dev, "%s: tx done\n", __func__);
310
311 while (lp->tx_skb[entry] != NULL) {
312 if ((td_status = sonic_tda_get(dev, entry, SONIC_TD_STATUS)) == 0)
313 break;
314
315 if (td_status & 0x0001) {
316 lp->stats.tx_packets++;
317 lp->stats.tx_bytes += sonic_tda_get(dev, entry, SONIC_TD_PKTSIZE);
318 } else {
319 lp->stats.tx_errors++;
320 if (td_status & 0x0642)
321 lp->stats.tx_aborted_errors++;
322 if (td_status & 0x0180)
323 lp->stats.tx_carrier_errors++;
324 if (td_status & 0x0020)
325 lp->stats.tx_window_errors++;
326 if (td_status & 0x0004)
327 lp->stats.tx_fifo_errors++;
328 }
329
330
331 dev_kfree_skb_irq(lp->tx_skb[entry]);
332 lp->tx_skb[entry] = NULL;
333
334 dma_unmap_single(lp->device, lp->tx_laddr[entry], lp->tx_len[entry], DMA_TO_DEVICE);
335 lp->tx_laddr[entry] = (dma_addr_t)0;
336 freed_some = 1;
337
338 if (sonic_tda_get(dev, entry, SONIC_TD_LINK) & SONIC_EOL) {
339 entry = (entry + 1) & SONIC_TDS_MASK;
340 break;
341 }
342 entry = (entry + 1) & SONIC_TDS_MASK;
343 }
344
345 if (freed_some || lp->tx_skb[entry] == NULL)
346 netif_wake_queue(dev);
347 lp->cur_tx = entry;
348 SONIC_WRITE(SONIC_ISR, SONIC_INT_TXDN);
349 }
350
351
352
353
354 if (status & SONIC_INT_RFO) {
355 netif_dbg(lp, rx_err, dev, "%s: rx fifo overrun\n",
356 __func__);
357 lp->stats.rx_fifo_errors++;
358 SONIC_WRITE(SONIC_ISR, SONIC_INT_RFO);
359 }
360 if (status & SONIC_INT_RDE) {
361 netif_dbg(lp, rx_err, dev, "%s: rx descriptors exhausted\n",
362 __func__);
363 lp->stats.rx_dropped++;
364 SONIC_WRITE(SONIC_ISR, SONIC_INT_RDE);
365 }
366 if (status & SONIC_INT_RBAE) {
367 netif_dbg(lp, rx_err, dev, "%s: rx buffer area exceeded\n",
368 __func__);
369 lp->stats.rx_dropped++;
370 SONIC_WRITE(SONIC_ISR, SONIC_INT_RBAE);
371 }
372
373
374 if (status & SONIC_INT_FAE) {
375 lp->stats.rx_frame_errors += 65536;
376 SONIC_WRITE(SONIC_ISR, SONIC_INT_FAE);
377 }
378 if (status & SONIC_INT_CRC) {
379 lp->stats.rx_crc_errors += 65536;
380 SONIC_WRITE(SONIC_ISR, SONIC_INT_CRC);
381 }
382 if (status & SONIC_INT_MP) {
383 lp->stats.rx_missed_errors += 65536;
384 SONIC_WRITE(SONIC_ISR, SONIC_INT_MP);
385 }
386
387
388 if (status & SONIC_INT_TXER) {
389 if (SONIC_READ(SONIC_TCR) & SONIC_TCR_FU)
390 netif_dbg(lp, tx_err, dev, "%s: tx fifo underrun\n",
391 __func__);
392 SONIC_WRITE(SONIC_ISR, SONIC_INT_TXER);
393 }
394
395
396 if (status & SONIC_INT_BR) {
397 printk(KERN_ERR "%s: Bus retry occurred! Device interrupt disabled.\n",
398 dev->name);
399
400
401 SONIC_WRITE(SONIC_IMR, 0);
402 SONIC_WRITE(SONIC_ISR, SONIC_INT_BR);
403 }
404
405
406 if (status & SONIC_INT_LCD)
407 SONIC_WRITE(SONIC_ISR, SONIC_INT_LCD);
408 } while((status = SONIC_READ(SONIC_ISR) & SONIC_IMR_DEFAULT));
409 return IRQ_HANDLED;
410}
411
412
413
414
415static void sonic_rx(struct net_device *dev)
416{
417 struct sonic_local *lp = netdev_priv(dev);
418 int status;
419 int entry = lp->cur_rx;
420
421 while (sonic_rda_get(dev, entry, SONIC_RD_IN_USE) == 0) {
422 struct sk_buff *used_skb;
423 struct sk_buff *new_skb;
424 dma_addr_t new_laddr;
425 u16 bufadr_l;
426 u16 bufadr_h;
427 int pkt_len;
428
429 status = sonic_rda_get(dev, entry, SONIC_RD_STATUS);
430 if (status & SONIC_RCR_PRX) {
431
432 new_skb = netdev_alloc_skb(dev, SONIC_RBSIZE + 2);
433 if (new_skb == NULL) {
434 lp->stats.rx_dropped++;
435 break;
436 }
437
438 if(SONIC_BUS_SCALE(lp->dma_bitmode) == 2)
439 skb_reserve(new_skb, 2);
440
441 new_laddr = dma_map_single(lp->device, skb_put(new_skb, SONIC_RBSIZE),
442 SONIC_RBSIZE, DMA_FROM_DEVICE);
443 if (!new_laddr) {
444 dev_kfree_skb(new_skb);
445 printk(KERN_ERR "%s: Failed to map rx buffer, dropping packet.\n", dev->name);
446 lp->stats.rx_dropped++;
447 break;
448 }
449
450
451 dma_unmap_single(lp->device, lp->rx_laddr[entry], SONIC_RBSIZE, DMA_FROM_DEVICE);
452 used_skb = lp->rx_skb[entry];
453 pkt_len = sonic_rda_get(dev, entry, SONIC_RD_PKTLEN);
454 skb_trim(used_skb, pkt_len);
455 used_skb->protocol = eth_type_trans(used_skb, dev);
456 netif_rx(used_skb);
457 lp->stats.rx_packets++;
458 lp->stats.rx_bytes += pkt_len;
459
460
461 lp->rx_laddr[entry] = new_laddr;
462 lp->rx_skb[entry] = new_skb;
463
464 bufadr_l = (unsigned long)new_laddr & 0xffff;
465 bufadr_h = (unsigned long)new_laddr >> 16;
466 sonic_rra_put(dev, entry, SONIC_RR_BUFADR_L, bufadr_l);
467 sonic_rra_put(dev, entry, SONIC_RR_BUFADR_H, bufadr_h);
468 } else {
469
470 lp->stats.rx_errors++;
471 if (status & SONIC_RCR_FAER)
472 lp->stats.rx_frame_errors++;
473 if (status & SONIC_RCR_CRCR)
474 lp->stats.rx_crc_errors++;
475 }
476 if (status & SONIC_RCR_LPKT) {
477
478
479
480
481 lp->cur_rwp += SIZEOF_SONIC_RR * SONIC_BUS_SCALE(lp->dma_bitmode);
482 if (lp->cur_rwp >= lp->rra_end) lp->cur_rwp = lp->rra_laddr & 0xffff;
483 SONIC_WRITE(SONIC_RWP, lp->cur_rwp);
484 if (SONIC_READ(SONIC_ISR) & SONIC_INT_RBE) {
485 netif_dbg(lp, rx_err, dev, "%s: rx buffer exhausted\n",
486 __func__);
487 SONIC_WRITE(SONIC_ISR, SONIC_INT_RBE);
488 }
489 } else
490 printk(KERN_ERR "%s: rx desc without RCR_LPKT. Shouldn't happen !?\n",
491 dev->name);
492
493
494
495 sonic_rda_put(dev, entry, SONIC_RD_LINK,
496 sonic_rda_get(dev, entry, SONIC_RD_LINK) | SONIC_EOL);
497 sonic_rda_put(dev, entry, SONIC_RD_IN_USE, 1);
498 sonic_rda_put(dev, lp->eol_rx, SONIC_RD_LINK,
499 sonic_rda_get(dev, lp->eol_rx, SONIC_RD_LINK) & ~SONIC_EOL);
500 lp->eol_rx = entry;
501 lp->cur_rx = entry = (entry + 1) & SONIC_RDS_MASK;
502 }
503
504
505
506
507
508}
509
510
511
512
513
514
515static struct net_device_stats *sonic_get_stats(struct net_device *dev)
516{
517 struct sonic_local *lp = netdev_priv(dev);
518
519
520 lp->stats.rx_crc_errors += SONIC_READ(SONIC_CRCT);
521 SONIC_WRITE(SONIC_CRCT, 0xffff);
522 lp->stats.rx_frame_errors += SONIC_READ(SONIC_FAET);
523 SONIC_WRITE(SONIC_FAET, 0xffff);
524 lp->stats.rx_missed_errors += SONIC_READ(SONIC_MPT);
525 SONIC_WRITE(SONIC_MPT, 0xffff);
526
527 return &lp->stats;
528}
529
530
531
532
533
534static void sonic_multicast_list(struct net_device *dev)
535{
536 struct sonic_local *lp = netdev_priv(dev);
537 unsigned int rcr;
538 struct netdev_hw_addr *ha;
539 unsigned char *addr;
540 int i;
541
542 rcr = SONIC_READ(SONIC_RCR) & ~(SONIC_RCR_PRO | SONIC_RCR_AMC);
543 rcr |= SONIC_RCR_BRD;
544
545 if (dev->flags & IFF_PROMISC) {
546 rcr |= SONIC_RCR_PRO;
547 } else {
548 if ((dev->flags & IFF_ALLMULTI) ||
549 (netdev_mc_count(dev) > 15)) {
550 rcr |= SONIC_RCR_AMC;
551 } else {
552 netif_dbg(lp, ifup, dev, "%s: mc_count %d\n", __func__,
553 netdev_mc_count(dev));
554 sonic_set_cam_enable(dev, 1);
555 i = 1;
556 netdev_for_each_mc_addr(ha, dev) {
557 addr = ha->addr;
558 sonic_cda_put(dev, i, SONIC_CD_CAP0, addr[1] << 8 | addr[0]);
559 sonic_cda_put(dev, i, SONIC_CD_CAP1, addr[3] << 8 | addr[2]);
560 sonic_cda_put(dev, i, SONIC_CD_CAP2, addr[5] << 8 | addr[4]);
561 sonic_set_cam_enable(dev, sonic_get_cam_enable(dev) | (1 << i));
562 i++;
563 }
564 SONIC_WRITE(SONIC_CDC, 16);
565
566 SONIC_WRITE(SONIC_CDP, lp->cda_laddr & 0xffff);
567 SONIC_WRITE(SONIC_CMD, SONIC_CR_LCAM);
568 }
569 }
570
571 netif_dbg(lp, ifup, dev, "%s: setting RCR=%x\n", __func__, rcr);
572
573 SONIC_WRITE(SONIC_RCR, rcr);
574}
575
576
577
578
579
580static int sonic_init(struct net_device *dev)
581{
582 unsigned int cmd;
583 struct sonic_local *lp = netdev_priv(dev);
584 int i;
585
586
587
588
589
590 SONIC_WRITE(SONIC_IMR, 0);
591 SONIC_WRITE(SONIC_ISR, 0x7fff);
592 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
593
594
595
596
597
598 SONIC_WRITE(SONIC_CMD, 0);
599 SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS);
600
601
602
603
604 netif_dbg(lp, ifup, dev, "%s: initialize receive resource area\n",
605 __func__);
606
607 for (i = 0; i < SONIC_NUM_RRS; i++) {
608 u16 bufadr_l = (unsigned long)lp->rx_laddr[i] & 0xffff;
609 u16 bufadr_h = (unsigned long)lp->rx_laddr[i] >> 16;
610 sonic_rra_put(dev, i, SONIC_RR_BUFADR_L, bufadr_l);
611 sonic_rra_put(dev, i, SONIC_RR_BUFADR_H, bufadr_h);
612 sonic_rra_put(dev, i, SONIC_RR_BUFSIZE_L, SONIC_RBSIZE >> 1);
613 sonic_rra_put(dev, i, SONIC_RR_BUFSIZE_H, 0);
614 }
615
616
617 lp->rra_end = (lp->rra_laddr + SONIC_NUM_RRS * SIZEOF_SONIC_RR *
618 SONIC_BUS_SCALE(lp->dma_bitmode)) & 0xffff;
619 lp->cur_rwp = (lp->rra_laddr + (SONIC_NUM_RRS - 1) * SIZEOF_SONIC_RR *
620 SONIC_BUS_SCALE(lp->dma_bitmode)) & 0xffff;
621
622 SONIC_WRITE(SONIC_RSA, lp->rra_laddr & 0xffff);
623 SONIC_WRITE(SONIC_REA, lp->rra_end);
624 SONIC_WRITE(SONIC_RRP, lp->rra_laddr & 0xffff);
625 SONIC_WRITE(SONIC_RWP, lp->cur_rwp);
626 SONIC_WRITE(SONIC_URRA, lp->rra_laddr >> 16);
627 SONIC_WRITE(SONIC_EOBC, (SONIC_RBSIZE >> 1) - (lp->dma_bitmode ? 2 : 1));
628
629
630 netif_dbg(lp, ifup, dev, "%s: issuing RRRA command\n", __func__);
631
632 SONIC_WRITE(SONIC_CMD, SONIC_CR_RRRA);
633 i = 0;
634 while (i++ < 100) {
635 if (SONIC_READ(SONIC_CMD) & SONIC_CR_RRRA)
636 break;
637 }
638
639 netif_dbg(lp, ifup, dev, "%s: status=%x, i=%d\n", __func__,
640 SONIC_READ(SONIC_CMD), i);
641
642
643
644
645
646
647 netif_dbg(lp, ifup, dev, "%s: initialize receive descriptors\n",
648 __func__);
649
650 for (i=0; i<SONIC_NUM_RDS; i++) {
651 sonic_rda_put(dev, i, SONIC_RD_STATUS, 0);
652 sonic_rda_put(dev, i, SONIC_RD_PKTLEN, 0);
653 sonic_rda_put(dev, i, SONIC_RD_PKTPTR_L, 0);
654 sonic_rda_put(dev, i, SONIC_RD_PKTPTR_H, 0);
655 sonic_rda_put(dev, i, SONIC_RD_SEQNO, 0);
656 sonic_rda_put(dev, i, SONIC_RD_IN_USE, 1);
657 sonic_rda_put(dev, i, SONIC_RD_LINK,
658 lp->rda_laddr +
659 ((i+1) * SIZEOF_SONIC_RD * SONIC_BUS_SCALE(lp->dma_bitmode)));
660 }
661
662 sonic_rda_put(dev, SONIC_NUM_RDS - 1, SONIC_RD_LINK,
663 (lp->rda_laddr & 0xffff) | SONIC_EOL);
664 lp->eol_rx = SONIC_NUM_RDS - 1;
665 lp->cur_rx = 0;
666 SONIC_WRITE(SONIC_URDA, lp->rda_laddr >> 16);
667 SONIC_WRITE(SONIC_CRDA, lp->rda_laddr & 0xffff);
668
669
670
671
672 netif_dbg(lp, ifup, dev, "%s: initialize transmit descriptors\n",
673 __func__);
674
675 for (i = 0; i < SONIC_NUM_TDS; i++) {
676 sonic_tda_put(dev, i, SONIC_TD_STATUS, 0);
677 sonic_tda_put(dev, i, SONIC_TD_CONFIG, 0);
678 sonic_tda_put(dev, i, SONIC_TD_PKTSIZE, 0);
679 sonic_tda_put(dev, i, SONIC_TD_FRAG_COUNT, 0);
680 sonic_tda_put(dev, i, SONIC_TD_LINK,
681 (lp->tda_laddr & 0xffff) +
682 (i + 1) * SIZEOF_SONIC_TD * SONIC_BUS_SCALE(lp->dma_bitmode));
683 lp->tx_skb[i] = NULL;
684 }
685
686 sonic_tda_put(dev, SONIC_NUM_TDS - 1, SONIC_TD_LINK,
687 (lp->tda_laddr & 0xffff));
688
689 SONIC_WRITE(SONIC_UTDA, lp->tda_laddr >> 16);
690 SONIC_WRITE(SONIC_CTDA, lp->tda_laddr & 0xffff);
691 lp->cur_tx = lp->next_tx = 0;
692 lp->eol_tx = SONIC_NUM_TDS - 1;
693
694
695
696
697 sonic_cda_put(dev, 0, SONIC_CD_CAP0, dev->dev_addr[1] << 8 | dev->dev_addr[0]);
698 sonic_cda_put(dev, 0, SONIC_CD_CAP1, dev->dev_addr[3] << 8 | dev->dev_addr[2]);
699 sonic_cda_put(dev, 0, SONIC_CD_CAP2, dev->dev_addr[5] << 8 | dev->dev_addr[4]);
700 sonic_set_cam_enable(dev, 1);
701
702 for (i = 0; i < 16; i++)
703 sonic_cda_put(dev, i, SONIC_CD_ENTRY_POINTER, i);
704
705
706
707
708 SONIC_WRITE(SONIC_CDP, lp->cda_laddr & 0xffff);
709 SONIC_WRITE(SONIC_CDC, 16);
710
711
712
713
714 SONIC_WRITE(SONIC_CMD, SONIC_CR_LCAM);
715
716 i = 0;
717 while (i++ < 100) {
718 if (SONIC_READ(SONIC_ISR) & SONIC_INT_LCD)
719 break;
720 }
721 netif_dbg(lp, ifup, dev, "%s: CMD=%x, ISR=%x, i=%d\n", __func__,
722 SONIC_READ(SONIC_CMD), SONIC_READ(SONIC_ISR), i);
723
724
725
726
727
728 SONIC_WRITE(SONIC_CMD, SONIC_CR_RXEN | SONIC_CR_STP);
729 SONIC_WRITE(SONIC_RCR, SONIC_RCR_DEFAULT);
730 SONIC_WRITE(SONIC_TCR, SONIC_TCR_DEFAULT);
731 SONIC_WRITE(SONIC_ISR, 0x7fff);
732 SONIC_WRITE(SONIC_IMR, SONIC_IMR_DEFAULT);
733
734 cmd = SONIC_READ(SONIC_CMD);
735 if ((cmd & SONIC_CR_RXEN) == 0 || (cmd & SONIC_CR_STP) == 0)
736 printk(KERN_ERR "sonic_init: failed, status=%x\n", cmd);
737
738 netif_dbg(lp, ifup, dev, "%s: new status=%x\n", __func__,
739 SONIC_READ(SONIC_CMD));
740
741 return 0;
742}
743
744MODULE_LICENSE("GPL");
745