Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * cdc-acm.c |
| 3 | * |
| 4 | * Copyright (c) 1999 Armin Fuerst <fuerst@in.tum.de> |
Pavel Machek | a253129 | 2010-07-18 14:27:13 +0200 | [diff] [blame] | 5 | * Copyright (c) 1999 Pavel Machek <pavel@ucw.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (c) 1999 Johannes Erdfelt <johannes@erdfelt.com> |
| 7 | * Copyright (c) 2000 Vojtech Pavlik <vojtech@suse.cz> |
| 8 | * Copyright (c) 2004 Oliver Neukum <oliver@neukum.name> |
David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 9 | * Copyright (c) 2005 David Kubicek <dave@awk.cz> |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 10 | * Copyright (c) 2011 Johan Hovold <jhovold@gmail.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * USB Abstract Control Model driver for USB modems and ISDN adapters |
| 13 | * |
| 14 | * Sponsored by SuSE |
| 15 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or |
| 19 | * (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 | */ |
| 30 | |
| 31 | #undef DEBUG |
David Brownell | e5fbab5 | 2008-08-06 18:46:10 -0700 | [diff] [blame] | 32 | #undef VERBOSE_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include <linux/kernel.h> |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 35 | #include <linux/sched/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/errno.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/slab.h> |
Tobias Herzog | ea25835 | 2017-03-30 22:15:11 +0200 | [diff] [blame] | 39 | #include <linux/log2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/tty.h> |
Oliver Neukum | 7af25b4 | 2009-09-08 23:51:28 +0200 | [diff] [blame] | 41 | #include <linux/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/tty_driver.h> |
| 43 | #include <linux/tty_flip.h> |
| 44 | #include <linux/module.h> |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 45 | #include <linux/mutex.h> |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 46 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/usb.h> |
David Brownell | a8c28f2 | 2006-06-13 09:57:47 -0700 | [diff] [blame] | 48 | #include <linux/usb/cdc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <asm/byteorder.h> |
| 50 | #include <asm/unaligned.h> |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 51 | #include <linux/idr.h> |
David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 52 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | #include "cdc-acm.h" |
| 55 | |
David Brownell | e5fbab5 | 2008-08-06 18:46:10 -0700 | [diff] [blame] | 56 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 57 | #define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek, Johan Hovold" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters" |
| 59 | |
| 60 | static struct usb_driver acm_driver; |
| 61 | static struct tty_driver *acm_tty_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 63 | static DEFINE_IDR(acm_minors); |
| 64 | static DEFINE_MUTEX(acm_minors_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Jim Paris | 24cb450 | 2014-10-30 11:04:47 -0400 | [diff] [blame] | 66 | static void acm_tty_set_termios(struct tty_struct *tty, |
| 67 | struct ktermios *termios_old); |
| 68 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 69 | /* |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 70 | * acm_minors accessors |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 71 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 73 | /* |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 74 | * Look up an ACM structure by minor. If found and not disconnected, increment |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 75 | * its refcount and return it with its mutex held. |
| 76 | */ |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 77 | static struct acm *acm_get_by_minor(unsigned int minor) |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 78 | { |
| 79 | struct acm *acm; |
| 80 | |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 81 | mutex_lock(&acm_minors_lock); |
| 82 | acm = idr_find(&acm_minors, minor); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 83 | if (acm) { |
| 84 | mutex_lock(&acm->mutex); |
| 85 | if (acm->disconnected) { |
| 86 | mutex_unlock(&acm->mutex); |
| 87 | acm = NULL; |
| 88 | } else { |
| 89 | tty_port_get(&acm->port); |
| 90 | mutex_unlock(&acm->mutex); |
| 91 | } |
| 92 | } |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 93 | mutex_unlock(&acm_minors_lock); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 94 | return acm; |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Try to find an available minor number and if found, associate it with 'acm'. |
| 99 | */ |
| 100 | static int acm_alloc_minor(struct acm *acm) |
| 101 | { |
| 102 | int minor; |
| 103 | |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 104 | mutex_lock(&acm_minors_lock); |
| 105 | minor = idr_alloc(&acm_minors, acm, 0, ACM_TTY_MINORS, GFP_KERNEL); |
| 106 | mutex_unlock(&acm_minors_lock); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 107 | |
| 108 | return minor; |
| 109 | } |
| 110 | |
| 111 | /* Release the minor number associated with 'acm'. */ |
| 112 | static void acm_release_minor(struct acm *acm) |
| 113 | { |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 114 | mutex_lock(&acm_minors_lock); |
| 115 | idr_remove(&acm_minors, acm->minor); |
| 116 | mutex_unlock(&acm_minors_lock); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 117 | } |
Alan Cox | 739e028 | 2009-06-11 12:27:50 +0100 | [diff] [blame] | 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* |
| 120 | * Functions for ACM control messages. |
| 121 | */ |
| 122 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 123 | static int acm_ctrl_msg(struct acm *acm, int request, int value, |
| 124 | void *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Johan Hovold | bae3f4c | 2014-05-26 19:23:39 +0200 | [diff] [blame] | 126 | int retval; |
| 127 | |
| 128 | retval = usb_autopm_get_interface(acm->control); |
| 129 | if (retval) |
| 130 | return retval; |
| 131 | |
| 132 | retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | request, USB_RT_ACM, value, |
| 134 | acm->control->altsetting[0].desc.bInterfaceNumber, |
| 135 | buf, len, 5000); |
Johan Hovold | bae3f4c | 2014-05-26 19:23:39 +0200 | [diff] [blame] | 136 | |
Johan Hovold | a5cc7ef | 2011-03-22 11:12:15 +0100 | [diff] [blame] | 137 | dev_dbg(&acm->control->dev, |
Ladislav Michl | 90744af8 | 2016-11-18 19:01:22 +0100 | [diff] [blame] | 138 | "%s - rq 0x%02x, val %#x, len %#x, result %d\n", |
| 139 | __func__, request, value, len, retval); |
Johan Hovold | bae3f4c | 2014-05-26 19:23:39 +0200 | [diff] [blame] | 140 | |
| 141 | usb_autopm_put_interface(acm->control); |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return retval < 0 ? retval : 0; |
| 144 | } |
| 145 | |
| 146 | /* devices aren't required to support these requests. |
| 147 | * the cdc acm descriptor tells whether they do... |
| 148 | */ |
Johan Hovold | 2a8cdfd | 2014-11-06 18:08:33 +0100 | [diff] [blame] | 149 | static inline int acm_set_control(struct acm *acm, int control) |
| 150 | { |
| 151 | if (acm->quirks & QUIRK_CONTROL_LINE_STATE) |
| 152 | return -EOPNOTSUPP; |
| 153 | |
| 154 | return acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE, |
| 155 | control, NULL, 0); |
| 156 | } |
| 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | #define acm_set_line(acm, line) \ |
| 159 | acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line)) |
| 160 | #define acm_send_break(acm, ms) \ |
| 161 | acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0) |
| 162 | |
Ladislav Michl | ba8c931 | 2016-11-18 19:07:08 +0100 | [diff] [blame] | 163 | static void acm_kill_urbs(struct acm *acm) |
| 164 | { |
| 165 | int i; |
| 166 | |
| 167 | usb_kill_urb(acm->ctrlurb); |
| 168 | for (i = 0; i < ACM_NW; i++) |
| 169 | usb_kill_urb(acm->wb[i].urb); |
| 170 | for (i = 0; i < acm->rx_buflimit; i++) |
| 171 | usb_kill_urb(acm->read_urbs[i]); |
| 172 | } |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | /* |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 175 | * Write buffer management. |
| 176 | * All of these assume proper locks taken by the caller. |
| 177 | */ |
| 178 | |
| 179 | static int acm_wb_alloc(struct acm *acm) |
| 180 | { |
| 181 | int i, wbn; |
| 182 | struct acm_wb *wb; |
| 183 | |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 184 | wbn = 0; |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 185 | i = 0; |
| 186 | for (;;) { |
| 187 | wb = &acm->wb[wbn]; |
| 188 | if (!wb->use) { |
| 189 | wb->use = 1; |
| 190 | return wbn; |
| 191 | } |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 192 | wbn = (wbn + 1) % ACM_NW; |
| 193 | if (++i >= ACM_NW) |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 194 | return -1; |
| 195 | } |
| 196 | } |
| 197 | |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 198 | static int acm_wb_is_avail(struct acm *acm) |
| 199 | { |
| 200 | int i, n; |
David Brownell | e5fbab5 | 2008-08-06 18:46:10 -0700 | [diff] [blame] | 201 | unsigned long flags; |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 202 | |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 203 | n = ACM_NW; |
David Brownell | e5fbab5 | 2008-08-06 18:46:10 -0700 | [diff] [blame] | 204 | spin_lock_irqsave(&acm->write_lock, flags); |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 205 | for (i = 0; i < ACM_NW; i++) |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 206 | n -= acm->wb[i].use; |
David Brownell | e5fbab5 | 2008-08-06 18:46:10 -0700 | [diff] [blame] | 207 | spin_unlock_irqrestore(&acm->write_lock, flags); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 208 | return n; |
| 209 | } |
| 210 | |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 211 | /* |
Brandon Philips | ad0b65e | 2008-11-06 11:19:11 -0800 | [diff] [blame] | 212 | * Finish write. Caller must hold acm->write_lock |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 213 | */ |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 214 | static void acm_write_done(struct acm *acm, struct acm_wb *wb) |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 215 | { |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 216 | wb->use = 0; |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 217 | acm->transmitting--; |
Oliver Neukum | 97d35f9 | 2009-12-16 17:05:57 +0100 | [diff] [blame] | 218 | usb_autopm_put_interface_async(acm->control); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* |
| 222 | * Poke write. |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 223 | * |
| 224 | * the caller is responsible for locking |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 225 | */ |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 226 | |
| 227 | static int acm_start_wb(struct acm *acm, struct acm_wb *wb) |
| 228 | { |
| 229 | int rc; |
| 230 | |
| 231 | acm->transmitting++; |
| 232 | |
| 233 | wb->urb->transfer_buffer = wb->buf; |
| 234 | wb->urb->transfer_dma = wb->dmah; |
| 235 | wb->urb->transfer_buffer_length = wb->len; |
| 236 | wb->urb->dev = acm->dev; |
| 237 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 238 | rc = usb_submit_urb(wb->urb, GFP_ATOMIC); |
| 239 | if (rc < 0) { |
Johan Hovold | a5cc7ef | 2011-03-22 11:12:15 +0100 | [diff] [blame] | 240 | dev_err(&acm->data->dev, |
| 241 | "%s - usb_submit_urb(write bulk) failed: %d\n", |
| 242 | __func__, rc); |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 243 | acm_write_done(acm, wb); |
| 244 | } |
| 245 | return rc; |
| 246 | } |
| 247 | |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 248 | /* |
| 249 | * attributes exported through sysfs |
| 250 | */ |
| 251 | static ssize_t show_caps |
| 252 | (struct device *dev, struct device_attribute *attr, char *buf) |
| 253 | { |
| 254 | struct usb_interface *intf = to_usb_interface(dev); |
| 255 | struct acm *acm = usb_get_intfdata(intf); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 256 | |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 257 | return sprintf(buf, "%d", acm->ctrl_caps); |
| 258 | } |
| 259 | static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL); |
| 260 | |
| 261 | static ssize_t show_country_codes |
| 262 | (struct device *dev, struct device_attribute *attr, char *buf) |
| 263 | { |
| 264 | struct usb_interface *intf = to_usb_interface(dev); |
| 265 | struct acm *acm = usb_get_intfdata(intf); |
| 266 | |
| 267 | memcpy(buf, acm->country_codes, acm->country_code_size); |
| 268 | return acm->country_code_size; |
| 269 | } |
| 270 | |
| 271 | static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL); |
| 272 | |
| 273 | static ssize_t show_country_rel_date |
| 274 | (struct device *dev, struct device_attribute *attr, char *buf) |
| 275 | { |
| 276 | struct usb_interface *intf = to_usb_interface(dev); |
| 277 | struct acm *acm = usb_get_intfdata(intf); |
| 278 | |
| 279 | return sprintf(buf, "%d", acm->country_rel_date); |
| 280 | } |
| 281 | |
| 282 | static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 283 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | * Interrupt handlers for various ACM device responses |
| 285 | */ |
| 286 | |
Tobias Herzog | ea25835 | 2017-03-30 22:15:11 +0200 | [diff] [blame] | 287 | static void acm_process_notification(struct acm *acm, unsigned char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | int newctrl; |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 290 | int difference; |
Tobias Herzog | ea25835 | 2017-03-30 22:15:11 +0200 | [diff] [blame] | 291 | struct usb_cdc_notification *dr = (struct usb_cdc_notification *)buf; |
| 292 | unsigned char *data = buf + sizeof(struct usb_cdc_notification); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | switch (dr->bNotificationType) { |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 295 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: |
Ladislav Michl | 90744af8 | 2016-11-18 19:01:22 +0100 | [diff] [blame] | 296 | dev_dbg(&acm->control->dev, |
| 297 | "%s - network connection: %d\n", __func__, dr->wValue); |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 298 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 300 | case USB_CDC_NOTIFY_SERIAL_STATE: |
Tobias Herzog | 1bb9914 | 2017-03-30 22:15:10 +0200 | [diff] [blame] | 301 | if (le16_to_cpu(dr->wLength) != 2) { |
| 302 | dev_dbg(&acm->control->dev, |
| 303 | "%s - malformed serial state\n", __func__); |
| 304 | break; |
| 305 | } |
| 306 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 307 | newctrl = get_unaligned_le16(data); |
Tobias Herzog | 2d6dfd1 | 2017-03-30 22:15:12 +0200 | [diff] [blame] | 308 | dev_dbg(&acm->control->dev, |
| 309 | "%s - serial state: 0x%x\n", __func__, newctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Jiri Slaby | aa27a09 | 2013-03-07 13:12:30 +0100 | [diff] [blame] | 311 | if (!acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { |
Ladislav Michl | 90744af8 | 2016-11-18 19:01:22 +0100 | [diff] [blame] | 312 | dev_dbg(&acm->control->dev, |
| 313 | "%s - calling hangup\n", __func__); |
Jiri Slaby | aa27a09 | 2013-03-07 13:12:30 +0100 | [diff] [blame] | 314 | tty_port_tty_hangup(&acm->port, false); |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 317 | difference = acm->ctrlin ^ newctrl; |
| 318 | spin_lock(&acm->read_lock); |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 319 | acm->ctrlin = newctrl; |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 320 | acm->oldcount = acm->iocount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 322 | if (difference & ACM_CTRL_DSR) |
| 323 | acm->iocount.dsr++; |
| 324 | if (difference & ACM_CTRL_BRK) |
| 325 | acm->iocount.brk++; |
| 326 | if (difference & ACM_CTRL_RI) |
| 327 | acm->iocount.rng++; |
| 328 | if (difference & ACM_CTRL_DCD) |
| 329 | acm->iocount.dcd++; |
| 330 | if (difference & ACM_CTRL_FRAMING) |
| 331 | acm->iocount.frame++; |
| 332 | if (difference & ACM_CTRL_PARITY) |
| 333 | acm->iocount.parity++; |
| 334 | if (difference & ACM_CTRL_OVERRUN) |
| 335 | acm->iocount.overrun++; |
| 336 | spin_unlock(&acm->read_lock); |
| 337 | |
| 338 | if (difference) |
| 339 | wake_up_all(&acm->wioctl); |
| 340 | |
| 341 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 343 | default: |
Johan Hovold | a5cc7ef | 2011-03-22 11:12:15 +0100 | [diff] [blame] | 344 | dev_dbg(&acm->control->dev, |
Tobias Herzog | 1bb9914 | 2017-03-30 22:15:10 +0200 | [diff] [blame] | 345 | "%s - unknown notification %d received: index %d len %d\n", |
Johan Hovold | a5cc7ef | 2011-03-22 11:12:15 +0100 | [diff] [blame] | 346 | __func__, |
Tobias Herzog | 1bb9914 | 2017-03-30 22:15:10 +0200 | [diff] [blame] | 347 | dr->bNotificationType, dr->wIndex, dr->wLength); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
Tobias Herzog | ea25835 | 2017-03-30 22:15:11 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* control interface reports status changes with "interrupt" transfers */ |
| 352 | static void acm_ctrl_irq(struct urb *urb) |
| 353 | { |
| 354 | struct acm *acm = urb->context; |
| 355 | struct usb_cdc_notification *dr = urb->transfer_buffer; |
| 356 | unsigned int current_size = urb->actual_length; |
| 357 | unsigned int expected_size, copy_size, alloc_size; |
| 358 | int retval; |
| 359 | int status = urb->status; |
| 360 | |
| 361 | switch (status) { |
| 362 | case 0: |
| 363 | /* success */ |
| 364 | break; |
| 365 | case -ECONNRESET: |
| 366 | case -ENOENT: |
| 367 | case -ESHUTDOWN: |
| 368 | /* this urb is terminated, clean up */ |
| 369 | acm->nb_index = 0; |
| 370 | dev_dbg(&acm->control->dev, |
| 371 | "%s - urb shutting down with status: %d\n", |
| 372 | __func__, status); |
| 373 | return; |
| 374 | default: |
| 375 | dev_dbg(&acm->control->dev, |
| 376 | "%s - nonzero urb status received: %d\n", |
| 377 | __func__, status); |
| 378 | goto exit; |
| 379 | } |
| 380 | |
| 381 | usb_mark_last_busy(acm->dev); |
| 382 | |
| 383 | if (acm->nb_index) |
| 384 | dr = (struct usb_cdc_notification *)acm->notification_buffer; |
| 385 | |
| 386 | /* size = notification-header + (optional) data */ |
| 387 | expected_size = sizeof(struct usb_cdc_notification) + |
| 388 | le16_to_cpu(dr->wLength); |
| 389 | |
| 390 | if (current_size < expected_size) { |
| 391 | /* notification is transmitted fragmented, reassemble */ |
| 392 | if (acm->nb_size < expected_size) { |
| 393 | if (acm->nb_size) { |
| 394 | kfree(acm->notification_buffer); |
| 395 | acm->nb_size = 0; |
| 396 | } |
| 397 | alloc_size = roundup_pow_of_two(expected_size); |
| 398 | /* |
| 399 | * kmalloc ensures a valid notification_buffer after a |
| 400 | * use of kfree in case the previous allocation was too |
| 401 | * small. Final freeing is done on disconnect. |
| 402 | */ |
| 403 | acm->notification_buffer = |
| 404 | kmalloc(alloc_size, GFP_ATOMIC); |
| 405 | if (!acm->notification_buffer) |
| 406 | goto exit; |
| 407 | acm->nb_size = alloc_size; |
| 408 | } |
| 409 | |
| 410 | copy_size = min(current_size, |
| 411 | expected_size - acm->nb_index); |
| 412 | |
| 413 | memcpy(&acm->notification_buffer[acm->nb_index], |
| 414 | urb->transfer_buffer, copy_size); |
| 415 | acm->nb_index += copy_size; |
| 416 | current_size = acm->nb_index; |
| 417 | } |
| 418 | |
| 419 | if (current_size >= expected_size) { |
| 420 | /* notification complete */ |
| 421 | acm_process_notification(acm, (unsigned char *)dr); |
| 422 | acm->nb_index = 0; |
| 423 | } |
| 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | exit: |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 426 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Oliver Neukum | 6c8074e | 2015-03-20 11:25:17 +0100 | [diff] [blame] | 427 | if (retval && retval != -EPERM) |
Ladislav Michl | 90744af8 | 2016-11-18 19:01:22 +0100 | [diff] [blame] | 428 | dev_err(&acm->control->dev, |
| 429 | "%s - usb_submit_urb failed: %d\n", __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 432 | static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 434 | int res; |
Greg Kroah-Hartman | 185d405 | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 435 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 436 | if (!test_and_clear_bit(index, &acm->read_urbs_free)) |
| 437 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 439 | res = usb_submit_urb(acm->read_urbs[index], mem_flags); |
| 440 | if (res) { |
| 441 | if (res != -EPERM) { |
| 442 | dev_err(&acm->data->dev, |
Ladislav Michl | 90744af8 | 2016-11-18 19:01:22 +0100 | [diff] [blame] | 443 | "urb %d failed submission with %d\n", |
| 444 | index, res); |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 445 | } |
| 446 | set_bit(index, &acm->read_urbs_free); |
| 447 | return res; |
Oliver Neukum | 46e7507 | 2016-09-13 16:44:36 +0200 | [diff] [blame] | 448 | } else { |
| 449 | dev_vdbg(&acm->data->dev, "submitted urb %d\n", index); |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int acm_submit_read_urbs(struct acm *acm, gfp_t mem_flags) |
| 456 | { |
| 457 | int res; |
| 458 | int i; |
| 459 | |
| 460 | for (i = 0; i < acm->rx_buflimit; ++i) { |
| 461 | res = acm_submit_read_urb(acm, i, mem_flags); |
| 462 | if (res) |
| 463 | return res; |
| 464 | } |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static void acm_process_read_urb(struct acm *acm, struct urb *urb) |
| 470 | { |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 471 | if (!urb->actual_length) |
| 472 | return; |
| 473 | |
Jiri Slaby | 05c7cd3 | 2013-01-03 15:53:04 +0100 | [diff] [blame] | 474 | tty_insert_flip_string(&acm->port, urb->transfer_buffer, |
| 475 | urb->actual_length); |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 476 | tty_flip_buffer_push(&acm->port); |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | static void acm_read_bulk_callback(struct urb *urb) |
| 480 | { |
| 481 | struct acm_rb *rb = urb->context; |
| 482 | struct acm *acm = rb->instance; |
| 483 | unsigned long flags; |
Oliver Neukum | 36e59e0 | 2015-03-20 09:24:24 +0100 | [diff] [blame] | 484 | int status = urb->status; |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 485 | |
Oliver Neukum | efbe27b | 2016-09-13 16:44:37 +0200 | [diff] [blame] | 486 | dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n", |
Ladislav Michl | 90744af8 | 2016-11-18 19:01:22 +0100 | [diff] [blame] | 487 | rb->index, urb->actual_length, status); |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 488 | |
Ladislav Michl | 1aba579 | 2016-11-18 19:11:26 +0100 | [diff] [blame] | 489 | set_bit(rb->index, &acm->read_urbs_free); |
| 490 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 491 | if (!acm->dev) { |
| 492 | dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | return; |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Ladislav Michl | 1aba579 | 2016-11-18 19:11:26 +0100 | [diff] [blame] | 496 | switch (status) { |
| 497 | case 0: |
| 498 | usb_mark_last_busy(acm->dev); |
| 499 | acm_process_read_urb(acm, urb); |
| 500 | break; |
| 501 | case -EPIPE: |
| 502 | set_bit(EVENT_RX_STALL, &acm->flags); |
| 503 | schedule_work(&acm->work); |
| 504 | return; |
| 505 | case -ENOENT: |
| 506 | case -ECONNRESET: |
| 507 | case -ESHUTDOWN: |
| 508 | dev_dbg(&acm->data->dev, |
| 509 | "%s - urb shutting down with status: %d\n", |
| 510 | __func__, status); |
| 511 | return; |
| 512 | default: |
| 513 | dev_dbg(&acm->data->dev, |
| 514 | "%s - nonzero urb status received: %d\n", |
| 515 | __func__, status); |
| 516 | break; |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 517 | } |
Johan Hovold | 4a8ee50 | 2014-05-26 19:23:49 +0200 | [diff] [blame] | 518 | |
Oliver Neukum | 36e59e0 | 2015-03-20 09:24:24 +0100 | [diff] [blame] | 519 | /* |
| 520 | * Unthrottle may run on another CPU which needs to see events |
| 521 | * in the same order. Submission has an implict barrier |
| 522 | */ |
| 523 | smp_mb__before_atomic(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 525 | /* throttle device if requested by tty */ |
| 526 | spin_lock_irqsave(&acm->read_lock, flags); |
| 527 | acm->throttled = acm->throttle_req; |
Johan Hovold | bbf0cb3 | 2014-05-26 19:23:46 +0200 | [diff] [blame] | 528 | if (!acm->throttled) { |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 529 | spin_unlock_irqrestore(&acm->read_lock, flags); |
| 530 | acm_submit_read_urb(acm, rb->index, GFP_ATOMIC); |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 531 | } else { |
Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 532 | spin_unlock_irqrestore(&acm->read_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* data interface wrote those outgoing bytes */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 537 | static void acm_write_bulk(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 539 | struct acm_wb *wb = urb->context; |
David Brownell | e5fbab5 | 2008-08-06 18:46:10 -0700 | [diff] [blame] | 540 | struct acm *acm = wb->instance; |
Brandon Philips | ad0b65e | 2008-11-06 11:19:11 -0800 | [diff] [blame] | 541 | unsigned long flags; |
Oliver Neukum | 4132cd0 | 2015-03-20 11:41:06 +0100 | [diff] [blame] | 542 | int status = urb->status; |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 543 | |
Oliver Neukum | 4132cd0 | 2015-03-20 11:41:06 +0100 | [diff] [blame] | 544 | if (status || (urb->actual_length != urb->transfer_buffer_length)) |
Oliver Neukum | efbe27b | 2016-09-13 16:44:37 +0200 | [diff] [blame] | 545 | dev_vdbg(&acm->data->dev, "wrote len %d/%d, status %d\n", |
David Brownell | e5fbab5 | 2008-08-06 18:46:10 -0700 | [diff] [blame] | 546 | urb->actual_length, |
| 547 | urb->transfer_buffer_length, |
Oliver Neukum | 4132cd0 | 2015-03-20 11:41:06 +0100 | [diff] [blame] | 548 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Brandon Philips | ad0b65e | 2008-11-06 11:19:11 -0800 | [diff] [blame] | 550 | spin_lock_irqsave(&acm->write_lock, flags); |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 551 | acm_write_done(acm, wb); |
Brandon Philips | ad0b65e | 2008-11-06 11:19:11 -0800 | [diff] [blame] | 552 | spin_unlock_irqrestore(&acm->write_lock, flags); |
Ladislav Michl | 1aba579 | 2016-11-18 19:11:26 +0100 | [diff] [blame] | 553 | set_bit(EVENT_TTY_WAKEUP, &acm->flags); |
Havard Skinnemoen | 99823f4 | 2011-12-09 16:51:54 -0800 | [diff] [blame] | 554 | schedule_work(&acm->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
| 556 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 557 | static void acm_softint(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
Ladislav Michl | 1aba579 | 2016-11-18 19:11:26 +0100 | [diff] [blame] | 559 | int i; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 560 | struct acm *acm = container_of(work, struct acm, work); |
David Brownell | e5fbab5 | 2008-08-06 18:46:10 -0700 | [diff] [blame] | 561 | |
Ladislav Michl | 1aba579 | 2016-11-18 19:11:26 +0100 | [diff] [blame] | 562 | if (test_bit(EVENT_RX_STALL, &acm->flags)) { |
| 563 | if (!(usb_autopm_get_interface(acm->data))) { |
| 564 | for (i = 0; i < acm->rx_buflimit; i++) |
| 565 | usb_kill_urb(acm->read_urbs[i]); |
| 566 | usb_clear_halt(acm->dev, acm->in); |
| 567 | acm_submit_read_urbs(acm, GFP_KERNEL); |
| 568 | usb_autopm_put_interface(acm->data); |
| 569 | } |
| 570 | clear_bit(EVENT_RX_STALL, &acm->flags); |
| 571 | } |
| 572 | |
| 573 | if (test_bit(EVENT_TTY_WAKEUP, &acm->flags)) { |
| 574 | tty_port_tty_wakeup(&acm->port); |
| 575 | clear_bit(EVENT_TTY_WAKEUP, &acm->flags); |
| 576 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /* |
| 580 | * TTY handlers |
| 581 | */ |
| 582 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 583 | static int acm_tty_install(struct tty_driver *driver, struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
| 585 | struct acm *acm; |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 586 | int retval; |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 587 | |
Johan Hovold | 6cb4f4d | 2015-05-18 17:34:11 +0200 | [diff] [blame] | 588 | acm = acm_get_by_minor(tty->index); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 589 | if (!acm) |
| 590 | return -ENODEV; |
| 591 | |
Jiri Slaby | f8a8c10 | 2012-03-05 14:51:48 +0100 | [diff] [blame] | 592 | retval = tty_standard_install(driver, tty); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 593 | if (retval) |
| 594 | goto error_init_termios; |
| 595 | |
| 596 | tty->driver_data = acm; |
| 597 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 598 | return 0; |
| 599 | |
| 600 | error_init_termios: |
| 601 | tty_port_put(&acm->port); |
| 602 | return retval; |
| 603 | } |
| 604 | |
| 605 | static int acm_tty_open(struct tty_struct *tty, struct file *filp) |
| 606 | { |
| 607 | struct acm *acm = tty->driver_data; |
| 608 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 609 | return tty_port_open(&acm->port, tty, filp); |
| 610 | } |
| 611 | |
Johan Hovold | 0943d8e | 2014-05-26 19:23:51 +0200 | [diff] [blame] | 612 | static void acm_port_dtr_rts(struct tty_port *port, int raise) |
| 613 | { |
| 614 | struct acm *acm = container_of(port, struct acm, port); |
| 615 | int val; |
| 616 | int res; |
| 617 | |
| 618 | if (raise) |
| 619 | val = ACM_CTRL_DTR | ACM_CTRL_RTS; |
| 620 | else |
| 621 | val = 0; |
| 622 | |
| 623 | /* FIXME: add missing ctrlout locking throughout driver */ |
| 624 | acm->ctrlout = val; |
| 625 | |
| 626 | res = acm_set_control(acm, val); |
| 627 | if (res && (acm->ctrl_caps & USB_CDC_CAP_LINE)) |
| 628 | dev_err(&acm->control->dev, "failed to set dtr/rts\n"); |
| 629 | } |
| 630 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 631 | static int acm_port_activate(struct tty_port *port, struct tty_struct *tty) |
| 632 | { |
| 633 | struct acm *acm = container_of(port, struct acm, port); |
| 634 | int retval = -ENODEV; |
Johan Hovold | e4c3607 | 2014-05-26 19:23:44 +0200 | [diff] [blame] | 635 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 637 | mutex_lock(&acm->mutex); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 638 | if (acm->disconnected) |
| 639 | goto disconnected; |
| 640 | |
| 641 | retval = usb_autopm_get_interface(acm->control); |
| 642 | if (retval) |
| 643 | goto error_get_interface; |
| 644 | |
| 645 | /* |
| 646 | * FIXME: Why do we need this? Allocating 64K of physically contiguous |
| 647 | * memory is really nasty... |
| 648 | */ |
| 649 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); |
| 650 | acm->control->needs_remote_wakeup = 1; |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | acm->ctrlurb->dev = acm->dev; |
Johan Hovold | 8727bf6 | 2014-05-26 19:23:43 +0200 | [diff] [blame] | 653 | retval = usb_submit_urb(acm->ctrlurb, GFP_KERNEL); |
| 654 | if (retval) { |
Johan Hovold | a5cc7ef | 2011-03-22 11:12:15 +0100 | [diff] [blame] | 655 | dev_err(&acm->control->dev, |
| 656 | "%s - usb_submit_urb(ctrl irq) failed\n", __func__); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 657 | goto error_submit_urb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Jim Paris | 24cb450 | 2014-10-30 11:04:47 -0400 | [diff] [blame] | 660 | acm_tty_set_termios(tty, NULL); |
| 661 | |
Otto Meta | 6c4707f | 2012-06-06 18:46:21 +0200 | [diff] [blame] | 662 | /* |
| 663 | * Unthrottle device in case the TTY was closed while throttled. |
| 664 | */ |
| 665 | spin_lock_irq(&acm->read_lock); |
| 666 | acm->throttled = 0; |
| 667 | acm->throttle_req = 0; |
| 668 | spin_unlock_irq(&acm->read_lock); |
| 669 | |
Johan Hovold | 8727bf6 | 2014-05-26 19:23:43 +0200 | [diff] [blame] | 670 | retval = acm_submit_read_urbs(acm, GFP_KERNEL); |
| 671 | if (retval) |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 672 | goto error_submit_read_urbs; |
Oliver Neukum | 2b626dc | 2010-02-03 17:10:22 +0100 | [diff] [blame] | 673 | |
Johan Hovold | 703df32 | 2014-05-26 19:23:42 +0200 | [diff] [blame] | 674 | usb_autopm_put_interface(acm->control); |
| 675 | |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 676 | mutex_unlock(&acm->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 678 | return 0; |
| 679 | |
| 680 | error_submit_read_urbs: |
Johan Hovold | e4c3607 | 2014-05-26 19:23:44 +0200 | [diff] [blame] | 681 | for (i = 0; i < acm->rx_buflimit; i++) |
| 682 | usb_kill_urb(acm->read_urbs[i]); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 683 | usb_kill_urb(acm->ctrlurb); |
| 684 | error_submit_urb: |
Johan Hovold | 703df32 | 2014-05-26 19:23:42 +0200 | [diff] [blame] | 685 | usb_autopm_put_interface(acm->control); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 686 | error_get_interface: |
| 687 | disconnected: |
| 688 | mutex_unlock(&acm->mutex); |
Johan Hovold | 8727bf6 | 2014-05-26 19:23:43 +0200 | [diff] [blame] | 689 | |
| 690 | return usb_translate_errors(retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 693 | static void acm_port_destruct(struct tty_port *port) |
brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 694 | { |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 695 | struct acm *acm = container_of(port, struct acm, port); |
| 696 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 697 | acm_release_minor(acm); |
brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 698 | usb_put_intf(acm->control); |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 699 | kfree(acm->country_codes); |
brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 700 | kfree(acm); |
| 701 | } |
| 702 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 703 | static void acm_port_shutdown(struct tty_port *port) |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 704 | { |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 705 | struct acm *acm = container_of(port, struct acm, port); |
Johan Hovold | 140cb81 | 2014-05-26 19:23:38 +0200 | [diff] [blame] | 706 | struct urb *urb; |
| 707 | struct acm_wb *wb; |
Johan Hovold | dab54c9 | 2011-03-22 11:12:21 +0100 | [diff] [blame] | 708 | |
Johan Hovold | b1d42ef | 2014-05-26 19:23:48 +0200 | [diff] [blame] | 709 | /* |
| 710 | * Need to grab write_lock to prevent race with resume, but no need to |
| 711 | * hold it due to the tty-port initialised flag. |
| 712 | */ |
| 713 | spin_lock_irq(&acm->write_lock); |
| 714 | spin_unlock_irq(&acm->write_lock); |
| 715 | |
| 716 | usb_autopm_get_interface_no_resume(acm->control); |
| 717 | acm->control->needs_remote_wakeup = 0; |
| 718 | usb_autopm_put_interface(acm->control); |
| 719 | |
Johan Hovold | 89e54e4 | 2014-05-26 19:23:47 +0200 | [diff] [blame] | 720 | for (;;) { |
| 721 | urb = usb_get_from_anchor(&acm->delayed); |
| 722 | if (!urb) |
| 723 | break; |
| 724 | wb = urb->context; |
| 725 | wb->use = 0; |
| 726 | usb_autopm_put_interface_async(acm->control); |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 727 | } |
Johan Hovold | 89e54e4 | 2014-05-26 19:23:47 +0200 | [diff] [blame] | 728 | |
Ladislav Michl | ba8c931 | 2016-11-18 19:07:08 +0100 | [diff] [blame] | 729 | acm_kill_urbs(acm); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | static void acm_tty_cleanup(struct tty_struct *tty) |
| 733 | { |
| 734 | struct acm *acm = tty->driver_data; |
Oliver Neukum | ab57f86 | 2016-09-07 14:30:01 +0200 | [diff] [blame] | 735 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 736 | tty_port_put(&acm->port); |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | static void acm_tty_hangup(struct tty_struct *tty) |
| 740 | { |
| 741 | struct acm *acm = tty->driver_data; |
Oliver Neukum | ab57f86 | 2016-09-07 14:30:01 +0200 | [diff] [blame] | 742 | |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 743 | tty_port_hangup(&acm->port); |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) |
| 747 | { |
| 748 | struct acm *acm = tty->driver_data; |
Oliver Neukum | ab57f86 | 2016-09-07 14:30:01 +0200 | [diff] [blame] | 749 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 750 | tty_port_close(&acm->port, tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 753 | static int acm_tty_write(struct tty_struct *tty, |
| 754 | const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | { |
| 756 | struct acm *acm = tty->driver_data; |
| 757 | int stat; |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 758 | unsigned long flags; |
| 759 | int wbn; |
| 760 | struct acm_wb *wb; |
| 761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | if (!count) |
| 763 | return 0; |
| 764 | |
Oliver Neukum | efbe27b | 2016-09-13 16:44:37 +0200 | [diff] [blame] | 765 | dev_vdbg(&acm->data->dev, "%d bytes from tty layer\n", count); |
Johan Hovold | a5cc7ef | 2011-03-22 11:12:15 +0100 | [diff] [blame] | 766 | |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 767 | spin_lock_irqsave(&acm->write_lock, flags); |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 768 | wbn = acm_wb_alloc(acm); |
| 769 | if (wbn < 0) { |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 770 | spin_unlock_irqrestore(&acm->write_lock, flags); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 771 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 773 | wb = &acm->wb[wbn]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Greg Kroah-Hartman | 71c2fb0 | 2013-06-07 11:42:08 -0700 | [diff] [blame] | 775 | if (!acm->dev) { |
| 776 | wb->use = 0; |
| 777 | spin_unlock_irqrestore(&acm->write_lock, flags); |
| 778 | return -ENODEV; |
| 779 | } |
| 780 | |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 781 | count = (count > acm->writesize) ? acm->writesize : count; |
Oliver Neukum | efbe27b | 2016-09-13 16:44:37 +0200 | [diff] [blame] | 782 | dev_vdbg(&acm->data->dev, "writing %d bytes\n", count); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 783 | memcpy(wb->buf, buf, count); |
| 784 | wb->len = count; |
Greg Kroah-Hartman | 71c2fb0 | 2013-06-07 11:42:08 -0700 | [diff] [blame] | 785 | |
Johan Hovold | 183a450 | 2014-05-26 19:23:41 +0200 | [diff] [blame] | 786 | stat = usb_autopm_get_interface_async(acm->control); |
| 787 | if (stat) { |
| 788 | wb->use = 0; |
| 789 | spin_unlock_irqrestore(&acm->write_lock, flags); |
| 790 | return stat; |
| 791 | } |
| 792 | |
Greg Kroah-Hartman | 71c2fb0 | 2013-06-07 11:42:08 -0700 | [diff] [blame] | 793 | if (acm->susp_count) { |
Oliver Neukum | a81cf97 | 2016-02-10 10:39:49 +0100 | [diff] [blame] | 794 | if (acm->putbuffer) { |
| 795 | /* now to preserve order */ |
| 796 | usb_anchor_urb(acm->putbuffer->urb, &acm->delayed); |
| 797 | acm->putbuffer = NULL; |
| 798 | } |
Johan Hovold | 140cb81 | 2014-05-26 19:23:38 +0200 | [diff] [blame] | 799 | usb_anchor_urb(wb->urb, &acm->delayed); |
Greg Kroah-Hartman | 71c2fb0 | 2013-06-07 11:42:08 -0700 | [diff] [blame] | 800 | spin_unlock_irqrestore(&acm->write_lock, flags); |
Johan Hovold | 140cb81 | 2014-05-26 19:23:38 +0200 | [diff] [blame] | 801 | return count; |
Oliver Neukum | a81cf97 | 2016-02-10 10:39:49 +0100 | [diff] [blame] | 802 | } else { |
| 803 | if (acm->putbuffer) { |
| 804 | /* at this point there is no good way to handle errors */ |
| 805 | acm_start_wb(acm, acm->putbuffer); |
| 806 | acm->putbuffer = NULL; |
| 807 | } |
Greg Kroah-Hartman | 71c2fb0 | 2013-06-07 11:42:08 -0700 | [diff] [blame] | 808 | } |
Greg Kroah-Hartman | 71c2fb0 | 2013-06-07 11:42:08 -0700 | [diff] [blame] | 809 | |
| 810 | stat = acm_start_wb(acm, wb); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 811 | spin_unlock_irqrestore(&acm->write_lock, flags); |
| 812 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 813 | if (stat < 0) |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 814 | return stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | return count; |
| 816 | } |
| 817 | |
Oliver Neukum | a81cf97 | 2016-02-10 10:39:49 +0100 | [diff] [blame] | 818 | static void acm_tty_flush_chars(struct tty_struct *tty) |
| 819 | { |
| 820 | struct acm *acm = tty->driver_data; |
| 821 | struct acm_wb *cur = acm->putbuffer; |
| 822 | int err; |
| 823 | unsigned long flags; |
| 824 | |
Oliver Neukum | 2a14759 | 2016-04-04 14:30:53 +0200 | [diff] [blame] | 825 | if (!cur) /* nothing to do */ |
| 826 | return; |
| 827 | |
Oliver Neukum | a81cf97 | 2016-02-10 10:39:49 +0100 | [diff] [blame] | 828 | acm->putbuffer = NULL; |
| 829 | err = usb_autopm_get_interface_async(acm->control); |
| 830 | spin_lock_irqsave(&acm->write_lock, flags); |
| 831 | if (err < 0) { |
| 832 | cur->use = 0; |
Oliver Neukum | 2a14759 | 2016-04-04 14:30:53 +0200 | [diff] [blame] | 833 | acm->putbuffer = cur; |
Oliver Neukum | a81cf97 | 2016-02-10 10:39:49 +0100 | [diff] [blame] | 834 | goto out; |
| 835 | } |
| 836 | |
| 837 | if (acm->susp_count) |
| 838 | usb_anchor_urb(cur->urb, &acm->delayed); |
| 839 | else |
| 840 | acm_start_wb(acm, cur); |
| 841 | out: |
| 842 | spin_unlock_irqrestore(&acm->write_lock, flags); |
| 843 | return; |
| 844 | } |
| 845 | |
| 846 | static int acm_tty_put_char(struct tty_struct *tty, unsigned char ch) |
| 847 | { |
| 848 | struct acm *acm = tty->driver_data; |
| 849 | struct acm_wb *cur; |
| 850 | int wbn; |
| 851 | unsigned long flags; |
| 852 | |
| 853 | overflow: |
| 854 | cur = acm->putbuffer; |
| 855 | if (!cur) { |
| 856 | spin_lock_irqsave(&acm->write_lock, flags); |
| 857 | wbn = acm_wb_alloc(acm); |
| 858 | if (wbn >= 0) { |
| 859 | cur = &acm->wb[wbn]; |
| 860 | acm->putbuffer = cur; |
| 861 | } |
| 862 | spin_unlock_irqrestore(&acm->write_lock, flags); |
| 863 | if (!cur) |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | if (cur->len == acm->writesize) { |
| 868 | acm_tty_flush_chars(tty); |
| 869 | goto overflow; |
| 870 | } |
| 871 | |
| 872 | cur->buf[cur->len++] = ch; |
| 873 | return 1; |
| 874 | } |
| 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | static int acm_tty_write_room(struct tty_struct *tty) |
| 877 | { |
| 878 | struct acm *acm = tty->driver_data; |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 879 | /* |
| 880 | * Do not let the line discipline to know that we have a reserve, |
| 881 | * or it might get too enthusiastic. |
| 882 | */ |
David Brownell | 934da46 | 2008-08-06 18:44:12 -0700 | [diff] [blame] | 883 | return acm_wb_is_avail(acm) ? acm->writesize : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static int acm_tty_chars_in_buffer(struct tty_struct *tty) |
| 887 | { |
| 888 | struct acm *acm = tty->driver_data; |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 889 | /* |
| 890 | * if the device was unplugged then any remaining characters fell out |
| 891 | * of the connector ;) |
| 892 | */ |
| 893 | if (acm->disconnected) |
Alan Cox | 23198fd | 2009-07-20 16:05:27 +0100 | [diff] [blame] | 894 | return 0; |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 895 | /* |
| 896 | * This is inaccurate (overcounts), but it works. |
| 897 | */ |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 898 | return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | static void acm_tty_throttle(struct tty_struct *tty) |
| 902 | { |
| 903 | struct acm *acm = tty->driver_data; |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 904 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 905 | spin_lock_irq(&acm->read_lock); |
| 906 | acm->throttle_req = 1; |
| 907 | spin_unlock_irq(&acm->read_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static void acm_tty_unthrottle(struct tty_struct *tty) |
| 911 | { |
| 912 | struct acm *acm = tty->driver_data; |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 913 | unsigned int was_throttled; |
| 914 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 915 | spin_lock_irq(&acm->read_lock); |
| 916 | was_throttled = acm->throttled; |
| 917 | acm->throttled = 0; |
| 918 | acm->throttle_req = 0; |
| 919 | spin_unlock_irq(&acm->read_lock); |
| 920 | |
| 921 | if (was_throttled) |
| 922 | acm_submit_read_urbs(acm, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Alan Cox | 9e98966c | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 925 | static int acm_tty_break_ctl(struct tty_struct *tty, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | { |
| 927 | struct acm *acm = tty->driver_data; |
Alan Cox | 9e98966c | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 928 | int retval; |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 929 | |
Alan Cox | 9e98966c | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 930 | retval = acm_send_break(acm, state ? 0xffff : 0); |
| 931 | if (retval < 0) |
Ladislav Michl | 90744af8 | 2016-11-18 19:01:22 +0100 | [diff] [blame] | 932 | dev_dbg(&acm->control->dev, |
| 933 | "%s - send break failed\n", __func__); |
Alan Cox | 9e98966c | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 934 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 937 | static int acm_tty_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | { |
| 939 | struct acm *acm = tty->driver_data; |
| 940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) | |
| 942 | (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) | |
| 943 | (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) | |
| 944 | (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) | |
| 945 | (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) | |
| 946 | TIOCM_CTS; |
| 947 | } |
| 948 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 949 | static int acm_tty_tiocmset(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | unsigned int set, unsigned int clear) |
| 951 | { |
| 952 | struct acm *acm = tty->driver_data; |
| 953 | unsigned int newctrl; |
| 954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | newctrl = acm->ctrlout; |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 956 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | |
| 957 | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); |
| 958 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | |
| 959 | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
| 961 | newctrl = (newctrl & ~clear) | set; |
| 962 | |
| 963 | if (acm->ctrlout == newctrl) |
| 964 | return 0; |
| 965 | return acm_set_control(acm, acm->ctrlout = newctrl); |
| 966 | } |
| 967 | |
Oliver Neukum | 18c7572 | 2012-02-17 17:21:24 -0500 | [diff] [blame] | 968 | static int get_serial_info(struct acm *acm, struct serial_struct __user *info) |
| 969 | { |
| 970 | struct serial_struct tmp; |
| 971 | |
Oliver Neukum | 18c7572 | 2012-02-17 17:21:24 -0500 | [diff] [blame] | 972 | memset(&tmp, 0, sizeof(tmp)); |
Oliver Neukum | 18c7572 | 2012-02-17 17:21:24 -0500 | [diff] [blame] | 973 | tmp.xmit_fifo_size = acm->writesize; |
| 974 | tmp.baud_base = le32_to_cpu(acm->line.dwDTERate); |
Dan Williams | ba2d8ce | 2012-11-08 12:47:41 -0600 | [diff] [blame] | 975 | tmp.close_delay = acm->port.close_delay / 10; |
| 976 | tmp.closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? |
| 977 | ASYNC_CLOSING_WAIT_NONE : |
| 978 | acm->port.closing_wait / 10; |
Oliver Neukum | 18c7572 | 2012-02-17 17:21:24 -0500 | [diff] [blame] | 979 | |
| 980 | if (copy_to_user(info, &tmp, sizeof(tmp))) |
| 981 | return -EFAULT; |
| 982 | else |
| 983 | return 0; |
| 984 | } |
| 985 | |
Dan Williams | ba2d8ce | 2012-11-08 12:47:41 -0600 | [diff] [blame] | 986 | static int set_serial_info(struct acm *acm, |
| 987 | struct serial_struct __user *newinfo) |
| 988 | { |
| 989 | struct serial_struct new_serial; |
| 990 | unsigned int closing_wait, close_delay; |
| 991 | int retval = 0; |
| 992 | |
| 993 | if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) |
| 994 | return -EFAULT; |
| 995 | |
| 996 | close_delay = new_serial.close_delay * 10; |
| 997 | closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ? |
| 998 | ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10; |
| 999 | |
| 1000 | mutex_lock(&acm->port.mutex); |
| 1001 | |
| 1002 | if (!capable(CAP_SYS_ADMIN)) { |
| 1003 | if ((close_delay != acm->port.close_delay) || |
| 1004 | (closing_wait != acm->port.closing_wait)) |
| 1005 | retval = -EPERM; |
| 1006 | else |
| 1007 | retval = -EOPNOTSUPP; |
| 1008 | } else { |
| 1009 | acm->port.close_delay = close_delay; |
| 1010 | acm->port.closing_wait = closing_wait; |
| 1011 | } |
| 1012 | |
| 1013 | mutex_unlock(&acm->port.mutex); |
| 1014 | return retval; |
| 1015 | } |
| 1016 | |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 1017 | static int wait_serial_change(struct acm *acm, unsigned long arg) |
| 1018 | { |
| 1019 | int rv = 0; |
| 1020 | DECLARE_WAITQUEUE(wait, current); |
| 1021 | struct async_icount old, new; |
| 1022 | |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 1023 | do { |
| 1024 | spin_lock_irq(&acm->read_lock); |
| 1025 | old = acm->oldcount; |
| 1026 | new = acm->iocount; |
| 1027 | acm->oldcount = new; |
| 1028 | spin_unlock_irq(&acm->read_lock); |
| 1029 | |
| 1030 | if ((arg & TIOCM_DSR) && |
| 1031 | old.dsr != new.dsr) |
| 1032 | break; |
| 1033 | if ((arg & TIOCM_CD) && |
| 1034 | old.dcd != new.dcd) |
| 1035 | break; |
| 1036 | if ((arg & TIOCM_RI) && |
| 1037 | old.rng != new.rng) |
| 1038 | break; |
| 1039 | |
| 1040 | add_wait_queue(&acm->wioctl, &wait); |
| 1041 | set_current_state(TASK_INTERRUPTIBLE); |
| 1042 | schedule(); |
| 1043 | remove_wait_queue(&acm->wioctl, &wait); |
| 1044 | if (acm->disconnected) { |
| 1045 | if (arg & TIOCM_CD) |
| 1046 | break; |
| 1047 | else |
| 1048 | rv = -ENODEV; |
| 1049 | } else { |
| 1050 | if (signal_pending(current)) |
| 1051 | rv = -ERESTARTSYS; |
| 1052 | } |
| 1053 | } while (!rv); |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | return rv; |
| 1058 | } |
| 1059 | |
Johan Hovold | bb2d387 | 2016-11-08 13:28:24 +0100 | [diff] [blame] | 1060 | static int acm_tty_get_icount(struct tty_struct *tty, |
| 1061 | struct serial_icounter_struct *icount) |
Oliver Neukum | 797ef13 | 2013-11-20 11:35:35 +0100 | [diff] [blame] | 1062 | { |
Johan Hovold | bb2d387 | 2016-11-08 13:28:24 +0100 | [diff] [blame] | 1063 | struct acm *acm = tty->driver_data; |
Oliver Neukum | 797ef13 | 2013-11-20 11:35:35 +0100 | [diff] [blame] | 1064 | |
Johan Hovold | bb2d387 | 2016-11-08 13:28:24 +0100 | [diff] [blame] | 1065 | icount->dsr = acm->iocount.dsr; |
| 1066 | icount->rng = acm->iocount.rng; |
| 1067 | icount->dcd = acm->iocount.dcd; |
| 1068 | icount->frame = acm->iocount.frame; |
| 1069 | icount->overrun = acm->iocount.overrun; |
| 1070 | icount->parity = acm->iocount.parity; |
| 1071 | icount->brk = acm->iocount.brk; |
Oliver Neukum | 797ef13 | 2013-11-20 11:35:35 +0100 | [diff] [blame] | 1072 | |
Johan Hovold | bb2d387 | 2016-11-08 13:28:24 +0100 | [diff] [blame] | 1073 | return 0; |
Oliver Neukum | 797ef13 | 2013-11-20 11:35:35 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 1076 | static int acm_tty_ioctl(struct tty_struct *tty, |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1077 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | { |
Oliver Neukum | 18c7572 | 2012-02-17 17:21:24 -0500 | [diff] [blame] | 1079 | struct acm *acm = tty->driver_data; |
| 1080 | int rv = -ENOIOCTLCMD; |
| 1081 | |
| 1082 | switch (cmd) { |
| 1083 | case TIOCGSERIAL: /* gets serial port data */ |
| 1084 | rv = get_serial_info(acm, (struct serial_struct __user *) arg); |
| 1085 | break; |
Dan Williams | ba2d8ce | 2012-11-08 12:47:41 -0600 | [diff] [blame] | 1086 | case TIOCSSERIAL: |
| 1087 | rv = set_serial_info(acm, (struct serial_struct __user *) arg); |
| 1088 | break; |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 1089 | case TIOCMIWAIT: |
Oliver Neukum | 8fdbeb2 | 2013-11-20 11:35:36 +0100 | [diff] [blame] | 1090 | rv = usb_autopm_get_interface(acm->control); |
| 1091 | if (rv < 0) { |
| 1092 | rv = -EIO; |
| 1093 | break; |
| 1094 | } |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 1095 | rv = wait_serial_change(acm, arg); |
Oliver Neukum | 8fdbeb2 | 2013-11-20 11:35:36 +0100 | [diff] [blame] | 1096 | usb_autopm_put_interface(acm->control); |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 1097 | break; |
Oliver Neukum | 18c7572 | 2012-02-17 17:21:24 -0500 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1103 | static void acm_tty_set_termios(struct tty_struct *tty, |
| 1104 | struct ktermios *termios_old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | { |
| 1106 | struct acm *acm = tty->driver_data; |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 1107 | struct ktermios *termios = &tty->termios; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | struct usb_cdc_line_coding newline; |
| 1109 | int newctrl = acm->ctrlout; |
| 1110 | |
Alan Cox | 9b80fee | 2009-09-19 13:13:23 -0700 | [diff] [blame] | 1111 | newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; |
| 1113 | newline.bParityType = termios->c_cflag & PARENB ? |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1114 | (termios->c_cflag & PARODD ? 1 : 2) + |
| 1115 | (termios->c_cflag & CMSPAR ? 2 : 0) : 0; |
Nicolas Boullis | 301a29d | 2012-10-16 00:06:23 +0200 | [diff] [blame] | 1116 | switch (termios->c_cflag & CSIZE) { |
| 1117 | case CS5: |
| 1118 | newline.bDataBits = 5; |
| 1119 | break; |
| 1120 | case CS6: |
| 1121 | newline.bDataBits = 6; |
| 1122 | break; |
| 1123 | case CS7: |
| 1124 | newline.bDataBits = 7; |
| 1125 | break; |
| 1126 | case CS8: |
| 1127 | default: |
| 1128 | newline.bDataBits = 8; |
| 1129 | break; |
| 1130 | } |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1131 | /* FIXME: Needs to clear unsupported bits in the termios */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); |
| 1133 | |
Johan Hovold | 4473d05 | 2014-11-05 18:41:59 +0100 | [diff] [blame] | 1134 | if (C_BAUD(tty) == B0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | newline.dwDTERate = acm->line.dwDTERate; |
| 1136 | newctrl &= ~ACM_CTRL_DTR; |
Johan Hovold | 4473d05 | 2014-11-05 18:41:59 +0100 | [diff] [blame] | 1137 | } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) { |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1138 | newctrl |= ACM_CTRL_DTR; |
Johan Hovold | 4473d05 | 2014-11-05 18:41:59 +0100 | [diff] [blame] | 1139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
| 1141 | if (newctrl != acm->ctrlout) |
| 1142 | acm_set_control(acm, acm->ctrlout = newctrl); |
| 1143 | |
| 1144 | if (memcmp(&acm->line, &newline, sizeof newline)) { |
| 1145 | memcpy(&acm->line, &newline, sizeof newline); |
Johan Hovold | a5cc7ef | 2011-03-22 11:12:15 +0100 | [diff] [blame] | 1146 | dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n", |
| 1147 | __func__, |
| 1148 | le32_to_cpu(newline.dwDTERate), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | newline.bCharFormat, newline.bParityType, |
| 1150 | newline.bDataBits); |
| 1151 | acm_set_line(acm, &acm->line); |
| 1152 | } |
| 1153 | } |
| 1154 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1155 | static const struct tty_port_operations acm_port_ops = { |
Johan Hovold | 0943d8e | 2014-05-26 19:23:51 +0200 | [diff] [blame] | 1156 | .dtr_rts = acm_port_dtr_rts, |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1157 | .shutdown = acm_port_shutdown, |
| 1158 | .activate = acm_port_activate, |
| 1159 | .destruct = acm_port_destruct, |
| 1160 | }; |
| 1161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | /* |
| 1163 | * USB probe and disconnect routines. |
| 1164 | */ |
| 1165 | |
Oliver Neukum | 830f402 | 2008-06-25 14:17:16 +0200 | [diff] [blame] | 1166 | /* Little helpers: write/read buffers free */ |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1167 | static void acm_write_buffers_free(struct acm *acm) |
| 1168 | { |
| 1169 | int i; |
| 1170 | struct acm_wb *wb; |
| 1171 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1172 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) |
Ladislav Michl | e461460 | 2016-11-18 19:06:10 +0100 | [diff] [blame] | 1173 | usb_free_coherent(acm->dev, acm->writesize, wb->buf, wb->dmah); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1174 | } |
| 1175 | |
Oliver Neukum | 830f402 | 2008-06-25 14:17:16 +0200 | [diff] [blame] | 1176 | static void acm_read_buffers_free(struct acm *acm) |
| 1177 | { |
Johan Hovold | dab54c9 | 2011-03-22 11:12:21 +0100 | [diff] [blame] | 1178 | int i; |
Oliver Neukum | 830f402 | 2008-06-25 14:17:16 +0200 | [diff] [blame] | 1179 | |
Johan Hovold | dab54c9 | 2011-03-22 11:12:21 +0100 | [diff] [blame] | 1180 | for (i = 0; i < acm->rx_buflimit; i++) |
Ladislav Michl | e461460 | 2016-11-18 19:06:10 +0100 | [diff] [blame] | 1181 | usb_free_coherent(acm->dev, acm->readsize, |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1182 | acm->read_buffers[i].base, acm->read_buffers[i].dma); |
Oliver Neukum | 830f402 | 2008-06-25 14:17:16 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1185 | /* Little helper: write buffers allocate */ |
| 1186 | static int acm_write_buffers_alloc(struct acm *acm) |
| 1187 | { |
| 1188 | int i; |
| 1189 | struct acm_wb *wb; |
| 1190 | |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1191 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1192 | wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL, |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1193 | &wb->dmah); |
| 1194 | if (!wb->buf) { |
| 1195 | while (i != 0) { |
| 1196 | --i; |
| 1197 | --wb; |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1198 | usb_free_coherent(acm->dev, acm->writesize, |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1199 | wb->buf, wb->dmah); |
| 1200 | } |
| 1201 | return -ENOMEM; |
| 1202 | } |
| 1203 | } |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 1207 | static int acm_probe(struct usb_interface *intf, |
| 1208 | const struct usb_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | { |
| 1210 | struct usb_cdc_union_desc *union_header = NULL; |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1211 | struct usb_cdc_call_mgmt_descriptor *cmgmd = NULL; |
David Brownell | c6dbf55 | 2008-04-13 14:00:44 -0700 | [diff] [blame] | 1212 | unsigned char *buffer = intf->altsetting->extra; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | int buflen = intf->altsetting->extralen; |
| 1214 | struct usb_interface *control_interface; |
| 1215 | struct usb_interface *data_interface; |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1216 | struct usb_endpoint_descriptor *epctrl = NULL; |
| 1217 | struct usb_endpoint_descriptor *epread = NULL; |
| 1218 | struct usb_endpoint_descriptor *epwrite = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1220 | struct usb_cdc_parsed_header h; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | struct acm *acm; |
| 1222 | int minor; |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1223 | int ctrlsize, readsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | u8 *buf; |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1225 | int call_intf_num = -1; |
| 1226 | int data_intf_num = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | unsigned long quirks; |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1228 | int num_rx_buf; |
David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1229 | int i; |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1230 | int combined_interfaces = 0; |
Alexey Khoroshilov | c93d819 | 2013-03-16 01:30:32 +0400 | [diff] [blame] | 1231 | struct device *tty_dev; |
| 1232 | int rv = -ENOMEM; |
Johan Hovold | f8d8464 | 2017-03-17 11:35:48 +0100 | [diff] [blame] | 1233 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1235 | /* normal quirks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | quirks = (unsigned long)id->driver_info; |
Dmitry Torokhov | 1614265 | 2013-02-02 11:02:14 -0800 | [diff] [blame] | 1237 | |
| 1238 | if (quirks == IGNORE_DEVICE) |
| 1239 | return -ENODEV; |
| 1240 | |
Oliver Neukum | 7309aa8 | 2016-11-02 14:42:52 +0100 | [diff] [blame] | 1241 | memset(&h, 0x00, sizeof(struct usb_cdc_parsed_header)); |
| 1242 | |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1243 | num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR; |
| 1244 | |
| 1245 | /* handle quirks deadly to normal probing*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | if (quirks == NO_UNION_NORMAL) { |
| 1247 | data_interface = usb_ifnum_to_if(usb_dev, 1); |
| 1248 | control_interface = usb_ifnum_to_if(usb_dev, 0); |
Oliver Neukum | 8835ba4 | 2016-03-15 10:14:04 +0100 | [diff] [blame] | 1249 | /* we would crash */ |
| 1250 | if (!data_interface || !control_interface) |
| 1251 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | goto skip_normal_probe; |
| 1253 | } |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | /* normal probing*/ |
| 1256 | if (!buffer) { |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 1257 | dev_err(&intf->dev, "Weird descriptor references\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | return -EINVAL; |
| 1259 | } |
| 1260 | |
Oliver Neukum | 2ad9d54 | 2016-09-20 15:45:42 +0200 | [diff] [blame] | 1261 | if (!intf->cur_altsetting) |
| 1262 | return -EINVAL; |
| 1263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | if (!buflen) { |
Toby Gray | 577045c | 2010-09-02 10:46:20 +0100 | [diff] [blame] | 1265 | if (intf->cur_altsetting->endpoint && |
| 1266 | intf->cur_altsetting->endpoint->extralen && |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1267 | intf->cur_altsetting->endpoint->extra) { |
| 1268 | dev_dbg(&intf->dev, |
| 1269 | "Seeking extra descriptors on endpoint\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | buflen = intf->cur_altsetting->endpoint->extralen; |
| 1271 | buffer = intf->cur_altsetting->endpoint->extra; |
| 1272 | } else { |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 1273 | dev_err(&intf->dev, |
| 1274 | "Zero length descriptor references\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | return -EINVAL; |
| 1276 | } |
| 1277 | } |
| 1278 | |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1279 | cdc_parse_cdc_header(&h, intf, buffer, buflen); |
| 1280 | union_header = h.usb_cdc_union_desc; |
| 1281 | cmgmd = h.usb_cdc_call_mgmt_descriptor; |
| 1282 | if (cmgmd) |
| 1283 | call_intf_num = cmgmd->bDataInterface; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
| 1285 | if (!union_header) { |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1286 | if (call_intf_num > 0) { |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1287 | dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); |
Erik Slagter | fd5054c1 | 2011-05-11 12:06:55 +0200 | [diff] [blame] | 1288 | /* quirks for Droids MuIn LCD */ |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1289 | if (quirks & NO_DATA_INTERFACE) { |
Erik Slagter | fd5054c1 | 2011-05-11 12:06:55 +0200 | [diff] [blame] | 1290 | data_interface = usb_ifnum_to_if(usb_dev, 0); |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1291 | } else { |
| 1292 | data_intf_num = call_intf_num; |
| 1293 | data_interface = usb_ifnum_to_if(usb_dev, data_intf_num); |
| 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | control_interface = intf; |
| 1296 | } else { |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1297 | if (intf->cur_altsetting->desc.bNumEndpoints != 3) { |
| 1298 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); |
| 1299 | return -ENODEV; |
| 1300 | } else { |
| 1301 | dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n"); |
| 1302 | combined_interfaces = 1; |
| 1303 | control_interface = data_interface = intf; |
| 1304 | goto look_for_collapsed_interface; |
| 1305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | } |
| 1307 | } else { |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1308 | data_intf_num = union_header->bSlaveInterface0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1310 | data_interface = usb_ifnum_to_if(usb_dev, data_intf_num); |
Greg Kroah-Hartman | 403dff4 | 2014-11-07 08:48:15 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | if (!control_interface || !data_interface) { |
| 1314 | dev_dbg(&intf->dev, "no interfaces\n"); |
| 1315 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | } |
Oliver Neukum | 2ad9d54 | 2016-09-20 15:45:42 +0200 | [diff] [blame] | 1317 | if (!data_interface->cur_altsetting || !control_interface->cur_altsetting) |
| 1318 | return -ENODEV; |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1319 | |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1320 | if (data_intf_num != call_intf_num) |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1321 | dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1323 | if (control_interface == data_interface) { |
| 1324 | /* some broken devices designed for windows work this way */ |
| 1325 | dev_warn(&intf->dev,"Control and data interfaces are not separated!\n"); |
| 1326 | combined_interfaces = 1; |
| 1327 | /* a popular other OS doesn't use it */ |
| 1328 | quirks |= NO_CAP_LINE; |
| 1329 | if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) { |
| 1330 | dev_err(&intf->dev, "This needs exactly 3 endpoints\n"); |
| 1331 | return -EINVAL; |
| 1332 | } |
| 1333 | look_for_collapsed_interface: |
Johan Hovold | f8d8464 | 2017-03-17 11:35:48 +0100 | [diff] [blame] | 1334 | res = usb_find_common_endpoints(data_interface->cur_altsetting, |
| 1335 | &epread, &epwrite, &epctrl, NULL); |
| 1336 | if (res) |
| 1337 | return res; |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1338 | |
Johan Hovold | f8d8464 | 2017-03-17 11:35:48 +0100 | [diff] [blame] | 1339 | goto made_compressed_probe; |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | skip_normal_probe: |
| 1343 | |
| 1344 | /*workaround for switched interfaces */ |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1345 | if (data_interface->cur_altsetting->desc.bInterfaceClass |
| 1346 | != CDC_DATA_INTERFACE_TYPE) { |
| 1347 | if (control_interface->cur_altsetting->desc.bInterfaceClass |
| 1348 | == CDC_DATA_INTERFACE_TYPE) { |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1349 | dev_dbg(&intf->dev, |
| 1350 | "Your device has switched interfaces.\n"); |
Fabian Frederick | 2cfef79 | 2015-05-18 19:59:37 +0200 | [diff] [blame] | 1351 | swap(control_interface, data_interface); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | } else { |
| 1353 | return -EINVAL; |
| 1354 | } |
| 1355 | } |
Alan Stern | 74da5d6 | 2007-08-02 13:29:10 -0400 | [diff] [blame] | 1356 | |
| 1357 | /* Accept probe requests only for the control interface */ |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1358 | if (!combined_interfaces && intf != control_interface) |
Alan Stern | 74da5d6 | 2007-08-02 13:29:10 -0400 | [diff] [blame] | 1359 | return -ENODEV; |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1360 | |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1361 | if (!combined_interfaces && usb_interface_claimed(data_interface)) { |
| 1362 | /* valid in this context */ |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1363 | dev_dbg(&intf->dev, "The data interface isn't available\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | return -EBUSY; |
| 1365 | } |
| 1366 | |
| 1367 | |
Sven Schnelle | 99f347c | 2012-08-17 21:43:43 +0200 | [diff] [blame] | 1368 | if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 || |
| 1369 | control_interface->cur_altsetting->desc.bNumEndpoints == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | return -EINVAL; |
| 1371 | |
| 1372 | epctrl = &control_interface->cur_altsetting->endpoint[0].desc; |
| 1373 | epread = &data_interface->cur_altsetting->endpoint[0].desc; |
| 1374 | epwrite = &data_interface->cur_altsetting->endpoint[1].desc; |
| 1375 | |
| 1376 | |
| 1377 | /* workaround for switched endpoints */ |
Luiz Fernando N. Capitulino | 45aea70 | 2006-10-26 13:02:48 -0300 | [diff] [blame] | 1378 | if (!usb_endpoint_dir_in(epread)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | /* descriptors are swapped */ |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1380 | dev_dbg(&intf->dev, |
| 1381 | "The data interface has switched endpoints\n"); |
Fabian Frederick | 2cfef79 | 2015-05-18 19:59:37 +0200 | [diff] [blame] | 1382 | swap(epread, epwrite); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | } |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1384 | made_compressed_probe: |
Johan Hovold | a5cc7ef | 2011-03-22 11:12:15 +0100 | [diff] [blame] | 1385 | dev_dbg(&intf->dev, "interfaces are valid\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1387 | acm = kzalloc(sizeof(struct acm), GFP_KERNEL); |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1388 | if (acm == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | goto alloc_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1391 | minor = acm_alloc_minor(acm); |
Oliver Neukum | 6dd3587 | 2016-07-14 15:41:32 +0200 | [diff] [blame] | 1392 | if (minor < 0) |
| 1393 | goto alloc_fail1; |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1394 | |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 1395 | ctrlsize = usb_endpoint_maxp(epctrl); |
| 1396 | readsize = usb_endpoint_maxp(epread) * |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1397 | (quirks == SINGLE_RX_URB ? 1 : 2); |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1398 | acm->combined_interfaces = combined_interfaces; |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 1399 | acm->writesize = usb_endpoint_maxp(epwrite) * 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | acm->control = control_interface; |
| 1401 | acm->data = data_interface; |
| 1402 | acm->minor = minor; |
| 1403 | acm->dev = usb_dev; |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1404 | if (h.usb_cdc_acm_descriptor) |
| 1405 | acm->ctrl_caps = h.usb_cdc_acm_descriptor->bmCapabilities; |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1406 | if (quirks & NO_CAP_LINE) |
| 1407 | acm->ctrl_caps &= ~USB_CDC_CAP_LINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | acm->ctrlsize = ctrlsize; |
| 1409 | acm->readsize = readsize; |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1410 | acm->rx_buflimit = num_rx_buf; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1411 | INIT_WORK(&acm->work, acm_softint); |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 1412 | init_waitqueue_head(&acm->wioctl); |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1413 | spin_lock_init(&acm->write_lock); |
David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1414 | spin_lock_init(&acm->read_lock); |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1415 | mutex_init(&acm->mutex); |
Ladislav Michl | d305394 | 2016-11-18 19:10:19 +0100 | [diff] [blame] | 1416 | if (usb_endpoint_xfer_int(epread)) { |
Oliver Neukum | cf7fdd5 | 2009-08-04 23:52:09 +0200 | [diff] [blame] | 1417 | acm->bInterval = epread->bInterval; |
Ladislav Michl | 74bccc9 | 2016-11-18 19:09:19 +0100 | [diff] [blame] | 1418 | acm->in = usb_rcvintpipe(usb_dev, epread->bEndpointAddress); |
| 1419 | } else { |
| 1420 | acm->in = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); |
| 1421 | } |
| 1422 | if (usb_endpoint_xfer_int(epwrite)) |
| 1423 | acm->out = usb_sndintpipe(usb_dev, epwrite->bEndpointAddress); |
| 1424 | else |
| 1425 | acm->out = usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress); |
Alan Cox | 739e028 | 2009-06-11 12:27:50 +0100 | [diff] [blame] | 1426 | tty_port_init(&acm->port); |
| 1427 | acm->port.ops = &acm_port_ops; |
Johan Hovold | 140cb81 | 2014-05-26 19:23:38 +0200 | [diff] [blame] | 1428 | init_usb_anchor(&acm->delayed); |
Johan Hovold | 2a8cdfd | 2014-11-06 18:08:33 +0100 | [diff] [blame] | 1429 | acm->quirks = quirks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1431 | buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1432 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | goto alloc_fail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | acm->ctrl_buffer = buf; |
| 1435 | |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1436 | if (acm_write_buffers_alloc(acm) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | goto alloc_fail4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | |
| 1439 | acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1440 | if (!acm->ctrlurb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | goto alloc_fail5; |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1442 | |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1443 | for (i = 0; i < num_rx_buf; i++) { |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1444 | struct acm_rb *rb = &(acm->read_buffers[i]); |
| 1445 | struct urb *urb; |
David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1446 | |
Johan Hovold | 74f5e1b | 2011-03-22 11:12:23 +0100 | [diff] [blame] | 1447 | rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL, |
| 1448 | &rb->dma); |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1449 | if (!rb->base) |
Johan Hovold | 74f5e1b | 2011-03-22 11:12:23 +0100 | [diff] [blame] | 1450 | goto alloc_fail6; |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1451 | rb->index = i; |
| 1452 | rb->instance = acm; |
Johan Hovold | 74f5e1b | 2011-03-22 11:12:23 +0100 | [diff] [blame] | 1453 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1454 | urb = usb_alloc_urb(0, GFP_KERNEL); |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1455 | if (!urb) |
Axel Lin | c2572b7 | 2010-05-31 08:04:47 +0800 | [diff] [blame] | 1456 | goto alloc_fail6; |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1457 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1458 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 1459 | urb->transfer_dma = rb->dma; |
Ladislav Michl | d305394 | 2016-11-18 19:10:19 +0100 | [diff] [blame] | 1460 | if (usb_endpoint_xfer_int(epread)) |
Ladislav Michl | 74bccc9 | 2016-11-18 19:09:19 +0100 | [diff] [blame] | 1461 | usb_fill_int_urb(urb, acm->dev, acm->in, rb->base, |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1462 | acm->readsize, |
| 1463 | acm_read_bulk_callback, rb, |
| 1464 | acm->bInterval); |
Ladislav Michl | 74bccc9 | 2016-11-18 19:09:19 +0100 | [diff] [blame] | 1465 | else |
| 1466 | usb_fill_bulk_urb(urb, acm->dev, acm->in, rb->base, |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1467 | acm->readsize, |
| 1468 | acm_read_bulk_callback, rb); |
David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1469 | |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1470 | acm->read_urbs[i] = urb; |
| 1471 | __set_bit(i, &acm->read_urbs_free); |
David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1472 | } |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1473 | for (i = 0; i < ACM_NW; i++) { |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1474 | struct acm_wb *snd = &(acm->wb[i]); |
| 1475 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1476 | snd->urb = usb_alloc_urb(0, GFP_KERNEL); |
Oliver Neukum | 17136d4 | 2015-01-28 16:56:24 +0100 | [diff] [blame] | 1477 | if (snd->urb == NULL) |
Johan Hovold | 74f5e1b | 2011-03-22 11:12:23 +0100 | [diff] [blame] | 1478 | goto alloc_fail7; |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1479 | |
Arseniy Lartsev | 5186ffe | 2009-07-01 16:27:26 +0400 | [diff] [blame] | 1480 | if (usb_endpoint_xfer_int(epwrite)) |
Ladislav Michl | 74bccc9 | 2016-11-18 19:09:19 +0100 | [diff] [blame] | 1481 | usb_fill_int_urb(snd->urb, usb_dev, acm->out, |
Arseniy Lartsev | 5186ffe | 2009-07-01 16:27:26 +0400 | [diff] [blame] | 1482 | NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval); |
| 1483 | else |
Ladislav Michl | 74bccc9 | 2016-11-18 19:09:19 +0100 | [diff] [blame] | 1484 | usb_fill_bulk_urb(snd->urb, usb_dev, acm->out, |
Arseniy Lartsev | 5186ffe | 2009-07-01 16:27:26 +0400 | [diff] [blame] | 1485 | NULL, acm->writesize, acm_write_bulk, snd); |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1486 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
Lu Baolu | ffdb1e3 | 2016-01-06 15:10:04 +0800 | [diff] [blame] | 1487 | if (quirks & SEND_ZERO_PACKET) |
| 1488 | snd->urb->transfer_flags |= URB_ZERO_PACKET; |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1489 | snd->instance = acm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1492 | usb_set_intfdata(intf, acm); |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1493 | |
| 1494 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); |
| 1495 | if (i < 0) |
Johan Hovold | 74f5e1b | 2011-03-22 11:12:23 +0100 | [diff] [blame] | 1496 | goto alloc_fail7; |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1497 | |
Oliver Neukum | cb42b63 | 2016-07-14 15:41:34 +0200 | [diff] [blame] | 1498 | if (h.usb_cdc_country_functional_desc) { /* export the country data */ |
| 1499 | struct usb_cdc_country_functional_desc * cfd = |
| 1500 | h.usb_cdc_country_functional_desc; |
| 1501 | |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1502 | acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); |
| 1503 | if (!acm->country_codes) |
| 1504 | goto skip_countries; |
| 1505 | acm->country_code_size = cfd->bLength - 4; |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1506 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, |
| 1507 | cfd->bLength - 4); |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1508 | acm->country_rel_date = cfd->iCountryCodeRelDate; |
| 1509 | |
| 1510 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); |
| 1511 | if (i < 0) { |
| 1512 | kfree(acm->country_codes); |
Julia Lawall | e7c8e86 | 2011-12-23 14:02:55 +0100 | [diff] [blame] | 1513 | acm->country_codes = NULL; |
| 1514 | acm->country_code_size = 0; |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1515 | goto skip_countries; |
| 1516 | } |
| 1517 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1518 | i = device_create_file(&intf->dev, |
| 1519 | &dev_attr_iCountryCodeRelDate); |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1520 | if (i < 0) { |
Axel Lin | c2572b7 | 2010-05-31 08:04:47 +0800 | [diff] [blame] | 1521 | device_remove_file(&intf->dev, &dev_attr_wCountryCodes); |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1522 | kfree(acm->country_codes); |
Julia Lawall | e7c8e86 | 2011-12-23 14:02:55 +0100 | [diff] [blame] | 1523 | acm->country_codes = NULL; |
| 1524 | acm->country_code_size = 0; |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1525 | goto skip_countries; |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | skip_countries: |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1530 | usb_fill_int_urb(acm->ctrlurb, usb_dev, |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1531 | usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), |
| 1532 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, |
| 1533 | /* works around buggy devices */ |
Felipe Balbi | d102e78 | 2013-07-01 11:23:24 +0300 | [diff] [blame] | 1534 | epctrl->bInterval ? epctrl->bInterval : 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 1536 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; |
Tobias Herzog | ea25835 | 2017-03-30 22:15:11 +0200 | [diff] [blame] | 1537 | acm->notification_buffer = NULL; |
| 1538 | acm->nb_index = 0; |
| 1539 | acm->nb_size = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); |
| 1542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | acm->line.dwDTERate = cpu_to_le32(9600); |
| 1544 | acm->line.bDataBits = 8; |
| 1545 | acm_set_line(acm, &acm->line); |
| 1546 | |
| 1547 | usb_driver_claim_interface(&acm_driver, data_interface, acm); |
David Brownell | 672c4e1 | 2008-08-06 18:41:12 -0700 | [diff] [blame] | 1548 | usb_set_intfdata(data_interface, acm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | |
brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 1550 | usb_get_intf(control_interface); |
Alexey Khoroshilov | c93d819 | 2013-03-16 01:30:32 +0400 | [diff] [blame] | 1551 | tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor, |
Jiri Slaby | 734cc17 | 2012-08-07 21:47:47 +0200 | [diff] [blame] | 1552 | &control_interface->dev); |
Alexey Khoroshilov | c93d819 | 2013-03-16 01:30:32 +0400 | [diff] [blame] | 1553 | if (IS_ERR(tty_dev)) { |
| 1554 | rv = PTR_ERR(tty_dev); |
| 1555 | goto alloc_fail8; |
| 1556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | |
Alexey Sokolov | 15bf722 | 2015-06-02 11:49:30 +0300 | [diff] [blame] | 1558 | if (quirks & CLEAR_HALT_CONDITIONS) { |
Ladislav Michl | 74bccc9 | 2016-11-18 19:09:19 +0100 | [diff] [blame] | 1559 | usb_clear_halt(usb_dev, acm->in); |
| 1560 | usb_clear_halt(usb_dev, acm->out); |
Alexey Sokolov | 15bf722 | 2015-06-02 11:49:30 +0300 | [diff] [blame] | 1561 | } |
| 1562 | |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1563 | return 0; |
Alexey Khoroshilov | c93d819 | 2013-03-16 01:30:32 +0400 | [diff] [blame] | 1564 | alloc_fail8: |
| 1565 | if (acm->country_codes) { |
| 1566 | device_remove_file(&acm->control->dev, |
| 1567 | &dev_attr_wCountryCodes); |
| 1568 | device_remove_file(&acm->control->dev, |
| 1569 | &dev_attr_iCountryCodeRelDate); |
Oliver Neukum | d908f84 | 2014-11-20 14:54:35 +0100 | [diff] [blame] | 1570 | kfree(acm->country_codes); |
Alexey Khoroshilov | c93d819 | 2013-03-16 01:30:32 +0400 | [diff] [blame] | 1571 | } |
| 1572 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); |
Johan Hovold | 74f5e1b | 2011-03-22 11:12:23 +0100 | [diff] [blame] | 1573 | alloc_fail7: |
Alexey Khoroshilov | c93d819 | 2013-03-16 01:30:32 +0400 | [diff] [blame] | 1574 | usb_set_intfdata(intf, NULL); |
David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1575 | for (i = 0; i < ACM_NW; i++) |
| 1576 | usb_free_urb(acm->wb[i].urb); |
Axel Lin | c2572b7 | 2010-05-31 08:04:47 +0800 | [diff] [blame] | 1577 | alloc_fail6: |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1578 | for (i = 0; i < num_rx_buf; i++) |
Johan Hovold | 088c64f | 2011-03-25 11:06:02 +0100 | [diff] [blame] | 1579 | usb_free_urb(acm->read_urbs[i]); |
Johan Hovold | 74f5e1b | 2011-03-22 11:12:23 +0100 | [diff] [blame] | 1580 | acm_read_buffers_free(acm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | usb_free_urb(acm->ctrlurb); |
| 1582 | alloc_fail5: |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1583 | acm_write_buffers_free(acm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | alloc_fail4: |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1585 | usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | alloc_fail2: |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1587 | acm_release_minor(acm); |
Oliver Neukum | 6dd3587 | 2016-07-14 15:41:32 +0200 | [diff] [blame] | 1588 | alloc_fail1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | kfree(acm); |
| 1590 | alloc_fail: |
Alexey Khoroshilov | c93d819 | 2013-03-16 01:30:32 +0400 | [diff] [blame] | 1591 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static void acm_disconnect(struct usb_interface *intf) |
| 1595 | { |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1596 | struct acm *acm = usb_get_intfdata(intf); |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 1597 | struct tty_struct *tty; |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1598 | |
David Brownell | 672c4e1 | 2008-08-06 18:41:12 -0700 | [diff] [blame] | 1599 | /* sibling interface is already cleaning up */ |
| 1600 | if (!acm) |
Oliver Neukum | 86067eea | 2006-01-08 12:39:13 +0100 | [diff] [blame] | 1601 | return; |
David Brownell | 672c4e1 | 2008-08-06 18:41:12 -0700 | [diff] [blame] | 1602 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1603 | mutex_lock(&acm->mutex); |
| 1604 | acm->disconnected = true; |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1605 | if (acm->country_codes) { |
Alan Stern | 74da5d6 | 2007-08-02 13:29:10 -0400 | [diff] [blame] | 1606 | device_remove_file(&acm->control->dev, |
| 1607 | &dev_attr_wCountryCodes); |
| 1608 | device_remove_file(&acm->control->dev, |
| 1609 | &dev_attr_iCountryCodeRelDate); |
Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1610 | } |
Oliver Neukum | 5a6a62b | 2013-11-20 11:35:34 +0100 | [diff] [blame] | 1611 | wake_up_all(&acm->wioctl); |
Alan Stern | 74da5d6 | 2007-08-02 13:29:10 -0400 | [diff] [blame] | 1612 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); |
Oliver Neukum | 86067eea | 2006-01-08 12:39:13 +0100 | [diff] [blame] | 1613 | usb_set_intfdata(acm->control, NULL); |
| 1614 | usb_set_intfdata(acm->data, NULL); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1615 | mutex_unlock(&acm->mutex); |
| 1616 | |
| 1617 | tty = tty_port_tty_get(&acm->port); |
| 1618 | if (tty) { |
| 1619 | tty_vhangup(tty); |
| 1620 | tty_kref_put(tty); |
| 1621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | |
Ladislav Michl | ba8c931 | 2016-11-18 19:07:08 +0100 | [diff] [blame] | 1623 | acm_kill_urbs(acm); |
| 1624 | cancel_work_sync(&acm->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | |
Johan Hovold | cb25505 | 2013-03-19 09:21:06 +0100 | [diff] [blame] | 1626 | tty_unregister_device(acm_tty_driver, acm->minor); |
| 1627 | |
Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1628 | acm_write_buffers_free(acm); |
Ladislav Michl | e461460 | 2016-11-18 19:06:10 +0100 | [diff] [blame] | 1629 | usb_free_coherent(acm->dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); |
Oliver Neukum | 830f402 | 2008-06-25 14:17:16 +0200 | [diff] [blame] | 1630 | acm_read_buffers_free(acm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | |
Tobias Herzog | ea25835 | 2017-03-30 22:15:11 +0200 | [diff] [blame] | 1632 | kfree(acm->notification_buffer); |
| 1633 | |
Oliver Neukum | a2bfb4a | 2009-05-16 21:13:19 +0200 | [diff] [blame] | 1634 | if (!acm->combined_interfaces) |
| 1635 | usb_driver_release_interface(&acm_driver, intf == acm->control ? |
Oliver Neukum | 830f402 | 2008-06-25 14:17:16 +0200 | [diff] [blame] | 1636 | acm->data : acm->control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1638 | tty_port_put(&acm->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 1641 | #ifdef CONFIG_PM |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1642 | static int acm_suspend(struct usb_interface *intf, pm_message_t message) |
| 1643 | { |
| 1644 | struct acm *acm = usb_get_intfdata(intf); |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 1645 | int cnt; |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1646 | |
Johan Hovold | bbf0cb3 | 2014-05-26 19:23:46 +0200 | [diff] [blame] | 1647 | spin_lock_irq(&acm->write_lock); |
Johan Hovold | 5a345c2 | 2014-05-26 19:23:36 +0200 | [diff] [blame] | 1648 | if (PMSG_IS_AUTO(message)) { |
| 1649 | if (acm->transmitting) { |
Johan Hovold | bbf0cb3 | 2014-05-26 19:23:46 +0200 | [diff] [blame] | 1650 | spin_unlock_irq(&acm->write_lock); |
Johan Hovold | 5a345c2 | 2014-05-26 19:23:36 +0200 | [diff] [blame] | 1651 | return -EBUSY; |
| 1652 | } |
| 1653 | } |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 1654 | cnt = acm->susp_count++; |
Johan Hovold | bbf0cb3 | 2014-05-26 19:23:46 +0200 | [diff] [blame] | 1655 | spin_unlock_irq(&acm->write_lock); |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 1656 | |
| 1657 | if (cnt) |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1658 | return 0; |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1659 | |
Ladislav Michl | ba8c931 | 2016-11-18 19:07:08 +0100 | [diff] [blame] | 1660 | acm_kill_urbs(acm); |
| 1661 | cancel_work_sync(&acm->work); |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1662 | |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1663 | return 0; |
| 1664 | } |
| 1665 | |
| 1666 | static int acm_resume(struct usb_interface *intf) |
| 1667 | { |
| 1668 | struct acm *acm = usb_get_intfdata(intf); |
Johan Hovold | 140cb81 | 2014-05-26 19:23:38 +0200 | [diff] [blame] | 1669 | struct urb *urb; |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1670 | int rv = 0; |
| 1671 | |
Johan Hovold | bbf0cb3 | 2014-05-26 19:23:46 +0200 | [diff] [blame] | 1672 | spin_lock_irq(&acm->write_lock); |
Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame] | 1673 | |
Johan Hovold | e144ed28 | 2014-05-26 19:23:37 +0200 | [diff] [blame] | 1674 | if (--acm->susp_count) |
| 1675 | goto out; |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1676 | |
Peter Hurley | d41861c | 2016-04-09 17:53:25 -0700 | [diff] [blame] | 1677 | if (tty_port_initialized(&acm->port)) { |
Johan Hovold | e144ed28 | 2014-05-26 19:23:37 +0200 | [diff] [blame] | 1678 | rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC); |
Oliver Neukum | 97d35f9 | 2009-12-16 17:05:57 +0100 | [diff] [blame] | 1679 | |
Johan Hovold | 140cb81 | 2014-05-26 19:23:38 +0200 | [diff] [blame] | 1680 | for (;;) { |
| 1681 | urb = usb_get_from_anchor(&acm->delayed); |
| 1682 | if (!urb) |
| 1683 | break; |
| 1684 | |
| 1685 | acm_start_wb(acm, urb->context); |
Oliver Neukum | 97d35f9 | 2009-12-16 17:05:57 +0100 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | /* |
| 1689 | * delayed error checking because we must |
| 1690 | * do the write path at all cost |
| 1691 | */ |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1692 | if (rv < 0) |
Johan Hovold | e144ed28 | 2014-05-26 19:23:37 +0200 | [diff] [blame] | 1693 | goto out; |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1694 | |
Johan Hovold | e144ed28 | 2014-05-26 19:23:37 +0200 | [diff] [blame] | 1695 | rv = acm_submit_read_urbs(acm, GFP_ATOMIC); |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1696 | } |
Johan Hovold | e144ed28 | 2014-05-26 19:23:37 +0200 | [diff] [blame] | 1697 | out: |
Johan Hovold | bbf0cb3 | 2014-05-26 19:23:46 +0200 | [diff] [blame] | 1698 | spin_unlock_irq(&acm->write_lock); |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1699 | |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1700 | return rv; |
| 1701 | } |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 1702 | |
Francesco Lavra | a91b0c5 | 2009-12-08 09:54:11 +0100 | [diff] [blame] | 1703 | static int acm_reset_resume(struct usb_interface *intf) |
| 1704 | { |
| 1705 | struct acm *acm = usb_get_intfdata(intf); |
Francesco Lavra | a91b0c5 | 2009-12-08 09:54:11 +0100 | [diff] [blame] | 1706 | |
Peter Hurley | d41861c | 2016-04-09 17:53:25 -0700 | [diff] [blame] | 1707 | if (tty_port_initialized(&acm->port)) |
Jiri Slaby | aa27a09 | 2013-03-07 13:12:30 +0100 | [diff] [blame] | 1708 | tty_port_tty_hangup(&acm->port, false); |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1709 | |
Francesco Lavra | a91b0c5 | 2009-12-08 09:54:11 +0100 | [diff] [blame] | 1710 | return acm_resume(intf); |
| 1711 | } |
| 1712 | |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 1713 | #endif /* CONFIG_PM */ |
Adrian Taylor | c1479a9 | 2009-11-19 10:35:33 +0000 | [diff] [blame] | 1714 | |
Ladislav Michl | 1aba579 | 2016-11-18 19:11:26 +0100 | [diff] [blame] | 1715 | static int acm_pre_reset(struct usb_interface *intf) |
| 1716 | { |
| 1717 | struct acm *acm = usb_get_intfdata(intf); |
| 1718 | |
| 1719 | clear_bit(EVENT_RX_STALL, &acm->flags); |
| 1720 | |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
Adrian Taylor | c1479a9 | 2009-11-19 10:35:33 +0000 | [diff] [blame] | 1724 | #define NOKIA_PCSUITE_ACM_INFO(x) \ |
| 1725 | USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \ |
| 1726 | USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \ |
| 1727 | USB_CDC_ACM_PROTO_VENDOR) |
| 1728 | |
Toby Gray | 4035e45 | 2010-09-01 16:01:19 +0100 | [diff] [blame] | 1729 | #define SAMSUNG_PCSUITE_ACM_INFO(x) \ |
| 1730 | USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \ |
| 1731 | USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \ |
| 1732 | USB_CDC_ACM_PROTO_VENDOR) |
| 1733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | /* |
| 1735 | * USB driver structure. |
| 1736 | */ |
| 1737 | |
Németh Márton | 6ef4852 | 2010-01-10 15:33:45 +0100 | [diff] [blame] | 1738 | static const struct usb_device_id acm_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | /* quirky and broken devices */ |
Björn Gerhart | b20b161 | 2015-02-18 07:19:44 +0100 | [diff] [blame] | 1740 | { USB_DEVICE(0x076d, 0x0006), /* Denso Cradle CU-321 */ |
| 1741 | .driver_info = NO_UNION_NORMAL, },/* has no union descriptor */ |
David Cluytens | 3b59d16 | 2013-12-03 14:18:57 +0100 | [diff] [blame] | 1742 | { USB_DEVICE(0x17ef, 0x7000), /* Lenovo USB modem */ |
| 1743 | .driver_info = NO_UNION_NORMAL, },/* has no union descriptor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */ |
| 1745 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1746 | }, |
Andrey Arapov | b0e2a70 | 2007-07-04 17:11:42 +0200 | [diff] [blame] | 1747 | { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */ |
| 1748 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1749 | }, |
Andrew Lunn | 0f9c7b4 | 2008-12-23 17:31:23 +0100 | [diff] [blame] | 1750 | { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */ |
| 1751 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1752 | }, |
Masahito Omote | 8753e65 | 2005-07-29 12:17:25 -0700 | [diff] [blame] | 1753 | { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */ |
| 1754 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1755 | }, |
Chris Malley | 91a9c92 | 2006-10-03 10:08:28 +0100 | [diff] [blame] | 1756 | { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */ |
| 1757 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1758 | }, |
Alan Cox | 7abcf20 | 2009-04-06 17:35:01 +0100 | [diff] [blame] | 1759 | { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */ |
| 1760 | .driver_info = SINGLE_RX_URB, |
| 1761 | }, |
Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1762 | { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */ |
| 1763 | .driver_info = SINGLE_RX_URB, /* firmware bug */ |
| 1764 | }, |
Oliver Neukum | 3dd2ae8 | 2006-06-23 09:14:17 +0200 | [diff] [blame] | 1765 | { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ |
| 1766 | .driver_info = SINGLE_RX_URB, /* firmware bug */ |
| 1767 | }, |
Oliver Neukum | 9be8456 | 2007-02-12 08:50:03 +0100 | [diff] [blame] | 1768 | { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */ |
| 1769 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1770 | }, |
Iain McFarlane | 6149ed5 | 2008-05-04 00:13:49 +0100 | [diff] [blame] | 1771 | { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */ |
| 1772 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1773 | }, |
Eric Sandeen | c8fd2c3 | 2008-08-14 08:25:40 -0500 | [diff] [blame] | 1774 | { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */ |
| 1775 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1776 | }, |
Alan Cox | c89c60e | 2009-01-11 19:53:10 +0000 | [diff] [blame] | 1777 | { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */ |
| 1778 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1779 | }, |
Xiao Kaijian | cab98a0 | 2009-05-08 00:48:23 +0800 | [diff] [blame] | 1780 | { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */ |
| 1781 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
| 1782 | }, |
Johan Hovold | 2a8cdfd | 2014-11-06 18:08:33 +0100 | [diff] [blame] | 1783 | { USB_DEVICE(0x20df, 0x0001), /* Simtec Electronics Entropy Key */ |
| 1784 | .driver_info = QUIRK_CONTROL_LINE_STATE, }, |
Johan Hovold | cf84a69 | 2014-10-27 18:34:33 +0100 | [diff] [blame] | 1785 | { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */ |
Nathaniel Quillin | 3012160 | 2016-12-05 06:53:00 -0800 | [diff] [blame] | 1786 | { USB_DEVICE(0x2184, 0x0036) }, /* GW Instek AFG-125 */ |
Dmitriy Taychenachev | 155df65 | 2009-02-25 12:36:51 +0800 | [diff] [blame] | 1787 | { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ |
| 1788 | }, |
Krzysztof Hałasa | 6abff5d | 2011-12-12 14:51:00 +0100 | [diff] [blame] | 1789 | /* Motorola H24 HSPA module: */ |
| 1790 | { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */ |
Michael Ulbricht | 895d240 | 2014-03-25 10:34:18 +0100 | [diff] [blame] | 1791 | { USB_DEVICE(0x22b8, 0x2d92), /* modem + diagnostics */ |
| 1792 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ |
| 1793 | }, |
| 1794 | { USB_DEVICE(0x22b8, 0x2d93), /* modem + AT port */ |
| 1795 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ |
| 1796 | }, |
| 1797 | { USB_DEVICE(0x22b8, 0x2d95), /* modem + AT port + diagnostics */ |
| 1798 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ |
| 1799 | }, |
| 1800 | { USB_DEVICE(0x22b8, 0x2d96), /* modem + NMEA */ |
| 1801 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ |
| 1802 | }, |
| 1803 | { USB_DEVICE(0x22b8, 0x2d97), /* modem + diagnostics + NMEA */ |
| 1804 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ |
| 1805 | }, |
| 1806 | { USB_DEVICE(0x22b8, 0x2d99), /* modem + AT port + NMEA */ |
| 1807 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ |
| 1808 | }, |
| 1809 | { USB_DEVICE(0x22b8, 0x2d9a), /* modem + AT port + diagnostics + NMEA */ |
| 1810 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ |
| 1811 | }, |
Krzysztof Hałasa | 6abff5d | 2011-12-12 14:51:00 +0100 | [diff] [blame] | 1812 | |
Adam Richter | c332b4e | 2009-02-18 16:17:15 -0800 | [diff] [blame] | 1813 | { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */ |
| 1814 | .driver_info = NO_UNION_NORMAL, /* union descriptor misplaced on |
| 1815 | data interface instead of |
| 1816 | communications interface. |
| 1817 | Maybe we should define a new |
| 1818 | quirk for this. */ |
| 1819 | }, |
Jean-Christian de Rivaz | e7d491a | 2012-10-10 12:49:02 +0000 | [diff] [blame] | 1820 | { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */ |
| 1821 | .driver_info = NO_UNION_NORMAL, |
| 1822 | }, |
Denis N Ladin | 036915a | 2012-12-26 18:29:44 +0500 | [diff] [blame] | 1823 | { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */ |
| 1824 | .driver_info = NO_UNION_NORMAL, |
| 1825 | }, |
Kir Kolyshkin | 1f17c50 | 2009-05-28 20:33:58 +0400 | [diff] [blame] | 1826 | { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */ |
| 1827 | .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ |
| 1828 | }, |
Russ Nelson | c3baa19 | 2010-04-21 23:07:03 -0400 | [diff] [blame] | 1829 | { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */ |
| 1830 | .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ |
| 1831 | }, |
Oliver Neukum | 9be8456 | 2007-02-12 08:50:03 +0100 | [diff] [blame] | 1832 | |
Alexey Sokolov | 15bf722 | 2015-06-02 11:49:30 +0300 | [diff] [blame] | 1833 | { USB_DEVICE(0x2912, 0x0001), /* ATOL FPrint */ |
| 1834 | .driver_info = CLEAR_HALT_CONDITIONS, |
| 1835 | }, |
| 1836 | |
Adrian Taylor | c1479a9 | 2009-11-19 10:35:33 +0000 | [diff] [blame] | 1837 | /* Nokia S60 phones expose two ACM channels. The first is |
| 1838 | * a modem and is picked up by the standard AT-command |
| 1839 | * information below. The second is 'vendor-specific' but |
| 1840 | * is treated as a serial device at the S60 end, so we want |
| 1841 | * to expose it on Linux too. */ |
| 1842 | { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */ |
| 1843 | { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */ |
| 1844 | { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */ |
| 1845 | { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */ |
| 1846 | { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */ |
| 1847 | { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */ |
| 1848 | { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */ |
| 1849 | { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */ |
| 1850 | { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */ |
| 1851 | { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */ |
| 1852 | { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */ |
| 1853 | { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */ |
| 1854 | { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */ |
| 1855 | { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */ |
| 1856 | { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */ |
| 1857 | { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */ |
| 1858 | { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */ |
| 1859 | { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */ |
| 1860 | { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */ |
| 1861 | { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */ |
| 1862 | { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */ |
| 1863 | { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */ |
| 1864 | { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */ |
| 1865 | { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */ |
| 1866 | { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */ |
| 1867 | { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */ |
| 1868 | { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */ |
| 1869 | { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */ |
| 1870 | { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */ |
| 1871 | { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */ |
| 1872 | { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */ |
| 1873 | { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */ |
| 1874 | { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */ |
| 1875 | { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */ |
| 1876 | { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */ |
| 1877 | { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */ |
| 1878 | { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */ |
| 1879 | { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */ |
| 1880 | { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */ |
| 1881 | { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */ |
| 1882 | { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */ |
| 1883 | { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */ |
| 1884 | { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */ |
Przemo Firszt | 83a4eae | 2010-06-28 21:29:34 +0100 | [diff] [blame] | 1885 | { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */ |
Toby Gray | 4035e45 | 2010-09-01 16:01:19 +0100 | [diff] [blame] | 1886 | { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */ |
| 1887 | { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */ |
| 1888 | { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */ |
| 1889 | { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */ |
| 1890 | { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */ |
| 1891 | { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */ |
| 1892 | { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */ |
| 1893 | { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */ |
| 1894 | { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */ |
| 1895 | { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */ |
Arvid Ephraim Picciani | 721d92f | 2011-01-25 15:58:40 +0100 | [diff] [blame] | 1896 | { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */ |
Toby Gray | 4061fde | 2011-06-06 14:52:48 +0100 | [diff] [blame] | 1897 | { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */ |
| 1898 | { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */ |
Toby Gray | 4035e45 | 2010-09-01 16:01:19 +0100 | [diff] [blame] | 1899 | { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */ |
Adrian Taylor | c1479a9 | 2009-11-19 10:35:33 +0000 | [diff] [blame] | 1900 | |
Denis Pershin | 65e52f4 | 2011-09-04 17:37:21 +0700 | [diff] [blame] | 1901 | /* Support for Owen devices */ |
| 1902 | { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */ |
| 1903 | |
Adrian Taylor | c1479a9 | 2009-11-19 10:35:33 +0000 | [diff] [blame] | 1904 | /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */ |
| 1905 | |
Erik Slagter | fd5054c1 | 2011-05-11 12:06:55 +0200 | [diff] [blame] | 1906 | /* Support for Droids MuIn LCD */ |
| 1907 | { USB_DEVICE(0x04d8, 0x000b), |
| 1908 | .driver_info = NO_DATA_INTERFACE, |
| 1909 | }, |
| 1910 | |
Dmitry Torokhov | 1614265 | 2013-02-02 11:02:14 -0800 | [diff] [blame] | 1911 | #if IS_ENABLED(CONFIG_INPUT_IMS_PCU) |
| 1912 | { USB_DEVICE(0x04d8, 0x0082), /* Application mode */ |
| 1913 | .driver_info = IGNORE_DEVICE, |
| 1914 | }, |
| 1915 | { USB_DEVICE(0x04d8, 0x0083), /* Bootloader mode */ |
| 1916 | .driver_info = IGNORE_DEVICE, |
| 1917 | }, |
| 1918 | #endif |
| 1919 | |
Oliver Neukum | e912e68 | 2016-01-18 15:45:18 +0100 | [diff] [blame] | 1920 | /*Samsung phone in firmware update mode */ |
| 1921 | { USB_DEVICE(0x04e8, 0x685d), |
| 1922 | .driver_info = IGNORE_DEVICE, |
| 1923 | }, |
| 1924 | |
Jonas Jonsson | f33a7f7 | 2015-11-22 11:47:17 +0100 | [diff] [blame] | 1925 | /* Exclude Infineon Flash Loader utility */ |
| 1926 | { USB_DEVICE(0x058b, 0x0041), |
| 1927 | .driver_info = IGNORE_DEVICE, |
| 1928 | }, |
| 1929 | |
Philippe Corbes | 5b239f0 | 2010-08-31 19:31:32 +0200 | [diff] [blame] | 1930 | /* control interfaces without any protocol set */ |
| 1931 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
| 1932 | USB_CDC_PROTO_NONE) }, |
| 1933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | /* control interfaces with various AT-command sets */ |
| 1935 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
| 1936 | USB_CDC_ACM_PROTO_AT_V25TER) }, |
| 1937 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
| 1938 | USB_CDC_ACM_PROTO_AT_PCCA101) }, |
| 1939 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
| 1940 | USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) }, |
| 1941 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
| 1942 | USB_CDC_ACM_PROTO_AT_GSM) }, |
| 1943 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1944 | USB_CDC_ACM_PROTO_AT_3G) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
| 1946 | USB_CDC_ACM_PROTO_AT_CDMA) }, |
| 1947 | |
Lu Baolu | ffdb1e3 | 2016-01-06 15:10:04 +0800 | [diff] [blame] | 1948 | { USB_DEVICE(0x1519, 0x0452), /* Intel 7260 modem */ |
| 1949 | .driver_info = SEND_ZERO_PACKET, |
| 1950 | }, |
| 1951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | { } |
| 1953 | }; |
| 1954 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 1955 | MODULE_DEVICE_TABLE(usb, acm_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
| 1957 | static struct usb_driver acm_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | .name = "cdc_acm", |
| 1959 | .probe = acm_probe, |
| 1960 | .disconnect = acm_disconnect, |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 1961 | #ifdef CONFIG_PM |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1962 | .suspend = acm_suspend, |
| 1963 | .resume = acm_resume, |
Francesco Lavra | a91b0c5 | 2009-12-08 09:54:11 +0100 | [diff] [blame] | 1964 | .reset_resume = acm_reset_resume, |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 1965 | #endif |
Ladislav Michl | 1aba579 | 2016-11-18 19:11:26 +0100 | [diff] [blame] | 1966 | .pre_reset = acm_pre_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | .id_table = acm_ids, |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 1968 | #ifdef CONFIG_PM |
Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1969 | .supports_autosuspend = 1, |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 1970 | #endif |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 1971 | .disable_hub_initiated_lpm = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | }; |
| 1973 | |
| 1974 | /* |
| 1975 | * TTY driver structures. |
| 1976 | */ |
| 1977 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 1978 | static const struct tty_operations acm_ops = { |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1979 | .install = acm_tty_install, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | .open = acm_tty_open, |
| 1981 | .close = acm_tty_close, |
Havard Skinnemoen | 7fb57a0 | 2011-11-30 13:28:14 -0800 | [diff] [blame] | 1982 | .cleanup = acm_tty_cleanup, |
Alan Cox | 10077d4 | 2009-06-11 12:36:09 +0100 | [diff] [blame] | 1983 | .hangup = acm_tty_hangup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | .write = acm_tty_write, |
Oliver Neukum | a81cf97 | 2016-02-10 10:39:49 +0100 | [diff] [blame] | 1985 | .put_char = acm_tty_put_char, |
| 1986 | .flush_chars = acm_tty_flush_chars, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | .write_room = acm_tty_write_room, |
| 1988 | .ioctl = acm_tty_ioctl, |
| 1989 | .throttle = acm_tty_throttle, |
| 1990 | .unthrottle = acm_tty_unthrottle, |
| 1991 | .chars_in_buffer = acm_tty_chars_in_buffer, |
| 1992 | .break_ctl = acm_tty_break_ctl, |
| 1993 | .set_termios = acm_tty_set_termios, |
| 1994 | .tiocmget = acm_tty_tiocmget, |
| 1995 | .tiocmset = acm_tty_tiocmset, |
Johan Hovold | bb2d387 | 2016-11-08 13:28:24 +0100 | [diff] [blame] | 1996 | .get_icount = acm_tty_get_icount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | }; |
| 1998 | |
| 1999 | /* |
| 2000 | * Init / exit. |
| 2001 | */ |
| 2002 | |
| 2003 | static int __init acm_init(void) |
| 2004 | { |
| 2005 | int retval; |
| 2006 | acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS); |
| 2007 | if (!acm_tty_driver) |
| 2008 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | acm_tty_driver->driver_name = "acm", |
| 2010 | acm_tty_driver->name = "ttyACM", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | acm_tty_driver->major = ACM_TTY_MAJOR, |
| 2012 | acm_tty_driver->minor_start = 0, |
| 2013 | acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, |
| 2014 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, |
Greg Kroah-Hartman | 331b831 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2015 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | acm_tty_driver->init_termios = tty_std_termios; |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 2017 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | |
| 2018 | HUPCL | CLOCAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | tty_set_operations(acm_tty_driver, &acm_ops); |
| 2020 | |
| 2021 | retval = tty_register_driver(acm_tty_driver); |
| 2022 | if (retval) { |
| 2023 | put_tty_driver(acm_tty_driver); |
| 2024 | return retval; |
| 2025 | } |
| 2026 | |
| 2027 | retval = usb_register(&acm_driver); |
| 2028 | if (retval) { |
| 2029 | tty_unregister_driver(acm_tty_driver); |
| 2030 | put_tty_driver(acm_tty_driver); |
| 2031 | return retval; |
| 2032 | } |
| 2033 | |
Johan Hovold | a2c7b93 | 2011-03-22 11:12:18 +0100 | [diff] [blame] | 2034 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
| 2036 | return 0; |
| 2037 | } |
| 2038 | |
| 2039 | static void __exit acm_exit(void) |
| 2040 | { |
| 2041 | usb_deregister(&acm_driver); |
| 2042 | tty_unregister_driver(acm_tty_driver); |
| 2043 | put_tty_driver(acm_tty_driver); |
Johannes Thumshirn | 91b7256 | 2015-07-08 17:25:42 +0200 | [diff] [blame] | 2044 | idr_destroy(&acm_minors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | module_init(acm_init); |
| 2048 | module_exit(acm_exit); |
| 2049 | |
Alan Cox | 6e47e06 | 2009-06-11 12:37:06 +0100 | [diff] [blame] | 2050 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 2051 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | MODULE_LICENSE("GPL"); |
Scott James Remnant | e766aeb | 2009-04-06 17:33:18 +0100 | [diff] [blame] | 2053 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); |