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