summaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/generic.c
Commit message (Collapse)AuthorAgeFilesLines
* USB: serial: make usb_serial_driver::chars_in_buffer return uintJiri Slaby2021-05-191-3/+3
| | | | | | | | | tty_operations::chars_in_buffer is being switched to return uint. Do the same for usb_serial_driver's chars_in_buffer. Signed-off-by: Jiri Slaby <jslaby@suse.cz> [ johan: amend commit message ] Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: make usb_serial_driver::write_room return uintJiri Slaby2021-05-191-3/+3
| | | | | | | | | | | Line disciplines expect a positive value or zero returned from tty->ops->write_room (invoked by tty_write_room). Both of them are being updated to return an unsigned int. Switch also usb_serial_driver::write_room and all its users. Signed-off-by: Jiri Slaby <jslaby@suse.cz> [ johan: amend commit message, drop unrelated comment change ] Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: drop redundant transfer-buffer castsJohan Hovold2020-07-091-1/+1
| | | | | | | Drop redundant URB transfer-buffer casts. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: add sysrq break-handler dummyJohan Hovold2020-07-091-2/+2
| | | | | | | | | Add inline sysrq break-handler dummy to allow the compiler to eliminate further code when either console or sysrq support isn't enabled and to clearly mark the two sysrq functions as belonging together. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: inline sysrq dummy functionJohan Hovold2020-07-091-7/+2
| | | | | | | | | Inline the dummy sysrq character handling when either console support or magic-sysrq support isn't enabled to allow the compiler to eliminate unused code. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: only process sysrq when enabledJohan Hovold2020-07-091-1/+1
| | | | | | | | Do not set the sysrq timestamp unless CONFIG_MAGIC_SYSRQ is enabled to avoid unnecessary per-character processing for consoles. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: only set sysrq timestamp for consolesJohan Hovold2020-07-091-4/+7
| | | | | | | | Only set the sysrq timestamp for console ports to avoid having every driver also check the console flag when processing incoming data. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: clean up carrier-detect helperJohan Hovold2020-03-111-5/+3
| | | | | | | | Drop the struct tty_port pointer and rename the struct usb_serial_port pointer "port", which is the named used throughout the subsystem and incidentally also matches the kernel-doc comment. Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: relax unthrottle memory barrierJohan Hovold2020-02-101-2/+2
| | | | | | | | | | | | Commit a8d78d9f3856 ("USB: serial: clean up throttle handling") converted the throttle handling to use atomic bitops. This means that we can relax the smp_mb() in unthrottle() to smp_mb__after_atomic(), which for example is a no-op on architectures like x86 that provide fully ordered atomics. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Davidlohr Bueso <dbueso@suse.de> Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: drop unnecessary gotoJohan Hovold2019-04-301-2/+1
| | | | | | Drop an unnecessary goto from a write-urb completion error path. Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: clean up throttle handlingJohan Hovold2019-04-301-26/+8
| | | | | | | | | | Clean up the throttle implementation by dropping the redundant throttle_req flag which was a remnant from back when there was only a single read URB. Also convert the throttled flag to an atomic bit flag. Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: fix unthrottle racesJohan Hovold2019-04-301-7/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix two long-standing bugs which could potentially lead to memory corruption or leave the port throttled until it is reopened (on weakly ordered systems), respectively, when read-URB completion races with unthrottle(). First, the URB must not be marked as free before processing is complete to prevent it from being submitted by unthrottle() on another CPU. CPU 1 CPU 2 ================ ================ complete() unthrottle() process_urb(); smp_mb__before_atomic(); set_bit(i, free); if (test_and_clear_bit(i, free)) submit_urb(); Second, the URB must be marked as free before checking the throttled flag to prevent unthrottle() on another CPU from failing to observe that the URB needs to be submitted if complete() sees that the throttled flag is set. CPU 1 CPU 2 ================ ================ complete() unthrottle() set_bit(i, free); throttled = 0; smp_mb__after_atomic(); smp_mb(); if (throttled) if (test_and_clear_bit(i, free)) return; submit_urb(); Note that test_and_clear_bit() only implies barriers when the test is successful. To handle the case where the URB is still in use an explicit barrier needs to be added to unthrottle() for the second race condition. Fixes: d83b405383c9 ("USB: serial: add support for multiple read urbs") Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: Remove redundant license textGreg Kroah-Hartman2017-11-041-4/+0
| | | | | | | | | | | | | | | | | Now that the SPDX tag is in all USB files, that identifies the license in a specific and legally-defined manner. So the extra GPL text wording can be removed as it is no longer needed at all. This is done on a quest to remove the 700+ different ways that files in the kernel describe the GPL license text. And there's unneeded stuff like the address (sometimes incorrect) for the FSF which is never needed. No copyright headers or other non-license-description text was removed. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: add SPDX identifiers to all remaining files in drivers/usb/Greg Kroah-Hartman2017-11-041-0/+1
| | | | | | | | | | | | | | | | | | | | | It's good to have SPDX identifiers in all files to make it easier to audit the kernel tree for correct licenses. Update the drivers/usb/ and include/linux/usb* files with the correct SPDX license identifier based on the license text in the file itself. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This work is based on a script and data from Thomas Gleixner, Philippe Ombredanne, and Kate Stewart. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Kate Stewart <kstewart@linuxfoundation.org> Cc: Philippe Ombredanne <pombredanne@nexb.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com> Acked-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: relax generic driver bulk-endpoint requirementJohan Hovold2017-03-281-2/+4
| | | | | | | Relax the generic driver bulk-endpoint requirement. The driver handles devices without bulk-out endpoints just fine these days. Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: add calc_num_ports callback to generic driverJohan Hovold2017-03-281-2/+16
| | | | | | | | | Add a calc_num_ports callback to the generic driver and verify that the device has the required endpoints there instead of in core. Note that the generic driver num_ports field was never used. Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: add probe callback to generic driverJohan Hovold2017-03-281-0/+12
| | | | | | | | | | Add a probe callback to the generic driver and print the only-for-testing message there. This is a first step in getting rid of the CONFIG_USB_SERIAL_GENERIC ifdef from usb-serial core. Signed-off-by: Johan Hovold <johan@kernel.org>
* sched/headers: Prepare to move signal wakeup & sigpending methods from ↵Ingo Molnar2017-03-021-0/+1
| | | | | | | | | | | | | <linux/sched.h> into <linux/sched/signal.h> Fix up affected files that include this signal functionality via sched.h. Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
* USB: serial: use variable for statusOliver Neukum2016-07-161-8/+10
| | | | | | | | | This patch turns status in a variable read once from the URB. The long term plan is to deliver status to the callback. In addition it makes the code a bit more elegant. Signed-off-by: Oliver Neukum <oneukum@suse.com> Signed-off-by: Johan Hovold <johan@kernel.org>
* tty: Replace ASYNC_INITIALIZED bit and update atomicallyPeter Hurley2016-04-301-3/+3
| | | | | | | | | | | | | | Replace ASYNC_INITIALIZED bit in the tty_port::flags field with TTY_PORT_INITIALIZED bit in the tty_port::iflags field. Introduce helpers tty_port_set_initialized() and tty_port_initialized() to abstract atomic bit ops. Note: the transforms for test_and_set_bit() and test_and_clear_bit() are unnecessary as the state transitions are already mutually exclusive; the tty lock prevents concurrent open/close/hangup. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: fix infinite wait_until_sent timeoutJohan Hovold2015-03-071-2/+3
| | | | | | | | | | | | | | Make sure to handle an infinite timeout (0). Note that wait_until_sent is currently never called with a 0-timeout argument due to a bug in tty_wait_until_sent. Fixes: dcf010503966 ("USB: serial: add generic wait_until_sent implementation") Cc: stable <stable@vger.kernel.org> # v3.10 Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* usb: serial: handle -ENODEV quietly in generic_submit_read_urbJeremiah Mahler2015-01-121-1/+1
| | | | | | | | | | | | | | If a USB serial device (e.g. /dev/ttyUSB0) with an active program is unplugged, an -ENODEV (19) error will be produced after it gives up trying to resubmit a read. usb_serial_generic_submit_read_urb - usb_submit_urb failed: -19 Add -ENODEV as one of the permanent errors along with -EPERM that usb_serial_generic_submit_read_urb() handles quietly without an error. Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com> Signed-off-by: Johan Hovold <johan@kernel.org>
* usb: serial: silence all non-critical read errorsJeremiah Mahler2015-01-121-1/+1
| | | | | | | | | | | | | | | | If a USB serial device is unplugged while there is an active program using the device it may spam the logs with -EPROTO (71) messages as it attempts to retry. Most serial usb drivers (metro-usb, pl2303, mos7840, ...) only output these messages for debugging. The generic driver treats these as errors. Change the default output for the generic serial driver from error to debug to silence these non-critical errors. Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com> Signed-off-by: Johan Hovold <johan@kernel.org>
* USB: serial: add missing bracesJohan Hovold2014-03-121-5/+6
| | | | | | | | Add missing braces to conditional branches and one loop in usb-serial core and generic implementation. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
* USB: serial: continue to write on errorsJohan Hovold2014-03-121-10/+19
| | | | | | | | | | | | | Do not discard buffered data and make sure to try to resubmit the write urbs on errors. Currently a recoverable error would lead to more data than necessary being dropped. Also upgrade error messages from debug to error log level. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
* USB: serial: continue to read on errorsJohan Hovold2014-03-121-4/+17
| | | | | | | | | | | | | Make sure to try to resubmit the read urb on errors. Currently a recoverable error would lead to reduced throughput as only one urb will be used until the port is closed and reopened (or resumed or unthrottled). Also upgrade error messages from debug to error log level. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
* USB: serial: fix write memory-allocation flagJohan Hovold2013-11-251-1/+1
| | | | | | | | | | | | Fix regression introduced by commit 818f60365a29 ("USB: serial: add memory flags to usb_serial_generic_write_start"), which incorrectly used GFP_KERNEL in write(), which must not not sleep. Reported-by: Dave Jones <davej@fedoraproject.org> Tested-by: Dave Jones <davej@fedoraproject.org> Cc: Dave Jones <davej@fedoraproject.org> Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: fix race in generic writeJohan Hovold2013-11-251-9/+1
| | | | | | | | | | | | | | | | | | | Fix race in generic write implementation, which could lead to temporarily degraded throughput. The current generic write implementation introduced by commit 27c7acf22047 ("USB: serial: reimplement generic fifo-based writes") has always had this bug, although it's fairly hard to trigger and the consequences are not likely to be noticed. Specifically, a write() on one CPU while the completion handler is running on another could result in only one of the two write urbs being utilised to empty the remainder of the write fifo (unless there is a second write() that doesn't race during that time). Cc: stable <stable@vger.kernel.org> # 2.6.35 Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: export usb_serial_generic_write_startJohan Hovold2013-10-111-1/+2
| | | | | | | | | Export usb_serial_generic_write_start which is needed when implementing a custom resume function while still relying on the generic write implementation. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: add memory flags to usb_serial_generic_write_startJohan Hovold2013-10-111-8/+10
| | | | | | | | | | | | | Add memory-flags parameter to usb_serial_generic_write_start which is called from write, resume and completion handler, all with different allocation requirements. Note that by using the memory flag to determine when called from the completion handler, everything will work as before even if the completion handler is run with interrupts enabled (as suggested). Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: clean up comments in generic driverJohan Hovold2013-10-111-32/+25
| | | | | | | Clean up some comments, drop excessive comments and fix-up style. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: invoke dcd_change ldisc's handler.Paul Chavent2013-09-261-0/+10
| | | | | | | | | | | | | The DCD pin of the serial port can receive a PPS signal. By calling the port line discipline dcd handle, this patch allow to monitor PPS through USB serial devices. However the performance aren't as good as the uart drivers, so document this point too. Signed-off-by: Paul Chavent <paul.chavent@onera.fr> Acked-by: Rodolfo Giometti <giometti@enneenne.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: remove hupping check from tiocmiwaitJohan Hovold2013-07-231-11/+2
| | | | | | | | | Since commit 31ca020b ("TTY: wake up processes last at hangup") there no longer any need to check the hupping flag in the generic tiocmiwait implementation, so remove it. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: add generic wait_until_sent implementationJohan Hovold2013-05-161-0/+31
| | | | | | | | | | | Add generic wait_until_sent implementation which polls for empty hardware buffers using the new port-operation tx_empty. The generic implementation will be used for all sub-drivers that implement tx_empty but does not define wait_until_sent. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: update copyright informationJohan Hovold2013-03-251-1/+1
| | | | | | | Update copyright information. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: add generic get_icount implementationJohan Hovold2013-03-251-0/+27
| | | | | | | | Add generic get_icount implementation that subdrivers relying on the port interrupt counters can use. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: add generic TIOCMIWAIT implementationJohan Hovold2013-03-251-0/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | Add generic TIOCMIWAIT implementation which correctly handles hangup, USB-device disconnect, does not rely on the deprecated sleep_on functions and hence does not suffer from the races currently affecting several usb-serial drivers. This makes it much easier to add TIOCMIWAIT support to subdrivers as the tricky details related to hangup and disconnect (e.g. atomicity, that the private port data may have been freed when woken up, and waking up processes at disconnect) have been handled once and for all. To add support to a subdriver, simply set the tiocmiwait-port-operation field, update the port icount fields and wake up any process sleeping on the tty-port modem-status-change wait queue on changes. Note that the tty-port initialised flag can be used to detect disconnected as the port will be hung up as part of disconnect (and cannot be reactivated due to the disconnected flag). However, as the tty-port implementation currently wakes up processes before calling port shutdown, the tty-hupping flag must also be checked to detect hangup for now. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: remove generic release callbackJohan Hovold2013-03-251-5/+0
| | | | | | | | Remove empty generic release implementation and make the release callback non-mandatory (like attach, probe and disconnect). Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: remove generic disconnect callbackJohan Hovold2013-03-251-6/+0
| | | | | | | | Remove the now empty generic disconnect callback and make the disconnect callback non-mandatory. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: fix generic disconnect implementationJohan Hovold2013-03-251-11/+1
| | | | | | | | | There is no need for the generic disconnect callback to stop the read and write urbs a second time as this has already been taken care of by close (which is called from hangup as part of disconnect). Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: remove bogus disconnect test in cleanupJohan Hovold2013-03-251-14/+10
| | | | | | | | | | | Remove bogus (and unnecessary) test for serial->dev being NULL in cleanup. The device is never cleared, and cleanup is never called after a completed disconnect anyway. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: remove port number from generic-driver debugJohan Hovold2013-03-251-6/+4
| | | | | | | | Remove redundant port number from debug output (already printed as part of device name). Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* TTY: switch tty_flip_buffer_pushJiri Slaby2013-01-151-7/+1
| | | | | | | | | | | | | | | | | | | | Now, we start converting tty buffer functions to actually use tty_port. This will allow us to get rid of the need of tty in many call sites. Only tty_port will needed and hence no more tty_port_tty_get in those paths. Now, the one where most of tty_port_tty_get gets removed: tty_flip_buffer_push. IOW we also closed all the races in drivers not using tty_port_tty_get at all yet. Also we move tty_flip_buffer_push declaration from include/linux/tty.h to include/linux/tty_flip.h to all others while we are changing it anyway. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* TTY: switch tty_insert_flip_stringJiri Slaby2013-01-151-1/+1
| | | | | | | | | | | | Now, we start converting tty buffer functions to actually use tty_port. This will allow us to get rid of the need of tty in many call sites. Only tty_port will needed and hence no more tty_port_tty_get in those paths. tty_insert_flip_string this time. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* TTY: switch tty_insert_flip_charJiri Slaby2013-01-151-1/+1
| | | | | | | | | | | | | Now, we start converting tty buffer functions to actually use tty_port. This will allow us to get rid of the need of tty in many call sites. Only tty_port will needed and hence no more tty_port_tty_get in those paths. tty_insert_flip_char is the next one to proceed. This one is used all over the code, so the patch is huge. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: export usb_serial_generic_chars_in_bufferJohan Hovold2012-10-301-0/+1
| | | | | | | | Export generic chars_in_buffer implementation so it can be used in subdrivers in combination with checks of any hardware buffers. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: Serial: usb-serial: remove debug module parameterGreg Kroah-Hartman2012-09-181-4/+1
| | | | | | | | | Now that all usb-serial modules are only using dev_dbg() the debug module parameter does not do anything at all, so remove it to reduce any confusion if someone were to try to use it. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial: remove debug parameter from usb_serial_debug_data()Greg Kroah-Hartman2012-09-181-4/+2
| | | | | | | | We should use dev_dbg() for usb_serial_debug_data() like all of the rest of the usb-serial drivers use, so remove the debug parameter as it's not needed. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: serial-generic: use a single set of device IDsAlan Stern2012-06-131-8/+2
| | | | | | | | | | | | | | | | The usb-serial-generic driver uses different device IDs for its USB matching and its serial matching. This can lead to problems: The driver can end up getting bound to a USB interface without being allowed to bind to the corresponding serial port. This patch (as1557) fixes the problem by using the same device ID table (the one that can be altered by the "vendor=" and "product=" module parameters) for both purposes. The unused table is removed. Now the driver will bind only to the intended devices. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> CC: Bjørn Mork <bjorn@mork.no> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* USB: generic.c: remove dbg() usageGreg Kroah-Hartman2012-05-151-8/+13
| | | | | | | | dbg() is a usb-serial specific macro. This patch converts the generic.c driver to use dev_dbg() instead to tie into the dynamic debug infrastructure. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>