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>
85 #include <asm/cache.h>
89 #include <ppc4xx_enet.h>
95 * Only compile for platform with AMCC EMAC ethernet controller and
96 * network support enabled.
97 * Remark: CONFIG_405 describes Xilinx PPC405 FPGA without EMAC controller!
99 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_405) && !defined(CONFIG_IOP480)
101 #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
102 #error "CONFIG_MII has to be defined!"
105 #if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI)
106 #error "CONFIG_NET_MULTI has to be defined for NetConsole"
109 #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
110 #define PHY_AUTONEGOTIATE_TIMEOUT 5000 /* 5000 ms autonegotiate timeout */
112 /* Ethernet Transmit and Receive Buffers */
114 * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
115 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
117 #define ENET_MAX_MTU PKTSIZE
118 #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
120 /*-----------------------------------------------------------------------------+
121 * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
122 * Interrupt Controller).
123 *-----------------------------------------------------------------------------*/
124 #define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * VECNUM_ETH1_OFFS))
126 #if defined(CONFIG_HAS_ETH3)
127 #if !defined(CONFIG_440GX)
128 #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
129 UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
131 /* Unfortunately 440GX spreads EMAC interrupts on multiple UIC's */
132 #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
133 #define UIC_ETHxB (UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
134 #endif /* !defined(CONFIG_440GX) */
135 #elif defined(CONFIG_HAS_ETH2)
136 #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
137 UIC_MASK(ETH_IRQ_NUM(2)))
138 #elif defined(CONFIG_HAS_ETH1)
139 #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
141 #define UIC_ETHx UIC_MASK(ETH_IRQ_NUM(0))
145 * Define a default version for UIC_ETHxB for non 440GX so that we can
146 * use common code for all 4xx variants
148 #if !defined(UIC_ETHxB)
152 #define UIC_MAL_SERR UIC_MASK(VECNUM_MAL_SERR)
153 #define UIC_MAL_TXDE UIC_MASK(VECNUM_MAL_TXDE)
154 #define UIC_MAL_RXDE UIC_MASK(VECNUM_MAL_RXDE)
155 #define UIC_MAL_TXEOB UIC_MASK(VECNUM_MAL_TXEOB)
156 #define UIC_MAL_RXEOB UIC_MASK(VECNUM_MAL_RXEOB)
158 #define MAL_UIC_ERR (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
159 #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
162 * We have 3 different interrupt types:
163 * - MAL interrupts indicating successful transfer
164 * - MAL error interrupts indicating MAL related errors
165 * - EMAC interrupts indicating EMAC related errors
167 * All those interrupts can be on different UIC's, but since
168 * now at least all interrupts from one type are on the same
169 * UIC. Only exception is 440GX where the EMAC interrupts are
170 * spread over two UIC's!
172 #if defined(CONFIG_440GX)
173 #define UIC_BASE_MAL UIC1_DCR_BASE
174 #define UIC_BASE_MAL_ERR UIC2_DCR_BASE
175 #define UIC_BASE_EMAC UIC2_DCR_BASE
176 #define UIC_BASE_EMAC_B UIC3_DCR_BASE
178 #define UIC_BASE_MAL (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_TXEOB) * 0x10))
179 #define UIC_BASE_MAL_ERR (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_SERR) * 0x10))
180 #define UIC_BASE_EMAC (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
181 #define UIC_BASE_EMAC_B (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
186 #define BI_PHYMODE_NONE 0
187 #define BI_PHYMODE_ZMII 1
188 #define BI_PHYMODE_RGMII 2
189 #define BI_PHYMODE_GMII 3
190 #define BI_PHYMODE_RTBI 4
191 #define BI_PHYMODE_TBI 5
192 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
193 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
194 defined(CONFIG_405EX)
195 #define BI_PHYMODE_SMII 6
196 #define BI_PHYMODE_MII 7
197 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
198 #define BI_PHYMODE_RMII 8
201 #define BI_PHYMODE_SGMII 9
203 #if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
204 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
205 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
206 defined(CONFIG_405EX)
207 #define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
210 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
211 #define SDR0_ETH_CFG_CLK_SEL_V(n) (0x01 << (8 + n))
214 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
215 #define MAL_RX_CHAN_MUL 8 /* 460EX/GT uses MAL channel 8 for EMAC1 */
217 #define MAL_RX_CHAN_MUL 1
220 /*--------------------------------------------------------------------+
221 * Fixed PHY (PHY-less) support for Ethernet Ports.
222 *--------------------------------------------------------------------*/
225 * Some boards do not have a PHY for each ethernet port. These ports
226 * are known as Fixed PHY (or PHY-less) ports. For such ports, set
227 * the appropriate CONFIG_PHY_ADDR equal to CONFIG_FIXED_PHY and
228 * then define CFG_FIXED_PHY_PORTS to define what the speed and
229 * duplex should be for these ports in the board configuration
233 * #define CONFIG_FIXED_PHY 0xFFFFFFFF
235 * #define CONFIG_PHY_ADDR CONFIG_FIXED_PHY
236 * #define CONFIG_PHY1_ADDR 1
237 * #define CONFIG_PHY2_ADDR CONFIG_FIXED_PHY
238 * #define CONFIG_PHY3_ADDR 3
240 * #define CFG_FIXED_PHY_PORT(devnum,speed,duplex) \
241 * {devnum, speed, duplex},
243 * #define CFG_FIXED_PHY_PORTS \
244 * CFG_FIXED_PHY_PORT(0,1000,FULL) \
245 * CFG_FIXED_PHY_PORT(2,100,HALF)
248 #ifndef CONFIG_FIXED_PHY
249 #define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */
252 #ifndef CFG_FIXED_PHY_PORTS
253 #define CFG_FIXED_PHY_PORTS /* default is an empty array */
256 struct fixed_phy_port
{
257 unsigned int devnum
; /* ethernet port */
258 unsigned int speed
; /* specified speed 10,100 or 1000 */
259 unsigned int duplex
; /* specified duplex FULL or HALF */
262 static const struct fixed_phy_port fixed_phy_port
[] = {
263 CFG_FIXED_PHY_PORTS
/* defined in board configuration file */
266 /*-----------------------------------------------------------------------------+
267 * Global variables. TX and RX descriptors and buffers.
268 *-----------------------------------------------------------------------------*/
269 #if !defined(CONFIG_NET_MULTI)
270 struct eth_device
*emac0_dev
= NULL
;
274 * Get count of EMAC devices (doesn't have to be the max. possible number
275 * supported by the cpu)
277 * CONFIG_BOARD_EMAC_COUNT added so now a "dynamic" way to configure the
278 * EMAC count is possible. As it is needed for the Kilauea/Haleakala
279 * 405EX/405EXr eval board, using the same binary.
281 #if defined(CONFIG_BOARD_EMAC_COUNT)
282 #define LAST_EMAC_NUM board_emac_count()
283 #else /* CONFIG_BOARD_EMAC_COUNT */
284 #if defined(CONFIG_HAS_ETH3)
285 #define LAST_EMAC_NUM 4
286 #elif defined(CONFIG_HAS_ETH2)
287 #define LAST_EMAC_NUM 3
288 #elif defined(CONFIG_HAS_ETH1)
289 #define LAST_EMAC_NUM 2
291 #define LAST_EMAC_NUM 1
293 #endif /* CONFIG_BOARD_EMAC_COUNT */
295 /* normal boards start with EMAC0 */
296 #if !defined(CONFIG_EMAC_NR_START)
297 #define CONFIG_EMAC_NR_START 0
300 #define MAL_RX_DESC_SIZE 2048
301 #define MAL_TX_DESC_SIZE 2048
302 #define MAL_ALLOC_SIZE (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE)
304 /*-----------------------------------------------------------------------------+
305 * Prototypes and externals.
306 *-----------------------------------------------------------------------------*/
307 static void enet_rcv (struct eth_device
*dev
, unsigned long malisr
);
309 int enetInt (struct eth_device
*dev
);
310 static void mal_err (struct eth_device
*dev
, unsigned long isr
,
311 unsigned long uic
, unsigned long maldef
,
312 unsigned long mal_errr
);
313 static void emac_err (struct eth_device
*dev
, unsigned long isr
);
315 extern int phy_setup_aneg (char *devname
, unsigned char addr
);
316 extern int emac4xx_miiphy_read (char *devname
, unsigned char addr
,
317 unsigned char reg
, unsigned short *value
);
318 extern int emac4xx_miiphy_write (char *devname
, unsigned char addr
,
319 unsigned char reg
, unsigned short value
);
321 int board_emac_count(void);
323 static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p
)
325 #if defined(CONFIG_440SPE) || \
326 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
327 defined(CONFIG_405EX)
331 val
|= SDR0_MFR_ETH_CLK_SEL_V(hw_p
->devnum
);
333 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
336 mfsdr(SDR0_ETH_CFG
, val
);
337 val
|= SDR0_ETH_CFG_CLK_SEL_V(hw_p
->devnum
);
338 mtsdr(SDR0_ETH_CFG
, val
);
342 static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p
)
344 #if defined(CONFIG_440SPE) || \
345 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
346 defined(CONFIG_405EX)
350 val
&= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p
->devnum
);
352 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
355 mfsdr(SDR0_ETH_CFG
, val
);
356 val
&= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p
->devnum
);
357 mtsdr(SDR0_ETH_CFG
, val
);
361 /*-----------------------------------------------------------------------------+
363 | Disable MAL channel, and EMACn
364 +-----------------------------------------------------------------------------*/
365 static void ppc_4xx_eth_halt (struct eth_device
*dev
)
367 EMAC_4XX_HW_PST hw_p
= dev
->priv
;
370 out_be32((void *)EMAC_IER
+ hw_p
->hw_addr
, 0x00000000); /* disable emac interrupts */
372 /* 1st reset MAL channel */
373 /* Note: writing a 0 to a channel has no effect */
374 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
375 mtdcr (maltxcarr
, (MAL_CR_MMSR
>> (hw_p
->devnum
* 2)));
377 mtdcr (maltxcarr
, (MAL_CR_MMSR
>> hw_p
->devnum
));
379 mtdcr (malrxcarr
, (MAL_CR_MMSR
>> hw_p
->devnum
));
382 while (mfdcr (malrxcasr
) & (MAL_CR_MMSR
>> hw_p
->devnum
)) {
383 udelay (1000); /* Delay 1 MS so as not to hammer the register */
389 /* provide clocks for EMAC internal loopback */
390 emac_loopback_enable(hw_p
);
393 out_be32((void *)EMAC_M0
+ hw_p
->hw_addr
, EMAC_M0_SRST
);
395 /* remove clocks for EMAC internal loopback */
396 emac_loopback_disable(hw_p
);
398 #ifndef CONFIG_NETCONSOLE
399 hw_p
->print_speed
= 1; /* print speed message again next time */
402 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
403 /* don't bypass the TAHOE0/TAHOE1 cores for Linux */
404 mfsdr(SDR0_ETH_CFG
, val
);
405 val
&= ~(SDR0_ETH_CFG_TAHOE0_BYPASS
| SDR0_ETH_CFG_TAHOE1_BYPASS
);
406 mtsdr(SDR0_ETH_CFG
, val
);
412 #if defined (CONFIG_440GX)
413 int ppc_4xx_eth_setup_bridge(int devnum
, bd_t
* bis
)
416 unsigned long zmiifer
;
417 unsigned long rmiifer
;
419 mfsdr(sdr_pfc1
, pfc1
);
420 pfc1
= SDR0_PFC1_EPS_DECODE(pfc1
);
427 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(0);
428 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(1);
429 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(2);
430 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(3);
431 bis
->bi_phymode
[0] = BI_PHYMODE_ZMII
;
432 bis
->bi_phymode
[1] = BI_PHYMODE_ZMII
;
433 bis
->bi_phymode
[2] = BI_PHYMODE_ZMII
;
434 bis
->bi_phymode
[3] = BI_PHYMODE_ZMII
;
437 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(0);
438 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(1);
439 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(2);
440 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(3);
441 bis
->bi_phymode
[0] = BI_PHYMODE_ZMII
;
442 bis
->bi_phymode
[1] = BI_PHYMODE_ZMII
;
443 bis
->bi_phymode
[2] = BI_PHYMODE_ZMII
;
444 bis
->bi_phymode
[3] = BI_PHYMODE_ZMII
;
447 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(0);
448 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V(2);
449 bis
->bi_phymode
[0] = BI_PHYMODE_ZMII
;
450 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
451 bis
->bi_phymode
[2] = BI_PHYMODE_RGMII
;
452 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
455 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(0);
456 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(1);
457 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V (2);
458 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V (3);
459 bis
->bi_phymode
[0] = BI_PHYMODE_ZMII
;
460 bis
->bi_phymode
[1] = BI_PHYMODE_ZMII
;
461 bis
->bi_phymode
[2] = BI_PHYMODE_RGMII
;
462 bis
->bi_phymode
[3] = BI_PHYMODE_RGMII
;
465 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V (0);
466 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V (1);
467 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V (2);
468 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V(3);
469 bis
->bi_phymode
[0] = BI_PHYMODE_ZMII
;
470 bis
->bi_phymode
[1] = BI_PHYMODE_ZMII
;
471 bis
->bi_phymode
[2] = BI_PHYMODE_ZMII
;
472 bis
->bi_phymode
[3] = BI_PHYMODE_RGMII
;
475 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V (0);
476 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V (1);
477 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V(2);
478 bis
->bi_phymode
[0] = BI_PHYMODE_ZMII
;
479 bis
->bi_phymode
[1] = BI_PHYMODE_ZMII
;
480 bis
->bi_phymode
[2] = BI_PHYMODE_RGMII
;
484 zmiifer
= ZMII_FER_MII
<< ZMII_FER_V(devnum
);
486 bis
->bi_phymode
[0] = BI_PHYMODE_ZMII
;
487 bis
->bi_phymode
[1] = BI_PHYMODE_ZMII
;
488 bis
->bi_phymode
[2] = BI_PHYMODE_ZMII
;
489 bis
->bi_phymode
[3] = BI_PHYMODE_ZMII
;
493 /* Ensure we setup mdio for this devnum and ONLY this devnum */
494 zmiifer
|= (ZMII_FER_MDI
) << ZMII_FER_V(devnum
);
496 out_be32((void *)ZMII_FER
, zmiifer
);
497 out_be32((void *)RGMII_FER
, rmiifer
);
501 #endif /* CONFIG_440_GX */
503 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
504 int ppc_4xx_eth_setup_bridge(int devnum
, bd_t
* bis
)
506 unsigned long zmiifer
=0x0;
509 mfsdr(sdr_pfc1
, pfc1
);
510 pfc1
&= SDR0_PFC1_SELECT_MASK
;
513 case SDR0_PFC1_SELECT_CONFIG_2
:
515 out_be32((void *)ZMII_FER
, 0x00);
516 out_be32((void *)RGMII_FER
, 0x00000037);
517 bis
->bi_phymode
[0] = BI_PHYMODE_GMII
;
518 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
520 case SDR0_PFC1_SELECT_CONFIG_4
:
521 /* 2 x RGMII ports */
522 out_be32((void *)ZMII_FER
, 0x00);
523 out_be32((void *)RGMII_FER
, 0x00000055);
524 bis
->bi_phymode
[0] = BI_PHYMODE_RGMII
;
525 bis
->bi_phymode
[1] = BI_PHYMODE_RGMII
;
527 case SDR0_PFC1_SELECT_CONFIG_6
:
529 out_be32((void *)ZMII_FER
,
530 ((ZMII_FER_SMII
) << ZMII_FER_V(0)) |
531 ((ZMII_FER_SMII
) << ZMII_FER_V(1)));
532 out_be32((void *)RGMII_FER
, 0x00000000);
533 bis
->bi_phymode
[0] = BI_PHYMODE_SMII
;
534 bis
->bi_phymode
[1] = BI_PHYMODE_SMII
;
536 case SDR0_PFC1_SELECT_CONFIG_1_2
:
537 /* only 1 x MII supported */
538 out_be32((void *)ZMII_FER
, (ZMII_FER_MII
) << ZMII_FER_V(0));
539 out_be32((void *)RGMII_FER
, 0x00000000);
540 bis
->bi_phymode
[0] = BI_PHYMODE_MII
;
541 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
547 /* Ensure we setup mdio for this devnum and ONLY this devnum */
548 zmiifer
= in_be32((void *)ZMII_FER
);
549 zmiifer
|= (ZMII_FER_MDI
) << ZMII_FER_V(devnum
);
550 out_be32((void *)ZMII_FER
, zmiifer
);
554 #endif /* CONFIG_440EPX */
556 #if defined(CONFIG_405EX)
557 int ppc_4xx_eth_setup_bridge(int devnum
, bd_t
* bis
)
562 * The 405EX(r)'s RGMII bridge can operate in one of several
563 * modes, only one of which (2 x RGMII) allows the
564 * simultaneous use of both EMACs on the 405EX.
567 switch (CONFIG_EMAC_PHY_MODE
) {
569 case EMAC_PHY_MODE_NONE
:
571 rgmiifer
|= RGMII_FER_DIS
<< 0;
572 rgmiifer
|= RGMII_FER_DIS
<< 4;
573 out_be32((void *)RGMII_FER
, rgmiifer
);
574 bis
->bi_phymode
[0] = BI_PHYMODE_NONE
;
575 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
577 case EMAC_PHY_MODE_NONE_RGMII
:
578 /* 1 x RGMII port on channel 0 */
579 rgmiifer
|= RGMII_FER_RGMII
<< 0;
580 rgmiifer
|= RGMII_FER_DIS
<< 4;
581 out_be32((void *)RGMII_FER
, rgmiifer
);
582 bis
->bi_phymode
[0] = BI_PHYMODE_RGMII
;
583 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
585 case EMAC_PHY_MODE_RGMII_NONE
:
586 /* 1 x RGMII port on channel 1 */
587 rgmiifer
|= RGMII_FER_DIS
<< 0;
588 rgmiifer
|= RGMII_FER_RGMII
<< 4;
589 out_be32((void *)RGMII_FER
, rgmiifer
);
590 bis
->bi_phymode
[0] = BI_PHYMODE_NONE
;
591 bis
->bi_phymode
[1] = BI_PHYMODE_RGMII
;
593 case EMAC_PHY_MODE_RGMII_RGMII
:
594 /* 2 x RGMII ports */
595 rgmiifer
|= RGMII_FER_RGMII
<< 0;
596 rgmiifer
|= RGMII_FER_RGMII
<< 4;
597 out_be32((void *)RGMII_FER
, rgmiifer
);
598 bis
->bi_phymode
[0] = BI_PHYMODE_RGMII
;
599 bis
->bi_phymode
[1] = BI_PHYMODE_RGMII
;
601 case EMAC_PHY_MODE_NONE_GMII
:
602 /* 1 x GMII port on channel 0 */
603 rgmiifer
|= RGMII_FER_GMII
<< 0;
604 rgmiifer
|= RGMII_FER_DIS
<< 4;
605 out_be32((void *)RGMII_FER
, rgmiifer
);
606 bis
->bi_phymode
[0] = BI_PHYMODE_GMII
;
607 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
609 case EMAC_PHY_MODE_NONE_MII
:
610 /* 1 x MII port on channel 0 */
611 rgmiifer
|= RGMII_FER_MII
<< 0;
612 rgmiifer
|= RGMII_FER_DIS
<< 4;
613 out_be32((void *)RGMII_FER
, rgmiifer
);
614 bis
->bi_phymode
[0] = BI_PHYMODE_MII
;
615 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
617 case EMAC_PHY_MODE_GMII_NONE
:
618 /* 1 x GMII port on channel 1 */
619 rgmiifer
|= RGMII_FER_DIS
<< 0;
620 rgmiifer
|= RGMII_FER_GMII
<< 4;
621 out_be32((void *)RGMII_FER
, rgmiifer
);
622 bis
->bi_phymode
[0] = BI_PHYMODE_NONE
;
623 bis
->bi_phymode
[1] = BI_PHYMODE_GMII
;
625 case EMAC_PHY_MODE_MII_NONE
:
626 /* 1 x MII port on channel 1 */
627 rgmiifer
|= RGMII_FER_DIS
<< 0;
628 rgmiifer
|= RGMII_FER_MII
<< 4;
629 out_be32((void *)RGMII_FER
, rgmiifer
);
630 bis
->bi_phymode
[0] = BI_PHYMODE_NONE
;
631 bis
->bi_phymode
[1] = BI_PHYMODE_MII
;
637 /* Ensure we setup mdio for this devnum and ONLY this devnum */
638 rgmiifer
= in_be32((void *)RGMII_FER
);
639 rgmiifer
|= (1 << (19-devnum
));
640 out_be32((void *)RGMII_FER
, rgmiifer
);
644 #endif /* CONFIG_405EX */
646 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
647 int ppc_4xx_eth_setup_bridge(int devnum
, bd_t
* bis
)
650 u32 zmiifer
; /* ZMII0_FER reg. */
651 u32 rmiifer
; /* RGMII0_FER reg. Bridge 0 */
652 u32 rmiifer1
; /* RGMII0_FER reg. Bridge 1 */
659 #if defined(CONFIG_460EX)
661 mfsdr(SDR0_ETH_CFG
, eth_cfg
);
662 if (((eth_cfg
& SDR0_ETH_CFG_SGMII0_ENABLE
) > 0) &&
663 ((eth_cfg
& SDR0_ETH_CFG_SGMII1_ENABLE
) > 0))
664 mode
= 11; /* config SGMII */
667 mfsdr(SDR0_ETH_CFG
, eth_cfg
);
668 if (((eth_cfg
& SDR0_ETH_CFG_SGMII0_ENABLE
) > 0) &&
669 ((eth_cfg
& SDR0_ETH_CFG_SGMII1_ENABLE
) > 0) &&
670 ((eth_cfg
& SDR0_ETH_CFG_SGMII2_ENABLE
) > 0))
671 mode
= 12; /* config SGMII */
675 * NOTE: 460GT has 2 RGMII bridge cores:
676 * emac0 ------ RGMII0_BASE
680 * emac2 ------ RGMII1_BASE
684 * 460EX has 1 RGMII bridge core:
685 * and RGMII1_BASE is disabled
686 * emac0 ------ RGMII0_BASE
692 * Right now only 2*RGMII is supported. Please extend when needed.
700 /* GMC0 EMAC4_0, ZMII Bridge */
701 zmiifer
|= ZMII_FER_MII
<< ZMII_FER_V(0);
702 bis
->bi_phymode
[0] = BI_PHYMODE_MII
;
703 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
704 bis
->bi_phymode
[2] = BI_PHYMODE_NONE
;
705 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
709 /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */
710 zmiifer
|= ZMII_FER_MII
<< ZMII_FER_V(0);
711 zmiifer
|= ZMII_FER_MII
<< ZMII_FER_V(2);
712 bis
->bi_phymode
[0] = BI_PHYMODE_MII
;
713 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
714 bis
->bi_phymode
[2] = BI_PHYMODE_MII
;
715 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
719 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
720 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(0);
721 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(1);
722 bis
->bi_phymode
[0] = BI_PHYMODE_RMII
;
723 bis
->bi_phymode
[1] = BI_PHYMODE_RMII
;
724 bis
->bi_phymode
[2] = BI_PHYMODE_NONE
;
725 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
729 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */
731 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(0);
732 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(1);
733 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(2);
734 zmiifer
|= ZMII_FER_RMII
<< ZMII_FER_V(3);
735 bis
->bi_phymode
[0] = BI_PHYMODE_RMII
;
736 bis
->bi_phymode
[1] = BI_PHYMODE_RMII
;
737 bis
->bi_phymode
[2] = BI_PHYMODE_RMII
;
738 bis
->bi_phymode
[3] = BI_PHYMODE_RMII
;
742 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
743 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(0);
744 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(1);
745 bis
->bi_phymode
[0] = BI_PHYMODE_SMII
;
746 bis
->bi_phymode
[1] = BI_PHYMODE_SMII
;
747 bis
->bi_phymode
[2] = BI_PHYMODE_NONE
;
748 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
752 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */
754 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(0);
755 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(1);
756 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(2);
757 zmiifer
|= ZMII_FER_SMII
<< ZMII_FER_V(3);
758 bis
->bi_phymode
[0] = BI_PHYMODE_SMII
;
759 bis
->bi_phymode
[1] = BI_PHYMODE_SMII
;
760 bis
->bi_phymode
[2] = BI_PHYMODE_SMII
;
761 bis
->bi_phymode
[3] = BI_PHYMODE_SMII
;
764 /* This is the default mode that we want for board bringup - Maple */
766 /* GMC0 EMAC4_0, RGMII Bridge 0 */
767 rmiifer
|= RGMII_FER_MDIO(0);
770 rmiifer
|= RGMII_FER_GMII
<< RGMII_FER_V(2); /* CH0CFG - EMAC0 */
771 bis
->bi_phymode
[0] = BI_PHYMODE_GMII
;
772 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
773 bis
->bi_phymode
[2] = BI_PHYMODE_NONE
;
774 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
776 rmiifer
|= RGMII_FER_GMII
<< RGMII_FER_V(3); /* CH1CFG - EMAC1 */
777 bis
->bi_phymode
[0] = BI_PHYMODE_NONE
;
778 bis
->bi_phymode
[1] = BI_PHYMODE_GMII
;
779 bis
->bi_phymode
[2] = BI_PHYMODE_NONE
;
780 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
785 /* GMC0 EMAC4_0, RGMII Bridge 0 */
786 /* GMC1 EMAC4_2, RGMII Bridge 1 */
787 rmiifer
|= RGMII_FER_GMII
<< RGMII_FER_V(2); /* CH0CFG - EMAC0 */
788 rmiifer1
|= RGMII_FER_GMII
<< RGMII_FER_V(2); /* CH0CFG - EMAC2 */
789 rmiifer
|= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
790 rmiifer1
|= RGMII_FER_MDIO(0); /* enable MDIO - EMAC2 */
792 bis
->bi_phymode
[0] = BI_PHYMODE_GMII
;
793 bis
->bi_phymode
[1] = BI_PHYMODE_NONE
;
794 bis
->bi_phymode
[2] = BI_PHYMODE_GMII
;
795 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
798 /* 2 RGMII - 460EX */
799 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
800 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V(2);
801 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V(3);
802 rmiifer
|= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
804 bis
->bi_phymode
[0] = BI_PHYMODE_RGMII
;
805 bis
->bi_phymode
[1] = BI_PHYMODE_RGMII
;
806 bis
->bi_phymode
[2] = BI_PHYMODE_NONE
;
807 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
810 /* 4 RGMII - 460GT */
811 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
812 /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */
813 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V(2);
814 rmiifer
|= RGMII_FER_RGMII
<< RGMII_FER_V(3);
815 rmiifer1
|= RGMII_FER_RGMII
<< RGMII_FER_V(2);
816 rmiifer1
|= RGMII_FER_RGMII
<< RGMII_FER_V(3);
817 bis
->bi_phymode
[0] = BI_PHYMODE_RGMII
;
818 bis
->bi_phymode
[1] = BI_PHYMODE_RGMII
;
819 bis
->bi_phymode
[2] = BI_PHYMODE_RGMII
;
820 bis
->bi_phymode
[3] = BI_PHYMODE_RGMII
;
823 /* 2 SGMII - 460EX */
824 bis
->bi_phymode
[0] = BI_PHYMODE_SGMII
;
825 bis
->bi_phymode
[1] = BI_PHYMODE_SGMII
;
826 bis
->bi_phymode
[2] = BI_PHYMODE_NONE
;
827 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
830 /* 3 SGMII - 460GT */
831 bis
->bi_phymode
[0] = BI_PHYMODE_SGMII
;
832 bis
->bi_phymode
[1] = BI_PHYMODE_SGMII
;
833 bis
->bi_phymode
[2] = BI_PHYMODE_SGMII
;
834 bis
->bi_phymode
[3] = BI_PHYMODE_NONE
;
840 /* Set EMAC for MDIO */
841 mfsdr(SDR0_ETH_CFG
, eth_cfg
);
842 eth_cfg
|= SDR0_ETH_CFG_MDIO_SEL_EMAC0
;
843 mtsdr(SDR0_ETH_CFG
, eth_cfg
);
845 out_be32((void *)RGMII_FER
, rmiifer
);
846 #if defined(CONFIG_460GT)
847 out_be32((void *)RGMII_FER
+ RGMII1_BASE_OFFSET
, rmiifer1
);
850 /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
851 mfsdr(SDR0_ETH_CFG
, eth_cfg
);
852 eth_cfg
|= (SDR0_ETH_CFG_TAHOE0_BYPASS
| SDR0_ETH_CFG_TAHOE1_BYPASS
);
853 mtsdr(SDR0_ETH_CFG
, eth_cfg
);
857 #endif /* CONFIG_460EX || CONFIG_460GT */
859 static inline void *malloc_aligned(u32 size
, u32 align
)
861 return (void *)(((u32
)malloc(size
+ align
) + align
- 1) &
865 static int ppc_4xx_eth_init (struct eth_device
*dev
, bd_t
* bis
)
868 unsigned long reg
= 0;
871 unsigned long duplex
;
872 unsigned long failsafe
;
874 unsigned short devnum
;
875 unsigned short reg_short
;
876 #if defined(CONFIG_440GX) || \
877 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
878 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
879 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
880 defined(CONFIG_405EX)
882 #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
883 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
884 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
885 defined(CONFIG_405EX)
891 #ifdef CONFIG_4xx_DCACHE
892 static u32 last_used_ea
= 0;
894 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
895 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
896 defined(CONFIG_405EX)
900 EMAC_4XX_HW_PST hw_p
= dev
->priv
;
902 /* before doing anything, figure out if we have a MAC address */
904 if (memcmp (dev
->enetaddr
, "\0\0\0\0\0\0", 6) == 0) {
905 printf("ERROR: ethaddr not set!\n");
909 #if defined(CONFIG_440GX) || \
910 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
911 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
912 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
913 defined(CONFIG_405EX)
914 /* Need to get the OPB frequency so we can access the PHY */
915 get_sys_info (&sysinfo
);
919 mtmsr (msr
& ~(MSR_EE
)); /* disable interrupts */
921 devnum
= hw_p
->devnum
;
926 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
927 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
928 * is possible that new packets (without relationship with
929 * current transfer) have got the time to arrived before
930 * netloop calls eth_halt
932 printf ("About preceeding transfer (eth%d):\n"
933 "- Sent packet number %d\n"
934 "- Received packet number %d\n"
935 "- Handled packet number %d\n",
938 hw_p
->stats
.pkts_rx
, hw_p
->stats
.pkts_handled
);
940 hw_p
->stats
.pkts_tx
= 0;
941 hw_p
->stats
.pkts_rx
= 0;
942 hw_p
->stats
.pkts_handled
= 0;
943 hw_p
->print_speed
= 1; /* print speed message again next time */
946 hw_p
->tx_err_index
= 0; /* Transmit Error Index for tx_err_log */
947 hw_p
->rx_err_index
= 0; /* Receive Error Index for rx_err_log */
949 hw_p
->rx_slot
= 0; /* MAL Receive Slot */
950 hw_p
->rx_i_index
= 0; /* Receive Interrupt Queue Index */
951 hw_p
->rx_u_index
= 0; /* Receive User Queue Index */
953 hw_p
->tx_slot
= 0; /* MAL Transmit Slot */
954 hw_p
->tx_i_index
= 0; /* Transmit Interrupt Queue Index */
955 hw_p
->tx_u_index
= 0; /* Transmit User Queue Index */
957 #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
959 /* NOTE: 440GX spec states that mode is mutually exclusive */
960 /* NOTE: Therefore, disable all other EMACS, since we handle */
961 /* NOTE: only one emac at a time */
963 out_be32((void *)ZMII_FER
, 0);
966 #if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
967 out_be32((void *)ZMII_FER
, (ZMII_FER_RMII
| ZMII_FER_MDI
) << ZMII_FER_V (devnum
));
968 #elif defined(CONFIG_440GX) || \
969 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
970 defined(CONFIG_460EX) || defined(CONFIG_460GT)
971 ethgroup
= ppc_4xx_eth_setup_bridge(devnum
, bis
);
974 out_be32((void *)ZMII_SSR
, ZMII_SSR_SP
<< ZMII_SSR_V(devnum
));
975 #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
976 #if defined(CONFIG_405EX)
977 ethgroup
= ppc_4xx_eth_setup_bridge(devnum
, bis
);
982 /* provide clocks for EMAC internal loopback */
983 emac_loopback_enable(hw_p
);
986 out_be32((void *)EMAC_M0
+ hw_p
->hw_addr
, EMAC_M0_SRST
);
988 /* remove clocks for EMAC internal loopback */
989 emac_loopback_disable(hw_p
);
992 while ((in_be32((void *)EMAC_M0
+ hw_p
->hw_addr
) & (EMAC_M0_SRST
)) && failsafe
) {
997 printf("\nProblem resetting EMAC!\n");
999 #if defined(CONFIG_440GX) || \
1000 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1001 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
1002 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1003 defined(CONFIG_405EX)
1004 /* Whack the M1 register */
1006 mode_reg
&= ~0x00000038;
1007 if (sysinfo
.freqOPB
<= 50000000);
1008 else if (sysinfo
.freqOPB
<= 66666667)
1009 mode_reg
|= EMAC_M1_OBCI_66
;
1010 else if (sysinfo
.freqOPB
<= 83333333)
1011 mode_reg
|= EMAC_M1_OBCI_83
;
1012 else if (sysinfo
.freqOPB
<= 100000000)
1013 mode_reg
|= EMAC_M1_OBCI_100
;
1015 mode_reg
|= EMAC_M1_OBCI_GT100
;
1017 out_be32((void *)EMAC_M1
+ hw_p
->hw_addr
, mode_reg
);
1018 #endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
1020 #if defined(CONFIG_GPCS_PHY_ADDR) || defined(CONFIG_GPCS_PHY1_ADDR) || \
1021 defined(CONFIG_GPCS_PHY2_ADDR) || defined(CONFIG_GPCS_PHY3_ADDR)
1022 if (bis
->bi_phymode
[devnum
] == BI_PHYMODE_SGMII
) {
1024 * In SGMII mode, GPCS access is needed for
1025 * communication with the internal SGMII SerDes.
1028 #if defined(CONFIG_GPCS_PHY_ADDR)
1030 reg
= CONFIG_GPCS_PHY_ADDR
;
1033 #if defined(CONFIG_GPCS_PHY1_ADDR)
1035 reg
= CONFIG_GPCS_PHY1_ADDR
;
1038 #if defined(CONFIG_GPCS_PHY2_ADDR)
1040 reg
= CONFIG_GPCS_PHY2_ADDR
;
1043 #if defined(CONFIG_GPCS_PHY3_ADDR)
1045 reg
= CONFIG_GPCS_PHY3_ADDR
;
1050 mode_reg
= in_be32((void *)EMAC_M1
+ hw_p
->hw_addr
);
1051 mode_reg
|= EMAC_M1_MF_1000GPCS
| EMAC_M1_IPPA_SET(reg
);
1052 out_be32((void *)EMAC_M1
+ hw_p
->hw_addr
, mode_reg
);
1054 /* Configure GPCS interface to recommended setting for SGMII */
1055 miiphy_reset(dev
->name
, reg
);
1056 miiphy_write(dev
->name
, reg
, 0x04, 0x8120); /* AsymPause, FDX */
1057 miiphy_write(dev
->name
, reg
, 0x07, 0x2801); /* msg_pg, toggle */
1058 miiphy_write(dev
->name
, reg
, 0x00, 0x0140); /* 1Gbps, FDX */
1060 #endif /* defined(CONFIG_GPCS_PHY_ADDR) */
1062 /* wait for PHY to complete auto negotiation */
1066 reg
= CONFIG_PHY_ADDR
;
1068 #if defined (CONFIG_PHY1_ADDR)
1070 reg
= CONFIG_PHY1_ADDR
;
1073 #if defined (CONFIG_PHY2_ADDR)
1075 reg
= CONFIG_PHY2_ADDR
;
1078 #if defined (CONFIG_PHY3_ADDR)
1080 reg
= CONFIG_PHY3_ADDR
;
1084 reg
= CONFIG_PHY_ADDR
;
1088 bis
->bi_phynum
[devnum
] = reg
;
1090 if (reg
== CONFIG_FIXED_PHY
)
1093 #if defined(CONFIG_PHY_RESET)
1095 * Reset the phy, only if its the first time through
1096 * otherwise, just check the speeds & feeds
1098 if (hw_p
->first_init
== 0) {
1099 #if defined(CONFIG_M88E1111_PHY)
1100 miiphy_write (dev
->name
, reg
, 0x14, 0x0ce3);
1101 miiphy_write (dev
->name
, reg
, 0x18, 0x4101);
1102 miiphy_write (dev
->name
, reg
, 0x09, 0x0e00);
1103 miiphy_write (dev
->name
, reg
, 0x04, 0x01e1);
1105 #if defined(CONFIG_M88E1112_PHY)
1106 if (bis
->bi_phymode
[devnum
] == BI_PHYMODE_SGMII
) {
1108 * Marvell 88E1112 PHY needs to have the SGMII MAC
1109 * interace (page 2) properly configured to
1110 * communicate with the 460EX/GT GPCS interface.
1113 /* Set access to Page 2 */
1114 miiphy_write(dev
->name
, reg
, 0x16, 0x0002);
1116 miiphy_write(dev
->name
, reg
, 0x00, 0x0040); /* 1Gbps */
1117 miiphy_read(dev
->name
, reg
, 0x1a, ®_short
);
1118 reg_short
|= 0x8000; /* bypass Auto-Negotiation */
1119 miiphy_write(dev
->name
, reg
, 0x1a, reg_short
);
1120 miiphy_reset(dev
->name
, reg
); /* reset MAC interface */
1122 /* Reset access to Page 0 */
1123 miiphy_write(dev
->name
, reg
, 0x16, 0x0000);
1125 #endif /* defined(CONFIG_M88E1112_PHY) */
1126 miiphy_reset (dev
->name
, reg
);
1128 #if defined(CONFIG_440GX) || \
1129 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1130 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
1131 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1132 defined(CONFIG_405EX)
1134 #if defined(CONFIG_CIS8201_PHY)
1136 * Cicada 8201 PHY needs to have an extended register whacked
1139 if (((devnum
== 2) || (devnum
== 3)) && (4 == ethgroup
)) {
1140 #if defined(CONFIG_CIS8201_SHORT_ETCH)
1141 miiphy_write (dev
->name
, reg
, 23, 0x1300);
1143 miiphy_write (dev
->name
, reg
, 23, 0x1000);
1146 * Vitesse VSC8201/Cicada CIS8201 errata:
1147 * Interoperability problem with Intel 82547EI phys
1148 * This work around (provided by Vitesse) changes
1149 * the default timer convergence from 8ms to 12ms
1151 miiphy_write (dev
->name
, reg
, 0x1f, 0x2a30);
1152 miiphy_write (dev
->name
, reg
, 0x08, 0x0200);
1153 miiphy_write (dev
->name
, reg
, 0x1f, 0x52b5);
1154 miiphy_write (dev
->name
, reg
, 0x02, 0x0004);
1155 miiphy_write (dev
->name
, reg
, 0x01, 0x0671);
1156 miiphy_write (dev
->name
, reg
, 0x00, 0x8fae);
1157 miiphy_write (dev
->name
, reg
, 0x1f, 0x2a30);
1158 miiphy_write (dev
->name
, reg
, 0x08, 0x0000);
1159 miiphy_write (dev
->name
, reg
, 0x1f, 0x0000);
1160 /* end Vitesse/Cicada errata */
1162 #endif /* defined(CONFIG_CIS8201_PHY) */
1164 #if defined(CONFIG_ET1011C_PHY)
1166 * Agere ET1011c PHY needs to have an extended register whacked
1169 if (((devnum
== 2) || (devnum
==3)) && (4 == ethgroup
)) {
1170 miiphy_read (dev
->name
, reg
, 0x16, ®_short
);
1171 reg_short
&= ~(0x7);
1172 reg_short
|= 0x6; /* RGMII DLL Delay*/
1173 miiphy_write (dev
->name
, reg
, 0x16, reg_short
);
1175 miiphy_read (dev
->name
, reg
, 0x17, ®_short
);
1176 reg_short
&= ~(0x40);
1177 miiphy_write (dev
->name
, reg
, 0x17, reg_short
);
1179 miiphy_write(dev
->name
, reg
, 0x1c, 0x74f0);
1181 #endif /* defined(CONFIG_ET1011C_PHY) */
1183 #endif /* defined(CONFIG_440GX) ... */
1184 /* Start/Restart autonegotiation */
1185 phy_setup_aneg (dev
->name
, reg
);
1188 #endif /* defined(CONFIG_PHY_RESET) */
1190 miiphy_read (dev
->name
, reg
, PHY_BMSR
, ®_short
);
1193 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
1195 if ((reg_short
& PHY_BMSR_AUTN_ABLE
)
1196 && !(reg_short
& PHY_BMSR_AUTN_COMP
)) {
1197 puts ("Waiting for PHY auto negotiation to complete");
1199 while (!(reg_short
& PHY_BMSR_AUTN_COMP
)) {
1203 if (i
> PHY_AUTONEGOTIATE_TIMEOUT
) {
1204 puts (" TIMEOUT !\n");
1208 if ((i
++ % 1000) == 0) {
1211 udelay (1000); /* 1 ms */
1212 miiphy_read (dev
->name
, reg
, PHY_BMSR
, ®_short
);
1215 udelay (500000); /* another 500 ms (results in faster booting) */
1219 if (reg
== CONFIG_FIXED_PHY
) {
1220 for (i
= 0; i
< ARRAY_SIZE(fixed_phy_port
); i
++) {
1221 if (devnum
== fixed_phy_port
[i
].devnum
) {
1222 speed
= fixed_phy_port
[i
].speed
;
1223 duplex
= fixed_phy_port
[i
].duplex
;
1228 if (i
== ARRAY_SIZE(fixed_phy_port
)) {
1229 printf("ERROR: PHY (%s) not configured correctly!\n",
1234 speed
= miiphy_speed(dev
->name
, reg
);
1235 duplex
= miiphy_duplex(dev
->name
, reg
);
1238 if (hw_p
->print_speed
) {
1239 hw_p
->print_speed
= 0;
1240 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
1241 (int) speed
, (duplex
== HALF
) ? "HALF" : "FULL",
1245 #if defined(CONFIG_440) && \
1246 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
1247 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
1248 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
1249 #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
1250 mfsdr(sdr_mfr
, reg
);
1252 reg
= (reg
& ~SDR0_MFR_ZMII_MODE_MASK
) | SDR0_MFR_ZMII_MODE_RMII_100M
;
1254 reg
= (reg
& ~SDR0_MFR_ZMII_MODE_MASK
) | SDR0_MFR_ZMII_MODE_RMII_10M
;
1256 mtsdr(sdr_mfr
, reg
);
1259 /* Set ZMII/RGMII speed according to the phy link speed */
1260 reg
= in_be32((void *)ZMII_SSR
);
1261 if ( (speed
== 100) || (speed
== 1000) )
1262 out_be32((void *)ZMII_SSR
, reg
| (ZMII_SSR_SP
<< ZMII_SSR_V (devnum
)));
1264 out_be32((void *)ZMII_SSR
, reg
& (~(ZMII_SSR_SP
<< ZMII_SSR_V (devnum
))));
1266 if ((devnum
== 2) || (devnum
== 3)) {
1268 reg
= (RGMII_SSR_SP_1000MBPS
<< RGMII_SSR_V (devnum
));
1269 else if (speed
== 100)
1270 reg
= (RGMII_SSR_SP_100MBPS
<< RGMII_SSR_V (devnum
));
1271 else if (speed
== 10)
1272 reg
= (RGMII_SSR_SP_10MBPS
<< RGMII_SSR_V (devnum
));
1274 printf("Error in RGMII Speed\n");
1277 out_be32((void *)RGMII_SSR
, reg
);
1279 #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
1281 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1282 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1283 defined(CONFIG_405EX)
1285 rgmii_channel
= devnum
- 2;
1287 rgmii_channel
= devnum
;
1290 reg
= (RGMII_SSR_SP_1000MBPS
<< RGMII_SSR_V(rgmii_channel
));
1291 else if (speed
== 100)
1292 reg
= (RGMII_SSR_SP_100MBPS
<< RGMII_SSR_V(rgmii_channel
));
1293 else if (speed
== 10)
1294 reg
= (RGMII_SSR_SP_10MBPS
<< RGMII_SSR_V(rgmii_channel
));
1296 printf("Error in RGMII Speed\n");
1299 out_be32((void *)RGMII_SSR
, reg
);
1300 #if defined(CONFIG_460GT)
1301 if ((devnum
== 2) || (devnum
== 3))
1302 out_be32((void *)RGMII_SSR
+ RGMII1_BASE_OFFSET
, reg
);
1306 /* set the Mal configuration reg */
1307 #if defined(CONFIG_440GX) || \
1308 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1309 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
1310 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1311 defined(CONFIG_405EX)
1312 mtdcr (malmcr
, MAL_CR_PLBB
| MAL_CR_OPBBL
| MAL_CR_LEA
|
1313 MAL_CR_PLBLT_DEFAULT
| MAL_CR_EOPIE
| 0x00330000);
1315 mtdcr (malmcr
, MAL_CR_PLBB
| MAL_CR_OPBBL
| MAL_CR_LEA
| MAL_CR_PLBLT_DEFAULT
);
1316 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
1317 if (get_pvr() == PVR_440GP_RB
) {
1318 mtdcr (malmcr
, mfdcr(malmcr
) & ~MAL_CR_PLBB
);
1323 * Malloc MAL buffer desciptors, make sure they are
1324 * aligned on cache line boundary size
1325 * (401/403/IOP480 = 16, 405 = 32)
1326 * and doesn't cross cache block boundaries.
1328 if (hw_p
->first_init
== 0) {
1329 debug("*** Allocating descriptor memory ***\n");
1331 bd_cached
= (u32
)malloc_aligned(MAL_ALLOC_SIZE
, 4096);
1333 printf("%s: Error allocating MAL descriptor buffers!\n", __func__
);
1337 #ifdef CONFIG_4xx_DCACHE
1338 flush_dcache_range(bd_cached
, bd_cached
+ MAL_ALLOC_SIZE
);
1340 #if defined(CFG_MEM_TOP_HIDE)
1341 bd_uncached
= bis
->bi_memsize
+ CFG_MEM_TOP_HIDE
;
1343 bd_uncached
= bis
->bi_memsize
;
1346 bd_uncached
= last_used_ea
+ MAL_ALLOC_SIZE
;
1348 last_used_ea
= bd_uncached
;
1349 program_tlb(bd_cached
, bd_uncached
, MAL_ALLOC_SIZE
,
1350 TLB_WORD2_I_ENABLE
);
1352 bd_uncached
= bd_cached
;
1354 hw_p
->tx_phys
= bd_cached
;
1355 hw_p
->rx_phys
= bd_cached
+ MAL_TX_DESC_SIZE
;
1356 hw_p
->tx
= (mal_desc_t
*)(bd_uncached
);
1357 hw_p
->rx
= (mal_desc_t
*)(bd_uncached
+ MAL_TX_DESC_SIZE
);
1358 debug("hw_p->tx=%08x, hw_p->rx=%08x\n", hw_p
->tx
, hw_p
->rx
);
1361 for (i
= 0; i
< NUM_TX_BUFF
; i
++) {
1362 hw_p
->tx
[i
].ctrl
= 0;
1363 hw_p
->tx
[i
].data_len
= 0;
1364 if (hw_p
->first_init
== 0)
1365 hw_p
->txbuf_ptr
= malloc_aligned(MAL_ALLOC_SIZE
,
1367 hw_p
->tx
[i
].data_ptr
= hw_p
->txbuf_ptr
;
1368 if ((NUM_TX_BUFF
- 1) == i
)
1369 hw_p
->tx
[i
].ctrl
|= MAL_TX_CTRL_WRAP
;
1370 hw_p
->tx_run
[i
] = -1;
1371 debug("TX_BUFF %d @ 0x%08lx\n", i
, (u32
)hw_p
->tx
[i
].data_ptr
);
1374 for (i
= 0; i
< NUM_RX_BUFF
; i
++) {
1375 hw_p
->rx
[i
].ctrl
= 0;
1376 hw_p
->rx
[i
].data_len
= 0;
1377 hw_p
->rx
[i
].data_ptr
= (char *)NetRxPackets
[i
];
1378 if ((NUM_RX_BUFF
- 1) == i
)
1379 hw_p
->rx
[i
].ctrl
|= MAL_RX_CTRL_WRAP
;
1380 hw_p
->rx
[i
].ctrl
|= MAL_RX_CTRL_EMPTY
| MAL_RX_CTRL_INTR
;
1381 hw_p
->rx_ready
[i
] = -1;
1382 debug("RX_BUFF %d @ 0x%08lx\n", i
, (u32
)hw_p
->rx
[i
].data_ptr
);
1387 reg
|= dev
->enetaddr
[0]; /* set high address */
1389 reg
|= dev
->enetaddr
[1];
1391 out_be32((void *)EMAC_IAH
+ hw_p
->hw_addr
, reg
);
1394 reg
|= dev
->enetaddr
[2]; /* set low address */
1396 reg
|= dev
->enetaddr
[3];
1398 reg
|= dev
->enetaddr
[4];
1400 reg
|= dev
->enetaddr
[5];
1402 out_be32((void *)EMAC_IAL
+ hw_p
->hw_addr
, reg
);
1406 /* setup MAL tx & rx channel pointers */
1407 #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
1408 mtdcr (maltxctp2r
, hw_p
->tx_phys
);
1410 mtdcr (maltxctp1r
, hw_p
->tx_phys
);
1412 #if defined(CONFIG_440)
1413 mtdcr (maltxbattr
, 0x0);
1414 mtdcr (malrxbattr
, 0x0);
1417 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
1418 mtdcr (malrxctp8r
, hw_p
->rx_phys
);
1419 /* set RX buffer size */
1420 mtdcr (malrcbs8
, ENET_MAX_MTU_ALIGNED
/ 16);
1422 mtdcr (malrxctp1r
, hw_p
->rx_phys
);
1423 /* set RX buffer size */
1424 mtdcr (malrcbs1
, ENET_MAX_MTU_ALIGNED
/ 16);
1427 #if defined (CONFIG_440GX)
1429 /* setup MAL tx & rx channel pointers */
1430 mtdcr (maltxbattr
, 0x0);
1431 mtdcr (malrxbattr
, 0x0);
1432 mtdcr (maltxctp2r
, hw_p
->tx_phys
);
1433 mtdcr (malrxctp2r
, hw_p
->rx_phys
);
1434 /* set RX buffer size */
1435 mtdcr (malrcbs2
, ENET_MAX_MTU_ALIGNED
/ 16);
1438 /* setup MAL tx & rx channel pointers */
1439 mtdcr (maltxbattr
, 0x0);
1440 mtdcr (maltxctp3r
, hw_p
->tx_phys
);
1441 mtdcr (malrxbattr
, 0x0);
1442 mtdcr (malrxctp3r
, hw_p
->rx_phys
);
1443 /* set RX buffer size */
1444 mtdcr (malrcbs3
, ENET_MAX_MTU_ALIGNED
/ 16);
1446 #endif /* CONFIG_440GX */
1447 #if defined (CONFIG_460GT)
1449 /* setup MAL tx & rx channel pointers */
1450 mtdcr (maltxbattr
, 0x0);
1451 mtdcr (malrxbattr
, 0x0);
1452 mtdcr (maltxctp2r
, hw_p
->tx_phys
);
1453 mtdcr (malrxctp16r
, hw_p
->rx_phys
);
1454 /* set RX buffer size */
1455 mtdcr (malrcbs16
, ENET_MAX_MTU_ALIGNED
/ 16);
1458 /* setup MAL tx & rx channel pointers */
1459 mtdcr (maltxbattr
, 0x0);
1460 mtdcr (malrxbattr
, 0x0);
1461 mtdcr (maltxctp3r
, hw_p
->tx_phys
);
1462 mtdcr (malrxctp24r
, hw_p
->rx_phys
);
1463 /* set RX buffer size */
1464 mtdcr (malrcbs24
, ENET_MAX_MTU_ALIGNED
/ 16);
1466 #endif /* CONFIG_460GT */
1469 /* setup MAL tx & rx channel pointers */
1470 #if defined(CONFIG_440)
1471 mtdcr (maltxbattr
, 0x0);
1472 mtdcr (malrxbattr
, 0x0);
1474 mtdcr (maltxctp0r
, hw_p
->tx_phys
);
1475 mtdcr (malrxctp0r
, hw_p
->rx_phys
);
1476 /* set RX buffer size */
1477 mtdcr (malrcbs0
, ENET_MAX_MTU_ALIGNED
/ 16);
1481 /* Enable MAL transmit and receive channels */
1482 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
1483 mtdcr (maltxcasr
, (MAL_TXRX_CASR
>> (hw_p
->devnum
*2)));
1485 mtdcr (maltxcasr
, (MAL_TXRX_CASR
>> hw_p
->devnum
));
1487 mtdcr (malrxcasr
, (MAL_TXRX_CASR
>> hw_p
->devnum
));
1489 /* set transmit enable & receive enable */
1490 out_be32((void *)EMAC_M0
+ hw_p
->hw_addr
, EMAC_M0_TXE
| EMAC_M0_RXE
);
1492 mode_reg
= in_be32((void *)EMAC_M1
+ hw_p
->hw_addr
);
1494 /* set rx-/tx-fifo size */
1495 mode_reg
= (mode_reg
& ~EMAC_MR1_FIFO_MASK
) | EMAC_MR1_FIFO_SIZE
;
1498 if (speed
== _1000BASET
) {
1499 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1500 defined(CONFIG_440SP) || defined(CONFIG_440SPE)
1503 mfsdr (sdr_pfc1
, pfc1
);
1504 pfc1
|= SDR0_PFC1_EM_1000
;
1505 mtsdr (sdr_pfc1
, pfc1
);
1507 mode_reg
= mode_reg
| EMAC_M1_MF_1000MBPS
| EMAC_M1_IST
;
1508 } else if (speed
== _100BASET
)
1509 mode_reg
= mode_reg
| EMAC_M1_MF_100MBPS
| EMAC_M1_IST
;
1511 mode_reg
= mode_reg
& ~0x00C00000; /* 10 MBPS */
1513 mode_reg
= mode_reg
| 0x80000000 | EMAC_M1_IST
;
1515 out_be32((void *)EMAC_M1
+ hw_p
->hw_addr
, mode_reg
);
1517 /* Enable broadcast and indvidual address */
1518 /* TBS: enabling runts as some misbehaved nics will send runts */
1519 out_be32((void *)EMAC_RXM
+ hw_p
->hw_addr
, EMAC_RMR_BAE
| EMAC_RMR_IAE
);
1521 /* we probably need to set the tx mode1 reg? maybe at tx time */
1523 /* set transmit request threshold register */
1524 out_be32((void *)EMAC_TRTR
+ hw_p
->hw_addr
, 0x18000000); /* 256 byte threshold */
1526 /* set receive low/high water mark register */
1527 #if defined(CONFIG_440)
1528 /* 440s has a 64 byte burst length */
1529 out_be32((void *)EMAC_RX_HI_LO_WMARK
+ hw_p
->hw_addr
, 0x80009000);
1531 /* 405s have a 16 byte burst length */
1532 out_be32((void *)EMAC_RX_HI_LO_WMARK
+ hw_p
->hw_addr
, 0x0f002000);
1533 #endif /* defined(CONFIG_440) */
1534 out_be32((void *)EMAC_TXM1
+ hw_p
->hw_addr
, 0xf8640000);
1536 /* Set fifo limit entry in tx mode 0 */
1537 out_be32((void *)EMAC_TXM0
+ hw_p
->hw_addr
, 0x00000003);
1539 out_be32((void *)EMAC_I_FRAME_GAP_REG
+ hw_p
->hw_addr
, 0x00000008);
1542 hw_p
->emac_ier
= EMAC_ISR_PTLE
| EMAC_ISR_BFCS
| EMAC_ISR_ORE
| EMAC_ISR_IRE
;
1543 if (speed
== _100BASET
)
1544 hw_p
->emac_ier
= hw_p
->emac_ier
| EMAC_ISR_SYE
;
1546 out_be32((void *)EMAC_ISR
+ hw_p
->hw_addr
, 0xffffffff); /* clear pending interrupts */
1547 out_be32((void *)EMAC_IER
+ hw_p
->hw_addr
, hw_p
->emac_ier
);
1549 if (hw_p
->first_init
== 0) {
1551 * Connect interrupt service routines
1553 irq_install_handler(ETH_IRQ_NUM(hw_p
->devnum
),
1554 (interrupt_handler_t
*) enetInt
, dev
);
1557 mtmsr (msr
); /* enable interrupts again */
1560 hw_p
->first_init
= 1;
1566 static int ppc_4xx_eth_send (struct eth_device
*dev
, volatile void *ptr
,
1569 struct enet_frame
*ef_ptr
;
1570 ulong time_start
, time_now
;
1571 unsigned long temp_txm0
;
1572 EMAC_4XX_HW_PST hw_p
= dev
->priv
;
1574 ef_ptr
= (struct enet_frame
*) ptr
;
1576 /*-----------------------------------------------------------------------+
1577 * Copy in our address into the frame.
1578 *-----------------------------------------------------------------------*/
1579 (void) memcpy (ef_ptr
->source_addr
, dev
->enetaddr
, ENET_ADDR_LENGTH
);
1581 /*-----------------------------------------------------------------------+
1582 * If frame is too long or too short, modify length.
1583 *-----------------------------------------------------------------------*/
1584 /* TBS: where does the fragment go???? */
1585 if (len
> ENET_MAX_MTU
)
1588 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1589 memcpy ((void *) hw_p
->txbuf_ptr
, (const void *) ptr
, len
);
1590 flush_dcache_range((u32
)hw_p
->txbuf_ptr
, (u32
)hw_p
->txbuf_ptr
+ len
);
1592 /*-----------------------------------------------------------------------+
1593 * set TX Buffer busy, and send it
1594 *-----------------------------------------------------------------------*/
1595 hw_p
->tx
[hw_p
->tx_slot
].ctrl
= (MAL_TX_CTRL_LAST
|
1596 EMAC_TX_CTRL_GFCS
| EMAC_TX_CTRL_GP
) &
1597 ~(EMAC_TX_CTRL_ISA
| EMAC_TX_CTRL_RSA
);
1598 if ((NUM_TX_BUFF
- 1) == hw_p
->tx_slot
)
1599 hw_p
->tx
[hw_p
->tx_slot
].ctrl
|= MAL_TX_CTRL_WRAP
;
1601 hw_p
->tx
[hw_p
->tx_slot
].data_len
= (short) len
;
1602 hw_p
->tx
[hw_p
->tx_slot
].ctrl
|= MAL_TX_CTRL_READY
;
1606 out_be32((void *)EMAC_TXM0
+ hw_p
->hw_addr
,
1607 in_be32((void *)EMAC_TXM0
+ hw_p
->hw_addr
) | EMAC_TXM0_GNP0
);
1608 #ifdef INFO_4XX_ENET
1609 hw_p
->stats
.pkts_tx
++;
1612 /*-----------------------------------------------------------------------+
1613 * poll unitl the packet is sent and then make sure it is OK
1614 *-----------------------------------------------------------------------*/
1615 time_start
= get_timer (0);
1617 temp_txm0
= in_be32((void *)EMAC_TXM0
+ hw_p
->hw_addr
);
1618 /* loop until either TINT turns on or 3 seconds elapse */
1619 if ((temp_txm0
& EMAC_TXM0_GNP0
) != 0) {
1620 /* transmit is done, so now check for errors
1621 * If there is an error, an interrupt should
1622 * happen when we return
1624 time_now
= get_timer (0);
1625 if ((time_now
- time_start
) > 3000) {
1634 int enetInt (struct eth_device
*dev
)
1637 int rc
= -1; /* default to not us */
1645 EMAC_4XX_HW_PST hw_p
;
1648 * Because the mal is generic, we need to get the current
1651 #if defined(CONFIG_NET_MULTI)
1652 dev
= eth_get_dev();
1659 /* enter loop that stays in interrupt code until nothing to service */
1663 uic_mal
= mfdcr(UIC_BASE_MAL
+ UIC_MSR
);
1664 uic_mal_err
= mfdcr(UIC_BASE_MAL_ERR
+ UIC_MSR
);
1665 uic_emac
= mfdcr(UIC_BASE_EMAC
+ UIC_MSR
);
1666 uic_emac_b
= mfdcr(UIC_BASE_EMAC_B
+ UIC_MSR
);
1668 if (!(uic_mal
& (UIC_MAL_RXEOB
| UIC_MAL_TXEOB
))
1669 && !(uic_mal_err
& (UIC_MAL_SERR
| UIC_MAL_TXDE
| UIC_MAL_RXDE
))
1670 && !(uic_emac
& UIC_ETHx
) && !(uic_emac_b
& UIC_ETHxB
)) {
1675 /* get and clear controller status interrupts */
1676 /* look at MAL and EMAC error interrupts */
1677 if (uic_mal_err
& (UIC_MAL_SERR
| UIC_MAL_TXDE
| UIC_MAL_RXDE
)) {
1678 /* we have a MAL error interrupt */
1679 mal_isr
= mfdcr(malesr
);
1680 mal_err(dev
, mal_isr
, uic_mal_err
,
1681 MAL_UIC_DEF
, MAL_UIC_ERR
);
1683 /* clear MAL error interrupt status bits */
1684 mtdcr(UIC_BASE_MAL_ERR
+ UIC_SR
,
1685 UIC_MAL_SERR
| UIC_MAL_TXDE
| UIC_MAL_RXDE
);
1690 /* look for EMAC errors */
1691 if ((uic_emac
& UIC_ETHx
) || (uic_emac_b
& UIC_ETHxB
)) {
1692 emac_isr
= in_be32((void *)EMAC_ISR
+ hw_p
->hw_addr
);
1693 emac_err(dev
, emac_isr
);
1695 /* clear EMAC error interrupt status bits */
1696 mtdcr(UIC_BASE_EMAC
+ UIC_SR
, UIC_ETHx
);
1697 mtdcr(UIC_BASE_EMAC_B
+ UIC_SR
, UIC_ETHxB
);
1702 /* handle MAX TX EOB interrupt from a tx */
1703 if (uic_mal
& UIC_MAL_TXEOB
) {
1704 /* clear MAL interrupt status bits */
1705 mal_eob
= mfdcr(maltxeobisr
);
1706 mtdcr(maltxeobisr
, mal_eob
);
1707 mtdcr(UIC_BASE_MAL
+ UIC_SR
, UIC_MAL_TXEOB
);
1709 /* indicate that we serviced an interrupt */
1714 /* handle MAL RX EOB interupt from a receive */
1715 /* check for EOB on valid channels */
1716 if (uic_mal
& UIC_MAL_RXEOB
) {
1717 mal_eob
= mfdcr(malrxeobisr
);
1719 (0x80000000 >> (hw_p
->devnum
* MAL_RX_CHAN_MUL
))) {
1720 /* push packet to upper layer */
1721 enet_rcv(dev
, emac_isr
);
1723 /* clear MAL interrupt status bits */
1724 mtdcr(UIC_BASE_MAL
+ UIC_SR
, UIC_MAL_RXEOB
);
1726 /* indicate that we serviced an interrupt */
1736 /*-----------------------------------------------------------------------------+
1738 *-----------------------------------------------------------------------------*/
1739 static void mal_err (struct eth_device
*dev
, unsigned long isr
,
1740 unsigned long uic
, unsigned long maldef
,
1741 unsigned long mal_errr
)
1743 EMAC_4XX_HW_PST hw_p
= dev
->priv
;
1745 mtdcr (malesr
, isr
); /* clear interrupt */
1747 /* clear DE interrupt */
1748 mtdcr (maltxdeir
, 0xC0000000);
1749 mtdcr (malrxdeir
, 0x80000000);
1751 #ifdef INFO_4XX_ENET
1752 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr
, uic
, maldef
, mal_errr
);
1755 eth_init (hw_p
->bis
); /* start again... */
1758 /*-----------------------------------------------------------------------------+
1759 * EMAC Error Routine
1760 *-----------------------------------------------------------------------------*/
1761 static void emac_err (struct eth_device
*dev
, unsigned long isr
)
1763 EMAC_4XX_HW_PST hw_p
= dev
->priv
;
1765 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p
->devnum
, isr
);
1766 out_be32((void *)EMAC_ISR
+ hw_p
->hw_addr
, isr
);
1769 /*-----------------------------------------------------------------------------+
1770 * enet_rcv() handles the ethernet receive data
1771 *-----------------------------------------------------------------------------*/
1772 static void enet_rcv (struct eth_device
*dev
, unsigned long malisr
)
1774 struct enet_frame
*ef_ptr
;
1775 unsigned long data_len
;
1776 unsigned long rx_eob_isr
;
1777 EMAC_4XX_HW_PST hw_p
= dev
->priv
;
1783 rx_eob_isr
= mfdcr (malrxeobisr
);
1784 if ((0x80000000 >> (hw_p
->devnum
* MAL_RX_CHAN_MUL
)) & rx_eob_isr
) {
1786 mtdcr (malrxeobisr
, rx_eob_isr
);
1789 while (1) { /* do all */
1792 if ((MAL_RX_CTRL_EMPTY
& hw_p
->rx
[i
].ctrl
)
1793 || (loop_count
>= NUM_RX_BUFF
))
1798 data_len
= (unsigned long) hw_p
->rx
[i
].data_len
& 0x0fff; /* Get len */
1800 if (data_len
> ENET_MAX_MTU
) /* Check len */
1803 if (EMAC_RX_ERRORS
& hw_p
->rx
[i
].ctrl
) { /* Check Errors */
1805 hw_p
->stats
.rx_err_log
[hw_p
->
1808 hw_p
->rx_err_index
++;
1809 if (hw_p
->rx_err_index
==
1811 hw_p
->rx_err_index
=
1814 } /* data_len < max mtu */
1816 if (!data_len
) { /* no data */
1817 hw_p
->rx
[i
].ctrl
|= MAL_RX_CTRL_EMPTY
; /* Free Recv Buffer */
1819 hw_p
->stats
.data_len_err
++; /* Error at Rx */
1824 /* Check if user has already eaten buffer */
1825 /* if not => ERROR */
1826 else if (hw_p
->rx_ready
[hw_p
->rx_i_index
] != -1) {
1827 if (hw_p
->is_receiving
)
1828 printf ("ERROR : Receive buffers are full!\n");
1831 hw_p
->stats
.rx_frames
++;
1832 hw_p
->stats
.rx
+= data_len
;
1833 ef_ptr
= (struct enet_frame
*) hw_p
->rx
[i
].
1835 #ifdef INFO_4XX_ENET
1836 hw_p
->stats
.pkts_rx
++;
1841 hw_p
->rx_ready
[hw_p
->rx_i_index
] = i
;
1843 if (NUM_RX_BUFF
== hw_p
->rx_i_index
)
1844 hw_p
->rx_i_index
= 0;
1847 if (NUM_RX_BUFF
== hw_p
->rx_slot
)
1851 * free receive buffer only when
1852 * buffer has been handled (eth_rx)
1853 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1857 } /* if EMACK_RXCHL */
1861 static int ppc_4xx_eth_rx (struct eth_device
*dev
)
1866 EMAC_4XX_HW_PST hw_p
= dev
->priv
;
1868 hw_p
->is_receiving
= 1; /* tell driver */
1872 * use ring buffer and
1873 * get index from rx buffer desciptor queue
1875 user_index
= hw_p
->rx_ready
[hw_p
->rx_u_index
];
1876 if (user_index
== -1) {
1878 break; /* nothing received - leave for() loop */
1882 mtmsr (msr
& ~(MSR_EE
));
1884 length
= hw_p
->rx
[user_index
].data_len
& 0x0fff;
1886 /* Pass the packet up to the protocol layers. */
1887 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1888 /* NetReceive(NetRxPackets[i], length); */
1889 invalidate_dcache_range((u32
)hw_p
->rx
[user_index
].data_ptr
,
1890 (u32
)hw_p
->rx
[user_index
].data_ptr
+
1892 NetReceive (NetRxPackets
[user_index
], length
- 4);
1893 /* Free Recv Buffer */
1894 hw_p
->rx
[user_index
].ctrl
|= MAL_RX_CTRL_EMPTY
;
1895 /* Free rx buffer descriptor queue */
1896 hw_p
->rx_ready
[hw_p
->rx_u_index
] = -1;
1898 if (NUM_RX_BUFF
== hw_p
->rx_u_index
)
1899 hw_p
->rx_u_index
= 0;
1901 #ifdef INFO_4XX_ENET
1902 hw_p
->stats
.pkts_handled
++;
1905 mtmsr (msr
); /* Enable IRQ's */
1908 hw_p
->is_receiving
= 0; /* tell driver */
1913 int ppc_4xx_eth_initialize (bd_t
* bis
)
1915 static int virgin
= 0;
1916 struct eth_device
*dev
;
1918 EMAC_4XX_HW_PST hw
= NULL
;
1919 u8 ethaddr
[4 + CONFIG_EMAC_NR_START
][6];
1923 #if defined(CONFIG_440GX)
1926 mfsdr (sdr_pfc1
, pfc1
);
1927 pfc1
&= ~(0x01e00000);
1929 mtsdr (sdr_pfc1
, pfc1
);
1932 /* first clear all mac-addresses */
1933 for (eth_num
= 0; eth_num
< LAST_EMAC_NUM
; eth_num
++)
1934 memcpy(ethaddr
[eth_num
], "\0\0\0\0\0\0", 6);
1936 for (eth_num
= 0; eth_num
< LAST_EMAC_NUM
; eth_num
++) {
1938 default: /* fall through */
1940 memcpy(ethaddr
[eth_num
+ CONFIG_EMAC_NR_START
],
1941 bis
->bi_enetaddr
, 6);
1942 hw_addr
[eth_num
] = 0x0;
1944 #ifdef CONFIG_HAS_ETH1
1946 memcpy(ethaddr
[eth_num
+ CONFIG_EMAC_NR_START
],
1947 bis
->bi_enet1addr
, 6);
1948 hw_addr
[eth_num
] = 0x100;
1951 #ifdef CONFIG_HAS_ETH2
1953 memcpy(ethaddr
[eth_num
+ CONFIG_EMAC_NR_START
],
1954 bis
->bi_enet2addr
, 6);
1955 #if defined(CONFIG_460GT)
1956 hw_addr
[eth_num
] = 0x300;
1958 hw_addr
[eth_num
] = 0x400;
1962 #ifdef CONFIG_HAS_ETH3
1964 memcpy(ethaddr
[eth_num
+ CONFIG_EMAC_NR_START
],
1965 bis
->bi_enet3addr
, 6);
1966 #if defined(CONFIG_460GT)
1967 hw_addr
[eth_num
] = 0x400;
1969 hw_addr
[eth_num
] = 0x600;
1976 /* set phy num and mode */
1977 bis
->bi_phynum
[0] = CONFIG_PHY_ADDR
;
1978 bis
->bi_phymode
[0] = 0;
1980 #if defined(CONFIG_PHY1_ADDR)
1981 bis
->bi_phynum
[1] = CONFIG_PHY1_ADDR
;
1982 bis
->bi_phymode
[1] = 0;
1984 #if defined(CONFIG_440GX)
1985 bis
->bi_phynum
[2] = CONFIG_PHY2_ADDR
;
1986 bis
->bi_phynum
[3] = CONFIG_PHY3_ADDR
;
1987 bis
->bi_phymode
[2] = 2;
1988 bis
->bi_phymode
[3] = 2;
1991 #if defined(CONFIG_440GX) || \
1992 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1993 defined(CONFIG_405EX)
1994 ppc_4xx_eth_setup_bridge(0, bis
);
1997 for (eth_num
= 0; eth_num
< LAST_EMAC_NUM
; eth_num
++) {
1999 * See if we can actually bring up the interface,
2000 * otherwise, skip it
2002 if (memcmp (ethaddr
[eth_num
], "\0\0\0\0\0\0", 6) == 0) {
2003 bis
->bi_phymode
[eth_num
] = BI_PHYMODE_NONE
;
2007 /* Allocate device structure */
2008 dev
= (struct eth_device
*) malloc (sizeof (*dev
));
2010 printf ("ppc_4xx_eth_initialize: "
2011 "Cannot allocate eth_device %d\n", eth_num
);
2014 memset(dev
, 0, sizeof(*dev
));
2016 /* Allocate our private use data */
2017 hw
= (EMAC_4XX_HW_PST
) malloc (sizeof (*hw
));
2019 printf ("ppc_4xx_eth_initialize: "
2020 "Cannot allocate private hw data for eth_device %d",
2025 memset(hw
, 0, sizeof(*hw
));
2027 hw
->hw_addr
= hw_addr
[eth_num
];
2028 memcpy (dev
->enetaddr
, ethaddr
[eth_num
], 6);
2029 hw
->devnum
= eth_num
;
2030 hw
->print_speed
= 1;
2032 sprintf (dev
->name
, "ppc_4xx_eth%d", eth_num
- CONFIG_EMAC_NR_START
);
2033 dev
->priv
= (void *) hw
;
2034 dev
->init
= ppc_4xx_eth_init
;
2035 dev
->halt
= ppc_4xx_eth_halt
;
2036 dev
->send
= ppc_4xx_eth_send
;
2037 dev
->recv
= ppc_4xx_eth_rx
;
2040 /* set the MAL IER ??? names may change with new spec ??? */
2041 #if defined(CONFIG_440SPE) || \
2042 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
2043 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
2044 defined(CONFIG_405EX)
2046 MAL_IER_PT
| MAL_IER_PRE
| MAL_IER_PWE
|
2047 MAL_IER_DE
| MAL_IER_OTE
| MAL_IER_OE
| MAL_IER_PE
;
2050 MAL_IER_DE
| MAL_IER_NE
| MAL_IER_TE
|
2051 MAL_IER_OPBE
| MAL_IER_PLBE
;
2053 mtdcr (malesr
, 0xffffffff); /* clear pending interrupts */
2054 mtdcr (maltxdeir
, 0xffffffff); /* clear pending interrupts */
2055 mtdcr (malrxdeir
, 0xffffffff); /* clear pending interrupts */
2056 mtdcr (malier
, mal_ier
);
2058 /* install MAL interrupt handler */
2059 irq_install_handler (VECNUM_MAL_SERR
,
2060 (interrupt_handler_t
*) enetInt
,
2062 irq_install_handler (VECNUM_MAL_TXEOB
,
2063 (interrupt_handler_t
*) enetInt
,
2065 irq_install_handler (VECNUM_MAL_RXEOB
,
2066 (interrupt_handler_t
*) enetInt
,
2068 irq_install_handler (VECNUM_MAL_TXDE
,
2069 (interrupt_handler_t
*) enetInt
,
2071 irq_install_handler (VECNUM_MAL_RXDE
,
2072 (interrupt_handler_t
*) enetInt
,
2077 #if defined(CONFIG_NET_MULTI)
2083 #if defined(CONFIG_NET_MULTI)
2084 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
2085 miiphy_register (dev
->name
,
2086 emac4xx_miiphy_read
, emac4xx_miiphy_write
);
2089 } /* end for each supported device */
2094 #if !defined(CONFIG_NET_MULTI)
2095 void eth_halt (void) {
2097 ppc_4xx_eth_halt(emac0_dev
);
2103 int eth_init (bd_t
*bis
)
2105 ppc_4xx_eth_initialize(bis
);
2107 return ppc_4xx_eth_init(emac0_dev
, bis
);
2109 printf("ERROR: ethaddr not set!\n");
2114 int eth_send(volatile void *packet
, int length
)
2116 return (ppc_4xx_eth_send(emac0_dev
, packet
, length
));
2121 return (ppc_4xx_eth_rx(emac0_dev
));
2124 int emac4xx_miiphy_initialize (bd_t
* bis
)
2126 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
2127 miiphy_register ("ppc_4xx_eth0",
2128 emac4xx_miiphy_read
, emac4xx_miiphy_write
);
2133 #endif /* !defined(CONFIG_NET_MULTI) */