blob: 21ba9228814f1fdb2704ea50203417bcd5f1247f [file] [log] [blame]
wdenk544e9732004-02-06 23:19:44 +00001/*-----------------------------------------------------------------------------+
2 *
Wolfgang Denk0cbaf642005-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.
wdenk544e9732004-02-06 23:19:44 +00009 *
Wolfgang Denk0cbaf642005-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.
wdenk544e9732004-02-06 23:19:44 +000013 *
Wolfgang Denk0cbaf642005-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.
wdenk544e9732004-02-06 23:19:44 +000017 *
Wolfgang Denk0cbaf642005-09-25 00:53:22 +020018 * COPYRIGHT I B M CORPORATION 1995
19 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
wdenk544e9732004-02-06 23:19:44 +000020 *-----------------------------------------------------------------------------*/
21/*-----------------------------------------------------------------------------+
22 *
Wolfgang Denk0cbaf642005-09-25 00:53:22 +020023 * File Name: enetemac.c
wdenk544e9732004-02-06 23:19:44 +000024 *
Wolfgang Denk0cbaf642005-09-25 00:53:22 +020025 * Function: Device driver for the ethernet EMAC3 macro on the 405GP.
wdenk544e9732004-02-06 23:19:44 +000026 *
Wolfgang Denk0cbaf642005-09-25 00:53:22 +020027 * Author: Mark Wisner
wdenk544e9732004-02-06 23:19:44 +000028 *
29 * Change Activity-
30 *
Wolfgang Denk0cbaf642005-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).
wdenk544e9732004-02-06 23:19:44 +000070 *-----------------------------------------------------------------------------*
Wolfgang Denk0cbaf642005-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.
wdenk544e9732004-02-06 23:19:44 +000078 *-----------------------------------------------------------------------------*/
79
80#include <config.h>
wdenk544e9732004-02-06 23:19:44 +000081#include <common.h>
82#include <net.h>
83#include <asm/processor.h>
Stefan Roese697100952007-10-23 14:03:17 +020084#include <asm/io.h>
Stefan Roese9c2a6472007-10-31 18:01:24 +010085#include <asm/cache.h>
86#include <asm/mmu.h>
wdenk544e9732004-02-06 23:19:44 +000087#include <commproc.h>
Stefan Roese0c7ffc02005-08-16 18:18:00 +020088#include <ppc4xx.h>
89#include <ppc4xx_enet.h>
wdenk544e9732004-02-06 23:19:44 +000090#include <405_mal.h>
91#include <miiphy.h>
92#include <malloc.h>
Matthias Fuchs0d548f92008-01-08 15:50:49 +010093#include <asm/ppc4xx-intvec.h>
wdenk544e9732004-02-06 23:19:44 +000094
Stefan Roese0c7ffc02005-08-16 18:18:00 +020095/*
Wolfgang Denk0ee70772005-09-23 11:05:55 +020096 * Only compile for platform with AMCC EMAC ethernet controller and
Stefan Roese0c7ffc02005-08-16 18:18:00 +020097 * network support enabled.
98 * Remark: CONFIG_405 describes Xilinx PPC405 FPGA without EMAC controller!
99 */
Jon Loeligera5217742007-07-09 18:57:22 -0500100#if defined(CONFIG_CMD_NET) && !defined(CONFIG_405) && !defined(CONFIG_IOP480)
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200101
Jon Loeligera5217742007-07-09 18:57:22 -0500102#if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200103#error "CONFIG_MII has to be defined!"
104#endif
wdenk544e9732004-02-06 23:19:44 +0000105
Stefan Roese7f98aec2005-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 Denk0cbaf642005-09-25 00:53:22 +0200110#define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
Stefan Roese3852e232007-10-23 14:05:08 +0200111#define PHY_AUTONEGOTIATE_TIMEOUT 5000 /* 5000 ms autonegotiate timeout */
wdenk544e9732004-02-06 23:19:44 +0000112
wdenk544e9732004-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 Denk0cbaf642005-09-25 00:53:22 +0200118#define ENET_MAX_MTU PKTSIZE
wdenk544e9732004-02-06 23:19:44 +0000119#define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
120
wdenk544e9732004-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 Roese0c7ffc02005-08-16 18:18:00 +0200128#define EMAC_UIC_DEF1 UIC_ENET1
129#define SEL_UIC_DEF(p) (p ? UIC_ENET1 : UIC_ENET )
wdenk544e9732004-02-06 23:19:44 +0000130
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200131#undef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +0000132
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200133#define BI_PHYMODE_NONE 0
134#define BI_PHYMODE_ZMII 1
wdenk56ed43e2004-02-22 23:46:08 +0000135#define BI_PHYMODE_RGMII 2
Stefan Roese42fbddd2006-09-07 11:51:23 +0200136#define BI_PHYMODE_GMII 3
137#define BI_PHYMODE_RTBI 4
138#define BI_PHYMODE_TBI 5
Stefan Roese153b3e22007-10-05 17:10:59 +0200139#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +0100140 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200141 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200142#define BI_PHYMODE_SMII 6
143#define BI_PHYMODE_MII 7
Stefan Roesebdd13d12008-03-11 15:05:26 +0100144#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
145#define BI_PHYMODE_RMII 8
146#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200147#endif
wdenk56ed43e2004-02-22 23:46:08 +0000148
Stefan Roese5a128832007-10-05 17:35:10 +0200149#if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200150 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +0100151 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200152 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200153#define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
154#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200155
Stefan Roesebdd13d12008-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
wdenk544e9732004-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 Roese0c7ffc02005-08-16 18:18:00 +0200172#if !defined(CONFIG_NET_MULTI)
Stefan Roese03510612005-10-10 17:43:58 +0200173struct eth_device *emac0_dev = NULL;
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200174#endif
175
Stefan Roese7f98aec2005-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 Roese15668052007-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 Roese7f98aec2005-10-20 16:34:28 +0200183 */
Stefan Roese15668052007-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 Roese7f98aec2005-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 Roese15668052007-10-23 10:10:08 +0200196#endif /* CONFIG_BOARD_EMAC_COUNT */
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200197
Stefan Roese8d982302007-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 Roese153b3e22007-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 Roese9c2a6472007-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
wdenk544e9732004-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 Balakowiczaab8c492005-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 Roese0c7ffc02005-08-16 18:18:00 +0200229
Stefan Roese15668052007-10-23 10:10:08 +0200230int board_emac_count(void);
231
Stefan Roesebdd13d12008-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
wdenk544e9732004-02-06 23:19:44 +0000270/*-----------------------------------------------------------------------------+
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200271| ppc_4xx_eth_halt
wdenk544e9732004-02-06 23:19:44 +0000272| Disable MAL channel, and EMACn
wdenk544e9732004-02-06 23:19:44 +0000273+-----------------------------------------------------------------------------*/
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200274static void ppc_4xx_eth_halt (struct eth_device *dev)
wdenk544e9732004-02-06 23:19:44 +0000275{
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200276 EMAC_4XX_HW_PST hw_p = dev->priv;
Stefan Roese40b8c0d2008-03-19 16:35:12 +0100277 u32 val = 10000;
wdenk544e9732004-02-06 23:19:44 +0000278
Stefan Roese697100952007-10-23 14:03:17 +0200279 out_be32((void *)EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
wdenk544e9732004-02-06 23:19:44 +0000280
281 /* 1st reset MAL channel */
282 /* Note: writing a 0 to a channel has no effect */
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200283#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
284 mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
285#else
wdenk544e9732004-02-06 23:19:44 +0000286 mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200287#endif
wdenk544e9732004-02-06 23:19:44 +0000288 mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
289
290 /* wait for reset */
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200291 while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
wdenk544e9732004-02-06 23:19:44 +0000292 udelay (1000); /* Delay 1 MS so as not to hammer the register */
Stefan Roese40b8c0d2008-03-19 16:35:12 +0100293 val--;
294 if (val == 0)
wdenk544e9732004-02-06 23:19:44 +0000295 break;
wdenk544e9732004-02-06 23:19:44 +0000296 }
297
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200298 /* provide clocks for EMAC internal loopback */
Stefan Roesebdd13d12008-03-11 15:05:26 +0100299 emac_loopback_enable(hw_p);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200300
Stefan Roesebdd13d12008-03-11 15:05:26 +0100301 /* EMAC RESET */
Stefan Roese697100952007-10-23 14:03:17 +0200302 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenk544e9732004-02-06 23:19:44 +0000303
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200304 /* remove clocks for EMAC internal loopback */
Stefan Roesebdd13d12008-03-11 15:05:26 +0100305 emac_loopback_disable(hw_p);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200306
Stefan Roesec8136d02005-10-18 19:17:12 +0200307#ifndef CONFIG_NETCONSOLE
Stefan Roese326c9712005-08-01 16:41:48 +0200308 hw_p->print_speed = 1; /* print speed message again next time */
Stefan Roesec8136d02005-10-18 19:17:12 +0200309#endif
Stefan Roese326c9712005-08-01 16:41:48 +0200310
Stefan Roese52df4192008-03-19 16:20:49 +0100311#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
312 /* don't bypass the TAHOE0/TAHOE1 cores for Linux */
Stefan Roese40b8c0d2008-03-19 16:35:12 +0100313 mfsdr(SDR0_ETH_CFG, val);
314 val &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
315 mtsdr(SDR0_ETH_CFG, val);
Stefan Roese52df4192008-03-19 16:20:49 +0100316#endif
317
wdenk544e9732004-02-06 23:19:44 +0000318 return;
319}
320
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200321#if defined (CONFIG_440GX)
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200322int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
wdenked2ac4b2004-03-14 18:23:55 +0000323{
324 unsigned long pfc1;
325 unsigned long zmiifer;
326 unsigned long rmiifer;
327
328 mfsdr(sdr_pfc1, pfc1);
329 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
330
331 zmiifer = 0;
332 rmiifer = 0;
333
334 switch (pfc1) {
335 case 1:
336 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
337 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
338 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
339 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
340 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
341 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
342 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
343 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
344 break;
345 case 2:
Stefan Roese0632d7b2006-11-27 17:43:25 +0100346 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
347 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
348 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
349 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
wdenked2ac4b2004-03-14 18:23:55 +0000350 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
351 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
352 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
353 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
354 break;
355 case 3:
356 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
357 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
358 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
359 bis->bi_phymode[1] = BI_PHYMODE_NONE;
360 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
361 bis->bi_phymode[3] = BI_PHYMODE_NONE;
362 break;
363 case 4:
364 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
365 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
366 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
367 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
368 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
369 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
370 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
371 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
372 break;
373 case 5:
374 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
375 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
376 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
377 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
378 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
379 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
380 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
381 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
382 break;
383 case 6:
384 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
385 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
386 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
wdenked2ac4b2004-03-14 18:23:55 +0000387 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
388 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
389 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
wdenked2ac4b2004-03-14 18:23:55 +0000390 break;
391 case 0:
392 default:
393 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
394 rmiifer = 0x0;
395 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
396 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
397 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
398 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
399 break;
400 }
401
402 /* Ensure we setup mdio for this devnum and ONLY this devnum */
403 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
404
Stefan Roese9c2a6472007-10-31 18:01:24 +0100405 out_be32((void *)ZMII_FER, zmiifer);
406 out_be32((void *)RGMII_FER, rmiifer);
wdenked2ac4b2004-03-14 18:23:55 +0000407
408 return ((int)pfc1);
wdenked2ac4b2004-03-14 18:23:55 +0000409}
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200410#endif /* CONFIG_440_GX */
wdenked2ac4b2004-03-14 18:23:55 +0000411
Stefan Roese42fbddd2006-09-07 11:51:23 +0200412#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
413int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
414{
415 unsigned long zmiifer=0x0;
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200416 unsigned long pfc1;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200417
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200418 mfsdr(sdr_pfc1, pfc1);
419 pfc1 &= SDR0_PFC1_SELECT_MASK;
420
Wolfgang Denk58c495b2007-05-05 18:23:11 +0200421 switch (pfc1) {
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200422 case SDR0_PFC1_SELECT_CONFIG_2:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200423 /* 1 x GMII port */
Stefan Roese697100952007-10-23 14:03:17 +0200424 out_be32((void *)ZMII_FER, 0x00);
425 out_be32((void *)RGMII_FER, 0x00000037);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200426 bis->bi_phymode[0] = BI_PHYMODE_GMII;
427 bis->bi_phymode[1] = BI_PHYMODE_NONE;
428 break;
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200429 case SDR0_PFC1_SELECT_CONFIG_4:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200430 /* 2 x RGMII ports */
Stefan Roese697100952007-10-23 14:03:17 +0200431 out_be32((void *)ZMII_FER, 0x00);
432 out_be32((void *)RGMII_FER, 0x00000055);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200433 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
434 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
435 break;
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200436 case SDR0_PFC1_SELECT_CONFIG_6:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200437 /* 2 x SMII ports */
Stefan Roese697100952007-10-23 14:03:17 +0200438 out_be32((void *)ZMII_FER,
439 ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
440 ((ZMII_FER_SMII) << ZMII_FER_V(1)));
441 out_be32((void *)RGMII_FER, 0x00000000);
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200442 bis->bi_phymode[0] = BI_PHYMODE_SMII;
443 bis->bi_phymode[1] = BI_PHYMODE_SMII;
444 break;
445 case SDR0_PFC1_SELECT_CONFIG_1_2:
446 /* only 1 x MII supported */
Stefan Roese697100952007-10-23 14:03:17 +0200447 out_be32((void *)ZMII_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
448 out_be32((void *)RGMII_FER, 0x00000000);
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200449 bis->bi_phymode[0] = BI_PHYMODE_MII;
450 bis->bi_phymode[1] = BI_PHYMODE_NONE;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200451 break;
452 default:
453 break;
454 }
455
456 /* Ensure we setup mdio for this devnum and ONLY this devnum */
Stefan Roese697100952007-10-23 14:03:17 +0200457 zmiifer = in_be32((void *)ZMII_FER);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200458 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
Stefan Roese697100952007-10-23 14:03:17 +0200459 out_be32((void *)ZMII_FER, zmiifer);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200460
461 return ((int)0x0);
462}
463#endif /* CONFIG_440EPX */
464
Stefan Roese153b3e22007-10-05 17:10:59 +0200465#if defined(CONFIG_405EX)
466int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
467{
468 u32 gmiifer = 0;
469
470 /*
471 * Right now only 2*RGMII is supported. Please extend when needed.
472 * sr - 2007-09-19
473 */
474 switch (1) {
475 case 1:
476 /* 2 x RGMII ports */
Stefan Roese697100952007-10-23 14:03:17 +0200477 out_be32((void *)RGMII_FER, 0x00000055);
Stefan Roese153b3e22007-10-05 17:10:59 +0200478 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
479 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
480 break;
481 case 2:
482 /* 2 x SMII ports */
483 break;
484 default:
485 break;
486 }
487
488 /* Ensure we setup mdio for this devnum and ONLY this devnum */
Stefan Roese697100952007-10-23 14:03:17 +0200489 gmiifer = in_be32((void *)RGMII_FER);
Stefan Roese153b3e22007-10-05 17:10:59 +0200490 gmiifer |= (1 << (19-devnum));
Stefan Roese697100952007-10-23 14:03:17 +0200491 out_be32((void *)RGMII_FER, gmiifer);
Stefan Roese153b3e22007-10-05 17:10:59 +0200492
493 return ((int)0x0);
494}
495#endif /* CONFIG_405EX */
496
Stefan Roesebdd13d12008-03-11 15:05:26 +0100497#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
498int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
499{
500 u32 eth_cfg;
501 u32 zmiifer; /* ZMII0_FER reg. */
502 u32 rmiifer; /* RGMII0_FER reg. Bridge 0 */
503 u32 rmiifer1; /* RGMII0_FER reg. Bridge 1 */
Stefan Roese52df4192008-03-19 16:20:49 +0100504 int mode;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100505
506 zmiifer = 0;
507 rmiifer = 0;
508 rmiifer1 = 0;
509
Stefan Roese52df4192008-03-19 16:20:49 +0100510#if defined(CONFIG_460EX)
511 mode = 9;
512#else
513 mode = 10;
514#endif
515
Stefan Roesebdd13d12008-03-11 15:05:26 +0100516 /* TODO:
517 * NOTE: 460GT has 2 RGMII bridge cores:
518 * emac0 ------ RGMII0_BASE
519 * |
520 * emac1 -----+
521 *
522 * emac2 ------ RGMII1_BASE
523 * |
524 * emac3 -----+
525 *
526 * 460EX has 1 RGMII bridge core:
527 * and RGMII1_BASE is disabled
528 * emac0 ------ RGMII0_BASE
529 * |
530 * emac1 -----+
531 */
532
533 /*
534 * Right now only 2*RGMII is supported. Please extend when needed.
535 * sr - 2008-02-19
536 */
Stefan Roese52df4192008-03-19 16:20:49 +0100537 switch (mode) {
Stefan Roesebdd13d12008-03-11 15:05:26 +0100538 case 1:
539 /* 1 MII - 460EX */
540 /* GMC0 EMAC4_0, ZMII Bridge */
541 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
542 bis->bi_phymode[0] = BI_PHYMODE_MII;
543 bis->bi_phymode[1] = BI_PHYMODE_NONE;
544 bis->bi_phymode[2] = BI_PHYMODE_NONE;
545 bis->bi_phymode[3] = BI_PHYMODE_NONE;
546 break;
547 case 2:
548 /* 2 MII - 460GT */
549 /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */
550 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
551 zmiifer |= ZMII_FER_MII << ZMII_FER_V(2);
552 bis->bi_phymode[0] = BI_PHYMODE_MII;
553 bis->bi_phymode[1] = BI_PHYMODE_NONE;
554 bis->bi_phymode[2] = BI_PHYMODE_MII;
555 bis->bi_phymode[3] = BI_PHYMODE_NONE;
556 break;
557 case 3:
558 /* 2 RMII - 460EX */
559 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
560 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
561 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
562 bis->bi_phymode[0] = BI_PHYMODE_RMII;
563 bis->bi_phymode[1] = BI_PHYMODE_RMII;
564 bis->bi_phymode[2] = BI_PHYMODE_NONE;
565 bis->bi_phymode[3] = BI_PHYMODE_NONE;
566 break;
567 case 4:
568 /* 4 RMII - 460GT */
569 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */
570 /* ZMII Bridge */
571 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
572 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
573 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
574 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
575 bis->bi_phymode[0] = BI_PHYMODE_RMII;
576 bis->bi_phymode[1] = BI_PHYMODE_RMII;
577 bis->bi_phymode[2] = BI_PHYMODE_RMII;
578 bis->bi_phymode[3] = BI_PHYMODE_RMII;
579 break;
580 case 5:
581 /* 2 SMII - 460EX */
582 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
583 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
584 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
585 bis->bi_phymode[0] = BI_PHYMODE_SMII;
586 bis->bi_phymode[1] = BI_PHYMODE_SMII;
587 bis->bi_phymode[2] = BI_PHYMODE_NONE;
588 bis->bi_phymode[3] = BI_PHYMODE_NONE;
589 break;
590 case 6:
591 /* 4 SMII - 460GT */
592 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */
593 /* ZMII Bridge */
594 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
595 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
596 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
597 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
598 bis->bi_phymode[0] = BI_PHYMODE_SMII;
599 bis->bi_phymode[1] = BI_PHYMODE_SMII;
600 bis->bi_phymode[2] = BI_PHYMODE_SMII;
601 bis->bi_phymode[3] = BI_PHYMODE_SMII;
602 break;
603 case 7:
604 /* This is the default mode that we want for board bringup - Maple */
605 /* 1 GMII - 460EX */
606 /* GMC0 EMAC4_0, RGMII Bridge 0 */
607 rmiifer |= RGMII_FER_MDIO(0);
608
609 if (devnum == 0) {
610 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
611 bis->bi_phymode[0] = BI_PHYMODE_GMII;
612 bis->bi_phymode[1] = BI_PHYMODE_NONE;
613 bis->bi_phymode[2] = BI_PHYMODE_NONE;
614 bis->bi_phymode[3] = BI_PHYMODE_NONE;
615 } else {
616 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3); /* CH1CFG - EMAC1 */
617 bis->bi_phymode[0] = BI_PHYMODE_NONE;
618 bis->bi_phymode[1] = BI_PHYMODE_GMII;
619 bis->bi_phymode[2] = BI_PHYMODE_NONE;
620 bis->bi_phymode[3] = BI_PHYMODE_NONE;
621 }
622 break;
623 case 8:
624 /* 2 GMII - 460GT */
625 /* GMC0 EMAC4_0, RGMII Bridge 0 */
626 /* GMC1 EMAC4_2, RGMII Bridge 1 */
627 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
628 rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC2 */
629 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
630 rmiifer1 |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC2 */
631
632 bis->bi_phymode[0] = BI_PHYMODE_GMII;
633 bis->bi_phymode[1] = BI_PHYMODE_NONE;
634 bis->bi_phymode[2] = BI_PHYMODE_GMII;
635 bis->bi_phymode[3] = BI_PHYMODE_NONE;
636 break;
637 case 9:
638 /* 2 RGMII - 460EX */
639 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
640 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
641 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
642 rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
643
644 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
645 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
646 bis->bi_phymode[2] = BI_PHYMODE_NONE;
647 bis->bi_phymode[3] = BI_PHYMODE_NONE;
648 break;
649 case 10:
650 /* 4 RGMII - 460GT */
651 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
652 /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */
653 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
654 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
655 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2);
656 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3);
657 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
658 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
659 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
660 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
661 break;
662 default:
663 break;
664 }
665
666 /* Set EMAC for MDIO */
667 mfsdr(SDR0_ETH_CFG, eth_cfg);
668 eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
669 mtsdr(SDR0_ETH_CFG, eth_cfg);
670
671 out_be32((void *)RGMII_FER, rmiifer);
672#if defined(CONFIG_460GT)
673 out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1);
674#endif
675
676 /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
677 mfsdr(SDR0_ETH_CFG, eth_cfg);
678 eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
679 mtsdr(SDR0_ETH_CFG, eth_cfg);
680
681 return 0;
682}
683#endif /* CONFIG_460EX || CONFIG_460GT */
684
Stefan Roese9c2a6472007-10-31 18:01:24 +0100685static inline void *malloc_aligned(u32 size, u32 align)
686{
687 return (void *)(((u32)malloc(size + align) + align - 1) &
688 ~(align - 1));
689}
690
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200691static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
wdenk544e9732004-02-06 23:19:44 +0000692{
Stefan Roese9c2a6472007-10-31 18:01:24 +0100693 int i;
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200694 unsigned long reg = 0;
wdenk544e9732004-02-06 23:19:44 +0000695 unsigned long msr;
696 unsigned long speed;
697 unsigned long duplex;
698 unsigned long failsafe;
699 unsigned mode_reg;
700 unsigned short devnum;
701 unsigned short reg_short;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200702#if defined(CONFIG_440GX) || \
703 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200704 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +0100705 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200706 defined(CONFIG_405EX)
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200707 sys_info_t sysinfo;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200708#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200709 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +0100710 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200711 defined(CONFIG_405EX)
Stefan Roese99644742005-11-29 18:18:21 +0100712 int ethgroup = -1;
713#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200714#endif
Stefan Roese9c2a6472007-10-31 18:01:24 +0100715 u32 bd_cached;
716 u32 bd_uncached = 0;
Anatolij Gustschina41f9182008-02-25 20:54:04 +0100717#ifdef CONFIG_4xx_DCACHE
718 static u32 last_used_ea = 0;
719#endif
wdenk544e9732004-02-06 23:19:44 +0000720
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200721 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +0000722
723 /* before doing anything, figure out if we have a MAC address */
724 /* if not, bail */
Stefan Roese03510612005-10-10 17:43:58 +0200725 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
726 printf("ERROR: ethaddr not set!\n");
wdenk544e9732004-02-06 23:19:44 +0000727 return -1;
Stefan Roese03510612005-10-10 17:43:58 +0200728 }
wdenk544e9732004-02-06 23:19:44 +0000729
Stefan Roese42fbddd2006-09-07 11:51:23 +0200730#if defined(CONFIG_440GX) || \
731 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200732 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +0100733 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200734 defined(CONFIG_405EX)
wdenk544e9732004-02-06 23:19:44 +0000735 /* Need to get the OPB frequency so we can access the PHY */
736 get_sys_info (&sysinfo);
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200737#endif
wdenk544e9732004-02-06 23:19:44 +0000738
wdenk544e9732004-02-06 23:19:44 +0000739 msr = mfmsr ();
740 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
741
742 devnum = hw_p->devnum;
743
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200744#ifdef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +0000745 /* AS.HARNOIS
746 * We should have :
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200747 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
wdenk544e9732004-02-06 23:19:44 +0000748 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
749 * is possible that new packets (without relationship with
750 * current transfer) have got the time to arrived before
751 * netloop calls eth_halt
752 */
753 printf ("About preceeding transfer (eth%d):\n"
754 "- Sent packet number %d\n"
755 "- Received packet number %d\n"
756 "- Handled packet number %d\n",
757 hw_p->devnum,
758 hw_p->stats.pkts_tx,
759 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
760
761 hw_p->stats.pkts_tx = 0;
762 hw_p->stats.pkts_rx = 0;
763 hw_p->stats.pkts_handled = 0;
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200764 hw_p->print_speed = 1; /* print speed message again next time */
wdenk544e9732004-02-06 23:19:44 +0000765#endif
766
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200767 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
768 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
wdenk544e9732004-02-06 23:19:44 +0000769
770 hw_p->rx_slot = 0; /* MAL Receive Slot */
771 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
772 hw_p->rx_u_index = 0; /* Receive User Queue Index */
773
774 hw_p->tx_slot = 0; /* MAL Transmit Slot */
775 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
776 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
777
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200778#if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
wdenk544e9732004-02-06 23:19:44 +0000779 /* set RMII mode */
780 /* NOTE: 440GX spec states that mode is mutually exclusive */
781 /* NOTE: Therefore, disable all other EMACS, since we handle */
782 /* NOTE: only one emac at a time */
783 reg = 0;
Stefan Roese697100952007-10-23 14:03:17 +0200784 out_be32((void *)ZMII_FER, 0);
wdenk544e9732004-02-06 23:19:44 +0000785 udelay (100);
wdenk544e9732004-02-06 23:19:44 +0000786
Stefan Roesebdd13d12008-03-11 15:05:26 +0100787#if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese697100952007-10-23 14:03:17 +0200788 out_be32((void *)ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
Stefan Roesebdd13d12008-03-11 15:05:26 +0100789#elif defined(CONFIG_440GX) || \
790 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
791 defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200792 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
wdenk00fe1612004-03-14 00:07:33 +0000793#endif
Stefan Roese797d8572005-08-11 17:56:56 +0200794
Stefan Roese697100952007-10-23 14:03:17 +0200795 out_be32((void *)ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
Stefan Roese99644742005-11-29 18:18:21 +0100796#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
Stefan Roese153b3e22007-10-05 17:10:59 +0200797#if defined(CONFIG_405EX)
798 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
799#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200800
Stefan Roesebdd13d12008-03-11 15:05:26 +0100801 sync();
wdenk00fe1612004-03-14 00:07:33 +0000802
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200803 /* provide clocks for EMAC internal loopback */
Stefan Roesebdd13d12008-03-11 15:05:26 +0100804 emac_loopback_enable(hw_p);
wdenk00fe1612004-03-14 00:07:33 +0000805
Stefan Roesebdd13d12008-03-11 15:05:26 +0100806 /* EMAC RESET */
Stefan Roese697100952007-10-23 14:03:17 +0200807 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenk544e9732004-02-06 23:19:44 +0000808
Stefan Roesebdd13d12008-03-11 15:05:26 +0100809 /* remove clocks for EMAC internal loopback */
810 emac_loopback_disable(hw_p);
811
wdenk544e9732004-02-06 23:19:44 +0000812 failsafe = 1000;
Stefan Roese697100952007-10-23 14:03:17 +0200813 while ((in_be32((void *)EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
wdenk544e9732004-02-06 23:19:44 +0000814 udelay (1000);
815 failsafe--;
816 }
Stefan Roese42fbddd2006-09-07 11:51:23 +0200817 if (failsafe <= 0)
818 printf("\nProblem resetting EMAC!\n");
wdenk544e9732004-02-06 23:19:44 +0000819
Stefan Roese42fbddd2006-09-07 11:51:23 +0200820#if defined(CONFIG_440GX) || \
821 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200822 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +0100823 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200824 defined(CONFIG_405EX)
wdenk544e9732004-02-06 23:19:44 +0000825 /* Whack the M1 register */
826 mode_reg = 0x0;
827 mode_reg &= ~0x00000038;
828 if (sysinfo.freqOPB <= 50000000);
829 else if (sysinfo.freqOPB <= 66666667)
830 mode_reg |= EMAC_M1_OBCI_66;
831 else if (sysinfo.freqOPB <= 83333333)
832 mode_reg |= EMAC_M1_OBCI_83;
833 else if (sysinfo.freqOPB <= 100000000)
834 mode_reg |= EMAC_M1_OBCI_100;
835 else
836 mode_reg |= EMAC_M1_OBCI_GT100;
837
Stefan Roese697100952007-10-23 14:03:17 +0200838 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
Stefan Roese99644742005-11-29 18:18:21 +0100839#endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
wdenk544e9732004-02-06 23:19:44 +0000840
841 /* wait for PHY to complete auto negotiation */
842 reg_short = 0;
843#ifndef CONFIG_CS8952_PHY
844 switch (devnum) {
845 case 0:
846 reg = CONFIG_PHY_ADDR;
847 break;
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200848#if defined (CONFIG_PHY1_ADDR)
wdenk544e9732004-02-06 23:19:44 +0000849 case 1:
850 reg = CONFIG_PHY1_ADDR;
851 break;
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200852#endif
Stefan Roese52df4192008-03-19 16:20:49 +0100853#if defined (CONFIG_PHY2_ADDR)
wdenk544e9732004-02-06 23:19:44 +0000854 case 2:
855 reg = CONFIG_PHY2_ADDR;
856 break;
Stefan Roese52df4192008-03-19 16:20:49 +0100857#endif
858#if defined (CONFIG_PHY3_ADDR)
wdenk544e9732004-02-06 23:19:44 +0000859 case 3:
860 reg = CONFIG_PHY3_ADDR;
861 break;
862#endif
863 default:
864 reg = CONFIG_PHY_ADDR;
865 break;
866 }
867
wdenk56ed43e2004-02-22 23:46:08 +0000868 bis->bi_phynum[devnum] = reg;
869
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200870#if defined(CONFIG_PHY_RESET)
wdenk97e8bda2004-09-29 22:43:59 +0000871 /*
872 * Reset the phy, only if its the first time through
873 * otherwise, just check the speeds & feeds
874 */
875 if (hw_p->first_init == 0) {
Stefan Roese21df1a42006-11-27 14:46:06 +0100876#if defined(CONFIG_M88E1111_PHY)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200877 miiphy_write (dev->name, reg, 0x14, 0x0ce3);
878 miiphy_write (dev->name, reg, 0x18, 0x4101);
879 miiphy_write (dev->name, reg, 0x09, 0x0e00);
880 miiphy_write (dev->name, reg, 0x04, 0x01e1);
881#endif
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200882 miiphy_reset (dev->name, reg);
wdenk544e9732004-02-06 23:19:44 +0000883
Stefan Roese42fbddd2006-09-07 11:51:23 +0200884#if defined(CONFIG_440GX) || \
885 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200886 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +0100887 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200888 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200889
wdenk00fe1612004-03-14 00:07:33 +0000890#if defined(CONFIG_CIS8201_PHY)
wdenk7ad5e4c2004-04-25 15:41:35 +0000891 /*
Stefan Roese363330b2005-08-04 17:09:16 +0200892 * Cicada 8201 PHY needs to have an extended register whacked
893 * for RGMII mode.
wdenk7ad5e4c2004-04-25 15:41:35 +0000894 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200895 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200896#if defined(CONFIG_CIS8201_SHORT_ETCH)
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200897 miiphy_write (dev->name, reg, 23, 0x1300);
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200898#else
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200899 miiphy_write (dev->name, reg, 23, 0x1000);
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200900#endif
Stefan Roese363330b2005-08-04 17:09:16 +0200901 /*
902 * Vitesse VSC8201/Cicada CIS8201 errata:
903 * Interoperability problem with Intel 82547EI phys
904 * This work around (provided by Vitesse) changes
905 * the default timer convergence from 8ms to 12ms
906 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200907 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
908 miiphy_write (dev->name, reg, 0x08, 0x0200);
909 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
910 miiphy_write (dev->name, reg, 0x02, 0x0004);
911 miiphy_write (dev->name, reg, 0x01, 0x0671);
912 miiphy_write (dev->name, reg, 0x00, 0x8fae);
913 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
914 miiphy_write (dev->name, reg, 0x08, 0x0000);
915 miiphy_write (dev->name, reg, 0x1f, 0x0000);
Stefan Roese363330b2005-08-04 17:09:16 +0200916 /* end Vitesse/Cicada errata */
917 }
wdenk00fe1612004-03-14 00:07:33 +0000918#endif
Stefan Roese8d982302007-01-18 10:25:34 +0100919
920#if defined(CONFIG_ET1011C_PHY)
921 /*
922 * Agere ET1011c PHY needs to have an extended register whacked
923 * for RGMII mode.
924 */
925 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
926 miiphy_read (dev->name, reg, 0x16, &reg_short);
927 reg_short &= ~(0x7);
928 reg_short |= 0x6; /* RGMII DLL Delay*/
929 miiphy_write (dev->name, reg, 0x16, reg_short);
930
931 miiphy_read (dev->name, reg, 0x17, &reg_short);
932 reg_short &= ~(0x40);
933 miiphy_write (dev->name, reg, 0x17, reg_short);
934
935 miiphy_write(dev->name, reg, 0x1c, 0x74f0);
936 }
937#endif
938
wdenked2ac4b2004-03-14 18:23:55 +0000939#endif
wdenk97e8bda2004-09-29 22:43:59 +0000940 /* Start/Restart autonegotiation */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200941 phy_setup_aneg (dev->name, reg);
wdenk97e8bda2004-09-29 22:43:59 +0000942 udelay (1000);
943 }
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200944#endif /* defined(CONFIG_PHY_RESET) */
wdenk544e9732004-02-06 23:19:44 +0000945
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200946 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenk544e9732004-02-06 23:19:44 +0000947
948 /*
wdenk00fe1612004-03-14 00:07:33 +0000949 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
wdenk544e9732004-02-06 23:19:44 +0000950 */
951 if ((reg_short & PHY_BMSR_AUTN_ABLE)
952 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
953 puts ("Waiting for PHY auto negotiation to complete");
954 i = 0;
955 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
956 /*
957 * Timeout reached ?
958 */
959 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
960 puts (" TIMEOUT !\n");
961 break;
962 }
963
964 if ((i++ % 1000) == 0) {
965 putc ('.');
966 }
967 udelay (1000); /* 1 ms */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200968 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenk544e9732004-02-06 23:19:44 +0000969
970 }
971 puts (" done\n");
972 udelay (500000); /* another 500 ms (results in faster booting) */
973 }
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200974#endif /* #ifndef CONFIG_CS8952_PHY */
975
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200976 speed = miiphy_speed (dev->name, reg);
977 duplex = miiphy_duplex (dev->name, reg);
wdenk544e9732004-02-06 23:19:44 +0000978
979 if (hw_p->print_speed) {
980 hw_p->print_speed = 0;
Stefan Roese8d982302007-01-18 10:25:34 +0100981 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
982 (int) speed, (duplex == HALF) ? "HALF" : "FULL",
983 hw_p->devnum);
wdenk544e9732004-02-06 23:19:44 +0000984 }
985
Stefan Roesebdd13d12008-03-11 15:05:26 +0100986#if defined(CONFIG_440) && \
987 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
988 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
989 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200990#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese326c9712005-08-01 16:41:48 +0200991 mfsdr(sdr_mfr, reg);
992 if (speed == 100) {
993 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
994 } else {
995 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
996 }
997 mtsdr(sdr_mfr, reg);
998#endif
Stefan Roese797d8572005-08-11 17:56:56 +0200999
wdenk544e9732004-02-06 23:19:44 +00001000 /* Set ZMII/RGMII speed according to the phy link speed */
Stefan Roese9c2a6472007-10-31 18:01:24 +01001001 reg = in_be32((void *)ZMII_SSR);
wdenked2ac4b2004-03-14 18:23:55 +00001002 if ( (speed == 100) || (speed == 1000) )
Stefan Roese9c2a6472007-10-31 18:01:24 +01001003 out_be32((void *)ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
wdenk544e9732004-02-06 23:19:44 +00001004 else
Stefan Roese9c2a6472007-10-31 18:01:24 +01001005 out_be32((void *)ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
wdenk544e9732004-02-06 23:19:44 +00001006
1007 if ((devnum == 2) || (devnum == 3)) {
1008 if (speed == 1000)
1009 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1010 else if (speed == 100)
1011 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
Stefan Roese42fbddd2006-09-07 11:51:23 +02001012 else if (speed == 10)
wdenk544e9732004-02-06 23:19:44 +00001013 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
Stefan Roese42fbddd2006-09-07 11:51:23 +02001014 else {
1015 printf("Error in RGMII Speed\n");
1016 return -1;
1017 }
Stefan Roese9c2a6472007-10-31 18:01:24 +01001018 out_be32((void *)RGMII_SSR, reg);
wdenk544e9732004-02-06 23:19:44 +00001019 }
Stefan Roese99644742005-11-29 18:18:21 +01001020#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
wdenk544e9732004-02-06 23:19:44 +00001021
Stefan Roese153b3e22007-10-05 17:10:59 +02001022#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +01001023 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +02001024 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +02001025 if (speed == 1000)
1026 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1027 else if (speed == 100)
1028 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
1029 else if (speed == 10)
1030 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
1031 else {
1032 printf("Error in RGMII Speed\n");
1033 return -1;
1034 }
Stefan Roese697100952007-10-23 14:03:17 +02001035 out_be32((void *)RGMII_SSR, reg);
Stefan Roesebdd13d12008-03-11 15:05:26 +01001036#if defined(CONFIG_460GT)
1037 if ((devnum == 2) || (devnum == 3))
1038 out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
1039#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +02001040#endif
1041
wdenk544e9732004-02-06 23:19:44 +00001042 /* set the Mal configuration reg */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001043#if defined(CONFIG_440GX) || \
1044 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +02001045 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +01001046 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +02001047 defined(CONFIG_405EX)
Stefan Roese363330b2005-08-04 17:09:16 +02001048 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
1049 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
1050#else
1051 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
wdenk544e9732004-02-06 23:19:44 +00001052 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
Stefan Roese363330b2005-08-04 17:09:16 +02001053 if (get_pvr() == PVR_440GP_RB) {
1054 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
1055 }
1056#endif
wdenk544e9732004-02-06 23:19:44 +00001057
wdenk544e9732004-02-06 23:19:44 +00001058 /*
1059 * Malloc MAL buffer desciptors, make sure they are
1060 * aligned on cache line boundary size
1061 * (401/403/IOP480 = 16, 405 = 32)
1062 * and doesn't cross cache block boundaries.
1063 */
Stefan Roese9c2a6472007-10-31 18:01:24 +01001064 if (hw_p->first_init == 0) {
1065 debug("*** Allocating descriptor memory ***\n");
wdenk544e9732004-02-06 23:19:44 +00001066
Stefan Roese9c2a6472007-10-31 18:01:24 +01001067 bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
1068 if (!bd_cached) {
1069 printf("%s: Error allocating MAL descriptor buffers!\n");
1070 return -1;
1071 }
Stefan Roese5ff4c3f2005-08-15 12:31:23 +02001072
Stefan Roese9c2a6472007-10-31 18:01:24 +01001073#ifdef CONFIG_4xx_DCACHE
Matthias Fuchs211105a2007-12-14 11:19:56 +01001074 flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
Anatolij Gustschina41f9182008-02-25 20:54:04 +01001075 if (!last_used_ea)
1076 bd_uncached = bis->bi_memsize;
1077 else
1078 bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
1079
1080 last_used_ea = bd_uncached;
Stefan Roese9c2a6472007-10-31 18:01:24 +01001081 program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
1082 TLB_WORD2_I_ENABLE);
1083#else
1084 bd_uncached = bd_cached;
1085#endif
1086 hw_p->tx_phys = bd_cached;
1087 hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
1088 hw_p->tx = (mal_desc_t *)(bd_uncached);
1089 hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
1090 debug("hw_p->tx=%08x, hw_p->rx=%08x\n", hw_p->tx, hw_p->rx);
wdenk544e9732004-02-06 23:19:44 +00001091 }
1092
1093 for (i = 0; i < NUM_TX_BUFF; i++) {
1094 hw_p->tx[i].ctrl = 0;
1095 hw_p->tx[i].data_len = 0;
Stefan Roese9c2a6472007-10-31 18:01:24 +01001096 if (hw_p->first_init == 0)
1097 hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
1098 L1_CACHE_BYTES);
wdenk544e9732004-02-06 23:19:44 +00001099 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
1100 if ((NUM_TX_BUFF - 1) == i)
1101 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
1102 hw_p->tx_run[i] = -1;
Stefan Roese9c2a6472007-10-31 18:01:24 +01001103 debug("TX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->tx[i].data_ptr);
wdenk544e9732004-02-06 23:19:44 +00001104 }
1105
1106 for (i = 0; i < NUM_RX_BUFF; i++) {
1107 hw_p->rx[i].ctrl = 0;
1108 hw_p->rx[i].data_len = 0;
Stefan Roese9c2a6472007-10-31 18:01:24 +01001109 hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
wdenk544e9732004-02-06 23:19:44 +00001110 if ((NUM_RX_BUFF - 1) == i)
1111 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
1112 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
1113 hw_p->rx_ready[i] = -1;
Stefan Roese9c2a6472007-10-31 18:01:24 +01001114 debug("RX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->rx[i].data_ptr);
wdenk544e9732004-02-06 23:19:44 +00001115 }
1116
1117 reg = 0x00000000;
1118
1119 reg |= dev->enetaddr[0]; /* set high address */
1120 reg = reg << 8;
1121 reg |= dev->enetaddr[1];
1122
Stefan Roese697100952007-10-23 14:03:17 +02001123 out_be32((void *)EMAC_IAH + hw_p->hw_addr, reg);
wdenk544e9732004-02-06 23:19:44 +00001124
1125 reg = 0x00000000;
1126 reg |= dev->enetaddr[2]; /* set low address */
1127 reg = reg << 8;
1128 reg |= dev->enetaddr[3];
1129 reg = reg << 8;
1130 reg |= dev->enetaddr[4];
1131 reg = reg << 8;
1132 reg |= dev->enetaddr[5];
1133
Stefan Roese697100952007-10-23 14:03:17 +02001134 out_be32((void *)EMAC_IAL + hw_p->hw_addr, reg);
wdenk544e9732004-02-06 23:19:44 +00001135
1136 switch (devnum) {
1137 case 1:
1138 /* setup MAL tx & rx channel pointers */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001139#if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
Stefan Roese9c2a6472007-10-31 18:01:24 +01001140 mtdcr (maltxctp2r, hw_p->tx_phys);
Stefan Roese326c9712005-08-01 16:41:48 +02001141#else
Stefan Roese9c2a6472007-10-31 18:01:24 +01001142 mtdcr (maltxctp1r, hw_p->tx_phys);
Stefan Roese326c9712005-08-01 16:41:48 +02001143#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001144#if defined(CONFIG_440)
Stefan Roese326c9712005-08-01 16:41:48 +02001145 mtdcr (maltxbattr, 0x0);
wdenk544e9732004-02-06 23:19:44 +00001146 mtdcr (malrxbattr, 0x0);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001147#endif
Stefan Roesebdd13d12008-03-11 15:05:26 +01001148
1149#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
Stefan Roese52df4192008-03-19 16:20:49 +01001150 mtdcr (malrxctp8r, hw_p->rx_phys);
Stefan Roesebdd13d12008-03-11 15:05:26 +01001151 /* set RX buffer size */
1152 mtdcr (malrcbs8, ENET_MAX_MTU_ALIGNED / 16);
1153#else
Stefan Roese9c2a6472007-10-31 18:01:24 +01001154 mtdcr (malrxctp1r, hw_p->rx_phys);
wdenk544e9732004-02-06 23:19:44 +00001155 /* set RX buffer size */
1156 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
Stefan Roesebdd13d12008-03-11 15:05:26 +01001157#endif
wdenk544e9732004-02-06 23:19:44 +00001158 break;
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001159#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001160 case 2:
1161 /* setup MAL tx & rx channel pointers */
1162 mtdcr (maltxbattr, 0x0);
wdenk544e9732004-02-06 23:19:44 +00001163 mtdcr (malrxbattr, 0x0);
Stefan Roese9c2a6472007-10-31 18:01:24 +01001164 mtdcr (maltxctp2r, hw_p->tx_phys);
1165 mtdcr (malrxctp2r, hw_p->rx_phys);
wdenk544e9732004-02-06 23:19:44 +00001166 /* set RX buffer size */
1167 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
1168 break;
1169 case 3:
1170 /* setup MAL tx & rx channel pointers */
1171 mtdcr (maltxbattr, 0x0);
Stefan Roese9c2a6472007-10-31 18:01:24 +01001172 mtdcr (maltxctp3r, hw_p->tx_phys);
wdenk544e9732004-02-06 23:19:44 +00001173 mtdcr (malrxbattr, 0x0);
Stefan Roese9c2a6472007-10-31 18:01:24 +01001174 mtdcr (malrxctp3r, hw_p->rx_phys);
wdenk544e9732004-02-06 23:19:44 +00001175 /* set RX buffer size */
1176 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
1177 break;
Stefan Roese797d8572005-08-11 17:56:56 +02001178#endif /* CONFIG_440GX */
Stefan Roese52df4192008-03-19 16:20:49 +01001179#if defined (CONFIG_460GT)
1180 case 2:
1181 /* setup MAL tx & rx channel pointers */
1182 mtdcr (maltxbattr, 0x0);
1183 mtdcr (malrxbattr, 0x0);
1184 mtdcr (maltxctp2r, hw_p->tx_phys);
1185 mtdcr (malrxctp16r, hw_p->rx_phys);
1186 /* set RX buffer size */
1187 mtdcr (malrcbs16, ENET_MAX_MTU_ALIGNED / 16);
1188 break;
1189 case 3:
1190 /* setup MAL tx & rx channel pointers */
1191 mtdcr (maltxbattr, 0x0);
1192 mtdcr (malrxbattr, 0x0);
1193 mtdcr (maltxctp3r, hw_p->tx_phys);
1194 mtdcr (malrxctp24r, hw_p->rx_phys);
1195 /* set RX buffer size */
1196 mtdcr (malrcbs24, ENET_MAX_MTU_ALIGNED / 16);
1197 break;
1198#endif /* CONFIG_460GT */
wdenk544e9732004-02-06 23:19:44 +00001199 case 0:
1200 default:
1201 /* setup MAL tx & rx channel pointers */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001202#if defined(CONFIG_440)
wdenk544e9732004-02-06 23:19:44 +00001203 mtdcr (maltxbattr, 0x0);
wdenk544e9732004-02-06 23:19:44 +00001204 mtdcr (malrxbattr, 0x0);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001205#endif
Stefan Roese9c2a6472007-10-31 18:01:24 +01001206 mtdcr (maltxctp0r, hw_p->tx_phys);
1207 mtdcr (malrxctp0r, hw_p->rx_phys);
wdenk544e9732004-02-06 23:19:44 +00001208 /* set RX buffer size */
1209 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
1210 break;
1211 }
1212
1213 /* Enable MAL transmit and receive channels */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001214#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese326c9712005-08-01 16:41:48 +02001215 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
1216#else
wdenk544e9732004-02-06 23:19:44 +00001217 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
Stefan Roese326c9712005-08-01 16:41:48 +02001218#endif
wdenk544e9732004-02-06 23:19:44 +00001219 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
1220
1221 /* set transmit enable & receive enable */
Stefan Roese697100952007-10-23 14:03:17 +02001222 out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
wdenk544e9732004-02-06 23:19:44 +00001223
Stefan Roese697100952007-10-23 14:03:17 +02001224 mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr);
Stefan Roeseca5ef8c2008-03-01 12:11:40 +01001225
1226 /* set rx-/tx-fifo size */
1227 mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
wdenk544e9732004-02-06 23:19:44 +00001228
1229 /* set speed */
Stefan Roese99644742005-11-29 18:18:21 +01001230 if (speed == _1000BASET) {
Stefan Roese43867c82007-10-02 11:44:46 +02001231#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1232 defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese99644742005-11-29 18:18:21 +01001233 unsigned long pfc1;
Stefan Roese42fbddd2006-09-07 11:51:23 +02001234
Stefan Roese99644742005-11-29 18:18:21 +01001235 mfsdr (sdr_pfc1, pfc1);
1236 pfc1 |= SDR0_PFC1_EM_1000;
1237 mtsdr (sdr_pfc1, pfc1);
1238#endif
wdenked2ac4b2004-03-14 18:23:55 +00001239 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
Stefan Roese99644742005-11-29 18:18:21 +01001240 } else if (speed == _100BASET)
wdenk544e9732004-02-06 23:19:44 +00001241 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
1242 else
1243 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
1244 if (duplex == FULL)
1245 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
1246
Stefan Roese697100952007-10-23 14:03:17 +02001247 out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
wdenk544e9732004-02-06 23:19:44 +00001248
1249 /* Enable broadcast and indvidual address */
1250 /* TBS: enabling runts as some misbehaved nics will send runts */
Stefan Roese697100952007-10-23 14:03:17 +02001251 out_be32((void *)EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
wdenk544e9732004-02-06 23:19:44 +00001252
1253 /* we probably need to set the tx mode1 reg? maybe at tx time */
1254
1255 /* set transmit request threshold register */
Stefan Roese697100952007-10-23 14:03:17 +02001256 out_be32((void *)EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
wdenk544e9732004-02-06 23:19:44 +00001257
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001258 /* set receive low/high water mark register */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001259#if defined(CONFIG_440)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001260 /* 440s has a 64 byte burst length */
Stefan Roese697100952007-10-23 14:03:17 +02001261 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001262#else
1263 /* 405s have a 16 byte burst length */
Stefan Roese697100952007-10-23 14:03:17 +02001264 out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001265#endif /* defined(CONFIG_440) */
Stefan Roese697100952007-10-23 14:03:17 +02001266 out_be32((void *)EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
wdenk544e9732004-02-06 23:19:44 +00001267
1268 /* Set fifo limit entry in tx mode 0 */
Stefan Roese697100952007-10-23 14:03:17 +02001269 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
wdenk544e9732004-02-06 23:19:44 +00001270 /* Frame gap set */
Stefan Roese697100952007-10-23 14:03:17 +02001271 out_be32((void *)EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
wdenk544e9732004-02-06 23:19:44 +00001272
1273 /* Set EMAC IER */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001274 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
wdenk544e9732004-02-06 23:19:44 +00001275 if (speed == _100BASET)
1276 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1277
Stefan Roese697100952007-10-23 14:03:17 +02001278 out_be32((void *)EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
1279 out_be32((void *)EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
wdenk544e9732004-02-06 23:19:44 +00001280
1281 if (hw_p->first_init == 0) {
1282 /*
1283 * Connect interrupt service routines
1284 */
Stefan Roese153b3e22007-10-05 17:10:59 +02001285 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1286 (interrupt_handler_t *) enetInt, dev);
wdenk544e9732004-02-06 23:19:44 +00001287 }
wdenk544e9732004-02-06 23:19:44 +00001288
1289 mtmsr (msr); /* enable interrupts again */
1290
1291 hw_p->bis = bis;
1292 hw_p->first_init = 1;
1293
Stefan Roese8111a0e2008-01-08 18:39:30 +01001294 return 0;
wdenk544e9732004-02-06 23:19:44 +00001295}
1296
1297
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001298static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
wdenk544e9732004-02-06 23:19:44 +00001299 int len)
1300{
1301 struct enet_frame *ef_ptr;
1302 ulong time_start, time_now;
1303 unsigned long temp_txm0;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001304 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001305
1306 ef_ptr = (struct enet_frame *) ptr;
1307
1308 /*-----------------------------------------------------------------------+
1309 * Copy in our address into the frame.
1310 *-----------------------------------------------------------------------*/
1311 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1312
1313 /*-----------------------------------------------------------------------+
1314 * If frame is too long or too short, modify length.
1315 *-----------------------------------------------------------------------*/
1316 /* TBS: where does the fragment go???? */
1317 if (len > ENET_MAX_MTU)
1318 len = ENET_MAX_MTU;
1319
1320 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1321 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
Matthias Fuchs211105a2007-12-14 11:19:56 +01001322 flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
wdenk544e9732004-02-06 23:19:44 +00001323
1324 /*-----------------------------------------------------------------------+
1325 * set TX Buffer busy, and send it
1326 *-----------------------------------------------------------------------*/
1327 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1328 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1329 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1330 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1331 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1332
1333 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1334 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1335
Stefan Roesebdd13d12008-03-11 15:05:26 +01001336 sync();
wdenk544e9732004-02-06 23:19:44 +00001337
Stefan Roese697100952007-10-23 14:03:17 +02001338 out_be32((void *)EMAC_TXM0 + hw_p->hw_addr,
1339 in_be32((void *)EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001340#ifdef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +00001341 hw_p->stats.pkts_tx++;
1342#endif
1343
1344 /*-----------------------------------------------------------------------+
1345 * poll unitl the packet is sent and then make sure it is OK
1346 *-----------------------------------------------------------------------*/
1347 time_start = get_timer (0);
1348 while (1) {
Stefan Roese697100952007-10-23 14:03:17 +02001349 temp_txm0 = in_be32((void *)EMAC_TXM0 + hw_p->hw_addr);
wdenk544e9732004-02-06 23:19:44 +00001350 /* loop until either TINT turns on or 3 seconds elapse */
1351 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
1352 /* transmit is done, so now check for errors
1353 * If there is an error, an interrupt should
1354 * happen when we return
1355 */
1356 time_now = get_timer (0);
1357 if ((time_now - time_start) > 3000) {
1358 return (-1);
1359 }
1360 } else {
1361 return (len);
1362 }
1363 }
1364}
1365
Stefan Roese99644742005-11-29 18:18:21 +01001366
Stefan Roese153b3e22007-10-05 17:10:59 +02001367#if defined (CONFIG_440) || defined(CONFIG_405EX)
wdenk544e9732004-02-06 23:19:44 +00001368
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001369#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese99644742005-11-29 18:18:21 +01001370/*
1371 * Hack: On 440SP all enet irq sources are located on UIC1
1372 * Needs some cleanup. --sr
1373 */
1374#define UIC0MSR uic1msr
1375#define UIC0SR uic1sr
Stefan Roesebdd13d12008-03-11 15:05:26 +01001376#define UIC1MSR uic1msr
1377#define UIC1SR uic1sr
1378#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
1379/*
1380 * Hack: On 460EX/GT all enet irq sources are located on UIC2
1381 * Needs some cleanup. --ag
1382 */
1383#define UIC0MSR uic2msr
1384#define UIC0SR uic2sr
1385#define UIC1MSR uic2msr
1386#define UIC1SR uic2sr
Stefan Roese99644742005-11-29 18:18:21 +01001387#else
1388#define UIC0MSR uic0msr
1389#define UIC0SR uic0sr
Stefan Roesebdd13d12008-03-11 15:05:26 +01001390#define UIC1MSR uic1msr
1391#define UIC1SR uic1sr
Stefan Roese99644742005-11-29 18:18:21 +01001392#endif
1393
Stefan Roese153b3e22007-10-05 17:10:59 +02001394#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1395 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +02001396#define UICMSR_ETHX uic0msr
1397#define UICSR_ETHX uic0sr
Stefan Roesebdd13d12008-03-11 15:05:26 +01001398#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
1399#define UICMSR_ETHX uic2msr
1400#define UICSR_ETHX uic2sr
Stefan Roese42fbddd2006-09-07 11:51:23 +02001401#else
1402#define UICMSR_ETHX uic1msr
1403#define UICSR_ETHX uic1sr
1404#endif
1405
wdenk544e9732004-02-06 23:19:44 +00001406int enetInt (struct eth_device *dev)
1407{
1408 int serviced;
1409 int rc = -1; /* default to not us */
1410 unsigned long mal_isr;
1411 unsigned long emac_isr = 0;
1412 unsigned long mal_rx_eob;
1413 unsigned long my_uic0msr, my_uic1msr;
Stefan Roese42fbddd2006-09-07 11:51:23 +02001414 unsigned long my_uicmsr_ethx;
wdenk544e9732004-02-06 23:19:44 +00001415
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001416#if defined(CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001417 unsigned long my_uic2msr;
1418#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001419 EMAC_4XX_HW_PST hw_p;
wdenk544e9732004-02-06 23:19:44 +00001420
1421 /*
1422 * Because the mal is generic, we need to get the current
1423 * eth device
1424 */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001425#if defined(CONFIG_NET_MULTI)
1426 dev = eth_get_dev();
1427#else
1428 dev = emac0_dev;
1429#endif
wdenk544e9732004-02-06 23:19:44 +00001430
1431 hw_p = dev->priv;
1432
wdenk544e9732004-02-06 23:19:44 +00001433 /* enter loop that stays in interrupt code until nothing to service */
1434 do {
1435 serviced = 0;
1436
Stefan Roese99644742005-11-29 18:18:21 +01001437 my_uic0msr = mfdcr (UIC0MSR);
Stefan Roesebdd13d12008-03-11 15:05:26 +01001438 my_uic1msr = mfdcr (UIC1MSR);
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001439#if defined(CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001440 my_uic2msr = mfdcr (uic2msr);
1441#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +02001442 my_uicmsr_ethx = mfdcr (UICMSR_ETHX);
1443
wdenk544e9732004-02-06 23:19:44 +00001444 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
Stefan Roese42fbddd2006-09-07 11:51:23 +02001445 && !(my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))
1446 && !(my_uicmsr_ethx & (UIC_ETH0 | UIC_ETH1))) {
wdenk544e9732004-02-06 23:19:44 +00001447 /* not for us */
1448 return (rc);
1449 }
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001450#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001451 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
1452 && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
1453 /* not for us */
1454 return (rc);
1455 }
1456#endif
1457 /* get and clear controller status interrupts */
1458 /* look at Mal and EMAC interrupts */
1459 if ((my_uic0msr & (UIC_MRE | UIC_MTE))
1460 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1461 /* we have a MAL interrupt */
1462 mal_isr = mfdcr (malesr);
1463 /* look for mal error */
1464 if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
Stefan Roese42fbddd2006-09-07 11:51:23 +02001465 mal_err (dev, mal_isr, my_uic1msr, MAL_UIC_DEF, MAL_UIC_ERR);
wdenk544e9732004-02-06 23:19:44 +00001466 serviced = 1;
1467 rc = 0;
1468 }
1469 }
1470
1471 /* port by port dispatch of emac interrupts */
1472 if (hw_p->devnum == 0) {
Stefan Roese42fbddd2006-09-07 11:51:23 +02001473 if (UIC_ETH0 & my_uicmsr_ethx) { /* look for EMAC errors */
Stefan Roese697100952007-10-23 14:03:17 +02001474 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
wdenk544e9732004-02-06 23:19:44 +00001475 if ((hw_p->emac_ier & emac_isr) != 0) {
1476 emac_err (dev, emac_isr);
1477 serviced = 1;
1478 rc = 0;
1479 }
1480 }
1481 if ((hw_p->emac_ier & emac_isr)
1482 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese99644742005-11-29 18:18:21 +01001483 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roesebdd13d12008-03-11 15:05:26 +01001484 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001485 mtdcr (UICSR_ETHX, UIC_ETH0); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001486 return (rc); /* we had errors so get out */
1487 }
1488 }
1489
Stefan Roese99644742005-11-29 18:18:21 +01001490#if !defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +00001491 if (hw_p->devnum == 1) {
Stefan Roese42fbddd2006-09-07 11:51:23 +02001492 if (UIC_ETH1 & my_uicmsr_ethx) { /* look for EMAC errors */
Stefan Roese697100952007-10-23 14:03:17 +02001493 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
wdenk544e9732004-02-06 23:19:44 +00001494 if ((hw_p->emac_ier & emac_isr) != 0) {
1495 emac_err (dev, emac_isr);
1496 serviced = 1;
1497 rc = 0;
1498 }
1499 }
1500 if ((hw_p->emac_ier & emac_isr)
1501 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese99644742005-11-29 18:18:21 +01001502 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roesebdd13d12008-03-11 15:05:26 +01001503 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001504 mtdcr (UICSR_ETHX, UIC_ETH1); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001505 return (rc); /* we had errors so get out */
1506 }
1507 }
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001508#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001509 if (hw_p->devnum == 2) {
1510 if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
Stefan Roese697100952007-10-23 14:03:17 +02001511 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
wdenk544e9732004-02-06 23:19:44 +00001512 if ((hw_p->emac_ier & emac_isr) != 0) {
1513 emac_err (dev, emac_isr);
1514 serviced = 1;
1515 rc = 0;
1516 }
1517 }
1518 if ((hw_p->emac_ier & emac_isr)
1519 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese99644742005-11-29 18:18:21 +01001520 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roesebdd13d12008-03-11 15:05:26 +01001521 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001522 mtdcr (uic2sr, UIC_ETH2);
1523 return (rc); /* we had errors so get out */
1524 }
1525 }
1526
1527 if (hw_p->devnum == 3) {
1528 if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
Stefan Roese697100952007-10-23 14:03:17 +02001529 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
wdenk544e9732004-02-06 23:19:44 +00001530 if ((hw_p->emac_ier & emac_isr) != 0) {
1531 emac_err (dev, emac_isr);
1532 serviced = 1;
1533 rc = 0;
1534 }
1535 }
1536 if ((hw_p->emac_ier & emac_isr)
1537 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese99644742005-11-29 18:18:21 +01001538 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roesebdd13d12008-03-11 15:05:26 +01001539 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001540 mtdcr (uic2sr, UIC_ETH3);
1541 return (rc); /* we had errors so get out */
1542 }
1543 }
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001544#endif /* CONFIG_440GX */
Stefan Roese99644742005-11-29 18:18:21 +01001545#endif /* !CONFIG_440SP */
1546
wdenk544e9732004-02-06 23:19:44 +00001547 /* handle MAX TX EOB interrupt from a tx */
1548 if (my_uic0msr & UIC_MTE) {
1549 mal_rx_eob = mfdcr (maltxeobisr);
1550 mtdcr (maltxeobisr, mal_rx_eob);
Stefan Roese99644742005-11-29 18:18:21 +01001551 mtdcr (UIC0SR, UIC_MTE);
wdenk544e9732004-02-06 23:19:44 +00001552 }
1553 /* handle MAL RX EOB interupt from a receive */
wdenk7ad5e4c2004-04-25 15:41:35 +00001554 /* check for EOB on valid channels */
wdenk544e9732004-02-06 23:19:44 +00001555 if (my_uic0msr & UIC_MRE) {
1556 mal_rx_eob = mfdcr (malrxeobisr);
Stefan Roesebdd13d12008-03-11 15:05:26 +01001557 if ((mal_rx_eob &
1558 (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)))
1559 != 0) { /* call emac routine for channel x */
wdenk544e9732004-02-06 23:19:44 +00001560 /* clear EOB
1561 mtdcr(malrxeobisr, mal_rx_eob); */
1562 enet_rcv (dev, emac_isr);
1563 /* indicate that we serviced an interrupt */
1564 serviced = 1;
1565 rc = 0;
1566 }
1567 }
Stefan Roese99644742005-11-29 18:18:21 +01001568
1569 mtdcr (UIC0SR, UIC_MRE); /* Clear */
Stefan Roesebdd13d12008-03-11 15:05:26 +01001570 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001571 switch (hw_p->devnum) {
1572 case 0:
Stefan Roese42fbddd2006-09-07 11:51:23 +02001573 mtdcr (UICSR_ETHX, UIC_ETH0);
wdenk544e9732004-02-06 23:19:44 +00001574 break;
1575 case 1:
Stefan Roese42fbddd2006-09-07 11:51:23 +02001576 mtdcr (UICSR_ETHX, UIC_ETH1);
wdenk544e9732004-02-06 23:19:44 +00001577 break;
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001578#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001579 case 2:
1580 mtdcr (uic2sr, UIC_ETH2);
1581 break;
1582 case 3:
1583 mtdcr (uic2sr, UIC_ETH3);
1584 break;
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001585#endif /* CONFIG_440GX */
wdenk544e9732004-02-06 23:19:44 +00001586 default:
1587 break;
1588 }
1589 } while (serviced);
1590
1591 return (rc);
1592}
1593
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001594#else /* CONFIG_440 */
1595
1596int enetInt (struct eth_device *dev)
1597{
1598 int serviced;
1599 int rc = -1; /* default to not us */
1600 unsigned long mal_isr;
1601 unsigned long emac_isr = 0;
1602 unsigned long mal_rx_eob;
1603 unsigned long my_uicmsr;
1604
1605 EMAC_4XX_HW_PST hw_p;
1606
1607 /*
1608 * Because the mal is generic, we need to get the current
1609 * eth device
1610 */
1611#if defined(CONFIG_NET_MULTI)
1612 dev = eth_get_dev();
1613#else
1614 dev = emac0_dev;
1615#endif
1616
1617 hw_p = dev->priv;
1618
1619 /* enter loop that stays in interrupt code until nothing to service */
1620 do {
1621 serviced = 0;
1622
1623 my_uicmsr = mfdcr (uicmsr);
1624
1625 if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) { /* not for us */
1626 return (rc);
1627 }
1628 /* get and clear controller status interrupts */
1629 /* look at Mal and EMAC interrupts */
1630 if ((MAL_UIC_DEF & my_uicmsr) != 0) { /* we have a MAL interrupt */
1631 mal_isr = mfdcr (malesr);
1632 /* look for mal error */
1633 if ((my_uicmsr & MAL_UIC_ERR) != 0) {
1634 mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR);
1635 serviced = 1;
1636 rc = 0;
1637 }
1638 }
1639
1640 /* port by port dispatch of emac interrupts */
1641
1642 if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) { /* look for EMAC errors */
Stefan Roese697100952007-10-23 14:03:17 +02001643 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001644 if ((hw_p->emac_ier & emac_isr) != 0) {
1645 emac_err (dev, emac_isr);
1646 serviced = 1;
1647 rc = 0;
1648 }
1649 }
1650 if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) {
1651 mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */
1652 return (rc); /* we had errors so get out */
1653 }
1654
1655 /* handle MAX TX EOB interrupt from a tx */
1656 if (my_uicmsr & UIC_MAL_TXEOB) {
1657 mal_rx_eob = mfdcr (maltxeobisr);
1658 mtdcr (maltxeobisr, mal_rx_eob);
1659 mtdcr (uicsr, UIC_MAL_TXEOB);
1660 }
1661 /* handle MAL RX EOB interupt from a receive */
1662 /* check for EOB on valid channels */
1663 if (my_uicmsr & UIC_MAL_RXEOB)
1664 {
1665 mal_rx_eob = mfdcr (malrxeobisr);
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001666 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001667 /* clear EOB
1668 mtdcr(malrxeobisr, mal_rx_eob); */
1669 enet_rcv (dev, emac_isr);
1670 /* indicate that we serviced an interrupt */
1671 serviced = 1;
1672 rc = 0;
1673 }
1674 }
1675 mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1); /* Clear */
Stefan Roese17ffbc82007-03-21 13:38:59 +01001676#if defined(CONFIG_405EZ)
1677 mtsdr (sdricintstat, SDR_ICRX_STAT | SDR_ICTX0_STAT | SDR_ICTX1_STAT);
1678#endif /* defined(CONFIG_405EZ) */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001679 }
1680 while (serviced);
1681
1682 return (rc);
1683}
1684
1685#endif /* CONFIG_440 */
1686
wdenk544e9732004-02-06 23:19:44 +00001687/*-----------------------------------------------------------------------------+
1688 * MAL Error Routine
1689 *-----------------------------------------------------------------------------*/
1690static void mal_err (struct eth_device *dev, unsigned long isr,
1691 unsigned long uic, unsigned long maldef,
1692 unsigned long mal_errr)
1693{
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001694 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001695
1696 mtdcr (malesr, isr); /* clear interrupt */
1697
1698 /* clear DE interrupt */
1699 mtdcr (maltxdeir, 0xC0000000);
1700 mtdcr (malrxdeir, 0x80000000);
1701
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001702#ifdef INFO_4XX_ENET
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001703 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
wdenk544e9732004-02-06 23:19:44 +00001704#endif
1705
1706 eth_init (hw_p->bis); /* start again... */
1707}
1708
1709/*-----------------------------------------------------------------------------+
1710 * EMAC Error Routine
1711 *-----------------------------------------------------------------------------*/
1712static void emac_err (struct eth_device *dev, unsigned long isr)
1713{
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001714 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001715
1716 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
Stefan Roese697100952007-10-23 14:03:17 +02001717 out_be32((void *)EMAC_ISR + hw_p->hw_addr, isr);
wdenk544e9732004-02-06 23:19:44 +00001718}
1719
1720/*-----------------------------------------------------------------------------+
1721 * enet_rcv() handles the ethernet receive data
1722 *-----------------------------------------------------------------------------*/
1723static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1724{
1725 struct enet_frame *ef_ptr;
1726 unsigned long data_len;
1727 unsigned long rx_eob_isr;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001728 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001729
1730 int handled = 0;
1731 int i;
1732 int loop_count = 0;
1733
1734 rx_eob_isr = mfdcr (malrxeobisr);
Stefan Roesebdd13d12008-03-11 15:05:26 +01001735 if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
wdenk544e9732004-02-06 23:19:44 +00001736 /* clear EOB */
1737 mtdcr (malrxeobisr, rx_eob_isr);
1738
1739 /* EMAC RX done */
1740 while (1) { /* do all */
1741 i = hw_p->rx_slot;
1742
1743 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1744 || (loop_count >= NUM_RX_BUFF))
1745 break;
Stefan Roese09feb382007-07-12 16:32:08 +02001746
wdenk544e9732004-02-06 23:19:44 +00001747 loop_count++;
wdenk544e9732004-02-06 23:19:44 +00001748 handled++;
Stefan Roesebdd13d12008-03-11 15:05:26 +01001749 data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */
wdenk544e9732004-02-06 23:19:44 +00001750 if (data_len) {
1751 if (data_len > ENET_MAX_MTU) /* Check len */
1752 data_len = 0;
1753 else {
1754 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1755 data_len = 0;
1756 hw_p->stats.rx_err_log[hw_p->
1757 rx_err_index]
1758 = hw_p->rx[i].ctrl;
1759 hw_p->rx_err_index++;
1760 if (hw_p->rx_err_index ==
1761 MAX_ERR_LOG)
1762 hw_p->rx_err_index =
1763 0;
wdenk7ad5e4c2004-04-25 15:41:35 +00001764 } /* emac_erros */
wdenk544e9732004-02-06 23:19:44 +00001765 } /* data_len < max mtu */
wdenk7ad5e4c2004-04-25 15:41:35 +00001766 } /* if data_len */
wdenk544e9732004-02-06 23:19:44 +00001767 if (!data_len) { /* no data */
1768 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1769
1770 hw_p->stats.data_len_err++; /* Error at Rx */
1771 }
1772
1773 /* !data_len */
1774 /* AS.HARNOIS */
1775 /* Check if user has already eaten buffer */
1776 /* if not => ERROR */
1777 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1778 if (hw_p->is_receiving)
1779 printf ("ERROR : Receive buffers are full!\n");
1780 break;
1781 } else {
1782 hw_p->stats.rx_frames++;
1783 hw_p->stats.rx += data_len;
1784 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1785 data_ptr;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001786#ifdef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +00001787 hw_p->stats.pkts_rx++;
1788#endif
1789 /* AS.HARNOIS
1790 * use ring buffer
1791 */
1792 hw_p->rx_ready[hw_p->rx_i_index] = i;
1793 hw_p->rx_i_index++;
1794 if (NUM_RX_BUFF == hw_p->rx_i_index)
1795 hw_p->rx_i_index = 0;
1796
Stefan Roese09feb382007-07-12 16:32:08 +02001797 hw_p->rx_slot++;
1798 if (NUM_RX_BUFF == hw_p->rx_slot)
1799 hw_p->rx_slot = 0;
1800
wdenk544e9732004-02-06 23:19:44 +00001801 /* AS.HARNOIS
1802 * free receive buffer only when
1803 * buffer has been handled (eth_rx)
1804 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1805 */
1806 } /* if data_len */
1807 } /* while */
1808 } /* if EMACK_RXCHL */
1809}
1810
1811
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001812static int ppc_4xx_eth_rx (struct eth_device *dev)
wdenk544e9732004-02-06 23:19:44 +00001813{
1814 int length;
1815 int user_index;
1816 unsigned long msr;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001817 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001818
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001819 hw_p->is_receiving = 1; /* tell driver */
wdenk544e9732004-02-06 23:19:44 +00001820
1821 for (;;) {
1822 /* AS.HARNOIS
1823 * use ring buffer and
1824 * get index from rx buffer desciptor queue
1825 */
1826 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1827 if (user_index == -1) {
1828 length = -1;
1829 break; /* nothing received - leave for() loop */
1830 }
1831
1832 msr = mfmsr ();
1833 mtmsr (msr & ~(MSR_EE));
1834
Stefan Roesebdd13d12008-03-11 15:05:26 +01001835 length = hw_p->rx[user_index].data_len & 0x0fff;
wdenk544e9732004-02-06 23:19:44 +00001836
1837 /* Pass the packet up to the protocol layers. */
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001838 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1839 /* NetReceive(NetRxPackets[i], length); */
Stefan Roese9c2a6472007-10-31 18:01:24 +01001840 invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
1841 (u32)hw_p->rx[user_index].data_ptr +
Matthias Fuchs211105a2007-12-14 11:19:56 +01001842 length - 4);
wdenk544e9732004-02-06 23:19:44 +00001843 NetReceive (NetRxPackets[user_index], length - 4);
1844 /* Free Recv Buffer */
1845 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1846 /* Free rx buffer descriptor queue */
1847 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1848 hw_p->rx_u_index++;
1849 if (NUM_RX_BUFF == hw_p->rx_u_index)
1850 hw_p->rx_u_index = 0;
1851
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001852#ifdef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +00001853 hw_p->stats.pkts_handled++;
1854#endif
1855
1856 mtmsr (msr); /* Enable IRQ's */
1857 }
1858
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001859 hw_p->is_receiving = 0; /* tell driver */
wdenk544e9732004-02-06 23:19:44 +00001860
1861 return length;
1862}
1863
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001864int ppc_4xx_eth_initialize (bd_t * bis)
wdenk544e9732004-02-06 23:19:44 +00001865{
1866 static int virgin = 0;
wdenk544e9732004-02-06 23:19:44 +00001867 struct eth_device *dev;
1868 int eth_num = 0;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001869 EMAC_4XX_HW_PST hw = NULL;
Stefan Roese8d982302007-01-18 10:25:34 +01001870 u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1871 u32 hw_addr[4];
wdenk544e9732004-02-06 23:19:44 +00001872
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001873#if defined(CONFIG_440GX)
Stefan Roese326c9712005-08-01 16:41:48 +02001874 unsigned long pfc1;
1875
wdenk544e9732004-02-06 23:19:44 +00001876 mfsdr (sdr_pfc1, pfc1);
1877 pfc1 &= ~(0x01e00000);
1878 pfc1 |= 0x01200000;
1879 mtsdr (sdr_pfc1, pfc1);
Stefan Roese326c9712005-08-01 16:41:48 +02001880#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001881
Stefan Roese8d982302007-01-18 10:25:34 +01001882 /* first clear all mac-addresses */
1883 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1884 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
wdenk97e8bda2004-09-29 22:43:59 +00001885
Stefan Roese7f98aec2005-10-20 16:34:28 +02001886 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
wdenk544e9732004-02-06 23:19:44 +00001887 switch (eth_num) {
wdenk54070ab2004-12-31 09:32:47 +00001888 default: /* fall through */
wdenk544e9732004-02-06 23:19:44 +00001889 case 0:
Stefan Roese8d982302007-01-18 10:25:34 +01001890 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1891 bis->bi_enetaddr, 6);
1892 hw_addr[eth_num] = 0x0;
wdenk544e9732004-02-06 23:19:44 +00001893 break;
wdenk54070ab2004-12-31 09:32:47 +00001894#ifdef CONFIG_HAS_ETH1
wdenk544e9732004-02-06 23:19:44 +00001895 case 1:
Stefan Roese8d982302007-01-18 10:25:34 +01001896 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1897 bis->bi_enet1addr, 6);
1898 hw_addr[eth_num] = 0x100;
wdenk544e9732004-02-06 23:19:44 +00001899 break;
wdenk54070ab2004-12-31 09:32:47 +00001900#endif
1901#ifdef CONFIG_HAS_ETH2
wdenk544e9732004-02-06 23:19:44 +00001902 case 2:
Stefan Roese8d982302007-01-18 10:25:34 +01001903 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1904 bis->bi_enet2addr, 6);
Stefan Roese52df4192008-03-19 16:20:49 +01001905#if defined(CONFIG_460GT)
1906 hw_addr[eth_num] = 0x300;
1907#else
Stefan Roese8d982302007-01-18 10:25:34 +01001908 hw_addr[eth_num] = 0x400;
Stefan Roese52df4192008-03-19 16:20:49 +01001909#endif
wdenk544e9732004-02-06 23:19:44 +00001910 break;
wdenk54070ab2004-12-31 09:32:47 +00001911#endif
1912#ifdef CONFIG_HAS_ETH3
wdenk544e9732004-02-06 23:19:44 +00001913 case 3:
Stefan Roese8d982302007-01-18 10:25:34 +01001914 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1915 bis->bi_enet3addr, 6);
Stefan Roese52df4192008-03-19 16:20:49 +01001916#if defined(CONFIG_460GT)
1917 hw_addr[eth_num] = 0x400;
1918#else
Stefan Roese8d982302007-01-18 10:25:34 +01001919 hw_addr[eth_num] = 0x600;
Stefan Roese52df4192008-03-19 16:20:49 +01001920#endif
wdenk544e9732004-02-06 23:19:44 +00001921 break;
wdenk54070ab2004-12-31 09:32:47 +00001922#endif
wdenk544e9732004-02-06 23:19:44 +00001923 }
Stefan Roese8d982302007-01-18 10:25:34 +01001924 }
1925
1926 /* set phy num and mode */
1927 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
1928 bis->bi_phymode[0] = 0;
1929
1930#if defined(CONFIG_PHY1_ADDR)
1931 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
1932 bis->bi_phymode[1] = 0;
1933#endif
1934#if defined(CONFIG_440GX)
1935 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1936 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1937 bis->bi_phymode[2] = 2;
1938 bis->bi_phymode[3] = 2;
Stefan Roese153b3e22007-10-05 17:10:59 +02001939#endif
Stefan Roese8d982302007-01-18 10:25:34 +01001940
Stefan Roese153b3e22007-10-05 17:10:59 +02001941#if defined(CONFIG_440GX) || \
1942 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1943 defined(CONFIG_405EX)
Stefan Roese8d982302007-01-18 10:25:34 +01001944 ppc_4xx_eth_setup_bridge(0, bis);
1945#endif
1946
1947 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1948 /*
1949 * See if we can actually bring up the interface,
1950 * otherwise, skip it
1951 */
1952 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
1953 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1954 continue;
1955 }
wdenk544e9732004-02-06 23:19:44 +00001956
1957 /* Allocate device structure */
1958 dev = (struct eth_device *) malloc (sizeof (*dev));
1959 if (dev == NULL) {
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001960 printf ("ppc_4xx_eth_initialize: "
wdenkef893942004-02-23 16:11:30 +00001961 "Cannot allocate eth_device %d\n", eth_num);
wdenk544e9732004-02-06 23:19:44 +00001962 return (-1);
1963 }
wdenkd1894de2005-06-20 10:17:34 +00001964 memset(dev, 0, sizeof(*dev));
wdenk544e9732004-02-06 23:19:44 +00001965
1966 /* Allocate our private use data */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001967 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
wdenk544e9732004-02-06 23:19:44 +00001968 if (hw == NULL) {
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001969 printf ("ppc_4xx_eth_initialize: "
wdenkef893942004-02-23 16:11:30 +00001970 "Cannot allocate private hw data for eth_device %d",
wdenk544e9732004-02-06 23:19:44 +00001971 eth_num);
1972 free (dev);
1973 return (-1);
1974 }
wdenkd1894de2005-06-20 10:17:34 +00001975 memset(hw, 0, sizeof(*hw));
wdenk544e9732004-02-06 23:19:44 +00001976
Stefan Roese8d982302007-01-18 10:25:34 +01001977 hw->hw_addr = hw_addr[eth_num];
1978 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
wdenk544e9732004-02-06 23:19:44 +00001979 hw->devnum = eth_num;
Stefan Roese326c9712005-08-01 16:41:48 +02001980 hw->print_speed = 1;
wdenk544e9732004-02-06 23:19:44 +00001981
Stefan Roese8d982302007-01-18 10:25:34 +01001982 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
wdenk544e9732004-02-06 23:19:44 +00001983 dev->priv = (void *) hw;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001984 dev->init = ppc_4xx_eth_init;
1985 dev->halt = ppc_4xx_eth_halt;
1986 dev->send = ppc_4xx_eth_send;
1987 dev->recv = ppc_4xx_eth_rx;
wdenk544e9732004-02-06 23:19:44 +00001988
1989 if (0 == virgin) {
1990 /* set the MAL IER ??? names may change with new spec ??? */
Stefan Roese153b3e22007-10-05 17:10:59 +02001991#if defined(CONFIG_440SPE) || \
1992 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesebdd13d12008-03-11 15:05:26 +01001993 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roese153b3e22007-10-05 17:10:59 +02001994 defined(CONFIG_405EX)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001995 mal_ier =
1996 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
1997 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
1998#else
wdenk544e9732004-02-06 23:19:44 +00001999 mal_ier =
2000 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
2001 MAL_IER_OPBE | MAL_IER_PLBE;
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02002002#endif
wdenk544e9732004-02-06 23:19:44 +00002003 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
2004 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
2005 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
2006 mtdcr (malier, mal_ier);
2007
2008 /* install MAL interrupt handler */
2009 irq_install_handler (VECNUM_MS,
2010 (interrupt_handler_t *) enetInt,
2011 dev);
2012 irq_install_handler (VECNUM_MTE,
2013 (interrupt_handler_t *) enetInt,
2014 dev);
2015 irq_install_handler (VECNUM_MRE,
2016 (interrupt_handler_t *) enetInt,
2017 dev);
2018 irq_install_handler (VECNUM_TXDE,
2019 (interrupt_handler_t *) enetInt,
2020 dev);
2021 irq_install_handler (VECNUM_RXDE,
2022 (interrupt_handler_t *) enetInt,
2023 dev);
2024 virgin = 1;
2025 }
2026
Stefan Roese0c7ffc02005-08-16 18:18:00 +02002027#if defined(CONFIG_NET_MULTI)
wdenk544e9732004-02-06 23:19:44 +00002028 eth_register (dev);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02002029#else
2030 emac0_dev = dev;
2031#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02002032
2033#if defined(CONFIG_NET_MULTI)
Jon Loeligera5217742007-07-09 18:57:22 -05002034#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +02002035 miiphy_register (dev->name,
Stefan Roese99644742005-11-29 18:18:21 +01002036 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowiczaab8c492005-10-28 22:30:33 +02002037#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02002038#endif
wdenk544e9732004-02-06 23:19:44 +00002039 } /* end for each supported device */
Stefan Roese8111a0e2008-01-08 18:39:30 +01002040
2041 return 0;
wdenk544e9732004-02-06 23:19:44 +00002042}
Stefan Roese0c7ffc02005-08-16 18:18:00 +02002043
Stefan Roese0c7ffc02005-08-16 18:18:00 +02002044#if !defined(CONFIG_NET_MULTI)
2045void eth_halt (void) {
2046 if (emac0_dev) {
2047 ppc_4xx_eth_halt(emac0_dev);
2048 free(emac0_dev);
2049 emac0_dev = NULL;
2050 }
2051}
2052
2053int eth_init (bd_t *bis)
2054{
2055 ppc_4xx_eth_initialize(bis);
Stefan Roese03510612005-10-10 17:43:58 +02002056 if (emac0_dev) {
2057 return ppc_4xx_eth_init(emac0_dev, bis);
2058 } else {
2059 printf("ERROR: ethaddr not set!\n");
2060 return -1;
2061 }
Stefan Roese0c7ffc02005-08-16 18:18:00 +02002062}
2063
2064int eth_send(volatile void *packet, int length)
2065{
Stefan Roese0c7ffc02005-08-16 18:18:00 +02002066 return (ppc_4xx_eth_send(emac0_dev, packet, length));
2067}
2068
2069int eth_rx(void)
2070{
2071 return (ppc_4xx_eth_rx(emac0_dev));
2072}
Marian Balakowiczaab8c492005-10-28 22:30:33 +02002073
2074int emac4xx_miiphy_initialize (bd_t * bis)
2075{
Jon Loeligera5217742007-07-09 18:57:22 -05002076#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +02002077 miiphy_register ("ppc_4xx_eth0",
Stefan Roese99644742005-11-29 18:18:21 +01002078 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowiczaab8c492005-10-28 22:30:33 +02002079#endif
2080
2081 return 0;
2082}
Stefan Roese0c7ffc02005-08-16 18:18:00 +02002083#endif /* !defined(CONFIG_NET_MULTI) */
2084
Jon Loeligera5217742007-07-09 18:57:22 -05002085#endif