2 * Ethernet driver for Motorola MPC8xx.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
5 * I copied the basic skeleton from the lance driver, because I did not
6 * know how to write the Linux driver, but I did know how the LANCE worked.
8 * This version of the driver is somewhat selectable for the different
9 * processor/board combinations. It works for the boards I know about
10 * now, and should be easily modified to include others. Some of the
11 * configuration information is contained in "commproc.h" and the
14 * Buffer descriptors are kept in the CPM dual port RAM, and the frame
15 * buffers are in the host memory.
17 * Right now, I am very watseful with the buffers. I allocate memory
18 * pages and then divide them into 2K frame buffers. This way I know I
19 * have buffers large enough to hold one frame within one buffer descriptor.
20 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
21 * will be much more memory efficient and will easily handle lots of
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/string.h>
28 #include <linux/ptrace.h>
29 #include <linux/errno.h>
30 #include <linux/ioport.h>
31 #include <linux/malloc.h>
32 #include <linux/interrupt.h>
33 #include <linux/pci.h>
34 #include <linux/init.h>
35 #include <linux/delay.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/skbuff.h>
40 #include <asm/8xx_immap.h>
41 #include <asm/pgtable.h>
42 #include <asm/mpc8xx.h>
43 #include <asm/bitops.h>
44 #include <asm/uaccess.h>
50 * The MPC8xx CPM performs the Ethernet processing on SCC1. It can use
51 * an aribtrary number of buffers on byte boundaries, but must have at
52 * least two receive buffers to prevent constant overrun conditions.
54 * The buffer descriptors are allocated from the CPM dual port memory
55 * with the data buffers allocated from host memory, just like all other
56 * serial communication protocols. The host memory buffers are allocated
57 * from the free page pool, and then divided into smaller receive and
58 * transmit buffers. The size of the buffers should be a power of two,
59 * since that nicely divides the page. This creates a ring buffer
60 * structure similar to the LANCE and other controllers.
62 * Like the LANCE driver:
63 * The driver runs as two independent, single-threaded flows of control. One
64 * is the send-packet routine, which enforces single-threaded use by the
65 * dev->tbusy flag. The other thread is the interrupt handler, which is single
66 * threaded by the hardware and other software.
68 * The send packet thread has partial control over the Tx ring and 'dev->tbusy'
69 * flag. It sets the tbusy flag whenever it's queuing a Tx packet. If the next
70 * queue slot is empty, it clears the tbusy flag when finished otherwise it sets
71 * the 'lp->tx_full' flag.
73 * The MBX has a control register external to the MPC8xx that has some
74 * control of the Ethernet interface. Control Register 1 has the
76 * bit 0 - Set to enable Ethernet transceiver
77 * bit 1 - Set to enable Ethernet internal loopback
78 * bit 2 - Set to auto select AUI or TP port
79 * bit 3 - if bit 2 is 0, set to select TP port
80 * bit 4 - Set to disable full duplex (loopback)
81 * bit 5 - Set to disable XCVR collision test
82 * bit 6, 7 - Used for RS-232 control.
84 * EPPC-Bug sets this register to 0x98 for normal Ethernet operation,
85 * so we should not have to touch it.
87 * The following I/O is used by the MBX implementation of the MPC8xx to
88 * the MC68160 transceiver. It DOES NOT exactly follow the cookbook
89 * example from the MPC860 manual.
90 * Port A, 15 - SCC1 Ethernet Rx
91 * Port A, 14 - SCC1 Ethernet Tx
92 * Port A, 6 (CLK2) - SCC1 Ethernet Tx Clk
93 * Port A, 4 (CLK4) - SCC1 Ethernet Rx Clk
94 * Port C, 15 - SCC1 Ethernet Tx Enable
95 * Port C, 11 - SCC1 Ethernet Collision
96 * Port C, 10 - SCC1 Ethernet Rx Enable
98 * The RPX-Lite (that I had :-), was the MPC850SAR. It has a control
99 * register to enable Ethernet functions in the 68160, and the Ethernet
100 * was controlled by SCC2. So, the pin I/O was like this:
101 * Port A, 13 - SCC2 Ethernet Rx
102 * Port A, 12 - SCC2 Ethernet Tx
103 * Port A, 6 (CLK2) - Ethernet Tx Clk
104 * Port A, 4 (CLK4) - Ethernet Rx Clk
105 * Port B, 18 (RTS2) - Ethernet Tx Enable
106 * Port C, 8 (CD2) - Ethernet Rx Enable
107 * Port C, 9 (CTS2) - SCC Ethernet Collision
110 /* The number of Tx and Rx buffers. These are allocated from the page
111 * pool. The code may assume these are power of two, so it is best
112 * to keep them that size.
113 * We don't need to allocate pages for the transmitter. We just use
114 * the skbuffer directly.
116 #define CPM_ENET_RX_PAGES 4
117 #define CPM_ENET_RX_FRSIZE 2048
118 #define CPM_ENET_RX_FRPPG (PAGE_SIZE / CPM_ENET_RX_FRSIZE)
119 #define RX_RING_SIZE (CPM_ENET_RX_FRPPG * CPM_ENET_RX_PAGES)
120 #define TX_RING_SIZE 8 /* Must be power of two */
121 #define TX_RING_MOD_MASK 7 /* for this to work */
123 /* The CPM stores dest/src/type, data, and checksum for receive packets.
125 #define PKT_MAXBUF_SIZE 1518
126 #define PKT_MINBUF_SIZE 64
127 #define PKT_MAXBLR_SIZE 1520
129 /* The CPM buffer descriptors track the ring buffers. The rx_bd_base and
130 * tx_bd_base always point to the base of the buffer descriptors. The
131 * cur_rx and cur_tx point to the currently available buffer.
132 * The dirty_tx tracks the current buffer that is being sent by the
133 * controller. The cur_tx and dirty_tx are equal under both completely
134 * empty and completely full conditions. The empty/ready indicator in
135 * the buffer descriptor determines the actual condition.
137 struct cpm_enet_private
{
138 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
139 struct sk_buff
* tx_skbuff
[TX_RING_SIZE
];
143 /* CPM dual port RAM relative addresses.
145 cbd_t
*rx_bd_base
; /* Address of Rx and Tx buffers. */
147 cbd_t
*cur_rx
, *cur_tx
; /* The next free ring entry */
148 cbd_t
*dirty_tx
; /* The ring entries to be free()ed. */
150 struct net_device_stats stats
;
155 static int cpm_enet_open(struct net_device
*dev
);
156 static int cpm_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
157 static int cpm_enet_rx(struct net_device
*dev
);
158 static void cpm_enet_interrupt(void *dev_id
);
159 static int cpm_enet_close(struct net_device
*dev
);
160 static struct net_device_stats
*cpm_enet_get_stats(struct net_device
*dev
);
161 static void set_multicast_list(struct net_device
*dev
);
163 /* Get this from various configuration locations (depends on board).
165 /*static ushort my_enet_addr[] = { 0x0800, 0x3e26, 0x1559 };*/
167 /* Typically, 860(T) boards use SCC1 for Ethernet, and other 8xx boards
168 * use SCC2. This is easily extended if necessary.
170 #ifdef CONFIG_SCC2_ENET
171 #define CPM_CR_ENET CPM_CR_CH_SCC2
172 #define PROFF_ENET PROFF_SCC2
173 #define SCC_ENET 1 /* Index, not number! */
174 #define CPMVEC_ENET CPMVEC_SCC2
177 #ifdef CONFIG_SCC1_ENET
178 #define CPM_CR_ENET CPM_CR_CH_SCC1
179 #define PROFF_ENET PROFF_SCC1
181 #define CPMVEC_ENET CPMVEC_SCC1
185 cpm_enet_open(struct net_device
*dev
)
188 /* I should reset the ring buffers here, but I don't yet know
189 * a simple way to do that.
196 return 0; /* Always succeed */
200 cpm_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
202 struct cpm_enet_private
*cep
= (struct cpm_enet_private
*)dev
->priv
;
206 /* Transmitter timeout, serious problems. */
208 int tickssofar
= jiffies
- dev
->trans_start
;
209 if (tickssofar
< 200)
211 printk("%s: transmit timed out.\n", dev
->name
);
212 cep
->stats
.tx_errors
++;
213 #ifndef final_version
217 printk(" Ring data dump: cur_tx %p%s cur_rx %p.\n",
218 cep
->cur_tx
, cep
->tx_full
? " (full)" : "",
220 bdp
= cep
->tx_bd_base
;
221 for (i
= 0 ; i
< TX_RING_SIZE
; i
++, bdp
++)
222 printk("%04x %04x %08x\n",
226 bdp
= cep
->rx_bd_base
;
227 for (i
= 0 ; i
< RX_RING_SIZE
; i
++, bdp
++)
228 printk("%04x %04x %08x\n",
236 dev
->trans_start
= jiffies
;
241 /* Block a timer-based transmit from overlapping. This could better be
242 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
243 if (test_and_set_bit(0, (void*)&dev
->tbusy
) != 0) {
244 printk("%s: Transmitter access conflict.\n", dev
->name
);
248 if (test_and_set_bit(0, (void*)&cep
->lock
) != 0) {
249 printk("%s: tx queue lock!.\n", dev
->name
);
250 /* don't clear dev->tbusy flag. */
254 /* Fill in a Tx ring entry */
257 #ifndef final_version
258 if (bdp
->cbd_sc
& BD_ENET_TX_READY
) {
259 /* Ooops. All transmit buffers are full. Bail out.
260 * This should not happen, since dev->tbusy should be set.
262 printk("%s: tx queue full!.\n", dev
->name
);
268 /* Clear all of the status flags.
270 bdp
->cbd_sc
&= ~BD_ENET_TX_STATS
;
272 /* If the frame is short, tell CPM to pad it.
274 if (skb
->len
<= ETH_ZLEN
)
275 bdp
->cbd_sc
|= BD_ENET_TX_PAD
;
277 bdp
->cbd_sc
&= ~BD_ENET_TX_PAD
;
279 /* Set buffer length and buffer pointer.
281 bdp
->cbd_datlen
= skb
->len
;
282 bdp
->cbd_bufaddr
= __pa(skb
->data
);
286 cep
->tx_skbuff
[cep
->skb_cur
] = skb
;
288 cep
->stats
.tx_bytes
+= skb
->len
;
289 cep
->skb_cur
= (cep
->skb_cur
+1) & TX_RING_MOD_MASK
;
291 /* Push the data cache so the CPM does not get stale memory
294 flush_dcache_range(skb
->data
, skb
->data
+ skb
->len
);
296 /* Send it on its way. Tell CPM its ready, interrupt when done,
297 * its the last BD of the frame, and to put the CRC on the end.
299 bdp
->cbd_sc
|= (BD_ENET_TX_READY
| BD_ENET_TX_INTR
| BD_ENET_TX_LAST
| BD_ENET_TX_TC
);
301 dev
->trans_start
= jiffies
;
303 /* If this was the last BD in the ring, start at the beginning again.
305 if (bdp
->cbd_sc
& BD_ENET_TX_WRAP
)
306 bdp
= cep
->tx_bd_base
;
313 if (bdp
->cbd_sc
& BD_ENET_TX_READY
)
317 restore_flags(flags
);
319 cep
->cur_tx
= (cbd_t
*)bdp
;
324 /* The interrupt handler.
325 * This is called from the CPM handler, not the MPC core interrupt.
328 cpm_enet_interrupt(void *dev_id
)
330 struct net_device
*dev
= dev_id
;
331 volatile struct cpm_enet_private
*cep
;
336 cep
= (struct cpm_enet_private
*)dev
->priv
;
338 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
342 /* Get the interrupt events that caused us to be here.
344 int_events
= cep
->sccp
->scc_scce
;
345 cep
->sccp
->scc_scce
= int_events
;
348 /* Handle receive event in its own function.
350 if (int_events
& SCCE_ENET_RXF
)
353 /* Check for a transmit error. The manual is a little unclear
354 * about this, so the debug code until I get it figured out. It
355 * appears that if TXE is set, then TXB is not set. However,
356 * if carrier sense is lost during frame transmission, the TXE
357 * bit is set, "and continues the buffer transmission normally."
358 * I don't know if "normally" implies TXB is set when the buffer
359 * descriptor is closed.....trial and error :-).
362 /* Transmit OK, or non-fatal error. Update the buffer descriptors.
364 if (int_events
& (SCCE_ENET_TXE
| SCCE_ENET_TXB
)) {
366 while ((bdp
->cbd_sc
&BD_ENET_TX_READY
)==0) {
367 if ((bdp
==cep
->cur_tx
) && (cep
->tx_full
== 0))
370 if (bdp
->cbd_sc
& BD_ENET_TX_HB
) /* No heartbeat */
371 cep
->stats
.tx_heartbeat_errors
++;
372 if (bdp
->cbd_sc
& BD_ENET_TX_LC
) /* Late collision */
373 cep
->stats
.tx_window_errors
++;
374 if (bdp
->cbd_sc
& BD_ENET_TX_RL
) /* Retrans limit */
375 cep
->stats
.tx_aborted_errors
++;
376 if (bdp
->cbd_sc
& BD_ENET_TX_UN
) /* Underrun */
377 cep
->stats
.tx_fifo_errors
++;
378 if (bdp
->cbd_sc
& BD_ENET_TX_CSL
) /* Carrier lost */
379 cep
->stats
.tx_carrier_errors
++;
382 /* No heartbeat or Lost carrier are not really bad errors.
383 * The others require a restart transmit command.
386 (BD_ENET_TX_LC
| BD_ENET_TX_RL
| BD_ENET_TX_UN
)) {
388 cep
->stats
.tx_errors
++;
391 cep
->stats
.tx_packets
++;
393 /* Deferred means some collisions occurred during transmit,
394 * but we eventually sent the packet OK.
396 if (bdp
->cbd_sc
& BD_ENET_TX_DEF
)
397 cep
->stats
.collisions
++;
399 /* Free the sk buffer associated with this last transmit.
401 dev_kfree_skb(cep
->tx_skbuff
[cep
->skb_dirty
]/*, FREE_WRITE*/);
402 cep
->skb_dirty
= (cep
->skb_dirty
+ 1) & TX_RING_MOD_MASK
;
404 /* Update pointer to next buffer descriptor to be transmitted.
406 if (bdp
->cbd_sc
& BD_ENET_TX_WRAP
)
407 bdp
= cep
->tx_bd_base
;
411 /* I don't know if we can be held off from processing these
412 * interrupts for more than one frame time. I really hope
413 * not. In such a case, we would now want to check the
414 * currently available BD (cur_tx) and determine if any
415 * buffers between the dirty_tx and cur_tx have also been
416 * sent. We would want to process anything in between that
417 * does not have BD_ENET_TX_READY set.
420 /* Since we have freed up a buffer, the ring is no longer
423 if (cep
->tx_full
&& dev
->tbusy
) {
429 cep
->dirty_tx
= (cbd_t
*)bdp
;
433 volatile cpm8xx_t
*cp
;
435 /* Some transmit errors cause the transmitter to shut
436 * down. We now issue a restart transmit. Since the
437 * errors close the BD and update the pointers, the restart
438 * _should_ pick up without having to reset any of our
443 mk_cr_cmd(CPM_CR_ENET
, CPM_CR_RESTART_TX
) | CPM_CR_FLG
;
444 while (cp
->cp_cpcr
& CPM_CR_FLG
);
448 /* Check for receive busy, i.e. packets coming but no place to
449 * put them. This "can't happen" because the receive interrupt
450 * is tossing previous frames.
452 if (int_events
& SCCE_ENET_BSY
) {
453 cep
->stats
.rx_dropped
++;
454 printk("CPM ENET: BSY can't happen.\n");
462 /* During a receive, the cur_rx points to the current incoming buffer.
463 * When we update through the ring, if the next incoming buffer has
464 * not been given to the system, we just set the empty indicator,
465 * effectively tossing the packet.
468 cpm_enet_rx(struct net_device
*dev
)
470 struct cpm_enet_private
*cep
;
475 cep
= (struct cpm_enet_private
*)dev
->priv
;
477 /* First, grab all of the stats for the incoming packet.
478 * These get messed up if we get called due to a busy condition.
483 if (bdp
->cbd_sc
& BD_ENET_RX_EMPTY
)
486 #ifndef final_version
487 /* Since we have allocated space to hold a complete frame, both
488 * the first and last indicators should be set.
490 if ((bdp
->cbd_sc
& (BD_ENET_RX_FIRST
| BD_ENET_RX_LAST
)) !=
491 (BD_ENET_RX_FIRST
| BD_ENET_RX_LAST
))
492 printk("CPM ENET: rcv is not first+last\n");
495 /* Frame too long or too short.
497 if (bdp
->cbd_sc
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
))
498 cep
->stats
.rx_length_errors
++;
499 if (bdp
->cbd_sc
& BD_ENET_RX_NO
) /* Frame alignment */
500 cep
->stats
.rx_frame_errors
++;
501 if (bdp
->cbd_sc
& BD_ENET_RX_CR
) /* CRC Error */
502 cep
->stats
.rx_crc_errors
++;
503 if (bdp
->cbd_sc
& BD_ENET_RX_OV
) /* FIFO overrun */
504 cep
->stats
.rx_crc_errors
++;
506 /* Report late collisions as a frame error.
507 * On this error, the BD is closed, but we don't know what we
508 * have in the buffer. So, just drop this frame on the floor.
510 if (bdp
->cbd_sc
& BD_ENET_RX_CL
) {
511 cep
->stats
.rx_frame_errors
++;
515 /* Process the incoming frame.
517 cep
->stats
.rx_packets
++;
518 pkt_len
= bdp
->cbd_datlen
;
519 cep
->stats
.rx_bytes
+= pkt_len
;
521 /* This does 16 byte alignment, much more than we need.
523 skb
= dev_alloc_skb(pkt_len
);
526 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
);
527 cep
->stats
.rx_dropped
++;
531 skb_put(skb
,pkt_len
); /* Make room */
532 eth_copy_and_sum(skb
,
533 (unsigned char *)__va(bdp
->cbd_bufaddr
),
535 skb
->protocol
=eth_type_trans(skb
,dev
);
540 /* Clear the status flags for this buffer.
542 bdp
->cbd_sc
&= ~BD_ENET_RX_STATS
;
544 /* Mark the buffer empty.
546 bdp
->cbd_sc
|= BD_ENET_RX_EMPTY
;
548 /* Update BD pointer to next entry.
550 if (bdp
->cbd_sc
& BD_ENET_RX_WRAP
)
551 bdp
= cep
->rx_bd_base
;
556 cep
->cur_rx
= (cbd_t
*)bdp
;
562 cpm_enet_close(struct net_device
*dev
)
564 /* Don't know what to do yet.
570 static struct net_device_stats
*cpm_enet_get_stats(struct net_device
*dev
)
572 struct cpm_enet_private
*cep
= (struct cpm_enet_private
*)dev
->priv
;
577 /* Set or clear the multicast filter for this adaptor.
578 * Skeleton taken from sunlance driver.
579 * The CPM Ethernet implementation allows Multicast as well as individual
580 * MAC address filtering. Some of the drivers check to make sure it is
581 * a group multicast address, and discard those that are not. I guess I
582 * will do the same for now, but just remove the test if you want
583 * individual filtering as well (do the upper net layers want or support
584 * this kind of feature?).
587 static void set_multicast_list(struct net_device
*dev
)
589 struct cpm_enet_private
*cep
;
590 struct dev_mc_list
*dmi
;
591 u_char
*mcptr
, *tdptr
;
592 volatile scc_enet_t
*ep
;
594 cep
= (struct cpm_enet_private
*)dev
->priv
;
596 /* Get pointer to SCC area in parameter RAM.
598 ep
= (scc_enet_t
*)dev
->base_addr
;
600 if (dev
->flags
&IFF_PROMISC
) {
602 /* Log any net taps. */
603 printk("%s: Promiscuous mode enabled.\n", dev
->name
);
604 cep
->sccp
->scc_pmsr
|= SCC_PMSR_PRO
;
607 cep
->sccp
->scc_pmsr
&= ~SCC_PMSR_PRO
;
609 if (dev
->flags
& IFF_ALLMULTI
) {
610 /* Catch all multicast addresses, so set the
613 ep
->sen_gaddr1
= 0xffff;
614 ep
->sen_gaddr2
= 0xffff;
615 ep
->sen_gaddr3
= 0xffff;
616 ep
->sen_gaddr4
= 0xffff;
619 /* Clear filter and add the addresses in the list.
628 for (i
=0; i
<dev
->mc_count
; i
++) {
630 /* Only support group multicast for now.
632 if (!(dmi
->dmi_addr
[0] & 1))
635 /* The address in dmi_addr is LSB first,
636 * and taddr is MSB first. We have to
637 * copy bytes MSB first from dmi_addr.
639 mcptr
= (u_char
*)dmi
->dmi_addr
+ 5;
640 tdptr
= (u_char
*)&ep
->sen_taddrh
;
644 /* Ask CPM to run CRC and set bit in
647 cpmp
->cp_cpcr
= mk_cr_cmd(CPM_CR_ENET
, CPM_CR_SET_GADDR
) | CPM_CR_FLG
;
648 /* this delay is necessary here -- Cort */
650 while (cpmp
->cp_cpcr
& CPM_CR_FLG
);
656 /* Initialize the CPM Ethernet on SCC. If EPPC-Bug loaded us, or performed
657 * some other network I/O, a whole bunch of this has already been set up.
658 * It is no big deal if we do it again, we just have to disable the
659 * transmit and receive to make sure we don't catch the CPM with some
660 * inconsistent control information.
662 int __init
cpm_enet_init(void)
664 struct net_device
*dev
;
665 struct cpm_enet_private
*cep
;
668 unsigned long mem_addr
;
672 volatile cpm8xx_t
*cp
;
673 volatile scc_t
*sccp
;
674 volatile scc_enet_t
*ep
;
675 volatile immap_t
*immap
;
677 cp
= cpmp
; /* Get pointer to Communication Processor */
679 immap
= (immap_t
*)IMAP_ADDR
; /* and to internal registers */
683 /* Allocate some private information.
685 cep
= (struct cpm_enet_private
*)kmalloc(sizeof(*cep
), GFP_KERNEL
);
686 /*memset(cep, 0, sizeof(*cep));*/
687 __clear_user(cep
,sizeof(*cep
));
689 /* Create an Ethernet device instance.
691 dev
= init_etherdev(0, 0);
693 /* Get pointer to SCC area in parameter RAM.
695 ep
= (scc_enet_t
*)(&cp
->cp_dparam
[PROFF_ENET
]);
697 /* And another to the SCC register area.
699 sccp
= (volatile scc_t
*)(&cp
->cp_scc
[SCC_ENET
]);
700 cep
->sccp
= (scc_t
*)sccp
; /* Keep the pointer handy */
702 /* Disable receive and transmit in case EPPC-Bug started it.
704 sccp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
706 /* Cookbook style from the MPC860 manual.....
707 * Not all of this is necessary if EPPC-Bug has initialized
709 * So far we are lucky, all board configurations use the same
710 * pins, or at least the same I/O Port for these functions.....
711 * It can't last though......
714 /* Configure port A pins for Txd and Rxd.
716 immap
->im_ioport
.iop_papar
|= (PA_ENET_RXD
| PA_ENET_TXD
);
717 immap
->im_ioport
.iop_padir
&= ~(PA_ENET_RXD
| PA_ENET_TXD
);
718 immap
->im_ioport
.iop_paodr
&= ~PA_ENET_TXD
;
720 /* Configure port C pins to enable CLSN and RENA.
722 immap
->im_ioport
.iop_pcpar
&= ~(PC_ENET_CLSN
| PC_ENET_RENA
);
723 immap
->im_ioport
.iop_pcdir
&= ~(PC_ENET_CLSN
| PC_ENET_RENA
);
724 immap
->im_ioport
.iop_pcso
|= (PC_ENET_CLSN
| PC_ENET_RENA
);
726 /* Configure port A for TCLK and RCLK.
728 immap
->im_ioport
.iop_papar
|= (PA_ENET_TCLK
| PA_ENET_RCLK
);
729 immap
->im_ioport
.iop_padir
&= ~(PA_ENET_TCLK
| PA_ENET_RCLK
);
731 /* Configure Serial Interface clock routing.
732 * First, clear all SCC bits to zero, then set the ones we want.
734 cp
->cp_sicr
&= ~SICR_ENET_MASK
;
735 cp
->cp_sicr
|= SICR_ENET_CLKRT
;
737 /* Manual says set SDDR, but I can't find anything with that
738 * name. I think it is a misprint, and should be SDCR. This
739 * has already been set by the communication processor initialization.
742 /* Allocate space for the buffer descriptors in the DP ram.
743 * These are relative offsets in the DP ram address space.
744 * Initialize base addresses for the buffer descriptors.
746 i
= m8xx_cpm_dpalloc(sizeof(cbd_t
) * RX_RING_SIZE
);
747 ep
->sen_genscc
.scc_rbase
= i
;
748 cep
->rx_bd_base
= (cbd_t
*)&cp
->cp_dpmem
[i
];
750 i
= m8xx_cpm_dpalloc(sizeof(cbd_t
) * TX_RING_SIZE
);
751 ep
->sen_genscc
.scc_tbase
= i
;
752 cep
->tx_bd_base
= (cbd_t
*)&cp
->cp_dpmem
[i
];
754 cep
->dirty_tx
= cep
->cur_tx
= cep
->tx_bd_base
;
755 cep
->cur_rx
= cep
->rx_bd_base
;
757 /* Issue init Rx BD command for SCC.
758 * Manual says to perform an Init Rx parameters here. We have
759 * to perform both Rx and Tx because the SCC may have been
761 * In addition, we have to do it later because we don't yet have
762 * all of the BD control/status set properly.
763 cp->cp_cpcr = mk_cr_cmd(CPM_CR_ENET, CPM_CR_INIT_RX) | CPM_CR_FLG;
764 while (cp->cp_cpcr & CPM_CR_FLG);
767 /* Initialize function code registers for big-endian.
769 ep
->sen_genscc
.scc_rfcr
= SCC_EB
;
770 ep
->sen_genscc
.scc_tfcr
= SCC_EB
;
772 /* Set maximum bytes per receive buffer.
773 * This appears to be an Ethernet frame size, not the buffer
774 * fragment size. It must be a multiple of four.
776 ep
->sen_genscc
.scc_mrblr
= PKT_MAXBLR_SIZE
;
778 /* Set CRC preset and mask.
780 ep
->sen_cpres
= 0xffffffff;
781 ep
->sen_cmask
= 0xdebb20e3;
783 ep
->sen_crcec
= 0; /* CRC Error counter */
784 ep
->sen_alec
= 0; /* alignment error counter */
785 ep
->sen_disfc
= 0; /* discard frame counter */
787 ep
->sen_pads
= 0x8888; /* Tx short frame pad character */
788 ep
->sen_retlim
= 15; /* Retry limit threshold */
790 ep
->sen_maxflr
= PKT_MAXBUF_SIZE
; /* maximum frame length register */
791 ep
->sen_minflr
= PKT_MINBUF_SIZE
; /* minimum frame length register */
793 ep
->sen_maxd1
= PKT_MAXBLR_SIZE
; /* maximum DMA1 length */
794 ep
->sen_maxd2
= PKT_MAXBLR_SIZE
; /* maximum DMA2 length */
796 /* Clear hash tables.
807 /* Set Ethernet station address.
809 * If we performed a MBX diskless boot, the Ethernet controller
810 * has been initialized and we copy the address out into our
813 * All other types of boards supply the address in the board
814 * information structure, so we copy that into the controller.
816 eap
= (unsigned char *)&(ep
->sen_paddrh
);
819 *eap
++ = dev
->dev_addr
[i
] = bd
->bi_enetaddr
[i
];
822 dev
->dev_addr
[i
] = *eap
++;
825 ep
->sen_pper
= 0; /* 'cause the book says so */
826 ep
->sen_taddrl
= 0; /* temp address (LSB) */
828 ep
->sen_taddrh
= 0; /* temp address (MSB) */
830 /* Now allocate the host memory pages and initialize the
831 * buffer descriptors.
833 bdp
= cep
->tx_bd_base
;
834 for (i
=0; i
<TX_RING_SIZE
; i
++) {
836 /* Initialize the BD for every fragment in the page.
839 bdp
->cbd_bufaddr
= 0;
843 /* Set the last buffer to wrap.
846 bdp
->cbd_sc
|= BD_SC_WRAP
;
848 bdp
= cep
->rx_bd_base
;
849 for (i
=0; i
<CPM_ENET_RX_PAGES
; i
++) {
853 mem_addr
= __get_free_page(GFP_KERNEL
);
857 pte
= find_pte(&init_mm
, mem_addr
);
858 pte_val(*pte
) |= _PAGE_NO_CACHE
;
859 flush_tlb_page(current
->mm
->mmap
, mem_addr
);
861 /* Initialize the BD for every fragment in the page.
863 for (j
=0; j
<CPM_ENET_RX_FRPPG
; j
++) {
864 bdp
->cbd_sc
= BD_ENET_RX_EMPTY
| BD_ENET_RX_INTR
;
865 bdp
->cbd_bufaddr
= __pa(mem_addr
);
866 mem_addr
+= CPM_ENET_RX_FRSIZE
;
871 /* Set the last buffer to wrap.
874 bdp
->cbd_sc
|= BD_SC_WRAP
;
876 /* Let's re-initialize the channel now. We have to do it later
877 * than the manual describes because we have just now finished
878 * the BD initialization.
880 cp
->cp_cpcr
= mk_cr_cmd(CPM_CR_ENET
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
881 while (cp
->cp_cpcr
& CPM_CR_FLG
);
883 cep
->skb_cur
= cep
->skb_dirty
= 0;
885 sccp
->scc_scce
= 0xffff; /* Clear any pending events */
887 /* Enable interrupts for transmit error, complete frame
888 * received, and any transmit buffer we have also set the
891 sccp
->scc_sccm
= (SCCE_ENET_TXE
| SCCE_ENET_RXF
| SCCE_ENET_TXB
);
893 /* Install our interrupt handler.
895 cpm_install_handler(CPMVEC_ENET
, cpm_enet_interrupt
, dev
);
897 /* Set GSMR_H to enable all normal operating modes.
898 * Set GSMR_L to enable Ethernet to MC68160.
901 sccp
->scc_gsmrl
= (SCC_GSMRL_TCI
| SCC_GSMRL_TPL_48
| SCC_GSMRL_TPP_10
| SCC_GSMRL_MODE_ENET
);
903 /* Set sync/delimiters.
905 sccp
->scc_dsr
= 0xd555;
907 /* Set processing mode. Use Ethernet CRC, catch broadcast, and
908 * start frame search 22 bit times after RENA.
910 sccp
->scc_pmsr
= (SCC_PMSR_ENCRC
| SCC_PMSR_NIB22
);
912 /* It is now OK to enable the Ethernet transmitter.
913 * Unfortunately, there are board implementation differences here.
916 immap
->im_ioport
.iop_pcpar
|= PC_ENET_TENA
;
917 immap
->im_ioport
.iop_pcdir
&= ~PC_ENET_TENA
;
920 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
921 cp
->cp_pbpar
|= PB_ENET_TENA
;
922 cp
->cp_pbdir
|= PB_ENET_TENA
;
924 /* And while we are here, set the configuration to enable ethernet.
926 *((volatile uint
*)RPX_CSR_ADDR
) &= ~BCSR0_ETHLPBK
;
927 *((volatile uint
*)RPX_CSR_ADDR
) |=
928 (BCSR0_ETHEN
| BCSR0_COLTESTDIS
| BCSR0_FULLDPLXDIS
);
932 cp
->cp_pbpar
|= PB_ENET_TENA
;
933 cp
->cp_pbdir
|= PB_ENET_TENA
;
935 /* BSE uses port B and C for PHY control.
937 cp
->cp_pbpar
&= ~(PB_BSE_POWERUP
| PB_BSE_FDXDIS
);
938 cp
->cp_pbdir
|= (PB_BSE_POWERUP
| PB_BSE_FDXDIS
);
939 cp
->cp_pbdat
|= (PB_BSE_POWERUP
| PB_BSE_FDXDIS
);
941 immap
->im_ioport
.iop_pcpar
&= ~PC_BSE_LOOPBACK
;
942 immap
->im_ioport
.iop_pcdir
|= PC_BSE_LOOPBACK
;
943 immap
->im_ioport
.iop_pcso
&= ~PC_BSE_LOOPBACK
;
944 immap
->im_ioport
.iop_pcdat
&= ~PC_BSE_LOOPBACK
;
947 dev
->base_addr
= (unsigned long)ep
;
950 dev
->name
= "CPM_ENET";
953 /* The CPM Ethernet specific entries in the device structure. */
954 dev
->open
= cpm_enet_open
;
955 dev
->hard_start_xmit
= cpm_enet_start_xmit
;
956 dev
->stop
= cpm_enet_close
;
957 dev
->get_stats
= cpm_enet_get_stats
;
958 dev
->set_multicast_list
= set_multicast_list
;
960 /* And last, enable the transmit and receive processing.
962 sccp
->scc_gsmrl
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
964 printk("%s: CPM ENET Version 0.2, ", dev
->name
);
966 printk("%02x:", dev
->dev_addr
[i
]);
967 printk("%02x\n", dev
->dev_addr
[5]);