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); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 66 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 67 | int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest, |
| 68 | u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 69 | { |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 70 | int ntStatus; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 71 | |
Andres More | 731047f | 2010-08-05 22:17:20 -0300 | [diff] [blame] | 72 | if (pDevice->Flags & fMP_DISCONNECTED) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 73 | return STATUS_FAILURE; |
| 74 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 75 | if (in_interrupt()) { |
| 76 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"in_interrupt return ..byRequest %x\n", byRequest); |
| 77 | return STATUS_FAILURE; |
| 78 | } |
| 79 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 80 | mutex_lock(&pDevice->usb_lock); |
| 81 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 82 | ntStatus = usb_control_msg( |
| 83 | pDevice->usb, |
| 84 | usb_sndctrlpipe(pDevice->usb , 0), |
| 85 | byRequest, |
| 86 | 0x40, // RequestType |
| 87 | wValue, |
| 88 | wIndex, |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 89 | (void *) pbyBuffer, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 90 | wLength, |
| 91 | HZ |
| 92 | ); |
| 93 | if (ntStatus >= 0) { |
| 94 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe ntStatus= %d\n", ntStatus); |
| 95 | ntStatus = 0; |
| 96 | } else { |
| 97 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"usb_sndctrlpipe fail, ntStatus= %d\n", ntStatus); |
| 98 | } |
| 99 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 100 | mutex_unlock(&pDevice->usb_lock); |
| 101 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 102 | return ntStatus; |
| 103 | } |
| 104 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 105 | int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue, |
| 106 | u16 wIndex, u16 wLength, u8 *pbyBuffer) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 107 | { |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 108 | int ntStatus = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 109 | |
Malcolm Priestley | 7021b68 | 2014-05-15 22:49:22 +0100 | [diff] [blame] | 110 | if (pDevice->Flags & fMP_DISCONNECTED) |
Malcolm Priestley | e1feda1 | 2013-10-14 19:44:13 +0100 | [diff] [blame] | 111 | return STATUS_FAILURE; |
| 112 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 113 | mutex_lock(&pDevice->usb_lock); |
| 114 | |
Malcolm Priestley | 7021b68 | 2014-05-15 22:49:22 +0100 | [diff] [blame] | 115 | ntStatus = usb_control_msg(pDevice->usb, |
| 116 | usb_sndctrlpipe(pDevice->usb, 0), byRequest, 0x40, wValue, |
| 117 | wIndex, pbyBuffer, wLength, USB_CTL_WAIT); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 118 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 119 | mutex_unlock(&pDevice->usb_lock); |
| 120 | |
Malcolm Priestley | 7021b68 | 2014-05-15 22:49:22 +0100 | [diff] [blame] | 121 | if (ntStatus < (int)wLength) |
| 122 | return STATUS_FAILURE; |
| 123 | |
| 124 | return STATUS_SUCCESS; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 127 | int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue, |
Malcolm Priestley | 0fb2af3 | 2014-05-15 22:49:23 +0100 | [diff] [blame^] | 128 | u16 wIndex, u16 wLength, u8 *pbyBuffer) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 129 | { |
Malcolm Priestley | 0fb2af3 | 2014-05-15 22:49:23 +0100 | [diff] [blame^] | 130 | int ntStatus; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 131 | |
Malcolm Priestley | 0fb2af3 | 2014-05-15 22:49:23 +0100 | [diff] [blame^] | 132 | if (pDevice->Flags & fMP_DISCONNECTED) |
Malcolm Priestley | e1feda1 | 2013-10-14 19:44:13 +0100 | [diff] [blame] | 133 | return STATUS_FAILURE; |
| 134 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 135 | mutex_lock(&pDevice->usb_lock); |
| 136 | |
Malcolm Priestley | 0fb2af3 | 2014-05-15 22:49:23 +0100 | [diff] [blame^] | 137 | ntStatus = usb_control_msg(pDevice->usb, |
| 138 | usb_rcvctrlpipe(pDevice->usb, 0), byRequest, 0xc0, wValue, |
| 139 | wIndex, pbyBuffer, wLength, USB_CTL_WAIT); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 140 | |
Malcolm Priestley | c91b186 | 2014-05-15 22:49:19 +0100 | [diff] [blame] | 141 | mutex_unlock(&pDevice->usb_lock); |
| 142 | |
Malcolm Priestley | 0fb2af3 | 2014-05-15 22:49:23 +0100 | [diff] [blame^] | 143 | if (ntStatus < (int)wLength) |
| 144 | return STATUS_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 145 | |
Malcolm Priestley | 0fb2af3 | 2014-05-15 22:49:23 +0100 | [diff] [blame^] | 146 | return STATUS_SUCCESS; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 149 | /* |
| 150 | * Description: |
| 151 | * Allocates an usb interrupt in irp and calls USBD. |
| 152 | * |
| 153 | * Parameters: |
| 154 | * In: |
| 155 | * pDevice - Pointer to the adapter |
| 156 | * Out: |
| 157 | * none |
| 158 | * |
| 159 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver |
| 160 | * |
| 161 | */ |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 162 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 163 | int PIPEnsInterruptRead(struct vnt_private *priv) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 164 | { |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 165 | int status = STATUS_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 166 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 167 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 168 | "---->s_nsStartInterruptUsbRead()\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 169 | |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 170 | if (priv->int_buf.in_use == true) |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 171 | return STATUS_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 172 | |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 173 | priv->int_buf.in_use = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 174 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 175 | usb_fill_int_urb(priv->pInterruptURB, |
| 176 | priv->usb, |
Malcolm Priestley | b9d93d1 | 2014-03-16 12:34:11 +0000 | [diff] [blame] | 177 | usb_rcvintpipe(priv->usb, 1), |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 178 | priv->int_buf.data_buf, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 179 | MAX_INTERRUPT_SIZE, |
| 180 | s_nsInterruptUsbIoCompleteRead, |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 181 | priv, |
| 182 | priv->int_interval); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 183 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 184 | status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC); |
| 185 | if (status) { |
Malcolm Priestley | 59858f5 | 2014-02-19 18:36:37 +0000 | [diff] [blame] | 186 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 187 | "Submit int URB failed %d\n", status); |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 188 | priv->int_buf.in_use = false; |
Malcolm Priestley | 59858f5 | 2014-02-19 18:36:37 +0000 | [diff] [blame] | 189 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 190 | |
Malcolm Priestley | 5f38b78 | 2014-02-19 18:37:32 +0000 | [diff] [blame] | 191 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 192 | "<----s_nsStartInterruptUsbRead Return(%x)\n", status); |
| 193 | |
| 194 | return status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 197 | /* |
| 198 | * Description: |
| 199 | * Complete function of usb interrupt in irp. |
| 200 | * |
| 201 | * Parameters: |
| 202 | * In: |
| 203 | * pDevice - Pointer to the adapter |
| 204 | * |
| 205 | * Out: |
| 206 | * none |
| 207 | * |
| 208 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver |
| 209 | * |
| 210 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 211 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 212 | static void s_nsInterruptUsbIoCompleteRead(struct urb *urb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 213 | { |
Malcolm Priestley | 599e4b5 | 2014-02-25 20:51:51 +0000 | [diff] [blame] | 214 | struct vnt_private *priv = urb->context; |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 215 | int status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 216 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 217 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 218 | "---->s_nsInterruptUsbIoCompleteRead\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 219 | |
Malcolm Priestley | c98fbf9 | 2014-02-17 21:16:20 +0000 | [diff] [blame] | 220 | switch (urb->status) { |
| 221 | case 0: |
| 222 | case -ETIMEDOUT: |
| 223 | break; |
| 224 | case -ECONNRESET: |
| 225 | case -ENOENT: |
| 226 | case -ESHUTDOWN: |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 227 | priv->int_buf.in_use = false; |
Malcolm Priestley | c98fbf9 | 2014-02-17 21:16:20 +0000 | [diff] [blame] | 228 | return; |
| 229 | default: |
| 230 | break; |
| 231 | } |
| 232 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 233 | status = urb->status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 234 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 235 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 236 | "s_nsInterruptUsbIoCompleteRead Status %d\n", status); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 237 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 238 | if (status != STATUS_SUCCESS) { |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 239 | priv->int_buf.in_use = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 240 | |
Malcolm Priestley | 247b4b6 | 2014-02-17 21:12:51 +0000 | [diff] [blame] | 241 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 242 | "IntUSBIoCompleteControl STATUS = %d\n", status); |
Malcolm Priestley | 247b4b6 | 2014-02-17 21:12:51 +0000 | [diff] [blame] | 243 | } else { |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 244 | INTnsProcessData(priv); |
Malcolm Priestley | 247b4b6 | 2014-02-17 21:12:51 +0000 | [diff] [blame] | 245 | } |
Malcolm Priestley | 749627f | 2014-02-17 21:24:33 +0000 | [diff] [blame] | 246 | |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 247 | status = usb_submit_urb(priv->pInterruptURB, GFP_ATOMIC); |
| 248 | if (status) { |
| 249 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 250 | "Submit int URB failed %d\n", status); |
| 251 | } else { |
Malcolm Priestley | f764e00 | 2014-02-19 18:39:09 +0000 | [diff] [blame] | 252 | priv->int_buf.in_use = true; |
Malcolm Priestley | d9ad7a9 | 2014-02-17 21:27:30 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /* |
| 259 | * Description: |
| 260 | * Allocates an usb BulkIn irp and calls USBD. |
| 261 | * |
| 262 | * Parameters: |
| 263 | * In: |
| 264 | * pDevice - Pointer to the adapter |
| 265 | * Out: |
| 266 | * none |
| 267 | * |
| 268 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver |
| 269 | * |
| 270 | */ |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 271 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 272 | int PIPEnsBulkInUsbRead(struct vnt_private *priv, struct vnt_rcb *rcb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 273 | { |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 274 | int status = 0; |
| 275 | struct urb *urb; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 276 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 277 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 278 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 279 | if (priv->Flags & fMP_DISCONNECTED) |
| 280 | return STATUS_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 281 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 282 | urb = rcb->pUrb; |
| 283 | if (rcb->skb == NULL) { |
| 284 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rcb->skb is null\n"); |
| 285 | return status; |
| 286 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 287 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 288 | usb_fill_bulk_urb(urb, |
| 289 | priv->usb, |
| 290 | usb_rcvbulkpipe(priv->usb, 2), |
| 291 | (void *) (rcb->skb->data), |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 292 | MAX_TOTAL_SIZE_WITH_ALL_HEADERS, |
| 293 | s_nsBulkInUsbIoCompleteRead, |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 294 | rcb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 295 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 296 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 297 | if (status != 0) { |
| 298 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 299 | "Submit Rx URB failed %d\n", status); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 300 | return STATUS_FAILURE ; |
| 301 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 302 | |
Malcolm Priestley | 0b787d7 | 2014-02-25 20:51:50 +0000 | [diff] [blame] | 303 | rcb->Ref = 1; |
| 304 | rcb->bBoolInUse = true; |
| 305 | |
| 306 | return status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 307 | } |
| 308 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 309 | /* |
| 310 | * Description: |
| 311 | * Complete function of usb BulkIn irp. |
| 312 | * |
| 313 | * Parameters: |
| 314 | * In: |
| 315 | * pDevice - Pointer to the adapter |
| 316 | * |
| 317 | * Out: |
| 318 | * none |
| 319 | * |
| 320 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver |
| 321 | * |
| 322 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 323 | |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 324 | static void s_nsBulkInUsbIoCompleteRead(struct urb *urb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 325 | { |
Malcolm Priestley | 599e4b5 | 2014-02-25 20:51:51 +0000 | [diff] [blame] | 326 | struct vnt_rcb *rcb = urb->context; |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 327 | struct vnt_private *priv = rcb->pDevice; |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 328 | unsigned long flags; |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 329 | int re_alloc_skb = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 330 | |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 331 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n"); |
Malcolm Priestley | e3a8fa1 | 2014-02-25 20:51:46 +0000 | [diff] [blame] | 332 | |
Malcolm Priestley | 6763898 | 2014-02-25 20:51:48 +0000 | [diff] [blame] | 333 | switch (urb->status) { |
| 334 | case 0: |
Malcolm Priestley | 6763898 | 2014-02-25 20:51:48 +0000 | [diff] [blame] | 335 | break; |
| 336 | case -ECONNRESET: |
| 337 | case -ENOENT: |
| 338 | case -ESHUTDOWN: |
| 339 | return; |
| 340 | case -ETIMEDOUT: |
| 341 | default: |
Malcolm Priestley | 6763898 | 2014-02-25 20:51:48 +0000 | [diff] [blame] | 342 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 343 | "BULK In failed %d\n", urb->status); |
| 344 | break; |
| 345 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 346 | |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 347 | if (urb->actual_length) { |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 348 | spin_lock_irqsave(&priv->lock, flags); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 349 | |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 350 | if (RXbBulkInProcessData(priv, rcb, urb->actual_length) == true) |
| 351 | re_alloc_skb = true; |
| 352 | |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 353 | spin_unlock_irqrestore(&priv->lock, flags); |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | rcb->Ref--; |
| 357 | if (rcb->Ref == 0) { |
| 358 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeNormal %d\n", |
| 359 | priv->NumRecvFreeList); |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 360 | spin_lock_irqsave(&priv->lock, flags); |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 361 | |
| 362 | RXvFreeRCB(rcb, re_alloc_skb); |
| 363 | |
Malcolm Priestley | 29b0237 | 2014-05-15 22:49:20 +0100 | [diff] [blame] | 364 | spin_unlock_irqrestore(&priv->lock, flags); |
Malcolm Priestley | d4fa2ab | 2014-02-25 20:51:49 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /* |
| 371 | * Description: |
| 372 | * Allocates an usb BulkOut irp and calls USBD. |
| 373 | * |
| 374 | * Parameters: |
| 375 | * In: |
| 376 | * pDevice - Pointer to the adapter |
| 377 | * Out: |
| 378 | * none |
| 379 | * |
| 380 | * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver |
| 381 | * |
| 382 | */ |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 383 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 384 | int PIPEnsSendBulkOut(struct vnt_private *priv, |
| 385 | struct vnt_usb_send_context *context) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 386 | { |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 387 | int status; |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 388 | struct urb *urb; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 389 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 390 | priv->bPWBitOn = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 391 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 392 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_nsSendBulkOut\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 393 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 394 | if (!(MP_IS_READY(priv) && priv->Flags & fMP_POST_WRITES)) { |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 395 | context->in_use = false; |
Malcolm Priestley | 1333830 | 2014-02-25 20:51:43 +0000 | [diff] [blame] | 396 | return STATUS_RESOURCES; |
| 397 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 398 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 399 | urb = context->urb; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 400 | |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 401 | usb_fill_bulk_urb(urb, |
| 402 | priv->usb, |
| 403 | usb_sndbulkpipe(priv->usb, 3), |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 404 | context->data, |
| 405 | context->buf_len, |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 406 | s_nsBulkOutIoCompleteWrite, |
| 407 | context); |
| 408 | |
| 409 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 410 | if (status != 0) { |
| 411 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 412 | "Submit Tx URB failed %d\n", status); |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 413 | context->in_use = false; |
Malcolm Priestley | 3f38290 | 2014-02-25 20:51:45 +0000 | [diff] [blame] | 414 | return STATUS_FAILURE; |
| 415 | } |
| 416 | |
| 417 | return STATUS_PENDING; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /* |
| 421 | * Description: s_nsBulkOutIoCompleteWrite |
| 422 | * 1a) Indicate to the protocol the status of the write. |
| 423 | * 1b) Return ownership of the packet to the protocol. |
| 424 | * |
| 425 | * 2) If any more packets are queue for sending, send another packet |
| 426 | * to USBD. |
| 427 | * If the attempt to send the packet to the driver fails, |
| 428 | * return ownership of the packet to the protocol and |
| 429 | * try another packet (until one succeeds). |
| 430 | * |
| 431 | * Parameters: |
| 432 | * In: |
| 433 | * pdoUsbDevObj - pointer to the USB device object which |
| 434 | * completed the irp |
| 435 | * pIrp - the irp which was completed by the |
| 436 | * device object |
| 437 | * pContext - the context given to IoSetCompletionRoutine |
| 438 | * before calling IoCallDriver on the irp |
| 439 | * The pContext is a pointer to the USB device object. |
| 440 | * Out: |
| 441 | * none |
| 442 | * |
| 443 | * Return Value: STATUS_MORE_PROCESSING_REQUIRED - allows the completion routine |
| 444 | * (IofCompleteRequest) to stop working on the irp. |
| 445 | * |
| 446 | */ |
Malcolm Priestley | fe5d00e | 2012-12-10 22:14:36 +0000 | [diff] [blame] | 447 | |
| 448 | static void s_nsBulkOutIoCompleteWrite(struct urb *urb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 449 | { |
Malcolm Priestley | 599e4b5 | 2014-02-25 20:51:51 +0000 | [diff] [blame] | 450 | struct vnt_usb_send_context *context = urb->context; |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 451 | struct vnt_private *priv = context->priv; |
Malcolm Priestley | 1450ba6 | 2014-02-19 21:56:33 +0000 | [diff] [blame] | 452 | u8 context_type = context->type; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 453 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 454 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 455 | |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 456 | switch (urb->status) { |
| 457 | case 0: |
Malcolm Priestley | d1b2a11 | 2014-02-27 23:06:15 +0000 | [diff] [blame] | 458 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 459 | "Write %d bytes\n", context->buf_len); |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 460 | break; |
| 461 | case -ECONNRESET: |
| 462 | case -ENOENT: |
| 463 | case -ESHUTDOWN: |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 464 | context->in_use = false; |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 465 | return; |
Malcolm Priestley | d1b2a11 | 2014-02-27 23:06:15 +0000 | [diff] [blame] | 466 | case -ETIMEDOUT: |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 467 | default: |
Malcolm Priestley | d1b2a11 | 2014-02-27 23:06:15 +0000 | [diff] [blame] | 468 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 469 | "BULK Out failed %d\n", urb->status); |
Malcolm Priestley | e8152bf | 2014-02-19 21:53:35 +0000 | [diff] [blame] | 470 | break; |
| 471 | } |
| 472 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 473 | if (!netif_device_present(priv->dev)) |
| 474 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 475 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 476 | if (CONTEXT_DATA_PACKET == context_type) { |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 477 | if (context->skb != NULL) { |
| 478 | dev_kfree_skb_irq(context->skb); |
| 479 | context->skb = NULL; |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 480 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 481 | "tx %d bytes\n", context->buf_len); |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 482 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 483 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 484 | priv->dev->trans_start = jiffies; |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 485 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 486 | |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 487 | if (priv->bLinkPass == true) { |
| 488 | if (netif_queue_stopped(priv->dev)) |
| 489 | netif_wake_queue(priv->dev); |
| 490 | } |
| 491 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 492 | context->in_use = false; |
Malcolm Priestley | 21aa212 | 2014-02-19 21:54:45 +0000 | [diff] [blame] | 493 | |
| 494 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 495 | } |