iwl-agn-lib.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  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 {
  90. u8 version;
  91. u8 pa_type;
  92. u16 voltage;
  93. } *hdr;
  94. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  95. EEPROM_CALIB_ALL);
  96. return hdr->version;
  97. }
  98. /*
  99. * EEPROM
  100. */
  101. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  102. {
  103. u16 offset = 0;
  104. if ((address & INDIRECT_ADDRESS) == 0)
  105. return address;
  106. switch (address & INDIRECT_TYPE_MSK) {
  107. case INDIRECT_HOST:
  108. offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
  109. break;
  110. case INDIRECT_GENERAL:
  111. offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
  112. break;
  113. case INDIRECT_REGULATORY:
  114. offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
  115. break;
  116. case INDIRECT_TXP_LIMIT:
  117. offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT);
  118. break;
  119. case INDIRECT_TXP_LIMIT_SIZE:
  120. offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE);
  121. break;
  122. case INDIRECT_CALIBRATION:
  123. offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
  124. break;
  125. case INDIRECT_PROCESS_ADJST:
  126. offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
  127. break;
  128. case INDIRECT_OTHERS:
  129. offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
  130. break;
  131. default:
  132. IWL_ERR(priv, "illegal indirect type: 0x%X\n",
  133. address & INDIRECT_TYPE_MSK);
  134. break;
  135. }
  136. /* translate the offset from words to byte */
  137. return (address & ADDRESS_MSK) + (offset << 1);
  138. }
  139. const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
  140. {
  141. u32 address = eeprom_indirect_address(priv, offset);
  142. BUG_ON(address >= priv->cfg->base_params->eeprom_size);
  143. return &priv->eeprom[address];
  144. }
  145. struct iwl_mod_params iwlagn_mod_params = {
  146. .amsdu_size_8K = 1,
  147. .restart_fw = 1,
  148. .plcp_check = true,
  149. .bt_coex_active = true,
  150. .no_sleep_autoadjust = true,
  151. .power_level = IWL_POWER_INDEX_1,
  152. .bt_ch_announce = true,
  153. .wanted_ucode_alternative = 1,
  154. .auto_agg = true,
  155. /* the rest are 0 by default */
  156. };
  157. int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  158. {
  159. int idx = 0;
  160. int band_offset = 0;
  161. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  162. if (rate_n_flags & RATE_MCS_HT_MSK) {
  163. idx = (rate_n_flags & 0xff);
  164. return idx;
  165. /* Legacy rate format, search for match in table */
  166. } else {
  167. if (band == IEEE80211_BAND_5GHZ)
  168. band_offset = IWL_FIRST_OFDM_RATE;
  169. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  170. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  171. return idx - band_offset;
  172. }
  173. return -1;
  174. }
  175. static int iwl_get_single_channel_for_scan(struct iwl_priv *priv,
  176. struct ieee80211_vif *vif,
  177. enum ieee80211_band band,
  178. struct iwl_scan_channel *scan_ch)
  179. {
  180. const struct ieee80211_supported_band *sband;
  181. u16 passive_dwell = 0;
  182. u16 active_dwell = 0;
  183. int added = 0;
  184. u16 channel = 0;
  185. sband = iwl_get_hw_mode(priv, band);
  186. if (!sband) {
  187. IWL_ERR(priv, "invalid band\n");
  188. return added;
  189. }
  190. active_dwell = iwl_get_active_dwell_time(priv, band, 0);
  191. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  192. if (passive_dwell <= active_dwell)
  193. passive_dwell = active_dwell + 1;
  194. channel = iwl_get_single_channel_number(priv, band);
  195. if (channel) {
  196. scan_ch->channel = cpu_to_le16(channel);
  197. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  198. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  199. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  200. /* Set txpower levels to defaults */
  201. scan_ch->dsp_atten = 110;
  202. if (band == IEEE80211_BAND_5GHZ)
  203. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  204. else
  205. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  206. added++;
  207. } else
  208. IWL_ERR(priv, "no valid channel found\n");
  209. return added;
  210. }
  211. static int iwl_get_channels_for_scan(struct iwl_priv *priv,
  212. struct ieee80211_vif *vif,
  213. enum ieee80211_band band,
  214. u8 is_active, u8 n_probes,
  215. struct iwl_scan_channel *scan_ch)
  216. {
  217. struct ieee80211_channel *chan;
  218. const struct ieee80211_supported_band *sband;
  219. const struct iwl_channel_info *ch_info;
  220. u16 passive_dwell = 0;
  221. u16 active_dwell = 0;
  222. int added, i;
  223. u16 channel;
  224. sband = iwl_get_hw_mode(priv, band);
  225. if (!sband)
  226. return 0;
  227. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  228. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  229. if (passive_dwell <= active_dwell)
  230. passive_dwell = active_dwell + 1;
  231. for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
  232. chan = priv->scan_request->channels[i];
  233. if (chan->band != band)
  234. continue;
  235. channel = chan->hw_value;
  236. scan_ch->channel = cpu_to_le16(channel);
  237. ch_info = iwl_get_channel_info(priv, band, channel);
  238. if (!is_channel_valid(ch_info)) {
  239. IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
  240. channel);
  241. continue;
  242. }
  243. if (!is_active || is_channel_passive(ch_info) ||
  244. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
  245. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  246. else
  247. scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
  248. if (n_probes)
  249. scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
  250. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  251. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  252. /* Set txpower levels to defaults */
  253. scan_ch->dsp_atten = 110;
  254. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  255. * power level:
  256. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  257. */
  258. if (band == IEEE80211_BAND_5GHZ)
  259. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  260. else
  261. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  262. IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n",
  263. channel, le32_to_cpu(scan_ch->type),
  264. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  265. "ACTIVE" : "PASSIVE",
  266. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  267. active_dwell : passive_dwell);
  268. scan_ch++;
  269. added++;
  270. }
  271. IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
  272. return added;
  273. }
  274. int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
  275. {
  276. struct iwl_host_cmd cmd = {
  277. .id = REPLY_SCAN_CMD,
  278. .len = { sizeof(struct iwl_scan_cmd), },
  279. .flags = CMD_SYNC,
  280. };
  281. struct iwl_scan_cmd *scan;
  282. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  283. u32 rate_flags = 0;
  284. u16 cmd_len;
  285. u16 rx_chain = 0;
  286. enum ieee80211_band band;
  287. u8 n_probes = 0;
  288. u8 rx_ant = hw_params(priv).valid_rx_ant;
  289. u8 rate;
  290. bool is_active = false;
  291. int chan_mod;
  292. u8 active_chains;
  293. u8 scan_tx_antennas = hw_params(priv).valid_tx_ant;
  294. int ret;
  295. lockdep_assert_held(&priv->shrd->mutex);
  296. if (vif)
  297. ctx = iwl_rxon_ctx_from_vif(vif);
  298. if (!priv->scan_cmd) {
  299. priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) +
  300. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  301. if (!priv->scan_cmd) {
  302. IWL_DEBUG_SCAN(priv,
  303. "fail to allocate memory for scan\n");
  304. return -ENOMEM;
  305. }
  306. }
  307. scan = priv->scan_cmd;
  308. memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE);
  309. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  310. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  311. if (priv->scan_type != IWL_SCAN_ROC &&
  312. iwl_is_any_associated(priv)) {
  313. u16 interval = 0;
  314. u32 extra;
  315. u32 suspend_time = 100;
  316. u32 scan_suspend_time = 100;
  317. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  318. switch (priv->scan_type) {
  319. case IWL_SCAN_ROC:
  320. WARN_ON(1);
  321. break;
  322. case IWL_SCAN_RADIO_RESET:
  323. interval = 0;
  324. break;
  325. case IWL_SCAN_NORMAL:
  326. interval = vif->bss_conf.beacon_int;
  327. break;
  328. }
  329. scan->suspend_time = 0;
  330. scan->max_out_time = cpu_to_le32(200 * 1024);
  331. if (!interval)
  332. interval = suspend_time;
  333. extra = (suspend_time / interval) << 22;
  334. scan_suspend_time = (extra |
  335. ((suspend_time % interval) * 1024));
  336. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  337. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  338. scan_suspend_time, interval);
  339. } else if (priv->scan_type == IWL_SCAN_ROC) {
  340. scan->suspend_time = 0;
  341. scan->max_out_time = 0;
  342. scan->quiet_time = 0;
  343. scan->quiet_plcp_th = 0;
  344. }
  345. switch (priv->scan_type) {
  346. case IWL_SCAN_RADIO_RESET:
  347. IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
  348. break;
  349. case IWL_SCAN_NORMAL:
  350. if (priv->scan_request->n_ssids) {
  351. int i, p = 0;
  352. IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
  353. for (i = 0; i < priv->scan_request->n_ssids; i++) {
  354. /* always does wildcard anyway */
  355. if (!priv->scan_request->ssids[i].ssid_len)
  356. continue;
  357. scan->direct_scan[p].id = WLAN_EID_SSID;
  358. scan->direct_scan[p].len =
  359. priv->scan_request->ssids[i].ssid_len;
  360. memcpy(scan->direct_scan[p].ssid,
  361. priv->scan_request->ssids[i].ssid,
  362. priv->scan_request->ssids[i].ssid_len);
  363. n_probes++;
  364. p++;
  365. }
  366. is_active = true;
  367. } else
  368. IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
  369. break;
  370. case IWL_SCAN_ROC:
  371. IWL_DEBUG_SCAN(priv, "Start ROC scan.\n");
  372. break;
  373. }
  374. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  375. scan->tx_cmd.sta_id = ctx->bcast_sta_id;
  376. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  377. switch (priv->scan_band) {
  378. case IEEE80211_BAND_2GHZ:
  379. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  380. chan_mod = le32_to_cpu(
  381. priv->contexts[IWL_RXON_CTX_BSS].active.flags &
  382. RXON_FLG_CHANNEL_MODE_MSK)
  383. >> RXON_FLG_CHANNEL_MODE_POS;
  384. if (chan_mod == CHANNEL_MODE_PURE_40) {
  385. rate = IWL_RATE_6M_PLCP;
  386. } else {
  387. rate = IWL_RATE_1M_PLCP;
  388. rate_flags = RATE_MCS_CCK_MSK;
  389. }
  390. /*
  391. * Internal scans are passive, so we can indiscriminately set
  392. * the BT ignore flag on 2.4 GHz since it applies to TX only.
  393. */
  394. if (priv->cfg->bt_params &&
  395. priv->cfg->bt_params->advanced_bt_coexist)
  396. scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT;
  397. break;
  398. case IEEE80211_BAND_5GHZ:
  399. rate = IWL_RATE_6M_PLCP;
  400. break;
  401. default:
  402. IWL_WARN(priv, "Invalid scan band\n");
  403. return -EIO;
  404. }
  405. /*
  406. * If active scanning is requested but a certain channel is
  407. * marked passive, we can do active scanning if we detect
  408. * transmissions.
  409. *
  410. * There is an issue with some firmware versions that triggers
  411. * a sysassert on a "good CRC threshold" of zero (== disabled),
  412. * on a radar channel even though this means that we should NOT
  413. * send probes.
  414. *
  415. * The "good CRC threshold" is the number of frames that we
  416. * need to receive during our dwell time on a channel before
  417. * sending out probes -- setting this to a huge value will
  418. * mean we never reach it, but at the same time work around
  419. * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER
  420. * here instead of IWL_GOOD_CRC_TH_DISABLED.
  421. *
  422. * This was fixed in later versions along with some other
  423. * scan changes, and the threshold behaves as a flag in those
  424. * versions.
  425. */
  426. if (priv->new_scan_threshold_behaviour)
  427. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  428. IWL_GOOD_CRC_TH_DISABLED;
  429. else
  430. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  431. IWL_GOOD_CRC_TH_NEVER;
  432. band = priv->scan_band;
  433. if (priv->cfg->scan_rx_antennas[band])
  434. rx_ant = priv->cfg->scan_rx_antennas[band];
  435. if (band == IEEE80211_BAND_2GHZ &&
  436. priv->cfg->bt_params &&
  437. priv->cfg->bt_params->advanced_bt_coexist) {
  438. /* transmit 2.4 GHz probes only on first antenna */
  439. scan_tx_antennas = first_antenna(scan_tx_antennas);
  440. }
  441. priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, priv->scan_tx_ant[band],
  442. scan_tx_antennas);
  443. rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
  444. scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
  445. /* In power save mode use one chain, otherwise use all chains */
  446. if (test_bit(STATUS_POWER_PMI, &priv->shrd->status)) {
  447. /* rx_ant has been set to all valid chains previously */
  448. active_chains = rx_ant &
  449. ((u8)(priv->chain_noise_data.active_chains));
  450. if (!active_chains)
  451. active_chains = rx_ant;
  452. IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n",
  453. priv->chain_noise_data.active_chains);
  454. rx_ant = first_antenna(active_chains);
  455. }
  456. if (priv->cfg->bt_params &&
  457. priv->cfg->bt_params->advanced_bt_coexist &&
  458. priv->bt_full_concurrent) {
  459. /* operated as 1x1 in full concurrency mode */
  460. rx_ant = first_antenna(rx_ant);
  461. }
  462. /* MIMO is not used here, but value is required */
  463. rx_chain |=
  464. hw_params(priv).valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  465. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  466. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  467. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  468. scan->rx_chain = cpu_to_le16(rx_chain);
  469. switch (priv->scan_type) {
  470. case IWL_SCAN_NORMAL:
  471. cmd_len = iwl_fill_probe_req(priv,
  472. (struct ieee80211_mgmt *)scan->data,
  473. vif->addr,
  474. priv->scan_request->ie,
  475. priv->scan_request->ie_len,
  476. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  477. break;
  478. case IWL_SCAN_RADIO_RESET:
  479. case IWL_SCAN_ROC:
  480. /* use bcast addr, will not be transmitted but must be valid */
  481. cmd_len = iwl_fill_probe_req(priv,
  482. (struct ieee80211_mgmt *)scan->data,
  483. iwl_bcast_addr, NULL, 0,
  484. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  485. break;
  486. default:
  487. BUG();
  488. }
  489. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  490. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  491. RXON_FILTER_BCON_AWARE_MSK);
  492. switch (priv->scan_type) {
  493. case IWL_SCAN_RADIO_RESET:
  494. scan->channel_count =
  495. iwl_get_single_channel_for_scan(priv, vif, band,
  496. (void *)&scan->data[cmd_len]);
  497. break;
  498. case IWL_SCAN_NORMAL:
  499. scan->channel_count =
  500. iwl_get_channels_for_scan(priv, vif, band,
  501. is_active, n_probes,
  502. (void *)&scan->data[cmd_len]);
  503. break;
  504. case IWL_SCAN_ROC: {
  505. struct iwl_scan_channel *scan_ch;
  506. scan->channel_count = 1;
  507. scan_ch = (void *)&scan->data[cmd_len];
  508. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  509. scan_ch->channel =
  510. cpu_to_le16(priv->hw_roc_channel->hw_value);
  511. scan_ch->active_dwell =
  512. scan_ch->passive_dwell =
  513. cpu_to_le16(priv->hw_roc_duration);
  514. /* Set txpower levels to defaults */
  515. scan_ch->dsp_atten = 110;
  516. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  517. * power level:
  518. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  519. */
  520. if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ)
  521. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  522. else
  523. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  524. }
  525. break;
  526. }
  527. if (scan->channel_count == 0) {
  528. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  529. return -EIO;
  530. }
  531. cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) +
  532. scan->channel_count * sizeof(struct iwl_scan_channel);
  533. cmd.data[0] = scan;
  534. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  535. scan->len = cpu_to_le16(cmd.len[0]);
  536. /* set scan bit here for PAN params */
  537. set_bit(STATUS_SCAN_HW, &priv->shrd->status);
  538. ret = iwlagn_set_pan_params(priv);
  539. if (ret)
  540. return ret;
  541. ret = iwl_trans_send_cmd(trans(priv), &cmd);
  542. if (ret) {
  543. clear_bit(STATUS_SCAN_HW, &priv->shrd->status);
  544. iwlagn_set_pan_params(priv);
  545. }
  546. return ret;
  547. }
  548. int iwlagn_manage_ibss_station(struct iwl_priv *priv,
  549. struct ieee80211_vif *vif, bool add)
  550. {
  551. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  552. if (add)
  553. return iwlagn_add_bssid_station(priv, vif_priv->ctx,
  554. vif->bss_conf.bssid,
  555. &vif_priv->ibss_bssid_sta_id);
  556. return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
  557. vif->bss_conf.bssid);
  558. }
  559. /**
  560. * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
  561. *
  562. * pre-requirements:
  563. * 1. acquire mutex before calling
  564. * 2. make sure rf is on and not in exit state
  565. */
  566. int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  567. {
  568. struct iwl_txfifo_flush_cmd flush_cmd;
  569. struct iwl_host_cmd cmd = {
  570. .id = REPLY_TXFIFO_FLUSH,
  571. .len = { sizeof(struct iwl_txfifo_flush_cmd), },
  572. .flags = CMD_SYNC,
  573. .data = { &flush_cmd, },
  574. };
  575. might_sleep();
  576. memset(&flush_cmd, 0, sizeof(flush_cmd));
  577. if (flush_control & BIT(IWL_RXON_CTX_BSS))
  578. flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK |
  579. IWL_SCD_BE_MSK | IWL_SCD_BK_MSK |
  580. IWL_SCD_MGMT_MSK;
  581. if ((flush_control & BIT(IWL_RXON_CTX_PAN)) &&
  582. (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS)))
  583. flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK |
  584. IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK |
  585. IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
  586. IWL_PAN_SCD_MULTICAST_MSK;
  587. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  588. flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
  589. IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
  590. flush_cmd.fifo_control);
  591. flush_cmd.flush_control = cpu_to_le16(flush_control);
  592. return iwl_trans_send_cmd(trans(priv), &cmd);
  593. }
  594. void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  595. {
  596. mutex_lock(&priv->shrd->mutex);
  597. ieee80211_stop_queues(priv->hw);
  598. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  599. IWL_ERR(priv, "flush request fail\n");
  600. goto done;
  601. }
  602. IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
  603. iwl_trans_wait_tx_queue_empty(trans(priv));
  604. done:
  605. ieee80211_wake_queues(priv->hw);
  606. mutex_unlock(&priv->shrd->mutex);
  607. }
  608. /*
  609. * BT coex
  610. */
  611. /*
  612. * Macros to access the lookup table.
  613. *
  614. * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
  615. * wifi_prio, wifi_txrx and wifi_sh_ant_req.
  616. *
  617. * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
  618. *
  619. * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
  620. * one after another in 32-bit registers, and "registers" 0 through 7 contain
  621. * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
  622. *
  623. * These macros encode that format.
  624. */
  625. #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
  626. wifi_txrx, wifi_sh_ant_req) \
  627. (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
  628. (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
  629. #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
  630. lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
  631. #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  632. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  633. (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
  634. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  635. wifi_sh_ant_req))))
  636. #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  637. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  638. LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
  639. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  640. wifi_sh_ant_req))
  641. #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
  642. wifi_req, wifi_prio, wifi_txrx, \
  643. wifi_sh_ant_req) \
  644. LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
  645. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  646. wifi_sh_ant_req))
  647. #define LUT_WLAN_KILL_OP(lut, op, val) \
  648. lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
  649. #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  650. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  651. (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  652. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
  653. #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  654. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  655. LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  656. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  657. #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  658. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  659. LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  660. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  661. #define LUT_ANT_SWITCH_OP(lut, op, val) \
  662. lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
  663. #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  664. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  665. (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  666. wifi_req, wifi_prio, wifi_txrx, \
  667. wifi_sh_ant_req))))
  668. #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  669. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  670. LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  671. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  672. #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  673. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  674. LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  675. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  676. static const __le32 iwlagn_def_3w_lookup[12] = {
  677. cpu_to_le32(0xaaaaaaaa),
  678. cpu_to_le32(0xaaaaaaaa),
  679. cpu_to_le32(0xaeaaaaaa),
  680. cpu_to_le32(0xaaaaaaaa),
  681. cpu_to_le32(0xcc00ff28),
  682. cpu_to_le32(0x0000aaaa),
  683. cpu_to_le32(0xcc00aaaa),
  684. cpu_to_le32(0x0000aaaa),
  685. cpu_to_le32(0xc0004000),
  686. cpu_to_le32(0x00004000),
  687. cpu_to_le32(0xf0005000),
  688. cpu_to_le32(0xf0005000),
  689. };
  690. static const __le32 iwlagn_concurrent_lookup[12] = {
  691. cpu_to_le32(0xaaaaaaaa),
  692. cpu_to_le32(0xaaaaaaaa),
  693. cpu_to_le32(0xaaaaaaaa),
  694. cpu_to_le32(0xaaaaaaaa),
  695. cpu_to_le32(0xaaaaaaaa),
  696. cpu_to_le32(0xaaaaaaaa),
  697. cpu_to_le32(0xaaaaaaaa),
  698. cpu_to_le32(0xaaaaaaaa),
  699. cpu_to_le32(0x00000000),
  700. cpu_to_le32(0x00000000),
  701. cpu_to_le32(0x00000000),
  702. cpu_to_le32(0x00000000),
  703. };
  704. void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
  705. {
  706. struct iwl_basic_bt_cmd basic = {
  707. .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
  708. .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
  709. .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
  710. .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
  711. };
  712. struct iwl6000_bt_cmd bt_cmd_6000;
  713. struct iwl2000_bt_cmd bt_cmd_2000;
  714. int ret;
  715. BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
  716. sizeof(basic.bt3_lookup_table));
  717. if (priv->cfg->bt_params) {
  718. if (priv->cfg->bt_params->bt_session_2) {
  719. bt_cmd_2000.prio_boost = cpu_to_le32(
  720. priv->cfg->bt_params->bt_prio_boost);
  721. bt_cmd_2000.tx_prio_boost = 0;
  722. bt_cmd_2000.rx_prio_boost = 0;
  723. } else {
  724. bt_cmd_6000.prio_boost =
  725. priv->cfg->bt_params->bt_prio_boost;
  726. bt_cmd_6000.tx_prio_boost = 0;
  727. bt_cmd_6000.rx_prio_boost = 0;
  728. }
  729. } else {
  730. IWL_ERR(priv, "failed to construct BT Coex Config\n");
  731. return;
  732. }
  733. basic.kill_ack_mask = priv->kill_ack_mask;
  734. basic.kill_cts_mask = priv->kill_cts_mask;
  735. basic.valid = priv->bt_valid;
  736. /*
  737. * Configure BT coex mode to "no coexistence" when the
  738. * user disabled BT coexistence, we have no interface
  739. * (might be in monitor mode), or the interface is in
  740. * IBSS mode (no proper uCode support for coex then).
  741. */
  742. if (!iwlagn_mod_params.bt_coex_active ||
  743. priv->iw_mode == NL80211_IFTYPE_ADHOC) {
  744. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
  745. } else {
  746. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
  747. IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
  748. if (!priv->bt_enable_pspoll)
  749. basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  750. else
  751. basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  752. if (priv->bt_ch_announce)
  753. basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
  754. IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags);
  755. }
  756. priv->bt_enable_flag = basic.flags;
  757. if (priv->bt_full_concurrent)
  758. memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
  759. sizeof(iwlagn_concurrent_lookup));
  760. else
  761. memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
  762. sizeof(iwlagn_def_3w_lookup));
  763. IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n",
  764. basic.flags ? "active" : "disabled",
  765. priv->bt_full_concurrent ?
  766. "full concurrency" : "3-wire");
  767. if (priv->cfg->bt_params->bt_session_2) {
  768. memcpy(&bt_cmd_2000.basic, &basic,
  769. sizeof(basic));
  770. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  771. CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000);
  772. } else {
  773. memcpy(&bt_cmd_6000.basic, &basic,
  774. sizeof(basic));
  775. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  776. CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000);
  777. }
  778. if (ret)
  779. IWL_ERR(priv, "failed to send BT Coex Config\n");
  780. }
  781. void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
  782. {
  783. struct iwl_rxon_context *ctx, *found_ctx = NULL;
  784. bool found_ap = false;
  785. lockdep_assert_held(&priv->shrd->mutex);
  786. /* Check whether AP or GO mode is active. */
  787. if (rssi_ena) {
  788. for_each_context(priv, ctx) {
  789. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP &&
  790. iwl_is_associated_ctx(ctx)) {
  791. found_ap = true;
  792. break;
  793. }
  794. }
  795. }
  796. /*
  797. * If disable was received or If GO/AP mode, disable RSSI
  798. * measurements.
  799. */
  800. if (!rssi_ena || found_ap) {
  801. if (priv->cur_rssi_ctx) {
  802. ctx = priv->cur_rssi_ctx;
  803. ieee80211_disable_rssi_reports(ctx->vif);
  804. priv->cur_rssi_ctx = NULL;
  805. }
  806. return;
  807. }
  808. /*
  809. * If rssi measurements need to be enabled, consider all cases now.
  810. * Figure out how many contexts are active.
  811. */
  812. for_each_context(priv, ctx) {
  813. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
  814. iwl_is_associated_ctx(ctx)) {
  815. found_ctx = ctx;
  816. break;
  817. }
  818. }
  819. /*
  820. * rssi monitor already enabled for the correct interface...nothing
  821. * to do.
  822. */
  823. if (found_ctx == priv->cur_rssi_ctx)
  824. return;
  825. /*
  826. * Figure out if rssi monitor is currently enabled, and needs
  827. * to be changed. If rssi monitor is already enabled, disable
  828. * it first else just enable rssi measurements on the
  829. * interface found above.
  830. */
  831. if (priv->cur_rssi_ctx) {
  832. ctx = priv->cur_rssi_ctx;
  833. if (ctx->vif)
  834. ieee80211_disable_rssi_reports(ctx->vif);
  835. }
  836. priv->cur_rssi_ctx = found_ctx;
  837. if (!found_ctx)
  838. return;
  839. ieee80211_enable_rssi_reports(found_ctx->vif,
  840. IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD,
  841. IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD);
  842. }
  843. static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
  844. {
  845. return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >>
  846. BT_UART_MSG_FRAME3SCOESCO_POS;
  847. }
  848. static void iwlagn_bt_traffic_change_work(struct work_struct *work)
  849. {
  850. struct iwl_priv *priv =
  851. container_of(work, struct iwl_priv, bt_traffic_change_work);
  852. struct iwl_rxon_context *ctx;
  853. int smps_request = -1;
  854. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  855. /* bt coex disabled */
  856. return;
  857. }
  858. /*
  859. * Note: bt_traffic_load can be overridden by scan complete and
  860. * coex profile notifications. Ignore that since only bad consequence
  861. * can be not matching debug print with actual state.
  862. */
  863. IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n",
  864. priv->bt_traffic_load);
  865. switch (priv->bt_traffic_load) {
  866. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  867. if (priv->bt_status)
  868. smps_request = IEEE80211_SMPS_DYNAMIC;
  869. else
  870. smps_request = IEEE80211_SMPS_AUTOMATIC;
  871. break;
  872. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  873. smps_request = IEEE80211_SMPS_DYNAMIC;
  874. break;
  875. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  876. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  877. smps_request = IEEE80211_SMPS_STATIC;
  878. break;
  879. default:
  880. IWL_ERR(priv, "Invalid BT traffic load: %d\n",
  881. priv->bt_traffic_load);
  882. break;
  883. }
  884. mutex_lock(&priv->shrd->mutex);
  885. /*
  886. * We can not send command to firmware while scanning. When the scan
  887. * complete we will schedule this work again. We do check with mutex
  888. * locked to prevent new scan request to arrive. We do not check
  889. * STATUS_SCANNING to avoid race when queue_work two times from
  890. * different notifications, but quit and not perform any work at all.
  891. */
  892. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status))
  893. goto out;
  894. iwl_update_chain_flags(priv);
  895. if (smps_request != -1) {
  896. priv->current_ht_config.smps = smps_request;
  897. for_each_context(priv, ctx) {
  898. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
  899. ieee80211_request_smps(ctx->vif, smps_request);
  900. }
  901. }
  902. /*
  903. * Dynamic PS poll related functionality. Adjust RSSI measurements if
  904. * necessary.
  905. */
  906. iwlagn_bt_coex_rssi_monitor(priv);
  907. out:
  908. mutex_unlock(&priv->shrd->mutex);
  909. }
  910. /*
  911. * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
  912. * correct interface or disable it if this is the last interface to be
  913. * removed.
  914. */
  915. void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv)
  916. {
  917. if (priv->bt_is_sco &&
  918. priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS)
  919. iwlagn_bt_adjust_rssi_monitor(priv, true);
  920. else
  921. iwlagn_bt_adjust_rssi_monitor(priv, false);
  922. }
  923. static void iwlagn_print_uartmsg(struct iwl_priv *priv,
  924. struct iwl_bt_uart_msg *uart_msg)
  925. {
  926. IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, "
  927. "Update Req = 0x%X",
  928. (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
  929. BT_UART_MSG_FRAME1MSGTYPE_POS,
  930. (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
  931. BT_UART_MSG_FRAME1SSN_POS,
  932. (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
  933. BT_UART_MSG_FRAME1UPDATEREQ_POS);
  934. IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
  935. "Chl_SeqN = 0x%X, In band = 0x%X",
  936. (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
  937. BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
  938. (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
  939. BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
  940. (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
  941. BT_UART_MSG_FRAME2CHLSEQN_POS,
  942. (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
  943. BT_UART_MSG_FRAME2INBAND_POS);
  944. IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
  945. "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
  946. (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
  947. BT_UART_MSG_FRAME3SCOESCO_POS,
  948. (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
  949. BT_UART_MSG_FRAME3SNIFF_POS,
  950. (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
  951. BT_UART_MSG_FRAME3A2DP_POS,
  952. (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
  953. BT_UART_MSG_FRAME3ACL_POS,
  954. (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
  955. BT_UART_MSG_FRAME3MASTER_POS,
  956. (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
  957. BT_UART_MSG_FRAME3OBEX_POS);
  958. IWL_DEBUG_COEX(priv, "Idle duration = 0x%X",
  959. (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
  960. BT_UART_MSG_FRAME4IDLEDURATION_POS);
  961. IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
  962. "eSCO Retransmissions = 0x%X",
  963. (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
  964. BT_UART_MSG_FRAME5TXACTIVITY_POS,
  965. (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
  966. BT_UART_MSG_FRAME5RXACTIVITY_POS,
  967. (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
  968. BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
  969. IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
  970. (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
  971. BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
  972. (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
  973. BT_UART_MSG_FRAME6DISCOVERABLE_POS);
  974. IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = "
  975. "0x%X, Inquiry = 0x%X, Connectable = 0x%X",
  976. (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
  977. BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
  978. (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
  979. BT_UART_MSG_FRAME7PAGE_POS,
  980. (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
  981. BT_UART_MSG_FRAME7INQUIRY_POS,
  982. (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
  983. BT_UART_MSG_FRAME7CONNECTABLE_POS);
  984. }
  985. static void iwlagn_set_kill_msk(struct iwl_priv *priv,
  986. struct iwl_bt_uart_msg *uart_msg)
  987. {
  988. u8 kill_msk;
  989. static const __le32 bt_kill_ack_msg[2] = {
  990. IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
  991. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  992. static const __le32 bt_kill_cts_msg[2] = {
  993. IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
  994. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  995. kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
  996. ? 1 : 0;
  997. if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
  998. priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
  999. priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
  1000. priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
  1001. priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
  1002. priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
  1003. /* schedule to send runtime bt_config */
  1004. queue_work(priv->shrd->workqueue, &priv->bt_runtime_config);
  1005. }
  1006. }
  1007. void iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
  1008. struct iwl_rx_mem_buffer *rxb)
  1009. {
  1010. unsigned long flags;
  1011. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1012. struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
  1013. struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
  1014. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  1015. /* bt coex disabled */
  1016. return;
  1017. }
  1018. IWL_DEBUG_COEX(priv, "BT Coex notification:\n");
  1019. IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status);
  1020. IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load);
  1021. IWL_DEBUG_COEX(priv, " CI compliance: %d\n",
  1022. coex->bt_ci_compliance);
  1023. iwlagn_print_uartmsg(priv, uart_msg);
  1024. priv->last_bt_traffic_load = priv->bt_traffic_load;
  1025. priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg);
  1026. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  1027. if (priv->bt_status != coex->bt_status ||
  1028. priv->last_bt_traffic_load != coex->bt_traffic_load) {
  1029. if (coex->bt_status) {
  1030. /* BT on */
  1031. if (!priv->bt_ch_announce)
  1032. priv->bt_traffic_load =
  1033. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1034. else
  1035. priv->bt_traffic_load =
  1036. coex->bt_traffic_load;
  1037. } else {
  1038. /* BT off */
  1039. priv->bt_traffic_load =
  1040. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  1041. }
  1042. priv->bt_status = coex->bt_status;
  1043. queue_work(priv->shrd->workqueue,
  1044. &priv->bt_traffic_change_work);
  1045. }
  1046. }
  1047. iwlagn_set_kill_msk(priv, uart_msg);
  1048. /* FIXME: based on notification, adjust the prio_boost */
  1049. spin_lock_irqsave(&priv->shrd->lock, flags);
  1050. priv->bt_ci_compliance = coex->bt_ci_compliance;
  1051. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  1052. }
  1053. void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
  1054. {
  1055. priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
  1056. iwlagn_bt_coex_profile_notif;
  1057. }
  1058. void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
  1059. {
  1060. INIT_WORK(&priv->bt_traffic_change_work,
  1061. iwlagn_bt_traffic_change_work);
  1062. }
  1063. void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
  1064. {
  1065. cancel_work_sync(&priv->bt_traffic_change_work);
  1066. }
  1067. static bool is_single_rx_stream(struct iwl_priv *priv)
  1068. {
  1069. return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  1070. priv->current_ht_config.single_chain_sufficient;
  1071. }
  1072. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  1073. #define IWL_NUM_RX_CHAINS_SINGLE 2
  1074. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  1075. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  1076. /*
  1077. * Determine how many receiver/antenna chains to use.
  1078. *
  1079. * More provides better reception via diversity. Fewer saves power
  1080. * at the expense of throughput, but only when not in powersave to
  1081. * start with.
  1082. *
  1083. * MIMO (dual stream) requires at least 2, but works better with 3.
  1084. * This does not determine *which* chains to use, just how many.
  1085. */
  1086. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  1087. {
  1088. if (priv->cfg->bt_params &&
  1089. priv->cfg->bt_params->advanced_bt_coexist &&
  1090. (priv->bt_full_concurrent ||
  1091. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1092. /*
  1093. * only use chain 'A' in bt high traffic load or
  1094. * full concurrency mode
  1095. */
  1096. return IWL_NUM_RX_CHAINS_SINGLE;
  1097. }
  1098. /* # of Rx chains to use when expecting MIMO. */
  1099. if (is_single_rx_stream(priv))
  1100. return IWL_NUM_RX_CHAINS_SINGLE;
  1101. else
  1102. return IWL_NUM_RX_CHAINS_MULTIPLE;
  1103. }
  1104. /*
  1105. * When we are in power saving mode, unless device support spatial
  1106. * multiplexing power save, use the active count for rx chain count.
  1107. */
  1108. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  1109. {
  1110. /* # Rx chains when idling, depending on SMPS mode */
  1111. switch (priv->current_ht_config.smps) {
  1112. case IEEE80211_SMPS_STATIC:
  1113. case IEEE80211_SMPS_DYNAMIC:
  1114. return IWL_NUM_IDLE_CHAINS_SINGLE;
  1115. case IEEE80211_SMPS_OFF:
  1116. return active_cnt;
  1117. default:
  1118. WARN(1, "invalid SMPS mode %d",
  1119. priv->current_ht_config.smps);
  1120. return active_cnt;
  1121. }
  1122. }
  1123. /* up to 4 chains */
  1124. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  1125. {
  1126. u8 res;
  1127. res = (chain_bitmap & BIT(0)) >> 0;
  1128. res += (chain_bitmap & BIT(1)) >> 1;
  1129. res += (chain_bitmap & BIT(2)) >> 2;
  1130. res += (chain_bitmap & BIT(3)) >> 3;
  1131. return res;
  1132. }
  1133. /**
  1134. * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  1135. *
  1136. * Selects how many and which Rx receivers/antennas/chains to use.
  1137. * This should not be used for scan command ... it puts data in wrong place.
  1138. */
  1139. void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1140. {
  1141. bool is_single = is_single_rx_stream(priv);
  1142. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->shrd->status);
  1143. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  1144. u32 active_chains;
  1145. u16 rx_chain;
  1146. /* Tell uCode which antennas are actually connected.
  1147. * Before first association, we assume all antennas are connected.
  1148. * Just after first association, iwl_chain_noise_calibration()
  1149. * checks which antennas actually *are* connected. */
  1150. if (priv->chain_noise_data.active_chains)
  1151. active_chains = priv->chain_noise_data.active_chains;
  1152. else
  1153. active_chains = hw_params(priv).valid_rx_ant;
  1154. if (priv->cfg->bt_params &&
  1155. priv->cfg->bt_params->advanced_bt_coexist &&
  1156. (priv->bt_full_concurrent ||
  1157. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1158. /*
  1159. * only use chain 'A' in bt high traffic load or
  1160. * full concurrency mode
  1161. */
  1162. active_chains = first_antenna(active_chains);
  1163. }
  1164. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  1165. /* How many receivers should we use? */
  1166. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  1167. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  1168. /* correct rx chain count according hw settings
  1169. * and chain noise calibration
  1170. */
  1171. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  1172. if (valid_rx_cnt < active_rx_cnt)
  1173. active_rx_cnt = valid_rx_cnt;
  1174. if (valid_rx_cnt < idle_rx_cnt)
  1175. idle_rx_cnt = valid_rx_cnt;
  1176. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  1177. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  1178. ctx->staging.rx_chain = cpu_to_le16(rx_chain);
  1179. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  1180. ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1181. else
  1182. ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1183. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  1184. ctx->staging.rx_chain,
  1185. active_rx_cnt, idle_rx_cnt);
  1186. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  1187. active_rx_cnt < idle_rx_cnt);
  1188. }
  1189. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
  1190. {
  1191. int i;
  1192. u8 ind = ant;
  1193. if (priv->band == IEEE80211_BAND_2GHZ &&
  1194. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
  1195. return 0;
  1196. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  1197. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  1198. if (valid & BIT(ind))
  1199. return ind;
  1200. }
  1201. return ant;
  1202. }
  1203. /* notification wait support */
  1204. void iwlagn_init_notification_wait(struct iwl_priv *priv,
  1205. struct iwl_notification_wait *wait_entry,
  1206. u8 cmd,
  1207. void (*fn)(struct iwl_priv *priv,
  1208. struct iwl_rx_packet *pkt,
  1209. void *data),
  1210. void *fn_data)
  1211. {
  1212. wait_entry->fn = fn;
  1213. wait_entry->fn_data = fn_data;
  1214. wait_entry->cmd = cmd;
  1215. wait_entry->triggered = false;
  1216. wait_entry->aborted = false;
  1217. spin_lock_bh(&priv->notif_wait_lock);
  1218. list_add(&wait_entry->list, &priv->notif_waits);
  1219. spin_unlock_bh(&priv->notif_wait_lock);
  1220. }
  1221. int iwlagn_wait_notification(struct iwl_priv *priv,
  1222. struct iwl_notification_wait *wait_entry,
  1223. unsigned long timeout)
  1224. {
  1225. int ret;
  1226. ret = wait_event_timeout(priv->notif_waitq,
  1227. wait_entry->triggered || wait_entry->aborted,
  1228. timeout);
  1229. spin_lock_bh(&priv->notif_wait_lock);
  1230. list_del(&wait_entry->list);
  1231. spin_unlock_bh(&priv->notif_wait_lock);
  1232. if (wait_entry->aborted)
  1233. return -EIO;
  1234. /* return value is always >= 0 */
  1235. if (ret <= 0)
  1236. return -ETIMEDOUT;
  1237. return 0;
  1238. }
  1239. void iwlagn_remove_notification(struct iwl_priv *priv,
  1240. struct iwl_notification_wait *wait_entry)
  1241. {
  1242. spin_lock_bh(&priv->notif_wait_lock);
  1243. list_del(&wait_entry->list);
  1244. spin_unlock_bh(&priv->notif_wait_lock);
  1245. }