Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2595124lqt; Mon, 22 Apr 2024 16:00:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBE2+lW6S6ZVfTCeHKfu4Lw/AHWmVAnn/mG2yZv/fAEeaJamwV40jo9K6BDKsBe75xX9N1OvJkLvucKNjylwWv9ykLNYOPb/bFj0loHA== X-Google-Smtp-Source: AGHT+IGFrJzQz9N60NTx5QIIrtu2v2klPIAC4xcbmCd+96pKPCNTnx+kGHSxLKNx+jITXuviEyat X-Received: by 2002:a05:6214:18f:b0:6a0:7c20:88b6 with SMTP id q15-20020a056214018f00b006a07c2088b6mr4887347qvr.18.1713826836971; Mon, 22 Apr 2024 16:00:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713826836; cv=pass; d=google.com; s=arc-20160816; b=BKSW+MWtq7hZfBLMvFGMFv5OykSor22a7pI7N+IeWlXvo5IApDOzHb4DRqZgZGLnDw K59kiwco/sGrNFWPzk/Z6YSaxgcIbhWGFiZZAbzU49dxrKZyvRhrcIib//1jwltOE/n1 14MocbpQuhtSvH06yu3fuqb4On9yp0bsCAlMYqrYx2wE9wURYU5KCyKy6vrhmdWxx6hW lyu1rYSO5BwLF98mof7XF3C817nkX1JTa6f4PMA2SvrO1GHqg1ob6C+HvrpImjjg847P GuEsGsZNn8qXdpRVBZ6tsRHd0GXqiMXDZnn8XLoV0QssJbJZlCr7bErfRMwBYaoautj/ q6EQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ss4yzKX67XBF/y2hls1QPAF54WxpQJYALhxIDTWi8nU=; fh=usWEz1eJjYCle08WABmDyuqCrJGq9m48/LVlmybnzRs=; b=OjVMeYvxJcrunldRxCJfuXFJF0Ck6pxcKpWdG3DqerssYwioPO/NsdGjN8d06WrjGu ecgy3CX9FJ+IqV6pixH4klSWafj1vmpfe7nzmnzDwU9/1zAlEd5WzYk49oLQndJiaTul zodo3Wj0ny4VQ8S3W2TE0Xfs1Rk80a7uAILMkp0ZdPilVWdoO9N8eXUkSfIzvUHKXJES UnRXFGq3ddowePpsOshEnOHDQXKeo9+POsSI2hLMvnoNxqrSg55M1xp6zYbbx8Ar2Kq6 Cwb9ef63bUQTM2Flaxyi++LBXONpvM6RYtKnUoChoEdHRWSPzgY5wNOkEtImIjSf98xP QbCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IP6pcDgT; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-154156-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154156-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ke14-20020a056214300e00b0069b56f0e477si11603715qvb.27.2024.04.22.16.00.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 16:00:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154156-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IP6pcDgT; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-154156-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154156-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A3B531C213D5 for ; Mon, 22 Apr 2024 23:00:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AA7516C6B5; Mon, 22 Apr 2024 22:50:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="IP6pcDgT" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 342951586C8; Mon, 22 Apr 2024 22:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713826212; cv=none; b=W2d1UoXUzFrfQUsQW2XDI1q3kF1iPBut9RxL1nfNE/Pp2nnYOpt2rWglwd0EyJZF0lXMTrl4lv98e3Z0jgo+Y9Ttx66yu48sQU4mXBZx9FPCj6/16GJ7WfgSW1uCWM3SgytWd2z25XXnb9ntpR+vGyWQHdtkKb6gJzQlGjVuYac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713826212; c=relaxed/simple; bh=PyacoRHyPt11V8Xo/YXoM2fjad3a11BzOgcVRgr3BJs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aIMsLr+mau2p+aEJx0p1o1kspuB9ufEB4O2TmAhlr61/lsVbY/RRzczv4LRIKvrfIk/mY234BACAXo2E2KlATiE1f2w4YtvAo62jehU+4nsmKfYEBctC6ZIrd1E+s4NPrdB1Rt8dZWvDVbzYAD3n75DZGPerGRpyMnzHyJdkzb4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=IP6pcDgT; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 43MLivAn030379; Mon, 22 Apr 2024 22:49:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=Ss4yzKX67XBF/y2hls1Q PAF54WxpQJYALhxIDTWi8nU=; b=IP6pcDgT4LSG20E4N330alIK/LzbTaNJOdG7 Kq6C2xT3sZw9jmUSQ4v/xzTeTgNp2js8glr7U4eqpxOA9HP3pskpP6Ob3eXI6fud LxzItj4Sus5ypEX5YQPhqanp0D4d2WI+b2ZKOdZ1VTn23VY+9AhX90PguHi3VTlP ASBqOsCWZXV+HB7ULVx/IdiQbEyHbixTL7U0sX/RRCW80LNBBaSh/xhgj4JcTcR9 25bVtt332lzsCi6fP3bGyGFgzVbTA1+hwE3r37QQGNKOLIXRz/25Z6C3NhnOi2da Pqh3MTVryUZ6/DR8quQSrNFJPqs9oHQVUjkakFCmDHMcqU8qgw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3xnn82hskd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Apr 2024 22:49:40 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 43MMnI2G027708 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Apr 2024 22:49:18 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 22 Apr 2024 15:49:18 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v19 07/41] usb: host: xhci-mem: Cleanup pending secondary event ring events Date: Mon, 22 Apr 2024 15:48:32 -0700 Message-ID: <20240422224906.15868-8-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240422224906.15868-1-quic_wcheng@quicinc.com> References: <20240422224906.15868-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: UQUag2D2v0hpZmJn9BBdIwBL3dAdJVlD X-Proofpoint-ORIG-GUID: UQUag2D2v0hpZmJn9BBdIwBL3dAdJVlD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-22_16,2024-04-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=944 priorityscore=1501 clxscore=1015 suspectscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 spamscore=0 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2404220096 As part of xHCI bus suspend, the XHCI is halted. However, if there are pending events in the secondary event ring, it is observed that the xHCI controller stops responding to further commands upon host or device initiated bus resume. Iterate through all pending events and update the dequeue pointer to the beginning of the event ring. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-mem.c | 7 ++++++- drivers/usb/host/xhci-ring.c | 33 ++++++++++++++++++++++++++++++++- drivers/usb/host/xhci.h | 5 +++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 69dd86669883..d686de0581b3 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1816,7 +1816,7 @@ xhci_remove_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) tmp &= ERST_SIZE_MASK; writel(tmp, &ir->ir_set->erst_size); - xhci_write_64(xhci, ERST_EHB, &ir->ir_set->erst_dequeue); + xhci_update_erst_dequeue(xhci, ir, true); } } @@ -1859,6 +1859,11 @@ void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrup return; } + /* + * Cleanup secondary interrupter to ensure there are no pending events. + * This also updates event ring dequeue pointer back to the start. + */ + xhci_skip_sec_intr_events(xhci, ir->event_ring, ir); intr_num = ir->intr_num; xhci_remove_interrupter(xhci, ir); diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 6c7a21f522cd..b9c2c23d5717 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3034,7 +3034,7 @@ static int xhci_handle_event_trb(struct xhci_hcd *xhci, struct xhci_interrupter * - When all events have finished * - To avoid "Event Ring Full Error" condition */ -static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, +void xhci_update_erst_dequeue(struct xhci_hcd *xhci, struct xhci_interrupter *ir, bool clear_ehb) { @@ -3134,6 +3134,37 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir return 0; } +/* + * Move the event ring dequeue pointer to skip events kept in the secondary + * event ring. This is used to ensure that pending events in the ring are + * acknowledged, so the XHCI HCD can properly enter suspend/resume. The + * secondary ring is typically maintained by an external component. + */ +void xhci_skip_sec_intr_events(struct xhci_hcd *xhci, + struct xhci_ring *ring, struct xhci_interrupter *ir) +{ + union xhci_trb *current_trb; + u64 erdp_reg; + dma_addr_t deq; + + /* disable irq, ack pending interrupt and ack all pending events */ + xhci_disable_interrupter(ir); + + /* last acked event trb is in erdp reg */ + erdp_reg = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); + deq = (dma_addr_t)(erdp_reg & ERST_PTR_MASK); + if (!deq) { + xhci_err(xhci, "event ring handling not required\n"); + return; + } + + current_trb = ir->event_ring->dequeue; + /* read cycle state of the last acked trb to find out CCS */ + ring->cycle_state = le32_to_cpu(current_trb->event_cmd.flags) & TRB_CYCLE; + + xhci_handle_events(xhci, ir); +} + /* * xHCI spec says we can get an interrupt, and if the HC has an error condition, * we might get bad data out of the event ring. Section 4.10.2.7 has a list of diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 57ad141242ca..79dc3801d359 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1841,6 +1841,8 @@ struct xhci_interrupter * xhci_create_secondary_interrupter(struct usb_hcd *hcd, int num_seg); void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrupter *ir); +void xhci_skip_sec_intr_events(struct xhci_hcd *xhci, + struct xhci_ring *ring, struct xhci_interrupter *ir); /* xHCI host controller glue */ typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); @@ -1932,6 +1934,9 @@ void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring); unsigned int count_trbs(u64 addr, u64 len); int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int suspend, gfp_t gfp_flags); +void xhci_update_erst_dequeue(struct xhci_hcd *xhci, + struct xhci_interrupter *ir, + bool clear_ehb); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,