main.c 18 KB

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