main.c 21 KB

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