blob: 071ac0a96771a0f5379edef3a90760765c12e90c [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
Stefan Roesed6c61aa2005-08-16 18:18:00 +020094/*
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020095 * Only compile for platform with AMCC EMAC ethernet controller and
Stefan Roesed6c61aa2005-08-16 18:18:00 +020096 * network support enabled.
97 * Remark: CONFIG_405 describes Xilinx PPC405 FPGA without EMAC controller!
98 */
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -050099#if defined(CONFIG_CMD_NET) && !defined(CONFIG_405) && !defined(CONFIG_IOP480)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200100
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500101#if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200102#error "CONFIG_MII has to be defined!"
103#endif
wdenkba56f622004-02-06 23:19:44 +0000104
Stefan Roese1e25f952005-10-20 16:34:28 +0200105#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI)
106#error "CONFIG_NET_MULTI has to be defined for NetConsole"
107#endif
108
Wolfgang Denk265817c2005-09-25 00:53:22 +0200109#define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
Stefan Roese1338e6a2007-10-23 14:05:08 +0200110#define PHY_AUTONEGOTIATE_TIMEOUT 5000 /* 5000 ms autonegotiate timeout */
wdenkba56f622004-02-06 23:19:44 +0000111
wdenkba56f622004-02-06 23:19:44 +0000112/* Ethernet Transmit and Receive Buffers */
113/* AS.HARNOIS
114 * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
115 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
116 */
Wolfgang Denk265817c2005-09-25 00:53:22 +0200117#define ENET_MAX_MTU PKTSIZE
wdenkba56f622004-02-06 23:19:44 +0000118#define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
119
wdenkba56f622004-02-06 23:19:44 +0000120/*-----------------------------------------------------------------------------+
121 * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
122 * Interrupt Controller).
123 *-----------------------------------------------------------------------------*/
Stefan Roesed1631fe2008-06-26 13:40:57 +0200124#define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * VECNUM_ETH1_OFFS))
125
126#if defined(CONFIG_HAS_ETH3)
127#if !defined(CONFIG_440GX)
128#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
129 UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
130#else
131/* Unfortunately 440GX spreads EMAC interrupts on multiple UIC's */
132#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
133#define UIC_ETHxB (UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
134#endif /* !defined(CONFIG_440GX) */
135#elif defined(CONFIG_HAS_ETH2)
136#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
137 UIC_MASK(ETH_IRQ_NUM(2)))
138#elif defined(CONFIG_HAS_ETH1)
139#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
140#else
141#define UIC_ETHx UIC_MASK(ETH_IRQ_NUM(0))
142#endif
143
144/*
145 * Define a default version for UIC_ETHxB for non 440GX so that we can
146 * use common code for all 4xx variants
147 */
148#if !defined(UIC_ETHxB)
149#define UIC_ETHxB 0
150#endif
151
152#define UIC_MAL_SERR UIC_MASK(VECNUM_MAL_SERR)
153#define UIC_MAL_TXDE UIC_MASK(VECNUM_MAL_TXDE)
154#define UIC_MAL_RXDE UIC_MASK(VECNUM_MAL_RXDE)
155#define UIC_MAL_TXEOB UIC_MASK(VECNUM_MAL_TXEOB)
156#define UIC_MAL_RXEOB UIC_MASK(VECNUM_MAL_RXEOB)
157
158#define MAL_UIC_ERR (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
159#define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
160
161/*
162 * We have 3 different interrupt types:
163 * - MAL interrupts indicating successful transfer
164 * - MAL error interrupts indicating MAL related errors
165 * - EMAC interrupts indicating EMAC related errors
166 *
167 * All those interrupts can be on different UIC's, but since
168 * now at least all interrupts from one type are on the same
169 * UIC. Only exception is 440GX where the EMAC interrupts are
170 * spread over two UIC's!
171 */
Stefan Roese5de85142008-06-26 17:36:39 +0200172#if defined(CONFIG_440GX)
173#define UIC_BASE_MAL UIC1_DCR_BASE
174#define UIC_BASE_MAL_ERR UIC2_DCR_BASE
175#define UIC_BASE_EMAC UIC2_DCR_BASE
176#define UIC_BASE_EMAC_B UIC3_DCR_BASE
177#else
Stefan Roesed1631fe2008-06-26 13:40:57 +0200178#define UIC_BASE_MAL (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_TXEOB) * 0x10))
179#define UIC_BASE_MAL_ERR (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_SERR) * 0x10))
180#define UIC_BASE_EMAC (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
Stefan Roesed1631fe2008-06-26 13:40:57 +0200181#define UIC_BASE_EMAC_B (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
182#endif
wdenkba56f622004-02-06 23:19:44 +0000183
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200184#undef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +0000185
Wolfgang Denk265817c2005-09-25 00:53:22 +0200186#define BI_PHYMODE_NONE 0
187#define BI_PHYMODE_ZMII 1
wdenk3c74e322004-02-22 23:46:08 +0000188#define BI_PHYMODE_RGMII 2
Stefan Roese887e2ec2006-09-07 11:51:23 +0200189#define BI_PHYMODE_GMII 3
190#define BI_PHYMODE_RTBI 4
191#define BI_PHYMODE_TBI 5
Stefan Roesedbbd1252007-10-05 17:10:59 +0200192#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100193 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200194 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200195#define BI_PHYMODE_SMII 6
196#define BI_PHYMODE_MII 7
Stefan Roese8ac41e32008-03-11 15:05:26 +0100197#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
198#define BI_PHYMODE_RMII 8
199#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +0200200#endif
Victor Gallardo78d78232008-09-04 23:49:36 -0700201#define BI_PHYMODE_SGMII 9
wdenk3c74e322004-02-22 23:46:08 +0000202
Stefan Roese1941cce2007-10-05 17:35:10 +0200203#if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200204 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100205 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200206 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200207#define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
208#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200209
Stefan Roese8ac41e32008-03-11 15:05:26 +0100210#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
211#define SDR0_ETH_CFG_CLK_SEL_V(n) (0x01 << (8 + n))
212#endif
213
214#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
215#define MAL_RX_CHAN_MUL 8 /* 460EX/GT uses MAL channel 8 for EMAC1 */
216#else
217#define MAL_RX_CHAN_MUL 1
218#endif
219
Victor Gallardo78d78232008-09-04 23:49:36 -0700220/*--------------------------------------------------------------------+
221 * Fixed PHY (PHY-less) support for Ethernet Ports.
222 *--------------------------------------------------------------------*/
223
224/*
225 * Some boards do not have a PHY for each ethernet port. These ports
226 * are known as Fixed PHY (or PHY-less) ports. For such ports, set
227 * the appropriate CONFIG_PHY_ADDR equal to CONFIG_FIXED_PHY and
228 * then define CFG_FIXED_PHY_PORTS to define what the speed and
229 * duplex should be for these ports in the board configuration
230 * file.
231 *
232 * For Example:
233 * #define CONFIG_FIXED_PHY 0xFFFFFFFF
234 *
235 * #define CONFIG_PHY_ADDR CONFIG_FIXED_PHY
236 * #define CONFIG_PHY1_ADDR 1
237 * #define CONFIG_PHY2_ADDR CONFIG_FIXED_PHY
238 * #define CONFIG_PHY3_ADDR 3
239 *
240 * #define CFG_FIXED_PHY_PORT(devnum,speed,duplex) \
241 * {devnum, speed, duplex},
242 *
243 * #define CFG_FIXED_PHY_PORTS \
244 * CFG_FIXED_PHY_PORT(0,1000,FULL) \
245 * CFG_FIXED_PHY_PORT(2,100,HALF)
246 */
247
248#ifndef CONFIG_FIXED_PHY
249#define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */
250#endif
251
252#ifndef CFG_FIXED_PHY_PORTS
253#define CFG_FIXED_PHY_PORTS /* default is an empty array */
254#endif
255
256struct fixed_phy_port {
257 unsigned int devnum; /* ethernet port */
258 unsigned int speed; /* specified speed 10,100 or 1000 */
259 unsigned int duplex; /* specified duplex FULL or HALF */
260};
261
262static const struct fixed_phy_port fixed_phy_port[] = {
263 CFG_FIXED_PHY_PORTS /* defined in board configuration file */
264};
265
wdenkba56f622004-02-06 23:19:44 +0000266/*-----------------------------------------------------------------------------+
267 * Global variables. TX and RX descriptors and buffers.
268 *-----------------------------------------------------------------------------*/
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200269#if !defined(CONFIG_NET_MULTI)
Stefan Roese4f92ac32005-10-10 17:43:58 +0200270struct eth_device *emac0_dev = NULL;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200271#endif
272
Stefan Roese1e25f952005-10-20 16:34:28 +0200273/*
274 * Get count of EMAC devices (doesn't have to be the max. possible number
275 * supported by the cpu)
Stefan Roese353f2682007-10-23 10:10:08 +0200276 *
277 * CONFIG_BOARD_EMAC_COUNT added so now a "dynamic" way to configure the
278 * EMAC count is possible. As it is needed for the Kilauea/Haleakala
279 * 405EX/405EXr eval board, using the same binary.
Stefan Roese1e25f952005-10-20 16:34:28 +0200280 */
Stefan Roese353f2682007-10-23 10:10:08 +0200281#if defined(CONFIG_BOARD_EMAC_COUNT)
282#define LAST_EMAC_NUM board_emac_count()
283#else /* CONFIG_BOARD_EMAC_COUNT */
Stefan Roese1e25f952005-10-20 16:34:28 +0200284#if defined(CONFIG_HAS_ETH3)
285#define LAST_EMAC_NUM 4
286#elif defined(CONFIG_HAS_ETH2)
287#define LAST_EMAC_NUM 3
288#elif defined(CONFIG_HAS_ETH1)
289#define LAST_EMAC_NUM 2
290#else
291#define LAST_EMAC_NUM 1
292#endif
Stefan Roese353f2682007-10-23 10:10:08 +0200293#endif /* CONFIG_BOARD_EMAC_COUNT */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200294
Stefan Roese5fb692c2007-01-18 10:25:34 +0100295/* normal boards start with EMAC0 */
296#if !defined(CONFIG_EMAC_NR_START)
297#define CONFIG_EMAC_NR_START 0
298#endif
299
Stefan Roeseff768cb2007-10-31 18:01:24 +0100300#define MAL_RX_DESC_SIZE 2048
301#define MAL_TX_DESC_SIZE 2048
302#define MAL_ALLOC_SIZE (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE)
303
wdenkba56f622004-02-06 23:19:44 +0000304/*-----------------------------------------------------------------------------+
305 * Prototypes and externals.
306 *-----------------------------------------------------------------------------*/
307static void enet_rcv (struct eth_device *dev, unsigned long malisr);
308
309int enetInt (struct eth_device *dev);
310static void mal_err (struct eth_device *dev, unsigned long isr,
311 unsigned long uic, unsigned long maldef,
312 unsigned long mal_errr);
313static void emac_err (struct eth_device *dev, unsigned long isr);
314
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200315extern int phy_setup_aneg (char *devname, unsigned char addr);
316extern int emac4xx_miiphy_read (char *devname, unsigned char addr,
317 unsigned char reg, unsigned short *value);
318extern int emac4xx_miiphy_write (char *devname, unsigned char addr,
319 unsigned char reg, unsigned short value);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200320
Stefan Roese353f2682007-10-23 10:10:08 +0200321int board_emac_count(void);
322
Stefan Roese8ac41e32008-03-11 15:05:26 +0100323static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p)
324{
325#if defined(CONFIG_440SPE) || \
326 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
327 defined(CONFIG_405EX)
328 u32 val;
329
330 mfsdr(sdr_mfr, val);
331 val |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
332 mtsdr(sdr_mfr, val);
333#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
334 u32 val;
335
336 mfsdr(SDR0_ETH_CFG, val);
337 val |= SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
338 mtsdr(SDR0_ETH_CFG, val);
339#endif
340}
341
342static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p)
343{
344#if defined(CONFIG_440SPE) || \
345 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
346 defined(CONFIG_405EX)
347 u32 val;
348
349 mfsdr(sdr_mfr, val);
350 val &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
351 mtsdr(sdr_mfr, val);
352#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
353 u32 val;
354
355 mfsdr(SDR0_ETH_CFG, val);
356 val &= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
357 mtsdr(SDR0_ETH_CFG, val);
358#endif
359}
360
wdenkba56f622004-02-06 23:19:44 +0000361/*-----------------------------------------------------------------------------+
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200362| ppc_4xx_eth_halt
wdenkba56f622004-02-06 23:19:44 +0000363| Disable MAL channel, and EMACn
wdenkba56f622004-02-06 23:19:44 +0000364+-----------------------------------------------------------------------------*/
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200365static void ppc_4xx_eth_halt (struct eth_device *dev)
wdenkba56f622004-02-06 23:19:44 +0000366{
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200367 EMAC_4XX_HW_PST hw_p = dev->priv;
Stefan Roese9ad31982008-03-19 16:35:12 +0100368 u32 val = 10000;
wdenkba56f622004-02-06 23:19:44 +0000369
Stefan Roese2d834762007-10-23 14:03:17 +0200370 out_be32((void *)EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
wdenkba56f622004-02-06 23:19:44 +0000371
372 /* 1st reset MAL channel */
373 /* Note: writing a 0 to a channel has no effect */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200374#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
375 mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
376#else
wdenkba56f622004-02-06 23:19:44 +0000377 mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200378#endif
wdenkba56f622004-02-06 23:19:44 +0000379 mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
380
381 /* wait for reset */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200382 while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
wdenkba56f622004-02-06 23:19:44 +0000383 udelay (1000); /* Delay 1 MS so as not to hammer the register */
Stefan Roese9ad31982008-03-19 16:35:12 +0100384 val--;
385 if (val == 0)
wdenkba56f622004-02-06 23:19:44 +0000386 break;
wdenkba56f622004-02-06 23:19:44 +0000387 }
388
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200389 /* provide clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100390 emac_loopback_enable(hw_p);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200391
Stefan Roese8ac41e32008-03-11 15:05:26 +0100392 /* EMAC RESET */
Stefan Roese2d834762007-10-23 14:03:17 +0200393 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenkba56f622004-02-06 23:19:44 +0000394
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200395 /* remove clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100396 emac_loopback_disable(hw_p);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200397
Stefan Roesea93316c2005-10-18 19:17:12 +0200398#ifndef CONFIG_NETCONSOLE
Stefan Roesec157d8e2005-08-01 16:41:48 +0200399 hw_p->print_speed = 1; /* print speed message again next time */
Stefan Roesea93316c2005-10-18 19:17:12 +0200400#endif
Stefan Roesec157d8e2005-08-01 16:41:48 +0200401
Stefan Roese4c9e8552008-03-19 16:20:49 +0100402#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
403 /* don't bypass the TAHOE0/TAHOE1 cores for Linux */
Stefan Roese9ad31982008-03-19 16:35:12 +0100404 mfsdr(SDR0_ETH_CFG, val);
405 val &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
406 mtsdr(SDR0_ETH_CFG, val);
Stefan Roese4c9e8552008-03-19 16:20:49 +0100407#endif
408
wdenkba56f622004-02-06 23:19:44 +0000409 return;
410}
411
Stefan Roese846b0dd2005-08-08 12:42:22 +0200412#if defined (CONFIG_440GX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200413int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
wdenk855a4962004-03-14 18:23:55 +0000414{
415 unsigned long pfc1;
416 unsigned long zmiifer;
417 unsigned long rmiifer;
418
419 mfsdr(sdr_pfc1, pfc1);
420 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
421
422 zmiifer = 0;
423 rmiifer = 0;
424
425 switch (pfc1) {
426 case 1:
427 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
428 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
429 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
430 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
431 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
432 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
433 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
434 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
435 break;
436 case 2:
Stefan Roesef6e495f2006-11-27 17:43:25 +0100437 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
438 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
439 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
440 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
wdenk855a4962004-03-14 18:23:55 +0000441 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
442 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
443 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
444 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
445 break;
446 case 3:
447 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
448 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
449 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
450 bis->bi_phymode[1] = BI_PHYMODE_NONE;
451 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
452 bis->bi_phymode[3] = BI_PHYMODE_NONE;
453 break;
454 case 4:
455 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
456 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
457 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
458 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
459 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
460 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
461 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
462 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
463 break;
464 case 5:
465 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
466 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
467 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
468 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
469 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
470 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
471 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
472 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
473 break;
474 case 6:
475 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
476 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
477 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
wdenk855a4962004-03-14 18:23:55 +0000478 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
479 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
480 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
wdenk855a4962004-03-14 18:23:55 +0000481 break;
482 case 0:
483 default:
484 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
485 rmiifer = 0x0;
486 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
487 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
488 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
489 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
490 break;
491 }
492
493 /* Ensure we setup mdio for this devnum and ONLY this devnum */
494 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
495
Stefan Roeseff768cb2007-10-31 18:01:24 +0100496 out_be32((void *)ZMII_FER, zmiifer);
497 out_be32((void *)RGMII_FER, rmiifer);
wdenk855a4962004-03-14 18:23:55 +0000498
499 return ((int)pfc1);
wdenk855a4962004-03-14 18:23:55 +0000500}
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200501#endif /* CONFIG_440_GX */
wdenk855a4962004-03-14 18:23:55 +0000502
Stefan Roese887e2ec2006-09-07 11:51:23 +0200503#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
504int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
505{
506 unsigned long zmiifer=0x0;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200507 unsigned long pfc1;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200508
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200509 mfsdr(sdr_pfc1, pfc1);
510 pfc1 &= SDR0_PFC1_SELECT_MASK;
511
Wolfgang Denk2f152782007-05-05 18:23:11 +0200512 switch (pfc1) {
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200513 case SDR0_PFC1_SELECT_CONFIG_2:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200514 /* 1 x GMII port */
Stefan Roese2d834762007-10-23 14:03:17 +0200515 out_be32((void *)ZMII_FER, 0x00);
516 out_be32((void *)RGMII_FER, 0x00000037);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200517 bis->bi_phymode[0] = BI_PHYMODE_GMII;
518 bis->bi_phymode[1] = BI_PHYMODE_NONE;
519 break;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200520 case SDR0_PFC1_SELECT_CONFIG_4:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200521 /* 2 x RGMII ports */
Stefan Roese2d834762007-10-23 14:03:17 +0200522 out_be32((void *)ZMII_FER, 0x00);
523 out_be32((void *)RGMII_FER, 0x00000055);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200524 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
525 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
526 break;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200527 case SDR0_PFC1_SELECT_CONFIG_6:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200528 /* 2 x SMII ports */
Stefan Roese2d834762007-10-23 14:03:17 +0200529 out_be32((void *)ZMII_FER,
530 ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
531 ((ZMII_FER_SMII) << ZMII_FER_V(1)));
532 out_be32((void *)RGMII_FER, 0x00000000);
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200533 bis->bi_phymode[0] = BI_PHYMODE_SMII;
534 bis->bi_phymode[1] = BI_PHYMODE_SMII;
535 break;
536 case SDR0_PFC1_SELECT_CONFIG_1_2:
537 /* only 1 x MII supported */
Stefan Roese2d834762007-10-23 14:03:17 +0200538 out_be32((void *)ZMII_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
539 out_be32((void *)RGMII_FER, 0x00000000);
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200540 bis->bi_phymode[0] = BI_PHYMODE_MII;
541 bis->bi_phymode[1] = BI_PHYMODE_NONE;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200542 break;
543 default:
544 break;
545 }
546
547 /* Ensure we setup mdio for this devnum and ONLY this devnum */
Stefan Roese2d834762007-10-23 14:03:17 +0200548 zmiifer = in_be32((void *)ZMII_FER);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200549 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
Stefan Roese2d834762007-10-23 14:03:17 +0200550 out_be32((void *)ZMII_FER, zmiifer);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200551
552 return ((int)0x0);
553}
554#endif /* CONFIG_440EPX */
555
Stefan Roesedbbd1252007-10-05 17:10:59 +0200556#if defined(CONFIG_405EX)
557int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
558{
Grant Erickson1740c1b2008-07-08 08:35:00 -0700559 u32 rgmiifer = 0;
Stefan Roesedbbd1252007-10-05 17:10:59 +0200560
561 /*
Grant Erickson1740c1b2008-07-08 08:35:00 -0700562 * The 405EX(r)'s RGMII bridge can operate in one of several
563 * modes, only one of which (2 x RGMII) allows the
564 * simultaneous use of both EMACs on the 405EX.
Stefan Roesedbbd1252007-10-05 17:10:59 +0200565 */
Grant Erickson1740c1b2008-07-08 08:35:00 -0700566
567 switch (CONFIG_EMAC_PHY_MODE) {
568
569 case EMAC_PHY_MODE_NONE:
570 /* No ports */
571 rgmiifer |= RGMII_FER_DIS << 0;
572 rgmiifer |= RGMII_FER_DIS << 4;
573 out_be32((void *)RGMII_FER, rgmiifer);
574 bis->bi_phymode[0] = BI_PHYMODE_NONE;
575 bis->bi_phymode[1] = BI_PHYMODE_NONE;
576 break;
577 case EMAC_PHY_MODE_NONE_RGMII:
578 /* 1 x RGMII port on channel 0 */
579 rgmiifer |= RGMII_FER_RGMII << 0;
580 rgmiifer |= RGMII_FER_DIS << 4;
581 out_be32((void *)RGMII_FER, rgmiifer);
582 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
583 bis->bi_phymode[1] = BI_PHYMODE_NONE;
584 break;
585 case EMAC_PHY_MODE_RGMII_NONE:
586 /* 1 x RGMII port on channel 1 */
587 rgmiifer |= RGMII_FER_DIS << 0;
588 rgmiifer |= RGMII_FER_RGMII << 4;
589 out_be32((void *)RGMII_FER, rgmiifer);
590 bis->bi_phymode[0] = BI_PHYMODE_NONE;
591 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
592 break;
593 case EMAC_PHY_MODE_RGMII_RGMII:
Stefan Roesedbbd1252007-10-05 17:10:59 +0200594 /* 2 x RGMII ports */
Grant Erickson1740c1b2008-07-08 08:35:00 -0700595 rgmiifer |= RGMII_FER_RGMII << 0;
596 rgmiifer |= RGMII_FER_RGMII << 4;
597 out_be32((void *)RGMII_FER, rgmiifer);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200598 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
599 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
600 break;
Grant Erickson1740c1b2008-07-08 08:35:00 -0700601 case EMAC_PHY_MODE_NONE_GMII:
602 /* 1 x GMII port on channel 0 */
603 rgmiifer |= RGMII_FER_GMII << 0;
604 rgmiifer |= RGMII_FER_DIS << 4;
605 out_be32((void *)RGMII_FER, rgmiifer);
606 bis->bi_phymode[0] = BI_PHYMODE_GMII;
607 bis->bi_phymode[1] = BI_PHYMODE_NONE;
608 break;
609 case EMAC_PHY_MODE_NONE_MII:
610 /* 1 x MII port on channel 0 */
611 rgmiifer |= RGMII_FER_MII << 0;
612 rgmiifer |= RGMII_FER_DIS << 4;
613 out_be32((void *)RGMII_FER, rgmiifer);
614 bis->bi_phymode[0] = BI_PHYMODE_MII;
615 bis->bi_phymode[1] = BI_PHYMODE_NONE;
616 break;
617 case EMAC_PHY_MODE_GMII_NONE:
618 /* 1 x GMII port on channel 1 */
619 rgmiifer |= RGMII_FER_DIS << 0;
620 rgmiifer |= RGMII_FER_GMII << 4;
621 out_be32((void *)RGMII_FER, rgmiifer);
622 bis->bi_phymode[0] = BI_PHYMODE_NONE;
623 bis->bi_phymode[1] = BI_PHYMODE_GMII;
624 break;
625 case EMAC_PHY_MODE_MII_NONE:
626 /* 1 x MII port on channel 1 */
627 rgmiifer |= RGMII_FER_DIS << 0;
628 rgmiifer |= RGMII_FER_MII << 4;
629 out_be32((void *)RGMII_FER, rgmiifer);
630 bis->bi_phymode[0] = BI_PHYMODE_NONE;
631 bis->bi_phymode[1] = BI_PHYMODE_MII;
Stefan Roesedbbd1252007-10-05 17:10:59 +0200632 break;
633 default:
634 break;
635 }
636
637 /* Ensure we setup mdio for this devnum and ONLY this devnum */
Grant Erickson1740c1b2008-07-08 08:35:00 -0700638 rgmiifer = in_be32((void *)RGMII_FER);
639 rgmiifer |= (1 << (19-devnum));
640 out_be32((void *)RGMII_FER, rgmiifer);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200641
642 return ((int)0x0);
643}
644#endif /* CONFIG_405EX */
645
Stefan Roese8ac41e32008-03-11 15:05:26 +0100646#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
647int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
648{
649 u32 eth_cfg;
650 u32 zmiifer; /* ZMII0_FER reg. */
651 u32 rmiifer; /* RGMII0_FER reg. Bridge 0 */
652 u32 rmiifer1; /* RGMII0_FER reg. Bridge 1 */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100653 int mode;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100654
655 zmiifer = 0;
656 rmiifer = 0;
657 rmiifer1 = 0;
658
Stefan Roese4c9e8552008-03-19 16:20:49 +0100659#if defined(CONFIG_460EX)
660 mode = 9;
Victor Gallardo78d78232008-09-04 23:49:36 -0700661 mfsdr(SDR0_ETH_CFG, eth_cfg);
662 if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
663 ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0))
664 mode = 11; /* config SGMII */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100665#else
666 mode = 10;
Victor Gallardo78d78232008-09-04 23:49:36 -0700667 mfsdr(SDR0_ETH_CFG, eth_cfg);
668 if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
669 ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0) &&
670 ((eth_cfg & SDR0_ETH_CFG_SGMII2_ENABLE) > 0))
671 mode = 12; /* config SGMII */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100672#endif
673
Stefan Roese8ac41e32008-03-11 15:05:26 +0100674 /* TODO:
675 * NOTE: 460GT has 2 RGMII bridge cores:
676 * emac0 ------ RGMII0_BASE
677 * |
678 * emac1 -----+
679 *
680 * emac2 ------ RGMII1_BASE
681 * |
682 * emac3 -----+
683 *
684 * 460EX has 1 RGMII bridge core:
685 * and RGMII1_BASE is disabled
686 * emac0 ------ RGMII0_BASE
687 * |
688 * emac1 -----+
689 */
690
691 /*
692 * Right now only 2*RGMII is supported. Please extend when needed.
693 * sr - 2008-02-19
Victor Gallardo78d78232008-09-04 23:49:36 -0700694 * Add SGMII support.
695 * vg - 2008-07-28
Stefan Roese8ac41e32008-03-11 15:05:26 +0100696 */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100697 switch (mode) {
Stefan Roese8ac41e32008-03-11 15:05:26 +0100698 case 1:
699 /* 1 MII - 460EX */
700 /* GMC0 EMAC4_0, ZMII Bridge */
701 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
702 bis->bi_phymode[0] = BI_PHYMODE_MII;
703 bis->bi_phymode[1] = BI_PHYMODE_NONE;
704 bis->bi_phymode[2] = BI_PHYMODE_NONE;
705 bis->bi_phymode[3] = BI_PHYMODE_NONE;
706 break;
707 case 2:
708 /* 2 MII - 460GT */
709 /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */
710 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
711 zmiifer |= ZMII_FER_MII << ZMII_FER_V(2);
712 bis->bi_phymode[0] = BI_PHYMODE_MII;
713 bis->bi_phymode[1] = BI_PHYMODE_NONE;
714 bis->bi_phymode[2] = BI_PHYMODE_MII;
715 bis->bi_phymode[3] = BI_PHYMODE_NONE;
716 break;
717 case 3:
718 /* 2 RMII - 460EX */
719 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
720 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
721 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
722 bis->bi_phymode[0] = BI_PHYMODE_RMII;
723 bis->bi_phymode[1] = BI_PHYMODE_RMII;
724 bis->bi_phymode[2] = BI_PHYMODE_NONE;
725 bis->bi_phymode[3] = BI_PHYMODE_NONE;
726 break;
727 case 4:
728 /* 4 RMII - 460GT */
729 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */
730 /* ZMII Bridge */
731 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
732 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
733 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
734 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
735 bis->bi_phymode[0] = BI_PHYMODE_RMII;
736 bis->bi_phymode[1] = BI_PHYMODE_RMII;
737 bis->bi_phymode[2] = BI_PHYMODE_RMII;
738 bis->bi_phymode[3] = BI_PHYMODE_RMII;
739 break;
740 case 5:
741 /* 2 SMII - 460EX */
742 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
743 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
744 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
745 bis->bi_phymode[0] = BI_PHYMODE_SMII;
746 bis->bi_phymode[1] = BI_PHYMODE_SMII;
747 bis->bi_phymode[2] = BI_PHYMODE_NONE;
748 bis->bi_phymode[3] = BI_PHYMODE_NONE;
749 break;
750 case 6:
751 /* 4 SMII - 460GT */
752 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */
753 /* ZMII Bridge */
754 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
755 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
756 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
757 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
758 bis->bi_phymode[0] = BI_PHYMODE_SMII;
759 bis->bi_phymode[1] = BI_PHYMODE_SMII;
760 bis->bi_phymode[2] = BI_PHYMODE_SMII;
761 bis->bi_phymode[3] = BI_PHYMODE_SMII;
762 break;
763 case 7:
764 /* This is the default mode that we want for board bringup - Maple */
765 /* 1 GMII - 460EX */
766 /* GMC0 EMAC4_0, RGMII Bridge 0 */
767 rmiifer |= RGMII_FER_MDIO(0);
768
769 if (devnum == 0) {
770 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
771 bis->bi_phymode[0] = BI_PHYMODE_GMII;
772 bis->bi_phymode[1] = BI_PHYMODE_NONE;
773 bis->bi_phymode[2] = BI_PHYMODE_NONE;
774 bis->bi_phymode[3] = BI_PHYMODE_NONE;
775 } else {
776 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3); /* CH1CFG - EMAC1 */
777 bis->bi_phymode[0] = BI_PHYMODE_NONE;
778 bis->bi_phymode[1] = BI_PHYMODE_GMII;
779 bis->bi_phymode[2] = BI_PHYMODE_NONE;
780 bis->bi_phymode[3] = BI_PHYMODE_NONE;
781 }
782 break;
783 case 8:
784 /* 2 GMII - 460GT */
785 /* GMC0 EMAC4_0, RGMII Bridge 0 */
786 /* GMC1 EMAC4_2, RGMII Bridge 1 */
787 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
788 rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC2 */
789 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
790 rmiifer1 |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC2 */
791
792 bis->bi_phymode[0] = BI_PHYMODE_GMII;
793 bis->bi_phymode[1] = BI_PHYMODE_NONE;
794 bis->bi_phymode[2] = BI_PHYMODE_GMII;
795 bis->bi_phymode[3] = BI_PHYMODE_NONE;
796 break;
797 case 9:
798 /* 2 RGMII - 460EX */
799 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
800 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
801 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
802 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
803
804 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
805 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
806 bis->bi_phymode[2] = BI_PHYMODE_NONE;
807 bis->bi_phymode[3] = BI_PHYMODE_NONE;
808 break;
809 case 10:
810 /* 4 RGMII - 460GT */
811 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
812 /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */
813 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
814 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
815 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2);
816 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3);
817 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
818 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
819 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
820 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
821 break;
Victor Gallardo78d78232008-09-04 23:49:36 -0700822 case 11:
823 /* 2 SGMII - 460EX */
824 bis->bi_phymode[0] = BI_PHYMODE_SGMII;
825 bis->bi_phymode[1] = BI_PHYMODE_SGMII;
826 bis->bi_phymode[2] = BI_PHYMODE_NONE;
827 bis->bi_phymode[3] = BI_PHYMODE_NONE;
828 break;
829 case 12:
830 /* 3 SGMII - 460GT */
831 bis->bi_phymode[0] = BI_PHYMODE_SGMII;
832 bis->bi_phymode[1] = BI_PHYMODE_SGMII;
833 bis->bi_phymode[2] = BI_PHYMODE_SGMII;
834 bis->bi_phymode[3] = BI_PHYMODE_NONE;
835 break;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100836 default:
837 break;
838 }
839
840 /* Set EMAC for MDIO */
841 mfsdr(SDR0_ETH_CFG, eth_cfg);
842 eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
843 mtsdr(SDR0_ETH_CFG, eth_cfg);
844
845 out_be32((void *)RGMII_FER, rmiifer);
846#if defined(CONFIG_460GT)
847 out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1);
848#endif
849
850 /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
851 mfsdr(SDR0_ETH_CFG, eth_cfg);
852 eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
853 mtsdr(SDR0_ETH_CFG, eth_cfg);
854
855 return 0;
856}
857#endif /* CONFIG_460EX || CONFIG_460GT */
858
Stefan Roeseff768cb2007-10-31 18:01:24 +0100859static inline void *malloc_aligned(u32 size, u32 align)
860{
861 return (void *)(((u32)malloc(size + align) + align - 1) &
862 ~(align - 1));
863}
864
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200865static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
wdenkba56f622004-02-06 23:19:44 +0000866{
Stefan Roeseff768cb2007-10-31 18:01:24 +0100867 int i;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200868 unsigned long reg = 0;
wdenkba56f622004-02-06 23:19:44 +0000869 unsigned long msr;
870 unsigned long speed;
871 unsigned long duplex;
872 unsigned long failsafe;
873 unsigned mode_reg;
874 unsigned short devnum;
875 unsigned short reg_short;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200876#if defined(CONFIG_440GX) || \
877 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200878 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100879 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200880 defined(CONFIG_405EX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200881 sys_info_t sysinfo;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200882#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200883 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100884 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200885 defined(CONFIG_405EX)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100886 int ethgroup = -1;
887#endif
Stefan Roesec157d8e2005-08-01 16:41:48 +0200888#endif
Stefan Roeseff768cb2007-10-31 18:01:24 +0100889 u32 bd_cached;
890 u32 bd_uncached = 0;
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +0100891#ifdef CONFIG_4xx_DCACHE
892 static u32 last_used_ea = 0;
893#endif
Stefan Roesee54ec0f2008-04-03 14:50:34 +0200894#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
895 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
896 defined(CONFIG_405EX)
897 int rgmii_channel;
898#endif
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200899
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200900 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +0000901
902 /* before doing anything, figure out if we have a MAC address */
903 /* if not, bail */
Stefan Roese4f92ac32005-10-10 17:43:58 +0200904 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
905 printf("ERROR: ethaddr not set!\n");
wdenkba56f622004-02-06 23:19:44 +0000906 return -1;
Stefan Roese4f92ac32005-10-10 17:43:58 +0200907 }
wdenkba56f622004-02-06 23:19:44 +0000908
Stefan Roese887e2ec2006-09-07 11:51:23 +0200909#if defined(CONFIG_440GX) || \
910 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200911 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100912 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200913 defined(CONFIG_405EX)
wdenkba56f622004-02-06 23:19:44 +0000914 /* Need to get the OPB frequency so we can access the PHY */
915 get_sys_info (&sysinfo);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200916#endif
wdenkba56f622004-02-06 23:19:44 +0000917
wdenkba56f622004-02-06 23:19:44 +0000918 msr = mfmsr ();
919 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
920
921 devnum = hw_p->devnum;
922
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200923#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +0000924 /* AS.HARNOIS
925 * We should have :
Wolfgang Denk265817c2005-09-25 00:53:22 +0200926 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
wdenkba56f622004-02-06 23:19:44 +0000927 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
928 * is possible that new packets (without relationship with
929 * current transfer) have got the time to arrived before
930 * netloop calls eth_halt
931 */
932 printf ("About preceeding transfer (eth%d):\n"
933 "- Sent packet number %d\n"
934 "- Received packet number %d\n"
935 "- Handled packet number %d\n",
936 hw_p->devnum,
937 hw_p->stats.pkts_tx,
938 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
939
940 hw_p->stats.pkts_tx = 0;
941 hw_p->stats.pkts_rx = 0;
942 hw_p->stats.pkts_handled = 0;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200943 hw_p->print_speed = 1; /* print speed message again next time */
wdenkba56f622004-02-06 23:19:44 +0000944#endif
945
Wolfgang Denk265817c2005-09-25 00:53:22 +0200946 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
947 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
wdenkba56f622004-02-06 23:19:44 +0000948
949 hw_p->rx_slot = 0; /* MAL Receive Slot */
950 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
951 hw_p->rx_u_index = 0; /* Receive User Queue Index */
952
953 hw_p->tx_slot = 0; /* MAL Transmit Slot */
954 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
955 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
956
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200957#if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
wdenkba56f622004-02-06 23:19:44 +0000958 /* set RMII mode */
959 /* NOTE: 440GX spec states that mode is mutually exclusive */
960 /* NOTE: Therefore, disable all other EMACS, since we handle */
961 /* NOTE: only one emac at a time */
962 reg = 0;
Stefan Roese2d834762007-10-23 14:03:17 +0200963 out_be32((void *)ZMII_FER, 0);
wdenkba56f622004-02-06 23:19:44 +0000964 udelay (100);
wdenkba56f622004-02-06 23:19:44 +0000965
Stefan Roese8ac41e32008-03-11 15:05:26 +0100966#if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese2d834762007-10-23 14:03:17 +0200967 out_be32((void *)ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
Stefan Roese8ac41e32008-03-11 15:05:26 +0100968#elif defined(CONFIG_440GX) || \
969 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
970 defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200971 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
wdenk0e6d7982004-03-14 00:07:33 +0000972#endif
Stefan Roesec57c7982005-08-11 17:56:56 +0200973
Stefan Roese2d834762007-10-23 14:03:17 +0200974 out_be32((void *)ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100975#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
Stefan Roesedbbd1252007-10-05 17:10:59 +0200976#if defined(CONFIG_405EX)
977 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
978#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200979
Stefan Roese8ac41e32008-03-11 15:05:26 +0100980 sync();
wdenk0e6d7982004-03-14 00:07:33 +0000981
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200982 /* provide clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100983 emac_loopback_enable(hw_p);
wdenk0e6d7982004-03-14 00:07:33 +0000984
Stefan Roese8ac41e32008-03-11 15:05:26 +0100985 /* EMAC RESET */
Stefan Roese2d834762007-10-23 14:03:17 +0200986 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenkba56f622004-02-06 23:19:44 +0000987
Stefan Roese8ac41e32008-03-11 15:05:26 +0100988 /* remove clocks for EMAC internal loopback */
989 emac_loopback_disable(hw_p);
990
wdenkba56f622004-02-06 23:19:44 +0000991 failsafe = 1000;
Stefan Roese2d834762007-10-23 14:03:17 +0200992 while ((in_be32((void *)EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
wdenkba56f622004-02-06 23:19:44 +0000993 udelay (1000);
994 failsafe--;
995 }
Stefan Roese887e2ec2006-09-07 11:51:23 +0200996 if (failsafe <= 0)
997 printf("\nProblem resetting EMAC!\n");
wdenkba56f622004-02-06 23:19:44 +0000998
Stefan Roese887e2ec2006-09-07 11:51:23 +0200999#if defined(CONFIG_440GX) || \
1000 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001001 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001002 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001003 defined(CONFIG_405EX)
wdenkba56f622004-02-06 23:19:44 +00001004 /* Whack the M1 register */
1005 mode_reg = 0x0;
1006 mode_reg &= ~0x00000038;
1007 if (sysinfo.freqOPB <= 50000000);
1008 else if (sysinfo.freqOPB <= 66666667)
1009 mode_reg |= EMAC_M1_OBCI_66;
1010 else if (sysinfo.freqOPB <= 83333333)
1011 mode_reg |= EMAC_M1_OBCI_83;
1012 else if (sysinfo.freqOPB <= 100000000)
1013 mode_reg |= EMAC_M1_OBCI_100;
1014 else
1015 mode_reg |= EMAC_M1_OBCI_GT100;
1016
Stefan Roese2d834762007-10-23 14:03:17 +02001017 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001018#endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
wdenkba56f622004-02-06 23:19:44 +00001019
Victor Gallardo78d78232008-09-04 23:49:36 -07001020#if defined(CONFIG_GPCS_PHY_ADDR) || defined(CONFIG_GPCS_PHY1_ADDR) || \
1021 defined(CONFIG_GPCS_PHY2_ADDR) || defined(CONFIG_GPCS_PHY3_ADDR)
1022 if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
1023 /*
1024 * In SGMII mode, GPCS access is needed for
1025 * communication with the internal SGMII SerDes.
1026 */
1027 switch (devnum) {
1028#if defined(CONFIG_GPCS_PHY_ADDR)
1029 case 0:
1030 reg = CONFIG_GPCS_PHY_ADDR;
1031 break;
1032#endif
1033#if defined(CONFIG_GPCS_PHY1_ADDR)
1034 case 1:
1035 reg = CONFIG_GPCS_PHY1_ADDR;
1036 break;
1037#endif
1038#if defined(CONFIG_GPCS_PHY2_ADDR)
1039 case 2:
1040 reg = CONFIG_GPCS_PHY2_ADDR;
1041 break;
1042#endif
1043#if defined(CONFIG_GPCS_PHY3_ADDR)
1044 case 3:
1045 reg = CONFIG_GPCS_PHY3_ADDR;
1046 break;
1047#endif
1048 }
1049
1050 mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr);
1051 mode_reg |= EMAC_M1_MF_1000GPCS | EMAC_M1_IPPA_SET(reg);
1052 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
1053
1054 /* Configure GPCS interface to recommended setting for SGMII */
1055 miiphy_reset(dev->name, reg);
1056 miiphy_write(dev->name, reg, 0x04, 0x8120); /* AsymPause, FDX */
1057 miiphy_write(dev->name, reg, 0x07, 0x2801); /* msg_pg, toggle */
1058 miiphy_write(dev->name, reg, 0x00, 0x0140); /* 1Gbps, FDX */
1059 }
1060#endif /* defined(CONFIG_GPCS_PHY_ADDR) */
1061
wdenkba56f622004-02-06 23:19:44 +00001062 /* wait for PHY to complete auto negotiation */
1063 reg_short = 0;
1064#ifndef CONFIG_CS8952_PHY
1065 switch (devnum) {
1066 case 0:
1067 reg = CONFIG_PHY_ADDR;
1068 break;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001069#if defined (CONFIG_PHY1_ADDR)
wdenkba56f622004-02-06 23:19:44 +00001070 case 1:
1071 reg = CONFIG_PHY1_ADDR;
1072 break;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001073#endif
Stefan Roese4c9e8552008-03-19 16:20:49 +01001074#if defined (CONFIG_PHY2_ADDR)
wdenkba56f622004-02-06 23:19:44 +00001075 case 2:
1076 reg = CONFIG_PHY2_ADDR;
1077 break;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001078#endif
1079#if defined (CONFIG_PHY3_ADDR)
wdenkba56f622004-02-06 23:19:44 +00001080 case 3:
1081 reg = CONFIG_PHY3_ADDR;
1082 break;
1083#endif
1084 default:
1085 reg = CONFIG_PHY_ADDR;
1086 break;
1087 }
1088
wdenk3c74e322004-02-22 23:46:08 +00001089 bis->bi_phynum[devnum] = reg;
1090
Victor Gallardo78d78232008-09-04 23:49:36 -07001091 if (reg == CONFIG_FIXED_PHY)
1092 goto get_speed;
1093
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001094#if defined(CONFIG_PHY_RESET)
wdenka06752e2004-09-29 22:43:59 +00001095 /*
1096 * Reset the phy, only if its the first time through
1097 * otherwise, just check the speeds & feeds
1098 */
1099 if (hw_p->first_init == 0) {
Stefan Roeseec0c2ec2006-11-27 14:46:06 +01001100#if defined(CONFIG_M88E1111_PHY)
Stefan Roese887e2ec2006-09-07 11:51:23 +02001101 miiphy_write (dev->name, reg, 0x14, 0x0ce3);
1102 miiphy_write (dev->name, reg, 0x18, 0x4101);
1103 miiphy_write (dev->name, reg, 0x09, 0x0e00);
1104 miiphy_write (dev->name, reg, 0x04, 0x01e1);
1105#endif
Victor Gallardo78d78232008-09-04 23:49:36 -07001106#if defined(CONFIG_M88E1112_PHY)
1107 if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
1108 /*
1109 * Marvell 88E1112 PHY needs to have the SGMII MAC
1110 * interace (page 2) properly configured to
1111 * communicate with the 460EX/GT GPCS interface.
1112 */
1113
1114 /* Set access to Page 2 */
1115 miiphy_write(dev->name, reg, 0x16, 0x0002);
1116
1117 miiphy_write(dev->name, reg, 0x00, 0x0040); /* 1Gbps */
1118 miiphy_read(dev->name, reg, 0x1a, &reg_short);
1119 reg_short |= 0x8000; /* bypass Auto-Negotiation */
1120 miiphy_write(dev->name, reg, 0x1a, reg_short);
1121 miiphy_reset(dev->name, reg); /* reset MAC interface */
1122
1123 /* Reset access to Page 0 */
1124 miiphy_write(dev->name, reg, 0x16, 0x0000);
1125 }
1126#endif /* defined(CONFIG_M88E1112_PHY) */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001127 miiphy_reset (dev->name, reg);
wdenkba56f622004-02-06 23:19:44 +00001128
Stefan Roese887e2ec2006-09-07 11:51:23 +02001129#if defined(CONFIG_440GX) || \
1130 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001131 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001132 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001133 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +02001134
wdenk0e6d7982004-03-14 00:07:33 +00001135#if defined(CONFIG_CIS8201_PHY)
wdenkfc1cfcd2004-04-25 15:41:35 +00001136 /*
Stefan Roese17f50f222005-08-04 17:09:16 +02001137 * Cicada 8201 PHY needs to have an extended register whacked
1138 * for RGMII mode.
wdenkfc1cfcd2004-04-25 15:41:35 +00001139 */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001140 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
Stefan Roeseb79316f2005-08-15 12:31:23 +02001141#if defined(CONFIG_CIS8201_SHORT_ETCH)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001142 miiphy_write (dev->name, reg, 23, 0x1300);
Stefan Roeseb79316f2005-08-15 12:31:23 +02001143#else
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001144 miiphy_write (dev->name, reg, 23, 0x1000);
Stefan Roeseb79316f2005-08-15 12:31:23 +02001145#endif
Stefan Roese17f50f222005-08-04 17:09:16 +02001146 /*
1147 * Vitesse VSC8201/Cicada CIS8201 errata:
1148 * Interoperability problem with Intel 82547EI phys
1149 * This work around (provided by Vitesse) changes
1150 * the default timer convergence from 8ms to 12ms
1151 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001152 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1153 miiphy_write (dev->name, reg, 0x08, 0x0200);
1154 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
1155 miiphy_write (dev->name, reg, 0x02, 0x0004);
1156 miiphy_write (dev->name, reg, 0x01, 0x0671);
1157 miiphy_write (dev->name, reg, 0x00, 0x8fae);
1158 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1159 miiphy_write (dev->name, reg, 0x08, 0x0000);
1160 miiphy_write (dev->name, reg, 0x1f, 0x0000);
Stefan Roese17f50f222005-08-04 17:09:16 +02001161 /* end Vitesse/Cicada errata */
1162 }
wdenk0e6d7982004-03-14 00:07:33 +00001163#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001164
1165#if defined(CONFIG_ET1011C_PHY)
1166 /*
1167 * Agere ET1011c PHY needs to have an extended register whacked
1168 * for RGMII mode.
1169 */
1170 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
1171 miiphy_read (dev->name, reg, 0x16, &reg_short);
1172 reg_short &= ~(0x7);
1173 reg_short |= 0x6; /* RGMII DLL Delay*/
1174 miiphy_write (dev->name, reg, 0x16, reg_short);
1175
1176 miiphy_read (dev->name, reg, 0x17, &reg_short);
1177 reg_short &= ~(0x40);
1178 miiphy_write (dev->name, reg, 0x17, reg_short);
1179
1180 miiphy_write(dev->name, reg, 0x1c, 0x74f0);
1181 }
1182#endif
1183
wdenk855a4962004-03-14 18:23:55 +00001184#endif
wdenka06752e2004-09-29 22:43:59 +00001185 /* Start/Restart autonegotiation */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001186 phy_setup_aneg (dev->name, reg);
wdenka06752e2004-09-29 22:43:59 +00001187 udelay (1000);
1188 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001189#endif /* defined(CONFIG_PHY_RESET) */
wdenkba56f622004-02-06 23:19:44 +00001190
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001191 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenkba56f622004-02-06 23:19:44 +00001192
1193 /*
wdenk0e6d7982004-03-14 00:07:33 +00001194 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
wdenkba56f622004-02-06 23:19:44 +00001195 */
1196 if ((reg_short & PHY_BMSR_AUTN_ABLE)
1197 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
1198 puts ("Waiting for PHY auto negotiation to complete");
1199 i = 0;
1200 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
1201 /*
1202 * Timeout reached ?
1203 */
1204 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
1205 puts (" TIMEOUT !\n");
1206 break;
1207 }
1208
1209 if ((i++ % 1000) == 0) {
1210 putc ('.');
1211 }
1212 udelay (1000); /* 1 ms */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001213 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenkba56f622004-02-06 23:19:44 +00001214
1215 }
1216 puts (" done\n");
1217 udelay (500000); /* another 500 ms (results in faster booting) */
1218 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001219#endif /* #ifndef CONFIG_CS8952_PHY */
1220
Victor Gallardo78d78232008-09-04 23:49:36 -07001221get_speed:
1222 if (reg == CONFIG_FIXED_PHY) {
1223 for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) {
1224 if (devnum == fixed_phy_port[i].devnum) {
1225 speed = fixed_phy_port[i].speed;
1226 duplex = fixed_phy_port[i].duplex;
1227 break;
1228 }
1229 }
1230
1231 if (i == ARRAY_SIZE(fixed_phy_port)) {
1232 printf("ERROR: PHY (%s) not configured correctly!\n",
1233 dev->name);
1234 return -1;
1235 }
1236 } else {
1237 speed = miiphy_speed(dev->name, reg);
1238 duplex = miiphy_duplex(dev->name, reg);
1239 }
wdenkba56f622004-02-06 23:19:44 +00001240
1241 if (hw_p->print_speed) {
1242 hw_p->print_speed = 0;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001243 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
1244 (int) speed, (duplex == HALF) ? "HALF" : "FULL",
1245 hw_p->devnum);
wdenkba56f622004-02-06 23:19:44 +00001246 }
1247
Stefan Roese8ac41e32008-03-11 15:05:26 +01001248#if defined(CONFIG_440) && \
1249 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
1250 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
1251 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
Stefan Roese846b0dd2005-08-08 12:42:22 +02001252#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001253 mfsdr(sdr_mfr, reg);
1254 if (speed == 100) {
1255 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
1256 } else {
1257 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
1258 }
1259 mtsdr(sdr_mfr, reg);
1260#endif
Stefan Roesec57c7982005-08-11 17:56:56 +02001261
wdenkba56f622004-02-06 23:19:44 +00001262 /* Set ZMII/RGMII speed according to the phy link speed */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001263 reg = in_be32((void *)ZMII_SSR);
wdenk855a4962004-03-14 18:23:55 +00001264 if ( (speed == 100) || (speed == 1000) )
Stefan Roeseff768cb2007-10-31 18:01:24 +01001265 out_be32((void *)ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
wdenkba56f622004-02-06 23:19:44 +00001266 else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001267 out_be32((void *)ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
wdenkba56f622004-02-06 23:19:44 +00001268
1269 if ((devnum == 2) || (devnum == 3)) {
1270 if (speed == 1000)
1271 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1272 else if (speed == 100)
1273 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001274 else if (speed == 10)
wdenkba56f622004-02-06 23:19:44 +00001275 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001276 else {
1277 printf("Error in RGMII Speed\n");
1278 return -1;
1279 }
Stefan Roeseff768cb2007-10-31 18:01:24 +01001280 out_be32((void *)RGMII_SSR, reg);
wdenkba56f622004-02-06 23:19:44 +00001281 }
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001282#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
wdenkba56f622004-02-06 23:19:44 +00001283
Stefan Roesedbbd1252007-10-05 17:10:59 +02001284#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001285 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001286 defined(CONFIG_405EX)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001287 if (devnum >= 2)
1288 rgmii_channel = devnum - 2;
1289 else
1290 rgmii_channel = devnum;
1291
Stefan Roese887e2ec2006-09-07 11:51:23 +02001292 if (speed == 1000)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001293 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001294 else if (speed == 100)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001295 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001296 else if (speed == 10)
Stefan Roesee54ec0f2008-04-03 14:50:34 +02001297 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V(rgmii_channel));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001298 else {
1299 printf("Error in RGMII Speed\n");
1300 return -1;
1301 }
Stefan Roese2d834762007-10-23 14:03:17 +02001302 out_be32((void *)RGMII_SSR, reg);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001303#if defined(CONFIG_460GT)
1304 if ((devnum == 2) || (devnum == 3))
1305 out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
1306#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +02001307#endif
1308
wdenkba56f622004-02-06 23:19:44 +00001309 /* set the Mal configuration reg */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001310#if defined(CONFIG_440GX) || \
1311 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001312 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001313 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001314 defined(CONFIG_405EX)
Stefan Roese17f50f222005-08-04 17:09:16 +02001315 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
1316 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
1317#else
1318 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
wdenkba56f622004-02-06 23:19:44 +00001319 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
Stefan Roese17f50f222005-08-04 17:09:16 +02001320 if (get_pvr() == PVR_440GP_RB) {
1321 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
1322 }
1323#endif
wdenkba56f622004-02-06 23:19:44 +00001324
wdenkba56f622004-02-06 23:19:44 +00001325 /*
1326 * Malloc MAL buffer desciptors, make sure they are
1327 * aligned on cache line boundary size
1328 * (401/403/IOP480 = 16, 405 = 32)
1329 * and doesn't cross cache block boundaries.
1330 */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001331 if (hw_p->first_init == 0) {
1332 debug("*** Allocating descriptor memory ***\n");
wdenkba56f622004-02-06 23:19:44 +00001333
Stefan Roeseff768cb2007-10-31 18:01:24 +01001334 bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
1335 if (!bd_cached) {
Stefan Roeseb0021442008-07-10 09:58:06 +02001336 printf("%s: Error allocating MAL descriptor buffers!\n", __func__);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001337 return -1;
1338 }
Stefan Roeseb79316f2005-08-15 12:31:23 +02001339
Stefan Roeseff768cb2007-10-31 18:01:24 +01001340#ifdef CONFIG_4xx_DCACHE
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001341 flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001342 if (!last_used_ea)
Anatolij Gustschin5e3dca52008-04-17 18:18:00 +02001343#if defined(CFG_MEM_TOP_HIDE)
1344 bd_uncached = bis->bi_memsize + CFG_MEM_TOP_HIDE;
1345#else
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001346 bd_uncached = bis->bi_memsize;
Anatolij Gustschin5e3dca52008-04-17 18:18:00 +02001347#endif
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001348 else
1349 bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
1350
1351 last_used_ea = bd_uncached;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001352 program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
1353 TLB_WORD2_I_ENABLE);
1354#else
1355 bd_uncached = bd_cached;
1356#endif
1357 hw_p->tx_phys = bd_cached;
1358 hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
1359 hw_p->tx = (mal_desc_t *)(bd_uncached);
1360 hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
1361 debug("hw_p->tx=%08x, hw_p->rx=%08x\n", hw_p->tx, hw_p->rx);
wdenkba56f622004-02-06 23:19:44 +00001362 }
1363
1364 for (i = 0; i < NUM_TX_BUFF; i++) {
1365 hw_p->tx[i].ctrl = 0;
1366 hw_p->tx[i].data_len = 0;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001367 if (hw_p->first_init == 0)
1368 hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
1369 L1_CACHE_BYTES);
wdenkba56f622004-02-06 23:19:44 +00001370 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
1371 if ((NUM_TX_BUFF - 1) == i)
1372 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
1373 hw_p->tx_run[i] = -1;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001374 debug("TX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->tx[i].data_ptr);
wdenkba56f622004-02-06 23:19:44 +00001375 }
1376
1377 for (i = 0; i < NUM_RX_BUFF; i++) {
1378 hw_p->rx[i].ctrl = 0;
1379 hw_p->rx[i].data_len = 0;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001380 hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
wdenkba56f622004-02-06 23:19:44 +00001381 if ((NUM_RX_BUFF - 1) == i)
1382 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
1383 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
1384 hw_p->rx_ready[i] = -1;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001385 debug("RX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->rx[i].data_ptr);
wdenkba56f622004-02-06 23:19:44 +00001386 }
1387
1388 reg = 0x00000000;
1389
1390 reg |= dev->enetaddr[0]; /* set high address */
1391 reg = reg << 8;
1392 reg |= dev->enetaddr[1];
1393
Stefan Roese2d834762007-10-23 14:03:17 +02001394 out_be32((void *)EMAC_IAH + hw_p->hw_addr, reg);
wdenkba56f622004-02-06 23:19:44 +00001395
1396 reg = 0x00000000;
1397 reg |= dev->enetaddr[2]; /* set low address */
1398 reg = reg << 8;
1399 reg |= dev->enetaddr[3];
1400 reg = reg << 8;
1401 reg |= dev->enetaddr[4];
1402 reg = reg << 8;
1403 reg |= dev->enetaddr[5];
1404
Stefan Roese2d834762007-10-23 14:03:17 +02001405 out_be32((void *)EMAC_IAL + hw_p->hw_addr, reg);
wdenkba56f622004-02-06 23:19:44 +00001406
1407 switch (devnum) {
1408 case 1:
1409 /* setup MAL tx & rx channel pointers */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001410#if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
Stefan Roeseff768cb2007-10-31 18:01:24 +01001411 mtdcr (maltxctp2r, hw_p->tx_phys);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001412#else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001413 mtdcr (maltxctp1r, hw_p->tx_phys);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001414#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001415#if defined(CONFIG_440)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001416 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001417 mtdcr (malrxbattr, 0x0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001418#endif
Stefan Roese8ac41e32008-03-11 15:05:26 +01001419
1420#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roese4c9e8552008-03-19 16:20:49 +01001421 mtdcr (malrxctp8r, hw_p->rx_phys);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001422 /* set RX buffer size */
1423 mtdcr (malrcbs8, ENET_MAX_MTU_ALIGNED / 16);
1424#else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001425 mtdcr (malrxctp1r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001426 /* set RX buffer size */
1427 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001428#endif
wdenkba56f622004-02-06 23:19:44 +00001429 break;
Stefan Roese846b0dd2005-08-08 12:42:22 +02001430#if defined (CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001431 case 2:
1432 /* setup MAL tx & rx channel pointers */
1433 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001434 mtdcr (malrxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001435 mtdcr (maltxctp2r, hw_p->tx_phys);
1436 mtdcr (malrxctp2r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001437 /* set RX buffer size */
1438 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
1439 break;
1440 case 3:
1441 /* setup MAL tx & rx channel pointers */
1442 mtdcr (maltxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001443 mtdcr (maltxctp3r, hw_p->tx_phys);
wdenkba56f622004-02-06 23:19:44 +00001444 mtdcr (malrxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001445 mtdcr (malrxctp3r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001446 /* set RX buffer size */
1447 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
1448 break;
Stefan Roesec57c7982005-08-11 17:56:56 +02001449#endif /* CONFIG_440GX */
Stefan Roese4c9e8552008-03-19 16:20:49 +01001450#if defined (CONFIG_460GT)
1451 case 2:
1452 /* setup MAL tx & rx channel pointers */
1453 mtdcr (maltxbattr, 0x0);
1454 mtdcr (malrxbattr, 0x0);
1455 mtdcr (maltxctp2r, hw_p->tx_phys);
1456 mtdcr (malrxctp16r, hw_p->rx_phys);
1457 /* set RX buffer size */
1458 mtdcr (malrcbs16, ENET_MAX_MTU_ALIGNED / 16);
1459 break;
1460 case 3:
1461 /* setup MAL tx & rx channel pointers */
1462 mtdcr (maltxbattr, 0x0);
1463 mtdcr (malrxbattr, 0x0);
1464 mtdcr (maltxctp3r, hw_p->tx_phys);
1465 mtdcr (malrxctp24r, hw_p->rx_phys);
1466 /* set RX buffer size */
1467 mtdcr (malrcbs24, ENET_MAX_MTU_ALIGNED / 16);
1468 break;
1469#endif /* CONFIG_460GT */
wdenkba56f622004-02-06 23:19:44 +00001470 case 0:
1471 default:
1472 /* setup MAL tx & rx channel pointers */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001473#if defined(CONFIG_440)
wdenkba56f622004-02-06 23:19:44 +00001474 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001475 mtdcr (malrxbattr, 0x0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001476#endif
Stefan Roeseff768cb2007-10-31 18:01:24 +01001477 mtdcr (maltxctp0r, hw_p->tx_phys);
1478 mtdcr (malrxctp0r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001479 /* set RX buffer size */
1480 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
1481 break;
1482 }
1483
1484 /* Enable MAL transmit and receive channels */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001485#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001486 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
1487#else
wdenkba56f622004-02-06 23:19:44 +00001488 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
Stefan Roesec157d8e2005-08-01 16:41:48 +02001489#endif
wdenkba56f622004-02-06 23:19:44 +00001490 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
1491
1492 /* set transmit enable & receive enable */
Stefan Roese2d834762007-10-23 14:03:17 +02001493 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
wdenkba56f622004-02-06 23:19:44 +00001494
Stefan Roese2d834762007-10-23 14:03:17 +02001495 mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr);
Stefan Roese76957cb2008-03-01 12:11:40 +01001496
1497 /* set rx-/tx-fifo size */
1498 mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
wdenkba56f622004-02-06 23:19:44 +00001499
1500 /* set speed */
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001501 if (speed == _1000BASET) {
Stefan Roese738815c2007-10-02 11:44:46 +02001502#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1503 defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001504 unsigned long pfc1;
Stefan Roese887e2ec2006-09-07 11:51:23 +02001505
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001506 mfsdr (sdr_pfc1, pfc1);
1507 pfc1 |= SDR0_PFC1_EM_1000;
1508 mtsdr (sdr_pfc1, pfc1);
1509#endif
wdenk855a4962004-03-14 18:23:55 +00001510 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001511 } else if (speed == _100BASET)
wdenkba56f622004-02-06 23:19:44 +00001512 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
1513 else
1514 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
1515 if (duplex == FULL)
1516 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
1517
Stefan Roese2d834762007-10-23 14:03:17 +02001518 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
wdenkba56f622004-02-06 23:19:44 +00001519
1520 /* Enable broadcast and indvidual address */
1521 /* TBS: enabling runts as some misbehaved nics will send runts */
Stefan Roese2d834762007-10-23 14:03:17 +02001522 out_be32((void *)EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
wdenkba56f622004-02-06 23:19:44 +00001523
1524 /* we probably need to set the tx mode1 reg? maybe at tx time */
1525
1526 /* set transmit request threshold register */
Stefan Roese2d834762007-10-23 14:03:17 +02001527 out_be32((void *)EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
wdenkba56f622004-02-06 23:19:44 +00001528
Wolfgang Denk265817c2005-09-25 00:53:22 +02001529 /* set receive low/high water mark register */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001530#if defined(CONFIG_440)
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001531 /* 440s has a 64 byte burst length */
Stefan Roese2d834762007-10-23 14:03:17 +02001532 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001533#else
1534 /* 405s have a 16 byte burst length */
Stefan Roese2d834762007-10-23 14:03:17 +02001535 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001536#endif /* defined(CONFIG_440) */
Stefan Roese2d834762007-10-23 14:03:17 +02001537 out_be32((void *)EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
wdenkba56f622004-02-06 23:19:44 +00001538
1539 /* Set fifo limit entry in tx mode 0 */
Stefan Roese2d834762007-10-23 14:03:17 +02001540 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
wdenkba56f622004-02-06 23:19:44 +00001541 /* Frame gap set */
Stefan Roese2d834762007-10-23 14:03:17 +02001542 out_be32((void *)EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
wdenkba56f622004-02-06 23:19:44 +00001543
1544 /* Set EMAC IER */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001545 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
wdenkba56f622004-02-06 23:19:44 +00001546 if (speed == _100BASET)
1547 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1548
Stefan Roese2d834762007-10-23 14:03:17 +02001549 out_be32((void *)EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
1550 out_be32((void *)EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
wdenkba56f622004-02-06 23:19:44 +00001551
1552 if (hw_p->first_init == 0) {
1553 /*
1554 * Connect interrupt service routines
1555 */
Stefan Roesedbbd1252007-10-05 17:10:59 +02001556 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1557 (interrupt_handler_t *) enetInt, dev);
wdenkba56f622004-02-06 23:19:44 +00001558 }
wdenkba56f622004-02-06 23:19:44 +00001559
1560 mtmsr (msr); /* enable interrupts again */
1561
1562 hw_p->bis = bis;
1563 hw_p->first_init = 1;
1564
Stefan Roese802b7692008-01-08 18:39:30 +01001565 return 0;
wdenkba56f622004-02-06 23:19:44 +00001566}
1567
1568
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001569static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
wdenkba56f622004-02-06 23:19:44 +00001570 int len)
1571{
1572 struct enet_frame *ef_ptr;
1573 ulong time_start, time_now;
1574 unsigned long temp_txm0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001575 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001576
1577 ef_ptr = (struct enet_frame *) ptr;
1578
1579 /*-----------------------------------------------------------------------+
1580 * Copy in our address into the frame.
1581 *-----------------------------------------------------------------------*/
1582 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1583
1584 /*-----------------------------------------------------------------------+
1585 * If frame is too long or too short, modify length.
1586 *-----------------------------------------------------------------------*/
1587 /* TBS: where does the fragment go???? */
1588 if (len > ENET_MAX_MTU)
1589 len = ENET_MAX_MTU;
1590
1591 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1592 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001593 flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
wdenkba56f622004-02-06 23:19:44 +00001594
1595 /*-----------------------------------------------------------------------+
1596 * set TX Buffer busy, and send it
1597 *-----------------------------------------------------------------------*/
1598 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1599 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1600 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1601 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1602 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1603
1604 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1605 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1606
Stefan Roese8ac41e32008-03-11 15:05:26 +01001607 sync();
wdenkba56f622004-02-06 23:19:44 +00001608
Stefan Roese2d834762007-10-23 14:03:17 +02001609 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr,
1610 in_be32((void *)EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001611#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001612 hw_p->stats.pkts_tx++;
1613#endif
1614
1615 /*-----------------------------------------------------------------------+
1616 * poll unitl the packet is sent and then make sure it is OK
1617 *-----------------------------------------------------------------------*/
1618 time_start = get_timer (0);
1619 while (1) {
Stefan Roese2d834762007-10-23 14:03:17 +02001620 temp_txm0 = in_be32((void *)EMAC_TXM0 + hw_p->hw_addr);
wdenkba56f622004-02-06 23:19:44 +00001621 /* loop until either TINT turns on or 3 seconds elapse */
1622 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
1623 /* transmit is done, so now check for errors
1624 * If there is an error, an interrupt should
1625 * happen when we return
1626 */
1627 time_now = get_timer (0);
1628 if ((time_now - time_start) > 3000) {
1629 return (-1);
1630 }
1631 } else {
1632 return (len);
1633 }
1634 }
1635}
1636
wdenkba56f622004-02-06 23:19:44 +00001637int enetInt (struct eth_device *dev)
1638{
1639 int serviced;
1640 int rc = -1; /* default to not us */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001641 u32 mal_isr;
1642 u32 emac_isr = 0;
1643 u32 mal_eob;
1644 u32 uic_mal;
1645 u32 uic_mal_err;
1646 u32 uic_emac;
1647 u32 uic_emac_b;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001648 EMAC_4XX_HW_PST hw_p;
wdenkba56f622004-02-06 23:19:44 +00001649
1650 /*
1651 * Because the mal is generic, we need to get the current
1652 * eth device
1653 */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001654#if defined(CONFIG_NET_MULTI)
1655 dev = eth_get_dev();
1656#else
1657 dev = emac0_dev;
1658#endif
wdenkba56f622004-02-06 23:19:44 +00001659
1660 hw_p = dev->priv;
1661
wdenkba56f622004-02-06 23:19:44 +00001662 /* enter loop that stays in interrupt code until nothing to service */
1663 do {
1664 serviced = 0;
1665
Stefan Roesed1631fe2008-06-26 13:40:57 +02001666 uic_mal = mfdcr(UIC_BASE_MAL + UIC_MSR);
1667 uic_mal_err = mfdcr(UIC_BASE_MAL_ERR + UIC_MSR);
1668 uic_emac = mfdcr(UIC_BASE_EMAC + UIC_MSR);
1669 uic_emac_b = mfdcr(UIC_BASE_EMAC_B + UIC_MSR);
Stefan Roese887e2ec2006-09-07 11:51:23 +02001670
Stefan Roesed1631fe2008-06-26 13:40:57 +02001671 if (!(uic_mal & (UIC_MAL_RXEOB | UIC_MAL_TXEOB))
1672 && !(uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE))
1673 && !(uic_emac & UIC_ETHx) && !(uic_emac_b & UIC_ETHxB)) {
wdenkba56f622004-02-06 23:19:44 +00001674 /* not for us */
1675 return (rc);
1676 }
Stefan Roesed1631fe2008-06-26 13:40:57 +02001677
wdenkba56f622004-02-06 23:19:44 +00001678 /* get and clear controller status interrupts */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001679 /* look at MAL and EMAC error interrupts */
1680 if (uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) {
1681 /* we have a MAL error interrupt */
1682 mal_isr = mfdcr(malesr);
1683 mal_err(dev, mal_isr, uic_mal_err,
1684 MAL_UIC_DEF, MAL_UIC_ERR);
1685
1686 /* clear MAL error interrupt status bits */
1687 mtdcr(UIC_BASE_MAL_ERR + UIC_SR,
1688 UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE);
1689
1690 return -1;
wdenkba56f622004-02-06 23:19:44 +00001691 }
1692
Stefan Roesed1631fe2008-06-26 13:40:57 +02001693 /* look for EMAC errors */
1694 if ((uic_emac & UIC_ETHx) || (uic_emac_b & UIC_ETHxB)) {
1695 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
1696 emac_err(dev, emac_isr);
wdenkba56f622004-02-06 23:19:44 +00001697
Stefan Roesed1631fe2008-06-26 13:40:57 +02001698 /* clear EMAC error interrupt status bits */
1699 mtdcr(UIC_BASE_EMAC + UIC_SR, UIC_ETHx);
1700 mtdcr(UIC_BASE_EMAC_B + UIC_SR, UIC_ETHxB);
wdenkba56f622004-02-06 23:19:44 +00001701
Stefan Roesed1631fe2008-06-26 13:40:57 +02001702 return -1;
wdenkba56f622004-02-06 23:19:44 +00001703 }
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001704
wdenkba56f622004-02-06 23:19:44 +00001705 /* handle MAX TX EOB interrupt from a tx */
Stefan Roesed1631fe2008-06-26 13:40:57 +02001706 if (uic_mal & UIC_MAL_TXEOB) {
1707 /* clear MAL interrupt status bits */
1708 mal_eob = mfdcr(maltxeobisr);
1709 mtdcr(maltxeobisr, mal_eob);
1710 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_TXEOB);
1711
1712 /* indicate that we serviced an interrupt */
1713 serviced = 1;
1714 rc = 0;
wdenkba56f622004-02-06 23:19:44 +00001715 }
Stefan Roesed1631fe2008-06-26 13:40:57 +02001716
1717 /* handle MAL RX EOB interupt from a receive */
1718 /* check for EOB on valid channels */
1719 if (uic_mal & UIC_MAL_RXEOB) {
1720 mal_eob = mfdcr(malrxeobisr);
1721 if (mal_eob &
1722 (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL))) {
1723 /* push packet to upper layer */
1724 enet_rcv(dev, emac_isr);
1725
1726 /* clear MAL interrupt status bits */
1727 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_RXEOB);
1728
wdenkba56f622004-02-06 23:19:44 +00001729 /* indicate that we serviced an interrupt */
1730 serviced = 1;
1731 rc = 0;
1732 }
1733 }
wdenkba56f622004-02-06 23:19:44 +00001734 } while (serviced);
1735
1736 return (rc);
1737}
1738
1739/*-----------------------------------------------------------------------------+
1740 * MAL Error Routine
1741 *-----------------------------------------------------------------------------*/
1742static void mal_err (struct eth_device *dev, unsigned long isr,
1743 unsigned long uic, unsigned long maldef,
1744 unsigned long mal_errr)
1745{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001746 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001747
1748 mtdcr (malesr, isr); /* clear interrupt */
1749
1750 /* clear DE interrupt */
1751 mtdcr (maltxdeir, 0xC0000000);
1752 mtdcr (malrxdeir, 0x80000000);
1753
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001754#ifdef INFO_4XX_ENET
Wolfgang Denk265817c2005-09-25 00:53:22 +02001755 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 +00001756#endif
1757
1758 eth_init (hw_p->bis); /* start again... */
1759}
1760
1761/*-----------------------------------------------------------------------------+
1762 * EMAC Error Routine
1763 *-----------------------------------------------------------------------------*/
1764static void emac_err (struct eth_device *dev, unsigned long isr)
1765{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001766 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001767
1768 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
Stefan Roese2d834762007-10-23 14:03:17 +02001769 out_be32((void *)EMAC_ISR + hw_p->hw_addr, isr);
wdenkba56f622004-02-06 23:19:44 +00001770}
1771
1772/*-----------------------------------------------------------------------------+
1773 * enet_rcv() handles the ethernet receive data
1774 *-----------------------------------------------------------------------------*/
1775static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1776{
1777 struct enet_frame *ef_ptr;
1778 unsigned long data_len;
1779 unsigned long rx_eob_isr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001780 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001781
1782 int handled = 0;
1783 int i;
1784 int loop_count = 0;
1785
1786 rx_eob_isr = mfdcr (malrxeobisr);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001787 if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
wdenkba56f622004-02-06 23:19:44 +00001788 /* clear EOB */
1789 mtdcr (malrxeobisr, rx_eob_isr);
1790
1791 /* EMAC RX done */
1792 while (1) { /* do all */
1793 i = hw_p->rx_slot;
1794
1795 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1796 || (loop_count >= NUM_RX_BUFF))
1797 break;
Stefan Roesea2e1c702007-07-12 16:32:08 +02001798
wdenkba56f622004-02-06 23:19:44 +00001799 loop_count++;
wdenkba56f622004-02-06 23:19:44 +00001800 handled++;
Stefan Roese8ac41e32008-03-11 15:05:26 +01001801 data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */
wdenkba56f622004-02-06 23:19:44 +00001802 if (data_len) {
1803 if (data_len > ENET_MAX_MTU) /* Check len */
1804 data_len = 0;
1805 else {
1806 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1807 data_len = 0;
1808 hw_p->stats.rx_err_log[hw_p->
1809 rx_err_index]
1810 = hw_p->rx[i].ctrl;
1811 hw_p->rx_err_index++;
1812 if (hw_p->rx_err_index ==
1813 MAX_ERR_LOG)
1814 hw_p->rx_err_index =
1815 0;
wdenkfc1cfcd2004-04-25 15:41:35 +00001816 } /* emac_erros */
wdenkba56f622004-02-06 23:19:44 +00001817 } /* data_len < max mtu */
wdenkfc1cfcd2004-04-25 15:41:35 +00001818 } /* if data_len */
wdenkba56f622004-02-06 23:19:44 +00001819 if (!data_len) { /* no data */
1820 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1821
1822 hw_p->stats.data_len_err++; /* Error at Rx */
1823 }
1824
1825 /* !data_len */
1826 /* AS.HARNOIS */
1827 /* Check if user has already eaten buffer */
1828 /* if not => ERROR */
1829 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1830 if (hw_p->is_receiving)
1831 printf ("ERROR : Receive buffers are full!\n");
1832 break;
1833 } else {
1834 hw_p->stats.rx_frames++;
1835 hw_p->stats.rx += data_len;
1836 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1837 data_ptr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001838#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001839 hw_p->stats.pkts_rx++;
1840#endif
1841 /* AS.HARNOIS
1842 * use ring buffer
1843 */
1844 hw_p->rx_ready[hw_p->rx_i_index] = i;
1845 hw_p->rx_i_index++;
1846 if (NUM_RX_BUFF == hw_p->rx_i_index)
1847 hw_p->rx_i_index = 0;
1848
Stefan Roesea2e1c702007-07-12 16:32:08 +02001849 hw_p->rx_slot++;
1850 if (NUM_RX_BUFF == hw_p->rx_slot)
1851 hw_p->rx_slot = 0;
1852
wdenkba56f622004-02-06 23:19:44 +00001853 /* AS.HARNOIS
1854 * free receive buffer only when
1855 * buffer has been handled (eth_rx)
1856 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1857 */
1858 } /* if data_len */
1859 } /* while */
1860 } /* if EMACK_RXCHL */
1861}
1862
1863
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001864static int ppc_4xx_eth_rx (struct eth_device *dev)
wdenkba56f622004-02-06 23:19:44 +00001865{
1866 int length;
1867 int user_index;
1868 unsigned long msr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001869 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001870
Wolfgang Denk265817c2005-09-25 00:53:22 +02001871 hw_p->is_receiving = 1; /* tell driver */
wdenkba56f622004-02-06 23:19:44 +00001872
1873 for (;;) {
1874 /* AS.HARNOIS
1875 * use ring buffer and
1876 * get index from rx buffer desciptor queue
1877 */
1878 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1879 if (user_index == -1) {
1880 length = -1;
1881 break; /* nothing received - leave for() loop */
1882 }
1883
1884 msr = mfmsr ();
1885 mtmsr (msr & ~(MSR_EE));
1886
Stefan Roese8ac41e32008-03-11 15:05:26 +01001887 length = hw_p->rx[user_index].data_len & 0x0fff;
wdenkba56f622004-02-06 23:19:44 +00001888
1889 /* Pass the packet up to the protocol layers. */
Wolfgang Denk265817c2005-09-25 00:53:22 +02001890 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1891 /* NetReceive(NetRxPackets[i], length); */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001892 invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
1893 (u32)hw_p->rx[user_index].data_ptr +
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001894 length - 4);
wdenkba56f622004-02-06 23:19:44 +00001895 NetReceive (NetRxPackets[user_index], length - 4);
1896 /* Free Recv Buffer */
1897 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1898 /* Free rx buffer descriptor queue */
1899 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1900 hw_p->rx_u_index++;
1901 if (NUM_RX_BUFF == hw_p->rx_u_index)
1902 hw_p->rx_u_index = 0;
1903
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001904#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001905 hw_p->stats.pkts_handled++;
1906#endif
1907
1908 mtmsr (msr); /* Enable IRQ's */
1909 }
1910
Wolfgang Denk265817c2005-09-25 00:53:22 +02001911 hw_p->is_receiving = 0; /* tell driver */
wdenkba56f622004-02-06 23:19:44 +00001912
1913 return length;
1914}
1915
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001916int ppc_4xx_eth_initialize (bd_t * bis)
wdenkba56f622004-02-06 23:19:44 +00001917{
1918 static int virgin = 0;
wdenkba56f622004-02-06 23:19:44 +00001919 struct eth_device *dev;
1920 int eth_num = 0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001921 EMAC_4XX_HW_PST hw = NULL;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001922 u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1923 u32 hw_addr[4];
Stefan Roesed1631fe2008-06-26 13:40:57 +02001924 u32 mal_ier;
wdenkba56f622004-02-06 23:19:44 +00001925
Stefan Roese846b0dd2005-08-08 12:42:22 +02001926#if defined(CONFIG_440GX)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001927 unsigned long pfc1;
1928
wdenkba56f622004-02-06 23:19:44 +00001929 mfsdr (sdr_pfc1, pfc1);
1930 pfc1 &= ~(0x01e00000);
1931 pfc1 |= 0x01200000;
1932 mtsdr (sdr_pfc1, pfc1);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001933#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001934
1935 /* first clear all mac-addresses */
1936 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1937 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
1938
1939 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1940 switch (eth_num) {
1941 default: /* fall through */
1942 case 0:
1943 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1944 bis->bi_enetaddr, 6);
1945 hw_addr[eth_num] = 0x0;
1946 break;
1947#ifdef CONFIG_HAS_ETH1
1948 case 1:
1949 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1950 bis->bi_enet1addr, 6);
1951 hw_addr[eth_num] = 0x100;
1952 break;
1953#endif
1954#ifdef CONFIG_HAS_ETH2
1955 case 2:
1956 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1957 bis->bi_enet2addr, 6);
Stefan Roese4c9e8552008-03-19 16:20:49 +01001958#if defined(CONFIG_460GT)
1959 hw_addr[eth_num] = 0x300;
1960#else
Stefan Roese5fb692c2007-01-18 10:25:34 +01001961 hw_addr[eth_num] = 0x400;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001962#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001963 break;
1964#endif
1965#ifdef CONFIG_HAS_ETH3
1966 case 3:
1967 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1968 bis->bi_enet3addr, 6);
Stefan Roese4c9e8552008-03-19 16:20:49 +01001969#if defined(CONFIG_460GT)
1970 hw_addr[eth_num] = 0x400;
1971#else
Stefan Roese5fb692c2007-01-18 10:25:34 +01001972 hw_addr[eth_num] = 0x600;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001973#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001974 break;
1975#endif
1976 }
1977 }
1978
wdenk3c74e322004-02-22 23:46:08 +00001979 /* set phy num and mode */
1980 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001981 bis->bi_phymode[0] = 0;
1982
Stefan Roesec157d8e2005-08-01 16:41:48 +02001983#if defined(CONFIG_PHY1_ADDR)
wdenk3c74e322004-02-22 23:46:08 +00001984 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001985 bis->bi_phymode[1] = 0;
Stefan Roesec157d8e2005-08-01 16:41:48 +02001986#endif
Stefan Roese846b0dd2005-08-08 12:42:22 +02001987#if defined(CONFIG_440GX)
wdenk3c74e322004-02-22 23:46:08 +00001988 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1989 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
wdenk3c74e322004-02-22 23:46:08 +00001990 bis->bi_phymode[2] = 2;
1991 bis->bi_phymode[3] = 2;
Stefan Roesedbbd1252007-10-05 17:10:59 +02001992#endif
wdenkba56f622004-02-06 23:19:44 +00001993
Stefan Roesedbbd1252007-10-05 17:10:59 +02001994#if defined(CONFIG_440GX) || \
1995 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1996 defined(CONFIG_405EX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001997 ppc_4xx_eth_setup_bridge(0, bis);
wdenka06752e2004-09-29 22:43:59 +00001998#endif
1999
Stefan Roese1e25f952005-10-20 16:34:28 +02002000 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
Stefan Roese5fb692c2007-01-18 10:25:34 +01002001 /*
2002 * See if we can actually bring up the interface,
2003 * otherwise, skip it
2004 */
2005 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
2006 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
2007 continue;
wdenkba56f622004-02-06 23:19:44 +00002008 }
2009
2010 /* Allocate device structure */
2011 dev = (struct eth_device *) malloc (sizeof (*dev));
2012 if (dev == NULL) {
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002013 printf ("ppc_4xx_eth_initialize: "
wdenk3f85ce22004-02-23 16:11:30 +00002014 "Cannot allocate eth_device %d\n", eth_num);
wdenkba56f622004-02-06 23:19:44 +00002015 return (-1);
2016 }
wdenkb2532ef2005-06-20 10:17:34 +00002017 memset(dev, 0, sizeof(*dev));
wdenkba56f622004-02-06 23:19:44 +00002018
2019 /* Allocate our private use data */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002020 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
wdenkba56f622004-02-06 23:19:44 +00002021 if (hw == NULL) {
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002022 printf ("ppc_4xx_eth_initialize: "
wdenk3f85ce22004-02-23 16:11:30 +00002023 "Cannot allocate private hw data for eth_device %d",
wdenkba56f622004-02-06 23:19:44 +00002024 eth_num);
2025 free (dev);
2026 return (-1);
2027 }
wdenkb2532ef2005-06-20 10:17:34 +00002028 memset(hw, 0, sizeof(*hw));
wdenkba56f622004-02-06 23:19:44 +00002029
Stefan Roese5fb692c2007-01-18 10:25:34 +01002030 hw->hw_addr = hw_addr[eth_num];
2031 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
wdenkba56f622004-02-06 23:19:44 +00002032 hw->devnum = eth_num;
Stefan Roesec157d8e2005-08-01 16:41:48 +02002033 hw->print_speed = 1;
wdenkba56f622004-02-06 23:19:44 +00002034
Stefan Roese5fb692c2007-01-18 10:25:34 +01002035 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
wdenkba56f622004-02-06 23:19:44 +00002036 dev->priv = (void *) hw;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002037 dev->init = ppc_4xx_eth_init;
2038 dev->halt = ppc_4xx_eth_halt;
2039 dev->send = ppc_4xx_eth_send;
2040 dev->recv = ppc_4xx_eth_rx;
wdenkba56f622004-02-06 23:19:44 +00002041
2042 if (0 == virgin) {
2043 /* set the MAL IER ??? names may change with new spec ??? */
Stefan Roesedbbd1252007-10-05 17:10:59 +02002044#if defined(CONFIG_440SPE) || \
2045 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01002046 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02002047 defined(CONFIG_405EX)
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002048 mal_ier =
2049 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
2050 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
2051#else
wdenkba56f622004-02-06 23:19:44 +00002052 mal_ier =
2053 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
2054 MAL_IER_OPBE | MAL_IER_PLBE;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002055#endif
wdenkba56f622004-02-06 23:19:44 +00002056 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
2057 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
2058 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
2059 mtdcr (malier, mal_ier);
2060
2061 /* install MAL interrupt handler */
Stefan Roesed1631fe2008-06-26 13:40:57 +02002062 irq_install_handler (VECNUM_MAL_SERR,
wdenkba56f622004-02-06 23:19:44 +00002063 (interrupt_handler_t *) enetInt,
2064 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002065 irq_install_handler (VECNUM_MAL_TXEOB,
wdenkba56f622004-02-06 23:19:44 +00002066 (interrupt_handler_t *) enetInt,
2067 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002068 irq_install_handler (VECNUM_MAL_RXEOB,
wdenkba56f622004-02-06 23:19:44 +00002069 (interrupt_handler_t *) enetInt,
2070 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002071 irq_install_handler (VECNUM_MAL_TXDE,
wdenkba56f622004-02-06 23:19:44 +00002072 (interrupt_handler_t *) enetInt,
2073 dev);
Stefan Roesed1631fe2008-06-26 13:40:57 +02002074 irq_install_handler (VECNUM_MAL_RXDE,
wdenkba56f622004-02-06 23:19:44 +00002075 (interrupt_handler_t *) enetInt,
2076 dev);
2077 virgin = 1;
2078 }
2079
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002080#if defined(CONFIG_NET_MULTI)
wdenkba56f622004-02-06 23:19:44 +00002081 eth_register (dev);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002082#else
2083 emac0_dev = dev;
2084#endif
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002085
2086#if defined(CONFIG_NET_MULTI)
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -05002087#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002088 miiphy_register (dev->name,
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01002089 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002090#endif
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002091#endif
wdenkba56f622004-02-06 23:19:44 +00002092 } /* end for each supported device */
Stefan Roese802b7692008-01-08 18:39:30 +01002093
2094 return 0;
wdenkba56f622004-02-06 23:19:44 +00002095}
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002096
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002097#if !defined(CONFIG_NET_MULTI)
2098void eth_halt (void) {
2099 if (emac0_dev) {
2100 ppc_4xx_eth_halt(emac0_dev);
2101 free(emac0_dev);
2102 emac0_dev = NULL;
2103 }
2104}
2105
2106int eth_init (bd_t *bis)
2107{
2108 ppc_4xx_eth_initialize(bis);
Stefan Roese4f92ac32005-10-10 17:43:58 +02002109 if (emac0_dev) {
2110 return ppc_4xx_eth_init(emac0_dev, bis);
2111 } else {
2112 printf("ERROR: ethaddr not set!\n");
2113 return -1;
2114 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002115}
2116
2117int eth_send(volatile void *packet, int length)
2118{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002119 return (ppc_4xx_eth_send(emac0_dev, packet, length));
2120}
2121
2122int eth_rx(void)
2123{
2124 return (ppc_4xx_eth_rx(emac0_dev));
2125}
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002126
2127int emac4xx_miiphy_initialize (bd_t * bis)
2128{
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -05002129#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002130 miiphy_register ("ppc_4xx_eth0",
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01002131 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002132#endif
2133
2134 return 0;
2135}
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002136#endif /* !defined(CONFIG_NET_MULTI) */
2137
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -05002138#endif