1 /*
2  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef _WLAN_DP_WFDS_H_
18 #define _WLAN_DP_WFDS_H_
19 
20 #ifdef FEATURE_DIRECT_LINK
21 
22 #include "qdf_atomic.h"
23 #include "wlan_dp_priv.h"
24 #include "wlan_qmi_public_struct.h"
25 #include "wlan_qmi_wfds_api.h"
26 
27 #define DP_WFDS_CE_MAX_SRNG QMI_WFDS_CE_MAX_SRNG
28 
29 /**
30  * enum dp_wfds_msg - WFDS message type
31  * @DP_WFDS_REQ_MEM_IND_MSG: Memory request indication message
32  * @DP_WFDS_IPCC_MAP_N_CFG_IND_MSG: IPCC map and configure indication message
33  * @DP_WFDS_MSG_MAX: not a real value just a placeholder for max
34  */
35 enum dp_wfds_msg {
36 	DP_WFDS_REQ_MEM_IND_MSG,
37 	DP_WFDS_IPCC_MAP_N_CFG_IND_MSG,
38 	DP_WFDS_MSG_MAX,
39 };
40 
41 /**
42  * enum dp_wfds_state - Datapath WFDS state
43  * @DP_WFDS_SVC_DISCONNECTED: service disconnected
44  * @DP_WFDS_SVC_CONNECTED: service connected
45  * @DP_WFDS_SVC_CONFIG_DONE: configuration msg handshake done
46  * @DP_WFDS_SVC_MEM_CONFIG_DONE: memory handshake with server done
47  * @DP_WFDS_SVC_IPCC_MAP_N_CFG_DONE: IPCC map and cfg handshake completed
48  */
49 enum dp_wfds_state {
50 	DP_WFDS_SVC_DISCONNECTED,
51 	DP_WFDS_SVC_CONNECTED,
52 	DP_WFDS_SVC_CONFIG_DONE,
53 	DP_WFDS_SVC_MEM_CONFIG_DONE,
54 	DP_WFDS_SVC_IPCC_MAP_N_CFG_DONE,
55 };
56 
57 /**
58  * enum dp_wfds_event_type  - Datapath WFDS event type
59  * @DP_WFDS_NEW_SERVER: QMI new server event
60  * @DP_WFDS_MEM_REQ: QMI memory request event
61  * @DP_WFDS_IPCC_MAP_N_CFG: QMI IPCC map and configure event
62  */
63 enum dp_wfds_event_type {
64 	DP_WFDS_NEW_SERVER,
65 	DP_WFDS_MEM_REQ,
66 	DP_WFDS_IPCC_MAP_N_CFG,
67 };
68 
69 /**
70  * struct dp_wfds_event - DP QMI event structure
71  * @list_node: node used for adding/deleting to a list
72  * @wfds_evt_type: QMI event type
73  * @data: Pointer to event data
74  */
75 struct dp_wfds_event {
76 	qdf_list_node_t list_node;
77 	enum dp_wfds_event_type wfds_evt_type;
78 	void *data;
79 };
80 
81 /**
82  * struct dp_direct_link_iommu_config - Direct link related IOMMU configuration
83  * @shadow_rdptr_paddr: shadow read pointer dma address
84  * @shadow_rdptr_map_size: shadow read pointer memory size
85  * @shadow_wrptr_paddr: shadow write pointer dma address
86  * @shadow_wrptr_map_size: shadow write pointer memory size
87  * @direct_link_srng_ring_base_paddr: SRNG ring base dma address
88  * @direct_link_srng_ring_map_size: SRNG ring memory size
89  * @direct_link_refill_ring_base_paddr: refill SRNG ring base dma address
90  * @direct_link_refill_ring_map_size: refill SRNG ring memory size
91  */
92 struct dp_direct_link_iommu_config {
93 	qdf_dma_addr_t shadow_rdptr_paddr;
94 	uint16_t shadow_rdptr_map_size;
95 	qdf_dma_addr_t shadow_wrptr_paddr;
96 	uint16_t shadow_wrptr_map_size;
97 	qdf_dma_addr_t direct_link_srng_ring_base_paddr[QMI_WFDS_CE_MAX_SRNG];
98 	uint16_t direct_link_srng_ring_map_size[QMI_WFDS_CE_MAX_SRNG];
99 	qdf_dma_addr_t direct_link_refill_ring_base_paddr;
100 	uint16_t direct_link_refill_ring_map_size;
101 };
102 
103 /**
104  * struct dp_direct_link_wfds_context - DP Direct Link WFDS context structure
105  * @direct_link_ctx: direct link context
106  * @wfds_work: work to be scheduled on QMI event
107  * @wfds_wq: QMI workqueue
108  * @wfds_event_list_lock: spinlock for event list access
109  * @wfds_event_list: QMI event list
110  * @wfds_state: QMI state
111  * @num_mem_arenas: Number of memory arenas requested by QMI server
112  * @mem_arena_pages: Pointer to array of mem multi page structure for arenas
113  * @ipcc_dma_addr: ipcc dma address
114  * @ipcc_ce_id: ids of CEs that are configured with IPCC MSI info
115  * @ipcc_ce_id_len: number of valid entries in ipcc_ce_id array
116  * @iommu_cfg: direct link iommu configuration
117  */
118 struct dp_direct_link_wfds_context {
119 	struct dp_direct_link_context *direct_link_ctx;
120 	qdf_work_t wfds_work;
121 	qdf_workqueue_t *wfds_wq;
122 	qdf_spinlock_t wfds_event_list_lock;
123 	qdf_list_t wfds_event_list;
124 	qdf_atomic_t wfds_state;
125 	uint32_t num_mem_arenas;
126 	struct qdf_mem_multi_page_t *mem_arena_pages;
127 	uint32_t ipcc_dma_addr;
128 	uint8_t ipcc_ce_id[DP_WFDS_CE_MAX_SRNG];
129 	uint8_t ipcc_ce_id_len;
130 	struct dp_direct_link_iommu_config iommu_cfg;
131 };
132 
133 /**
134  * dp_wfds_handle_request_mem_ind() - Process request memory indication received
135  *  from QMI server
136  * @mem_msg: pointer to memory request indication message
137  *
138  * Return: None
139  */
140 void
141 dp_wfds_handle_request_mem_ind(struct wlan_qmi_wfds_mem_ind_msg *mem_msg);
142 
143 /**
144  * dp_wfds_handle_ipcc_map_n_cfg_ind() - Process IPCC map and configure
145  *  indication received from QMI server
146  * @ipcc_msg: pointer to IPCC map and configure indication message
147  *
148  * Return: None
149  */
150 void
151 dp_wfds_handle_ipcc_map_n_cfg_ind(struct wlan_qmi_wfds_ipcc_map_n_cfg_ind_msg *ipcc_msg);
152 
153 /**
154  * dp_wfds_new_server() - New server callback triggered when service is up.
155  *  Connect to the service as part of this call.
156  *
157  * Return: QDF status
158  */
159 QDF_STATUS dp_wfds_new_server(void);
160 
161 /**
162  * dp_wfds_del_server() - Del server callback triggered when service is
163  *  down.
164  *
165  * Return: None
166  */
167 void dp_wfds_del_server(void);
168 
169 /**
170  * dp_wfds_init() - Initialize DP WFDS context
171  * @direct_link_ctx: DP Direct Link context
172  *
173  * Return: QDF status
174  */
175 QDF_STATUS dp_wfds_init(struct dp_direct_link_context *direct_link_ctx);
176 
177 /**
178  * dp_wfds_deinit() - Deinitialize DP WFDS context
179  * @direct_link_ctx: DP Direct Link context
180  * @is_ssr: true if SSR is in progress else false
181  *
182  * Return: None
183  */
184 void dp_wfds_deinit(struct dp_direct_link_context *direct_link_ctx,
185 		    bool is_ssr);
186 #endif
187 #endif
188