xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8822be/hal/rtl8822b/rtl8822b_mac.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2015 - 2016 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 #define _RTL8822B_MAC_C_
21 
22 #include <drv_types.h>		/* PADAPTER, basic_types.h and etc. */
23 #include <hal_data.h>		/* HAL_DATA_TYPE */
24 #include "../hal_halmac.h"	/* Register Definition and etc. */
25 
26 
rtl8822b_rcr_config(PADAPTER p,u32 rcr)27 inline u8 rtl8822b_rcr_config(PADAPTER p, u32 rcr)
28 {
29 	u32 v32;
30 	int err;
31 
32 
33 	v32 = GET_HAL_DATA(p)->ReceiveConfig;
34 	v32 ^= rcr;
35 	v32 &= BIT_APP_PHYSTS_8822B;
36 	if (v32) {
37 		v32 = rcr & BIT_APP_PHYSTS_8822B;
38 		RTW_INFO("%s: runtime %s rx phy status!\n",
39 			 __FUNCTION__, v32 ? "ENABLE" : "DISABLE");
40 		if (v32) {
41 			err = rtw_halmac_config_rx_info(adapter_to_dvobj(p), HALMAC_DRV_INFO_PHY_STATUS);
42 			if (err) {
43 				RTW_INFO("%s: Enable rx phy status FAIL!!", __FUNCTION__);
44 				rcr &= ~BIT_APP_PHYSTS_8822B;
45 			}
46 		} else {
47 			err = rtw_halmac_config_rx_info(adapter_to_dvobj(p), HALMAC_DRV_INFO_NONE);
48 			if (err) {
49 				RTW_INFO("%s: Disable rx phy status FAIL!!", __FUNCTION__);
50 				rcr |= BIT_APP_PHYSTS_8822B;
51 			}
52 		}
53 	}
54 
55 	err = rtw_write32(p, REG_RCR_8822B, rcr);
56 	if (_FAIL == err)
57 		return _FALSE;
58 
59 	GET_HAL_DATA(p)->ReceiveConfig = rcr;
60 	return _TRUE;
61 }
62 
rtl8822b_rcr_get(PADAPTER p,u32 * rcr)63 inline u8 rtl8822b_rcr_get(PADAPTER p, u32 *rcr)
64 {
65 	u32 v32;
66 
67 	v32 = rtw_read32(p, REG_RCR_8822B);
68 	if (rcr)
69 		*rcr = v32;
70 	GET_HAL_DATA(p)->ReceiveConfig = v32;
71 	return _TRUE;
72 }
73 
rtl8822b_rcr_check(PADAPTER p,u32 check_bit)74 inline u8 rtl8822b_rcr_check(PADAPTER p, u32 check_bit)
75 {
76 	PHAL_DATA_TYPE hal;
77 	u32 rcr;
78 
79 	hal = GET_HAL_DATA(p);
80 	rcr = hal->ReceiveConfig;
81 	if ((rcr & check_bit) == check_bit)
82 		return _TRUE;
83 
84 	return _FALSE;
85 }
86 
rtl8822b_rcr_add(PADAPTER p,u32 add)87 inline u8 rtl8822b_rcr_add(PADAPTER p, u32 add)
88 {
89 	PHAL_DATA_TYPE hal;
90 	u32 rcr;
91 	u8 ret = _TRUE;
92 
93 	hal = GET_HAL_DATA(p);
94 
95 	rcr = hal->ReceiveConfig;
96 	rcr |= add;
97 	if (rcr != hal->ReceiveConfig)
98 		ret = rtl8822b_rcr_config(p, rcr);
99 
100 	return ret;
101 }
102 
rtl8822b_rcr_clear(PADAPTER p,u32 clear)103 inline u8 rtl8822b_rcr_clear(PADAPTER p, u32 clear)
104 {
105 	PHAL_DATA_TYPE hal;
106 	u32 rcr;
107 	u8 ret = _TRUE;
108 
109 	hal = GET_HAL_DATA(p);
110 
111 	rcr = hal->ReceiveConfig;
112 	rcr &= ~clear;
113 	if (rcr != hal->ReceiveConfig)
114 		ret = rtl8822b_rcr_config(p, rcr);
115 
116 	return ret;
117 }
118 
rtl8822b_rx_ba_ssn_appended(PADAPTER p)119 inline u8 rtl8822b_rx_ba_ssn_appended(PADAPTER p)
120 {
121 	return rtl8822b_rcr_check(p, BIT_APP_BASSN_8822B);
122 }
123 
rtl8822b_rx_fcs_append_switch(PADAPTER p,u8 enable)124 inline u8 rtl8822b_rx_fcs_append_switch(PADAPTER p, u8 enable)
125 {
126 	u32 rcr_bit;
127 	u8 ret = _TRUE;
128 
129 	rcr_bit = BIT_APP_FCS_8822B;
130 	if (_TRUE == enable)
131 		ret = rtl8822b_rcr_add(p, rcr_bit);
132 	else
133 		ret = rtl8822b_rcr_clear(p, rcr_bit);
134 
135 	return ret;
136 }
137 
rtl8822b_rx_fcs_appended(PADAPTER p)138 inline u8 rtl8822b_rx_fcs_appended(PADAPTER p)
139 {
140 	return rtl8822b_rcr_check(p, BIT_APP_FCS_8822B);
141 }
142 
rtl8822b_rx_tsf_addr_filter_config(PADAPTER p,u8 config)143 inline u8 rtl8822b_rx_tsf_addr_filter_config(PADAPTER p, u8 config)
144 {
145 	u8 v8;
146 	int err;
147 
148 	v8 = GET_HAL_DATA(p)->rx_tsf_addr_filter_config;
149 
150 	if (v8 != config) {
151 
152 		err = rtw_write8(p, REG_NAN_RX_TSF_FILTER_8822B, config);
153 		if (_FAIL == err)
154 			return _FALSE;
155 	}
156 
157 	GET_HAL_DATA(p)->rx_tsf_addr_filter_config = config;
158 	return _TRUE;
159 }
160 
161 /*
162  * Return:
163  *	_SUCCESS	Download Firmware OK.
164  *	_FAIL		Download Firmware FAIL!
165  */
rtl8822b_fw_dl(PADAPTER adapter,u8 wowlan)166 s32 rtl8822b_fw_dl(PADAPTER adapter, u8 wowlan)
167 {
168 	struct dvobj_priv *d;
169 	int err;
170 
171 
172 	if (_TRUE == wowlan) {
173 		RTW_INFO("%s: NOT support WOWLan firmware yet!\n", __FUNCTION__);
174 		return _FAIL;
175 	}
176 
177 	d = adapter_to_dvobj(adapter);
178 
179 	err = rtw_halmac_dlfw_from_file(d, REALTEK_CONFIG_PATH "RTL8822Bfw_NIC.bin");
180 	if (err) {
181 		RTW_INFO("%s: Download Firmware fail\n", __FUNCTION__);
182 		return _FALSE;
183 	}
184 
185 	return _SUCCESS;
186 }
187