1 /*
2 * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022-2023 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 #ifndef __CDS_UTILS_H
21 #define __CDS_UTILS_H
22
23 /**
24 * DOC: cds_utils.h
25 * Connectivity driver services (CDS) utility APIs
26 * Various utility functions
27 */
28
29 #include <qdf_types.h>
30 #include <qdf_status.h>
31 #include <qdf_event.h>
32 #include <qdf_lock.h>
33 #include "ani_global.h"
34
35 /*--------------------------------------------------------------------------
36 Preprocessor definitions and constants
37 ------------------------------------------------------------------------*/
38 #define CDS_24_GHZ_BASE_FREQ (2407)
39 #define CDS_5_GHZ_BASE_FREQ (5000)
40 #define CDS_24_GHZ_CHANNEL_1 (1)
41 #define CDS_24_GHZ_CHANNEL_14 (14)
42 #define CDS_24_GHZ_CHANNEL_15 (15)
43 #define CDS_24_GHZ_CHANNEL_27 (27)
44 #define CDS_5_GHZ_CHANNEL_165 (165)
45 #define CDS_5_GHZ_CHANNEL_170 (170)
46 #define CDS_CHAN_SPACING_5MHZ (5)
47 #define CDS_CHAN_SPACING_20MHZ (20)
48 #define CDS_CHAN_14_FREQ (2484)
49 #define CDS_CHAN_15_FREQ (2512)
50 #define CDS_CHAN_170_FREQ (5852)
51
52 #define INVALID_SCAN_ID 0xFFFFFFFF
53
54 #define CDS_DBS_SCAN_CLIENTS_MAX (7)
55 #define CDS_DBS_SCAN_PARAM_PER_CLIENT (3)
56
57 #define cds_alert(params...) QDF_TRACE_FATAL(QDF_MODULE_ID_QDF, params)
58 #define cds_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, params)
59 #define cds_warn(params...) QDF_TRACE_WARN(QDF_MODULE_ID_QDF, params)
60 #define cds_info(params...) QDF_TRACE_INFO(QDF_MODULE_ID_QDF, params)
61 #define cds_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_QDF, params)
62
63 #define cds_nofl_alert(params...) \
64 QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_QDF, params)
65 #define cds_nofl_err(params...) \
66 QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_QDF, params)
67 #define cds_nofl_warn(params...) \
68 QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_QDF, params)
69 #define cds_nofl_info(params...) \
70 QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_QDF, params)
71 #define cds_nofl_debug(params...) \
72 QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_QDF, params)
73
74 #define cds_enter() QDF_TRACE_ENTER(QDF_MODULE_ID_QDF, "enter")
75 #define cds_exit() QDF_TRACE_EXIT(QDF_MODULE_ID_QDF, "exit")
76
77 /**
78 * enum cds_band_type - Band type - 2g, 5g or all
79 * @CDS_BAND_ALL: Both 2G and 5G are valid.
80 * @CDS_BAND_2GHZ: only 2G is valid.
81 * @CDS_BAND_5GHZ: only 5G is valid.
82 */
83 enum cds_band_type {
84 CDS_BAND_ALL = 0,
85 CDS_BAND_2GHZ = 1,
86 CDS_BAND_5GHZ = 2
87 };
88
89 /*-------------------------------------------------------------------------
90 Function declarations and documentation
91 ------------------------------------------------------------------------*/
92
93 uint32_t cds_chan_to_freq(uint8_t chan);
94 uint8_t cds_freq_to_chan(uint32_t freq);
95 enum cds_band_type cds_chan_to_band(uint32_t chan);
96
97 uint8_t cds_get_mmie_size(void);
98
99 /**
100 * cds_get_gmac_mmie_size() - Gives length of GMAC MMIE size
101 *
102 * Return: Size of MMIE for GMAC
103 */
104 uint8_t cds_get_gmac_mmie_size(void);
105
cds_host_diag_log_work(qdf_wake_lock_t * lock,uint32_t msec,uint32_t reason)106 static inline void cds_host_diag_log_work(qdf_wake_lock_t *lock, uint32_t msec,
107 uint32_t reason) {
108 if (((cds_get_ring_log_level(RING_ID_WAKELOCK) >= WLAN_LOG_LEVEL_ACTIVE)
109 && (WIFI_POWER_EVENT_WAKELOCK_HOLD_RX == reason)) ||
110 (WIFI_POWER_EVENT_WAKELOCK_HOLD_RX != reason)) {
111 host_diag_log_wlock(reason, qdf_wake_lock_name(lock),
112 msec, WIFI_POWER_EVENT_WAKELOCK_TAKEN);
113 }
114 }
115
116 /**
117 * cds_copy_hlp_info() - Copy HLP info
118 * @input_dst_mac: input HLP destination MAC address
119 * @input_src_mac: input HLP source MAC address
120 * @input_hlp_data_len: input HLP data length
121 * @input_hlp_data: Pointer to input HLP data
122 * @output_dst_mac: output HLP destination MAC address
123 * @output_src_mac: output HLP source MAC address
124 * @output_hlp_data_len: Pointer to output HLP data length
125 * @output_hlp_data: output Pointer to HLP data
126 *
127 * Util API to copy HLP info from input to output
128 *
129 * Return: None
130 */
131 void cds_copy_hlp_info(struct qdf_mac_addr *input_dst_mac,
132 struct qdf_mac_addr *input_src_mac,
133 uint16_t input_hlp_data_len,
134 uint8_t *input_hlp_data,
135 struct qdf_mac_addr *output_dst_mac,
136 struct qdf_mac_addr *output_src_mac,
137 uint16_t *output_hlp_data_len,
138 uint8_t *output_hlp_data);
139 #endif /* #ifndef __CDS_UTILS_H */
140