Lines Matching refs:f
193 struct usb_fifo *f; in usb_ref_device() local
254 f = ppf[cpd->fifo_index + USB_FIFO_TX]; in usb_ref_device()
255 crd->txfifo = f; in usb_ref_device()
257 if (f == NULL || f->refcount == USB_FIFO_REF_MAX) in usb_ref_device()
259 if (f->curr_cpd != cpd) in usb_ref_device()
262 if (f->fs_ep_max != 0) { in usb_ref_device()
270 f = ppf[cpd->fifo_index + USB_FIFO_RX]; in usb_ref_device()
271 crd->rxfifo = f; in usb_ref_device()
273 if (f == NULL || f->refcount == USB_FIFO_REF_MAX) in usb_ref_device()
275 if (f->curr_cpd != cpd) in usb_ref_device()
278 if (f->fs_ep_max != 0) { in usb_ref_device()
383 struct usb_fifo *f; in usb_fifo_alloc() local
385 f = malloc(sizeof(*f), M_USBDEV, M_WAITOK | M_ZERO); in usb_fifo_alloc()
386 cv_init(&f->cv_io, "FIFO-IO"); in usb_fifo_alloc()
387 cv_init(&f->cv_drain, "FIFO-DRAIN"); in usb_fifo_alloc()
388 sx_init(&f->fs_fastpath_lock, "FIFO-FP"); in usb_fifo_alloc()
389 f->priv_mtx = mtx; in usb_fifo_alloc()
390 f->refcount = 1; in usb_fifo_alloc()
391 knlist_init_mtx(&f->selinfo.si_note, mtx); in usb_fifo_alloc()
392 return (f); in usb_fifo_alloc()
403 struct usb_fifo *f; in usb_fifo_create() local
421 f = udev->fifo[cpd->fifo_index + USB_FIFO_TX]; in usb_fifo_create()
422 if (f == NULL) in usb_fifo_create()
424 crd->txfifo = f; in usb_fifo_create()
427 f = udev->fifo[cpd->fifo_index + USB_FIFO_RX]; in usb_fifo_create()
428 if (f == NULL) in usb_fifo_create()
430 crd->rxfifo = f; in usb_fifo_create()
452 f = udev->fifo[n + USB_FIFO_TX]; in usb_fifo_create()
453 if (f != NULL) { in usb_fifo_create()
454 if (f->dev_ep_index != e) { in usb_fifo_create()
458 if (f->curr_cpd != NULL) { in usb_fifo_create()
469 f = udev->fifo[n + USB_FIFO_RX]; in usb_fifo_create()
470 if (f != NULL) { in usb_fifo_create()
471 if (f->dev_ep_index != e) { in usb_fifo_create()
475 if (f->curr_cpd != NULL) { in usb_fifo_create()
513 f = usb_fifo_alloc(&udev->device_mtx); in usb_fifo_create()
514 if (f == NULL) { in usb_fifo_create()
519 f->fifo_index = n + USB_FIFO_TX; in usb_fifo_create()
520 f->dev_ep_index = e; in usb_fifo_create()
521 f->priv_sc0 = ep; in usb_fifo_create()
522 f->methods = &usb_ugen_methods; in usb_fifo_create()
523 f->iface_index = ep->iface_index; in usb_fifo_create()
524 f->udev = udev; in usb_fifo_create()
526 udev->fifo[n + USB_FIFO_TX] = f; in usb_fifo_create()
538 f = usb_fifo_alloc(&udev->device_mtx); in usb_fifo_create()
539 if (f == NULL) { in usb_fifo_create()
544 f->fifo_index = n + USB_FIFO_RX; in usb_fifo_create()
545 f->dev_ep_index = e; in usb_fifo_create()
546 f->priv_sc0 = ep; in usb_fifo_create()
547 f->methods = &usb_ugen_methods; in usb_fifo_create()
548 f->iface_index = ep->iface_index; in usb_fifo_create()
549 f->udev = udev; in usb_fifo_create()
551 udev->fifo[n + USB_FIFO_RX] = f; in usb_fifo_create()
570 usb_fifo_free(struct usb_fifo *f) in usb_fifo_free() argument
574 if (f == NULL) { in usb_fifo_free()
580 if (f->symlink[n]) { in usb_fifo_free()
581 usb_free_symlink(f->symlink[n]); in usb_fifo_free()
582 f->symlink[n] = NULL; in usb_fifo_free()
588 if ((f->fifo_index < USB_FIFO_MAX) && in usb_fifo_free()
589 (f->udev != NULL) && in usb_fifo_free()
590 (f->udev->fifo[f->fifo_index] == f)) { in usb_fifo_free()
591 f->udev->fifo[f->fifo_index] = NULL; in usb_fifo_free()
593 DPRINTFN(0, "USB FIFO %p has not been linked\n", f); in usb_fifo_free()
597 f->refcount--; in usb_fifo_free()
599 while (f->refcount != 0) { in usb_fifo_free()
601 mtx_lock(f->priv_mtx); in usb_fifo_free()
603 f->flag_iserror = 1; in usb_fifo_free()
605 if (f->flag_sleeping) { in usb_fifo_free()
606 f->flag_sleeping = 0; in usb_fifo_free()
607 cv_broadcast(&f->cv_io); in usb_fifo_free()
609 mtx_unlock(f->priv_mtx); in usb_fifo_free()
616 if (f->refcount == 0) in usb_fifo_free()
620 cv_wait(&f->cv_drain, &usb_ref_lock); in usb_fifo_free()
625 usb_fifo_close(f, 0); in usb_fifo_free()
627 cv_destroy(&f->cv_io); in usb_fifo_free()
628 cv_destroy(&f->cv_drain); in usb_fifo_free()
629 sx_destroy(&f->fs_fastpath_lock); in usb_fifo_free()
631 knlist_clear(&f->selinfo.si_note, 0); in usb_fifo_free()
632 seldrain(&f->selinfo); in usb_fifo_free()
633 knlist_destroy(&f->selinfo.si_note); in usb_fifo_free()
635 free(f, M_USBDEV); in usb_fifo_free()
683 struct usb_fifo *f, int fflags) in usb_fifo_open() argument
687 if (f == NULL) { in usb_fifo_open()
696 if ((f->fifo_index & 1) == USB_FIFO_TX) { in usb_fifo_open()
704 if (f->curr_cpd != NULL) { in usb_fifo_open()
710 f->flag_short = 0; in usb_fifo_open()
713 err = (f->methods->f_open) (f, fflags); in usb_fifo_open()
717 mtx_lock(f->priv_mtx); in usb_fifo_open()
720 f->flag_sleeping = 0; in usb_fifo_open()
723 f->flag_iserror = 0; in usb_fifo_open()
726 f->flag_iscomplete = 0; in usb_fifo_open()
729 f->flag_isselect = 0; in usb_fifo_open()
732 f->flag_flushing = 0; in usb_fifo_open()
735 f->async_p = NULL; in usb_fifo_open()
739 f->curr_cpd = cpd; in usb_fifo_open()
743 usb_fifo_reset(f); in usb_fifo_open()
745 mtx_unlock(f->priv_mtx); in usb_fifo_open()
754 usb_fifo_reset(struct usb_fifo *f) in usb_fifo_reset() argument
758 if (f == NULL) { in usb_fifo_reset()
762 USB_IF_DEQUEUE(&f->used_q, m); in usb_fifo_reset()
764 USB_IF_ENQUEUE(&f->free_q, m); in usb_fifo_reset()
770 f->flag_have_fragment = 0; in usb_fifo_reset()
777 usb_fifo_close(struct usb_fifo *f, int fflags) in usb_fifo_close() argument
782 if (f->curr_cpd == NULL) { in usb_fifo_close()
786 mtx_lock(f->priv_mtx); in usb_fifo_close()
790 f->curr_cpd = NULL; in usb_fifo_close()
794 KNOTE_LOCKED(&f->selinfo.si_note, 0); in usb_fifo_close()
797 if (f->flag_isselect) { in usb_fifo_close()
798 selwakeup(&f->selinfo); in usb_fifo_close()
799 f->flag_isselect = 0; in usb_fifo_close()
802 if (f->async_p != NULL) { in usb_fifo_close()
803 PROC_LOCK(f->async_p); in usb_fifo_close()
804 kern_psignal(f->async_p, SIGIO); in usb_fifo_close()
805 PROC_UNLOCK(f->async_p); in usb_fifo_close()
806 f->async_p = NULL; in usb_fifo_close()
812 if ((f->fifo_index & 1) == USB_FIFO_TX) { in usb_fifo_close()
813 if (!f->flag_iserror) { in usb_fifo_close()
815 f->flag_flushing = 1; in usb_fifo_close()
818 if (f->flag_have_fragment) { in usb_fifo_close()
820 f->flag_have_fragment = 0; in usb_fifo_close()
821 USB_IF_DEQUEUE(&f->free_q, m); in usb_fifo_close()
823 USB_IF_ENQUEUE(&f->used_q, m); in usb_fifo_close()
828 (f->methods->f_start_write) (f); in usb_fifo_close()
831 while (f->flag_flushing && in usb_fifo_close()
832 (!f->flag_iserror)) { in usb_fifo_close()
834 f->flag_sleeping = 1; in usb_fifo_close()
835 err = cv_timedwait_sig(&f->cv_io, f->priv_mtx, in usb_fifo_close()
846 (f->methods->f_stop_write) (f); in usb_fifo_close()
851 (f->methods->f_stop_read) (f); in usb_fifo_close()
855 if (f->flag_sleeping) { in usb_fifo_close()
858 mtx_unlock(f->priv_mtx); in usb_fifo_close()
861 (f->methods->f_close) (f, fflags); in usb_fifo_close()
1006 usb_ioctl_f_sub(struct usb_fifo *f, u_long cmd, void *addr, in usb_ioctl_f_sub() argument
1022 if (f->async_p != NULL) { in usb_ioctl_f_sub()
1026 f->async_p = USB_TD_GET_PROC(td); in usb_ioctl_f_sub()
1028 f->async_p = NULL; in usb_ioctl_f_sub()
1034 if (f->async_p == NULL) { in usb_ioctl_f_sub()
1038 if (*(int *)addr != USB_PROC_GET_GID(f->async_p)) { in usb_ioctl_f_sub()
1058 struct usb_fifo *f; in usb_ioctl() local
1079 f = NULL; /* set default value */ in usb_ioctl()
1083 f = refs.txfifo; in usb_ioctl()
1084 err = usb_ioctl_f_sub(f, cmd, addr, td); in usb_ioctl()
1087 f = refs.rxfifo; in usb_ioctl()
1088 err = usb_ioctl_f_sub(f, cmd, addr, td); in usb_ioctl()
1090 KASSERT(f != NULL, ("fifo not found")); in usb_ioctl()
1094 err = (f->methods->f_ioctl) (f, cmd, addr, fflags); in usb_ioctl()
1106 err = (f->methods->f_ioctl_post) (f, cmd, addr, fflags); in usb_ioctl()
1118 while (f->udev->re_enumerate_wait != USB_RE_ENUM_DONE) { in usb_ioctl()
1141 struct usb_fifo *f = kn->kn_hook; in usb_filter_detach() local
1142 knlist_remove(&f->selinfo.si_note, kn, 0); in usb_filter_detach()
1149 struct usb_fifo *f; in usb_filter_write() local
1154 f = kn->kn_hook; in usb_filter_write()
1156 USB_MTX_ASSERT(f->priv_mtx, MA_OWNED); in usb_filter_write()
1158 cpd = f->curr_cpd; in usb_filter_write()
1161 } else if (f->fs_ep_max == 0) { in usb_filter_write()
1162 if (f->flag_iserror) { in usb_filter_write()
1166 if (f->queue_data == NULL) { in usb_filter_write()
1171 (f->methods->f_start_write) (f); in usb_filter_write()
1174 USB_IF_POLL(&f->free_q, m); in usb_filter_write()
1177 if (f->flag_iscomplete) { in usb_filter_write()
1190 struct usb_fifo *f; in usb_filter_read() local
1195 f = kn->kn_hook; in usb_filter_read()
1197 USB_MTX_ASSERT(f->priv_mtx, MA_OWNED); in usb_filter_read()
1199 cpd = f->curr_cpd; in usb_filter_read()
1202 } else if (f->fs_ep_max == 0) { in usb_filter_read()
1203 if (f->flag_iserror) { in usb_filter_read()
1207 if (f->queue_data == NULL) { in usb_filter_read()
1212 (f->methods->f_start_read) (f); in usb_filter_read()
1215 USB_IF_POLL(&f->used_q, m); in usb_filter_read()
1219 (f->methods->f_start_read) (f); in usb_filter_read()
1222 if (f->flag_iscomplete) { in usb_filter_read()
1249 struct usb_fifo *f; in usb_kqfilter() local
1265 f = refs.txfifo; in usb_kqfilter()
1272 f = refs.rxfifo; in usb_kqfilter()
1283 kn->kn_hook = f; in usb_kqfilter()
1284 mtx_lock(f->priv_mtx); in usb_kqfilter()
1285 knlist_add(&f->selinfo.si_note, kn, 1); in usb_kqfilter()
1286 mtx_unlock(f->priv_mtx); in usb_kqfilter()
1299 struct usb_fifo *f; in usb_poll() local
1314 f = refs.txfifo; in usb_poll()
1316 mtx_lock(f->priv_mtx); in usb_poll()
1319 if (f->flag_iserror) { in usb_poll()
1323 if (f->queue_data == NULL) { in usb_poll()
1328 (f->methods->f_start_write) (f); in usb_poll()
1331 USB_IF_POLL(&f->free_q, m); in usb_poll()
1334 if (f->flag_iscomplete) { in usb_poll()
1344 f->flag_isselect = 1; in usb_poll()
1345 selrecord(td, &f->selinfo); in usb_poll()
1348 mtx_unlock(f->priv_mtx); in usb_poll()
1352 f = refs.rxfifo; in usb_poll()
1354 mtx_lock(f->priv_mtx); in usb_poll()
1357 if (f->flag_iserror) { in usb_poll()
1361 if (f->queue_data == NULL) { in usb_poll()
1366 (f->methods->f_start_read) (f); in usb_poll()
1369 USB_IF_POLL(&f->used_q, m); in usb_poll()
1372 if (f->flag_iscomplete) { in usb_poll()
1382 f->flag_isselect = 1; in usb_poll()
1383 selrecord(td, &f->selinfo); in usb_poll()
1387 (f->methods->f_start_read) (f); in usb_poll()
1391 mtx_unlock(f->priv_mtx); in usb_poll()
1402 struct usb_fifo *f; in usb_read() local
1416 f = refs.rxfifo; in usb_read()
1417 if (f == NULL) { in usb_read()
1423 mtx_lock(f->priv_mtx); in usb_read()
1426 if (f->flag_iserror) { in usb_read()
1440 USB_IF_DEQUEUE(&f->used_q, m); in usb_read()
1445 (f->methods->f_start_read) (f); in usb_read()
1457 err = usb_fifo_wait(f); in usb_read()
1463 if (f->methods->f_filter_read) { in usb_read()
1469 (f->methods->f_filter_read) (f, m); in usb_read()
1478 err = usb_fifo_uiomove(f, in usb_read()
1489 USB_IF_ENQUEUE(&f->free_q, m); in usb_read()
1496 USB_IF_PREPEND(&f->used_q, m); in usb_read()
1504 mtx_unlock(f->priv_mtx); in usb_read()
1516 struct usb_fifo *f; in usb_write() local
1533 f = refs.txfifo; in usb_write()
1534 if (f == NULL) { in usb_write()
1540 mtx_lock(f->priv_mtx); in usb_write()
1543 if (f->flag_iserror) { in usb_write()
1556 if (f->queue_data == NULL) { in usb_write()
1558 (f->methods->f_start_write) (f); in usb_write()
1562 USB_IF_DEQUEUE(&f->free_q, m); in usb_write()
1575 err = usb_fifo_wait(f); in usb_write()
1583 if (f->flag_have_fragment == 0) { in usb_write()
1601 err = usb_fifo_uiomove(f, pdata, io_len, uio); in usb_write()
1604 f->flag_have_fragment = 0; in usb_write()
1605 USB_IF_ENQUEUE(&f->free_q, m); in usb_write()
1611 if ((f->flag_write_defrag == 0) || in usb_write()
1613 f->flag_have_fragment = 0; in usb_write()
1622 if (f->methods->f_filter_write) { in usb_write()
1623 (f->methods->f_filter_write) (f, m); in usb_write()
1627 USB_IF_ENQUEUE(&f->used_q, m); in usb_write()
1630 (f->methods->f_start_write) (f); in usb_write()
1633 f->flag_have_fragment = 1; in usb_write()
1634 USB_IF_PREPEND(&f->free_q, m); in usb_write()
1639 mtx_unlock(f->priv_mtx); in usb_write()
1695 usb_fifo_uiomove(struct usb_fifo *f, void *cp, in usb_fifo_uiomove() argument
1700 mtx_unlock(f->priv_mtx); in usb_fifo_uiomove()
1708 mtx_lock(f->priv_mtx); in usb_fifo_uiomove()
1714 usb_fifo_wait(struct usb_fifo *f) in usb_fifo_wait() argument
1718 USB_MTX_ASSERT(f->priv_mtx, MA_OWNED); in usb_fifo_wait()
1720 if (f->flag_iserror) { in usb_fifo_wait()
1724 f->flag_sleeping = 1; in usb_fifo_wait()
1726 err = cv_wait_sig(&f->cv_io, f->priv_mtx); in usb_fifo_wait()
1728 if (f->flag_iserror) { in usb_fifo_wait()
1736 usb_fifo_signal(struct usb_fifo *f) in usb_fifo_signal() argument
1738 if (f->flag_sleeping) { in usb_fifo_signal()
1739 f->flag_sleeping = 0; in usb_fifo_signal()
1740 cv_broadcast(&f->cv_io); in usb_fifo_signal()
1745 usb_fifo_wakeup(struct usb_fifo *f) in usb_fifo_wakeup() argument
1747 usb_fifo_signal(f); in usb_fifo_wakeup()
1749 KNOTE_LOCKED(&f->selinfo.si_note, 0); in usb_fifo_wakeup()
1751 if (f->flag_isselect) { in usb_fifo_wakeup()
1752 selwakeup(&f->selinfo); in usb_fifo_wakeup()
1753 f->flag_isselect = 0; in usb_fifo_wakeup()
1755 if (f->async_p != NULL) { in usb_fifo_wakeup()
1756 PROC_LOCK(f->async_p); in usb_fifo_wakeup()
1757 kern_psignal(f->async_p, SIGIO); in usb_fifo_wakeup()
1758 PROC_UNLOCK(f->async_p); in usb_fifo_wakeup()
1946 usb_fifo_alloc_buffer(struct usb_fifo *f, usb_size_t bufsize, in usb_fifo_alloc_buffer() argument
1952 usb_fifo_free_buffer(f); in usb_fifo_alloc_buffer()
1962 mtx_lock(f->priv_mtx); in usb_fifo_alloc_buffer()
1968 f->free_q = temp_q; in usb_fifo_alloc_buffer()
1969 f->used_q.ifq_maxlen = nbuf; in usb_fifo_alloc_buffer()
1970 f->queue_data = queue_data; in usb_fifo_alloc_buffer()
1971 mtx_unlock(f->priv_mtx); in usb_fifo_alloc_buffer()
1983 usb_fifo_free_buffer(struct usb_fifo *f) in usb_fifo_free_buffer() argument
1987 mtx_lock(f->priv_mtx); in usb_fifo_free_buffer()
1990 queue_data = f->queue_data; in usb_fifo_free_buffer()
1991 f->queue_data = NULL; in usb_fifo_free_buffer()
1997 memset(&f->free_q, 0, sizeof(f->free_q)); in usb_fifo_free_buffer()
1998 memset(&f->used_q, 0, sizeof(f->used_q)); in usb_fifo_free_buffer()
1999 mtx_unlock(f->priv_mtx); in usb_fifo_free_buffer()
2025 usb_fifo_put_bytes_max(struct usb_fifo *f) in usb_fifo_put_bytes_max() argument
2030 USB_IF_POLL(&f->free_q, m); in usb_fifo_put_bytes_max()
2048 usb_fifo_put_data(struct usb_fifo *f, struct usb_page_cache *pc, in usb_fifo_put_data() argument
2055 USB_IF_DEQUEUE(&f->free_q, m); in usb_fifo_put_data()
2071 USB_IF_ENQUEUE(&f->used_q, m); in usb_fifo_put_data()
2073 usb_fifo_wakeup(f); in usb_fifo_put_data()
2085 usb_fifo_put_data_linear(struct usb_fifo *f, void *ptr, in usb_fifo_put_data_linear() argument
2092 USB_IF_DEQUEUE(&f->free_q, m); in usb_fifo_put_data_linear()
2108 USB_IF_ENQUEUE(&f->used_q, m); in usb_fifo_put_data_linear()
2110 usb_fifo_wakeup(f); in usb_fifo_put_data_linear()
2122 usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len) in usb_fifo_put_data_buffer() argument
2126 USB_IF_DEQUEUE(&f->free_q, m); in usb_fifo_put_data_buffer()
2131 USB_IF_ENQUEUE(&f->used_q, m); in usb_fifo_put_data_buffer()
2132 usb_fifo_wakeup(f); in usb_fifo_put_data_buffer()
2139 usb_fifo_put_data_error(struct usb_fifo *f) in usb_fifo_put_data_error() argument
2141 f->flag_iserror = 1; in usb_fifo_put_data_error()
2142 usb_fifo_wakeup(f); in usb_fifo_put_data_error()
2157 usb_fifo_get_data(struct usb_fifo *f, struct usb_page_cache *pc, in usb_fifo_get_data() argument
2168 USB_IF_DEQUEUE(&f->used_q, m); in usb_fifo_get_data()
2184 USB_IF_ENQUEUE(&f->free_q, m); in usb_fifo_get_data()
2186 usb_fifo_wakeup(f); in usb_fifo_get_data()
2192 USB_IF_PREPEND(&f->used_q, m); in usb_fifo_get_data()
2199 if (f->flag_flushing) { in usb_fifo_get_data()
2201 if (f->flag_short != 0) { in usb_fifo_get_data()
2202 f->flag_short = 0; in usb_fifo_get_data()
2207 f->flag_flushing = 0; in usb_fifo_get_data()
2208 usb_fifo_wakeup(f); in usb_fifo_get_data()
2220 usb_fifo_get_data_linear(struct usb_fifo *f, void *ptr, in usb_fifo_get_data_linear() argument
2230 USB_IF_DEQUEUE(&f->used_q, m); in usb_fifo_get_data_linear()
2246 USB_IF_ENQUEUE(&f->free_q, m); in usb_fifo_get_data_linear()
2248 usb_fifo_wakeup(f); in usb_fifo_get_data_linear()
2254 USB_IF_PREPEND(&f->used_q, m); in usb_fifo_get_data_linear()
2261 if (f->flag_flushing) { in usb_fifo_get_data_linear()
2263 if (f->flag_short != 0) { in usb_fifo_get_data_linear()
2264 f->flag_short = 0; in usb_fifo_get_data_linear()
2269 f->flag_flushing = 0; in usb_fifo_get_data_linear()
2270 usb_fifo_wakeup(f); in usb_fifo_get_data_linear()
2282 usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr, usb_size_t *plen) in usb_fifo_get_data_buffer() argument
2286 USB_IF_POLL(&f->used_q, m); in usb_fifo_get_data_buffer()
2298 usb_fifo_get_data_error(struct usb_fifo *f) in usb_fifo_get_data_error() argument
2300 f->flag_iserror = 1; in usb_fifo_get_data_error()
2301 usb_fifo_wakeup(f); in usb_fifo_get_data_error()
2445 usb_fifo_set_close_zlp(struct usb_fifo *f, uint8_t onoff) in usb_fifo_set_close_zlp() argument
2447 if (f == NULL) in usb_fifo_set_close_zlp()
2451 f->flag_short = onoff; in usb_fifo_set_close_zlp()
2455 usb_fifo_set_write_defrag(struct usb_fifo *f, uint8_t onoff) in usb_fifo_set_write_defrag() argument
2457 if (f == NULL) in usb_fifo_set_write_defrag()
2461 f->flag_write_defrag = onoff; in usb_fifo_set_write_defrag()
2463 f->flag_have_fragment = 0; in usb_fifo_set_write_defrag()
2467 usb_fifo_softc(struct usb_fifo *f) in usb_fifo_softc() argument
2469 return (f->priv_sc0); in usb_fifo_softc()