Release 4.16 drivers/usb/usbip/vhci_rx.c
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2003-2008 Takahiro Hirofuchi
*/
#include <linux/kthread.h>
#include <linux/slab.h>
#include "usbip_common.h"
#include "vhci.h"
/* get URB from transmitted urb queue. caller must hold vdev->priv_lock */
struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum)
{
struct vhci_priv *priv, *tmp;
struct urb *urb = NULL;
int status;
list_for_each_entry_safe(priv, tmp, &vdev->priv_rx, list) {
if (priv->seqnum != seqnum)
continue;
urb = priv->urb;
status = urb->status;
usbip_dbg_vhci_rx("find urb seqnum %u\n", seqnum);
switch (status) {
case -ENOENT:
/* fall through */
case -ECONNRESET:
dev_dbg(&urb->dev->dev,
"urb seq# %u was unlinked %ssynchronously\n",
seqnum, status == -ENOENT ? "" : "a");
break;
case -EINPROGRESS:
/* no info output */
break;
default:
dev_dbg(&urb->dev->dev,
"urb seq# %u may be in a error, status %d\n",
seqnum, status);
}
list_del(&priv->list);
kfree(priv);
urb->hcpriv = NULL;
break;
}
return urb;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Takahiro Hirofuchi | 134 | 84.81% | 1 | 20.00% |
Stefan Reif | 16 | 10.13% | 1 | 20.00% |
Shuah Khan | 6 | 3.80% | 1 | 20.00% |
Brian G. Merrell | 1 | 0.63% | 1 | 20.00% |
Colin Ian King | 1 | 0.63% | 1 | 20.00% |
Total | 158 | 100.00% | 5 | 100.00% |
static void vhci_recv_ret_submit(struct vhci_device *vdev,
struct usbip_header *pdu)
{
struct vhci_hcd *vhci_hcd = vdev_to_vhci_hcd(vdev);
struct vhci *vhci = vhci_hcd->vhci;
struct usbip_device *ud = &vdev->ud;
struct urb *urb;
unsigned long flags;
spin_lock_irqsave(&vdev->priv_lock, flags);
urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum);
spin_unlock_irqrestore(&vdev->priv_lock, flags);
if (!urb) {
pr_err("cannot find a urb of seqnum %u max seqnum %d\n",
pdu->base.seqnum,
atomic_read(&vhci_hcd->seqnum));
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
return;
}
/* unpack the pdu to a urb */
usbip_pack_pdu(pdu, urb, USBIP_RET_SUBMIT, 0);
/* recv transfer buffer */
if (usbip_recv_xbuff(ud, urb) < 0)
return;
/* recv iso_packet_descriptor */
if (usbip_recv_iso(ud, urb) < 0)
return;
/* restore the padding in iso packets */
usbip_pad_iso(ud, urb);
if (usbip_dbg_flag_vhci_rx)
usbip_dump_urb(urb);
usbip_dbg_vhci_rx("now giveback urb %u\n", pdu->base.seqnum);
spin_lock_irqsave(&vhci->lock, flags);
usb_hcd_unlink_urb_from_ep(vhci_hcd_to_hcd(vhci_hcd), urb);
spin_unlock_irqrestore(&vhci->lock, flags);
usb_hcd_giveback_urb(vhci_hcd_to_hcd(vhci_hcd), urb, urb->status);
usbip_dbg_vhci_rx("Leave\n");
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Takahiro Hirofuchi | 161 | 68.22% | 1 | 9.09% |
Andrew Goodbody | 16 | 6.78% | 1 | 9.09% |
Yuyang Du | 16 | 6.78% | 2 | 18.18% |
Max Vozeler | 14 | 5.93% | 1 | 9.09% |
Nobuo Iwata | 10 | 4.24% | 1 | 9.09% |
Arjan Mels | 7 | 2.97% | 1 | 9.09% |
Shuah Khan | 7 | 2.97% | 1 | 9.09% |
Brian G. Merrell | 3 | 1.27% | 1 | 9.09% |
Bart Westgeest | 1 | 0.42% | 1 | 9.09% |
Matt Mooney | 1 | 0.42% | 1 | 9.09% |
Total | 236 | 100.00% | 11 | 100.00% |
static struct vhci_unlink *dequeue_pending_unlink(struct vhci_device *vdev,
struct usbip_header *pdu)
{
struct vhci_unlink *unlink, *tmp;
unsigned long flags;
spin_lock_irqsave(&vdev->priv_lock, flags);
list_for_each_entry_safe(unlink, tmp, &vdev->unlink_rx, list) {
pr_info("unlink->seqnum %lu\n", unlink->seqnum);
if (unlink->seqnum == pdu->base.seqnum) {
usbip_dbg_vhci_rx("found pending unlink, %lu\n",
unlink->seqnum);
list_del(&unlink->list);
spin_unlock_irqrestore(&vdev->priv_lock, flags);
return unlink;
}
}
spin_unlock_irqrestore(&vdev->priv_lock, flags);
return NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Takahiro Hirofuchi | 103 | 87.29% | 1 | 25.00% |
Andrew Goodbody | 13 | 11.02% | 1 | 25.00% |
Matt Mooney | 1 | 0.85% | 1 | 25.00% |
Brian G. Merrell | 1 | 0.85% | 1 | 25.00% |
Total | 118 | 100.00% | 4 | 100.00% |
static void vhci_recv_ret_unlink(struct vhci_device *vdev,
struct usbip_header *pdu)
{
struct vhci_hcd *vhci_hcd = vdev_to_vhci_hcd(vdev);
struct vhci *vhci = vhci_hcd->vhci;
struct vhci_unlink *unlink;
struct urb *urb;
unsigned long flags;
usbip_dump_header(pdu);
unlink = dequeue_pending_unlink(vdev, pdu);
if (!unlink) {
pr_info("cannot find the pending unlink %u\n",
pdu->base.seqnum);
return;
}
spin_lock_irqsave(&vdev->priv_lock, flags);
urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum);
spin_unlock_irqrestore(&vdev->priv_lock, flags);
if (!urb) {
/*
* I get the result of a unlink request. But, it seems that I
* already received the result of its submit result and gave
* back the URB.
*/
pr_info("the urb (seqnum %d) was already given back\n",
pdu->base.seqnum);
} else {
usbip_dbg_vhci_rx("now giveback urb %d\n", pdu->base.seqnum);
/* If unlink is successful, status is -ECONNRESET */
urb->status = pdu->u.ret_unlink.status;
pr_info("urb->status %d\n", urb->status);
spin_lock_irqsave(&vhci->lock, flags);
usb_hcd_unlink_urb_from_ep(vhci_hcd_to_hcd(vhci_hcd), urb);
spin_unlock_irqrestore(&vhci->lock, flags);
usb_hcd_giveback_urb(vhci_hcd_to_hcd(vhci_hcd), urb, urb->status);
}
kfree(unlink);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Takahiro Hirofuchi | 149 | 68.66% | 1 | 9.09% |
Andrew Goodbody | 16 | 7.37% | 1 | 9.09% |
Yuyang Du | 15 | 6.91% | 2 | 18.18% |
Max Vozeler | 14 | 6.45% | 1 | 9.09% |
Nobuo Iwata | 10 | 4.61% | 1 | 9.09% |
Shuah Khan | 6 | 2.76% | 1 | 9.09% |
Matt Mooney | 4 | 1.84% | 1 | 9.09% |
Brian G. Merrell | 1 | 0.46% | 1 | 9.09% |
Christopher Harvey | 1 | 0.46% | 1 | 9.09% |
Bart Westgeest | 1 | 0.46% | 1 | 9.09% |
Total | 217 | 100.00% | 11 | 100.00% |
static int vhci_priv_tx_empty(struct vhci_device *vdev)
{
int empty = 0;
unsigned long flags;
spin_lock_irqsave(&vdev->priv_lock, flags);
empty = list_empty(&vdev->priv_rx);
spin_unlock_irqrestore(&vdev->priv_lock, flags);
return empty;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Max Vozeler | 43 | 81.13% | 1 | 50.00% |
Andrew Goodbody | 10 | 18.87% | 1 | 50.00% |
Total | 53 | 100.00% | 2 | 100.00% |
/* recv a pdu */
static void vhci_rx_pdu(struct usbip_device *ud)
{
int ret;
struct usbip_header pdu;
struct vhci_device *vdev = container_of(ud, struct vhci_device, ud);
usbip_dbg_vhci_rx("Enter\n");
memset(&pdu, 0, sizeof(pdu));
/* receive a pdu header */
ret = usbip_recv(ud->tcp_socket, &pdu, sizeof(pdu));
if (ret < 0) {
if (ret == -ECONNRESET)
pr_info("connection reset by peer\n");
else if (ret == -EAGAIN) {
/* ignore if connection was idle */
if (vhci_priv_tx_empty(vdev))
return;
pr_info("connection timed out with pending urbs\n");
} else if (ret != -ERESTARTSYS)
pr_info("xmit failed %d\n", ret);
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
return;
}
if (ret == 0) {
pr_info("connection closed");
usbip_event_add(ud, VDEV_EVENT_DOWN);
return;
}
if (ret != sizeof(pdu)) {
pr_err("received pdu size is %d, should be %d\n", ret,
(unsigned int)sizeof(pdu));
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
return;
}
usbip_header_correct_endian(&pdu, 0);
if (usbip_dbg_flag_vhci_rx)
usbip_dump_header(&pdu);
switch (pdu.base.command) {
case USBIP_RET_SUBMIT:
vhci_recv_ret_submit(vdev, &pdu);
break;
case USBIP_RET_UNLINK:
vhci_recv_ret_unlink(vdev, &pdu);
break;
default:
/* NOT REACHED */
pr_err("unknown pdu %u\n", pdu.base.command);
usbip_dump_header(&pdu);
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
break;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Takahiro Hirofuchi | 170 | 62.73% | 1 | 11.11% |
Max Vozeler | 85 | 31.37% | 2 | 22.22% |
Matt Mooney | 8 | 2.95% | 2 | 22.22% |
Greg Kroah-Hartman | 4 | 1.48% | 1 | 11.11% |
Brian G. Merrell | 2 | 0.74% | 1 | 11.11% |
Bart Westgeest | 1 | 0.37% | 1 | 11.11% |
Kurt Kanzenbach | 1 | 0.37% | 1 | 11.11% |
Total | 271 | 100.00% | 9 | 100.00% |
int vhci_rx_loop(void *data)
{
struct usbip_device *ud = data;
while (!kthread_should_stop()) {
if (usbip_event_happened(ud))
break;
vhci_rx_pdu(ud);
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Takahiro Hirofuchi | 29 | 72.50% | 1 | 33.33% |
Arnd Bergmann | 10 | 25.00% | 1 | 33.33% |
Brian G. Merrell | 1 | 2.50% | 1 | 33.33% |
Total | 40 | 100.00% | 3 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Takahiro Hirofuchi | 753 | 67.90% | 1 | 3.85% |
Max Vozeler | 157 | 14.16% | 3 | 11.54% |
Andrew Goodbody | 55 | 4.96% | 1 | 3.85% |
Yuyang Du | 31 | 2.80% | 2 | 7.69% |
Nobuo Iwata | 20 | 1.80% | 1 | 3.85% |
Shuah Khan | 19 | 1.71% | 1 | 3.85% |
Stefan Reif | 16 | 1.44% | 1 | 3.85% |
Matt Mooney | 16 | 1.44% | 3 | 11.54% |
Arnd Bergmann | 12 | 1.08% | 1 | 3.85% |
Brian G. Merrell | 9 | 0.81% | 1 | 3.85% |
Arjan Mels | 7 | 0.63% | 1 | 3.85% |
Greg Kroah-Hartman | 6 | 0.54% | 3 | 11.54% |
Bart Westgeest | 3 | 0.27% | 3 | 11.54% |
Tejun Heo | 2 | 0.18% | 1 | 3.85% |
Kurt Kanzenbach | 1 | 0.09% | 1 | 3.85% |
Colin Ian King | 1 | 0.09% | 1 | 3.85% |
Christopher Harvey | 1 | 0.09% | 1 | 3.85% |
Total | 1109 | 100.00% | 26 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.