iwl-agn-lib.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  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. #define IWL_FLUSH_WAIT_MS 2000
  560. int iwlagn_wait_tx_queue_empty(struct iwl_priv *priv)
  561. {
  562. struct iwl_tx_queue *txq;
  563. struct iwl_queue *q;
  564. int cnt;
  565. unsigned long now = jiffies;
  566. int ret = 0;
  567. /* waiting for all the tx frames complete might take a while */
  568. for (cnt = 0; cnt < hw_params(priv).max_txq_num; cnt++) {
  569. if (cnt == priv->shrd->cmd_queue)
  570. continue;
  571. txq = &priv->txq[cnt];
  572. q = &txq->q;
  573. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  574. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  575. msleep(1);
  576. if (q->read_ptr != q->write_ptr) {
  577. IWL_ERR(priv, "fail to flush all tx fifo queues\n");
  578. ret = -ETIMEDOUT;
  579. break;
  580. }
  581. }
  582. return ret;
  583. }
  584. #define IWL_TX_QUEUE_MSK 0xfffff
  585. /**
  586. * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
  587. *
  588. * pre-requirements:
  589. * 1. acquire mutex before calling
  590. * 2. make sure rf is on and not in exit state
  591. */
  592. int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  593. {
  594. struct iwl_txfifo_flush_cmd flush_cmd;
  595. struct iwl_host_cmd cmd = {
  596. .id = REPLY_TXFIFO_FLUSH,
  597. .len = { sizeof(struct iwl_txfifo_flush_cmd), },
  598. .flags = CMD_SYNC,
  599. .data = { &flush_cmd, },
  600. };
  601. might_sleep();
  602. memset(&flush_cmd, 0, sizeof(flush_cmd));
  603. if (flush_control & BIT(IWL_RXON_CTX_BSS))
  604. flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK |
  605. IWL_SCD_BE_MSK | IWL_SCD_BK_MSK |
  606. IWL_SCD_MGMT_MSK;
  607. if ((flush_control & BIT(IWL_RXON_CTX_PAN)) &&
  608. (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS)))
  609. flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK |
  610. IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK |
  611. IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
  612. IWL_PAN_SCD_MULTICAST_MSK;
  613. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  614. flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
  615. IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
  616. flush_cmd.fifo_control);
  617. flush_cmd.flush_control = cpu_to_le16(flush_control);
  618. return iwl_trans_send_cmd(trans(priv), &cmd);
  619. }
  620. void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  621. {
  622. mutex_lock(&priv->shrd->mutex);
  623. ieee80211_stop_queues(priv->hw);
  624. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  625. IWL_ERR(priv, "flush request fail\n");
  626. goto done;
  627. }
  628. IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
  629. iwlagn_wait_tx_queue_empty(priv);
  630. done:
  631. ieee80211_wake_queues(priv->hw);
  632. mutex_unlock(&priv->shrd->mutex);
  633. }
  634. /*
  635. * BT coex
  636. */
  637. /*
  638. * Macros to access the lookup table.
  639. *
  640. * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
  641. * wifi_prio, wifi_txrx and wifi_sh_ant_req.
  642. *
  643. * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
  644. *
  645. * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
  646. * one after another in 32-bit registers, and "registers" 0 through 7 contain
  647. * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
  648. *
  649. * These macros encode that format.
  650. */
  651. #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
  652. wifi_txrx, wifi_sh_ant_req) \
  653. (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
  654. (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
  655. #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
  656. lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
  657. #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  658. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  659. (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
  660. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  661. wifi_sh_ant_req))))
  662. #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  663. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  664. LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
  665. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  666. wifi_sh_ant_req))
  667. #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
  668. wifi_req, wifi_prio, wifi_txrx, \
  669. wifi_sh_ant_req) \
  670. LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
  671. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  672. wifi_sh_ant_req))
  673. #define LUT_WLAN_KILL_OP(lut, op, val) \
  674. lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
  675. #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  676. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  677. (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  678. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
  679. #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  680. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  681. LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  682. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  683. #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  684. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  685. LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  686. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  687. #define LUT_ANT_SWITCH_OP(lut, op, val) \
  688. lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
  689. #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  690. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  691. (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  692. wifi_req, wifi_prio, wifi_txrx, \
  693. wifi_sh_ant_req))))
  694. #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  695. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  696. LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  697. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  698. #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  699. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  700. LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  701. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  702. static const __le32 iwlagn_def_3w_lookup[12] = {
  703. cpu_to_le32(0xaaaaaaaa),
  704. cpu_to_le32(0xaaaaaaaa),
  705. cpu_to_le32(0xaeaaaaaa),
  706. cpu_to_le32(0xaaaaaaaa),
  707. cpu_to_le32(0xcc00ff28),
  708. cpu_to_le32(0x0000aaaa),
  709. cpu_to_le32(0xcc00aaaa),
  710. cpu_to_le32(0x0000aaaa),
  711. cpu_to_le32(0xc0004000),
  712. cpu_to_le32(0x00004000),
  713. cpu_to_le32(0xf0005000),
  714. cpu_to_le32(0xf0005000),
  715. };
  716. static const __le32 iwlagn_concurrent_lookup[12] = {
  717. cpu_to_le32(0xaaaaaaaa),
  718. cpu_to_le32(0xaaaaaaaa),
  719. cpu_to_le32(0xaaaaaaaa),
  720. cpu_to_le32(0xaaaaaaaa),
  721. cpu_to_le32(0xaaaaaaaa),
  722. cpu_to_le32(0xaaaaaaaa),
  723. cpu_to_le32(0xaaaaaaaa),
  724. cpu_to_le32(0xaaaaaaaa),
  725. cpu_to_le32(0x00000000),
  726. cpu_to_le32(0x00000000),
  727. cpu_to_le32(0x00000000),
  728. cpu_to_le32(0x00000000),
  729. };
  730. void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
  731. {
  732. struct iwl_basic_bt_cmd basic = {
  733. .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
  734. .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
  735. .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
  736. .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
  737. };
  738. struct iwl6000_bt_cmd bt_cmd_6000;
  739. struct iwl2000_bt_cmd bt_cmd_2000;
  740. int ret;
  741. BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
  742. sizeof(basic.bt3_lookup_table));
  743. if (priv->cfg->bt_params) {
  744. if (priv->cfg->bt_params->bt_session_2) {
  745. bt_cmd_2000.prio_boost = cpu_to_le32(
  746. priv->cfg->bt_params->bt_prio_boost);
  747. bt_cmd_2000.tx_prio_boost = 0;
  748. bt_cmd_2000.rx_prio_boost = 0;
  749. } else {
  750. bt_cmd_6000.prio_boost =
  751. priv->cfg->bt_params->bt_prio_boost;
  752. bt_cmd_6000.tx_prio_boost = 0;
  753. bt_cmd_6000.rx_prio_boost = 0;
  754. }
  755. } else {
  756. IWL_ERR(priv, "failed to construct BT Coex Config\n");
  757. return;
  758. }
  759. basic.kill_ack_mask = priv->kill_ack_mask;
  760. basic.kill_cts_mask = priv->kill_cts_mask;
  761. basic.valid = priv->bt_valid;
  762. /*
  763. * Configure BT coex mode to "no coexistence" when the
  764. * user disabled BT coexistence, we have no interface
  765. * (might be in monitor mode), or the interface is in
  766. * IBSS mode (no proper uCode support for coex then).
  767. */
  768. if (!iwlagn_mod_params.bt_coex_active ||
  769. priv->iw_mode == NL80211_IFTYPE_ADHOC) {
  770. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
  771. } else {
  772. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
  773. IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
  774. if (!priv->bt_enable_pspoll)
  775. basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  776. else
  777. basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  778. if (priv->bt_ch_announce)
  779. basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
  780. IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags);
  781. }
  782. priv->bt_enable_flag = basic.flags;
  783. if (priv->bt_full_concurrent)
  784. memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
  785. sizeof(iwlagn_concurrent_lookup));
  786. else
  787. memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
  788. sizeof(iwlagn_def_3w_lookup));
  789. IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n",
  790. basic.flags ? "active" : "disabled",
  791. priv->bt_full_concurrent ?
  792. "full concurrency" : "3-wire");
  793. if (priv->cfg->bt_params->bt_session_2) {
  794. memcpy(&bt_cmd_2000.basic, &basic,
  795. sizeof(basic));
  796. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  797. CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000);
  798. } else {
  799. memcpy(&bt_cmd_6000.basic, &basic,
  800. sizeof(basic));
  801. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  802. CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000);
  803. }
  804. if (ret)
  805. IWL_ERR(priv, "failed to send BT Coex Config\n");
  806. }
  807. void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
  808. {
  809. struct iwl_rxon_context *ctx, *found_ctx = NULL;
  810. bool found_ap = false;
  811. lockdep_assert_held(&priv->shrd->mutex);
  812. /* Check whether AP or GO mode is active. */
  813. if (rssi_ena) {
  814. for_each_context(priv, ctx) {
  815. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP &&
  816. iwl_is_associated_ctx(ctx)) {
  817. found_ap = true;
  818. break;
  819. }
  820. }
  821. }
  822. /*
  823. * If disable was received or If GO/AP mode, disable RSSI
  824. * measurements.
  825. */
  826. if (!rssi_ena || found_ap) {
  827. if (priv->cur_rssi_ctx) {
  828. ctx = priv->cur_rssi_ctx;
  829. ieee80211_disable_rssi_reports(ctx->vif);
  830. priv->cur_rssi_ctx = NULL;
  831. }
  832. return;
  833. }
  834. /*
  835. * If rssi measurements need to be enabled, consider all cases now.
  836. * Figure out how many contexts are active.
  837. */
  838. for_each_context(priv, ctx) {
  839. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
  840. iwl_is_associated_ctx(ctx)) {
  841. found_ctx = ctx;
  842. break;
  843. }
  844. }
  845. /*
  846. * rssi monitor already enabled for the correct interface...nothing
  847. * to do.
  848. */
  849. if (found_ctx == priv->cur_rssi_ctx)
  850. return;
  851. /*
  852. * Figure out if rssi monitor is currently enabled, and needs
  853. * to be changed. If rssi monitor is already enabled, disable
  854. * it first else just enable rssi measurements on the
  855. * interface found above.
  856. */
  857. if (priv->cur_rssi_ctx) {
  858. ctx = priv->cur_rssi_ctx;
  859. if (ctx->vif)
  860. ieee80211_disable_rssi_reports(ctx->vif);
  861. }
  862. priv->cur_rssi_ctx = found_ctx;
  863. if (!found_ctx)
  864. return;
  865. ieee80211_enable_rssi_reports(found_ctx->vif,
  866. IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD,
  867. IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD);
  868. }
  869. static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
  870. {
  871. return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >>
  872. BT_UART_MSG_FRAME3SCOESCO_POS;
  873. }
  874. static void iwlagn_bt_traffic_change_work(struct work_struct *work)
  875. {
  876. struct iwl_priv *priv =
  877. container_of(work, struct iwl_priv, bt_traffic_change_work);
  878. struct iwl_rxon_context *ctx;
  879. int smps_request = -1;
  880. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  881. /* bt coex disabled */
  882. return;
  883. }
  884. /*
  885. * Note: bt_traffic_load can be overridden by scan complete and
  886. * coex profile notifications. Ignore that since only bad consequence
  887. * can be not matching debug print with actual state.
  888. */
  889. IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n",
  890. priv->bt_traffic_load);
  891. switch (priv->bt_traffic_load) {
  892. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  893. if (priv->bt_status)
  894. smps_request = IEEE80211_SMPS_DYNAMIC;
  895. else
  896. smps_request = IEEE80211_SMPS_AUTOMATIC;
  897. break;
  898. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  899. smps_request = IEEE80211_SMPS_DYNAMIC;
  900. break;
  901. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  902. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  903. smps_request = IEEE80211_SMPS_STATIC;
  904. break;
  905. default:
  906. IWL_ERR(priv, "Invalid BT traffic load: %d\n",
  907. priv->bt_traffic_load);
  908. break;
  909. }
  910. mutex_lock(&priv->shrd->mutex);
  911. /*
  912. * We can not send command to firmware while scanning. When the scan
  913. * complete we will schedule this work again. We do check with mutex
  914. * locked to prevent new scan request to arrive. We do not check
  915. * STATUS_SCANNING to avoid race when queue_work two times from
  916. * different notifications, but quit and not perform any work at all.
  917. */
  918. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status))
  919. goto out;
  920. iwl_update_chain_flags(priv);
  921. if (smps_request != -1) {
  922. priv->current_ht_config.smps = smps_request;
  923. for_each_context(priv, ctx) {
  924. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
  925. ieee80211_request_smps(ctx->vif, smps_request);
  926. }
  927. }
  928. /*
  929. * Dynamic PS poll related functionality. Adjust RSSI measurements if
  930. * necessary.
  931. */
  932. iwlagn_bt_coex_rssi_monitor(priv);
  933. out:
  934. mutex_unlock(&priv->shrd->mutex);
  935. }
  936. /*
  937. * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
  938. * correct interface or disable it if this is the last interface to be
  939. * removed.
  940. */
  941. void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv)
  942. {
  943. if (priv->bt_is_sco &&
  944. priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS)
  945. iwlagn_bt_adjust_rssi_monitor(priv, true);
  946. else
  947. iwlagn_bt_adjust_rssi_monitor(priv, false);
  948. }
  949. static void iwlagn_print_uartmsg(struct iwl_priv *priv,
  950. struct iwl_bt_uart_msg *uart_msg)
  951. {
  952. IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, "
  953. "Update Req = 0x%X",
  954. (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
  955. BT_UART_MSG_FRAME1MSGTYPE_POS,
  956. (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
  957. BT_UART_MSG_FRAME1SSN_POS,
  958. (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
  959. BT_UART_MSG_FRAME1UPDATEREQ_POS);
  960. IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
  961. "Chl_SeqN = 0x%X, In band = 0x%X",
  962. (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
  963. BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
  964. (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
  965. BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
  966. (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
  967. BT_UART_MSG_FRAME2CHLSEQN_POS,
  968. (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
  969. BT_UART_MSG_FRAME2INBAND_POS);
  970. IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
  971. "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
  972. (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
  973. BT_UART_MSG_FRAME3SCOESCO_POS,
  974. (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
  975. BT_UART_MSG_FRAME3SNIFF_POS,
  976. (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
  977. BT_UART_MSG_FRAME3A2DP_POS,
  978. (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
  979. BT_UART_MSG_FRAME3ACL_POS,
  980. (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
  981. BT_UART_MSG_FRAME3MASTER_POS,
  982. (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
  983. BT_UART_MSG_FRAME3OBEX_POS);
  984. IWL_DEBUG_COEX(priv, "Idle duration = 0x%X",
  985. (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
  986. BT_UART_MSG_FRAME4IDLEDURATION_POS);
  987. IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
  988. "eSCO Retransmissions = 0x%X",
  989. (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
  990. BT_UART_MSG_FRAME5TXACTIVITY_POS,
  991. (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
  992. BT_UART_MSG_FRAME5RXACTIVITY_POS,
  993. (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
  994. BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
  995. IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
  996. (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
  997. BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
  998. (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
  999. BT_UART_MSG_FRAME6DISCOVERABLE_POS);
  1000. IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = "
  1001. "0x%X, Inquiry = 0x%X, Connectable = 0x%X",
  1002. (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
  1003. BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
  1004. (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
  1005. BT_UART_MSG_FRAME7PAGE_POS,
  1006. (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
  1007. BT_UART_MSG_FRAME7INQUIRY_POS,
  1008. (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
  1009. BT_UART_MSG_FRAME7CONNECTABLE_POS);
  1010. }
  1011. static void iwlagn_set_kill_msk(struct iwl_priv *priv,
  1012. struct iwl_bt_uart_msg *uart_msg)
  1013. {
  1014. u8 kill_msk;
  1015. static const __le32 bt_kill_ack_msg[2] = {
  1016. IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
  1017. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  1018. static const __le32 bt_kill_cts_msg[2] = {
  1019. IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
  1020. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  1021. kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
  1022. ? 1 : 0;
  1023. if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
  1024. priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
  1025. priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
  1026. priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
  1027. priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
  1028. priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
  1029. /* schedule to send runtime bt_config */
  1030. queue_work(priv->shrd->workqueue, &priv->bt_runtime_config);
  1031. }
  1032. }
  1033. void iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
  1034. struct iwl_rx_mem_buffer *rxb)
  1035. {
  1036. unsigned long flags;
  1037. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1038. struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
  1039. struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
  1040. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  1041. /* bt coex disabled */
  1042. return;
  1043. }
  1044. IWL_DEBUG_COEX(priv, "BT Coex notification:\n");
  1045. IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status);
  1046. IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load);
  1047. IWL_DEBUG_COEX(priv, " CI compliance: %d\n",
  1048. coex->bt_ci_compliance);
  1049. iwlagn_print_uartmsg(priv, uart_msg);
  1050. priv->last_bt_traffic_load = priv->bt_traffic_load;
  1051. priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg);
  1052. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  1053. if (priv->bt_status != coex->bt_status ||
  1054. priv->last_bt_traffic_load != coex->bt_traffic_load) {
  1055. if (coex->bt_status) {
  1056. /* BT on */
  1057. if (!priv->bt_ch_announce)
  1058. priv->bt_traffic_load =
  1059. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1060. else
  1061. priv->bt_traffic_load =
  1062. coex->bt_traffic_load;
  1063. } else {
  1064. /* BT off */
  1065. priv->bt_traffic_load =
  1066. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  1067. }
  1068. priv->bt_status = coex->bt_status;
  1069. queue_work(priv->shrd->workqueue,
  1070. &priv->bt_traffic_change_work);
  1071. }
  1072. }
  1073. iwlagn_set_kill_msk(priv, uart_msg);
  1074. /* FIXME: based on notification, adjust the prio_boost */
  1075. spin_lock_irqsave(&priv->shrd->lock, flags);
  1076. priv->bt_ci_compliance = coex->bt_ci_compliance;
  1077. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  1078. }
  1079. void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
  1080. {
  1081. priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
  1082. iwlagn_bt_coex_profile_notif;
  1083. }
  1084. void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
  1085. {
  1086. INIT_WORK(&priv->bt_traffic_change_work,
  1087. iwlagn_bt_traffic_change_work);
  1088. }
  1089. void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
  1090. {
  1091. cancel_work_sync(&priv->bt_traffic_change_work);
  1092. }
  1093. static bool is_single_rx_stream(struct iwl_priv *priv)
  1094. {
  1095. return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  1096. priv->current_ht_config.single_chain_sufficient;
  1097. }
  1098. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  1099. #define IWL_NUM_RX_CHAINS_SINGLE 2
  1100. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  1101. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  1102. /*
  1103. * Determine how many receiver/antenna chains to use.
  1104. *
  1105. * More provides better reception via diversity. Fewer saves power
  1106. * at the expense of throughput, but only when not in powersave to
  1107. * start with.
  1108. *
  1109. * MIMO (dual stream) requires at least 2, but works better with 3.
  1110. * This does not determine *which* chains to use, just how many.
  1111. */
  1112. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  1113. {
  1114. if (priv->cfg->bt_params &&
  1115. priv->cfg->bt_params->advanced_bt_coexist &&
  1116. (priv->bt_full_concurrent ||
  1117. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1118. /*
  1119. * only use chain 'A' in bt high traffic load or
  1120. * full concurrency mode
  1121. */
  1122. return IWL_NUM_RX_CHAINS_SINGLE;
  1123. }
  1124. /* # of Rx chains to use when expecting MIMO. */
  1125. if (is_single_rx_stream(priv))
  1126. return IWL_NUM_RX_CHAINS_SINGLE;
  1127. else
  1128. return IWL_NUM_RX_CHAINS_MULTIPLE;
  1129. }
  1130. /*
  1131. * When we are in power saving mode, unless device support spatial
  1132. * multiplexing power save, use the active count for rx chain count.
  1133. */
  1134. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  1135. {
  1136. /* # Rx chains when idling, depending on SMPS mode */
  1137. switch (priv->current_ht_config.smps) {
  1138. case IEEE80211_SMPS_STATIC:
  1139. case IEEE80211_SMPS_DYNAMIC:
  1140. return IWL_NUM_IDLE_CHAINS_SINGLE;
  1141. case IEEE80211_SMPS_OFF:
  1142. return active_cnt;
  1143. default:
  1144. WARN(1, "invalid SMPS mode %d",
  1145. priv->current_ht_config.smps);
  1146. return active_cnt;
  1147. }
  1148. }
  1149. /* up to 4 chains */
  1150. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  1151. {
  1152. u8 res;
  1153. res = (chain_bitmap & BIT(0)) >> 0;
  1154. res += (chain_bitmap & BIT(1)) >> 1;
  1155. res += (chain_bitmap & BIT(2)) >> 2;
  1156. res += (chain_bitmap & BIT(3)) >> 3;
  1157. return res;
  1158. }
  1159. /**
  1160. * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  1161. *
  1162. * Selects how many and which Rx receivers/antennas/chains to use.
  1163. * This should not be used for scan command ... it puts data in wrong place.
  1164. */
  1165. void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1166. {
  1167. bool is_single = is_single_rx_stream(priv);
  1168. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->shrd->status);
  1169. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  1170. u32 active_chains;
  1171. u16 rx_chain;
  1172. /* Tell uCode which antennas are actually connected.
  1173. * Before first association, we assume all antennas are connected.
  1174. * Just after first association, iwl_chain_noise_calibration()
  1175. * checks which antennas actually *are* connected. */
  1176. if (priv->chain_noise_data.active_chains)
  1177. active_chains = priv->chain_noise_data.active_chains;
  1178. else
  1179. active_chains = hw_params(priv).valid_rx_ant;
  1180. if (priv->cfg->bt_params &&
  1181. priv->cfg->bt_params->advanced_bt_coexist &&
  1182. (priv->bt_full_concurrent ||
  1183. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1184. /*
  1185. * only use chain 'A' in bt high traffic load or
  1186. * full concurrency mode
  1187. */
  1188. active_chains = first_antenna(active_chains);
  1189. }
  1190. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  1191. /* How many receivers should we use? */
  1192. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  1193. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  1194. /* correct rx chain count according hw settings
  1195. * and chain noise calibration
  1196. */
  1197. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  1198. if (valid_rx_cnt < active_rx_cnt)
  1199. active_rx_cnt = valid_rx_cnt;
  1200. if (valid_rx_cnt < idle_rx_cnt)
  1201. idle_rx_cnt = valid_rx_cnt;
  1202. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  1203. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  1204. ctx->staging.rx_chain = cpu_to_le16(rx_chain);
  1205. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  1206. ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1207. else
  1208. ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1209. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  1210. ctx->staging.rx_chain,
  1211. active_rx_cnt, idle_rx_cnt);
  1212. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  1213. active_rx_cnt < idle_rx_cnt);
  1214. }
  1215. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
  1216. {
  1217. int i;
  1218. u8 ind = ant;
  1219. if (priv->band == IEEE80211_BAND_2GHZ &&
  1220. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
  1221. return 0;
  1222. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  1223. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  1224. if (valid & BIT(ind))
  1225. return ind;
  1226. }
  1227. return ant;
  1228. }
  1229. /* notification wait support */
  1230. void iwlagn_init_notification_wait(struct iwl_priv *priv,
  1231. struct iwl_notification_wait *wait_entry,
  1232. u8 cmd,
  1233. void (*fn)(struct iwl_priv *priv,
  1234. struct iwl_rx_packet *pkt,
  1235. void *data),
  1236. void *fn_data)
  1237. {
  1238. wait_entry->fn = fn;
  1239. wait_entry->fn_data = fn_data;
  1240. wait_entry->cmd = cmd;
  1241. wait_entry->triggered = false;
  1242. wait_entry->aborted = false;
  1243. spin_lock_bh(&priv->notif_wait_lock);
  1244. list_add(&wait_entry->list, &priv->notif_waits);
  1245. spin_unlock_bh(&priv->notif_wait_lock);
  1246. }
  1247. int iwlagn_wait_notification(struct iwl_priv *priv,
  1248. struct iwl_notification_wait *wait_entry,
  1249. unsigned long timeout)
  1250. {
  1251. int ret;
  1252. ret = wait_event_timeout(priv->notif_waitq,
  1253. wait_entry->triggered || wait_entry->aborted,
  1254. timeout);
  1255. spin_lock_bh(&priv->notif_wait_lock);
  1256. list_del(&wait_entry->list);
  1257. spin_unlock_bh(&priv->notif_wait_lock);
  1258. if (wait_entry->aborted)
  1259. return -EIO;
  1260. /* return value is always >= 0 */
  1261. if (ret <= 0)
  1262. return -ETIMEDOUT;
  1263. return 0;
  1264. }
  1265. void iwlagn_remove_notification(struct iwl_priv *priv,
  1266. struct iwl_notification_wait *wait_entry)
  1267. {
  1268. spin_lock_bh(&priv->notif_wait_lock);
  1269. list_del(&wait_entry->list);
  1270. spin_unlock_bh(&priv->notif_wait_lock);
  1271. }