[keymgr,lint] Fix minor width mismatches for round counts
Another way to define e.g. LastAdvRound this would be code like
CntWidth'(AdvRounds - 1), but I think way this is probably better
because it ensures we're slicing rather than expanding.
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/hw/ip/keymgr/rtl/keymgr_kmac_if.sv b/hw/ip/keymgr/rtl/keymgr_kmac_if.sv
index 0407cd5..d16f7aa 100644
--- a/hw/ip/keymgr/rtl/keymgr_kmac_if.sv
+++ b/hw/ip/keymgr/rtl/keymgr_kmac_if.sv
@@ -75,6 +75,13 @@
localparam int DecoyCopies = KmacDataIfWidth / 32;
localparam int DecoyOutputCopies = (KeyWidth / 32) * Shares;
+ localparam int unsigned LastAdvRoundInt = AdvRounds - 1;
+ localparam int unsigned LastIdRoundInt = IdRounds - 1;
+ localparam int unsigned LastGenRoundInt = GenRounds - 1;
+ localparam bit [CntWidth-1:0] LastAdvRound = LastAdvRoundInt[CntWidth-1:0];
+ localparam bit [CntWidth-1:0] LastIdRound = LastIdRoundInt[CntWidth-1:0];
+ localparam bit [CntWidth-1:0] LastGenRound = LastGenRoundInt[CntWidth-1:0];
+
// byte mask for the last transfer
localparam logic [IfBytes-1:0] AdvByteMask = (AdvRem > 0) ? (2**(AdvRem/8)-1) : {IfBytes{1'b1}};
localparam logic [IfBytes-1:0] IdByteMask = (IdRem > 0) ? (2**(IdRem/8)-1) : {IfBytes{1'b1}};
@@ -151,11 +158,11 @@
if (start) begin
cnt_set = 1'b1;
if (adv_en_i) begin
- rounds = AdvRounds - 1;
+ rounds = LastAdvRound;
end else if (id_en_i) begin
- rounds = IdRounds - 1;
+ rounds = LastIdRound;
end else if (gen_en_i) begin
- rounds = GenRounds - 1;
+ rounds = LastGenRound;
end
// we are sending only 1 entry
@@ -262,11 +269,11 @@
if (|cmd_error_o || inputs_invalid_o || fsm_error_o) begin
kmac_data_o.data = decoy_data;
end else if (valid && adv_en_i) begin
- kmac_data_o.data = adv_data[AdvRounds-1-cnt];
+ kmac_data_o.data = adv_data[LastAdvRound - cnt];
end else if (valid && id_en_i) begin
- kmac_data_o.data = id_data[IdRounds-1-cnt];
+ kmac_data_o.data = id_data[LastIdRound - cnt];
end else if (valid && gen_en_i) begin
- kmac_data_o.data = gen_data[GenRounds-1-cnt];
+ kmac_data_o.data = gen_data[LastGenRound - cnt];
end
end
diff --git a/hw/ip/keymgr/rtl/keymgr_reseed_ctrl.sv b/hw/ip/keymgr/rtl/keymgr_reseed_ctrl.sv
index b224d2b..b715b47 100644
--- a/hw/ip/keymgr/rtl/keymgr_reseed_ctrl.sv
+++ b/hw/ip/keymgr/rtl/keymgr_reseed_ctrl.sv
@@ -29,8 +29,9 @@
output logic [LfsrWidth-1:0] seed_o
);
- localparam int EdnRounds = LfsrWidth / EdnWidth;
- localparam int EdnCntWidth = prim_util_pkg::vbits(EdnRounds);
+ localparam int unsigned EdnRounds = LfsrWidth / EdnWidth;
+ localparam int unsigned EdnCntWidth = prim_util_pkg::vbits(EdnRounds);
+ localparam int unsigned LastEdnRound = EdnRounds - 1;
// counter to track number of edn rounds
logic [EdnCntWidth-1:0] edn_cnt;
@@ -42,7 +43,7 @@
// This tracks how many edn rounds are required to fill up
// one required entry.
assign edn_txn_done = edn_req & edn_ack;
- assign edn_done = (edn_cnt == EdnRounds - 1) & edn_txn_done;
+ assign edn_done = (edn_cnt == LastEdnRound[EdnCntWidth-1:0]) & edn_txn_done;
always_ff @(posedge clk_i or negedge rst_ni) begin
if (!rst_ni) begin
edn_cnt <= '0;