From: Paul Zimmerman <pauldzim@gmail.com>
To: kraxel@redhat.com
Cc: peter.maydell@linaro.org, stefanha@gmail.com,
qemu-devel@nongnu.org, Paul Zimmerman <pauldzim@gmail.com>,
jsnow@redhat.com, f4bug@amsat.org
Subject: [PATCH 5/6] Add short-packet handling to usb-storage driver
Date: Sun, 22 Mar 2020 15:27:25 -0700 [thread overview]
Message-ID: <20200322222726.10244-6-pauldzim@gmail.com> (raw)
In-Reply-To: <20200322222726.10244-1-pauldzim@gmail.com>
The dwc-hsotg (dwc2) USB host depends on a short packet to
indicate the end of an IN transfer. The usb-storage driver
currently doesn't provide this, so fix it.
Signed-off-by: Paul Zimmerman <pauldzim@gmail.com>
---
hw/usb/dev-storage.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 5c4b57b06b..ae3c550042 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -229,6 +229,9 @@ static void usb_msd_copy_data(MSDState *s, USBPacket *p)
usb_packet_copy(p, scsi_req_get_buf(s->req) + s->scsi_off, len);
s->scsi_len -= len;
s->scsi_off += len;
+ if (len > s->data_len) {
+ len = s->data_len;
+ }
s->data_len -= len;
if (s->scsi_len == 0 || s->data_len == 0) {
scsi_req_continue(s->req);
@@ -303,6 +306,9 @@ static void usb_msd_command_complete(SCSIRequest *req, uint32_t status, size_t r
if (s->data_len) {
int len = (p->iov.size - p->actual_length);
usb_packet_skip(p, len);
+ if (len > s->data_len) {
+ len = s->data_len;
+ }
s->data_len -= len;
}
if (s->data_len == 0) {
@@ -469,6 +475,9 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
int len = p->iov.size - p->actual_length;
if (len) {
usb_packet_skip(p, len);
+ if (len > s->data_len) {
+ len = s->data_len;
+ }
s->data_len -= len;
if (s->data_len == 0) {
s->mode = USB_MSDM_CSW;
@@ -528,13 +537,17 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
int len = p->iov.size - p->actual_length;
if (len) {
usb_packet_skip(p, len);
+ if (len > s->data_len) {
+ len = s->data_len;
+ }
s->data_len -= len;
if (s->data_len == 0) {
s->mode = USB_MSDM_CSW;
}
}
}
- if (p->actual_length < p->iov.size) {
+ if (p->actual_length < p->iov.size && (p->short_not_ok ||
+ s->scsi_len >= p->ep->max_packet_size)) {
DPRINTF("Deferring packet %p [wait data-in]\n", p);
s->packet = p;
p->status = USB_RET_ASYNC;
--
2.17.1
next prev parent reply other threads:[~2020-03-22 22:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-22 22:27 [PATCH 0/6] dwc-hsotg (aka dwc2) USB host contoller emulation Paul Zimmerman
2020-03-22 22:27 ` [PATCH 1/6] Add BCM2835 SOC MPHI emulation Paul Zimmerman
2020-03-22 22:27 ` [PATCH 2/6] dwc-hsotg USB host controller register definitions Paul Zimmerman
2020-03-22 22:27 ` [PATCH 3/6] dwc-hsotg USB host controller state definitions Paul Zimmerman
2020-03-22 22:27 ` [PATCH 4/6] dwc-hsotg USB host controller emulation Paul Zimmerman
2020-03-22 22:27 ` Paul Zimmerman [this message]
2020-03-22 22:27 ` [PATCH 6/6] Wire in the " Paul Zimmerman
2020-03-22 22:39 ` [PATCH 0/6] dwc-hsotg (aka dwc2) USB host contoller emulation Paul Zimmerman
2020-03-22 22:46 ` no-reply
2020-03-23 11:09 ` Gerd Hoffmann
2020-03-24 23:32 ` Paul Zimmerman
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=20200322222726.10244-6-pauldzim@gmail.com \
--to=pauldzim@gmail.com \
--cc=f4bug@amsat.org \
--cc=jsnow@redhat.com \
--cc=kraxel@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).