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