def test_sq_overflow(nvme0): cq = IOCQ(nvme0, 1, 5, PRP()) sq = IOSQ(nvme0, 1, 2, PRP(), cqid=1) # send commands sq[0] = SQE(4<<16+0, 1); sq.tail = 1 sq[1] = SQE(3<<16+0, 1); sq.tail = 0 sq[0] = SQE(2<<16+0, 1); sq.tail = 0 with pytest.warns(UserWarning, match="AER notification is triggered: 0x10100"): nvme0.getfeatures(7).waitdone() # check cq time.sleep(0.1) assert cq[0][3] == 0x10004 assert cq[1][3] == 0x10003 assert cq[2][3] == 0 time.sleep(1) assert cq[2][3] == 0 assert cq[3][3] == 0 assert cq[4][3] == 0 logging.info(sq[0]) logging.info(cq[0]) sq.delete() cq.delete()
def test_sq_cq_around(nvme0): cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 2, PRP(), cqid=1) # send commands sq[0] = SQE(4<<16+0, 1); sq.tail = 1 sq[1] = SQE(3<<16+0, 1); sq.tail = 0 sq[0] = SQE(2<<16+0, 1); sq.tail = 1 sq[1] = SQE(1<<16+0, 1); sq.tail = 0 # check cq time.sleep(0.1) assert cq[0][3] == 0x10004 assert cq[1][3] == 0x10003 assert cq[2][3] == 0 cq.head = 1 assert cq[0][3] == 0x10004 assert cq[2][3] == 0x10002 cq.head = 2 assert cq[2][3] == 0x10002 assert cq[1][3] == 0x10003 assert cq[0][3] == 0x00001 sq.delete() cq.delete()
def test_sq_overflow(nvme0): cq = IOCQ(nvme0, 1, 5, PRP()) sq = IOSQ(nvme0, 1, 2, PRP(), cqid=1) # send commands sq[0] = SQE(4 << 16 + 0, 1) sq.tail = 1 time.sleep(0.1) sq[1] = SQE(3 << 16 + 0, 1) sq.tail = 0 time.sleep(0.1) # check cq assert cq[0][3] == 0x10004 assert cq[1][3] == 0x10003 assert cq[2][3] == 0 time.sleep(1) assert cq[2][3] == 0 assert cq[3][3] == 0 assert cq[4][3] == 0 logging.debug(sq[0]) logging.debug(cq[0]) sq.delete() cq.delete()
def test_sq_cq_another_sq(nvme0): cq = IOCQ(nvme0, 1, 3, PRP()) # send commands in sq1 sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) sq[0] = SQE(4 << 16 + 0, 1) sq[1] = SQE(3 << 16 + 0, 1) sq.tail = 2 sq2 = IOSQ(nvme0, 2, 3, PRP(), cqid=1) sq2[0] = SQE(2 << 16 + 0, 1) sq2[1] = SQE(1 << 16 + 0, 1) sq2.tail = 2 # check cq time.sleep(0.1) assert cq[0][3] == 0x10004 assert cq[1][3] == 0x10003 assert cq[2][3] == 0 cq.head = 1 time.sleep(0.1) assert cq[2][3] == 0x10002 assert cq[0][3] == 0x10004 cq.head = 2 time.sleep(0.1) assert cq[0][3] == 0x00001 sq.delete() sq2.delete() cq.delete()
def test_sq_doorbell(nvme0): cq = IOCQ(nvme0, 1, 5, PRP()) sq = IOSQ(nvme0, 1, 2, PRP(), cqid=1) sq.tail = 1 time.sleep(0.1) sq.delete() cq.delete()
def test_cid_conflict(nvme0): mdts_lba = nvme0.mdts // 512 cq = IOCQ(nvme0, 1, 20, PRP()) sq = IOSQ(nvme0, 1, 20, PRP(), cqid=1) # prp for the long buffer write_buf_1 = PRP(ptype=32, pvalue=0xaaaaaaaa) pages = mdts_lba // 8 pages -= 1 prp_list = PRPList() prp_list_head = prp_list while pages: logging.info(pages) for i in range(63): if pages: prp_list[i] = PRP() pages -= 1 logging.debug(pages) if pages > 1: tmp = PRPList() prp_list[63] = tmp prp_list = tmp logging.debug("prp_list") elif pages == 1: prp_list[63] = PRP() pages -= 1 logging.debug(pages) #send first cmd w1 = SQE((1 << 16) + 1, 1) w1.prp1 = write_buf_1 w1.prp2 = prp_list_head w1[12] = mdts_lba - 1 # 0based, nlba sq[0] = w1 sq[1] = w1 logging.info(sq[0]) logging.info(sq[1]) assert sq[0][0] >> 16 == 1 assert sq[1][0] >> 16 == 1 sq.tail = 2 time.sleep(1) logging.info(cq[0]) logging.info(cq[1]) cqe = CQE(cq[0]) assert cqe.p == 1 status = (cqe[3] >> 17) & 0x3ff assert status == 0 or status == 0x0003 cqe = CQE(cq[1]) assert cqe.p == 1 status = (cqe[3] >> 17) & 0x3ff assert status == 0 or status == 0x0003 cq.head = 2 sq.delete() cq.delete()
def _test_cq_sqhd_aer(nvme0, buf): #Create cq and sq a = () cq = IOCQ(nvme0, 1, 5, PRP()) sq = IOSQ(nvme0, 1, 5, PRP(), cqid=1) #Trigger aer cmd response by invaild doorbell write value sq.tail = 5 time.sleep(0.1) #Invalid Doorbell Write Value with pytest.warns(UserWarning, match="AER notification is triggered: 0x10100"): nvme0.waitdone() sq.delete() cq.delete() def call_back_cpl(cpl): nonlocal a a = cpl #Check normal cmd cqe sqhd value nvme0.getlogpage(1, buf, cb=call_back_cpl).waitdone() sqhd1 = a[2] & 0xffff logging.info(sqhd1) nvme0.aer(cb=call_back_cpl) nvme0.getlogpage(1, buf, cb=call_back_cpl).waitdone() sqhd2 = a[2] & 0xffff logging.info(sqhd2) assert sqhd2 == sqhd1 + 2 #Trigger aer cmd response by invaild doorbell write value cq = IOCQ(nvme0, 1, 5, PRP()) sq = IOSQ(nvme0, 1, 5, PRP(), cqid=1) sq.tail = 5 time.sleep(0.1) #Invalid Doorbell Write Value with pytest.warns(UserWarning, match="AER notification is triggered: 0x10100"): nvme0.waitdone() #verify aer cmd cqe sqhd sqhd_aer = a[2] & 0xffff sqhd_aer = sqhd2 + 2 logging.info("aer sqhd is {}".format(sqhd_aer)) sq.delete() cq.delete() #verify the following cmd cqe sqhd nvme0.getlogpage(1, buf, cb=call_back_cpl).waitdone() sqhd3 = a[2] & 0xffff assert sqhd3 == sqhd_aer + 3 logging.info(sqhd3)
def test_sq_doorbell_invalid(nvme0, tail): cq = IOCQ(nvme0, 1, 5, PRP()) sq = IOSQ(nvme0, 1, 2, PRP(), cqid=1) sq.tail = tail time.sleep(0.1) #Invalid Doorbell Write Value with pytest.warns(UserWarning, match="AER notification is triggered: 0x10100"): nvme0.getfeatures(7).waitdone() sq.delete() cq.delete()
def test_sq_fuse_is_zero(nvme0): cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) # FUSE field is zero. sq[0] = SQE((1<<16) + (0<<8), 1); sq.tail = 1; time.sleep(0.1) # check cq time.sleep(0.1) assert cq[0][3] == 0x10001 sq.delete() cq.delete()
def test_sq_reserved(nvme0): cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) # Reserved field is non-zero. sq[0] = SQE((1<<16) + (7<<10) + 0, 1); sq.tail = 1; time.sleep(0.1) # check cq time.sleep(0.1) assert cq[0][3] == 0x10001 sq.delete() cq.delete()
def test_reset_with_outstanding_io(nvme0, nvme0n1, delay, io_count=100): nvme0n1.format(512) logging.debug("format done") cq = IOCQ(nvme0, 1, 128, PRP(1024 * 64)) sq = IOSQ(nvme0, 1, 128, PRP(1024 * 64), cqid=1) write_cmd = SQE(1, 1) write_cmd[12] = 7 # 4K write buf_list = [] for i in range(io_count): buf = PRP(ptype=32, pvalue=i) # use cid as data pattern buf_list.append(buf) write_cmd.prp1 = buf write_cmd.cid = i write_cmd[10] = i sq[i] = write_cmd sq.tail = io_count # reset while io is active logging.debug("write done") time.sleep(delay) nvme0.reset() # read after reset with outstanding writes cq = IOCQ(nvme0, 1, 128, PRP(1024 * 64)) sq = IOSQ(nvme0, 1, 128, PRP(1024 * 64), cqid=1) read_cmd = SQE(2, 1) read_cmd[12] = 7 # 4K read buf_list = [] for i in range(io_count): buf = PRP() buf_list.append(buf) read_cmd.prp1 = buf read_cmd.cid = i read_cmd[10] = i sq[i] = read_cmd sq.tail = io_count logging.debug("read done") # data verify time.sleep(3) assert cq[io_count - 1].p != 0 for i in range(io_count): cid = cq[i].cid dp = buf_list[cq[i].cid].data(3, 0) # check data pattern logging.debug("cpl %d: cid %d, data pattern %d" % (i, cid, dp)) assert dp == 0 or dp == cid sq.delete() cq.delete()
def test_sq_fuse_is_reserved(nvme0): cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) # FUSE field is 0x3(Reserved). sq[0] = SQE((1<<16) + (3<<8), 1); sq.tail = 1; time.sleep(0.1) # check cq time.sleep(0.1) #sct=0,sc=2(Invalid Field in Command) assert cq[0][3]>>17 == 0x0002 sq.delete() cq.delete()
def test_sq_opc_invalid_nvm_cmd(nvme0,opc_id): cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) # OPC field is invalid. sq[0] = SQE((1<<16) + opc_id, 1); sq.tail = 1; time.sleep(0.1) # check cq time.sleep(0.1) #sct=0,sc=1(Invalid Command Opcode) assert (cq[0][3]>>17)&0x3ff == 0x0001 sq.delete() cq.delete()
def test_sq_cid2(nvme0): cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) # send max/min cid commands sq[0] = SQE(0xFFFF<<16+0, 1); sq[1] = SQE(0<<16+0, 1); sq.tail = 2; time.sleep(0.1) # check cq time.sleep(0.1) assert cq[0][3] == 0x1FFFF assert cq[1][3] == 0x10000 sq.delete() cq.delete()
def test_sq_ns_invalid(nvme0,ns_id): cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) # ns field is invalid. sq[0] = SQE(2, ns_id); sq.tail = 1; time.sleep(0.1) # check cq time.sleep(0.1) #sct=0,sc=0x0b(Invalid Namespace or Format) assert (cq[0][3]>>17)&0x3ff == 0x000b sq.delete() cq.delete()
def test_sq_cid1(nvme0): cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) # send discontinuous cid commands sq[0] = SQE(4<<16+0, 1); sq.tail = 1; time.sleep(0.1) sq[1] = SQE(1<<16+0, 1); sq.tail = 2; time.sleep(0.1) # check cq time.sleep(0.1) assert cq[0][3] == 0x10004 assert cq[1][3] == 0x10001 sq.delete() cq.delete()
def test_write_mdts(nvme0, mdts): cq = IOCQ(nvme0, 1, 2, PRP()) sq = IOSQ(nvme0, 1, 2, PRP(), cqid=1) # prp for the long buffer write_buf_1 = PRP(ptype=32, pvalue=0xaaaaaaaa) pages = mdts // 8 pages -= 1 prp_list = PRPList() prp_list_head = prp_list while pages: for i in range(511): if pages: prp_list[i] = PRP() pages -= 1 logging.debug(pages) if pages > 1: tmp = PRPList() prp_list[511] = tmp prp_list = tmp logging.debug("prp_list") elif pages == 1: prp_list[511] = PRP() pages -= 1 logging.debug(pages) w1 = SQE(1, 1) w1.prp1 = write_buf_1 w1.prp2 = prp_list_head w1[12] = mdts - 1 # 0based, nlba w1.cid = 0x123 sq[0] = w1 sq.tail = 1 time.sleep(1) cqe = CQE(cq[0]) logging.info(cqe) assert cqe.p == 1 assert cqe.cid == 0x123 assert cqe.sqhd == 1 logging.info("cqe status is {}".format(cqe.status)) assert cqe.status == 0 or cqe.status == 2 cq.head = 1 sq.delete() cq.delete()
def test_pcie_link_control_aspm(nvme0, pcie, aspm): #1:0 linkctrl_addr = pcie.cap_offset(0x10) + 16 linkctrl = pcie.register(linkctrl_addr, 2) logging.info("link control register [0x%x]= 0x%x" % (linkctrl_addr, linkctrl)) # set ASPM control pcie[linkctrl_addr] = (linkctrl & 0xfc) | aspm linkctrl = pcie.register(linkctrl_addr, 2) logging.info("link control register [0x%x]= 0x%x" % (linkctrl_addr, linkctrl)) # IO queue for read commands cq = IOCQ(nvme0, 1, 16, PRP()) sq = IOSQ(nvme0, 1, 16, PRP(), cqid=1) # read lba 0 for 1000 times, interleaved with delays read_cmd = SQE(2, 1) read_cmd.prp1 = PRPList() pbit = 1 for i in range(100): logging.debug(i) slot = i % 16 if slot == 0: pbit = not pbit next_slot = slot + 1 if next_slot == 16: next_slot = 0 sq[slot] = read_cmd sq.tail = next_slot while cq[slot].p == pbit: pass cq.head = next_slot # delay to trigger ASPM time.sleep(0.01) sq.delete() cq.delete() time.sleep(1) #return ASPM L0 pcie[linkctrl_addr] = (linkctrl & 0xfc) | 0
def test_invalid_offset_prp_in_list(nvme0): cq = IOCQ(nvme0, 1, 10, PRP()) sq = IOSQ(nvme0, 1, 10, PRP(), cqid=1) buf = PRP(ptype=32, pvalue=0xffffffff) buf.offset = 0x10 prp_list = PRPList() prp_list.offset = 0x20 for i in range(8): tmp = PRP(ptype=32, pvalue=0xffffffff) tmp.offset = 0x10 prp_list[i] = tmp logging.info(prp_list.dump(64)) print(buf.dump(32)) for i in range(8): print(prp_list[i].dump(32)) cmd = SQE(2, 1) cmd.prp1 = buf cmd.prp2 = prp_list cmd[12] = 0x4000001f sq[0] = cmd logging.info(sq[0]) sq.tail = 1 while CQE(cq[0]).p == 0: pass cq.head = 1 logging.info(cq[0]) logging.info(hex(cq[0][3] >> 17)) print(buf.dump(32)) for i in range(8): print(prp_list[i].dump(32)) status = (cq[0][3] >> 17) & 0x3ff assert status == 0x0013 or status == 0 sq.delete() cq.delete()
def test_controller_cc_en(nvme0): en=nvme0[0x14]&0x1 logging.info("en:{}".format(en)) logging.info("cc:{}".format(nvme0[0x14])) assert nvme0[0x14] == 0x00460001 cq = IOCQ(nvme0, 1, 3, PRP()) sq = IOSQ(nvme0, 1, 3, PRP(), cqid=1) sq[0] = SQE(2, 1); sq.tail = 1; time.sleep(0.1) # check cq time.sleep(0.1) assert (cq[0][3]>>17)&0x3ff == 0x0000 sq.delete() cq.delete() #change cc.en from '1' to '0' nvme0[0x14] = 0 #wait csts.rdy change from '1' to '0' while not (nvme0[0x1c]&0x1)==0: pass nvme0.aer() try: nvme0.waitdone() except Exception as e: logging.warning(e) if 0 != nvme0.init_adminq(): raise NvmeEnumerateError("fail to init admin queue") #change cc.en from '0' to '1' nvme0[0x14] = 0x00460001 #wait csts.rdy change from '0' to '1' while not (nvme0[0x1c]&0x1)==1: pass assert nvme0[0x14] ==0x00460001
def test_create_sq_with_invalid_id(nvme0, ncqa): # helper cq: id 1 cq = IOCQ(nvme0, 1, 10, PRP(4096)) # pass case sq = IOSQ(nvme0, 5, 10, PRP(4096), cqid=1) # sqid: 0 with pytest.warns(UserWarning, match="ERROR status: 01/01"): IOSQ(nvme0, 0, 10, PRP(4096), cqid=1) # sqid: 0xffff with pytest.warns(UserWarning, match="ERROR status: 01/01"): IOSQ(nvme0, 0xffff, 10, PRP(4096), cqid=1) # sqid: larger than supported number of queue with pytest.warns(UserWarning, match="ERROR status: 01/01"): IOSQ(nvme0, ncqa + 1, 10, PRP(4096), cqid=1) # sqid: duplicated cqid with pytest.warns(UserWarning, match="ERROR status: 01/01"): IOSQ(nvme0, 5, 10, PRP(4096), cqid=1) # sqid: 0 with pytest.warns(UserWarning, match="ERROR status: 01/01"): IOSQ(nvme0, 0, 10, PRP(4096), cqid=1) # sqid: 0xdead with pytest.warns(UserWarning, match="ERROR status: 01/01"): IOSQ(nvme0, 0xdead, 10, PRP(4096), cqid=1) # sqid: 0xff with pytest.warns(UserWarning, match="ERROR status: 01/01"): IOSQ(nvme0, ncqa + 0xff, 10, PRP(4096), cqid=1) sq.delete() cq.delete()
def sq(nvme0, cq): ret = IOSQ(nvme0, 1, 10, PRP(), cq.id) yield ret ret.delete()
def test_controller_mdts(nvme0,nvme0n1): if nvme0.mdts == 1024*1024: # up to 1MB pytest.skip("mdts is maximum") mps_min = (nvme0.cap>>48) & 0xf logging.info("mps_min:{}".format(mps_min)) mdts=nvme0.id_data(77,77) logging.info("mdts:{}".format(mdts)) max_data_size=(2**mdts)*(2**(12+mps_min)) logging.info(max_data_size) max_pages=max_data_size//4//1024 pages=max_pages-1 max_lba=max_data_size//512 cq = IOCQ(nvme0, 1, 5, PRP()) sq = IOSQ(nvme0, 1, 5, PRP(), cqid=1) # prp for the long buffer write_buf_1 = PRP(ptype=32, pvalue=0xaaaaaaaa) prp_list = PRPList() prp_list_head = prp_list while pages: for i in range(511): if pages: prp_list[i] = PRP() pages -= 1 logging.debug(pages) if pages>1: tmp = PRPList() prp_list[511] = tmp prp_list = tmp logging.debug("prp_list") elif pages==1: prp_list[511] = PRP() pages -= 1 logging.debug(pages) w1 = SQE(1, 1) w1.prp1 = write_buf_1 w1.prp2 = prp_list_head w1[12] = max_lba-1 # 0based, nlba w1.cid = 0x123 sq[0] = w1 sq.tail = 1 time.sleep(1) cqe = CQE(cq[0]) logging.info(cqe) assert cqe.p == 1 assert cqe.cid == 0x123 assert cqe.sqhd == 1 assert cqe.status == 0 cq.head = 1 w2 = SQE(1, 1) w2.prp1 = write_buf_1 w2.prp2 = prp_list_head w2[12] = max_lba # 0based, nlba w2.cid = 0x234 sq[1] = w2 sq.tail = 2 time.sleep(1) cqe = CQE(cq[1]) logging.info(cqe) assert cqe.p == 1 assert cqe.cid == 0x234 assert cqe.sqhd == 2 assert cqe.status == 2 cq.head = 2 r1 = SQE(2, 1) r1.prp1 = write_buf_1 r1.prp2 = prp_list_head r1[12] = max_lba # 0based, nlba r1.cid = 0x345 sq[2] = r1 sq.tail = 3 time.sleep(1) cqe = CQE(cq[2]) logging.info(cqe) assert cqe.p == 1 assert cqe.cid == 0x345 assert cqe.sqhd == 3 assert cqe.status == 2 cq.head = 3 r2 = SQE(2, 1) r2.prp1 = write_buf_1 r2.prp2 = prp_list_head r2[12] = max_lba-1 # 0based, nlba r2.cid = 0x456 sq[3] = r2 sq.tail = 4 time.sleep(1) cqe = CQE(cq[3]) logging.info(cqe) assert cqe.p == 1 assert cqe.cid == 0x456 assert cqe.sqhd == 4 assert cqe.status == 0 cq.head = 4 sq.delete() cq.delete()