Re: Trouble loading firmware to USB device

From: Farhan Khan <farhan_at_farhan.codes>
Date: Thu, 28 Apr 2022 05:53:36 UTC
On Wednesday, April 27, 2022 3:41:27 AM EDT Hans Petter Selasky wrote:
> Somewhere in the code you are asking for a read of 1024 bytes on the
> interrupt endpoint. That is what usbdump says. That means multiple
> packets will have to be received for it to complete. I'm not sure

Making progress: I got this down to 64 bytes, not 1024, and identified the 
read location.

-----
18:17:30.880855 usbus3.2 SUBM-INTR-EP=00000083,SPD=HIGH,NFR=1,SLEN=0,IVAL=1
 frame[0] READ 64 bytes
 flags 0xa <SHORT_XFER_OK|PIPE_BOF|0>
 status 0xeb023 <OPEN|TRANSFERRING|STARTED|SHORT_XFER_OK|BDMA_ENABLE|
BDMA_SETUP|CURR_DMA_SET|CAN_CANCEL_IMMED|DOING_CALLBACK|0>
-----

The source of this read appears to be after the usbd_transfer_setup(), where I 
send two initial usbd_transfer_start()s, specifically the for the RX Data 
transfer.

usbd_transfer_start(usc->usc_xfer[ATHN_RX_DATA]);

I do this immediately after the usbd_transfer_setup(). I identified this by 
commenting out other lines until I narrowed it down to this single source. 
This line should trigger this callback:

The code is located here: https://github.com/khanzf/freebsd/blob/ar9271/sys/
dev/athn/usb/if_athn_usb.c#L303

I believe earlier in our conversation you advised me to include that transfer. 
Is there something wrong in my callback? The OpenBSD callback is pretty robust 
but for now I was aiming for the minimum necessary to load the firmware.

> printf("FRAME LENGTH = %d\n", usbd_xfer_max_len(xfer));

64 bytes, sounds correct.

> Also make sure there is only one instance of your .ko in /boot/kernel or
> /boot/modules, that you are not loading an old version of the built .ko.

My build script is running make -C /usr/src/sys/modules/athn_usb/ clean, 
cleandepend, then load, I never actually install the module such that it is 
stored in my /boot/modules directory, so I do not anticipate this being an 
issue.

- Farhan