Commit graph

35 commits

Author SHA1 Message Date
cinap_lenrek 990ceeef3b nusb/usbd: retry opendevtata() a few times on attach (work around mnt-reform trackball)
this is a known and already fixed issue with version the following version
of the mnt-reform trackball firmware:

55ca5bf848
2022-06-18 23:37:12 +00:00
cinap_lenrek 065d601916 nusb: Fix handling of interface altsetting.
The altsetting was handled only for a single endpoint
(per interface number), but has to be handled for each
endpoint (per interface *AND* altsetting number).

A multi function device (like a disk) can have
multiple interfaces, all with the same interface number
but varying altsetting numbers and each of these
interfaces would list distict endpoint configurations.

Multiple interfaces can even share some endpoints (they
use the same endpoint addresses), but
we still have to duplicate them for each
interface+altsetting number (as they'r part of
actually distict interfaces with distict endpoint
configurations).

It is also important to *NOT* make endpoints bi-directional
(dir == Eboth) when only one direction is used in a
interface/altsetting and the other direction in another.
This was the case for nusb/disk with some seagate drive
where endpoints where shared between the UAS and
usb storage class interface (but with distict altsettings).

The duplicate endpoints (as in using the same endpoint address)
are chained together by a next pointer and the head
is stored in Usbdev.ep[addr], where addr is the endpoint
address. These Ep structures will have distinct endpoint
numbers Ep.id (when they have conflicting types), but all
will share the endpoint address (lower 4 bits of the
endpoint number).

The consequence is that all of the endpoints configuration
(attributes, interval) is now stored in the Ep struct and
no more Altc struct is present.

A pointer to the Ep struct has to be passed to openep()
for it to configure the endpoint.

For the Iface struct, we will now create multiple of them:
one for each interface *AND* altsetting nunber,
chained together on a next pointer and the head being
stored in conf->iface[ifaceid].

--
cinap
2022-02-21 19:50:16 +00:00
cinap_lenrek 4ab2d149d4 nusb/usbd: use per hname collision counter instead of device address to resolve collisions
The device address is highly variable and depends on
all prior enumerated devices.

This can happen with some devices that do not have
a serial number and all devices of the same type
having the same hname.

Using a counter of collisions per hname makes more sense
and is more stable (given that the order devices are
enumerated is deterministic).
2022-02-06 01:19:01 +00:00
cinap_lenrek ecba7822e3 nusb/usbd: fix portreset error handling
error handling in portreset() was wrong. we called closedev()
on the device without changing the reference.

just call portdetach() when the reset fails.
2020-04-05 03:05:06 +02:00
cinap_lenrek fe39388250 nusb/usbd: cleanup processes on unmount
this makes sure that when postsharesrv() fails (for
example because the shr file already exists), the
worker process gets killed and all file descriptors
to devusb get closed.
2020-03-08 16:06:37 +01:00
cinap_lenrek efd64da989 nusb/usbd: fix /env/usbbusy bug
run the usb hub poll "work()" proc in the same filedescriptor
group as the fileserver by forking the process in Srv.start
callback.

this also prevents the usbbusy filedescriptor from being kept
open by the fileserver process.
2020-03-07 22:26:49 +01:00
mischief 83ab780783 nusb/usbd: stop sending port enable commands
from what i can tell, sending port enable is a spec violation.

this fixes a hang during hub enumeration in the ASMedia
xhci controller when i plug in my IBM UltraNav SK-8845.

also, send unsuspend when port is suspended instead of enable.

from the USB 2 specification:

11.24.2.7.1.2 PORT_ENABLE
...
This bit may be set only as a result of a SetPortFeature(PORT_ENABLE).
...
The hub response to a SetPortFeature(PORT_ENABLE) request is not specified.
2019-04-18 02:48:35 -07:00
mischief 07674f6e8d nusb/usbd: fix dump %U formatter 2019-04-13 22:37:52 -07:00
cinap_lenrek dc8432d459 nusb/usbd: increase buffer size to capture port information
due to the addition of uframes property, the buffer got truncated
resulting in usbd not recognizing the number of roothub ports.
2018-04-08 20:51:48 +02:00
cinap_lenrek a2e8246ffc nusb: add missing header dependencies to mkfiles 2018-02-18 02:06:55 +01:00
cinap_lenrek 56ac6ea29e nusb/*: cleanup 2017-07-31 15:29:08 +02:00
cinap_lenrek b1d4e86064 nusb/usbd: support for usb3 hubs 2017-07-31 14:38:39 +02:00
cinap_lenrek 215b67ff3d nusb/usbd: create endpoint files for conf #1, usb3 preparation 2017-07-31 03:19:24 +02:00
cinap_lenrek 7e3b2cdb55 usbd: intoruce /env/usbbusy
to solve the usb device enumeration race on boot, usbd creates /env/usbbusy
on startup and once all devices have been enumerated and readers have consumed
all the events, we remove the file so nusbrc/bootrc can continue. this makes
sure all the usb devices that where plugged in on boot are made available.
2015-11-22 03:17:15 +01:00
cinap_lenrek 76ee4c3988 usbd: set device info for control file (see usb(3), thanks qeed) 2015-05-18 01:26:29 +02:00
cinap_lenrek eec5799f4c nusb/usbd: fix typo in debug prints, dont use %U format as its not installed 2015-02-17 22:17:30 +01:00
cinap_lenrek 4ad63a4c56 nusb: fix spelling, sorry 2014-06-28 19:55:14 +02:00
cinap_lenrek 4275c49e72 nusb: implement aijus stable uniqueue device names
instead of naming devices by ther dynamically assigned device address,
we hash device uniqueue fields from the device descriptor and produce
a 5 digit hex string that will identify the device across machines.

when there is a collision (less than 1% chance with 100 devices),
usbd will append the device address to the name to make it uniqueue
for this machine.

the hname is passed to drivers in the devid argument, which now has
the form addr:hname, where the colon and hname can be omited (for backwards
compatibility).

when the new behaviour isnt desired, nousbhname= environment variable
can be defined giving the old behaviour.
2014-06-28 18:09:43 +02:00
cinap_lenrek 93d0474f77 nusb/usbd: cleanup 2014-06-03 21:40:30 +02:00
cinap_lenrek 5ab9f9c621 nusb/usbd: serialize /dev/usbevent processing
when there are multiple readers of /dev/usbevent, we have to
serialize the processing to make sure that only one driver
is opening the devices control endpoint at a time.

to do this, we assume the device is busy after reading the
event file until the next read or clunk on the same fid.

to mark a device busy, we set the dev->aux pointer to the
fid processing a event. And the Event structure takes a
reference to the device producing the event.

the problem arised from cdc ethernet and nusb/serial sharing
the same device class, and we need to run the particular driver
to figure out if the device can be used. doing this concurrently
fails because devusb allows only one open per endpoint.
2014-06-03 07:21:48 +02:00
cinap_lenrek 3cdaf6ea5f usbd: add missing quotefmtinstall 2012-09-06 04:07:51 +02:00
cinap_lenrek 93063b3db0 nusbd: properly handle port detach on hub disconnect 2012-09-05 00:06:20 +02:00
cinap_lenrek 9b0fc40aee nusbd: properly terminate worker proc if no hubs can be found 2012-03-09 07:55:01 +01:00
cinap_lenrek 424f8a9520 nusb: debug flags 2012-03-01 18:56:54 +01:00
cinap_lenrek d1b98305de nusb: fix enumarate bug, rename startdev/rmdev 2011-07-31 10:46:03 +02:00
aiju 2ba1b4c476 changed dev/rmdev to attach/detach, fixed nusbrc 2011-07-30 16:28:45 +02:00
aiju 6aed9711b4 devshr: changed #σc to contain directories
nusb: detaching
2011-07-30 14:30:27 +02:00
cinap_lenrek f9846213d1 nusb: change usbevent format, put nusbrc in bootfs 2011-07-30 07:23:26 +02:00
cinap_lenrek 9d49fcdb37 nusb: handle sub hubs 1970-01-01 01:34:55 +01:00
aiju 7f27b397ca nusb: more locking, also close dfd 2011-07-29 16:24:52 +02:00
aiju 61d322679b minor polishing of usbd 2011-07-29 10:24:18 +02:00
aiju 6f824732a6 usbd: improved event file 2011-07-28 21:26:42 +02:00
aiju 4792c6bef9 usbd: added event file, removed usbdb 2011-07-28 17:31:45 +02:00
aiju 05d09f086f nusb: improved 2011-07-27 20:07:30 +02:00
aiju 1a2afe988b started work on new usbd 2011-07-27 14:27:22 +02:00