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