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.
18 * Purpose: Handle USB interrupt endpoint
27 * 04-02-2004 Jerry Chen: Initial release
36 static const u8 fallback_rate0[5][5] = {
37 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
38 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
39 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
40 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
41 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
44 static const u8 fallback_rate1[5][5] = {
45 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
46 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
47 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
48 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
49 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
52 void vnt_int_start_interrupt(struct vnt_private *priv)
57 dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n");
59 spin_lock_irqsave(&priv->lock, flags);
61 status = vnt_start_interrupt_urb(priv);
63 spin_unlock_irqrestore(&priv->lock, flags);
66 static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr)
68 struct vnt_usb_send_context *context;
69 struct ieee80211_tx_info *info;
70 struct ieee80211_rate *rate;
71 u8 tx_retry = (tsr & 0xf0) >> 4;
74 if (pkt_no >= priv->num_tx_context)
77 context = priv->tx_context[pkt_no];
82 info = IEEE80211_SKB_CB(context->skb);
83 idx = info->control.rates[0].idx;
85 if (context->fb_option && !(tsr & (TSR_TMO | TSR_RETRYTMO))) {
89 rate = ieee80211_get_tx_rate(priv->hw, info);
90 tx_rate = rate->hw_value - RATE_18M;
95 if (context->fb_option == AUTO_FB_0)
96 tx_rate = fallback_rate0[tx_rate][retry];
97 else if (context->fb_option == AUTO_FB_1)
98 tx_rate = fallback_rate1[tx_rate][retry];
100 if (info->band == NL80211_BAND_5GHZ)
101 idx = tx_rate - RATE_6M;
106 ieee80211_tx_info_clear_status(info);
108 info->status.rates[0].count = tx_retry;
110 if (!(tsr & TSR_TMO)) {
111 info->status.rates[0].idx = idx;
113 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
114 info->flags |= IEEE80211_TX_STAT_ACK;
117 ieee80211_tx_status_irqsafe(priv->hw, context->skb);
119 context->in_use = false;
124 void vnt_int_process_data(struct vnt_private *priv)
126 struct vnt_interrupt_data *int_data;
127 struct ieee80211_low_level_stats *low_stats = &priv->low_stats;
129 dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n");
131 int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf;
133 if (int_data->tsr0 & TSR_VALID)
134 vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0);
136 if (int_data->tsr1 & TSR_VALID)
137 vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1);
139 if (int_data->tsr2 & TSR_VALID)
140 vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2);
142 if (int_data->tsr3 & TSR_VALID)
143 vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3);
145 if (int_data->isr0 != 0) {
146 if (int_data->isr0 & ISR_BNTX &&
147 priv->op_mode == NL80211_IFTYPE_AP)
148 vnt_schedule_command(priv, WLAN_CMD_BECON_SEND);
150 if (int_data->isr0 & ISR_TBTT &&
151 priv->hw->conf.flags & IEEE80211_CONF_PS) {
152 if (!priv->wake_up_count)
153 priv->wake_up_count =
154 priv->hw->conf.listen_interval;
156 if (priv->wake_up_count)
157 --priv->wake_up_count;
159 /* Turn on wake up to listen next beacon */
160 if (priv->wake_up_count == 1)
161 vnt_schedule_command(priv,
162 WLAN_CMD_TBTT_WAKEUP);
164 priv->current_tsf = le64_to_cpu(int_data->tsf);
166 low_stats->dot11RTSSuccessCount += int_data->rts_success;
167 low_stats->dot11RTSFailureCount += int_data->rts_fail;
168 low_stats->dot11ACKFailureCount += int_data->ack_fail;
169 low_stats->dot11FCSErrorCount += int_data->fcs_err;
172 priv->int_buf.in_use = false;