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