1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
4  * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
5  */
6 
7 #ifndef ATH11K_DBRING_H
8 #define ATH11K_DBRING_H
9 
10 #include <linux/types.h>
11 #include <linux/idr.h>
12 #include <linux/spinlock.h>
13 #include "dp.h"
14 
15 struct ath11k_dbring_element {
16 	dma_addr_t paddr;
17 	u8 *payload;
18 };
19 
20 struct ath11k_dbring_data {
21 	void *data;
22 	u32 data_sz;
23 	struct wmi_dma_buf_release_meta_data meta;
24 };
25 
26 struct ath11k_dbring_buf_release_event {
27 	struct ath11k_wmi_dma_buf_release_fixed_param fixed;
28 	struct wmi_dma_buf_release_entry *buf_entry;
29 	struct wmi_dma_buf_release_meta_data *meta_data;
30 	u32 num_buf_entry;
31 	u32 num_meta;
32 };
33 
34 struct ath11k_dbring_cap {
35 	u32 pdev_id;
36 	enum wmi_direct_buffer_module id;
37 	u32 min_elem;
38 	u32 min_buf_sz;
39 	u32 min_buf_align;
40 };
41 
42 struct ath11k_dbring {
43 	struct dp_srng refill_srng;
44 	struct idr bufs_idr;
45 	/* Protects bufs_idr */
46 	spinlock_t idr_lock;
47 	dma_addr_t tp_addr;
48 	dma_addr_t hp_addr;
49 	int bufs_max;
50 	u32 pdev_id;
51 	u32 buf_sz;
52 	u32 buf_align;
53 	u32 num_resp_per_event;
54 	u32 event_timeout_ms;
55 	int (*handler)(struct ath11k *, struct ath11k_dbring_data *);
56 };
57 
58 int ath11k_dbring_set_cfg(struct ath11k *ar,
59 			  struct ath11k_dbring *ring,
60 			  u32 num_resp_per_event,
61 			  u32 event_timeout_ms,
62 			  int (*handler)(struct ath11k *,
63 					 struct ath11k_dbring_data *));
64 int ath11k_dbring_wmi_cfg_setup(struct ath11k *ar,
65 				struct ath11k_dbring *ring,
66 				enum wmi_direct_buffer_module id);
67 int ath11k_dbring_buf_setup(struct ath11k *ar,
68 			    struct ath11k_dbring *ring,
69 			    struct ath11k_dbring_cap *db_cap);
70 int ath11k_dbring_srng_setup(struct ath11k *ar, struct ath11k_dbring *ring,
71 			     int ring_num, int num_entries);
72 int ath11k_dbring_buffer_release_event(struct ath11k_base *ab,
73 				       struct ath11k_dbring_buf_release_event *ev);
74 int ath11k_dbring_get_cap(struct ath11k_base *ab,
75 			  u8 pdev_idx,
76 			  enum wmi_direct_buffer_module id,
77 			  struct ath11k_dbring_cap *db_cap);
78 void ath11k_dbring_srng_cleanup(struct ath11k *ar, struct ath11k_dbring *ring);
79 void ath11k_dbring_buf_cleanup(struct ath11k *ar, struct ath11k_dbring *ring);
80 int ath11k_dbring_validate_buffer(struct ath11k *ar, void *data, u32 size);
81 
82 #endif /* ATH11K_DBRING_H */
83