All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Akihiko Odaki" <akihiko.odaki@gmail.com>,
	"Canokeys.org" <contact@canokeys.org>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Hongren (Zenithal) Zheng" <i@zenithal.me>
Subject: [PULL 6/8] hw/usb/canokey: fix compatibility of qemu-xhci
Date: Mon,  4 Jul 2022 09:59:44 +0200	[thread overview]
Message-ID: <20220704075946.921883-7-kraxel@redhat.com> (raw)
In-Reply-To: <20220704075946.921883-1-kraxel@redhat.com>

From: "Hongren (Zenithal) Zheng" <i@zenithal.me>

XHCI wont poll interrupt IN endpoint if NAKed, and needs wakeup

Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Hongren (Zenithal) Zheng <i@zenithal.me>
Message-Id: <YqcqSHNpI7sXRNpZ@Sun>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/canokey.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/hw/usb/canokey.c b/hw/usb/canokey.c
index 86548923eb16..8da0d65556af 100644
--- a/hw/usb/canokey.c
+++ b/hw/usb/canokey.c
@@ -103,6 +103,13 @@ int canokey_emu_transmit(
             pbuf, size);
     key->ep_in_size[ep_in] += size;
     key->ep_in_state[ep_in] = CANOKEY_EP_IN_READY;
+    /*
+     * wake up controller if we NAKed IN token before
+     * Note: this is a quirk for CanoKey CTAPHID
+     */
+    if (ep_in == CANOKEY_EMU_EP_CTAPHID) {
+        usb_wakeup(usb_ep_get(&key->dev, USB_TOKEN_IN, ep_in), 0);
+    }
     /*
      * ready for more data in device loop
      *
@@ -208,6 +215,22 @@ static void canokey_handle_data(USBDevice *dev, USBPacket *p)
             key->ep_out_size[ep_out] = out_len;
             canokey_emu_data_out(ep_out, NULL);
         }
+        /*
+         * Note: this is a quirk for CanoKey CTAPHID
+         *
+         * There is one code path that uses this device loop
+         * INTR IN -> useful data_in and useless device_loop -> NAKed
+         * INTR OUT -> useful device loop -> transmit -> wakeup
+         *   (useful thanks to both data_in and data_out having been called)
+         * the next INTR IN -> actual data to guest
+         *
+         * if there is no such device loop, there would be no further
+         * INTR IN, no device loop, no transmit hence no usb_wakeup
+         * then qemu would hang
+         */
+        if (ep_in == CANOKEY_EMU_EP_CTAPHID) {
+            canokey_emu_device_loop(); /* may call transmit multiple times */
+        }
         break;
     case USB_TOKEN_IN:
         if (key->ep_in_pos[ep_in] == 0) { /* first time IN */
-- 
2.36.1



  parent reply	other threads:[~2022-07-04  8:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04  7:59 [PULL 0/8] Kraxel 20220704 patches Gerd Hoffmann
2022-07-04  7:59 ` [PULL 1/8] Rename docs/specs/fw_cfg.txt to .rst Gerd Hoffmann
2022-07-04  7:59 ` [PULL 2/8] Convert fw_cfg.rst to reStructuredText syntax Gerd Hoffmann
2022-07-04  7:59 ` [PULL 3/8] ui/console: allow display device to be labeled with given id Gerd Hoffmann
2022-07-04  7:59 ` [PULL 4/8] ui/cocoa: Fix clipboard text release Gerd Hoffmann
2022-07-04  7:59 ` [PULL 5/8] hw/usb/canokey: Fix CCID ZLP Gerd Hoffmann
2022-07-04  7:59 ` Gerd Hoffmann [this message]
2022-07-04  7:59 ` [PULL 7/8] docs/system/devices/usb/canokey: remove limitations on qemu-xhci Gerd Hoffmann
2022-07-04  7:59 ` [PULL 8/8] hw: canokey: Remove HS support as not compliant to the spec Gerd Hoffmann
2022-07-04 11:06 ` [PULL 0/8] Kraxel 20220704 patches Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220704075946.921883-7-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=akihiko.odaki@gmail.com \
    --cc=contact@canokeys.org \
    --cc=f4bug@amsat.org \
    --cc=i@zenithal.me \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.