From patchwork Fri Sep 2 13:17:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 12964137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B125C38145 for ; Fri, 2 Sep 2022 13:18:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.397610.638316 (Exim 4.92) (envelope-from ) id 1oU6Ya-0002RT-LF; Fri, 02 Sep 2022 13:18:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 397610.638316; Fri, 02 Sep 2022 13:18:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oU6Ya-0002OP-F2; Fri, 02 Sep 2022 13:18:00 +0000 Received: by outflank-mailman (input) for mailman id 397610; Fri, 02 Sep 2022 13:17:59 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oU6YY-0008Qk-Sv for xen-devel@lists.xenproject.org; Fri, 02 Sep 2022 13:17:59 +0000 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a949c846-2ac1-11ed-82f2-63bd783d45fa; Fri, 02 Sep 2022 15:17:58 +0200 (CEST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 53DA45C00DF; Fri, 2 Sep 2022 09:17:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 02 Sep 2022 09:17:57 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Sep 2022 09:17:55 -0400 (EDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a949c846-2ac1-11ed-82f2-63bd783d45fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1662124677; x=1662211077; bh=FT/9EaeivQ 6Yg0Q2MVnR1LdECut0xAgreZVi3/6Rzrs=; b=dYZzdvRf5MIoXjIPWqATS14Fx5 ISV/gzq+An9kBONWb/K8oAFpremfs0fAyDISlgQf7BcxhUA6zveYEQeWdf4gttok MDW6f9RnvDt9Wakm1BmTVlNRsLL5XoFQOCxpQG6CgZajwHAJaY9Yss00ias+RMu4 MV/p7E5REt9Erbvllo5Ojq9TJS2S32sxPrLVZUB+U+lT/bp6UzniZw1ggT96m+5f ctpYcZDasBsK23t/nlP/L2IZfUnr5pLtn79yj/PlMbo0krq5oY80/JuY8R0DEQ2Z 9L7QnoSDB1LgyYNzGXPO+uzoAC2hmH58l0PGmKYyI4sma7Hk3cXJ7msPNuug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1662124677; x= 1662211077; bh=FT/9EaeivQ6Yg0Q2MVnR1LdECut0xAgreZVi3/6Rzrs=; b=N vgc5yW0Tjb2kyfTYH2j7sftlaDHvjiaD311RHKMEXFW5cTWPW+YisU5La9ghcTpN KaNIIfM6egaUB8eTzcmo+a4xq7xb6yVm9vGWa/AgCyv38IxhecGsRrHIkjz9VAWe wHZ0QAfqFLywrPsqBOVygf3VoEKdmv0LNVqHtHqYvJTbEqJr4w8mQssp03i1jWy4 xyN76gc8L26hettC9WFuRik8Pvsgxuz5ebUD3mlBkq9pIsKj87qAaOZV1dOeSXE/ 6bEa4DdFEpRdJz97gp7TTPMRsyDea3cIBouYhild0cxPfWa1NDPt1fE+NjyvIHvM XfiQRJUlsN66Kpj4Jg3rQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdeltddgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpeforghr vghkucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesih hnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpefg ueduhefgvdefheehudejheefudevueeghfekhfehleegveduteeuiedugffgffenucevlh hushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrghrmhgrrhgv khesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhm X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v6 09/10] drivers/char: fix handling cable re-plug in XHCI console driver Date: Fri, 2 Sep 2022 15:17:30 +0200 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 When cable is unplugged, dbc_ensure_running() correctly detects this situation (DBC_CTRL_DCR flag is clear), and prevent sending data immediately to the device. It gets only queued in work ring buffers. When cable is plugged in again, subsequent dbc_flush() will send the buffered data. But there is a corner case, where no subsequent data was buffered in the work buffer, but a TRB was still pending. Ring the doorbell to let the controller re-send them. For console output it is rare corner case (TRB is pending for a very short time), but for console input it is very normal case (there is always one pending TRB for input). Extract doorbell ringing into separate function to avoid duplication. Signed-off-by: Marek Marczykowski-Górecki Acked-by: Jan Beulich --- Changes in v6: - keep barriers consistent --- xen/drivers/char/xhci-dbc.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/xen/drivers/char/xhci-dbc.c b/xen/drivers/char/xhci-dbc.c index 9f7e1dd60a78..829f1d1d910f 100644 --- a/xen/drivers/char/xhci-dbc.c +++ b/xen/drivers/char/xhci-dbc.c @@ -554,6 +554,15 @@ static unsigned int dbc_work_ring_space_to_end(const struct dbc_work_ring *ring) return ring->deq - ring->enq; } +static void dbc_ring_doorbell(struct dbc *dbc, int doorbell) +{ + uint32_t __iomem *db_reg = &dbc->dbc_reg->db; + uint32_t db = (readl(db_reg) & ~DBC_DOORBELL_TARGET_MASK) | + (doorbell << DBC_DOORBELL_TARGET_SHIFT); + + writel(db, db_reg); +} + static void dbc_push_trb(struct dbc *dbc, struct xhci_trb_ring *ring, uint64_t dma, uint64_t len) { @@ -1024,6 +1033,8 @@ static bool dbc_ensure_running(struct dbc *dbc) writel(ctrl | (1U << DBC_CTRL_DRC), ®->ctrl); writel(readl(®->portsc) | (1U << DBC_PSC_PED), ®->portsc); wmb(); + dbc_ring_doorbell(dbc, dbc->dbc_iring.db); + dbc_ring_doorbell(dbc, dbc->dbc_oring.db); } return true; @@ -1041,10 +1052,6 @@ static bool dbc_ensure_running(struct dbc *dbc) static void dbc_flush(struct dbc *dbc, struct xhci_trb_ring *trb, struct dbc_work_ring *wrk) { - struct dbc_reg *reg = dbc->dbc_reg; - uint32_t db = (readl(®->db) & ~DBC_DOORBELL_TARGET_MASK) | - (trb->db << DBC_DOORBELL_TARGET_SHIFT); - if ( xhci_trb_ring_full(trb) ) return; @@ -1068,7 +1075,7 @@ static void dbc_flush(struct dbc *dbc, struct xhci_trb_ring *trb, } wmb(); - writel(db, ®->db); + dbc_ring_doorbell(dbc, trb->db); } /**