2017-11-03 18:28:30 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-07-10 04:56:51 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2008 Takahiro Hirofuchi
|
2016-03-09 04:48:57 +08:00
|
|
|
* Copyright (C) 2015-2016 Samsung Electronics
|
|
|
|
* Krzysztof Opasiak <k.opasiak@samsung.com>
|
2008-07-10 04:56:51 +08:00
|
|
|
*/
|
|
|
|
|
2011-05-12 13:33:43 +08:00
|
|
|
#include <asm/byteorder.h>
|
2008-07-10 04:56:51 +08:00
|
|
|
#include <linux/file.h>
|
2011-05-12 13:33:43 +08:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/kernel.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2012-08-17 10:22:36 +08:00
|
|
|
#include <linux/stat.h>
|
2011-08-31 05:50:46 +08:00
|
|
|
#include <linux/module.h>
|
2012-08-17 10:22:36 +08:00
|
|
|
#include <linux/moduleparam.h>
|
2011-05-12 13:33:43 +08:00
|
|
|
#include <net/sock.h>
|
2011-05-06 18:47:56 +08:00
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
#include "usbip_common.h"
|
|
|
|
|
2011-05-06 18:47:56 +08:00
|
|
|
#define DRIVER_AUTHOR "Takahiro Hirofuchi <hirofuchi@users.sourceforge.net>"
|
2011-05-12 13:33:44 +08:00
|
|
|
#define DRIVER_DESC "USB/IP Core"
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2011-05-12 13:33:44 +08:00
|
|
|
#ifdef CONFIG_USBIP_DEBUG
|
2008-07-10 04:56:51 +08:00
|
|
|
unsigned long usbip_debug_flag = 0xffffffff;
|
|
|
|
#else
|
|
|
|
unsigned long usbip_debug_flag;
|
|
|
|
#endif
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_debug_flag);
|
2012-08-17 10:22:36 +08:00
|
|
|
module_param(usbip_debug_flag, ulong, S_IRUGO|S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(usbip_debug_flag, "debug flags (defined in usbip_common.h)");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
struct device_attribute dev_attr_usbip_debug;
|
|
|
|
EXPORT_SYMBOL_GPL(dev_attr_usbip_debug);
|
|
|
|
|
2013-08-27 03:02:54 +08:00
|
|
|
static ssize_t usbip_debug_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%lx\n", usbip_debug_flag);
|
|
|
|
}
|
|
|
|
|
2013-08-27 03:02:54 +08:00
|
|
|
static ssize_t usbip_debug_store(struct device *dev,
|
|
|
|
struct device_attribute *attr, const char *buf,
|
|
|
|
size_t count)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
2014-03-07 07:51:59 +08:00
|
|
|
if (sscanf(buf, "%lx", &usbip_debug_flag) != 1)
|
|
|
|
return -EINVAL;
|
2008-07-10 04:56:51 +08:00
|
|
|
return count;
|
|
|
|
}
|
2013-08-27 03:02:54 +08:00
|
|
|
DEVICE_ATTR_RW(usbip_debug);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
static void usbip_dump_buffer(char *buff, int bufflen)
|
|
|
|
{
|
2011-05-20 07:47:32 +08:00
|
|
|
print_hex_dump(KERN_DEBUG, "usbip-core", DUMP_PREFIX_OFFSET, 16, 4,
|
2010-01-23 05:22:41 +08:00
|
|
|
buff, bufflen, false);
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usbip_dump_pipe(unsigned int p)
|
|
|
|
{
|
|
|
|
unsigned char type = usb_pipetype(p);
|
2011-05-20 12:36:56 +08:00
|
|
|
unsigned char ep = usb_pipeendpoint(p);
|
|
|
|
unsigned char dev = usb_pipedevice(p);
|
|
|
|
unsigned char dir = usb_pipein(p);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("dev(%d) ep(%d) [%s] ", dev, ep, dir ? "IN" : "OUT");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case PIPE_ISOCHRONOUS:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("ISO\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case PIPE_INTERRUPT:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("INT\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case PIPE_CONTROL:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("CTRL\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case PIPE_BULK:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("BULK\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("ERR\n");
|
2011-05-06 18:47:54 +08:00
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usbip_dump_usb_device(struct usb_device *udev)
|
|
|
|
{
|
|
|
|
struct device *dev = &udev->dev;
|
|
|
|
int i;
|
|
|
|
|
2014-01-25 00:25:05 +08:00
|
|
|
dev_dbg(dev, " devnum(%d) devpath(%s) usb speed(%s)",
|
|
|
|
udev->devnum, udev->devpath, usb_speed_string(udev->speed));
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2017-12-23 08:00:06 +08:00
|
|
|
pr_debug("tt hub ttport %d\n", udev->ttport);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
dev_dbg(dev, " ");
|
|
|
|
for (i = 0; i < 16; i++)
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug(" %2u", i);
|
|
|
|
pr_debug("\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
dev_dbg(dev, " toggle0(IN) :");
|
|
|
|
for (i = 0; i < 16; i++)
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug(" %2u", (udev->toggle[0] & (1 << i)) ? 1 : 0);
|
|
|
|
pr_debug("\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
dev_dbg(dev, " toggle1(OUT):");
|
|
|
|
for (i = 0; i < 16; i++)
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug(" %2u", (udev->toggle[1] & (1 << i)) ? 1 : 0);
|
|
|
|
pr_debug("\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
dev_dbg(dev, " epmaxp_in :");
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
if (udev->ep_in[i])
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug(" %2u",
|
|
|
|
le16_to_cpu(udev->ep_in[i]->desc.wMaxPacketSize));
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
dev_dbg(dev, " epmaxp_out :");
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
if (udev->ep_out[i])
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug(" %2u",
|
|
|
|
le16_to_cpu(udev->ep_out[i]->desc.wMaxPacketSize));
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2017-12-23 08:00:06 +08:00
|
|
|
dev_dbg(dev, "parent %s, bus %s\n", dev_name(&udev->parent->dev),
|
|
|
|
udev->bus->bus_name);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
dev_dbg(dev, "have_langid %d, string_langid %d\n",
|
|
|
|
udev->have_langid, udev->string_langid);
|
|
|
|
|
2012-09-05 13:44:32 +08:00
|
|
|
dev_dbg(dev, "maxchild %d\n", udev->maxchild);
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usbip_dump_request_type(__u8 rt)
|
|
|
|
{
|
|
|
|
switch (rt & USB_RECIP_MASK) {
|
|
|
|
case USB_RECIP_DEVICE:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("DEVICE");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_RECIP_INTERFACE:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("INTERF");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_RECIP_ENDPOINT:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("ENDPOI");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_RECIP_OTHER:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("OTHER ");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("------");
|
2011-05-06 18:47:54 +08:00
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usbip_dump_usb_ctrlrequest(struct usb_ctrlrequest *cmd)
|
|
|
|
{
|
|
|
|
if (!cmd) {
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug(" : null pointer\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug(" ");
|
2014-03-20 06:04:56 +08:00
|
|
|
pr_debug("bRequestType(%02X) bRequest(%02X) wValue(%04X) wIndex(%04X) wLength(%04X) ",
|
|
|
|
cmd->bRequestType, cmd->bRequest,
|
2011-05-20 07:47:32 +08:00
|
|
|
cmd->wValue, cmd->wIndex, cmd->wLength);
|
|
|
|
pr_debug("\n ");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("STANDARD ");
|
2008-07-10 04:56:51 +08:00
|
|
|
switch (cmd->bRequest) {
|
|
|
|
case USB_REQ_GET_STATUS:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("GET_STATUS\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_CLEAR_FEATURE:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("CLEAR_FEAT\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_FEATURE:
|
2011-06-06 21:07:31 +08:00
|
|
|
pr_debug("SET_FEAT\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_ADDRESS:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("SET_ADDRRS\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_GET_DESCRIPTOR:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("GET_DESCRI\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_DESCRIPTOR:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("SET_DESCRI\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_GET_CONFIGURATION:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("GET_CONFIG\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_CONFIGURATION:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("SET_CONFIG\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_GET_INTERFACE:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("GET_INTERF\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_INTERFACE:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("SET_INTERF\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_SYNCH_FRAME:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("SYNC_FRAME\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
2011-06-06 21:07:31 +08:00
|
|
|
pr_debug("REQ(%02X)\n", cmd->bRequest);
|
2011-05-06 18:47:54 +08:00
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
usbip_dump_request_type(cmd->bRequestType);
|
2011-05-20 07:47:32 +08:00
|
|
|
} else if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS) {
|
2011-06-06 21:07:31 +08:00
|
|
|
pr_debug("CLASS\n");
|
2011-05-20 07:47:32 +08:00
|
|
|
} else if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_VENDOR) {
|
2011-06-06 21:07:31 +08:00
|
|
|
pr_debug("VENDOR\n");
|
2011-05-20 07:47:32 +08:00
|
|
|
} else if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_RESERVED) {
|
|
|
|
pr_debug("RESERVED\n");
|
|
|
|
}
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void usbip_dump_urb(struct urb *urb)
|
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
if (!urb) {
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("urb: null pointer!!\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!urb->dev) {
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("urb->dev: null pointer!!\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-05-20 07:47:32 +08:00
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
dev = &urb->dev->dev;
|
|
|
|
|
|
|
|
usbip_dump_usb_device(urb->dev);
|
|
|
|
|
|
|
|
dev_dbg(dev, " pipe :%08x ", urb->pipe);
|
|
|
|
|
|
|
|
usbip_dump_pipe(urb->pipe);
|
|
|
|
|
|
|
|
dev_dbg(dev, " status :%d\n", urb->status);
|
|
|
|
dev_dbg(dev, " transfer_flags :%08X\n", urb->transfer_flags);
|
2009-07-21 14:46:13 +08:00
|
|
|
dev_dbg(dev, " transfer_buffer_length:%d\n",
|
|
|
|
urb->transfer_buffer_length);
|
2008-07-10 04:56:51 +08:00
|
|
|
dev_dbg(dev, " actual_length :%d\n", urb->actual_length);
|
|
|
|
|
|
|
|
if (urb->setup_packet && usb_pipetype(urb->pipe) == PIPE_CONTROL)
|
2011-05-06 18:47:46 +08:00
|
|
|
usbip_dump_usb_ctrlrequest(
|
2008-07-10 04:56:51 +08:00
|
|
|
(struct usb_ctrlrequest *)urb->setup_packet);
|
|
|
|
|
|
|
|
dev_dbg(dev, " start_frame :%d\n", urb->start_frame);
|
|
|
|
dev_dbg(dev, " number_of_packets :%d\n", urb->number_of_packets);
|
|
|
|
dev_dbg(dev, " interval :%d\n", urb->interval);
|
|
|
|
dev_dbg(dev, " error_count :%d\n", urb->error_count);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_dump_urb);
|
|
|
|
|
|
|
|
void usbip_dump_header(struct usbip_header *pdu)
|
|
|
|
{
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("BASE: cmd %u seq %u devid %u dir %u ep %u\n",
|
|
|
|
pdu->base.command,
|
|
|
|
pdu->base.seqnum,
|
|
|
|
pdu->base.devid,
|
|
|
|
pdu->base.direction,
|
|
|
|
pdu->base.ep);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
switch (pdu->base.command) {
|
|
|
|
case USBIP_CMD_SUBMIT:
|
2014-03-20 06:04:56 +08:00
|
|
|
pr_debug("USBIP_CMD_SUBMIT: x_flags %u x_len %u sf %u #p %d iv %d\n",
|
2011-05-20 07:47:32 +08:00
|
|
|
pdu->u.cmd_submit.transfer_flags,
|
|
|
|
pdu->u.cmd_submit.transfer_buffer_length,
|
|
|
|
pdu->u.cmd_submit.start_frame,
|
|
|
|
pdu->u.cmd_submit.number_of_packets,
|
|
|
|
pdu->u.cmd_submit.interval);
|
2011-05-06 18:47:46 +08:00
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
case USBIP_CMD_UNLINK:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("USBIP_CMD_UNLINK: seq %u\n",
|
|
|
|
pdu->u.cmd_unlink.seqnum);
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
case USBIP_RET_SUBMIT:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("USBIP_RET_SUBMIT: st %d al %u sf %d #p %d ec %d\n",
|
|
|
|
pdu->u.ret_submit.status,
|
|
|
|
pdu->u.ret_submit.actual_length,
|
|
|
|
pdu->u.ret_submit.start_frame,
|
|
|
|
pdu->u.ret_submit.number_of_packets,
|
|
|
|
pdu->u.ret_submit.error_count);
|
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
case USBIP_RET_UNLINK:
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_debug("USBIP_RET_UNLINK: status %d\n",
|
|
|
|
pdu->u.ret_unlink.status);
|
2008-07-10 04:56:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* NOT REACHED */
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_err("unknown command\n");
|
2011-05-06 18:47:54 +08:00
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_dump_header);
|
|
|
|
|
2011-12-20 06:44:11 +08:00
|
|
|
/* Receive data over TCP/IP. */
|
|
|
|
int usbip_recv(struct socket *sock, void *buf, int size)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
int result;
|
2014-12-21 16:53:10 +08:00
|
|
|
struct kvec iov = {.iov_base = buf, .iov_len = size};
|
|
|
|
struct msghdr msg = {.msg_flags = MSG_NOSIGNAL};
|
2008-07-10 04:56:51 +08:00
|
|
|
int total = 0;
|
|
|
|
|
2017-12-16 01:50:09 +08:00
|
|
|
if (!sock || !buf || !size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-10-20 07:57:56 +08:00
|
|
|
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, size);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2009-07-21 14:46:13 +08:00
|
|
|
usbip_dbg_xmit("enter\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
do {
|
|
|
|
sock->sk->sk_allocation = GFP_NOIO;
|
2014-12-21 16:53:10 +08:00
|
|
|
|
|
|
|
result = sock_recvmsg(sock, &msg, MSG_WAITALL);
|
2017-12-16 01:50:09 +08:00
|
|
|
if (result <= 0)
|
2008-07-10 04:56:51 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
total += result;
|
2014-12-21 16:53:10 +08:00
|
|
|
} while (msg_data_left(&msg));
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2009-07-21 14:46:13 +08:00
|
|
|
if (usbip_dbg_flag_xmit) {
|
2011-12-20 06:44:11 +08:00
|
|
|
if (!in_interrupt())
|
|
|
|
pr_debug("%-10s:", current->comm);
|
|
|
|
else
|
|
|
|
pr_debug("interrupt :");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2011-12-20 06:44:11 +08:00
|
|
|
pr_debug("receiving....\n");
|
2014-12-21 16:53:10 +08:00
|
|
|
usbip_dump_buffer(buf, size);
|
|
|
|
pr_debug("received, osize %d ret %d size %zd total %d\n",
|
|
|
|
size, result, msg_data_left(&msg), total);
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
|
|
|
|
err:
|
|
|
|
return result;
|
|
|
|
}
|
2011-12-20 06:44:11 +08:00
|
|
|
EXPORT_SYMBOL_GPL(usbip_recv);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/* there may be more cases to tweak the flags. */
|
|
|
|
static unsigned int tweak_transfer_flags(unsigned int flags)
|
|
|
|
{
|
2010-05-01 04:35:37 +08:00
|
|
|
flags &= ~URB_NO_TRANSFER_DMA_MAP;
|
2008-07-10 04:56:51 +08:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usbip_pack_cmd_submit(struct usbip_header *pdu, struct urb *urb,
|
2011-05-06 18:47:46 +08:00
|
|
|
int pack)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
struct usbip_header_cmd_submit *spdu = &pdu->u.cmd_submit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some members are not still implemented in usbip. I hope this issue
|
|
|
|
* will be discussed when usbip is ported to other operating systems.
|
|
|
|
*/
|
|
|
|
if (pack) {
|
|
|
|
spdu->transfer_flags =
|
2011-05-06 18:47:46 +08:00
|
|
|
tweak_transfer_flags(urb->transfer_flags);
|
2008-07-10 04:56:51 +08:00
|
|
|
spdu->transfer_buffer_length = urb->transfer_buffer_length;
|
|
|
|
spdu->start_frame = urb->start_frame;
|
|
|
|
spdu->number_of_packets = urb->number_of_packets;
|
|
|
|
spdu->interval = urb->interval;
|
|
|
|
} else {
|
|
|
|
urb->transfer_flags = spdu->transfer_flags;
|
|
|
|
urb->transfer_buffer_length = spdu->transfer_buffer_length;
|
|
|
|
urb->start_frame = spdu->start_frame;
|
|
|
|
urb->number_of_packets = spdu->number_of_packets;
|
|
|
|
urb->interval = spdu->interval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usbip_pack_ret_submit(struct usbip_header *pdu, struct urb *urb,
|
2011-05-06 18:47:46 +08:00
|
|
|
int pack)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
struct usbip_header_ret_submit *rpdu = &pdu->u.ret_submit;
|
|
|
|
|
|
|
|
if (pack) {
|
|
|
|
rpdu->status = urb->status;
|
|
|
|
rpdu->actual_length = urb->actual_length;
|
|
|
|
rpdu->start_frame = urb->start_frame;
|
2011-04-06 02:26:38 +08:00
|
|
|
rpdu->number_of_packets = urb->number_of_packets;
|
2008-07-10 04:56:51 +08:00
|
|
|
rpdu->error_count = urb->error_count;
|
|
|
|
} else {
|
|
|
|
urb->status = rpdu->status;
|
|
|
|
urb->actual_length = rpdu->actual_length;
|
|
|
|
urb->start_frame = rpdu->start_frame;
|
2011-04-06 02:26:38 +08:00
|
|
|
urb->number_of_packets = rpdu->number_of_packets;
|
2008-07-10 04:56:51 +08:00
|
|
|
urb->error_count = rpdu->error_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd,
|
2011-05-06 18:47:46 +08:00
|
|
|
int pack)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case USBIP_CMD_SUBMIT:
|
|
|
|
usbip_pack_cmd_submit(pdu, urb, pack);
|
|
|
|
break;
|
|
|
|
case USBIP_RET_SUBMIT:
|
|
|
|
usbip_pack_ret_submit(pdu, urb, pack);
|
|
|
|
break;
|
|
|
|
default:
|
2011-05-06 18:47:54 +08:00
|
|
|
/* NOT REACHED */
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_err("unknown command\n");
|
2011-05-06 18:47:54 +08:00
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_pack_pdu);
|
|
|
|
|
|
|
|
static void correct_endian_basic(struct usbip_header_basic *base, int send)
|
|
|
|
{
|
|
|
|
if (send) {
|
|
|
|
base->command = cpu_to_be32(base->command);
|
|
|
|
base->seqnum = cpu_to_be32(base->seqnum);
|
|
|
|
base->devid = cpu_to_be32(base->devid);
|
|
|
|
base->direction = cpu_to_be32(base->direction);
|
|
|
|
base->ep = cpu_to_be32(base->ep);
|
|
|
|
} else {
|
|
|
|
base->command = be32_to_cpu(base->command);
|
|
|
|
base->seqnum = be32_to_cpu(base->seqnum);
|
|
|
|
base->devid = be32_to_cpu(base->devid);
|
|
|
|
base->direction = be32_to_cpu(base->direction);
|
|
|
|
base->ep = be32_to_cpu(base->ep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void correct_endian_cmd_submit(struct usbip_header_cmd_submit *pdu,
|
2011-05-06 18:47:46 +08:00
|
|
|
int send)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
if (send) {
|
|
|
|
pdu->transfer_flags = cpu_to_be32(pdu->transfer_flags);
|
|
|
|
|
|
|
|
cpu_to_be32s(&pdu->transfer_buffer_length);
|
|
|
|
cpu_to_be32s(&pdu->start_frame);
|
|
|
|
cpu_to_be32s(&pdu->number_of_packets);
|
|
|
|
cpu_to_be32s(&pdu->interval);
|
|
|
|
} else {
|
|
|
|
pdu->transfer_flags = be32_to_cpu(pdu->transfer_flags);
|
|
|
|
|
|
|
|
be32_to_cpus(&pdu->transfer_buffer_length);
|
|
|
|
be32_to_cpus(&pdu->start_frame);
|
|
|
|
be32_to_cpus(&pdu->number_of_packets);
|
|
|
|
be32_to_cpus(&pdu->interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void correct_endian_ret_submit(struct usbip_header_ret_submit *pdu,
|
2011-05-06 18:47:46 +08:00
|
|
|
int send)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
if (send) {
|
|
|
|
cpu_to_be32s(&pdu->status);
|
|
|
|
cpu_to_be32s(&pdu->actual_length);
|
|
|
|
cpu_to_be32s(&pdu->start_frame);
|
2011-04-06 02:26:38 +08:00
|
|
|
cpu_to_be32s(&pdu->number_of_packets);
|
2008-07-10 04:56:51 +08:00
|
|
|
cpu_to_be32s(&pdu->error_count);
|
|
|
|
} else {
|
|
|
|
be32_to_cpus(&pdu->status);
|
|
|
|
be32_to_cpus(&pdu->actual_length);
|
|
|
|
be32_to_cpus(&pdu->start_frame);
|
2011-05-12 18:31:11 +08:00
|
|
|
be32_to_cpus(&pdu->number_of_packets);
|
2008-07-10 04:56:51 +08:00
|
|
|
be32_to_cpus(&pdu->error_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void correct_endian_cmd_unlink(struct usbip_header_cmd_unlink *pdu,
|
2011-05-06 18:47:46 +08:00
|
|
|
int send)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
if (send)
|
|
|
|
pdu->seqnum = cpu_to_be32(pdu->seqnum);
|
|
|
|
else
|
|
|
|
pdu->seqnum = be32_to_cpu(pdu->seqnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void correct_endian_ret_unlink(struct usbip_header_ret_unlink *pdu,
|
2011-05-06 18:47:46 +08:00
|
|
|
int send)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
if (send)
|
|
|
|
cpu_to_be32s(&pdu->status);
|
|
|
|
else
|
|
|
|
be32_to_cpus(&pdu->status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void usbip_header_correct_endian(struct usbip_header *pdu, int send)
|
|
|
|
{
|
|
|
|
__u32 cmd = 0;
|
|
|
|
|
|
|
|
if (send)
|
|
|
|
cmd = pdu->base.command;
|
|
|
|
|
|
|
|
correct_endian_basic(&pdu->base, send);
|
|
|
|
|
|
|
|
if (!send)
|
|
|
|
cmd = pdu->base.command;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case USBIP_CMD_SUBMIT:
|
|
|
|
correct_endian_cmd_submit(&pdu->u.cmd_submit, send);
|
|
|
|
break;
|
|
|
|
case USBIP_RET_SUBMIT:
|
|
|
|
correct_endian_ret_submit(&pdu->u.ret_submit, send);
|
|
|
|
break;
|
|
|
|
case USBIP_CMD_UNLINK:
|
|
|
|
correct_endian_cmd_unlink(&pdu->u.cmd_unlink, send);
|
|
|
|
break;
|
|
|
|
case USBIP_RET_UNLINK:
|
|
|
|
correct_endian_ret_unlink(&pdu->u.ret_unlink, send);
|
|
|
|
break;
|
|
|
|
default:
|
2011-05-06 18:47:54 +08:00
|
|
|
/* NOT REACHED */
|
2011-05-20 07:47:32 +08:00
|
|
|
pr_err("unknown command\n");
|
2011-05-06 18:47:54 +08:00
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_header_correct_endian);
|
|
|
|
|
2011-05-20 12:37:01 +08:00
|
|
|
static void usbip_iso_packet_correct_endian(
|
2011-05-20 12:36:56 +08:00
|
|
|
struct usbip_iso_packet_descriptor *iso, int send)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
/* does not need all members. but copy all simply. */
|
|
|
|
if (send) {
|
|
|
|
iso->offset = cpu_to_be32(iso->offset);
|
|
|
|
iso->length = cpu_to_be32(iso->length);
|
|
|
|
iso->status = cpu_to_be32(iso->status);
|
|
|
|
iso->actual_length = cpu_to_be32(iso->actual_length);
|
|
|
|
} else {
|
|
|
|
iso->offset = be32_to_cpu(iso->offset);
|
|
|
|
iso->length = be32_to_cpu(iso->length);
|
|
|
|
iso->status = be32_to_cpu(iso->status);
|
|
|
|
iso->actual_length = be32_to_cpu(iso->actual_length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usbip_pack_iso(struct usbip_iso_packet_descriptor *iso,
|
2011-05-06 18:47:46 +08:00
|
|
|
struct usb_iso_packet_descriptor *uiso, int pack)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
if (pack) {
|
|
|
|
iso->offset = uiso->offset;
|
|
|
|
iso->length = uiso->length;
|
|
|
|
iso->status = uiso->status;
|
|
|
|
iso->actual_length = uiso->actual_length;
|
|
|
|
} else {
|
|
|
|
uiso->offset = iso->offset;
|
|
|
|
uiso->length = iso->length;
|
|
|
|
uiso->status = iso->status;
|
|
|
|
uiso->actual_length = iso->actual_length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must free buffer */
|
2012-10-11 01:34:25 +08:00
|
|
|
struct usbip_iso_packet_descriptor*
|
|
|
|
usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
struct usbip_iso_packet_descriptor *iso;
|
|
|
|
int np = urb->number_of_packets;
|
|
|
|
ssize_t size = np * sizeof(*iso);
|
|
|
|
int i;
|
|
|
|
|
2012-10-11 01:34:25 +08:00
|
|
|
iso = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!iso)
|
2008-07-10 04:56:51 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < np; i++) {
|
2012-10-11 01:34:25 +08:00
|
|
|
usbip_pack_iso(&iso[i], &urb->iso_frame_desc[i], 1);
|
|
|
|
usbip_iso_packet_correct_endian(&iso[i], 1);
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
*bufflen = size;
|
|
|
|
|
2012-10-11 01:34:25 +08:00
|
|
|
return iso;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_alloc_iso_desc_pdu);
|
|
|
|
|
|
|
|
/* some members of urb must be substituted before. */
|
|
|
|
int usbip_recv_iso(struct usbip_device *ud, struct urb *urb)
|
|
|
|
{
|
|
|
|
void *buff;
|
|
|
|
struct usbip_iso_packet_descriptor *iso;
|
|
|
|
int np = urb->number_of_packets;
|
|
|
|
int size = np * sizeof(*iso);
|
|
|
|
int i;
|
|
|
|
int ret;
|
2011-04-06 02:26:59 +08:00
|
|
|
int total_length = 0;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
if (!usb_pipeisoc(urb->pipe))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* my Bluetooth dongle gets ISO URBs which are np = 0 */
|
2013-01-17 11:16:05 +08:00
|
|
|
if (np == 0)
|
2008-07-10 04:56:51 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
buff = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!buff)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-12-20 06:44:11 +08:00
|
|
|
ret = usbip_recv(ud->tcp_socket, buff, size);
|
2008-07-10 04:56:51 +08:00
|
|
|
if (ret != size) {
|
|
|
|
dev_err(&urb->dev->dev, "recv iso_frame_descriptor, %d\n",
|
|
|
|
ret);
|
|
|
|
kfree(buff);
|
|
|
|
|
2016-03-09 04:48:57 +08:00
|
|
|
if (ud->side == USBIP_STUB || ud->side == USBIP_VUDC)
|
2008-07-10 04:56:51 +08:00
|
|
|
usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
|
|
|
|
else
|
|
|
|
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
|
|
|
|
|
|
|
|
return -EPIPE;
|
|
|
|
}
|
|
|
|
|
2012-10-11 01:34:25 +08:00
|
|
|
iso = (struct usbip_iso_packet_descriptor *) buff;
|
2008-07-10 04:56:51 +08:00
|
|
|
for (i = 0; i < np; i++) {
|
2012-10-11 01:34:25 +08:00
|
|
|
usbip_iso_packet_correct_endian(&iso[i], 0);
|
|
|
|
usbip_pack_iso(&iso[i], &urb->iso_frame_desc[i], 0);
|
2011-04-06 02:26:59 +08:00
|
|
|
total_length += urb->iso_frame_desc[i].actual_length;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(buff);
|
|
|
|
|
2011-04-06 02:26:59 +08:00
|
|
|
if (total_length != urb->actual_length) {
|
|
|
|
dev_err(&urb->dev->dev,
|
2014-03-20 06:04:56 +08:00
|
|
|
"total length of iso packets %d not equal to actual length of buffer %d\n",
|
2011-05-06 18:47:46 +08:00
|
|
|
total_length, urb->actual_length);
|
2011-04-06 02:26:59 +08:00
|
|
|
|
2016-03-09 04:48:57 +08:00
|
|
|
if (ud->side == USBIP_STUB || ud->side == USBIP_VUDC)
|
2011-04-06 02:26:59 +08:00
|
|
|
usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
|
|
|
|
else
|
|
|
|
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
|
|
|
|
|
|
|
|
return -EPIPE;
|
|
|
|
}
|
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_recv_iso);
|
|
|
|
|
2011-04-06 02:26:59 +08:00
|
|
|
/*
|
|
|
|
* This functions restores the padding which was removed for optimizing
|
|
|
|
* the bandwidth during transfer over tcp/ip
|
|
|
|
*
|
|
|
|
* buffer and iso packets need to be stored and be in propeper endian in urb
|
|
|
|
* before calling this function
|
|
|
|
*/
|
2012-01-23 23:55:46 +08:00
|
|
|
void usbip_pad_iso(struct usbip_device *ud, struct urb *urb)
|
2011-04-06 02:26:59 +08:00
|
|
|
{
|
|
|
|
int np = urb->number_of_packets;
|
|
|
|
int i;
|
|
|
|
int actualoffset = urb->actual_length;
|
|
|
|
|
|
|
|
if (!usb_pipeisoc(urb->pipe))
|
2012-01-23 23:55:46 +08:00
|
|
|
return;
|
2011-04-06 02:26:59 +08:00
|
|
|
|
|
|
|
/* if no packets or length of data is 0, then nothing to unpack */
|
|
|
|
if (np == 0 || urb->actual_length == 0)
|
2012-01-23 23:55:46 +08:00
|
|
|
return;
|
2011-04-06 02:26:59 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if actual_length is transfer_buffer_length then no padding is
|
|
|
|
* present.
|
2012-10-11 01:34:27 +08:00
|
|
|
*/
|
2011-04-06 02:26:59 +08:00
|
|
|
if (urb->actual_length == urb->transfer_buffer_length)
|
2012-01-23 23:55:46 +08:00
|
|
|
return;
|
2011-04-06 02:26:59 +08:00
|
|
|
|
|
|
|
/*
|
2017-02-28 06:29:48 +08:00
|
|
|
* loop over all packets from last to first (to prevent overwriting
|
2011-04-06 02:26:59 +08:00
|
|
|
* memory when padding) and move them into the proper place
|
|
|
|
*/
|
|
|
|
for (i = np-1; i > 0; i--) {
|
|
|
|
actualoffset -= urb->iso_frame_desc[i].actual_length;
|
|
|
|
memmove(urb->transfer_buffer + urb->iso_frame_desc[i].offset,
|
2011-05-06 18:47:46 +08:00
|
|
|
urb->transfer_buffer + actualoffset,
|
|
|
|
urb->iso_frame_desc[i].actual_length);
|
2011-04-06 02:26:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_pad_iso);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/* some members of urb must be substituted before. */
|
|
|
|
int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb)
|
|
|
|
{
|
usbip: Implement SG support to vhci-hcd and stub driver
There are bugs on vhci with usb 3.0 storage device. In USB, each SG
list entry buffer should be divisible by the bulk max packet size.
But with native SG support, this problem doesn't matter because the
SG buffer is treated as contiguous buffer. But without native SG
support, USB storage driver breaks SG list into several URBs and the
error occurs because of a buffer size of URB that cannot be divided
by the bulk max packet size. The error situation is as follows.
When USB Storage driver requests 31.5 KB data and has SG list which
has 3584 bytes buffer followed by 7 4096 bytes buffer for some
reason. USB Storage driver splits this SG list into several URBs
because VHCI doesn't support SG and sends them separately. So the
first URB buffer size is 3584 bytes. When receiving data from device,
USB 3.0 device sends data packet of 1024 bytes size because the max
packet size of BULK pipe is 1024 bytes. So device sends 4096 bytes.
But the first URB buffer has only 3584 bytes buffer size. So host
controller terminates the transfer even though there is more data to
receive. So, vhci needs to support SG transfer to prevent this error.
In this patch, vhci supports SG regardless of whether the server's
host controller supports SG or not, because stub driver splits SG
list into several URBs if the server's host controller doesn't
support SG.
To support SG, vhci sets URB_DMA_MAP_SG flag in urb->transfer_flags
if URB has SG list and this flag will tell stub driver to use SG
list. After receiving urb from stub driver, vhci clear URB_DMA_MAP_SG
flag to avoid unnecessary DMA unmapping in HCD.
vhci sends each SG list entry to stub driver. Then, stub driver sees
the total length of the buffer and allocates SG table and pages
according to the total buffer length calling sgl_alloc(). After stub
driver receives completed URB, it again sends each SG list entry to
vhci.
If the server's host controller doesn't support SG, stub driver
breaks a single SG request into several URBs and submits them to
the server's host controller. When all the split URBs are completed,
stub driver reassembles the URBs into a single return command and
sends it to vhci.
Moreover, in the situation where vhci supports SG, but stub driver
does not, or vice versa, usbip works normally. Because there is no
protocol modification, there is no problem in communication between
server and client even if the one has a kernel without SG support.
In the case of vhci supports SG and stub driver doesn't, because
vhci sends only the total length of the buffer to stub driver as
it did before the patch applied, stub driver only needs to allocate
the required length of buffers using only kmalloc() regardless of
whether vhci supports SG or not. But stub driver has to allocate
buffer with kmalloc() as much as the total length of SG buffer which
is quite huge when vhci sends SG request, so it has overhead in
buffer allocation in this situation.
If stub driver needs to send data buffer to vhci because of IN pipe,
stub driver also sends only total length of buffer as metadata and
then sends real data as vhci does. Then vhci receive data from stub
driver and store it to the corresponding buffer of SG list entry.
And for the case of stub driver supports SG and vhci doesn't, since
the USB storage driver checks that vhci doesn't support SG and sends
the request to stub driver by splitting the SG list into multiple
URBs, stub driver allocates a buffer for each URB with kmalloc() as
it did before this patch.
* Test environment
Test uses two difference machines and two different kernel version
to make mismatch situation between the client and the server where
vhci supports SG, but stub driver does not, or vice versa. All tests
are conducted in both full SG support that both vhci and stub support
SG and half SG support that is the mismatch situation. Test kernel
version is 5.3-rc6 with commit "usb: add a HCD_DMA flag instead of
guestimating DMA capabilities" to avoid unnecessary DMA mapping and
unmapping.
- Test kernel version
- 5.3-rc6 with SG support
- 5.1.20-200.fc29.x86_64 without SG support
* SG support test
- Test devices
- Super-speed storage device - SanDisk Ultra USB 3.0
- High-speed storage device - SMI corporation USB 2.0 flash drive
- Test description
Test read and write operation of mass storage device that uses the
BULK transfer. In test, the client reads and writes files whose size
is over 1G and it works normally.
* Regression test
- Test devices
- Super-speed device - Logitech Brio webcam
- High-speed device - Logitech C920 HD Pro webcam
- Full-speed device - Logitech bluetooth mouse
- Britz BR-Orion speaker
- Low-speed device - Logitech wired mouse
- Test description
Moving and click test for mouse. To test the webcam, use gnome-cheese.
To test the speaker, play music and video on the client. All works
normally.
* VUDC compatibility test
VUDC also works well with this patch. Tests are done with two USB
gadget created by CONFIGFS USB gadget. Both use the BULK pipe.
1. Serial gadget
2. Mass storage gadget
- Serial gadget test
Serial gadget on the host sends and receives data using cat command
on the /dev/ttyGS<N>. The client uses minicom to communicate with
the serial gadget.
- Mass storage gadget test
After connecting the gadget with vhci, use "dd" to test read and
write operation on the client side.
Read - dd if=/dev/sd<N> iflag=direct of=/dev/null bs=1G count=1
Write - dd if=<my file path> iflag=direct of=/dev/sd<N> bs=1G count=1
Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
Acked-by: Shuah khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190828032741.12234-1-suwan.kim027@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-28 11:27:41 +08:00
|
|
|
struct scatterlist *sg;
|
|
|
|
int ret = 0;
|
|
|
|
int recv;
|
2008-07-10 04:56:51 +08:00
|
|
|
int size;
|
usbip: Implement SG support to vhci-hcd and stub driver
There are bugs on vhci with usb 3.0 storage device. In USB, each SG
list entry buffer should be divisible by the bulk max packet size.
But with native SG support, this problem doesn't matter because the
SG buffer is treated as contiguous buffer. But without native SG
support, USB storage driver breaks SG list into several URBs and the
error occurs because of a buffer size of URB that cannot be divided
by the bulk max packet size. The error situation is as follows.
When USB Storage driver requests 31.5 KB data and has SG list which
has 3584 bytes buffer followed by 7 4096 bytes buffer for some
reason. USB Storage driver splits this SG list into several URBs
because VHCI doesn't support SG and sends them separately. So the
first URB buffer size is 3584 bytes. When receiving data from device,
USB 3.0 device sends data packet of 1024 bytes size because the max
packet size of BULK pipe is 1024 bytes. So device sends 4096 bytes.
But the first URB buffer has only 3584 bytes buffer size. So host
controller terminates the transfer even though there is more data to
receive. So, vhci needs to support SG transfer to prevent this error.
In this patch, vhci supports SG regardless of whether the server's
host controller supports SG or not, because stub driver splits SG
list into several URBs if the server's host controller doesn't
support SG.
To support SG, vhci sets URB_DMA_MAP_SG flag in urb->transfer_flags
if URB has SG list and this flag will tell stub driver to use SG
list. After receiving urb from stub driver, vhci clear URB_DMA_MAP_SG
flag to avoid unnecessary DMA unmapping in HCD.
vhci sends each SG list entry to stub driver. Then, stub driver sees
the total length of the buffer and allocates SG table and pages
according to the total buffer length calling sgl_alloc(). After stub
driver receives completed URB, it again sends each SG list entry to
vhci.
If the server's host controller doesn't support SG, stub driver
breaks a single SG request into several URBs and submits them to
the server's host controller. When all the split URBs are completed,
stub driver reassembles the URBs into a single return command and
sends it to vhci.
Moreover, in the situation where vhci supports SG, but stub driver
does not, or vice versa, usbip works normally. Because there is no
protocol modification, there is no problem in communication between
server and client even if the one has a kernel without SG support.
In the case of vhci supports SG and stub driver doesn't, because
vhci sends only the total length of the buffer to stub driver as
it did before the patch applied, stub driver only needs to allocate
the required length of buffers using only kmalloc() regardless of
whether vhci supports SG or not. But stub driver has to allocate
buffer with kmalloc() as much as the total length of SG buffer which
is quite huge when vhci sends SG request, so it has overhead in
buffer allocation in this situation.
If stub driver needs to send data buffer to vhci because of IN pipe,
stub driver also sends only total length of buffer as metadata and
then sends real data as vhci does. Then vhci receive data from stub
driver and store it to the corresponding buffer of SG list entry.
And for the case of stub driver supports SG and vhci doesn't, since
the USB storage driver checks that vhci doesn't support SG and sends
the request to stub driver by splitting the SG list into multiple
URBs, stub driver allocates a buffer for each URB with kmalloc() as
it did before this patch.
* Test environment
Test uses two difference machines and two different kernel version
to make mismatch situation between the client and the server where
vhci supports SG, but stub driver does not, or vice versa. All tests
are conducted in both full SG support that both vhci and stub support
SG and half SG support that is the mismatch situation. Test kernel
version is 5.3-rc6 with commit "usb: add a HCD_DMA flag instead of
guestimating DMA capabilities" to avoid unnecessary DMA mapping and
unmapping.
- Test kernel version
- 5.3-rc6 with SG support
- 5.1.20-200.fc29.x86_64 without SG support
* SG support test
- Test devices
- Super-speed storage device - SanDisk Ultra USB 3.0
- High-speed storage device - SMI corporation USB 2.0 flash drive
- Test description
Test read and write operation of mass storage device that uses the
BULK transfer. In test, the client reads and writes files whose size
is over 1G and it works normally.
* Regression test
- Test devices
- Super-speed device - Logitech Brio webcam
- High-speed device - Logitech C920 HD Pro webcam
- Full-speed device - Logitech bluetooth mouse
- Britz BR-Orion speaker
- Low-speed device - Logitech wired mouse
- Test description
Moving and click test for mouse. To test the webcam, use gnome-cheese.
To test the speaker, play music and video on the client. All works
normally.
* VUDC compatibility test
VUDC also works well with this patch. Tests are done with two USB
gadget created by CONFIGFS USB gadget. Both use the BULK pipe.
1. Serial gadget
2. Mass storage gadget
- Serial gadget test
Serial gadget on the host sends and receives data using cat command
on the /dev/ttyGS<N>. The client uses minicom to communicate with
the serial gadget.
- Mass storage gadget test
After connecting the gadget with vhci, use "dd" to test read and
write operation on the client side.
Read - dd if=/dev/sd<N> iflag=direct of=/dev/null bs=1G count=1
Write - dd if=<my file path> iflag=direct of=/dev/sd<N> bs=1G count=1
Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
Acked-by: Shuah khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190828032741.12234-1-suwan.kim027@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-28 11:27:41 +08:00
|
|
|
int copy;
|
|
|
|
int i;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2016-03-09 04:48:57 +08:00
|
|
|
if (ud->side == USBIP_STUB || ud->side == USBIP_VUDC) {
|
2008-07-10 04:56:51 +08:00
|
|
|
/* the direction of urb must be OUT. */
|
|
|
|
if (usb_pipein(urb->pipe))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size = urb->transfer_buffer_length;
|
|
|
|
} else {
|
|
|
|
/* the direction of urb must be IN. */
|
|
|
|
if (usb_pipeout(urb->pipe))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size = urb->actual_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no need to recv xbuff */
|
|
|
|
if (!(size > 0))
|
|
|
|
return 0;
|
|
|
|
|
usbip: Implement SG support to vhci-hcd and stub driver
There are bugs on vhci with usb 3.0 storage device. In USB, each SG
list entry buffer should be divisible by the bulk max packet size.
But with native SG support, this problem doesn't matter because the
SG buffer is treated as contiguous buffer. But without native SG
support, USB storage driver breaks SG list into several URBs and the
error occurs because of a buffer size of URB that cannot be divided
by the bulk max packet size. The error situation is as follows.
When USB Storage driver requests 31.5 KB data and has SG list which
has 3584 bytes buffer followed by 7 4096 bytes buffer for some
reason. USB Storage driver splits this SG list into several URBs
because VHCI doesn't support SG and sends them separately. So the
first URB buffer size is 3584 bytes. When receiving data from device,
USB 3.0 device sends data packet of 1024 bytes size because the max
packet size of BULK pipe is 1024 bytes. So device sends 4096 bytes.
But the first URB buffer has only 3584 bytes buffer size. So host
controller terminates the transfer even though there is more data to
receive. So, vhci needs to support SG transfer to prevent this error.
In this patch, vhci supports SG regardless of whether the server's
host controller supports SG or not, because stub driver splits SG
list into several URBs if the server's host controller doesn't
support SG.
To support SG, vhci sets URB_DMA_MAP_SG flag in urb->transfer_flags
if URB has SG list and this flag will tell stub driver to use SG
list. After receiving urb from stub driver, vhci clear URB_DMA_MAP_SG
flag to avoid unnecessary DMA unmapping in HCD.
vhci sends each SG list entry to stub driver. Then, stub driver sees
the total length of the buffer and allocates SG table and pages
according to the total buffer length calling sgl_alloc(). After stub
driver receives completed URB, it again sends each SG list entry to
vhci.
If the server's host controller doesn't support SG, stub driver
breaks a single SG request into several URBs and submits them to
the server's host controller. When all the split URBs are completed,
stub driver reassembles the URBs into a single return command and
sends it to vhci.
Moreover, in the situation where vhci supports SG, but stub driver
does not, or vice versa, usbip works normally. Because there is no
protocol modification, there is no problem in communication between
server and client even if the one has a kernel without SG support.
In the case of vhci supports SG and stub driver doesn't, because
vhci sends only the total length of the buffer to stub driver as
it did before the patch applied, stub driver only needs to allocate
the required length of buffers using only kmalloc() regardless of
whether vhci supports SG or not. But stub driver has to allocate
buffer with kmalloc() as much as the total length of SG buffer which
is quite huge when vhci sends SG request, so it has overhead in
buffer allocation in this situation.
If stub driver needs to send data buffer to vhci because of IN pipe,
stub driver also sends only total length of buffer as metadata and
then sends real data as vhci does. Then vhci receive data from stub
driver and store it to the corresponding buffer of SG list entry.
And for the case of stub driver supports SG and vhci doesn't, since
the USB storage driver checks that vhci doesn't support SG and sends
the request to stub driver by splitting the SG list into multiple
URBs, stub driver allocates a buffer for each URB with kmalloc() as
it did before this patch.
* Test environment
Test uses two difference machines and two different kernel version
to make mismatch situation between the client and the server where
vhci supports SG, but stub driver does not, or vice versa. All tests
are conducted in both full SG support that both vhci and stub support
SG and half SG support that is the mismatch situation. Test kernel
version is 5.3-rc6 with commit "usb: add a HCD_DMA flag instead of
guestimating DMA capabilities" to avoid unnecessary DMA mapping and
unmapping.
- Test kernel version
- 5.3-rc6 with SG support
- 5.1.20-200.fc29.x86_64 without SG support
* SG support test
- Test devices
- Super-speed storage device - SanDisk Ultra USB 3.0
- High-speed storage device - SMI corporation USB 2.0 flash drive
- Test description
Test read and write operation of mass storage device that uses the
BULK transfer. In test, the client reads and writes files whose size
is over 1G and it works normally.
* Regression test
- Test devices
- Super-speed device - Logitech Brio webcam
- High-speed device - Logitech C920 HD Pro webcam
- Full-speed device - Logitech bluetooth mouse
- Britz BR-Orion speaker
- Low-speed device - Logitech wired mouse
- Test description
Moving and click test for mouse. To test the webcam, use gnome-cheese.
To test the speaker, play music and video on the client. All works
normally.
* VUDC compatibility test
VUDC also works well with this patch. Tests are done with two USB
gadget created by CONFIGFS USB gadget. Both use the BULK pipe.
1. Serial gadget
2. Mass storage gadget
- Serial gadget test
Serial gadget on the host sends and receives data using cat command
on the /dev/ttyGS<N>. The client uses minicom to communicate with
the serial gadget.
- Mass storage gadget test
After connecting the gadget with vhci, use "dd" to test read and
write operation on the client side.
Read - dd if=/dev/sd<N> iflag=direct of=/dev/null bs=1G count=1
Write - dd if=<my file path> iflag=direct of=/dev/sd<N> bs=1G count=1
Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
Acked-by: Shuah khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190828032741.12234-1-suwan.kim027@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-28 11:27:41 +08:00
|
|
|
if (size > urb->transfer_buffer_length)
|
2016-03-18 02:00:29 +08:00
|
|
|
/* should not happen, probably malicious packet */
|
usbip: Implement SG support to vhci-hcd and stub driver
There are bugs on vhci with usb 3.0 storage device. In USB, each SG
list entry buffer should be divisible by the bulk max packet size.
But with native SG support, this problem doesn't matter because the
SG buffer is treated as contiguous buffer. But without native SG
support, USB storage driver breaks SG list into several URBs and the
error occurs because of a buffer size of URB that cannot be divided
by the bulk max packet size. The error situation is as follows.
When USB Storage driver requests 31.5 KB data and has SG list which
has 3584 bytes buffer followed by 7 4096 bytes buffer for some
reason. USB Storage driver splits this SG list into several URBs
because VHCI doesn't support SG and sends them separately. So the
first URB buffer size is 3584 bytes. When receiving data from device,
USB 3.0 device sends data packet of 1024 bytes size because the max
packet size of BULK pipe is 1024 bytes. So device sends 4096 bytes.
But the first URB buffer has only 3584 bytes buffer size. So host
controller terminates the transfer even though there is more data to
receive. So, vhci needs to support SG transfer to prevent this error.
In this patch, vhci supports SG regardless of whether the server's
host controller supports SG or not, because stub driver splits SG
list into several URBs if the server's host controller doesn't
support SG.
To support SG, vhci sets URB_DMA_MAP_SG flag in urb->transfer_flags
if URB has SG list and this flag will tell stub driver to use SG
list. After receiving urb from stub driver, vhci clear URB_DMA_MAP_SG
flag to avoid unnecessary DMA unmapping in HCD.
vhci sends each SG list entry to stub driver. Then, stub driver sees
the total length of the buffer and allocates SG table and pages
according to the total buffer length calling sgl_alloc(). After stub
driver receives completed URB, it again sends each SG list entry to
vhci.
If the server's host controller doesn't support SG, stub driver
breaks a single SG request into several URBs and submits them to
the server's host controller. When all the split URBs are completed,
stub driver reassembles the URBs into a single return command and
sends it to vhci.
Moreover, in the situation where vhci supports SG, but stub driver
does not, or vice versa, usbip works normally. Because there is no
protocol modification, there is no problem in communication between
server and client even if the one has a kernel without SG support.
In the case of vhci supports SG and stub driver doesn't, because
vhci sends only the total length of the buffer to stub driver as
it did before the patch applied, stub driver only needs to allocate
the required length of buffers using only kmalloc() regardless of
whether vhci supports SG or not. But stub driver has to allocate
buffer with kmalloc() as much as the total length of SG buffer which
is quite huge when vhci sends SG request, so it has overhead in
buffer allocation in this situation.
If stub driver needs to send data buffer to vhci because of IN pipe,
stub driver also sends only total length of buffer as metadata and
then sends real data as vhci does. Then vhci receive data from stub
driver and store it to the corresponding buffer of SG list entry.
And for the case of stub driver supports SG and vhci doesn't, since
the USB storage driver checks that vhci doesn't support SG and sends
the request to stub driver by splitting the SG list into multiple
URBs, stub driver allocates a buffer for each URB with kmalloc() as
it did before this patch.
* Test environment
Test uses two difference machines and two different kernel version
to make mismatch situation between the client and the server where
vhci supports SG, but stub driver does not, or vice versa. All tests
are conducted in both full SG support that both vhci and stub support
SG and half SG support that is the mismatch situation. Test kernel
version is 5.3-rc6 with commit "usb: add a HCD_DMA flag instead of
guestimating DMA capabilities" to avoid unnecessary DMA mapping and
unmapping.
- Test kernel version
- 5.3-rc6 with SG support
- 5.1.20-200.fc29.x86_64 without SG support
* SG support test
- Test devices
- Super-speed storage device - SanDisk Ultra USB 3.0
- High-speed storage device - SMI corporation USB 2.0 flash drive
- Test description
Test read and write operation of mass storage device that uses the
BULK transfer. In test, the client reads and writes files whose size
is over 1G and it works normally.
* Regression test
- Test devices
- Super-speed device - Logitech Brio webcam
- High-speed device - Logitech C920 HD Pro webcam
- Full-speed device - Logitech bluetooth mouse
- Britz BR-Orion speaker
- Low-speed device - Logitech wired mouse
- Test description
Moving and click test for mouse. To test the webcam, use gnome-cheese.
To test the speaker, play music and video on the client. All works
normally.
* VUDC compatibility test
VUDC also works well with this patch. Tests are done with two USB
gadget created by CONFIGFS USB gadget. Both use the BULK pipe.
1. Serial gadget
2. Mass storage gadget
- Serial gadget test
Serial gadget on the host sends and receives data using cat command
on the /dev/ttyGS<N>. The client uses minicom to communicate with
the serial gadget.
- Mass storage gadget test
After connecting the gadget with vhci, use "dd" to test read and
write operation on the client side.
Read - dd if=/dev/sd<N> iflag=direct of=/dev/null bs=1G count=1
Write - dd if=<my file path> iflag=direct of=/dev/sd<N> bs=1G count=1
Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
Acked-by: Shuah khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190828032741.12234-1-suwan.kim027@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-28 11:27:41 +08:00
|
|
|
goto error;
|
2016-03-18 02:00:29 +08:00
|
|
|
|
usbip: Implement SG support to vhci-hcd and stub driver
There are bugs on vhci with usb 3.0 storage device. In USB, each SG
list entry buffer should be divisible by the bulk max packet size.
But with native SG support, this problem doesn't matter because the
SG buffer is treated as contiguous buffer. But without native SG
support, USB storage driver breaks SG list into several URBs and the
error occurs because of a buffer size of URB that cannot be divided
by the bulk max packet size. The error situation is as follows.
When USB Storage driver requests 31.5 KB data and has SG list which
has 3584 bytes buffer followed by 7 4096 bytes buffer for some
reason. USB Storage driver splits this SG list into several URBs
because VHCI doesn't support SG and sends them separately. So the
first URB buffer size is 3584 bytes. When receiving data from device,
USB 3.0 device sends data packet of 1024 bytes size because the max
packet size of BULK pipe is 1024 bytes. So device sends 4096 bytes.
But the first URB buffer has only 3584 bytes buffer size. So host
controller terminates the transfer even though there is more data to
receive. So, vhci needs to support SG transfer to prevent this error.
In this patch, vhci supports SG regardless of whether the server's
host controller supports SG or not, because stub driver splits SG
list into several URBs if the server's host controller doesn't
support SG.
To support SG, vhci sets URB_DMA_MAP_SG flag in urb->transfer_flags
if URB has SG list and this flag will tell stub driver to use SG
list. After receiving urb from stub driver, vhci clear URB_DMA_MAP_SG
flag to avoid unnecessary DMA unmapping in HCD.
vhci sends each SG list entry to stub driver. Then, stub driver sees
the total length of the buffer and allocates SG table and pages
according to the total buffer length calling sgl_alloc(). After stub
driver receives completed URB, it again sends each SG list entry to
vhci.
If the server's host controller doesn't support SG, stub driver
breaks a single SG request into several URBs and submits them to
the server's host controller. When all the split URBs are completed,
stub driver reassembles the URBs into a single return command and
sends it to vhci.
Moreover, in the situation where vhci supports SG, but stub driver
does not, or vice versa, usbip works normally. Because there is no
protocol modification, there is no problem in communication between
server and client even if the one has a kernel without SG support.
In the case of vhci supports SG and stub driver doesn't, because
vhci sends only the total length of the buffer to stub driver as
it did before the patch applied, stub driver only needs to allocate
the required length of buffers using only kmalloc() regardless of
whether vhci supports SG or not. But stub driver has to allocate
buffer with kmalloc() as much as the total length of SG buffer which
is quite huge when vhci sends SG request, so it has overhead in
buffer allocation in this situation.
If stub driver needs to send data buffer to vhci because of IN pipe,
stub driver also sends only total length of buffer as metadata and
then sends real data as vhci does. Then vhci receive data from stub
driver and store it to the corresponding buffer of SG list entry.
And for the case of stub driver supports SG and vhci doesn't, since
the USB storage driver checks that vhci doesn't support SG and sends
the request to stub driver by splitting the SG list into multiple
URBs, stub driver allocates a buffer for each URB with kmalloc() as
it did before this patch.
* Test environment
Test uses two difference machines and two different kernel version
to make mismatch situation between the client and the server where
vhci supports SG, but stub driver does not, or vice versa. All tests
are conducted in both full SG support that both vhci and stub support
SG and half SG support that is the mismatch situation. Test kernel
version is 5.3-rc6 with commit "usb: add a HCD_DMA flag instead of
guestimating DMA capabilities" to avoid unnecessary DMA mapping and
unmapping.
- Test kernel version
- 5.3-rc6 with SG support
- 5.1.20-200.fc29.x86_64 without SG support
* SG support test
- Test devices
- Super-speed storage device - SanDisk Ultra USB 3.0
- High-speed storage device - SMI corporation USB 2.0 flash drive
- Test description
Test read and write operation of mass storage device that uses the
BULK transfer. In test, the client reads and writes files whose size
is over 1G and it works normally.
* Regression test
- Test devices
- Super-speed device - Logitech Brio webcam
- High-speed device - Logitech C920 HD Pro webcam
- Full-speed device - Logitech bluetooth mouse
- Britz BR-Orion speaker
- Low-speed device - Logitech wired mouse
- Test description
Moving and click test for mouse. To test the webcam, use gnome-cheese.
To test the speaker, play music and video on the client. All works
normally.
* VUDC compatibility test
VUDC also works well with this patch. Tests are done with two USB
gadget created by CONFIGFS USB gadget. Both use the BULK pipe.
1. Serial gadget
2. Mass storage gadget
- Serial gadget test
Serial gadget on the host sends and receives data using cat command
on the /dev/ttyGS<N>. The client uses minicom to communicate with
the serial gadget.
- Mass storage gadget test
After connecting the gadget with vhci, use "dd" to test read and
write operation on the client side.
Read - dd if=/dev/sd<N> iflag=direct of=/dev/null bs=1G count=1
Write - dd if=<my file path> iflag=direct of=/dev/sd<N> bs=1G count=1
Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
Acked-by: Shuah khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190828032741.12234-1-suwan.kim027@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-28 11:27:41 +08:00
|
|
|
if (urb->num_sgs) {
|
|
|
|
copy = size;
|
|
|
|
for_each_sg(urb->sg, sg, urb->num_sgs, i) {
|
|
|
|
int recv_size;
|
|
|
|
|
|
|
|
if (copy < sg->length)
|
|
|
|
recv_size = copy;
|
|
|
|
else
|
|
|
|
recv_size = sg->length;
|
|
|
|
|
|
|
|
recv = usbip_recv(ud->tcp_socket, sg_virt(sg),
|
|
|
|
recv_size);
|
|
|
|
|
|
|
|
if (recv != recv_size)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
copy -= recv;
|
|
|
|
ret += recv;
|
2024-06-11 20:08:33 +08:00
|
|
|
|
|
|
|
if (!copy)
|
|
|
|
break;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
usbip: Implement SG support to vhci-hcd and stub driver
There are bugs on vhci with usb 3.0 storage device. In USB, each SG
list entry buffer should be divisible by the bulk max packet size.
But with native SG support, this problem doesn't matter because the
SG buffer is treated as contiguous buffer. But without native SG
support, USB storage driver breaks SG list into several URBs and the
error occurs because of a buffer size of URB that cannot be divided
by the bulk max packet size. The error situation is as follows.
When USB Storage driver requests 31.5 KB data and has SG list which
has 3584 bytes buffer followed by 7 4096 bytes buffer for some
reason. USB Storage driver splits this SG list into several URBs
because VHCI doesn't support SG and sends them separately. So the
first URB buffer size is 3584 bytes. When receiving data from device,
USB 3.0 device sends data packet of 1024 bytes size because the max
packet size of BULK pipe is 1024 bytes. So device sends 4096 bytes.
But the first URB buffer has only 3584 bytes buffer size. So host
controller terminates the transfer even though there is more data to
receive. So, vhci needs to support SG transfer to prevent this error.
In this patch, vhci supports SG regardless of whether the server's
host controller supports SG or not, because stub driver splits SG
list into several URBs if the server's host controller doesn't
support SG.
To support SG, vhci sets URB_DMA_MAP_SG flag in urb->transfer_flags
if URB has SG list and this flag will tell stub driver to use SG
list. After receiving urb from stub driver, vhci clear URB_DMA_MAP_SG
flag to avoid unnecessary DMA unmapping in HCD.
vhci sends each SG list entry to stub driver. Then, stub driver sees
the total length of the buffer and allocates SG table and pages
according to the total buffer length calling sgl_alloc(). After stub
driver receives completed URB, it again sends each SG list entry to
vhci.
If the server's host controller doesn't support SG, stub driver
breaks a single SG request into several URBs and submits them to
the server's host controller. When all the split URBs are completed,
stub driver reassembles the URBs into a single return command and
sends it to vhci.
Moreover, in the situation where vhci supports SG, but stub driver
does not, or vice versa, usbip works normally. Because there is no
protocol modification, there is no problem in communication between
server and client even if the one has a kernel without SG support.
In the case of vhci supports SG and stub driver doesn't, because
vhci sends only the total length of the buffer to stub driver as
it did before the patch applied, stub driver only needs to allocate
the required length of buffers using only kmalloc() regardless of
whether vhci supports SG or not. But stub driver has to allocate
buffer with kmalloc() as much as the total length of SG buffer which
is quite huge when vhci sends SG request, so it has overhead in
buffer allocation in this situation.
If stub driver needs to send data buffer to vhci because of IN pipe,
stub driver also sends only total length of buffer as metadata and
then sends real data as vhci does. Then vhci receive data from stub
driver and store it to the corresponding buffer of SG list entry.
And for the case of stub driver supports SG and vhci doesn't, since
the USB storage driver checks that vhci doesn't support SG and sends
the request to stub driver by splitting the SG list into multiple
URBs, stub driver allocates a buffer for each URB with kmalloc() as
it did before this patch.
* Test environment
Test uses two difference machines and two different kernel version
to make mismatch situation between the client and the server where
vhci supports SG, but stub driver does not, or vice versa. All tests
are conducted in both full SG support that both vhci and stub support
SG and half SG support that is the mismatch situation. Test kernel
version is 5.3-rc6 with commit "usb: add a HCD_DMA flag instead of
guestimating DMA capabilities" to avoid unnecessary DMA mapping and
unmapping.
- Test kernel version
- 5.3-rc6 with SG support
- 5.1.20-200.fc29.x86_64 without SG support
* SG support test
- Test devices
- Super-speed storage device - SanDisk Ultra USB 3.0
- High-speed storage device - SMI corporation USB 2.0 flash drive
- Test description
Test read and write operation of mass storage device that uses the
BULK transfer. In test, the client reads and writes files whose size
is over 1G and it works normally.
* Regression test
- Test devices
- Super-speed device - Logitech Brio webcam
- High-speed device - Logitech C920 HD Pro webcam
- Full-speed device - Logitech bluetooth mouse
- Britz BR-Orion speaker
- Low-speed device - Logitech wired mouse
- Test description
Moving and click test for mouse. To test the webcam, use gnome-cheese.
To test the speaker, play music and video on the client. All works
normally.
* VUDC compatibility test
VUDC also works well with this patch. Tests are done with two USB
gadget created by CONFIGFS USB gadget. Both use the BULK pipe.
1. Serial gadget
2. Mass storage gadget
- Serial gadget test
Serial gadget on the host sends and receives data using cat command
on the /dev/ttyGS<N>. The client uses minicom to communicate with
the serial gadget.
- Mass storage gadget test
After connecting the gadget with vhci, use "dd" to test read and
write operation on the client side.
Read - dd if=/dev/sd<N> iflag=direct of=/dev/null bs=1G count=1
Write - dd if=<my file path> iflag=direct of=/dev/sd<N> bs=1G count=1
Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
Acked-by: Shuah khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190828032741.12234-1-suwan.kim027@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-28 11:27:41 +08:00
|
|
|
|
|
|
|
if (ret != size)
|
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
ret = usbip_recv(ud->tcp_socket, urb->transfer_buffer, size);
|
|
|
|
if (ret != size)
|
|
|
|
goto error;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
usbip: Implement SG support to vhci-hcd and stub driver
There are bugs on vhci with usb 3.0 storage device. In USB, each SG
list entry buffer should be divisible by the bulk max packet size.
But with native SG support, this problem doesn't matter because the
SG buffer is treated as contiguous buffer. But without native SG
support, USB storage driver breaks SG list into several URBs and the
error occurs because of a buffer size of URB that cannot be divided
by the bulk max packet size. The error situation is as follows.
When USB Storage driver requests 31.5 KB data and has SG list which
has 3584 bytes buffer followed by 7 4096 bytes buffer for some
reason. USB Storage driver splits this SG list into several URBs
because VHCI doesn't support SG and sends them separately. So the
first URB buffer size is 3584 bytes. When receiving data from device,
USB 3.0 device sends data packet of 1024 bytes size because the max
packet size of BULK pipe is 1024 bytes. So device sends 4096 bytes.
But the first URB buffer has only 3584 bytes buffer size. So host
controller terminates the transfer even though there is more data to
receive. So, vhci needs to support SG transfer to prevent this error.
In this patch, vhci supports SG regardless of whether the server's
host controller supports SG or not, because stub driver splits SG
list into several URBs if the server's host controller doesn't
support SG.
To support SG, vhci sets URB_DMA_MAP_SG flag in urb->transfer_flags
if URB has SG list and this flag will tell stub driver to use SG
list. After receiving urb from stub driver, vhci clear URB_DMA_MAP_SG
flag to avoid unnecessary DMA unmapping in HCD.
vhci sends each SG list entry to stub driver. Then, stub driver sees
the total length of the buffer and allocates SG table and pages
according to the total buffer length calling sgl_alloc(). After stub
driver receives completed URB, it again sends each SG list entry to
vhci.
If the server's host controller doesn't support SG, stub driver
breaks a single SG request into several URBs and submits them to
the server's host controller. When all the split URBs are completed,
stub driver reassembles the URBs into a single return command and
sends it to vhci.
Moreover, in the situation where vhci supports SG, but stub driver
does not, or vice versa, usbip works normally. Because there is no
protocol modification, there is no problem in communication between
server and client even if the one has a kernel without SG support.
In the case of vhci supports SG and stub driver doesn't, because
vhci sends only the total length of the buffer to stub driver as
it did before the patch applied, stub driver only needs to allocate
the required length of buffers using only kmalloc() regardless of
whether vhci supports SG or not. But stub driver has to allocate
buffer with kmalloc() as much as the total length of SG buffer which
is quite huge when vhci sends SG request, so it has overhead in
buffer allocation in this situation.
If stub driver needs to send data buffer to vhci because of IN pipe,
stub driver also sends only total length of buffer as metadata and
then sends real data as vhci does. Then vhci receive data from stub
driver and store it to the corresponding buffer of SG list entry.
And for the case of stub driver supports SG and vhci doesn't, since
the USB storage driver checks that vhci doesn't support SG and sends
the request to stub driver by splitting the SG list into multiple
URBs, stub driver allocates a buffer for each URB with kmalloc() as
it did before this patch.
* Test environment
Test uses two difference machines and two different kernel version
to make mismatch situation between the client and the server where
vhci supports SG, but stub driver does not, or vice versa. All tests
are conducted in both full SG support that both vhci and stub support
SG and half SG support that is the mismatch situation. Test kernel
version is 5.3-rc6 with commit "usb: add a HCD_DMA flag instead of
guestimating DMA capabilities" to avoid unnecessary DMA mapping and
unmapping.
- Test kernel version
- 5.3-rc6 with SG support
- 5.1.20-200.fc29.x86_64 without SG support
* SG support test
- Test devices
- Super-speed storage device - SanDisk Ultra USB 3.0
- High-speed storage device - SMI corporation USB 2.0 flash drive
- Test description
Test read and write operation of mass storage device that uses the
BULK transfer. In test, the client reads and writes files whose size
is over 1G and it works normally.
* Regression test
- Test devices
- Super-speed device - Logitech Brio webcam
- High-speed device - Logitech C920 HD Pro webcam
- Full-speed device - Logitech bluetooth mouse
- Britz BR-Orion speaker
- Low-speed device - Logitech wired mouse
- Test description
Moving and click test for mouse. To test the webcam, use gnome-cheese.
To test the speaker, play music and video on the client. All works
normally.
* VUDC compatibility test
VUDC also works well with this patch. Tests are done with two USB
gadget created by CONFIGFS USB gadget. Both use the BULK pipe.
1. Serial gadget
2. Mass storage gadget
- Serial gadget test
Serial gadget on the host sends and receives data using cat command
on the /dev/ttyGS<N>. The client uses minicom to communicate with
the serial gadget.
- Mass storage gadget test
After connecting the gadget with vhci, use "dd" to test read and
write operation on the client side.
Read - dd if=/dev/sd<N> iflag=direct of=/dev/null bs=1G count=1
Write - dd if=<my file path> iflag=direct of=/dev/sd<N> bs=1G count=1
Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
Acked-by: Shuah khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190828032741.12234-1-suwan.kim027@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-28 11:27:41 +08:00
|
|
|
|
|
|
|
error:
|
|
|
|
dev_err(&urb->dev->dev, "recv xbuf, %d\n", ret);
|
|
|
|
if (ud->side == USBIP_STUB || ud->side == USBIP_VUDC)
|
|
|
|
usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
|
|
|
|
else
|
|
|
|
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
|
|
|
|
|
|
|
|
return -EPIPE;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usbip_recv_xbuff);
|
|
|
|
|
2011-05-20 12:37:05 +08:00
|
|
|
static int __init usbip_core_init(void)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
2016-03-24 09:50:59 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = usbip_init_eh();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-20 12:37:05 +08:00
|
|
|
static void __exit usbip_core_exit(void)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
2016-03-24 09:50:59 +08:00
|
|
|
usbip_finish_eh();
|
2008-07-10 04:56:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-20 12:37:05 +08:00
|
|
|
module_init(usbip_core_init);
|
|
|
|
module_exit(usbip_core_exit);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|