iwl-agn-lib.c 32 KB

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