blob: 47659d40f4b0ba7bfb684b548d7936bec57a0bb5 [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 Chendb0ffc02022-02-04 15:35:32 -080029 // SEC_CM: LC_CTRL.INTERSIG.MUBI
Timothy Chen99f3e3a2020-12-09 18:30:19 -080030 input lc_ctrl_pkg::lc_tx_t lc_creator_seed_sw_rw_en_i,
31 input lc_ctrl_pkg::lc_tx_t lc_owner_seed_sw_rw_en_i,
32 input lc_ctrl_pkg::lc_tx_t lc_iso_part_sw_rd_en_i,
33 input lc_ctrl_pkg::lc_tx_t lc_iso_part_sw_wr_en_i,
34 input lc_ctrl_pkg::lc_tx_t lc_seed_hw_rd_en_i,
Timothy Chenef5b0762021-06-17 18:19:35 -070035 input lc_ctrl_pkg::lc_tx_t lc_escalate_en_i,
Timothy Chenfb8a7842021-08-20 00:23:47 -070036 input lc_ctrl_pkg::lc_tx_t lc_nvm_debug_en_i,
Timothy Chen8ea1b412020-11-18 18:32:08 -080037
Timothy Chenff4a7702020-10-27 15:08:53 -070038 // Bus Interface
Timothy Chen8adb20d2021-03-25 16:49:04 -070039 input tlul_pkg::tl_h2d_t core_tl_i,
40 output tlul_pkg::tl_d2h_t core_tl_o,
41 input tlul_pkg::tl_h2d_t prim_tl_i,
42 output tlul_pkg::tl_d2h_t prim_tl_o,
Timothy Chenfb8a7842021-08-20 00:23:47 -070043 input tlul_pkg::tl_h2d_t mem_tl_i,
44 output tlul_pkg::tl_d2h_t mem_tl_o,
Timothy Chenff4a7702020-10-27 15:08:53 -070045
46 // otp/lc/pwrmgr/keymgr Interface
Timothy Chendb0ffc02022-02-04 15:35:32 -080047 // SEC_CM: SCRAMBLE.KEY.SIDELOAD
Timothy Chenf52a4612020-12-04 20:37:49 -080048 output otp_ctrl_pkg::flash_otp_key_req_t otp_o,
49 input otp_ctrl_pkg::flash_otp_key_rsp_t otp_i,
Timothy Chend39402a2020-12-15 20:34:09 -080050 input lc_ctrl_pkg::lc_tx_t rma_req_i,
51 input lc_ctrl_pkg::lc_flash_rma_seed_t rma_seed_i,
52 output lc_ctrl_pkg::lc_tx_t rma_ack_o,
Timothy Chen6efde1e2021-04-16 15:39:23 -070053 output pwrmgr_pkg::pwr_flash_t pwrmgr_o,
Timothy Chenff4a7702020-10-27 15:08:53 -070054 output keymgr_flash_t keymgr_o,
55
Timothy Chend8fded82021-02-22 11:32:55 -080056 // IOs
57 input cio_tck_i,
58 input cio_tms_i,
59 input cio_tdi_i,
60 output logic cio_tdo_en_o,
61 output logic cio_tdo_o,
62
Timothy Chenff4a7702020-10-27 15:08:53 -070063 // Interrupts
Timothy Chen37eec2c2021-09-15 15:31:22 -070064 output logic intr_corr_err_o, // Correctable errors encountered
Timothy Chenff4a7702020-10-27 15:08:53 -070065 output logic intr_prog_empty_o, // Program fifo is empty
66 output logic intr_prog_lvl_o, // Program fifo is empty
67 output logic intr_rd_full_o, // Read fifo is full
68 output logic intr_rd_lvl_o, // Read fifo is full
69 output logic intr_op_done_o, // Requested flash operation (wr/erase) done
Timothy Chen16741102021-01-15 17:32:13 -080070
71 // Alerts
72 input prim_alert_pkg::alert_rx_t [flash_ctrl_reg_pkg::NumAlerts-1:0] alert_rx_i,
Timothy Chenfb8a7842021-08-20 00:23:47 -070073 output prim_alert_pkg::alert_tx_t [flash_ctrl_reg_pkg::NumAlerts-1:0] alert_tx_o,
Timothy Chen16741102021-01-15 17:32:13 -080074
Timothy Chenfb8a7842021-08-20 00:23:47 -070075 // Flash test interface
76 input scan_en_i,
Timothy Chenf4d5e9a2021-11-09 13:41:04 -080077 input prim_mubi_pkg::mubi4_t scanmode_i,
Timothy Chenfb8a7842021-08-20 00:23:47 -070078 input scan_rst_ni,
Timothy Chenf4d5e9a2021-11-09 13:41:04 -080079 input prim_mubi_pkg::mubi4_t flash_bist_enable_i,
Timothy Chenfb8a7842021-08-20 00:23:47 -070080 input flash_power_down_h_i,
81 input flash_power_ready_h_i,
82 inout [1:0] flash_test_mode_a_io,
83 inout flash_test_voltage_h_io,
84 output ast_pkg::ast_dif_t flash_alert_o
Timothy Chenff4a7702020-10-27 15:08:53 -070085);
86
87 import flash_ctrl_reg_pkg::*;
Weicai Yang5aaad4e2021-11-16 23:45:28 -080088 import prim_mubi_pkg::mubi4_t;
Timothy Chenff4a7702020-10-27 15:08:53 -070089
Timothy Chen8adb20d2021-03-25 16:49:04 -070090 flash_ctrl_core_reg2hw_t reg2hw;
91 flash_ctrl_core_hw2reg_t hw2reg;
Timothy Chenff4a7702020-10-27 15:08:53 -070092
Timothy Chen8adb20d2021-03-25 16:49:04 -070093 tlul_pkg::tl_h2d_t tl_win_h2d [2];
94 tlul_pkg::tl_d2h_t tl_win_d2h [2];
Timothy Chenff4a7702020-10-27 15:08:53 -070095
96 // Register module
Timothy Chene1e0fd62021-04-07 16:13:28 -070097 logic intg_err;
Timothy Chen3adcbce2021-09-20 16:48:38 -070098 logic update_err;
99 logic storage_err;
100
Timothy Chendb0ffc02022-02-04 15:35:32 -0800101 // SEC_CM: BUS.INTEGRITY
102 // SEC_CM: CTRL.CONFIG.REGWEN
103 // SEC_CM: DATA_REGIONS.CONFIG.REGWEN, DATA_REGIONS.CONFIG.SHADOW
104 // SEC_CM: INFO_REGIONS.CONFIG.REGWEN, INFO_REGIONS.CONFIG.SHADOW
105 // SEC_CM: BANK.CONFIG.REGWEN, BANK.CONFIG.SHADOW
Timothy Chen8adb20d2021-03-25 16:49:04 -0700106 flash_ctrl_core_reg_top u_reg_core (
Timothy Chenff4a7702020-10-27 15:08:53 -0700107 .clk_i,
108 .rst_ni,
Timothy Chen3adcbce2021-09-20 16:48:38 -0700109 .rst_shadowed_ni,
Timothy Chenff4a7702020-10-27 15:08:53 -0700110
Timothy Chen8adb20d2021-03-25 16:49:04 -0700111 .tl_i(core_tl_i),
112 .tl_o(core_tl_o),
Timothy Chenff4a7702020-10-27 15:08:53 -0700113
Timothy Chen6e495182020-12-28 16:16:35 -0800114 .tl_win_o (tl_win_h2d),
115 .tl_win_i (tl_win_d2h),
Timothy Chenff4a7702020-10-27 15:08:53 -0700116
117 .reg2hw,
118 .hw2reg,
119
Timothy Chene1e0fd62021-04-07 16:13:28 -0700120 .intg_err_o (intg_err),
Timothy Chenff4a7702020-10-27 15:08:53 -0700121 .devmode_i (1'b1)
122 );
123
Timothy Chen936cc942021-09-21 10:48:19 -0700124 bank_cfg_t [NumBanks-1:0] bank_cfgs;
125 mp_region_cfg_t [MpRegions:0] region_cfgs;
126 info_page_cfg_t [NumBanks-1:0][InfoTypes-1:0][InfosPerBank-1:0] info_page_cfgs;
127
128 flash_ctrl_region_cfg u_region_cfg (
129 .clk_i,
130 .rst_ni,
131 .lc_creator_seed_sw_rw_en_i,
132 .lc_owner_seed_sw_rw_en_i,
133 .lc_iso_part_sw_wr_en_i,
134 .lc_iso_part_sw_rd_en_i,
135 .bank_cfg_i(reg2hw.mp_bank_cfg_shadowed),
136 .region_cfg_i(reg2hw.mp_region_cfg_shadowed),
137 .default_cfg_i(reg2hw.default_region_shadowed),
138% for bank in range(cfg.banks):
139 % for idx in range(cfg.info_types):
140 .bank${bank}_info${idx}_cfg_i(reg2hw.bank${bank}_info${idx}_page_cfg_shadowed),
141 % endfor
142% endfor
143 .bank_cfg_o(bank_cfgs),
144 .region_cfgs_o(region_cfgs),
145 .info_page_cfgs_o(info_page_cfgs),
146 .update_err_o(update_err),
147 .storage_err_o(storage_err)
148 );
Timothy Chen3adcbce2021-09-20 16:48:38 -0700149
Timothy Chenff4a7702020-10-27 15:08:53 -0700150 // FIFO Connections
151 logic prog_fifo_wvalid;
152 logic prog_fifo_wready;
153 logic prog_fifo_rvalid;
154 logic prog_fifo_ren;
155 logic [BusWidth-1:0] prog_fifo_wdata;
156 logic [BusWidth-1:0] prog_fifo_rdata;
157 logic [FifoDepthW-1:0] prog_fifo_depth;
158 logic rd_fifo_wready;
159 logic rd_fifo_rvalid;
160 logic rd_fifo_rready;
161 logic rd_fifo_wen;
162 logic rd_fifo_ren;
163 logic [BusWidth-1:0] rd_fifo_wdata;
164 logic [BusWidth-1:0] rd_fifo_rdata;
165 logic [FifoDepthW-1:0] rd_fifo_depth;
Timothy Chen71d98f82020-12-17 17:17:25 -0800166 logic rd_fifo_full;
Timothy Chenff4a7702020-10-27 15:08:53 -0700167
168 // Program Control Connections
169 logic prog_flash_req;
170 logic prog_flash_ovfl;
171 logic [BusAddrW-1:0] prog_flash_addr;
172 logic prog_op_valid;
173
174 // Read Control Connections
175 logic rd_flash_req;
176 logic rd_flash_ovfl;
177 logic [BusAddrW-1:0] rd_flash_addr;
Timothy Chen24798832021-08-20 16:12:12 -0700178 logic rd_op_valid;
Timothy Chenff4a7702020-10-27 15:08:53 -0700179
180 // Erase Control Connections
181 logic erase_flash_req;
182 logic [BusAddrW-1:0] erase_flash_addr;
183 flash_erase_e erase_flash_type;
Timothy Chen24798832021-08-20 16:12:12 -0700184 logic erase_op_valid;
185
Timothy Chenff4a7702020-10-27 15:08:53 -0700186 // Done / Error signaling from ctrl modules
187 logic prog_done, rd_done, erase_done;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700188 flash_ctrl_err_t prog_err, rd_err, erase_err;
189 logic [BusAddrW-1:0] prog_err_addr, rd_err_addr, erase_err_addr;
Timothy Chenff4a7702020-10-27 15:08:53 -0700190
Timothy Chend5323562020-12-02 16:10:44 -0800191 // Flash Memory Properties Connections
Timothy Chenff4a7702020-10-27 15:08:53 -0700192 logic [BusAddrW-1:0] flash_addr;
193 logic flash_req;
194 logic flash_rd_done, flash_prog_done, flash_erase_done;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700195 logic flash_mp_err;
Timothy Chenff4a7702020-10-27 15:08:53 -0700196 logic [BusWidth-1:0] flash_prog_data;
197 logic flash_prog_last;
198 flash_prog_e flash_prog_type;
199 logic [BusWidth-1:0] flash_rd_data;
200 logic flash_rd_err;
201 logic flash_phy_busy;
202 logic rd_op;
203 logic prog_op;
204 logic erase_op;
Timothy Chenff4a7702020-10-27 15:08:53 -0700205 flash_lcmgr_phase_e phase;
206
207 // Flash control arbitration connections to hardware interface
Timothy Chenf52a4612020-12-04 20:37:49 -0800208 flash_key_t addr_key;
Timothy Chene1e0fd62021-04-07 16:13:28 -0700209 flash_key_t rand_addr_key;
Timothy Chenf52a4612020-12-04 20:37:49 -0800210 flash_key_t data_key;
Timothy Chene1e0fd62021-04-07 16:13:28 -0700211 flash_key_t rand_data_key;
Timothy Chenff4a7702020-10-27 15:08:53 -0700212 flash_ctrl_reg2hw_control_reg_t hw_ctrl;
213 logic hw_req;
Timothy Chen5f4877b2021-11-30 17:39:10 -0800214 logic [BusAddrByteW-1:0] hw_addr;
Timothy Chenff4a7702020-10-27 15:08:53 -0700215 logic hw_done;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700216 flash_ctrl_err_t hw_err;
Timothy Chenff4a7702020-10-27 15:08:53 -0700217 logic hw_rvalid;
218 logic hw_rready;
Timothy Chend39402a2020-12-15 20:34:09 -0800219 logic hw_wvalid;
220 logic [BusWidth-1:0] hw_wdata;
221 logic hw_wready;
Timothy Chenff4a7702020-10-27 15:08:53 -0700222 flash_sel_e if_sel;
223 logic sw_sel;
224 flash_lcmgr_phase_e hw_phase;
Timothy Chen23a45672021-09-16 17:18:58 -0700225 logic lcmgr_err;
Timothy Chenc61a4ec2022-01-18 17:04:56 -0800226 logic arb_fsm_err;
Timothy Chend7475c62022-02-04 13:21:37 -0800227 logic seed_err;
Timothy Chenff4a7702020-10-27 15:08:53 -0700228
229 // Flash control arbitration connections to software interface
230 logic sw_ctrl_done;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700231 flash_ctrl_err_t sw_ctrl_err;
Timothy Chenff4a7702020-10-27 15:08:53 -0700232
233 // Flash control muxed connections
234 flash_ctrl_reg2hw_control_reg_t muxed_ctrl;
Timothy Chen5f4877b2021-11-30 17:39:10 -0800235 logic [BusAddrByteW-1:0] muxed_addr;
Timothy Chenff4a7702020-10-27 15:08:53 -0700236 logic op_start;
237 logic [11:0] op_num_words;
238 logic [BusAddrW-1:0] op_addr;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700239 logic [BusAddrW-1:0] ctrl_err_addr;
Timothy Chenff4a7702020-10-27 15:08:53 -0700240 flash_op_e op_type;
241 flash_part_e op_part;
242 logic [InfoTypesWidth-1:0] op_info_sel;
243 flash_erase_e op_erase_type;
244 flash_prog_e op_prog_type;
245
246 logic ctrl_init_busy;
247 logic fifo_clr;
248
249 // software tlul to flash control aribration
250 logic sw_rvalid;
251 logic adapter_rvalid;
252 logic sw_wvalid;
Timothy Chend39402a2020-12-15 20:34:09 -0800253 logic [BusWidth-1:0] sw_wdata;
Timothy Chenff4a7702020-10-27 15:08:53 -0700254 logic sw_wready;
255
256 // lfsr for local entropy usage
257 logic [31:0] rand_val;
258 logic lfsr_en;
Timothy Chend39402a2020-12-15 20:34:09 -0800259 logic lfsr_seed_en;
Timothy Chenff4a7702020-10-27 15:08:53 -0700260
Timothy Chenfb8a7842021-08-20 00:23:47 -0700261 // interface to flash phy
262 flash_rsp_t flash_phy_rsp;
263 flash_req_t flash_phy_req;
264
Timothy Chen8ea1b412020-11-18 18:32:08 -0800265 // life cycle connections
Cindy Chenf309ea52021-04-01 18:16:57 -0700266 lc_ctrl_pkg::lc_tx_t lc_seed_hw_rd_en;
Timothy Chen8ea1b412020-11-18 18:32:08 -0800267
Timothy Chend7475c62022-02-04 13:21:37 -0800268 lc_ctrl_pkg::lc_tx_t dis_access;
269
Timothy Chen99f3e3a2020-12-09 18:30:19 -0800270 prim_lc_sync #(
271 .NumCopies(1)
272 ) u_lc_seed_hw_rd_en_sync (
273 .clk_i,
274 .rst_ni,
275 .lc_en_i(lc_seed_hw_rd_en_i),
276 .lc_en_o(lc_seed_hw_rd_en)
277 );
Timothy Chen8d923152020-12-02 18:01:28 -0800278
Timothy Chenff4a7702020-10-27 15:08:53 -0700279 prim_lfsr #(
Timothy Chenaeffadc2020-12-11 15:03:07 -0800280 .EntropyDw(EdnWidth),
Timothy Chenf52a4612020-12-04 20:37:49 -0800281 .LfsrDw(LfsrWidth),
Timothy Chenaeffadc2020-12-11 15:03:07 -0800282 .StateOutDw(LfsrWidth),
283 .DefaultSeed(RndCnstLfsrSeed),
284 .StatePermEn(1),
285 .StatePerm(RndCnstLfsrPerm)
Timothy Chenff4a7702020-10-27 15:08:53 -0700286 ) u_lfsr (
287 .clk_i,
288 .rst_ni,
Timothy Chend39402a2020-12-15 20:34:09 -0800289 .seed_en_i(lfsr_seed_en),
290 .seed_i(rma_seed_i),
Timothy Chenff4a7702020-10-27 15:08:53 -0700291 .lfsr_en_i(lfsr_en),
Timothy Chenaeffadc2020-12-11 15:03:07 -0800292 .entropy_i('0),
Timothy Chenff4a7702020-10-27 15:08:53 -0700293 .state_o(rand_val)
294 );
295
296 // flash control arbitration between softawre / harware interfaces
297 flash_ctrl_arb u_ctrl_arb (
298 .clk_i,
299 .rst_ni,
300
Timothy Chen37eec2c2021-09-15 15:31:22 -0700301 // error output shared by both interfaces
302 .ctrl_err_addr_o(ctrl_err_addr),
303
Timothy Chenff4a7702020-10-27 15:08:53 -0700304 // software interface to rd_ctrl / erase_ctrl
305 .sw_ctrl_i(reg2hw.control),
306 .sw_addr_i(reg2hw.addr.q),
307 .sw_ack_o(sw_ctrl_done),
308 .sw_err_o(sw_ctrl_err),
309
310 // software interface to rd_fifo
311 .sw_rvalid_o(sw_rvalid),
312 .sw_rready_i(adapter_rvalid),
313
314 // software interface to prog_fifo
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800315 // if prog operation not selected, software interface
316 // writes have no meaning
317 .sw_wvalid_i(sw_wvalid & prog_op_valid),
Timothy Chend39402a2020-12-15 20:34:09 -0800318 .sw_wdata_i(sw_wdata),
Timothy Chenff4a7702020-10-27 15:08:53 -0700319 .sw_wready_o(sw_wready),
320
321 // hardware interface to rd_ctrl / erase_ctrl
322 .hw_req_i(hw_req),
323 .hw_ctrl_i(hw_ctrl),
324
325 // hardware interface indicating operation phase
326 .hw_phase_i(hw_phase),
327
328 // hardware works on word address, however software expects byte address
329 .hw_addr_i(hw_addr),
330 .hw_ack_o(hw_done),
331 .hw_err_o(hw_err),
332
333 // hardware interface to rd_fifo
334 .hw_rvalid_o(hw_rvalid),
335 .hw_rready_i(hw_rready),
Timothy Chend39402a2020-12-15 20:34:09 -0800336 .hw_wvalid_i(hw_wvalid),
337 .hw_wdata_i(hw_wdata),
338 .hw_wready_o(hw_wready),
Timothy Chenff4a7702020-10-27 15:08:53 -0700339
340 // hardware interface does not talk to prog_fifo
341
342 // muxed interface to rd_ctrl / erase_ctrl
343 .muxed_ctrl_o(muxed_ctrl),
344 .muxed_addr_o(muxed_addr),
345 .prog_ack_i(prog_done),
346 .prog_err_i(prog_err),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700347 .prog_err_addr_i(prog_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700348 .rd_ack_i(rd_done),
349 .rd_err_i(rd_err),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700350 .rd_err_addr_i(rd_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700351 .erase_ack_i(erase_done),
352 .erase_err_i(erase_err),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700353 .erase_err_addr_i(erase_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700354
355 // muxed interface to rd_fifo
356 .rd_fifo_rvalid_i(rd_fifo_rvalid),
357 .rd_fifo_rready_o(rd_fifo_rready),
358
359 // muxed interface to prog_fifo
360 .prog_fifo_wvalid_o(prog_fifo_wvalid),
Timothy Chend39402a2020-12-15 20:34:09 -0800361 .prog_fifo_wdata_o(prog_fifo_wdata),
Timothy Chenff4a7702020-10-27 15:08:53 -0700362 .prog_fifo_wready_i(prog_fifo_wready),
363
364 // flash phy initilization ongoing
365 .flash_phy_busy_i(flash_phy_busy),
366
367 // clear fifos
368 .fifo_clr_o(fifo_clr),
369
370 // phase indication
371 .phase_o(phase),
372
373 // indication that sw has been selected
Timothy Chenc61a4ec2022-01-18 17:04:56 -0800374 .sel_o(if_sel),
375 .fsm_err_o(arb_fsm_err)
Timothy Chenff4a7702020-10-27 15:08:53 -0700376 );
377
378 assign op_start = muxed_ctrl.start.q;
379 assign op_num_words = muxed_ctrl.num.q;
380 assign op_erase_type = flash_erase_e'(muxed_ctrl.erase_sel.q);
381 assign op_prog_type = flash_prog_e'(muxed_ctrl.prog_sel.q);
382 assign op_addr = muxed_addr[BusByteWidth +: BusAddrW];
383 assign op_type = flash_op_e'(muxed_ctrl.op.q);
384 assign op_part = flash_part_e'(muxed_ctrl.partition_sel.q);
385 assign op_info_sel = muxed_ctrl.info_sel.q;
386 assign rd_op = op_type == FlashOpRead;
387 assign prog_op = op_type == FlashOpProgram;
388 assign erase_op = op_type == FlashOpErase;
389 assign sw_sel = if_sel == SwSel;
390
391 // hardware interface
Timothy Chenf52a4612020-12-04 20:37:49 -0800392 flash_ctrl_lcmgr #(
393 .RndCnstAddrKey(RndCnstAddrKey),
394 .RndCnstDataKey(RndCnstDataKey)
395 ) u_flash_hw_if (
Timothy Chenff4a7702020-10-27 15:08:53 -0700396 .clk_i,
397 .rst_ni,
Timothy Chenf52a4612020-12-04 20:37:49 -0800398 .clk_otp_i,
399 .rst_otp_ni,
Timothy Chenff4a7702020-10-27 15:08:53 -0700400
Timothy Chen568b2142021-04-16 13:10:43 -0700401 .init_i(reg2hw.init),
Cindy Chenf309ea52021-04-01 18:16:57 -0700402 .provision_en_i(lc_seed_hw_rd_en == lc_ctrl_pkg::On),
Timothy Chenff4a7702020-10-27 15:08:53 -0700403
404 // interface to ctrl arb control ports
405 .ctrl_o(hw_ctrl),
406 .req_o(hw_req),
407 .addr_o(hw_addr),
408 .done_i(hw_done),
409 .err_i(hw_err),
410
411 // interface to ctrl_arb data ports
412 .rready_o(hw_rready),
413 .rvalid_i(hw_rvalid),
Timothy Chend39402a2020-12-15 20:34:09 -0800414 .wready_i(hw_wready),
415 .wvalid_o(hw_wvalid),
416 .wdata_o(hw_wdata),
Timothy Chenff4a7702020-10-27 15:08:53 -0700417
418 // direct form rd_fifo
419 .rdata_i(rd_fifo_rdata),
420
421 // external rma request
Timothy Chend39402a2020-12-15 20:34:09 -0800422 .rma_req_i,
423 .rma_ack_o,
Timothy Chenff4a7702020-10-27 15:08:53 -0700424
Timothy Chenff4a7702020-10-27 15:08:53 -0700425 // outgoing seeds
426 .seeds_o(keymgr_o.seeds),
Timothy Chend7475c62022-02-04 13:21:37 -0800427 .seed_err_o(seed_err),
Timothy Chenff4a7702020-10-27 15:08:53 -0700428
429 // phase indication
430 .phase_o(hw_phase),
431
Timothy Chen6b241b32020-11-13 15:15:45 -0800432 // phy read buffer enable
Timothy Chenfb8a7842021-08-20 00:23:47 -0700433 .rd_buf_en_o(flash_phy_req.rd_buf_en),
Timothy Chen6b241b32020-11-13 15:15:45 -0800434
Timothy Chenf52a4612020-12-04 20:37:49 -0800435 // connection to otp
436 .otp_key_req_o(otp_o),
437 .otp_key_rsp_i(otp_i),
438 .addr_key_o(addr_key),
439 .data_key_o(data_key),
Timothy Chene1e0fd62021-04-07 16:13:28 -0700440 .rand_addr_key_o(rand_addr_key),
441 .rand_data_key_o(rand_data_key),
Timothy Chenf52a4612020-12-04 20:37:49 -0800442
Timothy Chenaeffadc2020-12-11 15:03:07 -0800443 // entropy interface
Timothy Chend39402a2020-12-15 20:34:09 -0800444 .edn_req_o(lfsr_seed_en),
445 .edn_ack_i(1'b1),
Timothy Chenaeffadc2020-12-11 15:03:07 -0800446 .lfsr_en_o(lfsr_en),
447 .rand_i(rand_val),
448
Timothy Chen23a45672021-09-16 17:18:58 -0700449 // error indication
450 .fatal_err_o(lcmgr_err),
451
Timothy Chend7475c62022-02-04 13:21:37 -0800452 // disable access to flash storage after rma process
453 .dis_access_o(dis_access),
454
Timothy Chenff4a7702020-10-27 15:08:53 -0700455 // init ongoing
456 .init_busy_o(ctrl_init_busy)
457 );
458
459 // Program FIFO
460 // Since the program and read FIFOs are never used at the same time, it should really be one
461 // FIFO with muxed inputs and outputs. This should be addressed once the flash integration
462 // strategy has been identified
463 assign prog_op_valid = op_start & prog_op;
464
465 tlul_adapter_sram #(
466 .SramAw(1), //address unused
467 .SramDw(BusWidth),
468 .ByteAccess(0), //flash may not support byte access
469 .ErrOnRead(1) //reads not supported
470 ) u_to_prog_fifo (
471 .clk_i,
472 .rst_ni,
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800473 .tl_i (tl_win_h2d[0]),
474 .tl_o (tl_win_d2h[0]),
Timothy Chen126c22a2021-09-30 15:51:46 -0700475 .en_ifetch_i (prim_mubi_pkg::MuBi4False),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800476 .req_o (sw_wvalid),
Timothy Chen4798f272021-03-24 17:19:42 -0700477 .req_type_o (),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800478 .gnt_i (sw_wready),
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800479 .we_o (),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800480 .addr_o (),
481 .wmask_o (),
Timothy Chen12cce142021-03-02 18:11:01 -0800482 .intg_error_o(),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800483 .wdata_o (sw_wdata),
484 .rdata_i (BusWidth'(0)),
485 .rvalid_i (1'b0),
486 .rerror_i (2'b0)
Timothy Chenff4a7702020-10-27 15:08:53 -0700487 );
488
489 prim_fifo_sync #(
490 .Width(BusWidth),
491 .Depth(FifoDepth)
492 ) u_prog_fifo (
493 .clk_i,
494 .rst_ni,
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800495 .clr_i (reg2hw.fifo_rst.q | fifo_clr | sw_ctrl_done),
496 .wvalid_i(prog_fifo_wvalid),
Timothy Chenff4a7702020-10-27 15:08:53 -0700497 .wready_o(prog_fifo_wready),
498 .wdata_i (prog_fifo_wdata),
499 .depth_o (prog_fifo_depth),
Philipp Wagner7858f3d2021-02-01 16:38:13 +0000500 .full_o (),
Timothy Chenff4a7702020-10-27 15:08:53 -0700501 .rvalid_o(prog_fifo_rvalid),
502 .rready_i(prog_fifo_ren),
503 .rdata_o (prog_fifo_rdata)
504 );
505
506 // Program handler is consumer of prog_fifo
Timothy Chenf52a4612020-12-04 20:37:49 -0800507 logic [1:0] prog_type_en;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700508 assign prog_type_en[FlashProgNormal] = flash_phy_rsp.prog_type_avail[FlashProgNormal] &
Timothy Chenf52a4612020-12-04 20:37:49 -0800509 reg2hw.prog_type_en.normal.q;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700510 assign prog_type_en[FlashProgRepair] = flash_phy_rsp.prog_type_avail[FlashProgRepair] &
Timothy Chenf52a4612020-12-04 20:37:49 -0800511 reg2hw.prog_type_en.repair.q;
Timothy Chenff4a7702020-10-27 15:08:53 -0700512 flash_ctrl_prog u_flash_ctrl_prog (
513 .clk_i,
514 .rst_ni,
515
516 // Control interface
517 .op_start_i (prog_op_valid),
518 .op_num_words_i (op_num_words),
519 .op_done_o (prog_done),
520 .op_err_o (prog_err),
521 .op_addr_i (op_addr),
Timothy Chen5f4877b2021-11-30 17:39:10 -0800522 .op_addr_oob_i ('0),
Timothy Chenff4a7702020-10-27 15:08:53 -0700523 .op_type_i (op_prog_type),
Timothy Chenf52a4612020-12-04 20:37:49 -0800524 .type_avail_i (prog_type_en),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700525 .op_err_addr_o (prog_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700526
527 // FIFO Interface
528 .data_i (prog_fifo_rdata),
529 .data_rdy_i (prog_fifo_rvalid),
530 .data_rd_o (prog_fifo_ren),
531
532 // Flash Macro Interface
533 .flash_req_o (prog_flash_req),
534 .flash_addr_o (prog_flash_addr),
535 .flash_ovfl_o (prog_flash_ovfl),
536 .flash_data_o (flash_prog_data),
537 .flash_last_o (flash_prog_last),
538 .flash_type_o (flash_prog_type),
539 .flash_done_i (flash_prog_done),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700540 .flash_phy_err_i(flash_phy_rsp.flash_err),
541 .flash_mp_err_i (flash_mp_err)
Timothy Chenff4a7702020-10-27 15:08:53 -0700542 );
543
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800544 // a read request is seen from software but a read operation is not enabled
545 // AND there are no pending entries to read from the fifo.
Timothy Chen133ae332021-12-21 12:42:54 -0800546 // This indicates software has issued a read when it should not have.
547 //
548 // sw_sel qualification is used here to ensure the no_op condition is ignored
549 // when software is not selected through arbitration.
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800550 logic rd_no_op_d, rd_no_op_q;
Timothy Chen133ae332021-12-21 12:42:54 -0800551 assign rd_no_op_d = rd_fifo_ren & ~rd_op_valid & ~sw_rvalid & sw_sel;
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800552
Timothy Chenff4a7702020-10-27 15:08:53 -0700553 always_ff @(posedge clk_i or negedge rst_ni) begin
554 if (!rst_ni) begin
555 adapter_rvalid <= 1'b0;
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800556 rd_no_op_q <= 1'b0;
Timothy Chenff4a7702020-10-27 15:08:53 -0700557 end else begin
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800558 adapter_rvalid <= rd_fifo_ren & sw_rvalid;
559 rd_no_op_q <= rd_no_op_d;
Timothy Chenff4a7702020-10-27 15:08:53 -0700560 end
561 end
562
563 // tlul adapter represents software's access interface to flash
564 tlul_adapter_sram #(
565 .SramAw(1), //address unused
566 .SramDw(BusWidth),
567 .ByteAccess(0), //flash may not support byte access
568 .ErrOnWrite(1) //writes not supported
569 ) u_to_rd_fifo (
570 .clk_i,
571 .rst_ni,
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800572 .tl_i (tl_win_h2d[1]),
573 .tl_o (tl_win_d2h[1]),
Timothy Chen126c22a2021-09-30 15:51:46 -0700574 .en_ifetch_i (prim_mubi_pkg::MuBi4False),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800575 .req_o (rd_fifo_ren),
Timothy Chen4798f272021-03-24 17:19:42 -0700576 .req_type_o (),
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800577 // if there is no valid read operation, don't hang the
578 // bus, just let things normally return
579 .gnt_i (sw_rvalid | rd_no_op_d),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800580 .we_o (),
581 .addr_o (),
582 .wmask_o (),
583 .wdata_o (),
Timothy Chen12cce142021-03-02 18:11:01 -0800584 .intg_error_o(),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800585 .rdata_i (rd_fifo_rdata),
Timothy Chenaf8e8d92021-12-02 21:11:58 -0800586 .rvalid_i (adapter_rvalid | rd_no_op_q),
587 .rerror_i ({rd_no_op_q, 1'b0})
Timothy Chenff4a7702020-10-27 15:08:53 -0700588 );
589
590 prim_fifo_sync #(
591 .Width(BusWidth),
592 .Depth(FifoDepth)
593 ) u_rd_fifo (
594 .clk_i,
595 .rst_ni,
596 .clr_i (reg2hw.fifo_rst.q | fifo_clr),
597 .wvalid_i(rd_fifo_wen),
598 .wready_o(rd_fifo_wready),
599 .wdata_i (rd_fifo_wdata),
Timothy Chen71d98f82020-12-17 17:17:25 -0800600 .full_o (rd_fifo_full),
Timothy Chenff4a7702020-10-27 15:08:53 -0700601 .depth_o (rd_fifo_depth),
602 .rvalid_o(rd_fifo_rvalid),
603 .rready_i(rd_fifo_rready),
604 .rdata_o (rd_fifo_rdata)
605 );
606
607 // Read handler is consumer of rd_fifo
Timothy Chen24798832021-08-20 16:12:12 -0700608 assign rd_op_valid = op_start & rd_op;
Timothy Chenff4a7702020-10-27 15:08:53 -0700609 flash_ctrl_rd u_flash_ctrl_rd (
610 .clk_i,
611 .rst_ni,
612
613 // To arbiter Interface
Timothy Chen24798832021-08-20 16:12:12 -0700614 .op_start_i (rd_op_valid),
Timothy Chenff4a7702020-10-27 15:08:53 -0700615 .op_num_words_i (op_num_words),
616 .op_done_o (rd_done),
617 .op_err_o (rd_err),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700618 .op_err_addr_o (rd_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700619 .op_addr_i (op_addr),
Timothy Chen5f4877b2021-11-30 17:39:10 -0800620 .op_addr_oob_i ('0),
Timothy Chenff4a7702020-10-27 15:08:53 -0700621
622 // FIFO Interface
623 .data_rdy_i (rd_fifo_wready),
624 .data_o (rd_fifo_wdata),
625 .data_wr_o (rd_fifo_wen),
626
627 // Flash Macro Interface
628 .flash_req_o (rd_flash_req),
629 .flash_addr_o (rd_flash_addr),
630 .flash_ovfl_o (rd_flash_ovfl),
631 .flash_data_i (flash_rd_data),
632 .flash_done_i (flash_rd_done),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700633 .flash_mp_err_i (flash_mp_err),
634 .flash_rd_err_i (flash_rd_err),
635 .flash_phy_err_i(flash_phy_rsp.flash_err)
Timothy Chenff4a7702020-10-27 15:08:53 -0700636 );
637
638 // Erase handler does not consume fifo
Timothy Chen24798832021-08-20 16:12:12 -0700639 assign erase_op_valid = op_start & erase_op;
Timothy Chenff4a7702020-10-27 15:08:53 -0700640 flash_ctrl_erase u_flash_ctrl_erase (
641 // Software Interface
Timothy Chen24798832021-08-20 16:12:12 -0700642 .op_start_i (erase_op_valid),
Timothy Chenff4a7702020-10-27 15:08:53 -0700643 .op_type_i (op_erase_type),
644 .op_done_o (erase_done),
645 .op_err_o (erase_err),
646 .op_addr_i (op_addr),
Timothy Chen5f4877b2021-11-30 17:39:10 -0800647 .op_addr_oob_i ('0),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700648 .op_err_addr_o (erase_err_addr),
Timothy Chenff4a7702020-10-27 15:08:53 -0700649
650 // Flash Macro Interface
651 .flash_req_o (erase_flash_req),
652 .flash_addr_o (erase_flash_addr),
653 .flash_op_o (erase_flash_type),
654 .flash_done_i (flash_erase_done),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700655 .flash_mp_err_i (flash_mp_err),
656 .flash_phy_err_i(flash_phy_rsp.flash_err)
Timothy Chenff4a7702020-10-27 15:08:53 -0700657 );
658
659 // Final muxing to flash macro module
660 always_comb begin
661 unique case (op_type)
662 FlashOpRead: begin
663 flash_req = rd_flash_req;
664 flash_addr = rd_flash_addr;
665 end
666 FlashOpProgram: begin
667 flash_req = prog_flash_req;
668 flash_addr = prog_flash_addr;
669 end
670 FlashOpErase: begin
671 flash_req = erase_flash_req;
672 flash_addr = erase_flash_addr;
673 end
674 default: begin
675 flash_req = 1'b0;
676 flash_addr = '0;
677 end
678 endcase // unique case (op_type)
679 end
680
Timothy Chenff4a7702020-10-27 15:08:53 -0700681
Timothy Chenff4a7702020-10-27 15:08:53 -0700682
683 //////////////////////////////////////
Timothy Chend5323562020-12-02 16:10:44 -0800684 // Info partition properties configuration
Timothy Chenff4a7702020-10-27 15:08:53 -0700685 //////////////////////////////////////
Timothy Chenff4a7702020-10-27 15:08:53 -0700686
Timothy Chenff4a7702020-10-27 15:08:53 -0700687
688 //////////////////////////////////////
Timothy Chend5323562020-12-02 16:10:44 -0800689 // flash memory properties
Timothy Chenff4a7702020-10-27 15:08:53 -0700690 //////////////////////////////////////
691 // direct assignment since prog/rd/erase_ctrl do not make use of op_part
692 flash_part_e flash_part_sel;
693 logic [InfoTypesWidth-1:0] flash_info_sel;
694 assign flash_part_sel = op_part;
695 assign flash_info_sel = op_info_sel;
696
Timothy Chen7d051eb2020-12-11 14:06:43 -0800697 // tie off hardware clear path
698 assign hw2reg.erase_suspend.d = 1'b0;
699
Timothy Chend5323562020-12-02 16:10:44 -0800700 // Flash memory Properties
701 // Memory property is page based and thus should use phy addressing
Timothy Chenff4a7702020-10-27 15:08:53 -0700702 // This should move to flash_phy long term
703 flash_mp u_flash_mp (
704 .clk_i,
705 .rst_ni,
706
707 // arbiter interface selection
708 .if_sel_i(if_sel),
709
710 // sw configuration for data partition
711 .region_cfgs_i(region_cfgs),
Timothy Chen936cc942021-09-21 10:48:19 -0700712 .bank_cfgs_i(bank_cfgs),
Timothy Chenff4a7702020-10-27 15:08:53 -0700713
714 // sw configuration for info partition
715 .info_page_cfgs_i(info_page_cfgs),
716
717 // read / prog / erase controls
718 .req_i(flash_req),
719 .phase_i(phase),
720 .req_addr_i(flash_addr[BusAddrW-1 -: AllPagesW]),
721 .req_part_i(flash_part_sel),
722 .info_sel_i(flash_info_sel),
723 .addr_ovfl_i(rd_flash_ovfl | prog_flash_ovfl),
724 .rd_i(rd_op),
725 .prog_i(prog_op),
726 .pg_erase_i(erase_op & (erase_flash_type == FlashErasePage)),
727 .bk_erase_i(erase_op & (erase_flash_type == FlashEraseBank)),
Timothy Chen7d051eb2020-12-11 14:06:43 -0800728 .erase_suspend_i(reg2hw.erase_suspend),
729 .erase_suspend_done_o(hw2reg.erase_suspend.de),
Timothy Chenff4a7702020-10-27 15:08:53 -0700730 .rd_done_o(flash_rd_done),
731 .prog_done_o(flash_prog_done),
732 .erase_done_o(flash_erase_done),
Timothy Chen37eec2c2021-09-15 15:31:22 -0700733 .error_o(flash_mp_err),
Timothy Chenff4a7702020-10-27 15:08:53 -0700734
735 // flash phy interface
Timothy Chenfb8a7842021-08-20 00:23:47 -0700736 .req_o(flash_phy_req.req),
737 .scramble_en_o(flash_phy_req.scramble_en),
738 .ecc_en_o(flash_phy_req.ecc_en),
739 .he_en_o(flash_phy_req.he_en),
740 .rd_o(flash_phy_req.rd),
741 .prog_o(flash_phy_req.prog),
742 .pg_erase_o(flash_phy_req.pg_erase),
743 .bk_erase_o(flash_phy_req.bk_erase),
744 .erase_suspend_o(flash_phy_req.erase_suspend),
745 .rd_done_i(flash_phy_rsp.rd_done),
746 .prog_done_i(flash_phy_rsp.prog_done),
747 .erase_done_i(flash_phy_rsp.erase_done)
Timothy Chenff4a7702020-10-27 15:08:53 -0700748 );
749
750
751 // software interface feedback
752 // most values (other than flash_phy_busy) should only update when software operations
753 // are actually selected
754 assign hw2reg.op_status.done.d = 1'b1;
755 assign hw2reg.op_status.done.de = sw_ctrl_done;
756 assign hw2reg.op_status.err.d = 1'b1;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700757 assign hw2reg.op_status.err.de = |sw_ctrl_err;
Timothy Chen71d98f82020-12-17 17:17:25 -0800758 assign hw2reg.status.rd_full.d = rd_fifo_full;
Timothy Chenff4a7702020-10-27 15:08:53 -0700759 assign hw2reg.status.rd_full.de = sw_sel;
760 assign hw2reg.status.rd_empty.d = ~rd_fifo_rvalid;
761 assign hw2reg.status.rd_empty.de = sw_sel;
762 assign hw2reg.status.prog_full.d = ~prog_fifo_wready;
763 assign hw2reg.status.prog_full.de = sw_sel;
764 assign hw2reg.status.prog_empty.d = ~prog_fifo_rvalid;
765 assign hw2reg.status.prog_empty.de = sw_sel;
766 assign hw2reg.status.init_wip.d = flash_phy_busy | ctrl_init_busy;
767 assign hw2reg.status.init_wip.de = 1'b1;
Timothy Chenff4a7702020-10-27 15:08:53 -0700768 assign hw2reg.control.start.d = 1'b0;
769 assign hw2reg.control.start.de = sw_ctrl_done;
770 // if software operation selected, based on transaction start
771 // if software operation not selected, software is free to change contents
772 assign hw2reg.ctrl_regwen.d = sw_sel ? !op_start : 1'b1;
773
774 // phy status
775 assign hw2reg.phy_status.init_wip.d = flash_phy_busy;
776 assign hw2reg.phy_status.init_wip.de = 1'b1;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700777 assign hw2reg.phy_status.prog_normal_avail.d = flash_phy_rsp.prog_type_avail[FlashProgNormal];
Timothy Chenff4a7702020-10-27 15:08:53 -0700778 assign hw2reg.phy_status.prog_normal_avail.de = 1'b1;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700779 assign hw2reg.phy_status.prog_repair_avail.d = flash_phy_rsp.prog_type_avail[FlashProgRepair];
Timothy Chenff4a7702020-10-27 15:08:53 -0700780 assign hw2reg.phy_status.prog_repair_avail.de = 1'b1;
781
782 // Flash Interface
Timothy Chenfb8a7842021-08-20 00:23:47 -0700783 assign flash_phy_req.addr = flash_addr;
784 assign flash_phy_req.part = flash_part_sel;
785 assign flash_phy_req.info_sel = flash_info_sel;
786 assign flash_phy_req.prog_type = flash_prog_type;
787 assign flash_phy_req.prog_data = flash_prog_data;
788 assign flash_phy_req.prog_last = flash_prog_last;
789 assign flash_phy_req.region_cfgs = region_cfgs;
790 assign flash_phy_req.addr_key = addr_key;
791 assign flash_phy_req.data_key = data_key;
792 assign flash_phy_req.rand_addr_key = rand_addr_key;
793 assign flash_phy_req.rand_data_key = rand_data_key;
794 assign flash_phy_req.alert_trig = reg2hw.phy_alert_cfg.alert_trig.q;
795 assign flash_phy_req.alert_ack = reg2hw.phy_alert_cfg.alert_ack.q;
796 assign flash_phy_req.jtag_req.tck = cio_tck_i;
797 assign flash_phy_req.jtag_req.tms = cio_tms_i;
798 assign flash_phy_req.jtag_req.tdi = cio_tdi_i;
799 assign flash_phy_req.jtag_req.trst_n = '0;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700800 assign flash_phy_req.intg_err = intg_err;
801 assign cio_tdo_o = flash_phy_rsp.jtag_rsp.tdo;
802 assign cio_tdo_en_o = flash_phy_rsp.jtag_rsp.tdo_oe;
803 assign flash_rd_err = flash_phy_rsp.rd_err;
804 assign flash_rd_data = flash_phy_rsp.rd_data;
805 assign flash_phy_busy = flash_phy_rsp.init_busy;
Timothy Chenff4a7702020-10-27 15:08:53 -0700806
Timothy Chend8fded82021-02-22 11:32:55 -0800807
Timothy Chenff4a7702020-10-27 15:08:53 -0700808 // Interface to pwrmgr
809 // flash is not idle as long as there is a stateful operation ongoing
810 logic flash_idle_d;
Timothy Chenfb8a7842021-08-20 00:23:47 -0700811 assign flash_idle_d = ~(flash_phy_req.req &
812 (flash_phy_req.prog | flash_phy_req.pg_erase | flash_phy_req.bk_erase));
Timothy Chenff4a7702020-10-27 15:08:53 -0700813
814 prim_flop #(
815 .Width(1),
816 .ResetValue(1'b1)
817 ) u_reg_idle (
818 .clk_i,
819 .rst_ni,
820 .d_i(flash_idle_d),
821 .q_o(pwrmgr_o.flash_idle)
822 );
823
Timothy Chen16741102021-01-15 17:32:13 -0800824 //////////////////////////////////////
825 // Alert senders
826 //////////////////////////////////////
Timothy Chenff4a7702020-10-27 15:08:53 -0700827
Timothy Chen3adcbce2021-09-20 16:48:38 -0700828
Timothy Chen16741102021-01-15 17:32:13 -0800829 logic [NumAlerts-1:0] alert_srcs;
830 logic [NumAlerts-1:0] alert_tests;
831
Timothy Chen37eec2c2021-09-15 15:31:22 -0700832 // An excessive number of recoverable errors may also indicate an attack
Timothy Chen5302fff2021-01-22 14:36:54 -0800833 logic recov_err;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700834 assign recov_err = (sw_ctrl_done & |sw_ctrl_err) |
835 update_err;
Timothy Chen16741102021-01-15 17:32:13 -0800836
Timothy Chen37eec2c2021-09-15 15:31:22 -0700837 logic fatal_err;
838 assign fatal_err = |reg2hw.fault_status;
Timothy Chen16741102021-01-15 17:32:13 -0800839
Timothy Chen16741102021-01-15 17:32:13 -0800840
Timothy Chen37eec2c2021-09-15 15:31:22 -0700841 assign alert_srcs = { fatal_err,
Timothy Chen5302fff2021-01-22 14:36:54 -0800842 recov_err
Timothy Chen16741102021-01-15 17:32:13 -0800843 };
844
Timothy Chen37eec2c2021-09-15 15:31:22 -0700845 assign alert_tests = { reg2hw.alert_test.fatal_err.q & reg2hw.alert_test.fatal_err.qe,
846 reg2hw.alert_test.recov_err.q & reg2hw.alert_test.recov_err.qe
Timothy Chen16741102021-01-15 17:32:13 -0800847 };
848
Timothy Chen37eec2c2021-09-15 15:31:22 -0700849 localparam logic [NumAlerts-1:0] IsFatal = {1'b1, 1'b0};
Timothy Chen16741102021-01-15 17:32:13 -0800850 for (genvar i = 0; i < NumAlerts; i++) begin : gen_alert_senders
851 prim_alert_sender #(
Timothy Chene1e0fd62021-04-07 16:13:28 -0700852 .AsyncOn(AlertAsyncOn[i]),
853 .IsFatal(IsFatal[i])
Timothy Chen16741102021-01-15 17:32:13 -0800854 ) u_alert_sender (
855 .clk_i,
856 .rst_ni,
Timothy Chen06f78312021-01-20 18:43:27 -0800857 .alert_req_i(alert_srcs[i]),
858 .alert_test_i(alert_tests[i]),
Timothy Chen16741102021-01-15 17:32:13 -0800859 .alert_ack_o(),
Timothy Chen06f78312021-01-20 18:43:27 -0800860 .alert_state_o(),
Timothy Chen16741102021-01-15 17:32:13 -0800861 .alert_rx_i(alert_rx_i[i]),
862 .alert_tx_o(alert_tx_o[i])
863 );
864 end
865
Timothy Chenef5b0762021-06-17 18:19:35 -0700866 //////////////////////////////////////
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700867 // Flash Disable and execute enable
Timothy Chenef5b0762021-06-17 18:19:35 -0700868 //////////////////////////////////////
Timothy Chenef5b0762021-06-17 18:19:35 -0700869
870 lc_ctrl_pkg::lc_tx_t lc_escalate_en;
871 prim_lc_sync #(
872 .NumCopies(1)
873 ) u_lc_escalation_en_sync (
874 .clk_i,
875 .rst_ni,
876 .lc_en_i(lc_escalate_en_i),
877 .lc_en_o(lc_escalate_en)
878 );
879
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700880 // flash functional disable
881 prim_mubi_pkg::mubi4_t flash_disable;
Timothy Chend7475c62022-02-04 13:21:37 -0800882 lc_ctrl_pkg::lc_tx_t lc_disable;
883 assign lc_disable = lc_ctrl_pkg::lc_tx_or(lc_escalate_en, dis_access, lc_ctrl_pkg::On);
884
885 // Normally, faults (those registered in fault_status) should also cause flash access
886 // to disable. However, most errors encountered by hardware during flash access
887 // are registered as faults (since they functionally never happen). Out of an abundance
888 // of caution for the first iteration, we will not kill flash access based on those
889 // faults immediately just in case there are unexpected corner conditions.
890 // In other words...cowardice.
Timothy Chendb0ffc02022-02-04 15:35:32 -0800891 // SEC_CM: MEM.CTRL.GLOBAL_ESC
892 // SEC_CM: MEM_DISABLE.CONFIG.MUBI
Timothy Chend7475c62022-02-04 13:21:37 -0800893 assign flash_disable = lc_ctrl_pkg::lc_tx_test_true_loose(lc_disable) ?
Michael Schaffner50c7af22021-10-12 11:30:13 -0700894 prim_mubi_pkg::MuBi4True :
Weicai Yang5aaad4e2021-11-16 23:45:28 -0800895 prim_mubi_pkg::mubi4_t'(reg2hw.dis.q);
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700896
897 assign flash_phy_req.flash_disable = flash_disable;
898
Timothy Chenbf6c7512022-01-13 10:41:47 -0800899 prim_mubi_pkg::mubi4_t sw_flash_exec_en;
Timothy Chen1e22a4b2021-09-29 15:35:01 -0700900 prim_mubi_pkg::mubi4_t flash_exec_en;
Timothy Chenbf6c7512022-01-13 10:41:47 -0800901
Timothy Chendb0ffc02022-02-04 15:35:32 -0800902 // SEC_CM: MEM_EN.CONFIG.REDUN
Timothy Chenbf6c7512022-01-13 10:41:47 -0800903 assign sw_flash_exec_en = (reg2hw.exec.q == unsigned'(ExecEn)) ?
904 prim_mubi_pkg::MuBi4True :
905 prim_mubi_pkg::MuBi4False;
906
Timothy Chendb0ffc02022-02-04 15:35:32 -0800907 assign flash_exec_en = lc_ctrl_pkg::lc_tx_test_true_loose(lc_escalate_en) ?
Michael Schaffner50c7af22021-10-12 11:30:13 -0700908 prim_mubi_pkg::MuBi4False :
Timothy Chenbf6c7512022-01-13 10:41:47 -0800909 sw_flash_exec_en;
910
Timothy Chen16741102021-01-15 17:32:13 -0800911
912 //////////////////////////////////////
913 // Errors and Interrupts
914 //////////////////////////////////////
915
Timothy Chen37eec2c2021-09-15 15:31:22 -0700916 // all software interface errors are treated as synchronous errors
Timothy Chen37eec2c2021-09-15 15:31:22 -0700917 assign hw2reg.err_code.mp_err.d = 1'b1;
918 assign hw2reg.err_code.rd_err.d = 1'b1;
919 assign hw2reg.err_code.prog_win_err.d = 1'b1;
920 assign hw2reg.err_code.prog_type_err.d = 1'b1;
921 assign hw2reg.err_code.flash_phy_err.d = 1'b1;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700922 assign hw2reg.err_code.update_err.d = 1'b1;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700923 assign hw2reg.err_code.mp_err.de = sw_ctrl_err.mp_err;
924 assign hw2reg.err_code.rd_err.de = sw_ctrl_err.rd_err;
925 assign hw2reg.err_code.prog_win_err.de = sw_ctrl_err.prog_win_err;
926 assign hw2reg.err_code.prog_type_err.de = sw_ctrl_err.prog_type_err;
927 assign hw2reg.err_code.flash_phy_err.de = sw_ctrl_err.phy_err;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700928 assign hw2reg.err_code.update_err.de = update_err;
Timothy Chen5f4877b2021-11-30 17:39:10 -0800929 assign hw2reg.err_addr.d = {ctrl_err_addr, {BusByteWidth{1'h0}}};
Timothy Chen37eec2c2021-09-15 15:31:22 -0700930 assign hw2reg.err_addr.de = sw_ctrl_err.mp_err |
931 sw_ctrl_err.rd_err |
932 sw_ctrl_err.phy_err;
Timothy Chen16741102021-01-15 17:32:13 -0800933
Timothy Chen37eec2c2021-09-15 15:31:22 -0700934 // all hardware interface errors are considered faults
Timothy Chen37eec2c2021-09-15 15:31:22 -0700935 assign hw2reg.fault_status.mp_err.d = 1'b1;
936 assign hw2reg.fault_status.rd_err.d = 1'b1;
937 assign hw2reg.fault_status.prog_win_err.d = 1'b1;
938 assign hw2reg.fault_status.prog_type_err.d = 1'b1;
939 assign hw2reg.fault_status.flash_phy_err.d = 1'b1;
940 assign hw2reg.fault_status.reg_intg_err.d = 1'b1;
941 assign hw2reg.fault_status.phy_intg_err.d = 1'b1;
Timothy Chen23a45672021-09-16 17:18:58 -0700942 assign hw2reg.fault_status.lcmgr_err.d = 1'b1;
Timothy Chenc61a4ec2022-01-18 17:04:56 -0800943 assign hw2reg.fault_status.arb_fsm_err.d = 1'b1;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700944 assign hw2reg.fault_status.storage_err.d = 1'b1;
Timothy Chend7475c62022-02-04 13:21:37 -0800945 assign hw2reg.fault_status.seed_err.d = 1'b1;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700946 assign hw2reg.fault_status.mp_err.de = hw_err.mp_err;
947 assign hw2reg.fault_status.rd_err.de = hw_err.rd_err;
948 assign hw2reg.fault_status.prog_win_err.de = hw_err.prog_win_err;
949 assign hw2reg.fault_status.prog_type_err.de = hw_err.prog_type_err;
950 assign hw2reg.fault_status.flash_phy_err.de = hw_err.phy_err;
951 assign hw2reg.fault_status.reg_intg_err.de = intg_err;
952 assign hw2reg.fault_status.phy_intg_err.de = flash_phy_rsp.intg_err;
Timothy Chen23a45672021-09-16 17:18:58 -0700953 assign hw2reg.fault_status.lcmgr_err.de = lcmgr_err;
Timothy Chenc61a4ec2022-01-18 17:04:56 -0800954 assign hw2reg.fault_status.arb_fsm_err.de = arb_fsm_err;
Timothy Chen3adcbce2021-09-20 16:48:38 -0700955 assign hw2reg.fault_status.storage_err.de = storage_err;
Timothy Chend7475c62022-02-04 13:21:37 -0800956 assign hw2reg.fault_status.seed_err.de = seed_err;
Timothy Chen37eec2c2021-09-15 15:31:22 -0700957
958 // Correctable ECC count / address
959 for (genvar i = 0; i < NumBanks; i++) begin : gen_ecc_single_err_reg
960 assign hw2reg.ecc_single_err_cnt[i].de = flash_phy_rsp.ecc_single_err[i];
961 assign hw2reg.ecc_single_err_cnt[i].d = &reg2hw.ecc_single_err_cnt[i].q ?
962 reg2hw.ecc_single_err_cnt[i].q :
963 reg2hw.ecc_single_err_cnt[i].q + 1'b1;
964
965 assign hw2reg.ecc_single_err_addr[i].de = flash_phy_rsp.ecc_single_err[i];
966 assign hw2reg.ecc_single_err_addr[i].d = {flash_phy_rsp.ecc_addr[i], {BusByteWidth{1'b0}}};
Timothy Chen16741102021-01-15 17:32:13 -0800967 end
968
Timothy Chen4798f272021-03-24 17:19:42 -0700969 // general interrupt events
Timothy Chen37eec2c2021-09-15 15:31:22 -0700970 logic [LastIntrIdx-1:0] intr_event;
Timothy Chen4798f272021-03-24 17:19:42 -0700971
Timothy Chen37eec2c2021-09-15 15:31:22 -0700972 prim_edge_detector #(
973 .Width(1),
974 .ResetValue(1)
975 ) u_prog_empty_event (
976 .clk_i,
977 .rst_ni,
978 .d_i(~prog_fifo_rvalid),
979 .q_sync_o(),
980 .q_posedge_pulse_o(intr_event[ProgEmpty]),
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_empty (
985 .clk_i,
986 .rst_ni,
987 .event_intr_i (intr_event[ProgEmpty]),
988 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.prog_empty.q),
989 .reg2hw_intr_test_q_i (reg2hw.intr_test.prog_empty.q),
990 .reg2hw_intr_test_qe_i (reg2hw.intr_test.prog_empty.qe),
991 .reg2hw_intr_state_q_i (reg2hw.intr_state.prog_empty.q),
992 .hw2reg_intr_state_de_o (hw2reg.intr_state.prog_empty.de),
993 .hw2reg_intr_state_d_o (hw2reg.intr_state.prog_empty.d),
994 .intr_o (intr_prog_empty_o)
995 );
Timothy Chenff4a7702020-10-27 15:08:53 -0700996
Timothy Chen37eec2c2021-09-15 15:31:22 -0700997 prim_edge_detector #(
998 .Width(1),
999 .ResetValue(0)
1000 ) u_prog_lvl_event (
1001 .clk_i,
1002 .rst_ni,
1003 .d_i(reg2hw.fifo_lvl.prog.q == prog_fifo_depth),
1004 .q_sync_o(),
1005 .q_posedge_pulse_o(intr_event[ProgLvl]),
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_prog_lvl (
1010 .clk_i,
1011 .rst_ni,
1012 .event_intr_i (intr_event[ProgLvl]),
1013 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.prog_lvl.q),
1014 .reg2hw_intr_test_q_i (reg2hw.intr_test.prog_lvl.q),
1015 .reg2hw_intr_test_qe_i (reg2hw.intr_test.prog_lvl.qe),
1016 .reg2hw_intr_state_q_i (reg2hw.intr_state.prog_lvl.q),
1017 .hw2reg_intr_state_de_o (hw2reg.intr_state.prog_lvl.de),
1018 .hw2reg_intr_state_d_o (hw2reg.intr_state.prog_lvl.d),
1019 .intr_o (intr_prog_lvl_o)
1020 );
Timothy Chen4798f272021-03-24 17:19:42 -07001021
Timothy Chen37eec2c2021-09-15 15:31:22 -07001022 prim_edge_detector #(
1023 .Width(1),
1024 .ResetValue(0)
1025 ) u_rd_full_event (
1026 .clk_i,
1027 .rst_ni,
1028 .d_i(rd_fifo_full),
1029 .q_sync_o(),
1030 .q_posedge_pulse_o(intr_event[RdFull]),
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_full (
1035 .clk_i,
1036 .rst_ni,
1037 .event_intr_i (intr_event[RdFull]),
1038 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.rd_full.q),
1039 .reg2hw_intr_test_q_i (reg2hw.intr_test.rd_full.q),
1040 .reg2hw_intr_test_qe_i (reg2hw.intr_test.rd_full.qe),
1041 .reg2hw_intr_state_q_i (reg2hw.intr_state.rd_full.q),
1042 .hw2reg_intr_state_de_o (hw2reg.intr_state.rd_full.de),
1043 .hw2reg_intr_state_d_o (hw2reg.intr_state.rd_full.d),
1044 .intr_o (intr_rd_full_o)
1045 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001046
Timothy Chen37eec2c2021-09-15 15:31:22 -07001047 prim_edge_detector #(
1048 .Width(1),
1049 .ResetValue(0)
1050 ) u_rd_lvl_event (
1051 .clk_i,
1052 .rst_ni,
1053 .d_i(reg2hw.fifo_lvl.rd.q == rd_fifo_depth),
1054 .q_sync_o(),
1055 .q_posedge_pulse_o(intr_event[RdLvl]),
1056 .q_negedge_pulse_o()
1057 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001058
Timothy Chen37eec2c2021-09-15 15:31:22 -07001059 prim_intr_hw #(.Width(1)) u_intr_rd_lvl (
1060 .clk_i,
1061 .rst_ni,
1062 .event_intr_i (intr_event[RdLvl]),
1063 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.rd_lvl.q),
1064 .reg2hw_intr_test_q_i (reg2hw.intr_test.rd_lvl.q),
1065 .reg2hw_intr_test_qe_i (reg2hw.intr_test.rd_lvl.qe),
1066 .reg2hw_intr_state_q_i (reg2hw.intr_state.rd_lvl.q),
1067 .hw2reg_intr_state_de_o (hw2reg.intr_state.rd_lvl.de),
1068 .hw2reg_intr_state_d_o (hw2reg.intr_state.rd_lvl.d),
1069 .intr_o (intr_rd_lvl_o)
1070 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001071
Timothy Chen37eec2c2021-09-15 15:31:22 -07001072 assign intr_event[OpDone] = sw_ctrl_done;
1073 assign intr_event[CorrErr] = |flash_phy_rsp.ecc_single_err;
Timothy Chenff4a7702020-10-27 15:08:53 -07001074
Timothy Chen37eec2c2021-09-15 15:31:22 -07001075 prim_intr_hw #(.Width(1)) u_intr_op_done (
1076 .clk_i,
1077 .rst_ni,
1078 .event_intr_i (intr_event[OpDone]),
1079 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.op_done.q),
1080 .reg2hw_intr_test_q_i (reg2hw.intr_test.op_done.q),
1081 .reg2hw_intr_test_qe_i (reg2hw.intr_test.op_done.qe),
1082 .reg2hw_intr_state_q_i (reg2hw.intr_state.op_done.q),
1083 .hw2reg_intr_state_de_o (hw2reg.intr_state.op_done.de),
1084 .hw2reg_intr_state_d_o (hw2reg.intr_state.op_done.d),
1085 .intr_o (intr_op_done_o)
1086 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001087
Timothy Chen37eec2c2021-09-15 15:31:22 -07001088 prim_intr_hw #(.Width(1)) u_intr_corr_err (
1089 .clk_i,
1090 .rst_ni,
1091 .event_intr_i (intr_event[CorrErr]),
1092 .reg2hw_intr_enable_q_i (reg2hw.intr_enable.corr_err.q),
1093 .reg2hw_intr_test_q_i (reg2hw.intr_test.corr_err.q),
1094 .reg2hw_intr_test_qe_i (reg2hw.intr_test.corr_err.qe),
1095 .reg2hw_intr_state_q_i (reg2hw.intr_state.corr_err.q),
1096 .hw2reg_intr_state_de_o (hw2reg.intr_state.corr_err.de),
1097 .hw2reg_intr_state_d_o (hw2reg.intr_state.corr_err.d),
1098 .intr_o (intr_corr_err_o)
1099 );
Timothy Chen4798f272021-03-24 17:19:42 -07001100
Timothy Chenff4a7702020-10-27 15:08:53 -07001101 // Unused bits
1102 logic [BusByteWidth-1:0] unused_byte_sel;
Timothy Chenff4a7702020-10-27 15:08:53 -07001103 logic [top_pkg::TL_AW-1:0] unused_scratch;
1104
Timothy Chenff4a7702020-10-27 15:08:53 -07001105 // Unused signals
1106 assign unused_byte_sel = muxed_addr[BusByteWidth-1:0];
Timothy Chenff4a7702020-10-27 15:08:53 -07001107 assign unused_scratch = reg2hw.scratch;
1108
Timothy Chen1e22a4b2021-09-29 15:35:01 -07001109
Timothy Chenfb8a7842021-08-20 00:23:47 -07001110 //////////////////////////////////////
1111 // flash phy module
1112 //////////////////////////////////////
1113 logic flash_host_req;
Weicai Yang5aaad4e2021-11-16 23:45:28 -08001114 mubi4_t flash_host_instr_type;
Timothy Chenfb8a7842021-08-20 00:23:47 -07001115 logic flash_host_req_rdy;
1116 logic flash_host_req_done;
1117 logic flash_host_rderr;
1118 logic [flash_ctrl_pkg::BusWidth-1:0] flash_host_rdata;
1119 logic [flash_ctrl_pkg::BusAddrW-1:0] flash_host_addr;
1120 logic flash_host_intg_err;
1121
1122 tlul_adapter_sram #(
1123 .SramAw(BusAddrW),
1124 .SramDw(BusWidth),
1125 .Outstanding(2),
1126 .ByteAccess(0),
1127 .ErrOnWrite(1),
1128 .CmdIntgCheck(1),
1129 .EnableRspIntgGen(1),
1130 .EnableDataIntgGen(1)
1131 ) u_tl_adapter_eflash (
1132 .clk_i,
1133 .rst_ni,
1134 .tl_i (mem_tl_i),
1135 .tl_o (mem_tl_o),
Timothy Chen126c22a2021-09-30 15:51:46 -07001136 .en_ifetch_i (flash_exec_en),
Timothy Chenfb8a7842021-08-20 00:23:47 -07001137 .req_o (flash_host_req),
Timothy Chen126c22a2021-09-30 15:51:46 -07001138 .req_type_o (flash_host_instr_type),
Timothy Chenfb8a7842021-08-20 00:23:47 -07001139 .gnt_i (flash_host_req_rdy),
1140 .we_o (),
1141 .addr_o (flash_host_addr),
1142 .wdata_o (),
1143 .wmask_o (),
1144 .intg_error_o(flash_host_intg_err),
1145 .rdata_i (flash_host_rdata),
1146 .rvalid_i (flash_host_req_done),
1147 .rerror_i ({flash_host_rderr,1'b0})
1148 );
1149
1150 flash_phy u_eflash (
1151 .clk_i,
1152 .rst_ni,
1153 .host_req_i (flash_host_req),
1154 .host_intg_err_i (flash_host_intg_err),
Timothy Chen126c22a2021-09-30 15:51:46 -07001155 .host_instr_type_i (flash_host_instr_type),
Timothy Chenfb8a7842021-08-20 00:23:47 -07001156 .host_addr_i (flash_host_addr),
1157 .host_req_rdy_o (flash_host_req_rdy),
1158 .host_req_done_o (flash_host_req_done),
1159 .host_rderr_o (flash_host_rderr),
1160 .host_rdata_o (flash_host_rdata),
1161 .flash_ctrl_i (flash_phy_req),
1162 .flash_ctrl_o (flash_phy_rsp),
1163 .tl_i (prim_tl_i),
1164 .tl_o (prim_tl_o),
1165 .lc_nvm_debug_en_i,
1166 .flash_bist_enable_i,
1167 .flash_power_down_h_i,
1168 .flash_power_ready_h_i,
1169 .flash_test_mode_a_io,
1170 .flash_test_voltage_h_io,
1171 .flash_alert_o,
1172 .scanmode_i,
1173 .scan_en_i,
1174 .scan_rst_ni
1175 );
Timothy Chenff4a7702020-10-27 15:08:53 -07001176
Timothy Chen24798832021-08-20 16:12:12 -07001177 /////////////////////////////////
Timothy Chenff4a7702020-10-27 15:08:53 -07001178 // Assertions
Timothy Chen24798832021-08-20 16:12:12 -07001179 /////////////////////////////////
1180
Timothy Chen8adb20d2021-03-25 16:49:04 -07001181 `ASSERT_KNOWN(TlDValidKnownO_A, core_tl_o.d_valid )
1182 `ASSERT_KNOWN(TlAReadyKnownO_A, core_tl_o.a_ready )
Timothy Chen1849c802022-01-26 16:31:37 -08001183 `ASSERT_KNOWN_IF(RspPayLoad_A, core_tl_o, core_tl_o.d_valid)
Timothy Chen8adb20d2021-03-25 16:49:04 -07001184 `ASSERT_KNOWN(PrimTlDValidKnownO_A, prim_tl_o.d_valid )
1185 `ASSERT_KNOWN(PrimTlAReadyKnownO_A, prim_tl_o.a_ready )
Timothy Chen1849c802022-01-26 16:31:37 -08001186 `ASSERT_KNOWN_IF(PrimRspPayLoad_A, prim_tl_o, prim_tl_o.d_valid)
1187 `ASSERT_KNOWN(MemTlDValidKnownO_A, mem_tl_o.d_valid )
1188 `ASSERT_KNOWN(MemTlAReadyKnownO_A, mem_tl_o.a_ready )
1189 `ASSERT_KNOWN_IF(MemRspPayLoad_A, mem_tl_o, mem_tl_o.d_valid)
Timothy Chenfb8a7842021-08-20 00:23:47 -07001190 `ASSERT_KNOWN(FlashKnownO_A, {flash_phy_req.req, flash_phy_req.rd,
1191 flash_phy_req.prog, flash_phy_req.pg_erase,
1192 flash_phy_req.bk_erase})
1193 `ASSERT_KNOWN_IF(FlashAddrKnown_A, flash_phy_req.addr, flash_phy_req.req)
1194 `ASSERT_KNOWN_IF(FlashProgKnown_A, flash_phy_req.prog_data,
1195 flash_phy_req.prog & flash_phy_req.req)
Timothy Chenff4a7702020-10-27 15:08:53 -07001196 `ASSERT_KNOWN(IntrProgEmptyKnownO_A, intr_prog_empty_o)
1197 `ASSERT_KNOWN(IntrProgLvlKnownO_A, intr_prog_lvl_o )
1198 `ASSERT_KNOWN(IntrProgRdFullKnownO_A, intr_rd_full_o )
1199 `ASSERT_KNOWN(IntrRdLvlKnownO_A, intr_rd_lvl_o )
1200 `ASSERT_KNOWN(IntrOpDoneKnownO_A, intr_op_done_o )
Timothy Chen37eec2c2021-09-15 15:31:22 -07001201 `ASSERT_KNOWN(IntrErrO_A, intr_corr_err_o )
Timothy Chenff4a7702020-10-27 15:08:53 -07001202
Timothy Chen37eec2c2021-09-15 15:31:22 -07001203 // combined indication that an operation has started
1204 // This is used only for assertions
1205 logic unused_op_valid;
1206 assign unused_op_valid = prog_op_valid | rd_op_valid | erase_op_valid;
Timothy Chen24798832021-08-20 16:12:12 -07001207
Timothy Chen24798832021-08-20 16:12:12 -07001208 // add more assertions
Weicai Yangfbf2edc2021-09-27 15:31:08 -07001209 `ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(PageCntAlertCheck_A, u_flash_hw_if.u_page_cnt,
1210 alert_tx_o[0])
1211 `ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(WordCntAlertCheck_A, u_flash_hw_if.u_word_cnt,
1212 alert_tx_o[0])
Timothy Chend7475c62022-02-04 13:21:37 -08001213 `ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(WipeIdx_A, u_flash_hw_if.u_wipe_idx_cnt,
1214 alert_tx_o[0])
Timothy Chenc61a4ec2022-01-18 17:04:56 -08001215
1216 `ASSERT_PRIM_FSM_ERROR_TRIGGER_ALERT(LcCtrlFsmCheck_A,
1217 u_flash_hw_if.u_state_regs, alert_tx_o[0])
1218 `ASSERT_PRIM_FSM_ERROR_TRIGGER_ALERT(LcCtrlRmaFsmCheck_A,
1219 u_flash_hw_if.u_rma_state_regs, alert_tx_o[0])
1220 `ASSERT_PRIM_FSM_ERROR_TRIGGER_ALERT(ArbFsmCheck_A,
1221 u_ctrl_arb.u_state_regs, alert_tx_o[0])
Timothy Chenff4a7702020-10-27 15:08:53 -07001222endmodule