]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/vt6656/usbpipe.c
staging: vt6656: s_nsBulkOutIoCompleteWrite reorganise variable order.
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / vt6656 / usbpipe.c
CommitLineData
92b96797
FB
1/*
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
92b96797 41#include "int.h"
92b96797 42#include "rxtx.h"
92b96797 43#include "dpc.h"
92b96797 44#include "control.h"
92b96797 45#include "desc.h"
92b96797 46#include "device.h"
92b96797 47
92b96797
FB
48//endpoint def
49//endpoint 0: control
50//endpoint 1: interrupt
51//endpoint 2: read bulk
52//endpoint 3: write bulk
53
92b96797
FB
54//static int msglevel =MSG_LEVEL_DEBUG;
55static int msglevel =MSG_LEVEL_INFO;
56
92b96797
FB
57#define USB_CTL_WAIT 500 //ms
58
59#ifndef URB_ASYNC_UNLINK
60#define URB_ASYNC_UNLINK 0
61#endif
62
fe5d00eb
MP
63static 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);
92b96797 68
fe5d00eb
MP
69int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest,
70 u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer)
92b96797 71{
6487c49e 72 int ntStatus;
92b96797 73
731047f9 74 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
75 return STATUS_FAILURE;
76
731047f9 77 if (pDevice->Flags & fMP_CONTROL_WRITES)
92b96797 78 return STATUS_FAILURE;
92b96797
FB
79
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
85 ntStatus = usb_control_msg(
86 pDevice->usb,
87 usb_sndctrlpipe(pDevice->usb , 0),
88 byRequest,
89 0x40, // RequestType
90 wValue,
91 wIndex,
8611a29a 92 (void *) pbyBuffer,
92b96797
FB
93 wLength,
94 HZ
95 );
96 if (ntStatus >= 0) {
97 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe ntStatus= %d\n", ntStatus);
98 ntStatus = 0;
99 } else {
100 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe fail, ntStatus= %d\n", ntStatus);
101 }
102
103 return ntStatus;
104}
105
fe5d00eb
MP
106int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
107 u16 wIndex, u16 wLength, u8 *pbyBuffer)
92b96797 108{
6487c49e 109 int ntStatus = 0;
fe5d00eb 110 int ii;
92b96797 111
731047f9 112 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
113 return STATUS_FAILURE;
114
731047f9 115 if (pDevice->Flags & fMP_CONTROL_WRITES)
92b96797 116 return STATUS_FAILURE;
92b96797 117
ae5943de
MP
118 if (pDevice->Flags & fMP_CONTROL_READS)
119 return STATUS_FAILURE;
120
e1feda13
MP
121 if (pDevice->pControlURB->hcpriv)
122 return STATUS_FAILURE;
123
ae5943de
MP
124 MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES);
125
92b96797
FB
126 pDevice->sUsbCtlRequest.bRequestType = 0x40;
127 pDevice->sUsbCtlRequest.bRequest = byRequest;
128 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
129 pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex);
130 pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength);
131 pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK;
132 pDevice->pControlURB->actual_length = 0;
133 // Notice, pbyBuffer limited point to variable buffer, can't be constant.
134 usb_fill_control_urb(pDevice->pControlURB, pDevice->usb,
135 usb_sndctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest,
136 pbyBuffer, wLength, s_nsControlInUsbIoCompleteWrite, pDevice);
137
bfbfeecc
JP
138 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
139 if (ntStatus != 0) {
ae5943de
MP
140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
141 "control send request submission failed: %d\n",
142 ntStatus);
143 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
92b96797
FB
144 return STATUS_FAILURE;
145 }
ae5943de 146
92b96797
FB
147 spin_unlock_irq(&pDevice->lock);
148 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
731047f9
AM
149
150 if (pDevice->Flags & fMP_CONTROL_WRITES)
151 mdelay(1);
92b96797 152 else
731047f9
AM
153 break;
154
92b96797 155 if (ii >= USB_CTL_WAIT) {
731047f9
AM
156 DBG_PRT(MSG_LEVEL_DEBUG,
157 KERN_INFO "control send request submission timeout\n");
92b96797
FB
158 spin_lock_irq(&pDevice->lock);
159 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
160 return STATUS_FAILURE;
161 }
162 }
163 spin_lock_irq(&pDevice->lock);
164
165 return STATUS_SUCCESS;
166}
167
fe5d00eb
MP
168int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
169 u16 wIndex, u16 wLength, u8 *pbyBuffer)
92b96797 170{
6487c49e 171 int ntStatus = 0;
fe5d00eb 172 int ii;
92b96797 173
731047f9 174 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
175 return STATUS_FAILURE;
176
731047f9
AM
177 if (pDevice->Flags & fMP_CONTROL_READS)
178 return STATUS_FAILURE;
179
ae5943de
MP
180 if (pDevice->Flags & fMP_CONTROL_WRITES)
181 return STATUS_FAILURE;
e1feda13
MP
182
183 if (pDevice->pControlURB->hcpriv)
184 return STATUS_FAILURE;
ae5943de
MP
185
186 MP_SET_FLAG(pDevice, fMP_CONTROL_READS);
187
92b96797
FB
188 pDevice->sUsbCtlRequest.bRequestType = 0xC0;
189 pDevice->sUsbCtlRequest.bRequest = byRequest;
190 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
191 pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex);
192 pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength);
193 pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK;
194 pDevice->pControlURB->actual_length = 0;
195 usb_fill_control_urb(pDevice->pControlURB, pDevice->usb,
196 usb_rcvctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest,
197 pbyBuffer, wLength, s_nsControlInUsbIoCompleteRead, pDevice);
198
bfbfeecc
JP
199 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
200 if (ntStatus != 0) {
ae5943de
MP
201 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
202 "control request submission failed: %d\n", ntStatus);
203 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
204 return STATUS_FAILURE;
205 }
92b96797
FB
206
207 spin_unlock_irq(&pDevice->lock);
208 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
731047f9
AM
209
210 if (pDevice->Flags & fMP_CONTROL_READS)
211 mdelay(1);
212 else
213 break;
214
215 if (ii >= USB_CTL_WAIT) {
216 DBG_PRT(MSG_LEVEL_DEBUG,
217 KERN_INFO "control rcv request submission timeout\n");
92b96797
FB
218 spin_lock_irq(&pDevice->lock);
219 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
220 return STATUS_FAILURE;
221 }
222 }
223 spin_lock_irq(&pDevice->lock);
224
225 return ntStatus;
226}
227
fe5d00eb 228static void s_nsControlInUsbIoCompleteWrite(struct urb *urb)
92b96797 229{
fe5d00eb 230 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
92b96797
FB
231
232 pDevice = urb->context;
233 switch (urb->status) {
234 case 0:
235 break;
236 case -EINPROGRESS:
237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status EINPROGRESS%d\n", urb->status);
238 break;
239 case -ENOENT:
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status ENOENT %d\n", urb->status);
241 break;
242 default:
243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status %d\n", urb->status);
244 }
245
246 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
247}
248
92b96797
FB
249/*
250 * Description:
251 * Complete function of usb Control callback
252 *
253 * Parameters:
254 * In:
255 * pDevice - Pointer to the adapter
256 *
257 * Out:
258 * none
259 *
260 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
261 *
262 */
fe5d00eb
MP
263
264static void s_nsControlInUsbIoCompleteRead(struct urb *urb)
92b96797 265{
fe5d00eb 266 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
92b96797 267
92b96797
FB
268 switch (urb->status) {
269 case 0:
270 break;
271 case -EINPROGRESS:
272 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status EINPROGRESS%d\n", urb->status);
273 break;
274 case -ENOENT:
275 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status = ENOENT %d\n", urb->status);
276 break;
277 default:
278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status %d\n", urb->status);
279 }
280
281 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
282}
283
92b96797
FB
284/*
285 * Description:
286 * Allocates an usb interrupt in irp and calls USBD.
287 *
288 * Parameters:
289 * In:
290 * pDevice - Pointer to the adapter
291 * Out:
292 * none
293 *
294 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
295 *
296 */
fe5d00eb 297
5f38b783 298int PIPEnsInterruptRead(struct vnt_private *priv)
92b96797 299{
5f38b783 300 int status = STATUS_FAILURE;
92b96797 301
5f38b783
MP
302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
303 "---->s_nsStartInterruptUsbRead()\n");
92b96797 304
f764e00d 305 if (priv->int_buf.in_use == true)
5f38b783
MP
306 return STATUS_FAILURE;
307
f764e00d 308 priv->int_buf.in_use = true;
5f38b783
MP
309 priv->ulIntInPosted++;
310
311 usb_fill_int_urb(priv->pInterruptURB,
312 priv->usb,
313 usb_rcvbulkpipe(priv->usb, 1),
f764e00d 314 priv->int_buf.data_buf,
92b96797
FB
315 MAX_INTERRUPT_SIZE,
316 s_nsInterruptUsbIoCompleteRead,
5f38b783
MP
317 priv,
318 priv->int_interval);
92b96797 319
5f38b783
MP
320 status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC);
321 if (status) {
59858f5e 322 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
5f38b783 323 "Submit int URB failed %d\n", status);
f764e00d 324 priv->int_buf.in_use = false;
59858f5e 325 }
92b96797 326
5f38b783
MP
327 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
328 "<----s_nsStartInterruptUsbRead Return(%x)\n", status);
329
330 return status;
92b96797
FB
331}
332
92b96797
FB
333/*
334 * Description:
335 * Complete function of usb interrupt in irp.
336 *
337 * Parameters:
338 * In:
339 * pDevice - Pointer to the adapter
340 *
341 * Out:
342 * none
343 *
344 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
345 *
346 */
92b96797 347
fe5d00eb 348static void s_nsInterruptUsbIoCompleteRead(struct urb *urb)
92b96797 349{
d9ad7a98
MP
350 struct vnt_private *priv = (struct vnt_private *)urb->context;
351 int status;
92b96797 352
d9ad7a98
MP
353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
354 "---->s_nsInterruptUsbIoCompleteRead\n");
92b96797 355
c98fbf90
MP
356 switch (urb->status) {
357 case 0:
358 case -ETIMEDOUT:
359 break;
360 case -ECONNRESET:
361 case -ENOENT:
362 case -ESHUTDOWN:
f764e00d 363 priv->int_buf.in_use = false;
c98fbf90
MP
364 return;
365 default:
366 break;
367 }
368
d9ad7a98 369 status = urb->status;
92b96797 370
d9ad7a98
MP
371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
372 "s_nsInterruptUsbIoCompleteRead Status %d\n", status);
92b96797 373
d9ad7a98
MP
374 if (status != STATUS_SUCCESS) {
375 priv->ulBulkInError++;
f764e00d 376 priv->int_buf.in_use = false;
92b96797 377
d9ad7a98
MP
378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
379 "IntUSBIoCompleteControl STATUS = %d\n", status);
380 } else {
381 priv->ulIntInBytesRead += (unsigned long)urb->actual_length;
382 priv->ulIntInContCRCError = 0;
383 priv->bEventAvailable = true;
384 INTnsProcessData(priv);
385 }
92b96797 386
d9ad7a98
MP
387 status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC);
388 if (status) {
247b4b68 389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
d9ad7a98 390 "Submit int URB failed %d\n", status);
247b4b68 391 } else {
f764e00d 392 priv->int_buf.in_use = true;
247b4b68 393 }
749627f2 394
d9ad7a98 395 return;
92b96797
FB
396}
397
398/*
399 * Description:
400 * Allocates an usb BulkIn irp and calls USBD.
401 *
402 * Parameters:
403 * In:
404 * pDevice - Pointer to the adapter
405 * Out:
406 * none
407 *
408 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
409 *
410 */
fe5d00eb 411
115cac2e 412int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, struct vnt_rcb *pRCB)
92b96797 413{
6487c49e 414 int ntStatus = 0;
fe5d00eb 415 struct urb *pUrb;
92b96797 416
92b96797
FB
417 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
418
731047f9 419 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
420 return STATUS_FAILURE;
421
422 pDevice->ulBulkInPosted++;
423
92b96797
FB
424 pUrb = pRCB->pUrb;
425 //
426 // Now that we have created the urb, we will send a
427 // request to the USB device object.
428 //
429 if (pRCB->skb == NULL) {
430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pRCB->skb is null \n");
431 return ntStatus;
432 }
433
434 usb_fill_bulk_urb(pUrb,
435 pDevice->usb,
436 usb_rcvbulkpipe(pDevice->usb, 2),
8611a29a 437 (void *) (pRCB->skb->data),
92b96797
FB
438 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
439 s_nsBulkInUsbIoCompleteRead,
440 pRCB);
441
bfbfeecc
JP
442 ntStatus = usb_submit_urb(pUrb, GFP_ATOMIC);
443 if (ntStatus != 0) {
92b96797
FB
444 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Rx URB failed %d\n", ntStatus);
445 return STATUS_FAILURE ;
446 }
447 pRCB->Ref = 1;
4e9b5e2b 448 pRCB->bBoolInUse= true;
92b96797
FB
449
450 return ntStatus;
451}
452
92b96797
FB
453/*
454 * Description:
455 * Complete function of usb BulkIn irp.
456 *
457 * Parameters:
458 * In:
459 * pDevice - Pointer to the adapter
460 *
461 * Out:
462 * none
463 *
464 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
465 *
466 */
92b96797 467
fe5d00eb 468static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
92b96797 469{
115cac2e 470 struct vnt_rcb *pRCB = (struct vnt_rcb *)urb->context;
fe5d00eb
MP
471 struct vnt_private *pDevice = pRCB->pDevice;
472 unsigned long bytesRead;
e269fc2d
AM
473 int bIndicateReceive = false;
474 int bReAllocSkb = false;
fe5d00eb 475 int status;
92b96797
FB
476
477 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
478 status = urb->status;
479 bytesRead = urb->actual_length;
480
481 if (status) {
482 pDevice->ulBulkInError++;
483 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK In failed %d\n", status);
92b96797
FB
484//todo...xxxxxx
485// if (status == USBD_STATUS_CRC) {
486// pDevice->ulBulkInContCRCError++;
487// }
488// if (status == STATUS_DEVICE_NOT_CONNECTED )
489// {
490// MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
491// }
492 } else {
87c62985 493 if (bytesRead)
4e9b5e2b 494 bIndicateReceive = true;
92b96797
FB
495 pDevice->ulBulkInContCRCError = 0;
496 pDevice->ulBulkInBytesRead += bytesRead;
92b96797
FB
497 }
498
92b96797
FB
499 if (bIndicateReceive) {
500 spin_lock(&pDevice->lock);
4e9b5e2b
AM
501 if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == true)
502 bReAllocSkb = true;
92b96797
FB
503 spin_unlock(&pDevice->lock);
504 }
505 pRCB->Ref--;
506 if (pRCB->Ref == 0)
507 {
508 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d \n",pDevice->NumRecvFreeList);
509 spin_lock(&pDevice->lock);
510 RXvFreeRCB(pRCB, bReAllocSkb);
511 spin_unlock(&pDevice->lock);
512 }
513
92b96797
FB
514 return;
515}
516
517/*
518 * Description:
519 * Allocates an usb BulkOut irp and calls USBD.
520 *
521 * Parameters:
522 * In:
523 * pDevice - Pointer to the adapter
524 * Out:
525 * none
526 *
527 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
528 *
529 */
fe5d00eb 530
dcdf1d03
MP
531int PIPEnsSendBulkOut(struct vnt_private *pDevice,
532 struct vnt_usb_send_context *pContext)
92b96797 533{
fe5d00eb
MP
534 int status;
535 struct urb *pUrb;
92b96797 536
e269fc2d 537 pDevice->bPWBitOn = false;
92b96797
FB
538
539/*
540 if (pDevice->pPendingBulkOutContext != NULL) {
541 pDevice->NumContextsQueued++;
542 EnqueueContext(pDevice->FirstTxContextQueue, pDevice->LastTxContextQueue, pContext);
543 status = STATUS_PENDING;
544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send pending!\n");
545 return status;
546 }
547*/
548
549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n");
550
731047f9 551 if (MP_IS_READY(pDevice) && (pDevice->Flags & fMP_POST_WRITES)) {
92b96797
FB
552
553 pUrb = pContext->pUrb;
554 pDevice->ulBulkOutPosted++;
555// pDevice->pPendingBulkOutContext = pContext;
556 usb_fill_bulk_urb(
557 pUrb,
558 pDevice->usb,
8611a29a
AM
559 usb_sndbulkpipe(pDevice->usb, 3),
560 (void *) &(pContext->Data[0]),
92b96797
FB
561 pContext->uBufLen,
562 s_nsBulkOutIoCompleteWrite,
563 pContext);
564
bfbfeecc
JP
565 status = usb_submit_urb(pUrb, GFP_ATOMIC);
566 if (status != 0)
92b96797
FB
567 {
568 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Tx URB failed %d\n", status);
e269fc2d 569 pContext->bBoolInUse = false;
92b96797
FB
570 return STATUS_FAILURE;
571 }
572 return STATUS_PENDING;
573 }
574 else {
e269fc2d 575 pContext->bBoolInUse = false;
92b96797
FB
576 return STATUS_RESOURCES;
577 }
578}
579
580/*
581 * Description: s_nsBulkOutIoCompleteWrite
582 * 1a) Indicate to the protocol the status of the write.
583 * 1b) Return ownership of the packet to the protocol.
584 *
585 * 2) If any more packets are queue for sending, send another packet
586 * to USBD.
587 * If the attempt to send the packet to the driver fails,
588 * return ownership of the packet to the protocol and
589 * try another packet (until one succeeds).
590 *
591 * Parameters:
592 * In:
593 * pdoUsbDevObj - pointer to the USB device object which
594 * completed the irp
595 * pIrp - the irp which was completed by the
596 * device object
597 * pContext - the context given to IoSetCompletionRoutine
598 * before calling IoCallDriver on the irp
599 * The pContext is a pointer to the USB device object.
600 * Out:
601 * none
602 *
603 * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine
604 * (IofCompleteRequest) to stop working on the irp.
605 *
606 */
fe5d00eb
MP
607
608static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
92b96797 609{
1c398a38
MP
610 struct vnt_usb_send_context *pContext =
611 (struct vnt_usb_send_context *)urb->context;
612 struct vnt_private *pDevice = pContext->pDevice;
613 CONTEXT_TYPE ContextType = pContext->Type;
614 unsigned long ulBufLen = pContext->uBufLen;
fe5d00eb 615 int status;
92b96797 616
92b96797 617 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
92b96797
FB
618
619 if (!netif_device_present(pDevice->dev))
620 return;
621
622 //
623 // Perform various IRP, URB, and buffer 'sanity checks'
624 //
625
626 status = urb->status;
92b96797
FB
627
628 if(status == STATUS_SUCCESS) {
629 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Write %d bytes\n",(int)ulBufLen);
630 pDevice->ulBulkOutBytesWrite += ulBufLen;
631 pDevice->ulBulkOutContCRCError = 0;
92b96797
FB
632 } else {
633 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK Out failed %d\n", status);
634 pDevice->ulBulkOutError++;
635 }
636
637// pDevice->ulCheckForHangCount = 0;
638// pDevice->pPendingBulkOutContext = NULL;
639
640 if ( CONTEXT_DATA_PACKET == ContextType ) {
641 // Indicate to the protocol the status of the sent packet and return
642 // ownership of the packet.
643 if (pContext->pPacket != NULL) {
644 dev_kfree_skb_irq(pContext->pPacket);
645 pContext->pPacket = NULL;
646 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"tx %d bytes\n",(int)ulBufLen);
647 }
648
649 pDevice->dev->trans_start = jiffies;
650
92b96797
FB
651 if (status == STATUS_SUCCESS) {
652 pDevice->packetsSent++;
653 }
654 else {
655 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send USB error! [%08xh]\n", status);
656 pDevice->packetsSentDropped++;
657 }
658
659 }
4e9b5e2b 660 if (pDevice->bLinkPass == true) {
92b96797
FB
661 if (netif_queue_stopped(pDevice->dev))
662 netif_wake_queue(pDevice->dev);
663 }
e269fc2d 664 pContext->bBoolInUse = false;
92b96797
FB
665
666 return;
667}