main.c 21 KB

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