Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.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
MP
297
298int PIPEnsInterruptRead(struct vnt_private *pDevice)
92b96797 299{
fe5d00eb 300 int ntStatus = STATUS_FAILURE;
92b96797
FB
301
302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartInterruptUsbRead()\n");
303
4e9b5e2b 304 if(pDevice->intBuf.bInUse == true){
92b96797
FB
305 return (STATUS_FAILURE);
306 }
4e9b5e2b 307 pDevice->intBuf.bInUse = true;
e269fc2d 308// pDevice->bEventAvailable = false;
92b96797
FB
309 pDevice->ulIntInPosted++;
310
311 //
312 // Now that we have created the urb, we will send a
313 // request to the USB device object.
314 //
92b96797 315 pDevice->pInterruptURB->interval = pDevice->int_interval;
92b96797
FB
316
317usb_fill_bulk_urb(pDevice->pInterruptURB,
318 pDevice->usb,
319 usb_rcvbulkpipe(pDevice->usb, 1),
8611a29a 320 (void *) pDevice->intBuf.pDataBuf,
92b96797
FB
321 MAX_INTERRUPT_SIZE,
322 s_nsInterruptUsbIoCompleteRead,
323 pDevice);
92b96797 324
bfbfeecc
JP
325 ntStatus = usb_submit_urb(pDevice->pInterruptURB, GFP_ATOMIC);
326 if (ntStatus != 0) {
92b96797
FB
327 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit int URB failed %d\n", ntStatus);
328 }
329
92b96797
FB
330 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----s_nsStartInterruptUsbRead Return(%x)\n",ntStatus);
331 return ntStatus;
332}
333
92b96797
FB
334/*
335 * Description:
336 * Complete function of usb interrupt in irp.
337 *
338 * Parameters:
339 * In:
340 * pDevice - Pointer to the adapter
341 *
342 * Out:
343 * none
344 *
345 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
346 *
347 */
92b96797 348
fe5d00eb 349static void s_nsInterruptUsbIoCompleteRead(struct urb *urb)
92b96797 350{
fe5d00eb
MP
351 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
352 int ntStatus;
92b96797
FB
353
354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptUsbIoCompleteRead\n");
355 //
356 // The context given to IoSetCompletionRoutine is the receive buffer object
357 //
92b96797
FB
358
359 //
360 // We have a number of cases:
361 // 1) The USB read timed out and we received no data.
362 // 2) The USB read timed out and we received some data.
363 // 3) The USB read was successful and fully filled our irp buffer.
364 // 4) The irp was cancelled.
365 // 5) Some other failure from the USB device object.
366 //
367 ntStatus = urb->status;
368
369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsInterruptUsbIoCompleteRead Status %d\n", ntStatus);
370
371 // if we were not successful, we need to free the int buffer for future use right here
372 // otherwise interrupt data handler will free int buffer after it handle it.
373 if (( ntStatus != STATUS_SUCCESS )) {
374 pDevice->ulBulkInError++;
e269fc2d 375 pDevice->intBuf.bInUse = false;
92b96797
FB
376
377// if (ntStatus == USBD_STATUS_CRC) {
378// pDevice->ulIntInContCRCError++;
379// }
380
381// if (ntStatus == STATUS_NOT_CONNECTED )
382// {
4e9b5e2b 383 pDevice->fKillEventPollingThread = true;
92b96797
FB
384// }
385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"IntUSBIoCompleteControl STATUS = %d\n", ntStatus );
cc856e61
AM
386 } else {
387 pDevice->ulIntInBytesRead += (unsigned long) urb->actual_length;
388 pDevice->ulIntInContCRCError = 0;
4e9b5e2b 389 pDevice->bEventAvailable = true;
cc856e61 390 INTnsProcessData(pDevice);
92b96797
FB
391 }
392
393 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_InterruptStat, ntStatus);
394
4e9b5e2b 395 if (pDevice->fKillEventPollingThread != true) {
92b96797
FB
396 usb_fill_bulk_urb(pDevice->pInterruptURB,
397 pDevice->usb,
398 usb_rcvbulkpipe(pDevice->usb, 1),
8611a29a 399 (void *) pDevice->intBuf.pDataBuf,
92b96797
FB
400 MAX_INTERRUPT_SIZE,
401 s_nsInterruptUsbIoCompleteRead,
402 pDevice);
403
bfbfeecc
JP
404 ntStatus = usb_submit_urb(pDevice->pInterruptURB, GFP_ATOMIC);
405 if (ntStatus != 0) {
92b96797
FB
406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit int URB failed %d\n", ntStatus);
407 }
92b96797
FB
408 }
409 //
410 // We return STATUS_MORE_PROCESSING_REQUIRED so that the completion
411 // routine (IofCompleteRequest) will stop working on the irp.
412 //
413 return ;
414}
415
416/*
417 * Description:
418 * Allocates an usb BulkIn irp and calls USBD.
419 *
420 * Parameters:
421 * In:
422 * pDevice - Pointer to the adapter
423 * Out:
424 * none
425 *
426 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
427 *
428 */
fe5d00eb 429
115cac2e 430int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, struct vnt_rcb *pRCB)
92b96797 431{
6487c49e 432 int ntStatus = 0;
fe5d00eb 433 struct urb *pUrb;
92b96797 434
92b96797
FB
435 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
436
731047f9 437 if (pDevice->Flags & fMP_DISCONNECTED)
92b96797
FB
438 return STATUS_FAILURE;
439
440 pDevice->ulBulkInPosted++;
441
92b96797
FB
442 pUrb = pRCB->pUrb;
443 //
444 // Now that we have created the urb, we will send a
445 // request to the USB device object.
446 //
447 if (pRCB->skb == NULL) {
448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pRCB->skb is null \n");
449 return ntStatus;
450 }
451
452 usb_fill_bulk_urb(pUrb,
453 pDevice->usb,
454 usb_rcvbulkpipe(pDevice->usb, 2),
8611a29a 455 (void *) (pRCB->skb->data),
92b96797
FB
456 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
457 s_nsBulkInUsbIoCompleteRead,
458 pRCB);
459
bfbfeecc
JP
460 ntStatus = usb_submit_urb(pUrb, GFP_ATOMIC);
461 if (ntStatus != 0) {
92b96797
FB
462 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Rx URB failed %d\n", ntStatus);
463 return STATUS_FAILURE ;
464 }
465 pRCB->Ref = 1;
4e9b5e2b 466 pRCB->bBoolInUse= true;
92b96797
FB
467
468 return ntStatus;
469}
470
92b96797
FB
471/*
472 * Description:
473 * Complete function of usb BulkIn irp.
474 *
475 * Parameters:
476 * In:
477 * pDevice - Pointer to the adapter
478 *
479 * Out:
480 * none
481 *
482 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
483 *
484 */
92b96797 485
fe5d00eb 486static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
92b96797 487{
115cac2e 488 struct vnt_rcb *pRCB = (struct vnt_rcb *)urb->context;
fe5d00eb
MP
489 struct vnt_private *pDevice = pRCB->pDevice;
490 unsigned long bytesRead;
e269fc2d
AM
491 int bIndicateReceive = false;
492 int bReAllocSkb = false;
fe5d00eb 493 int status;
92b96797
FB
494
495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
496 status = urb->status;
497 bytesRead = urb->actual_length;
498
499 if (status) {
500 pDevice->ulBulkInError++;
501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK In failed %d\n", status);
502
92b96797 503 pDevice->scStatistic.RxFcsErrCnt ++;
92b96797
FB
504//todo...xxxxxx
505// if (status == USBD_STATUS_CRC) {
506// pDevice->ulBulkInContCRCError++;
507// }
508// if (status == STATUS_DEVICE_NOT_CONNECTED )
509// {
510// MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
511// }
512 } else {
87c62985 513 if (bytesRead)
4e9b5e2b 514 bIndicateReceive = true;
92b96797
FB
515 pDevice->ulBulkInContCRCError = 0;
516 pDevice->ulBulkInBytesRead += bytesRead;
517
92b96797 518 pDevice->scStatistic.RxOkCnt ++;
92b96797
FB
519 }
520
92b96797
FB
521 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_BulkInStat, status);
522
523 if (bIndicateReceive) {
524 spin_lock(&pDevice->lock);
4e9b5e2b
AM
525 if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == true)
526 bReAllocSkb = true;
92b96797
FB
527 spin_unlock(&pDevice->lock);
528 }
529 pRCB->Ref--;
530 if (pRCB->Ref == 0)
531 {
532 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d \n",pDevice->NumRecvFreeList);
533 spin_lock(&pDevice->lock);
534 RXvFreeRCB(pRCB, bReAllocSkb);
535 spin_unlock(&pDevice->lock);
536 }
537
92b96797
FB
538 return;
539}
540
541/*
542 * Description:
543 * Allocates an usb BulkOut irp and calls USBD.
544 *
545 * Parameters:
546 * In:
547 * pDevice - Pointer to the adapter
548 * Out:
549 * none
550 *
551 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
552 *
553 */
fe5d00eb 554
dcdf1d03
MP
555int PIPEnsSendBulkOut(struct vnt_private *pDevice,
556 struct vnt_usb_send_context *pContext)
92b96797 557{
fe5d00eb
MP
558 int status;
559 struct urb *pUrb;
92b96797 560
e269fc2d 561 pDevice->bPWBitOn = false;
92b96797
FB
562
563/*
564 if (pDevice->pPendingBulkOutContext != NULL) {
565 pDevice->NumContextsQueued++;
566 EnqueueContext(pDevice->FirstTxContextQueue, pDevice->LastTxContextQueue, pContext);
567 status = STATUS_PENDING;
568 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send pending!\n");
569 return status;
570 }
571*/
572
573 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n");
574
731047f9 575 if (MP_IS_READY(pDevice) && (pDevice->Flags & fMP_POST_WRITES)) {
92b96797
FB
576
577 pUrb = pContext->pUrb;
578 pDevice->ulBulkOutPosted++;
579// pDevice->pPendingBulkOutContext = pContext;
580 usb_fill_bulk_urb(
581 pUrb,
582 pDevice->usb,
8611a29a
AM
583 usb_sndbulkpipe(pDevice->usb, 3),
584 (void *) &(pContext->Data[0]),
92b96797
FB
585 pContext->uBufLen,
586 s_nsBulkOutIoCompleteWrite,
587 pContext);
588
bfbfeecc
JP
589 status = usb_submit_urb(pUrb, GFP_ATOMIC);
590 if (status != 0)
92b96797
FB
591 {
592 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Tx URB failed %d\n", status);
e269fc2d 593 pContext->bBoolInUse = false;
92b96797
FB
594 return STATUS_FAILURE;
595 }
596 return STATUS_PENDING;
597 }
598 else {
e269fc2d 599 pContext->bBoolInUse = false;
92b96797
FB
600 return STATUS_RESOURCES;
601 }
602}
603
604/*
605 * Description: s_nsBulkOutIoCompleteWrite
606 * 1a) Indicate to the protocol the status of the write.
607 * 1b) Return ownership of the packet to the protocol.
608 *
609 * 2) If any more packets are queue for sending, send another packet
610 * to USBD.
611 * If the attempt to send the packet to the driver fails,
612 * return ownership of the packet to the protocol and
613 * try another packet (until one succeeds).
614 *
615 * Parameters:
616 * In:
617 * pdoUsbDevObj - pointer to the USB device object which
618 * completed the irp
619 * pIrp - the irp which was completed by the
620 * device object
621 * pContext - the context given to IoSetCompletionRoutine
622 * before calling IoCallDriver on the irp
623 * The pContext is a pointer to the USB device object.
624 * Out:
625 * none
626 *
627 * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine
628 * (IofCompleteRequest) to stop working on the irp.
629 *
630 */
fe5d00eb
MP
631
632static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
92b96797 633{
fe5d00eb
MP
634 struct vnt_private *pDevice;
635 int status;
636 CONTEXT_TYPE ContextType;
637 unsigned long ulBufLen;
dcdf1d03 638 struct vnt_usb_send_context *pContext;
92b96797 639
92b96797
FB
640 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
641 //
642 // The context given to IoSetCompletionRoutine is an USB_CONTEXT struct
643 //
dcdf1d03 644 pContext = (struct vnt_usb_send_context *)urb->context;
92b96797
FB
645
646 pDevice = pContext->pDevice;
647 ContextType = pContext->Type;
648 ulBufLen = pContext->uBufLen;
649
650 if (!netif_device_present(pDevice->dev))
651 return;
652
653 //
654 // Perform various IRP, URB, and buffer 'sanity checks'
655 //
656
657 status = urb->status;
658 //we should have failed, succeeded, or cancelled, but NOT be pending
659 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_BulkOutStat, status);
660
661 if(status == STATUS_SUCCESS) {
662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Write %d bytes\n",(int)ulBufLen);
663 pDevice->ulBulkOutBytesWrite += ulBufLen;
664 pDevice->ulBulkOutContCRCError = 0;
92b96797
FB
665 } else {
666 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK Out failed %d\n", status);
667 pDevice->ulBulkOutError++;
668 }
669
670// pDevice->ulCheckForHangCount = 0;
671// pDevice->pPendingBulkOutContext = NULL;
672
673 if ( CONTEXT_DATA_PACKET == ContextType ) {
674 // Indicate to the protocol the status of the sent packet and return
675 // ownership of the packet.
676 if (pContext->pPacket != NULL) {
677 dev_kfree_skb_irq(pContext->pPacket);
678 pContext->pPacket = NULL;
679 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"tx %d bytes\n",(int)ulBufLen);
680 }
681
682 pDevice->dev->trans_start = jiffies;
683
92b96797
FB
684 if (status == STATUS_SUCCESS) {
685 pDevice->packetsSent++;
686 }
687 else {
688 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send USB error! [%08xh]\n", status);
689 pDevice->packetsSentDropped++;
690 }
691
692 }
4e9b5e2b 693 if (pDevice->bLinkPass == true) {
92b96797
FB
694 if (netif_queue_stopped(pDevice->dev))
695 netif_wake_queue(pDevice->dev);
696 }
e269fc2d 697 pContext->bBoolInUse = false;
92b96797
FB
698
699 return;
700}
This page took 0.43699 seconds and 5 git commands to generate.