xilinx_ll_temac_fifo.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * SPDX-License-Identifier: GPL-2.0+
  17. *
  18. * [0]: http://www.xilinx.com/support/documentation
  19. *
  20. * [F]: [0]/ip_documentation/xps_ll_fifo.pdf
  21. * [S]: [0]/ip_documentation/xps_ll_temac.pdf
  22. * [A]: [0]/application_notes/xapp1041.pdf
  23. */
  24. #include <config.h>
  25. #include <common.h>
  26. #include <net.h>
  27. #include <asm/types.h>
  28. #include <asm/io.h>
  29. #include "xilinx_ll_temac.h"
  30. #include "xilinx_ll_temac_fifo.h"
  31. int ll_temac_reset_fifo(struct eth_device *dev)
  32. {
  33. struct ll_temac *ll_temac = dev->priv;
  34. struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
  35. out_be32(&fifo_ctrl->tdfr, LL_FIFO_TDFR_KEY);
  36. out_be32(&fifo_ctrl->rdfr, LL_FIFO_RDFR_KEY);
  37. out_be32(&fifo_ctrl->isr, ~0UL);
  38. out_be32(&fifo_ctrl->ier, 0);
  39. return 0;
  40. }
  41. int ll_temac_recv_fifo(struct eth_device *dev)
  42. {
  43. int i, length = 0;
  44. u32 *buf = (u32 *)net_rx_packets[0];
  45. struct ll_temac *ll_temac = dev->priv;
  46. struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
  47. if (in_be32(&fifo_ctrl->isr) & LL_FIFO_ISR_RC) {
  48. /* reset isr */
  49. out_be32(&fifo_ctrl->isr, ~0UL);
  50. /*
  51. * MAYBE here:
  52. * while (fifo_ctrl->isr);
  53. */
  54. /*
  55. * The length is written (into RLR) by the XPS LL FIFO
  56. * when the packet is received across the RX LocalLink
  57. * interface and the receive data FIFO had enough
  58. * locations that all of the packet data has been saved.
  59. * The RLR should only be read when a receive packet is
  60. * available for processing (the receive occupancy is
  61. * not zero). Once the RLR is read, the receive packet
  62. * data should be read from the receive data FIFO before
  63. * the RLR is read again.
  64. *
  65. * [F] page 17, Receive Length Register (RLR)
  66. */
  67. if (in_be32(&fifo_ctrl->rdfo) & LL_FIFO_RDFO_MASK) {
  68. length = in_be32(&fifo_ctrl->rlf) & LL_FIFO_RLF_MASK;
  69. } else {
  70. printf("%s: Got error, no receive occupancy\n",
  71. __func__);
  72. return -1;
  73. }
  74. if (length > PKTSIZE_ALIGN) {
  75. printf("%s: Got error, receive package too big (%i)\n",
  76. __func__, length);
  77. ll_temac_reset_fifo(dev);
  78. return -1;
  79. }
  80. for (i = 0; i < length; i += 4)
  81. *buf++ = in_be32(&fifo_ctrl->rdfd);
  82. net_process_received_packet(net_rx_packets[0], length);
  83. }
  84. return 0;
  85. }
  86. int ll_temac_send_fifo(struct eth_device *dev, void *packet, int length)
  87. {
  88. int i;
  89. u32 *buf = (u32 *)packet;
  90. struct ll_temac *ll_temac = dev->priv;
  91. struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
  92. if (length < LL_FIFO_TLF_MIN) {
  93. printf("%s: Got error, transmit package too small (%i)\n",
  94. __func__, length);
  95. return -1;
  96. }
  97. if (length > LL_FIFO_TLF_MAX) {
  98. printf("%s: Got error, transmit package too big (%i)\n",
  99. __func__, length);
  100. return -1;
  101. }
  102. for (i = 0; i < length; i += 4)
  103. out_be32(&fifo_ctrl->tdfd, *buf++);
  104. /*
  105. * Once the packet length is written to the TLR it is
  106. * automatically moved to the transmit data FIFO with
  107. * the packet data freeing up the TLR for another value.
  108. * The packet length must be written to the TLR after
  109. * the packet data is written to the transmit data FIFO.
  110. * It is not valid to write data for multiple packets
  111. * to the transmit data FIFO before writing the packet
  112. * length values.
  113. *
  114. * [F] page 17, Transmit Length Register (TLR)
  115. */
  116. out_be32(&fifo_ctrl->tlf, length);
  117. return 0;
  118. }