1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82#include <config.h>
83#include <common.h>
84#include <net.h>
85#include <asm/processor.h>
86#include <asm/io.h>
87#include <asm/cache.h>
88#include <asm/mmu.h>
89#include <commproc.h>
90#include <asm/ppc4xx.h>
91#include <asm/ppc4xx-emac.h>
92#include <asm/ppc4xx-mal.h>
93#include <miiphy.h>
94#include <malloc.h>
95#include <linux/compiler.h>
96
97#if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
98#error "CONFIG_MII has to be defined!"
99#endif
100
101#define EMAC_RESET_TIMEOUT 1000
102#define PHY_AUTONEGOTIATE_TIMEOUT 5000
103
104
105
106
107
108
109#define ENET_MAX_MTU PKTSIZE
110#define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
111
112
113
114
115
116#define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * VECNUM_ETH1_OFFS))
117
118#if defined(CONFIG_HAS_ETH3)
119#if !defined(CONFIG_440GX)
120#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
121 UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
122#else
123
124#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
125#define UIC_ETHxB (UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
126#endif
127#elif defined(CONFIG_HAS_ETH2)
128#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
129 UIC_MASK(ETH_IRQ_NUM(2)))
130#elif defined(CONFIG_HAS_ETH1)
131#define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
132#else
133#define UIC_ETHx UIC_MASK(ETH_IRQ_NUM(0))
134#endif
135
136
137
138
139
140#if !defined(UIC_ETHxB)
141#define UIC_ETHxB 0
142#endif
143
144#define UIC_MAL_SERR UIC_MASK(VECNUM_MAL_SERR)
145#define UIC_MAL_TXDE UIC_MASK(VECNUM_MAL_TXDE)
146#define UIC_MAL_RXDE UIC_MASK(VECNUM_MAL_RXDE)
147#define UIC_MAL_TXEOB UIC_MASK(VECNUM_MAL_TXEOB)
148#define UIC_MAL_RXEOB UIC_MASK(VECNUM_MAL_RXEOB)
149
150#define MAL_UIC_ERR (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
151#define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
152
153
154
155
156
157
158
159
160
161
162
163
164#if defined(CONFIG_440GX)
165#define UIC_BASE_MAL UIC1_DCR_BASE
166#define UIC_BASE_MAL_ERR UIC2_DCR_BASE
167#define UIC_BASE_EMAC UIC2_DCR_BASE
168#define UIC_BASE_EMAC_B UIC3_DCR_BASE
169#else
170#define UIC_BASE_MAL (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_TXEOB) * 0x10))
171#define UIC_BASE_MAL_ERR (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_SERR) * 0x10))
172#define UIC_BASE_EMAC (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
173#define UIC_BASE_EMAC_B (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
174#endif
175
176#undef INFO_4XX_ENET
177
178#define BI_PHYMODE_NONE 0
179#define BI_PHYMODE_ZMII 1
180#define BI_PHYMODE_RGMII 2
181#define BI_PHYMODE_GMII 3
182#define BI_PHYMODE_RTBI 4
183#define BI_PHYMODE_TBI 5
184#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
185 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
186 defined(CONFIG_405EX)
187#define BI_PHYMODE_SMII 6
188#define BI_PHYMODE_MII 7
189#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
190#define BI_PHYMODE_RMII 8
191#endif
192#endif
193#define BI_PHYMODE_SGMII 9
194
195#if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
196 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
197 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
198 defined(CONFIG_405EX)
199#define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
200#endif
201
202#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
203#define SDR0_ETH_CFG_CLK_SEL_V(n) (0x01 << (8 + n))
204#endif
205
206#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
207#define MAL_RX_CHAN_MUL 8
208#else
209#define MAL_RX_CHAN_MUL 1
210#endif
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240#ifndef CONFIG_FIXED_PHY
241#define CONFIG_FIXED_PHY 0xFFFFFFFF
242#endif
243
244#ifndef CONFIG_SYS_FIXED_PHY_PORTS
245#define CONFIG_SYS_FIXED_PHY_PORTS
246#endif
247
248struct fixed_phy_port {
249 unsigned int devnum;
250 unsigned int speed;
251 unsigned int duplex;
252};
253
254static const struct fixed_phy_port fixed_phy_port[] = {
255 CONFIG_SYS_FIXED_PHY_PORTS
256};
257
258
259
260
261
262
263
264
265
266
267
268
269
270#if defined(CONFIG_BOARD_EMAC_COUNT)
271#define LAST_EMAC_NUM board_emac_count()
272#else
273#if defined(CONFIG_HAS_ETH3)
274#define LAST_EMAC_NUM 4
275#elif defined(CONFIG_HAS_ETH2)
276#define LAST_EMAC_NUM 3
277#elif defined(CONFIG_HAS_ETH1)
278#define LAST_EMAC_NUM 2
279#else
280#define LAST_EMAC_NUM 1
281#endif
282#endif
283
284
285#if !defined(CONFIG_EMAC_NR_START)
286#define CONFIG_EMAC_NR_START 0
287#endif
288
289#define MAL_RX_DESC_SIZE 2048
290#define MAL_TX_DESC_SIZE 2048
291#define MAL_ALLOC_SIZE (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE)
292
293
294
295
296static void enet_rcv (struct eth_device *dev, unsigned long malisr);
297
298int enetInt (struct eth_device *dev);
299static void mal_err (struct eth_device *dev, unsigned long isr,
300 unsigned long uic, unsigned long maldef,
301 unsigned long mal_errr);
302static void emac_err (struct eth_device *dev, unsigned long isr);
303
304extern int phy_setup_aneg (char *devname, unsigned char addr);
305extern int emac4xx_miiphy_read (const char *devname, unsigned char addr,
306 unsigned char reg, unsigned short *value);
307extern int emac4xx_miiphy_write (const char *devname, unsigned char addr,
308 unsigned char reg, unsigned short value);
309
310int board_emac_count(void);
311
312static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p)
313{
314#if defined(CONFIG_440SPE) || \
315 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
316 defined(CONFIG_405EX)
317 u32 val;
318
319 mfsdr(SDR0_MFR, val);
320 val |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
321 mtsdr(SDR0_MFR, val);
322#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
323 u32 val;
324
325 mfsdr(SDR0_ETH_CFG, val);
326 val |= SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
327 mtsdr(SDR0_ETH_CFG, val);
328#endif
329}
330
331static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p)
332{
333#if defined(CONFIG_440SPE) || \
334 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
335 defined(CONFIG_405EX)
336 u32 val;
337
338 mfsdr(SDR0_MFR, val);
339 val &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
340 mtsdr(SDR0_MFR, val);
341#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
342 u32 val;
343
344 mfsdr(SDR0_ETH_CFG, val);
345 val &= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
346 mtsdr(SDR0_ETH_CFG, val);
347#endif
348}
349
350
351
352
353
354static void ppc_4xx_eth_halt (struct eth_device *dev)
355{
356 EMAC_4XX_HW_PST hw_p = dev->priv;
357 u32 val = 10000;
358
359 out_be32((void *)EMAC0_IER + hw_p->hw_addr, 0x00000000);
360
361
362
363#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
364 mtdcr (MAL0_TXCARR, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
365#else
366 mtdcr (MAL0_TXCARR, (MAL_CR_MMSR >> hw_p->devnum));
367#endif
368 mtdcr (MAL0_RXCARR, (MAL_CR_MMSR >> hw_p->devnum));
369
370
371 while (mfdcr (MAL0_RXCASR) & (MAL_CR_MMSR >> hw_p->devnum)) {
372 udelay (1000);
373 val--;
374 if (val == 0)
375 break;
376 }
377
378
379 emac_loopback_enable(hw_p);
380
381
382 out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_SRST);
383
384
385 emac_loopback_disable(hw_p);
386
387#ifndef CONFIG_NETCONSOLE
388 hw_p->print_speed = 1;
389#endif
390
391#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
392
393 mfsdr(SDR0_ETH_CFG, val);
394 val &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
395 mtsdr(SDR0_ETH_CFG, val);
396#endif
397
398 return;
399}
400
401#if defined (CONFIG_440GX)
402int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
403{
404 unsigned long pfc1;
405 unsigned long zmiifer;
406 unsigned long rmiifer;
407
408 mfsdr(SDR0_PFC1, pfc1);
409 pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
410
411 zmiifer = 0;
412 rmiifer = 0;
413
414 switch (pfc1) {
415 case 1:
416 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
417 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
418 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
419 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
420 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
421 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
422 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
423 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
424 break;
425 case 2:
426 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
427 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
428 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
429 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
430 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
431 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
432 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
433 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
434 break;
435 case 3:
436 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
437 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
438 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
439 bis->bi_phymode[1] = BI_PHYMODE_NONE;
440 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
441 bis->bi_phymode[3] = BI_PHYMODE_NONE;
442 break;
443 case 4:
444 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
445 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
446 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
447 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
448 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
449 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
450 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
451 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
452 break;
453 case 5:
454 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
455 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
456 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
457 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
458 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
459 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
460 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
461 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
462 break;
463 case 6:
464 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
465 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
466 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
467 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
468 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
469 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
470 break;
471 case 0:
472 default:
473 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
474 rmiifer = 0x0;
475 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
476 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
477 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
478 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
479 break;
480 }
481
482
483 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
484
485 out_be32((void *)ZMII0_FER, zmiifer);
486 out_be32((void *)RGMII_FER, rmiifer);
487
488 return ((int)pfc1);
489}
490#endif
491
492#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
493int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
494{
495 unsigned long zmiifer=0x0;
496 unsigned long pfc1;
497
498 mfsdr(SDR0_PFC1, pfc1);
499 pfc1 &= SDR0_PFC1_SELECT_MASK;
500
501 switch (pfc1) {
502 case SDR0_PFC1_SELECT_CONFIG_2:
503
504 out_be32((void *)ZMII0_FER, 0x00);
505 out_be32((void *)RGMII_FER, 0x00000037);
506 bis->bi_phymode[0] = BI_PHYMODE_GMII;
507 bis->bi_phymode[1] = BI_PHYMODE_NONE;
508 break;
509 case SDR0_PFC1_SELECT_CONFIG_4:
510
511 out_be32((void *)ZMII0_FER, 0x00);
512 out_be32((void *)RGMII_FER, 0x00000055);
513 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
514 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
515 break;
516 case SDR0_PFC1_SELECT_CONFIG_6:
517
518 out_be32((void *)ZMII0_FER,
519 ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
520 ((ZMII_FER_SMII) << ZMII_FER_V(1)));
521 out_be32((void *)RGMII_FER, 0x00000000);
522 bis->bi_phymode[0] = BI_PHYMODE_SMII;
523 bis->bi_phymode[1] = BI_PHYMODE_SMII;
524 break;
525 case SDR0_PFC1_SELECT_CONFIG_1_2:
526
527 out_be32((void *)ZMII0_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
528 out_be32((void *)RGMII_FER, 0x00000000);
529 bis->bi_phymode[0] = BI_PHYMODE_MII;
530 bis->bi_phymode[1] = BI_PHYMODE_NONE;
531 break;
532 default:
533 break;
534 }
535
536
537 zmiifer = in_be32((void *)ZMII0_FER);
538 zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
539 out_be32((void *)ZMII0_FER, zmiifer);
540
541 return ((int)0x0);
542}
543#endif
544
545#if defined(CONFIG_405EX)
546int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
547{
548 u32 rgmiifer = 0;
549
550
551
552
553
554
555
556 switch (CONFIG_EMAC_PHY_MODE) {
557
558 case EMAC_PHY_MODE_NONE:
559
560 rgmiifer |= RGMII_FER_DIS << 0;
561 rgmiifer |= RGMII_FER_DIS << 4;
562 out_be32((void *)RGMII_FER, rgmiifer);
563 bis->bi_phymode[0] = BI_PHYMODE_NONE;
564 bis->bi_phymode[1] = BI_PHYMODE_NONE;
565 break;
566 case EMAC_PHY_MODE_NONE_RGMII:
567
568 rgmiifer |= RGMII_FER_RGMII << 0;
569 rgmiifer |= RGMII_FER_DIS << 4;
570 out_be32((void *)RGMII_FER, rgmiifer);
571 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
572 bis->bi_phymode[1] = BI_PHYMODE_NONE;
573 break;
574 case EMAC_PHY_MODE_RGMII_NONE:
575
576 rgmiifer |= RGMII_FER_DIS << 0;
577 rgmiifer |= RGMII_FER_RGMII << 4;
578 out_be32((void *)RGMII_FER, rgmiifer);
579 bis->bi_phymode[0] = BI_PHYMODE_NONE;
580 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
581 break;
582 case EMAC_PHY_MODE_RGMII_RGMII:
583
584 rgmiifer |= RGMII_FER_RGMII << 0;
585 rgmiifer |= RGMII_FER_RGMII << 4;
586 out_be32((void *)RGMII_FER, rgmiifer);
587 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
588 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
589 break;
590 case EMAC_PHY_MODE_NONE_GMII:
591
592 rgmiifer |= RGMII_FER_GMII << 0;
593 rgmiifer |= RGMII_FER_DIS << 4;
594 out_be32((void *)RGMII_FER, rgmiifer);
595 bis->bi_phymode[0] = BI_PHYMODE_GMII;
596 bis->bi_phymode[1] = BI_PHYMODE_NONE;
597 break;
598 case EMAC_PHY_MODE_NONE_MII:
599
600 rgmiifer |= RGMII_FER_MII << 0;
601 rgmiifer |= RGMII_FER_DIS << 4;
602 out_be32((void *)RGMII_FER, rgmiifer);
603 bis->bi_phymode[0] = BI_PHYMODE_MII;
604 bis->bi_phymode[1] = BI_PHYMODE_NONE;
605 break;
606 case EMAC_PHY_MODE_GMII_NONE:
607
608 rgmiifer |= RGMII_FER_DIS << 0;
609 rgmiifer |= RGMII_FER_GMII << 4;
610 out_be32((void *)RGMII_FER, rgmiifer);
611 bis->bi_phymode[0] = BI_PHYMODE_NONE;
612 bis->bi_phymode[1] = BI_PHYMODE_GMII;
613 break;
614 case EMAC_PHY_MODE_MII_NONE:
615
616 rgmiifer |= RGMII_FER_DIS << 0;
617 rgmiifer |= RGMII_FER_MII << 4;
618 out_be32((void *)RGMII_FER, rgmiifer);
619 bis->bi_phymode[0] = BI_PHYMODE_NONE;
620 bis->bi_phymode[1] = BI_PHYMODE_MII;
621 break;
622 default:
623 break;
624 }
625
626
627 rgmiifer = in_be32((void *)RGMII_FER);
628 rgmiifer |= (1 << (19-devnum));
629 out_be32((void *)RGMII_FER, rgmiifer);
630
631 return ((int)0x0);
632}
633#endif
634
635#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
636int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
637{
638 u32 eth_cfg;
639 u32 zmiifer;
640 u32 rmiifer;
641 u32 rmiifer1;
642 int mode;
643
644 zmiifer = 0;
645 rmiifer = 0;
646 rmiifer1 = 0;
647
648#if defined(CONFIG_460EX)
649 mode = 9;
650 mfsdr(SDR0_ETH_CFG, eth_cfg);
651 if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
652 ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0))
653 mode = 11;
654#else
655 mode = 10;
656 mfsdr(SDR0_ETH_CFG, eth_cfg);
657 if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
658 ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0) &&
659 ((eth_cfg & SDR0_ETH_CFG_SGMII2_ENABLE) > 0))
660 mode = 12;
661#endif
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686 switch (mode) {
687 case 1:
688
689
690 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
691 bis->bi_phymode[0] = BI_PHYMODE_MII;
692 bis->bi_phymode[1] = BI_PHYMODE_NONE;
693 bis->bi_phymode[2] = BI_PHYMODE_NONE;
694 bis->bi_phymode[3] = BI_PHYMODE_NONE;
695 break;
696 case 2:
697
698
699 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
700 zmiifer |= ZMII_FER_MII << ZMII_FER_V(2);
701 bis->bi_phymode[0] = BI_PHYMODE_MII;
702 bis->bi_phymode[1] = BI_PHYMODE_NONE;
703 bis->bi_phymode[2] = BI_PHYMODE_MII;
704 bis->bi_phymode[3] = BI_PHYMODE_NONE;
705 break;
706 case 3:
707
708
709 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
710 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
711 bis->bi_phymode[0] = BI_PHYMODE_RMII;
712 bis->bi_phymode[1] = BI_PHYMODE_RMII;
713 bis->bi_phymode[2] = BI_PHYMODE_NONE;
714 bis->bi_phymode[3] = BI_PHYMODE_NONE;
715 break;
716 case 4:
717
718
719
720 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
721 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
722 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
723 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
724 bis->bi_phymode[0] = BI_PHYMODE_RMII;
725 bis->bi_phymode[1] = BI_PHYMODE_RMII;
726 bis->bi_phymode[2] = BI_PHYMODE_RMII;
727 bis->bi_phymode[3] = BI_PHYMODE_RMII;
728 break;
729 case 5:
730
731
732 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
733 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
734 bis->bi_phymode[0] = BI_PHYMODE_SMII;
735 bis->bi_phymode[1] = BI_PHYMODE_SMII;
736 bis->bi_phymode[2] = BI_PHYMODE_NONE;
737 bis->bi_phymode[3] = BI_PHYMODE_NONE;
738 break;
739 case 6:
740
741
742
743 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
744 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
745 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
746 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
747 bis->bi_phymode[0] = BI_PHYMODE_SMII;
748 bis->bi_phymode[1] = BI_PHYMODE_SMII;
749 bis->bi_phymode[2] = BI_PHYMODE_SMII;
750 bis->bi_phymode[3] = BI_PHYMODE_SMII;
751 break;
752 case 7:
753
754
755
756 rmiifer |= RGMII_FER_MDIO(0);
757
758 if (devnum == 0) {
759 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2);
760 bis->bi_phymode[0] = BI_PHYMODE_GMII;
761 bis->bi_phymode[1] = BI_PHYMODE_NONE;
762 bis->bi_phymode[2] = BI_PHYMODE_NONE;
763 bis->bi_phymode[3] = BI_PHYMODE_NONE;
764 } else {
765 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3);
766 bis->bi_phymode[0] = BI_PHYMODE_NONE;
767 bis->bi_phymode[1] = BI_PHYMODE_GMII;
768 bis->bi_phymode[2] = BI_PHYMODE_NONE;
769 bis->bi_phymode[3] = BI_PHYMODE_NONE;
770 }
771 break;
772 case 8:
773
774
775
776 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2);
777 rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2);
778 rmiifer |= RGMII_FER_MDIO(0);
779 rmiifer1 |= RGMII_FER_MDIO(0);
780
781 bis->bi_phymode[0] = BI_PHYMODE_GMII;
782 bis->bi_phymode[1] = BI_PHYMODE_NONE;
783 bis->bi_phymode[2] = BI_PHYMODE_GMII;
784 bis->bi_phymode[3] = BI_PHYMODE_NONE;
785 break;
786 case 9:
787
788
789 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
790 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
791 rmiifer |= RGMII_FER_MDIO(0);
792
793 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
794 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
795 bis->bi_phymode[2] = BI_PHYMODE_NONE;
796 bis->bi_phymode[3] = BI_PHYMODE_NONE;
797 break;
798 case 10:
799
800
801
802 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
803 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
804 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2);
805 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3);
806 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
807 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
808 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
809 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
810 break;
811 case 11:
812
813 bis->bi_phymode[0] = BI_PHYMODE_SGMII;
814 bis->bi_phymode[1] = BI_PHYMODE_SGMII;
815 bis->bi_phymode[2] = BI_PHYMODE_NONE;
816 bis->bi_phymode[3] = BI_PHYMODE_NONE;
817 break;
818 case 12:
819
820 bis->bi_phymode[0] = BI_PHYMODE_SGMII;
821 bis->bi_phymode[1] = BI_PHYMODE_SGMII;
822 bis->bi_phymode[2] = BI_PHYMODE_SGMII;
823 bis->bi_phymode[3] = BI_PHYMODE_NONE;
824 break;
825 default:
826 break;
827 }
828
829
830 mfsdr(SDR0_ETH_CFG, eth_cfg);
831 eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
832 mtsdr(SDR0_ETH_CFG, eth_cfg);
833
834 out_be32((void *)RGMII_FER, rmiifer);
835#if defined(CONFIG_460GT)
836 out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1);
837#endif
838
839
840 mfsdr(SDR0_ETH_CFG, eth_cfg);
841 eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
842 mtsdr(SDR0_ETH_CFG, eth_cfg);
843
844 return 0;
845}
846#endif
847
848static inline void *malloc_aligned(u32 size, u32 align)
849{
850 return (void *)(((u32)malloc(size + align) + align - 1) &
851 ~(align - 1));
852}
853
854static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
855{
856 int i;
857 unsigned long reg = 0;
858 unsigned long msr;
859 unsigned long speed;
860 unsigned long duplex;
861 unsigned long failsafe;
862 unsigned mode_reg;
863 unsigned short devnum;
864 unsigned short reg_short;
865#if defined(CONFIG_440GX) || \
866 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
867 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
868 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
869 defined(CONFIG_405EX)
870 u32 opbfreq;
871 sys_info_t sysinfo;
872#if defined(CONFIG_440GX) || \
873 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
874 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
875 defined(CONFIG_405EX)
876 __maybe_unused int ethgroup = -1;
877#endif
878#endif
879 u32 bd_cached;
880 u32 bd_uncached = 0;
881#ifdef CONFIG_4xx_DCACHE
882 static u32 last_used_ea = 0;
883#endif
884#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
885 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
886 defined(CONFIG_405EX)
887 int rgmii_channel;
888#endif
889
890 EMAC_4XX_HW_PST hw_p = dev->priv;
891
892
893
894 if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
895 printf("ERROR: ethaddr not set!\n");
896 return -1;
897 }
898
899#if defined(CONFIG_440GX) || \
900 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
901 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
902 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
903 defined(CONFIG_405EX)
904
905 get_sys_info (&sysinfo);
906#endif
907
908 msr = mfmsr ();
909 mtmsr (msr & ~(MSR_EE));
910
911 devnum = hw_p->devnum;
912
913#ifdef INFO_4XX_ENET
914
915
916
917
918
919
920
921
922 printf ("About preceeding transfer (eth%d):\n"
923 "- Sent packet number %d\n"
924 "- Received packet number %d\n"
925 "- Handled packet number %d\n",
926 hw_p->devnum,
927 hw_p->stats.pkts_tx,
928 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
929
930 hw_p->stats.pkts_tx = 0;
931 hw_p->stats.pkts_rx = 0;
932 hw_p->stats.pkts_handled = 0;
933 hw_p->print_speed = 1;
934#endif
935
936 hw_p->tx_err_index = 0;
937 hw_p->rx_err_index = 0;
938
939 hw_p->rx_slot = 0;
940 hw_p->rx_i_index = 0;
941 hw_p->rx_u_index = 0;
942
943 hw_p->tx_slot = 0;
944 hw_p->tx_i_index = 0;
945 hw_p->tx_u_index = 0;
946
947#if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
948
949
950
951
952 reg = 0;
953 out_be32((void *)ZMII0_FER, 0);
954 udelay (100);
955
956#if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
957 out_be32((void *)ZMII0_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
958#elif defined(CONFIG_440GX) || \
959 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
960 defined(CONFIG_460EX) || defined(CONFIG_460GT)
961 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
962#endif
963
964 out_be32((void *)ZMII0_SSR, ZMII0_SSR_SP << ZMII0_SSR_V(devnum));
965#endif
966#if defined(CONFIG_405EX)
967 ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
968#endif
969
970 sync();
971
972
973 emac_loopback_enable(hw_p);
974
975
976 out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_SRST);
977
978
979 emac_loopback_disable(hw_p);
980
981 failsafe = 1000;
982 while ((in_be32((void *)EMAC0_MR0 + hw_p->hw_addr) & (EMAC_MR0_SRST)) && failsafe) {
983 udelay (1000);
984 failsafe--;
985 }
986 if (failsafe <= 0)
987 printf("\nProblem resetting EMAC!\n");
988
989#if defined(CONFIG_440GX) || \
990 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
991 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
992 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
993 defined(CONFIG_405EX)
994
995 mode_reg = 0x0;
996 mode_reg &= ~0x00000038;
997 opbfreq = sysinfo.freqOPB / 1000000;
998 if (opbfreq <= 50);
999 else if (opbfreq <= 66)
1000 mode_reg |= EMAC_MR1_OBCI_66;
1001 else if (opbfreq <= 83)
1002 mode_reg |= EMAC_MR1_OBCI_83;
1003 else if (opbfreq <= 100)
1004 mode_reg |= EMAC_MR1_OBCI_100;
1005 else
1006 mode_reg |= EMAC_MR1_OBCI_GT100;
1007
1008 out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
1009#endif
1010
1011#if defined(CONFIG_GPCS_PHY_ADDR) || defined(CONFIG_GPCS_PHY1_ADDR) || \
1012 defined(CONFIG_GPCS_PHY2_ADDR) || defined(CONFIG_GPCS_PHY3_ADDR)
1013 if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
1014
1015
1016
1017
1018 switch (devnum) {
1019#if defined(CONFIG_GPCS_PHY_ADDR)
1020 case 0:
1021 reg = CONFIG_GPCS_PHY_ADDR;
1022 break;
1023#endif
1024#if defined(CONFIG_GPCS_PHY1_ADDR)
1025 case 1:
1026 reg = CONFIG_GPCS_PHY1_ADDR;
1027 break;
1028#endif
1029#if defined(CONFIG_GPCS_PHY2_ADDR)
1030 case 2:
1031 reg = CONFIG_GPCS_PHY2_ADDR;
1032 break;
1033#endif
1034#if defined(CONFIG_GPCS_PHY3_ADDR)
1035 case 3:
1036 reg = CONFIG_GPCS_PHY3_ADDR;
1037 break;
1038#endif
1039 }
1040
1041 mode_reg = in_be32((void *)EMAC0_MR1 + hw_p->hw_addr);
1042 mode_reg |= EMAC_MR1_MF_1000GPCS | EMAC_MR1_IPPA_SET(reg);
1043 out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
1044
1045
1046 miiphy_reset(dev->name, reg);
1047 miiphy_write(dev->name, reg, 0x04, 0x8120);
1048 miiphy_write(dev->name, reg, 0x07, 0x2801);
1049 miiphy_write(dev->name, reg, 0x00, 0x0140);
1050 }
1051#endif
1052
1053
1054 reg_short = 0;
1055 switch (devnum) {
1056 case 0:
1057 reg = CONFIG_PHY_ADDR;
1058 break;
1059#if defined (CONFIG_PHY1_ADDR)
1060 case 1:
1061 reg = CONFIG_PHY1_ADDR;
1062 break;
1063#endif
1064#if defined (CONFIG_PHY2_ADDR)
1065 case 2:
1066 reg = CONFIG_PHY2_ADDR;
1067 break;
1068#endif
1069#if defined (CONFIG_PHY3_ADDR)
1070 case 3:
1071 reg = CONFIG_PHY3_ADDR;
1072 break;
1073#endif
1074 default:
1075 reg = CONFIG_PHY_ADDR;
1076 break;
1077 }
1078
1079 bis->bi_phynum[devnum] = reg;
1080
1081 if (reg == CONFIG_FIXED_PHY)
1082 goto get_speed;
1083
1084#if defined(CONFIG_PHY_RESET)
1085
1086
1087
1088
1089 if (hw_p->first_init == 0) {
1090#if defined(CONFIG_M88E1111_PHY)
1091 miiphy_write (dev->name, reg, 0x14, 0x0ce3);
1092 miiphy_write (dev->name, reg, 0x18, 0x4101);
1093 miiphy_write (dev->name, reg, 0x09, 0x0e00);
1094 miiphy_write (dev->name, reg, 0x04, 0x01e1);
1095#if defined(CONFIG_M88E1111_DISABLE_FIBER)
1096 miiphy_read(dev->name, reg, 0x1b, ®_short);
1097 reg_short |= 0x8000;
1098 miiphy_write(dev->name, reg, 0x1b, reg_short);
1099#endif
1100#endif
1101#if defined(CONFIG_M88E1112_PHY)
1102 if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
1103
1104
1105
1106
1107
1108
1109
1110 miiphy_write(dev->name, reg, 0x16, 0x0002);
1111
1112 miiphy_write(dev->name, reg, 0x00, 0x0040);
1113 miiphy_read(dev->name, reg, 0x1a, ®_short);
1114 reg_short |= 0x8000;
1115 miiphy_write(dev->name, reg, 0x1a, reg_short);
1116 miiphy_reset(dev->name, reg);
1117
1118
1119 miiphy_write(dev->name, reg, 0x16, 0x0000);
1120 }
1121#endif
1122 miiphy_reset (dev->name, reg);
1123
1124#if defined(CONFIG_440GX) || \
1125 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1126 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1127 defined(CONFIG_405EX)
1128
1129#if defined(CONFIG_CIS8201_PHY)
1130
1131
1132
1133
1134 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
1135#if defined(CONFIG_CIS8201_SHORT_ETCH)
1136 miiphy_write (dev->name, reg, 23, 0x1300);
1137#else
1138 miiphy_write (dev->name, reg, 23, 0x1000);
1139#endif
1140
1141
1142
1143
1144
1145
1146 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1147 miiphy_write (dev->name, reg, 0x08, 0x0200);
1148 miiphy_write (dev->name, reg, 0x1f, 0x52b5);
1149 miiphy_write (dev->name, reg, 0x02, 0x0004);
1150 miiphy_write (dev->name, reg, 0x01, 0x0671);
1151 miiphy_write (dev->name, reg, 0x00, 0x8fae);
1152 miiphy_write (dev->name, reg, 0x1f, 0x2a30);
1153 miiphy_write (dev->name, reg, 0x08, 0x0000);
1154 miiphy_write (dev->name, reg, 0x1f, 0x0000);
1155
1156 }
1157#endif
1158
1159#if defined(CONFIG_ET1011C_PHY)
1160
1161
1162
1163
1164 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
1165 miiphy_read (dev->name, reg, 0x16, ®_short);
1166 reg_short &= ~(0x7);
1167 reg_short |= 0x6;
1168 miiphy_write (dev->name, reg, 0x16, reg_short);
1169
1170 miiphy_read (dev->name, reg, 0x17, ®_short);
1171 reg_short &= ~(0x40);
1172 miiphy_write (dev->name, reg, 0x17, reg_short);
1173
1174 miiphy_write(dev->name, reg, 0x1c, 0x74f0);
1175 }
1176#endif
1177
1178#endif
1179
1180 phy_setup_aneg (dev->name, reg);
1181 udelay (1000);
1182 }
1183#endif
1184
1185 miiphy_read (dev->name, reg, MII_BMSR, ®_short);
1186
1187
1188
1189
1190 if ((reg_short & BMSR_ANEGCAPABLE)
1191 && !(reg_short & BMSR_ANEGCOMPLETE)) {
1192 puts ("Waiting for PHY auto negotiation to complete");
1193 i = 0;
1194 while (!(reg_short & BMSR_ANEGCOMPLETE)) {
1195
1196
1197
1198 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
1199 puts (" TIMEOUT !\n");
1200 break;
1201 }
1202
1203 if ((i++ % 1000) == 0) {
1204 putc ('.');
1205 }
1206 udelay (1000);
1207 miiphy_read (dev->name, reg, MII_BMSR, ®_short);
1208 }
1209 puts (" done\n");
1210 udelay (500000);
1211 }
1212
1213get_speed:
1214 if (reg == CONFIG_FIXED_PHY) {
1215 for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) {
1216 if (devnum == fixed_phy_port[i].devnum) {
1217 speed = fixed_phy_port[i].speed;
1218 duplex = fixed_phy_port[i].duplex;
1219 break;
1220 }
1221 }
1222
1223 if (i == ARRAY_SIZE(fixed_phy_port)) {
1224 printf("ERROR: PHY (%s) not configured correctly!\n",
1225 dev->name);
1226 return -1;
1227 }
1228 } else {
1229 speed = miiphy_speed(dev->name, reg);
1230 duplex = miiphy_duplex(dev->name, reg);
1231 }
1232
1233 if (hw_p->print_speed) {
1234 hw_p->print_speed = 0;
1235 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
1236 (int) speed, (duplex == HALF) ? "HALF" : "FULL",
1237 hw_p->devnum);
1238 }
1239
1240#if defined(CONFIG_440) && \
1241 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
1242 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
1243 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
1244#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
1245 mfsdr(SDR0_MFR, reg);
1246 if (speed == 100) {
1247 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
1248 } else {
1249 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
1250 }
1251 mtsdr(SDR0_MFR, reg);
1252#endif
1253
1254
1255 reg = in_be32((void *)ZMII0_SSR);
1256 if ( (speed == 100) || (speed == 1000) )
1257 out_be32((void *)ZMII0_SSR, reg | (ZMII0_SSR_SP << ZMII0_SSR_V (devnum)));
1258 else
1259 out_be32((void *)ZMII0_SSR, reg & (~(ZMII0_SSR_SP << ZMII0_SSR_V (devnum))));
1260
1261 if ((devnum == 2) || (devnum == 3)) {
1262 if (speed == 1000)
1263 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1264 else if (speed == 100)
1265 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
1266 else if (speed == 10)
1267 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
1268 else {
1269 printf("Error in RGMII Speed\n");
1270 return -1;
1271 }
1272 out_be32((void *)RGMII_SSR, reg);
1273 }
1274#endif
1275
1276#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1277 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1278 defined(CONFIG_405EX)
1279 if (devnum >= 2)
1280 rgmii_channel = devnum - 2;
1281 else
1282 rgmii_channel = devnum;
1283
1284 if (speed == 1000)
1285 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V(rgmii_channel));
1286 else if (speed == 100)
1287 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V(rgmii_channel));
1288 else if (speed == 10)
1289 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V(rgmii_channel));
1290 else {
1291 printf("Error in RGMII Speed\n");
1292 return -1;
1293 }
1294 out_be32((void *)RGMII_SSR, reg);
1295#if defined(CONFIG_460GT)
1296 if ((devnum == 2) || (devnum == 3))
1297 out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
1298#endif
1299#endif
1300
1301
1302#if defined(CONFIG_440GX) || \
1303 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1304 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
1305 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1306 defined(CONFIG_405EX)
1307 mtdcr (MAL0_CFG, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
1308 MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
1309#else
1310 mtdcr (MAL0_CFG, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
1311
1312 if (get_pvr() == PVR_440GP_RB) {
1313 mtdcr (MAL0_CFG, mfdcr(MAL0_CFG) & ~MAL_CR_PLBB);
1314 }
1315#endif
1316
1317
1318
1319
1320
1321
1322
1323 if (hw_p->first_init == 0) {
1324 debug("*** Allocating descriptor memory ***\n");
1325
1326 bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
1327 if (!bd_cached) {
1328 printf("%s: Error allocating MAL descriptor buffers!\n", __func__);
1329 return -1;
1330 }
1331
1332#ifdef CONFIG_4xx_DCACHE
1333 flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
1334 if (!last_used_ea)
1335#if defined(CONFIG_SYS_MEM_TOP_HIDE)
1336 bd_uncached = bis->bi_memsize + CONFIG_SYS_MEM_TOP_HIDE;
1337#else
1338 bd_uncached = bis->bi_memsize;
1339#endif
1340 else
1341 bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
1342
1343 last_used_ea = bd_uncached;
1344 program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
1345 TLB_WORD2_I_ENABLE);
1346#else
1347 bd_uncached = bd_cached;
1348#endif
1349 hw_p->tx_phys = bd_cached;
1350 hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
1351 hw_p->tx = (mal_desc_t *)(bd_uncached);
1352 hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
1353 debug("hw_p->tx=%p, hw_p->rx=%p\n", hw_p->tx, hw_p->rx);
1354 }
1355
1356 for (i = 0; i < NUM_TX_BUFF; i++) {
1357 hw_p->tx[i].ctrl = 0;
1358 hw_p->tx[i].data_len = 0;
1359 if (hw_p->first_init == 0)
1360 hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
1361 L1_CACHE_BYTES);
1362 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
1363 if ((NUM_TX_BUFF - 1) == i)
1364 hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
1365 hw_p->tx_run[i] = -1;
1366 debug("TX_BUFF %d @ 0x%08x\n", i, (u32)hw_p->tx[i].data_ptr);
1367 }
1368
1369 for (i = 0; i < NUM_RX_BUFF; i++) {
1370 hw_p->rx[i].ctrl = 0;
1371 hw_p->rx[i].data_len = 0;
1372 hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
1373 if ((NUM_RX_BUFF - 1) == i)
1374 hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
1375 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
1376 hw_p->rx_ready[i] = -1;
1377 debug("RX_BUFF %d @ 0x%08x\n", i, (u32)hw_p->rx[i].data_ptr);
1378 }
1379
1380 reg = 0x00000000;
1381
1382 reg |= dev->enetaddr[0];
1383 reg = reg << 8;
1384 reg |= dev->enetaddr[1];
1385
1386 out_be32((void *)EMAC0_IAH + hw_p->hw_addr, reg);
1387
1388 reg = 0x00000000;
1389 reg |= dev->enetaddr[2];
1390 reg = reg << 8;
1391 reg |= dev->enetaddr[3];
1392 reg = reg << 8;
1393 reg |= dev->enetaddr[4];
1394 reg = reg << 8;
1395 reg |= dev->enetaddr[5];
1396
1397 out_be32((void *)EMAC0_IAL + hw_p->hw_addr, reg);
1398
1399 switch (devnum) {
1400 case 1:
1401
1402#if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
1403 mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
1404#else
1405 mtdcr (MAL0_TXCTP1R, hw_p->tx_phys);
1406#endif
1407#if defined(CONFIG_440)
1408 mtdcr (MAL0_TXBADDR, 0x0);
1409 mtdcr (MAL0_RXBADDR, 0x0);
1410#endif
1411
1412#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
1413 mtdcr (MAL0_RXCTP8R, hw_p->rx_phys);
1414
1415 mtdcr (MAL0_RCBS8, ENET_MAX_MTU_ALIGNED / 16);
1416#else
1417 mtdcr (MAL0_RXCTP1R, hw_p->rx_phys);
1418
1419 mtdcr (MAL0_RCBS1, ENET_MAX_MTU_ALIGNED / 16);
1420#endif
1421 break;
1422#if defined (CONFIG_440GX)
1423 case 2:
1424
1425 mtdcr (MAL0_TXBADDR, 0x0);
1426 mtdcr (MAL0_RXBADDR, 0x0);
1427 mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
1428 mtdcr (MAL0_RXCTP2R, hw_p->rx_phys);
1429
1430 mtdcr (MAL0_RCBS2, ENET_MAX_MTU_ALIGNED / 16);
1431 break;
1432 case 3:
1433
1434 mtdcr (MAL0_TXBADDR, 0x0);
1435 mtdcr (MAL0_TXCTP3R, hw_p->tx_phys);
1436 mtdcr (MAL0_RXBADDR, 0x0);
1437 mtdcr (MAL0_RXCTP3R, hw_p->rx_phys);
1438
1439 mtdcr (MAL0_RCBS3, ENET_MAX_MTU_ALIGNED / 16);
1440 break;
1441#endif
1442#if defined (CONFIG_460GT)
1443 case 2:
1444
1445 mtdcr (MAL0_TXBADDR, 0x0);
1446 mtdcr (MAL0_RXBADDR, 0x0);
1447 mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
1448 mtdcr (MAL0_RXCTP16R, hw_p->rx_phys);
1449
1450 mtdcr (MAL0_RCBS16, ENET_MAX_MTU_ALIGNED / 16);
1451 break;
1452 case 3:
1453
1454 mtdcr (MAL0_TXBADDR, 0x0);
1455 mtdcr (MAL0_RXBADDR, 0x0);
1456 mtdcr (MAL0_TXCTP3R, hw_p->tx_phys);
1457 mtdcr (MAL0_RXCTP24R, hw_p->rx_phys);
1458
1459 mtdcr (MAL0_RCBS24, ENET_MAX_MTU_ALIGNED / 16);
1460 break;
1461#endif
1462 case 0:
1463 default:
1464
1465#if defined(CONFIG_440)
1466 mtdcr (MAL0_TXBADDR, 0x0);
1467 mtdcr (MAL0_RXBADDR, 0x0);
1468#endif
1469 mtdcr (MAL0_TXCTP0R, hw_p->tx_phys);
1470 mtdcr (MAL0_RXCTP0R, hw_p->rx_phys);
1471
1472 mtdcr (MAL0_RCBS0, ENET_MAX_MTU_ALIGNED / 16);
1473 break;
1474 }
1475
1476
1477#if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
1478 mtdcr (MAL0_TXCASR, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
1479#else
1480 mtdcr (MAL0_TXCASR, (MAL_TXRX_CASR >> hw_p->devnum));
1481#endif
1482 mtdcr (MAL0_RXCASR, (MAL_TXRX_CASR >> hw_p->devnum));
1483
1484
1485 out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_TXE | EMAC_MR0_RXE);
1486
1487 mode_reg = in_be32((void *)EMAC0_MR1 + hw_p->hw_addr);
1488
1489
1490 mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
1491
1492
1493 if (speed == _1000BASET) {
1494#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
1495 unsigned long pfc1;
1496
1497 mfsdr (SDR0_PFC1, pfc1);
1498 pfc1 |= SDR0_PFC1_EM_1000;
1499 mtsdr (SDR0_PFC1, pfc1);
1500#endif
1501 mode_reg = mode_reg | EMAC_MR1_MF_1000MBPS | EMAC_MR1_IST;
1502 } else if (speed == _100BASET)
1503 mode_reg = mode_reg | EMAC_MR1_MF_100MBPS | EMAC_MR1_IST;
1504 else
1505 mode_reg = mode_reg & ~0x00C00000;
1506 if (duplex == FULL)
1507 mode_reg = mode_reg | 0x80000000 | EMAC_MR1_IST;
1508
1509 out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
1510
1511
1512
1513 out_be32((void *)EMAC0_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
1514
1515
1516
1517
1518 out_be32((void *)EMAC0_TRTR + hw_p->hw_addr, 0x18000000);
1519
1520
1521#if defined(CONFIG_440)
1522
1523 out_be32((void *)EMAC0_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
1524#else
1525
1526 out_be32((void *)EMAC0_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
1527#endif
1528 out_be32((void *)EMAC0_TMR1 + hw_p->hw_addr, 0xf8640000);
1529
1530
1531 out_be32((void *)EMAC0_TMR0 + hw_p->hw_addr, 0x00000003);
1532
1533 out_be32((void *)EMAC0_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
1534
1535
1536 hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
1537 if (speed == _100BASET)
1538 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1539
1540 out_be32((void *)EMAC0_ISR + hw_p->hw_addr, 0xffffffff);
1541 out_be32((void *)EMAC0_IER + hw_p->hw_addr, hw_p->emac_ier);
1542
1543 if (hw_p->first_init == 0) {
1544
1545
1546
1547 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1548 (interrupt_handler_t *) enetInt, dev);
1549 }
1550
1551 mtmsr (msr);
1552
1553 hw_p->bis = bis;
1554 hw_p->first_init = 1;
1555
1556 return 0;
1557}
1558
1559
1560static int ppc_4xx_eth_send(struct eth_device *dev, void *ptr, int len)
1561{
1562 struct enet_frame *ef_ptr;
1563 ulong time_start, time_now;
1564 unsigned long temp_txm0;
1565 EMAC_4XX_HW_PST hw_p = dev->priv;
1566
1567 ef_ptr = (struct enet_frame *) ptr;
1568
1569
1570
1571
1572 (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1573
1574
1575
1576
1577
1578 if (len > ENET_MAX_MTU)
1579 len = ENET_MAX_MTU;
1580
1581
1582 memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
1583 flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
1584
1585
1586
1587
1588 hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1589 EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1590 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1591 if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1592 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1593
1594 hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1595 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1596
1597 sync();
1598
1599 out_be32((void *)EMAC0_TMR0 + hw_p->hw_addr,
1600 in_be32((void *)EMAC0_TMR0 + hw_p->hw_addr) | EMAC_TMR0_GNP0);
1601#ifdef INFO_4XX_ENET
1602 hw_p->stats.pkts_tx++;
1603#endif
1604
1605
1606
1607
1608 time_start = get_timer (0);
1609 while (1) {
1610 temp_txm0 = in_be32((void *)EMAC0_TMR0 + hw_p->hw_addr);
1611
1612 if ((temp_txm0 & EMAC_TMR0_GNP0) != 0) {
1613
1614
1615
1616
1617 time_now = get_timer (0);
1618 if ((time_now - time_start) > 3000) {
1619 return (-1);
1620 }
1621 } else {
1622 return (len);
1623 }
1624 }
1625}
1626
1627int enetInt (struct eth_device *dev)
1628{
1629 int serviced;
1630 int rc = -1;
1631 u32 mal_isr;
1632 u32 emac_isr = 0;
1633 u32 mal_eob;
1634 u32 uic_mal;
1635 u32 uic_mal_err;
1636 u32 uic_emac;
1637 u32 uic_emac_b;
1638 EMAC_4XX_HW_PST hw_p;
1639
1640
1641
1642
1643
1644 dev = eth_get_dev();
1645
1646 hw_p = dev->priv;
1647
1648
1649 do {
1650 serviced = 0;
1651
1652 uic_mal = mfdcr(UIC_BASE_MAL + UIC_MSR);
1653 uic_mal_err = mfdcr(UIC_BASE_MAL_ERR + UIC_MSR);
1654 uic_emac = mfdcr(UIC_BASE_EMAC + UIC_MSR);
1655 uic_emac_b = mfdcr(UIC_BASE_EMAC_B + UIC_MSR);
1656
1657 if (!(uic_mal & (UIC_MAL_RXEOB | UIC_MAL_TXEOB))
1658 && !(uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE))
1659 && !(uic_emac & UIC_ETHx) && !(uic_emac_b & UIC_ETHxB)) {
1660
1661 return (rc);
1662 }
1663
1664
1665
1666 if (uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) {
1667
1668 mal_isr = mfdcr(MAL0_ESR);
1669 mal_err(dev, mal_isr, uic_mal_err,
1670 MAL_UIC_DEF, MAL_UIC_ERR);
1671
1672
1673 mtdcr(UIC_BASE_MAL_ERR + UIC_SR,
1674 UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE);
1675
1676 return -1;
1677 }
1678
1679
1680 if ((uic_emac & UIC_ETHx) || (uic_emac_b & UIC_ETHxB)) {
1681 emac_isr = in_be32((void *)EMAC0_ISR + hw_p->hw_addr);
1682 emac_err(dev, emac_isr);
1683
1684
1685 mtdcr(UIC_BASE_EMAC + UIC_SR, UIC_ETHx);
1686 mtdcr(UIC_BASE_EMAC_B + UIC_SR, UIC_ETHxB);
1687
1688 return -1;
1689 }
1690
1691
1692 if (uic_mal & UIC_MAL_TXEOB) {
1693
1694 mal_eob = mfdcr(MAL0_TXEOBISR);
1695 mtdcr(MAL0_TXEOBISR, mal_eob);
1696 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_TXEOB);
1697
1698
1699 serviced = 1;
1700 rc = 0;
1701 }
1702
1703
1704
1705 if (uic_mal & UIC_MAL_RXEOB) {
1706 mal_eob = mfdcr(MAL0_RXEOBISR);
1707 if (mal_eob &
1708 (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL))) {
1709
1710 enet_rcv(dev, emac_isr);
1711
1712
1713 mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_RXEOB);
1714
1715
1716 serviced = 1;
1717 rc = 0;
1718 }
1719 }
1720#if defined(CONFIG_405EZ)
1721
1722
1723
1724
1725
1726 mtsdr(SDR0_ICINTSTAT,
1727 SDR_ICRX_STAT | SDR_ICTX0_STAT | SDR_ICTX1_STAT);
1728#endif
1729 } while (serviced);
1730
1731 return (rc);
1732}
1733
1734
1735
1736
1737static void mal_err (struct eth_device *dev, unsigned long isr,
1738 unsigned long uic, unsigned long maldef,
1739 unsigned long mal_errr)
1740{
1741 EMAC_4XX_HW_PST hw_p = dev->priv;
1742
1743 mtdcr (MAL0_ESR, isr);
1744
1745
1746 mtdcr (MAL0_TXDEIR, 0xC0000000);
1747 mtdcr (MAL0_RXDEIR, 0x80000000);
1748
1749#ifdef INFO_4XX_ENET
1750 printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
1751#endif
1752
1753 eth_init (hw_p->bis);
1754}
1755
1756
1757
1758
1759static void emac_err (struct eth_device *dev, unsigned long isr)
1760{
1761 EMAC_4XX_HW_PST hw_p = dev->priv;
1762
1763 printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
1764 out_be32((void *)EMAC0_ISR + hw_p->hw_addr, isr);
1765}
1766
1767
1768
1769
1770static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1771{
1772 unsigned long data_len;
1773 unsigned long rx_eob_isr;
1774 EMAC_4XX_HW_PST hw_p = dev->priv;
1775
1776 int handled = 0;
1777 int i;
1778 int loop_count = 0;
1779
1780 rx_eob_isr = mfdcr (MAL0_RXEOBISR);
1781 if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
1782
1783 mtdcr (MAL0_RXEOBISR, rx_eob_isr);
1784
1785
1786 while (1) {
1787 i = hw_p->rx_slot;
1788
1789 if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1790 || (loop_count >= NUM_RX_BUFF))
1791 break;
1792
1793 loop_count++;
1794 handled++;
1795 data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff;
1796 if (data_len) {
1797 if (data_len > ENET_MAX_MTU)
1798 data_len = 0;
1799 else {
1800 if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) {
1801 data_len = 0;
1802 hw_p->stats.rx_err_log[hw_p->
1803 rx_err_index]
1804 = hw_p->rx[i].ctrl;
1805 hw_p->rx_err_index++;
1806 if (hw_p->rx_err_index ==
1807 MAX_ERR_LOG)
1808 hw_p->rx_err_index =
1809 0;
1810 }
1811 }
1812 }
1813 if (!data_len) {
1814 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1815
1816 hw_p->stats.data_len_err++;
1817 }
1818
1819
1820
1821
1822
1823 else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1824 if (hw_p->is_receiving)
1825 printf ("ERROR : Receive buffers are full!\n");
1826 break;
1827 } else {
1828 hw_p->stats.rx_frames++;
1829 hw_p->stats.rx += data_len;
1830#ifdef INFO_4XX_ENET
1831 hw_p->stats.pkts_rx++;
1832#endif
1833
1834
1835
1836 hw_p->rx_ready[hw_p->rx_i_index] = i;
1837 hw_p->rx_i_index++;
1838 if (NUM_RX_BUFF == hw_p->rx_i_index)
1839 hw_p->rx_i_index = 0;
1840
1841 hw_p->rx_slot++;
1842 if (NUM_RX_BUFF == hw_p->rx_slot)
1843 hw_p->rx_slot = 0;
1844
1845
1846
1847
1848
1849
1850 }
1851 }
1852 }
1853}
1854
1855
1856static int ppc_4xx_eth_rx (struct eth_device *dev)
1857{
1858 int length;
1859 int user_index;
1860 unsigned long msr;
1861 EMAC_4XX_HW_PST hw_p = dev->priv;
1862
1863 hw_p->is_receiving = 1;
1864
1865 for (;;) {
1866
1867
1868
1869
1870 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1871 if (user_index == -1) {
1872 length = -1;
1873 break;
1874 }
1875
1876 msr = mfmsr ();
1877 mtmsr (msr & ~(MSR_EE));
1878
1879 length = hw_p->rx[user_index].data_len & 0x0fff;
1880
1881
1882
1883
1884 invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
1885 (u32)hw_p->rx[user_index].data_ptr +
1886 length - 4);
1887 NetReceive (NetRxPackets[user_index], length - 4);
1888
1889 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1890
1891 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1892 hw_p->rx_u_index++;
1893 if (NUM_RX_BUFF == hw_p->rx_u_index)
1894 hw_p->rx_u_index = 0;
1895
1896#ifdef INFO_4XX_ENET
1897 hw_p->stats.pkts_handled++;
1898#endif
1899
1900 mtmsr (msr);
1901 }
1902
1903 hw_p->is_receiving = 0;
1904
1905 return length;
1906}
1907
1908int ppc_4xx_eth_initialize (bd_t * bis)
1909{
1910 static int virgin = 0;
1911 struct eth_device *dev;
1912 int eth_num = 0;
1913 EMAC_4XX_HW_PST hw = NULL;
1914 u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1915 u32 hw_addr[4];
1916 u32 mal_ier;
1917
1918#if defined(CONFIG_440GX)
1919 unsigned long pfc1;
1920
1921 mfsdr (SDR0_PFC1, pfc1);
1922 pfc1 &= ~(0x01e00000);
1923 pfc1 |= 0x01200000;
1924 mtsdr (SDR0_PFC1, pfc1);
1925#endif
1926
1927
1928 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1929 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
1930
1931 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1932 int ethaddr_idx = eth_num + CONFIG_EMAC_NR_START;
1933 switch (eth_num) {
1934 default:
1935 case 0:
1936 eth_getenv_enetaddr("ethaddr", ethaddr[ethaddr_idx]);
1937 hw_addr[eth_num] = 0x0;
1938 break;
1939#ifdef CONFIG_HAS_ETH1
1940 case 1:
1941 eth_getenv_enetaddr("eth1addr", ethaddr[ethaddr_idx]);
1942 hw_addr[eth_num] = 0x100;
1943 break;
1944#endif
1945#ifdef CONFIG_HAS_ETH2
1946 case 2:
1947 eth_getenv_enetaddr("eth2addr", ethaddr[ethaddr_idx]);
1948#if defined(CONFIG_460GT)
1949 hw_addr[eth_num] = 0x300;
1950#else
1951 hw_addr[eth_num] = 0x400;
1952#endif
1953 break;
1954#endif
1955#ifdef CONFIG_HAS_ETH3
1956 case 3:
1957 eth_getenv_enetaddr("eth3addr", ethaddr[ethaddr_idx]);
1958#if defined(CONFIG_460GT)
1959 hw_addr[eth_num] = 0x400;
1960#else
1961 hw_addr[eth_num] = 0x600;
1962#endif
1963 break;
1964#endif
1965 }
1966 }
1967
1968
1969 bis->bi_phynum[0] = CONFIG_PHY_ADDR;
1970 bis->bi_phymode[0] = 0;
1971
1972#if defined(CONFIG_PHY1_ADDR)
1973 bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
1974 bis->bi_phymode[1] = 0;
1975#endif
1976#if defined(CONFIG_440GX)
1977 bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1978 bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1979 bis->bi_phymode[2] = 2;
1980 bis->bi_phymode[3] = 2;
1981#endif
1982
1983#if defined(CONFIG_440GX) || \
1984 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1985 defined(CONFIG_405EX)
1986 ppc_4xx_eth_setup_bridge(0, bis);
1987#endif
1988
1989 for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1990
1991
1992
1993
1994 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
1995 bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1996 continue;
1997 }
1998
1999
2000 dev = (struct eth_device *) malloc (sizeof (*dev));
2001 if (dev == NULL) {
2002 printf ("ppc_4xx_eth_initialize: "
2003 "Cannot allocate eth_device %d\n", eth_num);
2004 return (-1);
2005 }
2006 memset(dev, 0, sizeof(*dev));
2007
2008
2009 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
2010 if (hw == NULL) {
2011 printf ("ppc_4xx_eth_initialize: "
2012 "Cannot allocate private hw data for eth_device %d",
2013 eth_num);
2014 free (dev);
2015 return (-1);
2016 }
2017 memset(hw, 0, sizeof(*hw));
2018
2019 hw->hw_addr = hw_addr[eth_num];
2020 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
2021 hw->devnum = eth_num;
2022 hw->print_speed = 1;
2023
2024 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
2025 dev->priv = (void *) hw;
2026 dev->init = ppc_4xx_eth_init;
2027 dev->halt = ppc_4xx_eth_halt;
2028 dev->send = ppc_4xx_eth_send;
2029 dev->recv = ppc_4xx_eth_rx;
2030
2031 eth_register(dev);
2032
2033#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
2034 miiphy_register(dev->name,
2035 emac4xx_miiphy_read, emac4xx_miiphy_write);
2036#endif
2037
2038 if (0 == virgin) {
2039
2040#if defined(CONFIG_440SPE) || \
2041 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
2042 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
2043 defined(CONFIG_405EX)
2044 mal_ier =
2045 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
2046 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
2047#else
2048 mal_ier =
2049 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
2050 MAL_IER_OPBE | MAL_IER_PLBE;
2051#endif
2052 mtdcr (MAL0_ESR, 0xffffffff);
2053 mtdcr (MAL0_TXDEIR, 0xffffffff);
2054 mtdcr (MAL0_RXDEIR, 0xffffffff);
2055 mtdcr (MAL0_IER, mal_ier);
2056
2057
2058 irq_install_handler (VECNUM_MAL_SERR,
2059 (interrupt_handler_t *) enetInt,
2060 dev);
2061 irq_install_handler (VECNUM_MAL_TXEOB,
2062 (interrupt_handler_t *) enetInt,
2063 dev);
2064 irq_install_handler (VECNUM_MAL_RXEOB,
2065 (interrupt_handler_t *) enetInt,
2066 dev);
2067 irq_install_handler (VECNUM_MAL_TXDE,
2068 (interrupt_handler_t *) enetInt,
2069 dev);
2070 irq_install_handler (VECNUM_MAL_RXDE,
2071 (interrupt_handler_t *) enetInt,
2072 dev);
2073 virgin = 1;
2074 }
2075 }
2076
2077 return 0;
2078}
2079