Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 35 | #include "int.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 36 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 37 | #include "power.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 38 | #include "usbpipe.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 39 | |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 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} |
| 46 | }; |
| 47 | |
| 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} |
| 54 | }; |
| 55 | |
Malcolm Priestley | 6200193 | 2014-07-15 19:54:35 +0100 | [diff] [blame] | 56 | void vnt_int_start_interrupt(struct vnt_private *priv) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 57 | { |
Malcolm Priestley | 0b596b2 | 2014-05-24 14:36:57 +0100 | [diff] [blame] | 58 | unsigned long flags; |
Malcolm Priestley | 526fed3 | 2014-07-15 19:54:32 +0100 | [diff] [blame] | 59 | int status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 60 | |
Malcolm Priestley | 5073060 | 2014-07-15 19:54:33 +0100 | [diff] [blame] | 61 | dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 62 | |
Malcolm Priestley | 526fed3 | 2014-07-15 19:54:32 +0100 | [diff] [blame] | 63 | spin_lock_irqsave(&priv->lock, flags); |
Malcolm Priestley | 749627f | 2014-02-17 21:24:33 +0000 | [diff] [blame] | 64 | |
Malcolm Priestley | b0bc572 | 2014-07-15 19:54:37 +0100 | [diff] [blame] | 65 | status = vnt_start_interrupt_urb(priv); |
Malcolm Priestley | 749627f | 2014-02-17 21:24:33 +0000 | [diff] [blame] | 66 | |
Malcolm Priestley | 526fed3 | 2014-07-15 19:54:32 +0100 | [diff] [blame] | 67 | spin_unlock_irqrestore(&priv->lock, flags); |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 68 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 69 | |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 70 | static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr) |
| 71 | { |
| 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; |
| 76 | s8 idx; |
| 77 | |
Malcolm Priestley | 03b7e35 | 2014-07-19 12:30:04 +0100 | [diff] [blame] | 78 | if (pkt_no >= priv->num_tx_context) |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 79 | return -EINVAL; |
| 80 | |
Malcolm Priestley | f7e4a8f | 2014-07-18 06:36:16 +0100 | [diff] [blame] | 81 | context = priv->tx_context[pkt_no]; |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 82 | |
| 83 | if (!context->skb) |
| 84 | return -EINVAL; |
| 85 | |
| 86 | info = IEEE80211_SKB_CB(context->skb); |
| 87 | idx = info->control.rates[0].idx; |
| 88 | |
| 89 | if (context->fb_option && !(tsr & (TSR_TMO | TSR_RETRYTMO))) { |
| 90 | u8 tx_rate; |
| 91 | u8 retry = tx_retry; |
| 92 | |
| 93 | rate = ieee80211_get_tx_rate(priv->hw, info); |
| 94 | tx_rate = rate->hw_value - RATE_18M; |
| 95 | |
| 96 | if (retry > 4) |
| 97 | retry = 4; |
| 98 | |
| 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]; |
| 103 | |
| 104 | if (info->band == IEEE80211_BAND_5GHZ) |
| 105 | idx = tx_rate - RATE_6M; |
| 106 | else |
| 107 | idx = tx_rate; |
| 108 | } |
| 109 | |
| 110 | ieee80211_tx_info_clear_status(info); |
| 111 | |
| 112 | info->status.rates[0].count = tx_retry; |
| 113 | |
| 114 | if (!(tsr & (TSR_TMO | TSR_RETRYTMO))) { |
| 115 | info->status.rates[0].idx = idx; |
| 116 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 117 | } |
| 118 | |
| 119 | ieee80211_tx_status_irqsafe(priv->hw, context->skb); |
| 120 | |
| 121 | context->in_use = false; |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Malcolm Priestley | e360d2b | 2014-07-15 19:54:34 +0100 | [diff] [blame] | 126 | void vnt_int_process_data(struct vnt_private *priv) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 127 | { |
Malcolm Priestley | 210098a | 2014-02-16 19:10:18 +0000 | [diff] [blame] | 128 | struct vnt_interrupt_data *int_data; |
Malcolm Priestley | 1786384 | 2014-06-29 20:39:54 +0100 | [diff] [blame] | 129 | struct ieee80211_low_level_stats *low_stats = &priv->low_stats; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 130 | |
Malcolm Priestley | 5073060 | 2014-07-15 19:54:33 +0100 | [diff] [blame] | 131 | dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 132 | |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 133 | int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf; |
Malcolm Priestley | 210098a | 2014-02-16 19:10:18 +0000 | [diff] [blame] | 134 | |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 135 | if (int_data->tsr0 & TSR_VALID) |
| 136 | vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0); |
Malcolm Priestley | 210098a | 2014-02-16 19:10:18 +0000 | [diff] [blame] | 137 | |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 138 | if (int_data->tsr1 & TSR_VALID) |
| 139 | vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1); |
Malcolm Priestley | 210098a | 2014-02-16 19:10:18 +0000 | [diff] [blame] | 140 | |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 141 | if (int_data->tsr2 & TSR_VALID) |
| 142 | vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2); |
Malcolm Priestley | 210098a | 2014-02-16 19:10:18 +0000 | [diff] [blame] | 143 | |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 144 | if (int_data->tsr3 & TSR_VALID) |
| 145 | vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3); |
Malcolm Priestley | 210098a | 2014-02-16 19:10:18 +0000 | [diff] [blame] | 146 | |
| 147 | if (int_data->isr0 != 0) { |
Malcolm Priestley | c224642 | 2014-06-25 21:14:32 +0100 | [diff] [blame] | 148 | if (int_data->isr0 & ISR_BNTX && |
| 149 | priv->op_mode == NL80211_IFTYPE_AP) |
Malcolm Priestley | 57981a6 | 2014-07-13 10:42:50 +0100 | [diff] [blame] | 150 | vnt_schedule_command(priv, WLAN_CMD_BECON_SEND); |
Malcolm Priestley | 210098a | 2014-02-16 19:10:18 +0000 | [diff] [blame] | 151 | |
| 152 | if (int_data->isr0 & ISR_TBTT) { |
Malcolm Priestley | c224642 | 2014-06-25 21:14:32 +0100 | [diff] [blame] | 153 | if (priv->hw->conf.flags & IEEE80211_CONF_PS) |
Malcolm Priestley | 57981a6 | 2014-07-13 10:42:50 +0100 | [diff] [blame] | 154 | vnt_schedule_command(priv, |
| 155 | WLAN_CMD_TBTT_WAKEUP); |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 156 | } |
Malcolm Priestley | 113f0b9 | 2014-07-19 12:30:13 +0100 | [diff] [blame] | 157 | priv->current_tsf = le64_to_cpu(int_data->tsf); |
Malcolm Priestley | 1786384 | 2014-06-29 20:39:54 +0100 | [diff] [blame] | 158 | |
| 159 | low_stats->dot11RTSSuccessCount += int_data->rts_success; |
| 160 | low_stats->dot11RTSFailureCount += int_data->rts_fail; |
| 161 | low_stats->dot11ACKFailureCount += int_data->ack_fail; |
| 162 | low_stats->dot11FCSErrorCount += int_data->fcs_err; |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 163 | } |
Malcolm Priestley | 210098a | 2014-02-16 19:10:18 +0000 | [diff] [blame] | 164 | |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 165 | priv->int_buf.in_use = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 166 | } |