Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: HW/FW Initialization |
| 3 | * |
| 4 | * Copyright (C) 2011, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include "decl.h" |
| 21 | #include "ioctl.h" |
| 22 | #include "util.h" |
| 23 | #include "fw.h" |
| 24 | #include "main.h" |
| 25 | #include "wmm.h" |
| 26 | #include "11n.h" |
| 27 | |
| 28 | /* |
| 29 | * This function adds a BSS priority table to the table list. |
| 30 | * |
| 31 | * The function allocates a new BSS priority table node and adds it to |
| 32 | * the end of BSS priority table list, kept in driver memory. |
| 33 | */ |
| 34 | static int mwifiex_add_bss_prio_tbl(struct mwifiex_private *priv) |
| 35 | { |
| 36 | struct mwifiex_adapter *adapter = priv->adapter; |
| 37 | struct mwifiex_bss_prio_node *bss_prio; |
Yogesh Ashok Powar | 931f158 | 2012-03-13 19:22:36 -0700 | [diff] [blame] | 38 | struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 39 | unsigned long flags; |
| 40 | |
| 41 | bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL); |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 42 | if (!bss_prio) |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 43 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 44 | |
| 45 | bss_prio->priv = priv; |
| 46 | INIT_LIST_HEAD(&bss_prio->list); |
Yogesh Ashok Powar | 931f158 | 2012-03-13 19:22:36 -0700 | [diff] [blame] | 47 | if (!tbl[priv->bss_priority].bss_prio_cur) |
| 48 | tbl[priv->bss_priority].bss_prio_cur = bss_prio; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 49 | |
Yogesh Ashok Powar | 931f158 | 2012-03-13 19:22:36 -0700 | [diff] [blame] | 50 | spin_lock_irqsave(&tbl[priv->bss_priority].bss_prio_lock, flags); |
| 51 | list_add_tail(&bss_prio->list, &tbl[priv->bss_priority].bss_prio_head); |
| 52 | spin_unlock_irqrestore(&tbl[priv->bss_priority].bss_prio_lock, flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 53 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 54 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 57 | static void scan_delay_timer_fn(unsigned long data) |
| 58 | { |
| 59 | struct mwifiex_private *priv = (struct mwifiex_private *)data; |
| 60 | struct mwifiex_adapter *adapter = priv->adapter; |
| 61 | struct cmd_ctrl_node *cmd_node, *tmp_node; |
| 62 | unsigned long flags; |
| 63 | |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 64 | if (adapter->scan_delay_cnt == MWIFIEX_MAX_SCAN_DELAY_CNT) { |
| 65 | /* |
| 66 | * Abort scan operation by cancelling all pending scan |
| 67 | * commands |
| 68 | */ |
| 69 | spin_lock_irqsave(&adapter->scan_pending_q_lock, flags); |
| 70 | list_for_each_entry_safe(cmd_node, tmp_node, |
| 71 | &adapter->scan_pending_q, list) { |
| 72 | list_del(&cmd_node->list); |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 73 | mwifiex_insert_cmd_to_free_q(adapter, cmd_node); |
| 74 | } |
| 75 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags); |
| 76 | |
| 77 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 78 | adapter->scan_processing = false; |
| 79 | adapter->scan_delay_cnt = 0; |
| 80 | adapter->empty_tx_q_cnt = 0; |
| 81 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 82 | |
| 83 | if (priv->user_scan_cfg) { |
Amitkumar Karwar | f162cac | 2012-10-19 19:19:16 -0700 | [diff] [blame] | 84 | if (priv->scan_request) { |
| 85 | dev_dbg(priv->adapter->dev, |
| 86 | "info: aborting scan\n"); |
| 87 | cfg80211_scan_done(priv->scan_request, 1); |
| 88 | priv->scan_request = NULL; |
| 89 | } else { |
| 90 | dev_dbg(priv->adapter->dev, |
| 91 | "info: scan already aborted\n"); |
| 92 | } |
| 93 | |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 94 | kfree(priv->user_scan_cfg); |
| 95 | priv->user_scan_cfg = NULL; |
| 96 | } |
| 97 | goto done; |
| 98 | } |
| 99 | |
| 100 | if (!atomic_read(&priv->adapter->is_tx_received)) { |
| 101 | adapter->empty_tx_q_cnt++; |
| 102 | if (adapter->empty_tx_q_cnt == MWIFIEX_MAX_EMPTY_TX_Q_CNT) { |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 103 | /* |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 104 | * No Tx traffic for 200msec. Get scan command from |
| 105 | * scan pending queue and put to cmd pending queue to |
| 106 | * resume scan operation |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 107 | */ |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 108 | adapter->scan_delay_cnt = 0; |
| 109 | adapter->empty_tx_q_cnt = 0; |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 110 | spin_lock_irqsave(&adapter->scan_pending_q_lock, flags); |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 111 | cmd_node = list_first_entry(&adapter->scan_pending_q, |
| 112 | struct cmd_ctrl_node, list); |
| 113 | list_del(&cmd_node->list); |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 114 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, |
| 115 | flags); |
| 116 | |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 117 | mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, |
| 118 | true); |
Amitkumar Karwar | 9a17bad | 2012-09-18 15:33:32 -0700 | [diff] [blame] | 119 | queue_work(adapter->workqueue, &adapter->main_work); |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 120 | goto done; |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 121 | } |
| 122 | } else { |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 123 | adapter->empty_tx_q_cnt = 0; |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 124 | } |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 125 | |
| 126 | /* Delay scan operation further by 20msec */ |
| 127 | mod_timer(&priv->scan_delay_timer, jiffies + |
| 128 | msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC)); |
| 129 | adapter->scan_delay_cnt++; |
| 130 | |
| 131 | done: |
| 132 | if (atomic_read(&priv->adapter->is_tx_received)) |
| 133 | atomic_set(&priv->adapter->is_tx_received, false); |
| 134 | |
| 135 | return; |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 138 | /* |
| 139 | * This function initializes the private structure and sets default |
| 140 | * values to the members. |
| 141 | * |
| 142 | * Additionally, it also initializes all the locks and sets up all the |
| 143 | * lists. |
| 144 | */ |
Stone Piao | 9197ab9 | 2012-09-25 20:23:42 -0700 | [diff] [blame] | 145 | int mwifiex_init_priv(struct mwifiex_private *priv) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 146 | { |
| 147 | u32 i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 148 | |
| 149 | priv->media_connected = false; |
| 150 | memset(priv->curr_addr, 0xff, ETH_ALEN); |
| 151 | |
| 152 | priv->pkt_tx_ctrl = 0; |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 153 | priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 154 | priv->data_rate = 0; /* Initially indicate the rate as auto */ |
| 155 | priv->is_data_rate_auto = true; |
| 156 | priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR; |
| 157 | priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR; |
| 158 | |
Amitkumar Karwar | 5eb02e4 | 2012-02-24 21:36:04 -0800 | [diff] [blame] | 159 | priv->sec_info.wep_enabled = 0; |
Marc Yang | f986b6d | 2011-03-28 17:55:42 -0700 | [diff] [blame] | 160 | priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM; |
Yogesh Ashok Powar | 2be50b8 | 2011-04-01 18:36:47 -0700 | [diff] [blame] | 161 | priv->sec_info.encryption_mode = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 162 | for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++) |
| 163 | memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key)); |
| 164 | priv->wep_key_curr_index = 0; |
| 165 | priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON | |
| 166 | HostCmd_ACT_MAC_ETHERNETII_ENABLE; |
| 167 | |
| 168 | priv->beacon_period = 100; /* beacon interval */ ; |
| 169 | priv->attempted_bss_desc = NULL; |
| 170 | memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params)); |
| 171 | priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL; |
| 172 | |
| 173 | memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid)); |
| 174 | memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid)); |
| 175 | memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf)); |
| 176 | priv->assoc_rsp_size = 0; |
| 177 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; |
| 178 | priv->atim_window = 0; |
| 179 | priv->adhoc_state = ADHOC_IDLE; |
| 180 | priv->tx_power_level = 0; |
| 181 | priv->max_tx_power_level = 0; |
| 182 | priv->min_tx_power_level = 0; |
| 183 | priv->tx_rate = 0; |
| 184 | priv->rxpd_htinfo = 0; |
| 185 | priv->rxpd_rate = 0; |
| 186 | priv->rate_bitmap = 0; |
| 187 | priv->data_rssi_last = 0; |
| 188 | priv->data_rssi_avg = 0; |
| 189 | priv->data_nf_avg = 0; |
| 190 | priv->data_nf_last = 0; |
| 191 | priv->bcn_rssi_last = 0; |
| 192 | priv->bcn_rssi_avg = 0; |
| 193 | priv->bcn_nf_avg = 0; |
| 194 | priv->bcn_nf_last = 0; |
| 195 | memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie)); |
| 196 | memset(&priv->aes_key, 0, sizeof(priv->aes_key)); |
| 197 | priv->wpa_ie_len = 0; |
| 198 | priv->wpa_is_gtk_set = false; |
| 199 | |
| 200 | memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf)); |
| 201 | priv->assoc_tlv_buf_len = 0; |
| 202 | memset(&priv->wps, 0, sizeof(priv->wps)); |
| 203 | memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf)); |
| 204 | priv->gen_ie_buf_len = 0; |
| 205 | memset(priv->vs_ie, 0, sizeof(priv->vs_ie)); |
| 206 | |
| 207 | priv->wmm_required = true; |
| 208 | priv->wmm_enabled = false; |
| 209 | priv->wmm_qosinfo = 0; |
| 210 | priv->curr_bcn_buf = NULL; |
| 211 | priv->curr_bcn_size = 0; |
Avinash Patil | 13d7ba78 | 2012-04-09 20:06:56 -0700 | [diff] [blame] | 212 | priv->wps_ie = NULL; |
| 213 | priv->wps_ie_len = 0; |
Avinash Patil | c825891 | 2012-08-03 18:06:05 -0700 | [diff] [blame] | 214 | priv->ap_11n_enabled = 0; |
Stone Piao | 7feb4c4 | 2012-09-25 20:23:36 -0700 | [diff] [blame] | 215 | memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 216 | |
| 217 | priv->scan_block = false; |
| 218 | |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 219 | setup_timer(&priv->scan_delay_timer, scan_delay_timer_fn, |
| 220 | (unsigned long)priv); |
| 221 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 222 | return mwifiex_add_bss_prio_tbl(priv); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* |
| 226 | * This function allocates buffers for members of the adapter |
| 227 | * structure. |
| 228 | * |
| 229 | * The memory allocated includes scan table, command buffers, and |
| 230 | * sleep confirm command buffer. In addition, the queues are |
| 231 | * also initialized. |
| 232 | */ |
| 233 | static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter) |
| 234 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 235 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 236 | |
| 237 | /* Allocate command buffer */ |
| 238 | ret = mwifiex_alloc_cmd_buffer(adapter); |
| 239 | if (ret) { |
| 240 | dev_err(adapter->dev, "%s: failed to alloc cmd buffer\n", |
Yogesh Ashok Powar | 931f158 | 2012-03-13 19:22:36 -0700 | [diff] [blame] | 241 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 242 | return -1; |
| 243 | } |
| 244 | |
| 245 | adapter->sleep_cfm = |
Amitkumar Karwar | 7cc5eb6 | 2011-05-09 19:00:18 -0700 | [diff] [blame] | 246 | dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm) |
Yogesh Ashok Powar | 931f158 | 2012-03-13 19:22:36 -0700 | [diff] [blame] | 247 | + INTF_HEADER_LEN); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 248 | |
| 249 | if (!adapter->sleep_cfm) { |
| 250 | dev_err(adapter->dev, "%s: failed to alloc sleep cfm" |
| 251 | " cmd buffer\n", __func__); |
| 252 | return -1; |
| 253 | } |
| 254 | skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN); |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | /* |
| 260 | * This function initializes the adapter structure and sets default |
| 261 | * values to the members of adapter. |
| 262 | * |
| 263 | * This also initializes the WMM related parameters in the driver private |
| 264 | * structures. |
| 265 | */ |
| 266 | static void mwifiex_init_adapter(struct mwifiex_adapter *adapter) |
| 267 | { |
Amitkumar Karwar | 7cc5eb6 | 2011-05-09 19:00:18 -0700 | [diff] [blame] | 268 | struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 269 | |
Amitkumar Karwar | 7cc5eb6 | 2011-05-09 19:00:18 -0700 | [diff] [blame] | 270 | skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 271 | |
| 272 | adapter->cmd_sent = false; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 273 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 274 | if (adapter->iface_type == MWIFIEX_SDIO) |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 275 | adapter->data_sent = true; |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 276 | else |
| 277 | adapter->data_sent = false; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 278 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 279 | adapter->cmd_resp_received = false; |
| 280 | adapter->event_received = false; |
| 281 | adapter->data_received = false; |
| 282 | |
| 283 | adapter->surprise_removed = false; |
| 284 | |
| 285 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; |
| 286 | |
| 287 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM; |
| 288 | adapter->ps_state = PS_STATE_AWAKE; |
| 289 | adapter->need_to_wakeup = false; |
| 290 | |
| 291 | adapter->scan_mode = HostCmd_BSS_MODE_ANY; |
| 292 | adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME; |
| 293 | adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME; |
| 294 | adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME; |
| 295 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 296 | adapter->scan_probes = 1; |
| 297 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 298 | adapter->multiple_dtim = 1; |
| 299 | |
| 300 | adapter->local_listen_interval = 0; /* default value in firmware |
| 301 | will be used */ |
| 302 | |
| 303 | adapter->is_deep_sleep = false; |
| 304 | |
| 305 | adapter->delay_null_pkt = false; |
| 306 | adapter->delay_to_ps = 1000; |
| 307 | adapter->enhanced_ps_mode = PS_MODE_AUTO; |
| 308 | |
| 309 | adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by |
| 310 | default */ |
| 311 | adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by |
| 312 | default */ |
| 313 | adapter->pm_wakeup_card_req = false; |
| 314 | |
| 315 | adapter->pm_wakeup_fw_try = false; |
| 316 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 317 | adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; |
| 318 | adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; |
| 319 | |
| 320 | adapter->is_hs_configured = false; |
| 321 | adapter->hs_cfg.conditions = cpu_to_le32(HOST_SLEEP_CFG_COND_DEF); |
| 322 | adapter->hs_cfg.gpio = HOST_SLEEP_CFG_GPIO_DEF; |
| 323 | adapter->hs_cfg.gap = HOST_SLEEP_CFG_GAP_DEF; |
| 324 | adapter->hs_activated = false; |
| 325 | |
| 326 | memset(adapter->event_body, 0, sizeof(adapter->event_body)); |
| 327 | adapter->hw_dot_11n_dev_cap = 0; |
| 328 | adapter->hw_dev_mcs_support = 0; |
Amitkumar Karwar | 21c3ba3 | 2011-12-20 23:47:21 -0800 | [diff] [blame] | 329 | adapter->sec_chan_offset = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 330 | adapter->adhoc_11n_enabled = false; |
| 331 | |
| 332 | mwifiex_wmm_init(adapter); |
| 333 | |
| 334 | if (adapter->sleep_cfm) { |
Yogesh Ashok Powar | 8ed1303 | 2011-11-07 21:41:10 -0800 | [diff] [blame] | 335 | sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *) |
| 336 | adapter->sleep_cfm->data; |
Amitkumar Karwar | 7cc5eb6 | 2011-05-09 19:00:18 -0700 | [diff] [blame] | 337 | memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len); |
| 338 | sleep_cfm_buf->command = |
| 339 | cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH); |
| 340 | sleep_cfm_buf->size = |
| 341 | cpu_to_le16(adapter->sleep_cfm->len); |
| 342 | sleep_cfm_buf->result = 0; |
| 343 | sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM); |
| 344 | sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 345 | } |
| 346 | memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params)); |
| 347 | memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period)); |
| 348 | adapter->tx_lock_flag = false; |
| 349 | adapter->null_pkt_interval = 0; |
| 350 | adapter->fw_bands = 0; |
| 351 | adapter->config_bands = 0; |
| 352 | adapter->adhoc_start_band = 0; |
| 353 | adapter->scan_channels = NULL; |
| 354 | adapter->fw_release_number = 0; |
| 355 | adapter->fw_cap_info = 0; |
| 356 | memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf)); |
| 357 | adapter->event_cause = 0; |
| 358 | adapter->region_code = 0; |
| 359 | adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT; |
| 360 | adapter->adhoc_awake_period = 0; |
| 361 | memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter)); |
| 362 | adapter->arp_filter_size = 0; |
Avinash Patil | ede98bf | 2012-05-08 18:30:28 -0700 | [diff] [blame] | 363 | adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX; |
Amitkumar Karwar | bdd37be | 2012-08-03 18:06:04 -0700 | [diff] [blame] | 364 | adapter->empty_tx_q_cnt = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 368 | * This function sets trans_start per tx_queue |
| 369 | */ |
| 370 | void mwifiex_set_trans_start(struct net_device *dev) |
| 371 | { |
| 372 | int i; |
| 373 | |
| 374 | for (i = 0; i < dev->num_tx_queues; i++) |
| 375 | netdev_get_tx_queue(dev, i)->trans_start = jiffies; |
| 376 | |
| 377 | dev->trans_start = jiffies; |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * This function wakes up all queues in net_device |
| 382 | */ |
| 383 | void mwifiex_wake_up_net_dev_queue(struct net_device *netdev, |
| 384 | struct mwifiex_adapter *adapter) |
| 385 | { |
| 386 | unsigned long dev_queue_flags; |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 387 | unsigned int i; |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 388 | |
| 389 | spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags); |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 390 | |
| 391 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 392 | struct netdev_queue *txq = netdev_get_tx_queue(netdev, i); |
| 393 | |
| 394 | if (netif_tx_queue_stopped(txq)) |
| 395 | netif_tx_wake_queue(txq); |
| 396 | } |
| 397 | |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 398 | spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * This function stops all queues in net_device |
| 403 | */ |
| 404 | void mwifiex_stop_net_dev_queue(struct net_device *netdev, |
| 405 | struct mwifiex_adapter *adapter) |
| 406 | { |
| 407 | unsigned long dev_queue_flags; |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 408 | unsigned int i; |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 409 | |
| 410 | spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags); |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 411 | |
| 412 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 413 | struct netdev_queue *txq = netdev_get_tx_queue(netdev, i); |
| 414 | |
| 415 | if (!netif_tx_queue_stopped(txq)) |
| 416 | netif_tx_stop_queue(txq); |
| 417 | } |
| 418 | |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 419 | spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags); |
| 420 | } |
| 421 | |
| 422 | /* |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 423 | * This function releases the lock variables and frees the locks and |
| 424 | * associated locks. |
| 425 | */ |
| 426 | static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter) |
| 427 | { |
| 428 | struct mwifiex_private *priv; |
| 429 | s32 i, j; |
| 430 | |
| 431 | /* Free lists */ |
| 432 | list_del(&adapter->cmd_free_q); |
| 433 | list_del(&adapter->cmd_pending_q); |
| 434 | list_del(&adapter->scan_pending_q); |
| 435 | |
| 436 | for (i = 0; i < adapter->priv_num; i++) |
| 437 | list_del(&adapter->bss_prio_tbl[i].bss_prio_head); |
| 438 | |
| 439 | for (i = 0; i < adapter->priv_num; i++) { |
| 440 | if (adapter->priv[i]) { |
| 441 | priv = adapter->priv[i]; |
| 442 | for (j = 0; j < MAX_NUM_TID; ++j) |
| 443 | list_del(&priv->wmm.tid_tbl_ptr[j].ra_list); |
| 444 | list_del(&priv->tx_ba_stream_tbl_ptr); |
| 445 | list_del(&priv->rx_reorder_tbl_ptr); |
Avinash Patil | 017a92a | 2012-08-03 18:06:07 -0700 | [diff] [blame] | 446 | list_del(&priv->sta_list); |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 452 | * This function frees the adapter structure. |
| 453 | * |
| 454 | * The freeing operation is done recursively, by canceling all |
| 455 | * pending commands, freeing the member buffers previously |
| 456 | * allocated (command buffers, scan table buffer, sleep confirm |
| 457 | * command buffer), stopping the timers and calling the cleanup |
| 458 | * routines for every interface, before the actual adapter |
| 459 | * structure is freed. |
| 460 | */ |
| 461 | static void |
| 462 | mwifiex_free_adapter(struct mwifiex_adapter *adapter) |
| 463 | { |
| 464 | if (!adapter) { |
| 465 | pr_err("%s: adapter is NULL\n", __func__); |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | mwifiex_cancel_all_pending_cmd(adapter); |
| 470 | |
| 471 | /* Free lock variables */ |
| 472 | mwifiex_free_lock_list(adapter); |
| 473 | |
| 474 | /* Free command buffer */ |
| 475 | dev_dbg(adapter->dev, "info: free cmd buffer\n"); |
| 476 | mwifiex_free_cmd_buffer(adapter); |
| 477 | |
| 478 | del_timer(&adapter->cmd_timer); |
| 479 | |
| 480 | dev_dbg(adapter->dev, "info: free scan table\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 481 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 482 | if (adapter->if_ops.cleanup_if) |
| 483 | adapter->if_ops.cleanup_if(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 484 | |
Amitkumar Karwar | 2da8cbf | 2012-02-03 20:34:02 -0800 | [diff] [blame] | 485 | if (adapter->sleep_cfm) |
| 486 | dev_kfree_skb_any(adapter->sleep_cfm); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* |
| 490 | * This function intializes the lock variables and |
| 491 | * the list heads. |
| 492 | */ |
| 493 | int mwifiex_init_lock_list(struct mwifiex_adapter *adapter) |
| 494 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 495 | struct mwifiex_private *priv; |
| 496 | s32 i, j; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 497 | |
| 498 | spin_lock_init(&adapter->mwifiex_lock); |
| 499 | spin_lock_init(&adapter->int_lock); |
| 500 | spin_lock_init(&adapter->main_proc_lock); |
| 501 | spin_lock_init(&adapter->mwifiex_cmd_lock); |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 502 | spin_lock_init(&adapter->queue_lock); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 503 | for (i = 0; i < adapter->priv_num; i++) { |
| 504 | if (adapter->priv[i]) { |
| 505 | priv = adapter->priv[i]; |
| 506 | spin_lock_init(&priv->rx_pkt_lock); |
| 507 | spin_lock_init(&priv->wmm.ra_list_spinlock); |
| 508 | spin_lock_init(&priv->curr_bcn_buf_lock); |
Avinash Patil | 017a92a | 2012-08-03 18:06:07 -0700 | [diff] [blame] | 509 | spin_lock_init(&priv->sta_list_spinlock); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | /* Initialize cmd_free_q */ |
| 514 | INIT_LIST_HEAD(&adapter->cmd_free_q); |
| 515 | /* Initialize cmd_pending_q */ |
| 516 | INIT_LIST_HEAD(&adapter->cmd_pending_q); |
| 517 | /* Initialize scan_pending_q */ |
| 518 | INIT_LIST_HEAD(&adapter->scan_pending_q); |
| 519 | |
| 520 | spin_lock_init(&adapter->cmd_free_q_lock); |
| 521 | spin_lock_init(&adapter->cmd_pending_q_lock); |
| 522 | spin_lock_init(&adapter->scan_pending_q_lock); |
| 523 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 524 | skb_queue_head_init(&adapter->usb_rx_data_q); |
| 525 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 526 | for (i = 0; i < adapter->priv_num; ++i) { |
| 527 | INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head); |
| 528 | adapter->bss_prio_tbl[i].bss_prio_cur = NULL; |
| 529 | spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock); |
| 530 | } |
| 531 | |
| 532 | for (i = 0; i < adapter->priv_num; i++) { |
| 533 | if (!adapter->priv[i]) |
| 534 | continue; |
| 535 | priv = adapter->priv[i]; |
| 536 | for (j = 0; j < MAX_NUM_TID; ++j) { |
| 537 | INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list); |
| 538 | spin_lock_init(&priv->wmm.tid_tbl_ptr[j].tid_tbl_lock); |
| 539 | } |
| 540 | INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr); |
| 541 | INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); |
Avinash Patil | 017a92a | 2012-08-03 18:06:07 -0700 | [diff] [blame] | 542 | INIT_LIST_HEAD(&priv->sta_list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 543 | |
| 544 | spin_lock_init(&priv->tx_ba_stream_tbl_lock); |
| 545 | spin_lock_init(&priv->rx_reorder_tbl_lock); |
| 546 | } |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 552 | * This function initializes the firmware. |
| 553 | * |
| 554 | * The following operations are performed sequentially - |
| 555 | * - Allocate adapter structure |
| 556 | * - Initialize the adapter structure |
| 557 | * - Initialize the private structure |
| 558 | * - Add BSS priority tables to the adapter structure |
| 559 | * - For each interface, send the init commands to firmware |
| 560 | * - Send the first command in command pending queue, if available |
| 561 | */ |
| 562 | int mwifiex_init_fw(struct mwifiex_adapter *adapter) |
| 563 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 564 | int ret; |
| 565 | struct mwifiex_private *priv; |
| 566 | u8 i, first_sta = true; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 567 | int is_cmd_pend_q_empty; |
| 568 | unsigned long flags; |
| 569 | |
| 570 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; |
| 571 | |
| 572 | /* Allocate memory for member of adapter structure */ |
| 573 | ret = mwifiex_allocate_adapter(adapter); |
| 574 | if (ret) |
| 575 | return -1; |
| 576 | |
| 577 | /* Initialize adapter structure */ |
| 578 | mwifiex_init_adapter(adapter); |
| 579 | |
| 580 | for (i = 0; i < adapter->priv_num; i++) { |
| 581 | if (adapter->priv[i]) { |
| 582 | priv = adapter->priv[i]; |
| 583 | |
| 584 | /* Initialize private structure */ |
| 585 | ret = mwifiex_init_priv(priv); |
| 586 | if (ret) |
| 587 | return -1; |
| 588 | } |
| 589 | } |
Avinash Patil | c6d1d87 | 2013-01-03 21:21:29 -0800 | [diff] [blame] | 590 | |
| 591 | if (adapter->if_ops.init_fw_port) { |
| 592 | if (adapter->if_ops.init_fw_port(adapter)) |
| 593 | return -1; |
| 594 | } |
| 595 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 596 | for (i = 0; i < adapter->priv_num; i++) { |
| 597 | if (adapter->priv[i]) { |
| 598 | ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta); |
| 599 | if (ret == -1) |
| 600 | return -1; |
| 601 | |
| 602 | first_sta = false; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); |
| 607 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); |
| 608 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); |
| 609 | if (!is_cmd_pend_q_empty) { |
| 610 | /* Send the first command in queue and return */ |
| 611 | if (mwifiex_main_process(adapter) != -1) |
| 612 | ret = -EINPROGRESS; |
| 613 | } else { |
| 614 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; |
| 615 | } |
| 616 | |
| 617 | return ret; |
| 618 | } |
| 619 | |
| 620 | /* |
| 621 | * This function deletes the BSS priority tables. |
| 622 | * |
| 623 | * The function traverses through all the allocated BSS priority nodes |
| 624 | * in every BSS priority table and frees them. |
| 625 | */ |
| 626 | static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv) |
| 627 | { |
| 628 | int i; |
| 629 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 630 | struct mwifiex_bss_prio_node *bssprio_node, *tmp_node, **cur; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 631 | struct list_head *head; |
Yogesh Ashok Powar | 931f158 | 2012-03-13 19:22:36 -0700 | [diff] [blame] | 632 | spinlock_t *lock; /* bss priority lock */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 633 | unsigned long flags; |
| 634 | |
| 635 | for (i = 0; i < adapter->priv_num; ++i) { |
| 636 | head = &adapter->bss_prio_tbl[i].bss_prio_head; |
| 637 | cur = &adapter->bss_prio_tbl[i].bss_prio_cur; |
| 638 | lock = &adapter->bss_prio_tbl[i].bss_prio_lock; |
| 639 | dev_dbg(adapter->dev, "info: delete BSS priority table," |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 640 | " bss_type = %d, bss_num = %d, i = %d," |
| 641 | " head = %p, cur = %p\n", |
| 642 | priv->bss_type, priv->bss_num, i, head, *cur); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 643 | if (*cur) { |
| 644 | spin_lock_irqsave(lock, flags); |
| 645 | if (list_empty(head)) { |
| 646 | spin_unlock_irqrestore(lock, flags); |
| 647 | continue; |
| 648 | } |
| 649 | bssprio_node = list_first_entry(head, |
| 650 | struct mwifiex_bss_prio_node, list); |
| 651 | spin_unlock_irqrestore(lock, flags); |
| 652 | |
| 653 | list_for_each_entry_safe(bssprio_node, tmp_node, head, |
| 654 | list) { |
| 655 | if (bssprio_node->priv == priv) { |
| 656 | dev_dbg(adapter->dev, "info: Delete " |
| 657 | "node %p, next = %p\n", |
| 658 | bssprio_node, tmp_node); |
| 659 | spin_lock_irqsave(lock, flags); |
| 660 | list_del(&bssprio_node->list); |
| 661 | spin_unlock_irqrestore(lock, flags); |
| 662 | kfree(bssprio_node); |
| 663 | } |
| 664 | } |
| 665 | *cur = (struct mwifiex_bss_prio_node *)head; |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | /* |
Stone Piao | 9197ab9 | 2012-09-25 20:23:42 -0700 | [diff] [blame] | 671 | * This function frees the private structure, including cleans |
| 672 | * up the TX and RX queues and frees the BSS priority tables. |
| 673 | */ |
| 674 | void mwifiex_free_priv(struct mwifiex_private *priv) |
| 675 | { |
| 676 | mwifiex_clean_txrx(priv); |
| 677 | mwifiex_delete_bss_prio_tbl(priv); |
| 678 | mwifiex_free_curr_bcn(priv); |
| 679 | } |
| 680 | |
| 681 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 682 | * This function is used to shutdown the driver. |
| 683 | * |
| 684 | * The following operations are performed sequentially - |
| 685 | * - Check if already shut down |
| 686 | * - Make sure the main process has stopped |
| 687 | * - Clean up the Tx and Rx queues |
| 688 | * - Delete BSS priority tables |
| 689 | * - Free the adapter |
| 690 | * - Notify completion |
| 691 | */ |
| 692 | int |
| 693 | mwifiex_shutdown_drv(struct mwifiex_adapter *adapter) |
| 694 | { |
| 695 | int ret = -EINPROGRESS; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 696 | struct mwifiex_private *priv; |
| 697 | s32 i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 698 | unsigned long flags; |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 699 | struct sk_buff *skb; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 700 | |
| 701 | /* mwifiex already shutdown */ |
| 702 | if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY) |
| 703 | return 0; |
| 704 | |
| 705 | adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING; |
| 706 | /* wait for mwifiex_process to complete */ |
| 707 | if (adapter->mwifiex_processing) { |
| 708 | dev_warn(adapter->dev, "main process is still running\n"); |
| 709 | return ret; |
| 710 | } |
| 711 | |
| 712 | /* shut down mwifiex */ |
| 713 | dev_dbg(adapter->dev, "info: shutdown mwifiex...\n"); |
| 714 | |
| 715 | /* Clean up Tx/Rx queues and delete BSS priority table */ |
| 716 | for (i = 0; i < adapter->priv_num; i++) { |
| 717 | if (adapter->priv[i]) { |
| 718 | priv = adapter->priv[i]; |
| 719 | |
| 720 | mwifiex_clean_txrx(priv); |
| 721 | mwifiex_delete_bss_prio_tbl(priv); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | spin_lock_irqsave(&adapter->mwifiex_lock, flags); |
| 726 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 727 | if (adapter->if_ops.data_complete) { |
| 728 | while ((skb = skb_dequeue(&adapter->usb_rx_data_q))) { |
| 729 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); |
| 730 | |
| 731 | priv = adapter->priv[rx_info->bss_num]; |
| 732 | if (priv) |
| 733 | priv->stats.rx_dropped++; |
| 734 | |
| 735 | adapter->if_ops.data_complete(adapter, skb); |
| 736 | } |
| 737 | } |
| 738 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 739 | /* Free adapter structure */ |
| 740 | mwifiex_free_adapter(adapter); |
| 741 | |
| 742 | spin_unlock_irqrestore(&adapter->mwifiex_lock, flags); |
| 743 | |
| 744 | /* Notify completion */ |
| 745 | ret = mwifiex_shutdown_fw_complete(adapter); |
| 746 | |
| 747 | return ret; |
| 748 | } |
| 749 | |
| 750 | /* |
| 751 | * This function downloads the firmware to the card. |
| 752 | * |
| 753 | * The actual download is preceded by two sanity checks - |
| 754 | * - Check if firmware is already running |
| 755 | * - Check if the interface is the winner to download the firmware |
| 756 | * |
| 757 | * ...and followed by another - |
| 758 | * - Check if the firmware is downloaded successfully |
| 759 | * |
| 760 | * After download is successfully completed, the host interrupts are enabled. |
| 761 | */ |
| 762 | int mwifiex_dnld_fw(struct mwifiex_adapter *adapter, |
| 763 | struct mwifiex_fw_image *pmfw) |
| 764 | { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 765 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 766 | u32 poll_num = 1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 767 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 768 | if (adapter->if_ops.check_fw_status) { |
| 769 | adapter->winner = 0; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 770 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 771 | /* check if firmware is already running */ |
| 772 | ret = adapter->if_ops.check_fw_status(adapter, poll_num); |
| 773 | if (!ret) { |
| 774 | dev_notice(adapter->dev, |
| 775 | "WLAN FW already running! Skip FW dnld\n"); |
| 776 | goto done; |
| 777 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 778 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 779 | poll_num = MAX_FIRMWARE_POLL_TRIES; |
| 780 | |
| 781 | /* check if we are the winner for downloading FW */ |
| 782 | if (!adapter->winner) { |
| 783 | dev_notice(adapter->dev, |
| 784 | "FW already running! Skip FW dnld\n"); |
| 785 | poll_num = MAX_MULTI_INTERFACE_POLL_TRIES; |
| 786 | goto poll_fw; |
| 787 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 788 | } |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 789 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 790 | if (pmfw) { |
| 791 | /* Download firmware with helper */ |
| 792 | ret = adapter->if_ops.prog_fw(adapter, pmfw); |
| 793 | if (ret) { |
| 794 | dev_err(adapter->dev, "prog_fw failed ret=%#x\n", ret); |
| 795 | return ret; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | poll_fw: |
| 800 | /* Check if the firmware is downloaded successfully or not */ |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 801 | ret = adapter->if_ops.check_fw_status(adapter, poll_num); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 802 | if (ret) { |
| 803 | dev_err(adapter->dev, "FW failed to be active in time\n"); |
| 804 | return -1; |
| 805 | } |
| 806 | done: |
| 807 | /* re-enable host interrupt for mwifiex after fw dnld is successful */ |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 808 | if (adapter->if_ops.enable_int) |
| 809 | adapter->if_ops.enable_int(adapter); |
| 810 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 811 | return ret; |
| 812 | } |