Linux-libre 3.16.85-gnu
[librecmc/linux-libre.git] / drivers / staging / rtl8188eu / core / rtw_sreset.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20
21 #include <rtw_sreset.h>
22
23 void sreset_init_value(struct adapter *padapter)
24 {
25         struct hal_data_8188e   *pHalData = GET_HAL_DATA(padapter);
26         struct sreset_priv *psrtpriv = &pHalData->srestpriv;
27
28         mutex_init(&psrtpriv->silentreset_mutex);
29         psrtpriv->silent_reset_inprogress = false;
30         psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
31         psrtpriv->last_tx_time = 0;
32         psrtpriv->last_tx_complete_time = 0;
33 }
34 void sreset_reset_value(struct adapter *padapter)
35 {
36         struct hal_data_8188e   *pHalData = GET_HAL_DATA(padapter);
37         struct sreset_priv *psrtpriv = &pHalData->srestpriv;
38
39         psrtpriv->silent_reset_inprogress = false;
40         psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
41         psrtpriv->last_tx_time = 0;
42         psrtpriv->last_tx_complete_time = 0;
43 }
44
45 u8 sreset_get_wifi_status(struct adapter *padapter)
46 {
47         struct hal_data_8188e   *pHalData = GET_HAL_DATA(padapter);
48         struct sreset_priv *psrtpriv = &pHalData->srestpriv;
49
50         u8 status = WIFI_STATUS_SUCCESS;
51         u32 val32 = 0;
52
53         if (psrtpriv->silent_reset_inprogress)
54                 return status;
55         val32 = rtw_read32(padapter, REG_TXDMA_STATUS);
56         if (val32 == 0xeaeaeaea) {
57                 psrtpriv->Wifi_Error_Status = WIFI_IF_NOT_EXIST;
58         } else if (val32 != 0) {
59                 DBG_88E("txdmastatu(%x)\n", val32);
60                 psrtpriv->Wifi_Error_Status = WIFI_MAC_TXDMA_ERROR;
61         }
62
63         if (WIFI_STATUS_SUCCESS != psrtpriv->Wifi_Error_Status) {
64                 DBG_88E("==>%s error_status(0x%x)\n", __func__, psrtpriv->Wifi_Error_Status);
65                 status = (psrtpriv->Wifi_Error_Status & (~(USB_READ_PORT_FAIL|USB_WRITE_PORT_FAIL)));
66         }
67         DBG_88E("==> %s wifi_status(0x%x)\n", __func__, status);
68
69         /* status restore */
70         psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
71
72         return status;
73 }
74
75 void sreset_set_wifi_error_status(struct adapter *padapter, u32 status)
76 {
77         struct hal_data_8188e   *pHalData = GET_HAL_DATA(padapter);
78         pHalData->srestpriv.Wifi_Error_Status = status;
79 }