init.c 21 KB

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