123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- #include "dp_types.h"
- #include "dp_tx_desc.h"
- #ifndef DESC_PARTITION
- #define DP_TX_DESC_SIZE(a) qdf_get_pwr2(a)
- #define DP_TX_DESC_PAGE_DIVIDER(soc, num_desc_per_page, pool_id) \
- do { \
- uint8_t sig_bit; \
- soc->tx_desc[pool_id].offset_filter = num_desc_per_page - 1; \
- \
- sig_bit = 0; \
- while (num_desc_per_page) { \
- sig_bit++; \
- num_desc_per_page = num_desc_per_page >> 1; \
- } \
- soc->tx_desc[pool_id].page_divider = (sig_bit - 1); \
- } while (0)
- #else
- #define DP_TX_DESC_SIZE(a) a
- #define DP_TX_DESC_PAGE_DIVIDER(soc, num_desc_per_page, pool_id) {}
- #endif
- QDF_STATUS dp_tx_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
- uint16_t num_elem)
- {
- uint32_t id, count, page_id, offset, pool_id_32;
- uint16_t num_page, num_desc_per_page;
- struct dp_tx_desc_s *tx_desc_elem;
- uint32_t desc_size;
- desc_size = DP_TX_DESC_SIZE(sizeof(*tx_desc_elem));
- soc->tx_desc[pool_id].elem_size = desc_size;
- qdf_mem_multi_pages_alloc(soc->osdev,
- &soc->tx_desc[pool_id].desc_pages, desc_size, num_elem,
- 0, true);
- if (!soc->tx_desc[pool_id].desc_pages.num_pages) {
- QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
- "Multi page alloc fail, tx desc");
- goto fail_exit;
- }
- num_page = soc->tx_desc[pool_id].desc_pages.num_pages;
- num_desc_per_page =
- soc->tx_desc[pool_id].desc_pages.num_element_per_page;
- soc->tx_desc[pool_id].freelist = (struct dp_tx_desc_s *)
- *soc->tx_desc[pool_id].desc_pages.cacheable_pages;
- if (qdf_mem_multi_page_link(soc->osdev,
- &soc->tx_desc[pool_id].desc_pages, desc_size, num_elem, true)) {
- QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
- "invalid tx desc allocation - overflow num link");
- goto free_tx_desc;
- }
-
- tx_desc_elem = soc->tx_desc[pool_id].freelist;
- count = 0;
- pool_id_32 = (uint32_t)pool_id;
- while (tx_desc_elem) {
- page_id = count / num_desc_per_page;
- offset = count % num_desc_per_page;
- id = ((pool_id_32 << DP_TX_DESC_ID_POOL_OS) |
- (page_id << DP_TX_DESC_ID_PAGE_OS) | offset);
- tx_desc_elem->id = id;
- tx_desc_elem->pool_id = pool_id;
- tx_desc_elem = tx_desc_elem->next;
- count++;
- }
- TX_DESC_LOCK_CREATE(&soc->tx_desc[pool_id].lock);
- return QDF_STATUS_SUCCESS;
- free_tx_desc:
- qdf_mem_multi_pages_free(soc->osdev,
- &soc->tx_desc[pool_id].desc_pages, 0, true);
- fail_exit:
- return QDF_STATUS_E_FAULT;
- }
- QDF_STATUS dp_tx_desc_pool_free(struct dp_soc *soc, uint8_t pool_id)
- {
- qdf_mem_multi_pages_free(soc->osdev,
- &soc->tx_desc[pool_id].desc_pages, 0, true);
- TX_DESC_LOCK_DESTROY(&soc->tx_desc[pool_id].lock);
- return QDF_STATUS_SUCCESS;
- }
- QDF_STATUS dp_tx_ext_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
- uint16_t num_elem)
- {
- uint16_t num_page;
- uint32_t count;
- struct dp_tx_ext_desc_elem_s *c_elem, *p_elem;
- struct qdf_mem_dma_page_t *page_info;
- struct qdf_mem_multi_page_t *pages;
- QDF_STATUS status;
-
- soc->tx_ext_desc[pool_id].elem_size = HAL_TX_EXTENSION_DESC_LEN_BYTES;
- soc->tx_ext_desc[pool_id].elem_count = num_elem;
- qdf_mem_multi_pages_alloc(soc->osdev,
- &soc->tx_ext_desc[pool_id].desc_pages,
- soc->tx_ext_desc[pool_id].elem_size,
- soc->tx_ext_desc[pool_id].elem_count,
- qdf_get_dma_mem_context((&soc->tx_ext_desc[pool_id]), memctx),
- false);
- if (!soc->tx_ext_desc[pool_id].desc_pages.num_pages) {
- QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
- "ext desc page alloc fail");
- status = QDF_STATUS_E_NOMEM;
- goto fail_exit;
- }
- num_page = soc->tx_ext_desc[pool_id].desc_pages.num_pages;
-
- soc->tx_ext_desc[pool_id].link_elem_size =
- sizeof(struct dp_tx_ext_desc_elem_s);
- qdf_mem_multi_pages_alloc(soc->osdev,
- &soc->tx_ext_desc[pool_id].desc_link_pages,
- soc->tx_ext_desc[pool_id].link_elem_size,
- soc->tx_ext_desc[pool_id].elem_count, 0,
- true);
- if (!soc->tx_ext_desc[pool_id].desc_link_pages.num_pages) {
- QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
- "ext link desc page alloc fail");
- status = QDF_STATUS_E_NOMEM;
- goto free_ext_desc_page;
- }
-
- soc->tx_ext_desc[pool_id].freelist = (struct dp_tx_ext_desc_elem_s *)
- *soc->tx_ext_desc[pool_id].desc_link_pages.cacheable_pages;
- if (qdf_mem_multi_page_link(soc->osdev,
- &soc->tx_ext_desc[pool_id].desc_link_pages,
- soc->tx_ext_desc[pool_id].link_elem_size,
- soc->tx_ext_desc[pool_id].elem_count, true)) {
- QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
- "ext link desc page linking fail");
- status = QDF_STATUS_E_FAULT;
- goto free_ext_link_desc_page;
- }
-
- pages = &soc->tx_ext_desc[pool_id].desc_pages;
- page_info = soc->tx_ext_desc[pool_id].desc_pages.dma_pages;
- c_elem = soc->tx_ext_desc[pool_id].freelist;
- p_elem = c_elem;
- for (count = 0; count < soc->tx_ext_desc[pool_id].elem_count; count++) {
- if (!(count % pages->num_element_per_page)) {
-
- if (!pages->dma_pages->page_v_addr_start) {
- QDF_TRACE(QDF_MODULE_ID_DP,
- QDF_TRACE_LEVEL_ERROR,
- "link over flow");
- status = QDF_STATUS_E_FAULT;
- goto free_ext_link_desc_page;
- }
- c_elem->vaddr = (void *)page_info->page_v_addr_start;
- c_elem->paddr = page_info->page_p_addr;
- page_info++;
- } else {
- c_elem->vaddr = (void *)(p_elem->vaddr +
- soc->tx_ext_desc[pool_id].elem_size);
- c_elem->paddr = (p_elem->paddr +
- soc->tx_ext_desc[pool_id].elem_size);
- }
- p_elem = c_elem;
- c_elem = c_elem->next;
- if (!c_elem)
- break;
- }
- TX_DESC_LOCK_CREATE(&soc->tx_ext_desc[pool_id].lock);
- return QDF_STATUS_SUCCESS;
- free_ext_link_desc_page:
- qdf_mem_multi_pages_free(soc->osdev,
- &soc->tx_ext_desc[pool_id].desc_link_pages, 0, true);
- free_ext_desc_page:
- qdf_mem_multi_pages_free(soc->osdev,
- &soc->tx_ext_desc[pool_id].desc_pages,
- qdf_get_dma_mem_context((&soc->tx_ext_desc[pool_id]), memctx),
- false);
- fail_exit:
- return status;
- }
- QDF_STATUS dp_tx_ext_desc_pool_free(struct dp_soc *soc, uint8_t pool_id)
- {
- qdf_mem_multi_pages_free(soc->osdev,
- &soc->tx_ext_desc[pool_id].desc_link_pages, 0, true);
- qdf_mem_multi_pages_free(soc->osdev,
- &soc->tx_ext_desc[pool_id].desc_pages,
- qdf_get_dma_mem_context((&soc->tx_ext_desc[pool_id]), memctx),
- false);
- TX_DESC_LOCK_DESTROY(&soc->tx_ext_desc[pool_id].lock);
- return QDF_STATUS_SUCCESS;
- }
|