blob: 1a2dc469adf89fec71feedabaa8b9f817e4c5847 [file] [log] [blame]
Timothy Chenff4a7702020-10-27 15:08:53 -07001// Copyright lowRISC contributors.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4//
5// Flash Controller Module
6//
7//
8
9`include "prim_assert.sv"
10
Rupert Swarbrick21d6e5b2021-03-18 09:07:35 +000011module flash_ctrl
12 import flash_ctrl_pkg::*;
13 import flash_ctrl_reg_pkg::*;
14#(
15 parameter logic [NumAlerts-1:0] AlertAsyncOn = {NumAlerts{1'b1}},
16 parameter flash_key_t RndCnstAddrKey = RndCnstAddrKeyDefault,
17 parameter flash_key_t RndCnstDataKey = RndCnstDataKeyDefault,
18 parameter lfsr_seed_t RndCnstLfsrSeed = RndCnstLfsrSeedDefault,
19 parameter lfsr_perm_t RndCnstLfsrPerm = RndCnstLfsrPermDefault
Timothy Chenf52a4612020-12-04 20:37:49 -080020) (
Timothy Chenff4a7702020-10-27 15:08:53 -070021 input clk_i,
22 input rst_ni,
Timothy Chen3adcbce2021-09-20 16:48:38 -070023 input rst_shadowed_ni,
Timothy Chenff4a7702020-10-27 15:08:53 -070024
Timothy Chenf52a4612020-12-04 20:37:49 -080025 input clk_otp_i,
26 input rst_otp_ni,
27
Timothy Chen8ea1b412020-11-18 18:32:08 -080028 // life cycle interface
Timothy Chen99f3e3a2020-12-09 18:30:19 -080029 input lc_ctrl_pkg::lc_tx_t lc_creator_seed_sw_rw_en_i,
30 input lc_ctrl_pkg::lc_tx_t lc_owner_seed_sw_rw_en_i,
31 input lc_ctrl_pkg::lc_tx_t lc_iso_part_sw_rd_en_i,
32 input lc_ctrl_pkg::lc_tx_t lc_iso_part_sw_wr_en_i,
33 input lc_ctrl_pkg::lc_tx_t lc_seed_hw_rd_en_i,
Timothy Chenef5b0762021-06-17 18:19:35 -070034 input lc_ctrl_pkg::lc_tx_t lc_escalate_en_i,
Timothy Chenfb8a7842021-08-20 00:23:47 -070035 input lc_ctrl_pkg::lc_tx_t lc_nvm_debug_en_i,
Timothy Chen8ea1b412020-11-18 18:32:08 -080036
Timothy Chenff4a7702020-10-27 15:08:53 -070037 // Bus Interface
Timothy Chen8adb20d2021-03-25 16:49:04 -070038 input tlul_pkg::tl_h2d_t core_tl_i,
39 output tlul_pkg::tl_d2h_t core_tl_o,
40 input tlul_pkg::tl_h2d_t prim_tl_i,
41 output tlul_pkg::tl_d2h_t prim_tl_o,
Timothy Chenfb8a7842021-08-20 00:23:47 -070042 input tlul_pkg::tl_h2d_t mem_tl_i,
43 output tlul_pkg::tl_d2h_t mem_tl_o,
Timothy Chenff4a7702020-10-27 15:08:53 -070044
45 // otp/lc/pwrmgr/keymgr Interface
Timothy Chenf52a4612020-12-04 20:37:49 -080046 output otp_ctrl_pkg::flash_otp_key_req_t otp_o,
47 input otp_ctrl_pkg::flash_otp_key_rsp_t otp_i,
Timothy Chend39402a2020-12-15 20:34:09 -080048 input lc_ctrl_pkg::lc_tx_t rma_req_i,
49 input lc_ctrl_pkg::lc_flash_rma_seed_t rma_seed_i,
50 output lc_ctrl_pkg::lc_tx_t rma_ack_o,
Timothy Chen6efde1e2021-04-16 15:39:23 -070051 output pwrmgr_pkg::pwr_flash_t pwrmgr_o,
Timothy Chenff4a7702020-10-27 15:08:53 -070052 output keymgr_flash_t keymgr_o,
53
Timothy Chend8fded82021-02-22 11:32:55 -080054 // IOs
55 input cio_tck_i,
56 input cio_tms_i,
57 input cio_tdi_i,
58 output logic cio_tdo_en_o,
59 output logic cio_tdo_o,
60
Timothy Chenff4a7702020-10-27 15:08:53 -070061 // Interrupts
Timothy Chen37eec2c2021-09-15 15:31:22 -070062 output logic intr_corr_err_o, // Correctable errors encountered
Timothy Chenff4a7702020-10-27 15:08:53 -070063 output logic intr_prog_empty_o, // Program fifo is empty
64 output logic intr_prog_lvl_o, // Program fifo is empty
65 output logic intr_rd_full_o, // Read fifo is full
66 output logic intr_rd_lvl_o, // Read fifo is full
67 output logic intr_op_done_o, // Requested flash operation (wr/erase) done
Timothy Chen16741102021-01-15 17:32:13 -080068
69 // Alerts
70 input prim_alert_pkg::alert_rx_t [flash_ctrl_reg_pkg::NumAlerts-1:0] alert_rx_i,
Timothy Chenfb8a7842021-08-20 00:23:47 -070071 output prim_alert_pkg::alert_tx_t [flash_ctrl_reg_pkg::NumAlerts-1:0] alert_tx_o,
Timothy Chen16741102021-01-15 17:32:13 -080072
Timothy Chenfb8a7842021-08-20 00:23:47 -070073 // Flash test interface
74 input scan_en_i,
Timothy Chenf4d5e9a2021-11-09 13:41:04 -080075 input prim_mubi_pkg::mubi4_t scanmode_i,
Timothy Chenfb8a7842021-08-20 00:23:47 -070076 input scan_rst_ni,
Timothy Chenf4d5e9a2021-11-09 13:41:04 -080077 input prim_mubi_pkg::mubi4_t flash_bist_enable_i,
Timothy Chenfb8a7842021-08-20 00:23:47 -070078 input flash_power_down_h_i,
79 input flash_power_ready_h_i,
80 inout [1:0] flash_test_mode_a_io,
81 inout flash_test_voltage_h_io,
82 output ast_pkg::ast_dif_t flash_alert_o
Timothy Chenff4a7702020-10-27 15:08:53 -070083);
84
85 import flash_ctrl_reg_pkg::*;
Weicai Yang5aaad4e2021-11-16 23:45:28 -080086 import prim_mubi_pkg::mubi4_t;
Timothy Chenff4a7702020-10-27 15:08:53 -070087
Timothy Chen8adb20d2021-03-25 16:49:04 -070088 flash_ctrl_core_reg2hw_t reg2hw;
89 flash_ctrl_core_hw2reg_t hw2reg;
Timothy Chenff4a7702020-10-27 15:08:53 -070090
Timothy Chen8adb20d2021-03-25 16:49:04 -070091 tlul_pkg::tl_h2d_t tl_win_h2d [2];
92 tlul_pkg::tl_d2h_t tl_win_d2h [2];
Timothy Chenff4a7702020-10-27 15:08:53 -070093
94 // Register module
Timothy Chene1e0fd62021-04-07 16:13:28 -070095 logic intg_err;
Timothy Chen3adcbce2021-09-20 16:48:38 -070096 logic update_err;
97 logic storage_err;
98
Timothy Chen8adb20d2021-03-25 16:49:04 -070099 flash_ctrl_core_reg_top u_reg_core (
Timothy Chenff4a7702020-10-27 15:08:53 -0700100 .clk_i,
101 .rst_ni,
Timothy Chen3adcbce2021-09-20 16:48:38 -0700102 .rst_shadowed_ni,
Timothy Chenff4a7702020-10-27 15:08:53 -0700103
Timothy Chen8adb20d2021-03-25 16:49:04 -0700104 .tl_i(core_tl_i),
105 .tl_o(core_tl_o),
Timothy Chenff4a7702020-10-27 15:08:53 -0700106
Timothy Chen6e495182020-12-28 16:16:35 -0800107 .tl_win_o (tl_win_h2d),
108 .tl_win_i (tl_win_d2h),
Timothy Chenff4a7702020-10-27 15:08:53 -0700109
110 .reg2hw,
111 .hw2reg,
112
Timothy Chene1e0fd62021-04-07 16:13:28 -0700113 .intg_err_o (intg_err),
Timothy Chenff4a7702020-10-27 15:08:53 -0700114 .devmode_i (1'b1)
115 );
116
Timothy Chen936cc942021-09-21 10:48:19 -0700117 bank_cfg_t [NumBanks-1:0] bank_cfgs;
118 mp_region_cfg_t [MpRegions:0] region_cfgs;
119 info_page_cfg_t [NumBanks-1:0][InfoTypes-1:0][InfosPerBank-1:0] info_page_cfgs;
120
121 flash_ctrl_region_cfg u_region_cfg (
122 .clk_i,
123 .rst_ni,
124 .lc_creator_seed_sw_rw_en_i,
125 .lc_owner_seed_sw_rw_en_i,
126 .lc_iso_part_sw_wr_en_i,
127 .lc_iso_part_sw_rd_en_i,
128 .bank_cfg_i(reg2hw.mp_bank_cfg_shadowed),
129 .region_cfg_i(reg2hw.mp_region_cfg_shadowed),
130 .default_cfg_i(reg2hw.default_region_shadowed),
131% for bank in range(cfg.banks):
132 % for idx in range(cfg.info_types):
133 .bank${bank}_info${idx}_cfg_i(reg2hw.bank${bank}_info${idx}_page_cfg_shadowed),
134 % endfor
135% endfor
136 .bank_cfg_o(bank_cfgs),
137 .region_cfgs_o(region_cfgs),
138 .info_page_cfgs_o(info_page_cfgs),
139 .update_err_o(update_err),
140 .storage_err_o(storage_err)
141 );
Timothy Chen3adcbce2021-09-20 16:48:38 -0700142
Timothy Chenff4a7702020-10-27 15:08:53 -0700143 // FIFO Connections
144 logic prog_fifo_wvalid;
145 logic prog_fifo_wready;
146 logic prog_fifo_rvalid;
147 logic prog_fifo_ren;
148 logic [BusWidth-1:0] prog_fifo_wdata;
149 logic [BusWidth-1:0] prog_fifo_rdata;
150 logic [FifoDepthW-1:0] prog_fifo_depth;
151 logic rd_fifo_wready;
152 logic rd_fifo_rvalid;
153 logic rd_fifo_rready;
154 logic rd_fifo_wen;
155 logic rd_fifo_ren;
156 logic [BusWidth-1:0] rd_fifo_wdata;
157 logic [BusWidth-1:0] rd_fifo_rdata;
158 logic [FifoDepthW-1:0] rd_fifo_depth;
Timothy Chen71d98f82020-12-17 17:17:25 -0800159 logic rd_fifo_full;
Timothy Chenff4a7702020-10-27 15:08:53 -0700160
161 // Program Control Connections
162 logic prog_flash_req;
163 logic prog_flash_ovfl;
164 logic [BusAddrW-1:0] prog_flash_addr;
165 logic prog_op_valid;
166
167 // Read Control Connections
168 logic rd_flash_req;
169 logic rd_flash_ovfl;
170 logic [BusAddrW-1:0] rd_flash_addr;
Timothy Chen24798832021-08-20 16:12:12 -0700171 logic rd_op_valid;
Timothy Chenff4a7702020-10-27 15:08:53 -0700172
173 // Erase Control Connections
174 logic erase_flash_req;
175 logic [BusAddrW-1:0] erase_flash_addr;
176 flash_erase_e erase_flash_type;
Timothy Chen24798832021-08-20 16:12:12 -0700177 logic erase_op_valid;
178
Timothy Chenff4a7702020-10-27 15:08:53 -0700179 // Done / Error signaling from ctrl modules
180 logic prog_done, rd_done, erase_done;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700181 flash_ctrl_err_t prog_err, rd_err, erase_err;
182 logic [BusAddrW-1:0] prog_err_addr, rd_err_addr, erase_err_addr;
Timothy Chenff4a7702020-10-27 15:08:53 -0700183
Timothy Chend5323562020-12-02 16:10:44 -0800184 // Flash Memory Properties Connections
Timothy Chenff4a7702020-10-27 15:08:53 -0700185 logic [BusAddrW-1:0] flash_addr;
186 logic flash_req;
187 logic flash_rd_done, flash_prog_done, flash_erase_done;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700188 logic flash_mp_err;
Timothy Chenff4a7702020-10-27 15:08:53 -0700189 logic [BusWidth-1:0] flash_prog_data;
190 logic flash_prog_last;
191 flash_prog_e flash_prog_type;
192 logic [BusWidth-1:0] flash_rd_data;
193 logic flash_rd_err;
194 logic flash_phy_busy;
195 logic rd_op;
196 logic prog_op;
197 logic erase_op;
Timothy Chenff4a7702020-10-27 15:08:53 -0700198 flash_lcmgr_phase_e phase;
199
200 // Flash control arbitration connections to hardware interface
Timothy Chenf52a4612020-12-04 20:37:49 -0800201 flash_key_t addr_key;
Timothy Chene1e0fd62021-04-07 16:13:28 -0700202 flash_key_t rand_addr_key;
Timothy Chenf52a4612020-12-04 20:37:49 -0800203 flash_key_t data_key;
Timothy Chene1e0fd62021-04-07 16:13:28 -0700204 flash_key_t rand_data_key;
Timothy Chenff4a7702020-10-27 15:08:53 -0700205 flash_ctrl_reg2hw_control_reg_t hw_ctrl;
206 logic hw_req;
Timothy Chen5f4877b2021-11-30 17:39:10 -0800207 logic [BusAddrByteW-1:0] hw_addr;
Timothy Chenff4a7702020-10-27 15:08:53 -0700208 logic hw_done;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700209 flash_ctrl_err_t hw_err;
Timothy Chenff4a7702020-10-27 15:08:53 -0700210 logic hw_rvalid;
211 logic hw_rready;
Timothy Chend39402a2020-12-15 20:34:09 -0800212 logic hw_wvalid;
213 logic [BusWidth-1:0] hw_wdata;
214 logic hw_wready;
Timothy Chenff4a7702020-10-27 15:08:53 -0700215 flash_sel_e if_sel;
216 logic sw_sel;
217 flash_lcmgr_phase_e hw_phase;
Timothy Chen23a45672021-09-16 17:18:58 -0700218 logic lcmgr_err;
Timothy Chenc61a4ec2022-01-18 17:04:56 -0800219 logic arb_fsm_err;
Timothy Chenff4a7702020-10-27 15:08:53 -0700220
221 // Flash control arbitration connections to software interface
222 logic sw_ctrl_done;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700223 flash_ctrl_err_t sw_ctrl_err;
Timothy Chenff4a7702020-10-27 15:08:53 -0700224
225 // Flash control muxed connections
226 flash_ctrl_reg2hw_control_reg_t muxed_ctrl;
Timothy Chen5f4877b2021-11-30 17:39:10 -0800227 logic [BusAddrByteW-1:0] muxed_addr;
Timothy Chenff4a7702020-10-27 15:08:53 -0700228 logic op_start;
229 logic [11:0] op_num_words;
230 logic [BusAddrW-1:0] op_addr;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700231 logic [BusAddrW-1:0] ctrl_err_addr;
Timothy Chenff4a7702020-10-27 15:08:53 -0700232 flash_op_e op_type;
233 flash_part_e op_part;
234 logic [InfoTypesWidth-1:0] op_info_sel;
235 flash_erase_e op_erase_type;
236 flash_prog_e op_prog_type;
237
238 logic ctrl_init_busy;
239 logic fifo_clr;
240
241 // software tlul to flash control aribration
242 logic sw_rvalid;
243 logic adapter_rvalid;
244 logic sw_wvalid;
Timothy Chend39402a2020-12-15 20:34:09 -0800245 logic [BusWidth-1:0] sw_wdata;
Timothy Chenff4a7702020-10-27 15:08:53 -0700246 logic sw_wready;
247
248 // lfsr for local entropy usage
249 logic [31:0] rand_val;
250 logic lfsr_en;
Timothy Chend39402a2020-12-15 20:34:09 -0800251 logic lfsr_seed_en;
Timothy Chenff4a7702020-10-27 15:08:53 -0700252
Timothy Chenfb8a7842021-08-20 00:23:47 -0700253 // interface to flash phy
254 flash_rsp_t flash_phy_rsp;
255 flash_req_t flash_phy_req;
256
Timothy Chen8ea1b412020-11-18 18:32:08 -0800257 // life cycle connections
Cindy Chenf309ea52021-04-01 18:16:57 -0700258 lc_ctrl_pkg::lc_tx_t lc_seed_hw_rd_en;
Timothy Chen8ea1b412020-11-18 18:32:08 -0800259
Timothy Chen99f3e3a2020-12-09 18:30:19 -0800260 prim_lc_sync #(
261 .NumCopies(1)
262 ) u_lc_seed_hw_rd_en_sync (
263 .clk_i,
264 .rst_ni,
265 .lc_en_i(lc_seed_hw_rd_en_i),
266 .lc_en_o(lc_seed_hw_rd_en)
267 );
Timothy Chen8d923152020-12-02 18:01:28 -0800268
Timothy Chenff4a7702020-10-27 15:08:53 -0700269 prim_lfsr #(
Timothy Chenaeffadc2020-12-11 15:03:07 -0800270 .EntropyDw(EdnWidth),
Timothy Chenf52a4612020-12-04 20:37:49 -0800271 .LfsrDw(LfsrWidth),
Timothy Chenaeffadc2020-12-11 15:03:07 -0800272 .StateOutDw(LfsrWidth),
273 .DefaultSeed(RndCnstLfsrSeed),
274 .StatePermEn(1),
275 .StatePerm(RndCnstLfsrPerm)
Timothy Chenff4a7702020-10-27 15:08:53 -0700276 ) u_lfsr (
277 .clk_i,
278 .rst_ni,
Timothy Chend39402a2020-12-15 20:34:09 -0800279 .seed_en_i(lfsr_seed_en),
280 .seed_i(rma_seed_i),
Timothy Chenff4a7702020-10-27 15:08:53 -0700281 .lfsr_en_i(lfsr_en),
Timothy Chenaeffadc2020-12-11 15:03:07 -0800282 .entropy_i('0),
Timothy Chenff4a7702020-10-27 15:08:53 -0700283 .state_o(rand_val)
284 );
285
286 // flash control arbitration between softawre / harware interfaces
287 flash_ctrl_arb u_ctrl_arb (
288 .clk_i,
289 .rst_ni,
290
Timothy Chen37eec2c2021-09-15 15:31:22 -0700291 // error output shared by both interfaces
292 .ctrl_err_addr_o(ctrl_err_addr),
293
Timothy Chenff4a7702020-10-27 15:08:53 -0700294 // software interface to rd_ctrl / erase_ctrl
295 .sw_ctrl_i(reg2hw.control),
296 .sw_addr_i(reg2hw.addr.q),
297 .sw_ack_o(sw_ctrl_done),
298 .sw_err_o(sw_ctrl_err),
299
300 // software interface to rd_fifo
301 .sw_rvalid_o(sw_rvalid),
302 .sw_rready_i(adapter_rvalid),
303
304 // software interface to prog_fifo
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800305 // if prog operation not selected, software interface
306 // writes have no meaning
307 .sw_wvalid_i(sw_wvalid & prog_op_valid),
Timothy Chend39402a2020-12-15 20:34:09 -0800308 .sw_wdata_i(sw_wdata),
Timothy Chenff4a7702020-10-27 15:08:53 -0700309 .sw_wready_o(sw_wready),
310
311 // hardware interface to rd_ctrl / erase_ctrl
312 .hw_req_i(hw_req),
313 .hw_ctrl_i(hw_ctrl),
314
315 // hardware interface indicating operation phase
316 .hw_phase_i(hw_phase),
317
318 // hardware works on word address, however software expects byte address
319 .hw_addr_i(hw_addr),
320 .hw_ack_o(hw_done),
321 .hw_err_o(hw_err),
322
323 // hardware interface to rd_fifo
324 .hw_rvalid_o(hw_rvalid),
325 .hw_rready_i(hw_rready),
Timothy Chend39402a2020-12-15 20:34:09 -0800326 .hw_wvalid_i(hw_wvalid),
327 .hw_wdata_i(hw_wdata),
328 .hw_wready_o(hw_wready),
Timothy Chenff4a7702020-10-27 15:08:53 -0700329
330 // hardware interface does not talk to prog_fifo
331
332 // muxed interface to rd_ctrl / erase_ctrl
333 .muxed_ctrl_o(muxed_ctrl),
334 .muxed_addr_o(muxed_addr),
335 .prog_ack_i(prog_done),
336 .prog_err_i(prog_err),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700337 .prog_err_addr_i(prog_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700338 .rd_ack_i(rd_done),
339 .rd_err_i(rd_err),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700340 .rd_err_addr_i(rd_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700341 .erase_ack_i(erase_done),
342 .erase_err_i(erase_err),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700343 .erase_err_addr_i(erase_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700344
345 // muxed interface to rd_fifo
346 .rd_fifo_rvalid_i(rd_fifo_rvalid),
347 .rd_fifo_rready_o(rd_fifo_rready),
348
349 // muxed interface to prog_fifo
350 .prog_fifo_wvalid_o(prog_fifo_wvalid),
Timothy Chend39402a2020-12-15 20:34:09 -0800351 .prog_fifo_wdata_o(prog_fifo_wdata),
Timothy Chenff4a7702020-10-27 15:08:53 -0700352 .prog_fifo_wready_i(prog_fifo_wready),
353
354 // flash phy initilization ongoing
355 .flash_phy_busy_i(flash_phy_busy),
356
357 // clear fifos
358 .fifo_clr_o(fifo_clr),
359
360 // phase indication
361 .phase_o(phase),
362
363 // indication that sw has been selected
Timothy Chenc61a4ec2022-01-18 17:04:56 -0800364 .sel_o(if_sel),
365 .fsm_err_o(arb_fsm_err)
Timothy Chenff4a7702020-10-27 15:08:53 -0700366 );
367
368 assign op_start = muxed_ctrl.start.q;
369 assign op_num_words = muxed_ctrl.num.q;
370 assign op_erase_type = flash_erase_e'(muxed_ctrl.erase_sel.q);
371 assign op_prog_type = flash_prog_e'(muxed_ctrl.prog_sel.q);
372 assign op_addr = muxed_addr[BusByteWidth +: BusAddrW];
373 assign op_type = flash_op_e'(muxed_ctrl.op.q);
374 assign op_part = flash_part_e'(muxed_ctrl.partition_sel.q);
375 assign op_info_sel = muxed_ctrl.info_sel.q;
376 assign rd_op = op_type == FlashOpRead;
377 assign prog_op = op_type == FlashOpProgram;
378 assign erase_op = op_type == FlashOpErase;
379 assign sw_sel = if_sel == SwSel;
380
381 // hardware interface
Timothy Chenf52a4612020-12-04 20:37:49 -0800382 flash_ctrl_lcmgr #(
383 .RndCnstAddrKey(RndCnstAddrKey),
384 .RndCnstDataKey(RndCnstDataKey)
385 ) u_flash_hw_if (
Timothy Chenff4a7702020-10-27 15:08:53 -0700386 .clk_i,
387 .rst_ni,
Timothy Chenf52a4612020-12-04 20:37:49 -0800388 .clk_otp_i,
389 .rst_otp_ni,
Timothy Chenff4a7702020-10-27 15:08:53 -0700390
Timothy Chen568b2142021-04-16 13:10:43 -0700391 .init_i(reg2hw.init),
Cindy Chenf309ea52021-04-01 18:16:57 -0700392 .provision_en_i(lc_seed_hw_rd_en == lc_ctrl_pkg::On),
Timothy Chenff4a7702020-10-27 15:08:53 -0700393
394 // interface to ctrl arb control ports
395 .ctrl_o(hw_ctrl),
396 .req_o(hw_req),
397 .addr_o(hw_addr),
398 .done_i(hw_done),
399 .err_i(hw_err),
400
401 // interface to ctrl_arb data ports
402 .rready_o(hw_rready),
403 .rvalid_i(hw_rvalid),
Timothy Chend39402a2020-12-15 20:34:09 -0800404 .wready_i(hw_wready),
405 .wvalid_o(hw_wvalid),
406 .wdata_o(hw_wdata),
Timothy Chenff4a7702020-10-27 15:08:53 -0700407
408 // direct form rd_fifo
409 .rdata_i(rd_fifo_rdata),
410
411 // external rma request
Timothy Chend39402a2020-12-15 20:34:09 -0800412 .rma_req_i,
413 .rma_ack_o,
Timothy Chenff4a7702020-10-27 15:08:53 -0700414
Timothy Chenff4a7702020-10-27 15:08:53 -0700415 // outgoing seeds
416 .seeds_o(keymgr_o.seeds),
417 .seed_err_o(), // TBD hook-up to Err code register
418
419 // phase indication
420 .phase_o(hw_phase),
421
Timothy Chen6b241b32020-11-13 15:15:45 -0800422 // phy read buffer enable
Timothy Chenfb8a7842021-08-20 00:23:47 -0700423 .rd_buf_en_o(flash_phy_req.rd_buf_en),
Timothy Chen6b241b32020-11-13 15:15:45 -0800424
Timothy Chenf52a4612020-12-04 20:37:49 -0800425 // connection to otp
426 .otp_key_req_o(otp_o),
427 .otp_key_rsp_i(otp_i),
428 .addr_key_o(addr_key),
429 .data_key_o(data_key),
Timothy Chene1e0fd62021-04-07 16:13:28 -0700430 .rand_addr_key_o(rand_addr_key),
431 .rand_data_key_o(rand_data_key),
Timothy Chenf52a4612020-12-04 20:37:49 -0800432
Timothy Chenaeffadc2020-12-11 15:03:07 -0800433 // entropy interface
Timothy Chend39402a2020-12-15 20:34:09 -0800434 .edn_req_o(lfsr_seed_en),
435 .edn_ack_i(1'b1),
Timothy Chenaeffadc2020-12-11 15:03:07 -0800436 .lfsr_en_o(lfsr_en),
437 .rand_i(rand_val),
438
Timothy Chen23a45672021-09-16 17:18:58 -0700439 // error indication
440 .fatal_err_o(lcmgr_err),
441
Timothy Chenff4a7702020-10-27 15:08:53 -0700442 // init ongoing
443 .init_busy_o(ctrl_init_busy)
444 );
445
446 // Program FIFO
447 // Since the program and read FIFOs are never used at the same time, it should really be one
448 // FIFO with muxed inputs and outputs. This should be addressed once the flash integration
449 // strategy has been identified
450 assign prog_op_valid = op_start & prog_op;
451
452 tlul_adapter_sram #(
453 .SramAw(1), //address unused
454 .SramDw(BusWidth),
455 .ByteAccess(0), //flash may not support byte access
456 .ErrOnRead(1) //reads not supported
457 ) u_to_prog_fifo (
458 .clk_i,
459 .rst_ni,
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800460 .tl_i (tl_win_h2d[0]),
461 .tl_o (tl_win_d2h[0]),
Timothy Chen126c22a2021-09-30 15:51:46 -0700462 .en_ifetch_i (prim_mubi_pkg::MuBi4False),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800463 .req_o (sw_wvalid),
Timothy Chen4798f272021-03-24 17:19:42 -0700464 .req_type_o (),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800465 .gnt_i (sw_wready),
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800466 .we_o (),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800467 .addr_o (),
468 .wmask_o (),
Timothy Chen12cce142021-03-02 18:11:01 -0800469 .intg_error_o(),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800470 .wdata_o (sw_wdata),
471 .rdata_i (BusWidth'(0)),
472 .rvalid_i (1'b0),
473 .rerror_i (2'b0)
Timothy Chenff4a7702020-10-27 15:08:53 -0700474 );
475
476 prim_fifo_sync #(
477 .Width(BusWidth),
478 .Depth(FifoDepth)
479 ) u_prog_fifo (
480 .clk_i,
481 .rst_ni,
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800482 .clr_i (reg2hw.fifo_rst.q | fifo_clr | sw_ctrl_done),
483 .wvalid_i(prog_fifo_wvalid),
Timothy Chenff4a7702020-10-27 15:08:53 -0700484 .wready_o(prog_fifo_wready),
485 .wdata_i (prog_fifo_wdata),
486 .depth_o (prog_fifo_depth),
Philipp Wagner7858f3d2021-02-01 16:38:13 +0000487 .full_o (),
Timothy Chenff4a7702020-10-27 15:08:53 -0700488 .rvalid_o(prog_fifo_rvalid),
489 .rready_i(prog_fifo_ren),
490 .rdata_o (prog_fifo_rdata)
491 );
492
493 // Program handler is consumer of prog_fifo
Timothy Chenf52a4612020-12-04 20:37:49 -0800494 logic [1:0] prog_type_en;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700495 assign prog_type_en[FlashProgNormal] = flash_phy_rsp.prog_type_avail[FlashProgNormal] &
Timothy Chenf52a4612020-12-04 20:37:49 -0800496 reg2hw.prog_type_en.normal.q;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700497 assign prog_type_en[FlashProgRepair] = flash_phy_rsp.prog_type_avail[FlashProgRepair] &
Timothy Chenf52a4612020-12-04 20:37:49 -0800498 reg2hw.prog_type_en.repair.q;
Timothy Chenff4a7702020-10-27 15:08:53 -0700499 flash_ctrl_prog u_flash_ctrl_prog (
500 .clk_i,
501 .rst_ni,
502
503 // Control interface
504 .op_start_i (prog_op_valid),
505 .op_num_words_i (op_num_words),
506 .op_done_o (prog_done),
507 .op_err_o (prog_err),
508 .op_addr_i (op_addr),
Timothy Chen5f4877b2021-11-30 17:39:10 -0800509 .op_addr_oob_i ('0),
Timothy Chenff4a7702020-10-27 15:08:53 -0700510 .op_type_i (op_prog_type),
Timothy Chenf52a4612020-12-04 20:37:49 -0800511 .type_avail_i (prog_type_en),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700512 .op_err_addr_o (prog_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700513
514 // FIFO Interface
515 .data_i (prog_fifo_rdata),
516 .data_rdy_i (prog_fifo_rvalid),
517 .data_rd_o (prog_fifo_ren),
518
519 // Flash Macro Interface
520 .flash_req_o (prog_flash_req),
521 .flash_addr_o (prog_flash_addr),
522 .flash_ovfl_o (prog_flash_ovfl),
523 .flash_data_o (flash_prog_data),
524 .flash_last_o (flash_prog_last),
525 .flash_type_o (flash_prog_type),
526 .flash_done_i (flash_prog_done),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700527 // TODO, pending feedback
528 .flash_phy_err_i(flash_phy_rsp.flash_err),
529 .flash_mp_err_i (flash_mp_err)
Timothy Chenff4a7702020-10-27 15:08:53 -0700530 );
531
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800532 // a read request is seen from software but a read operation is not enabled
533 // AND there are no pending entries to read from the fifo.
Timothy Chen133ae332021-12-21 12:42:54 -0800534 // This indicates software has issued a read when it should not have.
535 //
536 // sw_sel qualification is used here to ensure the no_op condition is ignored
537 // when software is not selected through arbitration.
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800538 logic rd_no_op_d, rd_no_op_q;
Timothy Chen133ae332021-12-21 12:42:54 -0800539 assign rd_no_op_d = rd_fifo_ren & ~rd_op_valid & ~sw_rvalid & sw_sel;
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800540
Timothy Chenff4a7702020-10-27 15:08:53 -0700541 always_ff @(posedge clk_i or negedge rst_ni) begin
542 if (!rst_ni) begin
543 adapter_rvalid <= 1'b0;
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800544 rd_no_op_q <= 1'b0;
Timothy Chenff4a7702020-10-27 15:08:53 -0700545 end else begin
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800546 adapter_rvalid <= rd_fifo_ren & sw_rvalid;
547 rd_no_op_q <= rd_no_op_d;
Timothy Chenff4a7702020-10-27 15:08:53 -0700548 end
549 end
550
551 // tlul adapter represents software's access interface to flash
552 tlul_adapter_sram #(
553 .SramAw(1), //address unused
554 .SramDw(BusWidth),
555 .ByteAccess(0), //flash may not support byte access
556 .ErrOnWrite(1) //writes not supported
557 ) u_to_rd_fifo (
558 .clk_i,
559 .rst_ni,
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800560 .tl_i (tl_win_h2d[1]),
561 .tl_o (tl_win_d2h[1]),
Timothy Chen126c22a2021-09-30 15:51:46 -0700562 .en_ifetch_i (prim_mubi_pkg::MuBi4False),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800563 .req_o (rd_fifo_ren),
Timothy Chen4798f272021-03-24 17:19:42 -0700564 .req_type_o (),
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800565 // if there is no valid read operation, don't hang the
566 // bus, just let things normally return
567 .gnt_i (sw_rvalid | rd_no_op_d),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800568 .we_o (),
569 .addr_o (),
570 .wmask_o (),
571 .wdata_o (),
Timothy Chen12cce142021-03-02 18:11:01 -0800572 .intg_error_o(),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800573 .rdata_i (rd_fifo_rdata),
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800574 .rvalid_i (adapter_rvalid | rd_no_op_q),
575 .rerror_i ({rd_no_op_q, 1'b0})
Timothy Chenff4a7702020-10-27 15:08:53 -0700576 );
577
578 prim_fifo_sync #(
579 .Width(BusWidth),
580 .Depth(FifoDepth)
581 ) u_rd_fifo (
582 .clk_i,
583 .rst_ni,
584 .clr_i (reg2hw.fifo_rst.q | fifo_clr),
585 .wvalid_i(rd_fifo_wen),
586 .wready_o(rd_fifo_wready),
587 .wdata_i (rd_fifo_wdata),
Timothy Chen71d98f82020-12-17 17:17:25 -0800588 .full_o (rd_fifo_full),
Timothy Chenff4a7702020-10-27 15:08:53 -0700589 .depth_o (rd_fifo_depth),
590 .rvalid_o(rd_fifo_rvalid),
591 .rready_i(rd_fifo_rready),
592 .rdata_o (rd_fifo_rdata)
593 );
594
595 // Read handler is consumer of rd_fifo
Timothy Chen24798832021-08-20 16:12:12 -0700596 assign rd_op_valid = op_start & rd_op;
Timothy Chenff4a7702020-10-27 15:08:53 -0700597 flash_ctrl_rd u_flash_ctrl_rd (
598 .clk_i,
599 .rst_ni,
600
601 // To arbiter Interface
Timothy Chen24798832021-08-20 16:12:12 -0700602 .op_start_i (rd_op_valid),
Timothy Chenff4a7702020-10-27 15:08:53 -0700603 .op_num_words_i (op_num_words),
604 .op_done_o (rd_done),
605 .op_err_o (rd_err),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700606 .op_err_addr_o (rd_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700607 .op_addr_i (op_addr),
Timothy Chen5f4877b2021-11-30 17:39:10 -0800608 .op_addr_oob_i ('0),
Timothy Chenff4a7702020-10-27 15:08:53 -0700609
610 // FIFO Interface
611 .data_rdy_i (rd_fifo_wready),
612 .data_o (rd_fifo_wdata),
613 .data_wr_o (rd_fifo_wen),
614
615 // Flash Macro Interface
616 .flash_req_o (rd_flash_req),
617 .flash_addr_o (rd_flash_addr),
618 .flash_ovfl_o (rd_flash_ovfl),
619 .flash_data_i (flash_rd_data),
620 .flash_done_i (flash_rd_done),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700621 .flash_mp_err_i (flash_mp_err),
622 .flash_rd_err_i (flash_rd_err),
623 .flash_phy_err_i(flash_phy_rsp.flash_err)
Timothy Chenff4a7702020-10-27 15:08:53 -0700624 );
625
626 // Erase handler does not consume fifo
Timothy Chen24798832021-08-20 16:12:12 -0700627 assign erase_op_valid = op_start & erase_op;
Timothy Chenff4a7702020-10-27 15:08:53 -0700628 flash_ctrl_erase u_flash_ctrl_erase (
629 // Software Interface
Timothy Chen24798832021-08-20 16:12:12 -0700630 .op_start_i (erase_op_valid),
Timothy Chenff4a7702020-10-27 15:08:53 -0700631 .op_type_i (op_erase_type),
632 .op_done_o (erase_done),
633 .op_err_o (erase_err),
634 .op_addr_i (op_addr),
Timothy Chen5f4877b2021-11-30 17:39:10 -0800635 .op_addr_oob_i ('0),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700636 .op_err_addr_o (erase_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700637
638 // Flash Macro Interface
639 .flash_req_o (erase_flash_req),
640 .flash_addr_o (erase_flash_addr),
641 .flash_op_o (erase_flash_type),
642 .flash_done_i (flash_erase_done),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700643 .flash_mp_err_i (flash_mp_err),
644 .flash_phy_err_i(flash_phy_rsp.flash_err)
Timothy Chenff4a7702020-10-27 15:08:53 -0700645 );
646
647 // Final muxing to flash macro module
648 always_comb begin
649 unique case (op_type)
650 FlashOpRead: begin
651 flash_req = rd_flash_req;
652 flash_addr = rd_flash_addr;
653 end
654 FlashOpProgram: begin
655 flash_req = prog_flash_req;
656 flash_addr = prog_flash_addr;
657 end
658 FlashOpErase: begin
659 flash_req = erase_flash_req;
660 flash_addr = erase_flash_addr;
661 end
662 default: begin
663 flash_req = 1'b0;
664 flash_addr = '0;
665 end
666 endcase // unique case (op_type)
667 end
668
Timothy Chenff4a7702020-10-27 15:08:53 -0700669
Timothy Chenff4a7702020-10-27 15:08:53 -0700670
671 //////////////////////////////////////
Timothy Chend5323562020-12-02 16:10:44 -0800672 // Info partition properties configuration
Timothy Chenff4a7702020-10-27 15:08:53 -0700673 //////////////////////////////////////
Timothy Chenff4a7702020-10-27 15:08:53 -0700674
Timothy Chenff4a7702020-10-27 15:08:53 -0700675
676 //////////////////////////////////////
Timothy Chend5323562020-12-02 16:10:44 -0800677 // flash memory properties
Timothy Chenff4a7702020-10-27 15:08:53 -0700678 //////////////////////////////////////
679 // direct assignment since prog/rd/erase_ctrl do not make use of op_part
680 flash_part_e flash_part_sel;
681 logic [InfoTypesWidth-1:0] flash_info_sel;
682 assign flash_part_sel = op_part;
683 assign flash_info_sel = op_info_sel;
684
Timothy Chen7d051eb2020-12-11 14:06:43 -0800685 // tie off hardware clear path
686 assign hw2reg.erase_suspend.d = 1'b0;
687
Timothy Chend5323562020-12-02 16:10:44 -0800688 // Flash memory Properties
689 // Memory property is page based and thus should use phy addressing
Timothy Chenff4a7702020-10-27 15:08:53 -0700690 // This should move to flash_phy long term
691 flash_mp u_flash_mp (
692 .clk_i,
693 .rst_ni,
694
695 // arbiter interface selection
696 .if_sel_i(if_sel),
697
698 // sw configuration for data partition
699 .region_cfgs_i(region_cfgs),
Timothy Chen936cc942021-09-21 10:48:19 -0700700 .bank_cfgs_i(bank_cfgs),
Timothy Chenff4a7702020-10-27 15:08:53 -0700701
702 // sw configuration for info partition
703 .info_page_cfgs_i(info_page_cfgs),
704
705 // read / prog / erase controls
706 .req_i(flash_req),
707 .phase_i(phase),
708 .req_addr_i(flash_addr[BusAddrW-1 -: AllPagesW]),
709 .req_part_i(flash_part_sel),
710 .info_sel_i(flash_info_sel),
711 .addr_ovfl_i(rd_flash_ovfl | prog_flash_ovfl),
712 .rd_i(rd_op),
713 .prog_i(prog_op),
714 .pg_erase_i(erase_op & (erase_flash_type == FlashErasePage)),
715 .bk_erase_i(erase_op & (erase_flash_type == FlashEraseBank)),
Timothy Chen7d051eb2020-12-11 14:06:43 -0800716 .erase_suspend_i(reg2hw.erase_suspend),
717 .erase_suspend_done_o(hw2reg.erase_suspend.de),
Timothy Chenff4a7702020-10-27 15:08:53 -0700718 .rd_done_o(flash_rd_done),
719 .prog_done_o(flash_prog_done),
720 .erase_done_o(flash_erase_done),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700721 .error_o(flash_mp_err),
Timothy Chenff4a7702020-10-27 15:08:53 -0700722
723 // flash phy interface
Timothy Chenfb8a7842021-08-20 00:23:47 -0700724 .req_o(flash_phy_req.req),
725 .scramble_en_o(flash_phy_req.scramble_en),
726 .ecc_en_o(flash_phy_req.ecc_en),
727 .he_en_o(flash_phy_req.he_en),
728 .rd_o(flash_phy_req.rd),
729 .prog_o(flash_phy_req.prog),
730 .pg_erase_o(flash_phy_req.pg_erase),
731 .bk_erase_o(flash_phy_req.bk_erase),
732 .erase_suspend_o(flash_phy_req.erase_suspend),
733 .rd_done_i(flash_phy_rsp.rd_done),
734 .prog_done_i(flash_phy_rsp.prog_done),
735 .erase_done_i(flash_phy_rsp.erase_done)
Timothy Chenff4a7702020-10-27 15:08:53 -0700736 );
737
738
739 // software interface feedback
740 // most values (other than flash_phy_busy) should only update when software operations
741 // are actually selected
742 assign hw2reg.op_status.done.d = 1'b1;
743 assign hw2reg.op_status.done.de = sw_ctrl_done;
744 assign hw2reg.op_status.err.d = 1'b1;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700745 assign hw2reg.op_status.err.de = |sw_ctrl_err;
Timothy Chen71d98f82020-12-17 17:17:25 -0800746 assign hw2reg.status.rd_full.d = rd_fifo_full;
Timothy Chenff4a7702020-10-27 15:08:53 -0700747 assign hw2reg.status.rd_full.de = sw_sel;
748 assign hw2reg.status.rd_empty.d = ~rd_fifo_rvalid;
749 assign hw2reg.status.rd_empty.de = sw_sel;
750 assign hw2reg.status.prog_full.d = ~prog_fifo_wready;
751 assign hw2reg.status.prog_full.de = sw_sel;
752 assign hw2reg.status.prog_empty.d = ~prog_fifo_rvalid;
753 assign hw2reg.status.prog_empty.de = sw_sel;
754 assign hw2reg.status.init_wip.d = flash_phy_busy | ctrl_init_busy;
755 assign hw2reg.status.init_wip.de = 1'b1;
Timothy Chenff4a7702020-10-27 15:08:53 -0700756 assign hw2reg.control.start.d = 1'b0;
757 assign hw2reg.control.start.de = sw_ctrl_done;
758 // if software operation selected, based on transaction start
759 // if software operation not selected, software is free to change contents
760 assign hw2reg.ctrl_regwen.d = sw_sel ? !op_start : 1'b1;
761
762 // phy status
763 assign hw2reg.phy_status.init_wip.d = flash_phy_busy;
764 assign hw2reg.phy_status.init_wip.de = 1'b1;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700765 assign hw2reg.phy_status.prog_normal_avail.d = flash_phy_rsp.prog_type_avail[FlashProgNormal];
Timothy Chenff4a7702020-10-27 15:08:53 -0700766 assign hw2reg.phy_status.prog_normal_avail.de = 1'b1;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700767 assign hw2reg.phy_status.prog_repair_avail.d = flash_phy_rsp.prog_type_avail[FlashProgRepair];
Timothy Chenff4a7702020-10-27 15:08:53 -0700768 assign hw2reg.phy_status.prog_repair_avail.de = 1'b1;
769
770 // Flash Interface
Timothy Chenfb8a7842021-08-20 00:23:47 -0700771 assign flash_phy_req.addr = flash_addr;
772 assign flash_phy_req.part = flash_part_sel;
773 assign flash_phy_req.info_sel = flash_info_sel;
774 assign flash_phy_req.prog_type = flash_prog_type;
775 assign flash_phy_req.prog_data = flash_prog_data;
776 assign flash_phy_req.prog_last = flash_prog_last;
777 assign flash_phy_req.region_cfgs = region_cfgs;
778 assign flash_phy_req.addr_key = addr_key;
779 assign flash_phy_req.data_key = data_key;
780 assign flash_phy_req.rand_addr_key = rand_addr_key;
781 assign flash_phy_req.rand_data_key = rand_data_key;
782 assign flash_phy_req.alert_trig = reg2hw.phy_alert_cfg.alert_trig.q;
783 assign flash_phy_req.alert_ack = reg2hw.phy_alert_cfg.alert_ack.q;
784 assign flash_phy_req.jtag_req.tck = cio_tck_i;
785 assign flash_phy_req.jtag_req.tms = cio_tms_i;
786 assign flash_phy_req.jtag_req.tdi = cio_tdi_i;
787 assign flash_phy_req.jtag_req.trst_n = '0;
788 assign flash_phy_req.ecc_multi_err_en = reg2hw.phy_err_cfg.q;
789 assign flash_phy_req.intg_err = intg_err;
790 assign cio_tdo_o = flash_phy_rsp.jtag_rsp.tdo;
791 assign cio_tdo_en_o = flash_phy_rsp.jtag_rsp.tdo_oe;
792 assign flash_rd_err = flash_phy_rsp.rd_err;
793 assign flash_rd_data = flash_phy_rsp.rd_data;
794 assign flash_phy_busy = flash_phy_rsp.init_busy;
Timothy Chenff4a7702020-10-27 15:08:53 -0700795
Timothy Chend8fded82021-02-22 11:32:55 -0800796
Timothy Chenff4a7702020-10-27 15:08:53 -0700797 // Interface to pwrmgr
798 // flash is not idle as long as there is a stateful operation ongoing
799 logic flash_idle_d;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700800 assign flash_idle_d = ~(flash_phy_req.req &
801 (flash_phy_req.prog | flash_phy_req.pg_erase | flash_phy_req.bk_erase));
Timothy Chenff4a7702020-10-27 15:08:53 -0700802
803 prim_flop #(
804 .Width(1),
805 .ResetValue(1'b1)
806 ) u_reg_idle (
807 .clk_i,
808 .rst_ni,
809 .d_i(flash_idle_d),
810 .q_o(pwrmgr_o.flash_idle)
811 );
812
Timothy Chen16741102021-01-15 17:32:13 -0800813 //////////////////////////////////////
814 // Alert senders
815 //////////////////////////////////////
Timothy Chenff4a7702020-10-27 15:08:53 -0700816
Timothy Chen3adcbce2021-09-20 16:48:38 -0700817
Timothy Chen16741102021-01-15 17:32:13 -0800818 logic [NumAlerts-1:0] alert_srcs;
819 logic [NumAlerts-1:0] alert_tests;
820
Timothy Chen37eec2c2021-09-15 15:31:22 -0700821 // An excessive number of recoverable errors may also indicate an attack
Timothy Chen5302fff2021-01-22 14:36:54 -0800822 logic recov_err;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700823 assign recov_err = (sw_ctrl_done & |sw_ctrl_err) |
824 update_err;
Timothy Chen16741102021-01-15 17:32:13 -0800825
Timothy Chen37eec2c2021-09-15 15:31:22 -0700826 logic fatal_err;
827 assign fatal_err = |reg2hw.fault_status;
Timothy Chen16741102021-01-15 17:32:13 -0800828
Timothy Chen16741102021-01-15 17:32:13 -0800829
Timothy Chen37eec2c2021-09-15 15:31:22 -0700830 assign alert_srcs = { fatal_err,
Timothy Chen5302fff2021-01-22 14:36:54 -0800831 recov_err
Timothy Chen16741102021-01-15 17:32:13 -0800832 };
833
Timothy Chen37eec2c2021-09-15 15:31:22 -0700834 assign alert_tests = { reg2hw.alert_test.fatal_err.q & reg2hw.alert_test.fatal_err.qe,
835 reg2hw.alert_test.recov_err.q & reg2hw.alert_test.recov_err.qe
Timothy Chen16741102021-01-15 17:32:13 -0800836 };
837
Timothy Chen37eec2c2021-09-15 15:31:22 -0700838 localparam logic [NumAlerts-1:0] IsFatal = {1'b1, 1'b0};
Timothy Chen16741102021-01-15 17:32:13 -0800839 for (genvar i = 0; i < NumAlerts; i++) begin : gen_alert_senders
840 prim_alert_sender #(
Timothy Chene1e0fd62021-04-07 16:13:28 -0700841 .AsyncOn(AlertAsyncOn[i]),
842 .IsFatal(IsFatal[i])
Timothy Chen16741102021-01-15 17:32:13 -0800843 ) u_alert_sender (
844 .clk_i,
845 .rst_ni,
Timothy Chen06f78312021-01-20 18:43:27 -0800846 .alert_req_i(alert_srcs[i]),
847 .alert_test_i(alert_tests[i]),
Timothy Chen16741102021-01-15 17:32:13 -0800848 .alert_ack_o(),
Timothy Chen06f78312021-01-20 18:43:27 -0800849 .alert_state_o(),
Timothy Chen16741102021-01-15 17:32:13 -0800850 .alert_rx_i(alert_rx_i[i]),
851 .alert_tx_o(alert_tx_o[i])
852 );
853 end
854
Timothy Chenef5b0762021-06-17 18:19:35 -0700855 //////////////////////////////////////
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700856 // Flash Disable and execute enable
Timothy Chenef5b0762021-06-17 18:19:35 -0700857 //////////////////////////////////////
Timothy Chenef5b0762021-06-17 18:19:35 -0700858
859 lc_ctrl_pkg::lc_tx_t lc_escalate_en;
860 prim_lc_sync #(
861 .NumCopies(1)
862 ) u_lc_escalation_en_sync (
863 .clk_i,
864 .rst_ni,
865 .lc_en_i(lc_escalate_en_i),
866 .lc_en_o(lc_escalate_en)
867 );
868
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700869 // flash functional disable
870 prim_mubi_pkg::mubi4_t flash_disable;
871 assign flash_disable = lc_escalate_en == lc_ctrl_pkg::On ?
Michael Schaffner50c7af22021-10-12 11:30:13 -0700872 prim_mubi_pkg::MuBi4True :
Weicai Yang5aaad4e2021-11-16 23:45:28 -0800873 prim_mubi_pkg::mubi4_t'(reg2hw.dis.q);
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700874
875 assign flash_phy_req.flash_disable = flash_disable;
876
Timothy Chenbf6c7512022-01-13 10:41:47 -0800877 prim_mubi_pkg::mubi4_t sw_flash_exec_en;
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700878 prim_mubi_pkg::mubi4_t flash_exec_en;
Timothy Chenbf6c7512022-01-13 10:41:47 -0800879
880 assign sw_flash_exec_en = (reg2hw.exec.q == unsigned'(ExecEn)) ?
881 prim_mubi_pkg::MuBi4True :
882 prim_mubi_pkg::MuBi4False;
883
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700884 assign flash_exec_en = lc_escalate_en == lc_ctrl_pkg::On ?
Michael Schaffner50c7af22021-10-12 11:30:13 -0700885 prim_mubi_pkg::MuBi4False :
Timothy Chenbf6c7512022-01-13 10:41:47 -0800886 sw_flash_exec_en;
887
Timothy Chen16741102021-01-15 17:32:13 -0800888
889 //////////////////////////////////////
890 // Errors and Interrupts
891 //////////////////////////////////////
892
Timothy Chen37eec2c2021-09-15 15:31:22 -0700893 // all software interface errors are treated as synchronous errors
Timothy Chen37eec2c2021-09-15 15:31:22 -0700894 assign hw2reg.err_code.mp_err.d = 1'b1;
895 assign hw2reg.err_code.rd_err.d = 1'b1;
896 assign hw2reg.err_code.prog_win_err.d = 1'b1;
897 assign hw2reg.err_code.prog_type_err.d = 1'b1;
898 assign hw2reg.err_code.flash_phy_err.d = 1'b1;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700899 assign hw2reg.err_code.update_err.d = 1'b1;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700900 assign hw2reg.err_code.mp_err.de = sw_ctrl_err.mp_err;
901 assign hw2reg.err_code.rd_err.de = sw_ctrl_err.rd_err;
902 assign hw2reg.err_code.prog_win_err.de = sw_ctrl_err.prog_win_err;
903 assign hw2reg.err_code.prog_type_err.de = sw_ctrl_err.prog_type_err;
904 assign hw2reg.err_code.flash_phy_err.de = sw_ctrl_err.phy_err;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700905 assign hw2reg.err_code.update_err.de = update_err;
Timothy Chen5f4877b2021-11-30 17:39:10 -0800906 assign hw2reg.err_addr.d = {ctrl_err_addr, {BusByteWidth{1'h0}}};
Timothy Chen37eec2c2021-09-15 15:31:22 -0700907 assign hw2reg.err_addr.de = sw_ctrl_err.mp_err |
908 sw_ctrl_err.rd_err |
909 sw_ctrl_err.phy_err;
Timothy Chen16741102021-01-15 17:32:13 -0800910
Timothy Chen37eec2c2021-09-15 15:31:22 -0700911 // all hardware interface errors are considered faults
Timothy Chen37eec2c2021-09-15 15:31:22 -0700912 assign hw2reg.fault_status.mp_err.d = 1'b1;
913 assign hw2reg.fault_status.rd_err.d = 1'b1;
914 assign hw2reg.fault_status.prog_win_err.d = 1'b1;
915 assign hw2reg.fault_status.prog_type_err.d = 1'b1;
916 assign hw2reg.fault_status.flash_phy_err.d = 1'b1;
917 assign hw2reg.fault_status.reg_intg_err.d = 1'b1;
918 assign hw2reg.fault_status.phy_intg_err.d = 1'b1;
Timothy Chen23a45672021-09-16 17:18:58 -0700919 assign hw2reg.fault_status.lcmgr_err.d = 1'b1;
Timothy Chenc61a4ec2022-01-18 17:04:56 -0800920 assign hw2reg.fault_status.arb_fsm_err.d = 1'b1;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700921 assign hw2reg.fault_status.storage_err.d = 1'b1;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700922 assign hw2reg.fault_status.mp_err.de = hw_err.mp_err;
923 assign hw2reg.fault_status.rd_err.de = hw_err.rd_err;
924 assign hw2reg.fault_status.prog_win_err.de = hw_err.prog_win_err;
925 assign hw2reg.fault_status.prog_type_err.de = hw_err.prog_type_err;
926 assign hw2reg.fault_status.flash_phy_err.de = hw_err.phy_err;
927 assign hw2reg.fault_status.reg_intg_err.de = intg_err;
928 assign hw2reg.fault_status.phy_intg_err.de = flash_phy_rsp.intg_err;
Timothy Chen23a45672021-09-16 17:18:58 -0700929 assign hw2reg.fault_status.lcmgr_err.de = lcmgr_err;
Timothy Chenc61a4ec2022-01-18 17:04:56 -0800930 assign hw2reg.fault_status.arb_fsm_err.de = arb_fsm_err;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700931 assign hw2reg.fault_status.storage_err.de = storage_err;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700932
933 // Correctable ECC count / address
934 for (genvar i = 0; i < NumBanks; i++) begin : gen_ecc_single_err_reg
935 assign hw2reg.ecc_single_err_cnt[i].de = flash_phy_rsp.ecc_single_err[i];
936 assign hw2reg.ecc_single_err_cnt[i].d = &reg2hw.ecc_single_err_cnt[i].q ?
937 reg2hw.ecc_single_err_cnt[i].q :
938 reg2hw.ecc_single_err_cnt[i].q + 1'b1;
939
940 assign hw2reg.ecc_single_err_addr[i].de = flash_phy_rsp.ecc_single_err[i];
941 assign hw2reg.ecc_single_err_addr[i].d = {flash_phy_rsp.ecc_addr[i], {BusByteWidth{1'b0}}};
Timothy Chen16741102021-01-15 17:32:13 -0800942 end
943
Timothy Chen4798f272021-03-24 17:19:42 -0700944 // general interrupt events
Timothy Chen37eec2c2021-09-15 15:31:22 -0700945 logic [LastIntrIdx-1:0] intr_event;
Timothy Chen4798f272021-03-24 17:19:42 -0700946
Timothy Chen37eec2c2021-09-15 15:31:22 -0700947 prim_edge_detector #(
948 .Width(1),
949 .ResetValue(1)
950 ) u_prog_empty_event (
951 .clk_i,
952 .rst_ni,
953 .d_i(~prog_fifo_rvalid),
954 .q_sync_o(),
955 .q_posedge_pulse_o(intr_event[ProgEmpty]),
956 .q_negedge_pulse_o()
957 );
Timothy Chenff4a7702020-10-27 15:08:53 -0700958
Timothy Chen37eec2c2021-09-15 15:31:22 -0700959 prim_intr_hw #(.Width(1)) u_intr_prog_empty (
960 .clk_i,
961 .rst_ni,
962 .event_intr_i (intr_event[ProgEmpty]),
963 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.prog_empty.q),
964 .reg2hw_intr_test_q_i (reg2hw.intr_test.prog_empty.q),
965 .reg2hw_intr_test_qe_i (reg2hw.intr_test.prog_empty.qe),
966 .reg2hw_intr_state_q_i (reg2hw.intr_state.prog_empty.q),
967 .hw2reg_intr_state_de_o (hw2reg.intr_state.prog_empty.de),
968 .hw2reg_intr_state_d_o (hw2reg.intr_state.prog_empty.d),
969 .intr_o (intr_prog_empty_o)
970 );
Timothy Chenff4a7702020-10-27 15:08:53 -0700971
Timothy Chen37eec2c2021-09-15 15:31:22 -0700972 prim_edge_detector #(
973 .Width(1),
974 .ResetValue(0)
975 ) u_prog_lvl_event (
976 .clk_i,
977 .rst_ni,
978 .d_i(reg2hw.fifo_lvl.prog.q == prog_fifo_depth),
979 .q_sync_o(),
980 .q_posedge_pulse_o(intr_event[ProgLvl]),
981 .q_negedge_pulse_o()
982 );
Timothy Chenff4a7702020-10-27 15:08:53 -0700983
Timothy Chen37eec2c2021-09-15 15:31:22 -0700984 prim_intr_hw #(.Width(1)) u_intr_prog_lvl (
985 .clk_i,
986 .rst_ni,
987 .event_intr_i (intr_event[ProgLvl]),
988 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.prog_lvl.q),
989 .reg2hw_intr_test_q_i (reg2hw.intr_test.prog_lvl.q),
990 .reg2hw_intr_test_qe_i (reg2hw.intr_test.prog_lvl.qe),
991 .reg2hw_intr_state_q_i (reg2hw.intr_state.prog_lvl.q),
992 .hw2reg_intr_state_de_o (hw2reg.intr_state.prog_lvl.de),
993 .hw2reg_intr_state_d_o (hw2reg.intr_state.prog_lvl.d),
994 .intr_o (intr_prog_lvl_o)
995 );
Timothy Chen4798f272021-03-24 17:19:42 -0700996
Timothy Chen37eec2c2021-09-15 15:31:22 -0700997 prim_edge_detector #(
998 .Width(1),
999 .ResetValue(0)
1000 ) u_rd_full_event (
1001 .clk_i,
1002 .rst_ni,
1003 .d_i(rd_fifo_full),
1004 .q_sync_o(),
1005 .q_posedge_pulse_o(intr_event[RdFull]),
1006 .q_negedge_pulse_o()
1007 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001008
Timothy Chen37eec2c2021-09-15 15:31:22 -07001009 prim_intr_hw #(.Width(1)) u_intr_rd_full (
1010 .clk_i,
1011 .rst_ni,
1012 .event_intr_i (intr_event[RdFull]),
1013 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.rd_full.q),
1014 .reg2hw_intr_test_q_i (reg2hw.intr_test.rd_full.q),
1015 .reg2hw_intr_test_qe_i (reg2hw.intr_test.rd_full.qe),
1016 .reg2hw_intr_state_q_i (reg2hw.intr_state.rd_full.q),
1017 .hw2reg_intr_state_de_o (hw2reg.intr_state.rd_full.de),
1018 .hw2reg_intr_state_d_o (hw2reg.intr_state.rd_full.d),
1019 .intr_o (intr_rd_full_o)
1020 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001021
Timothy Chen37eec2c2021-09-15 15:31:22 -07001022 prim_edge_detector #(
1023 .Width(1),
1024 .ResetValue(0)
1025 ) u_rd_lvl_event (
1026 .clk_i,
1027 .rst_ni,
1028 .d_i(reg2hw.fifo_lvl.rd.q == rd_fifo_depth),
1029 .q_sync_o(),
1030 .q_posedge_pulse_o(intr_event[RdLvl]),
1031 .q_negedge_pulse_o()
1032 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001033
Timothy Chen37eec2c2021-09-15 15:31:22 -07001034 prim_intr_hw #(.Width(1)) u_intr_rd_lvl (
1035 .clk_i,
1036 .rst_ni,
1037 .event_intr_i (intr_event[RdLvl]),
1038 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.rd_lvl.q),
1039 .reg2hw_intr_test_q_i (reg2hw.intr_test.rd_lvl.q),
1040 .reg2hw_intr_test_qe_i (reg2hw.intr_test.rd_lvl.qe),
1041 .reg2hw_intr_state_q_i (reg2hw.intr_state.rd_lvl.q),
1042 .hw2reg_intr_state_de_o (hw2reg.intr_state.rd_lvl.de),
1043 .hw2reg_intr_state_d_o (hw2reg.intr_state.rd_lvl.d),
1044 .intr_o (intr_rd_lvl_o)
1045 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001046
Timothy Chen37eec2c2021-09-15 15:31:22 -07001047 assign intr_event[OpDone] = sw_ctrl_done;
1048 assign intr_event[CorrErr] = |flash_phy_rsp.ecc_single_err;
Timothy Chenff4a7702020-10-27 15:08:53 -07001049
Timothy Chen37eec2c2021-09-15 15:31:22 -07001050 prim_intr_hw #(.Width(1)) u_intr_op_done (
1051 .clk_i,
1052 .rst_ni,
1053 .event_intr_i (intr_event[OpDone]),
1054 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.op_done.q),
1055 .reg2hw_intr_test_q_i (reg2hw.intr_test.op_done.q),
1056 .reg2hw_intr_test_qe_i (reg2hw.intr_test.op_done.qe),
1057 .reg2hw_intr_state_q_i (reg2hw.intr_state.op_done.q),
1058 .hw2reg_intr_state_de_o (hw2reg.intr_state.op_done.de),
1059 .hw2reg_intr_state_d_o (hw2reg.intr_state.op_done.d),
1060 .intr_o (intr_op_done_o)
1061 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001062
Timothy Chen37eec2c2021-09-15 15:31:22 -07001063 prim_intr_hw #(.Width(1)) u_intr_corr_err (
1064 .clk_i,
1065 .rst_ni,
1066 .event_intr_i (intr_event[CorrErr]),
1067 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.corr_err.q),
1068 .reg2hw_intr_test_q_i (reg2hw.intr_test.corr_err.q),
1069 .reg2hw_intr_test_qe_i (reg2hw.intr_test.corr_err.qe),
1070 .reg2hw_intr_state_q_i (reg2hw.intr_state.corr_err.q),
1071 .hw2reg_intr_state_de_o (hw2reg.intr_state.corr_err.de),
1072 .hw2reg_intr_state_d_o (hw2reg.intr_state.corr_err.d),
1073 .intr_o (intr_corr_err_o)
1074 );
Timothy Chen4798f272021-03-24 17:19:42 -07001075
Timothy Chenff4a7702020-10-27 15:08:53 -07001076 // Unused bits
1077 logic [BusByteWidth-1:0] unused_byte_sel;
Timothy Chenff4a7702020-10-27 15:08:53 -07001078 logic [top_pkg::TL_AW-1:0] unused_scratch;
1079
Timothy Chenff4a7702020-10-27 15:08:53 -07001080 // Unused signals
1081 assign unused_byte_sel = muxed_addr[BusByteWidth-1:0];
Timothy Chenff4a7702020-10-27 15:08:53 -07001082 assign unused_scratch = reg2hw.scratch;
1083
Timothy Chen1e22a4b2021-09-29 15:35:01 -07001084
Timothy Chenfb8a7842021-08-20 00:23:47 -07001085 //////////////////////////////////////
1086 // flash phy module
1087 //////////////////////////////////////
1088 logic flash_host_req;
Weicai Yang5aaad4e2021-11-16 23:45:28 -08001089 mubi4_t flash_host_instr_type;
Timothy Chenfb8a7842021-08-20 00:23:47 -07001090 logic flash_host_req_rdy;
1091 logic flash_host_req_done;
1092 logic flash_host_rderr;
1093 logic [flash_ctrl_pkg::BusWidth-1:0] flash_host_rdata;
1094 logic [flash_ctrl_pkg::BusAddrW-1:0] flash_host_addr;
1095 logic flash_host_intg_err;
1096
1097 tlul_adapter_sram #(
1098 .SramAw(BusAddrW),
1099 .SramDw(BusWidth),
1100 .Outstanding(2),
1101 .ByteAccess(0),
1102 .ErrOnWrite(1),
1103 .CmdIntgCheck(1),
1104 .EnableRspIntgGen(1),
1105 .EnableDataIntgGen(1)
1106 ) u_tl_adapter_eflash (
1107 .clk_i,
1108 .rst_ni,
1109 .tl_i (mem_tl_i),
1110 .tl_o (mem_tl_o),
Timothy Chen126c22a2021-09-30 15:51:46 -07001111 .en_ifetch_i (flash_exec_en),
Timothy Chenfb8a7842021-08-20 00:23:47 -07001112 .req_o (flash_host_req),
Timothy Chen126c22a2021-09-30 15:51:46 -07001113 .req_type_o (flash_host_instr_type),
Timothy Chenfb8a7842021-08-20 00:23:47 -07001114 .gnt_i (flash_host_req_rdy),
1115 .we_o (),
1116 .addr_o (flash_host_addr),
1117 .wdata_o (),
1118 .wmask_o (),
1119 .intg_error_o(flash_host_intg_err),
1120 .rdata_i (flash_host_rdata),
1121 .rvalid_i (flash_host_req_done),
1122 .rerror_i ({flash_host_rderr,1'b0})
1123 );
1124
1125 flash_phy u_eflash (
1126 .clk_i,
1127 .rst_ni,
1128 .host_req_i (flash_host_req),
1129 .host_intg_err_i (flash_host_intg_err),
Timothy Chen126c22a2021-09-30 15:51:46 -07001130 .host_instr_type_i (flash_host_instr_type),
Timothy Chenfb8a7842021-08-20 00:23:47 -07001131 .host_addr_i (flash_host_addr),
1132 .host_req_rdy_o (flash_host_req_rdy),
1133 .host_req_done_o (flash_host_req_done),
1134 .host_rderr_o (flash_host_rderr),
1135 .host_rdata_o (flash_host_rdata),
1136 .flash_ctrl_i (flash_phy_req),
1137 .flash_ctrl_o (flash_phy_rsp),
1138 .tl_i (prim_tl_i),
1139 .tl_o (prim_tl_o),
1140 .lc_nvm_debug_en_i,
1141 .flash_bist_enable_i,
1142 .flash_power_down_h_i,
1143 .flash_power_ready_h_i,
1144 .flash_test_mode_a_io,
1145 .flash_test_voltage_h_io,
1146 .flash_alert_o,
1147 .scanmode_i,
1148 .scan_en_i,
1149 .scan_rst_ni
1150 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001151
Timothy Chen24798832021-08-20 16:12:12 -07001152 /////////////////////////////////
Timothy Chenff4a7702020-10-27 15:08:53 -07001153 // Assertions
Timothy Chen24798832021-08-20 16:12:12 -07001154 /////////////////////////////////
1155
Timothy Chen8adb20d2021-03-25 16:49:04 -07001156 `ASSERT_KNOWN(TlDValidKnownO_A, core_tl_o.d_valid )
1157 `ASSERT_KNOWN(TlAReadyKnownO_A, core_tl_o.a_ready )
1158 `ASSERT_KNOWN(PrimTlDValidKnownO_A, prim_tl_o.d_valid )
1159 `ASSERT_KNOWN(PrimTlAReadyKnownO_A, prim_tl_o.a_ready )
Timothy Chenfb8a7842021-08-20 00:23:47 -07001160 `ASSERT_KNOWN(FlashKnownO_A, {flash_phy_req.req, flash_phy_req.rd,
1161 flash_phy_req.prog, flash_phy_req.pg_erase,
1162 flash_phy_req.bk_erase})
1163 `ASSERT_KNOWN_IF(FlashAddrKnown_A, flash_phy_req.addr, flash_phy_req.req)
1164 `ASSERT_KNOWN_IF(FlashProgKnown_A, flash_phy_req.prog_data,
1165 flash_phy_req.prog & flash_phy_req.req)
Timothy Chenff4a7702020-10-27 15:08:53 -07001166 `ASSERT_KNOWN(IntrProgEmptyKnownO_A, intr_prog_empty_o)
1167 `ASSERT_KNOWN(IntrProgLvlKnownO_A, intr_prog_lvl_o )
1168 `ASSERT_KNOWN(IntrProgRdFullKnownO_A, intr_rd_full_o )
1169 `ASSERT_KNOWN(IntrRdLvlKnownO_A, intr_rd_lvl_o )
1170 `ASSERT_KNOWN(IntrOpDoneKnownO_A, intr_op_done_o )
Timothy Chen37eec2c2021-09-15 15:31:22 -07001171 `ASSERT_KNOWN(IntrErrO_A, intr_corr_err_o )
Timothy Chenff4a7702020-10-27 15:08:53 -07001172
Timothy Chen37eec2c2021-09-15 15:31:22 -07001173 // combined indication that an operation has started
1174 // This is used only for assertions
1175 logic unused_op_valid;
1176 assign unused_op_valid = prog_op_valid | rd_op_valid | erase_op_valid;
Timothy Chen24798832021-08-20 16:12:12 -07001177
Timothy Chen24798832021-08-20 16:12:12 -07001178 // add more assertions
Weicai Yangfbf2edc2021-09-27 15:31:08 -07001179 `ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(PageCntAlertCheck_A, u_flash_hw_if.u_page_cnt,
1180 alert_tx_o[0])
1181 `ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(WordCntAlertCheck_A, u_flash_hw_if.u_word_cnt,
1182 alert_tx_o[0])
Timothy Chenc61a4ec2022-01-18 17:04:56 -08001183
1184 `ASSERT_PRIM_FSM_ERROR_TRIGGER_ALERT(LcCtrlFsmCheck_A,
1185 u_flash_hw_if.u_state_regs, alert_tx_o[0])
1186 `ASSERT_PRIM_FSM_ERROR_TRIGGER_ALERT(LcCtrlRmaFsmCheck_A,
1187 u_flash_hw_if.u_rma_state_regs, alert_tx_o[0])
1188 `ASSERT_PRIM_FSM_ERROR_TRIGGER_ALERT(ArbFsmCheck_A,
1189 u_ctrl_arb.u_state_regs, alert_tx_o[0])
Timothy Chenff4a7702020-10-27 15:08:53 -07001190endmodule