dp_rx.h 4.7 KB

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