Lines Matching refs:pmc
21 static int wil_is_pmc_allocated(struct pmc_ctx *pmc) in wil_is_pmc_allocated() argument
23 return !!pmc->pring_va; in wil_is_pmc_allocated()
28 memset(&wil->pmc, 0, sizeof(struct pmc_ctx)); in wil_pmc_init()
29 mutex_init(&wil->pmc.lock); in wil_pmc_init()
44 struct pmc_ctx *pmc = &wil->pmc; in wil_pmc_alloc() local
50 mutex_lock(&pmc->lock); in wil_pmc_alloc()
52 if (wil_is_pmc_allocated(pmc)) { in wil_pmc_alloc()
81 pmc->num_descriptors = num_descriptors; in wil_pmc_alloc()
82 pmc->descriptor_size = descriptor_size; in wil_pmc_alloc()
88 pmc->descriptors = kcalloc(num_descriptors, in wil_pmc_alloc()
91 if (!pmc->descriptors) { in wil_pmc_alloc()
97 pmc->descriptors); in wil_pmc_alloc()
115 pmc->pring_va = dma_alloc_coherent(dev, in wil_pmc_alloc()
117 &pmc->pring_pa, in wil_pmc_alloc()
126 pmc->pring_va, &pmc->pring_pa, in wil_pmc_alloc()
131 if (!pmc->pring_va) { in wil_pmc_alloc()
141 struct vring_tx_desc *_d = &pmc->pring_va[i]; in wil_pmc_alloc()
145 pmc->descriptors[i].va = dma_alloc_coherent(dev, in wil_pmc_alloc()
147 &pmc->descriptors[i].pa, in wil_pmc_alloc()
150 if (unlikely(!pmc->descriptors[i].va)) { in wil_pmc_alloc()
156 u32 *p = (u32 *)pmc->descriptors[i].va + j; in wil_pmc_alloc()
162 cpu_to_le32(lower_32_bits(pmc->descriptors[i].pa)); in wil_pmc_alloc()
164 cpu_to_le16((u16)upper_32_bits(pmc->descriptors[i].pa)); in wil_pmc_alloc()
174 pmc_cmd.ring_size = cpu_to_le16(pmc->num_descriptors); in wil_pmc_alloc()
175 pmc_cmd.mem_base = cpu_to_le64(pmc->pring_pa); in wil_pmc_alloc()
178 pmc->last_cmd_status = wmi_send(wil, in wil_pmc_alloc()
183 if (pmc->last_cmd_status) { in wil_pmc_alloc()
186 pmc->last_cmd_status); in wil_pmc_alloc()
190 mutex_unlock(&pmc->lock); in wil_pmc_alloc()
196 for (i = 0; i < num_descriptors && pmc->descriptors[i].va; i++) { in wil_pmc_alloc()
199 pmc->descriptors[i].va, in wil_pmc_alloc()
200 pmc->descriptors[i].pa); in wil_pmc_alloc()
202 pmc->descriptors[i].va = NULL; in wil_pmc_alloc()
208 pmc->pring_va, in wil_pmc_alloc()
209 pmc->pring_pa); in wil_pmc_alloc()
211 pmc->pring_va = NULL; in wil_pmc_alloc()
215 kfree(pmc->descriptors); in wil_pmc_alloc()
216 pmc->descriptors = NULL; in wil_pmc_alloc()
219 pmc->last_cmd_status = last_cmd_err; in wil_pmc_alloc()
220 mutex_unlock(&pmc->lock); in wil_pmc_alloc()
228 struct pmc_ctx *pmc = &wil->pmc; in wil_pmc_free() local
233 mutex_lock(&pmc->lock); in wil_pmc_free()
235 pmc->last_cmd_status = 0; in wil_pmc_free()
237 if (!wil_is_pmc_allocated(pmc)) { in wil_pmc_free()
240 pmc->last_cmd_status = -EPERM; in wil_pmc_free()
241 mutex_unlock(&pmc->lock); in wil_pmc_free()
248 pmc->last_cmd_status = in wil_pmc_free()
251 if (pmc->last_cmd_status) { in wil_pmc_free()
254 pmc->last_cmd_status); in wil_pmc_free()
262 if (pmc->pring_va) { in wil_pmc_free()
264 pmc->num_descriptors; in wil_pmc_free()
267 pmc->pring_va); in wil_pmc_free()
268 dma_free_coherent(dev, buf_size, pmc->pring_va, pmc->pring_pa); in wil_pmc_free()
270 pmc->pring_va = NULL; in wil_pmc_free()
272 pmc->last_cmd_status = -ENOENT; in wil_pmc_free()
275 if (pmc->descriptors) { in wil_pmc_free()
279 i < pmc->num_descriptors && pmc->descriptors[i].va; i++) { in wil_pmc_free()
281 pmc->descriptor_size, in wil_pmc_free()
282 pmc->descriptors[i].va, in wil_pmc_free()
283 pmc->descriptors[i].pa); in wil_pmc_free()
284 pmc->descriptors[i].va = NULL; in wil_pmc_free()
287 pmc->num_descriptors); in wil_pmc_free()
290 pmc->descriptors); in wil_pmc_free()
291 kfree(pmc->descriptors); in wil_pmc_free()
292 pmc->descriptors = NULL; in wil_pmc_free()
294 pmc->last_cmd_status = -ENOENT; in wil_pmc_free()
297 mutex_unlock(&pmc->lock); in wil_pmc_free()
306 wil->pmc.last_cmd_status); in wil_pmc_last_cmd_status()
308 return wil->pmc.last_cmd_status; in wil_pmc_last_cmd_status()
318 struct pmc_ctx *pmc = &wil->pmc; in wil_pmc_read() local
324 mutex_lock(&pmc->lock); in wil_pmc_read()
326 if (!wil_is_pmc_allocated(pmc)) { in wil_pmc_read()
328 pmc->last_cmd_status = -EPERM; in wil_pmc_read()
329 mutex_unlock(&pmc->lock); in wil_pmc_read()
333 pmc_size = pmc->descriptor_size * pmc->num_descriptors; in wil_pmc_read()
339 pmc->last_cmd_status = 0; in wil_pmc_read()
342 do_div(idx, pmc->descriptor_size); in wil_pmc_read()
343 offset = *f_pos - (idx * pmc->descriptor_size); in wil_pmc_read()
349 pmc->last_cmd_status = -ERANGE; in wil_pmc_read()
361 pmc->descriptors[idx].va, in wil_pmc_read()
362 pmc->descriptor_size); in wil_pmc_read()
365 mutex_unlock(&pmc->lock); in wil_pmc_read()
374 struct pmc_ctx *pmc = &wil->pmc; in wil_pmc_llseek() local
377 mutex_lock(&pmc->lock); in wil_pmc_llseek()
379 if (!wil_is_pmc_allocated(pmc)) { in wil_pmc_llseek()
381 pmc->last_cmd_status = -EPERM; in wil_pmc_llseek()
382 mutex_unlock(&pmc->lock); in wil_pmc_llseek()
386 pmc_size = pmc->descriptor_size * pmc->num_descriptors; in wil_pmc_llseek()
416 mutex_unlock(&pmc->lock); in wil_pmc_llseek()
424 struct pmc_ctx *pmc = &wil->pmc; in wil_pmcring_read() local
426 sizeof(struct vring_rx_desc) * pmc->num_descriptors; in wil_pmcring_read()
428 mutex_lock(&pmc->lock); in wil_pmcring_read()
430 if (!wil_is_pmc_allocated(pmc)) { in wil_pmcring_read()
432 pmc->last_cmd_status = -EPERM; in wil_pmcring_read()
433 mutex_unlock(&pmc->lock); in wil_pmcring_read()
439 seq_write(s, pmc->pring_va, pmc_ring_size); in wil_pmcring_read()
441 mutex_unlock(&pmc->lock); in wil_pmcring_read()