6 * Converted to DMA API, added zero-copy buffer handling, and
7 * (from the mac68k project) introduced dhd's support for 16-bit cards.
9 * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
11 * This driver is based on work from Andreas Busse, but most of
12 * the code is rewritten.
14 * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
16 * Core code included by system sonic drivers
18 * And... partially rewritten again by David Huggins-Daines in order
19 * to cope with screwed up Macintosh NICs that may or may not use
22 * (C) 1999 David Huggins-Daines <dhd@debian.org>
27 * Sources: Olivetti M700-10 Risc Personal Computer hardware handbook,
28 * National Semiconductors data sheet for the DP83932B Sonic Ethernet
29 * controller, and the files "8390.c" and "skeleton.c" in this directory.
31 * Additional sources: Nat Semi data sheet for the DP83932C and Nat Semi
32 * Application Note AN-746, the files "lance.c" and "ibmlana.c". See also
33 * the NetBSD file "sys/arch/mac68k/dev/if_sn.c".
36 static unsigned int version_printed;
38 static int sonic_debug = -1;
39 module_param(sonic_debug, int, 0);
40 MODULE_PARM_DESC(sonic_debug, "debug message level");
42 static void sonic_msg_init(struct net_device *dev)
44 struct sonic_local *lp = netdev_priv(dev);
46 lp->msg_enable = netif_msg_init(sonic_debug, 0);
48 if (version_printed++ == 0)
49 netif_dbg(lp, drv, dev, "%s", version);
53 * Open/initialize the SONIC controller.
55 * This routine should set everything up anew at each open, even
56 * registers that "should" only need to be set once at boot, so that
57 * there is non-reboot way to recover if something goes wrong.
59 static int sonic_open(struct net_device *dev)
61 struct sonic_local *lp = netdev_priv(dev);
64 netif_dbg(lp, ifup, dev, "%s: initializing sonic driver\n", __func__);
66 spin_lock_init(&lp->lock);
68 for (i = 0; i < SONIC_NUM_RRS; i++) {
69 struct sk_buff *skb = netdev_alloc_skb(dev, SONIC_RBSIZE + 2);
71 while(i > 0) { /* free any that were allocated successfully */
73 dev_kfree_skb(lp->rx_skb[i]);
76 printk(KERN_ERR "%s: couldn't allocate receive buffers\n",
80 /* align IP header unless DMA requires otherwise */
81 if (SONIC_BUS_SCALE(lp->dma_bitmode) == 2)
86 for (i = 0; i < SONIC_NUM_RRS; i++) {
87 dma_addr_t laddr = dma_map_single(lp->device, skb_put(lp->rx_skb[i], SONIC_RBSIZE),
88 SONIC_RBSIZE, DMA_FROM_DEVICE);
89 if (dma_mapping_error(lp->device, laddr)) {
90 while(i > 0) { /* free any that were mapped successfully */
92 dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE);
93 lp->rx_laddr[i] = (dma_addr_t)0;
95 for (i = 0; i < SONIC_NUM_RRS; i++) {
96 dev_kfree_skb(lp->rx_skb[i]);
99 printk(KERN_ERR "%s: couldn't map rx DMA buffers\n",
103 lp->rx_laddr[i] = laddr;
107 * Initialize the SONIC
111 netif_start_queue(dev);
113 netif_dbg(lp, ifup, dev, "%s: Initialization done\n", __func__);
118 /* Wait for the SONIC to become idle. */
119 static void sonic_quiesce(struct net_device *dev, u16 mask)
121 struct sonic_local * __maybe_unused lp = netdev_priv(dev);
125 for (i = 0; i < 1000; ++i) {
126 bits = SONIC_READ(SONIC_CMD) & mask;
129 if (irqs_disabled() || in_interrupt())
132 usleep_range(100, 200);
134 WARN_ONCE(1, "command deadline expired! 0x%04x\n", bits);
138 * Close the SONIC device
140 static int sonic_close(struct net_device *dev)
142 struct sonic_local *lp = netdev_priv(dev);
145 netif_dbg(lp, ifdown, dev, "%s\n", __func__);
147 netif_stop_queue(dev);
150 * stop the SONIC, disable interrupts
152 SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS);
153 sonic_quiesce(dev, SONIC_CR_ALL);
155 SONIC_WRITE(SONIC_IMR, 0);
156 SONIC_WRITE(SONIC_ISR, 0x7fff);
157 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
159 /* unmap and free skbs that haven't been transmitted */
160 for (i = 0; i < SONIC_NUM_TDS; i++) {
161 if(lp->tx_laddr[i]) {
162 dma_unmap_single(lp->device, lp->tx_laddr[i], lp->tx_len[i], DMA_TO_DEVICE);
163 lp->tx_laddr[i] = (dma_addr_t)0;
166 dev_kfree_skb(lp->tx_skb[i]);
167 lp->tx_skb[i] = NULL;
171 /* unmap and free the receive buffers */
172 for (i = 0; i < SONIC_NUM_RRS; i++) {
173 if(lp->rx_laddr[i]) {
174 dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE);
175 lp->rx_laddr[i] = (dma_addr_t)0;
178 dev_kfree_skb(lp->rx_skb[i]);
179 lp->rx_skb[i] = NULL;
186 static void sonic_tx_timeout(struct net_device *dev)
188 struct sonic_local *lp = netdev_priv(dev);
191 * put the Sonic into software-reset mode and
192 * disable all interrupts before releasing DMA buffers
194 SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS);
195 sonic_quiesce(dev, SONIC_CR_ALL);
197 SONIC_WRITE(SONIC_IMR, 0);
198 SONIC_WRITE(SONIC_ISR, 0x7fff);
199 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
200 /* We could resend the original skbs. Easier to re-initialise. */
201 for (i = 0; i < SONIC_NUM_TDS; i++) {
202 if(lp->tx_laddr[i]) {
203 dma_unmap_single(lp->device, lp->tx_laddr[i], lp->tx_len[i], DMA_TO_DEVICE);
204 lp->tx_laddr[i] = (dma_addr_t)0;
207 dev_kfree_skb(lp->tx_skb[i]);
208 lp->tx_skb[i] = NULL;
211 /* Try to restart the adaptor. */
213 lp->stats.tx_errors++;
214 netif_trans_update(dev); /* prevent tx timeout */
215 netif_wake_queue(dev);
221 * Appends new TD during transmission thus avoiding any TX interrupts
222 * until we run out of TDs.
223 * This routine interacts closely with the ISR in that it may,
225 * reset the status flags of the new TD
226 * set and reset EOL flags
228 * The ISR interacts with this routine in various ways. It may,
230 * test the EOL and status flags of the TDs
232 * Concurrently with all of this, the SONIC is potentially writing to
233 * the status flags of the TDs.
236 static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)
238 struct sonic_local *lp = netdev_priv(dev);
244 netif_dbg(lp, tx_queued, dev, "%s: skb=%p\n", __func__, skb);
247 if (length < ETH_ZLEN) {
248 if (skb_padto(skb, ETH_ZLEN))
254 * Map the packet data into the logical DMA address space
257 laddr = dma_map_single(lp->device, skb->data, length, DMA_TO_DEVICE);
259 pr_err_ratelimited("%s: failed to map tx DMA buffer.\n", dev->name);
260 dev_kfree_skb_any(skb);
264 spin_lock_irqsave(&lp->lock, flags);
268 sonic_tda_put(dev, entry, SONIC_TD_STATUS, 0); /* clear status */
269 sonic_tda_put(dev, entry, SONIC_TD_FRAG_COUNT, 1); /* single fragment */
270 sonic_tda_put(dev, entry, SONIC_TD_PKTSIZE, length); /* length of packet */
271 sonic_tda_put(dev, entry, SONIC_TD_FRAG_PTR_L, laddr & 0xffff);
272 sonic_tda_put(dev, entry, SONIC_TD_FRAG_PTR_H, laddr >> 16);
273 sonic_tda_put(dev, entry, SONIC_TD_FRAG_SIZE, length);
274 sonic_tda_put(dev, entry, SONIC_TD_LINK,
275 sonic_tda_get(dev, entry, SONIC_TD_LINK) | SONIC_EOL);
278 lp->tx_len[entry] = length;
279 lp->tx_laddr[entry] = laddr;
280 lp->tx_skb[entry] = skb;
283 sonic_tda_put(dev, lp->eol_tx, SONIC_TD_LINK,
284 sonic_tda_get(dev, lp->eol_tx, SONIC_TD_LINK) & ~SONIC_EOL);
287 lp->next_tx = (entry + 1) & SONIC_TDS_MASK;
288 if (lp->tx_skb[lp->next_tx] != NULL) {
289 /* The ring is full, the ISR has yet to process the next TD. */
290 netif_dbg(lp, tx_queued, dev, "%s: stopping queue\n", __func__);
291 netif_stop_queue(dev);
292 /* after this packet, wait for ISR to free up some TDAs */
293 } else netif_start_queue(dev);
295 netif_dbg(lp, tx_queued, dev, "%s: issuing Tx command\n", __func__);
297 SONIC_WRITE(SONIC_CMD, SONIC_CR_TXP);
299 spin_unlock_irqrestore(&lp->lock, flags);
305 * The typical workload of the driver:
306 * Handle the network interface interrupts.
308 static irqreturn_t sonic_interrupt(int irq, void *dev_id)
310 struct net_device *dev = dev_id;
311 struct sonic_local *lp = netdev_priv(dev);
315 /* The lock has two purposes. Firstly, it synchronizes sonic_interrupt()
316 * with sonic_send_packet() so that the two functions can share state.
317 * Secondly, it makes sonic_interrupt() re-entrant, as that is required
318 * by macsonic which must use two IRQs with different priority levels.
320 spin_lock_irqsave(&lp->lock, flags);
322 status = SONIC_READ(SONIC_ISR) & SONIC_IMR_DEFAULT;
324 spin_unlock_irqrestore(&lp->lock, flags);
330 SONIC_WRITE(SONIC_ISR, status); /* clear the interrupt(s) */
332 if (status & SONIC_INT_PKTRX) {
333 netif_dbg(lp, intr, dev, "%s: packet rx\n", __func__);
334 sonic_rx(dev); /* got packet(s) */
337 if (status & SONIC_INT_TXDN) {
338 int entry = lp->cur_tx;
342 /* The state of a Transmit Descriptor may be inferred
343 * from { tx_skb[entry], td_status } as follows.
344 * { clear, clear } => the TD has never been used
345 * { set, clear } => the TD was handed to SONIC
346 * { set, set } => the TD was handed back
347 * { clear, set } => the TD is available for re-use
350 netif_dbg(lp, intr, dev, "%s: tx done\n", __func__);
352 while (lp->tx_skb[entry] != NULL) {
353 if ((td_status = sonic_tda_get(dev, entry, SONIC_TD_STATUS)) == 0)
356 if (td_status & SONIC_TCR_PTX) {
357 lp->stats.tx_packets++;
358 lp->stats.tx_bytes += sonic_tda_get(dev, entry, SONIC_TD_PKTSIZE);
360 if (td_status & (SONIC_TCR_EXD |
361 SONIC_TCR_EXC | SONIC_TCR_BCM))
362 lp->stats.tx_aborted_errors++;
364 (SONIC_TCR_NCRS | SONIC_TCR_CRLS))
365 lp->stats.tx_carrier_errors++;
366 if (td_status & SONIC_TCR_OWC)
367 lp->stats.tx_window_errors++;
368 if (td_status & SONIC_TCR_FU)
369 lp->stats.tx_fifo_errors++;
372 /* We must free the original skb */
373 dev_kfree_skb_irq(lp->tx_skb[entry]);
374 lp->tx_skb[entry] = NULL;
375 /* and unmap DMA buffer */
376 dma_unmap_single(lp->device, lp->tx_laddr[entry], lp->tx_len[entry], DMA_TO_DEVICE);
377 lp->tx_laddr[entry] = (dma_addr_t)0;
380 if (sonic_tda_get(dev, entry, SONIC_TD_LINK) & SONIC_EOL) {
381 entry = (entry + 1) & SONIC_TDS_MASK;
384 entry = (entry + 1) & SONIC_TDS_MASK;
387 if (freed_some || lp->tx_skb[entry] == NULL)
388 netif_wake_queue(dev); /* The ring is no longer full */
393 * check error conditions
395 if (status & SONIC_INT_RFO) {
396 netif_dbg(lp, rx_err, dev, "%s: rx fifo overrun\n",
399 if (status & SONIC_INT_RDE) {
400 netif_dbg(lp, rx_err, dev, "%s: rx descriptors exhausted\n",
403 if (status & SONIC_INT_RBAE) {
404 netif_dbg(lp, rx_err, dev, "%s: rx buffer area exceeded\n",
408 /* counter overruns; all counters are 16bit wide */
409 if (status & SONIC_INT_FAE)
410 lp->stats.rx_frame_errors += 65536;
411 if (status & SONIC_INT_CRC)
412 lp->stats.rx_crc_errors += 65536;
413 if (status & SONIC_INT_MP)
414 lp->stats.rx_missed_errors += 65536;
417 if (status & SONIC_INT_TXER)
418 if (SONIC_READ(SONIC_TCR) & SONIC_TCR_FU)
419 netif_dbg(lp, tx_err, dev, "%s: tx fifo underrun\n",
423 if (status & SONIC_INT_BR) {
424 printk(KERN_ERR "%s: Bus retry occurred! Device interrupt disabled.\n",
426 /* ... to help debug DMA problems causing endless interrupts. */
427 /* Bounce the eth interface to turn on the interrupt again. */
428 SONIC_WRITE(SONIC_IMR, 0);
431 status = SONIC_READ(SONIC_ISR) & SONIC_IMR_DEFAULT;
434 spin_unlock_irqrestore(&lp->lock, flags);
439 /* Return the array index corresponding to a given Receive Buffer pointer. */
440 static int index_from_addr(struct sonic_local *lp, dma_addr_t addr,
443 unsigned int i = last;
446 i = (i + 1) & SONIC_RRS_MASK;
447 if (addr == lp->rx_laddr[i])
454 /* Allocate and map a new skb to be used as a receive buffer. */
455 static bool sonic_alloc_rb(struct net_device *dev, struct sonic_local *lp,
456 struct sk_buff **new_skb, dma_addr_t *new_addr)
458 *new_skb = netdev_alloc_skb(dev, SONIC_RBSIZE + 2);
462 if (SONIC_BUS_SCALE(lp->dma_bitmode) == 2)
463 skb_reserve(*new_skb, 2);
465 *new_addr = dma_map_single(lp->device, skb_put(*new_skb, SONIC_RBSIZE),
466 SONIC_RBSIZE, DMA_FROM_DEVICE);
468 dev_kfree_skb(*new_skb);
476 /* Place a new receive resource in the Receive Resource Area and update RWP. */
477 static void sonic_update_rra(struct net_device *dev, struct sonic_local *lp,
478 dma_addr_t old_addr, dma_addr_t new_addr)
480 unsigned int entry = sonic_rr_entry(dev, SONIC_READ(SONIC_RWP));
481 unsigned int end = sonic_rr_entry(dev, SONIC_READ(SONIC_RRP));
484 /* The resources in the range [RRP, RWP) belong to the SONIC. This loop
485 * scans the other resources in the RRA, those in the range [RWP, RRP).
488 buf = (sonic_rra_get(dev, entry, SONIC_RR_BUFADR_H) << 16) |
489 sonic_rra_get(dev, entry, SONIC_RR_BUFADR_L);
494 entry = (entry + 1) & SONIC_RRS_MASK;
495 } while (entry != end);
497 WARN_ONCE(buf != old_addr, "failed to find resource!\n");
499 sonic_rra_put(dev, entry, SONIC_RR_BUFADR_H, new_addr >> 16);
500 sonic_rra_put(dev, entry, SONIC_RR_BUFADR_L, new_addr & 0xffff);
502 entry = (entry + 1) & SONIC_RRS_MASK;
504 SONIC_WRITE(SONIC_RWP, sonic_rr_addr(dev, entry));
508 * We have a good packet(s), pass it/them up the network stack.
510 static void sonic_rx(struct net_device *dev)
512 struct sonic_local *lp = netdev_priv(dev);
513 int entry = lp->cur_rx;
514 int prev_entry = lp->eol_rx;
517 while (sonic_rda_get(dev, entry, SONIC_RD_IN_USE) == 0) {
518 u16 status = sonic_rda_get(dev, entry, SONIC_RD_STATUS);
520 /* If the RD has LPKT set, the chip has finished with the RB */
521 if ((status & SONIC_RCR_PRX) && (status & SONIC_RCR_LPKT)) {
522 struct sk_buff *new_skb;
523 dma_addr_t new_laddr;
524 u32 addr = (sonic_rda_get(dev, entry,
525 SONIC_RD_PKTPTR_H) << 16) |
526 sonic_rda_get(dev, entry, SONIC_RD_PKTPTR_L);
527 int i = index_from_addr(lp, addr, entry);
530 WARN_ONCE(1, "failed to find buffer!\n");
534 if (sonic_alloc_rb(dev, lp, &new_skb, &new_laddr)) {
535 struct sk_buff *used_skb = lp->rx_skb[i];
538 /* Pass the used buffer up the stack */
539 dma_unmap_single(lp->device, addr, SONIC_RBSIZE,
542 pkt_len = sonic_rda_get(dev, entry,
544 skb_trim(used_skb, pkt_len);
545 used_skb->protocol = eth_type_trans(used_skb,
548 lp->stats.rx_packets++;
549 lp->stats.rx_bytes += pkt_len;
551 lp->rx_skb[i] = new_skb;
552 lp->rx_laddr[i] = new_laddr;
554 /* Failed to obtain a new buffer so re-use it */
556 lp->stats.rx_dropped++;
558 /* If RBE is already asserted when RWP advances then
559 * it's safe to clear RBE after processing this packet.
561 rbe = rbe || SONIC_READ(SONIC_ISR) & SONIC_INT_RBE;
562 sonic_update_rra(dev, lp, addr, new_laddr);
565 * give back the descriptor
567 sonic_rda_put(dev, entry, SONIC_RD_STATUS, 0);
568 sonic_rda_put(dev, entry, SONIC_RD_IN_USE, 1);
571 entry = (entry + 1) & SONIC_RDS_MASK;
576 if (prev_entry != lp->eol_rx) {
577 /* Advance the EOL flag to put descriptors back into service */
578 sonic_rda_put(dev, prev_entry, SONIC_RD_LINK, SONIC_EOL |
579 sonic_rda_get(dev, prev_entry, SONIC_RD_LINK));
580 sonic_rda_put(dev, lp->eol_rx, SONIC_RD_LINK, ~SONIC_EOL &
581 sonic_rda_get(dev, lp->eol_rx, SONIC_RD_LINK));
582 lp->eol_rx = prev_entry;
586 SONIC_WRITE(SONIC_ISR, SONIC_INT_RBE);
588 * If any worth-while packets have been received, netif_rx()
589 * has done a mark_bh(NET_BH) for us and will work on them
590 * when we get to the bottom-half routine.
596 * Get the current statistics.
597 * This may be called with the device open or closed.
599 static struct net_device_stats *sonic_get_stats(struct net_device *dev)
601 struct sonic_local *lp = netdev_priv(dev);
603 /* read the tally counter from the SONIC and reset them */
604 lp->stats.rx_crc_errors += SONIC_READ(SONIC_CRCT);
605 SONIC_WRITE(SONIC_CRCT, 0xffff);
606 lp->stats.rx_frame_errors += SONIC_READ(SONIC_FAET);
607 SONIC_WRITE(SONIC_FAET, 0xffff);
608 lp->stats.rx_missed_errors += SONIC_READ(SONIC_MPT);
609 SONIC_WRITE(SONIC_MPT, 0xffff);
616 * Set or clear the multicast filter for this adaptor.
618 static void sonic_multicast_list(struct net_device *dev)
620 struct sonic_local *lp = netdev_priv(dev);
622 struct netdev_hw_addr *ha;
626 rcr = SONIC_READ(SONIC_RCR) & ~(SONIC_RCR_PRO | SONIC_RCR_AMC);
627 rcr |= SONIC_RCR_BRD; /* accept broadcast packets */
629 if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
630 rcr |= SONIC_RCR_PRO;
632 if ((dev->flags & IFF_ALLMULTI) ||
633 (netdev_mc_count(dev) > 15)) {
634 rcr |= SONIC_RCR_AMC;
638 netif_dbg(lp, ifup, dev, "%s: mc_count %d\n", __func__,
639 netdev_mc_count(dev));
640 sonic_set_cam_enable(dev, 1); /* always enable our own address */
642 netdev_for_each_mc_addr(ha, dev) {
644 sonic_cda_put(dev, i, SONIC_CD_CAP0, addr[1] << 8 | addr[0]);
645 sonic_cda_put(dev, i, SONIC_CD_CAP1, addr[3] << 8 | addr[2]);
646 sonic_cda_put(dev, i, SONIC_CD_CAP2, addr[5] << 8 | addr[4]);
647 sonic_set_cam_enable(dev, sonic_get_cam_enable(dev) | (1 << i));
650 SONIC_WRITE(SONIC_CDC, 16);
651 SONIC_WRITE(SONIC_CDP, lp->cda_laddr & 0xffff);
653 /* LCAM and TXP commands can't be used simultaneously */
654 spin_lock_irqsave(&lp->lock, flags);
655 sonic_quiesce(dev, SONIC_CR_TXP);
656 SONIC_WRITE(SONIC_CMD, SONIC_CR_LCAM);
657 sonic_quiesce(dev, SONIC_CR_LCAM);
658 spin_unlock_irqrestore(&lp->lock, flags);
662 netif_dbg(lp, ifup, dev, "%s: setting RCR=%x\n", __func__, rcr);
664 SONIC_WRITE(SONIC_RCR, rcr);
669 * Initialize the SONIC ethernet controller.
671 static int sonic_init(struct net_device *dev)
673 struct sonic_local *lp = netdev_priv(dev);
677 * put the Sonic into software-reset mode and
678 * disable all interrupts
680 SONIC_WRITE(SONIC_IMR, 0);
681 SONIC_WRITE(SONIC_ISR, 0x7fff);
682 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
684 /* While in reset mode, clear CAM Enable register */
685 SONIC_WRITE(SONIC_CE, 0);
688 * clear software reset flag, disable receiver, clear and
689 * enable interrupts, then completely initialize the SONIC
691 SONIC_WRITE(SONIC_CMD, 0);
692 SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS | SONIC_CR_STP);
693 sonic_quiesce(dev, SONIC_CR_ALL);
696 * initialize the receive resource area
698 netif_dbg(lp, ifup, dev, "%s: initialize receive resource area\n",
701 for (i = 0; i < SONIC_NUM_RRS; i++) {
702 u16 bufadr_l = (unsigned long)lp->rx_laddr[i] & 0xffff;
703 u16 bufadr_h = (unsigned long)lp->rx_laddr[i] >> 16;
704 sonic_rra_put(dev, i, SONIC_RR_BUFADR_L, bufadr_l);
705 sonic_rra_put(dev, i, SONIC_RR_BUFADR_H, bufadr_h);
706 sonic_rra_put(dev, i, SONIC_RR_BUFSIZE_L, SONIC_RBSIZE >> 1);
707 sonic_rra_put(dev, i, SONIC_RR_BUFSIZE_H, 0);
710 /* initialize all RRA registers */
711 SONIC_WRITE(SONIC_RSA, sonic_rr_addr(dev, 0));
712 SONIC_WRITE(SONIC_REA, sonic_rr_addr(dev, SONIC_NUM_RRS));
713 SONIC_WRITE(SONIC_RRP, sonic_rr_addr(dev, 0));
714 SONIC_WRITE(SONIC_RWP, sonic_rr_addr(dev, SONIC_NUM_RRS - 1));
715 SONIC_WRITE(SONIC_URRA, lp->rra_laddr >> 16);
716 SONIC_WRITE(SONIC_EOBC, (SONIC_RBSIZE >> 1) - (lp->dma_bitmode ? 2 : 1));
718 /* load the resource pointers */
719 netif_dbg(lp, ifup, dev, "%s: issuing RRRA command\n", __func__);
721 SONIC_WRITE(SONIC_CMD, SONIC_CR_RRRA);
722 sonic_quiesce(dev, SONIC_CR_RRRA);
725 * Initialize the receive descriptors so that they
726 * become a circular linked list, ie. let the last
727 * descriptor point to the first again.
729 netif_dbg(lp, ifup, dev, "%s: initialize receive descriptors\n",
732 for (i=0; i<SONIC_NUM_RDS; i++) {
733 sonic_rda_put(dev, i, SONIC_RD_STATUS, 0);
734 sonic_rda_put(dev, i, SONIC_RD_PKTLEN, 0);
735 sonic_rda_put(dev, i, SONIC_RD_PKTPTR_L, 0);
736 sonic_rda_put(dev, i, SONIC_RD_PKTPTR_H, 0);
737 sonic_rda_put(dev, i, SONIC_RD_SEQNO, 0);
738 sonic_rda_put(dev, i, SONIC_RD_IN_USE, 1);
739 sonic_rda_put(dev, i, SONIC_RD_LINK,
741 ((i+1) * SIZEOF_SONIC_RD * SONIC_BUS_SCALE(lp->dma_bitmode)));
743 /* fix last descriptor */
744 sonic_rda_put(dev, SONIC_NUM_RDS - 1, SONIC_RD_LINK,
745 (lp->rda_laddr & 0xffff) | SONIC_EOL);
746 lp->eol_rx = SONIC_NUM_RDS - 1;
748 SONIC_WRITE(SONIC_URDA, lp->rda_laddr >> 16);
749 SONIC_WRITE(SONIC_CRDA, lp->rda_laddr & 0xffff);
752 * initialize transmit descriptors
754 netif_dbg(lp, ifup, dev, "%s: initialize transmit descriptors\n",
757 for (i = 0; i < SONIC_NUM_TDS; i++) {
758 sonic_tda_put(dev, i, SONIC_TD_STATUS, 0);
759 sonic_tda_put(dev, i, SONIC_TD_CONFIG, 0);
760 sonic_tda_put(dev, i, SONIC_TD_PKTSIZE, 0);
761 sonic_tda_put(dev, i, SONIC_TD_FRAG_COUNT, 0);
762 sonic_tda_put(dev, i, SONIC_TD_LINK,
763 (lp->tda_laddr & 0xffff) +
764 (i + 1) * SIZEOF_SONIC_TD * SONIC_BUS_SCALE(lp->dma_bitmode));
765 lp->tx_skb[i] = NULL;
767 /* fix last descriptor */
768 sonic_tda_put(dev, SONIC_NUM_TDS - 1, SONIC_TD_LINK,
769 (lp->tda_laddr & 0xffff));
771 SONIC_WRITE(SONIC_UTDA, lp->tda_laddr >> 16);
772 SONIC_WRITE(SONIC_CTDA, lp->tda_laddr & 0xffff);
773 lp->cur_tx = lp->next_tx = 0;
774 lp->eol_tx = SONIC_NUM_TDS - 1;
777 * put our own address to CAM desc[0]
779 sonic_cda_put(dev, 0, SONIC_CD_CAP0, dev->dev_addr[1] << 8 | dev->dev_addr[0]);
780 sonic_cda_put(dev, 0, SONIC_CD_CAP1, dev->dev_addr[3] << 8 | dev->dev_addr[2]);
781 sonic_cda_put(dev, 0, SONIC_CD_CAP2, dev->dev_addr[5] << 8 | dev->dev_addr[4]);
782 sonic_set_cam_enable(dev, 1);
784 for (i = 0; i < 16; i++)
785 sonic_cda_put(dev, i, SONIC_CD_ENTRY_POINTER, i);
788 * initialize CAM registers
790 SONIC_WRITE(SONIC_CDP, lp->cda_laddr & 0xffff);
791 SONIC_WRITE(SONIC_CDC, 16);
796 SONIC_WRITE(SONIC_CMD, SONIC_CR_LCAM);
797 sonic_quiesce(dev, SONIC_CR_LCAM);
800 * enable receiver, disable loopback
801 * and enable all interrupts
803 SONIC_WRITE(SONIC_RCR, SONIC_RCR_DEFAULT);
804 SONIC_WRITE(SONIC_TCR, SONIC_TCR_DEFAULT);
805 SONIC_WRITE(SONIC_ISR, 0x7fff);
806 SONIC_WRITE(SONIC_IMR, SONIC_IMR_DEFAULT);
807 SONIC_WRITE(SONIC_CMD, SONIC_CR_RXEN);
809 netif_dbg(lp, ifup, dev, "%s: new status=%x\n", __func__,
810 SONIC_READ(SONIC_CMD));
815 MODULE_LICENSE("GPL");