1. 23 4月, 2013 1 次提交
    • H
      ehci_free_packet: Discard finished packets when the queue is halted · e449f26b
      Hans de Goede 提交于
      With pipelining it is possible to encounter a finished packet when cleaning
      the queue due to a halt. This happens when a non stall error happens while
      talking to a real device. In this case the queue on the usb-host side will
      continue processing packets, and we can have completed packets waiting in
      the queue after an error condition packet causing a halt.
      
      There are 2 reasons to discard the completed packets at this point, rather
      then trying to writing them back to the guest:
      
      1) The guest expect to be able to cancel and/or change packets after the
      packet with the error without doing an unlink, so writing them back may
      confuse the guest.
      
      2) Since the queue does not advance when halted, the writing back of these
      packets will fail anyways since p->qtdaddr != q->qtdaddr, so the
      ehci_verify_qtd call in ehci_writeback_async_complete_packet will fail.
      
      Note that 2) means that then only functional change this patch introduces
      is the printing of a warning when this scenario happens.
      
      Note that discarding these packets means that the guest driver and the device
      will get out of sync! This is unfortunate, but should not be a problem since
      with a non stall error (iow an io-error) the 2 are out of sync already anyways.
      Still this patch adds a warning to signal this happening.
      
      Note that sofar this has only been seen with a DVB-T receiver, which gives
      of a MPEG-2 stream, which allows for recovering from lost packets, see:
      https://bugzilla.redhat.com/show_bug.cgi?id=890320Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      e449f26b
  2. 19 2月, 2013 1 次提交
  3. 14 1月, 2013 1 次提交
  4. 07 1月, 2013 12 次提交
  5. 04 12月, 2012 1 次提交
    • H
      ehci: Lower timer freq when the periodic schedule is idle · 80826240
      Hans de Goede 提交于
      Lower the timer freq if no iso schedule packets complete for 64 frames in
      a row.
      
      We can safely do this, without adding latency, because:
      1) If there is isoc traffic this will never trigger
      2) For async handled interrupt packets (only usb-host), the completion handler
         will immediately schedule the frame_timer from a bh
      3) All devices using NAK to signal no data for interrupt endpoints now use
         wakeup, which will immediately schedule the frame_timer from a bh
      
      The advantage of this is that when we only have interrupt packets in the
      periodic schedule, async_stepdown can do its work and significantly lower
      the frequency at which the frame_timer runs.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      80826240
  6. 16 11月, 2012 6 次提交
  7. 09 11月, 2012 3 次提交
    • H
    • H
      ehci: Get rid of the magical PROC_ERR status · 01e26b0e
      Hans de Goede 提交于
      Instead make ehci_execute and ehci_fill_queue return the again value.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      01e26b0e
    • H
      usb: split packet result into actual_length + status · 9a77a0f5
      Hans de Goede 提交于
      Since with the ehci and xhci controllers a single packet can be larger
      then maxpacketsize, it is possible for the result of a single packet
      to be both having transferred some data as well as the transfer to have
      an error.
      
      An example would be an input transfer from a bulk endpoint successfully
      receiving 1 or more maxpacketsize packets from the device, followed
      by a packet signalling halt.
      
      While already touching all the devices and controllers handle_packet /
      handle_data / handle_control code, also change the return type of
      these functions to void, solely storing the status in the packet. To
      make the code paths for regular versus async packet handling more
      uniform.
      
      This patch unfortunately is somewhat invasive, since makeing the qemu
      usb core deal with this requires changes everywhere. This patch only
      prepares the usb core for this, all the hcd / device changes are done
      in such a way that there are no functional changes.
      
      This patch has been tested with uhci and ehci hcds, together with usb-audio,
      usb-hid and usb-storage devices, as well as with usb-redir redirection
      with a wide variety of real devices.
      
      Note that there is usually no need to directly set packet->actual_length
      form devices handle_data callback, as that is done by usb_packet_copy()
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      9a77a0f5
  8. 01 11月, 2012 5 次提交
  9. 25 10月, 2012 10 次提交
    • H
      usb: Enforce iso endpoints never returing USB_RET_ASYNC · aaac7434
      Hans de Goede 提交于
      ehci was already testing for this, and we depend in various places
      on no devices doing this, so lets move the check for this to the
      usb core.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      aaac7434
    • H
      usb: Add an int_req flag to USBPacket · a6fb2ddb
      Hans de Goede 提交于
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      a6fb2ddb
    • H
      usb: Move short-not-ok handling to the core · 6ba43f1f
      Hans de Goede 提交于
      After a short-not-ok packet ending short, we should not advance the queue.
      Move enforcing this to the core, rather then handling it in the hcd code.
      
      This may result in the queue now actually containing multiple input packets
      (which would not happen before), and this requires special handling in
      combination with pipelining, so disable pipleining for input endpoints
      (for now).
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      6ba43f1f
    • H
      usb: Move clearing of queue on halt to the core · 0cae7b1a
      Hans de Goede 提交于
      hcds which queue up more then one packet at once (uhci, ehci and xhci),
      must clear the queue after an error which has caused the queue to halt.
      
      Currently this is handled as a special case inside the hcd code, this
      patch instead adds an USB_RET_REMOVE_FROM_QUEUE packet result code, teaches
      the 3 hcds about this and moves the clearing of the queue on a halt into
      the USB core.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      0cae7b1a
    • H
      usb: Add USB_RET_ADD_TO_QUEUE packet result code · 36dfe324
      Hans de Goede 提交于
      This can be used by usb-device code which wishes to process an entire endpoint
      queue at once, to do this the usb-device code returns USB_RET_ADD_TO_QUEUE
      from its handle_data class method and defines a flush_ep_queue class method
      to call when the hcd is done queuing up packets.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      36dfe324
    • H
      ehci: Retry to fill the queue while waiting for td completion · b4ea8664
      Hans de Goede 提交于
      If the guest is using multiple transfers to try and keep the usb bus busy /
      used at maximum efficiency, currently we would see / do the following:
      
      1) submit transfer 1 to the device
      2) submit transfer 2 to the device
      3) report transfer 1 completion to guest
      4) report transfer 2 completion to guest
      5) submit transfer 1 to the device
      6) report transfer 1 completion to guest
      7) submit transfer 2 to the device
      8) report transfer 2 completion to guest
      etc.
      
      So after the initial submission we would effectively only have 1 transfer
      in flight, rather then 2. This is caused by us not checking the queue for
      addition of new transfers by the guest (ie the resubmission of a recently
      finished transfer), while waiting for a pending transfer to complete.
      This patch does add a check for this, changing the sequence to:
      
      1) submit transfer 1 to the device
      2) submit transfer 2 to the device
      3) report transfer 1 completion to guest
      4) submit transfer 1 to the device
      5) report transfer 2 completion to guest
      6) submit transfer 2 to the device
      etc.
      
      Thus keeping 2 transfers in flight (most of the time, and always 1),
      as intended by the guest.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      b4ea8664
    • H
      ehci: Detect going in circles when filling the queue · e3a36bce
      Hans de Goede 提交于
      For ctrl endpoints Windows (atleast Win7) creates circular td lists, so far
      these were not a problem because we would stop filling the queue if altnext
      was set. Since further patches in this patchset remove the altnext check this
      does become a problem and we need detection for going in circles.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      e3a36bce
    • H
      ehci: Speed up the timer of raising int from the async schedule · 44272b0f
      Hans de Goede 提交于
      Often the guest will queue up new packets in response to a packet, in the
      async schedule with its IOC flag set, completing. By speeding up the
      frame-timer, we notice these new packets earlier. This increases the
      speed (MB/s) of a Linux guest reading from a USB mass storage device by a
      factor of 1.15 on top of the "Improve latency of interrupt delivery"
      speed-ups, both with and without input pipelining enabled.
      
      I've not tested the speed-up of this patch without the
      "Improve latency of interrupt delivery" patch.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      44272b0f
    • H
      ehci: Improve latency of interrupt delivery and async schedule scanning · 0262f65a
      Hans de Goede 提交于
      While doing various performance tests of reading from USB mass storage devices
      I noticed the following::
      1) When an async handled packet completes, we don't immediately report an
         interrupt to the guest, instead we wait for the frame-timer to run and
         report it from there
      2) If 1) has been fixed and an async handled packet takes a while to complete,
         then async_stepdown will become a high value, which means that there
         will be a large latency before any new packets queued by the guest in
         response to the interrupt get seen
      
      1) was done deliberately as part of commit f0ad01f9:
      http://www.kraxel.org/cgit/qemu/commit/?h=usb.57&id=f0ad01f92ca02eee7cadbfd225c5de753ebd5fce
      Since setting the interrupt immediately on async packet completion was causing
      issues with Linux guests, I believe this recently fixed Linux bug explains
      why this is happening:
      http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=361aabf395e4a23cf554cf4ec0c0c6963b8beb01
      
      Note that we can *not* count on this fix being present in all Linux guests!
      
      I was hoping that the recently added support for Interrupt Threshold Control
      would fix the issues with Linux guests, but adding a simple ehci_commit_irq()
      call to ehci_async_bh() still caused problems with Linux guests.
      
      The problem is, that when doing ehci_commit_irq() from ehci_async_bh(),
      the "old" frindex value is used to calculate usbsts_frindex, and when
      the frame-timer then runs possibly very shortly after ehci_async_bh(),
      it increases the frame-timer, and thus any interrupts raised from that
      frame-timer run, will also get reported to the guest immediately, rather
      then being delayed to the next frame-timer run.
      
      Luckily the solution for this is simple, this means that we need to
      increase frindex before calling ehci_commit_irq() from ehci_async_bh(),
      which in the end boils down to simple calling ehci_frame_timer() instead
      of ehci_async_bh() from the bh.
      
      This may seem like it causes a lot of extra work to be done, but this
      is not true. Any work done from the frame-timer processing the periodic
      schedule is work which then does not need to be done the next time the
      frame timer runs, also the frame-timer will re-arm itself at (possibly)
      a later time then it was armed for saving a vmexit at that time.
      
      As an additional advantage moving to simply calling the frame-timer also
      fixes 2) as the packet completion will set async_stepdown to 0, and the
      re-arming of the timer with an async_stepdown of 0 ensures that any
      newly queued up packets get seen in a reasonable amount of time.
      
      This improves the speed (MB/s) of a Linux guest reading from a USB mass
      storage device by a factor of 1.5 - 1.7 with input pipelining disabled,
      and by a factor of 1.8 with input pipelining enabled.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      0262f65a
    • H
      ehci: Set int flag on a short input packet · cf08a8a1
      Hans de Goede 提交于
      According to 4.15.1.2 an interrupt must be raised when a short packet
      is received. If we don't do this it may take a significant time for
      the guest to notice a short trasnfer has completed, since only the last td
      will have its IOC flag set, and a short transfer may complete in an earlier
      packet.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      cf08a8a1