blob: a4a4bf24aad6f3b98dfb73d88b2219c1940a0107 [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
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000298int PIPEnsInterruptRead(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400299{
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000300 int status = STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400301
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
303 "---->s_nsStartInterruptUsbRead()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400304
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000305 if (priv->int_buf.in_use == true)
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000306 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400307
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000308 priv->int_buf.in_use = true;
Forest Bond92b96792009-06-13 07:38:31 -0400309
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000310 usb_fill_int_urb(priv->pInterruptURB,
311 priv->usb,
312 usb_rcvbulkpipe(priv->usb, 1),
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000313 priv->int_buf.data_buf,
Forest Bond92b96792009-06-13 07:38:31 -0400314 MAX_INTERRUPT_SIZE,
315 s_nsInterruptUsbIoCompleteRead,
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000316 priv,
317 priv->int_interval);
Forest Bond92b96792009-06-13 07:38:31 -0400318
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000319 status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC);
320 if (status) {
Malcolm Priestley59858f52014-02-19 18:36:37 +0000321 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000322 "Submit int URB failed %d\n", status);
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000323 priv->int_buf.in_use = false;
Malcolm Priestley59858f52014-02-19 18:36:37 +0000324 }
Forest Bond92b96792009-06-13 07:38:31 -0400325
Malcolm Priestley5f38b782014-02-19 18:37:32 +0000326 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
327 "<----s_nsStartInterruptUsbRead Return(%x)\n", status);
328
329 return status;
Forest Bond92b96792009-06-13 07:38:31 -0400330}
331
Forest Bond92b96792009-06-13 07:38:31 -0400332/*
333 * Description:
334 * Complete function of usb interrupt in irp.
335 *
336 * Parameters:
337 * In:
338 * pDevice - Pointer to the adapter
339 *
340 * Out:
341 * none
342 *
343 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
344 *
345 */
Forest Bond92b96792009-06-13 07:38:31 -0400346
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000347static void s_nsInterruptUsbIoCompleteRead(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400348{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000349 struct vnt_private *priv = urb->context;
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000350 int status;
Forest Bond92b96792009-06-13 07:38:31 -0400351
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000352 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
353 "---->s_nsInterruptUsbIoCompleteRead\n");
Forest Bond92b96792009-06-13 07:38:31 -0400354
Malcolm Priestleyc98fbf92014-02-17 21:16:20 +0000355 switch (urb->status) {
356 case 0:
357 case -ETIMEDOUT:
358 break;
359 case -ECONNRESET:
360 case -ENOENT:
361 case -ESHUTDOWN:
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000362 priv->int_buf.in_use = false;
Malcolm Priestleyc98fbf92014-02-17 21:16:20 +0000363 return;
364 default:
365 break;
366 }
367
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000368 status = urb->status;
Forest Bond92b96792009-06-13 07:38:31 -0400369
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
371 "s_nsInterruptUsbIoCompleteRead Status %d\n", status);
Forest Bond92b96792009-06-13 07:38:31 -0400372
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000373 if (status != STATUS_SUCCESS) {
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000374 priv->int_buf.in_use = false;
Forest Bond92b96792009-06-13 07:38:31 -0400375
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000377 "IntUSBIoCompleteControl STATUS = %d\n", status);
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000378 } else {
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000379 INTnsProcessData(priv);
Malcolm Priestley247b4b62014-02-17 21:12:51 +0000380 }
Malcolm Priestley749627f2014-02-17 21:24:33 +0000381
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000382 status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC);
383 if (status) {
384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
385 "Submit int URB failed %d\n", status);
386 } else {
Malcolm Priestleyf764e002014-02-19 18:39:09 +0000387 priv->int_buf.in_use = true;
Malcolm Priestleyd9ad7a92014-02-17 21:27:30 +0000388 }
389
390 return;
Forest Bond92b96792009-06-13 07:38:31 -0400391}
392
393/*
394 * Description:
395 * Allocates an usb BulkIn irp and calls USBD.
396 *
397 * Parameters:
398 * In:
399 * pDevice - Pointer to the adapter
400 * Out:
401 * none
402 *
403 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
404 *
405 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000406
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000407int PIPEnsBulkInUsbRead(struct vnt_private *priv, struct vnt_rcb *rcb)
Forest Bond92b96792009-06-13 07:38:31 -0400408{
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000409 int status = 0;
410 struct urb *urb;
Forest Bond92b96792009-06-13 07:38:31 -0400411
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000412 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
Forest Bond92b96792009-06-13 07:38:31 -0400413
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000414 if (priv->Flags & fMP_DISCONNECTED)
415 return STATUS_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -0400416
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000417 urb = rcb->pUrb;
418 if (rcb->skb == NULL) {
419 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rcb->skb is null\n");
420 return status;
421 }
Forest Bond92b96792009-06-13 07:38:31 -0400422
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000423 usb_fill_bulk_urb(urb,
424 priv->usb,
425 usb_rcvbulkpipe(priv->usb, 2),
426 (void *) (rcb->skb->data),
Forest Bond92b96792009-06-13 07:38:31 -0400427 MAX_TOTAL_SIZE_WITH_ALL_HEADERS,
428 s_nsBulkInUsbIoCompleteRead,
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000429 rcb);
Forest Bond92b96792009-06-13 07:38:31 -0400430
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000431 status = usb_submit_urb(urb, GFP_ATOMIC);
432 if (status != 0) {
433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
434 "Submit Rx URB failed %d\n", status);
Forest Bond92b96792009-06-13 07:38:31 -0400435 return STATUS_FAILURE ;
436 }
Forest Bond92b96792009-06-13 07:38:31 -0400437
Malcolm Priestley0b787d72014-02-25 20:51:50 +0000438 rcb->Ref = 1;
439 rcb->bBoolInUse = true;
440
441 return status;
Forest Bond92b96792009-06-13 07:38:31 -0400442}
443
Forest Bond92b96792009-06-13 07:38:31 -0400444/*
445 * Description:
446 * Complete function of usb BulkIn irp.
447 *
448 * Parameters:
449 * In:
450 * pDevice - Pointer to the adapter
451 *
452 * Out:
453 * none
454 *
455 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
456 *
457 */
Forest Bond92b96792009-06-13 07:38:31 -0400458
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000459static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400460{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000461 struct vnt_rcb *rcb = urb->context;
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000462 struct vnt_private *priv = rcb->pDevice;
463 int re_alloc_skb = false;
Forest Bond92b96792009-06-13 07:38:31 -0400464
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000465 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
Malcolm Priestleye3a8fa12014-02-25 20:51:46 +0000466
Malcolm Priestley67638982014-02-25 20:51:48 +0000467 switch (urb->status) {
468 case 0:
Malcolm Priestley67638982014-02-25 20:51:48 +0000469 break;
470 case -ECONNRESET:
471 case -ENOENT:
472 case -ESHUTDOWN:
473 return;
474 case -ETIMEDOUT:
475 default:
Malcolm Priestley67638982014-02-25 20:51:48 +0000476 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
477 "BULK In failed %d\n", urb->status);
478 break;
479 }
Forest Bond92b96792009-06-13 07:38:31 -0400480
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000481 if (urb->actual_length) {
482 spin_lock(&priv->lock);
Forest Bond92b96792009-06-13 07:38:31 -0400483
Malcolm Priestleyd4fa2ab2014-02-25 20:51:49 +0000484 if (RXbBulkInProcessData(priv, rcb, urb->actual_length) == true)
485 re_alloc_skb = true;
486
487 spin_unlock(&priv->lock);
488 }
489
490 rcb->Ref--;
491 if (rcb->Ref == 0) {
492 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d\n",
493 priv->NumRecvFreeList);
494 spin_lock(&priv->lock);
495
496 RXvFreeRCB(rcb, re_alloc_skb);
497
498 spin_unlock(&priv->lock);
499 }
500
501 return;
Forest Bond92b96792009-06-13 07:38:31 -0400502}
503
504/*
505 * Description:
506 * Allocates an usb BulkOut irp and calls USBD.
507 *
508 * Parameters:
509 * In:
510 * pDevice - Pointer to the adapter
511 * Out:
512 * none
513 *
514 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
515 *
516 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000517
Malcolm Priestley3f382902014-02-25 20:51:45 +0000518int PIPEnsSendBulkOut(struct vnt_private *priv,
519 struct vnt_usb_send_context *context)
Forest Bond92b96792009-06-13 07:38:31 -0400520{
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000521 int status;
Malcolm Priestley3f382902014-02-25 20:51:45 +0000522 struct urb *urb;
Forest Bond92b96792009-06-13 07:38:31 -0400523
Malcolm Priestley3f382902014-02-25 20:51:45 +0000524 priv->bPWBitOn = false;
Forest Bond92b96792009-06-13 07:38:31 -0400525
Malcolm Priestley3f382902014-02-25 20:51:45 +0000526 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n");
Forest Bond92b96792009-06-13 07:38:31 -0400527
Malcolm Priestley3f382902014-02-25 20:51:45 +0000528 if (!(MP_IS_READY(priv) && priv->Flags & fMP_POST_WRITES)) {
529 context->bBoolInUse = false;
Malcolm Priestley13338302014-02-25 20:51:43 +0000530 return STATUS_RESOURCES;
531 }
Forest Bond92b96792009-06-13 07:38:31 -0400532
Malcolm Priestley3f382902014-02-25 20:51:45 +0000533 urb = context->pUrb;
Forest Bond92b96792009-06-13 07:38:31 -0400534
Malcolm Priestley3f382902014-02-25 20:51:45 +0000535 usb_fill_bulk_urb(urb,
536 priv->usb,
537 usb_sndbulkpipe(priv->usb, 3),
538 context->Data,
539 context->uBufLen,
540 s_nsBulkOutIoCompleteWrite,
541 context);
542
543 status = usb_submit_urb(urb, GFP_ATOMIC);
544 if (status != 0) {
545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
546 "Submit Tx URB failed %d\n", status);
547 context->bBoolInUse = false;
548 return STATUS_FAILURE;
549 }
550
551 return STATUS_PENDING;
Forest Bond92b96792009-06-13 07:38:31 -0400552}
553
554/*
555 * Description: s_nsBulkOutIoCompleteWrite
556 * 1a) Indicate to the protocol the status of the write.
557 * 1b) Return ownership of the packet to the protocol.
558 *
559 * 2) If any more packets are queue for sending, send another packet
560 * to USBD.
561 * If the attempt to send the packet to the driver fails,
562 * return ownership of the packet to the protocol and
563 * try another packet (until one succeeds).
564 *
565 * Parameters:
566 * In:
567 * pdoUsbDevObj - pointer to the USB device object which
568 * completed the irp
569 * pIrp - the irp which was completed by the
570 * device object
571 * pContext - the context given to IoSetCompletionRoutine
572 * before calling IoCallDriver on the irp
573 * The pContext is a pointer to the USB device object.
574 * Out:
575 * none
576 *
577 * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine
578 * (IofCompleteRequest) to stop working on the irp.
579 *
580 */
Malcolm Priestleyfe5d00e2012-12-10 22:14:36 +0000581
582static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
Forest Bond92b96792009-06-13 07:38:31 -0400583{
Malcolm Priestley599e4b52014-02-25 20:51:51 +0000584 struct vnt_usb_send_context *context = urb->context;
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000585 struct vnt_private *priv = context->pDevice;
Malcolm Priestley1450ba62014-02-19 21:56:33 +0000586 u8 context_type = context->type;
Forest Bond92b96792009-06-13 07:38:31 -0400587
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000588 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
Forest Bond92b96792009-06-13 07:38:31 -0400589
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000590 switch (urb->status) {
591 case 0:
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000592 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
593 "Write %d bytes\n", context->uBufLen);
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000594 break;
595 case -ECONNRESET:
596 case -ENOENT:
597 case -ESHUTDOWN:
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000598 context->bBoolInUse = false;
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000599 return;
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000600 case -ETIMEDOUT:
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000601 default:
Malcolm Priestleyd1b2a112014-02-27 23:06:15 +0000602 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
603 "BULK Out failed %d\n", urb->status);
Malcolm Priestleye8152bf2014-02-19 21:53:35 +0000604 break;
605 }
606
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000607 if (!netif_device_present(priv->dev))
608 return;
Forest Bond92b96792009-06-13 07:38:31 -0400609
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000610 if (CONTEXT_DATA_PACKET == context_type) {
611 if (context->pPacket != NULL) {
612 dev_kfree_skb_irq(context->pPacket);
613 context->pPacket = NULL;
614 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
Malcolm Priestleyd597aae2014-02-27 23:06:14 +0000615 "tx %d bytes\n", context->uBufLen);
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000616 }
Forest Bond92b96792009-06-13 07:38:31 -0400617
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000618 priv->dev->trans_start = jiffies;
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000619 }
Forest Bond92b96792009-06-13 07:38:31 -0400620
Malcolm Priestley21aa2122014-02-19 21:54:45 +0000621 if (priv->bLinkPass == true) {
622 if (netif_queue_stopped(priv->dev))
623 netif_wake_queue(priv->dev);
624 }
625
626 context->bBoolInUse = false;
627
628 return;
Forest Bond92b96792009-06-13 07:38:31 -0400629}