main.c 19 KB

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