main.c 21 KB

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