From owner-svn-src-head@FreeBSD.ORG Sun Apr 5 18:19:32 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 713901065950; Sun, 5 Apr 2009 18:19:32 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EC7038FC16; Sun, 5 Apr 2009 18:19:30 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n35IJUYS027638; Sun, 5 Apr 2009 18:19:30 GMT (envelope-from thompsa@svn.freebsd.org) Received: (from thompsa@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n35IJU43027637; Sun, 5 Apr 2009 18:19:30 GMT (envelope-from thompsa@svn.freebsd.org) Message-Id: <200904051819.n35IJU43027637@svn.freebsd.org> From: Andrew Thompson Date: Sun, 5 Apr 2009 18:19:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190728 - head/sys/dev/usb/bluetooth X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Apr 2009 18:19:36 -0000 Author: thompsa Date: Sun Apr 5 18:19:30 2009 New Revision: 190728 URL: http://svn.freebsd.org/changeset/base/190728 Log: MFp4 //depot/projects/usb@159863 Speed up the endpoint descriptor search Submitted by: Hans Petter Selasky Modified: head/sys/dev/usb/bluetooth/ng_ubt.c Modified: head/sys/dev/usb/bluetooth/ng_ubt.c ============================================================================== --- head/sys/dev/usb/bluetooth/ng_ubt.c Sun Apr 5 18:19:19 2009 (r190727) +++ head/sys/dev/usb/bluetooth/ng_ubt.c Sun Apr 5 18:19:30 2009 (r190728) @@ -426,6 +426,7 @@ ubt_attach(device_t dev) struct usb2_attach_arg *uaa = device_get_ivars(dev); struct ubt_softc *sc = device_get_softc(dev); struct usb2_endpoint_descriptor *ed; + struct usb2_interface_descriptor *id; uint16_t wMaxPacketSize; uint8_t alt_index, i, j; uint8_t iface_index[2] = { 0, 1 }; @@ -496,31 +497,34 @@ ubt_attach(device_t dev) alt_index = 0; i = 0; j = 0; + ed = NULL; - /* Search through all the descriptors looking for bidir mode */ - while (1) { - uint16_t temp; - - ed = usb2_find_edesc(usb2_get_config_descriptor(uaa->device), - 1, i, j); - if (ed == NULL) { - if (j != 0) { - /* next interface */ - j = 0; - i ++; - continue; + /* + * Search through all the descriptors looking for the largest + * packet size: + */ + while ((ed = (struct usb2_endpoint_descriptor *)usb2_desc_foreach( + usb2_get_config_descriptor(uaa->device), + (struct usb2_descriptor *)ed))) { + + if ((ed->bDescriptorType == UDESC_INTERFACE) && + (ed->bLength >= sizeof(*id))) { + id = (struct usb2_interface_descriptor *)ed; + i = id->bInterfaceNumber; + j = id->bAlternateSetting; + } + + if ((ed->bDescriptorType == UDESC_ENDPOINT) && + (ed->bLength >= sizeof(*ed)) && + (i == 1)) { + uint16_t temp; + + temp = UGETW(ed->wMaxPacketSize); + if (temp > wMaxPacketSize) { + wMaxPacketSize = temp; + alt_index = j; } - - break; /* end of interfaces */ } - - temp = UGETW(ed->wMaxPacketSize); - if (temp > wMaxPacketSize) { - wMaxPacketSize = temp; - alt_index = i; - } - - j ++; } /* Set alt configuration on interface #1 only if we found it */