ring.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Applied Micro X-Gene SoC Ethernet v2 Driver
  3. *
  4. * Copyright (c) 2017, Applied Micro Circuits Corporation
  5. * Author(s): Iyappan Subramanian <isubramanian@apm.com>
  6. * Keyur Chudgar <kchudgar@apm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "main.h"
  22. /* create circular linked list of descriptors */
  23. void xge_setup_desc(struct xge_desc_ring *ring)
  24. {
  25. struct xge_raw_desc *raw_desc;
  26. dma_addr_t dma_h, next_dma;
  27. u16 offset;
  28. int i;
  29. for (i = 0; i < XGENE_ENET_NUM_DESC; i++) {
  30. raw_desc = &ring->raw_desc[i];
  31. offset = (i + 1) & (XGENE_ENET_NUM_DESC - 1);
  32. next_dma = ring->dma_addr + (offset * XGENE_ENET_DESC_SIZE);
  33. raw_desc->m0 = cpu_to_le64(SET_BITS(E, 1) |
  34. SET_BITS(PKT_SIZE, SLOT_EMPTY));
  35. dma_h = upper_32_bits(next_dma);
  36. raw_desc->m1 = cpu_to_le64(SET_BITS(NEXT_DESC_ADDRL, next_dma) |
  37. SET_BITS(NEXT_DESC_ADDRH, dma_h));
  38. }
  39. }
  40. void xge_update_tx_desc_addr(struct xge_pdata *pdata)
  41. {
  42. struct xge_desc_ring *ring = pdata->tx_ring;
  43. dma_addr_t dma_addr = ring->dma_addr;
  44. xge_wr_csr(pdata, DMATXDESCL, dma_addr);
  45. xge_wr_csr(pdata, DMATXDESCH, upper_32_bits(dma_addr));
  46. ring->head = 0;
  47. ring->tail = 0;
  48. }
  49. void xge_update_rx_desc_addr(struct xge_pdata *pdata)
  50. {
  51. struct xge_desc_ring *ring = pdata->rx_ring;
  52. dma_addr_t dma_addr = ring->dma_addr;
  53. xge_wr_csr(pdata, DMARXDESCL, dma_addr);
  54. xge_wr_csr(pdata, DMARXDESCH, upper_32_bits(dma_addr));
  55. ring->head = 0;
  56. ring->tail = 0;
  57. }
  58. void xge_intr_enable(struct xge_pdata *pdata)
  59. {
  60. u32 data;
  61. data = RX_PKT_RCVD | TX_PKT_SENT;
  62. xge_wr_csr(pdata, DMAINTRMASK, data);
  63. }
  64. void xge_intr_disable(struct xge_pdata *pdata)
  65. {
  66. xge_wr_csr(pdata, DMAINTRMASK, 0);
  67. }