main.c 18 KB

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