usb devices passthrough in bhyve

From: Steven Friedrich <freebsdlouisville_at_gmail.com>
Date: Sat, 28 Dec 2024 02:10:46 UTC
I have an HP Envy running FreeBSD 14.2.

I am a bhyve noob, but I am able to create a bhyve guest, and installed 
freebsd 14.2 on it.

Here's my host pci devices:

xhci1@pci0:0:20:0:      class=0x0c0330 rev=0x00 hdr=0x00 vendor=0x8086 
device=0x06ed subvendor=0x103c subdevice=0x8767
     vendor     = 'Intel Corporation'
     device     = 'Comet Lake USB 3.1 xHCI Host Controller'
     class      = serial bus
     subclass   = USB

xhci0@pci0:1:0:0:       class=0x0c0330 rev=0x00 hdr=0x00 vendor=0x1b21 
device=0x3242 subvendor=0x1b21 subdevice=0x3242
     vendor     = 'ASMedia Technology Inc.'
     device     = 'ASM3242 USB 3.2 Host Controller'
     class      = serial bus
     subclass   = USB

Here's my usbconfig:

usbconfig
ugen1.1: <Intel XHCI root HUB> at usbus1, cfg=0 md=HOST spd=SUPER 
(5.0Gbps) pwr=SAVE (0mA)
ugen0.1: <(0x1b21) XHCI root HUB> at usbus0, cfg=0 md=HOST spd=SUPER 
(5.0Gbps) pwr=SAVE (0mA)
ugen0.2: <Hub Genesys Logic, Inc.> at usbus0, cfg=0 md=HOST spd=SUPER 
(5.0Gbps) pwr=SAVE (0mA)
ugen1.2: <PixArt HP USB Optical Mouse> at usbus1, cfg=0 md=HOST spd=LOW 
(1.5Mbps) pwr=ON (100mA)
ugen1.3: <Chicony HP USB Keyboard> at usbus1, cfg=0 md=HOST spd=LOW 
(1.5Mbps) pwr=ON (100mA)
ugen1.4: <Realtek Bluetooth Radio> at usbus1, cfg=0 md=HOST spd=FULL 
(12Mbps) pwr=ON (500mA)
ugen0.3: <PNY USB 3.2.1 FD> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) 
pwr=ON (126mA)
ugen0.4: <Hub Genesys Logic, Inc.> at usbus0, cfg=0 md=HOST spd=HIGH 
(480Mbps) pwr=SAVE (100mA)

Originally, my PNY flash drive was on usbus1, but when I added 
pptdevs="0/20/0" to /boot/loader.conf, I lost my mouse and keyboard.

Fortunately, I recently added a pcie card supporting usb 20 gbps rates.

So I changed /boot/loader.conf to  pptdevs="1/0/0"

But I don't know how to see the PNY flash drive in the guest.  I was 
hoping I could use gpart show -l and see a /dev/da0 or /dev/da1 drive, 
but I don't.

In the guest, usbconfig:

usbconfig
No device match or lack of permissions.

and pciconf -v -l:

pciconf -v -l
hostb0@pci0:0:0:0:      class=0x060000 rev=0x00 hdr=0x00 vendor=0x1275 
device=0x1275 subvendor=0x0000 subdevice=0x0000
     vendor     = 'Network Appliance Corporation'
     class      = bridge
     subclass   = HOST-PCI
isab0@pci0:0:1:0:       class=0x060100 rev=0x00 hdr=0x00 vendor=0x8086 
device=0x7000 subvendor=0x0000 subdevice=0x0000
     vendor     = 'Intel Corporation'
     device     = '82371SB PIIX3 ISA [Natoma/Triton II]'
     class      = bridge
     subclass   = PCI-ISA
virtio_pci0@pci0:0:2:0: class=0x020000 rev=0x00 hdr=0x00 vendor=0x1af4 
device=0x1000 subvendor=0x1af4 subdevice=0x0001
     vendor     = 'Red Hat, Inc.'
     device     = 'Virtio network device'
     class      = network
     subclass   = ethernet
virtio_pci1@pci0:0:3:0: class=0x010000 rev=0x00 hdr=0x00 vendor=0x1af4 
device=0x1001 subvendor=0x1af4 subdevice=0x0002
     vendor     = 'Red Hat, Inc.'
     device     = 'Virtio block device'
     class      = mass storage
     subclass   = SCSI

How do I fix this?