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);
170 extern int phy_setup_aneg (char *devname, unsigned char addr);
171 extern int emac4xx_miiphy_read (char *devname, unsigned char addr,
172 unsigned char reg, unsigned short *value);
173 extern int emac4xx_miiphy_write (char *devname, unsigned char addr,
174 unsigned char reg, unsigned short value);
176 /*-----------------------------------------------------------------------------+
178 | Disable MAL channel, and EMACn
179 +-----------------------------------------------------------------------------*/
180 static void ppc_4xx_eth_halt (struct eth_device *dev)
182 EMAC_4XX_HW_PST hw_p = dev->priv;
183 uint32_t failsafe = 10000;
184 #if defined(CONFIG_440SPE)
188 out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
190 /* 1st reset MAL channel */
191 /* Note: writing a 0 to a channel has no effect */
192 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
193 mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
195 mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
197 mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
200 while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
201 udelay (1000); /* Delay 1 MS so as not to hammer the register */
208 #if defined(CONFIG_440SPE)
209 /* provide clocks for EMAC internal loopback */
210 mfsdr (sdr_mfr, mfr);
215 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
217 #if defined(CONFIG_440SPE)
218 /* remove clocks for EMAC internal loopback */
219 mfsdr (sdr_mfr, mfr);
225 #ifndef CONFIG_NETCONSOLE
226 hw_p->print_speed = 1; /* print speed message again next time */
232 #if defined (CONFIG_440GX)
233 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
236 unsigned long zmiifer;
237 unsigned long rmiifer;
239 mfsdr(sdr_pfc1, pfc1);
240 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
247 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
248 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
249 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
250 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
251 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
252 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
253 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
254 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
257 zmiifer = ZMII_FER_SMII << ZMII_FER_V(0);
258 zmiifer = ZMII_FER_SMII << ZMII_FER_V(1);
259 zmiifer = ZMII_FER_SMII << ZMII_FER_V(2);
260 zmiifer = ZMII_FER_SMII << ZMII_FER_V(3);
261 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
262 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
263 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
264 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
267 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
268 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
269 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
270 bis->bi_phymode[1] = BI_PHYMODE_NONE;
271 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
272 bis->bi_phymode[3] = BI_PHYMODE_NONE;
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 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
279 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
280 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
281 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
282 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
285 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
286 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
287 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
288 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
289 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
290 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
291 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
292 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
295 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
296 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
297 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
298 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
299 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
300 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
304 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
306 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
307 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
308 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
309 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
313 /* Ensure we setup mdio for this devnum and ONLY this devnum */
314 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
316 out32 (ZMII_FER, zmiifer);
317 out32 (RGMII_FER, rmiifer);
322 #endif /* CONFIG_440_GX */
324 static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
327 unsigned long reg = 0;
330 unsigned long duplex;
331 unsigned long failsafe;
333 unsigned short devnum;
334 unsigned short reg_short;
335 #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
337 #if defined(CONFIG_440GX) || defined(CONFIG_440SPE)
341 #if defined(CONFIG_440SPE)
346 EMAC_4XX_HW_PST hw_p = dev->priv;
348 /* before doing anything, figure out if we have a MAC address */
350 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
351 printf("ERROR: ethaddr not set!\n");
355 #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
356 /* Need to get the OPB frequency so we can access the PHY */
357 get_sys_info (&sysinfo);
361 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
363 devnum = hw_p->devnum;
368 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
369 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
370 * is possible that new packets (without relationship with
371 * current transfer) have got the time to arrived before
372 * netloop calls eth_halt
374 printf ("About preceeding transfer (eth%d):\n"
375 "- Sent packet number %d\n"
376 "- Received packet number %d\n"
377 "- Handled packet number %d\n",
380 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
382 hw_p->stats.pkts_tx = 0;
383 hw_p->stats.pkts_rx = 0;
384 hw_p->stats.pkts_handled = 0;
385 hw_p->print_speed = 1; /* print speed message again next time */
388 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
389 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
391 hw_p->rx_slot = 0; /* MAL Receive Slot */
392 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
393 hw_p->rx_u_index = 0; /* Receive User Queue Index */
395 hw_p->tx_slot = 0; /* MAL Transmit Slot */
396 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
397 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
399 #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
401 /* NOTE: 440GX spec states that mode is mutually exclusive */
402 /* NOTE: Therefore, disable all other EMACS, since we handle */
403 /* NOTE: only one emac at a time */
408 #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
409 out32 (ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
410 #elif defined(CONFIG_440GX)
411 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
412 #elif defined(CONFIG_440GP)
414 out32 (ZMII_FER, ZMII_RMII | ZMII_MDI0);
416 if ((devnum == 0) || (devnum == 1)) {
417 out32 (ZMII_FER, (ZMII_FER_SMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
419 else { /* ((devnum == 2) || (devnum == 3)) */
420 out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum));
421 out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) |
422 (RGMII_FER_RGMII << RGMII_FER_V (3))));
426 out32 (ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
427 #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
429 __asm__ volatile ("eieio");
431 /* reset emac so we have access to the phy */
432 #if defined(CONFIG_440SPE)
433 /* provide clocks for EMAC internal loopback */
434 mfsdr (sdr_mfr, mfr);
439 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
440 __asm__ volatile ("eieio");
443 while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
448 #if defined(CONFIG_440SPE)
449 /* remove clocks for EMAC internal loopback */
450 mfsdr (sdr_mfr, mfr);
455 #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
456 /* Whack the M1 register */
458 mode_reg &= ~0x00000038;
459 if (sysinfo.freqOPB <= 50000000);
460 else if (sysinfo.freqOPB <= 66666667)
461 mode_reg |= EMAC_M1_OBCI_66;
462 else if (sysinfo.freqOPB <= 83333333)
463 mode_reg |= EMAC_M1_OBCI_83;
464 else if (sysinfo.freqOPB <= 100000000)
465 mode_reg |= EMAC_M1_OBCI_100;
467 mode_reg |= EMAC_M1_OBCI_GT100;
469 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
470 #endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
472 /* wait for PHY to complete auto negotiation */
474 #ifndef CONFIG_CS8952_PHY
477 reg = CONFIG_PHY_ADDR;
479 #if defined (CONFIG_PHY1_ADDR)
481 reg = CONFIG_PHY1_ADDR;
484 #if defined (CONFIG_440GX)
486 reg = CONFIG_PHY2_ADDR;
489 reg = CONFIG_PHY3_ADDR;
493 reg = CONFIG_PHY_ADDR;
497 bis->bi_phynum[devnum] = reg;
499 #if defined(CONFIG_PHY_RESET)
501 * Reset the phy, only if its the first time through
502 * otherwise, just check the speeds & feeds
504 if (hw_p->first_init == 0) {
505 #if defined(CONFIG_88E1111_CLK_DELAY)
507 * On some boards (e.g. ALPR) the Marvell 88E1111 PHY needs
508 * the "RGMII transmit timing control" and "RGMII receive
509 * timing control" bits set, so that Gbit communication works
511 * Also set the "Transmitter disable" to 1 to enable the
513 * After setting these bits a soft-reset must occur for this
514 * change to become active.
516 miiphy_read (dev->name, reg, 0x14, ®_short);
517 reg_short |= (1 << 7) | (1 << 1) | (1 << 0);
518 miiphy_write (dev->name, reg, 0x14, reg_short);
520 miiphy_reset (dev->name, reg);
522 #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
523 #if defined(CONFIG_CIS8201_PHY)
525 * Cicada 8201 PHY needs to have an extended register whacked
528 if ( ((devnum == 2) || (devnum ==3)) && (4 == ethgroup) ) {
529 #if defined(CONFIG_CIS8201_SHORT_ETCH)
530 miiphy_write (dev->name, reg, 23, 0x1300);
532 miiphy_write (dev->name, reg, 23, 0x1000);
535 * Vitesse VSC8201/Cicada CIS8201 errata:
536 * Interoperability problem with Intel 82547EI phys
537 * This work around (provided by Vitesse) changes
538 * the default timer convergence from 8ms to 12ms
540 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
541 miiphy_write (dev->name, reg, 0x08, 0x0200);
542 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
543 miiphy_write (dev->name, reg, 0x02, 0x0004);
544 miiphy_write (dev->name, reg, 0x01, 0x0671);
545 miiphy_write (dev->name, reg, 0x00, 0x8fae);
546 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
547 miiphy_write (dev->name, reg, 0x08, 0x0000);
548 miiphy_write (dev->name, reg, 0x1f, 0x0000);
549 /* end Vitesse/Cicada errata */
553 /* Start/Restart autonegotiation */
554 phy_setup_aneg (dev->name, reg);
557 #endif /* defined(CONFIG_PHY_RESET) */
559 miiphy_read (dev->name, reg, PHY_BMSR, ®_short);
562 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
564 if ((reg_short & PHY_BMSR_AUTN_ABLE)
565 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
566 puts ("Waiting for PHY auto negotiation to complete");
568 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
572 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
573 puts (" TIMEOUT !\n");
577 if ((i++ % 1000) == 0) {
580 udelay (1000); /* 1 ms */
581 miiphy_read (dev->name, reg, PHY_BMSR, ®_short);
585 udelay (500000); /* another 500 ms (results in faster booting) */
587 #endif /* #ifndef CONFIG_CS8952_PHY */
589 speed = miiphy_speed (dev->name, reg);
590 duplex = miiphy_duplex (dev->name, reg);
592 if (hw_p->print_speed) {
593 hw_p->print_speed = 0;
594 printf ("ENET Speed is %d Mbps - %s duplex connection\n",
595 (int) speed, (duplex == HALF) ? "HALF" : "FULL");
598 #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
599 #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
602 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
604 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
609 /* Set ZMII/RGMII speed according to the phy link speed */
610 reg = in32 (ZMII_SSR);
611 if ( (speed == 100) || (speed == 1000) )
612 out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
614 out32 (ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
616 if ((devnum == 2) || (devnum == 3)) {
618 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
619 else if (speed == 100)
620 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
622 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
624 out32 (RGMII_SSR, reg);
626 #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
628 /* set the Mal configuration reg */
629 #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
630 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
631 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
633 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
634 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
635 if (get_pvr() == PVR_440GP_RB) {
636 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
640 /* Free "old" buffers */
641 if (hw_p->alloc_tx_buf)
642 free (hw_p->alloc_tx_buf);
643 if (hw_p->alloc_rx_buf)
644 free (hw_p->alloc_rx_buf);
647 * Malloc MAL buffer desciptors, make sure they are
648 * aligned on cache line boundary size
649 * (401/403/IOP480 = 16, 405 = 32)
650 * and doesn't cross cache block boundaries.
653 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
654 ((2 * CFG_CACHELINE_SIZE) - 2));
655 if (NULL == hw_p->alloc_tx_buf)
657 if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
659 (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
662 alloc_tx_buf & CACHELINE_MASK));
664 hw_p->tx = hw_p->alloc_tx_buf;
668 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
669 ((2 * CFG_CACHELINE_SIZE) - 2));
670 if (NULL == hw_p->alloc_rx_buf) {
671 free(hw_p->alloc_tx_buf);
672 hw_p->alloc_tx_buf = NULL;
676 if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
678 (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
681 alloc_rx_buf & CACHELINE_MASK));
683 hw_p->rx = hw_p->alloc_rx_buf;
686 for (i = 0; i < NUM_TX_BUFF; i++) {
687 hw_p->tx[i].ctrl = 0;
688 hw_p->tx[i].data_len = 0;
689 if (hw_p->first_init == 0) {
691 (char *) malloc (ENET_MAX_MTU_ALIGNED);
692 if (NULL == hw_p->txbuf_ptr) {
693 free(hw_p->alloc_rx_buf);
694 free(hw_p->alloc_tx_buf);
695 hw_p->alloc_rx_buf = NULL;
696 hw_p->alloc_tx_buf = NULL;
697 for(j = 0; j < i; j++) {
698 free(hw_p->tx[i].data_ptr);
699 hw_p->tx[i].data_ptr = NULL;
703 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
704 if ((NUM_TX_BUFF - 1) == i)
705 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
706 hw_p->tx_run[i] = -1;
708 printf ("TX_BUFF %d @ 0x%08lx\n", i,
709 (ulong) hw_p->tx[i].data_ptr);
713 for (i = 0; i < NUM_RX_BUFF; i++) {
714 hw_p->rx[i].ctrl = 0;
715 hw_p->rx[i].data_len = 0;
716 /* rx[i].data_ptr = (char *) &rx_buff[i]; */
717 hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
718 if ((NUM_RX_BUFF - 1) == i)
719 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
720 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
721 hw_p->rx_ready[i] = -1;
723 printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr);
729 reg |= dev->enetaddr[0]; /* set high address */
731 reg |= dev->enetaddr[1];
733 out32 (EMAC_IAH + hw_p->hw_addr, reg);
736 reg |= dev->enetaddr[2]; /* set low address */
738 reg |= dev->enetaddr[3];
740 reg |= dev->enetaddr[4];
742 reg |= dev->enetaddr[5];
744 out32 (EMAC_IAL + hw_p->hw_addr, reg);
748 /* setup MAL tx & rx channel pointers */
749 #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
750 mtdcr (maltxctp2r, hw_p->tx);
752 mtdcr (maltxctp1r, hw_p->tx);
754 #if defined(CONFIG_440)
755 mtdcr (maltxbattr, 0x0);
756 mtdcr (malrxbattr, 0x0);
758 mtdcr (malrxctp1r, hw_p->rx);
759 /* set RX buffer size */
760 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
762 #if defined (CONFIG_440GX)
764 /* setup MAL tx & rx channel pointers */
765 mtdcr (maltxbattr, 0x0);
766 mtdcr (malrxbattr, 0x0);
767 mtdcr (maltxctp2r, hw_p->tx);
768 mtdcr (malrxctp2r, hw_p->rx);
769 /* set RX buffer size */
770 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
773 /* setup MAL tx & rx channel pointers */
774 mtdcr (maltxbattr, 0x0);
775 mtdcr (maltxctp3r, hw_p->tx);
776 mtdcr (malrxbattr, 0x0);
777 mtdcr (malrxctp3r, hw_p->rx);
778 /* set RX buffer size */
779 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
781 #endif /* CONFIG_440GX */
784 /* setup MAL tx & rx channel pointers */
785 #if defined(CONFIG_440)
786 mtdcr (maltxbattr, 0x0);
787 mtdcr (malrxbattr, 0x0);
789 mtdcr (maltxctp0r, hw_p->tx);
790 mtdcr (malrxctp0r, hw_p->rx);
791 /* set RX buffer size */
792 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
796 /* Enable MAL transmit and receive channels */
797 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
798 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
800 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
802 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
804 /* set transmit enable & receive enable */
805 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
807 /* set receive fifo to 4k and tx fifo to 2k */
808 mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
809 mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
812 if (speed == _1000BASET) {
813 #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
815 mfsdr (sdr_pfc1, pfc1);
816 pfc1 |= SDR0_PFC1_EM_1000;
817 mtsdr (sdr_pfc1, pfc1);
819 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
820 } else if (speed == _100BASET)
821 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
823 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
825 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
827 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
829 /* Enable broadcast and indvidual address */
830 /* TBS: enabling runts as some misbehaved nics will send runts */
831 out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
833 /* we probably need to set the tx mode1 reg? maybe at tx time */
835 /* set transmit request threshold register */
836 out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
838 /* set receive low/high water mark register */
839 #if defined(CONFIG_440)
840 /* 440s has a 64 byte burst length */
841 out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
843 /* 405s have a 16 byte burst length */
844 out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
845 #endif /* defined(CONFIG_440) */
846 out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
848 /* Set fifo limit entry in tx mode 0 */
849 out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
851 out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
854 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
855 if (speed == _100BASET)
856 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
858 out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
859 out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
861 if (hw_p->first_init == 0) {
863 * Connect interrupt service routines
865 irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2),
866 (interrupt_handler_t *) enetInt, dev);
869 mtmsr (msr); /* enable interrupts again */
872 hw_p->first_init = 1;
878 static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
881 struct enet_frame *ef_ptr;
882 ulong time_start, time_now;
883 unsigned long temp_txm0;
884 EMAC_4XX_HW_PST hw_p = dev->priv;
886 ef_ptr = (struct enet_frame *) ptr;
888 /*-----------------------------------------------------------------------+
889 * Copy in our address into the frame.
890 *-----------------------------------------------------------------------*/
891 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
893 /*-----------------------------------------------------------------------+
894 * If frame is too long or too short, modify length.
895 *-----------------------------------------------------------------------*/
896 /* TBS: where does the fragment go???? */
897 if (len > ENET_MAX_MTU)
900 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
901 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
903 /*-----------------------------------------------------------------------+
904 * set TX Buffer busy, and send it
905 *-----------------------------------------------------------------------*/
906 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
907 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
908 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
909 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
910 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
912 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
913 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
915 __asm__ volatile ("eieio");
917 out32 (EMAC_TXM0 + hw_p->hw_addr,
918 in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
920 hw_p->stats.pkts_tx++;
923 /*-----------------------------------------------------------------------+
924 * poll unitl the packet is sent and then make sure it is OK
925 *-----------------------------------------------------------------------*/
926 time_start = get_timer (0);
928 temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
929 /* loop until either TINT turns on or 3 seconds elapse */
930 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
931 /* transmit is done, so now check for errors
932 * If there is an error, an interrupt should
933 * happen when we return
935 time_now = get_timer (0);
936 if ((time_now - time_start) > 3000) {
946 #if defined (CONFIG_440)
948 #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
950 * Hack: On 440SP all enet irq sources are located on UIC1
951 * Needs some cleanup. --sr
953 #define UIC0MSR uic1msr
954 #define UIC0SR uic1sr
956 #define UIC0MSR uic0msr
957 #define UIC0SR uic0sr
960 int enetInt (struct eth_device *dev)
963 int rc = -1; /* default to not us */
964 unsigned long mal_isr;
965 unsigned long emac_isr = 0;
966 unsigned long mal_rx_eob;
967 unsigned long my_uic0msr, my_uic1msr;
969 #if defined(CONFIG_440GX)
970 unsigned long my_uic2msr;
972 EMAC_4XX_HW_PST hw_p;
975 * Because the mal is generic, we need to get the current
978 #if defined(CONFIG_NET_MULTI)
986 /* enter loop that stays in interrupt code until nothing to service */
990 my_uic0msr = mfdcr (UIC0MSR);
991 my_uic1msr = mfdcr (uic1msr);
992 #if defined(CONFIG_440GX)
993 my_uic2msr = mfdcr (uic2msr);
995 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
996 && !(my_uic1msr & (UIC_ETH0 | UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE))) {
1000 #if defined (CONFIG_440GX)
1001 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
1002 && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
1007 /* get and clear controller status interrupts */
1008 /* look at Mal and EMAC interrupts */
1009 if ((my_uic0msr & (UIC_MRE | UIC_MTE))
1010 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1011 /* we have a MAL interrupt */
1012 mal_isr = mfdcr (malesr);
1013 /* look for mal error */
1014 if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
1015 mal_err (dev, mal_isr, my_uic0msr,
1016 MAL_UIC_DEF, MAL_UIC_ERR);
1022 /* port by port dispatch of emac interrupts */
1023 if (hw_p->devnum == 0) {
1024 if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */
1025 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1026 if ((hw_p->emac_ier & emac_isr) != 0) {
1027 emac_err (dev, emac_isr);
1032 if ((hw_p->emac_ier & emac_isr)
1033 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1034 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
1035 mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1036 return (rc); /* we had errors so get out */
1040 #if !defined(CONFIG_440SP)
1041 if (hw_p->devnum == 1) {
1042 if (UIC_ETH1 & my_uic1msr) { /* look for EMAC errors */
1043 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1044 if ((hw_p->emac_ier & emac_isr) != 0) {
1045 emac_err (dev, emac_isr);
1050 if ((hw_p->emac_ier & emac_isr)
1051 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1052 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
1053 mtdcr (uic1sr, UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1054 return (rc); /* we had errors so get out */
1057 #if defined (CONFIG_440GX)
1058 if (hw_p->devnum == 2) {
1059 if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
1060 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1061 if ((hw_p->emac_ier & emac_isr) != 0) {
1062 emac_err (dev, emac_isr);
1067 if ((hw_p->emac_ier & emac_isr)
1068 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1069 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
1070 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1071 mtdcr (uic2sr, UIC_ETH2);
1072 return (rc); /* we had errors so get out */
1076 if (hw_p->devnum == 3) {
1077 if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
1078 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1079 if ((hw_p->emac_ier & emac_isr) != 0) {
1080 emac_err (dev, emac_isr);
1085 if ((hw_p->emac_ier & emac_isr)
1086 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1087 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
1088 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1089 mtdcr (uic2sr, UIC_ETH3);
1090 return (rc); /* we had errors so get out */
1093 #endif /* CONFIG_440GX */
1094 #endif /* !CONFIG_440SP */
1096 /* handle MAX TX EOB interrupt from a tx */
1097 if (my_uic0msr & UIC_MTE) {
1098 mal_rx_eob = mfdcr (maltxeobisr);
1099 mtdcr (maltxeobisr, mal_rx_eob);
1100 mtdcr (UIC0SR, UIC_MTE);
1102 /* handle MAL RX EOB interupt from a receive */
1103 /* check for EOB on valid channels */
1104 if (my_uic0msr & UIC_MRE) {
1105 mal_rx_eob = mfdcr (malrxeobisr);
1106 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
1108 mtdcr(malrxeobisr, mal_rx_eob); */
1109 enet_rcv (dev, emac_isr);
1110 /* indicate that we serviced an interrupt */
1116 mtdcr (UIC0SR, UIC_MRE); /* Clear */
1117 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1118 switch (hw_p->devnum) {
1120 mtdcr (uic1sr, UIC_ETH0);
1123 mtdcr (uic1sr, UIC_ETH1);
1125 #if defined (CONFIG_440GX)
1127 mtdcr (uic2sr, UIC_ETH2);
1130 mtdcr (uic2sr, UIC_ETH3);
1132 #endif /* CONFIG_440GX */
1141 #else /* CONFIG_440 */
1143 int enetInt (struct eth_device *dev)
1146 int rc = -1; /* default to not us */
1147 unsigned long mal_isr;
1148 unsigned long emac_isr = 0;
1149 unsigned long mal_rx_eob;
1150 unsigned long my_uicmsr;
1152 EMAC_4XX_HW_PST hw_p;
1155 * Because the mal is generic, we need to get the current
1158 #if defined(CONFIG_NET_MULTI)
1159 dev = eth_get_dev();
1166 /* enter loop that stays in interrupt code until nothing to service */
1170 my_uicmsr = mfdcr (uicmsr);
1172 if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) { /* not for us */
1175 /* get and clear controller status interrupts */
1176 /* look at Mal and EMAC interrupts */
1177 if ((MAL_UIC_DEF & my_uicmsr) != 0) { /* we have a MAL interrupt */
1178 mal_isr = mfdcr (malesr);
1179 /* look for mal error */
1180 if ((my_uicmsr & MAL_UIC_ERR) != 0) {
1181 mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR);
1187 /* port by port dispatch of emac interrupts */
1189 if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) { /* look for EMAC errors */
1190 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1191 if ((hw_p->emac_ier & emac_isr) != 0) {
1192 emac_err (dev, emac_isr);
1197 if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) {
1198 mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */
1199 return (rc); /* we had errors so get out */
1202 /* handle MAX TX EOB interrupt from a tx */
1203 if (my_uicmsr & UIC_MAL_TXEOB) {
1204 mal_rx_eob = mfdcr (maltxeobisr);
1205 mtdcr (maltxeobisr, mal_rx_eob);
1206 mtdcr (uicsr, UIC_MAL_TXEOB);
1208 /* handle MAL RX EOB interupt from a receive */
1209 /* check for EOB on valid channels */
1210 if (my_uicmsr & UIC_MAL_RXEOB)
1212 mal_rx_eob = mfdcr (malrxeobisr);
1213 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
1215 mtdcr(malrxeobisr, mal_rx_eob); */
1216 enet_rcv (dev, emac_isr);
1217 /* indicate that we serviced an interrupt */
1222 mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1); /* Clear */
1229 #endif /* CONFIG_440 */
1231 /*-----------------------------------------------------------------------------+
1233 *-----------------------------------------------------------------------------*/
1234 static void mal_err (struct eth_device *dev, unsigned long isr,
1235 unsigned long uic, unsigned long maldef,
1236 unsigned long mal_errr)
1238 EMAC_4XX_HW_PST hw_p = dev->priv;
1240 mtdcr (malesr, isr); /* clear interrupt */
1242 /* clear DE interrupt */
1243 mtdcr (maltxdeir, 0xC0000000);
1244 mtdcr (malrxdeir, 0x80000000);
1246 #ifdef INFO_4XX_ENET
1247 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
1250 eth_init (hw_p->bis); /* start again... */
1253 /*-----------------------------------------------------------------------------+
1254 * EMAC Error Routine
1255 *-----------------------------------------------------------------------------*/
1256 static void emac_err (struct eth_device *dev, unsigned long isr)
1258 EMAC_4XX_HW_PST hw_p = dev->priv;
1260 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
1261 out32 (EMAC_ISR + hw_p->hw_addr, isr);
1264 /*-----------------------------------------------------------------------------+
1265 * enet_rcv() handles the ethernet receive data
1266 *-----------------------------------------------------------------------------*/
1267 static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1269 struct enet_frame *ef_ptr;
1270 unsigned long data_len;
1271 unsigned long rx_eob_isr;
1272 EMAC_4XX_HW_PST hw_p = dev->priv;
1278 rx_eob_isr = mfdcr (malrxeobisr);
1279 if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
1281 mtdcr (malrxeobisr, rx_eob_isr);
1284 while (1) { /* do all */
1287 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1288 || (loop_count >= NUM_RX_BUFF))
1292 if (NUM_RX_BUFF == hw_p->rx_slot)
1295 data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
1297 if (data_len > ENET_MAX_MTU) /* Check len */
1300 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1302 hw_p->stats.rx_err_log[hw_p->
1305 hw_p->rx_err_index++;
1306 if (hw_p->rx_err_index ==
1308 hw_p->rx_err_index =
1311 } /* data_len < max mtu */
1313 if (!data_len) { /* no data */
1314 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1316 hw_p->stats.data_len_err++; /* Error at Rx */
1321 /* Check if user has already eaten buffer */
1322 /* if not => ERROR */
1323 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1324 if (hw_p->is_receiving)
1325 printf ("ERROR : Receive buffers are full!\n");
1328 hw_p->stats.rx_frames++;
1329 hw_p->stats.rx += data_len;
1330 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1332 #ifdef INFO_4XX_ENET
1333 hw_p->stats.pkts_rx++;
1338 hw_p->rx_ready[hw_p->rx_i_index] = i;
1340 if (NUM_RX_BUFF == hw_p->rx_i_index)
1341 hw_p->rx_i_index = 0;
1344 * free receive buffer only when
1345 * buffer has been handled (eth_rx)
1346 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1350 } /* if EMACK_RXCHL */
1354 static int ppc_4xx_eth_rx (struct eth_device *dev)
1359 EMAC_4XX_HW_PST hw_p = dev->priv;
1361 hw_p->is_receiving = 1; /* tell driver */
1365 * use ring buffer and
1366 * get index from rx buffer desciptor queue
1368 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1369 if (user_index == -1) {
1371 break; /* nothing received - leave for() loop */
1375 mtmsr (msr & ~(MSR_EE));
1377 length = hw_p->rx[user_index].data_len;
1379 /* Pass the packet up to the protocol layers. */
1380 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1381 /* NetReceive(NetRxPackets[i], length); */
1382 NetReceive (NetRxPackets[user_index], length - 4);
1383 /* Free Recv Buffer */
1384 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1385 /* Free rx buffer descriptor queue */
1386 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1388 if (NUM_RX_BUFF == hw_p->rx_u_index)
1389 hw_p->rx_u_index = 0;
1391 #ifdef INFO_4XX_ENET
1392 hw_p->stats.pkts_handled++;
1395 mtmsr (msr); /* Enable IRQ's */
1398 hw_p->is_receiving = 0; /* tell driver */
1403 int ppc_4xx_eth_initialize (bd_t * bis)
1405 static int virgin = 0;
1406 struct eth_device *dev;
1408 EMAC_4XX_HW_PST hw = NULL;
1410 #if defined(CONFIG_440GX)
1413 mfsdr (sdr_pfc1, pfc1);
1414 pfc1 &= ~(0x01e00000);
1416 mtsdr (sdr_pfc1, pfc1);
1418 /* set phy num and mode */
1419 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
1420 bis->bi_phymode[0] = 0;
1422 #if defined(CONFIG_PHY1_ADDR)
1423 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
1424 bis->bi_phymode[1] = 0;
1426 #if defined(CONFIG_440GX)
1427 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1428 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1429 bis->bi_phymode[2] = 2;
1430 bis->bi_phymode[3] = 2;
1432 ppc_4xx_eth_setup_bridge(0, bis);
1435 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1437 /* See if we can actually bring up the interface, otherwise, skip it */
1439 default: /* fall through */
1441 if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
1442 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1446 #ifdef CONFIG_HAS_ETH1
1448 if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
1449 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1454 #ifdef CONFIG_HAS_ETH2
1456 if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) {
1457 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1462 #ifdef CONFIG_HAS_ETH3
1464 if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) {
1465 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1472 /* Allocate device structure */
1473 dev = (struct eth_device *) malloc (sizeof (*dev));
1475 printf ("ppc_4xx_eth_initialize: "
1476 "Cannot allocate eth_device %d\n", eth_num);
1479 memset(dev, 0, sizeof(*dev));
1481 /* Allocate our private use data */
1482 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
1484 printf ("ppc_4xx_eth_initialize: "
1485 "Cannot allocate private hw data for eth_device %d",
1490 memset(hw, 0, sizeof(*hw));
1493 default: /* fall through */
1496 memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
1498 #ifdef CONFIG_HAS_ETH1
1500 hw->hw_addr = 0x100;
1501 memcpy (dev->enetaddr, bis->bi_enet1addr, 6);
1504 #ifdef CONFIG_HAS_ETH2
1506 hw->hw_addr = 0x400;
1507 memcpy (dev->enetaddr, bis->bi_enet2addr, 6);
1510 #ifdef CONFIG_HAS_ETH3
1512 hw->hw_addr = 0x600;
1513 memcpy (dev->enetaddr, bis->bi_enet3addr, 6);
1518 hw->devnum = eth_num;
1519 hw->print_speed = 1;
1521 sprintf (dev->name, "ppc_4xx_eth%d", eth_num);
1522 dev->priv = (void *) hw;
1523 dev->init = ppc_4xx_eth_init;
1524 dev->halt = ppc_4xx_eth_halt;
1525 dev->send = ppc_4xx_eth_send;
1526 dev->recv = ppc_4xx_eth_rx;
1529 /* set the MAL IER ??? names may change with new spec ??? */
1530 #if defined(CONFIG_440SPE)
1532 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
1533 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
1536 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
1537 MAL_IER_OPBE | MAL_IER_PLBE;
1539 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
1540 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
1541 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
1542 mtdcr (malier, mal_ier);
1544 /* install MAL interrupt handler */
1545 irq_install_handler (VECNUM_MS,
1546 (interrupt_handler_t *) enetInt,
1548 irq_install_handler (VECNUM_MTE,
1549 (interrupt_handler_t *) enetInt,
1551 irq_install_handler (VECNUM_MRE,
1552 (interrupt_handler_t *) enetInt,
1554 irq_install_handler (VECNUM_TXDE,
1555 (interrupt_handler_t *) enetInt,
1557 irq_install_handler (VECNUM_RXDE,
1558 (interrupt_handler_t *) enetInt,
1563 #if defined(CONFIG_NET_MULTI)
1569 #if defined(CONFIG_NET_MULTI)
1570 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
1571 miiphy_register (dev->name,
1572 emac4xx_miiphy_read, emac4xx_miiphy_write);
1575 } /* end for each supported device */
1580 #if !defined(CONFIG_NET_MULTI)
1581 void eth_halt (void) {
1583 ppc_4xx_eth_halt(emac0_dev);
1589 int eth_init (bd_t *bis)
1591 ppc_4xx_eth_initialize(bis);
1593 return ppc_4xx_eth_init(emac0_dev, bis);
1595 printf("ERROR: ethaddr not set!\n");
1600 int eth_send(volatile void *packet, int length)
1602 return (ppc_4xx_eth_send(emac0_dev, packet, length));
1607 return (ppc_4xx_eth_rx(emac0_dev));
1610 int emac4xx_miiphy_initialize (bd_t * bis)
1612 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
1613 miiphy_register ("ppc_4xx_eth0",
1614 emac4xx_miiphy_read, emac4xx_miiphy_write);
1619 #endif /* !defined(CONFIG_NET_MULTI) */
1621 #endif /* #if (CONFIG_COMMANDS & CFG_CMD_NET) */