Lines Matching +full:double +full:- +full:phase
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Audio and Music Data Transmission Protocol (IEC 61883-6) streams
4 * with Common Isochronous Packet (IEC 61883-1) headers
12 #include <linux/firewire-constants.h>
17 #include "amdtp-stream.h"
27 #include "amdtp-stream-trace.h"
70 * amdtp_stream_init - initialize an AMDTP stream structure
86 return -EINVAL; in amdtp_stream_init()
88 s->protocol = kzalloc(protocol_size, GFP_KERNEL); in amdtp_stream_init()
89 if (!s->protocol) in amdtp_stream_init()
90 return -ENOMEM; in amdtp_stream_init()
92 s->unit = unit; in amdtp_stream_init()
93 s->direction = dir; in amdtp_stream_init()
94 s->flags = flags; in amdtp_stream_init()
95 s->context = ERR_PTR(-1); in amdtp_stream_init()
96 mutex_init(&s->mutex); in amdtp_stream_init()
97 INIT_WORK(&s->period_work, pcm_period_work); in amdtp_stream_init()
98 s->packet_index = 0; in amdtp_stream_init()
100 init_waitqueue_head(&s->callback_wait); in amdtp_stream_init()
101 s->callbacked = false; in amdtp_stream_init()
103 s->fmt = fmt; in amdtp_stream_init()
104 s->process_ctx_payloads = process_ctx_payloads; in amdtp_stream_init()
107 s->ctx_data.rx.syt_override = -1; in amdtp_stream_init()
114 * amdtp_stream_destroy - free stream resources
120 if (s->protocol == NULL) in amdtp_stream_destroy()
124 kfree(s->protocol); in amdtp_stream_destroy()
125 mutex_destroy(&s->mutex); in amdtp_stream_destroy()
154 struct snd_interval *s = hw_param_interval(params, rule->var); in apply_constraint_to_size()
166 t.min = roundup(s->min, step); in apply_constraint_to_size()
167 t.max = rounddown(s->max, step); in apply_constraint_to_size()
174 * amdtp_stream_add_pcm_hw_constraints - add hw constraints for PCM substream
181 struct snd_pcm_hardware *hw = &runtime->hw; in amdtp_stream_add_pcm_hw_constraints()
186 hw->info = SNDRV_PCM_INFO_BATCH | in amdtp_stream_add_pcm_hw_constraints()
194 hw->periods_min = 2; in amdtp_stream_add_pcm_hw_constraints()
195 hw->periods_max = UINT_MAX; in amdtp_stream_add_pcm_hw_constraints()
198 hw->period_bytes_min = 4 * hw->channels_max; in amdtp_stream_add_pcm_hw_constraints()
201 hw->period_bytes_max = hw->period_bytes_min * 2048; in amdtp_stream_add_pcm_hw_constraints()
202 hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min; in amdtp_stream_add_pcm_hw_constraints()
212 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_add_pcm_hw_constraints()
219 // In IEC 61883-6, one isoc packet can transfer events up to the value in amdtp_stream_add_pcm_hw_constraints()
223 // However, there are two ways of transmission in IEC 61883-6; blocking in amdtp_stream_add_pcm_hw_constraints()
224 // and non-blocking modes. In blocking mode, the sequence of isoc packet in amdtp_stream_add_pcm_hw_constraints()
226 // non-blocking mode, the number of events per packet is variable up to in amdtp_stream_add_pcm_hw_constraints()
229 // interrupt should be double of the value of syt interval, thus it is in amdtp_stream_add_pcm_hw_constraints()
237 /* Non-Blocking stream has no more constraints */ in amdtp_stream_add_pcm_hw_constraints()
238 if (!(s->flags & CIP_BLOCKING)) in amdtp_stream_add_pcm_hw_constraints()
250 SNDRV_PCM_HW_PARAM_RATE, -1); in amdtp_stream_add_pcm_hw_constraints()
256 SNDRV_PCM_HW_PARAM_RATE, -1); in amdtp_stream_add_pcm_hw_constraints()
265 * amdtp_stream_set_parameters - set stream parameters
283 return -EINVAL; in amdtp_stream_set_parameters()
285 s->sfc = sfc; in amdtp_stream_set_parameters()
286 s->data_block_quadlets = data_block_quadlets; in amdtp_stream_set_parameters()
287 s->syt_interval = amdtp_syt_intervals[sfc]; in amdtp_stream_set_parameters()
290 if (s->direction == AMDTP_OUT_STREAM) { in amdtp_stream_set_parameters()
291 s->ctx_data.rx.transfer_delay = in amdtp_stream_set_parameters()
292 TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE; in amdtp_stream_set_parameters()
294 if (s->flags & CIP_BLOCKING) { in amdtp_stream_set_parameters()
295 // additional buffering needed to adjust for no-data in amdtp_stream_set_parameters()
297 s->ctx_data.rx.transfer_delay += in amdtp_stream_set_parameters()
298 TICKS_PER_SECOND * s->syt_interval / rate; in amdtp_stream_set_parameters()
307 * amdtp_stream_get_max_payload - get the stream's packet size
318 if (s->flags & CIP_JUMBO_PAYLOAD) in amdtp_stream_get_max_payload()
320 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_get_max_payload()
324 s->syt_interval * s->data_block_quadlets * sizeof(__be32) * multiplier; in amdtp_stream_get_max_payload()
329 * amdtp_stream_pcm_prepare - prepare PCM device for running
336 cancel_work_sync(&s->period_work); in amdtp_stream_pcm_prepare()
337 s->pcm_buffer_pointer = 0; in amdtp_stream_pcm_prepare()
338 s->pcm_period_pointer = 0; in amdtp_stream_pcm_prepare()
355 /* Non-blocking mode. */ in calculate_data_blocks()
361 unsigned int phase = *data_block_state; in calculate_data_blocks() local
367 * 2) packets with a rounded-up number of blocks occur as early in calculate_data_blocks()
373 data_blocks = 5 + ((phase & 1) ^ in calculate_data_blocks()
374 (phase == 0 || phase >= 40)); in calculate_data_blocks()
377 data_blocks = 11 * (sfc >> 1) + (phase == 0); in calculate_data_blocks()
378 if (++phase >= (80 >> (sfc >> 1))) in calculate_data_blocks()
379 phase = 0; in calculate_data_blocks()
380 *data_block_state = phase; in calculate_data_blocks()
406 unsigned int phase = *syt_offset_state; in calculate_syt_offset() local
407 unsigned int index = phase % 13; in calculate_syt_offset()
411 phase == 146); in calculate_syt_offset()
412 if (++phase >= 147) in calculate_syt_offset()
413 phase = 0; in calculate_syt_offset()
414 *syt_offset_state = phase; in calculate_syt_offset()
417 syt_offset = *last_syt_offset - TICKS_PER_CYCLE; in calculate_syt_offset()
432 ptr = s->pcm_buffer_pointer + frames; in update_pcm_pointers()
433 if (ptr >= pcm->runtime->buffer_size) in update_pcm_pointers()
434 ptr -= pcm->runtime->buffer_size; in update_pcm_pointers()
435 WRITE_ONCE(s->pcm_buffer_pointer, ptr); in update_pcm_pointers()
437 s->pcm_period_pointer += frames; in update_pcm_pointers()
438 if (s->pcm_period_pointer >= pcm->runtime->period_size) { in update_pcm_pointers()
439 s->pcm_period_pointer -= pcm->runtime->period_size; in update_pcm_pointers()
440 queue_work(system_highpri_wq, &s->period_work); in update_pcm_pointers()
448 struct snd_pcm_substream *pcm = READ_ONCE(s->pcm); in pcm_period_work()
459 params->interrupt = sched_irq; in queue_packet()
460 params->tag = s->tag; in queue_packet()
461 params->sy = 0; in queue_packet()
463 err = fw_iso_context_queue(s->context, params, &s->buffer.iso_buffer, in queue_packet()
464 s->buffer.packets[s->packet_index].offset); in queue_packet()
466 dev_err(&s->unit->device, "queueing error: %d\n", err); in queue_packet()
470 if (++s->packet_index >= s->queue_size) in queue_packet()
471 s->packet_index = 0; in queue_packet()
479 params->skip = in queue_out_packet()
480 !!(params->header_length == 0 && params->payload_length == 0); in queue_out_packet()
488 params->header_length = s->ctx_data.tx.ctx_header_size; in queue_in_packet()
489 params->payload_length = s->ctx_data.tx.max_ctx_payload_length; in queue_in_packet()
490 params->skip = false; in queue_in_packet()
497 cip_header[0] = cpu_to_be32(READ_ONCE(s->source_node_id_field) | in generate_cip_header()
498 (s->data_block_quadlets << CIP_DBS_SHIFT) | in generate_cip_header()
499 ((s->sph << CIP_SPH_SHIFT) & CIP_SPH_MASK) | in generate_cip_header()
502 ((s->fmt << CIP_FMT_SHIFT) & CIP_FMT_MASK) | in generate_cip_header()
503 ((s->ctx_data.rx.fdf << CIP_FDF_SHIFT) & CIP_FDF_MASK) | in generate_cip_header()
516 payload_length = data_blocks * sizeof(__be32) * s->data_block_quadlets; in build_it_pkt_header()
517 params->payload_length = payload_length; in build_it_pkt_header()
519 if (!(s->flags & CIP_NO_HEADER)) { in build_it_pkt_header()
520 cip_header = (__be32 *)params->header; in build_it_pkt_header()
522 params->header_length = 2 * sizeof(__be32); in build_it_pkt_header()
523 payload_length += params->header_length; in build_it_pkt_header()
529 data_block_counter, s->packet_index, index); in build_it_pkt_header()
548 * This module supports 'Two-quadlet CIP header with SYT field'. in check_cip_header()
553 (!(s->flags & CIP_HEADER_WITHOUT_EOH))) { in check_cip_header()
554 dev_info_ratelimited(&s->unit->device, in check_cip_header()
557 return -EAGAIN; in check_cip_header()
563 if (sph != s->sph || fmt != s->fmt) { in check_cip_header()
564 dev_info_ratelimited(&s->unit->device, in check_cip_header()
567 return -EAGAIN; in check_cip_header()
580 dev_err(&s->unit->device, in check_cip_header()
583 return -EPROTO; in check_cip_header()
585 if (s->flags & CIP_WRONG_DBS) in check_cip_header()
586 data_block_quadlets = s->data_block_quadlets; in check_cip_header()
588 *data_blocks = (payload_length / sizeof(__be32) - 2) / in check_cip_header()
594 if (*data_blocks == 0 && (s->flags & CIP_EMPTY_HAS_WRONG_DBC) && in check_cip_header()
598 if ((dbc == 0x00 && (s->flags & CIP_SKIP_DBC_ZERO_CHECK)) || in check_cip_header()
601 } else if (!(s->flags & CIP_DBC_IS_END_EVENT)) { in check_cip_header()
606 if (*data_blocks > 0 && s->ctx_data.tx.dbc_interval > 0) in check_cip_header()
607 dbc_interval = s->ctx_data.tx.dbc_interval; in check_cip_header()
615 dev_err(&s->unit->device, in check_cip_header()
618 return -EIO; in check_cip_header()
641 if (!(s->flags & CIP_NO_HEADER)) in parse_ir_ctx_header()
646 if (*payload_length > cip_header_size + s->ctx_data.tx.max_ctx_payload_length) { in parse_ir_ctx_header()
647 dev_err(&s->unit->device, in parse_ir_ctx_header()
649 *payload_length, cip_header_size + s->ctx_data.tx.max_ctx_payload_length); in parse_ir_ctx_header()
650 return -EIO; in parse_ir_ctx_header()
663 s->data_block_quadlets; in parse_ir_ctx_header()
689 cycle -= OHCI_MAX_SECOND * CYCLES_PER_SECOND; in increment_cycle_count()
709 unsigned int dbc = s->data_block_counter; in generate_device_pkt_descs()
710 unsigned int packet_index = s->packet_index; in generate_device_pkt_descs()
711 unsigned int queue_size = s->queue_size; in generate_device_pkt_descs()
729 desc->cycle = cycle; in generate_device_pkt_descs()
730 desc->syt = syt; in generate_device_pkt_descs()
731 desc->data_blocks = data_blocks; in generate_device_pkt_descs()
732 desc->data_block_counter = dbc; in generate_device_pkt_descs()
733 desc->ctx_payload = s->buffer.packets[packet_index].buffer; in generate_device_pkt_descs()
735 if (!(s->flags & CIP_DBC_IS_END_EVENT)) in generate_device_pkt_descs()
736 dbc = (dbc + desc->data_blocks) & 0xff; in generate_device_pkt_descs()
739 s->ctx_data.tx.ctx_header_size / sizeof(*ctx_header); in generate_device_pkt_descs()
744 s->data_block_counter = dbc; in generate_device_pkt_descs()
765 unsigned int dbc = s->data_block_counter; in generate_pkt_descs()
766 unsigned int seq_index = s->ctx_data.rx.seq_index; in generate_pkt_descs()
771 unsigned int index = (s->packet_index + i) % s->queue_size; in generate_pkt_descs()
775 desc->cycle = compute_it_cycle(*ctx_header, s->queue_size); in generate_pkt_descs()
777 syt = seq->syt_offset; in generate_pkt_descs()
779 syt = compute_syt(syt, desc->cycle, in generate_pkt_descs()
780 s->ctx_data.rx.transfer_delay); in generate_pkt_descs()
782 desc->syt = syt; in generate_pkt_descs()
783 desc->data_blocks = seq->data_blocks; in generate_pkt_descs()
785 if (s->flags & CIP_DBC_IS_END_EVENT) in generate_pkt_descs()
786 dbc = (dbc + desc->data_blocks) & 0xff; in generate_pkt_descs()
788 desc->data_block_counter = dbc; in generate_pkt_descs()
790 if (!(s->flags & CIP_DBC_IS_END_EVENT)) in generate_pkt_descs()
791 dbc = (dbc + desc->data_blocks) & 0xff; in generate_pkt_descs()
793 desc->ctx_payload = s->buffer.packets[index].buffer; in generate_pkt_descs()
800 s->data_block_counter = dbc; in generate_pkt_descs()
801 s->ctx_data.rx.seq_index = seq_index; in generate_pkt_descs()
806 s->packet_index = -1; in cancel_stream()
809 WRITE_ONCE(s->pcm_buffer_pointer, SNDRV_PCM_POS_XRUN); in cancel_stream()
819 pcm = READ_ONCE(s->pcm); in process_ctx_payloads()
820 pcm_frames = s->process_ctx_payloads(s, descs, packets, pcm); in process_ctx_payloads()
830 const struct amdtp_domain *d = s->domain; in out_stream_callback()
832 unsigned int events_per_period = s->ctx_data.rx.events_per_period; in out_stream_callback()
833 unsigned int event_count = s->ctx_data.rx.event_count; in out_stream_callback()
837 if (s->packet_index < 0) in out_stream_callback()
843 generate_pkt_descs(s, s->pkt_descs, ctx_header, packets, d->seq_descs, in out_stream_callback()
844 d->seq_size); in out_stream_callback()
846 process_ctx_payloads(s, s->pkt_descs, packets); in out_stream_callback()
849 const struct pkt_desc *desc = s->pkt_descs + i; in out_stream_callback()
857 if (s->ctx_data.rx.syt_override < 0) in out_stream_callback()
858 syt = desc->syt; in out_stream_callback()
860 syt = s->ctx_data.rx.syt_override; in out_stream_callback()
862 build_it_pkt_header(s, desc->cycle, &template.params, in out_stream_callback()
863 desc->data_blocks, desc->data_block_counter, in out_stream_callback()
866 if (s == s->domain->irq_target) { in out_stream_callback()
867 event_count += desc->data_blocks; in out_stream_callback()
869 event_count -= events_per_period; in out_stream_callback()
880 s->ctx_data.rx.event_count = event_count; in out_stream_callback()
893 if (s->packet_index < 0) in in_stream_callback()
897 packets = header_length / s->ctx_data.tx.ctx_header_size; in in_stream_callback()
899 err = generate_device_pkt_descs(s, s->pkt_descs, ctx_header, packets); in in_stream_callback()
901 if (err != -EAGAIN) { in in_stream_callback()
906 process_ctx_payloads(s, s->pkt_descs, packets); in in_stream_callback()
921 struct amdtp_stream *irq_target = d->irq_target; in pool_ideal_seq_descs()
922 unsigned int seq_tail = d->seq_tail; in pool_ideal_seq_descs()
923 unsigned int seq_size = d->seq_size; in pool_ideal_seq_descs()
927 min_avail = d->seq_size; in pool_ideal_seq_descs()
928 list_for_each_entry(s, &d->streams, list) { in pool_ideal_seq_descs()
932 if (s->direction == AMDTP_IN_STREAM) in pool_ideal_seq_descs()
935 seq_index = s->ctx_data.rx.seq_index; in pool_ideal_seq_descs()
936 avail = d->seq_tail; in pool_ideal_seq_descs()
938 avail += d->seq_size; in pool_ideal_seq_descs()
939 avail -= seq_index; in pool_ideal_seq_descs()
946 struct seq_desc *desc = d->seq_descs + seq_tail; in pool_ideal_seq_descs()
948 desc->syt_offset = calculate_syt_offset(&d->last_syt_offset, in pool_ideal_seq_descs()
949 &d->syt_offset_state, irq_target->sfc); in pool_ideal_seq_descs()
950 desc->data_blocks = calculate_data_blocks(&d->data_block_state, in pool_ideal_seq_descs()
951 !!(irq_target->flags & CIP_BLOCKING), in pool_ideal_seq_descs()
952 desc->syt_offset == CIP_SYT_NO_INFO, in pool_ideal_seq_descs()
953 irq_target->syt_interval, irq_target->sfc); in pool_ideal_seq_descs()
961 d->seq_tail = seq_tail; in pool_ideal_seq_descs()
969 struct amdtp_domain *d = irq_target->domain; in irq_target_callback()
980 list_for_each_entry(s, &d->streams, list) { in irq_target_callback()
982 fw_iso_context_flush_completions(s->context); in irq_target_callback()
993 list_for_each_entry(s, &d->streams, list) { in irq_target_callback()
1009 * For in-stream, first packet has come. in amdtp_stream_first_callback()
1010 * For out-stream, prepared to transmit first packet in amdtp_stream_first_callback()
1012 s->callbacked = true; in amdtp_stream_first_callback()
1013 wake_up(&s->callback_wait); in amdtp_stream_first_callback()
1015 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_first_callback()
1018 context->callback.sc = in_stream_callback; in amdtp_stream_first_callback()
1020 cycle = compute_it_cycle(*ctx_header, s->queue_size); in amdtp_stream_first_callback()
1022 if (s == s->domain->irq_target) in amdtp_stream_first_callback()
1023 context->callback.sc = irq_target_callback; in amdtp_stream_first_callback()
1025 context->callback.sc = out_stream_callback; in amdtp_stream_first_callback()
1028 s->start_cycle = cycle; in amdtp_stream_first_callback()
1030 context->callback.sc(context, tstamp, header_length, header, s); in amdtp_stream_first_callback()
1034 * amdtp_stream_start - start transferring packets
1051 bool is_irq_target = (s == s->domain->irq_target); in amdtp_stream_start()
1057 mutex_lock(&s->mutex); in amdtp_stream_start()
1060 (s->data_block_quadlets < 1))) { in amdtp_stream_start()
1061 err = -EBADFD; in amdtp_stream_start()
1065 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1068 err = -EINVAL; in amdtp_stream_start()
1072 s->data_block_counter = UINT_MAX; in amdtp_stream_start()
1074 s->data_block_counter = 0; in amdtp_stream_start()
1079 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1082 if (!(s->flags & CIP_NO_HEADER)) { in amdtp_stream_start()
1083 max_ctx_payload_size -= 8; in amdtp_stream_start()
1093 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_start()
1094 max_ctx_payload_size -= IT_PKT_HEADER_SIZE_CIP; in amdtp_stream_start()
1097 err = iso_packets_buffer_init(&s->buffer, s->unit, queue_size, in amdtp_stream_start()
1101 s->queue_size = queue_size; in amdtp_stream_start()
1103 s->context = fw_iso_context_create(fw_parent_device(s->unit)->card, in amdtp_stream_start()
1106 if (IS_ERR(s->context)) { in amdtp_stream_start()
1107 err = PTR_ERR(s->context); in amdtp_stream_start()
1108 if (err == -EBUSY) in amdtp_stream_start()
1109 dev_err(&s->unit->device, in amdtp_stream_start()
1116 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1117 s->ctx_data.tx.max_ctx_payload_length = max_ctx_payload_size; in amdtp_stream_start()
1118 s->ctx_data.tx.ctx_header_size = ctx_header_size; in amdtp_stream_start()
1121 if (s->flags & CIP_NO_HEADER) in amdtp_stream_start()
1122 s->tag = TAG_NO_CIP_HEADER; in amdtp_stream_start()
1124 s->tag = TAG_CIP; in amdtp_stream_start()
1126 s->pkt_descs = kcalloc(s->queue_size, sizeof(*s->pkt_descs), in amdtp_stream_start()
1128 if (!s->pkt_descs) { in amdtp_stream_start()
1129 err = -ENOMEM; in amdtp_stream_start()
1133 s->packet_index = 0; in amdtp_stream_start()
1137 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1146 sched_irq = !((s->packet_index + 1) % in amdtp_stream_start()
1154 } while (s->packet_index > 0); in amdtp_stream_start()
1158 if ((s->flags & CIP_EMPTY_WITH_TAG0) || (s->flags & CIP_NO_HEADER)) in amdtp_stream_start()
1161 s->callbacked = false; in amdtp_stream_start()
1162 err = fw_iso_context_start(s->context, start_cycle, 0, tag); in amdtp_stream_start()
1166 mutex_unlock(&s->mutex); in amdtp_stream_start()
1170 kfree(s->pkt_descs); in amdtp_stream_start()
1172 fw_iso_context_destroy(s->context); in amdtp_stream_start()
1173 s->context = ERR_PTR(-1); in amdtp_stream_start()
1175 iso_packets_buffer_destroy(&s->buffer, s->unit); in amdtp_stream_start()
1177 mutex_unlock(&s->mutex); in amdtp_stream_start()
1183 * amdtp_domain_stream_pcm_pointer - get the PCM buffer position
1192 struct amdtp_stream *irq_target = d->irq_target; in amdtp_domain_stream_pcm_pointer()
1209 if (current_work() != &s->period_work) { in amdtp_domain_stream_pcm_pointer()
1213 fw_iso_context_flush_completions(irq_target->context); in amdtp_domain_stream_pcm_pointer()
1218 return READ_ONCE(s->pcm_buffer_pointer); in amdtp_domain_stream_pcm_pointer()
1223 * amdtp_domain_stream_pcm_ack - acknowledge queued PCM frames
1231 struct amdtp_stream *irq_target = d->irq_target; in amdtp_domain_stream_pcm_ack()
1239 fw_iso_context_flush_completions(irq_target->context); in amdtp_domain_stream_pcm_ack()
1248 * amdtp_stream_update - update the stream after a bus reset
1254 WRITE_ONCE(s->source_node_id_field, in amdtp_stream_update()
1255 (fw_parent_device(s->unit)->card->node_id << CIP_SID_SHIFT) & CIP_SID_MASK); in amdtp_stream_update()
1260 * amdtp_stream_stop - stop sending packets
1268 mutex_lock(&s->mutex); in amdtp_stream_stop()
1271 mutex_unlock(&s->mutex); in amdtp_stream_stop()
1275 cancel_work_sync(&s->period_work); in amdtp_stream_stop()
1276 fw_iso_context_stop(s->context); in amdtp_stream_stop()
1277 fw_iso_context_destroy(s->context); in amdtp_stream_stop()
1278 s->context = ERR_PTR(-1); in amdtp_stream_stop()
1279 iso_packets_buffer_destroy(&s->buffer, s->unit); in amdtp_stream_stop()
1280 kfree(s->pkt_descs); in amdtp_stream_stop()
1282 s->callbacked = false; in amdtp_stream_stop()
1284 mutex_unlock(&s->mutex); in amdtp_stream_stop()
1288 * amdtp_stream_pcm_abort - abort the running PCM device
1298 pcm = READ_ONCE(s->pcm); in amdtp_stream_pcm_abort()
1305 * amdtp_domain_init - initialize an AMDTP domain structure
1310 INIT_LIST_HEAD(&d->streams); in amdtp_domain_init()
1312 d->events_per_period = 0; in amdtp_domain_init()
1314 d->seq_descs = NULL; in amdtp_domain_init()
1321 * amdtp_domain_destroy - destroy an AMDTP domain structure
1332 * amdtp_domain_add_stream - register isoc context into the domain.
1343 list_for_each_entry(tmp, &d->streams, list) { in amdtp_domain_add_stream()
1345 return -EBUSY; in amdtp_domain_add_stream()
1348 list_add(&s->list, &d->streams); in amdtp_domain_add_stream()
1350 s->channel = channel; in amdtp_domain_add_stream()
1351 s->speed = speed; in amdtp_domain_add_stream()
1352 s->domain = d; in amdtp_domain_add_stream()
1367 generation = fw_card->generation; in get_current_cycle_time()
1370 fw_card->node_id, generation, SCODE_100, in get_current_cycle_time()
1374 return -EIO; in get_current_cycle_time()
1383 * amdtp_domain_start - start sending packets for isoc context in the domain.
1401 unsigned int events_per_buffer = d->events_per_buffer; in amdtp_domain_start()
1402 unsigned int events_per_period = d->events_per_period; in amdtp_domain_start()
1411 list_for_each_entry(s, &d->streams, list) { in amdtp_domain_start()
1412 if (s->direction == AMDTP_OUT_STREAM) { in amdtp_domain_start()
1418 return -ENXIO; in amdtp_domain_start()
1419 d->irq_target = s; in amdtp_domain_start()
1425 events_per_period = amdtp_rate_table[d->irq_target->sfc] / 100; in amdtp_domain_start()
1430 amdtp_rate_table[d->irq_target->sfc]); in amdtp_domain_start()
1432 d->seq_descs = kcalloc(queue_size, sizeof(*d->seq_descs), GFP_KERNEL); in amdtp_domain_start()
1433 if (!d->seq_descs) in amdtp_domain_start()
1434 return -ENOMEM; in amdtp_domain_start()
1435 d->seq_size = queue_size; in amdtp_domain_start()
1436 d->seq_tail = 0; in amdtp_domain_start()
1438 entry = &initial_state[s->sfc]; in amdtp_domain_start()
1439 d->data_block_state = entry->data_block; in amdtp_domain_start()
1440 d->syt_offset_state = entry->syt_offset; in amdtp_domain_start()
1441 d->last_syt_offset = TICKS_PER_CYCLE; in amdtp_domain_start()
1444 struct fw_card *fw_card = fw_parent_device(s->unit)->card; in amdtp_domain_start()
1468 cycle = -1; in amdtp_domain_start()
1471 list_for_each_entry(s, &d->streams, list) { in amdtp_domain_start()
1474 if (s->direction == AMDTP_IN_STREAM) { in amdtp_domain_start()
1478 cycle_match = -1; in amdtp_domain_start()
1479 s->ctx_data.rx.seq_index = 0; in amdtp_domain_start()
1482 if (s != d->irq_target) { in amdtp_domain_start()
1483 err = amdtp_stream_start(s, s->channel, s->speed, in amdtp_domain_start()
1490 s = d->irq_target; in amdtp_domain_start()
1491 s->ctx_data.rx.events_per_period = events_per_period; in amdtp_domain_start()
1492 s->ctx_data.rx.event_count = 0; in amdtp_domain_start()
1493 s->ctx_data.rx.seq_index = 0; in amdtp_domain_start()
1496 amdtp_rate_table[d->irq_target->sfc]); in amdtp_domain_start()
1497 err = amdtp_stream_start(s, s->channel, s->speed, -1, queue_size, in amdtp_domain_start()
1504 list_for_each_entry(s, &d->streams, list) in amdtp_domain_start()
1506 kfree(d->seq_descs); in amdtp_domain_start()
1507 d->seq_descs = NULL; in amdtp_domain_start()
1513 * amdtp_domain_stop - stop sending packets for isoc context in the same domain.
1520 if (d->irq_target) in amdtp_domain_stop()
1521 amdtp_stream_stop(d->irq_target); in amdtp_domain_stop()
1523 list_for_each_entry_safe(s, next, &d->streams, list) { in amdtp_domain_stop()
1524 list_del(&s->list); in amdtp_domain_stop()
1526 if (s != d->irq_target) in amdtp_domain_stop()
1530 d->events_per_period = 0; in amdtp_domain_stop()
1531 d->irq_target = NULL; in amdtp_domain_stop()
1533 kfree(d->seq_descs); in amdtp_domain_stop()
1534 d->seq_descs = NULL; in amdtp_domain_stop()