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