Lines Matching refs:ffs
42 static void ffs_data_get(struct ffs_data *ffs);
43 static void ffs_data_put(struct ffs_data *ffs);
49 static void ffs_data_opened(struct ffs_data *ffs);
50 static void ffs_data_closed(struct ffs_data *ffs);
54 __ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len);
56 __ffs_data_got_strings(struct ffs_data *ffs, char *data, size_t len);
66 struct ffs_data *ffs; member
83 ffs_setup_state_clear_cancelled(struct ffs_data *ffs) in ffs_setup_state_clear_cancelled() argument
86 cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP); in ffs_setup_state_clear_cancelled()
128 struct ffs_data *ffs; member
223 struct ffs_data *ffs; member
227 struct ffs_data *ffs; member
232 static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
249 static int ffs_ready(struct ffs_data *ffs);
250 static void ffs_closed(struct ffs_data *ffs);
264 struct ffs_data *ffs = req->context; in ffs_ep0_complete() local
266 complete(&ffs->ep0req_completion); in ffs_ep0_complete()
269 static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) in __ffs_ep0_queue_wait() argument
270 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_queue_wait()
272 struct usb_request *req = ffs->ep0req; in __ffs_ep0_queue_wait()
275 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
277 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
290 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
292 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
296 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
298 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
302 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
306 static int __ffs_ep0_stall(struct ffs_data *ffs) in __ffs_ep0_stall() argument
308 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
310 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
311 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
322 struct ffs_data *ffs = file->private_data; in ffs_ep0_write() local
329 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_write()
333 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
338 switch (ffs->state) { in ffs_ep0_write()
354 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
356 ret = __ffs_data_got_descs(ffs, data, len); in ffs_ep0_write()
360 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
364 ret = __ffs_data_got_strings(ffs, data, len); in ffs_ep0_write()
368 ret = ffs_epfiles_create(ffs); in ffs_ep0_write()
370 ffs->state = FFS_CLOSING; in ffs_ep0_write()
374 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
375 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
377 ret = ffs_ready(ffs); in ffs_ep0_write()
379 ffs->state = FFS_CLOSING; in ffs_ep0_write()
393 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
394 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_write()
408 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
409 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
410 ret = __ffs_ep0_stall(ffs); in ffs_ep0_write()
415 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
417 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
425 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
439 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_write()
443 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
446 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_write()
456 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
461 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, in __ffs_ep0_read_events() argument
463 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
470 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
477 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
479 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
480 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
484 ffs->ev.count -= n; in __ffs_ep0_read_events()
485 if (ffs->ev.count) in __ffs_ep0_read_events()
486 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
487 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
489 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
490 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
498 struct ffs_data *ffs = file->private_data; in ffs_ep0_read() local
506 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_read()
510 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
515 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
524 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
526 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_read()
538 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
543 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
544 ffs->ev.count)) { in ffs_ep0_read()
550 return __ffs_ep0_read_events(ffs, buf, in ffs_ep0_read()
551 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
554 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
555 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
556 ret = __ffs_ep0_stall(ffs); in ffs_ep0_read()
560 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
562 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
572 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
575 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_read()
582 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_read()
592 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
594 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
601 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open() local
605 if (unlikely(ffs->state == FFS_CLOSING)) in ffs_ep0_open()
608 file->private_data = ffs; in ffs_ep0_open()
609 ffs_data_opened(ffs); in ffs_ep0_open()
616 struct ffs_data *ffs = file->private_data; in ffs_ep0_release() local
620 ffs_data_closed(ffs); in ffs_ep0_release()
627 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl() local
628 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
634 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
647 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll() local
651 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
653 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
657 switch (ffs->state) { in ffs_ep0_poll()
664 switch (ffs->setup_state) { in ffs_ep0_poll()
666 if (ffs->ev.count) in ffs_ep0_poll()
681 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
773 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
774 eventfd_signal(io_data->ffs->ffs_eventfd, 1); in ffs_user_copy_worker()
788 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete() local
793 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
888 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
898 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_io()
935 gadget = epfile->ffs->gadget; in ffs_epfile_io()
937 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
950 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
964 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1002 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1032 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1052 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1067 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1071 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
1089 struct ffs_data *ffs = io_data->ffs; in ffs_aio_cancel() local
1096 queue_work(ffs->io_completion_wq, &io_data->cancellation_work); in ffs_aio_cancel()
1197 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1211 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1221 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_ioctl()
1226 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1230 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1253 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1265 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1274 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1345 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file() local
1355 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1383 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill() local
1387 ffs->sb = sb; in ffs_sb_fill()
1389 sb->s_fs_info = ffs; in ffs_sb_fill()
1407 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs, in ffs_sb_fill()
1521 struct ffs_data *ffs; in ffs_fs_mount() local
1529 ffs = ffs_data_new(dev_name); in ffs_fs_mount()
1530 if (unlikely(!ffs)) in ffs_fs_mount()
1532 ffs->file_perms = data.perms; in ffs_fs_mount()
1533 ffs->no_disconnect = data.no_disconnect; in ffs_fs_mount()
1535 ffs->dev_name = kstrdup(dev_name, GFP_KERNEL); in ffs_fs_mount()
1536 if (unlikely(!ffs->dev_name)) { in ffs_fs_mount()
1537 ffs_data_put(ffs); in ffs_fs_mount()
1543 ffs_data_put(ffs); in ffs_fs_mount()
1546 ffs->private_data = ffs_dev; in ffs_fs_mount()
1547 data.ffs_data = ffs; in ffs_fs_mount()
1606 static void ffs_data_clear(struct ffs_data *ffs);
1607 static void ffs_data_reset(struct ffs_data *ffs);
1609 static void ffs_data_get(struct ffs_data *ffs) in ffs_data_get() argument
1613 refcount_inc(&ffs->ref); in ffs_data_get()
1616 static void ffs_data_opened(struct ffs_data *ffs) in ffs_data_opened() argument
1620 refcount_inc(&ffs->ref); in ffs_data_opened()
1621 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1622 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1623 ffs->state = FFS_CLOSING; in ffs_data_opened()
1624 ffs_data_reset(ffs); in ffs_data_opened()
1628 static void ffs_data_put(struct ffs_data *ffs) in ffs_data_put() argument
1632 if (unlikely(refcount_dec_and_test(&ffs->ref))) { in ffs_data_put()
1634 ffs_data_clear(ffs); in ffs_data_put()
1635 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1636 waitqueue_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1637 waitqueue_active(&ffs->wait)); in ffs_data_put()
1638 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1639 kfree(ffs->dev_name); in ffs_data_put()
1640 kfree(ffs); in ffs_data_put()
1644 static void ffs_data_closed(struct ffs_data *ffs) in ffs_data_closed() argument
1648 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1649 if (ffs->no_disconnect) { in ffs_data_closed()
1650 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1651 if (ffs->epfiles) { in ffs_data_closed()
1652 ffs_epfiles_destroy(ffs->epfiles, in ffs_data_closed()
1653 ffs->eps_count); in ffs_data_closed()
1654 ffs->epfiles = NULL; in ffs_data_closed()
1656 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1657 __ffs_ep0_stall(ffs); in ffs_data_closed()
1659 ffs->state = FFS_CLOSING; in ffs_data_closed()
1660 ffs_data_reset(ffs); in ffs_data_closed()
1663 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1664 ffs->state = FFS_CLOSING; in ffs_data_closed()
1665 ffs_data_reset(ffs); in ffs_data_closed()
1668 ffs_data_put(ffs); in ffs_data_closed()
1673 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); in ffs_data_new() local
1674 if (unlikely(!ffs)) in ffs_data_new()
1679 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1680 if (!ffs->io_completion_wq) { in ffs_data_new()
1681 kfree(ffs); in ffs_data_new()
1685 refcount_set(&ffs->ref, 1); in ffs_data_new()
1686 atomic_set(&ffs->opened, 0); in ffs_data_new()
1687 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1688 mutex_init(&ffs->mutex); in ffs_data_new()
1689 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1690 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1691 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1692 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1695 ffs->ev.can_stall = 1; in ffs_data_new()
1697 return ffs; in ffs_data_new()
1700 static void ffs_data_clear(struct ffs_data *ffs) in ffs_data_clear() argument
1704 ffs_closed(ffs); in ffs_data_clear()
1706 BUG_ON(ffs->gadget); in ffs_data_clear()
1708 if (ffs->epfiles) in ffs_data_clear()
1709 ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count); in ffs_data_clear()
1711 if (ffs->ffs_eventfd) in ffs_data_clear()
1712 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1714 kfree(ffs->raw_descs_data); in ffs_data_clear()
1715 kfree(ffs->raw_strings); in ffs_data_clear()
1716 kfree(ffs->stringtabs); in ffs_data_clear()
1719 static void ffs_data_reset(struct ffs_data *ffs) in ffs_data_reset() argument
1723 ffs_data_clear(ffs); in ffs_data_reset()
1725 ffs->epfiles = NULL; in ffs_data_reset()
1726 ffs->raw_descs_data = NULL; in ffs_data_reset()
1727 ffs->raw_descs = NULL; in ffs_data_reset()
1728 ffs->raw_strings = NULL; in ffs_data_reset()
1729 ffs->stringtabs = NULL; in ffs_data_reset()
1731 ffs->raw_descs_length = 0; in ffs_data_reset()
1732 ffs->fs_descs_count = 0; in ffs_data_reset()
1733 ffs->hs_descs_count = 0; in ffs_data_reset()
1734 ffs->ss_descs_count = 0; in ffs_data_reset()
1736 ffs->strings_count = 0; in ffs_data_reset()
1737 ffs->interfaces_count = 0; in ffs_data_reset()
1738 ffs->eps_count = 0; in ffs_data_reset()
1740 ffs->ev.count = 0; in ffs_data_reset()
1742 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1743 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1744 ffs->flags = 0; in ffs_data_reset()
1748 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) in functionfs_bind() argument
1755 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1756 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1759 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1763 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1764 if (unlikely(!ffs->ep0req)) in functionfs_bind()
1766 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1767 ffs->ep0req->context = ffs; in functionfs_bind()
1769 lang = ffs->stringtabs; in functionfs_bind()
1779 ffs->gadget = cdev->gadget; in functionfs_bind()
1780 ffs_data_get(ffs); in functionfs_bind()
1784 static void functionfs_unbind(struct ffs_data *ffs) in functionfs_unbind() argument
1788 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1789 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1790 ffs->ep0req = NULL; in functionfs_unbind()
1791 ffs->gadget = NULL; in functionfs_unbind()
1792 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1793 ffs_data_put(ffs); in functionfs_unbind()
1797 static int ffs_epfiles_create(struct ffs_data *ffs) in ffs_epfiles_create() argument
1804 count = ffs->eps_count; in ffs_epfiles_create()
1811 epfile->ffs = ffs; in ffs_epfiles_create()
1813 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1814 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1817 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1826 ffs->epfiles = epfiles; in ffs_epfiles_create()
1851 struct ffs_epfile *epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1852 unsigned count = func->ffs->eps_count; in ffs_func_eps_disable()
1855 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1868 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1873 struct ffs_data *ffs = func->ffs; in ffs_func_eps_enable() local
1875 struct ffs_epfile *epfile = ffs->epfiles; in ffs_func_eps_enable()
1876 unsigned count = ffs->eps_count; in ffs_func_eps_enable()
1880 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1904 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
1905 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
2131 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2132 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2141 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2142 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2144 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2277 struct ffs_data *ffs = priv; in __ffs_data_do_os_desc() local
2288 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2312 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2336 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2338 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2339 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2349 static int __ffs_data_got_descs(struct ffs_data *ffs, in __ffs_data_got_descs() argument
2370 ffs->user_flags = flags; in __ffs_data_got_descs()
2392 ffs->ffs_eventfd = in __ffs_data_got_descs()
2394 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2395 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2396 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2426 helper.ffs = ffs; in __ffs_data_got_descs()
2436 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2437 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2438 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2440 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2444 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2454 __ffs_data_do_os_desc, ffs); in __ffs_data_got_descs()
2466 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2467 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2468 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2469 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2470 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2471 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2472 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2481 static int __ffs_data_got_strings(struct ffs_data *ffs, in __ffs_data_got_strings() argument
2503 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2602 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2603 ffs->raw_strings = _data; in __ffs_data_got_strings()
2617 static void __ffs_event_add(struct ffs_data *ffs, in __ffs_event_add() argument
2631 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2632 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2667 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2668 unsigned n = ffs->ev.count; in __ffs_event_add()
2674 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2678 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2679 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2680 if (ffs->ffs_eventfd) in __ffs_event_add()
2681 eventfd_signal(ffs->ffs_eventfd, 1); in __ffs_event_add()
2684 static void ffs_event_add(struct ffs_data *ffs, in ffs_event_add() argument
2688 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2689 __ffs_event_add(ffs, type); in ffs_event_add()
2690 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2695 static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) in ffs_ep_addr2idx() argument
2699 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2700 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2739 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2786 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2821 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
2879 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
2880 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
2888 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
2889 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
2892 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
2893 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
2948 func->ffs = ffs_opts->dev->ffs_data; in ffs_do_functionfs_bind()
2965 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
2970 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
2979 struct ffs_data *ffs = func->ffs; in _ffs_func_bind() local
2981 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
2982 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
2983 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
2990 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
2992 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
2994 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
2996 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
2997 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
2999 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3001 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3003 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3005 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3007 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3009 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3010 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3024 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3025 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3027 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3031 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3032 ffs->raw_descs_length); in _ffs_func_bind()
3036 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3052 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3066 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3080 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3097 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3098 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3099 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3107 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3117 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3127 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3130 ffs_event_add(ffs, FUNCTIONFS_BIND); in _ffs_func_bind()
3150 functionfs_unbind(func->ffs); in ffs_func_bind()
3160 struct ffs_data *ffs = container_of(work, in ffs_reset_work() local
3162 ffs_data_reset(ffs); in ffs_reset_work()
3169 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt() local
3178 if (ffs->func) in ffs_func_set_alt()
3179 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3181 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3182 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3183 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3184 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3188 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3192 ffs->func = NULL; in ffs_func_set_alt()
3193 ffs_event_add(ffs, FUNCTIONFS_DISABLE); in ffs_func_set_alt()
3197 ffs->func = func; in ffs_func_set_alt()
3200 ffs_event_add(ffs, FUNCTIONFS_ENABLE); in ffs_func_set_alt()
3213 struct ffs_data *ffs = func->ffs; in ffs_func_setup() local
3235 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3249 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3250 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3254 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3260 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3261 ffs->ev.setup = *creq; in ffs_func_setup()
3262 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3263 __ffs_event_add(ffs, FUNCTIONFS_SETUP); in ffs_func_setup()
3264 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3275 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3286 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3294 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3300 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3315 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3455 struct ffs_data *ffs = func->ffs; in ffs_func_unbind() local
3459 unsigned count = ffs->eps_count; in ffs_func_unbind()
3463 if (ffs->func == func) { in ffs_func_unbind()
3465 ffs->func = NULL; in ffs_func_unbind()
3469 functionfs_unbind(ffs); in ffs_func_unbind()
3472 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3479 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3491 ffs_event_add(ffs, FUNCTIONFS_UNBIND); in ffs_func_unbind()
3639 static int ffs_ready(struct ffs_data *ffs) in ffs_ready() argument
3647 ffs_obj = ffs->private_data; in ffs_ready()
3658 ffs_obj->ffs_data = ffs; in ffs_ready()
3661 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3666 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3672 static void ffs_closed(struct ffs_data *ffs) in ffs_closed() argument
3681 ffs_obj = ffs->private_data; in ffs_closed()
3688 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3690 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3704 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3742 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc);