Lines Matching refs:chan

587 		struct xillyusb_channel *chan = &xdev->channels[i];
589 mutex_lock(&chan->lock);
591 if (chan->in_fifo) {
596 chan->read_data_ok = 0;
597 wake_up_interruptible(&chan->in_fifo->waitq);
600 if (chan->out_ep)
601 wake_up_interruptible(&chan->out_ep->fifo.waitq);
603 mutex_unlock(&chan->lock);
605 wake_up_interruptible(&chan->flushq);
635 * safely_assign_in_fifo() changes the value of chan->in_fifo and ensures
639 static void safely_assign_in_fifo(struct xillyusb_channel *chan,
642 mutex_lock(&chan->lock);
643 chan->in_fifo = fifo;
644 mutex_unlock(&chan->lock);
646 flush_work(&chan->xdev->in_ep->workitem);
888 struct xillyusb_channel *chan;
898 chan = &xdev->channels[chan_idx];
902 if (!chan->read_data_ok) {
914 WRITE_ONCE(chan->read_data_ok, 0);
915 wake_up_interruptible(&chan->in_fifo->waitq);
919 chan->flushing = 0;
920 wake_up_interruptible(&chan->flushq);
924 chan->canceled = 1;
925 wake_up_interruptible(&chan->flushq);
945 struct xillyusb_channel *chan;
1003 chan = &xdev->channels[chan_idx];
1005 fifo = chan->in_fifo;
1119 * This function is not reentrant for the same @chan, but this is covered
1120 * by the fact that for any given @chan, it's called either by the open,
1124 * chan->flushed is there to avoid multiple flushes at the same position,
1129 static int flush_downstream(struct xillyusb_channel *chan,
1133 struct xillyusb_dev *xdev = chan->xdev;
1134 int chan_num = chan->chan_idx << 1;
1138 if (chan->flushed)
1143 if (chan->flushing) {
1146 chan->canceled = 0;
1154 while (!chan->canceled) {
1162 rc = wait_event_interruptible_timeout(chan->flushq,
1163 chan->canceled ||
1172 chan->flushing = 1;
1183 chan->out_bytes >>
1184 chan->out_log2_element_size);
1190 while (chan->flushing) {
1191 rc = wait_event_interruptible(chan->flushq,
1192 !chan->flushing ||
1204 while (chan->flushing) {
1210 rc = wait_event_interruptible_timeout(chan->flushq,
1211 !chan->flushing ||
1223 chan->flushed = 1;
1228 static int request_read_anything(struct xillyusb_channel *chan,
1231 struct xillyusb_dev *xdev = chan->xdev;
1232 unsigned int sh = chan->in_log2_element_size;
1233 int chan_num = (chan->chan_idx << 1) | 1;
1234 u32 mercy = chan->in_consumed_bytes + (2 << sh) - 1;
1242 struct xillyusb_channel *chan;
1259 chan = &xdev->channels[index];
1260 filp->private_data = chan;
1262 mutex_lock(&chan->lock);
1269 if (((filp->f_mode & FMODE_READ) && !chan->readable) ||
1270 ((filp->f_mode & FMODE_WRITE) && !chan->writable))
1274 chan->in_synchronous) {
1281 chan->out_synchronous) {
1289 if (((filp->f_mode & FMODE_READ) && chan->open_for_read) ||
1290 ((filp->f_mode & FMODE_WRITE) && chan->open_for_write))
1294 chan->open_for_read = 1;
1297 chan->open_for_write = 1;
1299 mutex_unlock(&chan->lock);
1303 (chan->chan_idx + 2) | USB_DIR_OUT,
1311 rc = fifo_init(&out_ep->fifo, chan->out_log2_fifo_size);
1316 out_ep->fill_mask = -(1 << chan->out_log2_element_size);
1317 chan->out_bytes = 0;
1318 chan->flushed = 0;
1330 rc = flush_downstream(chan, XILLY_RESPONSE_TIMEOUT, false);
1349 rc = fifo_init(in_fifo, chan->in_log2_fifo_size);
1357 mutex_lock(&chan->lock);
1359 chan->in_fifo = in_fifo;
1360 chan->read_data_ok = 1;
1363 chan->out_ep = out_ep;
1364 mutex_unlock(&chan->lock);
1369 if (!chan->in_synchronous)
1371 chan->in_log2_element_size;
1373 chan->in_consumed_bytes = 0;
1374 chan->poll_used = 0;
1375 chan->in_current_checkpoint = in_checkpoint;
1376 rc = xillyusb_send_opcode(xdev, (chan->chan_idx << 1) | 1,
1392 request_read_anything(chan, OPCODE_SET_PUSH);
1398 chan->read_data_ok = 0;
1399 safely_assign_in_fifo(chan, NULL);
1404 mutex_lock(&chan->lock);
1405 chan->out_ep = NULL;
1406 mutex_unlock(&chan->lock);
1414 mutex_lock(&chan->lock);
1417 chan->open_for_read = 0;
1420 chan->open_for_write = 0;
1422 mutex_unlock(&chan->lock);
1430 mutex_unlock(&chan->lock);
1437 struct xillyusb_channel *chan = filp->private_data;
1438 struct xillyusb_dev *xdev = chan->xdev;
1439 struct xillyfifo *fifo = chan->in_fifo;
1440 int chan_num = (chan->chan_idx << 1) | 1;
1449 rc = mutex_lock_interruptible(&chan->in_mutex);
1459 unsigned int sh = chan->in_log2_element_size;
1469 chan->in_consumed_bytes += rc;
1481 fifo_checkpoint_bytes = chan->in_consumed_bytes + fifo->size;
1483 chan->in_consumed_bytes + count - bytes_done;
1491 if (chan->in_synchronous && diff >= 0) {
1499 leap = (checkpoint - chan->in_current_checkpoint) << sh;
1508 * chan->read_data_ok is checked to spare an unnecessary
1513 if (chan->read_data_ok &&
1516 chan->in_current_checkpoint = checkpoint;
1536 if (!READ_ONCE(chan->read_data_ok)) { /* FPGA has sent EOF */
1577 fifo->fill || !chan->read_data_ok,
1581 rc = request_read_anything(chan, OPCODE_UPDATE_PUSH);
1588 fifo->fill || !chan->read_data_ok);
1597 if (((filp->f_flags & O_NONBLOCK) || chan->poll_used) &&
1599 request_read_anything(chan, OPCODE_SET_PUSH);
1601 mutex_unlock(&chan->in_mutex);
1611 struct xillyusb_channel *chan = filp->private_data;
1617 rc = mutex_lock_interruptible(&chan->out_mutex);
1627 rc = flush_downstream(chan, HZ, false);
1629 mutex_unlock(&chan->out_mutex);
1633 struct xillyusb_dev *xdev = chan->xdev;
1635 mutex_lock(&chan->lock);
1639 mutex_unlock(&chan->lock);
1648 struct xillyusb_channel *chan = filp->private_data;
1649 struct xillyusb_dev *xdev = chan->xdev;
1650 struct xillyfifo *fifo = &chan->out_ep->fifo;
1653 rc = mutex_lock_interruptible(&chan->out_mutex);
1689 chan->out_bytes += rc;
1692 try_queue_bulk_out(chan->out_ep);
1693 chan->flushed = 0;
1696 if (chan->out_synchronous) {
1697 int flush_rc = flush_downstream(chan, 0, true);
1704 mutex_unlock(&chan->out_mutex);
1711 struct xillyusb_channel *chan = filp->private_data;
1712 struct xillyusb_dev *xdev = chan->xdev;
1716 struct xillyfifo *in_fifo = chan->in_fifo;
1718 rc_read = xillyusb_send_opcode(xdev, (chan->chan_idx << 1) | 1,
1729 * there's a global device error, chan->read_data_ok is
1734 !chan->read_data_ok))
1737 safely_assign_in_fifo(chan, NULL);
1741 mutex_lock(&chan->lock);
1742 chan->open_for_read = 0;
1743 mutex_unlock(&chan->lock);
1747 struct xillyusb_endpoint *ep = chan->out_ep;
1749 * chan->flushing isn't zeroed. If the pre-release flush timed
1759 mutex_lock(&chan->lock);
1760 chan->out_ep = NULL;
1761 mutex_unlock(&chan->lock);
1767 rc_write = xillyusb_send_opcode(xdev, chan->chan_idx << 1,
1770 mutex_lock(&chan->lock);
1771 chan->open_for_write = 0;
1772 mutex_unlock(&chan->lock);
1787 struct xillyusb_channel *chan = filp->private_data;
1788 struct xillyusb_dev *xdev = chan->xdev;
1791 unsigned int log2_element_size = chan->readable ?
1792 chan->in_log2_element_size : chan->out_log2_element_size;
1801 mutex_lock(&chan->out_mutex);
1802 mutex_lock(&chan->in_mutex);
1825 rc = xillyusb_send_opcode(xdev, chan->chan_idx << 1,
1832 if (chan->writable) {
1833 chan->flushed = 0;
1834 rc = flush_downstream(chan, HZ, false);
1838 mutex_unlock(&chan->out_mutex);
1839 mutex_unlock(&chan->in_mutex);
1851 struct xillyusb_channel *chan = filp->private_data;
1854 if (chan->in_fifo)
1855 poll_wait(filp, &chan->in_fifo->waitq, wait);
1857 if (chan->out_ep)
1858 poll_wait(filp, &chan->out_ep->fifo.waitq, wait);
1870 if (!chan->poll_used && chan->in_fifo) {
1871 chan->poll_used = 1;
1872 request_read_anything(chan, OPCODE_SET_PUSH);
1882 if (chan->in_fifo && !chan->in_synchronous &&
1883 (READ_ONCE(chan->in_fifo->fill) || !chan->read_data_ok))
1886 if (chan->out_ep &&
1887 (READ_ONCE(chan->out_ep->fifo.fill) != chan->out_ep->fifo.size))
1890 if (chan->xdev->error)
1938 struct xillyusb_channel *chan;
1941 chan = kcalloc(num_channels, sizeof(*chan), GFP_KERNEL);
1942 if (!chan)
1945 xdev->channels = chan;
1947 for (i = 0; i < num_channels; i++, chan++) {
1951 chan->xdev = xdev;
1952 mutex_init(&chan->in_mutex);
1953 mutex_init(&chan->out_mutex);
1954 mutex_init(&chan->lock);
1955 init_waitqueue_head(&chan->flushq);
1957 chan->chan_idx = i;
1960 chan->readable = 1;
1961 chan->in_synchronous = !!(in_desc & 0x40);
1962 chan->in_seekable = !!(in_desc & 0x20);
1963 chan->in_log2_element_size = in_desc & 0x0f;
1964 chan->in_log2_fifo_size = ((in_desc >> 8) & 0x1f) + 16;
1974 chan->writable = 1;
1975 chan->out_synchronous = !!(out_desc & 0x40);
1976 chan->out_seekable = !!(out_desc & 0x20);
1977 chan->out_log2_element_size = out_desc & 0x0f;
1978 chan->out_log2_fifo_size =
1992 struct xillyusb_channel *chan;
2020 chan = xdev->channels;
2022 chan->in_fifo = &idt_fifo;
2023 chan->read_data_ok = 1;
2035 !chan->read_data_ok,
2048 if (chan->read_data_ok) {
2106 kfree(chan);
2123 safely_assign_in_fifo(chan, NULL);
2224 struct xillyusb_channel *chan = &xdev->channels[i];
2227 * Lock taken to prevent chan->out_ep from changing. It also
2231 mutex_lock(&chan->lock);
2232 if (chan->out_ep)
2233 endpoint_quiesce(chan->out_ep);
2234 mutex_unlock(&chan->lock);