Lines Matching refs:s

90 int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,  in amdtp_stream_init()  argument
99 s->protocol = kzalloc(protocol_size, GFP_KERNEL); in amdtp_stream_init()
100 if (!s->protocol) in amdtp_stream_init()
103 s->unit = unit; in amdtp_stream_init()
104 s->direction = dir; in amdtp_stream_init()
105 s->flags = flags; in amdtp_stream_init()
106 s->context = ERR_PTR(-1); in amdtp_stream_init()
107 mutex_init(&s->mutex); in amdtp_stream_init()
108 s->packet_index = 0; in amdtp_stream_init()
110 init_waitqueue_head(&s->ready_wait); in amdtp_stream_init()
112 s->fmt = fmt; in amdtp_stream_init()
113 s->process_ctx_payloads = process_ctx_payloads; in amdtp_stream_init()
123 void amdtp_stream_destroy(struct amdtp_stream *s) in amdtp_stream_destroy() argument
126 if (s->protocol == NULL) in amdtp_stream_destroy()
129 WARN_ON(amdtp_stream_running(s)); in amdtp_stream_destroy()
130 kfree(s->protocol); in amdtp_stream_destroy()
131 mutex_destroy(&s->mutex); in amdtp_stream_destroy()
160 struct snd_interval *s = hw_param_interval(params, rule->var); in apply_constraint_to_size() local
172 t.min = roundup(s->min, step); in apply_constraint_to_size()
173 t.max = rounddown(s->max, step); in apply_constraint_to_size()
176 return snd_interval_refine(s, &t); in apply_constraint_to_size()
184 int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s, in amdtp_stream_add_pcm_hw_constraints() argument
217 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_add_pcm_hw_constraints()
243 if (!(s->flags & CIP_BLOCKING)) in amdtp_stream_add_pcm_hw_constraints()
278 int amdtp_stream_set_parameters(struct amdtp_stream *s, unsigned int rate, in amdtp_stream_set_parameters() argument
290 s->sfc = sfc; in amdtp_stream_set_parameters()
291 s->data_block_quadlets = data_block_quadlets; in amdtp_stream_set_parameters()
292 s->syt_interval = amdtp_syt_intervals[sfc]; in amdtp_stream_set_parameters()
295 s->transfer_delay = TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE; in amdtp_stream_set_parameters()
298 if (s->flags & CIP_BLOCKING) in amdtp_stream_set_parameters()
299 s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate; in amdtp_stream_set_parameters()
306 static int amdtp_stream_get_max_ctx_payload_size(struct amdtp_stream *s) in amdtp_stream_get_max_ctx_payload_size() argument
310 if (s->flags & CIP_JUMBO_PAYLOAD) in amdtp_stream_get_max_ctx_payload_size()
315 return s->syt_interval * s->data_block_quadlets * sizeof(__be32) * multiplier; in amdtp_stream_get_max_ctx_payload_size()
325 unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s) in amdtp_stream_get_max_payload() argument
329 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_get_max_payload()
334 return cip_header_size + amdtp_stream_get_max_ctx_payload_size(s); in amdtp_stream_get_max_payload()
344 void amdtp_stream_pcm_prepare(struct amdtp_stream *s) in amdtp_stream_pcm_prepare() argument
346 s->pcm_buffer_pointer = 0; in amdtp_stream_pcm_prepare()
347 s->pcm_period_pointer = 0; in amdtp_stream_pcm_prepare()
351 static void pool_blocking_data_blocks(struct amdtp_stream *s, struct seq_desc *descs, in pool_blocking_data_blocks() argument
355 const unsigned int syt_interval = s->syt_interval; in pool_blocking_data_blocks()
370 static void pool_ideal_nonblocking_data_blocks(struct amdtp_stream *s, struct seq_desc *descs, in pool_ideal_nonblocking_data_blocks() argument
374 const enum cip_sfc sfc = s->sfc; in pool_ideal_nonblocking_data_blocks()
375 unsigned int state = s->ctx_data.rx.data_block_state; in pool_ideal_nonblocking_data_blocks()
409 s->ctx_data.rx.data_block_state = state; in pool_ideal_nonblocking_data_blocks()
451 static void pool_ideal_syt_offsets(struct amdtp_stream *s, struct seq_desc *descs, in pool_ideal_syt_offsets() argument
455 const enum cip_sfc sfc = s->sfc; in pool_ideal_syt_offsets()
456 unsigned int last = s->ctx_data.rx.last_syt_offset; in pool_ideal_syt_offsets()
457 unsigned int state = s->ctx_data.rx.syt_offset_state; in pool_ideal_syt_offsets()
468 s->ctx_data.rx.last_syt_offset = last; in pool_ideal_syt_offsets()
469 s->ctx_data.rx.syt_offset_state = state; in pool_ideal_syt_offsets()
497 static unsigned int calculate_cached_cycle_count(struct amdtp_stream *s, unsigned int head) in calculate_cached_cycle_count() argument
499 const unsigned int cache_size = s->ctx_data.tx.cache.size; in calculate_cached_cycle_count()
500 unsigned int cycles = s->ctx_data.tx.cache.tail; in calculate_cached_cycle_count()
509 static void cache_seq(struct amdtp_stream *s, const struct pkt_desc *descs, unsigned int desc_count) in cache_seq() argument
511 const unsigned int transfer_delay = s->transfer_delay; in cache_seq()
512 const unsigned int cache_size = s->ctx_data.tx.cache.size; in cache_seq()
513 struct seq_desc *cache = s->ctx_data.tx.cache.descs; in cache_seq()
514 unsigned int cache_tail = s->ctx_data.tx.cache.tail; in cache_seq()
515 bool aware_syt = !(s->flags & CIP_UNAWARE_SYT); in cache_seq()
531 s->ctx_data.tx.cache.tail = cache_tail; in cache_seq()
534 static void pool_ideal_seq_descs(struct amdtp_stream *s, unsigned int count) in pool_ideal_seq_descs() argument
536 struct seq_desc *descs = s->ctx_data.rx.seq.descs; in pool_ideal_seq_descs()
537 unsigned int seq_tail = s->ctx_data.rx.seq.tail; in pool_ideal_seq_descs()
538 const unsigned int seq_size = s->ctx_data.rx.seq.size; in pool_ideal_seq_descs()
540 pool_ideal_syt_offsets(s, descs, seq_size, seq_tail, count); in pool_ideal_seq_descs()
542 if (s->flags & CIP_BLOCKING) in pool_ideal_seq_descs()
543 pool_blocking_data_blocks(s, descs, seq_size, seq_tail, count); in pool_ideal_seq_descs()
545 pool_ideal_nonblocking_data_blocks(s, descs, seq_size, seq_tail, count); in pool_ideal_seq_descs()
547 s->ctx_data.rx.seq.tail = (seq_tail + count) % seq_size; in pool_ideal_seq_descs()
550 static void pool_replayed_seq(struct amdtp_stream *s, unsigned int count) in pool_replayed_seq() argument
552 struct amdtp_stream *target = s->ctx_data.rx.replay_target; in pool_replayed_seq()
555 unsigned int cache_head = s->ctx_data.rx.cache_head; in pool_replayed_seq()
556 struct seq_desc *descs = s->ctx_data.rx.seq.descs; in pool_replayed_seq()
557 const unsigned int seq_size = s->ctx_data.rx.seq.size; in pool_replayed_seq()
558 unsigned int seq_tail = s->ctx_data.rx.seq.tail; in pool_replayed_seq()
567 s->ctx_data.rx.seq.tail = seq_tail; in pool_replayed_seq()
568 s->ctx_data.rx.cache_head = cache_head; in pool_replayed_seq()
571 static void pool_seq_descs(struct amdtp_stream *s, unsigned int count) in pool_seq_descs() argument
573 struct amdtp_domain *d = s->domain; in pool_seq_descs()
575 if (!d->replay.enable || !s->ctx_data.rx.replay_target) { in pool_seq_descs()
576 pool_ideal_seq_descs(s, count); in pool_seq_descs()
579 pool_replayed_seq(s, count); in pool_seq_descs()
581 struct amdtp_stream *tx = s->ctx_data.rx.replay_target; in pool_seq_descs()
583 const unsigned int cache_head = s->ctx_data.rx.cache_head; in pool_seq_descs()
587 pool_replayed_seq(s, count); in pool_seq_descs()
589 pool_ideal_seq_descs(s, count); in pool_seq_descs()
594 static void update_pcm_pointers(struct amdtp_stream *s, in update_pcm_pointers() argument
600 ptr = s->pcm_buffer_pointer + frames; in update_pcm_pointers()
603 WRITE_ONCE(s->pcm_buffer_pointer, ptr); in update_pcm_pointers()
605 s->pcm_period_pointer += frames; in update_pcm_pointers()
606 if (s->pcm_period_pointer >= pcm->runtime->period_size) { in update_pcm_pointers()
607 s->pcm_period_pointer -= pcm->runtime->period_size; in update_pcm_pointers()
625 static int queue_packet(struct amdtp_stream *s, struct fw_iso_packet *params, in queue_packet() argument
631 params->tag = s->tag; in queue_packet()
634 err = fw_iso_context_queue(s->context, params, &s->buffer.iso_buffer, in queue_packet()
635 s->buffer.packets[s->packet_index].offset); in queue_packet()
637 dev_err(&s->unit->device, "queueing error: %d\n", err); in queue_packet()
641 if (++s->packet_index >= s->queue_size) in queue_packet()
642 s->packet_index = 0; in queue_packet()
647 static inline int queue_out_packet(struct amdtp_stream *s, in queue_out_packet() argument
652 return queue_packet(s, params, sched_irq); in queue_out_packet()
655 static inline int queue_in_packet(struct amdtp_stream *s, in queue_in_packet() argument
659 params->header_length = s->ctx_data.tx.ctx_header_size; in queue_in_packet()
660 params->payload_length = s->ctx_data.tx.max_ctx_payload_length; in queue_in_packet()
662 return queue_packet(s, params, false); in queue_in_packet()
665 static void generate_cip_header(struct amdtp_stream *s, __be32 cip_header[2], in generate_cip_header() argument
668 cip_header[0] = cpu_to_be32(READ_ONCE(s->source_node_id_field) | in generate_cip_header()
669 (s->data_block_quadlets << CIP_DBS_SHIFT) | in generate_cip_header()
670 ((s->sph << CIP_SPH_SHIFT) & CIP_SPH_MASK) | in generate_cip_header()
673 ((s->fmt << CIP_FMT_SHIFT) & CIP_FMT_MASK) | in generate_cip_header()
674 ((s->ctx_data.rx.fdf << CIP_FDF_SHIFT) & CIP_FDF_MASK) | in generate_cip_header()
678 static void build_it_pkt_header(struct amdtp_stream *s, unsigned int cycle, in build_it_pkt_header() argument
687 payload_length = data_blocks * sizeof(__be32) * s->data_block_quadlets; in build_it_pkt_header()
692 generate_cip_header(s, cip_header, data_block_counter, syt); in build_it_pkt_header()
698 trace_amdtp_packet(s, cycle, cip_header, payload_length + header_length, data_blocks, in build_it_pkt_header()
699 data_block_counter, s->packet_index, index); in build_it_pkt_header()
702 static int check_cip_header(struct amdtp_stream *s, const __be32 *buf, in check_cip_header() argument
723 (!(s->flags & CIP_HEADER_WITHOUT_EOH))) { in check_cip_header()
724 dev_info_ratelimited(&s->unit->device, in check_cip_header()
733 if (sph != s->sph || fmt != s->fmt) { in check_cip_header()
734 dev_info_ratelimited(&s->unit->device, in check_cip_header()
749 dev_err(&s->unit->device, in check_cip_header()
754 if (s->flags & CIP_WRONG_DBS) in check_cip_header()
755 data_block_quadlets = s->data_block_quadlets; in check_cip_header()
762 if (*data_blocks == 0 && (s->flags & CIP_EMPTY_HAS_WRONG_DBC) && in check_cip_header()
766 if ((dbc == 0x00 && (s->flags & CIP_SKIP_DBC_ZERO_CHECK)) || in check_cip_header()
769 } else if (!(s->flags & CIP_DBC_IS_END_EVENT)) { in check_cip_header()
774 if (*data_blocks > 0 && s->ctx_data.tx.dbc_interval > 0) in check_cip_header()
775 dbc_interval = s->ctx_data.tx.dbc_interval; in check_cip_header()
783 dev_err(&s->unit->device, in check_cip_header()
791 if (!(s->flags & CIP_UNAWARE_SYT)) in check_cip_header()
797 static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, in parse_ir_ctx_header() argument
809 if (!(s->flags & CIP_NO_HEADER)) in parse_ir_ctx_header()
814 if (payload_length > cip_header_size + s->ctx_data.tx.max_ctx_payload_length) { in parse_ir_ctx_header()
815 dev_err(&s->unit->device, in parse_ir_ctx_header()
817 payload_length, cip_header_size + s->ctx_data.tx.max_ctx_payload_length); in parse_ir_ctx_header()
826 err = check_cip_header(s, cip_header, payload_length - cip_header_size, in parse_ir_ctx_header()
838 *data_blocks = payload_length / sizeof(__be32) / s->data_block_quadlets; in parse_ir_ctx_header()
845 trace_amdtp_packet(s, cycle, cip_header, payload_length, *data_blocks, in parse_ir_ctx_header()
889 static int generate_device_pkt_descs(struct amdtp_stream *s, in generate_device_pkt_descs() argument
895 unsigned int next_cycle = s->next_cycle; in generate_device_pkt_descs()
896 unsigned int dbc = s->data_block_counter; in generate_device_pkt_descs()
897 unsigned int packet_index = s->packet_index; in generate_device_pkt_descs()
898 unsigned int queue_size = s->queue_size; in generate_device_pkt_descs()
913 if (s->flags & CIP_NO_HEADER) { in generate_device_pkt_descs()
931 } else if (s->flags & CIP_JUMBO_PAYLOAD) { in generate_device_pkt_descs()
940 dev_err(&s->unit->device, "Detect discontinuity of cycle: %d %d\n", in generate_device_pkt_descs()
946 err = parse_ir_ctx_header(s, cycle, ctx_header, &data_blocks, &dbc, &syt, in generate_device_pkt_descs()
955 desc->ctx_payload = s->buffer.packets[packet_index].buffer; in generate_device_pkt_descs()
957 if (!(s->flags & CIP_DBC_IS_END_EVENT)) in generate_device_pkt_descs()
962 ctx_header += s->ctx_data.tx.ctx_header_size / sizeof(*ctx_header); in generate_device_pkt_descs()
966 s->next_cycle = next_cycle; in generate_device_pkt_descs()
967 s->data_block_counter = dbc; in generate_device_pkt_descs()
983 static void generate_pkt_descs(struct amdtp_stream *s, const __be32 *ctx_header, unsigned int packe… in generate_pkt_descs() argument
985 struct pkt_desc *descs = s->pkt_descs; in generate_pkt_descs()
986 const struct seq_desc *seq_descs = s->ctx_data.rx.seq.descs; in generate_pkt_descs()
987 const unsigned int seq_size = s->ctx_data.rx.seq.size; in generate_pkt_descs()
988 unsigned int dbc = s->data_block_counter; in generate_pkt_descs()
989 unsigned int seq_head = s->ctx_data.rx.seq.head; in generate_pkt_descs()
990 bool aware_syt = !(s->flags & CIP_UNAWARE_SYT); in generate_pkt_descs()
995 unsigned int index = (s->packet_index + i) % s->queue_size; in generate_pkt_descs()
998 desc->cycle = compute_ohci_it_cycle(*ctx_header, s->queue_size); in generate_pkt_descs()
1001 desc->syt = compute_syt(seq->syt_offset, desc->cycle, s->transfer_delay); in generate_pkt_descs()
1007 if (s->flags & CIP_DBC_IS_END_EVENT) in generate_pkt_descs()
1012 if (!(s->flags & CIP_DBC_IS_END_EVENT)) in generate_pkt_descs()
1015 desc->ctx_payload = s->buffer.packets[index].buffer; in generate_pkt_descs()
1022 s->data_block_counter = dbc; in generate_pkt_descs()
1023 s->ctx_data.rx.seq.head = seq_head; in generate_pkt_descs()
1026 static inline void cancel_stream(struct amdtp_stream *s) in cancel_stream() argument
1028 s->packet_index = -1; in cancel_stream()
1030 amdtp_stream_pcm_abort(s); in cancel_stream()
1031 WRITE_ONCE(s->pcm_buffer_pointer, SNDRV_PCM_POS_XRUN); in cancel_stream()
1034 static void process_ctx_payloads(struct amdtp_stream *s, in process_ctx_payloads() argument
1041 pcm = READ_ONCE(s->pcm); in process_ctx_payloads()
1042 pcm_frames = s->process_ctx_payloads(s, descs, packets, pcm); in process_ctx_payloads()
1044 update_pcm_pointers(s, pcm, pcm_frames); in process_ctx_payloads()
1050 struct amdtp_stream *s = private_data; in process_rx_packets() local
1051 const struct amdtp_domain *d = s->domain; in process_rx_packets()
1054 unsigned int event_count = s->ctx_data.rx.event_count; in process_rx_packets()
1060 if (s->packet_index < 0) in process_rx_packets()
1066 pool_seq_descs(s, packets); in process_rx_packets()
1068 generate_pkt_descs(s, ctx_header, packets); in process_rx_packets()
1070 process_ctx_payloads(s, s->pkt_descs, packets); in process_rx_packets()
1072 if (!(s->flags & CIP_NO_HEADER)) in process_rx_packets()
1077 if (s == d->irq_target) { in process_rx_packets()
1081 struct snd_pcm_substream *pcm = READ_ONCE(s->pcm); in process_rx_packets()
1088 const struct pkt_desc *desc = s->pkt_descs + i; in process_rx_packets()
1095 build_it_pkt_header(s, desc->cycle, &template.params, pkt_header_length, in process_rx_packets()
1099 if (s == s->domain->irq_target) { in process_rx_packets()
1107 if (queue_out_packet(s, &template.params, sched_irq) < 0) { in process_rx_packets()
1108 cancel_stream(s); in process_rx_packets()
1113 s->ctx_data.rx.event_count = event_count; in process_rx_packets()
1119 struct amdtp_stream *s = private_data; in skip_rx_packets() local
1120 struct amdtp_domain *d = s->domain; in skip_rx_packets()
1126 if (s->packet_index < 0) in skip_rx_packets()
1131 cycle = compute_ohci_it_cycle(ctx_header[packets - 1], s->queue_size); in skip_rx_packets()
1132 s->next_cycle = increment_ohci_cycle_count(cycle, 1); in skip_rx_packets()
1139 bool sched_irq = (s == d->irq_target && i == packets - 1); in skip_rx_packets()
1141 if (queue_out_packet(s, &params, sched_irq) < 0) { in skip_rx_packets()
1142 cancel_stream(s); in skip_rx_packets()
1154 struct amdtp_stream *s = private_data; in process_rx_packets_intermediately() local
1155 struct amdtp_domain *d = s->domain; in process_rx_packets_intermediately()
1157 const unsigned int queue_size = s->queue_size; in process_rx_packets_intermediately()
1161 if (s->packet_index < 0) in process_rx_packets_intermediately()
1180 if (amdtp_streaming_error(s)) in process_rx_packets_intermediately()
1188 s->ready_processing = true; in process_rx_packets_intermediately()
1189 wake_up(&s->ready_wait); in process_rx_packets_intermediately()
1192 if (amdtp_streaming_error(s)) in process_rx_packets_intermediately()
1195 if (s == d->irq_target) in process_rx_packets_intermediately()
1196 s->context->callback.sc = irq_target_callback; in process_rx_packets_intermediately()
1198 s->context->callback.sc = process_rx_packets; in process_rx_packets_intermediately()
1205 struct amdtp_stream *s = private_data; in process_tx_packets() local
1212 if (s->packet_index < 0) in process_tx_packets()
1216 packets = header_length / s->ctx_data.tx.ctx_header_size; in process_tx_packets()
1219 err = generate_device_pkt_descs(s, s->pkt_descs, ctx_header, packets, &desc_count); in process_tx_packets()
1222 cancel_stream(s); in process_tx_packets()
1226 struct amdtp_domain *d = s->domain; in process_tx_packets()
1228 process_ctx_payloads(s, s->pkt_descs, desc_count); in process_tx_packets()
1231 cache_seq(s, s->pkt_descs, desc_count); in process_tx_packets()
1237 if (queue_in_packet(s, &params) < 0) { in process_tx_packets()
1238 cancel_stream(s); in process_tx_packets()
1247 struct amdtp_stream *s = private_data; in drop_tx_packets() local
1253 if (s->packet_index < 0) in drop_tx_packets()
1256 packets = header_length / s->ctx_data.tx.ctx_header_size; in drop_tx_packets()
1258 ctx_header += (packets - 1) * s->ctx_data.tx.ctx_header_size / sizeof(*ctx_header); in drop_tx_packets()
1260 s->next_cycle = increment_ohci_cycle_count(cycle, 1); in drop_tx_packets()
1265 if (queue_in_packet(s, &params) < 0) { in drop_tx_packets()
1266 cancel_stream(s); in drop_tx_packets()
1275 struct amdtp_stream *s = private_data; in process_tx_packets_intermediately() local
1276 struct amdtp_domain *d = s->domain; in process_tx_packets_intermediately()
1281 if (s->packet_index < 0) in process_tx_packets_intermediately()
1284 packets = header_length / s->ctx_data.tx.ctx_header_size; in process_tx_packets_intermediately()
1294 ctx_header += s->ctx_data.tx.ctx_header_size / sizeof(__be32); in process_tx_packets_intermediately()
1301 size_t length = s->ctx_data.tx.ctx_header_size * offset; in process_tx_packets_intermediately()
1303 drop_tx_packets(context, tstamp, length, ctx_header, s); in process_tx_packets_intermediately()
1304 if (amdtp_streaming_error(s)) in process_tx_packets_intermediately()
1312 s->ready_processing = true; in process_tx_packets_intermediately()
1313 wake_up(&s->ready_wait); in process_tx_packets_intermediately()
1315 process_tx_packets(context, tstamp, header_length, ctx_header, s); in process_tx_packets_intermediately()
1316 if (amdtp_streaming_error(s)) in process_tx_packets_intermediately()
1326 struct amdtp_stream *s = private_data; in drop_tx_packets_initially() local
1327 struct amdtp_domain *d = s->domain; in drop_tx_packets_initially()
1333 if (s->packet_index < 0) in drop_tx_packets_initially()
1336 count = header_length / s->ctx_data.tx.ctx_header_size; in drop_tx_packets_initially()
1346 if (s->flags & CIP_NO_HEADER) { in drop_tx_packets_initially()
1347 data_blocks = payload_quads / s->data_block_quadlets; in drop_tx_packets_initially()
1356 if (s->flags & CIP_UNAWARE_SYT) { in drop_tx_packets_initially()
1357 data_blocks = payload_quads / s->data_block_quadlets; in drop_tx_packets_initially()
1366 data_blocks = payload_quads / s->data_block_quadlets; in drop_tx_packets_initially()
1373 ctx_header += s->ctx_data.tx.ctx_header_size / sizeof(__be32); in drop_tx_packets_initially()
1376 drop_tx_packets(context, tstamp, header_length, header, s); in drop_tx_packets_initially()
1379 s->ctx_data.tx.event_starts = true; in drop_tx_packets_initially()
1387 list_for_each_entry(s, &d->streams, list) { in drop_tx_packets_initially()
1388 if (s->direction == AMDTP_IN_STREAM) { in drop_tx_packets_initially()
1390 if (s->ctx_data.tx.event_starts) in drop_tx_packets_initially()
1398 list_for_each_entry(s, &d->streams, list) { in drop_tx_packets_initially()
1399 if (s->direction != AMDTP_IN_STREAM) in drop_tx_packets_initially()
1402 next_cycle = increment_ohci_cycle_count(s->next_cycle, in drop_tx_packets_initially()
1408 s->context->callback.sc = process_tx_packets_intermediately; in drop_tx_packets_initially()
1418 struct amdtp_stream *s; in process_ctxs_in_domain() local
1420 list_for_each_entry(s, &d->streams, list) { in process_ctxs_in_domain()
1421 if (s != d->irq_target && amdtp_stream_running(s)) in process_ctxs_in_domain()
1422 fw_iso_context_flush_completions(s->context); in process_ctxs_in_domain()
1424 if (amdtp_streaming_error(s)) in process_ctxs_in_domain()
1433 list_for_each_entry(s, &d->streams, list) { in process_ctxs_in_domain()
1434 if (amdtp_stream_running(s)) in process_ctxs_in_domain()
1435 cancel_stream(s); in process_ctxs_in_domain()
1442 struct amdtp_stream *s = private_data; in irq_target_callback() local
1443 struct amdtp_domain *d = s->domain; in irq_target_callback()
1452 struct amdtp_stream *s = private_data; in irq_target_callback_intermediately() local
1453 struct amdtp_domain *d = s->domain; in irq_target_callback_intermediately()
1462 struct amdtp_stream *s = private_data; in irq_target_callback_skip() local
1463 struct amdtp_domain *d = s->domain; in irq_target_callback_skip()
1496 unsigned int cycle = s->next_cycle; in irq_target_callback_skip()
1497 list_for_each_entry(s, &d->streams, list) { in irq_target_callback_skip()
1498 if (s->direction != AMDTP_OUT_STREAM) in irq_target_callback_skip()
1501 if (compare_ohci_cycle_count(s->next_cycle, cycle) > 0) in irq_target_callback_skip()
1502 cycle = s->next_cycle; in irq_target_callback_skip()
1504 if (s == d->irq_target) in irq_target_callback_skip()
1505 s->context->callback.sc = irq_target_callback_intermediately; in irq_target_callback_skip()
1507 s->context->callback.sc = process_rx_packets_intermediately; in irq_target_callback_skip()
1520 struct amdtp_stream *s = private_data; in amdtp_stream_first_callback() local
1521 struct amdtp_domain *d = s->domain; in amdtp_stream_first_callback()
1523 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_first_callback()
1526 if (s == d->irq_target) in amdtp_stream_first_callback()
1532 context->callback.sc(context, tstamp, header_length, header, s); in amdtp_stream_first_callback()
1547 static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed, in amdtp_stream_start() argument
1550 bool is_irq_target = (s == s->domain->irq_target); in amdtp_stream_start()
1556 mutex_lock(&s->mutex); in amdtp_stream_start()
1558 if (WARN_ON(amdtp_stream_running(s) || in amdtp_stream_start()
1559 (s->data_block_quadlets < 1))) { in amdtp_stream_start()
1564 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1571 s->data_block_counter = UINT_MAX; in amdtp_stream_start()
1573 s->data_block_counter = 0; in amdtp_stream_start()
1577 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1580 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_start()
1589 max_ctx_payload_size = amdtp_stream_get_max_ctx_payload_size(s); in amdtp_stream_start()
1591 err = iso_packets_buffer_init(&s->buffer, s->unit, queue_size, max_ctx_payload_size, dir); in amdtp_stream_start()
1594 s->queue_size = queue_size; in amdtp_stream_start()
1596 s->context = fw_iso_context_create(fw_parent_device(s->unit)->card, in amdtp_stream_start()
1598 amdtp_stream_first_callback, s); in amdtp_stream_start()
1599 if (IS_ERR(s->context)) { in amdtp_stream_start()
1600 err = PTR_ERR(s->context); in amdtp_stream_start()
1602 dev_err(&s->unit->device, in amdtp_stream_start()
1607 amdtp_stream_update(s); in amdtp_stream_start()
1609 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1610 s->ctx_data.tx.max_ctx_payload_length = max_ctx_payload_size; in amdtp_stream_start()
1611 s->ctx_data.tx.ctx_header_size = ctx_header_size; in amdtp_stream_start()
1612 s->ctx_data.tx.event_starts = false; in amdtp_stream_start()
1614 if (s->domain->replay.enable) { in amdtp_stream_start()
1617 s->ctx_data.tx.cache.size = max_t(unsigned int, s->syt_interval * 2, in amdtp_stream_start()
1619 s->ctx_data.tx.cache.tail = 0; in amdtp_stream_start()
1620 s->ctx_data.tx.cache.descs = kcalloc(s->ctx_data.tx.cache.size, in amdtp_stream_start()
1621 sizeof(*s->ctx_data.tx.cache.descs), GFP_KERNEL); in amdtp_stream_start()
1622 if (!s->ctx_data.tx.cache.descs) { in amdtp_stream_start()
1641 s->ctx_data.rx.seq.descs = kcalloc(queue_size, sizeof(*s->ctx_data.rx.seq.descs), GFP_KERNEL); in amdtp_stream_start()
1642 if (!s->ctx_data.rx.seq.descs) { in amdtp_stream_start()
1646 s->ctx_data.rx.seq.size = queue_size; in amdtp_stream_start()
1647 s->ctx_data.rx.seq.tail = 0; in amdtp_stream_start()
1648 s->ctx_data.rx.seq.head = 0; in amdtp_stream_start()
1650 entry = &initial_state[s->sfc]; in amdtp_stream_start()
1651 s->ctx_data.rx.data_block_state = entry->data_block; in amdtp_stream_start()
1652 s->ctx_data.rx.syt_offset_state = entry->syt_offset; in amdtp_stream_start()
1653 s->ctx_data.rx.last_syt_offset = TICKS_PER_CYCLE; in amdtp_stream_start()
1655 s->ctx_data.rx.event_count = 0; in amdtp_stream_start()
1658 if (s->flags & CIP_NO_HEADER) in amdtp_stream_start()
1659 s->tag = TAG_NO_CIP_HEADER; in amdtp_stream_start()
1661 s->tag = TAG_CIP; in amdtp_stream_start()
1663 s->pkt_descs = kcalloc(s->queue_size, sizeof(*s->pkt_descs), in amdtp_stream_start()
1665 if (!s->pkt_descs) { in amdtp_stream_start()
1670 s->packet_index = 0; in amdtp_stream_start()
1674 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1675 err = queue_in_packet(s, &params); in amdtp_stream_start()
1683 sched_irq = !((s->packet_index + 1) % in amdtp_stream_start()
1687 err = queue_out_packet(s, &params, sched_irq); in amdtp_stream_start()
1691 } while (s->packet_index > 0); in amdtp_stream_start()
1695 if ((s->flags & CIP_EMPTY_WITH_TAG0) || (s->flags & CIP_NO_HEADER)) in amdtp_stream_start()
1698 s->ready_processing = false; in amdtp_stream_start()
1699 err = fw_iso_context_start(s->context, -1, 0, tag); in amdtp_stream_start()
1703 mutex_unlock(&s->mutex); in amdtp_stream_start()
1707 kfree(s->pkt_descs); in amdtp_stream_start()
1709 if (s->direction == AMDTP_OUT_STREAM) { in amdtp_stream_start()
1710 kfree(s->ctx_data.rx.seq.descs); in amdtp_stream_start()
1712 if (s->domain->replay.enable) in amdtp_stream_start()
1713 kfree(s->ctx_data.tx.cache.descs); in amdtp_stream_start()
1715 fw_iso_context_destroy(s->context); in amdtp_stream_start()
1716 s->context = ERR_PTR(-1); in amdtp_stream_start()
1718 iso_packets_buffer_destroy(&s->buffer, s->unit); in amdtp_stream_start()
1720 mutex_unlock(&s->mutex); in amdtp_stream_start()
1733 struct amdtp_stream *s) in amdtp_domain_stream_pcm_pointer() argument
1745 return READ_ONCE(s->pcm_buffer_pointer); in amdtp_domain_stream_pcm_pointer()
1756 int amdtp_domain_stream_pcm_ack(struct amdtp_domain *d, struct amdtp_stream *s) in amdtp_domain_stream_pcm_ack() argument
1773 void amdtp_stream_update(struct amdtp_stream *s) in amdtp_stream_update() argument
1776 WRITE_ONCE(s->source_node_id_field, in amdtp_stream_update()
1777 (fw_parent_device(s->unit)->card->node_id << CIP_SID_SHIFT) & CIP_SID_MASK); in amdtp_stream_update()
1788 static void amdtp_stream_stop(struct amdtp_stream *s) in amdtp_stream_stop() argument
1790 mutex_lock(&s->mutex); in amdtp_stream_stop()
1792 if (!amdtp_stream_running(s)) { in amdtp_stream_stop()
1793 mutex_unlock(&s->mutex); in amdtp_stream_stop()
1797 fw_iso_context_stop(s->context); in amdtp_stream_stop()
1798 fw_iso_context_destroy(s->context); in amdtp_stream_stop()
1799 s->context = ERR_PTR(-1); in amdtp_stream_stop()
1800 iso_packets_buffer_destroy(&s->buffer, s->unit); in amdtp_stream_stop()
1801 kfree(s->pkt_descs); in amdtp_stream_stop()
1803 if (s->direction == AMDTP_OUT_STREAM) { in amdtp_stream_stop()
1804 kfree(s->ctx_data.rx.seq.descs); in amdtp_stream_stop()
1806 if (s->domain->replay.enable) in amdtp_stream_stop()
1807 kfree(s->ctx_data.tx.cache.descs); in amdtp_stream_stop()
1810 mutex_unlock(&s->mutex); in amdtp_stream_stop()
1820 void amdtp_stream_pcm_abort(struct amdtp_stream *s) in amdtp_stream_pcm_abort() argument
1824 pcm = READ_ONCE(s->pcm); in amdtp_stream_pcm_abort()
1862 int amdtp_domain_add_stream(struct amdtp_domain *d, struct amdtp_stream *s, in amdtp_domain_add_stream() argument
1868 if (s == tmp) in amdtp_domain_add_stream()
1872 list_add(&s->list, &d->streams); in amdtp_domain_add_stream()
1874 s->channel = channel; in amdtp_domain_add_stream()
1875 s->speed = speed; in amdtp_domain_add_stream()
1876 s->domain = d; in amdtp_domain_add_stream()
1894 struct amdtp_stream *s; in make_association() local
1896 list_for_each_entry(s, &d->streams, list) { in make_association()
1897 if (s->direction == AMDTP_IN_STREAM) { in make_association()
1899 tx = s; in make_association()
1908 list_for_each_entry(s, &d->streams, list) { in make_association()
1909 if (s->direction == AMDTP_IN_STREAM) { in make_association()
1910 tx = s; in make_association()
1945 struct amdtp_stream *s; in amdtp_domain_start() local
1958 list_for_each_entry(s, &d->streams, list) { in amdtp_domain_start()
1959 if (s->direction == AMDTP_OUT_STREAM) { in amdtp_domain_start()
1966 d->irq_target = s; in amdtp_domain_start()
1981 list_for_each_entry(s, &d->streams, list) { in amdtp_domain_start()
1984 if (s->direction == AMDTP_OUT_STREAM && s == d->irq_target) { in amdtp_domain_start()
1990 err = amdtp_stream_start(s, s->channel, s->speed, queue_size, idle_irq_interval); in amdtp_domain_start()
1997 list_for_each_entry(s, &d->streams, list) in amdtp_domain_start()
1998 amdtp_stream_stop(s); in amdtp_domain_start()
2009 struct amdtp_stream *s, *next; in amdtp_domain_stop() local
2014 list_for_each_entry_safe(s, next, &d->streams, list) { in amdtp_domain_stop()
2015 list_del(&s->list); in amdtp_domain_stop()
2017 if (s != d->irq_target) in amdtp_domain_stop()
2018 amdtp_stream_stop(s); in amdtp_domain_stop()