1 /*-----------------------------------------------------------------------------+
3 * This source code has been made available to you by IBM on an AS-IS
4 * basis. Anyone receiving this source is licensed under IBM
5 * copyrights to use it in any way he or she deems fit, including
6 * copying it, modifying it, compiling it, and redistributing it either
7 * with or without modifications. No license under IBM patents or
8 * patent applications is to be implied by the copyright license.
10 * Any user of this software should understand that IBM cannot provide
11 * technical support for this software and will not be responsible for
12 * any consequences resulting from the use of this software.
14 * Any person who transfers this source code or any derivative work
15 * must include the IBM copyright notice, this paragraph, and the
16 * preceding two paragraphs in the transferred software.
18 * COPYRIGHT I B M CORPORATION 1995
19 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
20 *-----------------------------------------------------------------------------*/
21 /*-----------------------------------------------------------------------------+
23 * File Name: enetemac.c
25 * Function: Device driver for the ethernet EMAC3 macro on the 405GP.
31 * Date Description of Change BY
32 * --------- --------------------- ---
33 * 05-May-99 Created MKW
34 * 27-Jun-99 Clean up JWB
35 * 16-Jul-99 Added MAL error recovery and better IP packet handling MKW
36 * 29-Jul-99 Added Full duplex support MKW
37 * 06-Aug-99 Changed names for Mal CR reg MKW
38 * 23-Aug-99 Turned off SYE when running at 10Mbs MKW
39 * 24-Aug-99 Marked descriptor empty after call_xlc MKW
40 * 07-Sep-99 Set MAL RX buffer size reg to ENET_MAX_MTU_ALIGNED / 16 MCG
41 * to avoid chaining maximum sized packets. Push starting
42 * RX descriptor address up to the next cache line boundary.
43 * 16-Jan-00 Added support for booting with IP of 0x0 MKW
44 * 15-Mar-00 Updated enetInit() to enable broadcast addresses in the
45 * EMAC_RXM register. JWB
46 * 12-Mar-01 anne-sophie.harnois@nextream.fr
47 * - Variables are compatible with those already defined in
49 * - Receive buffer descriptor ring is used to send buffers
51 * - Info print about send/received/handled packet number if
52 * INFO_405_ENET is set
53 * 17-Apr-01 stefan.roese@esd-electronics.com
54 * - MAL reset in "eth_halt" included
55 * - Enet speed and duplex output now in one line
56 * 08-May-01 stefan.roese@esd-electronics.com
57 * - MAL error handling added (eth_init called again)
58 * 13-Nov-01 stefan.roese@esd-electronics.com
59 * - Set IST bit in EMAC_M1 reg upon 100MBit or full duplex
60 * 04-Jan-02 stefan.roese@esd-electronics.com
61 * - Wait for PHY auto negotiation to complete added
62 * 06-Feb-02 stefan.roese@esd-electronics.com
63 * - Bug fixed in waiting for auto negotiation to complete
64 * 26-Feb-02 stefan.roese@esd-electronics.com
65 * - rx and tx buffer descriptors now allocated (no fixed address
67 * 17-Jun-02 stefan.roese@esd-electronics.com
68 * - MAL error debug printf 'M' removed (rx de interrupt may
69 * occur upon many incoming packets with only 4 rx buffers).
70 *-----------------------------------------------------------------------------*
71 * 17-Nov-03 travis.sawyer@sandburst.com
72 * - ported from 405gp_enet.c to utilized upto 4 EMAC ports
73 * in the 440GX. This port should work with the 440GP
75 * 15-Aug-05 sr@denx.de
76 * - merged 405gp_enet.c and 440gx_enet.c to generic 4xx_enet.c
77 now handling all 4xx cpu's.
78 *-----------------------------------------------------------------------------*/
83 #include <asm/processor.h>
86 #include <ppc4xx_enet.h>
93 * Only compile for platform with AMCC EMAC ethernet controller and
94 * network support enabled.
95 * Remark: CONFIG_405 describes Xilinx PPC405 FPGA without EMAC controller!
97 #if (CONFIG_COMMANDS & CFG_CMD_NET) && !defined(CONFIG_405) && !defined(CONFIG_IOP480)
99 #if !(defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII))
100 #error "CONFIG_MII has to be defined!"
103 #if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI)
104 #error "CONFIG_NET_MULTI has to be defined for NetConsole"
107 #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
108 #define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */
110 /* Ethernet Transmit and Receive Buffers */
112 * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
113 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
115 #define ENET_MAX_MTU PKTSIZE
116 #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
118 /*-----------------------------------------------------------------------------+
119 * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
120 * Interrupt Controller).
121 *-----------------------------------------------------------------------------*/
122 #define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
123 #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
124 #define EMAC_UIC_DEF UIC_ENET
125 #define EMAC_UIC_DEF1 UIC_ENET1
126 #define SEL_UIC_DEF(p) (p ? UIC_ENET1 : UIC_ENET )
130 #define BI_PHYMODE_NONE 0
131 #define BI_PHYMODE_ZMII 1
132 #define BI_PHYMODE_RGMII 2
135 /*-----------------------------------------------------------------------------+
136 * Global variables. TX and RX descriptors and buffers.
137 *-----------------------------------------------------------------------------*/
139 static uint32_t mal_ier;
141 #if !defined(CONFIG_NET_MULTI)
142 struct eth_device *emac0_dev = NULL;
146 * Get count of EMAC devices (doesn't have to be the max. possible number
147 * supported by the cpu)
149 #if defined(CONFIG_HAS_ETH3)
150 #define LAST_EMAC_NUM 4
151 #elif defined(CONFIG_HAS_ETH2)
152 #define LAST_EMAC_NUM 3
153 #elif defined(CONFIG_HAS_ETH1)
154 #define LAST_EMAC_NUM 2
156 #define LAST_EMAC_NUM 1
159 /*-----------------------------------------------------------------------------+
160 * Prototypes and externals.
161 *-----------------------------------------------------------------------------*/
162 static void enet_rcv (struct eth_device *dev, unsigned long malisr);
164 int enetInt (struct eth_device *dev);
165 static void mal_err (struct eth_device *dev, unsigned long isr,
166 unsigned long uic, unsigned long maldef,
167 unsigned long mal_errr);
168 static void emac_err (struct eth_device *dev, unsigned long isr);
171 /*-----------------------------------------------------------------------------+
173 | Disable MAL channel, and EMACn
174 +-----------------------------------------------------------------------------*/
175 static void ppc_4xx_eth_halt (struct eth_device *dev)
177 EMAC_4XX_HW_PST hw_p = dev->priv;
178 uint32_t failsafe = 10000;
180 out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
182 /* 1st reset MAL channel */
183 /* Note: writing a 0 to a channel has no effect */
184 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
185 mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
187 mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
189 mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
192 while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
193 udelay (1000); /* Delay 1 MS so as not to hammer the register */
200 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
202 #ifndef CONFIG_NETCONSOLE
203 hw_p->print_speed = 1; /* print speed message again next time */
209 extern int phy_setup_aneg (unsigned char addr);
210 extern int miiphy_reset (unsigned char addr);
212 #if defined (CONFIG_440GX)
213 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
216 unsigned long zmiifer;
217 unsigned long rmiifer;
219 mfsdr(sdr_pfc1, pfc1);
220 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
227 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
228 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
229 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
230 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
231 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
232 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
233 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
234 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
237 zmiifer = ZMII_FER_SMII << ZMII_FER_V(0);
238 zmiifer = ZMII_FER_SMII << ZMII_FER_V(1);
239 zmiifer = ZMII_FER_SMII << ZMII_FER_V(2);
240 zmiifer = ZMII_FER_SMII << ZMII_FER_V(3);
241 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
242 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
243 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
244 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
247 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
248 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
249 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
250 bis->bi_phymode[1] = BI_PHYMODE_NONE;
251 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
252 bis->bi_phymode[3] = BI_PHYMODE_NONE;
255 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
256 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
257 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
258 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
259 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
260 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
261 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
262 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
265 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
266 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
267 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
268 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
269 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
270 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
271 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
272 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
275 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
276 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
277 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
278 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
279 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
280 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
284 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
286 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
287 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
288 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
289 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
293 /* Ensure we setup mdio for this devnum and ONLY this devnum */
294 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
296 out32 (ZMII_FER, zmiifer);
297 out32 (RGMII_FER, rmiifer);
304 static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
307 unsigned long reg = 0;
310 unsigned long duplex;
311 unsigned long failsafe;
313 unsigned short devnum;
314 unsigned short reg_short;
315 #if defined(CONFIG_440GX)
320 EMAC_4XX_HW_PST hw_p = dev->priv;
322 /* before doing anything, figure out if we have a MAC address */
324 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
325 printf("ERROR: ethaddr not set!\n");
329 #if defined(CONFIG_440GX)
330 /* Need to get the OPB frequency so we can access the PHY */
331 get_sys_info (&sysinfo);
335 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
337 devnum = hw_p->devnum;
342 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
343 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
344 * is possible that new packets (without relationship with
345 * current transfer) have got the time to arrived before
346 * netloop calls eth_halt
348 printf ("About preceeding transfer (eth%d):\n"
349 "- Sent packet number %d\n"
350 "- Received packet number %d\n"
351 "- Handled packet number %d\n",
354 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
356 hw_p->stats.pkts_tx = 0;
357 hw_p->stats.pkts_rx = 0;
358 hw_p->stats.pkts_handled = 0;
361 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
362 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
364 hw_p->rx_slot = 0; /* MAL Receive Slot */
365 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
366 hw_p->rx_u_index = 0; /* Receive User Queue Index */
368 hw_p->tx_slot = 0; /* MAL Transmit Slot */
369 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
370 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
372 #if defined(CONFIG_440)
374 /* NOTE: 440GX spec states that mode is mutually exclusive */
375 /* NOTE: Therefore, disable all other EMACS, since we handle */
376 /* NOTE: only one emac at a time */
381 #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
382 out32 (ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
383 #elif defined(CONFIG_440GX)
384 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
385 #elif defined(CONFIG_440GP)
387 out32 (ZMII_FER, ZMII_RMII | ZMII_MDI0);
389 if ((devnum == 0) || (devnum == 1)) {
390 out32 (ZMII_FER, (ZMII_FER_SMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
392 else { /* ((devnum == 2) || (devnum == 3)) */
393 out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum));
394 out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) |
395 (RGMII_FER_RGMII << RGMII_FER_V (3))));
399 out32 (ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
400 #endif /* defined(CONFIG_440) */
402 __asm__ volatile ("eieio");
404 /* reset emac so we have access to the phy */
406 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
407 __asm__ volatile ("eieio");
410 while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
415 #if defined(CONFIG_440GX)
416 /* Whack the M1 register */
418 mode_reg &= ~0x00000038;
419 if (sysinfo.freqOPB <= 50000000);
420 else if (sysinfo.freqOPB <= 66666667)
421 mode_reg |= EMAC_M1_OBCI_66;
422 else if (sysinfo.freqOPB <= 83333333)
423 mode_reg |= EMAC_M1_OBCI_83;
424 else if (sysinfo.freqOPB <= 100000000)
425 mode_reg |= EMAC_M1_OBCI_100;
427 mode_reg |= EMAC_M1_OBCI_GT100;
429 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
430 #endif /* defined(CONFIG_440GX) */
432 /* wait for PHY to complete auto negotiation */
434 #ifndef CONFIG_CS8952_PHY
437 reg = CONFIG_PHY_ADDR;
439 #if defined (CONFIG_PHY1_ADDR)
441 reg = CONFIG_PHY1_ADDR;
444 #if defined (CONFIG_440GX)
446 reg = CONFIG_PHY2_ADDR;
449 reg = CONFIG_PHY3_ADDR;
453 reg = CONFIG_PHY_ADDR;
457 bis->bi_phynum[devnum] = reg;
459 #if defined(CONFIG_PHY_RESET)
461 * Reset the phy, only if its the first time through
462 * otherwise, just check the speeds & feeds
464 if (hw_p->first_init == 0) {
467 #if defined(CONFIG_440GX)
468 #if defined(CONFIG_CIS8201_PHY)
470 * Cicada 8201 PHY needs to have an extended register whacked
473 if ( ((devnum == 2) || (devnum ==3)) && (4 == ethgroup) ) {
474 #if defined(CONFIG_CIS8201_SHORT_ETCH)
475 miiphy_write (reg, 23, 0x1300);
477 miiphy_write (reg, 23, 0x1000);
480 * Vitesse VSC8201/Cicada CIS8201 errata:
481 * Interoperability problem with Intel 82547EI phys
482 * This work around (provided by Vitesse) changes
483 * the default timer convergence from 8ms to 12ms
485 miiphy_write (reg, 0x1f, 0x2a30);
486 miiphy_write (reg, 0x08, 0x0200);
487 miiphy_write (reg, 0x1f, 0x52b5);
488 miiphy_write (reg, 0x02, 0x0004);
489 miiphy_write (reg, 0x01, 0x0671);
490 miiphy_write (reg, 0x00, 0x8fae);
491 miiphy_write (reg, 0x1f, 0x2a30);
492 miiphy_write (reg, 0x08, 0x0000);
493 miiphy_write (reg, 0x1f, 0x0000);
494 /* end Vitesse/Cicada errata */
498 /* Start/Restart autonegotiation */
499 phy_setup_aneg (reg);
502 #endif /* defined(CONFIG_PHY_RESET) */
504 miiphy_read (reg, PHY_BMSR, ®_short);
507 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
509 if ((reg_short & PHY_BMSR_AUTN_ABLE)
510 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
511 puts ("Waiting for PHY auto negotiation to complete");
513 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
517 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
518 puts (" TIMEOUT !\n");
522 if ((i++ % 1000) == 0) {
525 udelay (1000); /* 1 ms */
526 miiphy_read (reg, PHY_BMSR, ®_short);
530 udelay (500000); /* another 500 ms (results in faster booting) */
532 #endif /* #ifndef CONFIG_CS8952_PHY */
534 speed = miiphy_speed (reg);
535 duplex = miiphy_duplex (reg);
537 if (hw_p->print_speed) {
538 hw_p->print_speed = 0;
539 printf ("ENET Speed is %d Mbps - %s duplex connection\n",
540 (int) speed, (duplex == HALF) ? "HALF" : "FULL");
543 #if defined(CONFIG_440)
544 #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
547 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
549 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
554 /* Set ZMII/RGMII speed according to the phy link speed */
555 reg = in32 (ZMII_SSR);
556 if ( (speed == 100) || (speed == 1000) )
557 out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
559 out32 (ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
561 if ((devnum == 2) || (devnum == 3)) {
563 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
564 else if (speed == 100)
565 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
567 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
569 out32 (RGMII_SSR, reg);
571 #endif /* defined(CONFIG_440) */
573 /* set the Mal configuration reg */
574 #if defined(CONFIG_440GX)
575 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
576 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
578 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
579 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
580 if (get_pvr() == PVR_440GP_RB) {
581 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
585 /* Free "old" buffers */
586 if (hw_p->alloc_tx_buf)
587 free (hw_p->alloc_tx_buf);
588 if (hw_p->alloc_rx_buf)
589 free (hw_p->alloc_rx_buf);
592 * Malloc MAL buffer desciptors, make sure they are
593 * aligned on cache line boundary size
594 * (401/403/IOP480 = 16, 405 = 32)
595 * and doesn't cross cache block boundaries.
598 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
599 ((2 * CFG_CACHELINE_SIZE) - 2));
600 if (NULL == hw_p->alloc_tx_buf)
602 if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
604 (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
607 alloc_tx_buf & CACHELINE_MASK));
609 hw_p->tx = hw_p->alloc_tx_buf;
613 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
614 ((2 * CFG_CACHELINE_SIZE) - 2));
615 if (NULL == hw_p->alloc_rx_buf) {
616 free(hw_p->alloc_tx_buf);
617 hw_p->alloc_tx_buf = NULL;
621 if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
623 (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
626 alloc_rx_buf & CACHELINE_MASK));
628 hw_p->rx = hw_p->alloc_rx_buf;
631 for (i = 0; i < NUM_TX_BUFF; i++) {
632 hw_p->tx[i].ctrl = 0;
633 hw_p->tx[i].data_len = 0;
634 if (hw_p->first_init == 0) {
636 (char *) malloc (ENET_MAX_MTU_ALIGNED);
637 if (NULL == hw_p->txbuf_ptr) {
638 free(hw_p->alloc_rx_buf);
639 free(hw_p->alloc_tx_buf);
640 hw_p->alloc_rx_buf = NULL;
641 hw_p->alloc_tx_buf = NULL;
642 for(j = 0; j < i; j++) {
643 free(hw_p->tx[i].data_ptr);
644 hw_p->tx[i].data_ptr = NULL;
648 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
649 if ((NUM_TX_BUFF - 1) == i)
650 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
651 hw_p->tx_run[i] = -1;
653 printf ("TX_BUFF %d @ 0x%08lx\n", i,
654 (ulong) hw_p->tx[i].data_ptr);
658 for (i = 0; i < NUM_RX_BUFF; i++) {
659 hw_p->rx[i].ctrl = 0;
660 hw_p->rx[i].data_len = 0;
661 /* rx[i].data_ptr = (char *) &rx_buff[i]; */
662 hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
663 if ((NUM_RX_BUFF - 1) == i)
664 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
665 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
666 hw_p->rx_ready[i] = -1;
668 printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr);
674 reg |= dev->enetaddr[0]; /* set high address */
676 reg |= dev->enetaddr[1];
678 out32 (EMAC_IAH + hw_p->hw_addr, reg);
681 reg |= dev->enetaddr[2]; /* set low address */
683 reg |= dev->enetaddr[3];
685 reg |= dev->enetaddr[4];
687 reg |= dev->enetaddr[5];
689 out32 (EMAC_IAL + hw_p->hw_addr, reg);
693 /* setup MAL tx & rx channel pointers */
694 #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
695 mtdcr (maltxctp2r, hw_p->tx);
697 mtdcr (maltxctp1r, hw_p->tx);
699 #if defined(CONFIG_440)
700 mtdcr (maltxbattr, 0x0);
701 mtdcr (malrxbattr, 0x0);
703 mtdcr (malrxctp1r, hw_p->rx);
704 /* set RX buffer size */
705 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
707 #if defined (CONFIG_440GX)
709 /* setup MAL tx & rx channel pointers */
710 mtdcr (maltxbattr, 0x0);
711 mtdcr (malrxbattr, 0x0);
712 mtdcr (maltxctp2r, hw_p->tx);
713 mtdcr (malrxctp2r, hw_p->rx);
714 /* set RX buffer size */
715 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
718 /* setup MAL tx & rx channel pointers */
719 mtdcr (maltxbattr, 0x0);
720 mtdcr (maltxctp3r, hw_p->tx);
721 mtdcr (malrxbattr, 0x0);
722 mtdcr (malrxctp3r, hw_p->rx);
723 /* set RX buffer size */
724 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
726 #endif /* CONFIG_440GX */
729 /* setup MAL tx & rx channel pointers */
730 #if defined(CONFIG_440)
731 mtdcr (maltxbattr, 0x0);
732 mtdcr (malrxbattr, 0x0);
734 mtdcr (maltxctp0r, hw_p->tx);
735 mtdcr (malrxctp0r, hw_p->rx);
736 /* set RX buffer size */
737 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
741 /* Enable MAL transmit and receive channels */
742 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
743 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
745 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
747 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
749 /* set transmit enable & receive enable */
750 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
752 /* set receive fifo to 4k and tx fifo to 2k */
753 mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
754 mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
757 if (speed == _1000BASET)
758 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
759 else if (speed == _100BASET)
760 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
762 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
764 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
766 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
768 /* Enable broadcast and indvidual address */
769 /* TBS: enabling runts as some misbehaved nics will send runts */
770 out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
772 /* we probably need to set the tx mode1 reg? maybe at tx time */
774 /* set transmit request threshold register */
775 out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
777 /* set receive low/high water mark register */
778 #if defined(CONFIG_440)
779 /* 440GP has a 64 byte burst length */
780 out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
782 /* 405s have a 16 byte burst length */
783 out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
784 #endif /* defined(CONFIG_440) */
785 out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
787 /* Set fifo limit entry in tx mode 0 */
788 out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
790 out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
793 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
794 if (speed == _100BASET)
795 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
797 out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
798 out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
800 if (hw_p->first_init == 0) {
802 * Connect interrupt service routines
804 irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2),
805 (interrupt_handler_t *) enetInt, dev);
808 mtmsr (msr); /* enable interrupts again */
811 hw_p->first_init = 1;
817 static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
820 struct enet_frame *ef_ptr;
821 ulong time_start, time_now;
822 unsigned long temp_txm0;
823 EMAC_4XX_HW_PST hw_p = dev->priv;
825 ef_ptr = (struct enet_frame *) ptr;
827 /*-----------------------------------------------------------------------+
828 * Copy in our address into the frame.
829 *-----------------------------------------------------------------------*/
830 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
832 /*-----------------------------------------------------------------------+
833 * If frame is too long or too short, modify length.
834 *-----------------------------------------------------------------------*/
835 /* TBS: where does the fragment go???? */
836 if (len > ENET_MAX_MTU)
839 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
840 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
842 /*-----------------------------------------------------------------------+
843 * set TX Buffer busy, and send it
844 *-----------------------------------------------------------------------*/
845 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
846 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
847 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
848 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
849 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
851 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
852 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
854 __asm__ volatile ("eieio");
856 out32 (EMAC_TXM0 + hw_p->hw_addr,
857 in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
859 hw_p->stats.pkts_tx++;
862 /*-----------------------------------------------------------------------+
863 * poll unitl the packet is sent and then make sure it is OK
864 *-----------------------------------------------------------------------*/
865 time_start = get_timer (0);
867 temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
868 /* loop until either TINT turns on or 3 seconds elapse */
869 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
870 /* transmit is done, so now check for errors
871 * If there is an error, an interrupt should
872 * happen when we return
874 time_now = get_timer (0);
875 if ((time_now - time_start) > 3000) {
884 #if defined (CONFIG_440)
886 int enetInt (struct eth_device *dev)
889 int rc = -1; /* default to not us */
890 unsigned long mal_isr;
891 unsigned long emac_isr = 0;
892 unsigned long mal_rx_eob;
893 unsigned long my_uic0msr, my_uic1msr;
895 #if defined(CONFIG_440GX)
896 unsigned long my_uic2msr;
898 EMAC_4XX_HW_PST hw_p;
901 * Because the mal is generic, we need to get the current
904 #if defined(CONFIG_NET_MULTI)
913 /* enter loop that stays in interrupt code until nothing to service */
917 my_uic0msr = mfdcr (uic0msr);
918 my_uic1msr = mfdcr (uic1msr);
919 #if defined(CONFIG_440GX)
920 my_uic2msr = mfdcr (uic2msr);
922 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
924 (UIC_ETH0 | UIC_ETH1 | UIC_MS | UIC_MTDE |
929 #if defined (CONFIG_440GX)
930 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
931 && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
936 /* get and clear controller status interrupts */
937 /* look at Mal and EMAC interrupts */
938 if ((my_uic0msr & (UIC_MRE | UIC_MTE))
939 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
940 /* we have a MAL interrupt */
941 mal_isr = mfdcr (malesr);
942 /* look for mal error */
943 if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
944 mal_err (dev, mal_isr, my_uic0msr,
945 MAL_UIC_DEF, MAL_UIC_ERR);
951 /* port by port dispatch of emac interrupts */
952 if (hw_p->devnum == 0) {
953 if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */
954 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
955 if ((hw_p->emac_ier & emac_isr) != 0) {
956 emac_err (dev, emac_isr);
961 if ((hw_p->emac_ier & emac_isr)
962 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
963 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
964 mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
965 return (rc); /* we had errors so get out */
969 if (hw_p->devnum == 1) {
970 if (UIC_ETH1 & my_uic1msr) { /* look for EMAC errors */
971 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
972 if ((hw_p->emac_ier & emac_isr) != 0) {
973 emac_err (dev, emac_isr);
978 if ((hw_p->emac_ier & emac_isr)
979 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
980 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
981 mtdcr (uic1sr, UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
982 return (rc); /* we had errors so get out */
985 #if defined (CONFIG_440GX)
986 if (hw_p->devnum == 2) {
987 if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
988 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
989 if ((hw_p->emac_ier & emac_isr) != 0) {
990 emac_err (dev, emac_isr);
995 if ((hw_p->emac_ier & emac_isr)
996 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
997 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
998 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
999 mtdcr (uic2sr, UIC_ETH2);
1000 return (rc); /* we had errors so get out */
1004 if (hw_p->devnum == 3) {
1005 if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
1006 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1007 if ((hw_p->emac_ier & emac_isr) != 0) {
1008 emac_err (dev, emac_isr);
1013 if ((hw_p->emac_ier & emac_isr)
1014 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1015 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
1016 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1017 mtdcr (uic2sr, UIC_ETH3);
1018 return (rc); /* we had errors so get out */
1021 #endif /* CONFIG_440GX */
1022 /* handle MAX TX EOB interrupt from a tx */
1023 if (my_uic0msr & UIC_MTE) {
1024 mal_rx_eob = mfdcr (maltxeobisr);
1025 mtdcr (maltxeobisr, mal_rx_eob);
1026 mtdcr (uic0sr, UIC_MTE);
1028 /* handle MAL RX EOB interupt from a receive */
1029 /* check for EOB on valid channels */
1030 if (my_uic0msr & UIC_MRE) {
1031 mal_rx_eob = mfdcr (malrxeobisr);
1032 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
1034 mtdcr(malrxeobisr, mal_rx_eob); */
1035 enet_rcv (dev, emac_isr);
1036 /* indicate that we serviced an interrupt */
1041 mtdcr (uic0sr, UIC_MRE); /* Clear */
1042 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1043 switch (hw_p->devnum) {
1045 mtdcr (uic1sr, UIC_ETH0);
1048 mtdcr (uic1sr, UIC_ETH1);
1050 #if defined (CONFIG_440GX)
1052 mtdcr (uic2sr, UIC_ETH2);
1055 mtdcr (uic2sr, UIC_ETH3);
1057 #endif /* CONFIG_440GX */
1066 #else /* CONFIG_440 */
1068 int enetInt (struct eth_device *dev)
1071 int rc = -1; /* default to not us */
1072 unsigned long mal_isr;
1073 unsigned long emac_isr = 0;
1074 unsigned long mal_rx_eob;
1075 unsigned long my_uicmsr;
1077 EMAC_4XX_HW_PST hw_p;
1080 * Because the mal is generic, we need to get the current
1083 #if defined(CONFIG_NET_MULTI)
1084 dev = eth_get_dev();
1091 /* enter loop that stays in interrupt code until nothing to service */
1095 my_uicmsr = mfdcr (uicmsr);
1097 if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) { /* not for us */
1100 /* get and clear controller status interrupts */
1101 /* look at Mal and EMAC interrupts */
1102 if ((MAL_UIC_DEF & my_uicmsr) != 0) { /* we have a MAL interrupt */
1103 mal_isr = mfdcr (malesr);
1104 /* look for mal error */
1105 if ((my_uicmsr & MAL_UIC_ERR) != 0) {
1106 mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR);
1112 /* port by port dispatch of emac interrupts */
1114 if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) { /* look for EMAC errors */
1115 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1116 if ((hw_p->emac_ier & emac_isr) != 0) {
1117 emac_err (dev, emac_isr);
1122 if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) {
1123 mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */
1124 return (rc); /* we had errors so get out */
1127 /* handle MAX TX EOB interrupt from a tx */
1128 if (my_uicmsr & UIC_MAL_TXEOB) {
1129 mal_rx_eob = mfdcr (maltxeobisr);
1130 mtdcr (maltxeobisr, mal_rx_eob);
1131 mtdcr (uicsr, UIC_MAL_TXEOB);
1133 /* handle MAL RX EOB interupt from a receive */
1134 /* check for EOB on valid channels */
1135 if (my_uicmsr & UIC_MAL_RXEOB)
1137 mal_rx_eob = mfdcr (malrxeobisr);
1138 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
1140 mtdcr(malrxeobisr, mal_rx_eob); */
1141 enet_rcv (dev, emac_isr);
1142 /* indicate that we serviced an interrupt */
1147 mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1); /* Clear */
1154 #endif /* CONFIG_440 */
1156 /*-----------------------------------------------------------------------------+
1158 *-----------------------------------------------------------------------------*/
1159 static void mal_err (struct eth_device *dev, unsigned long isr,
1160 unsigned long uic, unsigned long maldef,
1161 unsigned long mal_errr)
1163 EMAC_4XX_HW_PST hw_p = dev->priv;
1165 mtdcr (malesr, isr); /* clear interrupt */
1167 /* clear DE interrupt */
1168 mtdcr (maltxdeir, 0xC0000000);
1169 mtdcr (malrxdeir, 0x80000000);
1171 #ifdef INFO_4XX_ENET
1172 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
1175 eth_init (hw_p->bis); /* start again... */
1178 /*-----------------------------------------------------------------------------+
1179 * EMAC Error Routine
1180 *-----------------------------------------------------------------------------*/
1181 static void emac_err (struct eth_device *dev, unsigned long isr)
1183 EMAC_4XX_HW_PST hw_p = dev->priv;
1185 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
1186 out32 (EMAC_ISR + hw_p->hw_addr, isr);
1189 /*-----------------------------------------------------------------------------+
1190 * enet_rcv() handles the ethernet receive data
1191 *-----------------------------------------------------------------------------*/
1192 static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1194 struct enet_frame *ef_ptr;
1195 unsigned long data_len;
1196 unsigned long rx_eob_isr;
1197 EMAC_4XX_HW_PST hw_p = dev->priv;
1203 rx_eob_isr = mfdcr (malrxeobisr);
1204 if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
1206 mtdcr (malrxeobisr, rx_eob_isr);
1209 while (1) { /* do all */
1212 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1213 || (loop_count >= NUM_RX_BUFF))
1217 if (NUM_RX_BUFF == hw_p->rx_slot)
1220 data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
1222 if (data_len > ENET_MAX_MTU) /* Check len */
1225 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1227 hw_p->stats.rx_err_log[hw_p->
1230 hw_p->rx_err_index++;
1231 if (hw_p->rx_err_index ==
1233 hw_p->rx_err_index =
1236 } /* data_len < max mtu */
1238 if (!data_len) { /* no data */
1239 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1241 hw_p->stats.data_len_err++; /* Error at Rx */
1246 /* Check if user has already eaten buffer */
1247 /* if not => ERROR */
1248 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1249 if (hw_p->is_receiving)
1250 printf ("ERROR : Receive buffers are full!\n");
1253 hw_p->stats.rx_frames++;
1254 hw_p->stats.rx += data_len;
1255 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1257 #ifdef INFO_4XX_ENET
1258 hw_p->stats.pkts_rx++;
1263 hw_p->rx_ready[hw_p->rx_i_index] = i;
1265 if (NUM_RX_BUFF == hw_p->rx_i_index)
1266 hw_p->rx_i_index = 0;
1269 * free receive buffer only when
1270 * buffer has been handled (eth_rx)
1271 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1275 } /* if EMACK_RXCHL */
1279 static int ppc_4xx_eth_rx (struct eth_device *dev)
1284 EMAC_4XX_HW_PST hw_p = dev->priv;
1286 hw_p->is_receiving = 1; /* tell driver */
1290 * use ring buffer and
1291 * get index from rx buffer desciptor queue
1293 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1294 if (user_index == -1) {
1296 break; /* nothing received - leave for() loop */
1300 mtmsr (msr & ~(MSR_EE));
1302 length = hw_p->rx[user_index].data_len;
1304 /* Pass the packet up to the protocol layers. */
1305 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1306 /* NetReceive(NetRxPackets[i], length); */
1307 NetReceive (NetRxPackets[user_index], length - 4);
1308 /* Free Recv Buffer */
1309 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1310 /* Free rx buffer descriptor queue */
1311 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1313 if (NUM_RX_BUFF == hw_p->rx_u_index)
1314 hw_p->rx_u_index = 0;
1316 #ifdef INFO_4XX_ENET
1317 hw_p->stats.pkts_handled++;
1320 mtmsr (msr); /* Enable IRQ's */
1323 hw_p->is_receiving = 0; /* tell driver */
1328 int ppc_4xx_eth_initialize (bd_t * bis)
1330 static int virgin = 0;
1331 struct eth_device *dev;
1333 EMAC_4XX_HW_PST hw = NULL;
1335 #if defined(CONFIG_440GX)
1338 mfsdr (sdr_pfc1, pfc1);
1339 pfc1 &= ~(0x01e00000);
1341 mtsdr (sdr_pfc1, pfc1);
1343 /* set phy num and mode */
1344 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
1345 #if defined(CONFIG_PHY1_ADDR)
1346 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
1348 #if defined(CONFIG_440GX)
1349 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1350 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1351 bis->bi_phymode[0] = 0;
1352 bis->bi_phymode[1] = 0;
1353 bis->bi_phymode[2] = 2;
1354 bis->bi_phymode[3] = 2;
1356 #if defined (CONFIG_440GX)
1357 ppc_4xx_eth_setup_bridge(0, bis);
1361 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1363 /* See if we can actually bring up the interface, otherwise, skip it */
1365 default: /* fall through */
1367 if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
1368 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1372 #ifdef CONFIG_HAS_ETH1
1374 if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
1375 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1380 #ifdef CONFIG_HAS_ETH2
1382 if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) {
1383 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1388 #ifdef CONFIG_HAS_ETH3
1390 if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) {
1391 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1398 /* Allocate device structure */
1399 dev = (struct eth_device *) malloc (sizeof (*dev));
1401 printf ("ppc_4xx_eth_initialize: "
1402 "Cannot allocate eth_device %d\n", eth_num);
1405 memset(dev, 0, sizeof(*dev));
1407 /* Allocate our private use data */
1408 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
1410 printf ("ppc_4xx_eth_initialize: "
1411 "Cannot allocate private hw data for eth_device %d",
1416 memset(hw, 0, sizeof(*hw));
1419 default: /* fall through */
1422 memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
1424 #ifdef CONFIG_HAS_ETH1
1426 hw->hw_addr = 0x100;
1427 memcpy (dev->enetaddr, bis->bi_enet1addr, 6);
1430 #ifdef CONFIG_HAS_ETH2
1432 hw->hw_addr = 0x400;
1433 memcpy (dev->enetaddr, bis->bi_enet2addr, 6);
1436 #ifdef CONFIG_HAS_ETH3
1438 hw->hw_addr = 0x600;
1439 memcpy (dev->enetaddr, bis->bi_enet3addr, 6);
1444 hw->devnum = eth_num;
1445 hw->print_speed = 1;
1447 sprintf (dev->name, "ppc_4xx_eth%d", eth_num);
1448 dev->priv = (void *) hw;
1449 dev->init = ppc_4xx_eth_init;
1450 dev->halt = ppc_4xx_eth_halt;
1451 dev->send = ppc_4xx_eth_send;
1452 dev->recv = ppc_4xx_eth_rx;
1455 /* set the MAL IER ??? names may change with new spec ??? */
1457 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
1458 MAL_IER_OPBE | MAL_IER_PLBE;
1459 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
1460 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
1461 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
1462 mtdcr (malier, mal_ier);
1464 /* install MAL interrupt handler */
1465 irq_install_handler (VECNUM_MS,
1466 (interrupt_handler_t *) enetInt,
1468 irq_install_handler (VECNUM_MTE,
1469 (interrupt_handler_t *) enetInt,
1471 irq_install_handler (VECNUM_MRE,
1472 (interrupt_handler_t *) enetInt,
1474 irq_install_handler (VECNUM_TXDE,
1475 (interrupt_handler_t *) enetInt,
1477 irq_install_handler (VECNUM_RXDE,
1478 (interrupt_handler_t *) enetInt,
1483 #if defined(CONFIG_NET_MULTI)
1489 } /* end for each supported device */
1494 #if !defined(CONFIG_NET_MULTI)
1495 void eth_halt (void) {
1497 ppc_4xx_eth_halt(emac0_dev);
1503 int eth_init (bd_t *bis)
1505 ppc_4xx_eth_initialize(bis);
1507 return ppc_4xx_eth_init(emac0_dev, bis);
1509 printf("ERROR: ethaddr not set!\n");
1514 int eth_send(volatile void *packet, int length)
1516 return (ppc_4xx_eth_send(emac0_dev, packet, length));
1521 return (ppc_4xx_eth_rx(emac0_dev));
1523 #endif /* !defined(CONFIG_NET_MULTI) */
1525 #endif /* #if (CONFIG_COMMANDS & CFG_CMD_NET) */