diff options
Diffstat (limited to 'drivers/staging/usbip/stub_dev.c')
-rw-r--r-- | drivers/staging/usbip/stub_dev.c | 97 |
1 files changed, 30 insertions, 67 deletions
diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c index bce7d039346c..6e99ec87fee0 100644 --- a/drivers/staging/usbip/stub_dev.c +++ b/drivers/staging/usbip/stub_dev.c @@ -17,19 +17,16 @@ * USA. */ -#include <linux/slab.h> +#include <linux/device.h> #include <linux/kthread.h> #include "usbip_common.h" #include "stub.h" - - static int stub_probe(struct usb_interface *interface, - const struct usb_device_id *id); + const struct usb_device_id *id); static void stub_disconnect(struct usb_interface *interface); - /* * Define device IDs here if you want to explicitly limit exportable devices. * In the most cases, wild card matching will be ok because driver binding can @@ -64,12 +61,6 @@ struct usb_driver stub_driver = { .id_table = stub_table, }; - -/*-------------------------------------------------------------------------*/ - -/* Define sysfs entries for a usbip-bound device */ - - /* * usbip_status shows status of usbip as long as this driver is bound to the * target device. @@ -128,13 +119,11 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr, spin_unlock(&sdev->ud.lock); return -EINVAL; } - #if 0 setnodelay(socket); setkeepalive(socket); setreuse(socket); #endif - sdev->ud.tcp_socket = socket; spin_unlock(&sdev->ud.lock); @@ -183,10 +172,8 @@ static int stub_add_files(struct device *dev) err_debug: device_remove_file(dev, &dev_attr_usbip_sockfd); - err_sockfd: device_remove_file(dev, &dev_attr_usbip_status); - err_status: return err; } @@ -198,12 +185,6 @@ static void stub_remove_files(struct device *dev) device_remove_file(dev, &dev_attr_usbip_debug); } - - -/*-------------------------------------------------------------------------*/ - -/* Event handler functions called by an event handler thread */ - static void stub_shutdown_connection(struct usbip_device *ud) { struct stub_device *sdev = container_of(ud, struct stub_device, ud); @@ -215,7 +196,8 @@ static void stub_shutdown_connection(struct usbip_device *ud) * step 1? */ if (ud->tcp_socket) { - usbip_udbg("shutdown tcp_socket %p\n", ud->tcp_socket); + dev_dbg(&sdev->udev->dev, "shutdown tcp_socket %p\n", + ud->tcp_socket); kernel_sock_shutdown(ud->tcp_socket, SHUT_RDWR); } @@ -244,18 +226,15 @@ static void stub_shutdown_connection(struct usbip_device *ud) 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); } - list_for_each_entry_safe(unlink, tmp, &sdev->unlink_free, list) { list_del(&unlink->list); kfree(unlink); } - spin_unlock_irqrestore(&sdev->priv_lock, flags); } } @@ -266,16 +245,14 @@ static void stub_device_reset(struct usbip_device *ud) struct usb_device *udev = sdev->udev; int ret; - usbip_udbg("device reset"); + dev_dbg(&udev->dev, "device reset"); ret = usb_lock_device_for_reset(udev, sdev->interface); if (ret < 0) { dev_err(&udev->dev, "lock for reset\n"); - spin_lock(&ud->lock); ud->status = SDEV_ST_ERROR; spin_unlock(&ud->lock); - return; } @@ -306,9 +283,6 @@ static void stub_device_unusable(struct usbip_device *ud) spin_unlock(&ud->lock); } - -/*-------------------------------------------------------------------------*/ - /** * stub_device_alloc - allocate a new stub_device struct * @interface: usb_interface of a new device @@ -339,13 +313,12 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev, * devnum may change later if a device is reset. However, devid never * changes during a usbip connection. */ - sdev->devid = (busnum << 16) | devnum; - - sdev->ud.side = USBIP_STUB; - sdev->ud.status = SDEV_ST_AVAILABLE; + sdev->devid = (busnum << 16) | devnum; + sdev->ud.side = USBIP_STUB; + sdev->ud.status = SDEV_ST_AVAILABLE; /* sdev->ud.lock = SPIN_LOCK_UNLOCKED; */ spin_lock_init(&sdev->ud.lock); - sdev->ud.tcp_socket = NULL; + sdev->ud.tcp_socket = NULL; INIT_LIST_HEAD(&sdev->priv_init); INIT_LIST_HEAD(&sdev->priv_tx); @@ -363,7 +336,8 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev, usbip_start_eh(&sdev->ud); - usbip_udbg("register new interface\n"); + dev_dbg(&interface->dev, "register new interface\n"); + return sdev; } @@ -373,14 +347,11 @@ static int stub_device_free(struct stub_device *sdev) return -EINVAL; kfree(sdev); - usbip_udbg("kfree udev ok\n"); + pr_debug("kfree udev ok\n"); return 0; } - -/*-------------------------------------------------------------------------*/ - /* * If a usb device has multiple active interfaces, this driver is bound to all * the active interfaces. However, usbip exports *a* usb device (i.e., not *an* @@ -405,10 +376,9 @@ static int stub_probe(struct usb_interface *interface, /* check we should claim or not by busid_table */ busid_priv = get_busid_priv(udev_busid); if (!busid_priv || (busid_priv->status == STUB_BUSID_REMOV) || - (busid_priv->status == STUB_BUSID_OTHER)) { - dev_info(&interface->dev, - "this device %s is not in match_busid table. skip!\n", - udev_busid); + (busid_priv->status == STUB_BUSID_OTHER)) { + dev_info(&interface->dev, "%s is not in match_busid table... " + "skip!\n", udev_busid); /* * Return value should be ENODEV or ENOXIO to continue trying @@ -418,36 +388,35 @@ static int stub_probe(struct usb_interface *interface, return -ENODEV; } - if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) { - usbip_udbg("this device %s is a usb hub device. skip!\n", - udev_busid); + if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) { + dev_dbg(&udev->dev, "%s is a usb hub device... skip!\n", + udev_busid); return -ENODEV; } if (!strcmp(udev->bus->bus_name, "vhci_hcd")) { - usbip_udbg("this device %s is attached on vhci_hcd. skip!\n", - udev_busid); + dev_dbg(&udev->dev, "%s is attached on vhci_hcd... skip!\n", + udev_busid); return -ENODEV; } - if (busid_priv->status == STUB_BUSID_ALLOC) { sdev = busid_priv->sdev; if (!sdev) return -ENODEV; busid_priv->interf_count++; - dev_info(&interface->dev, - "USB/IP Stub: register a new interface " - "(bus %u dev %u ifn %u)\n", udev->bus->busnum, udev->devnum, - interface->cur_altsetting->desc.bInterfaceNumber); + dev_info(&interface->dev, "usbip-host: register new interface " + "(bus %u dev %u ifn %u)\n", + udev->bus->busnum, udev->devnum, + interface->cur_altsetting->desc.bInterfaceNumber); /* set private data to usb_interface */ usb_set_intfdata(interface, sdev); err = stub_add_files(&interface->dev); if (err) { - dev_err(&interface->dev, "create sysfs files for %s\n", + dev_err(&interface->dev, "stub_add_files for %s\n", udev_busid); usb_set_intfdata(interface, NULL); busid_priv->interf_count--; @@ -464,7 +433,7 @@ static int stub_probe(struct usb_interface *interface, if (!sdev) return -ENOMEM; - dev_info(&interface->dev, "USB/IP Stub: register a new device " + dev_info(&interface->dev, "usbip-host: register new device " "(bus %u dev %u ifn %u)\n", udev->bus->busnum, udev->devnum, interface->cur_altsetting->desc.bInterfaceNumber); @@ -479,8 +448,7 @@ static int stub_probe(struct usb_interface *interface, err = stub_add_files(&interface->dev); if (err) { - dev_err(&interface->dev, "create sysfs files for %s\n", - udev_busid); + dev_err(&interface->dev, "stub_add_files for %s\n", udev_busid); usb_set_intfdata(interface, NULL); usb_put_intf(interface); @@ -504,10 +472,8 @@ static void shutdown_busid(struct bus_id_priv *busid_priv) /* 2. wait for the stop of the event handler */ usbip_stop_eh(&busid_priv->sdev->ud); } - } - /* * called in usb_disconnect() or usb_deregister() * but only if actconfig(active configuration) exists @@ -518,10 +484,9 @@ static void stub_disconnect(struct usb_interface *interface) const char *udev_busid = dev_name(interface->dev.parent); struct bus_id_priv *busid_priv; - busid_priv = get_busid_priv(udev_busid); - - usbip_udbg("Enter\n"); + dev_dbg(&interface->dev, "Enter\n"); + busid_priv = get_busid_priv(udev_busid); if (!busid_priv) { BUG(); return; @@ -531,7 +496,7 @@ static void stub_disconnect(struct usb_interface *interface) /* get stub_device */ if (!sdev) { - err(" could not get device from inteface data"); + dev_err(&interface->dev, "could not get device"); /* BUG(); */ return; } @@ -559,7 +524,6 @@ static void stub_disconnect(struct usb_interface *interface) busid_priv->interf_count = 0; - /* 1. shutdown the current connection */ shutdown_busid(busid_priv); @@ -576,5 +540,4 @@ static void stub_disconnect(struct usb_interface *interface) busid_priv->status = STUB_BUSID_OTHER; del_match_busid((char *)udev_busid); } - usbip_udbg("bye\n"); } |