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()
282 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
284 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
297 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
299 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
303 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
305 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
309 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
313 static int __ffs_ep0_stall(struct ffs_data *ffs) in __ffs_ep0_stall() argument
315 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
317 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
318 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
329 struct ffs_data *ffs = file->private_data; in ffs_ep0_write() local
336 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_write()
340 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
345 switch (ffs->state) { in ffs_ep0_write()
361 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
363 ret = __ffs_data_got_descs(ffs, data, len); in ffs_ep0_write()
367 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
371 ret = __ffs_data_got_strings(ffs, data, len); in ffs_ep0_write()
375 ret = ffs_epfiles_create(ffs); in ffs_ep0_write()
377 ffs->state = FFS_CLOSING; in ffs_ep0_write()
381 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
382 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
384 ret = ffs_ready(ffs); in ffs_ep0_write()
386 ffs->state = FFS_CLOSING; in ffs_ep0_write()
400 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
401 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_write()
415 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
416 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
417 ret = __ffs_ep0_stall(ffs); in ffs_ep0_write()
422 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
424 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
432 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
446 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_write()
450 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
453 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_write()
463 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
468 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, in __ffs_ep0_read_events() argument
470 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
477 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
484 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
486 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
487 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
491 ffs->ev.count -= n; in __ffs_ep0_read_events()
492 if (ffs->ev.count) in __ffs_ep0_read_events()
493 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
494 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
496 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
497 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
505 struct ffs_data *ffs = file->private_data; in ffs_ep0_read() local
513 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_read()
517 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
522 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
531 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
533 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_read()
545 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
550 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
551 ffs->ev.count)) { in ffs_ep0_read()
557 return __ffs_ep0_read_events(ffs, buf, in ffs_ep0_read()
558 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
561 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
562 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
563 ret = __ffs_ep0_stall(ffs); in ffs_ep0_read()
567 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
569 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
579 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
582 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_read()
589 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_read()
599 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
601 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
608 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open() local
612 if (ffs->state == FFS_CLOSING) in ffs_ep0_open()
615 file->private_data = ffs; in ffs_ep0_open()
616 ffs_data_opened(ffs); in ffs_ep0_open()
623 struct ffs_data *ffs = file->private_data; in ffs_ep0_release() local
627 ffs_data_closed(ffs); in ffs_ep0_release()
634 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl() local
635 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
641 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
654 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll() local
658 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
660 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
664 switch (ffs->state) { in ffs_ep0_poll()
671 switch (ffs->setup_state) { in ffs_ep0_poll()
673 if (ffs->ev.count) in ffs_ep0_poll()
690 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
840 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
841 eventfd_signal(io_data->ffs->ffs_eventfd, 1); in ffs_user_copy_worker()
855 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete() local
860 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
955 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
965 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_io()
1002 gadget = epfile->ffs->gadget; in ffs_epfile_io()
1004 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1019 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1033 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1080 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1083 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1095 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1124 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1145 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1161 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1165 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
1179 spin_lock_irqsave(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1186 spin_unlock_irqrestore(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1285 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1299 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1309 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_ioctl()
1314 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1318 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1341 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1356 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1365 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1426 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file() local
1436 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1464 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill() local
1468 ffs->sb = sb; in ffs_sb_fill()
1470 sb->s_fs_info = ffs; in ffs_sb_fill()
1488 if (!ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations)) in ffs_sb_fill()
1567 struct ffs_data *ffs; in ffs_fs_get_tree() local
1575 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
1576 if (!ffs) in ffs_fs_get_tree()
1578 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
1579 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
1581 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
1582 if (!ffs->dev_name) { in ffs_fs_get_tree()
1583 ffs_data_put(ffs); in ffs_fs_get_tree()
1587 ret = ffs_acquire_dev(ffs->dev_name, ffs); in ffs_fs_get_tree()
1589 ffs_data_put(ffs); in ffs_fs_get_tree()
1593 ctx->ffs_data = ffs; in ffs_fs_get_tree()
1683 static void ffs_data_clear(struct ffs_data *ffs);
1684 static void ffs_data_reset(struct ffs_data *ffs);
1686 static void ffs_data_get(struct ffs_data *ffs) in ffs_data_get() argument
1690 refcount_inc(&ffs->ref); in ffs_data_get()
1693 static void ffs_data_opened(struct ffs_data *ffs) in ffs_data_opened() argument
1697 refcount_inc(&ffs->ref); in ffs_data_opened()
1698 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1699 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1700 ffs->state = FFS_CLOSING; in ffs_data_opened()
1701 ffs_data_reset(ffs); in ffs_data_opened()
1705 static void ffs_data_put(struct ffs_data *ffs) in ffs_data_put() argument
1709 if (refcount_dec_and_test(&ffs->ref)) { in ffs_data_put()
1711 ffs_data_clear(ffs); in ffs_data_put()
1712 ffs_release_dev(ffs->private_data); in ffs_data_put()
1713 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1714 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1715 waitqueue_active(&ffs->wait)); in ffs_data_put()
1716 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1717 kfree(ffs->dev_name); in ffs_data_put()
1718 kfree(ffs); in ffs_data_put()
1722 static void ffs_data_closed(struct ffs_data *ffs) in ffs_data_closed() argument
1729 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1730 if (ffs->no_disconnect) { in ffs_data_closed()
1731 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1732 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_closed()
1733 epfiles = ffs->epfiles; in ffs_data_closed()
1734 ffs->epfiles = NULL; in ffs_data_closed()
1735 spin_unlock_irqrestore(&ffs->eps_lock, in ffs_data_closed()
1740 ffs->eps_count); in ffs_data_closed()
1742 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1743 __ffs_ep0_stall(ffs); in ffs_data_closed()
1745 ffs->state = FFS_CLOSING; in ffs_data_closed()
1746 ffs_data_reset(ffs); in ffs_data_closed()
1749 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1750 ffs->state = FFS_CLOSING; in ffs_data_closed()
1751 ffs_data_reset(ffs); in ffs_data_closed()
1754 ffs_data_put(ffs); in ffs_data_closed()
1759 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); in ffs_data_new() local
1760 if (!ffs) in ffs_data_new()
1765 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1766 if (!ffs->io_completion_wq) { in ffs_data_new()
1767 kfree(ffs); in ffs_data_new()
1771 refcount_set(&ffs->ref, 1); in ffs_data_new()
1772 atomic_set(&ffs->opened, 0); in ffs_data_new()
1773 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1774 mutex_init(&ffs->mutex); in ffs_data_new()
1775 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1776 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1777 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1778 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1781 ffs->ev.can_stall = 1; in ffs_data_new()
1783 return ffs; in ffs_data_new()
1786 static void ffs_data_clear(struct ffs_data *ffs) in ffs_data_clear() argument
1793 ffs_closed(ffs); in ffs_data_clear()
1795 BUG_ON(ffs->gadget); in ffs_data_clear()
1797 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_clear()
1798 epfiles = ffs->epfiles; in ffs_data_clear()
1799 ffs->epfiles = NULL; in ffs_data_clear()
1800 spin_unlock_irqrestore(&ffs->eps_lock, flags); in ffs_data_clear()
1808 ffs_epfiles_destroy(epfiles, ffs->eps_count); in ffs_data_clear()
1809 ffs->epfiles = NULL; in ffs_data_clear()
1812 if (ffs->ffs_eventfd) { in ffs_data_clear()
1813 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1814 ffs->ffs_eventfd = NULL; in ffs_data_clear()
1817 kfree(ffs->raw_descs_data); in ffs_data_clear()
1818 kfree(ffs->raw_strings); in ffs_data_clear()
1819 kfree(ffs->stringtabs); in ffs_data_clear()
1822 static void ffs_data_reset(struct ffs_data *ffs) in ffs_data_reset() argument
1826 ffs_data_clear(ffs); in ffs_data_reset()
1828 ffs->raw_descs_data = NULL; in ffs_data_reset()
1829 ffs->raw_descs = NULL; in ffs_data_reset()
1830 ffs->raw_strings = NULL; in ffs_data_reset()
1831 ffs->stringtabs = NULL; in ffs_data_reset()
1833 ffs->raw_descs_length = 0; in ffs_data_reset()
1834 ffs->fs_descs_count = 0; in ffs_data_reset()
1835 ffs->hs_descs_count = 0; in ffs_data_reset()
1836 ffs->ss_descs_count = 0; in ffs_data_reset()
1838 ffs->strings_count = 0; in ffs_data_reset()
1839 ffs->interfaces_count = 0; in ffs_data_reset()
1840 ffs->eps_count = 0; in ffs_data_reset()
1842 ffs->ev.count = 0; in ffs_data_reset()
1844 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1845 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1846 ffs->flags = 0; in ffs_data_reset()
1848 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
1849 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
1850 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
1854 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) in functionfs_bind() argument
1861 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1862 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1865 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1869 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1870 if (!ffs->ep0req) in functionfs_bind()
1872 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1873 ffs->ep0req->context = ffs; in functionfs_bind()
1875 lang = ffs->stringtabs; in functionfs_bind()
1885 ffs->gadget = cdev->gadget; in functionfs_bind()
1886 ffs_data_get(ffs); in functionfs_bind()
1890 static void functionfs_unbind(struct ffs_data *ffs) in functionfs_unbind() argument
1894 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1895 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1896 ffs->ep0req = NULL; in functionfs_unbind()
1897 ffs->gadget = NULL; in functionfs_unbind()
1898 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1899 ffs_data_put(ffs); in functionfs_unbind()
1903 static int ffs_epfiles_create(struct ffs_data *ffs) in ffs_epfiles_create() argument
1910 count = ffs->eps_count; in ffs_epfiles_create()
1917 epfile->ffs = ffs; in ffs_epfiles_create()
1919 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1920 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1923 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1932 ffs->epfiles = epfiles; in ffs_epfiles_create()
1961 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1962 count = func->ffs->eps_count; in ffs_func_eps_disable()
1963 epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1977 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1982 struct ffs_data *ffs; in ffs_func_eps_enable() local
1989 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1990 ffs = func->ffs; in ffs_func_eps_enable()
1992 epfile = ffs->epfiles; in ffs_func_eps_enable()
1993 count = ffs->eps_count; in ffs_func_eps_enable()
2017 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
2018 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
2258 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2259 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2268 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2269 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2271 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2404 struct ffs_data *ffs = priv; in __ffs_data_do_os_desc() local
2415 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2439 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2463 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2465 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2466 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2476 static int __ffs_data_got_descs(struct ffs_data *ffs, in __ffs_data_got_descs() argument
2497 ffs->user_flags = flags; in __ffs_data_got_descs()
2519 ffs->ffs_eventfd = in __ffs_data_got_descs()
2521 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2522 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2523 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2553 helper.ffs = ffs; in __ffs_data_got_descs()
2563 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2564 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2565 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2567 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2571 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2581 __ffs_data_do_os_desc, ffs); in __ffs_data_got_descs()
2593 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2594 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2595 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2596 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2597 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2598 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2599 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2608 static int __ffs_data_got_strings(struct ffs_data *ffs, in __ffs_data_got_strings() argument
2630 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2730 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2731 ffs->raw_strings = _data; in __ffs_data_got_strings()
2745 static void __ffs_event_add(struct ffs_data *ffs, in __ffs_event_add() argument
2759 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2760 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2795 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2796 unsigned n = ffs->ev.count; in __ffs_event_add()
2802 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2806 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2807 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2808 if (ffs->ffs_eventfd) in __ffs_event_add()
2809 eventfd_signal(ffs->ffs_eventfd, 1); in __ffs_event_add()
2812 static void ffs_event_add(struct ffs_data *ffs, in ffs_event_add() argument
2816 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2817 __ffs_event_add(ffs, type); in ffs_event_add()
2818 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2823 static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) in ffs_ep_addr2idx() argument
2827 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2828 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2867 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2920 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2960 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
3018 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
3019 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
3027 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
3028 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
3031 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
3032 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
3094 func->ffs = ffs_data; in ffs_do_functionfs_bind()
3106 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3111 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3120 struct ffs_data *ffs = func->ffs; in _ffs_func_bind() local
3122 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3123 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3124 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3131 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3133 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3135 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3137 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3138 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
3140 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3142 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3144 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3146 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3148 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3150 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3151 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3165 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3166 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3168 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3172 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3173 ffs->raw_descs_length); in _ffs_func_bind()
3177 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3193 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3207 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3222 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3239 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3240 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3241 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3249 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3259 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3269 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3272 ffs_event_add(ffs, FUNCTIONFS_BIND); in _ffs_func_bind()
3292 functionfs_unbind(func->ffs); in ffs_func_bind()
3302 struct ffs_data *ffs = container_of(work, in ffs_reset_work() local
3304 ffs_data_reset(ffs); in ffs_reset_work()
3311 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt() local
3320 if (ffs->func) in ffs_func_set_alt()
3321 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3323 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3324 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3325 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3326 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3330 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3334 ffs->func = NULL; in ffs_func_set_alt()
3335 ffs_event_add(ffs, FUNCTIONFS_DISABLE); in ffs_func_set_alt()
3339 ffs->func = func; in ffs_func_set_alt()
3342 ffs_event_add(ffs, FUNCTIONFS_ENABLE); in ffs_func_set_alt()
3355 struct ffs_data *ffs = func->ffs; in ffs_func_setup() local
3377 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3391 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3392 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3396 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3402 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3403 ffs->ev.setup = *creq; in ffs_func_setup()
3404 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3405 __ffs_event_add(ffs, FUNCTIONFS_SETUP); in ffs_func_setup()
3406 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3417 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3428 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3436 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3442 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3457 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3598 struct ffs_data *ffs = func->ffs; in ffs_func_unbind() local
3602 unsigned count = ffs->eps_count; in ffs_func_unbind()
3606 if (ffs->func == func) { in ffs_func_unbind()
3608 ffs->func = NULL; in ffs_func_unbind()
3612 drain_workqueue(ffs->io_completion_wq); in ffs_func_unbind()
3615 functionfs_unbind(ffs); in ffs_func_unbind()
3618 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3625 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3638 ffs_event_add(ffs, FUNCTIONFS_UNBIND); in ffs_func_unbind()
3787 static int ffs_ready(struct ffs_data *ffs) in ffs_ready() argument
3795 ffs_obj = ffs->private_data; in ffs_ready()
3808 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3813 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3819 static void ffs_closed(struct ffs_data *ffs) in ffs_closed() argument
3828 ffs_obj = ffs->private_data; in ffs_closed()
3834 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3836 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3850 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3883 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc);