utils.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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 - 2013 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 - 2013 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 "mvm.h"
  67. #include "fw-api-rs.h"
  68. /*
  69. * Will return 0 even if the cmd failed when RFKILL is asserted unless
  70. * CMD_WANT_SKB is set in cmd->flags.
  71. */
  72. int iwl_mvm_send_cmd(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd)
  73. {
  74. int ret;
  75. #if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
  76. if (WARN_ON(mvm->d3_test_active))
  77. return -EIO;
  78. #endif
  79. /*
  80. * Synchronous commands from this op-mode must hold
  81. * the mutex, this ensures we don't try to send two
  82. * (or more) synchronous commands at a time.
  83. */
  84. if (!(cmd->flags & CMD_ASYNC))
  85. lockdep_assert_held(&mvm->mutex);
  86. ret = iwl_trans_send_cmd(mvm->trans, cmd);
  87. /*
  88. * If the caller wants the SKB, then don't hide any problems, the
  89. * caller might access the response buffer which will be NULL if
  90. * the command failed.
  91. */
  92. if (cmd->flags & CMD_WANT_SKB)
  93. return ret;
  94. /* Silently ignore failures if RFKILL is asserted */
  95. if (!ret || ret == -ERFKILL)
  96. return 0;
  97. return ret;
  98. }
  99. int iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u8 id,
  100. u32 flags, u16 len, const void *data)
  101. {
  102. struct iwl_host_cmd cmd = {
  103. .id = id,
  104. .len = { len, },
  105. .data = { data, },
  106. .flags = flags,
  107. };
  108. return iwl_mvm_send_cmd(mvm, &cmd);
  109. }
  110. /*
  111. * We assume that the caller set the status to the sucess value
  112. */
  113. int iwl_mvm_send_cmd_status(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd,
  114. u32 *status)
  115. {
  116. struct iwl_rx_packet *pkt;
  117. struct iwl_cmd_response *resp;
  118. int ret, resp_len;
  119. lockdep_assert_held(&mvm->mutex);
  120. #if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
  121. if (WARN_ON(mvm->d3_test_active))
  122. return -EIO;
  123. #endif
  124. /*
  125. * Only synchronous commands can wait for status,
  126. * we use WANT_SKB so the caller can't.
  127. */
  128. if (WARN_ONCE(cmd->flags & (CMD_ASYNC | CMD_WANT_SKB),
  129. "cmd flags %x", cmd->flags))
  130. return -EINVAL;
  131. cmd->flags |= CMD_SYNC | CMD_WANT_SKB;
  132. ret = iwl_trans_send_cmd(mvm->trans, cmd);
  133. if (ret == -ERFKILL) {
  134. /*
  135. * The command failed because of RFKILL, don't update
  136. * the status, leave it as success and return 0.
  137. */
  138. return 0;
  139. } else if (ret) {
  140. return ret;
  141. }
  142. pkt = cmd->resp_pkt;
  143. /* Can happen if RFKILL is asserted */
  144. if (!pkt) {
  145. ret = 0;
  146. goto out_free_resp;
  147. }
  148. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  149. ret = -EIO;
  150. goto out_free_resp;
  151. }
  152. resp_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  153. if (WARN_ON_ONCE(resp_len != sizeof(pkt->hdr) + sizeof(*resp))) {
  154. ret = -EIO;
  155. goto out_free_resp;
  156. }
  157. resp = (void *)pkt->data;
  158. *status = le32_to_cpu(resp->status);
  159. out_free_resp:
  160. iwl_free_resp(cmd);
  161. return ret;
  162. }
  163. /*
  164. * We assume that the caller set the status to the sucess value
  165. */
  166. int iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u8 id, u16 len,
  167. const void *data, u32 *status)
  168. {
  169. struct iwl_host_cmd cmd = {
  170. .id = id,
  171. .len = { len, },
  172. .data = { data, },
  173. };
  174. return iwl_mvm_send_cmd_status(mvm, &cmd, status);
  175. }
  176. #define IWL_DECLARE_RATE_INFO(r) \
  177. [IWL_RATE_##r##M_INDEX] = IWL_RATE_##r##M_PLCP
  178. /*
  179. * Translate from fw_rate_index (IWL_RATE_XXM_INDEX) to PLCP
  180. */
  181. static const u8 fw_rate_idx_to_plcp[IWL_RATE_COUNT] = {
  182. IWL_DECLARE_RATE_INFO(1),
  183. IWL_DECLARE_RATE_INFO(2),
  184. IWL_DECLARE_RATE_INFO(5),
  185. IWL_DECLARE_RATE_INFO(11),
  186. IWL_DECLARE_RATE_INFO(6),
  187. IWL_DECLARE_RATE_INFO(9),
  188. IWL_DECLARE_RATE_INFO(12),
  189. IWL_DECLARE_RATE_INFO(18),
  190. IWL_DECLARE_RATE_INFO(24),
  191. IWL_DECLARE_RATE_INFO(36),
  192. IWL_DECLARE_RATE_INFO(48),
  193. IWL_DECLARE_RATE_INFO(54),
  194. };
  195. int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
  196. enum ieee80211_band band)
  197. {
  198. int rate = rate_n_flags & RATE_LEGACY_RATE_MSK;
  199. int idx;
  200. int band_offset = 0;
  201. /* Legacy rate format, search for match in table */
  202. if (band == IEEE80211_BAND_5GHZ)
  203. band_offset = IWL_FIRST_OFDM_RATE;
  204. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  205. if (fw_rate_idx_to_plcp[idx] == rate)
  206. return idx - band_offset;
  207. return -1;
  208. }
  209. u8 iwl_mvm_mac80211_idx_to_hwrate(int rate_idx)
  210. {
  211. /* Get PLCP rate for tx_cmd->rate_n_flags */
  212. return fw_rate_idx_to_plcp[rate_idx];
  213. }
  214. int iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
  215. struct iwl_device_cmd *cmd)
  216. {
  217. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  218. struct iwl_error_resp *err_resp = (void *)pkt->data;
  219. IWL_ERR(mvm, "FW Error notification: type 0x%08X cmd_id 0x%02X\n",
  220. le32_to_cpu(err_resp->error_type), err_resp->cmd_id);
  221. IWL_ERR(mvm, "FW Error notification: seq 0x%04X service 0x%08X\n",
  222. le16_to_cpu(err_resp->bad_cmd_seq_num),
  223. le32_to_cpu(err_resp->error_service));
  224. IWL_ERR(mvm, "FW Error notification: timestamp 0x%16llX\n",
  225. le64_to_cpu(err_resp->timestamp));
  226. return 0;
  227. }
  228. /*
  229. * Returns the first antenna as ANT_[ABC], as defined in iwl-config.h.
  230. * The parameter should also be a combination of ANT_[ABC].
  231. */
  232. u8 first_antenna(u8 mask)
  233. {
  234. BUILD_BUG_ON(ANT_A != BIT(0)); /* using ffs is wrong if not */
  235. if (WARN_ON_ONCE(!mask)) /* ffs will return 0 if mask is zeroed */
  236. return BIT(0);
  237. return BIT(ffs(mask) - 1);
  238. }
  239. /*
  240. * Toggles between TX antennas to send the probe request on.
  241. * Receives the bitmask of valid TX antennas and the *index* used
  242. * for the last TX, and returns the next valid *index* to use.
  243. * In order to set it in the tx_cmd, must do BIT(idx).
  244. */
  245. u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx)
  246. {
  247. u8 ind = last_idx;
  248. int i;
  249. for (i = 0; i < RATE_MCS_ANT_NUM; i++) {
  250. ind = (ind + 1) % RATE_MCS_ANT_NUM;
  251. if (valid & BIT(ind))
  252. return ind;
  253. }
  254. WARN_ONCE(1, "Failed to toggle between antennas 0x%x", valid);
  255. return last_idx;
  256. }
  257. static struct {
  258. char *name;
  259. u8 num;
  260. } advanced_lookup[] = {
  261. { "NMI_INTERRUPT_WDG", 0x34 },
  262. { "SYSASSERT", 0x35 },
  263. { "UCODE_VERSION_MISMATCH", 0x37 },
  264. { "BAD_COMMAND", 0x38 },
  265. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  266. { "FATAL_ERROR", 0x3D },
  267. { "NMI_TRM_HW_ERR", 0x46 },
  268. { "NMI_INTERRUPT_TRM", 0x4C },
  269. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  270. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  271. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  272. { "NMI_INTERRUPT_HOST", 0x66 },
  273. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  274. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  275. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  276. { "ADVANCED_SYSASSERT", 0 },
  277. };
  278. static const char *desc_lookup(u32 num)
  279. {
  280. int i;
  281. for (i = 0; i < ARRAY_SIZE(advanced_lookup) - 1; i++)
  282. if (advanced_lookup[i].num == num)
  283. return advanced_lookup[i].name;
  284. /* No entry matches 'num', so it is the last: ADVANCED_SYSASSERT */
  285. return advanced_lookup[i].name;
  286. }
  287. /*
  288. * Note: This structure is read from the device with IO accesses,
  289. * and the reading already does the endian conversion. As it is
  290. * read with u32-sized accesses, any members with a different size
  291. * need to be ordered correctly though!
  292. */
  293. struct iwl_error_event_table {
  294. u32 valid; /* (nonzero) valid, (0) log is empty */
  295. u32 error_id; /* type of error */
  296. u32 pc; /* program counter */
  297. u32 blink1; /* branch link */
  298. u32 blink2; /* branch link */
  299. u32 ilink1; /* interrupt link */
  300. u32 ilink2; /* interrupt link */
  301. u32 data1; /* error-specific data */
  302. u32 data2; /* error-specific data */
  303. u32 data3; /* error-specific data */
  304. u32 bcon_time; /* beacon timer */
  305. u32 tsf_low; /* network timestamp function timer */
  306. u32 tsf_hi; /* network timestamp function timer */
  307. u32 gp1; /* GP1 timer register */
  308. u32 gp2; /* GP2 timer register */
  309. u32 gp3; /* GP3 timer register */
  310. u32 ucode_ver; /* uCode version */
  311. u32 hw_ver; /* HW Silicon version */
  312. u32 brd_ver; /* HW board version */
  313. u32 log_pc; /* log program counter */
  314. u32 frame_ptr; /* frame pointer */
  315. u32 stack_ptr; /* stack pointer */
  316. u32 hcmd; /* last host command header */
  317. u32 isr0; /* isr status register LMPM_NIC_ISR0:
  318. * rxtx_flag */
  319. u32 isr1; /* isr status register LMPM_NIC_ISR1:
  320. * host_flag */
  321. u32 isr2; /* isr status register LMPM_NIC_ISR2:
  322. * enc_flag */
  323. u32 isr3; /* isr status register LMPM_NIC_ISR3:
  324. * time_flag */
  325. u32 isr4; /* isr status register LMPM_NIC_ISR4:
  326. * wico interrupt */
  327. u32 isr_pref; /* isr status register LMPM_NIC_PREF_STAT */
  328. u32 wait_event; /* wait event() caller address */
  329. u32 l2p_control; /* L2pControlField */
  330. u32 l2p_duration; /* L2pDurationField */
  331. u32 l2p_mhvalid; /* L2pMhValidBits */
  332. u32 l2p_addr_match; /* L2pAddrMatchStat */
  333. u32 lmpm_pmg_sel; /* indicate which clocks are turned on
  334. * (LMPM_PMG_SEL) */
  335. u32 u_timestamp; /* indicate when the date and time of the
  336. * compilation */
  337. u32 flow_handler; /* FH read/write pointers, RX credit */
  338. } __packed;
  339. #define ERROR_START_OFFSET (1 * sizeof(u32))
  340. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  341. void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
  342. {
  343. struct iwl_trans *trans = mvm->trans;
  344. struct iwl_error_event_table table;
  345. u32 base;
  346. base = mvm->error_event_table;
  347. if (mvm->cur_ucode == IWL_UCODE_INIT) {
  348. if (!base)
  349. base = mvm->fw->init_errlog_ptr;
  350. } else {
  351. if (!base)
  352. base = mvm->fw->inst_errlog_ptr;
  353. }
  354. if (base < 0x800000 || base >= 0x80C000) {
  355. IWL_ERR(mvm,
  356. "Not valid error log pointer 0x%08X for %s uCode\n",
  357. base,
  358. (mvm->cur_ucode == IWL_UCODE_INIT)
  359. ? "Init" : "RT");
  360. return;
  361. }
  362. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  363. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  364. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  365. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  366. mvm->status, table.valid);
  367. }
  368. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  369. table.data1, table.data2, table.data3,
  370. table.blink1, table.blink2, table.ilink1,
  371. table.ilink2, table.bcon_time, table.gp1,
  372. table.gp2, table.gp3, table.ucode_ver,
  373. table.hw_ver, table.brd_ver);
  374. IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
  375. desc_lookup(table.error_id));
  376. IWL_ERR(mvm, "0x%08X | uPc\n", table.pc);
  377. IWL_ERR(mvm, "0x%08X | branchlink1\n", table.blink1);
  378. IWL_ERR(mvm, "0x%08X | branchlink2\n", table.blink2);
  379. IWL_ERR(mvm, "0x%08X | interruptlink1\n", table.ilink1);
  380. IWL_ERR(mvm, "0x%08X | interruptlink2\n", table.ilink2);
  381. IWL_ERR(mvm, "0x%08X | data1\n", table.data1);
  382. IWL_ERR(mvm, "0x%08X | data2\n", table.data2);
  383. IWL_ERR(mvm, "0x%08X | data3\n", table.data3);
  384. IWL_ERR(mvm, "0x%08X | beacon time\n", table.bcon_time);
  385. IWL_ERR(mvm, "0x%08X | tsf low\n", table.tsf_low);
  386. IWL_ERR(mvm, "0x%08X | tsf hi\n", table.tsf_hi);
  387. IWL_ERR(mvm, "0x%08X | time gp1\n", table.gp1);
  388. IWL_ERR(mvm, "0x%08X | time gp2\n", table.gp2);
  389. IWL_ERR(mvm, "0x%08X | time gp3\n", table.gp3);
  390. IWL_ERR(mvm, "0x%08X | uCode version\n", table.ucode_ver);
  391. IWL_ERR(mvm, "0x%08X | hw version\n", table.hw_ver);
  392. IWL_ERR(mvm, "0x%08X | board version\n", table.brd_ver);
  393. IWL_ERR(mvm, "0x%08X | hcmd\n", table.hcmd);
  394. IWL_ERR(mvm, "0x%08X | isr0\n", table.isr0);
  395. IWL_ERR(mvm, "0x%08X | isr1\n", table.isr1);
  396. IWL_ERR(mvm, "0x%08X | isr2\n", table.isr2);
  397. IWL_ERR(mvm, "0x%08X | isr3\n", table.isr3);
  398. IWL_ERR(mvm, "0x%08X | isr4\n", table.isr4);
  399. IWL_ERR(mvm, "0x%08X | isr_pref\n", table.isr_pref);
  400. IWL_ERR(mvm, "0x%08X | wait_event\n", table.wait_event);
  401. IWL_ERR(mvm, "0x%08X | l2p_control\n", table.l2p_control);
  402. IWL_ERR(mvm, "0x%08X | l2p_duration\n", table.l2p_duration);
  403. IWL_ERR(mvm, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  404. IWL_ERR(mvm, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  405. IWL_ERR(mvm, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  406. IWL_ERR(mvm, "0x%08X | timestamp\n", table.u_timestamp);
  407. IWL_ERR(mvm, "0x%08X | flow_handler\n", table.flow_handler);
  408. }
  409. void iwl_mvm_dump_sram(struct iwl_mvm *mvm)
  410. {
  411. const struct fw_img *img;
  412. int ofs, len = 0;
  413. u8 *buf;
  414. if (!mvm->ucode_loaded)
  415. return;
  416. img = &mvm->fw->img[mvm->cur_ucode];
  417. ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  418. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  419. buf = kzalloc(len, GFP_KERNEL);
  420. if (!buf)
  421. return;
  422. iwl_trans_read_mem_bytes(mvm->trans, ofs, buf, len);
  423. iwl_print_hex_error(mvm->trans, buf, len);
  424. kfree(buf);
  425. }
  426. /**
  427. * iwl_mvm_send_lq_cmd() - Send link quality command
  428. * @init: This command is sent as part of station initialization right
  429. * after station has been added.
  430. *
  431. * The link quality command is sent as the last step of station creation.
  432. * This is the special case in which init is set and we call a callback in
  433. * this case to clear the state indicating that station creation is in
  434. * progress.
  435. */
  436. int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq,
  437. u8 flags, bool init)
  438. {
  439. struct iwl_host_cmd cmd = {
  440. .id = LQ_CMD,
  441. .len = { sizeof(struct iwl_lq_cmd), },
  442. .flags = flags,
  443. .data = { lq, },
  444. };
  445. if (WARN_ON(lq->sta_id == IWL_MVM_STATION_COUNT))
  446. return -EINVAL;
  447. if (WARN_ON(init && (cmd.flags & CMD_ASYNC)))
  448. return -EINVAL;
  449. return iwl_mvm_send_cmd(mvm, &cmd);
  450. }
  451. /**
  452. * iwl_mvm_update_smps - Get a requst to change the SMPS mode
  453. * @req_type: The part of the driver who call for a change.
  454. * @smps_requests: The request to change the SMPS mode.
  455. *
  456. * Get a requst to change the SMPS mode,
  457. * and change it according to all other requests in the driver.
  458. */
  459. void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  460. enum iwl_mvm_smps_type_request req_type,
  461. enum ieee80211_smps_mode smps_request)
  462. {
  463. struct iwl_mvm_vif *mvmvif;
  464. enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC;
  465. int i;
  466. lockdep_assert_held(&mvm->mutex);
  467. mvmvif = iwl_mvm_vif_from_mac80211(vif);
  468. mvmvif->smps_requests[req_type] = smps_request;
  469. for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
  470. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC) {
  471. smps_mode = IEEE80211_SMPS_STATIC;
  472. break;
  473. }
  474. if (mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
  475. smps_mode = IEEE80211_SMPS_DYNAMIC;
  476. }
  477. ieee80211_request_smps(vif, smps_mode);
  478. }