43 input mrst,
// @posedge mclk - sync reset 44 input hrst,
// @posedge hclk - sync reset 46 input mclk,
// for command/status 47 input hclk,
// global clock to run axi_hp @ 150MHz 48 // Control interface (@mclk) 49 // Documentation insists 6 LSBs should be 0, but AHCI driver seems to ignore it. Will align to just 128 bits. 50 // input [31:7] ctba, // command table base address 51 input [
31:
4]
ctba,
// command table base address 52 input ctba_ld,
// load command table base address 53 input [
15:
0]
prdtl,
// number of entries in PRD table (valid at cmd_start) 54 input dev_wr,
// write to device (valid at start) 55 input cmd_start,
// start processing command table, reset prdbc 56 input prd_start,
// at or after cmd_start - enable reading PRD/data (if any) 57 input cmd_abort,
// try to abort a command: Will keep afi_rready on until RD FIFO is empty and 58 // afi_awvalid (slowly one by one?) until afi_wacount is empty, keeping afi_wlast on 60 // Optional control of the AXI cache mode, default will be set to 4'h3, 4'h3 at mrst 66 // Some data from the command table will be used internally, data will be available on the general 67 // sys_out[31:0] port and should be consumed 68 output reg ct_busy,
// cleared after 0x20 DWORDs are read out 69 // reading out command table data 71 input [
1:
0]
ct_re,
// [0] - re, [1]-regen 74 // After the first 0x80 bytes of the Command Table are read out, this module will read/process PRDs, 75 // not forwarding them to the output 76 output prd_done,
// @mclk prd done (regardless of the interrupt) - data transfer of one PRD is finished (any direction) 78 output reg prd_irq_pend,
// prd interrupt pending. This is just a condition for irq - actual will be generated after FIS OK 83 output axi_mismatch,
// axi hp counters where empty when calculated counters were not (handled, but seems to be a bug - catch it) 85 // Data System memory -> HBA interface @ mclk 86 output [
31:
0]
sys_out,
// 32-bit data from the system memory to HBA (dma data) 87 output sys_dav,
// at least one dword is ready to be read 88 // output sys_dav_many, // several DWORDs are in the FIFO (TODO: decide how many) 89 input sys_re,
// sys_out data read, advance internal FIFO 90 output last_h2d_data,
// when active and no new data for 2 clocks - that was the last one 92 // Data HBA -> System memory interface @ mclk 93 input [
31:
0]
sys_in,
// HBA -> system memory 94 output sys_nfull,
// internal FIFO has room for more data (will decide - how big reserved space to keep) 97 output extra_din,
// all DRDs are transferred to memory, but FIFO has some data. Valid when transfer is stopped 99 // axi_hp signals write channel 103 input afi_awready,
// @SuppressThisWarning VEditor unused - used FIF0 level 115 input afi_wready,
// @SuppressThisWarning VEditor unused - used FIF0 level 122 input [
5:
0]
afi_bid,
// @SuppressThisWarning VEditor unused 123 input [
1:
0]
afi_bresp,
// @SuppressThisWarning VEditor unused 124 // PL extra (non-AXI) signals 128 // AXI_HP signals - read channel 132 input afi_arready,
// @SuppressThisWarning VEditor unused - used FIF0 level 145 input [
5:
0]
afi_rid,
// @SuppressThisWarning VEditor unused 147 input [
1:
0]
afi_rresp,
// @SuppressThisWarning VEditor unused 148 // PL extra (non-AXI) signals 161 // Read command table 162 // localparam AFI_FIFO_LAT = 2; // >=2 167 // reg [31:7] ctba_r; 168 reg [
31:
4]
ctba_r;
// Seems that AHCI driver ignores requirement to have 6 LSB==0 173 reg prd_start_hclk_r;
// to make sure it is with/after prd_start_hclk if in mclk they are in the same cycle 178 reg [
31:
4]
ct_maddr;
// granularity matches PRDT entry - 4xDWORD, 2xQWORD 181 reg [
31:
0]
afi_addr;
// common for afi_araddr and afi_awaddr 183 // wire axi_set_raddr_ready = !(|afi_racount) && !axi_set_raddr_r); // Most pessimistic 195 reg [
31:
1]
data_addr;
// 2 lower addresses will be used in in/out fifo modules 200 reg [
22:
1]
qwcount;
// only [21:3] are used ([22] - carry from subtraction ) 233 // wire raddr_prd_rq = (|prds_left) && (ct_done || prd_done); 242 wire addr_data_rq = (wcount_set || data_next_burst); 244 wire waddr_data_rq = !dev_wr_hclk && addr_data_rq; 245 wire raddr_data_rq = dev_wr_hclk && addr_data_rq; 256 // count different types of AXI ID separately - just for debugging 261 reg [
5:
0]
afi_id;
// common for 3 channels 266 // reg abort_busy_hclk; 269 // reg axi_dirty_r; // afi_wacount of afi_rcount are non-zero (assuming afi_wcount should be zero as addresses are posted first 286 reg rwaddr_rq_r;
// next cycle after requesting waddr_data_rq, raddr_data_rq, raddr_ct_rq and raddr_prd_rq (*-pend is valid) 296 // assign prd_done = done_dev_wr || done_dev_rd; 301 /// assign axi_set_waddr_w = axi_set_raddr_ready && raddr_data_pend; 312 /// assign afi_rready = afi_rd_ctl[0] || data_afi_re; 314 /// assign afi_wlast = qw_datawr_last; 317 // assign afi_wid = afi_id; 320 // Unused or static output signals 323 // assign afi_awcache = 4'h3; 331 // assign afi_arcache = 4'h3; 338 // reg [31:0] ct_data_reg; 353 // if (ctba_ld) ctba_r <= ctba[31:7]; 385 // afi_rd_ctl <= { afi_rd_ctl[0],(ct_busy_r[0] || prd_rd_busy) && ((|afi_rcount[7:SAFE_RD_BITS]) || (afi_rvalid && !(|afi_rd_ctl)))}; 407 // if (cmd_start_hclk) ct_maddr[31:4] <= {ctba_r[31:7],3'b0}; 412 // overall sequencing makes sure that there will be no new requests until older served 413 // additionally they are mutuially exclusive - only one may be pending at a time 433 /// if (axi_set_raddr_w || axi_set_waddr_w) begin 434 if (
rwaddr_rq_r)
begin // first cycle one of the *_pend is set 454 /// if (addr_data_rq) data_len <= ((|qwcount[21:7]) || (&qwcount[6:3]))? 4'hf: qwcount[6:3]; // early calculate 468 //wcount_plus_data_addr 470 /// data_next_burst <= !qwcount[22] && axi_set_addr_data_w && (|qwcount[21:7]); // same time as afi_awvalid || afi_arvalid 474 // store data address from PRD, increment when needed 489 // Set/increment address to store (internally) CT and PRD data 495 // generate busy for command table (CT) read 505 // generate busy for PRD table entry read 507 // else if (prd_rd_busy) prd_rd_busy <= 1; 518 // calculate afi_wlast - it is (qw_datawr_burst == 0), just use register qw_datawr_last 546 // Flushing AXI HP - there is no easy way to reset it, so if there was an error in SATA communication we need to read any data 547 // that was already requested (over AXI read adderss channel) and send junk data (with appropriate afi_wlast bit) to the write 548 // channel. THis module is not reset and even bitsteram relaod will not work, so hrst input is used just as disable paying attention 549 // to other inputs, doe s not reset anything inside. 550 // FPGA should not be reset /reloaded if there are any outstanding transactions not aborted 551 // Current implementation counts all transactions and relies on it - not on afi_*count. TODO: Implement recovering from mismatch 587 )
ahci_dma_rd_fifo_i (
613 )
ahci_dma_wr_fifo_i (
623 // .dout_av (), // input 635 // mclk -> hclk cross-clock synchronization 721 // if (axi_set_raddr_w || axi_set_waddr_w) begin 727 // if (hrst) dbg_last_afi_len <= 0; 731 // if (wcount_set) qwcount[22:7] <= {1'b0,wcount_plus_data_addr[21:7]}; // wcount[21:1] + data_addr[2:1]; //minus 1 734 // else if (wcount_set) dbg_qwcount_cntr <= dbg_qwcount_cntr + 1; 735 // else if (data_next_burst) dbg_qwcount_cntr <= dbg_qwcount_cntr + 1; 740 // else if (axi_set_raddr_w) dbg_set_raddr_count <= dbg_set_raddr_count + 1; 745 // else if (axi_set_waddr_w) dbg_set_waddr_count <= dbg_set_waddr_count + 1; 746 // else if (axi_set_waddr_ready && waddr_data_pend) dbg_set_waddr_count <= dbg_set_waddr_count + 1; //0x14 774 assign debug_out = {qwcount_done, 781 assign debug_out1 = { //dbg_set_raddr_count[7:0], 784 //{qwcount[22], qwcount[13:7]}, 785 dbg_set_waddr_count[7:0], 788 dbg_qwcount_cntr[7:0]}; 790 assign debug_out1 = {
//dbg_set_raddr_count[7:0] 794 abort_debug[
21:
0]};
// {aw_count[5:0], w_count[7:0], r_count[7:0]};
12992abort_debugwire[21:0]
12987afi_wid_abortwire[5:0]
axi_hp_abort_i axi_hp_abort
12923axi_set_addr_data_wwire
12835set_axi_rd_cache_mode
12937qw_datawr_burstreg[3:0]
ahci_dma_wr_fifo_i ahci_dma_wr_fifo
12905int_data_addrreg[3:0]
12983abort_done_unneededreg
[31:0] 12902debug_dma_h2d
12936qw_datawr_leftreg[21:3]
12997wcount_plus_data_addrwire[21:1]
12988afi_rready_abortwire
[3:0] 12833axi_rd_cache_mode
abort_done_i pulse_cross_clock
reg 13115fifo_nempty_mclk
[WCNT_BITS-1:0] 13104wcnt
reg [ 3:0] 12861afi_awcache
12919axi_set_raddr_readywire
[0:31] 12904ct_data_ramreg[31:0]
12974fifo_nempty_mclkwire
13002dbg_set_waddr_countreg[7:0]
13000dbg_qwcount_cntrreg[7:0]
ahci_dma_rd_fifo_i ahci_dma_rd_fifo
12920axi_set_waddr_readywire
13001dbg_set_raddr_countreg[7:0]
reg [ 3:0] 12885afi_arcache
12914ct_over_prd_enabledreg[1:0]
12998dbg_afi_awvalid_cntrreg[7:0]
12976ct_data_regreg[31:0]
[3:0] 12832axi_wr_cache_mode
[WCNT_BITS-1:0] 13010wcnt
12834set_axi_wr_cache_mode
[31:0] 13024debug_dma_h2d
12986afi_wvalid_abortwire