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