main.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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. spin_lock_init(&iwm->ticket_lock);
  232. for (i = 0; i < IWM_RX_ID_HASH; i++) {
  233. INIT_LIST_HEAD(&iwm->rx_packets[i]);
  234. spin_lock_init(&iwm->packet_lock[i]);
  235. }
  236. INIT_WORK(&iwm->rx_worker, iwm_rx_worker);
  237. iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx");
  238. if (!iwm->rx_wq)
  239. return -EAGAIN;
  240. for (i = 0; i < IWM_TX_QUEUES; i++) {
  241. INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker);
  242. snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i);
  243. iwm->txq[i].id = i;
  244. iwm->txq[i].wq = create_singlethread_workqueue(name);
  245. if (!iwm->txq[i].wq)
  246. return -EAGAIN;
  247. skb_queue_head_init(&iwm->txq[i].queue);
  248. skb_queue_head_init(&iwm->txq[i].stopped_queue);
  249. spin_lock_init(&iwm->txq[i].lock);
  250. }
  251. for (i = 0; i < IWM_NUM_KEYS; i++)
  252. memset(&iwm->keys[i], 0, sizeof(struct iwm_key));
  253. iwm->default_key = -1;
  254. for (i = 0; i < IWM_STA_TABLE_NUM; i++)
  255. for (j = 0; j < IWM_UMAC_TID_NR; j++) {
  256. mutex_init(&iwm->sta_table[i].tid_info[j].mutex);
  257. iwm->sta_table[i].tid_info[j].stopped = false;
  258. }
  259. init_timer(&iwm->watchdog);
  260. iwm->watchdog.function = iwm_watchdog;
  261. iwm->watchdog.data = (unsigned long)iwm;
  262. mutex_init(&iwm->mutex);
  263. iwm->last_fw_err = kzalloc(sizeof(struct iwm_fw_error_hdr),
  264. GFP_KERNEL);
  265. if (iwm->last_fw_err == NULL)
  266. return -ENOMEM;
  267. return 0;
  268. }
  269. void iwm_priv_deinit(struct iwm_priv *iwm)
  270. {
  271. int i;
  272. for (i = 0; i < IWM_TX_QUEUES; i++)
  273. destroy_workqueue(iwm->txq[i].wq);
  274. destroy_workqueue(iwm->rx_wq);
  275. kfree(iwm->last_fw_err);
  276. }
  277. /*
  278. * We reset all the structures, and we reset the UMAC.
  279. * After calling this routine, you're expected to reload
  280. * the firmware.
  281. */
  282. void iwm_reset(struct iwm_priv *iwm)
  283. {
  284. struct iwm_notif *notif, *next;
  285. if (test_bit(IWM_STATUS_READY, &iwm->status))
  286. iwm_target_reset(iwm);
  287. if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) {
  288. iwm->status = 0;
  289. set_bit(IWM_STATUS_RESETTING, &iwm->status);
  290. } else
  291. iwm->status = 0;
  292. iwm->scan_id = 1;
  293. list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
  294. list_del(&notif->pending);
  295. kfree(notif->buf);
  296. kfree(notif);
  297. }
  298. iwm_cmd_flush(iwm);
  299. flush_workqueue(iwm->rx_wq);
  300. iwm_link_off(iwm);
  301. }
  302. void iwm_resetting(struct iwm_priv *iwm)
  303. {
  304. set_bit(IWM_STATUS_RESETTING, &iwm->status);
  305. schedule_work(&iwm->reset_worker);
  306. }
  307. /*
  308. * Notification code:
  309. *
  310. * We're faced with the following issue: Any host command can
  311. * have an answer or not, and if there's an answer to expect,
  312. * it can be treated synchronously or asynchronously.
  313. * To work around the synchronous answer case, we implemented
  314. * our notification mechanism.
  315. * When a code path needs to wait for a command response
  316. * synchronously, it calls notif_handle(), which waits for the
  317. * right notification to show up, and then process it. Before
  318. * starting to wait, it registered as a waiter for this specific
  319. * answer (by toggling a bit in on of the handler_map), so that
  320. * the rx code knows that it needs to send a notification to the
  321. * waiting processes. It does so by calling iwm_notif_send(),
  322. * which adds the notification to the pending notifications list,
  323. * and then wakes the waiting processes up.
  324. */
  325. int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
  326. u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size)
  327. {
  328. struct iwm_notif *notif;
  329. notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL);
  330. if (!notif) {
  331. IWM_ERR(iwm, "Couldn't alloc memory for notification\n");
  332. return -ENOMEM;
  333. }
  334. INIT_LIST_HEAD(&notif->pending);
  335. notif->cmd = cmd;
  336. notif->cmd_id = cmd_id;
  337. notif->src = source;
  338. notif->buf = kzalloc(buf_size, GFP_KERNEL);
  339. if (!notif->buf) {
  340. IWM_ERR(iwm, "Couldn't alloc notification buffer\n");
  341. kfree(notif);
  342. return -ENOMEM;
  343. }
  344. notif->buf_size = buf_size;
  345. memcpy(notif->buf, buf, buf_size);
  346. list_add_tail(&notif->pending, &iwm->pending_notif);
  347. wake_up_interruptible(&iwm->notif_queue);
  348. return 0;
  349. }
  350. static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd,
  351. u8 source)
  352. {
  353. struct iwm_notif *notif;
  354. list_for_each_entry(notif, &iwm->pending_notif, pending) {
  355. if ((notif->cmd_id == cmd) && (notif->src == source)) {
  356. list_del(&notif->pending);
  357. return notif;
  358. }
  359. }
  360. return NULL;
  361. }
  362. static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd,
  363. u8 source, long timeout)
  364. {
  365. int ret;
  366. struct iwm_notif *notif;
  367. unsigned long *map = NULL;
  368. switch (source) {
  369. case IWM_SRC_LMAC:
  370. map = &iwm->lmac_handler_map[0];
  371. break;
  372. case IWM_SRC_UMAC:
  373. map = &iwm->umac_handler_map[0];
  374. break;
  375. case IWM_SRC_UDMA:
  376. map = &iwm->udma_handler_map[0];
  377. break;
  378. }
  379. set_bit(cmd, map);
  380. ret = wait_event_interruptible_timeout(iwm->notif_queue,
  381. ((notif = iwm_notif_find(iwm, cmd, source)) != NULL),
  382. timeout);
  383. clear_bit(cmd, map);
  384. if (!ret)
  385. return NULL;
  386. return notif;
  387. }
  388. int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout)
  389. {
  390. int ret;
  391. struct iwm_notif *notif;
  392. notif = iwm_notif_wait(iwm, cmd, source, timeout);
  393. if (!notif)
  394. return -ETIME;
  395. ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd);
  396. kfree(notif->buf);
  397. kfree(notif);
  398. return ret;
  399. }
  400. static int iwm_config_boot_params(struct iwm_priv *iwm)
  401. {
  402. struct iwm_udma_nonwifi_cmd target_cmd;
  403. int ret;
  404. /* check Wimax is off and config debug monitor */
  405. if (!modparam_wimax_enable) {
  406. u32 data1 = 0x1f;
  407. u32 addr1 = 0x606BE258;
  408. u32 data2_set = 0x0;
  409. u32 data2_clr = 0x1;
  410. u32 addr2 = 0x606BE100;
  411. u32 data3 = 0x1;
  412. u32 addr3 = 0x606BEC00;
  413. target_cmd.resp = 0;
  414. target_cmd.handle_by_hw = 0;
  415. target_cmd.eop = 1;
  416. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
  417. target_cmd.addr = cpu_to_le32(addr1);
  418. target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
  419. target_cmd.op2 = 0;
  420. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
  421. if (ret < 0) {
  422. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  423. return ret;
  424. }
  425. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE;
  426. target_cmd.addr = cpu_to_le32(addr2);
  427. target_cmd.op1_sz = cpu_to_le32(data2_set);
  428. target_cmd.op2 = cpu_to_le32(data2_clr);
  429. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
  430. if (ret < 0) {
  431. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  432. return ret;
  433. }
  434. target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
  435. target_cmd.addr = cpu_to_le32(addr3);
  436. target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
  437. target_cmd.op2 = 0;
  438. ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3);
  439. if (ret < 0) {
  440. IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
  441. return ret;
  442. }
  443. }
  444. return 0;
  445. }
  446. void iwm_init_default_profile(struct iwm_priv *iwm,
  447. struct iwm_umac_profile *profile)
  448. {
  449. memset(profile, 0, sizeof(struct iwm_umac_profile));
  450. profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
  451. profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
  452. profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE;
  453. profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE;
  454. if (iwm->conf.enable_qos)
  455. profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED);
  456. profile->wireless_mode = iwm->conf.wireless_mode;
  457. profile->mode = cpu_to_le32(iwm->conf.mode);
  458. profile->ibss.atim = 0;
  459. profile->ibss.beacon_interval = 100;
  460. profile->ibss.join_only = 0;
  461. profile->ibss.band = iwm->conf.ibss_band;
  462. profile->ibss.channel = iwm->conf.ibss_channel;
  463. }
  464. void iwm_link_on(struct iwm_priv *iwm)
  465. {
  466. netif_carrier_on(iwm_to_ndev(iwm));
  467. netif_tx_wake_all_queues(iwm_to_ndev(iwm));
  468. iwm_send_umac_stats_req(iwm, 0);
  469. }
  470. void iwm_link_off(struct iwm_priv *iwm)
  471. {
  472. struct iw_statistics *wstats = &iwm->wstats;
  473. int i;
  474. netif_tx_stop_all_queues(iwm_to_ndev(iwm));
  475. netif_carrier_off(iwm_to_ndev(iwm));
  476. for (i = 0; i < IWM_TX_QUEUES; i++) {
  477. skb_queue_purge(&iwm->txq[i].queue);
  478. skb_queue_purge(&iwm->txq[i].stopped_queue);
  479. iwm->txq[i].concat_count = 0;
  480. iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf;
  481. flush_workqueue(iwm->txq[i].wq);
  482. }
  483. iwm_rx_free(iwm);
  484. cancel_delayed_work_sync(&iwm->stats_request);
  485. memset(wstats, 0, sizeof(struct iw_statistics));
  486. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  487. kfree(iwm->req_ie);
  488. iwm->req_ie = NULL;
  489. iwm->req_ie_len = 0;
  490. kfree(iwm->resp_ie);
  491. iwm->resp_ie = NULL;
  492. iwm->resp_ie_len = 0;
  493. del_timer_sync(&iwm->watchdog);
  494. }
  495. static void iwm_bss_list_clean(struct iwm_priv *iwm)
  496. {
  497. struct iwm_bss_info *bss, *next;
  498. list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
  499. list_del(&bss->node);
  500. kfree(bss->bss);
  501. kfree(bss);
  502. }
  503. }
  504. static int iwm_channels_init(struct iwm_priv *iwm)
  505. {
  506. int ret;
  507. ret = iwm_send_umac_channel_list(iwm);
  508. if (ret) {
  509. IWM_ERR(iwm, "Send channel list failed\n");
  510. return ret;
  511. }
  512. ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST,
  513. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  514. if (ret) {
  515. IWM_ERR(iwm, "Didn't get a channel list notification\n");
  516. return ret;
  517. }
  518. return 0;
  519. }
  520. static int __iwm_up(struct iwm_priv *iwm)
  521. {
  522. int ret;
  523. struct iwm_notif *notif_reboot, *notif_ack = NULL;
  524. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  525. u32 wireless_mode;
  526. ret = iwm_bus_enable(iwm);
  527. if (ret) {
  528. IWM_ERR(iwm, "Couldn't enable function\n");
  529. return ret;
  530. }
  531. iwm_rx_setup_handlers(iwm);
  532. /* Wait for initial BARKER_REBOOT from hardware */
  533. notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION,
  534. IWM_SRC_UDMA, 2 * HZ);
  535. if (!notif_reboot) {
  536. IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n");
  537. goto err_disable;
  538. }
  539. /* We send the barker back */
  540. ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16);
  541. if (ret) {
  542. IWM_ERR(iwm, "REBOOT barker response failed\n");
  543. kfree(notif_reboot);
  544. goto err_disable;
  545. }
  546. kfree(notif_reboot->buf);
  547. kfree(notif_reboot);
  548. /* Wait for ACK_BARKER from hardware */
  549. notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION,
  550. IWM_SRC_UDMA, 2 * HZ);
  551. if (!notif_ack) {
  552. IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n");
  553. goto err_disable;
  554. }
  555. kfree(notif_ack->buf);
  556. kfree(notif_ack);
  557. /* We start to config static boot parameters */
  558. ret = iwm_config_boot_params(iwm);
  559. if (ret) {
  560. IWM_ERR(iwm, "Config boot parameters failed\n");
  561. goto err_disable;
  562. }
  563. ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr);
  564. if (ret) {
  565. IWM_ERR(iwm, "MAC reading failed\n");
  566. goto err_disable;
  567. }
  568. memcpy(iwm_to_ndev(iwm)->perm_addr, iwm_to_ndev(iwm)->dev_addr,
  569. ETH_ALEN);
  570. /* We can load the FWs */
  571. ret = iwm_load_fw(iwm);
  572. if (ret) {
  573. IWM_ERR(iwm, "FW loading failed\n");
  574. goto err_disable;
  575. }
  576. ret = iwm_eeprom_fat_channels(iwm);
  577. if (ret) {
  578. IWM_ERR(iwm, "Couldnt read HT channels EEPROM entries\n");
  579. goto err_fw;
  580. }
  581. /*
  582. * Read our SKU capabilities.
  583. * If it's valid, we AND the configured wireless mode with the
  584. * device EEPROM value as the current profile wireless mode.
  585. */
  586. wireless_mode = iwm_eeprom_wireless_mode(iwm);
  587. if (wireless_mode) {
  588. iwm->conf.wireless_mode &= wireless_mode;
  589. if (iwm->umac_profile)
  590. iwm->umac_profile->wireless_mode =
  591. iwm->conf.wireless_mode;
  592. } else
  593. IWM_ERR(iwm, "Wrong SKU capabilities: 0x%x\n",
  594. *((u16 *)iwm_eeprom_access(iwm, IWM_EEPROM_SKU_CAP)));
  595. snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "L%s_U%s",
  596. iwm->lmac_version, iwm->umac_version);
  597. /* We configure the UMAC and enable the wifi module */
  598. ret = iwm_send_umac_config(iwm,
  599. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) |
  600. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) |
  601. cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN));
  602. if (ret) {
  603. IWM_ERR(iwm, "UMAC config failed\n");
  604. goto err_fw;
  605. }
  606. ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
  607. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  608. if (ret) {
  609. IWM_ERR(iwm, "Didn't get a wifi core status notification\n");
  610. goto err_fw;
  611. }
  612. if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
  613. UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
  614. IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n",
  615. iwm->core_enabled);
  616. ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
  617. IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
  618. if (ret) {
  619. IWM_ERR(iwm, "Didn't get a core status notification\n");
  620. goto err_fw;
  621. }
  622. if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
  623. UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
  624. IWM_ERR(iwm, "Not all cores enabled: 0x%x\n",
  625. iwm->core_enabled);
  626. goto err_fw;
  627. } else {
  628. IWM_INFO(iwm, "All cores enabled\n");
  629. }
  630. }
  631. ret = iwm_channels_init(iwm);
  632. if (ret < 0) {
  633. IWM_ERR(iwm, "Couldn't init channels\n");
  634. goto err_fw;
  635. }
  636. /* Set the READY bit to indicate interface is brought up successfully */
  637. set_bit(IWM_STATUS_READY, &iwm->status);
  638. return 0;
  639. err_fw:
  640. iwm_eeprom_exit(iwm);
  641. err_disable:
  642. ret = iwm_bus_disable(iwm);
  643. if (ret < 0)
  644. IWM_ERR(iwm, "Couldn't disable function\n");
  645. return -EIO;
  646. }
  647. int iwm_up(struct iwm_priv *iwm)
  648. {
  649. int ret;
  650. mutex_lock(&iwm->mutex);
  651. ret = __iwm_up(iwm);
  652. mutex_unlock(&iwm->mutex);
  653. return ret;
  654. }
  655. static int __iwm_down(struct iwm_priv *iwm)
  656. {
  657. int ret;
  658. /* The interface is already down */
  659. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  660. return 0;
  661. if (iwm->scan_request) {
  662. cfg80211_scan_done(iwm->scan_request, true);
  663. iwm->scan_request = NULL;
  664. }
  665. clear_bit(IWM_STATUS_READY, &iwm->status);
  666. iwm_eeprom_exit(iwm);
  667. iwm_bss_list_clean(iwm);
  668. iwm_init_default_profile(iwm, iwm->umac_profile);
  669. iwm->umac_profile_active = false;
  670. iwm->default_key = -1;
  671. iwm->core_enabled = 0;
  672. ret = iwm_bus_disable(iwm);
  673. if (ret < 0) {
  674. IWM_ERR(iwm, "Couldn't disable function\n");
  675. return ret;
  676. }
  677. return 0;
  678. }
  679. int iwm_down(struct iwm_priv *iwm)
  680. {
  681. int ret;
  682. mutex_lock(&iwm->mutex);
  683. ret = __iwm_down(iwm);
  684. mutex_unlock(&iwm->mutex);
  685. return ret;
  686. }