utils.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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 sucess 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 {
  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;
  342. /*
  343. * UMAC error struct - relevant starting from family 8000 chip.
  344. * Note: This structure is read from the device with IO accesses,
  345. * and the reading already does the endian conversion. As it is
  346. * read with u32-sized accesses, any members with a different size
  347. * need to be ordered correctly though!
  348. */
  349. struct iwl_umac_error_event_table {
  350. u32 valid; /* (nonzero) valid, (0) log is empty */
  351. u32 error_id; /* type of error */
  352. u32 blink1; /* branch link */
  353. u32 blink2; /* branch link */
  354. u32 ilink1; /* interrupt link */
  355. u32 ilink2; /* interrupt link */
  356. u32 data1; /* error-specific data */
  357. u32 data2; /* error-specific data */
  358. u32 data3; /* error-specific data */
  359. u32 umac_fw_ver; /* UMAC version */
  360. u32 umac_fw_api_ver; /* UMAC FW API ver */
  361. u32 frame_pointer; /* core register 27*/
  362. u32 stack_pointer; /* core register 28 */
  363. u32 cmd_header; /* latest host cmd sent to UMAC */
  364. u32 nic_isr_pref; /* ISR status register */
  365. } __packed;
  366. #define ERROR_START_OFFSET (1 * sizeof(u32))
  367. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  368. static void iwl_mvm_dump_umac_error_log(struct iwl_mvm *mvm)
  369. {
  370. struct iwl_trans *trans = mvm->trans;
  371. struct iwl_umac_error_event_table table;
  372. u32 base;
  373. base = mvm->umac_error_event_table;
  374. if (base < 0x800000) {
  375. IWL_ERR(mvm,
  376. "Not valid error log pointer 0x%08X for %s uCode\n",
  377. base,
  378. (mvm->cur_ucode == IWL_UCODE_INIT)
  379. ? "Init" : "RT");
  380. return;
  381. }
  382. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  383. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  384. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  385. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  386. mvm->status, table.valid);
  387. }
  388. IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
  389. desc_lookup(table.error_id));
  390. IWL_ERR(mvm, "0x%08X | umac branchlink1\n", table.blink1);
  391. IWL_ERR(mvm, "0x%08X | umac branchlink2\n", table.blink2);
  392. IWL_ERR(mvm, "0x%08X | umac interruptlink1\n", table.ilink1);
  393. IWL_ERR(mvm, "0x%08X | umac interruptlink2\n", table.ilink2);
  394. IWL_ERR(mvm, "0x%08X | umac data1\n", table.data1);
  395. IWL_ERR(mvm, "0x%08X | umac data2\n", table.data2);
  396. IWL_ERR(mvm, "0x%08X | umac data3\n", table.data3);
  397. IWL_ERR(mvm, "0x%08X | umac version\n", table.umac_fw_ver);
  398. IWL_ERR(mvm, "0x%08X | umac api version\n", table.umac_fw_api_ver);
  399. IWL_ERR(mvm, "0x%08X | frame pointer\n", table.frame_pointer);
  400. IWL_ERR(mvm, "0x%08X | stack pointer\n", table.stack_pointer);
  401. IWL_ERR(mvm, "0x%08X | last host cmd\n", table.cmd_header);
  402. IWL_ERR(mvm, "0x%08X | isr status reg\n", table.nic_isr_pref);
  403. }
  404. void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
  405. {
  406. struct iwl_trans *trans = mvm->trans;
  407. struct iwl_error_event_table table;
  408. u32 base;
  409. base = mvm->error_event_table;
  410. if (mvm->cur_ucode == IWL_UCODE_INIT) {
  411. if (!base)
  412. base = mvm->fw->init_errlog_ptr;
  413. } else {
  414. if (!base)
  415. base = mvm->fw->inst_errlog_ptr;
  416. }
  417. if (base < 0x800000) {
  418. IWL_ERR(mvm,
  419. "Not valid error log pointer 0x%08X for %s uCode\n",
  420. base,
  421. (mvm->cur_ucode == IWL_UCODE_INIT)
  422. ? "Init" : "RT");
  423. return;
  424. }
  425. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  426. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  427. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  428. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  429. mvm->status, table.valid);
  430. }
  431. /* Do not change this output - scripts rely on it */
  432. IWL_ERR(mvm, "Loaded firmware version: %s\n", mvm->fw->fw_version);
  433. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  434. table.data1, table.data2, table.data3,
  435. table.blink1, table.blink2, table.ilink1,
  436. table.ilink2, table.bcon_time, table.gp1,
  437. table.gp2, table.gp3, table.ucode_ver,
  438. table.hw_ver, table.brd_ver);
  439. IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
  440. desc_lookup(table.error_id));
  441. IWL_ERR(mvm, "0x%08X | uPc\n", table.pc);
  442. IWL_ERR(mvm, "0x%08X | branchlink1\n", table.blink1);
  443. IWL_ERR(mvm, "0x%08X | branchlink2\n", table.blink2);
  444. IWL_ERR(mvm, "0x%08X | interruptlink1\n", table.ilink1);
  445. IWL_ERR(mvm, "0x%08X | interruptlink2\n", table.ilink2);
  446. IWL_ERR(mvm, "0x%08X | data1\n", table.data1);
  447. IWL_ERR(mvm, "0x%08X | data2\n", table.data2);
  448. IWL_ERR(mvm, "0x%08X | data3\n", table.data3);
  449. IWL_ERR(mvm, "0x%08X | beacon time\n", table.bcon_time);
  450. IWL_ERR(mvm, "0x%08X | tsf low\n", table.tsf_low);
  451. IWL_ERR(mvm, "0x%08X | tsf hi\n", table.tsf_hi);
  452. IWL_ERR(mvm, "0x%08X | time gp1\n", table.gp1);
  453. IWL_ERR(mvm, "0x%08X | time gp2\n", table.gp2);
  454. IWL_ERR(mvm, "0x%08X | time gp3\n", table.gp3);
  455. IWL_ERR(mvm, "0x%08X | uCode version\n", table.ucode_ver);
  456. IWL_ERR(mvm, "0x%08X | hw version\n", table.hw_ver);
  457. IWL_ERR(mvm, "0x%08X | board version\n", table.brd_ver);
  458. IWL_ERR(mvm, "0x%08X | hcmd\n", table.hcmd);
  459. IWL_ERR(mvm, "0x%08X | isr0\n", table.isr0);
  460. IWL_ERR(mvm, "0x%08X | isr1\n", table.isr1);
  461. IWL_ERR(mvm, "0x%08X | isr2\n", table.isr2);
  462. IWL_ERR(mvm, "0x%08X | isr3\n", table.isr3);
  463. IWL_ERR(mvm, "0x%08X | isr4\n", table.isr4);
  464. IWL_ERR(mvm, "0x%08X | isr_pref\n", table.isr_pref);
  465. IWL_ERR(mvm, "0x%08X | wait_event\n", table.wait_event);
  466. IWL_ERR(mvm, "0x%08X | l2p_control\n", table.l2p_control);
  467. IWL_ERR(mvm, "0x%08X | l2p_duration\n", table.l2p_duration);
  468. IWL_ERR(mvm, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  469. IWL_ERR(mvm, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  470. IWL_ERR(mvm, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  471. IWL_ERR(mvm, "0x%08X | timestamp\n", table.u_timestamp);
  472. IWL_ERR(mvm, "0x%08X | flow_handler\n", table.flow_handler);
  473. if (mvm->support_umac_log)
  474. iwl_mvm_dump_umac_error_log(mvm);
  475. }
  476. void iwl_mvm_enable_txq(struct iwl_mvm *mvm, int queue, u16 ssn,
  477. const struct iwl_trans_txq_scd_cfg *cfg)
  478. {
  479. if (iwl_mvm_is_dqa_supported(mvm)) {
  480. struct iwl_scd_txq_cfg_cmd cmd = {
  481. .scd_queue = queue,
  482. .enable = 1,
  483. .window = cfg->frame_limit,
  484. .sta_id = cfg->sta_id,
  485. .ssn = cpu_to_le16(ssn),
  486. .tx_fifo = cfg->fifo,
  487. .aggregate = cfg->aggregate,
  488. .flags = IWL_SCD_FLAGS_DQA_ENABLED,
  489. .tid = cfg->tid,
  490. .control = IWL_SCD_CONTROL_SET_SSN,
  491. };
  492. int ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0,
  493. sizeof(cmd), &cmd);
  494. if (ret)
  495. IWL_ERR(mvm,
  496. "Failed to configure queue %d on FIFO %d\n",
  497. queue, cfg->fifo);
  498. }
  499. iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn,
  500. iwl_mvm_is_dqa_supported(mvm) ? NULL : cfg);
  501. }
  502. void iwl_mvm_disable_txq(struct iwl_mvm *mvm, int queue)
  503. {
  504. iwl_trans_txq_disable(mvm->trans, queue,
  505. !iwl_mvm_is_dqa_supported(mvm));
  506. if (iwl_mvm_is_dqa_supported(mvm)) {
  507. struct iwl_scd_txq_cfg_cmd cmd = {
  508. .scd_queue = queue,
  509. .enable = 0,
  510. };
  511. int ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, CMD_ASYNC,
  512. sizeof(cmd), &cmd);
  513. if (ret)
  514. IWL_ERR(mvm, "Failed to disable queue %d (ret=%d)\n",
  515. queue, ret);
  516. }
  517. }
  518. /**
  519. * iwl_mvm_send_lq_cmd() - Send link quality command
  520. * @init: This command is sent as part of station initialization right
  521. * after station has been added.
  522. *
  523. * The link quality command is sent as the last step of station creation.
  524. * This is the special case in which init is set and we call a callback in
  525. * this case to clear the state indicating that station creation is in
  526. * progress.
  527. */
  528. int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq, bool init)
  529. {
  530. struct iwl_host_cmd cmd = {
  531. .id = LQ_CMD,
  532. .len = { sizeof(struct iwl_lq_cmd), },
  533. .flags = init ? 0 : CMD_ASYNC,
  534. .data = { lq, },
  535. };
  536. if (WARN_ON(lq->sta_id == IWL_MVM_STATION_COUNT))
  537. return -EINVAL;
  538. return iwl_mvm_send_cmd(mvm, &cmd);
  539. }
  540. /**
  541. * iwl_mvm_update_smps - Get a requst to change the SMPS mode
  542. * @req_type: The part of the driver who call for a change.
  543. * @smps_requests: The request to change the SMPS mode.
  544. *
  545. * Get a requst to change the SMPS mode,
  546. * and change it according to all other requests in the driver.
  547. */
  548. void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  549. enum iwl_mvm_smps_type_request req_type,
  550. enum ieee80211_smps_mode smps_request)
  551. {
  552. struct iwl_mvm_vif *mvmvif;
  553. enum ieee80211_smps_mode smps_mode;
  554. int i;
  555. lockdep_assert_held(&mvm->mutex);
  556. /* SMPS is irrelevant for NICs that don't have at least 2 RX antenna */
  557. if (num_of_ant(mvm->fw->valid_rx_ant) == 1)
  558. return;
  559. if (vif->type == NL80211_IFTYPE_AP)
  560. smps_mode = IEEE80211_SMPS_OFF;
  561. else
  562. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  563. mvmvif = iwl_mvm_vif_from_mac80211(vif);
  564. mvmvif->smps_requests[req_type] = smps_request;
  565. for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
  566. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC) {
  567. smps_mode = IEEE80211_SMPS_STATIC;
  568. break;
  569. }
  570. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
  571. smps_mode = IEEE80211_SMPS_DYNAMIC;
  572. }
  573. ieee80211_request_smps(vif, smps_mode);
  574. }
  575. static void iwl_mvm_diversity_iter(void *_data, u8 *mac,
  576. struct ieee80211_vif *vif)
  577. {
  578. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  579. bool *result = _data;
  580. int i;
  581. for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
  582. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC ||
  583. mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
  584. *result = false;
  585. }
  586. }
  587. bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm)
  588. {
  589. bool result = true;
  590. lockdep_assert_held(&mvm->mutex);
  591. if (num_of_ant(mvm->fw->valid_rx_ant) == 1)
  592. return false;
  593. if (!mvm->cfg->rx_with_siso_diversity)
  594. return false;
  595. ieee80211_iterate_active_interfaces_atomic(
  596. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  597. iwl_mvm_diversity_iter, &result);
  598. return result;
  599. }
  600. int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  601. bool value)
  602. {
  603. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  604. int res;
  605. lockdep_assert_held(&mvm->mutex);
  606. if (mvmvif->low_latency == value)
  607. return 0;
  608. mvmvif->low_latency = value;
  609. res = iwl_mvm_update_quotas(mvm, NULL);
  610. if (res)
  611. return res;
  612. iwl_mvm_bt_coex_vif_change(mvm);
  613. return iwl_mvm_power_update_mac(mvm);
  614. }
  615. static void iwl_mvm_ll_iter(void *_data, u8 *mac, struct ieee80211_vif *vif)
  616. {
  617. bool *result = _data;
  618. if (iwl_mvm_vif_low_latency(iwl_mvm_vif_from_mac80211(vif)))
  619. *result = true;
  620. }
  621. bool iwl_mvm_low_latency(struct iwl_mvm *mvm)
  622. {
  623. bool result = false;
  624. ieee80211_iterate_active_interfaces_atomic(
  625. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  626. iwl_mvm_ll_iter, &result);
  627. return result;
  628. }
  629. static void iwl_mvm_idle_iter(void *_data, u8 *mac, struct ieee80211_vif *vif)
  630. {
  631. bool *idle = _data;
  632. if (!vif->bss_conf.idle)
  633. *idle = false;
  634. }
  635. bool iwl_mvm_is_idle(struct iwl_mvm *mvm)
  636. {
  637. bool idle = true;
  638. ieee80211_iterate_active_interfaces_atomic(
  639. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  640. iwl_mvm_idle_iter, &idle);
  641. return idle;
  642. }
  643. struct iwl_bss_iter_data {
  644. struct ieee80211_vif *vif;
  645. bool error;
  646. };
  647. static void iwl_mvm_bss_iface_iterator(void *_data, u8 *mac,
  648. struct ieee80211_vif *vif)
  649. {
  650. struct iwl_bss_iter_data *data = _data;
  651. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  652. return;
  653. if (data->vif) {
  654. data->error = true;
  655. return;
  656. }
  657. data->vif = vif;
  658. }
  659. struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm)
  660. {
  661. struct iwl_bss_iter_data bss_iter_data = {};
  662. ieee80211_iterate_active_interfaces_atomic(
  663. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  664. iwl_mvm_bss_iface_iterator, &bss_iter_data);
  665. if (bss_iter_data.error) {
  666. IWL_ERR(mvm, "More than one managed interface active!\n");
  667. return ERR_PTR(-EINVAL);
  668. }
  669. return bss_iter_data.vif;
  670. }