blob: 24e6ef35730c90b8771bd9cb141cb05f58823677 [file] [log] [blame]
wdenkba56f622004-02-06 23:19:44 +00001/*-----------------------------------------------------------------------------+
2 *
3 * 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.
9 *
10 * 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.
13 *
14 * 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.
17 *
18 * COPYRIGHT I B M CORPORATION 1995
19 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
20 *-----------------------------------------------------------------------------*/
21/*-----------------------------------------------------------------------------+
22 *
23 * File Name: enetemac.c
24 *
25 * Function: Device driver for the ethernet EMAC3 macro on the 405GP.
26 *
27 * Author: Mark Wisner
28 *
29 * Change Activity-
30 *
31 * 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).
70 *-----------------------------------------------------------------------------*
71 * 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 *-----------------------------------------------------------------------------*/
76
77#include <config.h>
78#if defined(CONFIG_440) && defined(CONFIG_NET_MULTI)
79
80#include <common.h>
81#include <net.h>
82#include <asm/processor.h>
83#include <ppc440.h>
84#include <commproc.h>
85#include <440gx_enet.h>
86#include <405_mal.h>
87#include <miiphy.h>
88#include <malloc.h>
89#include "vecnum.h"
90
91
92#define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
93#define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */
94
95
96/* Ethernet Transmit and Receive Buffers */
97/* AS.HARNOIS
98 * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
99 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
100 */
101#define ENET_MAX_MTU PKTSIZE
102#define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
103
104
105/* define the number of channels implemented */
106#define EMAC_RXCHL EMAC_NUM_DEV
107#define EMAC_TXCHL EMAC_NUM_DEV
108
109/*-----------------------------------------------------------------------------+
110 * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
111 * Interrupt Controller).
112 *-----------------------------------------------------------------------------*/
113#define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
114#define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
115#define EMAC_UIC_DEF UIC_ENET
116
117#undef INFO_440_ENET
118
wdenk3c74e322004-02-22 23:46:08 +0000119#define BI_PHYMODE_NONE 0
120#define BI_PHYMODE_ZMII 1
121#define BI_PHYMODE_RGMII 2
122
wdenkba56f622004-02-06 23:19:44 +0000123/*-----------------------------------------------------------------------------+
124 * Global variables. TX and RX descriptors and buffers.
125 *-----------------------------------------------------------------------------*/
126/* IER globals */
127static uint32_t mal_ier;
128
129/*-----------------------------------------------------------------------------+
130 * Prototypes and externals.
131 *-----------------------------------------------------------------------------*/
132static void enet_rcv (struct eth_device *dev, unsigned long malisr);
133
134int enetInt (struct eth_device *dev);
135static void mal_err (struct eth_device *dev, unsigned long isr,
136 unsigned long uic, unsigned long maldef,
137 unsigned long mal_errr);
138static void emac_err (struct eth_device *dev, unsigned long isr);
139
140/*-----------------------------------------------------------------------------+
141| ppc_440x_eth_halt
142| Disable MAL channel, and EMACn
143|
144|
145+-----------------------------------------------------------------------------*/
146static void ppc_440x_eth_halt (struct eth_device *dev)
147{
148 EMAC_440GX_HW_PST hw_p = dev->priv;
149 uint32_t failsafe = 10000;
150
151 out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
152
153 /* 1st reset MAL channel */
154 /* Note: writing a 0 to a channel has no effect */
155 mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
156 mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
157
158 /* wait for reset */
159 while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
160 udelay (1000); /* Delay 1 MS so as not to hammer the register */
161 failsafe--;
162 if (failsafe == 0)
163 break;
164
165 }
166
167 /* EMAC RESET */
168 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
169
Stefan Roesec157d8e2005-08-01 16:41:48 +0200170 hw_p->print_speed = 1; /* print speed message again next time */
171
wdenkba56f622004-02-06 23:19:44 +0000172 return;
173}
174
175extern int phy_setup_aneg (unsigned char addr);
176extern int miiphy_reset (unsigned char addr);
177
wdenk855a4962004-03-14 18:23:55 +0000178#if defined (CONFIG_440_GX)
179int ppc_440x_eth_setup_bridge(int devnum, bd_t * bis)
180{
181 unsigned long pfc1;
182 unsigned long zmiifer;
183 unsigned long rmiifer;
184
185 mfsdr(sdr_pfc1, pfc1);
186 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
187
188 zmiifer = 0;
189 rmiifer = 0;
190
191 switch (pfc1) {
192 case 1:
193 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
194 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
195 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
196 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
197 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
198 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
199 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
200 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
201 break;
202 case 2:
203 zmiifer = ZMII_FER_SMII << ZMII_FER_V(0);
204 zmiifer = ZMII_FER_SMII << ZMII_FER_V(1);
205 zmiifer = ZMII_FER_SMII << ZMII_FER_V(2);
206 zmiifer = ZMII_FER_SMII << ZMII_FER_V(3);
207 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
208 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
209 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
210 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
211 break;
212 case 3:
213 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
214 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
215 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
216 bis->bi_phymode[1] = BI_PHYMODE_NONE;
217 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
218 bis->bi_phymode[3] = BI_PHYMODE_NONE;
219 break;
220 case 4:
221 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
222 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
223 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
224 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
225 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
226 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
227 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
228 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
229 break;
230 case 5:
231 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
232 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
233 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
234 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
235 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
236 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
237 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
238 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
239 break;
240 case 6:
241 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
242 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
243 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
wdenk855a4962004-03-14 18:23:55 +0000244 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
245 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
246 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
wdenk855a4962004-03-14 18:23:55 +0000247 break;
248 case 0:
249 default:
250 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
251 rmiifer = 0x0;
252 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
253 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
254 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
255 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
256 break;
257 }
258
259 /* Ensure we setup mdio for this devnum and ONLY this devnum */
260 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
261
262 out32 (ZMII_FER, zmiifer);
263 out32 (RGMII_FER, rmiifer);
264
265 return ((int)pfc1);
266
267}
268#endif
269
wdenkba56f622004-02-06 23:19:44 +0000270static int ppc_440x_eth_init (struct eth_device *dev, bd_t * bis)
271{
272 int i;
273 unsigned long reg;
274 unsigned long msr;
275 unsigned long speed;
276 unsigned long duplex;
277 unsigned long failsafe;
278 unsigned mode_reg;
279 unsigned short devnum;
280 unsigned short reg_short;
281 sys_info_t sysinfo;
Stefan Roesec157d8e2005-08-01 16:41:48 +0200282#if defined(CONFIG_440_GX)
wdenk855a4962004-03-14 18:23:55 +0000283 int ethgroup;
Stefan Roesec157d8e2005-08-01 16:41:48 +0200284#endif
wdenkba56f622004-02-06 23:19:44 +0000285
286 EMAC_440GX_HW_PST hw_p = dev->priv;
287
288 /* before doing anything, figure out if we have a MAC address */
289 /* if not, bail */
290 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0)
291 return -1;
292
293 /* Need to get the OPB frequency so we can access the PHY */
294 get_sys_info (&sysinfo);
295
wdenkba56f622004-02-06 23:19:44 +0000296 msr = mfmsr ();
297 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
298
299 devnum = hw_p->devnum;
300
301#ifdef INFO_440_ENET
302 /* AS.HARNOIS
303 * We should have :
304 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
305 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
306 * is possible that new packets (without relationship with
307 * current transfer) have got the time to arrived before
308 * netloop calls eth_halt
309 */
310 printf ("About preceeding transfer (eth%d):\n"
311 "- Sent packet number %d\n"
312 "- Received packet number %d\n"
313 "- Handled packet number %d\n",
314 hw_p->devnum,
315 hw_p->stats.pkts_tx,
316 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
317
318 hw_p->stats.pkts_tx = 0;
319 hw_p->stats.pkts_rx = 0;
320 hw_p->stats.pkts_handled = 0;
321#endif
322
323 /* MAL Channel RESET */
324 /* 1st reset MAL channel */
325 /* Note: writing a 0 to a channel has no effect */
Stefan Roesec157d8e2005-08-01 16:41:48 +0200326#if defined(CONFIG_440_EP) || defined(CONFIG_440_GR)
327 mtdcr (maltxcarr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
328#else
wdenkba56f622004-02-06 23:19:44 +0000329 mtdcr (maltxcarr, (MAL_TXRX_CASR >> hw_p->devnum));
Stefan Roesec157d8e2005-08-01 16:41:48 +0200330#endif
331
wdenkba56f622004-02-06 23:19:44 +0000332 mtdcr (malrxcarr, (MAL_TXRX_CASR >> hw_p->devnum));
333
334 /* wait for reset */
335 /* TBS: should have udelay and failsafe here */
336 failsafe = 10000;
337 /* wait for reset */
338 while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
339 udelay (1000); /* Delay 1 MS so as not to hammer the register */
340 failsafe--;
341 if (failsafe == 0)
342 break;
343
344 }
345
346 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
347 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
348
349 hw_p->rx_slot = 0; /* MAL Receive Slot */
350 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
351 hw_p->rx_u_index = 0; /* Receive User Queue Index */
352
353 hw_p->tx_slot = 0; /* MAL Transmit Slot */
354 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
355 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
356
357 /* set RMII mode */
358 /* NOTE: 440GX spec states that mode is mutually exclusive */
359 /* NOTE: Therefore, disable all other EMACS, since we handle */
360 /* NOTE: only one emac at a time */
361 reg = 0;
362 out32 (ZMII_FER, 0);
363 udelay (100);
wdenkba56f622004-02-06 23:19:44 +0000364
Stefan Roesec157d8e2005-08-01 16:41:48 +0200365#if defined(CONFIG_440_EP) || defined(CONFIG_440_GR)
366 out32 (ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
367#elif defined(CONFIG_440_GX)
wdenk855a4962004-03-14 18:23:55 +0000368 ethgroup = ppc_440x_eth_setup_bridge(devnum, bis);
wdenk0e6d7982004-03-14 00:07:33 +0000369#else
370 if ((devnum == 0) || (devnum == 1)) {
371 out32 (ZMII_FER, (ZMII_FER_SMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
372 }
373 else { /* ((devnum == 2) || (devnum == 3)) */
374 out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum));
wdenkba56f622004-02-06 23:19:44 +0000375 out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) |
376 (RGMII_FER_RGMII << RGMII_FER_V (3))));
wdenk0e6d7982004-03-14 00:07:33 +0000377 }
wdenk855a4962004-03-14 18:23:55 +0000378
wdenk0e6d7982004-03-14 00:07:33 +0000379#endif
380 out32 (ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
381 __asm__ volatile ("eieio");
382
383 /* reset emac so we have access to the phy */
384
385 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenkba56f622004-02-06 23:19:44 +0000386 __asm__ volatile ("eieio");
387
388 failsafe = 1000;
389 while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
390 udelay (1000);
391 failsafe--;
392 }
393
394 /* Whack the M1 register */
395 mode_reg = 0x0;
396 mode_reg &= ~0x00000038;
397 if (sysinfo.freqOPB <= 50000000);
398 else if (sysinfo.freqOPB <= 66666667)
399 mode_reg |= EMAC_M1_OBCI_66;
400 else if (sysinfo.freqOPB <= 83333333)
401 mode_reg |= EMAC_M1_OBCI_83;
402 else if (sysinfo.freqOPB <= 100000000)
403 mode_reg |= EMAC_M1_OBCI_100;
404 else
405 mode_reg |= EMAC_M1_OBCI_GT100;
406
407 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
408
409
410 /* wait for PHY to complete auto negotiation */
411 reg_short = 0;
412#ifndef CONFIG_CS8952_PHY
413 switch (devnum) {
414 case 0:
415 reg = CONFIG_PHY_ADDR;
416 break;
417 case 1:
418 reg = CONFIG_PHY1_ADDR;
419 break;
420#if defined (CONFIG_440_GX)
421 case 2:
422 reg = CONFIG_PHY2_ADDR;
423 break;
424 case 3:
425 reg = CONFIG_PHY3_ADDR;
426 break;
427#endif
428 default:
429 reg = CONFIG_PHY_ADDR;
430 break;
431 }
432
wdenk3c74e322004-02-22 23:46:08 +0000433 bis->bi_phynum[devnum] = reg;
434
wdenka06752e2004-09-29 22:43:59 +0000435 /*
436 * Reset the phy, only if its the first time through
437 * otherwise, just check the speeds & feeds
438 */
439 if (hw_p->first_init == 0) {
440 miiphy_reset (reg);
wdenkba56f622004-02-06 23:19:44 +0000441
wdenk855a4962004-03-14 18:23:55 +0000442#if defined(CONFIG_440_GX)
wdenk0e6d7982004-03-14 00:07:33 +0000443#if defined(CONFIG_CIS8201_PHY)
444 /*
445 * Cicada 8201 PHY needs to have an extended register whacked
446 * for RGMII mode.
447 */
wdenk855a4962004-03-14 18:23:55 +0000448 if ( ((devnum == 2) || (devnum ==3)) && (4 == ethgroup) ) {
wdenk0e6d7982004-03-14 00:07:33 +0000449 miiphy_write (reg, 23, 0x1200);
wdenkfc1cfcd2004-04-25 15:41:35 +0000450 /*
451 * Vitesse VSC8201/Cicada CIS8201 errata:
452 * Interoperability problem with Intel 82547EI phys
453 * This work around (provided by Vitesse) changes
454 * the default timer convergence from 8ms to 12ms
455 */
456 miiphy_write (reg, 0x1f, 0x2a30);
457 miiphy_write (reg, 0x08, 0x0200);
458 miiphy_write (reg, 0x1f, 0x52b5);
459 miiphy_write (reg, 0x02, 0x0004);
460 miiphy_write (reg, 0x01, 0x0671);
461 miiphy_write (reg, 0x00, 0x8fae);
462 miiphy_write (reg, 0x1f, 0x2a30);
463 miiphy_write (reg, 0x08, 0x0000);
464 miiphy_write (reg, 0x1f, 0x0000);
465 /* end Vitesse/Cicada errata */
wdenk0e6d7982004-03-14 00:07:33 +0000466 }
467#endif
wdenk855a4962004-03-14 18:23:55 +0000468#endif
wdenka06752e2004-09-29 22:43:59 +0000469 /* Start/Restart autonegotiation */
470 phy_setup_aneg (reg);
471 udelay (1000);
472 }
wdenkba56f622004-02-06 23:19:44 +0000473
474 miiphy_read (reg, PHY_BMSR, &reg_short);
475
476 /*
wdenk0e6d7982004-03-14 00:07:33 +0000477 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
wdenkba56f622004-02-06 23:19:44 +0000478 */
479 if ((reg_short & PHY_BMSR_AUTN_ABLE)
480 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
481 puts ("Waiting for PHY auto negotiation to complete");
482 i = 0;
483 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
484 /*
485 * Timeout reached ?
486 */
487 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
488 puts (" TIMEOUT !\n");
489 break;
490 }
491
492 if ((i++ % 1000) == 0) {
493 putc ('.');
494 }
495 udelay (1000); /* 1 ms */
496 miiphy_read (reg, PHY_BMSR, &reg_short);
497
498 }
499 puts (" done\n");
500 udelay (500000); /* another 500 ms (results in faster booting) */
501 }
502#endif
503 speed = miiphy_speed (reg);
504 duplex = miiphy_duplex (reg);
505
506 if (hw_p->print_speed) {
507 hw_p->print_speed = 0;
508 printf ("ENET Speed is %d Mbps - %s duplex connection\n",
509 (int) speed, (duplex == HALF) ? "HALF" : "FULL");
510 }
511
Stefan Roesec157d8e2005-08-01 16:41:48 +0200512#if defined(CONFIG_440_EP) || defined(CONFIG_440_GR)
513 mfsdr(sdr_mfr, reg);
514 if (speed == 100) {
515 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
516 } else {
517 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
518 }
519 mtsdr(sdr_mfr, reg);
520#endif
wdenkba56f622004-02-06 23:19:44 +0000521 /* Set ZMII/RGMII speed according to the phy link speed */
522 reg = in32 (ZMII_SSR);
wdenk855a4962004-03-14 18:23:55 +0000523 if ( (speed == 100) || (speed == 1000) )
wdenkba56f622004-02-06 23:19:44 +0000524 out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
525 else
526 out32 (ZMII_SSR,
527 reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
528
529 if ((devnum == 2) || (devnum == 3)) {
530 if (speed == 1000)
531 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
532 else if (speed == 100)
533 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
534 else
535 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
536
537 out32 (RGMII_SSR, reg);
538 }
539
540 /* set the Mal configuration reg */
541 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
542 if (get_pvr () == PVR_440GP_RB)
543 mtdcr (malmcr,
544 MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
545 else
546 mtdcr (malmcr,
547 MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
548 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
549
550 /* Free "old" buffers */
551 if (hw_p->alloc_tx_buf)
552 free (hw_p->alloc_tx_buf);
553 if (hw_p->alloc_rx_buf)
554 free (hw_p->alloc_rx_buf);
555
556 /*
557 * Malloc MAL buffer desciptors, make sure they are
558 * aligned on cache line boundary size
559 * (401/403/IOP480 = 16, 405 = 32)
560 * and doesn't cross cache block boundaries.
561 */
562 hw_p->alloc_tx_buf =
563 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
564 ((2 * CFG_CACHELINE_SIZE) - 2));
565 if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
566 hw_p->tx =
567 (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
568 CFG_CACHELINE_SIZE -
569 ((int) hw_p->
570 alloc_tx_buf & CACHELINE_MASK));
571 } else {
572 hw_p->tx = hw_p->alloc_tx_buf;
573 }
574
575 hw_p->alloc_rx_buf =
576 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
577 ((2 * CFG_CACHELINE_SIZE) - 2));
578 if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
579 hw_p->rx =
580 (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
581 CFG_CACHELINE_SIZE -
582 ((int) hw_p->
583 alloc_rx_buf & CACHELINE_MASK));
584 } else {
585 hw_p->rx = hw_p->alloc_rx_buf;
586 }
587
588 for (i = 0; i < NUM_TX_BUFF; i++) {
589 hw_p->tx[i].ctrl = 0;
590 hw_p->tx[i].data_len = 0;
591 if (hw_p->first_init == 0)
592 hw_p->txbuf_ptr =
593 (char *) malloc (ENET_MAX_MTU_ALIGNED);
594 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
595 if ((NUM_TX_BUFF - 1) == i)
596 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
597 hw_p->tx_run[i] = -1;
598#if 0
599 printf ("TX_BUFF %d @ 0x%08lx\n", i,
600 (ulong) hw_p->tx[i].data_ptr);
601#endif
602 }
603
604 for (i = 0; i < NUM_RX_BUFF; i++) {
605 hw_p->rx[i].ctrl = 0;
606 hw_p->rx[i].data_len = 0;
607 /* rx[i].data_ptr = (char *) &rx_buff[i]; */
608 hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
609 if ((NUM_RX_BUFF - 1) == i)
610 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
611 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
612 hw_p->rx_ready[i] = -1;
613#if 0
614 printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr);
615#endif
616 }
617
618 reg = 0x00000000;
619
620 reg |= dev->enetaddr[0]; /* set high address */
621 reg = reg << 8;
622 reg |= dev->enetaddr[1];
623
624 out32 (EMAC_IAH + hw_p->hw_addr, reg);
625
626 reg = 0x00000000;
627 reg |= dev->enetaddr[2]; /* set low address */
628 reg = reg << 8;
629 reg |= dev->enetaddr[3];
630 reg = reg << 8;
631 reg |= dev->enetaddr[4];
632 reg = reg << 8;
633 reg |= dev->enetaddr[5];
634
635 out32 (EMAC_IAL + hw_p->hw_addr, reg);
636
637 switch (devnum) {
638 case 1:
639 /* setup MAL tx & rx channel pointers */
Stefan Roesec157d8e2005-08-01 16:41:48 +0200640#if defined (CONFIG_440_EP) || defined (CONFIG_440_GR)
641 mtdcr (maltxctp2r, hw_p->tx);
642#else
wdenkba56f622004-02-06 23:19:44 +0000643 mtdcr (maltxctp1r, hw_p->tx);
Stefan Roesec157d8e2005-08-01 16:41:48 +0200644#endif
645 mtdcr (maltxbattr, 0x0);
wdenkba56f622004-02-06 23:19:44 +0000646 mtdcr (malrxbattr, 0x0);
647 mtdcr (malrxctp1r, hw_p->rx);
648 /* set RX buffer size */
649 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
650 break;
651#if defined (CONFIG_440_GX)
652 case 2:
653 /* setup MAL tx & rx channel pointers */
654 mtdcr (maltxbattr, 0x0);
655 mtdcr (maltxctp2r, hw_p->tx);
656 mtdcr (malrxbattr, 0x0);
657 mtdcr (malrxctp2r, hw_p->rx);
658 /* set RX buffer size */
659 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
660 break;
661 case 3:
662 /* setup MAL tx & rx channel pointers */
663 mtdcr (maltxbattr, 0x0);
664 mtdcr (maltxctp3r, hw_p->tx);
665 mtdcr (malrxbattr, 0x0);
666 mtdcr (malrxctp3r, hw_p->rx);
667 /* set RX buffer size */
668 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
669 break;
670#endif /*CONFIG_440_GX */
671 case 0:
672 default:
673 /* setup MAL tx & rx channel pointers */
674 mtdcr (maltxbattr, 0x0);
675 mtdcr (maltxctp0r, hw_p->tx);
676 mtdcr (malrxbattr, 0x0);
677 mtdcr (malrxctp0r, hw_p->rx);
678 /* set RX buffer size */
679 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
680 break;
681 }
682
683 /* Enable MAL transmit and receive channels */
Stefan Roesec157d8e2005-08-01 16:41:48 +0200684#if defined(CONFIG_440_EP) || defined(CONFIG_440_GR)
685 mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
686#else
wdenkba56f622004-02-06 23:19:44 +0000687 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
Stefan Roesec157d8e2005-08-01 16:41:48 +0200688#endif
wdenkba56f622004-02-06 23:19:44 +0000689 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
690
691 /* set transmit enable & receive enable */
692 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
693
694 /* set receive fifo to 4k and tx fifo to 2k */
695 mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
696 mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
697
698 /* set speed */
wdenk855a4962004-03-14 18:23:55 +0000699 if (speed == _1000BASET)
700 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
701 else if (speed == _100BASET)
wdenkba56f622004-02-06 23:19:44 +0000702 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
703 else
704 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
705 if (duplex == FULL)
706 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
707
708 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
709
710 /* Enable broadcast and indvidual address */
711 /* TBS: enabling runts as some misbehaved nics will send runts */
712 out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
713
714 /* we probably need to set the tx mode1 reg? maybe at tx time */
715
716 /* set transmit request threshold register */
717 out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
718
719 /* set receive low/high water mark register */
720 /* 440GP has a 64 byte burst length */
721 out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
722 out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
723
724 /* Set fifo limit entry in tx mode 0 */
725 out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
726 /* Frame gap set */
727 out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
728
729 /* Set EMAC IER */
730 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS |
731 EMAC_ISR_PTLE | EMAC_ISR_ORE | EMAC_ISR_IRE;
732 if (speed == _100BASET)
733 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
734
735 out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
736 out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
737
738 if (hw_p->first_init == 0) {
739 /*
740 * Connect interrupt service routines
741 */
742 irq_install_handler (VECNUM_EWU0 + (hw_p->devnum * 2),
743 (interrupt_handler_t *) enetInt, dev);
744 irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2),
745 (interrupt_handler_t *) enetInt, dev);
746 }
wdenkba56f622004-02-06 23:19:44 +0000747
748 mtmsr (msr); /* enable interrupts again */
749
750 hw_p->bis = bis;
751 hw_p->first_init = 1;
752
753 return (1);
754}
755
756
757static int ppc_440x_eth_send (struct eth_device *dev, volatile void *ptr,
758 int len)
759{
760 struct enet_frame *ef_ptr;
761 ulong time_start, time_now;
762 unsigned long temp_txm0;
763 EMAC_440GX_HW_PST hw_p = dev->priv;
764
765 ef_ptr = (struct enet_frame *) ptr;
766
767 /*-----------------------------------------------------------------------+
768 * Copy in our address into the frame.
769 *-----------------------------------------------------------------------*/
770 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
771
772 /*-----------------------------------------------------------------------+
773 * If frame is too long or too short, modify length.
774 *-----------------------------------------------------------------------*/
775 /* TBS: where does the fragment go???? */
776 if (len > ENET_MAX_MTU)
777 len = ENET_MAX_MTU;
778
779 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
780 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
781
782 /*-----------------------------------------------------------------------+
783 * set TX Buffer busy, and send it
784 *-----------------------------------------------------------------------*/
785 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
786 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
787 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
788 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
789 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
790
791 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
792 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
793
794 __asm__ volatile ("eieio");
795
796 out32 (EMAC_TXM0 + hw_p->hw_addr,
797 in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
798#ifdef INFO_440_ENET
799 hw_p->stats.pkts_tx++;
800#endif
801
802 /*-----------------------------------------------------------------------+
803 * poll unitl the packet is sent and then make sure it is OK
804 *-----------------------------------------------------------------------*/
805 time_start = get_timer (0);
806 while (1) {
807 temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
808 /* loop until either TINT turns on or 3 seconds elapse */
809 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
810 /* transmit is done, so now check for errors
811 * If there is an error, an interrupt should
812 * happen when we return
813 */
814 time_now = get_timer (0);
815 if ((time_now - time_start) > 3000) {
816 return (-1);
817 }
818 } else {
819 return (len);
820 }
821 }
822}
823
824
825int enetInt (struct eth_device *dev)
826{
827 int serviced;
828 int rc = -1; /* default to not us */
829 unsigned long mal_isr;
830 unsigned long emac_isr = 0;
831 unsigned long mal_rx_eob;
832 unsigned long my_uic0msr, my_uic1msr;
833
834#if defined(CONFIG_440_GX)
835 unsigned long my_uic2msr;
836#endif
837 EMAC_440GX_HW_PST hw_p;
838
839 /*
840 * Because the mal is generic, we need to get the current
841 * eth device
842 */
843 dev = eth_get_dev ();
844
845 hw_p = dev->priv;
846
847
848 /* enter loop that stays in interrupt code until nothing to service */
849 do {
850 serviced = 0;
851
852 my_uic0msr = mfdcr (uic0msr);
853 my_uic1msr = mfdcr (uic1msr);
854#if defined(CONFIG_440_GX)
855 my_uic2msr = mfdcr (uic2msr);
856#endif
857 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
858 && !(my_uic1msr &
859 (UIC_ETH0 | UIC_ETH1 | UIC_MS | UIC_MTDE |
860 UIC_MRDE))) {
861 /* not for us */
862 return (rc);
863 }
864#if defined (CONFIG_440_GX)
865 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
866 && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
867 /* not for us */
868 return (rc);
869 }
870#endif
871 /* get and clear controller status interrupts */
872 /* look at Mal and EMAC interrupts */
873 if ((my_uic0msr & (UIC_MRE | UIC_MTE))
874 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
875 /* we have a MAL interrupt */
876 mal_isr = mfdcr (malesr);
877 /* look for mal error */
878 if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
879 mal_err (dev, mal_isr, my_uic0msr,
880 MAL_UIC_DEF, MAL_UIC_ERR);
881 serviced = 1;
882 rc = 0;
883 }
884 }
885
886 /* port by port dispatch of emac interrupts */
887 if (hw_p->devnum == 0) {
888 if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */
889 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
890 if ((hw_p->emac_ier & emac_isr) != 0) {
891 emac_err (dev, emac_isr);
892 serviced = 1;
893 rc = 0;
894 }
895 }
896 if ((hw_p->emac_ier & emac_isr)
897 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
898 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
899 mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
900 return (rc); /* we had errors so get out */
901 }
902 }
903
904 if (hw_p->devnum == 1) {
905 if (UIC_ETH1 & my_uic1msr) { /* look for EMAC errors */
906 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
907 if ((hw_p->emac_ier & emac_isr) != 0) {
908 emac_err (dev, emac_isr);
909 serviced = 1;
910 rc = 0;
911 }
912 }
913 if ((hw_p->emac_ier & emac_isr)
914 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
915 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
916 mtdcr (uic1sr, UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
917 return (rc); /* we had errors so get out */
918 }
919 }
920#if defined (CONFIG_440_GX)
921 if (hw_p->devnum == 2) {
922 if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
923 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
924 if ((hw_p->emac_ier & emac_isr) != 0) {
925 emac_err (dev, emac_isr);
926 serviced = 1;
927 rc = 0;
928 }
929 }
930 if ((hw_p->emac_ier & emac_isr)
931 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
932 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
933 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
934 mtdcr (uic2sr, UIC_ETH2);
935 return (rc); /* we had errors so get out */
936 }
937 }
938
939 if (hw_p->devnum == 3) {
940 if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
941 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
942 if ((hw_p->emac_ier & emac_isr) != 0) {
943 emac_err (dev, emac_isr);
944 serviced = 1;
945 rc = 0;
946 }
947 }
948 if ((hw_p->emac_ier & emac_isr)
949 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
950 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
951 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
952 mtdcr (uic2sr, UIC_ETH3);
953 return (rc); /* we had errors so get out */
954 }
955 }
956#endif /* CONFIG_440_GX */
957 /* handle MAX TX EOB interrupt from a tx */
958 if (my_uic0msr & UIC_MTE) {
959 mal_rx_eob = mfdcr (maltxeobisr);
960 mtdcr (maltxeobisr, mal_rx_eob);
961 mtdcr (uic0sr, UIC_MTE);
962 }
963 /* handle MAL RX EOB interupt from a receive */
wdenkfc1cfcd2004-04-25 15:41:35 +0000964 /* check for EOB on valid channels */
wdenkba56f622004-02-06 23:19:44 +0000965 if (my_uic0msr & UIC_MRE) {
966 mal_rx_eob = mfdcr (malrxeobisr);
967 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
968 /* clear EOB
969 mtdcr(malrxeobisr, mal_rx_eob); */
970 enet_rcv (dev, emac_isr);
971 /* indicate that we serviced an interrupt */
972 serviced = 1;
973 rc = 0;
974 }
975 }
976 mtdcr (uic0sr, UIC_MRE); /* Clear */
977 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
978 switch (hw_p->devnum) {
979 case 0:
980 mtdcr (uic1sr, UIC_ETH0);
981 break;
982 case 1:
983 mtdcr (uic1sr, UIC_ETH1);
984 break;
985#if defined (CONFIG_440_GX)
986 case 2:
987 mtdcr (uic2sr, UIC_ETH2);
988 break;
989 case 3:
990 mtdcr (uic2sr, UIC_ETH3);
991 break;
992#endif /* CONFIG_440_GX */
993 default:
994 break;
995 }
996 } while (serviced);
997
998 return (rc);
999}
1000
1001/*-----------------------------------------------------------------------------+
1002 * MAL Error Routine
1003 *-----------------------------------------------------------------------------*/
1004static void mal_err (struct eth_device *dev, unsigned long isr,
1005 unsigned long uic, unsigned long maldef,
1006 unsigned long mal_errr)
1007{
1008 EMAC_440GX_HW_PST hw_p = dev->priv;
1009
1010 mtdcr (malesr, isr); /* clear interrupt */
1011
1012 /* clear DE interrupt */
1013 mtdcr (maltxdeir, 0xC0000000);
1014 mtdcr (malrxdeir, 0x80000000);
1015
1016#ifdef INFO_440_ENET
1017 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
1018#endif
1019
1020 eth_init (hw_p->bis); /* start again... */
1021}
1022
1023/*-----------------------------------------------------------------------------+
1024 * EMAC Error Routine
1025 *-----------------------------------------------------------------------------*/
1026static void emac_err (struct eth_device *dev, unsigned long isr)
1027{
1028 EMAC_440GX_HW_PST hw_p = dev->priv;
1029
1030 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
1031 out32 (EMAC_ISR + hw_p->hw_addr, isr);
1032}
1033
1034/*-----------------------------------------------------------------------------+
1035 * enet_rcv() handles the ethernet receive data
1036 *-----------------------------------------------------------------------------*/
1037static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1038{
1039 struct enet_frame *ef_ptr;
1040 unsigned long data_len;
1041 unsigned long rx_eob_isr;
1042 EMAC_440GX_HW_PST hw_p = dev->priv;
1043
1044 int handled = 0;
1045 int i;
1046 int loop_count = 0;
1047
1048 rx_eob_isr = mfdcr (malrxeobisr);
1049 if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
1050 /* clear EOB */
1051 mtdcr (malrxeobisr, rx_eob_isr);
1052
1053 /* EMAC RX done */
1054 while (1) { /* do all */
1055 i = hw_p->rx_slot;
1056
1057 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1058 || (loop_count >= NUM_RX_BUFF))
1059 break;
1060 loop_count++;
1061 hw_p->rx_slot++;
1062 if (NUM_RX_BUFF == hw_p->rx_slot)
1063 hw_p->rx_slot = 0;
1064 handled++;
1065 data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
1066 if (data_len) {
1067 if (data_len > ENET_MAX_MTU) /* Check len */
1068 data_len = 0;
1069 else {
1070 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
1071 data_len = 0;
1072 hw_p->stats.rx_err_log[hw_p->
1073 rx_err_index]
1074 = hw_p->rx[i].ctrl;
1075 hw_p->rx_err_index++;
1076 if (hw_p->rx_err_index ==
1077 MAX_ERR_LOG)
1078 hw_p->rx_err_index =
1079 0;
wdenkfc1cfcd2004-04-25 15:41:35 +00001080 } /* emac_erros */
wdenkba56f622004-02-06 23:19:44 +00001081 } /* data_len < max mtu */
wdenkfc1cfcd2004-04-25 15:41:35 +00001082 } /* if data_len */
wdenkba56f622004-02-06 23:19:44 +00001083 if (!data_len) { /* no data */
1084 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1085
1086 hw_p->stats.data_len_err++; /* Error at Rx */
1087 }
1088
1089 /* !data_len */
1090 /* AS.HARNOIS */
1091 /* Check if user has already eaten buffer */
1092 /* if not => ERROR */
1093 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1094 if (hw_p->is_receiving)
1095 printf ("ERROR : Receive buffers are full!\n");
1096 break;
1097 } else {
1098 hw_p->stats.rx_frames++;
1099 hw_p->stats.rx += data_len;
1100 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1101 data_ptr;
1102#ifdef INFO_440_ENET
1103 hw_p->stats.pkts_rx++;
1104#endif
1105 /* AS.HARNOIS
1106 * use ring buffer
1107 */
1108 hw_p->rx_ready[hw_p->rx_i_index] = i;
1109 hw_p->rx_i_index++;
1110 if (NUM_RX_BUFF == hw_p->rx_i_index)
1111 hw_p->rx_i_index = 0;
1112
1113 /* printf("X"); /|* test-only *|/ */
1114
1115 /* AS.HARNOIS
1116 * free receive buffer only when
1117 * buffer has been handled (eth_rx)
1118 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1119 */
1120 } /* if data_len */
1121 } /* while */
1122 } /* if EMACK_RXCHL */
1123}
1124
1125
1126static int ppc_440x_eth_rx (struct eth_device *dev)
1127{
1128 int length;
1129 int user_index;
1130 unsigned long msr;
1131 EMAC_440GX_HW_PST hw_p = dev->priv;
1132
1133 hw_p->is_receiving = 1; /* tell driver */
1134
1135 for (;;) {
1136 /* AS.HARNOIS
1137 * use ring buffer and
1138 * get index from rx buffer desciptor queue
1139 */
1140 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1141 if (user_index == -1) {
1142 length = -1;
1143 break; /* nothing received - leave for() loop */
1144 }
1145
1146 msr = mfmsr ();
1147 mtmsr (msr & ~(MSR_EE));
1148
1149 length = hw_p->rx[user_index].data_len;
1150
1151 /* Pass the packet up to the protocol layers. */
1152 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1153 /* NetReceive(NetRxPackets[i], length); */
1154 NetReceive (NetRxPackets[user_index], length - 4);
1155 /* Free Recv Buffer */
1156 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1157 /* Free rx buffer descriptor queue */
1158 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1159 hw_p->rx_u_index++;
1160 if (NUM_RX_BUFF == hw_p->rx_u_index)
1161 hw_p->rx_u_index = 0;
1162
1163#ifdef INFO_440_ENET
1164 hw_p->stats.pkts_handled++;
1165#endif
1166
1167 mtmsr (msr); /* Enable IRQ's */
1168 }
1169
1170 hw_p->is_receiving = 0; /* tell driver */
1171
1172 return length;
1173}
1174
1175int ppc_440x_eth_initialize (bd_t * bis)
1176{
1177 static int virgin = 0;
wdenkba56f622004-02-06 23:19:44 +00001178 struct eth_device *dev;
1179 int eth_num = 0;
wdenkba56f622004-02-06 23:19:44 +00001180 EMAC_440GX_HW_PST hw = NULL;
1181
Stefan Roesec157d8e2005-08-01 16:41:48 +02001182#if defined(CONFIG_440_GX)
1183 unsigned long pfc1;
1184
wdenkba56f622004-02-06 23:19:44 +00001185 mfsdr (sdr_pfc1, pfc1);
1186 pfc1 &= ~(0x01e00000);
1187 pfc1 |= 0x01200000;
1188 mtsdr (sdr_pfc1, pfc1);
Stefan Roesec157d8e2005-08-01 16:41:48 +02001189#endif
wdenk3c74e322004-02-22 23:46:08 +00001190 /* set phy num and mode */
1191 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
Stefan Roesec157d8e2005-08-01 16:41:48 +02001192#if defined(CONFIG_PHY1_ADDR)
wdenk3c74e322004-02-22 23:46:08 +00001193 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
Stefan Roesec157d8e2005-08-01 16:41:48 +02001194#endif
1195#if defined(CONFIG_440_GX)
wdenk3c74e322004-02-22 23:46:08 +00001196 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1197 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1198 bis->bi_phymode[0] = 0;
1199 bis->bi_phymode[1] = 0;
1200 bis->bi_phymode[2] = 2;
1201 bis->bi_phymode[3] = 2;
wdenkba56f622004-02-06 23:19:44 +00001202
wdenka06752e2004-09-29 22:43:59 +00001203#if defined (CONFIG_440_GX)
1204 ppc_440x_eth_setup_bridge(0, bis);
1205#endif
Stefan Roesec157d8e2005-08-01 16:41:48 +02001206#endif
wdenka06752e2004-09-29 22:43:59 +00001207
wdenkba56f622004-02-06 23:19:44 +00001208 for (eth_num = 0; eth_num < EMAC_NUM_DEV; eth_num++) {
1209
1210 /* See if we can actually bring up the interface, otherwise, skip it */
1211 switch (eth_num) {
wdenke2ffd592004-12-31 09:32:47 +00001212 default: /* fall through */
wdenkba56f622004-02-06 23:19:44 +00001213 case 0:
wdenk3c74e322004-02-22 23:46:08 +00001214 if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
1215 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenkba56f622004-02-06 23:19:44 +00001216 continue;
wdenk3c74e322004-02-22 23:46:08 +00001217 }
wdenkba56f622004-02-06 23:19:44 +00001218 break;
wdenke2ffd592004-12-31 09:32:47 +00001219#ifdef CONFIG_HAS_ETH1
wdenkba56f622004-02-06 23:19:44 +00001220 case 1:
wdenk3c74e322004-02-22 23:46:08 +00001221 if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
1222 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenkba56f622004-02-06 23:19:44 +00001223 continue;
wdenk3c74e322004-02-22 23:46:08 +00001224 }
wdenkba56f622004-02-06 23:19:44 +00001225 break;
wdenke2ffd592004-12-31 09:32:47 +00001226#endif
1227#ifdef CONFIG_HAS_ETH2
wdenkba56f622004-02-06 23:19:44 +00001228 case 2:
wdenk3c74e322004-02-22 23:46:08 +00001229 if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) {
1230 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenkba56f622004-02-06 23:19:44 +00001231 continue;
wdenk3c74e322004-02-22 23:46:08 +00001232 }
wdenkba56f622004-02-06 23:19:44 +00001233 break;
wdenke2ffd592004-12-31 09:32:47 +00001234#endif
1235#ifdef CONFIG_HAS_ETH3
wdenkba56f622004-02-06 23:19:44 +00001236 case 3:
wdenk3c74e322004-02-22 23:46:08 +00001237 if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) {
1238 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenkba56f622004-02-06 23:19:44 +00001239 continue;
wdenk3c74e322004-02-22 23:46:08 +00001240 }
wdenkba56f622004-02-06 23:19:44 +00001241 break;
wdenke2ffd592004-12-31 09:32:47 +00001242#endif
wdenkba56f622004-02-06 23:19:44 +00001243 }
1244
1245 /* Allocate device structure */
1246 dev = (struct eth_device *) malloc (sizeof (*dev));
1247 if (dev == NULL) {
wdenk3f85ce22004-02-23 16:11:30 +00001248 printf ("ppc_440x_eth_initialize: "
1249 "Cannot allocate eth_device %d\n", eth_num);
wdenkba56f622004-02-06 23:19:44 +00001250 return (-1);
1251 }
wdenkb2532ef2005-06-20 10:17:34 +00001252 memset(dev, 0, sizeof(*dev));
wdenkba56f622004-02-06 23:19:44 +00001253
1254 /* Allocate our private use data */
1255 hw = (EMAC_440GX_HW_PST) malloc (sizeof (*hw));
1256 if (hw == NULL) {
wdenk3f85ce22004-02-23 16:11:30 +00001257 printf ("ppc_440x_eth_initialize: "
1258 "Cannot allocate private hw data for eth_device %d",
wdenkba56f622004-02-06 23:19:44 +00001259 eth_num);
1260 free (dev);
1261 return (-1);
1262 }
wdenkb2532ef2005-06-20 10:17:34 +00001263 memset(hw, 0, sizeof(*hw));
wdenkba56f622004-02-06 23:19:44 +00001264
1265 switch (eth_num) {
wdenke2ffd592004-12-31 09:32:47 +00001266 default: /* fall through */
wdenkba56f622004-02-06 23:19:44 +00001267 case 0:
1268 hw->hw_addr = 0;
1269 memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
1270 break;
wdenke2ffd592004-12-31 09:32:47 +00001271#ifdef CONFIG_HAS_ETH1
wdenkba56f622004-02-06 23:19:44 +00001272 case 1:
1273 hw->hw_addr = 0x100;
1274 memcpy (dev->enetaddr, bis->bi_enet1addr, 6);
1275 break;
wdenke2ffd592004-12-31 09:32:47 +00001276#endif
1277#ifdef CONFIG_HAS_ETH2
wdenkba56f622004-02-06 23:19:44 +00001278 case 2:
1279 hw->hw_addr = 0x400;
1280 memcpy (dev->enetaddr, bis->bi_enet2addr, 6);
1281 break;
wdenke2ffd592004-12-31 09:32:47 +00001282#endif
1283#ifdef CONFIG_HAS_ETH3
wdenkba56f622004-02-06 23:19:44 +00001284 case 3:
1285 hw->hw_addr = 0x600;
1286 memcpy (dev->enetaddr, bis->bi_enet3addr, 6);
1287 break;
wdenke2ffd592004-12-31 09:32:47 +00001288#endif
wdenkba56f622004-02-06 23:19:44 +00001289 }
1290
1291 hw->devnum = eth_num;
Stefan Roesec157d8e2005-08-01 16:41:48 +02001292 hw->print_speed = 1;
wdenkba56f622004-02-06 23:19:44 +00001293
1294 sprintf (dev->name, "ppc_440x_eth%d", eth_num);
1295 dev->priv = (void *) hw;
1296 dev->init = ppc_440x_eth_init;
1297 dev->halt = ppc_440x_eth_halt;
1298 dev->send = ppc_440x_eth_send;
1299 dev->recv = ppc_440x_eth_rx;
1300
1301 if (0 == virgin) {
1302 /* set the MAL IER ??? names may change with new spec ??? */
1303 mal_ier =
1304 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
1305 MAL_IER_OPBE | MAL_IER_PLBE;
1306 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
1307 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
1308 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
1309 mtdcr (malier, mal_ier);
1310
1311 /* install MAL interrupt handler */
1312 irq_install_handler (VECNUM_MS,
1313 (interrupt_handler_t *) enetInt,
1314 dev);
1315 irq_install_handler (VECNUM_MTE,
1316 (interrupt_handler_t *) enetInt,
1317 dev);
1318 irq_install_handler (VECNUM_MRE,
1319 (interrupt_handler_t *) enetInt,
1320 dev);
1321 irq_install_handler (VECNUM_TXDE,
1322 (interrupt_handler_t *) enetInt,
1323 dev);
1324 irq_install_handler (VECNUM_RXDE,
1325 (interrupt_handler_t *) enetInt,
1326 dev);
1327 virgin = 1;
1328 }
1329
1330 eth_register (dev);
1331
1332 } /* end for each supported device */
1333 return (1);
1334}
1335#endif /* CONFIG_440 && CONFIG_NET_MULTI */