From c2699d2f02aa4caeb01e20a52cc126e8967783fb Mon Sep 17 00:00:00 2001 From: Mubashir Saleem Date: Thu, 21 Dec 2023 17:11:36 +0500 Subject: [PATCH] [usbdev] usbdev_smoke_sequence Add usbdev smoke test of simple packet transmission in both direction over the USB. Signed-off-by: Mubashir Saleem --- hw/dv/sv/usb20_agent/usb20_item.sv | 80 ------------------ .../dv/env/seq_lib/usbdev_smoke_vseq.sv | 82 ++++++++++++++++++- 2 files changed, 80 insertions(+), 82 deletions(-) diff --git a/hw/dv/sv/usb20_agent/usb20_item.sv b/hw/dv/sv/usb20_agent/usb20_item.sv index dded485102661..a17a335ac3f6a 100644 --- a/hw/dv/sv/usb20_agent/usb20_item.sv +++ b/hw/dv/sv/usb20_agent/usb20_item.sv @@ -71,88 +71,8 @@ class data_pkt extends usb20_item; function void set_payload(byte bmRequestType, byte bRequest, byte wVH, byte wVL, byte wIH, byte wIL, byte wLH, byte wLL); -<<<<<<< HEAD data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; crc16 = generate_crc16(data); -======= - // bRequestType 0_00_00000 - if (bmRequestType == bmRequestType0) begin - if (bRequest == bRequestCLEAR_FEATURE) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestSET_ADDRESS) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestSET_CONFIGURATION) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestSET_DESCRIPTOR) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestSET_FEATURE) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - end - - // bRequestType 0_00_00001 - else if (bmRequestType == bmRequestType1) begin - if (bRequest == bRequestCLEAR_FEATURE) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestSET_FEATURE) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestSET_INTERFACE) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - end - - // bRequestType 0_00_00010 - else if (bmRequestType == bmRequestType2) begin - if (bRequest == bRequestCLEAR_FEATURE) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestSET_FEATURE) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - end - - // bRequestType 1_00_00000 - else if (bmRequestType == bmRequestType3) begin - if(bRequest == bRequestGET_CONFIGURATION) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestGET_DESCRIPTOR) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestGET_STATUS) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - end - - // bRequestType 1_00_00001 - else if (bmRequestType == bmRequestType4) begin - if (bRequest == bRequestGET_INTERFACE) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestGET_STATUS) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - end - - // bRequestType 1_00_00010 - else if (bmRequestType == bmRequestType5) begin - if (bRequest == bRequestGET_STATUS) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - else if (bRequest == bRequestSYNCH_FRAME) begin - data = '{bmRequestType, bRequest, wVH, wVL, wIH, wIL, wLH, wLL}; - end - end else begin - data = data; - end - crc16 = generate_crc16(data); ->>>>>>> 331d1f7645 ([Usbdev] usbdev_env) endfunction function void post_randomize(); diff --git a/hw/ip/usbdev/dv/env/seq_lib/usbdev_smoke_vseq.sv b/hw/ip/usbdev/dv/env/seq_lib/usbdev_smoke_vseq.sv index c242824b4b5ac..627f6d74b2364 100644 --- a/hw/ip/usbdev/dv/env/seq_lib/usbdev_smoke_vseq.sv +++ b/hw/ip/usbdev/dv/env/seq_lib/usbdev_smoke_vseq.sv @@ -8,8 +8,86 @@ class usbdev_smoke_vseq extends usbdev_base_vseq; `uvm_object_new + usb20_item m_usb20_item; + usb20_item rsp_itm; + token_pkt m_token_pkt; + data_pkt m_data_pkt; + handshake_pkt m_handshake_pkt; + task body(); - `uvm_error(`gfn, "FIXME") - endtask : body + uvm_reg_data_t rx_fifo_read; + uvm_reg_data_t rx_fifo_expected; + uvm_reg_data_t rx_empty; + uvm_reg_data_t usbstat; + uvm_reg_data_t data; + uvm_status_e status; + bit [4:0] buffer_id = 5'd1; + super.apply_reset("HARD"); + super.dut_init("HARD"); + cfg.clk_rst_vif.wait_clks(200); + csr_wr(.ptr(ral.intr_state), .value(32'h0001_ffff)); // clear interrupts + csr_wr(.ptr(ral.ep_out_enable[0].enable[0]), .value(1'b1)); // Enable EP0 Out + csr_update(ral.ep_out_enable[0]); + ral.rxenable_setup[0].setup[0].set(1'b1); // Enable rx setup + csr_update(ral.rxenable_setup[0]); + ral.avbuffer.buffer.set(buffer_id); // set buffer id =1 + csr_update(ral.avbuffer); + ral.intr_enable.pkt_received.set(1'b1); // Enable pkt_received interrupt + csr_update(ral.intr_enable); + // Setup token packet followed by a data packet of 8 bytes + call_token_sequence(PktTypeToken, PidTypeSetupToken); + cfg.clk_rst_vif.wait_clks(20); + call_data_sequence(PktTypeData, PidTypeData0); + cfg.clk_rst_vif.wait_clks(20); + // read rx_fifo register to check rcvd buffer id, endpoint number and type setup/out + csr_rd(.ptr(ral.rxfifo), .value(rx_fifo_read)); + // expected value of rx_fifof reg is (32'h80801)[setup = 1, payload size = 8 bytes buffid = 1] + rx_fifo_expected = 32'h80801; + `DV_CHECK_EQ(rx_fifo_expected, rx_fifo_read); + ral.avbuffer.buffer.set(buffer_id + 1); // change available buffer id + csr_update(ral.avbuffer); + endtask + + task call_token_sequence(input string pkt_type, input string pid_type); + RSP rsp_item; + `uvm_create_on(m_token_pkt, p_sequencer.usb20_sequencer_h) + m_token_pkt.m_pkt_type = pkt_type; + m_token_pkt.m_pid_type = pid_type; + assert(m_token_pkt.randomize() with {m_token_pkt.address inside {7'b0}; + m_token_pkt.endpoint inside {4'd0};}); + m_usb20_item = m_token_pkt; + start_item(m_token_pkt); + finish_item(m_token_pkt); + if (pid_type == "PidTypeInToken") begin + get_response(rsp_item); + $cast(rsp_itm, rsp_item); + get_response_from_device(rsp_itm, PidTypeData1); + end + endtask + + task call_data_sequence(input string pkt_type, input string pid_type); + RSP rsp_item; + `uvm_create_on(m_data_pkt, p_sequencer.usb20_sequencer_h) + m_data_pkt.m_pkt_type = pkt_type; + m_data_pkt.m_pid_type = pid_type; + m_data_pkt.m_bmRT = 8'h80; + m_data_pkt.m_bR = 8'h06; + assert(m_data_pkt.randomize()); + m_usb20_item = m_data_pkt; + m_data_pkt.set_payload (m_data_pkt.m_bmRT, m_data_pkt.m_bR,8'h00, 8'h01, 8'h00, 8'h00, + 8'h40,8'h00); + start_item(m_data_pkt); + finish_item(m_data_pkt); + get_response(rsp_item); + $cast(rsp_itm, rsp_item); + get_response_from_device(rsp_itm, PidTypeAck); + endtask + task get_response_from_device(usb20_item rsp_itm, input string pid_type); + `uvm_create_on(m_handshake_pkt, p_sequencer.usb20_sequencer_h) + m_handshake_pkt.m_pid_type = pid_type; + m_usb20_item = m_handshake_pkt; + // DV_CHECK on device reponse packet id + `DV_CHECK_EQ(m_usb20_item.m_pid_type, rsp_itm.m_pid_type); + endtask endclass : usbdev_smoke_vseq