Today i'm tried to write up mass storage driver. I'm already have working UHCI driver and almost working EHCI(only at QEMU).
I'm write function to make endpoint calls:
Code: Select all
static void EhciDevIntr(UsbDevice *dev, UsbTransfer *t)
{
EhciController *hc = (EhciController *)dev->hc;
// Determine transfer properties
uint speed = dev->speed;
uint addr = dev->addr;
uint maxSize = dev->maxPacketSize;
uint endp = t->endp->desc->addr & 0xf;
// Create queue of transfer descriptors
EhciTD *td = EhciAllocTD(hc);
if (!td)
{
t->success = false;
t->complete = true;
return;
}
EhciTD *head = td;
EhciTD *prev = 0;
// Data in/out packets
uint toggle = t->endp->toggle;
uint packetType = USB_PACKET_IN;
if (t->endp->desc->addr&0x80!=0)
packetType = USB_PACKET_OUT;
kprintf("$#%x#$", packetType);
uint packetSize = t->len;
EhciInitTD(td, prev, toggle, packetType, packetSize, t->data);
// Initialize queue head
EhciQH *qh = EhciAllocQH(hc);
EhciInitQH(qh, t, head, dev->parent, true, speed, addr, endp, maxSize);
//printQh(qh);
// Schedule queue
EhciInsertPeriodicQH(hc->periodicQH, qh);
EhciWaitForQH(hc, qh);
}
So, firstly i'm reseting MassStorage and reciving lun count:
Code: Select all
UsbDevRequest(dev, RT_HOST_TO_DEV | RT_CLASS | RT_INTF, 0xff, 0, dev->intfDesc->intfIndex, 0, 0);
u8 lunCnt = 0;
UsbDevRequest(dev, 0b10100001, 0xfe, 0, dev->intfDesc->intfIndex, 1, &lunCnt);
Next i'm getting two endpoints to in and out packets.
Code: Select all
UsbEndpoint * endpointIn = malloc(sizeof(UsbEndpoint));
endpointIn->toggle = 1;
if(dev->intfDesc->endpoints->addr & 0x80)
endpointIn->desc = dev->intfDesc->endpoints;
else
endpointIn->desc = dev->intfDesc->endpoints->next;
UsbEndpoint * endpointOut = malloc(sizeof(UsbEndpoint));
endpointOut->toggle = 0;
if (dev->intfDesc->endpoints->addr & 0x80)
endpointOut->desc = dev->intfDesc->endpoints->next;
else
endpointOut->desc = dev->intfDesc->endpoints;
Code: Select all
// Prepare transfer
UsbTransfer *t = malloc(sizeof(UsbTransfer));
Read10 ro;
memset(&ro, 0, sizeof(Read10));
ro.signature = 0x43425355;
ro.tag =0x21;
ro.dataLength = 0x200;
ro.flags = 0x80;
ro.lun = 0;
ro.cmdLength = 10;
ro.opcode = 0x28;
ro.LBA = 0;
ro.cnt =1<<8;
t->endp = endpointOut;
t->req = 0;
t->data = &ro;
t->len = 0x1F;
t->complete = false;
t->success = false;
dev->hcIntr(dev, t);
Next i'm read data:
Code: Select all
t->endp = endpointIn;
t->req = 0;
t->data = buf;
t->len = 0x200;
t->complete = false;
t->success = false;
dev->hcIntr(dev, t);
With best regards,
Aleksandr