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