Commit | Line | Data |
---|---|---|
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; |
55 | static 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 |
63 | static void s_nsInterruptUsbIoCompleteRead(struct urb *urb); |
64 | static void s_nsBulkInUsbIoCompleteRead(struct urb *urb); | |
65 | static void s_nsBulkOutIoCompleteWrite(struct urb *urb); | |
66 | static void s_nsControlInUsbIoCompleteRead(struct urb *urb); | |
92b96797 | 67 | |
fe5d00eb MP |
68 | int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest, |
69 | u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer) | |
92b96797 | 70 | { |
6487c49e | 71 | int ntStatus; |
92b96797 | 72 | |
731047f9 | 73 | if (pDevice->Flags & fMP_DISCONNECTED) |
92b96797 FB |
74 | return STATUS_FAILURE; |
75 | ||
92b96797 FB |
76 | if (in_interrupt()) { |
77 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"in_interrupt return ..byRequest %x\n", byRequest); | |
78 | return STATUS_FAILURE; | |
79 | } | |
80 | ||
c91b1869 MP |
81 | mutex_lock(&pDevice->usb_lock); |
82 | ||
92b96797 FB |
83 | ntStatus = usb_control_msg( |
84 | pDevice->usb, | |
85 | usb_sndctrlpipe(pDevice->usb , 0), | |
86 | byRequest, | |
87 | 0x40, // RequestType | |
88 | wValue, | |
89 | wIndex, | |
8611a29a | 90 | (void *) pbyBuffer, |
92b96797 FB |
91 | wLength, |
92 | HZ | |
93 | ); | |
94 | if (ntStatus >= 0) { | |
95 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe ntStatus= %d\n", ntStatus); | |
96 | ntStatus = 0; | |
97 | } else { | |
98 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe fail, ntStatus= %d\n", ntStatus); | |
99 | } | |
100 | ||
c91b1869 MP |
101 | mutex_unlock(&pDevice->usb_lock); |
102 | ||
92b96797 FB |
103 | return ntStatus; |
104 | } | |
105 | ||
fe5d00eb MP |
106 | int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue, |
107 | u16 wIndex, u16 wLength, u8 *pbyBuffer) | |
92b96797 | 108 | { |
6487c49e | 109 | int ntStatus = 0; |
92b96797 | 110 | |
7021b684 | 111 | if (pDevice->Flags & fMP_DISCONNECTED) |
e1feda13 MP |
112 | return STATUS_FAILURE; |
113 | ||
c91b1869 MP |
114 | mutex_lock(&pDevice->usb_lock); |
115 | ||
7021b684 MP |
116 | ntStatus = usb_control_msg(pDevice->usb, |
117 | usb_sndctrlpipe(pDevice->usb, 0), byRequest, 0x40, wValue, | |
118 | wIndex, pbyBuffer, wLength, USB_CTL_WAIT); | |
ae5943de | 119 | |
7021b684 | 120 | mutex_unlock(&pDevice->usb_lock); |
92b96797 | 121 | |
7021b684 | 122 | if (ntStatus < (int)wLength) |
92b96797 | 123 | return STATUS_FAILURE; |
ae5943de | 124 | |
7021b684 | 125 | return STATUS_SUCCESS; |
92b96797 FB |
126 | } |
127 | ||
fe5d00eb MP |
128 | int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue, |
129 | u16 wIndex, u16 wLength, u8 *pbyBuffer) | |
9009dd16 IM |
130 | __releases(&pDevice->lock) |
131 | __acquires(&pDevice->lock) | |
92b96797 | 132 | { |
6487c49e | 133 | int ntStatus = 0; |
fe5d00eb | 134 | int ii; |
92b96797 | 135 | |
731047f9 | 136 | if (pDevice->Flags & fMP_DISCONNECTED) |
92b96797 FB |
137 | return STATUS_FAILURE; |
138 | ||
731047f9 AM |
139 | if (pDevice->Flags & fMP_CONTROL_READS) |
140 | return STATUS_FAILURE; | |
141 | ||
e1feda13 MP |
142 | if (pDevice->pControlURB->hcpriv) |
143 | return STATUS_FAILURE; | |
ae5943de | 144 | |
c91b1869 MP |
145 | mutex_lock(&pDevice->usb_lock); |
146 | ||
ae5943de MP |
147 | MP_SET_FLAG(pDevice, fMP_CONTROL_READS); |
148 | ||
92b96797 FB |
149 | pDevice->sUsbCtlRequest.bRequestType = 0xC0; |
150 | pDevice->sUsbCtlRequest.bRequest = byRequest; | |
151 | pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue); | |
152 | pDevice->sUsbCtlRequest.wIndex = cpu_to_le16p(&wIndex); | |
153 | pDevice->sUsbCtlRequest.wLength = cpu_to_le16p(&wLength); | |
154 | pDevice->pControlURB->transfer_flags |= URB_ASYNC_UNLINK; | |
155 | pDevice->pControlURB->actual_length = 0; | |
156 | usb_fill_control_urb(pDevice->pControlURB, pDevice->usb, | |
157 | usb_rcvctrlpipe(pDevice->usb , 0), (char *) &pDevice->sUsbCtlRequest, | |
158 | pbyBuffer, wLength, s_nsControlInUsbIoCompleteRead, pDevice); | |
159 | ||
bfbfeecc JP |
160 | ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC); |
161 | if (ntStatus != 0) { | |
ae5943de MP |
162 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
163 | "control request submission failed: %d\n", ntStatus); | |
164 | MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS); | |
c91b1869 | 165 | mutex_unlock(&pDevice->usb_lock); |
ae5943de MP |
166 | return STATUS_FAILURE; |
167 | } | |
92b96797 | 168 | |
92b96797 | 169 | for (ii = 0; ii <= USB_CTL_WAIT; ii ++) { |
731047f9 AM |
170 | |
171 | if (pDevice->Flags & fMP_CONTROL_READS) | |
172 | mdelay(1); | |
173 | else | |
174 | break; | |
175 | ||
176 | if (ii >= USB_CTL_WAIT) { | |
177 | DBG_PRT(MSG_LEVEL_DEBUG, | |
178 | KERN_INFO "control rcv request submission timeout\n"); | |
92b96797 | 179 | MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS); |
c91b1869 | 180 | mutex_unlock(&pDevice->usb_lock); |
92b96797 FB |
181 | return STATUS_FAILURE; |
182 | } | |
183 | } | |
92b96797 | 184 | |
c91b1869 MP |
185 | mutex_unlock(&pDevice->usb_lock); |
186 | ||
92b96797 FB |
187 | return ntStatus; |
188 | } | |
189 | ||
92b96797 FB |
190 | /* |
191 | * Description: | |
192 | * Complete function of usb Control callback | |
193 | * | |
194 | * Parameters: | |
195 | * In: | |
196 | * pDevice - Pointer to the adapter | |
197 | * | |
198 | * Out: | |
199 | * none | |
200 | * | |
201 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver | |
202 | * | |
203 | */ | |
fe5d00eb MP |
204 | |
205 | static void s_nsControlInUsbIoCompleteRead(struct urb *urb) | |
92b96797 | 206 | { |
fe5d00eb | 207 | struct vnt_private *pDevice = (struct vnt_private *)urb->context; |
92b96797 | 208 | |
92b96797 FB |
209 | switch (urb->status) { |
210 | case 0: | |
211 | break; | |
212 | case -EINPROGRESS: | |
213 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status EINPROGRESS%d\n", urb->status); | |
214 | break; | |
215 | case -ENOENT: | |
216 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status = ENOENT %d\n", urb->status); | |
217 | break; | |
218 | default: | |
219 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ctrl read urb status %d\n", urb->status); | |
220 | } | |
221 | ||
222 | MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS); | |
223 | } | |
224 | ||
92b96797 FB |
225 | /* |
226 | * Description: | |
227 | * Allocates an usb interrupt in irp and calls USBD. | |
228 | * | |
229 | * Parameters: | |
230 | * In: | |
231 | * pDevice - Pointer to the adapter | |
232 | * Out: | |
233 | * none | |
234 | * | |
235 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver | |
236 | * | |
237 | */ | |
fe5d00eb | 238 | |
5f38b783 | 239 | int PIPEnsInterruptRead(struct vnt_private *priv) |
92b96797 | 240 | { |
5f38b783 | 241 | int status = STATUS_FAILURE; |
92b96797 | 242 | |
5f38b783 MP |
243 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
244 | "---->s_nsStartInterruptUsbRead()\n"); | |
92b96797 | 245 | |
f764e00d | 246 | if (priv->int_buf.in_use == true) |
5f38b783 MP |
247 | return STATUS_FAILURE; |
248 | ||
f764e00d | 249 | priv->int_buf.in_use = true; |
5f38b783 MP |
250 | |
251 | usb_fill_int_urb(priv->pInterruptURB, | |
252 | priv->usb, | |
b9d93d1c | 253 | usb_rcvintpipe(priv->usb, 1), |
f764e00d | 254 | priv->int_buf.data_buf, |
92b96797 FB |
255 | MAX_INTERRUPT_SIZE, |
256 | s_nsInterruptUsbIoCompleteRead, | |
5f38b783 MP |
257 | priv, |
258 | priv->int_interval); | |
92b96797 | 259 | |
5f38b783 MP |
260 | status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC); |
261 | if (status) { | |
59858f5e | 262 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
5f38b783 | 263 | "Submit int URB failed %d\n", status); |
f764e00d | 264 | priv->int_buf.in_use = false; |
59858f5e | 265 | } |
92b96797 | 266 | |
5f38b783 MP |
267 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
268 | "<----s_nsStartInterruptUsbRead Return(%x)\n", status); | |
269 | ||
270 | return status; | |
92b96797 FB |
271 | } |
272 | ||
92b96797 FB |
273 | /* |
274 | * Description: | |
275 | * Complete function of usb interrupt in irp. | |
276 | * | |
277 | * Parameters: | |
278 | * In: | |
279 | * pDevice - Pointer to the adapter | |
280 | * | |
281 | * Out: | |
282 | * none | |
283 | * | |
284 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver | |
285 | * | |
286 | */ | |
92b96797 | 287 | |
fe5d00eb | 288 | static void s_nsInterruptUsbIoCompleteRead(struct urb *urb) |
92b96797 | 289 | { |
599e4b5c | 290 | struct vnt_private *priv = urb->context; |
d9ad7a98 | 291 | int status; |
92b96797 | 292 | |
d9ad7a98 MP |
293 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
294 | "---->s_nsInterruptUsbIoCompleteRead\n"); | |
92b96797 | 295 | |
c98fbf90 MP |
296 | switch (urb->status) { |
297 | case 0: | |
298 | case -ETIMEDOUT: | |
299 | break; | |
300 | case -ECONNRESET: | |
301 | case -ENOENT: | |
302 | case -ESHUTDOWN: | |
f764e00d | 303 | priv->int_buf.in_use = false; |
c98fbf90 MP |
304 | return; |
305 | default: | |
306 | break; | |
307 | } | |
308 | ||
d9ad7a98 | 309 | status = urb->status; |
92b96797 | 310 | |
d9ad7a98 MP |
311 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
312 | "s_nsInterruptUsbIoCompleteRead Status %d\n", status); | |
92b96797 | 313 | |
d9ad7a98 | 314 | if (status != STATUS_SUCCESS) { |
f764e00d | 315 | priv->int_buf.in_use = false; |
92b96797 | 316 | |
d9ad7a98 MP |
317 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
318 | "IntUSBIoCompleteControl STATUS = %d\n", status); | |
319 | } else { | |
d9ad7a98 MP |
320 | INTnsProcessData(priv); |
321 | } | |
92b96797 | 322 | |
d9ad7a98 MP |
323 | status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC); |
324 | if (status) { | |
247b4b68 | 325 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
d9ad7a98 | 326 | "Submit int URB failed %d\n", status); |
247b4b68 | 327 | } else { |
f764e00d | 328 | priv->int_buf.in_use = true; |
247b4b68 | 329 | } |
749627f2 | 330 | |
d9ad7a98 | 331 | return; |
92b96797 FB |
332 | } |
333 | ||
334 | /* | |
335 | * Description: | |
336 | * Allocates an usb BulkIn irp and calls USBD. | |
337 | * | |
338 | * Parameters: | |
339 | * In: | |
340 | * pDevice - Pointer to the adapter | |
341 | * Out: | |
342 | * none | |
343 | * | |
344 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver | |
345 | * | |
346 | */ | |
fe5d00eb | 347 | |
0b787d71 | 348 | int PIPEnsBulkInUsbRead(struct vnt_private *priv, struct vnt_rcb *rcb) |
92b96797 | 349 | { |
0b787d71 MP |
350 | int status = 0; |
351 | struct urb *urb; | |
92b96797 | 352 | |
0b787d71 | 353 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n"); |
92b96797 | 354 | |
0b787d71 MP |
355 | if (priv->Flags & fMP_DISCONNECTED) |
356 | return STATUS_FAILURE; | |
92b96797 | 357 | |
0b787d71 MP |
358 | urb = rcb->pUrb; |
359 | if (rcb->skb == NULL) { | |
360 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rcb->skb is null\n"); | |
361 | return status; | |
362 | } | |
92b96797 | 363 | |
0b787d71 MP |
364 | usb_fill_bulk_urb(urb, |
365 | priv->usb, | |
366 | usb_rcvbulkpipe(priv->usb, 2), | |
367 | (void *) (rcb->skb->data), | |
92b96797 FB |
368 | MAX_TOTAL_SIZE_WITH_ALL_HEADERS, |
369 | s_nsBulkInUsbIoCompleteRead, | |
0b787d71 | 370 | rcb); |
92b96797 | 371 | |
0b787d71 MP |
372 | status = usb_submit_urb(urb, GFP_ATOMIC); |
373 | if (status != 0) { | |
374 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO | |
375 | "Submit Rx URB failed %d\n", status); | |
92b96797 FB |
376 | return STATUS_FAILURE ; |
377 | } | |
92b96797 | 378 | |
0b787d71 MP |
379 | rcb->Ref = 1; |
380 | rcb->bBoolInUse = true; | |
381 | ||
382 | return status; | |
92b96797 FB |
383 | } |
384 | ||
92b96797 FB |
385 | /* |
386 | * Description: | |
387 | * Complete function of usb BulkIn 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 | 399 | |
fe5d00eb | 400 | static void s_nsBulkInUsbIoCompleteRead(struct urb *urb) |
92b96797 | 401 | { |
599e4b5c | 402 | struct vnt_rcb *rcb = urb->context; |
d4fa2ab0 | 403 | struct vnt_private *priv = rcb->pDevice; |
29b02373 | 404 | unsigned long flags; |
d4fa2ab0 | 405 | int re_alloc_skb = false; |
92b96797 | 406 | |
d4fa2ab0 | 407 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n"); |
e3a8fa17 | 408 | |
67638980 MP |
409 | switch (urb->status) { |
410 | case 0: | |
67638980 MP |
411 | break; |
412 | case -ECONNRESET: | |
413 | case -ENOENT: | |
414 | case -ESHUTDOWN: | |
415 | return; | |
416 | case -ETIMEDOUT: | |
417 | default: | |
67638980 MP |
418 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
419 | "BULK In failed %d\n", urb->status); | |
420 | break; | |
421 | } | |
92b96797 | 422 | |
d4fa2ab0 | 423 | if (urb->actual_length) { |
29b02373 | 424 | spin_lock_irqsave(&priv->lock, flags); |
d4fa2ab0 MP |
425 | |
426 | if (RXbBulkInProcessData(priv, rcb, urb->actual_length) == true) | |
427 | re_alloc_skb = true; | |
428 | ||
29b02373 | 429 | spin_unlock_irqrestore(&priv->lock, flags); |
d4fa2ab0 | 430 | } |
92b96797 | 431 | |
d4fa2ab0 MP |
432 | rcb->Ref--; |
433 | if (rcb->Ref == 0) { | |
434 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d\n", | |
435 | priv->NumRecvFreeList); | |
29b02373 | 436 | spin_lock_irqsave(&priv->lock, flags); |
d4fa2ab0 MP |
437 | |
438 | RXvFreeRCB(rcb, re_alloc_skb); | |
439 | ||
29b02373 | 440 | spin_unlock_irqrestore(&priv->lock, flags); |
d4fa2ab0 MP |
441 | } |
442 | ||
443 | return; | |
92b96797 FB |
444 | } |
445 | ||
446 | /* | |
447 | * Description: | |
448 | * Allocates an usb BulkOut irp and calls USBD. | |
449 | * | |
450 | * Parameters: | |
451 | * In: | |
452 | * pDevice - Pointer to the adapter | |
453 | * Out: | |
454 | * none | |
455 | * | |
456 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver | |
457 | * | |
458 | */ | |
fe5d00eb | 459 | |
3f38290e MP |
460 | int PIPEnsSendBulkOut(struct vnt_private *priv, |
461 | struct vnt_usb_send_context *context) | |
92b96797 | 462 | { |
fe5d00eb | 463 | int status; |
3f38290e | 464 | struct urb *urb; |
92b96797 | 465 | |
3f38290e | 466 | priv->bPWBitOn = false; |
92b96797 | 467 | |
3f38290e | 468 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n"); |
92b96797 | 469 | |
3f38290e | 470 | if (!(MP_IS_READY(priv) && priv->Flags & fMP_POST_WRITES)) { |
30a05b39 | 471 | context->in_use = false; |
13338303 MP |
472 | return STATUS_RESOURCES; |
473 | } | |
92b96797 | 474 | |
30a05b39 | 475 | urb = context->urb; |
3f38290e MP |
476 | |
477 | usb_fill_bulk_urb(urb, | |
478 | priv->usb, | |
479 | usb_sndbulkpipe(priv->usb, 3), | |
30a05b39 MP |
480 | context->data, |
481 | context->buf_len, | |
da5c99fd | 482 | s_nsBulkOutIoCompleteWrite, |
3f38290e MP |
483 | context); |
484 | ||
485 | status = usb_submit_urb(urb, GFP_ATOMIC); | |
486 | if (status != 0) { | |
487 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO | |
488 | "Submit Tx URB failed %d\n", status); | |
30a05b39 | 489 | context->in_use = false; |
3f38290e MP |
490 | return STATUS_FAILURE; |
491 | } | |
492 | ||
493 | return STATUS_PENDING; | |
92b96797 FB |
494 | } |
495 | ||
496 | /* | |
497 | * Description: s_nsBulkOutIoCompleteWrite | |
498 | * 1a) Indicate to the protocol the status of the write. | |
499 | * 1b) Return ownership of the packet to the protocol. | |
500 | * | |
501 | * 2) If any more packets are queue for sending, send another packet | |
502 | * to USBD. | |
503 | * If the attempt to send the packet to the driver fails, | |
504 | * return ownership of the packet to the protocol and | |
505 | * try another packet (until one succeeds). | |
506 | * | |
507 | * Parameters: | |
508 | * In: | |
509 | * pdoUsbDevObj - pointer to the USB device object which | |
510 | * completed the irp | |
511 | * pIrp - the irp which was completed by the | |
512 | * device object | |
513 | * pContext - the context given to IoSetCompletionRoutine | |
514 | * before calling IoCallDriver on the irp | |
515 | * The pContext is a pointer to the USB device object. | |
516 | * Out: | |
517 | * none | |
518 | * | |
519 | * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine | |
520 | * (IofCompleteRequest) to stop working on the irp. | |
521 | * | |
522 | */ | |
fe5d00eb MP |
523 | |
524 | static void s_nsBulkOutIoCompleteWrite(struct urb *urb) | |
92b96797 | 525 | { |
599e4b5c | 526 | struct vnt_usb_send_context *context = urb->context; |
30a05b39 | 527 | struct vnt_private *priv = context->priv; |
1450ba62 | 528 | u8 context_type = context->type; |
92b96797 | 529 | |
21aa212c | 530 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n"); |
92b96797 | 531 | |
e8152bfb MP |
532 | switch (urb->status) { |
533 | case 0: | |
d1b2a11d | 534 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
30a05b39 | 535 | "Write %d bytes\n", context->buf_len); |
e8152bfb MP |
536 | break; |
537 | case -ECONNRESET: | |
538 | case -ENOENT: | |
539 | case -ESHUTDOWN: | |
30a05b39 | 540 | context->in_use = false; |
e8152bfb | 541 | return; |
d1b2a11d | 542 | case -ETIMEDOUT: |
e8152bfb | 543 | default: |
d1b2a11d MP |
544 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
545 | "BULK Out failed %d\n", urb->status); | |
e8152bfb MP |
546 | break; |
547 | } | |
548 | ||
21aa212c MP |
549 | if (!netif_device_present(priv->dev)) |
550 | return; | |
92b96797 | 551 | |
21aa212c | 552 | if (CONTEXT_DATA_PACKET == context_type) { |
30a05b39 MP |
553 | if (context->skb != NULL) { |
554 | dev_kfree_skb_irq(context->skb); | |
555 | context->skb = NULL; | |
21aa212c | 556 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
30a05b39 | 557 | "tx %d bytes\n", context->buf_len); |
21aa212c | 558 | } |
92b96797 | 559 | |
21aa212c | 560 | priv->dev->trans_start = jiffies; |
21aa212c | 561 | } |
92b96797 | 562 | |
21aa212c MP |
563 | if (priv->bLinkPass == true) { |
564 | if (netif_queue_stopped(priv->dev)) | |
565 | netif_wake_queue(priv->dev); | |
566 | } | |
567 | ||
30a05b39 | 568 | context->in_use = false; |
21aa212c MP |
569 | |
570 | return; | |
92b96797 | 571 | } |