iwl-agn-lib.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/etherdevice.h>
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/sched.h>
  34. #include "iwl-dev.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-helpers.h"
  38. #include "iwl-agn-hw.h"
  39. #include "iwl-agn.h"
  40. #include "iwl-sta.h"
  41. #include "iwl-trans.h"
  42. #include "iwl-shared.h"
  43. int iwlagn_hw_valid_rtc_data_addr(u32 addr)
  44. {
  45. return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
  46. (addr < IWLAGN_RTC_DATA_UPPER_BOUND);
  47. }
  48. int iwlagn_send_tx_power(struct iwl_priv *priv)
  49. {
  50. struct iwlagn_tx_power_dbm_cmd tx_power_cmd;
  51. u8 tx_ant_cfg_cmd;
  52. if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->shrd->status),
  53. "TX Power requested while scanning!\n"))
  54. return -EAGAIN;
  55. /* half dBm need to multiply */
  56. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  57. if (priv->tx_power_lmt_in_half_dbm &&
  58. priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
  59. /*
  60. * For the newer devices which using enhanced/extend tx power
  61. * table in EEPROM, the format is in half dBm. driver need to
  62. * convert to dBm format before report to mac80211.
  63. * By doing so, there is a possibility of 1/2 dBm resolution
  64. * lost. driver will perform "round-up" operation before
  65. * reporting, but it will cause 1/2 dBm tx power over the
  66. * regulatory limit. Perform the checking here, if the
  67. * "tx_power_user_lmt" is higher than EEPROM value (in
  68. * half-dBm format), lower the tx power based on EEPROM
  69. */
  70. tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
  71. }
  72. tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED;
  73. tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO;
  74. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  75. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  76. else
  77. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  78. return iwl_trans_send_cmd_pdu(trans(priv), tx_ant_cfg_cmd, CMD_SYNC,
  79. sizeof(tx_power_cmd), &tx_power_cmd);
  80. }
  81. void iwlagn_temperature(struct iwl_priv *priv)
  82. {
  83. /* store temperature from correct statistics (in Celsius) */
  84. priv->temperature = le32_to_cpu(priv->statistics.common.temperature);
  85. iwl_tt_handler(priv);
  86. }
  87. u16 iwlagn_eeprom_calib_version(struct iwl_priv *priv)
  88. {
  89. struct iwl_eeprom_calib_hdr *hdr;
  90. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  91. EEPROM_CALIB_ALL);
  92. return hdr->version;
  93. }
  94. /*
  95. * EEPROM
  96. */
  97. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  98. {
  99. u16 offset = 0;
  100. if ((address & INDIRECT_ADDRESS) == 0)
  101. return address;
  102. switch (address & INDIRECT_TYPE_MSK) {
  103. case INDIRECT_HOST:
  104. offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
  105. break;
  106. case INDIRECT_GENERAL:
  107. offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
  108. break;
  109. case INDIRECT_REGULATORY:
  110. offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
  111. break;
  112. case INDIRECT_TXP_LIMIT:
  113. offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT);
  114. break;
  115. case INDIRECT_TXP_LIMIT_SIZE:
  116. offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE);
  117. break;
  118. case INDIRECT_CALIBRATION:
  119. offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
  120. break;
  121. case INDIRECT_PROCESS_ADJST:
  122. offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
  123. break;
  124. case INDIRECT_OTHERS:
  125. offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
  126. break;
  127. default:
  128. IWL_ERR(priv, "illegal indirect type: 0x%X\n",
  129. address & INDIRECT_TYPE_MSK);
  130. break;
  131. }
  132. /* translate the offset from words to byte */
  133. return (address & ADDRESS_MSK) + (offset << 1);
  134. }
  135. const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
  136. {
  137. u32 address = eeprom_indirect_address(priv, offset);
  138. BUG_ON(address >= priv->cfg->base_params->eeprom_size);
  139. return &priv->eeprom[address];
  140. }
  141. struct iwl_mod_params iwlagn_mod_params = {
  142. .amsdu_size_8K = 1,
  143. .restart_fw = 1,
  144. .plcp_check = true,
  145. .bt_coex_active = true,
  146. .no_sleep_autoadjust = true,
  147. .power_level = IWL_POWER_INDEX_1,
  148. .bt_ch_announce = true,
  149. .wanted_ucode_alternative = 1,
  150. .auto_agg = true,
  151. /* the rest are 0 by default */
  152. };
  153. int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  154. {
  155. int idx = 0;
  156. int band_offset = 0;
  157. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  158. if (rate_n_flags & RATE_MCS_HT_MSK) {
  159. idx = (rate_n_flags & 0xff);
  160. return idx;
  161. /* Legacy rate format, search for match in table */
  162. } else {
  163. if (band == IEEE80211_BAND_5GHZ)
  164. band_offset = IWL_FIRST_OFDM_RATE;
  165. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  166. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  167. return idx - band_offset;
  168. }
  169. return -1;
  170. }
  171. int iwlagn_manage_ibss_station(struct iwl_priv *priv,
  172. struct ieee80211_vif *vif, bool add)
  173. {
  174. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  175. if (add)
  176. return iwlagn_add_bssid_station(priv, vif_priv->ctx,
  177. vif->bss_conf.bssid,
  178. &vif_priv->ibss_bssid_sta_id);
  179. return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
  180. vif->bss_conf.bssid);
  181. }
  182. /**
  183. * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
  184. *
  185. * pre-requirements:
  186. * 1. acquire mutex before calling
  187. * 2. make sure rf is on and not in exit state
  188. */
  189. int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  190. {
  191. struct iwl_txfifo_flush_cmd flush_cmd;
  192. struct iwl_host_cmd cmd = {
  193. .id = REPLY_TXFIFO_FLUSH,
  194. .len = { sizeof(struct iwl_txfifo_flush_cmd), },
  195. .flags = CMD_SYNC,
  196. .data = { &flush_cmd, },
  197. };
  198. might_sleep();
  199. memset(&flush_cmd, 0, sizeof(flush_cmd));
  200. if (flush_control & BIT(IWL_RXON_CTX_BSS))
  201. flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK |
  202. IWL_SCD_BE_MSK | IWL_SCD_BK_MSK |
  203. IWL_SCD_MGMT_MSK;
  204. if ((flush_control & BIT(IWL_RXON_CTX_PAN)) &&
  205. (priv->shrd->valid_contexts != BIT(IWL_RXON_CTX_BSS)))
  206. flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK |
  207. IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK |
  208. IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
  209. IWL_PAN_SCD_MULTICAST_MSK;
  210. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  211. flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
  212. IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
  213. flush_cmd.fifo_control);
  214. flush_cmd.flush_control = cpu_to_le16(flush_control);
  215. return iwl_trans_send_cmd(trans(priv), &cmd);
  216. }
  217. void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  218. {
  219. mutex_lock(&priv->shrd->mutex);
  220. ieee80211_stop_queues(priv->hw);
  221. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  222. IWL_ERR(priv, "flush request fail\n");
  223. goto done;
  224. }
  225. IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
  226. iwl_trans_wait_tx_queue_empty(trans(priv));
  227. done:
  228. ieee80211_wake_queues(priv->hw);
  229. mutex_unlock(&priv->shrd->mutex);
  230. }
  231. /*
  232. * BT coex
  233. */
  234. /*
  235. * Macros to access the lookup table.
  236. *
  237. * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
  238. * wifi_prio, wifi_txrx and wifi_sh_ant_req.
  239. *
  240. * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
  241. *
  242. * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
  243. * one after another in 32-bit registers, and "registers" 0 through 7 contain
  244. * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
  245. *
  246. * These macros encode that format.
  247. */
  248. #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
  249. wifi_txrx, wifi_sh_ant_req) \
  250. (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
  251. (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
  252. #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
  253. lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
  254. #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  255. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  256. (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
  257. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  258. wifi_sh_ant_req))))
  259. #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  260. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  261. LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
  262. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  263. wifi_sh_ant_req))
  264. #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
  265. wifi_req, wifi_prio, wifi_txrx, \
  266. wifi_sh_ant_req) \
  267. LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
  268. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  269. wifi_sh_ant_req))
  270. #define LUT_WLAN_KILL_OP(lut, op, val) \
  271. lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
  272. #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  273. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  274. (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  275. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
  276. #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  277. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  278. LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  279. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  280. #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  281. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  282. LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  283. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  284. #define LUT_ANT_SWITCH_OP(lut, op, val) \
  285. lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
  286. #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  287. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  288. (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  289. wifi_req, wifi_prio, wifi_txrx, \
  290. wifi_sh_ant_req))))
  291. #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  292. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  293. LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  294. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  295. #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  296. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  297. LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  298. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  299. static const __le32 iwlagn_def_3w_lookup[12] = {
  300. cpu_to_le32(0xaaaaaaaa),
  301. cpu_to_le32(0xaaaaaaaa),
  302. cpu_to_le32(0xaeaaaaaa),
  303. cpu_to_le32(0xaaaaaaaa),
  304. cpu_to_le32(0xcc00ff28),
  305. cpu_to_le32(0x0000aaaa),
  306. cpu_to_le32(0xcc00aaaa),
  307. cpu_to_le32(0x0000aaaa),
  308. cpu_to_le32(0xc0004000),
  309. cpu_to_le32(0x00004000),
  310. cpu_to_le32(0xf0005000),
  311. cpu_to_le32(0xf0005000),
  312. };
  313. static const __le32 iwlagn_concurrent_lookup[12] = {
  314. cpu_to_le32(0xaaaaaaaa),
  315. cpu_to_le32(0xaaaaaaaa),
  316. cpu_to_le32(0xaaaaaaaa),
  317. cpu_to_le32(0xaaaaaaaa),
  318. cpu_to_le32(0xaaaaaaaa),
  319. cpu_to_le32(0xaaaaaaaa),
  320. cpu_to_le32(0xaaaaaaaa),
  321. cpu_to_le32(0xaaaaaaaa),
  322. cpu_to_le32(0x00000000),
  323. cpu_to_le32(0x00000000),
  324. cpu_to_le32(0x00000000),
  325. cpu_to_le32(0x00000000),
  326. };
  327. void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
  328. {
  329. struct iwl_basic_bt_cmd basic = {
  330. .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
  331. .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
  332. .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
  333. .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
  334. };
  335. struct iwl6000_bt_cmd bt_cmd_6000;
  336. struct iwl2000_bt_cmd bt_cmd_2000;
  337. int ret;
  338. BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
  339. sizeof(basic.bt3_lookup_table));
  340. if (priv->cfg->bt_params) {
  341. if (priv->cfg->bt_params->bt_session_2) {
  342. bt_cmd_2000.prio_boost = cpu_to_le32(
  343. priv->cfg->bt_params->bt_prio_boost);
  344. bt_cmd_2000.tx_prio_boost = 0;
  345. bt_cmd_2000.rx_prio_boost = 0;
  346. } else {
  347. bt_cmd_6000.prio_boost =
  348. priv->cfg->bt_params->bt_prio_boost;
  349. bt_cmd_6000.tx_prio_boost = 0;
  350. bt_cmd_6000.rx_prio_boost = 0;
  351. }
  352. } else {
  353. IWL_ERR(priv, "failed to construct BT Coex Config\n");
  354. return;
  355. }
  356. basic.kill_ack_mask = priv->kill_ack_mask;
  357. basic.kill_cts_mask = priv->kill_cts_mask;
  358. basic.valid = priv->bt_valid;
  359. /*
  360. * Configure BT coex mode to "no coexistence" when the
  361. * user disabled BT coexistence, we have no interface
  362. * (might be in monitor mode), or the interface is in
  363. * IBSS mode (no proper uCode support for coex then).
  364. */
  365. if (!iwlagn_mod_params.bt_coex_active ||
  366. priv->iw_mode == NL80211_IFTYPE_ADHOC) {
  367. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
  368. } else {
  369. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
  370. IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
  371. if (!priv->bt_enable_pspoll)
  372. basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  373. else
  374. basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  375. if (priv->bt_ch_announce)
  376. basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
  377. IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags);
  378. }
  379. priv->bt_enable_flag = basic.flags;
  380. if (priv->bt_full_concurrent)
  381. memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
  382. sizeof(iwlagn_concurrent_lookup));
  383. else
  384. memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
  385. sizeof(iwlagn_def_3w_lookup));
  386. IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n",
  387. basic.flags ? "active" : "disabled",
  388. priv->bt_full_concurrent ?
  389. "full concurrency" : "3-wire");
  390. if (priv->cfg->bt_params->bt_session_2) {
  391. memcpy(&bt_cmd_2000.basic, &basic,
  392. sizeof(basic));
  393. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  394. CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000);
  395. } else {
  396. memcpy(&bt_cmd_6000.basic, &basic,
  397. sizeof(basic));
  398. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  399. CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000);
  400. }
  401. if (ret)
  402. IWL_ERR(priv, "failed to send BT Coex Config\n");
  403. }
  404. void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
  405. {
  406. struct iwl_rxon_context *ctx, *found_ctx = NULL;
  407. bool found_ap = false;
  408. lockdep_assert_held(&priv->shrd->mutex);
  409. /* Check whether AP or GO mode is active. */
  410. if (rssi_ena) {
  411. for_each_context(priv, ctx) {
  412. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP &&
  413. iwl_is_associated_ctx(ctx)) {
  414. found_ap = true;
  415. break;
  416. }
  417. }
  418. }
  419. /*
  420. * If disable was received or If GO/AP mode, disable RSSI
  421. * measurements.
  422. */
  423. if (!rssi_ena || found_ap) {
  424. if (priv->cur_rssi_ctx) {
  425. ctx = priv->cur_rssi_ctx;
  426. ieee80211_disable_rssi_reports(ctx->vif);
  427. priv->cur_rssi_ctx = NULL;
  428. }
  429. return;
  430. }
  431. /*
  432. * If rssi measurements need to be enabled, consider all cases now.
  433. * Figure out how many contexts are active.
  434. */
  435. for_each_context(priv, ctx) {
  436. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
  437. iwl_is_associated_ctx(ctx)) {
  438. found_ctx = ctx;
  439. break;
  440. }
  441. }
  442. /*
  443. * rssi monitor already enabled for the correct interface...nothing
  444. * to do.
  445. */
  446. if (found_ctx == priv->cur_rssi_ctx)
  447. return;
  448. /*
  449. * Figure out if rssi monitor is currently enabled, and needs
  450. * to be changed. If rssi monitor is already enabled, disable
  451. * it first else just enable rssi measurements on the
  452. * interface found above.
  453. */
  454. if (priv->cur_rssi_ctx) {
  455. ctx = priv->cur_rssi_ctx;
  456. if (ctx->vif)
  457. ieee80211_disable_rssi_reports(ctx->vif);
  458. }
  459. priv->cur_rssi_ctx = found_ctx;
  460. if (!found_ctx)
  461. return;
  462. ieee80211_enable_rssi_reports(found_ctx->vif,
  463. IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD,
  464. IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD);
  465. }
  466. static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
  467. {
  468. return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >>
  469. BT_UART_MSG_FRAME3SCOESCO_POS;
  470. }
  471. static void iwlagn_bt_traffic_change_work(struct work_struct *work)
  472. {
  473. struct iwl_priv *priv =
  474. container_of(work, struct iwl_priv, bt_traffic_change_work);
  475. struct iwl_rxon_context *ctx;
  476. int smps_request = -1;
  477. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  478. /* bt coex disabled */
  479. return;
  480. }
  481. /*
  482. * Note: bt_traffic_load can be overridden by scan complete and
  483. * coex profile notifications. Ignore that since only bad consequence
  484. * can be not matching debug print with actual state.
  485. */
  486. IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n",
  487. priv->bt_traffic_load);
  488. switch (priv->bt_traffic_load) {
  489. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  490. if (priv->bt_status)
  491. smps_request = IEEE80211_SMPS_DYNAMIC;
  492. else
  493. smps_request = IEEE80211_SMPS_AUTOMATIC;
  494. break;
  495. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  496. smps_request = IEEE80211_SMPS_DYNAMIC;
  497. break;
  498. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  499. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  500. smps_request = IEEE80211_SMPS_STATIC;
  501. break;
  502. default:
  503. IWL_ERR(priv, "Invalid BT traffic load: %d\n",
  504. priv->bt_traffic_load);
  505. break;
  506. }
  507. mutex_lock(&priv->shrd->mutex);
  508. /*
  509. * We can not send command to firmware while scanning. When the scan
  510. * complete we will schedule this work again. We do check with mutex
  511. * locked to prevent new scan request to arrive. We do not check
  512. * STATUS_SCANNING to avoid race when queue_work two times from
  513. * different notifications, but quit and not perform any work at all.
  514. */
  515. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status))
  516. goto out;
  517. iwl_update_chain_flags(priv);
  518. if (smps_request != -1) {
  519. priv->current_ht_config.smps = smps_request;
  520. for_each_context(priv, ctx) {
  521. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
  522. ieee80211_request_smps(ctx->vif, smps_request);
  523. }
  524. }
  525. /*
  526. * Dynamic PS poll related functionality. Adjust RSSI measurements if
  527. * necessary.
  528. */
  529. iwlagn_bt_coex_rssi_monitor(priv);
  530. out:
  531. mutex_unlock(&priv->shrd->mutex);
  532. }
  533. /*
  534. * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
  535. * correct interface or disable it if this is the last interface to be
  536. * removed.
  537. */
  538. void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv)
  539. {
  540. if (priv->bt_is_sco &&
  541. priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS)
  542. iwlagn_bt_adjust_rssi_monitor(priv, true);
  543. else
  544. iwlagn_bt_adjust_rssi_monitor(priv, false);
  545. }
  546. static void iwlagn_print_uartmsg(struct iwl_priv *priv,
  547. struct iwl_bt_uart_msg *uart_msg)
  548. {
  549. IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, "
  550. "Update Req = 0x%X",
  551. (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
  552. BT_UART_MSG_FRAME1MSGTYPE_POS,
  553. (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
  554. BT_UART_MSG_FRAME1SSN_POS,
  555. (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
  556. BT_UART_MSG_FRAME1UPDATEREQ_POS);
  557. IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
  558. "Chl_SeqN = 0x%X, In band = 0x%X",
  559. (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
  560. BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
  561. (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
  562. BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
  563. (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
  564. BT_UART_MSG_FRAME2CHLSEQN_POS,
  565. (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
  566. BT_UART_MSG_FRAME2INBAND_POS);
  567. IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
  568. "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
  569. (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
  570. BT_UART_MSG_FRAME3SCOESCO_POS,
  571. (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
  572. BT_UART_MSG_FRAME3SNIFF_POS,
  573. (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
  574. BT_UART_MSG_FRAME3A2DP_POS,
  575. (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
  576. BT_UART_MSG_FRAME3ACL_POS,
  577. (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
  578. BT_UART_MSG_FRAME3MASTER_POS,
  579. (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
  580. BT_UART_MSG_FRAME3OBEX_POS);
  581. IWL_DEBUG_COEX(priv, "Idle duration = 0x%X",
  582. (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
  583. BT_UART_MSG_FRAME4IDLEDURATION_POS);
  584. IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
  585. "eSCO Retransmissions = 0x%X",
  586. (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
  587. BT_UART_MSG_FRAME5TXACTIVITY_POS,
  588. (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
  589. BT_UART_MSG_FRAME5RXACTIVITY_POS,
  590. (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
  591. BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
  592. IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
  593. (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
  594. BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
  595. (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
  596. BT_UART_MSG_FRAME6DISCOVERABLE_POS);
  597. IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = "
  598. "0x%X, Inquiry = 0x%X, Connectable = 0x%X",
  599. (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
  600. BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
  601. (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
  602. BT_UART_MSG_FRAME7PAGE_POS,
  603. (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
  604. BT_UART_MSG_FRAME7INQUIRY_POS,
  605. (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
  606. BT_UART_MSG_FRAME7CONNECTABLE_POS);
  607. }
  608. static void iwlagn_set_kill_msk(struct iwl_priv *priv,
  609. struct iwl_bt_uart_msg *uart_msg)
  610. {
  611. u8 kill_msk;
  612. static const __le32 bt_kill_ack_msg[2] = {
  613. IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
  614. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  615. static const __le32 bt_kill_cts_msg[2] = {
  616. IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
  617. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  618. kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
  619. ? 1 : 0;
  620. if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
  621. priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
  622. priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
  623. priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
  624. priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
  625. priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
  626. /* schedule to send runtime bt_config */
  627. queue_work(priv->shrd->workqueue, &priv->bt_runtime_config);
  628. }
  629. }
  630. int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
  631. struct iwl_rx_mem_buffer *rxb,
  632. struct iwl_device_cmd *cmd)
  633. {
  634. unsigned long flags;
  635. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  636. struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
  637. struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
  638. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  639. /* bt coex disabled */
  640. return 0;
  641. }
  642. IWL_DEBUG_COEX(priv, "BT Coex notification:\n");
  643. IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status);
  644. IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load);
  645. IWL_DEBUG_COEX(priv, " CI compliance: %d\n",
  646. coex->bt_ci_compliance);
  647. iwlagn_print_uartmsg(priv, uart_msg);
  648. priv->last_bt_traffic_load = priv->bt_traffic_load;
  649. priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg);
  650. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  651. if (priv->bt_status != coex->bt_status ||
  652. priv->last_bt_traffic_load != coex->bt_traffic_load) {
  653. if (coex->bt_status) {
  654. /* BT on */
  655. if (!priv->bt_ch_announce)
  656. priv->bt_traffic_load =
  657. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  658. else
  659. priv->bt_traffic_load =
  660. coex->bt_traffic_load;
  661. } else {
  662. /* BT off */
  663. priv->bt_traffic_load =
  664. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  665. }
  666. priv->bt_status = coex->bt_status;
  667. queue_work(priv->shrd->workqueue,
  668. &priv->bt_traffic_change_work);
  669. }
  670. }
  671. iwlagn_set_kill_msk(priv, uart_msg);
  672. /* FIXME: based on notification, adjust the prio_boost */
  673. spin_lock_irqsave(&priv->shrd->lock, flags);
  674. priv->bt_ci_compliance = coex->bt_ci_compliance;
  675. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  676. return 0;
  677. }
  678. void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
  679. {
  680. priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
  681. iwlagn_bt_coex_profile_notif;
  682. }
  683. void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
  684. {
  685. INIT_WORK(&priv->bt_traffic_change_work,
  686. iwlagn_bt_traffic_change_work);
  687. }
  688. void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
  689. {
  690. cancel_work_sync(&priv->bt_traffic_change_work);
  691. }
  692. static bool is_single_rx_stream(struct iwl_priv *priv)
  693. {
  694. return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  695. priv->current_ht_config.single_chain_sufficient;
  696. }
  697. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  698. #define IWL_NUM_RX_CHAINS_SINGLE 2
  699. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  700. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  701. /*
  702. * Determine how many receiver/antenna chains to use.
  703. *
  704. * More provides better reception via diversity. Fewer saves power
  705. * at the expense of throughput, but only when not in powersave to
  706. * start with.
  707. *
  708. * MIMO (dual stream) requires at least 2, but works better with 3.
  709. * This does not determine *which* chains to use, just how many.
  710. */
  711. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  712. {
  713. if (priv->cfg->bt_params &&
  714. priv->cfg->bt_params->advanced_bt_coexist &&
  715. (priv->bt_full_concurrent ||
  716. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  717. /*
  718. * only use chain 'A' in bt high traffic load or
  719. * full concurrency mode
  720. */
  721. return IWL_NUM_RX_CHAINS_SINGLE;
  722. }
  723. /* # of Rx chains to use when expecting MIMO. */
  724. if (is_single_rx_stream(priv))
  725. return IWL_NUM_RX_CHAINS_SINGLE;
  726. else
  727. return IWL_NUM_RX_CHAINS_MULTIPLE;
  728. }
  729. /*
  730. * When we are in power saving mode, unless device support spatial
  731. * multiplexing power save, use the active count for rx chain count.
  732. */
  733. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  734. {
  735. /* # Rx chains when idling, depending on SMPS mode */
  736. switch (priv->current_ht_config.smps) {
  737. case IEEE80211_SMPS_STATIC:
  738. case IEEE80211_SMPS_DYNAMIC:
  739. return IWL_NUM_IDLE_CHAINS_SINGLE;
  740. case IEEE80211_SMPS_OFF:
  741. return active_cnt;
  742. default:
  743. WARN(1, "invalid SMPS mode %d",
  744. priv->current_ht_config.smps);
  745. return active_cnt;
  746. }
  747. }
  748. /* up to 4 chains */
  749. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  750. {
  751. u8 res;
  752. res = (chain_bitmap & BIT(0)) >> 0;
  753. res += (chain_bitmap & BIT(1)) >> 1;
  754. res += (chain_bitmap & BIT(2)) >> 2;
  755. res += (chain_bitmap & BIT(3)) >> 3;
  756. return res;
  757. }
  758. /**
  759. * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  760. *
  761. * Selects how many and which Rx receivers/antennas/chains to use.
  762. * This should not be used for scan command ... it puts data in wrong place.
  763. */
  764. void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  765. {
  766. bool is_single = is_single_rx_stream(priv);
  767. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->shrd->status);
  768. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  769. u32 active_chains;
  770. u16 rx_chain;
  771. /* Tell uCode which antennas are actually connected.
  772. * Before first association, we assume all antennas are connected.
  773. * Just after first association, iwl_chain_noise_calibration()
  774. * checks which antennas actually *are* connected. */
  775. if (priv->chain_noise_data.active_chains)
  776. active_chains = priv->chain_noise_data.active_chains;
  777. else
  778. active_chains = hw_params(priv).valid_rx_ant;
  779. if (priv->cfg->bt_params &&
  780. priv->cfg->bt_params->advanced_bt_coexist &&
  781. (priv->bt_full_concurrent ||
  782. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  783. /*
  784. * only use chain 'A' in bt high traffic load or
  785. * full concurrency mode
  786. */
  787. active_chains = first_antenna(active_chains);
  788. }
  789. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  790. /* How many receivers should we use? */
  791. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  792. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  793. /* correct rx chain count according hw settings
  794. * and chain noise calibration
  795. */
  796. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  797. if (valid_rx_cnt < active_rx_cnt)
  798. active_rx_cnt = valid_rx_cnt;
  799. if (valid_rx_cnt < idle_rx_cnt)
  800. idle_rx_cnt = valid_rx_cnt;
  801. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  802. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  803. ctx->staging.rx_chain = cpu_to_le16(rx_chain);
  804. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  805. ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  806. else
  807. ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  808. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  809. ctx->staging.rx_chain,
  810. active_rx_cnt, idle_rx_cnt);
  811. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  812. active_rx_cnt < idle_rx_cnt);
  813. }
  814. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
  815. {
  816. int i;
  817. u8 ind = ant;
  818. if (priv->band == IEEE80211_BAND_2GHZ &&
  819. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
  820. return 0;
  821. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  822. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  823. if (valid & BIT(ind))
  824. return ind;
  825. }
  826. return ant;
  827. }
  828. /* notification wait support */
  829. void iwlagn_init_notification_wait(struct iwl_priv *priv,
  830. struct iwl_notification_wait *wait_entry,
  831. u8 cmd,
  832. void (*fn)(struct iwl_priv *priv,
  833. struct iwl_rx_packet *pkt,
  834. void *data),
  835. void *fn_data)
  836. {
  837. wait_entry->fn = fn;
  838. wait_entry->fn_data = fn_data;
  839. wait_entry->cmd = cmd;
  840. wait_entry->triggered = false;
  841. wait_entry->aborted = false;
  842. spin_lock_bh(&priv->notif_wait_lock);
  843. list_add(&wait_entry->list, &priv->notif_waits);
  844. spin_unlock_bh(&priv->notif_wait_lock);
  845. }
  846. int iwlagn_wait_notification(struct iwl_priv *priv,
  847. struct iwl_notification_wait *wait_entry,
  848. unsigned long timeout)
  849. {
  850. int ret;
  851. ret = wait_event_timeout(priv->notif_waitq,
  852. wait_entry->triggered || wait_entry->aborted,
  853. timeout);
  854. spin_lock_bh(&priv->notif_wait_lock);
  855. list_del(&wait_entry->list);
  856. spin_unlock_bh(&priv->notif_wait_lock);
  857. if (wait_entry->aborted)
  858. return -EIO;
  859. /* return value is always >= 0 */
  860. if (ret <= 0)
  861. return -ETIMEDOUT;
  862. return 0;
  863. }
  864. void iwlagn_remove_notification(struct iwl_priv *priv,
  865. struct iwl_notification_wait *wait_entry)
  866. {
  867. spin_lock_bh(&priv->notif_wait_lock);
  868. list_del(&wait_entry->list);
  869. spin_unlock_bh(&priv->notif_wait_lock);
  870. }