Lines Matching +full:num +full:- +full:strings
1 // SPDX-License-Identifier: GPL-2.0+
3 * f_fs.c -- user mode file system API for USB composite function controllers
9 * Copyright (C) 2003-2004 David Brownell
57 /* Called with ffs->mutex held; take over ownership of data. */
91 cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP); in ffs_setup_state_clear_cancelled()
111 static int ffs_func_revmap_ep(struct ffs_function *func, u8 num);
118 struct usb_ep *ep; /* P: ffs->eps_lock */
119 struct usb_request *req; /* P: epfile->mutex */
124 u8 num; member
126 int status; /* P: epfile->mutex */
130 /* Protects ep->ep and ep->req. */
134 struct ffs_ep *ep; /* P: ffs->eps_lock */
149 * can never run concurrently (they are synchronised by epfile->mutex)
159 * pointer is not-NULL (namely READ_BUFFER_DROP) it will instead free
194 #define READ_BUFFER_DROP ((struct ffs_buffer *)ERR_PTR(-ESHUTDOWN))
198 unsigned char in; /* P: ffs->eps_lock */
199 unsigned char isoc; /* P: ffs->eps_lock */
270 struct ffs_data *ffs = req->context; in ffs_ep0_complete()
272 complete(&ffs->ep0req_completion); in ffs_ep0_complete()
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()
285 req->buf = data; in __ffs_ep0_queue_wait()
286 req->length = len; in __ffs_ep0_queue_wait()
293 if (req->buf == NULL) in __ffs_ep0_queue_wait()
294 req->buf = (void *)0xDEADBABE; 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()
305 return -EINTR; in __ffs_ep0_queue_wait()
308 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
309 return req->status ? req->status : req->actual; in __ffs_ep0_queue_wait()
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()
318 return -EL2HLT; in __ffs_ep0_stall()
321 return -ESRCH; in __ffs_ep0_stall()
328 struct ffs_data *ffs = file->private_data; in ffs_ep0_write()
336 return -EIDRM; 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()
349 ret = -EINVAL; in ffs_ep0_write()
360 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
366 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
369 pr_info("read strings\n"); 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()
385 ffs->state = FFS_CLOSING; in ffs_ep0_write()
399 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
402 ret = -EIDRM; in ffs_ep0_write()
406 ret = -ESRCH; 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()
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()
441 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP in ffs_ep0_write()
447 ret = -EIDRM; in ffs_ep0_write()
449 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
458 ret = -EBADFD; in ffs_ep0_write()
462 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
466 /* Called with ffs->ev.waitq.lock and ffs->mutex held, both released on exit. */
469 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
472 * n cannot be bigger than ffs->ev.count, which cannot be bigger than in __ffs_ep0_read_events()
473 * size of ffs->ev.types array (which is four) so that's how much space 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()
498 return copy_to_user(buf, events, size) ? -EFAULT : size; in __ffs_ep0_read_events()
504 struct ffs_data *ffs = file->private_data; in ffs_ep0_read()
513 return -EIDRM; 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()
522 ret = -EBADFD; in ffs_ep0_read()
530 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
534 ret = -EIDRM; in ffs_ep0_read()
540 ret = -EINVAL; in ffs_ep0_read()
544 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
545 ret = -EAGAIN; 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()
551 ret = -EINTR; 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()
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()
573 ret = -ENOMEM; in ffs_ep0_read()
578 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
583 ret = -EIDRM; in ffs_ep0_read()
590 ret = -EFAULT; in ffs_ep0_read()
594 ret = -EBADFD; 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()
611 if (ffs->state == FFS_CLOSING) in ffs_ep0_open()
612 return -EBUSY; in ffs_ep0_open()
614 file->private_data = ffs; in ffs_ep0_open()
622 struct ffs_data *ffs = file->private_data; in ffs_ep0_release()
633 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl()
634 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
640 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
641 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV; in ffs_ep0_ioctl()
642 } else if (gadget && gadget->ops->ioctl) { in ffs_ep0_ioctl()
643 ret = gadget->ops->ioctl(gadget, code, value); in ffs_ep0_ioctl()
645 ret = -ENOTTY; in ffs_ep0_ioctl()
653 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll()
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()
689 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
711 if (req->context) { in ffs_epfile_io_complete()
712 struct ffs_ep *ep = _ep->driver_data; in ffs_epfile_io_complete()
713 ep->status = req->status ? req->status : req->actual; in ffs_epfile_io_complete()
714 complete(req->context); in ffs_epfile_io_complete()
725 return -EFAULT; in ffs_copy_to_iter()
763 * @sg_table - pointer to a place to be filled with sg_table contents
764 * @size - required buffer size
801 if (io_data->use_sg) in ffs_alloc_buffer()
802 return ffs_build_sg_list(&io_data->sgt, data_len); in ffs_alloc_buffer()
809 if (!io_data->buf) in ffs_free_buffer()
812 if (io_data->use_sg) { in ffs_free_buffer()
813 sg_free_table(&io_data->sgt); in ffs_free_buffer()
814 vfree(io_data->buf); in ffs_free_buffer()
816 kfree(io_data->buf); in ffs_free_buffer()
824 int ret = io_data->req->status ? io_data->req->status : in ffs_user_copy_worker()
825 io_data->req->actual; in ffs_user_copy_worker()
826 bool kiocb_has_eventfd = io_data->kiocb->ki_flags & IOCB_EVENTFD; in ffs_user_copy_worker()
828 if (io_data->read && ret > 0) { in ffs_user_copy_worker()
829 kthread_use_mm(io_data->mm); in ffs_user_copy_worker()
830 ret = ffs_copy_to_iter(io_data->buf, ret, &io_data->data); in ffs_user_copy_worker()
831 kthread_unuse_mm(io_data->mm); in ffs_user_copy_worker()
834 io_data->kiocb->ki_complete(io_data->kiocb, ret, ret); in ffs_user_copy_worker()
836 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
837 eventfd_signal(io_data->ffs->ffs_eventfd, 1); in ffs_user_copy_worker()
839 usb_ep_free_request(io_data->ep, io_data->req); in ffs_user_copy_worker()
841 if (io_data->read) in ffs_user_copy_worker()
842 kfree(io_data->to_free); in ffs_user_copy_worker()
850 struct ffs_io_data *io_data = req->context; in ffs_epfile_async_io_complete()
851 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete()
855 INIT_WORK(&io_data->work, ffs_user_copy_worker); in ffs_epfile_async_io_complete()
856 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
865 struct ffs_buffer *buf = xchg(&epfile->read_buffer, READ_BUFFER_DROP); in __ffs_epfile_read_buffer_free()
870 /* Assumes epfile->mutex is held. */
875 * Null out epfile->read_buffer so ffs_func_eps_disable does not free in __ffs_epfile_read_buffered()
879 struct ffs_buffer *buf = xchg(&epfile->read_buffer, NULL); in __ffs_epfile_read_buffered()
884 ret = copy_to_iter(buf->data, buf->length, iter); in __ffs_epfile_read_buffered()
885 if (buf->length == ret) { in __ffs_epfile_read_buffered()
891 ret = -EFAULT; in __ffs_epfile_read_buffered()
893 buf->length -= ret; in __ffs_epfile_read_buffered()
894 buf->data += ret; in __ffs_epfile_read_buffered()
897 if (cmpxchg(&epfile->read_buffer, NULL, buf)) in __ffs_epfile_read_buffered()
903 /* Assumes epfile->mutex is held. */
915 return -EFAULT; in __ffs_epfile_read_data()
921 data_len -= ret; in __ffs_epfile_read_data()
924 return -ENOMEM; in __ffs_epfile_read_data()
925 buf->length = data_len; in __ffs_epfile_read_data()
926 buf->data = buf->storage; in __ffs_epfile_read_data()
927 memcpy(buf->storage, data + ret, data_len); in __ffs_epfile_read_data()
935 if (cmpxchg(&epfile->read_buffer, NULL, buf)) in __ffs_epfile_read_data()
943 struct ffs_epfile *epfile = file->private_data; in ffs_epfile_io()
947 ssize_t ret, data_len = -EINVAL; in ffs_epfile_io()
951 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
952 return -ENODEV; in ffs_epfile_io()
955 ep = epfile->ep; in ffs_epfile_io()
957 if (file->f_flags & O_NONBLOCK) in ffs_epfile_io()
958 return -EAGAIN; in ffs_epfile_io()
961 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_io()
963 return -EINTR; in ffs_epfile_io()
967 halt = (!io_data->read == !epfile->in); in ffs_epfile_io()
968 if (halt && epfile->isoc) in ffs_epfile_io()
969 return -EINVAL; in ffs_epfile_io()
972 ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); in ffs_epfile_io()
987 if (!io_data->aio && io_data->read) { in ffs_epfile_io()
988 ret = __ffs_epfile_read_buffered(epfile, &io_data->data); in ffs_epfile_io()
994 * if we _do_ wait above, the epfile->ffs->gadget might be NULL in ffs_epfile_io()
998 gadget = epfile->ffs->gadget; in ffs_epfile_io()
1000 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1002 if (epfile->ep != ep) { in ffs_epfile_io()
1003 ret = -ESHUTDOWN; in ffs_epfile_io()
1006 data_len = iov_iter_count(&io_data->data); in ffs_epfile_io()
1011 if (io_data->read) in ffs_epfile_io()
1012 data_len = usb_ep_align_maybe(gadget, ep->ep, data_len); in ffs_epfile_io()
1014 io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; in ffs_epfile_io()
1015 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1019 ret = -ENOMEM; in ffs_epfile_io()
1022 if (!io_data->read && in ffs_epfile_io()
1023 !copy_from_iter_full(data, data_len, &io_data->data)) { in ffs_epfile_io()
1024 ret = -EFAULT; in ffs_epfile_io()
1029 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1031 if (epfile->ep != ep) { in ffs_epfile_io()
1033 ret = -ESHUTDOWN; in ffs_epfile_io()
1035 ret = usb_ep_set_halt(ep->ep); in ffs_epfile_io()
1037 ret = -EBADMSG; in ffs_epfile_io()
1038 } else if (data_len == -EINVAL) { in ffs_epfile_io()
1044 * being initialized to -EINVAL during its declaration, which in ffs_epfile_io()
1050 WARN(1, "%s: data_len == -EINVAL\n", __func__); in ffs_epfile_io()
1051 ret = -EINVAL; in ffs_epfile_io()
1052 } else if (!io_data->aio) { in ffs_epfile_io()
1056 req = ep->req; in ffs_epfile_io()
1057 if (io_data->use_sg) { in ffs_epfile_io()
1058 req->buf = NULL; in ffs_epfile_io()
1059 req->sg = io_data->sgt.sgl; in ffs_epfile_io()
1060 req->num_sgs = io_data->sgt.nents; in ffs_epfile_io()
1062 req->buf = data; in ffs_epfile_io()
1063 req->num_sgs = 0; in ffs_epfile_io()
1065 req->length = data_len; in ffs_epfile_io()
1067 io_data->buf = data; in ffs_epfile_io()
1069 req->context = &done; in ffs_epfile_io()
1070 req->complete = ffs_epfile_io_complete; in ffs_epfile_io()
1072 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); in ffs_epfile_io()
1076 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1083 * condition with req->complete callback. in ffs_epfile_io()
1085 usb_ep_dequeue(ep->ep, req); in ffs_epfile_io()
1087 interrupted = ep->status < 0; in ffs_epfile_io()
1091 ret = -EINTR; in ffs_epfile_io()
1092 else if (io_data->read && ep->status > 0) in ffs_epfile_io()
1093 ret = __ffs_epfile_read_data(epfile, data, ep->status, in ffs_epfile_io()
1094 &io_data->data); in ffs_epfile_io()
1096 ret = ep->status; in ffs_epfile_io()
1098 } else if (!(req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC))) { in ffs_epfile_io()
1099 ret = -ENOMEM; in ffs_epfile_io()
1101 if (io_data->use_sg) { in ffs_epfile_io()
1102 req->buf = NULL; in ffs_epfile_io()
1103 req->sg = io_data->sgt.sgl; in ffs_epfile_io()
1104 req->num_sgs = io_data->sgt.nents; in ffs_epfile_io()
1106 req->buf = data; in ffs_epfile_io()
1107 req->num_sgs = 0; in ffs_epfile_io()
1109 req->length = data_len; in ffs_epfile_io()
1111 io_data->buf = data; in ffs_epfile_io()
1112 io_data->ep = ep->ep; in ffs_epfile_io()
1113 io_data->req = req; in ffs_epfile_io()
1114 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1116 req->context = io_data; in ffs_epfile_io()
1117 req->complete = ffs_epfile_async_io_complete; in ffs_epfile_io()
1119 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); in ffs_epfile_io()
1121 io_data->req = NULL; in ffs_epfile_io()
1122 usb_ep_free_request(ep->ep, req); in ffs_epfile_io()
1126 ret = -EIOCBQUEUED; in ffs_epfile_io()
1135 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1137 mutex_unlock(&epfile->mutex); in ffs_epfile_io()
1139 if (ret != -EIOCBQUEUED) /* don't free if there is iocb queued */ in ffs_epfile_io()
1147 struct ffs_epfile *epfile = inode->i_private; in ffs_epfile_open()
1151 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1152 return -ENODEV; in ffs_epfile_open()
1154 file->private_data = epfile; in ffs_epfile_open()
1155 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
1162 struct ffs_io_data *io_data = kiocb->private; in ffs_aio_cancel()
1163 struct ffs_epfile *epfile = kiocb->ki_filp->private_data; in ffs_aio_cancel()
1169 spin_lock_irqsave(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1171 if (io_data && io_data->ep && io_data->req) in ffs_aio_cancel()
1172 value = usb_ep_dequeue(io_data->ep, io_data->req); in ffs_aio_cancel()
1174 value = -EINVAL; in ffs_aio_cancel()
1176 spin_unlock_irqrestore(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1191 return -ENOMEM; in ffs_epfile_write_iter()
1192 p->aio = true; in ffs_epfile_write_iter()
1195 p->aio = false; in ffs_epfile_write_iter()
1198 p->read = false; in ffs_epfile_write_iter()
1199 p->kiocb = kiocb; in ffs_epfile_write_iter()
1200 p->data = *from; in ffs_epfile_write_iter()
1201 p->mm = current->mm; in ffs_epfile_write_iter()
1203 kiocb->private = p; in ffs_epfile_write_iter()
1205 if (p->aio) in ffs_epfile_write_iter()
1208 res = ffs_epfile_io(kiocb->ki_filp, p); in ffs_epfile_write_iter()
1209 if (res == -EIOCBQUEUED) in ffs_epfile_write_iter()
1211 if (p->aio) in ffs_epfile_write_iter()
1214 *from = p->data; in ffs_epfile_write_iter()
1228 return -ENOMEM; in ffs_epfile_read_iter()
1229 p->aio = true; in ffs_epfile_read_iter()
1232 p->aio = false; in ffs_epfile_read_iter()
1235 p->read = true; in ffs_epfile_read_iter()
1236 p->kiocb = kiocb; in ffs_epfile_read_iter()
1237 if (p->aio) { in ffs_epfile_read_iter()
1238 p->to_free = dup_iter(&p->data, to, GFP_KERNEL); in ffs_epfile_read_iter()
1239 if (!p->to_free) { in ffs_epfile_read_iter()
1241 return -ENOMEM; in ffs_epfile_read_iter()
1244 p->data = *to; in ffs_epfile_read_iter()
1245 p->to_free = NULL; in ffs_epfile_read_iter()
1247 p->mm = current->mm; in ffs_epfile_read_iter()
1249 kiocb->private = p; in ffs_epfile_read_iter()
1251 if (p->aio) in ffs_epfile_read_iter()
1254 res = ffs_epfile_io(kiocb->ki_filp, p); in ffs_epfile_read_iter()
1255 if (res == -EIOCBQUEUED) in ffs_epfile_read_iter()
1258 if (p->aio) { in ffs_epfile_read_iter()
1259 kfree(p->to_free); in ffs_epfile_read_iter()
1262 *to = p->data; in ffs_epfile_read_iter()
1270 struct ffs_epfile *epfile = inode->i_private; in ffs_epfile_release()
1275 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1283 struct ffs_epfile *epfile = file->private_data; in ffs_epfile_ioctl()
1289 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1290 return -ENODEV; in ffs_epfile_ioctl()
1293 ep = epfile->ep; in ffs_epfile_ioctl()
1295 if (file->f_flags & O_NONBLOCK) in ffs_epfile_ioctl()
1296 return -EAGAIN; in ffs_epfile_ioctl()
1299 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_ioctl()
1301 return -EINTR; in ffs_epfile_ioctl()
1304 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1307 if (epfile->ep != ep) { in ffs_epfile_ioctl()
1308 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1309 return -ESHUTDOWN; in ffs_epfile_ioctl()
1314 ret = usb_ep_fifo_status(epfile->ep->ep); in ffs_epfile_ioctl()
1317 usb_ep_fifo_flush(epfile->ep->ep); in ffs_epfile_ioctl()
1321 ret = usb_ep_clear_halt(epfile->ep->ep); in ffs_epfile_ioctl()
1324 ret = epfile->ep->num; in ffs_epfile_ioctl()
1331 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1343 desc = epfile->ep->descs[desc_idx]; in ffs_epfile_ioctl()
1344 memcpy(&desc1, desc, desc->bLength); in ffs_epfile_ioctl()
1346 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1349 ret = -EFAULT; in ffs_epfile_ioctl()
1353 ret = -ENOTTY; in ffs_epfile_ioctl()
1355 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1394 inode->i_ino = get_next_ino(); in ffs_sb_make_inode()
1395 inode->i_mode = perms->mode; in ffs_sb_make_inode()
1396 inode->i_uid = perms->uid; in ffs_sb_make_inode()
1397 inode->i_gid = perms->gid; in ffs_sb_make_inode()
1398 inode->i_atime = ts; in ffs_sb_make_inode()
1399 inode->i_mtime = ts; in ffs_sb_make_inode()
1400 inode->i_ctime = ts; in ffs_sb_make_inode()
1401 inode->i_private = data; in ffs_sb_make_inode()
1403 inode->i_fop = fops; in ffs_sb_make_inode()
1405 inode->i_op = iops; in ffs_sb_make_inode()
1416 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file()
1422 dentry = d_alloc_name(sb->s_root, name); in ffs_sb_create_file()
1426 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1452 struct ffs_sb_fill_data *data = fc->fs_private; in ffs_sb_fill()
1454 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill()
1458 ffs->sb = sb; in ffs_sb_fill()
1459 data->ffs_data = NULL; in ffs_sb_fill()
1460 sb->s_fs_info = ffs; in ffs_sb_fill()
1461 sb->s_blocksize = PAGE_SIZE; in ffs_sb_fill()
1462 sb->s_blocksize_bits = PAGE_SHIFT; in ffs_sb_fill()
1463 sb->s_magic = FUNCTIONFS_MAGIC; in ffs_sb_fill()
1464 sb->s_op = &ffs_sb_operations; in ffs_sb_fill()
1465 sb->s_time_gran = 1; in ffs_sb_fill()
1468 data->perms.mode = data->root_mode; in ffs_sb_fill()
1472 &data->perms); in ffs_sb_fill()
1473 sb->s_root = d_make_root(inode); in ffs_sb_fill()
1474 if (!sb->s_root) in ffs_sb_fill()
1475 return -ENOMEM; in ffs_sb_fill()
1479 return -ENOMEM; in ffs_sb_fill()
1505 struct ffs_sb_fill_data *data = fc->fs_private; in ffs_fs_parse_param()
1517 data->no_disconnect = result.boolean; in ffs_fs_parse_param()
1520 data->root_mode = (result.uint_32 & 0555) | S_IFDIR; in ffs_fs_parse_param()
1523 data->perms.mode = (result.uint_32 & 0666) | S_IFREG; in ffs_fs_parse_param()
1526 data->root_mode = (result.uint_32 & 0555) | S_IFDIR; in ffs_fs_parse_param()
1527 data->perms.mode = (result.uint_32 & 0666) | S_IFREG; in ffs_fs_parse_param()
1531 data->perms.uid = make_kuid(current_user_ns(), result.uint_32); in ffs_fs_parse_param()
1532 if (!uid_valid(data->perms.uid)) in ffs_fs_parse_param()
1536 data->perms.gid = make_kgid(current_user_ns(), result.uint_32); in ffs_fs_parse_param()
1537 if (!gid_valid(data->perms.gid)) in ffs_fs_parse_param()
1542 return -ENOPARAM; in ffs_fs_parse_param()
1548 return invalf(fc, "%s: unmapped value: %u", param->key, result.uint_32); in ffs_fs_parse_param()
1556 struct ffs_sb_fill_data *ctx = fc->fs_private; in ffs_fs_get_tree()
1562 if (!fc->source) in ffs_fs_get_tree()
1565 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
1567 return -ENOMEM; in ffs_fs_get_tree()
1568 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
1569 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
1571 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
1572 if (!ffs->dev_name) { in ffs_fs_get_tree()
1574 return -ENOMEM; in ffs_fs_get_tree()
1577 ret = ffs_acquire_dev(ffs->dev_name, ffs); in ffs_fs_get_tree()
1583 ctx->ffs_data = ffs; in ffs_fs_get_tree()
1589 struct ffs_sb_fill_data *ctx = fc->fs_private; in ffs_fs_free_fc()
1592 if (ctx->ffs_data) { in ffs_fs_free_fc()
1593 ffs_data_put(ctx->ffs_data); in ffs_fs_free_fc()
1612 return -ENOMEM; in ffs_fs_init_fs_context()
1614 ctx->perms.mode = S_IFREG | 0600; in ffs_fs_init_fs_context()
1615 ctx->perms.uid = GLOBAL_ROOT_UID; in ffs_fs_init_fs_context()
1616 ctx->perms.gid = GLOBAL_ROOT_GID; in ffs_fs_init_fs_context()
1617 ctx->root_mode = S_IFDIR | 0500; in ffs_fs_init_fs_context()
1618 ctx->no_disconnect = false; in ffs_fs_init_fs_context()
1620 fc->fs_private = ctx; in ffs_fs_init_fs_context()
1621 fc->ops = &ffs_fs_context_ops; in ffs_fs_init_fs_context()
1631 if (sb->s_fs_info) in ffs_fs_kill_sb()
1632 ffs_data_closed(sb->s_fs_info); in ffs_fs_kill_sb()
1680 refcount_inc(&ffs->ref); in ffs_data_get()
1687 refcount_inc(&ffs->ref); in ffs_data_opened()
1688 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1689 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1690 ffs->state = FFS_CLOSING; in ffs_data_opened()
1699 if (refcount_dec_and_test(&ffs->ref)) { in ffs_data_put()
1702 ffs_release_dev(ffs->private_data); in ffs_data_put()
1703 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1704 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1705 waitqueue_active(&ffs->wait)); in ffs_data_put()
1706 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1707 kfree(ffs->dev_name); in ffs_data_put()
1716 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1717 if (ffs->no_disconnect) { in ffs_data_closed()
1718 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1719 if (ffs->epfiles) { in ffs_data_closed()
1720 ffs_epfiles_destroy(ffs->epfiles, in ffs_data_closed()
1721 ffs->eps_count); in ffs_data_closed()
1722 ffs->epfiles = NULL; in ffs_data_closed()
1724 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1727 ffs->state = FFS_CLOSING; in ffs_data_closed()
1731 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1732 ffs->state = FFS_CLOSING; in ffs_data_closed()
1747 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1748 if (!ffs->io_completion_wq) { in ffs_data_new()
1753 refcount_set(&ffs->ref, 1); in ffs_data_new()
1754 atomic_set(&ffs->opened, 0); in ffs_data_new()
1755 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1756 mutex_init(&ffs->mutex); in ffs_data_new()
1757 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1758 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1759 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1760 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1763 ffs->ev.can_stall = 1; in ffs_data_new()
1774 BUG_ON(ffs->gadget); in ffs_data_clear()
1776 if (ffs->epfiles) in ffs_data_clear()
1777 ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count); in ffs_data_clear()
1779 if (ffs->ffs_eventfd) in ffs_data_clear()
1780 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1782 kfree(ffs->raw_descs_data); in ffs_data_clear()
1783 kfree(ffs->raw_strings); in ffs_data_clear()
1784 kfree(ffs->stringtabs); in ffs_data_clear()
1793 ffs->epfiles = NULL; in ffs_data_reset()
1794 ffs->raw_descs_data = NULL; in ffs_data_reset()
1795 ffs->raw_descs = NULL; in ffs_data_reset()
1796 ffs->raw_strings = NULL; in ffs_data_reset()
1797 ffs->stringtabs = NULL; in ffs_data_reset()
1799 ffs->raw_descs_length = 0; in ffs_data_reset()
1800 ffs->fs_descs_count = 0; in ffs_data_reset()
1801 ffs->hs_descs_count = 0; in ffs_data_reset()
1802 ffs->ss_descs_count = 0; in ffs_data_reset()
1804 ffs->strings_count = 0; in ffs_data_reset()
1805 ffs->interfaces_count = 0; in ffs_data_reset()
1806 ffs->eps_count = 0; in ffs_data_reset()
1808 ffs->ev.count = 0; in ffs_data_reset()
1810 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1811 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1812 ffs->flags = 0; in ffs_data_reset()
1814 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
1815 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
1816 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
1827 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1828 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1829 return -EBADFD; in functionfs_bind()
1831 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1835 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1836 if (!ffs->ep0req) in functionfs_bind()
1837 return -ENOMEM; in functionfs_bind()
1838 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1839 ffs->ep0req->context = ffs; in functionfs_bind()
1841 lang = ffs->stringtabs; in functionfs_bind()
1844 struct usb_string *str = (*lang)->strings; in functionfs_bind()
1846 for (; str->s; ++id, ++str) in functionfs_bind()
1847 str->id = id; in functionfs_bind()
1851 ffs->gadget = cdev->gadget; in functionfs_bind()
1860 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1861 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1862 ffs->ep0req = NULL; in functionfs_unbind()
1863 ffs->gadget = NULL; in functionfs_unbind()
1864 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1876 count = ffs->eps_count; in ffs_epfiles_create()
1879 return -ENOMEM; in ffs_epfiles_create()
1883 epfile->ffs = ffs; in ffs_epfiles_create()
1884 mutex_init(&epfile->mutex); in ffs_epfiles_create()
1885 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1886 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1888 sprintf(epfile->name, "ep%u", i); in ffs_epfiles_create()
1889 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1892 if (!epfile->dentry) { in ffs_epfiles_create()
1893 ffs_epfiles_destroy(epfiles, i - 1); in ffs_epfiles_create()
1894 return -ENOMEM; in ffs_epfiles_create()
1898 ffs->epfiles = epfiles; in ffs_epfiles_create()
1908 for (; count; --count, ++epfile) { in ffs_epfiles_destroy()
1909 BUG_ON(mutex_is_locked(&epfile->mutex)); in ffs_epfiles_destroy()
1910 if (epfile->dentry) { in ffs_epfiles_destroy()
1911 d_delete(epfile->dentry); in ffs_epfiles_destroy()
1912 dput(epfile->dentry); in ffs_epfiles_destroy()
1913 epfile->dentry = NULL; in ffs_epfiles_destroy()
1922 struct ffs_ep *ep = func->eps; in ffs_func_eps_disable()
1923 struct ffs_epfile *epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1924 unsigned count = func->ffs->eps_count; in ffs_func_eps_disable()
1927 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1928 while (count--) { in ffs_func_eps_disable()
1930 if (ep->ep) in ffs_func_eps_disable()
1931 usb_ep_disable(ep->ep); in ffs_func_eps_disable()
1935 epfile->ep = NULL; in ffs_func_eps_disable()
1940 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1945 struct ffs_data *ffs = func->ffs; in ffs_func_eps_enable()
1946 struct ffs_ep *ep = func->eps; in ffs_func_eps_enable()
1947 struct ffs_epfile *epfile = ffs->epfiles; in ffs_func_eps_enable()
1948 unsigned count = ffs->eps_count; in ffs_func_eps_enable()
1952 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1953 while(count--) { in ffs_func_eps_enable()
1954 ep->ep->driver_data = ep; in ffs_func_eps_enable()
1956 ret = config_ep_by_speed(func->gadget, &func->function, ep->ep); in ffs_func_eps_enable()
1959 __func__, ep->ep->name, ret); in ffs_func_eps_enable()
1963 ret = usb_ep_enable(ep->ep); in ffs_func_eps_enable()
1965 epfile->ep = ep; in ffs_func_eps_enable()
1966 epfile->in = usb_endpoint_dir_in(ep->ep->desc); in ffs_func_eps_enable()
1967 epfile->isoc = usb_endpoint_xfer_isoc(ep->ep->desc); in ffs_func_eps_enable()
1976 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
1977 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1983 /* Parsing and building descriptors and strings *****************************/
1987 * well as record how many interfaces, endpoints and strings are
2022 return -EINVAL; in ffs_do_single_desc()
2026 length = _ds->bLength; in ffs_do_single_desc()
2029 return -EINVAL; in ffs_do_single_desc()
2039 return -EINVAL; \ in ffs_do_single_desc()
2050 switch (_ds->bDescriptorType) { in ffs_do_single_desc()
2057 _ds->bDescriptorType); in ffs_do_single_desc()
2058 return -EINVAL; in ffs_do_single_desc()
2066 __entity(INTERFACE, ds->bInterfaceNumber); in ffs_do_single_desc()
2067 if (ds->iInterface) in ffs_do_single_desc()
2068 __entity(STRING, ds->iInterface); in ffs_do_single_desc()
2069 *current_class = ds->bInterfaceClass; in ffs_do_single_desc()
2079 __entity(ENDPOINT, ds->bEndpointAddress); in ffs_do_single_desc()
2096 _ds->bDescriptorType, *current_class); in ffs_do_single_desc()
2097 return -EINVAL; in ffs_do_single_desc()
2110 if (ds->iFunction) in ffs_do_single_desc()
2111 __entity(STRING, ds->iFunction); in ffs_do_single_desc()
2127 pr_vdebug("unimplemented descriptor: %d\n", _ds->bDescriptorType); in ffs_do_single_desc()
2128 return -EINVAL; in ffs_do_single_desc()
2132 pr_vdebug("unknown descriptor: %d\n", _ds->bDescriptorType); in ffs_do_single_desc()
2133 return -EINVAL; in ffs_do_single_desc()
2137 _ds->bLength, _ds->bDescriptorType); in ffs_do_single_desc()
2138 return -EINVAL; in ffs_do_single_desc()
2154 unsigned long num = 0; in ffs_do_descs() local
2155 int current_class = -1; in ffs_do_descs()
2162 if (num == count) in ffs_do_descs()
2166 ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); in ffs_do_descs()
2169 num, ret); in ffs_do_descs()
2174 return _len - len; in ffs_do_descs()
2183 len -= ret; in ffs_do_descs()
2185 ++num; in ffs_do_descs()
2208 if (*valuep >= helper->interfaces_count) in __ffs_data_do_entity()
2209 helper->interfaces_count = *valuep + 1; in __ffs_data_do_entity()
2214 * Strings are indexed from 1 (0 is reserved in __ffs_data_do_entity()
2217 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2218 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2223 helper->eps_count++; in __ffs_data_do_entity()
2224 if (helper->eps_count >= FFS_MAX_EPS_COUNT) in __ffs_data_do_entity()
2225 return -EINVAL; in __ffs_data_do_entity()
2227 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2228 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2229 d->bEndpointAddress; in __ffs_data_do_entity()
2230 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2231 d->bEndpointAddress) in __ffs_data_do_entity()
2232 return -EINVAL; in __ffs_data_do_entity()
2242 u16 bcd_version = le16_to_cpu(desc->bcdVersion); in __ffs_do_os_desc_header()
2243 u16 w_index = le16_to_cpu(desc->wIndex); in __ffs_do_os_desc_header()
2248 return -EINVAL; in __ffs_do_os_desc_header()
2259 return -EINVAL; in __ffs_do_os_desc_header()
2282 while (feature_count--) { in ffs_do_single_os_desc()
2289 len -= ret; in ffs_do_single_os_desc()
2291 return _len - len; in ffs_do_single_os_desc()
2300 unsigned long num = 0; in ffs_do_os_descs() local
2304 for (num = 0; num < count; ++num) { in ffs_do_os_descs()
2311 return -EINVAL; in ffs_do_os_descs()
2320 if (le32_to_cpu(desc->dwLength) > len) in ffs_do_os_descs()
2321 return -EINVAL; in ffs_do_os_descs()
2326 num, ret); in ffs_do_os_descs()
2330 * 16-bit hex "?? 00" Little Endian looks like 8-bit hex "??" in ffs_do_os_descs()
2332 feature_count = le16_to_cpu(desc->wCount); in ffs_do_os_descs()
2334 (feature_count > 255 || desc->Reserved)) in ffs_do_os_descs()
2335 return -EINVAL; in ffs_do_os_descs()
2336 len -= ret; in ffs_do_os_descs()
2350 len -= ret; in ffs_do_os_descs()
2353 return _len - len; in ffs_do_os_descs()
2374 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2375 return -EINVAL; in __ffs_data_do_os_desc()
2376 if (d->Reserved1 != 1) { in __ffs_data_do_os_desc()
2379 * but older kernels incorrectly rejected non-zero in __ffs_data_do_os_desc()
2384 d->Reserved1 = 1; in __ffs_data_do_os_desc()
2386 for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i) in __ffs_data_do_os_desc()
2387 if (d->Reserved2[i]) in __ffs_data_do_os_desc()
2388 return -EINVAL; in __ffs_data_do_os_desc()
2398 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2399 return -EINVAL; in __ffs_data_do_os_desc()
2400 length = le32_to_cpu(d->dwSize); in __ffs_data_do_os_desc()
2402 return -EINVAL; in __ffs_data_do_os_desc()
2403 type = le32_to_cpu(d->dwPropertyDataType); in __ffs_data_do_os_desc()
2408 return -EINVAL; in __ffs_data_do_os_desc()
2410 pnl = le16_to_cpu(d->wPropertyNameLength); in __ffs_data_do_os_desc()
2414 return -EINVAL; in __ffs_data_do_os_desc()
2420 return -EINVAL; in __ffs_data_do_os_desc()
2422 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2424 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2425 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2430 return -EINVAL; in __ffs_data_do_os_desc()
2440 int ret = -EINVAL, i; in __ffs_data_got_descs()
2452 len -= 8; in __ffs_data_got_descs()
2456 ffs->user_flags = flags; in __ffs_data_got_descs()
2465 ret = -ENOSYS; in __ffs_data_got_descs()
2469 len -= 12; in __ffs_data_got_descs()
2478 ffs->ffs_eventfd = in __ffs_data_got_descs()
2480 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2481 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2482 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2486 len -= 4; in __ffs_data_got_descs()
2498 len -= 4; in __ffs_data_got_descs()
2507 len -= 4; in __ffs_data_got_descs()
2522 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2523 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2524 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2526 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2527 ret = -EINVAL; in __ffs_data_got_descs()
2530 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2531 ret = -EINVAL; in __ffs_data_got_descs()
2536 len -= ret; in __ffs_data_got_descs()
2544 len -= ret; in __ffs_data_got_descs()
2548 ret = -EINVAL; in __ffs_data_got_descs()
2552 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2553 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2554 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2555 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2556 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2557 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2558 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2588 /* Do we have at least as many strings as descriptors need? */ in __ffs_data_got_strings()
2589 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2594 * If we don't need any strings just return and free all in __ffs_data_got_strings()
2609 vla_item(d, struct usb_string, strings, in __ffs_data_got_strings()
2616 return -ENOMEM; in __ffs_data_got_strings()
2625 } while (--i); in __ffs_data_got_strings()
2631 s = vla_ptr(vlabuf, d, strings); in __ffs_data_got_strings()
2636 len -= 16; in __ffs_data_got_strings()
2638 do { /* lang_count > 0 so we can use do-while */ in __ffs_data_got_strings()
2644 t->language = get_unaligned_le16(data); in __ffs_data_got_strings()
2645 t->strings = s; in __ffs_data_got_strings()
2649 len -= 2; in __ffs_data_got_strings()
2652 do { /* str_count > 0 so we can use do-while */ in __ffs_data_got_strings()
2659 * User may provide more strings then we need, in __ffs_data_got_strings()
2665 * s->id will be set while adding in __ffs_data_got_strings()
2669 s->s = data; in __ffs_data_got_strings()
2670 --needed; in __ffs_data_got_strings()
2675 len -= length + 1; in __ffs_data_got_strings()
2676 } while (--str_per_lang); in __ffs_data_got_strings()
2678 s->id = 0; /* terminator */ in __ffs_data_got_strings()
2679 s->s = NULL; in __ffs_data_got_strings()
2682 } while (--lang_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()
2698 return -EINVAL; in __ffs_data_got_strings()
2714 * of ffs->setup_state without holding the lock because when in __ffs_event_add()
2718 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2719 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2723 * evens on ffs->ev.types queue. This is important because the queue 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()
2756 for (; n; --n, ++ev) 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()
2775 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2777 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
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()
2789 return -ENOENT; in ffs_ep_addr2idx()
2812 if (func->function.ss_descriptors) { in __ffs_func_bind_do_descs()
2814 func->function.ss_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2815 } else if (func->function.hs_descriptors) { in __ffs_func_bind_do_descs()
2817 func->function.hs_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2820 func->function.fs_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2823 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) in __ffs_func_bind_do_descs()
2826 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2830 ffs_ep = func->eps + idx; in __ffs_func_bind_do_descs()
2832 if (ffs_ep->descs[ep_desc_id]) { in __ffs_func_bind_do_descs()
2835 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); in __ffs_func_bind_do_descs()
2836 return -EINVAL; in __ffs_func_bind_do_descs()
2838 ffs_ep->descs[ep_desc_id] = ds; in __ffs_func_bind_do_descs()
2840 ffs_dump_mem(": Original ep desc", ds, ds->bLength); in __ffs_func_bind_do_descs()
2841 if (ffs_ep->ep) { in __ffs_func_bind_do_descs()
2842 ds->bEndpointAddress = ffs_ep->descs[0]->bEndpointAddress; in __ffs_func_bind_do_descs()
2843 if (!ds->wMaxPacketSize) in __ffs_func_bind_do_descs()
2844 ds->wMaxPacketSize = ffs_ep->descs[0]->wMaxPacketSize; in __ffs_func_bind_do_descs()
2855 bEndpointAddress = ds->bEndpointAddress; in __ffs_func_bind_do_descs()
2860 wMaxPacketSize = ds->wMaxPacketSize; in __ffs_func_bind_do_descs()
2862 ep = usb_ep_autoconfig(func->gadget, ds); in __ffs_func_bind_do_descs()
2864 return -ENOTSUPP; in __ffs_func_bind_do_descs()
2865 ep->driver_data = func->eps + idx; in __ffs_func_bind_do_descs()
2869 return -ENOMEM; in __ffs_func_bind_do_descs()
2871 ffs_ep->ep = ep; in __ffs_func_bind_do_descs()
2872 ffs_ep->req = req; in __ffs_func_bind_do_descs()
2873 func->eps_revmap[ds->bEndpointAddress & in __ffs_func_bind_do_descs()
2879 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2880 ds->bEndpointAddress = bEndpointAddress; in __ffs_func_bind_do_descs()
2885 ds->wMaxPacketSize = wMaxPacketSize; in __ffs_func_bind_do_descs()
2887 ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength); in __ffs_func_bind_do_descs()
2908 if (func->interfaces_nums[idx] < 0) { in __ffs_func_bind_do_nums()
2909 int id = usb_interface_id(func->conf, &func->function); in __ffs_func_bind_do_nums()
2912 func->interfaces_nums[idx] = id; in __ffs_func_bind_do_nums()
2914 newValue = func->interfaces_nums[idx]; in __ffs_func_bind_do_nums()
2919 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
2927 if (desc->bDescriptorType == USB_DT_ENDPOINT) in __ffs_func_bind_do_nums()
2930 idx = (*valuep & USB_ENDPOINT_NUMBER_MASK) - 1; in __ffs_func_bind_do_nums()
2931 if (!func->eps[idx].ep) in __ffs_func_bind_do_nums()
2932 return -EINVAL; in __ffs_func_bind_do_nums()
2936 descs = func->eps[idx].descs; in __ffs_func_bind_do_nums()
2937 newValue = descs[descs[0] ? 0 : 1]->bEndpointAddress; in __ffs_func_bind_do_nums()
2942 pr_vdebug("%02x -> %02x\n", *valuep, newValue); in __ffs_func_bind_do_nums()
2959 t = &func->function.os_desc_table[desc->bFirstInterfaceNumber]; in __ffs_func_bind_do_os_desc()
2960 t->if_id = func->interfaces_nums[desc->bFirstInterfaceNumber]; in __ffs_func_bind_do_os_desc()
2961 memcpy(t->os_desc->ext_compat_id, &desc->CompatibleID, in __ffs_func_bind_do_os_desc()
2962 ARRAY_SIZE(desc->CompatibleID) + in __ffs_func_bind_do_os_desc()
2963 ARRAY_SIZE(desc->SubCompatibleID)); in __ffs_func_bind_do_os_desc()
2974 t = &func->function.os_desc_table[h->interface]; in __ffs_func_bind_do_os_desc()
2975 t->if_id = func->interfaces_nums[h->interface]; in __ffs_func_bind_do_os_desc()
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()
2980 ext_prop->type = le32_to_cpu(desc->dwPropertyDataType); in __ffs_func_bind_do_os_desc()
2981 ext_prop->name_len = le16_to_cpu(desc->wPropertyNameLength); in __ffs_func_bind_do_os_desc()
2982 ext_prop->data_len = le32_to_cpu(*(__le32 *) in __ffs_func_bind_do_os_desc()
2983 usb_ext_prop_data_len_ptr(data, ext_prop->name_len)); in __ffs_func_bind_do_os_desc()
2984 length = ext_prop->name_len + ext_prop->data_len + 14; 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()
2988 ext_prop->name_len; 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()
2992 ext_prop->data_len; in __ffs_func_bind_do_os_desc()
2994 usb_ext_prop_data_ptr(data, ext_prop->name_len), in __ffs_func_bind_do_os_desc()
2995 ext_prop->data_len); in __ffs_func_bind_do_os_desc()
2997 switch (ext_prop->type) { in __ffs_func_bind_do_os_desc()
3002 ext_prop->data_len *= 2; in __ffs_func_bind_do_os_desc()
3005 ext_prop->data = ext_prop_data; in __ffs_func_bind_do_os_desc()
3008 ext_prop->name_len); in __ffs_func_bind_do_os_desc()
3010 ext_prop->name_len *= 2; in __ffs_func_bind_do_os_desc()
3011 ext_prop->name = ext_prop_name; in __ffs_func_bind_do_os_desc()
3013 t->os_desc->ext_prop_len += in __ffs_func_bind_do_os_desc()
3014 ext_prop->name_len + ext_prop->data_len + 14; in __ffs_func_bind_do_os_desc()
3015 ++t->os_desc->ext_prop_count; in __ffs_func_bind_do_os_desc()
3016 list_add_tail(&ext_prop->entry, &t->os_desc->ext_prop); in __ffs_func_bind_do_os_desc()
3031 container_of(f->fi, struct f_fs_opts, func_inst); in ffs_do_functionfs_bind()
3042 * Configfs-enabled gadgets however do need ffs_dev_lock. in ffs_do_functionfs_bind()
3044 if (!ffs_opts->no_configfs) in ffs_do_functionfs_bind()
3046 ret = ffs_opts->dev->desc_ready ? 0 : -ENODEV; in ffs_do_functionfs_bind()
3047 ffs_data = ffs_opts->dev->ffs_data; in ffs_do_functionfs_bind()
3048 if (!ffs_opts->no_configfs) in ffs_do_functionfs_bind()
3053 func->ffs = ffs_data; in ffs_do_functionfs_bind()
3054 func->conf = c; in ffs_do_functionfs_bind()
3055 func->gadget = c->cdev->gadget; in ffs_do_functionfs_bind()
3062 * with regard to ffs_opts->bound access in ffs_do_functionfs_bind()
3064 if (!ffs_opts->refcnt) { in ffs_do_functionfs_bind()
3065 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3069 ffs_opts->refcnt++; in ffs_do_functionfs_bind()
3070 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3079 struct ffs_data *ffs = func->ffs; in _ffs_func_bind()
3081 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3082 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3083 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3090 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3092 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3094 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3096 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3097 vla_item_with_sz(d, short, inums, ffs->interfaces_count); 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 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3105 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3107 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3109 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3110 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3117 return -ENOTSUPP; in _ffs_func_bind()
3122 return -ENOMEM; in _ffs_func_bind()
3124 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3125 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3127 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3131 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3132 ffs->raw_descs_length); in _ffs_func_bind()
3136 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3137 eps_ptr[i].num = -1; in _ffs_func_bind()
3140 * d_eps == vlabuf, func->eps used to kfree vlabuf later in _ffs_func_bind()
3142 func->eps = vla_ptr(vlabuf, d, eps); in _ffs_func_bind()
3143 func->interfaces_nums = vla_ptr(vlabuf, d, inums); in _ffs_func_bind()
3151 func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); in _ffs_func_bind()
3152 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3165 func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); in _ffs_func_bind()
3166 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3168 d_raw_descs__sz - fs_len, in _ffs_func_bind()
3179 func->function.ss_descriptors = func->function.ssp_descriptors = in _ffs_func_bind()
3181 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3183 d_raw_descs__sz - fs_len - hs_len, in _ffs_func_bind()
3198 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3199 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3200 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3206 func->function.os_desc_table = vla_ptr(vlabuf, d, os_desc_table); in _ffs_func_bind()
3207 if (c->cdev->use_os_string) { in _ffs_func_bind()
3208 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3211 desc = func->function.os_desc_table[i].os_desc = in _ffs_func_bind()
3214 desc->ext_compat_id = in _ffs_func_bind()
3216 INIT_LIST_HEAD(&desc->ext_prop); in _ffs_func_bind()
3218 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3221 d_raw_descs__sz - fs_len - hs_len - in _ffs_func_bind()
3227 func->function.os_desc_n = in _ffs_func_bind()
3228 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3250 if (ret && !--ffs_opts->refcnt) in ffs_func_bind()
3251 functionfs_unbind(func->ffs); in ffs_func_bind()
3270 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt()
3273 if (alt != (unsigned)-1) { in ffs_func_set_alt()
3279 if (ffs->func) in ffs_func_set_alt()
3280 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3282 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3283 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3284 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3285 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3286 return -ENODEV; in ffs_func_set_alt()
3289 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3290 return -ENODEV; in ffs_func_set_alt()
3292 if (alt == (unsigned)-1) { in ffs_func_set_alt()
3293 ffs->func = NULL; in ffs_func_set_alt()
3298 ffs->func = func; in ffs_func_set_alt()
3307 ffs_func_set_alt(f, 0, (unsigned)-1); in ffs_func_disable()
3314 struct ffs_data *ffs = func->ffs; in ffs_func_setup()
3320 pr_vdebug("creq->bRequestType = %02x\n", creq->bRequestType); in ffs_func_setup()
3321 pr_vdebug("creq->bRequest = %02x\n", creq->bRequest); in ffs_func_setup()
3322 pr_vdebug("creq->wValue = %04x\n", le16_to_cpu(creq->wValue)); in ffs_func_setup()
3323 pr_vdebug("creq->wIndex = %04x\n", le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3324 pr_vdebug("creq->wLength = %04x\n", le16_to_cpu(creq->wLength)); in ffs_func_setup()
3330 * passed to usb_configuration->setup() (if one is set). No in ffs_func_setup()
3336 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3337 return -ENODEV; in ffs_func_setup()
3339 switch (creq->bRequestType & USB_RECIP_MASK) { in ffs_func_setup()
3341 ret = ffs_func_revmap_intf(func, le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3347 ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3350 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3351 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3355 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3356 ret = le16_to_cpu(creq->wIndex); in ffs_func_setup()
3358 return -EOPNOTSUPP; in ffs_func_setup()
3361 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3362 ffs->ev.setup = *creq; in ffs_func_setup()
3363 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3365 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3367 return creq->wLength == 0 ? USB_GADGET_DELAYED_STATUS : 0; in ffs_func_setup()
3376 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3379 switch (creq->bRequestType & USB_RECIP_MASK) { in ffs_func_req_match()
3382 le16_to_cpu(creq->wIndex)) >= 0); in ffs_func_req_match()
3385 le16_to_cpu(creq->wIndex)) >= 0); in ffs_func_req_match()
3387 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3395 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3401 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3407 static int ffs_func_revmap_ep(struct ffs_function *func, u8 num) in ffs_func_revmap_ep() argument
3409 num = func->eps_revmap[num & USB_ENDPOINT_NUMBER_MASK]; in ffs_func_revmap_ep()
3410 return num ? num : -EDOM; in ffs_func_revmap_ep()
3415 short *nums = func->interfaces_nums; in ffs_func_revmap_intf()
3416 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3418 for (; count; --count, ++nums) { in ffs_func_revmap_intf()
3420 return nums - func->interfaces_nums; in ffs_func_revmap_intf()
3423 return -EDOM; in ffs_func_revmap_intf()
3439 if (strcmp(dev->name, name) == 0) in _ffs_do_find_dev()
3455 if (dev->single) in _ffs_get_single_dev()
3488 usb_put_function_instance(&opts->func_inst); in ffs_attr_release()
3508 ffs_release_dev(opts->dev); in ffs_free_inst()
3510 _ffs_free_dev(opts->dev); in ffs_free_inst()
3518 return -ENAMETOOLONG; in ffs_set_inst_name()
3519 return ffs_name_dev(to_f_fs_opts(fi)->dev, name); in ffs_set_inst_name()
3529 return ERR_PTR(-ENOMEM); in ffs_alloc_inst()
3531 opts->func_inst.set_inst_name = ffs_set_inst_name; in ffs_alloc_inst()
3532 opts->func_inst.free_func_inst = ffs_free_inst; in ffs_alloc_inst()
3540 opts->dev = dev; in ffs_alloc_inst()
3541 dev->opts = opts; in ffs_alloc_inst()
3543 config_group_init_type_name(&opts->func_inst.group, "", in ffs_alloc_inst()
3545 return &opts->func_inst; in ffs_alloc_inst()
3557 struct ffs_data *ffs = func->ffs; in ffs_func_unbind()
3559 container_of(f->fi, struct f_fs_opts, func_inst); in ffs_func_unbind()
3560 struct ffs_ep *ep = func->eps; in ffs_func_unbind()
3561 unsigned count = ffs->eps_count; in ffs_func_unbind()
3565 if (ffs->func == func) { in ffs_func_unbind()
3567 ffs->func = NULL; in ffs_func_unbind()
3571 drain_workqueue(ffs->io_completion_wq); in ffs_func_unbind()
3573 if (!--opts->refcnt) in ffs_func_unbind()
3577 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3578 while (count--) { in ffs_func_unbind()
3579 if (ep->ep && ep->req) in ffs_func_unbind()
3580 usb_ep_free_request(ep->ep, ep->req); in ffs_func_unbind()
3581 ep->req = NULL; in ffs_func_unbind()
3584 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3585 kfree(func->eps); in ffs_func_unbind()
3586 func->eps = NULL; in ffs_func_unbind()
3591 func->function.fs_descriptors = NULL; in ffs_func_unbind()
3592 func->function.hs_descriptors = NULL; in ffs_func_unbind()
3593 func->function.ss_descriptors = NULL; in ffs_func_unbind()
3594 func->function.ssp_descriptors = NULL; in ffs_func_unbind()
3595 func->interfaces_nums = NULL; in ffs_func_unbind()
3608 return ERR_PTR(-ENOMEM); in ffs_alloc()
3610 func->function.name = "Function FS Gadget"; in ffs_alloc()
3612 func->function.bind = ffs_func_bind; in ffs_alloc()
3613 func->function.unbind = ffs_func_unbind; in ffs_alloc()
3614 func->function.set_alt = ffs_func_set_alt; in ffs_alloc()
3615 func->function.disable = ffs_func_disable; in ffs_alloc()
3616 func->function.setup = ffs_func_setup; in ffs_alloc()
3617 func->function.req_match = ffs_func_req_match; in ffs_alloc()
3618 func->function.suspend = ffs_func_suspend; in ffs_alloc()
3619 func->function.resume = ffs_func_resume; in ffs_alloc()
3620 func->function.free_func = ffs_free; in ffs_alloc()
3622 return &func->function; in ffs_alloc()
3634 return ERR_PTR(-EBUSY); in _ffs_alloc_dev()
3638 return ERR_PTR(-ENOMEM); in _ffs_alloc_dev()
3648 list_add(&dev->entry, &ffs_devices); in _ffs_alloc_dev()
3662 strlcpy(dev->name, name, ARRAY_SIZE(dev->name)); in ffs_name_dev()
3664 ret = -EBUSY; in ffs_name_dev()
3680 ret = -EBUSY; in ffs_single_dev()
3682 dev->single = true; in ffs_single_dev()
3694 list_del(&dev->entry); in _ffs_free_dev()
3711 ret = -ENOENT; in ffs_acquire_dev()
3712 } else if (ffs_dev->mounted) { in ffs_acquire_dev()
3713 ret = -EBUSY; in ffs_acquire_dev()
3714 } else if (ffs_dev->ffs_acquire_dev_callback && in ffs_acquire_dev()
3715 ffs_dev->ffs_acquire_dev_callback(ffs_dev)) { in ffs_acquire_dev()
3716 ret = -ENOENT; in ffs_acquire_dev()
3718 ffs_dev->mounted = true; in ffs_acquire_dev()
3719 ffs_dev->ffs_data = ffs_data; in ffs_acquire_dev()
3720 ffs_data->private_data = ffs_dev; in ffs_acquire_dev()
3732 if (ffs_dev && ffs_dev->mounted) { in ffs_release_dev()
3733 ffs_dev->mounted = false; in ffs_release_dev()
3734 if (ffs_dev->ffs_data) { in ffs_release_dev()
3735 ffs_dev->ffs_data->private_data = NULL; in ffs_release_dev()
3736 ffs_dev->ffs_data = NULL; in ffs_release_dev()
3739 if (ffs_dev->ffs_release_dev_callback) in ffs_release_dev()
3740 ffs_dev->ffs_release_dev_callback(ffs_dev); in ffs_release_dev()
3754 ffs_obj = ffs->private_data; in ffs_ready()
3756 ret = -EINVAL; in ffs_ready()
3759 if (WARN_ON(ffs_obj->desc_ready)) { in ffs_ready()
3760 ret = -EBUSY; in ffs_ready()
3764 ffs_obj->desc_ready = true; in ffs_ready()
3766 if (ffs_obj->ffs_ready_callback) { in ffs_ready()
3767 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3772 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3787 ffs_obj = ffs->private_data; in ffs_closed()
3791 ffs_obj->desc_ready = false; in ffs_closed()
3793 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3794 ffs_obj->ffs_closed_callback) in ffs_closed()
3795 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3797 if (ffs_obj->opts) in ffs_closed()
3798 opts = ffs_obj->opts; in ffs_closed()
3802 if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent in ffs_closed()
3803 || !kref_read(&opts->func_inst.group.cg_item.ci_kref)) in ffs_closed()
3806 ci = opts->func_inst.group.cg_item.ci_parent->ci_parent; in ffs_closed()
3809 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3821 ? mutex_trylock(mutex) ? 0 : -EAGAIN in ffs_mutex_lock()