emac_adapter.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #include <common.h>
  40. #include <net.h>
  41. #include <configs/ml300.h>
  42. #include "xparameters.h"
  43. #include "xemac.h"
  44. #if defined(XPAR_EMAC_0_DEVICE_ID)
  45. /*
  46. * ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
  47. * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
  48. */
  49. #define ENET_MAX_MTU PKTSIZE
  50. #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
  51. #define ENET_ADDR_LENGTH 6
  52. static XEmac Emac;
  53. static char etherrxbuff[PKTSIZE_ALIGN]; /* Receive buffer */
  54. /* hardcoded MAC address for the Xilinx EMAC Core when env is nowhere*/
  55. #ifdef CFG_ENV_IS_NOWHERE
  56. static u8 EMACAddr[ENET_ADDR_LENGTH] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 };
  57. #endif
  58. static int initialized = 0;
  59. void
  60. eth_halt(void)
  61. {
  62. if (initialized)
  63. (void) XEmac_Stop(&Emac);
  64. }
  65. int
  66. eth_init(bd_t * bis)
  67. {
  68. u32 Options;
  69. XStatus Result;
  70. #ifdef DEBUG
  71. printf("EMAC Initialization Started\n\r");
  72. #endif
  73. Result = XEmac_Initialize(&Emac, XPAR_EMAC_0_DEVICE_ID);
  74. if (Result != XST_SUCCESS) {
  75. return 0;
  76. }
  77. /* make sure the Emac is stopped before it is started */
  78. (void) XEmac_Stop(&Emac);
  79. #ifdef CFG_ENV_IS_NOWHERE
  80. memcpy(bis->bi_enetaddr, EMACAddr, 6);
  81. #endif
  82. Result = XEmac_SetMacAddress(&Emac, bis->bi_enetaddr);
  83. if (Result != XST_SUCCESS) {
  84. return 0;
  85. }
  86. Options =
  87. (XEM_POLLED_OPTION | XEM_UNICAST_OPTION | XEM_BROADCAST_OPTION |
  88. XEM_FDUPLEX_OPTION | XEM_INSERT_FCS_OPTION |
  89. XEM_INSERT_PAD_OPTION);
  90. Result = XEmac_SetOptions(&Emac, Options);
  91. if (Result != XST_SUCCESS) {
  92. return 0;
  93. }
  94. Result = XEmac_Start(&Emac);
  95. if (Result != XST_SUCCESS) {
  96. return 0;
  97. }
  98. #ifdef DEBUG
  99. printf("EMAC Initialization complete\n\r");
  100. #endif
  101. initialized = 1;
  102. return (0);
  103. }
  104. /*-----------------------------------------------------------------------------+
  105. +-----------------------------------------------------------------------------*/
  106. int
  107. eth_send(volatile void *ptr, int len)
  108. {
  109. XStatus Result;
  110. if (len > ENET_MAX_MTU)
  111. len = ENET_MAX_MTU;
  112. Result = XEmac_PollSend(&Emac, (u8 *) ptr, len);
  113. if (Result == XST_SUCCESS) {
  114. return (1);
  115. } else {
  116. printf("Error while sending frame\n\r");
  117. return (0);
  118. }
  119. }
  120. int
  121. eth_rx(void)
  122. {
  123. u32 RecvFrameLength;
  124. XStatus Result;
  125. RecvFrameLength = PKTSIZE;
  126. Result = XEmac_PollRecv(&Emac, (u8 *) etherrxbuff, &RecvFrameLength);
  127. if (Result == XST_SUCCESS) {
  128. NetReceive((uchar *)etherrxbuff, RecvFrameLength);
  129. return (1);
  130. } else {
  131. return (0);
  132. }
  133. }
  134. #endif