treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / staging / vt6656 / int.c
blobaf215860be4c6c2a1028065920c0d88fb3c7df57
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 int vnt_int_start_interrupt(struct vnt_private *priv)
44 int ret = 0;
45 unsigned long flags;
47 dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n");
49 spin_lock_irqsave(&priv->lock, flags);
51 ret = vnt_start_interrupt_urb(priv);
53 spin_unlock_irqrestore(&priv->lock, flags);
55 return ret;
58 static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr)
60 struct vnt_usb_send_context *context;
61 struct ieee80211_tx_info *info;
62 struct ieee80211_rate *rate;
63 u8 tx_retry = (tsr & 0xf0) >> 4;
64 s8 idx;
66 if (pkt_no >= priv->num_tx_context)
67 return -EINVAL;
69 context = priv->tx_context[pkt_no];
71 if (!context->skb)
72 return -EINVAL;
74 info = IEEE80211_SKB_CB(context->skb);
75 idx = info->control.rates[0].idx;
77 if (context->fb_option && !(tsr & (TSR_TMO | TSR_RETRYTMO))) {
78 u8 tx_rate;
79 u8 retry = tx_retry;
81 rate = ieee80211_get_tx_rate(priv->hw, info);
82 tx_rate = rate->hw_value - RATE_18M;
84 if (retry > 4)
85 retry = 4;
87 if (context->fb_option == AUTO_FB_0)
88 tx_rate = fallback_rate0[tx_rate][retry];
89 else if (context->fb_option == AUTO_FB_1)
90 tx_rate = fallback_rate1[tx_rate][retry];
92 if (info->band == NL80211_BAND_5GHZ)
93 idx = tx_rate - RATE_6M;
94 else
95 idx = tx_rate;
98 ieee80211_tx_info_clear_status(info);
100 info->status.rates[0].count = tx_retry;
102 if (!(tsr & TSR_TMO)) {
103 info->status.rates[0].idx = idx;
105 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
106 info->flags |= IEEE80211_TX_STAT_ACK;
109 ieee80211_tx_status_irqsafe(priv->hw, context->skb);
111 context->in_use = false;
113 return 0;
116 void vnt_int_process_data(struct vnt_private *priv)
118 struct vnt_interrupt_data *int_data;
119 struct ieee80211_low_level_stats *low_stats = &priv->low_stats;
121 dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n");
123 int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf;
125 if (int_data->tsr0 & TSR_VALID)
126 vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0);
128 if (int_data->tsr1 & TSR_VALID)
129 vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1);
131 if (int_data->tsr2 & TSR_VALID)
132 vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2);
134 if (int_data->tsr3 & TSR_VALID)
135 vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3);
137 if (int_data->isr0 != 0) {
138 if (int_data->isr0 & ISR_BNTX &&
139 priv->op_mode == NL80211_IFTYPE_AP)
140 vnt_schedule_command(priv, WLAN_CMD_BECON_SEND);
142 if (int_data->isr0 & ISR_TBTT &&
143 priv->hw->conf.flags & IEEE80211_CONF_PS) {
144 if (!priv->wake_up_count)
145 priv->wake_up_count =
146 priv->hw->conf.listen_interval;
148 --priv->wake_up_count;
150 /* Turn on wake up to listen next beacon */
151 if (priv->wake_up_count == 1)
152 vnt_schedule_command(priv,
153 WLAN_CMD_TBTT_WAKEUP);
155 priv->current_tsf = le64_to_cpu(int_data->tsf);
157 low_stats->dot11RTSSuccessCount += int_data->rts_success;
158 low_stats->dot11RTSFailureCount += int_data->rts_fail;
159 low_stats->dot11ACKFailureCount += int_data->ack_fail;
160 low_stats->dot11FCSErrorCount += int_data->fcs_err;
163 priv->int_buf.in_use = false;