bna: fix interrupts storm caused by erroneous packets
[linux/fpc-iii.git] / drivers / staging / vt6656 / usbpipe.c
blob88bf518f23eb6c5360ffb07ab8359d08b4fcf33d
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
20 * File: usbpipe.c
22 * Purpose: Handle USB control endpoint
24 * Author: Warren Hsu
26 * Date: Mar. 29, 2005
28 * Functions:
29 * vnt_control_out - Write variable length bytes to MEM/BB/MAC/EEPROM
30 * vnt_control_in - Read variable length bytes from MEM/BB/MAC/EEPROM
31 * vnt_control_out_u8 - Write one byte to MEM/BB/MAC/EEPROM
32 * vnt_control_in_u8 - Read one byte from MEM/BB/MAC/EEPROM
34 * Revision History:
35 * 04-05-2004 Jerry Chen: Initial release
36 * 11-24-2004 Warren Hsu: Add ControlvWriteByte,ControlvReadByte,ControlvMaskByte
40 #include "int.h"
41 #include "rxtx.h"
42 #include "dpc.h"
43 #include "desc.h"
44 #include "device.h"
45 #include "usbpipe.h"
47 #define USB_CTL_WAIT 500 /* ms */
49 int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
50 u16 index, u16 length, u8 *buffer)
52 int status = 0;
54 if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
55 return STATUS_FAILURE;
57 mutex_lock(&priv->usb_lock);
59 status = usb_control_msg(priv->usb,
60 usb_sndctrlpipe(priv->usb, 0), request, 0x40, value,
61 index, buffer, length, USB_CTL_WAIT);
63 mutex_unlock(&priv->usb_lock);
65 if (status < (int)length)
66 return STATUS_FAILURE;
68 return STATUS_SUCCESS;
71 void vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data)
73 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
74 reg_off, reg, sizeof(u8), &data);
77 int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
78 u16 index, u16 length, u8 *buffer)
80 int status;
82 if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
83 return STATUS_FAILURE;
85 mutex_lock(&priv->usb_lock);
87 status = usb_control_msg(priv->usb,
88 usb_rcvctrlpipe(priv->usb, 0), request, 0xc0, value,
89 index, buffer, length, USB_CTL_WAIT);
91 mutex_unlock(&priv->usb_lock);
93 if (status < (int)length)
94 return STATUS_FAILURE;
96 return STATUS_SUCCESS;
99 void vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data)
101 vnt_control_in(priv, MESSAGE_TYPE_READ,
102 reg_off, reg, sizeof(u8), data);
105 static void vnt_start_interrupt_urb_complete(struct urb *urb)
107 struct vnt_private *priv = urb->context;
108 int status;
110 switch (urb->status) {
111 case 0:
112 case -ETIMEDOUT:
113 break;
114 case -ECONNRESET:
115 case -ENOENT:
116 case -ESHUTDOWN:
117 priv->int_buf.in_use = false;
118 return;
119 default:
120 break;
123 status = urb->status;
125 if (status != STATUS_SUCCESS) {
126 priv->int_buf.in_use = false;
128 dev_dbg(&priv->usb->dev, "%s status = %d\n", __func__, status);
129 } else {
130 vnt_int_process_data(priv);
133 status = usb_submit_urb(priv->interrupt_urb, GFP_ATOMIC);
134 if (status)
135 dev_dbg(&priv->usb->dev, "Submit int URB failed %d\n", status);
136 else
137 priv->int_buf.in_use = true;
140 int vnt_start_interrupt_urb(struct vnt_private *priv)
142 int status = STATUS_FAILURE;
144 if (priv->int_buf.in_use == true)
145 return STATUS_FAILURE;
147 priv->int_buf.in_use = true;
149 usb_fill_int_urb(priv->interrupt_urb,
150 priv->usb,
151 usb_rcvintpipe(priv->usb, 1),
152 priv->int_buf.data_buf,
153 MAX_INTERRUPT_SIZE,
154 vnt_start_interrupt_urb_complete,
155 priv,
156 priv->int_interval);
158 status = usb_submit_urb(priv->interrupt_urb, GFP_ATOMIC);
159 if (status) {
160 dev_dbg(&priv->usb->dev, "Submit int URB failed %d\n", status);
161 priv->int_buf.in_use = false;
164 return status;
167 static void vnt_submit_rx_urb_complete(struct urb *urb)
169 struct vnt_rcb *rcb = urb->context;
170 struct vnt_private *priv = rcb->priv;
171 unsigned long flags;
173 switch (urb->status) {
174 case 0:
175 break;
176 case -ECONNRESET:
177 case -ENOENT:
178 case -ESHUTDOWN:
179 return;
180 case -ETIMEDOUT:
181 default:
182 dev_dbg(&priv->usb->dev, "BULK In failed %d\n", urb->status);
183 break;
186 if (urb->actual_length) {
187 spin_lock_irqsave(&priv->lock, flags);
189 if (vnt_rx_data(priv, rcb, urb->actual_length)) {
190 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
191 if (!rcb->skb) {
192 dev_dbg(&priv->usb->dev,
193 "Failed to re-alloc rx skb\n");
195 rcb->in_use = false;
196 spin_unlock_irqrestore(&priv->lock, flags);
197 return;
199 } else {
200 skb_push(rcb->skb, skb_headroom(rcb->skb));
201 skb_trim(rcb->skb, 0);
204 urb->transfer_buffer = skb_put(rcb->skb,
205 skb_tailroom(rcb->skb));
207 spin_unlock_irqrestore(&priv->lock, flags);
210 if (usb_submit_urb(urb, GFP_ATOMIC)) {
211 dev_dbg(&priv->usb->dev, "Failed to re submit rx skb\n");
213 rcb->in_use = false;
217 int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb)
219 int status = 0;
220 struct urb *urb;
222 urb = rcb->urb;
223 if (rcb->skb == NULL) {
224 dev_dbg(&priv->usb->dev, "rcb->skb is null\n");
225 return status;
228 usb_fill_bulk_urb(urb,
229 priv->usb,
230 usb_rcvbulkpipe(priv->usb, 2),
231 skb_put(rcb->skb, skb_tailroom(rcb->skb)),
232 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
233 vnt_submit_rx_urb_complete,
234 rcb);
236 status = usb_submit_urb(urb, GFP_ATOMIC);
237 if (status != 0) {
238 dev_dbg(&priv->usb->dev, "Submit Rx URB failed %d\n", status);
239 return STATUS_FAILURE;
242 rcb->in_use = true;
244 return status;
247 static void vnt_tx_context_complete(struct urb *urb)
249 struct vnt_usb_send_context *context = urb->context;
250 struct vnt_private *priv = context->priv;
252 switch (urb->status) {
253 case 0:
254 dev_dbg(&priv->usb->dev, "Write %d bytes\n", context->buf_len);
255 break;
256 case -ECONNRESET:
257 case -ENOENT:
258 case -ESHUTDOWN:
259 context->in_use = false;
260 return;
261 case -ETIMEDOUT:
262 default:
263 dev_dbg(&priv->usb->dev, "BULK Out failed %d\n", urb->status);
264 break;
267 if (context->type == CONTEXT_DATA_PACKET)
268 ieee80211_wake_queues(priv->hw);
270 if (urb->status || context->type == CONTEXT_BEACON_PACKET) {
271 if (context->skb)
272 ieee80211_free_txskb(priv->hw, context->skb);
274 context->in_use = false;
278 int vnt_tx_context(struct vnt_private *priv,
279 struct vnt_usb_send_context *context)
281 int status;
282 struct urb *urb;
284 if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) {
285 context->in_use = false;
286 return STATUS_RESOURCES;
289 urb = context->urb;
291 usb_fill_bulk_urb(urb,
292 priv->usb,
293 usb_sndbulkpipe(priv->usb, 3),
294 context->data,
295 context->buf_len,
296 vnt_tx_context_complete,
297 context);
299 status = usb_submit_urb(urb, GFP_ATOMIC);
300 if (status != 0) {
301 dev_dbg(&priv->usb->dev, "Submit Tx URB failed %d\n", status);
303 context->in_use = false;
304 return STATUS_FAILURE;
307 return STATUS_PENDING;