Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: serial: add generic support for TIOCSSERIAL

TIOCSSERIAL is a horrid, underspecified, legacy interface which for most
serial devices is only useful for setting the close_delay and
closing_wait parameters.

The closing_wait parameter determines how long to wait for the transfer
buffers to drain during close and the default timeout of 30 seconds may
not be sufficient at low line speeds. In other cases, when for example
flow is stopped, the default timeout may instead be too long.

Add generic support for TIOCSSERIAL and TIOCGSERIAL with handling of the
three common parameters close_delay, closing_wait and line for the
benefit of all USB serial drivers while still allowing drivers to
implement further functionality through the existing callbacks.

This currently includes a few drivers that report their base baud clock
rate even if that is really only of interest when setting custom
divisors through the deprecated ASYNC_SPD_CUST interface; an interface
which only the FTDI driver actually implements.

Some drivers have also been reporting back a fake UART type, something
which should no longer be needed and will be dropped by a follow-on
patch.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Johan Hovold <johan@kernel.org>

+70 -226
+1 -8
drivers/usb/serial/ark3116.c
··· 385 385 return result; 386 386 } 387 387 388 - static int ark3116_get_serial_info(struct tty_struct *tty, 388 + static void ark3116_get_serial_info(struct tty_struct *tty, 389 389 struct serial_struct *ss) 390 390 { 391 - struct usb_serial_port *port = tty->driver_data; 392 - 393 391 ss->type = PORT_16654; 394 - ss->line = port->minor; 395 - ss->close_delay = 50; 396 - ss->closing_wait = 3000; 397 - 398 - return 0; 399 392 } 400 393 401 394 static int ark3116_tiocmget(struct tty_struct *tty)
+3 -9
drivers/usb/serial/f81232.c
··· 820 820 return 0; 821 821 } 822 822 823 - static int f81232_get_serial_info(struct tty_struct *tty, 824 - struct serial_struct *ss) 823 + static void f81232_get_serial(struct tty_struct *tty, struct serial_struct *ss) 825 824 { 826 825 struct usb_serial_port *port = tty->driver_data; 827 826 struct f81232_private *priv = usb_get_serial_port_data(port); 828 827 829 828 ss->type = PORT_16550A; 830 - ss->line = port->minor; 831 829 ss->baud_base = priv->baud_base; 832 - ss->close_delay = 50; 833 - ss->closing_wait = 3000; 834 - 835 - return 0; 836 830 } 837 831 838 832 static void f81232_interrupt_work(struct work_struct *work) ··· 1017 1023 .close = f81232_close, 1018 1024 .dtr_rts = f81232_dtr_rts, 1019 1025 .carrier_raised = f81232_carrier_raised, 1020 - .get_serial = f81232_get_serial_info, 1026 + .get_serial = f81232_get_serial, 1021 1027 .break_ctl = f81232_break_ctl, 1022 1028 .set_termios = f81232_set_termios, 1023 1029 .tiocmget = f81232_tiocmget, ··· 1042 1048 .close = f81232_close, 1043 1049 .dtr_rts = f81232_dtr_rts, 1044 1050 .carrier_raised = f81232_carrier_raised, 1045 - .get_serial = f81232_get_serial_info, 1051 + .get_serial = f81232_get_serial, 1046 1052 .break_ctl = f81232_break_ctl, 1047 1053 .set_termios = f81232_set_termios, 1048 1054 .tiocmget = f81232_tiocmget,
+1 -7
drivers/usb/serial/f81534.c
··· 1140 1140 mutex_unlock(&serial_priv->urb_mutex); 1141 1141 } 1142 1142 1143 - static int f81534_get_serial_info(struct tty_struct *tty, 1144 - struct serial_struct *ss) 1143 + static void f81534_get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1145 1144 { 1146 1145 struct usb_serial_port *port = tty->driver_data; 1147 1146 struct f81534_port_private *port_priv; ··· 1148 1149 port_priv = usb_get_serial_port_data(port); 1149 1150 1150 1151 ss->type = PORT_16550A; 1151 - ss->line = port->minor; 1152 1152 ss->baud_base = port_priv->baud_base; 1153 - ss->close_delay = 50; 1154 - ss->closing_wait = 3000; 1155 - 1156 - return 0; 1157 1153 } 1158 1154 1159 1155 static void f81534_process_per_serial_block(struct usb_serial_port *port,
+2 -9
drivers/usb/serial/ftdi_sio.c
··· 1082 1082 unsigned int set, unsigned int clear); 1083 1083 static int ftdi_ioctl(struct tty_struct *tty, 1084 1084 unsigned int cmd, unsigned long arg); 1085 - static int get_serial_info(struct tty_struct *tty, 1086 - struct serial_struct *ss); 1085 + static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss); 1087 1086 static int set_serial_info(struct tty_struct *tty, 1088 1087 struct serial_struct *ss); 1089 1088 static void ftdi_break_ctl(struct tty_struct *tty, int break_state); ··· 1476 1477 return 0; 1477 1478 } 1478 1479 1479 - static int get_serial_info(struct tty_struct *tty, 1480 - struct serial_struct *ss) 1480 + static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1481 1481 { 1482 1482 struct usb_serial_port *port = tty->driver_data; 1483 1483 struct ftdi_private *priv = usb_get_serial_port_data(port); 1484 1484 1485 - ss->line = port->minor; 1486 1485 ss->flags = priv->flags; 1487 1486 ss->baud_base = priv->baud_base; 1488 1487 ss->custom_divisor = priv->custom_divisor; 1489 - ss->close_delay = 50; 1490 - ss->closing_wait = 3000; 1491 - 1492 - return 0; 1493 1488 } 1494 1489 1495 1490 static int set_serial_info(struct tty_struct *tty,
+2 -10
drivers/usb/serial/io_edgeport.c
··· 1594 1594 return result; 1595 1595 } 1596 1596 1597 - static int get_serial_info(struct tty_struct *tty, 1598 - struct serial_struct *ss) 1597 + static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1599 1598 { 1600 - struct usb_serial_port *port = tty->driver_data; 1601 - 1602 - ss->type = PORT_16550A; 1603 - ss->line = port->minor; 1604 - ss->close_delay = 50; 1605 - ss->closing_wait = 3000; 1606 - 1607 - return 0; 1599 + ss->type = PORT_16550A; 1608 1600 } 1609 1601 1610 1602
+2 -15
drivers/usb/serial/io_ti.c
··· 2433 2433 return result; 2434 2434 } 2435 2435 2436 - static int get_serial_info(struct tty_struct *tty, 2437 - struct serial_struct *ss) 2436 + static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 2438 2437 { 2439 - struct usb_serial_port *port = tty->driver_data; 2440 - unsigned cwait; 2441 - 2442 - cwait = port->port.closing_wait; 2443 - if (cwait != ASYNC_CLOSING_WAIT_NONE) 2444 - cwait = jiffies_to_msecs(cwait) / 10; 2445 - 2446 - ss->type = PORT_16550A; 2447 - ss->line = port->minor; 2448 - ss->close_delay = 50; 2449 - ss->closing_wait = cwait; 2450 - 2451 - return 0; 2438 + ss->type = PORT_16550A; 2452 2439 } 2453 2440 2454 2441 static void edge_break(struct tty_struct *tty, int break_state)
+2 -10
drivers/usb/serial/mos7720.c
··· 1634 1634 return 0; 1635 1635 } 1636 1636 1637 - static int get_serial_info(struct tty_struct *tty, 1638 - struct serial_struct *ss) 1637 + static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1639 1638 { 1640 - struct usb_serial_port *port = tty->driver_data; 1641 - 1642 - ss->type = PORT_16550A; 1643 - ss->line = port->minor; 1644 - ss->close_delay = 50; 1645 - ss->closing_wait = 3000; 1646 - 1647 - return 0; 1639 + ss->type = PORT_16550A; 1648 1640 } 1649 1641 1650 1642 static int mos7720_ioctl(struct tty_struct *tty,
+1 -9
drivers/usb/serial/mos7840.c
··· 1388 1388 * function to get information about serial port 1389 1389 *****************************************************************************/ 1390 1390 1391 - static int mos7840_get_serial_info(struct tty_struct *tty, 1392 - struct serial_struct *ss) 1391 + static void mos7840_get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1393 1392 { 1394 - struct usb_serial_port *port = tty->driver_data; 1395 - 1396 1393 ss->type = PORT_16550A; 1397 - ss->line = port->minor; 1398 - ss->close_delay = 50; 1399 - ss->closing_wait = 3000; 1400 - 1401 - return 0; 1402 1394 } 1403 1395 1404 1396 /*****************************************************************************
+2 -10
drivers/usb/serial/opticon.c
··· 352 352 return 0; 353 353 } 354 354 355 - static int get_serial_info(struct tty_struct *tty, 356 - struct serial_struct *ss) 355 + static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 357 356 { 358 - struct usb_serial_port *port = tty->driver_data; 359 - 360 357 /* fake emulate a 16550 uart to make userspace code happy */ 361 - ss->type = PORT_16550A; 362 - ss->line = port->minor; 363 - ss->close_delay = 50; 364 - ss->closing_wait = 3000; 365 - 366 - return 0; 358 + ss->type = PORT_16550A; 367 359 } 368 360 369 361 static int opticon_port_probe(struct usb_serial_port *port)
-2
drivers/usb/serial/option.c
··· 2095 2095 .chars_in_buffer = usb_wwan_chars_in_buffer, 2096 2096 .tiocmget = usb_wwan_tiocmget, 2097 2097 .tiocmset = usb_wwan_tiocmset, 2098 - .get_serial = usb_wwan_get_serial_info, 2099 - .set_serial = usb_wwan_set_serial_info, 2100 2098 .attach = option_attach, 2101 2099 .release = option_release, 2102 2100 .port_probe = usb_wwan_port_probe,
+1 -9
drivers/usb/serial/pl2303.c
··· 1048 1048 return 0; 1049 1049 } 1050 1050 1051 - static int pl2303_get_serial(struct tty_struct *tty, 1052 - struct serial_struct *ss) 1051 + static void pl2303_get_serial(struct tty_struct *tty, struct serial_struct *ss) 1053 1052 { 1054 - struct usb_serial_port *port = tty->driver_data; 1055 - 1056 1053 ss->type = PORT_16654; 1057 - ss->line = port->minor; 1058 - ss->close_delay = 50; 1059 - ss->closing_wait = 3000; 1060 - 1061 - return 0; 1062 1054 } 1063 1055 1064 1056 static void pl2303_set_break(struct usb_serial_port *port, bool enable)
-13
drivers/usb/serial/quatech2.c
··· 453 453 usb_kill_urb(serial_priv->read_urb); 454 454 } 455 455 456 - static int get_serial_info(struct tty_struct *tty, 457 - struct serial_struct *ss) 458 - { 459 - struct usb_serial_port *port = tty->driver_data; 460 - 461 - ss->line = port->minor; 462 - ss->close_delay = 50; 463 - ss->closing_wait = 3000; 464 - 465 - return 0; 466 - } 467 - 468 456 static void qt2_process_status(struct usb_serial_port *port, unsigned char *ch) 469 457 { 470 458 switch (*ch) { ··· 963 975 .tiocmset = qt2_tiocmset, 964 976 .tiocmiwait = usb_serial_generic_tiocmiwait, 965 977 .get_icount = usb_serial_generic_get_icount, 966 - .get_serial = get_serial_info, 967 978 .set_termios = qt2_set_termios, 968 979 }; 969 980
-13
drivers/usb/serial/ssu100.c
··· 331 331 return usb_serial_generic_open(tty, port); 332 332 } 333 333 334 - static int get_serial_info(struct tty_struct *tty, 335 - struct serial_struct *ss) 336 - { 337 - struct usb_serial_port *port = tty->driver_data; 338 - 339 - ss->line = port->minor; 340 - ss->close_delay = 50; 341 - ss->closing_wait = 3000; 342 - 343 - return 0; 344 - } 345 - 346 334 static int ssu100_attach(struct usb_serial *serial) 347 335 { 348 336 return ssu100_initdevice(serial->dev); ··· 530 542 .tiocmset = ssu100_tiocmset, 531 543 .tiocmiwait = usb_serial_generic_tiocmiwait, 532 544 .get_icount = usb_serial_generic_get_icount, 533 - .get_serial = get_serial_info, 534 545 .set_termios = ssu100_set_termios, 535 546 }; 536 547
+2 -40
drivers/usb/serial/ti_usb_3410_5052.c
··· 328 328 static void ti_send(struct ti_port *tport); 329 329 static int ti_set_mcr(struct ti_port *tport, unsigned int mcr); 330 330 static int ti_get_lsr(struct ti_port *tport, u8 *lsr); 331 - static int ti_get_serial_info(struct tty_struct *tty, 332 - struct serial_struct *ss); 333 - static int ti_set_serial_info(struct tty_struct *tty, 334 - struct serial_struct *ss); 331 + static void ti_get_serial_info(struct tty_struct *tty, struct serial_struct *ss); 335 332 static void ti_handle_new_msr(struct ti_port *tport, u8 msr); 336 333 337 334 static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty); ··· 432 435 .throttle = ti_throttle, 433 436 .unthrottle = ti_unthrottle, 434 437 .get_serial = ti_get_serial_info, 435 - .set_serial = ti_set_serial_info, 436 438 .set_termios = ti_set_termios, 437 439 .tiocmget = ti_tiocmget, 438 440 .tiocmset = ti_tiocmset, ··· 465 469 .throttle = ti_throttle, 466 470 .unthrottle = ti_unthrottle, 467 471 .get_serial = ti_get_serial_info, 468 - .set_serial = ti_set_serial_info, 469 472 .set_termios = ti_set_termios, 470 473 .tiocmget = ti_tiocmget, 471 474 .tiocmset = ti_tiocmset, ··· 1388 1393 } 1389 1394 1390 1395 1391 - static int ti_get_serial_info(struct tty_struct *tty, 1392 - struct serial_struct *ss) 1396 + static void ti_get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1393 1397 { 1394 1398 struct usb_serial_port *port = tty->driver_data; 1395 1399 struct ti_port *tport = usb_get_serial_port_data(port); 1396 - unsigned cwait; 1397 - 1398 - cwait = port->port.closing_wait; 1399 - if (cwait != ASYNC_CLOSING_WAIT_NONE) 1400 - cwait = jiffies_to_msecs(cwait) / 10; 1401 1400 1402 1401 ss->type = PORT_16550A; 1403 - ss->line = port->minor; 1404 1402 ss->baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800; 1405 - ss->close_delay = 50; 1406 - ss->closing_wait = cwait; 1407 - 1408 - return 0; 1409 - } 1410 - 1411 - 1412 - static int ti_set_serial_info(struct tty_struct *tty, 1413 - struct serial_struct *ss) 1414 - { 1415 - struct usb_serial_port *port = tty->driver_data; 1416 - struct tty_port *tport = &port->port; 1417 - unsigned cwait; 1418 - 1419 - cwait = ss->closing_wait; 1420 - if (cwait != ASYNC_CLOSING_WAIT_NONE) 1421 - cwait = msecs_to_jiffies(10 * ss->closing_wait); 1422 - 1423 - if (!capable(CAP_SYS_ADMIN)) { 1424 - if (cwait != tport->closing_wait) 1425 - return -EPERM; 1426 - } 1427 - 1428 - tport->closing_wait = cwait; 1429 - 1430 - return 0; 1431 1403 } 1432 1404 1433 1405
+48 -5
drivers/usb/serial/usb-serial.c
··· 437 437 static int serial_get_serial(struct tty_struct *tty, struct serial_struct *ss) 438 438 { 439 439 struct usb_serial_port *port = tty->driver_data; 440 + struct tty_port *tport = &port->port; 441 + unsigned int close_delay, closing_wait; 442 + 443 + mutex_lock(&tport->mutex); 444 + 445 + close_delay = jiffies_to_msecs(tport->close_delay) / 10; 446 + closing_wait = tport->closing_wait; 447 + if (closing_wait != ASYNC_CLOSING_WAIT_NONE) 448 + closing_wait = jiffies_to_msecs(closing_wait) / 10; 449 + 450 + ss->line = port->minor; 451 + ss->close_delay = close_delay; 452 + ss->closing_wait = closing_wait; 440 453 441 454 if (port->serial->type->get_serial) 442 - return port->serial->type->get_serial(tty, ss); 443 - return -ENOTTY; 455 + port->serial->type->get_serial(tty, ss); 456 + 457 + mutex_unlock(&tport->mutex); 458 + 459 + return 0; 444 460 } 445 461 446 462 static int serial_set_serial(struct tty_struct *tty, struct serial_struct *ss) 447 463 { 448 464 struct usb_serial_port *port = tty->driver_data; 465 + struct tty_port *tport = &port->port; 466 + unsigned int close_delay, closing_wait; 467 + int ret = 0; 449 468 450 - if (port->serial->type->set_serial) 451 - return port->serial->type->set_serial(tty, ss); 452 - return -ENOTTY; 469 + close_delay = msecs_to_jiffies(ss->close_delay * 10); 470 + closing_wait = ss->closing_wait; 471 + if (closing_wait != ASYNC_CLOSING_WAIT_NONE) 472 + closing_wait = msecs_to_jiffies(closing_wait * 10); 473 + 474 + mutex_lock(&tport->mutex); 475 + 476 + if (!capable(CAP_SYS_ADMIN)) { 477 + if (close_delay != tport->close_delay || 478 + closing_wait != tport->closing_wait) { 479 + ret = -EPERM; 480 + goto out_unlock; 481 + } 482 + } 483 + 484 + if (port->serial->type->set_serial) { 485 + ret = port->serial->type->set_serial(tty, ss); 486 + if (ret) 487 + goto out_unlock; 488 + } 489 + 490 + tport->close_delay = close_delay; 491 + tport->closing_wait = closing_wait; 492 + out_unlock: 493 + mutex_unlock(&tport->mutex); 494 + 495 + return ret; 453 496 } 454 497 455 498 static int serial_ioctl(struct tty_struct *tty,
-4
drivers/usb/serial/usb-wwan.h
··· 15 15 extern int usb_wwan_tiocmget(struct tty_struct *tty); 16 16 extern int usb_wwan_tiocmset(struct tty_struct *tty, 17 17 unsigned int set, unsigned int clear); 18 - extern int usb_wwan_get_serial_info(struct tty_struct *tty, 19 - struct serial_struct *ss); 20 - extern int usb_wwan_set_serial_info(struct tty_struct *tty, 21 - struct serial_struct *ss); 22 18 extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, 23 19 const unsigned char *buf, int count); 24 20 extern int usb_wwan_chars_in_buffer(struct tty_struct *tty);
-42
drivers/usb/serial/usb_wwan.c
··· 132 132 } 133 133 EXPORT_SYMBOL(usb_wwan_tiocmset); 134 134 135 - int usb_wwan_get_serial_info(struct tty_struct *tty, 136 - struct serial_struct *ss) 137 - { 138 - struct usb_serial_port *port = tty->driver_data; 139 - 140 - ss->line = port->minor; 141 - ss->close_delay = jiffies_to_msecs(port->port.close_delay) / 10; 142 - ss->closing_wait = port->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? 143 - ASYNC_CLOSING_WAIT_NONE : 144 - jiffies_to_msecs(port->port.closing_wait) / 10; 145 - return 0; 146 - } 147 - EXPORT_SYMBOL(usb_wwan_get_serial_info); 148 - 149 - int usb_wwan_set_serial_info(struct tty_struct *tty, 150 - struct serial_struct *ss) 151 - { 152 - struct usb_serial_port *port = tty->driver_data; 153 - unsigned int closing_wait, close_delay; 154 - int retval = 0; 155 - 156 - close_delay = msecs_to_jiffies(ss->close_delay * 10); 157 - closing_wait = ss->closing_wait == ASYNC_CLOSING_WAIT_NONE ? 158 - ASYNC_CLOSING_WAIT_NONE : 159 - msecs_to_jiffies(ss->closing_wait * 10); 160 - 161 - mutex_lock(&port->port.mutex); 162 - 163 - if (!capable(CAP_SYS_ADMIN)) { 164 - if ((close_delay != port->port.close_delay) || 165 - (closing_wait != port->port.closing_wait)) 166 - retval = -EPERM; 167 - } else { 168 - port->port.close_delay = close_delay; 169 - port->port.closing_wait = closing_wait; 170 - } 171 - 172 - mutex_unlock(&port->port.mutex); 173 - return retval; 174 - } 175 - EXPORT_SYMBOL(usb_wwan_set_serial_info); 176 - 177 135 int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, 178 136 const unsigned char *buf, int count) 179 137 {
+2 -10
drivers/usb/serial/whiteheat.c
··· 83 83 static int whiteheat_open(struct tty_struct *tty, 84 84 struct usb_serial_port *port); 85 85 static void whiteheat_close(struct usb_serial_port *port); 86 - static int whiteheat_get_serial(struct tty_struct *tty, 86 + static void whiteheat_get_serial(struct tty_struct *tty, 87 87 struct serial_struct *ss); 88 88 static void whiteheat_set_termios(struct tty_struct *tty, 89 89 struct usb_serial_port *port, struct ktermios *old); ··· 439 439 } 440 440 441 441 442 - static int whiteheat_get_serial(struct tty_struct *tty, 443 - struct serial_struct *ss) 442 + static void whiteheat_get_serial(struct tty_struct *tty, struct serial_struct *ss) 444 443 { 445 - struct usb_serial_port *port = tty->driver_data; 446 - 447 444 ss->type = PORT_16654; 448 - ss->line = port->minor; 449 445 ss->baud_base = 460800; 450 - ss->close_delay = 50; 451 - ss->closing_wait = 3000; 452 - 453 - return 0; 454 446 } 455 447 456 448
+1 -1
include/linux/usb/serial.h
··· 279 279 int (*write_room)(struct tty_struct *tty); 280 280 int (*ioctl)(struct tty_struct *tty, 281 281 unsigned int cmd, unsigned long arg); 282 - int (*get_serial)(struct tty_struct *tty, struct serial_struct *ss); 282 + void (*get_serial)(struct tty_struct *tty, struct serial_struct *ss); 283 283 int (*set_serial)(struct tty_struct *tty, struct serial_struct *ss); 284 284 void (*set_termios)(struct tty_struct *tty, 285 285 struct usb_serial_port *port, struct ktermios *old);