xilinx_ll_temac_fifo.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Xilinx xps_ll_temac ethernet driver for u-boot
  3. *
  4. * FIFO sub-controller
  5. *
  6. * Copyright (C) 2011 - 2012 Stephan Linz <linz@li-pro.net>
  7. * Copyright (C) 2008 - 2011 Michal Simek <monstr@monstr.eu>
  8. * Copyright (C) 2008 - 2011 PetaLogix
  9. *
  10. * Based on Yoshio Kashiwagi kashiwagi@co-nss.co.jp driver
  11. * Copyright (C) 2008 Nissin Systems Co.,Ltd.
  12. * March 2008 created
  13. *
  14. * CREDITS: tsec driver
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License as published by the
  18. * Free Software Foundation; either version 2 of the License, or (at your
  19. * option) any later version.
  20. *
  21. * [0]: http://www.xilinx.com/support/documentation
  22. *
  23. * [F]: [0]/ip_documentation/xps_ll_fifo.pdf
  24. * [S]: [0]/ip_documentation/xps_ll_temac.pdf
  25. * [A]: [0]/application_notes/xapp1041.pdf
  26. */
  27. #include <config.h>
  28. #include <common.h>
  29. #include <net.h>
  30. #include <asm/types.h>
  31. #include <asm/io.h>
  32. #include "xilinx_ll_temac.h"
  33. #include "xilinx_ll_temac_fifo.h"
  34. int ll_temac_reset_fifo(struct eth_device *dev)
  35. {
  36. struct ll_temac *ll_temac = dev->priv;
  37. struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
  38. out_be32(&fifo_ctrl->tdfr, LL_FIFO_TDFR_KEY);
  39. out_be32(&fifo_ctrl->rdfr, LL_FIFO_RDFR_KEY);
  40. out_be32(&fifo_ctrl->isr, ~0UL);
  41. out_be32(&fifo_ctrl->ier, 0);
  42. return 0;
  43. }
  44. int ll_temac_recv_fifo(struct eth_device *dev)
  45. {
  46. int i, length = 0;
  47. u32 *buf = (u32 *)NetRxPackets[0];
  48. struct ll_temac *ll_temac = dev->priv;
  49. struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
  50. if (in_be32(&fifo_ctrl->isr) & LL_FIFO_ISR_RC) {
  51. /* reset isr */
  52. out_be32(&fifo_ctrl->isr, ~0UL);
  53. /*
  54. * MAYBE here:
  55. * while (fifo_ctrl->isr);
  56. */
  57. /*
  58. * The length is written (into RLR) by the XPS LL FIFO
  59. * when the packet is received across the RX LocalLink
  60. * interface and the receive data FIFO had enough
  61. * locations that all of the packet data has been saved.
  62. * The RLR should only be read when a receive packet is
  63. * available for processing (the receive occupancy is
  64. * not zero). Once the RLR is read, the receive packet
  65. * data should be read from the receive data FIFO before
  66. * the RLR is read again.
  67. *
  68. * [F] page 17, Receive Length Register (RLR)
  69. */
  70. if (in_be32(&fifo_ctrl->rdfo) & LL_FIFO_RDFO_MASK) {
  71. length = in_be32(&fifo_ctrl->rlf) & LL_FIFO_RLF_MASK;
  72. } else {
  73. printf("%s: Got error, no receive occupancy\n",
  74. __func__);
  75. return -1;
  76. }
  77. if (length > PKTSIZE_ALIGN) {
  78. printf("%s: Got error, receive package too big (%i)\n",
  79. __func__, length);
  80. ll_temac_reset_fifo(dev);
  81. return -1;
  82. }
  83. for (i = 0; i < length; i += 4)
  84. *buf++ = in_be32(&fifo_ctrl->rdfd);
  85. NetReceive(NetRxPackets[0], length);
  86. }
  87. return 0;
  88. }
  89. int ll_temac_send_fifo(struct eth_device *dev, volatile void *packet,
  90. int length)
  91. {
  92. int i;
  93. u32 *buf = (u32 *)packet;
  94. struct ll_temac *ll_temac = dev->priv;
  95. struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
  96. if (length < LL_FIFO_TLF_MIN) {
  97. printf("%s: Got error, transmit package too small (%i)\n",
  98. __func__, length);
  99. return -1;
  100. }
  101. if (length > LL_FIFO_TLF_MAX) {
  102. printf("%s: Got error, transmit package too big (%i)\n",
  103. __func__, length);
  104. return -1;
  105. }
  106. for (i = 0; i < length; i += 4)
  107. out_be32(&fifo_ctrl->tdfd, *buf++);
  108. /*
  109. * Once the packet length is written to the TLR it is
  110. * automatically moved to the transmit data FIFO with
  111. * the packet data freeing up the TLR for another value.
  112. * The packet length must be written to the TLR after
  113. * the packet data is written to the transmit data FIFO.
  114. * It is not valid to write data for multiple packets
  115. * to the transmit data FIFO before writing the packet
  116. * length values.
  117. *
  118. * [F] page 17, Transmit Length Register (TLR)
  119. */
  120. out_be32(&fifo_ctrl->tlf, length);
  121. return 0;
  122. }