Why UserInitializeTargetForID() not be invoked after UserCreateTargetForID() successfully?

Hello Everyone,

I am trying to create a Fake SCSI target based on SCSIControllerDriverKit.framework and inherent from IOUserSCSIParallelInterfaceController, here is the code

kern_return_t IMPL(DRV_MAIN_CLASS_NAME, Start)
{
...
    // Programmatically create a null SCSI Target
    SCSIDeviceIdentifier nullTargetID = 0; // Example target ID, adjust as needed
    ret = UserCreateTargetForID(nullTargetID, nullptr);
    if (ret != kIOReturnSuccess) {
        Log("Failed to create Null SCSI Target for ID %llu", nullTargetID);
        return ret;
    }
...
}

According the document UserCreateTargetForID, after creating a TargetID successfully, the framework will call the UserInitializeTargetForID()

The document said:

As part of the UserCreateTargetForID call, the kernel calls several APIs like UserInitializeTargetForID which run on the default dispatch queue of the dext.

But after UserCreateTargetForID created, why the UserInitializeTargetForID() not be invoked automatically? Here is the part of log show

init() - Start
init() - End
Start() - Start
Start() - try 1 times
UserCreateTargetForID() - Start
   Allocating resources for Target ID 0
UserCreateTargetForID() - End
Start() - Finished.
UserInitializeController() - Start
 - PCI vendorID: 0x14d6, deviceID: 0x626f.
 - BAR0: 0x1, BAR1: 0x200004.
 - GetBARInfo() - BAR1 - MemoryIndex: 0, Size: 262144, Type: 0.
UserInitializeController() - End
UserStartController() - Start
 - msiInterruptIndex : 0x00000000
 - interruptType info is 0x00010000
 - PCI Dext interrupt final value, return status info is 0x00000000
UserStartController() - End

Any assistance would be greatly appreciated! Thank you in advance for your support.

Best regards, Charles

Answered by DTS Engineer in 830501022

I am trying to create a Fake SCSI target based on SCSIControllerDriverKit.framework and inherent from IOUserSCSIParallelInterfaceController, here is the code

FYI, I do not believe it is currently possible to create a virtual SCSI device using SCSIControllerDriverKit or, in fact, use SCSIControllerDriverKit with any bus other than PCI/Thunderbolt. The core issue here is that data is passed into SCSIControllerDriverKit through "fBufferIOVMAddr" as a physical address, not a memory descriptor (which is what most other busses use). You could use that address on PCI (which woud use it to do DMA), but I don't know of any mechanism in DriverKit that will convert that physical address in a VM address (which your DEXT could then access). That means your DEXT doesn't any way to access the data it's supposed to be manipulating.

But after UserCreateTargetForID created, why the UserInitializeTargetForID() not be invoked automatically? Here is the part of log show

If you take another look at the documentation for UserCreateTargetForID, it outlines the full call sequence and specifically mentions that he call should come from UserStartController:

"Then you can call this handler in UserStartController:"

That sequence is important because it allows IOUserSCSIParallelInterfaceController (the support driver in the kernel) to complete start and fully configure before you start trying to create devices.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Accepted Answer

I am trying to create a Fake SCSI target based on SCSIControllerDriverKit.framework and inherent from IOUserSCSIParallelInterfaceController, here is the code

FYI, I do not believe it is currently possible to create a virtual SCSI device using SCSIControllerDriverKit or, in fact, use SCSIControllerDriverKit with any bus other than PCI/Thunderbolt. The core issue here is that data is passed into SCSIControllerDriverKit through "fBufferIOVMAddr" as a physical address, not a memory descriptor (which is what most other busses use). You could use that address on PCI (which woud use it to do DMA), but I don't know of any mechanism in DriverKit that will convert that physical address in a VM address (which your DEXT could then access). That means your DEXT doesn't any way to access the data it's supposed to be manipulating.

But after UserCreateTargetForID created, why the UserInitializeTargetForID() not be invoked automatically? Here is the part of log show

If you take another look at the documentation for UserCreateTargetForID, it outlines the full call sequence and specifically mentions that he call should come from UserStartController:

"Then you can call this handler in UserStartController:"

That sequence is important because it allows IOUserSCSIParallelInterfaceController (the support driver in the kernel) to complete start and fully configure before you start trying to create devices.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Why UserInitializeTargetForID() not be invoked after UserCreateTargetForID() successfully?
 
 
Q