Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 41 | #include "int.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 42 | #include "rxtx.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 43 | #include "dpc.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 44 | #include "control.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 45 | #include "desc.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 46 | #include "device.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 47 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 48 | //endpoint def |
| 49 | //endpoint 0: control |
| 50 | //endpoint 1: interrupt |
| 51 | //endpoint 2: read bulk |
| 52 | //endpoint 3: write bulk |
| 53 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 54 | //static int msglevel =MSG_LEVEL_DEBUG; |
| 55 | static int msglevel =MSG_LEVEL_INFO; |
| 56 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 57 | #define USB_CTL_WAIT 500 //ms |
| 58 | |
| 59 | #ifndef URB_ASYNC_UNLINK |
| 60 | #define URB_ASYNC_UNLINK 0 |
| 61 | #endif |
| 62 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 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); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 67 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 68 | int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest, |
| 69 | u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 70 | { |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 71 | int ntStatus; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 72 | |
Andres More | 731047f | 2010-08-05 22:17:20 -0300 | [diff] [blame] | 73 | if (pDevice->Flags & fMP_DISCONNECTED) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 74 | return STATUS_FAILURE; |
| 75 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 81 | mutex_lock(&pDevice->usb_lock); |
| 82 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 83 | ntStatus = usb_control_msg( |
| 84 | pDevice->usb, |
| 85 | usb_sndctrlpipe(pDevice->usb , 0), |
| 86 | byRequest, |
| 87 | 0x40, // RequestType |
| 88 | wValue, |
| 89 | wIndex, |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 90 | (void *) pbyBuffer, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 101 | mutex_unlock(&pDevice->usb_lock); |
| 102 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 103 | return ntStatus; |
| 104 | } |
| 105 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 106 | int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue, |
| 107 | u16 wIndex, u16 wLength, u8 *pbyBuffer) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 108 | { |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 109 | int ntStatus = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 110 | |
Malcolm Priestley | 7021b68 | 2014-05-15 22:49:22 +0100 | [diff] [blame^] | 111 | if (pDevice->Flags & fMP_DISCONNECTED) |
Malcolm Priestley | e1feda1 | 2013-10-14 19:44:13 +0100 | [diff] [blame] | 112 | return STATUS_FAILURE; |
| 113 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 114 | mutex_lock(&pDevice->usb_lock); |
| 115 | |
Malcolm Priestley | 7021b68 | 2014-05-15 22:49:22 +0100 | [diff] [blame^] | 116 | ntStatus = usb_control_msg(pDevice->usb, |
| 117 | usb_sndctrlpipe(pDevice->usb, 0), byRequest, 0x40, wValue, |
| 118 | wIndex, pbyBuffer, wLength, USB_CTL_WAIT); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 119 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 120 | mutex_unlock(&pDevice->usb_lock); |
| 121 | |
Malcolm Priestley | 7021b68 | 2014-05-15 22:49:22 +0100 | [diff] [blame^] | 122 | if (ntStatus < (int)wLength) |
| 123 | return STATUS_FAILURE; |
| 124 | |
| 125 | return STATUS_SUCCESS; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 128 | int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue, |
| 129 | u16 wIndex, u16 wLength, u8 *pbyBuffer) |
Iulia Manda | 9009dd1 | 2014-03-13 01:35:40 +0200 | [diff] [blame] | 130 | __releases(&pDevice->lock) |
| 131 | __acquires(&pDevice->lock) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 132 | { |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 133 | int ntStatus = 0; |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 134 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 135 | |
Andres More | 731047f | 2010-08-05 22:17:20 -0300 | [diff] [blame] | 136 | if (pDevice->Flags & fMP_DISCONNECTED) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 137 | return STATUS_FAILURE; |
| 138 | |
Andres More | 731047f | 2010-08-05 22:17:20 -0300 | [diff] [blame] | 139 | if (pDevice->Flags & fMP_CONTROL_READS) |
| 140 | return STATUS_FAILURE; |
| 141 | |
Malcolm Priestley | e1feda1 | 2013-10-14 19:44:13 +0100 | [diff] [blame] | 142 | if (pDevice->pControlURB->hcpriv) |
| 143 | return STATUS_FAILURE; |
| 144 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 145 | mutex_lock(&pDevice->usb_lock); |
| 146 | |
Malcolm Priestley | ae5943d | 2013-01-30 20:07:29 +0000 | [diff] [blame] | 147 | MP_SET_FLAG(pDevice, fMP_CONTROL_READS); |
| 148 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | |
Joe Perches | bfbfeec | 2010-03-24 22:17:06 -0700 | [diff] [blame] | 160 | ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC); |
| 161 | if (ntStatus != 0) { |
Malcolm Priestley | ae5943d | 2013-01-30 20:07:29 +0000 | [diff] [blame] | 162 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 163 | "control request submission failed: %d\n", ntStatus); |
| 164 | MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS); |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 165 | mutex_unlock(&pDevice->usb_lock); |
Malcolm Priestley | ae5943d | 2013-01-30 20:07:29 +0000 | [diff] [blame] | 166 | return STATUS_FAILURE; |
| 167 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 168 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 169 | for (ii = 0; ii <= USB_CTL_WAIT; ii ++) { |
Andres More | 731047f | 2010-08-05 22:17:20 -0300 | [diff] [blame] | 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"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 179 | MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS); |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 180 | mutex_unlock(&pDevice->usb_lock); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 181 | return STATUS_FAILURE; |
| 182 | } |
| 183 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 184 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 185 | mutex_unlock(&pDevice->usb_lock); |
| 186 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 187 | return ntStatus; |
| 188 | } |
| 189 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 204 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 205 | static void s_nsControlInUsbIoCompleteRead(struct urb *urb) |
| 206 | { |
| 207 | struct vnt_private *pDevice = (struct vnt_private *)urb->context; |
| 208 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | */ |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 238 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 239 | int PIPEnsInterruptRead(struct vnt_private *priv) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 240 | { |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 241 | int status = STATUS_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 242 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 243 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 244 | "---->s_nsStartInterruptUsbRead()\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 245 | |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 246 | if (priv->int_buf.in_use == true) |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 247 | return STATUS_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 248 | |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 249 | priv->int_buf.in_use = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 250 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 251 | usb_fill_int_urb(priv->pInterruptURB, |
| 252 | priv->usb, |
Malcolm Priestley | b9d93d1 | 2014-03-16 12:34:11 +0000 | [diff] [blame] | 253 | usb_rcvintpipe(priv->usb, 1), |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 254 | priv->int_buf.data_buf, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 255 | MAX_INTERRUPT_SIZE, |
| 256 | s_nsInterruptUsbIoCompleteRead, |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 257 | priv, |
| 258 | priv->int_interval); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 259 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 260 | status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC); |
| 261 | if (status) { |
Malcolm Priestley | 59858f5 | 2014-02-19 18:36:37 +0000 | [diff] [blame] | 262 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 263 | "Submit int URB failed %d\n", status); |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 264 | priv->int_buf.in_use = false; |
Malcolm Priestley | 59858f5 | 2014-02-19 18:36:37 +0000 | [diff] [blame] | 265 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 266 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 267 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 268 | "<----s_nsStartInterruptUsbRead Return(%x)\n", status); |
| 269 | |
| 270 | return status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 287 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 288 | static void s_nsInterruptUsbIoCompleteRead(struct urb *urb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 289 | { |
Malcolm Priestley | 599e4b5 | 2014-02-25 20:51:51 +0000 | [diff] [blame] | 290 | struct vnt_private *priv = urb->context; |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 291 | int status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 292 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 293 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 294 | "---->s_nsInterruptUsbIoCompleteRead\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 295 | |
Malcolm Priestley | c98fbf9 | 2014-02-17 21:16:20 +0000 | [diff] [blame] | 296 | switch (urb->status) { |
| 297 | case 0: |
| 298 | case -ETIMEDOUT: |
| 299 | break; |
| 300 | case -ECONNRESET: |
| 301 | case -ENOENT: |
| 302 | case -ESHUTDOWN: |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 303 | priv->int_buf.in_use = false; |
Malcolm Priestley | c98fbf9 | 2014-02-17 21:16:20 +0000 | [diff] [blame] | 304 | return; |
| 305 | default: |
| 306 | break; |
| 307 | } |
| 308 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 309 | status = urb->status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 310 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 311 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 312 | "s_nsInterruptUsbIoCompleteRead Status %d\n", status); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 313 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 314 | if (status != STATUS_SUCCESS) { |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 315 | priv->int_buf.in_use = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 316 | |
Malcolm Priestley | 247b4b6 | 2014-02-17 21:12:51 +0000 | [diff] [blame] | 317 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 318 | "IntUSBIoCompleteControl STATUS = %d\n", status); |
Malcolm Priestley | 247b4b6 | 2014-02-17 21:12:51 +0000 | [diff] [blame] | 319 | } else { |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 320 | INTnsProcessData(priv); |
Malcolm Priestley | 247b4b6 | 2014-02-17 21:12:51 +0000 | [diff] [blame] | 321 | } |
Malcolm Priestley | 749627f | 2014-02-17 21:24:33 +0000 | [diff] [blame] | 322 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 323 | 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 Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 328 | priv->int_buf.in_use = true; |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | */ |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 347 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 348 | int PIPEnsBulkInUsbRead(struct vnt_private *priv, struct vnt_rcb *rcb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 349 | { |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 350 | int status = 0; |
| 351 | struct urb *urb; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 352 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 353 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 354 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 355 | if (priv->Flags & fMP_DISCONNECTED) |
| 356 | return STATUS_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 357 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 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 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 363 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 364 | usb_fill_bulk_urb(urb, |
| 365 | priv->usb, |
| 366 | usb_rcvbulkpipe(priv->usb, 2), |
| 367 | (void *) (rcb->skb->data), |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 368 | MAX_TOTAL_SIZE_WITH_ALL_HEADERS, |
| 369 | s_nsBulkInUsbIoCompleteRead, |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 370 | rcb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 371 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 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); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 376 | return STATUS_FAILURE ; |
| 377 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 378 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 379 | rcb->Ref = 1; |
| 380 | rcb->bBoolInUse = true; |
| 381 | |
| 382 | return status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 399 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 400 | static void s_nsBulkInUsbIoCompleteRead(struct urb *urb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 401 | { |
Malcolm Priestley | 599e4b5 | 2014-02-25 20:51:51 +0000 | [diff] [blame] | 402 | struct vnt_rcb *rcb = urb->context; |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 403 | struct vnt_private *priv = rcb->pDevice; |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 404 | unsigned long flags; |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 405 | int re_alloc_skb = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 406 | |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 407 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n"); |
Malcolm Priestley | e3a8fa1 | 2014-02-25 20:51:46 +0000 | [diff] [blame] | 408 | |
Malcolm Priestley | 6763898 | 2014-02-25 20:51:48 +0000 | [diff] [blame] | 409 | switch (urb->status) { |
| 410 | case 0: |
Malcolm Priestley | 6763898 | 2014-02-25 20:51:48 +0000 | [diff] [blame] | 411 | break; |
| 412 | case -ECONNRESET: |
| 413 | case -ENOENT: |
| 414 | case -ESHUTDOWN: |
| 415 | return; |
| 416 | case -ETIMEDOUT: |
| 417 | default: |
Malcolm Priestley | 6763898 | 2014-02-25 20:51:48 +0000 | [diff] [blame] | 418 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 419 | "BULK In failed %d\n", urb->status); |
| 420 | break; |
| 421 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 422 | |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 423 | if (urb->actual_length) { |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 424 | spin_lock_irqsave(&priv->lock, flags); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 425 | |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 426 | if (RXbBulkInProcessData(priv, rcb, urb->actual_length) == true) |
| 427 | re_alloc_skb = true; |
| 428 | |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 429 | spin_unlock_irqrestore(&priv->lock, flags); |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | rcb->Ref--; |
| 433 | if (rcb->Ref == 0) { |
| 434 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d\n", |
| 435 | priv->NumRecvFreeList); |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 436 | spin_lock_irqsave(&priv->lock, flags); |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 437 | |
| 438 | RXvFreeRCB(rcb, re_alloc_skb); |
| 439 | |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 440 | spin_unlock_irqrestore(&priv->lock, flags); |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | */ |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 459 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 460 | int PIPEnsSendBulkOut(struct vnt_private *priv, |
| 461 | struct vnt_usb_send_context *context) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 462 | { |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 463 | int status; |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 464 | struct urb *urb; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 465 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 466 | priv->bPWBitOn = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 467 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 468 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 469 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 470 | if (!(MP_IS_READY(priv) && priv->Flags & fMP_POST_WRITES)) { |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 471 | context->in_use = false; |
Malcolm Priestley | 1333830 | 2014-02-25 20:51:43 +0000 | [diff] [blame] | 472 | return STATUS_RESOURCES; |
| 473 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 474 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 475 | urb = context->urb; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 476 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 477 | usb_fill_bulk_urb(urb, |
| 478 | priv->usb, |
| 479 | usb_sndbulkpipe(priv->usb, 3), |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 480 | context->data, |
| 481 | context->buf_len, |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 482 | 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 Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 489 | context->in_use = false; |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 490 | return STATUS_FAILURE; |
| 491 | } |
| 492 | |
| 493 | return STATUS_PENDING; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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 | */ |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 523 | |
| 524 | static void s_nsBulkOutIoCompleteWrite(struct urb *urb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 525 | { |
Malcolm Priestley | 599e4b5 | 2014-02-25 20:51:51 +0000 | [diff] [blame] | 526 | struct vnt_usb_send_context *context = urb->context; |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 527 | struct vnt_private *priv = context->priv; |
Malcolm Priestley | 1450ba6 | 2014-02-19 21:56:33 +0000 | [diff] [blame] | 528 | u8 context_type = context->type; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 529 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 530 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 531 | |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 532 | switch (urb->status) { |
| 533 | case 0: |
Malcolm Priestley | d1b2a11 | 2014-02-27 23:06:15 +0000 | [diff] [blame] | 534 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 535 | "Write %d bytes\n", context->buf_len); |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 536 | break; |
| 537 | case -ECONNRESET: |
| 538 | case -ENOENT: |
| 539 | case -ESHUTDOWN: |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 540 | context->in_use = false; |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 541 | return; |
Malcolm Priestley | d1b2a11 | 2014-02-27 23:06:15 +0000 | [diff] [blame] | 542 | case -ETIMEDOUT: |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 543 | default: |
Malcolm Priestley | d1b2a11 | 2014-02-27 23:06:15 +0000 | [diff] [blame] | 544 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 545 | "BULK Out failed %d\n", urb->status); |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 546 | break; |
| 547 | } |
| 548 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 549 | if (!netif_device_present(priv->dev)) |
| 550 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 551 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 552 | if (CONTEXT_DATA_PACKET == context_type) { |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 553 | if (context->skb != NULL) { |
| 554 | dev_kfree_skb_irq(context->skb); |
| 555 | context->skb = NULL; |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 556 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 557 | "tx %d bytes\n", context->buf_len); |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 558 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 559 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 560 | priv->dev->trans_start = jiffies; |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 561 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 562 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 563 | if (priv->bLinkPass == true) { |
| 564 | if (netif_queue_stopped(priv->dev)) |
| 565 | netif_wake_queue(priv->dev); |
| 566 | } |
| 567 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 568 | context->in_use = false; |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 569 | |
| 570 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 571 | } |