xref: /wlan-dirver/qca-wifi-host-cmn/dp/wifi3.0/dp_htt.h (revision a86b23ee68a2491aede2e03991f3fb37046f4e41)
1 /*
2  * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _DP_HTT_H_
20 #define _DP_HTT_H_
21 
22 #include <qdf_types.h>
23 #include <qdf_lock.h>
24 #include <qdf_nbuf.h>
25 #include <htc_api.h>
26 
27 #include "cdp_txrx_cmn_struct.h"
28 #include "dp_types.h"
29 #ifdef HTT_LOGGER
30 #include "dp_htt_logger.h"
31 #else
32 struct htt_logger;
33 static inline
34 void htt_interface_logging_init(struct htt_logger **htt_logger_handle)
35 {
36 }
37 
38 static inline
39 void htt_interface_logging_deinit(struct htt_logger *htt_logger_handle)
40 {
41 }
42 
43 static inline
44 int htt_command_record(struct htt_logger *h, uint8_t msg_type,
45 		       uint8_t *msg_data)
46 {
47 	return 0;
48 }
49 
50 static inline
51 int htt_event_record(struct htt_logger *h, uint8_t msg_type,
52 		     uint8_t *msg_data)
53 {
54 	return 0;
55 }
56 
57 static inline
58 int htt_wbm_event_record(struct htt_logger *h, uint8_t tx_status,
59 			 uint8_t *msg_data)
60 {
61 	return 0;
62 }
63 
64 #endif
65 
66 void htt_htc_pkt_pool_free(struct htt_soc *soc);
67 
68 #define HTT_TX_MUTEX_TYPE qdf_spinlock_t
69 
70 #define HTT_TX_MUTEX_INIT(_mutex)				\
71 	qdf_spinlock_create(_mutex)
72 
73 #define HTT_TX_MUTEX_ACQUIRE(_mutex)			\
74 	qdf_spin_lock_bh(_mutex)
75 
76 #define HTT_TX_MUTEX_RELEASE(_mutex)			\
77 	qdf_spin_unlock_bh(_mutex)
78 
79 #define HTT_TX_MUTEX_DESTROY(_mutex)			\
80 	qdf_spinlock_destroy(_mutex)
81 
82 #define DP_HTT_MAX_SEND_QUEUE_DEPTH 64
83 
84 #ifndef HTT_MAC_ADDR_LEN
85 #define HTT_MAC_ADDR_LEN 6
86 #endif
87 
88 #define HTT_FRAMECTRL_TYPE_MASK 0x0C
89 #define HTT_GET_FRAME_CTRL_TYPE(_val)	\
90 		(((_val) & HTT_FRAMECTRL_TYPE_MASK) >> 2)
91 #define FRAME_CTRL_TYPE_MGMT	0x0
92 #define FRAME_CTRL_TYPE_CTRL	0x1
93 #define FRAME_CTRL_TYPE_DATA	0x2
94 #define FRAME_CTRL_TYPE_RESV	0x3
95 
96 #define HTT_FRAMECTRL_DATATYPE 0x08
97 #define HTT_PPDU_DESC_MAX_DEPTH 16
98 #define DP_SCAN_PEER_ID 0xFFFF
99 
100 #define HTT_RX_DELBA_WIN_SIZE_M    0x0000FC00
101 #define HTT_RX_DELBA_WIN_SIZE_S    10
102 
103 #define HTT_RX_DELBA_WIN_SIZE_GET(word)		\
104 	(((word) & HTT_RX_DELBA_WIN_SIZE_M) >> HTT_RX_DELBA_WIN_SIZE_S)
105 
106 /*
107  * Set the base misclist size to HTT copy engine source ring size
108  * to guarantee that a packet on the misclist wont be freed while it
109  * is sitting in the copy engine.
110  */
111 #define DP_HTT_HTC_PKT_MISCLIST_SIZE          2048
112 #define HTT_T2H_MAX_MSG_SIZE 2048
113 
114 #define HTT_T2H_EXT_STATS_TLV_START_OFFSET    3
115 
116 /*
117  * Below offset are based on htt_ppdu_stats_common_tlv
118  * defined in htt_ppdu_stats.h
119  */
120 #define HTT_PPDU_STATS_COMMON_TLV_TLV_HDR_OFFSET 0
121 #define HTT_PPDU_STATS_COMMON_TLV_PPDU_ID_OFFSET 1
122 #define HTT_PPDU_STATS_COMMON_TLV_RING_ID_SCH_CMD_ID_OFFSET 2
123 #define HTT_PPDU_STATS_COMMON_TLV_QTYPE_FRM_TYPE_OFFSET 3
124 #define HTT_PPDU_STATS_COMMON_TLV_CHAIN_MASK_OFFSET 4
125 #define HTT_PPDU_STATS_COMMON_TLV_FES_DUR_US_OFFSET 5
126 #define HTT_PPDU_STATS_COMMON_TLV_SCH_EVAL_START_TSTMP_L32_US_OFFSET 6
127 #define HTT_PPDU_STATS_COMMON_TLV_SCH_END_TSTMP_US_OFFSET 7
128 #define HTT_PPDU_STATS_COMMON_TLV_START_TSTMP_L32_US_OFFSET 8
129 #define HTT_PPDU_STATS_COMMON_TLV_CHAN_MHZ_PHY_MODE_OFFSET 9
130 #define HTT_PPDU_STATS_COMMON_TLV_CCA_DELTA_TIME_US_OFFSET 10
131 #define HTT_PPDU_STATS_COMMON_TLV_RXFRM_DELTA_TIME_US_OFFSET 11
132 #define HTT_PPDU_STATS_COMMON_TLV_TXFRM_DELTA_TIME_US_OFFSET 12
133 #define HTT_PPDU_STATS_COMMON_TLV_RESV_NUM_UL_BEAM_OFFSET 13
134 #define HTT_PPDU_STATS_COMMON_TLV_START_TSTMP_U32_US_OFFSET 14
135 
136 /* get index for field in htt_ppdu_stats_common_tlv */
137 #define HTT_GET_STATS_CMN_INDEX(index) \
138 	HTT_PPDU_STATS_COMMON_TLV_##index##_OFFSET
139 
140 /**
141  * enum dp_full_mon_config - enum to enable/disable full monitor mode
142  *
143  * @DP_FULL_MON_DISABLE: Disable full monitor mode
144  * @DP_FULL_MON_ENABLE: Enable full monitor mode
145  */
146 enum dp_full_mon_config {
147 	DP_FULL_MON_DISABLE,
148 	DP_FULL_MON_ENABLE,
149 };
150 
151 struct dp_htt_htc_pkt {
152 	void *soc_ctxt;
153 	qdf_dma_addr_t nbuf_paddr;
154 	HTC_PACKET htc_pkt;
155 };
156 
157 struct dp_htt_htc_pkt_union {
158 	union {
159 		struct dp_htt_htc_pkt pkt;
160 		struct dp_htt_htc_pkt_union *next;
161 	} u;
162 };
163 
164 struct dp_htt_timestamp {
165 	long *umac_ttt;
166 	long *lmac_ttt;
167 };
168 
169 struct htt_soc {
170 	struct cdp_ctrl_objmgr_psoc *ctrl_psoc;
171 	struct dp_soc *dp_soc;
172 	hal_soc_handle_t hal_soc;
173 	struct dp_htt_timestamp pdevid_tt[MAX_PDEV_CNT];
174 	/* htt_logger handle */
175 	struct htt_logger *htt_logger_handle;
176 	HTC_HANDLE htc_soc;
177 	qdf_device_t osdev;
178 	HTC_ENDPOINT_ID htc_endpoint;
179 	struct dp_htt_htc_pkt_union *htt_htc_pkt_freelist;
180 	struct dp_htt_htc_pkt_union *htt_htc_pkt_misclist;
181 	struct {
182 		u_int8_t major;
183 		u_int8_t minor;
184 	} tgt_ver;
185 	struct {
186 		u_int8_t major;
187 		u_int8_t minor;
188 	} wifi_ip_ver;
189 
190 	struct {
191 		int htc_err_cnt;
192 		int htc_pkt_free;
193 	} stats;
194 
195 	HTT_TX_MUTEX_TYPE htt_tx_mutex;
196 };
197 
198 /**
199  * struct htt_rx_ring_tlv_filter - Rx ring TLV filter
200  * enable/disable.
201  * @mpdu_start: enable/disable MPDU start TLV
202  * @msdu_start: enable/disable MSDU start TLV
203  * @packet: enable/disable PACKET TLV
204  * @msdu_end: enable/disable MSDU end TLV
205  * @mpdu_end: enable/disable MPDU end TLV
206  * @packet_header: enable/disable PACKET header TLV
207  * @attention: enable/disable ATTENTION TLV
208  * @ppdu_start: enable/disable PPDU start TLV
209  * @ppdu_end: enable/disable PPDU end TLV
210  * @ppdu_end_user_stats: enable/disable PPDU user stats TLV
211  * @ppdu_end_user_stats_ext: enable/disable PPDU user stats ext TLV
212  * @ppdu_end_status_done: enable/disable PPDU end status done TLV
213  * @enable_fp: enable/disable FP packet
214  * @enable_md: enable/disable MD packet
215  * @enable_mo: enable/disable MO packet
216  * @enable_mgmt: enable/disable MGMT packet
217  * @enable_ctrl: enable/disable CTRL packet
218  * @enable_data: enable/disable DATA packet
219  * @offset_valid: Flag to indicate if below offsets are valid
220  * @rx_packet_offset: Offset of packet payload
221  * @rx_header_offset: Offset of rx_header tlv
222  * @rx_mpdu_end_offset: Offset of rx_mpdu_end tlv
223  * @rx_mpdu_start_offset: Offset of rx_mpdu_start tlv
224  * @rx_msdu_end_offset: Offset of rx_msdu_end tlv
225  * @rx_msdu_start_offset: Offset of rx_msdu_start tlv
226  * @rx_attn_offset: Offset of rx_attention tlv
227  *
228  * NOTE: Do not change the layout of this structure
229  */
230 struct htt_rx_ring_tlv_filter {
231 	u_int32_t mpdu_start:1,
232 		msdu_start:1,
233 		packet:1,
234 		msdu_end:1,
235 		mpdu_end:1,
236 		packet_header:1,
237 		attention:1,
238 		ppdu_start:1,
239 		ppdu_end:1,
240 		ppdu_end_user_stats:1,
241 		ppdu_end_user_stats_ext:1,
242 		ppdu_end_status_done:1,
243 		header_per_msdu:1,
244 		enable_fp:1,
245 		enable_md:1,
246 		enable_mo:1;
247 	u_int32_t fp_mgmt_filter:16,
248 		mo_mgmt_filter:16;
249 	u_int32_t fp_ctrl_filter:16,
250 		mo_ctrl_filter:16;
251 	u_int32_t fp_data_filter:16,
252 		mo_data_filter:16;
253 	u_int16_t md_data_filter;
254 	u_int16_t md_mgmt_filter;
255 	u_int16_t md_ctrl_filter;
256 	bool offset_valid;
257 	uint16_t rx_packet_offset;
258 	uint16_t rx_header_offset;
259 	uint16_t rx_mpdu_end_offset;
260 	uint16_t rx_mpdu_start_offset;
261 	uint16_t rx_msdu_end_offset;
262 	uint16_t rx_msdu_start_offset;
263 	uint16_t rx_attn_offset;
264 };
265 
266 /**
267  * struct dp_htt_rx_flow_fst_setup - Rx FST setup message
268  * @pdev_id: DP Pdev identifier
269  * @max_entries: Size of Rx FST in number of entries
270  * @max_search: Number of collisions allowed
271  * @base_addr_lo: lower 32-bit physical address
272  * @base_addr_hi: upper 32-bit physical address
273  * @ip_da_sa_prefix: IPv4 prefix to map to IPv6 address scheme
274  * @hash_key_len: Rx FST hash key size
275  * @hash_key: Rx FST Toeplitz hash key
276  */
277 struct dp_htt_rx_flow_fst_setup {
278 	uint8_t pdev_id;
279 	uint32_t max_entries;
280 	uint32_t max_search;
281 	uint32_t base_addr_lo;
282 	uint32_t base_addr_hi;
283 	uint32_t ip_da_sa_prefix;
284 	uint32_t hash_key_len;
285 	uint8_t *hash_key;
286 };
287 
288 /**
289  * enum dp_htt_flow_fst_operation - FST related operations allowed
290  * @DP_HTT_FST_CACHE_OP_NONE: Cache no-op
291  * @DP_HTT_FST_CACHE_INVALIDATE_ENTRY: Invalidate single cache entry
292  * @DP_HTT_FST_CACHE_INVALIDATE_FULL: Invalidate entire cache
293  * @DP_HTT_FST_ENABLE: Bypass FST is enabled
294  * @DP_HTT_FST_DISABLE: Disable bypass FST
295  */
296 enum dp_htt_flow_fst_operation {
297 	DP_HTT_FST_CACHE_OP_NONE,
298 	DP_HTT_FST_CACHE_INVALIDATE_ENTRY,
299 	DP_HTT_FST_CACHE_INVALIDATE_FULL,
300 	DP_HTT_FST_ENABLE,
301 	DP_HTT_FST_DISABLE
302 };
303 
304 /**
305  * struct dp_htt_rx_flow_fst_setup - Rx FST setup message
306  * @pdev_id: DP Pdev identifier
307  * @op_code: FST operation to be performed by FW/HW
308  * @rx_flow: Rx Flow information on which operation is to be performed
309  */
310 struct dp_htt_rx_flow_fst_operation {
311 	uint8_t pdev_id;
312 	enum dp_htt_flow_fst_operation op_code;
313 	struct cdp_rx_flow_info *rx_flow;
314 };
315 
316 /**
317  * struct dp_htt_rx_fisa_config - Rx fisa config
318  * @pdev_id: DP Pdev identifier
319  * @fisa_timeout: fisa aggregation timeout
320  */
321 struct dp_htt_rx_fisa_cfg {
322 	uint8_t pdev_id;
323 	uint32_t fisa_timeout;
324 };
325 
326 QDF_STATUS dp_htt_rx_fisa_config(struct dp_pdev *pdev,
327 				 struct dp_htt_rx_fisa_cfg *fisa_config);
328 
329 /*
330  * htt_soc_initialize() - SOC level HTT initialization
331  * @htt_soc: Opaque htt SOC handle
332  * @ctrl_psoc: Opaque ctrl SOC handle
333  * @htc_soc: SOC level HTC handle
334  * @hal_soc: Opaque HAL SOC handle
335  * @osdev: QDF device
336  *
337  * Return: HTT handle on success; NULL on failure
338  */
339 void *
340 htt_soc_initialize(struct htt_soc *htt_soc,
341 		   struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
342 		   HTC_HANDLE htc_soc,
343 		   hal_soc_handle_t hal_soc_hdl, qdf_device_t osdev);
344 
345 /*
346  * htt_soc_attach() - attach DP and HTT SOC
347  * @soc: DP SOC handle
348  * @htc_hdl: HTC handle
349  *
350  * Return: htt_soc handle on Success, NULL on Failure
351  */
352 struct htt_soc *htt_soc_attach(struct dp_soc *soc, HTC_HANDLE htc_hdl);
353 
354 /*
355  * htt_set_htc_handle_() - set HTC handle
356  * @htt_hdl: HTT handle/SOC
357  * @htc_soc: HTC handle
358  *
359  * Return: None
360  */
361 void htt_set_htc_handle(struct htt_soc *htt_hdl, HTC_HANDLE htc_soc);
362 
363 /*
364  * htt_get_htc_handle_() - set HTC handle
365  * @htt_hdl: HTT handle/SOC
366  *
367  * Return: HTC_HANDLE
368  */
369 HTC_HANDLE htt_get_htc_handle(struct htt_soc *htt_hdl);
370 
371 /*
372  * htt_soc_htc_dealloc() - HTC memory de-alloc
373  * @htt_soc: SOC level HTT handle
374  *
375  * Return: None
376  */
377 void htt_soc_htc_dealloc(struct htt_soc *htt_handle);
378 
379 /*
380  * htt_soc_htc_prealloc() - HTC memory prealloc
381  * @htt_soc: SOC level HTT handle
382  *
383  * Return: QDF_STATUS_SUCCESS on success or
384  * QDF_STATUS_E_NO_MEM on allocation failure
385  */
386 QDF_STATUS htt_soc_htc_prealloc(struct htt_soc *htt_soc);
387 
388 void htt_soc_detach(struct htt_soc *soc);
389 
390 int htt_srng_setup(struct htt_soc *htt_soc, int pdev_id,
391 		   hal_ring_handle_t hal_ring_hdl,
392 		   int hal_ring_type);
393 
394 int htt_soc_attach_target(struct htt_soc *htt_soc);
395 
396 /*
397  * htt_h2t_rx_ring_cfg() - Send SRNG packet and TLV filter
398  * config message to target
399  * @htt_soc:	HTT SOC handle
400  * @pdev_id:	PDEV Id
401  * @hal_srng:	Opaque HAL SRNG pointer
402  * @hal_ring_type:	SRNG ring type
403  * @ring_buf_size:	SRNG buffer size
404  * @htt_tlv_filter:	Rx SRNG TLV and filter setting
405  *
406  * Return: 0 on success; error code on failure
407  */
408 int htt_h2t_rx_ring_cfg(struct htt_soc *htt_soc, int pdev_id,
409 			hal_ring_handle_t hal_ring_hdl,
410 			int hal_ring_type, int ring_buf_size,
411 			struct htt_rx_ring_tlv_filter *htt_tlv_filter);
412 
413 /*
414  * htt_t2h_stats_handler() - target to host stats work handler
415  * @context:	context (dp soc context)
416  *
417  * Return: void
418  */
419 void htt_t2h_stats_handler(void *context);
420 
421 /**
422  * struct htt_stats_context - htt stats information
423  * @soc: Size of each descriptor in the pool
424  * @msg: T2H Ext stats message queue
425  * @msg_len: T2H Ext stats message length
426  */
427 struct htt_stats_context {
428 	struct dp_soc *soc;
429 	qdf_nbuf_queue_t msg;
430 	uint32_t msg_len;
431 };
432 
433 int
434 dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(uint32_t bitmap);
435 
436 /**
437  * dp_ppdu_desc_user_stats_update(): Function to update TX user stats
438  * @pdev: DP pdev handle
439  * @ppdu_info: per PPDU TLV descriptor
440  *
441  * return: void
442  */
443 void
444 dp_ppdu_desc_user_stats_update(struct dp_pdev *pdev,
445 			       struct ppdu_info *ppdu_info);
446 
447 /**
448  * dp_htt_rx_flow_fst_setup(): Send HTT Rx FST setup message to FW
449  * @pdev: DP pdev handle
450  * @fse_setup_info: FST setup parameters
451  *
452  * Return: Success when HTT message is sent, error on failure
453  */
454 QDF_STATUS
455 dp_htt_rx_flow_fst_setup(struct dp_pdev *pdev,
456 			 struct dp_htt_rx_flow_fst_setup *setup_info);
457 
458 /**
459  * dp_htt_rx_flow_fse_operation(): Send HTT Flow Search Entry msg to
460  * add/del a flow in HW
461  * @pdev: DP pdev handle
462  * @fse_op_info: Flow entry parameters
463  *
464  * Return: Success when HTT message is sent, error on failure
465  */
466 QDF_STATUS
467 dp_htt_rx_flow_fse_operation(struct dp_pdev *pdev,
468 			     struct dp_htt_rx_flow_fst_operation *op_info);
469 
470 /**
471  * htt_h2t_full_mon_cfg() - Send full monitor configuarion msg to FW
472  *
473  * @htt_soc: HTT Soc handle
474  * @pdev_id: Radio id
475  * @dp_full_mon_config: enabled/disable configuration
476  *
477  * Return: Success when HTT message is sent, error on failure
478  */
479 int htt_h2t_full_mon_cfg(struct htt_soc *htt_soc,
480 			 uint8_t pdev_id,
481 			 enum dp_full_mon_config);
482 #endif /* _DP_HTT_H_ */
483