utils.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <net/mac80211.h>
  64. #include "iwl-debug.h"
  65. #include "iwl-io.h"
  66. #include "iwl-prph.h"
  67. #include "mvm.h"
  68. #include "fw-api-rs.h"
  69. /*
  70. * Will return 0 even if the cmd failed when RFKILL is asserted unless
  71. * CMD_WANT_SKB is set in cmd->flags.
  72. */
  73. int iwl_mvm_send_cmd(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd)
  74. {
  75. int ret;
  76. #if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
  77. if (WARN_ON(mvm->d3_test_active))
  78. return -EIO;
  79. #endif
  80. /*
  81. * Synchronous commands from this op-mode must hold
  82. * the mutex, this ensures we don't try to send two
  83. * (or more) synchronous commands at a time.
  84. */
  85. if (!(cmd->flags & CMD_ASYNC))
  86. lockdep_assert_held(&mvm->mutex);
  87. ret = iwl_trans_send_cmd(mvm->trans, cmd);
  88. /*
  89. * If the caller wants the SKB, then don't hide any problems, the
  90. * caller might access the response buffer which will be NULL if
  91. * the command failed.
  92. */
  93. if (cmd->flags & CMD_WANT_SKB)
  94. return ret;
  95. /* Silently ignore failures if RFKILL is asserted */
  96. if (!ret || ret == -ERFKILL)
  97. return 0;
  98. return ret;
  99. }
  100. int iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u8 id,
  101. u32 flags, u16 len, const void *data)
  102. {
  103. struct iwl_host_cmd cmd = {
  104. .id = id,
  105. .len = { len, },
  106. .data = { data, },
  107. .flags = flags,
  108. };
  109. return iwl_mvm_send_cmd(mvm, &cmd);
  110. }
  111. /*
  112. * We assume that the caller set the status to the sucess value
  113. */
  114. int iwl_mvm_send_cmd_status(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd,
  115. u32 *status)
  116. {
  117. struct iwl_rx_packet *pkt;
  118. struct iwl_cmd_response *resp;
  119. int ret, resp_len;
  120. lockdep_assert_held(&mvm->mutex);
  121. #if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
  122. if (WARN_ON(mvm->d3_test_active))
  123. return -EIO;
  124. #endif
  125. /*
  126. * Only synchronous commands can wait for status,
  127. * we use WANT_SKB so the caller can't.
  128. */
  129. if (WARN_ONCE(cmd->flags & (CMD_ASYNC | CMD_WANT_SKB),
  130. "cmd flags %x", cmd->flags))
  131. return -EINVAL;
  132. cmd->flags |= CMD_WANT_SKB;
  133. ret = iwl_trans_send_cmd(mvm->trans, cmd);
  134. if (ret == -ERFKILL) {
  135. /*
  136. * The command failed because of RFKILL, don't update
  137. * the status, leave it as success and return 0.
  138. */
  139. return 0;
  140. } else if (ret) {
  141. return ret;
  142. }
  143. pkt = cmd->resp_pkt;
  144. /* Can happen if RFKILL is asserted */
  145. if (!pkt) {
  146. ret = 0;
  147. goto out_free_resp;
  148. }
  149. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  150. ret = -EIO;
  151. goto out_free_resp;
  152. }
  153. resp_len = iwl_rx_packet_payload_len(pkt);
  154. if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
  155. ret = -EIO;
  156. goto out_free_resp;
  157. }
  158. resp = (void *)pkt->data;
  159. *status = le32_to_cpu(resp->status);
  160. out_free_resp:
  161. iwl_free_resp(cmd);
  162. return ret;
  163. }
  164. /*
  165. * We assume that the caller set the status to the sucess value
  166. */
  167. int iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u8 id, u16 len,
  168. const void *data, u32 *status)
  169. {
  170. struct iwl_host_cmd cmd = {
  171. .id = id,
  172. .len = { len, },
  173. .data = { data, },
  174. };
  175. return iwl_mvm_send_cmd_status(mvm, &cmd, status);
  176. }
  177. #define IWL_DECLARE_RATE_INFO(r) \
  178. [IWL_RATE_##r##M_INDEX] = IWL_RATE_##r##M_PLCP
  179. /*
  180. * Translate from fw_rate_index (IWL_RATE_XXM_INDEX) to PLCP
  181. */
  182. static const u8 fw_rate_idx_to_plcp[IWL_RATE_COUNT] = {
  183. IWL_DECLARE_RATE_INFO(1),
  184. IWL_DECLARE_RATE_INFO(2),
  185. IWL_DECLARE_RATE_INFO(5),
  186. IWL_DECLARE_RATE_INFO(11),
  187. IWL_DECLARE_RATE_INFO(6),
  188. IWL_DECLARE_RATE_INFO(9),
  189. IWL_DECLARE_RATE_INFO(12),
  190. IWL_DECLARE_RATE_INFO(18),
  191. IWL_DECLARE_RATE_INFO(24),
  192. IWL_DECLARE_RATE_INFO(36),
  193. IWL_DECLARE_RATE_INFO(48),
  194. IWL_DECLARE_RATE_INFO(54),
  195. };
  196. int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
  197. enum ieee80211_band band)
  198. {
  199. int rate = rate_n_flags & RATE_LEGACY_RATE_MSK;
  200. int idx;
  201. int band_offset = 0;
  202. /* Legacy rate format, search for match in table */
  203. if (band == IEEE80211_BAND_5GHZ)
  204. band_offset = IWL_FIRST_OFDM_RATE;
  205. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  206. if (fw_rate_idx_to_plcp[idx] == rate)
  207. return idx - band_offset;
  208. return -1;
  209. }
  210. u8 iwl_mvm_mac80211_idx_to_hwrate(int rate_idx)
  211. {
  212. /* Get PLCP rate for tx_cmd->rate_n_flags */
  213. return fw_rate_idx_to_plcp[rate_idx];
  214. }
  215. int iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
  216. struct iwl_device_cmd *cmd)
  217. {
  218. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  219. struct iwl_error_resp *err_resp = (void *)pkt->data;
  220. IWL_ERR(mvm, "FW Error notification: type 0x%08X cmd_id 0x%02X\n",
  221. le32_to_cpu(err_resp->error_type), err_resp->cmd_id);
  222. IWL_ERR(mvm, "FW Error notification: seq 0x%04X service 0x%08X\n",
  223. le16_to_cpu(err_resp->bad_cmd_seq_num),
  224. le32_to_cpu(err_resp->error_service));
  225. IWL_ERR(mvm, "FW Error notification: timestamp 0x%16llX\n",
  226. le64_to_cpu(err_resp->timestamp));
  227. return 0;
  228. }
  229. /*
  230. * Returns the first antenna as ANT_[ABC], as defined in iwl-config.h.
  231. * The parameter should also be a combination of ANT_[ABC].
  232. */
  233. u8 first_antenna(u8 mask)
  234. {
  235. BUILD_BUG_ON(ANT_A != BIT(0)); /* using ffs is wrong if not */
  236. if (WARN_ON_ONCE(!mask)) /* ffs will return 0 if mask is zeroed */
  237. return BIT(0);
  238. return BIT(ffs(mask) - 1);
  239. }
  240. /*
  241. * Toggles between TX antennas to send the probe request on.
  242. * Receives the bitmask of valid TX antennas and the *index* used
  243. * for the last TX, and returns the next valid *index* to use.
  244. * In order to set it in the tx_cmd, must do BIT(idx).
  245. */
  246. u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx)
  247. {
  248. u8 ind = last_idx;
  249. int i;
  250. for (i = 0; i < RATE_MCS_ANT_NUM; i++) {
  251. ind = (ind + 1) % RATE_MCS_ANT_NUM;
  252. if (valid & BIT(ind))
  253. return ind;
  254. }
  255. WARN_ONCE(1, "Failed to toggle between antennas 0x%x", valid);
  256. return last_idx;
  257. }
  258. static const struct {
  259. const char *name;
  260. u8 num;
  261. } advanced_lookup[] = {
  262. { "NMI_INTERRUPT_WDG", 0x34 },
  263. { "SYSASSERT", 0x35 },
  264. { "UCODE_VERSION_MISMATCH", 0x37 },
  265. { "BAD_COMMAND", 0x38 },
  266. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  267. { "FATAL_ERROR", 0x3D },
  268. { "NMI_TRM_HW_ERR", 0x46 },
  269. { "NMI_INTERRUPT_TRM", 0x4C },
  270. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  271. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  272. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  273. { "NMI_INTERRUPT_HOST", 0x66 },
  274. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  275. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  276. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  277. { "ADVANCED_SYSASSERT", 0 },
  278. };
  279. static const char *desc_lookup(u32 num)
  280. {
  281. int i;
  282. for (i = 0; i < ARRAY_SIZE(advanced_lookup) - 1; i++)
  283. if (advanced_lookup[i].num == num)
  284. return advanced_lookup[i].name;
  285. /* No entry matches 'num', so it is the last: ADVANCED_SYSASSERT */
  286. return advanced_lookup[i].name;
  287. }
  288. /*
  289. * Note: This structure is read from the device with IO accesses,
  290. * and the reading already does the endian conversion. As it is
  291. * read with u32-sized accesses, any members with a different size
  292. * need to be ordered correctly though!
  293. */
  294. struct iwl_error_event_table {
  295. u32 valid; /* (nonzero) valid, (0) log is empty */
  296. u32 error_id; /* type of error */
  297. u32 pc; /* program counter */
  298. u32 blink1; /* branch link */
  299. u32 blink2; /* branch link */
  300. u32 ilink1; /* interrupt link */
  301. u32 ilink2; /* interrupt link */
  302. u32 data1; /* error-specific data */
  303. u32 data2; /* error-specific data */
  304. u32 data3; /* error-specific data */
  305. u32 bcon_time; /* beacon timer */
  306. u32 tsf_low; /* network timestamp function timer */
  307. u32 tsf_hi; /* network timestamp function timer */
  308. u32 gp1; /* GP1 timer register */
  309. u32 gp2; /* GP2 timer register */
  310. u32 gp3; /* GP3 timer register */
  311. u32 ucode_ver; /* uCode version */
  312. u32 hw_ver; /* HW Silicon version */
  313. u32 brd_ver; /* HW board version */
  314. u32 log_pc; /* log program counter */
  315. u32 frame_ptr; /* frame pointer */
  316. u32 stack_ptr; /* stack pointer */
  317. u32 hcmd; /* last host command header */
  318. u32 isr0; /* isr status register LMPM_NIC_ISR0:
  319. * rxtx_flag */
  320. u32 isr1; /* isr status register LMPM_NIC_ISR1:
  321. * host_flag */
  322. u32 isr2; /* isr status register LMPM_NIC_ISR2:
  323. * enc_flag */
  324. u32 isr3; /* isr status register LMPM_NIC_ISR3:
  325. * time_flag */
  326. u32 isr4; /* isr status register LMPM_NIC_ISR4:
  327. * wico interrupt */
  328. u32 isr_pref; /* isr status register LMPM_NIC_PREF_STAT */
  329. u32 wait_event; /* wait event() caller address */
  330. u32 l2p_control; /* L2pControlField */
  331. u32 l2p_duration; /* L2pDurationField */
  332. u32 l2p_mhvalid; /* L2pMhValidBits */
  333. u32 l2p_addr_match; /* L2pAddrMatchStat */
  334. u32 lmpm_pmg_sel; /* indicate which clocks are turned on
  335. * (LMPM_PMG_SEL) */
  336. u32 u_timestamp; /* indicate when the date and time of the
  337. * compilation */
  338. u32 flow_handler; /* FH read/write pointers, RX credit */
  339. } __packed;
  340. /*
  341. * UMAC error struct - relevant starting from family 8000 chip.
  342. * Note: This structure is read from the device with IO accesses,
  343. * and the reading already does the endian conversion. As it is
  344. * read with u32-sized accesses, any members with a different size
  345. * need to be ordered correctly though!
  346. */
  347. struct iwl_umac_error_event_table {
  348. u32 valid; /* (nonzero) valid, (0) log is empty */
  349. u32 error_id; /* type of error */
  350. u32 pc; /* program counter */
  351. u32 blink1; /* branch link */
  352. u32 blink2; /* branch link */
  353. u32 ilink1; /* interrupt link */
  354. u32 ilink2; /* interrupt link */
  355. u32 data1; /* error-specific data */
  356. u32 data2; /* error-specific data */
  357. u32 line; /* source code line of error */
  358. u32 umac_ver; /* umac version */
  359. } __packed;
  360. #define ERROR_START_OFFSET (1 * sizeof(u32))
  361. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  362. static void iwl_mvm_dump_umac_error_log(struct iwl_mvm *mvm)
  363. {
  364. struct iwl_trans *trans = mvm->trans;
  365. struct iwl_umac_error_event_table table;
  366. u32 base;
  367. base = mvm->umac_error_event_table;
  368. if (base < 0x800000 || base >= 0x80C000) {
  369. IWL_ERR(mvm,
  370. "Not valid error log pointer 0x%08X for %s uCode\n",
  371. base,
  372. (mvm->cur_ucode == IWL_UCODE_INIT)
  373. ? "Init" : "RT");
  374. return;
  375. }
  376. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  377. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  378. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  379. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  380. mvm->status, table.valid);
  381. }
  382. IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
  383. desc_lookup(table.error_id));
  384. IWL_ERR(mvm, "0x%08X | umac uPc\n", table.pc);
  385. IWL_ERR(mvm, "0x%08X | umac branchlink1\n", table.blink1);
  386. IWL_ERR(mvm, "0x%08X | umac branchlink2\n", table.blink2);
  387. IWL_ERR(mvm, "0x%08X | umac interruptlink1\n", table.ilink1);
  388. IWL_ERR(mvm, "0x%08X | umac interruptlink2\n", table.ilink2);
  389. IWL_ERR(mvm, "0x%08X | umac data1\n", table.data1);
  390. IWL_ERR(mvm, "0x%08X | umac data2\n", table.data2);
  391. IWL_ERR(mvm, "0x%08X | umac version\n", table.umac_ver);
  392. }
  393. void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
  394. {
  395. struct iwl_trans *trans = mvm->trans;
  396. struct iwl_error_event_table table;
  397. u32 base;
  398. base = mvm->error_event_table;
  399. if (mvm->cur_ucode == IWL_UCODE_INIT) {
  400. if (!base)
  401. base = mvm->fw->init_errlog_ptr;
  402. } else {
  403. if (!base)
  404. base = mvm->fw->inst_errlog_ptr;
  405. }
  406. if (base < 0x800000) {
  407. IWL_ERR(mvm,
  408. "Not valid error log pointer 0x%08X for %s uCode\n",
  409. base,
  410. (mvm->cur_ucode == IWL_UCODE_INIT)
  411. ? "Init" : "RT");
  412. return;
  413. }
  414. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  415. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  416. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  417. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  418. mvm->status, table.valid);
  419. }
  420. /* Do not change this output - scripts rely on it */
  421. IWL_ERR(mvm, "Loaded firmware version: %s\n", mvm->fw->fw_version);
  422. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  423. table.data1, table.data2, table.data3,
  424. table.blink1, table.blink2, table.ilink1,
  425. table.ilink2, table.bcon_time, table.gp1,
  426. table.gp2, table.gp3, table.ucode_ver,
  427. table.hw_ver, table.brd_ver);
  428. IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
  429. desc_lookup(table.error_id));
  430. IWL_ERR(mvm, "0x%08X | uPc\n", table.pc);
  431. IWL_ERR(mvm, "0x%08X | branchlink1\n", table.blink1);
  432. IWL_ERR(mvm, "0x%08X | branchlink2\n", table.blink2);
  433. IWL_ERR(mvm, "0x%08X | interruptlink1\n", table.ilink1);
  434. IWL_ERR(mvm, "0x%08X | interruptlink2\n", table.ilink2);
  435. IWL_ERR(mvm, "0x%08X | data1\n", table.data1);
  436. IWL_ERR(mvm, "0x%08X | data2\n", table.data2);
  437. IWL_ERR(mvm, "0x%08X | data3\n", table.data3);
  438. IWL_ERR(mvm, "0x%08X | beacon time\n", table.bcon_time);
  439. IWL_ERR(mvm, "0x%08X | tsf low\n", table.tsf_low);
  440. IWL_ERR(mvm, "0x%08X | tsf hi\n", table.tsf_hi);
  441. IWL_ERR(mvm, "0x%08X | time gp1\n", table.gp1);
  442. IWL_ERR(mvm, "0x%08X | time gp2\n", table.gp2);
  443. IWL_ERR(mvm, "0x%08X | time gp3\n", table.gp3);
  444. IWL_ERR(mvm, "0x%08X | uCode version\n", table.ucode_ver);
  445. IWL_ERR(mvm, "0x%08X | hw version\n", table.hw_ver);
  446. IWL_ERR(mvm, "0x%08X | board version\n", table.brd_ver);
  447. IWL_ERR(mvm, "0x%08X | hcmd\n", table.hcmd);
  448. IWL_ERR(mvm, "0x%08X | isr0\n", table.isr0);
  449. IWL_ERR(mvm, "0x%08X | isr1\n", table.isr1);
  450. IWL_ERR(mvm, "0x%08X | isr2\n", table.isr2);
  451. IWL_ERR(mvm, "0x%08X | isr3\n", table.isr3);
  452. IWL_ERR(mvm, "0x%08X | isr4\n", table.isr4);
  453. IWL_ERR(mvm, "0x%08X | isr_pref\n", table.isr_pref);
  454. IWL_ERR(mvm, "0x%08X | wait_event\n", table.wait_event);
  455. IWL_ERR(mvm, "0x%08X | l2p_control\n", table.l2p_control);
  456. IWL_ERR(mvm, "0x%08X | l2p_duration\n", table.l2p_duration);
  457. IWL_ERR(mvm, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  458. IWL_ERR(mvm, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  459. IWL_ERR(mvm, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  460. IWL_ERR(mvm, "0x%08X | timestamp\n", table.u_timestamp);
  461. IWL_ERR(mvm, "0x%08X | flow_handler\n", table.flow_handler);
  462. if (mvm->support_umac_log)
  463. iwl_mvm_dump_umac_error_log(mvm);
  464. }
  465. #ifdef CONFIG_IWLWIFI_DEBUGFS
  466. void iwl_mvm_fw_error_sram_dump(struct iwl_mvm *mvm)
  467. {
  468. const struct fw_img *img;
  469. u32 ofs, sram_len;
  470. void *sram;
  471. if (!mvm->ucode_loaded || mvm->fw_error_sram || mvm->fw_error_dump)
  472. return;
  473. img = &mvm->fw->img[mvm->cur_ucode];
  474. ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  475. sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  476. sram = kzalloc(sram_len, GFP_ATOMIC);
  477. if (!sram)
  478. return;
  479. iwl_trans_read_mem_bytes(mvm->trans, ofs, sram, sram_len);
  480. mvm->fw_error_sram = sram;
  481. mvm->fw_error_sram_len = sram_len;
  482. }
  483. void iwl_mvm_fw_error_rxf_dump(struct iwl_mvm *mvm)
  484. {
  485. int i, reg_val;
  486. unsigned long flags;
  487. if (!mvm->ucode_loaded || mvm->fw_error_rxf || mvm->fw_error_dump)
  488. return;
  489. /* reading buffer size */
  490. reg_val = iwl_trans_read_prph(mvm->trans, RXF_SIZE_ADDR);
  491. mvm->fw_error_rxf_len =
  492. (reg_val & RXF_SIZE_BYTE_CNT_MSK) >> RXF_SIZE_BYTE_CND_POS;
  493. /* the register holds the value divided by 128 */
  494. mvm->fw_error_rxf_len = mvm->fw_error_rxf_len << 7;
  495. if (!mvm->fw_error_rxf_len)
  496. return;
  497. mvm->fw_error_rxf = kzalloc(mvm->fw_error_rxf_len, GFP_ATOMIC);
  498. if (!mvm->fw_error_rxf) {
  499. mvm->fw_error_rxf_len = 0;
  500. return;
  501. }
  502. if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags)) {
  503. kfree(mvm->fw_error_rxf);
  504. mvm->fw_error_rxf = NULL;
  505. mvm->fw_error_rxf_len = 0;
  506. return;
  507. }
  508. for (i = 0; i < (mvm->fw_error_rxf_len / sizeof(u32)); i++) {
  509. iwl_trans_write_prph(mvm->trans, RXF_LD_FENCE_OFFSET_ADDR,
  510. i * sizeof(u32));
  511. mvm->fw_error_rxf[i] =
  512. iwl_trans_read_prph(mvm->trans, RXF_FIFO_RD_FENCE_ADDR);
  513. }
  514. iwl_trans_release_nic_access(mvm->trans, &flags);
  515. }
  516. #endif
  517. /**
  518. * iwl_mvm_send_lq_cmd() - Send link quality command
  519. * @init: This command is sent as part of station initialization right
  520. * after station has been added.
  521. *
  522. * The link quality command is sent as the last step of station creation.
  523. * This is the special case in which init is set and we call a callback in
  524. * this case to clear the state indicating that station creation is in
  525. * progress.
  526. */
  527. int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq, bool init)
  528. {
  529. struct iwl_host_cmd cmd = {
  530. .id = LQ_CMD,
  531. .len = { sizeof(struct iwl_lq_cmd), },
  532. .flags = init ? 0 : CMD_ASYNC,
  533. .data = { lq, },
  534. };
  535. if (WARN_ON(lq->sta_id == IWL_MVM_STATION_COUNT))
  536. return -EINVAL;
  537. return iwl_mvm_send_cmd(mvm, &cmd);
  538. }
  539. /**
  540. * iwl_mvm_update_smps - Get a requst to change the SMPS mode
  541. * @req_type: The part of the driver who call for a change.
  542. * @smps_requests: The request to change the SMPS mode.
  543. *
  544. * Get a requst to change the SMPS mode,
  545. * and change it according to all other requests in the driver.
  546. */
  547. void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  548. enum iwl_mvm_smps_type_request req_type,
  549. enum ieee80211_smps_mode smps_request)
  550. {
  551. struct iwl_mvm_vif *mvmvif;
  552. enum ieee80211_smps_mode smps_mode;
  553. int i;
  554. lockdep_assert_held(&mvm->mutex);
  555. /* SMPS is irrelevant for NICs that don't have at least 2 RX antenna */
  556. if (num_of_ant(mvm->fw->valid_rx_ant) == 1)
  557. return;
  558. if (vif->type == NL80211_IFTYPE_AP)
  559. smps_mode = IEEE80211_SMPS_OFF;
  560. else
  561. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  562. mvmvif = iwl_mvm_vif_from_mac80211(vif);
  563. mvmvif->smps_requests[req_type] = smps_request;
  564. for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
  565. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC) {
  566. smps_mode = IEEE80211_SMPS_STATIC;
  567. break;
  568. }
  569. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
  570. smps_mode = IEEE80211_SMPS_DYNAMIC;
  571. }
  572. ieee80211_request_smps(vif, smps_mode);
  573. }
  574. static void iwl_mvm_diversity_iter(void *_data, u8 *mac,
  575. struct ieee80211_vif *vif)
  576. {
  577. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  578. bool *result = _data;
  579. int i;
  580. for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
  581. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC ||
  582. mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
  583. *result = false;
  584. }
  585. }
  586. bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm)
  587. {
  588. bool result = true;
  589. lockdep_assert_held(&mvm->mutex);
  590. if (num_of_ant(mvm->fw->valid_rx_ant) == 1)
  591. return false;
  592. if (!mvm->cfg->rx_with_siso_diversity)
  593. return false;
  594. ieee80211_iterate_active_interfaces_atomic(
  595. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  596. iwl_mvm_diversity_iter, &result);
  597. return result;
  598. }
  599. int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  600. bool value)
  601. {
  602. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  603. int res;
  604. lockdep_assert_held(&mvm->mutex);
  605. if (mvmvif->low_latency == value)
  606. return 0;
  607. mvmvif->low_latency = value;
  608. res = iwl_mvm_update_quotas(mvm, NULL);
  609. if (res)
  610. return res;
  611. iwl_mvm_bt_coex_vif_change(mvm);
  612. return iwl_mvm_power_update_mac(mvm);
  613. }
  614. static void iwl_mvm_ll_iter(void *_data, u8 *mac, struct ieee80211_vif *vif)
  615. {
  616. bool *result = _data;
  617. if (iwl_mvm_vif_low_latency(iwl_mvm_vif_from_mac80211(vif)))
  618. *result = true;
  619. }
  620. bool iwl_mvm_low_latency(struct iwl_mvm *mvm)
  621. {
  622. bool result = false;
  623. ieee80211_iterate_active_interfaces_atomic(
  624. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  625. iwl_mvm_ll_iter, &result);
  626. return result;
  627. }
  628. static void iwl_mvm_idle_iter(void *_data, u8 *mac, struct ieee80211_vif *vif)
  629. {
  630. bool *idle = _data;
  631. if (!vif->bss_conf.idle)
  632. *idle = false;
  633. }
  634. bool iwl_mvm_is_idle(struct iwl_mvm *mvm)
  635. {
  636. bool idle = true;
  637. ieee80211_iterate_active_interfaces_atomic(
  638. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  639. iwl_mvm_idle_iter, &idle);
  640. return idle;
  641. }