Lines Matching refs:wqs

31 #define WQS_FREE_BLOCKS_SIZE(wqs)       (WQS_MAX_NUM_BLOCKS * \  argument
32 sizeof((wqs)->free_blocks[0]))
44 #define WQ_BASE_VADDR(wqs, wq) \ argument
45 ((void *)((wqs)->page_vaddr[(wq)->page_idx]) \
48 #define WQ_BASE_PADDR(wqs, wq) \ argument
49 ((wqs)->page_paddr[(wq)->page_idx] \
52 #define WQ_BASE_ADDR(wqs, wq) \ argument
53 ((void *)((wqs)->shadow_page_vaddr[(wq)->page_idx]) \
136 static int wqs_allocate_page(struct hinic_wqs *wqs, int page_idx) in wqs_allocate_page() argument
138 return queue_alloc_page(wqs->hwif, &wqs->page_vaddr[page_idx], in wqs_allocate_page()
139 &wqs->page_paddr[page_idx], in wqs_allocate_page()
140 &wqs->shadow_page_vaddr[page_idx], in wqs_allocate_page()
149 static void wqs_free_page(struct hinic_wqs *wqs, int page_idx) in wqs_free_page() argument
151 struct hinic_hwif *hwif = wqs->hwif; in wqs_free_page()
155 wqs->page_vaddr[page_idx], in wqs_free_page()
156 (dma_addr_t)wqs->page_paddr[page_idx]); in wqs_free_page()
157 vfree(wqs->shadow_page_vaddr[page_idx]); in wqs_free_page()
191 static int alloc_page_arrays(struct hinic_wqs *wqs) in alloc_page_arrays() argument
193 struct hinic_hwif *hwif = wqs->hwif; in alloc_page_arrays()
197 size = wqs->num_pages * sizeof(*wqs->page_paddr); in alloc_page_arrays()
198 wqs->page_paddr = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); in alloc_page_arrays()
199 if (!wqs->page_paddr) in alloc_page_arrays()
202 size = wqs->num_pages * sizeof(*wqs->page_vaddr); in alloc_page_arrays()
203 wqs->page_vaddr = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); in alloc_page_arrays()
204 if (!wqs->page_vaddr) in alloc_page_arrays()
207 size = wqs->num_pages * sizeof(*wqs->shadow_page_vaddr); in alloc_page_arrays()
208 wqs->shadow_page_vaddr = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); in alloc_page_arrays()
209 if (!wqs->shadow_page_vaddr) in alloc_page_arrays()
215 devm_kfree(&pdev->dev, wqs->page_vaddr); in alloc_page_arrays()
218 devm_kfree(&pdev->dev, wqs->page_paddr); in alloc_page_arrays()
222 static void free_page_arrays(struct hinic_wqs *wqs) in free_page_arrays() argument
224 struct hinic_hwif *hwif = wqs->hwif; in free_page_arrays()
227 devm_kfree(&pdev->dev, wqs->shadow_page_vaddr); in free_page_arrays()
228 devm_kfree(&pdev->dev, wqs->page_vaddr); in free_page_arrays()
229 devm_kfree(&pdev->dev, wqs->page_paddr); in free_page_arrays()
232 static int wqs_next_block(struct hinic_wqs *wqs, int *page_idx, in wqs_next_block() argument
237 down(&wqs->alloc_blocks_lock); in wqs_next_block()
239 wqs->num_free_blks--; in wqs_next_block()
241 if (wqs->num_free_blks < 0) { in wqs_next_block()
242 wqs->num_free_blks++; in wqs_next_block()
243 up(&wqs->alloc_blocks_lock); in wqs_next_block()
247 pos = wqs->alloc_blk_pos++; in wqs_next_block()
250 *page_idx = wqs->free_blocks[pos].page_idx; in wqs_next_block()
251 *block_idx = wqs->free_blocks[pos].block_idx; in wqs_next_block()
253 wqs->free_blocks[pos].page_idx = -1; in wqs_next_block()
254 wqs->free_blocks[pos].block_idx = -1; in wqs_next_block()
256 up(&wqs->alloc_blocks_lock); in wqs_next_block()
260 static void wqs_return_block(struct hinic_wqs *wqs, int page_idx, in wqs_return_block() argument
265 down(&wqs->alloc_blocks_lock); in wqs_return_block()
267 pos = wqs->return_blk_pos++; in wqs_return_block()
270 wqs->free_blocks[pos].page_idx = page_idx; in wqs_return_block()
271 wqs->free_blocks[pos].block_idx = block_idx; in wqs_return_block()
273 wqs->num_free_blks++; in wqs_return_block()
275 up(&wqs->alloc_blocks_lock); in wqs_return_block()
278 static void init_wqs_blocks_arr(struct hinic_wqs *wqs) in init_wqs_blocks_arr() argument
282 for (page_idx = 0; page_idx < wqs->num_pages; page_idx++) { in init_wqs_blocks_arr()
284 wqs->free_blocks[pos].page_idx = page_idx; in init_wqs_blocks_arr()
285 wqs->free_blocks[pos].block_idx = blk_idx; in init_wqs_blocks_arr()
290 wqs->alloc_blk_pos = 0; in init_wqs_blocks_arr()
291 wqs->return_blk_pos = pos; in init_wqs_blocks_arr()
292 wqs->num_free_blks = pos; in init_wqs_blocks_arr()
294 sema_init(&wqs->alloc_blocks_lock, 1); in init_wqs_blocks_arr()
305 int hinic_wqs_alloc(struct hinic_wqs *wqs, int max_wqs, in hinic_wqs_alloc() argument
317 wqs->hwif = hwif; in hinic_wqs_alloc()
318 wqs->num_pages = max_wqs / WQS_BLOCKS_PER_PAGE; in hinic_wqs_alloc()
320 if (alloc_page_arrays(wqs)) { in hinic_wqs_alloc()
326 for (page_idx = 0; page_idx < wqs->num_pages; page_idx++) { in hinic_wqs_alloc()
327 err = wqs_allocate_page(wqs, page_idx); in hinic_wqs_alloc()
334 wqs->free_blocks = devm_kzalloc(&pdev->dev, WQS_FREE_BLOCKS_SIZE(wqs), in hinic_wqs_alloc()
336 if (!wqs->free_blocks) { in hinic_wqs_alloc()
341 init_wqs_blocks_arr(wqs); in hinic_wqs_alloc()
347 wqs_free_page(wqs, i); in hinic_wqs_alloc()
349 free_page_arrays(wqs); in hinic_wqs_alloc()
357 void hinic_wqs_free(struct hinic_wqs *wqs) in hinic_wqs_free() argument
359 struct hinic_hwif *hwif = wqs->hwif; in hinic_wqs_free()
363 devm_kfree(&pdev->dev, wqs->free_blocks); in hinic_wqs_free()
365 for (page_idx = 0; page_idx < wqs->num_pages; page_idx++) in hinic_wqs_free()
366 wqs_free_page(wqs, page_idx); in hinic_wqs_free()
368 free_page_arrays(wqs); in hinic_wqs_free()
505 int hinic_wq_allocate(struct hinic_wqs *wqs, struct hinic_wq *wq, in hinic_wq_allocate() argument
509 struct hinic_hwif *hwif = wqs->hwif; in hinic_wq_allocate()
541 err = wqs_next_block(wqs, &wq->page_idx, &wq->block_idx); in hinic_wq_allocate()
554 wq->block_vaddr = WQ_BASE_VADDR(wqs, wq); in hinic_wq_allocate()
555 wq->shadow_block_vaddr = WQ_BASE_ADDR(wqs, wq); in hinic_wq_allocate()
556 wq->block_paddr = WQ_BASE_PADDR(wqs, wq); in hinic_wq_allocate()
558 err = alloc_wq_pages(wq, wqs->hwif, WQ_MAX_PAGES); in hinic_wq_allocate()
572 wqs_return_block(wqs, wq->page_idx, wq->block_idx); in hinic_wq_allocate()
581 void hinic_wq_free(struct hinic_wqs *wqs, struct hinic_wq *wq) in hinic_wq_free() argument
583 free_wq_pages(wq, wqs->hwif, wq->num_q_pages); in hinic_wq_free()
585 wqs_return_block(wqs, wq->page_idx, wq->block_idx); in hinic_wq_free()