dp_rx.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2017 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. #ifndef _DP_RX_H
  19. #define _DP_RX_H
  20. #include "hal_rx.h"
  21. #include "dp_tx.h"
  22. #define DP_PEER_METADATA_PEER_ID_MASK 0x0000ffff
  23. #define DP_PEER_METADATA_PEER_ID_SHIFT 0
  24. #define DP_PEER_METADATA_VDEV_ID_MASK 0x00070000
  25. #define DP_PEER_METADATA_VDEV_ID_SHIFT 16
  26. #define DP_PEER_METADATA_PEER_ID_GET(_peer_metadata) \
  27. (((_peer_metadata) & DP_PEER_METADATA_PEER_ID_MASK) \
  28. >> DP_PEER_METADATA_PEER_ID_SHIFT)
  29. #define DP_PEER_METADATA_ID_GET(_peer_metadata) \
  30. (((_peer_metadata) & DP_PEER_METADATA_VDEV_ID_MASK) \
  31. >> DP_PEER_METADATA_VDEV_ID_SHIFT)
  32. /**
  33. * struct dp_rx_desc
  34. *
  35. * @nbuf : VA of the "skb" posted
  36. * @rx_buf_start : VA of the original Rx buffer, before
  37. * movement of any skb->data pointer
  38. * @cookie : index into the sw array which holds
  39. * the sw Rx descriptors
  40. * Cookie space is 21 bits:
  41. * lower 18 bits -- index
  42. * upper 3 bits -- pool_id
  43. * @pool_id : pool Id for which this allocated.
  44. * Can only be used if there is no flow
  45. * steering
  46. */
  47. struct dp_rx_desc {
  48. qdf_nbuf_t nbuf;
  49. uint8_t *rx_buf_start;
  50. uint16_t cookie;
  51. uint8_t pool_id;
  52. };
  53. #define RX_DESC_COOKIE_INDEX_SHIFT 0
  54. #define RX_DESC_COOKIE_INDEX_MASK 0x3ffff /* 18 bits */
  55. #define RX_DESC_COOKIE_POOL_ID_SHIFT 18
  56. #define RX_DESC_COOKIE_POOL_ID_MASK 0x1c0000
  57. #define DP_RX_DESC_COOKIE_POOL_ID_GET(_cookie) \
  58. (((_cookie) & RX_DESC_COOKIE_POOL_ID_MASK) >> \
  59. RX_DESC_COOKIE_POOL_ID_SHIFT)
  60. #define DP_RX_DESC_COOKIE_INDEX_GET(_cookie) \
  61. (((_cookie) & RX_DESC_COOKIE_INDEX_MASK) >> \
  62. RX_DESC_COOKIE_INDEX_SHIFT)
  63. /**
  64. * struct dp_rx_desc_list_elem_t
  65. *
  66. * @next : Next pointer to form free list
  67. * @rx_desc : DP Rx descriptor
  68. */
  69. union dp_rx_desc_list_elem_t {
  70. union dp_rx_desc_list_elem_t *next;
  71. struct dp_rx_desc rx_desc;
  72. };
  73. /**
  74. * dp_rx_cookie_2_va() - Converts cookie to a virtual address of
  75. * the Rx descriptor.
  76. * @soc: core txrx main context
  77. * @cookie: cookie used to lookup virtual address
  78. *
  79. * Return: void *: Virtual Address of the Rx descriptor
  80. */
  81. static inline
  82. void *dp_rx_cookie_2_va(struct dp_soc *soc, uint32_t cookie)
  83. {
  84. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  85. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  86. /* TODO */
  87. /* Add sanity for pool_id & index */
  88. return &(soc->rx_desc[pool_id].array[index].rx_desc);
  89. }
  90. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  91. union dp_rx_desc_list_elem_t **local_desc_list,
  92. union dp_rx_desc_list_elem_t **tail,
  93. uint16_t pool_id);
  94. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  95. uint16_t num_descs,
  96. union dp_rx_desc_list_elem_t **desc_list,
  97. union dp_rx_desc_list_elem_t **tail);
  98. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc, uint32_t pool_id);
  99. void dp_rx_desc_pool_free(struct dp_soc *soc, uint32_t pool_id);
  100. QDF_STATUS dp_rx_pdev_attach(struct dp_pdev *pdev);
  101. void dp_rx_pdev_detach(struct dp_pdev *pdev);
  102. QDF_STATUS dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  103. uint32_t num_req_buffers,
  104. union dp_rx_desc_list_elem_t **desc_list,
  105. union dp_rx_desc_list_elem_t **tail,
  106. uint8_t owner);
  107. uint32_t dp_rx_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  108. uint32_t dp_rx_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  109. uint32_t
  110. dp_rx_wbm_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  111. /**
  112. * dp_rx_add_to_free_desc_list() - Adds to a local free descriptor list
  113. *
  114. * @head: pointer to the head of local free list
  115. * @tail: pointer to the tail of local free list
  116. * @new: new descriptor that is added to the free list
  117. *
  118. * Return: void:
  119. */
  120. static inline
  121. void dp_rx_add_to_free_desc_list(union dp_rx_desc_list_elem_t **head,
  122. union dp_rx_desc_list_elem_t **tail,
  123. struct dp_rx_desc *new)
  124. {
  125. qdf_assert(head && new);
  126. new->nbuf = NULL;
  127. ((union dp_rx_desc_list_elem_t *)new)->next = *head;
  128. *head = (union dp_rx_desc_list_elem_t *)new;
  129. if (*tail == NULL)
  130. *tail = *head;
  131. }
  132. #define DP_RX_LIST_APPEND(head, tail, elem) \
  133. do { \
  134. if (!(head)) { \
  135. (head) = (elem); \
  136. } else { \
  137. qdf_nbuf_set_next((tail), (elem)); \
  138. } \
  139. (tail) = (elem); \
  140. } while (0)
  141. #endif /* _DP_RX_H */