Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3568053rdh; Thu, 28 Sep 2023 16:13:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXLrRa1ymOlc63tYl/VwdC6FXAATcjTdBQgfuI8hUO6rjO1lQV3gQCZjUlacfBAtGfFtzo X-Received: by 2002:a05:6a00:1488:b0:693:3733:4b09 with SMTP id v8-20020a056a00148800b0069337334b09mr2989904pfu.13.1695942809236; Thu, 28 Sep 2023 16:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695942809; cv=none; d=google.com; s=arc-20160816; b=cP8NWa1TqvSkZ0n6/tlVs9Kae6hvfLemkN7PoZ1vtk1MVtrNo0g2Tmo8CY588hd6QH f+1z5xm4Y0E7/yilEIAhuD86wF/s9ZD3GM/yx1Q8WDBAA+/Lw/N/L4vX0+8XrKmHK/6p NduaGThqi/vbjX/MjCZpfcVrjYUaqVmyEuiyM5t8tMc41sqqf16efFBvJQr2/2Gq0UrI k6tsA2aSXjhjWauK89dpdfBB3NNempeS/WTpj2L6UA+Zx2WU0cKWTGZYKdQliPGUd1la VWqT9pSBnygkxjWzNFtVHiI3B+LvlqQYO8uTGTyA62Yk/RkLBpwa+sdUpaap9/POFxFe UGYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=fMFZ1LOpYIA7vxYtrtcMwqwSA8LYXqgC3wa6Z8gwFb8=; fh=QnMiPHshWHBKrUamx5v591AnsWFwm+I/ZBEi6H+RSFI=; b=lM9ixnGFz8D0hZmj1Iz8Aba3LYjxqQ14Cy/TLRp8DBT9ENnv8KS7bRzC36ZlZie4iH nVyd3qlAPEo3atPDC754Nww3hme2Aq2eNEzTrt86hMVkm0YmEiz+/e9R088K6yOqkbx8 SJ0KrSc6B/Tl47JYsptUoCSwRbmueovYS2GKxiaw1aV89DPOcCN+YQvGtsBEk6UFFE14 nhVUSDwM9yifoQupxNYeQliweZvM4qUWI5jiM0H0FFk/BEXhaxBoQZBjoUR+1ha7JT5x 9pkqytuZoZCeuLWSObrBOk+o8Hn2IX5OYDIIgrkheJ84Q1EGPJ9ypAD/qYMHaGphvmrR wSHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AapLIZpf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id q18-20020a056a0002b200b0069023c19351si18237374pfs.154.2023.09.28.16.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 16:13:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AapLIZpf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1DB4883D0ABE; Thu, 28 Sep 2023 06:35:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232084AbjI1NfC (ORCPT + 99 others); Thu, 28 Sep 2023 09:35:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231868AbjI1NfC (ORCPT ); Thu, 28 Sep 2023 09:35:02 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C22B11F; Thu, 28 Sep 2023 06:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695908100; x=1727444100; h=message-id:date:mime-version:to:cc:references:from: subject:in-reply-to:content-transfer-encoding; bh=2q/ofJbjVnxsiWF4wpyLGs7XzpOCXPm/6xI4ePXLves=; b=AapLIZpfhIbLoy2Bxnc3/gaTMXAiw948rsHJtPSPwuyuZO1+AEeUaoaw NEJC1PLrRRpU7eX117AmHyxkBaIUXoicCsieo/l/V4rRGLhAIFPuGBUnx xB2pc6+8XwLBKtkrWQjm1PIQNMv2flyGAMFwMLmb/SM465ovRE5TIzBMo UTH8ktwTDNv66boYuM+x6UEo0OYw3vpMx6JGqXowVoJcCJUHhbiuu5wok 7NIRP8dQuliZlbdB8RNCgGTSNoy4yL+ecDz33KS2g+ZK/fLI3ERRp+7AN eWKgvfu/gmt8+DznE9UmRlJhrRQDgo91U7mE+nqAL+Yt2md7wAgzAv4vb w==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="381968817" X-IronPort-AV: E=Sophos;i="6.03,184,1694761200"; d="scan'208";a="381968817" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 06:30:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="923216353" X-IronPort-AV: E=Sophos;i="6.03,184,1694761200"; d="scan'208";a="923216353" Received: from mattu-haswell.fi.intel.com (HELO [10.237.72.199]) ([10.237.72.199]) by orsmga005.jf.intel.com with ESMTP; 28 Sep 2023 06:30:28 -0700 Message-ID: <6e9d2094-0bf9-b2ac-29f3-99115b456fdb@linux.intel.com> Date: Thu, 28 Sep 2023 16:31:52 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.13.0 Content-Language: en-US To: Wesley Cheng , mathias.nyman@intel.com, gregkh@linuxfoundation.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, srinivas.kandagatla@linaro.org, bgoswami@quicinc.com, Thinh.Nguyen@synopsys.com Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org References: <20230921214843.18450-1-quic_wcheng@quicinc.com> <20230921214843.18450-3-quic_wcheng@quicinc.com> From: Mathias Nyman Subject: Re: [PATCH v7 02/33] xhci: add helper to stop endpoint and wait for completion In-Reply-To: <20230921214843.18450-3-quic_wcheng@quicinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 28 Sep 2023 06:35:19 -0700 (PDT) On 22.9.2023 0.48, Wesley Cheng wrote: > 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-hub.c | 29 +++--------------- > drivers/usb/host/xhci.c | 60 +++++++++++++++++++++++++++---------- > drivers/usb/host/xhci.h | 2 ++ > 3 files changed, 50 insertions(+), 41 deletions(-) > > diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c > index 0054d02239e2..2f7309bdc922 100644 > --- a/drivers/usb/host/xhci-hub.c > +++ b/drivers/usb/host/xhci-hub.c > @@ -489,7 +489,6 @@ EXPORT_SYMBOL_GPL(xhci_find_slot_id_by_port); > static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) > { > struct xhci_virt_device *virt_dev; > - struct xhci_command *cmd; > unsigned long flags; > int ret; > int i; > @@ -501,10 +500,6 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) > > trace_xhci_stop_device(virt_dev); > > - cmd = xhci_alloc_command(xhci, true, GFP_NOIO); > - if (!cmd) > - return -ENOMEM; > - > spin_lock_irqsave(&xhci->lock, flags); > for (i = LAST_EP_INDEX; i > 0; i--) { > if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) { > @@ -521,7 +516,7 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) > if (!command) { > spin_unlock_irqrestore(&xhci->lock, flags); > ret = -ENOMEM; > - goto cmd_cleanup; > + goto out; > } > > ret = xhci_queue_stop_endpoint(xhci, command, slot_id, > @@ -529,30 +524,14 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) > if (ret) { > spin_unlock_irqrestore(&xhci->lock, flags); > xhci_free_command(xhci, command); > - goto cmd_cleanup; > + goto out; > } > } > } > - ret = xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend); > - if (ret) { > - spin_unlock_irqrestore(&xhci->lock, flags); > - goto cmd_cleanup; > - } > - > - xhci_ring_cmd_db(xhci); > spin_unlock_irqrestore(&xhci->lock, flags); > + ret = xhci_stop_endpoint_sync(xhci, &virt_dev->eps[0], suspend); I didn't take this new xhci_stop_endpoint_sync() helper into use as it causes an extra xhci spinlock release and reacquire here. Also the memory allocation flags differ, GFP_NOIO is turned into GFP_KERNEL after this change. > > - /* Wait for last stop endpoint command to finish */ > - wait_for_completion(cmd->completion); > - > - if (cmd->status == COMP_COMMAND_ABORTED || > - cmd->status == COMP_COMMAND_RING_STOPPED) { > - xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); > - ret = -ETIME; > - } > - > -cmd_cleanup: > - xhci_free_command(xhci, cmd); > +out: > return ret; > } > > diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c > index 3fd2b58ee1d3..163d533d6200 100644 > --- a/drivers/usb/host/xhci.c > +++ b/drivers/usb/host/xhci.c > @@ -2758,6 +2758,46 @@ 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) > +{ > + 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; > +} > > /* Issue a configure endpoint command or evaluate context command > * and wait for it to finish. > @@ -3078,7 +3118,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; > @@ -3118,10 +3158,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; > @@ -3144,23 +3180,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); > + Same here, extra unlock -> lock, and GFP flags differ. > + err = xhci_stop_endpoint_sync(xhci, ep, 0); Thanks Mathias