Commit d32872f3 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai

ALSA: firewire-lib: code refactoring for sequence descriptor'

A internal structure is used to gather parameters relevant to sequence
descriptor.
Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20210518130048.146596-4-o-takashi@sakamocchi.jpSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c09010ee
...@@ -852,8 +852,8 @@ static void out_stream_callback(struct fw_iso_context *context, u32 tstamp, ...@@ -852,8 +852,8 @@ static void out_stream_callback(struct fw_iso_context *context, u32 tstamp,
// Calculate the number of packets in buffer and check XRUN. // Calculate the number of packets in buffer and check XRUN.
packets = header_length / sizeof(*ctx_header); packets = header_length / sizeof(*ctx_header);
generate_pkt_descs(s, s->pkt_descs, ctx_header, packets, d->seq_descs, generate_pkt_descs(s, s->pkt_descs, ctx_header, packets, d->seq.descs,
d->seq_size); d->seq.size);
process_ctx_payloads(s, s->pkt_descs, packets); process_ctx_payloads(s, s->pkt_descs, packets);
...@@ -931,12 +931,12 @@ static void in_stream_callback(struct fw_iso_context *context, u32 tstamp, ...@@ -931,12 +931,12 @@ static void in_stream_callback(struct fw_iso_context *context, u32 tstamp,
static void pool_ideal_seq_descs(struct amdtp_domain *d, unsigned int packets) static void pool_ideal_seq_descs(struct amdtp_domain *d, unsigned int packets)
{ {
struct amdtp_stream *irq_target = d->irq_target; struct amdtp_stream *irq_target = d->irq_target;
unsigned int seq_tail = d->seq_tail; unsigned int seq_tail = d->seq.tail;
unsigned int seq_size = d->seq_size; unsigned int seq_size = d->seq.size;
unsigned int min_avail; unsigned int min_avail;
struct amdtp_stream *s; struct amdtp_stream *s;
min_avail = d->seq_size; min_avail = d->seq.size;
list_for_each_entry(s, &d->streams, list) { list_for_each_entry(s, &d->streams, list) {
unsigned int seq_index; unsigned int seq_index;
unsigned int avail; unsigned int avail;
...@@ -945,9 +945,9 @@ static void pool_ideal_seq_descs(struct amdtp_domain *d, unsigned int packets) ...@@ -945,9 +945,9 @@ static void pool_ideal_seq_descs(struct amdtp_domain *d, unsigned int packets)
continue; continue;
seq_index = s->ctx_data.rx.seq_index; seq_index = s->ctx_data.rx.seq_index;
avail = d->seq_tail; avail = d->seq.tail;
if (seq_index > avail) if (seq_index > avail)
avail += d->seq_size; avail += d->seq.size;
avail -= seq_index; avail -= seq_index;
if (avail < min_avail) if (avail < min_avail)
...@@ -955,7 +955,7 @@ static void pool_ideal_seq_descs(struct amdtp_domain *d, unsigned int packets) ...@@ -955,7 +955,7 @@ static void pool_ideal_seq_descs(struct amdtp_domain *d, unsigned int packets)
} }
while (min_avail < packets) { while (min_avail < packets) {
struct seq_desc *desc = d->seq_descs + seq_tail; struct seq_desc *desc = d->seq.descs + seq_tail;
desc->syt_offset = calculate_syt_offset(&d->last_syt_offset, desc->syt_offset = calculate_syt_offset(&d->last_syt_offset,
&d->syt_offset_state, irq_target->sfc); &d->syt_offset_state, irq_target->sfc);
...@@ -970,7 +970,7 @@ static void pool_ideal_seq_descs(struct amdtp_domain *d, unsigned int packets) ...@@ -970,7 +970,7 @@ static void pool_ideal_seq_descs(struct amdtp_domain *d, unsigned int packets)
++min_avail; ++min_avail;
} }
d->seq_tail = seq_tail; d->seq.tail = seq_tail;
} }
static void irq_target_callback(struct fw_iso_context *context, u32 tstamp, static void irq_target_callback(struct fw_iso_context *context, u32 tstamp,
...@@ -1323,7 +1323,7 @@ int amdtp_domain_init(struct amdtp_domain *d) ...@@ -1323,7 +1323,7 @@ int amdtp_domain_init(struct amdtp_domain *d)
d->events_per_period = 0; d->events_per_period = 0;
d->seq_descs = NULL; d->seq.descs = NULL;
return 0; return 0;
} }
...@@ -1438,11 +1438,11 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int ir_delay_cycle) ...@@ -1438,11 +1438,11 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int ir_delay_cycle)
queue_size = DIV_ROUND_UP(CYCLES_PER_SECOND * events_per_buffer, queue_size = DIV_ROUND_UP(CYCLES_PER_SECOND * events_per_buffer,
amdtp_rate_table[d->irq_target->sfc]); amdtp_rate_table[d->irq_target->sfc]);
d->seq_descs = kcalloc(queue_size, sizeof(*d->seq_descs), GFP_KERNEL); d->seq.descs = kcalloc(queue_size, sizeof(*d->seq.descs), GFP_KERNEL);
if (!d->seq_descs) if (!d->seq.descs)
return -ENOMEM; return -ENOMEM;
d->seq_size = queue_size; d->seq.size = queue_size;
d->seq_tail = 0; d->seq.tail = 0;
entry = &initial_state[s->sfc]; entry = &initial_state[s->sfc];
d->data_block_state = entry->data_block; d->data_block_state = entry->data_block;
...@@ -1511,8 +1511,8 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int ir_delay_cycle) ...@@ -1511,8 +1511,8 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int ir_delay_cycle)
error: error:
list_for_each_entry(s, &d->streams, list) list_for_each_entry(s, &d->streams, list)
amdtp_stream_stop(s); amdtp_stream_stop(s);
kfree(d->seq_descs); kfree(d->seq.descs);
d->seq_descs = NULL; d->seq.descs = NULL;
return err; return err;
} }
EXPORT_SYMBOL_GPL(amdtp_domain_start); EXPORT_SYMBOL_GPL(amdtp_domain_start);
...@@ -1538,7 +1538,7 @@ void amdtp_domain_stop(struct amdtp_domain *d) ...@@ -1538,7 +1538,7 @@ void amdtp_domain_stop(struct amdtp_domain *d)
d->events_per_period = 0; d->events_per_period = 0;
d->irq_target = NULL; d->irq_target = NULL;
kfree(d->seq_descs); kfree(d->seq.descs);
d->seq_descs = NULL; d->seq.descs = NULL;
} }
EXPORT_SYMBOL_GPL(amdtp_domain_stop); EXPORT_SYMBOL_GPL(amdtp_domain_stop);
...@@ -287,9 +287,11 @@ struct amdtp_domain { ...@@ -287,9 +287,11 @@ struct amdtp_domain {
struct amdtp_stream *irq_target; struct amdtp_stream *irq_target;
struct seq_desc *seq_descs; struct {
unsigned int seq_size; struct seq_desc *descs;
unsigned int seq_tail; unsigned int size;
unsigned int tail;
} seq;
unsigned int data_block_state; unsigned int data_block_state;
unsigned int syt_offset_state; unsigned int syt_offset_state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment