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