init.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * Marvell Wireless LAN device driver: HW/FW Initialization
  3. *
  4. * Copyright (C) 2011-2014, 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. return -ENOMEM;
  41. bss_prio->priv = priv;
  42. INIT_LIST_HEAD(&bss_prio->list);
  43. spin_lock_irqsave(&tbl[priv->bss_priority].bss_prio_lock, flags);
  44. list_add_tail(&bss_prio->list, &tbl[priv->bss_priority].bss_prio_head);
  45. spin_unlock_irqrestore(&tbl[priv->bss_priority].bss_prio_lock, flags);
  46. return 0;
  47. }
  48. /*
  49. * This function initializes the private structure and sets default
  50. * values to the members.
  51. *
  52. * Additionally, it also initializes all the locks and sets up all the
  53. * lists.
  54. */
  55. int mwifiex_init_priv(struct mwifiex_private *priv)
  56. {
  57. u32 i;
  58. priv->media_connected = false;
  59. memset(priv->curr_addr, 0xff, ETH_ALEN);
  60. priv->pkt_tx_ctrl = 0;
  61. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  62. priv->data_rate = 0; /* Initially indicate the rate as auto */
  63. priv->is_data_rate_auto = true;
  64. priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
  65. priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
  66. priv->sec_info.wep_enabled = 0;
  67. priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
  68. priv->sec_info.encryption_mode = 0;
  69. for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++)
  70. memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key));
  71. priv->wep_key_curr_index = 0;
  72. priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
  73. HostCmd_ACT_MAC_ETHERNETII_ENABLE;
  74. priv->beacon_period = 100; /* beacon interval */ ;
  75. priv->attempted_bss_desc = NULL;
  76. memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params));
  77. priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL;
  78. memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid));
  79. memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid));
  80. memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
  81. priv->assoc_rsp_size = 0;
  82. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  83. priv->atim_window = 0;
  84. priv->adhoc_state = ADHOC_IDLE;
  85. priv->tx_power_level = 0;
  86. priv->max_tx_power_level = 0;
  87. priv->min_tx_power_level = 0;
  88. priv->tx_rate = 0;
  89. priv->rxpd_htinfo = 0;
  90. priv->rxpd_rate = 0;
  91. priv->rate_bitmap = 0;
  92. priv->data_rssi_last = 0;
  93. priv->data_rssi_avg = 0;
  94. priv->data_nf_avg = 0;
  95. priv->data_nf_last = 0;
  96. priv->bcn_rssi_last = 0;
  97. priv->bcn_rssi_avg = 0;
  98. priv->bcn_nf_avg = 0;
  99. priv->bcn_nf_last = 0;
  100. memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  101. memset(&priv->aes_key, 0, sizeof(priv->aes_key));
  102. priv->wpa_ie_len = 0;
  103. priv->wpa_is_gtk_set = false;
  104. memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
  105. priv->assoc_tlv_buf_len = 0;
  106. memset(&priv->wps, 0, sizeof(priv->wps));
  107. memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
  108. priv->gen_ie_buf_len = 0;
  109. memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
  110. priv->wmm_required = true;
  111. priv->wmm_enabled = false;
  112. priv->wmm_qosinfo = 0;
  113. priv->curr_bcn_buf = NULL;
  114. priv->curr_bcn_size = 0;
  115. priv->wps_ie = NULL;
  116. priv->wps_ie_len = 0;
  117. priv->ap_11n_enabled = 0;
  118. memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg));
  119. priv->scan_block = false;
  120. priv->csa_chan = 0;
  121. priv->csa_expire_time = 0;
  122. priv->del_list_idx = 0;
  123. priv->hs2_enabled = false;
  124. memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID);
  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_SDIO)
  169. adapter->data_sent = true;
  170. else
  171. adapter->data_sent = false;
  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_chan_gap_time = MWIFIEX_DEF_SCAN_CHAN_GAP_TIME;
  185. adapter->scan_probes = 1;
  186. adapter->multiple_dtim = 1;
  187. adapter->local_listen_interval = 0; /* default value in firmware
  188. will be used */
  189. adapter->is_deep_sleep = false;
  190. adapter->delay_null_pkt = false;
  191. adapter->delay_to_ps = 1000;
  192. adapter->enhanced_ps_mode = PS_MODE_AUTO;
  193. adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
  194. default */
  195. adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
  196. default */
  197. adapter->pm_wakeup_card_req = false;
  198. adapter->pm_wakeup_fw_try = false;
  199. adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  200. adapter->is_hs_configured = false;
  201. adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF);
  202. adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF;
  203. adapter->hs_cfg.gap = HS_CFG_GAP_DEF;
  204. adapter->hs_activated = false;
  205. memset(adapter->event_body, 0, sizeof(adapter->event_body));
  206. adapter->hw_dot_11n_dev_cap = 0;
  207. adapter->hw_dev_mcs_support = 0;
  208. adapter->sec_chan_offset = 0;
  209. adapter->adhoc_11n_enabled = false;
  210. mwifiex_wmm_init(adapter);
  211. if (adapter->sleep_cfm) {
  212. sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
  213. adapter->sleep_cfm->data;
  214. memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
  215. sleep_cfm_buf->command =
  216. cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
  217. sleep_cfm_buf->size =
  218. cpu_to_le16(adapter->sleep_cfm->len);
  219. sleep_cfm_buf->result = 0;
  220. sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
  221. sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
  222. }
  223. memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
  224. memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
  225. adapter->tx_lock_flag = false;
  226. adapter->null_pkt_interval = 0;
  227. adapter->fw_bands = 0;
  228. adapter->config_bands = 0;
  229. adapter->adhoc_start_band = 0;
  230. adapter->scan_channels = NULL;
  231. adapter->fw_release_number = 0;
  232. adapter->fw_cap_info = 0;
  233. memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
  234. adapter->event_cause = 0;
  235. adapter->region_code = 0;
  236. adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
  237. adapter->adhoc_awake_period = 0;
  238. memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  239. adapter->arp_filter_size = 0;
  240. adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
  241. adapter->ext_scan = true;
  242. adapter->key_api_major_ver = 0;
  243. adapter->key_api_minor_ver = 0;
  244. }
  245. /*
  246. * This function sets trans_start per tx_queue
  247. */
  248. void mwifiex_set_trans_start(struct net_device *dev)
  249. {
  250. int i;
  251. for (i = 0; i < dev->num_tx_queues; i++)
  252. netdev_get_tx_queue(dev, i)->trans_start = jiffies;
  253. dev->trans_start = jiffies;
  254. }
  255. /*
  256. * This function wakes up all queues in net_device
  257. */
  258. void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
  259. struct mwifiex_adapter *adapter)
  260. {
  261. unsigned long dev_queue_flags;
  262. unsigned int i;
  263. spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
  264. for (i = 0; i < netdev->num_tx_queues; i++) {
  265. struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
  266. if (netif_tx_queue_stopped(txq))
  267. netif_tx_wake_queue(txq);
  268. }
  269. spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
  270. }
  271. /*
  272. * This function stops all queues in net_device
  273. */
  274. void mwifiex_stop_net_dev_queue(struct net_device *netdev,
  275. struct mwifiex_adapter *adapter)
  276. {
  277. unsigned long dev_queue_flags;
  278. unsigned int i;
  279. spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
  280. for (i = 0; i < netdev->num_tx_queues; i++) {
  281. struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
  282. if (!netif_tx_queue_stopped(txq))
  283. netif_tx_stop_queue(txq);
  284. }
  285. spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
  286. }
  287. /*
  288. * This function releases the lock variables and frees the locks and
  289. * associated locks.
  290. */
  291. static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
  292. {
  293. struct mwifiex_private *priv;
  294. s32 i, j;
  295. /* Free lists */
  296. list_del(&adapter->cmd_free_q);
  297. list_del(&adapter->cmd_pending_q);
  298. list_del(&adapter->scan_pending_q);
  299. for (i = 0; i < adapter->priv_num; i++)
  300. list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
  301. for (i = 0; i < adapter->priv_num; i++) {
  302. if (adapter->priv[i]) {
  303. priv = adapter->priv[i];
  304. for (j = 0; j < MAX_NUM_TID; ++j)
  305. list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
  306. list_del(&priv->tx_ba_stream_tbl_ptr);
  307. list_del(&priv->rx_reorder_tbl_ptr);
  308. list_del(&priv->sta_list);
  309. }
  310. }
  311. }
  312. /*
  313. * This function performs cleanup for adapter structure.
  314. *
  315. * The cleanup is done recursively, by canceling all pending
  316. * commands, freeing the member buffers previously allocated
  317. * (command buffers, scan table buffer, sleep confirm command
  318. * buffer), stopping the timers and calling the cleanup routines
  319. * for every interface.
  320. */
  321. static void
  322. mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter)
  323. {
  324. int idx;
  325. if (!adapter) {
  326. pr_err("%s: adapter is NULL\n", __func__);
  327. return;
  328. }
  329. mwifiex_cancel_all_pending_cmd(adapter);
  330. /* Free lock variables */
  331. mwifiex_free_lock_list(adapter);
  332. /* Free command buffer */
  333. dev_dbg(adapter->dev, "info: free cmd buffer\n");
  334. mwifiex_free_cmd_buffer(adapter);
  335. for (idx = 0; idx < adapter->num_mem_types; idx++) {
  336. struct memory_type_mapping *entry =
  337. &adapter->mem_type_mapping_tbl[idx];
  338. if (entry->mem_ptr) {
  339. vfree(entry->mem_ptr);
  340. entry->mem_ptr = NULL;
  341. }
  342. entry->mem_size = 0;
  343. }
  344. if (adapter->sleep_cfm)
  345. dev_kfree_skb_any(adapter->sleep_cfm);
  346. }
  347. /*
  348. * This function intializes the lock variables and
  349. * the list heads.
  350. */
  351. int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
  352. {
  353. struct mwifiex_private *priv;
  354. s32 i, j;
  355. spin_lock_init(&adapter->mwifiex_lock);
  356. spin_lock_init(&adapter->int_lock);
  357. spin_lock_init(&adapter->main_proc_lock);
  358. spin_lock_init(&adapter->mwifiex_cmd_lock);
  359. spin_lock_init(&adapter->queue_lock);
  360. for (i = 0; i < adapter->priv_num; i++) {
  361. if (adapter->priv[i]) {
  362. priv = adapter->priv[i];
  363. spin_lock_init(&priv->rx_pkt_lock);
  364. spin_lock_init(&priv->wmm.ra_list_spinlock);
  365. spin_lock_init(&priv->curr_bcn_buf_lock);
  366. spin_lock_init(&priv->sta_list_spinlock);
  367. }
  368. }
  369. /* Initialize cmd_free_q */
  370. INIT_LIST_HEAD(&adapter->cmd_free_q);
  371. /* Initialize cmd_pending_q */
  372. INIT_LIST_HEAD(&adapter->cmd_pending_q);
  373. /* Initialize scan_pending_q */
  374. INIT_LIST_HEAD(&adapter->scan_pending_q);
  375. spin_lock_init(&adapter->cmd_free_q_lock);
  376. spin_lock_init(&adapter->cmd_pending_q_lock);
  377. spin_lock_init(&adapter->scan_pending_q_lock);
  378. spin_lock_init(&adapter->rx_proc_lock);
  379. skb_queue_head_init(&adapter->usb_rx_data_q);
  380. skb_queue_head_init(&adapter->rx_data_q);
  381. for (i = 0; i < adapter->priv_num; ++i) {
  382. INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
  383. spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
  384. }
  385. for (i = 0; i < adapter->priv_num; i++) {
  386. if (!adapter->priv[i])
  387. continue;
  388. priv = adapter->priv[i];
  389. for (j = 0; j < MAX_NUM_TID; ++j)
  390. INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
  391. INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
  392. INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
  393. INIT_LIST_HEAD(&priv->sta_list);
  394. skb_queue_head_init(&priv->tdls_txq);
  395. spin_lock_init(&priv->tx_ba_stream_tbl_lock);
  396. spin_lock_init(&priv->rx_reorder_tbl_lock);
  397. }
  398. return 0;
  399. }
  400. /*
  401. * This function initializes the firmware.
  402. *
  403. * The following operations are performed sequentially -
  404. * - Allocate adapter structure
  405. * - Initialize the adapter structure
  406. * - Initialize the private structure
  407. * - Add BSS priority tables to the adapter structure
  408. * - For each interface, send the init commands to firmware
  409. * - Send the first command in command pending queue, if available
  410. */
  411. int mwifiex_init_fw(struct mwifiex_adapter *adapter)
  412. {
  413. int ret;
  414. struct mwifiex_private *priv;
  415. u8 i, first_sta = true;
  416. int is_cmd_pend_q_empty;
  417. unsigned long flags;
  418. adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
  419. /* Allocate memory for member of adapter structure */
  420. ret = mwifiex_allocate_adapter(adapter);
  421. if (ret)
  422. return -1;
  423. /* Initialize adapter structure */
  424. mwifiex_init_adapter(adapter);
  425. for (i = 0; i < adapter->priv_num; i++) {
  426. if (adapter->priv[i]) {
  427. priv = adapter->priv[i];
  428. /* Initialize private structure */
  429. ret = mwifiex_init_priv(priv);
  430. if (ret)
  431. return -1;
  432. }
  433. }
  434. if (adapter->if_ops.init_fw_port) {
  435. if (adapter->if_ops.init_fw_port(adapter))
  436. return -1;
  437. }
  438. for (i = 0; i < adapter->priv_num; i++) {
  439. if (adapter->priv[i]) {
  440. ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta);
  441. if (ret == -1)
  442. return -1;
  443. first_sta = false;
  444. }
  445. }
  446. spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
  447. is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
  448. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
  449. if (!is_cmd_pend_q_empty) {
  450. /* Send the first command in queue and return */
  451. if (mwifiex_main_process(adapter) != -1)
  452. ret = -EINPROGRESS;
  453. } else {
  454. adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  455. }
  456. return ret;
  457. }
  458. /*
  459. * This function deletes the BSS priority tables.
  460. *
  461. * The function traverses through all the allocated BSS priority nodes
  462. * in every BSS priority table and frees them.
  463. */
  464. static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
  465. {
  466. int i;
  467. struct mwifiex_adapter *adapter = priv->adapter;
  468. struct mwifiex_bss_prio_node *bssprio_node, *tmp_node;
  469. struct list_head *head;
  470. spinlock_t *lock; /* bss priority lock */
  471. unsigned long flags;
  472. for (i = 0; i < adapter->priv_num; ++i) {
  473. head = &adapter->bss_prio_tbl[i].bss_prio_head;
  474. lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
  475. dev_dbg(adapter->dev, "info: delete BSS priority table,"
  476. " bss_type = %d, bss_num = %d, i = %d,"
  477. " head = %p\n",
  478. priv->bss_type, priv->bss_num, i, head);
  479. {
  480. spin_lock_irqsave(lock, flags);
  481. if (list_empty(head)) {
  482. spin_unlock_irqrestore(lock, flags);
  483. continue;
  484. }
  485. list_for_each_entry_safe(bssprio_node, tmp_node, head,
  486. list) {
  487. if (bssprio_node->priv == priv) {
  488. dev_dbg(adapter->dev, "info: Delete "
  489. "node %p, next = %p\n",
  490. bssprio_node, tmp_node);
  491. list_del(&bssprio_node->list);
  492. kfree(bssprio_node);
  493. }
  494. }
  495. spin_unlock_irqrestore(lock, flags);
  496. }
  497. }
  498. }
  499. /*
  500. * This function frees the private structure, including cleans
  501. * up the TX and RX queues and frees the BSS priority tables.
  502. */
  503. void mwifiex_free_priv(struct mwifiex_private *priv)
  504. {
  505. mwifiex_clean_txrx(priv);
  506. mwifiex_delete_bss_prio_tbl(priv);
  507. mwifiex_free_curr_bcn(priv);
  508. }
  509. /*
  510. * This function is used to shutdown the driver.
  511. *
  512. * The following operations are performed sequentially -
  513. * - Check if already shut down
  514. * - Make sure the main process has stopped
  515. * - Clean up the Tx and Rx queues
  516. * - Delete BSS priority tables
  517. * - Free the adapter
  518. * - Notify completion
  519. */
  520. int
  521. mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
  522. {
  523. int ret = -EINPROGRESS;
  524. struct mwifiex_private *priv;
  525. s32 i;
  526. unsigned long flags;
  527. struct sk_buff *skb;
  528. /* mwifiex already shutdown */
  529. if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
  530. return 0;
  531. adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING;
  532. /* wait for mwifiex_process to complete */
  533. if (adapter->mwifiex_processing) {
  534. dev_warn(adapter->dev, "main process is still running\n");
  535. return ret;
  536. }
  537. /* cancel current command */
  538. if (adapter->curr_cmd) {
  539. dev_warn(adapter->dev, "curr_cmd is still in processing\n");
  540. del_timer_sync(&adapter->cmd_timer);
  541. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  542. adapter->curr_cmd = NULL;
  543. }
  544. /* shut down mwifiex */
  545. dev_dbg(adapter->dev, "info: shutdown mwifiex...\n");
  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. mwifiex_clean_txrx(priv);
  551. mwifiex_delete_bss_prio_tbl(priv);
  552. }
  553. }
  554. spin_lock_irqsave(&adapter->rx_proc_lock, flags);
  555. while ((skb = skb_dequeue(&adapter->rx_data_q))) {
  556. struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
  557. atomic_dec(&adapter->rx_pending);
  558. priv = adapter->priv[rx_info->bss_num];
  559. if (priv)
  560. priv->stats.rx_dropped++;
  561. dev_kfree_skb_any(skb);
  562. }
  563. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  564. spin_lock(&adapter->mwifiex_lock);
  565. if (adapter->if_ops.data_complete) {
  566. while ((skb = skb_dequeue(&adapter->usb_rx_data_q))) {
  567. struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
  568. priv = adapter->priv[rx_info->bss_num];
  569. if (priv)
  570. priv->stats.rx_dropped++;
  571. dev_kfree_skb_any(skb);
  572. adapter->if_ops.data_complete(adapter);
  573. }
  574. }
  575. mwifiex_adapter_cleanup(adapter);
  576. spin_unlock(&adapter->mwifiex_lock);
  577. /* Notify completion */
  578. ret = mwifiex_shutdown_fw_complete(adapter);
  579. return ret;
  580. }
  581. /*
  582. * This function downloads the firmware to the card.
  583. *
  584. * The actual download is preceded by two sanity checks -
  585. * - Check if firmware is already running
  586. * - Check if the interface is the winner to download the firmware
  587. *
  588. * ...and followed by another -
  589. * - Check if the firmware is downloaded successfully
  590. *
  591. * After download is successfully completed, the host interrupts are enabled.
  592. */
  593. int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
  594. struct mwifiex_fw_image *pmfw)
  595. {
  596. int ret;
  597. u32 poll_num = 1;
  598. if (adapter->if_ops.check_fw_status) {
  599. adapter->winner = 0;
  600. /* check if firmware is already running */
  601. ret = adapter->if_ops.check_fw_status(adapter, poll_num);
  602. if (!ret) {
  603. dev_notice(adapter->dev,
  604. "WLAN FW already running! Skip FW dnld\n");
  605. return 0;
  606. }
  607. poll_num = MAX_FIRMWARE_POLL_TRIES;
  608. /* check if we are the winner for downloading FW */
  609. if (!adapter->winner) {
  610. dev_notice(adapter->dev,
  611. "FW already running! Skip FW dnld\n");
  612. goto poll_fw;
  613. }
  614. }
  615. if (pmfw) {
  616. /* Download firmware with helper */
  617. ret = adapter->if_ops.prog_fw(adapter, pmfw);
  618. if (ret) {
  619. dev_err(adapter->dev, "prog_fw failed ret=%#x\n", ret);
  620. return ret;
  621. }
  622. }
  623. poll_fw:
  624. /* Check if the firmware is downloaded successfully or not */
  625. ret = adapter->if_ops.check_fw_status(adapter, poll_num);
  626. if (ret)
  627. dev_err(adapter->dev, "FW failed to be active in time\n");
  628. return ret;
  629. }