[usb] Select preferred USB device configuration based on driver score

Generate a score for each possible USB device configuration based on
the available driver support, and select the configuration with the
highest score.  This will allow us to prefer ECM over RNDIS (for
devices which support both) and will allow us to meaningfully select a
configuration even when we have drivers available for all functions
(e.g. when exposing unused functions via EFI_USB_IO_PROTOCOL).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2015-09-14 21:45:34 +01:00
parent e727f576c2
commit 549a0caabb
10 changed files with 309 additions and 167 deletions
+1
View File
@@ -542,6 +542,7 @@ static struct usb_device_id hub_ids[] = {
struct usb_driver usb_hub_driver __usb_driver = {
.ids = hub_ids,
.id_count = ( sizeof ( hub_ids ) / sizeof ( hub_ids[0] ) ),
.score = USB_SCORE_NORMAL,
.probe = hub_probe,
.remove = hub_remove,
};
+8 -10
View File
@@ -158,7 +158,7 @@ static int usbio_interface ( struct usbio_device *usbio,
continue;
/* Iterate over all interfaces for a match */
for ( i = 0 ; i < func->count ; i++ ) {
for ( i = 0 ; i < func->desc.count ; i++ ) {
if ( interface->interface ==
func->interface[i] )
return interface->interface;
@@ -1287,15 +1287,13 @@ static int usbio_supported ( EFI_HANDLE handle ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_USB_DEVICE_DESCRIPTOR device;
EFI_USB_INTERFACE_DESCRIPTOR interface;
struct usb_class class;
struct usb_function_descriptor desc;
struct usb_driver *driver;
struct usb_device_id *id;
union {
void *interface;
EFI_USB_IO_PROTOCOL *io;
} usb;
unsigned int vendor;
unsigned int product;
EFI_STATUS efirc;
int rc;
@@ -1318,8 +1316,8 @@ static int usbio_supported ( EFI_HANDLE handle ) {
"%s\n", efi_handle_name ( handle ), strerror ( rc ) );
goto err_get_device_descriptor;
}
vendor = device.IdVendor;
product = device.IdProduct;
desc.vendor = device.IdVendor;
desc.product = device.IdProduct;
/* Get interface descriptor */
if ( ( efirc = usb.io->UsbGetInterfaceDescriptor ( usb.io,
@@ -1329,12 +1327,12 @@ static int usbio_supported ( EFI_HANDLE handle ) {
"%s\n", efi_handle_name ( handle ), strerror ( rc ) );
goto err_get_interface_descriptor;
}
class.class = interface.InterfaceClass;
class.subclass = interface.InterfaceSubClass;
class.protocol = interface.InterfaceProtocol;
desc.class.class = interface.InterfaceClass;
desc.class.subclass = interface.InterfaceSubClass;
desc.class.protocol = interface.InterfaceProtocol;
/* Look for a driver for this interface */
driver = usb_find_driver ( vendor, product, &class, &id );
driver = usb_find_driver ( &desc, &id );
if ( ! driver ) {
rc = -ENOTSUP;
goto err_unsupported;
+1
View File
@@ -449,6 +449,7 @@ static struct usb_device_id usbkbd_ids[] = {
struct usb_driver usbkbd_driver __usb_driver = {
.ids = usbkbd_ids,
.id_count = ( sizeof ( usbkbd_ids ) / sizeof ( usbkbd_ids[0] ) ),
.score = USB_SCORE_NORMAL,
.probe = usbkbd_probe,
.remove = usbkbd_remove,
};
+2 -2
View File
@@ -173,7 +173,7 @@ static int usbnet_comms_describe ( struct usbnet_device *usbnet,
int rc;
/* Iterate over all available interfaces */
for ( i = 0 ; i < usbnet->func->count ; i++ ) {
for ( i = 0 ; i < usbnet->func->desc.count ; i++ ) {
/* Get interface number */
comms = usbnet->func->interface[i];
@@ -217,7 +217,7 @@ static int usbnet_data_describe ( struct usbnet_device *usbnet,
int rc;
/* Iterate over all available interfaces */
for ( i = 0 ; i < usbnet->func->count ; i++ ) {
for ( i = 0 ; i < usbnet->func->desc.count ; i++ ) {
/* Get interface number */
data = usbnet->func->interface[i];