|
| 1 | +// Copyright lowRISC contributors (OpenTitan project). |
| 2 | +// Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +// Host sequence for AppDynamic (OTBN) XOF transactions. |
| 6 | +// |
| 7 | +// Transaction flow: |
| 8 | +// Phase 0, Config beat: one push_pull beat encoding mode/strength as data. |
| 9 | +// Phase 1, Message beats: drive message bytes. |
| 10 | +// Phase 2, Digest: KMAC pushes req_output_len chunks (rsp_valid pulses) without |
| 11 | +// per-chunk requests. Once all chunks are received the host |
| 12 | +// sends a single finish beat (last=1). Any further rsp_valid |
| 13 | +// pulses are discarded until rsp_finish signals session end. |
| 14 | +class kmac_app_xof_host_seq extends kmac_app_base_seq; |
| 15 | + `uvm_object_utils(kmac_app_xof_host_seq) |
| 16 | + `uvm_object_new |
| 17 | + |
| 18 | + // Message to hash. Must be set before starting this sequence. |
| 19 | + byte msg_q[$]; |
| 20 | + |
| 21 | + // Number of 64-bit digest chunks to request. |
| 22 | + int unsigned req_output_len = 8; |
| 23 | + |
| 24 | + virtual task body(); |
| 25 | + cfg.m_data_push_agent_cfg.zero_delays = cfg.zero_delays; |
| 26 | + |
| 27 | + // Phase 0: config beat. |
| 28 | + begin |
| 29 | + kmac_pkg::app_ses_config_t ses_cfg; |
| 30 | + ses_cfg = '{prefix_mode: '0, // dummy value |
| 31 | + en_xof: cfg.app_en_xof, |
| 32 | + mode: cfg.app_mode, |
| 33 | + kstrength: cfg.app_strength}; |
| 34 | + send_one_beat(.data(KmacDataIfWidth'(ses_cfg)), .strb('1), .last(1'b0)); |
| 35 | + end |
| 36 | + |
| 37 | + // Phase 1: message beats. |
| 38 | + begin |
| 39 | + byte local_msg[$] = msg_q; |
| 40 | + while (1) begin |
| 41 | + bit [KmacDataIfWidth-1:0] beat_data = '0; |
| 42 | + bit [KmacDataIfWidth/8-1:0] beat_strb = '0; |
| 43 | + bit beat_last; |
| 44 | + int bytes_sent = 0; |
| 45 | + |
| 46 | + for (int i = 0; i < KmacDataIfWidth / 8; i++) begin |
| 47 | + if (local_msg.size() == 0) break; |
| 48 | + beat_data[i*8 +: 8] = local_msg.pop_front(); |
| 49 | + beat_strb[i] = 1; |
| 50 | + bytes_sent++; |
| 51 | + end |
| 52 | + |
| 53 | + if (bytes_sent == 0) begin |
| 54 | + // Empty message: one beat with strb='1, last=1. |
| 55 | + beat_strb = '1; |
| 56 | + end |
| 57 | + |
| 58 | + beat_last = (local_msg.size() == 0); |
| 59 | + send_one_beat(.data(beat_data), .strb(beat_strb), .last(beat_last)); |
| 60 | + if (beat_last) break; |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + // Phase 2: receive digest chunks pushed by KMAC, then send finish. |
| 65 | + // Back pressure on rsp_ready is handled automatically by the push_pull device driver. |
| 66 | + for (int i = 0; i < int'(req_output_len); i++) begin |
| 67 | + wait_rsp_valid(); |
| 68 | + end |
| 69 | + |
| 70 | + // Signal to KMAC that enough digest data has been received. |
| 71 | + send_one_beat(.data('0), .strb('1), .last(1'b1)); |
| 72 | + |
| 73 | + // Drain any extra chunks in the pipeline before the finish response arrives. |
| 74 | + wait_rsp_finish(); |
| 75 | + endtask |
| 76 | + |
| 77 | + // Drive a single push-pull beat by adding to the push-pull host's user-data |
| 78 | + // queue and running a one-shot push_pull_host_seq. |
| 79 | + virtual task send_one_beat( |
| 80 | + input bit [KmacDataIfWidth-1:0] data, |
| 81 | + input bit [KmacDataIfWidth/8-1:0] strb, |
| 82 | + input bit last |
| 83 | + ); |
| 84 | + push_pull_host_seq#(`CONNECT_DATA_WIDTH) host_seq; |
| 85 | + `uvm_create_on(host_seq, p_sequencer.m_push_pull_sequencer) |
| 86 | + `DV_CHECK_RANDOMIZE_FATAL(host_seq) |
| 87 | + cfg.m_data_push_agent_cfg.add_h_user_data({data, strb, last}); |
| 88 | + `uvm_send(host_seq) |
| 89 | + endtask |
| 90 | + |
| 91 | + // Wait for one rsp_valid/rsp_ready handshake transfer. |
| 92 | + virtual task wait_rsp_valid(); |
| 93 | + while (!(cfg.vif.mon_cb.rsp_valid === 1 && cfg.vif.mon_cb.rsp_ready === 1)) |
| 94 | + @(cfg.vif.mon_cb); |
| 95 | + @(cfg.vif.mon_cb); |
| 96 | + endtask |
| 97 | + |
| 98 | + // Wait for the session-end handshake: a completed transfer with rsp_finish asserted. |
| 99 | + virtual task wait_rsp_finish(); |
| 100 | + while (!(cfg.vif.mon_cb.rsp_valid === 1 && cfg.vif.mon_cb.rsp_ready === 1 && |
| 101 | + cfg.vif.mon_cb.rsp_finish === 1)) |
| 102 | + @(cfg.vif.mon_cb); |
| 103 | + @(cfg.vif.mon_cb); |
| 104 | + endtask |
| 105 | + |
| 106 | +endclass |
0 commit comments