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
341 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_write()
345 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
350 switch (ffs->state) { in ffs_ep0_write()
366 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
368 ret = __ffs_data_got_descs(ffs, data, len); in ffs_ep0_write()
372 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
376 ret = __ffs_data_got_strings(ffs, data, len); in ffs_ep0_write()
380 ret = ffs_epfiles_create(ffs); in ffs_ep0_write()
382 ffs->state = FFS_CLOSING; in ffs_ep0_write()
386 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
387 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
389 ret = ffs_ready(ffs); in ffs_ep0_write()
391 ffs->state = FFS_CLOSING; in ffs_ep0_write()
405 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
406 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_write()
420 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
421 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
422 ret = __ffs_ep0_stall(ffs); in ffs_ep0_write()
427 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
429 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
437 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
451 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_write()
455 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
458 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_write()
468 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
473 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, in __ffs_ep0_read_events() argument
475 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
482 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
489 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
491 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
492 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
496 ffs->ev.count -= n; in __ffs_ep0_read_events()
497 if (ffs->ev.count) in __ffs_ep0_read_events()
498 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
499 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
501 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
502 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
510 struct ffs_data *ffs = file->private_data; in ffs_ep0_read() local
518 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_read()
522 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
527 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
536 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
538 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_read()
550 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
555 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
556 ffs->ev.count)) { in ffs_ep0_read()
562 return __ffs_ep0_read_events(ffs, buf, in ffs_ep0_read()
563 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
566 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
567 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
568 ret = __ffs_ep0_stall(ffs); in ffs_ep0_read()
572 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
574 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
584 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
587 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_read()
594 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_read()
604 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
606 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
613 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open() local
617 if (unlikely(ffs->state == FFS_CLOSING)) in ffs_ep0_open()
620 file->private_data = ffs; in ffs_ep0_open()
621 ffs_data_opened(ffs); in ffs_ep0_open()
628 struct ffs_data *ffs = file->private_data; in ffs_ep0_release() local
632 ffs_data_closed(ffs); in ffs_ep0_release()
639 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl() local
640 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
646 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
659 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll() local
663 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
665 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
669 switch (ffs->state) { in ffs_ep0_poll()
676 switch (ffs->setup_state) { in ffs_ep0_poll()
678 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 (unlikely(!ffs_sb_create_file(sb, "ep0", ffs, in ffs_sb_fill()
1571 struct ffs_data *ffs; in ffs_fs_get_tree() local
1579 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
1580 if (unlikely(!ffs)) in ffs_fs_get_tree()
1582 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
1583 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
1585 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
1586 if (unlikely(!ffs->dev_name)) { in ffs_fs_get_tree()
1587 ffs_data_put(ffs); in ffs_fs_get_tree()
1591 ret = ffs_acquire_dev(ffs->dev_name, ffs); in ffs_fs_get_tree()
1593 ffs_data_put(ffs); in ffs_fs_get_tree()
1597 ctx->ffs_data = ffs; in ffs_fs_get_tree()
1687 static void ffs_data_clear(struct ffs_data *ffs);
1688 static void ffs_data_reset(struct ffs_data *ffs);
1690 static void ffs_data_get(struct ffs_data *ffs) in ffs_data_get() argument
1694 refcount_inc(&ffs->ref); in ffs_data_get()
1697 static void ffs_data_opened(struct ffs_data *ffs) in ffs_data_opened() argument
1701 refcount_inc(&ffs->ref); in ffs_data_opened()
1702 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1703 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1704 ffs->state = FFS_CLOSING; in ffs_data_opened()
1705 ffs_data_reset(ffs); in ffs_data_opened()
1709 static void ffs_data_put(struct ffs_data *ffs) in ffs_data_put() argument
1713 if (unlikely(refcount_dec_and_test(&ffs->ref))) { in ffs_data_put()
1715 ffs_data_clear(ffs); in ffs_data_put()
1716 ffs_release_dev(ffs->private_data); in ffs_data_put()
1717 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1718 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1719 waitqueue_active(&ffs->wait)); in ffs_data_put()
1720 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1721 kfree(ffs->dev_name); in ffs_data_put()
1722 kfree(ffs); in ffs_data_put()
1726 static void ffs_data_closed(struct ffs_data *ffs) in ffs_data_closed() argument
1733 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1734 if (ffs->no_disconnect) { in ffs_data_closed()
1735 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1736 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_closed()
1737 epfiles = ffs->epfiles; in ffs_data_closed()
1738 ffs->epfiles = NULL; in ffs_data_closed()
1739 spin_unlock_irqrestore(&ffs->eps_lock, in ffs_data_closed()
1744 ffs->eps_count); in ffs_data_closed()
1746 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1747 __ffs_ep0_stall(ffs); in ffs_data_closed()
1749 ffs->state = FFS_CLOSING; in ffs_data_closed()
1750 ffs_data_reset(ffs); in ffs_data_closed()
1753 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1754 ffs->state = FFS_CLOSING; in ffs_data_closed()
1755 ffs_data_reset(ffs); in ffs_data_closed()
1758 ffs_data_put(ffs); in ffs_data_closed()
1763 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); in ffs_data_new() local
1764 if (unlikely(!ffs)) in ffs_data_new()
1769 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1770 if (!ffs->io_completion_wq) { in ffs_data_new()
1771 kfree(ffs); in ffs_data_new()
1775 refcount_set(&ffs->ref, 1); in ffs_data_new()
1776 atomic_set(&ffs->opened, 0); in ffs_data_new()
1777 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1778 mutex_init(&ffs->mutex); in ffs_data_new()
1779 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1780 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1781 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1782 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1785 ffs->ev.can_stall = 1; in ffs_data_new()
1787 return ffs; in ffs_data_new()
1790 static void ffs_data_clear(struct ffs_data *ffs) in ffs_data_clear() argument
1797 ffs_closed(ffs); in ffs_data_clear()
1799 BUG_ON(ffs->gadget); in ffs_data_clear()
1801 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_clear()
1802 epfiles = ffs->epfiles; in ffs_data_clear()
1803 ffs->epfiles = NULL; in ffs_data_clear()
1804 spin_unlock_irqrestore(&ffs->eps_lock, flags); in ffs_data_clear()
1812 ffs_epfiles_destroy(epfiles, ffs->eps_count); in ffs_data_clear()
1813 ffs->epfiles = NULL; in ffs_data_clear()
1816 if (ffs->ffs_eventfd) { in ffs_data_clear()
1817 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1818 ffs->ffs_eventfd = NULL; in ffs_data_clear()
1821 kfree(ffs->raw_descs_data); in ffs_data_clear()
1822 kfree(ffs->raw_strings); in ffs_data_clear()
1823 kfree(ffs->stringtabs); in ffs_data_clear()
1826 static void ffs_data_reset(struct ffs_data *ffs) in ffs_data_reset() argument
1830 ffs_data_clear(ffs); in ffs_data_reset()
1832 ffs->raw_descs_data = NULL; in ffs_data_reset()
1833 ffs->raw_descs = NULL; in ffs_data_reset()
1834 ffs->raw_strings = NULL; in ffs_data_reset()
1835 ffs->stringtabs = NULL; in ffs_data_reset()
1837 ffs->raw_descs_length = 0; in ffs_data_reset()
1838 ffs->fs_descs_count = 0; in ffs_data_reset()
1839 ffs->hs_descs_count = 0; in ffs_data_reset()
1840 ffs->ss_descs_count = 0; in ffs_data_reset()
1842 ffs->strings_count = 0; in ffs_data_reset()
1843 ffs->interfaces_count = 0; in ffs_data_reset()
1844 ffs->eps_count = 0; in ffs_data_reset()
1846 ffs->ev.count = 0; in ffs_data_reset()
1848 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1849 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1850 ffs->flags = 0; in ffs_data_reset()
1852 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
1853 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
1854 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
1858 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) in functionfs_bind() argument
1865 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1866 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1869 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1873 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1874 if (unlikely(!ffs->ep0req)) in functionfs_bind()
1876 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1877 ffs->ep0req->context = ffs; in functionfs_bind()
1879 lang = ffs->stringtabs; in functionfs_bind()
1889 ffs->gadget = cdev->gadget; in functionfs_bind()
1890 ffs_data_get(ffs); in functionfs_bind()
1894 static void functionfs_unbind(struct ffs_data *ffs) in functionfs_unbind() argument
1898 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1900 usb_ep_dequeue(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1901 mutex_lock(&ffs->mutex); in functionfs_unbind()
1902 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1903 ffs->ep0req = NULL; in functionfs_unbind()
1904 ffs->gadget = NULL; in functionfs_unbind()
1905 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1906 mutex_unlock(&ffs->mutex); in functionfs_unbind()
1907 ffs_data_put(ffs); in functionfs_unbind()
1911 static int ffs_epfiles_create(struct ffs_data *ffs) in ffs_epfiles_create() argument
1918 count = ffs->eps_count; in ffs_epfiles_create()
1925 epfile->ffs = ffs; in ffs_epfiles_create()
1927 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1928 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1931 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1940 ffs->epfiles = epfiles; in ffs_epfiles_create()
1969 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1970 count = func->ffs->eps_count; in ffs_func_eps_disable()
1971 epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1985 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1990 struct ffs_data *ffs; in ffs_func_eps_enable() local
1997 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1998 ffs = func->ffs; in ffs_func_eps_enable()
2000 epfile = ffs->epfiles; in ffs_func_eps_enable()
2001 count = ffs->eps_count; in ffs_func_eps_enable()
2025 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
2026 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
2266 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2267 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2276 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2277 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2279 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2412 struct ffs_data *ffs = priv; in __ffs_data_do_os_desc() local
2423 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2447 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2471 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2473 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2474 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2484 static int __ffs_data_got_descs(struct ffs_data *ffs, in __ffs_data_got_descs() argument
2505 ffs->user_flags = flags; in __ffs_data_got_descs()
2527 ffs->ffs_eventfd = in __ffs_data_got_descs()
2529 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2530 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2531 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2561 helper.ffs = ffs; in __ffs_data_got_descs()
2571 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2572 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2573 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2575 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2579 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2589 __ffs_data_do_os_desc, ffs); in __ffs_data_got_descs()
2601 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2602 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2603 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2604 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2605 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2606 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2607 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2616 static int __ffs_data_got_strings(struct ffs_data *ffs, in __ffs_data_got_strings() argument
2638 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2738 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2739 ffs->raw_strings = _data; in __ffs_data_got_strings()
2753 static void __ffs_event_add(struct ffs_data *ffs, in __ffs_event_add() argument
2767 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2768 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2803 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2804 unsigned n = ffs->ev.count; in __ffs_event_add()
2810 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2814 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2815 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2816 if (ffs->ffs_eventfd) in __ffs_event_add()
2817 eventfd_signal(ffs->ffs_eventfd, 1); in __ffs_event_add()
2820 static void ffs_event_add(struct ffs_data *ffs, in ffs_event_add() argument
2824 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2825 __ffs_event_add(ffs, type); in ffs_event_add()
2826 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2831 static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) in ffs_ep_addr2idx() argument
2835 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2836 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2875 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2929 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2969 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
3027 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
3028 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
3036 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
3037 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
3040 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
3041 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
3103 func->ffs = ffs_data; in ffs_do_functionfs_bind()
3115 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3120 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3129 struct ffs_data *ffs = func->ffs; in _ffs_func_bind() local
3131 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3132 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3133 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3140 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3142 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3144 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3146 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3147 vla_item_with_sz(d, short, inums, ffs->interfaces_count); 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 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3155 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3157 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3159 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3160 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3174 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3175 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3177 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3181 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3182 ffs->raw_descs_length); in _ffs_func_bind()
3186 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3202 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3216 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3231 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3248 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3249 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3250 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3258 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3268 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3278 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3281 ffs_event_add(ffs, FUNCTIONFS_BIND); in _ffs_func_bind()
3301 functionfs_unbind(func->ffs); in ffs_func_bind()
3311 struct ffs_data *ffs = container_of(work, in ffs_reset_work() local
3313 ffs_data_reset(ffs); in ffs_reset_work()
3320 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt() local
3329 if (ffs->func) in ffs_func_set_alt()
3330 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3332 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3333 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3334 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3335 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3339 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3343 ffs->func = NULL; in ffs_func_set_alt()
3344 ffs_event_add(ffs, FUNCTIONFS_DISABLE); in ffs_func_set_alt()
3348 ffs->func = func; in ffs_func_set_alt()
3351 ffs_event_add(ffs, FUNCTIONFS_ENABLE); in ffs_func_set_alt()
3364 struct ffs_data *ffs = func->ffs; in ffs_func_setup() local
3386 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3400 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3401 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3405 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3411 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3412 ffs->ev.setup = *creq; in ffs_func_setup()
3413 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3414 __ffs_event_add(ffs, FUNCTIONFS_SETUP); in ffs_func_setup()
3415 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3426 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3437 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3445 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3451 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3469 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3610 struct ffs_data *ffs = func->ffs; in ffs_func_unbind() local
3614 unsigned count = ffs->eps_count; in ffs_func_unbind()
3618 if (ffs->func == func) { in ffs_func_unbind()
3620 ffs->func = NULL; in ffs_func_unbind()
3624 drain_workqueue(ffs->io_completion_wq); in ffs_func_unbind()
3627 functionfs_unbind(ffs); in ffs_func_unbind()
3630 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3637 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3650 ffs_event_add(ffs, FUNCTIONFS_UNBIND); in ffs_func_unbind()
3799 static int ffs_ready(struct ffs_data *ffs) in ffs_ready() argument
3807 ffs_obj = ffs->private_data; in ffs_ready()
3820 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3825 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3831 static void ffs_closed(struct ffs_data *ffs) in ffs_closed() argument
3840 ffs_obj = ffs->private_data; in ffs_closed()
3846 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3848 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3862 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3900 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc);