blob: ba7418a9717610cac5e2ce24e9e62b0fdd03e9ea [file] [log] [blame]
wdenk544e9732004-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
wdenk56ed43e2004-02-22 23:46:08 +0000119#define BI_PHYMODE_NONE 0
120#define BI_PHYMODE_ZMII 1
121#define BI_PHYMODE_RGMII 2
122
wdenk544e9732004-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
170 hw_p->print_speed = 1; /* print speed message again next time */
171
172 return;
173}
174
175extern int phy_setup_aneg (unsigned char addr);
176extern int miiphy_reset (unsigned char addr);
177
178static int ppc_440x_eth_init (struct eth_device *dev, bd_t * bis)
179{
180 int i;
181 unsigned long reg;
182 unsigned long msr;
183 unsigned long speed;
184 unsigned long duplex;
185 unsigned long failsafe;
186 unsigned mode_reg;
187 unsigned short devnum;
188 unsigned short reg_short;
189 sys_info_t sysinfo;
wdenk00fe1612004-03-14 00:07:33 +0000190#if defined (CONFIG_440_GX)
191 unsigned long pfc1;
192 unsigned long zmiifer;
193 unsigned long rmiifer;
194#endif
wdenk544e9732004-02-06 23:19:44 +0000195
196 EMAC_440GX_HW_PST hw_p = dev->priv;
197
198 /* before doing anything, figure out if we have a MAC address */
199 /* if not, bail */
200 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0)
201 return -1;
202
203 /* Need to get the OPB frequency so we can access the PHY */
204 get_sys_info (&sysinfo);
205
206
207 msr = mfmsr ();
208 mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
209
210 devnum = hw_p->devnum;
211
212#ifdef INFO_440_ENET
213 /* AS.HARNOIS
214 * We should have :
215 * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
216 * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
217 * is possible that new packets (without relationship with
218 * current transfer) have got the time to arrived before
219 * netloop calls eth_halt
220 */
221 printf ("About preceeding transfer (eth%d):\n"
222 "- Sent packet number %d\n"
223 "- Received packet number %d\n"
224 "- Handled packet number %d\n",
225 hw_p->devnum,
226 hw_p->stats.pkts_tx,
227 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
228
229 hw_p->stats.pkts_tx = 0;
230 hw_p->stats.pkts_rx = 0;
231 hw_p->stats.pkts_handled = 0;
232#endif
233
234 /* MAL Channel RESET */
235 /* 1st reset MAL channel */
236 /* Note: writing a 0 to a channel has no effect */
237 mtdcr (maltxcarr, (MAL_TXRX_CASR >> hw_p->devnum));
238 mtdcr (malrxcarr, (MAL_TXRX_CASR >> hw_p->devnum));
239
240 /* wait for reset */
241 /* TBS: should have udelay and failsafe here */
242 failsafe = 10000;
243 /* wait for reset */
244 while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
245 udelay (1000); /* Delay 1 MS so as not to hammer the register */
246 failsafe--;
247 if (failsafe == 0)
248 break;
249
250 }
251
252 hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
253 hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
254
255 hw_p->rx_slot = 0; /* MAL Receive Slot */
256 hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
257 hw_p->rx_u_index = 0; /* Receive User Queue Index */
258
259 hw_p->tx_slot = 0; /* MAL Transmit Slot */
260 hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
261 hw_p->tx_u_index = 0; /* Transmit User Queue Index */
262
263 /* set RMII mode */
264 /* NOTE: 440GX spec states that mode is mutually exclusive */
265 /* NOTE: Therefore, disable all other EMACS, since we handle */
266 /* NOTE: only one emac at a time */
267 reg = 0;
268 out32 (ZMII_FER, 0);
269 udelay (100);
wdenk544e9732004-02-06 23:19:44 +0000270
wdenk00fe1612004-03-14 00:07:33 +0000271#if defined(CONFIG_440_GX)
272 mfsdr(sdr_pfc1, pfc1);
273 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
wdenk544e9732004-02-06 23:19:44 +0000274
wdenk00fe1612004-03-14 00:07:33 +0000275 switch (pfc1) {
276 case 1:
277 zmiifer = (ZMII_FER_MDI | ZMII_FER_RMII) << ZMII_FER_V(devnum);
278 rmiifer = 0x0;
279 break;
280 case 2:
281 zmiifer = (ZMII_FER_MDI | ZMII_FER_SMII) << ZMII_FER_V(devnum);
282 rmiifer = 0x0;
283 break;
284 case 3:
285 if (devnum == 0) {
286 zmiifer = (ZMII_FER_MDI | ZMII_FER_RMII) << ZMII_FER_V(devnum);
287 rmiifer = 0x0;
288 } else if (devnum == 2) {
289 zmiifer = (ZMII_FER_MDI | ZMII_FER_RMII) << ZMII_FER_V(devnum);
290 rmiifer = RGMII_FER_RGMII << RGMII_FER_V(devnum);
291 } else { /* invalid case */
292 zmiifer = 0x0;
293 rmiifer = 0x0;
294 }
295 break;
296 case 4:
297 if ((devnum == 0) || (devnum == 1)) {
298 zmiifer = (ZMII_FER_MDI | ZMII_FER_SMII) << ZMII_FER_V (devnum);
299 rmiifer = 0x0;
300 } else { /* ((devnum == 2) || (devnum == 3)) */
301 zmiifer = (ZMII_FER_MDI/* | ZMII_FER_RMII */) << ZMII_FER_V (devnum);
302 rmiifer = RGMII_FER_RGMII << RGMII_FER_V (devnum);
303 }
304 break;
305 case 5:
306 if ((devnum == 0) || (devnum == 1) || (devnum == 2)) {
307 zmiifer = (ZMII_FER_MDI | ZMII_FER_SMII) << ZMII_FER_V (devnum);
308 rmiifer = 0x0;
309 } else {
310 zmiifer = (ZMII_FER_MDI | ZMII_FER_RMII) << ZMII_FER_V(devnum);
311 rmiifer = RGMII_FER_RGMII << RGMII_FER_V(devnum);
312 }
313 break;
314 case 6:
315 if ((devnum == 0) || (devnum == 1)) {
316 zmiifer = (ZMII_FER_MDI | ZMII_FER_SMII) << ZMII_FER_V (devnum);
317 rmiifer = 0x0;
318 } else {
319 zmiifer = (ZMII_FER_MDI | ZMII_FER_RMII) << ZMII_FER_V(devnum);
320 rmiifer = RGMII_FER_RGMII << RGMII_FER_V(devnum);
321 }
322 break;
323 case 0:
324 default:
325 zmiifer = (ZMII_FER_MDI | ZMII_FER_MII) << ZMII_FER_V(devnum);
326 rmiifer = 0x0;
327 break;
328 }
329
330 out32 (ZMII_FER, zmiifer);
331 out32 (RGMII_FER, rmiifer);
332#else
333 if ((devnum == 0) || (devnum == 1)) {
334 out32 (ZMII_FER, (ZMII_FER_SMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
335 }
336 else { /* ((devnum == 2) || (devnum == 3)) */
337 out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum));
wdenk544e9732004-02-06 23:19:44 +0000338 out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) |
339 (RGMII_FER_RGMII << RGMII_FER_V (3))));
wdenk00fe1612004-03-14 00:07:33 +0000340 }
341#endif
342 out32 (ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
343 __asm__ volatile ("eieio");
344
345 /* reset emac so we have access to the phy */
346
347 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
wdenk544e9732004-02-06 23:19:44 +0000348 __asm__ volatile ("eieio");
349
350 failsafe = 1000;
351 while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
352 udelay (1000);
353 failsafe--;
354 }
355
356 /* Whack the M1 register */
357 mode_reg = 0x0;
358 mode_reg &= ~0x00000038;
359 if (sysinfo.freqOPB <= 50000000);
360 else if (sysinfo.freqOPB <= 66666667)
361 mode_reg |= EMAC_M1_OBCI_66;
362 else if (sysinfo.freqOPB <= 83333333)
363 mode_reg |= EMAC_M1_OBCI_83;
364 else if (sysinfo.freqOPB <= 100000000)
365 mode_reg |= EMAC_M1_OBCI_100;
366 else
367 mode_reg |= EMAC_M1_OBCI_GT100;
368
369 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
370
371
372 /* wait for PHY to complete auto negotiation */
373 reg_short = 0;
374#ifndef CONFIG_CS8952_PHY
375 switch (devnum) {
376 case 0:
377 reg = CONFIG_PHY_ADDR;
378 break;
379 case 1:
380 reg = CONFIG_PHY1_ADDR;
381 break;
382#if defined (CONFIG_440_GX)
383 case 2:
384 reg = CONFIG_PHY2_ADDR;
385 break;
386 case 3:
387 reg = CONFIG_PHY3_ADDR;
388 break;
389#endif
390 default:
391 reg = CONFIG_PHY_ADDR;
392 break;
393 }
394
wdenk56ed43e2004-02-22 23:46:08 +0000395 bis->bi_phynum[devnum] = reg;
396
wdenk544e9732004-02-06 23:19:44 +0000397 /* Reset the phy */
398 miiphy_reset (reg);
399
wdenk00fe1612004-03-14 00:07:33 +0000400#if defined(CONFIG_CIS8201_PHY)
401 /*
402 * Cicada 8201 PHY needs to have an extended register whacked
403 * for RGMII mode.
404 */
405 if ( ((devnum == 2) || (devnum ==3)) && (4 == pfc1) ) {
406 miiphy_write (reg, 23, 0x1200);
407 }
408#endif
409
wdenk544e9732004-02-06 23:19:44 +0000410 /* Start/Restart autonegotiation */
wdenk544e9732004-02-06 23:19:44 +0000411 phy_setup_aneg (reg);
412 udelay (1000);
413
414 miiphy_read (reg, PHY_BMSR, &reg_short);
415
416 /*
wdenk00fe1612004-03-14 00:07:33 +0000417 * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
wdenk544e9732004-02-06 23:19:44 +0000418 */
419 if ((reg_short & PHY_BMSR_AUTN_ABLE)
420 && !(reg_short & PHY_BMSR_AUTN_COMP)) {
421 puts ("Waiting for PHY auto negotiation to complete");
422 i = 0;
423 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
424 /*
425 * Timeout reached ?
426 */
427 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
428 puts (" TIMEOUT !\n");
429 break;
430 }
431
432 if ((i++ % 1000) == 0) {
433 putc ('.');
434 }
435 udelay (1000); /* 1 ms */
436 miiphy_read (reg, PHY_BMSR, &reg_short);
437
438 }
439 puts (" done\n");
440 udelay (500000); /* another 500 ms (results in faster booting) */
441 }
442#endif
443 speed = miiphy_speed (reg);
444 duplex = miiphy_duplex (reg);
445
446 if (hw_p->print_speed) {
447 hw_p->print_speed = 0;
448 printf ("ENET Speed is %d Mbps - %s duplex connection\n",
449 (int) speed, (duplex == HALF) ? "HALF" : "FULL");
450 }
451
452 /* Set ZMII/RGMII speed according to the phy link speed */
453 reg = in32 (ZMII_SSR);
454 if (speed == 100)
455 out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
456 else
457 out32 (ZMII_SSR,
458 reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
459
460 if ((devnum == 2) || (devnum == 3)) {
461 if (speed == 1000)
462 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
463 else if (speed == 100)
464 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
465 else
466 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
467
468 out32 (RGMII_SSR, reg);
469 }
470
471 /* set the Mal configuration reg */
472 /* Errata 1.12: MAL_1 -- Disable MAL bursting */
473 if (get_pvr () == PVR_440GP_RB)
474 mtdcr (malmcr,
475 MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
476 else
477 mtdcr (malmcr,
478 MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
479 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
480
481 /* Free "old" buffers */
482 if (hw_p->alloc_tx_buf)
483 free (hw_p->alloc_tx_buf);
484 if (hw_p->alloc_rx_buf)
485 free (hw_p->alloc_rx_buf);
486
487 /*
488 * Malloc MAL buffer desciptors, make sure they are
489 * aligned on cache line boundary size
490 * (401/403/IOP480 = 16, 405 = 32)
491 * and doesn't cross cache block boundaries.
492 */
493 hw_p->alloc_tx_buf =
494 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
495 ((2 * CFG_CACHELINE_SIZE) - 2));
496 if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
497 hw_p->tx =
498 (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
499 CFG_CACHELINE_SIZE -
500 ((int) hw_p->
501 alloc_tx_buf & CACHELINE_MASK));
502 } else {
503 hw_p->tx = hw_p->alloc_tx_buf;
504 }
505
506 hw_p->alloc_rx_buf =
507 (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
508 ((2 * CFG_CACHELINE_SIZE) - 2));
509 if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
510 hw_p->rx =
511 (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
512 CFG_CACHELINE_SIZE -
513 ((int) hw_p->
514 alloc_rx_buf & CACHELINE_MASK));
515 } else {
516 hw_p->rx = hw_p->alloc_rx_buf;
517 }
518
519 for (i = 0; i < NUM_TX_BUFF; i++) {
520 hw_p->tx[i].ctrl = 0;
521 hw_p->tx[i].data_len = 0;
522 if (hw_p->first_init == 0)
523 hw_p->txbuf_ptr =
524 (char *) malloc (ENET_MAX_MTU_ALIGNED);
525 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
526 if ((NUM_TX_BUFF - 1) == i)
527 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
528 hw_p->tx_run[i] = -1;
529#if 0
530 printf ("TX_BUFF %d @ 0x%08lx\n", i,
531 (ulong) hw_p->tx[i].data_ptr);
532#endif
533 }
534
535 for (i = 0; i < NUM_RX_BUFF; i++) {
536 hw_p->rx[i].ctrl = 0;
537 hw_p->rx[i].data_len = 0;
538 /* rx[i].data_ptr = (char *) &rx_buff[i]; */
539 hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
540 if ((NUM_RX_BUFF - 1) == i)
541 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
542 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
543 hw_p->rx_ready[i] = -1;
544#if 0
545 printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr);
546#endif
547 }
548
549 reg = 0x00000000;
550
551 reg |= dev->enetaddr[0]; /* set high address */
552 reg = reg << 8;
553 reg |= dev->enetaddr[1];
554
555 out32 (EMAC_IAH + hw_p->hw_addr, reg);
556
557 reg = 0x00000000;
558 reg |= dev->enetaddr[2]; /* set low address */
559 reg = reg << 8;
560 reg |= dev->enetaddr[3];
561 reg = reg << 8;
562 reg |= dev->enetaddr[4];
563 reg = reg << 8;
564 reg |= dev->enetaddr[5];
565
566 out32 (EMAC_IAL + hw_p->hw_addr, reg);
567
568 switch (devnum) {
569 case 1:
570 /* setup MAL tx & rx channel pointers */
571 mtdcr (maltxbattr, 0x0);
572 mtdcr (maltxctp1r, hw_p->tx);
573 mtdcr (malrxbattr, 0x0);
574 mtdcr (malrxctp1r, hw_p->rx);
575 /* set RX buffer size */
576 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
577 break;
578#if defined (CONFIG_440_GX)
579 case 2:
580 /* setup MAL tx & rx channel pointers */
581 mtdcr (maltxbattr, 0x0);
582 mtdcr (maltxctp2r, hw_p->tx);
583 mtdcr (malrxbattr, 0x0);
584 mtdcr (malrxctp2r, hw_p->rx);
585 /* set RX buffer size */
586 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
587 break;
588 case 3:
589 /* setup MAL tx & rx channel pointers */
590 mtdcr (maltxbattr, 0x0);
591 mtdcr (maltxctp3r, hw_p->tx);
592 mtdcr (malrxbattr, 0x0);
593 mtdcr (malrxctp3r, hw_p->rx);
594 /* set RX buffer size */
595 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
596 break;
597#endif /*CONFIG_440_GX */
598 case 0:
599 default:
600 /* setup MAL tx & rx channel pointers */
601 mtdcr (maltxbattr, 0x0);
602 mtdcr (maltxctp0r, hw_p->tx);
603 mtdcr (malrxbattr, 0x0);
604 mtdcr (malrxctp0r, hw_p->rx);
605 /* set RX buffer size */
606 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
607 break;
608 }
609
610 /* Enable MAL transmit and receive channels */
611 mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
612 mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
613
614 /* set transmit enable & receive enable */
615 out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
616
617 /* set receive fifo to 4k and tx fifo to 2k */
618 mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
619 mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
620
621 /* set speed */
622 /* TBS: do 1GbE */
623 if (speed == _100BASET)
624 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
625 else
626 mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
627 if (duplex == FULL)
628 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
629
630 out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
631
632 /* Enable broadcast and indvidual address */
633 /* TBS: enabling runts as some misbehaved nics will send runts */
634 out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
635
636 /* we probably need to set the tx mode1 reg? maybe at tx time */
637
638 /* set transmit request threshold register */
639 out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
640
641 /* set receive low/high water mark register */
642 /* 440GP has a 64 byte burst length */
643 out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
644 out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
645
646 /* Set fifo limit entry in tx mode 0 */
647 out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
648 /* Frame gap set */
649 out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
650
651 /* Set EMAC IER */
652 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS |
653 EMAC_ISR_PTLE | EMAC_ISR_ORE | EMAC_ISR_IRE;
654 if (speed == _100BASET)
655 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
656
657 out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
658 out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
659
660 if (hw_p->first_init == 0) {
661 /*
662 * Connect interrupt service routines
663 */
664 irq_install_handler (VECNUM_EWU0 + (hw_p->devnum * 2),
665 (interrupt_handler_t *) enetInt, dev);
666 irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2),
667 (interrupt_handler_t *) enetInt, dev);
668 }
wdenk544e9732004-02-06 23:19:44 +0000669
670 mtmsr (msr); /* enable interrupts again */
671
672 hw_p->bis = bis;
673 hw_p->first_init = 1;
674
675 return (1);
676}
677
678
679static int ppc_440x_eth_send (struct eth_device *dev, volatile void *ptr,
680 int len)
681{
682 struct enet_frame *ef_ptr;
683 ulong time_start, time_now;
684 unsigned long temp_txm0;
685 EMAC_440GX_HW_PST hw_p = dev->priv;
686
687 ef_ptr = (struct enet_frame *) ptr;
688
689 /*-----------------------------------------------------------------------+
690 * Copy in our address into the frame.
691 *-----------------------------------------------------------------------*/
692 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
693
694 /*-----------------------------------------------------------------------+
695 * If frame is too long or too short, modify length.
696 *-----------------------------------------------------------------------*/
697 /* TBS: where does the fragment go???? */
698 if (len > ENET_MAX_MTU)
699 len = ENET_MAX_MTU;
700
701 /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
702 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
703
704 /*-----------------------------------------------------------------------+
705 * set TX Buffer busy, and send it
706 *-----------------------------------------------------------------------*/
707 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
708 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
709 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
710 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
711 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
712
713 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
714 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
715
716 __asm__ volatile ("eieio");
717
718 out32 (EMAC_TXM0 + hw_p->hw_addr,
719 in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
720#ifdef INFO_440_ENET
721 hw_p->stats.pkts_tx++;
722#endif
723
724 /*-----------------------------------------------------------------------+
725 * poll unitl the packet is sent and then make sure it is OK
726 *-----------------------------------------------------------------------*/
727 time_start = get_timer (0);
728 while (1) {
729 temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
730 /* loop until either TINT turns on or 3 seconds elapse */
731 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
732 /* transmit is done, so now check for errors
733 * If there is an error, an interrupt should
734 * happen when we return
735 */
736 time_now = get_timer (0);
737 if ((time_now - time_start) > 3000) {
738 return (-1);
739 }
740 } else {
741 return (len);
742 }
743 }
744}
745
746
747int enetInt (struct eth_device *dev)
748{
749 int serviced;
750 int rc = -1; /* default to not us */
751 unsigned long mal_isr;
752 unsigned long emac_isr = 0;
753 unsigned long mal_rx_eob;
754 unsigned long my_uic0msr, my_uic1msr;
755
756#if defined(CONFIG_440_GX)
757 unsigned long my_uic2msr;
758#endif
759 EMAC_440GX_HW_PST hw_p;
760
761 /*
762 * Because the mal is generic, we need to get the current
763 * eth device
764 */
765 dev = eth_get_dev ();
766
767 hw_p = dev->priv;
768
769
770 /* enter loop that stays in interrupt code until nothing to service */
771 do {
772 serviced = 0;
773
774 my_uic0msr = mfdcr (uic0msr);
775 my_uic1msr = mfdcr (uic1msr);
776#if defined(CONFIG_440_GX)
777 my_uic2msr = mfdcr (uic2msr);
778#endif
779 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
780 && !(my_uic1msr &
781 (UIC_ETH0 | UIC_ETH1 | UIC_MS | UIC_MTDE |
782 UIC_MRDE))) {
783 /* not for us */
784 return (rc);
785 }
786#if defined (CONFIG_440_GX)
787 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
788 && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
789 /* not for us */
790 return (rc);
791 }
792#endif
793 /* get and clear controller status interrupts */
794 /* look at Mal and EMAC interrupts */
795 if ((my_uic0msr & (UIC_MRE | UIC_MTE))
796 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
797 /* we have a MAL interrupt */
798 mal_isr = mfdcr (malesr);
799 /* look for mal error */
800 if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
801 mal_err (dev, mal_isr, my_uic0msr,
802 MAL_UIC_DEF, MAL_UIC_ERR);
803 serviced = 1;
804 rc = 0;
805 }
806 }
807
808 /* port by port dispatch of emac interrupts */
809 if (hw_p->devnum == 0) {
810 if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */
811 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
812 if ((hw_p->emac_ier & emac_isr) != 0) {
813 emac_err (dev, emac_isr);
814 serviced = 1;
815 rc = 0;
816 }
817 }
818 if ((hw_p->emac_ier & emac_isr)
819 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
820 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
821 mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
822 return (rc); /* we had errors so get out */
823 }
824 }
825
826 if (hw_p->devnum == 1) {
827 if (UIC_ETH1 & my_uic1msr) { /* look for EMAC errors */
828 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
829 if ((hw_p->emac_ier & emac_isr) != 0) {
830 emac_err (dev, emac_isr);
831 serviced = 1;
832 rc = 0;
833 }
834 }
835 if ((hw_p->emac_ier & emac_isr)
836 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
837 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
838 mtdcr (uic1sr, UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
839 return (rc); /* we had errors so get out */
840 }
841 }
842#if defined (CONFIG_440_GX)
843 if (hw_p->devnum == 2) {
844 if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
845 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
846 if ((hw_p->emac_ier & emac_isr) != 0) {
847 emac_err (dev, emac_isr);
848 serviced = 1;
849 rc = 0;
850 }
851 }
852 if ((hw_p->emac_ier & emac_isr)
853 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
854 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
855 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
856 mtdcr (uic2sr, UIC_ETH2);
857 return (rc); /* we had errors so get out */
858 }
859 }
860
861 if (hw_p->devnum == 3) {
862 if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
863 emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
864 if ((hw_p->emac_ier & emac_isr) != 0) {
865 emac_err (dev, emac_isr);
866 serviced = 1;
867 rc = 0;
868 }
869 }
870 if ((hw_p->emac_ier & emac_isr)
871 || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
872 mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
873 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
874 mtdcr (uic2sr, UIC_ETH3);
875 return (rc); /* we had errors so get out */
876 }
877 }
878#endif /* CONFIG_440_GX */
879 /* handle MAX TX EOB interrupt from a tx */
880 if (my_uic0msr & UIC_MTE) {
881 mal_rx_eob = mfdcr (maltxeobisr);
882 mtdcr (maltxeobisr, mal_rx_eob);
883 mtdcr (uic0sr, UIC_MTE);
884 }
885 /* handle MAL RX EOB interupt from a receive */
886 /* check for EOB on valid channels */
887 if (my_uic0msr & UIC_MRE) {
888 mal_rx_eob = mfdcr (malrxeobisr);
889 if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
890 /* clear EOB
891 mtdcr(malrxeobisr, mal_rx_eob); */
892 enet_rcv (dev, emac_isr);
893 /* indicate that we serviced an interrupt */
894 serviced = 1;
895 rc = 0;
896 }
897 }
898 mtdcr (uic0sr, UIC_MRE); /* Clear */
899 mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
900 switch (hw_p->devnum) {
901 case 0:
902 mtdcr (uic1sr, UIC_ETH0);
903 break;
904 case 1:
905 mtdcr (uic1sr, UIC_ETH1);
906 break;
907#if defined (CONFIG_440_GX)
908 case 2:
909 mtdcr (uic2sr, UIC_ETH2);
910 break;
911 case 3:
912 mtdcr (uic2sr, UIC_ETH3);
913 break;
914#endif /* CONFIG_440_GX */
915 default:
916 break;
917 }
918 } while (serviced);
919
920 return (rc);
921}
922
923/*-----------------------------------------------------------------------------+
924 * MAL Error Routine
925 *-----------------------------------------------------------------------------*/
926static void mal_err (struct eth_device *dev, unsigned long isr,
927 unsigned long uic, unsigned long maldef,
928 unsigned long mal_errr)
929{
930 EMAC_440GX_HW_PST hw_p = dev->priv;
931
932 mtdcr (malesr, isr); /* clear interrupt */
933
934 /* clear DE interrupt */
935 mtdcr (maltxdeir, 0xC0000000);
936 mtdcr (malrxdeir, 0x80000000);
937
938#ifdef INFO_440_ENET
939 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
940#endif
941
942 eth_init (hw_p->bis); /* start again... */
943}
944
945/*-----------------------------------------------------------------------------+
946 * EMAC Error Routine
947 *-----------------------------------------------------------------------------*/
948static void emac_err (struct eth_device *dev, unsigned long isr)
949{
950 EMAC_440GX_HW_PST hw_p = dev->priv;
951
952 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
953 out32 (EMAC_ISR + hw_p->hw_addr, isr);
954}
955
956/*-----------------------------------------------------------------------------+
957 * enet_rcv() handles the ethernet receive data
958 *-----------------------------------------------------------------------------*/
959static void enet_rcv (struct eth_device *dev, unsigned long malisr)
960{
961 struct enet_frame *ef_ptr;
962 unsigned long data_len;
963 unsigned long rx_eob_isr;
964 EMAC_440GX_HW_PST hw_p = dev->priv;
965
966 int handled = 0;
967 int i;
968 int loop_count = 0;
969
970 rx_eob_isr = mfdcr (malrxeobisr);
971 if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
972 /* clear EOB */
973 mtdcr (malrxeobisr, rx_eob_isr);
974
975 /* EMAC RX done */
976 while (1) { /* do all */
977 i = hw_p->rx_slot;
978
979 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
980 || (loop_count >= NUM_RX_BUFF))
981 break;
982 loop_count++;
983 hw_p->rx_slot++;
984 if (NUM_RX_BUFF == hw_p->rx_slot)
985 hw_p->rx_slot = 0;
986 handled++;
987 data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
988 if (data_len) {
989 if (data_len > ENET_MAX_MTU) /* Check len */
990 data_len = 0;
991 else {
992 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
993 data_len = 0;
994 hw_p->stats.rx_err_log[hw_p->
995 rx_err_index]
996 = hw_p->rx[i].ctrl;
997 hw_p->rx_err_index++;
998 if (hw_p->rx_err_index ==
999 MAX_ERR_LOG)
1000 hw_p->rx_err_index =
1001 0;
1002 } /* emac_erros */
1003 } /* data_len < max mtu */
1004 } /* if data_len */
1005 if (!data_len) { /* no data */
1006 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
1007
1008 hw_p->stats.data_len_err++; /* Error at Rx */
1009 }
1010
1011 /* !data_len */
1012 /* AS.HARNOIS */
1013 /* Check if user has already eaten buffer */
1014 /* if not => ERROR */
1015 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1016 if (hw_p->is_receiving)
1017 printf ("ERROR : Receive buffers are full!\n");
1018 break;
1019 } else {
1020 hw_p->stats.rx_frames++;
1021 hw_p->stats.rx += data_len;
1022 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1023 data_ptr;
1024#ifdef INFO_440_ENET
1025 hw_p->stats.pkts_rx++;
1026#endif
1027 /* AS.HARNOIS
1028 * use ring buffer
1029 */
1030 hw_p->rx_ready[hw_p->rx_i_index] = i;
1031 hw_p->rx_i_index++;
1032 if (NUM_RX_BUFF == hw_p->rx_i_index)
1033 hw_p->rx_i_index = 0;
1034
1035 /* printf("X"); /|* test-only *|/ */
1036
1037 /* AS.HARNOIS
1038 * free receive buffer only when
1039 * buffer has been handled (eth_rx)
1040 rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1041 */
1042 } /* if data_len */
1043 } /* while */
1044 } /* if EMACK_RXCHL */
1045}
1046
1047
1048static int ppc_440x_eth_rx (struct eth_device *dev)
1049{
1050 int length;
1051 int user_index;
1052 unsigned long msr;
1053 EMAC_440GX_HW_PST hw_p = dev->priv;
1054
1055 hw_p->is_receiving = 1; /* tell driver */
1056
1057 for (;;) {
1058 /* AS.HARNOIS
1059 * use ring buffer and
1060 * get index from rx buffer desciptor queue
1061 */
1062 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1063 if (user_index == -1) {
1064 length = -1;
1065 break; /* nothing received - leave for() loop */
1066 }
1067
1068 msr = mfmsr ();
1069 mtmsr (msr & ~(MSR_EE));
1070
1071 length = hw_p->rx[user_index].data_len;
1072
1073 /* Pass the packet up to the protocol layers. */
1074 /* NetReceive(NetRxPackets[rxIdx], length - 4); */
1075 /* NetReceive(NetRxPackets[i], length); */
1076 NetReceive (NetRxPackets[user_index], length - 4);
1077 /* Free Recv Buffer */
1078 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1079 /* Free rx buffer descriptor queue */
1080 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1081 hw_p->rx_u_index++;
1082 if (NUM_RX_BUFF == hw_p->rx_u_index)
1083 hw_p->rx_u_index = 0;
1084
1085#ifdef INFO_440_ENET
1086 hw_p->stats.pkts_handled++;
1087#endif
1088
1089 mtmsr (msr); /* Enable IRQ's */
1090 }
1091
1092 hw_p->is_receiving = 0; /* tell driver */
1093
1094 return length;
1095}
1096
1097int ppc_440x_eth_initialize (bd_t * bis)
1098{
1099 static int virgin = 0;
1100 unsigned long pfc1;
1101 struct eth_device *dev;
1102 int eth_num = 0;
1103
1104 EMAC_440GX_HW_PST hw = NULL;
1105
1106 mfsdr (sdr_pfc1, pfc1);
1107 pfc1 &= ~(0x01e00000);
1108 pfc1 |= 0x01200000;
1109 mtsdr (sdr_pfc1, pfc1);
wdenk56ed43e2004-02-22 23:46:08 +00001110 /* set phy num and mode */
1111 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
1112 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
1113 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1114 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1115 bis->bi_phymode[0] = 0;
1116 bis->bi_phymode[1] = 0;
1117 bis->bi_phymode[2] = 2;
1118 bis->bi_phymode[3] = 2;
wdenk544e9732004-02-06 23:19:44 +00001119
1120 for (eth_num = 0; eth_num < EMAC_NUM_DEV; eth_num++) {
1121
1122 /* See if we can actually bring up the interface, otherwise, skip it */
1123 switch (eth_num) {
1124 case 0:
wdenk56ed43e2004-02-22 23:46:08 +00001125 if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
1126 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenk544e9732004-02-06 23:19:44 +00001127 continue;
wdenk56ed43e2004-02-22 23:46:08 +00001128 }
wdenk544e9732004-02-06 23:19:44 +00001129 break;
1130 case 1:
wdenk56ed43e2004-02-22 23:46:08 +00001131 if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
1132 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenk544e9732004-02-06 23:19:44 +00001133 continue;
wdenk56ed43e2004-02-22 23:46:08 +00001134 }
wdenk544e9732004-02-06 23:19:44 +00001135 break;
1136 case 2:
wdenk56ed43e2004-02-22 23:46:08 +00001137 if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) {
1138 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenk544e9732004-02-06 23:19:44 +00001139 continue;
wdenk56ed43e2004-02-22 23:46:08 +00001140 }
wdenk544e9732004-02-06 23:19:44 +00001141 break;
1142 case 3:
wdenk56ed43e2004-02-22 23:46:08 +00001143 if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) {
1144 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenk544e9732004-02-06 23:19:44 +00001145 continue;
wdenk56ed43e2004-02-22 23:46:08 +00001146 }
wdenk544e9732004-02-06 23:19:44 +00001147 break;
1148 default:
wdenk56ed43e2004-02-22 23:46:08 +00001149 if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
1150 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
wdenk544e9732004-02-06 23:19:44 +00001151 continue;
wdenk56ed43e2004-02-22 23:46:08 +00001152 }
wdenk544e9732004-02-06 23:19:44 +00001153 break;
1154 }
1155
1156 /* Allocate device structure */
1157 dev = (struct eth_device *) malloc (sizeof (*dev));
1158 if (dev == NULL) {
wdenkef893942004-02-23 16:11:30 +00001159 printf ("ppc_440x_eth_initialize: "
1160 "Cannot allocate eth_device %d\n", eth_num);
wdenk544e9732004-02-06 23:19:44 +00001161 return (-1);
1162 }
1163
1164 /* Allocate our private use data */
1165 hw = (EMAC_440GX_HW_PST) malloc (sizeof (*hw));
1166 if (hw == NULL) {
wdenkef893942004-02-23 16:11:30 +00001167 printf ("ppc_440x_eth_initialize: "
1168 "Cannot allocate private hw data for eth_device %d",
wdenk544e9732004-02-06 23:19:44 +00001169 eth_num);
1170 free (dev);
1171 return (-1);
1172 }
1173
1174 switch (eth_num) {
1175 case 0:
1176 hw->hw_addr = 0;
1177 memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
1178 break;
1179 case 1:
1180 hw->hw_addr = 0x100;
1181 memcpy (dev->enetaddr, bis->bi_enet1addr, 6);
1182 break;
1183 case 2:
1184 hw->hw_addr = 0x400;
1185 memcpy (dev->enetaddr, bis->bi_enet2addr, 6);
1186 break;
1187 case 3:
1188 hw->hw_addr = 0x600;
1189 memcpy (dev->enetaddr, bis->bi_enet3addr, 6);
1190 break;
1191 default:
1192 hw->hw_addr = 0;
1193 memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
1194 break;
1195 }
1196
1197 hw->devnum = eth_num;
1198
1199 sprintf (dev->name, "ppc_440x_eth%d", eth_num);
1200 dev->priv = (void *) hw;
1201 dev->init = ppc_440x_eth_init;
1202 dev->halt = ppc_440x_eth_halt;
1203 dev->send = ppc_440x_eth_send;
1204 dev->recv = ppc_440x_eth_rx;
1205
1206 if (0 == virgin) {
1207 /* set the MAL IER ??? names may change with new spec ??? */
1208 mal_ier =
1209 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
1210 MAL_IER_OPBE | MAL_IER_PLBE;
1211 mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
1212 mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
1213 mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
1214 mtdcr (malier, mal_ier);
1215
1216 /* install MAL interrupt handler */
1217 irq_install_handler (VECNUM_MS,
1218 (interrupt_handler_t *) enetInt,
1219 dev);
1220 irq_install_handler (VECNUM_MTE,
1221 (interrupt_handler_t *) enetInt,
1222 dev);
1223 irq_install_handler (VECNUM_MRE,
1224 (interrupt_handler_t *) enetInt,
1225 dev);
1226 irq_install_handler (VECNUM_TXDE,
1227 (interrupt_handler_t *) enetInt,
1228 dev);
1229 irq_install_handler (VECNUM_RXDE,
1230 (interrupt_handler_t *) enetInt,
1231 dev);
1232 virgin = 1;
1233 }
1234
1235 eth_register (dev);
1236
1237 } /* end for each supported device */
1238 return (1);
1239}
1240#endif /* CONFIG_440 && CONFIG_NET_MULTI */