xref: /wlan-driver/qca-wifi-host-cmn/ipa/core/inc/wlan_ipa_priv.h (revision 5113495b16420b49004c444715d2daae2066e7dc) !
1 /*
2  * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: Declare various struct, macros which are used privately in IPA
22  * component.
23  */
24 
25 #ifndef _WLAN_IPA_PRIV_STRUCT_H_
26 #define _WLAN_IPA_PRIV_STRUCT_H_
27 
28 #ifdef IPA_OFFLOAD
29 
30 #include <linux/version.h>
31 #include <linux/kernel.h>
32 
33 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) || \
34 	defined(CONFIG_IPA_WDI_UNIFIED_API)
35 #include <qdf_ipa_wdi3.h>
36 #else
37 #include <qdf_ipa.h>
38 #endif
39 
40 #include <qdf_net_types.h>
41 #include <qdf_mc_timer.h>
42 #include <qdf_list.h>
43 #include <qdf_defer.h>
44 #include "qdf_delayed_work.h"
45 #include <qdf_event.h>
46 #include "wlan_ipa_public_struct.h"
47 #ifdef IPA_OPT_WIFI_DP
48 #include "cdp_txrx_ipa.h"
49 #endif
50 
51 #define WLAN_IPA_RX_INACTIVITY_MSEC_DELAY   1000
52 #define WLAN_IPA_UC_WLAN_8023_HDR_SIZE      14
53 
54 #define WLAN_IPA_UC_NUM_WDI_PIPE            2
55 #define WLAN_IPA_UC_MAX_PENDING_EVENT       33
56 
57 #define WLAN_IPA_UC_DEBUG_DUMMY_MEM_SIZE    32000
58 #define WLAN_IPA_UC_RT_DEBUG_PERIOD         300
59 #define WLAN_IPA_UC_RT_DEBUG_BUF_COUNT      30
60 #define WLAN_IPA_UC_RT_DEBUG_FILL_INTERVAL  10000
61 
62 #define WLAN_IPA_WLAN_HDR_DES_MAC_OFFSET    0
63 #define WLAN_IPA_MAX_IFACE                  MAX_IPA_IFACE
64 #define WLAN_IPA_CLIENT_MAX_IFACE           MAX_IPA_IFACE
65 #define WLAN_IPA_MAX_SYSBAM_PIPE            4
66 
67 #if defined(IPA_WDS_EASYMESH_FEATURE) || defined(QCA_WIFI_QCN9224)
68 #define WLAN_IPA_MAX_SESSION                MAX_IPA_IFACE //7
69 #else
70 #define WLAN_IPA_MAX_SESSION                5
71 #endif
72 
73 #ifdef WLAN_MAX_CLIENTS_ALLOWED
74 #define WLAN_IPA_MAX_STA_COUNT              WLAN_MAX_CLIENTS_ALLOWED
75 #else
76 #define WLAN_IPA_MAX_STA_COUNT              41
77 #endif
78 
79 #define WLAN_IPA_RX_PIPE                    (WLAN_IPA_MAX_SYSBAM_PIPE - 1)
80 #define WLAN_IPA_ENABLE_MASK                BIT(0)
81 #define WLAN_IPA_PRE_FILTER_ENABLE_MASK     BIT(1)
82 #define WLAN_IPA_IPV6_ENABLE_MASK           BIT(2)
83 #define WLAN_IPA_RM_ENABLE_MASK             BIT(3)
84 #define WLAN_IPA_CLK_SCALING_ENABLE_MASK    BIT(4)
85 #define WLAN_IPA_UC_ENABLE_MASK             BIT(5)
86 #define WLAN_IPA_UC_STA_ENABLE_MASK         BIT(6)
87 #define WLAN_IPA_REAL_TIME_DEBUGGING        BIT(8)
88 #define WLAN_IPA_OPT_WIFI_DP                BIT(9)
89 
90 #ifdef QCA_IPA_LL_TX_FLOW_CONTROL
91 #define WLAN_IPA_MAX_BANDWIDTH              4800
92 #define WLAN_IPA_MAX_BANDWIDTH_2G           1400
93 #else /* !QCA_IPA_LL_TX_FLOW_CONTROL */
94 #define WLAN_IPA_MAX_BANDWIDTH              800
95 #endif /* QCA_IPA_LL_TX_FLOW_CONTROL */
96 
97 #define WLAN_IPA_MAX_PENDING_EVENT_COUNT    20
98 
99 #define IPA_WLAN_RX_SOFTIRQ_THRESH 32
100 
101 #define WLAN_IPA_UC_BW_MONITOR_LEVEL        3
102 
103 /**
104  * enum wlan_ipa_uc_op_code - IPA UC operation message
105  *
106  * @WLAN_IPA_UC_OPCODE_TX_SUSPEND: IPA WDI TX pipe suspend
107  * @WLAN_IPA_UC_OPCODE_TX_RESUME: IPA WDI TX pipe resume
108  * @WLAN_IPA_UC_OPCODE_RX_SUSPEND: IPA WDI RX pipe suspend
109  * @WLAN_IPA_UC_OPCODE_RX_RESUME: IPA WDI RX pipe resume
110  * @WLAN_IPA_UC_OPCODE_STATS: IPA UC stats
111  * @WLAN_IPA_UC_OPCODE_SHARING_STATS: IPA UC sharing stats
112  * @WLAN_IPA_UC_OPCODE_QUOTA_RSP: IPA UC quota response
113  * @WLAN_IPA_UC_OPCODE_QUOTA_IND: IPA UC quota indication
114  * @WLAN_IPA_UC_OPCODE_UC_READY: IPA UC ready indication
115  * @WLAN_IPA_FILTER_RSV_NOTIFY: OPT WIFI DP filter reserve notification
116  * @WLAN_IPA_FILTER_REL_NOTIFY: OPT WIFI DP filter release notification
117  * @WLAN_IPA_SMMU_MAP: IPA SMMU map call
118  * @WLAN_IPA_SMMU_UNMAP: IPA SMMU unmap call
119  * @WLAN_IPA_UC_OPCODE_MAX: IPA UC max operation code
120  */
121 enum wlan_ipa_uc_op_code {
122 	WLAN_IPA_UC_OPCODE_TX_SUSPEND = 0,
123 	WLAN_IPA_UC_OPCODE_TX_RESUME = 1,
124 	WLAN_IPA_UC_OPCODE_RX_SUSPEND = 2,
125 	WLAN_IPA_UC_OPCODE_RX_RESUME = 3,
126 	WLAN_IPA_UC_OPCODE_STATS = 4,
127 #ifdef FEATURE_METERING
128 	WLAN_IPA_UC_OPCODE_SHARING_STATS = 5,
129 	WLAN_IPA_UC_OPCODE_QUOTA_RSP = 6,
130 	WLAN_IPA_UC_OPCODE_QUOTA_IND = 7,
131 #endif
132 	WLAN_IPA_UC_OPCODE_UC_READY = 8,
133 	WLAN_IPA_FILTER_RSV_NOTIFY = 9,
134 	WLAN_IPA_FILTER_REL_NOTIFY = 10,
135 	WLAN_IPA_SMMU_MAP = 11,
136 	WLAN_IPA_SMMU_UNMAP = 12,
137 	/* keep this last */
138 	WLAN_IPA_UC_OPCODE_MAX
139 };
140 
141 /**
142  * enum - Reason codes for stat query
143  *
144  * @WLAN_IPA_UC_STAT_REASON_NONE: Initial value
145  * @WLAN_IPA_UC_STAT_REASON_DEBUG: For debug/info
146  * @WLAN_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
147  */
148 enum {
149 	WLAN_IPA_UC_STAT_REASON_NONE,
150 	WLAN_IPA_UC_STAT_REASON_DEBUG,
151 	WLAN_IPA_UC_STAT_REASON_BW_CAL
152 };
153 
154 /**
155  * enum wlan_ipa_rm_state - IPA resource manager state
156  * @WLAN_IPA_RM_RELEASED:      PROD pipe resource released
157  * @WLAN_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
158  * @WLAN_IPA_RM_GRANTED:       PROD pipe resource granted
159  */
160 enum wlan_ipa_rm_state {
161 	WLAN_IPA_RM_RELEASED,
162 	WLAN_IPA_RM_GRANT_PENDING,
163 	WLAN_IPA_RM_GRANTED,
164 };
165 
166 /**
167  * enum wlan_ipa_forward_type: Type of forward packet received from IPA
168  * @WLAN_IPA_FORWARD_PKT_NONE: No forward packet
169  * @WLAN_IPA_FORWARD_PKT_LOCAL_STACK: Packet forwarded to kernel network stack
170  * @WLAN_IPA_FORWARD_PKT_DISCARD: Discarded packet before sending to kernel
171  */
172 enum wlan_ipa_forward_type {
173 	WLAN_IPA_FORWARD_PKT_NONE = 0,
174 	WLAN_IPA_FORWARD_PKT_LOCAL_STACK = 1,
175 	WLAN_IPA_FORWARD_PKT_DISCARD = 2
176 };
177 
178 /**
179  * struct llc_snap_hdr - LLC snap header
180  * @dsap: Destination service access point
181  * @ssap: Source service access point
182  * @resv: Reserved for future use
183  * @eth_type: Ether type
184  */
185 struct llc_snap_hdr {
186 	uint8_t dsap;
187 	uint8_t ssap;
188 	uint8_t resv[4];
189 	qdf_be16_t eth_type;
190 } qdf_packed;
191 
192 /**
193  * struct wlan_ipa_tx_hdr - header type which IPA should handle to TX packet
194  * @eth:      ether II header
195  * @llc_snap: LLC snap header
196  */
197 struct wlan_ipa_tx_hdr {
198 	qdf_ether_header_t eth;
199 	struct llc_snap_hdr llc_snap;
200 } qdf_packed;
201 
202 #if defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCA6390) || \
203     defined(QCA_WIFI_QCA6490) || defined(QCA_WIFI_QCA6750) || \
204     defined(QCA_WIFI_WCN7850) || defined(QCA_WIFI_QCN9000) || \
205     defined(QCA_WIFI_KIWI) || defined(QCA_WIFI_KIWI_V2)
206 /**
207  * struct frag_header - fragment header type registered to IPA hardware
208  * @length:    fragment length
209  * @reserved: Reserved not used
210  */
211 struct frag_header {
212 	__QDF_DECLARE_FLEX_ARRAY(uint8_t, reserved);
213 };
214 #elif defined(QCA_WIFI_3_0)
215 /**
216  * struct frag_header - fragment header type registered to IPA hardware
217  * @length:    fragment length
218  * @reserved1: Reserved not used
219  * @reserved2: Reserved not used
220  */
221 struct frag_header {
222 	uint16_t length;
223 	uint32_t reserved1;
224 	uint32_t reserved2;
225 } qdf_packed;
226 #else
227 struct frag_header {
228 	uint32_t
229 		length:16,
230 		reserved16:16;
231 	uint32_t reserved2;
232 } qdf_packed;
233 #endif
234 
235 #if defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCA6390) || \
236     defined(QCA_WIFI_QCA6490) || defined(QCA_WIFI_QCA6750) || \
237     defined(QCA_WIFI_WCN7850) || defined(QCA_WIFI_QCN9000) || \
238     defined(QCA_WIFI_KIWI) || defined(QCA_WIFI_KIWI_V2)
239 /**
240  * struct ipa_header - ipa header type registered to IPA hardware
241  * @reserved: Reserved not used
242  */
243 struct ipa_header {
244 	__QDF_DECLARE_FLEX_ARRAY(uint8_t, reserved);
245 };
246 #else
247 /**
248  * struct ipa_header - ipa header type registered to IPA hardware
249  * @vdev_id:  vdev id
250  * @reserved: Reserved not used
251  */
252 struct ipa_header {
253 	uint32_t
254 		vdev_id:8,	/* vdev_id field is LSB of IPA DESC */
255 		reserved:24;
256 } qdf_packed;
257 #endif
258 
259 /**
260  * struct wlan_ipa_uc_tx_hdr - full tx header registered to IPA hardware
261  * @frag_hd: fragment header
262  * @ipa_hd:  ipa header
263  * @eth:     ether II header
264  */
265 struct wlan_ipa_uc_tx_hdr {
266 	struct frag_header frag_hd;
267 	struct ipa_header ipa_hd;
268 	qdf_ether_header_t eth;
269 } qdf_packed;
270 
271 /**
272  * struct wlan_ipa_cld_hdr - IPA CLD Header
273  * @reserved: reserved fields
274  * @iface_id: interface ID
275  * @sta_id: Station ID
276  *
277  * Packed 32-bit structure
278  * +----------+----------+--------------+--------+
279  * | Reserved | QCMAP ID | interface id | STA ID |
280  * +----------+----------+--------------+--------+
281  */
282 struct wlan_ipa_cld_hdr {
283 	uint8_t reserved[2];
284 	uint8_t iface_id;
285 	uint8_t sta_id;
286 } qdf_packed;
287 
288 /**
289  * struct wlan_ipa_rx_hdr - IPA RX header
290  * @cld_hdr: IPA CLD header
291  * @eth:     ether II header
292  */
293 struct wlan_ipa_rx_hdr {
294 	struct wlan_ipa_cld_hdr cld_hdr;
295 	qdf_ether_header_t eth;
296 } qdf_packed;
297 
298 /**
299  * struct wlan_ipa_pm_tx_cb - PM resume TX callback
300  * @exception: Exception packet
301  * @iface_context: Interface context
302  * @ipa_tx_desc: IPA TX descriptor
303  * @send_to_nw: RX exception packet that needs to be passed up to stack
304  */
305 struct wlan_ipa_pm_tx_cb {
306 	bool exception;
307 	struct wlan_ipa_iface_context *iface_context;
308 	qdf_ipa_rx_data_t *ipa_tx_desc;
309 	bool send_to_nw;
310 };
311 
312 /**
313  * struct wlan_ipa_sys_pipe - IPA system pipe
314  * @conn_hdl: IPA system pipe connection handle
315  * @conn_hdl_valid: IPA system pipe valid flag
316  * @ipa_sys_params: IPA system pipe params
317  */
318 struct wlan_ipa_sys_pipe {
319 	uint32_t conn_hdl;
320 	uint8_t conn_hdl_valid;
321 	qdf_ipa_sys_connect_params_t ipa_sys_params;
322 };
323 
324 /**
325  * struct wlan_ipa_iface_stats - IPA system pipe
326  * @num_tx: Number of TX packets
327  * @num_tx_drop: Number of TX packet drops
328  * @num_tx_err: Number of TX packet errors
329  * @num_tx_cac_drop: Number of TX packet drop due to CAC
330  * @num_rx_ipa_excep: Number of RX IPA exception packets
331  */
332 struct wlan_ipa_iface_stats {
333 	uint64_t num_tx;
334 	uint64_t num_tx_drop;
335 	uint64_t num_tx_err;
336 	uint64_t num_tx_cac_drop;
337 	uint64_t num_rx_ipa_excep;
338 };
339 
340 /* IPA private context structure */
341 struct wlan_ipa_priv;
342 
343 /**
344  * struct wlan_ipa_iface_context - IPA interface context
345  * @ipa_ctx: IPA private context
346  * @cons_client: IPA consumer pipe
347  * @prod_client: IPA producer pipe
348  * @iface_id: IPA interface ID
349  * @dev: Net device structure
350  * @device_mode: Interface device mode
351  * @mac_addr: MAC address
352  * @conn_count: Connect count
353  * @disconn_count: Disconnect count
354  * @session_id: Session ID
355  * @interface_lock: Interface lock
356  * @ifa_address: Interface address
357  * @stats: Interface stats
358  * @bssid: BSSID. valid only for sta iface ctx
359  * @is_authenticated: is peer authenticated
360  * @alt_pipe: Indicate whether the interface uses alternate TX pipe
361  */
362 struct wlan_ipa_iface_context {
363 	struct wlan_ipa_priv *ipa_ctx;
364 
365 	qdf_ipa_client_type_t cons_client;
366 	qdf_ipa_client_type_t prod_client;
367 
368 	uint8_t iface_id;       /* This iface ID */
369 	qdf_netdev_t dev;
370 	enum QDF_OPMODE device_mode;
371 	uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
372 	qdf_atomic_t conn_count;
373 	qdf_atomic_t disconn_count;
374 	uint8_t session_id;
375 	qdf_spinlock_t interface_lock;
376 	uint32_t ifa_address;
377 	struct wlan_ipa_iface_stats stats;
378 	struct qdf_mac_addr bssid;
379 	uint8_t is_authenticated;
380 #ifdef IPA_WDI3_TX_TWO_PIPES
381 	bool alt_pipe;
382 #endif
383 };
384 
385 /**
386  * struct wlan_ipa_stats - IPA system stats
387  * @event: WLAN IPA event record
388  * @num_send_msg: Number of sent IPA messages
389  * @num_free_msg: Number of freed IPA messages
390  * @num_rm_grant: Number of times IPA RM resource granted
391  * @num_rm_release: Number of times IPA RM resource released
392  * @num_rm_grant_imm: Number of immediate IPA RM granted
393  * @num_cons_perf_req: Number of CONS pipe perf request
394  * @num_prod_perf_req: Number of PROD pipe perf request
395  * @num_rx_drop: Number of RX packet drops
396  * @num_tx_desc_q_cnt: Number of TX descriptor queue count
397  * @num_tx_desc_error: Number of TX descriptor error
398  * @num_tx_comp_cnt: Number of TX qdf_event_t count
399  * @num_tx_queued: Number of TX queued
400  * @num_tx_dequeued: Number of TX dequeued
401  * @num_max_pm_queue: Number of packets in PM queue
402  * @num_rx_excep: Number of RX IPA exception packets
403  * @num_rx_no_iface_eapol: No of EAPOL pkts before iface setup
404  * @num_tx_fwd_ok: Number of TX forward packet success
405  * @num_tx_fwd_err: Number of TX forward packet failures
406  */
407 struct wlan_ipa_stats {
408 	uint32_t event[QDF_IPA_WLAN_EVENT_MAX];
409 	uint64_t num_send_msg;
410 	uint64_t num_free_msg;
411 	uint64_t num_rm_grant;
412 	uint64_t num_rm_release;
413 	uint64_t num_rm_grant_imm;
414 	uint64_t num_cons_perf_req;
415 	uint64_t num_prod_perf_req;
416 	uint64_t num_rx_drop;
417 	uint64_t num_tx_desc_q_cnt;
418 	uint64_t num_tx_desc_error;
419 	uint64_t num_tx_comp_cnt;
420 	uint64_t num_tx_queued;
421 	uint64_t num_tx_dequeued;
422 	uint64_t num_max_pm_queue;
423 	uint64_t num_rx_excep;
424 	uint64_t num_rx_no_iface_eapol;
425 	uint64_t num_tx_fwd_ok;
426 	uint64_t num_tx_fwd_err;
427 };
428 
429 /**
430  * struct ipa_uc_stas_map - IPA UC assoc station map
431  * @is_reserved: STA reserved flag
432  * @is_authenticated: is peer authenticated
433  * @mac_addr: Station mac address
434  */
435 struct ipa_uc_stas_map {
436 	bool is_reserved;
437 	struct qdf_mac_addr mac_addr;
438 	uint8_t is_authenticated;
439 };
440 
441 /**
442  * struct op_msg_type - IPA operation message type
443  * @msg_t: Message type
444  * @rsvd: Reserved
445  * @op_code: IPA Operation type
446  * @len: IPA message length
447  * @rsvd_snd: Reserved
448  */
449 struct op_msg_type {
450 	uint8_t msg_t;
451 	uint8_t rsvd;
452 	uint16_t op_code;
453 	uint16_t len;
454 	uint16_t rsvd_snd;
455 };
456 
457 /**
458  * struct ipa_uc_fw_stats - IPA FW stats
459  * @tx_comp_ring_base: TX completion ring base address
460  * @tx_comp_ring_size: TX completion ring size
461  * @tx_comp_ring_dbell_addr: TX completion ring door bell address
462  * @tx_comp_ring_dbell_ind_val: TX completion ring door bell indication
463  * @tx_comp_ring_dbell_cached_val: TX completion ring cached value
464  * @tx_pkts_enqueued: TX packets enqueued
465  * @tx_pkts_completed: TX packets completed
466  * @tx_is_suspend: TX suspend flag
467  * @tx_reserved: Reserved for TX stat
468  * @rx_ind_ring_base: RX indication ring base address
469  * @rx_ind_ring_size: RX indication ring size
470  * @rx_ind_ring_dbell_addr: RX indication ring doorbell address
471  * @rx_ind_ring_dbell_ind_val: RX indication ring doorbell indication
472  * @rx_ind_ring_dbell_ind_cached_val: RX indication ring doorbell cached value
473  * @rx_ind_ring_rdidx_addr: RX indication ring read index address
474  * @rx_ind_ring_rd_idx_cached_val: RX indication ring read index cached value
475  * @rx_refill_idx: RX ring refill index
476  * @rx_num_pkts_indicated: Number of RX packets indicated
477  * @rx_buf_refilled: Number of RX buffer refilled
478  * @rx_num_ind_drop_no_space: Number of RX indication drops due to no space
479  * @rx_num_ind_drop_no_buf: Number of RX indication drops due to no buffer
480  * @rx_is_suspend: RX suspend flag
481  * @rx_reserved: Reserved for RX stat
482  */
483 struct ipa_uc_fw_stats {
484 	uint32_t tx_comp_ring_base;
485 	uint32_t tx_comp_ring_size;
486 	uint32_t tx_comp_ring_dbell_addr;
487 	uint32_t tx_comp_ring_dbell_ind_val;
488 	uint32_t tx_comp_ring_dbell_cached_val;
489 	uint32_t tx_pkts_enqueued;
490 	uint32_t tx_pkts_completed;
491 	uint32_t tx_is_suspend;
492 	uint32_t tx_reserved;
493 	uint32_t rx_ind_ring_base;
494 	uint32_t rx_ind_ring_size;
495 	uint32_t rx_ind_ring_dbell_addr;
496 	uint32_t rx_ind_ring_dbell_ind_val;
497 	uint32_t rx_ind_ring_dbell_ind_cached_val;
498 	uint32_t rx_ind_ring_rdidx_addr;
499 	uint32_t rx_ind_ring_rd_idx_cached_val;
500 	uint32_t rx_refill_idx;
501 	uint32_t rx_num_pkts_indicated;
502 	uint32_t rx_buf_refilled;
503 	uint32_t rx_num_ind_drop_no_space;
504 	uint32_t rx_num_ind_drop_no_buf;
505 	uint32_t rx_is_suspend;
506 	uint32_t rx_reserved;
507 };
508 
509 /**
510  * struct wlan_ipa_uc_pending_event - WLAN IPA UC pending event
511  * @node: Pending event list node
512  * @type: WLAN IPA event type
513  * @net_dev: network device
514  * @device_mode: Device mode
515  * @session_id: Session ID
516  * @mac_addr: Mac address
517  * @is_loading: Driver loading flag
518  * @is_2g_iface: true if interface is operating on 2G band, otherwise false
519  */
520 struct wlan_ipa_uc_pending_event {
521 	qdf_list_node_t node;
522 	qdf_ipa_wlan_event type;
523 	qdf_netdev_t net_dev;
524 	uint8_t device_mode;
525 	uint8_t session_id;
526 	uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
527 	bool is_loading;
528 	bool is_2g_iface;
529 };
530 
531 /**
532  * struct uc_rm_work_struct
533  * @work: uC RM work
534  * @event: IPA RM event
535  */
536 struct uc_rm_work_struct {
537 	qdf_work_t work;
538 	qdf_ipa_rm_event_t event;
539 };
540 
541 /**
542  * struct uc_op_work_struct
543  * @work: uC OP work
544  * @msg: OP message
545  * @osdev: pointer to qdf net device, used by osif_psoc_sync_trans_start_wait
546  * @ipa_priv_bp: back pointer to ipa_obj
547  */
548 struct uc_op_work_struct {
549 	qdf_work_t work;
550 	struct op_msg_type *msg;
551 	qdf_device_t osdev;
552 	struct wlan_ipa_priv *ipa_priv_bp;
553 };
554 
555 /**
556  * struct uc_rt_debug_info
557  * @time: system time
558  * @ipa_excep_count: IPA exception packet count
559  * @rx_drop_count: IPA Rx drop packet count
560  * @net_sent_count: IPA Rx packet sent to network stack count
561  * @rx_discard_count: IPA Rx discard packet count
562  * @tx_fwd_ok_count: IPA Tx forward success packet count
563  * @tx_fwd_count: IPA Tx forward packet count
564  * @rx_destructor_call: IPA Rx packet destructor count
565  */
566 struct uc_rt_debug_info {
567 	uint64_t time;
568 	uint64_t ipa_excep_count;
569 	uint64_t rx_drop_count;
570 	uint64_t net_sent_count;
571 	uint64_t rx_discard_count;
572 	uint64_t tx_fwd_ok_count;
573 	uint64_t tx_fwd_count;
574 	uint64_t rx_destructor_call;
575 };
576 
577 #ifdef FEATURE_METERING
578 /**
579  * struct ipa_uc_sharing_stats - IPA UC sharing stats
580  * @ipv4_rx_packets: IPv4 RX packets
581  * @ipv4_rx_bytes: IPv4 RX bytes
582  * @ipv6_rx_packets: IPv6 RX packets
583  * @ipv6_rx_bytes: IPv6 RX bytes
584  * @ipv4_tx_packets: IPv4 TX packets
585  * @ipv4_tx_bytes: IPv4 TX bytes
586  * @ipv6_tx_packets: IPv4 TX packets
587  * @ipv6_tx_bytes: IPv6 TX bytes
588  */
589 struct ipa_uc_sharing_stats {
590 	uint64_t ipv4_rx_packets;
591 	uint64_t ipv4_rx_bytes;
592 	uint64_t ipv6_rx_packets;
593 	uint64_t ipv6_rx_bytes;
594 	uint64_t ipv4_tx_packets;
595 	uint64_t ipv4_tx_bytes;
596 	uint64_t ipv6_tx_packets;
597 	uint64_t ipv6_tx_bytes;
598 };
599 
600 /**
601  * struct ipa_uc_quota_rsp - IPA UC quota response
602  * @success: Success or fail flag
603  * @reserved: Reserved
604  * @quota_lo: Quota limit low bytes
605  * @quota_hi: Quota limit high bytes
606  */
607 struct ipa_uc_quota_rsp {
608 	uint8_t success;
609 	uint8_t reserved[3];
610 	uint32_t quota_lo;
611 	uint32_t quota_hi;
612 };
613 
614 /**
615  * struct ipa_uc_quota_ind
616  * @quota_bytes: Quota bytes to set
617  */
618 struct ipa_uc_quota_ind {
619 	uint64_t quota_bytes;
620 };
621 #endif
622 
623 /**
624  * struct wlan_ipa_tx_desc
625  * @node: TX descriptor node
626  * @priv: pointer to priv list entry
627  * @id: Tx desc idex
628  * @ipa_tx_desc_ptr: pointer to IPA Tx descriptor
629  */
630 struct wlan_ipa_tx_desc {
631 	qdf_list_node_t node;
632 	void *priv;
633 	uint32_t id;
634 	qdf_ipa_rx_data_t *ipa_tx_desc_ptr;
635 };
636 
637 typedef QDF_STATUS (*wlan_ipa_softap_xmit)(qdf_nbuf_t nbuf, qdf_netdev_t dev);
638 typedef void (*wlan_ipa_send_to_nw)(qdf_nbuf_t nbuf, qdf_netdev_t dev);
639 typedef bool (*wlan_ipa_driver_unloading)(void);
640 
641 /**
642  * typedef wlan_ipa_rps_enable - Enable/disable RPS for adapter using vdev id
643  * @vdev_id: vdev_id of adapter
644  * @enable: Set true to enable RPS
645  */
646 typedef void (*wlan_ipa_rps_enable)(uint8_t vdev_id, bool enable);
647 
648 /* IPA private context structure definition */
649 struct wlan_ipa_priv {
650 	struct wlan_objmgr_pdev *pdev;
651 	struct wlan_ipa_sys_pipe sys_pipe[WLAN_IPA_MAX_SYSBAM_PIPE];
652 	struct wlan_ipa_iface_context iface_context[WLAN_IPA_MAX_IFACE];
653 	uint8_t num_iface;
654 	void *dp_soc;
655 	uint8_t dp_pdev_id;
656 	struct wlan_ipa_config *config;
657 	enum wlan_ipa_rm_state rm_state;
658 	/*
659 	 * IPA driver can send RM notifications with IRQ disabled so using qdf
660 	 * APIs as it is taken care gracefully. Without this, kernel would throw
661 	 * an warning if spin_lock_bh is used while IRQ is disabled
662 	 */
663 	qdf_spinlock_t rm_lock;
664 	struct uc_rm_work_struct uc_rm_work;
665 	struct uc_op_work_struct uc_op_work[WLAN_IPA_UC_OPCODE_MAX];
666 	qdf_wake_lock_t wake_lock;
667 	struct qdf_delayed_work wake_lock_work;
668 	bool wake_lock_released;
669 
670 	qdf_atomic_t tx_ref_cnt;
671 	qdf_nbuf_queue_t pm_queue_head;
672 	qdf_work_t pm_work;
673 	qdf_spinlock_t pm_lock;
674 	bool suspended;
675 	qdf_spinlock_t q_lock;
676 	qdf_spinlock_t enable_disable_lock;
677 	/* Flag to indicate wait on pending TX completions */
678 	qdf_atomic_t waiting_on_pending_tx;
679 	/* Timer ticks to keep track of time after which pipes are disabled */
680 	uint64_t pending_tx_start_ticks;
681 	/* Indicates if cdp_ipa_disable_autonomy is called for IPA pipes */
682 	qdf_atomic_t autonomy_disabled;
683 	/* Indicates if cdp_disable_ipa_pipes has been called for IPA pipes */
684 	qdf_atomic_t pipes_disabled;
685 	/*
686 	 * IPA pipes are considered "down" when both autonomy_disabled and
687 	 * ipa_pipes_disabled are set
688 	 */
689 	bool ipa_pipes_down;
690 	/* Flag for mutual exclusion during IPA disable pipes */
691 	bool pipes_down_in_progress;
692 	/* Flag for mutual exclusion during IPA enable pipes */
693 	bool pipes_enable_in_progress;
694 	qdf_list_node_t pend_desc_head;
695 	struct wlan_ipa_tx_desc *tx_desc_pool;
696 	qdf_list_t tx_desc_free_list;
697 
698 	struct wlan_ipa_stats stats;
699 
700 	uint32_t curr_prod_bw;
701 	uint32_t curr_cons_bw;
702 
703 	uint8_t activated_fw_pipe;
704 	uint8_t num_sap_connected;
705 	uint8_t sap_num_connected_sta;
706 	uint8_t sta_connected;
707 	uint32_t tx_pipe_handle;
708 	uint32_t rx_pipe_handle;
709 	bool resource_loading;
710 	bool resource_unloading;
711 	bool pending_cons_req;
712 	struct ipa_uc_stas_map assoc_stas_map[WLAN_IPA_MAX_STA_COUNT];
713 	qdf_list_t pending_event;
714 	qdf_mutex_t event_lock;
715 	uint32_t ipa_tx_packets_diff;
716 	uint32_t ipa_rx_packets_diff;
717 	uint32_t ipa_p_tx_packets;
718 	uint32_t ipa_p_rx_packets;
719 	uint32_t stat_req_reason;
720 	uint64_t ipa_tx_forward;
721 	uint64_t ipa_rx_discard;
722 	uint64_t ipa_rx_net_send_count;
723 	uint64_t ipa_rx_internal_drop_count;
724 	uint64_t ipa_rx_destructor_count;
725 	qdf_mc_timer_t rt_debug_timer;
726 	struct uc_rt_debug_info rt_bug_buffer[WLAN_IPA_UC_RT_DEBUG_BUF_COUNT];
727 	unsigned int rt_buf_fill_index;
728 	qdf_ipa_wdi_in_params_t cons_pipe_in;
729 	qdf_ipa_wdi_in_params_t prod_pipe_in;
730 	bool uc_loaded;
731 	bool wdi_enabled;
732 	bool over_gsi;
733 	qdf_mc_timer_t rt_debug_fill_timer;
734 	qdf_mutex_t rt_debug_lock;
735 	qdf_mutex_t ipa_lock;
736 
737 	uint8_t vdev_to_iface[WLAN_IPA_MAX_SESSION];
738 	bool vdev_offload_enabled[WLAN_IPA_MAX_SESSION];
739 	bool mcc_mode;
740 	qdf_work_t mcc_work;
741 	bool disable_intrabss_fwd[WLAN_IPA_MAX_SESSION];
742 	bool dfs_cac_block_tx;
743 #ifdef FEATURE_METERING
744 	struct ipa_uc_sharing_stats ipa_sharing_stats;
745 	struct ipa_uc_quota_rsp ipa_quota_rsp;
746 	struct ipa_uc_quota_ind ipa_quota_ind;
747 	qdf_event_t ipa_uc_sharing_stats_comp;
748 	qdf_event_t ipa_uc_set_quota_comp;
749 #endif
750 
751 	wlan_ipa_softap_xmit softap_xmit;
752 	wlan_ipa_send_to_nw send_to_nw;
753 
754 #if defined(QCA_CONFIG_RPS) && !defined(MDM_PLATFORM)
755 	/*Callback to enable RPS for STA in STA+SAP scenario*/
756 	wlan_ipa_rps_enable rps_enable;
757 #endif
758 	wlan_ipa_driver_unloading driver_is_unloading;
759 	qdf_event_t ipa_resource_comp;
760 
761 	uint32_t wdi_version;
762 	bool is_smmu_enabled;	/* IPA caps returned from ipa_wdi_init */
763 	/* Flag to notify whether optional wifi dp feature is enabled or not */
764 	bool opt_wifi_datapath;
765 	qdf_atomic_t stats_quota;
766 	uint8_t curr_bw_level;
767 	qdf_atomic_t deinit_in_prog;
768 	uint8_t instance_id;
769 	bool handle_initialized;
770 	qdf_ipa_wdi_hdl_t hdl;
771 #ifdef IPA_OPT_WIFI_DP
772 	struct wifi_dp_flt_setup dp_cce_super_rule_flt_param;
773 	qdf_event_t ipa_flt_evnt;
774 	qdf_wake_lock_t opt_dp_wake_lock;
775 #endif
776 };
777 
778 #define WLAN_IPA_WLAN_FRAG_HEADER        sizeof(struct frag_header)
779 #define WLAN_IPA_WLAN_IPA_HEADER         sizeof(struct ipa_header)
780 #define WLAN_IPA_WLAN_CLD_HDR_LEN        sizeof(struct wlan_ipa_cld_hdr)
781 #define WLAN_IPA_UC_WLAN_CLD_HDR_LEN     0
782 #define WLAN_IPA_WLAN_TX_HDR_LEN         sizeof(struct wlan_ipa_tx_hdr)
783 #define WLAN_IPA_UC_WLAN_TX_HDR_LEN      sizeof(struct wlan_ipa_uc_tx_hdr)
784 #define WLAN_IPA_WLAN_RX_HDR_LEN         sizeof(struct wlan_ipa_rx_hdr)
785 #define WLAN_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
786 	(WLAN_IPA_WLAN_FRAG_HEADER + WLAN_IPA_WLAN_IPA_HEADER)
787 
788 #define WLAN_IPA_GET_IFACE_ID(_data) \
789 	(((struct wlan_ipa_cld_hdr *) (_data))->iface_id)
790 
791 #define WLAN_IPA_LOG(LVL, fmt, args ...) \
792 	QDF_TRACE(QDF_MODULE_ID_IPA, LVL, \
793 		  "%s:%d: "fmt, __func__, __LINE__, ## args)
794 
795 #define WLAN_IPA_IS_CONFIG_ENABLED(_ipa_cfg, _mask) \
796 	(((_ipa_cfg)->ipa_config & (_mask)) == (_mask))
797 
798 #define BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
799 
800 #define IPA_RESOURCE_COMP_WAIT_TIME	500
801 
802 #ifdef FEATURE_METERING
803 #define IPA_UC_SHARING_STATES_WAIT_TIME	500
804 #define IPA_UC_SET_QUOTA_WAIT_TIME	500
805 #endif
806 
807 /**
808  * wlan_ipa_wlan_event_to_str() - convert IPA WLAN event to string
809  * @event: IPA WLAN event to be converted to a string
810  *
811  * Return: ASCII string representing the IPA WLAN event
812  */
wlan_ipa_wlan_event_to_str(qdf_ipa_wlan_event event)813 static inline char *wlan_ipa_wlan_event_to_str(qdf_ipa_wlan_event event)
814 {
815 	switch (event) {
816 	CASE_RETURN_STRING(QDF_IPA_CLIENT_CONNECT);
817 	CASE_RETURN_STRING(QDF_IPA_CLIENT_DISCONNECT);
818 	CASE_RETURN_STRING(QDF_IPA_AP_CONNECT);
819 	CASE_RETURN_STRING(QDF_IPA_AP_DISCONNECT);
820 	CASE_RETURN_STRING(QDF_IPA_STA_CONNECT);
821 	CASE_RETURN_STRING(QDF_IPA_STA_DISCONNECT);
822 	CASE_RETURN_STRING(QDF_IPA_CLIENT_CONNECT_EX);
823 	CASE_RETURN_STRING(QDF_SWITCH_TO_SCC);
824 	CASE_RETURN_STRING(QDF_SWITCH_TO_MCC);
825 	CASE_RETURN_STRING(QDF_WDI_ENABLE);
826 	CASE_RETURN_STRING(QDF_WDI_DISABLE);
827 	default:
828 		return "UNKNOWN";
829 	}
830 }
831 
832 /**
833  * wlan_ipa_get_iface() - Get IPA interface
834  * @ipa_ctx: IPA context
835  * @mode: Interface device mode
836  *
837  * Return: IPA interface address
838  */
839 struct wlan_ipa_iface_context
840 *wlan_ipa_get_iface(struct wlan_ipa_priv *ipa_ctx, uint8_t mode);
841 
842 #endif /* IPA_OFFLOAD */
843 #endif /* _WLAN_IPA_PRIV_STRUCT_H_ */
844