main.c 18 KB

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