From patchwork Fri May 14 00:56:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Davis X-Patchwork-Id: 439710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8086C433ED for ; Fri, 14 May 2021 00:57:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C54D76142E for ; Fri, 14 May 2021 00:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231852AbhENA6m (ORCPT ); Thu, 13 May 2021 20:58:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231841AbhENA6k (ORCPT ); Thu, 13 May 2021 20:58:40 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E868C061574; Thu, 13 May 2021 17:57:28 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id l21so26712203iob.1; Thu, 13 May 2021 17:57:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=puac9P/1pH2gTjwWoFDjpCGPhH1RSMCtsgJsRORZsps=; b=uleaoi7pw6pKKSvyheVtu5WrdsRZupmmjo1QujTNyVGJQ8DgVhO7y4jFYpwCkJIhy2 68VKEMoj9rYzzCOBLGWHjXSfvisPps5OKm/Jqp9PN5IR9eHiG2WO3QCYVHXMwSzLNd9A O0uK2IdzmG6w6ZUgWg0XIor/h80j1JteyuNu5gj+cCHZ6YX9EGGAKryY0N7AcUPnQcIK vIdeab3oi0stWuXuAWdv1sQQaa2U/oM1C01bnoAVje+WPnbUZxDSwbt0jDrGDvqpwA1v tpqspuZUJ3yxTcLvPcN9YJEahK0dWjqgC/eQ8eTK/DAK7lEatlPwq4qb3xayS5RwgZXG 5QPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=puac9P/1pH2gTjwWoFDjpCGPhH1RSMCtsgJsRORZsps=; b=oKgXSuxl+E/nmVHpnbpaAAbJrCB6CUKEAZy1VuRda2PuquvlfEbNXd9FODyZtiH/R3 FlsJk9EaEbSZItCPiPSDBs2cAF7qpSl1sy8iDCRUy0bBJw+my2M8gi7hvgIAwnes4W9f e9rP+PldMOo45Aaw0qhbms/9LvWCPqkOK0gDLPHkq2EV/rkgQDYXZlF0+Yc1tIHW0e3L 1Dg67UBqi3lWg7T9DtpxgERRM5ZWSE1zCQ47zk/ouKSURJEWkzOuRYc1tDf77KIKS5BU PoSw+cRekYLRHBtw5bTNedFwXeaHK5QtbWp90lXcctQWvI3nfx5tXCpUg8jy/kVoP/wX nbqw== X-Gm-Message-State: AOAM530W2whbjTJ3jPAa81YhXDtu2kqyYf98fI1UuxDfrxsYm9LZazPC Au1KEoFbVo1RKGYGflLyXKg= X-Google-Smtp-Source: ABdhPJwxVFI67Tc3W19dlbyZNc1e3oxlbpVUX3LqDmZg7zTCXURGdjpwQ/MpJv+vQ6Drwqm86KEn+w== X-Received: by 2002:a6b:7413:: with SMTP id s19mr32097168iog.151.1620953848097; Thu, 13 May 2021 17:57:28 -0700 (PDT) Received: from localhost.localdomain (142-79-211-230.starry-inc.net. [142.79.211.230]) by smtp.gmail.com with ESMTPSA id g25sm1981538ion.32.2021.05.13.17.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 17:57:27 -0700 (PDT) From: Connor Davis To: Greg Kroah-Hartman Cc: Connor Davis , Jann Horn , Lee Jones , Chunfeng Yun , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH v2 1/4] usb: early: Avoid using DbC if already enabled Date: Thu, 13 May 2021 18:56:48 -0600 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Check if the debug capability is enabled in early_xdbc_parse_parameter, and if it is, return with an error. This avoids collisions with whatever enabled the DbC prior to linux starting. Signed-off-by: Connor Davis --- drivers/usb/early/xhci-dbc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c index be4ecbabdd58..ca67fddc2d36 100644 --- a/drivers/usb/early/xhci-dbc.c +++ b/drivers/usb/early/xhci-dbc.c @@ -642,6 +642,16 @@ int __init early_xdbc_parse_parameter(char *s) } xdbc.xdbc_reg = (struct xdbc_regs __iomem *)(xdbc.xhci_base + offset); + if (readl(&xdbc.xdbc_reg->control) & CTRL_DBC_ENABLE) { + pr_notice("xhci debug capability already in use\n"); + early_iounmap(xdbc.xhci_base, xdbc.xhci_length); + xdbc.xdbc_reg = NULL; + xdbc.xhci_base = NULL; + xdbc.xhci_length = 0; + + return -ENODEV; + } + return 0; } From patchwork Fri May 14 00:56:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Davis X-Patchwork-Id: 439288 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25D36C43461 for ; Fri, 14 May 2021 00:57:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0411D61206 for ; Fri, 14 May 2021 00:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231872AbhENA6p (ORCPT ); Thu, 13 May 2021 20:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbhENA6n (ORCPT ); Thu, 13 May 2021 20:58:43 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE611C061574; Thu, 13 May 2021 17:57:31 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id i7so19221319ioa.12; Thu, 13 May 2021 17:57:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kaolo11x7BDn/0QfbTzKyesjjtUEBXBeIP8y1OlvuS8=; b=oNgcz//ZDfFesKvkG1DPiB9mV5Cjp3q09B7rZg/T1l5DnxEicJF0uHcIatOkszgULL SQEJkOvXso5TLe2DSdp1mnCW64dlGG6ReyWh0c7IIHMw9cwQsc362Qp27R2rjjO8CVQd Hsw6El7hP5PO+qzVt53ggMKbyvifV+phwY4TkxOVrtqS6hgLNDvZV6mBSbUARwiLfufR Ly6yjfKaiELXc2e4+vGzFYHJ0ZIMTafqZLtowv+yMlm4zsWPw3g2DEpcIKeDfUdmlAhM CdJOXn8FA9S3rpcCWGZkKyU4k5ld6wYJ5P997dkD5hYRHf17+oUiV7WuTWVcVh/IGXQM RjMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kaolo11x7BDn/0QfbTzKyesjjtUEBXBeIP8y1OlvuS8=; b=nSDW4SN4x0/yANZTctPn5DyEWNp64CZBCcciNkVf7W8KhnJHsgdMYjCNZQ7qCOl5+J 04CGOVfUxfamGukrBj5y83W494U+PHezfDFQfOCTnfxsLhc+0noRIpaclDFiBND3iuXy EtgxpFYw4mr3vSzTw8ARIxlkxE+TC656F/wWL4TtozzOH0WTbiOPmNgPrc5ysVV/Ue+P YRuLGFyyrpqvdadxbixnZ3orrhrmW6L9smswShwdLusL6Cu7KXyXIynE8HsRX1mCf7UJ Q98FMA28uUR6OsUD30M/E6qo53uh3htakh29reUxvfWXd5wq7pIvPIzb4uJx1GbfZZKi 2olA== X-Gm-Message-State: AOAM533i0H+Mdc0chDQA0YWILBiPPEhRd6LC04yGFjOf+MSZt2HlV4Ak PF1NYnI8LauUEXxhaALF/Z4= X-Google-Smtp-Source: ABdhPJygkbUw3fnDxhQdUp2/4URvzqUJF2PZVWTCLi/wLAoCtayuWSrLwm2fsyOwJJpdijs/Hs4iAg== X-Received: by 2002:a05:6638:3013:: with SMTP id r19mr41336649jak.36.1620953851491; Thu, 13 May 2021 17:57:31 -0700 (PDT) Received: from localhost.localdomain (142-79-211-230.starry-inc.net. [142.79.211.230]) by smtp.gmail.com with ESMTPSA id g25sm1981538ion.32.2021.05.13.17.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 17:57:31 -0700 (PDT) From: Connor Davis To: Greg Kroah-Hartman , Boris Ostrovsky , Juergen Gross , Stefano Stabellini Cc: Connor Davis , Douglas Anderson , "Eric W. Biederman" , Chunfeng Yun , Petr Mladek , Sumit Garg , Lee Jones , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH v2 3/4] usb: dbgp: Fix return values for reset prep and startup Date: Thu, 13 May 2021 18:56:50 -0600 Message-Id: <0010a6165f3560f16123a142d297276e7d6c2087.1620952511.git.connojdavis@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Callers of dbgp_reset_prep treat a 0 return value as "stop using the debug port", which means they don't make any subsequent calls to dbgp_reset_prep or dbgp_external_startup. To ensure the callers' interpretation is correct, first return -EPERM from xen_dbgp_op if !xen_initial_domain(). This ensures that both xen_dbgp_reset_prep and xen_dbgp_external_startup return 0 iff the PHYSDEVOP_DBGP_RESET_{PREPARE,DONE} hypercalls succeed. Also update xen_dbgp_reset_prep and xen_dbgp_external_startup to return -EPERM when !CONFIG_XEN_DOM0 for consistency. Next, return nonzero from dbgp_reset_prep if xen_dbgp_reset_prep returns 0. The nonzero value ensures that callers of dbgp_reset_prep will subsequently call dbgp_external_startup when it is safe to do so. Also invert the return values from dbgp_external_startup for consistency with dbgp_reset_prep (this inversion has no functional change since no callers actually check the value). Signed-off-by: Connor Davis Reviewed-by: Boris Ostrovsky --- drivers/usb/early/ehci-dbgp.c | 9 ++++++--- drivers/xen/dbgp.c | 2 +- include/linux/usb/ehci-dbgp.h | 14 +++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c index 45b42d8f6453..ff993d330c01 100644 --- a/drivers/usb/early/ehci-dbgp.c +++ b/drivers/usb/early/ehci-dbgp.c @@ -970,8 +970,8 @@ int dbgp_reset_prep(struct usb_hcd *hcd) int ret = xen_dbgp_reset_prep(hcd); u32 ctrl; - if (ret) - return ret; + if (!ret) + return 1; dbgp_not_safe = 1; if (!ehci_debug) @@ -995,7 +995,10 @@ EXPORT_SYMBOL_GPL(dbgp_reset_prep); int dbgp_external_startup(struct usb_hcd *hcd) { - return xen_dbgp_external_startup(hcd) ?: _dbgp_external_startup(); + if (!xen_dbgp_external_startup(hcd)) + return 1; + + return !_dbgp_external_startup(); } EXPORT_SYMBOL_GPL(dbgp_external_startup); #endif /* USB */ diff --git a/drivers/xen/dbgp.c b/drivers/xen/dbgp.c index fef32dd1a5dc..d54f98380e6f 100644 --- a/drivers/xen/dbgp.c +++ b/drivers/xen/dbgp.c @@ -15,7 +15,7 @@ static int xen_dbgp_op(struct usb_hcd *hcd, int op) struct physdev_dbgp_op dbgp; if (!xen_initial_domain()) - return 0; + return -EPERM; dbgp.op = op; diff --git a/include/linux/usb/ehci-dbgp.h b/include/linux/usb/ehci-dbgp.h index 62ab3805172d..c0e98557efc0 100644 --- a/include/linux/usb/ehci-dbgp.h +++ b/include/linux/usb/ehci-dbgp.h @@ -56,28 +56,32 @@ extern int xen_dbgp_external_startup(struct usb_hcd *); #else static inline int xen_dbgp_reset_prep(struct usb_hcd *hcd) { - return 1; /* Shouldn't this be 0? */ + return -EPERM; } static inline int xen_dbgp_external_startup(struct usb_hcd *hcd) { - return -1; + return -EPERM; } #endif #ifdef CONFIG_EARLY_PRINTK_DBGP -/* Call backs from ehci host driver to ehci debug driver */ +/* + * Call backs from ehci host driver to ehci debug driver. + * Returns 0 if the debug port should stopped being used, + * nonzero otherwise. + */ extern int dbgp_external_startup(struct usb_hcd *); extern int dbgp_reset_prep(struct usb_hcd *); #else static inline int dbgp_reset_prep(struct usb_hcd *hcd) { - return xen_dbgp_reset_prep(hcd); + return !xen_dbgp_reset_prep(hcd); } static inline int dbgp_external_startup(struct usb_hcd *hcd) { - return xen_dbgp_external_startup(hcd); + return !xen_dbgp_external_startup(hcd); } #endif From patchwork Fri May 14 00:56:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Davis X-Patchwork-Id: 439709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 195C9C433B4 for ; Fri, 14 May 2021 00:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8F8C6142E for ; Fri, 14 May 2021 00:57:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231841AbhENA6q (ORCPT ); Thu, 13 May 2021 20:58:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231861AbhENA6o (ORCPT ); Thu, 13 May 2021 20:58:44 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2349EC061574; Thu, 13 May 2021 17:57:34 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id d11so6153893iod.5; Thu, 13 May 2021 17:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=73bCew6rTmXHX45d4vmDXZwsqCa9qTPna/Qeda9j70Q=; b=OWiu1eeiDjY/XbCbDJVr3kheFbNnpd+b6JgU9t/vkdpI9pGe9e642trB1IIKCogmK6 2x3rnx6FAZeb0kzyLMXFZPeLzSU8UFDfAYEQl1IZSXrP0mt9lYpM11u6gIbfv/L4jb2T 7FTU4qK8dsedPAjW6QjpAKdFoRCG3tL/6UIBmKtGX0PG9ha6n9eBVwmEOYdhmBRaqfDl OBMfukolCkeSB+D5mH7KBhLRUYIREf9Hjo7NBudYTWWFFNzUAFvWWvEur5T+Rgs+5ptt CvqVph2XwLV5G+Ihq02r2AuxTAEPjp5mUDItT72UIbq9S4e/uX7eaIntRpyDIcDzBIPx fZmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=73bCew6rTmXHX45d4vmDXZwsqCa9qTPna/Qeda9j70Q=; b=YQ7DWTl3X6hAfW4DidXaOfTOJla5D8bAS1OvhIKKj7vqqnmC1jI7A+uk9d/1Ua0Phh UHy15KC+DlMDbOg+cnFKDoEiqOESm76m4uVw+xy3hzGYoIfe4pbtcKeRBne1KYZCRGLk iRtbR3ykUVb86RUyBvZiT61Hc+vWuj5PJqo114a0C2wAUqTCDleicbhmUjGZSDwxASMM c91jbf2Drbu1wSYdsgYU1L1ex3LpkU1FGIIYq/pjj39whmNqfOoyHJDTzbZX8SFhgqJL 7gVC4KWCX7rQJ33m9iKAj0i9aGUUGhyoIfzI9dJZGfkFCCpDc84F1YftqvVUc4xPukk7 SLyQ== X-Gm-Message-State: AOAM531pvqymqCEILsWTfAixNzkHA9YwyQQlt428vDPJqZo21wicqk4m u0rad1Rzcfmte9SeIW7IHhE= X-Google-Smtp-Source: ABdhPJyc14f+idUQGuxzMTRpgDqLeTm6a2MTtRB9zAQhuQxUvXuWK89n1nBtt5rmwV5lQMRfJff/UQ== X-Received: by 2002:a02:b057:: with SMTP id q23mr18689622jah.25.1620953853645; Thu, 13 May 2021 17:57:33 -0700 (PDT) Received: from localhost.localdomain (142-79-211-230.starry-inc.net. [142.79.211.230]) by smtp.gmail.com with ESMTPSA id g25sm1981538ion.32.2021.05.13.17.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 17:57:33 -0700 (PDT) From: Connor Davis To: Greg Kroah-Hartman Cc: Connor Davis , Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] usb: xhci: Notify xen when DbC is unsafe to use Date: Thu, 13 May 2021 18:56:51 -0600 Message-Id: <5c4a8a65a038563f2d20a734d74d2ed4a0f2d69e.1620952511.git.connojdavis@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When running as a dom0 guest on Xen, check if the USB3 debug capability is enabled before xHCI reset, suspend, and resume. If it is, call xen_dbgp_reset_prep() to notify Xen that it is unsafe to touch MMIO registers until the next xen_dbgp_external_startup(). This notification allows Xen to avoid undefined behavior resulting from MMIO access when the host controller's CNR bit is set or when the device transitions to D3hot. Signed-off-by: Connor Davis --- drivers/usb/host/xhci-dbgcap.h | 19 ++++++++++++++ drivers/usb/host/xhci.c | 47 ++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 1 + 3 files changed, 67 insertions(+) diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h index c70b78d504eb..332be531bebd 100644 --- a/drivers/usb/host/xhci-dbgcap.h +++ b/drivers/usb/host/xhci-dbgcap.h @@ -227,4 +227,23 @@ static inline int xhci_dbc_resume(struct xhci_hcd *xhci) return 0; } #endif /* CONFIG_USB_XHCI_DBGCAP */ + +#ifdef CONFIG_XEN_DOM0 +#include + +int xen_dbgp_reset_prep(struct usb_hcd *hcd); +int xen_dbgp_external_startup(struct usb_hcd *hcd); + +void xhci_dbc_external_reset_prep(struct xhci_hcd *xhci); +void xhci_dbc_external_reset_done(struct xhci_hcd *xhci); +#else +static inline void xhci_dbc_external_reset_prep(struct xhci_hcd *xhci) +{ +} + +static inline void xhci_dbc_external_reset_done(struct xhci_hcd *xhci) +{ +} +#endif /* CONFIG_XEN_DOM0 */ + #endif /* __LINUX_XHCI_DBGCAP_H */ diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index ca9385d22f68..3ff7879069ec 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -37,6 +37,47 @@ static unsigned long long quirks; module_param(quirks, ullong, S_IRUGO); MODULE_PARM_DESC(quirks, "Bit flags for quirks to be enabled as default"); +#ifdef CONFIG_XEN_DOM0 +void xhci_dbc_external_reset_prep(struct xhci_hcd *xhci) +{ + struct dbc_regs __iomem *regs; + void __iomem *base; + int dbc_cap; + + if (!xen_initial_domain()) + return; + + base = &xhci->cap_regs->hc_capbase; + dbc_cap = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_DEBUG); + + if (!dbc_cap) + return; + + xhci->external_dbc = 0; + regs = base + dbc_cap; + + if (readl(®s->control) & DBC_CTRL_DBC_ENABLE) { + if (xen_dbgp_reset_prep(xhci_to_hcd(xhci))) + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "// Failed to reset external DBC"); + else { + xhci->external_dbc = 1; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "// Completed reset of external DBC"); + } + } +} + +void xhci_dbc_external_reset_done(struct xhci_hcd *xhci) +{ + if (!xen_initial_domain() || !xhci->external_dbc) + return; + + if (xen_dbgp_external_startup(xhci_to_hcd(xhci))) + xhci->external_dbc = 0; +} +#endif + static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring) { struct xhci_segment *seg = ring->first_seg; @@ -180,6 +221,8 @@ int xhci_reset(struct xhci_hcd *xhci) return 0; } + xhci_dbc_external_reset_prep(xhci); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC"); command = readl(&xhci->op_regs->command); command |= CMD_RESET; @@ -211,6 +254,8 @@ int xhci_reset(struct xhci_hcd *xhci) */ ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, 10 * 1000 * 1000); + if (!ret) + xhci_dbc_external_reset_done(xhci); xhci->usb2_rhub.bus_state.port_c_suspend = 0; xhci->usb2_rhub.bus_state.suspended_ports = 0; @@ -991,6 +1036,7 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup) return 0; xhci_dbc_suspend(xhci); + xhci_dbc_external_reset_prep(xhci); /* Don't poll the roothubs on bus suspend. */ xhci_dbg(xhci, "%s: stopping port polling.\n", __func__); @@ -1225,6 +1271,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) spin_unlock_irq(&xhci->lock); xhci_dbc_resume(xhci); + xhci_dbc_external_reset_done(xhci); done: if (retval == 0) { diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 2595a8f057c4..61d8efc9eef2 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1920,6 +1920,7 @@ struct xhci_hcd { struct list_head regset_list; void *dbc; + int external_dbc; /* platform-specific data -- must come last */ unsigned long priv[] __aligned(sizeof(s64)); };