From owner-freebsd-hackers@freebsd.org Tue Mar 17 13:13:27 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B3E75265E9E; Tue, 17 Mar 2020 13:13:27 +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) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 48hYWn5NH1z4K5r; Tue, 17 Mar 2020 13:13:25 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2020.home.selasky.org (unknown [62.141.129.235]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id CB5E2260133; Tue, 17 Mar 2020 14:13:20 +0100 (CET) Subject: Re: USB device passthrough implementation To: Daniel Nicolescu , freebsd-virtualization@freebsd.org, freebsd-hackers@freebsd.org Cc: patrascu.naina14@gmail.com, Mihai Carabas References: From: Hans Petter Selasky Message-ID: Date: Tue, 17 Mar 2020 14:12:19 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 48hYWn5NH1z4K5r 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 [-3.19 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+a:mail.turbocat.net:c]; NEURAL_HAM_LONG(-1.00)[-0.996,0]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[selasky.org]; RCPT_COUNT_FIVE(0.00)[5]; SUSPICIOUS_RECIPS(1.50)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_MEDIUM(-0.72)[-0.722,0]; IP_SCORE(-2.67)[ip: (-9.20), ipnet: 2a01:4f8::/29(-2.57), asn: 24940(-1.56), country: DE(-0.02)]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/29, country:DE]; FREEMAIL_CC(0.00)[gmail.com]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Mar 2020 13:13:27 -0000 Hi, On 2020-03-17 13:41, Daniel Nicolescu wrote: > Hi, > > We want to implement the USB pass through feature for bhyve so that users > will be able to pass through individual USB devices like in QEMU. We are > trying to emulate the USB controller and pass to the virtual machine only > one port. > > * We need to disconnect the USB device from host: we are currently not very > familiar with the kernel API to perform this See: libusb_detach_kernel_driver(). > * We need to emulate a USB device controller: we are currently looking into > pci_xhci.c and usb_mouse.c to reuse some of the code from there and we > would like to know if there is some sort of in depth documentation > regarding these. > * We need to pass the USB device to the guest through an emulated port of > the device controller: we know that project ACRN implements USB device > passthrough and we are trying to figure out how they do it. > > Could you give us a few suggestions on how to tackle these? USB has four transfer types: 1) Control transfers 2) Interrupt transfers 3) Bulk transfers 4) Isochronous transfers If your implementation is supposed to be fully USB compliant you need to support and test all transfer types. Please also pay attention to error conditions. USB has different speeds, LOW, HIGH, FULL, SUPER, which impose different characteristics on the USB wMaxPacketSize for example. You should know about the principle of short-terminated USB transfers. Is the wrapper supposed to be implemented in the kernel or in user-space? --HPS