From patchwork Wed Oct 20 08:18:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 68397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8ADDEB70A6 for ; Wed, 20 Oct 2010 19:28:49 +1100 (EST) Received: from localhost ([127.0.0.1]:54205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8U1c-00082l-6b for incoming@patchwork.ozlabs.org; Wed, 20 Oct 2010 04:27:56 -0400 Received: from [140.186.70.92] (port=43777 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8Tyh-0004AR-R0 for qemu-devel@nongnu.org; Wed, 20 Oct 2010 04:25:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8Tt4-0000Wc-FL for qemu-devel@nongnu.org; Wed, 20 Oct 2010 04:19:08 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:46425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8Tt3-0000Vu-Uo for qemu-devel@nongnu.org; Wed, 20 Oct 2010 04:19:06 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id D0DE38740B; Wed, 20 Oct 2010 17:19:03 +0900 (JST) Received: (nullmailer pid 20060 invoked by uid 1000); Wed, 20 Oct 2010 08:19:01 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org Date: Wed, 20 Oct 2010 17:18:58 +0900 Message-Id: <99c473b524046dac0c98eb2a10df3b682afee1c2.1287562197.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.7.1.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: skandasa@cisco.com, adnan@khaleel.us, wexu2@cisco.com, mst@redhat.com, yamahata@valinux.co.jp, etmartin@cisco.com Subject: [Qemu-devel] [PATCH v6 09/12] pcie/aer: glue aer error injection into qemu monitor X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org introduce pcie_aer_inject_error command. Signed-off-by: Isaku Yamahata --- Changes v3 -> v4: - s/PCIE_AER/PCIEAER/g for structure names. - compilation adjustment. Changes v2 -> v3: - compilation adjustment. --- hw/pcie_aer.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-monitor.hx | 22 ++++++++++++++ sysemu.h | 5 +++ 3 files changed, 111 insertions(+), 0 deletions(-) diff --git a/hw/pcie_aer.c b/hw/pcie_aer.c index b8cede3..459e0d7 100644 --- a/hw/pcie_aer.c +++ b/hw/pcie_aer.c @@ -19,6 +19,8 @@ */ #include "sysemu.h" +#include "qemu-objects.h" +#include "monitor.h" #include "pci_bridge.h" #include "pcie.h" #include "msix.h" @@ -778,3 +780,85 @@ const VMStateDescription vmstate_pcie_aer_log = { } }; +void pcie_aer_inject_error_print(Monitor *mon, const QObject *data) +{ + QDict *qdict; + int devfn; + assert(qobject_type(data) == QTYPE_QDICT); + qdict = qobject_to_qdict(data); + + devfn = (int)qdict_get_int(qdict, "devfn"); + monitor_printf(mon, "OK domain: %x, bus: %x devfn: %x.%x\n", + (int) qdict_get_int(qdict, "domain"), + (int) qdict_get_int(qdict, "bus"), + PCI_SLOT(devfn), PCI_FUNC(devfn)); +} + +int do_pcie_aer_inejct_error(Monitor *mon, + const QDict *qdict, QObject **ret_data) +{ + const char *pci_addr = qdict_get_str(qdict, "pci_addr"); + int dom; + int bus; + unsigned int slot; + unsigned int func; + PCIDevice *dev; + PCIEAERErr err; + + /* Ideally qdev device path should be used. + * However at the moment there is no reliable way to determine + * wheher a given qdev is pci device or not. + * so pci_addr is used. + */ + if (pci_parse_devaddr(pci_addr, &dom, &bus, &slot, &func)) { + monitor_printf(mon, "invalid pci address %s\n", pci_addr); + return -1; + } + dev = pci_find_device(pci_find_root_bus(dom), bus, slot, func); + if (!dev) { + monitor_printf(mon, "device is not found. 0x%x:0x%x.0x%x\n", + bus, slot, func); + return -1; + } + if (!pci_is_express(dev)) { + monitor_printf(mon, "the device doesn't support pci express. " + "0x%x:0x%x.0x%x\n", + bus, slot, func); + return -1; + } + + err.status = qdict_get_int(qdict, "error_status"); + err.source_id = (pci_bus_num(dev->bus) << 8) | dev->devfn; + + err.flags = 0; + if (qdict_get_int(qdict, "is_correctable")) { + err.flags |= PCIE_AER_ERR_IS_CORRECTABLE; + } + if (qdict_get_int(qdict, "advisory_non_fatal")) { + err.flags |= PCIE_AER_ERR_MAYBE_ADVISORY; + } + if (qdict_haskey(qdict, "tlph0")) { + err.flags |= PCIE_AER_ERR_HEADER_VALID; + } + if (qdict_haskey(qdict, "hpfx0")) { + err.flags |= PCIE_AER_ERR_TLP_PRESENT; + } + + err.header[0] = qdict_get_try_int(qdict, "tlph0", 0); + err.header[1] = qdict_get_try_int(qdict, "tlph1", 0); + err.header[2] = qdict_get_try_int(qdict, "tlph2", 0); + err.header[3] = qdict_get_try_int(qdict, "tlph3", 0); + + err.prefix[0] = qdict_get_try_int(qdict, "hpfx0", 0); + err.prefix[1] = qdict_get_try_int(qdict, "hpfx1", 0); + err.prefix[2] = qdict_get_try_int(qdict, "hpfx2", 0); + err.prefix[3] = qdict_get_try_int(qdict, "hpfx3", 0); + + pcie_aer_inject_error(dev, &err); + *ret_data = qobject_from_jsonf("{ 'domain': %d, 'bus': %d, 'devfn': %d }", + pci_find_domain(dev->bus), + pci_bus_num(dev->bus), dev->devfn); + assert(*ret_data); + + return 0; +} diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 965c754..ccb3d0e 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -1168,6 +1168,28 @@ Push PCI express attention button ETEXI { + .name = "pcie_aer_inject_error", + .args_type = "advisory_non_fatal:-a,is_correctable:-c," + "pci_addr:s,error_status:i," + "tlph0:i?,tlph1:i?,tlph2:i?,tlph3:i?," + "hpfx0:i?,hpfx1:i?,hpfx2:i?,hpfx3:i?", + .params = "[-a] [-c] [[:]:]. " + " " + "[] " + "[]", + .help = "inject pcie aer error " + "(use -a for advisory non fatal error) " + "(use -c for correctrable error)", + .user_print = pcie_aer_inject_error_print, + .mhandler.cmd_new = do_pcie_aer_inejct_error, + }, + +STEXI +@item pcie_abp +Push PCI express attention button +ETEXI + + { .name = "host_net_add", .args_type = "device:s,opts:s?", .params = "tap|user|socket|vde|dump [options]", diff --git a/sysemu.h b/sysemu.h index cca411d..2f7157c 100644 --- a/sysemu.h +++ b/sysemu.h @@ -155,6 +155,11 @@ void pcie_attention_button_push_print(Monitor *mon, const QObject *data); int pcie_attention_button_push(Monitor *mon, const QDict *qdict, QObject **ret_data); +/* pcie aer error injection */ +void pcie_aer_inject_error_print(Monitor *mon, const QObject *data); +int do_pcie_aer_inejct_error(Monitor *mon, + const QDict *qdict, QObject **ret_data); + /* serial ports */ #define MAX_SERIAL_PORTS 4