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