OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:59 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [SOLVED] XHCI/USB disk doesn't respond to SCSI INQUIRY
PostPosted: Sun Mar 12, 2017 7:06 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 154
Hello

I have a USB 2.0 disk (MSD) connected to XHCI. I am able to detect the device connected and complete all standard USB device initialization steps up-to the point of ConfigureEndpoint + SetConfiguration + Reset USB MSD + Send 31 byte CBW with INQUIRY command

After sending 31 byte CBW SCSI INQUIRY command I get an IRQ indicating the completion of TD corresponding to CBW on bulk-out-endpoint
After this, I place an in/read TD for 36 bytes on bulk-in-endpoint but there is no IRQ !

Apart from going through XHCI intel documentation I also went through Benjamin David's book. I can't see anything being done incorrectly in my code/approach

Please note:-
1. The code to form SCSI commands is common irrespective of whether the underlying USB controller is XHCI or EHCI. It works fine with EHCI
2. The code works on QEMU with XHCI

I am not sure why there is no IRQ for 36 byte read TD while I do receive an IRQ for 32 byte CBW INQUIRY command

Appreciate some guidance...

Thanks
Prajwal

_________________
complexity is the core of simplicity


Last edited by prajwal on Thu Mar 23, 2017 8:32 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: XHCI/USB disk doesn't respond to SCSI INQUIRY
PostPosted: Mon Mar 13, 2017 11:24 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
prajwal wrote:
Hello

I have a USB 2.0 disk (MSD) connected to XHCI. I am able to detect the device connected and complete all standard USB device initialization steps up-to the point of ConfigureEndpoint + SetConfiguration + Reset USB MSD + Send 31 byte CBW with INQUIRY command

After sending 31 byte CBW SCSI INQUIRY command I get an IRQ indicating the completion of TD corresponding to CBW on bulk-out-endpoint
After this, I place an in/read TD for 36 bytes on bulk-in-endpoint but there is no IRQ !

Apart from going through XHCI intel documentation I also went through Benjamin David Lunt's book. I can't see anything being done incorrectly in my code/approach

Please note:-
1. The code to form SCSI commands is common irrespective of whether the underlying USB controller is XHCI or EHCI. It works fine with EHCI
2. The code works on QEMU with XHCI

I am not sure why there is no IRQ for 36 byte read TD while I do receive an IRQ for 32 byte CBW INQUIRY command

Appreciate some guidance...

Thanks
Prajwal
I am sure you meant 31 byte CBW in that last line.

Anyway, at the moment, I can't think of anything you may be doing wrong, especially since it works when plugged into a EHCI port.

However, this tells you that it most likely will be with your xHCI code.

A few notes to check:
1) make sure the command part of the CBW is big-endian.
2) are you receiving the data? Even though the IRQ didn't fire, does the memory contain 36-bytes of data?
3) I can't imagine a device checking for it, but make sure the TAG parameter is different than the last one.
4) try requesting only the first 8 bytes and see if you get a IRQ to fire (same for a larger value, say 128).
5) (obvious, but still worth mentioning) you acknowledged the last IRQ so that this one will fire, yes?

Without more details, I can't help much further. This is were a USB Protocol Analyzer comes in really handy. This lets you know what actually gets sent down the wire.

Anyway, do a few more checks. I know you will find it. I had a problem with something like this one time and couldn't ever figure it out. Finally I found it, it being something mostly unrelated to what I was working on. It happens. Check all code even remotely associated with it.

Ben


Top
 Profile  
 
 Post subject: Re: XHCI/USB disk doesn't respond to SCSI INQUIRY
PostPosted: Tue Mar 14, 2017 8:37 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
I assume the problem is on a physical machine, since you mentioned it working in QEMU. I have noticed a lot of issues plugging in USB 2.0 devices into USB 3.0 ports my work laptop. For instance, plugging in my iPhone causes it to constantly connect, disconnect, re-connect, disconnect every few seconds. If I disable the USB 3.0 host controller in Windows Device Manager, it works fine, even in the same USB port.

I did a little googling, and found quite a few people reporting issues using USB 2.0 devices on a USB 3.0 port. You may have stumbled upon a device that is somehow not forward compatible with 3.0 ports. I am curious what you find out in your troubleshooting. I don't have XHCI support in my OS yet, or else I would be right there with you trying to figure out what is happening with this laptop...

Good luck, though.

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: XHCI/USB disk doesn't respond to SCSI INQUIRY
PostPosted: Sat Mar 18, 2017 8:41 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
I am curious to see if you found the problem.

If so, what was it? If not, what have you done to eliminate test cases?

Ben
http://www.fysnet.net/the_universal_serial_bus.htm


Top
 Profile  
 
 Post subject: Re: XHCI/USB disk doesn't respond to SCSI INQUIRY
PostPosted: Sun Mar 19, 2017 11:10 pm 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 154
Hi Ben

Thank you very much for your suggestions on possible areas to look at. I tried through all the points you suggested, that is:- CBW command part in big-endian, Check data even if no IRQ, Changing Tag, ensuring previous IRQ is acked, but, they all looked fine in my implementation and didn't work

I did suspect the issue should be with my new code specific to XHCI. I noticed that I was sending Data stage TRBs (i.e. with TRB Type = 3) on Bulk OUT and Bulk IN endpoints. Please note that SCSI INQUIRY is the first message/command on Bulk Out and Bulk IN endpoints. Bulk Out worked by responding with an IRQ and marking the TRB completion code as SUCCESS however the following Bulk IN (for 36 bytes) didn't get any IRQ/response from device

I didn't read anywhere (at-least I didn't come across - may be missed it) what the TRB type of Bulk IN and Bulk OUT should be. So, I just changed the TRB Type from "3" to "1" (Normal TRB). After this, I received IRQ on Bulk IN (36 bytes) with TRB completion status marked as SUCCESS !

Can you please confirm if TRB Type for Bulk IN and OUT should be "1" and not "3" - and if it's anywhere mentioned in XHCI intel doc or your book (just in case I missed/didn't pay attention to)

My next code/logic to extract data from 36 bytes is crashing the system with PAGE FAULT. This code is common code and it worked with EHCI (long time back) - so I am further checking if it's the issue with data returned by controller or some bug in my parsing code - will update on my findings soon

Thanks
Prajwal

_________________
complexity is the core of simplicity


Top
 Profile  
 
 Post subject: Re: XHCI/USB disk doesn't respond to SCSI INQUIRY
PostPosted: Mon Mar 20, 2017 1:19 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
Yes, the DATA stage TRB's are used on the Control Pipe. i.e.: when you are sending or receiving data via a Control packet. Normal TRB's are used for Bulk transfers.

I will have to check my notes and text, but I can't image I missed that in my book, though I might have.

Thanks for the follow up.
Ben


Top
 Profile  
 
 Post subject: Re: XHCI/USB disk doesn't respond to SCSI INQUIRY
PostPosted: Thu Mar 23, 2017 8:32 pm 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 154
Thanks Ben

I am marking this issue as SOLVED

To summarize, the reason for not receiving any response/IRQ from XHCI controller for SCSI INQUIRY Bulk IN transfer is because I was using TRB Type (3 - Data) on Bulk OUT and Bulk IN transfers. The correct TRB type to use on Bulk OUT and Bulk IN transfers is "1 - Normal"

Regards
Prajwal

_________________
complexity is the core of simplicity


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 72 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