GNU Linux-libre 4.14.257-gnu1
[releases.git] / drivers / staging / rtlwifi / btcoexist / halbtc8822b1ant.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2016  Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25
26 /* *******************************************
27  * The following is for 8822B 1ANT BT Co-exist definition
28  * ********************************************/
29 #define BT_INFO_8822B_1ANT_B_FTP        BIT(7)
30 #define BT_INFO_8822B_1ANT_B_A2DP       BIT(6)
31 #define BT_INFO_8822B_1ANT_B_HID        BIT(5)
32 #define BT_INFO_8822B_1ANT_B_SCO_BUSY   BIT(4)
33 #define BT_INFO_8822B_1ANT_B_ACL_BUSY   BIT(3)
34 #define BT_INFO_8822B_1ANT_B_INQ_PAGE   BIT(2)
35 #define BT_INFO_8822B_1ANT_B_SCO_ESCO   BIT(1)
36 #define BT_INFO_8822B_1ANT_B_CONNECTION BIT(0)
37
38 #define BT_INFO_8822B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_)                      \
39         (((_BT_INFO_EXT_ & BIT(0))) ? true : false)
40
41 #define BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT     2
42
43 #define BT_8822B_1ANT_WIFI_NOISY_THRESH 150 /* max: 255 */
44 #define BT_8822B_1ANT_DEFAULT_ISOLATION 15 /*  unit: dB */
45
46 /* for Antenna detection */
47 #define BT_8822B_1ANT_ANTDET_PSDTHRES_BACKGROUND        50
48 #define BT_8822B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70
49 #define BT_8822B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION        55
50 #define BT_8822B_1ANT_ANTDET_PSDTHRES_1ANT      35
51 #define BT_8822B_1ANT_ANTDET_RETRY_INTERVAL                                    \
52         10 /* retry timer if ant det is fail, unit: second */
53 #define BT_8822B_1ANT_ANTDET_ENABLE     0
54 #define BT_8822B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE 0
55
56 #define BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT        30000
57
58 enum bt_8822b_1ant_signal_state {
59         BT_8822B_1ANT_SIG_STA_SET_TO_LOW        = 0x0,
60         BT_8822B_1ANT_SIG_STA_SET_BY_HW = 0x0,
61         BT_8822B_1ANT_SIG_STA_SET_TO_HIGH       = 0x1,
62         BT_8822B_1ANT_SIG_STA_MAX
63 };
64
65 enum bt_8822b_1ant_path_ctrl_owner {
66         BT_8822B_1ANT_PCO_BTSIDE        = 0x0,
67         BT_8822B_1ANT_PCO_WLSIDE        = 0x1,
68         BT_8822B_1ANT_PCO_MAX
69 };
70
71 enum bt_8822b_1ant_gnt_ctrl_type {
72         BT_8822B_1ANT_GNT_CTRL_BY_PTA   = 0x0,
73         BT_8822B_1ANT_GNT_CTRL_BY_SW    = 0x1,
74         BT_8822B_1ANT_GNT_CTRL_MAX
75 };
76
77 enum bt_8822b_1ant_gnt_ctrl_block {
78         BT_8822B_1ANT_GNT_BLOCK_RFC_BB  = 0x0,
79         BT_8822B_1ANT_GNT_BLOCK_RFC     = 0x1,
80         BT_8822B_1ANT_GNT_BLOCK_BB      = 0x2,
81         BT_8822B_1ANT_GNT_BLOCK_MAX
82 };
83
84 enum bt_8822b_1ant_lte_coex_table_type {
85         BT_8822B_1ANT_CTT_WL_VS_LTE     = 0x0,
86         BT_8822B_1ANT_CTT_BT_VS_LTE     = 0x1,
87         BT_8822B_1ANT_CTT_MAX
88 };
89
90 enum bt_8822b_1ant_lte_break_table_type {
91         BT_8822B_1ANT_LBTT_WL_BREAK_LTE = 0x0,
92         BT_8822B_1ANT_LBTT_BT_BREAK_LTE = 0x1,
93         BT_8822B_1ANT_LBTT_LTE_BREAK_WL = 0x2,
94         BT_8822B_1ANT_LBTT_LTE_BREAK_BT = 0x3,
95         BT_8822B_1ANT_LBTT_MAX
96 };
97
98 enum bt_info_src_8822b_1ant {
99         BT_INFO_SRC_8822B_1ANT_WIFI_FW  = 0x0,
100         BT_INFO_SRC_8822B_1ANT_BT_RSP   = 0x1,
101         BT_INFO_SRC_8822B_1ANT_BT_ACTIVE_SEND   = 0x2,
102         BT_INFO_SRC_8822B_1ANT_MAX
103 };
104
105 enum bt_8822b_1ant_bt_status {
106         BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE      = 0x0,
107         BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE  = 0x1,
108         BT_8822B_1ANT_BT_STATUS_INQ_PAGE        = 0x2,
109         BT_8822B_1ANT_BT_STATUS_ACL_BUSY        = 0x3,
110         BT_8822B_1ANT_BT_STATUS_SCO_BUSY        = 0x4,
111         BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY    = 0x5,
112         BT_8822B_1ANT_BT_STATUS_MAX
113 };
114
115 enum bt_8822b_1ant_wifi_status {
116         BT_8822B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE    = 0x0,
117         BT_8822B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN  = 0x1,
118         BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN        = 0x2,
119         BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT        = 0x3,
120         BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE        = 0x4,
121         BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY        = 0x5,
122         BT_8822B_1ANT_WIFI_STATUS_MAX
123 };
124
125 enum bt_8822b_1ant_coex_algo {
126         BT_8822B_1ANT_COEX_ALGO_UNDEFINED       = 0x0,
127         BT_8822B_1ANT_COEX_ALGO_SCO     = 0x1,
128         BT_8822B_1ANT_COEX_ALGO_HID     = 0x2,
129         BT_8822B_1ANT_COEX_ALGO_A2DP    = 0x3,
130         BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS      = 0x4,
131         BT_8822B_1ANT_COEX_ALGO_PANEDR  = 0x5,
132         BT_8822B_1ANT_COEX_ALGO_PANHS   = 0x6,
133         BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP     = 0x7,
134         BT_8822B_1ANT_COEX_ALGO_PANEDR_HID      = 0x8,
135         BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9,
136         BT_8822B_1ANT_COEX_ALGO_HID_A2DP        = 0xa,
137         BT_8822B_1ANT_COEX_ALGO_MAX     = 0xb,
138 };
139
140 enum bt_8822b_1ant_ext_ant_switch_type {
141         BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT   = 0x0,
142         BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SP3T   = 0x1,
143         BT_8822B_1ANT_EXT_ANT_SWITCH_MAX
144 };
145
146 enum bt_8822b_1ant_ext_ant_switch_ctrl_type {
147         BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW       = 0x0,
148         BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA        = 0x1,
149         BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV     = 0x2,
150         BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC        = 0x3,
151         BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT = 0x4,
152         BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_MAX
153 };
154
155 enum bt_8822b_1ant_ext_ant_switch_pos_type {
156         BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT      = 0x0,
157         BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG     = 0x1,
158         BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA     = 0x2,
159         BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE  = 0x3,
160         BT_8822B_1ANT_EXT_ANT_SWITCH_TO_MAX
161 };
162
163 enum bt_8822b_1ant_phase {
164         BT_8822B_1ANT_PHASE_COEX_INIT   = 0x0,
165         BT_8822B_1ANT_PHASE_WLANONLY_INIT       = 0x1,
166         BT_8822B_1ANT_PHASE_WLAN_OFF    = 0x2,
167         BT_8822B_1ANT_PHASE_2G_RUNTIME  = 0x3,
168         BT_8822B_1ANT_PHASE_5G_RUNTIME  = 0x4,
169         BT_8822B_1ANT_PHASE_BTMPMODE    = 0x5,
170         BT_8822B_1ANT_PHASE_MAX
171 };
172
173 /*ADD SCOREBOARD TO FIX BT LPS 32K ISSUE WHILE WL BUSY*/
174 enum bt_8822b_1ant_scoreboard {
175         BT_8822B_1ANT_SCOREBOARD_ACTIVE = BIT(0),
176         BT_8822B_1ANT_SCOREBOARD_ONOFF  = BIT(1),
177         BT_8822B_1ANT_SCOREBOARD_SCAN   = BIT(2),
178         BT_8822B_1ANT_SCOREBOARD_UNDERTEST      = BIT(3),
179         BT_8822B_1ANT_SCOREBOARD_WLBUSY = BIT(6)
180 };
181
182 struct coex_dm_8822b_1ant {
183         /* hw setting */
184         u32     pre_ant_pos_type;
185         u32     cur_ant_pos_type;
186         /* fw mechanism */
187         bool    cur_ignore_wlan_act;
188         bool    pre_ignore_wlan_act;
189         u8      pre_ps_tdma;
190         u8      cur_ps_tdma;
191         u8      ps_tdma_para[5];
192         u8      ps_tdma_du_adj_type;
193         bool    auto_tdma_adjust;
194         bool    pre_ps_tdma_on;
195         bool    cur_ps_tdma_on;
196         bool    pre_bt_auto_report;
197         bool    cur_bt_auto_report;
198         u8      pre_lps;
199         u8      cur_lps;
200         u8      pre_rpwm;
201         u8      cur_rpwm;
202
203         /* sw mechanism */
204         bool    pre_low_penalty_ra;
205         bool    cur_low_penalty_ra;
206         u32     pre_val0x6c0;
207         u32     cur_val0x6c0;
208         u32     pre_val0x6c4;
209         u32     cur_val0x6c4;
210         u32     pre_val0x6c8;
211         u32     cur_val0x6c8;
212         u8      pre_val0x6cc;
213         u8      cur_val0x6cc;
214         bool    limited_dig;
215
216         u32     backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */
217         u32     backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */
218         u16     backup_retry_limit;
219         u8      backup_ampdu_max_time;
220
221         /* algorithm related */
222         u8      pre_algorithm;
223         u8      cur_algorithm;
224         u8      bt_status;
225         u8      wifi_chnl_info[3];
226
227         u32     pre_ra_mask;
228         u32     cur_ra_mask;
229         u8      pre_arfr_type;
230         u8      cur_arfr_type;
231         u8      pre_retry_limit_type;
232         u8      cur_retry_limit_type;
233         u8      pre_ampdu_time_type;
234         u8      cur_ampdu_time_type;
235         u32     arp_cnt;
236
237         u32     pre_ext_ant_switch_status;
238         u32     cur_ext_ant_switch_status;
239
240         u8      error_condition;
241 };
242
243 struct coex_sta_8822b_1ant {
244         bool    bt_disabled;
245         bool    bt_link_exist;
246         bool    sco_exist;
247         bool    a2dp_exist;
248         bool    hid_exist;
249         bool    pan_exist;
250         u8      num_of_profile;
251
252         bool    under_lps;
253         bool    under_ips;
254         u32     specific_pkt_period_cnt;
255         u32     high_priority_tx;
256         u32     high_priority_rx;
257         u32     low_priority_tx;
258         u32     low_priority_rx;
259         bool    is_hi_pri_rx_overhead;
260         s8      bt_rssi;
261         u8      pre_bt_rssi_state;
262         u8      pre_wifi_rssi_state[4];
263         u8      bt_info_c2h[BT_INFO_SRC_8822B_1ANT_MAX][10];
264         u32     bt_info_c2h_cnt[BT_INFO_SRC_8822B_1ANT_MAX];
265         bool    bt_whck_test;
266         bool    c2h_bt_inquiry_page;
267         bool    c2h_bt_remote_name_req;
268         bool    c2h_bt_page; /* Add for win8.1 page out issue */
269         bool    wifi_is_high_pri_task; /* Add for win8.1 page out issue */
270
271         u8      bt_info_ext;
272         u8      bt_info_ext2;
273         u32     pop_event_cnt;
274         u8      scan_ap_num;
275         u8      bt_retry_cnt;
276
277         u32     crc_ok_cck;
278         u32     crc_ok_11g;
279         u32     crc_ok_11n;
280         u32     crc_ok_11n_vht;
281
282         u32     crc_err_cck;
283         u32     crc_err_11g;
284         u32     crc_err_11n;
285         u32     crc_err_11n_vht;
286
287         bool    cck_lock;
288         bool    pre_ccklock;
289         bool    cck_ever_lock;
290         u8      coex_table_type;
291
292         bool    force_lps_ctrl;
293
294         bool    concurrent_rx_mode_on;
295
296         u16     score_board;
297         u8      isolation_btween_wb; /* 0~ 50 */
298
299         u8      a2dp_bit_pool;
300         u8      cut_version;
301         bool    acl_busy;
302         bool    bt_create_connection;
303
304         u32     bt_coex_supported_feature;
305         u32     bt_coex_supported_version;
306
307         u8      bt_ble_scan_type;
308         u32     bt_ble_scan_para[3];
309
310         bool    run_time_state;
311         bool    freeze_coexrun_by_btinfo;
312
313         bool    is_A2DP_3M;
314         bool    voice_over_HOGP;
315         u8      bt_info;
316         bool    is_autoslot;
317         u8      forbidden_slot;
318         u8      hid_busy_num;
319         u8      hid_pair_cnt;
320
321         u32     cnt_remote_name_req;
322         u32     cnt_setup_link;
323         u32     cnt_reinit;
324         u32     cnt_ign_wlan_act;
325         u32     cnt_page;
326         u32     cnt_role_switch;
327
328         u16     bt_reg_vendor_ac;
329         u16     bt_reg_vendor_ae;
330
331         bool    is_setup_link;
332         u8      wl_noisy_level;
333         u32     gnt_error_cnt;
334         u8      bt_afh_map[10];
335         u8      bt_relink_downcount;
336         bool    is_tdma_btautoslot;
337         bool    is_tdma_btautoslot_hang;
338
339         u8      switch_band_notify_to;
340         bool    is_rf_state_off;
341
342         bool    is_hid_low_pri_tx_overhead;
343         bool    is_bt_multi_link;
344         bool    is_bt_a2dp_sink;
345         bool    rf4ce_enabled;
346
347         bool    is_set_ps_state_fail;
348         u8      cnt_set_ps_state_fail;
349 };
350
351 struct rfe_type_8822b_1ant {
352         u8      rfe_module_type;
353         bool    ext_ant_switch_exist;
354         u8      ext_ant_switch_type;
355         /*  iF 0: ANTSW(rfe_sel9)=0, ANTSWB(rfe_sel8)=1 =>  Ant to BT/5G */
356         u8      ext_ant_switch_ctrl_polarity;
357 };
358
359 #define BT_8822B_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */
360 #define BT_8822B_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */
361 #define BT_8822B_1ANT_ANTDET_BUF_LEN    16
362
363 struct psdscan_sta_8822b_1ant {
364         u32     ant_det_bt_le_channel; /* BT LE Channel ex:2412 */
365         u32     ant_det_bt_tx_time;
366         u32     ant_det_pre_psdscan_peak_val;
367         bool    ant_det_is_ant_det_available;
368         u32     ant_det_psd_scan_peak_val;
369         bool    ant_det_is_btreply_available;
370         u32     ant_det_psd_scan_peak_freq;
371
372         u8      ant_det_result;
373         u8      ant_det_peak_val[BT_8822B_1ANT_ANTDET_BUF_LEN];
374         u8      ant_det_peak_freq[BT_8822B_1ANT_ANTDET_BUF_LEN];
375         u32     ant_det_try_count;
376         u32     ant_det_fail_count;
377         u32     ant_det_inteval_count;
378         u32     ant_det_thres_offset;
379
380         u32     real_cent_freq;
381         s32     real_offset;
382         u32     real_span;
383
384         u32     psd_band_width; /* unit: Hz */
385         u32     psd_point; /* 128/256/512/1024 */
386         u32     psd_report[1024]; /* unit:dB (20logx), 0~255 */
387         u32     psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */
388         u32     psd_start_point;
389         u32     psd_stop_point;
390         u32     psd_max_value_point;
391         u32     psd_max_value;
392         u32     psd_start_base;
393         u32     psd_avg_num; /* 1/8/16/32 */
394         u32     psd_gen_count;
395         bool    is_psd_running;
396         bool    is_psd_show_max_only;
397         bool    is_ant_det_running;
398 };
399
400 /* *******************************************
401  * The following is interface which will notify coex module.
402  * ********************************************/
403 void ex_btc8822b1ant_power_on_setting(struct btc_coexist *btcoexist);
404 void ex_btc8822b1ant_pre_load_firmware(struct btc_coexist *btcoexist);
405 void ex_btc8822b1ant_init_hw_config(struct btc_coexist *btcoexist,
406                                     bool wifi_only);
407 void ex_btc8822b1ant_init_coex_dm(struct btc_coexist *btcoexist);
408 void ex_btc8822b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type);
409 void ex_btc8822b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type);
410 void ex_btc8822b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type);
411 void ex_btc8822b1ant_scan_notify_without_bt(struct btc_coexist *btcoexist,
412                                             u8 type);
413 void ex_btc8822b1ant_switchband_notify(struct btc_coexist *btcoexist, u8 type);
414 void ex_btc8822b1ant_switchband_notify_without_bt(struct btc_coexist *btcoexist,
415                                                   u8 type);
416 void ex_btc8822b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type);
417 void ex_btc8822b1ant_media_status_notify(struct btc_coexist *btcoexist,
418                                          u8 type);
419 void ex_btc8822b1ant_specific_packet_notify(struct btc_coexist *btcoexist,
420                                             u8 type);
421 void ex_btc8822b1ant_bt_info_notify(struct btc_coexist *btcoexist, u8 *tmp_buf,
422                                     u8 length);
423 void ex_btc8822b1ant_rf_status_notify(struct btc_coexist *btcoexist, u8 type);
424 void ex_btc8822b1ant_halt_notify(struct btc_coexist *btcoexist);
425 void ex_btc8822b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state);
426 void ex_halbtc8822b1ant_score_board_status_notify(struct btc_coexist *btcoexist,
427                                                   u8 *tmp_buf, u8 length);
428 void ex_btc8822b1ant_coex_dm_reset(struct btc_coexist *btcoexist);
429 void ex_btc8822b1ant_periodical(struct btc_coexist *btcoexist);
430 void ex_btc8822b1ant_display_coex_info(struct btc_coexist *btcoexist,
431                                        struct seq_file *m);
432 void ex_btc8822b1ant_antenna_detection(struct btc_coexist *btcoexist,
433                                        u32 cent_freq, u32 offset, u32 span,
434                                        u32 seconds);
435 void ex_btc8822b1ant_antenna_isolation(struct btc_coexist *btcoexist,
436                                        u32 cent_freq, u32 offset, u32 span,
437                                        u32 seconds);
438
439 void ex_btc8822b1ant_psd_scan(struct btc_coexist *btcoexist, u32 cent_freq,
440                               u32 offset, u32 span, u32 seconds);
441 void ex_btc8822b1ant_display_ant_detection(struct btc_coexist *btcoexist);
442
443 void ex_btc8822b1ant_dbg_control(struct btc_coexist *btcoexist, u8 op_code,
444                                  u8 op_len, u8 *pdata);