int.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. *
  20. * File: int.c
  21. *
  22. * Purpose: Handle USB interrupt endpoint
  23. *
  24. * Author: Jerry Chen
  25. *
  26. * Date: Apr. 2, 2004
  27. *
  28. * Functions:
  29. *
  30. * Revision History:
  31. * 04-02-2004 Jerry Chen: Initial release
  32. *
  33. */
  34. #include "int.h"
  35. #include "mac.h"
  36. #include "power.h"
  37. #include "usbpipe.h"
  38. static const u8 fallback_rate0[5][5] = {
  39. {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
  40. {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
  41. {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
  42. {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
  43. {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
  44. };
  45. static const u8 fallback_rate1[5][5] = {
  46. {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
  47. {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
  48. {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
  49. {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
  50. {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
  51. };
  52. void vnt_int_start_interrupt(struct vnt_private *priv)
  53. {
  54. unsigned long flags;
  55. int status;
  56. dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n");
  57. spin_lock_irqsave(&priv->lock, flags);
  58. status = vnt_start_interrupt_urb(priv);
  59. spin_unlock_irqrestore(&priv->lock, flags);
  60. }
  61. static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr)
  62. {
  63. struct vnt_usb_send_context *context;
  64. struct ieee80211_tx_info *info;
  65. struct ieee80211_rate *rate;
  66. u8 tx_retry = (tsr & 0xf0) >> 4;
  67. s8 idx;
  68. if (pkt_no >= priv->num_tx_context)
  69. return -EINVAL;
  70. context = priv->tx_context[pkt_no];
  71. if (!context->skb)
  72. return -EINVAL;
  73. info = IEEE80211_SKB_CB(context->skb);
  74. idx = info->control.rates[0].idx;
  75. if (context->fb_option && !(tsr & (TSR_TMO | TSR_RETRYTMO))) {
  76. u8 tx_rate;
  77. u8 retry = tx_retry;
  78. rate = ieee80211_get_tx_rate(priv->hw, info);
  79. tx_rate = rate->hw_value - RATE_18M;
  80. if (retry > 4)
  81. retry = 4;
  82. if (context->fb_option == AUTO_FB_0)
  83. tx_rate = fallback_rate0[tx_rate][retry];
  84. else if (context->fb_option == AUTO_FB_1)
  85. tx_rate = fallback_rate1[tx_rate][retry];
  86. if (info->band == IEEE80211_BAND_5GHZ)
  87. idx = tx_rate - RATE_6M;
  88. else
  89. idx = tx_rate;
  90. }
  91. ieee80211_tx_info_clear_status(info);
  92. info->status.rates[0].count = tx_retry;
  93. if (!(tsr & (TSR_TMO | TSR_RETRYTMO))) {
  94. info->status.rates[0].idx = idx;
  95. info->flags |= IEEE80211_TX_STAT_ACK;
  96. }
  97. ieee80211_tx_status_irqsafe(priv->hw, context->skb);
  98. context->in_use = false;
  99. return 0;
  100. }
  101. void vnt_int_process_data(struct vnt_private *priv)
  102. {
  103. struct vnt_interrupt_data *int_data;
  104. struct ieee80211_low_level_stats *low_stats = &priv->low_stats;
  105. dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n");
  106. int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf;
  107. if (int_data->tsr0 & TSR_VALID)
  108. vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0);
  109. if (int_data->tsr1 & TSR_VALID)
  110. vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1);
  111. if (int_data->tsr2 & TSR_VALID)
  112. vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2);
  113. if (int_data->tsr3 & TSR_VALID)
  114. vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3);
  115. if (int_data->isr0 != 0) {
  116. if (int_data->isr0 & ISR_BNTX &&
  117. priv->op_mode == NL80211_IFTYPE_AP)
  118. vnt_schedule_command(priv, WLAN_CMD_BECON_SEND);
  119. if (int_data->isr0 & ISR_TBTT &&
  120. priv->hw->conf.flags & IEEE80211_CONF_PS) {
  121. if (!priv->wake_up_count)
  122. priv->wake_up_count =
  123. priv->hw->conf.listen_interval;
  124. --priv->wake_up_count;
  125. /* Turn on wake up to listen next beacon */
  126. if (priv->wake_up_count == 1)
  127. vnt_schedule_command(priv,
  128. WLAN_CMD_TBTT_WAKEUP);
  129. }
  130. priv->current_tsf = le64_to_cpu(int_data->tsf);
  131. low_stats->dot11RTSSuccessCount += int_data->rts_success;
  132. low_stats->dot11RTSFailureCount += int_data->rts_fail;
  133. low_stats->dot11ACKFailureCount += int_data->ack_fail;
  134. low_stats->dot11FCSErrorCount += int_data->fcs_err;
  135. }
  136. priv->int_buf.in_use = false;
  137. }