blob: 258eec13b8dfdebe583f8ba156d7867311408f5e [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
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
Forest Bond92b96792009-06-13 07:38:31 -040041#include "int.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040043#include "dpc.h"
Forest Bond92b96792009-06-13 07:38:31 -040044#include "control.h"
Forest Bond92b96792009-06-13 07:38:31 -040045#include "desc.h"
Forest Bond92b96792009-06-13 07:38:31 -040046#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040047
Forest Bond92b96792009-06-13 07:38:31 -040048//endpoint def
49//endpoint 0: control
50//endpoint 1: interrupt
51//endpoint 2: read bulk
52//endpoint 3: write bulk
53
Forest Bond92b96792009-06-13 07:38:31 -040054//static int msglevel =MSG_LEVEL_DEBUG;
55static int msglevel =MSG_LEVEL_INFO;
56
Forest Bond92b96792009-06-13 07:38:31 -040057#define USB_CTL_WAIT 500 //ms
58
59#ifndef URB_ASYNC_UNLINK
60#define URB_ASYNC_UNLINK 0
61#endif
62
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +000063static 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);
Forest Bond92b96792009-06-13 07:38:31 -040068
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +000069int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest,
70 u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer)
Forest Bond92b96792009-06-13 07:38:31 -040071{
Andres More6487c492010-08-02 20:51:57 -030072 int ntStatus;
Forest Bond92b96792009-06-13 07:38:31 -040073
Andres More731047f2010-08-05 22:17:20 -030074 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -040075 return STATUS_FAILURE;
76
Andres More731047f2010-08-05 22:17:20 -030077 if (pDevice->Flags & fMP_CONTROL_WRITES)
Forest Bond92b96792009-06-13 07:38:31 -040078 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -040079
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,
Andres More8611a292010-05-01 14:25:00 -030092 (void *) pbyBuffer,
Forest Bond92b96792009-06-13 07:38:31 -040093 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
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000106int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
107 u16 wIndex, u16 wLength, u8 *pbyBuffer)
Forest Bond92b96792009-06-13 07:38:31 -0400108{
Andres More6487c492010-08-02 20:51:57 -0300109 int ntStatus = 0;
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000110 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400111
Andres More731047f2010-08-05 22:17:20 -0300112 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -0400113 return STATUS_FAILURE;
114
Andres More731047f2010-08-05 22:17:20 -0300115 if (pDevice->Flags & fMP_CONTROL_WRITES)
Forest Bond92b96792009-06-13 07:38:31 -0400116 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000118 if (pDevice->Flags & fMP_CONTROL_READS)
119 return STATUS_FAILURE;
120
Malcolm Priestleye1feda12013-10-14 19:44:13 +0100121 if (pDevice->pControlURB->hcpriv)
122 return STATUS_FAILURE;
123
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000124 MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES);
125
Forest Bond92b96792009-06-13 07:38:31 -0400126 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
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700138 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
139 if (ntStatus != 0) {
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000140 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);
Forest Bond92b96792009-06-13 07:38:31 -0400144 return STATUS_FAILURE;
145 }
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000146
Forest Bond92b96792009-06-13 07:38:31 -0400147 spin_unlock_irq(&pDevice->lock);
148 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
Andres More731047f2010-08-05 22:17:20 -0300149
150 if (pDevice->Flags & fMP_CONTROL_WRITES)
151 mdelay(1);
Forest Bond92b96792009-06-13 07:38:31 -0400152 else
Andres More731047f2010-08-05 22:17:20 -0300153 break;
154
Forest Bond92b96792009-06-13 07:38:31 -0400155 if (ii >= USB_CTL_WAIT) {
Andres More731047f2010-08-05 22:17:20 -0300156 DBG_PRT(MSG_LEVEL_DEBUG,
157 KERN_INFO "control send request submission timeout\n");
Forest Bond92b96792009-06-13 07:38:31 -0400158 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
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000168int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
169 u16 wIndex, u16 wLength, u8 *pbyBuffer)
Forest Bond92b96792009-06-13 07:38:31 -0400170{
Andres More6487c492010-08-02 20:51:57 -0300171 int ntStatus = 0;
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000172 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400173
Andres More731047f2010-08-05 22:17:20 -0300174 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -0400175 return STATUS_FAILURE;
176
Andres More731047f2010-08-05 22:17:20 -0300177 if (pDevice->Flags & fMP_CONTROL_READS)
178 return STATUS_FAILURE;
179
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000180 if (pDevice->Flags & fMP_CONTROL_WRITES)
181 return STATUS_FAILURE;
182
Malcolm Priestleye1feda12013-10-14 19:44:13 +0100183 if (pDevice->pControlURB->hcpriv)
184 return STATUS_FAILURE;
185
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000186 MP_SET_FLAG(pDevice, fMP_CONTROL_READS);
187
Forest Bond92b96792009-06-13 07:38:31 -0400188 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
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700199 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
200 if (ntStatus != 0) {
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000201 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 }
Forest Bond92b96792009-06-13 07:38:31 -0400206
207 spin_unlock_irq(&pDevice->lock);
208 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
Andres More731047f2010-08-05 22:17:20 -0300209
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");
Forest Bond92b96792009-06-13 07:38:31 -0400218 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
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000228static void s_nsControlInUsbIoCompleteWrite(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400229{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000230 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
Forest Bond92b96792009-06-13 07:38:31 -0400231
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
Forest Bond92b96792009-06-13 07:38:31 -0400249/*
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 */
Forest Bond92b96792009-06-13 07:38:31 -0400263
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000264static void s_nsControlInUsbIoCompleteRead(struct urb *urb)
265{
266 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
267
Forest Bond92b96792009-06-13 07:38:31 -0400268 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
Forest Bond92b96792009-06-13 07:38:31 -0400284/*
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 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000297
298int PIPEnsInterruptRead(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400299{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000300 int ntStatus = STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400301
302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartInterruptUsbRead()\n");
303
Andres More4e9b5e22013-02-12 20:36:30 -0500304 if(pDevice->intBuf.bInUse == true){
Forest Bond92b96792009-06-13 07:38:31 -0400305 return (STATUS_FAILURE);
306 }
Andres More4e9b5e22013-02-12 20:36:30 -0500307 pDevice->intBuf.bInUse = true;
Andres Moree269fc22013-02-12 20:36:29 -0500308// pDevice->bEventAvailable = false;
Forest Bond92b96792009-06-13 07:38:31 -0400309 pDevice->ulIntInPosted++;
310
311 //
312 // Now that we have created the urb, we will send a
313 // request to the USB device object.
314 //
Forest Bond92b96792009-06-13 07:38:31 -0400315 pDevice->pInterruptURB->interval = pDevice->int_interval;
Forest Bond92b96792009-06-13 07:38:31 -0400316
317usb_fill_bulk_urb(pDevice->pInterruptURB,
318 pDevice->usb,
319 usb_rcvbulkpipe(pDevice->usb, 1),
Andres More8611a292010-05-01 14:25:00 -0300320 (void *) pDevice->intBuf.pDataBuf,
Forest Bond92b96792009-06-13 07:38:31 -0400321 MAX_INTERRUPT_SIZE,
322 s_nsInterruptUsbIoCompleteRead,
323 pDevice);
Forest Bond92b96792009-06-13 07:38:31 -0400324
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700325 ntStatus = usb_submit_urb(pDevice->pInterruptURB, GFP_ATOMIC);
326 if (ntStatus != 0) {
Forest Bond92b96792009-06-13 07:38:31 -0400327 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit int URB failed %d\n", ntStatus);
328 }
329
Forest Bond92b96792009-06-13 07:38:31 -0400330 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----s_nsStartInterruptUsbRead Return(%x)\n",ntStatus);
331 return ntStatus;
332}
333
Forest Bond92b96792009-06-13 07:38:31 -0400334/*
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 */
Forest Bond92b96792009-06-13 07:38:31 -0400348
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000349static void s_nsInterruptUsbIoCompleteRead(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400350{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000351 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
352 int ntStatus;
Forest Bond92b96792009-06-13 07:38:31 -0400353
354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptUsbIoCompleteRead\n");
355 //
356 // The context given to IoSetCompletionRoutine is the receive buffer object
357 //
Forest Bond92b96792009-06-13 07:38:31 -0400358
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++;
Andres Moree269fc22013-02-12 20:36:29 -0500375 pDevice->intBuf.bInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -0400376
377// if (ntStatus == USBD_STATUS_CRC) {
378// pDevice->ulIntInContCRCError++;
379// }
380
381// if (ntStatus == STATUS_NOT_CONNECTED )
382// {
Andres More4e9b5e22013-02-12 20:36:30 -0500383 pDevice->fKillEventPollingThread = true;
Forest Bond92b96792009-06-13 07:38:31 -0400384// }
385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"IntUSBIoCompleteControl STATUS = %d\n", ntStatus );
Andres Morecc856e62010-05-17 21:34:01 -0300386 } else {
387 pDevice->ulIntInBytesRead += (unsigned long) urb->actual_length;
388 pDevice->ulIntInContCRCError = 0;
Andres More4e9b5e22013-02-12 20:36:30 -0500389 pDevice->bEventAvailable = true;
Andres Morecc856e62010-05-17 21:34:01 -0300390 INTnsProcessData(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -0400391 }
392
Andres More4e9b5e22013-02-12 20:36:30 -0500393 if (pDevice->fKillEventPollingThread != true) {
Forest Bond92b96792009-06-13 07:38:31 -0400394 usb_fill_bulk_urb(pDevice->pInterruptURB,
395 pDevice->usb,
396 usb_rcvbulkpipe(pDevice->usb, 1),
Andres More8611a292010-05-01 14:25:00 -0300397 (void *) pDevice->intBuf.pDataBuf,
Forest Bond92b96792009-06-13 07:38:31 -0400398 MAX_INTERRUPT_SIZE,
399 s_nsInterruptUsbIoCompleteRead,
400 pDevice);
401
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700402 ntStatus = usb_submit_urb(pDevice->pInterruptURB, GFP_ATOMIC);
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000403 if (ntStatus) {
404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
405 "Submit int URB failed %d\n", ntStatus);
406 } else {
407 pDevice->intBuf.bInUse = true;
408 }
Forest Bond92b96792009-06-13 07:38:31 -0400409 }
410 //
411 // We return STATUS_MORE_PROCESSING_REQUIRED so that the completion
412 // routine (IofCompleteRequest) will stop working on the irp.
413 //
414 return ;
415}
416
417/*
418 * Description:
419 * Allocates an usb BulkIn irp and calls USBD.
420 *
421 * Parameters:
422 * In:
423 * pDevice - Pointer to the adapter
424 * Out:
425 * none
426 *
427 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
428 *
429 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000430
Malcolm Priestley115cac22013-08-28 21:12:35 +0100431int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, struct vnt_rcb *pRCB)
Forest Bond92b96792009-06-13 07:38:31 -0400432{
Andres More6487c492010-08-02 20:51:57 -0300433 int ntStatus = 0;
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000434 struct urb *pUrb;
Forest Bond92b96792009-06-13 07:38:31 -0400435
Forest Bond92b96792009-06-13 07:38:31 -0400436 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
437
Andres More731047f2010-08-05 22:17:20 -0300438 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -0400439 return STATUS_FAILURE;
440
441 pDevice->ulBulkInPosted++;
442
Forest Bond92b96792009-06-13 07:38:31 -0400443 pUrb = pRCB->pUrb;
444 //
445 // Now that we have created the urb, we will send a
446 // request to the USB device object.
447 //
448 if (pRCB->skb == NULL) {
449 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pRCB->skb is null \n");
450 return ntStatus;
451 }
452
453 usb_fill_bulk_urb(pUrb,
454 pDevice->usb,
455 usb_rcvbulkpipe(pDevice->usb, 2),
Andres More8611a292010-05-01 14:25:00 -0300456 (void *) (pRCB->skb->data),
Forest Bond92b96792009-06-13 07:38:31 -0400457 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
458 s_nsBulkInUsbIoCompleteRead,
459 pRCB);
460
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700461 ntStatus = usb_submit_urb(pUrb, GFP_ATOMIC);
462 if (ntStatus != 0) {
Forest Bond92b96792009-06-13 07:38:31 -0400463 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Rx URB failed %d\n", ntStatus);
464 return STATUS_FAILURE ;
465 }
466 pRCB->Ref = 1;
Andres More4e9b5e22013-02-12 20:36:30 -0500467 pRCB->bBoolInUse= true;
Forest Bond92b96792009-06-13 07:38:31 -0400468
469 return ntStatus;
470}
471
Forest Bond92b96792009-06-13 07:38:31 -0400472/*
473 * Description:
474 * Complete function of usb BulkIn irp.
475 *
476 * Parameters:
477 * In:
478 * pDevice - Pointer to the adapter
479 *
480 * Out:
481 * none
482 *
483 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
484 *
485 */
Forest Bond92b96792009-06-13 07:38:31 -0400486
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000487static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400488{
Malcolm Priestley115cac22013-08-28 21:12:35 +0100489 struct vnt_rcb *pRCB = (struct vnt_rcb *)urb->context;
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000490 struct vnt_private *pDevice = pRCB->pDevice;
491 unsigned long bytesRead;
Andres Moree269fc22013-02-12 20:36:29 -0500492 int bIndicateReceive = false;
493 int bReAllocSkb = false;
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000494 int status;
Forest Bond92b96792009-06-13 07:38:31 -0400495
496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
497 status = urb->status;
498 bytesRead = urb->actual_length;
499
500 if (status) {
501 pDevice->ulBulkInError++;
502 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK In failed %d\n", status);
Forest Bond92b96792009-06-13 07:38:31 -0400503//todo...xxxxxx
504// if (status == USBD_STATUS_CRC) {
505// pDevice->ulBulkInContCRCError++;
506// }
507// if (status == STATUS_DEVICE_NOT_CONNECTED )
508// {
509// MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
510// }
511 } else {
Malcolm Priestley87c62982012-11-04 16:18:56 +0000512 if (bytesRead)
Andres More4e9b5e22013-02-12 20:36:30 -0500513 bIndicateReceive = true;
Forest Bond92b96792009-06-13 07:38:31 -0400514 pDevice->ulBulkInContCRCError = 0;
515 pDevice->ulBulkInBytesRead += bytesRead;
Forest Bond92b96792009-06-13 07:38:31 -0400516 }
517
Forest Bond92b96792009-06-13 07:38:31 -0400518 if (bIndicateReceive) {
519 spin_lock(&pDevice->lock);
Andres More4e9b5e22013-02-12 20:36:30 -0500520 if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == true)
521 bReAllocSkb = true;
Forest Bond92b96792009-06-13 07:38:31 -0400522 spin_unlock(&pDevice->lock);
523 }
524 pRCB->Ref--;
525 if (pRCB->Ref == 0)
526 {
527 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d \n",pDevice->NumRecvFreeList);
528 spin_lock(&pDevice->lock);
529 RXvFreeRCB(pRCB, bReAllocSkb);
530 spin_unlock(&pDevice->lock);
531 }
532
Forest Bond92b96792009-06-13 07:38:31 -0400533 return;
534}
535
536/*
537 * Description:
538 * Allocates an usb BulkOut irp and calls USBD.
539 *
540 * Parameters:
541 * In:
542 * pDevice - Pointer to the adapter
543 * Out:
544 * none
545 *
546 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
547 *
548 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000549
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100550int PIPEnsSendBulkOut(struct vnt_private *pDevice,
551 struct vnt_usb_send_context *pContext)
Forest Bond92b96792009-06-13 07:38:31 -0400552{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000553 int status;
554 struct urb *pUrb;
Forest Bond92b96792009-06-13 07:38:31 -0400555
Andres Moree269fc22013-02-12 20:36:29 -0500556 pDevice->bPWBitOn = false;
Forest Bond92b96792009-06-13 07:38:31 -0400557
558/*
559 if (pDevice->pPendingBulkOutContext != NULL) {
560 pDevice->NumContextsQueued++;
561 EnqueueContext(pDevice->FirstTxContextQueue, pDevice->LastTxContextQueue, pContext);
562 status = STATUS_PENDING;
563 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send pending!\n");
564 return status;
565 }
566*/
567
568 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n");
569
Andres More731047f2010-08-05 22:17:20 -0300570 if (MP_IS_READY(pDevice) && (pDevice->Flags & fMP_POST_WRITES)) {
Forest Bond92b96792009-06-13 07:38:31 -0400571
572 pUrb = pContext->pUrb;
573 pDevice->ulBulkOutPosted++;
574// pDevice->pPendingBulkOutContext = pContext;
575 usb_fill_bulk_urb(
576 pUrb,
577 pDevice->usb,
Andres More8611a292010-05-01 14:25:00 -0300578 usb_sndbulkpipe(pDevice->usb, 3),
579 (void *) &(pContext->Data[0]),
Forest Bond92b96792009-06-13 07:38:31 -0400580 pContext->uBufLen,
581 s_nsBulkOutIoCompleteWrite,
582 pContext);
583
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700584 status = usb_submit_urb(pUrb, GFP_ATOMIC);
585 if (status != 0)
Forest Bond92b96792009-06-13 07:38:31 -0400586 {
587 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Tx URB failed %d\n", status);
Andres Moree269fc22013-02-12 20:36:29 -0500588 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -0400589 return STATUS_FAILURE;
590 }
591 return STATUS_PENDING;
592 }
593 else {
Andres Moree269fc22013-02-12 20:36:29 -0500594 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -0400595 return STATUS_RESOURCES;
596 }
597}
598
599/*
600 * Description: s_nsBulkOutIoCompleteWrite
601 * 1a) Indicate to the protocol the status of the write.
602 * 1b) Return ownership of the packet to the protocol.
603 *
604 * 2) If any more packets are queue for sending, send another packet
605 * to USBD.
606 * If the attempt to send the packet to the driver fails,
607 * return ownership of the packet to the protocol and
608 * try another packet (until one succeeds).
609 *
610 * Parameters:
611 * In:
612 * pdoUsbDevObj - pointer to the USB device object which
613 * completed the irp
614 * pIrp - the irp which was completed by the
615 * device object
616 * pContext - the context given to IoSetCompletionRoutine
617 * before calling IoCallDriver on the irp
618 * The pContext is a pointer to the USB device object.
619 * Out:
620 * none
621 *
622 * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine
623 * (IofCompleteRequest) to stop working on the irp.
624 *
625 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000626
627static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400628{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000629 struct vnt_private *pDevice;
630 int status;
631 CONTEXT_TYPE ContextType;
632 unsigned long ulBufLen;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100633 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -0400634
Forest Bond92b96792009-06-13 07:38:31 -0400635 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
636 //
637 // The context given to IoSetCompletionRoutine is an USB_CONTEXT struct
638 //
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100639 pContext = (struct vnt_usb_send_context *)urb->context;
Forest Bond92b96792009-06-13 07:38:31 -0400640
641 pDevice = pContext->pDevice;
642 ContextType = pContext->Type;
643 ulBufLen = pContext->uBufLen;
644
645 if (!netif_device_present(pDevice->dev))
646 return;
647
648 //
649 // Perform various IRP, URB, and buffer 'sanity checks'
650 //
651
652 status = urb->status;
Forest Bond92b96792009-06-13 07:38:31 -0400653
654 if(status == STATUS_SUCCESS) {
655 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Write %d bytes\n",(int)ulBufLen);
656 pDevice->ulBulkOutBytesWrite += ulBufLen;
657 pDevice->ulBulkOutContCRCError = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400658 } else {
659 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BULK Out failed %d\n", status);
660 pDevice->ulBulkOutError++;
661 }
662
663// pDevice->ulCheckForHangCount = 0;
664// pDevice->pPendingBulkOutContext = NULL;
665
666 if ( CONTEXT_DATA_PACKET == ContextType ) {
667 // Indicate to the protocol the status of the sent packet and return
668 // ownership of the packet.
669 if (pContext->pPacket != NULL) {
670 dev_kfree_skb_irq(pContext->pPacket);
671 pContext->pPacket = NULL;
672 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"tx %d bytes\n",(int)ulBufLen);
673 }
674
675 pDevice->dev->trans_start = jiffies;
676
Forest Bond92b96792009-06-13 07:38:31 -0400677 if (status == STATUS_SUCCESS) {
678 pDevice->packetsSent++;
679 }
680 else {
681 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send USB error! [%08xh]\n", status);
682 pDevice->packetsSentDropped++;
683 }
684
685 }
Andres More4e9b5e22013-02-12 20:36:30 -0500686 if (pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -0400687 if (netif_queue_stopped(pDevice->dev))
688 netif_wake_queue(pDevice->dev);
689 }
Andres Moree269fc22013-02-12 20:36:29 -0500690 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -0400691
692 return;
693}