init.c 21 KB

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