From patchwork Tue Feb 13 00:53:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp277000dyb; Mon, 12 Feb 2024 17:54:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUrR2aI4tD45bXwnNgz9xBrDnwSA+KAfh/fBp/aIhOTFbOSNNko9xKbxk2gtm0ykHHnBIHxq5FWUjO63r1tJtXsRJy6TQ== X-Google-Smtp-Source: AGHT+IFnDqN0wRCHDmHjZYRovh3tnTjoF3q7/zhNwDDSmO0uaMgnKPIcRUejAX0KxenaAfNtdtSF X-Received: by 2002:a05:6a00:2da0:b0:6e0:f2a6:abd8 with SMTP id fb32-20020a056a002da000b006e0f2a6abd8mr2295328pfb.34.1707789270946; Mon, 12 Feb 2024 17:54:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789270; cv=pass; d=google.com; s=arc-20160816; b=JH7fRYm7AseQx6IF3v9V7ZXyeyoKMsCXFDY6HDdV4XM80RNSVpgaNTFTqIVi5YHWH3 VLYyJh0HgO87dBhP+mSkbrH4+cpldQkfsc2jIfahJKWek2COmK4a1oIGxPUUqdPJLVJW U+lfOWUXSqMWXRFUQmp7EjsaPaY8bRWsShAjfH918q7oct+rAlOw9jMrh7Q4S6IItCO1 FDGeJdUMT3IzwoGCL9icCF0Xom9+KyW4NrViHOASxlnyQXwmVUK6T4uLp5Uq4G8Cc96Q XJXNAuPN3iDyIYcVMgNV37lQmkxKOuOigVdXVVWDixCDRAVuT21FLYNkcabsHYZnU9mW qinw== 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=/sAK0l6KhmBr0wHjMWMWN+A9UguzYRdYNwmoexTrTrQ=; fh=RGJYrsr8ydg3bt6+3RGdcZhd7OWaQMOtSYzkrcFvTAA=; b=Jh/TDixz7UJp7FghSV9sjuSnq/s4n1I4lfGiIZUOagYDlnIReKM6+Ng8Op99jRaFap m0AYC7eRPUNqyfxJD5semI7iYMjivJGsCwzNDY0HQJeKmsAB6g+mD3jjS3bA9c0jVaIU +eMNAGL45FhCE0cuQBQVJMAYmDG6OvBD9WtpeUg6+tzJy1a8uC16OQzEQ/E2oHt1jEBO NnfYaZ6DCGZ24VnlHzBC/QabAfgIdKKG0gNnQ2eLjsaBFOisLZVWkJ2fLMgK3+flq4q1 27P3mP5eUFHkNV8opOk85MNTvCGyCQxJTFn/b5BjIcEfCrH+6q0BY3oeAAJ5YP2DwIWz musQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="HE/41sCi"; 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-62794-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62794-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWu2/XJapqLNGv3Ks8qULMz4i7l5UsdSZj1lks3eM5jTzWYJxbUpN5+LreihdHZR+3nQVRou5scsbj3Jj352cOLpiXVnQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u17-20020a63b551000000b005cd90b47495si1117186pgo.264.2024.02.12.17.54.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:54:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62794-ouuuleilei=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="HE/41sCi"; 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-62794-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62794-ouuuleilei=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 0FFF2B28625 for ; Tue, 13 Feb 2024 01:32:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D79AD60BB6; Tue, 13 Feb 2024 00:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="HE/41sCi" 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 C6FC336B17; Tue, 13 Feb 2024 00:54:57 +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=1707785700; cv=none; b=M6lzthuNon8L+pLQVqB2ggo+RrPFaOTCAyoKpANtlANQJjPkbBRFDn2y0YJvDtgIiFVYGnAZ3D2ljGZI7jmVaya2QGbfiJ2TOWEOecawJOe+5ZtVCKOkz0u5jr89PqWaE2vJfWPrxoQZVMsELX/kyeMm4gO6cxDS9RSSTz8P0c0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; c=relaxed/simple; bh=RtzWV/1LJX88jylynkZkjLYqkeu4eisuZBnouYa2i2E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HGOCktKcG3lgF1lR3f25xV+gVWenGExodInC/cMsEj3Ah1kmhnuvBf+reRtwzFCe+Mg93SeUbEEuZODFKa00v4hOMf17LrLQB3bbOgppLgAgrvppTvJWzoEr45zGSFvgkv0IKFc5ICcpWPN0tkC8+Sv51vj3tQ6RqW1FiCMmkKo= 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=HE/41sCi; 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 (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CM42k2008671; Tue, 13 Feb 2024 00:54:37 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=/sAK0l6KhmBr0wHjMWMW N+A9UguzYRdYNwmoexTrTrQ=; b=HE/41sCir1aTc8S1HhSxoDlKIcEZZ6fSU/eH w1cRWhZKMaG+FK+y4sbvSoTBvik3v25I7IuFaMF4DAT8KDLhZFbfqA9DI4BGvoP8 kES0xNBDJA0yb/DXcl/x0/xikssKrFmD65ISJSyzM8I4Sg+svc3BPklZKgv/aTF1 FKEIZ3CHFrsaAWjXw9tsvaZJ+U9/mUNH+tnTtsZIOA0mSP+Q4tvSSV9R5vNB0ozm 9SGKnfDztX9kqhBiLBnY8JxuyWn8ci5kTau/kB5olBSkZnKfhyTJdNyinWa4czJX nL1rlcKwuPO4SO8ycd/bdkX1ys2RA6AXOXut8DNourw1HBtVRQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhuwy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:36 +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 41D0sZLX026779 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 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:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 10/50] xhci: add helper to stop endpoint and wait for completion Date: Mon, 12 Feb 2024 16:53:42 -0800 Message-ID: <20240213005422.3121-11-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 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: I6Z5lkvj98F16MKUXWt3jpR0IW8q8YFB X-Proofpoint-ORIG-GUID: I6Z5lkvj98F16MKUXWt3jpR0IW8q8YFB 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 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746842581776149 X-GMAIL-MSGID: 1790746842581776149 From: Mathias Nyman Expose xhci_stop_endpoint_sync() which is a synchronous variant of xhci_queue_stop_endpoint(). This is useful for client drivers that are using the secondary interrupters, and need to stop/clean up the current session. The stop endpoint command handler will also take care of cleaning up the ring. Modifications to repurpose the new API into existing stop endpoint sequences was implemented by Wesley Cheng. Signed-off-by: Mathias Nyman Co-developed-by: Wesley Cheng Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci.c | 62 ++++++++++++++++++++++++++++++----------- drivers/usb/host/xhci.h | 2 ++ 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index b405b8236134..872ce8c1a5ba 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -2796,6 +2796,48 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, return -ENOMEM; } +/* + * Synchronous XHCI stop endpoint helper. Issues the stop endpoint command and + * waits for the command completion before returning. + */ +int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int suspend, + gfp_t gfp_flags) +{ + struct xhci_command *command; + unsigned long flags; + int ret; + + command = xhci_alloc_command(xhci, true, gfp_flags); + if (!command) + return -ENOMEM; + + spin_lock_irqsave(&xhci->lock, flags); + ret = xhci_queue_stop_endpoint(xhci, command, ep->vdev->slot_id, + ep->ep_index, suspend); + if (ret < 0) { + spin_unlock_irqrestore(&xhci->lock, flags); + goto out; + } + + xhci_ring_cmd_db(xhci); + spin_unlock_irqrestore(&xhci->lock, flags); + + ret = wait_for_completion_timeout(command->completion, msecs_to_jiffies(3000)); + if (!ret) + xhci_warn(xhci, "%s: Unable to stop endpoint.\n", + __func__); + + if (command->status == COMP_COMMAND_ABORTED || + command->status == COMP_COMMAND_RING_STOPPED) { + xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); + ret = -ETIME; + } +out: + xhci_free_command(xhci, command); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_stop_endpoint_sync); /* Issue a configure endpoint command or evaluate context command * and wait for it to finish. @@ -3119,7 +3161,7 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, struct xhci_virt_device *vdev; struct xhci_virt_ep *ep; struct xhci_input_control_ctx *ctrl_ctx; - struct xhci_command *stop_cmd, *cfg_cmd; + struct xhci_command *cfg_cmd; unsigned int ep_index; unsigned long flags; u32 ep_flag; @@ -3177,10 +3219,6 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, if (ep_flag == SLOT_FLAG || ep_flag == EP0_FLAG) return; - stop_cmd = xhci_alloc_command(xhci, true, GFP_NOWAIT); - if (!stop_cmd) - return; - cfg_cmd = xhci_alloc_command_with_ctx(xhci, true, GFP_NOWAIT); if (!cfg_cmd) goto cleanup; @@ -3203,23 +3241,16 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, goto cleanup; } - err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, - ep_index, 0); + spin_unlock_irqrestore(&xhci->lock, flags); + + err = xhci_stop_endpoint_sync(xhci, ep, 0, GFP_NOWAIT); if (err < 0) { - spin_unlock_irqrestore(&xhci->lock, flags); - xhci_free_command(xhci, cfg_cmd); xhci_dbg(xhci, "%s: Failed to queue stop ep command, %d ", __func__, err); goto cleanup; } - xhci_ring_cmd_db(xhci); - spin_unlock_irqrestore(&xhci->lock, flags); - - wait_for_completion(stop_cmd->completion); - spin_lock_irqsave(&xhci->lock, flags); - /* config ep command clears toggle if add and drop ep flags are set */ ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); if (!ctrl_ctx) { @@ -3251,7 +3282,6 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, xhci_free_command(xhci, cfg_cmd); cleanup: - xhci_free_command(xhci, stop_cmd); spin_lock_irqsave(&xhci->lock, flags); if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 44e447fdad62..eaea676c85d2 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1919,6 +1919,8 @@ void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, void xhci_cleanup_command_queue(struct xhci_hcd *xhci); 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); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,