Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp481845ybk; Wed, 20 May 2020 04:43:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7k6GMzVAR0k25pMnAUVQLfQFYqmgWtrX7/6aEIWO/TAPrNgA3RfnM76MTk69mjj4AZB+j X-Received: by 2002:a50:b701:: with SMTP id g1mr3107144ede.259.1589974992764; Wed, 20 May 2020 04:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589974992; cv=none; d=google.com; s=arc-20160816; b=qN4MVckt5dgOqKZMIVavG8y/7sgKxIr6BWupWeXT9ouViCVOeskgN0VyDBFtV5TJBf b1qLgHAYxOpGAplcVJdd59dqOCSXfveBAZ8Ohx0xvTgxNEMRdD2YkoL0noWys4HcC3oM M5OCVLbezDdqagE8mAglH7TXvD2378HYKwa/JuGO58RXMOWoAR3cyBqqkIy6Y5MNMlOQ bII0fdxeXSs3bHpnuczEiY7vIXQ1kY0lzODy28NksqiTeOtc3OMsFzS+o2VEGAOHPTiv o6EwV3i3A5cNlCs9YnwPF1FRJZA9vmhKHK8QOWT3Kt5ZjImqGbpkpg4Sm2bsWcS8fhEF E95Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=KDv2lWClx1QhUYQwf+7pCsDrJNpvAjnt2JyN9jo8o7s=; b=AX1gFSY2++lWC/jjVCS13H/s7G2nM4ZWyS6ohzt2DXCPIn0EDWyDQienxMEHDMJb/m 4DhsbKwQggyODnAF608wIhGS/5pZ3vgRnqmnlx8kvShwlH22ty8h1XKnmvRZ6LvC7Ncw jx2V28QjytWVAm9k1lFGd5wS5CvueNVN59mZKoGUVo5kURfA2qbXMLEcSXn0U4gMu9w/ uVVly/30nMFHtPLxx90zatJFti0u6NYXK/V7YjAatQwbUAmxI0KhthzcnfAOazNl2o+g QRba6iym60ZO+uC4g3MR/mcfAarrlLRu08N0iO8jAifpppx9wpvvglgEz2jTFXkRTetI hGEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i6si1593143eje.512.2020.05.20.04.42.49; Wed, 20 May 2020 04:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726757AbgETLl1 (ORCPT + 99 others); Wed, 20 May 2020 07:41:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:56544 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbgETLl0 (ORCPT ); Wed, 20 May 2020 07:41:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6ADE0B14A; Wed, 20 May 2020 11:41:27 +0000 (UTC) Date: Wed, 20 May 2020 13:41:24 +0200 Message-ID: From: Takashi Iwai To: Rik van Riel Cc: linux-usb , , "linux-kernel@vger.kernel.org" , Mathias Nyman , Greg Kroah-Hartman , Jaroslav Kysela , Takashi Iwai Subject: Re: XHCI vs PCM2903B/PCM2904 part 2 In-Reply-To: <273cc1c074cc4a4058f31afe487fb233f5cf0351.camel@surriel.com> References: <273cc1c074cc4a4058f31afe487fb233f5cf0351.camel@surriel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") 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 Wed, 20 May 2020 13:26:57 +0200, Rik van Riel wrote: > > After a few more weeks of digging, I have come to the tentative > conclusion that either the XHCI driver, or the USB sound driver, > or both, fail to handle USB errors correctly. > > I have some questions at the bottom, after a (brief-ish) explanation > of exactly what seems to go wrong. > > TL;DR: arecord from a misbehaving device can hang forever > after a USB error, due to poll on /dev/snd/timer never returning. > > The details: under some mysterious circumstances, the PCM290x > family sound chips can send more data than expected during an > isochronous transfer, leading to a babble error. Those > circumstances seem to in part depend on the USB host controller > and/or the electrical environment, since the chips work just > fine for most people. > > Receiving data past the end of the isochronous transfer window > scheduled for a device results in the XHCI controller throwing > a babble error, which moves the endpoint into halted state. > > This is followed by the host controller software sending a > reset endpoint command, and moving the endpoint into stopped > state, as specified on pages 164-165 of the XHCI specification. > > However, the USB sound driver seems to have no idea that this > error happened. The function retire_capture_urb looks at the > status of each isochronous frame, but seems to be under the > assumption that the sound device just keeps on running. > > The function snd_complete_urb seems to only detect that the > device is not running if usb_submit_urb returns a failure. > > err = usb_submit_urb(urb, GFP_ATOMIC); > if (err == 0) > return; > > usb_audio_err(ep->chip, "cannot submit urb (err = %d)\n", err); > > if (ep->data_subs && ep->data_subs->pcm_substream) { > substream = ep->data_subs->pcm_substream; > snd_pcm_stop_xrun(substream); > } > > However, the XHCI driver will happily submit an URB to a > stopped device. Looking at the call trace usb_submit_urb -> > xhci_urb_enqueue -> xhci_queue_isoc_tx_prepare -> prepare_ring, > you can see this code: > > /* Make sure the endpoint has been added to xHC schedule */ > switch (ep_state) { > ... > case EP_STATE_HALTED: > xhci_dbg(xhci, "WARN halted endpoint, queueing URB anyway.\n"); > case EP_STATE_STOPPED: > case EP_STATE_RUNNING: > break; > > This leads me to a few questions: > - should retire_capture_urb call snd_pcm_stop_xrun, > or another function like it, if it sees certain > errors in the iso frame in the URB? I guess it makes sense, yes. > - should snd_complete_urb do something with these > errors, too, in case they happen on the sync frames > and not the data frames? Ditto, the error can be handled similarly. > - does the XHCI code need to ring the doorbell when > submitting an URB to a stopped device, or is it > always up to the higher-level driver to fully reset > the device before it can do anything useful? > - if a device in stopped state does not do anything > useful, should usb_submit_urb return an error? > - how should the USB sound driver recover from these > occasional and/or one-off errors? stop the sound > stream, or try to reinitialize the device and start > recording again? When snd_pcm_stop_xrun() is called, it stops the stream and sets in XRUN state. Then the application receives -EPIPE error upon the next access, and the application needs to re-setup the stream and restart. Takashi > > I am willing to write patches and can test with my > setup, but both the sound code and the USB code are > new to me so I would like to know what direction I > should go in :) > > -- > All Rights Reversed. > [2 This is a digitally signed message part ] >