Re: Understanding USB callback + assertion panic

From: Daniel O'Connor <darius_at_dons.net.au>
Date: Wed, 09 Mar 2022 09:56:05 UTC
Hi Farhan,

> On 9 Mar 2022, at 10:29, Farhan Khan <farhan@farhan.codes> wrote:
> 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.

This one?

	USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);


> 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.
> 
> Any suggestions?

I think that assertion is saying you have to have acquired the USB transfer lock USB_XFER_LOCK() et al, although I am not entirely sure how you do that 'bare'. I have only called usbd_transfer_start in the USB FIFO setup routines.

--
Daniel O'Connor
"The nice thing about standards is that there
are so many of them to choose from."
 -- Andrew Tanenbaum