21 #define DRIVER_VERSION "v.1.7.16"
22 #define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer"
23 #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
25 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/tty.h>
29 #include <linux/slab.h>
31 #include <linux/module.h>
35 #define SWIMS_USB_REQUEST_SetPower 0x00
36 #define SWIMS_USB_REQUEST_SetNmea 0x07
39 #define N_OUT_URB_HM 64
42 #define IN_BUFLEN 4096
44 #define MAX_TRANSFER (PAGE_SIZE - 512)
63 static int sierra_set_power_state(
struct usb_device *
udev,
__u16 swiState)
72 USB_CTRL_SET_TIMEOUT);
84 USB_CTRL_SET_TIMEOUT);
90 u8 ifnum, numendpoints;
92 ifnum = serial->
interface->cur_altsetting->desc.bInterfaceNumber;
93 numendpoints = serial->
interface->cur_altsetting->desc.bNumEndpoints;
98 else if (numendpoints <= 3)
101 num_ports = (numendpoints-1)/2;
114 for (i = 0; i < blacklist->
infolen; i++) {
115 if (info[i] == ifnum)
122 static int is_himemory(
const u8 ifnum,
131 for (i=0; i < himemorylist->
infolen; i++) {
132 if (info[i] == ifnum)
139 static int sierra_calc_interface(
struct usb_serial *serial)
143 struct usb_host_interface *p_host_interface;
149 p_host_interface = p_interface->cur_altsetting;
159 static int sierra_probe(
struct usb_serial *serial,
163 struct usb_device *
udev;
167 ifnum = sierra_calc_interface(serial);
173 if (serial->
interface->num_altsetting == 2) {
174 dev_dbg(&udev->dev,
"Selecting alt setting for interface %d\n",
181 ifnum = sierra_calc_interface(serial);
186 "Ignoring blacklisted interface #%d\n", ifnum);
194 static const u8 hi_memory_typeA_ifaces[] = { 0, 2 };
196 .infolen =
ARRAY_SIZE(hi_memory_typeA_ifaces),
197 .ifaceinfo = hi_memory_typeA_ifaces,
200 static const u8 hi_memory_typeB_ifaces[] = { 3, 4, 5, 6 };
202 .infolen =
ARRAY_SIZE(hi_memory_typeB_ifaces),
203 .ifaceinfo = hi_memory_typeB_ifaces,
207 static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11, 19, 20 };
209 .infolen =
ARRAY_SIZE(direct_ip_non_serial_ifaces),
210 .ifaceinfo = direct_ip_non_serial_ifaces,
214 { USB_DEVICE(0x0F3D, 0x0112) },
215 { USB_DEVICE(0x03F0, 0x1B1D) },
216 { USB_DEVICE(0x03F0, 0x211D) },
217 { USB_DEVICE(0x03F0, 0x1E1D) },
219 { USB_DEVICE(0x1199, 0x0017) },
220 { USB_DEVICE(0x1199, 0x0018) },
221 { USB_DEVICE(0x1199, 0x0218) },
222 { USB_DEVICE(0x1199, 0x0020) },
223 { USB_DEVICE(0x1199, 0x0220) },
224 { USB_DEVICE(0x1199, 0x0022) },
225 { USB_DEVICE(0x1199, 0x0024) },
226 { USB_DEVICE(0x1199, 0x0224) },
227 { USB_DEVICE(0x1199, 0x0019) },
228 { USB_DEVICE(0x1199, 0x0021) },
229 { USB_DEVICE(0x1199, 0x0112) },
230 { USB_DEVICE(0x1199, 0x0120) },
231 { USB_DEVICE(0x1199, 0x0301) },
233 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0023, 0xFF, 0xFF, 0xFF) },
235 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0025, 0xFF, 0xFF, 0xFF) },
236 { USB_DEVICE(0x1199, 0x0026) },
237 { USB_DEVICE(0x1199, 0x0027) },
238 { USB_DEVICE(0x1199, 0x0028) },
239 { USB_DEVICE(0x1199, 0x0029) },
241 { USB_DEVICE(0x1199, 0x6802) },
242 { USB_DEVICE(0x1199, 0x6803) },
243 { USB_DEVICE(0x1199, 0x6804) },
244 { USB_DEVICE(0x1199, 0x6805) },
245 { USB_DEVICE(0x1199, 0x6808) },
246 { USB_DEVICE(0x1199, 0x6809) },
247 { USB_DEVICE(0x1199, 0x6812) },
248 { USB_DEVICE(0x1199, 0x6813) },
249 { USB_DEVICE(0x1199, 0x6815) },
250 { USB_DEVICE(0x1199, 0x6816) },
251 { USB_DEVICE(0x1199, 0x6820) },
252 { USB_DEVICE(0x1199, 0x6821) },
253 { USB_DEVICE(0x1199, 0x6822) },
254 { USB_DEVICE(0x1199, 0x6832) },
255 { USB_DEVICE(0x1199, 0x6833) },
256 { USB_DEVICE(0x1199, 0x6834) },
257 { USB_DEVICE(0x1199, 0x6835) },
258 { USB_DEVICE(0x1199, 0x6838) },
259 { USB_DEVICE(0x1199, 0x6839) },
260 { USB_DEVICE(0x1199, 0x683A) },
261 { USB_DEVICE(0x1199, 0x683B) },
263 { USB_DEVICE(0x1199, 0x683C) },
264 { USB_DEVICE(0x1199, 0x683D) },
266 { USB_DEVICE(0x1199, 0x683E) },
267 { USB_DEVICE(0x1199, 0x6850) },
268 { USB_DEVICE(0x1199, 0x6851) },
269 { USB_DEVICE(0x1199, 0x6852) },
270 { USB_DEVICE(0x1199, 0x6853) },
271 { USB_DEVICE(0x1199, 0x6855) },
272 { USB_DEVICE(0x1199, 0x6856) },
273 { USB_DEVICE(0x1199, 0x6859) },
274 { USB_DEVICE(0x1199, 0x685A) },
276 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6880, 0xFF, 0xFF, 0xFF)},
278 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6890, 0xFF, 0xFF, 0xFF)},
280 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6891, 0xFF, 0xFF, 0xFF)},
282 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6892, 0xFF, 0xFF, 0xFF)},
283 { USB_DEVICE(0x1199, 0x6893) },
284 { USB_DEVICE(0x1199, 0x68A3),
288 { USB_DEVICE_AND_INTERFACE_INFO(0x0F3D, 0x68AA, 0xFF, 0xFF, 0xFF),
291 { USB_DEVICE(0x0f3d, 0x68A3),
294 { USB_DEVICE(0x413C, 0x08133) },
331 portdata = usb_get_serial_port_data(port);
340 interface = sierra_calc_interface(serial);
364 retval = usb_autopm_get_interface(serial->
interface);
370 usb_autopm_put_interface(serial->
interface);
375 static void sierra_set_termios(
struct tty_struct *tty,
379 sierra_send_setup(port);
382 static int sierra_tiocmget(
struct tty_struct *tty)
388 portdata = usb_get_serial_port_data(port);
400 static int sierra_tiocmset(
struct tty_struct *tty,
401 unsigned int set,
unsigned int clear)
406 portdata = usb_get_serial_port_data(port);
417 return sierra_send_setup(port);
420 static void sierra_release_urb(
struct urb *
urb)
425 kfree(urb->transfer_buffer);
430 static void sierra_outdat_callback(
struct urb *urb)
437 intfdata = port->
serial->private;
440 kfree(urb->transfer_buffer);
441 usb_autopm_put_interface_async(port->
serial->interface);
443 dev_dbg(&port->
dev,
"%s - nonzero write bulk status "
444 "received: %d\n", __func__, status);
446 spin_lock(&portdata->
lock);
448 spin_unlock(&portdata->
lock);
458 const unsigned char *
buf,
int count)
473 portdata = usb_get_serial_port_data(port);
476 dev_dbg(&port->
dev,
"%s: write (%zd bytes)\n", __func__, writesize);
478 dev_dbg(&port->
dev,
"%s - outstanding_urbs: %d\n", __func__,
481 spin_unlock_irqrestore(&portdata->
lock, flags);
482 dev_dbg(&port->
dev,
"%s - write limit hit\n", __func__);
486 dev_dbg(&port->
dev,
"%s - 1, outstanding_urbs: %d\n", __func__,
488 spin_unlock_irqrestore(&portdata->
lock, flags);
490 retval = usb_autopm_get_interface_async(serial->
interface);
494 spin_unlock_irqrestore(&portdata->
lock, flags);
502 goto error_no_buffer;
512 memcpy(buffer, buf, writesize);
514 usb_serial_debug_data(&port->
dev, __func__, writesize, buffer);
516 usb_fill_bulk_urb(urb, serial->
dev,
517 usb_sndbulkpipe(serial->
dev,
519 buffer, writesize, sierra_outdat_callback, port);
522 urb->transfer_flags |= URB_ZERO_PACKET;
528 spin_unlock_irqrestore(&intfdata->
susp_lock, flags);
537 spin_unlock_irqrestore(&intfdata->
susp_lock, flags);
538 dev_err(&port->
dev,
"%s - usb_submit_urb(write bulk) failed "
539 "with status = %d\n", __func__, retval);
543 spin_unlock_irqrestore(&intfdata->
susp_lock, flags);
559 dev_dbg(&port->
dev,
"%s - 2. outstanding_urbs: %d\n", __func__,
561 spin_unlock_irqrestore(&portdata->
lock, flags);
562 usb_autopm_put_interface_async(serial->
interface);
567 static void sierra_indat_callback(
struct urb *urb)
573 unsigned char *
data = urb->transfer_buffer;
574 int status = urb->status;
576 endpoint = usb_pipeendpoint(urb->pipe);
580 dev_dbg(&port->
dev,
"%s: nonzero status: %d on"
581 " endpoint %02x\n", __func__, status, endpoint);
583 if (urb->actual_length) {
586 tty_insert_flip_string(tty, data,
591 usb_serial_debug_data(&port->
dev, __func__,
592 urb->actual_length, data);
596 " received\n", __func__);
602 usb_mark_last_busy(port->
serial->dev);
604 if (err && err != -
EPERM)
605 dev_err(&port->
dev,
"resubmit read urb failed."
610 static void sierra_instat_callback(
struct urb *urb)
613 int status = urb->status;
618 dev_dbg(&port->
dev,
"%s: urb %p port %p has data %p\n", __func__,
619 urb, port, portdata);
633 unsigned char signals = *((
unsigned char *)
634 urb->transfer_buffer +
638 dev_dbg(&port->
dev,
"%s: signal x%x\n", __func__,
643 portdata->
dcd_state = ((signals & 0x01) ? 1 : 0);
644 portdata->
dsr_state = ((signals & 0x02) ? 1 : 0);
645 portdata->
ri_state = ((signals & 0x08) ? 1 : 0);
658 dev_dbg(&port->
dev,
"%s: error %d\n", __func__, status);
662 usb_mark_last_busy(serial->
dev);
664 if (err && err != -
EPERM)
666 "failed. (%d)\n", __func__, err);
670 static int sierra_write_room(
struct tty_struct *tty)
680 spin_unlock_irqrestore(&portdata->
lock, flags);
681 dev_dbg(&port->
dev,
"%s - write limit hit\n", __func__);
684 spin_unlock_irqrestore(&portdata->
lock, flags);
715 dev_err(&port->
dev,
"%s: submit urb failed: %d\n",
725 dev_err(&port->
dev,
"%s: submit intr urb failed: %d\n",
736 static struct urb *sierra_setup_urb(
struct usb_serial *serial,
int endpoint,
737 int dir,
void *
ctx,
int len,
749 dev_dbg(&serial->
dev->dev,
"%s: alloc for endpoint %d failed\n",
757 usb_fill_bulk_urb(urb, serial->
dev,
758 usb_sndbulkpipe(serial->
dev, endpoint) | dir,
759 buf, len, callback, ctx);
761 dev_dbg(&serial->
dev->dev,
"%s %c u : %p d:%p\n", __func__,
764 dev_dbg(&serial->
dev->dev,
"%s %c u:%p d:%p\n", __func__,
767 sierra_release_urb(urb);
781 portdata = usb_get_serial_port_data(port);
789 serial->
interface->needs_remote_wakeup = 0;
791 if (!usb_autopm_get_interface(serial->
interface))
792 sierra_send_setup(port);
794 usb_autopm_get_interface_no_resume(serial->
interface);
804 sierra_stop_rx_urbs(port);
807 sierra_release_urb(portdata->
in_urbs[i]);
823 portdata = usb_get_serial_port_data(port);
832 urb = sierra_setup_urb(serial, endpoint,
USB_DIR_IN, port,
834 sierra_indat_callback);
841 err = sierra_submit_rx_urbs(port,
GFP_KERNEL);
847 usb_autopm_put_interface(serial->
interface);
850 sierra_send_setup(port);
852 serial->
interface->needs_remote_wakeup = 1;
856 usb_autopm_put_interface(serial->
interface);
867 portdata = usb_get_serial_port_data(port);
874 sierra_send_setup(port);
879 static int sierra_startup(
struct usb_serial *serial)
883 intfdata = kzalloc(
sizeof(*intfdata),
GFP_KERNEL);
889 usb_set_serial_data(serial, intfdata);
892 sierra_set_power_state(serial->
dev, 0x0000);
896 sierra_vsc_set_nmea(serial->
dev, 1);
901 static void sierra_release(
struct usb_serial *serial)
905 intfdata = usb_get_serial_data(serial);
916 portdata = kzalloc(
sizeof(*portdata),
GFP_KERNEL);
921 init_usb_anchor(&portdata->
active);
922 init_usb_anchor(&portdata->
delayed);
931 ifnum = sierra_calc_interface(serial);
932 himemoryp = &typeB_interface_list;
938 himemoryp = &typeA_interface_list;
941 if (is_himemory(ifnum, himemoryp)) {
947 "Memory usage (urbs) interface #%d, in=%d, out=%d\n",
950 usb_set_serial_port_data(port, portdata);
959 portdata = usb_get_serial_port_data(port);
966 static void stop_read_write_urbs(
struct usb_serial *serial)
974 port = serial->
port[
i];
975 portdata = usb_get_serial_port_data(port);
976 sierra_stop_rx_urbs(port);
999 stop_read_write_urbs(serial);
1014 for (i = 0; i < serial->
num_ports; i++) {
1015 port = serial->
port[
i];
1016 portdata = usb_get_serial_port_data(port);
1031 err = sierra_submit_rx_urbs(port,
GFP_ATOMIC);
1039 return ec ? -
EIO : 0;
1043 #define sierra_suspend NULL
1044 #define sierra_resume NULL
1052 .description =
"Sierra USB modem",
1054 .calc_num_ports = sierra_calc_num_ports,
1055 .probe = sierra_probe,
1056 .open = sierra_open,
1057 .close = sierra_close,
1058 .dtr_rts = sierra_dtr_rts,
1059 .write = sierra_write,
1060 .write_room = sierra_write_room,
1061 .set_termios = sierra_set_termios,
1062 .tiocmget = sierra_tiocmget,
1063 .tiocmset = sierra_tiocmset,
1064 .attach = sierra_startup,
1065 .release = sierra_release,
1066 .port_probe = sierra_port_probe,
1067 .port_remove = sierra_port_remove,
1070 .read_int_callback = sierra_instat_callback,
1074 &sierra_device,
NULL