Uhci Transaction Trouble

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Uhci Transaction Trouble

Post by MollenOS »

Hi,

I am having trouble getting transactions to send in UHCI, though everything is not out of place.

My procedure is like this:

First, I disable EHCI and route all actions to companion controllers,
I then enumerate all UHCI controllers, and each time I find one I do the following:

1. Write 0xF800 to PCI LEGSUB
2. Do a HCRESET and wait for it to complete
3. 0 interrupt & command registers
4. Setup frame list base address register
5. 0 frame number register
6. set SOFMOD to 64
7. Enable PCI interrupts by writing 0x2000 to LEGSUB
8. Start controller & set the FGR bit
9. wait 20 ms
10. Deassert FGR bit but keep it in running state
11. Wait 50 ms for everything to stabilize
12. Enumerate ports, and for each port I find, I reset it and configure it

Now, It seems like the UHCI controller starts correctly, the resulting command state is 0xC1 which means it is running and configured.
I then enumerate ports, I reset the port, and the state switches from 0x9B to 0x95 which is great, I then proceed to build a SetAddress transaction to the newly resetted port, but here it goes wrong, it fails on the setup TD.

Setup TD Result:
Initial State - After Transaction
Control&Status 0x800000 0x850007 (CRC/Timeout???)
Packet Header 0xe0002d 0xe0002d

Buffer and link pointer is set appropriately to their physical addresses with "Depth" first to the link.

What could possibly be wrong? And just to clarify, I should not reset ALL ports and then try to set them up, but rather reset ONE and then set it up, and then reset another one and set that up?


Thank you in advance!
pikasoo
Member
Member
Posts: 30
Joined: Sun Sep 02, 2012 11:04 am
Contact:

Re: Uhci Transaction Trouble

Post by pikasoo »

Im not sure i can help you much on this, i went trought the same path on my end and the nightmare is not completly done...

as far as i can help you with the information you gave, you have to set up the device one by one, make sure all the other plugged device that are unconfigured yet have theire port disabled. a freshly reseted device has the ID 0 and you use the setup command to assign them an ID. for the CRC error, make sure that you start the bit crc(Toggle) of the TD at 0 for every new control ED.

also you said you disabled the the EHCI controler if you can disable it from the bios or on an emulator just dont enable it yet. some conputer here gave me problems with the EHCI. even disabled, any usb2 device stop working after a few TD.

hope you get it working!
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Uhci Transaction Trouble

Post by MollenOS »

First of all, thank you so much for answering, its always nice to get some input.

Next, I do 0 out the port registers to make sure they are disabled, and then set them up one by one, so unfortunately this is not the issue.
I also make sure that the data-toggle starts at 0 for the setup td, and it never progresses beyond the Setup TD, so I'm really pulling out hair at my end.
My reset procedure is like this: (After UHCI setup is done, I enumerate the ports and do this for each port that has bit 0 set)

1. Write 0x200 (Reset, bit 9) to the port register
2. Sleep 50 ms
3. Write 0 to the port register to deassert the reset-signal
4. Sleep 4 ms
5. Enable the port by writing 0xE to the port register (Enable bit, clear event bits)
6. Wait for enable bit to set, and after this the port status is now 0x95 (which by inspecting the bits is perfectly fine)

I then proceed to create a SetAddress transaction which then fails on the setup Td, it seriously boggles me :/
pikasoo
Member
Member
Posts: 30
Joined: Sun Sep 02, 2012 11:04 am
Contact:

Re: Uhci Transaction Trouble

Post by pikasoo »

in your reset steps, i have a few diference, it's valid only if you are testing on a real hardware but here what i do on my end:

after a connection status change is reported,
1- i whait 100ms beafor doing the reset, according to the docs some device might take a few ms to power up proprely.
2 - write 0x202 to the port control reg, the 0x2 is to clear the connection change status
3 - whait 50 ms for the reset to be done and write 0x0, docs suggest 20ms but just to be sure i added a few more.
4 - whait an other 50 - 100ms for the device to completly recover from the reset, some device will take longer than other

those step work fine on my end, tested on bochs and on 4 computer. i succefully got a mouse and kb working on those.

if its not helping the result then the bug is in the ED/TD headers
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Uhci Transaction Trouble

Post by MollenOS »

I am testing on real hardware, I'm gonna try your procedure for resetting, though they vary just a little.
My UHCI driver works fine in bochs (stupid bochs, stuff is always so easy to get working there)

I am though beginning to suspect that its because the port has been disabled by the controller (Initial state was 0x9B, the enabled event is set), and thus might be why the device fails?
pikasoo
Member
Member
Posts: 30
Joined: Sun Sep 02, 2012 11:04 am
Contact:

Re: Uhci Transaction Trouble

Post by pikasoo »

I am though beginning to suspect that its because the port has been disabled by the controller (Initial state was 0x9B, the enabled event is set), and thus might be why the device fails?
actualy after a succeful reset of the HC, the ports will be disabled and the device change event will be set if a device is connected. the enable event might have been set beacause the bios previously configured the HC. in the emulator, bochs and virtualbox, theire bios doesnt claim the ownership of the usb HC mabe this is why your code is failling on a real computer. Make sure you disabled the fallowing beafor the HC reset:

PIRQ
SMI
R/WC

basicly write 0 to the USBCMD register and USBINTR
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Uhci Transaction Trouble

Post by MollenOS »

Before the HCReset? I 0 registers (USBCMD and USBINTR) and port registers just after the HCReset, not before, and yes, before resetting the controller i write 0xF800 to the pci 0xC0 register to disable interrupts, so this should not be the problem i think?

Trying your form of port reset unfortunately did not change anything, and I have triple-checked my TD/QH setup, and I'm 130% sure that is not the problem
pikasoo
Member
Member
Posts: 30
Joined: Sun Sep 02, 2012 11:04 am
Contact:

Re: Uhci Transaction Trouble

Post by pikasoo »

here is the part of my reset for the HC

i write 0 to the USBCMD and USBINTR reg
then i write to the pci space 0xc0 the value 0x8f00
then i send the USBCMD_HCRESET to the HC
finaly i write 0 to the USBCMD and USBINTR again

i dont remember why i do it beafor and after, i wrote my uhci driver a year ago, but just like you i ended up debuging on a real pc what used to be perfect on bochs...
Post Reply