Lines Matching refs:ffs

55 static void ffs_data_get(struct ffs_data *ffs);
56 static void ffs_data_put(struct ffs_data *ffs);
62 static void ffs_data_opened(struct ffs_data *ffs);
63 static void ffs_data_closed(struct ffs_data *ffs);
67 __ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len);
69 __ffs_data_got_strings(struct ffs_data *ffs, char *data, size_t len);
79 struct ffs_data *ffs; member
97 ffs_setup_state_clear_cancelled(struct ffs_data *ffs) in ffs_setup_state_clear_cancelled() argument
100 cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP); in ffs_setup_state_clear_cancelled()
140 struct ffs_data *ffs; member
160 struct ffs_data *ffs; member
261 struct ffs_data *ffs; member
268 struct ffs_data *ffs; member
273 static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
290 static int ffs_ready(struct ffs_data *ffs);
291 static void ffs_closed(struct ffs_data *ffs);
305 struct ffs_data *ffs = req->context; in ffs_ep0_complete() local
307 complete(&ffs->ep0req_completion); in ffs_ep0_complete()
310 static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) in __ffs_ep0_queue_wait() argument
311 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_queue_wait()
313 struct usb_request *req = ffs->ep0req; in __ffs_ep0_queue_wait()
317 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
321 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
323 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
336 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
338 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
342 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
344 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
348 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
352 static int __ffs_ep0_stall(struct ffs_data *ffs) in __ffs_ep0_stall() argument
354 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
356 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
357 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
368 struct ffs_data *ffs = file->private_data; in ffs_ep0_write() local
373 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_write()
377 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
382 switch (ffs->state) { in ffs_ep0_write()
398 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
400 ret = __ffs_data_got_descs(ffs, data, len); in ffs_ep0_write()
404 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
408 ret = __ffs_data_got_strings(ffs, data, len); in ffs_ep0_write()
412 ret = ffs_epfiles_create(ffs); in ffs_ep0_write()
414 ffs->state = FFS_CLOSING; in ffs_ep0_write()
418 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
419 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
421 ret = ffs_ready(ffs); in ffs_ep0_write()
423 ffs->state = FFS_CLOSING; in ffs_ep0_write()
437 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
438 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_write()
452 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
453 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
454 ret = __ffs_ep0_stall(ffs); in ffs_ep0_write()
459 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
461 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
469 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
483 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_write()
487 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
490 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_write()
500 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
505 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, in __ffs_ep0_read_events() argument
507 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
514 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
521 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
523 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
524 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
528 ffs->ev.count -= n; in __ffs_ep0_read_events()
529 if (ffs->ev.count) in __ffs_ep0_read_events()
530 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
531 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
533 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
534 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
542 struct ffs_data *ffs = file->private_data; in ffs_ep0_read() local
548 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_read()
552 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
557 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
566 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
568 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_read()
580 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
585 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
586 ffs->ev.count)) { in ffs_ep0_read()
592 return __ffs_ep0_read_events(ffs, buf, in ffs_ep0_read()
593 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
596 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
597 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
598 ret = __ffs_ep0_stall(ffs); in ffs_ep0_read()
602 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
604 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
614 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
617 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_read()
624 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_read()
634 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
636 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
643 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open() local
645 if (ffs->state == FFS_CLOSING) in ffs_ep0_open()
648 file->private_data = ffs; in ffs_ep0_open()
649 ffs_data_opened(ffs); in ffs_ep0_open()
656 struct ffs_data *ffs = file->private_data; in ffs_ep0_release() local
658 ffs_data_closed(ffs); in ffs_ep0_release()
665 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl() local
666 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
670 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
683 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll() local
687 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
689 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
693 switch (ffs->state) { in ffs_ep0_poll()
700 switch (ffs->setup_state) { in ffs_ep0_poll()
702 if (ffs->ev.count) in ffs_ep0_poll()
719 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
867 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
868 eventfd_signal(io_data->ffs->ffs_eventfd); in ffs_user_copy_worker()
870 spin_lock_irqsave(&io_data->ffs->eps_lock, flags); in ffs_user_copy_worker()
873 spin_unlock_irqrestore(&io_data->ffs->eps_lock, flags); in ffs_user_copy_worker()
885 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete() local
890 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
988 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_wait_ep()
1006 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
1045 gadget = epfile->ffs->gadget; in ffs_epfile_io()
1047 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1062 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1076 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1123 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1126 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1138 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1167 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1188 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1202 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1206 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
1218 spin_lock_irqsave(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1225 spin_unlock_irqrestore(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1347 struct ffs_data *ffs = epfile->ffs; in ffs_epfile_release() local
1354 spin_lock_irq(&ffs->eps_lock); in ffs_epfile_release()
1357 spin_unlock_irq(&ffs->eps_lock); in ffs_epfile_release()
1366 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1400 queue_work(priv->ffs->io_completion_wq, &dma_fence->work); in ffs_dmabuf_signal_done()
1449 struct device *dev = epfile->ffs->gadget->dev.parent; in ffs_dmabuf_find_attachment()
1475 struct usb_gadget *gadget = epfile->ffs->gadget; in ffs_dmabuf_attach()
1520 priv->ffs = epfile->ffs; in ffs_dmabuf_attach()
1545 struct ffs_data *ffs = epfile->ffs; in ffs_dmabuf_detach() local
1546 struct device *dev = ffs->gadget->dev.parent; in ffs_dmabuf_detach()
1561 spin_lock_irq(&ffs->eps_lock); in ffs_dmabuf_detach()
1564 spin_unlock_irq(&ffs->eps_lock); in ffs_dmabuf_detach()
1653 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_dmabuf_transfer()
1704 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_dmabuf_transfer()
1710 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_dmabuf_transfer()
1729 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1775 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1779 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1802 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1817 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1826 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1883 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file() local
1891 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1919 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill() local
1921 ffs->sb = sb; in ffs_sb_fill()
1923 sb->s_fs_info = ffs; in ffs_sb_fill()
1941 if (!ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations)) in ffs_sb_fill()
2018 struct ffs_data *ffs; in ffs_fs_get_tree() local
2024 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
2025 if (!ffs) in ffs_fs_get_tree()
2027 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
2028 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
2030 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
2031 if (!ffs->dev_name) { in ffs_fs_get_tree()
2032 ffs_data_put(ffs); in ffs_fs_get_tree()
2036 ret = ffs_acquire_dev(ffs->dev_name, ffs); in ffs_fs_get_tree()
2038 ffs_data_put(ffs); in ffs_fs_get_tree()
2042 ctx->ffs_data = ffs; in ffs_fs_get_tree()
2126 static void ffs_data_clear(struct ffs_data *ffs);
2127 static void ffs_data_reset(struct ffs_data *ffs);
2129 static void ffs_data_get(struct ffs_data *ffs) in ffs_data_get() argument
2131 refcount_inc(&ffs->ref); in ffs_data_get()
2134 static void ffs_data_opened(struct ffs_data *ffs) in ffs_data_opened() argument
2136 refcount_inc(&ffs->ref); in ffs_data_opened()
2137 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
2138 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
2139 ffs->state = FFS_CLOSING; in ffs_data_opened()
2140 ffs_data_reset(ffs); in ffs_data_opened()
2144 static void ffs_data_put(struct ffs_data *ffs) in ffs_data_put() argument
2146 if (refcount_dec_and_test(&ffs->ref)) { in ffs_data_put()
2148 ffs_data_clear(ffs); in ffs_data_put()
2149 ffs_release_dev(ffs->private_data); in ffs_data_put()
2150 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
2151 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
2152 waitqueue_active(&ffs->wait)); in ffs_data_put()
2153 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
2154 kfree(ffs->dev_name); in ffs_data_put()
2155 kfree(ffs); in ffs_data_put()
2159 static void ffs_data_closed(struct ffs_data *ffs) in ffs_data_closed() argument
2164 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
2165 if (ffs->no_disconnect) { in ffs_data_closed()
2166 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
2167 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_closed()
2168 epfiles = ffs->epfiles; in ffs_data_closed()
2169 ffs->epfiles = NULL; in ffs_data_closed()
2170 spin_unlock_irqrestore(&ffs->eps_lock, in ffs_data_closed()
2175 ffs->eps_count); in ffs_data_closed()
2177 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
2178 __ffs_ep0_stall(ffs); in ffs_data_closed()
2180 ffs->state = FFS_CLOSING; in ffs_data_closed()
2181 ffs_data_reset(ffs); in ffs_data_closed()
2184 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
2185 ffs->state = FFS_CLOSING; in ffs_data_closed()
2186 ffs_data_reset(ffs); in ffs_data_closed()
2189 ffs_data_put(ffs); in ffs_data_closed()
2194 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); in ffs_data_new() local
2195 if (!ffs) in ffs_data_new()
2198 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
2199 if (!ffs->io_completion_wq) { in ffs_data_new()
2200 kfree(ffs); in ffs_data_new()
2204 refcount_set(&ffs->ref, 1); in ffs_data_new()
2205 atomic_set(&ffs->opened, 0); in ffs_data_new()
2206 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
2207 mutex_init(&ffs->mutex); in ffs_data_new()
2208 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
2209 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
2210 init_waitqueue_head(&ffs->wait); in ffs_data_new()
2211 init_completion(&ffs->ep0req_completion); in ffs_data_new()
2214 ffs->ev.can_stall = 1; in ffs_data_new()
2216 return ffs; in ffs_data_new()
2219 static void ffs_data_clear(struct ffs_data *ffs) in ffs_data_clear() argument
2224 ffs_closed(ffs); in ffs_data_clear()
2226 BUG_ON(ffs->gadget); in ffs_data_clear()
2228 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_clear()
2229 epfiles = ffs->epfiles; in ffs_data_clear()
2230 ffs->epfiles = NULL; in ffs_data_clear()
2231 spin_unlock_irqrestore(&ffs->eps_lock, flags); in ffs_data_clear()
2239 ffs_epfiles_destroy(epfiles, ffs->eps_count); in ffs_data_clear()
2240 ffs->epfiles = NULL; in ffs_data_clear()
2243 if (ffs->ffs_eventfd) { in ffs_data_clear()
2244 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
2245 ffs->ffs_eventfd = NULL; in ffs_data_clear()
2248 kfree(ffs->raw_descs_data); in ffs_data_clear()
2249 kfree(ffs->raw_strings); in ffs_data_clear()
2250 kfree(ffs->stringtabs); in ffs_data_clear()
2253 static void ffs_data_reset(struct ffs_data *ffs) in ffs_data_reset() argument
2255 ffs_data_clear(ffs); in ffs_data_reset()
2257 ffs->raw_descs_data = NULL; in ffs_data_reset()
2258 ffs->raw_descs = NULL; in ffs_data_reset()
2259 ffs->raw_strings = NULL; in ffs_data_reset()
2260 ffs->stringtabs = NULL; in ffs_data_reset()
2262 ffs->raw_descs_length = 0; in ffs_data_reset()
2263 ffs->fs_descs_count = 0; in ffs_data_reset()
2264 ffs->hs_descs_count = 0; in ffs_data_reset()
2265 ffs->ss_descs_count = 0; in ffs_data_reset()
2267 ffs->strings_count = 0; in ffs_data_reset()
2268 ffs->interfaces_count = 0; in ffs_data_reset()
2269 ffs->eps_count = 0; in ffs_data_reset()
2271 ffs->ev.count = 0; in ffs_data_reset()
2273 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
2274 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
2275 ffs->flags = 0; in ffs_data_reset()
2277 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
2278 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
2279 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
2283 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) in functionfs_bind() argument
2288 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
2289 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
2292 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
2296 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
2297 if (!ffs->ep0req) in functionfs_bind()
2299 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
2300 ffs->ep0req->context = ffs; in functionfs_bind()
2302 lang = ffs->stringtabs; in functionfs_bind()
2312 ffs->gadget = cdev->gadget; in functionfs_bind()
2313 ffs_data_get(ffs); in functionfs_bind()
2317 static void functionfs_unbind(struct ffs_data *ffs) in functionfs_unbind() argument
2319 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
2321 usb_ep_dequeue(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
2322 mutex_lock(&ffs->mutex); in functionfs_unbind()
2323 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
2324 ffs->ep0req = NULL; in functionfs_unbind()
2325 ffs->gadget = NULL; in functionfs_unbind()
2326 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
2327 mutex_unlock(&ffs->mutex); in functionfs_unbind()
2328 ffs_data_put(ffs); in functionfs_unbind()
2332 static int ffs_epfiles_create(struct ffs_data *ffs) in ffs_epfiles_create() argument
2337 count = ffs->eps_count; in ffs_epfiles_create()
2344 epfile->ffs = ffs; in ffs_epfiles_create()
2348 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
2349 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
2352 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
2361 ffs->epfiles = epfiles; in ffs_epfiles_create()
2388 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
2389 count = func->ffs->eps_count; in ffs_func_eps_disable()
2390 epfile = func->ffs->epfiles; in ffs_func_eps_disable()
2404 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
2409 struct ffs_data *ffs; in ffs_func_eps_enable() local
2416 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
2417 ffs = func->ffs; in ffs_func_eps_enable()
2419 epfile = ffs->epfiles; in ffs_func_eps_enable()
2420 count = ffs->eps_count; in ffs_func_eps_enable()
2444 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
2445 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
2687 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2688 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2697 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2698 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2700 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2832 struct ffs_data *ffs = priv; in __ffs_data_do_os_desc() local
2841 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2865 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2889 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2891 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2892 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2902 static int __ffs_data_got_descs(struct ffs_data *ffs, in __ffs_data_got_descs() argument
2921 ffs->user_flags = flags; in __ffs_data_got_descs()
2943 ffs->ffs_eventfd = in __ffs_data_got_descs()
2945 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2946 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2947 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2977 helper.ffs = ffs; in __ffs_data_got_descs()
2987 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2988 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2989 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2991 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2995 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
3005 __ffs_data_do_os_desc, ffs); in __ffs_data_got_descs()
3017 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
3018 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
3019 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
3020 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
3021 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
3022 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
3023 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
3032 static int __ffs_data_got_strings(struct ffs_data *ffs, in __ffs_data_got_strings() argument
3052 needed_count = ffs->strings_count; in __ffs_data_got_strings()
3152 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
3153 ffs->raw_strings = _data; in __ffs_data_got_strings()
3167 static void __ffs_event_add(struct ffs_data *ffs, in __ffs_event_add() argument
3181 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
3182 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
3217 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
3218 unsigned n = ffs->ev.count; in __ffs_event_add()
3224 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
3228 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
3229 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
3230 if (ffs->ffs_eventfd) in __ffs_event_add()
3231 eventfd_signal(ffs->ffs_eventfd); in __ffs_event_add()
3234 static void ffs_event_add(struct ffs_data *ffs, in ffs_event_add() argument
3238 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
3239 __ffs_event_add(ffs, type); in ffs_event_add()
3240 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
3245 static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) in ffs_ep_addr2idx() argument
3249 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
3250 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
3289 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
3342 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
3382 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
3439 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
3440 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
3448 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
3449 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
3452 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
3453 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
3513 func->ffs = ffs_data; in ffs_do_functionfs_bind()
3525 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3530 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3539 struct ffs_data *ffs = func->ffs; in _ffs_func_bind() local
3541 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3542 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3543 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3550 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3552 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3554 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3556 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3557 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
3559 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3561 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3563 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3565 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3567 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3569 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3570 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3582 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3583 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3585 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3589 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3590 ffs->raw_descs_length); in _ffs_func_bind()
3594 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3610 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3624 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3639 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3656 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3657 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3658 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3666 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3676 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3686 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3689 ffs_event_add(ffs, FUNCTIONFS_BIND); in _ffs_func_bind()
3709 functionfs_unbind(func->ffs); in ffs_func_bind()
3719 struct ffs_data *ffs = container_of(work, in ffs_reset_work() local
3721 ffs_data_reset(ffs); in ffs_reset_work()
3737 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt() local
3747 if (ffs->func) in ffs_func_set_alt()
3748 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3750 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3751 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3752 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3753 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3757 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3760 ffs->func = func; in ffs_func_set_alt()
3763 ffs_event_add(ffs, FUNCTIONFS_ENABLE); in ffs_func_set_alt()
3772 struct ffs_data *ffs = func->ffs; in ffs_func_disable() local
3774 if (ffs->func) in ffs_func_disable()
3775 ffs_func_eps_disable(ffs->func); in ffs_func_disable()
3777 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_disable()
3778 ffs->state = FFS_CLOSING; in ffs_func_disable()
3779 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_disable()
3780 schedule_work(&ffs->reset_work); in ffs_func_disable()
3784 if (ffs->state == FFS_ACTIVE) { in ffs_func_disable()
3785 ffs->func = NULL; in ffs_func_disable()
3786 ffs_event_add(ffs, FUNCTIONFS_DISABLE); in ffs_func_disable()
3794 struct ffs_data *ffs = func->ffs; in ffs_func_setup() local
3814 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3828 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3829 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3833 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3839 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3840 ffs->ev.setup = *creq; in ffs_func_setup()
3841 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3842 __ffs_event_add(ffs, FUNCTIONFS_SETUP); in ffs_func_setup()
3843 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3845 return ffs->ev.setup.wLength == 0 ? USB_GADGET_DELAYED_STATUS : 0; in ffs_func_setup()
3854 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3865 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3872 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3877 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3892 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
4053 struct ffs_data *ffs = func->ffs; in ffs_func_unbind() local
4057 unsigned count = ffs->eps_count; in ffs_func_unbind()
4060 if (ffs->func == func) { in ffs_func_unbind()
4062 ffs->func = NULL; in ffs_func_unbind()
4066 drain_workqueue(ffs->io_completion_wq); in ffs_func_unbind()
4068 ffs_event_add(ffs, FUNCTIONFS_UNBIND); in ffs_func_unbind()
4070 functionfs_unbind(ffs); in ffs_func_unbind()
4073 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
4080 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
4238 static int ffs_ready(struct ffs_data *ffs) in ffs_ready() argument
4245 ffs_obj = ffs->private_data; in ffs_ready()
4258 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
4263 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
4269 static void ffs_closed(struct ffs_data *ffs) in ffs_closed() argument
4277 ffs_obj = ffs->private_data; in ffs_closed()
4283 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
4285 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
4299 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
4332 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc);