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