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