xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723bu/hal/btc/HalBtc8723b1Ant.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
4 
5 #if (RTL8723B_SUPPORT == 1)
6 /* *******************************************
7  * The following is for 8723B 1ANT BT Co-exist definition
8  * ******************************************* */
9 #define	BT_AUTO_REPORT_ONLY_8723B_1ANT				1
10 
11 #define	BT_INFO_8723B_1ANT_B_FTP						BIT(7)
12 #define	BT_INFO_8723B_1ANT_B_A2DP					BIT(6)
13 #define	BT_INFO_8723B_1ANT_B_HID						BIT(5)
14 #define	BT_INFO_8723B_1ANT_B_SCO_BUSY				BIT(4)
15 #define	BT_INFO_8723B_1ANT_B_ACL_BUSY				BIT(3)
16 #define	BT_INFO_8723B_1ANT_B_INQ_PAGE				BIT(2)
17 #define	BT_INFO_8723B_1ANT_B_SCO_ESCO				BIT(1)
18 #define	BT_INFO_8723B_1ANT_B_CONNECTION				BIT(0)
19 
20 #define	BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_)	\
21 		(((_BT_INFO_EXT_&BIT(0))) ? true : false)
22 
23 #define	BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT		2
24 
25 #define  BT_8723B_1ANT_WIFI_NOISY_THRESH								50 /* 30   //max: 255								 */
26 
27 /* for Antenna detection */
28 #define	BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND						50
29 #define	BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION				70
30 #define	BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION			48
31 #define	BT_8723B_1ANT_ANTDET_PSDTHRES_1ANT							32
32 #define	BT_8723B_1ANT_ANTDET_RETRY_INTERVAL							10	/* retry timer if ant det is fail, unit: second */
33 #define	BT_8723B_1ANT_ANTDET_SWEEPPOINT_DELAY							40000
34 #define	BT_8723B_1ANT_ANTDET_ENABLE										1
35 #define	BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE				1
36 #define	BT_8723B_1ANT_ANTDET_BTTXTIME									100
37 #define	BT_8723B_1ANT_ANTDET_BTTXCHANNEL								39
38 
39 enum bt_info_src_8723b_1ant {
40 	BT_INFO_SRC_8723B_1ANT_WIFI_FW			= 0x0,
41 	BT_INFO_SRC_8723B_1ANT_BT_RSP				= 0x1,
42 	BT_INFO_SRC_8723B_1ANT_BT_ACTIVE_SEND		= 0x2,
43 	BT_INFO_SRC_8723B_1ANT_MAX
44 };
45 
46 enum bt_8723b_1ant_bt_status {
47 	BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE	= 0x0,
48 	BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE		= 0x1,
49 	BT_8723B_1ANT_BT_STATUS_INQ_PAGE				= 0x2,
50 	BT_8723B_1ANT_BT_STATUS_ACL_BUSY				= 0x3,
51 	BT_8723B_1ANT_BT_STATUS_SCO_BUSY				= 0x4,
52 	BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY			= 0x5,
53 	BT_8723B_1ANT_BT_STATUS_MAX
54 };
55 
56 enum bt_8723b_1ant_wifi_status {
57 	BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE				= 0x0,
58 	BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN		= 0x1,
59 	BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN					= 0x2,
60 	BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT				= 0x3,
61 	BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE					= 0x4,
62 	BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY					= 0x5,
63 	BT_8723B_1ANT_WIFI_STATUS_MAX
64 };
65 
66 enum bt_8723b_1ant_coex_algo {
67 	BT_8723B_1ANT_COEX_ALGO_UNDEFINED			= 0x0,
68 	BT_8723B_1ANT_COEX_ALGO_SCO				= 0x1,
69 	BT_8723B_1ANT_COEX_ALGO_HID				= 0x2,
70 	BT_8723B_1ANT_COEX_ALGO_A2DP				= 0x3,
71 	BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS		= 0x4,
72 	BT_8723B_1ANT_COEX_ALGO_PANEDR			= 0x5,
73 	BT_8723B_1ANT_COEX_ALGO_PANHS			= 0x6,
74 	BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP		= 0x7,
75 	BT_8723B_1ANT_COEX_ALGO_PANEDR_HID		= 0x8,
76 	BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR	= 0x9,
77 	BT_8723B_1ANT_COEX_ALGO_HID_A2DP			= 0xa,
78 	BT_8723B_1ANT_COEX_ALGO_MAX				= 0xb,
79 };
80 
81 struct coex_dm_8723b_1ant {
82 	/* hw setting */
83 	u8		pre_ant_pos_type;
84 	u8		cur_ant_pos_type;
85 	/* fw mechanism */
86 	boolean		cur_ignore_wlan_act;
87 	boolean		pre_ignore_wlan_act;
88 	u8		pre_ps_tdma;
89 	u8		cur_ps_tdma;
90 	u8		ps_tdma_para[5];
91 	u8		ps_tdma_du_adj_type;
92 	boolean		auto_tdma_adjust;
93 	boolean		pre_ps_tdma_on;
94 	boolean		cur_ps_tdma_on;
95 	boolean		pre_bt_auto_report;
96 	boolean		cur_bt_auto_report;
97 	u8		pre_lps;
98 	u8		cur_lps;
99 	u8		pre_rpwm;
100 	u8		cur_rpwm;
101 
102 	/* sw mechanism */
103 	boolean	pre_low_penalty_ra;
104 	boolean		cur_low_penalty_ra;
105 	u32		pre_val0x6c0;
106 	u32		cur_val0x6c0;
107 	u32		pre_val0x6c4;
108 	u32		cur_val0x6c4;
109 	u32		pre_val0x6c8;
110 	u32		cur_val0x6c8;
111 	u8		pre_val0x6cc;
112 	u8		cur_val0x6cc;
113 
114 	u32		backup_arfr_cnt1;	/* Auto Rate Fallback Retry cnt */
115 	u32		backup_arfr_cnt2;	/* Auto Rate Fallback Retry cnt */
116 	u16		backup_retry_limit;
117 	u8		backup_ampdu_max_time;
118 
119 	/* algorithm related */
120 	u8		bt_status;
121 	u8		wifi_chnl_info[3];
122 
123 	u32		pre_ra_mask;
124 	u32		cur_ra_mask;
125 	u8		pre_arfr_type;
126 	u8		cur_arfr_type;
127 	u8		pre_retry_limit_type;
128 	u8		cur_retry_limit_type;
129 	u8		pre_ampdu_time_type;
130 	u8		cur_ampdu_time_type;
131 	u32		arp_cnt;
132 
133 	u8		error_condition;
134 };
135 
136 struct coex_sta_8723b_1ant {
137 	boolean					bt_disabled;
138 	boolean					bt_enable_disable_change;
139 	boolean					bt_link_exist;
140 	boolean					sco_exist;
141 	boolean					a2dp_exist;
142 	boolean					hid_exist;
143 	boolean					pan_exist;
144 	boolean					bt_hi_pri_link_exist;
145 	u8					num_of_profile;
146 	boolean					bt_abnormal_scan;
147 
148 	boolean					under_lps;
149 	boolean					under_ips;
150 	u32					specific_pkt_period_cnt;
151 	u32					high_priority_tx;
152 	u32					high_priority_rx;
153 	u32					low_priority_tx;
154 	u32					low_priority_rx;
155 	s8					bt_rssi;
156 	boolean					bt_tx_rx_mask;
157 	boolean					c2h_bt_info_req_sent;
158 	u8					bt_info_c2h[BT_INFO_SRC_8723B_1ANT_MAX][10];
159 	u32					bt_info_c2h_cnt[BT_INFO_SRC_8723B_1ANT_MAX];
160 	boolean					bt_whck_test;
161 	boolean					c2h_bt_inquiry_page;
162 	boolean					c2h_bt_remote_name_req;
163 	boolean					wifi_is_high_pri_task;		/* Add for win8.1 page out issue */
164 	u8					bt_retry_cnt;
165 	u8					bt_info_ext;
166 	u32					pop_event_cnt;
167 	u8					scan_ap_num;
168 
169 	u32					crc_ok_cck;
170 	u32					crc_ok_11g;
171 	u32					crc_ok_11n;
172 	u32					crc_ok_11n_agg;
173 
174 	u32					crc_err_cck;
175 	u32					crc_err_11g;
176 	u32					crc_err_11n;
177 	u32					crc_err_11n_agg;
178 
179 	boolean					cck_lock;
180 	boolean					pre_ccklock;
181 	boolean					cck_ever_lock;
182 	u8					coex_table_type;
183 
184 	boolean					force_lps_on;
185 	u32					wrong_profile_notification;
186 
187 	u8					a2dp_bit_pool;
188 	u8					cut_version;
189 };
190 
191 #define BT_8723B_1ANT_ANTDET_PSD_POINTS			256	/* MAX:1024 */
192 #define BT_8723B_1ANT_ANTDET_PSD_AVGNUM		1	/* MAX:3 */
193 #define	BT_8723B_1ANT_ANTDET_BUF_LEN			16
194 
195 struct psdscan_sta_8723b_1ant {
196 
197 	u32			ant_det_bt_le_channel;  /* BT LE Channel ex:2412 */
198 	u32			ant_det_bt_tx_time;
199 	u32			ant_det_pre_psdscan_peak_val;
200 	boolean			ant_det_is_ant_det_available;
201 	u32			ant_det_psd_scan_peak_val;
202 	boolean			ant_det_is_btreply_available;
203 	u32			ant_det_psd_scan_peak_freq;
204 
205 	u8			ant_det_result;
206 	u8			ant_det_peak_val[BT_8723B_1ANT_ANTDET_BUF_LEN];
207 	u8			ant_det_peak_freq[BT_8723B_1ANT_ANTDET_BUF_LEN];
208 	u32			ant_det_try_count;
209 	u32			ant_det_fail_count;
210 	u32			ant_det_inteval_count;
211 	u32			ant_det_thres_offset;
212 
213 	u32			real_cent_freq;
214 	s32			real_offset;
215 	u32			real_span;
216 
217 	u32			psd_band_width;  /* unit: Hz */
218 	u32			psd_point;		/* 128/256/512/1024 */
219 	u32			psd_report[1024];  /* unit:dB (20logx), 0~255 */
220 	u32			psd_report_max_hold[1024];  /* unit:dB (20logx), 0~255 */
221 	u32			psd_start_point;
222 	u32			psd_stop_point;
223 	u32			psd_max_value_point;
224 	u32			psd_max_value;
225 	u32			psd_start_base;
226 	u32			psd_avg_num;	/* 1/8/16/32 */
227 	u32			psd_gen_count;
228 	boolean			is_psd_running;
229 	boolean			is_psd_show_max_only;
230 };
231 
232 /* *******************************************
233  * The following is interface which will notify coex module.
234  * ******************************************* */
235 void ex_halbtc8723b1ant_power_on_setting(IN struct btc_coexist *btcoexist);
236 void ex_halbtc8723b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist);
237 void ex_halbtc8723b1ant_init_hw_config(IN struct btc_coexist *btcoexist,
238 				       IN boolean wifi_only);
239 void ex_halbtc8723b1ant_init_coex_dm(IN struct btc_coexist *btcoexist);
240 void ex_halbtc8723b1ant_ips_notify(IN struct btc_coexist *btcoexist,
241 				   IN u8 type);
242 void ex_halbtc8723b1ant_lps_notify(IN struct btc_coexist *btcoexist,
243 				   IN u8 type);
244 void ex_halbtc8723b1ant_scan_notify(IN struct btc_coexist *btcoexist,
245 				    IN u8 type);
246 void ex_halbtc8723b1ant_connect_notify(IN struct btc_coexist *btcoexist,
247 				       IN u8 type);
248 void ex_halbtc8723b1ant_media_status_notify(IN struct btc_coexist *btcoexist,
249 		IN u8 type);
250 void ex_halbtc8723b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
251 		IN u8 type);
252 void ex_halbtc8723b1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
253 				       IN u8 *tmp_buf, IN u8 length);
254 void ex_halbtc8723b1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
255 		IN u8 type);
256 void ex_halbtc8723b1ant_halt_notify(IN struct btc_coexist *btcoexist);
257 void ex_halbtc8723b1ant_pnp_notify(IN struct btc_coexist *btcoexist,
258 				   IN u8 pnp_state);
259 void ex_halbtc8723b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist);
260 void ex_halbtc8723b1ant_periodical(IN struct btc_coexist *btcoexist);
261 void ex_halbtc8723b1ant_display_coex_info(IN struct btc_coexist *btcoexist);
262 void ex_halbtc8723b1ant_antenna_detection(IN struct btc_coexist *btcoexist,
263 		IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds);
264 
265 void ex_halbtc8723b1ant_display_ant_detection(IN struct btc_coexist *btcoexist);
266 
267 #else
268 #define	ex_halbtc8723b1ant_power_on_setting(btcoexist)
269 #define	ex_halbtc8723b1ant_pre_load_firmware(btcoexist)
270 #define	ex_halbtc8723b1ant_init_hw_config(btcoexist, wifi_only)
271 #define	ex_halbtc8723b1ant_init_coex_dm(btcoexist)
272 #define	ex_halbtc8723b1ant_ips_notify(btcoexist, type)
273 #define	ex_halbtc8723b1ant_lps_notify(btcoexist, type)
274 #define	ex_halbtc8723b1ant_scan_notify(btcoexist, type)
275 #define	ex_halbtc8723b1ant_connect_notify(btcoexist, type)
276 #define	ex_halbtc8723b1ant_media_status_notify(btcoexist, type)
277 #define	ex_halbtc8723b1ant_specific_packet_notify(btcoexist, type)
278 #define	ex_halbtc8723b1ant_bt_info_notify(btcoexist, tmp_buf, length)
279 #define	ex_halbtc8723b1ant_rf_status_notify(btcoexist, type)
280 #define	ex_halbtc8723b1ant_halt_notify(btcoexist)
281 #define	ex_halbtc8723b1ant_pnp_notify(btcoexist, pnp_state)
282 #define	ex_halbtc8723b1ant_coex_dm_reset(btcoexist)
283 #define	ex_halbtc8723b1ant_periodical(btcoexist)
284 #define	ex_halbtc8723b1ant_display_coex_info(btcoexist)
285 #define	ex_halbtc8723b1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds)
286 #define	ex_halbtc8723b1ant_display_ant_detection(btcoexist)
287 
288 #endif
289 
290 #endif
291