^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2003-2008 Takahiro Hirofuchi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "usbip_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "vhci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static void setup_cmd_submit_pdu(struct usbip_header *pdup, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct vhci_priv *priv = ((struct vhci_priv *)urb->hcpriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct vhci_device *vdev = priv->vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) usbip_dbg_vhci_tx("URB, local devnum %u, remote devid %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) usb_pipedevice(urb->pipe), vdev->devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) pdup->base.command = USBIP_CMD_SUBMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) pdup->base.seqnum = priv->seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) pdup->base.devid = vdev->devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) pdup->base.direction = usb_pipein(urb->pipe) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) USBIP_DIR_IN : USBIP_DIR_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) pdup->base.ep = usb_pipeendpoint(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) usbip_pack_pdu(pdup, urb, USBIP_CMD_SUBMIT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if (urb->setup_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) memcpy(pdup->u.cmd_submit.setup, urb->setup_packet, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static struct vhci_priv *dequeue_from_priv_tx(struct vhci_device *vdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct vhci_priv *priv, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) spin_lock_irqsave(&vdev->priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) list_for_each_entry_safe(priv, tmp, &vdev->priv_tx, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) list_move_tail(&priv->list, &vdev->priv_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) spin_unlock_irqrestore(&vdev->priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) spin_unlock_irqrestore(&vdev->priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static int vhci_send_cmd_submit(struct vhci_device *vdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct usbip_iso_packet_descriptor *iso_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct vhci_priv *priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct msghdr msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct kvec *iov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) size_t txsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) size_t total_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int iovnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) while ((priv = dequeue_from_priv_tx(vdev)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct urb *urb = priv->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct usbip_header pdu_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) txsize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) memset(&pdu_header, 0, sizeof(pdu_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) memset(&msg, 0, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) memset(&iov, 0, sizeof(iov));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) usbip_dbg_vhci_tx("setup txdata urb seqnum %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) priv->seqnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (urb->num_sgs && usb_pipeout(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) iovnum = 2 + urb->num_sgs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) iovnum = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) iov = kcalloc(iovnum, sizeof(*iov), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (!iov) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) usbip_event_add(&vdev->ud, SDEV_EVENT_ERROR_MALLOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (urb->num_sgs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) urb->transfer_flags |= URB_DMA_MAP_SG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* 1. setup usbip_header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) setup_cmd_submit_pdu(&pdu_header, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) usbip_header_correct_endian(&pdu_header, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) iovnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) iov[iovnum].iov_base = &pdu_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) iov[iovnum].iov_len = sizeof(pdu_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) txsize += sizeof(pdu_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) iovnum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* 2. setup transfer buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!usb_pipein(urb->pipe) && urb->transfer_buffer_length > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (urb->num_sgs &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) !usb_endpoint_xfer_isoc(&urb->ep->desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) for_each_sg(urb->sg, sg, urb->num_sgs, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) iov[iovnum].iov_base = sg_virt(sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) iov[iovnum].iov_len = sg->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) iovnum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) iov[iovnum].iov_base = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) iov[iovnum].iov_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) iovnum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) txsize += urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* 3. setup iso_packet_descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ssize_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) iso_buffer = usbip_alloc_iso_desc_pdu(urb, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!iso_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) usbip_event_add(&vdev->ud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) SDEV_EVENT_ERROR_MALLOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto err_iso_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) iov[iovnum].iov_base = iso_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) iov[iovnum].iov_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) iovnum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) txsize += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ret = kernel_sendmsg(vdev->ud.tcp_socket, &msg, iov, iovnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) txsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (ret != txsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) pr_err("sendmsg failed!, ret=%d for %zd\n", ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) txsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_TCP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) goto err_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) kfree(iov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* This is only for isochronous case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) kfree(iso_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) iso_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) usbip_dbg_vhci_tx("send txdata\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) total_size += txsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return total_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) err_tx:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) kfree(iso_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) err_iso_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) kfree(iov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static struct vhci_unlink *dequeue_from_unlink_tx(struct vhci_device *vdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct vhci_unlink *unlink, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) spin_lock_irqsave(&vdev->priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) list_move_tail(&unlink->list, &vdev->unlink_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) spin_unlock_irqrestore(&vdev->priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return unlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) spin_unlock_irqrestore(&vdev->priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int vhci_send_cmd_unlink(struct vhci_device *vdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct vhci_unlink *unlink = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct msghdr msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct kvec iov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) size_t txsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) size_t total_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) while ((unlink = dequeue_from_unlink_tx(vdev)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct usbip_header pdu_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) memset(&pdu_header, 0, sizeof(pdu_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) memset(&msg, 0, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) memset(&iov, 0, sizeof(iov));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) usbip_dbg_vhci_tx("setup cmd unlink, %lu\n", unlink->seqnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* 1. setup usbip_header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) pdu_header.base.command = USBIP_CMD_UNLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pdu_header.base.seqnum = unlink->seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) pdu_header.base.devid = vdev->devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pdu_header.base.ep = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) pdu_header.u.cmd_unlink.seqnum = unlink->unlink_seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) usbip_header_correct_endian(&pdu_header, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) iov.iov_base = &pdu_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) iov.iov_len = sizeof(pdu_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) txsize = sizeof(pdu_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ret = kernel_sendmsg(vdev->ud.tcp_socket, &msg, &iov, 1, txsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (ret != txsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) pr_err("sendmsg failed!, ret=%d for %zd\n", ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) txsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_TCP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) usbip_dbg_vhci_tx("send txdata\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) total_size += txsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return total_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int vhci_tx_loop(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct usbip_device *ud = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct vhci_device *vdev = container_of(ud, struct vhci_device, ud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (vhci_send_cmd_submit(vdev) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (vhci_send_cmd_unlink(vdev) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) wait_event_interruptible(vdev->waitq_tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) (!list_empty(&vdev->priv_tx) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) !list_empty(&vdev->unlink_tx) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) kthread_should_stop()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) usbip_dbg_vhci_tx("pending urbs ?, now wake up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }