iwl-agn-lib.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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. static inline u32 iwlagn_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
  41. {
  42. return le32_to_cpup((__le32 *)&tx_resp->status +
  43. tx_resp->frame_count) & MAX_SN;
  44. }
  45. static int iwlagn_tx_status_reply_tx(struct iwl_priv *priv,
  46. struct iwl_ht_agg *agg,
  47. struct iwl5000_tx_resp *tx_resp,
  48. int txq_id, u16 start_idx)
  49. {
  50. u16 status;
  51. struct agg_tx_status *frame_status = &tx_resp->status;
  52. struct ieee80211_tx_info *info = NULL;
  53. struct ieee80211_hdr *hdr = NULL;
  54. u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  55. int i, sh, idx;
  56. u16 seq;
  57. if (agg->wait_for_ba)
  58. IWL_DEBUG_TX_REPLY(priv, "got tx response w/o block-ack\n");
  59. agg->frame_count = tx_resp->frame_count;
  60. agg->start_idx = start_idx;
  61. agg->rate_n_flags = rate_n_flags;
  62. agg->bitmap = 0;
  63. /* # frames attempted by Tx command */
  64. if (agg->frame_count == 1) {
  65. /* Only one frame was attempted; no block-ack will arrive */
  66. status = le16_to_cpu(frame_status[0].status);
  67. idx = start_idx;
  68. /* FIXME: code repetition */
  69. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, StartIdx=%d idx=%d\n",
  70. agg->frame_count, agg->start_idx, idx);
  71. info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
  72. info->status.rates[0].count = tx_resp->failure_frame + 1;
  73. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  74. info->flags |= iwl_tx_status_to_mac80211(status);
  75. iwlagn_hwrate_to_tx_control(priv, rate_n_flags, info);
  76. /* FIXME: code repetition end */
  77. IWL_DEBUG_TX_REPLY(priv, "1 Frame 0x%x failure :%d\n",
  78. status & 0xff, tx_resp->failure_frame);
  79. IWL_DEBUG_TX_REPLY(priv, "Rate Info rate_n_flags=%x\n", rate_n_flags);
  80. agg->wait_for_ba = 0;
  81. } else {
  82. /* Two or more frames were attempted; expect block-ack */
  83. u64 bitmap = 0;
  84. int start = agg->start_idx;
  85. /* Construct bit-map of pending frames within Tx window */
  86. for (i = 0; i < agg->frame_count; i++) {
  87. u16 sc;
  88. status = le16_to_cpu(frame_status[i].status);
  89. seq = le16_to_cpu(frame_status[i].sequence);
  90. idx = SEQ_TO_INDEX(seq);
  91. txq_id = SEQ_TO_QUEUE(seq);
  92. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  93. AGG_TX_STATE_ABORT_MSK))
  94. continue;
  95. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, txq_id=%d idx=%d\n",
  96. agg->frame_count, txq_id, idx);
  97. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  98. if (!hdr) {
  99. IWL_ERR(priv,
  100. "BUG_ON idx doesn't point to valid skb"
  101. " idx=%d, txq_id=%d\n", idx, txq_id);
  102. return -1;
  103. }
  104. sc = le16_to_cpu(hdr->seq_ctrl);
  105. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  106. IWL_ERR(priv,
  107. "BUG_ON idx doesn't match seq control"
  108. " idx=%d, seq_idx=%d, seq=%d\n",
  109. idx, SEQ_TO_SN(sc),
  110. hdr->seq_ctrl);
  111. return -1;
  112. }
  113. IWL_DEBUG_TX_REPLY(priv, "AGG Frame i=%d idx %d seq=%d\n",
  114. i, idx, SEQ_TO_SN(sc));
  115. sh = idx - start;
  116. if (sh > 64) {
  117. sh = (start - idx) + 0xff;
  118. bitmap = bitmap << sh;
  119. sh = 0;
  120. start = idx;
  121. } else if (sh < -64)
  122. sh = 0xff - (start - idx);
  123. else if (sh < 0) {
  124. sh = start - idx;
  125. start = idx;
  126. bitmap = bitmap << sh;
  127. sh = 0;
  128. }
  129. bitmap |= 1ULL << sh;
  130. IWL_DEBUG_TX_REPLY(priv, "start=%d bitmap=0x%llx\n",
  131. start, (unsigned long long)bitmap);
  132. }
  133. agg->bitmap = bitmap;
  134. agg->start_idx = start;
  135. IWL_DEBUG_TX_REPLY(priv, "Frames %d start_idx=%d bitmap=0x%llx\n",
  136. agg->frame_count, agg->start_idx,
  137. (unsigned long long)agg->bitmap);
  138. if (bitmap)
  139. agg->wait_for_ba = 1;
  140. }
  141. return 0;
  142. }
  143. void iwl_check_abort_status(struct iwl_priv *priv,
  144. u8 frame_count, u32 status)
  145. {
  146. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  147. IWL_ERR(priv, "TODO: Implement Tx flush command!!!\n");
  148. }
  149. }
  150. static void iwlagn_rx_reply_tx(struct iwl_priv *priv,
  151. struct iwl_rx_mem_buffer *rxb)
  152. {
  153. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  154. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  155. int txq_id = SEQ_TO_QUEUE(sequence);
  156. int index = SEQ_TO_INDEX(sequence);
  157. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  158. struct ieee80211_tx_info *info;
  159. struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  160. u32 status = le16_to_cpu(tx_resp->status.status);
  161. int tid;
  162. int sta_id;
  163. int freed;
  164. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  165. IWL_ERR(priv, "Read index for DMA queue txq_id (%d) index %d "
  166. "is out of range [0-%d] %d %d\n", txq_id,
  167. index, txq->q.n_bd, txq->q.write_ptr,
  168. txq->q.read_ptr);
  169. return;
  170. }
  171. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
  172. memset(&info->status, 0, sizeof(info->status));
  173. tid = (tx_resp->ra_tid & IWL50_TX_RES_TID_MSK) >> IWL50_TX_RES_TID_POS;
  174. sta_id = (tx_resp->ra_tid & IWL50_TX_RES_RA_MSK) >> IWL50_TX_RES_RA_POS;
  175. if (txq->sched_retry) {
  176. const u32 scd_ssn = iwlagn_get_scd_ssn(tx_resp);
  177. struct iwl_ht_agg *agg = NULL;
  178. agg = &priv->stations[sta_id].tid[tid].agg;
  179. iwlagn_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  180. /* check if BAR is needed */
  181. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
  182. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  183. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  184. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  185. IWL_DEBUG_TX_REPLY(priv, "Retry scheduler reclaim "
  186. "scd_ssn=%d idx=%d txq=%d swq=%d\n",
  187. scd_ssn , index, txq_id, txq->swq_id);
  188. freed = iwlagn_tx_queue_reclaim(priv, txq_id, index);
  189. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  190. if (priv->mac80211_registered &&
  191. (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  192. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)) {
  193. if (agg->state == IWL_AGG_OFF)
  194. iwl_wake_queue(priv, txq_id);
  195. else
  196. iwl_wake_queue(priv, txq->swq_id);
  197. }
  198. }
  199. } else {
  200. BUG_ON(txq_id != txq->swq_id);
  201. info->status.rates[0].count = tx_resp->failure_frame + 1;
  202. info->flags |= iwl_tx_status_to_mac80211(status);
  203. iwlagn_hwrate_to_tx_control(priv,
  204. le32_to_cpu(tx_resp->rate_n_flags),
  205. info);
  206. IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x) rate_n_flags "
  207. "0x%x retries %d\n",
  208. txq_id,
  209. iwl_get_tx_fail_reason(status), status,
  210. le32_to_cpu(tx_resp->rate_n_flags),
  211. tx_resp->failure_frame);
  212. freed = iwlagn_tx_queue_reclaim(priv, txq_id, index);
  213. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  214. if (priv->mac80211_registered &&
  215. (iwl_queue_space(&txq->q) > txq->q.low_mark))
  216. iwl_wake_queue(priv, txq_id);
  217. }
  218. iwlagn_txq_check_empty(priv, sta_id, tid, txq_id);
  219. iwl_check_abort_status(priv, tx_resp->frame_count, status);
  220. }
  221. void iwlagn_rx_handler_setup(struct iwl_priv *priv)
  222. {
  223. /* init calibration handlers */
  224. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  225. iwlagn_rx_calib_result;
  226. priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
  227. iwlagn_rx_calib_complete;
  228. priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
  229. }
  230. void iwlagn_setup_deferred_work(struct iwl_priv *priv)
  231. {
  232. /* in agn, the tx power calibration is done in uCode */
  233. priv->disable_tx_power_cal = 1;
  234. }
  235. int iwlagn_hw_valid_rtc_data_addr(u32 addr)
  236. {
  237. return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
  238. (addr < IWLAGN_RTC_DATA_UPPER_BOUND);
  239. }
  240. int iwlagn_send_tx_power(struct iwl_priv *priv)
  241. {
  242. struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
  243. u8 tx_ant_cfg_cmd;
  244. /* half dBm need to multiply */
  245. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  246. if (priv->tx_power_lmt_in_half_dbm &&
  247. priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
  248. /*
  249. * For the newer devices which using enhanced/extend tx power
  250. * table in EEPROM, the format is in half dBm. driver need to
  251. * convert to dBm format before report to mac80211.
  252. * By doing so, there is a possibility of 1/2 dBm resolution
  253. * lost. driver will perform "round-up" operation before
  254. * reporting, but it will cause 1/2 dBm tx power over the
  255. * regulatory limit. Perform the checking here, if the
  256. * "tx_power_user_lmt" is higher than EEPROM value (in
  257. * half-dBm format), lower the tx power based on EEPROM
  258. */
  259. tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
  260. }
  261. tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
  262. tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
  263. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  264. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  265. else
  266. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  267. return iwl_send_cmd_pdu_async(priv, tx_ant_cfg_cmd,
  268. sizeof(tx_power_cmd), &tx_power_cmd,
  269. NULL);
  270. }
  271. void iwlagn_temperature(struct iwl_priv *priv)
  272. {
  273. /* store temperature from statistics (in Celsius) */
  274. priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
  275. iwl_tt_handler(priv);
  276. }
  277. u16 iwlagn_eeprom_calib_version(struct iwl_priv *priv)
  278. {
  279. struct iwl_eeprom_calib_hdr {
  280. u8 version;
  281. u8 pa_type;
  282. u16 voltage;
  283. } *hdr;
  284. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  285. EEPROM_5000_CALIB_ALL);
  286. return hdr->version;
  287. }
  288. /*
  289. * EEPROM
  290. */
  291. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  292. {
  293. u16 offset = 0;
  294. if ((address & INDIRECT_ADDRESS) == 0)
  295. return address;
  296. switch (address & INDIRECT_TYPE_MSK) {
  297. case INDIRECT_HOST:
  298. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
  299. break;
  300. case INDIRECT_GENERAL:
  301. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
  302. break;
  303. case INDIRECT_REGULATORY:
  304. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
  305. break;
  306. case INDIRECT_CALIBRATION:
  307. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
  308. break;
  309. case INDIRECT_PROCESS_ADJST:
  310. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
  311. break;
  312. case INDIRECT_OTHERS:
  313. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
  314. break;
  315. default:
  316. IWL_ERR(priv, "illegal indirect type: 0x%X\n",
  317. address & INDIRECT_TYPE_MSK);
  318. break;
  319. }
  320. /* translate the offset from words to byte */
  321. return (address & ADDRESS_MSK) + (offset << 1);
  322. }
  323. const u8 *iwlagn_eeprom_query_addr(const struct iwl_priv *priv,
  324. size_t offset)
  325. {
  326. u32 address = eeprom_indirect_address(priv, offset);
  327. BUG_ON(address >= priv->cfg->eeprom_size);
  328. return &priv->eeprom[address];
  329. }
  330. struct iwl_mod_params iwlagn_mod_params = {
  331. .amsdu_size_8K = 1,
  332. .restart_fw = 1,
  333. /* the rest are 0 by default */
  334. };
  335. void iwlagn_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  336. {
  337. unsigned long flags;
  338. int i;
  339. spin_lock_irqsave(&rxq->lock, flags);
  340. INIT_LIST_HEAD(&rxq->rx_free);
  341. INIT_LIST_HEAD(&rxq->rx_used);
  342. /* Fill the rx_used queue with _all_ of the Rx buffers */
  343. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  344. /* In the reset function, these buffers may have been allocated
  345. * to an SKB, so we need to unmap and free potential storage */
  346. if (rxq->pool[i].page != NULL) {
  347. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  348. PAGE_SIZE << priv->hw_params.rx_page_order,
  349. PCI_DMA_FROMDEVICE);
  350. __iwl_free_pages(priv, rxq->pool[i].page);
  351. rxq->pool[i].page = NULL;
  352. }
  353. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  354. }
  355. for (i = 0; i < RX_QUEUE_SIZE; i++)
  356. rxq->queue[i] = NULL;
  357. /* Set us so that we have processed and used all buffers, but have
  358. * not restocked the Rx queue with fresh buffers */
  359. rxq->read = rxq->write = 0;
  360. rxq->write_actual = 0;
  361. rxq->free_count = 0;
  362. spin_unlock_irqrestore(&rxq->lock, flags);
  363. }
  364. int iwlagn_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  365. {
  366. u32 rb_size;
  367. const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
  368. u32 rb_timeout = 0; /* FIXME: RX_RB_TIMEOUT for all devices? */
  369. if (!priv->cfg->use_isr_legacy)
  370. rb_timeout = RX_RB_TIMEOUT;
  371. if (priv->cfg->mod_params->amsdu_size_8K)
  372. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  373. else
  374. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  375. /* Stop Rx DMA */
  376. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  377. /* Reset driver's Rx queue write index */
  378. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  379. /* Tell device where to find RBD circular buffer in DRAM */
  380. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  381. (u32)(rxq->dma_addr >> 8));
  382. /* Tell device where in DRAM to update its Rx status */
  383. iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
  384. rxq->rb_stts_dma >> 4);
  385. /* Enable Rx DMA
  386. * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set because of HW bug in
  387. * the credit mechanism in 5000 HW RX FIFO
  388. * Direct rx interrupts to hosts
  389. * Rx buffer size 4 or 8k
  390. * RB timeout 0x10
  391. * 256 RBDs
  392. */
  393. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
  394. FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  395. FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY |
  396. FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  397. FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK |
  398. rb_size|
  399. (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)|
  400. (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
  401. /* Set interrupt coalescing timer to default (2048 usecs) */
  402. iwl_write8(priv, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF);
  403. return 0;
  404. }
  405. int iwlagn_hw_nic_init(struct iwl_priv *priv)
  406. {
  407. unsigned long flags;
  408. struct iwl_rx_queue *rxq = &priv->rxq;
  409. int ret;
  410. /* nic_init */
  411. spin_lock_irqsave(&priv->lock, flags);
  412. priv->cfg->ops->lib->apm_ops.init(priv);
  413. /* Set interrupt coalescing calibration timer to default (512 usecs) */
  414. iwl_write8(priv, CSR_INT_COALESCING, IWL_HOST_INT_CALIB_TIMEOUT_DEF);
  415. spin_unlock_irqrestore(&priv->lock, flags);
  416. ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
  417. priv->cfg->ops->lib->apm_ops.config(priv);
  418. /* Allocate the RX queue, or reset if it is already allocated */
  419. if (!rxq->bd) {
  420. ret = iwl_rx_queue_alloc(priv);
  421. if (ret) {
  422. IWL_ERR(priv, "Unable to initialize Rx queue\n");
  423. return -ENOMEM;
  424. }
  425. } else
  426. iwlagn_rx_queue_reset(priv, rxq);
  427. iwlagn_rx_replenish(priv);
  428. iwlagn_rx_init(priv, rxq);
  429. spin_lock_irqsave(&priv->lock, flags);
  430. rxq->need_update = 1;
  431. iwl_rx_queue_update_write_ptr(priv, rxq);
  432. spin_unlock_irqrestore(&priv->lock, flags);
  433. /* Allocate and init all Tx and Command queues */
  434. ret = iwlagn_txq_ctx_reset(priv);
  435. if (ret)
  436. return ret;
  437. set_bit(STATUS_INIT, &priv->status);
  438. return 0;
  439. }
  440. /**
  441. * iwlagn_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  442. */
  443. static inline __le32 iwlagn_dma_addr2rbd_ptr(struct iwl_priv *priv,
  444. dma_addr_t dma_addr)
  445. {
  446. return cpu_to_le32((u32)(dma_addr >> 8));
  447. }
  448. /**
  449. * iwlagn_rx_queue_restock - refill RX queue from pre-allocated pool
  450. *
  451. * If there are slots in the RX queue that need to be restocked,
  452. * and we have free pre-allocated buffers, fill the ranks as much
  453. * as we can, pulling from rx_free.
  454. *
  455. * This moves the 'write' index forward to catch up with 'processed', and
  456. * also updates the memory address in the firmware to reference the new
  457. * target buffer.
  458. */
  459. void iwlagn_rx_queue_restock(struct iwl_priv *priv)
  460. {
  461. struct iwl_rx_queue *rxq = &priv->rxq;
  462. struct list_head *element;
  463. struct iwl_rx_mem_buffer *rxb;
  464. unsigned long flags;
  465. spin_lock_irqsave(&rxq->lock, flags);
  466. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  467. /* The overwritten rxb must be a used one */
  468. rxb = rxq->queue[rxq->write];
  469. BUG_ON(rxb && rxb->page);
  470. /* Get next free Rx buffer, remove from free list */
  471. element = rxq->rx_free.next;
  472. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  473. list_del(element);
  474. /* Point to Rx buffer via next RBD in circular buffer */
  475. rxq->bd[rxq->write] = iwlagn_dma_addr2rbd_ptr(priv,
  476. rxb->page_dma);
  477. rxq->queue[rxq->write] = rxb;
  478. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  479. rxq->free_count--;
  480. }
  481. spin_unlock_irqrestore(&rxq->lock, flags);
  482. /* If the pre-allocated buffer pool is dropping low, schedule to
  483. * refill it */
  484. if (rxq->free_count <= RX_LOW_WATERMARK)
  485. queue_work(priv->workqueue, &priv->rx_replenish);
  486. /* If we've added more space for the firmware to place data, tell it.
  487. * Increment device's write pointer in multiples of 8. */
  488. if (rxq->write_actual != (rxq->write & ~0x7)) {
  489. spin_lock_irqsave(&rxq->lock, flags);
  490. rxq->need_update = 1;
  491. spin_unlock_irqrestore(&rxq->lock, flags);
  492. iwl_rx_queue_update_write_ptr(priv, rxq);
  493. }
  494. }
  495. /**
  496. * iwlagn_rx_replenish - Move all used packet from rx_used to rx_free
  497. *
  498. * When moving to rx_free an SKB is allocated for the slot.
  499. *
  500. * Also restock the Rx queue via iwl_rx_queue_restock.
  501. * This is called as a scheduled work item (except for during initialization)
  502. */
  503. void iwlagn_rx_allocate(struct iwl_priv *priv, gfp_t priority)
  504. {
  505. struct iwl_rx_queue *rxq = &priv->rxq;
  506. struct list_head *element;
  507. struct iwl_rx_mem_buffer *rxb;
  508. struct page *page;
  509. unsigned long flags;
  510. gfp_t gfp_mask = priority;
  511. while (1) {
  512. spin_lock_irqsave(&rxq->lock, flags);
  513. if (list_empty(&rxq->rx_used)) {
  514. spin_unlock_irqrestore(&rxq->lock, flags);
  515. return;
  516. }
  517. spin_unlock_irqrestore(&rxq->lock, flags);
  518. if (rxq->free_count > RX_LOW_WATERMARK)
  519. gfp_mask |= __GFP_NOWARN;
  520. if (priv->hw_params.rx_page_order > 0)
  521. gfp_mask |= __GFP_COMP;
  522. /* Alloc a new receive buffer */
  523. page = alloc_pages(gfp_mask, priv->hw_params.rx_page_order);
  524. if (!page) {
  525. if (net_ratelimit())
  526. IWL_DEBUG_INFO(priv, "alloc_pages failed, "
  527. "order: %d\n",
  528. priv->hw_params.rx_page_order);
  529. if ((rxq->free_count <= RX_LOW_WATERMARK) &&
  530. net_ratelimit())
  531. IWL_CRIT(priv, "Failed to alloc_pages with %s. Only %u free buffers remaining.\n",
  532. priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
  533. rxq->free_count);
  534. /* We don't reschedule replenish work here -- we will
  535. * call the restock method and if it still needs
  536. * more buffers it will schedule replenish */
  537. return;
  538. }
  539. spin_lock_irqsave(&rxq->lock, flags);
  540. if (list_empty(&rxq->rx_used)) {
  541. spin_unlock_irqrestore(&rxq->lock, flags);
  542. __free_pages(page, priv->hw_params.rx_page_order);
  543. return;
  544. }
  545. element = rxq->rx_used.next;
  546. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  547. list_del(element);
  548. spin_unlock_irqrestore(&rxq->lock, flags);
  549. BUG_ON(rxb->page);
  550. rxb->page = page;
  551. /* Get physical address of the RB */
  552. rxb->page_dma = pci_map_page(priv->pci_dev, page, 0,
  553. PAGE_SIZE << priv->hw_params.rx_page_order,
  554. PCI_DMA_FROMDEVICE);
  555. /* dma address must be no more than 36 bits */
  556. BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
  557. /* and also 256 byte aligned! */
  558. BUG_ON(rxb->page_dma & DMA_BIT_MASK(8));
  559. spin_lock_irqsave(&rxq->lock, flags);
  560. list_add_tail(&rxb->list, &rxq->rx_free);
  561. rxq->free_count++;
  562. priv->alloc_rxb_page++;
  563. spin_unlock_irqrestore(&rxq->lock, flags);
  564. }
  565. }
  566. void iwlagn_rx_replenish(struct iwl_priv *priv)
  567. {
  568. unsigned long flags;
  569. iwlagn_rx_allocate(priv, GFP_KERNEL);
  570. spin_lock_irqsave(&priv->lock, flags);
  571. iwlagn_rx_queue_restock(priv);
  572. spin_unlock_irqrestore(&priv->lock, flags);
  573. }
  574. void iwlagn_rx_replenish_now(struct iwl_priv *priv)
  575. {
  576. iwlagn_rx_allocate(priv, GFP_ATOMIC);
  577. iwlagn_rx_queue_restock(priv);
  578. }
  579. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  580. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  581. * This free routine walks the list of POOL entries and if SKB is set to
  582. * non NULL it is unmapped and freed
  583. */
  584. void iwlagn_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  585. {
  586. int i;
  587. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  588. if (rxq->pool[i].page != NULL) {
  589. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  590. PAGE_SIZE << priv->hw_params.rx_page_order,
  591. PCI_DMA_FROMDEVICE);
  592. __iwl_free_pages(priv, rxq->pool[i].page);
  593. rxq->pool[i].page = NULL;
  594. }
  595. }
  596. dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  597. rxq->dma_addr);
  598. dma_free_coherent(&priv->pci_dev->dev, sizeof(struct iwl_rb_status),
  599. rxq->rb_stts, rxq->rb_stts_dma);
  600. rxq->bd = NULL;
  601. rxq->rb_stts = NULL;
  602. }
  603. int iwlagn_rxq_stop(struct iwl_priv *priv)
  604. {
  605. /* stop Rx DMA */
  606. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  607. iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
  608. FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  609. return 0;
  610. }
  611. int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  612. {
  613. int idx = 0;
  614. int band_offset = 0;
  615. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  616. if (rate_n_flags & RATE_MCS_HT_MSK) {
  617. idx = (rate_n_flags & 0xff);
  618. return idx;
  619. /* Legacy rate format, search for match in table */
  620. } else {
  621. if (band == IEEE80211_BAND_5GHZ)
  622. band_offset = IWL_FIRST_OFDM_RATE;
  623. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  624. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  625. return idx - band_offset;
  626. }
  627. return -1;
  628. }
  629. /* Calc max signal level (dBm) among 3 possible receivers */
  630. static inline int iwlagn_calc_rssi(struct iwl_priv *priv,
  631. struct iwl_rx_phy_res *rx_resp)
  632. {
  633. return priv->cfg->ops->utils->calc_rssi(priv, rx_resp);
  634. }
  635. #ifdef CONFIG_IWLWIFI_DEBUG
  636. /**
  637. * iwlagn_dbg_report_frame - dump frame to syslog during debug sessions
  638. *
  639. * You may hack this function to show different aspects of received frames,
  640. * including selective frame dumps.
  641. * group100 parameter selects whether to show 1 out of 100 good data frames.
  642. * All beacon and probe response frames are printed.
  643. */
  644. static void iwlagn_dbg_report_frame(struct iwl_priv *priv,
  645. struct iwl_rx_phy_res *phy_res, u16 length,
  646. struct ieee80211_hdr *header, int group100)
  647. {
  648. u32 to_us;
  649. u32 print_summary = 0;
  650. u32 print_dump = 0; /* set to 1 to dump all frames' contents */
  651. u32 hundred = 0;
  652. u32 dataframe = 0;
  653. __le16 fc;
  654. u16 seq_ctl;
  655. u16 channel;
  656. u16 phy_flags;
  657. u32 rate_n_flags;
  658. u32 tsf_low;
  659. int rssi;
  660. if (likely(!(iwl_get_debug_level(priv) & IWL_DL_RX)))
  661. return;
  662. /* MAC header */
  663. fc = header->frame_control;
  664. seq_ctl = le16_to_cpu(header->seq_ctrl);
  665. /* metadata */
  666. channel = le16_to_cpu(phy_res->channel);
  667. phy_flags = le16_to_cpu(phy_res->phy_flags);
  668. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  669. /* signal statistics */
  670. rssi = iwlagn_calc_rssi(priv, phy_res);
  671. tsf_low = le64_to_cpu(phy_res->timestamp) & 0x0ffffffff;
  672. to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
  673. /* if data frame is to us and all is good,
  674. * (optionally) print summary for only 1 out of every 100 */
  675. if (to_us && (fc & ~cpu_to_le16(IEEE80211_FCTL_PROTECTED)) ==
  676. cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
  677. dataframe = 1;
  678. if (!group100)
  679. print_summary = 1; /* print each frame */
  680. else if (priv->framecnt_to_us < 100) {
  681. priv->framecnt_to_us++;
  682. print_summary = 0;
  683. } else {
  684. priv->framecnt_to_us = 0;
  685. print_summary = 1;
  686. hundred = 1;
  687. }
  688. } else {
  689. /* print summary for all other frames */
  690. print_summary = 1;
  691. }
  692. if (print_summary) {
  693. char *title;
  694. int rate_idx;
  695. u32 bitrate;
  696. if (hundred)
  697. title = "100Frames";
  698. else if (ieee80211_has_retry(fc))
  699. title = "Retry";
  700. else if (ieee80211_is_assoc_resp(fc))
  701. title = "AscRsp";
  702. else if (ieee80211_is_reassoc_resp(fc))
  703. title = "RasRsp";
  704. else if (ieee80211_is_probe_resp(fc)) {
  705. title = "PrbRsp";
  706. print_dump = 1; /* dump frame contents */
  707. } else if (ieee80211_is_beacon(fc)) {
  708. title = "Beacon";
  709. print_dump = 1; /* dump frame contents */
  710. } else if (ieee80211_is_atim(fc))
  711. title = "ATIM";
  712. else if (ieee80211_is_auth(fc))
  713. title = "Auth";
  714. else if (ieee80211_is_deauth(fc))
  715. title = "DeAuth";
  716. else if (ieee80211_is_disassoc(fc))
  717. title = "DisAssoc";
  718. else
  719. title = "Frame";
  720. rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
  721. if (unlikely((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT))) {
  722. bitrate = 0;
  723. WARN_ON_ONCE(1);
  724. } else {
  725. bitrate = iwl_rates[rate_idx].ieee / 2;
  726. }
  727. /* print frame summary.
  728. * MAC addresses show just the last byte (for brevity),
  729. * but you can hack it to show more, if you'd like to. */
  730. if (dataframe)
  731. IWL_DEBUG_RX(priv, "%s: mhd=0x%04x, dst=0x%02x, "
  732. "len=%u, rssi=%d, chnl=%d, rate=%u,\n",
  733. title, le16_to_cpu(fc), header->addr1[5],
  734. length, rssi, channel, bitrate);
  735. else {
  736. /* src/dst addresses assume managed mode */
  737. IWL_DEBUG_RX(priv, "%s: 0x%04x, dst=0x%02x, src=0x%02x, "
  738. "len=%u, rssi=%d, tim=%lu usec, "
  739. "phy=0x%02x, chnl=%d\n",
  740. title, le16_to_cpu(fc), header->addr1[5],
  741. header->addr3[5], length, rssi,
  742. tsf_low - priv->scan_start_tsf,
  743. phy_flags, channel);
  744. }
  745. }
  746. if (print_dump)
  747. iwl_print_hex_dump(priv, IWL_DL_RX, header, length);
  748. }
  749. #endif
  750. static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
  751. {
  752. u32 decrypt_out = 0;
  753. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  754. RX_RES_STATUS_STATION_FOUND)
  755. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  756. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  757. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  758. /* packet was not encrypted */
  759. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  760. RX_RES_STATUS_SEC_TYPE_NONE)
  761. return decrypt_out;
  762. /* packet was encrypted with unknown alg */
  763. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  764. RX_RES_STATUS_SEC_TYPE_ERR)
  765. return decrypt_out;
  766. /* decryption was not done in HW */
  767. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  768. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  769. return decrypt_out;
  770. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  771. case RX_RES_STATUS_SEC_TYPE_CCMP:
  772. /* alg is CCM: check MIC only */
  773. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  774. /* Bad MIC */
  775. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  776. else
  777. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  778. break;
  779. case RX_RES_STATUS_SEC_TYPE_TKIP:
  780. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  781. /* Bad TTAK */
  782. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  783. break;
  784. }
  785. /* fall through if TTAK OK */
  786. default:
  787. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  788. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  789. else
  790. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  791. break;
  792. };
  793. IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
  794. decrypt_in, decrypt_out);
  795. return decrypt_out;
  796. }
  797. static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
  798. struct ieee80211_hdr *hdr,
  799. u16 len,
  800. u32 ampdu_status,
  801. struct iwl_rx_mem_buffer *rxb,
  802. struct ieee80211_rx_status *stats)
  803. {
  804. struct sk_buff *skb;
  805. __le16 fc = hdr->frame_control;
  806. /* We only process data packets if the interface is open */
  807. if (unlikely(!priv->is_open)) {
  808. IWL_DEBUG_DROP_LIMIT(priv,
  809. "Dropping packet while interface is not open.\n");
  810. return;
  811. }
  812. /* In case of HW accelerated crypto and bad decryption, drop */
  813. if (!priv->cfg->mod_params->sw_crypto &&
  814. iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
  815. return;
  816. skb = dev_alloc_skb(128);
  817. if (!skb) {
  818. IWL_ERR(priv, "dev_alloc_skb failed\n");
  819. return;
  820. }
  821. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  822. iwl_update_stats(priv, false, fc, len);
  823. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  824. ieee80211_rx(priv->hw, skb);
  825. priv->alloc_rxb_page--;
  826. rxb->page = NULL;
  827. }
  828. /* Called for REPLY_RX (legacy ABG frames), or
  829. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  830. void iwlagn_rx_reply_rx(struct iwl_priv *priv,
  831. struct iwl_rx_mem_buffer *rxb)
  832. {
  833. struct ieee80211_hdr *header;
  834. struct ieee80211_rx_status rx_status;
  835. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  836. struct iwl_rx_phy_res *phy_res;
  837. __le32 rx_pkt_status;
  838. struct iwl4965_rx_mpdu_res_start *amsdu;
  839. u32 len;
  840. u32 ampdu_status;
  841. u32 rate_n_flags;
  842. /**
  843. * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
  844. * REPLY_RX: physical layer info is in this buffer
  845. * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
  846. * command and cached in priv->last_phy_res
  847. *
  848. * Here we set up local variables depending on which command is
  849. * received.
  850. */
  851. if (pkt->hdr.cmd == REPLY_RX) {
  852. phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
  853. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
  854. + phy_res->cfg_phy_cnt);
  855. len = le16_to_cpu(phy_res->byte_count);
  856. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
  857. phy_res->cfg_phy_cnt + len);
  858. ampdu_status = le32_to_cpu(rx_pkt_status);
  859. } else {
  860. if (!priv->_agn.last_phy_res_valid) {
  861. IWL_ERR(priv, "MPDU frame without cached PHY data\n");
  862. return;
  863. }
  864. phy_res = &priv->_agn.last_phy_res;
  865. amsdu = (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
  866. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  867. len = le16_to_cpu(amsdu->byte_count);
  868. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
  869. ampdu_status = iwlagn_translate_rx_status(priv,
  870. le32_to_cpu(rx_pkt_status));
  871. }
  872. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  873. IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
  874. phy_res->cfg_phy_cnt);
  875. return;
  876. }
  877. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  878. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  879. IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
  880. le32_to_cpu(rx_pkt_status));
  881. return;
  882. }
  883. /* This will be used in several places later */
  884. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  885. /* rx_status carries information about the packet to mac80211 */
  886. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  887. rx_status.freq =
  888. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel));
  889. rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  890. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  891. rx_status.rate_idx =
  892. iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  893. rx_status.flag = 0;
  894. /* TSF isn't reliable. In order to allow smooth user experience,
  895. * this W/A doesn't propagate it to the mac80211 */
  896. /*rx_status.flag |= RX_FLAG_TSFT;*/
  897. priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  898. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  899. rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
  900. #ifdef CONFIG_IWLWIFI_DEBUG
  901. /* Set "1" to report good data frames in groups of 100 */
  902. if (unlikely(iwl_get_debug_level(priv) & IWL_DL_RX))
  903. iwlagn_dbg_report_frame(priv, phy_res, len, header, 1);
  904. #endif
  905. iwl_dbg_log_rx_data_frame(priv, len, header);
  906. IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
  907. rx_status.signal, (unsigned long long)rx_status.mactime);
  908. /*
  909. * "antenna number"
  910. *
  911. * It seems that the antenna field in the phy flags value
  912. * is actually a bit field. This is undefined by radiotap,
  913. * it wants an actual antenna number but I always get "7"
  914. * for most legacy frames I receive indicating that the
  915. * same frame was received on all three RX chains.
  916. *
  917. * I think this field should be removed in favor of a
  918. * new 802.11n radiotap field "RX chains" that is defined
  919. * as a bitmask.
  920. */
  921. rx_status.antenna =
  922. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
  923. >> RX_RES_PHY_FLAGS_ANTENNA_POS;
  924. /* set the preamble flag if appropriate */
  925. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  926. rx_status.flag |= RX_FLAG_SHORTPRE;
  927. /* Set up the HT phy flags */
  928. if (rate_n_flags & RATE_MCS_HT_MSK)
  929. rx_status.flag |= RX_FLAG_HT;
  930. if (rate_n_flags & RATE_MCS_HT40_MSK)
  931. rx_status.flag |= RX_FLAG_40MHZ;
  932. if (rate_n_flags & RATE_MCS_SGI_MSK)
  933. rx_status.flag |= RX_FLAG_SHORT_GI;
  934. iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
  935. rxb, &rx_status);
  936. }
  937. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  938. * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  939. void iwlagn_rx_reply_rx_phy(struct iwl_priv *priv,
  940. struct iwl_rx_mem_buffer *rxb)
  941. {
  942. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  943. priv->_agn.last_phy_res_valid = true;
  944. memcpy(&priv->_agn.last_phy_res, pkt->u.raw,
  945. sizeof(struct iwl_rx_phy_res));
  946. }