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()
133 struct ffs_data *ffs; member
229 struct ffs_data *ffs; member
233 struct ffs_data *ffs; member
238 static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
255 static int ffs_ready(struct ffs_data *ffs);
256 static void ffs_closed(struct ffs_data *ffs);
270 struct ffs_data *ffs = req->context; in ffs_ep0_complete() local
272 complete(&ffs->ep0req_completion); in ffs_ep0_complete()
275 static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) in __ffs_ep0_queue_wait() argument
276 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_queue_wait()
278 struct usb_request *req = ffs->ep0req; in __ffs_ep0_queue_wait()
281 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
283 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
296 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
298 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
302 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
304 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
308 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
312 static int __ffs_ep0_stall(struct ffs_data *ffs) in __ffs_ep0_stall() argument
314 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
316 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
317 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
328 struct ffs_data *ffs = file->private_data; in ffs_ep0_write() local
335 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_write()
339 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
344 switch (ffs->state) { in ffs_ep0_write()
360 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
362 ret = __ffs_data_got_descs(ffs, data, len); in ffs_ep0_write()
366 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
370 ret = __ffs_data_got_strings(ffs, data, len); in ffs_ep0_write()
374 ret = ffs_epfiles_create(ffs); in ffs_ep0_write()
376 ffs->state = FFS_CLOSING; in ffs_ep0_write()
380 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
381 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
383 ret = ffs_ready(ffs); in ffs_ep0_write()
385 ffs->state = FFS_CLOSING; in ffs_ep0_write()
399 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
400 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_write()
414 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
415 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
416 ret = __ffs_ep0_stall(ffs); in ffs_ep0_write()
421 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
423 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
431 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
445 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_write()
449 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
452 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_write()
462 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
467 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, in __ffs_ep0_read_events() argument
469 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
476 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
483 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
485 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
486 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
490 ffs->ev.count -= n; in __ffs_ep0_read_events()
491 if (ffs->ev.count) in __ffs_ep0_read_events()
492 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
493 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
495 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
496 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
504 struct ffs_data *ffs = file->private_data; in ffs_ep0_read() local
512 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_read()
516 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
521 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
530 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
532 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_read()
544 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
549 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
550 ffs->ev.count)) { in ffs_ep0_read()
556 return __ffs_ep0_read_events(ffs, buf, in ffs_ep0_read()
557 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
560 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
561 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
562 ret = __ffs_ep0_stall(ffs); in ffs_ep0_read()
566 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
568 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
578 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
581 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_read()
588 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_read()
598 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
600 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
607 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open() local
611 if (unlikely(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
626 ffs_data_closed(ffs); in ffs_ep0_release()
633 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl() local
634 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
640 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
653 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll() local
657 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
659 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
663 switch (ffs->state) { in ffs_ep0_poll()
670 switch (ffs->setup_state) { in ffs_ep0_poll()
672 if (ffs->ev.count) in ffs_ep0_poll()
687 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
834 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
835 eventfd_signal(io_data->ffs->ffs_eventfd, 1); in ffs_user_copy_worker()
849 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete() local
854 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
949 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
959 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_io()
996 gadget = epfile->ffs->gadget; in ffs_epfile_io()
998 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1013 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1027 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1074 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1112 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1133 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1149 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1153 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()
1273 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1287 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1297 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_ioctl()
1302 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1306 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1329 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1343 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1352 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1413 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file() local
1423 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1451 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill() local
1455 ffs->sb = sb; in ffs_sb_fill()
1457 sb->s_fs_info = ffs; in ffs_sb_fill()
1475 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs, in ffs_sb_fill()
1556 struct ffs_data *ffs; in ffs_fs_get_tree() local
1563 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
1564 if (unlikely(!ffs)) in ffs_fs_get_tree()
1566 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
1567 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
1569 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
1570 if (unlikely(!ffs->dev_name)) { in ffs_fs_get_tree()
1571 ffs_data_put(ffs); in ffs_fs_get_tree()
1575 ffs_dev = ffs_acquire_dev(ffs->dev_name); in ffs_fs_get_tree()
1577 ffs_data_put(ffs); in ffs_fs_get_tree()
1581 ffs->private_data = ffs_dev; in ffs_fs_get_tree()
1582 ctx->ffs_data = ffs; in ffs_fs_get_tree()
1675 static void ffs_data_clear(struct ffs_data *ffs);
1676 static void ffs_data_reset(struct ffs_data *ffs);
1678 static void ffs_data_get(struct ffs_data *ffs) in ffs_data_get() argument
1682 refcount_inc(&ffs->ref); in ffs_data_get()
1685 static void ffs_data_opened(struct ffs_data *ffs) in ffs_data_opened() argument
1689 refcount_inc(&ffs->ref); in ffs_data_opened()
1690 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1691 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1692 ffs->state = FFS_CLOSING; in ffs_data_opened()
1693 ffs_data_reset(ffs); in ffs_data_opened()
1697 static void ffs_data_put(struct ffs_data *ffs) in ffs_data_put() argument
1701 if (unlikely(refcount_dec_and_test(&ffs->ref))) { in ffs_data_put()
1703 ffs_data_clear(ffs); in ffs_data_put()
1704 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1705 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1706 waitqueue_active(&ffs->wait)); in ffs_data_put()
1707 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1708 kfree(ffs->dev_name); in ffs_data_put()
1709 kfree(ffs); in ffs_data_put()
1713 static void ffs_data_closed(struct ffs_data *ffs) in ffs_data_closed() argument
1717 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1718 if (ffs->no_disconnect) { in ffs_data_closed()
1719 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1720 if (ffs->epfiles) { in ffs_data_closed()
1721 ffs_epfiles_destroy(ffs->epfiles, in ffs_data_closed()
1722 ffs->eps_count); in ffs_data_closed()
1723 ffs->epfiles = NULL; in ffs_data_closed()
1725 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1726 __ffs_ep0_stall(ffs); in ffs_data_closed()
1728 ffs->state = FFS_CLOSING; in ffs_data_closed()
1729 ffs_data_reset(ffs); in ffs_data_closed()
1732 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1733 ffs->state = FFS_CLOSING; in ffs_data_closed()
1734 ffs_data_reset(ffs); in ffs_data_closed()
1737 ffs_data_put(ffs); in ffs_data_closed()
1742 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); in ffs_data_new() local
1743 if (unlikely(!ffs)) in ffs_data_new()
1748 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1749 if (!ffs->io_completion_wq) { in ffs_data_new()
1750 kfree(ffs); in ffs_data_new()
1754 refcount_set(&ffs->ref, 1); in ffs_data_new()
1755 atomic_set(&ffs->opened, 0); in ffs_data_new()
1756 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1757 mutex_init(&ffs->mutex); in ffs_data_new()
1758 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1759 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1760 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1761 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1764 ffs->ev.can_stall = 1; in ffs_data_new()
1766 return ffs; in ffs_data_new()
1769 static void ffs_data_clear(struct ffs_data *ffs) in ffs_data_clear() argument
1773 ffs_closed(ffs); in ffs_data_clear()
1775 BUG_ON(ffs->gadget); in ffs_data_clear()
1777 if (ffs->epfiles) in ffs_data_clear()
1778 ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count); in ffs_data_clear()
1780 if (ffs->ffs_eventfd) in ffs_data_clear()
1781 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1783 kfree(ffs->raw_descs_data); in ffs_data_clear()
1784 kfree(ffs->raw_strings); in ffs_data_clear()
1785 kfree(ffs->stringtabs); in ffs_data_clear()
1788 static void ffs_data_reset(struct ffs_data *ffs) in ffs_data_reset() argument
1792 ffs_data_clear(ffs); in ffs_data_reset()
1794 ffs->epfiles = NULL; in ffs_data_reset()
1795 ffs->raw_descs_data = NULL; in ffs_data_reset()
1796 ffs->raw_descs = NULL; in ffs_data_reset()
1797 ffs->raw_strings = NULL; in ffs_data_reset()
1798 ffs->stringtabs = NULL; in ffs_data_reset()
1800 ffs->raw_descs_length = 0; in ffs_data_reset()
1801 ffs->fs_descs_count = 0; in ffs_data_reset()
1802 ffs->hs_descs_count = 0; in ffs_data_reset()
1803 ffs->ss_descs_count = 0; in ffs_data_reset()
1805 ffs->strings_count = 0; in ffs_data_reset()
1806 ffs->interfaces_count = 0; in ffs_data_reset()
1807 ffs->eps_count = 0; in ffs_data_reset()
1809 ffs->ev.count = 0; in ffs_data_reset()
1811 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1812 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1813 ffs->flags = 0; in ffs_data_reset()
1815 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
1816 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
1817 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
1821 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) in functionfs_bind() argument
1828 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1829 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1832 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1836 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1837 if (unlikely(!ffs->ep0req)) in functionfs_bind()
1839 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1840 ffs->ep0req->context = ffs; in functionfs_bind()
1842 lang = ffs->stringtabs; in functionfs_bind()
1852 ffs->gadget = cdev->gadget; in functionfs_bind()
1853 ffs_data_get(ffs); in functionfs_bind()
1857 static void functionfs_unbind(struct ffs_data *ffs) in functionfs_unbind() argument
1861 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1862 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1863 ffs->ep0req = NULL; in functionfs_unbind()
1864 ffs->gadget = NULL; in functionfs_unbind()
1865 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1866 ffs_data_put(ffs); in functionfs_unbind()
1870 static int ffs_epfiles_create(struct ffs_data *ffs) in ffs_epfiles_create() argument
1877 count = ffs->eps_count; in ffs_epfiles_create()
1884 epfile->ffs = ffs; in ffs_epfiles_create()
1886 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1887 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1890 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1899 ffs->epfiles = epfiles; in ffs_epfiles_create()
1924 struct ffs_epfile *epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1925 unsigned count = func->ffs->eps_count; in ffs_func_eps_disable()
1928 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1941 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1946 struct ffs_data *ffs = func->ffs; in ffs_func_eps_enable() local
1948 struct ffs_epfile *epfile = ffs->epfiles; in ffs_func_eps_enable()
1949 unsigned count = ffs->eps_count; in ffs_func_eps_enable()
1953 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1977 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
1978 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
2218 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2219 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2228 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2229 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2231 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2364 struct ffs_data *ffs = priv; in __ffs_data_do_os_desc() local
2375 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2399 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2423 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2425 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2426 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2436 static int __ffs_data_got_descs(struct ffs_data *ffs, in __ffs_data_got_descs() argument
2457 ffs->user_flags = flags; in __ffs_data_got_descs()
2479 ffs->ffs_eventfd = in __ffs_data_got_descs()
2481 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2482 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2483 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2513 helper.ffs = ffs; in __ffs_data_got_descs()
2523 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2524 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2525 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2527 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2531 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2541 __ffs_data_do_os_desc, ffs); in __ffs_data_got_descs()
2553 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2554 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2555 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2556 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2557 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2558 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2559 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2568 static int __ffs_data_got_strings(struct ffs_data *ffs, in __ffs_data_got_strings() argument
2590 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2689 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2690 ffs->raw_strings = _data; in __ffs_data_got_strings()
2704 static void __ffs_event_add(struct ffs_data *ffs, in __ffs_event_add() argument
2718 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2719 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2754 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2755 unsigned n = ffs->ev.count; in __ffs_event_add()
2761 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2765 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2766 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2767 if (ffs->ffs_eventfd) in __ffs_event_add()
2768 eventfd_signal(ffs->ffs_eventfd, 1); in __ffs_event_add()
2771 static void ffs_event_add(struct ffs_data *ffs, in ffs_event_add() argument
2775 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2776 __ffs_event_add(ffs, type); in ffs_event_add()
2777 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2782 static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) in ffs_ep_addr2idx() argument
2786 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2787 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2826 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2879 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2919 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
2977 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
2978 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
2986 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
2987 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
2990 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
2991 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
3046 func->ffs = ffs_opts->dev->ffs_data; in ffs_do_functionfs_bind()
3063 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3068 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3077 struct ffs_data *ffs = func->ffs; in _ffs_func_bind() local
3079 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3080 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3081 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3088 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3090 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3092 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3094 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3095 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
3097 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3099 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3101 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3103 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3105 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3107 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3108 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3122 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3123 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3125 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3129 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3130 ffs->raw_descs_length); in _ffs_func_bind()
3134 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3150 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3164 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3178 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3195 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3196 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3197 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3205 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3215 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3225 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3228 ffs_event_add(ffs, FUNCTIONFS_BIND); in _ffs_func_bind()
3248 functionfs_unbind(func->ffs); in ffs_func_bind()
3258 struct ffs_data *ffs = container_of(work, in ffs_reset_work() local
3260 ffs_data_reset(ffs); in ffs_reset_work()
3267 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt() local
3276 if (ffs->func) in ffs_func_set_alt()
3277 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3279 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3280 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3281 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3282 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3286 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3290 ffs->func = NULL; in ffs_func_set_alt()
3291 ffs_event_add(ffs, FUNCTIONFS_DISABLE); in ffs_func_set_alt()
3295 ffs->func = func; in ffs_func_set_alt()
3298 ffs_event_add(ffs, FUNCTIONFS_ENABLE); in ffs_func_set_alt()
3311 struct ffs_data *ffs = func->ffs; in ffs_func_setup() local
3333 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3347 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3348 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3352 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3358 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3359 ffs->ev.setup = *creq; in ffs_func_setup()
3360 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3361 __ffs_event_add(ffs, FUNCTIONFS_SETUP); in ffs_func_setup()
3362 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3373 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3384 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3392 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3398 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3413 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3553 struct ffs_data *ffs = func->ffs; in ffs_func_unbind() local
3557 unsigned count = ffs->eps_count; in ffs_func_unbind()
3561 if (ffs->func == func) { in ffs_func_unbind()
3563 ffs->func = NULL; in ffs_func_unbind()
3567 functionfs_unbind(ffs); in ffs_func_unbind()
3570 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3577 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3589 ffs_event_add(ffs, FUNCTIONFS_UNBIND); in ffs_func_unbind()
3737 static int ffs_ready(struct ffs_data *ffs) in ffs_ready() argument
3745 ffs_obj = ffs->private_data; in ffs_ready()
3756 ffs_obj->ffs_data = ffs; in ffs_ready()
3759 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3764 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3770 static void ffs_closed(struct ffs_data *ffs) in ffs_closed() argument
3779 ffs_obj = ffs->private_data; in ffs_closed()
3786 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3788 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3802 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3840 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc);