Wait (with timeout) to 3 interrupts upon IOCTL request

Hello,

In a previous driver, upon IOCTL request a DMA is started. The request is forwarded to internal queue. Upon DMA completion, an MSI interrupt is generated and the ISR dpc is called.
In this dpc, the IOCTL request is pulled from the internal queue and completed. Till then, the application is blocked with timeout.

Currently I have to do the following upon IOCTL request:

  1. Start DMA and wait for DMA completed interrupt.
  2. Wait for a second interrupt (no related to a DMA)
  3. Start DMA and wait for DMA completed interrupt.
  4. Complete IOCTL request

Can you please advise what is the right mechanism for this scenario ?

I want IOCTL to be blocked (with timeout) till 4th step is completed.
In case (for example) step 2 is not completed within specified time, the IOCTL request will be completed with error.

Thank you,
Zvika

zvivered wrote:

Can you please advise what is the right mechanism for this scenario ?
I want IOCTL to be blocked (with timeout) till 4th step is completed.

I already told you this.  You’re not going to get a different answer by
asking again.

ioctl handler:
    set state = 1 // waiting for first DMA complete
    prepare first DMA
    submit DMA
    start timer
    put the ioctl on a queue
    return STATUS_PENDING

DPC:
    if state == 1:
        // make sure it was a DMA complete
        state = 2  // wait for unrelated interrupt
    else if state == 2:
        prepare second DMA
        submit second DMA
        kill the timer
        set state = 3 // wait for second DMA complete
    else if state == 3:
        pop ioctl from queue
        complete it
        set state = 0 // idle

timer DPC:
        if state == 1 or 2:
            cancel DMA?
            pop ioctl from queue
            complete STATUS_TIMEOUT
            set state = 0 // idle
        else:
            // it’s probably working

What you’re doing isn’t unusual. It’s commonly called “staged processing.” I don’t understand what your issue is, though. Surely it’s just a matter of implementation (how you store, manage, retrieve, and cancel requests), and that will depend greatly on the details of how your device works. It seems Mr Roberts has given you a pretty good answer. What is it, specifically, you don’t understand or that you need us to tell you??

I already told you this.

Actually, the whole thing is suspiciously similar to the thread where a poster asks whether he can wait in IOCTL handler…

Anton Bassov