microsoft / Network-Adapter-Class-Extension

Network Adapter Class Extension to WDF (NetAdapter Cx) makes it easy to write high quality and high speed drivers for Network Interface Controllers
MIT License
54 stars 17 forks source link

Failed to create multiple NetAdapter on a WDFDevice #11

Closed BijieXu closed 1 year ago

BijieXu commented 2 years ago

Hi MS team,

I'm developing the NIC driver for our NIC adapter. Our card hardware has 1 PCIE device but 2 physical network ports.

In this case, we need to create a WDFDEVICE for the PCIE device, and 2 NETADAPTER instances on the WDFDevice to represent the 2 physical ports. I checked the official document and seems this mode is supported.

We are creating these items in the callback "EvtDriverDeviceAdd". We have no problem creating the WDFDEVICE, and the 1st NETADAPTER. But it return error when creating the 2nd NETADAPTER. the errno is "-2147483622" which is "STATUS_NO_MORE_ENTRIES". Is there anything wrong here?

Here is part of the code.

`   WDFDEVICE wdfDevice;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
    WdfDeviceCreate(&deviceInit, &deviceAttributes, &wdfDevice));

DbgPrint("<-- Created WDF Device OK\n");

WdfDeviceSetAlignmentRequirement(wdfDevice, FILE_256_BYTE_ALIGNMENT);

WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS idleSettings;
WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&idleSettings, IdleCannotWakeFromS0);
idleSettings.UserControlOfIdleSettings = IdleAllowUserControl;

GOTO_IF_NOT_NT_SUCCESS(Exit, status,
    WdfDeviceAssignS0IdleSettings(wdfDevice, &idleSettings));

pf = RtGetDeviceContext(wdfDevice);

DbgBreakPoint();

for (int i = 0; i < MAX_NFP_PORT; i++) {
    adapterInit = NetAdapterInitAllocate(wdfDevice);

    GOTO_WITH_INSUFFICIENT_RESOURCES_IF_NULL(Exit, status, adapterInit);

    NET_ADAPTER_DATAPATH_CALLBACKS datapathCallbacks;
    NET_ADAPTER_DATAPATH_CALLBACKS_INIT(
        &datapathCallbacks,
        EvtAdapterCreateTxQueue,
        EvtAdapterCreateRxQueue);

    NetAdapterInitSetDatapathCallbacks(
        adapterInit,
        &datapathCallbacks);

    WDF_OBJECT_ATTRIBUTES adapterAttributes;
    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&adapterAttributes, NFP_NET_ADAPTER);

    NETADAPTER netAdapter;
    GOTO_IF_NOT_NT_SUCCESS(Exit, status,
        NetAdapterCreate(adapterInit, &adapterAttributes, &netAdapter));

    DbgPrint("<-- Created NetAdapter %d OK\n", i);

    NFP_NET_ADAPTER* adapter = RtGetAdapterContext(netAdapter);

    adapter->pf = pf;

    GOTO_IF_NOT_NT_SUCCESS(Exit, status,
        RtInitializeAdapterContext(adapter, wdfDevice, netAdapter));

    pf->Adapters[i] = adapter;
    NetAdapterInitFree(adapterInit);
    adapterInit = nullptr;
}`
BijieXu commented 2 years ago

I step into the code execution with windbg, and here is the process: windbg.txt

BijieXu commented 1 year ago

We have fixed this problem by modifying the .inf file to allow creating multiple network interfaces. Close this ticket.

grimbeaver commented 7 months ago

@BijieXu I realize this was a while ago but can you share what you modified in the INF to allow creating multiple network interfaces?

amrutha-chandramohan commented 7 months ago

The NumberOfNetworkInterfaces keyword can be added to the INF to support multiple adapter creation: https://learn.microsoft.com/en-us/windows-hardware/drivers/netcx/inf-files-for-netadaptercx-client-drivers

BijieXu commented 7 months ago

@grimbeaver and @amrutha-chandramohan , exactly, just add "NumberOfNetworkInterfaces" to inf.

` nfp-win: update inf to support 2 ports on one device Add a registry entry 'NumberOfNetworkInterfaces' to specify the # of ports

Signed-off-by: Bijie Xu bijie.xu@corigine.com`

grimbeaver commented 7 months ago

@amrutha-chandramohan and @BijieXu thanks that seems to do the trick.