Lines Matching +full:fixed +full:- +full:size
1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
12 int ath11k_dbring_validate_buffer(struct ath11k *ar, void *buffer, u32 size) in ath11k_dbring_validate_buffer() argument
17 size = size >> 2; in ath11k_dbring_validate_buffer()
19 for (idx = 0, temp = buffer; idx < size; idx++, temp++) { in ath11k_dbring_validate_buffer()
21 return -EINVAL; in ath11k_dbring_validate_buffer()
28 void *buffer, u32 size) in ath11k_dbring_fill_magic_value() argument
31 * and the variable size is expected to be the number of u32 values in ath11k_dbring_fill_magic_value()
34 size = size / sizeof(u32); in ath11k_dbring_fill_magic_value()
36 memset32(buffer, ATH11K_DB_MAGIC_VALUE, size); in ath11k_dbring_fill_magic_value()
44 struct ath11k_base *ab = ar->ab; in ath11k_dbring_bufs_replenish()
52 srng = &ab->hal.srng_list[ring->refill_srng.ring_id]; in ath11k_dbring_bufs_replenish()
54 lockdep_assert_held(&srng->lock); in ath11k_dbring_bufs_replenish()
58 ptr_unaligned = buff->payload; in ath11k_dbring_bufs_replenish()
59 ptr_aligned = PTR_ALIGN(ptr_unaligned, ring->buf_align); in ath11k_dbring_bufs_replenish()
60 ath11k_dbring_fill_magic_value(ar, ptr_aligned, ring->buf_sz); in ath11k_dbring_bufs_replenish()
61 paddr = dma_map_single(ab->dev, ptr_aligned, ring->buf_sz, in ath11k_dbring_bufs_replenish()
64 ret = dma_mapping_error(ab->dev, paddr); in ath11k_dbring_bufs_replenish()
68 spin_lock_bh(&ring->idr_lock); in ath11k_dbring_bufs_replenish()
69 buf_id = idr_alloc(&ring->bufs_idr, buff, 0, ring->bufs_max, GFP_ATOMIC); in ath11k_dbring_bufs_replenish()
70 spin_unlock_bh(&ring->idr_lock); in ath11k_dbring_bufs_replenish()
72 ret = -ENOBUFS; in ath11k_dbring_bufs_replenish()
78 ret = -ENOENT; in ath11k_dbring_bufs_replenish()
82 buff->paddr = paddr; in ath11k_dbring_bufs_replenish()
84 cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, ar->pdev_idx) | in ath11k_dbring_bufs_replenish()
95 spin_lock_bh(&ring->idr_lock); in ath11k_dbring_bufs_replenish()
96 idr_remove(&ring->bufs_idr, buf_id); in ath11k_dbring_bufs_replenish()
97 spin_unlock_bh(&ring->idr_lock); in ath11k_dbring_bufs_replenish()
99 dma_unmap_single(ab->dev, paddr, ring->buf_sz, in ath11k_dbring_bufs_replenish()
114 int size, ret; in ath11k_dbring_fill_bufs() local
116 srng = &ar->ab->hal.srng_list[ring->refill_srng.ring_id]; in ath11k_dbring_fill_bufs()
118 spin_lock_bh(&srng->lock); in ath11k_dbring_fill_bufs()
120 num_free = ath11k_hal_srng_src_num_free(ar->ab, srng, true); in ath11k_dbring_fill_bufs()
121 req_entries = min(num_free, ring->bufs_max); in ath11k_dbring_fill_bufs()
123 align = ring->buf_align; in ath11k_dbring_fill_bufs()
124 size = ring->buf_sz + align - 1; in ath11k_dbring_fill_bufs()
131 buff->payload = kzalloc(size, GFP_ATOMIC); in ath11k_dbring_fill_bufs()
132 if (!buff->payload) { in ath11k_dbring_fill_bufs()
138 ath11k_warn(ar->ab, "failed to replenish db ring num_remain %d req_ent %d\n", in ath11k_dbring_fill_bufs()
140 kfree(buff->payload); in ath11k_dbring_fill_bufs()
144 num_remain--; in ath11k_dbring_fill_bufs()
147 spin_unlock_bh(&srng->lock); in ath11k_dbring_fill_bufs()
160 return -EINVAL; in ath11k_dbring_wmi_cfg_setup()
162 param.pdev_id = DP_SW2HW_MACID(ring->pdev_id); in ath11k_dbring_wmi_cfg_setup()
164 param.base_paddr_lo = lower_32_bits(ring->refill_srng.paddr); in ath11k_dbring_wmi_cfg_setup()
165 param.base_paddr_hi = upper_32_bits(ring->refill_srng.paddr); in ath11k_dbring_wmi_cfg_setup()
166 param.head_idx_paddr_lo = lower_32_bits(ring->hp_addr); in ath11k_dbring_wmi_cfg_setup()
167 param.head_idx_paddr_hi = upper_32_bits(ring->hp_addr); in ath11k_dbring_wmi_cfg_setup()
168 param.tail_idx_paddr_lo = lower_32_bits(ring->tp_addr); in ath11k_dbring_wmi_cfg_setup()
169 param.tail_idx_paddr_hi = upper_32_bits(ring->tp_addr); in ath11k_dbring_wmi_cfg_setup()
170 param.num_elems = ring->bufs_max; in ath11k_dbring_wmi_cfg_setup()
171 param.buf_size = ring->buf_sz; in ath11k_dbring_wmi_cfg_setup()
172 param.num_resp_per_event = ring->num_resp_per_event; in ath11k_dbring_wmi_cfg_setup()
173 param.event_timeout_ms = ring->event_timeout_ms; in ath11k_dbring_wmi_cfg_setup()
177 ath11k_warn(ar->ab, "failed to setup db ring cfg\n"); in ath11k_dbring_wmi_cfg_setup()
190 return -EINVAL; in ath11k_dbring_set_cfg()
192 ring->num_resp_per_event = num_resp_per_event; in ath11k_dbring_set_cfg()
193 ring->event_timeout_ms = event_timeout_ms; in ath11k_dbring_set_cfg()
194 ring->handler = handler; in ath11k_dbring_set_cfg()
203 struct ath11k_base *ab = ar->ab; in ath11k_dbring_buf_setup()
207 srng = &ab->hal.srng_list[ring->refill_srng.ring_id]; in ath11k_dbring_buf_setup()
208 ring->bufs_max = ring->refill_srng.size / in ath11k_dbring_buf_setup()
211 ring->buf_sz = db_cap->min_buf_sz; in ath11k_dbring_buf_setup()
212 ring->buf_align = db_cap->min_buf_align; in ath11k_dbring_buf_setup()
213 ring->pdev_id = db_cap->pdev_id; in ath11k_dbring_buf_setup()
214 ring->hp_addr = ath11k_hal_srng_get_hp_addr(ar->ab, srng); in ath11k_dbring_buf_setup()
215 ring->tp_addr = ath11k_hal_srng_get_tp_addr(ar->ab, srng); in ath11k_dbring_buf_setup()
217 ret = ath11k_dbring_fill_bufs(ar, ring, db_cap->id); in ath11k_dbring_buf_setup()
227 ret = ath11k_dp_srng_setup(ar->ab, &ring->refill_srng, HAL_RXDMA_DIR_BUF, in ath11k_dbring_srng_setup()
228 ring_num, ar->pdev_idx, num_entries); in ath11k_dbring_srng_setup()
230 ath11k_warn(ar->ab, "failed to setup srng: %d ring_id %d\n", in ath11k_dbring_srng_setup()
237 ath11k_dp_srng_cleanup(ar->ab, &ring->refill_srng); in ath11k_dbring_srng_setup()
248 if (!ab->num_db_cap || !ab->db_caps) in ath11k_dbring_get_cap()
249 return -ENOENT; in ath11k_dbring_get_cap()
252 return -EINVAL; in ath11k_dbring_get_cap()
254 for (i = 0; i < ab->num_db_cap; i++) { in ath11k_dbring_get_cap()
255 if (pdev_idx == ab->db_caps[i].pdev_id && in ath11k_dbring_get_cap()
256 id == ab->db_caps[i].id) { in ath11k_dbring_get_cap()
257 *db_cap = ab->db_caps[i]; in ath11k_dbring_get_cap()
263 return -ENOENT; in ath11k_dbring_get_cap()
280 int size; in ath11k_dbring_buffer_release_event() local
284 pdev_idx = ev->fixed.pdev_id; in ath11k_dbring_buffer_release_event()
285 module_id = ev->fixed.module_id; in ath11k_dbring_buffer_release_event()
287 if (pdev_idx >= ab->num_radios) { in ath11k_dbring_buffer_release_event()
289 return -EINVAL; in ath11k_dbring_buffer_release_event()
292 if (ev->fixed.num_buf_release_entry != in ath11k_dbring_buffer_release_event()
293 ev->fixed.num_meta_data_entry) { in ath11k_dbring_buffer_release_event()
295 ev->fixed.num_buf_release_entry, in ath11k_dbring_buffer_release_event()
296 ev->fixed.num_meta_data_entry); in ath11k_dbring_buffer_release_event()
297 return -EINVAL; in ath11k_dbring_buffer_release_event()
300 ar = ab->pdevs[pdev_idx].ar; in ath11k_dbring_buffer_release_event()
303 if (!rcu_dereference(ab->pdevs_active[pdev_idx])) { in ath11k_dbring_buffer_release_event()
304 ret = -EINVAL; in ath11k_dbring_buffer_release_event()
308 switch (ev->fixed.module_id) { in ath11k_dbring_buffer_release_event()
315 ev->fixed.module_id); in ath11k_dbring_buffer_release_event()
320 ret = -EINVAL; in ath11k_dbring_buffer_release_event()
324 srng = &ab->hal.srng_list[ring->refill_srng.ring_id]; in ath11k_dbring_buffer_release_event()
325 num_entry = ev->fixed.num_buf_release_entry; in ath11k_dbring_buffer_release_event()
326 size = ring->buf_sz + ring->buf_align - 1; in ath11k_dbring_buffer_release_event()
329 spin_lock_bh(&srng->lock); in ath11k_dbring_buffer_release_event()
332 desc.info0 = ev->buf_entry[num_buff_reaped].paddr_lo; in ath11k_dbring_buffer_release_event()
333 desc.info1 = ev->buf_entry[num_buff_reaped].paddr_hi; in ath11k_dbring_buffer_release_event()
334 handler_data.meta = ev->meta_data[num_buff_reaped]; in ath11k_dbring_buffer_release_event()
342 spin_lock_bh(&ring->idr_lock); in ath11k_dbring_buffer_release_event()
343 buff = idr_find(&ring->bufs_idr, buf_id); in ath11k_dbring_buffer_release_event()
345 spin_unlock_bh(&ring->idr_lock); in ath11k_dbring_buffer_release_event()
348 idr_remove(&ring->bufs_idr, buf_id); in ath11k_dbring_buffer_release_event()
349 spin_unlock_bh(&ring->idr_lock); in ath11k_dbring_buffer_release_event()
351 dma_unmap_single(ab->dev, buff->paddr, ring->buf_sz, in ath11k_dbring_buffer_release_event()
357 if (ring->handler) { in ath11k_dbring_buffer_release_event()
358 vaddr_unalign = buff->payload; in ath11k_dbring_buffer_release_event()
360 ring->buf_align); in ath11k_dbring_buffer_release_event()
361 handler_data.data_sz = ring->buf_sz; in ath11k_dbring_buffer_release_event()
363 ring->handler(ar, &handler_data); in ath11k_dbring_buffer_release_event()
366 buff->paddr = 0; in ath11k_dbring_buffer_release_event()
367 memset(buff->payload, 0, size); in ath11k_dbring_buffer_release_event()
371 spin_unlock_bh(&srng->lock); in ath11k_dbring_buffer_release_event()
381 ath11k_dp_srng_cleanup(ar->ab, &ring->refill_srng); in ath11k_dbring_srng_cleanup()
389 spin_lock_bh(&ring->idr_lock); in ath11k_dbring_buf_cleanup()
390 idr_for_each_entry(&ring->bufs_idr, buff, buf_id) { in ath11k_dbring_buf_cleanup()
391 idr_remove(&ring->bufs_idr, buf_id); in ath11k_dbring_buf_cleanup()
392 dma_unmap_single(ar->ab->dev, buff->paddr, in ath11k_dbring_buf_cleanup()
393 ring->buf_sz, DMA_FROM_DEVICE); in ath11k_dbring_buf_cleanup()
394 kfree(buff->payload); in ath11k_dbring_buf_cleanup()
398 idr_destroy(&ring->bufs_idr); in ath11k_dbring_buf_cleanup()
399 spin_unlock_bh(&ring->idr_lock); in ath11k_dbring_buf_cleanup()