init.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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->port_open = false;
  70. priv->usb_port = MWIFIEX_USB_EP_DATA;
  71. priv->pkt_tx_ctrl = 0;
  72. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  73. priv->data_rate = 0; /* Initially indicate the rate as auto */
  74. priv->is_data_rate_auto = true;
  75. priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
  76. priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
  77. priv->sec_info.wep_enabled = 0;
  78. priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
  79. priv->sec_info.encryption_mode = 0;
  80. for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++)
  81. memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key));
  82. priv->wep_key_curr_index = 0;
  83. priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
  84. HostCmd_ACT_MAC_ETHERNETII_ENABLE;
  85. priv->beacon_period = 100; /* beacon interval */ ;
  86. priv->attempted_bss_desc = NULL;
  87. memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params));
  88. priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL;
  89. memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid));
  90. memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid));
  91. memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
  92. priv->assoc_rsp_size = 0;
  93. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  94. priv->atim_window = 0;
  95. priv->adhoc_state = ADHOC_IDLE;
  96. priv->tx_power_level = 0;
  97. priv->max_tx_power_level = 0;
  98. priv->min_tx_power_level = 0;
  99. priv->tx_rate = 0;
  100. priv->rxpd_htinfo = 0;
  101. priv->rxpd_rate = 0;
  102. priv->rate_bitmap = 0;
  103. priv->data_rssi_last = 0;
  104. priv->data_rssi_avg = 0;
  105. priv->data_nf_avg = 0;
  106. priv->data_nf_last = 0;
  107. priv->bcn_rssi_last = 0;
  108. priv->bcn_rssi_avg = 0;
  109. priv->bcn_nf_avg = 0;
  110. priv->bcn_nf_last = 0;
  111. memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  112. memset(&priv->aes_key, 0, sizeof(priv->aes_key));
  113. priv->wpa_ie_len = 0;
  114. priv->wpa_is_gtk_set = false;
  115. memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
  116. priv->assoc_tlv_buf_len = 0;
  117. memset(&priv->wps, 0, sizeof(priv->wps));
  118. memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
  119. priv->gen_ie_buf_len = 0;
  120. memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
  121. priv->wmm_required = true;
  122. priv->wmm_enabled = false;
  123. priv->wmm_qosinfo = 0;
  124. priv->curr_bcn_buf = NULL;
  125. priv->curr_bcn_size = 0;
  126. priv->wps_ie = NULL;
  127. priv->wps_ie_len = 0;
  128. priv->ap_11n_enabled = 0;
  129. memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg));
  130. priv->scan_block = false;
  131. priv->csa_chan = 0;
  132. priv->csa_expire_time = 0;
  133. priv->del_list_idx = 0;
  134. priv->hs2_enabled = false;
  135. priv->check_tdls_tx = false;
  136. memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID);
  137. mwifiex_init_11h_params(priv);
  138. return mwifiex_add_bss_prio_tbl(priv);
  139. }
  140. /*
  141. * This function allocates buffers for members of the adapter
  142. * structure.
  143. *
  144. * The memory allocated includes scan table, command buffers, and
  145. * sleep confirm command buffer. In addition, the queues are
  146. * also initialized.
  147. */
  148. static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
  149. {
  150. int ret;
  151. /* Allocate command buffer */
  152. ret = mwifiex_alloc_cmd_buffer(adapter);
  153. if (ret) {
  154. mwifiex_dbg(adapter, ERROR,
  155. "%s: failed to alloc cmd buffer\n",
  156. __func__);
  157. return -1;
  158. }
  159. adapter->sleep_cfm =
  160. dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
  161. + INTF_HEADER_LEN);
  162. if (!adapter->sleep_cfm) {
  163. mwifiex_dbg(adapter, ERROR,
  164. "%s: failed to alloc sleep cfm\t"
  165. " cmd buffer\n", __func__);
  166. return -1;
  167. }
  168. skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
  169. return 0;
  170. }
  171. /*
  172. * This function initializes the adapter structure and sets default
  173. * values to the members of adapter.
  174. *
  175. * This also initializes the WMM related parameters in the driver private
  176. * structures.
  177. */
  178. static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
  179. {
  180. struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
  181. skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
  182. adapter->cmd_sent = false;
  183. if (adapter->iface_type == MWIFIEX_SDIO)
  184. adapter->data_sent = true;
  185. else
  186. adapter->data_sent = false;
  187. adapter->cmd_resp_received = false;
  188. adapter->event_received = false;
  189. adapter->data_received = false;
  190. adapter->surprise_removed = false;
  191. adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
  192. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  193. adapter->ps_state = PS_STATE_AWAKE;
  194. adapter->need_to_wakeup = false;
  195. adapter->scan_mode = HostCmd_BSS_MODE_ANY;
  196. adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
  197. adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
  198. adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
  199. adapter->scan_chan_gap_time = MWIFIEX_DEF_SCAN_CHAN_GAP_TIME;
  200. adapter->scan_probes = 1;
  201. adapter->multiple_dtim = 1;
  202. adapter->local_listen_interval = 0; /* default value in firmware
  203. will be used */
  204. adapter->is_deep_sleep = false;
  205. adapter->delay_null_pkt = false;
  206. adapter->delay_to_ps = 1000;
  207. adapter->enhanced_ps_mode = PS_MODE_AUTO;
  208. adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
  209. default */
  210. adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
  211. default */
  212. adapter->pm_wakeup_card_req = false;
  213. adapter->pm_wakeup_fw_try = false;
  214. adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  215. adapter->is_hs_configured = false;
  216. adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF);
  217. adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF;
  218. adapter->hs_cfg.gap = HS_CFG_GAP_DEF;
  219. adapter->hs_activated = false;
  220. memset(adapter->event_body, 0, sizeof(adapter->event_body));
  221. adapter->hw_dot_11n_dev_cap = 0;
  222. adapter->hw_dev_mcs_support = 0;
  223. adapter->sec_chan_offset = 0;
  224. adapter->adhoc_11n_enabled = false;
  225. mwifiex_wmm_init(adapter);
  226. sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
  227. adapter->sleep_cfm->data;
  228. memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
  229. sleep_cfm_buf->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
  230. sleep_cfm_buf->size = cpu_to_le16(adapter->sleep_cfm->len);
  231. sleep_cfm_buf->result = 0;
  232. sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
  233. sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
  234. memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
  235. memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
  236. adapter->tx_lock_flag = false;
  237. adapter->null_pkt_interval = 0;
  238. adapter->fw_bands = 0;
  239. adapter->config_bands = 0;
  240. adapter->adhoc_start_band = 0;
  241. adapter->scan_channels = NULL;
  242. adapter->fw_release_number = 0;
  243. adapter->fw_cap_info = 0;
  244. memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
  245. adapter->event_cause = 0;
  246. adapter->region_code = 0;
  247. adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
  248. adapter->adhoc_awake_period = 0;
  249. memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  250. adapter->arp_filter_size = 0;
  251. adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
  252. adapter->key_api_major_ver = 0;
  253. adapter->key_api_minor_ver = 0;
  254. eth_broadcast_addr(adapter->perm_addr);
  255. adapter->iface_limit.sta_intf = MWIFIEX_MAX_STA_NUM;
  256. adapter->iface_limit.uap_intf = MWIFIEX_MAX_UAP_NUM;
  257. adapter->iface_limit.p2p_intf = MWIFIEX_MAX_P2P_NUM;
  258. adapter->active_scan_triggered = false;
  259. setup_timer(&adapter->wakeup_timer, wakeup_timer_fn,
  260. (unsigned long)adapter);
  261. }
  262. /*
  263. * This function sets trans_start per tx_queue
  264. */
  265. void mwifiex_set_trans_start(struct net_device *dev)
  266. {
  267. int i;
  268. for (i = 0; i < dev->num_tx_queues; i++)
  269. netdev_get_tx_queue(dev, i)->trans_start = jiffies;
  270. dev->trans_start = jiffies;
  271. }
  272. /*
  273. * This function wakes up all queues in net_device
  274. */
  275. void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
  276. struct mwifiex_adapter *adapter)
  277. {
  278. unsigned long dev_queue_flags;
  279. unsigned int i;
  280. spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
  281. for (i = 0; i < netdev->num_tx_queues; i++) {
  282. struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
  283. if (netif_tx_queue_stopped(txq))
  284. netif_tx_wake_queue(txq);
  285. }
  286. spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
  287. }
  288. /*
  289. * This function stops all queues in net_device
  290. */
  291. void mwifiex_stop_net_dev_queue(struct net_device *netdev,
  292. struct mwifiex_adapter *adapter)
  293. {
  294. unsigned long dev_queue_flags;
  295. unsigned int i;
  296. spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
  297. for (i = 0; i < netdev->num_tx_queues; i++) {
  298. struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
  299. if (!netif_tx_queue_stopped(txq))
  300. netif_tx_stop_queue(txq);
  301. }
  302. spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
  303. }
  304. /*
  305. * This function releases the lock variables and frees the locks and
  306. * associated locks.
  307. */
  308. static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
  309. {
  310. struct mwifiex_private *priv;
  311. s32 i, j;
  312. /* Free lists */
  313. list_del(&adapter->cmd_free_q);
  314. list_del(&adapter->cmd_pending_q);
  315. list_del(&adapter->scan_pending_q);
  316. for (i = 0; i < adapter->priv_num; i++)
  317. list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
  318. for (i = 0; i < adapter->priv_num; i++) {
  319. if (adapter->priv[i]) {
  320. priv = adapter->priv[i];
  321. for (j = 0; j < MAX_NUM_TID; ++j)
  322. list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
  323. list_del(&priv->tx_ba_stream_tbl_ptr);
  324. list_del(&priv->rx_reorder_tbl_ptr);
  325. list_del(&priv->sta_list);
  326. list_del(&priv->auto_tdls_list);
  327. }
  328. }
  329. }
  330. /*
  331. * This function performs cleanup for adapter structure.
  332. *
  333. * The cleanup is done recursively, by canceling all pending
  334. * commands, freeing the member buffers previously allocated
  335. * (command buffers, scan table buffer, sleep confirm command
  336. * buffer), stopping the timers and calling the cleanup routines
  337. * for every interface.
  338. */
  339. static void
  340. mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter)
  341. {
  342. int idx;
  343. if (!adapter) {
  344. pr_err("%s: adapter is NULL\n", __func__);
  345. return;
  346. }
  347. del_timer(&adapter->wakeup_timer);
  348. mwifiex_cancel_all_pending_cmd(adapter);
  349. wake_up_interruptible(&adapter->cmd_wait_q.wait);
  350. wake_up_interruptible(&adapter->hs_activate_wait_q);
  351. /* Free lock variables */
  352. mwifiex_free_lock_list(adapter);
  353. /* Free command buffer */
  354. mwifiex_dbg(adapter, INFO, "info: free cmd buffer\n");
  355. mwifiex_free_cmd_buffer(adapter);
  356. for (idx = 0; idx < adapter->num_mem_types; idx++) {
  357. struct memory_type_mapping *entry =
  358. &adapter->mem_type_mapping_tbl[idx];
  359. if (entry->mem_ptr) {
  360. vfree(entry->mem_ptr);
  361. entry->mem_ptr = NULL;
  362. }
  363. entry->mem_size = 0;
  364. }
  365. if (adapter->drv_info_dump) {
  366. vfree(adapter->drv_info_dump);
  367. adapter->drv_info_dump = NULL;
  368. adapter->drv_info_size = 0;
  369. }
  370. if (adapter->sleep_cfm)
  371. dev_kfree_skb_any(adapter->sleep_cfm);
  372. }
  373. /*
  374. * This function intializes the lock variables and
  375. * the list heads.
  376. */
  377. int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
  378. {
  379. struct mwifiex_private *priv;
  380. s32 i, j;
  381. spin_lock_init(&adapter->mwifiex_lock);
  382. spin_lock_init(&adapter->int_lock);
  383. spin_lock_init(&adapter->main_proc_lock);
  384. spin_lock_init(&adapter->mwifiex_cmd_lock);
  385. spin_lock_init(&adapter->queue_lock);
  386. for (i = 0; i < adapter->priv_num; i++) {
  387. if (adapter->priv[i]) {
  388. priv = adapter->priv[i];
  389. spin_lock_init(&priv->rx_pkt_lock);
  390. spin_lock_init(&priv->wmm.ra_list_spinlock);
  391. spin_lock_init(&priv->curr_bcn_buf_lock);
  392. spin_lock_init(&priv->sta_list_spinlock);
  393. spin_lock_init(&priv->auto_tdls_lock);
  394. }
  395. }
  396. /* Initialize cmd_free_q */
  397. INIT_LIST_HEAD(&adapter->cmd_free_q);
  398. /* Initialize cmd_pending_q */
  399. INIT_LIST_HEAD(&adapter->cmd_pending_q);
  400. /* Initialize scan_pending_q */
  401. INIT_LIST_HEAD(&adapter->scan_pending_q);
  402. spin_lock_init(&adapter->cmd_free_q_lock);
  403. spin_lock_init(&adapter->cmd_pending_q_lock);
  404. spin_lock_init(&adapter->scan_pending_q_lock);
  405. spin_lock_init(&adapter->rx_proc_lock);
  406. skb_queue_head_init(&adapter->rx_data_q);
  407. skb_queue_head_init(&adapter->tx_data_q);
  408. for (i = 0; i < adapter->priv_num; ++i) {
  409. INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
  410. spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
  411. }
  412. for (i = 0; i < adapter->priv_num; i++) {
  413. if (!adapter->priv[i])
  414. continue;
  415. priv = adapter->priv[i];
  416. for (j = 0; j < MAX_NUM_TID; ++j)
  417. INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
  418. INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
  419. INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
  420. INIT_LIST_HEAD(&priv->sta_list);
  421. INIT_LIST_HEAD(&priv->auto_tdls_list);
  422. skb_queue_head_init(&priv->tdls_txq);
  423. skb_queue_head_init(&priv->bypass_txq);
  424. spin_lock_init(&priv->tx_ba_stream_tbl_lock);
  425. spin_lock_init(&priv->rx_reorder_tbl_lock);
  426. spin_lock_init(&priv->ack_status_lock);
  427. idr_init(&priv->ack_status_frames);
  428. }
  429. return 0;
  430. }
  431. /*
  432. * This function initializes the firmware.
  433. *
  434. * The following operations are performed sequentially -
  435. * - Allocate adapter structure
  436. * - Initialize the adapter structure
  437. * - Initialize the private structure
  438. * - Add BSS priority tables to the adapter structure
  439. * - For each interface, send the init commands to firmware
  440. * - Send the first command in command pending queue, if available
  441. */
  442. int mwifiex_init_fw(struct mwifiex_adapter *adapter)
  443. {
  444. int ret;
  445. struct mwifiex_private *priv;
  446. u8 i, first_sta = true;
  447. int is_cmd_pend_q_empty;
  448. unsigned long flags;
  449. adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
  450. /* Allocate memory for member of adapter structure */
  451. ret = mwifiex_allocate_adapter(adapter);
  452. if (ret)
  453. return -1;
  454. /* Initialize adapter structure */
  455. mwifiex_init_adapter(adapter);
  456. for (i = 0; i < adapter->priv_num; i++) {
  457. if (adapter->priv[i]) {
  458. priv = adapter->priv[i];
  459. /* Initialize private structure */
  460. ret = mwifiex_init_priv(priv);
  461. if (ret)
  462. return -1;
  463. }
  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. }