blob: c0200481c62cdd2fac1bf197663a1a68fd8aa848 [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;
Alessio Centazzo0544c632009-07-11 11:56:06 -0700873#if defined(CONFIG_440GX) || \
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 Roese8ac41e32008-03-11 15:05:26 +01001122 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001123 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +02001124
wdenk0e6d7982004-03-14 00:07:33 +00001125#if defined(CONFIG_CIS8201_PHY)
wdenkfc1cfcd2004-04-25 15:41:35 +00001126 /*
Stefan Roese17f50f222005-08-04 17:09:16 +02001127 * Cicada 8201 PHY needs to have an extended register whacked
1128 * for RGMII mode.
wdenkfc1cfcd2004-04-25 15:41:35 +00001129 */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001130 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
Stefan Roeseb79316f2005-08-15 12:31:23 +02001131#if defined(CONFIG_CIS8201_SHORT_ETCH)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001132 miiphy_write (dev->name, reg, 23, 0x1300);
Stefan Roeseb79316f2005-08-15 12:31:23 +02001133#else
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001134 miiphy_write (dev->name, reg, 23, 0x1000);
Stefan Roeseb79316f2005-08-15 12:31:23 +02001135#endif
Stefan Roese17f50f222005-08-04 17:09:16 +02001136 /*
1137 * Vitesse VSC8201/Cicada CIS8201 errata:
1138 * Interoperability problem with Intel 82547EI phys
1139 * This work around (provided by Vitesse) changes
1140 * the default timer convergence from 8ms to 12ms
1141 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001142 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1143 miiphy_write (dev->name, reg, 0x08, 0x0200);
1144 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
1145 miiphy_write (dev->name, reg, 0x02, 0x0004);
1146 miiphy_write (dev->name, reg, 0x01, 0x0671);
1147 miiphy_write (dev->name, reg, 0x00, 0x8fae);
1148 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1149 miiphy_write (dev->name, reg, 0x08, 0x0000);
1150 miiphy_write (dev->name, reg, 0x1f, 0x0000);
Stefan Roese17f50f222005-08-04 17:09:16 +02001151 /* end Vitesse/Cicada errata */
1152 }
Stefan Roese6ca86462008-09-05 14:11:40 +02001153#endif /* defined(CONFIG_CIS8201_PHY) */
Stefan Roese5fb692c2007-01-18 10:25:34 +01001154
1155#if defined(CONFIG_ET1011C_PHY)
1156 /*
1157 * Agere ET1011c PHY needs to have an extended register whacked
1158 * for RGMII mode.
1159 */
1160 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
1161 miiphy_read (dev->name, reg, 0x16, &reg_short);
1162 reg_short &= ~(0x7);
1163 reg_short |= 0x6; /* RGMII DLL Delay*/
1164 miiphy_write (dev->name, reg, 0x16, reg_short);
1165
1166 miiphy_read (dev->name, reg, 0x17, &reg_short);
1167 reg_short &= ~(0x40);
1168 miiphy_write (dev->name, reg, 0x17, reg_short);
1169
1170 miiphy_write(dev->name, reg, 0x1c, 0x74f0);
1171 }
Stefan Roese6ca86462008-09-05 14:11:40 +02001172#endif /* defined(CONFIG_ET1011C_PHY) */
Stefan Roese5fb692c2007-01-18 10:25:34 +01001173
Stefan Roese6ca86462008-09-05 14:11:40 +02001174#endif /* defined(CONFIG_440GX) ... */
wdenka06752e2004-09-29 22:43:59 +00001175 /* Start/Restart autonegotiation */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001176 phy_setup_aneg (dev->name, reg);
wdenka06752e2004-09-29 22:43:59 +00001177 udelay (1000);
1178 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001179#endif /* defined(CONFIG_PHY_RESET) */
wdenkba56f622004-02-06 23:19:44 +00001180
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001181 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenkba56f622004-02-06 23:19:44 +00001182
1183 /*
wdenk0e6d7982004-03-14 00:07:33 +00001184 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
wdenkba56f622004-02-06 23:19:44 +00001185 */
1186 if ((reg_short & PHY_BMSR_AUTN_ABLE)
1187 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
1188 puts ("Waiting for PHY auto negotiation to complete");
1189 i = 0;
1190 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
1191 /*
1192 * Timeout reached ?
1193 */
1194 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
1195 puts (" TIMEOUT !\n");
1196 break;
1197 }
1198
1199 if ((i++ % 1000) == 0) {
1200 putc ('.');
1201 }
1202 udelay (1000); /* 1 ms */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001203 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenkba56f622004-02-06 23:19:44 +00001204 }
1205 puts (" done\n");
1206 udelay (500000); /* another 500 ms (results in faster booting) */
1207 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001208
Victor Gallardo78d78232008-09-04 23:49:36 -07001209get_speed:
1210 if (reg == CONFIG_FIXED_PHY) {
1211 for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) {
1212 if (devnum == fixed_phy_port[i].devnum) {
1213 speed = fixed_phy_port[i].speed;
1214 duplex = fixed_phy_port[i].duplex;
1215 break;
1216 }
1217 }
1218
1219 if (i == ARRAY_SIZE(fixed_phy_port)) {
1220 printf("ERROR: PHY (%s) not configured correctly!\n",
1221 dev->name);
1222 return -1;
1223 }
1224 } else {
1225 speed = miiphy_speed(dev->name, reg);
1226 duplex = miiphy_duplex(dev->name, reg);
1227 }
wdenkba56f622004-02-06 23:19:44 +00001228
1229 if (hw_p->print_speed) {
1230 hw_p->print_speed = 0;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001231 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
1232 (int) speed, (duplex == HALF) ? "HALF" : "FULL",
1233 hw_p->devnum);
wdenkba56f622004-02-06 23:19:44 +00001234 }
1235
Stefan Roese8ac41e32008-03-11 15:05:26 +01001236#if defined(CONFIG_440) && \
1237 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
1238 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
1239 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
Stefan Roese846b0dd2005-08-08 12:42:22 +02001240#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001241 mfsdr(sdr_mfr, reg);
1242 if (speed == 100) {
1243 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
1244 } else {
1245 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
1246 }
1247 mtsdr(sdr_mfr, reg);
1248#endif
Stefan Roesec57c7982005-08-11 17:56:56 +02001249
wdenkba56f622004-02-06 23:19:44 +00001250 /* Set ZMII/RGMII speed according to the phy link speed */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001251 reg = in_be32((void *)ZMII_SSR);
wdenk855a4962004-03-14 18:23:55 +00001252 if ( (speed == 100) || (speed == 1000) )
Stefan Roeseff768cb2007-10-31 18:01:24 +01001253 out_be32((void *)ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
wdenkba56f622004-02-06 23:19:44 +00001254 else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001255 out_be32((void *)ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
wdenkba56f622004-02-06 23:19:44 +00001256
1257 if ((devnum == 2) || (devnum == 3)) {
1258 if (speed == 1000)
1259 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1260 else if (speed == 100)
1261 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001262 else if (speed == 10)
wdenkba56f622004-02-06 23:19:44 +00001263 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001264 else {
1265 printf("Error in RGMII Speed\n");
1266 return -1;
1267 }
Stefan Roeseff768cb2007-10-31 18:01:24 +01001268 out_be32((void *)RGMII_SSR, reg);
wdenkba56f622004-02-06 23:19:44 +00001269 }
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001270#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
wdenkba56f622004-02-06 23:19:44 +00001271
Stefan Roesedbbd1252007-10-05 17:10:59 +02001272#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001273 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001274 defined(CONFIG_405EX)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001275 if (devnum >= 2)
1276 rgmii_channel = devnum - 2;
1277 else
1278 rgmii_channel = devnum;
1279
Stefan Roese887e2ec2006-09-07 11:51:23 +02001280 if (speed == 1000)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001281 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001282 else if (speed == 100)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001283 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001284 else if (speed == 10)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001285 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001286 else {
1287 printf("Error in RGMII Speed\n");
1288 return -1;
1289 }
Stefan Roese2d834762007-10-23 14:03:17 +02001290 out_be32((void *)RGMII_SSR, reg);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001291#if defined(CONFIG_460GT)
1292 if ((devnum == 2) || (devnum == 3))
1293 out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
1294#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +02001295#endif
1296
wdenkba56f622004-02-06 23:19:44 +00001297 /* set the Mal configuration reg */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001298#if defined(CONFIG_440GX) || \
1299 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001300 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001301 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001302 defined(CONFIG_405EX)
Stefan Roese17f50f222005-08-04 17:09:16 +02001303 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
1304 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
1305#else
1306 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
wdenkba56f622004-02-06 23:19:44 +00001307 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
Stefan Roese17f50f222005-08-04 17:09:16 +02001308 if (get_pvr() == PVR_440GP_RB) {
1309 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
1310 }
1311#endif
wdenkba56f622004-02-06 23:19:44 +00001312
wdenkba56f622004-02-06 23:19:44 +00001313 /*
1314 * Malloc MAL buffer desciptors, make sure they are
1315 * aligned on cache line boundary size
1316 * (401/403/IOP480 = 16, 405 = 32)
1317 * and doesn't cross cache block boundaries.
1318 */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001319 if (hw_p->first_init == 0) {
1320 debug("*** Allocating descriptor memory ***\n");
wdenkba56f622004-02-06 23:19:44 +00001321
Stefan Roeseff768cb2007-10-31 18:01:24 +01001322 bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
1323 if (!bd_cached) {
Stefan Roeseb0021442008-07-10 09:58:06 +02001324 printf("%s: Error allocating MAL descriptor buffers!\n", __func__);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001325 return -1;
1326 }
Stefan Roeseb79316f2005-08-15 12:31:23 +02001327
Stefan Roeseff768cb2007-10-31 18:01:24 +01001328#ifdef CONFIG_4xx_DCACHE
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001329 flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001330 if (!last_used_ea)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001331#if defined(CONFIG_SYS_MEM_TOP_HIDE)
1332 bd_uncached = bis->bi_memsize + CONFIG_SYS_MEM_TOP_HIDE;
Anatolij Gustschin5e3dca52008-04-17 18:18:00 +02001333#else
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001334 bd_uncached = bis->bi_memsize;
Anatolij Gustschin5e3dca52008-04-17 18:18:00 +02001335#endif
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001336 else
1337 bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
1338
1339 last_used_ea = bd_uncached;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001340 program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
1341 TLB_WORD2_I_ENABLE);
1342#else
1343 bd_uncached = bd_cached;
1344#endif
1345 hw_p->tx_phys = bd_cached;
1346 hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
1347 hw_p->tx = (mal_desc_t *)(bd_uncached);
1348 hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
1349 debug("hw_p->tx=%08x, hw_p->rx=%08x\n", hw_p->tx, hw_p->rx);
wdenkba56f622004-02-06 23:19:44 +00001350 }
1351
1352 for (i = 0; i < NUM_TX_BUFF; i++) {
1353 hw_p->tx[i].ctrl = 0;
1354 hw_p->tx[i].data_len = 0;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001355 if (hw_p->first_init == 0)
1356 hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
1357 L1_CACHE_BYTES);
wdenkba56f622004-02-06 23:19:44 +00001358 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
1359 if ((NUM_TX_BUFF - 1) == i)
1360 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
1361 hw_p->tx_run[i] = -1;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001362 debug("TX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->tx[i].data_ptr);
wdenkba56f622004-02-06 23:19:44 +00001363 }
1364
1365 for (i = 0; i < NUM_RX_BUFF; i++) {
1366 hw_p->rx[i].ctrl = 0;
1367 hw_p->rx[i].data_len = 0;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001368 hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
wdenkba56f622004-02-06 23:19:44 +00001369 if ((NUM_RX_BUFF - 1) == i)
1370 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
1371 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
1372 hw_p->rx_ready[i] = -1;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001373 debug("RX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->rx[i].data_ptr);
wdenkba56f622004-02-06 23:19:44 +00001374 }
1375
1376 reg = 0x00000000;
1377
1378 reg |= dev->enetaddr[0]; /* set high address */
1379 reg = reg << 8;
1380 reg |= dev->enetaddr[1];
1381
Stefan Roese2d834762007-10-23 14:03:17 +02001382 out_be32((void *)EMAC_IAH + hw_p->hw_addr, reg);
wdenkba56f622004-02-06 23:19:44 +00001383
1384 reg = 0x00000000;
1385 reg |= dev->enetaddr[2]; /* set low address */
1386 reg = reg << 8;
1387 reg |= dev->enetaddr[3];
1388 reg = reg << 8;
1389 reg |= dev->enetaddr[4];
1390 reg = reg << 8;
1391 reg |= dev->enetaddr[5];
1392
Stefan Roese2d834762007-10-23 14:03:17 +02001393 out_be32((void *)EMAC_IAL + hw_p->hw_addr, reg);
wdenkba56f622004-02-06 23:19:44 +00001394
1395 switch (devnum) {
1396 case 1:
1397 /* setup MAL tx & rx channel pointers */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001398#if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
Stefan Roeseff768cb2007-10-31 18:01:24 +01001399 mtdcr (maltxctp2r, hw_p->tx_phys);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001400#else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001401 mtdcr (maltxctp1r, hw_p->tx_phys);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001402#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001403#if defined(CONFIG_440)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001404 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001405 mtdcr (malrxbattr, 0x0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001406#endif
Stefan Roese8ac41e32008-03-11 15:05:26 +01001407
1408#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roese4c9e8552008-03-19 16:20:49 +01001409 mtdcr (malrxctp8r, hw_p->rx_phys);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001410 /* set RX buffer size */
1411 mtdcr (malrcbs8, ENET_MAX_MTU_ALIGNED / 16);
1412#else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001413 mtdcr (malrxctp1r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001414 /* set RX buffer size */
1415 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001416#endif
wdenkba56f622004-02-06 23:19:44 +00001417 break;
Stefan Roese846b0dd2005-08-08 12:42:22 +02001418#if defined (CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001419 case 2:
1420 /* setup MAL tx & rx channel pointers */
1421 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001422 mtdcr (malrxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001423 mtdcr (maltxctp2r, hw_p->tx_phys);
1424 mtdcr (malrxctp2r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001425 /* set RX buffer size */
1426 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
1427 break;
1428 case 3:
1429 /* setup MAL tx & rx channel pointers */
1430 mtdcr (maltxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001431 mtdcr (maltxctp3r, hw_p->tx_phys);
wdenkba56f622004-02-06 23:19:44 +00001432 mtdcr (malrxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001433 mtdcr (malrxctp3r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001434 /* set RX buffer size */
1435 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
1436 break;
Stefan Roesec57c7982005-08-11 17:56:56 +02001437#endif /* CONFIG_440GX */
Stefan Roese4c9e8552008-03-19 16:20:49 +01001438#if defined (CONFIG_460GT)
1439 case 2:
1440 /* setup MAL tx & rx channel pointers */
1441 mtdcr (maltxbattr, 0x0);
1442 mtdcr (malrxbattr, 0x0);
1443 mtdcr (maltxctp2r, hw_p->tx_phys);
1444 mtdcr (malrxctp16r, hw_p->rx_phys);
1445 /* set RX buffer size */
1446 mtdcr (malrcbs16, ENET_MAX_MTU_ALIGNED / 16);
1447 break;
1448 case 3:
1449 /* setup MAL tx & rx channel pointers */
1450 mtdcr (maltxbattr, 0x0);
1451 mtdcr (malrxbattr, 0x0);
1452 mtdcr (maltxctp3r, hw_p->tx_phys);
1453 mtdcr (malrxctp24r, hw_p->rx_phys);
1454 /* set RX buffer size */
1455 mtdcr (malrcbs24, ENET_MAX_MTU_ALIGNED / 16);
1456 break;
1457#endif /* CONFIG_460GT */
wdenkba56f622004-02-06 23:19:44 +00001458 case 0:
1459 default:
1460 /* setup MAL tx & rx channel pointers */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001461#if defined(CONFIG_440)
wdenkba56f622004-02-06 23:19:44 +00001462 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001463 mtdcr (malrxbattr, 0x0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001464#endif
Stefan Roeseff768cb2007-10-31 18:01:24 +01001465 mtdcr (maltxctp0r, hw_p->tx_phys);
1466 mtdcr (malrxctp0r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001467 /* set RX buffer size */
1468 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
1469 break;
1470 }
1471
1472 /* Enable MAL transmit and receive channels */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001473#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001474 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
1475#else
wdenkba56f622004-02-06 23:19:44 +00001476 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
Stefan Roesec157d8e2005-08-01 16:41:48 +02001477#endif
wdenkba56f622004-02-06 23:19:44 +00001478 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
1479
1480 /* set transmit enable & receive enable */
Stefan Roese2d834762007-10-23 14:03:17 +02001481 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
wdenkba56f622004-02-06 23:19:44 +00001482
Stefan Roese2d834762007-10-23 14:03:17 +02001483 mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr);
Stefan Roese76957cb2008-03-01 12:11:40 +01001484
1485 /* set rx-/tx-fifo size */
1486 mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
wdenkba56f622004-02-06 23:19:44 +00001487
1488 /* set speed */
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001489 if (speed == _1000BASET) {
Stefan Roese738815c2007-10-02 11:44:46 +02001490#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1491 defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001492 unsigned long pfc1;
Stefan Roese887e2ec2006-09-07 11:51:23 +02001493
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001494 mfsdr (sdr_pfc1, pfc1);
1495 pfc1 |= SDR0_PFC1_EM_1000;
1496 mtsdr (sdr_pfc1, pfc1);
1497#endif
wdenk855a4962004-03-14 18:23:55 +00001498 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001499 } else if (speed == _100BASET)
wdenkba56f622004-02-06 23:19:44 +00001500 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
1501 else
1502 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
1503 if (duplex == FULL)
1504 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
1505
Stefan Roese2d834762007-10-23 14:03:17 +02001506 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
wdenkba56f622004-02-06 23:19:44 +00001507
1508 /* Enable broadcast and indvidual address */
1509 /* TBS: enabling runts as some misbehaved nics will send runts */
Stefan Roese2d834762007-10-23 14:03:17 +02001510 out_be32((void *)EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
wdenkba56f622004-02-06 23:19:44 +00001511
1512 /* we probably need to set the tx mode1 reg? maybe at tx time */
1513
1514 /* set transmit request threshold register */
Stefan Roese2d834762007-10-23 14:03:17 +02001515 out_be32((void *)EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
wdenkba56f622004-02-06 23:19:44 +00001516
Wolfgang Denk265817c2005-09-25 00:53:22 +02001517 /* set receive low/high water mark register */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001518#if defined(CONFIG_440)
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001519 /* 440s has a 64 byte burst length */
Stefan Roese2d834762007-10-23 14:03:17 +02001520 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001521#else
1522 /* 405s have a 16 byte burst length */
Stefan Roese2d834762007-10-23 14:03:17 +02001523 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001524#endif /* defined(CONFIG_440) */
Stefan Roese2d834762007-10-23 14:03:17 +02001525 out_be32((void *)EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
wdenkba56f622004-02-06 23:19:44 +00001526
1527 /* Set fifo limit entry in tx mode 0 */
Stefan Roese2d834762007-10-23 14:03:17 +02001528 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
wdenkba56f622004-02-06 23:19:44 +00001529 /* Frame gap set */
Stefan Roese2d834762007-10-23 14:03:17 +02001530 out_be32((void *)EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
wdenkba56f622004-02-06 23:19:44 +00001531
1532 /* Set EMAC IER */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001533 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
wdenkba56f622004-02-06 23:19:44 +00001534 if (speed == _100BASET)
1535 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1536
Stefan Roese2d834762007-10-23 14:03:17 +02001537 out_be32((void *)EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
1538 out_be32((void *)EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
wdenkba56f622004-02-06 23:19:44 +00001539
1540 if (hw_p->first_init == 0) {
1541 /*
1542 * Connect interrupt service routines
1543 */
Stefan Roesedbbd1252007-10-05 17:10:59 +02001544 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1545 (interrupt_handler_t *) enetInt, dev);
wdenkba56f622004-02-06 23:19:44 +00001546 }
wdenkba56f622004-02-06 23:19:44 +00001547
1548 mtmsr (msr); /* enable interrupts again */
1549
1550 hw_p->bis = bis;
1551 hw_p->first_init = 1;
1552
Stefan Roese802b7692008-01-08 18:39:30 +01001553 return 0;
wdenkba56f622004-02-06 23:19:44 +00001554}
1555
1556
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001557static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
wdenkba56f622004-02-06 23:19:44 +00001558 int len)
1559{
1560 struct enet_frame *ef_ptr;
1561 ulong time_start, time_now;
1562 unsigned long temp_txm0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001563 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001564
1565 ef_ptr = (struct enet_frame *) ptr;
1566
1567 /*-----------------------------------------------------------------------+
1568 * Copy in our address into the frame.
1569 *-----------------------------------------------------------------------*/
1570 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1571
1572 /*-----------------------------------------------------------------------+
1573 * If frame is too long or too short, modify length.
1574 *-----------------------------------------------------------------------*/
1575 /* TBS: where does the fragment go???? */
1576 if (len > ENET_MAX_MTU)
1577 len = ENET_MAX_MTU;
1578
1579 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1580 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001581 flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
wdenkba56f622004-02-06 23:19:44 +00001582
1583 /*-----------------------------------------------------------------------+
1584 * set TX Buffer busy, and send it
1585 *-----------------------------------------------------------------------*/
1586 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1587 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1588 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1589 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1590 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1591
1592 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1593 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1594
Stefan Roese8ac41e32008-03-11 15:05:26 +01001595 sync();
wdenkba56f622004-02-06 23:19:44 +00001596
Stefan Roese2d834762007-10-23 14:03:17 +02001597 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr,
1598 in_be32((void *)EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001599#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001600 hw_p->stats.pkts_tx++;
1601#endif
1602
1603 /*-----------------------------------------------------------------------+
1604 * poll unitl the packet is sent and then make sure it is OK
1605 *-----------------------------------------------------------------------*/
1606 time_start = get_timer (0);
1607 while (1) {
Stefan Roese2d834762007-10-23 14:03:17 +02001608 temp_txm0 = in_be32((void *)EMAC_TXM0 + hw_p->hw_addr);
wdenkba56f622004-02-06 23:19:44 +00001609 /* loop until either TINT turns on or 3 seconds elapse */
1610 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
1611 /* transmit is done, so now check for errors
1612 * If there is an error, an interrupt should
1613 * happen when we return
1614 */
1615 time_now = get_timer (0);
1616 if ((time_now - time_start) > 3000) {
1617 return (-1);
1618 }
1619 } else {
1620 return (len);
1621 }
1622 }
1623}
1624
wdenkba56f622004-02-06 23:19:44 +00001625int enetInt (struct eth_device *dev)
1626{
1627 int serviced;
1628 int rc = -1; /* default to not us */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001629 u32 mal_isr;
1630 u32 emac_isr = 0;
1631 u32 mal_eob;
1632 u32 uic_mal;
1633 u32 uic_mal_err;
1634 u32 uic_emac;
1635 u32 uic_emac_b;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001636 EMAC_4XX_HW_PST hw_p;
wdenkba56f622004-02-06 23:19:44 +00001637
1638 /*
1639 * Because the mal is generic, we need to get the current
1640 * eth device
1641 */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001642 dev = eth_get_dev();
wdenkba56f622004-02-06 23:19:44 +00001643
1644 hw_p = dev->priv;
1645
wdenkba56f622004-02-06 23:19:44 +00001646 /* enter loop that stays in interrupt code until nothing to service */
1647 do {
1648 serviced = 0;
1649
Stefan Roesed1631fe2008-06-26 13:40:57 +02001650 uic_mal = mfdcr(UIC_BASE_MAL + UIC_MSR);
1651 uic_mal_err = mfdcr(UIC_BASE_MAL_ERR + UIC_MSR);
1652 uic_emac = mfdcr(UIC_BASE_EMAC + UIC_MSR);
1653 uic_emac_b = mfdcr(UIC_BASE_EMAC_B + UIC_MSR);
Stefan Roese887e2ec2006-09-07 11:51:23 +02001654
Stefan Roesed1631fe2008-06-26 13:40:57 +02001655 if (!(uic_mal & (UIC_MAL_RXEOB | UIC_MAL_TXEOB))
1656 && !(uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE))
1657 && !(uic_emac & UIC_ETHx) && !(uic_emac_b & UIC_ETHxB)) {
wdenkba56f622004-02-06 23:19:44 +00001658 /* not for us */
1659 return (rc);
1660 }
Stefan Roesed1631fe2008-06-26 13:40:57 +02001661
wdenkba56f622004-02-06 23:19:44 +00001662 /* get and clear controller status interrupts */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001663 /* look at MAL and EMAC error interrupts */
1664 if (uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) {
1665 /* we have a MAL error interrupt */
1666 mal_isr = mfdcr(malesr);
1667 mal_err(dev, mal_isr, uic_mal_err,
1668 MAL_UIC_DEF, MAL_UIC_ERR);
1669
1670 /* clear MAL error interrupt status bits */
1671 mtdcr(UIC_BASE_MAL_ERR + UIC_SR,
1672 UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE);
1673
1674 return -1;
wdenkba56f622004-02-06 23:19:44 +00001675 }
1676
Stefan Roesed1631fe2008-06-26 13:40:57 +02001677 /* look for EMAC errors */
1678 if ((uic_emac & UIC_ETHx) || (uic_emac_b & UIC_ETHxB)) {
1679 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
1680 emac_err(dev, emac_isr);
wdenkba56f622004-02-06 23:19:44 +00001681
Stefan Roesed1631fe2008-06-26 13:40:57 +02001682 /* clear EMAC error interrupt status bits */
1683 mtdcr(UIC_BASE_EMAC + UIC_SR, UIC_ETHx);
1684 mtdcr(UIC_BASE_EMAC_B + UIC_SR, UIC_ETHxB);
wdenkba56f622004-02-06 23:19:44 +00001685
Stefan Roesed1631fe2008-06-26 13:40:57 +02001686 return -1;
wdenkba56f622004-02-06 23:19:44 +00001687 }
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001688
wdenkba56f622004-02-06 23:19:44 +00001689 /* handle MAX TX EOB interrupt from a tx */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001690 if (uic_mal & UIC_MAL_TXEOB) {
1691 /* clear MAL interrupt status bits */
1692 mal_eob = mfdcr(maltxeobisr);
1693 mtdcr(maltxeobisr, mal_eob);
1694 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_TXEOB);
1695
1696 /* indicate that we serviced an interrupt */
1697 serviced = 1;
1698 rc = 0;
wdenkba56f622004-02-06 23:19:44 +00001699 }
Stefan Roesed1631fe2008-06-26 13:40:57 +02001700
1701 /* handle MAL RX EOB interupt from a receive */
1702 /* check for EOB on valid channels */
1703 if (uic_mal & UIC_MAL_RXEOB) {
1704 mal_eob = mfdcr(malrxeobisr);
1705 if (mal_eob &
1706 (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL))) {
1707 /* push packet to upper layer */
1708 enet_rcv(dev, emac_isr);
1709
1710 /* clear MAL interrupt status bits */
1711 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_RXEOB);
1712
wdenkba56f622004-02-06 23:19:44 +00001713 /* indicate that we serviced an interrupt */
1714 serviced = 1;
1715 rc = 0;
1716 }
1717 }
wdenkba56f622004-02-06 23:19:44 +00001718 } while (serviced);
1719
1720 return (rc);
1721}
1722
1723/*-----------------------------------------------------------------------------+
1724 * MAL Error Routine
1725 *-----------------------------------------------------------------------------*/
1726static void mal_err (struct eth_device *dev, unsigned long isr,
1727 unsigned long uic, unsigned long maldef,
1728 unsigned long mal_errr)
1729{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001730 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001731
1732 mtdcr (malesr, isr); /* clear interrupt */
1733
1734 /* clear DE interrupt */
1735 mtdcr (maltxdeir, 0xC0000000);
1736 mtdcr (malrxdeir, 0x80000000);
1737
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001738#ifdef INFO_4XX_ENET
Wolfgang Denk265817c2005-09-25 00:53:22 +02001739 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 +00001740#endif
1741
1742 eth_init (hw_p->bis); /* start again... */
1743}
1744
1745/*-----------------------------------------------------------------------------+
1746 * EMAC Error Routine
1747 *-----------------------------------------------------------------------------*/
1748static void emac_err (struct eth_device *dev, unsigned long isr)
1749{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001750 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001751
1752 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
Stefan Roese2d834762007-10-23 14:03:17 +02001753 out_be32((void *)EMAC_ISR + hw_p->hw_addr, isr);
wdenkba56f622004-02-06 23:19:44 +00001754}
1755
1756/*-----------------------------------------------------------------------------+
1757 * enet_rcv() handles the ethernet receive data
1758 *-----------------------------------------------------------------------------*/
1759static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1760{
1761 struct enet_frame *ef_ptr;
1762 unsigned long data_len;
1763 unsigned long rx_eob_isr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001764 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001765
1766 int handled = 0;
1767 int i;
1768 int loop_count = 0;
1769
1770 rx_eob_isr = mfdcr (malrxeobisr);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001771 if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
wdenkba56f622004-02-06 23:19:44 +00001772 /* clear EOB */
1773 mtdcr (malrxeobisr, rx_eob_isr);
1774
1775 /* EMAC RX done */
1776 while (1) { /* do all */
1777 i = hw_p->rx_slot;
1778
1779 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1780 || (loop_count >= NUM_RX_BUFF))
1781 break;
Stefan Roesea2e1c702007-07-12 16:32:08 +02001782
wdenkba56f622004-02-06 23:19:44 +00001783 loop_count++;
wdenkba56f622004-02-06 23:19:44 +00001784 handled++;
Stefan Roese8ac41e32008-03-11 15:05:26 +01001785 data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */
wdenkba56f622004-02-06 23:19:44 +00001786 if (data_len) {
1787 if (data_len > ENET_MAX_MTU) /* Check len */
1788 data_len = 0;
1789 else {
1790 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1791 data_len = 0;
1792 hw_p->stats.rx_err_log[hw_p->
1793 rx_err_index]
1794 = hw_p->rx[i].ctrl;
1795 hw_p->rx_err_index++;
1796 if (hw_p->rx_err_index ==
1797 MAX_ERR_LOG)
1798 hw_p->rx_err_index =
1799 0;
wdenkfc1cfcd2004-04-25 15:41:35 +00001800 } /* emac_erros */
wdenkba56f622004-02-06 23:19:44 +00001801 } /* data_len < max mtu */
wdenkfc1cfcd2004-04-25 15:41:35 +00001802 } /* if data_len */
wdenkba56f622004-02-06 23:19:44 +00001803 if (!data_len) { /* no data */
1804 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1805
1806 hw_p->stats.data_len_err++; /* Error at Rx */
1807 }
1808
1809 /* !data_len */
1810 /* AS.HARNOIS */
1811 /* Check if user has already eaten buffer */
1812 /* if not => ERROR */
1813 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1814 if (hw_p->is_receiving)
1815 printf ("ERROR : Receive buffers are full!\n");
1816 break;
1817 } else {
1818 hw_p->stats.rx_frames++;
1819 hw_p->stats.rx += data_len;
1820 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1821 data_ptr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001822#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001823 hw_p->stats.pkts_rx++;
1824#endif
1825 /* AS.HARNOIS
1826 * use ring buffer
1827 */
1828 hw_p->rx_ready[hw_p->rx_i_index] = i;
1829 hw_p->rx_i_index++;
1830 if (NUM_RX_BUFF == hw_p->rx_i_index)
1831 hw_p->rx_i_index = 0;
1832
Stefan Roesea2e1c702007-07-12 16:32:08 +02001833 hw_p->rx_slot++;
1834 if (NUM_RX_BUFF == hw_p->rx_slot)
1835 hw_p->rx_slot = 0;
1836
wdenkba56f622004-02-06 23:19:44 +00001837 /* AS.HARNOIS
1838 * free receive buffer only when
1839 * buffer has been handled (eth_rx)
1840 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1841 */
1842 } /* if data_len */
1843 } /* while */
1844 } /* if EMACK_RXCHL */
1845}
1846
1847
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001848static int ppc_4xx_eth_rx (struct eth_device *dev)
wdenkba56f622004-02-06 23:19:44 +00001849{
1850 int length;
1851 int user_index;
1852 unsigned long msr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001853 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001854
Wolfgang Denk265817c2005-09-25 00:53:22 +02001855 hw_p->is_receiving = 1; /* tell driver */
wdenkba56f622004-02-06 23:19:44 +00001856
1857 for (;;) {
1858 /* AS.HARNOIS
1859 * use ring buffer and
1860 * get index from rx buffer desciptor queue
1861 */
1862 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1863 if (user_index == -1) {
1864 length = -1;
1865 break; /* nothing received - leave for() loop */
1866 }
1867
1868 msr = mfmsr ();
1869 mtmsr (msr & ~(MSR_EE));
1870
Stefan Roese8ac41e32008-03-11 15:05:26 +01001871 length = hw_p->rx[user_index].data_len & 0x0fff;
wdenkba56f622004-02-06 23:19:44 +00001872
1873 /* Pass the packet up to the protocol layers. */
Wolfgang Denk265817c2005-09-25 00:53:22 +02001874 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1875 /* NetReceive(NetRxPackets[i], length); */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001876 invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
1877 (u32)hw_p->rx[user_index].data_ptr +
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001878 length - 4);
wdenkba56f622004-02-06 23:19:44 +00001879 NetReceive (NetRxPackets[user_index], length - 4);
1880 /* Free Recv Buffer */
1881 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1882 /* Free rx buffer descriptor queue */
1883 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1884 hw_p->rx_u_index++;
1885 if (NUM_RX_BUFF == hw_p->rx_u_index)
1886 hw_p->rx_u_index = 0;
1887
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001888#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001889 hw_p->stats.pkts_handled++;
1890#endif
1891
1892 mtmsr (msr); /* Enable IRQ's */
1893 }
1894
Wolfgang Denk265817c2005-09-25 00:53:22 +02001895 hw_p->is_receiving = 0; /* tell driver */
wdenkba56f622004-02-06 23:19:44 +00001896
1897 return length;
1898}
1899
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001900int ppc_4xx_eth_initialize (bd_t * bis)
wdenkba56f622004-02-06 23:19:44 +00001901{
1902 static int virgin = 0;
wdenkba56f622004-02-06 23:19:44 +00001903 struct eth_device *dev;
1904 int eth_num = 0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001905 EMAC_4XX_HW_PST hw = NULL;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001906 u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1907 u32 hw_addr[4];
Stefan Roesed1631fe2008-06-26 13:40:57 +02001908 u32 mal_ier;
wdenkba56f622004-02-06 23:19:44 +00001909
Stefan Roese846b0dd2005-08-08 12:42:22 +02001910#if defined(CONFIG_440GX)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001911 unsigned long pfc1;
1912
wdenkba56f622004-02-06 23:19:44 +00001913 mfsdr (sdr_pfc1, pfc1);
1914 pfc1 &= ~(0x01e00000);
1915 pfc1 |= 0x01200000;
1916 mtsdr (sdr_pfc1, pfc1);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001917#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001918
1919 /* first clear all mac-addresses */
1920 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1921 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
1922
1923 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
Mike Frysingerd3f87142009-02-11 19:01:26 -05001924 int ethaddr_idx = eth_num + CONFIG_EMAC_NR_START;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001925 switch (eth_num) {
1926 default: /* fall through */
1927 case 0:
Mike Frysingerd3f87142009-02-11 19:01:26 -05001928 eth_getenv_enetaddr("ethaddr", ethaddr[ethaddr_idx]);
Stefan Roese5fb692c2007-01-18 10:25:34 +01001929 hw_addr[eth_num] = 0x0;
1930 break;
1931#ifdef CONFIG_HAS_ETH1
1932 case 1:
Mike Frysingerd3f87142009-02-11 19:01:26 -05001933 eth_getenv_enetaddr("eth1addr", ethaddr[ethaddr_idx]);
Stefan Roese5fb692c2007-01-18 10:25:34 +01001934 hw_addr[eth_num] = 0x100;
1935 break;
1936#endif
1937#ifdef CONFIG_HAS_ETH2
1938 case 2:
Mike Frysingerd3f87142009-02-11 19:01:26 -05001939 eth_getenv_enetaddr("eth2addr", ethaddr[ethaddr_idx]);
Stefan Roese4c9e8552008-03-19 16:20:49 +01001940#if defined(CONFIG_460GT)
1941 hw_addr[eth_num] = 0x300;
1942#else
Stefan Roese5fb692c2007-01-18 10:25:34 +01001943 hw_addr[eth_num] = 0x400;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001944#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001945 break;
1946#endif
1947#ifdef CONFIG_HAS_ETH3
1948 case 3:
Mike Frysingerd3f87142009-02-11 19:01:26 -05001949 eth_getenv_enetaddr("eth3addr", ethaddr[ethaddr_idx]);
Stefan Roese4c9e8552008-03-19 16:20:49 +01001950#if defined(CONFIG_460GT)
1951 hw_addr[eth_num] = 0x400;
1952#else
Stefan Roese5fb692c2007-01-18 10:25:34 +01001953 hw_addr[eth_num] = 0x600;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001954#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001955 break;
1956#endif
1957 }
1958 }
1959
wdenk3c74e322004-02-22 23:46:08 +00001960 /* set phy num and mode */
1961 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001962 bis->bi_phymode[0] = 0;
1963
Stefan Roesec157d8e2005-08-01 16:41:48 +02001964#if defined(CONFIG_PHY1_ADDR)
wdenk3c74e322004-02-22 23:46:08 +00001965 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001966 bis->bi_phymode[1] = 0;
Stefan Roesec157d8e2005-08-01 16:41:48 +02001967#endif
Stefan Roese846b0dd2005-08-08 12:42:22 +02001968#if defined(CONFIG_440GX)
wdenk3c74e322004-02-22 23:46:08 +00001969 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1970 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
wdenk3c74e322004-02-22 23:46:08 +00001971 bis->bi_phymode[2] = 2;
1972 bis->bi_phymode[3] = 2;
Stefan Roesedbbd1252007-10-05 17:10:59 +02001973#endif
wdenkba56f622004-02-06 23:19:44 +00001974
Stefan Roesedbbd1252007-10-05 17:10:59 +02001975#if defined(CONFIG_440GX) || \
1976 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1977 defined(CONFIG_405EX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001978 ppc_4xx_eth_setup_bridge(0, bis);
wdenka06752e2004-09-29 22:43:59 +00001979#endif
1980
Stefan Roese1e25f952005-10-20 16:34:28 +02001981 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
Stefan Roese5fb692c2007-01-18 10:25:34 +01001982 /*
1983 * See if we can actually bring up the interface,
1984 * otherwise, skip it
1985 */
1986 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
1987 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1988 continue;
wdenkba56f622004-02-06 23:19:44 +00001989 }
1990
1991 /* Allocate device structure */
1992 dev = (struct eth_device *) malloc (sizeof (*dev));
1993 if (dev == NULL) {
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001994 printf ("ppc_4xx_eth_initialize: "
wdenk3f85ce22004-02-23 16:11:30 +00001995 "Cannot allocate eth_device %d\n", eth_num);
wdenkba56f622004-02-06 23:19:44 +00001996 return (-1);
1997 }
wdenkb2532ef2005-06-20 10:17:34 +00001998 memset(dev, 0, sizeof(*dev));
wdenkba56f622004-02-06 23:19:44 +00001999
2000 /* Allocate our private use data */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002001 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
wdenkba56f622004-02-06 23:19:44 +00002002 if (hw == NULL) {
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002003 printf ("ppc_4xx_eth_initialize: "
wdenk3f85ce22004-02-23 16:11:30 +00002004 "Cannot allocate private hw data for eth_device %d",
wdenkba56f622004-02-06 23:19:44 +00002005 eth_num);
2006 free (dev);
2007 return (-1);
2008 }
wdenkb2532ef2005-06-20 10:17:34 +00002009 memset(hw, 0, sizeof(*hw));
wdenkba56f622004-02-06 23:19:44 +00002010
Stefan Roese5fb692c2007-01-18 10:25:34 +01002011 hw->hw_addr = hw_addr[eth_num];
2012 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
wdenkba56f622004-02-06 23:19:44 +00002013 hw->devnum = eth_num;
Stefan Roesec157d8e2005-08-01 16:41:48 +02002014 hw->print_speed = 1;
wdenkba56f622004-02-06 23:19:44 +00002015
Stefan Roese5fb692c2007-01-18 10:25:34 +01002016 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
wdenkba56f622004-02-06 23:19:44 +00002017 dev->priv = (void *) hw;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002018 dev->init = ppc_4xx_eth_init;
2019 dev->halt = ppc_4xx_eth_halt;
2020 dev->send = ppc_4xx_eth_send;
2021 dev->recv = ppc_4xx_eth_rx;
wdenkba56f622004-02-06 23:19:44 +00002022
2023 if (0 == virgin) {
2024 /* set the MAL IER ??? names may change with new spec ??? */
Stefan Roesedbbd1252007-10-05 17:10:59 +02002025#if defined(CONFIG_440SPE) || \
2026 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01002027 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02002028 defined(CONFIG_405EX)
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002029 mal_ier =
2030 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
2031 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
2032#else
wdenkba56f622004-02-06 23:19:44 +00002033 mal_ier =
2034 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
2035 MAL_IER_OPBE | MAL_IER_PLBE;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002036#endif
wdenkba56f622004-02-06 23:19:44 +00002037 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
2038 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
2039 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
2040 mtdcr (malier, mal_ier);
2041
2042 /* install MAL interrupt handler */
Stefan Roesed1631fe2008-06-26 13:40:57 +02002043 irq_install_handler (VECNUM_MAL_SERR,
wdenkba56f622004-02-06 23:19:44 +00002044 (interrupt_handler_t *) enetInt,
2045 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002046 irq_install_handler (VECNUM_MAL_TXEOB,
wdenkba56f622004-02-06 23:19:44 +00002047 (interrupt_handler_t *) enetInt,
2048 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002049 irq_install_handler (VECNUM_MAL_RXEOB,
wdenkba56f622004-02-06 23:19:44 +00002050 (interrupt_handler_t *) enetInt,
2051 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002052 irq_install_handler (VECNUM_MAL_TXDE,
wdenkba56f622004-02-06 23:19:44 +00002053 (interrupt_handler_t *) enetInt,
2054 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002055 irq_install_handler (VECNUM_MAL_RXDE,
wdenkba56f622004-02-06 23:19:44 +00002056 (interrupt_handler_t *) enetInt,
2057 dev);
2058 virgin = 1;
2059 }
2060
2061 eth_register (dev);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002062
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -05002063#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002064 miiphy_register (dev->name,
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01002065 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002066#endif
wdenkba56f622004-02-06 23:19:44 +00002067 } /* end for each supported device */
Stefan Roese802b7692008-01-08 18:39:30 +01002068
2069 return 0;
wdenkba56f622004-02-06 23:19:44 +00002070}