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