iwl-agn-lib.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 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. static inline u32 iwlagn_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
  42. {
  43. return le32_to_cpup((__le32 *)&tx_resp->status +
  44. tx_resp->frame_count) & MAX_SN;
  45. }
  46. static void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status)
  47. {
  48. status &= TX_STATUS_MSK;
  49. switch (status) {
  50. case TX_STATUS_POSTPONE_DELAY:
  51. priv->_agn.reply_tx_stats.pp_delay++;
  52. break;
  53. case TX_STATUS_POSTPONE_FEW_BYTES:
  54. priv->_agn.reply_tx_stats.pp_few_bytes++;
  55. break;
  56. case TX_STATUS_POSTPONE_BT_PRIO:
  57. priv->_agn.reply_tx_stats.pp_bt_prio++;
  58. break;
  59. case TX_STATUS_POSTPONE_QUIET_PERIOD:
  60. priv->_agn.reply_tx_stats.pp_quiet_period++;
  61. break;
  62. case TX_STATUS_POSTPONE_CALC_TTAK:
  63. priv->_agn.reply_tx_stats.pp_calc_ttak++;
  64. break;
  65. case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY:
  66. priv->_agn.reply_tx_stats.int_crossed_retry++;
  67. break;
  68. case TX_STATUS_FAIL_SHORT_LIMIT:
  69. priv->_agn.reply_tx_stats.short_limit++;
  70. break;
  71. case TX_STATUS_FAIL_LONG_LIMIT:
  72. priv->_agn.reply_tx_stats.long_limit++;
  73. break;
  74. case TX_STATUS_FAIL_FIFO_UNDERRUN:
  75. priv->_agn.reply_tx_stats.fifo_underrun++;
  76. break;
  77. case TX_STATUS_FAIL_DRAIN_FLOW:
  78. priv->_agn.reply_tx_stats.drain_flow++;
  79. break;
  80. case TX_STATUS_FAIL_RFKILL_FLUSH:
  81. priv->_agn.reply_tx_stats.rfkill_flush++;
  82. break;
  83. case TX_STATUS_FAIL_LIFE_EXPIRE:
  84. priv->_agn.reply_tx_stats.life_expire++;
  85. break;
  86. case TX_STATUS_FAIL_DEST_PS:
  87. priv->_agn.reply_tx_stats.dest_ps++;
  88. break;
  89. case TX_STATUS_FAIL_HOST_ABORTED:
  90. priv->_agn.reply_tx_stats.host_abort++;
  91. break;
  92. case TX_STATUS_FAIL_BT_RETRY:
  93. priv->_agn.reply_tx_stats.bt_retry++;
  94. break;
  95. case TX_STATUS_FAIL_STA_INVALID:
  96. priv->_agn.reply_tx_stats.sta_invalid++;
  97. break;
  98. case TX_STATUS_FAIL_FRAG_DROPPED:
  99. priv->_agn.reply_tx_stats.frag_drop++;
  100. break;
  101. case TX_STATUS_FAIL_TID_DISABLE:
  102. priv->_agn.reply_tx_stats.tid_disable++;
  103. break;
  104. case TX_STATUS_FAIL_FIFO_FLUSHED:
  105. priv->_agn.reply_tx_stats.fifo_flush++;
  106. break;
  107. case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL:
  108. priv->_agn.reply_tx_stats.insuff_cf_poll++;
  109. break;
  110. case TX_STATUS_FAIL_PASSIVE_NO_RX:
  111. priv->_agn.reply_tx_stats.fail_hw_drop++;
  112. break;
  113. case TX_STATUS_FAIL_NO_BEACON_ON_RADAR:
  114. priv->_agn.reply_tx_stats.sta_color_mismatch++;
  115. break;
  116. default:
  117. priv->_agn.reply_tx_stats.unknown++;
  118. break;
  119. }
  120. }
  121. static void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status)
  122. {
  123. status &= AGG_TX_STATUS_MSK;
  124. switch (status) {
  125. case AGG_TX_STATE_UNDERRUN_MSK:
  126. priv->_agn.reply_agg_tx_stats.underrun++;
  127. break;
  128. case AGG_TX_STATE_BT_PRIO_MSK:
  129. priv->_agn.reply_agg_tx_stats.bt_prio++;
  130. break;
  131. case AGG_TX_STATE_FEW_BYTES_MSK:
  132. priv->_agn.reply_agg_tx_stats.few_bytes++;
  133. break;
  134. case AGG_TX_STATE_ABORT_MSK:
  135. priv->_agn.reply_agg_tx_stats.abort++;
  136. break;
  137. case AGG_TX_STATE_LAST_SENT_TTL_MSK:
  138. priv->_agn.reply_agg_tx_stats.last_sent_ttl++;
  139. break;
  140. case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK:
  141. priv->_agn.reply_agg_tx_stats.last_sent_try++;
  142. break;
  143. case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK:
  144. priv->_agn.reply_agg_tx_stats.last_sent_bt_kill++;
  145. break;
  146. case AGG_TX_STATE_SCD_QUERY_MSK:
  147. priv->_agn.reply_agg_tx_stats.scd_query++;
  148. break;
  149. case AGG_TX_STATE_TEST_BAD_CRC32_MSK:
  150. priv->_agn.reply_agg_tx_stats.bad_crc32++;
  151. break;
  152. case AGG_TX_STATE_RESPONSE_MSK:
  153. priv->_agn.reply_agg_tx_stats.response++;
  154. break;
  155. case AGG_TX_STATE_DUMP_TX_MSK:
  156. priv->_agn.reply_agg_tx_stats.dump_tx++;
  157. break;
  158. case AGG_TX_STATE_DELAY_TX_MSK:
  159. priv->_agn.reply_agg_tx_stats.delay_tx++;
  160. break;
  161. default:
  162. priv->_agn.reply_agg_tx_stats.unknown++;
  163. break;
  164. }
  165. }
  166. static void iwlagn_set_tx_status(struct iwl_priv *priv,
  167. struct ieee80211_tx_info *info,
  168. struct iwl5000_tx_resp *tx_resp,
  169. int txq_id, bool is_agg)
  170. {
  171. u16 status = le16_to_cpu(tx_resp->status.status);
  172. info->status.rates[0].count = tx_resp->failure_frame + 1;
  173. if (is_agg)
  174. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  175. info->flags |= iwl_tx_status_to_mac80211(status);
  176. iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
  177. info);
  178. if (!iwl_is_tx_success(status))
  179. iwlagn_count_tx_err_status(priv, status);
  180. IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x) rate_n_flags "
  181. "0x%x retries %d\n",
  182. txq_id,
  183. iwl_get_tx_fail_reason(status), status,
  184. le32_to_cpu(tx_resp->rate_n_flags),
  185. tx_resp->failure_frame);
  186. }
  187. #ifdef CONFIG_IWLWIFI_DEBUG
  188. #define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x
  189. const char *iwl_get_agg_tx_fail_reason(u16 status)
  190. {
  191. status &= AGG_TX_STATUS_MSK;
  192. switch (status) {
  193. case AGG_TX_STATE_TRANSMITTED:
  194. return "SUCCESS";
  195. AGG_TX_STATE_FAIL(UNDERRUN_MSK);
  196. AGG_TX_STATE_FAIL(BT_PRIO_MSK);
  197. AGG_TX_STATE_FAIL(FEW_BYTES_MSK);
  198. AGG_TX_STATE_FAIL(ABORT_MSK);
  199. AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK);
  200. AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK);
  201. AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK);
  202. AGG_TX_STATE_FAIL(SCD_QUERY_MSK);
  203. AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK);
  204. AGG_TX_STATE_FAIL(RESPONSE_MSK);
  205. AGG_TX_STATE_FAIL(DUMP_TX_MSK);
  206. AGG_TX_STATE_FAIL(DELAY_TX_MSK);
  207. }
  208. return "UNKNOWN";
  209. }
  210. #endif /* CONFIG_IWLWIFI_DEBUG */
  211. static int iwlagn_tx_status_reply_tx(struct iwl_priv *priv,
  212. struct iwl_ht_agg *agg,
  213. struct iwl5000_tx_resp *tx_resp,
  214. int txq_id, u16 start_idx)
  215. {
  216. u16 status;
  217. struct agg_tx_status *frame_status = &tx_resp->status;
  218. struct ieee80211_hdr *hdr = NULL;
  219. int i, sh, idx;
  220. u16 seq;
  221. if (agg->wait_for_ba)
  222. IWL_DEBUG_TX_REPLY(priv, "got tx response w/o block-ack\n");
  223. agg->frame_count = tx_resp->frame_count;
  224. agg->start_idx = start_idx;
  225. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  226. agg->bitmap = 0;
  227. /* # frames attempted by Tx command */
  228. if (agg->frame_count == 1) {
  229. /* Only one frame was attempted; no block-ack will arrive */
  230. idx = start_idx;
  231. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, StartIdx=%d idx=%d\n",
  232. agg->frame_count, agg->start_idx, idx);
  233. iwlagn_set_tx_status(priv,
  234. IEEE80211_SKB_CB(
  235. priv->txq[txq_id].txb[idx].skb),
  236. tx_resp, txq_id, true);
  237. agg->wait_for_ba = 0;
  238. } else {
  239. /* Two or more frames were attempted; expect block-ack */
  240. u64 bitmap = 0;
  241. /*
  242. * Start is the lowest frame sent. It may not be the first
  243. * frame in the batch; we figure this out dynamically during
  244. * the following loop.
  245. */
  246. int start = agg->start_idx;
  247. /* Construct bit-map of pending frames within Tx window */
  248. for (i = 0; i < agg->frame_count; i++) {
  249. u16 sc;
  250. status = le16_to_cpu(frame_status[i].status);
  251. seq = le16_to_cpu(frame_status[i].sequence);
  252. idx = SEQ_TO_INDEX(seq);
  253. txq_id = SEQ_TO_QUEUE(seq);
  254. if (status & AGG_TX_STATUS_MSK)
  255. iwlagn_count_agg_tx_err_status(priv, status);
  256. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  257. AGG_TX_STATE_ABORT_MSK))
  258. continue;
  259. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, txq_id=%d idx=%d\n",
  260. agg->frame_count, txq_id, idx);
  261. IWL_DEBUG_TX_REPLY(priv, "status %s (0x%08x), "
  262. "try-count (0x%08x)\n",
  263. iwl_get_agg_tx_fail_reason(status),
  264. status & AGG_TX_STATUS_MSK,
  265. status & AGG_TX_TRY_MSK);
  266. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  267. if (!hdr) {
  268. IWL_ERR(priv,
  269. "BUG_ON idx doesn't point to valid skb"
  270. " idx=%d, txq_id=%d\n", idx, txq_id);
  271. return -1;
  272. }
  273. sc = le16_to_cpu(hdr->seq_ctrl);
  274. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  275. IWL_ERR(priv,
  276. "BUG_ON idx doesn't match seq control"
  277. " idx=%d, seq_idx=%d, seq=%d\n",
  278. idx, SEQ_TO_SN(sc),
  279. hdr->seq_ctrl);
  280. return -1;
  281. }
  282. IWL_DEBUG_TX_REPLY(priv, "AGG Frame i=%d idx %d seq=%d\n",
  283. i, idx, SEQ_TO_SN(sc));
  284. /*
  285. * sh -> how many frames ahead of the starting frame is
  286. * the current one?
  287. *
  288. * Note that all frames sent in the batch must be in a
  289. * 64-frame window, so this number should be in [0,63].
  290. * If outside of this window, then we've found a new
  291. * "first" frame in the batch and need to change start.
  292. */
  293. sh = idx - start;
  294. /*
  295. * If >= 64, out of window. start must be at the front
  296. * of the circular buffer, idx must be near the end of
  297. * the buffer, and idx is the new "first" frame. Shift
  298. * the indices around.
  299. */
  300. if (sh >= 64) {
  301. /* Shift bitmap by start - idx, wrapped */
  302. sh = 0x100 - idx + start;
  303. bitmap = bitmap << sh;
  304. /* Now idx is the new start so sh = 0 */
  305. sh = 0;
  306. start = idx;
  307. /*
  308. * If <= -64 then wraps the 256-pkt circular buffer
  309. * (e.g., start = 255 and idx = 0, sh should be 1)
  310. */
  311. } else if (sh <= -64) {
  312. sh = 0x100 - start + idx;
  313. /*
  314. * If < 0 but > -64, out of window. idx is before start
  315. * but not wrapped. Shift the indices around.
  316. */
  317. } else if (sh < 0) {
  318. /* Shift by how far start is ahead of idx */
  319. sh = start - idx;
  320. bitmap = bitmap << sh;
  321. /* Now idx is the new start so sh = 0 */
  322. start = idx;
  323. sh = 0;
  324. }
  325. /* Sequence number start + sh was sent in this batch */
  326. bitmap |= 1ULL << sh;
  327. IWL_DEBUG_TX_REPLY(priv, "start=%d bitmap=0x%llx\n",
  328. start, (unsigned long long)bitmap);
  329. }
  330. /*
  331. * Store the bitmap and possibly the new start, if we wrapped
  332. * the buffer above
  333. */
  334. agg->bitmap = bitmap;
  335. agg->start_idx = start;
  336. IWL_DEBUG_TX_REPLY(priv, "Frames %d start_idx=%d bitmap=0x%llx\n",
  337. agg->frame_count, agg->start_idx,
  338. (unsigned long long)agg->bitmap);
  339. if (bitmap)
  340. agg->wait_for_ba = 1;
  341. }
  342. return 0;
  343. }
  344. void iwl_check_abort_status(struct iwl_priv *priv,
  345. u8 frame_count, u32 status)
  346. {
  347. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  348. IWL_ERR(priv, "Tx flush command to flush out all frames\n");
  349. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  350. queue_work(priv->workqueue, &priv->tx_flush);
  351. }
  352. }
  353. static void iwlagn_rx_reply_tx(struct iwl_priv *priv,
  354. struct iwl_rx_mem_buffer *rxb)
  355. {
  356. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  357. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  358. int txq_id = SEQ_TO_QUEUE(sequence);
  359. int index = SEQ_TO_INDEX(sequence);
  360. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  361. struct ieee80211_tx_info *info;
  362. struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  363. u32 status = le16_to_cpu(tx_resp->status.status);
  364. int tid;
  365. int sta_id;
  366. int freed;
  367. unsigned long flags;
  368. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  369. IWL_ERR(priv, "Read index for DMA queue txq_id (%d) index %d "
  370. "is out of range [0-%d] %d %d\n", txq_id,
  371. index, txq->q.n_bd, txq->q.write_ptr,
  372. txq->q.read_ptr);
  373. return;
  374. }
  375. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb);
  376. memset(&info->status, 0, sizeof(info->status));
  377. tid = (tx_resp->ra_tid & IWL50_TX_RES_TID_MSK) >> IWL50_TX_RES_TID_POS;
  378. sta_id = (tx_resp->ra_tid & IWL50_TX_RES_RA_MSK) >> IWL50_TX_RES_RA_POS;
  379. spin_lock_irqsave(&priv->sta_lock, flags);
  380. if (txq->sched_retry) {
  381. const u32 scd_ssn = iwlagn_get_scd_ssn(tx_resp);
  382. struct iwl_ht_agg *agg;
  383. agg = &priv->stations[sta_id].tid[tid].agg;
  384. /*
  385. * If the BT kill count is non-zero, we'll get this
  386. * notification again.
  387. */
  388. if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 &&
  389. priv->cfg->advanced_bt_coexist) {
  390. IWL_WARN(priv, "receive reply tx with bt_kill\n");
  391. }
  392. iwlagn_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  393. /* check if BAR is needed */
  394. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
  395. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  396. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  397. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  398. IWL_DEBUG_TX_REPLY(priv, "Retry scheduler reclaim "
  399. "scd_ssn=%d idx=%d txq=%d swq=%d\n",
  400. scd_ssn , index, txq_id, txq->swq_id);
  401. freed = iwlagn_tx_queue_reclaim(priv, txq_id, index);
  402. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  403. if (priv->mac80211_registered &&
  404. (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  405. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)) {
  406. if (agg->state == IWL_AGG_OFF)
  407. iwl_wake_queue(priv, txq_id);
  408. else
  409. iwl_wake_queue(priv, txq->swq_id);
  410. }
  411. }
  412. } else {
  413. BUG_ON(txq_id != txq->swq_id);
  414. iwlagn_set_tx_status(priv, info, tx_resp, txq_id, false);
  415. freed = iwlagn_tx_queue_reclaim(priv, txq_id, index);
  416. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  417. if (priv->mac80211_registered &&
  418. (iwl_queue_space(&txq->q) > txq->q.low_mark))
  419. iwl_wake_queue(priv, txq_id);
  420. }
  421. iwlagn_txq_check_empty(priv, sta_id, tid, txq_id);
  422. iwl_check_abort_status(priv, tx_resp->frame_count, status);
  423. spin_unlock_irqrestore(&priv->sta_lock, flags);
  424. }
  425. void iwlagn_rx_handler_setup(struct iwl_priv *priv)
  426. {
  427. /* init calibration handlers */
  428. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  429. iwlagn_rx_calib_result;
  430. priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
  431. iwlagn_rx_calib_complete;
  432. priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
  433. }
  434. void iwlagn_setup_deferred_work(struct iwl_priv *priv)
  435. {
  436. /* in agn, the tx power calibration is done in uCode */
  437. priv->disable_tx_power_cal = 1;
  438. }
  439. int iwlagn_hw_valid_rtc_data_addr(u32 addr)
  440. {
  441. return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
  442. (addr < IWLAGN_RTC_DATA_UPPER_BOUND);
  443. }
  444. int iwlagn_send_tx_power(struct iwl_priv *priv)
  445. {
  446. struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
  447. u8 tx_ant_cfg_cmd;
  448. /* half dBm need to multiply */
  449. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  450. if (priv->tx_power_lmt_in_half_dbm &&
  451. priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
  452. /*
  453. * For the newer devices which using enhanced/extend tx power
  454. * table in EEPROM, the format is in half dBm. driver need to
  455. * convert to dBm format before report to mac80211.
  456. * By doing so, there is a possibility of 1/2 dBm resolution
  457. * lost. driver will perform "round-up" operation before
  458. * reporting, but it will cause 1/2 dBm tx power over the
  459. * regulatory limit. Perform the checking here, if the
  460. * "tx_power_user_lmt" is higher than EEPROM value (in
  461. * half-dBm format), lower the tx power based on EEPROM
  462. */
  463. tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
  464. }
  465. tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
  466. tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
  467. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  468. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  469. else
  470. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  471. return iwl_send_cmd_pdu_async(priv, tx_ant_cfg_cmd,
  472. sizeof(tx_power_cmd), &tx_power_cmd,
  473. NULL);
  474. }
  475. void iwlagn_temperature(struct iwl_priv *priv)
  476. {
  477. /* store temperature from statistics (in Celsius) */
  478. priv->temperature =
  479. le32_to_cpu(priv->_agn.statistics.general.common.temperature);
  480. iwl_tt_handler(priv);
  481. }
  482. u16 iwlagn_eeprom_calib_version(struct iwl_priv *priv)
  483. {
  484. struct iwl_eeprom_calib_hdr {
  485. u8 version;
  486. u8 pa_type;
  487. u16 voltage;
  488. } *hdr;
  489. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  490. EEPROM_CALIB_ALL);
  491. return hdr->version;
  492. }
  493. /*
  494. * EEPROM
  495. */
  496. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  497. {
  498. u16 offset = 0;
  499. if ((address & INDIRECT_ADDRESS) == 0)
  500. return address;
  501. switch (address & INDIRECT_TYPE_MSK) {
  502. case INDIRECT_HOST:
  503. offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
  504. break;
  505. case INDIRECT_GENERAL:
  506. offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
  507. break;
  508. case INDIRECT_REGULATORY:
  509. offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
  510. break;
  511. case INDIRECT_CALIBRATION:
  512. offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
  513. break;
  514. case INDIRECT_PROCESS_ADJST:
  515. offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
  516. break;
  517. case INDIRECT_OTHERS:
  518. offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
  519. break;
  520. default:
  521. IWL_ERR(priv, "illegal indirect type: 0x%X\n",
  522. address & INDIRECT_TYPE_MSK);
  523. break;
  524. }
  525. /* translate the offset from words to byte */
  526. return (address & ADDRESS_MSK) + (offset << 1);
  527. }
  528. const u8 *iwlagn_eeprom_query_addr(const struct iwl_priv *priv,
  529. size_t offset)
  530. {
  531. u32 address = eeprom_indirect_address(priv, offset);
  532. BUG_ON(address >= priv->cfg->eeprom_size);
  533. return &priv->eeprom[address];
  534. }
  535. struct iwl_mod_params iwlagn_mod_params = {
  536. .amsdu_size_8K = 1,
  537. .restart_fw = 1,
  538. /* the rest are 0 by default */
  539. };
  540. void iwlagn_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  541. {
  542. unsigned long flags;
  543. int i;
  544. spin_lock_irqsave(&rxq->lock, flags);
  545. INIT_LIST_HEAD(&rxq->rx_free);
  546. INIT_LIST_HEAD(&rxq->rx_used);
  547. /* Fill the rx_used queue with _all_ of the Rx buffers */
  548. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  549. /* In the reset function, these buffers may have been allocated
  550. * to an SKB, so we need to unmap and free potential storage */
  551. if (rxq->pool[i].page != NULL) {
  552. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  553. PAGE_SIZE << priv->hw_params.rx_page_order,
  554. PCI_DMA_FROMDEVICE);
  555. __iwl_free_pages(priv, rxq->pool[i].page);
  556. rxq->pool[i].page = NULL;
  557. }
  558. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  559. }
  560. for (i = 0; i < RX_QUEUE_SIZE; i++)
  561. rxq->queue[i] = NULL;
  562. /* Set us so that we have processed and used all buffers, but have
  563. * not restocked the Rx queue with fresh buffers */
  564. rxq->read = rxq->write = 0;
  565. rxq->write_actual = 0;
  566. rxq->free_count = 0;
  567. spin_unlock_irqrestore(&rxq->lock, flags);
  568. }
  569. int iwlagn_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  570. {
  571. u32 rb_size;
  572. const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
  573. u32 rb_timeout = 0; /* FIXME: RX_RB_TIMEOUT for all devices? */
  574. if (!priv->cfg->use_isr_legacy)
  575. rb_timeout = RX_RB_TIMEOUT;
  576. if (priv->cfg->mod_params->amsdu_size_8K)
  577. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  578. else
  579. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  580. /* Stop Rx DMA */
  581. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  582. /* Reset driver's Rx queue write index */
  583. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  584. /* Tell device where to find RBD circular buffer in DRAM */
  585. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  586. (u32)(rxq->bd_dma >> 8));
  587. /* Tell device where in DRAM to update its Rx status */
  588. iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
  589. rxq->rb_stts_dma >> 4);
  590. /* Enable Rx DMA
  591. * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set because of HW bug in
  592. * the credit mechanism in 5000 HW RX FIFO
  593. * Direct rx interrupts to hosts
  594. * Rx buffer size 4 or 8k
  595. * RB timeout 0x10
  596. * 256 RBDs
  597. */
  598. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
  599. FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  600. FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY |
  601. FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  602. FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK |
  603. rb_size|
  604. (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)|
  605. (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
  606. /* Set interrupt coalescing timer to default (2048 usecs) */
  607. iwl_write8(priv, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF);
  608. return 0;
  609. }
  610. int iwlagn_hw_nic_init(struct iwl_priv *priv)
  611. {
  612. unsigned long flags;
  613. struct iwl_rx_queue *rxq = &priv->rxq;
  614. int ret;
  615. /* nic_init */
  616. spin_lock_irqsave(&priv->lock, flags);
  617. priv->cfg->ops->lib->apm_ops.init(priv);
  618. /* Set interrupt coalescing calibration timer to default (512 usecs) */
  619. iwl_write8(priv, CSR_INT_COALESCING, IWL_HOST_INT_CALIB_TIMEOUT_DEF);
  620. spin_unlock_irqrestore(&priv->lock, flags);
  621. ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
  622. priv->cfg->ops->lib->apm_ops.config(priv);
  623. /* Allocate the RX queue, or reset if it is already allocated */
  624. if (!rxq->bd) {
  625. ret = iwl_rx_queue_alloc(priv);
  626. if (ret) {
  627. IWL_ERR(priv, "Unable to initialize Rx queue\n");
  628. return -ENOMEM;
  629. }
  630. } else
  631. iwlagn_rx_queue_reset(priv, rxq);
  632. iwlagn_rx_replenish(priv);
  633. iwlagn_rx_init(priv, rxq);
  634. spin_lock_irqsave(&priv->lock, flags);
  635. rxq->need_update = 1;
  636. iwl_rx_queue_update_write_ptr(priv, rxq);
  637. spin_unlock_irqrestore(&priv->lock, flags);
  638. /* Allocate or reset and init all Tx and Command queues */
  639. if (!priv->txq) {
  640. ret = iwlagn_txq_ctx_alloc(priv);
  641. if (ret)
  642. return ret;
  643. } else
  644. iwlagn_txq_ctx_reset(priv);
  645. set_bit(STATUS_INIT, &priv->status);
  646. return 0;
  647. }
  648. /**
  649. * iwlagn_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  650. */
  651. static inline __le32 iwlagn_dma_addr2rbd_ptr(struct iwl_priv *priv,
  652. dma_addr_t dma_addr)
  653. {
  654. return cpu_to_le32((u32)(dma_addr >> 8));
  655. }
  656. /**
  657. * iwlagn_rx_queue_restock - refill RX queue from pre-allocated pool
  658. *
  659. * If there are slots in the RX queue that need to be restocked,
  660. * and we have free pre-allocated buffers, fill the ranks as much
  661. * as we can, pulling from rx_free.
  662. *
  663. * This moves the 'write' index forward to catch up with 'processed', and
  664. * also updates the memory address in the firmware to reference the new
  665. * target buffer.
  666. */
  667. void iwlagn_rx_queue_restock(struct iwl_priv *priv)
  668. {
  669. struct iwl_rx_queue *rxq = &priv->rxq;
  670. struct list_head *element;
  671. struct iwl_rx_mem_buffer *rxb;
  672. unsigned long flags;
  673. spin_lock_irqsave(&rxq->lock, flags);
  674. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  675. /* The overwritten rxb must be a used one */
  676. rxb = rxq->queue[rxq->write];
  677. BUG_ON(rxb && rxb->page);
  678. /* Get next free Rx buffer, remove from free list */
  679. element = rxq->rx_free.next;
  680. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  681. list_del(element);
  682. /* Point to Rx buffer via next RBD in circular buffer */
  683. rxq->bd[rxq->write] = iwlagn_dma_addr2rbd_ptr(priv,
  684. rxb->page_dma);
  685. rxq->queue[rxq->write] = rxb;
  686. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  687. rxq->free_count--;
  688. }
  689. spin_unlock_irqrestore(&rxq->lock, flags);
  690. /* If the pre-allocated buffer pool is dropping low, schedule to
  691. * refill it */
  692. if (rxq->free_count <= RX_LOW_WATERMARK)
  693. queue_work(priv->workqueue, &priv->rx_replenish);
  694. /* If we've added more space for the firmware to place data, tell it.
  695. * Increment device's write pointer in multiples of 8. */
  696. if (rxq->write_actual != (rxq->write & ~0x7)) {
  697. spin_lock_irqsave(&rxq->lock, flags);
  698. rxq->need_update = 1;
  699. spin_unlock_irqrestore(&rxq->lock, flags);
  700. iwl_rx_queue_update_write_ptr(priv, rxq);
  701. }
  702. }
  703. /**
  704. * iwlagn_rx_replenish - Move all used packet from rx_used to rx_free
  705. *
  706. * When moving to rx_free an SKB is allocated for the slot.
  707. *
  708. * Also restock the Rx queue via iwl_rx_queue_restock.
  709. * This is called as a scheduled work item (except for during initialization)
  710. */
  711. void iwlagn_rx_allocate(struct iwl_priv *priv, gfp_t priority)
  712. {
  713. struct iwl_rx_queue *rxq = &priv->rxq;
  714. struct list_head *element;
  715. struct iwl_rx_mem_buffer *rxb;
  716. struct page *page;
  717. unsigned long flags;
  718. gfp_t gfp_mask = priority;
  719. while (1) {
  720. spin_lock_irqsave(&rxq->lock, flags);
  721. if (list_empty(&rxq->rx_used)) {
  722. spin_unlock_irqrestore(&rxq->lock, flags);
  723. return;
  724. }
  725. spin_unlock_irqrestore(&rxq->lock, flags);
  726. if (rxq->free_count > RX_LOW_WATERMARK)
  727. gfp_mask |= __GFP_NOWARN;
  728. if (priv->hw_params.rx_page_order > 0)
  729. gfp_mask |= __GFP_COMP;
  730. /* Alloc a new receive buffer */
  731. page = alloc_pages(gfp_mask, priv->hw_params.rx_page_order);
  732. if (!page) {
  733. if (net_ratelimit())
  734. IWL_DEBUG_INFO(priv, "alloc_pages failed, "
  735. "order: %d\n",
  736. priv->hw_params.rx_page_order);
  737. if ((rxq->free_count <= RX_LOW_WATERMARK) &&
  738. net_ratelimit())
  739. IWL_CRIT(priv, "Failed to alloc_pages with %s. Only %u free buffers remaining.\n",
  740. priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
  741. rxq->free_count);
  742. /* We don't reschedule replenish work here -- we will
  743. * call the restock method and if it still needs
  744. * more buffers it will schedule replenish */
  745. return;
  746. }
  747. spin_lock_irqsave(&rxq->lock, flags);
  748. if (list_empty(&rxq->rx_used)) {
  749. spin_unlock_irqrestore(&rxq->lock, flags);
  750. __free_pages(page, priv->hw_params.rx_page_order);
  751. return;
  752. }
  753. element = rxq->rx_used.next;
  754. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  755. list_del(element);
  756. spin_unlock_irqrestore(&rxq->lock, flags);
  757. BUG_ON(rxb->page);
  758. rxb->page = page;
  759. /* Get physical address of the RB */
  760. rxb->page_dma = pci_map_page(priv->pci_dev, page, 0,
  761. PAGE_SIZE << priv->hw_params.rx_page_order,
  762. PCI_DMA_FROMDEVICE);
  763. /* dma address must be no more than 36 bits */
  764. BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
  765. /* and also 256 byte aligned! */
  766. BUG_ON(rxb->page_dma & DMA_BIT_MASK(8));
  767. spin_lock_irqsave(&rxq->lock, flags);
  768. list_add_tail(&rxb->list, &rxq->rx_free);
  769. rxq->free_count++;
  770. priv->alloc_rxb_page++;
  771. spin_unlock_irqrestore(&rxq->lock, flags);
  772. }
  773. }
  774. void iwlagn_rx_replenish(struct iwl_priv *priv)
  775. {
  776. unsigned long flags;
  777. iwlagn_rx_allocate(priv, GFP_KERNEL);
  778. spin_lock_irqsave(&priv->lock, flags);
  779. iwlagn_rx_queue_restock(priv);
  780. spin_unlock_irqrestore(&priv->lock, flags);
  781. }
  782. void iwlagn_rx_replenish_now(struct iwl_priv *priv)
  783. {
  784. iwlagn_rx_allocate(priv, GFP_ATOMIC);
  785. iwlagn_rx_queue_restock(priv);
  786. }
  787. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  788. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  789. * This free routine walks the list of POOL entries and if SKB is set to
  790. * non NULL it is unmapped and freed
  791. */
  792. void iwlagn_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  793. {
  794. int i;
  795. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  796. if (rxq->pool[i].page != NULL) {
  797. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  798. PAGE_SIZE << priv->hw_params.rx_page_order,
  799. PCI_DMA_FROMDEVICE);
  800. __iwl_free_pages(priv, rxq->pool[i].page);
  801. rxq->pool[i].page = NULL;
  802. }
  803. }
  804. dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  805. rxq->bd_dma);
  806. dma_free_coherent(&priv->pci_dev->dev, sizeof(struct iwl_rb_status),
  807. rxq->rb_stts, rxq->rb_stts_dma);
  808. rxq->bd = NULL;
  809. rxq->rb_stts = NULL;
  810. }
  811. int iwlagn_rxq_stop(struct iwl_priv *priv)
  812. {
  813. /* stop Rx DMA */
  814. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  815. iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
  816. FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  817. return 0;
  818. }
  819. int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  820. {
  821. int idx = 0;
  822. int band_offset = 0;
  823. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  824. if (rate_n_flags & RATE_MCS_HT_MSK) {
  825. idx = (rate_n_flags & 0xff);
  826. return idx;
  827. /* Legacy rate format, search for match in table */
  828. } else {
  829. if (band == IEEE80211_BAND_5GHZ)
  830. band_offset = IWL_FIRST_OFDM_RATE;
  831. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  832. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  833. return idx - band_offset;
  834. }
  835. return -1;
  836. }
  837. /* Calc max signal level (dBm) among 3 possible receivers */
  838. static inline int iwlagn_calc_rssi(struct iwl_priv *priv,
  839. struct iwl_rx_phy_res *rx_resp)
  840. {
  841. return priv->cfg->ops->utils->calc_rssi(priv, rx_resp);
  842. }
  843. static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
  844. {
  845. u32 decrypt_out = 0;
  846. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  847. RX_RES_STATUS_STATION_FOUND)
  848. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  849. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  850. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  851. /* packet was not encrypted */
  852. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  853. RX_RES_STATUS_SEC_TYPE_NONE)
  854. return decrypt_out;
  855. /* packet was encrypted with unknown alg */
  856. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  857. RX_RES_STATUS_SEC_TYPE_ERR)
  858. return decrypt_out;
  859. /* decryption was not done in HW */
  860. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  861. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  862. return decrypt_out;
  863. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  864. case RX_RES_STATUS_SEC_TYPE_CCMP:
  865. /* alg is CCM: check MIC only */
  866. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  867. /* Bad MIC */
  868. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  869. else
  870. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  871. break;
  872. case RX_RES_STATUS_SEC_TYPE_TKIP:
  873. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  874. /* Bad TTAK */
  875. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  876. break;
  877. }
  878. /* fall through if TTAK OK */
  879. default:
  880. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  881. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  882. else
  883. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  884. break;
  885. }
  886. IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
  887. decrypt_in, decrypt_out);
  888. return decrypt_out;
  889. }
  890. static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
  891. struct ieee80211_hdr *hdr,
  892. u16 len,
  893. u32 ampdu_status,
  894. struct iwl_rx_mem_buffer *rxb,
  895. struct ieee80211_rx_status *stats)
  896. {
  897. struct sk_buff *skb;
  898. __le16 fc = hdr->frame_control;
  899. /* We only process data packets if the interface is open */
  900. if (unlikely(!priv->is_open)) {
  901. IWL_DEBUG_DROP_LIMIT(priv,
  902. "Dropping packet while interface is not open.\n");
  903. return;
  904. }
  905. /* In case of HW accelerated crypto and bad decryption, drop */
  906. if (!priv->cfg->mod_params->sw_crypto &&
  907. iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
  908. return;
  909. skb = dev_alloc_skb(128);
  910. if (!skb) {
  911. IWL_ERR(priv, "dev_alloc_skb failed\n");
  912. return;
  913. }
  914. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  915. iwl_update_stats(priv, false, fc, len);
  916. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  917. ieee80211_rx(priv->hw, skb);
  918. priv->alloc_rxb_page--;
  919. rxb->page = NULL;
  920. }
  921. /* Called for REPLY_RX (legacy ABG frames), or
  922. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  923. void iwlagn_rx_reply_rx(struct iwl_priv *priv,
  924. struct iwl_rx_mem_buffer *rxb)
  925. {
  926. struct ieee80211_hdr *header;
  927. struct ieee80211_rx_status rx_status;
  928. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  929. struct iwl_rx_phy_res *phy_res;
  930. __le32 rx_pkt_status;
  931. struct iwl_rx_mpdu_res_start *amsdu;
  932. u32 len;
  933. u32 ampdu_status;
  934. u32 rate_n_flags;
  935. /**
  936. * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
  937. * REPLY_RX: physical layer info is in this buffer
  938. * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
  939. * command and cached in priv->last_phy_res
  940. *
  941. * Here we set up local variables depending on which command is
  942. * received.
  943. */
  944. if (pkt->hdr.cmd == REPLY_RX) {
  945. phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
  946. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
  947. + phy_res->cfg_phy_cnt);
  948. len = le16_to_cpu(phy_res->byte_count);
  949. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
  950. phy_res->cfg_phy_cnt + len);
  951. ampdu_status = le32_to_cpu(rx_pkt_status);
  952. } else {
  953. if (!priv->_agn.last_phy_res_valid) {
  954. IWL_ERR(priv, "MPDU frame without cached PHY data\n");
  955. return;
  956. }
  957. phy_res = &priv->_agn.last_phy_res;
  958. amsdu = (struct iwl_rx_mpdu_res_start *)pkt->u.raw;
  959. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  960. len = le16_to_cpu(amsdu->byte_count);
  961. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
  962. ampdu_status = iwlagn_translate_rx_status(priv,
  963. le32_to_cpu(rx_pkt_status));
  964. }
  965. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  966. IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
  967. phy_res->cfg_phy_cnt);
  968. return;
  969. }
  970. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  971. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  972. IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
  973. le32_to_cpu(rx_pkt_status));
  974. return;
  975. }
  976. /* This will be used in several places later */
  977. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  978. /* rx_status carries information about the packet to mac80211 */
  979. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  980. rx_status.freq =
  981. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel));
  982. rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  983. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  984. rx_status.rate_idx =
  985. iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  986. rx_status.flag = 0;
  987. /* TSF isn't reliable. In order to allow smooth user experience,
  988. * this W/A doesn't propagate it to the mac80211 */
  989. /*rx_status.flag |= RX_FLAG_TSFT;*/
  990. priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  991. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  992. rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
  993. iwl_dbg_log_rx_data_frame(priv, len, header);
  994. IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
  995. rx_status.signal, (unsigned long long)rx_status.mactime);
  996. /*
  997. * "antenna number"
  998. *
  999. * It seems that the antenna field in the phy flags value
  1000. * is actually a bit field. This is undefined by radiotap,
  1001. * it wants an actual antenna number but I always get "7"
  1002. * for most legacy frames I receive indicating that the
  1003. * same frame was received on all three RX chains.
  1004. *
  1005. * I think this field should be removed in favor of a
  1006. * new 802.11n radiotap field "RX chains" that is defined
  1007. * as a bitmask.
  1008. */
  1009. rx_status.antenna =
  1010. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
  1011. >> RX_RES_PHY_FLAGS_ANTENNA_POS;
  1012. /* set the preamble flag if appropriate */
  1013. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  1014. rx_status.flag |= RX_FLAG_SHORTPRE;
  1015. /* Set up the HT phy flags */
  1016. if (rate_n_flags & RATE_MCS_HT_MSK)
  1017. rx_status.flag |= RX_FLAG_HT;
  1018. if (rate_n_flags & RATE_MCS_HT40_MSK)
  1019. rx_status.flag |= RX_FLAG_40MHZ;
  1020. if (rate_n_flags & RATE_MCS_SGI_MSK)
  1021. rx_status.flag |= RX_FLAG_SHORT_GI;
  1022. iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
  1023. rxb, &rx_status);
  1024. }
  1025. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  1026. * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  1027. void iwlagn_rx_reply_rx_phy(struct iwl_priv *priv,
  1028. struct iwl_rx_mem_buffer *rxb)
  1029. {
  1030. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1031. priv->_agn.last_phy_res_valid = true;
  1032. memcpy(&priv->_agn.last_phy_res, pkt->u.raw,
  1033. sizeof(struct iwl_rx_phy_res));
  1034. }
  1035. static int iwl_get_single_channel_for_scan(struct iwl_priv *priv,
  1036. struct ieee80211_vif *vif,
  1037. enum ieee80211_band band,
  1038. struct iwl_scan_channel *scan_ch)
  1039. {
  1040. const struct ieee80211_supported_band *sband;
  1041. u16 passive_dwell = 0;
  1042. u16 active_dwell = 0;
  1043. int added = 0;
  1044. u16 channel = 0;
  1045. sband = iwl_get_hw_mode(priv, band);
  1046. if (!sband) {
  1047. IWL_ERR(priv, "invalid band\n");
  1048. return added;
  1049. }
  1050. active_dwell = iwl_get_active_dwell_time(priv, band, 0);
  1051. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  1052. if (passive_dwell <= active_dwell)
  1053. passive_dwell = active_dwell + 1;
  1054. channel = iwl_get_single_channel_number(priv, band);
  1055. if (channel) {
  1056. scan_ch->channel = cpu_to_le16(channel);
  1057. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  1058. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  1059. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  1060. /* Set txpower levels to defaults */
  1061. scan_ch->dsp_atten = 110;
  1062. if (band == IEEE80211_BAND_5GHZ)
  1063. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  1064. else
  1065. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  1066. added++;
  1067. } else
  1068. IWL_ERR(priv, "no valid channel found\n");
  1069. return added;
  1070. }
  1071. static int iwl_get_channels_for_scan(struct iwl_priv *priv,
  1072. struct ieee80211_vif *vif,
  1073. enum ieee80211_band band,
  1074. u8 is_active, u8 n_probes,
  1075. struct iwl_scan_channel *scan_ch)
  1076. {
  1077. struct ieee80211_channel *chan;
  1078. const struct ieee80211_supported_band *sband;
  1079. const struct iwl_channel_info *ch_info;
  1080. u16 passive_dwell = 0;
  1081. u16 active_dwell = 0;
  1082. int added, i;
  1083. u16 channel;
  1084. sband = iwl_get_hw_mode(priv, band);
  1085. if (!sband)
  1086. return 0;
  1087. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  1088. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  1089. if (passive_dwell <= active_dwell)
  1090. passive_dwell = active_dwell + 1;
  1091. for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
  1092. chan = priv->scan_request->channels[i];
  1093. if (chan->band != band)
  1094. continue;
  1095. channel = chan->hw_value;
  1096. scan_ch->channel = cpu_to_le16(channel);
  1097. ch_info = iwl_get_channel_info(priv, band, channel);
  1098. if (!is_channel_valid(ch_info)) {
  1099. IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
  1100. channel);
  1101. continue;
  1102. }
  1103. if (!is_active || is_channel_passive(ch_info) ||
  1104. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
  1105. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  1106. else
  1107. scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
  1108. if (n_probes)
  1109. scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
  1110. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  1111. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  1112. /* Set txpower levels to defaults */
  1113. scan_ch->dsp_atten = 110;
  1114. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  1115. * power level:
  1116. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  1117. */
  1118. if (band == IEEE80211_BAND_5GHZ)
  1119. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  1120. else
  1121. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  1122. IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n",
  1123. channel, le32_to_cpu(scan_ch->type),
  1124. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  1125. "ACTIVE" : "PASSIVE",
  1126. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  1127. active_dwell : passive_dwell);
  1128. scan_ch++;
  1129. added++;
  1130. }
  1131. IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
  1132. return added;
  1133. }
  1134. int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
  1135. {
  1136. struct iwl_host_cmd cmd = {
  1137. .id = REPLY_SCAN_CMD,
  1138. .len = sizeof(struct iwl_scan_cmd),
  1139. .flags = CMD_SIZE_HUGE,
  1140. };
  1141. struct iwl_scan_cmd *scan;
  1142. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1143. u32 rate_flags = 0;
  1144. u16 cmd_len;
  1145. u16 rx_chain = 0;
  1146. enum ieee80211_band band;
  1147. u8 n_probes = 0;
  1148. u8 rx_ant = priv->hw_params.valid_rx_ant;
  1149. u8 rate;
  1150. bool is_active = false;
  1151. int chan_mod;
  1152. u8 active_chains;
  1153. u8 scan_tx_antennas = priv->hw_params.valid_tx_ant;
  1154. int ret;
  1155. lockdep_assert_held(&priv->mutex);
  1156. if (vif)
  1157. ctx = iwl_rxon_ctx_from_vif(vif);
  1158. if (!priv->scan_cmd) {
  1159. priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) +
  1160. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  1161. if (!priv->scan_cmd) {
  1162. IWL_DEBUG_SCAN(priv,
  1163. "fail to allocate memory for scan\n");
  1164. return -ENOMEM;
  1165. }
  1166. }
  1167. scan = priv->scan_cmd;
  1168. memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE);
  1169. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  1170. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  1171. if (iwl_is_any_associated(priv)) {
  1172. u16 interval = 0;
  1173. u32 extra;
  1174. u32 suspend_time = 100;
  1175. u32 scan_suspend_time = 100;
  1176. unsigned long flags;
  1177. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  1178. spin_lock_irqsave(&priv->lock, flags);
  1179. if (priv->is_internal_short_scan)
  1180. interval = 0;
  1181. else
  1182. interval = vif->bss_conf.beacon_int;
  1183. spin_unlock_irqrestore(&priv->lock, flags);
  1184. scan->suspend_time = 0;
  1185. scan->max_out_time = cpu_to_le32(200 * 1024);
  1186. if (!interval)
  1187. interval = suspend_time;
  1188. extra = (suspend_time / interval) << 22;
  1189. scan_suspend_time = (extra |
  1190. ((suspend_time % interval) * 1024));
  1191. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  1192. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  1193. scan_suspend_time, interval);
  1194. }
  1195. if (priv->is_internal_short_scan) {
  1196. IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
  1197. } else if (priv->scan_request->n_ssids) {
  1198. int i, p = 0;
  1199. IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
  1200. for (i = 0; i < priv->scan_request->n_ssids; i++) {
  1201. /* always does wildcard anyway */
  1202. if (!priv->scan_request->ssids[i].ssid_len)
  1203. continue;
  1204. scan->direct_scan[p].id = WLAN_EID_SSID;
  1205. scan->direct_scan[p].len =
  1206. priv->scan_request->ssids[i].ssid_len;
  1207. memcpy(scan->direct_scan[p].ssid,
  1208. priv->scan_request->ssids[i].ssid,
  1209. priv->scan_request->ssids[i].ssid_len);
  1210. n_probes++;
  1211. p++;
  1212. }
  1213. is_active = true;
  1214. } else
  1215. IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
  1216. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  1217. scan->tx_cmd.sta_id = ctx->bcast_sta_id;
  1218. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  1219. switch (priv->scan_band) {
  1220. case IEEE80211_BAND_2GHZ:
  1221. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  1222. chan_mod = le32_to_cpu(
  1223. priv->contexts[IWL_RXON_CTX_BSS].active.flags &
  1224. RXON_FLG_CHANNEL_MODE_MSK)
  1225. >> RXON_FLG_CHANNEL_MODE_POS;
  1226. if (chan_mod == CHANNEL_MODE_PURE_40) {
  1227. rate = IWL_RATE_6M_PLCP;
  1228. } else {
  1229. rate = IWL_RATE_1M_PLCP;
  1230. rate_flags = RATE_MCS_CCK_MSK;
  1231. }
  1232. /*
  1233. * Internal scans are passive, so we can indiscriminately set
  1234. * the BT ignore flag on 2.4 GHz since it applies to TX only.
  1235. */
  1236. if (priv->cfg->advanced_bt_coexist)
  1237. scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT;
  1238. scan->good_CRC_th = IWL_GOOD_CRC_TH_DISABLED;
  1239. break;
  1240. case IEEE80211_BAND_5GHZ:
  1241. rate = IWL_RATE_6M_PLCP;
  1242. /*
  1243. * If active scanning is requested but a certain channel is
  1244. * marked passive, we can do active scanning if we detect
  1245. * transmissions.
  1246. *
  1247. * There is an issue with some firmware versions that triggers
  1248. * a sysassert on a "good CRC threshold" of zero (== disabled),
  1249. * on a radar channel even though this means that we should NOT
  1250. * send probes.
  1251. *
  1252. * The "good CRC threshold" is the number of frames that we
  1253. * need to receive during our dwell time on a channel before
  1254. * sending out probes -- setting this to a huge value will
  1255. * mean we never reach it, but at the same time work around
  1256. * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER
  1257. * here instead of IWL_GOOD_CRC_TH_DISABLED.
  1258. */
  1259. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  1260. IWL_GOOD_CRC_TH_NEVER;
  1261. break;
  1262. default:
  1263. IWL_WARN(priv, "Invalid scan band\n");
  1264. return -EIO;
  1265. }
  1266. band = priv->scan_band;
  1267. if (priv->cfg->scan_rx_antennas[band])
  1268. rx_ant = priv->cfg->scan_rx_antennas[band];
  1269. if (priv->cfg->scan_tx_antennas[band])
  1270. scan_tx_antennas = priv->cfg->scan_tx_antennas[band];
  1271. if (priv->cfg->advanced_bt_coexist && priv->bt_full_concurrent) {
  1272. /* operated as 1x1 in full concurrency mode */
  1273. scan_tx_antennas =
  1274. first_antenna(priv->cfg->scan_tx_antennas[band]);
  1275. }
  1276. priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, priv->scan_tx_ant[band],
  1277. scan_tx_antennas);
  1278. rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
  1279. scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
  1280. /* In power save mode use one chain, otherwise use all chains */
  1281. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  1282. /* rx_ant has been set to all valid chains previously */
  1283. active_chains = rx_ant &
  1284. ((u8)(priv->chain_noise_data.active_chains));
  1285. if (!active_chains)
  1286. active_chains = rx_ant;
  1287. IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n",
  1288. priv->chain_noise_data.active_chains);
  1289. rx_ant = first_antenna(active_chains);
  1290. }
  1291. if (priv->cfg->advanced_bt_coexist && priv->bt_full_concurrent) {
  1292. /* operated as 1x1 in full concurrency mode */
  1293. rx_ant = first_antenna(rx_ant);
  1294. }
  1295. /* MIMO is not used here, but value is required */
  1296. rx_chain |= priv->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  1297. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  1298. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  1299. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  1300. scan->rx_chain = cpu_to_le16(rx_chain);
  1301. if (!priv->is_internal_short_scan) {
  1302. cmd_len = iwl_fill_probe_req(priv,
  1303. (struct ieee80211_mgmt *)scan->data,
  1304. vif->addr,
  1305. priv->scan_request->ie,
  1306. priv->scan_request->ie_len,
  1307. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  1308. } else {
  1309. /* use bcast addr, will not be transmitted but must be valid */
  1310. cmd_len = iwl_fill_probe_req(priv,
  1311. (struct ieee80211_mgmt *)scan->data,
  1312. iwl_bcast_addr, NULL, 0,
  1313. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  1314. }
  1315. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  1316. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  1317. RXON_FILTER_BCON_AWARE_MSK);
  1318. if (priv->is_internal_short_scan) {
  1319. scan->channel_count =
  1320. iwl_get_single_channel_for_scan(priv, vif, band,
  1321. (void *)&scan->data[le16_to_cpu(
  1322. scan->tx_cmd.len)]);
  1323. } else {
  1324. scan->channel_count =
  1325. iwl_get_channels_for_scan(priv, vif, band,
  1326. is_active, n_probes,
  1327. (void *)&scan->data[le16_to_cpu(
  1328. scan->tx_cmd.len)]);
  1329. }
  1330. if (scan->channel_count == 0) {
  1331. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  1332. return -EIO;
  1333. }
  1334. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  1335. scan->channel_count * sizeof(struct iwl_scan_channel);
  1336. cmd.data = scan;
  1337. scan->len = cpu_to_le16(cmd.len);
  1338. if (priv->cfg->ops->hcmd->set_pan_params) {
  1339. ret = priv->cfg->ops->hcmd->set_pan_params(priv);
  1340. if (ret)
  1341. return ret;
  1342. }
  1343. set_bit(STATUS_SCAN_HW, &priv->status);
  1344. ret = iwl_send_cmd_sync(priv, &cmd);
  1345. if (ret) {
  1346. clear_bit(STATUS_SCAN_HW, &priv->status);
  1347. if (priv->cfg->ops->hcmd->set_pan_params)
  1348. priv->cfg->ops->hcmd->set_pan_params(priv);
  1349. }
  1350. return ret;
  1351. }
  1352. int iwlagn_manage_ibss_station(struct iwl_priv *priv,
  1353. struct ieee80211_vif *vif, bool add)
  1354. {
  1355. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1356. if (add)
  1357. return iwl_add_bssid_station(priv, vif_priv->ctx,
  1358. vif->bss_conf.bssid, true,
  1359. &vif_priv->ibss_bssid_sta_id);
  1360. return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
  1361. vif->bss_conf.bssid);
  1362. }
  1363. void iwl_free_tfds_in_queue(struct iwl_priv *priv,
  1364. int sta_id, int tid, int freed)
  1365. {
  1366. lockdep_assert_held(&priv->sta_lock);
  1367. if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed)
  1368. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1369. else {
  1370. IWL_DEBUG_TX(priv, "free more than tfds_in_queue (%u:%d)\n",
  1371. priv->stations[sta_id].tid[tid].tfds_in_queue,
  1372. freed);
  1373. priv->stations[sta_id].tid[tid].tfds_in_queue = 0;
  1374. }
  1375. }
  1376. #define IWL_FLUSH_WAIT_MS 2000
  1377. int iwlagn_wait_tx_queue_empty(struct iwl_priv *priv)
  1378. {
  1379. struct iwl_tx_queue *txq;
  1380. struct iwl_queue *q;
  1381. int cnt;
  1382. unsigned long now = jiffies;
  1383. int ret = 0;
  1384. /* waiting for all the tx frames complete might take a while */
  1385. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  1386. if (cnt == priv->cmd_queue)
  1387. continue;
  1388. txq = &priv->txq[cnt];
  1389. q = &txq->q;
  1390. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  1391. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  1392. msleep(1);
  1393. if (q->read_ptr != q->write_ptr) {
  1394. IWL_ERR(priv, "fail to flush all tx fifo queues\n");
  1395. ret = -ETIMEDOUT;
  1396. break;
  1397. }
  1398. }
  1399. return ret;
  1400. }
  1401. #define IWL_TX_QUEUE_MSK 0xfffff
  1402. /**
  1403. * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
  1404. *
  1405. * pre-requirements:
  1406. * 1. acquire mutex before calling
  1407. * 2. make sure rf is on and not in exit state
  1408. */
  1409. int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  1410. {
  1411. struct iwl_txfifo_flush_cmd flush_cmd;
  1412. struct iwl_host_cmd cmd = {
  1413. .id = REPLY_TXFIFO_FLUSH,
  1414. .len = sizeof(struct iwl_txfifo_flush_cmd),
  1415. .flags = CMD_SYNC,
  1416. .data = &flush_cmd,
  1417. };
  1418. might_sleep();
  1419. memset(&flush_cmd, 0, sizeof(flush_cmd));
  1420. flush_cmd.fifo_control = IWL_TX_FIFO_VO_MSK | IWL_TX_FIFO_VI_MSK |
  1421. IWL_TX_FIFO_BE_MSK | IWL_TX_FIFO_BK_MSK;
  1422. if (priv->cfg->sku & IWL_SKU_N)
  1423. flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
  1424. IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
  1425. flush_cmd.fifo_control);
  1426. flush_cmd.flush_control = cpu_to_le16(flush_control);
  1427. return iwl_send_cmd(priv, &cmd);
  1428. }
  1429. void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  1430. {
  1431. mutex_lock(&priv->mutex);
  1432. ieee80211_stop_queues(priv->hw);
  1433. if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
  1434. IWL_ERR(priv, "flush request fail\n");
  1435. goto done;
  1436. }
  1437. IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
  1438. iwlagn_wait_tx_queue_empty(priv);
  1439. done:
  1440. ieee80211_wake_queues(priv->hw);
  1441. mutex_unlock(&priv->mutex);
  1442. }
  1443. /*
  1444. * BT coex
  1445. */
  1446. /*
  1447. * Macros to access the lookup table.
  1448. *
  1449. * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
  1450. * wifi_prio, wifi_txrx and wifi_sh_ant_req.
  1451. *
  1452. * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
  1453. *
  1454. * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
  1455. * one after another in 32-bit registers, and "registers" 0 through 7 contain
  1456. * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
  1457. *
  1458. * These macros encode that format.
  1459. */
  1460. #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
  1461. wifi_txrx, wifi_sh_ant_req) \
  1462. (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
  1463. (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
  1464. #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
  1465. lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
  1466. #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1467. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1468. (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
  1469. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1470. wifi_sh_ant_req))))
  1471. #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1472. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1473. LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
  1474. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1475. wifi_sh_ant_req))
  1476. #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
  1477. wifi_req, wifi_prio, wifi_txrx, \
  1478. wifi_sh_ant_req) \
  1479. LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
  1480. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1481. wifi_sh_ant_req))
  1482. #define LUT_WLAN_KILL_OP(lut, op, val) \
  1483. lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
  1484. #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1485. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1486. (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1487. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
  1488. #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1489. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1490. LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1491. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1492. #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1493. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1494. LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1495. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1496. #define LUT_ANT_SWITCH_OP(lut, op, val) \
  1497. lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
  1498. #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1499. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1500. (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1501. wifi_req, wifi_prio, wifi_txrx, \
  1502. wifi_sh_ant_req))))
  1503. #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1504. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1505. LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1506. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1507. #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1508. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1509. LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1510. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1511. static const __le32 iwlagn_def_3w_lookup[12] = {
  1512. cpu_to_le32(0xaaaaaaaa),
  1513. cpu_to_le32(0xaaaaaaaa),
  1514. cpu_to_le32(0xaeaaaaaa),
  1515. cpu_to_le32(0xaaaaaaaa),
  1516. cpu_to_le32(0xcc00ff28),
  1517. cpu_to_le32(0x0000aaaa),
  1518. cpu_to_le32(0xcc00aaaa),
  1519. cpu_to_le32(0x0000aaaa),
  1520. cpu_to_le32(0xc0004000),
  1521. cpu_to_le32(0x00004000),
  1522. cpu_to_le32(0xf0005000),
  1523. cpu_to_le32(0xf0004000),
  1524. };
  1525. static const __le32 iwlagn_concurrent_lookup[12] = {
  1526. cpu_to_le32(0xaaaaaaaa),
  1527. cpu_to_le32(0xaaaaaaaa),
  1528. cpu_to_le32(0xaaaaaaaa),
  1529. cpu_to_le32(0xaaaaaaaa),
  1530. cpu_to_le32(0xaaaaaaaa),
  1531. cpu_to_le32(0xaaaaaaaa),
  1532. cpu_to_le32(0xaaaaaaaa),
  1533. cpu_to_le32(0xaaaaaaaa),
  1534. cpu_to_le32(0x00000000),
  1535. cpu_to_le32(0x00000000),
  1536. cpu_to_le32(0x00000000),
  1537. cpu_to_le32(0x00000000),
  1538. };
  1539. void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
  1540. {
  1541. struct iwlagn_bt_cmd bt_cmd = {
  1542. .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
  1543. .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
  1544. .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
  1545. .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
  1546. };
  1547. BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
  1548. sizeof(bt_cmd.bt3_lookup_table));
  1549. bt_cmd.prio_boost = priv->cfg->bt_prio_boost;
  1550. bt_cmd.kill_ack_mask = priv->kill_ack_mask;
  1551. bt_cmd.kill_cts_mask = priv->kill_cts_mask;
  1552. bt_cmd.valid = priv->bt_valid;
  1553. /*
  1554. * Configure BT coex mode to "no coexistence" when the
  1555. * user disabled BT coexistence, we have no interface
  1556. * (might be in monitor mode), or the interface is in
  1557. * IBSS mode (no proper uCode support for coex then).
  1558. */
  1559. if (!bt_coex_active || priv->iw_mode == NL80211_IFTYPE_ADHOC) {
  1560. bt_cmd.flags = 0;
  1561. } else {
  1562. bt_cmd.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
  1563. IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
  1564. if (priv->bt_ch_announce)
  1565. bt_cmd.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
  1566. IWL_DEBUG_INFO(priv, "BT coex flag: 0X%x\n", bt_cmd.flags);
  1567. }
  1568. if (priv->bt_full_concurrent)
  1569. memcpy(bt_cmd.bt3_lookup_table, iwlagn_concurrent_lookup,
  1570. sizeof(iwlagn_concurrent_lookup));
  1571. else
  1572. memcpy(bt_cmd.bt3_lookup_table, iwlagn_def_3w_lookup,
  1573. sizeof(iwlagn_def_3w_lookup));
  1574. IWL_DEBUG_INFO(priv, "BT coex %s in %s mode\n",
  1575. bt_cmd.flags ? "active" : "disabled",
  1576. priv->bt_full_concurrent ?
  1577. "full concurrency" : "3-wire");
  1578. if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, sizeof(bt_cmd), &bt_cmd))
  1579. IWL_ERR(priv, "failed to send BT Coex Config\n");
  1580. /*
  1581. * When we are doing a restart, need to also reconfigure BT
  1582. * SCO to the device. If not doing a restart, bt_sco_active
  1583. * will always be false, so there's no need to have an extra
  1584. * variable to check for it.
  1585. */
  1586. if (priv->bt_sco_active) {
  1587. struct iwlagn_bt_sco_cmd sco_cmd = { .flags = 0 };
  1588. if (priv->bt_sco_active)
  1589. sco_cmd.flags |= IWLAGN_BT_SCO_ACTIVE;
  1590. if (iwl_send_cmd_pdu(priv, REPLY_BT_COEX_SCO,
  1591. sizeof(sco_cmd), &sco_cmd))
  1592. IWL_ERR(priv, "failed to send BT SCO command\n");
  1593. }
  1594. }
  1595. static void iwlagn_bt_traffic_change_work(struct work_struct *work)
  1596. {
  1597. struct iwl_priv *priv =
  1598. container_of(work, struct iwl_priv, bt_traffic_change_work);
  1599. struct iwl_rxon_context *ctx;
  1600. int smps_request = -1;
  1601. IWL_DEBUG_INFO(priv, "BT traffic load changes: %d\n",
  1602. priv->bt_traffic_load);
  1603. switch (priv->bt_traffic_load) {
  1604. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  1605. smps_request = IEEE80211_SMPS_AUTOMATIC;
  1606. break;
  1607. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  1608. smps_request = IEEE80211_SMPS_DYNAMIC;
  1609. break;
  1610. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  1611. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  1612. smps_request = IEEE80211_SMPS_STATIC;
  1613. break;
  1614. default:
  1615. IWL_ERR(priv, "Invalid BT traffic load: %d\n",
  1616. priv->bt_traffic_load);
  1617. break;
  1618. }
  1619. mutex_lock(&priv->mutex);
  1620. if (priv->cfg->ops->lib->update_chain_flags)
  1621. priv->cfg->ops->lib->update_chain_flags(priv);
  1622. if (smps_request != -1) {
  1623. for_each_context(priv, ctx) {
  1624. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
  1625. ieee80211_request_smps(ctx->vif, smps_request);
  1626. }
  1627. }
  1628. mutex_unlock(&priv->mutex);
  1629. }
  1630. static void iwlagn_print_uartmsg(struct iwl_priv *priv,
  1631. struct iwl_bt_uart_msg *uart_msg)
  1632. {
  1633. IWL_DEBUG_NOTIF(priv, "Message Type = 0x%X, SSN = 0x%X, "
  1634. "Update Req = 0x%X",
  1635. (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
  1636. BT_UART_MSG_FRAME1MSGTYPE_POS,
  1637. (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
  1638. BT_UART_MSG_FRAME1SSN_POS,
  1639. (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
  1640. BT_UART_MSG_FRAME1UPDATEREQ_POS);
  1641. IWL_DEBUG_NOTIF(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
  1642. "Chl_SeqN = 0x%X, In band = 0x%X",
  1643. (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
  1644. BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
  1645. (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
  1646. BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
  1647. (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
  1648. BT_UART_MSG_FRAME2CHLSEQN_POS,
  1649. (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
  1650. BT_UART_MSG_FRAME2INBAND_POS);
  1651. IWL_DEBUG_NOTIF(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
  1652. "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
  1653. (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
  1654. BT_UART_MSG_FRAME3SCOESCO_POS,
  1655. (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
  1656. BT_UART_MSG_FRAME3SNIFF_POS,
  1657. (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
  1658. BT_UART_MSG_FRAME3A2DP_POS,
  1659. (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
  1660. BT_UART_MSG_FRAME3ACL_POS,
  1661. (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
  1662. BT_UART_MSG_FRAME3MASTER_POS,
  1663. (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
  1664. BT_UART_MSG_FRAME3OBEX_POS);
  1665. IWL_DEBUG_NOTIF(priv, "Idle duration = 0x%X",
  1666. (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
  1667. BT_UART_MSG_FRAME4IDLEDURATION_POS);
  1668. IWL_DEBUG_NOTIF(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
  1669. "eSCO Retransmissions = 0x%X",
  1670. (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
  1671. BT_UART_MSG_FRAME5TXACTIVITY_POS,
  1672. (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
  1673. BT_UART_MSG_FRAME5RXACTIVITY_POS,
  1674. (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
  1675. BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
  1676. IWL_DEBUG_NOTIF(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
  1677. (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
  1678. BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
  1679. (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
  1680. BT_UART_MSG_FRAME6DISCOVERABLE_POS);
  1681. IWL_DEBUG_NOTIF(priv, "Sniff Activity = 0x%X, Inquiry/Page SR Mode = "
  1682. "0x%X, Connectable = 0x%X",
  1683. (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
  1684. BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
  1685. (BT_UART_MSG_FRAME7INQUIRYPAGESRMODE_MSK & uart_msg->frame7) >>
  1686. BT_UART_MSG_FRAME7INQUIRYPAGESRMODE_POS,
  1687. (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
  1688. BT_UART_MSG_FRAME7CONNECTABLE_POS);
  1689. }
  1690. static void iwlagn_set_kill_ack_msk(struct iwl_priv *priv,
  1691. struct iwl_bt_uart_msg *uart_msg)
  1692. {
  1693. u8 kill_ack_msk;
  1694. __le32 bt_kill_ack_msg[2] = {
  1695. cpu_to_le32(0xFFFFFFF), cpu_to_le32(0xFFFFFC00) };
  1696. kill_ack_msk = (((BT_UART_MSG_FRAME3A2DP_MSK |
  1697. BT_UART_MSG_FRAME3SNIFF_MSK |
  1698. BT_UART_MSG_FRAME3SCOESCO_MSK) &
  1699. uart_msg->frame3) == 0) ? 1 : 0;
  1700. if (priv->kill_ack_mask != bt_kill_ack_msg[kill_ack_msk]) {
  1701. priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
  1702. priv->kill_ack_mask = bt_kill_ack_msg[kill_ack_msk];
  1703. /* schedule to send runtime bt_config */
  1704. queue_work(priv->workqueue, &priv->bt_runtime_config);
  1705. }
  1706. }
  1707. void iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
  1708. struct iwl_rx_mem_buffer *rxb)
  1709. {
  1710. unsigned long flags;
  1711. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1712. struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
  1713. struct iwlagn_bt_sco_cmd sco_cmd = { .flags = 0 };
  1714. struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
  1715. u8 last_traffic_load;
  1716. IWL_DEBUG_NOTIF(priv, "BT Coex notification:\n");
  1717. IWL_DEBUG_NOTIF(priv, " status: %d\n", coex->bt_status);
  1718. IWL_DEBUG_NOTIF(priv, " traffic load: %d\n", coex->bt_traffic_load);
  1719. IWL_DEBUG_NOTIF(priv, " CI compliance: %d\n",
  1720. coex->bt_ci_compliance);
  1721. iwlagn_print_uartmsg(priv, uart_msg);
  1722. last_traffic_load = priv->notif_bt_traffic_load;
  1723. priv->notif_bt_traffic_load = coex->bt_traffic_load;
  1724. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  1725. if (priv->bt_status != coex->bt_status ||
  1726. last_traffic_load != coex->bt_traffic_load) {
  1727. if (coex->bt_status) {
  1728. /* BT on */
  1729. if (!priv->bt_ch_announce)
  1730. priv->bt_traffic_load =
  1731. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1732. else
  1733. priv->bt_traffic_load =
  1734. coex->bt_traffic_load;
  1735. } else {
  1736. /* BT off */
  1737. priv->bt_traffic_load =
  1738. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  1739. }
  1740. priv->bt_status = coex->bt_status;
  1741. queue_work(priv->workqueue,
  1742. &priv->bt_traffic_change_work);
  1743. }
  1744. if (priv->bt_sco_active !=
  1745. (uart_msg->frame3 & BT_UART_MSG_FRAME3SCOESCO_MSK)) {
  1746. priv->bt_sco_active = uart_msg->frame3 &
  1747. BT_UART_MSG_FRAME3SCOESCO_MSK;
  1748. if (priv->bt_sco_active)
  1749. sco_cmd.flags |= IWLAGN_BT_SCO_ACTIVE;
  1750. iwl_send_cmd_pdu_async(priv, REPLY_BT_COEX_SCO,
  1751. sizeof(sco_cmd), &sco_cmd, NULL);
  1752. }
  1753. }
  1754. iwlagn_set_kill_ack_msk(priv, uart_msg);
  1755. /* FIXME: based on notification, adjust the prio_boost */
  1756. spin_lock_irqsave(&priv->lock, flags);
  1757. priv->bt_ci_compliance = coex->bt_ci_compliance;
  1758. spin_unlock_irqrestore(&priv->lock, flags);
  1759. }
  1760. void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
  1761. {
  1762. iwlagn_rx_handler_setup(priv);
  1763. priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
  1764. iwlagn_bt_coex_profile_notif;
  1765. }
  1766. void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
  1767. {
  1768. iwlagn_setup_deferred_work(priv);
  1769. INIT_WORK(&priv->bt_traffic_change_work,
  1770. iwlagn_bt_traffic_change_work);
  1771. }
  1772. void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
  1773. {
  1774. cancel_work_sync(&priv->bt_traffic_change_work);
  1775. }