Lines Matching refs:ffs

47 static void ffs_data_get(struct ffs_data *ffs);
48 static void ffs_data_put(struct ffs_data *ffs);
54 static void ffs_data_opened(struct ffs_data *ffs);
55 static void ffs_data_closed(struct ffs_data *ffs);
59 __ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len);
61 __ffs_data_got_strings(struct ffs_data *ffs, char *data, size_t len);
71 struct ffs_data *ffs; member
88 ffs_setup_state_clear_cancelled(struct ffs_data *ffs) in ffs_setup_state_clear_cancelled() argument
91 cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP); in ffs_setup_state_clear_cancelled()
131 struct ffs_data *ffs; member
227 struct ffs_data *ffs; member
234 struct ffs_data *ffs; member
239 static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
256 static int ffs_ready(struct ffs_data *ffs);
257 static void ffs_closed(struct ffs_data *ffs);
271 struct ffs_data *ffs = req->context; in ffs_ep0_complete() local
273 complete(&ffs->ep0req_completion); in ffs_ep0_complete()
276 static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) in __ffs_ep0_queue_wait() argument
277 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_queue_wait()
279 struct usb_request *req = ffs->ep0req; in __ffs_ep0_queue_wait()
285 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
287 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
300 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
302 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
306 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
308 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
312 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
316 static int __ffs_ep0_stall(struct ffs_data *ffs) in __ffs_ep0_stall() argument
318 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
320 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
321 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
332 struct ffs_data *ffs = file->private_data; in ffs_ep0_write() local
339 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_write()
343 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
348 switch (ffs->state) { in ffs_ep0_write()
364 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
366 ret = __ffs_data_got_descs(ffs, data, len); in ffs_ep0_write()
370 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
374 ret = __ffs_data_got_strings(ffs, data, len); in ffs_ep0_write()
378 ret = ffs_epfiles_create(ffs); in ffs_ep0_write()
380 ffs->state = FFS_CLOSING; in ffs_ep0_write()
384 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
385 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
387 ret = ffs_ready(ffs); in ffs_ep0_write()
389 ffs->state = FFS_CLOSING; in ffs_ep0_write()
403 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
404 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_write()
418 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
419 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
420 ret = __ffs_ep0_stall(ffs); in ffs_ep0_write()
425 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
427 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
435 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
449 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_write()
453 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
456 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_write()
466 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
471 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, in __ffs_ep0_read_events() argument
473 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
480 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
487 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
489 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
490 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
494 ffs->ev.count -= n; in __ffs_ep0_read_events()
495 if (ffs->ev.count) in __ffs_ep0_read_events()
496 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
497 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
499 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
500 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
508 struct ffs_data *ffs = file->private_data; in ffs_ep0_read() local
516 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_read()
520 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
525 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
534 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
536 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_read()
548 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
553 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
554 ffs->ev.count)) { in ffs_ep0_read()
560 return __ffs_ep0_read_events(ffs, buf, in ffs_ep0_read()
561 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
564 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
565 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
566 ret = __ffs_ep0_stall(ffs); in ffs_ep0_read()
570 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
572 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
582 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
585 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_read()
592 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_read()
602 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
604 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
611 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open() local
615 if (ffs->state == FFS_CLOSING) in ffs_ep0_open()
618 file->private_data = ffs; in ffs_ep0_open()
619 ffs_data_opened(ffs); in ffs_ep0_open()
626 struct ffs_data *ffs = file->private_data; in ffs_ep0_release() local
630 ffs_data_closed(ffs); in ffs_ep0_release()
637 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl() local
638 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
644 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
657 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll() local
661 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
663 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
667 switch (ffs->state) { in ffs_ep0_poll()
674 switch (ffs->setup_state) { in ffs_ep0_poll()
676 if (ffs->ev.count) in ffs_ep0_poll()
693 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
843 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
844 eventfd_signal(io_data->ffs->ffs_eventfd, 1); in ffs_user_copy_worker()
858 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete() local
863 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
958 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
968 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_io()
1005 gadget = epfile->ffs->gadget; in ffs_epfile_io()
1007 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1022 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1036 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1083 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1086 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1098 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1127 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1148 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1164 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1168 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
1182 spin_lock_irqsave(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1189 spin_unlock_irqrestore(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1288 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1302 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1312 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_ioctl()
1317 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1321 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1344 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1359 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1368 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1429 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file() local
1439 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1467 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill() local
1471 ffs->sb = sb; in ffs_sb_fill()
1473 sb->s_fs_info = ffs; in ffs_sb_fill()
1491 if (!ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations)) in ffs_sb_fill()
1570 struct ffs_data *ffs; in ffs_fs_get_tree() local
1578 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
1579 if (!ffs) in ffs_fs_get_tree()
1581 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
1582 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
1584 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
1585 if (!ffs->dev_name) { in ffs_fs_get_tree()
1586 ffs_data_put(ffs); in ffs_fs_get_tree()
1590 ret = ffs_acquire_dev(ffs->dev_name, ffs); in ffs_fs_get_tree()
1592 ffs_data_put(ffs); in ffs_fs_get_tree()
1596 ctx->ffs_data = ffs; in ffs_fs_get_tree()
1686 static void ffs_data_clear(struct ffs_data *ffs);
1687 static void ffs_data_reset(struct ffs_data *ffs);
1689 static void ffs_data_get(struct ffs_data *ffs) in ffs_data_get() argument
1693 refcount_inc(&ffs->ref); in ffs_data_get()
1696 static void ffs_data_opened(struct ffs_data *ffs) in ffs_data_opened() argument
1700 refcount_inc(&ffs->ref); in ffs_data_opened()
1701 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1702 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1703 ffs->state = FFS_CLOSING; in ffs_data_opened()
1704 ffs_data_reset(ffs); in ffs_data_opened()
1708 static void ffs_data_put(struct ffs_data *ffs) in ffs_data_put() argument
1712 if (refcount_dec_and_test(&ffs->ref)) { in ffs_data_put()
1714 ffs_data_clear(ffs); in ffs_data_put()
1715 ffs_release_dev(ffs->private_data); in ffs_data_put()
1716 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1717 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1718 waitqueue_active(&ffs->wait)); in ffs_data_put()
1719 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1720 kfree(ffs->dev_name); in ffs_data_put()
1721 kfree(ffs); in ffs_data_put()
1725 static void ffs_data_closed(struct ffs_data *ffs) in ffs_data_closed() argument
1732 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1733 if (ffs->no_disconnect) { in ffs_data_closed()
1734 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1735 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_closed()
1736 epfiles = ffs->epfiles; in ffs_data_closed()
1737 ffs->epfiles = NULL; in ffs_data_closed()
1738 spin_unlock_irqrestore(&ffs->eps_lock, in ffs_data_closed()
1743 ffs->eps_count); in ffs_data_closed()
1745 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1746 __ffs_ep0_stall(ffs); in ffs_data_closed()
1748 ffs->state = FFS_CLOSING; in ffs_data_closed()
1749 ffs_data_reset(ffs); in ffs_data_closed()
1752 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1753 ffs->state = FFS_CLOSING; in ffs_data_closed()
1754 ffs_data_reset(ffs); in ffs_data_closed()
1757 ffs_data_put(ffs); in ffs_data_closed()
1762 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); in ffs_data_new() local
1763 if (!ffs) in ffs_data_new()
1768 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1769 if (!ffs->io_completion_wq) { in ffs_data_new()
1770 kfree(ffs); in ffs_data_new()
1774 refcount_set(&ffs->ref, 1); in ffs_data_new()
1775 atomic_set(&ffs->opened, 0); in ffs_data_new()
1776 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1777 mutex_init(&ffs->mutex); in ffs_data_new()
1778 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1779 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1780 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1781 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1784 ffs->ev.can_stall = 1; in ffs_data_new()
1786 return ffs; in ffs_data_new()
1789 static void ffs_data_clear(struct ffs_data *ffs) in ffs_data_clear() argument
1796 ffs_closed(ffs); in ffs_data_clear()
1798 BUG_ON(ffs->gadget); in ffs_data_clear()
1800 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_clear()
1801 epfiles = ffs->epfiles; in ffs_data_clear()
1802 ffs->epfiles = NULL; in ffs_data_clear()
1803 spin_unlock_irqrestore(&ffs->eps_lock, flags); in ffs_data_clear()
1811 ffs_epfiles_destroy(epfiles, ffs->eps_count); in ffs_data_clear()
1812 ffs->epfiles = NULL; in ffs_data_clear()
1815 if (ffs->ffs_eventfd) { in ffs_data_clear()
1816 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1817 ffs->ffs_eventfd = NULL; in ffs_data_clear()
1820 kfree(ffs->raw_descs_data); in ffs_data_clear()
1821 kfree(ffs->raw_strings); in ffs_data_clear()
1822 kfree(ffs->stringtabs); in ffs_data_clear()
1825 static void ffs_data_reset(struct ffs_data *ffs) in ffs_data_reset() argument
1829 ffs_data_clear(ffs); in ffs_data_reset()
1831 ffs->raw_descs_data = NULL; in ffs_data_reset()
1832 ffs->raw_descs = NULL; in ffs_data_reset()
1833 ffs->raw_strings = NULL; in ffs_data_reset()
1834 ffs->stringtabs = NULL; in ffs_data_reset()
1836 ffs->raw_descs_length = 0; in ffs_data_reset()
1837 ffs->fs_descs_count = 0; in ffs_data_reset()
1838 ffs->hs_descs_count = 0; in ffs_data_reset()
1839 ffs->ss_descs_count = 0; in ffs_data_reset()
1841 ffs->strings_count = 0; in ffs_data_reset()
1842 ffs->interfaces_count = 0; in ffs_data_reset()
1843 ffs->eps_count = 0; in ffs_data_reset()
1845 ffs->ev.count = 0; in ffs_data_reset()
1847 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1848 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1849 ffs->flags = 0; in ffs_data_reset()
1851 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
1852 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
1853 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
1857 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) in functionfs_bind() argument
1864 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1865 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1868 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1872 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1873 if (!ffs->ep0req) in functionfs_bind()
1875 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1876 ffs->ep0req->context = ffs; in functionfs_bind()
1878 lang = ffs->stringtabs; in functionfs_bind()
1888 ffs->gadget = cdev->gadget; in functionfs_bind()
1889 ffs_data_get(ffs); in functionfs_bind()
1893 static void functionfs_unbind(struct ffs_data *ffs) in functionfs_unbind() argument
1897 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1899 usb_ep_dequeue(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1900 mutex_lock(&ffs->mutex); in functionfs_unbind()
1901 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1902 ffs->ep0req = NULL; in functionfs_unbind()
1903 ffs->gadget = NULL; in functionfs_unbind()
1904 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1905 mutex_unlock(&ffs->mutex); in functionfs_unbind()
1906 ffs_data_put(ffs); in functionfs_unbind()
1910 static int ffs_epfiles_create(struct ffs_data *ffs) in ffs_epfiles_create() argument
1917 count = ffs->eps_count; in ffs_epfiles_create()
1924 epfile->ffs = ffs; in ffs_epfiles_create()
1926 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1927 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1930 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1939 ffs->epfiles = epfiles; in ffs_epfiles_create()
1968 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1969 count = func->ffs->eps_count; in ffs_func_eps_disable()
1970 epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1984 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1989 struct ffs_data *ffs; in ffs_func_eps_enable() local
1996 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1997 ffs = func->ffs; in ffs_func_eps_enable()
1999 epfile = ffs->epfiles; in ffs_func_eps_enable()
2000 count = ffs->eps_count; in ffs_func_eps_enable()
2024 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
2025 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
2265 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2266 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2275 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2276 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2278 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2411 struct ffs_data *ffs = priv; in __ffs_data_do_os_desc() local
2422 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2446 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2470 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2472 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2473 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2483 static int __ffs_data_got_descs(struct ffs_data *ffs, in __ffs_data_got_descs() argument
2504 ffs->user_flags = flags; in __ffs_data_got_descs()
2526 ffs->ffs_eventfd = in __ffs_data_got_descs()
2528 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2529 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2530 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2560 helper.ffs = ffs; in __ffs_data_got_descs()
2570 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2571 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2572 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2574 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2578 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2588 __ffs_data_do_os_desc, ffs); in __ffs_data_got_descs()
2600 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2601 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2602 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2603 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2604 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2605 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2606 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2615 static int __ffs_data_got_strings(struct ffs_data *ffs, in __ffs_data_got_strings() argument
2637 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2737 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2738 ffs->raw_strings = _data; in __ffs_data_got_strings()
2752 static void __ffs_event_add(struct ffs_data *ffs, in __ffs_event_add() argument
2766 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2767 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2802 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2803 unsigned n = ffs->ev.count; in __ffs_event_add()
2809 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2813 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2814 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2815 if (ffs->ffs_eventfd) in __ffs_event_add()
2816 eventfd_signal(ffs->ffs_eventfd, 1); in __ffs_event_add()
2819 static void ffs_event_add(struct ffs_data *ffs, in ffs_event_add() argument
2823 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2824 __ffs_event_add(ffs, type); in ffs_event_add()
2825 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2830 static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) in ffs_ep_addr2idx() argument
2834 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2835 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2874 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2927 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2967 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
3025 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
3026 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
3034 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
3035 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
3038 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
3039 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
3101 func->ffs = ffs_data; in ffs_do_functionfs_bind()
3113 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3118 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3127 struct ffs_data *ffs = func->ffs; in _ffs_func_bind() local
3129 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3130 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3131 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3138 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3140 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3142 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3144 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3145 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
3147 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3149 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3151 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3153 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3155 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3157 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3158 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3172 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3173 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3175 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3179 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3180 ffs->raw_descs_length); in _ffs_func_bind()
3184 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3200 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3214 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3229 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3246 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3247 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3248 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3256 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3266 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3276 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3279 ffs_event_add(ffs, FUNCTIONFS_BIND); in _ffs_func_bind()
3299 functionfs_unbind(func->ffs); in ffs_func_bind()
3309 struct ffs_data *ffs = container_of(work, in ffs_reset_work() local
3311 ffs_data_reset(ffs); in ffs_reset_work()
3318 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt() local
3327 if (ffs->func) in ffs_func_set_alt()
3328 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3330 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3331 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3332 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3333 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3337 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3341 ffs->func = NULL; in ffs_func_set_alt()
3342 ffs_event_add(ffs, FUNCTIONFS_DISABLE); in ffs_func_set_alt()
3346 ffs->func = func; in ffs_func_set_alt()
3349 ffs_event_add(ffs, FUNCTIONFS_ENABLE); in ffs_func_set_alt()
3362 struct ffs_data *ffs = func->ffs; in ffs_func_setup() local
3384 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3398 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3399 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3403 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3409 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3410 ffs->ev.setup = *creq; in ffs_func_setup()
3411 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3412 __ffs_event_add(ffs, FUNCTIONFS_SETUP); in ffs_func_setup()
3413 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3424 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3435 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3443 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3449 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3464 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3605 struct ffs_data *ffs = func->ffs; in ffs_func_unbind() local
3609 unsigned count = ffs->eps_count; in ffs_func_unbind()
3613 if (ffs->func == func) { in ffs_func_unbind()
3615 ffs->func = NULL; in ffs_func_unbind()
3619 drain_workqueue(ffs->io_completion_wq); in ffs_func_unbind()
3622 functionfs_unbind(ffs); in ffs_func_unbind()
3625 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3632 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3645 ffs_event_add(ffs, FUNCTIONFS_UNBIND); in ffs_func_unbind()
3794 static int ffs_ready(struct ffs_data *ffs) in ffs_ready() argument
3802 ffs_obj = ffs->private_data; in ffs_ready()
3815 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3820 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3826 static void ffs_closed(struct ffs_data *ffs) in ffs_closed() argument
3835 ffs_obj = ffs->private_data; in ffs_closed()
3841 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3843 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3857 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3890 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc);