blob: b707470143af9bb113293f9f9bc4c2f69c7b3322 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
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: usbpipe.c
21 *
22 * Purpose: Handle USB control endpoint
23 *
24 * Author: Warren Hsu
25 *
26 * Date: Mar. 29, 2005
27 *
28 * Functions:
29 * CONTROLnsRequestOut - Write variable length bytes to MEM/BB/MAC/EEPROM
30 * CONTROLnsRequestIn - Read variable length bytes from MEM/BB/MAC/EEPROM
31 * ControlvWriteByte - Write one byte to MEM/BB/MAC/EEPROM
32 * ControlvReadByte - Read one byte from MEM/BB/MAC/EEPROM
33 * ControlvMaskByte - Read one byte from MEM/BB/MAC/EEPROM and clear/set some bits in the same address
34 *
35 * Revision History:
36 * 04-05-2004 Jerry Chen: Initial release
37 * 11-24-2004 Warren Hsu: Add ControlvWriteByte,ControlvReadByte,ControlvMaskByte
38 *
39 */
40
Forest Bond92b96792009-06-13 07:38:31 -040041#include "int.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040043#include "dpc.h"
Forest Bond92b96792009-06-13 07:38:31 -040044#include "control.h"
Forest Bond92b96792009-06-13 07:38:31 -040045#include "desc.h"
Forest Bond92b96792009-06-13 07:38:31 -040046#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040047
Forest Bond92b96792009-06-13 07:38:31 -040048//endpoint def
49//endpoint 0: control
50//endpoint 1: interrupt
51//endpoint 2: read bulk
52//endpoint 3: write bulk
53
Forest Bond92b96792009-06-13 07:38:31 -040054//static int msglevel =MSG_LEVEL_DEBUG;
55static int msglevel =MSG_LEVEL_INFO;
56
Forest Bond92b96792009-06-13 07:38:31 -040057#define USB_CTL_WAIT 500 //ms
58
59#ifndef URB_ASYNC_UNLINK
60#define URB_ASYNC_UNLINK 0
61#endif
62
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +000063static void s_nsInterruptUsbIoCompleteRead(struct urb *urb);
64static void s_nsBulkInUsbIoCompleteRead(struct urb *urb);
65static void s_nsBulkOutIoCompleteWrite(struct urb *urb);
66static void s_nsControlInUsbIoCompleteRead(struct urb *urb);
67static void s_nsControlInUsbIoCompleteWrite(struct urb *urb);
Forest Bond92b96792009-06-13 07:38:31 -040068
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +000069int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest,
70 u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer)
Forest Bond92b96792009-06-13 07:38:31 -040071{
Andres More6487c492010-08-02 20:51:57 -030072 int ntStatus;
Forest Bond92b96792009-06-13 07:38:31 -040073
Andres More731047f2010-08-05 22:17:20 -030074 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -040075 return STATUS_FAILURE;
76
Andres More731047f2010-08-05 22:17:20 -030077 if (pDevice->Flags & fMP_CONTROL_WRITES)
Forest Bond92b96792009-06-13 07:38:31 -040078 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -040079
80 if (in_interrupt()) {
81 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"in_interrupt return ..byRequest %x\n", byRequest);
82 return STATUS_FAILURE;
83 }
84
Malcolm Priestleyc91b1862014-05-15 22:49:19 +010085 mutex_lock(&pDevice->usb_lock);
86
Forest Bond92b96792009-06-13 07:38:31 -040087 ntStatus = usb_control_msg(
88 pDevice->usb,
89 usb_sndctrlpipe(pDevice->usb , 0),
90 byRequest,
91 0x40, // RequestType
92 wValue,
93 wIndex,
Andres More8611a292010-05-01 14:25:00 -030094 (void *) pbyBuffer,
Forest Bond92b96792009-06-13 07:38:31 -040095 wLength,
96 HZ
97 );
98 if (ntStatus >= 0) {
99 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe ntStatus= %d\n", ntStatus);
100 ntStatus = 0;
101 } else {
102 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe fail, ntStatus= %d\n", ntStatus);
103 }
104
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100105 mutex_unlock(&pDevice->usb_lock);
106
Forest Bond92b96792009-06-13 07:38:31 -0400107 return ntStatus;
108}
109
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000110int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
111 u16 wIndex, u16 wLength, u8 *pbyBuffer)
Iulia Manda9009dd12014-03-13 01:35:40 +0200112 __releases(&pDevice->lock)
113 __acquires(&pDevice->lock)
Forest Bond92b96792009-06-13 07:38:31 -0400114{
Andres More6487c492010-08-02 20:51:57 -0300115 int ntStatus = 0;
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000116 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400117
Andres More731047f2010-08-05 22:17:20 -0300118 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -0400119 return STATUS_FAILURE;
120
Andres More731047f2010-08-05 22:17:20 -0300121 if (pDevice->Flags & fMP_CONTROL_WRITES)
Forest Bond92b96792009-06-13 07:38:31 -0400122 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000124 if (pDevice->Flags & fMP_CONTROL_READS)
125 return STATUS_FAILURE;
126
Malcolm Priestleye1feda12013-10-14 19:44:13 +0100127 if (pDevice->pControlURB->hcpriv)
128 return STATUS_FAILURE;
129
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100130 mutex_lock(&pDevice->usb_lock);
131
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000132 MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES);
133
Forest Bond92b96792009-06-13 07:38:31 -0400134 pDevice->sUsbCtlRequest.bRequestType = 0x40;
135 pDevice->sUsbCtlRequest.bRequest = byRequest;
136 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
137 pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex);
138 pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength);
139 pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK;
140 pDevice->pControlURB->actual_length = 0;
141 // Notice, pbyBuffer limited point to variable buffer, can't be constant.
142 usb_fill_control_urb(pDevice->pControlURB, pDevice->usb,
143 usb_sndctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest,
144 pbyBuffer, wLength, s_nsControlInUsbIoCompleteWrite, pDevice);
145
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700146 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
147 if (ntStatus != 0) {
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
149 "control send request submission failed: %d\n",
150 ntStatus);
151 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100152 mutex_unlock(&pDevice->usb_lock);
Forest Bond92b96792009-06-13 07:38:31 -0400153 return STATUS_FAILURE;
154 }
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000155
Forest Bond92b96792009-06-13 07:38:31 -0400156 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
Andres More731047f2010-08-05 22:17:20 -0300157
158 if (pDevice->Flags & fMP_CONTROL_WRITES)
159 mdelay(1);
Forest Bond92b96792009-06-13 07:38:31 -0400160 else
Andres More731047f2010-08-05 22:17:20 -0300161 break;
162
Forest Bond92b96792009-06-13 07:38:31 -0400163 if (ii >= USB_CTL_WAIT) {
Andres More731047f2010-08-05 22:17:20 -0300164 DBG_PRT(MSG_LEVEL_DEBUG,
165 KERN_INFO "control send request submission timeout\n");
Forest Bond92b96792009-06-13 07:38:31 -0400166 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100167 mutex_unlock(&pDevice->usb_lock);
Forest Bond92b96792009-06-13 07:38:31 -0400168 return STATUS_FAILURE;
169 }
170 }
Forest Bond92b96792009-06-13 07:38:31 -0400171
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100172 mutex_unlock(&pDevice->usb_lock);
173
Forest Bond92b96792009-06-13 07:38:31 -0400174 return STATUS_SUCCESS;
175}
176
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000177int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
178 u16 wIndex, u16 wLength, u8 *pbyBuffer)
Iulia Manda9009dd12014-03-13 01:35:40 +0200179 __releases(&pDevice->lock)
180 __acquires(&pDevice->lock)
Forest Bond92b96792009-06-13 07:38:31 -0400181{
Andres More6487c492010-08-02 20:51:57 -0300182 int ntStatus = 0;
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000183 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400184
Andres More731047f2010-08-05 22:17:20 -0300185 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -0400186 return STATUS_FAILURE;
187
Andres More731047f2010-08-05 22:17:20 -0300188 if (pDevice->Flags & fMP_CONTROL_READS)
189 return STATUS_FAILURE;
190
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000191 if (pDevice->Flags & fMP_CONTROL_WRITES)
192 return STATUS_FAILURE;
193
Malcolm Priestleye1feda12013-10-14 19:44:13 +0100194 if (pDevice->pControlURB->hcpriv)
195 return STATUS_FAILURE;
196
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100197 mutex_lock(&pDevice->usb_lock);
198
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000199 MP_SET_FLAG(pDevice, fMP_CONTROL_READS);
200
Forest Bond92b96792009-06-13 07:38:31 -0400201 pDevice->sUsbCtlRequest.bRequestType = 0xC0;
202 pDevice->sUsbCtlRequest.bRequest = byRequest;
203 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
204 pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex);
205 pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength);
206 pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK;
207 pDevice->pControlURB->actual_length = 0;
208 usb_fill_control_urb(pDevice->pControlURB, pDevice->usb,
209 usb_rcvctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest,
210 pbyBuffer, wLength, s_nsControlInUsbIoCompleteRead, pDevice);
211
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700212 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
213 if (ntStatus != 0) {
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
215 "control request submission failed: %d\n", ntStatus);
216 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100217 mutex_unlock(&pDevice->usb_lock);
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000218 return STATUS_FAILURE;
219 }
Forest Bond92b96792009-06-13 07:38:31 -0400220
Forest Bond92b96792009-06-13 07:38:31 -0400221 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
Andres More731047f2010-08-05 22:17:20 -0300222
223 if (pDevice->Flags & fMP_CONTROL_READS)
224 mdelay(1);
225 else
226 break;
227
228 if (ii >= USB_CTL_WAIT) {
229 DBG_PRT(MSG_LEVEL_DEBUG,
230 KERN_INFO "control rcv request submission timeout\n");
Forest Bond92b96792009-06-13 07:38:31 -0400231 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100232 mutex_unlock(&pDevice->usb_lock);
Forest Bond92b96792009-06-13 07:38:31 -0400233 return STATUS_FAILURE;
234 }
235 }
Forest Bond92b96792009-06-13 07:38:31 -0400236
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100237 mutex_unlock(&pDevice->usb_lock);
238
Forest Bond92b96792009-06-13 07:38:31 -0400239 return ntStatus;
240}
241
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000242static void s_nsControlInUsbIoCompleteWrite(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400243{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000244 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
Forest Bond92b96792009-06-13 07:38:31 -0400245
246 pDevice = urb->context;
247 switch (urb->status) {
248 case 0:
249 break;
250 case -EINPROGRESS:
251 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status EINPROGRESS%d\n", urb->status);
252 break;
253 case -ENOENT:
254 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status ENOENT %d\n", urb->status);
255 break;
256 default:
257 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status %d\n", urb->status);
258 }
259
260 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
261}
262
Forest Bond92b96792009-06-13 07:38:31 -0400263/*
264 * Description:
265 * Complete function of usb Control callback
266 *
267 * Parameters:
268 * In:
269 * pDevice - Pointer to the adapter
270 *
271 * Out:
272 * none
273 *
274 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
275 *
276 */
Forest Bond92b96792009-06-13 07:38:31 -0400277
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000278static void s_nsControlInUsbIoCompleteRead(struct urb *urb)
279{
280 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
281
Forest Bond92b96792009-06-13 07:38:31 -0400282 switch (urb->status) {
283 case 0:
284 break;
285 case -EINPROGRESS:
286 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status EINPROGRESS%d\n", urb->status);
287 break;
288 case -ENOENT:
289 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status = ENOENT %d\n", urb->status);
290 break;
291 default:
292 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status %d\n", urb->status);
293 }
294
295 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
296}
297
Forest Bond92b96792009-06-13 07:38:31 -0400298/*
299 * Description:
300 * Allocates an usb interrupt in irp and calls USBD.
301 *
302 * Parameters:
303 * In:
304 * pDevice - Pointer to the adapter
305 * Out:
306 * none
307 *
308 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
309 *
310 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000311
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000312int PIPEnsInterruptRead(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400313{
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000314 int status = STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400315
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
317 "---->s_nsStartInterruptUsbRead()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400318
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000319 if (priv->int_buf.in_use == true)
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000320 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400321
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000322 priv->int_buf.in_use = true;
Forest Bond92b96792009-06-13 07:38:31 -0400323
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000324 usb_fill_int_urb(priv->pInterruptURB,
325 priv->usb,
Malcolm Priestleyb9d93d12014-03-16 12:34:11 +0000326 usb_rcvintpipe(priv->usb, 1),
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000327 priv->int_buf.data_buf,
Forest Bond92b96792009-06-13 07:38:31 -0400328 MAX_INTERRUPT_SIZE,
329 s_nsInterruptUsbIoCompleteRead,
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000330 priv,
331 priv->int_interval);
Forest Bond92b96792009-06-13 07:38:31 -0400332
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000333 status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC);
334 if (status) {
Malcolm Priestley59858f52014-02-19 18:36:37 +0000335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000336 "Submit int URB failed %d\n", status);
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000337 priv->int_buf.in_use = false;
Malcolm Priestley59858f52014-02-19 18:36:37 +0000338 }
Forest Bond92b96792009-06-13 07:38:31 -0400339
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000340 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
341 "<----s_nsStartInterruptUsbRead Return(%x)\n", status);
342
343 return status;
Forest Bond92b96792009-06-13 07:38:31 -0400344}
345
Forest Bond92b96792009-06-13 07:38:31 -0400346/*
347 * Description:
348 * Complete function of usb interrupt in irp.
349 *
350 * Parameters:
351 * In:
352 * pDevice - Pointer to the adapter
353 *
354 * Out:
355 * none
356 *
357 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
358 *
359 */
Forest Bond92b96792009-06-13 07:38:31 -0400360
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000361static void s_nsInterruptUsbIoCompleteRead(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400362{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000363 struct vnt_private *priv = urb->context;
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000364 int status;
Forest Bond92b96792009-06-13 07:38:31 -0400365
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000366 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
367 "---->s_nsInterruptUsbIoCompleteRead\n");
Forest Bond92b96792009-06-13 07:38:31 -0400368
Malcolm Priestleyc98fbf92014-02-17 21:16:20 +0000369 switch (urb->status) {
370 case 0:
371 case -ETIMEDOUT:
372 break;
373 case -ECONNRESET:
374 case -ENOENT:
375 case -ESHUTDOWN:
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000376 priv->int_buf.in_use = false;
Malcolm Priestleyc98fbf92014-02-17 21:16:20 +0000377 return;
378 default:
379 break;
380 }
381
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000382 status = urb->status;
Forest Bond92b96792009-06-13 07:38:31 -0400383
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
385 "s_nsInterruptUsbIoCompleteRead Status %d\n", status);
Forest Bond92b96792009-06-13 07:38:31 -0400386
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000387 if (status != STATUS_SUCCESS) {
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000388 priv->int_buf.in_use = false;
Forest Bond92b96792009-06-13 07:38:31 -0400389
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000391 "IntUSBIoCompleteControl STATUS = %d\n", status);
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000392 } else {
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000393 INTnsProcessData(priv);
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000394 }
Malcolm Priestley749627f2014-02-17 21:24:33 +0000395
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000396 status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC);
397 if (status) {
398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
399 "Submit int URB failed %d\n", status);
400 } else {
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000401 priv->int_buf.in_use = true;
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000402 }
403
404 return;
Forest Bond92b96792009-06-13 07:38:31 -0400405}
406
407/*
408 * Description:
409 * Allocates an usb BulkIn irp and calls USBD.
410 *
411 * Parameters:
412 * In:
413 * pDevice - Pointer to the adapter
414 * Out:
415 * none
416 *
417 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
418 *
419 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000420
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000421int PIPEnsBulkInUsbRead(struct vnt_private *priv, struct vnt_rcb *rcb)
Forest Bond92b96792009-06-13 07:38:31 -0400422{
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000423 int status = 0;
424 struct urb *urb;
Forest Bond92b96792009-06-13 07:38:31 -0400425
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000426 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
Forest Bond92b96792009-06-13 07:38:31 -0400427
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000428 if (priv->Flags & fMP_DISCONNECTED)
429 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400430
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000431 urb = rcb->pUrb;
432 if (rcb->skb == NULL) {
433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rcb->skb is null\n");
434 return status;
435 }
Forest Bond92b96792009-06-13 07:38:31 -0400436
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000437 usb_fill_bulk_urb(urb,
438 priv->usb,
439 usb_rcvbulkpipe(priv->usb, 2),
440 (void *) (rcb->skb->data),
Forest Bond92b96792009-06-13 07:38:31 -0400441 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
442 s_nsBulkInUsbIoCompleteRead,
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000443 rcb);
Forest Bond92b96792009-06-13 07:38:31 -0400444
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000445 status = usb_submit_urb(urb, GFP_ATOMIC);
446 if (status != 0) {
447 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
448 "Submit Rx URB failed %d\n", status);
Forest Bond92b96792009-06-13 07:38:31 -0400449 return STATUS_FAILURE ;
450 }
Forest Bond92b96792009-06-13 07:38:31 -0400451
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000452 rcb->Ref = 1;
453 rcb->bBoolInUse = true;
454
455 return status;
Forest Bond92b96792009-06-13 07:38:31 -0400456}
457
Forest Bond92b96792009-06-13 07:38:31 -0400458/*
459 * Description:
460 * Complete function of usb BulkIn irp.
461 *
462 * Parameters:
463 * In:
464 * pDevice - Pointer to the adapter
465 *
466 * Out:
467 * none
468 *
469 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
470 *
471 */
Forest Bond92b96792009-06-13 07:38:31 -0400472
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000473static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400474{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000475 struct vnt_rcb *rcb = urb->context;
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000476 struct vnt_private *priv = rcb->pDevice;
Malcolm Priestley29b02372014-05-15 22:49:20 +0100477 unsigned long flags;
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000478 int re_alloc_skb = false;
Forest Bond92b96792009-06-13 07:38:31 -0400479
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000480 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
Malcolm Priestleye3a8fa12014-02-25 20:51:46 +0000481
Malcolm Priestley67638982014-02-25 20:51:48 +0000482 switch (urb->status) {
483 case 0:
Malcolm Priestley67638982014-02-25 20:51:48 +0000484 break;
485 case -ECONNRESET:
486 case -ENOENT:
487 case -ESHUTDOWN:
488 return;
489 case -ETIMEDOUT:
490 default:
Malcolm Priestley67638982014-02-25 20:51:48 +0000491 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
492 "BULK In failed %d\n", urb->status);
493 break;
494 }
Forest Bond92b96792009-06-13 07:38:31 -0400495
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000496 if (urb->actual_length) {
Malcolm Priestley29b02372014-05-15 22:49:20 +0100497 spin_lock_irqsave(&priv->lock, flags);
Forest Bond92b96792009-06-13 07:38:31 -0400498
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000499 if (RXbBulkInProcessData(priv, rcb, urb->actual_length) == true)
500 re_alloc_skb = true;
501
Malcolm Priestley29b02372014-05-15 22:49:20 +0100502 spin_unlock_irqrestore(&priv->lock, flags);
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000503 }
504
505 rcb->Ref--;
506 if (rcb->Ref == 0) {
507 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d\n",
508 priv->NumRecvFreeList);
Malcolm Priestley29b02372014-05-15 22:49:20 +0100509 spin_lock_irqsave(&priv->lock, flags);
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000510
511 RXvFreeRCB(rcb, re_alloc_skb);
512
Malcolm Priestley29b02372014-05-15 22:49:20 +0100513 spin_unlock_irqrestore(&priv->lock, flags);
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000514 }
515
516 return;
Forest Bond92b96792009-06-13 07:38:31 -0400517}
518
519/*
520 * Description:
521 * Allocates an usb BulkOut irp and calls USBD.
522 *
523 * Parameters:
524 * In:
525 * pDevice - Pointer to the adapter
526 * Out:
527 * none
528 *
529 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
530 *
531 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000532
Malcolm Priestley3f382902014-02-25 20:51:45 +0000533int PIPEnsSendBulkOut(struct vnt_private *priv,
534 struct vnt_usb_send_context *context)
Forest Bond92b96792009-06-13 07:38:31 -0400535{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000536 int status;
Malcolm Priestley3f382902014-02-25 20:51:45 +0000537 struct urb *urb;
Forest Bond92b96792009-06-13 07:38:31 -0400538
Malcolm Priestley3f382902014-02-25 20:51:45 +0000539 priv->bPWBitOn = false;
Forest Bond92b96792009-06-13 07:38:31 -0400540
Malcolm Priestley3f382902014-02-25 20:51:45 +0000541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n");
Forest Bond92b96792009-06-13 07:38:31 -0400542
Malcolm Priestley3f382902014-02-25 20:51:45 +0000543 if (!(MP_IS_READY(priv) && priv->Flags & fMP_POST_WRITES)) {
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100544 context->in_use = false;
Malcolm Priestley13338302014-02-25 20:51:43 +0000545 return STATUS_RESOURCES;
546 }
Forest Bond92b96792009-06-13 07:38:31 -0400547
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100548 urb = context->urb;
Forest Bond92b96792009-06-13 07:38:31 -0400549
Malcolm Priestley3f382902014-02-25 20:51:45 +0000550 usb_fill_bulk_urb(urb,
551 priv->usb,
552 usb_sndbulkpipe(priv->usb, 3),
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100553 context->data,
554 context->buf_len,
Malcolm Priestley3f382902014-02-25 20:51:45 +0000555 s_nsBulkOutIoCompleteWrite,
556 context);
557
558 status = usb_submit_urb(urb, GFP_ATOMIC);
559 if (status != 0) {
560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
561 "Submit Tx URB failed %d\n", status);
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100562 context->in_use = false;
Malcolm Priestley3f382902014-02-25 20:51:45 +0000563 return STATUS_FAILURE;
564 }
565
566 return STATUS_PENDING;
Forest Bond92b96792009-06-13 07:38:31 -0400567}
568
569/*
570 * Description: s_nsBulkOutIoCompleteWrite
571 * 1a) Indicate to the protocol the status of the write.
572 * 1b) Return ownership of the packet to the protocol.
573 *
574 * 2) If any more packets are queue for sending, send another packet
575 * to USBD.
576 * If the attempt to send the packet to the driver fails,
577 * return ownership of the packet to the protocol and
578 * try another packet (until one succeeds).
579 *
580 * Parameters:
581 * In:
582 * pdoUsbDevObj - pointer to the USB device object which
583 * completed the irp
584 * pIrp - the irp which was completed by the
585 * device object
586 * pContext - the context given to IoSetCompletionRoutine
587 * before calling IoCallDriver on the irp
588 * The pContext is a pointer to the USB device object.
589 * Out:
590 * none
591 *
592 * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine
593 * (IofCompleteRequest) to stop working on the irp.
594 *
595 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000596
597static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400598{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000599 struct vnt_usb_send_context *context = urb->context;
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100600 struct vnt_private *priv = context->priv;
Malcolm Priestley1450ba62014-02-19 21:56:33 +0000601 u8 context_type = context->type;
Forest Bond92b96792009-06-13 07:38:31 -0400602
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000603 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
Forest Bond92b96792009-06-13 07:38:31 -0400604
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000605 switch (urb->status) {
606 case 0:
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000607 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100608 "Write %d bytes\n", context->buf_len);
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000609 break;
610 case -ECONNRESET:
611 case -ENOENT:
612 case -ESHUTDOWN:
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100613 context->in_use = false;
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000614 return;
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000615 case -ETIMEDOUT:
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000616 default:
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000617 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
618 "BULK Out failed %d\n", urb->status);
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000619 break;
620 }
621
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000622 if (!netif_device_present(priv->dev))
623 return;
Forest Bond92b96792009-06-13 07:38:31 -0400624
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000625 if (CONTEXT_DATA_PACKET == context_type) {
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100626 if (context->skb != NULL) {
627 dev_kfree_skb_irq(context->skb);
628 context->skb = NULL;
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000629 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100630 "tx %d bytes\n", context->buf_len);
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000631 }
Forest Bond92b96792009-06-13 07:38:31 -0400632
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000633 priv->dev->trans_start = jiffies;
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000634 }
Forest Bond92b96792009-06-13 07:38:31 -0400635
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000636 if (priv->bLinkPass == true) {
637 if (netif_queue_stopped(priv->dev))
638 netif_wake_queue(priv->dev);
639 }
640
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100641 context->in_use = false;
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000642
643 return;
Forest Bond92b96792009-06-13 07:38:31 -0400644}