0001
0002
0003
0004
0005
0006
0007
0008 #include <asm/unaligned.h>
0009 #include "decl.h"
0010 #include "ioctl.h"
0011 #include "util.h"
0012 #include "fw.h"
0013 #include "main.h"
0014 #include "wmm.h"
0015 #include "11n.h"
0016
0017 static void mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter);
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 static void
0028 mwifiex_init_cmd_node(struct mwifiex_private *priv,
0029 struct cmd_ctrl_node *cmd_node,
0030 u32 cmd_no, void *data_buf, bool sync)
0031 {
0032 cmd_node->priv = priv;
0033 cmd_node->cmd_no = cmd_no;
0034
0035 if (sync) {
0036 cmd_node->wait_q_enabled = true;
0037 cmd_node->cmd_wait_q_woken = false;
0038 cmd_node->condition = &cmd_node->cmd_wait_q_woken;
0039 }
0040 cmd_node->data_buf = data_buf;
0041 cmd_node->cmd_skb = cmd_node->skb;
0042 }
0043
0044
0045
0046
0047
0048 static struct cmd_ctrl_node *
0049 mwifiex_get_cmd_node(struct mwifiex_adapter *adapter)
0050 {
0051 struct cmd_ctrl_node *cmd_node;
0052
0053 spin_lock_bh(&adapter->cmd_free_q_lock);
0054 if (list_empty(&adapter->cmd_free_q)) {
0055 mwifiex_dbg(adapter, ERROR,
0056 "GET_CMD_NODE: cmd node not available\n");
0057 spin_unlock_bh(&adapter->cmd_free_q_lock);
0058 return NULL;
0059 }
0060 cmd_node = list_first_entry(&adapter->cmd_free_q,
0061 struct cmd_ctrl_node, list);
0062 list_del(&cmd_node->list);
0063 spin_unlock_bh(&adapter->cmd_free_q_lock);
0064
0065 return cmd_node;
0066 }
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079 static void
0080 mwifiex_clean_cmd_node(struct mwifiex_adapter *adapter,
0081 struct cmd_ctrl_node *cmd_node)
0082 {
0083 cmd_node->cmd_no = 0;
0084 cmd_node->cmd_flag = 0;
0085 cmd_node->data_buf = NULL;
0086 cmd_node->wait_q_enabled = false;
0087
0088 if (cmd_node->cmd_skb)
0089 skb_trim(cmd_node->cmd_skb, 0);
0090
0091 if (cmd_node->resp_skb) {
0092 adapter->if_ops.cmdrsp_complete(adapter, cmd_node->resp_skb);
0093 cmd_node->resp_skb = NULL;
0094 }
0095 }
0096
0097
0098
0099
0100
0101
0102
0103 static void
0104 mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
0105 struct cmd_ctrl_node *cmd_node)
0106 {
0107 if (!cmd_node)
0108 return;
0109
0110 if (cmd_node->wait_q_enabled)
0111 mwifiex_complete_cmd(adapter, cmd_node);
0112
0113 mwifiex_clean_cmd_node(adapter, cmd_node);
0114
0115
0116 spin_lock_bh(&adapter->cmd_free_q_lock);
0117 list_add_tail(&cmd_node->list, &adapter->cmd_free_q);
0118 spin_unlock_bh(&adapter->cmd_free_q_lock);
0119 }
0120
0121
0122 void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter,
0123 struct cmd_ctrl_node *cmd_node)
0124 {
0125 struct host_cmd_ds_command *host_cmd = (void *)cmd_node->cmd_skb->data;
0126
0127 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
0128
0129 atomic_dec(&adapter->cmd_pending);
0130 mwifiex_dbg(adapter, CMD,
0131 "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
0132 le16_to_cpu(host_cmd->command),
0133 atomic_read(&adapter->cmd_pending));
0134 }
0135
0136
0137
0138
0139
0140
0141
0142
0143 static int mwifiex_cmd_host_cmd(struct mwifiex_private *priv,
0144 struct host_cmd_ds_command *cmd,
0145 struct mwifiex_ds_misc_cmd *pcmd_ptr)
0146 {
0147
0148 memcpy(cmd, pcmd_ptr->cmd, pcmd_ptr->len);
0149 mwifiex_dbg(priv->adapter, CMD,
0150 "cmd: host cmd size = %d\n", pcmd_ptr->len);
0151 return 0;
0152 }
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
0163 struct cmd_ctrl_node *cmd_node)
0164 {
0165
0166 struct mwifiex_adapter *adapter = priv->adapter;
0167 int ret;
0168 struct host_cmd_ds_command *host_cmd;
0169 uint16_t cmd_code;
0170 uint16_t cmd_size;
0171
0172 if (!adapter || !cmd_node)
0173 return -1;
0174
0175 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
0176
0177
0178 if (host_cmd->size == 0) {
0179 mwifiex_dbg(adapter, ERROR,
0180 "DNLD_CMD: host_cmd is null\t"
0181 "or cmd size is 0, not sending\n");
0182 if (cmd_node->wait_q_enabled)
0183 adapter->cmd_wait_q.status = -1;
0184 mwifiex_recycle_cmd_node(adapter, cmd_node);
0185 return -1;
0186 }
0187
0188 cmd_code = le16_to_cpu(host_cmd->command);
0189 cmd_node->cmd_no = cmd_code;
0190 cmd_size = le16_to_cpu(host_cmd->size);
0191
0192 if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET &&
0193 cmd_code != HostCmd_CMD_FUNC_SHUTDOWN &&
0194 cmd_code != HostCmd_CMD_FUNC_INIT) {
0195 mwifiex_dbg(adapter, ERROR,
0196 "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
0197 cmd_code);
0198 mwifiex_recycle_cmd_node(adapter, cmd_node);
0199 queue_work(adapter->workqueue, &adapter->main_work);
0200 return -1;
0201 }
0202
0203
0204 adapter->seq_num++;
0205 host_cmd->seq_num = cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
0206 (adapter->seq_num,
0207 cmd_node->priv->bss_num,
0208 cmd_node->priv->bss_type));
0209
0210 spin_lock_bh(&adapter->mwifiex_cmd_lock);
0211 adapter->curr_cmd = cmd_node;
0212 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
0213
0214
0215 if (cmd_node->cmd_skb->len > cmd_size)
0216
0217
0218
0219
0220 skb_trim(cmd_node->cmd_skb, cmd_size);
0221 else if (cmd_node->cmd_skb->len < cmd_size)
0222
0223
0224
0225
0226
0227 skb_put(cmd_node->cmd_skb, cmd_size - cmd_node->cmd_skb->len);
0228
0229 mwifiex_dbg(adapter, CMD,
0230 "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
0231 cmd_code,
0232 get_unaligned_le16((u8 *)host_cmd + S_DS_GEN),
0233 cmd_size, le16_to_cpu(host_cmd->seq_num));
0234 mwifiex_dbg_dump(adapter, CMD_D, "cmd buffer:", host_cmd, cmd_size);
0235
0236 if (adapter->iface_type == MWIFIEX_USB) {
0237 skb_push(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN);
0238 put_unaligned_le32(MWIFIEX_USB_TYPE_CMD,
0239 cmd_node->cmd_skb->data);
0240 adapter->cmd_sent = true;
0241 ret = adapter->if_ops.host_to_card(adapter,
0242 MWIFIEX_USB_EP_CMD_EVENT,
0243 cmd_node->cmd_skb, NULL);
0244 skb_pull(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN);
0245 if (ret == -EBUSY)
0246 cmd_node->cmd_skb = NULL;
0247 } else {
0248 skb_push(cmd_node->cmd_skb, adapter->intf_hdr_len);
0249 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD,
0250 cmd_node->cmd_skb, NULL);
0251 skb_pull(cmd_node->cmd_skb, adapter->intf_hdr_len);
0252 }
0253
0254 if (ret == -1) {
0255 mwifiex_dbg(adapter, ERROR,
0256 "DNLD_CMD: host to card failed\n");
0257 if (adapter->iface_type == MWIFIEX_USB)
0258 adapter->cmd_sent = false;
0259 if (cmd_node->wait_q_enabled)
0260 adapter->cmd_wait_q.status = -1;
0261 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
0262
0263 spin_lock_bh(&adapter->mwifiex_cmd_lock);
0264 adapter->curr_cmd = NULL;
0265 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
0266
0267 adapter->dbg.num_cmd_host_to_card_failure++;
0268 return -1;
0269 }
0270
0271
0272 adapter->dbg.last_cmd_index =
0273 (adapter->dbg.last_cmd_index + 1) % DBG_CMD_NUM;
0274 adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index] = cmd_code;
0275 adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index] =
0276 get_unaligned_le16((u8 *)host_cmd + S_DS_GEN);
0277
0278
0279
0280
0281 if (cmd_code != HostCmd_CMD_FW_DUMP_EVENT)
0282 mod_timer(&adapter->cmd_timer,
0283 jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
0284
0285
0286 cmd_code &= HostCmd_CMD_ID_MASK;
0287
0288 return 0;
0289 }
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300 static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
0301 {
0302 int ret;
0303 struct mwifiex_private *priv;
0304 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf =
0305 (struct mwifiex_opt_sleep_confirm *)
0306 adapter->sleep_cfm->data;
0307 struct sk_buff *sleep_cfm_tmp;
0308
0309 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
0310
0311 adapter->seq_num++;
0312 sleep_cfm_buf->seq_num =
0313 cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
0314 (adapter->seq_num, priv->bss_num,
0315 priv->bss_type));
0316
0317 mwifiex_dbg(adapter, CMD,
0318 "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
0319 le16_to_cpu(sleep_cfm_buf->command),
0320 le16_to_cpu(sleep_cfm_buf->action),
0321 le16_to_cpu(sleep_cfm_buf->size),
0322 le16_to_cpu(sleep_cfm_buf->seq_num));
0323 mwifiex_dbg_dump(adapter, CMD_D, "SLEEP_CFM buffer: ", sleep_cfm_buf,
0324 le16_to_cpu(sleep_cfm_buf->size));
0325
0326 if (adapter->iface_type == MWIFIEX_USB) {
0327 sleep_cfm_tmp =
0328 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
0329 + MWIFIEX_TYPE_LEN);
0330 if (!sleep_cfm_tmp) {
0331 mwifiex_dbg(adapter, ERROR,
0332 "SLEEP_CFM: dev_alloc_skb failed\n");
0333 return -ENOMEM;
0334 }
0335
0336 skb_put(sleep_cfm_tmp, sizeof(struct mwifiex_opt_sleep_confirm)
0337 + MWIFIEX_TYPE_LEN);
0338 put_unaligned_le32(MWIFIEX_USB_TYPE_CMD, sleep_cfm_tmp->data);
0339 memcpy(sleep_cfm_tmp->data + MWIFIEX_TYPE_LEN,
0340 adapter->sleep_cfm->data,
0341 sizeof(struct mwifiex_opt_sleep_confirm));
0342 ret = adapter->if_ops.host_to_card(adapter,
0343 MWIFIEX_USB_EP_CMD_EVENT,
0344 sleep_cfm_tmp, NULL);
0345 if (ret != -EBUSY)
0346 dev_kfree_skb_any(sleep_cfm_tmp);
0347 } else {
0348 skb_push(adapter->sleep_cfm, adapter->intf_hdr_len);
0349 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD,
0350 adapter->sleep_cfm, NULL);
0351 skb_pull(adapter->sleep_cfm, adapter->intf_hdr_len);
0352 }
0353
0354 if (ret == -1) {
0355 mwifiex_dbg(adapter, ERROR, "SLEEP_CFM: failed\n");
0356 adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure++;
0357 return -1;
0358 }
0359
0360 if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl))
0361
0362 adapter->ps_state = PS_STATE_SLEEP;
0363 else
0364 adapter->ps_state = PS_STATE_SLEEP_CFM;
0365
0366 if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl) &&
0367 (test_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags) &&
0368 !adapter->sleep_period.period)) {
0369 adapter->pm_wakeup_card_req = true;
0370 mwifiex_hs_activated_event(mwifiex_get_priv
0371 (adapter, MWIFIEX_BSS_ROLE_ANY), true);
0372 }
0373
0374 return ret;
0375 }
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter)
0390 {
0391 struct cmd_ctrl_node *cmd_array;
0392 u32 i;
0393
0394
0395 cmd_array = kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER,
0396 sizeof(struct cmd_ctrl_node), GFP_KERNEL);
0397 if (!cmd_array)
0398 return -ENOMEM;
0399
0400 adapter->cmd_pool = cmd_array;
0401
0402
0403 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
0404 cmd_array[i].skb = dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER);
0405 if (!cmd_array[i].skb) {
0406 mwifiex_dbg(adapter, ERROR,
0407 "unable to allocate command buffer\n");
0408 return -ENOMEM;
0409 }
0410 }
0411
0412 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++)
0413 mwifiex_insert_cmd_to_free_q(adapter, &cmd_array[i]);
0414
0415 return 0;
0416 }
0417
0418
0419
0420
0421
0422
0423
0424 void mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter)
0425 {
0426 struct cmd_ctrl_node *cmd_array;
0427 u32 i;
0428
0429
0430 if (!adapter->cmd_pool) {
0431 mwifiex_dbg(adapter, FATAL,
0432 "info: FREE_CMD_BUF: cmd_pool is null\n");
0433 return;
0434 }
0435
0436 cmd_array = adapter->cmd_pool;
0437
0438
0439 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
0440 if (cmd_array[i].skb) {
0441 mwifiex_dbg(adapter, CMD,
0442 "cmd: free cmd buffer %d\n", i);
0443 dev_kfree_skb_any(cmd_array[i].skb);
0444 }
0445 if (!cmd_array[i].resp_skb)
0446 continue;
0447
0448 if (adapter->iface_type == MWIFIEX_USB)
0449 adapter->if_ops.cmdrsp_complete(adapter,
0450 cmd_array[i].resp_skb);
0451 else
0452 dev_kfree_skb_any(cmd_array[i].resp_skb);
0453 }
0454
0455 if (adapter->cmd_pool) {
0456 mwifiex_dbg(adapter, CMD,
0457 "cmd: free cmd pool\n");
0458 kfree(adapter->cmd_pool);
0459 adapter->cmd_pool = NULL;
0460 }
0461 }
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473 int mwifiex_process_event(struct mwifiex_adapter *adapter)
0474 {
0475 int ret, i;
0476 struct mwifiex_private *priv =
0477 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
0478 struct sk_buff *skb = adapter->event_skb;
0479 u32 eventcause;
0480 struct mwifiex_rxinfo *rx_info;
0481
0482 if ((adapter->event_cause & EVENT_ID_MASK) == EVENT_RADAR_DETECTED) {
0483 for (i = 0; i < adapter->priv_num; i++) {
0484 priv = adapter->priv[i];
0485 if (priv && mwifiex_is_11h_active(priv)) {
0486 adapter->event_cause |=
0487 ((priv->bss_num & 0xff) << 16) |
0488 ((priv->bss_type & 0xff) << 24);
0489 break;
0490 }
0491 }
0492 }
0493
0494 eventcause = adapter->event_cause;
0495
0496
0497 adapter->dbg.last_event_index =
0498 (adapter->dbg.last_event_index + 1) % DBG_CMD_NUM;
0499 adapter->dbg.last_event[adapter->dbg.last_event_index] =
0500 (u16) eventcause;
0501
0502
0503 priv = mwifiex_get_priv_by_id(adapter, EVENT_GET_BSS_NUM(eventcause),
0504 EVENT_GET_BSS_TYPE(eventcause));
0505 if (!priv)
0506 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
0507
0508
0509 eventcause &= EVENT_ID_MASK;
0510 adapter->event_cause = eventcause;
0511
0512 if (skb) {
0513 rx_info = MWIFIEX_SKB_RXCB(skb);
0514 memset(rx_info, 0, sizeof(*rx_info));
0515 rx_info->bss_num = priv->bss_num;
0516 rx_info->bss_type = priv->bss_type;
0517 mwifiex_dbg_dump(adapter, EVT_D, "Event Buf:",
0518 skb->data, skb->len);
0519 }
0520
0521 mwifiex_dbg(adapter, EVENT, "EVENT: cause: %#x\n", eventcause);
0522
0523 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
0524 ret = mwifiex_process_uap_event(priv);
0525 else
0526 ret = mwifiex_process_sta_event(priv);
0527
0528 adapter->event_cause = 0;
0529 adapter->event_skb = NULL;
0530 adapter->if_ops.event_complete(adapter, skb);
0531
0532 return ret;
0533 }
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546 int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
0547 u16 cmd_action, u32 cmd_oid, void *data_buf, bool sync)
0548 {
0549 int ret;
0550 struct mwifiex_adapter *adapter = priv->adapter;
0551 struct cmd_ctrl_node *cmd_node;
0552 struct host_cmd_ds_command *cmd_ptr;
0553
0554 if (!adapter) {
0555 pr_err("PREP_CMD: adapter is NULL\n");
0556 return -1;
0557 }
0558
0559 if (test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
0560 mwifiex_dbg(adapter, ERROR,
0561 "PREP_CMD: device in suspended state\n");
0562 return -1;
0563 }
0564
0565 if (test_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags) &&
0566 cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) {
0567 mwifiex_dbg(adapter, ERROR,
0568 "PREP_CMD: host entering sleep state\n");
0569 return -1;
0570 }
0571
0572 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags)) {
0573 mwifiex_dbg(adapter, ERROR,
0574 "PREP_CMD: card is removed\n");
0575 return -1;
0576 }
0577
0578 if (test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
0579 mwifiex_dbg(adapter, ERROR,
0580 "PREP_CMD: FW is in bad state\n");
0581 return -1;
0582 }
0583
0584 if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET) {
0585 if (cmd_no != HostCmd_CMD_FUNC_INIT) {
0586 mwifiex_dbg(adapter, ERROR,
0587 "PREP_CMD: FW in reset state\n");
0588 return -1;
0589 }
0590 }
0591
0592
0593
0594 if (adapter->mfg_mode && cmd_no) {
0595 dev_dbg(adapter->dev, "Ignoring commands in manufacturing mode\n");
0596 return -1;
0597 }
0598
0599 if (priv->adapter->hs_activated_manually &&
0600 cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) {
0601 mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
0602 priv->adapter->hs_activated_manually = false;
0603 }
0604
0605
0606 cmd_node = mwifiex_get_cmd_node(adapter);
0607
0608 if (!cmd_node) {
0609 mwifiex_dbg(adapter, ERROR,
0610 "PREP_CMD: no free cmd node\n");
0611 return -1;
0612 }
0613
0614
0615 mwifiex_init_cmd_node(priv, cmd_node, cmd_no, data_buf, sync);
0616
0617 if (!cmd_node->cmd_skb) {
0618 mwifiex_dbg(adapter, ERROR,
0619 "PREP_CMD: no free cmd buf\n");
0620 return -1;
0621 }
0622
0623 skb_put_zero(cmd_node->cmd_skb, sizeof(struct host_cmd_ds_command));
0624
0625 cmd_ptr = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
0626 cmd_ptr->command = cpu_to_le16(cmd_no);
0627 cmd_ptr->result = 0;
0628
0629
0630 if (cmd_no) {
0631 switch (cmd_no) {
0632 case HostCmd_CMD_UAP_SYS_CONFIG:
0633 case HostCmd_CMD_UAP_BSS_START:
0634 case HostCmd_CMD_UAP_BSS_STOP:
0635 case HostCmd_CMD_UAP_STA_DEAUTH:
0636 case HOST_CMD_APCMD_SYS_RESET:
0637 case HOST_CMD_APCMD_STA_LIST:
0638 ret = mwifiex_uap_prepare_cmd(priv, cmd_no, cmd_action,
0639 cmd_oid, data_buf,
0640 cmd_ptr);
0641 break;
0642 default:
0643 ret = mwifiex_sta_prepare_cmd(priv, cmd_no, cmd_action,
0644 cmd_oid, data_buf,
0645 cmd_ptr);
0646 break;
0647 }
0648 } else {
0649 ret = mwifiex_cmd_host_cmd(priv, cmd_ptr, data_buf);
0650 cmd_node->cmd_flag |= CMD_F_HOSTCMD;
0651 }
0652
0653
0654 if (ret) {
0655 mwifiex_dbg(adapter, ERROR,
0656 "PREP_CMD: cmd %#x preparation failed\n",
0657 cmd_no);
0658 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
0659 return -1;
0660 }
0661
0662
0663 if (cmd_no == HostCmd_CMD_802_11_SCAN ||
0664 cmd_no == HostCmd_CMD_802_11_SCAN_EXT) {
0665 mwifiex_queue_scan_cmd(priv, cmd_node);
0666 } else {
0667 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node);
0668 queue_work(adapter->workqueue, &adapter->main_work);
0669 if (cmd_node->wait_q_enabled)
0670 ret = mwifiex_wait_queue_complete(adapter, cmd_node);
0671 }
0672
0673 return ret;
0674 }
0675
0676
0677
0678
0679
0680
0681
0682
0683 void
0684 mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
0685 struct cmd_ctrl_node *cmd_node)
0686 {
0687 struct host_cmd_ds_command *host_cmd = NULL;
0688 u16 command;
0689 bool add_tail = true;
0690
0691 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
0692 if (!host_cmd) {
0693 mwifiex_dbg(adapter, ERROR, "QUEUE_CMD: host_cmd is NULL\n");
0694 return;
0695 }
0696
0697 command = le16_to_cpu(host_cmd->command);
0698
0699
0700 if (command == HostCmd_CMD_802_11_PS_MODE_ENH) {
0701 struct host_cmd_ds_802_11_ps_mode_enh *pm =
0702 &host_cmd->params.psmode_enh;
0703 if ((le16_to_cpu(pm->action) == DIS_PS) ||
0704 (le16_to_cpu(pm->action) == DIS_AUTO_PS)) {
0705 if (adapter->ps_state != PS_STATE_AWAKE)
0706 add_tail = false;
0707 }
0708 }
0709
0710
0711 if (command == HostCmd_CMD_802_11_HS_CFG_ENH) {
0712 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg =
0713 &host_cmd->params.opt_hs_cfg;
0714
0715 if (le16_to_cpu(hs_cfg->action) == HS_ACTIVATE)
0716 add_tail = false;
0717 }
0718
0719 spin_lock_bh(&adapter->cmd_pending_q_lock);
0720 if (add_tail)
0721 list_add_tail(&cmd_node->list, &adapter->cmd_pending_q);
0722 else
0723 list_add(&cmd_node->list, &adapter->cmd_pending_q);
0724 spin_unlock_bh(&adapter->cmd_pending_q_lock);
0725
0726 atomic_inc(&adapter->cmd_pending);
0727 mwifiex_dbg(adapter, CMD,
0728 "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
0729 command, atomic_read(&adapter->cmd_pending));
0730 }
0731
0732
0733
0734
0735
0736
0737
0738
0739
0740
0741
0742
0743 int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter)
0744 {
0745 struct mwifiex_private *priv;
0746 struct cmd_ctrl_node *cmd_node;
0747 int ret = 0;
0748 struct host_cmd_ds_command *host_cmd;
0749
0750
0751 if (adapter->curr_cmd) {
0752 mwifiex_dbg(adapter, FATAL,
0753 "EXEC_NEXT_CMD: cmd in processing\n");
0754 return -1;
0755 }
0756
0757 spin_lock_bh(&adapter->mwifiex_cmd_lock);
0758
0759 spin_lock_bh(&adapter->cmd_pending_q_lock);
0760 if (list_empty(&adapter->cmd_pending_q)) {
0761 spin_unlock_bh(&adapter->cmd_pending_q_lock);
0762 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
0763 return 0;
0764 }
0765 cmd_node = list_first_entry(&adapter->cmd_pending_q,
0766 struct cmd_ctrl_node, list);
0767
0768 host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
0769 priv = cmd_node->priv;
0770
0771 if (adapter->ps_state != PS_STATE_AWAKE) {
0772 mwifiex_dbg(adapter, ERROR,
0773 "%s: cannot send cmd in sleep state,\t"
0774 "this should not happen\n", __func__);
0775 spin_unlock_bh(&adapter->cmd_pending_q_lock);
0776 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
0777 return ret;
0778 }
0779
0780 list_del(&cmd_node->list);
0781 spin_unlock_bh(&adapter->cmd_pending_q_lock);
0782
0783 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
0784 ret = mwifiex_dnld_cmd_to_fw(priv, cmd_node);
0785 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
0786
0787
0788
0789
0790 if (priv && (host_cmd->command !=
0791 cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH))) {
0792 if (adapter->hs_activated) {
0793 clear_bit(MWIFIEX_IS_HS_CONFIGURED,
0794 &adapter->work_flags);
0795 mwifiex_hs_activated_event(priv, false);
0796 }
0797 }
0798
0799 return ret;
0800 }
0801
0802
0803
0804
0805
0806
0807
0808 int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
0809 {
0810 struct host_cmd_ds_command *resp;
0811 struct mwifiex_private *priv =
0812 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
0813 int ret = 0;
0814 uint16_t orig_cmdresp_no;
0815 uint16_t cmdresp_no;
0816 uint16_t cmdresp_result;
0817
0818 if (!adapter->curr_cmd || !adapter->curr_cmd->resp_skb) {
0819 resp = (struct host_cmd_ds_command *) adapter->upld_buf;
0820 mwifiex_dbg(adapter, ERROR,
0821 "CMD_RESP: NULL curr_cmd, %#x\n",
0822 le16_to_cpu(resp->command));
0823 return -1;
0824 }
0825
0826 resp = (struct host_cmd_ds_command *)adapter->curr_cmd->resp_skb->data;
0827 orig_cmdresp_no = le16_to_cpu(resp->command);
0828 cmdresp_no = (orig_cmdresp_no & HostCmd_CMD_ID_MASK);
0829
0830 if (adapter->curr_cmd->cmd_no != cmdresp_no) {
0831 mwifiex_dbg(adapter, ERROR,
0832 "cmdresp error: cmd=0x%x cmd_resp=0x%x\n",
0833 adapter->curr_cmd->cmd_no, cmdresp_no);
0834 return -1;
0835 }
0836
0837 del_timer_sync(&adapter->cmd_timer);
0838 clear_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags);
0839
0840 if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
0841
0842 struct mwifiex_ds_misc_cmd *hostcmd;
0843 uint16_t size = le16_to_cpu(resp->size);
0844 mwifiex_dbg(adapter, INFO,
0845 "info: host cmd resp size = %d\n", size);
0846 size = min_t(u16, size, MWIFIEX_SIZE_OF_CMD_BUFFER);
0847 if (adapter->curr_cmd->data_buf) {
0848 hostcmd = adapter->curr_cmd->data_buf;
0849 hostcmd->len = size;
0850 memcpy(hostcmd->cmd, resp, size);
0851 }
0852 }
0853
0854
0855 priv = mwifiex_get_priv_by_id(adapter,
0856 HostCmd_GET_BSS_NO(le16_to_cpu(resp->seq_num)),
0857 HostCmd_GET_BSS_TYPE(le16_to_cpu(resp->seq_num)));
0858 if (!priv)
0859 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
0860
0861 resp->command = cpu_to_le16(orig_cmdresp_no & HostCmd_CMD_ID_MASK);
0862
0863 cmdresp_no = le16_to_cpu(resp->command);
0864 cmdresp_result = le16_to_cpu(resp->result);
0865
0866
0867 adapter->dbg.last_cmd_resp_index =
0868 (adapter->dbg.last_cmd_resp_index + 1) % DBG_CMD_NUM;
0869 adapter->dbg.last_cmd_resp_id[adapter->dbg.last_cmd_resp_index] =
0870 orig_cmdresp_no;
0871
0872 mwifiex_dbg(adapter, CMD,
0873 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
0874 orig_cmdresp_no, cmdresp_result,
0875 le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num));
0876 mwifiex_dbg_dump(adapter, CMD_D, "CMD_RESP buffer:", resp,
0877 le16_to_cpu(resp->size));
0878
0879 if (!(orig_cmdresp_no & HostCmd_RET_BIT)) {
0880 mwifiex_dbg(adapter, ERROR, "CMD_RESP: invalid cmd resp\n");
0881 if (adapter->curr_cmd->wait_q_enabled)
0882 adapter->cmd_wait_q.status = -1;
0883
0884 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
0885 spin_lock_bh(&adapter->mwifiex_cmd_lock);
0886 adapter->curr_cmd = NULL;
0887 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
0888 return -1;
0889 }
0890
0891 if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
0892 adapter->curr_cmd->cmd_flag &= ~CMD_F_HOSTCMD;
0893 if ((cmdresp_result == HostCmd_RESULT_OK) &&
0894 (cmdresp_no == HostCmd_CMD_802_11_HS_CFG_ENH))
0895 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
0896 } else {
0897
0898 ret = mwifiex_process_sta_cmdresp(priv, cmdresp_no, resp);
0899 }
0900
0901
0902 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
0903 if (ret) {
0904 mwifiex_dbg(adapter, ERROR,
0905 "%s: cmd %#x failed during\t"
0906 "initialization\n", __func__, cmdresp_no);
0907 mwifiex_init_fw_complete(adapter);
0908 return -1;
0909 } else if (adapter->last_init_cmd == cmdresp_no)
0910 adapter->hw_status = MWIFIEX_HW_STATUS_INIT_DONE;
0911 }
0912
0913 if (adapter->curr_cmd) {
0914 if (adapter->curr_cmd->wait_q_enabled)
0915 adapter->cmd_wait_q.status = ret;
0916
0917 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
0918
0919 spin_lock_bh(&adapter->mwifiex_cmd_lock);
0920 adapter->curr_cmd = NULL;
0921 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
0922 }
0923
0924 return ret;
0925 }
0926
0927
0928
0929
0930
0931
0932 void
0933 mwifiex_cmd_timeout_func(struct timer_list *t)
0934 {
0935 struct mwifiex_adapter *adapter = from_timer(adapter, t, cmd_timer);
0936 struct cmd_ctrl_node *cmd_node;
0937
0938 set_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags);
0939 if (!adapter->curr_cmd) {
0940 mwifiex_dbg(adapter, ERROR,
0941 "cmd: empty curr_cmd\n");
0942 return;
0943 }
0944 cmd_node = adapter->curr_cmd;
0945 if (cmd_node) {
0946 adapter->dbg.timeout_cmd_id =
0947 adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index];
0948 adapter->dbg.timeout_cmd_act =
0949 adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index];
0950 mwifiex_dbg(adapter, MSG,
0951 "%s: Timeout cmd id = %#x, act = %#x\n", __func__,
0952 adapter->dbg.timeout_cmd_id,
0953 adapter->dbg.timeout_cmd_act);
0954
0955 mwifiex_dbg(adapter, MSG,
0956 "num_data_h2c_failure = %d\n",
0957 adapter->dbg.num_tx_host_to_card_failure);
0958 mwifiex_dbg(adapter, MSG,
0959 "num_cmd_h2c_failure = %d\n",
0960 adapter->dbg.num_cmd_host_to_card_failure);
0961
0962 mwifiex_dbg(adapter, MSG,
0963 "is_cmd_timedout = %d\n",
0964 test_bit(MWIFIEX_IS_CMD_TIMEDOUT,
0965 &adapter->work_flags));
0966 mwifiex_dbg(adapter, MSG,
0967 "num_tx_timeout = %d\n",
0968 adapter->dbg.num_tx_timeout);
0969
0970 mwifiex_dbg(adapter, MSG,
0971 "last_cmd_index = %d\n",
0972 adapter->dbg.last_cmd_index);
0973 mwifiex_dbg(adapter, MSG,
0974 "last_cmd_id: %*ph\n",
0975 (int)sizeof(adapter->dbg.last_cmd_id),
0976 adapter->dbg.last_cmd_id);
0977 mwifiex_dbg(adapter, MSG,
0978 "last_cmd_act: %*ph\n",
0979 (int)sizeof(adapter->dbg.last_cmd_act),
0980 adapter->dbg.last_cmd_act);
0981
0982 mwifiex_dbg(adapter, MSG,
0983 "last_cmd_resp_index = %d\n",
0984 adapter->dbg.last_cmd_resp_index);
0985 mwifiex_dbg(adapter, MSG,
0986 "last_cmd_resp_id: %*ph\n",
0987 (int)sizeof(adapter->dbg.last_cmd_resp_id),
0988 adapter->dbg.last_cmd_resp_id);
0989
0990 mwifiex_dbg(adapter, MSG,
0991 "last_event_index = %d\n",
0992 adapter->dbg.last_event_index);
0993 mwifiex_dbg(adapter, MSG,
0994 "last_event: %*ph\n",
0995 (int)sizeof(adapter->dbg.last_event),
0996 adapter->dbg.last_event);
0997
0998 mwifiex_dbg(adapter, MSG,
0999 "data_sent=%d cmd_sent=%d\n",
1000 adapter->data_sent, adapter->cmd_sent);
1001
1002 mwifiex_dbg(adapter, MSG,
1003 "ps_mode=%d ps_state=%d\n",
1004 adapter->ps_mode, adapter->ps_state);
1005
1006 if (cmd_node->wait_q_enabled) {
1007 adapter->cmd_wait_q.status = -ETIMEDOUT;
1008 mwifiex_cancel_pending_ioctl(adapter);
1009 }
1010 }
1011 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
1012 mwifiex_init_fw_complete(adapter);
1013 return;
1014 }
1015
1016 if (adapter->if_ops.device_dump)
1017 adapter->if_ops.device_dump(adapter);
1018
1019 if (adapter->if_ops.card_reset)
1020 adapter->if_ops.card_reset(adapter);
1021 }
1022
1023 void
1024 mwifiex_cancel_pending_scan_cmd(struct mwifiex_adapter *adapter)
1025 {
1026 struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
1027
1028
1029 spin_lock_bh(&adapter->scan_pending_q_lock);
1030 list_for_each_entry_safe(cmd_node, tmp_node,
1031 &adapter->scan_pending_q, list) {
1032 list_del(&cmd_node->list);
1033 cmd_node->wait_q_enabled = false;
1034 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
1035 }
1036 spin_unlock_bh(&adapter->scan_pending_q_lock);
1037 }
1038
1039
1040
1041
1042
1043
1044
1045
1046 void
1047 mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
1048 {
1049 struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
1050
1051 spin_lock_bh(&adapter->mwifiex_cmd_lock);
1052
1053 if ((adapter->curr_cmd) && (adapter->curr_cmd->wait_q_enabled)) {
1054 adapter->cmd_wait_q.status = -1;
1055 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1056 adapter->curr_cmd->wait_q_enabled = false;
1057
1058 }
1059
1060 spin_lock_bh(&adapter->cmd_pending_q_lock);
1061 list_for_each_entry_safe(cmd_node, tmp_node,
1062 &adapter->cmd_pending_q, list) {
1063 list_del(&cmd_node->list);
1064
1065 if (cmd_node->wait_q_enabled)
1066 adapter->cmd_wait_q.status = -1;
1067 mwifiex_recycle_cmd_node(adapter, cmd_node);
1068 }
1069 spin_unlock_bh(&adapter->cmd_pending_q_lock);
1070 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
1071
1072 mwifiex_cancel_scan(adapter);
1073 }
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085 static void
1086 mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
1087 {
1088 struct cmd_ctrl_node *cmd_node = NULL;
1089
1090 if ((adapter->curr_cmd) &&
1091 (adapter->curr_cmd->wait_q_enabled)) {
1092 spin_lock_bh(&adapter->mwifiex_cmd_lock);
1093 cmd_node = adapter->curr_cmd;
1094
1095
1096
1097
1098
1099
1100
1101
1102 adapter->curr_cmd = NULL;
1103 spin_unlock_bh(&adapter->mwifiex_cmd_lock);
1104
1105 mwifiex_recycle_cmd_node(adapter, cmd_node);
1106 }
1107
1108 mwifiex_cancel_scan(adapter);
1109 }
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120 void
1121 mwifiex_check_ps_cond(struct mwifiex_adapter *adapter)
1122 {
1123 if (!adapter->cmd_sent && !atomic_read(&adapter->tx_hw_pending) &&
1124 !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))
1125 mwifiex_dnld_sleep_confirm_cmd(adapter);
1126 else
1127 mwifiex_dbg(adapter, CMD,
1128 "cmd: Delay Sleep Confirm (%s%s%s%s)\n",
1129 (adapter->cmd_sent) ? "D" : "",
1130 atomic_read(&adapter->tx_hw_pending) ? "T" : "",
1131 (adapter->curr_cmd) ? "C" : "",
1132 (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
1133 }
1134
1135
1136
1137
1138
1139
1140 void
1141 mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated)
1142 {
1143 if (activated) {
1144 if (test_bit(MWIFIEX_IS_HS_CONFIGURED,
1145 &priv->adapter->work_flags)) {
1146 priv->adapter->hs_activated = true;
1147 mwifiex_update_rxreor_flags(priv->adapter,
1148 RXREOR_FORCE_NO_DROP);
1149 mwifiex_dbg(priv->adapter, EVENT,
1150 "event: hs_activated\n");
1151 priv->adapter->hs_activate_wait_q_woken = true;
1152 wake_up_interruptible(
1153 &priv->adapter->hs_activate_wait_q);
1154 } else {
1155 mwifiex_dbg(priv->adapter, EVENT,
1156 "event: HS not configured\n");
1157 }
1158 } else {
1159 mwifiex_dbg(priv->adapter, EVENT,
1160 "event: hs_deactivated\n");
1161 priv->adapter->hs_activated = false;
1162 }
1163 }
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
1176 struct host_cmd_ds_command *resp)
1177 {
1178 struct mwifiex_adapter *adapter = priv->adapter;
1179 struct host_cmd_ds_802_11_hs_cfg_enh *phs_cfg =
1180 &resp->params.opt_hs_cfg;
1181 uint32_t conditions = le32_to_cpu(phs_cfg->params.hs_config.conditions);
1182
1183 if (phs_cfg->action == cpu_to_le16(HS_ACTIVATE) &&
1184 adapter->iface_type != MWIFIEX_USB) {
1185 mwifiex_hs_activated_event(priv, true);
1186 return 0;
1187 } else {
1188 mwifiex_dbg(adapter, CMD,
1189 "cmd: CMD_RESP: HS_CFG cmd reply\t"
1190 " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
1191 resp->result, conditions,
1192 phs_cfg->params.hs_config.gpio,
1193 phs_cfg->params.hs_config.gap);
1194 }
1195 if (conditions != HS_CFG_CANCEL) {
1196 set_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
1197 if (adapter->iface_type == MWIFIEX_USB)
1198 mwifiex_hs_activated_event(priv, true);
1199 } else {
1200 clear_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
1201 if (adapter->hs_activated)
1202 mwifiex_hs_activated_event(priv, false);
1203 }
1204
1205 return 0;
1206 }
1207
1208
1209
1210
1211
1212 void
1213 mwifiex_process_hs_config(struct mwifiex_adapter *adapter)
1214 {
1215 mwifiex_dbg(adapter, INFO,
1216 "info: %s: auto cancelling host sleep\t"
1217 "since there is interrupt from the firmware\n",
1218 __func__);
1219
1220 adapter->if_ops.wakeup(adapter);
1221
1222 if (adapter->hs_activated_manually) {
1223 mwifiex_cancel_hs(mwifiex_get_priv (adapter, MWIFIEX_BSS_ROLE_ANY),
1224 MWIFIEX_ASYNC_CMD);
1225 adapter->hs_activated_manually = false;
1226 }
1227
1228 adapter->hs_activated = false;
1229 clear_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
1230 clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
1231 mwifiex_hs_activated_event(mwifiex_get_priv(adapter,
1232 MWIFIEX_BSS_ROLE_ANY),
1233 false);
1234 }
1235 EXPORT_SYMBOL_GPL(mwifiex_process_hs_config);
1236
1237
1238
1239
1240
1241
1242 void
1243 mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter,
1244 u8 *pbuf, u32 upld_len)
1245 {
1246 struct host_cmd_ds_command *cmd = (struct host_cmd_ds_command *) pbuf;
1247 struct mwifiex_private *priv =
1248 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1249 uint16_t result = le16_to_cpu(cmd->result);
1250 uint16_t command = le16_to_cpu(cmd->command);
1251 uint16_t seq_num = le16_to_cpu(cmd->seq_num);
1252
1253 if (!upld_len) {
1254 mwifiex_dbg(adapter, ERROR,
1255 "%s: cmd size is 0\n", __func__);
1256 return;
1257 }
1258
1259 mwifiex_dbg(adapter, CMD,
1260 "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
1261 command, result, le16_to_cpu(cmd->size), seq_num);
1262
1263
1264 priv = mwifiex_get_priv_by_id(adapter, HostCmd_GET_BSS_NO(seq_num),
1265 HostCmd_GET_BSS_TYPE(seq_num));
1266 if (!priv)
1267 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1268
1269
1270 seq_num = HostCmd_GET_SEQ_NO(seq_num);
1271
1272 command &= HostCmd_CMD_ID_MASK;
1273
1274 if (command != HostCmd_CMD_802_11_PS_MODE_ENH) {
1275 mwifiex_dbg(adapter, ERROR,
1276 "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
1277 __func__, command, result);
1278 return;
1279 }
1280
1281 if (result) {
1282 mwifiex_dbg(adapter, ERROR,
1283 "%s: sleep confirm cmd failed\n",
1284 __func__);
1285 adapter->pm_wakeup_card_req = false;
1286 adapter->ps_state = PS_STATE_AWAKE;
1287 return;
1288 }
1289 adapter->pm_wakeup_card_req = true;
1290 if (test_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags))
1291 mwifiex_hs_activated_event(mwifiex_get_priv
1292 (adapter, MWIFIEX_BSS_ROLE_ANY),
1293 true);
1294 adapter->ps_state = PS_STATE_SLEEP;
1295 cmd->command = cpu_to_le16(command);
1296 cmd->seq_num = cpu_to_le16(seq_num);
1297 }
1298 EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp);
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312 int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
1313 struct host_cmd_ds_command *cmd,
1314 u16 cmd_action, uint16_t ps_bitmap,
1315 struct mwifiex_ds_auto_ds *auto_ds)
1316 {
1317 struct host_cmd_ds_802_11_ps_mode_enh *psmode_enh =
1318 &cmd->params.psmode_enh;
1319 u8 *tlv;
1320 u16 cmd_size = 0;
1321
1322 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
1323 if (cmd_action == DIS_AUTO_PS) {
1324 psmode_enh->action = cpu_to_le16(DIS_AUTO_PS);
1325 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1326 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
1327 sizeof(psmode_enh->params.ps_bitmap));
1328 } else if (cmd_action == GET_PS) {
1329 psmode_enh->action = cpu_to_le16(GET_PS);
1330 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1331 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
1332 sizeof(psmode_enh->params.ps_bitmap));
1333 } else if (cmd_action == EN_AUTO_PS) {
1334 psmode_enh->action = cpu_to_le16(EN_AUTO_PS);
1335 psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
1336 cmd_size = S_DS_GEN + sizeof(psmode_enh->action) +
1337 sizeof(psmode_enh->params.ps_bitmap);
1338 tlv = (u8 *) cmd + cmd_size;
1339 if (ps_bitmap & BITMAP_STA_PS) {
1340 struct mwifiex_adapter *adapter = priv->adapter;
1341 struct mwifiex_ie_types_ps_param *ps_tlv =
1342 (struct mwifiex_ie_types_ps_param *) tlv;
1343 struct mwifiex_ps_param *ps_mode = &ps_tlv->param;
1344 ps_tlv->header.type = cpu_to_le16(TLV_TYPE_PS_PARAM);
1345 ps_tlv->header.len = cpu_to_le16(sizeof(*ps_tlv) -
1346 sizeof(struct mwifiex_ie_types_header));
1347 cmd_size += sizeof(*ps_tlv);
1348 tlv += sizeof(*ps_tlv);
1349 mwifiex_dbg(priv->adapter, CMD,
1350 "cmd: PS Command: Enter PS\n");
1351 ps_mode->null_pkt_interval =
1352 cpu_to_le16(adapter->null_pkt_interval);
1353 ps_mode->multiple_dtims =
1354 cpu_to_le16(adapter->multiple_dtim);
1355 ps_mode->bcn_miss_timeout =
1356 cpu_to_le16(adapter->bcn_miss_time_out);
1357 ps_mode->local_listen_interval =
1358 cpu_to_le16(adapter->local_listen_interval);
1359 ps_mode->adhoc_wake_period =
1360 cpu_to_le16(adapter->adhoc_awake_period);
1361 ps_mode->delay_to_ps =
1362 cpu_to_le16(adapter->delay_to_ps);
1363 ps_mode->mode = cpu_to_le16(adapter->enhanced_ps_mode);
1364
1365 }
1366 if (ps_bitmap & BITMAP_AUTO_DS) {
1367 struct mwifiex_ie_types_auto_ds_param *auto_ds_tlv =
1368 (struct mwifiex_ie_types_auto_ds_param *) tlv;
1369 u16 idletime = 0;
1370
1371 auto_ds_tlv->header.type =
1372 cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM);
1373 auto_ds_tlv->header.len =
1374 cpu_to_le16(sizeof(*auto_ds_tlv) -
1375 sizeof(struct mwifiex_ie_types_header));
1376 cmd_size += sizeof(*auto_ds_tlv);
1377 tlv += sizeof(*auto_ds_tlv);
1378 if (auto_ds)
1379 idletime = auto_ds->idle_time;
1380 mwifiex_dbg(priv->adapter, CMD,
1381 "cmd: PS Command: Enter Auto Deep Sleep\n");
1382 auto_ds_tlv->deep_sleep_timeout = cpu_to_le16(idletime);
1383 }
1384 cmd->size = cpu_to_le16(cmd_size);
1385 }
1386 return 0;
1387 }
1388
1389
1390
1391
1392
1393
1394
1395
1396 int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
1397 struct host_cmd_ds_command *resp,
1398 struct mwifiex_ds_pm_cfg *pm_cfg)
1399 {
1400 struct mwifiex_adapter *adapter = priv->adapter;
1401 struct host_cmd_ds_802_11_ps_mode_enh *ps_mode =
1402 &resp->params.psmode_enh;
1403 uint16_t action = le16_to_cpu(ps_mode->action);
1404 uint16_t ps_bitmap = le16_to_cpu(ps_mode->params.ps_bitmap);
1405 uint16_t auto_ps_bitmap =
1406 le16_to_cpu(ps_mode->params.ps_bitmap);
1407
1408 mwifiex_dbg(adapter, INFO,
1409 "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
1410 __func__, resp->result, action);
1411 if (action == EN_AUTO_PS) {
1412 if (auto_ps_bitmap & BITMAP_AUTO_DS) {
1413 mwifiex_dbg(adapter, CMD,
1414 "cmd: Enabled auto deep sleep\n");
1415 priv->adapter->is_deep_sleep = true;
1416 }
1417 if (auto_ps_bitmap & BITMAP_STA_PS) {
1418 mwifiex_dbg(adapter, CMD,
1419 "cmd: Enabled STA power save\n");
1420 if (adapter->sleep_period.period)
1421 mwifiex_dbg(adapter, CMD,
1422 "cmd: set to uapsd/pps mode\n");
1423 }
1424 } else if (action == DIS_AUTO_PS) {
1425 if (ps_bitmap & BITMAP_AUTO_DS) {
1426 priv->adapter->is_deep_sleep = false;
1427 mwifiex_dbg(adapter, CMD,
1428 "cmd: Disabled auto deep sleep\n");
1429 }
1430 if (ps_bitmap & BITMAP_STA_PS) {
1431 mwifiex_dbg(adapter, CMD,
1432 "cmd: Disabled STA power save\n");
1433 if (adapter->sleep_period.period) {
1434 adapter->delay_null_pkt = false;
1435 adapter->tx_lock_flag = false;
1436 adapter->pps_uapsd_mode = false;
1437 }
1438 }
1439 } else if (action == GET_PS) {
1440 if (ps_bitmap & BITMAP_STA_PS)
1441 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
1442 else
1443 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
1444
1445 mwifiex_dbg(adapter, CMD,
1446 "cmd: ps_bitmap=%#x\n", ps_bitmap);
1447
1448 if (pm_cfg) {
1449
1450 if (ps_bitmap & BITMAP_STA_PS)
1451 pm_cfg->param.ps_mode = 1;
1452 else
1453 pm_cfg->param.ps_mode = 0;
1454 }
1455 }
1456 return 0;
1457 }
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467 int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv,
1468 struct host_cmd_ds_command *cmd)
1469 {
1470 struct host_cmd_ds_get_hw_spec *hw_spec = &cmd->params.hw_spec;
1471
1472 cmd->command = cpu_to_le16(HostCmd_CMD_GET_HW_SPEC);
1473 cmd->size =
1474 cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec) + S_DS_GEN);
1475 memcpy(hw_spec->permanent_addr, priv->curr_addr, ETH_ALEN);
1476
1477 return 0;
1478 }
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500 int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
1501 struct host_cmd_ds_command *resp)
1502 {
1503 struct host_cmd_ds_get_hw_spec *hw_spec = &resp->params.hw_spec;
1504 struct mwifiex_adapter *adapter = priv->adapter;
1505 struct mwifiex_ie_types_header *tlv;
1506 struct hw_spec_api_rev *api_rev;
1507 struct hw_spec_max_conn *max_conn;
1508 u16 resp_size, api_id;
1509 int i, left_len, parsed_len = 0;
1510
1511 adapter->fw_cap_info = le32_to_cpu(hw_spec->fw_cap_info);
1512
1513 if (IS_SUPPORT_MULTI_BANDS(adapter))
1514 adapter->fw_bands = (u8) GET_FW_DEFAULT_BANDS(adapter);
1515 else
1516 adapter->fw_bands = BAND_B;
1517
1518 adapter->config_bands = adapter->fw_bands;
1519
1520 if (adapter->fw_bands & BAND_A) {
1521 if (adapter->fw_bands & BAND_GN) {
1522 adapter->config_bands |= BAND_AN;
1523 adapter->fw_bands |= BAND_AN;
1524 }
1525 if (adapter->fw_bands & BAND_AN) {
1526 adapter->adhoc_start_band = BAND_A | BAND_AN;
1527 adapter->adhoc_11n_enabled = true;
1528 } else {
1529 adapter->adhoc_start_band = BAND_A;
1530 }
1531 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL_A;
1532 } else if (adapter->fw_bands & BAND_GN) {
1533 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
1534 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1535 adapter->adhoc_11n_enabled = true;
1536 } else if (adapter->fw_bands & BAND_G) {
1537 adapter->adhoc_start_band = BAND_G | BAND_B;
1538 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1539 } else if (adapter->fw_bands & BAND_B) {
1540 adapter->adhoc_start_band = BAND_B;
1541 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
1542 }
1543
1544 adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number);
1545 adapter->fw_api_ver = (adapter->fw_release_number >> 16) & 0xff;
1546 adapter->number_of_antenna =
1547 le16_to_cpu(hw_spec->number_of_antenna) & 0xf;
1548
1549 if (le32_to_cpu(hw_spec->dot_11ac_dev_cap)) {
1550 adapter->is_hw_11ac_capable = true;
1551
1552
1553 adapter->hw_dot_11ac_dev_cap =
1554 le32_to_cpu(hw_spec->dot_11ac_dev_cap);
1555 adapter->usr_dot_11ac_dev_cap_bg = adapter->hw_dot_11ac_dev_cap
1556 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK;
1557 adapter->usr_dot_11ac_dev_cap_a = adapter->hw_dot_11ac_dev_cap
1558 & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK;
1559
1560
1561 adapter->hw_dot_11ac_mcs_support =
1562 le32_to_cpu(hw_spec->dot_11ac_mcs_support);
1563 adapter->usr_dot_11ac_mcs_support =
1564 adapter->hw_dot_11ac_mcs_support;
1565 } else {
1566 adapter->is_hw_11ac_capable = false;
1567 }
1568
1569 resp_size = le16_to_cpu(resp->size) - S_DS_GEN;
1570 if (resp_size > sizeof(struct host_cmd_ds_get_hw_spec)) {
1571
1572 left_len = resp_size - sizeof(struct host_cmd_ds_get_hw_spec);
1573 while (left_len > sizeof(struct mwifiex_ie_types_header)) {
1574 tlv = (void *)&hw_spec->tlvs + parsed_len;
1575 switch (le16_to_cpu(tlv->type)) {
1576 case TLV_TYPE_API_REV:
1577 api_rev = (struct hw_spec_api_rev *)tlv;
1578 api_id = le16_to_cpu(api_rev->api_id);
1579 switch (api_id) {
1580 case KEY_API_VER_ID:
1581 adapter->key_api_major_ver =
1582 api_rev->major_ver;
1583 adapter->key_api_minor_ver =
1584 api_rev->minor_ver;
1585 mwifiex_dbg(adapter, INFO,
1586 "key_api v%d.%d\n",
1587 adapter->key_api_major_ver,
1588 adapter->key_api_minor_ver);
1589 break;
1590 case FW_API_VER_ID:
1591 adapter->fw_api_ver =
1592 api_rev->major_ver;
1593 mwifiex_dbg(adapter, INFO,
1594 "Firmware api version %d.%d\n",
1595 adapter->fw_api_ver,
1596 api_rev->minor_ver);
1597 break;
1598 case UAP_FW_API_VER_ID:
1599 mwifiex_dbg(adapter, INFO,
1600 "uAP api version %d.%d\n",
1601 api_rev->major_ver,
1602 api_rev->minor_ver);
1603 break;
1604 case CHANRPT_API_VER_ID:
1605 mwifiex_dbg(adapter, INFO,
1606 "channel report api version %d.%d\n",
1607 api_rev->major_ver,
1608 api_rev->minor_ver);
1609 break;
1610 default:
1611 mwifiex_dbg(adapter, FATAL,
1612 "Unknown api_id: %d\n",
1613 api_id);
1614 break;
1615 }
1616 break;
1617 case TLV_TYPE_MAX_CONN:
1618 max_conn = (struct hw_spec_max_conn *)tlv;
1619 adapter->max_p2p_conn = max_conn->max_p2p_conn;
1620 adapter->max_sta_conn = max_conn->max_sta_conn;
1621 mwifiex_dbg(adapter, INFO,
1622 "max p2p connections: %u\n",
1623 adapter->max_p2p_conn);
1624 mwifiex_dbg(adapter, INFO,
1625 "max sta connections: %u\n",
1626 adapter->max_sta_conn);
1627 break;
1628 default:
1629 mwifiex_dbg(adapter, FATAL,
1630 "Unknown GET_HW_SPEC TLV type: %#x\n",
1631 le16_to_cpu(tlv->type));
1632 break;
1633 }
1634 parsed_len += le16_to_cpu(tlv->len) +
1635 sizeof(struct mwifiex_ie_types_header);
1636 left_len -= le16_to_cpu(tlv->len) +
1637 sizeof(struct mwifiex_ie_types_header);
1638 }
1639 }
1640
1641 mwifiex_dbg(adapter, INFO,
1642 "info: GET_HW_SPEC: fw_release_number- %#x\n",
1643 adapter->fw_release_number);
1644 mwifiex_dbg(adapter, INFO,
1645 "info: GET_HW_SPEC: permanent addr: %pM\n",
1646 hw_spec->permanent_addr);
1647 mwifiex_dbg(adapter, INFO,
1648 "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
1649 le16_to_cpu(hw_spec->hw_if_version),
1650 le16_to_cpu(hw_spec->version));
1651
1652 ether_addr_copy(priv->adapter->perm_addr, hw_spec->permanent_addr);
1653 adapter->region_code = le16_to_cpu(hw_spec->region_code);
1654
1655 for (i = 0; i < MWIFIEX_MAX_REGION_CODE; i++)
1656
1657 if (adapter->region_code == region_code_index[i])
1658 break;
1659
1660
1661 if (i >= MWIFIEX_MAX_REGION_CODE) {
1662 adapter->region_code = 0x00;
1663 mwifiex_dbg(adapter, WARN,
1664 "cmd: unknown region code, use default (USA)\n");
1665 }
1666
1667 adapter->hw_dot_11n_dev_cap = le32_to_cpu(hw_spec->dot_11n_dev_cap);
1668 adapter->hw_dev_mcs_support = hw_spec->dev_mcs_support;
1669 adapter->user_dev_mcs_support = adapter->hw_dev_mcs_support;
1670
1671 if (adapter->if_ops.update_mp_end_port)
1672 adapter->if_ops.update_mp_end_port(adapter,
1673 le16_to_cpu(hw_spec->mp_end_port));
1674
1675 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
1676 adapter->scan_chan_gap_enabled = true;
1677
1678 return 0;
1679 }
1680
1681
1682
1683
1684 int mwifiex_ret_wakeup_reason(struct mwifiex_private *priv,
1685 struct host_cmd_ds_command *resp,
1686 struct host_cmd_ds_wakeup_reason *wakeup_reason)
1687 {
1688 wakeup_reason->wakeup_reason =
1689 resp->params.hs_wakeup_reason.wakeup_reason;
1690
1691 return 0;
1692 }