• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 #include <osdep_service.h>
8 #include <drv_types.h>
9 
10 #include <hal_intf.h>
11 #include <hal_com.h>
12 #include <rtl8188e_hal.h>
13 
14 #define _HAL_INIT_C_
15 
dump_chip_info(struct HAL_VERSION chip_vers)16 void dump_chip_info(struct HAL_VERSION	chip_vers)
17 {
18 	uint cnt = 0;
19 	char buf[128];
20 
21 	cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8188E_");
22 	cnt += sprintf((buf+cnt), "%s_", chip_vers.ChipType == NORMAL_CHIP ?
23 		       "Normal_Chip" : "Test_Chip");
24 	cnt += sprintf((buf+cnt), "%s_", chip_vers.VendorType == CHIP_VENDOR_TSMC ?
25 		       "TSMC" : "UMC");
26 	if (chip_vers.CUTVersion == A_CUT_VERSION)
27 		cnt += sprintf((buf+cnt), "A_CUT_");
28 	else if (chip_vers.CUTVersion == B_CUT_VERSION)
29 		cnt += sprintf((buf+cnt), "B_CUT_");
30 	else if (chip_vers.CUTVersion == C_CUT_VERSION)
31 		cnt += sprintf((buf+cnt), "C_CUT_");
32 	else if (chip_vers.CUTVersion == D_CUT_VERSION)
33 		cnt += sprintf((buf+cnt), "D_CUT_");
34 	else if (chip_vers.CUTVersion == E_CUT_VERSION)
35 		cnt += sprintf((buf+cnt), "E_CUT_");
36 	else
37 		cnt += sprintf((buf+cnt), "UNKNOWN_CUT(%d)_",
38 			       chip_vers.CUTVersion);
39 	cnt += sprintf((buf+cnt), "1T1R_");
40 	cnt += sprintf((buf+cnt), "RomVer(0)\n");
41 
42 	pr_info("%s", buf);
43 }
44 
45 #define	CHAN_PLAN_HW	0x80
46 
47 /* return the final channel plan decision */
hal_com_get_channel_plan(u8 hw_channel_plan,u8 sw_channel_plan,u8 def_channel_plan,bool load_fail)48 u8 hal_com_get_channel_plan(u8 hw_channel_plan, u8 sw_channel_plan,
49 			    u8 def_channel_plan, bool load_fail)
50 {
51 	u8 sw_cfg;
52 	u8 chnlplan;
53 
54 	sw_cfg = true;
55 	if (!load_fail) {
56 		if (!rtw_is_channel_plan_valid(sw_channel_plan))
57 			sw_cfg = false;
58 		if (hw_channel_plan & CHAN_PLAN_HW)
59 			sw_cfg = false;
60 	}
61 
62 	if (sw_cfg)
63 		chnlplan = sw_channel_plan;
64 	else
65 		chnlplan = hw_channel_plan & (~CHAN_PLAN_HW);
66 
67 	if (!rtw_is_channel_plan_valid(chnlplan))
68 		chnlplan = def_channel_plan;
69 
70 	return chnlplan;
71 }
72 
MRateToHwRate(u8 rate)73 u8 MRateToHwRate(u8 rate)
74 {
75 	u8 ret = DESC_RATE1M;
76 
77 	switch (rate) {
78 		/*  CCK and OFDM non-HT rates */
79 	case IEEE80211_CCK_RATE_1MB:
80 		ret = DESC_RATE1M;
81 		break;
82 	case IEEE80211_CCK_RATE_2MB:
83 		ret = DESC_RATE2M;
84 		break;
85 	case IEEE80211_CCK_RATE_5MB:
86 		ret = DESC_RATE5_5M;
87 		break;
88 	case IEEE80211_CCK_RATE_11MB:
89 		ret = DESC_RATE11M;
90 		break;
91 	case IEEE80211_OFDM_RATE_6MB:
92 		ret = DESC_RATE6M;
93 		break;
94 	case IEEE80211_OFDM_RATE_9MB:
95 		ret = DESC_RATE9M;
96 		break;
97 	case IEEE80211_OFDM_RATE_12MB:
98 		ret = DESC_RATE12M;
99 		break;
100 	case IEEE80211_OFDM_RATE_18MB:
101 		ret = DESC_RATE18M;
102 		break;
103 	case IEEE80211_OFDM_RATE_24MB:
104 		ret = DESC_RATE24M;
105 		break;
106 	case IEEE80211_OFDM_RATE_36MB:
107 		ret = DESC_RATE36M;
108 		break;
109 	case IEEE80211_OFDM_RATE_48MB:
110 		ret = DESC_RATE48M;
111 		break;
112 	case IEEE80211_OFDM_RATE_54MB:
113 		ret = DESC_RATE54M;
114 		break;
115 	default:
116 		break;
117 	}
118 	return ret;
119 }
120 
hal_set_brate_cfg(u8 * brates,u16 * rate_cfg)121 void hal_set_brate_cfg(u8 *brates, u16 *rate_cfg)
122 {
123 	u8 i, is_brate, brate;
124 
125 	for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
126 		is_brate = brates[i] & IEEE80211_BASIC_RATE_MASK;
127 		brate = brates[i] & 0x7f;
128 
129 		if (is_brate) {
130 			switch (brate) {
131 			case IEEE80211_CCK_RATE_1MB:
132 				*rate_cfg |= RATE_1M;
133 				break;
134 			case IEEE80211_CCK_RATE_2MB:
135 				*rate_cfg |= RATE_2M;
136 				break;
137 			case IEEE80211_CCK_RATE_5MB:
138 				*rate_cfg |= RATE_5_5M;
139 				break;
140 			case IEEE80211_CCK_RATE_11MB:
141 				*rate_cfg |= RATE_11M;
142 				break;
143 			case IEEE80211_OFDM_RATE_6MB:
144 				*rate_cfg |= RATE_6M;
145 				break;
146 			case IEEE80211_OFDM_RATE_9MB:
147 				*rate_cfg |= RATE_9M;
148 				break;
149 			case IEEE80211_OFDM_RATE_12MB:
150 				*rate_cfg |= RATE_12M;
151 				break;
152 			case IEEE80211_OFDM_RATE_18MB:
153 				*rate_cfg |= RATE_18M;
154 				break;
155 			case IEEE80211_OFDM_RATE_24MB:
156 				*rate_cfg |= RATE_24M;
157 				break;
158 			case IEEE80211_OFDM_RATE_36MB:
159 				*rate_cfg |= RATE_36M;
160 				break;
161 			case IEEE80211_OFDM_RATE_48MB:
162 				*rate_cfg |= RATE_48M;
163 				break;
164 			case IEEE80211_OFDM_RATE_54MB:
165 				*rate_cfg |= RATE_54M;
166 				break;
167 			}
168 		}
169 	}
170 }
171 
one_out_pipe(struct adapter * adapter)172 static void one_out_pipe(struct adapter *adapter)
173 {
174 	struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
175 
176 	pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */
177 	pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */
178 	pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[0];/* BE */
179 	pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[0];/* BK */
180 
181 	pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
182 	pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
183 	pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
184 	pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
185 }
186 
two_out_pipe(struct adapter * adapter,bool wifi_cfg)187 static void two_out_pipe(struct adapter *adapter, bool wifi_cfg)
188 {
189 	struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
190 
191 	if (wifi_cfg) {
192 		/*
193 		 * WMM
194 		 * BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA
195 		 *  0,  1,  0,  1,   0,   0,   0,    0,    0
196 		 * 0:H, 1:L
197 		 */
198 		pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[1];/* VO */
199 		pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */
200 		pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[1];/* BE */
201 		pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[0];/* BK */
202 
203 		pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
204 		pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
205 		pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
206 		pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
207 	} else {
208 		/*
209 		 * typical setting
210 		 * BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA
211 		 *  1,  1,  0,  0,   0,   0,   0,    0,    0
212 		 * 0:H, 1:L
213 		 */
214 		pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */
215 		pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */
216 		pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[1];/* BE */
217 		pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[1];/* BK */
218 
219 		pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
220 		pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
221 		pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
222 		pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
223 	}
224 }
225 
three_out_pipe(struct adapter * adapter,bool wifi_cfg)226 static void three_out_pipe(struct adapter *adapter, bool wifi_cfg)
227 {
228 	struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapter);
229 
230 	if (wifi_cfg) {
231 		/*
232 		 * for WMM
233 		 * BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA
234 		 *  1,  2,  1,  0,   0,   0,   0,    0,    0
235 		 * 0:H, 1:N, 2:L
236 		 */
237 		pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */
238 		pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[1];/* VI */
239 		pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[2];/* BE */
240 		pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[1];/* BK */
241 
242 		pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
243 		pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
244 		pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
245 		pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
246 	} else {
247 		/*
248 		 * typical setting
249 		 * BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA
250 		 *  2,  2,  1,  0,   0,   0,   0,    0,    0
251 		 * 0:H, 1:N, 2:L
252 		 */
253 		pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */
254 		pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[1];/* VI */
255 		pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[2];/* BE */
256 		pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[2];/* BK */
257 
258 		pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */
259 		pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */
260 		pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */
261 		pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */
262 	}
263 }
264 
hal_mapping_out_pipe(struct adapter * adapter,u8 numoutpipe)265 bool hal_mapping_out_pipe(struct adapter *adapter, u8 numoutpipe)
266 {
267 	struct registry_priv *pregistrypriv = &adapter->registrypriv;
268 	bool wifi_cfg = (pregistrypriv->wifi_spec) ? true : false;
269 	bool result = true;
270 
271 	switch (numoutpipe) {
272 	case 1:
273 		one_out_pipe(adapter);
274 		break;
275 	case 2:
276 		two_out_pipe(adapter, wifi_cfg);
277 		break;
278 	case 3:
279 		three_out_pipe(adapter, wifi_cfg);
280 		break;
281 	default:
282 		result = false;
283 	}
284 	return result;
285 }
286