summaryrefslogtreecommitdiff
path: root/sys/dev/usb/ucom.c
AgeCommit message (Collapse)Author
2023-03-05ucom(4): Simplify logic fixing PR kern/57259.riastradh
cv_timedwait only ever returns 0 or EWOULDBLOCK, so this would always return ERESTART anyway. No functional change intended.
2023-03-05In the HUP-wait path in ucomopen():thorpej
- Use cv_timedwait() rather than cv_timedwait_sig(); the wait here is bounded (and fairly short besides) and seems appropriate to treat like other uninterruptible waits. The behavior is now consistent with com(4) in this regard. - Map EWOULDBLOCK return from cv_timedwait() to 0, as the successful passage of time is not an error in this case. - If the HUP-wait time has passed, clear the HUP-wait timestamp. kern/57259 (although insufficient -- another change to vfs_syscalls.c is required)
2023-02-17ucom(4): Missed a spot in previous -- nix now-unused local.riastradh
2023-02-17ucom(4): Nix broken error branch.riastradh
This error branch was introduced to make the system act, when a USB serial adapter is yanked, as if the other end had spat out a line feed in an attempt to wake any sleeping readers so they will stop using the USB serial port. This is no longer necessary, because ttycancel will wake them anyway, and it is actually harmful because it puts stuff in the output queue (CR LF) that will never be processed, causing subsequent users to hang trying to open the device. Problem found and patch tested by tih@.
2022-10-26ucom(4): Convert to ttylock/ttyunlock.riastradh
2022-04-17ucom(4): Make sure rndsource is attached before use and detach.riastradh
Reported-by: syzbot+04fb6786e0cf873905e8@syzkaller.appspotmail.com
2022-04-07ucom(4): Use tty_unit -- save a couple lines of code.riastradh
2022-04-07ucom(4): Fix unit numbering for devsw/autoconf cross-wiring.riastradh
Should introduce a tty_unit function to use here but this'll do for now to fix the bug I introduced in ucom(4).
2022-03-28ucom(4): Rework open/close/attach/detach logic.riastradh
- Defer sleep after hangup until open. No need to make close hang; we just need to make sure some time has passed before we next try to open. This changes the wchan for the sleep. Oh well. - Use .d_cfdriver/devtounit/cancel to resolve races between attach, detach, open, close, and revoke. - Use a separate .sc_closing flag instead of a UCOM_CLOSING state. ucomcancel/ucomclose owns this flag, and it may be set in any state (except UCOM_DEAD). UCOM_OPENING remains owned by ucomopen, which might be interrupted by cancel/close. - Rework error branches in ucomopen. Much simpler this way. - Nix unnecessary reference counting.
2021-06-24ucom(4): Fix earlier mistake causing pipes not to be closed.riastradh
In revision 1.123, mrg@ changed what he thought was a double-close, but was actually abort&close (as is appropriate) to just abort (which is not enough -- leaks the pipe). This restores the abort&close. The original `bug' was found by code inspection, whereas this bug was found by asserting in usb_subr.c that no pipes are open on device disconnection after detach; the asserts actually triggered with several ucom(4) devices, and no longer trigger with this change. XXX pullup-9
2020-10-26properly wait for refcounts to drain.mrg
fixes panic at detach that jmnceill saw. XXX: pullup-[89].
2020-03-14revert the 0x% -> %# change for fixed width formats pointed out by uwe.christos
2020-03-13PR/55068: sc.dying: Fix printf formats:christos
- no %s/%p for kernel log - 0x% -> %# - always %j for kernel log
2019-05-09clean up ucom parents some more:mrg
- it's always "bool sc_dying" now, with true/false - heavy use of static functions - remove all ucom parent ca_activate callbacks. they're never called. - callbacks should generally do little to nothing if sc_dying is set - open resources should be released in detach after setting sc_dying - don't complain about usbd_abort_pipe() or usbd_close_pipe() failure - when releasing resources, zero the softc member as well - remove ucom_methods members no longer destined to be filled in - generally, DPRINTF() before sc_dying short circuit - use EIO when dying, not ENXIO or 0 - add some ucom_open() callbacks that simply return EIO if dying
2019-05-05remove explicit 'extern struct cfdriver <my>_cd;' and use ioconf.hmrg
2019-05-01fix a locking botch in ucomhwiflow():mrg
tty.c always calls t_hwiflow() with tty_lock held, and the caller of this for ucom always holds sc->sc_lock when calling down into the tty layer. don't try to re-take the sc_lock in ucomhwiflow() (locking against myself is triggered here currently), but instead assert that the lock is already held _and_ that tty_lock is held. in ucom_detach(), when closing pipes set sc_bulkin_pipe and sc_bulkout_pipe to NULL. fixes bug noticed by code inspection: a failed detach would attempt to close them a second time.
2019-04-20fix umodem(4) detach:mrg
- ucom(4) needs kpreempt disabled around softint_schedule() - switch a copied printf() to aprint_error_dev() - use static normally in umodem_common.c - remove unused sc_openings in softc, convert sc_dying to real bool - add sc_refcnt, sc_lock and sc_detach_cv to softc. usage is: - sc_dying is protected by sc_lock - sc_detach_cv is matched with sc_lock for cv operations - sc_refcnt is increased in open and decreased in close, any time it is decreased, it is checked for less than zero, and a broadcast performed on sc_detach_cv. detach waits for sc_refcnt. - umodem_param() and umodem_set() check for sc_dying this fixes pullout out an open ucom@umodem. @skrll. XXX: pullup
2018-12-11restore error reporting in ucomparam() lost in 1.115jakllsch
2018-01-21PR kern/52931 Kernel panics with Atheros usb wireless interfaceskrll
Audit the flags to usbd_create_xfer so that USBD_FORCE_SHORT_XFER is supplied wherever such a transfer is setup. We can drop USBD_SHORT_XFER_OK as it has not bearing on number of TDs
2017-10-28Update the kernhist(9) kernel history code to address issues identifiedpgoyette
in PR kern/52639, as well as some general cleaning-up... (As proposed on tech-kern@ with additional changes and enhancements.) Details of changes: * All history arguments are now stored as uintmax_t values[1], both in the kernel and in the structures used for exporting the history data to userland via sysctl(9). This avoids problems on some architectures where passing a 64-bit (or larger) value to printf(3) can cause it to process the value as multiple arguments. (This can be particularly problematic when printf()'s format string is not a literal, since in that case the compiler cannot know how large each argument should be.) * Update the data structures used for exporting kernel history data to include a version number as well as the length of history arguments. * All [2] existing users of kernhist(9) have had their format strings updated. Each format specifier now includes an explicit length modifier 'j' to refer to numeric values of the size of uintmax_t. * All [2] existing users of kernhist(9) have had their format strings updated to replace uses of "%p" with "%#jx", and the pointer arguments are now cast to (uintptr_t) before being subsequently cast to (uintmax_t). This is needed to avoid compiler warnings about casting "pointer to integer of a different size." * All [2] existing users of kernhist(9) have had instances of "%s" or "%c" format strings replaced with numeric formats; several instances of mis-match between format string and argument list have been fixed. * vmstat(1) has been modified to handle the new size of arguments in the history data as exported by sysctl(9). * vmstat(1) now provides a warning message if the history requested with the -u option does not exist (previously, this condition was silently ignored, with only a single blank line being printed). * vmstat(1) now checks the version and argument length included in the data exported via sysctl(9) and exits if they do not match the values with which vmstat was built. * The kernhist(9) man-page has been updated to note the additional requirements imposed on the format strings, along with several other minor changes and enhancements. [1] It would have been possible to use an explicit length (for example, uint64_t) for the history arguments. But that would require another "rototill" of all the users in the future when we add support for an architecture that supports a larger size. Also, the printf(3) format specifiers for explicitly-sized values, such as "%"PRIu64, are much more verbose (and less aesthetically appealing, IMHO) than simply using "%ju". [2] I've tried very hard to find "all [the] existing users of kernhist(9)" but it is possible that I've missed some of them. I would be glad to update any stragglers that anyone identifies.
2016-12-14Don't hold softc lock when calling ucom_readskrll
PR/51714: uftdi (on xhci): mutex_vector_enter: locking against myself
2016-12-04Whitespaceskrll
2016-11-29Ensure the softc lock is not held in ucom_shutdown as the call to ucom_dtrskrll
can sleep.
2016-11-19Pull across various locking and reference counting fixes from nick-nhusb.skrll
2016-10-03Do not hold the softc lock (IPL_SOFTUSB) unnecessarily and specificallyskrll
across ucomparam (and the ucom_param method). The method can sleep wait- ing for transfers... any input/output will try to acquire the lock and get stuck
2016-05-14All com devices have an issue that they sleep in the final closemlelstv
when they signal a hangup while still using the device. This allows a concurrent open to succeed without proper locking because it only checks the state of the tty layer. This issue triggers an assertion in ucom due to a reused USB xfer, but it can also cause misbehaviour in other com devices. For now in ucom: - make open block while close is in progress - also serialize close operations
2016-05-10Fixup ucom_cleanup to not forget our pipe handles.skrll
Simplify ucomreadcb by dealing with the USBD_CANCELLED separately and not taking sc_lock. We can't hold sc_lock while aborting now.
2016-04-23Merge nick-nhusbskrll
- API / infrastructure changes to support memory management changes. - Memory management improvements and bug fixes. - HCDs should now be MP safe - conversion to KERNHIST based debug - FS/LS isoc support on ehci(4). - conversion to kmem(9) - Some USB 3 support - mostly from Takahiro HAYASHI (t-hash). - interrupt transfers now get proper DMA operations - general bug fixes - kern/48308 - uhub status notification improvements - umass(4) probe fix (applied to HEAD already) - ohci(4) short transfer fix
2015-11-08Add the port number to the device properties to make it easier to relatejoerg
a specific ucom instance with the physical port of multi-port devices like the FTDI 4232.
2015-04-13Convert sys/dev to use <sys/rndsource.h>.riastradh
2014-11-15centralize the dialout/call unit macros.christos
2014-08-10Merge tls-earlyentropy branch into HEAD.tls
2014-07-25Add PPS support to ucom(4).gdt
This is basically cribbed from regular serial ports, and just adds hooks to call the pps support routines. Also, note in the ucom(4) man page that there is about 1 ms of latency. Discussed on tech-kern in October of 2013, with the only concern being that someone who didn't know what they were doing might set up a stratum 1 server, and that somehow might have worse timekeeping than whatever else that person might have done; the man page comment is a mitigation for this. This patch has been live-tested in netbsd-5/i386 and netbsd-6/i386, and has been running on machines without a USB-serial GPS device for most of a year with no adverse consequences (very little happens if the PPS ioctls are not invoked).
2014-07-25Add d_discard to all struct cdevsw instances I could find.dholland
All have been set to "nodiscard"; some should get a real implementation.
2014-05-04remove hack for PR/42848christos
2014-03-16Change (mostly mechanically) every cdevsw/bdevsw I can find to usedholland
designated initializers. I have not built every extant kernel so I have probably broken at least one build; however I've also found and fixed some wrong cdevsw/bdevsw entries so even if so I think we come out ahead.
2012-12-15drop trailing whitespace.jakllsch
2012-12-15Sometimes the device disappears out from under us and device_lookup_private()jakllsch
will return NULL. Be paranoid about this to prevent NULL pointer dereferences.
2012-10-17Don't rely on TS_BUSY to determine wether there is a buffermlelstv
available. Instead handle a possible buffer shortage. Also aquire lock when modifying t_state.
2012-03-06pull down from usbmp branch:mrg
- rename usb_detach_{wake,waitup}() to usb_detach_{wake,waitup}old() - use some c99 struct .initialisers
2012-02-24remove any remnants of freebsd/openbsd code.mrg
2012-02-02Entropy-pool implementation move and cleanup.tls
1) Move core entropy-pool code and source/sink/sample management code to sys/kern from sys/dev. 2) Remove use of NRND as test for presence of entropy-pool code throughout source tree. 3) Remove use of RND_ENABLED in device drivers as microoptimization to avoid expensive operations on disabled entropy sources; make the rnd_add calls do this directly so all callers benefit. 4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might have lead to slight entropy overestimation for some sources. 5) Add new source types for environmental sensors, power sensors, VM system events, and skew between clocks, with a sample implementation for each. ok releng to go in before the branch due to the difficulty of later pullup (widespread #ifdef removal and moved files). Tested with release builds on amd64 and evbarm and live testing on amd64.
2012-01-14Stopgap XXX kludge for PR kern/42848 and PR kern/45013.jakllsch
Someone should really find and fix the real problem, but it's better to not crash in the meantime.
2012-01-14Don't notify about zero length reads without UCOM_DEBUG && ucomdebug > 0.jakllsch
It's typical for uslsa(4) hardware to do this occasionally.
2012-01-14In ucompoll() also bail out if we don't have a valid softc.jakllsch
Seems to prevent occasional crashes when a open ucom is removed.
2011-12-23Revert previous due to active usbmp branch(es).jakllsch
2011-12-22Adjust-away inconsistent and trailing whitespace.jakllsch
2011-12-19It's tp->t_dev, not tp->tp_dev. Corrects commit prior to previous.jakllsch
2011-12-19const-ify struct ucom_methods pointer within ucom(4).jakllsch
2011-12-19Make commented-out code in ucomstop() compilable.jakllsch