Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ1034
Page ↗
Q1034FWMetaASIC interview problem

DMA descriptor-ring submission

TechniquesFWDMARing bufferMemory ordering
DifficultyHard
TopicFirmware
LanguageC
Requirements4 checkpoints
01

Problem

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.

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

Example input and output

Use this case to check your interpretation
Input
tail=7, head=3, addr is 64-byte aligned, len=1024, and the ring has space
Output
Write desc[7], execute dma_wmb, set tail=0, write doorbell=0, and return 0
Explanation

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

02

Requirements (4)

  • 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.
  • Read hardware head, compute next=(tail+1)&7, and return -EAGAIN without writing a descriptor when next==head.
  • Write addr and len into desc[tail], execute a DMA write barrier, then publish tail=next and doorbell=next in that order.
  • Use modulo-eight wraparound, submit exactly one descriptor per successful call, and return 0 only after the doorbell write.