Page 1 of 1

USB xHCI device connectivity

Posted: Mon Oct 17, 2022 8:26 pm
by Kamal123
Hi,
I have a working xHCI driver, it initialises ports, setup port related data structures and I can get usb descriptors. My confusion is in device connectivity, when a new device is connected, xHCI receive an PortStatusChange event from where I can get port number, from here how can I respond to the device? How device specific drivers are get loaded here?.... What are the steps ? How matured OS like linux handles device connectivity?..

Thanks,
Manas Kamal

Re: USB xHCI device connectivity

Posted: Tue Oct 18, 2022 10:35 am
by nullplan
Kamal123 wrote:My confusion is in device connectivity, when a new device is connected, xHCI receive an PortStatusChange event from where I can get port number, from here how can I respond to the device?
You do what you always do when a hub tells you there is something new. If the port tells you that there is now a device attached, you enumerate the device like normal. If it tells you there is now no device attached, you find all USB devices that used to be on that port and tell their drivers that the device was lost. How you do that specifically is up to you. Since each port connects to exactly one device directly, you can just send the event to the driver of that one device, and if it is a hub, it better have a list of its subordinate devices ready to tell those drivers that the device is gone now.
Kamal123 wrote:How device specific drivers are get loaded here?.... What are the steps ?
You enumerate the port? Like you do during boot? Only now you only enumerate the single port that talked to you, not all of them. And that means you enable a slot for the port, reset the device on there, set its address, then read out its descriptors. And then the USB class drivers must tell you if they want to deal with the device or not.

Re: USB xHCI device connectivity

Posted: Fri Oct 28, 2022 7:47 pm
by Kamal123
Hello, thanks for reply and heartily sorry for being late, I do enumeration of port during startup of the driver, after initialisation of command ring, event ring, interrupt setup and all necessary setup. Now I got the idea how actually device connectivity works. I create a kernel thread which is responsible for initialising device context , command ring for default endpoint and all other necessary setup, whenever a new device is plugged into a port, _port_change_status_ event causes interrupt which finally wakeups the USB thread and drops a _new_device_ message with correct TRB index, and USB thread finally processes the message by initialising the required setup..
By default,USB thread is blocked. Now I got device hot plug working :D

https://github.com/manaskamal/aurora-xe ... vers%2Fusb

Thank you,
Manas Kamal