utils.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <net/mac80211.h>
  66. #include "iwl-debug.h"
  67. #include "iwl-io.h"
  68. #include "iwl-prph.h"
  69. #include "mvm.h"
  70. #include "fw-api-rs.h"
  71. /*
  72. * Will return 0 even if the cmd failed when RFKILL is asserted unless
  73. * CMD_WANT_SKB is set in cmd->flags.
  74. */
  75. int iwl_mvm_send_cmd(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd)
  76. {
  77. int ret;
  78. #if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
  79. if (WARN_ON(mvm->d3_test_active))
  80. return -EIO;
  81. #endif
  82. /*
  83. * Synchronous commands from this op-mode must hold
  84. * the mutex, this ensures we don't try to send two
  85. * (or more) synchronous commands at a time.
  86. */
  87. if (!(cmd->flags & CMD_ASYNC))
  88. lockdep_assert_held(&mvm->mutex);
  89. ret = iwl_trans_send_cmd(mvm->trans, cmd);
  90. /*
  91. * If the caller wants the SKB, then don't hide any problems, the
  92. * caller might access the response buffer which will be NULL if
  93. * the command failed.
  94. */
  95. if (cmd->flags & CMD_WANT_SKB)
  96. return ret;
  97. /* Silently ignore failures if RFKILL is asserted */
  98. if (!ret || ret == -ERFKILL)
  99. return 0;
  100. return ret;
  101. }
  102. int iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u8 id,
  103. u32 flags, u16 len, const void *data)
  104. {
  105. struct iwl_host_cmd cmd = {
  106. .id = id,
  107. .len = { len, },
  108. .data = { data, },
  109. .flags = flags,
  110. };
  111. return iwl_mvm_send_cmd(mvm, &cmd);
  112. }
  113. /*
  114. * We assume that the caller set the status to the success value
  115. */
  116. int iwl_mvm_send_cmd_status(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd,
  117. u32 *status)
  118. {
  119. struct iwl_rx_packet *pkt;
  120. struct iwl_cmd_response *resp;
  121. int ret, resp_len;
  122. lockdep_assert_held(&mvm->mutex);
  123. #if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
  124. if (WARN_ON(mvm->d3_test_active))
  125. return -EIO;
  126. #endif
  127. /*
  128. * Only synchronous commands can wait for status,
  129. * we use WANT_SKB so the caller can't.
  130. */
  131. if (WARN_ONCE(cmd->flags & (CMD_ASYNC | CMD_WANT_SKB),
  132. "cmd flags %x", cmd->flags))
  133. return -EINVAL;
  134. cmd->flags |= CMD_WANT_SKB;
  135. ret = iwl_trans_send_cmd(mvm->trans, cmd);
  136. if (ret == -ERFKILL) {
  137. /*
  138. * The command failed because of RFKILL, don't update
  139. * the status, leave it as success and return 0.
  140. */
  141. return 0;
  142. } else if (ret) {
  143. return ret;
  144. }
  145. pkt = cmd->resp_pkt;
  146. /* Can happen if RFKILL is asserted */
  147. if (!pkt) {
  148. ret = 0;
  149. goto out_free_resp;
  150. }
  151. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  152. ret = -EIO;
  153. goto out_free_resp;
  154. }
  155. resp_len = iwl_rx_packet_payload_len(pkt);
  156. if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
  157. ret = -EIO;
  158. goto out_free_resp;
  159. }
  160. resp = (void *)pkt->data;
  161. *status = le32_to_cpu(resp->status);
  162. out_free_resp:
  163. iwl_free_resp(cmd);
  164. return ret;
  165. }
  166. /*
  167. * We assume that the caller set the status to the sucess value
  168. */
  169. int iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u8 id, u16 len,
  170. const void *data, u32 *status)
  171. {
  172. struct iwl_host_cmd cmd = {
  173. .id = id,
  174. .len = { len, },
  175. .data = { data, },
  176. };
  177. return iwl_mvm_send_cmd_status(mvm, &cmd, status);
  178. }
  179. #define IWL_DECLARE_RATE_INFO(r) \
  180. [IWL_RATE_##r##M_INDEX] = IWL_RATE_##r##M_PLCP
  181. /*
  182. * Translate from fw_rate_index (IWL_RATE_XXM_INDEX) to PLCP
  183. */
  184. static const u8 fw_rate_idx_to_plcp[IWL_RATE_COUNT] = {
  185. IWL_DECLARE_RATE_INFO(1),
  186. IWL_DECLARE_RATE_INFO(2),
  187. IWL_DECLARE_RATE_INFO(5),
  188. IWL_DECLARE_RATE_INFO(11),
  189. IWL_DECLARE_RATE_INFO(6),
  190. IWL_DECLARE_RATE_INFO(9),
  191. IWL_DECLARE_RATE_INFO(12),
  192. IWL_DECLARE_RATE_INFO(18),
  193. IWL_DECLARE_RATE_INFO(24),
  194. IWL_DECLARE_RATE_INFO(36),
  195. IWL_DECLARE_RATE_INFO(48),
  196. IWL_DECLARE_RATE_INFO(54),
  197. };
  198. int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
  199. enum ieee80211_band band)
  200. {
  201. int rate = rate_n_flags & RATE_LEGACY_RATE_MSK;
  202. int idx;
  203. int band_offset = 0;
  204. /* Legacy rate format, search for match in table */
  205. if (band == IEEE80211_BAND_5GHZ)
  206. band_offset = IWL_FIRST_OFDM_RATE;
  207. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  208. if (fw_rate_idx_to_plcp[idx] == rate)
  209. return idx - band_offset;
  210. return -1;
  211. }
  212. u8 iwl_mvm_mac80211_idx_to_hwrate(int rate_idx)
  213. {
  214. /* Get PLCP rate for tx_cmd->rate_n_flags */
  215. return fw_rate_idx_to_plcp[rate_idx];
  216. }
  217. int iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
  218. struct iwl_device_cmd *cmd)
  219. {
  220. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  221. struct iwl_error_resp *err_resp = (void *)pkt->data;
  222. IWL_ERR(mvm, "FW Error notification: type 0x%08X cmd_id 0x%02X\n",
  223. le32_to_cpu(err_resp->error_type), err_resp->cmd_id);
  224. IWL_ERR(mvm, "FW Error notification: seq 0x%04X service 0x%08X\n",
  225. le16_to_cpu(err_resp->bad_cmd_seq_num),
  226. le32_to_cpu(err_resp->error_service));
  227. IWL_ERR(mvm, "FW Error notification: timestamp 0x%16llX\n",
  228. le64_to_cpu(err_resp->timestamp));
  229. return 0;
  230. }
  231. /*
  232. * Returns the first antenna as ANT_[ABC], as defined in iwl-config.h.
  233. * The parameter should also be a combination of ANT_[ABC].
  234. */
  235. u8 first_antenna(u8 mask)
  236. {
  237. BUILD_BUG_ON(ANT_A != BIT(0)); /* using ffs is wrong if not */
  238. if (WARN_ON_ONCE(!mask)) /* ffs will return 0 if mask is zeroed */
  239. return BIT(0);
  240. return BIT(ffs(mask) - 1);
  241. }
  242. /*
  243. * Toggles between TX antennas to send the probe request on.
  244. * Receives the bitmask of valid TX antennas and the *index* used
  245. * for the last TX, and returns the next valid *index* to use.
  246. * In order to set it in the tx_cmd, must do BIT(idx).
  247. */
  248. u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx)
  249. {
  250. u8 ind = last_idx;
  251. int i;
  252. for (i = 0; i < RATE_MCS_ANT_NUM; i++) {
  253. ind = (ind + 1) % RATE_MCS_ANT_NUM;
  254. if (valid & BIT(ind))
  255. return ind;
  256. }
  257. WARN_ONCE(1, "Failed to toggle between antennas 0x%x", valid);
  258. return last_idx;
  259. }
  260. static const struct {
  261. const char *name;
  262. u8 num;
  263. } advanced_lookup[] = {
  264. { "NMI_INTERRUPT_WDG", 0x34 },
  265. { "SYSASSERT", 0x35 },
  266. { "UCODE_VERSION_MISMATCH", 0x37 },
  267. { "BAD_COMMAND", 0x38 },
  268. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  269. { "FATAL_ERROR", 0x3D },
  270. { "NMI_TRM_HW_ERR", 0x46 },
  271. { "NMI_INTERRUPT_TRM", 0x4C },
  272. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  273. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  274. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  275. { "NMI_INTERRUPT_HOST", 0x66 },
  276. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  277. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  278. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  279. { "ADVANCED_SYSASSERT", 0 },
  280. };
  281. static const char *desc_lookup(u32 num)
  282. {
  283. int i;
  284. for (i = 0; i < ARRAY_SIZE(advanced_lookup) - 1; i++)
  285. if (advanced_lookup[i].num == num)
  286. return advanced_lookup[i].name;
  287. /* No entry matches 'num', so it is the last: ADVANCED_SYSASSERT */
  288. return advanced_lookup[i].name;
  289. }
  290. /*
  291. * Note: This structure is read from the device with IO accesses,
  292. * and the reading already does the endian conversion. As it is
  293. * read with u32-sized accesses, any members with a different size
  294. * need to be ordered correctly though!
  295. */
  296. struct iwl_error_event_table_v1 {
  297. u32 valid; /* (nonzero) valid, (0) log is empty */
  298. u32 error_id; /* type of error */
  299. u32 pc; /* program counter */
  300. u32 blink1; /* branch link */
  301. u32 blink2; /* branch link */
  302. u32 ilink1; /* interrupt link */
  303. u32 ilink2; /* interrupt link */
  304. u32 data1; /* error-specific data */
  305. u32 data2; /* error-specific data */
  306. u32 data3; /* error-specific data */
  307. u32 bcon_time; /* beacon timer */
  308. u32 tsf_low; /* network timestamp function timer */
  309. u32 tsf_hi; /* network timestamp function timer */
  310. u32 gp1; /* GP1 timer register */
  311. u32 gp2; /* GP2 timer register */
  312. u32 gp3; /* GP3 timer register */
  313. u32 ucode_ver; /* uCode version */
  314. u32 hw_ver; /* HW Silicon version */
  315. u32 brd_ver; /* HW board version */
  316. u32 log_pc; /* log program counter */
  317. u32 frame_ptr; /* frame pointer */
  318. u32 stack_ptr; /* stack pointer */
  319. u32 hcmd; /* last host command header */
  320. u32 isr0; /* isr status register LMPM_NIC_ISR0:
  321. * rxtx_flag */
  322. u32 isr1; /* isr status register LMPM_NIC_ISR1:
  323. * host_flag */
  324. u32 isr2; /* isr status register LMPM_NIC_ISR2:
  325. * enc_flag */
  326. u32 isr3; /* isr status register LMPM_NIC_ISR3:
  327. * time_flag */
  328. u32 isr4; /* isr status register LMPM_NIC_ISR4:
  329. * wico interrupt */
  330. u32 isr_pref; /* isr status register LMPM_NIC_PREF_STAT */
  331. u32 wait_event; /* wait event() caller address */
  332. u32 l2p_control; /* L2pControlField */
  333. u32 l2p_duration; /* L2pDurationField */
  334. u32 l2p_mhvalid; /* L2pMhValidBits */
  335. u32 l2p_addr_match; /* L2pAddrMatchStat */
  336. u32 lmpm_pmg_sel; /* indicate which clocks are turned on
  337. * (LMPM_PMG_SEL) */
  338. u32 u_timestamp; /* indicate when the date and time of the
  339. * compilation */
  340. u32 flow_handler; /* FH read/write pointers, RX credit */
  341. } __packed /* LOG_ERROR_TABLE_API_S_VER_1 */;
  342. struct iwl_error_event_table {
  343. u32 valid; /* (nonzero) valid, (0) log is empty */
  344. u32 error_id; /* type of error */
  345. u32 pc; /* program counter */
  346. u32 blink1; /* branch link */
  347. u32 blink2; /* branch link */
  348. u32 ilink1; /* interrupt link */
  349. u32 ilink2; /* interrupt link */
  350. u32 data1; /* error-specific data */
  351. u32 data2; /* error-specific data */
  352. u32 data3; /* error-specific data */
  353. u32 bcon_time; /* beacon timer */
  354. u32 tsf_low; /* network timestamp function timer */
  355. u32 tsf_hi; /* network timestamp function timer */
  356. u32 gp1; /* GP1 timer register */
  357. u32 gp2; /* GP2 timer register */
  358. u32 gp3; /* GP3 timer register */
  359. u32 major; /* uCode version major */
  360. u32 minor; /* uCode version minor */
  361. u32 hw_ver; /* HW Silicon version */
  362. u32 brd_ver; /* HW board version */
  363. u32 log_pc; /* log program counter */
  364. u32 frame_ptr; /* frame pointer */
  365. u32 stack_ptr; /* stack pointer */
  366. u32 hcmd; /* last host command header */
  367. u32 isr0; /* isr status register LMPM_NIC_ISR0:
  368. * rxtx_flag */
  369. u32 isr1; /* isr status register LMPM_NIC_ISR1:
  370. * host_flag */
  371. u32 isr2; /* isr status register LMPM_NIC_ISR2:
  372. * enc_flag */
  373. u32 isr3; /* isr status register LMPM_NIC_ISR3:
  374. * time_flag */
  375. u32 isr4; /* isr status register LMPM_NIC_ISR4:
  376. * wico interrupt */
  377. u32 isr_pref; /* isr status register LMPM_NIC_PREF_STAT */
  378. u32 wait_event; /* wait event() caller address */
  379. u32 l2p_control; /* L2pControlField */
  380. u32 l2p_duration; /* L2pDurationField */
  381. u32 l2p_mhvalid; /* L2pMhValidBits */
  382. u32 l2p_addr_match; /* L2pAddrMatchStat */
  383. u32 lmpm_pmg_sel; /* indicate which clocks are turned on
  384. * (LMPM_PMG_SEL) */
  385. u32 u_timestamp; /* indicate when the date and time of the
  386. * compilation */
  387. u32 flow_handler; /* FH read/write pointers, RX credit */
  388. } __packed /* LOG_ERROR_TABLE_API_S_VER_2 */;
  389. /*
  390. * UMAC error struct - relevant starting from family 8000 chip.
  391. * Note: This structure is read from the device with IO accesses,
  392. * and the reading already does the endian conversion. As it is
  393. * read with u32-sized accesses, any members with a different size
  394. * need to be ordered correctly though!
  395. */
  396. struct iwl_umac_error_event_table {
  397. u32 valid; /* (nonzero) valid, (0) log is empty */
  398. u32 error_id; /* type of error */
  399. u32 blink1; /* branch link */
  400. u32 blink2; /* branch link */
  401. u32 ilink1; /* interrupt link */
  402. u32 ilink2; /* interrupt link */
  403. u32 data1; /* error-specific data */
  404. u32 data2; /* error-specific data */
  405. u32 data3; /* error-specific data */
  406. u32 umac_major;
  407. u32 umac_minor;
  408. u32 frame_pointer; /* core register 27*/
  409. u32 stack_pointer; /* core register 28 */
  410. u32 cmd_header; /* latest host cmd sent to UMAC */
  411. u32 nic_isr_pref; /* ISR status register */
  412. } __packed;
  413. #define ERROR_START_OFFSET (1 * sizeof(u32))
  414. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  415. static void iwl_mvm_dump_umac_error_log(struct iwl_mvm *mvm)
  416. {
  417. struct iwl_trans *trans = mvm->trans;
  418. struct iwl_umac_error_event_table table;
  419. u32 base;
  420. base = mvm->umac_error_event_table;
  421. if (base < 0x800000) {
  422. IWL_ERR(mvm,
  423. "Not valid error log pointer 0x%08X for %s uCode\n",
  424. base,
  425. (mvm->cur_ucode == IWL_UCODE_INIT)
  426. ? "Init" : "RT");
  427. return;
  428. }
  429. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  430. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  431. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  432. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  433. mvm->status, table.valid);
  434. }
  435. IWL_ERR(mvm, "0x%08X | %s\n", table.error_id,
  436. desc_lookup(table.error_id));
  437. IWL_ERR(mvm, "0x%08X | umac branchlink1\n", table.blink1);
  438. IWL_ERR(mvm, "0x%08X | umac branchlink2\n", table.blink2);
  439. IWL_ERR(mvm, "0x%08X | umac interruptlink1\n", table.ilink1);
  440. IWL_ERR(mvm, "0x%08X | umac interruptlink2\n", table.ilink2);
  441. IWL_ERR(mvm, "0x%08X | umac data1\n", table.data1);
  442. IWL_ERR(mvm, "0x%08X | umac data2\n", table.data2);
  443. IWL_ERR(mvm, "0x%08X | umac data3\n", table.data3);
  444. IWL_ERR(mvm, "0x%08X | umac major\n", table.umac_major);
  445. IWL_ERR(mvm, "0x%08X | umac minor\n", table.umac_minor);
  446. IWL_ERR(mvm, "0x%08X | frame pointer\n", table.frame_pointer);
  447. IWL_ERR(mvm, "0x%08X | stack pointer\n", table.stack_pointer);
  448. IWL_ERR(mvm, "0x%08X | last host cmd\n", table.cmd_header);
  449. IWL_ERR(mvm, "0x%08X | isr status reg\n", table.nic_isr_pref);
  450. }
  451. static void iwl_mvm_dump_nic_error_log_old(struct iwl_mvm *mvm)
  452. {
  453. struct iwl_trans *trans = mvm->trans;
  454. struct iwl_error_event_table_v1 table;
  455. u32 base;
  456. base = mvm->error_event_table;
  457. if (mvm->cur_ucode == IWL_UCODE_INIT) {
  458. if (!base)
  459. base = mvm->fw->init_errlog_ptr;
  460. } else {
  461. if (!base)
  462. base = mvm->fw->inst_errlog_ptr;
  463. }
  464. if (base < 0x800000) {
  465. IWL_ERR(mvm,
  466. "Not valid error log pointer 0x%08X for %s uCode\n",
  467. base,
  468. (mvm->cur_ucode == IWL_UCODE_INIT)
  469. ? "Init" : "RT");
  470. return;
  471. }
  472. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  473. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  474. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  475. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  476. mvm->status, table.valid);
  477. }
  478. /* Do not change this output - scripts rely on it */
  479. IWL_ERR(mvm, "Loaded firmware version: %s\n", mvm->fw->fw_version);
  480. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  481. table.data1, table.data2, table.data3,
  482. table.blink1, table.blink2, table.ilink1,
  483. table.ilink2, table.bcon_time, table.gp1,
  484. table.gp2, table.gp3, table.ucode_ver, 0,
  485. table.hw_ver, table.brd_ver);
  486. IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
  487. desc_lookup(table.error_id));
  488. IWL_ERR(mvm, "0x%08X | uPc\n", table.pc);
  489. IWL_ERR(mvm, "0x%08X | branchlink1\n", table.blink1);
  490. IWL_ERR(mvm, "0x%08X | branchlink2\n", table.blink2);
  491. IWL_ERR(mvm, "0x%08X | interruptlink1\n", table.ilink1);
  492. IWL_ERR(mvm, "0x%08X | interruptlink2\n", table.ilink2);
  493. IWL_ERR(mvm, "0x%08X | data1\n", table.data1);
  494. IWL_ERR(mvm, "0x%08X | data2\n", table.data2);
  495. IWL_ERR(mvm, "0x%08X | data3\n", table.data3);
  496. IWL_ERR(mvm, "0x%08X | beacon time\n", table.bcon_time);
  497. IWL_ERR(mvm, "0x%08X | tsf low\n", table.tsf_low);
  498. IWL_ERR(mvm, "0x%08X | tsf hi\n", table.tsf_hi);
  499. IWL_ERR(mvm, "0x%08X | time gp1\n", table.gp1);
  500. IWL_ERR(mvm, "0x%08X | time gp2\n", table.gp2);
  501. IWL_ERR(mvm, "0x%08X | time gp3\n", table.gp3);
  502. IWL_ERR(mvm, "0x%08X | uCode version\n", table.ucode_ver);
  503. IWL_ERR(mvm, "0x%08X | hw version\n", table.hw_ver);
  504. IWL_ERR(mvm, "0x%08X | board version\n", table.brd_ver);
  505. IWL_ERR(mvm, "0x%08X | hcmd\n", table.hcmd);
  506. IWL_ERR(mvm, "0x%08X | isr0\n", table.isr0);
  507. IWL_ERR(mvm, "0x%08X | isr1\n", table.isr1);
  508. IWL_ERR(mvm, "0x%08X | isr2\n", table.isr2);
  509. IWL_ERR(mvm, "0x%08X | isr3\n", table.isr3);
  510. IWL_ERR(mvm, "0x%08X | isr4\n", table.isr4);
  511. IWL_ERR(mvm, "0x%08X | isr_pref\n", table.isr_pref);
  512. IWL_ERR(mvm, "0x%08X | wait_event\n", table.wait_event);
  513. IWL_ERR(mvm, "0x%08X | l2p_control\n", table.l2p_control);
  514. IWL_ERR(mvm, "0x%08X | l2p_duration\n", table.l2p_duration);
  515. IWL_ERR(mvm, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  516. IWL_ERR(mvm, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  517. IWL_ERR(mvm, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  518. IWL_ERR(mvm, "0x%08X | timestamp\n", table.u_timestamp);
  519. IWL_ERR(mvm, "0x%08X | flow_handler\n", table.flow_handler);
  520. if (mvm->support_umac_log)
  521. iwl_mvm_dump_umac_error_log(mvm);
  522. }
  523. void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
  524. {
  525. struct iwl_trans *trans = mvm->trans;
  526. struct iwl_error_event_table table;
  527. u32 base;
  528. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_NEW_VERSION)) {
  529. iwl_mvm_dump_nic_error_log_old(mvm);
  530. return;
  531. }
  532. base = mvm->error_event_table;
  533. if (mvm->cur_ucode == IWL_UCODE_INIT) {
  534. if (!base)
  535. base = mvm->fw->init_errlog_ptr;
  536. } else {
  537. if (!base)
  538. base = mvm->fw->inst_errlog_ptr;
  539. }
  540. if (base < 0x800000) {
  541. IWL_ERR(mvm,
  542. "Not valid error log pointer 0x%08X for %s uCode\n",
  543. base,
  544. (mvm->cur_ucode == IWL_UCODE_INIT)
  545. ? "Init" : "RT");
  546. return;
  547. }
  548. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  549. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  550. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  551. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  552. mvm->status, table.valid);
  553. }
  554. /* Do not change this output - scripts rely on it */
  555. IWL_ERR(mvm, "Loaded firmware version: %s\n", mvm->fw->fw_version);
  556. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  557. table.data1, table.data2, table.data3,
  558. table.blink1, table.blink2, table.ilink1,
  559. table.ilink2, table.bcon_time, table.gp1,
  560. table.gp2, table.gp3, table.major,
  561. table.minor, table.hw_ver, table.brd_ver);
  562. IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
  563. desc_lookup(table.error_id));
  564. IWL_ERR(mvm, "0x%08X | uPc\n", table.pc);
  565. IWL_ERR(mvm, "0x%08X | branchlink1\n", table.blink1);
  566. IWL_ERR(mvm, "0x%08X | branchlink2\n", table.blink2);
  567. IWL_ERR(mvm, "0x%08X | interruptlink1\n", table.ilink1);
  568. IWL_ERR(mvm, "0x%08X | interruptlink2\n", table.ilink2);
  569. IWL_ERR(mvm, "0x%08X | data1\n", table.data1);
  570. IWL_ERR(mvm, "0x%08X | data2\n", table.data2);
  571. IWL_ERR(mvm, "0x%08X | data3\n", table.data3);
  572. IWL_ERR(mvm, "0x%08X | beacon time\n", table.bcon_time);
  573. IWL_ERR(mvm, "0x%08X | tsf low\n", table.tsf_low);
  574. IWL_ERR(mvm, "0x%08X | tsf hi\n", table.tsf_hi);
  575. IWL_ERR(mvm, "0x%08X | time gp1\n", table.gp1);
  576. IWL_ERR(mvm, "0x%08X | time gp2\n", table.gp2);
  577. IWL_ERR(mvm, "0x%08X | time gp3\n", table.gp3);
  578. IWL_ERR(mvm, "0x%08X | uCode version major\n", table.major);
  579. IWL_ERR(mvm, "0x%08X | uCode version minor\n", table.minor);
  580. IWL_ERR(mvm, "0x%08X | hw version\n", table.hw_ver);
  581. IWL_ERR(mvm, "0x%08X | board version\n", table.brd_ver);
  582. IWL_ERR(mvm, "0x%08X | hcmd\n", table.hcmd);
  583. IWL_ERR(mvm, "0x%08X | isr0\n", table.isr0);
  584. IWL_ERR(mvm, "0x%08X | isr1\n", table.isr1);
  585. IWL_ERR(mvm, "0x%08X | isr2\n", table.isr2);
  586. IWL_ERR(mvm, "0x%08X | isr3\n", table.isr3);
  587. IWL_ERR(mvm, "0x%08X | isr4\n", table.isr4);
  588. IWL_ERR(mvm, "0x%08X | isr_pref\n", table.isr_pref);
  589. IWL_ERR(mvm, "0x%08X | wait_event\n", table.wait_event);
  590. IWL_ERR(mvm, "0x%08X | l2p_control\n", table.l2p_control);
  591. IWL_ERR(mvm, "0x%08X | l2p_duration\n", table.l2p_duration);
  592. IWL_ERR(mvm, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  593. IWL_ERR(mvm, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  594. IWL_ERR(mvm, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  595. IWL_ERR(mvm, "0x%08X | timestamp\n", table.u_timestamp);
  596. IWL_ERR(mvm, "0x%08X | flow_handler\n", table.flow_handler);
  597. if (mvm->support_umac_log)
  598. iwl_mvm_dump_umac_error_log(mvm);
  599. }
  600. void iwl_mvm_enable_txq(struct iwl_mvm *mvm, int queue, u16 ssn,
  601. const struct iwl_trans_txq_scd_cfg *cfg,
  602. unsigned int wdg_timeout)
  603. {
  604. struct iwl_scd_txq_cfg_cmd cmd = {
  605. .scd_queue = queue,
  606. .enable = 1,
  607. .window = cfg->frame_limit,
  608. .sta_id = cfg->sta_id,
  609. .ssn = cpu_to_le16(ssn),
  610. .tx_fifo = cfg->fifo,
  611. .aggregate = cfg->aggregate,
  612. .tid = cfg->tid,
  613. };
  614. if (!iwl_mvm_is_scd_cfg_supported(mvm)) {
  615. iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, cfg,
  616. wdg_timeout);
  617. return;
  618. }
  619. iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout);
  620. WARN(iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd),
  621. "Failed to configure queue %d on FIFO %d\n", queue, cfg->fifo);
  622. }
  623. void iwl_mvm_disable_txq(struct iwl_mvm *mvm, int queue, u8 flags)
  624. {
  625. struct iwl_scd_txq_cfg_cmd cmd = {
  626. .scd_queue = queue,
  627. .enable = 0,
  628. };
  629. int ret;
  630. if (!iwl_mvm_is_scd_cfg_supported(mvm)) {
  631. iwl_trans_txq_disable(mvm->trans, queue, true);
  632. return;
  633. }
  634. iwl_trans_txq_disable(mvm->trans, queue, false);
  635. ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, flags,
  636. sizeof(cmd), &cmd);
  637. if (ret)
  638. IWL_ERR(mvm, "Failed to disable queue %d (ret=%d)\n",
  639. queue, ret);
  640. }
  641. /**
  642. * iwl_mvm_send_lq_cmd() - Send link quality command
  643. * @init: This command is sent as part of station initialization right
  644. * after station has been added.
  645. *
  646. * The link quality command is sent as the last step of station creation.
  647. * This is the special case in which init is set and we call a callback in
  648. * this case to clear the state indicating that station creation is in
  649. * progress.
  650. */
  651. int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq, bool init)
  652. {
  653. struct iwl_host_cmd cmd = {
  654. .id = LQ_CMD,
  655. .len = { sizeof(struct iwl_lq_cmd), },
  656. .flags = init ? 0 : CMD_ASYNC,
  657. .data = { lq, },
  658. };
  659. if (WARN_ON(lq->sta_id == IWL_MVM_STATION_COUNT))
  660. return -EINVAL;
  661. return iwl_mvm_send_cmd(mvm, &cmd);
  662. }
  663. /**
  664. * iwl_mvm_update_smps - Get a request to change the SMPS mode
  665. * @req_type: The part of the driver who call for a change.
  666. * @smps_requests: The request to change the SMPS mode.
  667. *
  668. * Get a requst to change the SMPS mode,
  669. * and change it according to all other requests in the driver.
  670. */
  671. void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  672. enum iwl_mvm_smps_type_request req_type,
  673. enum ieee80211_smps_mode smps_request)
  674. {
  675. struct iwl_mvm_vif *mvmvif;
  676. enum ieee80211_smps_mode smps_mode;
  677. int i;
  678. lockdep_assert_held(&mvm->mutex);
  679. /* SMPS is irrelevant for NICs that don't have at least 2 RX antenna */
  680. if (num_of_ant(iwl_mvm_get_valid_rx_ant(mvm)) == 1)
  681. return;
  682. if (vif->type == NL80211_IFTYPE_AP)
  683. smps_mode = IEEE80211_SMPS_OFF;
  684. else
  685. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  686. mvmvif = iwl_mvm_vif_from_mac80211(vif);
  687. mvmvif->smps_requests[req_type] = smps_request;
  688. for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
  689. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC) {
  690. smps_mode = IEEE80211_SMPS_STATIC;
  691. break;
  692. }
  693. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
  694. smps_mode = IEEE80211_SMPS_DYNAMIC;
  695. }
  696. ieee80211_request_smps(vif, smps_mode);
  697. }
  698. int iwl_mvm_request_statistics(struct iwl_mvm *mvm, bool clear)
  699. {
  700. struct iwl_statistics_cmd scmd = {
  701. .flags = clear ? cpu_to_le32(IWL_STATISTICS_FLG_CLEAR) : 0,
  702. };
  703. struct iwl_host_cmd cmd = {
  704. .id = STATISTICS_CMD,
  705. .len[0] = sizeof(scmd),
  706. .data[0] = &scmd,
  707. .flags = CMD_WANT_SKB,
  708. };
  709. int ret;
  710. ret = iwl_mvm_send_cmd(mvm, &cmd);
  711. if (ret)
  712. return ret;
  713. iwl_mvm_handle_rx_statistics(mvm, cmd.resp_pkt);
  714. iwl_free_resp(&cmd);
  715. if (clear)
  716. iwl_mvm_accu_radio_stats(mvm);
  717. return 0;
  718. }
  719. void iwl_mvm_accu_radio_stats(struct iwl_mvm *mvm)
  720. {
  721. mvm->accu_radio_stats.rx_time += mvm->radio_stats.rx_time;
  722. mvm->accu_radio_stats.tx_time += mvm->radio_stats.tx_time;
  723. mvm->accu_radio_stats.on_time_rf += mvm->radio_stats.on_time_rf;
  724. mvm->accu_radio_stats.on_time_scan += mvm->radio_stats.on_time_scan;
  725. }
  726. static void iwl_mvm_diversity_iter(void *_data, u8 *mac,
  727. struct ieee80211_vif *vif)
  728. {
  729. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  730. bool *result = _data;
  731. int i;
  732. for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
  733. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC ||
  734. mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
  735. *result = false;
  736. }
  737. }
  738. bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm)
  739. {
  740. bool result = true;
  741. lockdep_assert_held(&mvm->mutex);
  742. if (num_of_ant(iwl_mvm_get_valid_rx_ant(mvm)) == 1)
  743. return false;
  744. if (mvm->cfg->rx_with_siso_diversity)
  745. return false;
  746. ieee80211_iterate_active_interfaces_atomic(
  747. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  748. iwl_mvm_diversity_iter, &result);
  749. return result;
  750. }
  751. int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  752. bool value)
  753. {
  754. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  755. int res;
  756. lockdep_assert_held(&mvm->mutex);
  757. if (mvmvif->low_latency == value)
  758. return 0;
  759. mvmvif->low_latency = value;
  760. res = iwl_mvm_update_quotas(mvm, false, NULL);
  761. if (res)
  762. return res;
  763. iwl_mvm_bt_coex_vif_change(mvm);
  764. return iwl_mvm_power_update_mac(mvm);
  765. }
  766. static void iwl_mvm_ll_iter(void *_data, u8 *mac, struct ieee80211_vif *vif)
  767. {
  768. bool *result = _data;
  769. if (iwl_mvm_vif_low_latency(iwl_mvm_vif_from_mac80211(vif)))
  770. *result = true;
  771. }
  772. bool iwl_mvm_low_latency(struct iwl_mvm *mvm)
  773. {
  774. bool result = false;
  775. ieee80211_iterate_active_interfaces_atomic(
  776. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  777. iwl_mvm_ll_iter, &result);
  778. return result;
  779. }
  780. struct iwl_bss_iter_data {
  781. struct ieee80211_vif *vif;
  782. bool error;
  783. };
  784. static void iwl_mvm_bss_iface_iterator(void *_data, u8 *mac,
  785. struct ieee80211_vif *vif)
  786. {
  787. struct iwl_bss_iter_data *data = _data;
  788. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  789. return;
  790. if (data->vif) {
  791. data->error = true;
  792. return;
  793. }
  794. data->vif = vif;
  795. }
  796. struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm)
  797. {
  798. struct iwl_bss_iter_data bss_iter_data = {};
  799. ieee80211_iterate_active_interfaces_atomic(
  800. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  801. iwl_mvm_bss_iface_iterator, &bss_iter_data);
  802. if (bss_iter_data.error) {
  803. IWL_ERR(mvm, "More than one managed interface active!\n");
  804. return ERR_PTR(-EINVAL);
  805. }
  806. return bss_iter_data.vif;
  807. }
  808. unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm,
  809. struct ieee80211_vif *vif,
  810. bool tdls, bool cmd_q)
  811. {
  812. struct iwl_fw_dbg_trigger_tlv *trigger;
  813. struct iwl_fw_dbg_trigger_txq_timer *txq_timer;
  814. unsigned int default_timeout =
  815. cmd_q ? IWL_DEF_WD_TIMEOUT : mvm->cfg->base_params->wd_timeout;
  816. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TXQ_TIMERS))
  817. return iwlmvm_mod_params.tfd_q_hang_detect ?
  818. default_timeout : IWL_WATCHDOG_DISABLED;
  819. trigger = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TXQ_TIMERS);
  820. txq_timer = (void *)trigger->data;
  821. if (tdls)
  822. return le32_to_cpu(txq_timer->tdls);
  823. if (cmd_q)
  824. return le32_to_cpu(txq_timer->command_queue);
  825. if (WARN_ON(!vif))
  826. return default_timeout;
  827. switch (ieee80211_vif_type_p2p(vif)) {
  828. case NL80211_IFTYPE_ADHOC:
  829. return le32_to_cpu(txq_timer->ibss);
  830. case NL80211_IFTYPE_STATION:
  831. return le32_to_cpu(txq_timer->bss);
  832. case NL80211_IFTYPE_AP:
  833. return le32_to_cpu(txq_timer->softap);
  834. case NL80211_IFTYPE_P2P_CLIENT:
  835. return le32_to_cpu(txq_timer->p2p_client);
  836. case NL80211_IFTYPE_P2P_GO:
  837. return le32_to_cpu(txq_timer->p2p_go);
  838. case NL80211_IFTYPE_P2P_DEVICE:
  839. return le32_to_cpu(txq_timer->p2p_device);
  840. default:
  841. WARN_ON(1);
  842. return mvm->cfg->base_params->wd_timeout;
  843. }
  844. }
  845. void iwl_mvm_connection_loss(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  846. const char *errmsg)
  847. {
  848. struct iwl_fw_dbg_trigger_tlv *trig;
  849. struct iwl_fw_dbg_trigger_mlme *trig_mlme;
  850. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
  851. goto out;
  852. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
  853. trig_mlme = (void *)trig->data;
  854. if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
  855. goto out;
  856. if (trig_mlme->stop_connection_loss &&
  857. --trig_mlme->stop_connection_loss)
  858. goto out;
  859. iwl_mvm_fw_dbg_collect_trig(mvm, trig, "%s", errmsg);
  860. out:
  861. ieee80211_connection_loss(vif);
  862. }