wdenk | 028ab6b | 2004-02-23 23:54:43 +0000 | [diff] [blame] | 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 | |
Grant Likely | 99b0f0f | 2007-02-20 09:04:52 +0100 | [diff] [blame] | 40 | #include <config.h> |
wdenk | 028ab6b | 2004-02-23 23:54:43 +0000 | [diff] [blame] | 41 | #include <common.h> |
| 42 | #include <net.h> |
wdenk | 028ab6b | 2004-02-23 23:54:43 +0000 | [diff] [blame] | 43 | #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 | |
| 55 | static XEmac Emac; |
| 56 | static char etherrxbuff[PKTSIZE_ALIGN]; /* Receive buffer */ |
| 57 | |
wdenk | a06752e | 2004-09-29 22:43:59 +0000 | [diff] [blame] | 58 | /* hardcoded MAC address for the Xilinx EMAC Core when env is nowhere*/ |
Jean-Christophe PLAGNIOL-VILLARD | 93f6d72 | 2008-09-10 22:48:00 +0200 | [diff] [blame] | 59 | #ifdef CONFIG_ENV_IS_NOWHERE |
wdenk | 028ab6b | 2004-02-23 23:54:43 +0000 | [diff] [blame] | 60 | static u8 EMACAddr[ENET_ADDR_LENGTH] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 }; |
wdenk | a06752e | 2004-09-29 22:43:59 +0000 | [diff] [blame] | 61 | #endif |
wdenk | 028ab6b | 2004-02-23 23:54:43 +0000 | [diff] [blame] | 62 | |
| 63 | static int initialized = 0; |
| 64 | |
| 65 | void |
| 66 | eth_halt(void) |
| 67 | { |
| 68 | if (initialized) |
| 69 | (void) XEmac_Stop(&Emac); |
| 70 | } |
| 71 | |
| 72 | int |
| 73 | eth_init(bd_t * bis) |
| 74 | { |
| 75 | u32 Options; |
| 76 | XStatus Result; |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 77 | uchar enetaddr[6]; |
wdenk | 028ab6b | 2004-02-23 23:54:43 +0000 | [diff] [blame] | 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 | |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 91 | if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { |
Jean-Christophe PLAGNIOL-VILLARD | 93f6d72 | 2008-09-10 22:48:00 +0200 | [diff] [blame] | 92 | #ifdef CONFIG_ENV_IS_NOWHERE |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 93 | memcpy(enetaddr, EMACAddr, 6); |
| 94 | eth_setenv_enetaddr("ethaddr", enetaddr); |
wdenk | a06752e | 2004-09-29 22:43:59 +0000 | [diff] [blame] | 95 | #endif |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 96 | } |
wdenk | a06752e | 2004-09-29 22:43:59 +0000 | [diff] [blame] | 97 | |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 98 | Result = XEmac_SetMacAddress(&Emac, enetaddr); |
wdenk | 028ab6b | 2004-02-23 23:54:43 +0000 | [diff] [blame] | 99 | 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 | +-----------------------------------------------------------------------------*/ |
| 127 | int |
| 128 | eth_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 | |
| 145 | int |
| 146 | eth_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 Denk | 31c98a8 | 2007-04-04 02:09:30 +0200 | [diff] [blame] | 154 | #ifndef CONFIG_EMACLITE |
Stefan Roese | 18c5e64 | 2006-01-18 20:06:44 +0100 | [diff] [blame] | 155 | NetReceive((uchar *)etherrxbuff, RecvFrameLength); |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 156 | #else |
| 157 | NetReceive(etherrxbuff, RecvFrameLength); |
| 158 | #endif |
wdenk | 028ab6b | 2004-02-23 23:54:43 +0000 | [diff] [blame] | 159 | return (1); |
| 160 | } else { |
| 161 | return (0); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | #endif |