2 * Ethernet driver for Motorola MPC8260.
3 * Copyright (c) 1999 Dan Malek (dmalek@jlc.net)
4 * Copyright (c) 2000 MontaVista Software Inc. (source@mvista.com)
7 * I copied this from the 8xx CPM Ethernet driver, so follow the
8 * credits back through that.
10 * This version of the driver is somewhat selectable for the different
11 * processor/board combinations. It works for the boards I know about
12 * now, and should be easily modified to include others. Some of the
13 * configuration information is contained in <asm/commproc.h> and the
16 * Buffer descriptors are kept in the CPM dual port RAM, and the frame
17 * buffers are in the host memory.
19 * Right now, I am very watseful with the buffers. I allocate memory
20 * pages and then divide them into 2K frame buffers. This way I know I
21 * have buffers large enough to hold one frame within one buffer descriptor.
22 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
23 * will be much more memory efficient and will easily handle lots of
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/string.h>
30 #include <linux/ptrace.h>
31 #include <linux/errno.h>
32 #include <linux/ioport.h>
33 #include <linux/slab.h>
34 #include <linux/interrupt.h>
35 #include <linux/pci.h>
36 #include <linux/init.h>
37 #include <linux/delay.h>
38 #include <linux/netdevice.h>
39 #include <linux/etherdevice.h>
40 #include <linux/skbuff.h>
41 #include <linux/spinlock.h>
42 #include <linux/bitops.h>
44 #include <asm/immap_cpm2.h>
45 #include <asm/pgtable.h>
46 #include <asm/mpc8260.h>
47 #include <asm/uaccess.h>
54 * The MPC8260 CPM performs the Ethernet processing on an SCC. It can use
55 * an aribtrary number of buffers on byte boundaries, but must have at
56 * least two receive buffers to prevent constant overrun conditions.
58 * The buffer descriptors are allocated from the CPM dual port memory
59 * with the data buffers allocated from host memory, just like all other
60 * serial communication protocols. The host memory buffers are allocated
61 * from the free page pool, and then divided into smaller receive and
62 * transmit buffers. The size of the buffers should be a power of two,
63 * since that nicely divides the page. This creates a ring buffer
64 * structure similar to the LANCE and other controllers.
66 * Like the LANCE driver:
67 * The driver runs as two independent, single-threaded flows of control. One
68 * is the send-packet routine, which enforces single-threaded use by the
69 * cep->tx_busy flag. The other thread is the interrupt handler, which is
70 * single threaded by the hardware and other software.
73 /* The transmitter timeout
75 #define TX_TIMEOUT (2*HZ)
77 /* The number of Tx and Rx buffers. These are allocated from the page
78 * pool. The code may assume these are power of two, so it is best
79 * to keep them that size.
80 * We don't need to allocate pages for the transmitter. We just use
81 * the skbuffer directly.
83 #define CPM_ENET_RX_PAGES 4
84 #define CPM_ENET_RX_FRSIZE 2048
85 #define CPM_ENET_RX_FRPPG (PAGE_SIZE / CPM_ENET_RX_FRSIZE)
86 #define RX_RING_SIZE (CPM_ENET_RX_FRPPG * CPM_ENET_RX_PAGES)
87 #define TX_RING_SIZE 8 /* Must be power of two */
88 #define TX_RING_MOD_MASK 7 /* for this to work */
90 /* The CPM stores dest/src/type, data, and checksum for receive packets.
92 #define PKT_MAXBUF_SIZE 1518
93 #define PKT_MINBUF_SIZE 64
94 #define PKT_MAXBLR_SIZE 1520
96 /* The CPM buffer descriptors track the ring buffers. The rx_bd_base and
97 * tx_bd_base always point to the base of the buffer descriptors. The
98 * cur_rx and cur_tx point to the currently available buffer.
99 * The dirty_tx tracks the current buffer that is being sent by the
100 * controller. The cur_tx and dirty_tx are equal under both completely
101 * empty and completely full conditions. The empty/ready indicator in
102 * the buffer descriptor determines the actual condition.
104 struct scc_enet_private {
105 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
106 struct sk_buff* tx_skbuff[TX_RING_SIZE];
110 /* CPM dual port RAM relative addresses.
112 cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
114 cbd_t *cur_rx, *cur_tx; /* The next free ring entry */
115 cbd_t *dirty_tx; /* The ring entries to be free()ed. */
117 struct net_device_stats stats;
122 static int scc_enet_open(struct net_device *dev);
123 static int scc_enet_start_xmit(struct sk_buff *skb, struct net_device *dev);
124 static int scc_enet_rx(struct net_device *dev);
125 static irqreturn_t scc_enet_interrupt(int irq, void *dev_id);
126 static int scc_enet_close(struct net_device *dev);
127 static struct net_device_stats *scc_enet_get_stats(struct net_device *dev);
128 static void set_multicast_list(struct net_device *dev);
130 /* These will be configurable for the SCC choice.
132 #define CPM_ENET_BLOCK CPM_CR_SCC1_SBLOCK
133 #define CPM_ENET_PAGE CPM_CR_SCC1_PAGE
134 #define PROFF_ENET PROFF_SCC1
136 #define SIU_INT_ENET SIU_INT_SCC1
138 /* These are both board and SCC dependent....
140 #define PD_ENET_RXD ((uint)0x00000001)
141 #define PD_ENET_TXD ((uint)0x00000002)
142 #define PD_ENET_TENA ((uint)0x00000004)
143 #define PC_ENET_RENA ((uint)0x00020000)
144 #define PC_ENET_CLSN ((uint)0x00000004)
145 #define PC_ENET_TXCLK ((uint)0x00000800)
146 #define PC_ENET_RXCLK ((uint)0x00000400)
147 #define CMX_CLK_ROUTE ((uint)0x25000000)
148 #define CMX_CLK_MASK ((uint)0xff000000)
150 /* Specific to a board.
152 #define PC_EST8260_ENET_LOOPBACK ((uint)0x80000000)
153 #define PC_EST8260_ENET_SQE ((uint)0x40000000)
154 #define PC_EST8260_ENET_NOTFD ((uint)0x20000000)
157 scc_enet_open(struct net_device *dev)
160 /* I should reset the ring buffers here, but I don't yet know
161 * a simple way to do that.
163 netif_start_queue(dev);
164 return 0; /* Always succeed */
168 scc_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
170 struct scc_enet_private *cep = (struct scc_enet_private *)dev->priv;
174 /* Fill in a Tx ring entry */
177 #ifndef final_version
178 if (bdp->cbd_sc & BD_ENET_TX_READY) {
179 /* Ooops. All transmit buffers are full. Bail out.
180 * This should not happen, since cep->tx_full should be set.
182 printk("%s: tx queue full!.\n", dev->name);
187 /* Clear all of the status flags.
189 bdp->cbd_sc &= ~BD_ENET_TX_STATS;
191 /* If the frame is short, tell CPM to pad it.
193 if (skb->len <= ETH_ZLEN)
194 bdp->cbd_sc |= BD_ENET_TX_PAD;
196 bdp->cbd_sc &= ~BD_ENET_TX_PAD;
198 /* Set buffer length and buffer pointer.
200 bdp->cbd_datlen = skb->len;
201 bdp->cbd_bufaddr = __pa(skb->data);
205 cep->tx_skbuff[cep->skb_cur] = skb;
207 cep->stats.tx_bytes += skb->len;
208 cep->skb_cur = (cep->skb_cur+1) & TX_RING_MOD_MASK;
210 spin_lock_irq(&cep->lock);
212 /* Send it on its way. Tell CPM its ready, interrupt when done,
213 * its the last BD of the frame, and to put the CRC on the end.
215 bdp->cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_INTR | BD_ENET_TX_LAST | BD_ENET_TX_TC);
217 dev->trans_start = jiffies;
219 /* If this was the last BD in the ring, start at the beginning again.
221 if (bdp->cbd_sc & BD_ENET_TX_WRAP)
222 bdp = cep->tx_bd_base;
226 if (bdp->cbd_sc & BD_ENET_TX_READY) {
227 netif_stop_queue(dev);
231 cep->cur_tx = (cbd_t *)bdp;
233 spin_unlock_irq(&cep->lock);
239 scc_enet_timeout(struct net_device *dev)
241 struct scc_enet_private *cep = (struct scc_enet_private *)dev->priv;
243 printk("%s: transmit timed out.\n", dev->name);
244 cep->stats.tx_errors++;
245 #ifndef final_version
249 printk(" Ring data dump: cur_tx %p%s cur_rx %p.\n",
250 cep->cur_tx, cep->tx_full ? " (full)" : "",
252 bdp = cep->tx_bd_base;
253 printk(" Tx @base %p :\n", bdp);
254 for (i = 0 ; i < TX_RING_SIZE; i++, bdp++)
255 printk("%04x %04x %08x\n",
259 bdp = cep->rx_bd_base;
260 printk(" Rx @base %p :\n", bdp);
261 for (i = 0 ; i < RX_RING_SIZE; i++, bdp++)
262 printk("%04x %04x %08x\n",
269 netif_wake_queue(dev);
272 /* The interrupt handler.
273 * This is called from the CPM handler, not the MPC core interrupt.
276 scc_enet_interrupt(int irq, void * dev_id)
278 struct net_device *dev = dev_id;
279 volatile struct scc_enet_private *cep;
284 cep = (struct scc_enet_private *)dev->priv;
286 /* Get the interrupt events that caused us to be here.
288 int_events = cep->sccp->scc_scce;
289 cep->sccp->scc_scce = int_events;
292 /* Handle receive event in its own function.
294 if (int_events & SCCE_ENET_RXF)
297 /* Check for a transmit error. The manual is a little unclear
298 * about this, so the debug code until I get it figured out. It
299 * appears that if TXE is set, then TXB is not set. However,
300 * if carrier sense is lost during frame transmission, the TXE
301 * bit is set, "and continues the buffer transmission normally."
302 * I don't know if "normally" implies TXB is set when the buffer
303 * descriptor is closed.....trial and error :-).
306 /* Transmit OK, or non-fatal error. Update the buffer descriptors.
308 if (int_events & (SCCE_ENET_TXE | SCCE_ENET_TXB)) {
309 spin_lock(&cep->lock);
311 while ((bdp->cbd_sc&BD_ENET_TX_READY)==0) {
312 if ((bdp==cep->cur_tx) && (cep->tx_full == 0))
315 if (bdp->cbd_sc & BD_ENET_TX_HB) /* No heartbeat */
316 cep->stats.tx_heartbeat_errors++;
317 if (bdp->cbd_sc & BD_ENET_TX_LC) /* Late collision */
318 cep->stats.tx_window_errors++;
319 if (bdp->cbd_sc & BD_ENET_TX_RL) /* Retrans limit */
320 cep->stats.tx_aborted_errors++;
321 if (bdp->cbd_sc & BD_ENET_TX_UN) /* Underrun */
322 cep->stats.tx_fifo_errors++;
323 if (bdp->cbd_sc & BD_ENET_TX_CSL) /* Carrier lost */
324 cep->stats.tx_carrier_errors++;
327 /* No heartbeat or Lost carrier are not really bad errors.
328 * The others require a restart transmit command.
331 (BD_ENET_TX_LC | BD_ENET_TX_RL | BD_ENET_TX_UN)) {
333 cep->stats.tx_errors++;
336 cep->stats.tx_packets++;
338 /* Deferred means some collisions occurred during transmit,
339 * but we eventually sent the packet OK.
341 if (bdp->cbd_sc & BD_ENET_TX_DEF)
342 cep->stats.collisions++;
344 /* Free the sk buffer associated with this last transmit.
346 dev_kfree_skb_irq(cep->tx_skbuff[cep->skb_dirty]);
347 cep->skb_dirty = (cep->skb_dirty + 1) & TX_RING_MOD_MASK;
349 /* Update pointer to next buffer descriptor to be transmitted.
351 if (bdp->cbd_sc & BD_ENET_TX_WRAP)
352 bdp = cep->tx_bd_base;
356 /* I don't know if we can be held off from processing these
357 * interrupts for more than one frame time. I really hope
358 * not. In such a case, we would now want to check the
359 * currently available BD (cur_tx) and determine if any
360 * buffers between the dirty_tx and cur_tx have also been
361 * sent. We would want to process anything in between that
362 * does not have BD_ENET_TX_READY set.
365 /* Since we have freed up a buffer, the ring is no longer
370 if (netif_queue_stopped(dev)) {
371 netif_wake_queue(dev);
375 cep->dirty_tx = (cbd_t *)bdp;
379 volatile cpm_cpm2_t *cp;
381 /* Some transmit errors cause the transmitter to shut
382 * down. We now issue a restart transmit. Since the
383 * errors close the BD and update the pointers, the restart
384 * _should_ pick up without having to reset any of our
390 mk_cr_cmd(CPM_ENET_PAGE, CPM_ENET_BLOCK, 0,
391 CPM_CR_RESTART_TX) | CPM_CR_FLG;
392 while (cp->cp_cpcr & CPM_CR_FLG);
394 spin_unlock(&cep->lock);
397 /* Check for receive busy, i.e. packets coming but no place to
398 * put them. This "can't happen" because the receive interrupt
399 * is tossing previous frames.
401 if (int_events & SCCE_ENET_BSY) {
402 cep->stats.rx_dropped++;
403 printk("SCC ENET: BSY can't happen.\n");
409 /* During a receive, the cur_rx points to the current incoming buffer.
410 * When we update through the ring, if the next incoming buffer has
411 * not been given to the system, we just set the empty indicator,
412 * effectively tossing the packet.
415 scc_enet_rx(struct net_device *dev)
417 struct scc_enet_private *cep;
422 cep = (struct scc_enet_private *)dev->priv;
424 /* First, grab all of the stats for the incoming packet.
425 * These get messed up if we get called due to a busy condition.
430 if (bdp->cbd_sc & BD_ENET_RX_EMPTY)
433 #ifndef final_version
434 /* Since we have allocated space to hold a complete frame, both
435 * the first and last indicators should be set.
437 if ((bdp->cbd_sc & (BD_ENET_RX_FIRST | BD_ENET_RX_LAST)) !=
438 (BD_ENET_RX_FIRST | BD_ENET_RX_LAST))
439 printk("CPM ENET: rcv is not first+last\n");
442 /* Frame too long or too short.
444 if (bdp->cbd_sc & (BD_ENET_RX_LG | BD_ENET_RX_SH))
445 cep->stats.rx_length_errors++;
446 if (bdp->cbd_sc & BD_ENET_RX_NO) /* Frame alignment */
447 cep->stats.rx_frame_errors++;
448 if (bdp->cbd_sc & BD_ENET_RX_CR) /* CRC Error */
449 cep->stats.rx_crc_errors++;
450 if (bdp->cbd_sc & BD_ENET_RX_OV) /* FIFO overrun */
451 cep->stats.rx_crc_errors++;
453 /* Report late collisions as a frame error.
454 * On this error, the BD is closed, but we don't know what we
455 * have in the buffer. So, just drop this frame on the floor.
457 if (bdp->cbd_sc & BD_ENET_RX_CL) {
458 cep->stats.rx_frame_errors++;
462 /* Process the incoming frame.
464 cep->stats.rx_packets++;
465 pkt_len = bdp->cbd_datlen;
466 cep->stats.rx_bytes += pkt_len;
468 /* This does 16 byte alignment, much more than we need.
469 * The packet length includes FCS, but we don't want to
470 * include that when passing upstream as it messes up
471 * bridging applications.
473 skb = dev_alloc_skb(pkt_len-4);
476 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
477 cep->stats.rx_dropped++;
480 skb_put(skb,pkt_len-4); /* Make room */
481 eth_copy_and_sum(skb,
482 (unsigned char *)__va(bdp->cbd_bufaddr),
484 skb->protocol=eth_type_trans(skb,dev);
489 /* Clear the status flags for this buffer.
491 bdp->cbd_sc &= ~BD_ENET_RX_STATS;
493 /* Mark the buffer empty.
495 bdp->cbd_sc |= BD_ENET_RX_EMPTY;
497 /* Update BD pointer to next entry.
499 if (bdp->cbd_sc & BD_ENET_RX_WRAP)
500 bdp = cep->rx_bd_base;
505 cep->cur_rx = (cbd_t *)bdp;
511 scc_enet_close(struct net_device *dev)
513 /* Don't know what to do yet.
515 netif_stop_queue(dev);
520 static struct net_device_stats *scc_enet_get_stats(struct net_device *dev)
522 struct scc_enet_private *cep = (struct scc_enet_private *)dev->priv;
527 /* Set or clear the multicast filter for this adaptor.
528 * Skeleton taken from sunlance driver.
529 * The CPM Ethernet implementation allows Multicast as well as individual
530 * MAC address filtering. Some of the drivers check to make sure it is
531 * a group multicast address, and discard those that are not. I guess I
532 * will do the same for now, but just remove the test if you want
533 * individual filtering as well (do the upper net layers want or support
534 * this kind of feature?).
537 static void set_multicast_list(struct net_device *dev)
539 struct scc_enet_private *cep;
540 struct dev_mc_list *dmi;
541 u_char *mcptr, *tdptr;
542 volatile scc_enet_t *ep;
544 cep = (struct scc_enet_private *)dev->priv;
546 /* Get pointer to SCC area in parameter RAM.
548 ep = (scc_enet_t *)dev->base_addr;
550 if (dev->flags&IFF_PROMISC) {
552 /* Log any net taps. */
553 printk("%s: Promiscuous mode enabled.\n", dev->name);
554 cep->sccp->scc_psmr |= SCC_PSMR_PRO;
557 cep->sccp->scc_psmr &= ~SCC_PSMR_PRO;
559 if (dev->flags & IFF_ALLMULTI) {
560 /* Catch all multicast addresses, so set the
563 ep->sen_gaddr1 = 0xffff;
564 ep->sen_gaddr2 = 0xffff;
565 ep->sen_gaddr3 = 0xffff;
566 ep->sen_gaddr4 = 0xffff;
569 /* Clear filter and add the addresses in the list.
578 for (i=0; i<dev->mc_count; i++) {
580 /* Only support group multicast for now.
582 if (!(dmi->dmi_addr[0] & 1))
585 /* The address in dmi_addr is LSB first,
586 * and taddr is MSB first. We have to
587 * copy bytes MSB first from dmi_addr.
589 mcptr = (u_char *)dmi->dmi_addr + 5;
590 tdptr = (u_char *)&ep->sen_taddrh;
594 /* Ask CPM to run CRC and set bit in
597 cpmp->cp_cpcr = mk_cr_cmd(CPM_ENET_PAGE,
599 CPM_CR_SET_GADDR) | CPM_CR_FLG;
600 /* this delay is necessary here -- Cort */
602 while (cpmp->cp_cpcr & CPM_CR_FLG);
608 /* Initialize the CPM Ethernet on SCC.
610 static int __init scc_enet_init(void)
612 struct net_device *dev;
613 struct scc_enet_private *cep;
617 unsigned long mem_addr;
620 volatile cpm_cpm2_t *cp;
621 volatile scc_t *sccp;
622 volatile scc_enet_t *ep;
623 volatile cpm2_map_t *immap;
624 volatile iop_cpm2_t *io;
626 cp = cpmp; /* Get pointer to Communication Processor */
628 immap = (cpm2_map_t *)CPM_MAP_ADDR; /* and to internal registers */
629 io = &immap->im_ioport;
633 /* Create an Ethernet device instance.
635 dev = alloc_etherdev(sizeof(*cep));
640 spin_lock_init(&cep->lock);
642 /* Get pointer to SCC area in parameter RAM.
644 ep = (scc_enet_t *)(&immap->im_dprambase[PROFF_ENET]);
646 /* And another to the SCC register area.
648 sccp = (volatile scc_t *)(&immap->im_scc[SCC_ENET]);
649 cep->sccp = (scc_t *)sccp; /* Keep the pointer handy */
651 /* Disable receive and transmit in case someone left it running.
653 sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
655 /* Configure port C and D pins for SCC Ethernet. This
656 * won't work for all SCC possibilities....it will be
657 * board/port specific.
660 (PC_ENET_RENA | PC_ENET_CLSN | PC_ENET_TXCLK | PC_ENET_RXCLK);
662 ~(PC_ENET_RENA | PC_ENET_CLSN | PC_ENET_TXCLK | PC_ENET_RXCLK);
664 ~(PC_ENET_RENA | PC_ENET_TXCLK | PC_ENET_RXCLK);
665 io->iop_psorc |= PC_ENET_CLSN;
667 io->iop_ppard |= (PD_ENET_RXD | PD_ENET_TXD | PD_ENET_TENA);
668 io->iop_pdird |= (PD_ENET_TXD | PD_ENET_TENA);
669 io->iop_pdird &= ~PD_ENET_RXD;
670 io->iop_psord |= PD_ENET_TXD;
671 io->iop_psord &= ~(PD_ENET_RXD | PD_ENET_TENA);
673 /* Configure Serial Interface clock routing.
674 * First, clear all SCC bits to zero, then set the ones we want.
676 immap->im_cpmux.cmx_scr &= ~CMX_CLK_MASK;
677 immap->im_cpmux.cmx_scr |= CMX_CLK_ROUTE;
679 /* Allocate space for the buffer descriptors in the DP ram.
680 * These are relative offsets in the DP ram address space.
681 * Initialize base addresses for the buffer descriptors.
683 dp_offset = cpm_dpalloc(sizeof(cbd_t) * RX_RING_SIZE, 8);
684 ep->sen_genscc.scc_rbase = dp_offset;
685 cep->rx_bd_base = (cbd_t *)cpm_dpram_addr(dp_offset);
687 dp_offset = cpm_dpalloc(sizeof(cbd_t) * TX_RING_SIZE, 8);
688 ep->sen_genscc.scc_tbase = dp_offset;
689 cep->tx_bd_base = (cbd_t *)cpm_dpram_addr(dp_offset);
691 cep->dirty_tx = cep->cur_tx = cep->tx_bd_base;
692 cep->cur_rx = cep->rx_bd_base;
694 ep->sen_genscc.scc_rfcr = CPMFCR_GBL | CPMFCR_EB;
695 ep->sen_genscc.scc_tfcr = CPMFCR_GBL | CPMFCR_EB;
697 /* Set maximum bytes per receive buffer.
698 * This appears to be an Ethernet frame size, not the buffer
699 * fragment size. It must be a multiple of four.
701 ep->sen_genscc.scc_mrblr = PKT_MAXBLR_SIZE;
703 /* Set CRC preset and mask.
705 ep->sen_cpres = 0xffffffff;
706 ep->sen_cmask = 0xdebb20e3;
708 ep->sen_crcec = 0; /* CRC Error counter */
709 ep->sen_alec = 0; /* alignment error counter */
710 ep->sen_disfc = 0; /* discard frame counter */
712 ep->sen_pads = 0x8888; /* Tx short frame pad character */
713 ep->sen_retlim = 15; /* Retry limit threshold */
715 ep->sen_maxflr = PKT_MAXBUF_SIZE; /* maximum frame length register */
716 ep->sen_minflr = PKT_MINBUF_SIZE; /* minimum frame length register */
718 ep->sen_maxd1 = PKT_MAXBLR_SIZE; /* maximum DMA1 length */
719 ep->sen_maxd2 = PKT_MAXBLR_SIZE; /* maximum DMA2 length */
721 /* Clear hash tables.
732 /* Set Ethernet station address.
734 * This is supplied in the board information structure, so we
735 * copy that into the controller.
737 eap = (unsigned char *)&(ep->sen_paddrh);
739 *eap++ = dev->dev_addr[i] = bd->bi_enetaddr[i];
741 ep->sen_pper = 0; /* 'cause the book says so */
742 ep->sen_taddrl = 0; /* temp address (LSB) */
744 ep->sen_taddrh = 0; /* temp address (MSB) */
746 /* Now allocate the host memory pages and initialize the
747 * buffer descriptors.
749 bdp = cep->tx_bd_base;
750 for (i=0; i<TX_RING_SIZE; i++) {
752 /* Initialize the BD for every fragment in the page.
755 bdp->cbd_bufaddr = 0;
759 /* Set the last buffer to wrap.
762 bdp->cbd_sc |= BD_SC_WRAP;
764 bdp = cep->rx_bd_base;
765 for (i=0; i<CPM_ENET_RX_PAGES; i++) {
769 mem_addr = __get_free_page(GFP_KERNEL);
770 /* BUG: no check for failure */
772 /* Initialize the BD for every fragment in the page.
774 for (j=0; j<CPM_ENET_RX_FRPPG; j++) {
775 bdp->cbd_sc = BD_ENET_RX_EMPTY | BD_ENET_RX_INTR;
776 bdp->cbd_bufaddr = __pa(mem_addr);
777 mem_addr += CPM_ENET_RX_FRSIZE;
782 /* Set the last buffer to wrap.
785 bdp->cbd_sc |= BD_SC_WRAP;
787 /* Let's re-initialize the channel now. We have to do it later
788 * than the manual describes because we have just now finished
789 * the BD initialization.
791 cpmp->cp_cpcr = mk_cr_cmd(CPM_ENET_PAGE, CPM_ENET_BLOCK, 0,
792 CPM_CR_INIT_TRX) | CPM_CR_FLG;
793 while (cp->cp_cpcr & CPM_CR_FLG);
795 cep->skb_cur = cep->skb_dirty = 0;
797 sccp->scc_scce = 0xffff; /* Clear any pending events */
799 /* Enable interrupts for transmit error, complete frame
800 * received, and any transmit buffer we have also set the
803 sccp->scc_sccm = (SCCE_ENET_TXE | SCCE_ENET_RXF | SCCE_ENET_TXB);
805 /* Install our interrupt handler.
807 request_irq(SIU_INT_ENET, scc_enet_interrupt, 0, "enet", dev);
808 /* BUG: no check for failure */
810 /* Set GSMR_H to enable all normal operating modes.
811 * Set GSMR_L to enable Ethernet to MC68160.
814 sccp->scc_gsmrl = (SCC_GSMRL_TCI | SCC_GSMRL_TPL_48 | SCC_GSMRL_TPP_10 | SCC_GSMRL_MODE_ENET);
816 /* Set sync/delimiters.
818 sccp->scc_dsr = 0xd555;
820 /* Set processing mode. Use Ethernet CRC, catch broadcast, and
821 * start frame search 22 bit times after RENA.
823 sccp->scc_psmr = (SCC_PSMR_ENCRC | SCC_PSMR_NIB22);
825 /* It is now OK to enable the Ethernet transmitter.
826 * Unfortunately, there are board implementation differences here.
828 io->iop_pparc &= ~(PC_EST8260_ENET_LOOPBACK |
829 PC_EST8260_ENET_SQE | PC_EST8260_ENET_NOTFD);
830 io->iop_psorc &= ~(PC_EST8260_ENET_LOOPBACK |
831 PC_EST8260_ENET_SQE | PC_EST8260_ENET_NOTFD);
832 io->iop_pdirc |= (PC_EST8260_ENET_LOOPBACK |
833 PC_EST8260_ENET_SQE | PC_EST8260_ENET_NOTFD);
834 io->iop_pdatc &= ~(PC_EST8260_ENET_LOOPBACK | PC_EST8260_ENET_SQE);
835 io->iop_pdatc |= PC_EST8260_ENET_NOTFD;
837 dev->base_addr = (unsigned long)ep;
839 /* The CPM Ethernet specific entries in the device structure. */
840 dev->open = scc_enet_open;
841 dev->hard_start_xmit = scc_enet_start_xmit;
842 dev->tx_timeout = scc_enet_timeout;
843 dev->watchdog_timeo = TX_TIMEOUT;
844 dev->stop = scc_enet_close;
845 dev->get_stats = scc_enet_get_stats;
846 dev->set_multicast_list = set_multicast_list;
848 /* And last, enable the transmit and receive processing.
850 sccp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
852 err = register_netdev(dev);
858 printk("%s: SCC ENET Version 0.1, ", dev->name);
860 printk("%02x:", dev->dev_addr[i]);
861 printk("%02x\n", dev->dev_addr[5]);
866 module_init(scc_enet_init);