aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/option.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/option.c')
-rw-r--r--drivers/usb/serial/option.c138
1 files changed, 120 insertions, 18 deletions
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index fe47051dbef2..f66e39883218 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -291,6 +291,7 @@ static int option_resume(struct usb_serial *serial);
291 291
292#define TELIT_VENDOR_ID 0x1bc7 292#define TELIT_VENDOR_ID 0x1bc7
293#define TELIT_PRODUCT_UC864E 0x1003 293#define TELIT_PRODUCT_UC864E 0x1003
294#define TELIT_PRODUCT_UC864G 0x1004
294 295
295/* ZTE PRODUCTS */ 296/* ZTE PRODUCTS */
296#define ZTE_VENDOR_ID 0x19d2 297#define ZTE_VENDOR_ID 0x19d2
@@ -299,6 +300,7 @@ static int option_resume(struct usb_serial *serial);
299#define ZTE_PRODUCT_MF626 0x0031 300#define ZTE_PRODUCT_MF626 0x0031
300#define ZTE_PRODUCT_CDMA_TECH 0xfffe 301#define ZTE_PRODUCT_CDMA_TECH 0xfffe
301#define ZTE_PRODUCT_AC8710 0xfff1 302#define ZTE_PRODUCT_AC8710 0xfff1
303#define ZTE_PRODUCT_AC2726 0xfff5
302 304
303#define BENQ_VENDOR_ID 0x04a5 305#define BENQ_VENDOR_ID 0x04a5
304#define BENQ_PRODUCT_H10 0x4068 306#define BENQ_PRODUCT_H10 0x4068
@@ -502,6 +504,7 @@ static struct usb_device_id option_ids[] = {
502 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */ 504 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */
503 { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */ 505 { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */
504 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) }, 506 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) },
507 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864G) },
505 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */ 508 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */
506 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff) }, 509 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff) },
507 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0003, 0xff, 0xff, 0xff) }, 510 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0003, 0xff, 0xff, 0xff) },
@@ -571,6 +574,7 @@ static struct usb_device_id option_ids[] = {
571 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) }, 574 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) },
572 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, 575 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) },
573 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) }, 576 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) },
577 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) },
574 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, 578 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) },
575 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, 579 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) },
576 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) }, 580 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) },
@@ -592,6 +596,7 @@ static struct usb_driver option_driver = {
592#ifdef CONFIG_PM 596#ifdef CONFIG_PM
593 .suspend = usb_serial_suspend, 597 .suspend = usb_serial_suspend,
594 .resume = usb_serial_resume, 598 .resume = usb_serial_resume,
599 .supports_autosuspend = 1,
595#endif 600#endif
596 .id_table = option_ids, 601 .id_table = option_ids,
597 .no_dynamic_id = 1, 602 .no_dynamic_id = 1,
@@ -639,6 +644,12 @@ static int debug;
639#define IN_BUFLEN 4096 644#define IN_BUFLEN 4096
640#define OUT_BUFLEN 4096 645#define OUT_BUFLEN 4096
641 646
647struct option_intf_private {
648 spinlock_t susp_lock;
649 unsigned int suspended:1;
650 int in_flight;
651};
652
642struct option_port_private { 653struct option_port_private {
643 /* Input endpoints and buffer for this port */ 654 /* Input endpoints and buffer for this port */
644 struct urb *in_urbs[N_IN_URB]; 655 struct urb *in_urbs[N_IN_URB];
@@ -647,6 +658,8 @@ struct option_port_private {
647 struct urb *out_urbs[N_OUT_URB]; 658 struct urb *out_urbs[N_OUT_URB];
648 u8 *out_buffer[N_OUT_URB]; 659 u8 *out_buffer[N_OUT_URB];
649 unsigned long out_busy; /* Bit vector of URBs in use */ 660 unsigned long out_busy; /* Bit vector of URBs in use */
661 int opened;
662 struct usb_anchor delayed;
650 663
651 /* Settings for the port */ 664 /* Settings for the port */
652 int rts_state; /* Handshaking pins (outputs) */ 665 int rts_state; /* Handshaking pins (outputs) */
@@ -693,12 +706,17 @@ module_exit(option_exit);
693static int option_probe(struct usb_serial *serial, 706static int option_probe(struct usb_serial *serial,
694 const struct usb_device_id *id) 707 const struct usb_device_id *id)
695{ 708{
709 struct option_intf_private *data;
696 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */ 710 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */
697 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID && 711 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID &&
698 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 && 712 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 &&
699 serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8) 713 serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8)
700 return -ENODEV; 714 return -ENODEV;
701 715
716 data = serial->private = kzalloc(sizeof(struct option_intf_private), GFP_KERNEL);
717 if (!data)
718 return -ENOMEM;
719 spin_lock_init(&data->susp_lock);
702 return 0; 720 return 0;
703} 721}
704 722
@@ -755,12 +773,15 @@ static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
755 const unsigned char *buf, int count) 773 const unsigned char *buf, int count)
756{ 774{
757 struct option_port_private *portdata; 775 struct option_port_private *portdata;
776 struct option_intf_private *intfdata;
758 int i; 777 int i;
759 int left, todo; 778 int left, todo;
760 struct urb *this_urb = NULL; /* spurious */ 779 struct urb *this_urb = NULL; /* spurious */
761 int err; 780 int err;
781 unsigned long flags;
762 782
763 portdata = usb_get_serial_port_data(port); 783 portdata = usb_get_serial_port_data(port);
784 intfdata = port->serial->private;
764 785
765 dbg("%s: write (%d chars)", __func__, count); 786 dbg("%s: write (%d chars)", __func__, count);
766 787
@@ -782,17 +803,33 @@ static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
782 dbg("%s: endpoint %d buf %d", __func__, 803 dbg("%s: endpoint %d buf %d", __func__,
783 usb_pipeendpoint(this_urb->pipe), i); 804 usb_pipeendpoint(this_urb->pipe), i);
784 805
806 err = usb_autopm_get_interface_async(port->serial->interface);
807 if (err < 0)
808 break;
809
785 /* send the data */ 810 /* send the data */
786 memcpy(this_urb->transfer_buffer, buf, todo); 811 memcpy(this_urb->transfer_buffer, buf, todo);
787 this_urb->transfer_buffer_length = todo; 812 this_urb->transfer_buffer_length = todo;
788 813
789 err = usb_submit_urb(this_urb, GFP_ATOMIC); 814 spin_lock_irqsave(&intfdata->susp_lock, flags);
790 if (err) { 815 if (intfdata->suspended) {
791 dbg("usb_submit_urb %p (write bulk) failed " 816 usb_anchor_urb(this_urb, &portdata->delayed);
792 "(%d)", this_urb, err); 817 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
793 clear_bit(i, &portdata->out_busy); 818 } else {
794 continue; 819 intfdata->in_flight++;
820 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
821 err = usb_submit_urb(this_urb, GFP_ATOMIC);
822 if (err) {
823 dbg("usb_submit_urb %p (write bulk) failed "
824 "(%d)", this_urb, err);
825 clear_bit(i, &portdata->out_busy);
826 spin_lock_irqsave(&intfdata->susp_lock, flags);
827 intfdata->in_flight--;
828 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
829 continue;
830 }
795 } 831 }
832
796 portdata->tx_start_time[i] = jiffies; 833 portdata->tx_start_time[i] = jiffies;
797 buf += todo; 834 buf += todo;
798 left -= todo; 835 left -= todo;
@@ -836,7 +873,10 @@ static void option_indat_callback(struct urb *urb)
836 if (err) 873 if (err)
837 printk(KERN_ERR "%s: resubmit read urb failed. " 874 printk(KERN_ERR "%s: resubmit read urb failed. "
838 "(%d)", __func__, err); 875 "(%d)", __func__, err);
876 else
877 usb_mark_last_busy(port->serial->dev);
839 } 878 }
879
840 } 880 }
841 return; 881 return;
842} 882}
@@ -845,15 +885,21 @@ static void option_outdat_callback(struct urb *urb)
845{ 885{
846 struct usb_serial_port *port; 886 struct usb_serial_port *port;
847 struct option_port_private *portdata; 887 struct option_port_private *portdata;
888 struct option_intf_private *intfdata;
848 int i; 889 int i;
849 890
850 dbg("%s", __func__); 891 dbg("%s", __func__);
851 892
852 port = urb->context; 893 port = urb->context;
894 intfdata = port->serial->private;
853 895
854 usb_serial_port_softint(port); 896 usb_serial_port_softint(port);
855 897 usb_autopm_put_interface_async(port->serial->interface);
856 portdata = usb_get_serial_port_data(port); 898 portdata = usb_get_serial_port_data(port);
899 spin_lock(&intfdata->susp_lock);
900 intfdata->in_flight--;
901 spin_unlock(&intfdata->susp_lock);
902
857 for (i = 0; i < N_OUT_URB; ++i) { 903 for (i = 0; i < N_OUT_URB; ++i) {
858 if (portdata->out_urbs[i] == urb) { 904 if (portdata->out_urbs[i] == urb) {
859 smp_mb__before_clear_bit(); 905 smp_mb__before_clear_bit();
@@ -963,10 +1009,13 @@ static int option_chars_in_buffer(struct tty_struct *tty)
963static int option_open(struct tty_struct *tty, struct usb_serial_port *port) 1009static int option_open(struct tty_struct *tty, struct usb_serial_port *port)
964{ 1010{
965 struct option_port_private *portdata; 1011 struct option_port_private *portdata;
1012 struct option_intf_private *intfdata;
1013 struct usb_serial *serial = port->serial;
966 int i, err; 1014 int i, err;
967 struct urb *urb; 1015 struct urb *urb;
968 1016
969 portdata = usb_get_serial_port_data(port); 1017 portdata = usb_get_serial_port_data(port);
1018 intfdata = serial->private;
970 1019
971 dbg("%s", __func__); 1020 dbg("%s", __func__);
972 1021
@@ -985,6 +1034,12 @@ static int option_open(struct tty_struct *tty, struct usb_serial_port *port)
985 1034
986 option_send_setup(port); 1035 option_send_setup(port);
987 1036
1037 serial->interface->needs_remote_wakeup = 1;
1038 spin_lock_irq(&intfdata->susp_lock);
1039 portdata->opened = 1;
1040 spin_unlock_irq(&intfdata->susp_lock);
1041 usb_autopm_put_interface(serial->interface);
1042
988 return 0; 1043 return 0;
989} 1044}
990 1045
@@ -1009,16 +1064,23 @@ static void option_close(struct usb_serial_port *port)
1009 int i; 1064 int i;
1010 struct usb_serial *serial = port->serial; 1065 struct usb_serial *serial = port->serial;
1011 struct option_port_private *portdata; 1066 struct option_port_private *portdata;
1067 struct option_intf_private *intfdata = port->serial->private;
1012 1068
1013 dbg("%s", __func__); 1069 dbg("%s", __func__);
1014 portdata = usb_get_serial_port_data(port); 1070 portdata = usb_get_serial_port_data(port);
1015 1071
1016 if (serial->dev) { 1072 if (serial->dev) {
1017 /* Stop reading/writing urbs */ 1073 /* Stop reading/writing urbs */
1074 spin_lock_irq(&intfdata->susp_lock);
1075 portdata->opened = 0;
1076 spin_unlock_irq(&intfdata->susp_lock);
1077
1018 for (i = 0; i < N_IN_URB; i++) 1078 for (i = 0; i < N_IN_URB; i++)
1019 usb_kill_urb(portdata->in_urbs[i]); 1079 usb_kill_urb(portdata->in_urbs[i]);
1020 for (i = 0; i < N_OUT_URB; i++) 1080 for (i = 0; i < N_OUT_URB; i++)
1021 usb_kill_urb(portdata->out_urbs[i]); 1081 usb_kill_urb(portdata->out_urbs[i]);
1082 usb_autopm_get_interface(serial->interface);
1083 serial->interface->needs_remote_wakeup = 0;
1022 } 1084 }
1023} 1085}
1024 1086
@@ -1123,6 +1185,7 @@ static int option_startup(struct usb_serial *serial)
1123 __func__, i); 1185 __func__, i);
1124 return 1; 1186 return 1;
1125 } 1187 }
1188 init_usb_anchor(&portdata->delayed);
1126 1189
1127 for (j = 0; j < N_IN_URB; j++) { 1190 for (j = 0; j < N_IN_URB; j++) {
1128 buffer = (u8 *)__get_free_page(GFP_KERNEL); 1191 buffer = (u8 *)__get_free_page(GFP_KERNEL);
@@ -1225,18 +1288,52 @@ static void option_release(struct usb_serial *serial)
1225#ifdef CONFIG_PM 1288#ifdef CONFIG_PM
1226static int option_suspend(struct usb_serial *serial, pm_message_t message) 1289static int option_suspend(struct usb_serial *serial, pm_message_t message)
1227{ 1290{
1291 struct option_intf_private *intfdata = serial->private;
1292 int b;
1293
1228 dbg("%s entered", __func__); 1294 dbg("%s entered", __func__);
1295
1296 if (serial->dev->auto_pm) {
1297 spin_lock_irq(&intfdata->susp_lock);
1298 b = intfdata->in_flight;
1299 spin_unlock_irq(&intfdata->susp_lock);
1300
1301 if (b)
1302 return -EBUSY;
1303 }
1304
1305 spin_lock_irq(&intfdata->susp_lock);
1306 intfdata->suspended = 1;
1307 spin_unlock_irq(&intfdata->susp_lock);
1229 stop_read_write_urbs(serial); 1308 stop_read_write_urbs(serial);
1230 1309
1231 return 0; 1310 return 0;
1232} 1311}
1233 1312
1313static void play_delayed(struct usb_serial_port *port)
1314{
1315 struct option_intf_private *data;
1316 struct option_port_private *portdata;
1317 struct urb *urb;
1318 int err;
1319
1320 portdata = usb_get_serial_port_data(port);
1321 data = port->serial->private;
1322 while ((urb = usb_get_from_anchor(&portdata->delayed))) {
1323 err = usb_submit_urb(urb, GFP_ATOMIC);
1324 if (!err)
1325 data->in_flight++;
1326 }
1327}
1328
1234static int option_resume(struct usb_serial *serial) 1329static int option_resume(struct usb_serial *serial)
1235{ 1330{
1236 int err, i, j; 1331 int i, j;
1237 struct usb_serial_port *port; 1332 struct usb_serial_port *port;
1238 struct urb *urb; 1333 struct option_intf_private *intfdata = serial->private;
1239 struct option_port_private *portdata; 1334 struct option_port_private *portdata;
1335 struct urb *urb;
1336 int err = 0;
1240 1337
1241 dbg("%s entered", __func__); 1338 dbg("%s entered", __func__);
1242 /* get the interrupt URBs resubmitted unconditionally */ 1339 /* get the interrupt URBs resubmitted unconditionally */
@@ -1251,7 +1348,7 @@ static int option_resume(struct usb_serial *serial)
1251 if (err < 0) { 1348 if (err < 0) {
1252 err("%s: Error %d for interrupt URB of port%d", 1349 err("%s: Error %d for interrupt URB of port%d",
1253 __func__, err, i); 1350 __func__, err, i);
1254 return err; 1351 goto err_out;
1255 } 1352 }
1256 } 1353 }
1257 1354
@@ -1259,27 +1356,32 @@ static int option_resume(struct usb_serial *serial)
1259 /* walk all ports */ 1356 /* walk all ports */
1260 port = serial->port[i]; 1357 port = serial->port[i];
1261 portdata = usb_get_serial_port_data(port); 1358 portdata = usb_get_serial_port_data(port);
1262 mutex_lock(&port->mutex);
1263 1359
1264 /* skip closed ports */ 1360 /* skip closed ports */
1265 if (!port->port.count) { 1361 spin_lock_irq(&intfdata->susp_lock);
1266 mutex_unlock(&port->mutex); 1362 if (!portdata->opened) {
1363 spin_unlock_irq(&intfdata->susp_lock);
1267 continue; 1364 continue;
1268 } 1365 }
1269 1366
1270 for (j = 0; j < N_IN_URB; j++) { 1367 for (j = 0; j < N_IN_URB; j++) {
1271 urb = portdata->in_urbs[j]; 1368 urb = portdata->in_urbs[j];
1272 err = usb_submit_urb(urb, GFP_NOIO); 1369 err = usb_submit_urb(urb, GFP_ATOMIC);
1273 if (err < 0) { 1370 if (err < 0) {
1274 mutex_unlock(&port->mutex);
1275 err("%s: Error %d for bulk URB %d", 1371 err("%s: Error %d for bulk URB %d",
1276 __func__, err, i); 1372 __func__, err, i);
1277 return err; 1373 spin_unlock_irq(&intfdata->susp_lock);
1374 goto err_out;
1278 } 1375 }
1279 } 1376 }
1280 mutex_unlock(&port->mutex); 1377 play_delayed(port);
1378 spin_unlock_irq(&intfdata->susp_lock);
1281 } 1379 }
1282 return 0; 1380 spin_lock_irq(&intfdata->susp_lock);
1381 intfdata->suspended = 0;
1382 spin_unlock_irq(&intfdata->susp_lock);
1383err_out:
1384 return err;
1283} 1385}
1284#endif 1386#endif
1285 1387