Release 4.7 drivers/usb/usbip/vhci_rx.c
/*
* Copyright (C) 2003-2008 Takahiro Hirofuchi
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
#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 %p vurb %p seqnum %u\n",
urb, priv, seqnum);
switch (status) {
case -ENOENT:
/* fall through */
case -ECONNRESET:
dev_info(&urb->dev->dev,
"urb %p was unlinked %ssynchronuously.\n", urb,
status == -ENOENT ? "" : "a");
break;
case -EINPROGRESS:
/* no info output */
break;
default:
dev_info(&urb->dev->dev,
"urb %p may be in a error, status %d\n", urb,
status);
}
list_del(&priv->list);
kfree(priv);
urb->hcpriv = NULL;
break;
}
return urb;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
takahiro hirofuchi | takahiro hirofuchi | 143 | 88.27% | 1 | 33.33% |
stefan reif | stefan reif | 18 | 11.11% | 1 | 33.33% |
brian g. merrell | brian g. merrell | 1 | 0.62% | 1 | 33.33% |
| Total | 162 | 100.00% | 3 | 100.00% |
static void vhci_recv_ret_submit(struct vhci_device *vdev,
struct usbip_header *pdu)
{
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\n", pdu->base.seqnum);
pr_info("max seqnum %d\n",
atomic_read(&the_controller->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 %p\n", urb);
spin_lock_irqsave(&the_controller->lock, flags);
usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb);
spin_unlock_irqrestore(&the_controller->lock, flags);
usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status);
usbip_dbg_vhci_rx("Leave\n");
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
takahiro hirofuchi | takahiro hirofuchi | 175 | 80.28% | 1 | 14.29% |
andrew goodbody | andrew goodbody | 16 | 7.34% | 1 | 14.29% |
max vozeler | max vozeler | 14 | 6.42% | 1 | 14.29% |
arjan mels | arjan mels | 7 | 3.21% | 1 | 14.29% |
brian g. merrell | brian g. merrell | 3 | 1.38% | 1 | 14.29% |
matt mooney | matt mooney | 2 | 0.92% | 1 | 14.29% |
bart westgeest | bart westgeest | 1 | 0.46% | 1 | 14.29% |
| Total | 218 | 100.00% | 7 | 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 | takahiro hirofuchi | 103 | 87.29% | 1 | 25.00% |
andrew goodbody | andrew goodbody | 13 | 11.02% | 1 | 25.00% |
brian g. merrell | brian g. merrell | 1 | 0.85% | 1 | 25.00% |
matt mooney | matt mooney | 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_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 %p\n", urb);
/* 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(&the_controller->lock, flags);
usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb);
spin_unlock_irqrestore(&the_controller->lock, flags);
usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
urb->status);
}
kfree(unlink);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
takahiro hirofuchi | takahiro hirofuchi | 157 | 80.93% | 1 | 14.29% |
andrew goodbody | andrew goodbody | 16 | 8.25% | 1 | 14.29% |
max vozeler | max vozeler | 14 | 7.22% | 1 | 14.29% |
matt mooney | matt mooney | 4 | 2.06% | 1 | 14.29% |
bart westgeest | bart westgeest | 1 | 0.52% | 1 | 14.29% |
brian g. merrell | brian g. merrell | 1 | 0.52% | 1 | 14.29% |
christopher harvey | christopher harvey | 1 | 0.52% | 1 | 14.29% |
| Total | 194 | 100.00% | 7 | 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 | max vozeler | 43 | 81.13% | 1 | 50.00% |
andrew goodbody | 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 | takahiro hirofuchi | 170 | 62.73% | 1 | 11.11% |
max vozeler | max vozeler | 85 | 31.37% | 2 | 22.22% |
matt mooney | matt mooney | 8 | 2.95% | 2 | 22.22% |
greg kroah-hartman | greg kroah-hartman | 4 | 1.48% | 1 | 11.11% |
brian g. merrell | brian g. merrell | 2 | 0.74% | 1 | 11.11% |
kurt kanzenbach | kurt kanzenbach | 1 | 0.37% | 1 | 11.11% |
bart westgeest | bart westgeest | 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 | takahiro hirofuchi | 29 | 72.50% | 1 | 33.33% |
arnd bergmann | arnd bergmann | 10 | 25.00% | 1 | 33.33% |
brian g. merrell | 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 | takahiro hirofuchi | 785 | 73.30% | 1 | 5.26% |
max vozeler | max vozeler | 157 | 14.66% | 3 | 15.79% |
andrew goodbody | andrew goodbody | 55 | 5.14% | 1 | 5.26% |
stefan reif | stefan reif | 18 | 1.68% | 1 | 5.26% |
matt mooney | matt mooney | 17 | 1.59% | 3 | 15.79% |
arnd bergmann | arnd bergmann | 12 | 1.12% | 1 | 5.26% |
brian g. merrell | brian g. merrell | 9 | 0.84% | 1 | 5.26% |
arjan mels | arjan mels | 7 | 0.65% | 1 | 5.26% |
greg kroah-hartman | greg kroah-hartman | 4 | 0.37% | 1 | 5.26% |
bart westgeest | bart westgeest | 3 | 0.28% | 3 | 15.79% |
tejun heo | tejun heo | 2 | 0.19% | 1 | 5.26% |
kurt kanzenbach | kurt kanzenbach | 1 | 0.09% | 1 | 5.26% |
christopher harvey | christopher harvey | 1 | 0.09% | 1 | 5.26% |
| Total | 1071 | 100.00% | 19 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.