Lines Matching refs:s

334 static struct packet_list *stream_get_free_packet_list(struct stream *s)  in stream_get_free_packet_list()  argument
339 if (list_empty(&s->free_packet_lists)) in stream_get_free_packet_list()
342 spin_lock_irqsave(&s->packet_list_lock, flags); in stream_get_free_packet_list()
343 pl = list_entry(s->free_packet_lists.next, struct packet_list, link); in stream_get_free_packet_list()
345 spin_unlock_irqrestore(&s->packet_list_lock, flags); in stream_get_free_packet_list()
350 static void stream_start_dma(struct stream *s, struct packet_list *pl) in stream_start_dma() argument
354 cycle_count = reg_read(s->host->ohci, in stream_start_dma()
366 ohci1394_start_it_ctx(s->host->ohci, s->iso_tasklet.context, in stream_start_dma()
371 static void stream_put_dma_packet_list(struct stream *s, in stream_put_dma_packet_list() argument
378 pl->last_cycle_count = atomic_read(&s->cycle_count2) - 1; in stream_put_dma_packet_list()
381 spin_lock_irqsave(&s->packet_list_lock, flags); in stream_put_dma_packet_list()
382 list_add_tail(&pl->link, &s->dma_packet_lists); in stream_put_dma_packet_list()
383 spin_unlock_irqrestore(&s->packet_list_lock, flags); in stream_put_dma_packet_list()
386 if (pl->link.prev != &s->dma_packet_lists) { in stream_put_dma_packet_list()
390 ohci1394_wake_it_ctx(s->host->ohci, s->iso_tasklet.context); in stream_put_dma_packet_list()
393 stream_start_dma(s, pl); in stream_put_dma_packet_list()
398 struct stream *s = (struct stream *) l; in stream_shift_packet_lists() local
403 if (list_empty(&s->dma_packet_lists)) { in stream_shift_packet_lists()
412 pl = list_entry(s->dma_packet_lists.next, struct packet_list, link); in stream_shift_packet_lists()
443 if (diff > 0 && s->stale_count == 0) { in stream_shift_packet_lists()
444 atomic_add(diff, &s->cycle_count); in stream_shift_packet_lists()
445 atomic_add(diff, &s->cycle_count2); in stream_shift_packet_lists()
446 s->stale_count = MAX_PACKET_LISTS; in stream_shift_packet_lists()
449 if (s->stale_count > 0) in stream_shift_packet_lists()
450 s->stale_count--; in stream_shift_packet_lists()
455 spin_lock(&s->packet_list_lock); in stream_shift_packet_lists()
457 list_add_tail(&pl->link, &s->free_packet_lists); in stream_shift_packet_lists()
458 spin_unlock(&s->packet_list_lock); in stream_shift_packet_lists()
460 wake_up_interruptible(&s->packet_list_wait); in stream_shift_packet_lists()
463 static struct packet *stream_current_packet(struct stream *s) in stream_current_packet() argument
465 if (s->current_packet_list == NULL && in stream_current_packet()
466 (s->current_packet_list = stream_get_free_packet_list(s)) == NULL) in stream_current_packet()
469 return &s->current_packet_list->packets[s->current_packet]; in stream_current_packet()
472 static void stream_queue_packet(struct stream *s) in stream_queue_packet() argument
474 s->current_packet++; in stream_queue_packet()
475 if (s->current_packet == PACKET_LIST_SIZE) { in stream_queue_packet()
476 stream_put_dma_packet_list(s, s->current_packet_list); in stream_queue_packet()
477 s->current_packet_list = NULL; in stream_queue_packet()
478 s->current_packet = 0; in stream_queue_packet()
561 struct packet_list *packet_list_alloc(struct stream *s) in packet_list_alloc() argument
573 p->db = pci_pool_alloc(s->descriptor_pool, SLAB_KERNEL, in packet_list_alloc()
575 p->payload = pci_pool_alloc(s->packet_pool, SLAB_KERNEL, in packet_list_alloc()
590 void packet_list_free(struct packet_list *pl, struct stream *s) in packet_list_free() argument
596 pci_pool_free(s->descriptor_pool, p->db, p->db_bus); in packet_list_free()
597 pci_pool_free(s->packet_pool, p->payload, p->payload_bus); in packet_list_free()
654 static u32 get_iec958_header_bits(struct stream *s, int sub_frame, u32 sample) in get_iec958_header_bits() argument
660 switch (s->iec958_frame_count) { in get_iec958_header_bits()
662 csi = s->format == AMDTP_FORMAT_IEC958_AC3; in get_iec958_header_bits()
669 csi = (s->iec958_rate_code >> (27 - s->iec958_frame_count)) & 0x01; in get_iec958_header_bits()
676 block_start = (s->iec958_frame_count == 0 && sub_frame == 0); in get_iec958_header_bits()
691 static u32 get_header_bits(struct stream *s, int sub_frame, u32 sample) in get_header_bits() argument
693 switch (s->format) { in get_header_bits()
696 return get_iec958_header_bits(s, sub_frame, sample); in get_header_bits()
706 static void fill_payload_le16(struct stream *s, quadlet_t *data, int nevents) in fill_payload_le16() argument
714 for (j = 0; j < s->dimension; j++) { in fill_payload_le16()
715 p = buffer_get_bytes(s->input, 2); in fill_payload_le16()
717 bits = get_header_bits(s, j, sample); in fill_payload_le16()
721 event += s->dimension; in fill_payload_le16()
722 if (++s->iec958_frame_count == 192) in fill_payload_le16()
723 s->iec958_frame_count = 0; in fill_payload_le16()
727 static void fill_packet(struct stream *s, struct packet *packet, int nevents) in fill_packet() argument
732 size = (nevents * s->dimension + 2) * sizeof(quadlet_t); in fill_packet()
742 (s->iso_channel << 8) | (TCODE_ISO_DATA << 4); in fill_packet()
748 syt_index = (s->syt_interval - s->dbc) & (s->syt_interval - 1); in fill_packet()
750 syt = ((atomic_read(&s->cycle_count) << 12) | in fill_packet()
751 s->cycle_offset.integer) & 0xffff; in fill_packet()
752 fraction_add(&s->cycle_offset, in fill_packet()
753 &s->cycle_offset, &s->ticks_per_syt_offset); in fill_packet()
758 atomic_add(s->cycle_offset.integer / 3072, &s->cycle_count); in fill_packet()
759 s->cycle_offset.integer %= 3072; in fill_packet()
764 atomic_inc(&s->cycle_count2); in fill_packet()
768 packet->payload->sid = s->host->host->node_id & 0x3f; in fill_packet()
769 packet->payload->dbs = s->dimension; in fill_packet()
774 packet->payload->dbc = s->dbc; in fill_packet()
777 packet->payload->fdf = s->fdf; in fill_packet()
780 switch (s->sample_format) { in fill_packet()
782 fill_payload_le16(s, packet->payload->data, nevents); in fill_packet()
786 s->dbc += nevents; in fill_packet()
789 static void stream_flush(struct stream *s) in stream_flush() argument
811 fraction_add(&next, &s->ready_samples, &s->samples_per_cycle); in stream_flush()
812 if (s->mode == AMDTP_MODE_BLOCKING) { in stream_flush()
813 if (fraction_floor(&next) >= s->syt_interval) in stream_flush()
814 nevents = s->syt_interval; in stream_flush()
821 p = stream_current_packet(s); in stream_flush()
822 if (s->input->length < nevents * s->dimension * 2 || p == NULL) in stream_flush()
825 fill_packet(s, p, nevents); in stream_flush()
826 stream_queue_packet(s); in stream_flush()
830 fraction_sub_int(&s->ready_samples, &next, nevents); in stream_flush()
834 static int stream_alloc_packet_lists(struct stream *s) in stream_alloc_packet_lists() argument
838 if (s->mode == AMDTP_MODE_BLOCKING) in stream_alloc_packet_lists()
839 max_nevents = s->syt_interval; in stream_alloc_packet_lists()
841 max_nevents = fraction_ceil(&s->samples_per_cycle); in stream_alloc_packet_lists()
843 max_packet_size = max_nevents * s->dimension * 4 + 8; in stream_alloc_packet_lists()
844 s->packet_pool = pci_pool_create("packet pool", s->host->ohci->dev, in stream_alloc_packet_lists()
847 if (s->packet_pool == NULL) in stream_alloc_packet_lists()
850 INIT_LIST_HEAD(&s->free_packet_lists); in stream_alloc_packet_lists()
851 INIT_LIST_HEAD(&s->dma_packet_lists); in stream_alloc_packet_lists()
853 struct packet_list *pl = packet_list_alloc(s); in stream_alloc_packet_lists()
856 list_add_tail(&pl->link, &s->free_packet_lists); in stream_alloc_packet_lists()
862 static void stream_free_packet_lists(struct stream *s) in stream_free_packet_lists() argument
866 if (s->current_packet_list != NULL) in stream_free_packet_lists()
867 packet_list_free(s->current_packet_list, s); in stream_free_packet_lists()
868 list_for_each_safe(lh, next, &s->dma_packet_lists) in stream_free_packet_lists()
869 packet_list_free(list_entry(lh, struct packet_list, link), s); in stream_free_packet_lists()
870 list_for_each_safe(lh, next, &s->free_packet_lists) in stream_free_packet_lists()
871 packet_list_free(list_entry(lh, struct packet_list, link), s); in stream_free_packet_lists()
872 if (s->packet_pool != NULL) in stream_free_packet_lists()
873 pci_pool_destroy(s->packet_pool); in stream_free_packet_lists()
875 s->current_packet_list = NULL; in stream_free_packet_lists()
876 INIT_LIST_HEAD(&s->free_packet_lists); in stream_free_packet_lists()
877 INIT_LIST_HEAD(&s->dma_packet_lists); in stream_free_packet_lists()
878 s->packet_pool = NULL; in stream_free_packet_lists()
883 struct stream *s = data; in plug_update() local
887 s->iso_channel = plug->channel; in plug_update()
891 pl = list_entry(s->dma_packet_lists.next, struct packet_list, link); in plug_update()
892 stream_start_dma(s, pl); in plug_update()
895 ohci1394_stop_it_ctx(s->host->ohci, s->iso_tasklet.context, 0); in plug_update()
899 static int stream_configure(struct stream *s, int cmd, struct amdtp_ioctl *cfg) in stream_configure() argument
904 s->format = cfg->format; in stream_configure()
910 s->syt_interval = 8; in stream_configure()
911 s->fdf = FDF_SFC_32KHZ; in stream_configure()
912 s->iec958_rate_code = 0x0c; in stream_configure()
915 s->syt_interval = 8; in stream_configure()
916 s->fdf = FDF_SFC_44K1HZ; in stream_configure()
917 s->iec958_rate_code = 0x00; in stream_configure()
920 s->syt_interval = 8; in stream_configure()
921 s->fdf = FDF_SFC_48KHZ; in stream_configure()
922 s->iec958_rate_code = 0x04; in stream_configure()
925 s->syt_interval = 16; in stream_configure()
926 s->fdf = FDF_SFC_88K2HZ; in stream_configure()
927 s->iec958_rate_code = 0x00; in stream_configure()
930 s->syt_interval = 16; in stream_configure()
931 s->fdf = FDF_SFC_96KHZ; in stream_configure()
932 s->iec958_rate_code = 0x00; in stream_configure()
935 s->syt_interval = 32; in stream_configure()
936 s->fdf = FDF_SFC_176K4HZ; in stream_configure()
937 s->iec958_rate_code = 0x00; in stream_configure()
940 s->syt_interval = 32; in stream_configure()
941 s->fdf = FDF_SFC_192KHZ; in stream_configure()
942 s->iec958_rate_code = 0x00; in stream_configure()
949 s->rate = cfg->rate; in stream_configure()
950 fraction_init(&s->samples_per_cycle, s->rate, 8000); in stream_configure()
951 fraction_init(&s->ready_samples, 0, 8000); in stream_configure()
958 fraction_init(&s->ticks_per_syt_offset, in stream_configure()
959 24576000 * s->syt_interval, s->rate); in stream_configure()
960 fraction_init(&s->cycle_offset, (transfer_delay % 3072) * s->rate, s->rate); in stream_configure()
961 atomic_set(&s->cycle_count, transfer_delay / 3072); in stream_configure()
962 atomic_set(&s->cycle_count2, 0); in stream_configure()
964 s->mode = cfg->mode; in stream_configure()
965 s->sample_format = AMDTP_INPUT_LE16; in stream_configure()
971 if (s->format == AMDTP_FORMAT_RAW || cfg->dimension == 2) in stream_configure()
972 s->dimension = cfg->dimension; in stream_configure()
976 if (s->opcr != NULL) { in stream_configure()
977 cmp_unregister_opcr(s->host->host, s->opcr); in stream_configure()
978 s->opcr = NULL; in stream_configure()
983 s->opcr = cmp_register_opcr(s->host->host, cfg->u.plug, in stream_configure()
984 /*payload*/ 12, plug_update, s); in stream_configure()
985 if (s->opcr == NULL) in stream_configure()
987 s->iso_channel = s->opcr->channel; in stream_configure()
992 s->iso_channel = cfg->u.channel; in stream_configure()
1001 if (s->packet_pool != NULL) in stream_configure()
1002 stream_free_packet_lists(s); in stream_configure()
1004 if (stream_alloc_packet_lists(s) < 0) { in stream_configure()
1005 stream_free_packet_lists(s); in stream_configure()
1014 struct stream *s; in stream_alloc() local
1017 s = kmalloc(sizeof(struct stream), SLAB_KERNEL); in stream_alloc()
1018 if (s == NULL) in stream_alloc()
1021 memset(s, 0, sizeof(struct stream)); in stream_alloc()
1022 s->host = host; in stream_alloc()
1024 s->input = buffer_alloc(BUFFER_SIZE); in stream_alloc()
1025 if (s->input == NULL) { in stream_alloc()
1026 kfree(s); in stream_alloc()
1030 s->descriptor_pool = pci_pool_create("descriptor pool", host->ohci->dev, in stream_alloc()
1034 if (s->descriptor_pool == NULL) { in stream_alloc()
1035 kfree(s->input); in stream_alloc()
1036 kfree(s); in stream_alloc()
1040 INIT_LIST_HEAD(&s->free_packet_lists); in stream_alloc()
1041 INIT_LIST_HEAD(&s->dma_packet_lists); in stream_alloc()
1043 init_waitqueue_head(&s->packet_list_wait); in stream_alloc()
1044 spin_lock_init(&s->packet_list_lock); in stream_alloc()
1046 ohci1394_init_iso_tasklet(&s->iso_tasklet, OHCI_ISO_TRANSMIT, in stream_alloc()
1048 (unsigned long) s); in stream_alloc()
1050 if (ohci1394_register_iso_tasklet(host->ohci, &s->iso_tasklet) < 0) { in stream_alloc()
1051 pci_pool_destroy(s->descriptor_pool); in stream_alloc()
1052 kfree(s->input); in stream_alloc()
1053 kfree(s); in stream_alloc()
1058 list_add_tail(&s->link, &host->stream_list); in stream_alloc()
1061 return s; in stream_alloc()
1064 void stream_free(struct stream *s) in stream_free() argument
1074 wait_event_interruptible(s->packet_list_wait, in stream_free()
1075 list_empty(&s->dma_packet_lists)); in stream_free()
1077 ohci1394_stop_it_ctx(s->host->ohci, s->iso_tasklet.context, 1); in stream_free()
1078 ohci1394_unregister_iso_tasklet(s->host->ohci, &s->iso_tasklet); in stream_free()
1080 if (s->opcr != NULL) in stream_free()
1081 cmp_unregister_opcr(s->host->host, s->opcr); in stream_free()
1083 spin_lock_irqsave(&s->host->stream_list_lock, flags); in stream_free()
1084 list_del(&s->link); in stream_free()
1085 spin_unlock_irqrestore(&s->host->stream_list_lock, flags); in stream_free()
1087 kfree(s->input); in stream_free()
1089 stream_free_packet_lists(s); in stream_free()
1090 pci_pool_destroy(s->descriptor_pool); in stream_free()
1092 kfree(s); in stream_free()
1100 struct stream *s = file->private_data; in amdtp_write() local
1105 if (s->packet_pool == NULL) in amdtp_write()
1120 p = buffer_put_bytes(s->input, count - i, &length); in amdtp_write()
1123 if (s->input->length < s->input->size) in amdtp_write()
1126 stream_flush(s); in amdtp_write()
1128 if (s->current_packet_list != NULL) in amdtp_write()
1134 if (wait_event_interruptible(s->packet_list_wait, in amdtp_write()
1135 !list_empty(&s->free_packet_lists))) in amdtp_write()
1145 struct stream *s = file->private_data; in amdtp_ioctl() local
1155 return stream_configure(s, cmd, &cfg); in amdtp_ioctl()
1164 struct stream *s = file->private_data; in amdtp_poll() local
1166 poll_wait(file, &s->packet_list_wait, pt); in amdtp_poll()
1168 if (!list_empty(&s->free_packet_lists)) in amdtp_poll()
1192 struct stream *s = file->private_data; in amdtp_release() local
1194 stream_free(s); in amdtp_release()