Lines Matching full:s

84  * @s: the AMDTP stream to initialize
92 int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit, in amdtp_stream_init() argument
101 s->protocol = kzalloc(protocol_size, GFP_KERNEL); in amdtp_stream_init()
102 if (!s->protocol) in amdtp_stream_init()
105 s->unit = unit; in amdtp_stream_init()
106 s->direction = dir; in amdtp_stream_init()
107 s->flags = flags; in amdtp_stream_init()
108 s->context = ERR_PTR(-1); in amdtp_stream_init()
109 mutex_init(&s->mutex); in amdtp_stream_init()
110 INIT_WORK(&s->period_work, pcm_period_work); in amdtp_stream_init()
111 s->packet_index = 0; in amdtp_stream_init()
113 init_waitqueue_head(&s->ready_wait); in amdtp_stream_init()
115 s->fmt = fmt; in amdtp_stream_init()
116 s->process_ctx_payloads = process_ctx_payloads; in amdtp_stream_init()
124 * @s: the AMDTP stream to destroy
126 void amdtp_stream_destroy(struct amdtp_stream *s) in amdtp_stream_destroy() argument
129 if (s->protocol == NULL) in amdtp_stream_destroy()
132 WARN_ON(amdtp_stream_running(s)); in amdtp_stream_destroy()
133 kfree(s->protocol); in amdtp_stream_destroy()
134 mutex_destroy(&s->mutex); in amdtp_stream_destroy()
163 struct snd_interval *s = hw_param_interval(params, rule->var); in apply_constraint_to_size() local
178 t.min = roundup(s->min, step); in apply_constraint_to_size()
179 t.max = rounddown(s->max, step); in apply_constraint_to_size()
182 return snd_interval_refine(s, &t); in apply_constraint_to_size()
187 * @s: the AMDTP stream, which must be initialized.
190 int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s, in amdtp_stream_add_pcm_hw_constraints() argument
223 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_add_pcm_hw_constraints()
249 if (!(s->flags & CIP_BLOCKING)) in amdtp_stream_add_pcm_hw_constraints()
255 * depending on its sampling rate. For accurate period interrupt, it's in amdtp_stream_add_pcm_hw_constraints()
277 * @s: the AMDTP stream to configure
286 int amdtp_stream_set_parameters(struct amdtp_stream *s, unsigned int rate, in amdtp_stream_set_parameters() argument
298 s->sfc = sfc; in amdtp_stream_set_parameters()
299 s->data_block_quadlets = data_block_quadlets; in amdtp_stream_set_parameters()
300 s->syt_interval = amdtp_syt_intervals[sfc]; in amdtp_stream_set_parameters()
303 s->transfer_delay = TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE; in amdtp_stream_set_parameters()
306 if (s->flags & CIP_BLOCKING) in amdtp_stream_set_parameters()
307 s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate; in amdtp_stream_set_parameters()
309 s->pcm_frame_multiplier = pcm_frame_multiplier; in amdtp_stream_set_parameters()
316 static int amdtp_stream_get_max_ctx_payload_size(struct amdtp_stream *s) in amdtp_stream_get_max_ctx_payload_size() argument
320 if (s->flags & CIP_JUMBO_PAYLOAD) in amdtp_stream_get_max_ctx_payload_size()
325 return s->syt_interval * s->data_block_quadlets * sizeof(__be32) * multiplier; in amdtp_stream_get_max_ctx_payload_size()
329 * amdtp_stream_get_max_payload - get the stream's packet size
330 * @s: the AMDTP stream
335 unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s) in amdtp_stream_get_max_payload() argument
339 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_get_max_payload()
344 return cip_header_size + amdtp_stream_get_max_ctx_payload_size(s); in amdtp_stream_get_max_payload()
350 * @s: the AMDTP stream
352 * This function should be called from the PCM device's .prepare callback.
354 void amdtp_stream_pcm_prepare(struct amdtp_stream *s) in amdtp_stream_pcm_prepare() argument
356 cancel_work_sync(&s->period_work); in amdtp_stream_pcm_prepare()
357 s->pcm_buffer_pointer = 0; in amdtp_stream_pcm_prepare()
358 s->pcm_period_pointer = 0; in amdtp_stream_pcm_prepare()
362 #define prev_packet_desc(s, desc) \ argument
363 list_prev_entry_circular(desc, &s->packet_descs_list, link)
365 static void pool_blocking_data_blocks(struct amdtp_stream *s, struct seq_desc *descs, in pool_blocking_data_blocks() argument
368 const unsigned int syt_interval = s->syt_interval; in pool_blocking_data_blocks()
383 static void pool_ideal_nonblocking_data_blocks(struct amdtp_stream *s, struct seq_desc *descs, in pool_ideal_nonblocking_data_blocks() argument
387 const enum cip_sfc sfc = s->sfc; in pool_ideal_nonblocking_data_blocks()
388 unsigned int state = s->ctx_data.rx.data_block_state; in pool_ideal_nonblocking_data_blocks()
406 * device's buffer). in pool_ideal_nonblocking_data_blocks()
422 s->ctx_data.rx.data_block_state = state; in pool_ideal_nonblocking_data_blocks()
464 static void pool_ideal_syt_offsets(struct amdtp_stream *s, struct seq_desc *descs, in pool_ideal_syt_offsets() argument
467 const enum cip_sfc sfc = s->sfc; in pool_ideal_syt_offsets()
468 unsigned int last = s->ctx_data.rx.last_syt_offset; in pool_ideal_syt_offsets()
469 unsigned int state = s->ctx_data.rx.syt_offset_state; in pool_ideal_syt_offsets()
480 s->ctx_data.rx.last_syt_offset = last; in pool_ideal_syt_offsets()
481 s->ctx_data.rx.syt_offset_state = state; in pool_ideal_syt_offsets()
509 static unsigned int calculate_cached_cycle_count(struct amdtp_stream *s, unsigned int head) in calculate_cached_cycle_count() argument
511 const unsigned int cache_size = s->ctx_data.tx.cache.size; in calculate_cached_cycle_count()
512 unsigned int cycles = s->ctx_data.tx.cache.pos; in calculate_cached_cycle_count()
521 static void cache_seq(struct amdtp_stream *s, const struct pkt_desc *src, unsigned int desc_count) in cache_seq() argument
523 const unsigned int transfer_delay = s->transfer_delay; in cache_seq()
524 const unsigned int cache_size = s->ctx_data.tx.cache.size; in cache_seq()
525 struct seq_desc *cache = s->ctx_data.tx.cache.descs; in cache_seq()
526 unsigned int cache_pos = s->ctx_data.tx.cache.pos; in cache_seq()
527 bool aware_syt = !(s->flags & CIP_UNAWARE_SYT); in cache_seq()
540 src = amdtp_stream_next_packet_desc(s, src); in cache_seq()
543 s->ctx_data.tx.cache.pos = cache_pos; in cache_seq()
546 static void pool_ideal_seq_descs(struct amdtp_stream *s, struct seq_desc *descs, unsigned int size, in pool_ideal_seq_descs() argument
549 pool_ideal_syt_offsets(s, descs, size, pos, count); in pool_ideal_seq_descs()
551 if (s->flags & CIP_BLOCKING) in pool_ideal_seq_descs()
552 pool_blocking_data_blocks(s, descs, size, pos, count); in pool_ideal_seq_descs()
554 pool_ideal_nonblocking_data_blocks(s, descs, size, pos, count); in pool_ideal_seq_descs()
557 static void pool_replayed_seq(struct amdtp_stream *s, struct seq_desc *descs, unsigned int size, in pool_replayed_seq() argument
560 struct amdtp_stream *target = s->ctx_data.rx.replay_target; in pool_replayed_seq()
563 unsigned int cache_pos = s->ctx_data.rx.cache_pos; in pool_replayed_seq()
572 s->ctx_data.rx.cache_pos = cache_pos; in pool_replayed_seq()
575 static void pool_seq_descs(struct amdtp_stream *s, struct seq_desc *descs, unsigned int size, in pool_seq_descs() argument
578 struct amdtp_domain *d = s->domain; in pool_seq_descs()
579 void (*pool_seq_descs)(struct amdtp_stream *s, struct seq_desc *descs, unsigned int size, in pool_seq_descs()
582 if (!d->replay.enable || !s->ctx_data.rx.replay_target) { in pool_seq_descs()
588 struct amdtp_stream *tx = s->ctx_data.rx.replay_target; in pool_seq_descs()
590 const unsigned int cache_pos = s->ctx_data.rx.cache_pos; in pool_seq_descs()
600 pool_seq_descs(s, descs, size, pos, count); in pool_seq_descs()
603 static void update_pcm_pointers(struct amdtp_stream *s, in update_pcm_pointers() argument
609 ptr = s->pcm_buffer_pointer + frames; in update_pcm_pointers()
612 WRITE_ONCE(s->pcm_buffer_pointer, ptr); in update_pcm_pointers()
614 s->pcm_period_pointer += frames; in update_pcm_pointers()
615 if (s->pcm_period_pointer >= pcm->runtime->period_size) { in update_pcm_pointers()
616 s->pcm_period_pointer -= pcm->runtime->period_size; in update_pcm_pointers()
638 queue_work(system_highpri_wq, &s->period_work); in update_pcm_pointers()
644 struct amdtp_stream *s = container_of(work, struct amdtp_stream, in pcm_period_work() local
646 struct snd_pcm_substream *pcm = READ_ONCE(s->pcm); in pcm_period_work()
652 static int queue_packet(struct amdtp_stream *s, struct fw_iso_packet *params, in queue_packet() argument
658 params->tag = s->tag; in queue_packet()
661 err = fw_iso_context_queue(s->context, params, &s->buffer.iso_buffer, in queue_packet()
662 s->buffer.packets[s->packet_index].offset); in queue_packet()
664 dev_err(&s->unit->device, "queueing error: %d\n", err); in queue_packet()
668 if (++s->packet_index >= s->queue_size) in queue_packet()
669 s->packet_index = 0; in queue_packet()
674 static inline int queue_out_packet(struct amdtp_stream *s, in queue_out_packet() argument
679 return queue_packet(s, params, sched_irq); in queue_out_packet()
682 static inline int queue_in_packet(struct amdtp_stream *s, in queue_in_packet() argument
686 params->header_length = s->ctx_data.tx.ctx_header_size; in queue_in_packet()
687 params->payload_length = s->ctx_data.tx.max_ctx_payload_length; in queue_in_packet()
689 return queue_packet(s, params, false); in queue_in_packet()
692 static void generate_cip_header(struct amdtp_stream *s, __be32 cip_header[2], in generate_cip_header() argument
695 cip_header[0] = cpu_to_be32(READ_ONCE(s->source_node_id_field) | in generate_cip_header()
696 (s->data_block_quadlets << CIP_DBS_SHIFT) | in generate_cip_header()
697 ((s->sph << CIP_SPH_SHIFT) & CIP_SPH_MASK) | in generate_cip_header()
700 ((s->fmt << CIP_FMT_SHIFT) & CIP_FMT_MASK) | in generate_cip_header()
701 ((s->ctx_data.rx.fdf << CIP_FDF_SHIFT) & CIP_FDF_MASK) | in generate_cip_header()
705 static void build_it_pkt_header(struct amdtp_stream *s, unsigned int cycle, in build_it_pkt_header() argument
714 payload_length = data_blocks * sizeof(__be32) * s->data_block_quadlets; in build_it_pkt_header()
719 generate_cip_header(s, cip_header, data_block_counter, syt); in build_it_pkt_header()
725 trace_amdtp_packet(s, cycle, cip_header, payload_length + header_length, data_blocks, in build_it_pkt_header()
726 data_block_counter, s->packet_index, index, curr_cycle_time); in build_it_pkt_header()
729 static int check_cip_header(struct amdtp_stream *s, const __be32 *buf, in check_cip_header() argument
750 (!(s->flags & CIP_HEADER_WITHOUT_EOH))) { in check_cip_header()
751 dev_info_ratelimited(&s->unit->device, in check_cip_header()
760 if (sph != s->sph || fmt != s->fmt) { in check_cip_header()
761 dev_info_ratelimited(&s->unit->device, in check_cip_header()
776 dev_err(&s->unit->device, in check_cip_header()
781 if (s->flags & CIP_WRONG_DBS) in check_cip_header()
782 data_block_quadlets = s->data_block_quadlets; in check_cip_header()
789 if (*data_blocks == 0 && (s->flags & CIP_EMPTY_HAS_WRONG_DBC) && in check_cip_header()
793 if ((dbc == 0x00 && (s->flags & CIP_SKIP_DBC_ZERO_CHECK)) || in check_cip_header()
796 } else if (!(s->flags & CIP_DBC_IS_END_EVENT)) { in check_cip_header()
801 if (!(s->flags & CIP_DBC_IS_PAYLOAD_QUADLETS)) { in check_cip_header()
802 if (*data_blocks > 0 && s->ctx_data.tx.dbc_interval > 0) in check_cip_header()
803 dbc_interval = s->ctx_data.tx.dbc_interval; in check_cip_header()
814 dev_err(&s->unit->device, in check_cip_header()
822 if (!(s->flags & CIP_UNAWARE_SYT)) in check_cip_header()
828 static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, in parse_ir_ctx_header() argument
841 if (!(s->flags & CIP_NO_HEADER)) in parse_ir_ctx_header()
846 if (payload_length > cip_header_size + s->ctx_data.tx.max_ctx_payload_length) { in parse_ir_ctx_header()
847 dev_err(&s->unit->device, in parse_ir_ctx_header()
849 payload_length, cip_header_size + s->ctx_data.tx.max_ctx_payload_length); in parse_ir_ctx_header()
858 err = check_cip_header(s, cip_header, payload_length - cip_header_size, in parse_ir_ctx_header()
870 *data_blocks = payload_length / sizeof(__be32) / s->data_block_quadlets; in parse_ir_ctx_header()
877 trace_amdtp_packet(s, cycle, cip_header, payload_length, *data_blocks, in parse_ir_ctx_header()
925 // to kip isochronous cycle, therefore it's OK to just increment the cycle by
934 static int generate_tx_packet_descs(struct amdtp_stream *s, struct pkt_desc *desc, in generate_tx_packet_descs() argument
938 unsigned int next_cycle = s->next_cycle; in generate_tx_packet_descs()
939 unsigned int dbc = s->data_block_counter; in generate_tx_packet_descs()
940 unsigned int packet_index = s->packet_index; in generate_tx_packet_descs()
941 unsigned int queue_size = s->queue_size; in generate_tx_packet_descs()
947 (void)fw_card_read_cycle_time(fw_parent_device(s->unit)->card, &curr_cycle_time); in generate_tx_packet_descs()
959 if (s->flags & CIP_NO_HEADER) { in generate_tx_packet_descs()
974 desc = amdtp_stream_next_packet_desc(s, desc); in generate_tx_packet_descs()
977 } else if (s->flags & CIP_JUMBO_PAYLOAD) { in generate_tx_packet_descs()
986 dev_err(&s->unit->device, "Detect discontinuity of cycle: %d %d\n", in generate_tx_packet_descs()
992 err = parse_ir_ctx_header(s, cycle, ctx_header, &data_blocks, &dbc, &syt, in generate_tx_packet_descs()
1001 desc->ctx_payload = s->buffer.packets[packet_index].buffer; in generate_tx_packet_descs()
1003 if (!(s->flags & CIP_DBC_IS_END_EVENT)) in generate_tx_packet_descs()
1007 desc = amdtp_stream_next_packet_desc(s, desc); in generate_tx_packet_descs()
1009 ctx_header += s->ctx_data.tx.ctx_header_size / sizeof(*ctx_header); in generate_tx_packet_descs()
1013 s->next_cycle = next_cycle; in generate_tx_packet_descs()
1014 s->data_block_counter = dbc; in generate_tx_packet_descs()
1030 static void generate_rx_packet_descs(struct amdtp_stream *s, struct pkt_desc *desc, in generate_rx_packet_descs() argument
1033 struct seq_desc *seq_descs = s->ctx_data.rx.seq.descs; in generate_rx_packet_descs()
1034 unsigned int seq_size = s->ctx_data.rx.seq.size; in generate_rx_packet_descs()
1035 unsigned int seq_pos = s->ctx_data.rx.seq.pos; in generate_rx_packet_descs()
1036 unsigned int dbc = s->data_block_counter; in generate_rx_packet_descs()
1037 bool aware_syt = !(s->flags & CIP_UNAWARE_SYT); in generate_rx_packet_descs()
1040 pool_seq_descs(s, seq_descs, seq_size, seq_pos, packet_count); in generate_rx_packet_descs()
1043 unsigned int index = (s->packet_index + i) % s->queue_size; in generate_rx_packet_descs()
1046 desc->cycle = compute_ohci_it_cycle(*ctx_header, s->queue_size); in generate_rx_packet_descs()
1049 desc->syt = compute_syt(seq->syt_offset, desc->cycle, s->transfer_delay); in generate_rx_packet_descs()
1055 if (s->flags & CIP_DBC_IS_END_EVENT) in generate_rx_packet_descs()
1060 if (!(s->flags & CIP_DBC_IS_END_EVENT)) in generate_rx_packet_descs()
1063 desc->ctx_payload = s->buffer.packets[index].buffer; in generate_rx_packet_descs()
1066 desc = amdtp_stream_next_packet_desc(s, desc); in generate_rx_packet_descs()
1071 s->data_block_counter = dbc; in generate_rx_packet_descs()
1072 s->ctx_data.rx.seq.pos = seq_pos; in generate_rx_packet_descs()
1075 static inline void cancel_stream(struct amdtp_stream *s) in cancel_stream() argument
1079 s->packet_index = -1; in cancel_stream()
1085 if (work && work != &s->period_work) in cancel_stream()
1086 amdtp_stream_pcm_abort(s); in cancel_stream()
1087 WRITE_ONCE(s->pcm_buffer_pointer, SNDRV_PCM_POS_XRUN); in cancel_stream()
1090 static snd_pcm_sframes_t compute_pcm_extra_delay(struct amdtp_stream *s, in compute_pcm_extra_delay() argument
1105 desc = amdtp_stream_next_packet_desc(s, desc); in compute_pcm_extra_delay()
1108 err = fw_card_read_cycle_time(fw_parent_device(s->unit)->card, &cycle_time); in compute_pcm_extra_delay()
1116 if (s->direction == AMDTP_IN_STREAM) { in compute_pcm_extra_delay()
1127 desc = amdtp_stream_next_packet_desc(s, desc); in compute_pcm_extra_delay()
1140 desc = prev_packet_desc(s, desc); in compute_pcm_extra_delay()
1144 return data_block_count * s->pcm_frame_multiplier; in compute_pcm_extra_delay()
1147 static void process_ctx_payloads(struct amdtp_stream *s, in process_ctx_payloads() argument
1154 pcm = READ_ONCE(s->pcm); in process_ctx_payloads()
1155 s->process_ctx_payloads(s, desc, count, pcm); in process_ctx_payloads()
1160 pcm->runtime->delay = compute_pcm_extra_delay(s, desc, count); in process_ctx_payloads()
1164 desc = amdtp_stream_next_packet_desc(s, desc); in process_ctx_payloads()
1167 update_pcm_pointers(s, pcm, data_block_count * s->pcm_frame_multiplier); in process_ctx_payloads()
1174 struct amdtp_stream *s = private_data; in process_rx_packets() local
1175 const struct amdtp_domain *d = s->domain; in process_rx_packets()
1178 unsigned int event_count = s->ctx_data.rx.event_count; in process_rx_packets()
1179 struct pkt_desc *desc = s->packet_descs_cursor; in process_rx_packets()
1186 if (s->packet_index < 0) in process_rx_packets()
1192 generate_rx_packet_descs(s, desc, ctx_header, packets); in process_rx_packets()
1194 process_ctx_payloads(s, desc, packets); in process_rx_packets()
1196 if (!(s->flags & CIP_NO_HEADER)) in process_rx_packets()
1201 if (s == d->irq_target) { in process_rx_packets()
1205 struct snd_pcm_substream *pcm = READ_ONCE(s->pcm); in process_rx_packets()
1212 (void)fw_card_read_cycle_time(fw_parent_device(s->unit)->card, &curr_cycle_time); in process_rx_packets()
1218 build_it_pkt_header(s, desc->cycle, template, pkt_header_length, in process_rx_packets()
1222 if (s == s->domain->irq_target) { in process_rx_packets()
1230 if (queue_out_packet(s, template, sched_irq) < 0) { in process_rx_packets()
1231 cancel_stream(s); in process_rx_packets()
1235 desc = amdtp_stream_next_packet_desc(s, desc); in process_rx_packets()
1238 s->ctx_data.rx.event_count = event_count; in process_rx_packets()
1239 s->packet_descs_cursor = desc; in process_rx_packets()
1245 struct amdtp_stream *s = private_data; in skip_rx_packets() local
1246 struct amdtp_domain *d = s->domain; in skip_rx_packets()
1252 if (s->packet_index < 0) in skip_rx_packets()
1257 cycle = compute_ohci_it_cycle(ctx_header[packets - 1], s->queue_size); in skip_rx_packets()
1258 s->next_cycle = increment_ohci_cycle_count(cycle, 1); in skip_rx_packets()
1265 bool sched_irq = (s == d->irq_target && i == packets - 1); in skip_rx_packets()
1267 if (queue_out_packet(s, &params, sched_irq) < 0) { in skip_rx_packets()
1268 cancel_stream(s); in skip_rx_packets()
1280 struct amdtp_stream *s = private_data; in process_rx_packets_intermediately() local
1281 struct amdtp_domain *d = s->domain; in process_rx_packets_intermediately()
1283 const unsigned int queue_size = s->queue_size; in process_rx_packets_intermediately()
1287 if (s->packet_index < 0) in process_rx_packets_intermediately()
1306 if (amdtp_streaming_error(s)) in process_rx_packets_intermediately()
1314 s->ready_processing = true; in process_rx_packets_intermediately()
1315 wake_up(&s->ready_wait); in process_rx_packets_intermediately()
1318 s->ctx_data.rx.cache_pos = 0; in process_rx_packets_intermediately()
1321 if (amdtp_streaming_error(s)) in process_rx_packets_intermediately()
1324 if (s == d->irq_target) in process_rx_packets_intermediately()
1325 s->context->callback.sc = irq_target_callback; in process_rx_packets_intermediately()
1327 s->context->callback.sc = process_rx_packets; in process_rx_packets_intermediately()
1334 struct amdtp_stream *s = private_data; in process_tx_packets() local
1336 struct pkt_desc *desc = s->packet_descs_cursor; in process_tx_packets()
1342 if (s->packet_index < 0) in process_tx_packets()
1346 packet_count = header_length / s->ctx_data.tx.ctx_header_size; in process_tx_packets()
1349 err = generate_tx_packet_descs(s, desc, ctx_header, packet_count, &desc_count); in process_tx_packets()
1352 cancel_stream(s); in process_tx_packets()
1356 struct amdtp_domain *d = s->domain; in process_tx_packets()
1358 process_ctx_payloads(s, desc, desc_count); in process_tx_packets()
1361 cache_seq(s, desc, desc_count); in process_tx_packets()
1364 desc = amdtp_stream_next_packet_desc(s, desc); in process_tx_packets()
1365 s->packet_descs_cursor = desc; in process_tx_packets()
1371 if (queue_in_packet(s, &params) < 0) { in process_tx_packets()
1372 cancel_stream(s); in process_tx_packets()
1381 struct amdtp_stream *s = private_data; in drop_tx_packets() local
1387 if (s->packet_index < 0) in drop_tx_packets()
1390 packets = header_length / s->ctx_data.tx.ctx_header_size; in drop_tx_packets()
1392 ctx_header += (packets - 1) * s->ctx_data.tx.ctx_header_size / sizeof(*ctx_header); in drop_tx_packets()
1394 s->next_cycle = increment_ohci_cycle_count(cycle, 1); in drop_tx_packets()
1399 if (queue_in_packet(s, &params) < 0) { in drop_tx_packets()
1400 cancel_stream(s); in drop_tx_packets()
1409 struct amdtp_stream *s = private_data; in process_tx_packets_intermediately() local
1410 struct amdtp_domain *d = s->domain; in process_tx_packets_intermediately()
1415 if (s->packet_index < 0) in process_tx_packets_intermediately()
1418 packets = header_length / s->ctx_data.tx.ctx_header_size; in process_tx_packets_intermediately()
1428 ctx_header += s->ctx_data.tx.ctx_header_size / sizeof(__be32); in process_tx_packets_intermediately()
1435 size_t length = s->ctx_data.tx.ctx_header_size * offset; in process_tx_packets_intermediately()
1437 drop_tx_packets(context, tstamp, length, ctx_header, s); in process_tx_packets_intermediately()
1438 if (amdtp_streaming_error(s)) in process_tx_packets_intermediately()
1446 s->ready_processing = true; in process_tx_packets_intermediately()
1447 wake_up(&s->ready_wait); in process_tx_packets_intermediately()
1449 process_tx_packets(context, tstamp, header_length, ctx_header, s); in process_tx_packets_intermediately()
1450 if (amdtp_streaming_error(s)) in process_tx_packets_intermediately()
1460 struct amdtp_stream *s = private_data; in drop_tx_packets_initially() local
1461 struct amdtp_domain *d = s->domain; in drop_tx_packets_initially()
1467 if (s->packet_index < 0) in drop_tx_packets_initially()
1470 count = header_length / s->ctx_data.tx.ctx_header_size; in drop_tx_packets_initially()
1480 if (s->flags & CIP_NO_HEADER) { in drop_tx_packets_initially()
1481 data_blocks = payload_quads / s->data_block_quadlets; in drop_tx_packets_initially()
1490 if (s->flags & CIP_UNAWARE_SYT) { in drop_tx_packets_initially()
1491 data_blocks = payload_quads / s->data_block_quadlets; in drop_tx_packets_initially()
1500 data_blocks = payload_quads / s->data_block_quadlets; in drop_tx_packets_initially()
1507 ctx_header += s->ctx_data.tx.ctx_header_size / sizeof(__be32); in drop_tx_packets_initially()
1510 drop_tx_packets(context, tstamp, header_length, header, s); in drop_tx_packets_initially()
1513 s->ctx_data.tx.event_starts = true; in drop_tx_packets_initially()
1521 list_for_each_entry(s, &d->streams, list) { in drop_tx_packets_initially()
1522 if (s->direction == AMDTP_IN_STREAM) { in drop_tx_packets_initially()
1524 if (s->ctx_data.tx.event_starts) in drop_tx_packets_initially()
1532 list_for_each_entry(s, &d->streams, list) { in drop_tx_packets_initially()
1533 if (s->direction != AMDTP_IN_STREAM) in drop_tx_packets_initially()
1536 next_cycle = increment_ohci_cycle_count(s->next_cycle, in drop_tx_packets_initially()
1542 s->context->callback.sc = process_tx_packets_intermediately; in drop_tx_packets_initially()
1552 struct amdtp_stream *s; in process_ctxs_in_domain() local
1554 list_for_each_entry(s, &d->streams, list) { in process_ctxs_in_domain()
1555 if (s != d->irq_target && amdtp_stream_running(s)) in process_ctxs_in_domain()
1556 fw_iso_context_flush_completions(s->context); in process_ctxs_in_domain()
1558 if (amdtp_streaming_error(s)) in process_ctxs_in_domain()
1567 list_for_each_entry(s, &d->streams, list) { in process_ctxs_in_domain()
1568 if (amdtp_stream_running(s)) in process_ctxs_in_domain()
1569 cancel_stream(s); in process_ctxs_in_domain()
1576 struct amdtp_stream *s = private_data; in irq_target_callback() local
1577 struct amdtp_domain *d = s->domain; in irq_target_callback()
1586 struct amdtp_stream *s = private_data; in irq_target_callback_intermediately() local
1587 struct amdtp_domain *d = s->domain; in irq_target_callback_intermediately()
1596 struct amdtp_stream *s = private_data; in irq_target_callback_skip() local
1597 struct amdtp_domain *d = s->domain; in irq_target_callback_skip()
1630 unsigned int cycle = s->next_cycle; in irq_target_callback_skip()
1631 list_for_each_entry(s, &d->streams, list) { in irq_target_callback_skip()
1632 if (s->direction != AMDTP_OUT_STREAM) in irq_target_callback_skip()
1635 if (compare_ohci_cycle_count(s->next_cycle, cycle) > 0) in irq_target_callback_skip()
1636 cycle = s->next_cycle; in irq_target_callback_skip()
1638 if (s == d->irq_target) in irq_target_callback_skip()
1639 s->context->callback.sc = irq_target_callback_intermediately; in irq_target_callback_skip()
1641 s->context->callback.sc = process_rx_packets_intermediately; in irq_target_callback_skip()
1654 struct amdtp_stream *s = private_data; in amdtp_stream_first_callback() local
1655 struct amdtp_domain *d = s->domain; in amdtp_stream_first_callback()
1657 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_first_callback()
1660 if (s == d->irq_target) in amdtp_stream_first_callback()
1666 context->callback.sc(context, tstamp, header_length, header, s); in amdtp_stream_first_callback()
1671 * @s: the AMDTP stream to start
1681 static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed, in amdtp_stream_start() argument
1684 bool is_irq_target = (s == s->domain->irq_target); in amdtp_stream_start()
1691 mutex_lock(&s->mutex); in amdtp_stream_start()
1693 if (WARN_ON(amdtp_stream_running(s) || in amdtp_stream_start()
1694 (s->data_block_quadlets < 1))) { in amdtp_stream_start()
1699 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1706 s->data_block_counter = UINT_MAX; in amdtp_stream_start()
1708 s->data_block_counter = 0; in amdtp_stream_start()
1712 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1715 if (!(s->flags & CIP_NO_HEADER)) in amdtp_stream_start()
1724 max_ctx_payload_size = amdtp_stream_get_max_ctx_payload_size(s); in amdtp_stream_start()
1726 err = iso_packets_buffer_init(&s->buffer, s->unit, queue_size, max_ctx_payload_size, dir); in amdtp_stream_start()
1729 s->queue_size = queue_size; in amdtp_stream_start()
1731 s->context = fw_iso_context_create(fw_parent_device(s->unit)->card, in amdtp_stream_start()
1733 amdtp_stream_first_callback, s); in amdtp_stream_start()
1734 if (IS_ERR(s->context)) { in amdtp_stream_start()
1735 err = PTR_ERR(s->context); in amdtp_stream_start()
1737 dev_err(&s->unit->device, in amdtp_stream_start()
1742 amdtp_stream_update(s); in amdtp_stream_start()
1744 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1745 s->ctx_data.tx.max_ctx_payload_length = max_ctx_payload_size; in amdtp_stream_start()
1746 s->ctx_data.tx.ctx_header_size = ctx_header_size; in amdtp_stream_start()
1747 s->ctx_data.tx.event_starts = false; in amdtp_stream_start()
1749 if (s->domain->replay.enable) { in amdtp_stream_start()
1750 // struct fw_iso_context.drop_overflow_headers is false therefore it's in amdtp_stream_start()
1752 s->ctx_data.tx.cache.size = max_t(unsigned int, s->syt_interval * 2, in amdtp_stream_start()
1754 s->ctx_data.tx.cache.pos = 0; in amdtp_stream_start()
1755 s->ctx_data.tx.cache.descs = kcalloc(s->ctx_data.tx.cache.size, in amdtp_stream_start()
1756 sizeof(*s->ctx_data.tx.cache.descs), GFP_KERNEL); in amdtp_stream_start()
1757 if (!s->ctx_data.tx.cache.descs) { in amdtp_stream_start()
1776 s->ctx_data.rx.seq.descs = kcalloc(queue_size, sizeof(*s->ctx_data.rx.seq.descs), GFP_KERNEL); in amdtp_stream_start()
1777 if (!s->ctx_data.rx.seq.descs) { in amdtp_stream_start()
1781 s->ctx_data.rx.seq.size = queue_size; in amdtp_stream_start()
1782 s->ctx_data.rx.seq.pos = 0; in amdtp_stream_start()
1784 entry = &initial_state[s->sfc]; in amdtp_stream_start()
1785 s->ctx_data.rx.data_block_state = entry->data_block; in amdtp_stream_start()
1786 s->ctx_data.rx.syt_offset_state = entry->syt_offset; in amdtp_stream_start()
1787 s->ctx_data.rx.last_syt_offset = TICKS_PER_CYCLE; in amdtp_stream_start()
1789 s->ctx_data.rx.event_count = 0; in amdtp_stream_start()
1792 if (s->flags & CIP_NO_HEADER) in amdtp_stream_start()
1793 s->tag = TAG_NO_CIP_HEADER; in amdtp_stream_start()
1795 s->tag = TAG_CIP; in amdtp_stream_start()
1801 descs = kcalloc(s->queue_size + 8, sizeof(*descs), GFP_KERNEL); in amdtp_stream_start()
1806 s->packet_descs = descs; in amdtp_stream_start()
1808 INIT_LIST_HEAD(&s->packet_descs_list); in amdtp_stream_start()
1809 for (i = 0; i < s->queue_size; ++i) { in amdtp_stream_start()
1811 list_add_tail(&descs->link, &s->packet_descs_list); in amdtp_stream_start()
1814 s->packet_descs_cursor = list_first_entry(&s->packet_descs_list, struct pkt_desc, link); in amdtp_stream_start()
1816 s->packet_index = 0; in amdtp_stream_start()
1820 if (s->direction == AMDTP_IN_STREAM) { in amdtp_stream_start()
1821 err = queue_in_packet(s, &params); in amdtp_stream_start()
1829 sched_irq = !((s->packet_index + 1) % in amdtp_stream_start()
1833 err = queue_out_packet(s, &params, sched_irq); in amdtp_stream_start()
1837 } while (s->packet_index > 0); in amdtp_stream_start()
1841 if ((s->flags & CIP_EMPTY_WITH_TAG0) || (s->flags & CIP_NO_HEADER)) in amdtp_stream_start()
1844 s->ready_processing = false; in amdtp_stream_start()
1845 err = fw_iso_context_start(s->context, -1, 0, tag); in amdtp_stream_start()
1849 mutex_unlock(&s->mutex); in amdtp_stream_start()
1853 kfree(s->packet_descs); in amdtp_stream_start()
1854 s->packet_descs = NULL; in amdtp_stream_start()
1856 if (s->direction == AMDTP_OUT_STREAM) { in amdtp_stream_start()
1857 kfree(s->ctx_data.rx.seq.descs); in amdtp_stream_start()
1859 if (s->domain->replay.enable) in amdtp_stream_start()
1860 kfree(s->ctx_data.tx.cache.descs); in amdtp_stream_start()
1862 fw_iso_context_destroy(s->context); in amdtp_stream_start()
1863 s->context = ERR_PTR(-1); in amdtp_stream_start()
1865 iso_packets_buffer_destroy(&s->buffer, s->unit); in amdtp_stream_start()
1867 mutex_unlock(&s->mutex); in amdtp_stream_start()
1875 * @s: the AMDTP stream that transports the PCM data
1880 struct amdtp_stream *s) in amdtp_domain_stream_pcm_pointer() argument
1888 if (current_work() != &s->period_work) in amdtp_domain_stream_pcm_pointer()
1892 return READ_ONCE(s->pcm_buffer_pointer); in amdtp_domain_stream_pcm_pointer()
1899 * @s: the AMDTP stream that transfers the PCM frames
1903 int amdtp_domain_stream_pcm_ack(struct amdtp_domain *d, struct amdtp_stream *s) in amdtp_domain_stream_pcm_ack() argument
1918 * @s: the AMDTP stream
1920 void amdtp_stream_update(struct amdtp_stream *s) in amdtp_stream_update() argument
1923 WRITE_ONCE(s->source_node_id_field, in amdtp_stream_update()
1924 (fw_parent_device(s->unit)->card->node_id << CIP_SID_SHIFT) & CIP_SID_MASK); in amdtp_stream_update()
1930 * @s: the AMDTP stream to stop
1935 static void amdtp_stream_stop(struct amdtp_stream *s) in amdtp_stream_stop() argument
1937 mutex_lock(&s->mutex); in amdtp_stream_stop()
1939 if (!amdtp_stream_running(s)) { in amdtp_stream_stop()
1940 mutex_unlock(&s->mutex); in amdtp_stream_stop()
1944 cancel_work_sync(&s->period_work); in amdtp_stream_stop()
1945 fw_iso_context_stop(s->context); in amdtp_stream_stop()
1946 fw_iso_context_destroy(s->context); in amdtp_stream_stop()
1947 s->context = ERR_PTR(-1); in amdtp_stream_stop()
1948 iso_packets_buffer_destroy(&s->buffer, s->unit); in amdtp_stream_stop()
1949 kfree(s->packet_descs); in amdtp_stream_stop()
1950 s->packet_descs = NULL; in amdtp_stream_stop()
1952 if (s->direction == AMDTP_OUT_STREAM) { in amdtp_stream_stop()
1953 kfree(s->ctx_data.rx.seq.descs); in amdtp_stream_stop()
1955 if (s->domain->replay.enable) in amdtp_stream_stop()
1956 kfree(s->ctx_data.tx.cache.descs); in amdtp_stream_stop()
1959 mutex_unlock(&s->mutex); in amdtp_stream_stop()
1964 * @s: the AMDTP stream about to be stopped
1969 void amdtp_stream_pcm_abort(struct amdtp_stream *s) in amdtp_stream_pcm_abort() argument
1973 pcm = READ_ONCE(s->pcm); in amdtp_stream_pcm_abort()
2007 * @s: the AMDTP stream.
2011 int amdtp_domain_add_stream(struct amdtp_domain *d, struct amdtp_stream *s, in amdtp_domain_add_stream() argument
2017 if (s == tmp) in amdtp_domain_add_stream()
2021 list_add(&s->list, &d->streams); in amdtp_domain_add_stream()
2023 s->channel = channel; in amdtp_domain_add_stream()
2024 s->speed = speed; in amdtp_domain_add_stream()
2025 s->domain = d; in amdtp_domain_add_stream()
2043 struct amdtp_stream *s; in make_association() local
2045 list_for_each_entry(s, &d->streams, list) { in make_association()
2046 if (s->direction == AMDTP_IN_STREAM) { in make_association()
2048 tx = s; in make_association()
2057 list_for_each_entry(s, &d->streams, list) { in make_association()
2058 if (s->direction == AMDTP_IN_STREAM) { in make_association()
2059 tx = s; in make_association()
2093 struct amdtp_stream *s; in amdtp_domain_start() local
2106 list_for_each_entry(s, &d->streams, list) { in amdtp_domain_start()
2107 if (s->direction == AMDTP_OUT_STREAM) { in amdtp_domain_start()
2114 d->irq_target = s; in amdtp_domain_start()
2129 list_for_each_entry(s, &d->streams, list) { in amdtp_domain_start()
2132 if (s->direction == AMDTP_OUT_STREAM && s == d->irq_target) { in amdtp_domain_start()
2138 err = amdtp_stream_start(s, s->channel, s->speed, queue_size, idle_irq_interval); in amdtp_domain_start()
2145 list_for_each_entry(s, &d->streams, list) in amdtp_domain_start()
2146 amdtp_stream_stop(s); in amdtp_domain_start()
2157 struct amdtp_stream *s, *next; in amdtp_domain_stop() local
2162 list_for_each_entry_safe(s, next, &d->streams, list) { in amdtp_domain_stop()
2163 list_del(&s->list); in amdtp_domain_stop()
2165 if (s != d->irq_target) in amdtp_domain_stop()
2166 amdtp_stream_stop(s); in amdtp_domain_stop()