Linux 4.19.133
[linux/fpc-iii.git] / drivers / staging / vt6656 / int.c
blob43f461f75b971aeb3f7730a3f0250401bcae95f7
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4 * All rights reserved.
6 * File: int.c
8 * Purpose: Handle USB interrupt endpoint
10 * Author: Jerry Chen
12 * Date: Apr. 2, 2004
14 * Functions:
16 * Revision History:
17 * 04-02-2004 Jerry Chen: Initial release
21 #include "int.h"
22 #include "mac.h"
23 #include "power.h"
24 #include "usbpipe.h"
26 static const u8 fallback_rate0[5][5] = {
27 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
28 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
29 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
30 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
31 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
34 static const u8 fallback_rate1[5][5] = {
35 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
36 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
37 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
38 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
39 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
42 void vnt_int_start_interrupt(struct vnt_private *priv)
44 unsigned long flags;
45 int status;
47 dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n");
49 spin_lock_irqsave(&priv->lock, flags);
51 status = vnt_start_interrupt_urb(priv);
53 spin_unlock_irqrestore(&priv->lock, flags);
56 static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr)
58 struct vnt_usb_send_context *context;
59 struct ieee80211_tx_info *info;
60 struct ieee80211_rate *rate;
61 u8 tx_retry = (tsr & 0xf0) >> 4;
62 s8 idx;
64 if (pkt_no >= priv->num_tx_context)
65 return -EINVAL;
67 context = priv->tx_context[pkt_no];
69 if (!context->skb)
70 return -EINVAL;
72 info = IEEE80211_SKB_CB(context->skb);
73 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;
79 rate = ieee80211_get_tx_rate(priv->hw, info);
80 tx_rate = rate->hw_value - RATE_18M;
82 if (retry > 4)
83 retry = 4;
85 if (context->fb_option == AUTO_FB_0)
86 tx_rate = fallback_rate0[tx_rate][retry];
87 else if (context->fb_option == AUTO_FB_1)
88 tx_rate = fallback_rate1[tx_rate][retry];
90 if (info->band == NL80211_BAND_5GHZ)
91 idx = tx_rate - RATE_6M;
92 else
93 idx = tx_rate;
96 ieee80211_tx_info_clear_status(info);
98 info->status.rates[0].count = tx_retry;
100 if (!(tsr & TSR_TMO)) {
101 info->status.rates[0].idx = idx;
103 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
104 info->flags |= IEEE80211_TX_STAT_ACK;
107 ieee80211_tx_status_irqsafe(priv->hw, context->skb);
109 context->in_use = false;
111 return 0;
114 void vnt_int_process_data(struct vnt_private *priv)
116 struct vnt_interrupt_data *int_data;
117 struct ieee80211_low_level_stats *low_stats = &priv->low_stats;
119 dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n");
121 int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf;
123 if (int_data->tsr0 & TSR_VALID)
124 vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0);
126 if (int_data->tsr1 & TSR_VALID)
127 vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1);
129 if (int_data->tsr2 & TSR_VALID)
130 vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2);
132 if (int_data->tsr3 & TSR_VALID)
133 vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3);
135 if (int_data->isr0 != 0) {
136 if (int_data->isr0 & ISR_BNTX &&
137 priv->op_mode == NL80211_IFTYPE_AP)
138 vnt_schedule_command(priv, WLAN_CMD_BECON_SEND);
140 if (int_data->isr0 & ISR_TBTT &&
141 priv->hw->conf.flags & IEEE80211_CONF_PS) {
142 if (!priv->wake_up_count)
143 priv->wake_up_count =
144 priv->hw->conf.listen_interval;
146 if (priv->wake_up_count)
147 --priv->wake_up_count;
149 /* Turn on wake up to listen next beacon */
150 if (priv->wake_up_count == 1)
151 vnt_schedule_command(priv,
152 WLAN_CMD_TBTT_WAKEUP);
154 priv->current_tsf = le64_to_cpu(int_data->tsf);
156 low_stats->dot11RTSSuccessCount += int_data->rts_success;
157 low_stats->dot11RTSFailureCount += int_data->rts_fail;
158 low_stats->dot11ACKFailureCount += int_data->ack_fail;
159 low_stats->dot11FCSErrorCount += int_data->fcs_err;
162 priv->int_buf.in_use = false;