blob: 6b4834481e352eb71cfe9297135c0e2992577920 [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>
wdenk544e9732004-02-06 23:19:44 +000084#include <commproc.h>
Stefan Roese0c7ffc02005-08-16 18:18:00 +020085#include <ppc4xx.h>
86#include <ppc4xx_enet.h>
wdenk544e9732004-02-06 23:19:44 +000087#include <405_mal.h>
88#include <miiphy.h>
89#include <malloc.h>
90#include "vecnum.h"
91
Stefan Roese0c7ffc02005-08-16 18:18:00 +020092/*
Wolfgang Denk0ee70772005-09-23 11:05:55 +020093 * Only compile for platform with AMCC EMAC ethernet controller and
Stefan Roese0c7ffc02005-08-16 18:18:00 +020094 * network support enabled.
95 * Remark: CONFIG_405 describes Xilinx PPC405 FPGA without EMAC controller!
96 */
Jon Loeligera5217742007-07-09 18:57:22 -050097#if defined(CONFIG_CMD_NET) && !defined(CONFIG_405) && !defined(CONFIG_IOP480)
Stefan Roese0c7ffc02005-08-16 18:18:00 +020098
Jon Loeligera5217742007-07-09 18:57:22 -050099#if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200100#error "CONFIG_MII has to be defined!"
101#endif
wdenk544e9732004-02-06 23:19:44 +0000102
Stefan Roese7f98aec2005-10-20 16:34:28 +0200103#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI)
104#error "CONFIG_NET_MULTI has to be defined for NetConsole"
105#endif
106
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200107#define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
wdenk544e9732004-02-06 23:19:44 +0000108#define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */
109
wdenk544e9732004-02-06 23:19:44 +0000110/* Ethernet Transmit and Receive Buffers */
111/* AS.HARNOIS
112 * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
113 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
114 */
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200115#define ENET_MAX_MTU PKTSIZE
wdenk544e9732004-02-06 23:19:44 +0000116#define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
117
wdenk544e9732004-02-06 23:19:44 +0000118/*-----------------------------------------------------------------------------+
119 * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
120 * Interrupt Controller).
121 *-----------------------------------------------------------------------------*/
122#define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
123#define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
124#define EMAC_UIC_DEF UIC_ENET
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200125#define EMAC_UIC_DEF1 UIC_ENET1
126#define SEL_UIC_DEF(p) (p ? UIC_ENET1 : UIC_ENET )
wdenk544e9732004-02-06 23:19:44 +0000127
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200128#undef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +0000129
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200130#define BI_PHYMODE_NONE 0
131#define BI_PHYMODE_ZMII 1
wdenk56ed43e2004-02-22 23:46:08 +0000132#define BI_PHYMODE_RGMII 2
Stefan Roese42fbddd2006-09-07 11:51:23 +0200133#define BI_PHYMODE_GMII 3
134#define BI_PHYMODE_RTBI 4
135#define BI_PHYMODE_TBI 5
Stefan Roese153b3e22007-10-05 17:10:59 +0200136#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
137 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200138#define BI_PHYMODE_SMII 6
139#define BI_PHYMODE_MII 7
140#endif
wdenk56ed43e2004-02-22 23:46:08 +0000141
Stefan Roese5a128832007-10-05 17:35:10 +0200142#if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200143 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
144 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200145#define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
146#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200147
wdenk544e9732004-02-06 23:19:44 +0000148/*-----------------------------------------------------------------------------+
149 * Global variables. TX and RX descriptors and buffers.
150 *-----------------------------------------------------------------------------*/
151/* IER globals */
152static uint32_t mal_ier;
153
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200154#if !defined(CONFIG_NET_MULTI)
Stefan Roese03510612005-10-10 17:43:58 +0200155struct eth_device *emac0_dev = NULL;
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200156#endif
157
Stefan Roese7f98aec2005-10-20 16:34:28 +0200158/*
159 * Get count of EMAC devices (doesn't have to be the max. possible number
160 * supported by the cpu)
161 */
162#if defined(CONFIG_HAS_ETH3)
163#define LAST_EMAC_NUM 4
164#elif defined(CONFIG_HAS_ETH2)
165#define LAST_EMAC_NUM 3
166#elif defined(CONFIG_HAS_ETH1)
167#define LAST_EMAC_NUM 2
168#else
169#define LAST_EMAC_NUM 1
170#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200171
Stefan Roese8d982302007-01-18 10:25:34 +0100172/* normal boards start with EMAC0 */
173#if !defined(CONFIG_EMAC_NR_START)
174#define CONFIG_EMAC_NR_START 0
175#endif
176
Stefan Roese153b3e22007-10-05 17:10:59 +0200177#if defined(CONFIG_405EX) || defined(CONFIG_440EPX)
178#define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev)))
179#else
180#define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * 2))
181#endif
182
wdenk544e9732004-02-06 23:19:44 +0000183/*-----------------------------------------------------------------------------+
184 * Prototypes and externals.
185 *-----------------------------------------------------------------------------*/
186static void enet_rcv (struct eth_device *dev, unsigned long malisr);
187
188int enetInt (struct eth_device *dev);
189static void mal_err (struct eth_device *dev, unsigned long isr,
190 unsigned long uic, unsigned long maldef,
191 unsigned long mal_errr);
192static void emac_err (struct eth_device *dev, unsigned long isr);
193
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200194extern int phy_setup_aneg (char *devname, unsigned char addr);
195extern int emac4xx_miiphy_read (char *devname, unsigned char addr,
196 unsigned char reg, unsigned short *value);
197extern int emac4xx_miiphy_write (char *devname, unsigned char addr,
198 unsigned char reg, unsigned short value);
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200199
wdenk544e9732004-02-06 23:19:44 +0000200/*-----------------------------------------------------------------------------+
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200201| ppc_4xx_eth_halt
wdenk544e9732004-02-06 23:19:44 +0000202| Disable MAL channel, and EMACn
wdenk544e9732004-02-06 23:19:44 +0000203+-----------------------------------------------------------------------------*/
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200204static void ppc_4xx_eth_halt (struct eth_device *dev)
wdenk544e9732004-02-06 23:19:44 +0000205{
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200206 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +0000207 uint32_t failsafe = 10000;
Stefan Roese153b3e22007-10-05 17:10:59 +0200208#if defined(CONFIG_440SPE) || \
209 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
210 defined(CONFIG_405EX)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200211 unsigned long mfr;
212#endif
wdenk544e9732004-02-06 23:19:44 +0000213
214 out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
215
216 /* 1st reset MAL channel */
217 /* Note: writing a 0 to a channel has no effect */
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200218#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
219 mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
220#else
wdenk544e9732004-02-06 23:19:44 +0000221 mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200222#endif
wdenk544e9732004-02-06 23:19:44 +0000223 mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
224
225 /* wait for reset */
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200226 while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
wdenk544e9732004-02-06 23:19:44 +0000227 udelay (1000); /* Delay 1 MS so as not to hammer the register */
228 failsafe--;
229 if (failsafe == 0)
230 break;
wdenk544e9732004-02-06 23:19:44 +0000231 }
232
233 /* EMAC RESET */
Stefan Roese153b3e22007-10-05 17:10:59 +0200234#if defined(CONFIG_440SPE) || \
235 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
236 defined(CONFIG_405EX)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200237 /* provide clocks for EMAC internal loopback */
238 mfsdr (sdr_mfr, mfr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200239 mfr |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200240 mtsdr(sdr_mfr, mfr);
241#endif
242
wdenk544e9732004-02-06 23:19:44 +0000243 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
244
Stefan Roese153b3e22007-10-05 17:10:59 +0200245#if defined(CONFIG_440SPE) || \
246 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
247 defined(CONFIG_405EX)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200248 /* remove clocks for EMAC internal loopback */
249 mfsdr (sdr_mfr, mfr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200250 mfr &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200251 mtsdr(sdr_mfr, mfr);
252#endif
253
254
Stefan Roesec8136d02005-10-18 19:17:12 +0200255#ifndef CONFIG_NETCONSOLE
Stefan Roese326c9712005-08-01 16:41:48 +0200256 hw_p->print_speed = 1; /* print speed message again next time */
Stefan Roesec8136d02005-10-18 19:17:12 +0200257#endif
Stefan Roese326c9712005-08-01 16:41:48 +0200258
wdenk544e9732004-02-06 23:19:44 +0000259 return;
260}
261
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200262#if defined (CONFIG_440GX)
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200263int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
wdenked2ac4b2004-03-14 18:23:55 +0000264{
265 unsigned long pfc1;
266 unsigned long zmiifer;
267 unsigned long rmiifer;
268
269 mfsdr(sdr_pfc1, pfc1);
270 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
271
272 zmiifer = 0;
273 rmiifer = 0;
274
275 switch (pfc1) {
276 case 1:
277 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
278 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
279 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
280 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
281 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
282 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
283 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
284 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
285 break;
286 case 2:
Stefan Roese0632d7b2006-11-27 17:43:25 +0100287 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
288 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
289 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
290 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
wdenked2ac4b2004-03-14 18:23:55 +0000291 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
292 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
293 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
294 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
295 break;
296 case 3:
297 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
298 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
299 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
300 bis->bi_phymode[1] = BI_PHYMODE_NONE;
301 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
302 bis->bi_phymode[3] = BI_PHYMODE_NONE;
303 break;
304 case 4:
305 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
306 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
307 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
308 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
309 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
310 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
311 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
312 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
313 break;
314 case 5:
315 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
316 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
317 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
318 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
319 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
320 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
321 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
322 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
323 break;
324 case 6:
325 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
326 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
327 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
wdenked2ac4b2004-03-14 18:23:55 +0000328 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
329 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
330 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
wdenked2ac4b2004-03-14 18:23:55 +0000331 break;
332 case 0:
333 default:
334 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
335 rmiifer = 0x0;
336 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
337 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
338 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
339 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
340 break;
341 }
342
343 /* Ensure we setup mdio for this devnum and ONLY this devnum */
344 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
345
346 out32 (ZMII_FER, zmiifer);
347 out32 (RGMII_FER, rmiifer);
348
349 return ((int)pfc1);
wdenked2ac4b2004-03-14 18:23:55 +0000350}
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200351#endif /* CONFIG_440_GX */
wdenked2ac4b2004-03-14 18:23:55 +0000352
Stefan Roese42fbddd2006-09-07 11:51:23 +0200353#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
354int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
355{
356 unsigned long zmiifer=0x0;
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200357 unsigned long pfc1;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200358
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200359 mfsdr(sdr_pfc1, pfc1);
360 pfc1 &= SDR0_PFC1_SELECT_MASK;
361
Wolfgang Denk58c495b2007-05-05 18:23:11 +0200362 switch (pfc1) {
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200363 case SDR0_PFC1_SELECT_CONFIG_2:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200364 /* 1 x GMII port */
365 out32 (ZMII_FER, 0x00);
366 out32 (RGMII_FER, 0x00000037);
367 bis->bi_phymode[0] = BI_PHYMODE_GMII;
368 bis->bi_phymode[1] = BI_PHYMODE_NONE;
369 break;
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200370 case SDR0_PFC1_SELECT_CONFIG_4:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200371 /* 2 x RGMII ports */
372 out32 (ZMII_FER, 0x00);
373 out32 (RGMII_FER, 0x00000055);
374 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
375 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
376 break;
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200377 case SDR0_PFC1_SELECT_CONFIG_6:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200378 /* 2 x SMII ports */
Wolfgang Denk58c495b2007-05-05 18:23:11 +0200379 out32 (ZMII_FER,
Matthias Fuchs8bdf1682007-04-24 14:03:45 +0200380 ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
381 ((ZMII_FER_SMII) << ZMII_FER_V(1)));
382 out32 (RGMII_FER, 0x00000000);
383 bis->bi_phymode[0] = BI_PHYMODE_SMII;
384 bis->bi_phymode[1] = BI_PHYMODE_SMII;
385 break;
386 case SDR0_PFC1_SELECT_CONFIG_1_2:
387 /* only 1 x MII supported */
388 out32 (ZMII_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
389 out32 (RGMII_FER, 0x00000000);
390 bis->bi_phymode[0] = BI_PHYMODE_MII;
391 bis->bi_phymode[1] = BI_PHYMODE_NONE;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200392 break;
393 default:
394 break;
395 }
396
397 /* Ensure we setup mdio for this devnum and ONLY this devnum */
398 zmiifer = in32 (ZMII_FER);
399 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
400 out32 (ZMII_FER, zmiifer);
401
402 return ((int)0x0);
403}
404#endif /* CONFIG_440EPX */
405
Stefan Roese153b3e22007-10-05 17:10:59 +0200406#if defined(CONFIG_405EX)
407int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
408{
409 u32 gmiifer = 0;
410
411 /*
412 * Right now only 2*RGMII is supported. Please extend when needed.
413 * sr - 2007-09-19
414 */
415 switch (1) {
416 case 1:
417 /* 2 x RGMII ports */
418 out32 (RGMII_FER, 0x00000055);
419 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
420 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
421 break;
422 case 2:
423 /* 2 x SMII ports */
424 break;
425 default:
426 break;
427 }
428
429 /* Ensure we setup mdio for this devnum and ONLY this devnum */
430 gmiifer = in32(RGMII_FER);
431 gmiifer |= (1 << (19-devnum));
432 out32 (RGMII_FER, gmiifer);
433
434 return ((int)0x0);
435}
436#endif /* CONFIG_405EX */
437
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200438static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
wdenk544e9732004-02-06 23:19:44 +0000439{
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200440 int i, j;
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200441 unsigned long reg = 0;
wdenk544e9732004-02-06 23:19:44 +0000442 unsigned long msr;
443 unsigned long speed;
444 unsigned long duplex;
445 unsigned long failsafe;
446 unsigned mode_reg;
447 unsigned short devnum;
448 unsigned short reg_short;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200449#if defined(CONFIG_440GX) || \
450 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200451 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
452 defined(CONFIG_405EX)
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200453 sys_info_t sysinfo;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200454#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200455 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
456 defined(CONFIG_405EX)
Stefan Roese99644742005-11-29 18:18:21 +0100457 int ethgroup = -1;
458#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200459#endif
Grzegorz Bernacki2462bbd2007-10-01 09:51:50 +0200460#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200461 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
462 defined(CONFIG_405EX)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200463 unsigned long mfr;
Stefan Roese326c9712005-08-01 16:41:48 +0200464#endif
wdenk544e9732004-02-06 23:19:44 +0000465
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200466 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +0000467
468 /* before doing anything, figure out if we have a MAC address */
469 /* if not, bail */
Stefan Roese03510612005-10-10 17:43:58 +0200470 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
471 printf("ERROR: ethaddr not set!\n");
wdenk544e9732004-02-06 23:19:44 +0000472 return -1;
Stefan Roese03510612005-10-10 17:43:58 +0200473 }
wdenk544e9732004-02-06 23:19:44 +0000474
Stefan Roese42fbddd2006-09-07 11:51:23 +0200475#if defined(CONFIG_440GX) || \
476 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200477 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
478 defined(CONFIG_405EX)
wdenk544e9732004-02-06 23:19:44 +0000479 /* Need to get the OPB frequency so we can access the PHY */
480 get_sys_info (&sysinfo);
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200481#endif
wdenk544e9732004-02-06 23:19:44 +0000482
wdenk544e9732004-02-06 23:19:44 +0000483 msr = mfmsr ();
484 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
485
486 devnum = hw_p->devnum;
487
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200488#ifdef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +0000489 /* AS.HARNOIS
490 * We should have :
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200491 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
wdenk544e9732004-02-06 23:19:44 +0000492 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
493 * is possible that new packets (without relationship with
494 * current transfer) have got the time to arrived before
495 * netloop calls eth_halt
496 */
497 printf ("About preceeding transfer (eth%d):\n"
498 "- Sent packet number %d\n"
499 "- Received packet number %d\n"
500 "- Handled packet number %d\n",
501 hw_p->devnum,
502 hw_p->stats.pkts_tx,
503 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
504
505 hw_p->stats.pkts_tx = 0;
506 hw_p->stats.pkts_rx = 0;
507 hw_p->stats.pkts_handled = 0;
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200508 hw_p->print_speed = 1; /* print speed message again next time */
wdenk544e9732004-02-06 23:19:44 +0000509#endif
510
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200511 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
512 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
wdenk544e9732004-02-06 23:19:44 +0000513
514 hw_p->rx_slot = 0; /* MAL Receive Slot */
515 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
516 hw_p->rx_u_index = 0; /* Receive User Queue Index */
517
518 hw_p->tx_slot = 0; /* MAL Transmit Slot */
519 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
520 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
521
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200522#if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
wdenk544e9732004-02-06 23:19:44 +0000523 /* set RMII mode */
524 /* NOTE: 440GX spec states that mode is mutually exclusive */
525 /* NOTE: Therefore, disable all other EMACS, since we handle */
526 /* NOTE: only one emac at a time */
527 reg = 0;
528 out32 (ZMII_FER, 0);
529 udelay (100);
wdenk544e9732004-02-06 23:19:44 +0000530
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200531#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200532 out32 (ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
Stefan Roese42fbddd2006-09-07 11:51:23 +0200533#elif defined(CONFIG_440GX) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200534 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
Stefan Roese74309032005-09-07 16:21:12 +0200535#elif defined(CONFIG_440GP)
536 /* set RMII mode */
537 out32 (ZMII_FER, ZMII_RMII | ZMII_MDI0);
wdenk00fe1612004-03-14 00:07:33 +0000538#else
539 if ((devnum == 0) || (devnum == 1)) {
540 out32 (ZMII_FER, (ZMII_FER_SMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
Stefan Roese2a4a9432006-11-27 14:12:17 +0100541 } else { /* ((devnum == 2) || (devnum == 3)) */
wdenk00fe1612004-03-14 00:07:33 +0000542 out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum));
wdenk544e9732004-02-06 23:19:44 +0000543 out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) |
544 (RGMII_FER_RGMII << RGMII_FER_V (3))));
wdenk00fe1612004-03-14 00:07:33 +0000545 }
546#endif
Stefan Roese797d8572005-08-11 17:56:56 +0200547
wdenk00fe1612004-03-14 00:07:33 +0000548 out32 (ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
Stefan Roese99644742005-11-29 18:18:21 +0100549#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
Stefan Roese153b3e22007-10-05 17:10:59 +0200550#if defined(CONFIG_405EX)
551 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
552#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200553
wdenk00fe1612004-03-14 00:07:33 +0000554 __asm__ volatile ("eieio");
555
556 /* reset emac so we have access to the phy */
Stefan Roese153b3e22007-10-05 17:10:59 +0200557#if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
558 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
559 defined(CONFIG_405EX)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200560 /* provide clocks for EMAC internal loopback */
561 mfsdr (sdr_mfr, mfr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200562 mfr |= SDR0_MFR_ETH_CLK_SEL_V(devnum);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200563 mtsdr(sdr_mfr, mfr);
564#endif
wdenk00fe1612004-03-14 00:07:33 +0000565
566 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenk544e9732004-02-06 23:19:44 +0000567 __asm__ volatile ("eieio");
568
569 failsafe = 1000;
570 while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
571 udelay (1000);
572 failsafe--;
573 }
Stefan Roese42fbddd2006-09-07 11:51:23 +0200574 if (failsafe <= 0)
575 printf("\nProblem resetting EMAC!\n");
wdenk544e9732004-02-06 23:19:44 +0000576
Stefan Roese153b3e22007-10-05 17:10:59 +0200577#if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
578 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
579 defined(CONFIG_405EX)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200580 /* remove clocks for EMAC internal loopback */
581 mfsdr (sdr_mfr, mfr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200582 mfr &= ~SDR0_MFR_ETH_CLK_SEL_V(devnum);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200583 mtsdr(sdr_mfr, mfr);
584#endif
585
Stefan Roese42fbddd2006-09-07 11:51:23 +0200586#if defined(CONFIG_440GX) || \
587 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200588 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
589 defined(CONFIG_405EX)
wdenk544e9732004-02-06 23:19:44 +0000590 /* Whack the M1 register */
591 mode_reg = 0x0;
592 mode_reg &= ~0x00000038;
593 if (sysinfo.freqOPB <= 50000000);
594 else if (sysinfo.freqOPB <= 66666667)
595 mode_reg |= EMAC_M1_OBCI_66;
596 else if (sysinfo.freqOPB <= 83333333)
597 mode_reg |= EMAC_M1_OBCI_83;
598 else if (sysinfo.freqOPB <= 100000000)
599 mode_reg |= EMAC_M1_OBCI_100;
600 else
601 mode_reg |= EMAC_M1_OBCI_GT100;
602
603 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
Stefan Roese99644742005-11-29 18:18:21 +0100604#endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
wdenk544e9732004-02-06 23:19:44 +0000605
606 /* wait for PHY to complete auto negotiation */
607 reg_short = 0;
608#ifndef CONFIG_CS8952_PHY
609 switch (devnum) {
610 case 0:
611 reg = CONFIG_PHY_ADDR;
612 break;
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200613#if defined (CONFIG_PHY1_ADDR)
wdenk544e9732004-02-06 23:19:44 +0000614 case 1:
615 reg = CONFIG_PHY1_ADDR;
616 break;
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200617#endif
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200618#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +0000619 case 2:
620 reg = CONFIG_PHY2_ADDR;
621 break;
622 case 3:
623 reg = CONFIG_PHY3_ADDR;
624 break;
625#endif
626 default:
627 reg = CONFIG_PHY_ADDR;
628 break;
629 }
630
wdenk56ed43e2004-02-22 23:46:08 +0000631 bis->bi_phynum[devnum] = reg;
632
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200633#if defined(CONFIG_PHY_RESET)
wdenk97e8bda2004-09-29 22:43:59 +0000634 /*
635 * Reset the phy, only if its the first time through
636 * otherwise, just check the speeds & feeds
637 */
638 if (hw_p->first_init == 0) {
Stefan Roese21df1a42006-11-27 14:46:06 +0100639#if defined(CONFIG_M88E1111_PHY)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200640 miiphy_write (dev->name, reg, 0x14, 0x0ce3);
641 miiphy_write (dev->name, reg, 0x18, 0x4101);
642 miiphy_write (dev->name, reg, 0x09, 0x0e00);
643 miiphy_write (dev->name, reg, 0x04, 0x01e1);
644#endif
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200645 miiphy_reset (dev->name, reg);
wdenk544e9732004-02-06 23:19:44 +0000646
Stefan Roese42fbddd2006-09-07 11:51:23 +0200647#if defined(CONFIG_440GX) || \
648 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200649 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
650 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200651
wdenk00fe1612004-03-14 00:07:33 +0000652#if defined(CONFIG_CIS8201_PHY)
wdenk7ad5e4c2004-04-25 15:41:35 +0000653 /*
Stefan Roese363330b2005-08-04 17:09:16 +0200654 * Cicada 8201 PHY needs to have an extended register whacked
655 * for RGMII mode.
wdenk7ad5e4c2004-04-25 15:41:35 +0000656 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200657 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200658#if defined(CONFIG_CIS8201_SHORT_ETCH)
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200659 miiphy_write (dev->name, reg, 23, 0x1300);
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200660#else
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200661 miiphy_write (dev->name, reg, 23, 0x1000);
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200662#endif
Stefan Roese363330b2005-08-04 17:09:16 +0200663 /*
664 * Vitesse VSC8201/Cicada CIS8201 errata:
665 * Interoperability problem with Intel 82547EI phys
666 * This work around (provided by Vitesse) changes
667 * the default timer convergence from 8ms to 12ms
668 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200669 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
670 miiphy_write (dev->name, reg, 0x08, 0x0200);
671 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
672 miiphy_write (dev->name, reg, 0x02, 0x0004);
673 miiphy_write (dev->name, reg, 0x01, 0x0671);
674 miiphy_write (dev->name, reg, 0x00, 0x8fae);
675 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
676 miiphy_write (dev->name, reg, 0x08, 0x0000);
677 miiphy_write (dev->name, reg, 0x1f, 0x0000);
Stefan Roese363330b2005-08-04 17:09:16 +0200678 /* end Vitesse/Cicada errata */
679 }
wdenk00fe1612004-03-14 00:07:33 +0000680#endif
Stefan Roese8d982302007-01-18 10:25:34 +0100681
682#if defined(CONFIG_ET1011C_PHY)
683 /*
684 * Agere ET1011c PHY needs to have an extended register whacked
685 * for RGMII mode.
686 */
687 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
688 miiphy_read (dev->name, reg, 0x16, &reg_short);
689 reg_short &= ~(0x7);
690 reg_short |= 0x6; /* RGMII DLL Delay*/
691 miiphy_write (dev->name, reg, 0x16, reg_short);
692
693 miiphy_read (dev->name, reg, 0x17, &reg_short);
694 reg_short &= ~(0x40);
695 miiphy_write (dev->name, reg, 0x17, reg_short);
696
697 miiphy_write(dev->name, reg, 0x1c, 0x74f0);
698 }
699#endif
700
wdenked2ac4b2004-03-14 18:23:55 +0000701#endif
wdenk97e8bda2004-09-29 22:43:59 +0000702 /* Start/Restart autonegotiation */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200703 phy_setup_aneg (dev->name, reg);
wdenk97e8bda2004-09-29 22:43:59 +0000704 udelay (1000);
705 }
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200706#endif /* defined(CONFIG_PHY_RESET) */
wdenk544e9732004-02-06 23:19:44 +0000707
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200708 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenk544e9732004-02-06 23:19:44 +0000709
710 /*
wdenk00fe1612004-03-14 00:07:33 +0000711 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
wdenk544e9732004-02-06 23:19:44 +0000712 */
713 if ((reg_short & PHY_BMSR_AUTN_ABLE)
714 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
715 puts ("Waiting for PHY auto negotiation to complete");
716 i = 0;
717 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
718 /*
719 * Timeout reached ?
720 */
721 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
722 puts (" TIMEOUT !\n");
723 break;
724 }
725
726 if ((i++ % 1000) == 0) {
727 putc ('.');
728 }
729 udelay (1000); /* 1 ms */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200730 miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
wdenk544e9732004-02-06 23:19:44 +0000731
732 }
733 puts (" done\n");
734 udelay (500000); /* another 500 ms (results in faster booting) */
735 }
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200736#endif /* #ifndef CONFIG_CS8952_PHY */
737
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200738 speed = miiphy_speed (dev->name, reg);
739 duplex = miiphy_duplex (dev->name, reg);
wdenk544e9732004-02-06 23:19:44 +0000740
741 if (hw_p->print_speed) {
742 hw_p->print_speed = 0;
Stefan Roese8d982302007-01-18 10:25:34 +0100743 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
744 (int) speed, (duplex == HALF) ? "HALF" : "FULL",
745 hw_p->devnum);
wdenk544e9732004-02-06 23:19:44 +0000746 }
747
Stefan Roese42fbddd2006-09-07 11:51:23 +0200748#if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
749 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX)
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200750#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese326c9712005-08-01 16:41:48 +0200751 mfsdr(sdr_mfr, reg);
752 if (speed == 100) {
753 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
754 } else {
755 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
756 }
757 mtsdr(sdr_mfr, reg);
758#endif
Stefan Roese797d8572005-08-11 17:56:56 +0200759
wdenk544e9732004-02-06 23:19:44 +0000760 /* Set ZMII/RGMII speed according to the phy link speed */
761 reg = in32 (ZMII_SSR);
wdenked2ac4b2004-03-14 18:23:55 +0000762 if ( (speed == 100) || (speed == 1000) )
wdenk544e9732004-02-06 23:19:44 +0000763 out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
764 else
Stefan Roese797d8572005-08-11 17:56:56 +0200765 out32 (ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
wdenk544e9732004-02-06 23:19:44 +0000766
767 if ((devnum == 2) || (devnum == 3)) {
768 if (speed == 1000)
769 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
770 else if (speed == 100)
771 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
Stefan Roese42fbddd2006-09-07 11:51:23 +0200772 else if (speed == 10)
wdenk544e9732004-02-06 23:19:44 +0000773 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
Stefan Roese42fbddd2006-09-07 11:51:23 +0200774 else {
775 printf("Error in RGMII Speed\n");
776 return -1;
777 }
wdenk544e9732004-02-06 23:19:44 +0000778 out32 (RGMII_SSR, reg);
779 }
Stefan Roese99644742005-11-29 18:18:21 +0100780#endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
wdenk544e9732004-02-06 23:19:44 +0000781
Stefan Roese153b3e22007-10-05 17:10:59 +0200782#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
783 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200784 if (speed == 1000)
785 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
786 else if (speed == 100)
787 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
788 else if (speed == 10)
789 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
790 else {
791 printf("Error in RGMII Speed\n");
792 return -1;
793 }
794 out32 (RGMII_SSR, reg);
795#endif
796
wdenk544e9732004-02-06 23:19:44 +0000797 /* set the Mal configuration reg */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200798#if defined(CONFIG_440GX) || \
799 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200800 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
801 defined(CONFIG_405EX)
Stefan Roese363330b2005-08-04 17:09:16 +0200802 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
803 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
804#else
805 mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
wdenk544e9732004-02-06 23:19:44 +0000806 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
Stefan Roese363330b2005-08-04 17:09:16 +0200807 if (get_pvr() == PVR_440GP_RB) {
808 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
809 }
810#endif
wdenk544e9732004-02-06 23:19:44 +0000811
812 /* Free "old" buffers */
813 if (hw_p->alloc_tx_buf)
814 free (hw_p->alloc_tx_buf);
815 if (hw_p->alloc_rx_buf)
816 free (hw_p->alloc_rx_buf);
817
818 /*
819 * Malloc MAL buffer desciptors, make sure they are
820 * aligned on cache line boundary size
821 * (401/403/IOP480 = 16, 405 = 32)
822 * and doesn't cross cache block boundaries.
823 */
824 hw_p->alloc_tx_buf =
825 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
826 ((2 * CFG_CACHELINE_SIZE) - 2));
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200827 if (NULL == hw_p->alloc_tx_buf)
828 return -1;
wdenk544e9732004-02-06 23:19:44 +0000829 if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
830 hw_p->tx =
831 (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
832 CFG_CACHELINE_SIZE -
833 ((int) hw_p->
834 alloc_tx_buf & CACHELINE_MASK));
835 } else {
836 hw_p->tx = hw_p->alloc_tx_buf;
837 }
838
839 hw_p->alloc_rx_buf =
840 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
841 ((2 * CFG_CACHELINE_SIZE) - 2));
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200842 if (NULL == hw_p->alloc_rx_buf) {
843 free(hw_p->alloc_tx_buf);
844 hw_p->alloc_tx_buf = NULL;
845 return -1;
846 }
847
wdenk544e9732004-02-06 23:19:44 +0000848 if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
849 hw_p->rx =
850 (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
851 CFG_CACHELINE_SIZE -
852 ((int) hw_p->
853 alloc_rx_buf & CACHELINE_MASK));
854 } else {
855 hw_p->rx = hw_p->alloc_rx_buf;
856 }
857
858 for (i = 0; i < NUM_TX_BUFF; i++) {
859 hw_p->tx[i].ctrl = 0;
860 hw_p->tx[i].data_len = 0;
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200861 if (hw_p->first_init == 0) {
wdenk544e9732004-02-06 23:19:44 +0000862 hw_p->txbuf_ptr =
863 (char *) malloc (ENET_MAX_MTU_ALIGNED);
Stefan Roese5ff4c3f2005-08-15 12:31:23 +0200864 if (NULL == hw_p->txbuf_ptr) {
865 free(hw_p->alloc_rx_buf);
866 free(hw_p->alloc_tx_buf);
867 hw_p->alloc_rx_buf = NULL;
868 hw_p->alloc_tx_buf = NULL;
869 for(j = 0; j < i; j++) {
870 free(hw_p->tx[i].data_ptr);
871 hw_p->tx[i].data_ptr = NULL;
872 }
873 }
874 }
wdenk544e9732004-02-06 23:19:44 +0000875 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
876 if ((NUM_TX_BUFF - 1) == i)
877 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
878 hw_p->tx_run[i] = -1;
879#if 0
880 printf ("TX_BUFF %d @ 0x%08lx\n", i,
881 (ulong) hw_p->tx[i].data_ptr);
882#endif
883 }
884
885 for (i = 0; i < NUM_RX_BUFF; i++) {
886 hw_p->rx[i].ctrl = 0;
887 hw_p->rx[i].data_len = 0;
Wolfgang Denk0cbaf642005-09-25 00:53:22 +0200888 /* rx[i].data_ptr = (char *) &rx_buff[i]; */
wdenk544e9732004-02-06 23:19:44 +0000889 hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
890 if ((NUM_RX_BUFF - 1) == i)
891 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
892 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
893 hw_p->rx_ready[i] = -1;
894#if 0
Stefan Roese2a4a9432006-11-27 14:12:17 +0100895 printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) hw_p->rx[i].data_ptr);
wdenk544e9732004-02-06 23:19:44 +0000896#endif
897 }
898
899 reg = 0x00000000;
900
901 reg |= dev->enetaddr[0]; /* set high address */
902 reg = reg << 8;
903 reg |= dev->enetaddr[1];
904
905 out32 (EMAC_IAH + hw_p->hw_addr, reg);
906
907 reg = 0x00000000;
908 reg |= dev->enetaddr[2]; /* set low address */
909 reg = reg << 8;
910 reg |= dev->enetaddr[3];
911 reg = reg << 8;
912 reg |= dev->enetaddr[4];
913 reg = reg << 8;
914 reg |= dev->enetaddr[5];
915
916 out32 (EMAC_IAL + hw_p->hw_addr, reg);
917
918 switch (devnum) {
919 case 1:
920 /* setup MAL tx & rx channel pointers */
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200921#if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
Stefan Roese326c9712005-08-01 16:41:48 +0200922 mtdcr (maltxctp2r, hw_p->tx);
923#else
wdenk544e9732004-02-06 23:19:44 +0000924 mtdcr (maltxctp1r, hw_p->tx);
Stefan Roese326c9712005-08-01 16:41:48 +0200925#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200926#if defined(CONFIG_440)
Stefan Roese326c9712005-08-01 16:41:48 +0200927 mtdcr (maltxbattr, 0x0);
wdenk544e9732004-02-06 23:19:44 +0000928 mtdcr (malrxbattr, 0x0);
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200929#endif
wdenk544e9732004-02-06 23:19:44 +0000930 mtdcr (malrxctp1r, hw_p->rx);
931 /* set RX buffer size */
932 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
933 break;
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200934#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +0000935 case 2:
936 /* setup MAL tx & rx channel pointers */
937 mtdcr (maltxbattr, 0x0);
wdenk544e9732004-02-06 23:19:44 +0000938 mtdcr (malrxbattr, 0x0);
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200939 mtdcr (maltxctp2r, hw_p->tx);
wdenk544e9732004-02-06 23:19:44 +0000940 mtdcr (malrxctp2r, hw_p->rx);
941 /* set RX buffer size */
942 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
943 break;
944 case 3:
945 /* setup MAL tx & rx channel pointers */
946 mtdcr (maltxbattr, 0x0);
947 mtdcr (maltxctp3r, hw_p->tx);
948 mtdcr (malrxbattr, 0x0);
949 mtdcr (malrxctp3r, hw_p->rx);
950 /* set RX buffer size */
951 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
952 break;
Stefan Roese797d8572005-08-11 17:56:56 +0200953#endif /* CONFIG_440GX */
wdenk544e9732004-02-06 23:19:44 +0000954 case 0:
955 default:
956 /* setup MAL tx & rx channel pointers */
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200957#if defined(CONFIG_440)
wdenk544e9732004-02-06 23:19:44 +0000958 mtdcr (maltxbattr, 0x0);
wdenk544e9732004-02-06 23:19:44 +0000959 mtdcr (malrxbattr, 0x0);
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200960#endif
961 mtdcr (maltxctp0r, hw_p->tx);
wdenk544e9732004-02-06 23:19:44 +0000962 mtdcr (malrxctp0r, hw_p->rx);
963 /* set RX buffer size */
964 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
965 break;
966 }
967
968 /* Enable MAL transmit and receive channels */
Stefan Roese0c7ffc02005-08-16 18:18:00 +0200969#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese326c9712005-08-01 16:41:48 +0200970 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
971#else
wdenk544e9732004-02-06 23:19:44 +0000972 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
Stefan Roese326c9712005-08-01 16:41:48 +0200973#endif
wdenk544e9732004-02-06 23:19:44 +0000974 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
975
976 /* set transmit enable & receive enable */
977 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
978
979 /* set receive fifo to 4k and tx fifo to 2k */
980 mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
981 mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
982
983 /* set speed */
Stefan Roese99644742005-11-29 18:18:21 +0100984 if (speed == _1000BASET) {
Stefan Roese43867c82007-10-02 11:44:46 +0200985#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
986 defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese99644742005-11-29 18:18:21 +0100987 unsigned long pfc1;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200988
Stefan Roese99644742005-11-29 18:18:21 +0100989 mfsdr (sdr_pfc1, pfc1);
990 pfc1 |= SDR0_PFC1_EM_1000;
991 mtsdr (sdr_pfc1, pfc1);
992#endif
wdenked2ac4b2004-03-14 18:23:55 +0000993 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
Stefan Roese99644742005-11-29 18:18:21 +0100994 } else if (speed == _100BASET)
wdenk544e9732004-02-06 23:19:44 +0000995 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
996 else
997 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
998 if (duplex == FULL)
999 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
1000
1001 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
1002
1003 /* Enable broadcast and indvidual address */
1004 /* TBS: enabling runts as some misbehaved nics will send runts */
1005 out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
1006
1007 /* we probably need to set the tx mode1 reg? maybe at tx time */
1008
1009 /* set transmit request threshold register */
1010 out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
1011
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001012 /* set receive low/high water mark register */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001013#if defined(CONFIG_440)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001014 /* 440s has a 64 byte burst length */
wdenk544e9732004-02-06 23:19:44 +00001015 out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001016#else
1017 /* 405s have a 16 byte burst length */
1018 out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
1019#endif /* defined(CONFIG_440) */
wdenk544e9732004-02-06 23:19:44 +00001020 out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
1021
1022 /* Set fifo limit entry in tx mode 0 */
1023 out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
1024 /* Frame gap set */
1025 out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
1026
1027 /* Set EMAC IER */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001028 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
wdenk544e9732004-02-06 23:19:44 +00001029 if (speed == _100BASET)
1030 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1031
1032 out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
1033 out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
1034
1035 if (hw_p->first_init == 0) {
1036 /*
1037 * Connect interrupt service routines
1038 */
Stefan Roese153b3e22007-10-05 17:10:59 +02001039 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1040 (interrupt_handler_t *) enetInt, dev);
wdenk544e9732004-02-06 23:19:44 +00001041 }
wdenk544e9732004-02-06 23:19:44 +00001042
1043 mtmsr (msr); /* enable interrupts again */
1044
1045 hw_p->bis = bis;
1046 hw_p->first_init = 1;
1047
1048 return (1);
1049}
1050
1051
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001052static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
wdenk544e9732004-02-06 23:19:44 +00001053 int len)
1054{
1055 struct enet_frame *ef_ptr;
1056 ulong time_start, time_now;
1057 unsigned long temp_txm0;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001058 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001059
1060 ef_ptr = (struct enet_frame *) ptr;
1061
1062 /*-----------------------------------------------------------------------+
1063 * Copy in our address into the frame.
1064 *-----------------------------------------------------------------------*/
1065 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1066
1067 /*-----------------------------------------------------------------------+
1068 * If frame is too long or too short, modify length.
1069 *-----------------------------------------------------------------------*/
1070 /* TBS: where does the fragment go???? */
1071 if (len > ENET_MAX_MTU)
1072 len = ENET_MAX_MTU;
1073
1074 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1075 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
1076
1077 /*-----------------------------------------------------------------------+
1078 * set TX Buffer busy, and send it
1079 *-----------------------------------------------------------------------*/
1080 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1081 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1082 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1083 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1084 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1085
1086 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1087 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1088
1089 __asm__ volatile ("eieio");
1090
1091 out32 (EMAC_TXM0 + hw_p->hw_addr,
1092 in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001093#ifdef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +00001094 hw_p->stats.pkts_tx++;
1095#endif
1096
1097 /*-----------------------------------------------------------------------+
1098 * poll unitl the packet is sent and then make sure it is OK
1099 *-----------------------------------------------------------------------*/
1100 time_start = get_timer (0);
1101 while (1) {
1102 temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
1103 /* loop until either TINT turns on or 3 seconds elapse */
1104 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
1105 /* transmit is done, so now check for errors
1106 * If there is an error, an interrupt should
1107 * happen when we return
1108 */
1109 time_now = get_timer (0);
1110 if ((time_now - time_start) > 3000) {
1111 return (-1);
1112 }
1113 } else {
1114 return (len);
1115 }
1116 }
1117}
1118
Stefan Roese99644742005-11-29 18:18:21 +01001119
Stefan Roese153b3e22007-10-05 17:10:59 +02001120#if defined (CONFIG_440) || defined(CONFIG_405EX)
wdenk544e9732004-02-06 23:19:44 +00001121
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001122#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese99644742005-11-29 18:18:21 +01001123/*
1124 * Hack: On 440SP all enet irq sources are located on UIC1
1125 * Needs some cleanup. --sr
1126 */
1127#define UIC0MSR uic1msr
1128#define UIC0SR uic1sr
1129#else
1130#define UIC0MSR uic0msr
1131#define UIC0SR uic0sr
1132#endif
1133
Stefan Roese153b3e22007-10-05 17:10:59 +02001134#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1135 defined(CONFIG_405EX)
Stefan Roese42fbddd2006-09-07 11:51:23 +02001136#define UICMSR_ETHX uic0msr
1137#define UICSR_ETHX uic0sr
1138#else
1139#define UICMSR_ETHX uic1msr
1140#define UICSR_ETHX uic1sr
1141#endif
1142
wdenk544e9732004-02-06 23:19:44 +00001143int enetInt (struct eth_device *dev)
1144{
1145 int serviced;
1146 int rc = -1; /* default to not us */
1147 unsigned long mal_isr;
1148 unsigned long emac_isr = 0;
1149 unsigned long mal_rx_eob;
1150 unsigned long my_uic0msr, my_uic1msr;
Stefan Roese42fbddd2006-09-07 11:51:23 +02001151 unsigned long my_uicmsr_ethx;
wdenk544e9732004-02-06 23:19:44 +00001152
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001153#if defined(CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001154 unsigned long my_uic2msr;
1155#endif
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001156 EMAC_4XX_HW_PST hw_p;
wdenk544e9732004-02-06 23:19:44 +00001157
1158 /*
1159 * Because the mal is generic, we need to get the current
1160 * eth device
1161 */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001162#if defined(CONFIG_NET_MULTI)
1163 dev = eth_get_dev();
1164#else
1165 dev = emac0_dev;
1166#endif
wdenk544e9732004-02-06 23:19:44 +00001167
1168 hw_p = dev->priv;
1169
wdenk544e9732004-02-06 23:19:44 +00001170 /* enter loop that stays in interrupt code until nothing to service */
1171 do {
1172 serviced = 0;
1173
Stefan Roese99644742005-11-29 18:18:21 +01001174 my_uic0msr = mfdcr (UIC0MSR);
wdenk544e9732004-02-06 23:19:44 +00001175 my_uic1msr = mfdcr (uic1msr);
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001176#if defined(CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001177 my_uic2msr = mfdcr (uic2msr);
1178#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +02001179 my_uicmsr_ethx = mfdcr (UICMSR_ETHX);
1180
wdenk544e9732004-02-06 23:19:44 +00001181 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
Stefan Roese42fbddd2006-09-07 11:51:23 +02001182 && !(my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))
1183 && !(my_uicmsr_ethx & (UIC_ETH0 | UIC_ETH1))) {
wdenk544e9732004-02-06 23:19:44 +00001184 /* not for us */
1185 return (rc);
1186 }
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001187#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001188 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
1189 && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
1190 /* not for us */
1191 return (rc);
1192 }
1193#endif
1194 /* get and clear controller status interrupts */
1195 /* look at Mal and EMAC interrupts */
1196 if ((my_uic0msr & (UIC_MRE | UIC_MTE))
1197 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1198 /* we have a MAL interrupt */
1199 mal_isr = mfdcr (malesr);
1200 /* look for mal error */
1201 if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
Stefan Roese42fbddd2006-09-07 11:51:23 +02001202 mal_err (dev, mal_isr, my_uic1msr, MAL_UIC_DEF, MAL_UIC_ERR);
wdenk544e9732004-02-06 23:19:44 +00001203 serviced = 1;
1204 rc = 0;
1205 }
1206 }
1207
1208 /* port by port dispatch of emac interrupts */
1209 if (hw_p->devnum == 0) {
Stefan Roese42fbddd2006-09-07 11:51:23 +02001210 if (UIC_ETH0 & my_uicmsr_ethx) { /* look for EMAC errors */
wdenk544e9732004-02-06 23:19:44 +00001211 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1212 if ((hw_p->emac_ier & emac_isr) != 0) {
1213 emac_err (dev, emac_isr);
1214 serviced = 1;
1215 rc = 0;
1216 }
1217 }
1218 if ((hw_p->emac_ier & emac_isr)
1219 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese99644742005-11-29 18:18:21 +01001220 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001221 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1222 mtdcr (UICSR_ETHX, UIC_ETH0); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001223 return (rc); /* we had errors so get out */
1224 }
1225 }
1226
Stefan Roese99644742005-11-29 18:18:21 +01001227#if !defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +00001228 if (hw_p->devnum == 1) {
Stefan Roese42fbddd2006-09-07 11:51:23 +02001229 if (UIC_ETH1 & my_uicmsr_ethx) { /* look for EMAC errors */
wdenk544e9732004-02-06 23:19:44 +00001230 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1231 if ((hw_p->emac_ier & emac_isr) != 0) {
1232 emac_err (dev, emac_isr);
1233 serviced = 1;
1234 rc = 0;
1235 }
1236 }
1237 if ((hw_p->emac_ier & emac_isr)
1238 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese99644742005-11-29 18:18:21 +01001239 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001240 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1241 mtdcr (UICSR_ETHX, UIC_ETH1); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001242 return (rc); /* we had errors so get out */
1243 }
1244 }
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001245#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001246 if (hw_p->devnum == 2) {
1247 if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
1248 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1249 if ((hw_p->emac_ier & emac_isr) != 0) {
1250 emac_err (dev, emac_isr);
1251 serviced = 1;
1252 rc = 0;
1253 }
1254 }
1255 if ((hw_p->emac_ier & emac_isr)
1256 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese99644742005-11-29 18:18:21 +01001257 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001258 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1259 mtdcr (uic2sr, UIC_ETH2);
1260 return (rc); /* we had errors so get out */
1261 }
1262 }
1263
1264 if (hw_p->devnum == 3) {
1265 if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
1266 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1267 if ((hw_p->emac_ier & emac_isr) != 0) {
1268 emac_err (dev, emac_isr);
1269 serviced = 1;
1270 rc = 0;
1271 }
1272 }
1273 if ((hw_p->emac_ier & emac_isr)
1274 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
Stefan Roese99644742005-11-29 18:18:21 +01001275 mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001276 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1277 mtdcr (uic2sr, UIC_ETH3);
1278 return (rc); /* we had errors so get out */
1279 }
1280 }
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001281#endif /* CONFIG_440GX */
Stefan Roese99644742005-11-29 18:18:21 +01001282#endif /* !CONFIG_440SP */
1283
wdenk544e9732004-02-06 23:19:44 +00001284 /* handle MAX TX EOB interrupt from a tx */
1285 if (my_uic0msr & UIC_MTE) {
1286 mal_rx_eob = mfdcr (maltxeobisr);
1287 mtdcr (maltxeobisr, mal_rx_eob);
Stefan Roese99644742005-11-29 18:18:21 +01001288 mtdcr (UIC0SR, UIC_MTE);
wdenk544e9732004-02-06 23:19:44 +00001289 }
1290 /* handle MAL RX EOB interupt from a receive */
wdenk7ad5e4c2004-04-25 15:41:35 +00001291 /* check for EOB on valid channels */
wdenk544e9732004-02-06 23:19:44 +00001292 if (my_uic0msr & UIC_MRE) {
1293 mal_rx_eob = mfdcr (malrxeobisr);
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001294 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
wdenk544e9732004-02-06 23:19:44 +00001295 /* clear EOB
1296 mtdcr(malrxeobisr, mal_rx_eob); */
1297 enet_rcv (dev, emac_isr);
1298 /* indicate that we serviced an interrupt */
1299 serviced = 1;
1300 rc = 0;
1301 }
1302 }
Stefan Roese99644742005-11-29 18:18:21 +01001303
1304 mtdcr (UIC0SR, UIC_MRE); /* Clear */
wdenk544e9732004-02-06 23:19:44 +00001305 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1306 switch (hw_p->devnum) {
1307 case 0:
Stefan Roese42fbddd2006-09-07 11:51:23 +02001308 mtdcr (UICSR_ETHX, UIC_ETH0);
wdenk544e9732004-02-06 23:19:44 +00001309 break;
1310 case 1:
Stefan Roese42fbddd2006-09-07 11:51:23 +02001311 mtdcr (UICSR_ETHX, UIC_ETH1);
wdenk544e9732004-02-06 23:19:44 +00001312 break;
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001313#if defined (CONFIG_440GX)
wdenk544e9732004-02-06 23:19:44 +00001314 case 2:
1315 mtdcr (uic2sr, UIC_ETH2);
1316 break;
1317 case 3:
1318 mtdcr (uic2sr, UIC_ETH3);
1319 break;
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001320#endif /* CONFIG_440GX */
wdenk544e9732004-02-06 23:19:44 +00001321 default:
1322 break;
1323 }
1324 } while (serviced);
1325
1326 return (rc);
1327}
1328
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001329#else /* CONFIG_440 */
1330
1331int enetInt (struct eth_device *dev)
1332{
1333 int serviced;
1334 int rc = -1; /* default to not us */
1335 unsigned long mal_isr;
1336 unsigned long emac_isr = 0;
1337 unsigned long mal_rx_eob;
1338 unsigned long my_uicmsr;
1339
1340 EMAC_4XX_HW_PST hw_p;
1341
1342 /*
1343 * Because the mal is generic, we need to get the current
1344 * eth device
1345 */
1346#if defined(CONFIG_NET_MULTI)
1347 dev = eth_get_dev();
1348#else
1349 dev = emac0_dev;
1350#endif
1351
1352 hw_p = dev->priv;
1353
1354 /* enter loop that stays in interrupt code until nothing to service */
1355 do {
1356 serviced = 0;
1357
1358 my_uicmsr = mfdcr (uicmsr);
1359
1360 if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) { /* not for us */
1361 return (rc);
1362 }
1363 /* get and clear controller status interrupts */
1364 /* look at Mal and EMAC interrupts */
1365 if ((MAL_UIC_DEF & my_uicmsr) != 0) { /* we have a MAL interrupt */
1366 mal_isr = mfdcr (malesr);
1367 /* look for mal error */
1368 if ((my_uicmsr & MAL_UIC_ERR) != 0) {
1369 mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR);
1370 serviced = 1;
1371 rc = 0;
1372 }
1373 }
1374
1375 /* port by port dispatch of emac interrupts */
1376
1377 if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) { /* look for EMAC errors */
1378 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
1379 if ((hw_p->emac_ier & emac_isr) != 0) {
1380 emac_err (dev, emac_isr);
1381 serviced = 1;
1382 rc = 0;
1383 }
1384 }
1385 if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) {
1386 mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */
1387 return (rc); /* we had errors so get out */
1388 }
1389
1390 /* handle MAX TX EOB interrupt from a tx */
1391 if (my_uicmsr & UIC_MAL_TXEOB) {
1392 mal_rx_eob = mfdcr (maltxeobisr);
1393 mtdcr (maltxeobisr, mal_rx_eob);
1394 mtdcr (uicsr, UIC_MAL_TXEOB);
1395 }
1396 /* handle MAL RX EOB interupt from a receive */
1397 /* check for EOB on valid channels */
1398 if (my_uicmsr & UIC_MAL_RXEOB)
1399 {
1400 mal_rx_eob = mfdcr (malrxeobisr);
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001401 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001402 /* clear EOB
1403 mtdcr(malrxeobisr, mal_rx_eob); */
1404 enet_rcv (dev, emac_isr);
1405 /* indicate that we serviced an interrupt */
1406 serviced = 1;
1407 rc = 0;
1408 }
1409 }
1410 mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1); /* Clear */
Stefan Roese17ffbc82007-03-21 13:38:59 +01001411#if defined(CONFIG_405EZ)
1412 mtsdr (sdricintstat, SDR_ICRX_STAT | SDR_ICTX0_STAT | SDR_ICTX1_STAT);
1413#endif /* defined(CONFIG_405EZ) */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001414 }
1415 while (serviced);
1416
1417 return (rc);
1418}
1419
1420#endif /* CONFIG_440 */
1421
wdenk544e9732004-02-06 23:19:44 +00001422/*-----------------------------------------------------------------------------+
1423 * MAL Error Routine
1424 *-----------------------------------------------------------------------------*/
1425static void mal_err (struct eth_device *dev, unsigned long isr,
1426 unsigned long uic, unsigned long maldef,
1427 unsigned long mal_errr)
1428{
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001429 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001430
1431 mtdcr (malesr, isr); /* clear interrupt */
1432
1433 /* clear DE interrupt */
1434 mtdcr (maltxdeir, 0xC0000000);
1435 mtdcr (malrxdeir, 0x80000000);
1436
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001437#ifdef INFO_4XX_ENET
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001438 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 +00001439#endif
1440
1441 eth_init (hw_p->bis); /* start again... */
1442}
1443
1444/*-----------------------------------------------------------------------------+
1445 * EMAC Error Routine
1446 *-----------------------------------------------------------------------------*/
1447static void emac_err (struct eth_device *dev, unsigned long isr)
1448{
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001449 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001450
1451 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
1452 out32 (EMAC_ISR + hw_p->hw_addr, isr);
1453}
1454
1455/*-----------------------------------------------------------------------------+
1456 * enet_rcv() handles the ethernet receive data
1457 *-----------------------------------------------------------------------------*/
1458static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1459{
1460 struct enet_frame *ef_ptr;
1461 unsigned long data_len;
1462 unsigned long rx_eob_isr;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001463 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001464
1465 int handled = 0;
1466 int i;
1467 int loop_count = 0;
1468
1469 rx_eob_isr = mfdcr (malrxeobisr);
1470 if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
1471 /* clear EOB */
1472 mtdcr (malrxeobisr, rx_eob_isr);
1473
1474 /* EMAC RX done */
1475 while (1) { /* do all */
1476 i = hw_p->rx_slot;
1477
1478 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1479 || (loop_count >= NUM_RX_BUFF))
1480 break;
Stefan Roese09feb382007-07-12 16:32:08 +02001481
wdenk544e9732004-02-06 23:19:44 +00001482 loop_count++;
wdenk544e9732004-02-06 23:19:44 +00001483 handled++;
1484 data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
1485 if (data_len) {
1486 if (data_len > ENET_MAX_MTU) /* Check len */
1487 data_len = 0;
1488 else {
1489 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1490 data_len = 0;
1491 hw_p->stats.rx_err_log[hw_p->
1492 rx_err_index]
1493 = hw_p->rx[i].ctrl;
1494 hw_p->rx_err_index++;
1495 if (hw_p->rx_err_index ==
1496 MAX_ERR_LOG)
1497 hw_p->rx_err_index =
1498 0;
wdenk7ad5e4c2004-04-25 15:41:35 +00001499 } /* emac_erros */
wdenk544e9732004-02-06 23:19:44 +00001500 } /* data_len < max mtu */
wdenk7ad5e4c2004-04-25 15:41:35 +00001501 } /* if data_len */
wdenk544e9732004-02-06 23:19:44 +00001502 if (!data_len) { /* no data */
1503 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1504
1505 hw_p->stats.data_len_err++; /* Error at Rx */
1506 }
1507
1508 /* !data_len */
1509 /* AS.HARNOIS */
1510 /* Check if user has already eaten buffer */
1511 /* if not => ERROR */
1512 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1513 if (hw_p->is_receiving)
1514 printf ("ERROR : Receive buffers are full!\n");
1515 break;
1516 } else {
1517 hw_p->stats.rx_frames++;
1518 hw_p->stats.rx += data_len;
1519 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1520 data_ptr;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001521#ifdef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +00001522 hw_p->stats.pkts_rx++;
1523#endif
1524 /* AS.HARNOIS
1525 * use ring buffer
1526 */
1527 hw_p->rx_ready[hw_p->rx_i_index] = i;
1528 hw_p->rx_i_index++;
1529 if (NUM_RX_BUFF == hw_p->rx_i_index)
1530 hw_p->rx_i_index = 0;
1531
Stefan Roese09feb382007-07-12 16:32:08 +02001532 hw_p->rx_slot++;
1533 if (NUM_RX_BUFF == hw_p->rx_slot)
1534 hw_p->rx_slot = 0;
1535
wdenk544e9732004-02-06 23:19:44 +00001536 /* AS.HARNOIS
1537 * free receive buffer only when
1538 * buffer has been handled (eth_rx)
1539 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1540 */
1541 } /* if data_len */
1542 } /* while */
1543 } /* if EMACK_RXCHL */
1544}
1545
1546
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001547static int ppc_4xx_eth_rx (struct eth_device *dev)
wdenk544e9732004-02-06 23:19:44 +00001548{
1549 int length;
1550 int user_index;
1551 unsigned long msr;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001552 EMAC_4XX_HW_PST hw_p = dev->priv;
wdenk544e9732004-02-06 23:19:44 +00001553
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001554 hw_p->is_receiving = 1; /* tell driver */
wdenk544e9732004-02-06 23:19:44 +00001555
1556 for (;;) {
1557 /* AS.HARNOIS
1558 * use ring buffer and
1559 * get index from rx buffer desciptor queue
1560 */
1561 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1562 if (user_index == -1) {
1563 length = -1;
1564 break; /* nothing received - leave for() loop */
1565 }
1566
1567 msr = mfmsr ();
1568 mtmsr (msr & ~(MSR_EE));
1569
1570 length = hw_p->rx[user_index].data_len;
1571
1572 /* Pass the packet up to the protocol layers. */
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001573 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1574 /* NetReceive(NetRxPackets[i], length); */
wdenk544e9732004-02-06 23:19:44 +00001575 NetReceive (NetRxPackets[user_index], length - 4);
1576 /* Free Recv Buffer */
1577 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1578 /* Free rx buffer descriptor queue */
1579 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1580 hw_p->rx_u_index++;
1581 if (NUM_RX_BUFF == hw_p->rx_u_index)
1582 hw_p->rx_u_index = 0;
1583
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001584#ifdef INFO_4XX_ENET
wdenk544e9732004-02-06 23:19:44 +00001585 hw_p->stats.pkts_handled++;
1586#endif
1587
1588 mtmsr (msr); /* Enable IRQ's */
1589 }
1590
Wolfgang Denk0cbaf642005-09-25 00:53:22 +02001591 hw_p->is_receiving = 0; /* tell driver */
wdenk544e9732004-02-06 23:19:44 +00001592
1593 return length;
1594}
1595
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001596int ppc_4xx_eth_initialize (bd_t * bis)
wdenk544e9732004-02-06 23:19:44 +00001597{
1598 static int virgin = 0;
wdenk544e9732004-02-06 23:19:44 +00001599 struct eth_device *dev;
1600 int eth_num = 0;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001601 EMAC_4XX_HW_PST hw = NULL;
Stefan Roese8d982302007-01-18 10:25:34 +01001602 u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1603 u32 hw_addr[4];
wdenk544e9732004-02-06 23:19:44 +00001604
Stefan Roeseb30f2a12005-08-08 12:42:22 +02001605#if defined(CONFIG_440GX)
Stefan Roese326c9712005-08-01 16:41:48 +02001606 unsigned long pfc1;
1607
wdenk544e9732004-02-06 23:19:44 +00001608 mfsdr (sdr_pfc1, pfc1);
1609 pfc1 &= ~(0x01e00000);
1610 pfc1 |= 0x01200000;
1611 mtsdr (sdr_pfc1, pfc1);
Stefan Roese326c9712005-08-01 16:41:48 +02001612#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001613
Stefan Roese8d982302007-01-18 10:25:34 +01001614 /* first clear all mac-addresses */
1615 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1616 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
wdenk97e8bda2004-09-29 22:43:59 +00001617
Stefan Roese7f98aec2005-10-20 16:34:28 +02001618 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
wdenk544e9732004-02-06 23:19:44 +00001619 switch (eth_num) {
wdenk54070ab2004-12-31 09:32:47 +00001620 default: /* fall through */
wdenk544e9732004-02-06 23:19:44 +00001621 case 0:
Stefan Roese8d982302007-01-18 10:25:34 +01001622 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1623 bis->bi_enetaddr, 6);
1624 hw_addr[eth_num] = 0x0;
wdenk544e9732004-02-06 23:19:44 +00001625 break;
wdenk54070ab2004-12-31 09:32:47 +00001626#ifdef CONFIG_HAS_ETH1
wdenk544e9732004-02-06 23:19:44 +00001627 case 1:
Stefan Roese8d982302007-01-18 10:25:34 +01001628 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1629 bis->bi_enet1addr, 6);
1630 hw_addr[eth_num] = 0x100;
wdenk544e9732004-02-06 23:19:44 +00001631 break;
wdenk54070ab2004-12-31 09:32:47 +00001632#endif
1633#ifdef CONFIG_HAS_ETH2
wdenk544e9732004-02-06 23:19:44 +00001634 case 2:
Stefan Roese8d982302007-01-18 10:25:34 +01001635 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1636 bis->bi_enet2addr, 6);
1637 hw_addr[eth_num] = 0x400;
wdenk544e9732004-02-06 23:19:44 +00001638 break;
wdenk54070ab2004-12-31 09:32:47 +00001639#endif
1640#ifdef CONFIG_HAS_ETH3
wdenk544e9732004-02-06 23:19:44 +00001641 case 3:
Stefan Roese8d982302007-01-18 10:25:34 +01001642 memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1643 bis->bi_enet3addr, 6);
1644 hw_addr[eth_num] = 0x600;
wdenk544e9732004-02-06 23:19:44 +00001645 break;
wdenk54070ab2004-12-31 09:32:47 +00001646#endif
wdenk544e9732004-02-06 23:19:44 +00001647 }
Stefan Roese8d982302007-01-18 10:25:34 +01001648 }
1649
1650 /* set phy num and mode */
1651 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
1652 bis->bi_phymode[0] = 0;
1653
1654#if defined(CONFIG_PHY1_ADDR)
1655 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
1656 bis->bi_phymode[1] = 0;
1657#endif
1658#if defined(CONFIG_440GX)
1659 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1660 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1661 bis->bi_phymode[2] = 2;
1662 bis->bi_phymode[3] = 2;
Stefan Roese153b3e22007-10-05 17:10:59 +02001663#endif
Stefan Roese8d982302007-01-18 10:25:34 +01001664
Stefan Roese153b3e22007-10-05 17:10:59 +02001665#if defined(CONFIG_440GX) || \
1666 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1667 defined(CONFIG_405EX)
Stefan Roese8d982302007-01-18 10:25:34 +01001668 ppc_4xx_eth_setup_bridge(0, bis);
1669#endif
1670
1671 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1672 /*
1673 * See if we can actually bring up the interface,
1674 * otherwise, skip it
1675 */
1676 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
1677 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1678 continue;
1679 }
wdenk544e9732004-02-06 23:19:44 +00001680
1681 /* Allocate device structure */
1682 dev = (struct eth_device *) malloc (sizeof (*dev));
1683 if (dev == NULL) {
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001684 printf ("ppc_4xx_eth_initialize: "
wdenkef893942004-02-23 16:11:30 +00001685 "Cannot allocate eth_device %d\n", eth_num);
wdenk544e9732004-02-06 23:19:44 +00001686 return (-1);
1687 }
wdenkd1894de2005-06-20 10:17:34 +00001688 memset(dev, 0, sizeof(*dev));
wdenk544e9732004-02-06 23:19:44 +00001689
1690 /* Allocate our private use data */
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001691 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
wdenk544e9732004-02-06 23:19:44 +00001692 if (hw == NULL) {
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001693 printf ("ppc_4xx_eth_initialize: "
wdenkef893942004-02-23 16:11:30 +00001694 "Cannot allocate private hw data for eth_device %d",
wdenk544e9732004-02-06 23:19:44 +00001695 eth_num);
1696 free (dev);
1697 return (-1);
1698 }
wdenkd1894de2005-06-20 10:17:34 +00001699 memset(hw, 0, sizeof(*hw));
wdenk544e9732004-02-06 23:19:44 +00001700
Stefan Roese8d982302007-01-18 10:25:34 +01001701 hw->hw_addr = hw_addr[eth_num];
1702 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
wdenk544e9732004-02-06 23:19:44 +00001703 hw->devnum = eth_num;
Stefan Roese326c9712005-08-01 16:41:48 +02001704 hw->print_speed = 1;
wdenk544e9732004-02-06 23:19:44 +00001705
Stefan Roese8d982302007-01-18 10:25:34 +01001706 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
wdenk544e9732004-02-06 23:19:44 +00001707 dev->priv = (void *) hw;
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001708 dev->init = ppc_4xx_eth_init;
1709 dev->halt = ppc_4xx_eth_halt;
1710 dev->send = ppc_4xx_eth_send;
1711 dev->recv = ppc_4xx_eth_rx;
wdenk544e9732004-02-06 23:19:44 +00001712
1713 if (0 == virgin) {
1714 /* set the MAL IER ??? names may change with new spec ??? */
Stefan Roese153b3e22007-10-05 17:10:59 +02001715#if defined(CONFIG_440SPE) || \
1716 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1717 defined(CONFIG_405EX)
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001718 mal_ier =
1719 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
1720 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
1721#else
wdenk544e9732004-02-06 23:19:44 +00001722 mal_ier =
1723 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
1724 MAL_IER_OPBE | MAL_IER_PLBE;
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001725#endif
wdenk544e9732004-02-06 23:19:44 +00001726 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
1727 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
1728 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
1729 mtdcr (malier, mal_ier);
1730
1731 /* install MAL interrupt handler */
1732 irq_install_handler (VECNUM_MS,
1733 (interrupt_handler_t *) enetInt,
1734 dev);
1735 irq_install_handler (VECNUM_MTE,
1736 (interrupt_handler_t *) enetInt,
1737 dev);
1738 irq_install_handler (VECNUM_MRE,
1739 (interrupt_handler_t *) enetInt,
1740 dev);
1741 irq_install_handler (VECNUM_TXDE,
1742 (interrupt_handler_t *) enetInt,
1743 dev);
1744 irq_install_handler (VECNUM_RXDE,
1745 (interrupt_handler_t *) enetInt,
1746 dev);
1747 virgin = 1;
1748 }
1749
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001750#if defined(CONFIG_NET_MULTI)
wdenk544e9732004-02-06 23:19:44 +00001751 eth_register (dev);
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001752#else
1753 emac0_dev = dev;
1754#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001755
1756#if defined(CONFIG_NET_MULTI)
Jon Loeligera5217742007-07-09 18:57:22 -05001757#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001758 miiphy_register (dev->name,
Stefan Roese99644742005-11-29 18:18:21 +01001759 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001760#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001761#endif
wdenk544e9732004-02-06 23:19:44 +00001762 } /* end for each supported device */
1763 return (1);
1764}
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001765
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001766#if !defined(CONFIG_NET_MULTI)
1767void eth_halt (void) {
1768 if (emac0_dev) {
1769 ppc_4xx_eth_halt(emac0_dev);
1770 free(emac0_dev);
1771 emac0_dev = NULL;
1772 }
1773}
1774
1775int eth_init (bd_t *bis)
1776{
1777 ppc_4xx_eth_initialize(bis);
Stefan Roese03510612005-10-10 17:43:58 +02001778 if (emac0_dev) {
1779 return ppc_4xx_eth_init(emac0_dev, bis);
1780 } else {
1781 printf("ERROR: ethaddr not set!\n");
1782 return -1;
1783 }
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001784}
1785
1786int eth_send(volatile void *packet, int length)
1787{
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001788 return (ppc_4xx_eth_send(emac0_dev, packet, length));
1789}
1790
1791int eth_rx(void)
1792{
1793 return (ppc_4xx_eth_rx(emac0_dev));
1794}
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001795
1796int emac4xx_miiphy_initialize (bd_t * bis)
1797{
Jon Loeligera5217742007-07-09 18:57:22 -05001798#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001799 miiphy_register ("ppc_4xx_eth0",
Stefan Roese99644742005-11-29 18:18:21 +01001800 emac4xx_miiphy_read, emac4xx_miiphy_write);
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001801#endif
1802
1803 return 0;
1804}
Stefan Roese0c7ffc02005-08-16 18:18:00 +02001805#endif /* !defined(CONFIG_NET_MULTI) */
1806
Jon Loeligera5217742007-07-09 18:57:22 -05001807#endif