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