blob: 587605dfd1f8b0da64c8538e5834e87ebc9e5651 [file] [log] [blame]
wdenkba56f622004-02-06 23:19:44 +00001/*-----------------------------------------------------------------------------+
2 *
Wolfgang Denk265817c2005-09-25 00:53:22 +02003 * 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.
wdenkba56f622004-02-06 23:19:44 +00009 *
Wolfgang Denk265817c2005-09-25 00:53:22 +020010 * 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.
wdenkba56f622004-02-06 23:19:44 +000013 *
Wolfgang Denk265817c2005-09-25 00:53:22 +020014 * 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.
wdenkba56f622004-02-06 23:19:44 +000017 *
Wolfgang Denk265817c2005-09-25 00:53:22 +020018 * COPYRIGHT I B M CORPORATION 1995
19 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
wdenkba56f622004-02-06 23:19:44 +000020 *-----------------------------------------------------------------------------*/
21/*-----------------------------------------------------------------------------+
22 *
Wolfgang Denk265817c2005-09-25 00:53:22 +020023 * File Name: enetemac.c
wdenkba56f622004-02-06 23:19:44 +000024 *
Wolfgang Denk265817c2005-09-25 00:53:22 +020025 * Function: Device driver for the ethernet EMAC3 macro on the 405GP.
wdenkba56f622004-02-06 23:19:44 +000026 *
Wolfgang Denk265817c2005-09-25 00:53:22 +020027 * Author: Mark Wisner
wdenkba56f622004-02-06 23:19:44 +000028 *
29 * Change Activity-
30 *
Wolfgang Denk265817c2005-09-25 00:53:22 +020031 * 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
48 * include/net.h
49 * - Receive buffer descriptor ring is used to send buffers
50 * to the user
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
66 * used anymore)
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).
wdenkba56f622004-02-06 23:19:44 +000070 *-----------------------------------------------------------------------------*
Wolfgang Denk265817c2005-09-25 00:53:22 +020071 * 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
74 * (2 EMACs) also
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.
wdenkba56f622004-02-06 23:19:44 +000078 *-----------------------------------------------------------------------------*/
79
80#include <config.h>
wdenkba56f622004-02-06 23:19:44 +000081#include <common.h>
82#include <net.h>
83#include <asm/processor.h>
Stefan Roese2d834762007-10-23 14:03:17 +020084#include <asm/io.h>
Stefan Roeseff768cb2007-10-31 18:01:24 +010085#include <asm/cache.h>
86#include <asm/mmu.h>
wdenkba56f622004-02-06 23:19:44 +000087#include <commproc.h>
Stefan Roesed6c61aa2005-08-16 18:18:00 +020088#include <ppc4xx.h>
89#include <ppc4xx_enet.h>
wdenkba56f622004-02-06 23:19:44 +000090#include <405_mal.h>
91#include <miiphy.h>
92#include <malloc.h>
wdenkba56f622004-02-06 23:19:44 +000093
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -050094#if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
Stefan Roesed6c61aa2005-08-16 18:18:00 +020095#error "CONFIG_MII has to be defined!"
96#endif
wdenkba56f622004-02-06 23:19:44 +000097
Stefan Roese1e25f952005-10-20 16:34:28 +020098#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI)
99#error "CONFIG_NET_MULTI has to be defined for NetConsole"
100#endif
101
Wolfgang Denk265817c2005-09-25 00:53:22 +0200102#define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
Stefan Roese1338e6a2007-10-23 14:05:08 +0200103#define PHY_AUTONEGOTIATE_TIMEOUT 5000 /* 5000 ms autonegotiate timeout */
wdenkba56f622004-02-06 23:19:44 +0000104
wdenkba56f622004-02-06 23:19:44 +0000105/* Ethernet Transmit and Receive Buffers */
106/* AS.HARNOIS
107 * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
108 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
109 */
Wolfgang Denk265817c2005-09-25 00:53:22 +0200110#define ENET_MAX_MTU PKTSIZE
wdenkba56f622004-02-06 23:19:44 +0000111#define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
112
wdenkba56f622004-02-06 23:19:44 +0000113/*-----------------------------------------------------------------------------+
114 * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
115 * Interrupt Controller).
116 *-----------------------------------------------------------------------------*/
Stefan Roesed1631fe2008-06-26 13:40:57 +0200117#define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * VECNUM_ETH1_OFFS))
118
119#if defined(CONFIG_HAS_ETH3)
120#if !defined(CONFIG_440GX)
121#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
122 UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
123#else
124/* Unfortunately 440GX spreads EMAC interrupts on multiple UIC's */
125#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
126#define UIC_ETHxB (UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
127#endif /* !defined(CONFIG_440GX) */
128#elif defined(CONFIG_HAS_ETH2)
129#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
130 UIC_MASK(ETH_IRQ_NUM(2)))
131#elif defined(CONFIG_HAS_ETH1)
132#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
133#else
134#define UIC_ETHx UIC_MASK(ETH_IRQ_NUM(0))
135#endif
136
137/*
138 * Define a default version for UIC_ETHxB for non 440GX so that we can
139 * use common code for all 4xx variants
140 */
141#if !defined(UIC_ETHxB)
142#define UIC_ETHxB 0
143#endif
144
145#define UIC_MAL_SERR UIC_MASK(VECNUM_MAL_SERR)
146#define UIC_MAL_TXDE UIC_MASK(VECNUM_MAL_TXDE)
147#define UIC_MAL_RXDE UIC_MASK(VECNUM_MAL_RXDE)
148#define UIC_MAL_TXEOB UIC_MASK(VECNUM_MAL_TXEOB)
149#define UIC_MAL_RXEOB UIC_MASK(VECNUM_MAL_RXEOB)
150
151#define MAL_UIC_ERR (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
152#define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
153
154/*
155 * We have 3 different interrupt types:
156 * - MAL interrupts indicating successful transfer
157 * - MAL error interrupts indicating MAL related errors
158 * - EMAC interrupts indicating EMAC related errors
159 *
160 * All those interrupts can be on different UIC's, but since
161 * now at least all interrupts from one type are on the same
162 * UIC. Only exception is 440GX where the EMAC interrupts are
163 * spread over two UIC's!
164 */
Stefan Roese5de85142008-06-26 17:36:39 +0200165#if defined(CONFIG_440GX)
166#define UIC_BASE_MAL UIC1_DCR_BASE
167#define UIC_BASE_MAL_ERR UIC2_DCR_BASE
168#define UIC_BASE_EMAC UIC2_DCR_BASE
169#define UIC_BASE_EMAC_B UIC3_DCR_BASE
170#else
Stefan Roesed1631fe2008-06-26 13:40:57 +0200171#define UIC_BASE_MAL (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_TXEOB) * 0x10))
172#define UIC_BASE_MAL_ERR (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_SERR) * 0x10))
173#define UIC_BASE_EMAC (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
Stefan Roesed1631fe2008-06-26 13:40:57 +0200174#define UIC_BASE_EMAC_B (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
175#endif
wdenkba56f622004-02-06 23:19:44 +0000176
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200177#undef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +0000178
Wolfgang Denk265817c2005-09-25 00:53:22 +0200179#define BI_PHYMODE_NONE 0
180#define BI_PHYMODE_ZMII 1
wdenk3c74e322004-02-22 23:46:08 +0000181#define BI_PHYMODE_RGMII 2
Stefan Roese887e2ec2006-09-07 11:51:23 +0200182#define BI_PHYMODE_GMII 3
183#define BI_PHYMODE_RTBI 4
184#define BI_PHYMODE_TBI 5
Stefan Roesedbbd1252007-10-05 17:10:59 +0200185#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100186 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200187 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200188#define BI_PHYMODE_SMII 6
189#define BI_PHYMODE_MII 7
Stefan Roese8ac41e32008-03-11 15:05:26 +0100190#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
191#define BI_PHYMODE_RMII 8
192#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +0200193#endif
Victor Gallardo78d78232008-09-04 23:49:36 -0700194#define BI_PHYMODE_SGMII 9
wdenk3c74e322004-02-22 23:46:08 +0000195
Stefan Roese1941cce2007-10-05 17:35:10 +0200196#if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200197 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100198 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200199 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200200#define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
201#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200202
Stefan Roese8ac41e32008-03-11 15:05:26 +0100203#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
204#define SDR0_ETH_CFG_CLK_SEL_V(n) (0x01 << (8 + n))
205#endif
206
207#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
208#define MAL_RX_CHAN_MUL 8 /* 460EX/GT uses MAL channel 8 for EMAC1 */
209#else
210#define MAL_RX_CHAN_MUL 1
211#endif
212
Victor Gallardo78d78232008-09-04 23:49:36 -0700213/*--------------------------------------------------------------------+
214 * Fixed PHY (PHY-less) support for Ethernet Ports.
215 *--------------------------------------------------------------------*/
216
217/*
218 * Some boards do not have a PHY for each ethernet port. These ports
219 * are known as Fixed PHY (or PHY-less) ports. For such ports, set
220 * the appropriate CONFIG_PHY_ADDR equal to CONFIG_FIXED_PHY and
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200221 * then define CONFIG_SYS_FIXED_PHY_PORTS to define what the speed and
Victor Gallardo78d78232008-09-04 23:49:36 -0700222 * duplex should be for these ports in the board configuration
223 * file.
224 *
225 * For Example:
226 * #define CONFIG_FIXED_PHY 0xFFFFFFFF
227 *
228 * #define CONFIG_PHY_ADDR CONFIG_FIXED_PHY
229 * #define CONFIG_PHY1_ADDR 1
230 * #define CONFIG_PHY2_ADDR CONFIG_FIXED_PHY
231 * #define CONFIG_PHY3_ADDR 3
232 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200233 * #define CONFIG_SYS_FIXED_PHY_PORT(devnum,speed,duplex) \
Victor Gallardo78d78232008-09-04 23:49:36 -0700234 * {devnum, speed, duplex},
235 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200236 * #define CONFIG_SYS_FIXED_PHY_PORTS \
237 * CONFIG_SYS_FIXED_PHY_PORT(0,1000,FULL) \
238 * CONFIG_SYS_FIXED_PHY_PORT(2,100,HALF)
Victor Gallardo78d78232008-09-04 23:49:36 -0700239 */
240
241#ifndef CONFIG_FIXED_PHY
242#define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */
243#endif
244
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200245#ifndef CONFIG_SYS_FIXED_PHY_PORTS
246#define CONFIG_SYS_FIXED_PHY_PORTS /* default is an empty array */
Victor Gallardo78d78232008-09-04 23:49:36 -0700247#endif
248
249struct fixed_phy_port {
250 unsigned int devnum; /* ethernet port */
251 unsigned int speed; /* specified speed 10,100 or 1000 */
252 unsigned int duplex; /* specified duplex FULL or HALF */
253};
254
255static const struct fixed_phy_port fixed_phy_port[] = {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200256 CONFIG_SYS_FIXED_PHY_PORTS /* defined in board configuration file */
Victor Gallardo78d78232008-09-04 23:49:36 -0700257};
258
wdenkba56f622004-02-06 23:19:44 +0000259/*-----------------------------------------------------------------------------+
260 * Global variables. TX and RX descriptors and buffers.
261 *-----------------------------------------------------------------------------*/
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200262
Stefan Roese1e25f952005-10-20 16:34:28 +0200263/*
264 * Get count of EMAC devices (doesn't have to be the max. possible number
265 * supported by the cpu)
Stefan Roese353f2682007-10-23 10:10:08 +0200266 *
267 * CONFIG_BOARD_EMAC_COUNT added so now a "dynamic" way to configure the
268 * EMAC count is possible. As it is needed for the Kilauea/Haleakala
269 * 405EX/405EXr eval board, using the same binary.
Stefan Roese1e25f952005-10-20 16:34:28 +0200270 */
Stefan Roese353f2682007-10-23 10:10:08 +0200271#if defined(CONFIG_BOARD_EMAC_COUNT)
272#define LAST_EMAC_NUM board_emac_count()
273#else /* CONFIG_BOARD_EMAC_COUNT */
Stefan Roese1e25f952005-10-20 16:34:28 +0200274#if defined(CONFIG_HAS_ETH3)
275#define LAST_EMAC_NUM 4
276#elif defined(CONFIG_HAS_ETH2)
277#define LAST_EMAC_NUM 3
278#elif defined(CONFIG_HAS_ETH1)
279#define LAST_EMAC_NUM 2
280#else
281#define LAST_EMAC_NUM 1
282#endif
Stefan Roese353f2682007-10-23 10:10:08 +0200283#endif /* CONFIG_BOARD_EMAC_COUNT */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200284
Stefan Roese5fb692c2007-01-18 10:25:34 +0100285/* normal boards start with EMAC0 */
286#if !defined(CONFIG_EMAC_NR_START)
287#define CONFIG_EMAC_NR_START 0
288#endif
289
Stefan Roeseff768cb2007-10-31 18:01:24 +0100290#define MAL_RX_DESC_SIZE 2048
291#define MAL_TX_DESC_SIZE 2048
292#define MAL_ALLOC_SIZE (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE)
293
wdenkba56f622004-02-06 23:19:44 +0000294/*-----------------------------------------------------------------------------+
295 * Prototypes and externals.
296 *-----------------------------------------------------------------------------*/
297static void enet_rcv (struct eth_device *dev, unsigned long malisr);
298
299int enetInt (struct eth_device *dev);
300static void mal_err (struct eth_device *dev, unsigned long isr,
301 unsigned long uic, unsigned long maldef,
302 unsigned long mal_errr);
303static void emac_err (struct eth_device *dev, unsigned long isr);
304
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200305extern int phy_setup_aneg (char *devname, unsigned char addr);
306extern int emac4xx_miiphy_read (char *devname, unsigned char addr,
307 unsigned char reg, unsigned short *value);
308extern int emac4xx_miiphy_write (char *devname, unsigned char addr,
309 unsigned char reg, unsigned short value);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200310
Stefan Roese353f2682007-10-23 10:10:08 +0200311int board_emac_count(void);
312
Stefan Roese8ac41e32008-03-11 15:05:26 +0100313static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p)
314{
315#if defined(CONFIG_440SPE) || \
316 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
317 defined(CONFIG_405EX)
318 u32 val;
319
320 mfsdr(sdr_mfr, val);
321 val |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
322 mtsdr(sdr_mfr, val);
323#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
324 u32 val;
325
326 mfsdr(SDR0_ETH_CFG, val);
327 val |= SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
328 mtsdr(SDR0_ETH_CFG, val);
329#endif
330}
331
332static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p)
333{
334#if defined(CONFIG_440SPE) || \
335 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
336 defined(CONFIG_405EX)
337 u32 val;
338
339 mfsdr(sdr_mfr, val);
340 val &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
341 mtsdr(sdr_mfr, val);
342#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
343 u32 val;
344
345 mfsdr(SDR0_ETH_CFG, val);
346 val &= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
347 mtsdr(SDR0_ETH_CFG, val);
348#endif
349}
350
wdenkba56f622004-02-06 23:19:44 +0000351/*-----------------------------------------------------------------------------+
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200352| ppc_4xx_eth_halt
wdenkba56f622004-02-06 23:19:44 +0000353| Disable MAL channel, and EMACn
wdenkba56f622004-02-06 23:19:44 +0000354+-----------------------------------------------------------------------------*/
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200355static void ppc_4xx_eth_halt (struct eth_device *dev)
wdenkba56f622004-02-06 23:19:44 +0000356{
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200357 EMAC_4XX_HW_PST hw_p = dev->priv;
Stefan Roese9ad31982008-03-19 16:35:12 +0100358 u32 val = 10000;
wdenkba56f622004-02-06 23:19:44 +0000359
Stefan Roese2d834762007-10-23 14:03:17 +0200360 out_be32((void *)EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
wdenkba56f622004-02-06 23:19:44 +0000361
362 /* 1st reset MAL channel */
363 /* Note: writing a 0 to a channel has no effect */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200364#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
365 mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
366#else
wdenkba56f622004-02-06 23:19:44 +0000367 mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200368#endif
wdenkba56f622004-02-06 23:19:44 +0000369 mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
370
371 /* wait for reset */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200372 while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
wdenkba56f622004-02-06 23:19:44 +0000373 udelay (1000); /* Delay 1 MS so as not to hammer the register */
Stefan Roese9ad31982008-03-19 16:35:12 +0100374 val--;
375 if (val == 0)
wdenkba56f622004-02-06 23:19:44 +0000376 break;
wdenkba56f622004-02-06 23:19:44 +0000377 }
378
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200379 /* provide clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100380 emac_loopback_enable(hw_p);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200381
Stefan Roese8ac41e32008-03-11 15:05:26 +0100382 /* EMAC RESET */
Stefan Roese2d834762007-10-23 14:03:17 +0200383 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenkba56f622004-02-06 23:19:44 +0000384
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200385 /* remove clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100386 emac_loopback_disable(hw_p);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200387
Stefan Roesea93316c2005-10-18 19:17:12 +0200388#ifndef CONFIG_NETCONSOLE
Stefan Roesec157d8e2005-08-01 16:41:48 +0200389 hw_p->print_speed = 1; /* print speed message again next time */
Stefan Roesea93316c2005-10-18 19:17:12 +0200390#endif
Stefan Roesec157d8e2005-08-01 16:41:48 +0200391
Stefan Roese4c9e8552008-03-19 16:20:49 +0100392#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
393 /* don't bypass the TAHOE0/TAHOE1 cores for Linux */
Stefan Roese9ad31982008-03-19 16:35:12 +0100394 mfsdr(SDR0_ETH_CFG, val);
395 val &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
396 mtsdr(SDR0_ETH_CFG, val);
Stefan Roese4c9e8552008-03-19 16:20:49 +0100397#endif
398
wdenkba56f622004-02-06 23:19:44 +0000399 return;
400}
401
Stefan Roese846b0dd2005-08-08 12:42:22 +0200402#if defined (CONFIG_440GX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200403int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
wdenk855a4962004-03-14 18:23:55 +0000404{
405 unsigned long pfc1;
406 unsigned long zmiifer;
407 unsigned long rmiifer;
408
409 mfsdr(sdr_pfc1, pfc1);
410 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
411
412 zmiifer = 0;
413 rmiifer = 0;
414
415 switch (pfc1) {
416 case 1:
417 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
418 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
419 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
420 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
421 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
422 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
423 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
424 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
425 break;
426 case 2:
Stefan Roesef6e495f2006-11-27 17:43:25 +0100427 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
428 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
429 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
430 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
wdenk855a4962004-03-14 18:23:55 +0000431 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;
435 break;
436 case 3:
437 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
438 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
439 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
440 bis->bi_phymode[1] = BI_PHYMODE_NONE;
441 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
442 bis->bi_phymode[3] = BI_PHYMODE_NONE;
443 break;
444 case 4:
445 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
446 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
447 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
448 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
449 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
450 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
451 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
452 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
453 break;
454 case 5:
455 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
456 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
457 zmiifer |= ZMII_FER_SMII << ZMII_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_ZMII;
462 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
463 break;
464 case 6:
465 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
466 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
467 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
wdenk855a4962004-03-14 18:23:55 +0000468 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
469 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
470 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
wdenk855a4962004-03-14 18:23:55 +0000471 break;
472 case 0:
473 default:
474 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
475 rmiifer = 0x0;
476 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
477 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
478 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
479 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
480 break;
481 }
482
483 /* Ensure we setup mdio for this devnum and ONLY this devnum */
484 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
485
Stefan Roeseff768cb2007-10-31 18:01:24 +0100486 out_be32((void *)ZMII_FER, zmiifer);
487 out_be32((void *)RGMII_FER, rmiifer);
wdenk855a4962004-03-14 18:23:55 +0000488
489 return ((int)pfc1);
wdenk855a4962004-03-14 18:23:55 +0000490}
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200491#endif /* CONFIG_440_GX */
wdenk855a4962004-03-14 18:23:55 +0000492
Stefan Roese887e2ec2006-09-07 11:51:23 +0200493#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
494int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
495{
496 unsigned long zmiifer=0x0;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200497 unsigned long pfc1;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200498
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200499 mfsdr(sdr_pfc1, pfc1);
500 pfc1 &= SDR0_PFC1_SELECT_MASK;
501
Wolfgang Denk2f152782007-05-05 18:23:11 +0200502 switch (pfc1) {
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200503 case SDR0_PFC1_SELECT_CONFIG_2:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200504 /* 1 x GMII port */
Stefan Roese2d834762007-10-23 14:03:17 +0200505 out_be32((void *)ZMII_FER, 0x00);
506 out_be32((void *)RGMII_FER, 0x00000037);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200507 bis->bi_phymode[0] = BI_PHYMODE_GMII;
508 bis->bi_phymode[1] = BI_PHYMODE_NONE;
509 break;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200510 case SDR0_PFC1_SELECT_CONFIG_4:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200511 /* 2 x RGMII ports */
Stefan Roese2d834762007-10-23 14:03:17 +0200512 out_be32((void *)ZMII_FER, 0x00);
513 out_be32((void *)RGMII_FER, 0x00000055);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200514 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
515 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
516 break;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200517 case SDR0_PFC1_SELECT_CONFIG_6:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200518 /* 2 x SMII ports */
Stefan Roese2d834762007-10-23 14:03:17 +0200519 out_be32((void *)ZMII_FER,
520 ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
521 ((ZMII_FER_SMII) << ZMII_FER_V(1)));
522 out_be32((void *)RGMII_FER, 0x00000000);
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200523 bis->bi_phymode[0] = BI_PHYMODE_SMII;
524 bis->bi_phymode[1] = BI_PHYMODE_SMII;
525 break;
526 case SDR0_PFC1_SELECT_CONFIG_1_2:
527 /* only 1 x MII supported */
Stefan Roese2d834762007-10-23 14:03:17 +0200528 out_be32((void *)ZMII_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
529 out_be32((void *)RGMII_FER, 0x00000000);
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200530 bis->bi_phymode[0] = BI_PHYMODE_MII;
531 bis->bi_phymode[1] = BI_PHYMODE_NONE;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200532 break;
533 default:
534 break;
535 }
536
537 /* Ensure we setup mdio for this devnum and ONLY this devnum */
Stefan Roese2d834762007-10-23 14:03:17 +0200538 zmiifer = in_be32((void *)ZMII_FER);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200539 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
Stefan Roese2d834762007-10-23 14:03:17 +0200540 out_be32((void *)ZMII_FER, zmiifer);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200541
542 return ((int)0x0);
543}
544#endif /* CONFIG_440EPX */
545
Stefan Roesedbbd1252007-10-05 17:10:59 +0200546#if defined(CONFIG_405EX)
547int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
548{
Grant Erickson1740c1b2008-07-08 08:35:00 -0700549 u32 rgmiifer = 0;
Stefan Roesedbbd1252007-10-05 17:10:59 +0200550
551 /*
Grant Erickson1740c1b2008-07-08 08:35:00 -0700552 * The 405EX(r)'s RGMII bridge can operate in one of several
553 * modes, only one of which (2 x RGMII) allows the
554 * simultaneous use of both EMACs on the 405EX.
Stefan Roesedbbd1252007-10-05 17:10:59 +0200555 */
Grant Erickson1740c1b2008-07-08 08:35:00 -0700556
557 switch (CONFIG_EMAC_PHY_MODE) {
558
559 case EMAC_PHY_MODE_NONE:
560 /* No ports */
561 rgmiifer |= RGMII_FER_DIS << 0;
562 rgmiifer |= RGMII_FER_DIS << 4;
563 out_be32((void *)RGMII_FER, rgmiifer);
564 bis->bi_phymode[0] = BI_PHYMODE_NONE;
565 bis->bi_phymode[1] = BI_PHYMODE_NONE;
566 break;
567 case EMAC_PHY_MODE_NONE_RGMII:
568 /* 1 x RGMII port on channel 0 */
569 rgmiifer |= RGMII_FER_RGMII << 0;
570 rgmiifer |= RGMII_FER_DIS << 4;
571 out_be32((void *)RGMII_FER, rgmiifer);
572 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
573 bis->bi_phymode[1] = BI_PHYMODE_NONE;
574 break;
575 case EMAC_PHY_MODE_RGMII_NONE:
576 /* 1 x RGMII port on channel 1 */
577 rgmiifer |= RGMII_FER_DIS << 0;
578 rgmiifer |= RGMII_FER_RGMII << 4;
579 out_be32((void *)RGMII_FER, rgmiifer);
580 bis->bi_phymode[0] = BI_PHYMODE_NONE;
581 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
582 break;
583 case EMAC_PHY_MODE_RGMII_RGMII:
Stefan Roesedbbd1252007-10-05 17:10:59 +0200584 /* 2 x RGMII ports */
Grant Erickson1740c1b2008-07-08 08:35:00 -0700585 rgmiifer |= RGMII_FER_RGMII << 0;
586 rgmiifer |= RGMII_FER_RGMII << 4;
587 out_be32((void *)RGMII_FER, rgmiifer);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200588 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
589 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
590 break;
Grant Erickson1740c1b2008-07-08 08:35:00 -0700591 case EMAC_PHY_MODE_NONE_GMII:
592 /* 1 x GMII port on channel 0 */
593 rgmiifer |= RGMII_FER_GMII << 0;
594 rgmiifer |= RGMII_FER_DIS << 4;
595 out_be32((void *)RGMII_FER, rgmiifer);
596 bis->bi_phymode[0] = BI_PHYMODE_GMII;
597 bis->bi_phymode[1] = BI_PHYMODE_NONE;
598 break;
599 case EMAC_PHY_MODE_NONE_MII:
600 /* 1 x MII port on channel 0 */
601 rgmiifer |= RGMII_FER_MII << 0;
602 rgmiifer |= RGMII_FER_DIS << 4;
603 out_be32((void *)RGMII_FER, rgmiifer);
604 bis->bi_phymode[0] = BI_PHYMODE_MII;
605 bis->bi_phymode[1] = BI_PHYMODE_NONE;
606 break;
607 case EMAC_PHY_MODE_GMII_NONE:
608 /* 1 x GMII port on channel 1 */
609 rgmiifer |= RGMII_FER_DIS << 0;
610 rgmiifer |= RGMII_FER_GMII << 4;
611 out_be32((void *)RGMII_FER, rgmiifer);
612 bis->bi_phymode[0] = BI_PHYMODE_NONE;
613 bis->bi_phymode[1] = BI_PHYMODE_GMII;
614 break;
615 case EMAC_PHY_MODE_MII_NONE:
616 /* 1 x MII port on channel 1 */
617 rgmiifer |= RGMII_FER_DIS << 0;
618 rgmiifer |= RGMII_FER_MII << 4;
619 out_be32((void *)RGMII_FER, rgmiifer);
620 bis->bi_phymode[0] = BI_PHYMODE_NONE;
621 bis->bi_phymode[1] = BI_PHYMODE_MII;
Stefan Roesedbbd1252007-10-05 17:10:59 +0200622 break;
623 default:
624 break;
625 }
626
627 /* Ensure we setup mdio for this devnum and ONLY this devnum */
Grant Erickson1740c1b2008-07-08 08:35:00 -0700628 rgmiifer = in_be32((void *)RGMII_FER);
629 rgmiifer |= (1 << (19-devnum));
630 out_be32((void *)RGMII_FER, rgmiifer);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200631
632 return ((int)0x0);
633}
634#endif /* CONFIG_405EX */
635
Stefan Roese8ac41e32008-03-11 15:05:26 +0100636#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
637int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
638{
639 u32 eth_cfg;
640 u32 zmiifer; /* ZMII0_FER reg. */
641 u32 rmiifer; /* RGMII0_FER reg. Bridge 0 */
642 u32 rmiifer1; /* RGMII0_FER reg. Bridge 1 */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100643 int mode;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100644
645 zmiifer = 0;
646 rmiifer = 0;
647 rmiifer1 = 0;
648
Stefan Roese4c9e8552008-03-19 16:20:49 +0100649#if defined(CONFIG_460EX)
650 mode = 9;
Victor Gallardo78d78232008-09-04 23:49:36 -0700651 mfsdr(SDR0_ETH_CFG, eth_cfg);
652 if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
653 ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0))
654 mode = 11; /* config SGMII */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100655#else
656 mode = 10;
Victor Gallardo78d78232008-09-04 23:49:36 -0700657 mfsdr(SDR0_ETH_CFG, eth_cfg);
658 if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
659 ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0) &&
660 ((eth_cfg & SDR0_ETH_CFG_SGMII2_ENABLE) > 0))
661 mode = 12; /* config SGMII */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100662#endif
663
Stefan Roese8ac41e32008-03-11 15:05:26 +0100664 /* TODO:
665 * NOTE: 460GT has 2 RGMII bridge cores:
666 * emac0 ------ RGMII0_BASE
667 * |
668 * emac1 -----+
669 *
670 * emac2 ------ RGMII1_BASE
671 * |
672 * emac3 -----+
673 *
674 * 460EX has 1 RGMII bridge core:
675 * and RGMII1_BASE is disabled
676 * emac0 ------ RGMII0_BASE
677 * |
678 * emac1 -----+
679 */
680
681 /*
682 * Right now only 2*RGMII is supported. Please extend when needed.
683 * sr - 2008-02-19
Victor Gallardo78d78232008-09-04 23:49:36 -0700684 * Add SGMII support.
685 * vg - 2008-07-28
Stefan Roese8ac41e32008-03-11 15:05:26 +0100686 */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100687 switch (mode) {
Stefan Roese8ac41e32008-03-11 15:05:26 +0100688 case 1:
689 /* 1 MII - 460EX */
690 /* GMC0 EMAC4_0, ZMII Bridge */
691 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
692 bis->bi_phymode[0] = BI_PHYMODE_MII;
693 bis->bi_phymode[1] = BI_PHYMODE_NONE;
694 bis->bi_phymode[2] = BI_PHYMODE_NONE;
695 bis->bi_phymode[3] = BI_PHYMODE_NONE;
696 break;
697 case 2:
698 /* 2 MII - 460GT */
699 /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */
700 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
701 zmiifer |= ZMII_FER_MII << ZMII_FER_V(2);
702 bis->bi_phymode[0] = BI_PHYMODE_MII;
703 bis->bi_phymode[1] = BI_PHYMODE_NONE;
704 bis->bi_phymode[2] = BI_PHYMODE_MII;
705 bis->bi_phymode[3] = BI_PHYMODE_NONE;
706 break;
707 case 3:
708 /* 2 RMII - 460EX */
709 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
710 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
711 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
712 bis->bi_phymode[0] = BI_PHYMODE_RMII;
713 bis->bi_phymode[1] = BI_PHYMODE_RMII;
714 bis->bi_phymode[2] = BI_PHYMODE_NONE;
715 bis->bi_phymode[3] = BI_PHYMODE_NONE;
716 break;
717 case 4:
718 /* 4 RMII - 460GT */
719 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */
720 /* ZMII Bridge */
721 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
722 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
723 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
724 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
725 bis->bi_phymode[0] = BI_PHYMODE_RMII;
726 bis->bi_phymode[1] = BI_PHYMODE_RMII;
727 bis->bi_phymode[2] = BI_PHYMODE_RMII;
728 bis->bi_phymode[3] = BI_PHYMODE_RMII;
729 break;
730 case 5:
731 /* 2 SMII - 460EX */
732 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
733 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
734 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
735 bis->bi_phymode[0] = BI_PHYMODE_SMII;
736 bis->bi_phymode[1] = BI_PHYMODE_SMII;
737 bis->bi_phymode[2] = BI_PHYMODE_NONE;
738 bis->bi_phymode[3] = BI_PHYMODE_NONE;
739 break;
740 case 6:
741 /* 4 SMII - 460GT */
742 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */
743 /* ZMII Bridge */
744 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
745 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
746 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
747 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
748 bis->bi_phymode[0] = BI_PHYMODE_SMII;
749 bis->bi_phymode[1] = BI_PHYMODE_SMII;
750 bis->bi_phymode[2] = BI_PHYMODE_SMII;
751 bis->bi_phymode[3] = BI_PHYMODE_SMII;
752 break;
753 case 7:
754 /* This is the default mode that we want for board bringup - Maple */
755 /* 1 GMII - 460EX */
756 /* GMC0 EMAC4_0, RGMII Bridge 0 */
757 rmiifer |= RGMII_FER_MDIO(0);
758
759 if (devnum == 0) {
760 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
761 bis->bi_phymode[0] = BI_PHYMODE_GMII;
762 bis->bi_phymode[1] = BI_PHYMODE_NONE;
763 bis->bi_phymode[2] = BI_PHYMODE_NONE;
764 bis->bi_phymode[3] = BI_PHYMODE_NONE;
765 } else {
766 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3); /* CH1CFG - EMAC1 */
767 bis->bi_phymode[0] = BI_PHYMODE_NONE;
768 bis->bi_phymode[1] = BI_PHYMODE_GMII;
769 bis->bi_phymode[2] = BI_PHYMODE_NONE;
770 bis->bi_phymode[3] = BI_PHYMODE_NONE;
771 }
772 break;
773 case 8:
774 /* 2 GMII - 460GT */
775 /* GMC0 EMAC4_0, RGMII Bridge 0 */
776 /* GMC1 EMAC4_2, RGMII Bridge 1 */
777 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
778 rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC2 */
779 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
780 rmiifer1 |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC2 */
781
782 bis->bi_phymode[0] = BI_PHYMODE_GMII;
783 bis->bi_phymode[1] = BI_PHYMODE_NONE;
784 bis->bi_phymode[2] = BI_PHYMODE_GMII;
785 bis->bi_phymode[3] = BI_PHYMODE_NONE;
786 break;
787 case 9:
788 /* 2 RGMII - 460EX */
789 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
790 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
791 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
792 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
793
794 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
795 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
796 bis->bi_phymode[2] = BI_PHYMODE_NONE;
797 bis->bi_phymode[3] = BI_PHYMODE_NONE;
798 break;
799 case 10:
800 /* 4 RGMII - 460GT */
801 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
802 /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */
803 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
804 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
805 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2);
806 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3);
807 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
808 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
809 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
810 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
811 break;
Victor Gallardo78d78232008-09-04 23:49:36 -0700812 case 11:
813 /* 2 SGMII - 460EX */
814 bis->bi_phymode[0] = BI_PHYMODE_SGMII;
815 bis->bi_phymode[1] = BI_PHYMODE_SGMII;
816 bis->bi_phymode[2] = BI_PHYMODE_NONE;
817 bis->bi_phymode[3] = BI_PHYMODE_NONE;
818 break;
819 case 12:
820 /* 3 SGMII - 460GT */
821 bis->bi_phymode[0] = BI_PHYMODE_SGMII;
822 bis->bi_phymode[1] = BI_PHYMODE_SGMII;
823 bis->bi_phymode[2] = BI_PHYMODE_SGMII;
824 bis->bi_phymode[3] = BI_PHYMODE_NONE;
825 break;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100826 default:
827 break;
828 }
829
830 /* Set EMAC for MDIO */
831 mfsdr(SDR0_ETH_CFG, eth_cfg);
832 eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
833 mtsdr(SDR0_ETH_CFG, eth_cfg);
834
835 out_be32((void *)RGMII_FER, rmiifer);
836#if defined(CONFIG_460GT)
837 out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1);
838#endif
839
840 /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
841 mfsdr(SDR0_ETH_CFG, eth_cfg);
842 eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
843 mtsdr(SDR0_ETH_CFG, eth_cfg);
844
845 return 0;
846}
847#endif /* CONFIG_460EX || CONFIG_460GT */
848
Stefan Roeseff768cb2007-10-31 18:01:24 +0100849static inline void *malloc_aligned(u32 size, u32 align)
850{
851 return (void *)(((u32)malloc(size + align) + align - 1) &
852 ~(align - 1));
853}
854
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200855static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
wdenkba56f622004-02-06 23:19:44 +0000856{
Stefan Roeseff768cb2007-10-31 18:01:24 +0100857 int i;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200858 unsigned long reg = 0;
wdenkba56f622004-02-06 23:19:44 +0000859 unsigned long msr;
860 unsigned long speed;
861 unsigned long duplex;
862 unsigned long failsafe;
863 unsigned mode_reg;
864 unsigned short devnum;
865 unsigned short reg_short;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200866#if defined(CONFIG_440GX) || \
867 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200868 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100869 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200870 defined(CONFIG_405EX)
Felix Radensky0c24dec2009-05-31 20:44:15 +0300871 u32 opbfreq;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200872 sys_info_t sysinfo;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200873#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200874 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100875 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200876 defined(CONFIG_405EX)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100877 int ethgroup = -1;
878#endif
Stefan Roesec157d8e2005-08-01 16:41:48 +0200879#endif
Stefan Roeseff768cb2007-10-31 18:01:24 +0100880 u32 bd_cached;
881 u32 bd_uncached = 0;
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +0100882#ifdef CONFIG_4xx_DCACHE
883 static u32 last_used_ea = 0;
884#endif
Stefan Roesee54ec0f2008-04-03 14:50:34 +0200885#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
886 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
887 defined(CONFIG_405EX)
888 int rgmii_channel;
889#endif
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200890
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200891 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +0000892
893 /* before doing anything, figure out if we have a MAC address */
894 /* if not, bail */
Stefan Roese4f92ac32005-10-10 17:43:58 +0200895 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
896 printf("ERROR: ethaddr not set!\n");
wdenkba56f622004-02-06 23:19:44 +0000897 return -1;
Stefan Roese4f92ac32005-10-10 17:43:58 +0200898 }
wdenkba56f622004-02-06 23:19:44 +0000899
Stefan Roese887e2ec2006-09-07 11:51:23 +0200900#if defined(CONFIG_440GX) || \
901 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200902 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100903 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200904 defined(CONFIG_405EX)
wdenkba56f622004-02-06 23:19:44 +0000905 /* Need to get the OPB frequency so we can access the PHY */
906 get_sys_info (&sysinfo);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200907#endif
wdenkba56f622004-02-06 23:19:44 +0000908
wdenkba56f622004-02-06 23:19:44 +0000909 msr = mfmsr ();
910 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
911
912 devnum = hw_p->devnum;
913
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200914#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +0000915 /* AS.HARNOIS
916 * We should have :
Wolfgang Denk265817c2005-09-25 00:53:22 +0200917 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
wdenkba56f622004-02-06 23:19:44 +0000918 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
919 * is possible that new packets (without relationship with
920 * current transfer) have got the time to arrived before
921 * netloop calls eth_halt
922 */
923 printf ("About preceeding transfer (eth%d):\n"
924 "- Sent packet number %d\n"
925 "- Received packet number %d\n"
926 "- Handled packet number %d\n",
927 hw_p->devnum,
928 hw_p->stats.pkts_tx,
929 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
930
931 hw_p->stats.pkts_tx = 0;
932 hw_p->stats.pkts_rx = 0;
933 hw_p->stats.pkts_handled = 0;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200934 hw_p->print_speed = 1; /* print speed message again next time */
wdenkba56f622004-02-06 23:19:44 +0000935#endif
936
Wolfgang Denk265817c2005-09-25 00:53:22 +0200937 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
938 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
wdenkba56f622004-02-06 23:19:44 +0000939
940 hw_p->rx_slot = 0; /* MAL Receive Slot */
941 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
942 hw_p->rx_u_index = 0; /* Receive User Queue Index */
943
944 hw_p->tx_slot = 0; /* MAL Transmit Slot */
945 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
946 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
947
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200948#if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
wdenkba56f622004-02-06 23:19:44 +0000949 /* set RMII mode */
950 /* NOTE: 440GX spec states that mode is mutually exclusive */
951 /* NOTE: Therefore, disable all other EMACS, since we handle */
952 /* NOTE: only one emac at a time */
953 reg = 0;
Stefan Roese2d834762007-10-23 14:03:17 +0200954 out_be32((void *)ZMII_FER, 0);
wdenkba56f622004-02-06 23:19:44 +0000955 udelay (100);
wdenkba56f622004-02-06 23:19:44 +0000956
Stefan Roese8ac41e32008-03-11 15:05:26 +0100957#if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese2d834762007-10-23 14:03:17 +0200958 out_be32((void *)ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
Stefan Roese8ac41e32008-03-11 15:05:26 +0100959#elif defined(CONFIG_440GX) || \
960 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
961 defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200962 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
wdenk0e6d7982004-03-14 00:07:33 +0000963#endif
Stefan Roesec57c7982005-08-11 17:56:56 +0200964
Stefan Roese2d834762007-10-23 14:03:17 +0200965 out_be32((void *)ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100966#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
Stefan Roesedbbd1252007-10-05 17:10:59 +0200967#if defined(CONFIG_405EX)
968 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
969#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200970
Stefan Roese8ac41e32008-03-11 15:05:26 +0100971 sync();
wdenk0e6d7982004-03-14 00:07:33 +0000972
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200973 /* provide clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100974 emac_loopback_enable(hw_p);
wdenk0e6d7982004-03-14 00:07:33 +0000975
Stefan Roese8ac41e32008-03-11 15:05:26 +0100976 /* EMAC RESET */
Stefan Roese2d834762007-10-23 14:03:17 +0200977 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenkba56f622004-02-06 23:19:44 +0000978
Stefan Roese8ac41e32008-03-11 15:05:26 +0100979 /* remove clocks for EMAC internal loopback */
980 emac_loopback_disable(hw_p);
981
wdenkba56f622004-02-06 23:19:44 +0000982 failsafe = 1000;
Stefan Roese2d834762007-10-23 14:03:17 +0200983 while ((in_be32((void *)EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
wdenkba56f622004-02-06 23:19:44 +0000984 udelay (1000);
985 failsafe--;
986 }
Stefan Roese887e2ec2006-09-07 11:51:23 +0200987 if (failsafe <= 0)
988 printf("\nProblem resetting EMAC!\n");
wdenkba56f622004-02-06 23:19:44 +0000989
Stefan Roese887e2ec2006-09-07 11:51:23 +0200990#if defined(CONFIG_440GX) || \
991 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200992 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100993 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200994 defined(CONFIG_405EX)
wdenkba56f622004-02-06 23:19:44 +0000995 /* Whack the M1 register */
996 mode_reg = 0x0;
997 mode_reg &= ~0x00000038;
Felix Radensky0c24dec2009-05-31 20:44:15 +0300998 opbfreq = sysinfo.freqOPB / 1000000;
999 if (opbfreq <= 50);
1000 else if (opbfreq <= 66)
wdenkba56f622004-02-06 23:19:44 +00001001 mode_reg |= EMAC_M1_OBCI_66;
Felix Radensky0c24dec2009-05-31 20:44:15 +03001002 else if (opbfreq <= 83)
wdenkba56f622004-02-06 23:19:44 +00001003 mode_reg |= EMAC_M1_OBCI_83;
Felix Radensky0c24dec2009-05-31 20:44:15 +03001004 else if (opbfreq <= 100)
wdenkba56f622004-02-06 23:19:44 +00001005 mode_reg |= EMAC_M1_OBCI_100;
1006 else
1007 mode_reg |= EMAC_M1_OBCI_GT100;
1008
Stefan Roese2d834762007-10-23 14:03:17 +02001009 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001010#endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
wdenkba56f622004-02-06 23:19:44 +00001011
Victor Gallardo78d78232008-09-04 23:49:36 -07001012#if defined(CONFIG_GPCS_PHY_ADDR) || defined(CONFIG_GPCS_PHY1_ADDR) || \
1013 defined(CONFIG_GPCS_PHY2_ADDR) || defined(CONFIG_GPCS_PHY3_ADDR)
1014 if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
1015 /*
1016 * In SGMII mode, GPCS access is needed for
1017 * communication with the internal SGMII SerDes.
1018 */
1019 switch (devnum) {
1020#if defined(CONFIG_GPCS_PHY_ADDR)
1021 case 0:
1022 reg = CONFIG_GPCS_PHY_ADDR;
1023 break;
1024#endif
1025#if defined(CONFIG_GPCS_PHY1_ADDR)
1026 case 1:
1027 reg = CONFIG_GPCS_PHY1_ADDR;
1028 break;
1029#endif
1030#if defined(CONFIG_GPCS_PHY2_ADDR)
1031 case 2:
1032 reg = CONFIG_GPCS_PHY2_ADDR;
1033 break;
1034#endif
1035#if defined(CONFIG_GPCS_PHY3_ADDR)
1036 case 3:
1037 reg = CONFIG_GPCS_PHY3_ADDR;
1038 break;
1039#endif
1040 }
1041
1042 mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr);
1043 mode_reg |= EMAC_M1_MF_1000GPCS | EMAC_M1_IPPA_SET(reg);
1044 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
1045
1046 /* Configure GPCS interface to recommended setting for SGMII */
1047 miiphy_reset(dev->name, reg);
1048 miiphy_write(dev->name, reg, 0x04, 0x8120); /* AsymPause, FDX */
1049 miiphy_write(dev->name, reg, 0x07, 0x2801); /* msg_pg, toggle */
1050 miiphy_write(dev->name, reg, 0x00, 0x0140); /* 1Gbps, FDX */
1051 }
1052#endif /* defined(CONFIG_GPCS_PHY_ADDR) */
1053
wdenkba56f622004-02-06 23:19:44 +00001054 /* wait for PHY to complete auto negotiation */
1055 reg_short = 0;
wdenkba56f622004-02-06 23:19:44 +00001056 switch (devnum) {
1057 case 0:
1058 reg = CONFIG_PHY_ADDR;
1059 break;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001060#if defined (CONFIG_PHY1_ADDR)
wdenkba56f622004-02-06 23:19:44 +00001061 case 1:
1062 reg = CONFIG_PHY1_ADDR;
1063 break;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001064#endif
Stefan Roese4c9e8552008-03-19 16:20:49 +01001065#if defined (CONFIG_PHY2_ADDR)
wdenkba56f622004-02-06 23:19:44 +00001066 case 2:
1067 reg = CONFIG_PHY2_ADDR;
1068 break;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001069#endif
1070#if defined (CONFIG_PHY3_ADDR)
wdenkba56f622004-02-06 23:19:44 +00001071 case 3:
1072 reg = CONFIG_PHY3_ADDR;
1073 break;
1074#endif
1075 default:
1076 reg = CONFIG_PHY_ADDR;
1077 break;
1078 }
1079
wdenk3c74e322004-02-22 23:46:08 +00001080 bis->bi_phynum[devnum] = reg;
1081
Victor Gallardo78d78232008-09-04 23:49:36 -07001082 if (reg == CONFIG_FIXED_PHY)
1083 goto get_speed;
1084
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001085#if defined(CONFIG_PHY_RESET)
wdenka06752e2004-09-29 22:43:59 +00001086 /*
1087 * Reset the phy, only if its the first time through
1088 * otherwise, just check the speeds & feeds
1089 */
1090 if (hw_p->first_init == 0) {
Stefan Roeseec0c2ec2006-11-27 14:46:06 +01001091#if defined(CONFIG_M88E1111_PHY)
Stefan Roese887e2ec2006-09-07 11:51:23 +02001092 miiphy_write (dev->name, reg, 0x14, 0x0ce3);
1093 miiphy_write (dev->name, reg, 0x18, 0x4101);
1094 miiphy_write (dev->name, reg, 0x09, 0x0e00);
1095 miiphy_write (dev->name, reg, 0x04, 0x01e1);
1096#endif
Victor Gallardo78d78232008-09-04 23:49:36 -07001097#if defined(CONFIG_M88E1112_PHY)
1098 if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
1099 /*
1100 * Marvell 88E1112 PHY needs to have the SGMII MAC
1101 * interace (page 2) properly configured to
1102 * communicate with the 460EX/GT GPCS interface.
1103 */
1104
1105 /* Set access to Page 2 */
1106 miiphy_write(dev->name, reg, 0x16, 0x0002);
1107
1108 miiphy_write(dev->name, reg, 0x00, 0x0040); /* 1Gbps */
1109 miiphy_read(dev->name, reg, 0x1a, &reg_short);
1110 reg_short |= 0x8000; /* bypass Auto-Negotiation */
1111 miiphy_write(dev->name, reg, 0x1a, reg_short);
1112 miiphy_reset(dev->name, reg); /* reset MAC interface */
1113
1114 /* Reset access to Page 0 */
1115 miiphy_write(dev->name, reg, 0x16, 0x0000);
1116 }
1117#endif /* defined(CONFIG_M88E1112_PHY) */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001118 miiphy_reset (dev->name, reg);
wdenkba56f622004-02-06 23:19:44 +00001119
Stefan Roese887e2ec2006-09-07 11:51:23 +02001120#if defined(CONFIG_440GX) || \
1121 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001122 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001123 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001124 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +02001125
wdenk0e6d7982004-03-14 00:07:33 +00001126#if defined(CONFIG_CIS8201_PHY)
wdenkfc1cfcd2004-04-25 15:41:35 +00001127 /*
Stefan Roese17f50f222005-08-04 17:09:16 +02001128 * Cicada 8201 PHY needs to have an extended register whacked
1129 * for RGMII mode.
wdenkfc1cfcd2004-04-25 15:41:35 +00001130 */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001131 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
Stefan Roeseb79316f2005-08-15 12:31:23 +02001132#if defined(CONFIG_CIS8201_SHORT_ETCH)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001133 miiphy_write (dev->name, reg, 23, 0x1300);
Stefan Roeseb79316f2005-08-15 12:31:23 +02001134#else
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001135 miiphy_write (dev->name, reg, 23, 0x1000);
Stefan Roeseb79316f2005-08-15 12:31:23 +02001136#endif
Stefan Roese17f50f222005-08-04 17:09:16 +02001137 /*
1138 * Vitesse VSC8201/Cicada CIS8201 errata:
1139 * Interoperability problem with Intel 82547EI phys
1140 * This work around (provided by Vitesse) changes
1141 * the default timer convergence from 8ms to 12ms
1142 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001143 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1144 miiphy_write (dev->name, reg, 0x08, 0x0200);
1145 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
1146 miiphy_write (dev->name, reg, 0x02, 0x0004);
1147 miiphy_write (dev->name, reg, 0x01, 0x0671);
1148 miiphy_write (dev->name, reg, 0x00, 0x8fae);
1149 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1150 miiphy_write (dev->name, reg, 0x08, 0x0000);
1151 miiphy_write (dev->name, reg, 0x1f, 0x0000);
Stefan Roese17f50f222005-08-04 17:09:16 +02001152 /* end Vitesse/Cicada errata */
1153 }
Stefan Roese6ca86462008-09-05 14:11:40 +02001154#endif /* defined(CONFIG_CIS8201_PHY) */
Stefan Roese5fb692c2007-01-18 10:25:34 +01001155
1156#if defined(CONFIG_ET1011C_PHY)
1157 /*
1158 * Agere ET1011c PHY needs to have an extended register whacked
1159 * for RGMII mode.
1160 */
1161 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
1162 miiphy_read (dev->name, reg, 0x16, &reg_short);
1163 reg_short &= ~(0x7);
1164 reg_short |= 0x6; /* RGMII DLL Delay*/
1165 miiphy_write (dev->name, reg, 0x16, reg_short);
1166
1167 miiphy_read (dev->name, reg, 0x17, &reg_short);
1168 reg_short &= ~(0x40);
1169 miiphy_write (dev->name, reg, 0x17, reg_short);
1170
1171 miiphy_write(dev->name, reg, 0x1c, 0x74f0);
1172 }
Stefan Roese6ca86462008-09-05 14:11:40 +02001173#endif /* defined(CONFIG_ET1011C_PHY) */
Stefan Roese5fb692c2007-01-18 10:25:34 +01001174
Stefan Roese6ca86462008-09-05 14:11:40 +02001175#endif /* defined(CONFIG_440GX) ... */
wdenka06752e2004-09-29 22:43:59 +00001176 /* Start/Restart autonegotiation */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001177 phy_setup_aneg (dev->name, reg);
wdenka06752e2004-09-29 22:43:59 +00001178 udelay (1000);
1179 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001180#endif /* defined(CONFIG_PHY_RESET) */
wdenkba56f622004-02-06 23:19:44 +00001181
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001182 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenkba56f622004-02-06 23:19:44 +00001183
1184 /*
wdenk0e6d7982004-03-14 00:07:33 +00001185 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
wdenkba56f622004-02-06 23:19:44 +00001186 */
1187 if ((reg_short & PHY_BMSR_AUTN_ABLE)
1188 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
1189 puts ("Waiting for PHY auto negotiation to complete");
1190 i = 0;
1191 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
1192 /*
1193 * Timeout reached ?
1194 */
1195 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
1196 puts (" TIMEOUT !\n");
1197 break;
1198 }
1199
1200 if ((i++ % 1000) == 0) {
1201 putc ('.');
1202 }
1203 udelay (1000); /* 1 ms */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001204 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenkba56f622004-02-06 23:19:44 +00001205 }
1206 puts (" done\n");
1207 udelay (500000); /* another 500 ms (results in faster booting) */
1208 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001209
Victor Gallardo78d78232008-09-04 23:49:36 -07001210get_speed:
1211 if (reg == CONFIG_FIXED_PHY) {
1212 for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) {
1213 if (devnum == fixed_phy_port[i].devnum) {
1214 speed = fixed_phy_port[i].speed;
1215 duplex = fixed_phy_port[i].duplex;
1216 break;
1217 }
1218 }
1219
1220 if (i == ARRAY_SIZE(fixed_phy_port)) {
1221 printf("ERROR: PHY (%s) not configured correctly!\n",
1222 dev->name);
1223 return -1;
1224 }
1225 } else {
1226 speed = miiphy_speed(dev->name, reg);
1227 duplex = miiphy_duplex(dev->name, reg);
1228 }
wdenkba56f622004-02-06 23:19:44 +00001229
1230 if (hw_p->print_speed) {
1231 hw_p->print_speed = 0;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001232 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
1233 (int) speed, (duplex == HALF) ? "HALF" : "FULL",
1234 hw_p->devnum);
wdenkba56f622004-02-06 23:19:44 +00001235 }
1236
Stefan Roese8ac41e32008-03-11 15:05:26 +01001237#if defined(CONFIG_440) && \
1238 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
1239 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
1240 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
Stefan Roese846b0dd2005-08-08 12:42:22 +02001241#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001242 mfsdr(sdr_mfr, reg);
1243 if (speed == 100) {
1244 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
1245 } else {
1246 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
1247 }
1248 mtsdr(sdr_mfr, reg);
1249#endif
Stefan Roesec57c7982005-08-11 17:56:56 +02001250
wdenkba56f622004-02-06 23:19:44 +00001251 /* Set ZMII/RGMII speed according to the phy link speed */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001252 reg = in_be32((void *)ZMII_SSR);
wdenk855a4962004-03-14 18:23:55 +00001253 if ( (speed == 100) || (speed == 1000) )
Stefan Roeseff768cb2007-10-31 18:01:24 +01001254 out_be32((void *)ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
wdenkba56f622004-02-06 23:19:44 +00001255 else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001256 out_be32((void *)ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
wdenkba56f622004-02-06 23:19:44 +00001257
1258 if ((devnum == 2) || (devnum == 3)) {
1259 if (speed == 1000)
1260 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1261 else if (speed == 100)
1262 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001263 else if (speed == 10)
wdenkba56f622004-02-06 23:19:44 +00001264 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001265 else {
1266 printf("Error in RGMII Speed\n");
1267 return -1;
1268 }
Stefan Roeseff768cb2007-10-31 18:01:24 +01001269 out_be32((void *)RGMII_SSR, reg);
wdenkba56f622004-02-06 23:19:44 +00001270 }
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001271#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
wdenkba56f622004-02-06 23:19:44 +00001272
Stefan Roesedbbd1252007-10-05 17:10:59 +02001273#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001274 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001275 defined(CONFIG_405EX)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001276 if (devnum >= 2)
1277 rgmii_channel = devnum - 2;
1278 else
1279 rgmii_channel = devnum;
1280
Stefan Roese887e2ec2006-09-07 11:51:23 +02001281 if (speed == 1000)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001282 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001283 else if (speed == 100)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001284 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001285 else if (speed == 10)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001286 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001287 else {
1288 printf("Error in RGMII Speed\n");
1289 return -1;
1290 }
Stefan Roese2d834762007-10-23 14:03:17 +02001291 out_be32((void *)RGMII_SSR, reg);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001292#if defined(CONFIG_460GT)
1293 if ((devnum == 2) || (devnum == 3))
1294 out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
1295#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +02001296#endif
1297
wdenkba56f622004-02-06 23:19:44 +00001298 /* set the Mal configuration reg */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001299#if defined(CONFIG_440GX) || \
1300 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001301 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001302 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001303 defined(CONFIG_405EX)
Stefan Roese17f50f222005-08-04 17:09:16 +02001304 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
1305 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
1306#else
1307 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
wdenkba56f622004-02-06 23:19:44 +00001308 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
Stefan Roese17f50f222005-08-04 17:09:16 +02001309 if (get_pvr() == PVR_440GP_RB) {
1310 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
1311 }
1312#endif
wdenkba56f622004-02-06 23:19:44 +00001313
wdenkba56f622004-02-06 23:19:44 +00001314 /*
1315 * Malloc MAL buffer desciptors, make sure they are
1316 * aligned on cache line boundary size
1317 * (401/403/IOP480 = 16, 405 = 32)
1318 * and doesn't cross cache block boundaries.
1319 */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001320 if (hw_p->first_init == 0) {
1321 debug("*** Allocating descriptor memory ***\n");
wdenkba56f622004-02-06 23:19:44 +00001322
Stefan Roeseff768cb2007-10-31 18:01:24 +01001323 bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
1324 if (!bd_cached) {
Stefan Roeseb0021442008-07-10 09:58:06 +02001325 printf("%s: Error allocating MAL descriptor buffers!\n", __func__);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001326 return -1;
1327 }
Stefan Roeseb79316f2005-08-15 12:31:23 +02001328
Stefan Roeseff768cb2007-10-31 18:01:24 +01001329#ifdef CONFIG_4xx_DCACHE
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001330 flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001331 if (!last_used_ea)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001332#if defined(CONFIG_SYS_MEM_TOP_HIDE)
1333 bd_uncached = bis->bi_memsize + CONFIG_SYS_MEM_TOP_HIDE;
Anatolij Gustschin5e3dca52008-04-17 18:18:00 +02001334#else
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001335 bd_uncached = bis->bi_memsize;
Anatolij Gustschin5e3dca52008-04-17 18:18:00 +02001336#endif
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001337 else
1338 bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
1339
1340 last_used_ea = bd_uncached;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001341 program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
1342 TLB_WORD2_I_ENABLE);
1343#else
1344 bd_uncached = bd_cached;
1345#endif
1346 hw_p->tx_phys = bd_cached;
1347 hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
1348 hw_p->tx = (mal_desc_t *)(bd_uncached);
1349 hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
1350 debug("hw_p->tx=%08x, hw_p->rx=%08x\n", hw_p->tx, hw_p->rx);
wdenkba56f622004-02-06 23:19:44 +00001351 }
1352
1353 for (i = 0; i < NUM_TX_BUFF; i++) {
1354 hw_p->tx[i].ctrl = 0;
1355 hw_p->tx[i].data_len = 0;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001356 if (hw_p->first_init == 0)
1357 hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
1358 L1_CACHE_BYTES);
wdenkba56f622004-02-06 23:19:44 +00001359 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
1360 if ((NUM_TX_BUFF - 1) == i)
1361 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
1362 hw_p->tx_run[i] = -1;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001363 debug("TX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->tx[i].data_ptr);
wdenkba56f622004-02-06 23:19:44 +00001364 }
1365
1366 for (i = 0; i < NUM_RX_BUFF; i++) {
1367 hw_p->rx[i].ctrl = 0;
1368 hw_p->rx[i].data_len = 0;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001369 hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
wdenkba56f622004-02-06 23:19:44 +00001370 if ((NUM_RX_BUFF - 1) == i)
1371 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
1372 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
1373 hw_p->rx_ready[i] = -1;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001374 debug("RX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->rx[i].data_ptr);
wdenkba56f622004-02-06 23:19:44 +00001375 }
1376
1377 reg = 0x00000000;
1378
1379 reg |= dev->enetaddr[0]; /* set high address */
1380 reg = reg << 8;
1381 reg |= dev->enetaddr[1];
1382
Stefan Roese2d834762007-10-23 14:03:17 +02001383 out_be32((void *)EMAC_IAH + hw_p->hw_addr, reg);
wdenkba56f622004-02-06 23:19:44 +00001384
1385 reg = 0x00000000;
1386 reg |= dev->enetaddr[2]; /* set low address */
1387 reg = reg << 8;
1388 reg |= dev->enetaddr[3];
1389 reg = reg << 8;
1390 reg |= dev->enetaddr[4];
1391 reg = reg << 8;
1392 reg |= dev->enetaddr[5];
1393
Stefan Roese2d834762007-10-23 14:03:17 +02001394 out_be32((void *)EMAC_IAL + hw_p->hw_addr, reg);
wdenkba56f622004-02-06 23:19:44 +00001395
1396 switch (devnum) {
1397 case 1:
1398 /* setup MAL tx & rx channel pointers */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001399#if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
Stefan Roeseff768cb2007-10-31 18:01:24 +01001400 mtdcr (maltxctp2r, hw_p->tx_phys);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001401#else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001402 mtdcr (maltxctp1r, hw_p->tx_phys);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001403#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001404#if defined(CONFIG_440)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001405 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001406 mtdcr (malrxbattr, 0x0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001407#endif
Stefan Roese8ac41e32008-03-11 15:05:26 +01001408
1409#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roese4c9e8552008-03-19 16:20:49 +01001410 mtdcr (malrxctp8r, hw_p->rx_phys);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001411 /* set RX buffer size */
1412 mtdcr (malrcbs8, ENET_MAX_MTU_ALIGNED / 16);
1413#else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001414 mtdcr (malrxctp1r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001415 /* set RX buffer size */
1416 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001417#endif
wdenkba56f622004-02-06 23:19:44 +00001418 break;
Stefan Roese846b0dd2005-08-08 12:42:22 +02001419#if defined (CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001420 case 2:
1421 /* setup MAL tx & rx channel pointers */
1422 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001423 mtdcr (malrxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001424 mtdcr (maltxctp2r, hw_p->tx_phys);
1425 mtdcr (malrxctp2r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001426 /* set RX buffer size */
1427 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
1428 break;
1429 case 3:
1430 /* setup MAL tx & rx channel pointers */
1431 mtdcr (maltxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001432 mtdcr (maltxctp3r, hw_p->tx_phys);
wdenkba56f622004-02-06 23:19:44 +00001433 mtdcr (malrxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001434 mtdcr (malrxctp3r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001435 /* set RX buffer size */
1436 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
1437 break;
Stefan Roesec57c7982005-08-11 17:56:56 +02001438#endif /* CONFIG_440GX */
Stefan Roese4c9e8552008-03-19 16:20:49 +01001439#if defined (CONFIG_460GT)
1440 case 2:
1441 /* setup MAL tx & rx channel pointers */
1442 mtdcr (maltxbattr, 0x0);
1443 mtdcr (malrxbattr, 0x0);
1444 mtdcr (maltxctp2r, hw_p->tx_phys);
1445 mtdcr (malrxctp16r, hw_p->rx_phys);
1446 /* set RX buffer size */
1447 mtdcr (malrcbs16, ENET_MAX_MTU_ALIGNED / 16);
1448 break;
1449 case 3:
1450 /* setup MAL tx & rx channel pointers */
1451 mtdcr (maltxbattr, 0x0);
1452 mtdcr (malrxbattr, 0x0);
1453 mtdcr (maltxctp3r, hw_p->tx_phys);
1454 mtdcr (malrxctp24r, hw_p->rx_phys);
1455 /* set RX buffer size */
1456 mtdcr (malrcbs24, ENET_MAX_MTU_ALIGNED / 16);
1457 break;
1458#endif /* CONFIG_460GT */
wdenkba56f622004-02-06 23:19:44 +00001459 case 0:
1460 default:
1461 /* setup MAL tx & rx channel pointers */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001462#if defined(CONFIG_440)
wdenkba56f622004-02-06 23:19:44 +00001463 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001464 mtdcr (malrxbattr, 0x0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001465#endif
Stefan Roeseff768cb2007-10-31 18:01:24 +01001466 mtdcr (maltxctp0r, hw_p->tx_phys);
1467 mtdcr (malrxctp0r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001468 /* set RX buffer size */
1469 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
1470 break;
1471 }
1472
1473 /* Enable MAL transmit and receive channels */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001474#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001475 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
1476#else
wdenkba56f622004-02-06 23:19:44 +00001477 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
Stefan Roesec157d8e2005-08-01 16:41:48 +02001478#endif
wdenkba56f622004-02-06 23:19:44 +00001479 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
1480
1481 /* set transmit enable & receive enable */
Stefan Roese2d834762007-10-23 14:03:17 +02001482 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
wdenkba56f622004-02-06 23:19:44 +00001483
Stefan Roese2d834762007-10-23 14:03:17 +02001484 mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr);
Stefan Roese76957cb2008-03-01 12:11:40 +01001485
1486 /* set rx-/tx-fifo size */
1487 mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
wdenkba56f622004-02-06 23:19:44 +00001488
1489 /* set speed */
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001490 if (speed == _1000BASET) {
Stefan Roese738815c2007-10-02 11:44:46 +02001491#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1492 defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001493 unsigned long pfc1;
Stefan Roese887e2ec2006-09-07 11:51:23 +02001494
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001495 mfsdr (sdr_pfc1, pfc1);
1496 pfc1 |= SDR0_PFC1_EM_1000;
1497 mtsdr (sdr_pfc1, pfc1);
1498#endif
wdenk855a4962004-03-14 18:23:55 +00001499 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001500 } else if (speed == _100BASET)
wdenkba56f622004-02-06 23:19:44 +00001501 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
1502 else
1503 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
1504 if (duplex == FULL)
1505 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
1506
Stefan Roese2d834762007-10-23 14:03:17 +02001507 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
wdenkba56f622004-02-06 23:19:44 +00001508
1509 /* Enable broadcast and indvidual address */
1510 /* TBS: enabling runts as some misbehaved nics will send runts */
Stefan Roese2d834762007-10-23 14:03:17 +02001511 out_be32((void *)EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
wdenkba56f622004-02-06 23:19:44 +00001512
1513 /* we probably need to set the tx mode1 reg? maybe at tx time */
1514
1515 /* set transmit request threshold register */
Stefan Roese2d834762007-10-23 14:03:17 +02001516 out_be32((void *)EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
wdenkba56f622004-02-06 23:19:44 +00001517
Wolfgang Denk265817c2005-09-25 00:53:22 +02001518 /* set receive low/high water mark register */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001519#if defined(CONFIG_440)
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001520 /* 440s has a 64 byte burst length */
Stefan Roese2d834762007-10-23 14:03:17 +02001521 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001522#else
1523 /* 405s have a 16 byte burst length */
Stefan Roese2d834762007-10-23 14:03:17 +02001524 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001525#endif /* defined(CONFIG_440) */
Stefan Roese2d834762007-10-23 14:03:17 +02001526 out_be32((void *)EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
wdenkba56f622004-02-06 23:19:44 +00001527
1528 /* Set fifo limit entry in tx mode 0 */
Stefan Roese2d834762007-10-23 14:03:17 +02001529 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
wdenkba56f622004-02-06 23:19:44 +00001530 /* Frame gap set */
Stefan Roese2d834762007-10-23 14:03:17 +02001531 out_be32((void *)EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
wdenkba56f622004-02-06 23:19:44 +00001532
1533 /* Set EMAC IER */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001534 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
wdenkba56f622004-02-06 23:19:44 +00001535 if (speed == _100BASET)
1536 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1537
Stefan Roese2d834762007-10-23 14:03:17 +02001538 out_be32((void *)EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
1539 out_be32((void *)EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
wdenkba56f622004-02-06 23:19:44 +00001540
1541 if (hw_p->first_init == 0) {
1542 /*
1543 * Connect interrupt service routines
1544 */
Stefan Roesedbbd1252007-10-05 17:10:59 +02001545 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1546 (interrupt_handler_t *) enetInt, dev);
wdenkba56f622004-02-06 23:19:44 +00001547 }
wdenkba56f622004-02-06 23:19:44 +00001548
1549 mtmsr (msr); /* enable interrupts again */
1550
1551 hw_p->bis = bis;
1552 hw_p->first_init = 1;
1553
Stefan Roese802b7692008-01-08 18:39:30 +01001554 return 0;
wdenkba56f622004-02-06 23:19:44 +00001555}
1556
1557
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001558static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
wdenkba56f622004-02-06 23:19:44 +00001559 int len)
1560{
1561 struct enet_frame *ef_ptr;
1562 ulong time_start, time_now;
1563 unsigned long temp_txm0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001564 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001565
1566 ef_ptr = (struct enet_frame *) ptr;
1567
1568 /*-----------------------------------------------------------------------+
1569 * Copy in our address into the frame.
1570 *-----------------------------------------------------------------------*/
1571 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1572
1573 /*-----------------------------------------------------------------------+
1574 * If frame is too long or too short, modify length.
1575 *-----------------------------------------------------------------------*/
1576 /* TBS: where does the fragment go???? */
1577 if (len > ENET_MAX_MTU)
1578 len = ENET_MAX_MTU;
1579
1580 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1581 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001582 flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
wdenkba56f622004-02-06 23:19:44 +00001583
1584 /*-----------------------------------------------------------------------+
1585 * set TX Buffer busy, and send it
1586 *-----------------------------------------------------------------------*/
1587 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1588 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1589 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1590 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1591 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1592
1593 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1594 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1595
Stefan Roese8ac41e32008-03-11 15:05:26 +01001596 sync();
wdenkba56f622004-02-06 23:19:44 +00001597
Stefan Roese2d834762007-10-23 14:03:17 +02001598 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr,
1599 in_be32((void *)EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001600#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001601 hw_p->stats.pkts_tx++;
1602#endif
1603
1604 /*-----------------------------------------------------------------------+
1605 * poll unitl the packet is sent and then make sure it is OK
1606 *-----------------------------------------------------------------------*/
1607 time_start = get_timer (0);
1608 while (1) {
Stefan Roese2d834762007-10-23 14:03:17 +02001609 temp_txm0 = in_be32((void *)EMAC_TXM0 + hw_p->hw_addr);
wdenkba56f622004-02-06 23:19:44 +00001610 /* loop until either TINT turns on or 3 seconds elapse */
1611 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
1612 /* transmit is done, so now check for errors
1613 * If there is an error, an interrupt should
1614 * happen when we return
1615 */
1616 time_now = get_timer (0);
1617 if ((time_now - time_start) > 3000) {
1618 return (-1);
1619 }
1620 } else {
1621 return (len);
1622 }
1623 }
1624}
1625
wdenkba56f622004-02-06 23:19:44 +00001626int enetInt (struct eth_device *dev)
1627{
1628 int serviced;
1629 int rc = -1; /* default to not us */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001630 u32 mal_isr;
1631 u32 emac_isr = 0;
1632 u32 mal_eob;
1633 u32 uic_mal;
1634 u32 uic_mal_err;
1635 u32 uic_emac;
1636 u32 uic_emac_b;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001637 EMAC_4XX_HW_PST hw_p;
wdenkba56f622004-02-06 23:19:44 +00001638
1639 /*
1640 * Because the mal is generic, we need to get the current
1641 * eth device
1642 */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001643 dev = eth_get_dev();
wdenkba56f622004-02-06 23:19:44 +00001644
1645 hw_p = dev->priv;
1646
wdenkba56f622004-02-06 23:19:44 +00001647 /* enter loop that stays in interrupt code until nothing to service */
1648 do {
1649 serviced = 0;
1650
Stefan Roesed1631fe2008-06-26 13:40:57 +02001651 uic_mal = mfdcr(UIC_BASE_MAL + UIC_MSR);
1652 uic_mal_err = mfdcr(UIC_BASE_MAL_ERR + UIC_MSR);
1653 uic_emac = mfdcr(UIC_BASE_EMAC + UIC_MSR);
1654 uic_emac_b = mfdcr(UIC_BASE_EMAC_B + UIC_MSR);
Stefan Roese887e2ec2006-09-07 11:51:23 +02001655
Stefan Roesed1631fe2008-06-26 13:40:57 +02001656 if (!(uic_mal & (UIC_MAL_RXEOB | UIC_MAL_TXEOB))
1657 && !(uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE))
1658 && !(uic_emac & UIC_ETHx) && !(uic_emac_b & UIC_ETHxB)) {
wdenkba56f622004-02-06 23:19:44 +00001659 /* not for us */
1660 return (rc);
1661 }
Stefan Roesed1631fe2008-06-26 13:40:57 +02001662
wdenkba56f622004-02-06 23:19:44 +00001663 /* get and clear controller status interrupts */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001664 /* look at MAL and EMAC error interrupts */
1665 if (uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) {
1666 /* we have a MAL error interrupt */
1667 mal_isr = mfdcr(malesr);
1668 mal_err(dev, mal_isr, uic_mal_err,
1669 MAL_UIC_DEF, MAL_UIC_ERR);
1670
1671 /* clear MAL error interrupt status bits */
1672 mtdcr(UIC_BASE_MAL_ERR + UIC_SR,
1673 UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE);
1674
1675 return -1;
wdenkba56f622004-02-06 23:19:44 +00001676 }
1677
Stefan Roesed1631fe2008-06-26 13:40:57 +02001678 /* look for EMAC errors */
1679 if ((uic_emac & UIC_ETHx) || (uic_emac_b & UIC_ETHxB)) {
1680 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
1681 emac_err(dev, emac_isr);
wdenkba56f622004-02-06 23:19:44 +00001682
Stefan Roesed1631fe2008-06-26 13:40:57 +02001683 /* clear EMAC error interrupt status bits */
1684 mtdcr(UIC_BASE_EMAC + UIC_SR, UIC_ETHx);
1685 mtdcr(UIC_BASE_EMAC_B + UIC_SR, UIC_ETHxB);
wdenkba56f622004-02-06 23:19:44 +00001686
Stefan Roesed1631fe2008-06-26 13:40:57 +02001687 return -1;
wdenkba56f622004-02-06 23:19:44 +00001688 }
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001689
wdenkba56f622004-02-06 23:19:44 +00001690 /* handle MAX TX EOB interrupt from a tx */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001691 if (uic_mal & UIC_MAL_TXEOB) {
1692 /* clear MAL interrupt status bits */
1693 mal_eob = mfdcr(maltxeobisr);
1694 mtdcr(maltxeobisr, mal_eob);
1695 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_TXEOB);
1696
1697 /* indicate that we serviced an interrupt */
1698 serviced = 1;
1699 rc = 0;
wdenkba56f622004-02-06 23:19:44 +00001700 }
Stefan Roesed1631fe2008-06-26 13:40:57 +02001701
1702 /* handle MAL RX EOB interupt from a receive */
1703 /* check for EOB on valid channels */
1704 if (uic_mal & UIC_MAL_RXEOB) {
1705 mal_eob = mfdcr(malrxeobisr);
1706 if (mal_eob &
1707 (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL))) {
1708 /* push packet to upper layer */
1709 enet_rcv(dev, emac_isr);
1710
1711 /* clear MAL interrupt status bits */
1712 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_RXEOB);
1713
wdenkba56f622004-02-06 23:19:44 +00001714 /* indicate that we serviced an interrupt */
1715 serviced = 1;
1716 rc = 0;
1717 }
1718 }
wdenkba56f622004-02-06 23:19:44 +00001719 } while (serviced);
1720
1721 return (rc);
1722}
1723
1724/*-----------------------------------------------------------------------------+
1725 * MAL Error Routine
1726 *-----------------------------------------------------------------------------*/
1727static void mal_err (struct eth_device *dev, unsigned long isr,
1728 unsigned long uic, unsigned long maldef,
1729 unsigned long mal_errr)
1730{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001731 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001732
1733 mtdcr (malesr, isr); /* clear interrupt */
1734
1735 /* clear DE interrupt */
1736 mtdcr (maltxdeir, 0xC0000000);
1737 mtdcr (malrxdeir, 0x80000000);
1738
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001739#ifdef INFO_4XX_ENET
Wolfgang Denk265817c2005-09-25 00:53:22 +02001740 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
wdenkba56f622004-02-06 23:19:44 +00001741#endif
1742
1743 eth_init (hw_p->bis); /* start again... */
1744}
1745
1746/*-----------------------------------------------------------------------------+
1747 * EMAC Error Routine
1748 *-----------------------------------------------------------------------------*/
1749static void emac_err (struct eth_device *dev, unsigned long isr)
1750{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001751 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001752
1753 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
Stefan Roese2d834762007-10-23 14:03:17 +02001754 out_be32((void *)EMAC_ISR + hw_p->hw_addr, isr);
wdenkba56f622004-02-06 23:19:44 +00001755}
1756
1757/*-----------------------------------------------------------------------------+
1758 * enet_rcv() handles the ethernet receive data
1759 *-----------------------------------------------------------------------------*/
1760static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1761{
1762 struct enet_frame *ef_ptr;
1763 unsigned long data_len;
1764 unsigned long rx_eob_isr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001765 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001766
1767 int handled = 0;
1768 int i;
1769 int loop_count = 0;
1770
1771 rx_eob_isr = mfdcr (malrxeobisr);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001772 if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
wdenkba56f622004-02-06 23:19:44 +00001773 /* clear EOB */
1774 mtdcr (malrxeobisr, rx_eob_isr);
1775
1776 /* EMAC RX done */
1777 while (1) { /* do all */
1778 i = hw_p->rx_slot;
1779
1780 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1781 || (loop_count >= NUM_RX_BUFF))
1782 break;
Stefan Roesea2e1c702007-07-12 16:32:08 +02001783
wdenkba56f622004-02-06 23:19:44 +00001784 loop_count++;
wdenkba56f622004-02-06 23:19:44 +00001785 handled++;
Stefan Roese8ac41e32008-03-11 15:05:26 +01001786 data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */
wdenkba56f622004-02-06 23:19:44 +00001787 if (data_len) {
1788 if (data_len > ENET_MAX_MTU) /* Check len */
1789 data_len = 0;
1790 else {
1791 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1792 data_len = 0;
1793 hw_p->stats.rx_err_log[hw_p->
1794 rx_err_index]
1795 = hw_p->rx[i].ctrl;
1796 hw_p->rx_err_index++;
1797 if (hw_p->rx_err_index ==
1798 MAX_ERR_LOG)
1799 hw_p->rx_err_index =
1800 0;
wdenkfc1cfcd2004-04-25 15:41:35 +00001801 } /* emac_erros */
wdenkba56f622004-02-06 23:19:44 +00001802 } /* data_len < max mtu */
wdenkfc1cfcd2004-04-25 15:41:35 +00001803 } /* if data_len */
wdenkba56f622004-02-06 23:19:44 +00001804 if (!data_len) { /* no data */
1805 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1806
1807 hw_p->stats.data_len_err++; /* Error at Rx */
1808 }
1809
1810 /* !data_len */
1811 /* AS.HARNOIS */
1812 /* Check if user has already eaten buffer */
1813 /* if not => ERROR */
1814 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1815 if (hw_p->is_receiving)
1816 printf ("ERROR : Receive buffers are full!\n");
1817 break;
1818 } else {
1819 hw_p->stats.rx_frames++;
1820 hw_p->stats.rx += data_len;
1821 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1822 data_ptr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001823#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001824 hw_p->stats.pkts_rx++;
1825#endif
1826 /* AS.HARNOIS
1827 * use ring buffer
1828 */
1829 hw_p->rx_ready[hw_p->rx_i_index] = i;
1830 hw_p->rx_i_index++;
1831 if (NUM_RX_BUFF == hw_p->rx_i_index)
1832 hw_p->rx_i_index = 0;
1833
Stefan Roesea2e1c702007-07-12 16:32:08 +02001834 hw_p->rx_slot++;
1835 if (NUM_RX_BUFF == hw_p->rx_slot)
1836 hw_p->rx_slot = 0;
1837
wdenkba56f622004-02-06 23:19:44 +00001838 /* AS.HARNOIS
1839 * free receive buffer only when
1840 * buffer has been handled (eth_rx)
1841 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1842 */
1843 } /* if data_len */
1844 } /* while */
1845 } /* if EMACK_RXCHL */
1846}
1847
1848
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001849static int ppc_4xx_eth_rx (struct eth_device *dev)
wdenkba56f622004-02-06 23:19:44 +00001850{
1851 int length;
1852 int user_index;
1853 unsigned long msr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001854 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001855
Wolfgang Denk265817c2005-09-25 00:53:22 +02001856 hw_p->is_receiving = 1; /* tell driver */
wdenkba56f622004-02-06 23:19:44 +00001857
1858 for (;;) {
1859 /* AS.HARNOIS
1860 * use ring buffer and
1861 * get index from rx buffer desciptor queue
1862 */
1863 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1864 if (user_index == -1) {
1865 length = -1;
1866 break; /* nothing received - leave for() loop */
1867 }
1868
1869 msr = mfmsr ();
1870 mtmsr (msr & ~(MSR_EE));
1871
Stefan Roese8ac41e32008-03-11 15:05:26 +01001872 length = hw_p->rx[user_index].data_len & 0x0fff;
wdenkba56f622004-02-06 23:19:44 +00001873
1874 /* Pass the packet up to the protocol layers. */
Wolfgang Denk265817c2005-09-25 00:53:22 +02001875 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1876 /* NetReceive(NetRxPackets[i], length); */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001877 invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
1878 (u32)hw_p->rx[user_index].data_ptr +
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001879 length - 4);
wdenkba56f622004-02-06 23:19:44 +00001880 NetReceive (NetRxPackets[user_index], length - 4);
1881 /* Free Recv Buffer */
1882 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1883 /* Free rx buffer descriptor queue */
1884 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1885 hw_p->rx_u_index++;
1886 if (NUM_RX_BUFF == hw_p->rx_u_index)
1887 hw_p->rx_u_index = 0;
1888
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001889#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001890 hw_p->stats.pkts_handled++;
1891#endif
1892
1893 mtmsr (msr); /* Enable IRQ's */
1894 }
1895
Wolfgang Denk265817c2005-09-25 00:53:22 +02001896 hw_p->is_receiving = 0; /* tell driver */
wdenkba56f622004-02-06 23:19:44 +00001897
1898 return length;
1899}
1900
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001901int ppc_4xx_eth_initialize (bd_t * bis)
wdenkba56f622004-02-06 23:19:44 +00001902{
1903 static int virgin = 0;
wdenkba56f622004-02-06 23:19:44 +00001904 struct eth_device *dev;
1905 int eth_num = 0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001906 EMAC_4XX_HW_PST hw = NULL;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001907 u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1908 u32 hw_addr[4];
Stefan Roesed1631fe2008-06-26 13:40:57 +02001909 u32 mal_ier;
wdenkba56f622004-02-06 23:19:44 +00001910
Stefan Roese846b0dd2005-08-08 12:42:22 +02001911#if defined(CONFIG_440GX)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001912 unsigned long pfc1;
1913
wdenkba56f622004-02-06 23:19:44 +00001914 mfsdr (sdr_pfc1, pfc1);
1915 pfc1 &= ~(0x01e00000);
1916 pfc1 |= 0x01200000;
1917 mtsdr (sdr_pfc1, pfc1);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001918#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001919
1920 /* first clear all mac-addresses */
1921 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1922 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
1923
1924 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
Mike Frysingerd3f87142009-02-11 19:01:26 -05001925 int ethaddr_idx = eth_num + CONFIG_EMAC_NR_START;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001926 switch (eth_num) {
1927 default: /* fall through */
1928 case 0:
Mike Frysingerd3f87142009-02-11 19:01:26 -05001929 eth_getenv_enetaddr("ethaddr", ethaddr[ethaddr_idx]);
Stefan Roese5fb692c2007-01-18 10:25:34 +01001930 hw_addr[eth_num] = 0x0;
1931 break;
1932#ifdef CONFIG_HAS_ETH1
1933 case 1:
Mike Frysingerd3f87142009-02-11 19:01:26 -05001934 eth_getenv_enetaddr("eth1addr", ethaddr[ethaddr_idx]);
Stefan Roese5fb692c2007-01-18 10:25:34 +01001935 hw_addr[eth_num] = 0x100;
1936 break;
1937#endif
1938#ifdef CONFIG_HAS_ETH2
1939 case 2:
Mike Frysingerd3f87142009-02-11 19:01:26 -05001940 eth_getenv_enetaddr("eth2addr", ethaddr[ethaddr_idx]);
Stefan Roese4c9e8552008-03-19 16:20:49 +01001941#if defined(CONFIG_460GT)
1942 hw_addr[eth_num] = 0x300;
1943#else
Stefan Roese5fb692c2007-01-18 10:25:34 +01001944 hw_addr[eth_num] = 0x400;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001945#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001946 break;
1947#endif
1948#ifdef CONFIG_HAS_ETH3
1949 case 3:
Mike Frysingerd3f87142009-02-11 19:01:26 -05001950 eth_getenv_enetaddr("eth3addr", ethaddr[ethaddr_idx]);
Stefan Roese4c9e8552008-03-19 16:20:49 +01001951#if defined(CONFIG_460GT)
1952 hw_addr[eth_num] = 0x400;
1953#else
Stefan Roese5fb692c2007-01-18 10:25:34 +01001954 hw_addr[eth_num] = 0x600;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001955#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001956 break;
1957#endif
1958 }
1959 }
1960
wdenk3c74e322004-02-22 23:46:08 +00001961 /* set phy num and mode */
1962 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001963 bis->bi_phymode[0] = 0;
1964
Stefan Roesec157d8e2005-08-01 16:41:48 +02001965#if defined(CONFIG_PHY1_ADDR)
wdenk3c74e322004-02-22 23:46:08 +00001966 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001967 bis->bi_phymode[1] = 0;
Stefan Roesec157d8e2005-08-01 16:41:48 +02001968#endif
Stefan Roese846b0dd2005-08-08 12:42:22 +02001969#if defined(CONFIG_440GX)
wdenk3c74e322004-02-22 23:46:08 +00001970 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1971 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
wdenk3c74e322004-02-22 23:46:08 +00001972 bis->bi_phymode[2] = 2;
1973 bis->bi_phymode[3] = 2;
Stefan Roesedbbd1252007-10-05 17:10:59 +02001974#endif
wdenkba56f622004-02-06 23:19:44 +00001975
Stefan Roesedbbd1252007-10-05 17:10:59 +02001976#if defined(CONFIG_440GX) || \
1977 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1978 defined(CONFIG_405EX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001979 ppc_4xx_eth_setup_bridge(0, bis);
wdenka06752e2004-09-29 22:43:59 +00001980#endif
1981
Stefan Roese1e25f952005-10-20 16:34:28 +02001982 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
Stefan Roese5fb692c2007-01-18 10:25:34 +01001983 /*
1984 * See if we can actually bring up the interface,
1985 * otherwise, skip it
1986 */
1987 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
1988 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1989 continue;
wdenkba56f622004-02-06 23:19:44 +00001990 }
1991
1992 /* Allocate device structure */
1993 dev = (struct eth_device *) malloc (sizeof (*dev));
1994 if (dev == NULL) {
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001995 printf ("ppc_4xx_eth_initialize: "
wdenk3f85ce22004-02-23 16:11:30 +00001996 "Cannot allocate eth_device %d\n", eth_num);
wdenkba56f622004-02-06 23:19:44 +00001997 return (-1);
1998 }
wdenkb2532ef2005-06-20 10:17:34 +00001999 memset(dev, 0, sizeof(*dev));
wdenkba56f622004-02-06 23:19:44 +00002000
2001 /* Allocate our private use data */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002002 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
wdenkba56f622004-02-06 23:19:44 +00002003 if (hw == NULL) {
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002004 printf ("ppc_4xx_eth_initialize: "
wdenk3f85ce22004-02-23 16:11:30 +00002005 "Cannot allocate private hw data for eth_device %d",
wdenkba56f622004-02-06 23:19:44 +00002006 eth_num);
2007 free (dev);
2008 return (-1);
2009 }
wdenkb2532ef2005-06-20 10:17:34 +00002010 memset(hw, 0, sizeof(*hw));
wdenkba56f622004-02-06 23:19:44 +00002011
Stefan Roese5fb692c2007-01-18 10:25:34 +01002012 hw->hw_addr = hw_addr[eth_num];
2013 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
wdenkba56f622004-02-06 23:19:44 +00002014 hw->devnum = eth_num;
Stefan Roesec157d8e2005-08-01 16:41:48 +02002015 hw->print_speed = 1;
wdenkba56f622004-02-06 23:19:44 +00002016
Stefan Roese5fb692c2007-01-18 10:25:34 +01002017 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
wdenkba56f622004-02-06 23:19:44 +00002018 dev->priv = (void *) hw;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002019 dev->init = ppc_4xx_eth_init;
2020 dev->halt = ppc_4xx_eth_halt;
2021 dev->send = ppc_4xx_eth_send;
2022 dev->recv = ppc_4xx_eth_rx;
wdenkba56f622004-02-06 23:19:44 +00002023
2024 if (0 == virgin) {
2025 /* set the MAL IER ??? names may change with new spec ??? */
Stefan Roesedbbd1252007-10-05 17:10:59 +02002026#if defined(CONFIG_440SPE) || \
2027 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01002028 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02002029 defined(CONFIG_405EX)
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002030 mal_ier =
2031 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
2032 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
2033#else
wdenkba56f622004-02-06 23:19:44 +00002034 mal_ier =
2035 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
2036 MAL_IER_OPBE | MAL_IER_PLBE;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002037#endif
wdenkba56f622004-02-06 23:19:44 +00002038 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
2039 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
2040 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
2041 mtdcr (malier, mal_ier);
2042
2043 /* install MAL interrupt handler */
Stefan Roesed1631fe2008-06-26 13:40:57 +02002044 irq_install_handler (VECNUM_MAL_SERR,
wdenkba56f622004-02-06 23:19:44 +00002045 (interrupt_handler_t *) enetInt,
2046 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002047 irq_install_handler (VECNUM_MAL_TXEOB,
wdenkba56f622004-02-06 23:19:44 +00002048 (interrupt_handler_t *) enetInt,
2049 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002050 irq_install_handler (VECNUM_MAL_RXEOB,
wdenkba56f622004-02-06 23:19:44 +00002051 (interrupt_handler_t *) enetInt,
2052 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002053 irq_install_handler (VECNUM_MAL_TXDE,
wdenkba56f622004-02-06 23:19:44 +00002054 (interrupt_handler_t *) enetInt,
2055 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002056 irq_install_handler (VECNUM_MAL_RXDE,
wdenkba56f622004-02-06 23:19:44 +00002057 (interrupt_handler_t *) enetInt,
2058 dev);
2059 virgin = 1;
2060 }
2061
2062 eth_register (dev);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002063
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -05002064#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002065 miiphy_register (dev->name,
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01002066 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002067#endif
wdenkba56f622004-02-06 23:19:44 +00002068 } /* end for each supported device */
Stefan Roese802b7692008-01-08 18:39:30 +01002069
2070 return 0;
wdenkba56f622004-02-06 23:19:44 +00002071}