• Home
  • Raw
  • Download

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]) \
137 static int wqs_allocate_page(struct hinic_wqs *wqs, int page_idx) in wqs_allocate_page() argument
139 return queue_alloc_page(wqs->hwif, &wqs->page_vaddr[page_idx], in wqs_allocate_page()
140 &wqs->page_paddr[page_idx], in wqs_allocate_page()
141 &wqs->shadow_page_vaddr[page_idx], in wqs_allocate_page()
150 static void wqs_free_page(struct hinic_wqs *wqs, int page_idx) in wqs_free_page() argument
152 struct hinic_hwif *hwif = wqs->hwif; in wqs_free_page()
156 wqs->page_vaddr[page_idx], in wqs_free_page()
157 (dma_addr_t)wqs->page_paddr[page_idx]); in wqs_free_page()
158 vfree(wqs->shadow_page_vaddr[page_idx]); in wqs_free_page()
192 static int alloc_page_arrays(struct hinic_wqs *wqs) in alloc_page_arrays() argument
194 struct hinic_hwif *hwif = wqs->hwif; in alloc_page_arrays()
197 wqs->page_paddr = devm_kcalloc(&pdev->dev, wqs->num_pages, in alloc_page_arrays()
198 sizeof(*wqs->page_paddr), GFP_KERNEL); in alloc_page_arrays()
199 if (!wqs->page_paddr) in alloc_page_arrays()
202 wqs->page_vaddr = devm_kcalloc(&pdev->dev, wqs->num_pages, in alloc_page_arrays()
203 sizeof(*wqs->page_vaddr), GFP_KERNEL); in alloc_page_arrays()
204 if (!wqs->page_vaddr) in alloc_page_arrays()
207 wqs->shadow_page_vaddr = devm_kcalloc(&pdev->dev, wqs->num_pages, in alloc_page_arrays()
208 sizeof(*wqs->shadow_page_vaddr), in alloc_page_arrays()
210 if (!wqs->shadow_page_vaddr) in alloc_page_arrays()
216 devm_kfree(&pdev->dev, wqs->page_vaddr); in alloc_page_arrays()
219 devm_kfree(&pdev->dev, wqs->page_paddr); in alloc_page_arrays()
223 static void free_page_arrays(struct hinic_wqs *wqs) in free_page_arrays() argument
225 struct hinic_hwif *hwif = wqs->hwif; in free_page_arrays()
228 devm_kfree(&pdev->dev, wqs->shadow_page_vaddr); in free_page_arrays()
229 devm_kfree(&pdev->dev, wqs->page_vaddr); in free_page_arrays()
230 devm_kfree(&pdev->dev, wqs->page_paddr); in free_page_arrays()
233 static int wqs_next_block(struct hinic_wqs *wqs, int *page_idx, in wqs_next_block() argument
238 down(&wqs->alloc_blocks_lock); in wqs_next_block()
240 wqs->num_free_blks--; in wqs_next_block()
242 if (wqs->num_free_blks < 0) { in wqs_next_block()
243 wqs->num_free_blks++; in wqs_next_block()
244 up(&wqs->alloc_blocks_lock); in wqs_next_block()
248 pos = wqs->alloc_blk_pos++; in wqs_next_block()
251 *page_idx = wqs->free_blocks[pos].page_idx; in wqs_next_block()
252 *block_idx = wqs->free_blocks[pos].block_idx; in wqs_next_block()
254 wqs->free_blocks[pos].page_idx = -1; in wqs_next_block()
255 wqs->free_blocks[pos].block_idx = -1; in wqs_next_block()
257 up(&wqs->alloc_blocks_lock); in wqs_next_block()
261 static void wqs_return_block(struct hinic_wqs *wqs, int page_idx, in wqs_return_block() argument
266 down(&wqs->alloc_blocks_lock); in wqs_return_block()
268 pos = wqs->return_blk_pos++; in wqs_return_block()
271 wqs->free_blocks[pos].page_idx = page_idx; in wqs_return_block()
272 wqs->free_blocks[pos].block_idx = block_idx; in wqs_return_block()
274 wqs->num_free_blks++; in wqs_return_block()
276 up(&wqs->alloc_blocks_lock); in wqs_return_block()
279 static void init_wqs_blocks_arr(struct hinic_wqs *wqs) in init_wqs_blocks_arr() argument
283 for (page_idx = 0; page_idx < wqs->num_pages; page_idx++) { in init_wqs_blocks_arr()
285 wqs->free_blocks[pos].page_idx = page_idx; in init_wqs_blocks_arr()
286 wqs->free_blocks[pos].block_idx = blk_idx; in init_wqs_blocks_arr()
291 wqs->alloc_blk_pos = 0; in init_wqs_blocks_arr()
292 wqs->return_blk_pos = pos; in init_wqs_blocks_arr()
293 wqs->num_free_blks = pos; in init_wqs_blocks_arr()
295 sema_init(&wqs->alloc_blocks_lock, 1); in init_wqs_blocks_arr()
306 int hinic_wqs_alloc(struct hinic_wqs *wqs, int max_wqs, in hinic_wqs_alloc() argument
318 wqs->hwif = hwif; in hinic_wqs_alloc()
319 wqs->num_pages = max_wqs / WQS_BLOCKS_PER_PAGE; in hinic_wqs_alloc()
321 if (alloc_page_arrays(wqs)) { in hinic_wqs_alloc()
327 for (page_idx = 0; page_idx < wqs->num_pages; page_idx++) { in hinic_wqs_alloc()
328 err = wqs_allocate_page(wqs, page_idx); in hinic_wqs_alloc()
335 wqs->free_blocks = devm_kzalloc(&pdev->dev, WQS_FREE_BLOCKS_SIZE(wqs), in hinic_wqs_alloc()
337 if (!wqs->free_blocks) { in hinic_wqs_alloc()
342 init_wqs_blocks_arr(wqs); in hinic_wqs_alloc()
348 wqs_free_page(wqs, i); in hinic_wqs_alloc()
350 free_page_arrays(wqs); in hinic_wqs_alloc()
358 void hinic_wqs_free(struct hinic_wqs *wqs) in hinic_wqs_free() argument
360 struct hinic_hwif *hwif = wqs->hwif; in hinic_wqs_free()
364 devm_kfree(&pdev->dev, wqs->free_blocks); in hinic_wqs_free()
366 for (page_idx = 0; page_idx < wqs->num_pages; page_idx++) in hinic_wqs_free()
367 wqs_free_page(wqs, page_idx); in hinic_wqs_free()
369 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()