main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. .init_calib_map = BIT(PHY_CALIBRATE_DC_CMD) |
  53. BIT(PHY_CALIBRATE_LO_CMD) |
  54. BIT(PHY_CALIBRATE_TX_IQ_CMD) |
  55. BIT(PHY_CALIBRATE_RX_IQ_CMD),
  56. .periodic_calib_map = BIT(PHY_CALIBRATE_DC_CMD) |
  57. BIT(PHY_CALIBRATE_LO_CMD) |
  58. BIT(PHY_CALIBRATE_TX_IQ_CMD) |
  59. BIT(PHY_CALIBRATE_RX_IQ_CMD) |
  60. BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
  61. .reset_on_fatal_err = 1,
  62. .auto_connect = 1,
  63. .wimax_not_present = 0,
  64. .enable_qos = 1,
  65. .mode = UMAC_MODE_BSS,
  66. /* UMAC configuration */
  67. .power_index = 0,
  68. .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
  69. .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
  70. .cts_to_self = 0,
  71. .assoc_timeout = 2,
  72. .roam_timeout = 10,
  73. .wireless_mode = WIRELESS_MODE_11A | WIRELESS_MODE_11G,
  74. .coexist_mode = COEX_MODE_CM,
  75. /* IBSS */
  76. .ibss_band = UMAC_BAND_2GHZ,
  77. .ibss_channel = 1,
  78. .mac_addr = {0x00, 0x02, 0xb3, 0x01, 0x02, 0x03},
  79. };
  80. static int modparam_reset;
  81. module_param_named(reset, modparam_reset, bool, 0644);
  82. MODULE_PARM_DESC(reset, "reset on firmware errors (default 0 [not reset])");
  83. int iwm_mode_to_nl80211_iftype(int mode)
  84. {
  85. switch (mode) {
  86. case UMAC_MODE_BSS:
  87. return NL80211_IFTYPE_STATION;
  88. case UMAC_MODE_IBSS:
  89. return NL80211_IFTYPE_ADHOC;
  90. default:
  91. return NL80211_IFTYPE_UNSPECIFIED;
  92. }
  93. return 0;
  94. }
  95. static void iwm_statistics_request(struct work_struct *work)
  96. {
  97. struct iwm_priv *iwm =
  98. container_of(work, struct iwm_priv, stats_request.work);
  99. iwm_send_umac_stats_req(iwm, 0);
  100. }
  101. static void iwm_reset_worker(struct work_struct *work)
  102. {
  103. struct iwm_priv *iwm;
  104. struct iwm_umac_profile *profile = NULL;
  105. int uninitialized_var(ret), retry = 0;
  106. iwm = container_of(work, struct iwm_priv, reset_worker);
  107. if (iwm->umac_profile_active) {
  108. profile = kmalloc(sizeof(struct iwm_umac_profile), GFP_KERNEL);
  109. if (profile)
  110. memcpy(profile, iwm->umac_profile, sizeof(*profile));
  111. else
  112. IWM_ERR(iwm, "Couldn't alloc memory for profile\n");
  113. }
  114. iwm_down(iwm);
  115. while (retry++ < 3) {
  116. ret = iwm_up(iwm);
  117. if (!ret)
  118. break;
  119. schedule_timeout_uninterruptible(10 * HZ);
  120. }
  121. if (ret) {
  122. IWM_WARN(iwm, "iwm_up() failed: %d\n", ret);
  123. kfree(profile);
  124. return;
  125. }
  126. if (profile) {
  127. IWM_DBG_MLME(iwm, DBG, "Resend UMAC profile\n");
  128. memcpy(iwm->umac_profile, profile, sizeof(*profile));
  129. iwm_send_mlme_profile(iwm);
  130. kfree(profile);
  131. }
  132. }
  133. static void iwm_watchdog(unsigned long data)
  134. {
  135. struct iwm_priv *iwm = (struct iwm_priv *)data;
  136. IWM_WARN(iwm, "Watchdog expired: UMAC stalls!\n");
  137. if (modparam_reset)
  138. schedule_work(&iwm->reset_worker);
  139. }
  140. int iwm_priv_init(struct iwm_priv *iwm)
  141. {
  142. int i;
  143. char name[32];
  144. iwm->status = 0;
  145. INIT_LIST_HEAD(&iwm->pending_notif);
  146. init_waitqueue_head(&iwm->notif_queue);
  147. init_waitqueue_head(&iwm->nonwifi_queue);
  148. init_waitqueue_head(&iwm->mlme_queue);
  149. memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf));
  150. spin_lock_init(&iwm->tx_credit.lock);
  151. INIT_LIST_HEAD(&iwm->wifi_pending_cmd);
  152. INIT_LIST_HEAD(&iwm->nonwifi_pending_cmd);
  153. iwm->wifi_seq_num = UMAC_WIFI_SEQ_NUM_BASE;
  154. iwm->nonwifi_seq_num = UMAC_NONWIFI_SEQ_NUM_BASE;
  155. spin_lock_init(&iwm->cmd_lock);
  156. iwm->scan_id = 1;
  157. INIT_DELAYED_WORK(&iwm->stats_request, iwm_statistics_request);
  158. INIT_WORK(&iwm->reset_worker, iwm_reset_worker);
  159. INIT_LIST_HEAD(&iwm->bss_list);
  160. skb_queue_head_init(&iwm->rx_list);
  161. INIT_LIST_HEAD(&iwm->rx_tickets);
  162. for (i = 0; i < IWM_RX_ID_HASH; i++)
  163. INIT_LIST_HEAD(&iwm->rx_packets[i]);
  164. INIT_WORK(&iwm->rx_worker, iwm_rx_worker);
  165. iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx");
  166. if (!iwm->rx_wq)
  167. return -EAGAIN;
  168. for (i = 0; i < IWM_TX_QUEUES; i++) {
  169. INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker);
  170. snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i);
  171. iwm->txq[i].id = i;
  172. iwm->txq[i].wq = create_singlethread_workqueue(name);
  173. if (!iwm->txq[i].wq)
  174. return -EAGAIN;
  175. skb_queue_head_init(&iwm->txq[i].queue);
  176. }
  177. for (i = 0; i < IWM_NUM_KEYS; i++)
  178. memset(&iwm->keys[i], 0, sizeof(struct iwm_key));
  179. iwm->default_key = NULL;
  180. init_timer(&iwm->watchdog);
  181. iwm->watchdog.function = iwm_watchdog;
  182. iwm->watchdog.data = (unsigned long)iwm;
  183. return 0;
  184. }
  185. /*
  186. * We reset all the structures, and we reset the UMAC.
  187. * After calling this routine, you're expected to reload
  188. * the firmware.
  189. */
  190. void iwm_reset(struct iwm_priv *iwm)
  191. {
  192. struct iwm_notif *notif, *next;
  193. if (test_bit(IWM_STATUS_READY, &iwm->status))
  194. iwm_target_reset(iwm);
  195. iwm->status = 0;
  196. iwm->scan_id = 1;
  197. list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
  198. list_del(&notif->pending);
  199. kfree(notif->buf);
  200. kfree(notif);
  201. }
  202. iwm_cmd_flush(iwm);
  203. flush_workqueue(iwm->rx_wq);
  204. iwm_link_off(iwm);
  205. }
  206. /*
  207. * Notification code:
  208. *
  209. * We're faced with the following issue: Any host command can
  210. * have an answer or not, and if there's an answer to expect,
  211. * it can be treated synchronously or asynchronously.
  212. * To work around the synchronous answer case, we implemented
  213. * our notification mechanism.
  214. * When a code path needs to wait for a command response
  215. * synchronously, it calls notif_handle(), which waits for the
  216. * right notification to show up, and then process it. Before
  217. * starting to wait, it registered as a waiter for this specific
  218. * answer (by toggling a bit in on of the handler_map), so that
  219. * the rx code knows that it needs to send a notification to the
  220. * waiting processes. It does so by calling iwm_notif_send(),
  221. * which adds the notification to the pending notifications list,
  222. * and then wakes the waiting processes up.
  223. */
  224. int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
  225. u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size)
  226. {
  227. struct iwm_notif *notif;
  228. notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL);
  229. if (!notif) {
  230. IWM_ERR(iwm, "Couldn't alloc memory for notification\n");
  231. return -ENOMEM;
  232. }
  233. INIT_LIST_HEAD(&notif->pending);
  234. notif->cmd = cmd;
  235. notif->cmd_id = cmd_id;
  236. notif->src = source;
  237. notif->buf = kzalloc(buf_size, GFP_KERNEL);
  238. if (!notif->buf) {
  239. IWM_ERR(iwm, "Couldn't alloc notification buffer\n");
  240. kfree(notif);
  241. return -ENOMEM;
  242. }
  243. notif->buf_size = buf_size;
  244. memcpy(notif->buf, buf, buf_size);
  245. list_add_tail(&notif->pending, &iwm->pending_notif);
  246. wake_up_interruptible(&iwm->notif_queue);
  247. return 0;
  248. }
  249. static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd,
  250. u8 source)
  251. {
  252. struct iwm_notif *notif, *next;
  253. list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
  254. if ((notif->cmd_id == cmd) && (notif->src == source)) {
  255. list_del(&notif->pending);
  256. return notif;
  257. }
  258. }
  259. return NULL;
  260. }
  261. static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd,
  262. u8 source, long timeout)
  263. {
  264. int ret;
  265. struct iwm_notif *notif;
  266. unsigned long *map = NULL;
  267. switch (source) {
  268. case IWM_SRC_LMAC:
  269. map = &iwm->lmac_handler_map[0];
  270. break;
  271. case IWM_SRC_UMAC:
  272. map = &iwm->umac_handler_map[0];
  273. break;
  274. case IWM_SRC_UDMA:
  275. map = &iwm->udma_handler_map[0];
  276. break;
  277. }
  278. set_bit(cmd, map);
  279. ret = wait_event_interruptible_timeout(iwm->notif_queue,
  280. ((notif = iwm_notif_find(iwm, cmd, source)) != NULL),
  281. timeout);
  282. clear_bit(cmd, map);
  283. if (!ret)
  284. return NULL;
  285. return notif;
  286. }
  287. int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout)
  288. {
  289. int ret;
  290. struct iwm_notif *notif;
  291. notif = iwm_notif_wait(iwm, cmd, source, timeout);
  292. if (!notif)
  293. return -ETIME;
  294. ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd);
  295. kfree(notif->buf);
  296. kfree(notif);
  297. return ret;
  298. }
  299. static int iwm_config_boot_params(struct iwm_priv *iwm)
  300. {
  301. struct iwm_udma_nonwifi_cmd target_cmd;
  302. int ret;
  303. /* check Wimax is off and config debug monitor */
  304. if (iwm->conf.wimax_not_present) {
  305. u32 data1 = 0x1f;
  306. u32 addr1 = 0x606BE258;
  307. u32 data2_set = 0x0;
  308. u32 data2_clr = 0x1;
  309. u32 addr2 = 0x606BE100;
  310. u32 data3 = 0x1;
  311. u32 addr3 = 0x606BEC00;
  312. target_cmd.resp = 0;
  313. target_cmd.handle_by_hw = 0;
  314. target_cmd.eop = 1;
  315. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
  316. target_cmd.addr = cpu_to_le32(addr1);
  317. target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
  318. target_cmd.op2 = 0;
  319. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
  320. if (ret < 0) {
  321. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  322. return ret;
  323. }
  324. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE;
  325. target_cmd.addr = cpu_to_le32(addr2);
  326. target_cmd.op1_sz = cpu_to_le32(data2_set);
  327. target_cmd.op2 = cpu_to_le32(data2_clr);
  328. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
  329. if (ret < 0) {
  330. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  331. return ret;
  332. }
  333. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
  334. target_cmd.addr = cpu_to_le32(addr3);
  335. target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
  336. target_cmd.op2 = 0;
  337. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3);
  338. if (ret < 0) {
  339. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  340. return ret;
  341. }
  342. }
  343. return 0;
  344. }
  345. void iwm_init_default_profile(struct iwm_priv *iwm,
  346. struct iwm_umac_profile *profile)
  347. {
  348. memset(profile, 0, sizeof(struct iwm_umac_profile));
  349. profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
  350. profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
  351. profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE;
  352. profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE;
  353. if (iwm->conf.enable_qos)
  354. profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED);
  355. profile->wireless_mode = iwm->conf.wireless_mode;
  356. profile->mode = cpu_to_le32(iwm->conf.mode);
  357. profile->ibss.atim = 0;
  358. profile->ibss.beacon_interval = 100;
  359. profile->ibss.join_only = 0;
  360. profile->ibss.band = iwm->conf.ibss_band;
  361. profile->ibss.channel = iwm->conf.ibss_channel;
  362. }
  363. void iwm_link_on(struct iwm_priv *iwm)
  364. {
  365. netif_carrier_on(iwm_to_ndev(iwm));
  366. netif_tx_wake_all_queues(iwm_to_ndev(iwm));
  367. iwm_send_umac_stats_req(iwm, 0);
  368. }
  369. void iwm_link_off(struct iwm_priv *iwm)
  370. {
  371. struct iw_statistics *wstats = &iwm->wstats;
  372. int i;
  373. netif_tx_stop_all_queues(iwm_to_ndev(iwm));
  374. netif_carrier_off(iwm_to_ndev(iwm));
  375. for (i = 0; i < IWM_TX_QUEUES; i++) {
  376. skb_queue_purge(&iwm->txq[i].queue);
  377. iwm->txq[i].concat_count = 0;
  378. iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf;
  379. flush_workqueue(iwm->txq[i].wq);
  380. }
  381. iwm_rx_free(iwm);
  382. cancel_delayed_work(&iwm->stats_request);
  383. memset(wstats, 0, sizeof(struct iw_statistics));
  384. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  385. del_timer_sync(&iwm->watchdog);
  386. }
  387. static void iwm_bss_list_clean(struct iwm_priv *iwm)
  388. {
  389. struct iwm_bss_info *bss, *next;
  390. list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
  391. list_del(&bss->node);
  392. kfree(bss->bss);
  393. kfree(bss);
  394. }
  395. }
  396. static int iwm_channels_init(struct iwm_priv *iwm)
  397. {
  398. int ret;
  399. #ifdef CONFIG_IWM_B0_HW_SUPPORT
  400. if (iwm->conf.hw_b0) {
  401. IWM_INFO(iwm, "Workaround EEPROM channels for B0 hardware\n");
  402. return 0;
  403. }
  404. #endif
  405. ret = iwm_send_umac_channel_list(iwm);
  406. if (ret) {
  407. IWM_ERR(iwm, "Send channel list failed\n");
  408. return ret;
  409. }
  410. ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST,
  411. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  412. if (ret) {
  413. IWM_ERR(iwm, "Didn't get a channel list notification\n");
  414. return ret;
  415. }
  416. return 0;
  417. }
  418. int iwm_up(struct iwm_priv *iwm)
  419. {
  420. int ret;
  421. struct iwm_notif *notif_reboot, *notif_ack = NULL;
  422. ret = iwm_bus_enable(iwm);
  423. if (ret) {
  424. IWM_ERR(iwm, "Couldn't enable function\n");
  425. return ret;
  426. }
  427. iwm_rx_setup_handlers(iwm);
  428. /* Wait for initial BARKER_REBOOT from hardware */
  429. notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION,
  430. IWM_SRC_UDMA, 2 * HZ);
  431. if (!notif_reboot) {
  432. IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n");
  433. goto err_disable;
  434. }
  435. /* We send the barker back */
  436. ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16);
  437. if (ret) {
  438. IWM_ERR(iwm, "REBOOT barker response failed\n");
  439. kfree(notif_reboot);
  440. goto err_disable;
  441. }
  442. kfree(notif_reboot->buf);
  443. kfree(notif_reboot);
  444. /* Wait for ACK_BARKER from hardware */
  445. notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION,
  446. IWM_SRC_UDMA, 2 * HZ);
  447. if (!notif_ack) {
  448. IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n");
  449. goto err_disable;
  450. }
  451. kfree(notif_ack->buf);
  452. kfree(notif_ack);
  453. /* We start to config static boot parameters */
  454. ret = iwm_config_boot_params(iwm);
  455. if (ret) {
  456. IWM_ERR(iwm, "Config boot parameters failed\n");
  457. goto err_disable;
  458. }
  459. ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr);
  460. if (ret) {
  461. IWM_ERR(iwm, "MAC reading failed\n");
  462. goto err_disable;
  463. }
  464. /* We can load the FWs */
  465. ret = iwm_load_fw(iwm);
  466. if (ret) {
  467. IWM_ERR(iwm, "FW loading failed\n");
  468. goto err_disable;
  469. }
  470. /* We configure the UMAC and enable the wifi module */
  471. ret = iwm_send_umac_config(iwm,
  472. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) |
  473. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) |
  474. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN));
  475. if (ret) {
  476. IWM_ERR(iwm, "UMAC config failed\n");
  477. goto err_fw;
  478. }
  479. ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
  480. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  481. if (ret) {
  482. IWM_ERR(iwm, "Didn't get a wifi core status notification\n");
  483. goto err_fw;
  484. }
  485. if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
  486. UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
  487. IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n",
  488. iwm->core_enabled);
  489. ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
  490. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  491. if (ret) {
  492. IWM_ERR(iwm, "Didn't get a core status notification\n");
  493. goto err_fw;
  494. }
  495. if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
  496. UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
  497. IWM_ERR(iwm, "Not all cores enabled: 0x%x\n",
  498. iwm->core_enabled);
  499. goto err_fw;
  500. } else {
  501. IWM_INFO(iwm, "All cores enabled\n");
  502. }
  503. }
  504. iwm->umac_profile = kmalloc(sizeof(struct iwm_umac_profile),
  505. GFP_KERNEL);
  506. if (!iwm->umac_profile) {
  507. IWM_ERR(iwm, "Couldn't alloc memory for profile\n");
  508. goto err_fw;
  509. }
  510. iwm_init_default_profile(iwm, iwm->umac_profile);
  511. ret = iwm_channels_init(iwm);
  512. if (ret < 0) {
  513. IWM_ERR(iwm, "Couldn't init channels\n");
  514. goto err_profile;
  515. }
  516. /* Set the READY bit to indicate interface is brought up successfully */
  517. set_bit(IWM_STATUS_READY, &iwm->status);
  518. return 0;
  519. err_profile:
  520. kfree(iwm->umac_profile);
  521. iwm->umac_profile = NULL;
  522. err_fw:
  523. iwm_eeprom_exit(iwm);
  524. err_disable:
  525. ret = iwm_bus_disable(iwm);
  526. if (ret < 0)
  527. IWM_ERR(iwm, "Couldn't disable function\n");
  528. return -EIO;
  529. }
  530. int iwm_down(struct iwm_priv *iwm)
  531. {
  532. int ret;
  533. /* The interface is already down */
  534. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  535. return 0;
  536. if (iwm->scan_request) {
  537. cfg80211_scan_done(iwm->scan_request, true);
  538. iwm->scan_request = NULL;
  539. }
  540. clear_bit(IWM_STATUS_READY, &iwm->status);
  541. iwm_eeprom_exit(iwm);
  542. kfree(iwm->umac_profile);
  543. iwm->umac_profile = NULL;
  544. iwm_bss_list_clean(iwm);
  545. iwm->default_key = NULL;
  546. iwm->core_enabled = 0;
  547. ret = iwm_bus_disable(iwm);
  548. if (ret < 0) {
  549. IWM_ERR(iwm, "Couldn't disable function\n");
  550. return ret;
  551. }
  552. return 0;
  553. }