Commit | Line | Data |
---|---|---|
dad0d04f FF |
1 | /** |
2 | * Copyright (c) 2014 Redpine Signals Inc. | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include <linux/etherdevice.h> | |
18 | #include "rsi_mgmt.h" | |
19 | #include "rsi_common.h" | |
20 | ||
21 | static struct bootup_params boot_params_20 = { | |
22 | .magic_number = cpu_to_le16(0x5aa5), | |
23 | .crystal_good_time = 0x0, | |
24 | .valid = cpu_to_le32(VALID_20), | |
25 | .reserved_for_valids = 0x0, | |
26 | .bootup_mode_info = 0x0, | |
27 | .digital_loop_back_params = 0x0, | |
28 | .rtls_timestamp_en = 0x0, | |
29 | .host_spi_intr_cfg = 0x0, | |
30 | .device_clk_info = {{ | |
31 | .pll_config_g = { | |
32 | .tapll_info_g = { | |
33 | .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)| | |
34 | (TA_PLL_M_VAL_20)), | |
35 | .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20), | |
36 | }, | |
37 | .pll960_info_g = { | |
38 | .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)| | |
39 | (PLL960_N_VAL_20)), | |
40 | .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20), | |
41 | .pll_reg_3 = 0x0, | |
42 | }, | |
43 | .afepll_info_g = { | |
44 | .pll_reg = cpu_to_le16(0x9f0), | |
45 | } | |
46 | }, | |
47 | .switch_clk_g = { | |
48 | .switch_clk_info = cpu_to_le16(BIT(3)), | |
49 | .bbp_lmac_clk_reg_val = cpu_to_le16(0x121), | |
50 | .umac_clock_reg_config = 0x0, | |
51 | .qspi_uart_clock_reg_config = 0x0 | |
52 | } | |
53 | }, | |
54 | { | |
55 | .pll_config_g = { | |
56 | .tapll_info_g = { | |
57 | .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)| | |
58 | (TA_PLL_M_VAL_20)), | |
59 | .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20), | |
60 | }, | |
61 | .pll960_info_g = { | |
62 | .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)| | |
63 | (PLL960_N_VAL_20)), | |
64 | .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20), | |
65 | .pll_reg_3 = 0x0, | |
66 | }, | |
67 | .afepll_info_g = { | |
68 | .pll_reg = cpu_to_le16(0x9f0), | |
69 | } | |
70 | }, | |
71 | .switch_clk_g = { | |
72 | .switch_clk_info = 0x0, | |
73 | .bbp_lmac_clk_reg_val = 0x0, | |
74 | .umac_clock_reg_config = 0x0, | |
75 | .qspi_uart_clock_reg_config = 0x0 | |
76 | } | |
77 | }, | |
78 | { | |
79 | .pll_config_g = { | |
80 | .tapll_info_g = { | |
81 | .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)| | |
82 | (TA_PLL_M_VAL_20)), | |
83 | .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20), | |
84 | }, | |
85 | .pll960_info_g = { | |
86 | .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)| | |
87 | (PLL960_N_VAL_20)), | |
88 | .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20), | |
89 | .pll_reg_3 = 0x0, | |
90 | }, | |
91 | .afepll_info_g = { | |
92 | .pll_reg = cpu_to_le16(0x9f0), | |
93 | } | |
94 | }, | |
95 | .switch_clk_g = { | |
96 | .switch_clk_info = 0x0, | |
97 | .bbp_lmac_clk_reg_val = 0x0, | |
98 | .umac_clock_reg_config = 0x0, | |
99 | .qspi_uart_clock_reg_config = 0x0 | |
100 | } | |
101 | } }, | |
102 | .buckboost_wakeup_cnt = 0x0, | |
103 | .pmu_wakeup_wait = 0x0, | |
104 | .shutdown_wait_time = 0x0, | |
105 | .pmu_slp_clkout_sel = 0x0, | |
106 | .wdt_prog_value = 0x0, | |
107 | .wdt_soc_rst_delay = 0x0, | |
108 | .dcdc_operation_mode = 0x0, | |
109 | .soc_reset_wait_cnt = 0x0 | |
110 | }; | |
111 | ||
112 | static struct bootup_params boot_params_40 = { | |
113 | .magic_number = cpu_to_le16(0x5aa5), | |
114 | .crystal_good_time = 0x0, | |
115 | .valid = cpu_to_le32(VALID_40), | |
116 | .reserved_for_valids = 0x0, | |
117 | .bootup_mode_info = 0x0, | |
118 | .digital_loop_back_params = 0x0, | |
119 | .rtls_timestamp_en = 0x0, | |
120 | .host_spi_intr_cfg = 0x0, | |
121 | .device_clk_info = {{ | |
122 | .pll_config_g = { | |
123 | .tapll_info_g = { | |
124 | .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)| | |
125 | (TA_PLL_M_VAL_40)), | |
126 | .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40), | |
127 | }, | |
128 | .pll960_info_g = { | |
129 | .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)| | |
130 | (PLL960_N_VAL_40)), | |
131 | .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40), | |
132 | .pll_reg_3 = 0x0, | |
133 | }, | |
134 | .afepll_info_g = { | |
135 | .pll_reg = cpu_to_le16(0x9f0), | |
136 | } | |
137 | }, | |
138 | .switch_clk_g = { | |
139 | .switch_clk_info = cpu_to_le16(0x09), | |
140 | .bbp_lmac_clk_reg_val = cpu_to_le16(0x1121), | |
141 | .umac_clock_reg_config = cpu_to_le16(0x48), | |
142 | .qspi_uart_clock_reg_config = 0x0 | |
143 | } | |
144 | }, | |
145 | { | |
146 | .pll_config_g = { | |
147 | .tapll_info_g = { | |
148 | .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)| | |
149 | (TA_PLL_M_VAL_40)), | |
150 | .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40), | |
151 | }, | |
152 | .pll960_info_g = { | |
153 | .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)| | |
154 | (PLL960_N_VAL_40)), | |
155 | .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40), | |
156 | .pll_reg_3 = 0x0, | |
157 | }, | |
158 | .afepll_info_g = { | |
159 | .pll_reg = cpu_to_le16(0x9f0), | |
160 | } | |
161 | }, | |
162 | .switch_clk_g = { | |
163 | .switch_clk_info = 0x0, | |
164 | .bbp_lmac_clk_reg_val = 0x0, | |
165 | .umac_clock_reg_config = 0x0, | |
166 | .qspi_uart_clock_reg_config = 0x0 | |
167 | } | |
168 | }, | |
169 | { | |
170 | .pll_config_g = { | |
171 | .tapll_info_g = { | |
172 | .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)| | |
173 | (TA_PLL_M_VAL_40)), | |
174 | .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40), | |
175 | }, | |
176 | .pll960_info_g = { | |
177 | .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)| | |
178 | (PLL960_N_VAL_40)), | |
179 | .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40), | |
180 | .pll_reg_3 = 0x0, | |
181 | }, | |
182 | .afepll_info_g = { | |
183 | .pll_reg = cpu_to_le16(0x9f0), | |
184 | } | |
185 | }, | |
186 | .switch_clk_g = { | |
187 | .switch_clk_info = 0x0, | |
188 | .bbp_lmac_clk_reg_val = 0x0, | |
189 | .umac_clock_reg_config = 0x0, | |
190 | .qspi_uart_clock_reg_config = 0x0 | |
191 | } | |
192 | } }, | |
193 | .buckboost_wakeup_cnt = 0x0, | |
194 | .pmu_wakeup_wait = 0x0, | |
195 | .shutdown_wait_time = 0x0, | |
196 | .pmu_slp_clkout_sel = 0x0, | |
197 | .wdt_prog_value = 0x0, | |
198 | .wdt_soc_rst_delay = 0x0, | |
199 | .dcdc_operation_mode = 0x0, | |
200 | .soc_reset_wait_cnt = 0x0 | |
201 | }; | |
202 | ||
203 | static u16 mcs[] = {13, 26, 39, 52, 78, 104, 117, 130}; | |
204 | ||
205 | /** | |
206 | * rsi_set_default_parameters() - This function sets default parameters. | |
207 | * @common: Pointer to the driver private structure. | |
208 | * | |
209 | * Return: none | |
210 | */ | |
211 | static void rsi_set_default_parameters(struct rsi_common *common) | |
212 | { | |
213 | common->band = IEEE80211_BAND_2GHZ; | |
214 | common->channel_width = BW_20MHZ; | |
215 | common->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
216 | common->channel = 1; | |
217 | common->min_rate = 0xffff; | |
218 | common->fsm_state = FSM_CARD_NOT_READY; | |
219 | common->iface_down = true; | |
f870a340 | 220 | common->endpoint = EP_2GHZ_20MHZ; |
dad0d04f FF |
221 | } |
222 | ||
223 | /** | |
224 | * rsi_set_contention_vals() - This function sets the contention values for the | |
225 | * backoff procedure. | |
226 | * @common: Pointer to the driver private structure. | |
227 | * | |
228 | * Return: None. | |
229 | */ | |
230 | static void rsi_set_contention_vals(struct rsi_common *common) | |
231 | { | |
232 | u8 ii = 0; | |
233 | ||
234 | for (; ii < NUM_EDCA_QUEUES; ii++) { | |
235 | common->tx_qinfo[ii].wme_params = | |
236 | (((common->edca_params[ii].cw_min / 2) + | |
237 | (common->edca_params[ii].aifs)) * | |
238 | WMM_SHORT_SLOT_TIME + SIFS_DURATION); | |
239 | common->tx_qinfo[ii].weight = common->tx_qinfo[ii].wme_params; | |
240 | common->tx_qinfo[ii].pkt_contended = 0; | |
241 | } | |
242 | } | |
243 | ||
244 | /** | |
245 | * rsi_send_internal_mgmt_frame() - This function sends management frames to | |
246 | * firmware.Also schedules packet to queue | |
247 | * for transmission. | |
248 | * @common: Pointer to the driver private structure. | |
249 | * @skb: Pointer to the socket buffer structure. | |
250 | * | |
251 | * Return: 0 on success, -1 on failure. | |
252 | */ | |
253 | static int rsi_send_internal_mgmt_frame(struct rsi_common *common, | |
254 | struct sk_buff *skb) | |
255 | { | |
256 | struct skb_info *tx_params; | |
257 | ||
258 | if (skb == NULL) { | |
259 | rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__); | |
260 | return -ENOMEM; | |
261 | } | |
262 | tx_params = (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data; | |
263 | tx_params->flags |= INTERNAL_MGMT_PKT; | |
264 | skb_queue_tail(&common->tx_queue[MGMT_SOFT_Q], skb); | |
265 | rsi_set_event(&common->tx_thread.event); | |
266 | return 0; | |
267 | } | |
268 | ||
269 | /** | |
270 | * rsi_load_radio_caps() - This function is used to send radio capabilities | |
271 | * values to firmware. | |
272 | * @common: Pointer to the driver private structure. | |
273 | * | |
274 | * Return: 0 on success, corresponding negative error code on failure. | |
275 | */ | |
276 | static int rsi_load_radio_caps(struct rsi_common *common) | |
277 | { | |
278 | struct rsi_radio_caps *radio_caps; | |
279 | struct rsi_hw *adapter = common->priv; | |
280 | struct ieee80211_hw *hw = adapter->hw; | |
281 | u16 inx = 0; | |
282 | u8 ii; | |
283 | u8 radio_id = 0; | |
284 | u16 gc[20] = {0xf0, 0xf0, 0xf0, 0xf0, | |
285 | 0xf0, 0xf0, 0xf0, 0xf0, | |
286 | 0xf0, 0xf0, 0xf0, 0xf0, | |
287 | 0xf0, 0xf0, 0xf0, 0xf0, | |
288 | 0xf0, 0xf0, 0xf0, 0xf0}; | |
289 | struct ieee80211_conf *conf = &hw->conf; | |
290 | struct sk_buff *skb; | |
291 | ||
292 | rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__); | |
293 | ||
294 | skb = dev_alloc_skb(sizeof(struct rsi_radio_caps)); | |
295 | ||
296 | if (!skb) { | |
297 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
298 | __func__); | |
299 | return -ENOMEM; | |
300 | } | |
301 | ||
302 | memset(skb->data, 0, sizeof(struct rsi_radio_caps)); | |
303 | radio_caps = (struct rsi_radio_caps *)skb->data; | |
304 | ||
305 | radio_caps->desc_word[1] = cpu_to_le16(RADIO_CAPABILITIES); | |
306 | radio_caps->desc_word[4] = cpu_to_le16(RSI_RF_TYPE << 8); | |
307 | ||
308 | if (common->channel_width == BW_40MHZ) { | |
309 | radio_caps->desc_word[7] |= cpu_to_le16(RSI_LMAC_CLOCK_80MHZ); | |
310 | radio_caps->desc_word[7] |= cpu_to_le16(RSI_ENABLE_40MHZ); | |
311 | if (common->channel_width) { | |
312 | radio_caps->desc_word[5] = | |
313 | cpu_to_le16(common->channel_width << 12); | |
314 | radio_caps->desc_word[5] |= cpu_to_le16(FULL40M_ENABLE); | |
315 | } | |
316 | ||
317 | if (conf_is_ht40_minus(conf)) { | |
318 | radio_caps->desc_word[5] = 0; | |
319 | radio_caps->desc_word[5] |= | |
320 | cpu_to_le16(LOWER_20_ENABLE); | |
321 | radio_caps->desc_word[5] |= | |
322 | cpu_to_le16(LOWER_20_ENABLE >> 12); | |
323 | } | |
324 | ||
325 | if (conf_is_ht40_plus(conf)) { | |
326 | radio_caps->desc_word[5] = 0; | |
327 | radio_caps->desc_word[5] |= | |
328 | cpu_to_le16(UPPER_20_ENABLE); | |
329 | radio_caps->desc_word[5] |= | |
330 | cpu_to_le16(UPPER_20_ENABLE >> 12); | |
331 | } | |
332 | } | |
333 | ||
334 | radio_caps->desc_word[7] |= cpu_to_le16(radio_id << 8); | |
335 | ||
336 | for (ii = 0; ii < MAX_HW_QUEUES; ii++) { | |
337 | radio_caps->qos_params[ii].cont_win_min_q = cpu_to_le16(3); | |
338 | radio_caps->qos_params[ii].cont_win_max_q = cpu_to_le16(0x3f); | |
339 | radio_caps->qos_params[ii].aifsn_val_q = cpu_to_le16(2); | |
340 | radio_caps->qos_params[ii].txop_q = 0; | |
341 | } | |
342 | ||
343 | for (ii = 0; ii < MAX_HW_QUEUES - 4; ii++) { | |
344 | radio_caps->qos_params[ii].cont_win_min_q = | |
345 | cpu_to_le16(common->edca_params[ii].cw_min); | |
346 | radio_caps->qos_params[ii].cont_win_max_q = | |
347 | cpu_to_le16(common->edca_params[ii].cw_max); | |
348 | radio_caps->qos_params[ii].aifsn_val_q = | |
349 | cpu_to_le16((common->edca_params[ii].aifs) << 8); | |
350 | radio_caps->qos_params[ii].txop_q = | |
351 | cpu_to_le16(common->edca_params[ii].txop); | |
352 | } | |
353 | ||
354 | memcpy(&common->rate_pwr[0], &gc[0], 40); | |
355 | for (ii = 0; ii < 20; ii++) | |
356 | radio_caps->gcpd_per_rate[inx++] = | |
357 | cpu_to_le16(common->rate_pwr[ii] & 0x00FF); | |
358 | ||
359 | radio_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_radio_caps) - | |
360 | FRAME_DESC_SZ) | | |
361 | (RSI_WIFI_MGMT_Q << 12)); | |
362 | ||
363 | ||
364 | skb_put(skb, (sizeof(struct rsi_radio_caps))); | |
365 | ||
366 | return rsi_send_internal_mgmt_frame(common, skb); | |
367 | } | |
368 | ||
369 | /** | |
370 | * rsi_mgmt_pkt_to_core() - This function is the entry point for Mgmt module. | |
371 | * @common: Pointer to the driver private structure. | |
372 | * @msg: Pointer to received packet. | |
373 | * @msg_len: Length of the recieved packet. | |
374 | * @type: Type of recieved packet. | |
375 | * | |
376 | * Return: 0 on success, -1 on failure. | |
377 | */ | |
378 | static int rsi_mgmt_pkt_to_core(struct rsi_common *common, | |
379 | u8 *msg, | |
380 | s32 msg_len, | |
381 | u8 type) | |
382 | { | |
383 | struct rsi_hw *adapter = common->priv; | |
384 | struct ieee80211_tx_info *info; | |
385 | struct skb_info *rx_params; | |
386 | u8 pad_bytes = msg[4]; | |
387 | u8 pkt_recv; | |
388 | struct sk_buff *skb; | |
389 | char *buffer; | |
390 | ||
391 | if (type == RX_DOT11_MGMT) { | |
392 | if (!adapter->sc_nvifs) | |
393 | return -ENOLINK; | |
394 | ||
395 | msg_len -= pad_bytes; | |
396 | if ((msg_len <= 0) || (!msg)) { | |
5fe1b76a JP |
397 | rsi_dbg(MGMT_RX_ZONE, |
398 | "%s: Invalid rx msg of len = %d\n", | |
dad0d04f FF |
399 | __func__, msg_len); |
400 | return -EINVAL; | |
401 | } | |
402 | ||
403 | skb = dev_alloc_skb(msg_len); | |
404 | if (!skb) { | |
405 | rsi_dbg(ERR_ZONE, "%s: Failed to allocate skb\n", | |
406 | __func__); | |
407 | return -ENOMEM; | |
408 | } | |
409 | ||
410 | buffer = skb_put(skb, msg_len); | |
411 | ||
412 | memcpy(buffer, | |
413 | (u8 *)(msg + FRAME_DESC_SZ + pad_bytes), | |
414 | msg_len); | |
415 | ||
416 | pkt_recv = buffer[0]; | |
417 | ||
418 | info = IEEE80211_SKB_CB(skb); | |
419 | rx_params = (struct skb_info *)info->driver_data; | |
420 | rx_params->rssi = rsi_get_rssi(msg); | |
421 | rx_params->channel = rsi_get_channel(msg); | |
422 | rsi_indicate_pkt_to_os(common, skb); | |
423 | } else { | |
424 | rsi_dbg(MGMT_TX_ZONE, "%s: Internal Packet\n", __func__); | |
425 | } | |
426 | ||
427 | return 0; | |
428 | } | |
429 | ||
430 | /** | |
431 | * rsi_hal_send_sta_notify_frame() - This function sends the station notify | |
432 | * frame to firmware. | |
433 | * @common: Pointer to the driver private structure. | |
434 | * @opmode: Operating mode of device. | |
435 | * @notify_event: Notification about station connection. | |
436 | * @bssid: bssid. | |
437 | * @qos_enable: Qos is enabled. | |
438 | * @aid: Aid (unique for all STA). | |
439 | * | |
440 | * Return: status: 0 on success, corresponding negative error code on failure. | |
441 | */ | |
442 | static int rsi_hal_send_sta_notify_frame(struct rsi_common *common, | |
443 | u8 opmode, | |
444 | u8 notify_event, | |
445 | const unsigned char *bssid, | |
446 | u8 qos_enable, | |
447 | u16 aid) | |
448 | { | |
449 | struct sk_buff *skb = NULL; | |
450 | struct rsi_peer_notify *peer_notify; | |
451 | u16 vap_id = 0; | |
452 | int status; | |
453 | ||
454 | rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__); | |
455 | ||
456 | skb = dev_alloc_skb(sizeof(struct rsi_peer_notify)); | |
457 | ||
458 | if (!skb) { | |
459 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
460 | __func__); | |
461 | return -ENOMEM; | |
462 | } | |
463 | ||
464 | memset(skb->data, 0, sizeof(struct rsi_peer_notify)); | |
465 | peer_notify = (struct rsi_peer_notify *)skb->data; | |
466 | ||
467 | peer_notify->command = cpu_to_le16(opmode << 1); | |
468 | ||
469 | switch (notify_event) { | |
470 | case STA_CONNECTED: | |
471 | peer_notify->command |= cpu_to_le16(RSI_ADD_PEER); | |
472 | break; | |
473 | case STA_DISCONNECTED: | |
474 | peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER); | |
475 | break; | |
476 | default: | |
477 | break; | |
478 | } | |
479 | ||
480 | peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4); | |
481 | ether_addr_copy(peer_notify->mac_addr, bssid); | |
482 | ||
483 | peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0); | |
484 | ||
485 | peer_notify->desc_word[0] = | |
486 | cpu_to_le16((sizeof(struct rsi_peer_notify) - FRAME_DESC_SZ) | | |
487 | (RSI_WIFI_MGMT_Q << 12)); | |
488 | peer_notify->desc_word[1] = cpu_to_le16(PEER_NOTIFY); | |
489 | peer_notify->desc_word[7] |= cpu_to_le16(vap_id << 8); | |
490 | ||
491 | skb_put(skb, sizeof(struct rsi_peer_notify)); | |
492 | ||
493 | status = rsi_send_internal_mgmt_frame(common, skb); | |
494 | ||
495 | if (!status && qos_enable) { | |
496 | rsi_set_contention_vals(common); | |
497 | status = rsi_load_radio_caps(common); | |
498 | } | |
499 | return status; | |
500 | } | |
501 | ||
502 | /** | |
503 | * rsi_send_aggregation_params_frame() - This function sends the ampdu | |
504 | * indication frame to firmware. | |
505 | * @common: Pointer to the driver private structure. | |
506 | * @tid: traffic identifier. | |
507 | * @ssn: ssn. | |
508 | * @buf_size: buffer size. | |
509 | * @event: notification about station connection. | |
510 | * | |
511 | * Return: 0 on success, corresponding negative error code on failure. | |
512 | */ | |
513 | int rsi_send_aggregation_params_frame(struct rsi_common *common, | |
514 | u16 tid, | |
515 | u16 ssn, | |
516 | u8 buf_size, | |
517 | u8 event) | |
518 | { | |
519 | struct sk_buff *skb = NULL; | |
520 | struct rsi_mac_frame *mgmt_frame; | |
521 | u8 peer_id = 0; | |
522 | ||
523 | skb = dev_alloc_skb(FRAME_DESC_SZ); | |
524 | ||
525 | if (!skb) { | |
526 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
527 | __func__); | |
528 | return -ENOMEM; | |
529 | } | |
530 | ||
531 | memset(skb->data, 0, FRAME_DESC_SZ); | |
532 | mgmt_frame = (struct rsi_mac_frame *)skb->data; | |
533 | ||
534 | rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__); | |
535 | ||
536 | mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12); | |
537 | mgmt_frame->desc_word[1] = cpu_to_le16(AMPDU_IND); | |
538 | ||
539 | if (event == STA_TX_ADDBA_DONE) { | |
540 | mgmt_frame->desc_word[4] = cpu_to_le16(ssn); | |
541 | mgmt_frame->desc_word[5] = cpu_to_le16(buf_size); | |
542 | mgmt_frame->desc_word[7] = | |
543 | cpu_to_le16((tid | (START_AMPDU_AGGR << 4) | (peer_id << 8))); | |
544 | } else if (event == STA_RX_ADDBA_DONE) { | |
545 | mgmt_frame->desc_word[4] = cpu_to_le16(ssn); | |
546 | mgmt_frame->desc_word[7] = cpu_to_le16(tid | | |
547 | (START_AMPDU_AGGR << 4) | | |
548 | (RX_BA_INDICATION << 5) | | |
549 | (peer_id << 8)); | |
550 | } else if (event == STA_TX_DELBA) { | |
551 | mgmt_frame->desc_word[7] = cpu_to_le16(tid | | |
552 | (STOP_AMPDU_AGGR << 4) | | |
553 | (peer_id << 8)); | |
554 | } else if (event == STA_RX_DELBA) { | |
555 | mgmt_frame->desc_word[7] = cpu_to_le16(tid | | |
556 | (STOP_AMPDU_AGGR << 4) | | |
557 | (RX_BA_INDICATION << 5) | | |
558 | (peer_id << 8)); | |
559 | } | |
560 | ||
561 | skb_put(skb, FRAME_DESC_SZ); | |
562 | ||
563 | return rsi_send_internal_mgmt_frame(common, skb); | |
564 | } | |
565 | ||
566 | /** | |
567 | * rsi_program_bb_rf() - This function starts base band and RF programming. | |
568 | * This is called after initial configurations are done. | |
569 | * @common: Pointer to the driver private structure. | |
570 | * | |
571 | * Return: 0 on success, corresponding negative error code on failure. | |
572 | */ | |
573 | static int rsi_program_bb_rf(struct rsi_common *common) | |
574 | { | |
575 | struct sk_buff *skb; | |
576 | struct rsi_mac_frame *mgmt_frame; | |
577 | ||
578 | rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__); | |
579 | ||
580 | skb = dev_alloc_skb(FRAME_DESC_SZ); | |
581 | if (!skb) { | |
582 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
583 | __func__); | |
584 | return -ENOMEM; | |
585 | } | |
586 | ||
587 | memset(skb->data, 0, FRAME_DESC_SZ); | |
588 | mgmt_frame = (struct rsi_mac_frame *)skb->data; | |
589 | ||
590 | mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12); | |
591 | mgmt_frame->desc_word[1] = cpu_to_le16(BBP_PROG_IN_TA); | |
592 | mgmt_frame->desc_word[4] = cpu_to_le16(common->endpoint << 8); | |
593 | ||
594 | if (common->rf_reset) { | |
595 | mgmt_frame->desc_word[7] = cpu_to_le16(RF_RESET_ENABLE); | |
596 | rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n", | |
597 | __func__); | |
598 | common->rf_reset = 0; | |
599 | } | |
600 | common->bb_rf_prog_count = 1; | |
601 | mgmt_frame->desc_word[7] |= cpu_to_le16(PUT_BBP_RESET | | |
602 | BBP_REG_WRITE | (RSI_RF_TYPE << 4)); | |
603 | skb_put(skb, FRAME_DESC_SZ); | |
604 | ||
605 | return rsi_send_internal_mgmt_frame(common, skb); | |
606 | } | |
607 | ||
608 | /** | |
609 | * rsi_set_vap_capabilities() - This function send vap capability to firmware. | |
610 | * @common: Pointer to the driver private structure. | |
611 | * @opmode: Operating mode of device. | |
612 | * | |
613 | * Return: 0 on success, corresponding negative error code on failure. | |
614 | */ | |
615 | int rsi_set_vap_capabilities(struct rsi_common *common, enum opmode mode) | |
616 | { | |
617 | struct sk_buff *skb = NULL; | |
618 | struct rsi_vap_caps *vap_caps; | |
619 | u16 vap_id = 0; | |
620 | ||
621 | rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__); | |
622 | ||
623 | skb = dev_alloc_skb(sizeof(struct rsi_vap_caps)); | |
624 | if (!skb) { | |
625 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
626 | __func__); | |
627 | return -ENOMEM; | |
628 | } | |
629 | ||
630 | memset(skb->data, 0, sizeof(struct rsi_vap_caps)); | |
631 | vap_caps = (struct rsi_vap_caps *)skb->data; | |
632 | ||
633 | vap_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_vap_caps) - | |
634 | FRAME_DESC_SZ) | | |
635 | (RSI_WIFI_MGMT_Q << 12)); | |
636 | vap_caps->desc_word[1] = cpu_to_le16(VAP_CAPABILITIES); | |
637 | vap_caps->desc_word[4] = cpu_to_le16(mode | | |
638 | (common->channel_width << 8)); | |
639 | vap_caps->desc_word[7] = cpu_to_le16((vap_id << 8) | | |
640 | (common->mac_id << 4) | | |
641 | common->radio_id); | |
642 | ||
643 | memcpy(vap_caps->mac_addr, common->mac_addr, IEEE80211_ADDR_LEN); | |
644 | vap_caps->keep_alive_period = cpu_to_le16(90); | |
645 | vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD); | |
646 | ||
647 | vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold); | |
648 | vap_caps->default_mgmt_rate = 0; | |
649 | if (conf_is_ht40(&common->priv->hw->conf)) { | |
650 | vap_caps->default_ctrl_rate = | |
651 | cpu_to_le32(RSI_RATE_6 | FULL40M_ENABLE << 16); | |
652 | } else { | |
653 | vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_6); | |
654 | } | |
655 | vap_caps->default_data_rate = 0; | |
656 | vap_caps->beacon_interval = cpu_to_le16(200); | |
657 | vap_caps->dtim_period = cpu_to_le16(4); | |
658 | ||
659 | skb_put(skb, sizeof(*vap_caps)); | |
660 | ||
661 | return rsi_send_internal_mgmt_frame(common, skb); | |
662 | } | |
663 | ||
664 | /** | |
665 | * rsi_hal_load_key() - This function is used to load keys within the firmware. | |
666 | * @common: Pointer to the driver private structure. | |
667 | * @data: Pointer to the key data. | |
668 | * @key_len: Key length to be loaded. | |
669 | * @key_type: Type of key: GROUP/PAIRWISE. | |
670 | * @key_id: Key index. | |
671 | * @cipher: Type of cipher used. | |
672 | * | |
673 | * Return: 0 on success, -1 on failure. | |
674 | */ | |
675 | int rsi_hal_load_key(struct rsi_common *common, | |
676 | u8 *data, | |
677 | u16 key_len, | |
678 | u8 key_type, | |
679 | u8 key_id, | |
680 | u32 cipher) | |
681 | { | |
682 | struct sk_buff *skb = NULL; | |
683 | struct rsi_set_key *set_key; | |
684 | u16 key_descriptor = 0; | |
685 | ||
686 | rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__); | |
687 | ||
688 | skb = dev_alloc_skb(sizeof(struct rsi_set_key)); | |
689 | if (!skb) { | |
690 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
691 | __func__); | |
692 | return -ENOMEM; | |
693 | } | |
694 | ||
695 | memset(skb->data, 0, sizeof(struct rsi_set_key)); | |
696 | set_key = (struct rsi_set_key *)skb->data; | |
697 | ||
698 | if ((cipher == WLAN_CIPHER_SUITE_WEP40) || | |
699 | (cipher == WLAN_CIPHER_SUITE_WEP104)) { | |
700 | key_len += 1; | |
701 | key_descriptor |= BIT(2); | |
702 | if (key_len >= 13) | |
703 | key_descriptor |= BIT(3); | |
704 | } else if (cipher != KEY_TYPE_CLEAR) { | |
705 | key_descriptor |= BIT(4); | |
706 | if (key_type == RSI_PAIRWISE_KEY) | |
707 | key_id = 0; | |
708 | if (cipher == WLAN_CIPHER_SUITE_TKIP) | |
709 | key_descriptor |= BIT(5); | |
710 | } | |
711 | key_descriptor |= (key_type | BIT(13) | (key_id << 14)); | |
712 | ||
713 | set_key->desc_word[0] = cpu_to_le16((sizeof(struct rsi_set_key) - | |
714 | FRAME_DESC_SZ) | | |
715 | (RSI_WIFI_MGMT_Q << 12)); | |
716 | set_key->desc_word[1] = cpu_to_le16(SET_KEY_REQ); | |
717 | set_key->desc_word[4] = cpu_to_le16(key_descriptor); | |
718 | ||
719 | if ((cipher == WLAN_CIPHER_SUITE_WEP40) || | |
720 | (cipher == WLAN_CIPHER_SUITE_WEP104)) { | |
721 | memcpy(&set_key->key[key_id][1], | |
722 | data, | |
723 | key_len * 2); | |
724 | } else { | |
725 | memcpy(&set_key->key[0][0], data, key_len); | |
726 | } | |
727 | ||
728 | memcpy(set_key->tx_mic_key, &data[16], 8); | |
729 | memcpy(set_key->rx_mic_key, &data[24], 8); | |
730 | ||
731 | skb_put(skb, sizeof(struct rsi_set_key)); | |
732 | ||
733 | return rsi_send_internal_mgmt_frame(common, skb); | |
734 | } | |
735 | ||
736 | /* | |
737 | * rsi_load_bootup_params() - This function send bootup params to the firmware. | |
738 | * @common: Pointer to the driver private structure. | |
739 | * | |
740 | * Return: 0 on success, corresponding error code on failure. | |
741 | */ | |
bff37af7 | 742 | static int rsi_load_bootup_params(struct rsi_common *common) |
dad0d04f FF |
743 | { |
744 | struct sk_buff *skb; | |
745 | struct rsi_boot_params *boot_params; | |
746 | ||
747 | rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__); | |
748 | skb = dev_alloc_skb(sizeof(struct rsi_boot_params)); | |
749 | if (!skb) { | |
750 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
751 | __func__); | |
752 | return -ENOMEM; | |
753 | } | |
754 | ||
755 | memset(skb->data, 0, sizeof(struct rsi_boot_params)); | |
756 | boot_params = (struct rsi_boot_params *)skb->data; | |
757 | ||
758 | rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__); | |
759 | ||
760 | if (common->channel_width == BW_40MHZ) { | |
761 | memcpy(&boot_params->bootup_params, | |
762 | &boot_params_40, | |
763 | sizeof(struct bootup_params)); | |
764 | rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__, | |
765 | UMAC_CLK_40BW); | |
766 | boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW); | |
767 | } else { | |
768 | memcpy(&boot_params->bootup_params, | |
769 | &boot_params_20, | |
770 | sizeof(struct bootup_params)); | |
771 | if (boot_params_20.valid != cpu_to_le32(VALID_20)) { | |
772 | boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW); | |
773 | rsi_dbg(MGMT_TX_ZONE, | |
774 | "%s: Packet 20MHZ <=== %d\n", __func__, | |
775 | UMAC_CLK_20BW); | |
776 | } else { | |
777 | boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ); | |
778 | rsi_dbg(MGMT_TX_ZONE, | |
779 | "%s: Packet 20MHZ <=== %d\n", __func__, | |
780 | UMAC_CLK_40MHZ); | |
781 | } | |
782 | } | |
783 | ||
784 | /** | |
785 | * Bit{0:11} indicates length of the Packet | |
786 | * Bit{12:15} indicates host queue number | |
787 | */ | |
788 | boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) | | |
789 | (RSI_WIFI_MGMT_Q << 12)); | |
790 | boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST); | |
791 | ||
792 | skb_put(skb, sizeof(struct rsi_boot_params)); | |
793 | ||
794 | return rsi_send_internal_mgmt_frame(common, skb); | |
795 | } | |
796 | ||
797 | /** | |
798 | * rsi_send_reset_mac() - This function prepares reset MAC request and sends an | |
799 | * internal management frame to indicate it to firmware. | |
800 | * @common: Pointer to the driver private structure. | |
801 | * | |
802 | * Return: 0 on success, corresponding error code on failure. | |
803 | */ | |
804 | static int rsi_send_reset_mac(struct rsi_common *common) | |
805 | { | |
806 | struct sk_buff *skb; | |
807 | struct rsi_mac_frame *mgmt_frame; | |
808 | ||
809 | rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__); | |
810 | ||
811 | skb = dev_alloc_skb(FRAME_DESC_SZ); | |
812 | if (!skb) { | |
813 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
814 | __func__); | |
815 | return -ENOMEM; | |
816 | } | |
817 | ||
818 | memset(skb->data, 0, FRAME_DESC_SZ); | |
819 | mgmt_frame = (struct rsi_mac_frame *)skb->data; | |
820 | ||
821 | mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12); | |
822 | mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ); | |
823 | mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8); | |
824 | ||
825 | skb_put(skb, FRAME_DESC_SZ); | |
826 | ||
827 | return rsi_send_internal_mgmt_frame(common, skb); | |
828 | } | |
829 | ||
830 | /** | |
831 | * rsi_set_channel() - This function programs the channel. | |
832 | * @common: Pointer to the driver private structure. | |
833 | * @channel: Channel value to be set. | |
834 | * | |
835 | * Return: 0 on success, corresponding error code on failure. | |
836 | */ | |
837 | int rsi_set_channel(struct rsi_common *common, u16 channel) | |
838 | { | |
839 | struct sk_buff *skb = NULL; | |
840 | struct rsi_mac_frame *mgmt_frame; | |
841 | ||
842 | rsi_dbg(MGMT_TX_ZONE, | |
843 | "%s: Sending scan req frame\n", __func__); | |
844 | ||
dad0d04f FF |
845 | if (common->band == IEEE80211_BAND_5GHZ) { |
846 | if ((channel >= 36) && (channel <= 64)) | |
847 | channel = ((channel - 32) / 4); | |
848 | else if ((channel > 64) && (channel <= 140)) | |
849 | channel = ((channel - 102) / 4) + 8; | |
850 | else if (channel >= 149) | |
851 | channel = ((channel - 151) / 4) + 18; | |
852 | else | |
853 | return -EINVAL; | |
854 | } else { | |
855 | if (channel > 14) { | |
856 | rsi_dbg(ERR_ZONE, "%s: Invalid chno %d, band = %d\n", | |
857 | __func__, channel, common->band); | |
858 | return -EINVAL; | |
859 | } | |
860 | } | |
861 | ||
98ddcbe0 CE |
862 | skb = dev_alloc_skb(FRAME_DESC_SZ); |
863 | if (!skb) { | |
864 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
865 | __func__); | |
866 | return -ENOMEM; | |
867 | } | |
868 | ||
869 | memset(skb->data, 0, FRAME_DESC_SZ); | |
870 | mgmt_frame = (struct rsi_mac_frame *)skb->data; | |
871 | ||
dad0d04f FF |
872 | mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12); |
873 | mgmt_frame->desc_word[1] = cpu_to_le16(SCAN_REQUEST); | |
874 | mgmt_frame->desc_word[4] = cpu_to_le16(channel); | |
875 | ||
876 | mgmt_frame->desc_word[7] = cpu_to_le16(PUT_BBP_RESET | | |
877 | BBP_REG_WRITE | | |
878 | (RSI_RF_TYPE << 4)); | |
879 | ||
880 | mgmt_frame->desc_word[5] = cpu_to_le16(0x01); | |
881 | ||
882 | if (common->channel_width == BW_40MHZ) | |
883 | mgmt_frame->desc_word[5] |= cpu_to_le16(0x1 << 8); | |
884 | ||
885 | common->channel = channel; | |
886 | ||
887 | skb_put(skb, FRAME_DESC_SZ); | |
888 | ||
889 | return rsi_send_internal_mgmt_frame(common, skb); | |
890 | } | |
891 | ||
892 | /** | |
893 | * rsi_compare() - This function is used to compare two integers | |
894 | * @a: pointer to the first integer | |
895 | * @b: pointer to the second integer | |
896 | * | |
897 | * Return: 0 if both are equal, -1 if the first is smaller, else 1 | |
898 | */ | |
899 | static int rsi_compare(const void *a, const void *b) | |
900 | { | |
901 | u16 _a = *(const u16 *)(a); | |
902 | u16 _b = *(const u16 *)(b); | |
903 | ||
904 | if (_a > _b) | |
905 | return -1; | |
906 | ||
907 | if (_a < _b) | |
908 | return 1; | |
909 | ||
910 | return 0; | |
911 | } | |
912 | ||
913 | /** | |
914 | * rsi_map_rates() - This function is used to map selected rates to hw rates. | |
915 | * @rate: The standard rate to be mapped. | |
916 | * @offset: Offset that will be returned. | |
917 | * | |
918 | * Return: 0 if it is a mcs rate, else 1 | |
919 | */ | |
920 | static bool rsi_map_rates(u16 rate, int *offset) | |
921 | { | |
922 | int kk; | |
923 | for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) { | |
924 | if (rate == mcs[kk]) { | |
925 | *offset = kk; | |
926 | return false; | |
927 | } | |
928 | } | |
929 | ||
930 | for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) { | |
931 | if (rate == rsi_rates[kk].bitrate / 5) { | |
932 | *offset = kk; | |
933 | break; | |
934 | } | |
935 | } | |
936 | return true; | |
937 | } | |
938 | ||
939 | /** | |
940 | * rsi_send_auto_rate_request() - This function is to set rates for connection | |
941 | * and send autorate request to firmware. | |
942 | * @common: Pointer to the driver private structure. | |
943 | * | |
944 | * Return: 0 on success, corresponding error code on failure. | |
945 | */ | |
946 | static int rsi_send_auto_rate_request(struct rsi_common *common) | |
947 | { | |
948 | struct sk_buff *skb; | |
949 | struct rsi_auto_rate *auto_rate; | |
950 | int ii = 0, jj = 0, kk = 0; | |
951 | struct ieee80211_hw *hw = common->priv->hw; | |
952 | u8 band = hw->conf.chandef.chan->band; | |
953 | u8 num_supported_rates = 0; | |
954 | u8 rate_offset = 0; | |
955 | u32 rate_bitmap = common->bitrate_mask[band]; | |
956 | ||
957 | u16 *selected_rates, min_rate; | |
958 | ||
959 | skb = dev_alloc_skb(sizeof(struct rsi_auto_rate)); | |
960 | if (!skb) { | |
961 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
962 | __func__); | |
963 | return -ENOMEM; | |
964 | } | |
965 | ||
966 | selected_rates = kmalloc(2 * RSI_TBL_SZ, GFP_KERNEL); | |
967 | if (!selected_rates) { | |
968 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n", | |
969 | __func__); | |
61698b7e | 970 | dev_kfree_skb(skb); |
dad0d04f FF |
971 | return -ENOMEM; |
972 | } | |
973 | ||
974 | memset(skb->data, 0, sizeof(struct rsi_auto_rate)); | |
975 | memset(selected_rates, 0, 2 * RSI_TBL_SZ); | |
976 | ||
977 | auto_rate = (struct rsi_auto_rate *)skb->data; | |
978 | ||
979 | auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f)); | |
980 | auto_rate->collision_tolerance = cpu_to_le16(3); | |
981 | auto_rate->failure_limit = cpu_to_le16(3); | |
982 | auto_rate->initial_boundary = cpu_to_le16(3); | |
983 | auto_rate->max_threshold_limt = cpu_to_le16(27); | |
984 | ||
985 | auto_rate->desc_word[1] = cpu_to_le16(AUTO_RATE_IND); | |
986 | ||
987 | if (common->channel_width == BW_40MHZ) | |
988 | auto_rate->desc_word[7] |= cpu_to_le16(1); | |
989 | ||
990 | if (band == IEEE80211_BAND_2GHZ) | |
991 | min_rate = STD_RATE_01; | |
992 | else | |
993 | min_rate = STD_RATE_06; | |
994 | ||
995 | for (ii = 0, jj = 0; ii < ARRAY_SIZE(rsi_rates); ii++) { | |
996 | if (rate_bitmap & BIT(ii)) { | |
997 | selected_rates[jj++] = (rsi_rates[ii].bitrate / 5); | |
998 | rate_offset++; | |
999 | } | |
1000 | } | |
1001 | num_supported_rates = jj; | |
1002 | ||
1003 | if (common->vif_info[0].is_ht) { | |
1004 | for (ii = 0; ii < ARRAY_SIZE(mcs); ii++) | |
1005 | selected_rates[jj++] = mcs[ii]; | |
1006 | num_supported_rates += ARRAY_SIZE(mcs); | |
1007 | rate_offset += ARRAY_SIZE(mcs); | |
1008 | } | |
1009 | ||
1010 | if (rate_offset < (RSI_TBL_SZ / 2) - 1) { | |
1011 | for (ii = jj; ii < (RSI_TBL_SZ / 2); ii++) { | |
1012 | selected_rates[jj++] = min_rate; | |
1013 | rate_offset++; | |
1014 | } | |
1015 | } | |
1016 | ||
1017 | sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL); | |
1018 | ||
1019 | /* mapping the rates to RSI rates */ | |
1020 | for (ii = 0; ii < jj; ii++) { | |
1021 | if (rsi_map_rates(selected_rates[ii], &kk)) { | |
1022 | auto_rate->supported_rates[ii] = | |
1023 | cpu_to_le16(rsi_rates[kk].hw_value); | |
1024 | } else { | |
1025 | auto_rate->supported_rates[ii] = | |
1026 | cpu_to_le16(rsi_mcsrates[kk]); | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | /* loading HT rates in the bottom half of the auto rate table */ | |
1031 | if (common->vif_info[0].is_ht) { | |
1032 | if (common->vif_info[0].sgi) | |
1033 | auto_rate->supported_rates[rate_offset++] = | |
1034 | cpu_to_le16(RSI_RATE_MCS7_SG); | |
1035 | ||
1036 | for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1; | |
1037 | ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) { | |
1038 | if (common->vif_info[0].sgi) | |
1039 | auto_rate->supported_rates[ii++] = | |
1040 | cpu_to_le16(rsi_mcsrates[kk] | BIT(9)); | |
1041 | auto_rate->supported_rates[ii] = | |
1042 | cpu_to_le16(rsi_mcsrates[kk--]); | |
1043 | } | |
1044 | ||
1045 | for (; ii < RSI_TBL_SZ; ii++) { | |
1046 | auto_rate->supported_rates[ii] = | |
1047 | cpu_to_le16(rsi_mcsrates[0]); | |
1048 | } | |
1049 | } | |
1050 | ||
1051 | auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2); | |
1052 | auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2); | |
1053 | auto_rate->desc_word[7] |= cpu_to_le16(0 << 8); | |
1054 | num_supported_rates *= 2; | |
1055 | ||
1056 | auto_rate->desc_word[0] = cpu_to_le16((sizeof(*auto_rate) - | |
1057 | FRAME_DESC_SZ) | | |
1058 | (RSI_WIFI_MGMT_Q << 12)); | |
1059 | ||
1060 | skb_put(skb, | |
1061 | sizeof(struct rsi_auto_rate)); | |
1062 | kfree(selected_rates); | |
1063 | ||
1064 | return rsi_send_internal_mgmt_frame(common, skb); | |
1065 | } | |
1066 | ||
1067 | /** | |
1068 | * rsi_inform_bss_status() - This function informs about bss status with the | |
1069 | * help of sta notify params by sending an internal | |
1070 | * management frame to firmware. | |
1071 | * @common: Pointer to the driver private structure. | |
1072 | * @status: Bss status type. | |
1073 | * @bssid: Bssid. | |
1074 | * @qos_enable: Qos is enabled. | |
1075 | * @aid: Aid (unique for all STAs). | |
1076 | * | |
1077 | * Return: None. | |
1078 | */ | |
1079 | void rsi_inform_bss_status(struct rsi_common *common, | |
1080 | u8 status, | |
1081 | const unsigned char *bssid, | |
1082 | u8 qos_enable, | |
1083 | u16 aid) | |
1084 | { | |
1085 | if (status) { | |
1086 | rsi_hal_send_sta_notify_frame(common, | |
48d11dc3 | 1087 | RSI_IFTYPE_STATION, |
dad0d04f FF |
1088 | STA_CONNECTED, |
1089 | bssid, | |
1090 | qos_enable, | |
1091 | aid); | |
1092 | if (common->min_rate == 0xffff) | |
1093 | rsi_send_auto_rate_request(common); | |
1094 | } else { | |
1095 | rsi_hal_send_sta_notify_frame(common, | |
48d11dc3 | 1096 | RSI_IFTYPE_STATION, |
dad0d04f FF |
1097 | STA_DISCONNECTED, |
1098 | bssid, | |
1099 | qos_enable, | |
1100 | aid); | |
1101 | } | |
1102 | } | |
1103 | ||
1104 | /** | |
1105 | * rsi_eeprom_read() - This function sends a frame to read the mac address | |
1106 | * from the eeprom. | |
1107 | * @common: Pointer to the driver private structure. | |
1108 | * | |
1109 | * Return: 0 on success, -1 on failure. | |
1110 | */ | |
1111 | static int rsi_eeprom_read(struct rsi_common *common) | |
1112 | { | |
1113 | struct rsi_mac_frame *mgmt_frame; | |
1114 | struct sk_buff *skb; | |
1115 | ||
1116 | rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__); | |
1117 | ||
1118 | skb = dev_alloc_skb(FRAME_DESC_SZ); | |
1119 | if (!skb) { | |
1120 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", | |
1121 | __func__); | |
1122 | return -ENOMEM; | |
1123 | } | |
1124 | ||
1125 | memset(skb->data, 0, FRAME_DESC_SZ); | |
1126 | mgmt_frame = (struct rsi_mac_frame *)skb->data; | |
1127 | ||
1128 | /* FrameType */ | |
1129 | mgmt_frame->desc_word[1] = cpu_to_le16(EEPROM_READ_TYPE); | |
1130 | mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12); | |
1131 | /* Number of bytes to read */ | |
1132 | mgmt_frame->desc_word[3] = cpu_to_le16(ETH_ALEN + | |
1133 | WLAN_MAC_MAGIC_WORD_LEN + | |
1134 | WLAN_HOST_MODE_LEN + | |
1135 | WLAN_FW_VERSION_LEN); | |
1136 | /* Address to read */ | |
1137 | mgmt_frame->desc_word[4] = cpu_to_le16(WLAN_MAC_EEPROM_ADDR); | |
1138 | ||
1139 | skb_put(skb, FRAME_DESC_SZ); | |
1140 | ||
1141 | return rsi_send_internal_mgmt_frame(common, skb); | |
1142 | } | |
1143 | ||
1144 | /** | |
1145 | * rsi_handle_ta_confirm_type() - This function handles the confirm frames. | |
1146 | * @common: Pointer to the driver private structure. | |
1147 | * @msg: Pointer to received packet. | |
1148 | * | |
1149 | * Return: 0 on success, -1 on failure. | |
1150 | */ | |
1151 | static int rsi_handle_ta_confirm_type(struct rsi_common *common, | |
1152 | u8 *msg) | |
1153 | { | |
1154 | u8 sub_type = (msg[15] & 0xff); | |
1155 | ||
1156 | switch (sub_type) { | |
1157 | case BOOTUP_PARAMS_REQUEST: | |
1158 | rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n", | |
1159 | __func__); | |
1160 | if (common->fsm_state == FSM_BOOT_PARAMS_SENT) { | |
1161 | if (rsi_eeprom_read(common)) { | |
1162 | common->fsm_state = FSM_CARD_NOT_READY; | |
1163 | goto out; | |
1164 | } else { | |
1165 | common->fsm_state = FSM_EEPROM_READ_MAC_ADDR; | |
1166 | } | |
1167 | } else { | |
1168 | rsi_dbg(ERR_ZONE, | |
1169 | "%s: Received bootup params cfm in %d state\n", | |
1170 | __func__, common->fsm_state); | |
1171 | return 0; | |
1172 | } | |
1173 | break; | |
1174 | ||
1175 | case EEPROM_READ_TYPE: | |
1176 | if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) { | |
1177 | if (msg[16] == MAGIC_WORD) { | |
1178 | u8 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN | |
1179 | + WLAN_MAC_MAGIC_WORD_LEN); | |
1180 | memcpy(common->mac_addr, | |
1181 | &msg[offset], | |
1182 | ETH_ALEN); | |
1183 | memcpy(&common->fw_ver, | |
1184 | &msg[offset + ETH_ALEN], | |
1185 | sizeof(struct version_info)); | |
1186 | ||
1187 | } else { | |
1188 | common->fsm_state = FSM_CARD_NOT_READY; | |
1189 | break; | |
1190 | } | |
1191 | if (rsi_send_reset_mac(common)) | |
1192 | goto out; | |
1193 | else | |
1194 | common->fsm_state = FSM_RESET_MAC_SENT; | |
1195 | } else { | |
1196 | rsi_dbg(ERR_ZONE, | |
1197 | "%s: Received eeprom mac addr in %d state\n", | |
1198 | __func__, common->fsm_state); | |
1199 | return 0; | |
1200 | } | |
1201 | break; | |
1202 | ||
1203 | case RESET_MAC_REQ: | |
1204 | if (common->fsm_state == FSM_RESET_MAC_SENT) { | |
1205 | rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n", | |
1206 | __func__); | |
1207 | ||
1208 | if (rsi_load_radio_caps(common)) | |
1209 | goto out; | |
1210 | else | |
1211 | common->fsm_state = FSM_RADIO_CAPS_SENT; | |
1212 | } else { | |
1213 | rsi_dbg(ERR_ZONE, | |
1214 | "%s: Received reset mac cfm in %d state\n", | |
1215 | __func__, common->fsm_state); | |
1216 | return 0; | |
1217 | } | |
1218 | break; | |
1219 | ||
1220 | case RADIO_CAPABILITIES: | |
1221 | if (common->fsm_state == FSM_RADIO_CAPS_SENT) { | |
1222 | common->rf_reset = 1; | |
1223 | if (rsi_program_bb_rf(common)) { | |
1224 | goto out; | |
1225 | } else { | |
1226 | common->fsm_state = FSM_BB_RF_PROG_SENT; | |
1227 | rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n", | |
1228 | __func__); | |
1229 | } | |
1230 | } else { | |
1231 | rsi_dbg(ERR_ZONE, | |
1232 | "%s: Received radio caps cfm in %d state\n", | |
1233 | __func__, common->fsm_state); | |
1234 | return 0; | |
1235 | } | |
1236 | break; | |
1237 | ||
1238 | case BB_PROG_VALUES_REQUEST: | |
1239 | case RF_PROG_VALUES_REQUEST: | |
1240 | case BBP_PROG_IN_TA: | |
1241 | rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__); | |
1242 | if (common->fsm_state == FSM_BB_RF_PROG_SENT) { | |
1243 | common->bb_rf_prog_count--; | |
1244 | if (!common->bb_rf_prog_count) { | |
1245 | common->fsm_state = FSM_MAC_INIT_DONE; | |
1246 | return rsi_mac80211_attach(common); | |
1247 | } | |
1248 | } else { | |
1249 | goto out; | |
1250 | } | |
1251 | break; | |
1252 | ||
1253 | default: | |
1254 | rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n", | |
1255 | __func__); | |
1256 | break; | |
1257 | } | |
1258 | return 0; | |
1259 | out: | |
1260 | rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n", | |
1261 | __func__); | |
1262 | return -EINVAL; | |
1263 | } | |
1264 | ||
1265 | /** | |
1266 | * rsi_mgmt_pkt_recv() - This function processes the management packets | |
1267 | * recieved from the hardware. | |
1268 | * @common: Pointer to the driver private structure. | |
1269 | * @msg: Pointer to the received packet. | |
1270 | * | |
1271 | * Return: 0 on success, -1 on failure. | |
1272 | */ | |
1273 | int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg) | |
1274 | { | |
1275 | s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff); | |
1276 | u16 msg_type = (msg[2]); | |
bff37af7 | 1277 | int ret; |
dad0d04f FF |
1278 | |
1279 | rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n", | |
1280 | __func__, msg_len, msg_type); | |
1281 | ||
1282 | if (msg_type == TA_CONFIRM_TYPE) { | |
1283 | return rsi_handle_ta_confirm_type(common, msg); | |
1284 | } else if (msg_type == CARD_READY_IND) { | |
1285 | rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n", | |
1286 | __func__); | |
1287 | if (common->fsm_state == FSM_CARD_NOT_READY) { | |
1288 | rsi_set_default_parameters(common); | |
1289 | ||
bff37af7 FF |
1290 | ret = rsi_load_bootup_params(common); |
1291 | if (ret) | |
1292 | return ret; | |
dad0d04f FF |
1293 | else |
1294 | common->fsm_state = FSM_BOOT_PARAMS_SENT; | |
1295 | } else { | |
1296 | return -EINVAL; | |
1297 | } | |
1298 | } else if (msg_type == TX_STATUS_IND) { | |
3f3aa2fb | 1299 | if (msg[15] == PROBEREQ_CONFIRM) { |
dad0d04f FF |
1300 | common->mgmt_q_block = false; |
1301 | rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n", | |
1302 | __func__); | |
3f3aa2fb | 1303 | } |
dad0d04f FF |
1304 | } else { |
1305 | return rsi_mgmt_pkt_to_core(common, msg, msg_len, msg_type); | |
1306 | } | |
1307 | return 0; | |
1308 | } |