Loading
This is the sample workspace. We wrote the sample project and its bugs. The findings are real review output. On your own install, this list shows your repositories.
Breakspec posts these findings as comments on the pull request on GitHub. This page keeps the history of each review.
| @@ -1,4 +1,4 @@ | |||
| 1 | − | # Axon DMA: interface specification (rev 1.4) | |
| 1 | + | # Axon DMA: interface specification (rev 1.5) | |
| 2 | 2 | ||
| 3 | 3 | The Axon card moves data between host buffers using a descriptor-driven DMA | |
| 4 | 4 | engine. Firmware programs it through a register bus; descriptors live in | |
| @@ -17,6 +17,11 @@ Every signal crossing between the two domains must go through `cdc_sync2`, | |||
| 17 | 17 | `rtl/axon_regs_pkg.sv` is the source of truth. `fw/include/axon_regs.h` must | |
| 18 | 18 | match it bit for bit. | |
| 19 | 19 | ||
| 20 | + | ### 2.1 Changes in rev 1.5 | |
| 21 | + | - New `IRQ_MASK` register at 0x10; `CTRL` moves to 0x14 so control registers are contiguous. | |
| 22 | + | - New read-only `BYTES_DONE` at 0x1C for progress reporting. | |
| 23 | + | - `CTRL.sg_en` enables scatter-gather chaining. | |
| 24 | + | ||
| 20 | 25 | ## 3. Descriptor and buffering | |
| 21 | 26 | ### 3.1 Descriptor | |
| 22 | 27 | `axon_desc_pkg::dma_desc_t`, fetched as little-endian 32-bit words; the least | |
| @@ -24,6 +29,6 @@ significant field is at byte offset 0. Firmware's `struct axon_dma_desc` must | |||
| 24 | 29 | have identical size, offsets and widths. | |
| 25 | 30 | ||
| 26 | 31 | ### 3.2 Beat buffer semantics | |
| 27 | − | `sync_fifo` accepts a write when `wr_en && !full` and a read when | |
| 28 | − | `rd_en && !empty`. Accepted words are returned in the order they were | |
| 32 | + | `sync_fifo` accepts a write when `wr_en && (!full || rd_en)` (a full FIFO | |
| 33 | + | takes a write in the same cycle as a read) and a read when `rd_en && !empty`. Accepted words are returned in the order they were | |
| 29 | 34 | accepted, and no accepted word is lost or duplicated. |
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | // Formal harness for sync_fifo. | |
| 2 | 2 | // Approved semantics (docs/axon_dma_spec.md §3.2): a write is accepted when | |
| 3 | − | // wr_en && !full; accepted words are returned in the order they were accepted. | |
| 3 | + | // wr_en && (!full || rd_en); accepted words are returned in the order they were accepted. | |
| 4 | 4 | module sync_fifo_formal #( | |
| 5 | 5 | parameter int W = 8, | |
| 6 | 6 | parameter int DEPTH = 4 | |
| @@ -25,7 +25,7 @@ module sync_fifo_formal #( | |||
| 25 | 25 | ||
| 26 | 26 | // Every accepted word carries its own sequence number. | |
| 27 | 27 | assign wdata = wr_seq; | |
| 28 | − | wire wr_acc = wr_en && !full; | |
| 28 | + | wire wr_acc = wr_en && (!full || rd_en); | |
| 29 | 29 | wire rd_acc = rd_en && !empty; | |
| 30 | 30 | ||
| 31 | 31 | logic f_past_valid = 1'b0; |
| @@ -14,8 +14,9 @@ struct axon_dma_desc { | |||
| 14 | 14 | uint32_t len; /* bytes, multiple of 4 */ | |
| 15 | 15 | uint16_t flags; | |
| 16 | 16 | uint16_t next_idx; | |
| 17 | + | uint32_t sg_count; /* scatter-gather segments that follow */ | |
| 17 | 18 | }; | |
| 18 | 19 | ||
| 19 | − | _Static_assert(sizeof(struct axon_dma_desc) == 16, "descriptor size"); | |
| 20 | + | _Static_assert(sizeof(struct axon_dma_desc) == 20, "descriptor size"); | |
| 20 | 21 | ||
| 21 | 22 | #endif /* AXON_DESC_H */ |
| @@ -13,5 +13,6 @@ struct axon_dma_desc; | |||
| 13 | 13 | int axon_dma_init(void); | |
| 14 | 14 | int axon_dma_submit(const struct axon_dma_desc *desc, uint32_t desc_bus_addr); | |
| 15 | 15 | int axon_dma_wait(uint32_t max_polls); | |
| 16 | + | uint32_t axon_dma_bytes_done(void); | |
| 16 | 17 | ||
| 17 | 18 | #endif /* AXON_DMA_H */ |
| @@ -6,14 +6,17 @@ | |||
| 6 | 6 | ||
| 7 | 7 | #define AXON_REG_ID 0x00u | |
| 8 | 8 | #define AXON_REG_VERSION 0x04u | |
| 9 | − | #define AXON_REG_CTRL 0x10u | |
| 9 | + | #define AXON_REG_IRQ_MASK 0x10u | |
| 10 | + | #define AXON_REG_CTRL 0x14u | |
| 10 | 11 | #define AXON_REG_STATUS 0x18u | |
| 12 | + | #define AXON_REG_BYTES_DONE 0x1Cu | |
| 11 | 13 | #define AXON_REG_DESC_ADDR 0x20u | |
| 12 | 14 | #define AXON_REG_IRQ_STAT 0x28u | |
| 13 | 15 | ||
| 14 | 16 | #define AXON_CTRL_START (1u << 0) | |
| 15 | 17 | #define AXON_CTRL_SOFT_RST (1u << 1) | |
| 16 | − | #define AXON_CTRL_IRQ_EN (1u << 2) | |
| 18 | + | #define AXON_CTRL_IRQ_EN (1u << 3) | |
| 19 | + | #define AXON_CTRL_SG_EN (1u << 2) | |
| 17 | 20 | ||
| 18 | 21 | #define AXON_STATUS_BUSY (1u << 0) | |
| 19 | 22 | #define AXON_STATUS_DONE (1u << 1) |
| @@ -17,12 +17,20 @@ int axon_dma_submit(const struct axon_dma_desc *desc, uint32_t desc_bus_addr) | |||
| 17 | 17 | { | |
| 18 | 18 | if (desc->len == 0 || (desc->len & 3u)) | |
| 19 | 19 | return AXON_ERR_INVAL; | |
| 20 | + | uint32_t ctrl = AXON_CTRL_IRQ_EN | AXON_CTRL_START; | |
| 21 | + | if (desc->sg_count) | |
| P1Scatter-gather is not implemented in RTL: CTRL.sg_en, sg_count and next_idx are ignored, so chained transfers report DONE after only the first segmentReproduced in simulation, rerun by Breakspec | |||
| 22 | + | ctrl |= AXON_CTRL_SG_EN; | |
| 20 | 23 | axon_mem_write(desc_bus_addr, desc, sizeof *desc); | |
| 21 | 24 | axon_write32(AXON_REG_DESC_ADDR, desc_bus_addr); | |
| 22 | − | axon_write32(AXON_REG_CTRL, AXON_CTRL_IRQ_EN | AXON_CTRL_START); | |
| 25 | + | axon_write32(AXON_REG_CTRL, ctrl); | |
| 23 | 26 | return 0; | |
| 24 | 27 | } | |
| 25 | 28 | ||
| 29 | + | uint32_t axon_dma_bytes_done(void) | |
| 30 | + | { | |
| 31 | + | return axon_read32(AXON_REG_BYTES_DONE); | |
| 32 | + | } | |
| 33 | + | ||
| 26 | 34 | int axon_dma_wait(uint32_t max_polls) | |
| 27 | 35 | { | |
| 28 | 36 | for (uint32_t i = 0; i < max_polls; i++) { | |
| @@ -21,11 +21,12 @@ int main(void) | |||
| 21 | 21 | .len = 69632u, | |
| 22 | 22 | .flags = AXON_DESC_F_LAST | AXON_DESC_F_IRQ, | |
| 23 | 23 | .next_idx = 0, | |
| 24 | + | .sg_count = 0, | |
| 24 | 25 | }; | |
| 25 | 26 | ||
| 26 | 27 | rc = axon_dma_submit(&desc, DESC_BUS_ADDR); | |
| 27 | 28 | if (rc == 0) | |
| 28 | 29 | rc = axon_dma_wait(10000); | |
| 29 | − | printf("transfer len=%u rc=%d\n", (unsigned)desc.len, rc); | |
| 30 | + | printf("transfer len=%u rc=%d bytes_done=%u\n", (unsigned)desc.len, rc, (unsigned)axon_dma_bytes_done()); | |
| 30 | 31 | return rc == 0 ? 0 : 1; | |
| 31 | 32 | } |
| @@ -26,13 +26,19 @@ class CommandRing(Protocol): | |||
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | 28 | class AxonClient: | |
| 29 | − | def __init__(self, ring: CommandRing, timeout_s: float = 0.5) -> None: | |
| 29 | + | def __init__(self, ring: CommandRing, timeout_s: float = 0.5, retries: int = 3) -> None: | |
| 30 | 30 | self._ring = ring | |
| 31 | 31 | self.timeout_s = timeout_s | |
| 32 | + | self.retries = retries | |
| 32 | 33 | ||
| 33 | 34 | def submit(self, desc: Descriptor) -> int: | |
| 34 | 35 | """Run one transfer and return the number of bytes moved.""" | |
| 35 | 36 | if desc.length <= 0 or desc.length % 4: | |
| 36 | 37 | raise ValueError("length must be a positive multiple of 4") | |
| 37 | 38 | tag = self._ring.push(desc) | |
| 38 | − | return self._ring.wait(tag, timeout=self.timeout_s) | |
| 39 | + | for attempt in range(self.retries + 1): | |
| 40 | + | try: | |
| 41 | + | return self._ring.wait(tag, timeout=self.timeout_s) | |
| 42 | + | except TimeoutError: | |
| 43 | + | log.warning("DMA tag %d still running, waiting again (%d)", tag, attempt + 1) | |
| 44 | + | raise TimeoutError(f"transfer did not complete after {self.retries + 1} attempts") |
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | [project] | |
| 2 | 2 | name = "axon-host" | |
| 3 | − | version = "0.4.0" | |
| 3 | + | version = "0.5.0" | |
| 4 | 4 | requires-python = ">=3.10" | |
| 5 | 5 | ||
| 6 | 6 | [tool.pytest.ini_options] |
| @@ -5,6 +5,7 @@ | |||
| 5 | 5 | package axon_desc_pkg; | |
| 6 | 6 | ||
| 7 | 7 | typedef struct packed { | |
| 8 | + | logic [31:0] sg_count; // byte 16: scatter-gather segments that follow | |
| 8 | 9 | logic [15:0] next_idx; // byte 14 | |
| 9 | 10 | logic [15:0] flags; // byte 12 | |
| 10 | 11 | logic [31:0] len; // byte 8: transfer length in bytes | |
| @@ -12,6 +13,6 @@ package axon_desc_pkg; | |||
| 12 | 13 | logic [31:0] src_addr; // byte 0 | |
| 13 | 14 | } dma_desc_t; | |
| 14 | 15 | ||
| 15 | − | localparam int DESC_WORDS = 4; // 128-bit descriptor | |
| 16 | + | localparam int DESC_WORDS = 5; // 160-bit descriptor | |
| 16 | 17 | ||
| 17 | 18 | endpackage |
| @@ -33,6 +33,12 @@ module axon_dma_engine ( | |||
| 33 | 33 | logic [31:0] desc_words [0:DESC_WORDS-1]; | |
| 34 | 34 | logic [31:0] bytes_issued; | |
| 35 | 35 | ||
| 36 | + | logic [DESC_WORDS*32-1:0] desc_flat; | |
| 37 | + | always_comb begin | |
| 38 | + | for (int i = 0; i < DESC_WORDS - 1; i++) desc_flat[i*32 +: 32] = desc_words[i]; | |
| 39 | + | desc_flat[(DESC_WORDS-1)*32 +: 32] = mem_rdata; | |
| 40 | + | end | |
| 41 | + | ||
| 36 | 42 | logic beat_valid, buf_full, buf_empty; | |
| 37 | 43 | logic [31:0] beat_data; | |
| 38 | 44 | ||
| @@ -101,7 +107,7 @@ module axon_dma_engine ( | |||
| 101 | 107 | default: state <= S_IDLE; | |
| P1Scatter-gather is not implemented in RTL: CTRL.sg_en, sg_count and next_idx are ignored, so chained transfers report DONE after only the first segmentReproduced in simulation, rerun by Breakspec | |||
| 102 | 108 | endcase | |
| 103 | 109 | if (state == S_FETCH && fetch_pending && fetch_idx == LAST_WORD) | |
| 104 | − | desc_q <= {mem_rdata, desc_words[2], desc_words[1], desc_words[0]}; | |
| 110 | + | desc_q <= desc_flat; | |
| 105 | 111 | end | |
| 106 | 112 | end | |
| 107 | 113 | ||
| @@ -48,6 +48,7 @@ module axon_dma_top ( | |||
| 48 | 48 | .busy_sync (busy_axi), | |
| 49 | 49 | .done_sync (done_axi), | |
| 50 | 50 | .err_sync (err_axi), | |
| 51 | + | .bytes_done (bytes_done), | |
| 51 | 52 | .irq (irq) | |
| 52 | 53 | ); | |
| 53 | 54 |
| @@ -19,10 +19,13 @@ module axon_regs ( | |||
| 19 | 19 | input logic busy_sync, | |
| 20 | 20 | input logic done_sync, | |
| 21 | 21 | input logic err_sync, | |
| 22 | + | input logic [31:0] bytes_done, | |
| 22 | 23 | output logic irq | |
| 23 | 24 | ); | |
| 24 | 25 | logic irq_stat; | |
| 26 | + | logic irq_mask; | |
| 25 | 27 | logic done_q; | |
| 28 | + | logic [31:0] bytes_done_q; // captured on DONE: bytes_done is stable once the engine is done | |
| 26 | 29 | axon_regs_pkg::status_reg_t status; | |
| 27 | 30 | ||
| 28 | 31 | assign status = {29'd0, err_sync, done_sync, busy_sync}; | |
| @@ -33,11 +36,16 @@ module axon_regs ( | |||
| 33 | 36 | desc_addr <= '0; | |
| 34 | 37 | start_pulse <= 1'b0; | |
| 35 | 38 | irq_stat <= 1'b0; | |
| 39 | + | irq_mask <= 1'b0; | |
| 36 | 40 | done_q <= 1'b0; | |
| 41 | + | bytes_done_q <= '0; | |
| 37 | 42 | end else begin | |
| 38 | 43 | start_pulse <= 1'b0; | |
| 39 | 44 | done_q <= done_sync; | |
| 40 | − | if (done_sync && !done_q) irq_stat <= 1'b1; | |
| 45 | + | if (done_sync && !done_q) begin | |
| 46 | + | irq_stat <= 1'b1; | |
| 47 | + | bytes_done_q <= bytes_done; | |
| 48 | + | end | |
| 41 | 49 | if (wr_en) begin | |
| 42 | 50 | case (wr_addr) | |
| 43 | 51 | ADDR_CTRL: begin | |
| @@ -45,6 +53,7 @@ module axon_regs ( | |||
| 45 | 53 | ctrl.start <= 1'b0; | |
| 46 | 54 | start_pulse <= wr_data[0]; | |
| 47 | 55 | end | |
| 56 | + | ADDR_IRQ_MASK: irq_mask <= wr_data[0]; | |
| 48 | 57 | ADDR_DESC_ADDR: desc_addr <= wr_data; | |
| 49 | 58 | ADDR_IRQ_STAT: if (wr_data[0]) irq_stat <= 1'b0; | |
| 50 | 59 | default: ; | |
| @@ -60,8 +69,10 @@ module axon_regs ( | |||
| 60 | 69 | case (rd_addr) | |
| 61 | 70 | ADDR_ID: rd_data <= AXON_ID; | |
| 62 | 71 | ADDR_VERSION: rd_data <= AXON_VERSION; | |
| 72 | + | ADDR_IRQ_MASK: rd_data <= {31'd0, irq_mask}; | |
| 63 | 73 | ADDR_CTRL: rd_data <= ctrl; | |
| 64 | 74 | ADDR_STATUS: rd_data <= status; | |
| 75 | + | ADDR_BYTES_DONE: rd_data <= bytes_done_q; | |
| 65 | 76 | ADDR_DESC_ADDR: rd_data <= desc_addr; | |
| 66 | 77 | ADDR_IRQ_STAT: rd_data <= {31'd0, irq_stat}; | |
| 67 | 78 | default: rd_data <= 32'd0; | |
| @@ -69,6 +80,6 @@ module axon_regs ( | |||
| 69 | 80 | end | |
| 70 | 81 | end | |
| 71 | 82 | ||
| 72 | − | assign irq = irq_stat & ctrl.irq_en; | |
| 83 | + | assign irq = irq_stat & ctrl.irq_en & ~irq_mask; | |
| 73 | 84 | ||
| 74 | 85 | endmodule |
| @@ -4,18 +4,21 @@ | |||
| 4 | 4 | package axon_regs_pkg; | |
| 5 | 5 | ||
| 6 | 6 | localparam logic [31:0] AXON_ID = 32'hA407_D3A0; | |
| 7 | − | localparam logic [31:0] AXON_VERSION = 32'h0001_0400; | |
| 7 | + | localparam logic [31:0] AXON_VERSION = 32'h0001_0500; | |
| 8 | 8 | ||
| 9 | 9 | localparam logic [7:0] ADDR_ID = 8'h00; // RO | |
| 10 | 10 | localparam logic [7:0] ADDR_VERSION = 8'h04; // RO | |
| 11 | − | localparam logic [7:0] ADDR_CTRL = 8'h10; // RW | |
| 11 | + | localparam logic [7:0] ADDR_IRQ_MASK = 8'h10; // RW | |
| 12 | + | localparam logic [7:0] ADDR_CTRL = 8'h14; // RW (moved next to IRQ_MASK) | |
| 12 | 13 | localparam logic [7:0] ADDR_STATUS = 8'h18; // RO | |
| 14 | + | localparam logic [7:0] ADDR_BYTES_DONE = 8'h1C; // RO | |
| 13 | 15 | localparam logic [7:0] ADDR_DESC_ADDR = 8'h20; // RW | |
| 14 | 16 | localparam logic [7:0] ADDR_IRQ_STAT = 8'h28; // W1C | |
| 15 | 17 | ||
| 16 | 18 | typedef struct packed { | |
| 17 | − | logic [28:0] rsvd; | |
| 18 | − | logic irq_en; // [2] | |
| 19 | + | logic [27:0] rsvd; | |
| 20 | + | logic irq_en; // [3] | |
| 21 | + | logic sg_en; // [2] follow next_idx chain | |
| 19 | 22 | logic soft_rst; // [1] | |
| 20 | 23 | logic start; // [0] self-clearing | |
| 21 | 24 | } ctrl_reg_t; |
| @@ -1,5 +1,7 @@ | |||
| 1 | 1 | // Single-clock FIFO, first-word fall-through. | |
| 2 | − | // A write is accepted when wr_en && !full. A read is accepted when rd_en && !empty. | |
| 2 | + | // A write is accepted when wr_en && (!full || rd_en): a full FIFO still takes a | |
| 3 | + | // write in the same cycle as a read, so back-to-back descriptors never stall. | |
| 4 | + | // A read is accepted when rd_en && !empty. | |
| 3 | 5 | module sync_fifo #( | |
| 4 | 6 | parameter int W = 32, | |
| 5 | 7 | parameter int DEPTH = 4 | |
| @@ -19,7 +21,7 @@ module sync_fifo #( | |||
| 19 | 21 | logic [AW-1:0] wptr, rptr; | |
| 20 | 22 | logic [AW:0] count; | |
| 21 | 23 | ||
| 22 | − | wire do_wr = wr_en && !full; | |
| 24 | + | wire do_wr = wr_en && (!full || rd_en); | |
| 23 | 25 | wire do_rd = rd_en && !empty; | |
| 24 | 26 | ||
| 25 | 27 | always_ff @(posedge clk or negedge rst_n) begin |