blob: 0b100d215c70b7e15a8174620fa1ead9a1f8795b [file] [log] [blame]
wdenke537b3b2004-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 Likely63675bd2007-02-20 09:04:52 +010040#include <config.h>
wdenke537b3b2004-02-23 23:54:43 +000041#include <common.h>
42#include <net.h>
wdenke537b3b2004-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
wdenk97e8bda2004-09-29 22:43:59 +000058/* hardcoded MAC address for the Xilinx EMAC Core when env is nowhere*/
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +020059#ifdef CONFIG_ENV_IS_NOWHERE
wdenke537b3b2004-02-23 23:54:43 +000060static u8 EMACAddr[ENET_ADDR_LENGTH] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 };
wdenk97e8bda2004-09-29 22:43:59 +000061#endif
wdenke537b3b2004-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;
77
78#ifdef DEBUG
79 printf("EMAC Initialization Started\n\r");
80#endif
81
82 Result = XEmac_Initialize(&Emac, XPAR_EMAC_0_DEVICE_ID);
83 if (Result != XST_SUCCESS) {
84 return 0;
85 }
86
87 /* make sure the Emac is stopped before it is started */
88 (void) XEmac_Stop(&Emac);
89
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +020090#ifdef CONFIG_ENV_IS_NOWHERE
wdenke537b3b2004-02-23 23:54:43 +000091 memcpy(bis->bi_enetaddr, EMACAddr, 6);
wdenk97e8bda2004-09-29 22:43:59 +000092#endif
93
94 Result = XEmac_SetMacAddress(&Emac, bis->bi_enetaddr);
wdenke537b3b2004-02-23 23:54:43 +000095 if (Result != XST_SUCCESS) {
96 return 0;
97 }
98
99 Options =
100 (XEM_POLLED_OPTION | XEM_UNICAST_OPTION | XEM_BROADCAST_OPTION |
101 XEM_FDUPLEX_OPTION | XEM_INSERT_FCS_OPTION |
102 XEM_INSERT_PAD_OPTION);
103 Result = XEmac_SetOptions(&Emac, Options);
104 if (Result != XST_SUCCESS) {
105 return 0;
106 }
107
108 Result = XEmac_Start(&Emac);
109 if (Result != XST_SUCCESS) {
110 return 0;
111 }
112#ifdef DEBUG
113 printf("EMAC Initialization complete\n\r");
114#endif
115
116 initialized = 1;
117
118 return (0);
119}
120
121/*-----------------------------------------------------------------------------+
122+-----------------------------------------------------------------------------*/
123int
124eth_send(volatile void *ptr, int len)
125{
126 XStatus Result;
127
128 if (len > ENET_MAX_MTU)
129 len = ENET_MAX_MTU;
130
131 Result = XEmac_PollSend(&Emac, (u8 *) ptr, len);
132 if (Result == XST_SUCCESS) {
133 return (1);
134 } else {
135 printf("Error while sending frame\n\r");
136 return (0);
137 }
138
139}
140
141int
142eth_rx(void)
143{
144 u32 RecvFrameLength;
145 XStatus Result;
146
147 RecvFrameLength = PKTSIZE;
148 Result = XEmac_PollRecv(&Emac, (u8 *) etherrxbuff, &RecvFrameLength);
149 if (Result == XST_SUCCESS) {
Wolfgang Denk8ed317c2007-04-04 02:09:30 +0200150#ifndef CONFIG_EMACLITE
Stefan Roese1586ded2006-01-18 20:06:44 +0100151 NetReceive((uchar *)etherrxbuff, RecvFrameLength);
Michal Simek922ce202007-03-11 13:48:24 +0100152#else
153 NetReceive(etherrxbuff, RecvFrameLength);
154#endif
wdenke537b3b2004-02-23 23:54:43 +0000155 return (1);
156 } else {
157 return (0);
158 }
159}
160
161#endif