From nobody Sat Apr 27 21:03:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151802244576763.52203288977864; Wed, 7 Feb 2018 08:54:05 -0800 (PST) Received: from localhost ([::1]:59092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejSyy-0002u8-Ul for importer@patchew.org; Wed, 07 Feb 2018 11:54:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejSfJ-0001YJ-8t for qemu-devel@nongnu.org; Wed, 07 Feb 2018 11:33:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejSfE-0002hm-EB for qemu-devel@nongnu.org; Wed, 07 Feb 2018 11:33:45 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38168 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ejSfE-0002ZV-8Q for qemu-devel@nongnu.org; Wed, 07 Feb 2018 11:33:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62D2A8182D13; Wed, 7 Feb 2018 16:33:29 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-231.bos.redhat.com [10.18.17.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA77A1008563; Wed, 7 Feb 2018 16:33:28 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Wed, 7 Feb 2018 11:33:22 -0500 Message-Id: <20180207163322.25820-2-jsnow@redhat.com> In-Reply-To: <20180207163322.25820-1-jsnow@redhat.com> References: <20180207163322.25820-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 07 Feb 2018 16:33:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 07 Feb 2018 16:33:29 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 1/1] ide-test: test trim requests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Anton Nefedov , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Anton Nefedov Signed-off-by: Anton Nefedov Reviewed-by: John Snow Message-id: 1516611841-5526-1-git-send-email-anton.nefedov@virtuozzo.com Signed-off-by: John Snow --- tests/ide-test.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 71 insertions(+) diff --git a/tests/ide-test.c b/tests/ide-test.c index aa9de065fc..be427e41d6 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -52,6 +52,7 @@ enum { reg_data =3D 0x0, reg_feature =3D 0x1, + reg_error =3D 0x1, reg_nsectors =3D 0x2, reg_lba_low =3D 0x3, reg_lba_middle =3D 0x4, @@ -69,6 +70,11 @@ enum { ERR =3D 0x01, }; =20 +/* Error field */ +enum { + ABRT =3D 0x04, +}; + enum { DEV =3D 0x10, LBA =3D 0x40, @@ -81,6 +87,7 @@ enum { }; =20 enum { + CMD_DSM =3D 0x06, CMD_READ_DMA =3D 0xc8, CMD_WRITE_DMA =3D 0xca, CMD_FLUSH_CACHE =3D 0xe7, @@ -179,6 +186,12 @@ typedef struct PrdtEntry { #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), =3D=3D= , (mask)) #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), =3D= =3D, 0) =20 +static uint64_t trim_range_le(uint64_t sector, uint16_t count) +{ + /* 2-byte range, 6-byte LBA */ + return cpu_to_le64(((uint64_t)count << 48) + sector); +} + static int send_dma_request(int cmd, uint64_t sector, int nb_sectors, PrdtEntry *prdt, int prdt_entries, void(*post_exec)(QPCIDevice *dev, QPCIBar ide_= bar, @@ -204,6 +217,7 @@ static int send_dma_request(int cmd, uint64_t sector, i= nt nb_sectors, * the SCSI command being sent in the packet, too. */ from_dev =3D true; break; + case CMD_DSM: case CMD_WRITE_DMA: from_dev =3D false; break; @@ -234,6 +248,10 @@ static int send_dma_request(int cmd, uint64_t sector, = int nb_sectors, /* Enables ATAPI DMA; otherwise PIO is attempted */ qpci_io_writeb(dev, ide_bar, reg_feature, 0x01); } else { + if (cmd =3D=3D CMD_DSM) { + /* trim bit */ + qpci_io_writeb(dev, ide_bar, reg_feature, 0x01); + } qpci_io_writeb(dev, ide_bar, reg_nsectors, nb_sectors); qpci_io_writeb(dev, ide_bar, reg_lba_low, sector & 0xff); qpci_io_writeb(dev, ide_bar, reg_lba_middle, (sector >> 8) & 0xff); @@ -344,6 +362,58 @@ static void test_bmdma_simple_rw(void) g_free(cmpbuf); } =20 +static void test_bmdma_trim(void) +{ + QPCIDevice *dev; + QPCIBar bmdma_bar, ide_bar; + uint8_t status; + const uint64_t trim_range[] =3D { trim_range_le(0, 2), + trim_range_le(6, 8), + trim_range_le(10, 1), + }; + const uint64_t bad_range =3D trim_range_le(TEST_IMAGE_SIZE / 512 - 1, = 2); + size_t len =3D 512; + uint8_t *buf; + uintptr_t guest_buf =3D guest_alloc(guest_malloc, len); + + PrdtEntry prdt[] =3D { + { + .addr =3D cpu_to_le32(guest_buf), + .size =3D cpu_to_le32(len | PRDT_EOT), + }, + }; + + dev =3D get_pci_device(&bmdma_bar, &ide_bar); + + buf =3D g_malloc(len); + + /* Normal request */ + *((uint64_t *)buf) =3D trim_range[0]; + *((uint64_t *)buf + 1) =3D trim_range[1]; + + memwrite(guest_buf, buf, 2 * sizeof(uint64_t)); + + status =3D send_dma_request(CMD_DSM, 0, 1, prdt, + ARRAY_SIZE(prdt), NULL); + g_assert_cmphex(status, =3D=3D, BM_STS_INTR); + assert_bit_clear(qpci_io_readb(dev, ide_bar, reg_status), DF | ERR); + + /* Request contains invalid range */ + *((uint64_t *)buf) =3D trim_range[2]; + *((uint64_t *)buf + 1) =3D bad_range; + + memwrite(guest_buf, buf, 2 * sizeof(uint64_t)); + + status =3D send_dma_request(CMD_DSM, 0, 1, prdt, + ARRAY_SIZE(prdt), NULL); + g_assert_cmphex(status, =3D=3D, BM_STS_INTR); + assert_bit_set(qpci_io_readb(dev, ide_bar, reg_status), ERR); + assert_bit_set(qpci_io_readb(dev, ide_bar, reg_error), ABRT); + + free_pci_device(dev); + g_free(buf); +} + static void test_bmdma_short_prdt(void) { QPCIDevice *dev; @@ -963,6 +1033,7 @@ int main(int argc, char **argv) =20 qtest_add_func("/ide/bmdma/setup", test_bmdma_setup); qtest_add_func("/ide/bmdma/simple_rw", test_bmdma_simple_rw); + qtest_add_func("/ide/bmdma/trim", test_bmdma_trim); qtest_add_func("/ide/bmdma/short_prdt", test_bmdma_short_prdt); qtest_add_func("/ide/bmdma/one_sector_short_prdt", test_bmdma_one_sector_short_prdt); --=20 2.14.3