Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2789206rdb; Mon, 12 Feb 2024 17:35:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWD3/z5i0QhG+uYuCrxn4VuV5gYmynznEl9i41qNySJVZ3qM+eR2t1NELYgnM/72earvvq7AnuouFSMh90hF6KEz9mdp79P8y9jP8yLNw== X-Google-Smtp-Source: AGHT+IGk+XlHsU+P1EHtGd+dN4qkYJD7oIZsKASg2Dmaz+DEnlIByjJPwUrXejqCZbJnw7Is1VfN X-Received: by 2002:a05:6a21:9103:b0:19e:9ad6:9213 with SMTP id tn3-20020a056a21910300b0019e9ad69213mr11452780pzb.2.1707788135716; Mon, 12 Feb 2024 17:35:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788135; cv=pass; d=google.com; s=arc-20160816; b=pN1jKSDAwmhZ0w06D0RmlL3fXjanK6NTzYVuxCzx8qqsswkIFVFntxLbvFS4TIO6Ww 6uqoQUw4aG9XbAdtrRI6bEXKKQSC3lw8ipGlK4ThJe4s58W01u727MyBGXvxlpXiphIZ vdtYbkkQuWGoVsaigCA7NooLwkuo0RbRxAk+pqgZh/b41U1hQffsMZrrGsdE5Yxno+Tt Ni24J7p+NSaevVHJfUfBezN0+LiZqc7KSQS4vrRQSVyzZttM/btY22YQnZYJZqHxtS4T 36biE8XCY33oPgk4HPumDMXYsspTUOi3fSgQZT8ONIN15+WRyV/r/KOMFgrsGKwDYb82 pPgQ== 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=r/s48r7Nd+rNVTCx+HL87L+3Njw26bFVh6+6XCcEXOU=; fh=hwMScv0oV2C0NHKVobT8K9odEbyVtSmSKn2qZMUzCh0=; b=WrWTnk4LRlM3bp5du/WKsGcb6oGTKCMHCc75h19fIoscL0dCkkraIKNj/ZA3GnetuO SD0i8b8RNZ5xoaBZpfuFNY5N5cJ/+SKJkAUh/Jt2cLEEuytZZbM41zdgAiUAERxFYahJ lsRoRKlJ6pv/3TjzlYykUzPuSrTs9k2VZxqpC5n8dPijICXNJSAoblGqvWbZfVb63EZ6 8uk0HCmGlL+3P9S4t8Fj0srhzJv7/fs+CSrnbSVGP8psVIj7LWAGneNJXfx1L54m1oKh QP0eEob39kbKPGjSEaKp3VZCoe2OcKxcbjdsuOoGtaLdxi87ybts2VWtU2DI3HXrQQDa V6hA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=a3NiQawg; 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-62791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWefiwbapY7mYPAQ8NxPWlQylUyMhofaUho+g7bPjmQSCX7IaaKMcEbj4aa7VpzuMHp/feSYzmsHfUCJiSdAoa1JLWBTsCwdeTMWQU+AQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h14-20020a170902680e00b001db29be0087si984313plk.547.2024.02.12.17.35.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:35:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=a3NiQawg; 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-62791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62791-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9202E288BD7 for ; Tue, 13 Feb 2024 01:25:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A96EE5A7A6; Tue, 13 Feb 2024 00:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="a3NiQawg" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 A9BA8224FB; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; cv=none; b=ZD/7ThF/7FfHK7hDT37KQB1tcsM0EEUPKsZsZRNbCH8ZIZjm9/FdKHjs9MZDKhgzG0TL783UUi1aLg/FIavlR0yfhv4qrI5vVrIBlC91MhD4aLkIwZg5jCKrNL1AJf+yom3dnuHfzDG90WHV2Uf9BoX53QFz+UYQXEm/VdACQoI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; c=relaxed/simple; bh=V8MdAsKTPp0AteG57V12qaeFcyZsxonTIhHZ2e6F4Bs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MFsC7R4AGSSAxfbmk2en6/jdQ3T9En11ZtShvJKH/lJXoQ4JceGD7akn3MT+zt5sMwz5cmt2hWnm/2u5bTwn1kfAJ3kBSxtYJ5nSdcveTqVbc/mLctC966GVRIkfct4KQlqQIAG6vJlI5KoD+BruvTF314/BJq4pDX9CiTD/Sik= 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=a3NiQawg; arc=none smtp.client-ip=205.220.180.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 (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0bZj9005335; Tue, 13 Feb 2024 00:54:36 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=r/s48r7Nd+rNVTCx+HL8 7L+3Njw26bFVh6+6XCcEXOU=; b=a3NiQawgLCWE1XTKxeDeI6RWlDd12MzOPzpb awDzHtKo/O4kL1aDJu3eoca9G7U7+H0UKLywqgHYg5ycpT+jUvtvDvR+V+qtXbRx VD/ThNo2cRLcuW9HHESGx324nY9RlgzVNrdudqKMaD5G9lS20fASbwg4vOjCmU1T x/nchYFGZoNfCWU/NDWRxuCP7VnO6e5BYF7cIf1JcUYDtIRPMulsm0emWtzw7a58 LHxlzIYKszPE5tQHiflI1jM11MmNyQPEJmNRgEVbkXAgmOnXtr+IM/8M48L3Rb9X oh7NhAXAWvEidOrPaArMtyS8yLy9m3QyJyTCKXfb8WQ/Mjq3Dw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4ty9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sYWW026767 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:34 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.1118.40; Mon, 12 Feb 2024 16:54:34 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 06/50] xhci: move event processing for one interrupter to a separate function Date: Mon, 12 Feb 2024 16:53:38 -0800 Message-ID: <20240213005422.3121-7-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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: qBvbpYauSl0v5LFXg7yx5sJbrhM-xZAt X-Proofpoint-ORIG-GUID: qBvbpYauSl0v5LFXg7yx5sJbrhM-xZAt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 From: Mathias Nyman Split the main XHCI interrupt handler into a different API, so that other potential interrupters can utilize similar event ring handling. A scenario would be if a secondary interrupter required to skip pending events in the event ring, which would warrant a similar set of operations. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 87 +++++++++++++++++------------------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 0289d77839cf..338b6fddedc3 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3019,6 +3019,46 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, } } +static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir) +{ + int event_loop = 0; + u64 temp; + + xhci_clear_interrupt_pending(xhci, ir); + + if (xhci->xhc_state & XHCI_STATE_DYING || + xhci->xhc_state & XHCI_STATE_HALTED) { + xhci_dbg(xhci, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?\n"); + + /* Clear the event handler busy flag (RW1C) */ + temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); + xhci_write_64(xhci, temp | ERST_EHB, &ir->ir_set->erst_dequeue); + return -ENODEV; + } + + while (xhci_handle_event(xhci, ir) > 0) { + /* + * If half a segment of events have been handled in one go then + * update ERDP, and force isoc trbs to interrupt more often + */ + if (event_loop++ > TRBS_PER_SEGMENT / 2) { + xhci_update_erst_dequeue(xhci, ir, false); + + if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) + ir->isoc_bei_interval = ir->isoc_bei_interval / 2; + + event_loop = 0; + } + + /* Update SW event ring dequeue pointer */ + inc_deq(xhci, ir->event_ring); + } + + xhci_update_erst_dequeue(xhci, ir, true); + + return 0; +} + /* * 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 @@ -3027,11 +3067,8 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, irqreturn_t xhci_irq(struct usb_hcd *hcd) { struct xhci_hcd *xhci = hcd_to_xhci(hcd); - struct xhci_interrupter *ir; irqreturn_t ret = IRQ_NONE; - u64 temp_64; u32 status; - int event_loop = 0; spin_lock(&xhci->lock); /* Check if the xHC generated the interrupt, or the irq is shared */ @@ -3064,50 +3101,10 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) */ status |= STS_EINT; writel(status, &xhci->op_regs->status); - - /* This is the handler of the primary interrupter */ - ir = xhci->interrupters[0]; - - xhci_clear_interrupt_pending(xhci, ir); - - if (xhci->xhc_state & XHCI_STATE_DYING || - xhci->xhc_state & XHCI_STATE_HALTED) { - xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " - "Shouldn't IRQs be disabled?\n"); - /* Clear the event handler busy flag (RW1C); - * the event ring should be empty. - */ - temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); - xhci_write_64(xhci, temp_64 | ERST_EHB, - &ir->ir_set->erst_dequeue); - ret = IRQ_HANDLED; - goto out; - } - - /* FIXME this should be a delayed service routine - * that clears the EHB. - */ - while (xhci_handle_event(xhci, ir) > 0) { - /* - * If half a segment of events have been handled in one go then - * update ERDP, and force isoc trbs to interrupt more often - */ - if (event_loop++ > TRBS_PER_SEGMENT / 2) { - xhci_update_erst_dequeue(xhci, ir, false); - - if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) - ir->isoc_bei_interval = ir->isoc_bei_interval / 2; - - event_loop = 0; - } - - /* Update SW event ring dequeue pointer */ - inc_deq(xhci, ir->event_ring); - } - - xhci_update_erst_dequeue(xhci, ir, true); ret = IRQ_HANDLED; + /* This is the handler of the primary interrupter */ + xhci_handle_events(xhci, xhci->interrupters[0]); out: spin_unlock(&xhci->lock);