Re: [PATCH] usb: phy: mxs: Remove unused flags
On Mon, Dec 28, 2015 at 11:03:03PM -0200, Fabio Estevam wrote: > From: Fabio Estevam > > MXS_PHY_ABNORMAL_IN_SUSPEND and MXS_PHY_SENDING_SOF_TOO_FAST flags > are never used, so let's get rid of them. > > Reported-by: Stefan Wahren > Signed-off-by: Fabio Estevam > --- > drivers/usb/phy/phy-mxs-usb.c | 31 +++ > 1 file changed, 3 insertions(+), 28 deletions(-) > > diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c > index c2936dc..cbcc899 100644 > --- a/drivers/usb/phy/phy-mxs-usb.c > +++ b/drivers/usb/phy/phy-mxs-usb.c > @@ -93,39 +93,14 @@ > > /* Do disconnection between PHY and controller without vbus */ > #define MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS BIT(0) > - > -/* > - * The PHY will be in messy if there is a wakeup after putting > - * bus to suspend (set portsc.suspendM) but before setting PHY to low > - * power mode (set portsc.phcd). > - */ > -#define MXS_PHY_ABNORMAL_IN_SUSPEND BIT(1) > - > -/* > - * The SOF sends too fast after resuming, it will cause disconnection > - * between host and high speed device. > - */ > -#define MXS_PHY_SENDING_SOF_TOO_FAST BIT(2) > - > -/* > - * IC has bug fixes logic, they include > - * MXS_PHY_ABNORMAL_IN_SUSPEND and MXS_PHY_SENDING_SOF_TOO_FAST > - * which are described at above flags, the RTL will handle it > - * according to different versions. > - */ > -#define MXS_PHY_NEED_IP_FIX BIT(3) > +#define MXS_PHY_NEED_IP_FIX BIT(1) > > struct mxs_phy_data { > unsigned int flags; > }; > > -static const struct mxs_phy_data imx23_phy_data = { > - .flags = MXS_PHY_ABNORMAL_IN_SUSPEND | MXS_PHY_SENDING_SOF_TOO_FAST, > -}; > - > static const struct mxs_phy_data imx6q_phy_data = { > - .flags = MXS_PHY_SENDING_SOF_TOO_FAST | > - MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | > + .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | > MXS_PHY_NEED_IP_FIX, > }; > > @@ -151,7 +126,7 @@ static const struct of_device_id mxs_phy_dt_ids[] = { > { .compatible = "fsl,imx6sx-usbphy", .data = &imx6sx_phy_data, }, > { .compatible = "fsl,imx6sl-usbphy", .data = &imx6sl_phy_data, }, > { .compatible = "fsl,imx6q-usbphy", .data = &imx6q_phy_data, }, > - { .compatible = "fsl,imx23-usbphy", .data = &imx23_phy_data, }, > + { .compatible = "fsl,imx23-usbphy", .data = NULL, }, > { .compatible = "fsl,vf610-usbphy", .data = &vf610_phy_data, }, > { .compatible = "fsl,imx6ul-usbphy", .data = &imx6ul_phy_data, }, > { /* sentinel */ } > -- I prefer to keep it, and it let us know the existing issues although we have not implemented workaround for them. In future, we may have solutions for how to implement them. -- Best Regards, Peter Chen -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] ehci-hcd: Disable memory-write-invalidate when the driver is removed
The driver calls pci_set_mwi to enable memory-write-invalidate when it is initialized, but does not call pci_clear_mwi when it is removed. Many other drivers calls pci_clear_mwi when pci_set_mwi is called, such as r8169, 8139cp and e1000. This patch adds a function "ehci_pci_remove" to remove the pci driver. This function calls pci_clear_mwi and usb_hcd_pci_remove, which can fix the problem. Signed-off-by: Jia-Ju Bai --- drivers/usb/host/ehci-pci.c |8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index 2a5d2fd..3b3649d 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c @@ -377,6 +377,12 @@ static int ehci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) return usb_hcd_pci_probe(pdev, id); } +static void ehci_pci_remove(struct pci_dev *pdev) +{ + pci_clear_mwi(pdev); + usb_hcd_pci_remove(pdev); +} + /* PCI driver selection metadata; PCI hotplugging uses this */ static const struct pci_device_id pci_ids [] = { { /* handle any USB 2.0 EHCI controller */ @@ -396,7 +402,7 @@ static struct pci_driver ehci_pci_driver = { .id_table = pci_ids, .probe =ehci_pci_probe, - .remove = usb_hcd_pci_remove, + .remove = ehci_pci_remove, .shutdown = usb_hcd_pci_shutdown, #ifdef CONFIG_PM -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] ehci-hcd: Cleanup memory resources when ehci_halt fails
On 12/29/2015 12:04 AM, Alan Stern wrote: On Mon, 28 Dec 2015, Jia-Ju Bai wrote: Please add a changelog. Signed-off-by: Jia-Ju Bai --- drivers/usb/host/ehci-hcd.c |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 48c92bf..015b411 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -675,8 +675,10 @@ int ehci_setup(struct usb_hcd *hcd) return retval; retval = ehci_halt(ehci); - if (retval) + if (retval) { + ehci_mem_cleanup(ehci); return retval; + } I would prefer to see the call to ehci_mem_init() moved into ehci_setup() as well, so that we don't do mem_init in one routine and mem_cleanup in another. Alan Stern Thanks ^_^ I will add the changelog. I find that it is a little hard to move ehci_mem_init into ehci_setup. In the code, ehci_mem_init needs data (ehci->periodic_size) in ehci_init to allocate memory, and some data (ehci->async->hw) in ehci_init needs the memory allocated by ehci_mem_init. Thus, moving ehci_mem_init out of ehci_init needs much modification. I think the easiest way is to call echi_mem_cleanup here (in ehci_setup). -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] ehci-hcd: Cleanup memory resources when ehci_halt fails
The driver calls ehci_mem_init to allocate memory resources. But these resources are not freed when ehci_halt fails. This patch adds "ehci_mem_cleanup" in error handling code to fix this problem. Signed-off-by: Jia-Ju Bai --- drivers/usb/host/ehci-hcd.c |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 48c92bf..015b411 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -675,8 +675,10 @@ int ehci_setup(struct usb_hcd *hcd) return retval; retval = ehci_halt(ehci); - if (retval) + if (retval) { + ehci_mem_cleanup(ehci); return retval; + } ehci_reset(ehci); -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] usb: phy: mxs: Remove unused flags
> Peter Chen hat am 29. Dezember 2015 um 09:15 > geschrieben: > > > On Mon, Dec 28, 2015 at 11:03:03PM -0200, Fabio Estevam wrote: > > From: Fabio Estevam > > > > MXS_PHY_ABNORMAL_IN_SUSPEND and MXS_PHY_SENDING_SOF_TOO_FAST flags > > are never used, so let's get rid of them. > > > > Reported-by: Stefan Wahren > > Signed-off-by: Fabio Estevam > > --- > ... > > I prefer to keep it, and it let us know the existing issues although > we have not implemented workaround for them. In future, we may have > solutions for how to implement them. I agree. It would be nice to have some chip errata references instead. But i'm afraid they aren't documented. > > -- > > Best Regards, > Peter Chen -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] usb: phy: mxs: Remove unused flags
On Tue, Dec 29, 2015 at 6:15 AM, Peter Chen wrote: > I prefer to keep it, and it let us know the existing issues although > we have not implemented workaround for them. In future, we may have > solutions for how to implement them. Ok, what about adding the recommendation below? --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c @@ -98,6 +98,9 @@ * The PHY will be in messy if there is a wakeup after putting * bus to suspend (set portsc.suspendM) but before setting PHY to low * power mode (set portsc.phcd). + * + * To work around this problem on mx23/mx28 user should pass + * 'usbcore.autosuspend=-1' in the kernel command line for now. */ #define MXS_PHY_ABNORMAL_IN_SUSPENDBIT(1) -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: MX28 with hub cannot reset
Hi Fabio, > Fabio Estevam hat am 22. Dezember 2015 um 23:54 > geschrieben: > > > Hi, > > On a mx28 custom board with a USB hub I can get a USB stick to get > detected after applying this change: > http://marc.info/?l=linux-usb&m=145079935324339&w=2 > > Things work fine if I boot without the USB stick connected. Then I can > insert/remove the USB device and it always gets detected. > > However, if I boot with the USB stick connected I get: > > [ 2.968513] hub 1-1:1.0: USB hub found > [ 2.973096] hub 1-1:1.0: 2 ports detected > [ 3.479731] usb 1-1: USB disconnect, device number 2 > [ 3.525403] usb usb1-port1: cannot reset (err = -32) > [ 3.530828] usb usb1-port1: cannot reset (err = -32) > [ 3.536089] usb usb1-port1: cannot reset (err = -32) > [ 3.541600] usb usb1-port1: cannot reset (err = -32) > [ 3.546857] usb usb1-port1: cannot reset (err = -32) > [ 3.551982] usb usb1-port1: Cannot enable. Maybe the USB cable is bad? > [ 3.560302] usb usb1-port1: cannot reset (err = -32) > [ 3.565566] usb usb1-port1: cannot reset (err = -32) > [ 3.571011] usb usb1-port1: cannot reset (err = -32) > [ 3.576266] usb usb1-port1: cannot reset (err = -32) > [ 3.581769] usb usb1-port1: cannot reset (err = -32) > [ 3.586780] usb usb1-port1: Cannot enable. Maybe the USB cable is bad? > [ 3.594138] usb usb1-port1: cannot reset (err = -32) > [ 3.599615] usb usb1-port1: cannot reset (err = -32) > [ 3.604871] usb usb1-port1: cannot reset (err = -32) > [ 3.610244] usb usb1-port1: cannot reset (err = -32) > [ 3.615499] usb usb1-port1: cannot reset (err = -32) > [ 3.620649] usb usb1-port1: Cannot enable. Maybe the USB cable is bad? > [ 3.627989] usb usb1-port1: cannot reset (err = -32) > [ 3.633370] usb usb1-port1: cannot reset (err = -32) > [ 3.638617] usb usb1-port1: cannot reset (err = -32) > [ 3.644171] usb usb1-port1: cannot reset (err = -32) > [ 3.649546] usb usb1-port1: cannot reset (err = -32) > [ 3.654557] usb usb1-port1: Cannot enable. Maybe the USB cable is bad? > [ 3.661650] usb usb1-port1: unable to enumerate USB device > > And the only way to get the USB port working again is to remove the > USB stick and reboot the board. > i did some tests with a IMX233-Olinuxino Maxi and external 4 port usb hub, but i can't reproduce the problem. Could you provide more information about the hub? I think we don't know that the issue comes really from the mx28 instead of the hub. Best regards Stefan -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6] USB: serial: add Moxa UPORT 11x0 driver
On Mon, Dec 28, 2015 at 09:21:25PM +0100, Mathieu OTHACEHE wrote: > Add a driver which supports : > > - UPort 1110 : 1 port RS-232 USB to Serial Hub. > - UPort 1130 : 1 port RS-422/485 USB to Serial Hub. > - UPort 1130I : 1 port RS-422/485 USB to Serial Hub with Isolation. > - UPort 1150 : 1 port RS-232/422/485 USB to Serial Hub. > - UPort 1150I : 1 port RS-232/422/485 USB to Serial Hub with Isolation. > > This driver is based on GPL MOXA driver written by Hen Huang and available > on MOXA website. The original driver was based on io_ti serial driver. > > Signed-off-by: Mathieu OTHACEHE > --- > > Hi Johan, > > Here is the v6 of the driver. > > I understand the problems with the TIOCSRS485/TIOCGRS485 ioctls in > this driver. > For now, I prefer dropping mode switching support from the driver as > you suggested. > > So UPORT 1110 and 1150 only support RS232 and UPORT 1130 only support > RS-485-2W. > If a new interface is developped, I'll restore mode switching code. Sounds good. > About firmware images, I just sent a patch to linux-firmware. Here is the > link : > https://lkml.org/lkml/2015/12/28/239 Thanks, I've done some quick tests using a 1150 now. When looking through the code one last time I found a few issues that I fixed up. I'll submit patches for these to the USB list. But there are couple of things you could consider to do as follow ups as well. Details below. > +static int mxu1_port_probe(struct usb_serial_port *port) > +{ > + struct mxu1_port *mxport; > + struct mxu1_device *mxdev; > + struct urb *urb; > + > + mxport = kzalloc(sizeof(struct mxu1_port), GFP_KERNEL); > + if (!mxport) > + return -ENOMEM; > + > + spin_lock_init(&mxport->spinlock); > + mutex_init(&mxport->mutex); > + > + mxdev = usb_get_serial_data(port->serial); > + > + urb = port->interrupt_in_urb; > + if (!urb) { You are leaking the port private data here (fixed). > + dev_err(&port->dev, "%s - no interrupt urb\n", __func__); > + return -EINVAL; > + } > + > + switch (mxdev->mxd_model) { > + case MXU1_1110_PRODUCT_ID: > + case MXU1_1150_PRODUCT_ID: > + case MXU1_1151_PRODUCT_ID: > + mxport->uart_mode = MXU1_UART_232; > + break; > + case MXU1_1130_PRODUCT_ID: > + case MXU1_1131_PRODUCT_ID: > + mxport->uart_mode = MXU1_UART_485_RECEIVER_DISABLED; > + break; > + } > + > + usb_set_serial_port_data(port, mxport); > + > + port->port.closing_wait = > + msecs_to_jiffies(MXU1_DEFAULT_CLOSING_WAIT * 10); > + port->port.drain_delay = 1; > + > + return 0; > +} > + > +static int mxu1_startup(struct usb_serial *serial) > +{ > + struct mxu1_device *mxdev; > + struct usb_device *dev = serial->dev; > + struct usb_host_interface *cur_altsetting; > + char fw_name[32]; > + const struct firmware *fw_p = NULL; > + int err; > + int status = 0; > + > + dev_dbg(&serial->interface->dev, "%s - product 0x%04X, num > configurations %d, configuration value %d\n", > + __func__, le16_to_cpu(dev->descriptor.idProduct), > + dev->descriptor.bNumConfigurations, > + dev->actconfig->desc.bConfigurationValue); > + > + /* create device structure */ > + mxdev = kzalloc(sizeof(struct mxu1_device), GFP_KERNEL); > + if (!mxdev) > + return -ENOMEM; > + > + usb_set_serial_data(serial, mxdev); > + > + mxdev->mxd_model = le16_to_cpu(dev->descriptor.idProduct); > + > + cur_altsetting = serial->interface->cur_altsetting; > + > + /* if we have only 1 configuration, download firmware */ > + if (cur_altsetting->desc.bNumEndpoints == 1) { > + > + snprintf(fw_name, > + sizeof(fw_name), > + "moxa/moxa-%04x.fw", > + mxdev->mxd_model); > + > + err = request_firmware(&fw_p, fw_name, &serial->interface->dev); > + if (err) { > + dev_err(&serial->interface->dev, "failed to request > firmware: %d\n", > + err); > + kfree(mxdev); > + return err; > + } > + > + err = mxu1_download_firmware(serial, fw_p); > + if (err) { > + release_firmware(fw_p); > + kfree(mxdev); > + return err; > + } > + > + status = -ENODEV; > + release_firmware(fw_p); And you're leaking the interface private data here as well (also fixed). What you could consider doing as a follow up it so move both the interrupt-in urb test in port_probe and the firmware download to a new probe callback. That way you avoid the unnecessary memory allocations done by core before attach is called, and you can verify and refuse to bind to a device in case the expected endpoints are missing. > + } > + > +
[PATCH 1/6] USB: mxu11x0: fix memory leak in port-probe error path
Fix memory leak in port-probe error path by verifying the interrupt-in urb before allocating the private data. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index 8884ca276e67..89426c3eba98 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -333,7 +333,11 @@ static int mxu1_port_probe(struct usb_serial_port *port) { struct mxu1_port *mxport; struct mxu1_device *mxdev; - struct urb *urb; + + if (!port->interrupt_in_urb) { + dev_err(&port->dev, "no interrupt urb\n"); + return -ENODEV; + } mxport = kzalloc(sizeof(struct mxu1_port), GFP_KERNEL); if (!mxport) @@ -344,12 +348,6 @@ static int mxu1_port_probe(struct usb_serial_port *port) mxdev = usb_get_serial_data(port->serial); - urb = port->interrupt_in_urb; - if (!urb) { - dev_err(&port->dev, "%s - no interrupt urb\n", __func__); - return -EINVAL; - } - switch (mxdev->mxd_model) { case MXU1_1110_PRODUCT_ID: case MXU1_1150_PRODUCT_ID: -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/6] USB: mxu11x0: fix memory leak on firmware download
Make sure to release the private data before returning -ENODEV after having downloaded the firmware during first probe. Clean up the error paths while at it. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 25 ++--- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index 89426c3eba98..c6c4776997fc 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -377,7 +377,6 @@ static int mxu1_startup(struct usb_serial *serial) char fw_name[32]; const struct firmware *fw_p = NULL; int err; - int status = 0; dev_dbg(&serial->interface->dev, "%s - product 0x%04X, num configurations %d, configuration value %d\n", __func__, le16_to_cpu(dev->descriptor.idProduct), @@ -407,22 +406,26 @@ static int mxu1_startup(struct usb_serial *serial) if (err) { dev_err(&serial->interface->dev, "failed to request firmware: %d\n", err); - kfree(mxdev); - return err; + goto err_free_mxdev; } err = mxu1_download_firmware(serial, fw_p); - if (err) { - release_firmware(fw_p); - kfree(mxdev); - return err; - } + if (err) + goto err_release_firmware; - status = -ENODEV; - release_firmware(fw_p); + /* device is being reset */ + err = -ENODEV; + goto err_release_firmware; } - return status; + return 0; + +err_release_firmware: + release_firmware(fw_p); +err_free_mxdev: + kfree(mxdev); + + return err; } static int mxu1_write_byte(struct usb_serial_port *port, u32 addr, -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/6] USB: mxu11x0: fix modem-control handling on B0-transitions
Make sure to raise DTR and RTS on transitions from B0 and leave the other bits unchanged. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index c6c4776997fc..c408cd7b4dc6 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -595,7 +595,7 @@ static void mxu1_set_termios(struct tty_struct *tty, if (C_BAUD(tty) == B0) mcr &= ~(MXU1_MCR_DTR | MXU1_MCR_RTS); else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) - mcr |= ~(MXU1_MCR_DTR | MXU1_MCR_RTS); + mcr |= MXU1_MCR_DTR | MXU1_MCR_RTS; status = mxu1_set_mcr(port, mcr); if (status) -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/6] USB: mxu11x0: fix memory leak in port-probe error path
Fix memory leak in port-probe error path by verifying the interrupt-in urb before allocating the private data. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index 8884ca276e67..89426c3eba98 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -333,7 +333,11 @@ static int mxu1_port_probe(struct usb_serial_port *port) { struct mxu1_port *mxport; struct mxu1_device *mxdev; - struct urb *urb; + + if (!port->interrupt_in_urb) { + dev_err(&port->dev, "no interrupt urb\n"); + return -ENODEV; + } mxport = kzalloc(sizeof(struct mxu1_port), GFP_KERNEL); if (!mxport) @@ -344,12 +348,6 @@ static int mxu1_port_probe(struct usb_serial_port *port) mxdev = usb_get_serial_data(port->serial); - urb = port->interrupt_in_urb; - if (!urb) { - dev_err(&port->dev, "%s - no interrupt urb\n", __func__); - return -EINVAL; - } - switch (mxdev->mxd_model) { case MXU1_1110_PRODUCT_ID: case MXU1_1150_PRODUCT_ID: -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/6] USB: mxu11x0: fix memory leak on firmware download
Make sure to release the private data before returning -ENODEV after having downloaded the firmware during first probe. Clean up the error paths while at it. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 25 ++--- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index 89426c3eba98..c6c4776997fc 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -377,7 +377,6 @@ static int mxu1_startup(struct usb_serial *serial) char fw_name[32]; const struct firmware *fw_p = NULL; int err; - int status = 0; dev_dbg(&serial->interface->dev, "%s - product 0x%04X, num configurations %d, configuration value %d\n", __func__, le16_to_cpu(dev->descriptor.idProduct), @@ -407,22 +406,26 @@ static int mxu1_startup(struct usb_serial *serial) if (err) { dev_err(&serial->interface->dev, "failed to request firmware: %d\n", err); - kfree(mxdev); - return err; + goto err_free_mxdev; } err = mxu1_download_firmware(serial, fw_p); - if (err) { - release_firmware(fw_p); - kfree(mxdev); - return err; - } + if (err) + goto err_release_firmware; - status = -ENODEV; - release_firmware(fw_p); + /* device is being reset */ + err = -ENODEV; + goto err_release_firmware; } - return status; + return 0; + +err_release_firmware: + release_firmware(fw_p); +err_free_mxdev: + kfree(mxdev); + + return err; } static int mxu1_write_byte(struct usb_serial_port *port, u32 addr, -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 6/6] USB: mxu11x0: drop redundant function name from error messages
Drop redundant function name from a few error messages. Drop redundant error message when generic open fails. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 32 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index c8c959679827..e3c3f57c2d82 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -776,24 +776,22 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) status = mxu1_send_ctrl_urb(serial, MXU1_OPEN_PORT, open_settings, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot send open command: %d\n", - __func__, status); + dev_err(&port->dev, "cannot send open command: %d\n", status); goto unlink_int_urb; } status = mxu1_send_ctrl_urb(serial, MXU1_START_PORT, 0, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot send start command: %d\n", - __func__, status); + dev_err(&port->dev, "cannot send start command: %d\n", status); goto unlink_int_urb; } status = mxu1_send_ctrl_urb(serial, MXU1_PURGE_PORT, MXU1_PURGE_INPUT, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot clear input buffers: %d\n", - __func__, status); + dev_err(&port->dev, "cannot clear input buffers: %d\n", + status); goto unlink_int_urb; } @@ -801,8 +799,8 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) status = mxu1_send_ctrl_urb(serial, MXU1_PURGE_PORT, MXU1_PURGE_OUTPUT, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot clear output buffers: %d\n", - __func__, status); + dev_err(&port->dev, "cannot clear output buffers: %d\n", + status); goto unlink_int_urb; } @@ -820,25 +818,20 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) status = mxu1_send_ctrl_urb(serial, MXU1_OPEN_PORT, open_settings, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot send open command: %d\n", - __func__, status); + dev_err(&port->dev, "cannot send open command: %d\n", status); goto unlink_int_urb; } status = mxu1_send_ctrl_urb(serial, MXU1_START_PORT, 0, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot send start command: %d\n", - __func__, status); + dev_err(&port->dev, "cannot send start command: %d\n", status); goto unlink_int_urb; } status = usb_serial_generic_open(tty, port); - if (status) { - dev_err(&port->dev, "%s - submit read urb failed: %d\n", - __func__, status); + if (status) goto unlink_int_urb; - } return 0; @@ -921,8 +914,7 @@ static void mxu1_interrupt_callback(struct urb *urb) } if (data[0] == MXU1_CODE_HARDWARE_ERROR) { - dev_err(&port->dev, "%s - hardware error: %d\n", - __func__, data[1]); + dev_err(&port->dev, "hardware error: %d\n", data[1]); goto exit; } @@ -943,8 +935,8 @@ static void mxu1_interrupt_callback(struct urb *urb) break; default: - dev_err(&port->dev, "%s - unknown interrupt code: 0x%02X\n", - __func__, data[1]); + dev_err(&port->dev, "unknown interrupt code: 0x%02X\n", + data[1]); break; } -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/6] USB: mxu11x0: rename usb-serial driver
Rename the usb-serial driver "mxu11x0" to match the USB driver name. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index c408cd7b4dc6..73cc8564a562 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -958,10 +958,10 @@ exit: status); } -static struct usb_serial_driver mxuport11_device = { +static struct usb_serial_driver mxu11x0_device = { .driver = { .owner = THIS_MODULE, - .name = "mxuport11", + .name = "mxu11x0", }, .description= "MOXA UPort 11x0", .id_table = mxu1_idtable, @@ -981,7 +981,7 @@ static struct usb_serial_driver mxuport11_device = { }; static struct usb_serial_driver *const serial_drivers[] = { - &mxuport11_device, NULL + &mxu11x0_device, NULL }; module_usb_serial_driver(serial_drivers, mxu1_idtable); -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 6/6] USB: mxu11x0: drop redundant function name from error messages
Drop redundant function name from a few error messages. Drop redundant error message when generic open fails. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 32 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index c8c959679827..e3c3f57c2d82 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -776,24 +776,22 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) status = mxu1_send_ctrl_urb(serial, MXU1_OPEN_PORT, open_settings, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot send open command: %d\n", - __func__, status); + dev_err(&port->dev, "cannot send open command: %d\n", status); goto unlink_int_urb; } status = mxu1_send_ctrl_urb(serial, MXU1_START_PORT, 0, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot send start command: %d\n", - __func__, status); + dev_err(&port->dev, "cannot send start command: %d\n", status); goto unlink_int_urb; } status = mxu1_send_ctrl_urb(serial, MXU1_PURGE_PORT, MXU1_PURGE_INPUT, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot clear input buffers: %d\n", - __func__, status); + dev_err(&port->dev, "cannot clear input buffers: %d\n", + status); goto unlink_int_urb; } @@ -801,8 +799,8 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) status = mxu1_send_ctrl_urb(serial, MXU1_PURGE_PORT, MXU1_PURGE_OUTPUT, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot clear output buffers: %d\n", - __func__, status); + dev_err(&port->dev, "cannot clear output buffers: %d\n", + status); goto unlink_int_urb; } @@ -820,25 +818,20 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) status = mxu1_send_ctrl_urb(serial, MXU1_OPEN_PORT, open_settings, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot send open command: %d\n", - __func__, status); + dev_err(&port->dev, "cannot send open command: %d\n", status); goto unlink_int_urb; } status = mxu1_send_ctrl_urb(serial, MXU1_START_PORT, 0, MXU1_UART1_PORT); if (status) { - dev_err(&port->dev, "%s - cannot send start command: %d\n", - __func__, status); + dev_err(&port->dev, "cannot send start command: %d\n", status); goto unlink_int_urb; } status = usb_serial_generic_open(tty, port); - if (status) { - dev_err(&port->dev, "%s - submit read urb failed: %d\n", - __func__, status); + if (status) goto unlink_int_urb; - } return 0; @@ -921,8 +914,7 @@ static void mxu1_interrupt_callback(struct urb *urb) } if (data[0] == MXU1_CODE_HARDWARE_ERROR) { - dev_err(&port->dev, "%s - hardware error: %d\n", - __func__, data[1]); + dev_err(&port->dev, "hardware error: %d\n", data[1]); goto exit; } @@ -943,8 +935,8 @@ static void mxu1_interrupt_callback(struct urb *urb) break; default: - dev_err(&port->dev, "%s - unknown interrupt code: 0x%02X\n", - __func__, data[1]); + dev_err(&port->dev, "unknown interrupt code: 0x%02X\n", + data[1]); break; } -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/6] USB: mxu11x0: fix modem-control handling on B0-transitions
Make sure to raise DTR and RTS on transitions from B0 and leave the other bits unchanged. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index c6c4776997fc..c408cd7b4dc6 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -595,7 +595,7 @@ static void mxu1_set_termios(struct tty_struct *tty, if (C_BAUD(tty) == B0) mcr &= ~(MXU1_MCR_DTR | MXU1_MCR_RTS); else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) - mcr |= ~(MXU1_MCR_DTR | MXU1_MCR_RTS); + mcr |= MXU1_MCR_DTR | MXU1_MCR_RTS; status = mxu1_set_mcr(port, mcr); if (status) -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 5/6] USB: mxu11x0: fix debug-message typos
Fix a couple of debug-message typos, and do some minor clean ups. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 18 -- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index 73cc8564a562..c8c959679827 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -1,5 +1,4 @@ /* - * * USB Moxa UPORT 11x0 Serial Driver * * Copyright (C) 2007 MOXA Technologies Co., Ltd. @@ -494,10 +493,10 @@ static void mxu1_set_termios(struct tty_struct *tty, } dev_dbg(&port->dev, - "%s - clfag %08x, iflag %08x\n", __func__, cflag, iflag); + "%s - cflag 0x%08x, iflag 0x%08x\n", __func__, cflag, iflag); if (old_termios) { - dev_dbg(&port->dev, "%s - old clfag %08x, old iflag %08x\n", + dev_dbg(&port->dev, "%s - old cflag 0x%08x, old iflag 0x%08x\n", __func__, old_termios->c_cflag, old_termios->c_iflag); @@ -764,7 +763,6 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) mxport->msr = 0; - dev_dbg(&port->dev, "%s - start interrupt in urb\n", __func__); status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); if (status) { dev_err(&port->dev, "failed to submit interrupt urb: %d\n", @@ -842,7 +840,7 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) goto unlink_int_urb; } - return status; + return 0; unlink_int_urb: usb_kill_urb(port->interrupt_in_urb); @@ -859,21 +857,20 @@ static void mxu1_close(struct usb_serial_port *port) status = mxu1_send_ctrl_urb(port->serial, MXU1_CLOSE_PORT, 0, MXU1_UART1_PORT); - if (status) + if (status) { dev_err(&port->dev, "failed to send close port command: %d\n", status); + } } static void mxu1_handle_new_msr(struct usb_serial_port *port, u8 msr) { + struct mxu1_port *mxport = usb_get_serial_port_data(port); struct async_icount *icount; - struct mxu1_port *mxport; unsigned long flags; dev_dbg(&port->dev, "%s - msr 0x%02X\n", __func__, msr); - mxport = usb_get_serial_port_data(port); - spin_lock_irqsave(&mxport->spinlock, flags); mxport->msr = msr & MXU1_MSR_MASK; spin_unlock_irqrestore(&mxport->spinlock, flags); @@ -953,9 +950,10 @@ static void mxu1_interrupt_callback(struct urb *urb) exit: status = usb_submit_urb(urb, GFP_ATOMIC); - if (status) + if (status) { dev_err(&port->dev, "resubmit interrupt urb failed: %d\n", status); + } } static struct usb_serial_driver mxu11x0_device = { -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/6] USB: mxu11x0: fixes and clean ups
Here are a few fixes and clean ups of issues found during a last review of the new driver. Johan Johan Hovold (6): USB: mxu11x0: fix memory leak in port-probe error path USB: mxu11x0: fix memory leak on firmware download USB: mxu11x0: fix modem-control handling on B0-transitions USB: mxu11x0: rename usb-serial driver USB: mxu11x0: fix debug-message typos USB: mxu11x0: drop redundant function name from error messages drivers/usb/serial/mxu11x0.c | 95 1 file changed, 43 insertions(+), 52 deletions(-) -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 5/6] USB: mxu11x0: fix debug-message typos
Fix a couple of debug-message typos, and do some minor clean ups. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 18 -- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index 73cc8564a562..c8c959679827 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -1,5 +1,4 @@ /* - * * USB Moxa UPORT 11x0 Serial Driver * * Copyright (C) 2007 MOXA Technologies Co., Ltd. @@ -494,10 +493,10 @@ static void mxu1_set_termios(struct tty_struct *tty, } dev_dbg(&port->dev, - "%s - clfag %08x, iflag %08x\n", __func__, cflag, iflag); + "%s - cflag 0x%08x, iflag 0x%08x\n", __func__, cflag, iflag); if (old_termios) { - dev_dbg(&port->dev, "%s - old clfag %08x, old iflag %08x\n", + dev_dbg(&port->dev, "%s - old cflag 0x%08x, old iflag 0x%08x\n", __func__, old_termios->c_cflag, old_termios->c_iflag); @@ -764,7 +763,6 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) mxport->msr = 0; - dev_dbg(&port->dev, "%s - start interrupt in urb\n", __func__); status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); if (status) { dev_err(&port->dev, "failed to submit interrupt urb: %d\n", @@ -842,7 +840,7 @@ static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) goto unlink_int_urb; } - return status; + return 0; unlink_int_urb: usb_kill_urb(port->interrupt_in_urb); @@ -859,21 +857,20 @@ static void mxu1_close(struct usb_serial_port *port) status = mxu1_send_ctrl_urb(port->serial, MXU1_CLOSE_PORT, 0, MXU1_UART1_PORT); - if (status) + if (status) { dev_err(&port->dev, "failed to send close port command: %d\n", status); + } } static void mxu1_handle_new_msr(struct usb_serial_port *port, u8 msr) { + struct mxu1_port *mxport = usb_get_serial_port_data(port); struct async_icount *icount; - struct mxu1_port *mxport; unsigned long flags; dev_dbg(&port->dev, "%s - msr 0x%02X\n", __func__, msr); - mxport = usb_get_serial_port_data(port); - spin_lock_irqsave(&mxport->spinlock, flags); mxport->msr = msr & MXU1_MSR_MASK; spin_unlock_irqrestore(&mxport->spinlock, flags); @@ -953,9 +950,10 @@ static void mxu1_interrupt_callback(struct urb *urb) exit: status = usb_submit_urb(urb, GFP_ATOMIC); - if (status) + if (status) { dev_err(&port->dev, "resubmit interrupt urb failed: %d\n", status); + } } static struct usb_serial_driver mxu11x0_device = { -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/6] USB: mxu11x0: fixes and clean ups
Here are a few fixes and clean ups of issues found during a last review of the new driver. Johan Johan Hovold (6): USB: mxu11x0: fix memory leak in port-probe error path USB: mxu11x0: fix memory leak on firmware download USB: mxu11x0: fix modem-control handling on B0-transitions USB: mxu11x0: rename usb-serial driver USB: mxu11x0: fix debug-message typos USB: mxu11x0: drop redundant function name from error messages drivers/usb/serial/mxu11x0.c | 95 1 file changed, 43 insertions(+), 52 deletions(-) -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/6] USB: mxu11x0: rename usb-serial driver
Rename the usb-serial driver "mxu11x0" to match the USB driver name. Signed-off-by: Johan Hovold --- drivers/usb/serial/mxu11x0.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/mxu11x0.c b/drivers/usb/serial/mxu11x0.c index c408cd7b4dc6..73cc8564a562 100644 --- a/drivers/usb/serial/mxu11x0.c +++ b/drivers/usb/serial/mxu11x0.c @@ -958,10 +958,10 @@ exit: status); } -static struct usb_serial_driver mxuport11_device = { +static struct usb_serial_driver mxu11x0_device = { .driver = { .owner = THIS_MODULE, - .name = "mxuport11", + .name = "mxu11x0", }, .description= "MOXA UPort 11x0", .id_table = mxu1_idtable, @@ -981,7 +981,7 @@ static struct usb_serial_driver mxuport11_device = { }; static struct usb_serial_driver *const serial_drivers[] = { - &mxuport11_device, NULL + &mxu11x0_device, NULL }; module_usb_serial_driver(serial_drivers, mxu1_idtable); -- 2.4.10 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/6] USB: mxu11x0: fixes and clean ups
On Tue, Dec 29, 2015 at 01:36:17PM +0100, Johan Hovold wrote: > Here are a few fixes and clean ups of issues found during a last review > of the new driver. Bah, sorry about the double post. Johan -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/1] usb: cdc-acm: handle unlinked urb in acm read callback
On Tue, 2015-12-29 at 13:46 +0800, Lu Baolu wrote: > In current acm driver, the bulk-in callback function ignores the > URBs unlinked in usb core. > > This causes unexpected data loss in some cases. For example, > runtime suspend entry will unlinked all urbs and set urb->status > to -ENOENT even those urbs might have data not processed yet. > Hence, data loss occurs. > > This patch lets bulk-in callback function handle unlinked urbs > to avoid data loss. > > Signed-off-by: Tang Jian Qiang > Signed-off-by: Lu Baolu > Cc: sta...@vger.kernel.org Acked-by: Oliver Neukum -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 5/5] usb: dwc2: gadget: free TX FIFO after killing requests
Hello. On 12/28/2015 07:25 PM, Robert Baldyga wrote: As kill_all_requests() potentially flushes TX FIFO, we should should free FIFO after calling it. Otherwise FIFO could stay unflushed properly. Signed-off-by: Robert Baldyga --- drivers/usb/dwc2/gadget.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index fadd635..e14d076 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -2779,10 +2779,6 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep) spin_lock_irqsave(&hsotg->lock, flags); - hsotg->fifo_map &= ~(1fifo_index = 0; - hs_ep->fifo_size = 0; - ctrl = dwc2_readl(hsotg->regs + epctrl_reg); ctrl &= ~DXEPCTL_EPENA; ctrl &= ~DXEPCTL_USBACTEP; @@ -2797,6 +2793,10 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep) /* terminate all requests with shutdown */ kill_all_requests(hsotg, hs_ep, -ESHUTDOWN); + hsotg->fifo_map &= ~(1
[PATCH 2/2] dt-bindings: ci-hdrc-usb2: add missing compatibles
This patch adds the missing compatible strings from ci_hdrc_imx. Signed-off-by: Stefan Wahren --- .../devicetree/bindings/usb/ci-hdrc-usb2.txt |7 +++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt index 781296b..1e83509 100644 --- a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +++ b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt @@ -2,7 +2,14 @@ Required properties: - compatible: should be one of: + "fsl,imx23-usb" "fsl,imx27-usb" + "fsl,imx28-usb" + "fsl,imx6q-usb" + "fsl,imx6sl-usb" + "fsl,imx6sx-usb" + "fsl,imx6ul-usb" + "fsl,imx7d-usb" "lsi,zevio-usb" "qcom,ci-hdrc" "chipidea,usb2" -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] usb: chipidea: add CI_HDRC_TURN_VBUS_EARLY_ON for imx23
Until now the imx23 uses the imx27 platform flag. But the imx23 needs the flag CI_HDRC_TURN_VBUS_EARLY_ON, too. So fix this by adding a separate platform flag. Suggested-by: Peter Chen Signed-off-by: Stefan Wahren --- drivers/usb/chipidea/ci_hdrc_imx.c |6 ++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index f14f4ab..b4605dd 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -28,6 +28,11 @@ struct ci_hdrc_imx_platform_flag { bool runtime_pm; }; +static const struct ci_hdrc_imx_platform_flag imx23_usb_data = { + .flags = CI_HDRC_TURN_VBUS_EARLY_ON | + CI_HDRC_DISABLE_STREAMING, +}; + static const struct ci_hdrc_imx_platform_flag imx27_usb_data = { CI_HDRC_DISABLE_STREAMING, }; @@ -66,6 +71,7 @@ static const struct ci_hdrc_imx_platform_flag imx7d_usb_data = { }; static const struct of_device_id ci_hdrc_imx_dt_ids[] = { + { .compatible = "fsl,imx23-usb", .data = &imx23_usb_data}, { .compatible = "fsl,imx28-usb", .data = &imx28_usb_data}, { .compatible = "fsl,imx27-usb", .data = &imx27_usb_data}, { .compatible = "fsl,imx6q-usb", .data = &imx6q_usb_data}, -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] dt-bindings: ci-hdrc-usb2: add missing compatibles
On Tue, Dec 29, 2015 at 04:41:09PM +, Stefan Wahren wrote: > This patch adds the missing compatible strings from ci_hdrc_imx. > > Signed-off-by: Stefan Wahren > --- > .../devicetree/bindings/usb/ci-hdrc-usb2.txt |7 +++ > 1 file changed, 7 insertions(+) Acked-by: Rob Herring -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RESEND] xhci:Remove unused marco definitions from the file xhci-hub.c
On Tue, Dec 29, 2015 at 01:28:16PM -0500, Nicholas Krause wrote: > This removes the unneeded marco definitions for the marcos > of XHCI_PORT_RW1S, XHCI_PORT_RW1C, XHCI_PORT_RWand > XHCI_PORT_RZ due to no uses of these marcos in the file > xhci-hub.c or any other related kernel source code file > related to supporting xhci host controllers. > > Signed-off-by: Nicholas Krause Sorry Nick, you know I will not be taking any patches from you due to your previous behavior. Mathias, please ignore this patch. greg k-h -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 1/1] usb: cdc-acm: handle unlinked urb in acm read callback
In current acm driver, the bulk-in callback function ignores the URBs unlinked in usb core. This causes unexpected data loss in some cases. For example, runtime suspend entry will unlinked all urbs and set urb->status to -ENOENT even those urbs might have data not processed yet. Hence, data loss occurs. This patch lets bulk-in callback function handle unlinked urbs to avoid data loss. Signed-off-by: Tang Jian Qiang Signed-off-by: Lu Baolu Cc: sta...@vger.kernel.org Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 26ca4f9..8cd193b 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -428,7 +428,8 @@ static void acm_read_bulk_callback(struct urb *urb) set_bit(rb->index, &acm->read_urbs_free); dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n", __func__, status); - return; + if ((status != -ENOENT) || (urb->actual_length == 0)) + return; } usb_mark_last_busy(acm->dev); -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: MX28 with hub cannot reset
Hi Stefan, On Tue, Dec 29, 2015 at 9:44 AM, Stefan Wahren wrote: > i did some tests with a IMX233-Olinuxino Maxi and external 4 port usb hub, > but i > can't reproduce the problem. > > Could you provide more information about the hub? It is a USB2512. > I think we don't know that the issue comes really from the mx28 instead of the > hub. It seems there are other users that reported this same issue at community.freescale.com. Regards, Fabio Estevam -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] usb: phy: mxs: Remove unused flags
On Tue, Dec 29, 2015 at 09:19:29AM -0200, Fabio Estevam wrote: > On Tue, Dec 29, 2015 at 6:15 AM, Peter Chen wrote: > > > I prefer to keep it, and it let us know the existing issues although > > we have not implemented workaround for them. In future, we may have > > solutions for how to implement them. > > Ok, what about adding the recommendation below? > > --- a/drivers/usb/phy/phy-mxs-usb.c > +++ b/drivers/usb/phy/phy-mxs-usb.c > @@ -98,6 +98,9 @@ > * The PHY will be in messy if there is a wakeup after putting > * bus to suspend (set portsc.suspendM) but before setting PHY to low > * power mode (set portsc.phcd). > + * > + * To work around this problem on mx23/mx28 user should pass > + * 'usbcore.autosuspend=-1' in the kernel command line for now. > */ > #define MXS_PHY_ABNORMAL_IN_SUSPENDBIT(1) Good suggestion, one more you can add "before these flags are implemented" at your comment. -- Best Regards, Peter Chen -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 1/1] usb: cdc-acm: handle unlinked urb in acm read callback
On Wed, Dec 30, 2015 at 08:42:01AM +0800, Lu Baolu wrote: > In current acm driver, the bulk-in callback function ignores the > URBs unlinked in usb core. > > This causes unexpected data loss in some cases. For example, > runtime suspend entry will unlinked all urbs and set urb->status > to -ENOENT even those urbs might have data not processed yet. > Hence, data loss occurs. > > This patch lets bulk-in callback function handle unlinked urbs > to avoid data loss. > > Signed-off-by: Tang Jian Qiang > Signed-off-by: Lu Baolu > Cc: sta...@vger.kernel.org > Acked-by: Oliver Neukum > --- > drivers/usb/class/cdc-acm.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) What changed in v2? Please always document that below the --- line. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 1/1] usb: cdc-acm: handle unlinked urb in acm read callback
In current acm driver, the bulk-in callback function ignores the URBs unlinked in usb core. This causes unexpected data loss in some cases. For example, runtime suspend entry will unlinked all urbs and set urb->status to -ENOENT even those urbs might have data not processed yet. Hence, data loss occurs. This patch lets bulk-in callback function handle unlinked urbs to avoid data loss. Signed-off-by: Tang Jian Qiang Signed-off-by: Lu Baolu Cc: sta...@vger.kernel.org Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) change log: v1->v2: add Acked-by: Oliver Neukum . v2->v3: add the change log. diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 26ca4f9..8cd193b 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -428,7 +428,8 @@ static void acm_read_bulk_callback(struct urb *urb) set_bit(rb->index, &acm->read_urbs_free); dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n", __func__, status); - return; + if ((status != -ENOENT) || (urb->actual_length == 0)) + return; } usb_mark_last_busy(acm->dev); -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 1/1] usb: cdc-acm: handle unlinked urb in acm read callback
On 12/30/2015 09:46 AM, Greg Kroah-Hartman wrote: > On Wed, Dec 30, 2015 at 08:42:01AM +0800, Lu Baolu wrote: >> In current acm driver, the bulk-in callback function ignores the >> URBs unlinked in usb core. >> >> This causes unexpected data loss in some cases. For example, >> runtime suspend entry will unlinked all urbs and set urb->status >> to -ENOENT even those urbs might have data not processed yet. >> Hence, data loss occurs. >> >> This patch lets bulk-in callback function handle unlinked urbs >> to avoid data loss. >> >> Signed-off-by: Tang Jian Qiang >> Signed-off-by: Lu Baolu >> Cc: sta...@vger.kernel.org >> Acked-by: Oliver Neukum >> --- >> drivers/usb/class/cdc-acm.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) > What changed in v2? > > Please always document that below the --- line. Thank you for the reminding. I will send a new version of patch with change logs. > -- > To unsubscribe from this list: send the line "unsubscribe linux-usb" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 08/11] usbip: letting connection establishment replaceable
To introduce some application protocols like WebSocket, this patch allows to substitute connection establishment and termination. In combination with previous patch, both connection and transmission can be replaced. usbip_connection_operations_t includes open and close operation. Open method returns usbip_sock_t which includes send, receive and close method. Then, transmission methods are replaced at the same time. Succeeding WebSocket patch uses this feature. Signed-off-by: Nobuo Iwata --- tools/usb/usbip/libsrc/usbip_common.c | 10 ++ tools/usb/usbip/libsrc/usbip_common.h | 11 +++ tools/usb/usbip/src/usbip.c| 1 + tools/usb/usbip/src/usbip_attach.c | 6 +++--- tools/usb/usbip/src/usbip_connect.c| 6 +++--- tools/usb/usbip/src/usbip_disconnect.c | 6 +++--- tools/usb/usbip/src/usbip_list.c | 6 +++--- tools/usb/usbip/src/usbip_network.c| 9 +++-- tools/usb/usbip/src/usbip_network.h| 3 +-- 9 files changed, 42 insertions(+), 16 deletions(-) diff --git a/tools/usb/usbip/libsrc/usbip_common.c b/tools/usb/usbip/libsrc/usbip_common.c index dc0712c..54efa10 100644 --- a/tools/usb/usbip/libsrc/usbip_common.c +++ b/tools/usb/usbip/libsrc/usbip_common.c @@ -297,3 +297,13 @@ void usbip_sock_init(usbip_sock_t *sock, int fd, void *arg, sock->shutdown = shutdown; } +usbip_connection_operations_t usbip_conn_ops = {NULL, NULL}; + +void usbip_conn_init( + usbip_sock_t *(*open)(char *host, char *port), + void (*close)(usbip_sock_t *sock)) +{ + usbip_conn_ops.open = open; + usbip_conn_ops.close = close; +} + diff --git a/tools/usb/usbip/libsrc/usbip_common.h b/tools/usb/usbip/libsrc/usbip_common.h index 0dcbd99..07c411f 100644 --- a/tools/usb/usbip/libsrc/usbip_common.h +++ b/tools/usb/usbip/libsrc/usbip_common.h @@ -148,4 +148,15 @@ void usbip_sock_init(usbip_sock_t *sock, int fd, void *arg, ssize_t (*recv)(void *arg, void *buf, size_t len, int wait_all), void (*shutdown)(void *arg)); +typedef struct usbip_connection_operations { + usbip_sock_t *(*open)(char *host, char *port); + void (*close)(usbip_sock_t *sock); +} usbip_connection_operations_t; + +extern usbip_connection_operations_t usbip_conn_ops; + +void usbip_conn_init( + usbip_sock_t *(*open)(char *host, char *port), + void (*close)(usbip_sock_t *sock)); + #endif /* __USBIP_COMMON_H */ diff --git a/tools/usb/usbip/src/usbip.c b/tools/usb/usbip/src/usbip.c index 9d1468f..505e384 100644 --- a/tools/usb/usbip/src/usbip.c +++ b/tools/usb/usbip/src/usbip.c @@ -202,6 +202,7 @@ int main(int argc, char *argv[]) argc -= optind; argv += optind; optind = 0; + usbip_net_tcp_conn_init(); rc = run_command(&cmds[i], argc, argv); goto out; } diff --git a/tools/usb/usbip/src/usbip_attach.c b/tools/usb/usbip/src/usbip_attach.c index ae0ca6e..c67e3d2 100644 --- a/tools/usb/usbip/src/usbip_attach.c +++ b/tools/usb/usbip/src/usbip_attach.c @@ -135,7 +135,7 @@ static int attach_device(char *host, char *busid) int rc; int rhport; - sock = usbip_net_tcp_connect(host, usbip_port_string); + sock = usbip_conn_ops.open(host, usbip_port_string); if (!sock) { err("tcp connect"); goto err_out; @@ -164,13 +164,13 @@ static int attach_device(char *host, char *busid) usbip_ux_join(ux); } usbip_ux_cleanup(&ux); - usbip_net_tcp_close(sock); + usbip_conn_ops.close(sock); return 0; err_cleanup_ux: usbip_ux_cleanup(&ux); err_close_conn: - usbip_net_tcp_close(sock); + usbip_conn_ops.close(sock); err_out: return -1; } diff --git a/tools/usb/usbip/src/usbip_connect.c b/tools/usb/usbip/src/usbip_connect.c index 5f9505c..8dabd0b 100644 --- a/tools/usb/usbip/src/usbip_connect.c +++ b/tools/usb/usbip/src/usbip_connect.c @@ -150,7 +150,7 @@ static int connect_device(char *host, char *busid) goto err_out; } - sock = usbip_net_tcp_connect(host, usbip_port_string); + sock = usbip_conn_ops.open(host, usbip_port_string); if (!sock) { err("tcp connect"); goto err_unbind_device; @@ -174,13 +174,13 @@ static int connect_device(char *host, char *busid) usbip_unbind_device(busid); } usbip_ux_cleanup(&ux); - usbip_net_tcp_close(sock); + usbip_conn_ops.close(sock); return 0; err_cleanup_ux: usbip_ux_cleanup(&ux); err_close_conn: - usbip_net_tcp_close(sock); + usbip_conn_ops.close(sock); err_unbind_device: usbip_unbind_device(busid); err_out: diff --git a/tools/usb/usbip/src/usbip_disconnect.c b/tools/usb/usbip/src/usbip_disconnect.c index 8da
[PATCH v5 06/11] usbip: readme about user space URBs transmission
Addition to README regarding user space URBs transmission. Signed-off-by: Nobuo Iwata --- tools/usb/usbip/README | 22 ++ 1 file changed, 22 insertions(+) diff --git a/tools/usb/usbip/README b/tools/usb/usbip/README index 74f4afb..6b61da5 100644 --- a/tools/usb/usbip/README +++ b/tools/usb/usbip/README @@ -98,6 +98,28 @@ Application-side: a machine runs an application software uses remote USB device. - Unbind usbip-host.ko from the device. +[Userspace Transmission] + +In usage shown above, once USB devices are imported or exported, USP/IP drivers send and receive URBs in kernel space. The usbip_ux.ko kernel module alternates the route to user space by forwarding USBs through USB/IP utilities (ie. usbip, usbipd, usbipa). When userspace transmission enabled, usbip attach and connect will continue executing until usbip detach or disconnect is exeuted. + +app:# insmod usbip-core.ko +app:# insmod usbip-ux.ko +app:# insmod vhci-hcd.ko + +app:# usbipa -D + +dev:# insmod usbip-core.ko +dev:# insmod usbip-ux.ko +dev:# insmod usbip-host.ko + +dev:# usbip connect --remote --busid + - Continue running. + - Until disconnect command is executed in other terminal window. + +dev:# usbip disconnect --remote --busid + - Stops transission, quits connect command and disconnect device. + + [Example] --- DEVICE SIDE -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 11/11] usbip: USB over WebSocket
This patch adds utilities transmit packets via WebSocket protocol. WebSocket version of utilities as following. usbws : command usbwsa : application-side daemon usbwsd : device-side daemon The command supports all sub-command (ie. list, connect, disconnect, port, bind, unbind, attach and detach). It uses --url option to specify remote address and port number. Implementation of this patch depends on Poco C++ (http://pocoproject.org/). The tree is shown below. tools +--usb +--usbip +--src : command, daemons and their core libraries +--libsrc : common library for command and daemon +--websocket : new! WebSocket implementations +--poco : new! implementation with Poco C++ Signed-off-by: Nobuo Iwata --- tools/usb/usbip/websocket/INSTALL | 237 ++ tools/usb/usbip/websocket/Makefile.am | 3 + tools/usb/usbip/websocket/README | 184 tools/usb/usbip/websocket/autogen.sh | 9 + tools/usb/usbip/websocket/cleanup.sh | 12 + tools/usb/usbip/websocket/configure.ac| 55 +++ tools/usb/usbip/websocket/doc/usbws.8 | 192 tools/usb/usbip/websocket/doc/usbwsa.8| 101 + tools/usb/usbip/websocket/doc/usbwsd.8| 109 + tools/usb/usbip/websocket/poco/Makefile.am| 18 + .../usb/usbip/websocket/poco/USBWSCommand.cpp | 410 ++ tools/usb/usbip/websocket/poco/USBWSCommand.h | 99 + .../usb/usbip/websocket/poco/USBWSDaemon.cpp | 228 ++ tools/usb/usbip/websocket/poco/USBWSDaemon.h | 80 .../websocket/poco/USBWSRequestHandler.cpp| 90 .../websocket/poco/USBWSRequestHandler.h | 49 +++ .../poco/USBWSRequestHandlerFactory.cpp | 49 +++ .../poco/USBWSRequestHandlerFactory.h | 48 ++ tools/usb/usbip/websocket/poco/USBWSUtil.h| 52 +++ .../usbip/websocket/poco/USBWSWebSocket.cpp | 204 + .../usb/usbip/websocket/poco/USBWSWebSocket.h | 69 +++ 21 files changed, 2298 insertions(+) diff --git a/tools/usb/usbip/websocket/INSTALL b/tools/usb/usbip/websocket/INSTALL new file mode 100644 index 000..d3c5b40 --- /dev/null +++ b/tools/usb/usbip/websocket/INSTALL @@ -0,0 +1,237 @@ +Installation Instructions +* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006, 2007 Free Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +== + +Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `
[PATCH v5 03/11] usbip: safe completion against usb_kill_urb()
stub_shutdown_connection() : drivers/usb/usbip/stub_dev.c stub_device_cleanup_urbs() : drivers/usb/usbip/stub_main.c requests to kill pending URBs and clears priv lists. stub_complete() : drivers/usb/usbip/stub_tx.c might be called with URBs to have been requested to kill. To avoid kernel panic, this patch ignores killed URBs linked to cleared priv lists. To know the killed URBs in stub_complete(), sdev->ud.tcp_socket which cleared before stub_device_cleanup_urbs() is checked. The critial condition will happen by unbind command before detach, broken connection in connect command and disconnect command. Signed-off-by: Nobuo Iwata --- drivers/usb/usbip/stub_tx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/usbip/stub_tx.c b/drivers/usb/usbip/stub_tx.c index dbcabc9..f19f321 100644 --- a/drivers/usb/usbip/stub_tx.c +++ b/drivers/usb/usbip/stub_tx.c @@ -97,7 +97,9 @@ void stub_complete(struct urb *urb) /* link a urb to the queue of tx. */ spin_lock_irqsave(&sdev->priv_lock, flags); - if (priv->unlinking) { + if (sdev->ud.tcp_socket == NULL) { + dev_info(&urb->dev->dev, "discard a urb for closed connection"); + } else if (priv->unlinking) { stub_enqueue_ret_unlink(sdev, priv->seqnum, urb->status); stub_free_priv_and_urb(priv); } else { -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 04/11] usbip: kernel module for userspace URBs transmission
Originally, USB/IP transmits requests and response PDUs for preparation to transfer URBs in user space, after the preparation, URBs are transmitted in kernel space. To make easy to introduce application network protocols like WebSocket and so on, the driver, usbip_ux.ko, forwards URBs to USB/IP user space utilities. It's just like fuse driver for user space file system. Then, utilities transfer URBs in user space. To do so, usbip_trx_ops makes send/receive functions pluggable. kernel_sendmsg() and kernel_recvmsg() for kernel mode transfer can be substituted by read/write methods to user space utilities. In the absence of usbip_ux.ko, original kernel space transferring is valid. usbip_ux.ko replaces usbip_trx_ops in its init routine. A) Original - kernel space URBs transfer User+---+ 1) import/export +---+ space |uspipd,|<>|usbip, | |usbip | |usbipa | +---+---+ +---+---+ | | 2)Set sockfd| |2)Set sockfd thru sysfs| | thru sysfs V V Kernel +---+4)URBs+---+ space |usbip |<>|vhci | |host.ko| |hcd.ko | +---+ +---+ 3)link to kernel trx_ops 3)link to kernel trx_ops B) New - user space URBs transfer User+---+1)import/export +---+ space |uspipd,|<>|usbip, | +---|usbip |<>|usbipa |---+ 2)Set sockfd|+--+---+6)URBs+---+--+|2)Set sockfd thru ioctl|| ^ ^ || thru ioctl (right) || |5)read/write 5)read/write| || (left) 3)Set sockfd|| +---+ +--+ ||3)Set Sockfd thru sysfs|+---+ | /dev/usbip-ux| +---+| thru sysfs (left)VV V V VV (right) Kernel +---+ +---+ +---+ +---+ space |usbip |<->|usbip | |usbip |<->|vhci | |host.ko|5)send |ux.ko | |ux.ko |5)send |hcd.ko | +---+ recv +---+ +---+ recv +---+ 4)link to user trx_ops 4)link to user trx_ops Kernel module configuration for the driver will be shown as below. USB/IP support USBIP_CORE +-- USB/IP userspace URB transmission USBIP_UX +-- VHCI hcdUSBIP_HCD +-- Debug messages for USB/IP USBIP_DEBUG The reason why the userspace transmission oter than usbfs is needed. a) Application(vhci_hcd)-side is needed Usbfs provides functions to control device. So it can be applied to device(usbip_host)-side but not to application(vhci_hcd)-side. b) Use existing kernel modules as-is To implement same functionality in userspace with interface like usbfs, almost same code to kernel modules must be copied to userspcae. Also interfaces between kernel modules and utiities (sysfs) should be changed to new one. So utilities must be modified according to the new interface too. Modifications to existing code by this patch is small and usbip_ux.c handles major part of userspace transmission. To get diff include/uapi/linux/usbip_ux.h, I used modified dontdiff.txt. Signed-off-by: Nobuo Iwata --- drivers/usb/usbip/Kconfig| 10 + drivers/usb/usbip/Makefile | 3 + drivers/usb/usbip/stub_dev.c | 16 +- drivers/usb/usbip/stub_rx.c | 3 +- drivers/usb/usbip/stub_tx.c | 5 +- drivers/usb/usbip/usbip_common.c | 79 +++- drivers/usb/usbip/usbip_common.h | 29 +- drivers/usb/usbip/usbip_ux.c | 602 +++ drivers/usb/usbip/usbip_ux.h | 82 + drivers/usb/usbip/vhci_hcd.c | 9 +- drivers/usb/usbip/vhci_rx.c | 3 +- drivers/usb/usbip/vhci_sysfs.c | 40 +- drivers/usb/usbip/vhci_tx.c | 6 +- include/uapi/linux/usbip_ux.h| 39 ++ 14 files changed, 869 insertions(+), 57 deletions(-) diff --git a/drivers/usb/usbip/Kconfig b/drivers/usb/usbip/Kconfig index bd99e9e..e847d06 100644 --- a/drivers/usb/usbip/Kconfig +++ b/drivers/usb/usbip/Kconfig @@ -14,6 +14,16 @@ config USBIP_CORE If unsure, say N. +config USBIP_UX + tristate "USB/IP userspace URB transmission" + depends on USBIP_CORE + ---help--- + This moves USB/IP URB transmission to userspace + to apply SSL, WebSocket and etc. + + To compile this driver as a module, choose M here: the + module will be called usbip-ux. + config USBIP_VHCI_HCD tristate "VHCI hcd" depends on USBIP_CORE diff --git
[PATCH v5 00/11] usbip: features to USB over WebSocket
Dear all, This series of patches introduces WebSocket to USB/IP. 0. Version info v5) # Added vendor/pruduct name conversion to port command. # Put initial value to pool_head in name.c. # Fixed list command exception when host option is omitted. # Fixed exception in case gai_strerror() returns NULL. # Fixed WebSocket connection close via proxy. # Fixed to stop WebSocket ping-pong on connection close. # Removed redundant usbipd daemon option. # Removed redundant SSL code had not been deleted. # Removed an unused local variable in WebSocket code. # Modified C++ reserved word in names.c as same as headers. v4) # Fixed regression of usbip list --remote v3) # Coding style for goto err labels are fixed. # Defined magic numbers for open_hc_device() argument. # Corrected include .../uapi/linux/usbip_ux.h as . # Modified parameter notation in manuals not to use '='. # Fixed inappropriate version definition in tools/.../websocket/configure.ac. # Remved unnecessary COPYING and AUTHORS fil from tools/.../websocket/. # Added -version-info to libraries in tools/.../src. v2) # Formatted patches from linux-next. # Fixed change log word wrapping. # Removed SSL patches. # Fixed a bug that vendor and product names are not shown by 'usbws list -l' because usbip_names_init() was not called in libusbip.la. 1. Features included It also includes some independent features effective in themselves. 1) Exporting devices Export request and response PDU had been defined in a header but not been used. Now it works! Also, it supports senarios, for example, connect ubiquetous devices to a Linux based cloud service. In this senario, it's needed to establish connection from a device inside of firewall to a service outside. Exporting is suit for the senario. 2) User space transmission USB/IP transfer URBs in kernel space. It's better for performance but difficult to introduce application protocols. Like fuse for file systems, it allows to transfer URBs in user space. When usbip_ux.ko is loaded, it replaces kernel_sendmsg() and kernel_recvmsg() with user spcace interface. When USB/IP utilities find usbip_ux.ko, they start threads to read/write PDUs from/to usbip_ux.ko and send/recv them. 3) Replaceable protocols Both transmission(send/receive) and connection establishment are replaceable. 4) a WebSocket implementation It's made with Poco C++. DNS and proxy client are supported. I published scripts I used while developed the patches. http://linux-usbip-additions.blogspot.jp/2015/03/scripts-to-patch-and-ma ke-locally.html http://linux-usbip-additions.blogspot.jp/2015/03/test-scripts.html 2. Why WebSocket? It allows to use USB/IP in internet. WebSocket is widely used to encapsulate packets in HTTP and to carry them through firewall using HTTP port numbers. Assumed use case is a system that service in internet serves distributes devices in home or office networks. Service may be called as cloud and devices as ubiquitous. Home/SOHO/IntranetInternet ++++ +--+ +--+ |Router, ||Internet| +|device|---|Linux |-|proxy, ||service | |+--+ +--+ |firewall||on Linux| +--+ controller++++ ex) Device Service sensors ... environment analysis cameras ... monitoring, recording ID/biometric readers .. authentication 3. Why userspace transmission? Userspace transmission and APIs provided by this series allow to apply application protocols to USB/IP. Why not use usbfs or libusb? a) Not only device(usbip-host) side, application(vhci-hcd) side must be handled. b) In device side, if using usbfs or libusb, many parts of usbip-common and usbip-host driver must be copied to userspace. It's not good for maintainability. Tunneling daemons can wrap TCP/IP with application protocol. They pass packets through loopback so this series has certain advantage regarding performance. It's important for small (IoT) devices. 4. Why exporting devices? Connection from outside firewall is usually blocked. So existing import request sent with attach command doesn't work. # usbipd (blocked)|| <- # usbip attach Firewall opens some ports, usually HTTP(80) and HTTPS(443), from inside. Then export request sent with new connect command works. # usbip connect -> # usbipa (passed) Thank you, Nobuo Iwata // *** BLURB HERE *** Nobuo Iwata (11): usbip: exporting devices usbip: readme and manuals about exporting devices usbip: safe completion against usb_kill_urb() usbip: kernel module for userspace URBs transmission usbip: tools for userspace URBs transmission usbip: readme about user space URBs transmission usbip: letting send and receive replace
[PATCH v5 09/11] usbip: deriving functions as libraries
To utilize core parts of USB/IP to application protocol implementations, this patch derives libraries by exposing some functions of utilities and removing some unnecessary portions. Following functions are exposed. For command: - usbip_attach_device() - usbip_detach_port() - usbip_bind_device() - usbip_unbind_device() - usbip_list_imported_devices() : port command - usbip_list_importable_devices() : list --remote - usbip_list_devices() : list --local - usbip_connect_device() - usbip_disconnect_device() For daemon: - usbip_recv_pdu() - processes accepted a connection - usbip_break_connections() - breaks send/receive threads - usbip_driver_open() - open host or vhci driver - usbip_driver_close() - close host or vhci driver main() and option processing are removed. AS_LIBRARY macro is used to remove option processing. Following libraries are generated. - libusbip.la : for commnad - libusbipa.la : for application-side daemon - libusbipd.la : for device-side daemon Succeeding WebSocket patch uses these libraries. Signed-off-by: Nobuo Iwata --- tools/usb/usbip/libsrc/Makefile.am | 10 +-- tools/usb/usbip/src/Makefile.am| 22 +- tools/usb/usbip/src/usbip.h| 7 ++ tools/usb/usbip/src/usbip_attach.c | 14 ++-- tools/usb/usbip/src/usbip_bind.c | 6 ++ tools/usb/usbip/src/usbip_connect.c| 12 +++- tools/usb/usbip/src/usbip_detach.c | 15 ++-- tools/usb/usbip/src/usbip_disconnect.c | 12 +++- tools/usb/usbip/src/usbip_list.c | 70 +++--- tools/usb/usbip/src/usbip_netconn.c| 98 ++ tools/usb/usbip/src/usbip_network.c| 67 -- tools/usb/usbip/src/usbip_port.c | 9 ++- tools/usb/usbip/src/usbip_unbind.c | 6 ++ tools/usb/usbip/src/usbipd.c | 13 +--- tools/usb/usbip/src/usbipd.h | 38 ++ tools/usb/usbip/src/usbipd_app.c | 1 + tools/usb/usbip/src/usbipd_dev.c | 1 + 17 files changed, 274 insertions(+), 127 deletions(-) diff --git a/tools/usb/usbip/libsrc/Makefile.am b/tools/usb/usbip/libsrc/Makefile.am index 5754425..356a6c0 100644 --- a/tools/usb/usbip/libsrc/Makefile.am +++ b/tools/usb/usbip/libsrc/Makefile.am @@ -1,9 +1,9 @@ -libusbip_la_CPPFLAGS = -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' -libusbip_la_CFLAGS = @EXTRA_CFLAGS@ -libusbip_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@ +libusbiplib_la_CPPFLAGS = -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' +libusbiplib_la_CFLAGS = @EXTRA_CFLAGS@ +libusbiplib_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@ -lib_LTLIBRARIES := libusbip.la -libusbip_la_SOURCES := names.c names.h usbip_host_driver.c usbip_host_driver.h \ +lib_LTLIBRARIES := libusbiplib.la +libusbiplib_la_SOURCES := names.c names.h usbip_host_driver.c usbip_host_driver.h \ usbip_common.c usbip_common.h vhci_driver.c vhci_driver.h \ usbip_ux.c usbip_ux.h \ sysfs_utils.c sysfs_utils.h diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am index f5697c2..780bdb3 100644 --- a/tools/usb/usbip/src/Makefile.am +++ b/tools/usb/usbip/src/Makefile.am @@ -1,14 +1,32 @@ AM_CPPFLAGS = -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' AM_CFLAGS = @EXTRA_CFLAGS@ -LDADD = $(top_builddir)/libsrc/libusbip.la +LDADD = $(top_builddir)/libsrc/libusbiplib.la sbin_PROGRAMS := usbip usbipd usbipa +lib_LTLIBRARIES := libusbip.la libusbipd.la libusbipa.la -usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \ +usbip_SOURCES := usbip.h utils.h usbip.c utils.c \ +usbip_network.c usbip_netconn.c\ usbip_attach.c usbip_detach.c usbip_list.c \ usbip_bind.c usbip_unbind.c usbip_port.c \ usbip_connect.c usbip_disconnect.c +usbip_CFLAGS := $(AM_CFLAGS) usbipd_SOURCES := usbip_network.h usbipd.c usbipd_dev.c usbip_network.c +usbipd_CFLAGS := $(AM_CFLAGS) usbipa_SOURCES := usbip_network.h usbipd.c usbipd_app.c usbip_network.c +usbipa_CFLAGS := $(AM_CFLAGS) + +libusbip_la_SOURCES := utils.h utils.c usbip_network.c \ +usbip_attach.c usbip_detach.c usbip_list.c \ +usbip_bind.c usbip_unbind.c usbip_port.c \ +usbip_connect.c usbip_disconnect.c +libusbip_la_CFLAGS := $(AM_CFLAGS) -DAS_LIBRARY +libusbip_la_LDFLAGS := -version-info @LIBUSBIP_VERSION@ + +libusbipd_la_SOURCES := usbipd_dev.c usbip_network.c +libusbipd_la_LDFLAGS := -version-info @LIBUSBIP_VERSION@ + +libusbipa_la_SOURCES := usbipd_app.c usbip_network.c +libusbipa_la_LDFLAGS := -version-info @LIBUSBIP_VERSION@ diff --git a/tools/usb/usbip/src/usbip.h b/tools/usb/usbip/src/usbip.h index 0875d15..1d642cc 100644 --- a/tools/usb/usbip/src/usbip.h +++ b/tools/usb/usbip/src/usbip.h @@ -34,8 +34,15 @@ int usbip_port_show(int argc, char *argv[]); int usbip_connect(int argc, char *argv[]); int usbip_disconnect(int argc, char *argv[]); +int usbip_attach_device(char *
[PATCH v5 05/11] usbip: tools for userspace URBs transmission
Originally, USB/IP transmits requests and response PDUs for preparation to transfer URBs in user space, after completion of the preparation, URBs are transmitted in kernel space. To make easy to introduce application network protocols like WebSocket, the driver, usbip_ux.ko, forwards URBs to USB/IP user space utilities. Then, the utilities exchange URBs in userspace. To do so, tools/usb/usbip/libsrc/usbip_ux.c includes tx/rx threads to read/wite URBs from usbip_ux.ko and transfer URBs in userspace. When usbip_ux.ko is installed, /dev/usbip-ux will be found, then the threads will be started. Otherwise, threads will not be started and original kernel space transmission is valid. Signed-off-by: Nobuo Iwata --- tools/usb/usbip/libsrc/Makefile.am | 1 + tools/usb/usbip/libsrc/usbip_ux.c | 244 + tools/usb/usbip/libsrc/usbip_ux.h | 30 +++ tools/usb/usbip/libsrc/vhci_driver.c | 10 +- tools/usb/usbip/src/usbip_attach.c | 30 ++- tools/usb/usbip/src/usbip_connect.c| 18 +- tools/usb/usbip/src/usbip_disconnect.c | 11 +- tools/usb/usbip/src/usbipd.c | 5 +- tools/usb/usbip/src/usbipd_app.c | 14 ++ tools/usb/usbip/src/usbipd_dev.c | 30 ++- 10 files changed, 370 insertions(+), 23 deletions(-) diff --git a/tools/usb/usbip/libsrc/Makefile.am b/tools/usb/usbip/libsrc/Makefile.am index 7c8f8a4..5754425 100644 --- a/tools/usb/usbip/libsrc/Makefile.am +++ b/tools/usb/usbip/libsrc/Makefile.am @@ -5,4 +5,5 @@ libusbip_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@ lib_LTLIBRARIES := libusbip.la libusbip_la_SOURCES := names.c names.h usbip_host_driver.c usbip_host_driver.h \ usbip_common.c usbip_common.h vhci_driver.c vhci_driver.h \ + usbip_ux.c usbip_ux.h \ sysfs_utils.c sysfs_utils.h diff --git a/tools/usb/usbip/libsrc/usbip_ux.c b/tools/usb/usbip/libsrc/usbip_ux.c new file mode 100644 index 000..3ac45a72 --- /dev/null +++ b/tools/usb/usbip/libsrc/usbip_ux.c @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2015 Nobuo Iwata + * + * USB/IP URB transmission in userspace. + */ + +#include +#include +#include +#include +#include +#include "usbip_common.h" +#include "usbip_ux.h" + +#undef PROGNAME +#define PROGNAME "libusbip" + +#define DEVNAME "/dev/" USBIP_UX_DEV_NAME + +#define BLEN 1500 + +#ifdef DEBUG +void dump_buff(char *buff, size_t bufflen, char *label) +{ +#define DUMP_BUFF 80 +#define WORK_BUFF 16 + size_t i = 0, j; + char b[DUMP_BUFF]; + char bb[WORK_BUFF]; + + dbg("dump %s for %zd bytes", label, bufflen); + for(i=0;isockfd, buf, BLEN, 0); + if (received == 0) { + dbg("connection closed on sock:%p", ux->kaddr.sock); + break; + } else if (received < 0) { + dbg("receive error on sock:%p", ux->kaddr.sock); + break; + } + dump_buff(buf, received, "ux received"); + written = 0; + while(written < received) { + ret = write(ux->devfd, buf+written, received-written); + if (ret < 0) { + dbg("write error for sock:%p", ux->kaddr.sock); + good = 0; + break; + } + written += ret; + } + } + dbg("end of ux-rx for sock:%p", ux->kaddr.sock); + ioctl(ux->devfd, USBIP_UX_IOCINTR); + return 0; +} + +static void *usbip_ux_tx(void *arg) +{ + usbip_ux_t *ux = (usbip_ux_t*)arg; + ssize_t sent, reads; + char buf[BLEN]; + + for(;;) { + reads = read(ux->devfd, buf, BLEN); + if (reads == 0) { +#ifdef DEBUG + dbg("end of read on sock:%p continue.", ux->kaddr.sock); +#endif + sched_yield(); + continue; + } else if (reads < 0) { + dbg("read error on sock:%p", ux->kaddr.sock); + break; + } + dump_buff(buf, reads, "ux sending"); + sent = send(ux->sockfd, buf, reads, 0); + if (sent < 0) { + dbg("connection closed on sock:%p", ux->kaddr.sock); + break; + } else if (sent < reads) { + dbg("send error on sock:%p %zd < %zd", ux->kaddr.sock, + sent, reads); + break; + } + } + dbg("end of ux-tx for sock:%p", ux->kaddr.sock); + shutdown(ux->sockfd, SHUT_RDWR); + return 0; +} + +/* + * Setup user space mode. + * Null will be set in ux if usbip_ux.ko is not installed. + */ +int usbip_ux_setup(int sockfd, usbip_ux_t **uxp) +{ + usbip_ux_t *ux; + int fd, ret; + + *
[PATCH v5 10/11] usbip: added const qualifier to arguments of some functions
This patch adds 'const' qualifier to 'char*' arguments of library interfaces to make acceptable std::string.c_str(). Essentially, these qualifiers are better to be used even if not to use C++. Although, I just added to functions related to previous patch. Also, it changes C++ reserved words (ie. new and class) in list.h. Signed-off-by: Nobuo Iwata --- tools/usb/usbip/libsrc/list.h | 24 -- tools/usb/usbip/libsrc/names.c | 15 +++--- tools/usb/usbip/libsrc/usbip_common.c | 16 +++ tools/usb/usbip/libsrc/usbip_common.h | 6 +++--- tools/usb/usbip/libsrc/usbip_host_driver.c | 10 + tools/usb/usbip/libsrc/usbip_host_driver.h | 2 +- tools/usb/usbip/libsrc/vhci_driver.c | 11 ++ tools/usb/usbip/libsrc/vhci_driver.h | 6 -- tools/usb/usbip/src/usbip.h| 16 --- tools/usb/usbip/src/usbip_attach.c | 4 ++-- tools/usb/usbip/src/usbip_bind.c | 6 +++--- tools/usb/usbip/src/usbip_connect.c| 4 ++-- tools/usb/usbip/src/usbip_detach.c | 2 +- tools/usb/usbip/src/usbip_disconnect.c | 5 +++-- tools/usb/usbip/src/usbip_list.c | 7 +++ tools/usb/usbip/src/usbip_netconn.c| 2 +- tools/usb/usbip/src/usbip_network.c| 12 +++ tools/usb/usbip/src/usbip_unbind.c | 2 +- tools/usb/usbip/src/usbipd.c | 4 ++-- tools/usb/usbip/src/usbipd.h | 2 +- tools/usb/usbip/src/usbipd_app.c | 9 tools/usb/usbip/src/usbipd_dev.c | 2 +- tools/usb/usbip/src/utils.c| 2 +- tools/usb/usbip/src/utils.h| 2 +- 24 files changed, 94 insertions(+), 77 deletions(-) diff --git a/tools/usb/usbip/libsrc/list.h b/tools/usb/usbip/libsrc/list.h index 5eaaa78..b46a98f 100644 --- a/tools/usb/usbip/libsrc/list.h +++ b/tools/usb/usbip/libsrc/list.h @@ -36,14 +36,14 @@ static inline void INIT_LIST_HEAD(struct list_head *list) * This is only for internal list manipulation where we know * the prev/next entries already! */ -static inline void __list_add(struct list_head *new, +static inline void __list_add(struct list_head *neo, struct list_head *prev, struct list_head *next) { - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; + next->prev = neo; + neo->next = next; + neo->prev = prev; + prev->next = neo; } /** @@ -54,9 +54,9 @@ static inline void __list_add(struct list_head *new, * Insert a new entry after the specified head. * This is good for implementing stacks. */ -static inline void list_add(struct list_head *new, struct list_head *head) +static inline void list_add(struct list_head *neo, struct list_head *head) { - __list_add(new, head, head->next); + __list_add(neo, head, head->next); } /* @@ -73,8 +73,8 @@ static inline void __list_del(struct list_head * prev, struct list_head * next) } #define POISON_POINTER_DELTA 0 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA) -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA) +#define LIST_POISON1 ((char *) 0x00100100 + POISON_POINTER_DELTA) +#define LIST_POISON2 ((char *) 0x00200200 + POISON_POINTER_DELTA) /** * list_del - deletes entry from list. @@ -90,8 +90,8 @@ static inline void __list_del_entry(struct list_head *entry) static inline void list_del(struct list_head *entry) { __list_del(entry->prev, entry->next); - entry->next = LIST_POISON1; - entry->prev = LIST_POISON2; + entry->next = (struct list_head *)LIST_POISON1; + entry->prev = (struct list_head *)LIST_POISON2; } /** @@ -120,7 +120,9 @@ static inline void list_del(struct list_head *entry) for (pos = (head)->next, n = pos->next; pos != (head); \ pos = n, n = pos->next) +#ifndef offsetof #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif /** * container_of - cast a member of a structure out to the containing structure diff --git a/tools/usb/usbip/libsrc/names.c b/tools/usb/usbip/libsrc/names.c index 7d65d28..656005f 100644 --- a/tools/usb/usbip/libsrc/names.c +++ b/tools/usb/usbip/libsrc/names.c @@ -23,6 +23,8 @@ * * Copyright (C) 2005 Takahiro Hirofuchi * - names_deinit() is added. + * Copyright (C) 2015 Nobuo Iwata + * - some modifications for portability. * */ @@ -38,7 +40,6 @@ #include #include "names.h" -#include "usbip_common.h" struct vendor { struct vendor *next; @@ -52,8 +53,8 @@ struct product { char name[1]; }; -struct class { - struct class *next; +struct clazz { + struct clazz *next; u_int8_t classid; char name[1]; }; @@ -94,7 +95,7 @@ static unsigned int hashnum(unsigned int num) static struct vendor *vendors[HA
[PATCH v5 01/11] usbip: exporting devices
USB/IP supports a function to import USB devices from application-side machine by attach command. The usage is as following. dev:# (Physically attach your USB device.) dev:# insmod usbip-core.ko and usbip-host.ko dev:# usbipd -D // Start usbip daemon. dev:# usbip list -l // List local USB devices and their busid. dev:# usbip bind --busid // Make a device exportable to other hosts. app:# insmod usbip-core.ko and vhci-hcd.ko app:# usbip list --remote // List importable USB devices from the . app:# usbip attach --remote --busid // Import a device By attach command, connection will be established from application-side to device-side. This patch introduces a function to export devices form device-side machine to application-side machine. The usage is as following. app:# insmod usbip-core.ko and vhci-hcd.ko app:# usbipa -D // Start usbip daemon. dev:# (Physically attach your USB device.) dev:# insmod usbip-core.ko and usbip-host.ko dev:# usbip list -l // List local USB devices and their busid. dev:# usbip connect --remote --busid // Export a device to . For this, export function, connection is established from device-side machine to application-side machine. Following use cases are supposed for the export function. 1) Server application or cloud service serves distributed ubiquitous devices. 2) Dedicate devices to server application or cloud service. To connect to cloud service, it needs to connect from inside of firewall. Probably, the export function was planned because the packets have been defined in a header file (usbip_network.h) but it not yet used. This patch fixes the defined packet structures (ie. int in reply to uinit32_t) and use them. Also, vendor/product name converion is added to port commnad as same as list command. Signed-off-by: Nobuo Iwata --- tools/usb/usbip/libsrc/names.c | 4 +- tools/usb/usbip/libsrc/usbip_host_driver.c | 16 ++ tools/usb/usbip/libsrc/usbip_host_driver.h | 1 + tools/usb/usbip/libsrc/vhci_driver.c | 127 +-- tools/usb/usbip/libsrc/vhci_driver.h | 8 +- tools/usb/usbip/src/Makefile.am| 9 +- tools/usb/usbip/src/usbip.c| 17 +- tools/usb/usbip/src/usbip.h| 11 +- tools/usb/usbip/src/usbip_attach.c | 49 +--- tools/usb/usbip/src/usbip_bind.c | 7 +- tools/usb/usbip/src/usbip_connect.c| 214 ++ tools/usb/usbip/src/usbip_detach.c | 13 +- tools/usb/usbip/src/usbip_disconnect.c | 202 + tools/usb/usbip/src/usbip_list.c | 22 +- tools/usb/usbip/src/usbip_network.h| 5 +- tools/usb/usbip/src/usbip_port.c | 21 +- tools/usb/usbip/src/usbip_unbind.c | 7 +- tools/usb/usbip/src/usbipd.c | 233 +++ tools/usb/usbip/src/usbipd_app.c | 240 tools/usb/usbip/src/usbipd_dev.c | 247 + 20 files changed, 1151 insertions(+), 302 deletions(-) diff --git a/tools/usb/usbip/libsrc/names.c b/tools/usb/usbip/libsrc/names.c index 81ff852..7d65d28 100644 --- a/tools/usb/usbip/libsrc/names.c +++ b/tools/usb/usbip/libsrc/names.c @@ -162,7 +162,7 @@ struct pool { void *mem; }; -static struct pool *pool_head; +static struct pool *pool_head = NULL; static void *my_malloc(size_t size) { @@ -201,6 +201,8 @@ void names_free(void) pool = pool->next; free(tmp); } + + pool_head = NULL; } static int new_vendor(const char *name, u_int16_t vendorid) diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c index bef08d5..de5541a 100644 --- a/tools/usb/usbip/libsrc/usbip_host_driver.c +++ b/tools/usb/usbip/libsrc/usbip_host_driver.c @@ -278,3 +278,19 @@ struct usbip_exported_device *usbip_host_get_device(int num) return NULL; } + +struct usbip_exported_device *usbip_host_find_device(char *busid) +{ + struct list_head *i; + struct usbip_exported_device *edev; + + list_for_each(i, &host_driver->edev_list) { + edev = list_entry(i, struct usbip_exported_device, node); + if (!strncmp(busid, edev->udev.busid, SYSFS_BUS_ID_SIZE)) { + return edev; + } + } + + return NULL; +} + diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.h b/tools/usb/usbip/libsrc/usbip_host_driver.h index 2a31f85..69c65a6 100644 --- a/tools/usb/usbip/libsrc/usbip_host_driver.h +++ b/tools/usb/usbip/libsrc/usbip_host_driver.h @@ -45,5 +45,6 @@ void usbip_host_driver_close(void); int usbip_host_refresh_device_list(void); int usbip_host_export_device(struct usbip_exported_device *edev, int sockfd); struct usbip_exported_device *usbip_host_get_device(int num); +struct usbip_exported_device *usbip_host_find_device(char *busid); #endif /* __USBIP_HOST_DRIVER_H */ diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools
[PATCH v5 02/11] usbip: readme and manuals about exporting devices
This patch adds function and usage of export to README and manuals. The wording, 'server' and 'client' is changed also. For existing attach command, the daemon runs device side machine and attach command is executed in application side machine. Then 'server' is used for device side and 'client' is for application side. For the new connect command, the daemon runs applications side machine and connect command is executed in device side machine. Now, 'server' and 'client' run in different machine than before. So, to avoid confusion, words 'device side' and 'application side' are used instead of 'client' and 'server'. Signed-off-by: Nobuo Iwata --- tools/usb/usbip/Makefile.am | 2 +- tools/usb/usbip/README | 70 +--- tools/usb/usbip/doc/usbip.8 | 82 +--- tools/usb/usbip/doc/usbipa.8 | 77 ++ tools/usb/usbip/doc/usbipd.8 | 29 +- tools/usb/usbip/libsrc/vhci_driver.c | 2 +- 6 files changed, 205 insertions(+), 57 deletions(-) diff --git a/tools/usb/usbip/Makefile.am b/tools/usb/usbip/Makefile.am index 66f8bf0..f371ed9 100644 --- a/tools/usb/usbip/Makefile.am +++ b/tools/usb/usbip/Makefile.am @@ -3,4 +3,4 @@ includedir = @includedir@/usbip include_HEADERS := $(addprefix libsrc/, \ usbip_common.h vhci_driver.h usbip_host_driver.h) -dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8) +dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8 usbipa.8) diff --git a/tools/usb/usbip/README b/tools/usb/usbip/README index 831f49f..74f4afb 100644 --- a/tools/usb/usbip/README +++ b/tools/usb/usbip/README @@ -1,7 +1,8 @@ # # README for usbip-utils # -# Copyright (C) 2011 matt mooney +# Copyright (C) 2015 Nobuo Iwata +# 2011 matt mooney # 2005-2008 Takahiro Hirofuchi @@ -36,41 +37,70 @@ [Usage] -server:# (Physically attach your USB device.) +Device-side: a machine has USB device(s). +Application-side: a machine runs an application software uses remote USB device. -server:# insmod usbip-core.ko -server:# insmod usbip-host.ko +1) Connect from application-side to device-side. -server:# usbipd -D +dev:# (Physically attach your USB device.) + +dev:# insmod usbip-core.ko +dev:# insmod usbip-host.ko + +dev:# usbipd -D - Start usbip daemon. -server:# usbip list -l - - List driver assignments for USB devices. +dev:# usbip list -l + - List driver assignments for USB devices and their busid. -server:# usbip bind --busid 1-2 - - Bind usbip-host.ko to the device with busid 1-2. - - The USB device 1-2 is now exportable to other hosts! - - Use `usbip unbind --busid 1-2' to stop exporting the device. +dev:# usbip bind --busid + - Bind usbip-host.ko to the device with . + - The USB device with is now exportable to other hosts! + - Use `usbip unbind --busid ` to stop exporting the device. -client:# insmod usbip-core.ko -client:# insmod vhci-hcd.ko +app:# insmod usbip-core.ko +app:# insmod vhci-hcd.ko -client:# usbip list --remote +app:# usbip list --remote - List exported USB devices on the . -client:# usbip attach --remote --busid 1-2 +app:# usbip attach --remote --busid - Connect the remote USB device. -client:# usbip port +app:# usbip port - Show virtual port status. -client:# usbip detach --port +app:# usbip detach --port - Detach the USB device. +2) Connect from device-side to application-side. + +app:# insmod usbip-core.ko +app:# insmod vhci-hcd.ko + +app:# usbipa -D + - Start usbip daemon. + +dev:# (Physically attach your USB device.) + +dev:# insmod usbip-core.ko +dev:# insmod usbip-host.ko + +dev:# usbip list -l + - List driver assignments for USB devices and their busid. + +dev:# usbip connect --remote --busid + - Bind usbip-host.ko to the device with . + - The USB device of is connected to remote host! + +dev:# usbip disconnect --remote --busid + - The USB device with is disconnected from remote host. + - Unbind usbip-host.ko from the device. + [Example] --- - SERVER SIDE + DEVICE SIDE --- Physically attach your USB devices to this host. @@ -131,7 +161,7 @@ Mark the device of busid 3-3.2 as exportable: ... --- - CLIENT SIDE + APPLICATION SIDE --- First, let's list available remote devices that are marked as exportable on the host. @@ -170,7 +200,7 @@ Attach a remote USB device: deux:# usbip attach --remote 10.0.0.3 --busid 1-1 port 0 attached -Show the devices attached to this client: +Show the devices attached to this machine: deux:# usbip port Port 00: at Full Speed(12Mbps) diff --git
[PATCH v5 07/11] usbip: letting send and receive replaceable
This patch allows to substitute send, receive and shutdown routines for both a) request/response PDUs among utilities and b) user space URBs transmission. usbip_sock_t is introduced instead of sockfd. it includes function pointers of send/receive/shutdown routines, an argument for the routines, and a sockfd. The argument is needed for the routines. The sockfd is needed to bind connection to USB device. Succeeding SSL and WebSocket patch use this feature. Signed-off-by: Nobuo Iwata --- tools/usb/usbip/libsrc/usbip_common.c | 14 + tools/usb/usbip/libsrc/usbip_common.h | 14 + tools/usb/usbip/libsrc/usbip_ux.c | 24 ++-- tools/usb/usbip/libsrc/usbip_ux.h | 4 +- tools/usb/usbip/src/usbip_attach.c | 30 +- tools/usb/usbip/src/usbip_connect.c| 30 +- tools/usb/usbip/src/usbip_disconnect.c | 26 - tools/usb/usbip/src/usbip_list.c | 27 + tools/usb/usbip/src/usbip_network.c| 78 +++--- tools/usb/usbip/src/usbip_network.h| 12 ++-- tools/usb/usbip/src/usbipd.c | 14 +++-- tools/usb/usbip/src/usbipd_app.c | 36 ++-- tools/usb/usbip/src/usbipd_dev.c | 40 ++--- 13 files changed, 214 insertions(+), 135 deletions(-) diff --git a/tools/usb/usbip/libsrc/usbip_common.c b/tools/usb/usbip/libsrc/usbip_common.c index ac73710..dc0712c 100644 --- a/tools/usb/usbip/libsrc/usbip_common.c +++ b/tools/usb/usbip/libsrc/usbip_common.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2005-2007 Takahiro Hirofuchi + * Copyright (C) 2015 Nobuo Iwata */ #include @@ -283,3 +284,16 @@ void usbip_names_get_class(char *buff, size_t size, uint8_t class, snprintf(buff, size, "%s / %s / %s (%02x/%02x/%02x)", c, s, p, class, subclass, protocol); } + +void usbip_sock_init(usbip_sock_t *sock, int fd, void *arg, + ssize_t (*send)(void *arg, void *buf, size_t len), + ssize_t (*recv)(void *arg, void *buf, size_t len, int wait_all), + void (*shutdown)(void *arg)) +{ + sock->fd = fd; + sock->arg = arg; + sock->send = send; + sock->recv = recv; + sock->shutdown = shutdown; +} + diff --git a/tools/usb/usbip/libsrc/usbip_common.h b/tools/usb/usbip/libsrc/usbip_common.h index 15fe792..0dcbd99 100644 --- a/tools/usb/usbip/libsrc/usbip_common.h +++ b/tools/usb/usbip/libsrc/usbip_common.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2005-2007 Takahiro Hirofuchi + * Copyright (C) 2015 Nobuo Iwata */ #ifndef __USBIP_COMMON_H @@ -134,4 +135,17 @@ void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, void usbip_names_get_class(char *buff, size_t size, uint8_t class, uint8_t subclass, uint8_t protocol); +typedef struct usbip_sock { + int fd; + void *arg; + ssize_t (*send)(void *arg, void *buf, size_t len); + ssize_t (*recv)(void *arg, void *buf, size_t len, int wait_all); + void (*shutdown)(void *arg); +} usbip_sock_t; + +void usbip_sock_init(usbip_sock_t *sock, int fd, void *arg, + ssize_t (*send)(void *arg, void *buf, size_t len), + ssize_t (*recv)(void *arg, void *buf, size_t len, int wait_all), + void (*shutdown)(void *arg)); + #endif /* __USBIP_COMMON_H */ diff --git a/tools/usb/usbip/libsrc/usbip_ux.c b/tools/usb/usbip/libsrc/usbip_ux.c index 3ac45a72..aa3d863 100644 --- a/tools/usb/usbip/libsrc/usbip_ux.c +++ b/tools/usb/usbip/libsrc/usbip_ux.c @@ -57,7 +57,11 @@ static void *usbip_ux_rx(void *arg) char buf[BLEN]; while(good) { - received = recv(ux->sockfd, buf, BLEN, 0); + if (ux->sock->recv) { + received = ux->sock->recv(ux->sock->arg, buf, BLEN, 0); + } else { + received = recv(ux->sock->fd, buf, BLEN, 0); + } if (received == 0) { dbg("connection closed on sock:%p", ux->kaddr.sock); break; @@ -101,7 +105,11 @@ static void *usbip_ux_tx(void *arg) break; } dump_buff(buf, reads, "ux sending"); - sent = send(ux->sockfd, buf, reads, 0); + if (ux->sock->send) { + sent = ux->sock->send(ux->sock->arg, buf, reads); + } else { + sent = send(ux->sock->fd, buf, reads, 0); + } if (sent < 0) { dbg("connection closed on sock:%p", ux->kaddr.sock); break; @@ -112,7 +120,11 @@ static void *usbip_ux_tx(void *arg) } } dbg("end of ux-tx for sock:%p", ux->kaddr.sock); - shutdown(ux->sockfd, SHUT_RDWR); + if (ux->sock->shutdown) { + ux->sock->shutdown(ux->sock->arg); + } else { + shutdown(ux->sock->fd, SHUT_RDWR); + } return 0; } @@ -120,7 +132,7 @@ static void *usbip_ux_tx(void *arg) * Se
[PATCH v1 0/2] usbip: vhci number of ports extension
This series of patches extends number of ports limitaion in application (vhci) side. This series conatins 2 patches. 1/2: Extends number of ports using multiple host controllers. 'num_controllers=N' module parameter denotes the number. The default is 1. Number of ports per controller are extended from 8 to USB_MAXCHILDREN(31). It can be altered with -DVHCI_NPORTS=n at compile time. 2/2: Event handling threads are used to be created for each port. This patch aggregates them to one thread. Rewritten with workqueue. Assumed use case is a system that service in internet serves distributes devices in home or office. In the use case, application side might be needed to support more ports than 31. Home/SOHO/Enterprise Intranet/Internet ++ +--+ +--+ |Service | +|device|---|Linux |---|on | |+--+ +--+ |Linux | +--+ controller ++ ex) Device Service sensors ... environment analysis cameras ... monitoring, recording ID/biometric readers .. authentication To increase number of ports, existing implementation has an overhead that event handing kernel threads are started for each port. The second patch eliminates the overhead. NOTE: This series depends on "USB/IP over WebSocket" patches. *** BLURB HERE *** Nobuo Iwata (2): usbip: vhci number of ports extension usbip: single thread event handler drivers/usb/usbip/README | 3 + drivers/usb/usbip/stub_dev.c | 3 +- drivers/usb/usbip/usbip_common.c | 7 + drivers/usb/usbip/usbip_common.h | 4 +- drivers/usb/usbip/usbip_event.c | 174 ++--- drivers/usb/usbip/usbip_ux.c | 2 +- drivers/usb/usbip/vhci.h | 41 +- drivers/usb/usbip/vhci_hcd.c | 259 - drivers/usb/usbip/vhci_rx.c | 21 +- drivers/usb/usbip/vhci_sysfs.c | 298 +++ tools/usb/usbip/libsrc/vhci_driver.c | 548 ++- tools/usb/usbip/libsrc/vhci_driver.h | 38 +- tools/usb/usbip/src/usbip_attach.c | 8 +- tools/usb/usbip/src/usbip_port.c | 13 +- tools/usb/usbip/src/usbipd_app.c | 56 ++- 15 files changed, 916 insertions(+), 559 deletions(-) -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v1 1/2] usbip: vhci number of ports extension
This patch extends number of ports limitation in application (vhci) side. To do so, vhci driver supports multiple host controllers. The number of controllers can be specified as a module parameter 'num_controllers'. The default is 1. ex) # insmod vhci_hcd.ko num_controllers=4 Also, ports per controller is changed from 8 to USB_MAXCHILDREN (31). It can be modified with VHCI_NPORTS flag at module compilation. So number of ports supported by vhci is 'num_controllers' * 31. Sysfs structure is changes as following. BEFORE: /sys/devices/platform +-- vhci +-- status +-- attach +-- detach +-- usbip_debug AFTER: example for num_controllers=4 /sys/devices/platform +-- vhci.0 | +-- nports | +-- status.0 | +-- status.1 | +-- status.2 | +-- status.3 | +-- attach | +-- detach | +-- usbip_debug +-- vhci.1 +-- vhci.2 +-- vhci.3 vhci.N is shown for each host controller kobj. vhch.1, vhci.2, ... are shown only when num_controllers is more than 1. Only vhci.0 has user space interfaces. 'nports' is newly added to give ports-per-controller and number of controlles. Before that, number of ports is acquired by counting status lines. Status is divided for each controller to avoid page size (4KB) limitation. Variable wording relating port has been corrected. 'port' represents id across multiple controllers. 'rhport (root hub port)' represents id within a controller. Some unimportant info level messages are changed to debug level because they are too busy when using many ports. NOTE: Syslog error messages "systemd-udevd[390]: error opening USB device 'descriptors' file" may be shown. They are not caused by this patch. It seems to be a systemd problem. Signed-off-by: Nobuo Iwata --- drivers/usb/usbip/README | 3 + drivers/usb/usbip/usbip_ux.c | 2 +- drivers/usb/usbip/vhci.h | 41 +- drivers/usb/usbip/vhci_hcd.c | 259 - drivers/usb/usbip/vhci_rx.c | 21 +- drivers/usb/usbip/vhci_sysfs.c | 298 +++ tools/usb/usbip/libsrc/vhci_driver.c | 548 ++- tools/usb/usbip/libsrc/vhci_driver.h | 38 +- tools/usb/usbip/src/usbip_attach.c | 8 +- tools/usb/usbip/src/usbip_port.c | 13 +- tools/usb/usbip/src/usbipd_app.c | 56 ++- 11 files changed, 775 insertions(+), 512 deletions(-) diff --git a/drivers/usb/usbip/README b/drivers/usb/usbip/README index 41a2cf2..fce3d7f 100644 --- a/drivers/usb/usbip/README +++ b/drivers/usb/usbip/README @@ -1,3 +1,6 @@ +MODULE PARAMS: + - num_controllers : number of controllers. Default is 1. + TODO: - more discussion about the protocol - testing diff --git a/drivers/usb/usbip/usbip_ux.c b/drivers/usb/usbip/usbip_ux.c index b82b6f4..40db362 100644 --- a/drivers/usb/usbip/usbip_ux.c +++ b/drivers/usb/usbip/usbip_ux.c @@ -399,7 +399,7 @@ int usbip_ux_unlink(struct usbip_device *ud) rcu_read_lock(); ux = rcu_dereference(ud->ux); if (ux == NULL) { - pr_err("Unlink to unlinked ux.\n"); + usbip_dbg_ux("Unlink to unlinked ux.\n"); rcu_read_unlock(); return -EINVAL; } diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h index a863a98..6c34075 100644 --- a/drivers/usb/usbip/vhci.h +++ b/drivers/usb/usbip/vhci.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2003-2008 Takahiro Hirofuchi + * Copyright (C) 2015 Nobuo Iwata * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -72,7 +73,11 @@ struct vhci_unlink { }; /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */ -#define VHCI_NPORTS 8 +#ifndef VHCI_NPORTS +#define VHCI_NPORTS USB_MAXCHILDREN +#endif + +#define MAX_STATUS_NAME 16 /* for usb_bus.hcpriv */ struct vhci_hcd { @@ -93,11 +98,16 @@ struct vhci_hcd { struct vhci_device vdev[VHCI_NPORTS]; }; -extern struct vhci_hcd *the_controller; -extern const struct attribute_group dev_attr_group; +extern int num_controllers; +extern struct platform_device **the_pdevs; +extern struct attribute_group dev_attr_group; /* vhci_hcd.c */ -void rh_port_connect(int rhport, enum usb_device_speed speed); +void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed); + +/* vhci_sysfs.c */ +int vhci_init_attr_group(void); +void vhci_finish_attr_group(void); /* vhci_rx.c */ struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum); @@ -106,9 +116,14 @@ int vhci_rx_loop(void *data); /* vhci_tx.c */ int vhci_tx_loop(void *data); -static inline struct vhci_device *port_to_vdev(__u32 port) +static inline __u32 port_to_rhport(__u32 port) +{ + return port % VHCI_NPORTS; +} + +static inline int port_to_pdev_nr(__u32 port)
[PATCH v1 2/2] usbip: single thread event handler
This patch reduces number of event handling threads to one. In existing implementation, event kernel threads are created for each port. The functions of the threads are terminationg connection and error handling. It's too expensive to have to each port. With this patch, event handler is a single thread workqueue [usbip_event]. Both application (vhci) and device (stub) side are replaced. Signed-off-by: Nobuo Iwata --- drivers/usb/usbip/stub_dev.c | 3 +- drivers/usb/usbip/usbip_common.c | 7 ++ drivers/usb/usbip/usbip_common.h | 4 +- drivers/usb/usbip/usbip_event.c | 174 +++ 4 files changed, 141 insertions(+), 47 deletions(-) diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c index d8d3add..9ec002d 100644 --- a/drivers/usb/usbip/stub_dev.c +++ b/drivers/usb/usbip/stub_dev.c @@ -380,7 +380,6 @@ err_files: err_port: dev_set_drvdata(&udev->dev, NULL); usb_put_dev(udev); - kthread_stop_put(sdev->ud.eh); busid_priv->sdev = NULL; stub_device_free(sdev); @@ -441,7 +440,7 @@ static void stub_disconnect(struct usb_device *udev) } /* If usb reset is called from event handler */ - if (busid_priv->sdev->ud.eh == current) + if (usbip_in_eh(current)) return; /* shutdown the current connection */ diff --git a/drivers/usb/usbip/usbip_common.c b/drivers/usb/usbip/usbip_common.c index 963d8db..8c9fb19 100644 --- a/drivers/usb/usbip/usbip_common.c +++ b/drivers/usb/usbip/usbip_common.c @@ -807,12 +807,19 @@ EXPORT_SYMBOL_GPL(usbip_trx_ops); static int __init usbip_core_init(void) { + int ret; + pr_info(DRIVER_DESC " v" USBIP_VERSION "\n"); + ret = usbip_init_eh(); + if (ret) { + return ret; + } return 0; } static void __exit usbip_core_exit(void) { + usbip_finish_eh(); return; } diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h index 33b470c..0c72ecb 100644 --- a/drivers/usb/usbip/usbip_common.h +++ b/drivers/usb/usbip/usbip_common.h @@ -275,7 +275,6 @@ struct usbip_device { struct task_struct *tcp_tx; unsigned long event; - struct task_struct *eh; wait_queue_head_t eh_waitq; struct eh_ops { @@ -321,10 +320,13 @@ void usbip_pad_iso(struct usbip_device *ud, struct urb *urb); int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb); /* usbip_event.c */ +int usbip_init_eh(void); +void usbip_finish_eh(void); int usbip_start_eh(struct usbip_device *ud); void usbip_stop_eh(struct usbip_device *ud); void usbip_event_add(struct usbip_device *ud, unsigned long event); int usbip_event_happened(struct usbip_device *ud); +int usbip_in_eh(struct task_struct *task); static inline int interface_to_busnum(struct usb_interface *interface) { diff --git a/drivers/usb/usbip/usbip_event.c b/drivers/usb/usbip/usbip_event.c index 64933b9..22cb4d8 100644 --- a/drivers/usb/usbip/usbip_event.c +++ b/drivers/usb/usbip/usbip_event.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2003-2008 Takahiro Hirofuchi + * Copyright (C) 2015 Nobuo Iwata * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,17 +20,68 @@ #include #include +#include +#include #include "usbip_common.h" -static int event_handler(struct usbip_device *ud) +struct usbip_event { + struct list_head node; + struct usbip_device *ud; +}; + +static DEFINE_SPINLOCK(event_lock); +static LIST_HEAD(event_list); + +void set_event(struct usbip_device *ud, unsigned long event) +{ + unsigned long flags; + + spin_lock_irqsave(&ud->lock, flags); + ud->event |= event; + spin_unlock_irqrestore(&ud->lock, flags); +} + +void unset_event(struct usbip_device *ud, unsigned long event) { - usbip_dbg_eh("enter\n"); + unsigned long flags; + + spin_lock_irqsave(&ud->lock, flags); + ud->event &= ~event; + spin_unlock_irqrestore(&ud->lock, flags); +} + +static struct usbip_device *get_event(void) +{ + struct usbip_event *ue = NULL; + struct usbip_device *ud = NULL; + unsigned long flags; - /* -* Events are handled by only this thread. -*/ - while (usbip_event_happened(ud)) { + spin_lock_irqsave(&event_lock, flags); + if (!list_empty(&event_list)) { + ue = list_first_entry(&event_list, struct usbip_event, node); + list_del(&ue->node); + } + spin_unlock_irqrestore(&event_lock, flags); + + if (ue) { + ud = ue->ud; + kfree(ue); + } + return ud; +} + +struct task_struct *worker_context = NULL; + +static void event_handler(struct work_struct *work) +{ + struct usbip_device *ud; + + if (worker_context == NULL) { + worker_context = current; + } + +
Re: [PATCH 0/6] USB: mxu11x0: fixes and clean ups
On Tue, Dec 29, 2015 at 01:36:10PM +0100, Johan Hovold wrote: > Here are a few fixes and clean ups of issues found during a last review > of the new driver. > Johan Hovold (6): > USB: mxu11x0: fix memory leak in port-probe error path > USB: mxu11x0: fix memory leak on firmware download > USB: mxu11x0: fix modem-control handling on B0-transitions > USB: mxu11x0: rename usb-serial driver > USB: mxu11x0: fix debug-message typos > USB: mxu11x0: drop redundant function name from error messages > > drivers/usb/serial/mxu11x0.c | 95 > > 1 file changed, 43 insertions(+), 52 deletions(-) Now applied. Johan -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html