From nobody Wed Mar 09 09:46:37 2022 X-Original-To: freebsd-usb@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 8B5271A04131 for ; Wed, 9 Mar 2022 09:46:52 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4KD6mC5TWmz4nJx for ; Wed, 9 Mar 2022 09:46:51 +0000 (UTC) (envelope-from hps@selasky.org) Received: from [10.36.2.165] (unknown [178.17.145.105]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id BB36226017B; Wed, 9 Mar 2022 10:46:49 +0100 (CET) Message-ID: <83464b27-75d5-3f74-c896-8bccab8bbbdb@selasky.org> Date: Wed, 9 Mar 2022 10:46:37 +0100 List-Id: FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-usb List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-usb@freebsd.org X-BeenThere: freebsd-usb@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: Understanding USB callback + assertion panic Content-Language: en-US To: Farhan Khan , freebsd-usb@freebsd.org References: <69696561-822a-4808-b142-4a22d3f6b6b2@farhan.codes> From: Hans Petter Selasky In-Reply-To: <69696561-822a-4808-b142-4a22d3f6b6b2@farhan.codes> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4KD6mC5TWmz4nJx X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of hps@selasky.org designates 2a01:4f8:c17:6c4b::2 as permitted sender) smtp.mailfrom=hps@selasky.org X-Spamd-Result: default: False [-2.86 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+a:mail.turbocat.net]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[selasky.org]; NEURAL_HAM_MEDIUM(-0.92)[-0.921]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-0.64)[-0.635]; RCPT_COUNT_TWO(0.00)[2]; MLMMJ_DEST(0.00)[freebsd-usb]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/32, country:DE]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On 3/9/22 00:59, Farhan Khan wrote: > Hi all, > > I am trying to understand how FreeBSD's USB subsystem works and appear to be running into a kernel panic due to a failed assertion that I do not understand. the assertion in question is /usr/src/sys/dev/usb/usb_transfer.c:1954. > > My understanding is that you first configure usbd_transfer_setup(9). To start a bulk transfer, you populate the appropriate list (typically an STAIL_* list), then initiate a transfer by calling usbd_transfer_start(9) with the correct transfer. In my case, my callback is a simple printf(). > > Upon the usbd_transfer_start(9) call, I am hitting the assertion error. I have looked at other device drivers and have not identified what they are doing differently. > Hi, When you call usbd_transfer_setup() you need to specify a mutex which protects the internal data structures of USB transfers. This mutex must be locked when you call: usbd_transfer_start(9) usbd_transfer_stop(9) And this mutex is also automagically locked in your USB callback function. This is to allow atomic stop of multiple USB transfers at the same time. It is similar to how the mutex enabled callout's work. --HPS