OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:27 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Sat Sep 03, 2022 4:57 am 
Offline

Joined: Thu Aug 25, 2022 7:28 am
Posts: 12
Hello!
I'm writing a xhci driver for my OS, all of the code runs well on QEMU.
But, when I run my OS on my computer, after the ENABLE_SLOT command sent, it looks like it is stuck.
I can ensure that the interrupt handler of XHCI can work normally, and I can receive the interrupt from the event ring when I reset the port. However, after the ENABLE SLOT command is issued, the handler does not run. Then the system looks jammed.


The code which related to the problem: Line 1326.
https://github.com/fslongjin/DragonOS/blob/357343b0d3b4817394f10ab79183aa3816058423/kernel/driver/usb/xhci/xhci.c#L1326

And, after I ring the doorbell at Line 1565, the problem come into being:
https://github.com/fslongjin/DragonOS/blob/357343b0d3b4817394f10ab79183aa3816058423/kernel/driver/usb/xhci/xhci.c#L1565

I have thought for a long time and still can't solve the problem. How can I solve this?


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Sat Sep 03, 2022 6:30 am 
Offline
Member
Member
User avatar

Joined: Fri Jun 11, 2021 6:02 am
Posts: 96
Location: Belgium
It's hard to tell what's wrong at a glance, but have you confirmed that the command ring works with No Op TRBs?

Also, it appears you're not assigning any scratchpad pages?

_________________
My OS is Norost B (website, Github, sourcehut)
My filesystem is NRFS (Github, sourcehut)


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Sat Sep 03, 2022 9:44 pm 
Offline

Joined: Thu Aug 25, 2022 7:28 am
Posts: 12
Demindiro wrote:
It's hard to tell what's wrong at a glance, but have you confirmed that the command ring works with No Op TRBs?

Also, it appears you're not assigning any scratchpad pages?


Yeah, the NOP trb can run properly after I ring the doorbell. And, is the scratchpad buffer necessary?


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Sat Sep 03, 2022 11:08 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 11, 2021 6:02 am
Posts: 96
Location: Belgium
longjin wrote:
And, is the scratchpad buffer necessary?


It absolutely is. Imagine what would happen to your program if it had no memory / something started randomly overwriting memory in it :)

Emulators such as QEMU do not need scratchpad buffers since they have access to malloc() which is faster & safer anyways.

_________________
My OS is Norost B (website, Github, sourcehut)
My filesystem is NRFS (Github, sourcehut)


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Sun Sep 04, 2022 12:06 am 
Offline

Joined: Thu Aug 25, 2022 7:28 am
Posts: 12
Demindiro wrote:

It absolutely is. Imagine what would happen to your program if it had no memory / something started randomly overwriting memory in it :)

Emulators such as QEMU do not need scratchpad buffers since they have access to malloc() which is faster & safer anyways.


I haven't thought about this before. The problem solved with your help, thank you!!! :D

May I ask you another question?

After I reset the port, and try to send ADDRESS_DEVICE again, something came wrong. I received an event TRB, which has completion code=17, trb type=33. It means a Parameter Error. (It can work on QEMU but the computer)
I only want to get the device descriptor, so I only set the slot_context and control EP context in the input_context. How can I solve this?
The code: https://github.com/fslongjin/DragonOS/blob/357343b0d3b4817394f10ab79183aa3816058423/kernel/driver/usb/xhci/xhci.c#L1379


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Sun Sep 04, 2022 12:15 am 
Offline
Member
Member
User avatar

Joined: Fri Jun 11, 2021 6:02 am
Posts: 96
Location: Belgium
longjin wrote:
I received an event TRB, which has completion code=17, trb type=33. It means a Parameter Error. (It can work on QEMU but the computer)


QEMU is quite lax and ignores many of the parameters it doesn't need (unlike real hardware).

Parameter Error means you didn't properly configure one or more fields in the Input Context. Looking at your code it appears you're not initializing a lot of fields, such as the maximum packet size. If you set the same fields as I do it should work fine (my code is GPLv3 but I give you permission to use it).

_________________
My OS is Norost B (website, Github, sourcehut)
My filesystem is NRFS (Github, sourcehut)


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Sun Sep 04, 2022 2:27 am 
Offline

Joined: Thu Aug 25, 2022 7:28 am
Posts: 12
Demindiro wrote:
Looking at your code it appears you're not initializing a lot of fields, such as the maximum packet size. If you set the same fields as I do it should work fine (my code is GPLv3 but I give you permission to use it).


Hmm, what I do is, copy the slot_context and ep_context from device_context of the port to the input context directly. I think this should contain all the information we need. The function works at the first time. But at the second time, it failed.


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Sun Sep 04, 2022 3:21 am 
Offline

Joined: Thu Aug 25, 2022 7:28 am
Posts: 12
And, I try to directly send the ADDRESS_DEVICE command with BSR=0 to the device (just comment out Line 1356~1375), and successfully got the descriptor.

So, why I cannot request the first 8 bytes and reset the device, then set address again, and request all 18 bytes?


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Mon Sep 05, 2022 2:43 pm 
Offline
Member
Member

Joined: Mon Dec 07, 2020 8:09 am
Posts: 212
longjin wrote:
Hmm, what I do is, copy the slot_context and ep_context from device_context of the port to the input context directly. I think this should contain all the information we need.


Unfortunately, the controller takes the same shortcut. It copies most fields from the input context as is to the output context,

longjin wrote:
So, why I cannot request the first 8 bytes and reset the device, then set address again, and request all 18 bytes?


I'm almost certain that you can. On the other hand, you could also send a evaluate context cmd instead of resetting the device.


Top
 Profile  
 
 Post subject: Re: xhci: OS crash after send ENABLE_SLOT command.
PostPosted: Tue Sep 06, 2022 12:14 am 
Offline

Joined: Thu Aug 25, 2022 7:28 am
Posts: 12
xeyes wrote:
I'm almost certain that you can. On the other hand, you could also send a evaluate context cmd instead of resetting the device.

Hmm, I'll try it. Thank u!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Kamal123 and 61 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group