main.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * Intel Wireless Multicomm 3200 WiFi driver
  3. *
  4. * Copyright (C) 2009 Intel Corporation. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Intel Corporation nor the names of its
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. *
  33. * Intel Corporation <ilw@linux.intel.com>
  34. * Samuel Ortiz <samuel.ortiz@intel.com>
  35. * Zhu Yi <yi.zhu@intel.com>
  36. *
  37. */
  38. #include <linux/kernel.h>
  39. #include <linux/netdevice.h>
  40. #include <linux/ieee80211.h>
  41. #include <linux/wireless.h>
  42. #include "iwm.h"
  43. #include "debug.h"
  44. #include "bus.h"
  45. #include "umac.h"
  46. #include "commands.h"
  47. #include "hal.h"
  48. #include "fw.h"
  49. #include "rx.h"
  50. static struct iwm_conf def_iwm_conf = {
  51. .sdio_ior_timeout = 5000,
  52. .calib_map = BIT(CALIB_CFG_DC_IDX) |
  53. BIT(CALIB_CFG_LO_IDX) |
  54. BIT(CALIB_CFG_TX_IQ_IDX) |
  55. BIT(CALIB_CFG_RX_IQ_IDX) |
  56. BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
  57. .expected_calib_map = BIT(PHY_CALIBRATE_DC_CMD) |
  58. BIT(PHY_CALIBRATE_LO_CMD) |
  59. BIT(PHY_CALIBRATE_TX_IQ_CMD) |
  60. BIT(PHY_CALIBRATE_RX_IQ_CMD) |
  61. BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
  62. .ct_kill_entry = 110,
  63. .ct_kill_exit = 110,
  64. .reset_on_fatal_err = 1,
  65. .auto_connect = 1,
  66. .wimax_not_present = 0,
  67. .enable_qos = 1,
  68. .mode = UMAC_MODE_BSS,
  69. /* UMAC configuration */
  70. .power_index = 0,
  71. .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
  72. .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
  73. .cts_to_self = 0,
  74. .assoc_timeout = 2,
  75. .roam_timeout = 10,
  76. .wireless_mode = WIRELESS_MODE_11A | WIRELESS_MODE_11G,
  77. .coexist_mode = COEX_MODE_CM,
  78. /* IBSS */
  79. .ibss_band = UMAC_BAND_2GHZ,
  80. .ibss_channel = 1,
  81. .mac_addr = {0x00, 0x02, 0xb3, 0x01, 0x02, 0x03},
  82. };
  83. static int modparam_reset;
  84. module_param_named(reset, modparam_reset, bool, 0644);
  85. MODULE_PARM_DESC(reset, "reset on firmware errors (default 0 [not reset])");
  86. int iwm_mode_to_nl80211_iftype(int mode)
  87. {
  88. switch (mode) {
  89. case UMAC_MODE_BSS:
  90. return NL80211_IFTYPE_STATION;
  91. case UMAC_MODE_IBSS:
  92. return NL80211_IFTYPE_ADHOC;
  93. default:
  94. return NL80211_IFTYPE_UNSPECIFIED;
  95. }
  96. return 0;
  97. }
  98. static void iwm_statistics_request(struct work_struct *work)
  99. {
  100. struct iwm_priv *iwm =
  101. container_of(work, struct iwm_priv, stats_request.work);
  102. iwm_send_umac_stats_req(iwm, 0);
  103. }
  104. static void iwm_disconnect_work(struct work_struct *work)
  105. {
  106. struct iwm_priv *iwm =
  107. container_of(work, struct iwm_priv, disconnect.work);
  108. if (iwm->umac_profile_active)
  109. iwm_invalidate_mlme_profile(iwm);
  110. clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
  111. iwm->umac_profile_active = 0;
  112. memset(iwm->bssid, 0, ETH_ALEN);
  113. iwm->channel = 0;
  114. iwm_link_off(iwm);
  115. wake_up_interruptible(&iwm->mlme_queue);
  116. cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0, GFP_KERNEL);
  117. }
  118. static void iwm_ct_kill_work(struct work_struct *work)
  119. {
  120. struct iwm_priv *iwm =
  121. container_of(work, struct iwm_priv, ct_kill_delay.work);
  122. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  123. IWM_INFO(iwm, "CT kill delay timeout\n");
  124. wiphy_rfkill_set_hw_state(wiphy, false);
  125. }
  126. static int __iwm_up(struct iwm_priv *iwm);
  127. static int __iwm_down(struct iwm_priv *iwm);
  128. static void iwm_reset_worker(struct work_struct *work)
  129. {
  130. struct iwm_priv *iwm;
  131. struct iwm_umac_profile *profile = NULL;
  132. int uninitialized_var(ret), retry = 0;
  133. iwm = container_of(work, struct iwm_priv, reset_worker);
  134. /*
  135. * XXX: The iwm->mutex is introduced purely for this reset work,
  136. * because the other users for iwm_up and iwm_down are only netdev
  137. * ndo_open and ndo_stop which are already protected by rtnl.
  138. * Please remove iwm->mutex together if iwm_reset_worker() is not
  139. * required in the future.
  140. */
  141. if (!mutex_trylock(&iwm->mutex)) {
  142. IWM_WARN(iwm, "We are in the middle of interface bringing "
  143. "UP/DOWN. Skip driver resetting.\n");
  144. return;
  145. }
  146. if (iwm->umac_profile_active) {
  147. profile = kmalloc(sizeof(struct iwm_umac_profile), GFP_KERNEL);
  148. if (profile)
  149. memcpy(profile, iwm->umac_profile, sizeof(*profile));
  150. else
  151. IWM_ERR(iwm, "Couldn't alloc memory for profile\n");
  152. }
  153. __iwm_down(iwm);
  154. while (retry++ < 3) {
  155. ret = __iwm_up(iwm);
  156. if (!ret)
  157. break;
  158. schedule_timeout_uninterruptible(10 * HZ);
  159. }
  160. if (ret) {
  161. IWM_WARN(iwm, "iwm_up() failed: %d\n", ret);
  162. kfree(profile);
  163. goto out;
  164. }
  165. if (profile) {
  166. IWM_DBG_MLME(iwm, DBG, "Resend UMAC profile\n");
  167. memcpy(iwm->umac_profile, profile, sizeof(*profile));
  168. iwm_send_mlme_profile(iwm);
  169. kfree(profile);
  170. } else
  171. clear_bit(IWM_STATUS_RESETTING, &iwm->status);
  172. out:
  173. mutex_unlock(&iwm->mutex);
  174. }
  175. static void iwm_auth_retry_worker(struct work_struct *work)
  176. {
  177. struct iwm_priv *iwm;
  178. int i, ret;
  179. iwm = container_of(work, struct iwm_priv, auth_retry_worker);
  180. if (iwm->umac_profile_active) {
  181. ret = iwm_invalidate_mlme_profile(iwm);
  182. if (ret < 0)
  183. return;
  184. }
  185. iwm->umac_profile->sec.auth_type = UMAC_AUTH_TYPE_LEGACY_PSK;
  186. ret = iwm_send_mlme_profile(iwm);
  187. if (ret < 0)
  188. return;
  189. for (i = 0; i < IWM_NUM_KEYS; i++)
  190. if (iwm->keys[i].key_len)
  191. iwm_set_key(iwm, 0, &iwm->keys[i]);
  192. iwm_set_tx_key(iwm, iwm->default_key);
  193. }
  194. static void iwm_watchdog(unsigned long data)
  195. {
  196. struct iwm_priv *iwm = (struct iwm_priv *)data;
  197. IWM_WARN(iwm, "Watchdog expired: UMAC stalls!\n");
  198. if (modparam_reset)
  199. iwm_resetting(iwm);
  200. }
  201. int iwm_priv_init(struct iwm_priv *iwm)
  202. {
  203. int i;
  204. char name[32];
  205. iwm->status = 0;
  206. INIT_LIST_HEAD(&iwm->pending_notif);
  207. init_waitqueue_head(&iwm->notif_queue);
  208. init_waitqueue_head(&iwm->nonwifi_queue);
  209. init_waitqueue_head(&iwm->wifi_ntfy_queue);
  210. init_waitqueue_head(&iwm->mlme_queue);
  211. memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf));
  212. spin_lock_init(&iwm->tx_credit.lock);
  213. INIT_LIST_HEAD(&iwm->wifi_pending_cmd);
  214. INIT_LIST_HEAD(&iwm->nonwifi_pending_cmd);
  215. iwm->wifi_seq_num = UMAC_WIFI_SEQ_NUM_BASE;
  216. iwm->nonwifi_seq_num = UMAC_NONWIFI_SEQ_NUM_BASE;
  217. spin_lock_init(&iwm->cmd_lock);
  218. iwm->scan_id = 1;
  219. INIT_DELAYED_WORK(&iwm->stats_request, iwm_statistics_request);
  220. INIT_DELAYED_WORK(&iwm->disconnect, iwm_disconnect_work);
  221. INIT_DELAYED_WORK(&iwm->ct_kill_delay, iwm_ct_kill_work);
  222. INIT_WORK(&iwm->reset_worker, iwm_reset_worker);
  223. INIT_WORK(&iwm->auth_retry_worker, iwm_auth_retry_worker);
  224. INIT_LIST_HEAD(&iwm->bss_list);
  225. skb_queue_head_init(&iwm->rx_list);
  226. INIT_LIST_HEAD(&iwm->rx_tickets);
  227. for (i = 0; i < IWM_RX_ID_HASH; i++)
  228. INIT_LIST_HEAD(&iwm->rx_packets[i]);
  229. INIT_WORK(&iwm->rx_worker, iwm_rx_worker);
  230. iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx");
  231. if (!iwm->rx_wq)
  232. return -EAGAIN;
  233. for (i = 0; i < IWM_TX_QUEUES; i++) {
  234. INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker);
  235. snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i);
  236. iwm->txq[i].id = i;
  237. iwm->txq[i].wq = create_singlethread_workqueue(name);
  238. if (!iwm->txq[i].wq)
  239. return -EAGAIN;
  240. skb_queue_head_init(&iwm->txq[i].queue);
  241. }
  242. for (i = 0; i < IWM_NUM_KEYS; i++)
  243. memset(&iwm->keys[i], 0, sizeof(struct iwm_key));
  244. iwm->default_key = -1;
  245. init_timer(&iwm->watchdog);
  246. iwm->watchdog.function = iwm_watchdog;
  247. iwm->watchdog.data = (unsigned long)iwm;
  248. mutex_init(&iwm->mutex);
  249. iwm->last_fw_err = kzalloc(sizeof(struct iwm_fw_error_hdr),
  250. GFP_KERNEL);
  251. if (iwm->last_fw_err == NULL)
  252. return -ENOMEM;
  253. return 0;
  254. }
  255. void iwm_priv_deinit(struct iwm_priv *iwm)
  256. {
  257. int i;
  258. for (i = 0; i < IWM_TX_QUEUES; i++)
  259. destroy_workqueue(iwm->txq[i].wq);
  260. destroy_workqueue(iwm->rx_wq);
  261. kfree(iwm->last_fw_err);
  262. }
  263. /*
  264. * We reset all the structures, and we reset the UMAC.
  265. * After calling this routine, you're expected to reload
  266. * the firmware.
  267. */
  268. void iwm_reset(struct iwm_priv *iwm)
  269. {
  270. struct iwm_notif *notif, *next;
  271. if (test_bit(IWM_STATUS_READY, &iwm->status))
  272. iwm_target_reset(iwm);
  273. if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) {
  274. iwm->status = 0;
  275. set_bit(IWM_STATUS_RESETTING, &iwm->status);
  276. } else
  277. iwm->status = 0;
  278. iwm->scan_id = 1;
  279. list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
  280. list_del(&notif->pending);
  281. kfree(notif->buf);
  282. kfree(notif);
  283. }
  284. iwm_cmd_flush(iwm);
  285. flush_workqueue(iwm->rx_wq);
  286. iwm_link_off(iwm);
  287. }
  288. void iwm_resetting(struct iwm_priv *iwm)
  289. {
  290. set_bit(IWM_STATUS_RESETTING, &iwm->status);
  291. schedule_work(&iwm->reset_worker);
  292. }
  293. /*
  294. * Notification code:
  295. *
  296. * We're faced with the following issue: Any host command can
  297. * have an answer or not, and if there's an answer to expect,
  298. * it can be treated synchronously or asynchronously.
  299. * To work around the synchronous answer case, we implemented
  300. * our notification mechanism.
  301. * When a code path needs to wait for a command response
  302. * synchronously, it calls notif_handle(), which waits for the
  303. * right notification to show up, and then process it. Before
  304. * starting to wait, it registered as a waiter for this specific
  305. * answer (by toggling a bit in on of the handler_map), so that
  306. * the rx code knows that it needs to send a notification to the
  307. * waiting processes. It does so by calling iwm_notif_send(),
  308. * which adds the notification to the pending notifications list,
  309. * and then wakes the waiting processes up.
  310. */
  311. int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
  312. u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size)
  313. {
  314. struct iwm_notif *notif;
  315. notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL);
  316. if (!notif) {
  317. IWM_ERR(iwm, "Couldn't alloc memory for notification\n");
  318. return -ENOMEM;
  319. }
  320. INIT_LIST_HEAD(&notif->pending);
  321. notif->cmd = cmd;
  322. notif->cmd_id = cmd_id;
  323. notif->src = source;
  324. notif->buf = kzalloc(buf_size, GFP_KERNEL);
  325. if (!notif->buf) {
  326. IWM_ERR(iwm, "Couldn't alloc notification buffer\n");
  327. kfree(notif);
  328. return -ENOMEM;
  329. }
  330. notif->buf_size = buf_size;
  331. memcpy(notif->buf, buf, buf_size);
  332. list_add_tail(&notif->pending, &iwm->pending_notif);
  333. wake_up_interruptible(&iwm->notif_queue);
  334. return 0;
  335. }
  336. static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd,
  337. u8 source)
  338. {
  339. struct iwm_notif *notif, *next;
  340. list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
  341. if ((notif->cmd_id == cmd) && (notif->src == source)) {
  342. list_del(&notif->pending);
  343. return notif;
  344. }
  345. }
  346. return NULL;
  347. }
  348. static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd,
  349. u8 source, long timeout)
  350. {
  351. int ret;
  352. struct iwm_notif *notif;
  353. unsigned long *map = NULL;
  354. switch (source) {
  355. case IWM_SRC_LMAC:
  356. map = &iwm->lmac_handler_map[0];
  357. break;
  358. case IWM_SRC_UMAC:
  359. map = &iwm->umac_handler_map[0];
  360. break;
  361. case IWM_SRC_UDMA:
  362. map = &iwm->udma_handler_map[0];
  363. break;
  364. }
  365. set_bit(cmd, map);
  366. ret = wait_event_interruptible_timeout(iwm->notif_queue,
  367. ((notif = iwm_notif_find(iwm, cmd, source)) != NULL),
  368. timeout);
  369. clear_bit(cmd, map);
  370. if (!ret)
  371. return NULL;
  372. return notif;
  373. }
  374. int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout)
  375. {
  376. int ret;
  377. struct iwm_notif *notif;
  378. notif = iwm_notif_wait(iwm, cmd, source, timeout);
  379. if (!notif)
  380. return -ETIME;
  381. ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd);
  382. kfree(notif->buf);
  383. kfree(notif);
  384. return ret;
  385. }
  386. static int iwm_config_boot_params(struct iwm_priv *iwm)
  387. {
  388. struct iwm_udma_nonwifi_cmd target_cmd;
  389. int ret;
  390. /* check Wimax is off and config debug monitor */
  391. if (iwm->conf.wimax_not_present) {
  392. u32 data1 = 0x1f;
  393. u32 addr1 = 0x606BE258;
  394. u32 data2_set = 0x0;
  395. u32 data2_clr = 0x1;
  396. u32 addr2 = 0x606BE100;
  397. u32 data3 = 0x1;
  398. u32 addr3 = 0x606BEC00;
  399. target_cmd.resp = 0;
  400. target_cmd.handle_by_hw = 0;
  401. target_cmd.eop = 1;
  402. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
  403. target_cmd.addr = cpu_to_le32(addr1);
  404. target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
  405. target_cmd.op2 = 0;
  406. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
  407. if (ret < 0) {
  408. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  409. return ret;
  410. }
  411. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE;
  412. target_cmd.addr = cpu_to_le32(addr2);
  413. target_cmd.op1_sz = cpu_to_le32(data2_set);
  414. target_cmd.op2 = cpu_to_le32(data2_clr);
  415. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
  416. if (ret < 0) {
  417. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  418. return ret;
  419. }
  420. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
  421. target_cmd.addr = cpu_to_le32(addr3);
  422. target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
  423. target_cmd.op2 = 0;
  424. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3);
  425. if (ret < 0) {
  426. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  427. return ret;
  428. }
  429. }
  430. return 0;
  431. }
  432. void iwm_init_default_profile(struct iwm_priv *iwm,
  433. struct iwm_umac_profile *profile)
  434. {
  435. memset(profile, 0, sizeof(struct iwm_umac_profile));
  436. profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
  437. profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
  438. profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE;
  439. profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE;
  440. if (iwm->conf.enable_qos)
  441. profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED);
  442. profile->wireless_mode = iwm->conf.wireless_mode;
  443. profile->mode = cpu_to_le32(iwm->conf.mode);
  444. profile->ibss.atim = 0;
  445. profile->ibss.beacon_interval = 100;
  446. profile->ibss.join_only = 0;
  447. profile->ibss.band = iwm->conf.ibss_band;
  448. profile->ibss.channel = iwm->conf.ibss_channel;
  449. }
  450. void iwm_link_on(struct iwm_priv *iwm)
  451. {
  452. netif_carrier_on(iwm_to_ndev(iwm));
  453. netif_tx_wake_all_queues(iwm_to_ndev(iwm));
  454. iwm_send_umac_stats_req(iwm, 0);
  455. }
  456. void iwm_link_off(struct iwm_priv *iwm)
  457. {
  458. struct iw_statistics *wstats = &iwm->wstats;
  459. int i;
  460. netif_tx_stop_all_queues(iwm_to_ndev(iwm));
  461. netif_carrier_off(iwm_to_ndev(iwm));
  462. for (i = 0; i < IWM_TX_QUEUES; i++) {
  463. skb_queue_purge(&iwm->txq[i].queue);
  464. iwm->txq[i].concat_count = 0;
  465. iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf;
  466. flush_workqueue(iwm->txq[i].wq);
  467. }
  468. iwm_rx_free(iwm);
  469. cancel_delayed_work_sync(&iwm->stats_request);
  470. memset(wstats, 0, sizeof(struct iw_statistics));
  471. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  472. kfree(iwm->req_ie);
  473. iwm->req_ie = NULL;
  474. iwm->req_ie_len = 0;
  475. kfree(iwm->resp_ie);
  476. iwm->resp_ie = NULL;
  477. iwm->resp_ie_len = 0;
  478. del_timer_sync(&iwm->watchdog);
  479. }
  480. static void iwm_bss_list_clean(struct iwm_priv *iwm)
  481. {
  482. struct iwm_bss_info *bss, *next;
  483. list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
  484. list_del(&bss->node);
  485. kfree(bss->bss);
  486. kfree(bss);
  487. }
  488. }
  489. static int iwm_channels_init(struct iwm_priv *iwm)
  490. {
  491. int ret;
  492. ret = iwm_send_umac_channel_list(iwm);
  493. if (ret) {
  494. IWM_ERR(iwm, "Send channel list failed\n");
  495. return ret;
  496. }
  497. ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST,
  498. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  499. if (ret) {
  500. IWM_ERR(iwm, "Didn't get a channel list notification\n");
  501. return ret;
  502. }
  503. return 0;
  504. }
  505. static int __iwm_up(struct iwm_priv *iwm)
  506. {
  507. int ret;
  508. struct iwm_notif *notif_reboot, *notif_ack = NULL;
  509. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  510. ret = iwm_bus_enable(iwm);
  511. if (ret) {
  512. IWM_ERR(iwm, "Couldn't enable function\n");
  513. return ret;
  514. }
  515. iwm_rx_setup_handlers(iwm);
  516. /* Wait for initial BARKER_REBOOT from hardware */
  517. notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION,
  518. IWM_SRC_UDMA, 2 * HZ);
  519. if (!notif_reboot) {
  520. IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n");
  521. goto err_disable;
  522. }
  523. /* We send the barker back */
  524. ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16);
  525. if (ret) {
  526. IWM_ERR(iwm, "REBOOT barker response failed\n");
  527. kfree(notif_reboot);
  528. goto err_disable;
  529. }
  530. kfree(notif_reboot->buf);
  531. kfree(notif_reboot);
  532. /* Wait for ACK_BARKER from hardware */
  533. notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION,
  534. IWM_SRC_UDMA, 2 * HZ);
  535. if (!notif_ack) {
  536. IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n");
  537. goto err_disable;
  538. }
  539. kfree(notif_ack->buf);
  540. kfree(notif_ack);
  541. /* We start to config static boot parameters */
  542. ret = iwm_config_boot_params(iwm);
  543. if (ret) {
  544. IWM_ERR(iwm, "Config boot parameters failed\n");
  545. goto err_disable;
  546. }
  547. ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr);
  548. if (ret) {
  549. IWM_ERR(iwm, "MAC reading failed\n");
  550. goto err_disable;
  551. }
  552. memcpy(iwm_to_ndev(iwm)->perm_addr, iwm_to_ndev(iwm)->dev_addr,
  553. ETH_ALEN);
  554. /* We can load the FWs */
  555. ret = iwm_load_fw(iwm);
  556. if (ret) {
  557. IWM_ERR(iwm, "FW loading failed\n");
  558. goto err_disable;
  559. }
  560. snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "L%s_U%s",
  561. iwm->lmac_version, iwm->umac_version);
  562. /* We configure the UMAC and enable the wifi module */
  563. ret = iwm_send_umac_config(iwm,
  564. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) |
  565. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) |
  566. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN));
  567. if (ret) {
  568. IWM_ERR(iwm, "UMAC config failed\n");
  569. goto err_fw;
  570. }
  571. ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
  572. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  573. if (ret) {
  574. IWM_ERR(iwm, "Didn't get a wifi core status notification\n");
  575. goto err_fw;
  576. }
  577. if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
  578. UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
  579. IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n",
  580. iwm->core_enabled);
  581. ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
  582. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  583. if (ret) {
  584. IWM_ERR(iwm, "Didn't get a core status notification\n");
  585. goto err_fw;
  586. }
  587. if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
  588. UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
  589. IWM_ERR(iwm, "Not all cores enabled: 0x%x\n",
  590. iwm->core_enabled);
  591. goto err_fw;
  592. } else {
  593. IWM_INFO(iwm, "All cores enabled\n");
  594. }
  595. }
  596. ret = iwm_channels_init(iwm);
  597. if (ret < 0) {
  598. IWM_ERR(iwm, "Couldn't init channels\n");
  599. goto err_fw;
  600. }
  601. /* Set the READY bit to indicate interface is brought up successfully */
  602. set_bit(IWM_STATUS_READY, &iwm->status);
  603. return 0;
  604. err_fw:
  605. iwm_eeprom_exit(iwm);
  606. err_disable:
  607. ret = iwm_bus_disable(iwm);
  608. if (ret < 0)
  609. IWM_ERR(iwm, "Couldn't disable function\n");
  610. return -EIO;
  611. }
  612. int iwm_up(struct iwm_priv *iwm)
  613. {
  614. int ret;
  615. mutex_lock(&iwm->mutex);
  616. ret = __iwm_up(iwm);
  617. mutex_unlock(&iwm->mutex);
  618. return ret;
  619. }
  620. static int __iwm_down(struct iwm_priv *iwm)
  621. {
  622. int ret;
  623. /* The interface is already down */
  624. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  625. return 0;
  626. if (iwm->scan_request) {
  627. cfg80211_scan_done(iwm->scan_request, true);
  628. iwm->scan_request = NULL;
  629. }
  630. clear_bit(IWM_STATUS_READY, &iwm->status);
  631. iwm_eeprom_exit(iwm);
  632. iwm_bss_list_clean(iwm);
  633. iwm_init_default_profile(iwm, iwm->umac_profile);
  634. iwm->umac_profile_active = false;
  635. iwm->default_key = -1;
  636. iwm->core_enabled = 0;
  637. ret = iwm_bus_disable(iwm);
  638. if (ret < 0) {
  639. IWM_ERR(iwm, "Couldn't disable function\n");
  640. return ret;
  641. }
  642. return 0;
  643. }
  644. int iwm_down(struct iwm_priv *iwm)
  645. {
  646. int ret;
  647. mutex_lock(&iwm->mutex);
  648. ret = __iwm_down(iwm);
  649. mutex_unlock(&iwm->mutex);
  650. return ret;
  651. }