Lines Matching refs:pmc
32 static int wil_is_pmc_allocated(struct pmc_ctx *pmc) in wil_is_pmc_allocated() argument
34 return !!pmc->pring_va; in wil_is_pmc_allocated()
39 memset(&wil->pmc, 0, sizeof(struct pmc_ctx)); in wil_pmc_init()
40 mutex_init(&wil->pmc.lock); in wil_pmc_init()
56 struct pmc_ctx *pmc = &wil->pmc; in wil_pmc_alloc() local
62 mutex_lock(&pmc->lock); in wil_pmc_alloc()
64 if (wil_is_pmc_allocated(pmc)) { in wil_pmc_alloc()
93 pmc->num_descriptors = num_descriptors; in wil_pmc_alloc()
94 pmc->descriptor_size = descriptor_size; in wil_pmc_alloc()
100 pmc->descriptors = kcalloc(num_descriptors, in wil_pmc_alloc()
103 if (!pmc->descriptors) { in wil_pmc_alloc()
109 pmc->descriptors); in wil_pmc_alloc()
127 pmc->pring_va = dma_alloc_coherent(dev, in wil_pmc_alloc()
129 &pmc->pring_pa, in wil_pmc_alloc()
138 pmc->pring_va, &pmc->pring_pa, in wil_pmc_alloc()
143 if (!pmc->pring_va) { in wil_pmc_alloc()
153 struct vring_tx_desc *_d = &pmc->pring_va[i]; in wil_pmc_alloc()
157 pmc->descriptors[i].va = dma_alloc_coherent(dev, in wil_pmc_alloc()
159 &pmc->descriptors[i].pa, in wil_pmc_alloc()
162 if (unlikely(!pmc->descriptors[i].va)) { in wil_pmc_alloc()
168 u32 *p = (u32 *)pmc->descriptors[i].va + j; in wil_pmc_alloc()
174 cpu_to_le32(lower_32_bits(pmc->descriptors[i].pa)); in wil_pmc_alloc()
176 cpu_to_le16((u16)upper_32_bits(pmc->descriptors[i].pa)); in wil_pmc_alloc()
186 pmc_cmd.ring_size = cpu_to_le16(pmc->num_descriptors); in wil_pmc_alloc()
187 pmc_cmd.mem_base = cpu_to_le64(pmc->pring_pa); in wil_pmc_alloc()
190 pmc->last_cmd_status = wmi_send(wil, in wil_pmc_alloc()
195 if (pmc->last_cmd_status) { in wil_pmc_alloc()
198 pmc->last_cmd_status); in wil_pmc_alloc()
202 mutex_unlock(&pmc->lock); in wil_pmc_alloc()
208 for (i = 0; i < num_descriptors && pmc->descriptors[i].va; i++) { in wil_pmc_alloc()
211 pmc->descriptors[i].va, in wil_pmc_alloc()
212 pmc->descriptors[i].pa); in wil_pmc_alloc()
214 pmc->descriptors[i].va = NULL; in wil_pmc_alloc()
220 pmc->pring_va, in wil_pmc_alloc()
221 pmc->pring_pa); in wil_pmc_alloc()
223 pmc->pring_va = NULL; in wil_pmc_alloc()
227 kfree(pmc->descriptors); in wil_pmc_alloc()
228 pmc->descriptors = NULL; in wil_pmc_alloc()
231 pmc->last_cmd_status = last_cmd_err; in wil_pmc_alloc()
232 mutex_unlock(&pmc->lock); in wil_pmc_alloc()
241 struct pmc_ctx *pmc = &wil->pmc; in wil_pmc_free() local
246 mutex_lock(&pmc->lock); in wil_pmc_free()
248 pmc->last_cmd_status = 0; in wil_pmc_free()
250 if (!wil_is_pmc_allocated(pmc)) { in wil_pmc_free()
253 pmc->last_cmd_status = -EPERM; in wil_pmc_free()
254 mutex_unlock(&pmc->lock); in wil_pmc_free()
261 pmc->last_cmd_status = in wil_pmc_free()
264 if (pmc->last_cmd_status) { in wil_pmc_free()
267 pmc->last_cmd_status); in wil_pmc_free()
275 if (pmc->pring_va) { in wil_pmc_free()
277 pmc->num_descriptors; in wil_pmc_free()
280 pmc->pring_va); in wil_pmc_free()
281 dma_free_coherent(dev, buf_size, pmc->pring_va, pmc->pring_pa); in wil_pmc_free()
283 pmc->pring_va = NULL; in wil_pmc_free()
285 pmc->last_cmd_status = -ENOENT; in wil_pmc_free()
288 if (pmc->descriptors) { in wil_pmc_free()
292 i < pmc->num_descriptors && pmc->descriptors[i].va; i++) { in wil_pmc_free()
294 pmc->descriptor_size, in wil_pmc_free()
295 pmc->descriptors[i].va, in wil_pmc_free()
296 pmc->descriptors[i].pa); in wil_pmc_free()
297 pmc->descriptors[i].va = NULL; in wil_pmc_free()
300 pmc->num_descriptors); in wil_pmc_free()
303 pmc->descriptors); in wil_pmc_free()
304 kfree(pmc->descriptors); in wil_pmc_free()
305 pmc->descriptors = NULL; in wil_pmc_free()
307 pmc->last_cmd_status = -ENOENT; in wil_pmc_free()
310 mutex_unlock(&pmc->lock); in wil_pmc_free()
320 wil->pmc.last_cmd_status); in wil_pmc_last_cmd_status()
322 return wil->pmc.last_cmd_status; in wil_pmc_last_cmd_status()
333 struct pmc_ctx *pmc = &wil->pmc; in wil_pmc_read() local
339 mutex_lock(&pmc->lock); in wil_pmc_read()
341 if (!wil_is_pmc_allocated(pmc)) { in wil_pmc_read()
343 pmc->last_cmd_status = -EPERM; in wil_pmc_read()
344 mutex_unlock(&pmc->lock); in wil_pmc_read()
348 pmc_size = pmc->descriptor_size * pmc->num_descriptors; in wil_pmc_read()
354 pmc->last_cmd_status = 0; in wil_pmc_read()
357 do_div(idx, pmc->descriptor_size); in wil_pmc_read()
358 offset = *f_pos - (idx * pmc->descriptor_size); in wil_pmc_read()
364 pmc->last_cmd_status = -ERANGE; in wil_pmc_read()
376 pmc->descriptors[idx].va, in wil_pmc_read()
377 pmc->descriptor_size); in wil_pmc_read()
380 mutex_unlock(&pmc->lock); in wil_pmc_read()
389 struct pmc_ctx *pmc = &wil->pmc; in wil_pmc_llseek() local
392 mutex_lock(&pmc->lock); in wil_pmc_llseek()
394 if (!wil_is_pmc_allocated(pmc)) { in wil_pmc_llseek()
396 pmc->last_cmd_status = -EPERM; in wil_pmc_llseek()
397 mutex_unlock(&pmc->lock); in wil_pmc_llseek()
401 pmc_size = pmc->descriptor_size * pmc->num_descriptors; in wil_pmc_llseek()
431 mutex_unlock(&pmc->lock); in wil_pmc_llseek()
439 struct pmc_ctx *pmc = &wil->pmc; in wil_pmcring_read() local
441 sizeof(struct vring_rx_desc) * pmc->num_descriptors; in wil_pmcring_read()
443 mutex_lock(&pmc->lock); in wil_pmcring_read()
445 if (!wil_is_pmc_allocated(pmc)) { in wil_pmcring_read()
447 pmc->last_cmd_status = -EPERM; in wil_pmcring_read()
448 mutex_unlock(&pmc->lock); in wil_pmcring_read()
454 seq_write(s, pmc->pring_va, pmc_ring_size); in wil_pmcring_read()
456 mutex_unlock(&pmc->lock); in wil_pmcring_read()