From patchwork Tue Jan 2 21:45:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 184495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4701181dyb; Tue, 2 Jan 2024 13:54:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVS71+mwHV/OQfc/gmxO90AnLsdTHKgJEH8tg8lQW5ksg31yPlyvLIH/5z1MilLxfAQETd X-Received: by 2002:a05:6a20:4114:b0:190:6617:270e with SMTP id y20-20020a056a20411400b001906617270emr19701668pze.41.1704232452686; Tue, 02 Jan 2024 13:54:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704232452; cv=none; d=google.com; s=arc-20160816; b=VCiibyEEtgJ//hPjzjG9vi5JFYR6it/fP73jXFnY3XYjX4WjAi+YtFaHLH2dzJu8Se 5rGuNaMag9Cg1+sALdLuSt8CZL+ussPsuMp7lOKyEkjIvVO6W9913JzMPEvZlBhuIqeP rQNPhUqDlmyZsN/stvdH+qyLvLSCDf1iP8lyXCY7KX1GVC65wXE8/e96bsi3bPCH0dF7 u8auaGwyv7kDkkn3Auw7aiYQYmWpNS0RWtow4KUvqhwdUxshM/WZxZzWNO9UmPTmmyFe kwC/fpqRreaZs1XhnJzrWr096k2fuojgZydUMl8wSrbRWNyESDAE1bVeVbiMwKGuN9ol Hc5w== ARC-Message-Signature: i=1; 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=hpcUlldGCArTiMPvhj750wOOJTS+Xbbm0shlAwP7dpM=; fh=AqyPF1mapYYsvsRm1pr4zqLpirWqzrfkK4jkJS8U09Q=; b=Ab9z0+YRBsxwrz5+Jiyqs6t7MyFPfb9GYsg5rz6pd6dAnwuWR3wWwn9x9VK4a6ToCB nb4PlcHuCLfWOb4wnqa5lZTLuCb8QR7fKfgPRKy8MVY6hQlBqYaTg1MSoOcN3/p+865S 0NTRFm+ABvx3/Rso/Ut5npd5U5qIsiaFStNixc+GSwZGiel0zlQrUpNaWoXx2BB4QQ6K N8EDDxKcbf1NyK6yXDUG2f9VG8MO9t/pEEREQD+YoRV7DxLLz3n41hRb24jg1kqspgim M/oGqckTnz7xqL56Xe4ZUdQvzbjqngQdQaMnqDxHsLNumoI8qyJ3qV+GG9l5w5swyAeW 9bAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dsjFABod; spf=pass (google.com: domain of linux-kernel+bounces-14881-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14881-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id fb27-20020a056a002d9b00b006d9b56a8629si11776620pfb.45.2024.01.02.13.54.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 13:54:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14881-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dsjFABod; spf=pass (google.com: domain of linux-kernel+bounces-14881-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14881-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 47E65284BFF for ; Tue, 2 Jan 2024 21:54:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3496A1C2B3; Tue, 2 Jan 2024 21:46:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="dsjFABod" X-Original-To: linux-kernel@vger.kernel.org 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 2DDF81BDE2; Tue, 2 Jan 2024 21:46:51 +0000 (UTC) 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 (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 402LaQiT021757; Tue, 2 Jan 2024 21:46:19 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=hpcUlldGCArTiMPvhj75 0wOOJTS+Xbbm0shlAwP7dpM=; b=dsjFABod2qqAFHfAvTKqF0coiYODewDSrwKL L61mZrc/X+A1D6G1CGz3Hl3OVrcqc3rn8PjyRpoGT3e6jTMpdEAVBH0OHNZTFAaW V4rD+pyO/jJw8rzDb3xMQ+Zh572lfaY3zooHlcqm4+oLu1ATTT8P3wDgIgjC7ji2 XH4O1gD71VsjT5AXqGXWugoYPr3W/Ytmcy+2CwgEcMUtayBBOa9pnGtWAXuRH/IJ FZvp5LcxgFWTsknFaVYd9KHlx4fnDu9+yrFjN8Bx6D+Faby9JTp8OEkz2ZNRFm6r SM27wWN/KaZ69O7/8mRaP9aplL9jUGy+dg8SLQSRU3q4Z33cnQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vch7n96r3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 21:46:19 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 402LkIut017324 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 2 Jan 2024 21:46: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.1118.40; Tue, 2 Jan 2024 13:46:17 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v12 02/41] xhci: add helper to stop endpoint and wait for completion Date: Tue, 2 Jan 2024 13:45:10 -0800 Message-ID: <20240102214549.22498-3-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240102214549.22498-1-quic_wcheng@quicinc.com> References: <20240102214549.22498-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: MPbT47YVlMCY0SktKQ336_Ub5SktI11a X-Proofpoint-ORIG-GUID: MPbT47YVlMCY0SktKQ336_Ub5SktI11a X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401020161 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787017248449239643 X-GMAIL-MSGID: 1787017248449239643 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 c057c42c36f4..573ca5c4f31a 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -2782,6 +2782,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_KERNEL); + 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. @@ -3105,7 +3147,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; @@ -3163,10 +3205,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; @@ -3189,23 +3227,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) { @@ -3237,7 +3268,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 a5c72a634e6a..b7d06fcd58d1 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -2174,6 +2174,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,