init.c 22 KB

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