iwl-agn-lib.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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 or reset and init all Tx and Command queues */
  434. if (!priv->txq) {
  435. ret = iwlagn_txq_ctx_alloc(priv);
  436. if (ret)
  437. return ret;
  438. } else
  439. iwlagn_txq_ctx_reset(priv);
  440. set_bit(STATUS_INIT, &priv->status);
  441. return 0;
  442. }
  443. /**
  444. * iwlagn_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  445. */
  446. static inline __le32 iwlagn_dma_addr2rbd_ptr(struct iwl_priv *priv,
  447. dma_addr_t dma_addr)
  448. {
  449. return cpu_to_le32((u32)(dma_addr >> 8));
  450. }
  451. /**
  452. * iwlagn_rx_queue_restock - refill RX queue from pre-allocated pool
  453. *
  454. * If there are slots in the RX queue that need to be restocked,
  455. * and we have free pre-allocated buffers, fill the ranks as much
  456. * as we can, pulling from rx_free.
  457. *
  458. * This moves the 'write' index forward to catch up with 'processed', and
  459. * also updates the memory address in the firmware to reference the new
  460. * target buffer.
  461. */
  462. void iwlagn_rx_queue_restock(struct iwl_priv *priv)
  463. {
  464. struct iwl_rx_queue *rxq = &priv->rxq;
  465. struct list_head *element;
  466. struct iwl_rx_mem_buffer *rxb;
  467. unsigned long flags;
  468. spin_lock_irqsave(&rxq->lock, flags);
  469. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  470. /* The overwritten rxb must be a used one */
  471. rxb = rxq->queue[rxq->write];
  472. BUG_ON(rxb && rxb->page);
  473. /* Get next free Rx buffer, remove from free list */
  474. element = rxq->rx_free.next;
  475. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  476. list_del(element);
  477. /* Point to Rx buffer via next RBD in circular buffer */
  478. rxq->bd[rxq->write] = iwlagn_dma_addr2rbd_ptr(priv,
  479. rxb->page_dma);
  480. rxq->queue[rxq->write] = rxb;
  481. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  482. rxq->free_count--;
  483. }
  484. spin_unlock_irqrestore(&rxq->lock, flags);
  485. /* If the pre-allocated buffer pool is dropping low, schedule to
  486. * refill it */
  487. if (rxq->free_count <= RX_LOW_WATERMARK)
  488. queue_work(priv->workqueue, &priv->rx_replenish);
  489. /* If we've added more space for the firmware to place data, tell it.
  490. * Increment device's write pointer in multiples of 8. */
  491. if (rxq->write_actual != (rxq->write & ~0x7)) {
  492. spin_lock_irqsave(&rxq->lock, flags);
  493. rxq->need_update = 1;
  494. spin_unlock_irqrestore(&rxq->lock, flags);
  495. iwl_rx_queue_update_write_ptr(priv, rxq);
  496. }
  497. }
  498. /**
  499. * iwlagn_rx_replenish - Move all used packet from rx_used to rx_free
  500. *
  501. * When moving to rx_free an SKB is allocated for the slot.
  502. *
  503. * Also restock the Rx queue via iwl_rx_queue_restock.
  504. * This is called as a scheduled work item (except for during initialization)
  505. */
  506. void iwlagn_rx_allocate(struct iwl_priv *priv, gfp_t priority)
  507. {
  508. struct iwl_rx_queue *rxq = &priv->rxq;
  509. struct list_head *element;
  510. struct iwl_rx_mem_buffer *rxb;
  511. struct page *page;
  512. unsigned long flags;
  513. gfp_t gfp_mask = priority;
  514. while (1) {
  515. spin_lock_irqsave(&rxq->lock, flags);
  516. if (list_empty(&rxq->rx_used)) {
  517. spin_unlock_irqrestore(&rxq->lock, flags);
  518. return;
  519. }
  520. spin_unlock_irqrestore(&rxq->lock, flags);
  521. if (rxq->free_count > RX_LOW_WATERMARK)
  522. gfp_mask |= __GFP_NOWARN;
  523. if (priv->hw_params.rx_page_order > 0)
  524. gfp_mask |= __GFP_COMP;
  525. /* Alloc a new receive buffer */
  526. page = alloc_pages(gfp_mask, priv->hw_params.rx_page_order);
  527. if (!page) {
  528. if (net_ratelimit())
  529. IWL_DEBUG_INFO(priv, "alloc_pages failed, "
  530. "order: %d\n",
  531. priv->hw_params.rx_page_order);
  532. if ((rxq->free_count <= RX_LOW_WATERMARK) &&
  533. net_ratelimit())
  534. IWL_CRIT(priv, "Failed to alloc_pages with %s. Only %u free buffers remaining.\n",
  535. priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
  536. rxq->free_count);
  537. /* We don't reschedule replenish work here -- we will
  538. * call the restock method and if it still needs
  539. * more buffers it will schedule replenish */
  540. return;
  541. }
  542. spin_lock_irqsave(&rxq->lock, flags);
  543. if (list_empty(&rxq->rx_used)) {
  544. spin_unlock_irqrestore(&rxq->lock, flags);
  545. __free_pages(page, priv->hw_params.rx_page_order);
  546. return;
  547. }
  548. element = rxq->rx_used.next;
  549. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  550. list_del(element);
  551. spin_unlock_irqrestore(&rxq->lock, flags);
  552. BUG_ON(rxb->page);
  553. rxb->page = page;
  554. /* Get physical address of the RB */
  555. rxb->page_dma = pci_map_page(priv->pci_dev, page, 0,
  556. PAGE_SIZE << priv->hw_params.rx_page_order,
  557. PCI_DMA_FROMDEVICE);
  558. /* dma address must be no more than 36 bits */
  559. BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
  560. /* and also 256 byte aligned! */
  561. BUG_ON(rxb->page_dma & DMA_BIT_MASK(8));
  562. spin_lock_irqsave(&rxq->lock, flags);
  563. list_add_tail(&rxb->list, &rxq->rx_free);
  564. rxq->free_count++;
  565. priv->alloc_rxb_page++;
  566. spin_unlock_irqrestore(&rxq->lock, flags);
  567. }
  568. }
  569. void iwlagn_rx_replenish(struct iwl_priv *priv)
  570. {
  571. unsigned long flags;
  572. iwlagn_rx_allocate(priv, GFP_KERNEL);
  573. spin_lock_irqsave(&priv->lock, flags);
  574. iwlagn_rx_queue_restock(priv);
  575. spin_unlock_irqrestore(&priv->lock, flags);
  576. }
  577. void iwlagn_rx_replenish_now(struct iwl_priv *priv)
  578. {
  579. iwlagn_rx_allocate(priv, GFP_ATOMIC);
  580. iwlagn_rx_queue_restock(priv);
  581. }
  582. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  583. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  584. * This free routine walks the list of POOL entries and if SKB is set to
  585. * non NULL it is unmapped and freed
  586. */
  587. void iwlagn_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  588. {
  589. int i;
  590. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  591. if (rxq->pool[i].page != NULL) {
  592. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  593. PAGE_SIZE << priv->hw_params.rx_page_order,
  594. PCI_DMA_FROMDEVICE);
  595. __iwl_free_pages(priv, rxq->pool[i].page);
  596. rxq->pool[i].page = NULL;
  597. }
  598. }
  599. dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  600. rxq->dma_addr);
  601. dma_free_coherent(&priv->pci_dev->dev, sizeof(struct iwl_rb_status),
  602. rxq->rb_stts, rxq->rb_stts_dma);
  603. rxq->bd = NULL;
  604. rxq->rb_stts = NULL;
  605. }
  606. int iwlagn_rxq_stop(struct iwl_priv *priv)
  607. {
  608. /* stop Rx DMA */
  609. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  610. iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
  611. FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  612. return 0;
  613. }
  614. int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  615. {
  616. int idx = 0;
  617. int band_offset = 0;
  618. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  619. if (rate_n_flags & RATE_MCS_HT_MSK) {
  620. idx = (rate_n_flags & 0xff);
  621. return idx;
  622. /* Legacy rate format, search for match in table */
  623. } else {
  624. if (band == IEEE80211_BAND_5GHZ)
  625. band_offset = IWL_FIRST_OFDM_RATE;
  626. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  627. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  628. return idx - band_offset;
  629. }
  630. return -1;
  631. }
  632. /* Calc max signal level (dBm) among 3 possible receivers */
  633. static inline int iwlagn_calc_rssi(struct iwl_priv *priv,
  634. struct iwl_rx_phy_res *rx_resp)
  635. {
  636. return priv->cfg->ops->utils->calc_rssi(priv, rx_resp);
  637. }
  638. #ifdef CONFIG_IWLWIFI_DEBUG
  639. /**
  640. * iwlagn_dbg_report_frame - dump frame to syslog during debug sessions
  641. *
  642. * You may hack this function to show different aspects of received frames,
  643. * including selective frame dumps.
  644. * group100 parameter selects whether to show 1 out of 100 good data frames.
  645. * All beacon and probe response frames are printed.
  646. */
  647. static void iwlagn_dbg_report_frame(struct iwl_priv *priv,
  648. struct iwl_rx_phy_res *phy_res, u16 length,
  649. struct ieee80211_hdr *header, int group100)
  650. {
  651. u32 to_us;
  652. u32 print_summary = 0;
  653. u32 print_dump = 0; /* set to 1 to dump all frames' contents */
  654. u32 hundred = 0;
  655. u32 dataframe = 0;
  656. __le16 fc;
  657. u16 seq_ctl;
  658. u16 channel;
  659. u16 phy_flags;
  660. u32 rate_n_flags;
  661. u32 tsf_low;
  662. int rssi;
  663. if (likely(!(iwl_get_debug_level(priv) & IWL_DL_RX)))
  664. return;
  665. /* MAC header */
  666. fc = header->frame_control;
  667. seq_ctl = le16_to_cpu(header->seq_ctrl);
  668. /* metadata */
  669. channel = le16_to_cpu(phy_res->channel);
  670. phy_flags = le16_to_cpu(phy_res->phy_flags);
  671. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  672. /* signal statistics */
  673. rssi = iwlagn_calc_rssi(priv, phy_res);
  674. tsf_low = le64_to_cpu(phy_res->timestamp) & 0x0ffffffff;
  675. to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
  676. /* if data frame is to us and all is good,
  677. * (optionally) print summary for only 1 out of every 100 */
  678. if (to_us && (fc & ~cpu_to_le16(IEEE80211_FCTL_PROTECTED)) ==
  679. cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
  680. dataframe = 1;
  681. if (!group100)
  682. print_summary = 1; /* print each frame */
  683. else if (priv->framecnt_to_us < 100) {
  684. priv->framecnt_to_us++;
  685. print_summary = 0;
  686. } else {
  687. priv->framecnt_to_us = 0;
  688. print_summary = 1;
  689. hundred = 1;
  690. }
  691. } else {
  692. /* print summary for all other frames */
  693. print_summary = 1;
  694. }
  695. if (print_summary) {
  696. char *title;
  697. int rate_idx;
  698. u32 bitrate;
  699. if (hundred)
  700. title = "100Frames";
  701. else if (ieee80211_has_retry(fc))
  702. title = "Retry";
  703. else if (ieee80211_is_assoc_resp(fc))
  704. title = "AscRsp";
  705. else if (ieee80211_is_reassoc_resp(fc))
  706. title = "RasRsp";
  707. else if (ieee80211_is_probe_resp(fc)) {
  708. title = "PrbRsp";
  709. print_dump = 1; /* dump frame contents */
  710. } else if (ieee80211_is_beacon(fc)) {
  711. title = "Beacon";
  712. print_dump = 1; /* dump frame contents */
  713. } else if (ieee80211_is_atim(fc))
  714. title = "ATIM";
  715. else if (ieee80211_is_auth(fc))
  716. title = "Auth";
  717. else if (ieee80211_is_deauth(fc))
  718. title = "DeAuth";
  719. else if (ieee80211_is_disassoc(fc))
  720. title = "DisAssoc";
  721. else
  722. title = "Frame";
  723. rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
  724. if (unlikely((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT))) {
  725. bitrate = 0;
  726. WARN_ON_ONCE(1);
  727. } else {
  728. bitrate = iwl_rates[rate_idx].ieee / 2;
  729. }
  730. /* print frame summary.
  731. * MAC addresses show just the last byte (for brevity),
  732. * but you can hack it to show more, if you'd like to. */
  733. if (dataframe)
  734. IWL_DEBUG_RX(priv, "%s: mhd=0x%04x, dst=0x%02x, "
  735. "len=%u, rssi=%d, chnl=%d, rate=%u,\n",
  736. title, le16_to_cpu(fc), header->addr1[5],
  737. length, rssi, channel, bitrate);
  738. else {
  739. /* src/dst addresses assume managed mode */
  740. IWL_DEBUG_RX(priv, "%s: 0x%04x, dst=0x%02x, src=0x%02x, "
  741. "len=%u, rssi=%d, tim=%lu usec, "
  742. "phy=0x%02x, chnl=%d\n",
  743. title, le16_to_cpu(fc), header->addr1[5],
  744. header->addr3[5], length, rssi,
  745. tsf_low - priv->scan_start_tsf,
  746. phy_flags, channel);
  747. }
  748. }
  749. if (print_dump)
  750. iwl_print_hex_dump(priv, IWL_DL_RX, header, length);
  751. }
  752. #endif
  753. static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
  754. {
  755. u32 decrypt_out = 0;
  756. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  757. RX_RES_STATUS_STATION_FOUND)
  758. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  759. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  760. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  761. /* packet was not encrypted */
  762. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  763. RX_RES_STATUS_SEC_TYPE_NONE)
  764. return decrypt_out;
  765. /* packet was encrypted with unknown alg */
  766. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  767. RX_RES_STATUS_SEC_TYPE_ERR)
  768. return decrypt_out;
  769. /* decryption was not done in HW */
  770. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  771. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  772. return decrypt_out;
  773. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  774. case RX_RES_STATUS_SEC_TYPE_CCMP:
  775. /* alg is CCM: check MIC only */
  776. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  777. /* Bad MIC */
  778. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  779. else
  780. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  781. break;
  782. case RX_RES_STATUS_SEC_TYPE_TKIP:
  783. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  784. /* Bad TTAK */
  785. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  786. break;
  787. }
  788. /* fall through if TTAK OK */
  789. default:
  790. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  791. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  792. else
  793. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  794. break;
  795. };
  796. IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
  797. decrypt_in, decrypt_out);
  798. return decrypt_out;
  799. }
  800. static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
  801. struct ieee80211_hdr *hdr,
  802. u16 len,
  803. u32 ampdu_status,
  804. struct iwl_rx_mem_buffer *rxb,
  805. struct ieee80211_rx_status *stats)
  806. {
  807. struct sk_buff *skb;
  808. __le16 fc = hdr->frame_control;
  809. /* We only process data packets if the interface is open */
  810. if (unlikely(!priv->is_open)) {
  811. IWL_DEBUG_DROP_LIMIT(priv,
  812. "Dropping packet while interface is not open.\n");
  813. return;
  814. }
  815. /* In case of HW accelerated crypto and bad decryption, drop */
  816. if (!priv->cfg->mod_params->sw_crypto &&
  817. iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
  818. return;
  819. skb = dev_alloc_skb(128);
  820. if (!skb) {
  821. IWL_ERR(priv, "dev_alloc_skb failed\n");
  822. return;
  823. }
  824. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  825. iwl_update_stats(priv, false, fc, len);
  826. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  827. ieee80211_rx(priv->hw, skb);
  828. priv->alloc_rxb_page--;
  829. rxb->page = NULL;
  830. }
  831. /* Called for REPLY_RX (legacy ABG frames), or
  832. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  833. void iwlagn_rx_reply_rx(struct iwl_priv *priv,
  834. struct iwl_rx_mem_buffer *rxb)
  835. {
  836. struct ieee80211_hdr *header;
  837. struct ieee80211_rx_status rx_status;
  838. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  839. struct iwl_rx_phy_res *phy_res;
  840. __le32 rx_pkt_status;
  841. struct iwl4965_rx_mpdu_res_start *amsdu;
  842. u32 len;
  843. u32 ampdu_status;
  844. u32 rate_n_flags;
  845. /**
  846. * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
  847. * REPLY_RX: physical layer info is in this buffer
  848. * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
  849. * command and cached in priv->last_phy_res
  850. *
  851. * Here we set up local variables depending on which command is
  852. * received.
  853. */
  854. if (pkt->hdr.cmd == REPLY_RX) {
  855. phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
  856. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
  857. + phy_res->cfg_phy_cnt);
  858. len = le16_to_cpu(phy_res->byte_count);
  859. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
  860. phy_res->cfg_phy_cnt + len);
  861. ampdu_status = le32_to_cpu(rx_pkt_status);
  862. } else {
  863. if (!priv->_agn.last_phy_res_valid) {
  864. IWL_ERR(priv, "MPDU frame without cached PHY data\n");
  865. return;
  866. }
  867. phy_res = &priv->_agn.last_phy_res;
  868. amsdu = (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
  869. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  870. len = le16_to_cpu(amsdu->byte_count);
  871. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
  872. ampdu_status = iwlagn_translate_rx_status(priv,
  873. le32_to_cpu(rx_pkt_status));
  874. }
  875. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  876. IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
  877. phy_res->cfg_phy_cnt);
  878. return;
  879. }
  880. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  881. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  882. IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
  883. le32_to_cpu(rx_pkt_status));
  884. return;
  885. }
  886. /* This will be used in several places later */
  887. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  888. /* rx_status carries information about the packet to mac80211 */
  889. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  890. rx_status.freq =
  891. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel));
  892. rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  893. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  894. rx_status.rate_idx =
  895. iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  896. rx_status.flag = 0;
  897. /* TSF isn't reliable. In order to allow smooth user experience,
  898. * this W/A doesn't propagate it to the mac80211 */
  899. /*rx_status.flag |= RX_FLAG_TSFT;*/
  900. priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  901. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  902. rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
  903. #ifdef CONFIG_IWLWIFI_DEBUG
  904. /* Set "1" to report good data frames in groups of 100 */
  905. if (unlikely(iwl_get_debug_level(priv) & IWL_DL_RX))
  906. iwlagn_dbg_report_frame(priv, phy_res, len, header, 1);
  907. #endif
  908. iwl_dbg_log_rx_data_frame(priv, len, header);
  909. IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
  910. rx_status.signal, (unsigned long long)rx_status.mactime);
  911. /*
  912. * "antenna number"
  913. *
  914. * It seems that the antenna field in the phy flags value
  915. * is actually a bit field. This is undefined by radiotap,
  916. * it wants an actual antenna number but I always get "7"
  917. * for most legacy frames I receive indicating that the
  918. * same frame was received on all three RX chains.
  919. *
  920. * I think this field should be removed in favor of a
  921. * new 802.11n radiotap field "RX chains" that is defined
  922. * as a bitmask.
  923. */
  924. rx_status.antenna =
  925. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
  926. >> RX_RES_PHY_FLAGS_ANTENNA_POS;
  927. /* set the preamble flag if appropriate */
  928. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  929. rx_status.flag |= RX_FLAG_SHORTPRE;
  930. /* Set up the HT phy flags */
  931. if (rate_n_flags & RATE_MCS_HT_MSK)
  932. rx_status.flag |= RX_FLAG_HT;
  933. if (rate_n_flags & RATE_MCS_HT40_MSK)
  934. rx_status.flag |= RX_FLAG_40MHZ;
  935. if (rate_n_flags & RATE_MCS_SGI_MSK)
  936. rx_status.flag |= RX_FLAG_SHORT_GI;
  937. iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
  938. rxb, &rx_status);
  939. }
  940. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  941. * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  942. void iwlagn_rx_reply_rx_phy(struct iwl_priv *priv,
  943. struct iwl_rx_mem_buffer *rxb)
  944. {
  945. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  946. priv->_agn.last_phy_res_valid = true;
  947. memcpy(&priv->_agn.last_phy_res, pkt->u.raw,
  948. sizeof(struct iwl_rx_phy_res));
  949. }