blob: 1ab39587ed87786b99ebe4b89069b24500f88aa3 [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);
Forest Bond92b96792009-06-13 07:38:31 -040067
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +000068int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest,
69 u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer)
Forest Bond92b96792009-06-13 07:38:31 -040070{
Andres More6487c492010-08-02 20:51:57 -030071 int ntStatus;
Forest Bond92b96792009-06-13 07:38:31 -040072
Andres More731047f2010-08-05 22:17:20 -030073 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -040074 return STATUS_FAILURE;
75
Forest Bond92b96792009-06-13 07:38:31 -040076 if (in_interrupt()) {
77 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"in_interrupt return ..byRequest %x\n", byRequest);
78 return STATUS_FAILURE;
79 }
80
Malcolm Priestleyc91b1862014-05-15 22:49:19 +010081 mutex_lock(&pDevice->usb_lock);
82
Forest Bond92b96792009-06-13 07:38:31 -040083 ntStatus = usb_control_msg(
84 pDevice->usb,
85 usb_sndctrlpipe(pDevice->usb , 0),
86 byRequest,
87 0x40, // RequestType
88 wValue,
89 wIndex,
Andres More8611a292010-05-01 14:25:00 -030090 (void *) pbyBuffer,
Forest Bond92b96792009-06-13 07:38:31 -040091 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
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100101 mutex_unlock(&pDevice->usb_lock);
102
Forest Bond92b96792009-06-13 07:38:31 -0400103 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;
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestley7021b682014-05-15 22:49:22 +0100111 if (pDevice->Flags & fMP_DISCONNECTED)
Malcolm Priestleye1feda12013-10-14 19:44:13 +0100112 return STATUS_FAILURE;
113
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100114 mutex_lock(&pDevice->usb_lock);
115
Malcolm Priestley7021b682014-05-15 22:49:22 +0100116 ntStatus = usb_control_msg(pDevice->usb,
117 usb_sndctrlpipe(pDevice->usb, 0), byRequest, 0x40, wValue,
118 wIndex, pbyBuffer, wLength, USB_CTL_WAIT);
Forest Bond92b96792009-06-13 07:38:31 -0400119
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100120 mutex_unlock(&pDevice->usb_lock);
121
Malcolm Priestley7021b682014-05-15 22:49:22 +0100122 if (ntStatus < (int)wLength)
123 return STATUS_FAILURE;
124
125 return STATUS_SUCCESS;
Forest Bond92b96792009-06-13 07:38:31 -0400126}
127
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000128int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
129 u16 wIndex, u16 wLength, u8 *pbyBuffer)
Iulia Manda9009dd12014-03-13 01:35:40 +0200130 __releases(&pDevice->lock)
131 __acquires(&pDevice->lock)
Forest Bond92b96792009-06-13 07:38:31 -0400132{
Andres More6487c492010-08-02 20:51:57 -0300133 int ntStatus = 0;
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000134 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400135
Andres More731047f2010-08-05 22:17:20 -0300136 if (pDevice->Flags & fMP_DISCONNECTED)
Forest Bond92b96792009-06-13 07:38:31 -0400137 return STATUS_FAILURE;
138
Andres More731047f2010-08-05 22:17:20 -0300139 if (pDevice->Flags & fMP_CONTROL_READS)
140 return STATUS_FAILURE;
141
Malcolm Priestleye1feda12013-10-14 19:44:13 +0100142 if (pDevice->pControlURB->hcpriv)
143 return STATUS_FAILURE;
144
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100145 mutex_lock(&pDevice->usb_lock);
146
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000147 MP_SET_FLAG(pDevice, fMP_CONTROL_READS);
148
Forest Bond92b96792009-06-13 07:38:31 -0400149 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
Joe Perchesbfbfeec2010-03-24 22:17:06 -0700160 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
161 if (ntStatus != 0) {
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000162 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
163 "control request submission failed: %d\n", ntStatus);
164 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100165 mutex_unlock(&pDevice->usb_lock);
Malcolm Priestleyae5943d2013-01-30 20:07:29 +0000166 return STATUS_FAILURE;
167 }
Forest Bond92b96792009-06-13 07:38:31 -0400168
Forest Bond92b96792009-06-13 07:38:31 -0400169 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
Andres More731047f2010-08-05 22:17:20 -0300170
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");
Forest Bond92b96792009-06-13 07:38:31 -0400179 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100180 mutex_unlock(&pDevice->usb_lock);
Forest Bond92b96792009-06-13 07:38:31 -0400181 return STATUS_FAILURE;
182 }
183 }
Forest Bond92b96792009-06-13 07:38:31 -0400184
Malcolm Priestleyc91b1862014-05-15 22:49:19 +0100185 mutex_unlock(&pDevice->usb_lock);
186
Forest Bond92b96792009-06-13 07:38:31 -0400187 return ntStatus;
188}
189
Forest Bond92b96792009-06-13 07:38:31 -0400190/*
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 */
Forest Bond92b96792009-06-13 07:38:31 -0400204
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000205static void s_nsControlInUsbIoCompleteRead(struct urb *urb)
206{
207 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
208
Forest Bond92b96792009-06-13 07:38:31 -0400209 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
Forest Bond92b96792009-06-13 07:38:31 -0400225/*
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 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000238
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000239int PIPEnsInterruptRead(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400240{
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000241 int status = STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400242
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
244 "---->s_nsStartInterruptUsbRead()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400245
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000246 if (priv->int_buf.in_use == true)
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000247 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400248
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000249 priv->int_buf.in_use = true;
Forest Bond92b96792009-06-13 07:38:31 -0400250
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000251 usb_fill_int_urb(priv->pInterruptURB,
252 priv->usb,
Malcolm Priestleyb9d93d12014-03-16 12:34:11 +0000253 usb_rcvintpipe(priv->usb, 1),
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000254 priv->int_buf.data_buf,
Forest Bond92b96792009-06-13 07:38:31 -0400255 MAX_INTERRUPT_SIZE,
256 s_nsInterruptUsbIoCompleteRead,
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000257 priv,
258 priv->int_interval);
Forest Bond92b96792009-06-13 07:38:31 -0400259
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000260 status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC);
261 if (status) {
Malcolm Priestley59858f52014-02-19 18:36:37 +0000262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000263 "Submit int URB failed %d\n", status);
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000264 priv->int_buf.in_use = false;
Malcolm Priestley59858f52014-02-19 18:36:37 +0000265 }
Forest Bond92b96792009-06-13 07:38:31 -0400266
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
268 "<----s_nsStartInterruptUsbRead Return(%x)\n", status);
269
270 return status;
Forest Bond92b96792009-06-13 07:38:31 -0400271}
272
Forest Bond92b96792009-06-13 07:38:31 -0400273/*
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 */
Forest Bond92b96792009-06-13 07:38:31 -0400287
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000288static void s_nsInterruptUsbIoCompleteRead(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400289{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000290 struct vnt_private *priv = urb->context;
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000291 int status;
Forest Bond92b96792009-06-13 07:38:31 -0400292
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000293 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
294 "---->s_nsInterruptUsbIoCompleteRead\n");
Forest Bond92b96792009-06-13 07:38:31 -0400295
Malcolm Priestleyc98fbf92014-02-17 21:16:20 +0000296 switch (urb->status) {
297 case 0:
298 case -ETIMEDOUT:
299 break;
300 case -ECONNRESET:
301 case -ENOENT:
302 case -ESHUTDOWN:
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000303 priv->int_buf.in_use = false;
Malcolm Priestleyc98fbf92014-02-17 21:16:20 +0000304 return;
305 default:
306 break;
307 }
308
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000309 status = urb->status;
Forest Bond92b96792009-06-13 07:38:31 -0400310
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000311 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
312 "s_nsInterruptUsbIoCompleteRead Status %d\n", status);
Forest Bond92b96792009-06-13 07:38:31 -0400313
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000314 if (status != STATUS_SUCCESS) {
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000315 priv->int_buf.in_use = false;
Forest Bond92b96792009-06-13 07:38:31 -0400316
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000317 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000318 "IntUSBIoCompleteControl STATUS = %d\n", status);
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000319 } else {
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000320 INTnsProcessData(priv);
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000321 }
Malcolm Priestley749627f2014-02-17 21:24:33 +0000322
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000323 status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC);
324 if (status) {
325 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
326 "Submit int URB failed %d\n", status);
327 } else {
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000328 priv->int_buf.in_use = true;
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000329 }
330
331 return;
Forest Bond92b96792009-06-13 07:38:31 -0400332}
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 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000347
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000348int PIPEnsBulkInUsbRead(struct vnt_private *priv, struct vnt_rcb *rcb)
Forest Bond92b96792009-06-13 07:38:31 -0400349{
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000350 int status = 0;
351 struct urb *urb;
Forest Bond92b96792009-06-13 07:38:31 -0400352
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
Forest Bond92b96792009-06-13 07:38:31 -0400354
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000355 if (priv->Flags & fMP_DISCONNECTED)
356 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400357
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000358 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 }
Forest Bond92b96792009-06-13 07:38:31 -0400363
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000364 usb_fill_bulk_urb(urb,
365 priv->usb,
366 usb_rcvbulkpipe(priv->usb, 2),
367 (void *) (rcb->skb->data),
Forest Bond92b96792009-06-13 07:38:31 -0400368 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
369 s_nsBulkInUsbIoCompleteRead,
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000370 rcb);
Forest Bond92b96792009-06-13 07:38:31 -0400371
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000372 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);
Forest Bond92b96792009-06-13 07:38:31 -0400376 return STATUS_FAILURE ;
377 }
Forest Bond92b96792009-06-13 07:38:31 -0400378
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000379 rcb->Ref = 1;
380 rcb->bBoolInUse = true;
381
382 return status;
Forest Bond92b96792009-06-13 07:38:31 -0400383}
384
Forest Bond92b96792009-06-13 07:38:31 -0400385/*
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 */
Forest Bond92b96792009-06-13 07:38:31 -0400399
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000400static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400401{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000402 struct vnt_rcb *rcb = urb->context;
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000403 struct vnt_private *priv = rcb->pDevice;
Malcolm Priestley29b02372014-05-15 22:49:20 +0100404 unsigned long flags;
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000405 int re_alloc_skb = false;
Forest Bond92b96792009-06-13 07:38:31 -0400406
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000407 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
Malcolm Priestleye3a8fa12014-02-25 20:51:46 +0000408
Malcolm Priestley67638982014-02-25 20:51:48 +0000409 switch (urb->status) {
410 case 0:
Malcolm Priestley67638982014-02-25 20:51:48 +0000411 break;
412 case -ECONNRESET:
413 case -ENOENT:
414 case -ESHUTDOWN:
415 return;
416 case -ETIMEDOUT:
417 default:
Malcolm Priestley67638982014-02-25 20:51:48 +0000418 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
419 "BULK In failed %d\n", urb->status);
420 break;
421 }
Forest Bond92b96792009-06-13 07:38:31 -0400422
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000423 if (urb->actual_length) {
Malcolm Priestley29b02372014-05-15 22:49:20 +0100424 spin_lock_irqsave(&priv->lock, flags);
Forest Bond92b96792009-06-13 07:38:31 -0400425
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000426 if (RXbBulkInProcessData(priv, rcb, urb->actual_length) == true)
427 re_alloc_skb = true;
428
Malcolm Priestley29b02372014-05-15 22:49:20 +0100429 spin_unlock_irqrestore(&priv->lock, flags);
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000430 }
431
432 rcb->Ref--;
433 if (rcb->Ref == 0) {
434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d\n",
435 priv->NumRecvFreeList);
Malcolm Priestley29b02372014-05-15 22:49:20 +0100436 spin_lock_irqsave(&priv->lock, flags);
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000437
438 RXvFreeRCB(rcb, re_alloc_skb);
439
Malcolm Priestley29b02372014-05-15 22:49:20 +0100440 spin_unlock_irqrestore(&priv->lock, flags);
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000441 }
442
443 return;
Forest Bond92b96792009-06-13 07:38:31 -0400444}
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 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000459
Malcolm Priestley3f382902014-02-25 20:51:45 +0000460int PIPEnsSendBulkOut(struct vnt_private *priv,
461 struct vnt_usb_send_context *context)
Forest Bond92b96792009-06-13 07:38:31 -0400462{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000463 int status;
Malcolm Priestley3f382902014-02-25 20:51:45 +0000464 struct urb *urb;
Forest Bond92b96792009-06-13 07:38:31 -0400465
Malcolm Priestley3f382902014-02-25 20:51:45 +0000466 priv->bPWBitOn = false;
Forest Bond92b96792009-06-13 07:38:31 -0400467
Malcolm Priestley3f382902014-02-25 20:51:45 +0000468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n");
Forest Bond92b96792009-06-13 07:38:31 -0400469
Malcolm Priestley3f382902014-02-25 20:51:45 +0000470 if (!(MP_IS_READY(priv) && priv->Flags & fMP_POST_WRITES)) {
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100471 context->in_use = false;
Malcolm Priestley13338302014-02-25 20:51:43 +0000472 return STATUS_RESOURCES;
473 }
Forest Bond92b96792009-06-13 07:38:31 -0400474
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100475 urb = context->urb;
Forest Bond92b96792009-06-13 07:38:31 -0400476
Malcolm Priestley3f382902014-02-25 20:51:45 +0000477 usb_fill_bulk_urb(urb,
478 priv->usb,
479 usb_sndbulkpipe(priv->usb, 3),
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100480 context->data,
481 context->buf_len,
Malcolm Priestley3f382902014-02-25 20:51:45 +0000482 s_nsBulkOutIoCompleteWrite,
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);
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100489 context->in_use = false;
Malcolm Priestley3f382902014-02-25 20:51:45 +0000490 return STATUS_FAILURE;
491 }
492
493 return STATUS_PENDING;
Forest Bond92b96792009-06-13 07:38:31 -0400494}
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 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000523
524static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400525{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000526 struct vnt_usb_send_context *context = urb->context;
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100527 struct vnt_private *priv = context->priv;
Malcolm Priestley1450ba62014-02-19 21:56:33 +0000528 u8 context_type = context->type;
Forest Bond92b96792009-06-13 07:38:31 -0400529
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000530 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
Forest Bond92b96792009-06-13 07:38:31 -0400531
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000532 switch (urb->status) {
533 case 0:
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000534 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100535 "Write %d bytes\n", context->buf_len);
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000536 break;
537 case -ECONNRESET:
538 case -ENOENT:
539 case -ESHUTDOWN:
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100540 context->in_use = false;
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000541 return;
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000542 case -ETIMEDOUT:
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000543 default:
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
545 "BULK Out failed %d\n", urb->status);
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000546 break;
547 }
548
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000549 if (!netif_device_present(priv->dev))
550 return;
Forest Bond92b96792009-06-13 07:38:31 -0400551
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000552 if (CONTEXT_DATA_PACKET == context_type) {
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100553 if (context->skb != NULL) {
554 dev_kfree_skb_irq(context->skb);
555 context->skb = NULL;
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000556 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100557 "tx %d bytes\n", context->buf_len);
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000558 }
Forest Bond92b96792009-06-13 07:38:31 -0400559
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000560 priv->dev->trans_start = jiffies;
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000561 }
Forest Bond92b96792009-06-13 07:38:31 -0400562
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000563 if (priv->bLinkPass == true) {
564 if (netif_queue_stopped(priv->dev))
565 netif_wake_queue(priv->dev);
566 }
567
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100568 context->in_use = false;
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000569
570 return;
Forest Bond92b96792009-06-13 07:38:31 -0400571}