blob: 4541a1468c98623b9f51c9e163fc3d5da65aa62e [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>
Matthias Fuchs6e9233d2008-01-08 15:50:49 +010093#include <asm/ppc4xx-intvec.h>
wdenkba56f622004-02-06 23:19:44 +000094
Stefan Roesed6c61aa2005-08-16 18:18:00 +020095/*
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020096 * Only compile for platform with AMCC EMAC ethernet controller and
Stefan Roesed6c61aa2005-08-16 18:18:00 +020097 * network support enabled.
98 * Remark: CONFIG_405 describes Xilinx PPC405 FPGA without EMAC controller!
99 */
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500100#if defined(CONFIG_CMD_NET) && !defined(CONFIG_405) && !defined(CONFIG_IOP480)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200101
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500102#if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200103#error "CONFIG_MII has to be defined!"
104#endif
wdenkba56f622004-02-06 23:19:44 +0000105
Stefan Roese1e25f952005-10-20 16:34:28 +0200106#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI)
107#error "CONFIG_NET_MULTI has to be defined for NetConsole"
108#endif
109
Wolfgang Denk265817c2005-09-25 00:53:22 +0200110#define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
Stefan Roese1338e6a2007-10-23 14:05:08 +0200111#define PHY_AUTONEGOTIATE_TIMEOUT 5000 /* 5000 ms autonegotiate timeout */
wdenkba56f622004-02-06 23:19:44 +0000112
wdenkba56f622004-02-06 23:19:44 +0000113/* Ethernet Transmit and Receive Buffers */
114/* AS.HARNOIS
115 * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
116 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
117 */
Wolfgang Denk265817c2005-09-25 00:53:22 +0200118#define ENET_MAX_MTU PKTSIZE
wdenkba56f622004-02-06 23:19:44 +0000119#define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
120
wdenkba56f622004-02-06 23:19:44 +0000121/*-----------------------------------------------------------------------------+
122 * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
123 * Interrupt Controller).
124 *-----------------------------------------------------------------------------*/
125#define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
126#define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
127#define EMAC_UIC_DEF UIC_ENET
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200128#define EMAC_UIC_DEF1 UIC_ENET1
129#define SEL_UIC_DEF(p) (p ? UIC_ENET1 : UIC_ENET )
wdenkba56f622004-02-06 23:19:44 +0000130
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200131#undef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +0000132
Wolfgang Denk265817c2005-09-25 00:53:22 +0200133#define BI_PHYMODE_NONE 0
134#define BI_PHYMODE_ZMII 1
wdenk3c74e322004-02-22 23:46:08 +0000135#define BI_PHYMODE_RGMII 2
Stefan Roese887e2ec2006-09-07 11:51:23 +0200136#define BI_PHYMODE_GMII 3
137#define BI_PHYMODE_RTBI 4
138#define BI_PHYMODE_TBI 5
Stefan Roesedbbd1252007-10-05 17:10:59 +0200139#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100140 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200141 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200142#define BI_PHYMODE_SMII 6
143#define BI_PHYMODE_MII 7
Stefan Roese8ac41e32008-03-11 15:05:26 +0100144#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
145#define BI_PHYMODE_RMII 8
146#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +0200147#endif
wdenk3c74e322004-02-22 23:46:08 +0000148
Stefan Roese1941cce2007-10-05 17:35:10 +0200149#if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200150 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100151 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200152 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200153#define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
154#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200155
Stefan Roese8ac41e32008-03-11 15:05:26 +0100156#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
157#define SDR0_ETH_CFG_CLK_SEL_V(n) (0x01 << (8 + n))
158#endif
159
160#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
161#define MAL_RX_CHAN_MUL 8 /* 460EX/GT uses MAL channel 8 for EMAC1 */
162#else
163#define MAL_RX_CHAN_MUL 1
164#endif
165
wdenkba56f622004-02-06 23:19:44 +0000166/*-----------------------------------------------------------------------------+
167 * Global variables. TX and RX descriptors and buffers.
168 *-----------------------------------------------------------------------------*/
169/* IER globals */
170static uint32_t mal_ier;
171
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200172#if !defined(CONFIG_NET_MULTI)
Stefan Roese4f92ac32005-10-10 17:43:58 +0200173struct eth_device *emac0_dev = NULL;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200174#endif
175
Stefan Roese1e25f952005-10-20 16:34:28 +0200176/*
177 * Get count of EMAC devices (doesn't have to be the max. possible number
178 * supported by the cpu)
Stefan Roese353f2682007-10-23 10:10:08 +0200179 *
180 * CONFIG_BOARD_EMAC_COUNT added so now a "dynamic" way to configure the
181 * EMAC count is possible. As it is needed for the Kilauea/Haleakala
182 * 405EX/405EXr eval board, using the same binary.
Stefan Roese1e25f952005-10-20 16:34:28 +0200183 */
Stefan Roese353f2682007-10-23 10:10:08 +0200184#if defined(CONFIG_BOARD_EMAC_COUNT)
185#define LAST_EMAC_NUM board_emac_count()
186#else /* CONFIG_BOARD_EMAC_COUNT */
Stefan Roese1e25f952005-10-20 16:34:28 +0200187#if defined(CONFIG_HAS_ETH3)
188#define LAST_EMAC_NUM 4
189#elif defined(CONFIG_HAS_ETH2)
190#define LAST_EMAC_NUM 3
191#elif defined(CONFIG_HAS_ETH1)
192#define LAST_EMAC_NUM 2
193#else
194#define LAST_EMAC_NUM 1
195#endif
Stefan Roese353f2682007-10-23 10:10:08 +0200196#endif /* CONFIG_BOARD_EMAC_COUNT */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200197
Stefan Roese5fb692c2007-01-18 10:25:34 +0100198/* normal boards start with EMAC0 */
199#if !defined(CONFIG_EMAC_NR_START)
200#define CONFIG_EMAC_NR_START 0
201#endif
202
Stefan Roesedbbd1252007-10-05 17:10:59 +0200203#if defined(CONFIG_405EX) || defined(CONFIG_440EPX)
204#define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev)))
205#else
206#define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * 2))
207#endif
208
Stefan Roeseff768cb2007-10-31 18:01:24 +0100209#define MAL_RX_DESC_SIZE 2048
210#define MAL_TX_DESC_SIZE 2048
211#define MAL_ALLOC_SIZE (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE)
212
wdenkba56f622004-02-06 23:19:44 +0000213/*-----------------------------------------------------------------------------+
214 * Prototypes and externals.
215 *-----------------------------------------------------------------------------*/
216static void enet_rcv (struct eth_device *dev, unsigned long malisr);
217
218int enetInt (struct eth_device *dev);
219static void mal_err (struct eth_device *dev, unsigned long isr,
220 unsigned long uic, unsigned long maldef,
221 unsigned long mal_errr);
222static void emac_err (struct eth_device *dev, unsigned long isr);
223
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200224extern int phy_setup_aneg (char *devname, unsigned char addr);
225extern int emac4xx_miiphy_read (char *devname, unsigned char addr,
226 unsigned char reg, unsigned short *value);
227extern int emac4xx_miiphy_write (char *devname, unsigned char addr,
228 unsigned char reg, unsigned short value);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200229
Stefan Roese353f2682007-10-23 10:10:08 +0200230int board_emac_count(void);
231
Stefan Roese8ac41e32008-03-11 15:05:26 +0100232static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p)
233{
234#if defined(CONFIG_440SPE) || \
235 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
236 defined(CONFIG_405EX)
237 u32 val;
238
239 mfsdr(sdr_mfr, val);
240 val |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
241 mtsdr(sdr_mfr, val);
242#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
243 u32 val;
244
245 mfsdr(SDR0_ETH_CFG, val);
246 val |= SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
247 mtsdr(SDR0_ETH_CFG, val);
248#endif
249}
250
251static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p)
252{
253#if defined(CONFIG_440SPE) || \
254 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
255 defined(CONFIG_405EX)
256 u32 val;
257
258 mfsdr(sdr_mfr, val);
259 val &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
260 mtsdr(sdr_mfr, val);
261#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
262 u32 val;
263
264 mfsdr(SDR0_ETH_CFG, val);
265 val &= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
266 mtsdr(SDR0_ETH_CFG, val);
267#endif
268}
269
wdenkba56f622004-02-06 23:19:44 +0000270/*-----------------------------------------------------------------------------+
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200271| ppc_4xx_eth_halt
wdenkba56f622004-02-06 23:19:44 +0000272| Disable MAL channel, and EMACn
wdenkba56f622004-02-06 23:19:44 +0000273+-----------------------------------------------------------------------------*/
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200274static void ppc_4xx_eth_halt (struct eth_device *dev)
wdenkba56f622004-02-06 23:19:44 +0000275{
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200276 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +0000277 uint32_t failsafe = 10000;
Stefan Roese4c9e8552008-03-19 16:20:49 +0100278 u32 eth_cfg = 0;
wdenkba56f622004-02-06 23:19:44 +0000279
Stefan Roese2d834762007-10-23 14:03:17 +0200280 out_be32((void *)EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
wdenkba56f622004-02-06 23:19:44 +0000281
282 /* 1st reset MAL channel */
283 /* Note: writing a 0 to a channel has no effect */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200284#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
285 mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
286#else
wdenkba56f622004-02-06 23:19:44 +0000287 mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200288#endif
wdenkba56f622004-02-06 23:19:44 +0000289 mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
290
291 /* wait for reset */
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200292 while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
wdenkba56f622004-02-06 23:19:44 +0000293 udelay (1000); /* Delay 1 MS so as not to hammer the register */
294 failsafe--;
295 if (failsafe == 0)
296 break;
wdenkba56f622004-02-06 23:19:44 +0000297 }
298
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200299 /* provide clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100300 emac_loopback_enable(hw_p);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200301
Stefan Roese8ac41e32008-03-11 15:05:26 +0100302 /* EMAC RESET */
Stefan Roese2d834762007-10-23 14:03:17 +0200303 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenkba56f622004-02-06 23:19:44 +0000304
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200305 /* remove clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100306 emac_loopback_disable(hw_p);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200307
Stefan Roesea93316c2005-10-18 19:17:12 +0200308#ifndef CONFIG_NETCONSOLE
Stefan Roesec157d8e2005-08-01 16:41:48 +0200309 hw_p->print_speed = 1; /* print speed message again next time */
Stefan Roesea93316c2005-10-18 19:17:12 +0200310#endif
Stefan Roesec157d8e2005-08-01 16:41:48 +0200311
Stefan Roese4c9e8552008-03-19 16:20:49 +0100312#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
313 /* don't bypass the TAHOE0/TAHOE1 cores for Linux */
314 mfsdr(SDR0_ETH_CFG, eth_cfg);
315 eth_cfg &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
316 mtsdr(SDR0_ETH_CFG, eth_cfg);
317#endif
318
wdenkba56f622004-02-06 23:19:44 +0000319 return;
320}
321
Stefan Roese846b0dd2005-08-08 12:42:22 +0200322#if defined (CONFIG_440GX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200323int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
wdenk855a4962004-03-14 18:23:55 +0000324{
325 unsigned long pfc1;
326 unsigned long zmiifer;
327 unsigned long rmiifer;
328
329 mfsdr(sdr_pfc1, pfc1);
330 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
331
332 zmiifer = 0;
333 rmiifer = 0;
334
335 switch (pfc1) {
336 case 1:
337 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
338 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
339 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
340 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
341 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
342 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
343 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
344 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
345 break;
346 case 2:
Stefan Roesef6e495f2006-11-27 17:43:25 +0100347 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
348 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
349 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
350 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
wdenk855a4962004-03-14 18:23:55 +0000351 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
352 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
353 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
354 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
355 break;
356 case 3:
357 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
358 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
359 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
360 bis->bi_phymode[1] = BI_PHYMODE_NONE;
361 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
362 bis->bi_phymode[3] = BI_PHYMODE_NONE;
363 break;
364 case 4:
365 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
366 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
367 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
368 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
369 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
370 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
371 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
372 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
373 break;
374 case 5:
375 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
376 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
377 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
378 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
379 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
380 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
381 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
382 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
383 break;
384 case 6:
385 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
386 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
387 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
wdenk855a4962004-03-14 18:23:55 +0000388 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
389 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
390 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
wdenk855a4962004-03-14 18:23:55 +0000391 break;
392 case 0:
393 default:
394 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
395 rmiifer = 0x0;
396 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
397 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
398 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
399 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
400 break;
401 }
402
403 /* Ensure we setup mdio for this devnum and ONLY this devnum */
404 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
405
Stefan Roeseff768cb2007-10-31 18:01:24 +0100406 out_be32((void *)ZMII_FER, zmiifer);
407 out_be32((void *)RGMII_FER, rmiifer);
wdenk855a4962004-03-14 18:23:55 +0000408
409 return ((int)pfc1);
wdenk855a4962004-03-14 18:23:55 +0000410}
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200411#endif /* CONFIG_440_GX */
wdenk855a4962004-03-14 18:23:55 +0000412
Stefan Roese887e2ec2006-09-07 11:51:23 +0200413#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
414int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
415{
416 unsigned long zmiifer=0x0;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200417 unsigned long pfc1;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200418
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200419 mfsdr(sdr_pfc1, pfc1);
420 pfc1 &= SDR0_PFC1_SELECT_MASK;
421
Wolfgang Denk2f152782007-05-05 18:23:11 +0200422 switch (pfc1) {
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200423 case SDR0_PFC1_SELECT_CONFIG_2:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200424 /* 1 x GMII port */
Stefan Roese2d834762007-10-23 14:03:17 +0200425 out_be32((void *)ZMII_FER, 0x00);
426 out_be32((void *)RGMII_FER, 0x00000037);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200427 bis->bi_phymode[0] = BI_PHYMODE_GMII;
428 bis->bi_phymode[1] = BI_PHYMODE_NONE;
429 break;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200430 case SDR0_PFC1_SELECT_CONFIG_4:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200431 /* 2 x RGMII ports */
Stefan Roese2d834762007-10-23 14:03:17 +0200432 out_be32((void *)ZMII_FER, 0x00);
433 out_be32((void *)RGMII_FER, 0x00000055);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200434 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
435 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
436 break;
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200437 case SDR0_PFC1_SELECT_CONFIG_6:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200438 /* 2 x SMII ports */
Stefan Roese2d834762007-10-23 14:03:17 +0200439 out_be32((void *)ZMII_FER,
440 ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
441 ((ZMII_FER_SMII) << ZMII_FER_V(1)));
442 out_be32((void *)RGMII_FER, 0x00000000);
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200443 bis->bi_phymode[0] = BI_PHYMODE_SMII;
444 bis->bi_phymode[1] = BI_PHYMODE_SMII;
445 break;
446 case SDR0_PFC1_SELECT_CONFIG_1_2:
447 /* only 1 x MII supported */
Stefan Roese2d834762007-10-23 14:03:17 +0200448 out_be32((void *)ZMII_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
449 out_be32((void *)RGMII_FER, 0x00000000);
Matthias Fuchs37ed6cd2007-04-24 14:03:45 +0200450 bis->bi_phymode[0] = BI_PHYMODE_MII;
451 bis->bi_phymode[1] = BI_PHYMODE_NONE;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200452 break;
453 default:
454 break;
455 }
456
457 /* Ensure we setup mdio for this devnum and ONLY this devnum */
Stefan Roese2d834762007-10-23 14:03:17 +0200458 zmiifer = in_be32((void *)ZMII_FER);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200459 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
Stefan Roese2d834762007-10-23 14:03:17 +0200460 out_be32((void *)ZMII_FER, zmiifer);
Stefan Roese887e2ec2006-09-07 11:51:23 +0200461
462 return ((int)0x0);
463}
464#endif /* CONFIG_440EPX */
465
Stefan Roesedbbd1252007-10-05 17:10:59 +0200466#if defined(CONFIG_405EX)
467int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
468{
469 u32 gmiifer = 0;
470
471 /*
472 * Right now only 2*RGMII is supported. Please extend when needed.
473 * sr - 2007-09-19
474 */
475 switch (1) {
476 case 1:
477 /* 2 x RGMII ports */
Stefan Roese2d834762007-10-23 14:03:17 +0200478 out_be32((void *)RGMII_FER, 0x00000055);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200479 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
480 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
481 break;
482 case 2:
483 /* 2 x SMII ports */
484 break;
485 default:
486 break;
487 }
488
489 /* Ensure we setup mdio for this devnum and ONLY this devnum */
Stefan Roese2d834762007-10-23 14:03:17 +0200490 gmiifer = in_be32((void *)RGMII_FER);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200491 gmiifer |= (1 << (19-devnum));
Stefan Roese2d834762007-10-23 14:03:17 +0200492 out_be32((void *)RGMII_FER, gmiifer);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200493
494 return ((int)0x0);
495}
496#endif /* CONFIG_405EX */
497
Stefan Roese8ac41e32008-03-11 15:05:26 +0100498#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
499int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
500{
501 u32 eth_cfg;
502 u32 zmiifer; /* ZMII0_FER reg. */
503 u32 rmiifer; /* RGMII0_FER reg. Bridge 0 */
504 u32 rmiifer1; /* RGMII0_FER reg. Bridge 1 */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100505 int mode;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100506
507 zmiifer = 0;
508 rmiifer = 0;
509 rmiifer1 = 0;
510
Stefan Roese4c9e8552008-03-19 16:20:49 +0100511#if defined(CONFIG_460EX)
512 mode = 9;
513#else
514 mode = 10;
515#endif
516
Stefan Roese8ac41e32008-03-11 15:05:26 +0100517 /* TODO:
518 * NOTE: 460GT has 2 RGMII bridge cores:
519 * emac0 ------ RGMII0_BASE
520 * |
521 * emac1 -----+
522 *
523 * emac2 ------ RGMII1_BASE
524 * |
525 * emac3 -----+
526 *
527 * 460EX has 1 RGMII bridge core:
528 * and RGMII1_BASE is disabled
529 * emac0 ------ RGMII0_BASE
530 * |
531 * emac1 -----+
532 */
533
534 /*
535 * Right now only 2*RGMII is supported. Please extend when needed.
536 * sr - 2008-02-19
537 */
Stefan Roese4c9e8552008-03-19 16:20:49 +0100538 switch (mode) {
Stefan Roese8ac41e32008-03-11 15:05:26 +0100539 case 1:
540 /* 1 MII - 460EX */
541 /* GMC0 EMAC4_0, ZMII Bridge */
542 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
543 bis->bi_phymode[0] = BI_PHYMODE_MII;
544 bis->bi_phymode[1] = BI_PHYMODE_NONE;
545 bis->bi_phymode[2] = BI_PHYMODE_NONE;
546 bis->bi_phymode[3] = BI_PHYMODE_NONE;
547 break;
548 case 2:
549 /* 2 MII - 460GT */
550 /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */
551 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
552 zmiifer |= ZMII_FER_MII << ZMII_FER_V(2);
553 bis->bi_phymode[0] = BI_PHYMODE_MII;
554 bis->bi_phymode[1] = BI_PHYMODE_NONE;
555 bis->bi_phymode[2] = BI_PHYMODE_MII;
556 bis->bi_phymode[3] = BI_PHYMODE_NONE;
557 break;
558 case 3:
559 /* 2 RMII - 460EX */
560 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
561 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
562 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
563 bis->bi_phymode[0] = BI_PHYMODE_RMII;
564 bis->bi_phymode[1] = BI_PHYMODE_RMII;
565 bis->bi_phymode[2] = BI_PHYMODE_NONE;
566 bis->bi_phymode[3] = BI_PHYMODE_NONE;
567 break;
568 case 4:
569 /* 4 RMII - 460GT */
570 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */
571 /* ZMII Bridge */
572 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
573 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
574 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
575 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
576 bis->bi_phymode[0] = BI_PHYMODE_RMII;
577 bis->bi_phymode[1] = BI_PHYMODE_RMII;
578 bis->bi_phymode[2] = BI_PHYMODE_RMII;
579 bis->bi_phymode[3] = BI_PHYMODE_RMII;
580 break;
581 case 5:
582 /* 2 SMII - 460EX */
583 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
584 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
585 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
586 bis->bi_phymode[0] = BI_PHYMODE_SMII;
587 bis->bi_phymode[1] = BI_PHYMODE_SMII;
588 bis->bi_phymode[2] = BI_PHYMODE_NONE;
589 bis->bi_phymode[3] = BI_PHYMODE_NONE;
590 break;
591 case 6:
592 /* 4 SMII - 460GT */
593 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */
594 /* ZMII Bridge */
595 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
596 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
597 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
598 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
599 bis->bi_phymode[0] = BI_PHYMODE_SMII;
600 bis->bi_phymode[1] = BI_PHYMODE_SMII;
601 bis->bi_phymode[2] = BI_PHYMODE_SMII;
602 bis->bi_phymode[3] = BI_PHYMODE_SMII;
603 break;
604 case 7:
605 /* This is the default mode that we want for board bringup - Maple */
606 /* 1 GMII - 460EX */
607 /* GMC0 EMAC4_0, RGMII Bridge 0 */
608 rmiifer |= RGMII_FER_MDIO(0);
609
610 if (devnum == 0) {
611 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
612 bis->bi_phymode[0] = BI_PHYMODE_GMII;
613 bis->bi_phymode[1] = BI_PHYMODE_NONE;
614 bis->bi_phymode[2] = BI_PHYMODE_NONE;
615 bis->bi_phymode[3] = BI_PHYMODE_NONE;
616 } else {
617 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3); /* CH1CFG - EMAC1 */
618 bis->bi_phymode[0] = BI_PHYMODE_NONE;
619 bis->bi_phymode[1] = BI_PHYMODE_GMII;
620 bis->bi_phymode[2] = BI_PHYMODE_NONE;
621 bis->bi_phymode[3] = BI_PHYMODE_NONE;
622 }
623 break;
624 case 8:
625 /* 2 GMII - 460GT */
626 /* GMC0 EMAC4_0, RGMII Bridge 0 */
627 /* GMC1 EMAC4_2, RGMII Bridge 1 */
628 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
629 rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC2 */
630 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
631 rmiifer1 |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC2 */
632
633 bis->bi_phymode[0] = BI_PHYMODE_GMII;
634 bis->bi_phymode[1] = BI_PHYMODE_NONE;
635 bis->bi_phymode[2] = BI_PHYMODE_GMII;
636 bis->bi_phymode[3] = BI_PHYMODE_NONE;
637 break;
638 case 9:
639 /* 2 RGMII - 460EX */
640 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
641 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
642 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
643 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
644
645 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
646 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
647 bis->bi_phymode[2] = BI_PHYMODE_NONE;
648 bis->bi_phymode[3] = BI_PHYMODE_NONE;
649 break;
650 case 10:
651 /* 4 RGMII - 460GT */
652 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
653 /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */
654 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
655 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
656 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2);
657 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3);
658 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
659 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
660 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
661 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
662 break;
663 default:
664 break;
665 }
666
667 /* Set EMAC for MDIO */
668 mfsdr(SDR0_ETH_CFG, eth_cfg);
669 eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
670 mtsdr(SDR0_ETH_CFG, eth_cfg);
671
672 out_be32((void *)RGMII_FER, rmiifer);
673#if defined(CONFIG_460GT)
674 out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1);
675#endif
676
677 /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
678 mfsdr(SDR0_ETH_CFG, eth_cfg);
679 eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
680 mtsdr(SDR0_ETH_CFG, eth_cfg);
681
682 return 0;
683}
684#endif /* CONFIG_460EX || CONFIG_460GT */
685
Stefan Roeseff768cb2007-10-31 18:01:24 +0100686static inline void *malloc_aligned(u32 size, u32 align)
687{
688 return (void *)(((u32)malloc(size + align) + align - 1) &
689 ~(align - 1));
690}
691
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200692static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
wdenkba56f622004-02-06 23:19:44 +0000693{
Stefan Roeseff768cb2007-10-31 18:01:24 +0100694 int i;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200695 unsigned long reg = 0;
wdenkba56f622004-02-06 23:19:44 +0000696 unsigned long msr;
697 unsigned long speed;
698 unsigned long duplex;
699 unsigned long failsafe;
700 unsigned mode_reg;
701 unsigned short devnum;
702 unsigned short reg_short;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200703#if defined(CONFIG_440GX) || \
704 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200705 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100706 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200707 defined(CONFIG_405EX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200708 sys_info_t sysinfo;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200709#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200710 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100711 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200712 defined(CONFIG_405EX)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100713 int ethgroup = -1;
714#endif
Stefan Roesec157d8e2005-08-01 16:41:48 +0200715#endif
Stefan Roeseff768cb2007-10-31 18:01:24 +0100716 u32 bd_cached;
717 u32 bd_uncached = 0;
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +0100718#ifdef CONFIG_4xx_DCACHE
719 static u32 last_used_ea = 0;
720#endif
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200721
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200722 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +0000723
724 /* before doing anything, figure out if we have a MAC address */
725 /* if not, bail */
Stefan Roese4f92ac32005-10-10 17:43:58 +0200726 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
727 printf("ERROR: ethaddr not set!\n");
wdenkba56f622004-02-06 23:19:44 +0000728 return -1;
Stefan Roese4f92ac32005-10-10 17:43:58 +0200729 }
wdenkba56f622004-02-06 23:19:44 +0000730
Stefan Roese887e2ec2006-09-07 11:51:23 +0200731#if defined(CONFIG_440GX) || \
732 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200733 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100734 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200735 defined(CONFIG_405EX)
wdenkba56f622004-02-06 23:19:44 +0000736 /* Need to get the OPB frequency so we can access the PHY */
737 get_sys_info (&sysinfo);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200738#endif
wdenkba56f622004-02-06 23:19:44 +0000739
wdenkba56f622004-02-06 23:19:44 +0000740 msr = mfmsr ();
741 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
742
743 devnum = hw_p->devnum;
744
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200745#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +0000746 /* AS.HARNOIS
747 * We should have :
Wolfgang Denk265817c2005-09-25 00:53:22 +0200748 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
wdenkba56f622004-02-06 23:19:44 +0000749 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
750 * is possible that new packets (without relationship with
751 * current transfer) have got the time to arrived before
752 * netloop calls eth_halt
753 */
754 printf ("About preceeding transfer (eth%d):\n"
755 "- Sent packet number %d\n"
756 "- Received packet number %d\n"
757 "- Handled packet number %d\n",
758 hw_p->devnum,
759 hw_p->stats.pkts_tx,
760 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
761
762 hw_p->stats.pkts_tx = 0;
763 hw_p->stats.pkts_rx = 0;
764 hw_p->stats.pkts_handled = 0;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200765 hw_p->print_speed = 1; /* print speed message again next time */
wdenkba56f622004-02-06 23:19:44 +0000766#endif
767
Wolfgang Denk265817c2005-09-25 00:53:22 +0200768 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
769 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
wdenkba56f622004-02-06 23:19:44 +0000770
771 hw_p->rx_slot = 0; /* MAL Receive Slot */
772 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
773 hw_p->rx_u_index = 0; /* Receive User Queue Index */
774
775 hw_p->tx_slot = 0; /* MAL Transmit Slot */
776 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
777 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
778
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200779#if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
wdenkba56f622004-02-06 23:19:44 +0000780 /* set RMII mode */
781 /* NOTE: 440GX spec states that mode is mutually exclusive */
782 /* NOTE: Therefore, disable all other EMACS, since we handle */
783 /* NOTE: only one emac at a time */
784 reg = 0;
Stefan Roese2d834762007-10-23 14:03:17 +0200785 out_be32((void *)ZMII_FER, 0);
wdenkba56f622004-02-06 23:19:44 +0000786 udelay (100);
wdenkba56f622004-02-06 23:19:44 +0000787
Stefan Roese8ac41e32008-03-11 15:05:26 +0100788#if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese2d834762007-10-23 14:03:17 +0200789 out_be32((void *)ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
Stefan Roese8ac41e32008-03-11 15:05:26 +0100790#elif defined(CONFIG_440GX) || \
791 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
792 defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200793 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
wdenk0e6d7982004-03-14 00:07:33 +0000794#endif
Stefan Roesec57c7982005-08-11 17:56:56 +0200795
Stefan Roese2d834762007-10-23 14:03:17 +0200796 out_be32((void *)ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100797#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
Stefan Roesedbbd1252007-10-05 17:10:59 +0200798#if defined(CONFIG_405EX)
799 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
800#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200801
Stefan Roese8ac41e32008-03-11 15:05:26 +0100802 sync();
wdenk0e6d7982004-03-14 00:07:33 +0000803
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200804 /* provide clocks for EMAC internal loopback */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100805 emac_loopback_enable(hw_p);
wdenk0e6d7982004-03-14 00:07:33 +0000806
Stefan Roese8ac41e32008-03-11 15:05:26 +0100807 /* EMAC RESET */
Stefan Roese2d834762007-10-23 14:03:17 +0200808 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenkba56f622004-02-06 23:19:44 +0000809
Stefan Roese8ac41e32008-03-11 15:05:26 +0100810 /* remove clocks for EMAC internal loopback */
811 emac_loopback_disable(hw_p);
812
wdenkba56f622004-02-06 23:19:44 +0000813 failsafe = 1000;
Stefan Roese2d834762007-10-23 14:03:17 +0200814 while ((in_be32((void *)EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
wdenkba56f622004-02-06 23:19:44 +0000815 udelay (1000);
816 failsafe--;
817 }
Stefan Roese887e2ec2006-09-07 11:51:23 +0200818 if (failsafe <= 0)
819 printf("\nProblem resetting EMAC!\n");
wdenkba56f622004-02-06 23:19:44 +0000820
Stefan Roese887e2ec2006-09-07 11:51:23 +0200821#if defined(CONFIG_440GX) || \
822 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200823 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100824 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200825 defined(CONFIG_405EX)
wdenkba56f622004-02-06 23:19:44 +0000826 /* Whack the M1 register */
827 mode_reg = 0x0;
828 mode_reg &= ~0x00000038;
829 if (sysinfo.freqOPB <= 50000000);
830 else if (sysinfo.freqOPB <= 66666667)
831 mode_reg |= EMAC_M1_OBCI_66;
832 else if (sysinfo.freqOPB <= 83333333)
833 mode_reg |= EMAC_M1_OBCI_83;
834 else if (sysinfo.freqOPB <= 100000000)
835 mode_reg |= EMAC_M1_OBCI_100;
836 else
837 mode_reg |= EMAC_M1_OBCI_GT100;
838
Stefan Roese2d834762007-10-23 14:03:17 +0200839 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100840#endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
wdenkba56f622004-02-06 23:19:44 +0000841
842 /* wait for PHY to complete auto negotiation */
843 reg_short = 0;
844#ifndef CONFIG_CS8952_PHY
845 switch (devnum) {
846 case 0:
847 reg = CONFIG_PHY_ADDR;
848 break;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200849#if defined (CONFIG_PHY1_ADDR)
wdenkba56f622004-02-06 23:19:44 +0000850 case 1:
851 reg = CONFIG_PHY1_ADDR;
852 break;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200853#endif
Stefan Roese4c9e8552008-03-19 16:20:49 +0100854#if defined (CONFIG_PHY2_ADDR)
wdenkba56f622004-02-06 23:19:44 +0000855 case 2:
856 reg = CONFIG_PHY2_ADDR;
857 break;
Stefan Roese4c9e8552008-03-19 16:20:49 +0100858#endif
859#if defined (CONFIG_PHY3_ADDR)
wdenkba56f622004-02-06 23:19:44 +0000860 case 3:
861 reg = CONFIG_PHY3_ADDR;
862 break;
863#endif
864 default:
865 reg = CONFIG_PHY_ADDR;
866 break;
867 }
868
wdenk3c74e322004-02-22 23:46:08 +0000869 bis->bi_phynum[devnum] = reg;
870
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200871#if defined(CONFIG_PHY_RESET)
wdenka06752e2004-09-29 22:43:59 +0000872 /*
873 * Reset the phy, only if its the first time through
874 * otherwise, just check the speeds & feeds
875 */
876 if (hw_p->first_init == 0) {
Stefan Roeseec0c2ec2006-11-27 14:46:06 +0100877#if defined(CONFIG_M88E1111_PHY)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200878 miiphy_write (dev->name, reg, 0x14, 0x0ce3);
879 miiphy_write (dev->name, reg, 0x18, 0x4101);
880 miiphy_write (dev->name, reg, 0x09, 0x0e00);
881 miiphy_write (dev->name, reg, 0x04, 0x01e1);
882#endif
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200883 miiphy_reset (dev->name, reg);
wdenkba56f622004-02-06 23:19:44 +0000884
Stefan Roese887e2ec2006-09-07 11:51:23 +0200885#if defined(CONFIG_440GX) || \
886 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200887 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +0100888 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200889 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200890
wdenk0e6d7982004-03-14 00:07:33 +0000891#if defined(CONFIG_CIS8201_PHY)
wdenkfc1cfcd2004-04-25 15:41:35 +0000892 /*
Stefan Roese17f50f222005-08-04 17:09:16 +0200893 * Cicada 8201 PHY needs to have an extended register whacked
894 * for RGMII mode.
wdenkfc1cfcd2004-04-25 15:41:35 +0000895 */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200896 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
Stefan Roeseb79316f2005-08-15 12:31:23 +0200897#if defined(CONFIG_CIS8201_SHORT_ETCH)
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200898 miiphy_write (dev->name, reg, 23, 0x1300);
Stefan Roeseb79316f2005-08-15 12:31:23 +0200899#else
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200900 miiphy_write (dev->name, reg, 23, 0x1000);
Stefan Roeseb79316f2005-08-15 12:31:23 +0200901#endif
Stefan Roese17f50f222005-08-04 17:09:16 +0200902 /*
903 * Vitesse VSC8201/Cicada CIS8201 errata:
904 * Interoperability problem with Intel 82547EI phys
905 * This work around (provided by Vitesse) changes
906 * the default timer convergence from 8ms to 12ms
907 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200908 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
909 miiphy_write (dev->name, reg, 0x08, 0x0200);
910 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
911 miiphy_write (dev->name, reg, 0x02, 0x0004);
912 miiphy_write (dev->name, reg, 0x01, 0x0671);
913 miiphy_write (dev->name, reg, 0x00, 0x8fae);
914 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
915 miiphy_write (dev->name, reg, 0x08, 0x0000);
916 miiphy_write (dev->name, reg, 0x1f, 0x0000);
Stefan Roese17f50f222005-08-04 17:09:16 +0200917 /* end Vitesse/Cicada errata */
918 }
wdenk0e6d7982004-03-14 00:07:33 +0000919#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +0100920
921#if defined(CONFIG_ET1011C_PHY)
922 /*
923 * Agere ET1011c PHY needs to have an extended register whacked
924 * for RGMII mode.
925 */
926 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
927 miiphy_read (dev->name, reg, 0x16, &reg_short);
928 reg_short &= ~(0x7);
929 reg_short |= 0x6; /* RGMII DLL Delay*/
930 miiphy_write (dev->name, reg, 0x16, reg_short);
931
932 miiphy_read (dev->name, reg, 0x17, &reg_short);
933 reg_short &= ~(0x40);
934 miiphy_write (dev->name, reg, 0x17, reg_short);
935
936 miiphy_write(dev->name, reg, 0x1c, 0x74f0);
937 }
938#endif
939
wdenk855a4962004-03-14 18:23:55 +0000940#endif
wdenka06752e2004-09-29 22:43:59 +0000941 /* Start/Restart autonegotiation */
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200942 phy_setup_aneg (dev->name, reg);
wdenka06752e2004-09-29 22:43:59 +0000943 udelay (1000);
944 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200945#endif /* defined(CONFIG_PHY_RESET) */
wdenkba56f622004-02-06 23:19:44 +0000946
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200947 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenkba56f622004-02-06 23:19:44 +0000948
949 /*
wdenk0e6d7982004-03-14 00:07:33 +0000950 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
wdenkba56f622004-02-06 23:19:44 +0000951 */
952 if ((reg_short & PHY_BMSR_AUTN_ABLE)
953 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
954 puts ("Waiting for PHY auto negotiation to complete");
955 i = 0;
956 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
957 /*
958 * Timeout reached ?
959 */
960 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
961 puts (" TIMEOUT !\n");
962 break;
963 }
964
965 if ((i++ % 1000) == 0) {
966 putc ('.');
967 }
968 udelay (1000); /* 1 ms */
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200969 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenkba56f622004-02-06 23:19:44 +0000970
971 }
972 puts (" done\n");
973 udelay (500000); /* another 500 ms (results in faster booting) */
974 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200975#endif /* #ifndef CONFIG_CS8952_PHY */
976
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200977 speed = miiphy_speed (dev->name, reg);
978 duplex = miiphy_duplex (dev->name, reg);
wdenkba56f622004-02-06 23:19:44 +0000979
980 if (hw_p->print_speed) {
981 hw_p->print_speed = 0;
Stefan Roese5fb692c2007-01-18 10:25:34 +0100982 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
983 (int) speed, (duplex == HALF) ? "HALF" : "FULL",
984 hw_p->devnum);
wdenkba56f622004-02-06 23:19:44 +0000985 }
986
Stefan Roese8ac41e32008-03-11 15:05:26 +0100987#if defined(CONFIG_440) && \
988 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
989 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
990 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
Stefan Roese846b0dd2005-08-08 12:42:22 +0200991#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roesec157d8e2005-08-01 16:41:48 +0200992 mfsdr(sdr_mfr, reg);
993 if (speed == 100) {
994 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
995 } else {
996 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
997 }
998 mtsdr(sdr_mfr, reg);
999#endif
Stefan Roesec57c7982005-08-11 17:56:56 +02001000
wdenkba56f622004-02-06 23:19:44 +00001001 /* Set ZMII/RGMII speed according to the phy link speed */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001002 reg = in_be32((void *)ZMII_SSR);
wdenk855a4962004-03-14 18:23:55 +00001003 if ( (speed == 100) || (speed == 1000) )
Stefan Roeseff768cb2007-10-31 18:01:24 +01001004 out_be32((void *)ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
wdenkba56f622004-02-06 23:19:44 +00001005 else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001006 out_be32((void *)ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
wdenkba56f622004-02-06 23:19:44 +00001007
1008 if ((devnum == 2) || (devnum == 3)) {
1009 if (speed == 1000)
1010 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1011 else if (speed == 100)
1012 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001013 else if (speed == 10)
wdenkba56f622004-02-06 23:19:44 +00001014 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
Stefan Roese887e2ec2006-09-07 11:51:23 +02001015 else {
1016 printf("Error in RGMII Speed\n");
1017 return -1;
1018 }
Stefan Roeseff768cb2007-10-31 18:01:24 +01001019 out_be32((void *)RGMII_SSR, reg);
wdenkba56f622004-02-06 23:19:44 +00001020 }
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001021#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
wdenkba56f622004-02-06 23:19:44 +00001022
Stefan Roesedbbd1252007-10-05 17:10:59 +02001023#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001024 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001025 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +02001026 if (speed == 1000)
1027 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1028 else if (speed == 100)
1029 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
1030 else if (speed == 10)
1031 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
1032 else {
1033 printf("Error in RGMII Speed\n");
1034 return -1;
1035 }
Stefan Roese2d834762007-10-23 14:03:17 +02001036 out_be32((void *)RGMII_SSR, reg);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001037#if defined(CONFIG_460GT)
1038 if ((devnum == 2) || (devnum == 3))
1039 out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
1040#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +02001041#endif
1042
wdenkba56f622004-02-06 23:19:44 +00001043 /* set the Mal configuration reg */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001044#if defined(CONFIG_440GX) || \
1045 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001046 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001047 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001048 defined(CONFIG_405EX)
Stefan Roese17f50f222005-08-04 17:09:16 +02001049 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
1050 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
1051#else
1052 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
wdenkba56f622004-02-06 23:19:44 +00001053 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
Stefan Roese17f50f222005-08-04 17:09:16 +02001054 if (get_pvr() == PVR_440GP_RB) {
1055 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
1056 }
1057#endif
wdenkba56f622004-02-06 23:19:44 +00001058
wdenkba56f622004-02-06 23:19:44 +00001059 /*
1060 * Malloc MAL buffer desciptors, make sure they are
1061 * aligned on cache line boundary size
1062 * (401/403/IOP480 = 16, 405 = 32)
1063 * and doesn't cross cache block boundaries.
1064 */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001065 if (hw_p->first_init == 0) {
1066 debug("*** Allocating descriptor memory ***\n");
wdenkba56f622004-02-06 23:19:44 +00001067
Stefan Roeseff768cb2007-10-31 18:01:24 +01001068 bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
1069 if (!bd_cached) {
1070 printf("%s: Error allocating MAL descriptor buffers!\n");
1071 return -1;
1072 }
Stefan Roeseb79316f2005-08-15 12:31:23 +02001073
Stefan Roeseff768cb2007-10-31 18:01:24 +01001074#ifdef CONFIG_4xx_DCACHE
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001075 flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
Anatolij Gustschin4fae35a2008-02-25 20:54:04 +01001076 if (!last_used_ea)
1077 bd_uncached = bis->bi_memsize;
1078 else
1079 bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
1080
1081 last_used_ea = bd_uncached;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001082 program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
1083 TLB_WORD2_I_ENABLE);
1084#else
1085 bd_uncached = bd_cached;
1086#endif
1087 hw_p->tx_phys = bd_cached;
1088 hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
1089 hw_p->tx = (mal_desc_t *)(bd_uncached);
1090 hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
1091 debug("hw_p->tx=%08x, hw_p->rx=%08x\n", hw_p->tx, hw_p->rx);
wdenkba56f622004-02-06 23:19:44 +00001092 }
1093
1094 for (i = 0; i < NUM_TX_BUFF; i++) {
1095 hw_p->tx[i].ctrl = 0;
1096 hw_p->tx[i].data_len = 0;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001097 if (hw_p->first_init == 0)
1098 hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
1099 L1_CACHE_BYTES);
wdenkba56f622004-02-06 23:19:44 +00001100 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
1101 if ((NUM_TX_BUFF - 1) == i)
1102 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
1103 hw_p->tx_run[i] = -1;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001104 debug("TX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->tx[i].data_ptr);
wdenkba56f622004-02-06 23:19:44 +00001105 }
1106
1107 for (i = 0; i < NUM_RX_BUFF; i++) {
1108 hw_p->rx[i].ctrl = 0;
1109 hw_p->rx[i].data_len = 0;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001110 hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
wdenkba56f622004-02-06 23:19:44 +00001111 if ((NUM_RX_BUFF - 1) == i)
1112 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
1113 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
1114 hw_p->rx_ready[i] = -1;
Stefan Roeseff768cb2007-10-31 18:01:24 +01001115 debug("RX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->rx[i].data_ptr);
wdenkba56f622004-02-06 23:19:44 +00001116 }
1117
1118 reg = 0x00000000;
1119
1120 reg |= dev->enetaddr[0]; /* set high address */
1121 reg = reg << 8;
1122 reg |= dev->enetaddr[1];
1123
Stefan Roese2d834762007-10-23 14:03:17 +02001124 out_be32((void *)EMAC_IAH + hw_p->hw_addr, reg);
wdenkba56f622004-02-06 23:19:44 +00001125
1126 reg = 0x00000000;
1127 reg |= dev->enetaddr[2]; /* set low address */
1128 reg = reg << 8;
1129 reg |= dev->enetaddr[3];
1130 reg = reg << 8;
1131 reg |= dev->enetaddr[4];
1132 reg = reg << 8;
1133 reg |= dev->enetaddr[5];
1134
Stefan Roese2d834762007-10-23 14:03:17 +02001135 out_be32((void *)EMAC_IAL + hw_p->hw_addr, reg);
wdenkba56f622004-02-06 23:19:44 +00001136
1137 switch (devnum) {
1138 case 1:
1139 /* setup MAL tx & rx channel pointers */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001140#if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
Stefan Roeseff768cb2007-10-31 18:01:24 +01001141 mtdcr (maltxctp2r, hw_p->tx_phys);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001142#else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001143 mtdcr (maltxctp1r, hw_p->tx_phys);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001144#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001145#if defined(CONFIG_440)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001146 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001147 mtdcr (malrxbattr, 0x0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001148#endif
Stefan Roese8ac41e32008-03-11 15:05:26 +01001149
1150#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roese4c9e8552008-03-19 16:20:49 +01001151 mtdcr (malrxctp8r, hw_p->rx_phys);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001152 /* set RX buffer size */
1153 mtdcr (malrcbs8, ENET_MAX_MTU_ALIGNED / 16);
1154#else
Stefan Roeseff768cb2007-10-31 18:01:24 +01001155 mtdcr (malrxctp1r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001156 /* set RX buffer size */
1157 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001158#endif
wdenkba56f622004-02-06 23:19:44 +00001159 break;
Stefan Roese846b0dd2005-08-08 12:42:22 +02001160#if defined (CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001161 case 2:
1162 /* setup MAL tx & rx channel pointers */
1163 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001164 mtdcr (malrxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001165 mtdcr (maltxctp2r, hw_p->tx_phys);
1166 mtdcr (malrxctp2r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001167 /* set RX buffer size */
1168 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
1169 break;
1170 case 3:
1171 /* setup MAL tx & rx channel pointers */
1172 mtdcr (maltxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001173 mtdcr (maltxctp3r, hw_p->tx_phys);
wdenkba56f622004-02-06 23:19:44 +00001174 mtdcr (malrxbattr, 0x0);
Stefan Roeseff768cb2007-10-31 18:01:24 +01001175 mtdcr (malrxctp3r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001176 /* set RX buffer size */
1177 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
1178 break;
Stefan Roesec57c7982005-08-11 17:56:56 +02001179#endif /* CONFIG_440GX */
Stefan Roese4c9e8552008-03-19 16:20:49 +01001180#if defined (CONFIG_460GT)
1181 case 2:
1182 /* setup MAL tx & rx channel pointers */
1183 mtdcr (maltxbattr, 0x0);
1184 mtdcr (malrxbattr, 0x0);
1185 mtdcr (maltxctp2r, hw_p->tx_phys);
1186 mtdcr (malrxctp16r, hw_p->rx_phys);
1187 /* set RX buffer size */
1188 mtdcr (malrcbs16, ENET_MAX_MTU_ALIGNED / 16);
1189 break;
1190 case 3:
1191 /* setup MAL tx & rx channel pointers */
1192 mtdcr (maltxbattr, 0x0);
1193 mtdcr (malrxbattr, 0x0);
1194 mtdcr (maltxctp3r, hw_p->tx_phys);
1195 mtdcr (malrxctp24r, hw_p->rx_phys);
1196 /* set RX buffer size */
1197 mtdcr (malrcbs24, ENET_MAX_MTU_ALIGNED / 16);
1198 break;
1199#endif /* CONFIG_460GT */
wdenkba56f622004-02-06 23:19:44 +00001200 case 0:
1201 default:
1202 /* setup MAL tx & rx channel pointers */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001203#if defined(CONFIG_440)
wdenkba56f622004-02-06 23:19:44 +00001204 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +00001205 mtdcr (malrxbattr, 0x0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001206#endif
Stefan Roeseff768cb2007-10-31 18:01:24 +01001207 mtdcr (maltxctp0r, hw_p->tx_phys);
1208 mtdcr (malrxctp0r, hw_p->rx_phys);
wdenkba56f622004-02-06 23:19:44 +00001209 /* set RX buffer size */
1210 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
1211 break;
1212 }
1213
1214 /* Enable MAL transmit and receive channels */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001215#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001216 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
1217#else
wdenkba56f622004-02-06 23:19:44 +00001218 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
Stefan Roesec157d8e2005-08-01 16:41:48 +02001219#endif
wdenkba56f622004-02-06 23:19:44 +00001220 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
1221
1222 /* set transmit enable & receive enable */
Stefan Roese2d834762007-10-23 14:03:17 +02001223 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
wdenkba56f622004-02-06 23:19:44 +00001224
Stefan Roese2d834762007-10-23 14:03:17 +02001225 mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr);
Stefan Roese76957cb2008-03-01 12:11:40 +01001226
1227 /* set rx-/tx-fifo size */
1228 mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
wdenkba56f622004-02-06 23:19:44 +00001229
1230 /* set speed */
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001231 if (speed == _1000BASET) {
Stefan Roese738815c2007-10-02 11:44:46 +02001232#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1233 defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001234 unsigned long pfc1;
Stefan Roese887e2ec2006-09-07 11:51:23 +02001235
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001236 mfsdr (sdr_pfc1, pfc1);
1237 pfc1 |= SDR0_PFC1_EM_1000;
1238 mtsdr (sdr_pfc1, pfc1);
1239#endif
wdenk855a4962004-03-14 18:23:55 +00001240 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001241 } else if (speed == _100BASET)
wdenkba56f622004-02-06 23:19:44 +00001242 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
1243 else
1244 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
1245 if (duplex == FULL)
1246 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
1247
Stefan Roese2d834762007-10-23 14:03:17 +02001248 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
wdenkba56f622004-02-06 23:19:44 +00001249
1250 /* Enable broadcast and indvidual address */
1251 /* TBS: enabling runts as some misbehaved nics will send runts */
Stefan Roese2d834762007-10-23 14:03:17 +02001252 out_be32((void *)EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
wdenkba56f622004-02-06 23:19:44 +00001253
1254 /* we probably need to set the tx mode1 reg? maybe at tx time */
1255
1256 /* set transmit request threshold register */
Stefan Roese2d834762007-10-23 14:03:17 +02001257 out_be32((void *)EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
wdenkba56f622004-02-06 23:19:44 +00001258
Wolfgang Denk265817c2005-09-25 00:53:22 +02001259 /* set receive low/high water mark register */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001260#if defined(CONFIG_440)
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001261 /* 440s has a 64 byte burst length */
Stefan Roese2d834762007-10-23 14:03:17 +02001262 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001263#else
1264 /* 405s have a 16 byte burst length */
Stefan Roese2d834762007-10-23 14:03:17 +02001265 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001266#endif /* defined(CONFIG_440) */
Stefan Roese2d834762007-10-23 14:03:17 +02001267 out_be32((void *)EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
wdenkba56f622004-02-06 23:19:44 +00001268
1269 /* Set fifo limit entry in tx mode 0 */
Stefan Roese2d834762007-10-23 14:03:17 +02001270 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
wdenkba56f622004-02-06 23:19:44 +00001271 /* Frame gap set */
Stefan Roese2d834762007-10-23 14:03:17 +02001272 out_be32((void *)EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
wdenkba56f622004-02-06 23:19:44 +00001273
1274 /* Set EMAC IER */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001275 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
wdenkba56f622004-02-06 23:19:44 +00001276 if (speed == _100BASET)
1277 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1278
Stefan Roese2d834762007-10-23 14:03:17 +02001279 out_be32((void *)EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
1280 out_be32((void *)EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
wdenkba56f622004-02-06 23:19:44 +00001281
1282 if (hw_p->first_init == 0) {
1283 /*
1284 * Connect interrupt service routines
1285 */
Stefan Roesedbbd1252007-10-05 17:10:59 +02001286 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1287 (interrupt_handler_t *) enetInt, dev);
wdenkba56f622004-02-06 23:19:44 +00001288 }
wdenkba56f622004-02-06 23:19:44 +00001289
1290 mtmsr (msr); /* enable interrupts again */
1291
1292 hw_p->bis = bis;
1293 hw_p->first_init = 1;
1294
Stefan Roese802b7692008-01-08 18:39:30 +01001295 return 0;
wdenkba56f622004-02-06 23:19:44 +00001296}
1297
1298
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001299static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
wdenkba56f622004-02-06 23:19:44 +00001300 int len)
1301{
1302 struct enet_frame *ef_ptr;
1303 ulong time_start, time_now;
1304 unsigned long temp_txm0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001305 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001306
1307 ef_ptr = (struct enet_frame *) ptr;
1308
1309 /*-----------------------------------------------------------------------+
1310 * Copy in our address into the frame.
1311 *-----------------------------------------------------------------------*/
1312 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1313
1314 /*-----------------------------------------------------------------------+
1315 * If frame is too long or too short, modify length.
1316 *-----------------------------------------------------------------------*/
1317 /* TBS: where does the fragment go???? */
1318 if (len > ENET_MAX_MTU)
1319 len = ENET_MAX_MTU;
1320
1321 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1322 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001323 flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
wdenkba56f622004-02-06 23:19:44 +00001324
1325 /*-----------------------------------------------------------------------+
1326 * set TX Buffer busy, and send it
1327 *-----------------------------------------------------------------------*/
1328 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1329 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1330 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1331 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1332 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1333
1334 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1335 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1336
Stefan Roese8ac41e32008-03-11 15:05:26 +01001337 sync();
wdenkba56f622004-02-06 23:19:44 +00001338
Stefan Roese2d834762007-10-23 14:03:17 +02001339 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr,
1340 in_be32((void *)EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001341#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001342 hw_p->stats.pkts_tx++;
1343#endif
1344
1345 /*-----------------------------------------------------------------------+
1346 * poll unitl the packet is sent and then make sure it is OK
1347 *-----------------------------------------------------------------------*/
1348 time_start = get_timer (0);
1349 while (1) {
Stefan Roese2d834762007-10-23 14:03:17 +02001350 temp_txm0 = in_be32((void *)EMAC_TXM0 + hw_p->hw_addr);
wdenkba56f622004-02-06 23:19:44 +00001351 /* loop until either TINT turns on or 3 seconds elapse */
1352 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
1353 /* transmit is done, so now check for errors
1354 * If there is an error, an interrupt should
1355 * happen when we return
1356 */
1357 time_now = get_timer (0);
1358 if ((time_now - time_start) > 3000) {
1359 return (-1);
1360 }
1361 } else {
1362 return (len);
1363 }
1364 }
1365}
1366
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001367
Stefan Roesedbbd1252007-10-05 17:10:59 +02001368#if defined (CONFIG_440) || defined(CONFIG_405EX)
wdenkba56f622004-02-06 23:19:44 +00001369
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001370#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001371/*
1372 * Hack: On 440SP all enet irq sources are located on UIC1
1373 * Needs some cleanup. --sr
1374 */
1375#define UIC0MSR uic1msr
1376#define UIC0SR uic1sr
Stefan Roese8ac41e32008-03-11 15:05:26 +01001377#define UIC1MSR uic1msr
1378#define UIC1SR uic1sr
1379#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
1380/*
1381 * Hack: On 460EX/GT all enet irq sources are located on UIC2
1382 * Needs some cleanup. --ag
1383 */
1384#define UIC0MSR uic2msr
1385#define UIC0SR uic2sr
1386#define UIC1MSR uic2msr
1387#define UIC1SR uic2sr
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001388#else
1389#define UIC0MSR uic0msr
1390#define UIC0SR uic0sr
Stefan Roese8ac41e32008-03-11 15:05:26 +01001391#define UIC1MSR uic1msr
1392#define UIC1SR uic1sr
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001393#endif
1394
Stefan Roesedbbd1252007-10-05 17:10:59 +02001395#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1396 defined(CONFIG_405EX)
Stefan Roese887e2ec2006-09-07 11:51:23 +02001397#define UICMSR_ETHX uic0msr
1398#define UICSR_ETHX uic0sr
Stefan Roese8ac41e32008-03-11 15:05:26 +01001399#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
1400#define UICMSR_ETHX uic2msr
1401#define UICSR_ETHX uic2sr
Stefan Roese887e2ec2006-09-07 11:51:23 +02001402#else
1403#define UICMSR_ETHX uic1msr
1404#define UICSR_ETHX uic1sr
1405#endif
1406
wdenkba56f622004-02-06 23:19:44 +00001407int enetInt (struct eth_device *dev)
1408{
1409 int serviced;
1410 int rc = -1; /* default to not us */
1411 unsigned long mal_isr;
1412 unsigned long emac_isr = 0;
1413 unsigned long mal_rx_eob;
1414 unsigned long my_uic0msr, my_uic1msr;
Stefan Roese887e2ec2006-09-07 11:51:23 +02001415 unsigned long my_uicmsr_ethx;
wdenkba56f622004-02-06 23:19:44 +00001416
Stefan Roese846b0dd2005-08-08 12:42:22 +02001417#if defined(CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001418 unsigned long my_uic2msr;
1419#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001420 EMAC_4XX_HW_PST hw_p;
wdenkba56f622004-02-06 23:19:44 +00001421
1422 /*
1423 * Because the mal is generic, we need to get the current
1424 * eth device
1425 */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001426#if defined(CONFIG_NET_MULTI)
1427 dev = eth_get_dev();
1428#else
1429 dev = emac0_dev;
1430#endif
wdenkba56f622004-02-06 23:19:44 +00001431
1432 hw_p = dev->priv;
1433
wdenkba56f622004-02-06 23:19:44 +00001434 /* enter loop that stays in interrupt code until nothing to service */
1435 do {
1436 serviced = 0;
1437
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001438 my_uic0msr = mfdcr (UIC0MSR);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001439 my_uic1msr = mfdcr (UIC1MSR);
Stefan Roese846b0dd2005-08-08 12:42:22 +02001440#if defined(CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001441 my_uic2msr = mfdcr (uic2msr);
1442#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +02001443 my_uicmsr_ethx = mfdcr (UICMSR_ETHX);
1444
wdenkba56f622004-02-06 23:19:44 +00001445 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
Stefan Roese887e2ec2006-09-07 11:51:23 +02001446 && !(my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))
1447 && !(my_uicmsr_ethx & (UIC_ETH0 | UIC_ETH1))) {
wdenkba56f622004-02-06 23:19:44 +00001448 /* not for us */
1449 return (rc);
1450 }
Stefan Roese846b0dd2005-08-08 12:42:22 +02001451#if defined (CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001452 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
1453 && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
1454 /* not for us */
1455 return (rc);
1456 }
1457#endif
1458 /* get and clear controller status interrupts */
1459 /* look at Mal and EMAC interrupts */
1460 if ((my_uic0msr & (UIC_MRE | UIC_MTE))
1461 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1462 /* we have a MAL interrupt */
1463 mal_isr = mfdcr (malesr);
1464 /* look for mal error */
1465 if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
Stefan Roese887e2ec2006-09-07 11:51:23 +02001466 mal_err (dev, mal_isr, my_uic1msr, MAL_UIC_DEF, MAL_UIC_ERR);
wdenkba56f622004-02-06 23:19:44 +00001467 serviced = 1;
1468 rc = 0;
1469 }
1470 }
1471
1472 /* port by port dispatch of emac interrupts */
1473 if (hw_p->devnum == 0) {
Stefan Roese887e2ec2006-09-07 11:51:23 +02001474 if (UIC_ETH0 & my_uicmsr_ethx) { /* look for EMAC errors */
Stefan Roese2d834762007-10-23 14:03:17 +02001475 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
wdenkba56f622004-02-06 23:19:44 +00001476 if ((hw_p->emac_ier & emac_isr) != 0) {
1477 emac_err (dev, emac_isr);
1478 serviced = 1;
1479 rc = 0;
1480 }
1481 }
1482 if ((hw_p->emac_ier & emac_isr)
1483 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001484 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roese8ac41e32008-03-11 15:05:26 +01001485 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001486 mtdcr (UICSR_ETHX, UIC_ETH0); /* Clear */
wdenkba56f622004-02-06 23:19:44 +00001487 return (rc); /* we had errors so get out */
1488 }
1489 }
1490
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001491#if !defined(CONFIG_440SP)
wdenkba56f622004-02-06 23:19:44 +00001492 if (hw_p->devnum == 1) {
Stefan Roese887e2ec2006-09-07 11:51:23 +02001493 if (UIC_ETH1 & my_uicmsr_ethx) { /* look for EMAC errors */
Stefan Roese2d834762007-10-23 14:03:17 +02001494 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
wdenkba56f622004-02-06 23:19:44 +00001495 if ((hw_p->emac_ier & emac_isr) != 0) {
1496 emac_err (dev, emac_isr);
1497 serviced = 1;
1498 rc = 0;
1499 }
1500 }
1501 if ((hw_p->emac_ier & emac_isr)
1502 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001503 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roese8ac41e32008-03-11 15:05:26 +01001504 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001505 mtdcr (UICSR_ETHX, UIC_ETH1); /* Clear */
wdenkba56f622004-02-06 23:19:44 +00001506 return (rc); /* we had errors so get out */
1507 }
1508 }
Stefan Roese846b0dd2005-08-08 12:42:22 +02001509#if defined (CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001510 if (hw_p->devnum == 2) {
1511 if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
Stefan Roese2d834762007-10-23 14:03:17 +02001512 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
wdenkba56f622004-02-06 23:19:44 +00001513 if ((hw_p->emac_ier & emac_isr) != 0) {
1514 emac_err (dev, emac_isr);
1515 serviced = 1;
1516 rc = 0;
1517 }
1518 }
1519 if ((hw_p->emac_ier & emac_isr)
1520 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001521 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roese8ac41e32008-03-11 15:05:26 +01001522 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
wdenkba56f622004-02-06 23:19:44 +00001523 mtdcr (uic2sr, UIC_ETH2);
1524 return (rc); /* we had errors so get out */
1525 }
1526 }
1527
1528 if (hw_p->devnum == 3) {
1529 if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
Stefan Roese2d834762007-10-23 14:03:17 +02001530 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
wdenkba56f622004-02-06 23:19:44 +00001531 if ((hw_p->emac_ier & emac_isr) != 0) {
1532 emac_err (dev, emac_isr);
1533 serviced = 1;
1534 rc = 0;
1535 }
1536 }
1537 if ((hw_p->emac_ier & emac_isr)
1538 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001539 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roese8ac41e32008-03-11 15:05:26 +01001540 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
wdenkba56f622004-02-06 23:19:44 +00001541 mtdcr (uic2sr, UIC_ETH3);
1542 return (rc); /* we had errors so get out */
1543 }
1544 }
Stefan Roese846b0dd2005-08-08 12:42:22 +02001545#endif /* CONFIG_440GX */
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001546#endif /* !CONFIG_440SP */
1547
wdenkba56f622004-02-06 23:19:44 +00001548 /* handle MAX TX EOB interrupt from a tx */
1549 if (my_uic0msr & UIC_MTE) {
1550 mal_rx_eob = mfdcr (maltxeobisr);
1551 mtdcr (maltxeobisr, mal_rx_eob);
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001552 mtdcr (UIC0SR, UIC_MTE);
wdenkba56f622004-02-06 23:19:44 +00001553 }
1554 /* handle MAL RX EOB interupt from a receive */
wdenkfc1cfcd2004-04-25 15:41:35 +00001555 /* check for EOB on valid channels */
wdenkba56f622004-02-06 23:19:44 +00001556 if (my_uic0msr & UIC_MRE) {
1557 mal_rx_eob = mfdcr (malrxeobisr);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001558 if ((mal_rx_eob &
1559 (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)))
1560 != 0) { /* call emac routine for channel x */
wdenkba56f622004-02-06 23:19:44 +00001561 /* clear EOB
1562 mtdcr(malrxeobisr, mal_rx_eob); */
1563 enet_rcv (dev, emac_isr);
1564 /* indicate that we serviced an interrupt */
1565 serviced = 1;
1566 rc = 0;
1567 }
1568 }
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001569
1570 mtdcr (UIC0SR, UIC_MRE); /* Clear */
Stefan Roese8ac41e32008-03-11 15:05:26 +01001571 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
wdenkba56f622004-02-06 23:19:44 +00001572 switch (hw_p->devnum) {
1573 case 0:
Stefan Roese887e2ec2006-09-07 11:51:23 +02001574 mtdcr (UICSR_ETHX, UIC_ETH0);
wdenkba56f622004-02-06 23:19:44 +00001575 break;
1576 case 1:
Stefan Roese887e2ec2006-09-07 11:51:23 +02001577 mtdcr (UICSR_ETHX, UIC_ETH1);
wdenkba56f622004-02-06 23:19:44 +00001578 break;
Stefan Roese846b0dd2005-08-08 12:42:22 +02001579#if defined (CONFIG_440GX)
wdenkba56f622004-02-06 23:19:44 +00001580 case 2:
1581 mtdcr (uic2sr, UIC_ETH2);
1582 break;
1583 case 3:
1584 mtdcr (uic2sr, UIC_ETH3);
1585 break;
Stefan Roese846b0dd2005-08-08 12:42:22 +02001586#endif /* CONFIG_440GX */
wdenkba56f622004-02-06 23:19:44 +00001587 default:
1588 break;
1589 }
1590 } while (serviced);
1591
1592 return (rc);
1593}
1594
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001595#else /* CONFIG_440 */
1596
1597int enetInt (struct eth_device *dev)
1598{
1599 int serviced;
1600 int rc = -1; /* default to not us */
1601 unsigned long mal_isr;
1602 unsigned long emac_isr = 0;
1603 unsigned long mal_rx_eob;
1604 unsigned long my_uicmsr;
1605
1606 EMAC_4XX_HW_PST hw_p;
1607
1608 /*
1609 * Because the mal is generic, we need to get the current
1610 * eth device
1611 */
1612#if defined(CONFIG_NET_MULTI)
1613 dev = eth_get_dev();
1614#else
1615 dev = emac0_dev;
1616#endif
1617
1618 hw_p = dev->priv;
1619
1620 /* enter loop that stays in interrupt code until nothing to service */
1621 do {
1622 serviced = 0;
1623
1624 my_uicmsr = mfdcr (uicmsr);
1625
1626 if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) { /* not for us */
1627 return (rc);
1628 }
1629 /* get and clear controller status interrupts */
1630 /* look at Mal and EMAC interrupts */
1631 if ((MAL_UIC_DEF & my_uicmsr) != 0) { /* we have a MAL interrupt */
1632 mal_isr = mfdcr (malesr);
1633 /* look for mal error */
1634 if ((my_uicmsr & MAL_UIC_ERR) != 0) {
1635 mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR);
1636 serviced = 1;
1637 rc = 0;
1638 }
1639 }
1640
1641 /* port by port dispatch of emac interrupts */
1642
1643 if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) { /* look for EMAC errors */
Stefan Roese2d834762007-10-23 14:03:17 +02001644 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001645 if ((hw_p->emac_ier & emac_isr) != 0) {
1646 emac_err (dev, emac_isr);
1647 serviced = 1;
1648 rc = 0;
1649 }
1650 }
1651 if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) {
1652 mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */
1653 return (rc); /* we had errors so get out */
1654 }
1655
1656 /* handle MAX TX EOB interrupt from a tx */
1657 if (my_uicmsr & UIC_MAL_TXEOB) {
1658 mal_rx_eob = mfdcr (maltxeobisr);
1659 mtdcr (maltxeobisr, mal_rx_eob);
1660 mtdcr (uicsr, UIC_MAL_TXEOB);
1661 }
1662 /* handle MAL RX EOB interupt from a receive */
1663 /* check for EOB on valid channels */
1664 if (my_uicmsr & UIC_MAL_RXEOB)
1665 {
1666 mal_rx_eob = mfdcr (malrxeobisr);
Wolfgang Denk265817c2005-09-25 00:53:22 +02001667 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001668 /* clear EOB
1669 mtdcr(malrxeobisr, mal_rx_eob); */
1670 enet_rcv (dev, emac_isr);
1671 /* indicate that we serviced an interrupt */
1672 serviced = 1;
1673 rc = 0;
1674 }
1675 }
1676 mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1); /* Clear */
Stefan Roesee01bd212007-03-21 13:38:59 +01001677#if defined(CONFIG_405EZ)
1678 mtsdr (sdricintstat, SDR_ICRX_STAT | SDR_ICTX0_STAT | SDR_ICTX1_STAT);
1679#endif /* defined(CONFIG_405EZ) */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001680 }
1681 while (serviced);
1682
1683 return (rc);
1684}
1685
1686#endif /* CONFIG_440 */
1687
wdenkba56f622004-02-06 23:19:44 +00001688/*-----------------------------------------------------------------------------+
1689 * MAL Error Routine
1690 *-----------------------------------------------------------------------------*/
1691static void mal_err (struct eth_device *dev, unsigned long isr,
1692 unsigned long uic, unsigned long maldef,
1693 unsigned long mal_errr)
1694{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001695 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001696
1697 mtdcr (malesr, isr); /* clear interrupt */
1698
1699 /* clear DE interrupt */
1700 mtdcr (maltxdeir, 0xC0000000);
1701 mtdcr (malrxdeir, 0x80000000);
1702
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001703#ifdef INFO_4XX_ENET
Wolfgang Denk265817c2005-09-25 00:53:22 +02001704 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 +00001705#endif
1706
1707 eth_init (hw_p->bis); /* start again... */
1708}
1709
1710/*-----------------------------------------------------------------------------+
1711 * EMAC Error Routine
1712 *-----------------------------------------------------------------------------*/
1713static void emac_err (struct eth_device *dev, unsigned long isr)
1714{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001715 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001716
1717 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
Stefan Roese2d834762007-10-23 14:03:17 +02001718 out_be32((void *)EMAC_ISR + hw_p->hw_addr, isr);
wdenkba56f622004-02-06 23:19:44 +00001719}
1720
1721/*-----------------------------------------------------------------------------+
1722 * enet_rcv() handles the ethernet receive data
1723 *-----------------------------------------------------------------------------*/
1724static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1725{
1726 struct enet_frame *ef_ptr;
1727 unsigned long data_len;
1728 unsigned long rx_eob_isr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001729 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001730
1731 int handled = 0;
1732 int i;
1733 int loop_count = 0;
1734
1735 rx_eob_isr = mfdcr (malrxeobisr);
Stefan Roese8ac41e32008-03-11 15:05:26 +01001736 if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
wdenkba56f622004-02-06 23:19:44 +00001737 /* clear EOB */
1738 mtdcr (malrxeobisr, rx_eob_isr);
1739
1740 /* EMAC RX done */
1741 while (1) { /* do all */
1742 i = hw_p->rx_slot;
1743
1744 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1745 || (loop_count >= NUM_RX_BUFF))
1746 break;
Stefan Roesea2e1c702007-07-12 16:32:08 +02001747
wdenkba56f622004-02-06 23:19:44 +00001748 loop_count++;
wdenkba56f622004-02-06 23:19:44 +00001749 handled++;
Stefan Roese8ac41e32008-03-11 15:05:26 +01001750 data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */
wdenkba56f622004-02-06 23:19:44 +00001751 if (data_len) {
1752 if (data_len > ENET_MAX_MTU) /* Check len */
1753 data_len = 0;
1754 else {
1755 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1756 data_len = 0;
1757 hw_p->stats.rx_err_log[hw_p->
1758 rx_err_index]
1759 = hw_p->rx[i].ctrl;
1760 hw_p->rx_err_index++;
1761 if (hw_p->rx_err_index ==
1762 MAX_ERR_LOG)
1763 hw_p->rx_err_index =
1764 0;
wdenkfc1cfcd2004-04-25 15:41:35 +00001765 } /* emac_erros */
wdenkba56f622004-02-06 23:19:44 +00001766 } /* data_len < max mtu */
wdenkfc1cfcd2004-04-25 15:41:35 +00001767 } /* if data_len */
wdenkba56f622004-02-06 23:19:44 +00001768 if (!data_len) { /* no data */
1769 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1770
1771 hw_p->stats.data_len_err++; /* Error at Rx */
1772 }
1773
1774 /* !data_len */
1775 /* AS.HARNOIS */
1776 /* Check if user has already eaten buffer */
1777 /* if not => ERROR */
1778 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1779 if (hw_p->is_receiving)
1780 printf ("ERROR : Receive buffers are full!\n");
1781 break;
1782 } else {
1783 hw_p->stats.rx_frames++;
1784 hw_p->stats.rx += data_len;
1785 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1786 data_ptr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001787#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001788 hw_p->stats.pkts_rx++;
1789#endif
1790 /* AS.HARNOIS
1791 * use ring buffer
1792 */
1793 hw_p->rx_ready[hw_p->rx_i_index] = i;
1794 hw_p->rx_i_index++;
1795 if (NUM_RX_BUFF == hw_p->rx_i_index)
1796 hw_p->rx_i_index = 0;
1797
Stefan Roesea2e1c702007-07-12 16:32:08 +02001798 hw_p->rx_slot++;
1799 if (NUM_RX_BUFF == hw_p->rx_slot)
1800 hw_p->rx_slot = 0;
1801
wdenkba56f622004-02-06 23:19:44 +00001802 /* AS.HARNOIS
1803 * free receive buffer only when
1804 * buffer has been handled (eth_rx)
1805 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1806 */
1807 } /* if data_len */
1808 } /* while */
1809 } /* if EMACK_RXCHL */
1810}
1811
1812
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001813static int ppc_4xx_eth_rx (struct eth_device *dev)
wdenkba56f622004-02-06 23:19:44 +00001814{
1815 int length;
1816 int user_index;
1817 unsigned long msr;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001818 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenkba56f622004-02-06 23:19:44 +00001819
Wolfgang Denk265817c2005-09-25 00:53:22 +02001820 hw_p->is_receiving = 1; /* tell driver */
wdenkba56f622004-02-06 23:19:44 +00001821
1822 for (;;) {
1823 /* AS.HARNOIS
1824 * use ring buffer and
1825 * get index from rx buffer desciptor queue
1826 */
1827 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1828 if (user_index == -1) {
1829 length = -1;
1830 break; /* nothing received - leave for() loop */
1831 }
1832
1833 msr = mfmsr ();
1834 mtmsr (msr & ~(MSR_EE));
1835
Stefan Roese8ac41e32008-03-11 15:05:26 +01001836 length = hw_p->rx[user_index].data_len & 0x0fff;
wdenkba56f622004-02-06 23:19:44 +00001837
1838 /* Pass the packet up to the protocol layers. */
Wolfgang Denk265817c2005-09-25 00:53:22 +02001839 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1840 /* NetReceive(NetRxPackets[i], length); */
Stefan Roeseff768cb2007-10-31 18:01:24 +01001841 invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
1842 (u32)hw_p->rx[user_index].data_ptr +
Matthias Fuchsba79fde2007-12-14 11:19:56 +01001843 length - 4);
wdenkba56f622004-02-06 23:19:44 +00001844 NetReceive (NetRxPackets[user_index], length - 4);
1845 /* Free Recv Buffer */
1846 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1847 /* Free rx buffer descriptor queue */
1848 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1849 hw_p->rx_u_index++;
1850 if (NUM_RX_BUFF == hw_p->rx_u_index)
1851 hw_p->rx_u_index = 0;
1852
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001853#ifdef INFO_4XX_ENET
wdenkba56f622004-02-06 23:19:44 +00001854 hw_p->stats.pkts_handled++;
1855#endif
1856
1857 mtmsr (msr); /* Enable IRQ's */
1858 }
1859
Wolfgang Denk265817c2005-09-25 00:53:22 +02001860 hw_p->is_receiving = 0; /* tell driver */
wdenkba56f622004-02-06 23:19:44 +00001861
1862 return length;
1863}
1864
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001865int ppc_4xx_eth_initialize (bd_t * bis)
wdenkba56f622004-02-06 23:19:44 +00001866{
1867 static int virgin = 0;
wdenkba56f622004-02-06 23:19:44 +00001868 struct eth_device *dev;
1869 int eth_num = 0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001870 EMAC_4XX_HW_PST hw = NULL;
Stefan Roese5fb692c2007-01-18 10:25:34 +01001871 u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1872 u32 hw_addr[4];
wdenkba56f622004-02-06 23:19:44 +00001873
Stefan Roese846b0dd2005-08-08 12:42:22 +02001874#if defined(CONFIG_440GX)
Stefan Roesec157d8e2005-08-01 16:41:48 +02001875 unsigned long pfc1;
1876
wdenkba56f622004-02-06 23:19:44 +00001877 mfsdr (sdr_pfc1, pfc1);
1878 pfc1 &= ~(0x01e00000);
1879 pfc1 |= 0x01200000;
1880 mtsdr (sdr_pfc1, pfc1);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001881#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001882
1883 /* first clear all mac-addresses */
1884 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1885 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
1886
1887 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1888 switch (eth_num) {
1889 default: /* fall through */
1890 case 0:
1891 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1892 bis->bi_enetaddr, 6);
1893 hw_addr[eth_num] = 0x0;
1894 break;
1895#ifdef CONFIG_HAS_ETH1
1896 case 1:
1897 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1898 bis->bi_enet1addr, 6);
1899 hw_addr[eth_num] = 0x100;
1900 break;
1901#endif
1902#ifdef CONFIG_HAS_ETH2
1903 case 2:
1904 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1905 bis->bi_enet2addr, 6);
Stefan Roese4c9e8552008-03-19 16:20:49 +01001906#if defined(CONFIG_460GT)
1907 hw_addr[eth_num] = 0x300;
1908#else
Stefan Roese5fb692c2007-01-18 10:25:34 +01001909 hw_addr[eth_num] = 0x400;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001910#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001911 break;
1912#endif
1913#ifdef CONFIG_HAS_ETH3
1914 case 3:
1915 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1916 bis->bi_enet3addr, 6);
Stefan Roese4c9e8552008-03-19 16:20:49 +01001917#if defined(CONFIG_460GT)
1918 hw_addr[eth_num] = 0x400;
1919#else
Stefan Roese5fb692c2007-01-18 10:25:34 +01001920 hw_addr[eth_num] = 0x600;
Stefan Roese4c9e8552008-03-19 16:20:49 +01001921#endif
Stefan Roese5fb692c2007-01-18 10:25:34 +01001922 break;
1923#endif
1924 }
1925 }
1926
wdenk3c74e322004-02-22 23:46:08 +00001927 /* set phy num and mode */
1928 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001929 bis->bi_phymode[0] = 0;
1930
Stefan Roesec157d8e2005-08-01 16:41:48 +02001931#if defined(CONFIG_PHY1_ADDR)
wdenk3c74e322004-02-22 23:46:08 +00001932 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001933 bis->bi_phymode[1] = 0;
Stefan Roesec157d8e2005-08-01 16:41:48 +02001934#endif
Stefan Roese846b0dd2005-08-08 12:42:22 +02001935#if defined(CONFIG_440GX)
wdenk3c74e322004-02-22 23:46:08 +00001936 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1937 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
wdenk3c74e322004-02-22 23:46:08 +00001938 bis->bi_phymode[2] = 2;
1939 bis->bi_phymode[3] = 2;
Stefan Roesedbbd1252007-10-05 17:10:59 +02001940#endif
wdenkba56f622004-02-06 23:19:44 +00001941
Stefan Roesedbbd1252007-10-05 17:10:59 +02001942#if defined(CONFIG_440GX) || \
1943 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1944 defined(CONFIG_405EX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001945 ppc_4xx_eth_setup_bridge(0, bis);
wdenka06752e2004-09-29 22:43:59 +00001946#endif
1947
Stefan Roese1e25f952005-10-20 16:34:28 +02001948 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
Stefan Roese5fb692c2007-01-18 10:25:34 +01001949 /*
1950 * See if we can actually bring up the interface,
1951 * otherwise, skip it
1952 */
1953 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
1954 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1955 continue;
wdenkba56f622004-02-06 23:19:44 +00001956 }
1957
1958 /* Allocate device structure */
1959 dev = (struct eth_device *) malloc (sizeof (*dev));
1960 if (dev == NULL) {
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001961 printf ("ppc_4xx_eth_initialize: "
wdenk3f85ce22004-02-23 16:11:30 +00001962 "Cannot allocate eth_device %d\n", eth_num);
wdenkba56f622004-02-06 23:19:44 +00001963 return (-1);
1964 }
wdenkb2532ef2005-06-20 10:17:34 +00001965 memset(dev, 0, sizeof(*dev));
wdenkba56f622004-02-06 23:19:44 +00001966
1967 /* Allocate our private use data */
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001968 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
wdenkba56f622004-02-06 23:19:44 +00001969 if (hw == NULL) {
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001970 printf ("ppc_4xx_eth_initialize: "
wdenk3f85ce22004-02-23 16:11:30 +00001971 "Cannot allocate private hw data for eth_device %d",
wdenkba56f622004-02-06 23:19:44 +00001972 eth_num);
1973 free (dev);
1974 return (-1);
1975 }
wdenkb2532ef2005-06-20 10:17:34 +00001976 memset(hw, 0, sizeof(*hw));
wdenkba56f622004-02-06 23:19:44 +00001977
Stefan Roese5fb692c2007-01-18 10:25:34 +01001978 hw->hw_addr = hw_addr[eth_num];
1979 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
wdenkba56f622004-02-06 23:19:44 +00001980 hw->devnum = eth_num;
Stefan Roesec157d8e2005-08-01 16:41:48 +02001981 hw->print_speed = 1;
wdenkba56f622004-02-06 23:19:44 +00001982
Stefan Roese5fb692c2007-01-18 10:25:34 +01001983 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
wdenkba56f622004-02-06 23:19:44 +00001984 dev->priv = (void *) hw;
Stefan Roesed6c61aa2005-08-16 18:18:00 +02001985 dev->init = ppc_4xx_eth_init;
1986 dev->halt = ppc_4xx_eth_halt;
1987 dev->send = ppc_4xx_eth_send;
1988 dev->recv = ppc_4xx_eth_rx;
wdenkba56f622004-02-06 23:19:44 +00001989
1990 if (0 == virgin) {
1991 /* set the MAL IER ??? names may change with new spec ??? */
Stefan Roesedbbd1252007-10-05 17:10:59 +02001992#if defined(CONFIG_440SPE) || \
1993 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese8ac41e32008-03-11 15:05:26 +01001994 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +02001995 defined(CONFIG_405EX)
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02001996 mal_ier =
1997 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
1998 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
1999#else
wdenkba56f622004-02-06 23:19:44 +00002000 mal_ier =
2001 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
2002 MAL_IER_OPBE | MAL_IER_PLBE;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002003#endif
wdenkba56f622004-02-06 23:19:44 +00002004 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
2005 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
2006 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
2007 mtdcr (malier, mal_ier);
2008
2009 /* install MAL interrupt handler */
2010 irq_install_handler (VECNUM_MS,
2011 (interrupt_handler_t *) enetInt,
2012 dev);
2013 irq_install_handler (VECNUM_MTE,
2014 (interrupt_handler_t *) enetInt,
2015 dev);
2016 irq_install_handler (VECNUM_MRE,
2017 (interrupt_handler_t *) enetInt,
2018 dev);
2019 irq_install_handler (VECNUM_TXDE,
2020 (interrupt_handler_t *) enetInt,
2021 dev);
2022 irq_install_handler (VECNUM_RXDE,
2023 (interrupt_handler_t *) enetInt,
2024 dev);
2025 virgin = 1;
2026 }
2027
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002028#if defined(CONFIG_NET_MULTI)
wdenkba56f622004-02-06 23:19:44 +00002029 eth_register (dev);
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002030#else
2031 emac0_dev = dev;
2032#endif
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002033
2034#if defined(CONFIG_NET_MULTI)
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -05002035#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002036 miiphy_register (dev->name,
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01002037 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002038#endif
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02002039#endif
wdenkba56f622004-02-06 23:19:44 +00002040 } /* end for each supported device */
Stefan Roese802b7692008-01-08 18:39:30 +01002041
2042 return 0;
wdenkba56f622004-02-06 23:19:44 +00002043}
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002044
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002045#if !defined(CONFIG_NET_MULTI)
2046void eth_halt (void) {
2047 if (emac0_dev) {
2048 ppc_4xx_eth_halt(emac0_dev);
2049 free(emac0_dev);
2050 emac0_dev = NULL;
2051 }
2052}
2053
2054int eth_init (bd_t *bis)
2055{
2056 ppc_4xx_eth_initialize(bis);
Stefan Roese4f92ac32005-10-10 17:43:58 +02002057 if (emac0_dev) {
2058 return ppc_4xx_eth_init(emac0_dev, bis);
2059 } else {
2060 printf("ERROR: ethaddr not set!\n");
2061 return -1;
2062 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002063}
2064
2065int eth_send(volatile void *packet, int length)
2066{
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002067 return (ppc_4xx_eth_send(emac0_dev, packet, length));
2068}
2069
2070int eth_rx(void)
2071{
2072 return (ppc_4xx_eth_rx(emac0_dev));
2073}
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002074
2075int emac4xx_miiphy_initialize (bd_t * bis)
2076{
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -05002077#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002078 miiphy_register ("ppc_4xx_eth0",
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01002079 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowicz63ff0042005-10-28 22:30:33 +02002080#endif
2081
2082 return 0;
2083}
Stefan Roesed6c61aa2005-08-16 18:18:00 +02002084#endif /* !defined(CONFIG_NET_MULTI) */
2085
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -05002086#endif