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