Lines Matching full:sdev

94  * @sdev: Pointer to the stream device
101 struct tbstream_dev *sdev; member
281 static inline struct tb_xdomain *tbstream_dev_xdomain(struct tbstream_dev *sdev) in tbstream_dev_xdomain() argument
283 if (sdev->stream) in tbstream_dev_xdomain()
284 return tb_service_parent(sdev->stream->svc); in tbstream_dev_xdomain()
290 struct tbstream_dev *sdev = container_of(kref, struct tbstream_dev, kref); in tbstream_dev_release() local
292 if (sdev->stream) { in tbstream_dev_release()
293 struct tb_xdomain *xd = tbstream_dev_xdomain(sdev); in tbstream_dev_release()
295 if (sdev->out_hopid > 0) in tbstream_dev_release()
296 tb_xdomain_release_out_hopid(xd, sdev->out_hopid); in tbstream_dev_release()
297 if (sdev->in_hopid > 0) in tbstream_dev_release()
298 tb_xdomain_release_in_hopid(xd, sdev->in_hopid); in tbstream_dev_release()
300 tbstream_put(sdev->stream); in tbstream_dev_release()
302 ida_free(&tbstream_indices, sdev->index); in tbstream_dev_release()
303 kfree(sdev->misc.name); in tbstream_dev_release()
304 kfree(sdev); in tbstream_dev_release()
307 static inline void tbstream_dev_put(struct tbstream_dev *sdev) in tbstream_dev_put() argument
310 kref_put(&sdev->kref, tbstream_dev_release); in tbstream_dev_put()
313 static inline struct tbstream_dev *tbstream_dev_get(struct tbstream_dev *sdev) in tbstream_dev_get() argument
316 kref_get(&sdev->kref); in tbstream_dev_get()
317 return sdev; in tbstream_dev_get()
325 static inline int tbstream_dev_valid(const struct tbstream_dev *sdev) in tbstream_dev_valid() argument
327 const struct tbstream *stream = sdev->stream; in tbstream_dev_valid()
331 if (sdev->in_hopid <= 0 || sdev->out_hopid <= 0) in tbstream_dev_valid()
336 static inline bool tbstream_dev_removed(const struct tbstream_dev *sdev) in tbstream_dev_removed() argument
338 return sdev->removed; in tbstream_dev_removed()
341 static inline bool tbstream_dev_closed(const struct tbstream_dev *sdev) in tbstream_dev_closed() argument
343 return sdev->closed; in tbstream_dev_closed()
351 struct tbstream_dev *sdev = sf->sdev; in tbstream_dev_rx_callback() local
357 sdev->rx_ring.prod++; in tbstream_dev_rx_callback()
364 wake_up_interruptible_poll(&sdev->wait, EPOLLIN | EPOLLRDNORM); in tbstream_dev_rx_callback()
368 tbstream_dev_completed_rx(struct tbstream_dev *sdev) in tbstream_dev_completed_rx() argument
370 struct device *dma_dev = tb_ring_dma_device(sdev->rx_ring.ring); in tbstream_dev_completed_rx()
374 index = sdev->rx_ring.cons % tb_ring_size(sdev->rx_ring.ring); in tbstream_dev_completed_rx()
375 sf = &sdev->rx_ring.frames[index]; in tbstream_dev_completed_rx()
385 static int tbstream_dev_consume_rx(struct tbstream_dev *sdev) in tbstream_dev_consume_rx() argument
387 struct device *dma_dev = tb_ring_dma_device(sdev->rx_ring.ring); in tbstream_dev_consume_rx()
391 index = sdev->rx_ring.cons % tb_ring_size(sdev->rx_ring.ring); in tbstream_dev_consume_rx()
392 sdev->rx_ring.cons++; in tbstream_dev_consume_rx()
394 sf = &sdev->rx_ring.frames[index]; in tbstream_dev_consume_rx()
403 return tb_ring_rx(sdev->rx_ring.ring, &sf->frame); in tbstream_dev_consume_rx()
406 static int tbstream_dev_alloc_rx_buffers(struct tbstream_dev *sdev) in tbstream_dev_alloc_rx_buffers() argument
408 size_t ring_size = tb_ring_size(sdev->rx_ring.ring); in tbstream_dev_alloc_rx_buffers()
411 sdev->rx_ring.frames = kzalloc_objs(struct tbstream_frame, ring_size); in tbstream_dev_alloc_rx_buffers()
412 if (!sdev->rx_ring.frames) in tbstream_dev_alloc_rx_buffers()
416 struct device *dma_dev = tb_ring_dma_device(sdev->rx_ring.ring); in tbstream_dev_alloc_rx_buffers()
417 struct tbstream_frame *sf = &sdev->rx_ring.frames[i]; in tbstream_dev_alloc_rx_buffers()
432 sf->sdev = sdev; in tbstream_dev_alloc_rx_buffers()
436 tb_ring_rx(sdev->rx_ring.ring, &sf->frame); in tbstream_dev_alloc_rx_buffers()
439 sdev->rx_ring.cons = 0; in tbstream_dev_alloc_rx_buffers()
440 sdev->rx_ring.prod = 0; in tbstream_dev_alloc_rx_buffers()
449 struct tbstream_dev *sdev = sf->sdev; in tbstream_dev_tx_callback() local
454 sdev->tx_ring.prod++; in tbstream_dev_tx_callback()
456 wake_up_interruptible_poll(&sdev->wait, EPOLLOUT | EPOLLWRNORM); in tbstream_dev_tx_callback()
459 static int tbstream_dev_alloc_tx_buffers(struct tbstream_dev *sdev) in tbstream_dev_alloc_tx_buffers() argument
461 struct device *dma_dev = tb_ring_dma_device(sdev->tx_ring.ring); in tbstream_dev_alloc_tx_buffers()
462 size_t ring_size = tb_ring_size(sdev->tx_ring.ring); in tbstream_dev_alloc_tx_buffers()
465 sdev->tx_ring.frames = kzalloc_objs(struct tbstream_frame, ring_size); in tbstream_dev_alloc_tx_buffers()
466 if (!sdev->tx_ring.frames) in tbstream_dev_alloc_tx_buffers()
470 struct tbstream_frame *sf = &sdev->tx_ring.frames[i]; in tbstream_dev_alloc_tx_buffers()
485 sf->sdev = sdev; in tbstream_dev_alloc_tx_buffers()
491 sdev->tx_ring.cons = 0; in tbstream_dev_alloc_tx_buffers()
492 sdev->tx_ring.prod = ring_size - 1; in tbstream_dev_alloc_tx_buffers()
497 tbstream_dev_alloc_tx(struct tbstream_dev *sdev, enum tbstream_frame_pdf pdf, in tbstream_dev_alloc_tx() argument
500 struct device *dma_dev = tb_ring_dma_device(sdev->tx_ring.ring); in tbstream_dev_alloc_tx()
504 if (!tbstream_ring_available(&sdev->tx_ring)) in tbstream_dev_alloc_tx()
507 index = sdev->tx_ring.cons % tb_ring_size(sdev->tx_ring.ring); in tbstream_dev_alloc_tx()
508 sdev->tx_ring.cons++; in tbstream_dev_alloc_tx()
510 sf = &sdev->tx_ring.frames[index]; in tbstream_dev_alloc_tx()
518 sdev->tx_ring.cons--; in tbstream_dev_alloc_tx()
530 tbstream_dev_send_data(struct tbstream_dev *sdev, struct iov_iter *from, in tbstream_dev_send_data() argument
535 sf = tbstream_dev_alloc_tx(sdev, TBSTREAM_DATA, from, size); in tbstream_dev_send_data()
538 return tb_ring_tx(sdev->tx_ring.ring, &sf->frame); in tbstream_dev_send_data()
542 tbstream_dev_poll_ring(struct tbstream_dev *sdev, struct tbstream_ring *ring) in tbstream_dev_poll_ring() argument
546 if (!sdev->busy_poll) in tbstream_dev_poll_ring()
553 static int tbstream_dev_send_close(struct tbstream_dev *sdev) in tbstream_dev_send_close() argument
557 if (sdev->busy_poll) { in tbstream_dev_send_close()
567 if (tbstream_ring_available(&sdev->tx_ring)) in tbstream_dev_send_close()
569 tbstream_dev_poll_ring(sdev, &sdev->tx_ring); in tbstream_dev_send_close()
574 sf = tbstream_dev_alloc_tx(sdev, TBSTREAM_CLOSE, NULL, SZ_256); in tbstream_dev_send_close()
577 return tb_ring_tx(sdev->tx_ring.ring, &sf->frame); in tbstream_dev_send_close()
580 static int tbstream_dev_start(struct tbstream_dev *sdev) in tbstream_dev_start() argument
582 struct tb_xdomain *xd = tbstream_dev_xdomain(sdev); in tbstream_dev_start()
588 if (sdev->busy_poll) in tbstream_dev_start()
591 ring = tb_ring_alloc_tx(xd->tb->nhi, -1, sdev->ring_size, flags); in tbstream_dev_start()
594 sdev->tx_ring.ring = ring; in tbstream_dev_start()
596 ret = tbstream_dev_alloc_tx_buffers(sdev); in tbstream_dev_start()
604 ring = tb_ring_alloc_rx(xd->tb->nhi, -1, sdev->ring_size, flags, in tbstream_dev_start()
610 sdev->rx_ring.ring = ring; in tbstream_dev_start()
612 ret = tb_xdomain_enable_paths(xd, sdev->out_hopid, in tbstream_dev_start()
613 sdev->tx_ring.ring->hop, in tbstream_dev_start()
614 sdev->in_hopid, in tbstream_dev_start()
615 sdev->rx_ring.ring->hop); in tbstream_dev_start()
619 tb_ring_throttling(sdev->tx_ring.ring, sdev->throttling); in tbstream_dev_start()
620 tb_ring_throttling(sdev->rx_ring.ring, sdev->throttling); in tbstream_dev_start()
622 tb_ring_start(sdev->tx_ring.ring); in tbstream_dev_start()
623 tb_ring_start(sdev->rx_ring.ring); in tbstream_dev_start()
625 ret = tbstream_dev_alloc_rx_buffers(sdev); in tbstream_dev_start()
631 tb_ring_stop(sdev->rx_ring.ring); in tbstream_dev_start()
632 tb_ring_stop(sdev->tx_ring.ring); in tbstream_dev_start()
634 tb_ring_free(sdev->rx_ring.ring); in tbstream_dev_start()
636 tbstream_ring_free(&sdev->tx_ring); in tbstream_dev_start()
638 tb_ring_free(sdev->tx_ring.ring); in tbstream_dev_start()
643 static bool tbstream_dev_tx_drained(const struct tbstream_dev *sdev) in tbstream_dev_tx_drained() argument
645 const struct tbstream_ring *ring = &sdev->tx_ring; in tbstream_dev_tx_drained()
654 static void tbstream_dev_stop(struct tbstream_dev *sdev) in tbstream_dev_stop() argument
658 if (sdev->busy_poll) { in tbstream_dev_stop()
666 if (tbstream_dev_tx_drained(sdev)) in tbstream_dev_stop()
668 tbstream_dev_poll_ring(sdev, &sdev->tx_ring); in tbstream_dev_stop()
672 tb_ring_stop(sdev->tx_ring.ring); in tbstream_dev_stop()
673 tb_ring_stop(sdev->rx_ring.ring); in tbstream_dev_stop()
675 tb_ring_flush(sdev->tx_ring.ring, 500); in tbstream_dev_stop()
676 tb_ring_stop(sdev->tx_ring.ring); in tbstream_dev_stop()
677 tb_ring_flush(sdev->rx_ring.ring, 500); in tbstream_dev_stop()
678 tb_ring_stop(sdev->rx_ring.ring); in tbstream_dev_stop()
681 xd = tbstream_dev_xdomain(sdev); in tbstream_dev_stop()
683 tb_xdomain_disable_paths(xd, sdev->out_hopid, in tbstream_dev_stop()
684 sdev->tx_ring.ring->hop, in tbstream_dev_stop()
685 sdev->in_hopid, in tbstream_dev_stop()
686 sdev->rx_ring.ring->hop); in tbstream_dev_stop()
689 tbstream_ring_free(&sdev->rx_ring); in tbstream_dev_stop()
690 tb_ring_free(sdev->rx_ring.ring); in tbstream_dev_stop()
691 sdev->rx_ring.ring = NULL; in tbstream_dev_stop()
692 tbstream_ring_free(&sdev->tx_ring); in tbstream_dev_stop()
693 tb_ring_free(sdev->tx_ring.ring); in tbstream_dev_stop()
694 sdev->tx_ring.ring = NULL; in tbstream_dev_stop()
698 static int tbstream_dev_lock(struct tbstream_dev *sdev, bool nowait) in tbstream_dev_lock() argument
701 if (!mutex_trylock(&sdev->lock)) in tbstream_dev_lock()
704 if (mutex_lock_interruptible(&sdev->lock)) in tbstream_dev_lock()
715 struct tbstream_dev *sdev = to_tbstream_dev(file->private_data); in tbstream_dev_fops_read_iter() local
719 ret = tbstream_dev_valid(sdev); in tbstream_dev_fops_read_iter()
723 ret = tbstream_dev_lock(sdev, nowait); in tbstream_dev_fops_read_iter()
729 tbstream_dev_poll_ring(sdev, &sdev->rx_ring); in tbstream_dev_fops_read_iter()
731 ret = tbstream_dev_valid(sdev); in tbstream_dev_fops_read_iter()
733 mutex_unlock(&sdev->lock); in tbstream_dev_fops_read_iter()
737 if (tbstream_dev_closed(sdev) || tbstream_dev_removed(sdev)) { in tbstream_dev_fops_read_iter()
738 mutex_unlock(&sdev->lock); in tbstream_dev_fops_read_iter()
742 if (tbstream_ring_available(&sdev->rx_ring)) in tbstream_dev_fops_read_iter()
745 mutex_unlock(&sdev->lock); in tbstream_dev_fops_read_iter()
750 if (sdev->busy_poll) { in tbstream_dev_fops_read_iter()
755 ret = wait_event_interruptible(sdev->wait, in tbstream_dev_fops_read_iter()
756 tbstream_ring_available(&sdev->rx_ring) || in tbstream_dev_fops_read_iter()
757 tbstream_dev_valid(sdev) != 0 || in tbstream_dev_fops_read_iter()
758 tbstream_dev_closed(sdev) || in tbstream_dev_fops_read_iter()
759 tbstream_dev_removed(sdev)); in tbstream_dev_fops_read_iter()
764 ret = tbstream_dev_lock(sdev, nowait); in tbstream_dev_fops_read_iter()
774 sf = tbstream_dev_completed_rx(sdev); in tbstream_dev_fops_read_iter()
785 tbstream_dev_consume_rx(sdev); in tbstream_dev_fops_read_iter()
786 sdev->closed = true; in tbstream_dev_fops_read_iter()
808 ret = tbstream_dev_consume_rx(sdev); in tbstream_dev_fops_read_iter()
816 mutex_unlock(&sdev->lock); in tbstream_dev_fops_read_iter()
827 struct tbstream_dev *sdev = to_tbstream_dev(file->private_data); in tbstream_dev_fops_write_iter() local
831 ret = tbstream_dev_valid(sdev); in tbstream_dev_fops_write_iter()
835 ret = tbstream_dev_lock(sdev, nowait); in tbstream_dev_fops_write_iter()
840 tbstream_dev_poll_ring(sdev, &sdev->tx_ring); in tbstream_dev_fops_write_iter()
842 ret = tbstream_dev_valid(sdev); in tbstream_dev_fops_write_iter()
844 mutex_unlock(&sdev->lock); in tbstream_dev_fops_write_iter()
848 if (tbstream_dev_closed(sdev) || tbstream_dev_removed(sdev)) { in tbstream_dev_fops_write_iter()
849 mutex_unlock(&sdev->lock); in tbstream_dev_fops_write_iter()
853 if (tbstream_ring_available(&sdev->tx_ring)) in tbstream_dev_fops_write_iter()
856 mutex_unlock(&sdev->lock); in tbstream_dev_fops_write_iter()
861 if (sdev->busy_poll) { in tbstream_dev_fops_write_iter()
866 ret = wait_event_interruptible(sdev->wait, in tbstream_dev_fops_write_iter()
867 tbstream_ring_available(&sdev->tx_ring) || in tbstream_dev_fops_write_iter()
868 tbstream_dev_valid(sdev) != 0 || in tbstream_dev_fops_write_iter()
869 tbstream_dev_closed(sdev) || in tbstream_dev_fops_write_iter()
870 tbstream_dev_removed(sdev)); in tbstream_dev_fops_write_iter()
875 ret = tbstream_dev_lock(sdev, nowait); in tbstream_dev_fops_write_iter()
885 ret = tbstream_dev_send_data(sdev, from, size); in tbstream_dev_fops_write_iter()
899 mutex_unlock(&sdev->lock); in tbstream_dev_fops_write_iter()
908 struct tbstream_dev *sdev = to_tbstream_dev(file->private_data); in tbstream_dev_fops_poll() local
915 if (sdev->busy_poll) in tbstream_dev_fops_poll()
918 poll_wait(file, &sdev->wait, wait); in tbstream_dev_fops_poll()
919 guard(mutex)(&sdev->lock); in tbstream_dev_fops_poll()
920 if (tbstream_dev_valid(sdev) != 0) { in tbstream_dev_fops_poll()
923 if (tbstream_ring_available(&sdev->tx_ring)) in tbstream_dev_fops_poll()
925 if (tbstream_ring_available(&sdev->rx_ring)) in tbstream_dev_fops_poll()
933 struct tbstream_dev *sdev = to_tbstream_dev(file->private_data); in tbstream_dev_fops_open() local
936 tbstream_dev_get(sdev); in tbstream_dev_fops_open()
938 if (mutex_lock_interruptible(&sdev->lock)) { in tbstream_dev_fops_open()
939 tbstream_dev_put(sdev); in tbstream_dev_fops_open()
947 while ((ret = tbstream_dev_valid(sdev))) { in tbstream_dev_fops_open()
948 mutex_unlock(&sdev->lock); in tbstream_dev_fops_open()
953 ret = wait_event_interruptible(sdev->wait, in tbstream_dev_fops_open()
954 tbstream_dev_valid(sdev) == 0 || in tbstream_dev_fops_open()
955 tbstream_dev_removed(sdev)); in tbstream_dev_fops_open()
959 if (tbstream_dev_removed(sdev)) { in tbstream_dev_fops_open()
964 if (mutex_lock_interruptible(&sdev->lock)) { in tbstream_dev_fops_open()
971 if (!sdev->users++) { in tbstream_dev_fops_open()
972 ret = tbstream_dev_start(sdev); in tbstream_dev_fops_open()
974 sdev->users--; in tbstream_dev_fops_open()
977 sdev->closed = false; in tbstream_dev_fops_open()
980 mutex_unlock(&sdev->lock); in tbstream_dev_fops_open()
984 mutex_unlock(&sdev->lock); in tbstream_dev_fops_open()
986 tbstream_dev_put(sdev); in tbstream_dev_fops_open()
993 struct tbstream_dev *sdev = to_tbstream_dev(file->private_data); in tbstream_dev_fops_release() local
995 mutex_lock(&sdev->lock); in tbstream_dev_fops_release()
996 if (--sdev->users == 0) { in tbstream_dev_fops_release()
1002 tbstream_dev_send_close(sdev); in tbstream_dev_fops_release()
1003 tbstream_dev_stop(sdev); in tbstream_dev_fops_release()
1005 mutex_unlock(&sdev->lock); in tbstream_dev_fops_release()
1007 tbstream_dev_put(sdev); in tbstream_dev_fops_release()
1030 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_busy_poll_show() local
1032 return sysfs_emit(buf, "%u\n", sdev->busy_poll); in tbstream_dev_busy_poll_show()
1040 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_busy_poll_store() local
1048 guard(mutex)(&sdev->lock); in tbstream_dev_busy_poll_store()
1049 if (sdev->users) in tbstream_dev_busy_poll_store()
1051 sdev->busy_poll = busy_poll; in tbstream_dev_busy_poll_store()
1059 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_index_show() local
1061 return sysfs_emit(buf, "%d\n", sdev->index); in tbstream_dev_index_show()
1068 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_in_hopid_show() local
1070 return sysfs_emit(buf, "%d\n", sdev->in_hopid); in tbstream_dev_in_hopid_show()
1167 static int tbstream_dev_update_properties(struct tbstream_dev *sdev) in tbstream_dev_update_properties() argument
1172 stream = tbstream_get(sdev->stream); in tbstream_dev_update_properties()
1177 config_item_name(&sdev->group.cg_item), in tbstream_dev_update_properties()
1178 sdev->in_hopid, sdev->out_hopid); in tbstream_dev_update_properties()
1186 static int tbstream_dev_alloc_in_hopid(struct tbstream_dev *sdev, int hopid) in tbstream_dev_alloc_in_hopid() argument
1188 struct tb_xdomain *xd = tbstream_dev_xdomain(sdev); in tbstream_dev_alloc_in_hopid()
1191 if (sdev->in_hopid > 0 && sdev->in_hopid != hopid) in tbstream_dev_alloc_in_hopid()
1192 tb_xdomain_release_in_hopid(xd, sdev->in_hopid); in tbstream_dev_alloc_in_hopid()
1194 sdev->in_hopid = hopid; in tbstream_dev_alloc_in_hopid()
1208 sdev->in_hopid = ret; in tbstream_dev_alloc_in_hopid()
1212 static int tbstream_dev_alloc_out_hopid(struct tbstream_dev *sdev, int hopid) in tbstream_dev_alloc_out_hopid() argument
1214 struct tb_xdomain *xd = tbstream_dev_xdomain(sdev); in tbstream_dev_alloc_out_hopid()
1217 if (sdev->out_hopid > 0 && sdev->out_hopid != hopid) in tbstream_dev_alloc_out_hopid()
1218 tb_xdomain_release_out_hopid(xd, sdev->out_hopid); in tbstream_dev_alloc_out_hopid()
1220 sdev->out_hopid = hopid; in tbstream_dev_alloc_out_hopid()
1230 sdev->out_hopid = ret; in tbstream_dev_alloc_out_hopid()
1239 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_in_hopid_store() local
1246 guard(mutex)(&sdev->lock); in tbstream_dev_in_hopid_store()
1247 if (sdev->users) in tbstream_dev_in_hopid_store()
1249 if (sdev->stream) { in tbstream_dev_in_hopid_store()
1250 ret = tbstream_dev_alloc_in_hopid(sdev, in_hopid); in tbstream_dev_in_hopid_store()
1253 ret = tbstream_dev_update_properties(sdev); in tbstream_dev_in_hopid_store()
1255 sdev->in_hopid = in_hopid; in tbstream_dev_in_hopid_store()
1264 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_out_hopid_show() local
1266 return sysfs_emit(buf, "%d\n", sdev->out_hopid); in tbstream_dev_out_hopid_show()
1274 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_out_hopid_store() local
1281 guard(mutex)(&sdev->lock); in tbstream_dev_out_hopid_store()
1282 if (sdev->users) in tbstream_dev_out_hopid_store()
1284 if (sdev->stream) { in tbstream_dev_out_hopid_store()
1285 ret = tbstream_dev_alloc_out_hopid(sdev, out_hopid); in tbstream_dev_out_hopid_store()
1288 ret = tbstream_dev_update_properties(sdev); in tbstream_dev_out_hopid_store()
1290 sdev->out_hopid = out_hopid; in tbstream_dev_out_hopid_store()
1299 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_ring_size_show() local
1301 return sysfs_emit(buf, "%u\n", sdev->ring_size); in tbstream_dev_ring_size_show()
1309 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_ring_size_store() local
1321 guard(mutex)(&sdev->lock); in tbstream_dev_ring_size_store()
1322 if (sdev->users) in tbstream_dev_ring_size_store()
1324 sdev->ring_size = ring_size; in tbstream_dev_ring_size_store()
1332 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_throttling_show() local
1334 return sysfs_emit(buf, "%u\n", sdev->throttling); in tbstream_dev_throttling_show()
1342 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_throttling_store() local
1353 guard(mutex)(&sdev->lock); in tbstream_dev_throttling_store()
1354 if (sdev->users) in tbstream_dev_throttling_store()
1356 sdev->throttling = throttling; in tbstream_dev_throttling_store()
1374 struct tbstream_dev *sdev = tbstream_dev_from_group(group); in tbstream_dev_item_release() local
1376 misc_deregister(&sdev->misc); in tbstream_dev_item_release()
1377 tbstream_dev_put(sdev); in tbstream_dev_item_release()
1419 tbstream_dev_attach_stream(struct tbstream_dev *sdev, struct tbstream_group *sg) in tbstream_dev_attach_stream() argument
1421 const char *name = config_item_name(&sdev->group.cg_item); in tbstream_dev_attach_stream()
1428 scoped_guard(mutex, &sdev->lock) { in tbstream_dev_attach_stream()
1429 sdev->stream = stream; in tbstream_dev_attach_stream()
1435 if (sdev->in_hopid <= 0 && sdev->out_hopid <= 0) in tbstream_dev_attach_stream()
1436 service_get_hopids(stream->svc, name, &sdev->in_hopid, in tbstream_dev_attach_stream()
1437 &sdev->out_hopid); in tbstream_dev_attach_stream()
1438 if (sdev->in_hopid) in tbstream_dev_attach_stream()
1439 tbstream_dev_alloc_in_hopid(sdev, sdev->in_hopid); in tbstream_dev_attach_stream()
1440 if (sdev->out_hopid) in tbstream_dev_attach_stream()
1441 tbstream_dev_alloc_out_hopid(sdev, sdev->out_hopid); in tbstream_dev_attach_stream()
1444 service_update_properties(stream->svc, name, sdev->in_hopid, in tbstream_dev_attach_stream()
1445 sdev->out_hopid); in tbstream_dev_attach_stream()
1449 wake_up_interruptible(&sdev->wait); in tbstream_dev_attach_stream()
1452 static void tbstream_dev_detach_stream(struct tbstream_dev *sdev) in tbstream_dev_detach_stream() argument
1454 const char *name = config_item_name(&sdev->group.cg_item); in tbstream_dev_detach_stream()
1458 scoped_guard(mutex, &sdev->lock) { in tbstream_dev_detach_stream()
1459 stream = sdev->stream; in tbstream_dev_detach_stream()
1462 sdev->stream = NULL; in tbstream_dev_detach_stream()
1464 if (sdev->out_hopid > 0) in tbstream_dev_detach_stream()
1465 tb_xdomain_release_out_hopid(xd, sdev->out_hopid); in tbstream_dev_detach_stream()
1466 if (sdev->in_hopid > 0) in tbstream_dev_detach_stream()
1467 tb_xdomain_release_in_hopid(xd, sdev->in_hopid); in tbstream_dev_detach_stream()
1476 wake_up_interruptible_poll(&sdev->wait, EPOLLHUP | EPOLLERR); in tbstream_dev_detach_stream()
1489 struct tbstream_dev *sdev; in tbstream_dev_make_group() local
1499 sdev = kzalloc_obj(*sdev); in tbstream_dev_make_group()
1500 if (!sdev) in tbstream_dev_make_group()
1505 kfree(sdev); in tbstream_dev_make_group()
1509 sdev->index = index; in tbstream_dev_make_group()
1510 sdev->ring_size = TBSTREAM_DEV_RING_SIZE; in tbstream_dev_make_group()
1511 sdev->throttling = TBSTREAM_DEV_THROTTLING; in tbstream_dev_make_group()
1512 mutex_init(&sdev->lock); in tbstream_dev_make_group()
1513 init_waitqueue_head(&sdev->wait); in tbstream_dev_make_group()
1514 INIT_LIST_HEAD(&sdev->list); in tbstream_dev_make_group()
1515 /* This point forward tbstream_dev_put() must be used to release sdev */ in tbstream_dev_make_group()
1516 kref_init(&sdev->kref); in tbstream_dev_make_group()
1518 config_group_init_type_name(&sdev->group, name, &tbstream_dev_type); in tbstream_dev_make_group()
1521 list_add_tail(&sdev->list, &sg->dev_list); in tbstream_dev_make_group()
1523 tbstream_dev_attach_stream(sdev, sg); in tbstream_dev_make_group()
1525 sdev->misc.name = kasprintf(GFP_KERNEL, "tbstream%d", index); in tbstream_dev_make_group()
1526 sdev->misc.minor = MISC_DYNAMIC_MINOR; in tbstream_dev_make_group()
1527 sdev->misc.fops = &tbstream_dev_fops; in tbstream_dev_make_group()
1529 ret = misc_register(&sdev->misc); in tbstream_dev_make_group()
1531 tbstream_dev_detach_stream(sdev); in tbstream_dev_make_group()
1533 list_del(&sdev->list); in tbstream_dev_make_group()
1535 config_group_put(&sdev->group); in tbstream_dev_make_group()
1539 return &sdev->group; in tbstream_dev_make_group()
1546 struct tbstream_dev *sdev = tbstream_dev_from_group(sdev_group); in tbstream_dev_drop_item() local
1550 list_del(&sdev->list); in tbstream_dev_drop_item()
1552 sdev->removed = true; in tbstream_dev_drop_item()
1553 wake_up_interruptible_poll(&sdev->wait, EPOLLHUP | EPOLLERR); in tbstream_dev_drop_item()
1646 struct tbstream_dev *sdev; in tbstream_group_attach_stream() local
1662 list_for_each_entry(sdev, &sg->dev_list, list) { in tbstream_group_attach_stream()
1663 tbstream_dev_get(sdev); in tbstream_group_attach_stream()
1664 tbstream_dev_attach_stream(sdev, sg); in tbstream_group_attach_stream()
1665 tbstream_dev_put(sdev); in tbstream_group_attach_stream()
1674 struct tbstream_dev *sdev; in tbstream_group_detach_stream() local
1683 list_for_each_entry_reverse(sdev, &sg->dev_list, list) { in tbstream_group_detach_stream()
1684 tbstream_dev_get(sdev); in tbstream_group_detach_stream()
1685 tbstream_dev_detach_stream(sdev); in tbstream_group_detach_stream()
1686 tbstream_dev_put(sdev); in tbstream_group_detach_stream()
1731 struct tbstream_dev *sdev; in tbstream_suspend() local
1737 list_for_each_entry_reverse(sdev, &sg->dev_list, list) { in tbstream_suspend()
1738 tbstream_dev_get(sdev); in tbstream_suspend()
1740 if (sdev->users) in tbstream_suspend()
1741 tbstream_dev_stop(sdev); in tbstream_suspend()
1742 tbstream_dev_put(sdev); in tbstream_suspend()
1754 struct tbstream_dev *sdev; in tbstream_resume() local
1760 list_for_each_entry(sdev, &sg->dev_list, list) { in tbstream_resume()
1761 tbstream_dev_get(sdev); in tbstream_resume()
1762 if (sdev->users) { in tbstream_resume()
1765 ret = tbstream_dev_start(sdev); in tbstream_resume()
1767 tbstream_dev_put(sdev); in tbstream_resume()
1772 tbstream_dev_put(sdev); in tbstream_resume()