Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: commands and events |
| 3 | * |
Xinming Hu | 65da33f | 2014-06-19 21:38:57 -0700 | [diff] [blame] | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include "decl.h" |
| 21 | #include "ioctl.h" |
| 22 | #include "util.h" |
| 23 | #include "fw.h" |
| 24 | #include "main.h" |
| 25 | #include "wmm.h" |
| 26 | #include "11n.h" |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 27 | #include "11ac.h" |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * This function initializes a command node. |
| 31 | * |
| 32 | * The actual allocation of the node is not done by this function. It only |
| 33 | * initiates a node by filling it with default parameters. Similarly, |
| 34 | * allocation of the different buffers used (IOCTL buffer, data buffer) are |
| 35 | * not done by this function either. |
| 36 | */ |
| 37 | static void |
| 38 | mwifiex_init_cmd_node(struct mwifiex_private *priv, |
| 39 | struct cmd_ctrl_node *cmd_node, |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 40 | u32 cmd_oid, void *data_buf, bool sync) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 41 | { |
| 42 | cmd_node->priv = priv; |
| 43 | cmd_node->cmd_oid = cmd_oid; |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 44 | if (sync) { |
| 45 | cmd_node->wait_q_enabled = true; |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 46 | cmd_node->cmd_wait_q_woken = false; |
| 47 | cmd_node->condition = &cmd_node->cmd_wait_q_woken; |
| 48 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 49 | cmd_node->data_buf = data_buf; |
| 50 | cmd_node->cmd_skb = cmd_node->skb; |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * This function returns a command node from the free queue depending upon |
| 55 | * availability. |
| 56 | */ |
| 57 | static struct cmd_ctrl_node * |
| 58 | mwifiex_get_cmd_node(struct mwifiex_adapter *adapter) |
| 59 | { |
| 60 | struct cmd_ctrl_node *cmd_node; |
| 61 | unsigned long flags; |
| 62 | |
| 63 | spin_lock_irqsave(&adapter->cmd_free_q_lock, flags); |
| 64 | if (list_empty(&adapter->cmd_free_q)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 65 | mwifiex_dbg(adapter, ERROR, |
| 66 | "GET_CMD_NODE: cmd node not available\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 67 | spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags); |
| 68 | return NULL; |
| 69 | } |
| 70 | cmd_node = list_first_entry(&adapter->cmd_free_q, |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 71 | struct cmd_ctrl_node, list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 72 | list_del(&cmd_node->list); |
| 73 | spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags); |
| 74 | |
| 75 | return cmd_node; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * This function cleans up a command node. |
| 80 | * |
| 81 | * The function resets the fields including the buffer pointers. |
| 82 | * This function does not try to free the buffers. They must be |
| 83 | * freed before calling this function. |
| 84 | * |
| 85 | * This function will however call the receive completion callback |
| 86 | * in case a response buffer is still available before resetting |
| 87 | * the pointer. |
| 88 | */ |
| 89 | static void |
| 90 | mwifiex_clean_cmd_node(struct mwifiex_adapter *adapter, |
| 91 | struct cmd_ctrl_node *cmd_node) |
| 92 | { |
| 93 | cmd_node->cmd_oid = 0; |
| 94 | cmd_node->cmd_flag = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 95 | cmd_node->data_buf = NULL; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 96 | cmd_node->wait_q_enabled = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 97 | |
Amitkumar Karwar | 5cf8099 | 2011-09-21 21:43:25 -0700 | [diff] [blame] | 98 | if (cmd_node->cmd_skb) |
| 99 | skb_trim(cmd_node->cmd_skb, 0); |
| 100 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 101 | if (cmd_node->resp_skb) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 102 | adapter->if_ops.cmdrsp_complete(adapter, cmd_node->resp_skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 103 | cmd_node->resp_skb = NULL; |
| 104 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
Andreas Fenkart | 85abfb1 | 2016-03-10 09:44:11 +0100 | [diff] [blame] | 108 | * This function returns a command to the command free queue. |
| 109 | * |
| 110 | * The function also calls the completion callback if required, before |
| 111 | * cleaning the command node and re-inserting it into the free queue. |
| 112 | */ |
| 113 | static void |
| 114 | mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter, |
| 115 | struct cmd_ctrl_node *cmd_node) |
| 116 | { |
| 117 | unsigned long flags; |
| 118 | |
| 119 | if (!cmd_node) |
| 120 | return; |
| 121 | |
| 122 | if (cmd_node->wait_q_enabled) |
| 123 | mwifiex_complete_cmd(adapter, cmd_node); |
| 124 | /* Clean the node */ |
| 125 | mwifiex_clean_cmd_node(adapter, cmd_node); |
| 126 | |
| 127 | /* Insert node into cmd_free_q */ |
| 128 | spin_lock_irqsave(&adapter->cmd_free_q_lock, flags); |
| 129 | list_add_tail(&cmd_node->list, &adapter->cmd_free_q); |
| 130 | spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags); |
| 131 | } |
| 132 | |
| 133 | /* This function reuses a command node. */ |
| 134 | void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter, |
| 135 | struct cmd_ctrl_node *cmd_node) |
| 136 | { |
| 137 | struct host_cmd_ds_command *host_cmd = (void *)cmd_node->cmd_skb->data; |
| 138 | |
| 139 | mwifiex_insert_cmd_to_free_q(adapter, cmd_node); |
| 140 | |
| 141 | atomic_dec(&adapter->cmd_pending); |
| 142 | mwifiex_dbg(adapter, CMD, |
| 143 | "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n", |
| 144 | le16_to_cpu(host_cmd->command), |
| 145 | atomic_read(&adapter->cmd_pending)); |
| 146 | } |
| 147 | |
| 148 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 149 | * This function sends a host command to the firmware. |
| 150 | * |
| 151 | * The function copies the host command into the driver command |
| 152 | * buffer, which will be transferred to the firmware later by the |
| 153 | * main thread. |
| 154 | */ |
| 155 | static int mwifiex_cmd_host_cmd(struct mwifiex_private *priv, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 156 | struct host_cmd_ds_command *cmd, |
| 157 | struct mwifiex_ds_misc_cmd *pcmd_ptr) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 158 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 159 | /* Copy the HOST command to command buffer */ |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 160 | memcpy(cmd, pcmd_ptr->cmd, pcmd_ptr->len); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 161 | mwifiex_dbg(priv->adapter, CMD, |
| 162 | "cmd: host cmd size = %d\n", pcmd_ptr->len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * This function downloads a command to the firmware. |
| 168 | * |
| 169 | * The function performs sanity tests, sets the command sequence |
| 170 | * number and size, converts the header fields to CPU format before |
| 171 | * sending. Afterwards, it logs the command ID and action for debugging |
| 172 | * and sets up the command timeout timer. |
| 173 | */ |
| 174 | static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv, |
| 175 | struct cmd_ctrl_node *cmd_node) |
| 176 | { |
| 177 | |
| 178 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 179 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 180 | struct host_cmd_ds_command *host_cmd; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 181 | uint16_t cmd_code; |
| 182 | uint16_t cmd_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 183 | unsigned long flags; |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 184 | __le32 tmp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 185 | |
| 186 | if (!adapter || !cmd_node) |
| 187 | return -1; |
| 188 | |
| 189 | host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 190 | |
| 191 | /* Sanity test */ |
| 192 | if (host_cmd == NULL || host_cmd->size == 0) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 193 | mwifiex_dbg(adapter, ERROR, |
| 194 | "DNLD_CMD: host_cmd is null\t" |
| 195 | "or cmd size is 0, not sending\n"); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 196 | if (cmd_node->wait_q_enabled) |
| 197 | adapter->cmd_wait_q.status = -1; |
Bing Zhao | 9908b07 | 2013-04-01 12:44:46 -0700 | [diff] [blame] | 198 | mwifiex_recycle_cmd_node(adapter, cmd_node); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 199 | return -1; |
| 200 | } |
| 201 | |
Bing Zhao | a3e240c | 2013-03-15 18:47:06 -0700 | [diff] [blame] | 202 | cmd_code = le16_to_cpu(host_cmd->command); |
| 203 | cmd_size = le16_to_cpu(host_cmd->size); |
| 204 | |
| 205 | if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET && |
| 206 | cmd_code != HostCmd_CMD_FUNC_SHUTDOWN && |
| 207 | cmd_code != HostCmd_CMD_FUNC_INIT) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 208 | mwifiex_dbg(adapter, ERROR, |
| 209 | "DNLD_CMD: FW in reset state, ignore cmd %#x\n", |
Bing Zhao | a3e240c | 2013-03-15 18:47:06 -0700 | [diff] [blame] | 210 | cmd_code); |
Bing Zhao | 9908b07 | 2013-04-01 12:44:46 -0700 | [diff] [blame] | 211 | mwifiex_recycle_cmd_node(adapter, cmd_node); |
Amitkumar Karwar | ace2735 | 2014-02-27 19:35:16 -0800 | [diff] [blame] | 212 | queue_work(adapter->workqueue, &adapter->main_work); |
Bing Zhao | a3e240c | 2013-03-15 18:47:06 -0700 | [diff] [blame] | 213 | return -1; |
| 214 | } |
| 215 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 216 | /* Set command sequence number */ |
| 217 | adapter->seq_num++; |
| 218 | host_cmd->seq_num = cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 219 | (adapter->seq_num, |
| 220 | cmd_node->priv->bss_num, |
| 221 | cmd_node->priv->bss_type)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 222 | |
| 223 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 224 | adapter->curr_cmd = cmd_node; |
| 225 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 226 | |
Stone Piao | da25186 | 2012-08-22 20:26:31 -0700 | [diff] [blame] | 227 | /* Adjust skb length */ |
| 228 | if (cmd_node->cmd_skb->len > cmd_size) |
| 229 | /* |
| 230 | * cmd_size is less than sizeof(struct host_cmd_ds_command). |
| 231 | * Trim off the unused portion. |
| 232 | */ |
| 233 | skb_trim(cmd_node->cmd_skb, cmd_size); |
| 234 | else if (cmd_node->cmd_skb->len < cmd_size) |
| 235 | /* |
| 236 | * cmd_size is larger than sizeof(struct host_cmd_ds_command) |
| 237 | * because we have appended custom IE TLV. Increase skb length |
| 238 | * accordingly. |
| 239 | */ |
| 240 | skb_put(cmd_node->cmd_skb, cmd_size - cmd_node->cmd_skb->len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 241 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 242 | mwifiex_dbg(adapter, CMD, |
| 243 | "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n", |
| 244 | cmd_code, |
| 245 | le16_to_cpu(*(__le16 *)((u8 *)host_cmd + S_DS_GEN)), |
| 246 | cmd_size, le16_to_cpu(host_cmd->seq_num)); |
Zhaoyang Liu | 868093a | 2015-05-12 00:48:19 +0530 | [diff] [blame] | 247 | mwifiex_dbg_dump(adapter, CMD_D, "cmd buffer:", host_cmd, cmd_size); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 248 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 249 | if (adapter->iface_type == MWIFIEX_USB) { |
| 250 | tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD); |
| 251 | skb_push(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN); |
| 252 | memcpy(cmd_node->cmd_skb->data, &tmp, MWIFIEX_TYPE_LEN); |
| 253 | adapter->cmd_sent = true; |
| 254 | ret = adapter->if_ops.host_to_card(adapter, |
| 255 | MWIFIEX_USB_EP_CMD_EVENT, |
| 256 | cmd_node->cmd_skb, NULL); |
| 257 | skb_pull(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN); |
| 258 | if (ret == -EBUSY) |
| 259 | cmd_node->cmd_skb = NULL; |
| 260 | } else { |
| 261 | skb_push(cmd_node->cmd_skb, INTF_HEADER_LEN); |
| 262 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD, |
| 263 | cmd_node->cmd_skb, NULL); |
| 264 | skb_pull(cmd_node->cmd_skb, INTF_HEADER_LEN); |
| 265 | } |
Bing Zhao | 18bf965 | 2011-04-06 16:46:55 -0700 | [diff] [blame] | 266 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 267 | if (ret == -1) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 268 | mwifiex_dbg(adapter, ERROR, |
| 269 | "DNLD_CMD: host to card failed\n"); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 270 | if (adapter->iface_type == MWIFIEX_USB) |
| 271 | adapter->cmd_sent = false; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 272 | if (cmd_node->wait_q_enabled) |
| 273 | adapter->cmd_wait_q.status = -1; |
Bing Zhao | 9908b07 | 2013-04-01 12:44:46 -0700 | [diff] [blame] | 274 | mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 275 | |
| 276 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 277 | adapter->curr_cmd = NULL; |
| 278 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 279 | |
| 280 | adapter->dbg.num_cmd_host_to_card_failure++; |
| 281 | return -1; |
| 282 | } |
| 283 | |
| 284 | /* Save the last command id and action to debug log */ |
| 285 | adapter->dbg.last_cmd_index = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 286 | (adapter->dbg.last_cmd_index + 1) % DBG_CMD_NUM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 287 | adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index] = cmd_code; |
| 288 | adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index] = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 289 | le16_to_cpu(*(__le16 *) ((u8 *) host_cmd + S_DS_GEN)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 290 | |
| 291 | /* Clear BSS_NO_BITS from HostCmd */ |
| 292 | cmd_code &= HostCmd_CMD_ID_MASK; |
| 293 | |
| 294 | /* Setup the timer after transmit command */ |
| 295 | mod_timer(&adapter->cmd_timer, |
Bing Zhao | 4587eea | 2013-04-19 17:44:44 -0700 | [diff] [blame] | 296 | jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * This function downloads a sleep confirm command to the firmware. |
| 303 | * |
| 304 | * The function performs sanity tests, sets the command sequence |
| 305 | * number and size, converts the header fields to CPU format before |
| 306 | * sending. |
| 307 | * |
| 308 | * No responses are needed for sleep confirm command. |
| 309 | */ |
| 310 | static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter) |
| 311 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 312 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 313 | struct mwifiex_private *priv; |
Amitkumar Karwar | 7cc5eb6 | 2011-05-09 19:00:18 -0700 | [diff] [blame] | 314 | struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = |
| 315 | (struct mwifiex_opt_sleep_confirm *) |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 316 | adapter->sleep_cfm->data; |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 317 | struct sk_buff *sleep_cfm_tmp; |
| 318 | __le32 tmp; |
| 319 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 320 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 321 | |
Amitkumar Karwar | b49f639 | 2014-03-25 19:01:19 -0700 | [diff] [blame] | 322 | adapter->seq_num++; |
Amitkumar Karwar | 7cc5eb6 | 2011-05-09 19:00:18 -0700 | [diff] [blame] | 323 | sleep_cfm_buf->seq_num = |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 324 | cpu_to_le16((HostCmd_SET_SEQ_NO_BSS_INFO |
| 325 | (adapter->seq_num, priv->bss_num, |
| 326 | priv->bss_type))); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 327 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 328 | mwifiex_dbg(adapter, CMD, |
| 329 | "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n", |
Bing Zhao | 1d9e954 | 2014-07-17 15:55:09 -0700 | [diff] [blame] | 330 | le16_to_cpu(sleep_cfm_buf->command), |
Bing Zhao | 363c1b4 | 2014-06-19 21:38:58 -0700 | [diff] [blame] | 331 | le16_to_cpu(sleep_cfm_buf->action), |
| 332 | le16_to_cpu(sleep_cfm_buf->size), |
| 333 | le16_to_cpu(sleep_cfm_buf->seq_num)); |
Zhaoyang Liu | 868093a | 2015-05-12 00:48:19 +0530 | [diff] [blame] | 334 | mwifiex_dbg_dump(adapter, CMD_D, "SLEEP_CFM buffer: ", sleep_cfm_buf, |
| 335 | le16_to_cpu(sleep_cfm_buf->size)); |
Bing Zhao | 363c1b4 | 2014-06-19 21:38:58 -0700 | [diff] [blame] | 336 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 337 | if (adapter->iface_type == MWIFIEX_USB) { |
| 338 | sleep_cfm_tmp = |
| 339 | dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm) |
| 340 | + MWIFIEX_TYPE_LEN); |
| 341 | skb_put(sleep_cfm_tmp, sizeof(struct mwifiex_opt_sleep_confirm) |
| 342 | + MWIFIEX_TYPE_LEN); |
| 343 | tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD); |
| 344 | memcpy(sleep_cfm_tmp->data, &tmp, MWIFIEX_TYPE_LEN); |
| 345 | memcpy(sleep_cfm_tmp->data + MWIFIEX_TYPE_LEN, |
| 346 | adapter->sleep_cfm->data, |
| 347 | sizeof(struct mwifiex_opt_sleep_confirm)); |
| 348 | ret = adapter->if_ops.host_to_card(adapter, |
| 349 | MWIFIEX_USB_EP_CMD_EVENT, |
| 350 | sleep_cfm_tmp, NULL); |
| 351 | if (ret != -EBUSY) |
| 352 | dev_kfree_skb_any(sleep_cfm_tmp); |
| 353 | } else { |
| 354 | skb_push(adapter->sleep_cfm, INTF_HEADER_LEN); |
| 355 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD, |
| 356 | adapter->sleep_cfm, NULL); |
| 357 | skb_pull(adapter->sleep_cfm, INTF_HEADER_LEN); |
| 358 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 359 | |
| 360 | if (ret == -1) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 361 | mwifiex_dbg(adapter, ERROR, "SLEEP_CFM: failed\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 362 | adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure++; |
| 363 | return -1; |
| 364 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 365 | |
Avinash Patil | 76c504c | 2015-01-28 15:42:04 +0530 | [diff] [blame] | 366 | if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl)) |
| 367 | /* Response is not needed for sleep confirm command */ |
| 368 | adapter->ps_state = PS_STATE_SLEEP; |
| 369 | else |
| 370 | adapter->ps_state = PS_STATE_SLEEP_CFM; |
| 371 | |
| 372 | if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl) && |
| 373 | (adapter->is_hs_configured && |
| 374 | !adapter->sleep_period.period)) { |
| 375 | adapter->pm_wakeup_card_req = true; |
| 376 | mwifiex_hs_activated_event(mwifiex_get_priv |
| 377 | (adapter, MWIFIEX_BSS_ROLE_ANY), true); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | return ret; |
| 381 | } |
| 382 | |
| 383 | /* |
| 384 | * This function allocates the command buffers and links them to |
| 385 | * the command free queue. |
| 386 | * |
| 387 | * The driver uses a pre allocated number of command buffers, which |
| 388 | * are created at driver initializations and freed at driver cleanup. |
| 389 | * Every command needs to obtain a command buffer from this pool before |
| 390 | * it can be issued. The command free queue lists the command buffers |
| 391 | * currently free to use, while the command pending queue lists the |
| 392 | * command buffers already in use and awaiting handling. Command buffers |
| 393 | * are returned to the free queue after use. |
| 394 | */ |
| 395 | int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter) |
| 396 | { |
| 397 | struct cmd_ctrl_node *cmd_array; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 398 | u32 i; |
| 399 | |
| 400 | /* Allocate and initialize struct cmd_ctrl_node */ |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 401 | cmd_array = kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER, |
| 402 | sizeof(struct cmd_ctrl_node), GFP_KERNEL); |
| 403 | if (!cmd_array) |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 404 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 405 | |
| 406 | adapter->cmd_pool = cmd_array; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 407 | |
| 408 | /* Allocate and initialize command buffers */ |
| 409 | for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) { |
| 410 | cmd_array[i].skb = dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER); |
| 411 | if (!cmd_array[i].skb) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 412 | mwifiex_dbg(adapter, ERROR, |
| 413 | "unable to allocate command buffer\n"); |
Zhaoyang Liu | 868093a | 2015-05-12 00:48:19 +0530 | [diff] [blame] | 414 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
| 418 | for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) |
| 419 | mwifiex_insert_cmd_to_free_q(adapter, &cmd_array[i]); |
| 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | /* |
| 425 | * This function frees the command buffers. |
| 426 | * |
| 427 | * The function calls the completion callback for all the command |
| 428 | * buffers that still have response buffers associated with them. |
| 429 | */ |
| 430 | int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter) |
| 431 | { |
| 432 | struct cmd_ctrl_node *cmd_array; |
| 433 | u32 i; |
| 434 | |
| 435 | /* Need to check if cmd pool is allocated or not */ |
| 436 | if (!adapter->cmd_pool) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 437 | mwifiex_dbg(adapter, FATAL, |
| 438 | "info: FREE_CMD_BUF: cmd_pool is null\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | cmd_array = adapter->cmd_pool; |
| 443 | |
| 444 | /* Release shared memory buffers */ |
| 445 | for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) { |
| 446 | if (cmd_array[i].skb) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 447 | mwifiex_dbg(adapter, CMD, |
| 448 | "cmd: free cmd buffer %d\n", i); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 449 | dev_kfree_skb_any(cmd_array[i].skb); |
| 450 | } |
| 451 | if (!cmd_array[i].resp_skb) |
| 452 | continue; |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 453 | |
| 454 | if (adapter->iface_type == MWIFIEX_USB) |
| 455 | adapter->if_ops.cmdrsp_complete(adapter, |
| 456 | cmd_array[i].resp_skb); |
| 457 | else |
| 458 | dev_kfree_skb_any(cmd_array[i].resp_skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 459 | } |
| 460 | /* Release struct cmd_ctrl_node */ |
| 461 | if (adapter->cmd_pool) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 462 | mwifiex_dbg(adapter, CMD, |
| 463 | "cmd: free cmd pool\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 464 | kfree(adapter->cmd_pool); |
| 465 | adapter->cmd_pool = NULL; |
| 466 | } |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * This function handles events generated by firmware. |
| 473 | * |
| 474 | * Event body of events received from firmware are not used (though they are |
| 475 | * saved), only the event ID is used. Some events are re-invoked by |
| 476 | * the driver, with a new event body. |
| 477 | * |
| 478 | * After processing, the function calls the completion callback |
| 479 | * for cleanup. |
| 480 | */ |
| 481 | int mwifiex_process_event(struct mwifiex_adapter *adapter) |
| 482 | { |
Ganapathi Bhat | 441756b | 2016-07-25 21:21:11 +0530 | [diff] [blame] | 483 | int ret, i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 484 | struct mwifiex_private *priv = |
| 485 | mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 486 | struct sk_buff *skb = adapter->event_skb; |
Ganapathi Bhat | 441756b | 2016-07-25 21:21:11 +0530 | [diff] [blame] | 487 | u32 eventcause; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 488 | struct mwifiex_rxinfo *rx_info; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 489 | |
Ganapathi Bhat | 441756b | 2016-07-25 21:21:11 +0530 | [diff] [blame] | 490 | if ((adapter->event_cause & EVENT_ID_MASK) == EVENT_RADAR_DETECTED) { |
| 491 | for (i = 0; i < adapter->priv_num; i++) { |
| 492 | priv = adapter->priv[i]; |
| 493 | if (priv && mwifiex_is_11h_active(priv)) { |
| 494 | adapter->event_cause |= |
| 495 | ((priv->bss_num & 0xff) << 16) | |
| 496 | ((priv->bss_type & 0xff) << 24); |
| 497 | break; |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | eventcause = adapter->event_cause; |
| 503 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 504 | /* Save the last event to debug log */ |
| 505 | adapter->dbg.last_event_index = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 506 | (adapter->dbg.last_event_index + 1) % DBG_CMD_NUM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 507 | adapter->dbg.last_event[adapter->dbg.last_event_index] = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 508 | (u16) eventcause; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 509 | |
| 510 | /* Get BSS number and corresponding priv */ |
| 511 | priv = mwifiex_get_priv_by_id(adapter, EVENT_GET_BSS_NUM(eventcause), |
| 512 | EVENT_GET_BSS_TYPE(eventcause)); |
| 513 | if (!priv) |
| 514 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
Avinash Patil | 76c504c | 2015-01-28 15:42:04 +0530 | [diff] [blame] | 515 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 516 | /* Clear BSS_NO_BITS from event */ |
| 517 | eventcause &= EVENT_ID_MASK; |
| 518 | adapter->event_cause = eventcause; |
| 519 | |
| 520 | if (skb) { |
| 521 | rx_info = MWIFIEX_SKB_RXCB(skb); |
Amitkumar Karwar | 701a9e6 | 2014-07-01 14:39:04 -0700 | [diff] [blame] | 522 | memset(rx_info, 0, sizeof(*rx_info)); |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 523 | rx_info->bss_num = priv->bss_num; |
| 524 | rx_info->bss_type = priv->bss_type; |
Zhaoyang Liu | 7a56c41 | 2015-06-05 01:01:53 +0530 | [diff] [blame] | 525 | mwifiex_dbg_dump(adapter, EVT_D, "Event Buf:", |
| 526 | skb->data, skb->len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 529 | mwifiex_dbg(adapter, EVENT, "EVENT: cause: %#x\n", eventcause); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 530 | |
Avinash Patil | 3d99d98 | 2012-08-03 18:06:06 -0700 | [diff] [blame] | 531 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) |
| 532 | ret = mwifiex_process_uap_event(priv); |
| 533 | else |
| 534 | ret = mwifiex_process_sta_event(priv); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 535 | |
| 536 | adapter->event_cause = 0; |
| 537 | adapter->event_skb = NULL; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 538 | adapter->if_ops.event_complete(adapter, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 539 | |
| 540 | return ret; |
| 541 | } |
| 542 | |
| 543 | /* |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 544 | * This function prepares a command and send it to the firmware. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 545 | * |
| 546 | * Preparation includes - |
| 547 | * - Sanity tests to make sure the card is still present or the FW |
| 548 | * is not reset |
| 549 | * - Getting a new command node from the command free queue |
| 550 | * - Initializing the command node for default parameters |
| 551 | * - Fill up the non-default parameters and buffer pointers |
| 552 | * - Add the command to pending queue |
| 553 | */ |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 554 | int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no, |
| 555 | u16 cmd_action, u32 cmd_oid, void *data_buf, bool sync) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 556 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 557 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 558 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 559 | struct cmd_ctrl_node *cmd_node; |
| 560 | struct host_cmd_ds_command *cmd_ptr; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 561 | |
| 562 | if (!adapter) { |
| 563 | pr_err("PREP_CMD: adapter is NULL\n"); |
| 564 | return -1; |
| 565 | } |
| 566 | |
| 567 | if (adapter->is_suspended) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 568 | mwifiex_dbg(adapter, ERROR, |
| 569 | "PREP_CMD: device in suspended state\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 570 | return -1; |
| 571 | } |
| 572 | |
Amitkumar Karwar | c0dbba6 | 2014-03-25 19:01:20 -0700 | [diff] [blame] | 573 | if (adapter->hs_enabling && cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 574 | mwifiex_dbg(adapter, ERROR, |
| 575 | "PREP_CMD: host entering sleep state\n"); |
Amitkumar Karwar | c0dbba6 | 2014-03-25 19:01:20 -0700 | [diff] [blame] | 576 | return -1; |
| 577 | } |
| 578 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 579 | if (adapter->surprise_removed) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 580 | mwifiex_dbg(adapter, ERROR, |
| 581 | "PREP_CMD: card is removed\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 582 | return -1; |
| 583 | } |
| 584 | |
Amitkumar Karwar | 0c9c4a0 | 2014-02-27 19:35:17 -0800 | [diff] [blame] | 585 | if (adapter->is_cmd_timedout) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 586 | mwifiex_dbg(adapter, ERROR, |
| 587 | "PREP_CMD: FW is in bad state\n"); |
Amitkumar Karwar | 38ec3f3 | 2014-02-27 19:35:15 -0800 | [diff] [blame] | 588 | return -1; |
| 589 | } |
| 590 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 591 | if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET) { |
| 592 | if (cmd_no != HostCmd_CMD_FUNC_INIT) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 593 | mwifiex_dbg(adapter, ERROR, |
| 594 | "PREP_CMD: FW in reset state\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 595 | return -1; |
| 596 | } |
| 597 | } |
Xinming Hu | cf5383b | 2016-09-02 13:05:06 +0530 | [diff] [blame] | 598 | /* We don't expect commands in manufacturing mode. They are cooked |
| 599 | * in application and ready to download buffer is passed to the driver |
| 600 | */ |
| 601 | if (adapter->mfg_mode && cmd_no) { |
| 602 | dev_dbg(adapter->dev, "Ignoring commands in manufacturing mode\n"); |
| 603 | return -1; |
| 604 | } |
| 605 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 606 | |
| 607 | /* Get a new command node */ |
| 608 | cmd_node = mwifiex_get_cmd_node(adapter); |
| 609 | |
| 610 | if (!cmd_node) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 611 | mwifiex_dbg(adapter, ERROR, |
| 612 | "PREP_CMD: no free cmd node\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 613 | return -1; |
| 614 | } |
| 615 | |
| 616 | /* Initialize the command node */ |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 617 | mwifiex_init_cmd_node(priv, cmd_node, cmd_oid, data_buf, sync); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 618 | |
| 619 | if (!cmd_node->cmd_skb) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 620 | mwifiex_dbg(adapter, ERROR, |
| 621 | "PREP_CMD: no free cmd buf\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 622 | return -1; |
| 623 | } |
| 624 | |
| 625 | memset(skb_put(cmd_node->cmd_skb, sizeof(struct host_cmd_ds_command)), |
| 626 | 0, sizeof(struct host_cmd_ds_command)); |
| 627 | |
| 628 | cmd_ptr = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data); |
| 629 | cmd_ptr->command = cpu_to_le16(cmd_no); |
| 630 | cmd_ptr->result = 0; |
| 631 | |
| 632 | /* Prepare command */ |
| 633 | if (cmd_no) { |
Avinash Patil | 40d0703 | 2012-05-08 18:30:19 -0700 | [diff] [blame] | 634 | switch (cmd_no) { |
| 635 | case HostCmd_CMD_UAP_SYS_CONFIG: |
| 636 | case HostCmd_CMD_UAP_BSS_START: |
| 637 | case HostCmd_CMD_UAP_BSS_STOP: |
Avinash Patil | 0f9e9b8 | 2013-05-17 17:50:23 -0700 | [diff] [blame] | 638 | case HostCmd_CMD_UAP_STA_DEAUTH: |
Avinash Patil | ed5cfbe | 2015-06-03 16:59:33 +0530 | [diff] [blame] | 639 | case HOST_CMD_APCMD_SYS_RESET: |
Xinming Hu | b21783e | 2015-06-03 16:59:39 +0530 | [diff] [blame] | 640 | case HOST_CMD_APCMD_STA_LIST: |
Avinash Patil | 40d0703 | 2012-05-08 18:30:19 -0700 | [diff] [blame] | 641 | ret = mwifiex_uap_prepare_cmd(priv, cmd_no, cmd_action, |
| 642 | cmd_oid, data_buf, |
| 643 | cmd_ptr); |
| 644 | break; |
| 645 | default: |
| 646 | ret = mwifiex_sta_prepare_cmd(priv, cmd_no, cmd_action, |
| 647 | cmd_oid, data_buf, |
| 648 | cmd_ptr); |
| 649 | break; |
| 650 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 651 | } else { |
| 652 | ret = mwifiex_cmd_host_cmd(priv, cmd_ptr, data_buf); |
| 653 | cmd_node->cmd_flag |= CMD_F_HOSTCMD; |
| 654 | } |
| 655 | |
| 656 | /* Return error, since the command preparation failed */ |
| 657 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 658 | mwifiex_dbg(adapter, ERROR, |
| 659 | "PREP_CMD: cmd %#x preparation failed\n", |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 660 | cmd_no); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 661 | mwifiex_insert_cmd_to_free_q(adapter, cmd_node); |
| 662 | return -1; |
| 663 | } |
| 664 | |
| 665 | /* Send command */ |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 666 | if (cmd_no == HostCmd_CMD_802_11_SCAN || |
| 667 | cmd_no == HostCmd_CMD_802_11_SCAN_EXT) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 668 | mwifiex_queue_scan_cmd(priv, cmd_node); |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 669 | } else { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 670 | mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true); |
Amitkumar Karwar | 1a1fb97 | 2012-06-27 19:57:56 -0700 | [diff] [blame] | 671 | queue_work(adapter->workqueue, &adapter->main_work); |
Amitkumar Karwar | 00d7ea1 | 2013-03-15 18:47:05 -0700 | [diff] [blame] | 672 | if (cmd_node->wait_q_enabled) |
| 673 | ret = mwifiex_wait_queue_complete(adapter, cmd_node); |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 674 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 675 | |
| 676 | return ret; |
| 677 | } |
| 678 | |
| 679 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 680 | * This function queues a command to the command pending queue. |
| 681 | * |
| 682 | * This in effect adds the command to the command list to be executed. |
| 683 | * Exit PS command is handled specially, by placing it always to the |
| 684 | * front of the command queue. |
| 685 | */ |
| 686 | void |
| 687 | mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter, |
| 688 | struct cmd_ctrl_node *cmd_node, u32 add_tail) |
| 689 | { |
| 690 | struct host_cmd_ds_command *host_cmd = NULL; |
| 691 | u16 command; |
| 692 | unsigned long flags; |
| 693 | |
| 694 | host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data); |
| 695 | if (!host_cmd) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 696 | mwifiex_dbg(adapter, ERROR, "QUEUE_CMD: host_cmd is NULL\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 697 | return; |
| 698 | } |
| 699 | |
| 700 | command = le16_to_cpu(host_cmd->command); |
| 701 | |
| 702 | /* Exit_PS command needs to be queued in the header always. */ |
| 703 | if (command == HostCmd_CMD_802_11_PS_MODE_ENH) { |
| 704 | struct host_cmd_ds_802_11_ps_mode_enh *pm = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 705 | &host_cmd->params.psmode_enh; |
| 706 | if ((le16_to_cpu(pm->action) == DIS_PS) || |
| 707 | (le16_to_cpu(pm->action) == DIS_AUTO_PS)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 708 | if (adapter->ps_state != PS_STATE_AWAKE) |
| 709 | add_tail = false; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); |
| 714 | if (add_tail) |
| 715 | list_add_tail(&cmd_node->list, &adapter->cmd_pending_q); |
| 716 | else |
| 717 | list_add(&cmd_node->list, &adapter->cmd_pending_q); |
| 718 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); |
| 719 | |
Bing Zhao | 9908b07 | 2013-04-01 12:44:46 -0700 | [diff] [blame] | 720 | atomic_inc(&adapter->cmd_pending); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 721 | mwifiex_dbg(adapter, CMD, |
| 722 | "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n", |
Bing Zhao | 9908b07 | 2013-04-01 12:44:46 -0700 | [diff] [blame] | 723 | command, atomic_read(&adapter->cmd_pending)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /* |
| 727 | * This function executes the next command in command pending queue. |
| 728 | * |
| 729 | * This function will fail if a command is already in processing stage, |
| 730 | * otherwise it will dequeue the first command from the command pending |
| 731 | * queue and send to the firmware. |
| 732 | * |
| 733 | * If the device is currently in host sleep mode, any commands, except the |
| 734 | * host sleep configuration command will de-activate the host sleep. For PS |
| 735 | * mode, the function will put the firmware back to sleep if applicable. |
| 736 | */ |
| 737 | int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter) |
| 738 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 739 | struct mwifiex_private *priv; |
| 740 | struct cmd_ctrl_node *cmd_node; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 741 | int ret = 0; |
| 742 | struct host_cmd_ds_command *host_cmd; |
| 743 | unsigned long cmd_flags; |
| 744 | unsigned long cmd_pending_q_flags; |
| 745 | |
| 746 | /* Check if already in processing */ |
| 747 | if (adapter->curr_cmd) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 748 | mwifiex_dbg(adapter, FATAL, |
| 749 | "EXEC_NEXT_CMD: cmd in processing\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 750 | return -1; |
| 751 | } |
| 752 | |
| 753 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); |
| 754 | /* Check if any command is pending */ |
| 755 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags); |
| 756 | if (list_empty(&adapter->cmd_pending_q)) { |
| 757 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, |
| 758 | cmd_pending_q_flags); |
| 759 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
| 760 | return 0; |
| 761 | } |
| 762 | cmd_node = list_first_entry(&adapter->cmd_pending_q, |
| 763 | struct cmd_ctrl_node, list); |
| 764 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, |
| 765 | cmd_pending_q_flags); |
| 766 | |
| 767 | host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data); |
| 768 | priv = cmd_node->priv; |
| 769 | |
| 770 | if (adapter->ps_state != PS_STATE_AWAKE) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 771 | mwifiex_dbg(adapter, ERROR, |
| 772 | "%s: cannot send cmd in sleep state,\t" |
| 773 | "this should not happen\n", __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 774 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
| 775 | return ret; |
| 776 | } |
| 777 | |
| 778 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags); |
| 779 | list_del(&cmd_node->list); |
| 780 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, |
| 781 | cmd_pending_q_flags); |
| 782 | |
| 783 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
| 784 | ret = mwifiex_dnld_cmd_to_fw(priv, cmd_node); |
| 785 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 786 | /* Any command sent to the firmware when host is in sleep |
| 787 | * mode should de-configure host sleep. We should skip the |
| 788 | * host sleep configuration command itself though |
| 789 | */ |
| 790 | if (priv && (host_cmd->command != |
| 791 | cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH))) { |
| 792 | if (adapter->hs_activated) { |
| 793 | adapter->is_hs_configured = false; |
| 794 | mwifiex_hs_activated_event(priv, false); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | return ret; |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * This function handles the command response. |
| 803 | * |
| 804 | * After processing, the function cleans the command node and puts |
| 805 | * it back to the command free queue. |
| 806 | */ |
| 807 | int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter) |
| 808 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 809 | struct host_cmd_ds_command *resp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 810 | struct mwifiex_private *priv = |
| 811 | mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 812 | int ret = 0; |
| 813 | uint16_t orig_cmdresp_no; |
| 814 | uint16_t cmdresp_no; |
| 815 | uint16_t cmdresp_result; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 816 | unsigned long flags; |
| 817 | |
| 818 | /* Now we got response from FW, cancel the command timer */ |
Avinash Patil | 629873f | 2014-02-18 15:47:55 -0800 | [diff] [blame] | 819 | del_timer_sync(&adapter->cmd_timer); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 820 | |
| 821 | if (!adapter->curr_cmd || !adapter->curr_cmd->resp_skb) { |
| 822 | resp = (struct host_cmd_ds_command *) adapter->upld_buf; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 823 | mwifiex_dbg(adapter, ERROR, |
| 824 | "CMD_RESP: NULL curr_cmd, %#x\n", |
| 825 | le16_to_cpu(resp->command)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 826 | return -1; |
| 827 | } |
| 828 | |
Amitkumar Karwar | 0c9c4a0 | 2014-02-27 19:35:17 -0800 | [diff] [blame] | 829 | adapter->is_cmd_timedout = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 830 | |
| 831 | resp = (struct host_cmd_ds_command *) adapter->curr_cmd->resp_skb->data; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 832 | if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) { |
| 833 | /* Copy original response back to response buffer */ |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 834 | struct mwifiex_ds_misc_cmd *hostcmd; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 835 | uint16_t size = le16_to_cpu(resp->size); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 836 | mwifiex_dbg(adapter, INFO, |
| 837 | "info: host cmd resp size = %d\n", size); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 838 | size = min_t(u16, size, MWIFIEX_SIZE_OF_CMD_BUFFER); |
| 839 | if (adapter->curr_cmd->data_buf) { |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 840 | hostcmd = adapter->curr_cmd->data_buf; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 841 | hostcmd->len = size; |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 842 | memcpy(hostcmd->cmd, resp, size); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | orig_cmdresp_no = le16_to_cpu(resp->command); |
| 846 | |
| 847 | /* Get BSS number and corresponding priv */ |
| 848 | priv = mwifiex_get_priv_by_id(adapter, |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 849 | HostCmd_GET_BSS_NO(le16_to_cpu(resp->seq_num)), |
| 850 | HostCmd_GET_BSS_TYPE(le16_to_cpu(resp->seq_num))); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 851 | if (!priv) |
| 852 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 853 | /* Clear RET_BIT from HostCmd */ |
| 854 | resp->command = cpu_to_le16(orig_cmdresp_no & HostCmd_CMD_ID_MASK); |
| 855 | |
| 856 | cmdresp_no = le16_to_cpu(resp->command); |
| 857 | cmdresp_result = le16_to_cpu(resp->result); |
| 858 | |
| 859 | /* Save the last command response to debug log */ |
| 860 | adapter->dbg.last_cmd_resp_index = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 861 | (adapter->dbg.last_cmd_resp_index + 1) % DBG_CMD_NUM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 862 | adapter->dbg.last_cmd_resp_id[adapter->dbg.last_cmd_resp_index] = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 863 | orig_cmdresp_no; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 864 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 865 | mwifiex_dbg(adapter, CMD, |
| 866 | "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n", |
| 867 | orig_cmdresp_no, cmdresp_result, |
| 868 | le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num)); |
Zhaoyang Liu | 868093a | 2015-05-12 00:48:19 +0530 | [diff] [blame] | 869 | mwifiex_dbg_dump(adapter, CMD_D, "CMD_RESP buffer:", resp, |
| 870 | le16_to_cpu(resp->size)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 871 | |
| 872 | if (!(orig_cmdresp_no & HostCmd_RET_BIT)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 873 | mwifiex_dbg(adapter, ERROR, "CMD_RESP: invalid cmd resp\n"); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 874 | if (adapter->curr_cmd->wait_q_enabled) |
| 875 | adapter->cmd_wait_q.status = -1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 876 | |
Bing Zhao | 9908b07 | 2013-04-01 12:44:46 -0700 | [diff] [blame] | 877 | mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 878 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 879 | adapter->curr_cmd = NULL; |
| 880 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 881 | return -1; |
| 882 | } |
| 883 | |
| 884 | if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) { |
| 885 | adapter->curr_cmd->cmd_flag &= ~CMD_F_HOSTCMD; |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 886 | if ((cmdresp_result == HostCmd_RESULT_OK) && |
| 887 | (cmdresp_no == HostCmd_CMD_802_11_HS_CFG_ENH)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 888 | ret = mwifiex_ret_802_11_hs_cfg(priv, resp); |
| 889 | } else { |
| 890 | /* handle response */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 891 | ret = mwifiex_process_sta_cmdresp(priv, cmdresp_no, resp); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | /* Check init command response */ |
| 895 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) { |
Amitkumar Karwar | a0f6d6c | 2012-02-24 21:36:05 -0800 | [diff] [blame] | 896 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 897 | mwifiex_dbg(adapter, ERROR, |
| 898 | "%s: cmd %#x failed during\t" |
| 899 | "initialization\n", __func__, cmdresp_no); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 900 | mwifiex_init_fw_complete(adapter); |
| 901 | return -1; |
| 902 | } else if (adapter->last_init_cmd == cmdresp_no) |
| 903 | adapter->hw_status = MWIFIEX_HW_STATUS_INIT_DONE; |
| 904 | } |
| 905 | |
| 906 | if (adapter->curr_cmd) { |
Amitkumar Karwar | a0f6d6c | 2012-02-24 21:36:05 -0800 | [diff] [blame] | 907 | if (adapter->curr_cmd->wait_q_enabled) |
| 908 | adapter->cmd_wait_q.status = ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 909 | |
Bing Zhao | 9908b07 | 2013-04-01 12:44:46 -0700 | [diff] [blame] | 910 | mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 911 | |
| 912 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 913 | adapter->curr_cmd = NULL; |
| 914 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 915 | } |
| 916 | |
| 917 | return ret; |
| 918 | } |
| 919 | |
| 920 | /* |
| 921 | * This function handles the timeout of command sending. |
| 922 | * |
| 923 | * It will re-send the same command again. |
| 924 | */ |
| 925 | void |
| 926 | mwifiex_cmd_timeout_func(unsigned long function_context) |
| 927 | { |
| 928 | struct mwifiex_adapter *adapter = |
| 929 | (struct mwifiex_adapter *) function_context; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 930 | struct cmd_ctrl_node *cmd_node; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 931 | |
Amitkumar Karwar | 0c9c4a0 | 2014-02-27 19:35:17 -0800 | [diff] [blame] | 932 | adapter->is_cmd_timedout = 1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 933 | if (!adapter->curr_cmd) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 934 | mwifiex_dbg(adapter, ERROR, |
| 935 | "cmd: empty curr_cmd\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 936 | return; |
| 937 | } |
| 938 | cmd_node = adapter->curr_cmd; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 939 | if (cmd_node) { |
| 940 | adapter->dbg.timeout_cmd_id = |
| 941 | adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index]; |
| 942 | adapter->dbg.timeout_cmd_act = |
| 943 | adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index]; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 944 | mwifiex_dbg(adapter, MSG, |
| 945 | "%s: Timeout cmd id = %#x, act = %#x\n", __func__, |
| 946 | adapter->dbg.timeout_cmd_id, |
| 947 | adapter->dbg.timeout_cmd_act); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 948 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 949 | mwifiex_dbg(adapter, MSG, |
| 950 | "num_data_h2c_failure = %d\n", |
| 951 | adapter->dbg.num_tx_host_to_card_failure); |
| 952 | mwifiex_dbg(adapter, MSG, |
| 953 | "num_cmd_h2c_failure = %d\n", |
| 954 | adapter->dbg.num_cmd_host_to_card_failure); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 955 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 956 | mwifiex_dbg(adapter, MSG, |
| 957 | "is_cmd_timedout = %d\n", |
| 958 | adapter->is_cmd_timedout); |
| 959 | mwifiex_dbg(adapter, MSG, |
| 960 | "num_tx_timeout = %d\n", |
| 961 | adapter->dbg.num_tx_timeout); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 962 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 963 | mwifiex_dbg(adapter, MSG, |
| 964 | "last_cmd_index = %d\n", |
| 965 | adapter->dbg.last_cmd_index); |
| 966 | mwifiex_dbg(adapter, MSG, |
| 967 | "last_cmd_id: %*ph\n", |
| 968 | (int)sizeof(adapter->dbg.last_cmd_id), |
| 969 | adapter->dbg.last_cmd_id); |
| 970 | mwifiex_dbg(adapter, MSG, |
| 971 | "last_cmd_act: %*ph\n", |
| 972 | (int)sizeof(adapter->dbg.last_cmd_act), |
| 973 | adapter->dbg.last_cmd_act); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 974 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 975 | mwifiex_dbg(adapter, MSG, |
| 976 | "last_cmd_resp_index = %d\n", |
| 977 | adapter->dbg.last_cmd_resp_index); |
| 978 | mwifiex_dbg(adapter, MSG, |
| 979 | "last_cmd_resp_id: %*ph\n", |
| 980 | (int)sizeof(adapter->dbg.last_cmd_resp_id), |
| 981 | adapter->dbg.last_cmd_resp_id); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 982 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 983 | mwifiex_dbg(adapter, MSG, |
| 984 | "last_event_index = %d\n", |
| 985 | adapter->dbg.last_event_index); |
| 986 | mwifiex_dbg(adapter, MSG, |
| 987 | "last_event: %*ph\n", |
| 988 | (int)sizeof(adapter->dbg.last_event), |
| 989 | adapter->dbg.last_event); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 990 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 991 | mwifiex_dbg(adapter, MSG, |
| 992 | "data_sent=%d cmd_sent=%d\n", |
| 993 | adapter->data_sent, adapter->cmd_sent); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 994 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 995 | mwifiex_dbg(adapter, MSG, |
| 996 | "ps_mode=%d ps_state=%d\n", |
| 997 | adapter->ps_mode, adapter->ps_state); |
Bing Zhao | b1a47aa | 2012-11-15 15:58:47 -0800 | [diff] [blame] | 998 | |
| 999 | if (cmd_node->wait_q_enabled) { |
| 1000 | adapter->cmd_wait_q.status = -ETIMEDOUT; |
Bing Zhao | b1a47aa | 2012-11-15 15:58:47 -0800 | [diff] [blame] | 1001 | mwifiex_cancel_pending_ioctl(adapter); |
Bing Zhao | b1a47aa | 2012-11-15 15:58:47 -0800 | [diff] [blame] | 1002 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1003 | } |
Zhaoyang Liu | d788ac2 | 2015-07-22 04:53:44 -0700 | [diff] [blame] | 1004 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1005 | mwifiex_init_fw_complete(adapter); |
Zhaoyang Liu | d788ac2 | 2015-07-22 04:53:44 -0700 | [diff] [blame] | 1006 | return; |
| 1007 | } |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 1008 | |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 1009 | if (adapter->if_ops.device_dump) |
| 1010 | adapter->if_ops.device_dump(adapter); |
Amitkumar Karwar | 92c2538 | 2014-06-19 21:38:52 -0700 | [diff] [blame] | 1011 | |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 1012 | if (adapter->if_ops.card_reset) |
| 1013 | adapter->if_ops.card_reset(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Andreas Fenkart | c70ca8c | 2016-03-10 09:44:10 +0100 | [diff] [blame] | 1016 | void |
| 1017 | mwifiex_cancel_pending_scan_cmd(struct mwifiex_adapter *adapter) |
| 1018 | { |
| 1019 | struct cmd_ctrl_node *cmd_node = NULL, *tmp_node; |
| 1020 | unsigned long flags; |
| 1021 | |
| 1022 | /* Cancel all pending scan command */ |
| 1023 | spin_lock_irqsave(&adapter->scan_pending_q_lock, flags); |
| 1024 | list_for_each_entry_safe(cmd_node, tmp_node, |
| 1025 | &adapter->scan_pending_q, list) { |
| 1026 | list_del(&cmd_node->list); |
| 1027 | cmd_node->wait_q_enabled = false; |
| 1028 | mwifiex_insert_cmd_to_free_q(adapter, cmd_node); |
| 1029 | } |
| 1030 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags); |
| 1031 | } |
| 1032 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1033 | /* |
| 1034 | * This function cancels all the pending commands. |
| 1035 | * |
| 1036 | * The current command, all commands in command pending queue and all scan |
| 1037 | * commands in scan pending queue are cancelled. All the completion callbacks |
| 1038 | * are called with failure status to ensure cleanup. |
| 1039 | */ |
| 1040 | void |
| 1041 | mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter) |
| 1042 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1043 | struct cmd_ctrl_node *cmd_node = NULL, *tmp_node; |
Amitkumar Karwar | 4af2bd4 | 2014-02-27 19:35:15 -0800 | [diff] [blame] | 1044 | unsigned long flags, cmd_flags; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1045 | |
Amitkumar Karwar | a7488c7 | 2014-03-27 21:05:26 -0700 | [diff] [blame] | 1046 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1047 | /* Cancel current cmd */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1048 | if ((adapter->curr_cmd) && (adapter->curr_cmd->wait_q_enabled)) { |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1049 | adapter->cmd_wait_q.status = -1; |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 1050 | mwifiex_complete_cmd(adapter, adapter->curr_cmd); |
Vishal Thanki | 8434969 | 2016-04-07 23:37:12 +0200 | [diff] [blame] | 1051 | adapter->curr_cmd->wait_q_enabled = false; |
Andreas Fenkart | e3a3ef2 | 2015-07-17 09:13:03 +0200 | [diff] [blame] | 1052 | /* no recycle probably wait for response */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1053 | } |
| 1054 | /* Cancel all pending command */ |
| 1055 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); |
| 1056 | list_for_each_entry_safe(cmd_node, tmp_node, |
| 1057 | &adapter->cmd_pending_q, list) { |
| 1058 | list_del(&cmd_node->list); |
| 1059 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); |
| 1060 | |
Andreas Fenkart | e3a3ef2 | 2015-07-17 09:13:03 +0200 | [diff] [blame] | 1061 | if (cmd_node->wait_q_enabled) |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1062 | adapter->cmd_wait_q.status = -1; |
Bing Zhao | 9908b07 | 2013-04-01 12:44:46 -0700 | [diff] [blame] | 1063 | mwifiex_recycle_cmd_node(adapter, cmd_node); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1064 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); |
| 1065 | } |
| 1066 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); |
Amitkumar Karwar | a7488c7 | 2014-03-27 21:05:26 -0700 | [diff] [blame] | 1067 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1068 | |
Xinming Hu | a9c790b | 2016-06-16 18:52:22 +0530 | [diff] [blame] | 1069 | mwifiex_cancel_scan(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | /* |
| 1073 | * This function cancels all pending commands that matches with |
| 1074 | * the given IOCTL request. |
| 1075 | * |
| 1076 | * Both the current command buffer and the pending command queue are |
| 1077 | * searched for matching IOCTL request. The completion callback of |
| 1078 | * the matched command is called with failure status to ensure cleanup. |
| 1079 | * In case of scan commands, all pending commands in scan pending queue |
| 1080 | * are cancelled. |
| 1081 | */ |
| 1082 | void |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1083 | mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1084 | { |
Andreas Fenkart | c70ca8c | 2016-03-10 09:44:10 +0100 | [diff] [blame] | 1085 | struct cmd_ctrl_node *cmd_node = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1086 | unsigned long cmd_flags; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1087 | |
| 1088 | if ((adapter->curr_cmd) && |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1089 | (adapter->curr_cmd->wait_q_enabled)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1090 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); |
| 1091 | cmd_node = adapter->curr_cmd; |
Andreas Fenkart | e9f21d4 | 2015-07-17 09:13:05 +0200 | [diff] [blame] | 1092 | /* setting curr_cmd to NULL is quite dangerous, because |
| 1093 | * mwifiex_process_cmdresp checks curr_cmd to be != NULL |
| 1094 | * at the beginning then relies on it and dereferences |
| 1095 | * it at will |
| 1096 | * this probably works since mwifiex_cmd_timeout_func |
| 1097 | * is the only caller of this function and responses |
| 1098 | * at that point |
| 1099 | */ |
Yogesh Ashok Powar | 51e708c | 2011-12-13 20:43:16 -0800 | [diff] [blame] | 1100 | adapter->curr_cmd = NULL; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1101 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
Andreas Fenkart | e9f21d4 | 2015-07-17 09:13:05 +0200 | [diff] [blame] | 1102 | |
| 1103 | mwifiex_recycle_cmd_node(adapter, cmd_node); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1104 | } |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1105 | |
Xinming Hu | a9c790b | 2016-06-16 18:52:22 +0530 | [diff] [blame] | 1106 | mwifiex_cancel_scan(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /* |
| 1110 | * This function sends the sleep confirm command to firmware, if |
| 1111 | * possible. |
| 1112 | * |
| 1113 | * The sleep confirm command cannot be issued if command response, |
| 1114 | * data response or event response is awaiting handling, or if we |
| 1115 | * are in the middle of sending a command, or expecting a command |
| 1116 | * response. |
| 1117 | */ |
| 1118 | void |
| 1119 | mwifiex_check_ps_cond(struct mwifiex_adapter *adapter) |
| 1120 | { |
| 1121 | if (!adapter->cmd_sent && |
| 1122 | !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter)) |
| 1123 | mwifiex_dnld_sleep_confirm_cmd(adapter); |
| 1124 | else |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1125 | mwifiex_dbg(adapter, CMD, |
| 1126 | "cmd: Delay Sleep Confirm (%s%s%s)\n", |
| 1127 | (adapter->cmd_sent) ? "D" : "", |
| 1128 | (adapter->curr_cmd) ? "C" : "", |
| 1129 | (IS_CARD_RX_RCVD(adapter)) ? "R" : ""); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /* |
| 1133 | * This function sends a Host Sleep activated event to applications. |
| 1134 | * |
| 1135 | * This event is generated by the driver, with a blank event body. |
| 1136 | */ |
| 1137 | void |
| 1138 | mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated) |
| 1139 | { |
| 1140 | if (activated) { |
| 1141 | if (priv->adapter->is_hs_configured) { |
| 1142 | priv->adapter->hs_activated = true; |
Avinash Patil | 2db96c3 | 2012-09-27 19:00:10 -0700 | [diff] [blame] | 1143 | mwifiex_update_rxreor_flags(priv->adapter, |
| 1144 | RXREOR_FORCE_NO_DROP); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1145 | mwifiex_dbg(priv->adapter, EVENT, |
| 1146 | "event: hs_activated\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1147 | priv->adapter->hs_activate_wait_q_woken = true; |
| 1148 | wake_up_interruptible( |
| 1149 | &priv->adapter->hs_activate_wait_q); |
| 1150 | } else { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1151 | mwifiex_dbg(priv->adapter, EVENT, |
| 1152 | "event: HS not configured\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1153 | } |
| 1154 | } else { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1155 | mwifiex_dbg(priv->adapter, EVENT, |
| 1156 | "event: hs_deactivated\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1157 | priv->adapter->hs_activated = false; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | /* |
| 1162 | * This function handles the command response of a Host Sleep configuration |
| 1163 | * command. |
| 1164 | * |
| 1165 | * Handling includes changing the header fields into CPU format |
| 1166 | * and setting the current host sleep activation status in driver. |
| 1167 | * |
| 1168 | * In case host sleep status change, the function generates an event to |
| 1169 | * notify the applications. |
| 1170 | */ |
| 1171 | int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv, |
| 1172 | struct host_cmd_ds_command *resp) |
| 1173 | { |
| 1174 | struct mwifiex_adapter *adapter = priv->adapter; |
| 1175 | struct host_cmd_ds_802_11_hs_cfg_enh *phs_cfg = |
| 1176 | &resp->params.opt_hs_cfg; |
| 1177 | uint32_t conditions = le32_to_cpu(phs_cfg->params.hs_config.conditions); |
| 1178 | |
Amitkumar Karwar | a4186ea | 2012-06-20 19:58:37 -0700 | [diff] [blame] | 1179 | if (phs_cfg->action == cpu_to_le16(HS_ACTIVATE) && |
Bing Zhao | b7be152 | 2013-09-20 19:56:45 -0700 | [diff] [blame] | 1180 | adapter->iface_type != MWIFIEX_USB) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1181 | mwifiex_hs_activated_event(priv, true); |
| 1182 | return 0; |
| 1183 | } else { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1184 | mwifiex_dbg(adapter, CMD, |
| 1185 | "cmd: CMD_RESP: HS_CFG cmd reply\t" |
| 1186 | " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n", |
| 1187 | resp->result, conditions, |
| 1188 | phs_cfg->params.hs_config.gpio, |
| 1189 | phs_cfg->params.hs_config.gap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1190 | } |
Amitkumar Karwar | cc0b5a6 | 2013-03-04 16:27:57 -0800 | [diff] [blame] | 1191 | if (conditions != HS_CFG_CANCEL) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1192 | adapter->is_hs_configured = true; |
Bing Zhao | b7be152 | 2013-09-20 19:56:45 -0700 | [diff] [blame] | 1193 | if (adapter->iface_type == MWIFIEX_USB) |
Amitkumar Karwar | a4186ea | 2012-06-20 19:58:37 -0700 | [diff] [blame] | 1194 | mwifiex_hs_activated_event(priv, true); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1195 | } else { |
| 1196 | adapter->is_hs_configured = false; |
| 1197 | if (adapter->hs_activated) |
| 1198 | mwifiex_hs_activated_event(priv, false); |
| 1199 | } |
| 1200 | |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | /* |
| 1205 | * This function wakes up the adapter and generates a Host Sleep |
| 1206 | * cancel event on receiving the power up interrupt. |
| 1207 | */ |
| 1208 | void |
| 1209 | mwifiex_process_hs_config(struct mwifiex_adapter *adapter) |
| 1210 | { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1211 | mwifiex_dbg(adapter, INFO, |
| 1212 | "info: %s: auto cancelling host sleep\t" |
| 1213 | "since there is interrupt from the firmware\n", |
| 1214 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1215 | |
| 1216 | adapter->if_ops.wakeup(adapter); |
| 1217 | adapter->hs_activated = false; |
| 1218 | adapter->is_hs_configured = false; |
Bing Zhao | 4879542 | 2013-05-06 19:46:53 -0700 | [diff] [blame] | 1219 | adapter->is_suspended = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1220 | mwifiex_hs_activated_event(mwifiex_get_priv(adapter, |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1221 | MWIFIEX_BSS_ROLE_ANY), |
| 1222 | false); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1223 | } |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 1224 | EXPORT_SYMBOL_GPL(mwifiex_process_hs_config); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1225 | |
| 1226 | /* |
| 1227 | * This function handles the command response of a sleep confirm command. |
| 1228 | * |
| 1229 | * The function sets the card state to SLEEP if the response indicates success. |
| 1230 | */ |
| 1231 | void |
| 1232 | mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter, |
| 1233 | u8 *pbuf, u32 upld_len) |
| 1234 | { |
| 1235 | struct host_cmd_ds_command *cmd = (struct host_cmd_ds_command *) pbuf; |
| 1236 | struct mwifiex_private *priv = |
| 1237 | mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 1238 | uint16_t result = le16_to_cpu(cmd->result); |
| 1239 | uint16_t command = le16_to_cpu(cmd->command); |
| 1240 | uint16_t seq_num = le16_to_cpu(cmd->seq_num); |
| 1241 | |
| 1242 | if (!upld_len) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1243 | mwifiex_dbg(adapter, ERROR, |
| 1244 | "%s: cmd size is 0\n", __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1245 | return; |
| 1246 | } |
| 1247 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1248 | mwifiex_dbg(adapter, CMD, |
| 1249 | "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n", |
| 1250 | command, result, le16_to_cpu(cmd->size), seq_num); |
Bing Zhao | 363c1b4 | 2014-06-19 21:38:58 -0700 | [diff] [blame] | 1251 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1252 | /* Get BSS number and corresponding priv */ |
| 1253 | priv = mwifiex_get_priv_by_id(adapter, HostCmd_GET_BSS_NO(seq_num), |
| 1254 | HostCmd_GET_BSS_TYPE(seq_num)); |
| 1255 | if (!priv) |
| 1256 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 1257 | |
| 1258 | /* Update sequence number */ |
| 1259 | seq_num = HostCmd_GET_SEQ_NO(seq_num); |
| 1260 | /* Clear RET_BIT from HostCmd */ |
| 1261 | command &= HostCmd_CMD_ID_MASK; |
| 1262 | |
| 1263 | if (command != HostCmd_CMD_802_11_PS_MODE_ENH) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1264 | mwifiex_dbg(adapter, ERROR, |
| 1265 | "%s: rcvd unexpected resp for cmd %#x, result = %x\n", |
| 1266 | __func__, command, result); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1267 | return; |
| 1268 | } |
| 1269 | |
| 1270 | if (result) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1271 | mwifiex_dbg(adapter, ERROR, |
| 1272 | "%s: sleep confirm cmd failed\n", |
| 1273 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1274 | adapter->pm_wakeup_card_req = false; |
| 1275 | adapter->ps_state = PS_STATE_AWAKE; |
| 1276 | return; |
| 1277 | } |
| 1278 | adapter->pm_wakeup_card_req = true; |
| 1279 | if (adapter->is_hs_configured) |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1280 | mwifiex_hs_activated_event(mwifiex_get_priv |
| 1281 | (adapter, MWIFIEX_BSS_ROLE_ANY), |
| 1282 | true); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1283 | adapter->ps_state = PS_STATE_SLEEP; |
| 1284 | cmd->command = cpu_to_le16(command); |
| 1285 | cmd->seq_num = cpu_to_le16(seq_num); |
| 1286 | } |
| 1287 | EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp); |
| 1288 | |
| 1289 | /* |
| 1290 | * This function prepares an enhanced power mode command. |
| 1291 | * |
| 1292 | * This function can be used to disable power save or to configure |
| 1293 | * power save with auto PS or STA PS or auto deep sleep. |
| 1294 | * |
| 1295 | * Preparation includes - |
| 1296 | * - Setting command ID, action and proper size |
| 1297 | * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV, |
| 1298 | * auto deep sleep TLV (as required) |
| 1299 | * - Ensuring correct endian-ness |
| 1300 | */ |
| 1301 | int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv, |
| 1302 | struct host_cmd_ds_command *cmd, |
| 1303 | u16 cmd_action, uint16_t ps_bitmap, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 1304 | struct mwifiex_ds_auto_ds *auto_ds) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1305 | { |
| 1306 | struct host_cmd_ds_802_11_ps_mode_enh *psmode_enh = |
| 1307 | &cmd->params.psmode_enh; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1308 | u8 *tlv; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1309 | u16 cmd_size = 0; |
| 1310 | |
| 1311 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH); |
| 1312 | if (cmd_action == DIS_AUTO_PS) { |
| 1313 | psmode_enh->action = cpu_to_le16(DIS_AUTO_PS); |
| 1314 | psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap); |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1315 | cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) + |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1316 | sizeof(psmode_enh->params.ps_bitmap)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1317 | } else if (cmd_action == GET_PS) { |
| 1318 | psmode_enh->action = cpu_to_le16(GET_PS); |
| 1319 | psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap); |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1320 | cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) + |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1321 | sizeof(psmode_enh->params.ps_bitmap)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1322 | } else if (cmd_action == EN_AUTO_PS) { |
| 1323 | psmode_enh->action = cpu_to_le16(EN_AUTO_PS); |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1324 | psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap); |
| 1325 | cmd_size = S_DS_GEN + sizeof(psmode_enh->action) + |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1326 | sizeof(psmode_enh->params.ps_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1327 | tlv = (u8 *) cmd + cmd_size; |
| 1328 | if (ps_bitmap & BITMAP_STA_PS) { |
| 1329 | struct mwifiex_adapter *adapter = priv->adapter; |
| 1330 | struct mwifiex_ie_types_ps_param *ps_tlv = |
| 1331 | (struct mwifiex_ie_types_ps_param *) tlv; |
| 1332 | struct mwifiex_ps_param *ps_mode = &ps_tlv->param; |
| 1333 | ps_tlv->header.type = cpu_to_le16(TLV_TYPE_PS_PARAM); |
| 1334 | ps_tlv->header.len = cpu_to_le16(sizeof(*ps_tlv) - |
| 1335 | sizeof(struct mwifiex_ie_types_header)); |
| 1336 | cmd_size += sizeof(*ps_tlv); |
| 1337 | tlv += sizeof(*ps_tlv); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1338 | mwifiex_dbg(priv->adapter, CMD, |
| 1339 | "cmd: PS Command: Enter PS\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1340 | ps_mode->null_pkt_interval = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1341 | cpu_to_le16(adapter->null_pkt_interval); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1342 | ps_mode->multiple_dtims = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1343 | cpu_to_le16(adapter->multiple_dtim); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1344 | ps_mode->bcn_miss_timeout = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1345 | cpu_to_le16(adapter->bcn_miss_time_out); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1346 | ps_mode->local_listen_interval = |
| 1347 | cpu_to_le16(adapter->local_listen_interval); |
| 1348 | ps_mode->adhoc_wake_period = |
| 1349 | cpu_to_le16(adapter->adhoc_awake_period); |
| 1350 | ps_mode->delay_to_ps = |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 1351 | cpu_to_le16(adapter->delay_to_ps); |
| 1352 | ps_mode->mode = cpu_to_le16(adapter->enhanced_ps_mode); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1353 | |
| 1354 | } |
| 1355 | if (ps_bitmap & BITMAP_AUTO_DS) { |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1356 | struct mwifiex_ie_types_auto_ds_param *auto_ds_tlv = |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1357 | (struct mwifiex_ie_types_auto_ds_param *) tlv; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1358 | u16 idletime = 0; |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1359 | |
| 1360 | auto_ds_tlv->header.type = |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1361 | cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM); |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1362 | auto_ds_tlv->header.len = |
| 1363 | cpu_to_le16(sizeof(*auto_ds_tlv) - |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1364 | sizeof(struct mwifiex_ie_types_header)); |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1365 | cmd_size += sizeof(*auto_ds_tlv); |
| 1366 | tlv += sizeof(*auto_ds_tlv); |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 1367 | if (auto_ds) |
| 1368 | idletime = auto_ds->idle_time; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1369 | mwifiex_dbg(priv->adapter, CMD, |
| 1370 | "cmd: PS Command: Enter Auto Deep Sleep\n"); |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1371 | auto_ds_tlv->deep_sleep_timeout = cpu_to_le16(idletime); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1372 | } |
| 1373 | cmd->size = cpu_to_le16(cmd_size); |
| 1374 | } |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
| 1378 | /* |
| 1379 | * This function handles the command response of an enhanced power mode |
| 1380 | * command. |
| 1381 | * |
| 1382 | * Handling includes changing the header fields into CPU format |
| 1383 | * and setting the current enhanced power mode in driver. |
| 1384 | */ |
| 1385 | int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv, |
| 1386 | struct host_cmd_ds_command *resp, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 1387 | struct mwifiex_ds_pm_cfg *pm_cfg) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1388 | { |
| 1389 | struct mwifiex_adapter *adapter = priv->adapter; |
| 1390 | struct host_cmd_ds_802_11_ps_mode_enh *ps_mode = |
| 1391 | &resp->params.psmode_enh; |
| 1392 | uint16_t action = le16_to_cpu(ps_mode->action); |
| 1393 | uint16_t ps_bitmap = le16_to_cpu(ps_mode->params.ps_bitmap); |
| 1394 | uint16_t auto_ps_bitmap = |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1395 | le16_to_cpu(ps_mode->params.ps_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1396 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1397 | mwifiex_dbg(adapter, INFO, |
| 1398 | "info: %s: PS_MODE cmd reply result=%#x action=%#X\n", |
| 1399 | __func__, resp->result, action); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1400 | if (action == EN_AUTO_PS) { |
| 1401 | if (auto_ps_bitmap & BITMAP_AUTO_DS) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1402 | mwifiex_dbg(adapter, CMD, |
| 1403 | "cmd: Enabled auto deep sleep\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1404 | priv->adapter->is_deep_sleep = true; |
| 1405 | } |
| 1406 | if (auto_ps_bitmap & BITMAP_STA_PS) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1407 | mwifiex_dbg(adapter, CMD, |
| 1408 | "cmd: Enabled STA power save\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1409 | if (adapter->sleep_period.period) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1410 | mwifiex_dbg(adapter, CMD, |
| 1411 | "cmd: set to uapsd/pps mode\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1412 | } |
| 1413 | } else if (action == DIS_AUTO_PS) { |
| 1414 | if (ps_bitmap & BITMAP_AUTO_DS) { |
| 1415 | priv->adapter->is_deep_sleep = false; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1416 | mwifiex_dbg(adapter, CMD, |
| 1417 | "cmd: Disabled auto deep sleep\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1418 | } |
| 1419 | if (ps_bitmap & BITMAP_STA_PS) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1420 | mwifiex_dbg(adapter, CMD, |
| 1421 | "cmd: Disabled STA power save\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1422 | if (adapter->sleep_period.period) { |
| 1423 | adapter->delay_null_pkt = false; |
| 1424 | adapter->tx_lock_flag = false; |
| 1425 | adapter->pps_uapsd_mode = false; |
| 1426 | } |
| 1427 | } |
| 1428 | } else if (action == GET_PS) { |
Marc Yang | 2b06bdb | 2011-03-30 18:12:44 -0700 | [diff] [blame] | 1429 | if (ps_bitmap & BITMAP_STA_PS) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1430 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP; |
| 1431 | else |
| 1432 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM; |
| 1433 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1434 | mwifiex_dbg(adapter, CMD, |
| 1435 | "cmd: ps_bitmap=%#x\n", ps_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1436 | |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 1437 | if (pm_cfg) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1438 | /* This section is for get power save mode */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1439 | if (ps_bitmap & BITMAP_STA_PS) |
| 1440 | pm_cfg->param.ps_mode = 1; |
| 1441 | else |
| 1442 | pm_cfg->param.ps_mode = 0; |
| 1443 | } |
| 1444 | } |
| 1445 | return 0; |
| 1446 | } |
| 1447 | |
| 1448 | /* |
| 1449 | * This function prepares command to get hardware specifications. |
| 1450 | * |
| 1451 | * Preparation includes - |
| 1452 | * - Setting command ID, action and proper size |
| 1453 | * - Setting permanent address parameter |
| 1454 | * - Ensuring correct endian-ness |
| 1455 | */ |
| 1456 | int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv, |
| 1457 | struct host_cmd_ds_command *cmd) |
| 1458 | { |
| 1459 | struct host_cmd_ds_get_hw_spec *hw_spec = &cmd->params.hw_spec; |
| 1460 | |
| 1461 | cmd->command = cpu_to_le16(HostCmd_CMD_GET_HW_SPEC); |
| 1462 | cmd->size = |
| 1463 | cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec) + S_DS_GEN); |
| 1464 | memcpy(hw_spec->permanent_addr, priv->curr_addr, ETH_ALEN); |
| 1465 | |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
| 1469 | /* |
| 1470 | * This function handles the command response of get hardware |
| 1471 | * specifications. |
| 1472 | * |
| 1473 | * Handling includes changing the header fields into CPU format |
| 1474 | * and saving/updating the following parameters in driver - |
| 1475 | * - Firmware capability information |
| 1476 | * - Firmware band settings |
| 1477 | * - Ad-hoc start band and channel |
| 1478 | * - Ad-hoc 11n activation status |
| 1479 | * - Firmware release number |
| 1480 | * - Number of antennas |
| 1481 | * - Hardware address |
| 1482 | * - Hardware interface version |
| 1483 | * - Firmware version |
| 1484 | * - Region code |
| 1485 | * - 11n capabilities |
| 1486 | * - MCS support fields |
| 1487 | * - MP end port |
| 1488 | */ |
| 1489 | int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv, |
| 1490 | struct host_cmd_ds_command *resp) |
| 1491 | { |
| 1492 | struct host_cmd_ds_get_hw_spec *hw_spec = &resp->params.hw_spec; |
| 1493 | struct mwifiex_adapter *adapter = priv->adapter; |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1494 | struct mwifiex_ie_types_header *tlv; |
Amitkumar Karwar | 4b9fede | 2014-08-19 08:24:25 -0400 | [diff] [blame] | 1495 | struct hw_spec_api_rev *api_rev; |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1496 | u16 resp_size, api_id; |
| 1497 | int i, left_len, parsed_len = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1498 | |
| 1499 | adapter->fw_cap_info = le32_to_cpu(hw_spec->fw_cap_info); |
| 1500 | |
| 1501 | if (IS_SUPPORT_MULTI_BANDS(adapter)) |
| 1502 | adapter->fw_bands = (u8) GET_FW_DEFAULT_BANDS(adapter); |
| 1503 | else |
| 1504 | adapter->fw_bands = BAND_B; |
| 1505 | |
| 1506 | adapter->config_bands = adapter->fw_bands; |
| 1507 | |
| 1508 | if (adapter->fw_bands & BAND_A) { |
| 1509 | if (adapter->fw_bands & BAND_GN) { |
| 1510 | adapter->config_bands |= BAND_AN; |
| 1511 | adapter->fw_bands |= BAND_AN; |
| 1512 | } |
| 1513 | if (adapter->fw_bands & BAND_AN) { |
| 1514 | adapter->adhoc_start_band = BAND_A | BAND_AN; |
| 1515 | adapter->adhoc_11n_enabled = true; |
| 1516 | } else { |
| 1517 | adapter->adhoc_start_band = BAND_A; |
| 1518 | } |
| 1519 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL_A; |
| 1520 | } else if (adapter->fw_bands & BAND_GN) { |
| 1521 | adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN; |
| 1522 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; |
| 1523 | adapter->adhoc_11n_enabled = true; |
| 1524 | } else if (adapter->fw_bands & BAND_G) { |
| 1525 | adapter->adhoc_start_band = BAND_G | BAND_B; |
| 1526 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; |
| 1527 | } else if (adapter->fw_bands & BAND_B) { |
| 1528 | adapter->adhoc_start_band = BAND_B; |
| 1529 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; |
| 1530 | } |
| 1531 | |
| 1532 | adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number); |
Avinash Patil | 4721c63 | 2014-09-12 20:08:45 +0530 | [diff] [blame] | 1533 | adapter->fw_api_ver = (adapter->fw_release_number >> 16) & 0xff; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1534 | adapter->number_of_antenna = le16_to_cpu(hw_spec->number_of_antenna); |
| 1535 | |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 1536 | if (le32_to_cpu(hw_spec->dot_11ac_dev_cap)) { |
| 1537 | adapter->is_hw_11ac_capable = true; |
| 1538 | |
| 1539 | /* Copy 11AC cap */ |
| 1540 | adapter->hw_dot_11ac_dev_cap = |
| 1541 | le32_to_cpu(hw_spec->dot_11ac_dev_cap); |
Amitkumar Karwar | 79d9a54 | 2014-02-07 16:27:27 -0800 | [diff] [blame] | 1542 | adapter->usr_dot_11ac_dev_cap_bg = adapter->hw_dot_11ac_dev_cap |
| 1543 | & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK; |
| 1544 | adapter->usr_dot_11ac_dev_cap_a = adapter->hw_dot_11ac_dev_cap |
| 1545 | & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK; |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 1546 | |
| 1547 | /* Copy 11AC mcs */ |
| 1548 | adapter->hw_dot_11ac_mcs_support = |
| 1549 | le32_to_cpu(hw_spec->dot_11ac_mcs_support); |
| 1550 | adapter->usr_dot_11ac_mcs_support = |
| 1551 | adapter->hw_dot_11ac_mcs_support; |
| 1552 | } else { |
| 1553 | adapter->is_hw_11ac_capable = false; |
| 1554 | } |
| 1555 | |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1556 | resp_size = le16_to_cpu(resp->size) - S_DS_GEN; |
| 1557 | if (resp_size > sizeof(struct host_cmd_ds_get_hw_spec)) { |
| 1558 | /* we have variable HW SPEC information */ |
| 1559 | left_len = resp_size - sizeof(struct host_cmd_ds_get_hw_spec); |
| 1560 | while (left_len > sizeof(struct mwifiex_ie_types_header)) { |
| 1561 | tlv = (void *)&hw_spec->tlvs + parsed_len; |
| 1562 | switch (le16_to_cpu(tlv->type)) { |
Amitkumar Karwar | 4b9fede | 2014-08-19 08:24:25 -0400 | [diff] [blame] | 1563 | case TLV_TYPE_API_REV: |
| 1564 | api_rev = (struct hw_spec_api_rev *)tlv; |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1565 | api_id = le16_to_cpu(api_rev->api_id); |
| 1566 | switch (api_id) { |
| 1567 | case KEY_API_VER_ID: |
Amitkumar Karwar | 4b9fede | 2014-08-19 08:24:25 -0400 | [diff] [blame] | 1568 | adapter->key_api_major_ver = |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1569 | api_rev->major_ver; |
Amitkumar Karwar | 4b9fede | 2014-08-19 08:24:25 -0400 | [diff] [blame] | 1570 | adapter->key_api_minor_ver = |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1571 | api_rev->minor_ver; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1572 | mwifiex_dbg(adapter, INFO, |
| 1573 | "key_api v%d.%d\n", |
| 1574 | adapter->key_api_major_ver, |
| 1575 | adapter->key_api_minor_ver); |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1576 | break; |
Amitkumar Karwar | 89be7ce | 2014-08-19 08:24:26 -0400 | [diff] [blame] | 1577 | case FW_API_VER_ID: |
| 1578 | adapter->fw_api_ver = |
| 1579 | api_rev->major_ver; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1580 | mwifiex_dbg(adapter, INFO, |
| 1581 | "Firmware api version %d\n", |
| 1582 | adapter->fw_api_ver); |
Amitkumar Karwar | 89be7ce | 2014-08-19 08:24:26 -0400 | [diff] [blame] | 1583 | break; |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1584 | default: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1585 | mwifiex_dbg(adapter, FATAL, |
| 1586 | "Unknown api_id: %d\n", |
| 1587 | api_id); |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1588 | break; |
| 1589 | } |
| 1590 | break; |
| 1591 | default: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1592 | mwifiex_dbg(adapter, FATAL, |
| 1593 | "Unknown GET_HW_SPEC TLV type: %#x\n", |
| 1594 | le16_to_cpu(tlv->type)); |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1595 | break; |
| 1596 | } |
| 1597 | parsed_len += le16_to_cpu(tlv->len) + |
| 1598 | sizeof(struct mwifiex_ie_types_header); |
Amitkumar Karwar | 2618d4f | 2014-08-19 08:24:24 -0400 | [diff] [blame] | 1599 | left_len -= le16_to_cpu(tlv->len) + |
| 1600 | sizeof(struct mwifiex_ie_types_header); |
Avinash Patil | 7f445d0 | 2014-02-07 16:30:42 -0800 | [diff] [blame] | 1601 | } |
| 1602 | } |
| 1603 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1604 | mwifiex_dbg(adapter, INFO, |
| 1605 | "info: GET_HW_SPEC: fw_release_number- %#x\n", |
| 1606 | adapter->fw_release_number); |
| 1607 | mwifiex_dbg(adapter, INFO, |
| 1608 | "info: GET_HW_SPEC: permanent addr: %pM\n", |
| 1609 | hw_spec->permanent_addr); |
| 1610 | mwifiex_dbg(adapter, INFO, |
| 1611 | "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n", |
| 1612 | le16_to_cpu(hw_spec->hw_if_version), |
| 1613 | le16_to_cpu(hw_spec->version)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1614 | |
Avinash Patil | 8d05eb2 | 2015-01-28 15:42:01 +0530 | [diff] [blame] | 1615 | ether_addr_copy(priv->adapter->perm_addr, hw_spec->permanent_addr); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1616 | adapter->region_code = le16_to_cpu(hw_spec->region_code); |
| 1617 | |
| 1618 | for (i = 0; i < MWIFIEX_MAX_REGION_CODE; i++) |
| 1619 | /* Use the region code to search for the index */ |
| 1620 | if (adapter->region_code == region_code_index[i]) |
| 1621 | break; |
| 1622 | |
Amitkumar Karwar | 19b0a71 | 2015-12-14 04:15:14 -0800 | [diff] [blame] | 1623 | /* If it's unidentified region code, use the default (world) */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1624 | if (i >= MWIFIEX_MAX_REGION_CODE) { |
Amitkumar Karwar | 19b0a71 | 2015-12-14 04:15:14 -0800 | [diff] [blame] | 1625 | adapter->region_code = 0x00; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1626 | mwifiex_dbg(adapter, WARN, |
| 1627 | "cmd: unknown region code, use default (USA)\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | adapter->hw_dot_11n_dev_cap = le32_to_cpu(hw_spec->dot_11n_dev_cap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1631 | adapter->hw_dev_mcs_support = hw_spec->dev_mcs_support; |
Amitkumar Karwar | a533391 | 2014-02-27 19:35:18 -0800 | [diff] [blame] | 1632 | adapter->user_dev_mcs_support = adapter->hw_dev_mcs_support; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1633 | |
| 1634 | if (adapter->if_ops.update_mp_end_port) |
| 1635 | adapter->if_ops.update_mp_end_port(adapter, |
| 1636 | le16_to_cpu(hw_spec->mp_end_port)); |
| 1637 | |
Avinash Patil | cb91be8 | 2014-09-12 20:08:54 +0530 | [diff] [blame] | 1638 | if (adapter->fw_api_ver == MWIFIEX_FW_V15) |
| 1639 | adapter->scan_chan_gap_enabled = true; |
| 1640 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1641 | return 0; |
| 1642 | } |
chunfan chen | 8de00f1 | 2016-01-13 01:26:55 -0800 | [diff] [blame] | 1643 | |
| 1644 | /* This function handles the command response of hs wakeup reason |
| 1645 | * command. |
| 1646 | */ |
| 1647 | int mwifiex_ret_wakeup_reason(struct mwifiex_private *priv, |
| 1648 | struct host_cmd_ds_command *resp, |
| 1649 | struct host_cmd_ds_wakeup_reason *wakeup_reason) |
| 1650 | { |
| 1651 | wakeup_reason->wakeup_reason = |
| 1652 | resp->params.hs_wakeup_reason.wakeup_reason; |
| 1653 | |
| 1654 | return 0; |
| 1655 | } |