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