sched: run_posix_cpu_timers: Don't check ->exit_state, use lock_task_sighand()
[linux-2.6.git] / drivers / staging / vt6656 / usbpipe.c
blobfd2355e34fb015cdc252a69f3aa9ec76c0e85b72
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 * 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
35 * Revision History:
36 * 04-05-2004 Jerry Chen: Initial release
37 * 11-24-2004 Warren Hsu: Add ControlvWriteByte,ControlvReadByte,ControlvMaskByte
41 #include "int.h"
42 #include "rxtx.h"
43 #include "dpc.h"
44 #include "control.h"
45 #include "desc.h"
46 #include "device.h"
48 /*--------------------- Static Definitions -------------------------*/
49 //endpoint def
50 //endpoint 0: control
51 //endpoint 1: interrupt
52 //endpoint 2: read bulk
53 //endpoint 3: write bulk
55 //RequestType:
56 //#define REQUEST_OUT (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE) // 0x40
57 //#define REQUEST_IN (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE ) //0xc0
58 //static int msglevel =MSG_LEVEL_DEBUG;
59 static int msglevel =MSG_LEVEL_INFO;
62 #define USB_CTL_WAIT 500 //ms
64 #ifndef URB_ASYNC_UNLINK
65 #define URB_ASYNC_UNLINK 0
66 #endif
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
72 /*--------------------- Static Functions --------------------------*/
73 static
74 void
75 s_nsInterruptUsbIoCompleteRead(
76 struct urb *urb
80 static
81 void
82 s_nsBulkInUsbIoCompleteRead(
83 struct urb *urb
87 static
88 void
89 s_nsBulkOutIoCompleteWrite(
90 struct urb *urb
94 static
95 void
96 s_nsControlInUsbIoCompleteRead(
97 struct urb *urb
100 static
101 void
102 s_nsControlInUsbIoCompleteWrite(
103 struct urb *urb
106 /*--------------------- Export Variables --------------------------*/
108 /*--------------------- Export Functions --------------------------*/
112 NTSTATUS
113 PIPEnsControlOutAsyn(
114 PSDevice pDevice,
115 BYTE byRequest,
116 WORD wValue,
117 WORD wIndex,
118 WORD wLength,
119 PBYTE pbyBuffer
122 NTSTATUS ntStatus;
125 if (MP_TEST_FLAG(pDevice, fMP_DISCONNECTED))
126 return STATUS_FAILURE;
129 if (MP_TEST_FLAG(pDevice, fMP_CONTROL_WRITES)) {
130 return STATUS_FAILURE;
133 if (in_interrupt()) {
134 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"in_interrupt return ..byRequest %x\n", byRequest);
135 return STATUS_FAILURE;
138 ntStatus = usb_control_msg(
139 pDevice->usb,
140 usb_sndctrlpipe(pDevice->usb , 0),
141 byRequest,
142 0x40, // RequestType
143 wValue,
144 wIndex,
145 (void *) pbyBuffer,
146 wLength,
149 if (ntStatus >= 0) {
150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe ntStatus= %d\n", ntStatus);
151 ntStatus = 0;
152 } else {
153 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe fail, ntStatus= %d\n", ntStatus);
156 return ntStatus;
163 NTSTATUS
164 PIPEnsControlOut(
165 PSDevice pDevice,
166 BYTE byRequest,
167 WORD wValue,
168 WORD wIndex,
169 WORD wLength,
170 PBYTE pbyBuffer
173 NTSTATUS ntStatus = 0;
174 int ii;
177 if (MP_TEST_FLAG(pDevice, fMP_DISCONNECTED))
178 return STATUS_FAILURE;
180 if (MP_TEST_FLAG(pDevice, fMP_CONTROL_WRITES)) {
181 return STATUS_FAILURE;
184 pDevice->sUsbCtlRequest.bRequestType = 0x40;
185 pDevice->sUsbCtlRequest.bRequest = byRequest;
186 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
187 pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex);
188 pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength);
189 pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK;
190 pDevice->pControlURB->actual_length = 0;
191 // Notice, pbyBuffer limited point to variable buffer, can't be constant.
192 usb_fill_control_urb(pDevice->pControlURB, pDevice->usb,
193 usb_sndctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest,
194 pbyBuffer, wLength, s_nsControlInUsbIoCompleteWrite, pDevice);
196 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
197 if (ntStatus != 0) {
198 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control send request submission failed: %d\n", ntStatus);
199 return STATUS_FAILURE;
201 else {
202 MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES);
204 spin_unlock_irq(&pDevice->lock);
205 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
206 if (MP_TEST_FLAG(pDevice, fMP_CONTROL_WRITES))
207 mdelay(1);
208 else
209 break;
210 if (ii >= USB_CTL_WAIT) {
211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control send request submission timeout \n");
212 spin_lock_irq(&pDevice->lock);
213 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
214 return STATUS_FAILURE;
217 spin_lock_irq(&pDevice->lock);
219 return STATUS_SUCCESS;
225 NTSTATUS
226 PIPEnsControlIn(
227 PSDevice pDevice,
228 BYTE byRequest,
229 WORD wValue,
230 WORD wIndex,
231 WORD wLength,
232 PBYTE pbyBuffer
235 NTSTATUS ntStatus = 0;
236 int ii;
238 if (MP_TEST_FLAG(pDevice, fMP_DISCONNECTED))
239 return STATUS_FAILURE;
241 if (MP_TEST_FLAG(pDevice, fMP_CONTROL_READS)) {
242 return STATUS_FAILURE;
244 pDevice->sUsbCtlRequest.bRequestType = 0xC0;
245 pDevice->sUsbCtlRequest.bRequest = byRequest;
246 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
247 pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex);
248 pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength);
249 pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK;
250 pDevice->pControlURB->actual_length = 0;
251 usb_fill_control_urb(pDevice->pControlURB, pDevice->usb,
252 usb_rcvctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest,
253 pbyBuffer, wLength, s_nsControlInUsbIoCompleteRead, pDevice);
255 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
256 if (ntStatus != 0) {
257 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control request submission failed: %d\n", ntStatus);
258 }else {
259 MP_SET_FLAG(pDevice, fMP_CONTROL_READS);
262 spin_unlock_irq(&pDevice->lock);
263 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
264 if (MP_TEST_FLAG(pDevice, fMP_CONTROL_READS))
265 mdelay(1);
266 else {
267 break;
269 if (ii >= USB_CTL_WAIT) {
270 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control rcv request submission timeout \n");
271 spin_lock_irq(&pDevice->lock);
272 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
273 return STATUS_FAILURE;
276 spin_lock_irq(&pDevice->lock);
278 return ntStatus;
281 static
282 void
283 s_nsControlInUsbIoCompleteWrite(
284 struct urb *urb
287 PSDevice pDevice;
289 pDevice = urb->context;
290 switch (urb->status) {
291 case 0:
292 break;
293 case -EINPROGRESS:
294 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status EINPROGRESS%d\n", urb->status);
295 break;
296 case -ENOENT:
297 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status ENOENT %d\n", urb->status);
298 break;
299 default:
300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status %d\n", urb->status);
303 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
309 * Description:
310 * Complete function of usb Control callback
312 * Parameters:
313 * In:
314 * pDevice - Pointer to the adapter
316 * Out:
317 * none
319 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
322 static
323 void
324 s_nsControlInUsbIoCompleteRead(
325 struct urb *urb
328 PSDevice pDevice;
330 pDevice = urb->context;
331 switch (urb->status) {
332 case 0:
333 break;
334 case -EINPROGRESS:
335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status EINPROGRESS%d\n", urb->status);
336 break;
337 case -ENOENT:
338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status = ENOENT %d\n", urb->status);
339 break;
340 default:
341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status %d\n", urb->status);
344 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
351 * Description:
352 * Allocates an usb interrupt in irp and calls USBD.
354 * Parameters:
355 * In:
356 * pDevice - Pointer to the adapter
357 * Out:
358 * none
360 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
363 NTSTATUS
364 PIPEnsInterruptRead(
365 PSDevice pDevice
368 NTSTATUS ntStatus = STATUS_FAILURE;
371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartInterruptUsbRead()\n");
373 if(pDevice->intBuf.bInUse == TRUE){
374 return (STATUS_FAILURE);
376 pDevice->intBuf.bInUse = TRUE;
377 // pDevice->bEventAvailable = FALSE;
378 pDevice->ulIntInPosted++;
381 // Now that we have created the urb, we will send a
382 // request to the USB device object.
384 #if 0 //reserve int URB submit
385 usb_fill_int_urb(pDevice->pInterruptURB,
386 pDevice->usb,
387 usb_rcvintpipe(pDevice->usb, 1),
388 (void *) pDevice->intBuf.pDataBuf,
389 MAX_INTERRUPT_SIZE,
390 s_nsInterruptUsbIoCompleteRead,
391 pDevice,
392 pDevice->int_interval
394 #else //replace int URB submit by bulk transfer
395 #ifndef Safe_Close
396 usb_fill_int_urb(pDevice->pInterruptURB,
397 pDevice->usb,
398 usb_rcvintpipe(pDevice->usb, 1),
399 (void *) pDevice->intBuf.pDataBuf,
400 MAX_INTERRUPT_SIZE,
401 s_nsInterruptUsbIoCompleteRead,
402 pDevice,
403 pDevice->int_interval
405 #else
407 pDevice->pInterruptURB->interval = pDevice->int_interval;
409 usb_fill_bulk_urb(pDevice->pInterruptURB,
410 pDevice->usb,
411 usb_rcvbulkpipe(pDevice->usb, 1),
412 (void *) pDevice->intBuf.pDataBuf,
413 MAX_INTERRUPT_SIZE,
414 s_nsInterruptUsbIoCompleteRead,
415 pDevice);
416 #endif
417 #endif
419 ntStatus = usb_submit_urb(pDevice->pInterruptURB, GFP_ATOMIC);
420 if (ntStatus != 0) {
421 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit int URB failed %d\n", ntStatus);
424 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----s_nsStartInterruptUsbRead Return(%x)\n",ntStatus);
425 return ntStatus;
430 * Description:
431 * Complete function of usb interrupt in irp.
433 * Parameters:
434 * In:
435 * pDevice - Pointer to the adapter
437 * Out:
438 * none
440 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
443 static
444 void
445 s_nsInterruptUsbIoCompleteRead(
446 struct urb *urb
450 PSDevice pDevice;
451 NTSTATUS ntStatus;
454 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptUsbIoCompleteRead\n");
456 // The context given to IoSetCompletionRoutine is the receive buffer object
458 pDevice = (PSDevice)urb->context;
461 // We have a number of cases:
462 // 1) The USB read timed out and we received no data.
463 // 2) The USB read timed out and we received some data.
464 // 3) The USB read was successful and fully filled our irp buffer.
465 // 4) The irp was cancelled.
466 // 5) Some other failure from the USB device object.
468 ntStatus = urb->status;
470 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsInterruptUsbIoCompleteRead Status %d\n", ntStatus);
472 // if we were not successful, we need to free the int buffer for future use right here
473 // otherwise interrupt data handler will free int buffer after it handle it.
474 if (( ntStatus != STATUS_SUCCESS )) {
475 pDevice->ulBulkInError++;
476 pDevice->intBuf.bInUse = FALSE;
478 // if (ntStatus == USBD_STATUS_CRC) {
479 // pDevice->ulIntInContCRCError++;
480 // }
482 // if (ntStatus == STATUS_NOT_CONNECTED )
483 // {
484 pDevice->fKillEventPollingThread = TRUE;
485 // }
486 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"IntUSBIoCompleteControl STATUS = %d\n", ntStatus );
487 } else {
488 pDevice->ulIntInBytesRead += (unsigned long) urb->actual_length;
489 pDevice->ulIntInContCRCError = 0;
490 pDevice->bEventAvailable = TRUE;
491 INTnsProcessData(pDevice);
494 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_InterruptStat, ntStatus);
497 if (pDevice->fKillEventPollingThread != TRUE) {
498 #if 0 //reserve int URB submit
499 ntStatus = usb_submit_urb(urb, GFP_ATOMIC);
500 if (ntStatus != 0) {
501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Re-Submit int URB failed %d\n", ntStatus);
503 #else //replace int URB submit by bulk transfer
504 #ifdef Safe_Close
505 usb_fill_bulk_urb(pDevice->pInterruptURB,
506 pDevice->usb,
507 usb_rcvbulkpipe(pDevice->usb, 1),
508 (void *) pDevice->intBuf.pDataBuf,
509 MAX_INTERRUPT_SIZE,
510 s_nsInterruptUsbIoCompleteRead,
511 pDevice);
513 ntStatus = usb_submit_urb(pDevice->pInterruptURB, GFP_ATOMIC);
514 if (ntStatus != 0) {
515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit int URB failed %d\n", ntStatus);
518 #else
519 tasklet_schedule(&pDevice->EventWorkItem);
520 #endif
521 #endif
524 // We return STATUS_MORE_PROCESSING_REQUIRED so that the completion
525 // routine (IofCompleteRequest) will stop working on the irp.
527 return ;
531 * Description:
532 * Allocates an usb BulkIn irp and calls USBD.
534 * Parameters:
535 * In:
536 * pDevice - Pointer to the adapter
537 * Out:
538 * none
540 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
543 NTSTATUS
544 PIPEnsBulkInUsbRead(
545 PSDevice pDevice,
546 PRCB pRCB
549 NTSTATUS ntStatus= 0;
550 struct urb *pUrb;
553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
555 if (MP_TEST_FLAG(pDevice, fMP_DISCONNECTED))
556 return STATUS_FAILURE;
558 pDevice->ulBulkInPosted++;
561 pUrb = pRCB->pUrb;
563 // Now that we have created the urb, we will send a
564 // request to the USB device object.
566 if (pRCB->skb == NULL) {
567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pRCB->skb is null \n");
568 return ntStatus;
571 usb_fill_bulk_urb(pUrb,
572 pDevice->usb,
573 usb_rcvbulkpipe(pDevice->usb, 2),
574 (void *) (pRCB->skb->data),
575 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
576 s_nsBulkInUsbIoCompleteRead,
577 pRCB);
579 ntStatus = usb_submit_urb(pUrb, GFP_ATOMIC);
580 if (ntStatus != 0) {
581 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Rx URB failed %d\n", ntStatus);
582 return STATUS_FAILURE ;
584 pRCB->Ref = 1;
585 pRCB->bBoolInUse= TRUE;
587 return ntStatus;
594 * Description:
595 * Complete function of usb BulkIn irp.
597 * Parameters:
598 * In:
599 * pDevice - Pointer to the adapter
601 * Out:
602 * none
604 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
607 static
608 void
609 s_nsBulkInUsbIoCompleteRead(
610 struct urb *urb
614 PRCB pRCB = (PRCB)urb->context;
615 PSDevice pDevice = (PSDevice)pRCB->pDevice;
616 unsigned long bytesRead;
617 BOOL bIndicateReceive = FALSE;
618 BOOL bReAllocSkb = FALSE;
619 NTSTATUS status;
623 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
624 status = urb->status;
625 bytesRead = urb->actual_length;
627 if (status) {
628 pDevice->ulBulkInError++;
629 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK In failed %d\n", status);
631 #ifdef Calcu_LinkQual
632 pDevice->scStatistic.RxFcsErrCnt ++;
633 #endif
634 //todo...xxxxxx
635 // if (status == USBD_STATUS_CRC) {
636 // pDevice->ulBulkInContCRCError++;
637 // }
638 // if (status == STATUS_DEVICE_NOT_CONNECTED )
639 // {
640 // MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
641 // }
642 } else {
643 bIndicateReceive = TRUE;
644 pDevice->ulBulkInContCRCError = 0;
645 pDevice->ulBulkInBytesRead += bytesRead;
647 #ifdef Calcu_LinkQual
648 pDevice->scStatistic.RxOkCnt ++;
649 #endif
653 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_BulkInStat, status);
655 if (bIndicateReceive) {
656 spin_lock(&pDevice->lock);
657 if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == TRUE)
658 bReAllocSkb = TRUE;
659 spin_unlock(&pDevice->lock);
661 pRCB->Ref--;
662 if (pRCB->Ref == 0)
664 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d \n",pDevice->NumRecvFreeList);
665 spin_lock(&pDevice->lock);
666 RXvFreeRCB(pRCB, bReAllocSkb);
667 spin_unlock(&pDevice->lock);
671 return;
675 * Description:
676 * Allocates an usb BulkOut irp and calls USBD.
678 * Parameters:
679 * In:
680 * pDevice - Pointer to the adapter
681 * Out:
682 * none
684 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
687 NDIS_STATUS
688 PIPEnsSendBulkOut(
689 PSDevice pDevice,
690 PUSB_SEND_CONTEXT pContext
693 NTSTATUS status;
694 struct urb *pUrb;
698 pDevice->bPWBitOn = FALSE;
701 if (pDevice->pPendingBulkOutContext != NULL) {
702 pDevice->NumContextsQueued++;
703 EnqueueContext(pDevice->FirstTxContextQueue, pDevice->LastTxContextQueue, pContext);
704 status = STATUS_PENDING;
705 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send pending!\n");
706 return status;
710 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n");
712 if(MP_IS_READY(pDevice) && MP_TEST_FLAG(pDevice, fMP_POST_WRITES)) {
714 pUrb = pContext->pUrb;
715 pDevice->ulBulkOutPosted++;
716 // pDevice->pPendingBulkOutContext = pContext;
717 usb_fill_bulk_urb(
718 pUrb,
719 pDevice->usb,
720 usb_sndbulkpipe(pDevice->usb, 3),
721 (void *) &(pContext->Data[0]),
722 pContext->uBufLen,
723 s_nsBulkOutIoCompleteWrite,
724 pContext);
726 status = usb_submit_urb(pUrb, GFP_ATOMIC);
727 if (status != 0)
729 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Tx URB failed %d\n", status);
730 return STATUS_FAILURE;
732 return STATUS_PENDING;
734 else {
735 pContext->bBoolInUse = FALSE;
736 return STATUS_RESOURCES;
741 * Description: s_nsBulkOutIoCompleteWrite
742 * 1a) Indicate to the protocol the status of the write.
743 * 1b) Return ownership of the packet to the protocol.
745 * 2) If any more packets are queue for sending, send another packet
746 * to USBD.
747 * If the attempt to send the packet to the driver fails,
748 * return ownership of the packet to the protocol and
749 * try another packet (until one succeeds).
751 * Parameters:
752 * In:
753 * pdoUsbDevObj - pointer to the USB device object which
754 * completed the irp
755 * pIrp - the irp which was completed by the
756 * device object
757 * pContext - the context given to IoSetCompletionRoutine
758 * before calling IoCallDriver on the irp
759 * The pContext is a pointer to the USB device object.
760 * Out:
761 * none
763 * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine
764 * (IofCompleteRequest) to stop working on the irp.
767 static
768 void
769 s_nsBulkOutIoCompleteWrite(
770 struct urb *urb
773 PSDevice pDevice;
774 NTSTATUS status;
775 CONTEXT_TYPE ContextType;
776 unsigned long ulBufLen;
777 PUSB_SEND_CONTEXT pContext;
780 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
782 // The context given to IoSetCompletionRoutine is an USB_CONTEXT struct
784 pContext = (PUSB_SEND_CONTEXT) urb->context;
785 ASSERT( NULL != pContext );
787 pDevice = pContext->pDevice;
788 ContextType = pContext->Type;
789 ulBufLen = pContext->uBufLen;
791 if (!netif_device_present(pDevice->dev))
792 return;
795 // Perform various IRP, URB, and buffer 'sanity checks'
798 status = urb->status;
799 //we should have failed, succeeded, or cancelled, but NOT be pending
800 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_BulkOutStat, status);
802 if(status == STATUS_SUCCESS) {
803 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Write %d bytes\n",(int)ulBufLen);
804 pDevice->ulBulkOutBytesWrite += ulBufLen;
805 pDevice->ulBulkOutContCRCError = 0;
806 //2007-0115-06<Add>by MikeLiu
807 #ifdef TxInSleep
808 pDevice->nTxDataTimeCout = 0;
809 #endif
811 } else {
812 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK Out failed %d\n", status);
813 pDevice->ulBulkOutError++;
816 // pDevice->ulCheckForHangCount = 0;
817 // pDevice->pPendingBulkOutContext = NULL;
819 if ( CONTEXT_DATA_PACKET == ContextType ) {
820 // Indicate to the protocol the status of the sent packet and return
821 // ownership of the packet.
822 if (pContext->pPacket != NULL) {
823 dev_kfree_skb_irq(pContext->pPacket);
824 pContext->pPacket = NULL;
825 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"tx %d bytes\n",(int)ulBufLen);
828 pDevice->dev->trans_start = jiffies;
831 if (status == STATUS_SUCCESS) {
832 pDevice->packetsSent++;
834 else {
835 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send USB error! [%08xh]\n", status);
836 pDevice->packetsSentDropped++;
840 if (pDevice->bLinkPass == TRUE) {
841 if (netif_queue_stopped(pDevice->dev))
842 netif_wake_queue(pDevice->dev);
844 pContext->bBoolInUse = FALSE;
846 return;