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