GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / net / wireless / realtek / rtlwifi / btcoexist / rtl_btc.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2013  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 #include "../wifi.h"
26 #include <linux/vmalloc.h>
27 #include <linux/module.h>
28
29 #include "rtl_btc.h"
30 #include "halbt_precomp.h"
31
32 static struct rtl_btc_ops rtl_btc_operation = {
33         .btc_init_variables = rtl_btc_init_variables,
34         .btc_init_hal_vars = rtl_btc_init_hal_vars,
35         .btc_power_on_setting = rtl_btc_power_on_setting,
36         .btc_init_hw_config = rtl_btc_init_hw_config,
37         .btc_ips_notify = rtl_btc_ips_notify,
38         .btc_lps_notify = rtl_btc_lps_notify,
39         .btc_scan_notify = rtl_btc_scan_notify,
40         .btc_connect_notify = rtl_btc_connect_notify,
41         .btc_mediastatus_notify = rtl_btc_mediastatus_notify,
42         .btc_periodical = rtl_btc_periodical,
43         .btc_halt_notify = rtl_btc_halt_notify,
44         .btc_btinfo_notify = rtl_btc_btinfo_notify,
45         .btc_btmpinfo_notify = rtl_btc_btmpinfo_notify,
46         .btc_is_limited_dig = rtl_btc_is_limited_dig,
47         .btc_is_disable_edca_turbo = rtl_btc_is_disable_edca_turbo,
48         .btc_is_bt_disabled = rtl_btc_is_bt_disabled,
49         .btc_special_packet_notify = rtl_btc_special_packet_notify,
50         .btc_record_pwr_mode = rtl_btc_record_pwr_mode,
51         .btc_get_lps_val = rtl_btc_get_lps_val,
52         .btc_get_rpwm_val = rtl_btc_get_rpwm_val,
53         .btc_is_bt_ctrl_lps = rtl_btc_is_bt_ctrl_lps,
54         .btc_is_bt_lps_on = rtl_btc_is_bt_lps_on,
55         .btc_get_ampdu_cfg = rtl_btc_get_ampdu_cfg,
56 };
57
58 void rtl_btc_record_pwr_mode(struct rtl_priv *rtlpriv, u8 *buf, u8 len)
59 {
60         u8 safe_len;
61
62         safe_len = sizeof(gl_bt_coexist.pwr_mode_val);
63
64         if (safe_len > len)
65                 safe_len = len;
66
67         memcpy(gl_bt_coexist.pwr_mode_val, buf, safe_len);
68 }
69
70 u8 rtl_btc_get_lps_val(struct rtl_priv *rtlpriv)
71 {
72         return gl_bt_coexist.bt_info.lps_val;
73 }
74
75 u8 rtl_btc_get_rpwm_val(struct rtl_priv *rtlpriv)
76 {
77         return gl_bt_coexist.bt_info.rpwm_val;
78 }
79
80 bool rtl_btc_is_bt_ctrl_lps(struct rtl_priv *rtlpriv)
81 {
82         return gl_bt_coexist.bt_info.bt_ctrl_lps;
83 }
84
85 bool rtl_btc_is_bt_lps_on(struct rtl_priv *rtlpriv)
86 {
87         return gl_bt_coexist.bt_info.bt_lps_on;
88 }
89
90 void rtl_btc_get_ampdu_cfg(struct rtl_priv *rtlpriv, u8 *reject_agg,
91                            u8 *ctrl_agg_size, u8 *agg_size)
92 {
93         if (reject_agg)
94                 *reject_agg = gl_bt_coexist.bt_info.reject_agg_pkt;
95         if (ctrl_agg_size)
96                 *ctrl_agg_size = gl_bt_coexist.bt_info.bt_ctrl_agg_buf_size;
97         if (agg_size)
98                 *agg_size = gl_bt_coexist.bt_info.agg_buf_size;
99 }
100
101 void rtl_btc_init_variables(struct rtl_priv *rtlpriv)
102 {
103         exhalbtc_initlize_variables();
104         exhalbtc_bind_bt_coex_withadapter(rtlpriv);
105 }
106
107 void rtl_btc_init_hal_vars(struct rtl_priv *rtlpriv)
108 {
109         /* move ant_num, bt_type and single_ant_path to
110          * exhalbtc_bind_bt_coex_withadapter()
111          */
112 }
113
114 void rtl_btc_power_on_setting(struct rtl_priv *rtlpriv)
115 {
116         exhalbtc_power_on_setting(&gl_bt_coexist);
117 }
118
119 void rtl_btc_init_hw_config(struct rtl_priv *rtlpriv)
120 {
121         u8 bt_exist;
122
123         bt_exist = rtl_get_hwpg_bt_exist(rtlpriv);
124         RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
125                 "%s, bt_exist is %d\n", __func__, bt_exist);
126
127         exhalbtc_init_hw_config(&gl_bt_coexist, !bt_exist);
128         exhalbtc_init_coex_dm(&gl_bt_coexist);
129 }
130
131 void rtl_btc_ips_notify(struct rtl_priv *rtlpriv, u8 type)
132 {
133         exhalbtc_ips_notify(&gl_bt_coexist, type);
134 }
135
136 void rtl_btc_lps_notify(struct rtl_priv *rtlpriv, u8 type)
137 {
138         exhalbtc_lps_notify(&gl_bt_coexist, type);
139 }
140
141 void rtl_btc_scan_notify(struct rtl_priv *rtlpriv, u8 scantype)
142 {
143         exhalbtc_scan_notify(&gl_bt_coexist, scantype);
144 }
145
146 void rtl_btc_connect_notify(struct rtl_priv *rtlpriv, u8 action)
147 {
148         exhalbtc_connect_notify(&gl_bt_coexist, action);
149 }
150
151 void rtl_btc_mediastatus_notify(struct rtl_priv *rtlpriv,
152                                 enum rt_media_status mstatus)
153 {
154         exhalbtc_mediastatus_notify(&gl_bt_coexist, mstatus);
155 }
156
157 void rtl_btc_periodical(struct rtl_priv *rtlpriv)
158 {
159         /*rtl_bt_dm_monitor();*/
160         exhalbtc_periodical(&gl_bt_coexist);
161 }
162
163 void rtl_btc_halt_notify(void)
164 {
165         struct btc_coexist *btcoexist = &gl_bt_coexist;
166
167         exhalbtc_halt_notify(btcoexist);
168 }
169
170 void rtl_btc_btinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
171 {
172         exhalbtc_bt_info_notify(&gl_bt_coexist, tmp_buf, length);
173 }
174
175 void rtl_btc_btmpinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
176 {
177         u8 extid, seq, len;
178         u16 bt_real_fw_ver;
179         u8 bt_fw_ver;
180
181         if ((length < 4) || (!tmp_buf))
182                 return;
183
184         extid = tmp_buf[0];
185         /* not response from BT FW then exit*/
186         if (extid != 1) /* C2H_TRIG_BY_BT_FW = 1 */
187                 return;
188
189         len = tmp_buf[1] >> 4;
190         seq = tmp_buf[2] >> 4;
191
192         /* BT Firmware version response */
193         if (seq == 0x0E) {
194                 bt_real_fw_ver = tmp_buf[3] | (tmp_buf[4] << 8);
195                 bt_fw_ver = tmp_buf[5];
196
197                 gl_bt_coexist.bt_info.bt_real_fw_ver = bt_real_fw_ver;
198                 gl_bt_coexist.bt_info.bt_fw_ver = bt_fw_ver;
199         }
200 }
201
202 bool rtl_btc_is_limited_dig(struct rtl_priv *rtlpriv)
203 {
204         return gl_bt_coexist.bt_info.limited_dig;
205 }
206
207 bool rtl_btc_is_disable_edca_turbo(struct rtl_priv *rtlpriv)
208 {
209         bool bt_change_edca = false;
210         u32 cur_edca_val;
211         u32 edca_bt_hs_uplink = 0x5ea42b, edca_bt_hs_downlink = 0x5ea42b;
212         u32 edca_hs;
213         u32 edca_addr = 0x504;
214
215         cur_edca_val = rtl_read_dword(rtlpriv, edca_addr);
216         if (halbtc_is_wifi_uplink(rtlpriv)) {
217                 if (cur_edca_val != edca_bt_hs_uplink) {
218                         edca_hs = edca_bt_hs_uplink;
219                         bt_change_edca = true;
220                 }
221         } else {
222                 if (cur_edca_val != edca_bt_hs_downlink) {
223                         edca_hs = edca_bt_hs_downlink;
224                         bt_change_edca = true;
225                 }
226         }
227
228         if (bt_change_edca)
229                 rtl_write_dword(rtlpriv, edca_addr, edca_hs);
230
231         return true;
232 }
233
234 bool rtl_btc_is_bt_disabled(struct rtl_priv *rtlpriv)
235 {
236         /* It seems 'bt_disabled' is never be initialized or set. */
237         if (gl_bt_coexist.bt_info.bt_disabled)
238                 return true;
239         else
240                 return false;
241 }
242
243 void rtl_btc_special_packet_notify(struct rtl_priv *rtlpriv, u8 pkt_type)
244 {
245         return exhalbtc_special_packet_notify(&gl_bt_coexist, pkt_type);
246 }
247
248 struct rtl_btc_ops *rtl_btc_get_ops_pointer(void)
249 {
250         return &rtl_btc_operation;
251 }
252 EXPORT_SYMBOL(rtl_btc_get_ops_pointer);
253
254
255 enum rt_media_status mgnt_link_status_query(struct ieee80211_hw *hw)
256 {
257         struct rtl_priv *rtlpriv = rtl_priv(hw);
258         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
259         enum rt_media_status    m_status = RT_MEDIA_DISCONNECT;
260
261         u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
262
263         if (bibss || rtlpriv->mac80211.link_state >= MAC80211_LINKED)
264                 m_status = RT_MEDIA_CONNECT;
265
266         return m_status;
267 }
268
269 u8 rtl_get_hwpg_bt_exist(struct rtl_priv *rtlpriv)
270 {
271         return rtlpriv->btcoexist.btc_info.btcoexist;
272 }
273
274 MODULE_AUTHOR("Page He  <page_he@realsil.com.cn>");
275 MODULE_AUTHOR("Realtek WlanFAE  <wlanfae@realtek.com>");
276 MODULE_AUTHOR("Larry Finger     <Larry.FInger@lwfinger.net>");
277 MODULE_LICENSE("GPL");
278 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
279
280 static int __init rtl_btcoexist_module_init(void)
281 {
282         return 0;
283 }
284
285 static void __exit rtl_btcoexist_module_exit(void)
286 {
287         return;
288 }
289
290 module_init(rtl_btcoexist_module_init);
291 module_exit(rtl_btcoexist_module_exit);