dpc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  4. * All rights reserved.
  5. *
  6. * File: dpc.c
  7. *
  8. * Purpose: handle dpc rx functions
  9. *
  10. * Author: Lyndon Chen
  11. *
  12. * Date: May 20, 2003
  13. *
  14. * Functions:
  15. *
  16. * Revision History:
  17. *
  18. */
  19. #include "device.h"
  20. #include "baseband.h"
  21. #include "rf.h"
  22. #include "dpc.h"
  23. static bool vnt_rx_data(struct vnt_private *priv, struct sk_buff *skb,
  24. u16 bytes_received)
  25. {
  26. struct ieee80211_hw *hw = priv->hw;
  27. struct ieee80211_supported_band *sband;
  28. struct ieee80211_rx_status rx_status = { 0 };
  29. struct ieee80211_hdr *hdr;
  30. __le16 fc;
  31. u8 *rsr, *new_rsr, *rssi;
  32. __le64 *tsf_time;
  33. u16 frame_size;
  34. int ii, r;
  35. u8 *rx_rate;
  36. u8 *skb_data;
  37. u8 rate_idx = 0;
  38. u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
  39. long rx_dbm;
  40. /* [31:16]RcvByteCount ( not include 4-byte Status ) */
  41. frame_size = le16_to_cpu(*((__le16 *)(skb->data + 2)));
  42. if (frame_size > 2346 || frame_size < 14) {
  43. dev_dbg(&priv->pcid->dev, "------- WRONG Length 1\n");
  44. return false;
  45. }
  46. skb_data = (u8 *)skb->data;
  47. rx_rate = skb_data + 1;
  48. sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
  49. for (r = RATE_1M; r < MAX_RATE; r++) {
  50. if (*rx_rate == rate[r])
  51. break;
  52. }
  53. priv->rx_rate = r;
  54. for (ii = 0; ii < sband->n_bitrates; ii++) {
  55. if (sband->bitrates[ii].hw_value == r) {
  56. rate_idx = ii;
  57. break;
  58. }
  59. }
  60. if (ii == sband->n_bitrates) {
  61. dev_dbg(&priv->pcid->dev, "Wrong RxRate %x\n", *rx_rate);
  62. return false;
  63. }
  64. tsf_time = (__le64 *)(skb_data + bytes_received - 12);
  65. new_rsr = skb_data + bytes_received - 3;
  66. rssi = skb_data + bytes_received - 2;
  67. rsr = skb_data + bytes_received - 1;
  68. if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
  69. return false;
  70. RFvRSSITodBm(priv, *rssi, &rx_dbm);
  71. priv->byBBPreEDRSSI = (u8)rx_dbm + 1;
  72. priv->uCurrRSSI = *rssi;
  73. skb_pull(skb, 4);
  74. skb_trim(skb, frame_size);
  75. rx_status.mactime = le64_to_cpu(*tsf_time);
  76. rx_status.band = hw->conf.chandef.chan->band;
  77. rx_status.signal = rx_dbm;
  78. rx_status.flag = 0;
  79. rx_status.freq = hw->conf.chandef.chan->center_freq;
  80. if (!(*rsr & RSR_CRCOK))
  81. rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
  82. hdr = (struct ieee80211_hdr *)(skb->data);
  83. fc = hdr->frame_control;
  84. rx_status.rate_idx = rate_idx;
  85. if (ieee80211_has_protected(fc)) {
  86. if (priv->byLocalID > REV_ID_VT3253_A1)
  87. rx_status.flag |= RX_FLAG_DECRYPTED;
  88. /* Drop packet */
  89. if (!(*new_rsr & NEWRSR_DECRYPTOK))
  90. return false;
  91. }
  92. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  93. ieee80211_rx_irqsafe(priv->hw, skb);
  94. return true;
  95. }
  96. bool vnt_receive_frame(struct vnt_private *priv, struct vnt_rx_desc *curr_rd)
  97. {
  98. struct vnt_rd_info *rd_info = curr_rd->rd_info;
  99. struct sk_buff *skb;
  100. u16 frame_size;
  101. skb = rd_info->skb;
  102. dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma,
  103. priv->rx_buf_sz, DMA_FROM_DEVICE);
  104. frame_size = le16_to_cpu(curr_rd->rd1.req_count)
  105. - le16_to_cpu(curr_rd->rd0.res_count);
  106. if ((frame_size > 2364) || (frame_size < 33)) {
  107. /* Frame Size error drop this packet.*/
  108. dev_dbg(&priv->pcid->dev, "Wrong frame size %d\n", frame_size);
  109. dev_kfree_skb_irq(skb);
  110. return true;
  111. }
  112. if (vnt_rx_data(priv, skb, frame_size))
  113. return true;
  114. dev_kfree_skb_irq(skb);
  115. return true;
  116. }