init.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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. static void wakeup_timer_fn(unsigned long data)
  49. {
  50. struct mwifiex_adapter *adapter = (struct mwifiex_adapter *)data;
  51. mwifiex_dbg(adapter, ERROR, "Firmware wakeup failed\n");
  52. adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
  53. mwifiex_cancel_all_pending_cmd(adapter);
  54. if (adapter->if_ops.card_reset)
  55. adapter->if_ops.card_reset(adapter);
  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. int mwifiex_init_priv(struct mwifiex_private *priv)
  65. {
  66. u32 i;
  67. priv->media_connected = false;
  68. eth_broadcast_addr(priv->curr_addr);
  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_enabled = 0;
  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->wps_ie = NULL;
  125. priv->wps_ie_len = 0;
  126. priv->ap_11n_enabled = 0;
  127. memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg));
  128. priv->scan_block = false;
  129. priv->csa_chan = 0;
  130. priv->csa_expire_time = 0;
  131. priv->del_list_idx = 0;
  132. priv->hs2_enabled = false;
  133. priv->check_tdls_tx = false;
  134. memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID);
  135. mwifiex_init_11h_params(priv);
  136. return mwifiex_add_bss_prio_tbl(priv);
  137. }
  138. /*
  139. * This function allocates buffers for members of the adapter
  140. * structure.
  141. *
  142. * The memory allocated includes scan table, command buffers, and
  143. * sleep confirm command buffer. In addition, the queues are
  144. * also initialized.
  145. */
  146. static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
  147. {
  148. int ret;
  149. /* Allocate command buffer */
  150. ret = mwifiex_alloc_cmd_buffer(adapter);
  151. if (ret) {
  152. mwifiex_dbg(adapter, ERROR,
  153. "%s: failed to alloc cmd buffer\n",
  154. __func__);
  155. return -1;
  156. }
  157. adapter->sleep_cfm =
  158. dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
  159. + INTF_HEADER_LEN);
  160. if (!adapter->sleep_cfm) {
  161. mwifiex_dbg(adapter, ERROR,
  162. "%s: failed to alloc sleep cfm\t"
  163. " cmd buffer\n", __func__);
  164. return -1;
  165. }
  166. skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
  167. return 0;
  168. }
  169. /*
  170. * This function initializes the adapter structure and sets default
  171. * values to the members of adapter.
  172. *
  173. * This also initializes the WMM related parameters in the driver private
  174. * structures.
  175. */
  176. static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
  177. {
  178. struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
  179. skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
  180. adapter->cmd_sent = false;
  181. if (adapter->iface_type == MWIFIEX_SDIO)
  182. adapter->data_sent = true;
  183. else
  184. adapter->data_sent = false;
  185. adapter->cmd_resp_received = false;
  186. adapter->event_received = false;
  187. adapter->data_received = false;
  188. adapter->surprise_removed = false;
  189. adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
  190. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  191. adapter->ps_state = PS_STATE_AWAKE;
  192. adapter->need_to_wakeup = false;
  193. adapter->scan_mode = HostCmd_BSS_MODE_ANY;
  194. adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
  195. adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
  196. adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
  197. adapter->scan_chan_gap_time = MWIFIEX_DEF_SCAN_CHAN_GAP_TIME;
  198. adapter->scan_probes = 1;
  199. adapter->multiple_dtim = 1;
  200. adapter->local_listen_interval = 0; /* default value in firmware
  201. will be used */
  202. adapter->is_deep_sleep = false;
  203. adapter->delay_null_pkt = false;
  204. adapter->delay_to_ps = 1000;
  205. adapter->enhanced_ps_mode = PS_MODE_AUTO;
  206. adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
  207. default */
  208. adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
  209. default */
  210. adapter->pm_wakeup_card_req = false;
  211. adapter->pm_wakeup_fw_try = false;
  212. adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  213. adapter->is_hs_configured = false;
  214. adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF);
  215. adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF;
  216. adapter->hs_cfg.gap = HS_CFG_GAP_DEF;
  217. adapter->hs_activated = false;
  218. memset(adapter->event_body, 0, sizeof(adapter->event_body));
  219. adapter->hw_dot_11n_dev_cap = 0;
  220. adapter->hw_dev_mcs_support = 0;
  221. adapter->sec_chan_offset = 0;
  222. adapter->adhoc_11n_enabled = false;
  223. mwifiex_wmm_init(adapter);
  224. sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
  225. adapter->sleep_cfm->data;
  226. memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
  227. sleep_cfm_buf->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
  228. sleep_cfm_buf->size = cpu_to_le16(adapter->sleep_cfm->len);
  229. sleep_cfm_buf->result = 0;
  230. sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
  231. sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
  232. memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
  233. memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
  234. adapter->tx_lock_flag = false;
  235. adapter->null_pkt_interval = 0;
  236. adapter->fw_bands = 0;
  237. adapter->config_bands = 0;
  238. adapter->adhoc_start_band = 0;
  239. adapter->scan_channels = NULL;
  240. adapter->fw_release_number = 0;
  241. adapter->fw_cap_info = 0;
  242. memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
  243. adapter->event_cause = 0;
  244. adapter->region_code = 0;
  245. adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
  246. adapter->adhoc_awake_period = 0;
  247. memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  248. adapter->arp_filter_size = 0;
  249. adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
  250. adapter->key_api_major_ver = 0;
  251. adapter->key_api_minor_ver = 0;
  252. eth_broadcast_addr(adapter->perm_addr);
  253. adapter->iface_limit.sta_intf = MWIFIEX_MAX_STA_NUM;
  254. adapter->iface_limit.uap_intf = MWIFIEX_MAX_UAP_NUM;
  255. adapter->iface_limit.p2p_intf = MWIFIEX_MAX_P2P_NUM;
  256. setup_timer(&adapter->wakeup_timer, wakeup_timer_fn,
  257. (unsigned long)adapter);
  258. }
  259. /*
  260. * This function sets trans_start per tx_queue
  261. */
  262. void mwifiex_set_trans_start(struct net_device *dev)
  263. {
  264. int i;
  265. for (i = 0; i < dev->num_tx_queues; i++)
  266. netdev_get_tx_queue(dev, i)->trans_start = jiffies;
  267. dev->trans_start = jiffies;
  268. }
  269. /*
  270. * This function wakes up all queues in net_device
  271. */
  272. void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
  273. struct mwifiex_adapter *adapter)
  274. {
  275. unsigned long dev_queue_flags;
  276. unsigned int i;
  277. spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
  278. for (i = 0; i < netdev->num_tx_queues; i++) {
  279. struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
  280. if (netif_tx_queue_stopped(txq))
  281. netif_tx_wake_queue(txq);
  282. }
  283. spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
  284. }
  285. /*
  286. * This function stops all queues in net_device
  287. */
  288. void mwifiex_stop_net_dev_queue(struct net_device *netdev,
  289. struct mwifiex_adapter *adapter)
  290. {
  291. unsigned long dev_queue_flags;
  292. unsigned int i;
  293. spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
  294. for (i = 0; i < netdev->num_tx_queues; i++) {
  295. struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
  296. if (!netif_tx_queue_stopped(txq))
  297. netif_tx_stop_queue(txq);
  298. }
  299. spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
  300. }
  301. /*
  302. * This function releases the lock variables and frees the locks and
  303. * associated locks.
  304. */
  305. static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
  306. {
  307. struct mwifiex_private *priv;
  308. s32 i, j;
  309. /* Free lists */
  310. list_del(&adapter->cmd_free_q);
  311. list_del(&adapter->cmd_pending_q);
  312. list_del(&adapter->scan_pending_q);
  313. for (i = 0; i < adapter->priv_num; i++)
  314. list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
  315. for (i = 0; i < adapter->priv_num; i++) {
  316. if (adapter->priv[i]) {
  317. priv = adapter->priv[i];
  318. for (j = 0; j < MAX_NUM_TID; ++j)
  319. list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
  320. list_del(&priv->tx_ba_stream_tbl_ptr);
  321. list_del(&priv->rx_reorder_tbl_ptr);
  322. list_del(&priv->sta_list);
  323. list_del(&priv->auto_tdls_list);
  324. }
  325. }
  326. }
  327. /*
  328. * This function performs cleanup for adapter structure.
  329. *
  330. * The cleanup is done recursively, by canceling all pending
  331. * commands, freeing the member buffers previously allocated
  332. * (command buffers, scan table buffer, sleep confirm command
  333. * buffer), stopping the timers and calling the cleanup routines
  334. * for every interface.
  335. */
  336. static void
  337. mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter)
  338. {
  339. int idx;
  340. if (!adapter) {
  341. pr_err("%s: adapter is NULL\n", __func__);
  342. return;
  343. }
  344. del_timer(&adapter->wakeup_timer);
  345. mwifiex_cancel_all_pending_cmd(adapter);
  346. wake_up_interruptible(&adapter->cmd_wait_q.wait);
  347. wake_up_interruptible(&adapter->hs_activate_wait_q);
  348. /* Free lock variables */
  349. mwifiex_free_lock_list(adapter);
  350. /* Free command buffer */
  351. mwifiex_dbg(adapter, INFO, "info: free cmd buffer\n");
  352. mwifiex_free_cmd_buffer(adapter);
  353. for (idx = 0; idx < adapter->num_mem_types; idx++) {
  354. struct memory_type_mapping *entry =
  355. &adapter->mem_type_mapping_tbl[idx];
  356. if (entry->mem_ptr) {
  357. vfree(entry->mem_ptr);
  358. entry->mem_ptr = NULL;
  359. }
  360. entry->mem_size = 0;
  361. }
  362. if (adapter->drv_info_dump) {
  363. vfree(adapter->drv_info_dump);
  364. adapter->drv_info_dump = NULL;
  365. adapter->drv_info_size = 0;
  366. }
  367. if (adapter->sleep_cfm)
  368. dev_kfree_skb_any(adapter->sleep_cfm);
  369. }
  370. /*
  371. * This function intializes the lock variables and
  372. * the list heads.
  373. */
  374. int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
  375. {
  376. struct mwifiex_private *priv;
  377. s32 i, j;
  378. spin_lock_init(&adapter->mwifiex_lock);
  379. spin_lock_init(&adapter->int_lock);
  380. spin_lock_init(&adapter->main_proc_lock);
  381. spin_lock_init(&adapter->mwifiex_cmd_lock);
  382. spin_lock_init(&adapter->queue_lock);
  383. for (i = 0; i < adapter->priv_num; i++) {
  384. if (adapter->priv[i]) {
  385. priv = adapter->priv[i];
  386. spin_lock_init(&priv->rx_pkt_lock);
  387. spin_lock_init(&priv->wmm.ra_list_spinlock);
  388. spin_lock_init(&priv->curr_bcn_buf_lock);
  389. spin_lock_init(&priv->sta_list_spinlock);
  390. spin_lock_init(&priv->auto_tdls_lock);
  391. }
  392. }
  393. /* Initialize cmd_free_q */
  394. INIT_LIST_HEAD(&adapter->cmd_free_q);
  395. /* Initialize cmd_pending_q */
  396. INIT_LIST_HEAD(&adapter->cmd_pending_q);
  397. /* Initialize scan_pending_q */
  398. INIT_LIST_HEAD(&adapter->scan_pending_q);
  399. spin_lock_init(&adapter->cmd_free_q_lock);
  400. spin_lock_init(&adapter->cmd_pending_q_lock);
  401. spin_lock_init(&adapter->scan_pending_q_lock);
  402. spin_lock_init(&adapter->rx_proc_lock);
  403. skb_queue_head_init(&adapter->rx_data_q);
  404. skb_queue_head_init(&adapter->tx_data_q);
  405. for (i = 0; i < adapter->priv_num; ++i) {
  406. INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
  407. spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
  408. }
  409. for (i = 0; i < adapter->priv_num; i++) {
  410. if (!adapter->priv[i])
  411. continue;
  412. priv = adapter->priv[i];
  413. for (j = 0; j < MAX_NUM_TID; ++j)
  414. INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
  415. INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
  416. INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
  417. INIT_LIST_HEAD(&priv->sta_list);
  418. INIT_LIST_HEAD(&priv->auto_tdls_list);
  419. skb_queue_head_init(&priv->tdls_txq);
  420. spin_lock_init(&priv->tx_ba_stream_tbl_lock);
  421. spin_lock_init(&priv->rx_reorder_tbl_lock);
  422. spin_lock_init(&priv->ack_status_lock);
  423. idr_init(&priv->ack_status_frames);
  424. }
  425. return 0;
  426. }
  427. /*
  428. * This function initializes the firmware.
  429. *
  430. * The following operations are performed sequentially -
  431. * - Allocate adapter structure
  432. * - Initialize the adapter structure
  433. * - Initialize the private structure
  434. * - Add BSS priority tables to the adapter structure
  435. * - For each interface, send the init commands to firmware
  436. * - Send the first command in command pending queue, if available
  437. */
  438. int mwifiex_init_fw(struct mwifiex_adapter *adapter)
  439. {
  440. int ret;
  441. struct mwifiex_private *priv;
  442. u8 i, first_sta = true;
  443. int is_cmd_pend_q_empty;
  444. unsigned long flags;
  445. adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
  446. /* Allocate memory for member of adapter structure */
  447. ret = mwifiex_allocate_adapter(adapter);
  448. if (ret)
  449. return -1;
  450. /* Initialize adapter structure */
  451. mwifiex_init_adapter(adapter);
  452. for (i = 0; i < adapter->priv_num; i++) {
  453. if (adapter->priv[i]) {
  454. priv = adapter->priv[i];
  455. /* Initialize private structure */
  456. ret = mwifiex_init_priv(priv);
  457. if (ret)
  458. return -1;
  459. }
  460. }
  461. if (adapter->if_ops.init_fw_port) {
  462. if (adapter->if_ops.init_fw_port(adapter))
  463. return -1;
  464. }
  465. for (i = 0; i < adapter->priv_num; i++) {
  466. if (adapter->priv[i]) {
  467. ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta,
  468. true);
  469. if (ret == -1)
  470. return -1;
  471. first_sta = false;
  472. }
  473. }
  474. spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
  475. is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
  476. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
  477. if (!is_cmd_pend_q_empty) {
  478. /* Send the first command in queue and return */
  479. if (mwifiex_main_process(adapter) != -1)
  480. ret = -EINPROGRESS;
  481. } else {
  482. adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  483. }
  484. return ret;
  485. }
  486. /*
  487. * This function deletes the BSS priority tables.
  488. *
  489. * The function traverses through all the allocated BSS priority nodes
  490. * in every BSS priority table and frees them.
  491. */
  492. static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
  493. {
  494. int i;
  495. struct mwifiex_adapter *adapter = priv->adapter;
  496. struct mwifiex_bss_prio_node *bssprio_node, *tmp_node;
  497. struct list_head *head;
  498. spinlock_t *lock; /* bss priority lock */
  499. unsigned long flags;
  500. for (i = 0; i < adapter->priv_num; ++i) {
  501. head = &adapter->bss_prio_tbl[i].bss_prio_head;
  502. lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
  503. mwifiex_dbg(adapter, INFO,
  504. "info: delete BSS priority table,\t"
  505. "bss_type = %d, bss_num = %d, i = %d,\t"
  506. "head = %p\n",
  507. priv->bss_type, priv->bss_num, i, head);
  508. {
  509. spin_lock_irqsave(lock, flags);
  510. if (list_empty(head)) {
  511. spin_unlock_irqrestore(lock, flags);
  512. continue;
  513. }
  514. list_for_each_entry_safe(bssprio_node, tmp_node, head,
  515. list) {
  516. if (bssprio_node->priv == priv) {
  517. mwifiex_dbg(adapter, INFO,
  518. "info: Delete\t"
  519. "node %p, next = %p\n",
  520. bssprio_node, tmp_node);
  521. list_del(&bssprio_node->list);
  522. kfree(bssprio_node);
  523. }
  524. }
  525. spin_unlock_irqrestore(lock, flags);
  526. }
  527. }
  528. }
  529. /*
  530. * This function frees the private structure, including cleans
  531. * up the TX and RX queues and frees the BSS priority tables.
  532. */
  533. void mwifiex_free_priv(struct mwifiex_private *priv)
  534. {
  535. mwifiex_clean_txrx(priv);
  536. mwifiex_delete_bss_prio_tbl(priv);
  537. mwifiex_free_curr_bcn(priv);
  538. }
  539. /*
  540. * This function is used to shutdown the driver.
  541. *
  542. * The following operations are performed sequentially -
  543. * - Check if already shut down
  544. * - Make sure the main process has stopped
  545. * - Clean up the Tx and Rx queues
  546. * - Delete BSS priority tables
  547. * - Free the adapter
  548. * - Notify completion
  549. */
  550. int
  551. mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
  552. {
  553. int ret = -EINPROGRESS;
  554. struct mwifiex_private *priv;
  555. s32 i;
  556. unsigned long flags;
  557. struct sk_buff *skb;
  558. /* mwifiex already shutdown */
  559. if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
  560. return 0;
  561. adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING;
  562. /* wait for mwifiex_process to complete */
  563. if (adapter->mwifiex_processing) {
  564. mwifiex_dbg(adapter, WARN,
  565. "main process is still running\n");
  566. return ret;
  567. }
  568. /* cancel current command */
  569. if (adapter->curr_cmd) {
  570. mwifiex_dbg(adapter, WARN,
  571. "curr_cmd is still in processing\n");
  572. del_timer_sync(&adapter->cmd_timer);
  573. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  574. adapter->curr_cmd = NULL;
  575. }
  576. /* shut down mwifiex */
  577. mwifiex_dbg(adapter, MSG,
  578. "info: shutdown mwifiex...\n");
  579. /* Clean up Tx/Rx queues and delete BSS priority table */
  580. for (i = 0; i < adapter->priv_num; i++) {
  581. if (adapter->priv[i]) {
  582. priv = adapter->priv[i];
  583. mwifiex_clean_auto_tdls(priv);
  584. mwifiex_abort_cac(priv);
  585. mwifiex_clean_txrx(priv);
  586. mwifiex_delete_bss_prio_tbl(priv);
  587. }
  588. }
  589. atomic_set(&adapter->tx_queued, 0);
  590. while ((skb = skb_dequeue(&adapter->tx_data_q)))
  591. mwifiex_write_data_complete(adapter, skb, 0, 0);
  592. spin_lock_irqsave(&adapter->rx_proc_lock, flags);
  593. while ((skb = skb_dequeue(&adapter->rx_data_q))) {
  594. struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
  595. atomic_dec(&adapter->rx_pending);
  596. priv = adapter->priv[rx_info->bss_num];
  597. if (priv)
  598. priv->stats.rx_dropped++;
  599. dev_kfree_skb_any(skb);
  600. }
  601. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  602. spin_lock(&adapter->mwifiex_lock);
  603. mwifiex_adapter_cleanup(adapter);
  604. spin_unlock(&adapter->mwifiex_lock);
  605. /* Notify completion */
  606. ret = mwifiex_shutdown_fw_complete(adapter);
  607. return ret;
  608. }
  609. /*
  610. * This function downloads the firmware to the card.
  611. *
  612. * The actual download is preceded by two sanity checks -
  613. * - Check if firmware is already running
  614. * - Check if the interface is the winner to download the firmware
  615. *
  616. * ...and followed by another -
  617. * - Check if the firmware is downloaded successfully
  618. *
  619. * After download is successfully completed, the host interrupts are enabled.
  620. */
  621. int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
  622. struct mwifiex_fw_image *pmfw)
  623. {
  624. int ret;
  625. u32 poll_num = 1;
  626. if (adapter->if_ops.check_fw_status) {
  627. adapter->winner = 0;
  628. /* check if firmware is already running */
  629. ret = adapter->if_ops.check_fw_status(adapter, poll_num);
  630. if (!ret) {
  631. mwifiex_dbg(adapter, MSG,
  632. "WLAN FW already running! Skip FW dnld\n");
  633. return 0;
  634. }
  635. poll_num = MAX_FIRMWARE_POLL_TRIES;
  636. /* check if we are the winner for downloading FW */
  637. if (!adapter->winner) {
  638. mwifiex_dbg(adapter, MSG,
  639. "FW already running! Skip FW dnld\n");
  640. goto poll_fw;
  641. }
  642. }
  643. if (pmfw) {
  644. /* Download firmware with helper */
  645. ret = adapter->if_ops.prog_fw(adapter, pmfw);
  646. if (ret) {
  647. mwifiex_dbg(adapter, ERROR,
  648. "prog_fw failed ret=%#x\n", ret);
  649. return ret;
  650. }
  651. }
  652. poll_fw:
  653. /* Check if the firmware is downloaded successfully or not */
  654. ret = adapter->if_ops.check_fw_status(adapter, poll_num);
  655. if (ret)
  656. mwifiex_dbg(adapter, ERROR,
  657. "FW failed to be active in time\n");
  658. return ret;
  659. }