dp_rx_desc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) 2016 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "dp_types.h"
  19. #include "dp_rx.h"
  20. /*
  21. * dp_rx_desc_pool_alloc() - create a pool of software rx_descs
  22. * at the time of dp rx initialization
  23. *
  24. * @soc: core txrx main context
  25. * @pool_id: pool_id which is one of 3 mac_ids
  26. *
  27. * return success or failure
  28. */
  29. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc, uint32_t pool_id)
  30. {
  31. uint32_t i;
  32. struct dp_pdev *dp_pdev = soc->pdev_list[pool_id];
  33. struct dp_srng *rxdma_srng = &dp_pdev->rx_refill_buf_ring;
  34. soc->rx_desc[pool_id].array = qdf_mem_malloc(
  35. ((rxdma_srng->alloc_size/hal_srng_get_entrysize(soc->hal_soc,
  36. RXDMA_BUF)) * 3) * sizeof(union dp_rx_desc_list_elem_t));
  37. if (!(soc->rx_desc[pool_id].array)) {
  38. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
  39. "%s: RX Desc Pool[%d] allocation failed\n",
  40. __func__, pool_id);
  41. return QDF_STATUS_E_NOMEM;
  42. }
  43. qdf_spin_lock_bh(&soc->rx_desc_mutex[pool_id]);
  44. soc->rx_desc[pool_id].pool_size = (rxdma_srng->alloc_size/
  45. hal_srng_get_entrysize(soc->hal_soc, RXDMA_BUF)) * 3;
  46. /* link SW rx descs into a freelist */
  47. soc->rx_desc[pool_id].freelist = &soc->rx_desc[pool_id].array[0];
  48. for (i = 0; i < soc->rx_desc[pool_id].pool_size-1; i++) {
  49. soc->rx_desc[pool_id].array[i].next =
  50. &soc->rx_desc[pool_id].array[i+1];
  51. soc->rx_desc[pool_id].array[i].rx_desc.cookie =
  52. i | (pool_id << 18);
  53. }
  54. soc->rx_desc[pool_id].array[i].next = NULL;
  55. soc->rx_desc[pool_id].array[i].rx_desc.cookie = i | (pool_id << 18);
  56. qdf_spin_unlock_bh(&soc->rx_desc_mutex[pool_id]);
  57. return QDF_STATUS_SUCCESS;
  58. }
  59. /*
  60. * dp_rx_desc_pool_free() - free the sw rx desc pool called during
  61. * de-initialization of wifi module.
  62. *
  63. * @soc: core txrx main context
  64. * @pool_id: pool_id which is one of 3 mac_ids
  65. */
  66. void dp_rx_desc_pool_free(struct dp_soc *soc, uint32_t pool_id)
  67. {
  68. qdf_spin_lock_bh(&soc->rx_desc_mutex[pool_id]);
  69. qdf_mem_free(soc->rx_desc[pool_id].array);
  70. qdf_spin_unlock_bh(&soc->rx_desc_mutex[pool_id]);
  71. }
  72. /*
  73. * dp_rx_get_free_desc_list() - provide a list of descriptors from
  74. * the free rx desc pool.
  75. *
  76. * @soc: core txrx main context
  77. * @pool_id: pool_id which is one of 3 mac_ids
  78. * @num_descs: number of descs requested from freelist
  79. * @desc_list: attach the descs to this list (output parameter)
  80. *
  81. * Return: number of descs allocated from free list.
  82. */
  83. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  84. uint16_t num_descs,
  85. union dp_rx_desc_list_elem_t **desc_list,
  86. union dp_rx_desc_list_elem_t **tail)
  87. {
  88. uint16_t count;
  89. qdf_spin_lock_bh(&soc->rx_desc_mutex[pool_id]);
  90. *desc_list = soc->rx_desc[pool_id].freelist;
  91. if (!(*desc_list)) {
  92. qdf_spin_unlock_bh(&soc->rx_desc_mutex[pool_id]);
  93. return 0;
  94. }
  95. for (count = 0; count < num_descs; count++) {
  96. *tail = soc->rx_desc[pool_id].freelist;
  97. soc->rx_desc[pool_id].freelist =
  98. soc->rx_desc[pool_id].freelist->next;
  99. if (qdf_unlikely(!soc->rx_desc[pool_id].freelist)) {
  100. qdf_spin_unlock_bh(&soc->rx_desc_mutex[pool_id]);
  101. return count;
  102. }
  103. }
  104. qdf_spin_unlock_bh(&soc->rx_desc_mutex[pool_id]);
  105. return count;
  106. }
  107. /*
  108. * dp_rx_add_desc_list_to_free_list() - append unused desc_list back to
  109. * freelist.
  110. *
  111. * @soc: core txrx main context
  112. * @local_desc_list: local desc list provided by the caller (output param)
  113. * @pool_id: pool_id which is one of 3 mac_ids
  114. */
  115. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  116. union dp_rx_desc_list_elem_t **local_desc_list,
  117. union dp_rx_desc_list_elem_t **tail,
  118. uint16_t pool_id)
  119. {
  120. union dp_rx_desc_list_elem_t *temp_list = NULL;
  121. qdf_spin_lock_bh(&soc->rx_desc_mutex[pool_id]);
  122. temp_list = soc->rx_desc[pool_id].freelist;
  123. qdf_print(
  124. "temp_list: %p, *local_desc_list: %p, *tail: %p (*tail)->next: %p\n",
  125. temp_list, *local_desc_list, *tail, (*tail)->next);
  126. soc->rx_desc[pool_id].freelist = *local_desc_list;
  127. (*tail)->next = temp_list;
  128. qdf_spin_unlock_bh(&soc->rx_desc_mutex[pool_id]);
  129. }