Merge tag 'staging-3.7-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[GitHub/mt8127/android_kernel_alcatel_ttab.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
FB
47
48/*--------------------- Static Definitions -------------------------*/
49//endpoint def
50//endpoint 0: control
51//endpoint 1: interrupt
52//endpoint 2: read bulk
53//endpoint 3: write bulk
54
92b96797
FB
55//static int msglevel =MSG_LEVEL_DEBUG;
56static int msglevel =MSG_LEVEL_INFO;
57
58
59#define USB_CTL_WAIT 500 //ms
60
61#ifndef URB_ASYNC_UNLINK
62#define URB_ASYNC_UNLINK 0
63#endif
64
65/*--------------------- Static Classes ----------------------------*/
66
67/*--------------------- Static Variables --------------------------*/
68
69/*--------------------- Static Functions --------------------------*/
92b96797 70static
8611a29a 71void
92b96797 72s_nsInterruptUsbIoCompleteRead(
592ccfeb 73 struct urb *urb
92b96797
FB
74 );
75
76
77static
8611a29a 78void
92b96797 79s_nsBulkInUsbIoCompleteRead(
592ccfeb 80 struct urb *urb
92b96797
FB
81 );
82
83
84static
8611a29a 85void
92b96797 86s_nsBulkOutIoCompleteWrite(
592ccfeb 87 struct urb *urb
92b96797
FB
88 );
89
90
91static
8611a29a 92void
92b96797 93s_nsControlInUsbIoCompleteRead(
592ccfeb 94 struct urb *urb
92b96797
FB
95 );
96
97static
8611a29a 98void
92b96797 99s_nsControlInUsbIoCompleteWrite(
592ccfeb 100 struct urb *urb
92b96797
FB
101 );
102
92b96797
FB
103/*--------------------- Export Variables --------------------------*/
104
105/*--------------------- Export Functions --------------------------*/
106
6487c49e 107int PIPEnsControlOutAsyn(
592ccfeb
AM
108 PSDevice pDevice,
109 BYTE byRequest,
110 WORD wValue,
111 WORD wIndex,
112 WORD wLength,
113 PBYTE pbyBuffer
92b96797
FB
114 )
115{
6487c49e 116 int ntStatus;
92b96797 117
731047f9 118 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
119 return STATUS_FAILURE;
120
731047f9 121 if (pDevice->Flags & fMP_CONTROL_WRITES)
92b96797 122 return STATUS_FAILURE;
92b96797
FB
123
124 if (in_interrupt()) {
125 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"in_interrupt return ..byRequest %x\n", byRequest);
126 return STATUS_FAILURE;
127 }
128
129 ntStatus = usb_control_msg(
130 pDevice->usb,
131 usb_sndctrlpipe(pDevice->usb , 0),
132 byRequest,
133 0x40, // RequestType
134 wValue,
135 wIndex,
8611a29a 136 (void *) pbyBuffer,
92b96797
FB
137 wLength,
138 HZ
139 );
140 if (ntStatus >= 0) {
141 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe ntStatus= %d\n", ntStatus);
142 ntStatus = 0;
143 } else {
144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe fail, ntStatus= %d\n", ntStatus);
145 }
146
147 return ntStatus;
148}
149
6487c49e 150int PIPEnsControlOut(
592ccfeb
AM
151 PSDevice pDevice,
152 BYTE byRequest,
153 WORD wValue,
154 WORD wIndex,
155 WORD wLength,
156 PBYTE pbyBuffer
92b96797
FB
157 )
158{
6487c49e 159 int ntStatus = 0;
92b96797
FB
160 int ii;
161
731047f9 162 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
163 return STATUS_FAILURE;
164
731047f9 165 if (pDevice->Flags & fMP_CONTROL_WRITES)
92b96797 166 return STATUS_FAILURE;
92b96797
FB
167
168 pDevice->sUsbCtlRequest.bRequestType = 0x40;
169 pDevice->sUsbCtlRequest.bRequest = byRequest;
170 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
171 pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex);
172 pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength);
173 pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK;
174 pDevice->pControlURB->actual_length = 0;
175 // Notice, pbyBuffer limited point to variable buffer, can't be constant.
176 usb_fill_control_urb(pDevice->pControlURB, pDevice->usb,
177 usb_sndctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest,
178 pbyBuffer, wLength, s_nsControlInUsbIoCompleteWrite, pDevice);
179
bfbfeecc
JP
180 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
181 if (ntStatus != 0) {
92b96797
FB
182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control send request submission failed: %d\n", ntStatus);
183 return STATUS_FAILURE;
184 }
185 else {
186 MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES);
187 }
188 spin_unlock_irq(&pDevice->lock);
189 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
731047f9
AM
190
191 if (pDevice->Flags & fMP_CONTROL_WRITES)
192 mdelay(1);
92b96797 193 else
731047f9
AM
194 break;
195
92b96797 196 if (ii >= USB_CTL_WAIT) {
731047f9
AM
197 DBG_PRT(MSG_LEVEL_DEBUG,
198 KERN_INFO "control send request submission timeout\n");
92b96797
FB
199 spin_lock_irq(&pDevice->lock);
200 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
201 return STATUS_FAILURE;
202 }
203 }
204 spin_lock_irq(&pDevice->lock);
205
206 return STATUS_SUCCESS;
207}
208
6487c49e 209int PIPEnsControlIn(
592ccfeb
AM
210 PSDevice pDevice,
211 BYTE byRequest,
212 WORD wValue,
213 WORD wIndex,
214 WORD wLength,
6f8c13c7 215 PBYTE pbyBuffer
92b96797
FB
216 )
217{
6487c49e 218 int ntStatus = 0;
92b96797
FB
219 int ii;
220
731047f9 221 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
222 return STATUS_FAILURE;
223
731047f9
AM
224 if (pDevice->Flags & fMP_CONTROL_READS)
225 return STATUS_FAILURE;
226
92b96797
FB
227 pDevice->sUsbCtlRequest.bRequestType = 0xC0;
228 pDevice->sUsbCtlRequest.bRequest = byRequest;
229 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
230 pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex);
231 pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength);
232 pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK;
233 pDevice->pControlURB->actual_length = 0;
234 usb_fill_control_urb(pDevice->pControlURB, pDevice->usb,
235 usb_rcvctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest,
236 pbyBuffer, wLength, s_nsControlInUsbIoCompleteRead, pDevice);
237
bfbfeecc
JP
238 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
239 if (ntStatus != 0) {
92b96797
FB
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control request submission failed: %d\n", ntStatus);
241 }else {
242 MP_SET_FLAG(pDevice, fMP_CONTROL_READS);
243 }
244
245 spin_unlock_irq(&pDevice->lock);
246 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
731047f9
AM
247
248 if (pDevice->Flags & fMP_CONTROL_READS)
249 mdelay(1);
250 else
251 break;
252
253 if (ii >= USB_CTL_WAIT) {
254 DBG_PRT(MSG_LEVEL_DEBUG,
255 KERN_INFO "control rcv request submission timeout\n");
92b96797
FB
256 spin_lock_irq(&pDevice->lock);
257 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
258 return STATUS_FAILURE;
259 }
260 }
261 spin_lock_irq(&pDevice->lock);
262
263 return ntStatus;
264}
265
92b96797 266static
8611a29a 267void
92b96797 268s_nsControlInUsbIoCompleteWrite(
592ccfeb 269 struct urb *urb
92b96797 270 )
92b96797
FB
271{
272 PSDevice pDevice;
273
274 pDevice = urb->context;
275 switch (urb->status) {
276 case 0:
277 break;
278 case -EINPROGRESS:
279 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status EINPROGRESS%d\n", urb->status);
280 break;
281 case -ENOENT:
282 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status ENOENT %d\n", urb->status);
283 break;
284 default:
285 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl write urb status %d\n", urb->status);
286 }
287
288 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
289}
290
291
292
293/*
294 * Description:
295 * Complete function of usb Control callback
296 *
297 * Parameters:
298 * In:
299 * pDevice - Pointer to the adapter
300 *
301 * Out:
302 * none
303 *
304 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
305 *
306 */
92b96797 307static
8611a29a 308void
92b96797 309s_nsControlInUsbIoCompleteRead(
592ccfeb 310 struct urb *urb
92b96797 311 )
92b96797
FB
312{
313 PSDevice pDevice;
314
315 pDevice = urb->context;
316 switch (urb->status) {
317 case 0:
318 break;
319 case -EINPROGRESS:
320 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status EINPROGRESS%d\n", urb->status);
321 break;
322 case -ENOENT:
323 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status = ENOENT %d\n", urb->status);
324 break;
325 default:
326 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status %d\n", urb->status);
327 }
328
329 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
330}
331
332
333
334
335/*
336 * Description:
337 * Allocates an usb interrupt in irp and calls USBD.
338 *
339 * Parameters:
340 * In:
341 * pDevice - Pointer to the adapter
342 * Out:
343 * none
344 *
345 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
346 *
347 */
6487c49e 348int PIPEnsInterruptRead(PSDevice pDevice)
92b96797 349{
6487c49e 350 int ntStatus = STATUS_FAILURE;
92b96797
FB
351
352 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartInterruptUsbRead()\n");
353
354 if(pDevice->intBuf.bInUse == TRUE){
355 return (STATUS_FAILURE);
356 }
357 pDevice->intBuf.bInUse = TRUE;
358// pDevice->bEventAvailable = FALSE;
359 pDevice->ulIntInPosted++;
360
361 //
362 // Now that we have created the urb, we will send a
363 // request to the USB device object.
364 //
92b96797 365 pDevice->pInterruptURB->interval = pDevice->int_interval;
92b96797
FB
366
367usb_fill_bulk_urb(pDevice->pInterruptURB,
368 pDevice->usb,
369 usb_rcvbulkpipe(pDevice->usb, 1),
8611a29a 370 (void *) pDevice->intBuf.pDataBuf,
92b96797
FB
371 MAX_INTERRUPT_SIZE,
372 s_nsInterruptUsbIoCompleteRead,
373 pDevice);
92b96797 374
bfbfeecc
JP
375 ntStatus = usb_submit_urb(pDevice->pInterruptURB, GFP_ATOMIC);
376 if (ntStatus != 0) {
92b96797
FB
377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit int URB failed %d\n", ntStatus);
378 }
379
92b96797
FB
380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----s_nsStartInterruptUsbRead Return(%x)\n",ntStatus);
381 return ntStatus;
382}
383
384
385/*
386 * Description:
387 * Complete function of usb interrupt in irp.
388 *
389 * Parameters:
390 * In:
391 * pDevice - Pointer to the adapter
392 *
393 * Out:
394 * none
395 *
396 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
397 *
398 */
92b96797 399static
8611a29a 400void
92b96797 401s_nsInterruptUsbIoCompleteRead(
592ccfeb 402 struct urb *urb
92b96797
FB
403 )
404
92b96797
FB
405{
406 PSDevice pDevice;
6487c49e 407 int ntStatus;
92b96797
FB
408
409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptUsbIoCompleteRead\n");
410 //
411 // The context given to IoSetCompletionRoutine is the receive buffer object
412 //
413 pDevice = (PSDevice)urb->context;
414
415 //
416 // We have a number of cases:
417 // 1) The USB read timed out and we received no data.
418 // 2) The USB read timed out and we received some data.
419 // 3) The USB read was successful and fully filled our irp buffer.
420 // 4) The irp was cancelled.
421 // 5) Some other failure from the USB device object.
422 //
423 ntStatus = urb->status;
424
425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsInterruptUsbIoCompleteRead Status %d\n", ntStatus);
426
427 // if we were not successful, we need to free the int buffer for future use right here
428 // otherwise interrupt data handler will free int buffer after it handle it.
429 if (( ntStatus != STATUS_SUCCESS )) {
430 pDevice->ulBulkInError++;
431 pDevice->intBuf.bInUse = FALSE;
432
433// if (ntStatus == USBD_STATUS_CRC) {
434// pDevice->ulIntInContCRCError++;
435// }
436
437// if (ntStatus == STATUS_NOT_CONNECTED )
438// {
439 pDevice->fKillEventPollingThread = TRUE;
440// }
441 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"IntUSBIoCompleteControl STATUS = %d\n", ntStatus );
cc856e61
AM
442 } else {
443 pDevice->ulIntInBytesRead += (unsigned long) urb->actual_length;
444 pDevice->ulIntInContCRCError = 0;
445 pDevice->bEventAvailable = TRUE;
446 INTnsProcessData(pDevice);
92b96797
FB
447 }
448
449 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_InterruptStat, ntStatus);
450
451
452 if (pDevice->fKillEventPollingThread != TRUE) {
92b96797
FB
453 usb_fill_bulk_urb(pDevice->pInterruptURB,
454 pDevice->usb,
455 usb_rcvbulkpipe(pDevice->usb, 1),
8611a29a 456 (void *) pDevice->intBuf.pDataBuf,
92b96797
FB
457 MAX_INTERRUPT_SIZE,
458 s_nsInterruptUsbIoCompleteRead,
459 pDevice);
460
bfbfeecc
JP
461 ntStatus = usb_submit_urb(pDevice->pInterruptURB, GFP_ATOMIC);
462 if (ntStatus != 0) {
92b96797
FB
463 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit int URB failed %d\n", ntStatus);
464 }
92b96797
FB
465 }
466 //
467 // We return STATUS_MORE_PROCESSING_REQUIRED so that the completion
468 // routine (IofCompleteRequest) will stop working on the irp.
469 //
470 return ;
471}
472
473/*
474 * Description:
475 * Allocates an usb BulkIn irp and calls USBD.
476 *
477 * Parameters:
478 * In:
479 * pDevice - Pointer to the adapter
480 * Out:
481 * none
482 *
483 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
484 *
485 */
6487c49e 486int PIPEnsBulkInUsbRead(PSDevice pDevice, PRCB pRCB)
92b96797 487{
6487c49e 488 int ntStatus = 0;
92b96797
FB
489 struct urb *pUrb;
490
491
492 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
493
731047f9 494 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
495 return STATUS_FAILURE;
496
497 pDevice->ulBulkInPosted++;
498
499
500 pUrb = pRCB->pUrb;
501 //
502 // Now that we have created the urb, we will send a
503 // request to the USB device object.
504 //
505 if (pRCB->skb == NULL) {
506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pRCB->skb is null \n");
507 return ntStatus;
508 }
509
510 usb_fill_bulk_urb(pUrb,
511 pDevice->usb,
512 usb_rcvbulkpipe(pDevice->usb, 2),
8611a29a 513 (void *) (pRCB->skb->data),
92b96797
FB
514 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
515 s_nsBulkInUsbIoCompleteRead,
516 pRCB);
517
bfbfeecc
JP
518 ntStatus = usb_submit_urb(pUrb, GFP_ATOMIC);
519 if (ntStatus != 0) {
92b96797
FB
520 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Rx URB failed %d\n", ntStatus);
521 return STATUS_FAILURE ;
522 }
523 pRCB->Ref = 1;
524 pRCB->bBoolInUse= TRUE;
525
526 return ntStatus;
527}
528
529
530
531
532/*
533 * Description:
534 * Complete function of usb BulkIn irp.
535 *
536 * Parameters:
537 * In:
538 * pDevice - Pointer to the adapter
539 *
540 * Out:
541 * none
542 *
543 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
544 *
545 */
92b96797 546static
8611a29a 547void
92b96797 548s_nsBulkInUsbIoCompleteRead(
592ccfeb 549 struct urb *urb
92b96797
FB
550 )
551
92b96797
FB
552{
553 PRCB pRCB = (PRCB)urb->context;
554 PSDevice pDevice = (PSDevice)pRCB->pDevice;
cc856e61 555 unsigned long bytesRead;
193a823c 556 BOOL bIndicateReceive = FALSE;
92b96797 557 BOOL bReAllocSkb = FALSE;
6487c49e 558 int status;
92b96797
FB
559
560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
561 status = urb->status;
562 bytesRead = urb->actual_length;
563
564 if (status) {
565 pDevice->ulBulkInError++;
566 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK In failed %d\n", status);
567
92b96797 568 pDevice->scStatistic.RxFcsErrCnt ++;
92b96797
FB
569//todo...xxxxxx
570// if (status == USBD_STATUS_CRC) {
571// pDevice->ulBulkInContCRCError++;
572// }
573// if (status == STATUS_DEVICE_NOT_CONNECTED )
574// {
575// MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
576// }
577 } else {
578 bIndicateReceive = TRUE;
579 pDevice->ulBulkInContCRCError = 0;
580 pDevice->ulBulkInBytesRead += bytesRead;
581
92b96797 582 pDevice->scStatistic.RxOkCnt ++;
92b96797
FB
583 }
584
585
586 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_BulkInStat, status);
587
588 if (bIndicateReceive) {
589 spin_lock(&pDevice->lock);
590 if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == TRUE)
591 bReAllocSkb = TRUE;
592 spin_unlock(&pDevice->lock);
593 }
594 pRCB->Ref--;
595 if (pRCB->Ref == 0)
596 {
597 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d \n",pDevice->NumRecvFreeList);
598 spin_lock(&pDevice->lock);
599 RXvFreeRCB(pRCB, bReAllocSkb);
600 spin_unlock(&pDevice->lock);
601 }
602
603
604 return;
605}
606
607/*
608 * Description:
609 * Allocates an usb BulkOut irp and calls USBD.
610 *
611 * Parameters:
612 * In:
613 * pDevice - Pointer to the adapter
614 * Out:
615 * none
616 *
617 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
618 *
619 */
27264fb8 620int
92b96797 621PIPEnsSendBulkOut(
592ccfeb
AM
622 PSDevice pDevice,
623 PUSB_SEND_CONTEXT pContext
92b96797
FB
624 )
625{
6487c49e 626 int status;
92b96797
FB
627 struct urb *pUrb;
628
629
630
631 pDevice->bPWBitOn = FALSE;
632
633/*
634 if (pDevice->pPendingBulkOutContext != NULL) {
635 pDevice->NumContextsQueued++;
636 EnqueueContext(pDevice->FirstTxContextQueue, pDevice->LastTxContextQueue, pContext);
637 status = STATUS_PENDING;
638 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send pending!\n");
639 return status;
640 }
641*/
642
643 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n");
644
731047f9 645 if (MP_IS_READY(pDevice) && (pDevice->Flags & fMP_POST_WRITES)) {
92b96797
FB
646
647 pUrb = pContext->pUrb;
648 pDevice->ulBulkOutPosted++;
649// pDevice->pPendingBulkOutContext = pContext;
650 usb_fill_bulk_urb(
651 pUrb,
652 pDevice->usb,
8611a29a
AM
653 usb_sndbulkpipe(pDevice->usb, 3),
654 (void *) &(pContext->Data[0]),
92b96797
FB
655 pContext->uBufLen,
656 s_nsBulkOutIoCompleteWrite,
657 pContext);
658
bfbfeecc
JP
659 status = usb_submit_urb(pUrb, GFP_ATOMIC);
660 if (status != 0)
92b96797
FB
661 {
662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Tx URB failed %d\n", status);
663 return STATUS_FAILURE;
664 }
665 return STATUS_PENDING;
666 }
667 else {
668 pContext->bBoolInUse = FALSE;
669 return STATUS_RESOURCES;
670 }
671}
672
673/*
674 * Description: s_nsBulkOutIoCompleteWrite
675 * 1a) Indicate to the protocol the status of the write.
676 * 1b) Return ownership of the packet to the protocol.
677 *
678 * 2) If any more packets are queue for sending, send another packet
679 * to USBD.
680 * If the attempt to send the packet to the driver fails,
681 * return ownership of the packet to the protocol and
682 * try another packet (until one succeeds).
683 *
684 * Parameters:
685 * In:
686 * pdoUsbDevObj - pointer to the USB device object which
687 * completed the irp
688 * pIrp - the irp which was completed by the
689 * device object
690 * pContext - the context given to IoSetCompletionRoutine
691 * before calling IoCallDriver on the irp
692 * The pContext is a pointer to the USB device object.
693 * Out:
694 * none
695 *
696 * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine
697 * (IofCompleteRequest) to stop working on the irp.
698 *
699 */
92b96797 700static
8611a29a 701void
92b96797 702s_nsBulkOutIoCompleteWrite(
592ccfeb 703 struct urb *urb
92b96797 704 )
92b96797
FB
705{
706 PSDevice pDevice;
6487c49e 707 int status;
92b96797 708 CONTEXT_TYPE ContextType;
cc856e61 709 unsigned long ulBufLen;
92b96797
FB
710 PUSB_SEND_CONTEXT pContext;
711
712
713 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
714 //
715 // The context given to IoSetCompletionRoutine is an USB_CONTEXT struct
716 //
717 pContext = (PUSB_SEND_CONTEXT) urb->context;
718 ASSERT( NULL != pContext );
719
720 pDevice = pContext->pDevice;
721 ContextType = pContext->Type;
722 ulBufLen = pContext->uBufLen;
723
724 if (!netif_device_present(pDevice->dev))
725 return;
726
727 //
728 // Perform various IRP, URB, and buffer 'sanity checks'
729 //
730
731 status = urb->status;
732 //we should have failed, succeeded, or cancelled, but NOT be pending
733 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_BulkOutStat, status);
734
735 if(status == STATUS_SUCCESS) {
736 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Write %d bytes\n",(int)ulBufLen);
737 pDevice->ulBulkOutBytesWrite += ulBufLen;
738 pDevice->ulBulkOutContCRCError = 0;
feaf03d3 739 pDevice->nTxDataTimeCout = 0;
92b96797
FB
740
741 } else {
742 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK Out failed %d\n", status);
743 pDevice->ulBulkOutError++;
744 }
745
746// pDevice->ulCheckForHangCount = 0;
747// pDevice->pPendingBulkOutContext = NULL;
748
749 if ( CONTEXT_DATA_PACKET == ContextType ) {
750 // Indicate to the protocol the status of the sent packet and return
751 // ownership of the packet.
752 if (pContext->pPacket != NULL) {
753 dev_kfree_skb_irq(pContext->pPacket);
754 pContext->pPacket = NULL;
755 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"tx %d bytes\n",(int)ulBufLen);
756 }
757
758 pDevice->dev->trans_start = jiffies;
759
760
761 if (status == STATUS_SUCCESS) {
762 pDevice->packetsSent++;
763 }
764 else {
765 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send USB error! [%08xh]\n", status);
766 pDevice->packetsSentDropped++;
767 }
768
769 }
770 if (pDevice->bLinkPass == TRUE) {
771 if (netif_queue_stopped(pDevice->dev))
772 netif_wake_queue(pDevice->dev);
773 }
774 pContext->bBoolInUse = FALSE;
775
776 return;
777}