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