Re: Understanding USB callback + assertion panic

From: Hans Petter Selasky <hps_at_selasky.org>
Date: Wed, 09 Mar 2022 09:46:37 UTC
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