xref: /wlan-dirver/qca-wifi-host-cmn/dp/wifi3.0/dp_htt.h (revision 97f44cd39e4ff816eaa1710279d28cf6b9e65ad9)
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 #define MAX_SCHED_STARVE 100000
141 #define WRAP_DROP_TSF_DELTA 10000
142 #define MAX_TSF_32 0xFFFFFFFF
143 
144 /**
145  * enum dp_full_mon_config - enum to enable/disable full monitor mode
146  *
147  * @DP_FULL_MON_DISABLE: Disable full monitor mode
148  * @DP_FULL_MON_ENABLE: Enable full monitor mode
149  */
150 enum dp_full_mon_config {
151 	DP_FULL_MON_DISABLE,
152 	DP_FULL_MON_ENABLE,
153 };
154 
155 struct dp_htt_htc_pkt {
156 	void *soc_ctxt;
157 	qdf_dma_addr_t nbuf_paddr;
158 	HTC_PACKET htc_pkt;
159 };
160 
161 struct dp_htt_htc_pkt_union {
162 	union {
163 		struct dp_htt_htc_pkt pkt;
164 		struct dp_htt_htc_pkt_union *next;
165 	} u;
166 };
167 
168 struct dp_htt_timestamp {
169 	long *umac_ttt;
170 	long *lmac_ttt;
171 };
172 
173 struct htt_soc {
174 	struct cdp_ctrl_objmgr_psoc *ctrl_psoc;
175 	struct dp_soc *dp_soc;
176 	hal_soc_handle_t hal_soc;
177 	struct dp_htt_timestamp pdevid_tt[MAX_PDEV_CNT];
178 	/* htt_logger handle */
179 	struct htt_logger *htt_logger_handle;
180 	HTC_HANDLE htc_soc;
181 	qdf_device_t osdev;
182 	HTC_ENDPOINT_ID htc_endpoint;
183 	struct dp_htt_htc_pkt_union *htt_htc_pkt_freelist;
184 	struct dp_htt_htc_pkt_union *htt_htc_pkt_misclist;
185 	struct {
186 		u_int8_t major;
187 		u_int8_t minor;
188 	} tgt_ver;
189 	struct {
190 		u_int8_t major;
191 		u_int8_t minor;
192 	} wifi_ip_ver;
193 
194 	struct {
195 		int htc_err_cnt;
196 		int htc_pkt_free;
197 		int skip_count;
198 		int fail_count;
199 		/* rtpm put skip count for ver req msg */
200 		int htt_ver_req_put_skip;
201 	} stats;
202 
203 	HTT_TX_MUTEX_TYPE htt_tx_mutex;
204 };
205 
206 /**
207  * struct htt_rx_ring_tlv_filter - Rx ring TLV filter
208  * enable/disable.
209  * @mpdu_start: enable/disable MPDU start TLV
210  * @msdu_start: enable/disable MSDU start TLV
211  * @packet: enable/disable PACKET TLV
212  * @msdu_end: enable/disable MSDU end TLV
213  * @mpdu_end: enable/disable MPDU end TLV
214  * @packet_header: enable/disable PACKET header TLV
215  * @attention: enable/disable ATTENTION TLV
216  * @ppdu_start: enable/disable PPDU start TLV
217  * @ppdu_end: enable/disable PPDU end TLV
218  * @ppdu_end_user_stats: enable/disable PPDU user stats TLV
219  * @ppdu_end_user_stats_ext: enable/disable PPDU user stats ext TLV
220  * @ppdu_end_status_done: enable/disable PPDU end status done TLV
221  * @enable_fp: enable/disable FP packet
222  * @enable_md: enable/disable MD packet
223  * @enable_mo: enable/disable MO packet
224  * @enable_mgmt: enable/disable MGMT packet
225  * @enable_ctrl: enable/disable CTRL packet
226  * @enable_data: enable/disable DATA packet
227  * @offset_valid: Flag to indicate if below offsets are valid
228  * @rx_packet_offset: Offset of packet payload
229  * @rx_header_offset: Offset of rx_header tlv
230  * @rx_mpdu_end_offset: Offset of rx_mpdu_end tlv
231  * @rx_mpdu_start_offset: Offset of rx_mpdu_start tlv
232  * @rx_msdu_end_offset: Offset of rx_msdu_end tlv
233  * @rx_msdu_start_offset: Offset of rx_msdu_start tlv
234  * @rx_attn_offset: Offset of rx_attention tlv
235  *
236  * NOTE: Do not change the layout of this structure
237  */
238 struct htt_rx_ring_tlv_filter {
239 	u_int32_t mpdu_start:1,
240 		msdu_start:1,
241 		packet:1,
242 		msdu_end:1,
243 		mpdu_end:1,
244 		packet_header:1,
245 		attention:1,
246 		ppdu_start:1,
247 		ppdu_end:1,
248 		ppdu_end_user_stats:1,
249 		ppdu_end_user_stats_ext:1,
250 		ppdu_end_status_done:1,
251 		header_per_msdu:1,
252 		enable_fp:1,
253 		enable_md:1,
254 		enable_mo:1;
255 	u_int32_t fp_mgmt_filter:16,
256 		mo_mgmt_filter:16;
257 	u_int32_t fp_ctrl_filter:16,
258 		mo_ctrl_filter:16;
259 	u_int32_t fp_data_filter:16,
260 		mo_data_filter:16;
261 	u_int16_t md_data_filter;
262 	u_int16_t md_mgmt_filter;
263 	u_int16_t md_ctrl_filter;
264 	bool offset_valid;
265 	uint16_t rx_packet_offset;
266 	uint16_t rx_header_offset;
267 	uint16_t rx_mpdu_end_offset;
268 	uint16_t rx_mpdu_start_offset;
269 	uint16_t rx_msdu_end_offset;
270 	uint16_t rx_msdu_start_offset;
271 	uint16_t rx_attn_offset;
272 };
273 
274 /**
275  * struct dp_htt_rx_flow_fst_setup - Rx FST setup message
276  * @pdev_id: DP Pdev identifier
277  * @max_entries: Size of Rx FST in number of entries
278  * @max_search: Number of collisions allowed
279  * @base_addr_lo: lower 32-bit physical address
280  * @base_addr_hi: upper 32-bit physical address
281  * @ip_da_sa_prefix: IPv4 prefix to map to IPv6 address scheme
282  * @hash_key_len: Rx FST hash key size
283  * @hash_key: Rx FST Toeplitz hash key
284  */
285 struct dp_htt_rx_flow_fst_setup {
286 	uint8_t pdev_id;
287 	uint32_t max_entries;
288 	uint32_t max_search;
289 	uint32_t base_addr_lo;
290 	uint32_t base_addr_hi;
291 	uint32_t ip_da_sa_prefix;
292 	uint32_t hash_key_len;
293 	uint8_t *hash_key;
294 };
295 
296 /**
297  * enum dp_htt_flow_fst_operation - FST related operations allowed
298  * @DP_HTT_FST_CACHE_OP_NONE: Cache no-op
299  * @DP_HTT_FST_CACHE_INVALIDATE_ENTRY: Invalidate single cache entry
300  * @DP_HTT_FST_CACHE_INVALIDATE_FULL: Invalidate entire cache
301  * @DP_HTT_FST_ENABLE: Bypass FST is enabled
302  * @DP_HTT_FST_DISABLE: Disable bypass FST
303  */
304 enum dp_htt_flow_fst_operation {
305 	DP_HTT_FST_CACHE_OP_NONE,
306 	DP_HTT_FST_CACHE_INVALIDATE_ENTRY,
307 	DP_HTT_FST_CACHE_INVALIDATE_FULL,
308 	DP_HTT_FST_ENABLE,
309 	DP_HTT_FST_DISABLE
310 };
311 
312 /**
313  * struct dp_htt_rx_flow_fst_setup - Rx FST setup message
314  * @pdev_id: DP Pdev identifier
315  * @op_code: FST operation to be performed by FW/HW
316  * @rx_flow: Rx Flow information on which operation is to be performed
317  */
318 struct dp_htt_rx_flow_fst_operation {
319 	uint8_t pdev_id;
320 	enum dp_htt_flow_fst_operation op_code;
321 	struct cdp_rx_flow_info *rx_flow;
322 };
323 
324 /**
325  * struct dp_htt_rx_fisa_config - Rx fisa config
326  * @pdev_id: DP Pdev identifier
327  * @fisa_timeout: fisa aggregation timeout
328  */
329 struct dp_htt_rx_fisa_cfg {
330 	uint8_t pdev_id;
331 	uint32_t fisa_timeout;
332 };
333 
334 QDF_STATUS dp_htt_rx_fisa_config(struct dp_pdev *pdev,
335 				 struct dp_htt_rx_fisa_cfg *fisa_config);
336 
337 /*
338  * htt_soc_initialize() - SOC level HTT initialization
339  * @htt_soc: Opaque htt SOC handle
340  * @ctrl_psoc: Opaque ctrl SOC handle
341  * @htc_soc: SOC level HTC handle
342  * @hal_soc: Opaque HAL SOC handle
343  * @osdev: QDF device
344  *
345  * Return: HTT handle on success; NULL on failure
346  */
347 void *
348 htt_soc_initialize(struct htt_soc *htt_soc,
349 		   struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
350 		   HTC_HANDLE htc_soc,
351 		   hal_soc_handle_t hal_soc_hdl, qdf_device_t osdev);
352 
353 /*
354  * htt_soc_attach() - attach DP and HTT SOC
355  * @soc: DP SOC handle
356  * @htc_hdl: HTC handle
357  *
358  * Return: htt_soc handle on Success, NULL on Failure
359  */
360 struct htt_soc *htt_soc_attach(struct dp_soc *soc, HTC_HANDLE htc_hdl);
361 
362 /*
363  * htt_set_htc_handle_() - set HTC handle
364  * @htt_hdl: HTT handle/SOC
365  * @htc_soc: HTC handle
366  *
367  * Return: None
368  */
369 void htt_set_htc_handle(struct htt_soc *htt_hdl, HTC_HANDLE htc_soc);
370 
371 /*
372  * htt_get_htc_handle_() - set HTC handle
373  * @htt_hdl: HTT handle/SOC
374  *
375  * Return: HTC_HANDLE
376  */
377 HTC_HANDLE htt_get_htc_handle(struct htt_soc *htt_hdl);
378 
379 /*
380  * htt_soc_htc_dealloc() - HTC memory de-alloc
381  * @htt_soc: SOC level HTT handle
382  *
383  * Return: None
384  */
385 void htt_soc_htc_dealloc(struct htt_soc *htt_handle);
386 
387 /*
388  * htt_soc_htc_prealloc() - HTC memory prealloc
389  * @htt_soc: SOC level HTT handle
390  *
391  * Return: QDF_STATUS_SUCCESS on success or
392  * QDF_STATUS_E_NO_MEM on allocation failure
393  */
394 QDF_STATUS htt_soc_htc_prealloc(struct htt_soc *htt_soc);
395 
396 void htt_soc_detach(struct htt_soc *soc);
397 
398 int htt_srng_setup(struct htt_soc *htt_soc, int pdev_id,
399 		   hal_ring_handle_t hal_ring_hdl,
400 		   int hal_ring_type);
401 
402 int htt_soc_attach_target(struct htt_soc *htt_soc);
403 
404 /*
405  * htt_h2t_rx_ring_cfg() - Send SRNG packet and TLV filter
406  * config message to target
407  * @htt_soc:	HTT SOC handle
408  * @pdev_id:	PDEV Id
409  * @hal_srng:	Opaque HAL SRNG pointer
410  * @hal_ring_type:	SRNG ring type
411  * @ring_buf_size:	SRNG buffer size
412  * @htt_tlv_filter:	Rx SRNG TLV and filter setting
413  *
414  * Return: 0 on success; error code on failure
415  */
416 int htt_h2t_rx_ring_cfg(struct htt_soc *htt_soc, int pdev_id,
417 			hal_ring_handle_t hal_ring_hdl,
418 			int hal_ring_type, int ring_buf_size,
419 			struct htt_rx_ring_tlv_filter *htt_tlv_filter);
420 
421 /*
422  * htt_t2h_stats_handler() - target to host stats work handler
423  * @context:	context (dp soc context)
424  *
425  * Return: void
426  */
427 void htt_t2h_stats_handler(void *context);
428 
429 /**
430  * struct htt_stats_context - htt stats information
431  * @soc: Size of each descriptor in the pool
432  * @msg: T2H Ext stats message queue
433  * @msg_len: T2H Ext stats message length
434  */
435 struct htt_stats_context {
436 	struct dp_soc *soc;
437 	qdf_nbuf_queue_t msg;
438 	uint32_t msg_len;
439 };
440 
441 int
442 dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(uint32_t bitmap);
443 
444 /**
445  * dp_ppdu_desc_user_stats_update(): Function to update TX user stats
446  * @pdev: DP pdev handle
447  * @ppdu_info: per PPDU TLV descriptor
448  *
449  * return: void
450  */
451 void
452 dp_ppdu_desc_user_stats_update(struct dp_pdev *pdev,
453 			       struct ppdu_info *ppdu_info);
454 
455 /**
456  * dp_htt_rx_flow_fst_setup(): Send HTT Rx FST setup message to FW
457  * @pdev: DP pdev handle
458  * @fse_setup_info: FST setup parameters
459  *
460  * Return: Success when HTT message is sent, error on failure
461  */
462 QDF_STATUS
463 dp_htt_rx_flow_fst_setup(struct dp_pdev *pdev,
464 			 struct dp_htt_rx_flow_fst_setup *setup_info);
465 
466 /**
467  * dp_htt_rx_flow_fse_operation(): Send HTT Flow Search Entry msg to
468  * add/del a flow in HW
469  * @pdev: DP pdev handle
470  * @fse_op_info: Flow entry parameters
471  *
472  * Return: Success when HTT message is sent, error on failure
473  */
474 QDF_STATUS
475 dp_htt_rx_flow_fse_operation(struct dp_pdev *pdev,
476 			     struct dp_htt_rx_flow_fst_operation *op_info);
477 
478 /**
479  * htt_h2t_full_mon_cfg() - Send full monitor configuarion msg to FW
480  *
481  * @htt_soc: HTT Soc handle
482  * @pdev_id: Radio id
483  * @dp_full_mon_config: enabled/disable configuration
484  *
485  * Return: Success when HTT message is sent, error on failure
486  */
487 int htt_h2t_full_mon_cfg(struct htt_soc *htt_soc,
488 			 uint8_t pdev_id,
489 			 enum dp_full_mon_config);
490 #endif /* _DP_HTT_H_ */
491