init.c 19 KB

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