Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: major functions |
| 3 | * |
Xinming Hu | 65da33f | 2014-06-19 21:38:57 -0700 | [diff] [blame] | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include "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 | |
Avinash Patil | 0013c7c | 2014-11-05 19:38:11 +0530 | [diff] [blame] | 31 | static unsigned short driver_mode; |
| 32 | module_param(driver_mode, ushort, 0); |
| 33 | MODULE_PARM_DESC(driver_mode, |
| 34 | "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7"); |
| 35 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 36 | /* |
| 37 | * This function registers the device and performs all the necessary |
| 38 | * initializations. |
| 39 | * |
| 40 | * The following initialization operations are performed - |
| 41 | * - Allocate adapter structure |
| 42 | * - Save interface specific operations table in adapter |
| 43 | * - Call interface specific initialization routine |
| 44 | * - Allocate private structures |
| 45 | * - Set default adapter structure parameters |
| 46 | * - Initialize locks |
| 47 | * |
| 48 | * In case of any errors during inittialization, this function also ensures |
| 49 | * proper cleanup before exiting. |
| 50 | */ |
| 51 | static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops, |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 52 | void **padapter) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 53 | { |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 54 | struct mwifiex_adapter *adapter; |
| 55 | int i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 56 | |
| 57 | adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 58 | if (!adapter) |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 59 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 60 | |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 61 | *padapter = adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 62 | adapter->card = card; |
| 63 | |
| 64 | /* Save interface specific operations in adapter */ |
| 65 | memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops)); |
| 66 | |
| 67 | /* card specific initialization has been deferred until now .. */ |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 68 | if (adapter->if_ops.init_if) |
| 69 | if (adapter->if_ops.init_if(adapter)) |
| 70 | goto error; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 71 | |
| 72 | adapter->priv_num = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 73 | |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 74 | for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { |
| 75 | /* Allocate memory for private structure */ |
| 76 | adapter->priv[i] = |
| 77 | kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL); |
| 78 | if (!adapter->priv[i]) |
| 79 | goto error; |
| 80 | |
| 81 | adapter->priv[i]->adapter = adapter; |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 82 | adapter->priv_num++; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 83 | } |
Amitkumar Karwar | 44b815c | 2011-09-29 20:43:41 -0700 | [diff] [blame] | 84 | mwifiex_init_lock_list(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 85 | |
Julia Lawall | c6c33e7 | 2014-12-26 15:35:56 +0100 | [diff] [blame] | 86 | setup_timer(&adapter->cmd_timer, mwifiex_cmd_timeout_func, |
| 87 | (unsigned long)adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 88 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 89 | return 0; |
| 90 | |
| 91 | error: |
| 92 | dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n"); |
| 93 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 94 | for (i = 0; i < adapter->priv_num; i++) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 95 | kfree(adapter->priv[i]); |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 96 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 97 | kfree(adapter); |
| 98 | |
| 99 | return -1; |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | * This function unregisters the device and performs all the necessary |
| 104 | * cleanups. |
| 105 | * |
| 106 | * The following cleanup operations are performed - |
| 107 | * - Free the timers |
| 108 | * - Free beacon buffers |
| 109 | * - Free private structures |
| 110 | * - Free adapter structure |
| 111 | */ |
| 112 | static int mwifiex_unregister(struct mwifiex_adapter *adapter) |
| 113 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 114 | s32 i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 115 | |
Amitkumar Karwar | 4cfda67 | 2013-07-22 19:17:50 -0700 | [diff] [blame] | 116 | if (adapter->if_ops.cleanup_if) |
| 117 | adapter->if_ops.cleanup_if(adapter); |
| 118 | |
Avinash Patil | 629873f | 2014-02-18 15:47:55 -0800 | [diff] [blame] | 119 | del_timer_sync(&adapter->cmd_timer); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 120 | |
| 121 | /* Free private structures */ |
| 122 | for (i = 0; i < adapter->priv_num; i++) { |
| 123 | if (adapter->priv[i]) { |
| 124 | mwifiex_free_curr_bcn(adapter->priv[i]); |
| 125 | kfree(adapter->priv[i]); |
| 126 | } |
| 127 | } |
| 128 | |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 129 | vfree(adapter->chan_stats); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 130 | kfree(adapter); |
| 131 | return 0; |
| 132 | } |
| 133 | |
Shengzhen Li | b2713f6 | 2015-03-13 17:37:54 +0530 | [diff] [blame] | 134 | void mwifiex_queue_main_work(struct mwifiex_adapter *adapter) |
| 135 | { |
| 136 | unsigned long flags; |
| 137 | |
| 138 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
| 139 | if (adapter->mwifiex_processing) { |
| 140 | adapter->more_task_flag = true; |
| 141 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 142 | } else { |
| 143 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 144 | queue_work(adapter->workqueue, &adapter->main_work); |
| 145 | } |
| 146 | } |
| 147 | EXPORT_SYMBOL_GPL(mwifiex_queue_main_work); |
| 148 | |
| 149 | static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter) |
| 150 | { |
| 151 | unsigned long flags; |
| 152 | |
| 153 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); |
| 154 | if (adapter->rx_processing) { |
| 155 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); |
| 156 | } else { |
| 157 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); |
| 158 | queue_work(adapter->rx_workqueue, &adapter->rx_work); |
| 159 | } |
| 160 | } |
| 161 | |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 162 | static int mwifiex_process_rx(struct mwifiex_adapter *adapter) |
| 163 | { |
| 164 | unsigned long flags; |
| 165 | struct sk_buff *skb; |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 166 | struct mwifiex_rxinfo *rx_info; |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 167 | |
| 168 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); |
| 169 | if (adapter->rx_processing || adapter->rx_locked) { |
| 170 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); |
| 171 | goto exit_rx_proc; |
| 172 | } else { |
| 173 | adapter->rx_processing = true; |
| 174 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); |
| 175 | } |
| 176 | |
| 177 | /* Check for Rx data */ |
| 178 | while ((skb = skb_dequeue(&adapter->rx_data_q))) { |
| 179 | atomic_dec(&adapter->rx_pending); |
Amitkumar Karwar | 381e9ff | 2014-11-25 06:43:04 -0800 | [diff] [blame] | 180 | if ((adapter->delay_main_work || |
| 181 | adapter->iface_type == MWIFIEX_USB) && |
Avinash Patil | b43a0d9 | 2014-09-29 21:44:14 +0530 | [diff] [blame] | 182 | (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) { |
Amitkumar Karwar | cf6a64f | 2014-11-05 17:04:29 +0530 | [diff] [blame] | 183 | if (adapter->if_ops.submit_rem_rx_urbs) |
| 184 | adapter->if_ops.submit_rem_rx_urbs(adapter); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 185 | adapter->delay_main_work = false; |
Shengzhen Li | b2713f6 | 2015-03-13 17:37:54 +0530 | [diff] [blame] | 186 | mwifiex_queue_main_work(adapter); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 187 | } |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 188 | rx_info = MWIFIEX_SKB_RXCB(skb); |
| 189 | if (rx_info->buf_type == MWIFIEX_TYPE_AGGR_DATA) { |
| 190 | if (adapter->if_ops.deaggr_pkt) |
| 191 | adapter->if_ops.deaggr_pkt(adapter, skb); |
| 192 | dev_kfree_skb_any(skb); |
| 193 | } else { |
| 194 | mwifiex_handle_rx_packet(adapter, skb); |
| 195 | } |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 196 | } |
| 197 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); |
| 198 | adapter->rx_processing = false; |
| 199 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); |
| 200 | |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 201 | exit_rx_proc: |
| 202 | return 0; |
| 203 | } |
| 204 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 205 | /* |
| 206 | * The main process. |
| 207 | * |
| 208 | * This function is the main procedure of the driver and handles various driver |
| 209 | * operations. It runs in a loop and provides the core functionalities. |
| 210 | * |
| 211 | * The main responsibilities of this function are - |
| 212 | * - Ensure concurrency control |
| 213 | * - Handle pending interrupts and call interrupt handlers |
| 214 | * - Wake up the card if required |
| 215 | * - Handle command responses and call response handlers |
| 216 | * - Handle events and call event handlers |
| 217 | * - Execute pending commands |
| 218 | * - Transmit pending data packets |
| 219 | */ |
| 220 | int mwifiex_main_process(struct mwifiex_adapter *adapter) |
| 221 | { |
| 222 | int ret = 0; |
| 223 | unsigned long flags; |
| 224 | |
| 225 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
| 226 | |
| 227 | /* Check if already processing */ |
Avinash Patil | a9adbcb | 2015-03-13 17:37:51 +0530 | [diff] [blame] | 228 | if (adapter->mwifiex_processing || adapter->main_locked) { |
Shengzhen Li | 04c7b36 | 2015-02-11 23:12:24 +0530 | [diff] [blame] | 229 | adapter->more_task_flag = true; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 230 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 231 | goto exit_main_proc; |
| 232 | } else { |
| 233 | adapter->mwifiex_processing = true; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 234 | } |
| 235 | process_start: |
| 236 | do { |
Shengzhen Li | 04c7b36 | 2015-02-11 23:12:24 +0530 | [diff] [blame] | 237 | adapter->more_task_flag = false; |
| 238 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 239 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) || |
| 240 | (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)) |
| 241 | break; |
| 242 | |
Amitkumar Karwar | 381e9ff | 2014-11-25 06:43:04 -0800 | [diff] [blame] | 243 | /* For non-USB interfaces, If we process interrupts first, it |
| 244 | * would increase RX pending even further. Avoid this by |
| 245 | * checking if rx_pending has crossed high threshold and |
| 246 | * schedule rx work queue and then process interrupts. |
| 247 | * For USB interface, there are no interrupts. We already have |
| 248 | * HIGH_RX_PENDING check in usb.c |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 249 | */ |
Amitkumar Karwar | 381e9ff | 2014-11-25 06:43:04 -0800 | [diff] [blame] | 250 | if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING && |
| 251 | adapter->iface_type != MWIFIEX_USB) { |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 252 | adapter->delay_main_work = true; |
Shengzhen Li | b2713f6 | 2015-03-13 17:37:54 +0530 | [diff] [blame] | 253 | mwifiex_queue_rx_work(adapter); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 254 | break; |
| 255 | } |
| 256 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 257 | /* Handle pending interrupt if any */ |
| 258 | if (adapter->int_status) { |
| 259 | if (adapter->hs_activated) |
| 260 | mwifiex_process_hs_config(adapter); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 261 | if (adapter->if_ops.process_int_status) |
| 262 | adapter->if_ops.process_int_status(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 265 | if (adapter->rx_work_enabled && adapter->data_received) |
Shengzhen Li | b2713f6 | 2015-03-13 17:37:54 +0530 | [diff] [blame] | 266 | mwifiex_queue_rx_work(adapter); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 267 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 268 | /* Need to wake up the card ? */ |
| 269 | if ((adapter->ps_state == PS_STATE_SLEEP) && |
| 270 | (adapter->pm_wakeup_card_req && |
| 271 | !adapter->pm_wakeup_fw_try) && |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 272 | (is_command_pending(adapter) || |
Zhaoyang Liu | e35000e | 2015-03-13 17:37:57 +0530 | [diff] [blame] | 273 | !skb_queue_empty(&adapter->tx_data_q) || |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 274 | !mwifiex_wmm_lists_empty(adapter))) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 275 | adapter->pm_wakeup_fw_try = true; |
Amitkumar Karwar | 4636187 | 2014-12-31 02:36:41 -0800 | [diff] [blame] | 276 | mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 277 | adapter->if_ops.wakeup(adapter); |
Shengzhen Li | 04c7b36 | 2015-02-11 23:12:24 +0530 | [diff] [blame] | 278 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 279 | continue; |
| 280 | } |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 281 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 282 | if (IS_CARD_RX_RCVD(adapter)) { |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 283 | adapter->data_received = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 284 | adapter->pm_wakeup_fw_try = false; |
Amitkumar Karwar | 6e9344f | 2015-03-12 00:38:40 -0700 | [diff] [blame] | 285 | del_timer(&adapter->wakeup_timer); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 286 | if (adapter->ps_state == PS_STATE_SLEEP) |
| 287 | adapter->ps_state = PS_STATE_AWAKE; |
| 288 | } else { |
| 289 | /* We have tried to wakeup the card already */ |
| 290 | if (adapter->pm_wakeup_fw_try) |
| 291 | break; |
| 292 | if (adapter->ps_state != PS_STATE_AWAKE || |
| 293 | adapter->tx_lock_flag) |
| 294 | break; |
| 295 | |
Avinash Patil | 5ec39ef | 2014-09-12 20:08:56 +0530 | [diff] [blame] | 296 | if ((!adapter->scan_chan_gap_enabled && |
Avinash Patil | 5ec39ef | 2014-09-12 20:08:56 +0530 | [diff] [blame] | 297 | adapter->scan_processing) || adapter->data_sent || |
Zhaoyang Liu | e35000e | 2015-03-13 17:37:57 +0530 | [diff] [blame] | 298 | (mwifiex_wmm_lists_empty(adapter) && |
| 299 | skb_queue_empty(&adapter->tx_data_q))) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 300 | if (adapter->cmd_sent || adapter->curr_cmd || |
| 301 | (!is_command_pending(adapter))) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | } |
| 305 | |
Amitkumar Karwar | 2047412 | 2014-04-14 15:31:05 -0700 | [diff] [blame] | 306 | /* Check for event */ |
| 307 | if (adapter->event_received) { |
| 308 | adapter->event_received = false; |
| 309 | mwifiex_process_event(adapter); |
| 310 | } |
| 311 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 312 | /* Check for Cmd Resp */ |
| 313 | if (adapter->cmd_resp_received) { |
| 314 | adapter->cmd_resp_received = false; |
| 315 | mwifiex_process_cmdresp(adapter); |
| 316 | |
| 317 | /* call mwifiex back when init_fw is done */ |
| 318 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) { |
| 319 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; |
| 320 | mwifiex_init_fw_complete(adapter); |
| 321 | } |
| 322 | } |
| 323 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 324 | /* Check if we need to confirm Sleep Request |
| 325 | received previously */ |
| 326 | if (adapter->ps_state == PS_STATE_PRE_SLEEP) { |
| 327 | if (!adapter->cmd_sent && !adapter->curr_cmd) |
| 328 | mwifiex_check_ps_cond(adapter); |
| 329 | } |
| 330 | |
| 331 | /* * The ps_state may have been changed during processing of |
| 332 | * Sleep Request event. |
| 333 | */ |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 334 | if ((adapter->ps_state == PS_STATE_SLEEP) || |
| 335 | (adapter->ps_state == PS_STATE_PRE_SLEEP) || |
| 336 | (adapter->ps_state == PS_STATE_SLEEP_CFM) || |
Shengzhen Li | 04c7b36 | 2015-02-11 23:12:24 +0530 | [diff] [blame] | 337 | adapter->tx_lock_flag){ |
| 338 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 339 | continue; |
Shengzhen Li | 04c7b36 | 2015-02-11 23:12:24 +0530 | [diff] [blame] | 340 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 341 | |
| 342 | if (!adapter->cmd_sent && !adapter->curr_cmd) { |
| 343 | if (mwifiex_exec_next_cmd(adapter) == -1) { |
| 344 | ret = -1; |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | |
Avinash Patil | 5ec39ef | 2014-09-12 20:08:56 +0530 | [diff] [blame] | 349 | if ((adapter->scan_chan_gap_enabled || |
Amitkumar Karwar | d8d9125 | 2014-09-12 20:08:58 +0530 | [diff] [blame] | 350 | !adapter->scan_processing) && |
Zhaoyang Liu | e35000e | 2015-03-13 17:37:57 +0530 | [diff] [blame] | 351 | !adapter->data_sent && |
| 352 | !skb_queue_empty(&adapter->tx_data_q)) { |
| 353 | mwifiex_process_tx_queue(adapter); |
| 354 | if (adapter->hs_activated) { |
| 355 | adapter->is_hs_configured = false; |
| 356 | mwifiex_hs_activated_event |
| 357 | (mwifiex_get_priv |
| 358 | (adapter, MWIFIEX_BSS_ROLE_ANY), |
| 359 | false); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if ((adapter->scan_chan_gap_enabled || |
| 364 | !adapter->scan_processing) && |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 365 | !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 366 | mwifiex_wmm_process_tx(adapter); |
| 367 | if (adapter->hs_activated) { |
| 368 | adapter->is_hs_configured = false; |
| 369 | mwifiex_hs_activated_event |
| 370 | (mwifiex_get_priv |
| 371 | (adapter, MWIFIEX_BSS_ROLE_ANY), |
| 372 | false); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | if (adapter->delay_null_pkt && !adapter->cmd_sent && |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 377 | !adapter->curr_cmd && !is_command_pending(adapter) && |
Zhaoyang Liu | e35000e | 2015-03-13 17:37:57 +0530 | [diff] [blame] | 378 | (mwifiex_wmm_lists_empty(adapter) && |
| 379 | skb_queue_empty(&adapter->tx_data_q))) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 380 | if (!mwifiex_send_null_packet |
| 381 | (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA), |
| 382 | MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET | |
| 383 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) { |
| 384 | adapter->delay_null_pkt = false; |
| 385 | adapter->ps_state = PS_STATE_SLEEP; |
| 386 | } |
| 387 | break; |
| 388 | } |
Shengzhen Li | 04c7b36 | 2015-02-11 23:12:24 +0530 | [diff] [blame] | 389 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 390 | } while (true); |
| 391 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 392 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
Shengzhen Li | 04c7b36 | 2015-02-11 23:12:24 +0530 | [diff] [blame] | 393 | if (adapter->more_task_flag) |
Amitkumar Karwar | 453b0c3 | 2013-09-27 10:55:38 -0700 | [diff] [blame] | 394 | goto process_start; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 395 | adapter->mwifiex_processing = false; |
| 396 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 397 | |
| 398 | exit_main_proc: |
| 399 | if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) |
| 400 | mwifiex_shutdown_drv(adapter); |
| 401 | return ret; |
| 402 | } |
Bing Zhao | 601216e | 2012-11-05 16:59:15 -0800 | [diff] [blame] | 403 | EXPORT_SYMBOL_GPL(mwifiex_main_process); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 404 | |
| 405 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 406 | * This function frees the adapter structure. |
| 407 | * |
| 408 | * Additionally, this closes the netlink socket, frees the timers |
| 409 | * and private structures. |
| 410 | */ |
| 411 | static void mwifiex_free_adapter(struct mwifiex_adapter *adapter) |
| 412 | { |
| 413 | if (!adapter) { |
| 414 | pr_err("%s: adapter is NULL\n", __func__); |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | mwifiex_unregister(adapter); |
| 419 | pr_debug("info: %s: free adapter\n", __func__); |
| 420 | } |
| 421 | |
| 422 | /* |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 423 | * This function cancels all works in the queue and destroys |
| 424 | * the main workqueue. |
| 425 | */ |
| 426 | static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter) |
| 427 | { |
| 428 | flush_workqueue(adapter->workqueue); |
| 429 | destroy_workqueue(adapter->workqueue); |
| 430 | adapter->workqueue = NULL; |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 431 | |
| 432 | if (adapter->rx_workqueue) { |
| 433 | flush_workqueue(adapter->rx_workqueue); |
| 434 | destroy_workqueue(adapter->rx_workqueue); |
| 435 | adapter->rx_workqueue = NULL; |
| 436 | } |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 440 | * This function gets firmware and initializes it. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 441 | * |
| 442 | * The main initialization steps followed are - |
| 443 | * - Download the correct firmware to card |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 444 | * - Issue the init commands to firmware |
| 445 | */ |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 446 | static void mwifiex_fw_dpc(const struct firmware *firmware, void *context) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 447 | { |
Amitkumar Karwar | bec568f | 2013-11-14 19:10:38 -0800 | [diff] [blame] | 448 | int ret; |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 449 | char fmt[64]; |
| 450 | struct mwifiex_private *priv; |
| 451 | struct mwifiex_adapter *adapter = context; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 452 | struct mwifiex_fw_image fw; |
Amitkumar Karwar | c3afd99 | 2013-07-30 17:18:15 -0700 | [diff] [blame] | 453 | struct semaphore *sem = adapter->card_sem; |
| 454 | bool init_failed = false; |
Amitkumar Karwar | 68b76e9 | 2013-11-14 19:10:37 -0800 | [diff] [blame] | 455 | struct wireless_dev *wdev; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 456 | |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 457 | if (!firmware) { |
| 458 | dev_err(adapter->dev, |
| 459 | "Failed to get firmware %s\n", adapter->fw_name); |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 460 | goto err_dnld_fw; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 461 | } |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 462 | |
| 463 | memset(&fw, 0, sizeof(struct mwifiex_fw_image)); |
| 464 | adapter->firmware = firmware; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 465 | fw.fw_buf = (u8 *) adapter->firmware->data; |
| 466 | fw.fw_len = adapter->firmware->size; |
| 467 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 468 | if (adapter->if_ops.dnld_fw) |
| 469 | ret = adapter->if_ops.dnld_fw(adapter, &fw); |
| 470 | else |
| 471 | ret = mwifiex_dnld_fw(adapter, &fw); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 472 | if (ret == -1) |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 473 | goto err_dnld_fw; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 474 | |
| 475 | dev_notice(adapter->dev, "WLAN FW is active\n"); |
| 476 | |
Amitkumar Karwar | 388ec38 | 2013-05-17 17:50:25 -0700 | [diff] [blame] | 477 | if (cal_data_cfg) { |
| 478 | if ((request_firmware(&adapter->cal_data, cal_data_cfg, |
| 479 | adapter->dev)) < 0) |
| 480 | dev_err(adapter->dev, |
| 481 | "Cal data request_firmware() failed\n"); |
| 482 | } |
| 483 | |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 484 | /* enable host interrupt after fw dnld is successful */ |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 485 | if (adapter->if_ops.enable_int) { |
| 486 | if (adapter->if_ops.enable_int(adapter)) |
| 487 | goto err_dnld_fw; |
| 488 | } |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 489 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 490 | adapter->init_wait_q_woken = false; |
| 491 | ret = mwifiex_init_fw(adapter); |
| 492 | if (ret == -1) { |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 493 | goto err_init_fw; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 494 | } else if (!ret) { |
| 495 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; |
| 496 | goto done; |
| 497 | } |
| 498 | /* Wait for mwifiex_init to complete */ |
| 499 | wait_event_interruptible(adapter->init_wait_q, |
| 500 | adapter->init_wait_q_woken); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 501 | if (adapter->hw_status != MWIFIEX_HW_STATUS_READY) |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 502 | goto err_init_fw; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 503 | |
Avinash Patil | d6bffe8 | 2012-05-08 18:30:15 -0700 | [diff] [blame] | 504 | priv = adapter->priv[MWIFIEX_BSS_ROLE_STA]; |
| 505 | if (mwifiex_register_cfg80211(adapter)) { |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 506 | dev_err(adapter->dev, "cannot register with cfg80211\n"); |
Amitkumar Karwar | d1af294 | 2013-11-14 19:10:39 -0800 | [diff] [blame] | 507 | goto err_init_fw; |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 510 | if (mwifiex_init_channel_scan_gap(adapter)) { |
| 511 | dev_err(adapter->dev, "could not init channel stats table\n"); |
| 512 | goto err_init_fw; |
| 513 | } |
| 514 | |
Avinash Patil | 0013c7c | 2014-11-05 19:38:11 +0530 | [diff] [blame] | 515 | if (driver_mode) { |
| 516 | driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK; |
| 517 | driver_mode |= MWIFIEX_DRIVER_MODE_STA; |
| 518 | } |
| 519 | |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 520 | rtnl_lock(); |
| 521 | /* Create station interface by default */ |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 522 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", NET_NAME_ENUM, |
Amitkumar Karwar | 68b76e9 | 2013-11-14 19:10:37 -0800 | [diff] [blame] | 523 | NL80211_IFTYPE_STATION, NULL, NULL); |
| 524 | if (IS_ERR(wdev)) { |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 525 | dev_err(adapter->dev, "cannot create default STA interface\n"); |
Amitkumar Karwar | bec568f | 2013-11-14 19:10:38 -0800 | [diff] [blame] | 526 | rtnl_unlock(); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 527 | goto err_add_intf; |
| 528 | } |
Avinash Patil | 0013c7c | 2014-11-05 19:38:11 +0530 | [diff] [blame] | 529 | |
| 530 | if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) { |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 531 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", NET_NAME_ENUM, |
Avinash Patil | 0013c7c | 2014-11-05 19:38:11 +0530 | [diff] [blame] | 532 | NL80211_IFTYPE_AP, NULL, NULL); |
| 533 | if (IS_ERR(wdev)) { |
| 534 | dev_err(adapter->dev, "cannot create AP interface\n"); |
| 535 | rtnl_unlock(); |
| 536 | goto err_add_intf; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) { |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 541 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", NET_NAME_ENUM, |
Avinash Patil | 0013c7c | 2014-11-05 19:38:11 +0530 | [diff] [blame] | 542 | NL80211_IFTYPE_P2P_CLIENT, NULL, |
| 543 | NULL); |
| 544 | if (IS_ERR(wdev)) { |
| 545 | dev_err(adapter->dev, |
| 546 | "cannot create p2p client interface\n"); |
| 547 | rtnl_unlock(); |
| 548 | goto err_add_intf; |
| 549 | } |
| 550 | } |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 551 | rtnl_unlock(); |
| 552 | |
| 553 | mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1); |
| 554 | dev_notice(adapter->dev, "driver_version = %s\n", fmt); |
| 555 | goto done; |
| 556 | |
| 557 | err_add_intf: |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 558 | wiphy_unregister(adapter->wiphy); |
| 559 | wiphy_free(adapter->wiphy); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 560 | err_init_fw: |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 561 | if (adapter->if_ops.disable_int) |
| 562 | adapter->if_ops.disable_int(adapter); |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 563 | err_dnld_fw: |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 564 | pr_debug("info: %s: unregister device\n", __func__); |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 565 | if (adapter->if_ops.unregister_dev) |
| 566 | adapter->if_ops.unregister_dev(adapter); |
| 567 | |
Amitkumar Karwar | 7197325 | 2014-12-31 02:36:38 -0800 | [diff] [blame] | 568 | if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) { |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 569 | pr_debug("info: %s: shutdown mwifiex\n", __func__); |
| 570 | adapter->init_wait_q_woken = false; |
| 571 | |
| 572 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) |
| 573 | wait_event_interruptible(adapter->init_wait_q, |
| 574 | adapter->init_wait_q_woken); |
| 575 | } |
| 576 | adapter->surprise_removed = true; |
| 577 | mwifiex_terminate_workqueue(adapter); |
Amitkumar Karwar | c3afd99 | 2013-07-30 17:18:15 -0700 | [diff] [blame] | 578 | init_failed = true; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 579 | done: |
Amitkumar Karwar | 388ec38 | 2013-05-17 17:50:25 -0700 | [diff] [blame] | 580 | if (adapter->cal_data) { |
| 581 | release_firmware(adapter->cal_data); |
| 582 | adapter->cal_data = NULL; |
| 583 | } |
Amitkumar Karwar | c3afd99 | 2013-07-30 17:18:15 -0700 | [diff] [blame] | 584 | if (adapter->firmware) { |
| 585 | release_firmware(adapter->firmware); |
| 586 | adapter->firmware = NULL; |
| 587 | } |
Amitkumar Karwar | c3afd99 | 2013-07-30 17:18:15 -0700 | [diff] [blame] | 588 | if (init_failed) |
| 589 | mwifiex_free_adapter(adapter); |
| 590 | up(sem); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 591 | return; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * This function initializes the hardware and gets firmware. |
| 596 | */ |
| 597 | static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter) |
| 598 | { |
| 599 | int ret; |
| 600 | |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 601 | ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name, |
| 602 | adapter->dev, GFP_KERNEL, adapter, |
| 603 | mwifiex_fw_dpc); |
| 604 | if (ret < 0) |
| 605 | dev_err(adapter->dev, |
| 606 | "request_firmware_nowait() returned error %d\n", ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 607 | return ret; |
| 608 | } |
| 609 | |
| 610 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 611 | * CFG802.11 network device handler for open. |
| 612 | * |
| 613 | * Starts the data queue. |
| 614 | */ |
| 615 | static int |
| 616 | mwifiex_open(struct net_device *dev) |
| 617 | { |
Johannes Berg | ea2325b | 2015-01-19 15:54:36 +0530 | [diff] [blame] | 618 | netif_carrier_off(dev); |
| 619 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * CFG802.11 network device handler for close. |
| 625 | */ |
| 626 | static int |
| 627 | mwifiex_close(struct net_device *dev) |
| 628 | { |
Amitkumar Karwar | f162cac | 2012-10-19 19:19:16 -0700 | [diff] [blame] | 629 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 630 | |
| 631 | if (priv->scan_request) { |
| 632 | dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n"); |
| 633 | cfg80211_scan_done(priv->scan_request, 1); |
| 634 | priv->scan_request = NULL; |
Amitkumar Karwar | 75ab753 | 2013-05-17 17:50:20 -0700 | [diff] [blame] | 635 | priv->scan_aborting = true; |
Amitkumar Karwar | f162cac | 2012-10-19 19:19:16 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | /* |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 642 | * Add buffer into wmm tx queue and queue work to transmit it. |
| 643 | */ |
| 644 | int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb) |
| 645 | { |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 646 | struct netdev_queue *txq; |
| 647 | int index = mwifiex_1d_to_wmm_queue[skb->priority]; |
| 648 | |
| 649 | if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) { |
| 650 | txq = netdev_get_tx_queue(priv->netdev, index); |
| 651 | if (!netif_tx_queue_stopped(txq)) { |
| 652 | netif_tx_stop_queue(txq); |
| 653 | dev_dbg(priv->adapter->dev, "stop queue: %d\n", index); |
| 654 | } |
| 655 | } |
| 656 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 657 | atomic_inc(&priv->adapter->tx_pending); |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 658 | mwifiex_wmm_add_buf_txqueue(priv, skb); |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 659 | |
Shengzhen Li | b2713f6 | 2015-03-13 17:37:54 +0530 | [diff] [blame] | 660 | mwifiex_queue_main_work(priv->adapter); |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
Amitkumar Karwar | 18ca438 | 2014-11-25 06:43:06 -0800 | [diff] [blame] | 665 | struct sk_buff * |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 666 | mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv, |
Amitkumar Karwar | 18ca438 | 2014-11-25 06:43:06 -0800 | [diff] [blame] | 667 | struct sk_buff *skb, u8 flag, u64 *cookie) |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 668 | { |
| 669 | struct sk_buff *orig_skb = skb; |
| 670 | struct mwifiex_txinfo *tx_info, *orig_tx_info; |
| 671 | |
| 672 | skb = skb_clone(skb, GFP_ATOMIC); |
| 673 | if (skb) { |
| 674 | unsigned long flags; |
| 675 | int id; |
| 676 | |
| 677 | spin_lock_irqsave(&priv->ack_status_lock, flags); |
| 678 | id = idr_alloc(&priv->ack_status_frames, orig_skb, |
| 679 | 1, 0xff, GFP_ATOMIC); |
| 680 | spin_unlock_irqrestore(&priv->ack_status_lock, flags); |
| 681 | |
| 682 | if (id >= 0) { |
| 683 | tx_info = MWIFIEX_SKB_TXCB(skb); |
| 684 | tx_info->ack_frame_id = id; |
| 685 | tx_info->flags |= flag; |
| 686 | orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb); |
| 687 | orig_tx_info->ack_frame_id = id; |
| 688 | orig_tx_info->flags |= flag; |
Amitkumar Karwar | 18ca438 | 2014-11-25 06:43:06 -0800 | [diff] [blame] | 689 | |
| 690 | if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie) |
| 691 | orig_tx_info->cookie = *cookie; |
| 692 | |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 693 | } else if (skb_shared(skb)) { |
| 694 | kfree_skb(orig_skb); |
| 695 | } else { |
| 696 | kfree_skb(skb); |
| 697 | skb = orig_skb; |
| 698 | } |
| 699 | } else { |
| 700 | /* couldn't clone -- lose tx status ... */ |
| 701 | skb = orig_skb; |
| 702 | } |
| 703 | |
| 704 | return skb; |
| 705 | } |
| 706 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 707 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 708 | * CFG802.11 network device handler for data transmission. |
| 709 | */ |
| 710 | static int |
| 711 | mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 712 | { |
| 713 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 714 | struct sk_buff *new_skb; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 715 | struct mwifiex_txinfo *tx_info; |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 716 | bool multicast; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 717 | |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 718 | 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] | 719 | jiffies, priv->bss_type, priv->bss_num); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 720 | |
| 721 | if (priv->adapter->surprise_removed) { |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 722 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 723 | priv->stats.tx_dropped++; |
| 724 | return 0; |
| 725 | } |
| 726 | if (!skb->len || (skb->len > ETH_FRAME_LEN)) { |
| 727 | 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] | 728 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 729 | priv->stats.tx_dropped++; |
| 730 | return 0; |
| 731 | } |
| 732 | if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) { |
| 733 | dev_dbg(priv->adapter->dev, |
| 734 | "data: Tx: insufficient skb headroom %d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 735 | skb_headroom(skb)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 736 | /* Insufficient skb headroom - allocate a new skb */ |
| 737 | new_skb = |
| 738 | skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN); |
| 739 | if (unlikely(!new_skb)) { |
| 740 | dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n"); |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 741 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 742 | priv->stats.tx_dropped++; |
| 743 | return 0; |
| 744 | } |
| 745 | kfree_skb(skb); |
| 746 | skb = new_skb; |
| 747 | dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 748 | skb_headroom(skb)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | tx_info = MWIFIEX_SKB_TXCB(skb); |
Amitkumar Karwar | d76744a | 2014-06-20 11:45:25 -0700 | [diff] [blame] | 752 | memset(tx_info, 0, sizeof(*tx_info)); |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 753 | tx_info->bss_num = priv->bss_num; |
| 754 | tx_info->bss_type = priv->bss_type; |
Ujjal Roy | a1ed484 | 2013-12-02 23:17:55 -0800 | [diff] [blame] | 755 | tx_info->pkt_len = skb->len; |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 756 | |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 757 | multicast = is_multicast_ether_addr(skb->data); |
| 758 | |
| 759 | if (unlikely(!multicast && skb->sk && |
| 760 | skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS && |
| 761 | priv->adapter->fw_api_ver == MWIFIEX_FW_V15)) |
| 762 | skb = mwifiex_clone_skb_for_tx_status(priv, |
| 763 | skb, |
Amitkumar Karwar | 18ca438 | 2014-11-25 06:43:06 -0800 | [diff] [blame] | 764 | MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL); |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 765 | |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 766 | /* Record the current time the packet was queued; used to |
| 767 | * determine the amount of time the packet was queued in |
| 768 | * the driver before it was sent to the firmware. |
| 769 | * The delay is then sent along with the packet to the |
| 770 | * firmware for aggregate delay calculation for stats and |
| 771 | * MSDU lifetime expiry. |
| 772 | */ |
Thomas Gleixner | c64800e | 2014-06-12 08:31:34 +0100 | [diff] [blame] | 773 | __net_timestamp(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 774 | |
Avinash Patil | 9927baa | 2014-11-13 21:54:16 +0530 | [diff] [blame] | 775 | if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && |
| 776 | priv->bss_type == MWIFIEX_BSS_TYPE_STA && |
| 777 | !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) { |
| 778 | if (priv->adapter->auto_tdls && priv->check_tdls_tx) |
| 779 | mwifiex_tdls_check_tx(priv, skb); |
| 780 | } |
| 781 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 782 | mwifiex_queue_tx_pkt(priv, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | /* |
| 788 | * CFG802.11 network device handler for setting MAC address. |
| 789 | */ |
| 790 | static int |
| 791 | mwifiex_set_mac_address(struct net_device *dev, void *addr) |
| 792 | { |
| 793 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 794 | struct sockaddr *hw_addr = addr; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 795 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 796 | |
| 797 | memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN); |
| 798 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 799 | /* Send request to firmware */ |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 800 | ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS, |
| 801 | HostCmd_ACT_GEN_SET, 0, NULL, true); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 802 | |
| 803 | if (!ret) |
| 804 | memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN); |
| 805 | else |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 806 | dev_err(priv->adapter->dev, |
| 807 | "set mac address failed: ret=%d\n", ret); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 808 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 809 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
| 810 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 811 | return ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | /* |
| 815 | * CFG802.11 network device handler for setting multicast list. |
| 816 | */ |
| 817 | static void mwifiex_set_multicast_list(struct net_device *dev) |
| 818 | { |
| 819 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 820 | struct mwifiex_multicast_list mcast_list; |
| 821 | |
| 822 | if (dev->flags & IFF_PROMISC) { |
| 823 | mcast_list.mode = MWIFIEX_PROMISC_MODE; |
| 824 | } else if (dev->flags & IFF_ALLMULTI || |
| 825 | netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) { |
| 826 | mcast_list.mode = MWIFIEX_ALL_MULTI_MODE; |
| 827 | } else { |
| 828 | mcast_list.mode = MWIFIEX_MULTICAST_MODE; |
Daniel Drake | 6390d88 | 2013-06-14 15:24:24 -0400 | [diff] [blame] | 829 | mcast_list.num_multicast_addr = |
| 830 | mwifiex_copy_mcast_addr(&mcast_list, dev); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 831 | } |
| 832 | mwifiex_request_set_multicast_list(priv, &mcast_list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | /* |
| 836 | * CFG802.11 network device handler for transmission timeout. |
| 837 | */ |
| 838 | static void |
| 839 | mwifiex_tx_timeout(struct net_device *dev) |
| 840 | { |
| 841 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 842 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 843 | priv->num_tx_timeout++; |
Ashok Nagarajan | 8908c7d | 2013-03-08 10:58:45 -0800 | [diff] [blame] | 844 | priv->tx_timeout_cnt++; |
| 845 | dev_err(priv->adapter->dev, |
| 846 | "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n", |
| 847 | jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num); |
| 848 | mwifiex_set_trans_start(dev); |
| 849 | |
| 850 | if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD && |
| 851 | priv->adapter->if_ops.card_reset) { |
| 852 | dev_err(priv->adapter->dev, |
| 853 | "tx_timeout_cnt exceeds threshold. Triggering card reset!\n"); |
| 854 | priv->adapter->if_ops.card_reset(priv->adapter); |
| 855 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Xinming Hu | 11cd07a | 2014-12-23 19:14:10 +0530 | [diff] [blame] | 858 | void mwifiex_dump_drv_info(struct mwifiex_adapter *adapter) |
| 859 | { |
| 860 | void *p; |
| 861 | char drv_version[64]; |
| 862 | struct usb_card_rec *cardp; |
| 863 | struct sdio_mmc_card *sdio_card; |
| 864 | struct mwifiex_private *priv; |
| 865 | int i, idx; |
| 866 | struct netdev_queue *txq; |
| 867 | struct mwifiex_debug_info *debug_info; |
| 868 | |
| 869 | if (adapter->drv_info_dump) { |
| 870 | vfree(adapter->drv_info_dump); |
| 871 | adapter->drv_info_size = 0; |
| 872 | } |
| 873 | |
| 874 | dev_info(adapter->dev, "=== DRIVER INFO DUMP START===\n"); |
| 875 | |
| 876 | adapter->drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX); |
| 877 | |
| 878 | if (!adapter->drv_info_dump) |
| 879 | return; |
| 880 | |
| 881 | p = (char *)(adapter->drv_info_dump); |
| 882 | p += sprintf(p, "driver_name = " "\"mwifiex\"\n"); |
| 883 | |
| 884 | mwifiex_drv_get_driver_version(adapter, drv_version, |
| 885 | sizeof(drv_version) - 1); |
| 886 | p += sprintf(p, "driver_version = %s\n", drv_version); |
| 887 | |
| 888 | if (adapter->iface_type == MWIFIEX_USB) { |
| 889 | cardp = (struct usb_card_rec *)adapter->card; |
| 890 | p += sprintf(p, "tx_cmd_urb_pending = %d\n", |
| 891 | atomic_read(&cardp->tx_cmd_urb_pending)); |
| 892 | p += sprintf(p, "tx_data_urb_pending = %d\n", |
| 893 | atomic_read(&cardp->tx_data_urb_pending)); |
| 894 | p += sprintf(p, "rx_cmd_urb_pending = %d\n", |
| 895 | atomic_read(&cardp->rx_cmd_urb_pending)); |
| 896 | p += sprintf(p, "rx_data_urb_pending = %d\n", |
| 897 | atomic_read(&cardp->rx_data_urb_pending)); |
| 898 | } |
| 899 | |
| 900 | p += sprintf(p, "tx_pending = %d\n", |
| 901 | atomic_read(&adapter->tx_pending)); |
| 902 | p += sprintf(p, "rx_pending = %d\n", |
| 903 | atomic_read(&adapter->rx_pending)); |
| 904 | |
| 905 | if (adapter->iface_type == MWIFIEX_SDIO) { |
| 906 | sdio_card = (struct sdio_mmc_card *)adapter->card; |
| 907 | p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n", |
| 908 | sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port); |
| 909 | p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n", |
| 910 | sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port); |
| 911 | } |
| 912 | |
| 913 | for (i = 0; i < adapter->priv_num; i++) { |
| 914 | if (!adapter->priv[i] || !adapter->priv[i]->netdev) |
| 915 | continue; |
| 916 | priv = adapter->priv[i]; |
| 917 | p += sprintf(p, "\n[interface : \"%s\"]\n", |
| 918 | priv->netdev->name); |
| 919 | p += sprintf(p, "wmm_tx_pending[0] = %d\n", |
| 920 | atomic_read(&priv->wmm_tx_pending[0])); |
| 921 | p += sprintf(p, "wmm_tx_pending[1] = %d\n", |
| 922 | atomic_read(&priv->wmm_tx_pending[1])); |
| 923 | p += sprintf(p, "wmm_tx_pending[2] = %d\n", |
| 924 | atomic_read(&priv->wmm_tx_pending[2])); |
| 925 | p += sprintf(p, "wmm_tx_pending[3] = %d\n", |
| 926 | atomic_read(&priv->wmm_tx_pending[3])); |
| 927 | p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ? |
| 928 | "Disconnected" : "Connected"); |
| 929 | p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev) |
| 930 | ? "on" : "off")); |
| 931 | for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) { |
| 932 | txq = netdev_get_tx_queue(priv->netdev, idx); |
| 933 | p += sprintf(p, "tx queue %d:%s ", idx, |
| 934 | netif_tx_queue_stopped(txq) ? |
| 935 | "stopped" : "started"); |
| 936 | } |
| 937 | p += sprintf(p, "\n%s: num_tx_timeout = %d\n", |
| 938 | priv->netdev->name, priv->num_tx_timeout); |
| 939 | } |
| 940 | |
Xinming Hu | 809c6ea | 2014-12-23 19:14:11 +0530 | [diff] [blame] | 941 | if (adapter->iface_type == MWIFIEX_SDIO) { |
| 942 | p += sprintf(p, "\n=== SDIO register DUMP===\n"); |
| 943 | if (adapter->if_ops.reg_dump) |
| 944 | p += adapter->if_ops.reg_dump(adapter, p); |
| 945 | } |
| 946 | |
Xinming Hu | 11cd07a | 2014-12-23 19:14:10 +0530 | [diff] [blame] | 947 | p += sprintf(p, "\n=== MORE DEBUG INFORMATION\n"); |
| 948 | debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL); |
| 949 | if (debug_info) { |
| 950 | for (i = 0; i < adapter->priv_num; i++) { |
| 951 | if (!adapter->priv[i] || !adapter->priv[i]->netdev) |
| 952 | continue; |
| 953 | priv = adapter->priv[i]; |
| 954 | mwifiex_get_debug_info(priv, debug_info); |
| 955 | p += mwifiex_debug_info_to_buffer(priv, p, debug_info); |
| 956 | break; |
| 957 | } |
| 958 | kfree(debug_info); |
| 959 | } |
| 960 | |
| 961 | adapter->drv_info_size = p - adapter->drv_info_dump; |
| 962 | dev_info(adapter->dev, "=== DRIVER INFO DUMP END===\n"); |
| 963 | } |
| 964 | EXPORT_SYMBOL_GPL(mwifiex_dump_drv_info); |
| 965 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 966 | /* |
| 967 | * CFG802.11 network device handler for statistics retrieval. |
| 968 | */ |
| 969 | static struct net_device_stats *mwifiex_get_stats(struct net_device *dev) |
| 970 | { |
| 971 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 972 | |
| 973 | return &priv->stats; |
| 974 | } |
| 975 | |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 976 | static u16 |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 977 | mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb, |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 978 | void *accel_priv, select_queue_fallback_t fallback) |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 979 | { |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 980 | skb->priority = cfg80211_classify8021d(skb, NULL); |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 981 | return mwifiex_1d_to_wmm_queue[skb->priority]; |
| 982 | } |
| 983 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 984 | /* Network device handlers */ |
| 985 | static const struct net_device_ops mwifiex_netdev_ops = { |
| 986 | .ndo_open = mwifiex_open, |
| 987 | .ndo_stop = mwifiex_close, |
| 988 | .ndo_start_xmit = mwifiex_hard_start_xmit, |
| 989 | .ndo_set_mac_address = mwifiex_set_mac_address, |
| 990 | .ndo_tx_timeout = mwifiex_tx_timeout, |
| 991 | .ndo_get_stats = mwifiex_get_stats, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 992 | .ndo_set_rx_mode = mwifiex_set_multicast_list, |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 993 | .ndo_select_queue = mwifiex_netdev_select_wmm_queue, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 994 | }; |
| 995 | |
| 996 | /* |
| 997 | * This function initializes the private structure parameters. |
| 998 | * |
| 999 | * The following wait queues are initialized - |
| 1000 | * - IOCTL wait queue |
| 1001 | * - Command wait queue |
| 1002 | * - Statistics wait queue |
| 1003 | * |
| 1004 | * ...and the following default parameters are set - |
| 1005 | * - Current key index : Set to 0 |
| 1006 | * - Rate index : Set to auto |
| 1007 | * - Media connected : Set to disconnected |
| 1008 | * - Adhoc link sensed : Set to false |
| 1009 | * - Nick name : Set to null |
| 1010 | * - Number of Tx timeout : Set to 0 |
| 1011 | * - Device address : Set to current address |
Xinming Hu | cbf6e05 | 2014-12-23 19:14:07 +0530 | [diff] [blame] | 1012 | * - Rx histogram statistc : Set to 0 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1013 | * |
| 1014 | * In addition, the CFG80211 work queue is also created. |
| 1015 | */ |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1016 | void mwifiex_init_priv_params(struct mwifiex_private *priv, |
Avinash Patil | 047eaaf | 2015-01-28 15:42:05 +0530 | [diff] [blame] | 1017 | struct net_device *dev) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1018 | { |
| 1019 | dev->netdev_ops = &mwifiex_netdev_ops; |
Amitkumar Karwar | f16fdc9 | 2013-05-06 19:46:54 -0700 | [diff] [blame] | 1020 | dev->destructor = free_netdev; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1021 | /* Initialize private structure */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1022 | priv->current_key_index = 0; |
| 1023 | priv->media_connected = false; |
Avinash Patil | ede98bf | 2012-05-08 18:30:28 -0700 | [diff] [blame] | 1024 | memset(priv->mgmt_ie, 0, |
| 1025 | sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX); |
Avinash Patil | f31acab | 2012-05-08 18:30:29 -0700 | [diff] [blame] | 1026 | priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK; |
| 1027 | priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK; |
| 1028 | priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK; |
Avinash Patil | 2ade566 | 2015-01-28 15:54:20 +0530 | [diff] [blame] | 1029 | priv->gen_idx = MWIFIEX_AUTO_IDX_MASK; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1030 | priv->num_tx_timeout = 0; |
Avinash Patil | 8d05eb2 | 2015-01-28 15:42:01 +0530 | [diff] [blame] | 1031 | ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1032 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
Xinming Hu | cbf6e05 | 2014-12-23 19:14:07 +0530 | [diff] [blame] | 1033 | |
| 1034 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA || |
| 1035 | GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { |
| 1036 | priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL); |
| 1037 | if (priv->hist_data) |
| 1038 | mwifiex_hist_data_reset(priv); |
| 1039 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1043 | * This function check if command is pending. |
| 1044 | */ |
| 1045 | int is_command_pending(struct mwifiex_adapter *adapter) |
| 1046 | { |
| 1047 | unsigned long flags; |
| 1048 | int is_cmd_pend_q_empty; |
| 1049 | |
| 1050 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); |
| 1051 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); |
| 1052 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); |
| 1053 | |
| 1054 | return !is_cmd_pend_q_empty; |
| 1055 | } |
| 1056 | |
| 1057 | /* |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1058 | * This is the RX work queue function. |
| 1059 | * |
| 1060 | * It handles the RX operations. |
| 1061 | */ |
| 1062 | static void mwifiex_rx_work_queue(struct work_struct *work) |
| 1063 | { |
| 1064 | struct mwifiex_adapter *adapter = |
| 1065 | container_of(work, struct mwifiex_adapter, rx_work); |
| 1066 | |
| 1067 | if (adapter->surprise_removed) |
| 1068 | return; |
| 1069 | mwifiex_process_rx(adapter); |
| 1070 | } |
| 1071 | |
| 1072 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1073 | * This is the main work queue function. |
| 1074 | * |
| 1075 | * It handles the main process, which in turn handles the complete |
| 1076 | * driver operations. |
| 1077 | */ |
| 1078 | static void mwifiex_main_work_queue(struct work_struct *work) |
| 1079 | { |
| 1080 | struct mwifiex_adapter *adapter = |
| 1081 | container_of(work, struct mwifiex_adapter, main_work); |
| 1082 | |
| 1083 | if (adapter->surprise_removed) |
| 1084 | return; |
| 1085 | mwifiex_main_process(adapter); |
| 1086 | } |
| 1087 | |
| 1088 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1089 | * This function adds the card. |
| 1090 | * |
| 1091 | * This function follows the following major steps to set up the device - |
| 1092 | * - Initialize software. This includes probing the card, registering |
| 1093 | * the interface operations table, and allocating/initializing the |
| 1094 | * adapter structure |
| 1095 | * - Set up the netlink socket |
| 1096 | * - Create and start the main work queue |
| 1097 | * - Register the device |
| 1098 | * - Initialize firmware and hardware |
| 1099 | * - Add logical interfaces |
| 1100 | */ |
| 1101 | int |
| 1102 | mwifiex_add_card(void *card, struct semaphore *sem, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1103 | struct mwifiex_if_ops *if_ops, u8 iface_type) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1104 | { |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 1105 | struct mwifiex_adapter *adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1106 | |
| 1107 | if (down_interruptible(sem)) |
| 1108 | goto exit_sem_err; |
| 1109 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1110 | if (mwifiex_register(card, if_ops, (void **)&adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1111 | pr_err("%s: software init failed\n", __func__); |
| 1112 | goto err_init_sw; |
| 1113 | } |
| 1114 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1115 | adapter->iface_type = iface_type; |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 1116 | adapter->card_sem = sem; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1117 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1118 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1119 | adapter->surprise_removed = false; |
| 1120 | init_waitqueue_head(&adapter->init_wait_q); |
| 1121 | adapter->is_suspended = false; |
| 1122 | adapter->hs_activated = false; |
| 1123 | init_waitqueue_head(&adapter->hs_activate_wait_q); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1124 | init_waitqueue_head(&adapter->cmd_wait_q.wait); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1125 | adapter->cmd_wait_q.status = 0; |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 1126 | adapter->scan_wait_q_woken = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1127 | |
Avinash Patil | ec4a16b | 2014-11-05 17:04:27 +0530 | [diff] [blame] | 1128 | if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) { |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1129 | adapter->rx_work_enabled = true; |
| 1130 | pr_notice("rx work enabled, cpus %d\n", num_possible_cpus()); |
| 1131 | } |
| 1132 | |
Amitkumar Karwar | 448a71c | 2013-10-11 18:33:04 -0700 | [diff] [blame] | 1133 | adapter->workqueue = |
| 1134 | alloc_workqueue("MWIFIEX_WORK_QUEUE", |
| 1135 | WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1136 | if (!adapter->workqueue) |
| 1137 | goto err_kmalloc; |
| 1138 | |
| 1139 | INIT_WORK(&adapter->main_work, mwifiex_main_work_queue); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1140 | |
| 1141 | if (adapter->rx_work_enabled) { |
| 1142 | adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE", |
| 1143 | WQ_HIGHPRI | |
| 1144 | WQ_MEM_RECLAIM | |
| 1145 | WQ_UNBOUND, 1); |
| 1146 | if (!adapter->rx_workqueue) |
| 1147 | goto err_kmalloc; |
| 1148 | |
| 1149 | INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue); |
| 1150 | } |
| 1151 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1152 | /* Register the device. Fill up the private data structure with relevant |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 1153 | information from the card. */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1154 | if (adapter->if_ops.register_dev(adapter)) { |
| 1155 | pr_err("%s: failed to register mwifiex device\n", __func__); |
| 1156 | goto err_registerdev; |
| 1157 | } |
| 1158 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1159 | if (mwifiex_init_hw_fw(adapter)) { |
| 1160 | pr_err("%s: firmware init failed\n", __func__); |
| 1161 | goto err_init_fw; |
| 1162 | } |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 1163 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1164 | return 0; |
| 1165 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1166 | err_init_fw: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1167 | pr_debug("info: %s: unregister device\n", __func__); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 1168 | if (adapter->if_ops.unregister_dev) |
| 1169 | adapter->if_ops.unregister_dev(adapter); |
Amitkumar Karwar | 7197325 | 2014-12-31 02:36:38 -0800 | [diff] [blame] | 1170 | if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1171 | pr_debug("info: %s: shutdown mwifiex\n", __func__); |
| 1172 | adapter->init_wait_q_woken = false; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1173 | |
| 1174 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1175 | wait_event_interruptible(adapter->init_wait_q, |
| 1176 | adapter->init_wait_q_woken); |
| 1177 | } |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 1178 | err_registerdev: |
| 1179 | adapter->surprise_removed = true; |
| 1180 | mwifiex_terminate_workqueue(adapter); |
| 1181 | err_kmalloc: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1182 | mwifiex_free_adapter(adapter); |
| 1183 | |
| 1184 | err_init_sw: |
| 1185 | up(sem); |
| 1186 | |
| 1187 | exit_sem_err: |
| 1188 | return -1; |
| 1189 | } |
| 1190 | EXPORT_SYMBOL_GPL(mwifiex_add_card); |
| 1191 | |
| 1192 | /* |
| 1193 | * This function removes the card. |
| 1194 | * |
| 1195 | * This function follows the following major steps to remove the device - |
| 1196 | * - Stop data traffic |
| 1197 | * - Shutdown firmware |
| 1198 | * - Remove the logical interfaces |
| 1199 | * - Terminate the work queue |
| 1200 | * - Unregister the device |
| 1201 | * - Free the adapter structure |
| 1202 | */ |
| 1203 | int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem) |
| 1204 | { |
| 1205 | struct mwifiex_private *priv = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1206 | int i; |
| 1207 | |
| 1208 | if (down_interruptible(sem)) |
| 1209 | goto exit_sem_err; |
| 1210 | |
| 1211 | if (!adapter) |
| 1212 | goto exit_remove; |
| 1213 | |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 1214 | /* We can no longer handle interrupts once we start doing the teardown |
| 1215 | * below. */ |
| 1216 | if (adapter->if_ops.disable_int) |
| 1217 | adapter->if_ops.disable_int(adapter); |
| 1218 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1219 | adapter->surprise_removed = true; |
| 1220 | |
Marc Yang | 9d2e85e | 2014-12-31 02:36:39 -0800 | [diff] [blame] | 1221 | mwifiex_terminate_workqueue(adapter); |
| 1222 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1223 | /* Stop data */ |
| 1224 | for (i = 0; i < adapter->priv_num; i++) { |
| 1225 | priv = adapter->priv[i]; |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1226 | if (priv && priv->netdev) { |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 1227 | mwifiex_stop_net_dev_queue(priv->netdev, adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1228 | if (netif_carrier_ok(priv->netdev)) |
| 1229 | netif_carrier_off(priv->netdev); |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n"); |
| 1234 | adapter->init_wait_q_woken = false; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1235 | |
| 1236 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1237 | wait_event_interruptible(adapter->init_wait_q, |
| 1238 | adapter->init_wait_q_woken); |
| 1239 | dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n"); |
| 1240 | if (atomic_read(&adapter->rx_pending) || |
| 1241 | atomic_read(&adapter->tx_pending) || |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1242 | atomic_read(&adapter->cmd_pending)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1243 | dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, " |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1244 | "cmd_pending=%d\n", |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1245 | atomic_read(&adapter->rx_pending), |
| 1246 | atomic_read(&adapter->tx_pending), |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1247 | atomic_read(&adapter->cmd_pending)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1250 | for (i = 0; i < adapter->priv_num; i++) { |
| 1251 | priv = adapter->priv[i]; |
| 1252 | |
| 1253 | if (!priv) |
| 1254 | continue; |
| 1255 | |
| 1256 | rtnl_lock(); |
Avinash Patil | 4facc34 | 2015-01-28 15:42:00 +0530 | [diff] [blame] | 1257 | if (priv->netdev && |
| 1258 | priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED) |
| 1259 | mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev); |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1260 | rtnl_unlock(); |
| 1261 | } |
| 1262 | |
Amitkumar Karwar | c2868ad | 2013-12-02 23:17:57 -0800 | [diff] [blame] | 1263 | wiphy_unregister(adapter->wiphy); |
| 1264 | wiphy_free(adapter->wiphy); |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 1265 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1266 | /* Unregister device */ |
| 1267 | dev_dbg(adapter->dev, "info: unregister device\n"); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 1268 | if (adapter->if_ops.unregister_dev) |
| 1269 | adapter->if_ops.unregister_dev(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1270 | /* Free adapter structure */ |
| 1271 | dev_dbg(adapter->dev, "info: free adapter\n"); |
| 1272 | mwifiex_free_adapter(adapter); |
| 1273 | |
| 1274 | exit_remove: |
| 1275 | up(sem); |
| 1276 | exit_sem_err: |
| 1277 | return 0; |
| 1278 | } |
| 1279 | EXPORT_SYMBOL_GPL(mwifiex_remove_card); |
| 1280 | |
| 1281 | /* |
| 1282 | * This function initializes the module. |
| 1283 | * |
| 1284 | * The debug FS is also initialized if configured. |
| 1285 | */ |
| 1286 | static int |
| 1287 | mwifiex_init_module(void) |
| 1288 | { |
| 1289 | #ifdef CONFIG_DEBUG_FS |
| 1290 | mwifiex_debugfs_init(); |
| 1291 | #endif |
| 1292 | return 0; |
| 1293 | } |
| 1294 | |
| 1295 | /* |
| 1296 | * This function cleans up the module. |
| 1297 | * |
| 1298 | * The debug FS is removed if available. |
| 1299 | */ |
| 1300 | static void |
| 1301 | mwifiex_cleanup_module(void) |
| 1302 | { |
| 1303 | #ifdef CONFIG_DEBUG_FS |
| 1304 | mwifiex_debugfs_remove(); |
| 1305 | #endif |
| 1306 | } |
| 1307 | |
| 1308 | module_init(mwifiex_init_module); |
| 1309 | module_exit(mwifiex_cleanup_module); |
| 1310 | |
| 1311 | MODULE_AUTHOR("Marvell International Ltd."); |
| 1312 | MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION); |
| 1313 | MODULE_VERSION(VERSION); |
| 1314 | MODULE_LICENSE("GPL v2"); |