1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4 * All rights reserved.
5 *
6 * File: int.c
7 *
8 * Purpose: Handle USB interrupt endpoint
9 *
10 * Author: Jerry Chen
11 *
12 * Date: Apr. 2, 2004
13 *
14 * Functions:
15 *
16 * Revision History:
17 * 04-02-2004 Jerry Chen: Initial release
18 *
19 */
20
21 #include "int.h"
22 #include "mac.h"
23 #include "power.h"
24 #include "usbpipe.h"
25
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}
32 };
33
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}
40 };
41
vnt_int_start_interrupt(struct vnt_private * priv)42 void vnt_int_start_interrupt(struct vnt_private *priv)
43 {
44 unsigned long flags;
45 int status;
46
47 dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n");
48
49 spin_lock_irqsave(&priv->lock, flags);
50
51 status = vnt_start_interrupt_urb(priv);
52
53 spin_unlock_irqrestore(&priv->lock, flags);
54 }
55
vnt_int_report_rate(struct vnt_private * priv,u8 pkt_no,u8 tsr)56 static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr)
57 {
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;
63
64 if (pkt_no >= priv->num_tx_context)
65 return -EINVAL;
66
67 context = priv->tx_context[pkt_no];
68
69 if (!context->skb)
70 return -EINVAL;
71
72 info = IEEE80211_SKB_CB(context->skb);
73 idx = info->control.rates[0].idx;
74
75 if (context->fb_option && !(tsr & (TSR_TMO | TSR_RETRYTMO))) {
76 u8 tx_rate;
77 u8 retry = tx_retry;
78
79 rate = ieee80211_get_tx_rate(priv->hw, info);
80 tx_rate = rate->hw_value - RATE_18M;
81
82 if (retry > 4)
83 retry = 4;
84
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];
89
90 if (info->band == NL80211_BAND_5GHZ)
91 idx = tx_rate - RATE_6M;
92 else
93 idx = tx_rate;
94 }
95
96 ieee80211_tx_info_clear_status(info);
97
98 info->status.rates[0].count = tx_retry;
99
100 if (!(tsr & (TSR_TMO | TSR_RETRYTMO))) {
101 info->status.rates[0].idx = idx;
102 info->flags |= IEEE80211_TX_STAT_ACK;
103 }
104
105 ieee80211_tx_status_irqsafe(priv->hw, context->skb);
106
107 context->in_use = false;
108
109 return 0;
110 }
111
vnt_int_process_data(struct vnt_private * priv)112 void vnt_int_process_data(struct vnt_private *priv)
113 {
114 struct vnt_interrupt_data *int_data;
115 struct ieee80211_low_level_stats *low_stats = &priv->low_stats;
116
117 dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n");
118
119 int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf;
120
121 if (int_data->tsr0 & TSR_VALID)
122 vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0);
123
124 if (int_data->tsr1 & TSR_VALID)
125 vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1);
126
127 if (int_data->tsr2 & TSR_VALID)
128 vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2);
129
130 if (int_data->tsr3 & TSR_VALID)
131 vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3);
132
133 if (int_data->isr0 != 0) {
134 if (int_data->isr0 & ISR_BNTX &&
135 priv->op_mode == NL80211_IFTYPE_AP)
136 vnt_schedule_command(priv, WLAN_CMD_BECON_SEND);
137
138 if (int_data->isr0 & ISR_TBTT &&
139 priv->hw->conf.flags & IEEE80211_CONF_PS) {
140 if (!priv->wake_up_count)
141 priv->wake_up_count =
142 priv->hw->conf.listen_interval;
143
144 --priv->wake_up_count;
145
146 /* Turn on wake up to listen next beacon */
147 if (priv->wake_up_count == 1)
148 vnt_schedule_command(priv,
149 WLAN_CMD_TBTT_WAKEUP);
150 }
151 priv->current_tsf = le64_to_cpu(int_data->tsf);
152
153 low_stats->dot11RTSSuccessCount += int_data->rts_success;
154 low_stats->dot11RTSFailureCount += int_data->rts_fail;
155 low_stats->dot11ACKFailureCount += int_data->ack_fail;
156 low_stats->dot11FCSErrorCount += int_data->fcs_err;
157 }
158
159 priv->int_buf.in_use = false;
160 }
161