^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) 2015 Karol Kosik <karo9@interia.eu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2015-2016 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Igor Kotrasinski <i.kotrasinsk@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Krzysztof Opasiak <k.opasiak@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/usb/gadget.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/usb/ch9.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/byteorder/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "usbip_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "vudc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* called with udc->lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int get_gadget_descs(struct vudc *udc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct vrequest *usb_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct vep *ep0 = to_vep(udc->gadget.ep0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct usb_device_descriptor *ddesc = &udc->dev_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct usb_ctrlrequest req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (!udc->driver || !udc->pullup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) req.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) req.bRequest = USB_REQ_GET_DESCRIPTOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) req.wValue = cpu_to_le16(USB_DT_DEVICE << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) req.wIndex = cpu_to_le16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) req.wLength = cpu_to_le16(sizeof(*ddesc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) spin_unlock(&udc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ret = udc->driver->setup(&(udc->gadget), &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) spin_lock(&udc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* assuming request queue is empty; request is now on top */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) usb_req = list_last_entry(&ep0->req_queue, struct vrequest, req_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) list_del(&usb_req->req_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (usb_req->req.length > sizeof(*ddesc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ret = -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) goto giveback_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) memcpy(ddesc, usb_req->req.buf, sizeof(*ddesc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) udc->desc_cached = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) giveback_req:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) usb_req->req.status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) usb_req->req.actual = usb_req->req.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) usb_gadget_giveback_request(&(ep0->ep), &(usb_req->req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * Exposes device descriptor from the gadget driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static ssize_t dev_desc_read(struct file *file, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct bin_attribute *attr, char *out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) loff_t off, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct device *dev = kobj_to_dev(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct vudc *udc = (struct vudc *)dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) char *desc_ptr = (char *) &udc->dev_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) spin_lock_irqsave(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (!udc->desc_cached) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) memcpy(out, desc_ptr + off, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) spin_unlock_irqrestore(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static BIN_ATTR_RO(dev_desc, sizeof(struct usb_device_descriptor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static ssize_t usbip_sockfd_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) const char *in, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct vudc *udc = (struct vudc *) dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int sockfd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct socket *socket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct task_struct *tcp_rx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct task_struct *tcp_tx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) rv = kstrtoint(in, 0, &sockfd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (rv != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (!udc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) dev_err(dev, "no device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) mutex_lock(&udc->ud.sysfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) spin_lock_irqsave(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* Don't export what we don't have */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!udc->driver || !udc->pullup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dev_err(dev, "gadget not bound");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (sockfd != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (udc->connected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) dev_err(dev, "Device already connected");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) spin_lock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (udc->ud.status != SDEV_ST_AVAILABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) goto unlock_ud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) socket = sockfd_lookup(sockfd, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!socket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) dev_err(dev, "failed to lookup sock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) goto unlock_ud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (socket->type != SOCK_STREAM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) dev_err(dev, "Expecting SOCK_STREAM - found %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) socket->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) goto sock_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* unlock and create threads and get tasks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) spin_unlock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) spin_unlock_irqrestore(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) tcp_rx = kthread_create(&v_rx_loop, &udc->ud, "vudc_rx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (IS_ERR(tcp_rx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) sockfd_put(socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) mutex_unlock(&udc->ud.sysfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) tcp_tx = kthread_create(&v_tx_loop, &udc->ud, "vudc_tx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (IS_ERR(tcp_tx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) kthread_stop(tcp_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) sockfd_put(socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) mutex_unlock(&udc->ud.sysfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* get task structs now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) get_task_struct(tcp_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) get_task_struct(tcp_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* lock and update udc->ud state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) spin_lock_irqsave(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) spin_lock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) udc->ud.tcp_socket = socket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) udc->ud.tcp_rx = tcp_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) udc->ud.tcp_tx = tcp_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) udc->ud.status = SDEV_ST_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) spin_unlock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ktime_get_ts64(&udc->start_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) v_start_timer(udc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) udc->connected = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) spin_unlock_irqrestore(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) wake_up_process(udc->ud.tcp_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) wake_up_process(udc->ud.tcp_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) mutex_unlock(&udc->ud.sysfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!udc->connected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dev_err(dev, "Device not connected");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) spin_lock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (udc->ud.status != SDEV_ST_USED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) goto unlock_ud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) spin_unlock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) usbip_event_add(&udc->ud, VUDC_EVENT_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) spin_unlock_irqrestore(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) mutex_unlock(&udc->ud.sysfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) sock_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) sockfd_put(socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) unlock_ud:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) spin_unlock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) spin_unlock_irqrestore(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) mutex_unlock(&udc->ud.sysfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static DEVICE_ATTR_WO(usbip_sockfd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static ssize_t usbip_status_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct device_attribute *attr, char *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct vudc *udc = (struct vudc *) dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (!udc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) dev_err(dev, "no device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) spin_lock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) status = udc->ud.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) spin_unlock_irq(&udc->ud.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return snprintf(out, PAGE_SIZE, "%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static DEVICE_ATTR_RO(usbip_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static struct attribute *dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) &dev_attr_usbip_sockfd.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) &dev_attr_usbip_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) NULL,
^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) static struct bin_attribute *dev_bin_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) &bin_attr_dev_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static const struct attribute_group vudc_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) .attrs = dev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .bin_attrs = dev_bin_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) const struct attribute_group *vudc_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) &vudc_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };