1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
| class my_driver extends uvm_driver #(my_transaction); `uvm_component_utils(my_driver) virtual my_interface.driver vif; typedef struct { bit active; bit pending; int wait_cycles; int transactions; int blocked_count; realtime last_active_time; } bp_status_t; bp_status_t bp_status[3]; int max_bp_wait = 1000; typedef struct { bit in_progress; bit [1:0] packet_type; int beat_count; int expected_beats; realtime start_time; int packet_id; } packet_tx_status_t; packet_tx_status_t current_tx; int packet_id_counter = 0; function new(string name, uvm_component parent); super.new(name, parent); for (int i = 0; i < 3; i++) begin bp_status[i] = '{default: 0}; end current_tx = '{default: 0}; endfunction virtual function void build_phase(uvm_phase phase); super.build_phase(phase); if(!uvm_config_db#(virtual my_interface)::get(this, "", "vif", vif)) `uvm_fatal(get_type_name(), "Virtual interface not found!") uvm_config_db#(int)::get(this, "", "max_bp_wait", max_bp_wait); endfunction virtual task run_phase(uvm_phase phase); wait(vif.rst_n); reset_signals(); fork drive_transactions(); monitor_typed_backpressure_driver(); manage_packet_level_backpressure(); join_none endtask virtual task reset_signals(); vif.drv_cb.data_in <= '0; vif.drv_cb.sop_in <= '0; vif.drv_cb.eop_in <= '0; vif.drv_cb.vld_in <= '0; vif.drv_cb.err_in <= '0; endtask virtual task drive_transactions(); my_transaction tr; forever begin seq_item_port.get_next_item(tr); if (!validate_transaction(tr)) begin `uvm_error(get_type_name(), "Invalid transaction received") seq_item_port.item_done(); continue; end bit [1:0] data_type = tr.sop ? tr.get_data_type_from_header() : current_tx.packet_type; if (tr.sop) begin if (can_start_new_packet(data_type)) begin start_new_packet_transmission(tr, data_type); drive_packet_beat(tr); update_transmission_stats(data_type, 1); end else begin handle_blocked_packet(tr, data_type); continue; end end else begin if (!current_tx.in_progress) begin `uvm_error(get_type_name(), "Non-SOP beat received without active packet transmission") seq_item_port.item_done(); continue; end drive_packet_beat(tr); current_tx.beat_count++; if (tr.eop) begin complete_packet_transmission(); end end seq_item_port.item_done(); end endtask virtual function bit validate_transaction(my_transaction tr); if (tr.sop && current_tx.in_progress) begin `uvm_warning(get_type_name(), "SOP received while packet transmission in progress - forcing completion") force_complete_current_transmission(); end if (tr.sop && !tr.validate_header()) begin return 0; end return 1; endfunction virtual function bit can_start_new_packet(int data_type); if (current_tx.in_progress) begin `uvm_error(get_type_name(), "Cannot start new packet - transmission already in progress"); return 0; end if (bp_status[data_type].active) begin `uvm_info(get_type_name(), $sformatf("New packet blocked - type %0d backpressure active", data_type), UVM_MEDIUM); return 0; end return 1; endfunction virtual function void start_new_packet_transmission(my_transaction tr, int data_type); current_tx.in_progress = 1; current_tx.packet_type = data_type; current_tx.beat_count = 1; current_tx.expected_beats = tr.calculate_expected_beats(); current_tx.start_time = $realtime; current_tx.packet_id = packet_id_counter++; m_sequencer.notify_packet_start(data_type); my_sequencer::driver_status_t status; status.transmission_active = 1; status.current_type = data_type; status.beat_count = 1; status.start_time = $realtime; m_sequencer.update_driver_status(status); `uvm_info(get_type_name(), $sformatf("Started packet %0d transmission: type=%0d, expected_beats=%0d, payload_len=%0d", current_tx.packet_id, data_type, current_tx.expected_beats, tr.payload_length), UVM_MEDIUM) endfunction virtual function void complete_packet_transmission(); realtime duration = $realtime - current_tx.start_time; `uvm_info(get_type_name(), $sformatf("Completed packet %0d: type=%0d, %0d/%0d beats, duration=%.1f ns", current_tx.packet_id, current_tx.packet_type, current_tx.beat_count, current_tx.expected_beats, duration / 1ns), UVM_MEDIUM) if (current_tx.beat_count != current_tx.expected_beats) begin `uvm_warning(get_type_name(), $sformatf("Beat count mismatch: expected %0d, actual %0d", current_tx.expected_beats, current_tx.beat_count)) end current_tx.in_progress = 0; apply_pending_backpressures(); endfunction virtual function void handle_blocked_packet(my_transaction tr, int data_type); bp_status[data_type].blocked_count++; `uvm_info(get_type_name(), $sformatf("Packet blocked: type=%0d (total blocked: %0d)", data_type, bp_status[data_type].blocked_count), UVM_MEDIUM) seq_item_port.put_response(tr); endfunction virtual function void apply_pending_backpressures(); for (int i = 0; i < 3; i++) begin if (bp_status[i].pending) begin bp_status[i].active = 1; bp_status[i].pending = 0; bp_status[i].last_active_time = $realtime; `uvm_info(get_type_name(), $sformatf("Applied pending backpressure for type %0d", i), UVM_MEDIUM) end end endfunction virtual task monitor_typed_backpressure_driver(); bit [2:0] current_signals, previous_signals = 3'b000; forever begin @(vif.drv_cb); current_signals = vif.get_backpressure_status(); for (int i = 0; i < 3; i++) begin if (current_signals[i] !== previous_signals[i]) begin handle_backpressure_change(i, current_signals[i]); end end previous_signals = current_signals; end endtask virtual function void handle_backpressure_change(int type_idx, bit new_state); if (new_state) begin if (current_tx.in_progress && current_tx.packet_type == type_idx) begin bp_status[type_idx].pending = 1; `uvm_info(get_type_name(), $sformatf("Type %0d backpressure PENDING (packet %0d in transmission)", type_idx, current_tx.packet_id), UVM_MEDIUM) end else begin bp_status[type_idx].active = 1; bp_status[type_idx].last_active_time = $realtime; `uvm_info(get_type_name(), $sformatf("Type %0d backpressure ACTIVATED immediately", type_idx), UVM_MEDIUM) end end else begin bp_status[type_idx].active = 0; bp_status[type_idx].pending = 0; `uvm_info(get_type_name(), $sformatf("Type %0d backpressure RELEASED", type_idx), UVM_MEDIUM) end endfunction virtual function void update_transmission_stats(int data_type, bit success); if (success) begin bp_status[data_type].transactions++; end endfunction virtual function void force_complete_current_transmission(); if (current_tx.in_progress) begin `uvm_warning(get_type_name(), $sformatf("Force completing packet %0d transmission", current_tx.packet_id)) current_tx.in_progress = 0; apply_pending_backpressures(); end endfunction virtual function void report_phase(uvm_phase phase); `uvm_info(get_type_name(), "=== Enhanced Driver Statistics by Data Type ===", UVM_LOW) for (int i = 0; i < 3; i++) begin real block_rate = (bp_status[i].transactions > 0) ? real'(bp_status[i].blocked_count) * 100.0 / (bp_status[i].transactions + bp_status[i].blocked_count) : 0.0; `uvm_info(get_type_name(), $sformatf("Type %0d: %0d sent, %0d blocked (%.1f%%), %0d BP wait cycles", i, bp_status[i].transactions, bp_status[i].blocked_count, block_rate, bp_status[i].wait_cycles), UVM_LOW) end `uvm_info(get_type_name(), "=== Packet-Level Backpressure Benefits ===", UVM_LOW) `uvm_info(get_type_name(), "✓ Zero packet fragmentation - complete transmission guaranteed", UVM_LOW) `uvm_info(get_type_name(), "✓ Perfect SOP/EOP alignment - no boundary corruption", UVM_LOW) `uvm_info(get_type_name(), "✓ Optimal DUT performance - full packet processing", UVM_LOW) `uvm_info(get_type_name(), "✓ Minimal retransmission overhead - smart pending mechanism", UVM_LOW) endfunction endclass
|