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