2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
22 * Purpose: Handle USB interrupt endpoint
31 * 04-02-2004 Jerry Chen: Initial release
40 static const u8 fallback_rate0[5][5] = {
41 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
42 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
43 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
44 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
45 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
48 static const u8 fallback_rate1[5][5] = {
49 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
50 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
51 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
52 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
53 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
56 void vnt_int_start_interrupt(struct vnt_private *priv)
61 dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n");
63 spin_lock_irqsave(&priv->lock, flags);
65 status = vnt_start_interrupt_urb(priv);
67 spin_unlock_irqrestore(&priv->lock, flags);
70 static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr)
72 struct vnt_usb_send_context *context;
73 struct ieee80211_tx_info *info;
74 struct ieee80211_rate *rate;
75 u8 tx_retry = (tsr & 0xf0) >> 4;
78 if (pkt_no >= priv->num_tx_context)
81 context = priv->tx_context[pkt_no];
86 info = IEEE80211_SKB_CB(context->skb);
87 idx = info->control.rates[0].idx;
89 if (context->fb_option && !(tsr & (TSR_TMO | TSR_RETRYTMO))) {
93 rate = ieee80211_get_tx_rate(priv->hw, info);
94 tx_rate = rate->hw_value - RATE_18M;
99 if (context->fb_option == AUTO_FB_0)
100 tx_rate = fallback_rate0[tx_rate][retry];
101 else if (context->fb_option == AUTO_FB_1)
102 tx_rate = fallback_rate1[tx_rate][retry];
104 if (info->band == IEEE80211_BAND_5GHZ)
105 idx = tx_rate - RATE_6M;
110 ieee80211_tx_info_clear_status(info);
112 info->status.rates[0].count = tx_retry;
114 if (!(tsr & (TSR_TMO | TSR_RETRYTMO))) {
115 info->status.rates[0].idx = idx;
116 info->flags |= IEEE80211_TX_STAT_ACK;
119 ieee80211_tx_status_irqsafe(priv->hw, context->skb);
121 context->in_use = false;
126 void vnt_int_process_data(struct vnt_private *priv)
128 struct vnt_interrupt_data *int_data;
129 struct ieee80211_low_level_stats *low_stats = &priv->low_stats;
131 dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n");
133 int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf;
135 if (int_data->tsr0 & TSR_VALID)
136 vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0);
138 if (int_data->tsr1 & TSR_VALID)
139 vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1);
141 if (int_data->tsr2 & TSR_VALID)
142 vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2);
144 if (int_data->tsr3 & TSR_VALID)
145 vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3);
147 if (int_data->isr0 != 0) {
148 if (int_data->isr0 & ISR_BNTX &&
149 priv->op_mode == NL80211_IFTYPE_AP)
150 vnt_schedule_command(priv, WLAN_CMD_BECON_SEND);
152 if (int_data->isr0 & ISR_TBTT &&
153 priv->hw->conf.flags & IEEE80211_CONF_PS) {
154 if (!priv->wake_up_count)
155 priv->wake_up_count =
156 priv->hw->conf.listen_interval;
158 --priv->wake_up_count;
160 /* Turn on wake up to listen next beacon */
161 if (priv->wake_up_count == 1)
162 vnt_schedule_command(priv,
163 WLAN_CMD_TBTT_WAKEUP);
165 priv->current_tsf = le64_to_cpu(int_data->tsf);
167 low_stats->dot11RTSSuccessCount += int_data->rts_success;
168 low_stats->dot11RTSFailureCount += int_data->rts_fail;
169 low_stats->dot11ACKFailureCount += int_data->ack_fail;
170 low_stats->dot11FCSErrorCount += int_data->fcs_err;
173 priv->int_buf.in_use = false;