2008-07-10 04:56:51 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2008 Takahiro Hirofuchi
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
2011-05-12 13:33:43 +08:00
|
|
|
#include <linux/device.h>
|
2012-10-22 03:45:00 +08:00
|
|
|
#include <linux/file.h>
|
2011-03-02 07:13:05 +08:00
|
|
|
#include <linux/kthread.h>
|
2011-07-04 03:49:50 +08:00
|
|
|
#include <linux/module.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
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
#include "usbip_common.h"
|
|
|
|
#include "stub.h"
|
|
|
|
|
|
|
|
/*
|
2011-05-20 12:37:03 +08:00
|
|
|
* usbip_status shows the status of usbip-host as long as this driver is bound
|
|
|
|
* to the target device.
|
2008-07-10 04:56:51 +08:00
|
|
|
*/
|
2013-08-27 03:02:54 +08:00
|
|
|
static ssize_t usbip_status_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
struct stub_device *sdev = dev_get_drvdata(dev);
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!sdev) {
|
|
|
|
dev_err(dev, "sdev is null\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_lock_irq(&sdev->ud.lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
status = sdev->ud.status;
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_unlock_irq(&sdev->ud.lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", status);
|
|
|
|
}
|
2013-08-27 03:02:54 +08:00
|
|
|
static DEVICE_ATTR_RO(usbip_status);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* usbip_sockfd gets a socket descriptor of an established TCP connection that
|
|
|
|
* is used to transfer usbip requests by kernel threads. -1 is a magic number
|
|
|
|
* by which usbip connection is finished.
|
|
|
|
*/
|
|
|
|
static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct stub_device *sdev = dev_get_drvdata(dev);
|
|
|
|
int sockfd = 0;
|
|
|
|
struct socket *socket;
|
2014-02-27 18:26:52 +08:00
|
|
|
int rv;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
if (!sdev) {
|
|
|
|
dev_err(dev, "sdev is null\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2014-02-27 18:26:52 +08:00
|
|
|
rv = sscanf(buf, "%d", &sockfd);
|
|
|
|
if (rv != 1)
|
|
|
|
return -EINVAL;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
if (sockfd != -1) {
|
2014-03-06 09:33:08 +08:00
|
|
|
int err;
|
2014-05-15 01:20:27 +08:00
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
dev_info(dev, "stub up\n");
|
|
|
|
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_lock_irq(&sdev->ud.lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
if (sdev->ud.status != SDEV_ST_AVAILABLE) {
|
|
|
|
dev_err(dev, "not ready\n");
|
2013-04-04 22:03:08 +08:00
|
|
|
goto err;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
2014-03-06 09:33:08 +08:00
|
|
|
socket = sockfd_lookup(sockfd, &err);
|
2013-04-04 22:03:08 +08:00
|
|
|
if (!socket)
|
|
|
|
goto err;
|
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
sdev->ud.tcp_socket = socket;
|
|
|
|
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_unlock_irq(&sdev->ud.lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2013-02-22 19:13:34 +08:00
|
|
|
sdev->ud.tcp_rx = kthread_get_run(stub_rx_loop, &sdev->ud,
|
|
|
|
"stub_rx");
|
|
|
|
sdev->ud.tcp_tx = kthread_get_run(stub_tx_loop, &sdev->ud,
|
|
|
|
"stub_tx");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_lock_irq(&sdev->ud.lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
sdev->ud.status = SDEV_ST_USED;
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_unlock_irq(&sdev->ud.lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
dev_info(dev, "stub down\n");
|
|
|
|
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_lock_irq(&sdev->ud.lock);
|
2013-04-04 22:03:08 +08:00
|
|
|
if (sdev->ud.status != SDEV_ST_USED)
|
|
|
|
goto err;
|
|
|
|
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_unlock_irq(&sdev->ud.lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
usbip_event_add(&sdev->ud, SDEV_EVENT_DOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
2013-04-04 22:03:08 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
spin_unlock_irq(&sdev->ud.lock);
|
2014-03-06 09:33:08 +08:00
|
|
|
return -EINVAL;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
static DEVICE_ATTR(usbip_sockfd, S_IWUSR, NULL, store_sockfd);
|
|
|
|
|
|
|
|
static int stub_add_files(struct device *dev)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
err = device_create_file(dev, &dev_attr_usbip_status);
|
|
|
|
if (err)
|
|
|
|
goto err_status;
|
|
|
|
|
|
|
|
err = device_create_file(dev, &dev_attr_usbip_sockfd);
|
|
|
|
if (err)
|
|
|
|
goto err_sockfd;
|
|
|
|
|
|
|
|
err = device_create_file(dev, &dev_attr_usbip_debug);
|
|
|
|
if (err)
|
|
|
|
goto err_debug;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_debug:
|
|
|
|
device_remove_file(dev, &dev_attr_usbip_sockfd);
|
|
|
|
err_sockfd:
|
|
|
|
device_remove_file(dev, &dev_attr_usbip_status);
|
|
|
|
err_status:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stub_remove_files(struct device *dev)
|
|
|
|
{
|
|
|
|
device_remove_file(dev, &dev_attr_usbip_status);
|
|
|
|
device_remove_file(dev, &dev_attr_usbip_sockfd);
|
|
|
|
device_remove_file(dev, &dev_attr_usbip_debug);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stub_shutdown_connection(struct usbip_device *ud)
|
|
|
|
{
|
|
|
|
struct stub_device *sdev = container_of(ud, struct stub_device, ud);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When removing an exported device, kernel panic sometimes occurred
|
|
|
|
* and then EIP was sk_wait_data of stub_rx thread. Is this because
|
|
|
|
* sk_wait_data returned though stub_rx thread was already finished by
|
|
|
|
* step 1?
|
|
|
|
*/
|
|
|
|
if (ud->tcp_socket) {
|
2011-05-20 07:47:32 +08:00
|
|
|
dev_dbg(&sdev->udev->dev, "shutdown tcp_socket %p\n",
|
|
|
|
ud->tcp_socket);
|
2008-07-10 04:56:51 +08:00
|
|
|
kernel_sock_shutdown(ud->tcp_socket, SHUT_RDWR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 1. stop threads */
|
2012-09-19 19:37:27 +08:00
|
|
|
if (ud->tcp_rx) {
|
2012-03-14 02:07:18 +08:00
|
|
|
kthread_stop_put(ud->tcp_rx);
|
2012-09-19 19:37:27 +08:00
|
|
|
ud->tcp_rx = NULL;
|
|
|
|
}
|
|
|
|
if (ud->tcp_tx) {
|
2012-03-14 02:07:18 +08:00
|
|
|
kthread_stop_put(ud->tcp_tx);
|
2012-09-19 19:37:27 +08:00
|
|
|
ud->tcp_tx = NULL;
|
|
|
|
}
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/*
|
2011-05-20 12:36:56 +08:00
|
|
|
* 2. close the socket
|
|
|
|
*
|
|
|
|
* tcp_socket is freed after threads are killed so that usbip_xmit does
|
|
|
|
* not touch NULL socket.
|
2008-07-10 04:56:51 +08:00
|
|
|
*/
|
|
|
|
if (ud->tcp_socket) {
|
2014-03-06 09:33:08 +08:00
|
|
|
sockfd_put(ud->tcp_socket);
|
2008-07-10 04:56:51 +08:00
|
|
|
ud->tcp_socket = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 3. free used data */
|
|
|
|
stub_device_cleanup_urbs(sdev);
|
|
|
|
|
|
|
|
/* 4. free stub_unlink */
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct stub_unlink *unlink, *tmp;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sdev->priv_lock, flags);
|
|
|
|
list_for_each_entry_safe(unlink, tmp, &sdev->unlink_tx, list) {
|
|
|
|
list_del(&unlink->list);
|
|
|
|
kfree(unlink);
|
|
|
|
}
|
2011-05-20 12:36:56 +08:00
|
|
|
list_for_each_entry_safe(unlink, tmp, &sdev->unlink_free,
|
|
|
|
list) {
|
2008-07-10 04:56:51 +08:00
|
|
|
list_del(&unlink->list);
|
|
|
|
kfree(unlink);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&sdev->priv_lock, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stub_device_reset(struct usbip_device *ud)
|
|
|
|
{
|
|
|
|
struct stub_device *sdev = container_of(ud, struct stub_device, ud);
|
2011-01-12 21:01:59 +08:00
|
|
|
struct usb_device *udev = sdev->udev;
|
2008-07-10 04:56:51 +08:00
|
|
|
int ret;
|
|
|
|
|
2011-05-20 07:47:32 +08:00
|
|
|
dev_dbg(&udev->dev, "device reset");
|
2011-01-12 21:01:59 +08:00
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
ret = usb_lock_device_for_reset(udev, sdev->interface);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&udev->dev, "lock for reset\n");
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_lock_irq(&ud->lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
ud->status = SDEV_ST_ERROR;
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_unlock_irq(&ud->lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to reset the device */
|
|
|
|
ret = usb_reset_device(udev);
|
|
|
|
usb_unlock_device(udev);
|
|
|
|
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_lock_irq(&ud->lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&udev->dev, "device reset\n");
|
|
|
|
ud->status = SDEV_ST_ERROR;
|
|
|
|
} else {
|
|
|
|
dev_info(&udev->dev, "device reset\n");
|
|
|
|
ud->status = SDEV_ST_AVAILABLE;
|
|
|
|
}
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_unlock_irq(&ud->lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void stub_device_unusable(struct usbip_device *ud)
|
|
|
|
{
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_lock_irq(&ud->lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
ud->status = SDEV_ST_ERROR;
|
2013-01-22 13:31:30 +08:00
|
|
|
spin_unlock_irq(&ud->lock);
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stub_device_alloc - allocate a new stub_device struct
|
|
|
|
* @interface: usb_interface of a new device
|
|
|
|
*
|
|
|
|
* Allocates and initializes a new stub_device struct.
|
|
|
|
*/
|
2014-01-24 05:12:29 +08:00
|
|
|
static struct stub_device *stub_device_alloc(struct usb_device *udev)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
struct stub_device *sdev;
|
2014-01-24 05:12:29 +08:00
|
|
|
int busnum = udev->bus->busnum;
|
|
|
|
int devnum = udev->devnum;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_dbg(&udev->dev, "allocating stub device");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/* yes, it's a new device */
|
|
|
|
sdev = kzalloc(sizeof(struct stub_device), GFP_KERNEL);
|
2013-02-12 01:41:29 +08:00
|
|
|
if (!sdev)
|
2008-07-10 04:56:51 +08:00
|
|
|
return NULL;
|
|
|
|
|
2011-01-12 21:01:59 +08:00
|
|
|
sdev->udev = usb_get_dev(udev);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* devid is defined with devnum when this driver is first allocated.
|
|
|
|
* devnum may change later if a device is reset. However, devid never
|
|
|
|
* changes during a usbip connection.
|
|
|
|
*/
|
2011-05-06 18:47:41 +08:00
|
|
|
sdev->devid = (busnum << 16) | devnum;
|
|
|
|
sdev->ud.side = USBIP_STUB;
|
|
|
|
sdev->ud.status = SDEV_ST_AVAILABLE;
|
2008-07-10 04:56:51 +08:00
|
|
|
spin_lock_init(&sdev->ud.lock);
|
2011-05-06 18:47:41 +08:00
|
|
|
sdev->ud.tcp_socket = NULL;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&sdev->priv_init);
|
|
|
|
INIT_LIST_HEAD(&sdev->priv_tx);
|
|
|
|
INIT_LIST_HEAD(&sdev->priv_free);
|
|
|
|
INIT_LIST_HEAD(&sdev->unlink_free);
|
|
|
|
INIT_LIST_HEAD(&sdev->unlink_tx);
|
|
|
|
spin_lock_init(&sdev->priv_lock);
|
|
|
|
|
|
|
|
init_waitqueue_head(&sdev->tx_waitq);
|
|
|
|
|
|
|
|
sdev->ud.eh_ops.shutdown = stub_shutdown_connection;
|
|
|
|
sdev->ud.eh_ops.reset = stub_device_reset;
|
|
|
|
sdev->ud.eh_ops.unusable = stub_device_unusable;
|
|
|
|
|
|
|
|
usbip_start_eh(&sdev->ud);
|
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_dbg(&udev->dev, "register new device\n");
|
2011-05-20 07:47:32 +08:00
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
return sdev;
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:03:11 +08:00
|
|
|
static void stub_device_free(struct stub_device *sdev)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
kfree(sdev);
|
|
|
|
}
|
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
static int stub_probe(struct usb_device *udev)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
|
|
|
struct stub_device *sdev = NULL;
|
2014-01-24 05:12:29 +08:00
|
|
|
const char *udev_busid = dev_name(&udev->dev);
|
2010-07-27 18:39:30 +08:00
|
|
|
struct bus_id_priv *busid_priv;
|
2014-03-08 20:53:34 +08:00
|
|
|
int rc;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_dbg(&udev->dev, "Enter\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/* check we should claim or not by busid_table */
|
2010-07-27 18:39:30 +08:00
|
|
|
busid_priv = get_busid_priv(udev_busid);
|
2011-05-20 12:36:56 +08:00
|
|
|
if (!busid_priv || (busid_priv->status == STUB_BUSID_REMOV) ||
|
2011-05-06 18:47:41 +08:00
|
|
|
(busid_priv->status == STUB_BUSID_OTHER)) {
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_info(&udev->dev,
|
2013-09-05 17:07:10 +08:00
|
|
|
"%s is not in match_busid table... skip!\n",
|
|
|
|
udev_busid);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return value should be ENODEV or ENOXIO to continue trying
|
|
|
|
* other matched drivers by the driver core.
|
|
|
|
* See driver_probe_device() in driver/base/dd.c
|
|
|
|
*/
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2011-05-20 07:47:32 +08:00
|
|
|
if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) {
|
|
|
|
dev_dbg(&udev->dev, "%s is a usb hub device... skip!\n",
|
|
|
|
udev_busid);
|
2008-07-10 04:56:51 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(udev->bus->bus_name, "vhci_hcd")) {
|
2013-09-05 17:07:10 +08:00
|
|
|
dev_dbg(&udev->dev,
|
|
|
|
"%s is attached on vhci_hcd... skip!\n",
|
|
|
|
udev_busid);
|
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2011-05-20 12:37:03 +08:00
|
|
|
/* ok, this is my device */
|
2014-01-24 05:12:29 +08:00
|
|
|
sdev = stub_device_alloc(udev);
|
2008-07-10 04:56:51 +08:00
|
|
|
if (!sdev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_info(&udev->dev,
|
|
|
|
"usbip-host: register new device (bus %u dev %u)\n",
|
|
|
|
udev->bus->busnum, udev->devnum);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2010-07-27 18:39:30 +08:00
|
|
|
busid_priv->shutdown_busid = 0;
|
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
/* set private data to usb_device */
|
|
|
|
dev_set_drvdata(&udev->dev, sdev);
|
2010-07-27 18:39:30 +08:00
|
|
|
busid_priv->sdev = sdev;
|
2014-03-08 20:53:33 +08:00
|
|
|
busid_priv->udev = udev;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2014-03-08 20:53:34 +08:00
|
|
|
/*
|
|
|
|
* Claim this hub port.
|
|
|
|
* It doesn't matter what value we pass as owner
|
|
|
|
* (struct dev_state) as long as it is unique.
|
|
|
|
*/
|
|
|
|
rc = usb_hub_claim_port(udev->parent, udev->portnum,
|
2014-03-10 16:36:40 +08:00
|
|
|
(struct usb_dev_state *) udev);
|
2014-03-08 20:53:34 +08:00
|
|
|
if (rc) {
|
|
|
|
dev_dbg(&udev->dev, "unable to claim port\n");
|
2014-11-29 06:29:10 +08:00
|
|
|
goto err_port;
|
2014-03-08 20:53:34 +08:00
|
|
|
}
|
|
|
|
|
2014-11-29 06:29:10 +08:00
|
|
|
rc = stub_add_files(&udev->dev);
|
|
|
|
if (rc) {
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_err(&udev->dev, "stub_add_files for %s\n", udev_busid);
|
2014-11-29 06:29:10 +08:00
|
|
|
goto err_files;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
2010-07-27 18:39:30 +08:00
|
|
|
busid_priv->status = STUB_BUSID_ALLOC;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
return 0;
|
2014-11-29 06:29:10 +08:00
|
|
|
err_files:
|
|
|
|
usb_hub_release_port(udev->parent, udev->portnum,
|
|
|
|
(struct usb_dev_state *) udev);
|
|
|
|
err_port:
|
|
|
|
dev_set_drvdata(&udev->dev, NULL);
|
|
|
|
usb_put_dev(udev);
|
|
|
|
|
|
|
|
busid_priv->sdev = NULL;
|
|
|
|
stub_device_free(sdev);
|
|
|
|
return rc;
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
|
|
|
|
2010-07-27 18:39:30 +08:00
|
|
|
static void shutdown_busid(struct bus_id_priv *busid_priv)
|
|
|
|
{
|
|
|
|
if (busid_priv->sdev && !busid_priv->shutdown_busid) {
|
|
|
|
busid_priv->shutdown_busid = 1;
|
|
|
|
usbip_event_add(&busid_priv->sdev->ud, SDEV_EVENT_REMOVED);
|
|
|
|
|
2013-04-04 22:03:05 +08:00
|
|
|
/* wait for the stop of the event handler */
|
2010-07-27 18:39:30 +08:00
|
|
|
usbip_stop_eh(&busid_priv->sdev->ud);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
/*
|
|
|
|
* called in usb_disconnect() or usb_deregister()
|
|
|
|
* but only if actconfig(active configuration) exists
|
|
|
|
*/
|
2014-01-24 05:12:29 +08:00
|
|
|
static void stub_disconnect(struct usb_device *udev)
|
2008-07-10 04:56:51 +08:00
|
|
|
{
|
2010-07-27 18:39:30 +08:00
|
|
|
struct stub_device *sdev;
|
2014-01-24 05:12:29 +08:00
|
|
|
const char *udev_busid = dev_name(&udev->dev);
|
2010-07-27 18:39:30 +08:00
|
|
|
struct bus_id_priv *busid_priv;
|
2014-03-08 20:53:34 +08:00
|
|
|
int rc;
|
2010-07-27 18:39:30 +08:00
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_dbg(&udev->dev, "Enter\n");
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2011-05-20 07:47:32 +08:00
|
|
|
busid_priv = get_busid_priv(udev_busid);
|
2010-07-27 18:39:30 +08:00
|
|
|
if (!busid_priv) {
|
|
|
|
BUG();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
sdev = dev_get_drvdata(&udev->dev);
|
2010-07-27 18:39:30 +08:00
|
|
|
|
2008-07-10 04:56:51 +08:00
|
|
|
/* get stub_device */
|
|
|
|
if (!sdev) {
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_err(&udev->dev, "could not get device");
|
2008-07-10 04:56:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_set_drvdata(&udev->dev, NULL);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
|
|
|
/*
|
2012-10-11 01:34:27 +08:00
|
|
|
* NOTE: rx/tx threads are invoked for each usb_device.
|
2008-07-10 04:56:51 +08:00
|
|
|
*/
|
2014-01-24 05:12:29 +08:00
|
|
|
stub_remove_files(&udev->dev);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2014-03-08 20:53:34 +08:00
|
|
|
/* release port */
|
|
|
|
rc = usb_hub_release_port(udev->parent, udev->portnum,
|
2014-03-10 16:36:40 +08:00
|
|
|
(struct usb_dev_state *) udev);
|
2014-03-08 20:53:34 +08:00
|
|
|
if (rc) {
|
|
|
|
dev_dbg(&udev->dev, "unable to release port\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-11 01:34:27 +08:00
|
|
|
/* If usb reset is called from event handler */
|
2016-03-24 09:50:59 +08:00
|
|
|
if (usbip_in_eh(current))
|
2010-07-27 18:39:30 +08:00
|
|
|
return;
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2012-10-11 01:34:27 +08:00
|
|
|
/* shutdown the current connection */
|
2010-07-27 18:39:30 +08:00
|
|
|
shutdown_busid(busid_priv);
|
2008-07-10 04:56:51 +08:00
|
|
|
|
2011-01-12 21:01:59 +08:00
|
|
|
usb_put_dev(sdev->udev);
|
|
|
|
|
2012-10-11 01:34:27 +08:00
|
|
|
/* free sdev */
|
2010-07-27 18:39:30 +08:00
|
|
|
busid_priv->sdev = NULL;
|
2008-07-10 04:56:51 +08:00
|
|
|
stub_device_free(sdev);
|
|
|
|
|
2010-07-27 18:39:30 +08:00
|
|
|
if (busid_priv->status == STUB_BUSID_ALLOC) {
|
|
|
|
busid_priv->status = STUB_BUSID_ADDED;
|
|
|
|
} else {
|
|
|
|
busid_priv->status = STUB_BUSID_OTHER;
|
|
|
|
del_match_busid((char *)udev_busid);
|
|
|
|
}
|
2008-07-10 04:56:51 +08:00
|
|
|
}
|
2011-05-20 12:37:03 +08:00
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
#ifdef CONFIG_PM
|
2011-08-18 03:58:31 +08:00
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
/* These functions need usb_port_suspend and usb_port_resume,
|
|
|
|
* which reside in drivers/usb/core/usb.h. Skip for now. */
|
|
|
|
|
|
|
|
static int stub_suspend(struct usb_device *udev, pm_message_t message)
|
2011-07-01 04:18:18 +08:00
|
|
|
{
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_dbg(&udev->dev, "stub_suspend\n");
|
|
|
|
|
2011-07-01 04:18:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
static int stub_resume(struct usb_device *udev, pm_message_t message)
|
2011-07-01 04:18:18 +08:00
|
|
|
{
|
2014-01-24 05:12:29 +08:00
|
|
|
dev_dbg(&udev->dev, "stub_resume\n");
|
|
|
|
|
2011-07-01 04:18:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-24 05:12:29 +08:00
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
|
|
|
struct usb_device_driver stub_driver = {
|
2011-05-20 12:37:03 +08:00
|
|
|
.name = "usbip-host",
|
|
|
|
.probe = stub_probe,
|
|
|
|
.disconnect = stub_disconnect,
|
2014-01-24 05:12:29 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = stub_suspend,
|
|
|
|
.resume = stub_resume,
|
|
|
|
#endif
|
|
|
|
.supports_autosuspend = 0,
|
2011-08-18 03:58:32 +08:00
|
|
|
};
|