init.c 19 KB

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