emac_adapter.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 */
  55. static u8 EMACAddr[ENET_ADDR_LENGTH] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 };
  56. static int initialized = 0;
  57. void
  58. eth_halt(void)
  59. {
  60. if (initialized)
  61. (void) XEmac_Stop(&Emac);
  62. }
  63. int
  64. eth_init(bd_t * bis)
  65. {
  66. u32 Options;
  67. XStatus Result;
  68. #ifdef DEBUG
  69. printf("EMAC Initialization Started\n\r");
  70. #endif
  71. Result = XEmac_Initialize(&Emac, XPAR_EMAC_0_DEVICE_ID);
  72. if (Result != XST_SUCCESS) {
  73. return 0;
  74. }
  75. /* make sure the Emac is stopped before it is started */
  76. (void) XEmac_Stop(&Emac);
  77. memcpy(bis->bi_enetaddr, EMACAddr, 6);
  78. Result = XEmac_SetMacAddress(&Emac, EMACAddr);
  79. if (Result != XST_SUCCESS) {
  80. return 0;
  81. }
  82. Options =
  83. (XEM_POLLED_OPTION | XEM_UNICAST_OPTION | XEM_BROADCAST_OPTION |
  84. XEM_FDUPLEX_OPTION | XEM_INSERT_FCS_OPTION |
  85. XEM_INSERT_PAD_OPTION);
  86. Result = XEmac_SetOptions(&Emac, Options);
  87. if (Result != XST_SUCCESS) {
  88. return 0;
  89. }
  90. Result = XEmac_Start(&Emac);
  91. if (Result != XST_SUCCESS) {
  92. return 0;
  93. }
  94. #ifdef DEBUG
  95. printf("EMAC Initialization complete\n\r");
  96. #endif
  97. initialized = 1;
  98. return (0);
  99. }
  100. /*-----------------------------------------------------------------------------+
  101. +-----------------------------------------------------------------------------*/
  102. int
  103. eth_send(volatile void *ptr, int len)
  104. {
  105. XStatus Result;
  106. if (len > ENET_MAX_MTU)
  107. len = ENET_MAX_MTU;
  108. Result = XEmac_PollSend(&Emac, (u8 *) ptr, len);
  109. if (Result == XST_SUCCESS) {
  110. return (1);
  111. } else {
  112. printf("Error while sending frame\n\r");
  113. return (0);
  114. }
  115. }
  116. int
  117. eth_rx(void)
  118. {
  119. u32 RecvFrameLength;
  120. XStatus Result;
  121. RecvFrameLength = PKTSIZE;
  122. Result = XEmac_PollRecv(&Emac, (u8 *) etherrxbuff, &RecvFrameLength);
  123. if (Result == XST_SUCCESS) {
  124. NetReceive(etherrxbuff, RecvFrameLength);
  125. return (1);
  126. } else {
  127. return (0);
  128. }
  129. }
  130. #endif