Merge branch 'master' of git://www.denx.de/git/u-boot-sh
[oweals/u-boot.git] / cpu / ppc4xx / 4xx_enet.c
1 /*-----------------------------------------------------------------------------+
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  *  15-Aug-05   sr@denx.de
76  *              - merged 405gp_enet.c and 440gx_enet.c to generic 4xx_enet.c
77                   now handling all 4xx cpu's.
78  *-----------------------------------------------------------------------------*/
79
80 #include <config.h>
81 #include <common.h>
82 #include <net.h>
83 #include <asm/processor.h>
84 #include <asm/io.h>
85 #include <asm/cache.h>
86 #include <asm/mmu.h>
87 #include <commproc.h>
88 #include <ppc4xx.h>
89 #include <ppc4xx_enet.h>
90 #include <405_mal.h>
91 #include <miiphy.h>
92 #include <malloc.h>
93 #include <asm/ppc4xx-intvec.h>
94
95 /*
96  * Only compile for platform with AMCC EMAC ethernet controller and
97  * network support enabled.
98  * Remark: CONFIG_405 describes Xilinx PPC405 FPGA without EMAC controller!
99  */
100 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_405) && !defined(CONFIG_IOP480)
101
102 #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
103 #error "CONFIG_MII has to be defined!"
104 #endif
105
106 #if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI)
107 #error "CONFIG_NET_MULTI has to be defined for NetConsole"
108 #endif
109
110 #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
111 #define PHY_AUTONEGOTIATE_TIMEOUT 5000  /* 5000 ms autonegotiate timeout */
112
113 /* Ethernet Transmit and Receive Buffers */
114 /* AS.HARNOIS
115  * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
116  * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
117  */
118 #define ENET_MAX_MTU           PKTSIZE
119 #define ENET_MAX_MTU_ALIGNED   PKTSIZE_ALIGN
120
121 /*-----------------------------------------------------------------------------+
122  * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
123  * Interrupt Controller).
124  *-----------------------------------------------------------------------------*/
125 #define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE  | UIC_MAL_RXDE)
126 #define MAL_UIC_DEF  (UIC_MAL_RXEOB | MAL_UIC_ERR)
127 #define EMAC_UIC_DEF UIC_ENET
128 #define EMAC_UIC_DEF1 UIC_ENET1
129 #define SEL_UIC_DEF(p) (p ? UIC_ENET1 : UIC_ENET )
130
131 #undef INFO_4XX_ENET
132
133 #define BI_PHYMODE_NONE  0
134 #define BI_PHYMODE_ZMII  1
135 #define BI_PHYMODE_RGMII 2
136 #define BI_PHYMODE_GMII  3
137 #define BI_PHYMODE_RTBI  4
138 #define BI_PHYMODE_TBI   5
139 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
140     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
141     defined(CONFIG_405EX)
142 #define BI_PHYMODE_SMII  6
143 #define BI_PHYMODE_MII   7
144 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
145 #define BI_PHYMODE_RMII  8
146 #endif
147 #endif
148
149 #if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
150     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
151     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
152     defined(CONFIG_405EX)
153 #define SDR0_MFR_ETH_CLK_SEL_V(n)       ((0x01<<27) / (n+1))
154 #endif
155
156 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
157 #define SDR0_ETH_CFG_CLK_SEL_V(n)       (0x01 << (8 + n))
158 #endif
159
160 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
161 #define MAL_RX_CHAN_MUL 8       /* 460EX/GT uses MAL channel 8 for EMAC1 */
162 #else
163 #define MAL_RX_CHAN_MUL 1
164 #endif
165
166 /*-----------------------------------------------------------------------------+
167  * Global variables. TX and RX descriptors and buffers.
168  *-----------------------------------------------------------------------------*/
169 /* IER globals */
170 static uint32_t mal_ier;
171
172 #if !defined(CONFIG_NET_MULTI)
173 struct eth_device *emac0_dev = NULL;
174 #endif
175
176 /*
177  * Get count of EMAC devices (doesn't have to be the max. possible number
178  * supported by the cpu)
179  *
180  * CONFIG_BOARD_EMAC_COUNT added so now a "dynamic" way to configure the
181  * EMAC count is possible. As it is needed for the Kilauea/Haleakala
182  * 405EX/405EXr eval board, using the same binary.
183  */
184 #if defined(CONFIG_BOARD_EMAC_COUNT)
185 #define LAST_EMAC_NUM   board_emac_count()
186 #else /* CONFIG_BOARD_EMAC_COUNT */
187 #if defined(CONFIG_HAS_ETH3)
188 #define LAST_EMAC_NUM   4
189 #elif defined(CONFIG_HAS_ETH2)
190 #define LAST_EMAC_NUM   3
191 #elif defined(CONFIG_HAS_ETH1)
192 #define LAST_EMAC_NUM   2
193 #else
194 #define LAST_EMAC_NUM   1
195 #endif
196 #endif /* CONFIG_BOARD_EMAC_COUNT */
197
198 /* normal boards start with EMAC0 */
199 #if !defined(CONFIG_EMAC_NR_START)
200 #define CONFIG_EMAC_NR_START    0
201 #endif
202
203 #if defined(CONFIG_405EX) || defined(CONFIG_440EPX)
204 #define ETH_IRQ_NUM(dev)        (VECNUM_ETH0 + ((dev)))
205 #else
206 #define ETH_IRQ_NUM(dev)        (VECNUM_ETH0 + ((dev) * 2))
207 #endif
208
209 #define MAL_RX_DESC_SIZE        2048
210 #define MAL_TX_DESC_SIZE        2048
211 #define MAL_ALLOC_SIZE          (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE)
212
213 /*-----------------------------------------------------------------------------+
214  * Prototypes and externals.
215  *-----------------------------------------------------------------------------*/
216 static void enet_rcv (struct eth_device *dev, unsigned long malisr);
217
218 int enetInt (struct eth_device *dev);
219 static void mal_err (struct eth_device *dev, unsigned long isr,
220                      unsigned long uic, unsigned long maldef,
221                      unsigned long mal_errr);
222 static void emac_err (struct eth_device *dev, unsigned long isr);
223
224 extern int phy_setup_aneg (char *devname, unsigned char addr);
225 extern int emac4xx_miiphy_read (char *devname, unsigned char addr,
226                 unsigned char reg, unsigned short *value);
227 extern int emac4xx_miiphy_write (char *devname, unsigned char addr,
228                 unsigned char reg, unsigned short value);
229
230 int board_emac_count(void);
231
232 static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p)
233 {
234 #if defined(CONFIG_440SPE) || \
235     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
236     defined(CONFIG_405EX)
237         u32 val;
238
239         mfsdr(sdr_mfr, val);
240         val |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
241         mtsdr(sdr_mfr, val);
242 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
243         u32 val;
244
245         mfsdr(SDR0_ETH_CFG, val);
246         val |= SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
247         mtsdr(SDR0_ETH_CFG, val);
248 #endif
249 }
250
251 static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p)
252 {
253 #if defined(CONFIG_440SPE) || \
254     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
255     defined(CONFIG_405EX)
256         u32 val;
257
258         mfsdr(sdr_mfr, val);
259         val &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
260         mtsdr(sdr_mfr, val);
261 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
262         u32 val;
263
264         mfsdr(SDR0_ETH_CFG, val);
265         val &= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
266         mtsdr(SDR0_ETH_CFG, val);
267 #endif
268 }
269
270 /*-----------------------------------------------------------------------------+
271 | ppc_4xx_eth_halt
272 | Disable MAL channel, and EMACn
273 +-----------------------------------------------------------------------------*/
274 static void ppc_4xx_eth_halt (struct eth_device *dev)
275 {
276         EMAC_4XX_HW_PST hw_p = dev->priv;
277         u32 val = 10000;
278
279         out_be32((void *)EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
280
281         /* 1st reset MAL channel */
282         /* Note: writing a 0 to a channel has no effect */
283 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
284         mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
285 #else
286         mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
287 #endif
288         mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
289
290         /* wait for reset */
291         while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
292                 udelay (1000);  /* Delay 1 MS so as not to hammer the register */
293                 val--;
294                 if (val == 0)
295                         break;
296         }
297
298         /* provide clocks for EMAC internal loopback  */
299         emac_loopback_enable(hw_p);
300
301         /* EMAC RESET */
302         out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
303
304         /* remove clocks for EMAC internal loopback  */
305         emac_loopback_disable(hw_p);
306
307 #ifndef CONFIG_NETCONSOLE
308         hw_p->print_speed = 1;  /* print speed message again next time */
309 #endif
310
311 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
312         /* don't bypass the TAHOE0/TAHOE1 cores for Linux */
313         mfsdr(SDR0_ETH_CFG, val);
314         val &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
315         mtsdr(SDR0_ETH_CFG, val);
316 #endif
317
318         return;
319 }
320
321 #if defined (CONFIG_440GX)
322 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
323 {
324         unsigned long pfc1;
325         unsigned long zmiifer;
326         unsigned long rmiifer;
327
328         mfsdr(sdr_pfc1, pfc1);
329         pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
330
331         zmiifer = 0;
332         rmiifer = 0;
333
334         switch (pfc1) {
335         case 1:
336                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
337                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
338                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
339                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
340                 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
341                 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
342                 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
343                 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
344                 break;
345         case 2:
346                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
347                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
348                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
349                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
350                 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
351                 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
352                 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
353                 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
354                 break;
355         case 3:
356                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
357                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
358                 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
359                 bis->bi_phymode[1] = BI_PHYMODE_NONE;
360                 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
361                 bis->bi_phymode[3] = BI_PHYMODE_NONE;
362                 break;
363         case 4:
364                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
365                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
366                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
367                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
368                 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
369                 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
370                 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
371                 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
372                 break;
373         case 5:
374                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
375                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
376                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
377                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
378                 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
379                 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
380                 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
381                 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
382                 break;
383         case 6:
384                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
385                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
386                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
387                 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
388                 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
389                 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
390                 break;
391         case 0:
392         default:
393                 zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
394                 rmiifer = 0x0;
395                 bis->bi_phymode[0] = BI_PHYMODE_ZMII;
396                 bis->bi_phymode[1] = BI_PHYMODE_ZMII;
397                 bis->bi_phymode[2] = BI_PHYMODE_ZMII;
398                 bis->bi_phymode[3] = BI_PHYMODE_ZMII;
399                 break;
400         }
401
402         /* Ensure we setup mdio for this devnum and ONLY this devnum */
403         zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
404
405         out_be32((void *)ZMII_FER, zmiifer);
406         out_be32((void *)RGMII_FER, rmiifer);
407
408         return ((int)pfc1);
409 }
410 #endif  /* CONFIG_440_GX */
411
412 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
413 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
414 {
415         unsigned long zmiifer=0x0;
416         unsigned long pfc1;
417
418         mfsdr(sdr_pfc1, pfc1);
419         pfc1 &= SDR0_PFC1_SELECT_MASK;
420
421         switch (pfc1) {
422         case SDR0_PFC1_SELECT_CONFIG_2:
423                 /* 1 x GMII port */
424                 out_be32((void *)ZMII_FER, 0x00);
425                 out_be32((void *)RGMII_FER, 0x00000037);
426                 bis->bi_phymode[0] = BI_PHYMODE_GMII;
427                 bis->bi_phymode[1] = BI_PHYMODE_NONE;
428                 break;
429         case SDR0_PFC1_SELECT_CONFIG_4:
430                 /* 2 x RGMII ports */
431                 out_be32((void *)ZMII_FER, 0x00);
432                 out_be32((void *)RGMII_FER, 0x00000055);
433                 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
434                 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
435                 break;
436         case SDR0_PFC1_SELECT_CONFIG_6:
437                 /* 2 x SMII ports */
438                 out_be32((void *)ZMII_FER,
439                          ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
440                          ((ZMII_FER_SMII) << ZMII_FER_V(1)));
441                 out_be32((void *)RGMII_FER, 0x00000000);
442                 bis->bi_phymode[0] = BI_PHYMODE_SMII;
443                 bis->bi_phymode[1] = BI_PHYMODE_SMII;
444                 break;
445         case SDR0_PFC1_SELECT_CONFIG_1_2:
446                 /* only 1 x MII supported */
447                 out_be32((void *)ZMII_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
448                 out_be32((void *)RGMII_FER, 0x00000000);
449                 bis->bi_phymode[0] = BI_PHYMODE_MII;
450                 bis->bi_phymode[1] = BI_PHYMODE_NONE;
451                 break;
452         default:
453                 break;
454         }
455
456         /* Ensure we setup mdio for this devnum and ONLY this devnum */
457         zmiifer = in_be32((void *)ZMII_FER);
458         zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
459         out_be32((void *)ZMII_FER, zmiifer);
460
461         return ((int)0x0);
462 }
463 #endif  /* CONFIG_440EPX */
464
465 #if defined(CONFIG_405EX)
466 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
467 {
468         u32 gmiifer = 0;
469
470         /*
471          * Right now only 2*RGMII is supported. Please extend when needed.
472          * sr - 2007-09-19
473          */
474         switch (1) {
475         case 1:
476                 /* 2 x RGMII ports */
477                 out_be32((void *)RGMII_FER, 0x00000055);
478                 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
479                 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
480                 break;
481         case 2:
482                 /* 2 x SMII ports */
483                 break;
484         default:
485                 break;
486         }
487
488         /* Ensure we setup mdio for this devnum and ONLY this devnum */
489         gmiifer = in_be32((void *)RGMII_FER);
490         gmiifer |= (1 << (19-devnum));
491         out_be32((void *)RGMII_FER, gmiifer);
492
493         return ((int)0x0);
494 }
495 #endif  /* CONFIG_405EX */
496
497 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
498 int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
499 {
500         u32 eth_cfg;
501         u32 zmiifer;            /* ZMII0_FER reg. */
502         u32 rmiifer;            /* RGMII0_FER reg. Bridge 0 */
503         u32 rmiifer1;           /* RGMII0_FER reg. Bridge 1 */
504         int mode;
505
506         zmiifer  = 0;
507         rmiifer  = 0;
508         rmiifer1 = 0;
509
510 #if defined(CONFIG_460EX)
511         mode = 9;
512 #else
513         mode = 10;
514 #endif
515
516         /* TODO:
517          * NOTE: 460GT has 2 RGMII bridge cores:
518          *              emac0 ------ RGMII0_BASE
519          *                         |
520          *              emac1 -----+
521          *
522          *              emac2 ------ RGMII1_BASE
523          *                         |
524          *              emac3 -----+
525          *
526          *      460EX has 1 RGMII bridge core:
527          *      and RGMII1_BASE is disabled
528          *              emac0 ------ RGMII0_BASE
529          *                         |
530          *              emac1 -----+
531          */
532
533         /*
534          * Right now only 2*RGMII is supported. Please extend when needed.
535          * sr - 2008-02-19
536          */
537         switch (mode) {
538         case 1:
539                 /* 1 MII - 460EX */
540                 /* GMC0 EMAC4_0, ZMII Bridge */
541                 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
542                 bis->bi_phymode[0] = BI_PHYMODE_MII;
543                 bis->bi_phymode[1] = BI_PHYMODE_NONE;
544                 bis->bi_phymode[2] = BI_PHYMODE_NONE;
545                 bis->bi_phymode[3] = BI_PHYMODE_NONE;
546                 break;
547         case 2:
548                 /* 2 MII - 460GT */
549                 /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */
550                 zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
551                 zmiifer |= ZMII_FER_MII << ZMII_FER_V(2);
552                 bis->bi_phymode[0] = BI_PHYMODE_MII;
553                 bis->bi_phymode[1] = BI_PHYMODE_NONE;
554                 bis->bi_phymode[2] = BI_PHYMODE_MII;
555                 bis->bi_phymode[3] = BI_PHYMODE_NONE;
556                 break;
557         case 3:
558                 /* 2 RMII - 460EX */
559                 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
560                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
561                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
562                 bis->bi_phymode[0] = BI_PHYMODE_RMII;
563                 bis->bi_phymode[1] = BI_PHYMODE_RMII;
564                 bis->bi_phymode[2] = BI_PHYMODE_NONE;
565                 bis->bi_phymode[3] = BI_PHYMODE_NONE;
566                 break;
567         case 4:
568                 /* 4 RMII - 460GT */
569                 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */
570                 /* ZMII Bridge */
571                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
572                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
573                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
574                 zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
575                 bis->bi_phymode[0] = BI_PHYMODE_RMII;
576                 bis->bi_phymode[1] = BI_PHYMODE_RMII;
577                 bis->bi_phymode[2] = BI_PHYMODE_RMII;
578                 bis->bi_phymode[3] = BI_PHYMODE_RMII;
579                 break;
580         case 5:
581                 /* 2 SMII - 460EX */
582                 /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
583                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
584                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
585                 bis->bi_phymode[0] = BI_PHYMODE_SMII;
586                 bis->bi_phymode[1] = BI_PHYMODE_SMII;
587                 bis->bi_phymode[2] = BI_PHYMODE_NONE;
588                 bis->bi_phymode[3] = BI_PHYMODE_NONE;
589                 break;
590         case 6:
591                 /* 4 SMII - 460GT */
592                 /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */
593                 /* ZMII Bridge */
594                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
595                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
596                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
597                 zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
598                 bis->bi_phymode[0] = BI_PHYMODE_SMII;
599                 bis->bi_phymode[1] = BI_PHYMODE_SMII;
600                 bis->bi_phymode[2] = BI_PHYMODE_SMII;
601                 bis->bi_phymode[3] = BI_PHYMODE_SMII;
602                 break;
603         case 7:
604                 /* This is the default mode that we want for board bringup - Maple */
605                 /* 1 GMII - 460EX */
606                 /* GMC0 EMAC4_0, RGMII Bridge 0 */
607                 rmiifer |= RGMII_FER_MDIO(0);
608
609                 if (devnum == 0) {
610                         rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
611                         bis->bi_phymode[0] = BI_PHYMODE_GMII;
612                         bis->bi_phymode[1] = BI_PHYMODE_NONE;
613                         bis->bi_phymode[2] = BI_PHYMODE_NONE;
614                         bis->bi_phymode[3] = BI_PHYMODE_NONE;
615                 } else {
616                         rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3); /* CH1CFG - EMAC1 */
617                         bis->bi_phymode[0] = BI_PHYMODE_NONE;
618                         bis->bi_phymode[1] = BI_PHYMODE_GMII;
619                         bis->bi_phymode[2] = BI_PHYMODE_NONE;
620                         bis->bi_phymode[3] = BI_PHYMODE_NONE;
621                 }
622                 break;
623         case 8:
624                 /* 2 GMII - 460GT */
625                 /* GMC0 EMAC4_0, RGMII Bridge 0 */
626                 /* GMC1 EMAC4_2, RGMII Bridge 1 */
627                 rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2);    /* CH0CFG - EMAC0 */
628                 rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2);   /* CH0CFG - EMAC2 */
629                 rmiifer |= RGMII_FER_MDIO(0);                   /* enable MDIO - EMAC0 */
630                 rmiifer1 |= RGMII_FER_MDIO(0);                  /* enable MDIO - EMAC2 */
631
632                 bis->bi_phymode[0] = BI_PHYMODE_GMII;
633                 bis->bi_phymode[1] = BI_PHYMODE_NONE;
634                 bis->bi_phymode[2] = BI_PHYMODE_GMII;
635                 bis->bi_phymode[3] = BI_PHYMODE_NONE;
636                 break;
637         case 9:
638                 /* 2 RGMII - 460EX */
639                 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
640                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
641                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
642                 rmiifer |= RGMII_FER_MDIO(0);                   /* enable MDIO - EMAC0 */
643
644                 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
645                 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
646                 bis->bi_phymode[2] = BI_PHYMODE_NONE;
647                 bis->bi_phymode[3] = BI_PHYMODE_NONE;
648                 break;
649         case 10:
650                 /* 4 RGMII - 460GT */
651                 /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
652                 /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */
653                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
654                 rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
655                 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2);
656                 rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3);
657                 bis->bi_phymode[0] = BI_PHYMODE_RGMII;
658                 bis->bi_phymode[1] = BI_PHYMODE_RGMII;
659                 bis->bi_phymode[2] = BI_PHYMODE_RGMII;
660                 bis->bi_phymode[3] = BI_PHYMODE_RGMII;
661                 break;
662         default:
663                 break;
664         }
665
666         /* Set EMAC for MDIO */
667         mfsdr(SDR0_ETH_CFG, eth_cfg);
668         eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
669         mtsdr(SDR0_ETH_CFG, eth_cfg);
670
671         out_be32((void *)RGMII_FER, rmiifer);
672 #if defined(CONFIG_460GT)
673         out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1);
674 #endif
675
676         /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
677         mfsdr(SDR0_ETH_CFG, eth_cfg);
678         eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
679         mtsdr(SDR0_ETH_CFG, eth_cfg);
680
681         return 0;
682 }
683 #endif /* CONFIG_460EX || CONFIG_460GT */
684
685 static inline void *malloc_aligned(u32 size, u32 align)
686 {
687         return (void *)(((u32)malloc(size + align) + align - 1) &
688                         ~(align - 1));
689 }
690
691 static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
692 {
693         int i;
694         unsigned long reg = 0;
695         unsigned long msr;
696         unsigned long speed;
697         unsigned long duplex;
698         unsigned long failsafe;
699         unsigned mode_reg;
700         unsigned short devnum;
701         unsigned short reg_short;
702 #if defined(CONFIG_440GX) || \
703     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
704     defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
705     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
706     defined(CONFIG_405EX)
707         sys_info_t sysinfo;
708 #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
709     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
710     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
711     defined(CONFIG_405EX)
712         int ethgroup = -1;
713 #endif
714 #endif
715         u32 bd_cached;
716         u32 bd_uncached = 0;
717 #ifdef CONFIG_4xx_DCACHE
718         static u32 last_used_ea = 0;
719 #endif
720 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
721     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
722     defined(CONFIG_405EX)
723         int rgmii_channel;
724 #endif
725
726         EMAC_4XX_HW_PST hw_p = dev->priv;
727
728         /* before doing anything, figure out if we have a MAC address */
729         /* if not, bail */
730         if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
731                 printf("ERROR: ethaddr not set!\n");
732                 return -1;
733         }
734
735 #if defined(CONFIG_440GX) || \
736     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
737     defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
738     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
739     defined(CONFIG_405EX)
740         /* Need to get the OPB frequency so we can access the PHY */
741         get_sys_info (&sysinfo);
742 #endif
743
744         msr = mfmsr ();
745         mtmsr (msr & ~(MSR_EE));        /* disable interrupts */
746
747         devnum = hw_p->devnum;
748
749 #ifdef INFO_4XX_ENET
750         /* AS.HARNOIS
751          * We should have :
752          * hw_p->stats.pkts_handled <=  hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
753          * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
754          * is possible that new packets (without relationship with
755          * current transfer) have got the time to arrived before
756          * netloop calls eth_halt
757          */
758         printf ("About preceeding transfer (eth%d):\n"
759                 "- Sent packet number %d\n"
760                 "- Received packet number %d\n"
761                 "- Handled packet number %d\n",
762                 hw_p->devnum,
763                 hw_p->stats.pkts_tx,
764                 hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
765
766         hw_p->stats.pkts_tx = 0;
767         hw_p->stats.pkts_rx = 0;
768         hw_p->stats.pkts_handled = 0;
769         hw_p->print_speed = 1;  /* print speed message again next time */
770 #endif
771
772         hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
773         hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
774
775         hw_p->rx_slot = 0;      /* MAL Receive Slot */
776         hw_p->rx_i_index = 0;   /* Receive Interrupt Queue Index */
777         hw_p->rx_u_index = 0;   /* Receive User Queue Index */
778
779         hw_p->tx_slot = 0;      /* MAL Transmit Slot */
780         hw_p->tx_i_index = 0;   /* Transmit Interrupt Queue Index */
781         hw_p->tx_u_index = 0;   /* Transmit User Queue Index */
782
783 #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
784         /* set RMII mode */
785         /* NOTE: 440GX spec states that mode is mutually exclusive */
786         /* NOTE: Therefore, disable all other EMACS, since we handle */
787         /* NOTE: only one emac at a time */
788         reg = 0;
789         out_be32((void *)ZMII_FER, 0);
790         udelay (100);
791
792 #if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
793         out_be32((void *)ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
794 #elif defined(CONFIG_440GX) || \
795     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
796     defined(CONFIG_460EX) || defined(CONFIG_460GT)
797         ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
798 #endif
799
800         out_be32((void *)ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
801 #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
802 #if defined(CONFIG_405EX)
803         ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
804 #endif
805
806         sync();
807
808         /* provide clocks for EMAC internal loopback  */
809         emac_loopback_enable(hw_p);
810
811         /* EMAC RESET */
812         out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
813
814         /* remove clocks for EMAC internal loopback  */
815         emac_loopback_disable(hw_p);
816
817         failsafe = 1000;
818         while ((in_be32((void *)EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
819                 udelay (1000);
820                 failsafe--;
821         }
822         if (failsafe <= 0)
823                 printf("\nProblem resetting EMAC!\n");
824
825 #if defined(CONFIG_440GX) || \
826     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
827     defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
828     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
829     defined(CONFIG_405EX)
830         /* Whack the M1 register */
831         mode_reg = 0x0;
832         mode_reg &= ~0x00000038;
833         if (sysinfo.freqOPB <= 50000000);
834         else if (sysinfo.freqOPB <= 66666667)
835                 mode_reg |= EMAC_M1_OBCI_66;
836         else if (sysinfo.freqOPB <= 83333333)
837                 mode_reg |= EMAC_M1_OBCI_83;
838         else if (sysinfo.freqOPB <= 100000000)
839                 mode_reg |= EMAC_M1_OBCI_100;
840         else
841                 mode_reg |= EMAC_M1_OBCI_GT100;
842
843         out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
844 #endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
845
846         /* wait for PHY to complete auto negotiation */
847         reg_short = 0;
848 #ifndef CONFIG_CS8952_PHY
849         switch (devnum) {
850         case 0:
851                 reg = CONFIG_PHY_ADDR;
852                 break;
853 #if defined (CONFIG_PHY1_ADDR)
854         case 1:
855                 reg = CONFIG_PHY1_ADDR;
856                 break;
857 #endif
858 #if defined (CONFIG_PHY2_ADDR)
859         case 2:
860                 reg = CONFIG_PHY2_ADDR;
861                 break;
862 #endif
863 #if defined (CONFIG_PHY3_ADDR)
864         case 3:
865                 reg = CONFIG_PHY3_ADDR;
866                 break;
867 #endif
868         default:
869                 reg = CONFIG_PHY_ADDR;
870                 break;
871         }
872
873         bis->bi_phynum[devnum] = reg;
874
875 #if defined(CONFIG_PHY_RESET)
876         /*
877          * Reset the phy, only if its the first time through
878          * otherwise, just check the speeds & feeds
879          */
880         if (hw_p->first_init == 0) {
881 #if defined(CONFIG_M88E1111_PHY)
882                 miiphy_write (dev->name, reg, 0x14, 0x0ce3);
883                 miiphy_write (dev->name, reg, 0x18, 0x4101);
884                 miiphy_write (dev->name, reg, 0x09, 0x0e00);
885                 miiphy_write (dev->name, reg, 0x04, 0x01e1);
886 #endif
887                 miiphy_reset (dev->name, reg);
888
889 #if defined(CONFIG_440GX) || \
890     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
891     defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
892     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
893     defined(CONFIG_405EX)
894
895 #if defined(CONFIG_CIS8201_PHY)
896                 /*
897                  * Cicada 8201 PHY needs to have an extended register whacked
898                  * for RGMII mode.
899                  */
900                 if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
901 #if defined(CONFIG_CIS8201_SHORT_ETCH)
902                         miiphy_write (dev->name, reg, 23, 0x1300);
903 #else
904                         miiphy_write (dev->name, reg, 23, 0x1000);
905 #endif
906                         /*
907                          * Vitesse VSC8201/Cicada CIS8201 errata:
908                          * Interoperability problem with Intel 82547EI phys
909                          * This work around (provided by Vitesse) changes
910                          * the default timer convergence from 8ms to 12ms
911                          */
912                         miiphy_write (dev->name, reg, 0x1f, 0x2a30);
913                         miiphy_write (dev->name, reg, 0x08, 0x0200);
914                         miiphy_write (dev->name, reg, 0x1f, 0x52b5);
915                         miiphy_write (dev->name, reg, 0x02, 0x0004);
916                         miiphy_write (dev->name, reg, 0x01, 0x0671);
917                         miiphy_write (dev->name, reg, 0x00, 0x8fae);
918                         miiphy_write (dev->name, reg, 0x1f, 0x2a30);
919                         miiphy_write (dev->name, reg, 0x08, 0x0000);
920                         miiphy_write (dev->name, reg, 0x1f, 0x0000);
921                         /* end Vitesse/Cicada errata */
922                 }
923 #endif
924
925 #if defined(CONFIG_ET1011C_PHY)
926                 /*
927                  * Agere ET1011c PHY needs to have an extended register whacked
928                  * for RGMII mode.
929                  */
930                 if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
931                         miiphy_read (dev->name, reg, 0x16, &reg_short);
932                         reg_short &= ~(0x7);
933                         reg_short |= 0x6;       /* RGMII DLL Delay*/
934                         miiphy_write (dev->name, reg, 0x16, reg_short);
935
936                         miiphy_read (dev->name, reg, 0x17, &reg_short);
937                         reg_short &= ~(0x40);
938                         miiphy_write (dev->name, reg, 0x17, reg_short);
939
940                         miiphy_write(dev->name, reg, 0x1c, 0x74f0);
941                 }
942 #endif
943
944 #endif
945                 /* Start/Restart autonegotiation */
946                 phy_setup_aneg (dev->name, reg);
947                 udelay (1000);
948         }
949 #endif /* defined(CONFIG_PHY_RESET) */
950
951         miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
952
953         /*
954          * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
955          */
956         if ((reg_short & PHY_BMSR_AUTN_ABLE)
957             && !(reg_short & PHY_BMSR_AUTN_COMP)) {
958                 puts ("Waiting for PHY auto negotiation to complete");
959                 i = 0;
960                 while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
961                         /*
962                          * Timeout reached ?
963                          */
964                         if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
965                                 puts (" TIMEOUT !\n");
966                                 break;
967                         }
968
969                         if ((i++ % 1000) == 0) {
970                                 putc ('.');
971                         }
972                         udelay (1000);  /* 1 ms */
973                         miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
974
975                 }
976                 puts (" done\n");
977                 udelay (500000);        /* another 500 ms (results in faster booting) */
978         }
979 #endif /* #ifndef CONFIG_CS8952_PHY */
980
981         speed = miiphy_speed (dev->name, reg);
982         duplex = miiphy_duplex (dev->name, reg);
983
984         if (hw_p->print_speed) {
985                 hw_p->print_speed = 0;
986                 printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
987                         (int) speed, (duplex == HALF) ? "HALF" : "FULL",
988                         hw_p->devnum);
989         }
990
991 #if defined(CONFIG_440) && \
992     !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
993     !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
994     !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
995 #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
996         mfsdr(sdr_mfr, reg);
997         if (speed == 100) {
998                 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
999         } else {
1000                 reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
1001         }
1002         mtsdr(sdr_mfr, reg);
1003 #endif
1004
1005         /* Set ZMII/RGMII speed according to the phy link speed */
1006         reg = in_be32((void *)ZMII_SSR);
1007         if ( (speed == 100) || (speed == 1000) )
1008                 out_be32((void *)ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
1009         else
1010                 out_be32((void *)ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
1011
1012         if ((devnum == 2) || (devnum == 3)) {
1013                 if (speed == 1000)
1014                         reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
1015                 else if (speed == 100)
1016                         reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
1017                 else if (speed == 10)
1018                         reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
1019                 else {
1020                         printf("Error in RGMII Speed\n");
1021                         return -1;
1022                 }
1023                 out_be32((void *)RGMII_SSR, reg);
1024         }
1025 #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
1026
1027 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1028     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1029     defined(CONFIG_405EX)
1030         if (devnum >= 2)
1031                 rgmii_channel = devnum - 2;
1032         else
1033                 rgmii_channel = devnum;
1034
1035         if (speed == 1000)
1036                 reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V(rgmii_channel));
1037         else if (speed == 100)
1038                 reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V(rgmii_channel));
1039         else if (speed == 10)
1040                 reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V(rgmii_channel));
1041         else {
1042                 printf("Error in RGMII Speed\n");
1043                 return -1;
1044         }
1045         out_be32((void *)RGMII_SSR, reg);
1046 #if defined(CONFIG_460GT)
1047         if ((devnum == 2) || (devnum == 3))
1048                 out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
1049 #endif
1050 #endif
1051
1052         /* set the Mal configuration reg */
1053 #if defined(CONFIG_440GX) || \
1054     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1055     defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
1056     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1057     defined(CONFIG_405EX)
1058         mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
1059                MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
1060 #else
1061         mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
1062         /* Errata 1.12: MAL_1 -- Disable MAL bursting */
1063         if (get_pvr() == PVR_440GP_RB) {
1064                 mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
1065         }
1066 #endif
1067
1068         /*
1069          * Malloc MAL buffer desciptors, make sure they are
1070          * aligned on cache line boundary size
1071          * (401/403/IOP480 = 16, 405 = 32)
1072          * and doesn't cross cache block boundaries.
1073          */
1074         if (hw_p->first_init == 0) {
1075                 debug("*** Allocating descriptor memory ***\n");
1076
1077                 bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
1078                 if (!bd_cached) {
1079                         printf("%s: Error allocating MAL descriptor buffers!\n");
1080                         return -1;
1081                 }
1082
1083 #ifdef CONFIG_4xx_DCACHE
1084                 flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
1085                 if (!last_used_ea)
1086                         bd_uncached = bis->bi_memsize;
1087                 else
1088                         bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
1089
1090                 last_used_ea = bd_uncached;
1091                 program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
1092                             TLB_WORD2_I_ENABLE);
1093 #else
1094                 bd_uncached = bd_cached;
1095 #endif
1096                 hw_p->tx_phys = bd_cached;
1097                 hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
1098                 hw_p->tx = (mal_desc_t *)(bd_uncached);
1099                 hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
1100                 debug("hw_p->tx=%08x, hw_p->rx=%08x\n", hw_p->tx, hw_p->rx);
1101         }
1102
1103         for (i = 0; i < NUM_TX_BUFF; i++) {
1104                 hw_p->tx[i].ctrl = 0;
1105                 hw_p->tx[i].data_len = 0;
1106                 if (hw_p->first_init == 0)
1107                         hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
1108                                                          L1_CACHE_BYTES);
1109                 hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
1110                 if ((NUM_TX_BUFF - 1) == i)
1111                         hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
1112                 hw_p->tx_run[i] = -1;
1113                 debug("TX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->tx[i].data_ptr);
1114         }
1115
1116         for (i = 0; i < NUM_RX_BUFF; i++) {
1117                 hw_p->rx[i].ctrl = 0;
1118                 hw_p->rx[i].data_len = 0;
1119                 hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
1120                 if ((NUM_RX_BUFF - 1) == i)
1121                         hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
1122                 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
1123                 hw_p->rx_ready[i] = -1;
1124                 debug("RX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->rx[i].data_ptr);
1125         }
1126
1127         reg = 0x00000000;
1128
1129         reg |= dev->enetaddr[0];        /* set high address */
1130         reg = reg << 8;
1131         reg |= dev->enetaddr[1];
1132
1133         out_be32((void *)EMAC_IAH + hw_p->hw_addr, reg);
1134
1135         reg = 0x00000000;
1136         reg |= dev->enetaddr[2];        /* set low address  */
1137         reg = reg << 8;
1138         reg |= dev->enetaddr[3];
1139         reg = reg << 8;
1140         reg |= dev->enetaddr[4];
1141         reg = reg << 8;
1142         reg |= dev->enetaddr[5];
1143
1144         out_be32((void *)EMAC_IAL + hw_p->hw_addr, reg);
1145
1146         switch (devnum) {
1147         case 1:
1148                 /* setup MAL tx & rx channel pointers */
1149 #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
1150                 mtdcr (maltxctp2r, hw_p->tx_phys);
1151 #else
1152                 mtdcr (maltxctp1r, hw_p->tx_phys);
1153 #endif
1154 #if defined(CONFIG_440)
1155                 mtdcr (maltxbattr, 0x0);
1156                 mtdcr (malrxbattr, 0x0);
1157 #endif
1158
1159 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
1160                 mtdcr (malrxctp8r, hw_p->rx_phys);
1161                 /* set RX buffer size */
1162                 mtdcr (malrcbs8, ENET_MAX_MTU_ALIGNED / 16);
1163 #else
1164                 mtdcr (malrxctp1r, hw_p->rx_phys);
1165                 /* set RX buffer size */
1166                 mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
1167 #endif
1168                 break;
1169 #if defined (CONFIG_440GX)
1170         case 2:
1171                 /* setup MAL tx & rx channel pointers */
1172                 mtdcr (maltxbattr, 0x0);
1173                 mtdcr (malrxbattr, 0x0);
1174                 mtdcr (maltxctp2r, hw_p->tx_phys);
1175                 mtdcr (malrxctp2r, hw_p->rx_phys);
1176                 /* set RX buffer size */
1177                 mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
1178                 break;
1179         case 3:
1180                 /* setup MAL tx & rx channel pointers */
1181                 mtdcr (maltxbattr, 0x0);
1182                 mtdcr (maltxctp3r, hw_p->tx_phys);
1183                 mtdcr (malrxbattr, 0x0);
1184                 mtdcr (malrxctp3r, hw_p->rx_phys);
1185                 /* set RX buffer size */
1186                 mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
1187                 break;
1188 #endif /* CONFIG_440GX */
1189 #if defined (CONFIG_460GT)
1190         case 2:
1191                 /* setup MAL tx & rx channel pointers */
1192                 mtdcr (maltxbattr, 0x0);
1193                 mtdcr (malrxbattr, 0x0);
1194                 mtdcr (maltxctp2r, hw_p->tx_phys);
1195                 mtdcr (malrxctp16r, hw_p->rx_phys);
1196                 /* set RX buffer size */
1197                 mtdcr (malrcbs16, ENET_MAX_MTU_ALIGNED / 16);
1198                 break;
1199         case 3:
1200                 /* setup MAL tx & rx channel pointers */
1201                 mtdcr (maltxbattr, 0x0);
1202                 mtdcr (malrxbattr, 0x0);
1203                 mtdcr (maltxctp3r, hw_p->tx_phys);
1204                 mtdcr (malrxctp24r, hw_p->rx_phys);
1205                 /* set RX buffer size */
1206                 mtdcr (malrcbs24, ENET_MAX_MTU_ALIGNED / 16);
1207                 break;
1208 #endif /* CONFIG_460GT */
1209         case 0:
1210         default:
1211                 /* setup MAL tx & rx channel pointers */
1212 #if defined(CONFIG_440)
1213                 mtdcr (maltxbattr, 0x0);
1214                 mtdcr (malrxbattr, 0x0);
1215 #endif
1216                 mtdcr (maltxctp0r, hw_p->tx_phys);
1217                 mtdcr (malrxctp0r, hw_p->rx_phys);
1218                 /* set RX buffer size */
1219                 mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
1220                 break;
1221         }
1222
1223         /* Enable MAL transmit and receive channels */
1224 #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
1225         mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
1226 #else
1227         mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
1228 #endif
1229         mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
1230
1231         /* set transmit enable & receive enable */
1232         out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
1233
1234         mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr);
1235
1236         /* set rx-/tx-fifo size */
1237         mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
1238
1239         /* set speed */
1240         if (speed == _1000BASET) {
1241 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1242     defined(CONFIG_440SP) || defined(CONFIG_440SPE)
1243                 unsigned long pfc1;
1244
1245                 mfsdr (sdr_pfc1, pfc1);
1246                 pfc1 |= SDR0_PFC1_EM_1000;
1247                 mtsdr (sdr_pfc1, pfc1);
1248 #endif
1249                 mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
1250         } else if (speed == _100BASET)
1251                 mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
1252         else
1253                 mode_reg = mode_reg & ~0x00C00000;      /* 10 MBPS */
1254         if (duplex == FULL)
1255                 mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
1256
1257         out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg);
1258
1259         /* Enable broadcast and indvidual address */
1260         /* TBS: enabling runts as some misbehaved nics will send runts */
1261         out_be32((void *)EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
1262
1263         /* we probably need to set the tx mode1 reg? maybe at tx time */
1264
1265         /* set transmit request threshold register */
1266         out_be32((void *)EMAC_TRTR + hw_p->hw_addr, 0x18000000);        /* 256 byte threshold */
1267
1268         /* set receive  low/high water mark register */
1269 #if defined(CONFIG_440)
1270         /* 440s has a 64 byte burst length */
1271         out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
1272 #else
1273         /* 405s have a 16 byte burst length */
1274         out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
1275 #endif /* defined(CONFIG_440) */
1276         out_be32((void *)EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
1277
1278         /* Set fifo limit entry in tx mode 0 */
1279         out_be32((void *)EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
1280         /* Frame gap set */
1281         out_be32((void *)EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
1282
1283         /* Set EMAC IER */
1284         hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
1285         if (speed == _100BASET)
1286                 hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
1287
1288         out_be32((void *)EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
1289         out_be32((void *)EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
1290
1291         if (hw_p->first_init == 0) {
1292                 /*
1293                  * Connect interrupt service routines
1294                  */
1295                 irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
1296                                     (interrupt_handler_t *) enetInt, dev);
1297         }
1298
1299         mtmsr (msr);            /* enable interrupts again */
1300
1301         hw_p->bis = bis;
1302         hw_p->first_init = 1;
1303
1304         return 0;
1305 }
1306
1307
1308 static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
1309                               int len)
1310 {
1311         struct enet_frame *ef_ptr;
1312         ulong time_start, time_now;
1313         unsigned long temp_txm0;
1314         EMAC_4XX_HW_PST hw_p = dev->priv;
1315
1316         ef_ptr = (struct enet_frame *) ptr;
1317
1318         /*-----------------------------------------------------------------------+
1319          *  Copy in our address into the frame.
1320          *-----------------------------------------------------------------------*/
1321         (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
1322
1323         /*-----------------------------------------------------------------------+
1324          * If frame is too long or too short, modify length.
1325          *-----------------------------------------------------------------------*/
1326         /* TBS: where does the fragment go???? */
1327         if (len > ENET_MAX_MTU)
1328                 len = ENET_MAX_MTU;
1329
1330         /*   memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
1331         memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
1332         flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
1333
1334         /*-----------------------------------------------------------------------+
1335          * set TX Buffer busy, and send it
1336          *-----------------------------------------------------------------------*/
1337         hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
1338                                         EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
1339                 ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
1340         if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
1341                 hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
1342
1343         hw_p->tx[hw_p->tx_slot].data_len = (short) len;
1344         hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
1345
1346         sync();
1347
1348         out_be32((void *)EMAC_TXM0 + hw_p->hw_addr,
1349                  in_be32((void *)EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
1350 #ifdef INFO_4XX_ENET
1351         hw_p->stats.pkts_tx++;
1352 #endif
1353
1354         /*-----------------------------------------------------------------------+
1355          * poll unitl the packet is sent and then make sure it is OK
1356          *-----------------------------------------------------------------------*/
1357         time_start = get_timer (0);
1358         while (1) {
1359                 temp_txm0 = in_be32((void *)EMAC_TXM0 + hw_p->hw_addr);
1360                 /* loop until either TINT turns on or 3 seconds elapse */
1361                 if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
1362                         /* transmit is done, so now check for errors
1363                          * If there is an error, an interrupt should
1364                          * happen when we return
1365                          */
1366                         time_now = get_timer (0);
1367                         if ((time_now - time_start) > 3000) {
1368                                 return (-1);
1369                         }
1370                 } else {
1371                         return (len);
1372                 }
1373         }
1374 }
1375
1376
1377 #if defined (CONFIG_440) || defined(CONFIG_405EX)
1378
1379 #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
1380 /*
1381  * Hack: On 440SP all enet irq sources are located on UIC1
1382  * Needs some cleanup. --sr
1383  */
1384 #define UIC0MSR         uic1msr
1385 #define UIC0SR          uic1sr
1386 #define UIC1MSR         uic1msr
1387 #define UIC1SR          uic1sr
1388 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
1389 /*
1390  * Hack: On 460EX/GT all enet irq sources are located on UIC2
1391  * Needs some cleanup. --ag
1392  */
1393 #define UIC0MSR         uic2msr
1394 #define UIC0SR          uic2sr
1395 #define UIC1MSR         uic2msr
1396 #define UIC1SR          uic2sr
1397 #else
1398 #define UIC0MSR         uic0msr
1399 #define UIC0SR          uic0sr
1400 #define UIC1MSR         uic1msr
1401 #define UIC1SR          uic1sr
1402 #endif
1403
1404 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1405     defined(CONFIG_405EX)
1406 #define UICMSR_ETHX     uic0msr
1407 #define UICSR_ETHX      uic0sr
1408 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
1409 #define UICMSR_ETHX     uic2msr
1410 #define UICSR_ETHX      uic2sr
1411 #else
1412 #define UICMSR_ETHX     uic1msr
1413 #define UICSR_ETHX      uic1sr
1414 #endif
1415
1416 int enetInt (struct eth_device *dev)
1417 {
1418         int serviced;
1419         int rc = -1;            /* default to not us */
1420         unsigned long mal_isr;
1421         unsigned long emac_isr = 0;
1422         unsigned long mal_rx_eob;
1423         unsigned long my_uic0msr, my_uic1msr;
1424         unsigned long my_uicmsr_ethx;
1425
1426 #if defined(CONFIG_440GX)
1427         unsigned long my_uic2msr;
1428 #endif
1429         EMAC_4XX_HW_PST hw_p;
1430
1431         /*
1432          * Because the mal is generic, we need to get the current
1433          * eth device
1434          */
1435 #if defined(CONFIG_NET_MULTI)
1436         dev = eth_get_dev();
1437 #else
1438         dev = emac0_dev;
1439 #endif
1440
1441         hw_p = dev->priv;
1442
1443         /* enter loop that stays in interrupt code until nothing to service */
1444         do {
1445                 serviced = 0;
1446
1447                 my_uic0msr = mfdcr (UIC0MSR);
1448                 my_uic1msr = mfdcr (UIC1MSR);
1449 #if defined(CONFIG_440GX)
1450                 my_uic2msr = mfdcr (uic2msr);
1451 #endif
1452                 my_uicmsr_ethx = mfdcr (UICMSR_ETHX);
1453
1454                 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
1455                     && !(my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))
1456                     && !(my_uicmsr_ethx & (UIC_ETH0 | UIC_ETH1))) {
1457                         /* not for us */
1458                         return (rc);
1459                 }
1460 #if defined (CONFIG_440GX)
1461                 if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
1462                     && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
1463                         /* not for us */
1464                         return (rc);
1465                 }
1466 #endif
1467                 /* get and clear controller status interrupts */
1468                 /* look at Mal and EMAC interrupts */
1469                 if ((my_uic0msr & (UIC_MRE | UIC_MTE))
1470                     || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1471                         /* we have a MAL interrupt */
1472                         mal_isr = mfdcr (malesr);
1473                         /* look for mal error */
1474                         if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
1475                                 mal_err (dev, mal_isr, my_uic1msr, MAL_UIC_DEF, MAL_UIC_ERR);
1476                                 serviced = 1;
1477                                 rc = 0;
1478                         }
1479                 }
1480
1481                 /* port by port dispatch of emac interrupts */
1482                 if (hw_p->devnum == 0) {
1483                         if (UIC_ETH0 & my_uicmsr_ethx) {        /* look for EMAC errors */
1484                                 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
1485                                 if ((hw_p->emac_ier & emac_isr) != 0) {
1486                                         emac_err (dev, emac_isr);
1487                                         serviced = 1;
1488                                         rc = 0;
1489                                 }
1490                         }
1491                         if ((hw_p->emac_ier & emac_isr)
1492                             || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1493                                 mtdcr (UIC0SR, UIC_MRE | UIC_MTE);      /* Clear */
1494                                 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE);   /* Clear */
1495                                 mtdcr (UICSR_ETHX, UIC_ETH0); /* Clear */
1496                                 return (rc);    /* we had errors so get out */
1497                         }
1498                 }
1499
1500 #if !defined(CONFIG_440SP)
1501                 if (hw_p->devnum == 1) {
1502                         if (UIC_ETH1 & my_uicmsr_ethx) {        /* look for EMAC errors */
1503                                 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
1504                                 if ((hw_p->emac_ier & emac_isr) != 0) {
1505                                         emac_err (dev, emac_isr);
1506                                         serviced = 1;
1507                                         rc = 0;
1508                                 }
1509                         }
1510                         if ((hw_p->emac_ier & emac_isr)
1511                             || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1512                                 mtdcr (UIC0SR, UIC_MRE | UIC_MTE);      /* Clear */
1513                                 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
1514                                 mtdcr (UICSR_ETHX, UIC_ETH1); /* Clear */
1515                                 return (rc);    /* we had errors so get out */
1516                         }
1517                 }
1518 #if defined (CONFIG_440GX)
1519                 if (hw_p->devnum == 2) {
1520                         if (UIC_ETH2 & my_uic2msr) {    /* look for EMAC errors */
1521                                 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
1522                                 if ((hw_p->emac_ier & emac_isr) != 0) {
1523                                         emac_err (dev, emac_isr);
1524                                         serviced = 1;
1525                                         rc = 0;
1526                                 }
1527                         }
1528                         if ((hw_p->emac_ier & emac_isr)
1529                             || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1530                                 mtdcr (UIC0SR, UIC_MRE | UIC_MTE);      /* Clear */
1531                                 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE);   /* Clear */
1532                                 mtdcr (uic2sr, UIC_ETH2);
1533                                 return (rc);    /* we had errors so get out */
1534                         }
1535                 }
1536
1537                 if (hw_p->devnum == 3) {
1538                         if (UIC_ETH3 & my_uic2msr) {    /* look for EMAC errors */
1539                                 emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
1540                                 if ((hw_p->emac_ier & emac_isr) != 0) {
1541                                         emac_err (dev, emac_isr);
1542                                         serviced = 1;
1543                                         rc = 0;
1544                                 }
1545                         }
1546                         if ((hw_p->emac_ier & emac_isr)
1547                             || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
1548                                 mtdcr (UIC0SR, UIC_MRE | UIC_MTE);      /* Clear */
1549                                 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE);   /* Clear */
1550                                 mtdcr (uic2sr, UIC_ETH3);
1551                                 return (rc);    /* we had errors so get out */
1552                         }
1553                 }
1554 #endif /* CONFIG_440GX */
1555 #endif /* !CONFIG_440SP */
1556
1557                 /* handle MAX TX EOB interrupt from a tx */
1558                 if (my_uic0msr & UIC_MTE) {
1559                         mal_rx_eob = mfdcr (maltxeobisr);
1560                         mtdcr (maltxeobisr, mal_rx_eob);
1561                         mtdcr (UIC0SR, UIC_MTE);
1562                 }
1563                 /* handle MAL RX EOB  interupt from a receive */
1564                 /* check for EOB on valid channels            */
1565                 if (my_uic0msr & UIC_MRE) {
1566                         mal_rx_eob = mfdcr (malrxeobisr);
1567                         if ((mal_rx_eob &
1568                              (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)))
1569                             != 0) { /* call emac routine for channel x */
1570                                 /* clear EOB
1571                                    mtdcr(malrxeobisr, mal_rx_eob); */
1572                                 enet_rcv (dev, emac_isr);
1573                                 /* indicate that we serviced an interrupt */
1574                                 serviced = 1;
1575                                 rc = 0;
1576                         }
1577                 }
1578
1579                 mtdcr (UIC0SR, UIC_MRE);        /* Clear */
1580                 mtdcr (UIC1SR, UIC_MS | UIC_MTDE | UIC_MRDE);   /* Clear */
1581                 switch (hw_p->devnum) {
1582                 case 0:
1583                         mtdcr (UICSR_ETHX, UIC_ETH0);
1584                         break;
1585                 case 1:
1586                         mtdcr (UICSR_ETHX, UIC_ETH1);
1587                         break;
1588 #if defined (CONFIG_440GX)
1589                 case 2:
1590                         mtdcr (uic2sr, UIC_ETH2);
1591                         break;
1592                 case 3:
1593                         mtdcr (uic2sr, UIC_ETH3);
1594                         break;
1595 #endif /* CONFIG_440GX */
1596                 default:
1597                         break;
1598                 }
1599         } while (serviced);
1600
1601         return (rc);
1602 }
1603
1604 #else /* CONFIG_440 */
1605
1606 int enetInt (struct eth_device *dev)
1607 {
1608         int serviced;
1609         int rc = -1;            /* default to not us */
1610         unsigned long mal_isr;
1611         unsigned long emac_isr = 0;
1612         unsigned long mal_rx_eob;
1613         unsigned long my_uicmsr;
1614
1615         EMAC_4XX_HW_PST hw_p;
1616
1617         /*
1618          * Because the mal is generic, we need to get the current
1619          * eth device
1620          */
1621 #if defined(CONFIG_NET_MULTI)
1622         dev = eth_get_dev();
1623 #else
1624         dev = emac0_dev;
1625 #endif
1626
1627         hw_p = dev->priv;
1628
1629         /* enter loop that stays in interrupt code until nothing to service */
1630         do {
1631                 serviced = 0;
1632
1633                 my_uicmsr = mfdcr (uicmsr);
1634
1635                 if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) {  /* not for us */
1636                         return (rc);
1637                 }
1638                 /* get and clear controller status interrupts */
1639                 /* look at Mal and EMAC interrupts */
1640                 if ((MAL_UIC_DEF & my_uicmsr) != 0) {   /* we have a MAL interrupt */
1641                         mal_isr = mfdcr (malesr);
1642                         /* look for mal error */
1643                         if ((my_uicmsr & MAL_UIC_ERR) != 0) {
1644                                 mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR);
1645                                 serviced = 1;
1646                                 rc = 0;
1647                         }
1648                 }
1649
1650                 /* port by port dispatch of emac interrupts */
1651
1652                 if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) {     /* look for EMAC errors */
1653                         emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr);
1654                         if ((hw_p->emac_ier & emac_isr) != 0) {
1655                                 emac_err (dev, emac_isr);
1656                                 serviced = 1;
1657                                 rc = 0;
1658                         }
1659                 }
1660                 if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) {
1661                         mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */
1662                         return (rc);            /* we had errors so get out */
1663                 }
1664
1665                 /* handle MAX TX EOB interrupt from a tx */
1666                 if (my_uicmsr & UIC_MAL_TXEOB) {
1667                         mal_rx_eob = mfdcr (maltxeobisr);
1668                         mtdcr (maltxeobisr, mal_rx_eob);
1669                         mtdcr (uicsr, UIC_MAL_TXEOB);
1670                 }
1671                 /* handle MAL RX EOB  interupt from a receive */
1672                 /* check for EOB on valid channels            */
1673                 if (my_uicmsr & UIC_MAL_RXEOB)
1674                 {
1675                         mal_rx_eob = mfdcr (malrxeobisr);
1676                         if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
1677                                 /* clear EOB
1678                                  mtdcr(malrxeobisr, mal_rx_eob); */
1679                                 enet_rcv (dev, emac_isr);
1680                                 /* indicate that we serviced an interrupt */
1681                                 serviced = 1;
1682                                 rc = 0;
1683                         }
1684                 }
1685                 mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1);  /* Clear */
1686 #if defined(CONFIG_405EZ)
1687                 mtsdr (sdricintstat, SDR_ICRX_STAT | SDR_ICTX0_STAT | SDR_ICTX1_STAT);
1688 #endif  /* defined(CONFIG_405EZ) */
1689         }
1690         while (serviced);
1691
1692         return (rc);
1693 }
1694
1695 #endif /* CONFIG_440 */
1696
1697 /*-----------------------------------------------------------------------------+
1698  *  MAL Error Routine
1699  *-----------------------------------------------------------------------------*/
1700 static void mal_err (struct eth_device *dev, unsigned long isr,
1701                      unsigned long uic, unsigned long maldef,
1702                      unsigned long mal_errr)
1703 {
1704         EMAC_4XX_HW_PST hw_p = dev->priv;
1705
1706         mtdcr (malesr, isr);    /* clear interrupt */
1707
1708         /* clear DE interrupt */
1709         mtdcr (maltxdeir, 0xC0000000);
1710         mtdcr (malrxdeir, 0x80000000);
1711
1712 #ifdef INFO_4XX_ENET
1713         printf ("\nMAL error occured.... ISR = %lx UIC = = %lx  MAL_DEF = %lx  MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
1714 #endif
1715
1716         eth_init (hw_p->bis);   /* start again... */
1717 }
1718
1719 /*-----------------------------------------------------------------------------+
1720  *  EMAC Error Routine
1721  *-----------------------------------------------------------------------------*/
1722 static void emac_err (struct eth_device *dev, unsigned long isr)
1723 {
1724         EMAC_4XX_HW_PST hw_p = dev->priv;
1725
1726         printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
1727         out_be32((void *)EMAC_ISR + hw_p->hw_addr, isr);
1728 }
1729
1730 /*-----------------------------------------------------------------------------+
1731  *  enet_rcv() handles the ethernet receive data
1732  *-----------------------------------------------------------------------------*/
1733 static void enet_rcv (struct eth_device *dev, unsigned long malisr)
1734 {
1735         struct enet_frame *ef_ptr;
1736         unsigned long data_len;
1737         unsigned long rx_eob_isr;
1738         EMAC_4XX_HW_PST hw_p = dev->priv;
1739
1740         int handled = 0;
1741         int i;
1742         int loop_count = 0;
1743
1744         rx_eob_isr = mfdcr (malrxeobisr);
1745         if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
1746                 /* clear EOB */
1747                 mtdcr (malrxeobisr, rx_eob_isr);
1748
1749                 /* EMAC RX done */
1750                 while (1) {     /* do all */
1751                         i = hw_p->rx_slot;
1752
1753                         if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
1754                             || (loop_count >= NUM_RX_BUFF))
1755                                 break;
1756
1757                         loop_count++;
1758                         handled++;
1759                         data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff;       /* Get len */
1760                         if (data_len) {
1761                                 if (data_len > ENET_MAX_MTU)    /* Check len */
1762                                         data_len = 0;
1763                                 else {
1764                                         if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) {        /* Check Errors */
1765                                                 data_len = 0;
1766                                                 hw_p->stats.rx_err_log[hw_p->
1767                                                                        rx_err_index]
1768                                                         = hw_p->rx[i].ctrl;
1769                                                 hw_p->rx_err_index++;
1770                                                 if (hw_p->rx_err_index ==
1771                                                     MAX_ERR_LOG)
1772                                                         hw_p->rx_err_index =
1773                                                                 0;
1774                                         }       /* emac_erros */
1775                                 }       /* data_len < max mtu */
1776                         }       /* if data_len */
1777                         if (!data_len) {        /* no data */
1778                                 hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY;  /* Free Recv Buffer */
1779
1780                                 hw_p->stats.data_len_err++;     /* Error at Rx */
1781                         }
1782
1783                         /* !data_len */
1784                         /* AS.HARNOIS */
1785                         /* Check if user has already eaten buffer */
1786                         /* if not => ERROR */
1787                         else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
1788                                 if (hw_p->is_receiving)
1789                                         printf ("ERROR : Receive buffers are full!\n");
1790                                 break;
1791                         } else {
1792                                 hw_p->stats.rx_frames++;
1793                                 hw_p->stats.rx += data_len;
1794                                 ef_ptr = (struct enet_frame *) hw_p->rx[i].
1795                                         data_ptr;
1796 #ifdef INFO_4XX_ENET
1797                                 hw_p->stats.pkts_rx++;
1798 #endif
1799                                 /* AS.HARNOIS
1800                                  * use ring buffer
1801                                  */
1802                                 hw_p->rx_ready[hw_p->rx_i_index] = i;
1803                                 hw_p->rx_i_index++;
1804                                 if (NUM_RX_BUFF == hw_p->rx_i_index)
1805                                         hw_p->rx_i_index = 0;
1806
1807                                 hw_p->rx_slot++;
1808                                 if (NUM_RX_BUFF == hw_p->rx_slot)
1809                                         hw_p->rx_slot = 0;
1810
1811                                 /*  AS.HARNOIS
1812                                  * free receive buffer only when
1813                                  * buffer has been handled (eth_rx)
1814                                  rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
1815                                  */
1816                         }       /* if data_len */
1817                 }               /* while */
1818         }                       /* if EMACK_RXCHL */
1819 }
1820
1821
1822 static int ppc_4xx_eth_rx (struct eth_device *dev)
1823 {
1824         int length;
1825         int user_index;
1826         unsigned long msr;
1827         EMAC_4XX_HW_PST hw_p = dev->priv;
1828
1829         hw_p->is_receiving = 1; /* tell driver */
1830
1831         for (;;) {
1832                 /* AS.HARNOIS
1833                  * use ring buffer and
1834                  * get index from rx buffer desciptor queue
1835                  */
1836                 user_index = hw_p->rx_ready[hw_p->rx_u_index];
1837                 if (user_index == -1) {
1838                         length = -1;
1839                         break;  /* nothing received - leave for() loop */
1840                 }
1841
1842                 msr = mfmsr ();
1843                 mtmsr (msr & ~(MSR_EE));
1844
1845                 length = hw_p->rx[user_index].data_len & 0x0fff;
1846
1847                 /* Pass the packet up to the protocol layers. */
1848                 /*       NetReceive(NetRxPackets[rxIdx], length - 4); */
1849                 /*       NetReceive(NetRxPackets[i], length); */
1850                 invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
1851                                         (u32)hw_p->rx[user_index].data_ptr +
1852                                         length - 4);
1853                 NetReceive (NetRxPackets[user_index], length - 4);
1854                 /* Free Recv Buffer */
1855                 hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
1856                 /* Free rx buffer descriptor queue */
1857                 hw_p->rx_ready[hw_p->rx_u_index] = -1;
1858                 hw_p->rx_u_index++;
1859                 if (NUM_RX_BUFF == hw_p->rx_u_index)
1860                         hw_p->rx_u_index = 0;
1861
1862 #ifdef INFO_4XX_ENET
1863                 hw_p->stats.pkts_handled++;
1864 #endif
1865
1866                 mtmsr (msr);    /* Enable IRQ's */
1867         }
1868
1869         hw_p->is_receiving = 0; /* tell driver */
1870
1871         return length;
1872 }
1873
1874 int ppc_4xx_eth_initialize (bd_t * bis)
1875 {
1876         static int virgin = 0;
1877         struct eth_device *dev;
1878         int eth_num = 0;
1879         EMAC_4XX_HW_PST hw = NULL;
1880         u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
1881         u32 hw_addr[4];
1882
1883 #if defined(CONFIG_440GX)
1884         unsigned long pfc1;
1885
1886         mfsdr (sdr_pfc1, pfc1);
1887         pfc1 &= ~(0x01e00000);
1888         pfc1 |= 0x01200000;
1889         mtsdr (sdr_pfc1, pfc1);
1890 #endif
1891
1892         /* first clear all mac-addresses */
1893         for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
1894                 memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
1895
1896         for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1897                 switch (eth_num) {
1898                 default:                /* fall through */
1899                 case 0:
1900                         memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1901                                bis->bi_enetaddr, 6);
1902                         hw_addr[eth_num] = 0x0;
1903                         break;
1904 #ifdef CONFIG_HAS_ETH1
1905                 case 1:
1906                         memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1907                                bis->bi_enet1addr, 6);
1908                         hw_addr[eth_num] = 0x100;
1909                         break;
1910 #endif
1911 #ifdef CONFIG_HAS_ETH2
1912                 case 2:
1913                         memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1914                                bis->bi_enet2addr, 6);
1915 #if defined(CONFIG_460GT)
1916                         hw_addr[eth_num] = 0x300;
1917 #else
1918                         hw_addr[eth_num] = 0x400;
1919 #endif
1920                         break;
1921 #endif
1922 #ifdef CONFIG_HAS_ETH3
1923                 case 3:
1924                         memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START],
1925                                bis->bi_enet3addr, 6);
1926 #if defined(CONFIG_460GT)
1927                         hw_addr[eth_num] = 0x400;
1928 #else
1929                         hw_addr[eth_num] = 0x600;
1930 #endif
1931                         break;
1932 #endif
1933                 }
1934         }
1935
1936         /* set phy num and mode */
1937         bis->bi_phynum[0] = CONFIG_PHY_ADDR;
1938         bis->bi_phymode[0] = 0;
1939
1940 #if defined(CONFIG_PHY1_ADDR)
1941         bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
1942         bis->bi_phymode[1] = 0;
1943 #endif
1944 #if defined(CONFIG_440GX)
1945         bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
1946         bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
1947         bis->bi_phymode[2] = 2;
1948         bis->bi_phymode[3] = 2;
1949 #endif
1950
1951 #if defined(CONFIG_440GX) || \
1952     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
1953     defined(CONFIG_405EX)
1954         ppc_4xx_eth_setup_bridge(0, bis);
1955 #endif
1956
1957         for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
1958                 /*
1959                  * See if we can actually bring up the interface,
1960                  * otherwise, skip it
1961                  */
1962                 if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
1963                         bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
1964                         continue;
1965                 }
1966
1967                 /* Allocate device structure */
1968                 dev = (struct eth_device *) malloc (sizeof (*dev));
1969                 if (dev == NULL) {
1970                         printf ("ppc_4xx_eth_initialize: "
1971                                 "Cannot allocate eth_device %d\n", eth_num);
1972                         return (-1);
1973                 }
1974                 memset(dev, 0, sizeof(*dev));
1975
1976                 /* Allocate our private use data */
1977                 hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
1978                 if (hw == NULL) {
1979                         printf ("ppc_4xx_eth_initialize: "
1980                                 "Cannot allocate private hw data for eth_device %d",
1981                                 eth_num);
1982                         free (dev);
1983                         return (-1);
1984                 }
1985                 memset(hw, 0, sizeof(*hw));
1986
1987                 hw->hw_addr = hw_addr[eth_num];
1988                 memcpy (dev->enetaddr, ethaddr[eth_num], 6);
1989                 hw->devnum = eth_num;
1990                 hw->print_speed = 1;
1991
1992                 sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
1993                 dev->priv = (void *) hw;
1994                 dev->init = ppc_4xx_eth_init;
1995                 dev->halt = ppc_4xx_eth_halt;
1996                 dev->send = ppc_4xx_eth_send;
1997                 dev->recv = ppc_4xx_eth_rx;
1998
1999                 if (0 == virgin) {
2000                         /* set the MAL IER ??? names may change with new spec ??? */
2001 #if defined(CONFIG_440SPE) || \
2002     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
2003     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
2004     defined(CONFIG_405EX)
2005                         mal_ier =
2006                                 MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
2007                                 MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
2008 #else
2009                         mal_ier =
2010                                 MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
2011                                 MAL_IER_OPBE | MAL_IER_PLBE;
2012 #endif
2013                         mtdcr (malesr, 0xffffffff);     /* clear pending interrupts */
2014                         mtdcr (maltxdeir, 0xffffffff);  /* clear pending interrupts */
2015                         mtdcr (malrxdeir, 0xffffffff);  /* clear pending interrupts */
2016                         mtdcr (malier, mal_ier);
2017
2018                         /* install MAL interrupt handler */
2019                         irq_install_handler (VECNUM_MS,
2020                                              (interrupt_handler_t *) enetInt,
2021                                              dev);
2022                         irq_install_handler (VECNUM_MTE,
2023                                              (interrupt_handler_t *) enetInt,
2024                                              dev);
2025                         irq_install_handler (VECNUM_MRE,
2026                                              (interrupt_handler_t *) enetInt,
2027                                              dev);
2028                         irq_install_handler (VECNUM_TXDE,
2029                                              (interrupt_handler_t *) enetInt,
2030                                              dev);
2031                         irq_install_handler (VECNUM_RXDE,
2032                                              (interrupt_handler_t *) enetInt,
2033                                              dev);
2034                         virgin = 1;
2035                 }
2036
2037 #if defined(CONFIG_NET_MULTI)
2038                 eth_register (dev);
2039 #else
2040                 emac0_dev = dev;
2041 #endif
2042
2043 #if defined(CONFIG_NET_MULTI)
2044 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
2045                 miiphy_register (dev->name,
2046                                  emac4xx_miiphy_read, emac4xx_miiphy_write);
2047 #endif
2048 #endif
2049         }                       /* end for each supported device */
2050
2051         return 0;
2052 }
2053
2054 #if !defined(CONFIG_NET_MULTI)
2055 void eth_halt (void) {
2056         if (emac0_dev) {
2057                 ppc_4xx_eth_halt(emac0_dev);
2058                 free(emac0_dev);
2059                 emac0_dev = NULL;
2060         }
2061 }
2062
2063 int eth_init (bd_t *bis)
2064 {
2065         ppc_4xx_eth_initialize(bis);
2066         if (emac0_dev) {
2067                 return ppc_4xx_eth_init(emac0_dev, bis);
2068         } else {
2069                 printf("ERROR: ethaddr not set!\n");
2070                 return -1;
2071         }
2072 }
2073
2074 int eth_send(volatile void *packet, int length)
2075 {
2076         return (ppc_4xx_eth_send(emac0_dev, packet, length));
2077 }
2078
2079 int eth_rx(void)
2080 {
2081         return (ppc_4xx_eth_rx(emac0_dev));
2082 }
2083
2084 int emac4xx_miiphy_initialize (bd_t * bis)
2085 {
2086 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
2087         miiphy_register ("ppc_4xx_eth0",
2088                          emac4xx_miiphy_read, emac4xx_miiphy_write);
2089 #endif
2090
2091         return 0;
2092 }
2093 #endif /* !defined(CONFIG_NET_MULTI) */
2094
2095 #endif