Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/DMA descriptor-ring submission

Hardware interview practice

DMA descriptor-ring submission

HardFirmwareC

Firmware produces descriptors for an eight-entry DMA ring. Hardware advances head, firmware advances tail, and one slot stays empty to distinguish full from empty. Implement validation, wraparound, full detection, and device-visible publication ordering.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

int submit(struct ring *r, uint64_t addr, uint32_t len);
ring has desc[8], head, tail, and MMIO doorbell
Reviewed example

Work through one case

Input
tail=7, head=3, addr is 64-byte aligned, len=1024, and the ring has space
Expected output
Write desc[7], execute dma_wmb, set tail=0, write doorbell=0, and return 0

The mask implements modulo-eight wraparound, and the barrier ensures the descriptor is visible before hardware learns the new producer index.

What to cover

Requirements

  1. Reject a null ring, null head or doorbell register pointer, len outside 1..4096, or addr not aligned to 64 bytes with -EINVAL and no ring or MMIO change.
  2. Read hardware head, compute next=(tail+1)&7, and return -EAGAIN without writing a descriptor when next==head.
  3. Write addr and len into desc[tail], execute a DMA write barrier, then publish tail=next and doorbell=next in that order.
  4. Use modulo-eight wraparound, submit exactly one descriptor per successful call, and return 0 only after the doorbell write.
Continue practicing

Related questions

Hardware-Software IntegrationVerify an in-place DMA merge transaction→Hardware-Software IntegrationVerify a DMA flood-fill transaction→
asic.fyi · Learn silicon end to end.info@asic.fyi