blob: 35bcc4d9da381fc75db9670a2c34011c03636d93 [file] [log] [blame]
wdenk028ab6b2004-02-23 23:54:43 +00001/******************************************************************************
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
Grant Likely99b0f0f2007-02-20 09:04:52 +010040#include <config.h>
wdenk028ab6b2004-02-23 23:54:43 +000041#include <common.h>
42#include <net.h>
wdenk028ab6b2004-02-23 23:54:43 +000043#include "xemac.h"
44
45#if defined(XPAR_EMAC_0_DEVICE_ID)
46/*
47 * ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
48 * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
49 */
50
51#define ENET_MAX_MTU PKTSIZE
52#define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
53#define ENET_ADDR_LENGTH 6
54
55static XEmac Emac;
56static char etherrxbuff[PKTSIZE_ALIGN]; /* Receive buffer */
57
wdenka06752e2004-09-29 22:43:59 +000058/* hardcoded MAC address for the Xilinx EMAC Core when env is nowhere*/
Jean-Christophe PLAGNIOL-VILLARD93f6d722008-09-10 22:48:00 +020059#ifdef CONFIG_ENV_IS_NOWHERE
wdenk028ab6b2004-02-23 23:54:43 +000060static u8 EMACAddr[ENET_ADDR_LENGTH] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 };
wdenka06752e2004-09-29 22:43:59 +000061#endif
wdenk028ab6b2004-02-23 23:54:43 +000062
63static int initialized = 0;
64
65void
66eth_halt(void)
67{
68 if (initialized)
69 (void) XEmac_Stop(&Emac);
70}
71
72int
73eth_init(bd_t * bis)
74{
75 u32 Options;
76 XStatus Result;
Mike Frysingerb6b46252009-02-11 18:38:38 -050077 uchar enetaddr[6];
wdenk028ab6b2004-02-23 23:54:43 +000078
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
Mike Frysingerb6b46252009-02-11 18:38:38 -050091 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
Jean-Christophe PLAGNIOL-VILLARD93f6d722008-09-10 22:48:00 +020092#ifdef CONFIG_ENV_IS_NOWHERE
Mike Frysingerb6b46252009-02-11 18:38:38 -050093 memcpy(enetaddr, EMACAddr, 6);
94 eth_setenv_enetaddr("ethaddr", enetaddr);
wdenka06752e2004-09-29 22:43:59 +000095#endif
Mike Frysingerb6b46252009-02-11 18:38:38 -050096 }
wdenka06752e2004-09-29 22:43:59 +000097
Mike Frysingerb6b46252009-02-11 18:38:38 -050098 Result = XEmac_SetMacAddress(&Emac, enetaddr);
wdenk028ab6b2004-02-23 23:54:43 +000099 if (Result != XST_SUCCESS) {
100 return 0;
101 }
102
103 Options =
104 (XEM_POLLED_OPTION | XEM_UNICAST_OPTION | XEM_BROADCAST_OPTION |
105 XEM_FDUPLEX_OPTION | XEM_INSERT_FCS_OPTION |
106 XEM_INSERT_PAD_OPTION);
107 Result = XEmac_SetOptions(&Emac, Options);
108 if (Result != XST_SUCCESS) {
109 return 0;
110 }
111
112 Result = XEmac_Start(&Emac);
113 if (Result != XST_SUCCESS) {
114 return 0;
115 }
116#ifdef DEBUG
117 printf("EMAC Initialization complete\n\r");
118#endif
119
120 initialized = 1;
121
122 return (0);
123}
124
125/*-----------------------------------------------------------------------------+
126+-----------------------------------------------------------------------------*/
127int
128eth_send(volatile void *ptr, int len)
129{
130 XStatus Result;
131
132 if (len > ENET_MAX_MTU)
133 len = ENET_MAX_MTU;
134
135 Result = XEmac_PollSend(&Emac, (u8 *) ptr, len);
136 if (Result == XST_SUCCESS) {
137 return (1);
138 } else {
139 printf("Error while sending frame\n\r");
140 return (0);
141 }
142
143}
144
145int
146eth_rx(void)
147{
148 u32 RecvFrameLength;
149 XStatus Result;
150
151 RecvFrameLength = PKTSIZE;
152 Result = XEmac_PollRecv(&Emac, (u8 *) etherrxbuff, &RecvFrameLength);
153 if (Result == XST_SUCCESS) {
Wolfgang Denk31c98a82007-04-04 02:09:30 +0200154#ifndef CONFIG_EMACLITE
Stefan Roese18c5e642006-01-18 20:06:44 +0100155 NetReceive((uchar *)etherrxbuff, RecvFrameLength);
Michal Simekcfc67112007-03-11 13:48:24 +0100156#else
157 NetReceive(etherrxbuff, RecvFrameLength);
158#endif
wdenk028ab6b2004-02-23 23:54:43 +0000159 return (1);
160 } else {
161 return (0);
162 }
163}
164
165#endif