1 /*-----------------------------------------------------------------------------+
2 * This source code is dual-licensed. You may use it under the terms of the
3 * GNU General Public License version 2, or under the license below.
5 * This source code has been made available to you by IBM on an AS-IS
6 * basis. Anyone receiving this source is licensed under IBM
7 * copyrights to use it in any way he or she deems fit, including
8 * copying it, modifying it, compiling it, and redistributing it either
9 * with or without modifications. No license under IBM patents or
10 * patent applications is to be implied by the copyright license.
12 * Any user of this software should understand that IBM cannot provide
13 * technical support for this software and will not be responsible for
14 * any consequences resulting from the use of this software.
16 * Any person who transfers this source code or any derivative work
17 * must include the IBM copyright notice, this paragraph, and the
18 * preceding two paragraphs in the transferred software.
20 * COPYRIGHT I B M CORPORATION 1995
21 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
22 *-----------------------------------------------------------------------------*/
23 /*-----------------------------------------------------------------------------+
25 * File Name: enetemac.c
27 * Function: Device driver for the ethernet EMAC3 macro on the 405GP.
33 * Date Description of Change BY
34 * --------- --------------------- ---
35 * 05-May-99 Created MKW
36 * 27-Jun-99 Clean up JWB
37 * 16-Jul-99 Added MAL error recovery and better IP packet handling MKW
38 * 29-Jul-99 Added Full duplex support MKW
39 * 06-Aug-99 Changed names for Mal CR reg MKW
40 * 23-Aug-99 Turned off SYE when running at 10Mbs MKW
41 * 24-Aug-99 Marked descriptor empty after call_xlc MKW
42 * 07-Sep-99 Set MAL RX buffer size reg to ENET_MAX_MTU_ALIGNED / 16 MCG
43 * to avoid chaining maximum sized packets. Push starting
44 * RX descriptor address up to the next cache line boundary.
45 * 16-Jan-00 Added support for booting with IP of 0x0 MKW
46 * 15-Mar-00 Updated enetInit() to enable broadcast addresses in the
47 * EMAC0_RXM register. JWB
48 * 12-Mar-01 anne-sophie.harnois@nextream.fr
49 * - Variables are compatible with those already defined in
51 * - Receive buffer descriptor ring is used to send buffers
53 * - Info print about send/received/handled packet number if
54 * INFO_405_ENET is set
55 * 17-Apr-01 stefan.roese@esd-electronics.com
56 * - MAL reset in "eth_halt" included
57 * - Enet speed and duplex output now in one line
58 * 08-May-01 stefan.roese@esd-electronics.com
59 * - MAL error handling added (eth_init called again)
60 * 13-Nov-01 stefan.roese@esd-electronics.com
61 * - Set IST bit in EMAC0_MR1 reg upon 100MBit or full duplex
62 * 04-Jan-02 stefan.roese@esd-electronics.com
63 * - Wait for PHY auto negotiation to complete added
64 * 06-Feb-02 stefan.roese@esd-electronics.com
65 * - Bug fixed in waiting for auto negotiation to complete
66 * 26-Feb-02 stefan.roese@esd-electronics.com
67 * - rx and tx buffer descriptors now allocated (no fixed address
69 * 17-Jun-02 stefan.roese@esd-electronics.com
70 * - MAL error debug printf 'M' removed (rx de interrupt may
71 * occur upon many incoming packets with only 4 rx buffers).
72 *-----------------------------------------------------------------------------*
73 * 17-Nov-03 travis.sawyer@sandburst.com
74 * - ported from 405gp_enet.c to utilized upto 4 EMAC ports
75 * in the 440GX. This port should work with the 440GP
77 * 15-Aug-05 sr@denx.de
78 * - merged 405gp_enet.c and 440gx_enet.c to generic 4xx_enet.c
79 now handling all 4xx cpu's.
80 *-----------------------------------------------------------------------------*/
85 #include <asm/processor.h>
87 #include <asm/cache.h>
90 #include <asm/ppc4xx.h>
91 #include <asm/ppc4xx-emac.h>
92 #include <asm/ppc4xx-mal.h>
96 #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
97 #error "CONFIG_MII has to be defined!"
100 #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
101 #define PHY_AUTONEGOTIATE_TIMEOUT 5000 /* 5000 ms autonegotiate timeout */
103 /* Ethernet Transmit and Receive Buffers */
105 * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
106 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
108 #define ENET_MAX_MTU PKTSIZE
109 #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
111 /*-----------------------------------------------------------------------------+
112 * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
113 * Interrupt Controller).
114 *-----------------------------------------------------------------------------*/
115 #define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * VECNUM_ETH1_OFFS))
117 #if defined(CONFIG_HAS_ETH3)
118 #if !defined(CONFIG_440GX)
119 #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
120 UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
122 /* Unfortunately 440GX spreads EMAC interrupts on multiple UIC's */
123 #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
124 #define UIC_ETHxB (UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
125 #endif /* !defined(CONFIG_440GX) */
126 #elif defined(CONFIG_HAS_ETH2)
127 #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
128 UIC_MASK(ETH_IRQ_NUM(2)))
129 #elif defined(CONFIG_HAS_ETH1)
130 #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
132 #define UIC_ETHx UIC_MASK(ETH_IRQ_NUM(0))
136 * Define a default version for UIC_ETHxB for non 440GX so that we can
137 * use common code for all 4xx variants
139 #if !defined(UIC_ETHxB)
143 #define UIC_MAL_SERR UIC_MASK(VECNUM_MAL_SERR)
144 #define UIC_MAL_TXDE UIC_MASK(VECNUM_MAL_TXDE)
145 #define UIC_MAL_RXDE UIC_MASK(VECNUM_MAL_RXDE)
146 #define UIC_MAL_TXEOB UIC_MASK(VECNUM_MAL_TXEOB)
147 #define UIC_MAL_RXEOB UIC_MASK(VECNUM_MAL_RXEOB)
149 #define MAL_UIC_ERR (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
150 #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
153 * We have 3 different interrupt types:
154 * - MAL interrupts indicating successful transfer
155 * - MAL error interrupts indicating MAL related errors
156 * - EMAC interrupts indicating EMAC related errors
158 * All those interrupts can be on different UIC's, but since
159 * now at least all interrupts from one type are on the same
160 * UIC. Only exception is 440GX where the EMAC interrupts are
161 * spread over two UIC's!
163 #if defined(CONFIG_440GX)
164 #define UIC_BASE_MAL UIC1_DCR_BASE
165 #define UIC_BASE_MAL_ERR UIC2_DCR_BASE
166 #define UIC_BASE_EMAC UIC2_DCR_BASE
167 #define UIC_BASE_EMAC_B UIC3_DCR_BASE
169 #define UIC_BASE_MAL (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_TXEOB) * 0x10))
170 #define UIC_BASE_MAL_ERR (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_SERR) * 0x10))
171 #define UIC_BASE_EMAC (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
172 #define UIC_BASE_EMAC_B (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
177 #define BI_PHYMODE_NONE 0
178 #define BI_PHYMODE_ZMII 1
179 #define BI_PHYMODE_RGMII 2
180 #define BI_PHYMODE_GMII 3
181 #define BI_PHYMODE_RTBI 4
182 #define BI_PHYMODE_TBI 5
183 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
184 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
185 defined(CONFIG_405EX)
186 #define BI_PHYMODE_SMII 6
187 #define BI_PHYMODE_MII 7
188 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
189 #define BI_PHYMODE_RMII 8
192 #define BI_PHYMODE_SGMII 9
194 #if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
195 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
196 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
197 defined(CONFIG_405EX)
198 #define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
201 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
202 #define SDR0_ETH_CFG_CLK_SEL_V(n) (0x01 << (8 + n))
205 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
206 #define MAL_RX_CHAN_MUL 8 /* 460EX/GT uses MAL channel 8 for EMAC1 */
208 #define MAL_RX_CHAN_MUL 1
211 /*--------------------------------------------------------------------+
212 * Fixed PHY (PHY-less) support for Ethernet Ports.
213 *--------------------------------------------------------------------*/
216 * Some boards do not have a PHY for each ethernet port. These ports
217 * are known as Fixed PHY (or PHY-less) ports. For such ports, set
218 * the appropriate CONFIG_PHY_ADDR equal to CONFIG_FIXED_PHY and
219 * then define CONFIG_SYS_FIXED_PHY_PORTS to define what the speed and
220 * duplex should be for these ports in the board configuration
224 * #define CONFIG_FIXED_PHY 0xFFFFFFFF
226 * #define CONFIG_PHY_ADDR CONFIG_FIXED_PHY
227 * #define CONFIG_PHY1_ADDR 1
228 * #define CONFIG_PHY2_ADDR CONFIG_FIXED_PHY
229 * #define CONFIG_PHY3_ADDR 3
231 * #define CONFIG_SYS_FIXED_PHY_PORT(devnum,speed,duplex) \
232 * {devnum, speed, duplex},
234 * #define CONFIG_SYS_FIXED_PHY_PORTS \
235 * CONFIG_SYS_FIXED_PHY_PORT(0,1000,FULL) \
236 * CONFIG_SYS_FIXED_PHY_PORT(2,100,HALF)
239 #ifndef CONFIG_FIXED_PHY
240 #define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */
243 #ifndef CONFIG_SYS_FIXED_PHY_PORTS
244 #define CONFIG_SYS_FIXED_PHY_PORTS /* default is an empty array */
247 struct fixed_phy_port {
248 unsigned int devnum; /* ethernet port */
249 unsigned int speed; /* specified speed 10,100 or 1000 */
250 unsigned int duplex; /* specified duplex FULL or HALF */
253 static const struct fixed_phy_port fixed_phy_port[] = {
254 CONFIG_SYS_FIXED_PHY_PORTS /* defined in board configuration file */
257 /*-----------------------------------------------------------------------------+
258 * Global variables. TX and RX descriptors and buffers.
259 *-----------------------------------------------------------------------------*/
262 * Get count of EMAC devices (doesn't have to be the max. possible number
263 * supported by the cpu)
265 * CONFIG_BOARD_EMAC_COUNT added so now a "dynamic" way to configure the
266 * EMAC count is possible. As it is needed for the Kilauea/Haleakala
267 * 405EX/405EXr eval board, using the same binary.
269 #if defined(CONFIG_BOARD_EMAC_COUNT)
270 #define LAST_EMAC_NUM board_emac_count()
271 #else /* CONFIG_BOARD_EMAC_COUNT */
272 #if defined(CONFIG_HAS_ETH3)
273 #define LAST_EMAC_NUM 4
274 #elif defined(CONFIG_HAS_ETH2)
275 #define LAST_EMAC_NUM 3
276 #elif defined(CONFIG_HAS_ETH1)
277 #define LAST_EMAC_NUM 2
279 #define LAST_EMAC_NUM 1
281 #endif /* CONFIG_BOARD_EMAC_COUNT */
283 /* normal boards start with EMAC0 */
284 #if !defined(CONFIG_EMAC_NR_START)
285 #define CONFIG_EMAC_NR_START 0
288 #define MAL_RX_DESC_SIZE 2048
289 #define MAL_TX_DESC_SIZE 2048
290 #define MAL_ALLOC_SIZE (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE)
292 /*-----------------------------------------------------------------------------+
293 * Prototypes and externals.
294 *-----------------------------------------------------------------------------*/
295 static void enet_rcv (struct eth_device *dev, unsigned long malisr);
297 int enetInt (struct eth_device *dev);
298 static void mal_err (struct eth_device *dev, unsigned long isr,
299 unsigned long uic, unsigned long maldef,
300 unsigned long mal_errr);
301 static void emac_err (struct eth_device *dev, unsigned long isr);
303 extern int phy_setup_aneg (char *devname, unsigned char addr);
304 extern int emac4xx_miiphy_read (const char *devname, unsigned char addr,
305 unsigned char reg, unsigned short *value);
306 extern int emac4xx_miiphy_write (const char *devname, unsigned char addr,
307 unsigned char reg, unsigned short value);
309 int board_emac_count(void);
311 static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p)
313 #if defined(CONFIG_440SPE) || \
314 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
315 defined(CONFIG_405EX)
318 mfsdr(SDR0_MFR, val);
319 val |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
320 mtsdr(SDR0_MFR, val);
321 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
324 mfsdr(SDR0_ETH_CFG, val);
325 val |= SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
326 mtsdr(SDR0_ETH_CFG, val);
330 static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p)
332 #if defined(CONFIG_440SPE) || \
333 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
334 defined(CONFIG_405EX)
337 mfsdr(SDR0_MFR, val);
338 val &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
339 mtsdr(SDR0_MFR, val);
340 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
343 mfsdr(SDR0_ETH_CFG, val);
344 val &= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
345 mtsdr(SDR0_ETH_CFG, val);
349 /*-----------------------------------------------------------------------------+
351 | Disable MAL channel, and EMACn
352 +-----------------------------------------------------------------------------*/
353 static void ppc_4xx_eth_halt (struct eth_device *dev)
355 EMAC_4XX_HW_PST hw_p = dev->priv;
358 out_be32((void *)EMAC0_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
360 /* 1st reset MAL channel */
361 /* Note: writing a 0 to a channel has no effect */
362 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
363 mtdcr (MAL0_TXCARR, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
365 mtdcr (MAL0_TXCARR, (MAL_CR_MMSR >> hw_p->devnum));
367 mtdcr (MAL0_RXCARR, (MAL_CR_MMSR >> hw_p->devnum));
370 while (mfdcr (MAL0_RXCASR) & (MAL_CR_MMSR >> hw_p->devnum)) {
371 udelay (1000); /* Delay 1 MS so as not to hammer the register */
377 /* provide clocks for EMAC internal loopback */
378 emac_loopback_enable(hw_p);
381 out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_SRST);
383 /* remove clocks for EMAC internal loopback */
384 emac_loopback_disable(hw_p);
386 #ifndef CONFIG_NETCONSOLE
387 hw_p->print_speed = 1; /* print speed message again next time */
390 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
391 /* don't bypass the TAHOE0/TAHOE1 cores for Linux */
392 mfsdr(SDR0_ETH_CFG, val);
393 val &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
394 mtsdr(SDR0_ETH_CFG, val);
400 #if defined (CONFIG_440GX)
401 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
404 unsigned long zmiifer;
405 unsigned long rmiifer;
407 mfsdr(SDR0_PFC1, pfc1);
408 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
415 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
416 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
417 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
418 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
419 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
420 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
421 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
422 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
425 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
426 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
427 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
428 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
429 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
430 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
431 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
432 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
435 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
436 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
437 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
438 bis->bi_phymode[1] = BI_PHYMODE_NONE;
439 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
440 bis->bi_phymode[3] = BI_PHYMODE_NONE;
443 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
444 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
445 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
446 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
447 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
448 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
449 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
450 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
453 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
454 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
455 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
456 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
457 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
458 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
459 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
460 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
463 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
464 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
465 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
466 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
467 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
468 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
472 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
474 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
475 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
476 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
477 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
481 /* Ensure we setup mdio for this devnum and ONLY this devnum */
482 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
484 out_be32((void *)ZMII0_FER, zmiifer);
485 out_be32((void *)RGMII_FER, rmiifer);
489 #endif /* CONFIG_440_GX */
491 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
492 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
494 unsigned long zmiifer=0x0;
497 mfsdr(SDR0_PFC1, pfc1);
498 pfc1 &= SDR0_PFC1_SELECT_MASK;
501 case SDR0_PFC1_SELECT_CONFIG_2:
503 out_be32((void *)ZMII0_FER, 0x00);
504 out_be32((void *)RGMII_FER, 0x00000037);
505 bis->bi_phymode[0] = BI_PHYMODE_GMII;
506 bis->bi_phymode[1] = BI_PHYMODE_NONE;
508 case SDR0_PFC1_SELECT_CONFIG_4:
509 /* 2 x RGMII ports */
510 out_be32((void *)ZMII0_FER, 0x00);
511 out_be32((void *)RGMII_FER, 0x00000055);
512 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
513 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
515 case SDR0_PFC1_SELECT_CONFIG_6:
517 out_be32((void *)ZMII0_FER,
518 ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
519 ((ZMII_FER_SMII) << ZMII_FER_V(1)));
520 out_be32((void *)RGMII_FER, 0x00000000);
521 bis->bi_phymode[0] = BI_PHYMODE_SMII;
522 bis->bi_phymode[1] = BI_PHYMODE_SMII;
524 case SDR0_PFC1_SELECT_CONFIG_1_2:
525 /* only 1 x MII supported */
526 out_be32((void *)ZMII0_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
527 out_be32((void *)RGMII_FER, 0x00000000);
528 bis->bi_phymode[0] = BI_PHYMODE_MII;
529 bis->bi_phymode[1] = BI_PHYMODE_NONE;
535 /* Ensure we setup mdio for this devnum and ONLY this devnum */
536 zmiifer = in_be32((void *)ZMII0_FER);
537 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
538 out_be32((void *)ZMII0_FER, zmiifer);
542 #endif /* CONFIG_440EPX */
544 #if defined(CONFIG_405EX)
545 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
550 * The 405EX(r)'s RGMII bridge can operate in one of several
551 * modes, only one of which (2 x RGMII) allows the
552 * simultaneous use of both EMACs on the 405EX.
555 switch (CONFIG_EMAC_PHY_MODE) {
557 case EMAC_PHY_MODE_NONE:
559 rgmiifer |= RGMII_FER_DIS << 0;
560 rgmiifer |= RGMII_FER_DIS << 4;
561 out_be32((void *)RGMII_FER, rgmiifer);
562 bis->bi_phymode[0] = BI_PHYMODE_NONE;
563 bis->bi_phymode[1] = BI_PHYMODE_NONE;
565 case EMAC_PHY_MODE_NONE_RGMII:
566 /* 1 x RGMII port on channel 0 */
567 rgmiifer |= RGMII_FER_RGMII << 0;
568 rgmiifer |= RGMII_FER_DIS << 4;
569 out_be32((void *)RGMII_FER, rgmiifer);
570 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
571 bis->bi_phymode[1] = BI_PHYMODE_NONE;
573 case EMAC_PHY_MODE_RGMII_NONE:
574 /* 1 x RGMII port on channel 1 */
575 rgmiifer |= RGMII_FER_DIS << 0;
576 rgmiifer |= RGMII_FER_RGMII << 4;
577 out_be32((void *)RGMII_FER, rgmiifer);
578 bis->bi_phymode[0] = BI_PHYMODE_NONE;
579 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
581 case EMAC_PHY_MODE_RGMII_RGMII:
582 /* 2 x RGMII ports */
583 rgmiifer |= RGMII_FER_RGMII << 0;
584 rgmiifer |= RGMII_FER_RGMII << 4;
585 out_be32((void *)RGMII_FER, rgmiifer);
586 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
587 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
589 case EMAC_PHY_MODE_NONE_GMII:
590 /* 1 x GMII port on channel 0 */
591 rgmiifer |= RGMII_FER_GMII << 0;
592 rgmiifer |= RGMII_FER_DIS << 4;
593 out_be32((void *)RGMII_FER, rgmiifer);
594 bis->bi_phymode[0] = BI_PHYMODE_GMII;
595 bis->bi_phymode[1] = BI_PHYMODE_NONE;
597 case EMAC_PHY_MODE_NONE_MII:
598 /* 1 x MII port on channel 0 */
599 rgmiifer |= RGMII_FER_MII << 0;
600 rgmiifer |= RGMII_FER_DIS << 4;
601 out_be32((void *)RGMII_FER, rgmiifer);
602 bis->bi_phymode[0] = BI_PHYMODE_MII;
603 bis->bi_phymode[1] = BI_PHYMODE_NONE;
605 case EMAC_PHY_MODE_GMII_NONE:
606 /* 1 x GMII port on channel 1 */
607 rgmiifer |= RGMII_FER_DIS << 0;
608 rgmiifer |= RGMII_FER_GMII << 4;
609 out_be32((void *)RGMII_FER, rgmiifer);
610 bis->bi_phymode[0] = BI_PHYMODE_NONE;
611 bis->bi_phymode[1] = BI_PHYMODE_GMII;
613 case EMAC_PHY_MODE_MII_NONE:
614 /* 1 x MII port on channel 1 */
615 rgmiifer |= RGMII_FER_DIS << 0;
616 rgmiifer |= RGMII_FER_MII << 4;
617 out_be32((void *)RGMII_FER, rgmiifer);
618 bis->bi_phymode[0] = BI_PHYMODE_NONE;
619 bis->bi_phymode[1] = BI_PHYMODE_MII;
625 /* Ensure we setup mdio for this devnum and ONLY this devnum */
626 rgmiifer = in_be32((void *)RGMII_FER);
627 rgmiifer |= (1 << (19-devnum));
628 out_be32((void *)RGMII_FER, rgmiifer);
632 #endif /* CONFIG_405EX */
634 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
635 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
638 u32 zmiifer; /* ZMII0_FER reg. */
639 u32 rmiifer; /* RGMII0_FER reg. Bridge 0 */
640 u32 rmiifer1; /* RGMII0_FER reg. Bridge 1 */
647 #if defined(CONFIG_460EX)
649 mfsdr(SDR0_ETH_CFG, eth_cfg);
650 if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
651 ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0))
652 mode = 11; /* config SGMII */
655 mfsdr(SDR0_ETH_CFG, eth_cfg);
656 if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
657 ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0) &&
658 ((eth_cfg & SDR0_ETH_CFG_SGMII2_ENABLE) > 0))
659 mode = 12; /* config SGMII */
663 * NOTE: 460GT has 2 RGMII bridge cores:
664 * emac0 ------ RGMII0_BASE
668 * emac2 ------ RGMII1_BASE
672 * 460EX has 1 RGMII bridge core:
673 * and RGMII1_BASE is disabled
674 * emac0 ------ RGMII0_BASE
680 * Right now only 2*RGMII is supported. Please extend when needed.
688 /* GMC0 EMAC4_0, ZMII Bridge */
689 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
690 bis->bi_phymode[0] = BI_PHYMODE_MII;
691 bis->bi_phymode[1] = BI_PHYMODE_NONE;
692 bis->bi_phymode[2] = BI_PHYMODE_NONE;
693 bis->bi_phymode[3] = BI_PHYMODE_NONE;
697 /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */
698 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
699 zmiifer |= ZMII_FER_MII << ZMII_FER_V(2);
700 bis->bi_phymode[0] = BI_PHYMODE_MII;
701 bis->bi_phymode[1] = BI_PHYMODE_NONE;
702 bis->bi_phymode[2] = BI_PHYMODE_MII;
703 bis->bi_phymode[3] = BI_PHYMODE_NONE;
707 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
708 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
709 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
710 bis->bi_phymode[0] = BI_PHYMODE_RMII;
711 bis->bi_phymode[1] = BI_PHYMODE_RMII;
712 bis->bi_phymode[2] = BI_PHYMODE_NONE;
713 bis->bi_phymode[3] = BI_PHYMODE_NONE;
717 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */
719 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
720 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
721 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
722 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
723 bis->bi_phymode[0] = BI_PHYMODE_RMII;
724 bis->bi_phymode[1] = BI_PHYMODE_RMII;
725 bis->bi_phymode[2] = BI_PHYMODE_RMII;
726 bis->bi_phymode[3] = BI_PHYMODE_RMII;
730 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
731 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
732 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
733 bis->bi_phymode[0] = BI_PHYMODE_SMII;
734 bis->bi_phymode[1] = BI_PHYMODE_SMII;
735 bis->bi_phymode[2] = BI_PHYMODE_NONE;
736 bis->bi_phymode[3] = BI_PHYMODE_NONE;
740 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */
742 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
743 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
744 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
745 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
746 bis->bi_phymode[0] = BI_PHYMODE_SMII;
747 bis->bi_phymode[1] = BI_PHYMODE_SMII;
748 bis->bi_phymode[2] = BI_PHYMODE_SMII;
749 bis->bi_phymode[3] = BI_PHYMODE_SMII;
752 /* This is the default mode that we want for board bringup - Maple */
754 /* GMC0 EMAC4_0, RGMII Bridge 0 */
755 rmiifer |= RGMII_FER_MDIO(0);
758 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
759 bis->bi_phymode[0] = BI_PHYMODE_GMII;
760 bis->bi_phymode[1] = BI_PHYMODE_NONE;
761 bis->bi_phymode[2] = BI_PHYMODE_NONE;
762 bis->bi_phymode[3] = BI_PHYMODE_NONE;
764 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3); /* CH1CFG - EMAC1 */
765 bis->bi_phymode[0] = BI_PHYMODE_NONE;
766 bis->bi_phymode[1] = BI_PHYMODE_GMII;
767 bis->bi_phymode[2] = BI_PHYMODE_NONE;
768 bis->bi_phymode[3] = BI_PHYMODE_NONE;
773 /* GMC0 EMAC4_0, RGMII Bridge 0 */
774 /* GMC1 EMAC4_2, RGMII Bridge 1 */
775 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
776 rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC2 */
777 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
778 rmiifer1 |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC2 */
780 bis->bi_phymode[0] = BI_PHYMODE_GMII;
781 bis->bi_phymode[1] = BI_PHYMODE_NONE;
782 bis->bi_phymode[2] = BI_PHYMODE_GMII;
783 bis->bi_phymode[3] = BI_PHYMODE_NONE;
786 /* 2 RGMII - 460EX */
787 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
788 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
789 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
790 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
792 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
793 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
794 bis->bi_phymode[2] = BI_PHYMODE_NONE;
795 bis->bi_phymode[3] = BI_PHYMODE_NONE;
798 /* 4 RGMII - 460GT */
799 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
800 /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */
801 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
802 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
803 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2);
804 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3);
805 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
806 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
807 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
808 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
811 /* 2 SGMII - 460EX */
812 bis->bi_phymode[0] = BI_PHYMODE_SGMII;
813 bis->bi_phymode[1] = BI_PHYMODE_SGMII;
814 bis->bi_phymode[2] = BI_PHYMODE_NONE;
815 bis->bi_phymode[3] = BI_PHYMODE_NONE;
818 /* 3 SGMII - 460GT */
819 bis->bi_phymode[0] = BI_PHYMODE_SGMII;
820 bis->bi_phymode[1] = BI_PHYMODE_SGMII;
821 bis->bi_phymode[2] = BI_PHYMODE_SGMII;
822 bis->bi_phymode[3] = BI_PHYMODE_NONE;
828 /* Set EMAC for MDIO */
829 mfsdr(SDR0_ETH_CFG, eth_cfg);
830 eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
831 mtsdr(SDR0_ETH_CFG, eth_cfg);
833 out_be32((void *)RGMII_FER, rmiifer);
834 #if defined(CONFIG_460GT)
835 out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1);
838 /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
839 mfsdr(SDR0_ETH_CFG, eth_cfg);
840 eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
841 mtsdr(SDR0_ETH_CFG, eth_cfg);
845 #endif /* CONFIG_460EX || CONFIG_460GT */
847 static inline void *malloc_aligned(u32 size, u32 align)
849 return (void *)(((u32)malloc(size + align) + align - 1) &
853 static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
856 unsigned long reg = 0;
859 unsigned long duplex;
860 unsigned long failsafe;
862 unsigned short devnum;
863 unsigned short reg_short;
864 #if defined(CONFIG_440GX) || \
865 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
866 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
867 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
868 defined(CONFIG_405EX)
871 #if defined(CONFIG_440GX) || \
872 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
873 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
874 defined(CONFIG_405EX)
880 #ifdef CONFIG_4xx_DCACHE
881 static u32 last_used_ea = 0;
883 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
884 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
885 defined(CONFIG_405EX)
889 EMAC_4XX_HW_PST hw_p = dev->priv;
891 /* before doing anything, figure out if we have a MAC address */
893 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
894 printf("ERROR: ethaddr not set!\n");
898 #if defined(CONFIG_440GX) || \
899 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
900 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
901 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
902 defined(CONFIG_405EX)
903 /* Need to get the OPB frequency so we can access the PHY */
904 get_sys_info (&sysinfo);
908 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
910 devnum = hw_p->devnum;
915 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
916 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
917 * is possible that new packets (without relationship with
918 * current transfer) have got the time to arrived before
919 * netloop calls eth_halt
921 printf ("About preceeding transfer (eth%d):\n"
922 "- Sent packet number %d\n"
923 "- Received packet number %d\n"
924 "- Handled packet number %d\n",
927 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
929 hw_p->stats.pkts_tx = 0;
930 hw_p->stats.pkts_rx = 0;
931 hw_p->stats.pkts_handled = 0;
932 hw_p->print_speed = 1; /* print speed message again next time */
935 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
936 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
938 hw_p->rx_slot = 0; /* MAL Receive Slot */
939 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
940 hw_p->rx_u_index = 0; /* Receive User Queue Index */
942 hw_p->tx_slot = 0; /* MAL Transmit Slot */
943 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
944 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
946 #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
948 /* NOTE: 440GX spec states that mode is mutually exclusive */
949 /* NOTE: Therefore, disable all other EMACS, since we handle */
950 /* NOTE: only one emac at a time */
952 out_be32((void *)ZMII0_FER, 0);
955 #if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
956 out_be32((void *)ZMII0_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
957 #elif defined(CONFIG_440GX) || \
958 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
959 defined(CONFIG_460EX) || defined(CONFIG_460GT)
960 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
963 out_be32((void *)ZMII0_SSR, ZMII0_SSR_SP << ZMII0_SSR_V(devnum));
964 #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
965 #if defined(CONFIG_405EX)
966 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
971 /* provide clocks for EMAC internal loopback */
972 emac_loopback_enable(hw_p);
975 out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_SRST);
977 /* remove clocks for EMAC internal loopback */
978 emac_loopback_disable(hw_p);
981 while ((in_be32((void *)EMAC0_MR0 + hw_p->hw_addr) & (EMAC_MR0_SRST)) && failsafe) {
986 printf("\nProblem resetting EMAC!\n");
988 #if defined(CONFIG_440GX) || \
989 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
990 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
991 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
992 defined(CONFIG_405EX)
993 /* Whack the M1 register */
995 mode_reg &= ~0x00000038;
996 opbfreq = sysinfo.freqOPB / 1000000;
998 else if (opbfreq <= 66)
999 mode_reg |= EMAC_MR1_OBCI_66;
1000 else if (opbfreq <= 83)
1001 mode_reg |= EMAC_MR1_OBCI_83;
1002 else if (opbfreq <= 100)
1003 mode_reg |= EMAC_MR1_OBCI_100;
1005 mode_reg |= EMAC_MR1_OBCI_GT100;
1007 out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
1008 #endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
1010 #if defined(CONFIG_GPCS_PHY_ADDR) || defined(CONFIG_GPCS_PHY1_ADDR) || \
1011 defined(CONFIG_GPCS_PHY2_ADDR) || defined(CONFIG_GPCS_PHY3_ADDR)
1012 if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
1014 * In SGMII mode, GPCS access is needed for
1015 * communication with the internal SGMII SerDes.
1018 #if defined(CONFIG_GPCS_PHY_ADDR)
1020 reg = CONFIG_GPCS_PHY_ADDR;
1023 #if defined(CONFIG_GPCS_PHY1_ADDR)
1025 reg = CONFIG_GPCS_PHY1_ADDR;
1028 #if defined(CONFIG_GPCS_PHY2_ADDR)
1030 reg = CONFIG_GPCS_PHY2_ADDR;
1033 #if defined(CONFIG_GPCS_PHY3_ADDR)
1035 reg = CONFIG_GPCS_PHY3_ADDR;
1040 mode_reg = in_be32((void *)EMAC0_MR1 + hw_p->hw_addr);
1041 mode_reg |= EMAC_MR1_MF_1000GPCS | EMAC_MR1_IPPA_SET(reg);
1042 out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
1044 /* Configure GPCS interface to recommended setting for SGMII */
1045 miiphy_reset(dev->name, reg);
1046 miiphy_write(dev->name, reg, 0x04, 0x8120); /* AsymPause, FDX */
1047 miiphy_write(dev->name, reg, 0x07, 0x2801); /* msg_pg, toggle */
1048 miiphy_write(dev->name, reg, 0x00, 0x0140); /* 1Gbps, FDX */
1050 #endif /* defined(CONFIG_GPCS_PHY_ADDR) */
1052 /* wait for PHY to complete auto negotiation */
1056 reg = CONFIG_PHY_ADDR;
1058 #if defined (CONFIG_PHY1_ADDR)
1060 reg = CONFIG_PHY1_ADDR;
1063 #if defined (CONFIG_PHY2_ADDR)
1065 reg = CONFIG_PHY2_ADDR;
1068 #if defined (CONFIG_PHY3_ADDR)
1070 reg = CONFIG_PHY3_ADDR;
1074 reg = CONFIG_PHY_ADDR;
1078 bis->bi_phynum[devnum] = reg;
1080 if (reg == CONFIG_FIXED_PHY)
1083 #if defined(CONFIG_PHY_RESET)
1085 * Reset the phy, only if its the first time through
1086 * otherwise, just check the speeds & feeds
1088 if (hw_p->first_init == 0) {
1089 #if defined(CONFIG_M88E1111_PHY)
1090 miiphy_write (dev->name, reg, 0x14, 0x0ce3);
1091 miiphy_write (dev->name, reg, 0x18, 0x4101);
1092 miiphy_write (dev->name, reg, 0x09, 0x0e00);
1093 miiphy_write (dev->name, reg, 0x04, 0x01e1);
1094 #if defined(CONFIG_M88E1111_DISABLE_FIBER)
1095 miiphy_read(dev->name, reg, 0x1b, ®_short);
1096 reg_short |= 0x8000;
1097 miiphy_write(dev->name, reg, 0x1b, reg_short);
1100 #if defined(CONFIG_M88E1112_PHY)
1101 if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
1103 * Marvell 88E1112 PHY needs to have the SGMII MAC
1104 * interace (page 2) properly configured to
1105 * communicate with the 460EX/GT GPCS interface.
1108 /* Set access to Page 2 */
1109 miiphy_write(dev->name, reg, 0x16, 0x0002);
1111 miiphy_write(dev->name, reg, 0x00, 0x0040); /* 1Gbps */
1112 miiphy_read(dev->name, reg, 0x1a, ®_short);
1113 reg_short |= 0x8000; /* bypass Auto-Negotiation */
1114 miiphy_write(dev->name, reg, 0x1a, reg_short);
1115 miiphy_reset(dev->name, reg); /* reset MAC interface */
1117 /* Reset access to Page 0 */
1118 miiphy_write(dev->name, reg, 0x16, 0x0000);
1120 #endif /* defined(CONFIG_M88E1112_PHY) */
1121 miiphy_reset (dev->name, reg);
1123 #if defined(CONFIG_440GX) || \
1124 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1125 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1126 defined(CONFIG_405EX)
1128 #if defined(CONFIG_CIS8201_PHY)
1130 * Cicada 8201 PHY needs to have an extended register whacked
1133 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
1134 #if defined(CONFIG_CIS8201_SHORT_ETCH)
1135 miiphy_write (dev->name, reg, 23, 0x1300);
1137 miiphy_write (dev->name, reg, 23, 0x1000);
1140 * Vitesse VSC8201/Cicada CIS8201 errata:
1141 * Interoperability problem with Intel 82547EI phys
1142 * This work around (provided by Vitesse) changes
1143 * the default timer convergence from 8ms to 12ms
1145 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1146 miiphy_write (dev->name, reg, 0x08, 0x0200);
1147 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
1148 miiphy_write (dev->name, reg, 0x02, 0x0004);
1149 miiphy_write (dev->name, reg, 0x01, 0x0671);
1150 miiphy_write (dev->name, reg, 0x00, 0x8fae);
1151 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1152 miiphy_write (dev->name, reg, 0x08, 0x0000);
1153 miiphy_write (dev->name, reg, 0x1f, 0x0000);
1154 /* end Vitesse/Cicada errata */
1156 #endif /* defined(CONFIG_CIS8201_PHY) */
1158 #if defined(CONFIG_ET1011C_PHY)
1160 * Agere ET1011c PHY needs to have an extended register whacked
1163 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
1164 miiphy_read (dev->name, reg, 0x16, ®_short);
1165 reg_short &= ~(0x7);
1166 reg_short |= 0x6; /* RGMII DLL Delay*/
1167 miiphy_write (dev->name, reg, 0x16, reg_short);
1169 miiphy_read (dev->name, reg, 0x17, ®_short);
1170 reg_short &= ~(0x40);
1171 miiphy_write (dev->name, reg, 0x17, reg_short);
1173 miiphy_write(dev->name, reg, 0x1c, 0x74f0);
1175 #endif /* defined(CONFIG_ET1011C_PHY) */
1177 #endif /* defined(CONFIG_440GX) ... */
1178 /* Start/Restart autonegotiation */
1179 phy_setup_aneg (dev->name, reg);
1182 #endif /* defined(CONFIG_PHY_RESET) */
1184 miiphy_read (dev->name, reg, MII_BMSR, ®_short);
1187 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
1189 if ((reg_short & BMSR_ANEGCAPABLE)
1190 && !(reg_short & BMSR_ANEGCOMPLETE)) {
1191 puts ("Waiting for PHY auto negotiation to complete");
1193 while (!(reg_short & BMSR_ANEGCOMPLETE)) {
1197 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
1198 puts (" TIMEOUT !\n");
1202 if ((i++ % 1000) == 0) {
1205 udelay (1000); /* 1 ms */
1206 miiphy_read (dev->name, reg, MII_BMSR, ®_short);
1209 udelay (500000); /* another 500 ms (results in faster booting) */
1213 if (reg == CONFIG_FIXED_PHY) {
1214 for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) {
1215 if (devnum == fixed_phy_port[i].devnum) {
1216 speed = fixed_phy_port[i].speed;
1217 duplex = fixed_phy_port[i].duplex;
1222 if (i == ARRAY_SIZE(fixed_phy_port)) {
1223 printf("ERROR: PHY (%s) not configured correctly!\n",
1228 speed = miiphy_speed(dev->name, reg);
1229 duplex = miiphy_duplex(dev->name, reg);
1232 if (hw_p->print_speed) {
1233 hw_p->print_speed = 0;
1234 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
1235 (int) speed, (duplex == HALF) ? "HALF" : "FULL",
1239 #if defined(CONFIG_440) && \
1240 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
1241 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
1242 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
1243 #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
1244 mfsdr(SDR0_MFR, reg);
1246 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
1248 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
1250 mtsdr(SDR0_MFR, reg);
1253 /* Set ZMII/RGMII speed according to the phy link speed */
1254 reg = in_be32((void *)ZMII0_SSR);
1255 if ( (speed == 100) || (speed == 1000) )
1256 out_be32((void *)ZMII0_SSR, reg | (ZMII0_SSR_SP << ZMII0_SSR_V (devnum)));
1258 out_be32((void *)ZMII0_SSR, reg & (~(ZMII0_SSR_SP << ZMII0_SSR_V (devnum))));
1260 if ((devnum == 2) || (devnum == 3)) {
1262 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1263 else if (speed == 100)
1264 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
1265 else if (speed == 10)
1266 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
1268 printf("Error in RGMII Speed\n");
1271 out_be32((void *)RGMII_SSR, reg);
1273 #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
1275 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1276 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1277 defined(CONFIG_405EX)
1279 rgmii_channel = devnum - 2;
1281 rgmii_channel = devnum;
1284 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V(rgmii_channel));
1285 else if (speed == 100)
1286 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V(rgmii_channel));
1287 else if (speed == 10)
1288 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V(rgmii_channel));
1290 printf("Error in RGMII Speed\n");
1293 out_be32((void *)RGMII_SSR, reg);
1294 #if defined(CONFIG_460GT)
1295 if ((devnum == 2) || (devnum == 3))
1296 out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
1300 /* set the Mal configuration reg */
1301 #if defined(CONFIG_440GX) || \
1302 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1303 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
1304 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1305 defined(CONFIG_405EX)
1306 mtdcr (MAL0_CFG, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
1307 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
1309 mtdcr (MAL0_CFG, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
1310 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
1311 if (get_pvr() == PVR_440GP_RB) {
1312 mtdcr (MAL0_CFG, mfdcr(MAL0_CFG) & ~MAL_CR_PLBB);
1317 * Malloc MAL buffer desciptors, make sure they are
1318 * aligned on cache line boundary size
1319 * (401/403/IOP480 = 16, 405 = 32)
1320 * and doesn't cross cache block boundaries.
1322 if (hw_p->first_init == 0) {
1323 debug("*** Allocating descriptor memory ***\n");
1325 bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
1327 printf("%s: Error allocating MAL descriptor buffers!\n", __func__);
1331 #ifdef CONFIG_4xx_DCACHE
1332 flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
1334 #if defined(CONFIG_SYS_MEM_TOP_HIDE)
1335 bd_uncached = bis->bi_memsize + CONFIG_SYS_MEM_TOP_HIDE;
1337 bd_uncached = bis->bi_memsize;
1340 bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
1342 last_used_ea = bd_uncached;
1343 program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
1344 TLB_WORD2_I_ENABLE);
1346 bd_uncached = bd_cached;
1348 hw_p->tx_phys = bd_cached;
1349 hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
1350 hw_p->tx = (mal_desc_t *)(bd_uncached);
1351 hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
1352 debug("hw_p->tx=%p, hw_p->rx=%p\n", hw_p->tx, hw_p->rx);
1355 for (i = 0; i < NUM_TX_BUFF; i++) {
1356 hw_p->tx[i].ctrl = 0;
1357 hw_p->tx[i].data_len = 0;
1358 if (hw_p->first_init == 0)
1359 hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
1361 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
1362 if ((NUM_TX_BUFF - 1) == i)
1363 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
1364 hw_p->tx_run[i] = -1;
1365 debug("TX_BUFF %d @ 0x%08x\n", i, (u32)hw_p->tx[i].data_ptr);
1368 for (i = 0; i < NUM_RX_BUFF; i++) {
1369 hw_p->rx[i].ctrl = 0;
1370 hw_p->rx[i].data_len = 0;
1371 hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
1372 if ((NUM_RX_BUFF - 1) == i)
1373 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
1374 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
1375 hw_p->rx_ready[i] = -1;
1376 debug("RX_BUFF %d @ 0x%08x\n", i, (u32)hw_p->rx[i].data_ptr);
1381 reg |= dev->enetaddr[0]; /* set high address */
1383 reg |= dev->enetaddr[1];
1385 out_be32((void *)EMAC0_IAH + hw_p->hw_addr, reg);
1388 reg |= dev->enetaddr[2]; /* set low address */
1390 reg |= dev->enetaddr[3];
1392 reg |= dev->enetaddr[4];
1394 reg |= dev->enetaddr[5];
1396 out_be32((void *)EMAC0_IAL + hw_p->hw_addr, reg);
1400 /* setup MAL tx & rx channel pointers */
1401 #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
1402 mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
1404 mtdcr (MAL0_TXCTP1R, hw_p->tx_phys);
1406 #if defined(CONFIG_440)
1407 mtdcr (MAL0_TXBADDR, 0x0);
1408 mtdcr (MAL0_RXBADDR, 0x0);
1411 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
1412 mtdcr (MAL0_RXCTP8R, hw_p->rx_phys);
1413 /* set RX buffer size */
1414 mtdcr (MAL0_RCBS8, ENET_MAX_MTU_ALIGNED / 16);
1416 mtdcr (MAL0_RXCTP1R, hw_p->rx_phys);
1417 /* set RX buffer size */
1418 mtdcr (MAL0_RCBS1, ENET_MAX_MTU_ALIGNED / 16);
1421 #if defined (CONFIG_440GX)
1423 /* setup MAL tx & rx channel pointers */
1424 mtdcr (MAL0_TXBADDR, 0x0);
1425 mtdcr (MAL0_RXBADDR, 0x0);
1426 mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
1427 mtdcr (MAL0_RXCTP2R, hw_p->rx_phys);
1428 /* set RX buffer size */
1429 mtdcr (MAL0_RCBS2, ENET_MAX_MTU_ALIGNED / 16);
1432 /* setup MAL tx & rx channel pointers */
1433 mtdcr (MAL0_TXBADDR, 0x0);
1434 mtdcr (MAL0_TXCTP3R, hw_p->tx_phys);
1435 mtdcr (MAL0_RXBADDR, 0x0);
1436 mtdcr (MAL0_RXCTP3R, hw_p->rx_phys);
1437 /* set RX buffer size */
1438 mtdcr (MAL0_RCBS3, ENET_MAX_MTU_ALIGNED / 16);
1440 #endif /* CONFIG_440GX */
1441 #if defined (CONFIG_460GT)
1443 /* setup MAL tx & rx channel pointers */
1444 mtdcr (MAL0_TXBADDR, 0x0);
1445 mtdcr (MAL0_RXBADDR, 0x0);
1446 mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
1447 mtdcr (MAL0_RXCTP16R, hw_p->rx_phys);
1448 /* set RX buffer size */
1449 mtdcr (MAL0_RCBS16, ENET_MAX_MTU_ALIGNED / 16);
1452 /* setup MAL tx & rx channel pointers */
1453 mtdcr (MAL0_TXBADDR, 0x0);
1454 mtdcr (MAL0_RXBADDR, 0x0);
1455 mtdcr (MAL0_TXCTP3R, hw_p->tx_phys);
1456 mtdcr (MAL0_RXCTP24R, hw_p->rx_phys);
1457 /* set RX buffer size */
1458 mtdcr (MAL0_RCBS24, ENET_MAX_MTU_ALIGNED / 16);
1460 #endif /* CONFIG_460GT */
1463 /* setup MAL tx & rx channel pointers */
1464 #if defined(CONFIG_440)
1465 mtdcr (MAL0_TXBADDR, 0x0);
1466 mtdcr (MAL0_RXBADDR, 0x0);
1468 mtdcr (MAL0_TXCTP0R, hw_p->tx_phys);
1469 mtdcr (MAL0_RXCTP0R, hw_p->rx_phys);
1470 /* set RX buffer size */
1471 mtdcr (MAL0_RCBS0, ENET_MAX_MTU_ALIGNED / 16);
1475 /* Enable MAL transmit and receive channels */
1476 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
1477 mtdcr (MAL0_TXCASR, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
1479 mtdcr (MAL0_TXCASR, (MAL_TXRX_CASR >> hw_p->devnum));
1481 mtdcr (MAL0_RXCASR, (MAL_TXRX_CASR >> hw_p->devnum));
1483 /* set transmit enable & receive enable */
1484 out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_TXE | EMAC_MR0_RXE);
1486 mode_reg = in_be32((void *)EMAC0_MR1 + hw_p->hw_addr);
1488 /* set rx-/tx-fifo size */
1489 mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
1492 if (speed == _1000BASET) {
1493 #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
1496 mfsdr (SDR0_PFC1, pfc1);
1497 pfc1 |= SDR0_PFC1_EM_1000;
1498 mtsdr (SDR0_PFC1, pfc1);
1500 mode_reg = mode_reg | EMAC_MR1_MF_1000MBPS | EMAC_MR1_IST;
1501 } else if (speed == _100BASET)
1502 mode_reg = mode_reg | EMAC_MR1_MF_100MBPS | EMAC_MR1_IST;
1504 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
1506 mode_reg = mode_reg | 0x80000000 | EMAC_MR1_IST;
1508 out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
1510 /* Enable broadcast and indvidual address */
1511 /* TBS: enabling runts as some misbehaved nics will send runts */
1512 out_be32((void *)EMAC0_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
1514 /* we probably need to set the tx mode1 reg? maybe at tx time */
1516 /* set transmit request threshold register */
1517 out_be32((void *)EMAC0_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
1519 /* set receive low/high water mark register */
1520 #if defined(CONFIG_440)
1521 /* 440s has a 64 byte burst length */
1522 out_be32((void *)EMAC0_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
1524 /* 405s have a 16 byte burst length */
1525 out_be32((void *)EMAC0_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
1526 #endif /* defined(CONFIG_440) */
1527 out_be32((void *)EMAC0_TMR1 + hw_p->hw_addr, 0xf8640000);
1529 /* Set fifo limit entry in tx mode 0 */
1530 out_be32((void *)EMAC0_TMR0 + hw_p->hw_addr, 0x00000003);
1532 out_be32((void *)EMAC0_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
1535 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
1536 if (speed == _100BASET)
1537 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1539 out_be32((void *)EMAC0_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
1540 out_be32((void *)EMAC0_IER + hw_p->hw_addr, hw_p->emac_ier);
1542 if (hw_p->first_init == 0) {
1544 * Connect interrupt service routines
1546 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1547 (interrupt_handler_t *) enetInt, dev);
1550 mtmsr (msr); /* enable interrupts again */
1553 hw_p->first_init = 1;
1559 static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
1562 struct enet_frame *ef_ptr;
1563 ulong time_start, time_now;
1564 unsigned long temp_txm0;
1565 EMAC_4XX_HW_PST hw_p = dev->priv;
1567 ef_ptr = (struct enet_frame *) ptr;
1569 /*-----------------------------------------------------------------------+
1570 * Copy in our address into the frame.
1571 *-----------------------------------------------------------------------*/
1572 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1574 /*-----------------------------------------------------------------------+
1575 * If frame is too long or too short, modify length.
1576 *-----------------------------------------------------------------------*/
1577 /* TBS: where does the fragment go???? */
1578 if (len > ENET_MAX_MTU)
1581 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1582 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
1583 flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
1585 /*-----------------------------------------------------------------------+
1586 * set TX Buffer busy, and send it
1587 *-----------------------------------------------------------------------*/
1588 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1589 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1590 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1591 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1592 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1594 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1595 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1599 out_be32((void *)EMAC0_TMR0 + hw_p->hw_addr,
1600 in_be32((void *)EMAC0_TMR0 + hw_p->hw_addr) | EMAC_TMR0_GNP0);
1601 #ifdef INFO_4XX_ENET
1602 hw_p->stats.pkts_tx++;
1605 /*-----------------------------------------------------------------------+
1606 * poll unitl the packet is sent and then make sure it is OK
1607 *-----------------------------------------------------------------------*/
1608 time_start = get_timer (0);
1610 temp_txm0 = in_be32((void *)EMAC0_TMR0 + hw_p->hw_addr);
1611 /* loop until either TINT turns on or 3 seconds elapse */
1612 if ((temp_txm0 & EMAC_TMR0_GNP0) != 0) {
1613 /* transmit is done, so now check for errors
1614 * If there is an error, an interrupt should
1615 * happen when we return
1617 time_now = get_timer (0);
1618 if ((time_now - time_start) > 3000) {
1627 int enetInt (struct eth_device *dev)
1630 int rc = -1; /* default to not us */
1638 EMAC_4XX_HW_PST hw_p;
1641 * Because the mal is generic, we need to get the current
1644 dev = eth_get_dev();
1648 /* enter loop that stays in interrupt code until nothing to service */
1652 uic_mal = mfdcr(UIC_BASE_MAL + UIC_MSR);
1653 uic_mal_err = mfdcr(UIC_BASE_MAL_ERR + UIC_MSR);
1654 uic_emac = mfdcr(UIC_BASE_EMAC + UIC_MSR);
1655 uic_emac_b = mfdcr(UIC_BASE_EMAC_B + UIC_MSR);
1657 if (!(uic_mal & (UIC_MAL_RXEOB | UIC_MAL_TXEOB))
1658 && !(uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE))
1659 && !(uic_emac & UIC_ETHx) && !(uic_emac_b & UIC_ETHxB)) {
1664 /* get and clear controller status interrupts */
1665 /* look at MAL and EMAC error interrupts */
1666 if (uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) {
1667 /* we have a MAL error interrupt */
1668 mal_isr = mfdcr(MAL0_ESR);
1669 mal_err(dev, mal_isr, uic_mal_err,
1670 MAL_UIC_DEF, MAL_UIC_ERR);
1672 /* clear MAL error interrupt status bits */
1673 mtdcr(UIC_BASE_MAL_ERR + UIC_SR,
1674 UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE);
1679 /* look for EMAC errors */
1680 if ((uic_emac & UIC_ETHx) || (uic_emac_b & UIC_ETHxB)) {
1681 emac_isr = in_be32((void *)EMAC0_ISR + hw_p->hw_addr);
1682 emac_err(dev, emac_isr);
1684 /* clear EMAC error interrupt status bits */
1685 mtdcr(UIC_BASE_EMAC + UIC_SR, UIC_ETHx);
1686 mtdcr(UIC_BASE_EMAC_B + UIC_SR, UIC_ETHxB);
1691 /* handle MAX TX EOB interrupt from a tx */
1692 if (uic_mal & UIC_MAL_TXEOB) {
1693 /* clear MAL interrupt status bits */
1694 mal_eob = mfdcr(MAL0_TXEOBISR);
1695 mtdcr(MAL0_TXEOBISR, mal_eob);
1696 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_TXEOB);
1698 /* indicate that we serviced an interrupt */
1703 /* handle MAL RX EOB interrupt from a receive */
1704 /* check for EOB on valid channels */
1705 if (uic_mal & UIC_MAL_RXEOB) {
1706 mal_eob = mfdcr(MAL0_RXEOBISR);
1708 (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL))) {
1709 /* push packet to upper layer */
1710 enet_rcv(dev, emac_isr);
1712 /* clear MAL interrupt status bits */
1713 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_RXEOB);
1715 /* indicate that we serviced an interrupt */
1720 #if defined(CONFIG_405EZ)
1722 * On 405EZ the RX-/TX-interrupts are coalesced into
1723 * one IRQ bit in the UIC. We need to acknowledge the
1724 * RX-/TX-interrupts in the SDR0_ICINTSTAT reg as well.
1726 mtsdr(SDR0_ICINTSTAT,
1727 SDR_ICRX_STAT | SDR_ICTX0_STAT | SDR_ICTX1_STAT);
1728 #endif /* defined(CONFIG_405EZ) */
1734 /*-----------------------------------------------------------------------------+
1736 *-----------------------------------------------------------------------------*/
1737 static void mal_err (struct eth_device *dev, unsigned long isr,
1738 unsigned long uic, unsigned long maldef,
1739 unsigned long mal_errr)
1741 EMAC_4XX_HW_PST hw_p = dev->priv;
1743 mtdcr (MAL0_ESR, isr); /* clear interrupt */
1745 /* clear DE interrupt */
1746 mtdcr (MAL0_TXDEIR, 0xC0000000);
1747 mtdcr (MAL0_RXDEIR, 0x80000000);
1749 #ifdef INFO_4XX_ENET
1750 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
1753 eth_init (hw_p->bis); /* start again... */
1756 /*-----------------------------------------------------------------------------+
1757 * EMAC Error Routine
1758 *-----------------------------------------------------------------------------*/
1759 static void emac_err (struct eth_device *dev, unsigned long isr)
1761 EMAC_4XX_HW_PST hw_p = dev->priv;
1763 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
1764 out_be32((void *)EMAC0_ISR + hw_p->hw_addr, isr);
1767 /*-----------------------------------------------------------------------------+
1768 * enet_rcv() handles the ethernet receive data
1769 *-----------------------------------------------------------------------------*/
1770 static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1772 struct enet_frame *ef_ptr;
1773 unsigned long data_len;
1774 unsigned long rx_eob_isr;
1775 EMAC_4XX_HW_PST hw_p = dev->priv;
1781 rx_eob_isr = mfdcr (MAL0_RXEOBISR);
1782 if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
1784 mtdcr (MAL0_RXEOBISR, rx_eob_isr);
1787 while (1) { /* do all */
1790 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1791 || (loop_count >= NUM_RX_BUFF))
1796 data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */
1798 if (data_len > ENET_MAX_MTU) /* Check len */
1801 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1803 hw_p->stats.rx_err_log[hw_p->
1806 hw_p->rx_err_index++;
1807 if (hw_p->rx_err_index ==
1809 hw_p->rx_err_index =
1812 } /* data_len < max mtu */
1814 if (!data_len) { /* no data */
1815 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1817 hw_p->stats.data_len_err++; /* Error at Rx */
1822 /* Check if user has already eaten buffer */
1823 /* if not => ERROR */
1824 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1825 if (hw_p->is_receiving)
1826 printf ("ERROR : Receive buffers are full!\n");
1829 hw_p->stats.rx_frames++;
1830 hw_p->stats.rx += data_len;
1831 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1833 #ifdef INFO_4XX_ENET
1834 hw_p->stats.pkts_rx++;
1839 hw_p->rx_ready[hw_p->rx_i_index] = i;
1841 if (NUM_RX_BUFF == hw_p->rx_i_index)
1842 hw_p->rx_i_index = 0;
1845 if (NUM_RX_BUFF == hw_p->rx_slot)
1849 * free receive buffer only when
1850 * buffer has been handled (eth_rx)
1851 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1855 } /* if EMACK_RXCHL */
1859 static int ppc_4xx_eth_rx (struct eth_device *dev)
1864 EMAC_4XX_HW_PST hw_p = dev->priv;
1866 hw_p->is_receiving = 1; /* tell driver */
1870 * use ring buffer and
1871 * get index from rx buffer desciptor queue
1873 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1874 if (user_index == -1) {
1876 break; /* nothing received - leave for() loop */
1880 mtmsr (msr & ~(MSR_EE));
1882 length = hw_p->rx[user_index].data_len & 0x0fff;
1884 /* Pass the packet up to the protocol layers. */
1885 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1886 /* NetReceive(NetRxPackets[i], length); */
1887 invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
1888 (u32)hw_p->rx[user_index].data_ptr +
1890 NetReceive (NetRxPackets[user_index], length - 4);
1891 /* Free Recv Buffer */
1892 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1893 /* Free rx buffer descriptor queue */
1894 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1896 if (NUM_RX_BUFF == hw_p->rx_u_index)
1897 hw_p->rx_u_index = 0;
1899 #ifdef INFO_4XX_ENET
1900 hw_p->stats.pkts_handled++;
1903 mtmsr (msr); /* Enable IRQ's */
1906 hw_p->is_receiving = 0; /* tell driver */
1911 int ppc_4xx_eth_initialize (bd_t * bis)
1913 static int virgin = 0;
1914 struct eth_device *dev;
1916 EMAC_4XX_HW_PST hw = NULL;
1917 u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1921 #if defined(CONFIG_440GX)
1924 mfsdr (SDR0_PFC1, pfc1);
1925 pfc1 &= ~(0x01e00000);
1927 mtsdr (SDR0_PFC1, pfc1);
1930 /* first clear all mac-addresses */
1931 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1932 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
1934 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1935 int ethaddr_idx = eth_num + CONFIG_EMAC_NR_START;
1937 default: /* fall through */
1939 eth_getenv_enetaddr("ethaddr", ethaddr[ethaddr_idx]);
1940 hw_addr[eth_num] = 0x0;
1942 #ifdef CONFIG_HAS_ETH1
1944 eth_getenv_enetaddr("eth1addr", ethaddr[ethaddr_idx]);
1945 hw_addr[eth_num] = 0x100;
1948 #ifdef CONFIG_HAS_ETH2
1950 eth_getenv_enetaddr("eth2addr", ethaddr[ethaddr_idx]);
1951 #if defined(CONFIG_460GT)
1952 hw_addr[eth_num] = 0x300;
1954 hw_addr[eth_num] = 0x400;
1958 #ifdef CONFIG_HAS_ETH3
1960 eth_getenv_enetaddr("eth3addr", ethaddr[ethaddr_idx]);
1961 #if defined(CONFIG_460GT)
1962 hw_addr[eth_num] = 0x400;
1964 hw_addr[eth_num] = 0x600;
1971 /* set phy num and mode */
1972 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
1973 bis->bi_phymode[0] = 0;
1975 #if defined(CONFIG_PHY1_ADDR)
1976 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
1977 bis->bi_phymode[1] = 0;
1979 #if defined(CONFIG_440GX)
1980 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1981 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1982 bis->bi_phymode[2] = 2;
1983 bis->bi_phymode[3] = 2;
1986 #if defined(CONFIG_440GX) || \
1987 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1988 defined(CONFIG_405EX)
1989 ppc_4xx_eth_setup_bridge(0, bis);
1992 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1994 * See if we can actually bring up the interface,
1995 * otherwise, skip it
1997 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
1998 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
2002 /* Allocate device structure */
2003 dev = (struct eth_device *) malloc (sizeof (*dev));
2005 printf ("ppc_4xx_eth_initialize: "
2006 "Cannot allocate eth_device %d\n", eth_num);
2009 memset(dev, 0, sizeof(*dev));
2011 /* Allocate our private use data */
2012 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
2014 printf ("ppc_4xx_eth_initialize: "
2015 "Cannot allocate private hw data for eth_device %d",
2020 memset(hw, 0, sizeof(*hw));
2022 hw->hw_addr = hw_addr[eth_num];
2023 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
2024 hw->devnum = eth_num;
2025 hw->print_speed = 1;
2027 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
2028 dev->priv = (void *) hw;
2029 dev->init = ppc_4xx_eth_init;
2030 dev->halt = ppc_4xx_eth_halt;
2031 dev->send = ppc_4xx_eth_send;
2032 dev->recv = ppc_4xx_eth_rx;
2036 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
2037 miiphy_register(dev->name,
2038 emac4xx_miiphy_read, emac4xx_miiphy_write);
2042 /* set the MAL IER ??? names may change with new spec ??? */
2043 #if defined(CONFIG_440SPE) || \
2044 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
2045 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
2046 defined(CONFIG_405EX)
2048 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
2049 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
2052 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
2053 MAL_IER_OPBE | MAL_IER_PLBE;
2055 mtdcr (MAL0_ESR, 0xffffffff); /* clear pending interrupts */
2056 mtdcr (MAL0_TXDEIR, 0xffffffff); /* clear pending interrupts */
2057 mtdcr (MAL0_RXDEIR, 0xffffffff); /* clear pending interrupts */
2058 mtdcr (MAL0_IER, mal_ier);
2060 /* install MAL interrupt handler */
2061 irq_install_handler (VECNUM_MAL_SERR,
2062 (interrupt_handler_t *) enetInt,
2064 irq_install_handler (VECNUM_MAL_TXEOB,
2065 (interrupt_handler_t *) enetInt,
2067 irq_install_handler (VECNUM_MAL_RXEOB,
2068 (interrupt_handler_t *) enetInt,
2070 irq_install_handler (VECNUM_MAL_TXDE,
2071 (interrupt_handler_t *) enetInt,
2073 irq_install_handler (VECNUM_MAL_RXDE,
2074 (interrupt_handler_t *) enetInt,
2078 } /* end for each supported device */