1 /******************************************************************************
2  *
3  * Copyright(c) 2012  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  * The following is for 8723B 1ANT BT Co-exist definition
27  **********************************************************************/
28 #define	BT_INFO_8723B_1ANT_B_FTP			BIT7
29 #define	BT_INFO_8723B_1ANT_B_A2DP			BIT6
30 #define	BT_INFO_8723B_1ANT_B_HID			BIT5
31 #define	BT_INFO_8723B_1ANT_B_SCO_BUSY			BIT4
32 #define	BT_INFO_8723B_1ANT_B_ACL_BUSY			BIT3
33 #define	BT_INFO_8723B_1ANT_B_INQ_PAGE			BIT2
34 #define	BT_INFO_8723B_1ANT_B_SCO_ESCO			BIT1
35 #define	BT_INFO_8723B_1ANT_B_CONNECTION			BIT0
36 
37 #define	BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_)	\
38 		(((_BT_INFO_EXT_&BIT0)) ? true : false)
39 
40 #define	BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT		2
41 
42 #define BT_8723B_1ANT_WIFI_NOISY_THRESH			50
43 
44 enum _BT_INFO_SRC_8723B_1ANT {
45 	BT_INFO_SRC_8723B_1ANT_WIFI_FW			= 0x0,
46 	BT_INFO_SRC_8723B_1ANT_BT_RSP			= 0x1,
47 	BT_INFO_SRC_8723B_1ANT_BT_ACTIVE_SEND		= 0x2,
48 	BT_INFO_SRC_8723B_1ANT_MAX
49 };
50 
51 enum _BT_8723B_1ANT_BT_STATUS {
52 	BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE	= 0x0,
53 	BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE		= 0x1,
54 	BT_8723B_1ANT_BT_STATUS_INQ_PAGE		= 0x2,
55 	BT_8723B_1ANT_BT_STATUS_ACL_BUSY		= 0x3,
56 	BT_8723B_1ANT_BT_STATUS_SCO_BUSY		= 0x4,
57 	BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY		= 0x5,
58 	BT_8723B_1ANT_BT_STATUS_MAX
59 };
60 
61 enum _BT_8723B_1ANT_WIFI_STATUS {
62 	BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE			= 0x0,
63 	BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN		= 0x1,
64 	BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN			= 0x2,
65 	BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT			= 0x3,
66 	BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE			= 0x4,
67 	BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY			= 0x5,
68 	BT_8723B_1ANT_WIFI_STATUS_MAX
69 };
70 
71 enum _BT_8723B_1ANT_COEX_ALGO {
72 	BT_8723B_1ANT_COEX_ALGO_UNDEFINED		= 0x0,
73 	BT_8723B_1ANT_COEX_ALGO_SCO			= 0x1,
74 	BT_8723B_1ANT_COEX_ALGO_HID			= 0x2,
75 	BT_8723B_1ANT_COEX_ALGO_A2DP			= 0x3,
76 	BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS		= 0x4,
77 	BT_8723B_1ANT_COEX_ALGO_PANEDR			= 0x5,
78 	BT_8723B_1ANT_COEX_ALGO_PANHS			= 0x6,
79 	BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP		= 0x7,
80 	BT_8723B_1ANT_COEX_ALGO_PANEDR_HID		= 0x8,
81 	BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR		= 0x9,
82 	BT_8723B_1ANT_COEX_ALGO_HID_A2DP		= 0xa,
83 	BT_8723B_1ANT_COEX_ALGO_MAX			= 0xb,
84 };
85 
86 struct coex_dm_8723b_1ant {
87 	/* hw setting */
88 	u8 pre_ant_pos_type;
89 	u8 cur_ant_pos_type;
90 	/* fw mechanism */
91 	bool cur_ignore_wlan_act;
92 	bool pre_ignore_wlan_act;
93 	u8 pre_ps_tdma;
94 	u8 cur_ps_tdma;
95 	u8 ps_tdma_para[5];
96 	u8 ps_tdma_du_adj_type;
97 	bool auto_tdma_adjust;
98 	bool pre_ps_tdma_on;
99 	bool cur_ps_tdma_on;
100 	bool pre_bt_auto_report;
101 	bool cur_bt_auto_report;
102 	u8 pre_lps;
103 	u8 cur_lps;
104 	u8 pre_rpwm;
105 	u8 cur_rpwm;
106 
107 	/* sw mechanism */
108 	bool pre_low_penalty_ra;
109 	bool cur_low_penalty_ra;
110 	u32 pre_val0x6c0;
111 	u32 cur_val0x6c0;
112 	u32 pre_val0x6c4;
113 	u32 cur_val0x6c4;
114 	u32 pre_val0x6c8;
115 	u32 cur_val0x6c8;
116 	u8 pre_val0x6cc;
117 	u8 cur_val0x6cc;
118 	bool limited_dig;
119 
120 	u32 backup_arfr_cnt1;	/* Auto Rate Fallback Retry cnt */
121 	u32 backup_arfr_cnt2;	/* Auto Rate Fallback Retry cnt */
122 	u16 backup_retry_limit;
123 	u8 backup_ampdu_max_time;
124 
125 	/* algorithm related */
126 	u8 pre_algorithm;
127 	u8 cur_algorithm;
128 	u8 bt_status;
129 	u8 wifi_chnl_info[3];
130 
131 	u32 prera_mask;
132 	u32 curra_mask;
133 	u8 pre_arfr_type;
134 	u8 cur_arfr_type;
135 	u8 pre_retry_limit_type;
136 	u8 cur_retry_limit_type;
137 	u8 pre_ampdu_time_type;
138 	u8 cur_ampdu_time_type;
139 	u32	arp_cnt;
140 
141 	u8 error_condition;
142 };
143 
144 struct coex_sta_8723b_1ant {
145 	bool bt_disabled;
146 	bool bt_link_exist;
147 	bool sco_exist;
148 	bool a2dp_exist;
149 	bool hid_exist;
150 	bool pan_exist;
151 	bool bt_hi_pri_link_exist;
152 	u8 num_of_profile;
153 	bool bt_abnormal_scan;
154 
155 	bool under_lps;
156 	bool under_ips;
157 	u32 special_pkt_period_cnt;
158 	u32 high_priority_tx;
159 	u32 high_priority_rx;
160 	u32 low_priority_tx;
161 	u32 low_priority_rx;
162 	u8 bt_rssi;
163 	u8 pre_bt_rssi_state;
164 	u8 pre_wifi_rssi_state[4];
165 	bool bt_tx_rx_mask;
166 	bool c2h_bt_info_req_sent;
167 	u8 bt_info_c2h[BT_INFO_SRC_8723B_1ANT_MAX][10];
168 	u32 bt_info_c2h_cnt[BT_INFO_SRC_8723B_1ANT_MAX];
169 	bool bt_whck_test;
170 	bool c2h_bt_inquiry_page;
171 	bool c2h_bt_remote_name_req;
172 	bool wifi_is_high_pri_task;
173 	u8 bt_retry_cnt;
174 	u8 bt_info_ext;
175 	u8 scan_ap_num;
176 	bool cck_ever_lock;
177 	u8 coex_table_type;
178 	bool force_lps_on;
179 	u32 pop_event_cnt;
180 
181 	u32 crc_ok_cck;
182 	u32 crc_ok_11g;
183 	u32 crc_ok_11n;
184 	u32 crc_ok_11n_agg;
185 
186 	u32 crc_err_cck;
187 	u32 crc_err_11g;
188 	u32 crc_err_11n;
189 	u32 crc_err_11n_agg;
190 
191 	bool cck_lock;
192 	bool pre_ccklock;
193 
194 	u32 wrong_profile_notification;
195 
196 	u8 a2dp_bit_pool;
197 	u8 cut_version;
198 };
199 
200 /*************************************************************************
201  * The following is interface which will notify coex module.
202  *************************************************************************/
203 void ex_btc8723b1ant_power_on_setting(struct btc_coexist *btcoexist);
204 void ex_btc8723b1ant_init_hwconfig(struct btc_coexist *btcoexist,
205 				   bool wifi_only);
206 void ex_btc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist);
207 void ex_btc8723b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type);
208 void ex_btc8723b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type);
209 void ex_btc8723b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type);
210 void ex_btc8723b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type);
211 void ex_btc8723b1ant_media_status_notify(struct btc_coexist *btcoexist,
212 					 u8 type);
213 void ex_btc8723b1ant_special_packet_notify(struct btc_coexist *btcoexist,
214 					   u8 type);
215 void ex_btc8723b1ant_bt_info_notify(struct btc_coexist *btcoexist,
216 				    u8 *tmpbuf, u8 length);
217 void ex_btc8723b1ant_rf_status_notify(struct btc_coexist *btcoexist,
218 				      u8 type);
219 void ex_btc8723b1ant_halt_notify(struct btc_coexist *btcoexist);
220 void ex_btc8723b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnpstate);
221 void ex_btc8723b1ant_coex_dm_reset(struct btc_coexist *btcoexist);
222 void ex_btc8723b1ant_periodical(struct btc_coexist *btcoexist);
223 void ex_btc8723b1ant_display_coex_info(struct btc_coexist *btcoexist,
224 				       struct seq_file *m);
225 void ex_btc8723b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state);
226