Lines Matching refs:ffs
45 static void ffs_data_get(struct ffs_data *ffs);
46 static void ffs_data_put(struct ffs_data *ffs);
51 static void ffs_data_opened(struct ffs_data *ffs);
52 static void ffs_data_closed(struct ffs_data *ffs);
56 __ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len);
58 __ffs_data_got_strings(struct ffs_data *ffs, char *data, size_t len);
68 struct ffs_data *ffs; member
85 ffs_setup_state_clear_cancelled(struct ffs_data *ffs) in ffs_setup_state_clear_cancelled() argument
88 cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP); in ffs_setup_state_clear_cancelled()
128 struct ffs_data *ffs; member
158 struct ffs_data *ffs; member
162 struct ffs_data *ffs; member
167 static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
185 static int ffs_ready(struct ffs_data *ffs);
186 static void ffs_closed(struct ffs_data *ffs);
200 struct ffs_data *ffs = req->context; in ffs_ep0_complete() local
202 complete_all(&ffs->ep0req_completion); in ffs_ep0_complete()
205 static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) in __ffs_ep0_queue_wait() argument
207 struct usb_request *req = ffs->ep0req; in __ffs_ep0_queue_wait()
210 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
212 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
225 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
227 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
231 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
233 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
237 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
241 static int __ffs_ep0_stall(struct ffs_data *ffs) in __ffs_ep0_stall() argument
243 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
245 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
246 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
257 struct ffs_data *ffs = file->private_data; in ffs_ep0_write() local
264 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_write()
268 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
273 switch (ffs->state) { in ffs_ep0_write()
289 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
291 ret = __ffs_data_got_descs(ffs, data, len); in ffs_ep0_write()
295 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
299 ret = __ffs_data_got_strings(ffs, data, len); in ffs_ep0_write()
303 ret = ffs_epfiles_create(ffs); in ffs_ep0_write()
305 ffs->state = FFS_CLOSING; in ffs_ep0_write()
309 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
310 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
312 ret = ffs_ready(ffs); in ffs_ep0_write()
314 ffs->state = FFS_CLOSING; in ffs_ep0_write()
328 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
329 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_write()
343 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
344 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
345 ret = __ffs_ep0_stall(ffs); in ffs_ep0_write()
350 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
352 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
360 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
374 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_write()
378 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
381 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_write()
391 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
396 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, in __ffs_ep0_read_events() argument
404 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
411 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
413 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
414 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
418 ffs->ev.count -= n; in __ffs_ep0_read_events()
419 if (ffs->ev.count) in __ffs_ep0_read_events()
420 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
421 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
423 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
424 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
432 struct ffs_data *ffs = file->private_data; in ffs_ep0_read() local
440 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED) in ffs_ep0_read()
444 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
449 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
458 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
460 switch (ffs_setup_state_clear_cancelled(ffs)) { in ffs_ep0_read()
472 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
477 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
478 ffs->ev.count)) { in ffs_ep0_read()
483 return __ffs_ep0_read_events(ffs, buf, in ffs_ep0_read()
484 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
487 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
488 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
489 ret = __ffs_ep0_stall(ffs); in ffs_ep0_read()
493 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
495 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
505 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
508 if (ffs_setup_state_clear_cancelled(ffs) == in ffs_ep0_read()
515 ret = __ffs_ep0_queue_wait(ffs, data, len); in ffs_ep0_read()
525 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
527 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
534 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open() local
538 if (unlikely(ffs->state == FFS_CLOSING)) in ffs_ep0_open()
541 file->private_data = ffs; in ffs_ep0_open()
542 ffs_data_opened(ffs); in ffs_ep0_open()
549 struct ffs_data *ffs = file->private_data; in ffs_ep0_release() local
553 ffs_data_closed(ffs); in ffs_ep0_release()
560 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl() local
561 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
567 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
580 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll() local
584 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
586 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
590 switch (ffs->state) { in ffs_ep0_poll()
597 switch (ffs->setup_state) { in ffs_ep0_poll()
599 if (ffs->ev.count) in ffs_ep0_poll()
614 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
661 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
662 eventfd_signal(io_data->ffs->ffs_eventfd, 1); in ffs_user_copy_worker()
692 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) { in ffs_epfile_io()
725 struct usb_gadget *gadget = epfile->ffs->gadget; in ffs_epfile_io()
728 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
731 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
741 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
760 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
765 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
770 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
804 io_data->ffs = epfile->ffs; in ffs_epfile_io()
816 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
829 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
860 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
874 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
878 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
891 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_aio_cancel()
898 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_aio_cancel()
994 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1007 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1010 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1031 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1043 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1055 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1115 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file() local
1125 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1153 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill() local
1157 ffs->sb = sb; in ffs_sb_fill()
1159 sb->s_fs_info = ffs; in ffs_sb_fill()
1177 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs, in ffs_sb_fill()
1291 struct ffs_data *ffs; in ffs_fs_mount() local
1299 ffs = ffs_data_new(); in ffs_fs_mount()
1300 if (unlikely(!ffs)) in ffs_fs_mount()
1302 ffs->file_perms = data.perms; in ffs_fs_mount()
1303 ffs->no_disconnect = data.no_disconnect; in ffs_fs_mount()
1305 ffs->dev_name = kstrdup(dev_name, GFP_KERNEL); in ffs_fs_mount()
1306 if (unlikely(!ffs->dev_name)) { in ffs_fs_mount()
1307 ffs_data_put(ffs); in ffs_fs_mount()
1313 ffs_data_put(ffs); in ffs_fs_mount()
1316 ffs->private_data = ffs_dev; in ffs_fs_mount()
1317 data.ffs_data = ffs; in ffs_fs_mount()
1377 static void ffs_data_clear(struct ffs_data *ffs);
1378 static void ffs_data_reset(struct ffs_data *ffs);
1380 static void ffs_data_get(struct ffs_data *ffs) in ffs_data_get() argument
1384 atomic_inc(&ffs->ref); in ffs_data_get()
1387 static void ffs_data_opened(struct ffs_data *ffs) in ffs_data_opened() argument
1391 atomic_inc(&ffs->ref); in ffs_data_opened()
1392 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1393 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1394 ffs->state = FFS_CLOSING; in ffs_data_opened()
1395 ffs_data_reset(ffs); in ffs_data_opened()
1399 static void ffs_data_put(struct ffs_data *ffs) in ffs_data_put() argument
1403 if (unlikely(atomic_dec_and_test(&ffs->ref))) { in ffs_data_put()
1405 ffs_data_clear(ffs); in ffs_data_put()
1406 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1407 waitqueue_active(&ffs->ep0req_completion.wait)); in ffs_data_put()
1408 kfree(ffs->dev_name); in ffs_data_put()
1409 kfree(ffs); in ffs_data_put()
1413 static void ffs_data_closed(struct ffs_data *ffs) in ffs_data_closed() argument
1417 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1418 if (ffs->no_disconnect) { in ffs_data_closed()
1419 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1420 if (ffs->epfiles) { in ffs_data_closed()
1421 ffs_epfiles_destroy(ffs->epfiles, in ffs_data_closed()
1422 ffs->eps_count); in ffs_data_closed()
1423 ffs->epfiles = NULL; in ffs_data_closed()
1425 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1426 __ffs_ep0_stall(ffs); in ffs_data_closed()
1428 ffs->state = FFS_CLOSING; in ffs_data_closed()
1429 ffs_data_reset(ffs); in ffs_data_closed()
1432 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1433 ffs->state = FFS_CLOSING; in ffs_data_closed()
1434 ffs_data_reset(ffs); in ffs_data_closed()
1437 ffs_data_put(ffs); in ffs_data_closed()
1442 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); in ffs_data_new() local
1443 if (unlikely(!ffs)) in ffs_data_new()
1448 atomic_set(&ffs->ref, 1); in ffs_data_new()
1449 atomic_set(&ffs->opened, 0); in ffs_data_new()
1450 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1451 mutex_init(&ffs->mutex); in ffs_data_new()
1452 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1453 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1454 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1457 ffs->ev.can_stall = 1; in ffs_data_new()
1459 return ffs; in ffs_data_new()
1462 static void ffs_data_clear(struct ffs_data *ffs) in ffs_data_clear() argument
1466 ffs_closed(ffs); in ffs_data_clear()
1468 BUG_ON(ffs->gadget); in ffs_data_clear()
1470 if (ffs->epfiles) in ffs_data_clear()
1471 ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count); in ffs_data_clear()
1473 if (ffs->ffs_eventfd) in ffs_data_clear()
1474 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1476 kfree(ffs->raw_descs_data); in ffs_data_clear()
1477 kfree(ffs->raw_strings); in ffs_data_clear()
1478 kfree(ffs->stringtabs); in ffs_data_clear()
1481 static void ffs_data_reset(struct ffs_data *ffs) in ffs_data_reset() argument
1485 ffs_data_clear(ffs); in ffs_data_reset()
1487 ffs->epfiles = NULL; in ffs_data_reset()
1488 ffs->raw_descs_data = NULL; in ffs_data_reset()
1489 ffs->raw_descs = NULL; in ffs_data_reset()
1490 ffs->raw_strings = NULL; in ffs_data_reset()
1491 ffs->stringtabs = NULL; in ffs_data_reset()
1493 ffs->raw_descs_length = 0; in ffs_data_reset()
1494 ffs->fs_descs_count = 0; in ffs_data_reset()
1495 ffs->hs_descs_count = 0; in ffs_data_reset()
1496 ffs->ss_descs_count = 0; in ffs_data_reset()
1498 ffs->strings_count = 0; in ffs_data_reset()
1499 ffs->interfaces_count = 0; in ffs_data_reset()
1500 ffs->eps_count = 0; in ffs_data_reset()
1502 ffs->ev.count = 0; in ffs_data_reset()
1504 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1505 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1506 ffs->flags = 0; in ffs_data_reset()
1510 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) in functionfs_bind() argument
1517 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1518 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1521 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1525 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1526 if (unlikely(!ffs->ep0req)) in functionfs_bind()
1528 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1529 ffs->ep0req->context = ffs; in functionfs_bind()
1531 lang = ffs->stringtabs; in functionfs_bind()
1541 ffs->gadget = cdev->gadget; in functionfs_bind()
1542 ffs_data_get(ffs); in functionfs_bind()
1546 static void functionfs_unbind(struct ffs_data *ffs) in functionfs_unbind() argument
1550 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1551 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1552 ffs->ep0req = NULL; in functionfs_unbind()
1553 ffs->gadget = NULL; in functionfs_unbind()
1554 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1555 ffs_data_put(ffs); in functionfs_unbind()
1559 static int ffs_epfiles_create(struct ffs_data *ffs) in ffs_epfiles_create() argument
1566 count = ffs->eps_count; in ffs_epfiles_create()
1573 epfile->ffs = ffs; in ffs_epfiles_create()
1576 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1577 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1580 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1589 ffs->epfiles = epfiles; in ffs_epfiles_create()
1615 struct ffs_epfile *epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1616 unsigned count = func->ffs->eps_count; in ffs_func_eps_disable()
1619 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1631 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1636 struct ffs_data *ffs = func->ffs; in ffs_func_eps_enable() local
1638 struct ffs_epfile *epfile = ffs->epfiles; in ffs_func_eps_enable()
1639 unsigned count = ffs->eps_count; in ffs_func_eps_enable()
1643 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1648 if (ffs->gadget->speed == USB_SPEED_SUPER) in ffs_func_eps_enable()
1650 else if (ffs->gadget->speed == USB_SPEED_HIGH) in ffs_func_eps_enable()
1681 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1907 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
1908 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
1917 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
1918 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
1920 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2053 struct ffs_data *ffs = priv; in __ffs_data_do_os_desc() local
2064 d->bFirstInterfaceNumber >= ffs->interfaces_count || in __ffs_data_do_os_desc()
2079 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2096 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2098 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2099 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2109 static int __ffs_data_got_descs(struct ffs_data *ffs, in __ffs_data_got_descs() argument
2130 ffs->user_flags = flags; in __ffs_data_got_descs()
2150 ffs->ffs_eventfd = in __ffs_data_got_descs()
2152 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2153 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2154 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2181 helper.ffs = ffs; in __ffs_data_got_descs()
2191 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2192 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2193 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2195 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2199 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2209 __ffs_data_do_os_desc, ffs); in __ffs_data_got_descs()
2221 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2222 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2223 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2224 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2225 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2226 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2227 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2236 static int __ffs_data_got_strings(struct ffs_data *ffs, in __ffs_data_got_strings() argument
2257 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2357 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2358 ffs->raw_strings = _data; in __ffs_data_got_strings()
2372 static void __ffs_event_add(struct ffs_data *ffs, in __ffs_event_add() argument
2386 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2387 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2422 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2423 unsigned n = ffs->ev.count; in __ffs_event_add()
2429 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2433 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2434 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2435 if (ffs->ffs_eventfd) in __ffs_event_add()
2436 eventfd_signal(ffs->ffs_eventfd, 1); in __ffs_event_add()
2439 static void ffs_event_add(struct ffs_data *ffs, in ffs_event_add() argument
2443 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2444 __ffs_event_add(ffs, type); in ffs_event_add()
2445 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2450 static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) in ffs_ep_addr2idx() argument
2454 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2455 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2494 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2541 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2576 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
2634 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
2635 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
2643 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
2644 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
2647 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
2648 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
2703 func->ffs = ffs_opts->dev->ffs_data; in ffs_do_functionfs_bind()
2720 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
2725 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
2734 struct ffs_data *ffs = func->ffs; in _ffs_func_bind() local
2736 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
2738 func->ffs->hs_descs_count; in _ffs_func_bind()
2740 func->ffs->ss_descs_count; in _ffs_func_bind()
2746 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
2748 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
2750 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
2752 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
2753 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
2755 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
2757 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
2759 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
2761 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
2763 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
2765 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
2766 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
2780 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
2781 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
2783 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
2787 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
2788 ffs->raw_descs_length); in _ffs_func_bind()
2791 for (ret = ffs->eps_count; ret; --ret) { in _ffs_func_bind()
2811 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
2825 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
2839 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
2856 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
2857 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
2858 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
2866 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
2876 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
2884 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
2887 ffs_event_add(ffs, FUNCTIONFS_BIND); in _ffs_func_bind()
2907 functionfs_unbind(func->ffs); in ffs_func_bind()
2917 struct ffs_data *ffs = container_of(work, in ffs_reset_work() local
2919 ffs_data_reset(ffs); in ffs_reset_work()
2926 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt() local
2935 if (ffs->func) in ffs_func_set_alt()
2936 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
2938 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
2939 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
2940 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
2941 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
2945 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
2949 ffs->func = NULL; in ffs_func_set_alt()
2950 ffs_event_add(ffs, FUNCTIONFS_DISABLE); in ffs_func_set_alt()
2954 ffs->func = func; in ffs_func_set_alt()
2957 ffs_event_add(ffs, FUNCTIONFS_ENABLE); in ffs_func_set_alt()
2970 struct ffs_data *ffs = func->ffs; in ffs_func_setup() local
2991 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3005 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3006 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3013 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3014 ffs->ev.setup = *creq; in ffs_func_setup()
3015 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3016 __ffs_event_add(ffs, FUNCTIONFS_SETUP); in ffs_func_setup()
3017 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3025 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3031 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3046 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3216 struct ffs_data *ffs = func->ffs; in ffs_func_unbind() local
3220 unsigned count = ffs->eps_count; in ffs_func_unbind()
3224 if (ffs->func == func) { in ffs_func_unbind()
3226 ffs->func = NULL; in ffs_func_unbind()
3230 functionfs_unbind(ffs); in ffs_func_unbind()
3233 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3240 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3252 ffs_event_add(ffs, FUNCTIONFS_UNBIND); in ffs_func_unbind()
3409 static int ffs_ready(struct ffs_data *ffs) in ffs_ready() argument
3417 ffs_obj = ffs->private_data; in ffs_ready()
3428 ffs_obj->ffs_data = ffs; in ffs_ready()
3431 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3436 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3442 static void ffs_closed(struct ffs_data *ffs) in ffs_closed() argument
3450 ffs_obj = ffs->private_data; in ffs_closed()
3456 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3458 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3506 DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc);