Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7562524imu; Mon, 3 Dec 2018 15:10:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/WIH/gIIy9PwXcWp47vrNk6TumLqqWcGqO5vN3FLbNAqHtBXUFgwty24WBIO/Pb1pwnCRgm X-Received: by 2002:a17:902:bf03:: with SMTP id bi3mr17825666plb.83.1543878646364; Mon, 03 Dec 2018 15:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543878646; cv=none; d=google.com; s=arc-20160816; b=RadNOc38eykNxhjru8FOe5b6GYS3vD4YT3FS5VhtuY3Oe4OKZrPwnEC8OjHXx9zLMj 2yA0OB9fq4j5/uLs00jxlyIvC9LrLGSM3OOkgP6ihO8wDrOzIx+XpUb4+RsgHX2x9746 PzxS50IL96VPFVVvsilynIJpFaDYYx9PfSiOutwkXesNL0sTkRiFErJ+/ZpwATB9EoNb v3aME5dskar5V3dS5+Dc2FNQ88qzGYujjnxIB2swh7Qho/FWKqOMD2v1+4ipI47zfNuV nimKinS2/v5Oc7YYvnH71N95dpK9CrFsc6wd/0DGHAEXVLm0kojBxi61KpkQfasCJ2WF gXzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=vqdQm2GKGEHQ9wTebZbOJg0cn5nIyFBcnkUw/3XSnZI=; b=sUb59fXM5HAnSqL9VhUbOlIg1G0okwrf6fWi8qCzXRWMDbRDR9xSn1QAqeDmphK0bK iiFXa8EAR4PAZnfwm9LaEIG0ta44kz3wJThPLWSSsNvtYl/bK1Nsn1B2JFxk/BexYabg iMPwxFl2T6+xM8/mG90ajcp7UwJjCjSo3RoVDjAmFEZDpYDTmHYm+T1ACyAStg365PpR YKbxd0r2+ehDBi6PBaGdZbCDtmODpyNZh8ntRy9tZX0rUVk/9BUxP4i0RbBHUj1fWGzX L/xWxDNweLYRKxyfXMc72TlqRefBMBcNEYW7+/uW87oAqyduwhTnyRbaMqkcLkmCpeX0 kQtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si15079715plk.9.2018.12.03.15.10.31; Mon, 03 Dec 2018 15:10:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726066AbeLCXIV (ORCPT + 99 others); Mon, 3 Dec 2018 18:08:21 -0500 Received: from netrider.rowland.org ([192.131.102.5]:40305 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1725981AbeLCXIU (ORCPT ); Mon, 3 Dec 2018 18:08:20 -0500 Received: (qmail 410 invoked by uid 500); 3 Dec 2018 18:08:19 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 3 Dec 2018 18:08:19 -0500 Date: Mon, 3 Dec 2018 18:08:19 -0500 (EST) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Anurag Kumar Vulisha cc: Felipe Balbi , Greg Kroah-Hartman , Shuah Khan , Johan Hovold , Jaejoong Kim , Benjamin Herrenschmidt , Roger Quadros , Manu Gautam , "martin.petersen@oracle.com" , Bart Van Assche , Mike Christie , Matthew Wilcox , Colin Ian King , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "v.anuragkumar@gmail.com" , Thinh Nguyen , Tejas Joglekar , Ajay Yugalkishore Pandey Subject: RE: [PATCH v7 01/10] usb: gadget: udc: Add timer support for usb requests In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 3 Dec 2018, Anurag Kumar Vulisha wrote: > >On Mon, 3 Dec 2018, Anurag Kumar Vulisha wrote: > > > >> >First of all, if some sort of deadlock causes a transfer to fail to > >> >complete, the host is expected to cancel and restart it. Not the > >> >gadget. > >> > > >> > >> Thanks for spending your time in reviewing this patch. The deadlock > >> is a very rare case scenario and is happening because both the gadget > >> controller & host controllers get out of sync and are stuck waiting for the > >> relevant event. For example this issue is observed in stream protocol where > >> the gadget controller is waiting on Host controller to issue PRIME transaction > >> and Host controller is waiting on gadget to issue ERDY transaction. Since > >> the stream protocol is gadget driven, the host may not proceed further until it > >> receives a valid Start Stream (ERDY) transaction from gadget. > > > >That's not entirely true. Can't the host cancel the transfer and then > >restart it? > > > > Yes the host can cancel the transfer. This issue originated from the endpoints using bulk > streaming protocol and may not occur with normal endpoints. AFAIK bulk streaming is > gadget driven, where the gadget is allowed to select which stream id transfer the host > should work on . Since the host doesn't have control on when the transfer would be > selected by gadget, it may wait for longer timeouts before cancelling the transfer. You're missing the point. Although the device selects which stream ID gets transferred, the _host_ decides whether a stream transfer should occur in the first place. No matter how many ERDY packets the device controller tries to send, no transfer will occur until the host wants to do it. In this sense, stream transfers (like all other USB interactions except wakeup requests) are host-driven. > >> Since the gadget > >> controller driver is aware that the controller is stuck , makes it responsible > >> to recover the controller from hang condition by restarting the transfer (which > >> triggers the controller FSM to issue ERDY to host). > > > >Isn't there a cleaner way to recover than by cancelling the request and > >resubmitting it? > > > > dequeuing the request issues the stop transfer command to the controller, which > cleans all the hardware resource allocated for that endpoint. This also resets the > hardware FSMs for that endpoint . So, when re-queuing of the transfer happens > the controller starts allocating hardware resources again, thus avoiding the probability > of entering into the issue. I am not sure of other controllers, but for dwc3, issuing > the stop transfer is the only way to handle this issue. Again you're missing the point. Can't the controller driver issue the Stop Transfer command but still consider the request to be in progress (i.e., don't dequeue the request) so that the gadget driver's completion callback isn't invoked and the request does not need to be explicitly resubmitted? > @Felipe: Can you please provide your suggestion on this. > >How can the gadget driver know what timeout to use? The host is > >allowed to be as slow as it wants; the gadget driver doesn't have any > >way to tell when the host wants to start the transfer. > > Yes , I agree with you that the timeout may vary from usage to usage. This timeout > should be decided by the class driver which queues the request. As discussed above > this issue was observed in streaming protocol , which is very much faster than normal > BOT modes and it works on super speed . Although USB mass storage is currently the only user of the stream protocol, that may not be true in the future. You should think in more general terms. A timeout which is appropriate for mass storage may not be appropriate for some other application. Alan Stern > More over the gadget controller decides > the selection of the stream id on which the host should work , so taking all these into > consideration I kept 50ms timeout for stream transfers, so that the performance may > not get decreased. > > Thanks, > Anurag Kumar Vulisha