main.c 21 KB

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