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()
283 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
287 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
289 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
302 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
304 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
308 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
310 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
314 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
318 static int __ffs_ep0_stall(struct ffs_data *ffs) in __ffs_ep0_stall() argument
320 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
322 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
323 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
334 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
514 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_read()
518 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
523 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
532 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
534 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_read()
546 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
551 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
552 ffs->ev.count)) { in ffs_ep0_read()
558 return __ffs_ep0_read_events(ffs, buf, in ffs_ep0_read()
559 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
562 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
563 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
564 ret = __ffs_ep0_stall(ffs); in ffs_ep0_read()
568 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
570 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
580 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
583 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_read()
590 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_read()
600 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
602 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
609 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open() local
611 if (ffs->state == FFS_CLOSING) in ffs_ep0_open()
614 file->private_data = ffs; in ffs_ep0_open()
615 ffs_data_opened(ffs); in ffs_ep0_open()
622 struct ffs_data *ffs = file->private_data; in ffs_ep0_release() local
624 ffs_data_closed(ffs); in ffs_ep0_release()
631 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl() local
632 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
636 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
649 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll() local
653 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
655 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
659 switch (ffs->state) { in ffs_ep0_poll()
666 switch (ffs->setup_state) { in ffs_ep0_poll()
668 if (ffs->ev.count) in ffs_ep0_poll()
685 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
833 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
834 eventfd_signal(io_data->ffs->ffs_eventfd, 1); in ffs_user_copy_worker()
846 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete() local
852 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
947 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
957 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_io()
994 gadget = epfile->ffs->gadget; in ffs_epfile_io()
996 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1011 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1025 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1072 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1075 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1087 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1116 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1137 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1151 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1155 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
1167 spin_lock_irqsave(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1174 spin_unlock_irqrestore(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1267 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1279 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1289 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_ioctl()
1294 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1298 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1321 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1336 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1345 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1403 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file() local
1411 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1439 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill() local
1441 ffs->sb = sb; in ffs_sb_fill()
1443 sb->s_fs_info = ffs; in ffs_sb_fill()
1461 if (!ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations)) in ffs_sb_fill()
1538 struct ffs_data *ffs; in ffs_fs_get_tree() local
1544 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
1545 if (!ffs) in ffs_fs_get_tree()
1547 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
1548 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
1550 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
1551 if (!ffs->dev_name) { in ffs_fs_get_tree()
1552 ffs_data_put(ffs); in ffs_fs_get_tree()
1556 ret = ffs_acquire_dev(ffs->dev_name, ffs); in ffs_fs_get_tree()
1558 ffs_data_put(ffs); in ffs_fs_get_tree()
1562 ctx->ffs_data = ffs; in ffs_fs_get_tree()
1646 static void ffs_data_clear(struct ffs_data *ffs);
1647 static void ffs_data_reset(struct ffs_data *ffs);
1649 static void ffs_data_get(struct ffs_data *ffs) in ffs_data_get() argument
1651 refcount_inc(&ffs->ref); in ffs_data_get()
1654 static void ffs_data_opened(struct ffs_data *ffs) in ffs_data_opened() argument
1656 refcount_inc(&ffs->ref); in ffs_data_opened()
1657 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1658 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1659 ffs->state = FFS_CLOSING; in ffs_data_opened()
1660 ffs_data_reset(ffs); in ffs_data_opened()
1664 static void ffs_data_put(struct ffs_data *ffs) in ffs_data_put() argument
1666 if (refcount_dec_and_test(&ffs->ref)) { in ffs_data_put()
1668 ffs_data_clear(ffs); in ffs_data_put()
1669 ffs_release_dev(ffs->private_data); in ffs_data_put()
1670 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1671 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1672 waitqueue_active(&ffs->wait)); in ffs_data_put()
1673 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1674 kfree(ffs->dev_name); in ffs_data_put()
1675 kfree(ffs); in ffs_data_put()
1679 static void ffs_data_closed(struct ffs_data *ffs) in ffs_data_closed() argument
1684 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1685 if (ffs->no_disconnect) { in ffs_data_closed()
1686 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1687 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_closed()
1688 epfiles = ffs->epfiles; in ffs_data_closed()
1689 ffs->epfiles = NULL; in ffs_data_closed()
1690 spin_unlock_irqrestore(&ffs->eps_lock, in ffs_data_closed()
1695 ffs->eps_count); in ffs_data_closed()
1697 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1698 __ffs_ep0_stall(ffs); in ffs_data_closed()
1700 ffs->state = FFS_CLOSING; in ffs_data_closed()
1701 ffs_data_reset(ffs); in ffs_data_closed()
1704 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1705 ffs->state = FFS_CLOSING; in ffs_data_closed()
1706 ffs_data_reset(ffs); in ffs_data_closed()
1709 ffs_data_put(ffs); in ffs_data_closed()
1714 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); in ffs_data_new() local
1715 if (!ffs) in ffs_data_new()
1718 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1719 if (!ffs->io_completion_wq) { in ffs_data_new()
1720 kfree(ffs); in ffs_data_new()
1724 refcount_set(&ffs->ref, 1); in ffs_data_new()
1725 atomic_set(&ffs->opened, 0); in ffs_data_new()
1726 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1727 mutex_init(&ffs->mutex); in ffs_data_new()
1728 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1729 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1730 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1731 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1734 ffs->ev.can_stall = 1; in ffs_data_new()
1736 return ffs; in ffs_data_new()
1739 static void ffs_data_clear(struct ffs_data *ffs) in ffs_data_clear() argument
1744 ffs_closed(ffs); in ffs_data_clear()
1746 BUG_ON(ffs->gadget); in ffs_data_clear()
1748 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_clear()
1749 epfiles = ffs->epfiles; in ffs_data_clear()
1750 ffs->epfiles = NULL; in ffs_data_clear()
1751 spin_unlock_irqrestore(&ffs->eps_lock, flags); in ffs_data_clear()
1759 ffs_epfiles_destroy(epfiles, ffs->eps_count); in ffs_data_clear()
1760 ffs->epfiles = NULL; in ffs_data_clear()
1763 if (ffs->ffs_eventfd) { in ffs_data_clear()
1764 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1765 ffs->ffs_eventfd = NULL; in ffs_data_clear()
1768 kfree(ffs->raw_descs_data); in ffs_data_clear()
1769 kfree(ffs->raw_strings); in ffs_data_clear()
1770 kfree(ffs->stringtabs); in ffs_data_clear()
1773 static void ffs_data_reset(struct ffs_data *ffs) in ffs_data_reset() argument
1775 ffs_data_clear(ffs); in ffs_data_reset()
1777 ffs->raw_descs_data = NULL; in ffs_data_reset()
1778 ffs->raw_descs = NULL; in ffs_data_reset()
1779 ffs->raw_strings = NULL; in ffs_data_reset()
1780 ffs->stringtabs = NULL; in ffs_data_reset()
1782 ffs->raw_descs_length = 0; in ffs_data_reset()
1783 ffs->fs_descs_count = 0; in ffs_data_reset()
1784 ffs->hs_descs_count = 0; in ffs_data_reset()
1785 ffs->ss_descs_count = 0; in ffs_data_reset()
1787 ffs->strings_count = 0; in ffs_data_reset()
1788 ffs->interfaces_count = 0; in ffs_data_reset()
1789 ffs->eps_count = 0; in ffs_data_reset()
1791 ffs->ev.count = 0; in ffs_data_reset()
1793 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1794 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1795 ffs->flags = 0; in ffs_data_reset()
1797 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
1798 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
1799 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
1803 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) in functionfs_bind() argument
1808 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1809 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1812 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1816 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1817 if (!ffs->ep0req) in functionfs_bind()
1819 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1820 ffs->ep0req->context = ffs; in functionfs_bind()
1822 lang = ffs->stringtabs; in functionfs_bind()
1832 ffs->gadget = cdev->gadget; in functionfs_bind()
1833 ffs_data_get(ffs); in functionfs_bind()
1837 static void functionfs_unbind(struct ffs_data *ffs) in functionfs_unbind() argument
1839 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1841 usb_ep_dequeue(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1842 mutex_lock(&ffs->mutex); in functionfs_unbind()
1843 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1844 ffs->ep0req = NULL; in functionfs_unbind()
1845 ffs->gadget = NULL; in functionfs_unbind()
1846 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1847 mutex_unlock(&ffs->mutex); in functionfs_unbind()
1848 ffs_data_put(ffs); in functionfs_unbind()
1852 static int ffs_epfiles_create(struct ffs_data *ffs) in ffs_epfiles_create() argument
1857 count = ffs->eps_count; in ffs_epfiles_create()
1864 epfile->ffs = ffs; in ffs_epfiles_create()
1866 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1867 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1870 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1879 ffs->epfiles = epfiles; in ffs_epfiles_create()
1906 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1907 count = func->ffs->eps_count; in ffs_func_eps_disable()
1908 epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1922 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1927 struct ffs_data *ffs; in ffs_func_eps_enable() local
1934 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1935 ffs = func->ffs; in ffs_func_eps_enable()
1937 epfile = ffs->epfiles; in ffs_func_eps_enable()
1938 count = ffs->eps_count; in ffs_func_eps_enable()
1962 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
1963 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
2197 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2198 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2207 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2208 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2210 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2342 struct ffs_data *ffs = priv; in __ffs_data_do_os_desc() local
2351 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2375 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2399 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2401 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2402 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2412 static int __ffs_data_got_descs(struct ffs_data *ffs, in __ffs_data_got_descs() argument
2431 ffs->user_flags = flags; in __ffs_data_got_descs()
2453 ffs->ffs_eventfd = in __ffs_data_got_descs()
2455 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2456 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2457 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2487 helper.ffs = ffs; in __ffs_data_got_descs()
2497 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2498 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2499 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2501 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2505 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2515 __ffs_data_do_os_desc, ffs); in __ffs_data_got_descs()
2527 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2528 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2529 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2530 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2531 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2532 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2533 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2542 static int __ffs_data_got_strings(struct ffs_data *ffs, in __ffs_data_got_strings() argument
2562 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2662 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2663 ffs->raw_strings = _data; in __ffs_data_got_strings()
2677 static void __ffs_event_add(struct ffs_data *ffs, in __ffs_event_add() argument
2691 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2692 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2727 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2728 unsigned n = ffs->ev.count; in __ffs_event_add()
2734 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2738 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2739 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2740 if (ffs->ffs_eventfd) in __ffs_event_add()
2741 eventfd_signal(ffs->ffs_eventfd, 1); in __ffs_event_add()
2744 static void ffs_event_add(struct ffs_data *ffs, in ffs_event_add() argument
2748 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2749 __ffs_event_add(ffs, type); in ffs_event_add()
2750 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2755 static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) in ffs_ep_addr2idx() argument
2759 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2760 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2799 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2852 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2892 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
2950 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
2951 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
2959 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
2960 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
2963 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
2964 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
3024 func->ffs = ffs_data; in ffs_do_functionfs_bind()
3036 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3041 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3050 struct ffs_data *ffs = func->ffs; in _ffs_func_bind() local
3052 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3053 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3054 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3061 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3063 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3065 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3067 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3068 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
3070 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3072 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3074 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3076 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3078 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3080 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3081 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3093 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3094 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3096 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3100 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3101 ffs->raw_descs_length); in _ffs_func_bind()
3105 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3121 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3135 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3150 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3167 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3168 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3169 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3177 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3187 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3197 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3200 ffs_event_add(ffs, FUNCTIONFS_BIND); in _ffs_func_bind()
3220 functionfs_unbind(func->ffs); in ffs_func_bind()
3230 struct ffs_data *ffs = container_of(work, in ffs_reset_work() local
3232 ffs_data_reset(ffs); in ffs_reset_work()
3239 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt() local
3248 if (ffs->func) in ffs_func_set_alt()
3249 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3251 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3252 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3253 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3254 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3258 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3262 ffs->func = NULL; in ffs_func_set_alt()
3263 ffs_event_add(ffs, FUNCTIONFS_DISABLE); in ffs_func_set_alt()
3267 ffs->func = func; in ffs_func_set_alt()
3270 ffs_event_add(ffs, FUNCTIONFS_ENABLE); in ffs_func_set_alt()
3283 struct ffs_data *ffs = func->ffs; in ffs_func_setup() local
3303 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3317 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3318 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3322 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3328 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3329 ffs->ev.setup = *creq; in ffs_func_setup()
3330 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3331 __ffs_event_add(ffs, FUNCTIONFS_SETUP); in ffs_func_setup()
3332 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3343 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3354 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3361 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3366 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3381 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3522 struct ffs_data *ffs = func->ffs; in ffs_func_unbind() local
3526 unsigned count = ffs->eps_count; in ffs_func_unbind()
3529 if (ffs->func == func) { in ffs_func_unbind()
3531 ffs->func = NULL; in ffs_func_unbind()
3535 drain_workqueue(ffs->io_completion_wq); in ffs_func_unbind()
3537 ffs_event_add(ffs, FUNCTIONFS_UNBIND); in ffs_func_unbind()
3539 functionfs_unbind(ffs); in ffs_func_unbind()
3542 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3549 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3706 static int ffs_ready(struct ffs_data *ffs) in ffs_ready() argument
3713 ffs_obj = ffs->private_data; in ffs_ready()
3726 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3731 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3737 static void ffs_closed(struct ffs_data *ffs) in ffs_closed() argument
3745 ffs_obj = ffs->private_data; in ffs_closed()
3751 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3753 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3767 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3800 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc);