From patchwork Wed Mar 28 18:47:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 149298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 27157B6EF1 for ; Thu, 29 Mar 2012 05:47:12 +1100 (EST) Received: from localhost ([::1]:51824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCxtl-0000yr-SG for incoming@patchwork.ozlabs.org; Wed, 28 Mar 2012 14:47:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCxsV-0000sJ-Lt for qemu-devel@nongnu.org; Wed, 28 Mar 2012 14:45:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCxsT-00041o-NO for qemu-devel@nongnu.org; Wed, 28 Mar 2012 14:45:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62482) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCxsT-00041g-FI for qemu-devel@nongnu.org; Wed, 28 Mar 2012 14:45:49 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2SIjlw8020794 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 28 Mar 2012 14:45:47 -0400 Received: from shalem.localdomain.com (vpn1-6-189.ams2.redhat.com [10.36.6.189]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2SIjjpK027421; Wed, 28 Mar 2012 14:45:46 -0400 From: Hans de Goede To: Gerd Hoffmann Date: Wed, 28 Mar 2012 20:47:51 +0200 Message-Id: <1332960471-3317-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Hans de Goede , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] usb-ehci: frindex always is a 14 bits counter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org frindex always is a 14 bits counter, and not a 13 bits one as we were emulating. There are some subtle hints to this in the spec, first of all "Table 2-12. FRINDEX - Frame Index Register" says: "Bit 13:0 Frame Index. The value in this register increments at the end of each time frame (e.g. micro-frame). Bits [N:3] are used for the Frame List current index. This means that each location of the frame list is accessed 8 times (frames or micro-frames) before moving to the next index. The following illustrates values of N based on the value of the Frame List Size field in the USBCMD register. USBCMD[Frame List Size] Number Elements N 00b 1024 12 01b 512 11 10b 256 10 11b Reserved" Notice how the text talks about "Bits [N:3]" are used ..., it does NOT say that when N == 12 (our case) the counter will wrap from 8191 to 0, or in otherwords that it is a 13 bits counter (bits 0 - 12). The other hint is in "Table 2-10. USBSTS USB Status Register Bit Definitions": "Bit 3 Frame List Rollover - R/WC. The Host Controller sets this bit to a one when the Frame List Index (see Section 2.3.4) rolls over from its maximum value to zero. The exact value at which the rollover occurs depends on the frame list size. For example, if the frame list size (as programmed in the Frame List Size field of the USBCMD register) is 1024, the Frame Index Register rolls over every time FRINDEX[13] toggles. Similarly, if the size is 512, the Host Controller sets this bit to a one every time FRINDEX[12] toggles." Notice how this text talks about setting bit 3 when bit 13 of frindex toggles (when there are 1024 entries, so our case), so this indicates that frindex has a bit 13 making it a 14 bit counter. Besides these clear hints the real proof is in the pudding. Before this patch I could not stream data from a USB2 webcam under Windows XP, after this cam using a USB2 webcam under Windows XP works fine, and no regressions with other operating systems were seen. Signed-off-by: Hans de Goede --- hw/usb-ehci.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c index b5d7037..3934bf0 100644 --- a/hw/usb-ehci.c +++ b/hw/usb-ehci.c @@ -2157,11 +2157,15 @@ static void ehci_frame_timer(void *opaque) if ( !(ehci->usbsts & USBSTS_HALT)) { ehci->frindex += 8; - if (ehci->frindex > 0x00001fff) { - ehci->frindex = 0; + if (ehci->frindex == 0x00002000) { ehci_set_interrupt(ehci, USBSTS_FLR); } + if (ehci->frindex == 0x00004000) { + ehci_set_interrupt(ehci, USBSTS_FLR); + ehci->frindex = 0; + } + ehci->sofv = (ehci->frindex - 1) >> 3; ehci->sofv &= 0x000003ff; }