Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 1 | /* |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 2 | USB Driver for Sierra Wireless |
| 3 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 4 | Copyright (C) 2006, 2007, 2008 Kevin Lloyd <klloyd@sierrawireless.com>, |
| 5 | |
| 6 | Copyright (C) 2008, 2009 Elina Pasheva, Matthew Safar, Rory Filer |
| 7 | <linux@sierrawireless.com> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 8 | |
| 9 | IMPORTANT DISCLAIMER: This driver is not commercially supported by |
| 10 | Sierra Wireless. Use at your own risk. |
| 11 | |
| 12 | This driver is free software; you can redistribute it and/or modify |
| 13 | it under the terms of Version 2 of the GNU General Public License as |
| 14 | published by the Free Software Foundation. |
| 15 | |
| 16 | Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de> |
| 17 | Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Elina Pasheva | 0f0ba79 | 2009-09-17 15:26:20 -0700 | [diff] [blame] | 20 | #define DRIVER_VERSION "v.1.3.8" |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 21 | #define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer" |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 22 | #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 23 | |
| 24 | #include <linux/kernel.h> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 25 | #include <linux/jiffies.h> |
| 26 | #include <linux/errno.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 27 | #include <linux/tty.h> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 28 | #include <linux/tty_flip.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
| 30 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 31 | #include <linux/usb/serial.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 32 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 33 | #define SWIMS_USB_REQUEST_SetPower 0x00 |
| 34 | #define SWIMS_USB_REQUEST_SetNmea 0x07 |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 35 | |
Elina Pasheva | b748bb7 | 2009-04-24 18:41:49 -0700 | [diff] [blame] | 36 | #define N_IN_URB 8 |
| 37 | #define N_OUT_URB 64 |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 38 | #define IN_BUFLEN 4096 |
| 39 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 40 | #define MAX_TRANSFER (PAGE_SIZE - 512) |
| 41 | /* MAX_TRANSFER is chosen so that the VM is not stressed by |
| 42 | allocations > PAGE_SIZE and the number of packets in a page |
| 43 | is an integer 512 is the largest possible packet on EHCI */ |
| 44 | |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 45 | static int debug; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 46 | static int nmea; |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 47 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 48 | /* Used in interface blacklisting */ |
| 49 | struct sierra_iface_info { |
| 50 | const u32 infolen; /* number of interface numbers on blacklist */ |
| 51 | const u8 *ifaceinfo; /* pointer to the array holding the numbers */ |
| 52 | }; |
| 53 | |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 54 | struct sierra_intf_private { |
| 55 | spinlock_t susp_lock; |
| 56 | unsigned int suspended:1; |
| 57 | int in_flight; |
| 58 | }; |
| 59 | |
Adrian Bunk | 82a24e6 | 2007-07-29 16:59:02 +0200 | [diff] [blame] | 60 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 61 | { |
| 62 | int result; |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 63 | dev_dbg(&udev->dev, "%s\n", __func__); |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 64 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 65 | SWIMS_USB_REQUEST_SetPower, /* __u8 request */ |
Kevin Lloyd | f3564de | 2008-03-28 10:05:08 -0700 | [diff] [blame] | 66 | USB_TYPE_VENDOR, /* __u8 request type */ |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 67 | swiState, /* __u16 value */ |
| 68 | 0, /* __u16 index */ |
| 69 | NULL, /* void *data */ |
| 70 | 0, /* __u16 size */ |
| 71 | USB_CTRL_SET_TIMEOUT); /* int timeout */ |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 72 | return result; |
| 73 | } |
| 74 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 75 | static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable) |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 76 | { |
| 77 | int result; |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 78 | dev_dbg(&udev->dev, "%s\n", __func__); |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 79 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 80 | SWIMS_USB_REQUEST_SetNmea, /* __u8 request */ |
Kevin Lloyd | f3564de | 2008-03-28 10:05:08 -0700 | [diff] [blame] | 81 | USB_TYPE_VENDOR, /* __u8 request type */ |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 82 | enable, /* __u16 value */ |
| 83 | 0x0000, /* __u16 index */ |
| 84 | NULL, /* void *data */ |
| 85 | 0, /* __u16 size */ |
| 86 | USB_CTRL_SET_TIMEOUT); /* int timeout */ |
| 87 | return result; |
| 88 | } |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 89 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 90 | static int sierra_calc_num_ports(struct usb_serial *serial) |
| 91 | { |
Elina Pasheva | 9636b68 | 2009-05-12 13:12:54 -0700 | [diff] [blame] | 92 | int num_ports = 0; |
| 93 | u8 ifnum, numendpoints; |
| 94 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 95 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 96 | |
Elina Pasheva | 9636b68 | 2009-05-12 13:12:54 -0700 | [diff] [blame] | 97 | ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; |
| 98 | numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 99 | |
Elina Pasheva | 9636b68 | 2009-05-12 13:12:54 -0700 | [diff] [blame] | 100 | /* Dummy interface present on some SKUs should be ignored */ |
| 101 | if (ifnum == 0x99) |
| 102 | num_ports = 0; |
| 103 | else if (numendpoints <= 3) |
| 104 | num_ports = 1; |
| 105 | else |
| 106 | num_ports = (numendpoints-1)/2; |
| 107 | return num_ports; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 110 | static int is_blacklisted(const u8 ifnum, |
| 111 | const struct sierra_iface_info *blacklist) |
| 112 | { |
| 113 | const u8 *info; |
| 114 | int i; |
| 115 | |
| 116 | if (blacklist) { |
| 117 | info = blacklist->ifaceinfo; |
| 118 | |
| 119 | for (i = 0; i < blacklist->infolen; i++) { |
| 120 | if (info[i] == ifnum) |
| 121 | return 1; |
| 122 | } |
| 123 | } |
| 124 | return 0; |
| 125 | } |
| 126 | |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 127 | static int sierra_calc_interface(struct usb_serial *serial) |
| 128 | { |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 129 | int interface; |
| 130 | struct usb_interface *p_interface; |
| 131 | struct usb_host_interface *p_host_interface; |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 132 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 133 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 134 | /* Get the interface structure pointer from the serial struct */ |
| 135 | p_interface = serial->interface; |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 136 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 137 | /* Get a pointer to the host interface structure */ |
| 138 | p_host_interface = p_interface->cur_altsetting; |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 139 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 140 | /* read the interface descriptor for this active altsetting |
| 141 | * to find out the interface number we are on |
| 142 | */ |
| 143 | interface = p_host_interface->desc.bInterfaceNumber; |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 144 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 145 | return interface; |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 148 | static int sierra_probe(struct usb_serial *serial, |
| 149 | const struct usb_device_id *id) |
| 150 | { |
| 151 | int result = 0; |
| 152 | struct usb_device *udev; |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 153 | struct sierra_intf_private *data; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 154 | u8 ifnum; |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 155 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 156 | udev = serial->dev; |
Elina Pasheva | 9636b68 | 2009-05-12 13:12:54 -0700 | [diff] [blame] | 157 | dev_dbg(&udev->dev, "%s\n", __func__); |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 158 | |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 159 | ifnum = sierra_calc_interface(serial); |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 160 | /* |
| 161 | * If this interface supports more than 1 alternate |
| 162 | * select the 2nd one |
| 163 | */ |
| 164 | if (serial->interface->num_altsetting == 2) { |
| 165 | dev_dbg(&udev->dev, "Selecting alt setting for interface %d\n", |
| 166 | ifnum); |
| 167 | /* We know the alternate setting is 1 for the MC8785 */ |
| 168 | usb_set_interface(udev, ifnum, 1); |
| 169 | } |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 170 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 171 | /* ifnum could have changed - by calling usb_set_interface */ |
| 172 | ifnum = sierra_calc_interface(serial); |
| 173 | |
| 174 | if (is_blacklisted(ifnum, |
| 175 | (struct sierra_iface_info *)id->driver_info)) { |
| 176 | dev_dbg(&serial->dev->dev, |
| 177 | "Ignoring blacklisted interface #%d\n", ifnum); |
| 178 | return -ENODEV; |
| 179 | } |
| 180 | |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 181 | data = serial->private = kzalloc(sizeof(struct sierra_intf_private), GFP_KERNEL); |
| 182 | if (!data) |
| 183 | return -ENOMEM; |
| 184 | spin_lock_init(&data->susp_lock); |
| 185 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 186 | return result; |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 187 | } |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 188 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 189 | static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; |
| 190 | static const struct sierra_iface_info direct_ip_interface_blacklist = { |
| 191 | .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces), |
| 192 | .ifaceinfo = direct_ip_non_serial_ifaces, |
| 193 | }; |
| 194 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 195 | static struct usb_device_id id_table [] = { |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 196 | { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ |
| 197 | { USB_DEVICE(0x03F0, 0x1B1D) }, /* HP ev2200 a.k.a MC5720 */ |
| 198 | { USB_DEVICE(0x03F0, 0x1E1D) }, /* HP hs2300 a.k.a MC8775 */ |
| 199 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 200 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 201 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ |
Greg Kroah-Hartman | 90ac3c8 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 202 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 203 | { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ |
agilmore@wirelessbeehive.com | b9e13ac | 2007-12-04 11:37:12 -0700 | [diff] [blame] | 204 | { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */ |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 205 | { USB_DEVICE(0x1199, 0x0022) }, /* Sierra Wireless EM5725 */ |
| 206 | { USB_DEVICE(0x1199, 0x0024) }, /* Sierra Wireless MC5727 */ |
| 207 | { USB_DEVICE(0x1199, 0x0224) }, /* Sierra Wireless MC5727 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 208 | { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ |
| 209 | { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 210 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 211 | { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */ |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 212 | /* Sierra Wireless C597 */ |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 213 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0023, 0xFF, 0xFF, 0xFF) }, |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 214 | /* Sierra Wireless T598 */ |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 215 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0025, 0xFF, 0xFF, 0xFF) }, |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 216 | { USB_DEVICE(0x1199, 0x0026) }, /* Sierra Wireless T11 */ |
| 217 | { USB_DEVICE(0x1199, 0x0027) }, /* Sierra Wireless AC402 */ |
| 218 | { USB_DEVICE(0x1199, 0x0028) }, /* Sierra Wireless MC5728 */ |
| 219 | { USB_DEVICE(0x1199, 0x0029) }, /* Sierra Wireless Device */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 220 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 221 | { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ |
| 222 | { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 223 | { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ |
| 224 | { USB_DEVICE(0x1199, 0x6805) }, /* Sierra Wireless MC8765 */ |
| 225 | { USB_DEVICE(0x1199, 0x6808) }, /* Sierra Wireless MC8755 */ |
| 226 | { USB_DEVICE(0x1199, 0x6809) }, /* Sierra Wireless MC8765 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 227 | { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 228 | { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 */ |
Kevin Lloyd | 7f170a6 | 2008-03-14 00:53:24 -0700 | [diff] [blame] | 229 | { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */ |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 230 | { USB_DEVICE(0x1199, 0x6816) }, /* Sierra Wireless MC8775 */ |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 231 | { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 232 | { USB_DEVICE(0x1199, 0x6821) }, /* Sierra Wireless AirCard 875U */ |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 233 | { USB_DEVICE(0x1199, 0x6822) }, /* Sierra Wireless AirCard 875E */ |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 234 | { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780 */ |
| 235 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */ |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 236 | { USB_DEVICE(0x1199, 0x6834) }, /* Sierra Wireless MC8780 */ |
| 237 | { USB_DEVICE(0x1199, 0x6835) }, /* Sierra Wireless MC8781 */ |
| 238 | { USB_DEVICE(0x1199, 0x6838) }, /* Sierra Wireless MC8780 */ |
| 239 | { USB_DEVICE(0x1199, 0x6839) }, /* Sierra Wireless MC8781 */ |
Kevin Lloyd | b77a5c7 | 2008-09-17 09:03:38 -0700 | [diff] [blame] | 240 | { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 241 | { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 242 | /* Sierra Wireless MC8790, MC8791, MC8792 Composite */ |
| 243 | { USB_DEVICE(0x1199, 0x683C) }, |
| 244 | { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */ |
| 245 | /* Sierra Wireless MC8790, MC8791, MC8792 */ |
| 246 | { USB_DEVICE(0x1199, 0x683E) }, |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 247 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ |
| 248 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ |
| 249 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ |
| 250 | { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */ |
Kevin Lloyd | 6835b32 | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 251 | { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */ |
Jessica L. Blank | 62aad3a | 2007-12-30 20:11:35 -0600 | [diff] [blame] | 252 | { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */ |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 253 | { USB_DEVICE(0x1199, 0x6859) }, /* Sierra Wireless AirCard 885 E */ |
| 254 | { USB_DEVICE(0x1199, 0x685A) }, /* Sierra Wireless AirCard 885 E */ |
| 255 | /* Sierra Wireless C885 */ |
| 256 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6880, 0xFF, 0xFF, 0xFF)}, |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 257 | /* Sierra Wireless C888, Air Card 501, USB 303, USB 304 */ |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 258 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6890, 0xFF, 0xFF, 0xFF)}, |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 259 | /* Sierra Wireless C22/C33 */ |
Kevin Lloyd | 73b2c20 | 2008-08-25 19:20:40 -0700 | [diff] [blame] | 260 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6891, 0xFF, 0xFF, 0xFF)}, |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 261 | /* Sierra Wireless HSPA Non-Composite Device */ |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 262 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6892, 0xFF, 0xFF, 0xFF)}, |
Elina Pasheva | c5f3d87 | 2009-07-09 17:55:18 -0700 | [diff] [blame] | 263 | { USB_DEVICE(0x1199, 0x6893) }, /* Sierra Wireless Device */ |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 264 | { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */ |
| 265 | .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist |
| 266 | }, |
| 267 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 268 | { } |
| 269 | }; |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 270 | MODULE_DEVICE_TABLE(usb, id_table); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 271 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 272 | static struct usb_driver sierra_driver = { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 273 | .name = "sierra", |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 274 | .probe = usb_serial_probe, |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 275 | .disconnect = usb_serial_disconnect, |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 276 | .suspend = usb_serial_suspend, |
| 277 | .resume = usb_serial_resume, |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 278 | .id_table = id_table, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 279 | .no_dynamic_id = 1, |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 280 | .supports_autosuspend = 1, |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 281 | }; |
| 282 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 283 | struct sierra_port_private { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 284 | spinlock_t lock; /* lock the structure */ |
| 285 | int outstanding_urbs; /* number of out urbs in flight */ |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 286 | struct usb_anchor active; |
| 287 | struct usb_anchor delayed; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 288 | |
Oliver Neukum | 4f4f9c5 | 2008-03-14 00:53:24 -0700 | [diff] [blame] | 289 | /* Input endpoints and buffers for this port */ |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 290 | struct urb *in_urbs[N_IN_URB]; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 291 | |
| 292 | /* Settings for the port */ |
| 293 | int rts_state; /* Handshaking pins (outputs) */ |
| 294 | int dtr_state; |
| 295 | int cts_state; /* Handshaking pins (inputs) */ |
| 296 | int dsr_state; |
| 297 | int dcd_state; |
| 298 | int ri_state; |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 299 | unsigned int opened:1; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 300 | }; |
| 301 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 302 | static int sierra_send_setup(struct usb_serial_port *port) |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 303 | { |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 304 | struct usb_serial *serial = port->serial; |
| 305 | struct sierra_port_private *portdata; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 306 | __u16 interface = 0; |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 307 | int val = 0; |
Elina Pasheva | 3c77d51 | 2009-10-16 12:04:54 -0700 | [diff] [blame] | 308 | int do_send = 0; |
| 309 | int retval; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 310 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 311 | dev_dbg(&port->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 312 | |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 313 | portdata = usb_get_serial_port_data(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 314 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 315 | if (portdata->dtr_state) |
| 316 | val |= 0x01; |
| 317 | if (portdata->rts_state) |
| 318 | val |= 0x02; |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 319 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 320 | /* If composite device then properly report interface */ |
Alan Cox | 00b040d | 2009-06-11 14:29:29 +0100 | [diff] [blame] | 321 | if (serial->num_ports == 1) { |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 322 | interface = sierra_calc_interface(serial); |
Alan Cox | 00b040d | 2009-06-11 14:29:29 +0100 | [diff] [blame] | 323 | /* Control message is sent only to interfaces with |
| 324 | * interrupt_in endpoints |
| 325 | */ |
| 326 | if (port->interrupt_in_urb) { |
| 327 | /* send control message */ |
Elina Pasheva | 3c77d51 | 2009-10-16 12:04:54 -0700 | [diff] [blame] | 328 | do_send = 1; |
Alan Cox | 00b040d | 2009-06-11 14:29:29 +0100 | [diff] [blame] | 329 | } |
| 330 | } |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 331 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 332 | /* Otherwise the need to do non-composite mapping */ |
| 333 | else { |
| 334 | if (port->bulk_out_endpointAddress == 2) |
| 335 | interface = 0; |
| 336 | else if (port->bulk_out_endpointAddress == 4) |
| 337 | interface = 1; |
| 338 | else if (port->bulk_out_endpointAddress == 5) |
| 339 | interface = 2; |
Elina Pasheva | 3c77d51 | 2009-10-16 12:04:54 -0700 | [diff] [blame] | 340 | |
| 341 | do_send = 1; |
Alan Cox | 00b040d | 2009-06-11 14:29:29 +0100 | [diff] [blame] | 342 | } |
Elina Pasheva | 3c77d51 | 2009-10-16 12:04:54 -0700 | [diff] [blame] | 343 | if (!do_send) |
| 344 | return 0; |
| 345 | |
| 346 | usb_autopm_get_interface(serial->interface); |
| 347 | retval = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
| 348 | 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 349 | usb_autopm_put_interface(serial->interface); |
| 350 | |
| 351 | return retval; |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 354 | static void sierra_set_termios(struct tty_struct *tty, |
| 355 | struct usb_serial_port *port, struct ktermios *old_termios) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 356 | { |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 357 | dev_dbg(&port->dev, "%s\n", __func__); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 358 | tty_termios_copy_hw(tty->termios, old_termios); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 359 | sierra_send_setup(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 362 | static int sierra_tiocmget(struct tty_struct *tty, struct file *file) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 363 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 364 | struct usb_serial_port *port = tty->driver_data; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 365 | unsigned int value; |
| 366 | struct sierra_port_private *portdata; |
| 367 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 368 | dev_dbg(&port->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 369 | portdata = usb_get_serial_port_data(port); |
| 370 | |
| 371 | value = ((portdata->rts_state) ? TIOCM_RTS : 0) | |
| 372 | ((portdata->dtr_state) ? TIOCM_DTR : 0) | |
| 373 | ((portdata->cts_state) ? TIOCM_CTS : 0) | |
| 374 | ((portdata->dsr_state) ? TIOCM_DSR : 0) | |
| 375 | ((portdata->dcd_state) ? TIOCM_CAR : 0) | |
| 376 | ((portdata->ri_state) ? TIOCM_RNG : 0); |
| 377 | |
| 378 | return value; |
| 379 | } |
| 380 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 381 | static int sierra_tiocmset(struct tty_struct *tty, struct file *file, |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 382 | unsigned int set, unsigned int clear) |
| 383 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 384 | struct usb_serial_port *port = tty->driver_data; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 385 | struct sierra_port_private *portdata; |
| 386 | |
| 387 | portdata = usb_get_serial_port_data(port); |
| 388 | |
| 389 | if (set & TIOCM_RTS) |
| 390 | portdata->rts_state = 1; |
| 391 | if (set & TIOCM_DTR) |
| 392 | portdata->dtr_state = 1; |
| 393 | |
| 394 | if (clear & TIOCM_RTS) |
| 395 | portdata->rts_state = 0; |
| 396 | if (clear & TIOCM_DTR) |
| 397 | portdata->dtr_state = 0; |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 398 | return sierra_send_setup(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 401 | static void sierra_release_urb(struct urb *urb) |
| 402 | { |
| 403 | struct usb_serial_port *port; |
| 404 | if (urb) { |
| 405 | port = urb->context; |
| 406 | dev_dbg(&port->dev, "%s: %p\n", __func__, urb); |
| 407 | kfree(urb->transfer_buffer); |
| 408 | usb_free_urb(urb); |
| 409 | } |
| 410 | } |
| 411 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 412 | static void sierra_outdat_callback(struct urb *urb) |
| 413 | { |
| 414 | struct usb_serial_port *port = urb->context; |
| 415 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 416 | struct sierra_intf_private *intfdata; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 417 | int status = urb->status; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 418 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 419 | dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 420 | intfdata = port->serial->private; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 421 | |
| 422 | /* free up the transfer buffer, as usb_free_urb() does not do this */ |
| 423 | kfree(urb->transfer_buffer); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 424 | usb_autopm_put_interface_async(port->serial->interface); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 425 | if (status) |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 426 | dev_dbg(&port->dev, "%s - nonzero write bulk status " |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 427 | "received: %d\n", __func__, status); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 428 | |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 429 | spin_lock(&portdata->lock); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 430 | --portdata->outstanding_urbs; |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 431 | spin_unlock(&portdata->lock); |
| 432 | spin_lock(&intfdata->susp_lock); |
| 433 | --intfdata->in_flight; |
| 434 | spin_unlock(&intfdata->susp_lock); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 435 | |
| 436 | usb_serial_port_softint(port); |
| 437 | } |
| 438 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 439 | /* Write */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 440 | static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 441 | const unsigned char *buf, int count) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 442 | { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 443 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 444 | struct sierra_intf_private *intfdata; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 445 | struct usb_serial *serial = port->serial; |
| 446 | unsigned long flags; |
| 447 | unsigned char *buffer; |
| 448 | struct urb *urb; |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 449 | size_t writesize = min((size_t)count, (size_t)MAX_TRANSFER); |
| 450 | int retval = 0; |
| 451 | |
| 452 | /* verify that we actually have some data to write */ |
| 453 | if (count == 0) |
| 454 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 455 | |
| 456 | portdata = usb_get_serial_port_data(port); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 457 | intfdata = serial->private; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 458 | |
Andrew Morton | 0b10395 | 2009-05-12 15:27:59 -0700 | [diff] [blame] | 459 | dev_dbg(&port->dev, "%s: write (%zd bytes)\n", __func__, writesize); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 460 | spin_lock_irqsave(&portdata->lock, flags); |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 461 | dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__, |
| 462 | portdata->outstanding_urbs); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 463 | if (portdata->outstanding_urbs > N_OUT_URB) { |
| 464 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 465 | dev_dbg(&port->dev, "%s - write limit hit\n", __func__); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | portdata->outstanding_urbs++; |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 469 | dev_dbg(&port->dev, "%s - 1, outstanding_urbs: %d\n", __func__, |
| 470 | portdata->outstanding_urbs); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 471 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 472 | |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 473 | retval = usb_autopm_get_interface_async(serial->interface); |
| 474 | if (retval < 0) { |
| 475 | spin_lock_irqsave(&portdata->lock, flags); |
| 476 | portdata->outstanding_urbs--; |
| 477 | spin_unlock_irqrestore(&portdata->lock, flags); |
| 478 | goto error_simple; |
| 479 | } |
| 480 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 481 | buffer = kmalloc(writesize, GFP_ATOMIC); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 482 | if (!buffer) { |
| 483 | dev_err(&port->dev, "out of memory\n"); |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 484 | retval = -ENOMEM; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 485 | goto error_no_buffer; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 488 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 489 | if (!urb) { |
| 490 | dev_err(&port->dev, "no more free urbs\n"); |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 491 | retval = -ENOMEM; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 492 | goto error_no_urb; |
| 493 | } |
| 494 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 495 | memcpy(buffer, buf, writesize); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 496 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 497 | usb_serial_debug_data(debug, &port->dev, __func__, writesize, buffer); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 498 | |
| 499 | usb_fill_bulk_urb(urb, serial->dev, |
| 500 | usb_sndbulkpipe(serial->dev, |
| 501 | port->bulk_out_endpointAddress), |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 502 | buffer, writesize, sierra_outdat_callback, port); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 503 | |
Elina Pasheva | 238ebd1 | 2009-05-12 13:12:24 -0700 | [diff] [blame] | 504 | /* Handle the need to send a zero length packet */ |
| 505 | urb->transfer_flags |= URB_ZERO_PACKET; |
| 506 | |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 507 | spin_lock_irqsave(&intfdata->susp_lock, flags); |
| 508 | |
| 509 | if (intfdata->suspended) { |
| 510 | usb_anchor_urb(urb, &portdata->delayed); |
| 511 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); |
| 512 | goto skip_power; |
| 513 | } else { |
| 514 | usb_anchor_urb(urb, &portdata->active); |
| 515 | } |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 516 | /* send it down the pipe */ |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 517 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
| 518 | if (retval) { |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 519 | usb_unanchor_urb(urb); |
| 520 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 521 | dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 522 | "with status = %d\n", __func__, retval); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 523 | goto error; |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 524 | } else { |
| 525 | intfdata->in_flight++; |
| 526 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 527 | } |
| 528 | |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 529 | skip_power: |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 530 | /* we are done with this urb, so let the host driver |
| 531 | * really free it when it is finished with it */ |
| 532 | usb_free_urb(urb); |
| 533 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 534 | return writesize; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 535 | error: |
| 536 | usb_free_urb(urb); |
| 537 | error_no_urb: |
| 538 | kfree(buffer); |
| 539 | error_no_buffer: |
| 540 | spin_lock_irqsave(&portdata->lock, flags); |
| 541 | --portdata->outstanding_urbs; |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 542 | dev_dbg(&port->dev, "%s - 2. outstanding_urbs: %d\n", __func__, |
| 543 | portdata->outstanding_urbs); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 544 | spin_unlock_irqrestore(&portdata->lock, flags); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 545 | usb_autopm_put_interface_async(serial->interface); |
| 546 | error_simple: |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame] | 547 | return retval; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static void sierra_indat_callback(struct urb *urb) |
| 551 | { |
| 552 | int err; |
| 553 | int endpoint; |
| 554 | struct usb_serial_port *port; |
| 555 | struct tty_struct *tty; |
| 556 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 557 | int status = urb->status; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 558 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 559 | endpoint = usb_pipeendpoint(urb->pipe); |
Elina Pasheva | b0cda8c | 2009-04-29 10:29:21 -0700 | [diff] [blame] | 560 | port = urb->context; |
| 561 | |
| 562 | dev_dbg(&port->dev, "%s: %p\n", __func__, urb); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 563 | |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 564 | if (status) { |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 565 | dev_dbg(&port->dev, "%s: nonzero status: %d on" |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 566 | " endpoint %02x\n", __func__, status, endpoint); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 567 | } else { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 568 | if (urb->actual_length) { |
Alan Cox | d95186d | 2009-01-02 13:42:56 +0000 | [diff] [blame] | 569 | tty = tty_port_tty_get(&port->port); |
Elina Pasheva | b0cda8c | 2009-04-29 10:29:21 -0700 | [diff] [blame] | 570 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 571 | tty_buffer_request_room(tty, urb->actual_length); |
| 572 | tty_insert_flip_string(tty, data, urb->actual_length); |
| 573 | tty_flip_buffer_push(tty); |
Elina Pasheva | b0cda8c | 2009-04-29 10:29:21 -0700 | [diff] [blame] | 574 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 575 | tty_kref_put(tty); |
Elina Pasheva | b0cda8c | 2009-04-29 10:29:21 -0700 | [diff] [blame] | 576 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 577 | urb->actual_length, data); |
| 578 | } else { |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 579 | dev_dbg(&port->dev, "%s: empty read urb" |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 580 | " received\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 581 | } |
| 582 | } |
Elina Pasheva | b0cda8c | 2009-04-29 10:29:21 -0700 | [diff] [blame] | 583 | |
| 584 | /* Resubmit urb so we continue receiving */ |
| 585 | if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 586 | usb_mark_last_busy(port->serial->dev); |
Elina Pasheva | b0cda8c | 2009-04-29 10:29:21 -0700 | [diff] [blame] | 587 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 588 | if (err) |
| 589 | dev_err(&port->dev, "resubmit read urb failed." |
| 590 | "(%d)\n", err); |
| 591 | } |
| 592 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 593 | return; |
| 594 | } |
| 595 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 596 | static void sierra_instat_callback(struct urb *urb) |
| 597 | { |
| 598 | int err; |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 599 | int status = urb->status; |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 600 | struct usb_serial_port *port = urb->context; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 601 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 602 | struct usb_serial *serial = port->serial; |
| 603 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 604 | dev_dbg(&port->dev, "%s: urb %p port %p has data %p\n", __func__, |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 605 | urb, port, portdata); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 606 | |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 607 | if (status == 0) { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 608 | struct usb_ctrlrequest *req_pkt = |
| 609 | (struct usb_ctrlrequest *)urb->transfer_buffer; |
| 610 | |
| 611 | if (!req_pkt) { |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 612 | dev_dbg(&port->dev, "%s: NULL req_pkt\n", |
| 613 | __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 614 | return; |
| 615 | } |
| 616 | if ((req_pkt->bRequestType == 0xA1) && |
| 617 | (req_pkt->bRequest == 0x20)) { |
| 618 | int old_dcd_state; |
| 619 | unsigned char signals = *((unsigned char *) |
| 620 | urb->transfer_buffer + |
| 621 | sizeof(struct usb_ctrlrequest)); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 622 | struct tty_struct *tty; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 623 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 624 | dev_dbg(&port->dev, "%s: signal x%x\n", __func__, |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 625 | signals); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 626 | |
| 627 | old_dcd_state = portdata->dcd_state; |
| 628 | portdata->cts_state = 1; |
| 629 | portdata->dcd_state = ((signals & 0x01) ? 1 : 0); |
| 630 | portdata->dsr_state = ((signals & 0x02) ? 1 : 0); |
| 631 | portdata->ri_state = ((signals & 0x08) ? 1 : 0); |
| 632 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 633 | tty = tty_port_tty_get(&port->port); |
| 634 | if (tty && !C_CLOCAL(tty) && |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 635 | old_dcd_state && !portdata->dcd_state) |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 636 | tty_hangup(tty); |
| 637 | tty_kref_put(tty); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 638 | } else { |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 639 | dev_dbg(&port->dev, "%s: type %x req %x\n", |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 640 | __func__, req_pkt->bRequestType, |
| 641 | req_pkt->bRequest); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 642 | } |
| 643 | } else |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 644 | dev_dbg(&port->dev, "%s: error %d\n", __func__, status); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 645 | |
| 646 | /* Resubmit urb so we continue receiving IRQ data */ |
Elina Pasheva | c76a23d | 2009-05-12 13:12:37 -0700 | [diff] [blame] | 647 | if (port->port.count && status != -ESHUTDOWN && status != -ENOENT) { |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 648 | usb_mark_last_busy(serial->dev); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 649 | urb->dev = serial->dev; |
| 650 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 651 | if (err) |
Elina Pasheva | c76a23d | 2009-05-12 13:12:37 -0700 | [diff] [blame] | 652 | dev_err(&port->dev, "%s: resubmit intr urb " |
| 653 | "failed. (%d)\n", __func__, err); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 657 | static int sierra_write_room(struct tty_struct *tty) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 658 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 659 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 660 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 661 | unsigned long flags; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 662 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 663 | dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 664 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 665 | /* try to give a good number back based on if we have any free urbs at |
| 666 | * this point in time */ |
| 667 | spin_lock_irqsave(&portdata->lock, flags); |
| 668 | if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) { |
| 669 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 670 | dev_dbg(&port->dev, "%s - write limit hit\n", __func__); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 671 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 672 | } |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 673 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 674 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 675 | return 2048; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 678 | static void sierra_stop_rx_urbs(struct usb_serial_port *port) |
| 679 | { |
| 680 | int i; |
| 681 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 682 | |
| 683 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) |
| 684 | usb_kill_urb(portdata->in_urbs[i]); |
| 685 | |
| 686 | usb_kill_urb(port->interrupt_in_urb); |
| 687 | } |
| 688 | |
| 689 | static int sierra_submit_rx_urbs(struct usb_serial_port *port, gfp_t mem_flags) |
| 690 | { |
| 691 | int ok_cnt; |
| 692 | int err = -EINVAL; |
| 693 | int i; |
| 694 | struct urb *urb; |
| 695 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 696 | |
| 697 | ok_cnt = 0; |
| 698 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { |
| 699 | urb = portdata->in_urbs[i]; |
| 700 | if (!urb) |
| 701 | continue; |
| 702 | err = usb_submit_urb(urb, mem_flags); |
| 703 | if (err) { |
| 704 | dev_err(&port->dev, "%s: submit urb failed: %d\n", |
| 705 | __func__, err); |
| 706 | } else { |
| 707 | ok_cnt++; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | if (ok_cnt && port->interrupt_in_urb) { |
| 712 | err = usb_submit_urb(port->interrupt_in_urb, mem_flags); |
| 713 | if (err) { |
| 714 | dev_err(&port->dev, "%s: submit intr urb failed: %d\n", |
| 715 | __func__, err); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | if (ok_cnt > 0) /* at least one rx urb submitted */ |
| 720 | return 0; |
| 721 | else |
| 722 | return err; |
| 723 | } |
| 724 | |
| 725 | static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, |
| 726 | int dir, void *ctx, int len, |
| 727 | gfp_t mem_flags, |
| 728 | usb_complete_t callback) |
| 729 | { |
| 730 | struct urb *urb; |
| 731 | u8 *buf; |
| 732 | |
| 733 | if (endpoint == -1) |
| 734 | return NULL; |
| 735 | |
| 736 | urb = usb_alloc_urb(0, mem_flags); |
| 737 | if (urb == NULL) { |
| 738 | dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n", |
| 739 | __func__, endpoint); |
| 740 | return NULL; |
| 741 | } |
| 742 | |
| 743 | buf = kmalloc(len, mem_flags); |
| 744 | if (buf) { |
| 745 | /* Fill URB using supplied data */ |
| 746 | usb_fill_bulk_urb(urb, serial->dev, |
| 747 | usb_sndbulkpipe(serial->dev, endpoint) | dir, |
| 748 | buf, len, callback, ctx); |
| 749 | |
| 750 | /* debug */ |
| 751 | dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__, |
| 752 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); |
| 753 | } else { |
| 754 | dev_dbg(&serial->dev->dev, "%s %c u:%p d:%p\n", __func__, |
| 755 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); |
| 756 | |
| 757 | sierra_release_urb(urb); |
| 758 | urb = NULL; |
| 759 | } |
| 760 | |
| 761 | return urb; |
| 762 | } |
| 763 | |
| 764 | static void sierra_close(struct usb_serial_port *port) |
| 765 | { |
| 766 | int i; |
| 767 | struct usb_serial *serial = port->serial; |
| 768 | struct sierra_port_private *portdata; |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 769 | struct sierra_intf_private *intfdata = port->serial->private; |
| 770 | |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 771 | |
| 772 | dev_dbg(&port->dev, "%s\n", __func__); |
| 773 | portdata = usb_get_serial_port_data(port); |
| 774 | |
| 775 | portdata->rts_state = 0; |
| 776 | portdata->dtr_state = 0; |
| 777 | |
| 778 | if (serial->dev) { |
| 779 | mutex_lock(&serial->disc_mutex); |
Elina Pasheva | b64dc0a | 2009-10-27 13:49:59 -0700 | [diff] [blame] | 780 | if (!serial->disconnected) { |
| 781 | serial->interface->needs_remote_wakeup = 0; |
| 782 | usb_autopm_get_interface(serial->interface); |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 783 | sierra_send_setup(port); |
Elina Pasheva | b64dc0a | 2009-10-27 13:49:59 -0700 | [diff] [blame] | 784 | } |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 785 | mutex_unlock(&serial->disc_mutex); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 786 | spin_lock_irq(&intfdata->susp_lock); |
| 787 | portdata->opened = 0; |
| 788 | spin_unlock_irq(&intfdata->susp_lock); |
| 789 | |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 790 | |
| 791 | /* Stop reading urbs */ |
| 792 | sierra_stop_rx_urbs(port); |
| 793 | /* .. and release them */ |
| 794 | for (i = 0; i < N_IN_URB; i++) { |
| 795 | sierra_release_urb(portdata->in_urbs[i]); |
| 796 | portdata->in_urbs[i] = NULL; |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 801 | static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 802 | { |
| 803 | struct sierra_port_private *portdata; |
| 804 | struct usb_serial *serial = port->serial; |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 805 | struct sierra_intf_private *intfdata = serial->private; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 806 | int i; |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 807 | int err; |
| 808 | int endpoint; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 809 | struct urb *urb; |
| 810 | |
| 811 | portdata = usb_get_serial_port_data(port); |
| 812 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 813 | dev_dbg(&port->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 814 | |
| 815 | /* Set some sane defaults */ |
| 816 | portdata->rts_state = 1; |
| 817 | portdata->dtr_state = 1; |
| 818 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 819 | |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 820 | endpoint = port->bulk_in_endpointAddress; |
| 821 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { |
| 822 | urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, |
| 823 | IN_BUFLEN, GFP_KERNEL, |
| 824 | sierra_indat_callback); |
| 825 | portdata->in_urbs[i] = urb; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 826 | } |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 827 | /* clear halt condition */ |
| 828 | usb_clear_halt(serial->dev, |
| 829 | usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 830 | |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 831 | err = sierra_submit_rx_urbs(port, GFP_KERNEL); |
| 832 | if (err) { |
| 833 | /* get rid of everything as in close */ |
| 834 | sierra_close(port); |
Elina Pasheva | b64dc0a | 2009-10-27 13:49:59 -0700 | [diff] [blame] | 835 | /* restore balance for autopm */ |
| 836 | usb_autopm_put_interface(serial->interface); |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 837 | return err; |
| 838 | } |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 839 | sierra_send_setup(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 840 | |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 841 | serial->interface->needs_remote_wakeup = 1; |
| 842 | spin_lock_irq(&intfdata->susp_lock); |
| 843 | portdata->opened = 1; |
| 844 | spin_unlock_irq(&intfdata->susp_lock); |
| 845 | usb_autopm_put_interface(serial->interface); |
| 846 | |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 847 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 850 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 851 | static void sierra_dtr_rts(struct usb_serial_port *port, int on) |
| 852 | { |
| 853 | struct usb_serial *serial = port->serial; |
| 854 | struct sierra_port_private *portdata; |
| 855 | |
| 856 | portdata = usb_get_serial_port_data(port); |
| 857 | portdata->rts_state = on; |
| 858 | portdata->dtr_state = on; |
| 859 | |
| 860 | if (serial->dev) { |
| 861 | mutex_lock(&serial->disc_mutex); |
| 862 | if (!serial->disconnected) |
| 863 | sierra_send_setup(port); |
| 864 | mutex_unlock(&serial->disc_mutex); |
| 865 | } |
| 866 | } |
| 867 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 868 | static int sierra_startup(struct usb_serial *serial) |
| 869 | { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 870 | struct usb_serial_port *port; |
| 871 | struct sierra_port_private *portdata; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 872 | int i; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 873 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 874 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 875 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 876 | /* Set Device mode to D0 */ |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 877 | sierra_set_power_state(serial->dev, 0x0000); |
| 878 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 879 | /* Check NMEA and set */ |
| 880 | if (nmea) |
| 881 | sierra_vsc_set_nmea(serial->dev, 1); |
| 882 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 883 | /* Now setup per port private data */ |
| 884 | for (i = 0; i < serial->num_ports; i++) { |
| 885 | port = serial->port[i]; |
| 886 | portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); |
| 887 | if (!portdata) { |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 888 | dev_dbg(&port->dev, "%s: kmalloc for " |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 889 | "sierra_port_private (%d) failed!.\n", |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 890 | __func__, i); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 891 | return -ENOMEM; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 892 | } |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 893 | spin_lock_init(&portdata->lock); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 894 | init_usb_anchor(&portdata->active); |
| 895 | init_usb_anchor(&portdata->delayed); |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 896 | /* Set the port private data pointer */ |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 897 | usb_set_serial_port_data(port, portdata); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 900 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Alan Stern | 7bae0a0 | 2009-07-07 09:50:14 -0400 | [diff] [blame] | 903 | static void sierra_release(struct usb_serial *serial) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 904 | { |
Elina Pasheva | b9a44bc | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 905 | int i; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 906 | struct usb_serial_port *port; |
| 907 | struct sierra_port_private *portdata; |
| 908 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 909 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 910 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 911 | for (i = 0; i < serial->num_ports; ++i) { |
| 912 | port = serial->port[i]; |
Greg Kroah-Hartman | f094e4f | 2007-04-26 00:12:01 -0700 | [diff] [blame] | 913 | if (!port) |
| 914 | continue; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 915 | portdata = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | f094e4f | 2007-04-26 00:12:01 -0700 | [diff] [blame] | 916 | if (!portdata) |
| 917 | continue; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 918 | kfree(portdata); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | |
Andrew Morton | cd60451 | 2009-09-23 15:57:43 -0700 | [diff] [blame] | 922 | #ifdef CONFIG_PM |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 923 | static void stop_read_write_urbs(struct usb_serial *serial) |
| 924 | { |
Elina Pasheva | b64dc0a | 2009-10-27 13:49:59 -0700 | [diff] [blame] | 925 | int i; |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 926 | struct usb_serial_port *port; |
| 927 | struct sierra_port_private *portdata; |
| 928 | |
| 929 | /* Stop reading/writing urbs */ |
| 930 | for (i = 0; i < serial->num_ports; ++i) { |
| 931 | port = serial->port[i]; |
| 932 | portdata = usb_get_serial_port_data(port); |
Elina Pasheva | b64dc0a | 2009-10-27 13:49:59 -0700 | [diff] [blame] | 933 | sierra_stop_rx_urbs(port); |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 934 | usb_kill_anchored_urbs(&portdata->active); |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | static int sierra_suspend(struct usb_serial *serial, pm_message_t message) |
| 939 | { |
| 940 | struct sierra_intf_private *intfdata; |
| 941 | int b; |
| 942 | |
| 943 | if (serial->dev->auto_pm) { |
| 944 | intfdata = serial->private; |
| 945 | spin_lock_irq(&intfdata->susp_lock); |
| 946 | b = intfdata->in_flight; |
| 947 | |
| 948 | if (b) { |
| 949 | spin_unlock_irq(&intfdata->susp_lock); |
| 950 | return -EBUSY; |
| 951 | } else { |
| 952 | intfdata->suspended = 1; |
| 953 | spin_unlock_irq(&intfdata->susp_lock); |
| 954 | } |
| 955 | } |
| 956 | stop_read_write_urbs(serial); |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | static int sierra_resume(struct usb_serial *serial) |
| 962 | { |
| 963 | struct usb_serial_port *port; |
| 964 | struct sierra_intf_private *intfdata = serial->private; |
| 965 | struct sierra_port_private *portdata; |
| 966 | struct urb *urb; |
| 967 | int ec = 0; |
| 968 | int i, err; |
| 969 | |
| 970 | spin_lock_irq(&intfdata->susp_lock); |
| 971 | for (i = 0; i < serial->num_ports; i++) { |
| 972 | port = serial->port[i]; |
| 973 | portdata = usb_get_serial_port_data(port); |
| 974 | |
| 975 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { |
| 976 | usb_anchor_urb(urb, &portdata->active); |
| 977 | intfdata->in_flight++; |
| 978 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 979 | if (err < 0) { |
| 980 | intfdata->in_flight--; |
| 981 | usb_unanchor_urb(urb); |
| 982 | usb_scuttle_anchored_urbs(&portdata->delayed); |
| 983 | break; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | if (portdata->opened) { |
| 988 | err = sierra_submit_rx_urbs(port, GFP_ATOMIC); |
| 989 | if (err) |
| 990 | ec++; |
| 991 | } |
| 992 | } |
| 993 | intfdata->suspended = 0; |
| 994 | spin_unlock_irq(&intfdata->susp_lock); |
| 995 | |
| 996 | return ec ? -EIO : 0; |
| 997 | } |
Andrew Morton | cd60451 | 2009-09-23 15:57:43 -0700 | [diff] [blame] | 998 | #else |
| 999 | #define sierra_suspend NULL |
| 1000 | #define sierra_resume NULL |
| 1001 | #endif |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 1002 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 1003 | static struct usb_serial_driver sierra_device = { |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1004 | .driver = { |
| 1005 | .owner = THIS_MODULE, |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 1006 | .name = "sierra", |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1007 | }, |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 1008 | .description = "Sierra USB modem", |
| 1009 | .id_table = id_table, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 1010 | .usb_driver = &sierra_driver, |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 1011 | .calc_num_ports = sierra_calc_num_ports, |
| 1012 | .probe = sierra_probe, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1013 | .open = sierra_open, |
| 1014 | .close = sierra_close, |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 1015 | .dtr_rts = sierra_dtr_rts, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1016 | .write = sierra_write, |
| 1017 | .write_room = sierra_write_room, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1018 | .set_termios = sierra_set_termios, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1019 | .tiocmget = sierra_tiocmget, |
| 1020 | .tiocmset = sierra_tiocmset, |
| 1021 | .attach = sierra_startup, |
Alan Stern | 7bae0a0 | 2009-07-07 09:50:14 -0400 | [diff] [blame] | 1022 | .release = sierra_release, |
Oliver Neukum | e6929a9 | 2009-09-04 23:19:53 +0200 | [diff] [blame] | 1023 | .suspend = sierra_suspend, |
| 1024 | .resume = sierra_resume, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1025 | .read_int_callback = sierra_instat_callback, |
| 1026 | }; |
| 1027 | |
| 1028 | /* Functions used by new usb-serial code. */ |
| 1029 | static int __init sierra_init(void) |
| 1030 | { |
| 1031 | int retval; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 1032 | retval = usb_serial_register(&sierra_device); |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1033 | if (retval) |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 1034 | goto failed_device_register; |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1035 | |
| 1036 | |
| 1037 | retval = usb_register(&sierra_driver); |
| 1038 | if (retval) |
| 1039 | goto failed_driver_register; |
| 1040 | |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 1041 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 1042 | DRIVER_DESC "\n"); |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1043 | |
| 1044 | return 0; |
| 1045 | |
| 1046 | failed_driver_register: |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 1047 | usb_serial_deregister(&sierra_device); |
| 1048 | failed_device_register: |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1049 | return retval; |
| 1050 | } |
| 1051 | |
| 1052 | static void __exit sierra_exit(void) |
| 1053 | { |
Alan Cox | 9660ea3 | 2008-07-22 11:14:59 +0100 | [diff] [blame] | 1054 | usb_deregister(&sierra_driver); |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 1055 | usb_serial_deregister(&sierra_device); |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | module_init(sierra_init); |
| 1059 | module_exit(sierra_exit); |
| 1060 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 1061 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1062 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1063 | MODULE_VERSION(DRIVER_VERSION); |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 1064 | MODULE_LICENSE("GPL"); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 1065 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 1066 | module_param(nmea, bool, S_IRUGO | S_IWUSR); |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 1067 | MODULE_PARM_DESC(nmea, "NMEA streaming"); |
| 1068 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 1069 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 1070 | MODULE_PARM_DESC(debug, "Debug messages"); |