Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1435018rdb; Fri, 16 Feb 2024 16:33:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWa5GQ/M/2xMUWq/AqwANmvofC5mio6uig5GTHi4Gn9wzmrVZhxhJvvPj6/dgi7VQPo+S4FirJXCxVH9WyCStub4DVRNBWaj0JgVPRHrA== X-Google-Smtp-Source: AGHT+IFI682ksIO1KnnXd6giG4jcfy4lAMNBNyZKlGKRRzop5vJzJHlxnNjkGzEXhjKk2FdWtWwY X-Received: by 2002:a05:6871:724b:b0:21e:8f7b:6e57 with SMTP id ml11-20020a056871724b00b0021e8f7b6e57mr140697oac.55.1708129981723; Fri, 16 Feb 2024 16:33:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708129981; cv=pass; d=google.com; s=arc-20160816; b=jdkG1QHJeAEnUzYhHWORnM8W/D5SQ3nP+eZwc6VxtUvZxDx6FBcecdnlTxnYmywpoM P7pI9LS9lkO3O7JFVb/Fs7tmdujKgXr0JIPXXcrvXCMoNhBucG118hVMZeB9Lp3iwK2j nM0dYy0DlK5se42+EXOVRYJ0F/bkGtxv6sq3k5eZkmqoESHHEKsGL9ffGer3hpwuVV4k GJQfz1rM+am89d227PqkXRLfgAXt+OpWZC8B4tlegSyEP1dsnbfR/1t+jhgchH/Gk2i5 2iL5RzzmEtn8G3jYOpwFkLHa3JIYdemgz5wf8i1WQZrXEDJIWupx3PnkHnZ/ssymvQfY 99EA== 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=7tr9m0v9Vw7mTZF+qY7TjWXb+zUwY5MherG9XL6zAF0=; fh=Dz/sGw+9lzNFrkoqVn+ZLx/Xi4dC8owgH35eQDavKgI=; b=lyTVa56AJ7xAsMhiXCvL8Nf5rHCbBfMxxGbg8s5BQsi3POixkNiQd9Utgry8LHUUy1 1+lESdpWstNrG0hbOksS3iAKGavbv5sZIXNxgd6wfREFEZ1zJ1AV4hdT6S59cH/IlkCY mfL79RehROo+IdK0HPYe8UpOXqEi08PV+eYVqXfmSGdvomuf/ENFowb9jD8UA3OGxBJX /vjsZwfXKKE9mlN8wHRS/cM5VM2eNxA9ziUO6j1Ppo3NvziWbr35M83pxrgAyU/3+G+8 05tYN070/BS3rpW/8YBtnyFNt9O8BUGZPi2L1J9L5/vZQ5F4n86fOZm+5HaRAXv0/A+T Rdig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=KJ1C4VIi; 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-69540-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69540-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f30-20020a63381e000000b005ca5616facesi653298pga.38.2024.02.16.16.33.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:33:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69540-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=KJ1C4VIi; 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-69540-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69540-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D2F5FB25880 for ; Sat, 17 Feb 2024 00:16:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D780E5A7AF; Sat, 17 Feb 2024 00:11:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="KJ1C4VIi" 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 64E451D535; Sat, 17 Feb 2024 00:10:54 +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=1708128656; cv=none; b=fdfT/agQLQFMgd9Re7Ve1pm9WM+OS+/+7zI58pOoE4UuHqHRnNUu1Ww24bQBQvL9Ulq7+r+42RMicNApmhxmvU5d85tBCGoaC8oKScq0ADB9GuXWtV2DtSrTMNIu98igW1j/1aITbiF/0VzGO2kadrH/gzLn1T8+C9bEvb2N9AM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708128656; c=relaxed/simple; bh=uaCPGA2xpM/XYzbNp4Zx/iXcVoo2XRBq3+RQP/b21ic=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oTEhznMXPiioPh3B3UDfvd0ehzD7bZ++I94I3xrFMzCwh9tDX7PhMetR0Yl3ceyIuqouxgpnXrB7cK7tzFf1CENBdVa9sORTF/j1EvWUuhhc1m1xJE5fqmMAQ6oDV8YYHqboM5x3W+K6nMXiBPZpVAbibGefY2z6M4lhz0ZC3qM= 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=KJ1C4VIi; 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 (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41GNt9v4000483; Sat, 17 Feb 2024 00:10:33 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=7tr9m0v9Vw7mTZF+qY7T jWXb+zUwY5MherG9XL6zAF0=; b=KJ1C4VIiNAwFj6FM+nG0j/31/jh6/oKIJqO/ tl96Aih4Vybmz+qsG/9dCQHAuYjv+h5C9y//d+cc97UeFjK01BGPQzlaeOqEBodR sv64PJoQzoxz7x4yzAFtGXmA3w3o4/P5stuMkV2m2f8Pj4bPJq8Htv1gNZDCWqRy wGjt/VkakzBRu2Hj4+9opbgcunZAHZwFPBzF+7YyxNjxxqpy5FNYyPOBoTDHl8dd e4wR8pVILOV0DnO1NNgblCCoJiwCYHFhPU6AB6wfNP5o4OS4HfrO4JRGC/h2RvfS pFNxzU4nYoJ2vM0j50TLHuJnmvDD+txNgVynpc5uFSTyD+x7OQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w9wxf2cn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 17 Feb 2024 00:10:33 +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 41H0AWBg017199 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 17 Feb 2024 00:10:32 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; Fri, 16 Feb 2024 16:10:32 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v17 09/51] xhci: Decouple handling an event from checking for unhandled events Date: Fri, 16 Feb 2024 16:09:35 -0800 Message-ID: <20240217001017.29969-10-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240217001017.29969-1-quic_wcheng@quicinc.com> References: <20240217001017.29969-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: nalasex01a.na.qualcomm.com (10.47.209.196) 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: DXZy5_W1P3Y7HiX2yAbUtJo8yPfNnQHX X-Proofpoint-ORIG-GUID: DXZy5_W1P3Y7HiX2yAbUtJo8yPfNnQHX 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-16_23,2024-02-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=907 lowpriorityscore=0 priorityscore=1501 mlxscore=0 clxscore=1015 impostorscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402160189 From: Mathias Nyman Some sequences, will require traversing through the entire event ring without handling the event TRB. This is ideal for when secondary interrupters that are utilized by external entities need to clean up the interrupter's event rings during halting of the XHCI HCD. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index d31599d46b92..d4a28ac4967f 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2962,25 +2962,18 @@ static int handle_tx_event(struct xhci_hcd *xhci, } /* - * This function handles all OS-owned events on the event ring. It may drop + * This function handles one OS-owned event on the event ring. It may drop * xhci->lock between event processing (e.g. to pass up port status changes). - * Returns >0 for "possibly more events to process" (caller should call again), - * otherwise 0 if done. In future, <0 returns should indicate error code. */ -static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) +static int xhci_handle_event_trb(struct xhci_hcd *xhci, struct xhci_interrupter *ir, + union xhci_trb *event) { - union xhci_trb *event; u32 trb_type; - event = ir->event_ring->dequeue; - - if (!unhandled_event_trb(ir->event_ring)) - return 0; - trace_xhci_handle_event(ir->event_ring, &event->generic); /* - * Barrier between reading the TRB_CYCLE (valid) flag above and any + * Barrier between reading the TRB_CYCLE (valid) flag before, and any * speculative reads of the event's flags/data below. */ rmb(); @@ -3010,15 +3003,11 @@ static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) * to make sure a watchdog timer didn't mark the host as non-responsive. */ if (xhci->xhc_state & XHCI_STATE_DYING) { - xhci_dbg(xhci, "xHCI host dying, returning from " - "event handler.\n"); - return 0; + xhci_dbg(xhci, "xHCI host dying, returning from event handler.\n"); + return -ENODEV; } - /* Are there more items on the event ring? Caller will call us again to - * check. - */ - return 1; + return 0; } /* @@ -3068,9 +3057,14 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, } } +/* + * Handle all OS-owned events on an interrupter event ring. It may drop + * and reaquire xhci->lock between event processing. + */ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir) { int event_loop = 0; + int err; u64 temp; xhci_clear_interrupt_pending(xhci, ir); @@ -3091,7 +3085,10 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir return -ENODEV; } - while (xhci_handle_event(xhci, ir) > 0) { + /* Process all OS owned event TRBs on this event ring */ + while (unhandled_event_trb(ir->event_ring)) { + err = xhci_handle_event_trb(xhci, ir, ir->event_ring->dequeue); + /* * If half a segment of events have been handled in one go then * update ERDP, and force isoc trbs to interrupt more often @@ -3107,6 +3104,9 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir /* Update SW event ring dequeue pointer */ inc_deq(xhci, ir->event_ring); + + if (err) + break; } xhci_update_erst_dequeue(xhci, ir, true);