Lines Matching full:chain
10 static void qed_chain_init(struct qed_chain *chain, in qed_chain_init() argument
14 memset(chain, 0, sizeof(*chain)); in qed_chain_init()
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()
23 chain->usable_per_page = USABLE_ELEMS_PER_PAGE(params->elem_size, in qed_chain_init()
26 chain->elem_unusable = UNUSABLE_ELEMS_PER_PAGE(params->elem_size, 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()
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()
46 static void qed_chain_init_next_ptr_elem(const struct qed_chain *chain, in qed_chain_init_next_ptr_elem() argument
53 size = chain->elem_size * chain->usable_per_page; in qed_chain_init_next_ptr_elem()
60 static void qed_chain_init_mem(struct qed_chain *chain, void *virt_addr, in qed_chain_init_mem() argument
63 chain->p_virt_addr = virt_addr; in qed_chain_init_mem()
64 chain->p_phys_addr = phys_addr; in qed_chain_init_mem()
68 struct qed_chain *chain) in qed_chain_free_next_ptr() argument
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()
88 dma_free_coherent(dev, chain->page_size, virt, phys); in qed_chain_free_next_ptr()
96 struct qed_chain *chain) in qed_chain_free_single() argument
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()
105 static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *chain) in qed_chain_free_pbl() argument
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()
119 dma_free_coherent(dev, chain->page_size, entry->virt_addr, 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.
136 * @chain: Chain to free.
138 void qed_chain_free(struct qed_dev *cdev, struct qed_chain *chain) in qed_chain_free() argument
140 switch (chain->mode) { in qed_chain_free()
142 qed_chain_free_next_ptr(cdev, chain); in qed_chain_free()
145 qed_chain_free_single(cdev, chain); in qed_chain_free()
148 qed_chain_free_pbl(cdev, chain); in qed_chain_free()
154 qed_chain_init_mem(chain, NULL, 0); in qed_chain_free()
170 /* The actual chain size can be larger than the maximal possible value in qed_chain_alloc_sanity_check()
173 * The size of a "u16" chain can be (U16_MAX + 1) since the chain in qed_chain_alloc_sanity_check()
192 "The actual chain size (0x%llx) is larger than the maximal possible value\n", in qed_chain_alloc_sanity_check()
199 struct qed_chain *chain) in qed_chain_alloc_next_ptr() argument
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()
213 qed_chain_init_mem(chain, virt, phys); in qed_chain_alloc_next_ptr()
214 qed_chain_reset(chain); in qed_chain_alloc_next_ptr()
216 qed_chain_init_next_ptr_elem(chain, virt_prev, virt, in qed_chain_alloc_next_ptr()
224 * chain. 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()
233 struct qed_chain *chain) in qed_chain_alloc_single() argument
238 virt = dma_alloc_coherent(&cdev->pdev->dev, chain->page_size, in qed_chain_alloc_single()
243 qed_chain_init_mem(chain, virt, phys); in qed_chain_alloc_single()
244 qed_chain_reset(chain); in qed_chain_alloc_single()
249 static int qed_chain_alloc_pbl(struct qed_dev *cdev, struct qed_chain *chain) in qed_chain_alloc_pbl() argument
259 page_cnt = chain->page_cnt; 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()
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()
296 qed_chain_init_mem(chain, virt, phys); in qed_chain_alloc_pbl()
297 qed_chain_reset(chain); in qed_chain_alloc_pbl()
312 * qed_chain_alloc() - Allocate and initialize a chain.
315 * @chain: Chain to be processed.
316 * @params: Chain initialization parameters.
320 int qed_chain_alloc(struct qed_dev *cdev, struct qed_chain *chain, in qed_chain_alloc() argument
340 "Cannot allocate a chain with the given arguments:\n"); in qed_chain_alloc()
349 qed_chain_init(chain, params, page_cnt); in qed_chain_alloc()
353 rc = qed_chain_alloc_next_ptr(cdev, chain); in qed_chain_alloc()
356 rc = qed_chain_alloc_single(cdev, chain); in qed_chain_alloc()
359 rc = qed_chain_alloc_pbl(cdev, chain); in qed_chain_alloc()
368 qed_chain_free(cdev, chain); in qed_chain_alloc()