OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 9:46 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [SOLVED]USB MassStorage Bulk-Only
PostPosted: Tue Sep 18, 2018 10:40 am 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
Hi!
I'm already done with hub, mouse and keyboard USB(uhci,ehci) drivers.
Now i'm developing MassStorage driver. So, on QEMU my two(Read10 and ReadCapacity10) functions work fine.
On real hardware after sending readCapcity10 command, my driver tries to read 8 bytes. But data never comes to driver, when i'm detach my USB stick from PC, host controller successfully performs all driver requests and returns to driver some random data.
Initialization code:
Code:
   UsbDevRequest(dev, RT_HOST_TO_DEV | RT_CLASS | RT_INTF, 0xff, 0, dev->intfDesc->intfIndex, 0, 0);
   UsbDevClearHalt(dev); dev->drvPoll = poll;
   u8 lunCnt = 0;
   UsbDevRequest(dev, 0b10100001, 0xfe, 0, dev->intfDesc->intfIndex, 1, &lunCnt);
   kprintf("LUN count:%x\n", lunCnt);
   UsbEndpoint * endpointIn, *endpointOut;
   endpointIn = malloc(sizeof(UsbEndpoint));
   endpointIn->toggle = 0;
   if (dev->intfDesc->endpoints->addr & 0x80)
      endpointIn->desc = dev->intfDesc->endpoints;
   else
      endpointIn->desc = dev->intfDesc->endpoints->next;
   endpointOut = malloc(sizeof(UsbEndpoint));
   endpointOut->toggle = 1;
   if (dev->intfDesc->endpoints->addr & 0x80)
      endpointOut->desc = dev->intfDesc->endpoints->next;
   else
      endpointOut->desc = dev->intfDesc->endpoints;
   UsbTransfer *t = malloc(sizeof(UsbTransfer));
   UsbStorage * storage = malloc(sizeof(UsbStorage));
   t->w = 1;
   storage->t = t;
   storage->tag = 10;
   storage->d = dev;
   storage->endpointIn = endpointIn;
   storage->endpointOut = endpointOut;

   uint sectorCount = 0;
   for (int lun = 0; lun <= lunCnt; ++lun) {
      sectorCount = readcapacity10(storage);
   };
   kprintf("Sectors count: %d\n", sectorCount);

so, my function:
Code:
typedef struct  __attribute__((__packed__)) _q1__q {
   uint32_t sig;
   uint32_t tag;
   uint32_t xfer_len;
   uint8_t flags;
   uint8_t lun;
   uint8_t wcb_len;
   u8 cmd;
} cbw_t;
uint32_t cbw_sig = 0x43425355;
typedef struct __attribute__((__packed__)) __cmd_rdcap_10_t {
   u8 op;  // 0x25
   u8 reserved;
   uint lba;
   u16 reserved2;
   u8 pmi;
   u8 control;
} cmd_rdcap_10_t;
uint sectCount = 0;
uint readcapacity10(UsbStorage * s)
{
   UsbDevice * dev = s->d;
   UsbTransfer *t = s->t;
   UsbEndpoint * endpointIn = s->endpointIn, *endpointOut = s->endpointOut;
   cbw_t * cbw = malloc(31);
   cbw->lun = 0;
   cbw->sig = 0x43425355;
   cbw->wcb_len = 10;
   cbw->flags = 0x80;
   cbw->xfer_len = 8;
   cmd_rdcap_10_t * cmd = (uint)cbw + 15;
   cmd->op = 0x25;
   
   t->endp = endpointOut;
   t->req = 0;
   t->data = cbw;
   t->len = 0x1f;
   t->complete = false;
   t->success = false;
   dev->hcIntr(dev, t);
   unsigned char res[8];
   t->endp = endpointIn;
   t->req = 0;
   t->data = &res;
   t->len = 0x8;
   t->complete = false;
   t->success = false;
   dev->hcIntr(dev, t);
   free(cbw);
   printMem(&res, 8);
   t->endp = endpointIn;
   t->req = 0;
   t->data = cbw;
   t->len = 13;
   t->complete = false;
   t->success = false;
   dev->hcIntr(dev, t);

   //printMem(cbw, 13);
   //kprintf("!%x!", (res[0] << 24) + (res[1] << 16) + (res[2] << 8) + res[3]);
   return (res[0] << 24) + (res[1] << 16) + (res[2] << 8) + res[3];
}

Are someone have any ideas?


Last edited by MrLolthe1st on Sun Sep 23, 2018 5:45 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Tue Sep 18, 2018 11:39 am 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
MrLolthe1st wrote:
i'm developing MassStorage driver. So, on QEMU my two(Read10 and ReadCapacity10) functions work fine.
On real hardware after sending readCapcity10 command, my driver tries to read 8 bytes. But data never comes to driver, when i'm detach my USB stick from PC, host controller successfully performs all driver requests and returns to driver some random data.

Many things could be going on here.
1) Many USB drives may and usually expect the Identify command before you get the capacity or read from the drive.
2) Some USB drives may and usually expect a Test Unit Ready command before you get the capacity or read from the drive.
3) Few USB drives may and usually expect a Sense Request command before you read from the drive, though allowing you to get the Capacity before hand.

As stated before in previous posts, unfortunately, many manufacturers test their drives on one or two of the major operating systems and if it works on those, they consider the test complete and successful. However, those OSes, namely one in particular, does a certain sequence of requests in a specific order. The manufacturer of the drive expects this specific order. It saves on the testing phase of the manufacturing process.

I have found that most drives work if I:
1) Identify the drive
2) Get Capacity
3) always assume that the first Get Capacity request will fail.
4) Test Unit Ready before each request thereafter

As for the controller sending bogus data after you disconnect the drive:
1) this could be the EHCI controller giving up control of the port to the companion controller (UHCI) and your UHCI driver/code is taking over
2) the EHCI firing an interrupt due to the disconnect (port status change) and your code assuming it is a completion interrupt
3) many different things could be going on.

Granted, I have not worked on my USB book non-stop, but I started it in 1994. It is now 24 years later and I am still finding issues and quirks with devices and what not, having to arrange my requests in a certain sequence to accommodate a broader range of devices.

It takes time and work. Don't give up.

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


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Tue Sep 18, 2018 4:13 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
Benjamin, command(inquire) have sent, i'm trying to read, but my driver waits for read request completion, but request never complete.
On BOCHS and QEMU all works fine.


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Tue Sep 18, 2018 4:50 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
Just a quick look over, I don't have the time to look over it much more at the moment, but you don't use a unique tag for each transfer. The device might see that the tag number is the same as the last command and simply ignore it. You need a new unique tag number for each command.

Also, does
Code:
dev->hcIntr(dev, t);

wait for the packet to be complete or do you instantly send the Status packet request before the data packet has time to be filled? What did the above line return? If it stalled, you still have to retrieve the status packet. After every successful command packet (minus one command), there will be a status packet no matter the status of the data transfer.

Just a quick comment or two. sorry it's not more.
Ben


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Thu Sep 20, 2018 10:32 am 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
Ben, i'm say, that i'm send only one Bulk request with CBW. After that i'm waiting for data, but nothing happens


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Thu Sep 20, 2018 12:16 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
I.e., in code are comments:
Code:
typedef struct PACKED
{
   u8 op;
   u16 res;
   u8 power;
   u8 pow2;
   u8 ctrl;
} startStop_cmd;
void startUnit(UsbStorage * s)
{
   UsbDevice * dev = s->d;
   UsbTransfer *t = s->t;
   UsbEndpoint * endpointIn = s->endpointIn, *endpointOut = s->endpointOut;

   cbw_t * cbw = malloc(sizeof(cbw_t) + 66);
   cbw->lun = 0;
   cbw->tag = 0x10;
   cbw->sig = 0x43425355;
   cbw->wcb_len = 10;
   cbw->flags = 0x80;
   cbw->xfer_len = 0;
   startStop_cmd * cmd = (uint)cbw + 15;
   cmd->op = 0x1b;
   cmd->pow2 = 1 ;
   t->endp = endpointOut;
   t->req = 0;
   t->data = cbw;
   t->len = 0x1F;
   t->complete = false;
   t->success = false;
   t->w = 1;//That variable shows to my InterfaceRequest function, that we need to wait until queue has been processed
   dev->hcIntr(dev, t);
   t->endp = endpointIn;
   t->req = 0;
   t->data = cbw;
   t->len = 13;
   t->complete = false;
   t->success = false;
   t->w = 1;//That variable shows to my InterfaceRequest function, that we need to wait until queue has been processed
   dev->hcIntr(dev, t);
   //FREEZES HERE. but if i eject device from PC, request completes, data is transferring
   printMem(cbw, 13);
}


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Thu Sep 20, 2018 12:32 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
MrLolthe1st wrote:
Code:
   //FREEZES HERE. but if i eject device from PC, request completes, data is transferring


No, it's not. First, a device that is not connected, cannot be transferring data.

You are waiting for an interrupt to happen, correct, for a successful transfer?

When you disconnect the device, the EHCI will throw an interrupt because the port status has now changed. When your code is waiting for an interrupt, if it does not query the controller for the type of interrupt, your code will falsely assume a successful transfer. I pointed this out to you in a previous post. Please go back and read it a little more.

Since you stated that it works in Bochs, I suggest that you turn on the DEBUG support for the USB MSD code. This will send all packets and other reads/writes to the log file. Have a look at the log file and see what is going on. Maybe even post that log file, or at least the relevant parts of it.

Ben


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Thu Sep 20, 2018 2:21 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
I'm call init function for massstorage after getting configurations,interfaces and endpoints, device is connected, that i've seeing after successfully getting lun count.Ben, i'm isn't working with interrupts, i'm wait until TD has been processed. How i can turn on debug MSD messages in Bochs?


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Thu Sep 20, 2018 2:58 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
MrLolthe1st wrote:
I'm call init function for massstorage after getting configurations,interfaces and endpoints, device is connected, that i've seeing after successfully getting lun count.Ben, i'm isn't working with interrupts, i'm wait until TD has been processed.

So this means that you are probably waiting for the controller to update the status byte within the TD. There are a few things you need to be careful with when doing this. You need to make sure that you are not trying to read from the physical address at the same time the controller is trying to write to it. You also need to make sure that cache lines are written and data is written in the correct order. i.e.: make sure all of the packet data is physically written to memory before you write the TD. i.e.: Any data pointed to by the TD must already be in physical memory (not the cache) before you write the TD.

This could be part of the reason that it works on an emulator (which has no cache) and not on real hardware (which does have a cache line(s)). However, this probably is not the problem.

MrLolthe1st wrote:
How i can turn on debug MSD messages in Bochs?

I use Windows (WinXP), and unknown if it is different on Linux or other, but:
While running bochs:
- Click on the "Config" button.
- A window named "Bochs Runtime Menu" comes up.
- Click on "Log Options"
- Click on the "Edit" Button
- Make sure "Specify Log options per device" is checked
- Scroll the left list down to "usb_msd" and click on it
- On the right-hand side, the "Debug Events" drop down list needs to be "log"
- Make sure the other two are "log" as well ("Info Events" and "Error Events")
- Click on "apply"
- Then click on "Okay" then "Continue"

To be more detailed, do the same for "usb_ehci" before you exit.

Ben


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Fri Sep 21, 2018 12:25 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
Ben, after massstorage reset and getting lun count i'm try to StartUnit command, but after i'm successfully sending 31 bytes(CBW), i'm try to read CSW, but nothing happens. I'm waiting completion, but request haven't completes ever. I'm didn't using interrupts.
With best regards,
Alex


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Fri Sep 21, 2018 1:13 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
BOCHS debug output:
02862800000d[USBMSD] MASS STORAGE RESET:
02863200000d[USBMSD] USB_REQ_CLEAR_FEATURE:
02863600000d[USBMSD] USB_REQ_CLEAR_FEATURE:
02864000000d[USBMSD] MASS STORAGE: GET MAX LUN
02864400000d[USBMSD] packet hexdump (31 bytes)
02864400000d[USBMSD] 55 53 42 43 00 10 00 00 00 00 00 00 00 00 0A 00
02864400000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02864400000d[USBMSD] command on LUN 0
02864400000d[USBMSD] command tag 0x1000 flags 00000000 len 10 data 0
02864400000d[SCSIHD] command: lun=0 tag=0x1000 data=0x00
02864400000d[SCSIHD] Test Unit Ready
02864400000d[SCSIHD] command complete tag=0x1000 status=0 sense=0
02864400000d[USBMSD] command complete 0
02864800000d[USBMSD] command status 0 tag 0x1000, len 13
02864800000d[USBMSD] packet hexdump (13 bytes)
02864800000d[USBMSD] 55 53 42 53 00 10 00 00 00 00 00 00 00
02865200000d[USBMSD] packet hexdump (31 bytes)
02865200000d[USBMSD] 55 53 42 43 00 00 01 00 24 00 00 00 80 00 0A 12
02865200000d[USBMSD] 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00
02865200000d[USBMSD] command on LUN 0
02865200000d[USBMSD] command tag 0x10000 flags 00000080 len 10 data 36
02865200000d[SCSIHD] command: lun=0 tag=0x10000 data=0x12
02865200000d[SCSIHD] inquiry (len 36)
02865200000d[SCSIHD] read buf_len=36
02865600000d[USBMSD] data in 36/36
02865600000d[SCSIHD] read sector_count=0
02865600000d[SCSIHD] command complete tag=0x10000 status=0 sense=0
02865600000d[USBMSD] command complete 0
02865600000d[USBMSD] packet hexdump (36 bytes)
02865600000d[USBMSD] 00 00 03 02 1F 00 00 10 42 4F 43 48 53 20 20 00
02865600000d[USBMSD] 42 4F 43 48 53 20 48 41 52 44 44 49 53 4B 20 00
02865600000d[USBMSD] 31 2E 30 00
02866000000d[USBMSD] command status 0 tag 0x10000, len 13
02866000000d[USBMSD] packet hexdump (13 bytes)
02866000000d[USBMSD] 55 53 42 53 00 00 01 00 00 00 00 00 00
02866400000d[USBMSD] packet hexdump (31 bytes)
02866400000d[USBMSD] 55 53 42 43 00 00 00 00 08 00 00 00 80 00 0A 25
02866400000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02866400000d[USBMSD] command on LUN 0
02866400000d[USBMSD] command tag 0x0 flags 00000080 len 10 data 8
02866400000d[SCSIHD] command: lun=0 tag=0x0 data=0x25
02866400000d[SCSIHD] Read Capacity
02866400000d[SCSIHD] read buf_len=8
02866800000d[USBMSD] data in 8/8
02866800000d[SCSIHD] read sector_count=0
02866800000d[SCSIHD] command complete tag=0x0 status=0 sense=0
02866800000d[USBMSD] command complete 0
02866800000d[USBMSD] packet hexdump (8 bytes)
02866800000d[USBMSD] 00 02 30 03 00 00 02 00
02867200000d[USBMSD] command status 0 tag 0x0, len 13
02867200000d[USBMSD] packet hexdump (13 bytes)
02867200000d[USBMSD] 55 53 42 53 00 00 00 00 00 00 00 00 00
02867600000d[USBMSD] packet hexdump (31 bytes)
02867600000d[USBMSD] 55 53 42 43 10 00 01 00 00 04 00 00 80 00 0A 28
02867600000d[USBMSD] 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00
02867600000d[USBMSD] command on LUN 0
02867600000d[USBMSD] command tag 0x10010 flags 00000080 len 10 data 1024
02867600000d[SCSIHD] command: lun=0 tag=0x10010 data=0x28
02867600000d[SCSIHD] Read (sector 0, count 2)
02867600000d[SCSIHD] read sector_count=2
02868000000d[USBMSD] data in 512/1024
02868000000d[USBMSD] deferring packet 0BA31020
02871199600d[SCSIHD] data ready tag=0x10010 len=1024
02871199600d[USBMSD] packet hexdump (512 bytes)
02871199600d[USBMSD] EB 58 90 4D 53 44 4F 53 35 2E 30 00 02 01 BE 17
02871199600d[USBMSD] 02 00 00 00 00 F8 00 00 3F 00 20 00 01 00 00 00
02871199600d[USBMSD] 04 30 02 00 21 04 00 00 00 00 00 00 02 00 00 00
02871199600d[USBMSD] 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00
02871199600d[USBMSD] 80 01 29 AA 12 8D C8 4E 4F 20 4E 41 4D 45 20 20
02871199600d[USBMSD] 20 20 46 41 54 33 32 20 20 20 FC B8 00 90 8E C0
02871199600d[USBMSD] 2D 80 00 8E D0 BC 00 08 B9 00 01 BE 00 7C 31 FF
02871199600d[USBMSD] 8E DF F3 A5 06 6A 78 CB 0E 1F 88 16 40 00 80 26
02871199600d[USBMSD] 2F 00 0F 66 8B 36 2C 00 6A 60 07 31 DB E8 50 00
02871199600d[USBMSD] 66 56 9C 6A 60 07 31 FF BE F3 01 A0 0D 00 98 F7
02871199600d[USBMSD] 26 0B 00 C1 E8 05 89 C2 B9 0B 00 26 38 2D 75 03
02871199600d[USBMSD] E9 CB 00 60 F3 A6 61 74 0E 83 C7 20 4A 75 EC 9D
02871199600d[USBMSD] 66 5E 72 C4 E9 B7 00 26 FF 75 14 26 FF 75 1A 66
02871199600d[USBMSD] 5E 6A 60 07 31 DB E8 07 00 72 FB EA 00 06 00 00
02871199600d[USBMSD] A1 0B 00 C1 E8 02 66 98 66 89 F5 66 96 66 99 66
02871199600d[USBMSD] F7 F6 66 0F B7 3E 0E 00 66 01 F8 52 B9 01 00 E8
02871199600d[USBMSD] 49 00 5E 01 F6 01 F6 26 80 64 03 0F 26 66 8B 34
02871199600d[USBMSD] 66 67 8D 45 FE 66 0F B6 0E 0D 00 66 F7 E1 66 89
02871199600d[USBMSD] C5 66 0F B6 06 10 00 66 F7 26 24 00 66 01 E8 66
02871199600d[USBMSD] 01 F8 E8 16 00 A1 0B 00 C1 E8 04 F7 E1 8C C1 01
02871199600d[USBMSD] C1 8E C1 66 81 FE F8 FF FF 0F C3 66 60 60 6A 00
02871199600d[USBMSD] 6A 00 66 50 06 53 6A 01 6A 10 B4 42 8A 16 40 00
02871199600d[USBMSD] 89 E6 16 1F CD 13 0E 1F 72 14 83 C4 10 61 49 74
02871199600d[USBMSD] 0A 03 1E 0B 00 66 83 C0 01 EB D2 66 61 C3 B8 45
02871199600d[USBMSD] 0E CD 10 EB FE 00 00 00 00 00 00 00 00 00 00 00
02871199600d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871199600d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871199600d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871199600d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871199600d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871199600d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871199600d[USBMSD] 00 00 00 53 54 41 52 54 55 50 20 20 20 20 55 AA
02871199600d[USBMSD] packet complete 0BA31020
02871600000d[USBMSD] data in 512/512
02871600000d[SCSIHD] read sector_count=0
02871600000d[SCSIHD] command complete tag=0x10010 status=0 sense=0
02871600000d[USBMSD] command complete 0
02871600000d[USBMSD] packet hexdump (512 bytes)
02871600000d[USBMSD] 52 52 61 41 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02871600000d[USBMSD] 00 00 00 00 72 72 41 61 87 0F 02 00 10 01 00 00
02871600000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA
02872000000d[USBMSD] command status 0 tag 0x10010, len 13
02872000000d[USBMSD] packet hexdump (13 bytes)
02872000000d[USBMSD] 55 53 42 53 10 00 01 00 00 00 00 00 00
02872400000d[USBMSD] packet hexdump (31 bytes)
02872400000d[USBMSD] 55 53 42 43 10 00 01 00 00 02 00 00 80 00 0A 28
02872400000d[USBMSD] 00 00 00 00 01 00 00 01 00 00 00 00 00 00 00
02872400000d[USBMSD] command on LUN 0
02872400000d[USBMSD] command tag 0x10010 flags 00000080 len 10 data 512
02872400000d[SCSIHD] command: lun=0 tag=0x10010 data=0x28
02872400000d[SCSIHD] Read (sector 1, count 1)
02872400000d[SCSIHD] read sector_count=1
02872800000d[USBMSD] data in 512/512
02872800000d[USBMSD] deferring packet 0BA311A0
02874000000d[SCSIHD] data ready tag=0x10010 len=512
02874000000d[USBMSD] packet hexdump (512 bytes)
02874000000d[USBMSD] 52 52 61 41 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02874000000d[USBMSD] 00 00 00 00 72 72 41 61 87 0F 02 00 10 01 00 00
02874000000d[USBMSD] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA
02874000000d[SCSIHD] read sector_count=0
02874000000d[SCSIHD] command complete tag=0x10010 status=0 sense=0
02874000000d[USBMSD] command complete 0
02874000000d[USBMSD] packet complete 0BA311A0
02874800000d[USBMSD] command status 0 tag 0x10010, len 13
02874800000d[USBMSD] packet hexdump (13 bytes)
02874800000d[USBMSD] 55 53 42 53 10 00 01 00 00 00 00 00 00


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Fri Sep 21, 2018 1:17 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
On Real hardware clear feture(halt) fails.


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Fri Sep 21, 2018 1:29 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
I'm recieving 0 lun cnt, is all ok? In spec written: "If no LUN is associated with the device, the value returned shall be 0. "


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Fri Sep 21, 2018 2:28 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 90
When i'm trying to clear halt, qh token sets halt bit.
MS Reset:
Code:
   if (!UsbDevRequest(dev, RT_HOST_TO_DEV | RT_CLASS | RT_INTF, 0xff, 0, dev->intfDesc->intfIndex, 0, 0))
      kprintf("NoReset.");
   UsbDevClearHalt(dev);

   
   u8 lunCnt = 0;
   kprintf("Intf index: %x", dev->intfDesc->intfIndex);
   if(!UsbDevRequest(dev, 0b10100001, 0xfe, 0, dev->intfDesc->intfIndex, 1, &lunCnt))
      kprintf("No lun.");
    dev->drvPoll = &poll;
   kprintf("LUN count:%x\n", lunCnt);
......
bool UsbDevClearHalt(UsbDevice *dev)
{

   UsbEndpDesc * z = dev->intfDesc->endpoints;
   while (z) {
      
         if(!UsbDevRequest(dev,
            0x2,
            0x01,
            0x2,
             z->addr&0xf,
            0, 0)
         )
         kprintf("Can't clear halt at endpoint %x!!!!\n", z->addr);
         //Wait(10000);
      
      z = z->next;
   }
}


Top
 Profile  
 
 Post subject: Re: USB MassStorage Bulk-Only
PostPosted: Fri Sep 21, 2018 2:50 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
Looking over your debug output, it looks like you are sending and receiving as you would expect. Therefore, it must be something within your EHCI driver. You will need to dig deeper into that part of it.

MrLolthe1st wrote:
I'm recieving 0 lun cnt, is all ok? In spec written: "If no LUN is associated with the device, the value returned shall be 0. "

This is correct. If the request fails, you must assume only one LUN.

However, please note that you are not necessarily receiving a LUN count of zero, but a LUN number of the last LUN. i.e.: if there is only one (1) LUN and since LUN numbers are zero based, this first (and last) LUN will have a LUN of zero. If you receive a value of one (1), you will actually have two LUN's, LUN 0 and LUN 1. I have a device that returns a value of 0xFF. Go figure... Not everyone is perfect.

Anyway, dig deeper into your EHCI code and see what you find.

Ben


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], MichaelPetch, SemrushBot [Bot] and 770 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