Add support for AMCC 440SPe CPU based eval board (Yucca).
[platform/kernel/u-boot.git] / board / xilinx / xilinx_enet / emac_adapter.c
1 /******************************************************************************
2 *
3 *     Author: Xilinx, Inc.
4 *
5 *
6 *     This program is free software; you can redistribute it and/or modify it
7 *     under the terms of the GNU General Public License as published by the
8 *     Free Software Foundation; either version 2 of the License, or (at your
9 *     option) any later version.
10 *
11 *
12 *     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
13 *     COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
14 *     ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
15 *     XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
16 *     FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
17 *     ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
18 *     XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
19 *     THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
20 *     WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
21 *     CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 *     FITNESS FOR A PARTICULAR PURPOSE.
23 *
24 *
25 *     Xilinx hardware products are not intended for use in life support
26 *     appliances, devices, or systems. Use in such applications is
27 *     expressly prohibited.
28 *
29 *
30 *     (c) Copyright 2002-2004 Xilinx Inc.
31 *     All rights reserved.
32 *
33 *
34 *     You should have received a copy of the GNU General Public License along
35 *     with this program; if not, write to the Free Software Foundation, Inc.,
36 *     675 Mass Ave, Cambridge, MA 02139, USA.
37 *
38 ******************************************************************************/
39
40 #include <common.h>
41 #include <net.h>
42 #include <configs/ml300.h>
43 #include "xparameters.h"
44 #include "xemac.h"
45
46 #if defined(XPAR_EMAC_0_DEVICE_ID)
47 /*
48  * ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
49  * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
50  */
51
52 #define ENET_MAX_MTU           PKTSIZE
53 #define ENET_MAX_MTU_ALIGNED   PKTSIZE_ALIGN
54 #define ENET_ADDR_LENGTH       6
55
56 static XEmac Emac;
57 static char etherrxbuff[PKTSIZE_ALIGN]; /* Receive buffer */
58
59 /* hardcoded MAC address for the Xilinx EMAC Core when env is nowhere*/
60 #ifdef CFG_ENV_IS_NOWHERE
61 static u8 EMACAddr[ENET_ADDR_LENGTH] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 };
62 #endif
63
64 static int initialized = 0;
65
66 void
67 eth_halt(void)
68 {
69         if (initialized)
70                 (void) XEmac_Stop(&Emac);
71 }
72
73 int
74 eth_init(bd_t * bis)
75 {
76         u32 Options;
77         XStatus Result;
78
79 #ifdef DEBUG
80         printf("EMAC Initialization Started\n\r");
81 #endif
82
83         Result = XEmac_Initialize(&Emac, XPAR_EMAC_0_DEVICE_ID);
84         if (Result != XST_SUCCESS) {
85                 return 0;
86         }
87
88         /* make sure the Emac is stopped before it is started */
89         (void) XEmac_Stop(&Emac);
90
91 #ifdef CFG_ENV_IS_NOWHERE
92         memcpy(bis->bi_enetaddr, EMACAddr, 6);
93 #endif
94
95         Result = XEmac_SetMacAddress(&Emac, bis->bi_enetaddr);
96         if (Result != XST_SUCCESS) {
97                 return 0;
98         }
99
100         Options =
101             (XEM_POLLED_OPTION | XEM_UNICAST_OPTION | XEM_BROADCAST_OPTION |
102              XEM_FDUPLEX_OPTION | XEM_INSERT_FCS_OPTION |
103              XEM_INSERT_PAD_OPTION);
104         Result = XEmac_SetOptions(&Emac, Options);
105         if (Result != XST_SUCCESS) {
106                 return 0;
107         }
108
109         Result = XEmac_Start(&Emac);
110         if (Result != XST_SUCCESS) {
111                 return 0;
112         }
113 #ifdef DEBUG
114         printf("EMAC Initialization complete\n\r");
115 #endif
116
117         initialized = 1;
118
119         return (0);
120 }
121
122 /*-----------------------------------------------------------------------------+
123 +-----------------------------------------------------------------------------*/
124 int
125 eth_send(volatile void *ptr, int len)
126 {
127         XStatus Result;
128
129         if (len > ENET_MAX_MTU)
130                 len = ENET_MAX_MTU;
131
132         Result = XEmac_PollSend(&Emac, (u8 *) ptr, len);
133         if (Result == XST_SUCCESS) {
134                 return (1);
135         } else {
136                 printf("Error while sending frame\n\r");
137                 return (0);
138         }
139
140 }
141
142 int
143 eth_rx(void)
144 {
145         u32 RecvFrameLength;
146         XStatus Result;
147
148         RecvFrameLength = PKTSIZE;
149         Result = XEmac_PollRecv(&Emac, (u8 *) etherrxbuff, &RecvFrameLength);
150         if (Result == XST_SUCCESS) {
151                 NetReceive((uchar)etherrxbuff, RecvFrameLength);
152                 return (1);
153         } else {
154                 return (0);
155         }
156 }
157
158 #endif