Lines Matching +full:next +full:- +full:mode

1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
4 #include <linux/dma-mapping.h>
16 chain->elem_size = params->elem_size; in qed_chain_init()
17 chain->intended_use = params->intended_use; in qed_chain_init()
18 chain->mode = params->mode; in qed_chain_init()
19 chain->cnt_type = params->cnt_type; in qed_chain_init()
21 chain->elem_per_page = ELEMS_PER_PAGE(params->elem_size, in qed_chain_init()
22 params->page_size); in qed_chain_init()
23 chain->usable_per_page = USABLE_ELEMS_PER_PAGE(params->elem_size, in qed_chain_init()
24 params->page_size, in qed_chain_init()
25 params->mode); in qed_chain_init()
26 chain->elem_unusable = UNUSABLE_ELEMS_PER_PAGE(params->elem_size, in qed_chain_init()
27 params->mode); in qed_chain_init()
29 chain->elem_per_page_mask = chain->elem_per_page - 1; in qed_chain_init()
30 chain->next_page_mask = chain->usable_per_page & in qed_chain_init()
31 chain->elem_per_page_mask; in qed_chain_init()
33 chain->page_size = params->page_size; in qed_chain_init()
34 chain->page_cnt = page_cnt; in qed_chain_init()
35 chain->capacity = chain->usable_per_page * page_cnt; in qed_chain_init()
36 chain->size = chain->elem_per_page * page_cnt; in qed_chain_init()
38 if (params->ext_pbl_virt) { in qed_chain_init()
39 chain->pbl_sp.table_virt = params->ext_pbl_virt; in qed_chain_init()
40 chain->pbl_sp.table_phys = params->ext_pbl_phys; in qed_chain_init()
42 chain->b_external_pbl = true; in qed_chain_init()
50 struct qed_chain_next *next; in qed_chain_init_next_ptr_elem() local
53 size = chain->elem_size * chain->usable_per_page; in qed_chain_init_next_ptr_elem()
54 next = virt_curr + size; in qed_chain_init_next_ptr_elem()
56 DMA_REGPAIR_LE(next->next_phys, phys_next); in qed_chain_init_next_ptr_elem()
57 next->next_virt = virt_next; in qed_chain_init_next_ptr_elem()
63 chain->p_virt_addr = virt_addr; in qed_chain_init_mem()
64 chain->p_phys_addr = phys_addr; in qed_chain_init_mem()
70 struct device *dev = &cdev->pdev->dev; in qed_chain_free_next_ptr()
71 struct qed_chain_next *next; in qed_chain_free_next_ptr() local
76 size = chain->elem_size * chain->usable_per_page; in qed_chain_free_next_ptr()
77 virt = chain->p_virt_addr; in qed_chain_free_next_ptr()
78 phys = chain->p_phys_addr; in qed_chain_free_next_ptr()
80 for (i = 0; i < chain->page_cnt; i++) { in qed_chain_free_next_ptr()
84 next = virt + size; in qed_chain_free_next_ptr()
85 virt_next = next->next_virt; in qed_chain_free_next_ptr()
86 phys_next = HILO_DMA_REGPAIR(next->next_phys); in qed_chain_free_next_ptr()
88 dma_free_coherent(dev, chain->page_size, virt, phys); in qed_chain_free_next_ptr()
98 if (!chain->p_virt_addr) in qed_chain_free_single()
101 dma_free_coherent(&cdev->pdev->dev, chain->page_size, in qed_chain_free_single()
102 chain->p_virt_addr, chain->p_phys_addr); in qed_chain_free_single()
107 struct device *dev = &cdev->pdev->dev; in qed_chain_free_pbl()
111 if (!chain->pbl.pp_addr_tbl) in qed_chain_free_pbl()
114 for (i = 0; i < chain->page_cnt; i++) { in qed_chain_free_pbl()
115 entry = chain->pbl.pp_addr_tbl + i; in qed_chain_free_pbl()
116 if (!entry->virt_addr) in qed_chain_free_pbl()
119 dma_free_coherent(dev, chain->page_size, entry->virt_addr, in qed_chain_free_pbl()
120 entry->dma_map); in qed_chain_free_pbl()
123 if (!chain->b_external_pbl) in qed_chain_free_pbl()
124 dma_free_coherent(dev, chain->pbl_sp.table_size, in qed_chain_free_pbl()
125 chain->pbl_sp.table_virt, in qed_chain_free_pbl()
126 chain->pbl_sp.table_phys); in qed_chain_free_pbl()
128 vfree(chain->pbl.pp_addr_tbl); in qed_chain_free_pbl()
129 chain->pbl.pp_addr_tbl = NULL; in qed_chain_free_pbl()
133 * qed_chain_free() - Free chain DMA memory.
140 switch (chain->mode) { in qed_chain_free()
164 chain_size = ELEMS_PER_PAGE(params->elem_size, params->page_size); in qed_chain_alloc_sanity_check()
168 return -EINVAL; in qed_chain_alloc_sanity_check()
172 * taking into account the unusuable elements (next-ptr elements). in qed_chain_alloc_sanity_check()
176 switch (params->cnt_type) { in qed_chain_alloc_sanity_check()
188 return -EINVAL; in qed_chain_alloc_sanity_check()
195 return -EINVAL; in qed_chain_alloc_sanity_check()
201 struct device *dev = &cdev->pdev->dev; in qed_chain_alloc_next_ptr()
206 for (i = 0; i < chain->page_cnt; i++) { in qed_chain_alloc_next_ptr()
207 virt = dma_alloc_coherent(dev, chain->page_size, &phys, in qed_chain_alloc_next_ptr()
210 return -ENOMEM; in qed_chain_alloc_next_ptr()
223 /* Last page's next element should point to the beginning of the in qed_chain_alloc_next_ptr()
226 qed_chain_init_next_ptr_elem(chain, virt_prev, chain->p_virt_addr, in qed_chain_alloc_next_ptr()
227 chain->p_phys_addr); in qed_chain_alloc_next_ptr()
238 virt = dma_alloc_coherent(&cdev->pdev->dev, chain->page_size, in qed_chain_alloc_single()
241 return -ENOMEM; in qed_chain_alloc_single()
251 struct device *dev = &cdev->pdev->dev; in qed_chain_alloc_pbl()
259 page_cnt = chain->page_cnt; in qed_chain_alloc_pbl()
263 return -EOVERFLOW; in qed_chain_alloc_pbl()
267 return -ENOMEM; in qed_chain_alloc_pbl()
269 chain->pbl.pp_addr_tbl = addr_tbl; in qed_chain_alloc_pbl()
271 if (chain->b_external_pbl) { in qed_chain_alloc_pbl()
272 pbl_virt = chain->pbl_sp.table_virt; in qed_chain_alloc_pbl()
278 return -EOVERFLOW; in qed_chain_alloc_pbl()
282 return -ENOMEM; in qed_chain_alloc_pbl()
284 chain->pbl_sp.table_virt = pbl_virt; in qed_chain_alloc_pbl()
285 chain->pbl_sp.table_phys = pbl_phys; in qed_chain_alloc_pbl()
286 chain->pbl_sp.table_size = size; in qed_chain_alloc_pbl()
290 virt = dma_alloc_coherent(dev, chain->page_size, &phys, in qed_chain_alloc_pbl()
293 return -ENOMEM; in qed_chain_alloc_pbl()
312 * qed_chain_alloc() - Allocate and initialize a chain.
326 if (!params->page_size) in qed_chain_alloc()
327 params->page_size = QED_CHAIN_PAGE_SIZE; in qed_chain_alloc()
329 if (params->mode == QED_CHAIN_MODE_SINGLE) in qed_chain_alloc()
332 page_cnt = QED_CHAIN_PAGE_CNT(params->num_elems, in qed_chain_alloc()
333 params->elem_size, in qed_chain_alloc()
334 params->page_size, in qed_chain_alloc()
335 params->mode); in qed_chain_alloc()
342 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu, page_size %u]\n", in qed_chain_alloc()
343 params->intended_use, params->mode, params->cnt_type, in qed_chain_alloc()
344 params->num_elems, params->elem_size, in qed_chain_alloc()
345 params->page_size); in qed_chain_alloc()
351 switch (params->mode) { in qed_chain_alloc()
362 return -EINVAL; in qed_chain_alloc()