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