Hello,
I wrote a driver for PCIe base card. Upon writing to a control register, the FPGA generates a legacy (but PCIe) interrupt every ~10msec.
The driver worked fine on a specified chipset with Server 2016 and now it does not work on Server 2019 with a newer chipset.
According to the FPGA debugger, the FPGA generates interrupts.
In the driver I read offset 0x6 in the configuration space. D3 is set to 1 as expected.
What can be the reason that PLxEvtInterruptIsr is not called at all ?
According to the device manager, the card takes interrupt 8 and vector 0x82.
Following is the code that calls WdfInterruptCreate.
Thank you,
Zvi
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.
Module Name:
IsrDpc.c
Abstract:
Contains routines related to interrupt and dpc handling.
Environment:
Kernel mode
--*/
#include "precomp.h"
#include "IsrDpc.tmh"
#include "ModuleIn.h"
#include "ModuleIoControl.h"
NTSTATUS
PLxInterruptCreate(
IN PDEVICE_EXTENSION DevExt
)
/*++
Routine Description:
Configure and create the WDFINTERRUPT object.
This routine is called by EvtDeviceAdd callback.
Arguments:
DevExt Pointer to our DEVICE_EXTENSION
Return Value:
NTSTATUS code
--*/
{
NTSTATUS status;
WDF_INTERRUPT_CONFIG InterruptConfig;
KdPrint(("--> PLxInterruptCreate\n"));
WDF_INTERRUPT_CONFIG_INIT( &InterruptConfig,
PLxEvtInterruptIsr,
PLxEvtInterruptDpc );
InterruptConfig.EvtInterruptEnable = PLxEvtInterruptEnable;
InterruptConfig.EvtInterruptDisable = PLxEvtInterruptDisable;
// JOHNR: Enable testing of the DpcForIsr Synchronization
InterruptConfig.AutomaticSerialization = TRUE;
//
// Unlike WDM, framework driver should create interrupt object in EvtDeviceAdd and
// let the framework do the resource parsing and registration of ISR with the kernel.
// Framework connects the interrupt after invoking the EvtDeviceD0Entry callback
// and disconnect before invoking EvtDeviceD0Exit. EvtInterruptEnable is called after
// the interrupt interrupt is connected and EvtInterruptDisable before the interrupt is
// disconnected.
//
status = WdfInterruptCreate( DevExt->Device,
&InterruptConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->Interrupt );
if( !NT_SUCCESS(status) ) {
/*TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
"WdfInterruptCreate failed: %!STATUS!", status);*/
}
KdPrint(("<-- PLxInterruptCreate\n"));
return status;
}
BOOLEAN
PLxEvtInterruptIsr(
IN WDFINTERRUPT Interrupt,
IN ULONG MessageID
)
/*++
Routine Description:
Interrupt handler for this driver. Called at DIRQL level when the
device or another device sharing the same interrupt line asserts
the interrupt. The driver first checks the device to make sure whether
this interrupt is generated by its device and if so clear the interrupt
register to disable further generation of interrupts and queue a
DPC to do other I/O work related to interrupt - such as reading
the device memory, starting a DMA transaction, coping it to
the request buffer and completing the request, etc.
Arguments:
Interupt - Handle to WDFINTERRUPT Object for this device.
MessageID - MSI message ID (always 0 in this configuration)
Return Value:
TRUE -- This device generated the interrupt.
FALSE -- This device did not generated this interrupt.
--*/
{
PDEVICE_EXTENSION devExt;
BOOLEAN isRecognized = FALSE;
CARD_STATUS_U status;
UINT32 Channel;
UINT32 DataMask, HeaderMask;
int BitId = 0;
UNREFERENCED_PARAMETER(MessageID);
KdPrint (("--> PLxInterruptHandler\n"));
devExt = PLxGetDeviceContext(WdfInterruptGetDevice(Interrupt));
//Read status register
status.Word = READ_REGISTER_ULONG((PVOID)((UINT64)devExt->Bar1Address + STATUS_REGISTER_OFFSET));
//The interrupt status is a 32bits word.
//1st byte contains the status of channel 0
//2nd byte contains the status of channel 1
//3rd byte contains the status of channel 2
//4th byte contains the status of channel 3
for (Channel = 0; Channel<N_CHANNELS; Channel++)
{
//Bits 0,8,16,24
DataMask = 1 << BitId;
if (status.Word & DataMask)
{
devExt->InterruptPending[Channel] = 1;
(devExt->InterruptCounter[Channel])++;
//Check if also header bit is '1'
HeaderMask = DataMask << 1;
if (status.Word & HeaderMask)
{
devExt->HeaderBlockReady[Channel] = 1;
//KdPrint (("Channel:%d Header block ready\n",Channel));
}
else
devExt->HeaderBlockReady[Channel] = 0;
isRecognized = TRUE;
}
//Move to next byte
BitId += 8;
}
if (isRecognized)
WdfInterruptQueueDpcForIsr(devExt->Interrupt);
//Write status register to clear interrupts
WRITE_REGISTER_ULONG((PVOID)((UINT64)devExt->Bar1Address + STATUS_REGISTER_OFFSET), status.Word);
devExt = PLxGetDeviceContext(WdfInterruptGetDevice(Interrupt));
return isRecognized;
}
_Use_decl_annotations_
VOID
PLxEvtInterruptDpc(
WDFINTERRUPT Interrupt,
WDFOBJECT Device
)
/*++
Routine Description:
DPC callback for ISR. Please note that on a multiprocessor system,
you could have more than one DPCs running simulataneously on
multiple processors. So if you are accesing any global resources
make sure to synchrnonize the accesses with a spinlock.
Arguments:
Interupt - Handle to WDFINTERRUPT Object for this device.
Device - WDFDEVICE object passed to InterruptCreate
Return Value:
--*/
{
PDEVICE_EXTENSION devExt;
ULONG InterruptPending[N_CHANNELS] = { 0,0,0,0 };
int Channel;
NTSTATUS status;
WDFREQUEST request;
MODULE_INTERRUPT_REPLY *pInterruptReply;
void *pOutBuffer;
size_t Length;
int bytesReturned;
UNREFERENCED_PARAMETER(Device);
KdPrint (("--> PLxEvtInterruptDpc"));
devExt = PLxGetDeviceContext(WdfInterruptGetDevice(Interrupt));
//
// Acquire this device's InterruptSpinLock.
//
WdfInterruptAcquireLock( Interrupt );
for (Channel = 0; Channel<N_CHANNELS; Channel++)
{
if (devExt->InterruptPending[Channel])
{
devExt->InterruptPending[Channel] = 0;
InterruptPending[Channel] = 1;
}
}
//
// Release our interrupt spinlock
//
WdfInterruptReleaseLock( Interrupt );
//Handle pending interrupts
for (Channel = 0; Channel<N_CHANNELS; Channel++)
{
if (InterruptPending[Channel])
{
status = WdfIoQueueRetrieveNextRequest(devExt->InternalQueue[Channel], &request);
//Request is pending in queue. EvtIoctl sent "was interrupt" request
if (NT_SUCCESS(status))
{
status = WdfRequestRetrieveOutputBuffer(request, sizeof(MODULE_INTERRUPT_REPLY),
&pOutBuffer, &Length);
pInterruptReply = (MODULE_INTERRUPT_REPLY *)pOutBuffer;
pInterruptReply->Counter = devExt->InterruptCounter[Channel];
pInterruptReply->HeaderBlockReady = devExt->HeaderBlockReady[Channel];
//KdPrint (("HeaderBlockReady[Channel]=%d\n",pInterruptReply->HeaderBlockReady));
//KdPrint (("WdfRequestRetrieveOutputBuffer: status=0x%x counter=%d\n",status,pInterruptReply->Counter));
bytesReturned = sizeof(MODULE_INTERRUPT_REPLY);
WdfRequestCompleteWithInformation(request, STATUS_SUCCESS, bytesReturned);
}
}
KdPrint (("<-- PLxEvtInterruptDpc"));
}
return;
}
NTSTATUS
PLxEvtInterruptEnable(
IN WDFINTERRUPT Interrupt,
IN WDFDEVICE Device
)
/*++
Routine Description:
Called by the framework at DIRQL immediately after registering the ISR with the kernel
by calling IoConnectInterrupt.
Return Value:
NTSTATUS
--*/
{
UNREFERENCED_PARAMETER(Device);
UNREFERENCED_PARAMETER(Interrupt);
return STATUS_SUCCESS;
}
NTSTATUS
PLxEvtInterruptDisable(
IN WDFINTERRUPT Interrupt,
IN WDFDEVICE Device
)
/*++
Routine Description:
Called by the framework at DIRQL before Deregistering the ISR with the kernel
by calling IoDisconnectInterrupt.
Return Value:
NTSTATUS
--*/
{
UNREFERENCED_PARAMETER(Device);
UNREFERENCED_PARAMETER(Interrupt);
return STATUS_SUCCESS;
}