GNU Linux-libre 4.14.262-gnu1
[releases.git] / drivers / staging / rtl8723bs / core / rtw_btcoex.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2013 Realtek Corporation. All rights reserved.
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  ******************************************************************************/
15 #include <drv_types.h>
16 #include <rtw_debug.h>
17 #include <rtw_btcoex.h>
18 #include <hal_btcoex.h>
19
20
21 void rtw_btcoex_Initialize(struct adapter *padapter)
22 {
23         hal_btcoex_Initialize(padapter);
24 }
25
26 void rtw_btcoex_PowerOnSetting(struct adapter *padapter)
27 {
28         hal_btcoex_PowerOnSetting(padapter);
29 }
30
31 void rtw_btcoex_HAL_Initialize(struct adapter *padapter, u8 bWifiOnly)
32 {
33         hal_btcoex_InitHwConfig(padapter, bWifiOnly);
34 }
35
36 void rtw_btcoex_IpsNotify(struct adapter *padapter, u8 type)
37 {
38         hal_btcoex_IpsNotify(padapter, type);
39 }
40
41 void rtw_btcoex_LpsNotify(struct adapter *padapter, u8 type)
42 {
43         hal_btcoex_LpsNotify(padapter, type);
44 }
45
46 void rtw_btcoex_ScanNotify(struct adapter *padapter, u8 type)
47 {
48         hal_btcoex_ScanNotify(padapter, type);
49 }
50
51 void rtw_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
52 {
53         hal_btcoex_ConnectNotify(padapter, action);
54 }
55
56 void rtw_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
57 {
58         if ((mediaStatus == RT_MEDIA_CONNECT)
59                 && (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == true)) {
60                 rtw_hal_set_hwreg(padapter, HW_VAR_DL_RSVD_PAGE, NULL);
61         }
62
63         hal_btcoex_MediaStatusNotify(padapter, mediaStatus);
64 }
65
66 void rtw_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
67 {
68         hal_btcoex_SpecialPacketNotify(padapter, pktType);
69 }
70
71 void rtw_btcoex_IQKNotify(struct adapter *padapter, u8 state)
72 {
73         hal_btcoex_IQKNotify(padapter, state);
74 }
75
76 void rtw_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
77 {
78         hal_btcoex_BtInfoNotify(padapter, length, tmpBuf);
79 }
80
81 void rtw_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
82 {
83         hal_btcoex_SuspendNotify(padapter, state);
84 }
85
86 void rtw_btcoex_HaltNotify(struct adapter *padapter)
87 {
88         if (false == padapter->bup) {
89                 DBG_871X(FUNC_ADPT_FMT ": bup =%d Skip!\n",
90                         FUNC_ADPT_ARG(padapter), padapter->bup);
91
92                 return;
93         }
94
95         if (true == padapter->bSurpriseRemoved) {
96                 DBG_871X(FUNC_ADPT_FMT ": bSurpriseRemoved =%d Skip!\n",
97                         FUNC_ADPT_ARG(padapter), padapter->bSurpriseRemoved);
98
99                 return;
100         }
101
102         hal_btcoex_HaltNotify(padapter);
103 }
104
105 u8 rtw_btcoex_IsBtDisabled(struct adapter *padapter)
106 {
107         return hal_btcoex_IsBtDisabled(padapter);
108 }
109
110 void rtw_btcoex_Handler(struct adapter *padapter)
111 {
112         hal_btcoex_Hanlder(padapter);
113 }
114
115 s32 rtw_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
116 {
117         s32 coexctrl;
118
119         coexctrl = hal_btcoex_IsBTCoexCtrlAMPDUSize(padapter);
120
121         return coexctrl;
122 }
123
124 void rtw_btcoex_SetManualControl(struct adapter *padapter, u8 manual)
125 {
126         if (true == manual) {
127                 hal_btcoex_SetManualControl(padapter, true);
128         } else{
129                 hal_btcoex_SetManualControl(padapter, false);
130         }
131 }
132
133 u8 rtw_btcoex_IsBtControlLps(struct adapter *padapter)
134 {
135         return hal_btcoex_IsBtControlLps(padapter);
136 }
137
138 u8 rtw_btcoex_IsLpsOn(struct adapter *padapter)
139 {
140         return hal_btcoex_IsLpsOn(padapter);
141 }
142
143 u8 rtw_btcoex_RpwmVal(struct adapter *padapter)
144 {
145         return hal_btcoex_RpwmVal(padapter);
146 }
147
148 u8 rtw_btcoex_LpsVal(struct adapter *padapter)
149 {
150         return hal_btcoex_LpsVal(padapter);
151 }
152
153 void rtw_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
154 {
155         hal_btcoex_SetBTCoexist(padapter, bBtExist);
156 }
157
158 void rtw_btcoex_SetChipType(struct adapter *padapter, u8 chipType)
159 {
160         hal_btcoex_SetChipType(padapter, chipType);
161 }
162
163 void rtw_btcoex_SetPGAntNum(struct adapter *padapter, u8 antNum)
164 {
165         hal_btcoex_SetPgAntNum(padapter, antNum);
166 }
167
168 void rtw_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
169 {
170         hal_btcoex_SetSingleAntPath(padapter, singleAntPath);
171 }
172
173 u32 rtw_btcoex_GetRaMask(struct adapter *padapter)
174 {
175         return hal_btcoex_GetRaMask(padapter);
176 }
177
178 void rtw_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
179 {
180         hal_btcoex_RecordPwrMode(padapter, pCmdBuf, cmdLen);
181 }
182
183 void rtw_btcoex_DisplayBtCoexInfo(struct adapter *padapter, u8 *pbuf, u32 bufsize)
184 {
185         hal_btcoex_DisplayBtCoexInfo(padapter, pbuf, bufsize);
186 }
187
188 void rtw_btcoex_SetDBG(struct adapter *padapter, u32 *pDbgModule)
189 {
190         hal_btcoex_SetDBG(padapter, pDbgModule);
191 }
192
193 u32 rtw_btcoex_GetDBG(struct adapter *padapter, u8 *pStrBuf, u32 bufSize)
194 {
195         return hal_btcoex_GetDBG(padapter, pStrBuf, bufSize);
196 }
197
198 /*  ================================================== */
199 /*  Below Functions are called by BT-Coex */
200 /*  ================================================== */
201 void rtw_btcoex_RejectApAggregatedPacket(struct adapter *padapter, u8 enable)
202 {
203         struct mlme_ext_info *pmlmeinfo;
204         struct sta_info *psta;
205
206         pmlmeinfo = &padapter->mlmeextpriv.mlmext_info;
207         psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
208
209         if (true == enable) {
210                 pmlmeinfo->bAcceptAddbaReq = false;
211                 if (psta)
212                         send_delba(padapter, 0, psta->hwaddr);
213         } else{
214                 pmlmeinfo->bAcceptAddbaReq = true;
215         }
216 }
217
218 void rtw_btcoex_LPS_Enter(struct adapter *padapter)
219 {
220         struct pwrctrl_priv *pwrpriv;
221         u8 lpsVal;
222
223
224         pwrpriv = adapter_to_pwrctl(padapter);
225
226         pwrpriv->bpower_saving = true;
227         lpsVal = rtw_btcoex_LpsVal(padapter);
228         rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, lpsVal, "BTCOEX");
229 }
230
231 void rtw_btcoex_LPS_Leave(struct adapter *padapter)
232 {
233         struct pwrctrl_priv *pwrpriv;
234
235
236         pwrpriv = adapter_to_pwrctl(padapter);
237
238         if (pwrpriv->pwr_mode != PS_MODE_ACTIVE) {
239                 rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, "BTCOEX");
240                 LPS_RF_ON_check(padapter, 100);
241                 pwrpriv->bpower_saving = false;
242         }
243 }