Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: major functions |
| 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 "main.h" |
| 21 | #include "wmm.h" |
| 22 | #include "cfg80211.h" |
| 23 | #include "11n.h" |
| 24 | |
| 25 | #define VERSION "1.0" |
| 26 | |
| 27 | const char driver_version[] = "mwifiex " VERSION " (%s) "; |
Amitkumar Karwar | 388ec38 | 2013-05-17 17:50:25 -0700 | [diff] [blame] | 28 | static char *cal_data_cfg; |
| 29 | module_param(cal_data_cfg, charp, 0); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 30 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 31 | /* |
| 32 | * This function registers the device and performs all the necessary |
| 33 | * initializations. |
| 34 | * |
| 35 | * The following initialization operations are performed - |
| 36 | * - Allocate adapter structure |
| 37 | * - Save interface specific operations table in adapter |
| 38 | * - Call interface specific initialization routine |
| 39 | * - Allocate private structures |
| 40 | * - Set default adapter structure parameters |
| 41 | * - Initialize locks |
| 42 | * |
| 43 | * In case of any errors during inittialization, this function also ensures |
| 44 | * proper cleanup before exiting. |
| 45 | */ |
| 46 | static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops, |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 47 | void **padapter) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 48 | { |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 49 | struct mwifiex_adapter *adapter; |
| 50 | int i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 51 | |
| 52 | adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 53 | if (!adapter) |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 54 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 55 | |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 56 | *padapter = adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 57 | adapter->card = card; |
| 58 | |
| 59 | /* Save interface specific operations in adapter */ |
| 60 | memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops)); |
| 61 | |
| 62 | /* card specific initialization has been deferred until now .. */ |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 63 | if (adapter->if_ops.init_if) |
| 64 | if (adapter->if_ops.init_if(adapter)) |
| 65 | goto error; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 66 | |
| 67 | adapter->priv_num = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 68 | |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 69 | for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { |
| 70 | /* Allocate memory for private structure */ |
| 71 | adapter->priv[i] = |
| 72 | kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL); |
| 73 | if (!adapter->priv[i]) |
| 74 | goto error; |
| 75 | |
| 76 | adapter->priv[i]->adapter = adapter; |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 77 | adapter->priv_num++; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 78 | } |
Amitkumar Karwar | 44b815c | 2011-09-29 20:43:41 -0700 | [diff] [blame] | 79 | mwifiex_init_lock_list(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 80 | |
| 81 | init_timer(&adapter->cmd_timer); |
| 82 | adapter->cmd_timer.function = mwifiex_cmd_timeout_func; |
| 83 | adapter->cmd_timer.data = (unsigned long) adapter; |
| 84 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | |
| 87 | error: |
| 88 | dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n"); |
| 89 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 90 | for (i = 0; i < adapter->priv_num; i++) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 91 | kfree(adapter->priv[i]); |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 92 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 93 | kfree(adapter); |
| 94 | |
| 95 | return -1; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * This function unregisters the device and performs all the necessary |
| 100 | * cleanups. |
| 101 | * |
| 102 | * The following cleanup operations are performed - |
| 103 | * - Free the timers |
| 104 | * - Free beacon buffers |
| 105 | * - Free private structures |
| 106 | * - Free adapter structure |
| 107 | */ |
| 108 | static int mwifiex_unregister(struct mwifiex_adapter *adapter) |
| 109 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 110 | s32 i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 111 | |
| 112 | del_timer(&adapter->cmd_timer); |
| 113 | |
| 114 | /* Free private structures */ |
| 115 | for (i = 0; i < adapter->priv_num; i++) { |
| 116 | if (adapter->priv[i]) { |
| 117 | mwifiex_free_curr_bcn(adapter->priv[i]); |
| 118 | kfree(adapter->priv[i]); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | kfree(adapter); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * The main process. |
| 128 | * |
| 129 | * This function is the main procedure of the driver and handles various driver |
| 130 | * operations. It runs in a loop and provides the core functionalities. |
| 131 | * |
| 132 | * The main responsibilities of this function are - |
| 133 | * - Ensure concurrency control |
| 134 | * - Handle pending interrupts and call interrupt handlers |
| 135 | * - Wake up the card if required |
| 136 | * - Handle command responses and call response handlers |
| 137 | * - Handle events and call event handlers |
| 138 | * - Execute pending commands |
| 139 | * - Transmit pending data packets |
| 140 | */ |
| 141 | int mwifiex_main_process(struct mwifiex_adapter *adapter) |
| 142 | { |
| 143 | int ret = 0; |
| 144 | unsigned long flags; |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 145 | struct sk_buff *skb; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 146 | |
| 147 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
| 148 | |
| 149 | /* Check if already processing */ |
| 150 | if (adapter->mwifiex_processing) { |
| 151 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 152 | goto exit_main_proc; |
| 153 | } else { |
| 154 | adapter->mwifiex_processing = true; |
| 155 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 156 | } |
| 157 | process_start: |
| 158 | do { |
| 159 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) || |
| 160 | (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)) |
| 161 | break; |
| 162 | |
| 163 | /* Handle pending interrupt if any */ |
| 164 | if (adapter->int_status) { |
| 165 | if (adapter->hs_activated) |
| 166 | mwifiex_process_hs_config(adapter); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 167 | if (adapter->if_ops.process_int_status) |
| 168 | adapter->if_ops.process_int_status(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* Need to wake up the card ? */ |
| 172 | if ((adapter->ps_state == PS_STATE_SLEEP) && |
| 173 | (adapter->pm_wakeup_card_req && |
| 174 | !adapter->pm_wakeup_fw_try) && |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 175 | (is_command_pending(adapter) || |
| 176 | !mwifiex_wmm_lists_empty(adapter))) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 177 | adapter->pm_wakeup_fw_try = true; |
| 178 | adapter->if_ops.wakeup(adapter); |
| 179 | continue; |
| 180 | } |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 181 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 182 | if (IS_CARD_RX_RCVD(adapter)) { |
| 183 | adapter->pm_wakeup_fw_try = false; |
| 184 | if (adapter->ps_state == PS_STATE_SLEEP) |
| 185 | adapter->ps_state = PS_STATE_AWAKE; |
| 186 | } else { |
| 187 | /* We have tried to wakeup the card already */ |
| 188 | if (adapter->pm_wakeup_fw_try) |
| 189 | break; |
| 190 | if (adapter->ps_state != PS_STATE_AWAKE || |
| 191 | adapter->tx_lock_flag) |
| 192 | break; |
| 193 | |
Amitkumar Karwar | f931c77 | 2012-06-20 19:58:36 -0700 | [diff] [blame] | 194 | if ((adapter->scan_processing && |
| 195 | !adapter->scan_delay_cnt) || adapter->data_sent || |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 196 | mwifiex_wmm_lists_empty(adapter)) { |
| 197 | if (adapter->cmd_sent || adapter->curr_cmd || |
| 198 | (!is_command_pending(adapter))) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 203 | /* Check Rx data for USB */ |
| 204 | if (adapter->iface_type == MWIFIEX_USB) |
| 205 | while ((skb = skb_dequeue(&adapter->usb_rx_data_q))) |
| 206 | mwifiex_handle_rx_packet(adapter, skb); |
| 207 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 208 | /* Check for Cmd Resp */ |
| 209 | if (adapter->cmd_resp_received) { |
| 210 | adapter->cmd_resp_received = false; |
| 211 | mwifiex_process_cmdresp(adapter); |
| 212 | |
| 213 | /* call mwifiex back when init_fw is done */ |
| 214 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) { |
| 215 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; |
| 216 | mwifiex_init_fw_complete(adapter); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /* Check for event */ |
| 221 | if (adapter->event_received) { |
| 222 | adapter->event_received = false; |
| 223 | mwifiex_process_event(adapter); |
| 224 | } |
| 225 | |
| 226 | /* Check if we need to confirm Sleep Request |
| 227 | received previously */ |
| 228 | if (adapter->ps_state == PS_STATE_PRE_SLEEP) { |
| 229 | if (!adapter->cmd_sent && !adapter->curr_cmd) |
| 230 | mwifiex_check_ps_cond(adapter); |
| 231 | } |
| 232 | |
| 233 | /* * The ps_state may have been changed during processing of |
| 234 | * Sleep Request event. |
| 235 | */ |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 236 | if ((adapter->ps_state == PS_STATE_SLEEP) || |
| 237 | (adapter->ps_state == PS_STATE_PRE_SLEEP) || |
| 238 | (adapter->ps_state == PS_STATE_SLEEP_CFM) || |
| 239 | adapter->tx_lock_flag) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 240 | continue; |
| 241 | |
| 242 | if (!adapter->cmd_sent && !adapter->curr_cmd) { |
| 243 | if (mwifiex_exec_next_cmd(adapter) == -1) { |
| 244 | ret = -1; |
| 245 | break; |
| 246 | } |
| 247 | } |
| 248 | |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 249 | if ((!adapter->scan_processing || adapter->scan_delay_cnt) && |
| 250 | !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 251 | mwifiex_wmm_process_tx(adapter); |
| 252 | if (adapter->hs_activated) { |
| 253 | adapter->is_hs_configured = false; |
| 254 | mwifiex_hs_activated_event |
| 255 | (mwifiex_get_priv |
| 256 | (adapter, MWIFIEX_BSS_ROLE_ANY), |
| 257 | false); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if (adapter->delay_null_pkt && !adapter->cmd_sent && |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 262 | !adapter->curr_cmd && !is_command_pending(adapter) && |
| 263 | mwifiex_wmm_lists_empty(adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 264 | if (!mwifiex_send_null_packet |
| 265 | (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA), |
| 266 | MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET | |
| 267 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) { |
| 268 | adapter->delay_null_pkt = false; |
| 269 | adapter->ps_state = PS_STATE_SLEEP; |
| 270 | } |
| 271 | break; |
| 272 | } |
| 273 | } while (true); |
| 274 | |
| 275 | if ((adapter->int_status) || IS_CARD_RX_RCVD(adapter)) |
| 276 | goto process_start; |
| 277 | |
| 278 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
| 279 | adapter->mwifiex_processing = false; |
| 280 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 281 | |
| 282 | exit_main_proc: |
| 283 | if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) |
| 284 | mwifiex_shutdown_drv(adapter); |
| 285 | return ret; |
| 286 | } |
Bing Zhao | 601216e | 2012-11-05 16:59:15 -0800 | [diff] [blame] | 287 | EXPORT_SYMBOL_GPL(mwifiex_main_process); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 288 | |
| 289 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 290 | * This function frees the adapter structure. |
| 291 | * |
| 292 | * Additionally, this closes the netlink socket, frees the timers |
| 293 | * and private structures. |
| 294 | */ |
| 295 | static void mwifiex_free_adapter(struct mwifiex_adapter *adapter) |
| 296 | { |
| 297 | if (!adapter) { |
| 298 | pr_err("%s: adapter is NULL\n", __func__); |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | mwifiex_unregister(adapter); |
| 303 | pr_debug("info: %s: free adapter\n", __func__); |
| 304 | } |
| 305 | |
| 306 | /* |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 307 | * This function gets firmware and initializes it. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 308 | * |
| 309 | * The main initialization steps followed are - |
| 310 | * - Download the correct firmware to card |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 311 | * - Issue the init commands to firmware |
| 312 | */ |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 313 | static void mwifiex_fw_dpc(const struct firmware *firmware, void *context) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 314 | { |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 315 | int ret; |
| 316 | char fmt[64]; |
| 317 | struct mwifiex_private *priv; |
| 318 | struct mwifiex_adapter *adapter = context; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 319 | struct mwifiex_fw_image fw; |
| 320 | |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 321 | if (!firmware) { |
| 322 | dev_err(adapter->dev, |
| 323 | "Failed to get firmware %s\n", adapter->fw_name); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 324 | goto done; |
| 325 | } |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 326 | |
| 327 | memset(&fw, 0, sizeof(struct mwifiex_fw_image)); |
| 328 | adapter->firmware = firmware; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 329 | fw.fw_buf = (u8 *) adapter->firmware->data; |
| 330 | fw.fw_len = adapter->firmware->size; |
| 331 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 332 | if (adapter->if_ops.dnld_fw) |
| 333 | ret = adapter->if_ops.dnld_fw(adapter, &fw); |
| 334 | else |
| 335 | ret = mwifiex_dnld_fw(adapter, &fw); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 336 | if (ret == -1) |
| 337 | goto done; |
| 338 | |
| 339 | dev_notice(adapter->dev, "WLAN FW is active\n"); |
| 340 | |
Amitkumar Karwar | 388ec38 | 2013-05-17 17:50:25 -0700 | [diff] [blame] | 341 | if (cal_data_cfg) { |
| 342 | if ((request_firmware(&adapter->cal_data, cal_data_cfg, |
| 343 | adapter->dev)) < 0) |
| 344 | dev_err(adapter->dev, |
| 345 | "Cal data request_firmware() failed\n"); |
| 346 | } |
| 347 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 348 | adapter->init_wait_q_woken = false; |
| 349 | ret = mwifiex_init_fw(adapter); |
| 350 | if (ret == -1) { |
| 351 | goto done; |
| 352 | } else if (!ret) { |
| 353 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; |
| 354 | goto done; |
| 355 | } |
| 356 | /* Wait for mwifiex_init to complete */ |
| 357 | wait_event_interruptible(adapter->init_wait_q, |
| 358 | adapter->init_wait_q_woken); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 359 | if (adapter->hw_status != MWIFIEX_HW_STATUS_READY) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 360 | goto done; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 361 | |
Avinash Patil | d6bffe8 | 2012-05-08 18:30:15 -0700 | [diff] [blame] | 362 | priv = adapter->priv[MWIFIEX_BSS_ROLE_STA]; |
| 363 | if (mwifiex_register_cfg80211(adapter)) { |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 364 | dev_err(adapter->dev, "cannot register with cfg80211\n"); |
| 365 | goto err_init_fw; |
| 366 | } |
| 367 | |
| 368 | rtnl_lock(); |
| 369 | /* Create station interface by default */ |
Avinash Patil | d6bffe8 | 2012-05-08 18:30:15 -0700 | [diff] [blame] | 370 | if (!mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 371 | NL80211_IFTYPE_STATION, NULL, NULL)) { |
| 372 | dev_err(adapter->dev, "cannot create default STA interface\n"); |
| 373 | goto err_add_intf; |
| 374 | } |
Avinash Patil | d6bffe8 | 2012-05-08 18:30:15 -0700 | [diff] [blame] | 375 | |
| 376 | /* Create AP interface by default */ |
| 377 | if (!mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", |
| 378 | NL80211_IFTYPE_AP, NULL, NULL)) { |
| 379 | dev_err(adapter->dev, "cannot create default AP interface\n"); |
| 380 | goto err_add_intf; |
| 381 | } |
Stone Piao | 197f4a2 | 2012-09-25 20:23:40 -0700 | [diff] [blame] | 382 | |
| 383 | /* Create P2P interface by default */ |
| 384 | if (!mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", |
| 385 | NL80211_IFTYPE_P2P_CLIENT, NULL, NULL)) { |
| 386 | dev_err(adapter->dev, "cannot create default P2P interface\n"); |
| 387 | goto err_add_intf; |
| 388 | } |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 389 | rtnl_unlock(); |
| 390 | |
| 391 | mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1); |
| 392 | dev_notice(adapter->dev, "driver_version = %s\n", fmt); |
| 393 | goto done; |
| 394 | |
| 395 | err_add_intf: |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 396 | mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 397 | rtnl_unlock(); |
| 398 | err_init_fw: |
| 399 | pr_debug("info: %s: unregister device\n", __func__); |
| 400 | adapter->if_ops.unregister_dev(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 401 | done: |
Amitkumar Karwar | 388ec38 | 2013-05-17 17:50:25 -0700 | [diff] [blame] | 402 | if (adapter->cal_data) { |
| 403 | release_firmware(adapter->cal_data); |
| 404 | adapter->cal_data = NULL; |
| 405 | } |
Jesper Juhl | 4fb25c5 | 2012-04-09 22:51:12 +0200 | [diff] [blame] | 406 | release_firmware(adapter->firmware); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 407 | complete(&adapter->fw_load); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * This function initializes the hardware and gets firmware. |
| 413 | */ |
| 414 | static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter) |
| 415 | { |
| 416 | int ret; |
| 417 | |
| 418 | init_completion(&adapter->fw_load); |
| 419 | ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name, |
| 420 | adapter->dev, GFP_KERNEL, adapter, |
| 421 | mwifiex_fw_dpc); |
| 422 | if (ret < 0) |
| 423 | dev_err(adapter->dev, |
| 424 | "request_firmware_nowait() returned error %d\n", ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 425 | return ret; |
| 426 | } |
| 427 | |
| 428 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 429 | * CFG802.11 network device handler for open. |
| 430 | * |
| 431 | * Starts the data queue. |
| 432 | */ |
| 433 | static int |
| 434 | mwifiex_open(struct net_device *dev) |
| 435 | { |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 436 | netif_tx_start_all_queues(dev); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * CFG802.11 network device handler for close. |
| 442 | */ |
| 443 | static int |
| 444 | mwifiex_close(struct net_device *dev) |
| 445 | { |
Amitkumar Karwar | f162cac | 2012-10-19 19:19:16 -0700 | [diff] [blame] | 446 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 447 | |
| 448 | if (priv->scan_request) { |
| 449 | dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n"); |
| 450 | cfg80211_scan_done(priv->scan_request, 1); |
| 451 | priv->scan_request = NULL; |
Amitkumar Karwar | 75ab753 | 2013-05-17 17:50:20 -0700 | [diff] [blame] | 452 | priv->scan_aborting = true; |
Amitkumar Karwar | f162cac | 2012-10-19 19:19:16 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | /* |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 459 | * Add buffer into wmm tx queue and queue work to transmit it. |
| 460 | */ |
| 461 | int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb) |
| 462 | { |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 463 | struct netdev_queue *txq; |
| 464 | int index = mwifiex_1d_to_wmm_queue[skb->priority]; |
| 465 | |
| 466 | if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) { |
| 467 | txq = netdev_get_tx_queue(priv->netdev, index); |
| 468 | if (!netif_tx_queue_stopped(txq)) { |
| 469 | netif_tx_stop_queue(txq); |
| 470 | dev_dbg(priv->adapter->dev, "stop queue: %d\n", index); |
| 471 | } |
| 472 | } |
| 473 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 474 | atomic_inc(&priv->adapter->tx_pending); |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 475 | mwifiex_wmm_add_buf_txqueue(priv, skb); |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 476 | |
| 477 | if (priv->adapter->scan_delay_cnt) |
| 478 | atomic_set(&priv->adapter->is_tx_received, true); |
| 479 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 480 | queue_work(priv->adapter->workqueue, &priv->adapter->main_work); |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 486 | * CFG802.11 network device handler for data transmission. |
| 487 | */ |
| 488 | static int |
| 489 | mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 490 | { |
| 491 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 492 | struct sk_buff *new_skb; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 493 | struct mwifiex_txinfo *tx_info; |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 494 | struct timeval tv; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 495 | |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 496 | dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 497 | jiffies, priv->bss_type, priv->bss_num); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 498 | |
| 499 | if (priv->adapter->surprise_removed) { |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 500 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 501 | priv->stats.tx_dropped++; |
| 502 | return 0; |
| 503 | } |
| 504 | if (!skb->len || (skb->len > ETH_FRAME_LEN)) { |
| 505 | dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len); |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 506 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 507 | priv->stats.tx_dropped++; |
| 508 | return 0; |
| 509 | } |
| 510 | if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) { |
| 511 | dev_dbg(priv->adapter->dev, |
| 512 | "data: Tx: insufficient skb headroom %d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 513 | skb_headroom(skb)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 514 | /* Insufficient skb headroom - allocate a new skb */ |
| 515 | new_skb = |
| 516 | skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN); |
| 517 | if (unlikely(!new_skb)) { |
| 518 | dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n"); |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 519 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 520 | priv->stats.tx_dropped++; |
| 521 | return 0; |
| 522 | } |
| 523 | kfree_skb(skb); |
| 524 | skb = new_skb; |
| 525 | dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 526 | skb_headroom(skb)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | tx_info = MWIFIEX_SKB_TXCB(skb); |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 530 | tx_info->bss_num = priv->bss_num; |
| 531 | tx_info->bss_type = priv->bss_type; |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 532 | |
| 533 | /* Record the current time the packet was queued; used to |
| 534 | * determine the amount of time the packet was queued in |
| 535 | * the driver before it was sent to the firmware. |
| 536 | * The delay is then sent along with the packet to the |
| 537 | * firmware for aggregate delay calculation for stats and |
| 538 | * MSDU lifetime expiry. |
| 539 | */ |
| 540 | do_gettimeofday(&tv); |
| 541 | skb->tstamp = timeval_to_ktime(tv); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 542 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 543 | mwifiex_queue_tx_pkt(priv, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * CFG802.11 network device handler for setting MAC address. |
| 550 | */ |
| 551 | static int |
| 552 | mwifiex_set_mac_address(struct net_device *dev, void *addr) |
| 553 | { |
| 554 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 555 | struct sockaddr *hw_addr = addr; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 556 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 557 | |
| 558 | memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN); |
| 559 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 560 | /* Send request to firmware */ |
| 561 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_MAC_ADDRESS, |
| 562 | HostCmd_ACT_GEN_SET, 0, NULL); |
| 563 | |
| 564 | if (!ret) |
| 565 | memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN); |
| 566 | else |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 567 | dev_err(priv->adapter->dev, |
| 568 | "set mac address failed: ret=%d\n", ret); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 569 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 570 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
| 571 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 572 | return ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /* |
| 576 | * CFG802.11 network device handler for setting multicast list. |
| 577 | */ |
| 578 | static void mwifiex_set_multicast_list(struct net_device *dev) |
| 579 | { |
| 580 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 581 | struct mwifiex_multicast_list mcast_list; |
| 582 | |
| 583 | if (dev->flags & IFF_PROMISC) { |
| 584 | mcast_list.mode = MWIFIEX_PROMISC_MODE; |
| 585 | } else if (dev->flags & IFF_ALLMULTI || |
| 586 | netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) { |
| 587 | mcast_list.mode = MWIFIEX_ALL_MULTI_MODE; |
| 588 | } else { |
| 589 | mcast_list.mode = MWIFIEX_MULTICAST_MODE; |
| 590 | if (netdev_mc_count(dev)) |
| 591 | mcast_list.num_multicast_addr = |
| 592 | mwifiex_copy_mcast_addr(&mcast_list, dev); |
| 593 | } |
| 594 | mwifiex_request_set_multicast_list(priv, &mcast_list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* |
| 598 | * CFG802.11 network device handler for transmission timeout. |
| 599 | */ |
| 600 | static void |
| 601 | mwifiex_tx_timeout(struct net_device *dev) |
| 602 | { |
| 603 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 604 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 605 | priv->num_tx_timeout++; |
Ashok Nagarajan | 8908c7d | 2013-03-08 10:58:45 -0800 | [diff] [blame] | 606 | priv->tx_timeout_cnt++; |
| 607 | dev_err(priv->adapter->dev, |
| 608 | "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n", |
| 609 | jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num); |
| 610 | mwifiex_set_trans_start(dev); |
| 611 | |
| 612 | if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD && |
| 613 | priv->adapter->if_ops.card_reset) { |
| 614 | dev_err(priv->adapter->dev, |
| 615 | "tx_timeout_cnt exceeds threshold. Triggering card reset!\n"); |
| 616 | priv->adapter->if_ops.card_reset(priv->adapter); |
| 617 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | /* |
| 621 | * CFG802.11 network device handler for statistics retrieval. |
| 622 | */ |
| 623 | static struct net_device_stats *mwifiex_get_stats(struct net_device *dev) |
| 624 | { |
| 625 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 626 | |
| 627 | return &priv->stats; |
| 628 | } |
| 629 | |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 630 | static u16 |
| 631 | mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb) |
| 632 | { |
| 633 | skb->priority = cfg80211_classify8021d(skb); |
| 634 | return mwifiex_1d_to_wmm_queue[skb->priority]; |
| 635 | } |
| 636 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 637 | /* Network device handlers */ |
| 638 | static const struct net_device_ops mwifiex_netdev_ops = { |
| 639 | .ndo_open = mwifiex_open, |
| 640 | .ndo_stop = mwifiex_close, |
| 641 | .ndo_start_xmit = mwifiex_hard_start_xmit, |
| 642 | .ndo_set_mac_address = mwifiex_set_mac_address, |
| 643 | .ndo_tx_timeout = mwifiex_tx_timeout, |
| 644 | .ndo_get_stats = mwifiex_get_stats, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 645 | .ndo_set_rx_mode = mwifiex_set_multicast_list, |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 646 | .ndo_select_queue = mwifiex_netdev_select_wmm_queue, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 647 | }; |
| 648 | |
| 649 | /* |
| 650 | * This function initializes the private structure parameters. |
| 651 | * |
| 652 | * The following wait queues are initialized - |
| 653 | * - IOCTL wait queue |
| 654 | * - Command wait queue |
| 655 | * - Statistics wait queue |
| 656 | * |
| 657 | * ...and the following default parameters are set - |
| 658 | * - Current key index : Set to 0 |
| 659 | * - Rate index : Set to auto |
| 660 | * - Media connected : Set to disconnected |
| 661 | * - Adhoc link sensed : Set to false |
| 662 | * - Nick name : Set to null |
| 663 | * - Number of Tx timeout : Set to 0 |
| 664 | * - Device address : Set to current address |
| 665 | * |
| 666 | * In addition, the CFG80211 work queue is also created. |
| 667 | */ |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 668 | void mwifiex_init_priv_params(struct mwifiex_private *priv, |
| 669 | struct net_device *dev) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 670 | { |
| 671 | dev->netdev_ops = &mwifiex_netdev_ops; |
Amitkumar Karwar | f16fdc9 | 2013-05-06 19:46:54 -0700 | [diff] [blame] | 672 | dev->destructor = free_netdev; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 673 | /* Initialize private structure */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 674 | priv->current_key_index = 0; |
| 675 | priv->media_connected = false; |
| 676 | memset(&priv->nick_name, 0, sizeof(priv->nick_name)); |
Avinash Patil | ede98bf | 2012-05-08 18:30:28 -0700 | [diff] [blame] | 677 | memset(priv->mgmt_ie, 0, |
| 678 | sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX); |
Avinash Patil | f31acab | 2012-05-08 18:30:29 -0700 | [diff] [blame] | 679 | priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK; |
| 680 | priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK; |
| 681 | priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK; |
| 682 | priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 683 | priv->num_tx_timeout = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 684 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
| 685 | } |
| 686 | |
| 687 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 688 | * This function check if command is pending. |
| 689 | */ |
| 690 | int is_command_pending(struct mwifiex_adapter *adapter) |
| 691 | { |
| 692 | unsigned long flags; |
| 693 | int is_cmd_pend_q_empty; |
| 694 | |
| 695 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); |
| 696 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); |
| 697 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); |
| 698 | |
| 699 | return !is_cmd_pend_q_empty; |
| 700 | } |
| 701 | |
| 702 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 703 | * This is the main work queue function. |
| 704 | * |
| 705 | * It handles the main process, which in turn handles the complete |
| 706 | * driver operations. |
| 707 | */ |
| 708 | static void mwifiex_main_work_queue(struct work_struct *work) |
| 709 | { |
| 710 | struct mwifiex_adapter *adapter = |
| 711 | container_of(work, struct mwifiex_adapter, main_work); |
| 712 | |
| 713 | if (adapter->surprise_removed) |
| 714 | return; |
| 715 | mwifiex_main_process(adapter); |
| 716 | } |
| 717 | |
| 718 | /* |
| 719 | * This function cancels all works in the queue and destroys |
| 720 | * the main workqueue. |
| 721 | */ |
| 722 | static void |
| 723 | mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter) |
| 724 | { |
| 725 | flush_workqueue(adapter->workqueue); |
| 726 | destroy_workqueue(adapter->workqueue); |
| 727 | adapter->workqueue = NULL; |
| 728 | } |
| 729 | |
| 730 | /* |
| 731 | * This function adds the card. |
| 732 | * |
| 733 | * This function follows the following major steps to set up the device - |
| 734 | * - Initialize software. This includes probing the card, registering |
| 735 | * the interface operations table, and allocating/initializing the |
| 736 | * adapter structure |
| 737 | * - Set up the netlink socket |
| 738 | * - Create and start the main work queue |
| 739 | * - Register the device |
| 740 | * - Initialize firmware and hardware |
| 741 | * - Add logical interfaces |
| 742 | */ |
| 743 | int |
| 744 | mwifiex_add_card(void *card, struct semaphore *sem, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 745 | struct mwifiex_if_ops *if_ops, u8 iface_type) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 746 | { |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 747 | struct mwifiex_adapter *adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 748 | |
| 749 | if (down_interruptible(sem)) |
| 750 | goto exit_sem_err; |
| 751 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 752 | if (mwifiex_register(card, if_ops, (void **)&adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 753 | pr_err("%s: software init failed\n", __func__); |
| 754 | goto err_init_sw; |
| 755 | } |
| 756 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 757 | adapter->iface_type = iface_type; |
| 758 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 759 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 760 | adapter->surprise_removed = false; |
| 761 | init_waitqueue_head(&adapter->init_wait_q); |
| 762 | adapter->is_suspended = false; |
| 763 | adapter->hs_activated = false; |
| 764 | init_waitqueue_head(&adapter->hs_activate_wait_q); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 765 | adapter->cmd_wait_q_required = false; |
| 766 | init_waitqueue_head(&adapter->cmd_wait_q.wait); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 767 | adapter->cmd_wait_q.status = 0; |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 768 | adapter->scan_wait_q_woken = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 769 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 770 | adapter->workqueue = create_workqueue("MWIFIEX_WORK_QUEUE"); |
| 771 | if (!adapter->workqueue) |
| 772 | goto err_kmalloc; |
| 773 | |
| 774 | INIT_WORK(&adapter->main_work, mwifiex_main_work_queue); |
| 775 | |
| 776 | /* Register the device. Fill up the private data structure with relevant |
| 777 | information from the card and request for the required IRQ. */ |
| 778 | if (adapter->if_ops.register_dev(adapter)) { |
| 779 | pr_err("%s: failed to register mwifiex device\n", __func__); |
| 780 | goto err_registerdev; |
| 781 | } |
| 782 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 783 | if (mwifiex_init_hw_fw(adapter)) { |
| 784 | pr_err("%s: firmware init failed\n", __func__); |
| 785 | goto err_init_fw; |
| 786 | } |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 787 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 788 | up(sem); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 789 | return 0; |
| 790 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 791 | err_init_fw: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 792 | pr_debug("info: %s: unregister device\n", __func__); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 793 | if (adapter->if_ops.unregister_dev) |
| 794 | adapter->if_ops.unregister_dev(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 795 | err_registerdev: |
| 796 | adapter->surprise_removed = true; |
| 797 | mwifiex_terminate_workqueue(adapter); |
| 798 | err_kmalloc: |
| 799 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) || |
| 800 | (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) { |
| 801 | pr_debug("info: %s: shutdown mwifiex\n", __func__); |
| 802 | adapter->init_wait_q_woken = false; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 803 | |
| 804 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 805 | wait_event_interruptible(adapter->init_wait_q, |
| 806 | adapter->init_wait_q_woken); |
| 807 | } |
| 808 | |
| 809 | mwifiex_free_adapter(adapter); |
| 810 | |
| 811 | err_init_sw: |
| 812 | up(sem); |
| 813 | |
| 814 | exit_sem_err: |
| 815 | return -1; |
| 816 | } |
| 817 | EXPORT_SYMBOL_GPL(mwifiex_add_card); |
| 818 | |
| 819 | /* |
| 820 | * This function removes the card. |
| 821 | * |
| 822 | * This function follows the following major steps to remove the device - |
| 823 | * - Stop data traffic |
| 824 | * - Shutdown firmware |
| 825 | * - Remove the logical interfaces |
| 826 | * - Terminate the work queue |
| 827 | * - Unregister the device |
| 828 | * - Free the adapter structure |
| 829 | */ |
| 830 | int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem) |
| 831 | { |
| 832 | struct mwifiex_private *priv = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 833 | int i; |
| 834 | |
| 835 | if (down_interruptible(sem)) |
| 836 | goto exit_sem_err; |
| 837 | |
| 838 | if (!adapter) |
| 839 | goto exit_remove; |
| 840 | |
| 841 | adapter->surprise_removed = true; |
| 842 | |
| 843 | /* Stop data */ |
| 844 | for (i = 0; i < adapter->priv_num; i++) { |
| 845 | priv = adapter->priv[i]; |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 846 | if (priv && priv->netdev) { |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 847 | mwifiex_stop_net_dev_queue(priv->netdev, adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 848 | if (netif_carrier_ok(priv->netdev)) |
| 849 | netif_carrier_off(priv->netdev); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n"); |
| 854 | adapter->init_wait_q_woken = false; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 855 | |
| 856 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 857 | wait_event_interruptible(adapter->init_wait_q, |
| 858 | adapter->init_wait_q_woken); |
| 859 | dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n"); |
| 860 | if (atomic_read(&adapter->rx_pending) || |
| 861 | atomic_read(&adapter->tx_pending) || |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 862 | atomic_read(&adapter->cmd_pending)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 863 | dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, " |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 864 | "cmd_pending=%d\n", |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 865 | atomic_read(&adapter->rx_pending), |
| 866 | atomic_read(&adapter->tx_pending), |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 867 | atomic_read(&adapter->cmd_pending)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 870 | for (i = 0; i < adapter->priv_num; i++) { |
| 871 | priv = adapter->priv[i]; |
| 872 | |
| 873 | if (!priv) |
| 874 | continue; |
| 875 | |
| 876 | rtnl_lock(); |
Amitkumar Karwar | 2da8cbf | 2012-02-03 20:34:02 -0800 | [diff] [blame] | 877 | if (priv->wdev && priv->netdev) |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 878 | mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev); |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 879 | rtnl_unlock(); |
| 880 | } |
| 881 | |
Yogesh Ashok Powar | 3d82de0 | 2011-10-05 14:58:24 -0700 | [diff] [blame] | 882 | priv = adapter->priv[0]; |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 883 | if (!priv || !priv->wdev) |
Yogesh Ashok Powar | 3d82de0 | 2011-10-05 14:58:24 -0700 | [diff] [blame] | 884 | goto exit_remove; |
| 885 | |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 886 | wiphy_unregister(priv->wdev->wiphy); |
| 887 | wiphy_free(priv->wdev->wiphy); |
| 888 | |
| 889 | for (i = 0; i < adapter->priv_num; i++) { |
| 890 | priv = adapter->priv[i]; |
| 891 | if (priv) |
| 892 | kfree(priv->wdev); |
Amitkumar Karwar | 2da8cbf | 2012-02-03 20:34:02 -0800 | [diff] [blame] | 893 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 894 | |
| 895 | mwifiex_terminate_workqueue(adapter); |
| 896 | |
| 897 | /* Unregister device */ |
| 898 | dev_dbg(adapter->dev, "info: unregister device\n"); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 899 | if (adapter->if_ops.unregister_dev) |
| 900 | adapter->if_ops.unregister_dev(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 901 | /* Free adapter structure */ |
| 902 | dev_dbg(adapter->dev, "info: free adapter\n"); |
| 903 | mwifiex_free_adapter(adapter); |
| 904 | |
| 905 | exit_remove: |
| 906 | up(sem); |
| 907 | exit_sem_err: |
| 908 | return 0; |
| 909 | } |
| 910 | EXPORT_SYMBOL_GPL(mwifiex_remove_card); |
| 911 | |
| 912 | /* |
| 913 | * This function initializes the module. |
| 914 | * |
| 915 | * The debug FS is also initialized if configured. |
| 916 | */ |
| 917 | static int |
| 918 | mwifiex_init_module(void) |
| 919 | { |
| 920 | #ifdef CONFIG_DEBUG_FS |
| 921 | mwifiex_debugfs_init(); |
| 922 | #endif |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | /* |
| 927 | * This function cleans up the module. |
| 928 | * |
| 929 | * The debug FS is removed if available. |
| 930 | */ |
| 931 | static void |
| 932 | mwifiex_cleanup_module(void) |
| 933 | { |
| 934 | #ifdef CONFIG_DEBUG_FS |
| 935 | mwifiex_debugfs_remove(); |
| 936 | #endif |
| 937 | } |
| 938 | |
| 939 | module_init(mwifiex_init_module); |
| 940 | module_exit(mwifiex_cleanup_module); |
| 941 | |
| 942 | MODULE_AUTHOR("Marvell International Ltd."); |
| 943 | MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION); |
| 944 | MODULE_VERSION(VERSION); |
| 945 | MODULE_LICENSE("GPL v2"); |