init.c 23 KB

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