Commit 26cd1e58 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai

ALSA: firewire-lib: use IT context header to compute cycle count for scheduling packet

In IT context, header includes information of cycle to have processed
queued packet.

This commit uses the per-packet information to compute the cycle for
packet to be queued, instead of callback argument. In current
implementaion of ALSA IEC 61883-1/6 packet streaming engine, 48 packets
are queued at first to skip recent cycle. When IT context calls handler,
cycle information in header plus 48 cycle means the cycle to be going
to queue packet.
Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent df9160b9
...@@ -694,13 +694,12 @@ static int handle_in_packet_without_header(struct amdtp_stream *s, ...@@ -694,13 +694,12 @@ static int handle_in_packet_without_header(struct amdtp_stream *s,
return 0; return 0;
} }
/* // In CYCLE_TIMER register of IEEE 1394, 7 bits are used to represent second. On
* In CYCLE_TIMER register of IEEE 1394, 7 bits are used to represent second. On // the other hand, in DMA descriptors of 1394 OHCI, 3 bits are used to represent
* the other hand, in DMA descriptors of 1394 OHCI, 3 bits are used to represent // it. Thus, via Linux firewire subsystem, we can get the 3 bits for second.
* it. Thus, via Linux firewire subsystem, we can get the 3 bits for second. static inline u32 compute_cycle_count(__be32 ctx_header_tstamp)
*/
static inline u32 compute_cycle_count(u32 tstamp)
{ {
u32 tstamp = be32_to_cpu(ctx_header_tstamp) & HEADER_TSTAMP_MASK;
return (((tstamp >> 13) & 0x07) * 8000) + (tstamp & 0x1fff); return (((tstamp >> 13) & 0x07) * 8000) + (tstamp & 0x1fff);
} }
...@@ -712,6 +711,16 @@ static inline u32 increment_cycle_count(u32 cycle, unsigned int addend) ...@@ -712,6 +711,16 @@ static inline u32 increment_cycle_count(u32 cycle, unsigned int addend)
return cycle; return cycle;
} }
// Align to actual cycle count for the packet which is going to be scheduled.
// This module queued the same number of isochronous cycle as QUEUE_LENGTH to
// skip isochronous cycle, therefore it's OK to just increment the cycle by
// QUEUE_LENGTH for scheduled cycle.
static inline u32 compute_it_cycle(const __be32 ctx_header_tstamp)
{
u32 cycle = compute_cycle_count(ctx_header_tstamp);
return increment_cycle_count(cycle, QUEUE_LENGTH);
}
static inline void cancel_stream(struct amdtp_stream *s) static inline void cancel_stream(struct amdtp_stream *s)
{ {
s->packet_index = -1; s->packet_index = -1;
...@@ -725,23 +734,23 @@ static void out_stream_callback(struct fw_iso_context *context, u32 tstamp, ...@@ -725,23 +734,23 @@ static void out_stream_callback(struct fw_iso_context *context, u32 tstamp,
void *private_data) void *private_data)
{ {
struct amdtp_stream *s = private_data; struct amdtp_stream *s = private_data;
unsigned int i, packets = header_length / 4; const __be32 *ctx_header = header;
u32 cycle; unsigned int i, packets = header_length / sizeof(*ctx_header);
if (s->packet_index < 0) if (s->packet_index < 0)
return; return;
cycle = compute_cycle_count(tstamp); for (i = 0; i < packets; ++i) {
u32 cycle;
/* Align to actual cycle count for the last packet. */ cycle = compute_it_cycle(*ctx_header);
cycle = increment_cycle_count(cycle, QUEUE_LENGTH - packets);
for (i = 0; i < packets; ++i) {
cycle = increment_cycle_count(cycle, 1);
if (s->handle_packet(s, 0, cycle, i) < 0) { if (s->handle_packet(s, 0, cycle, i) < 0) {
cancel_stream(s); cancel_stream(s);
return; return;
} }
++ctx_header;
} }
fw_iso_context_queue_flush(s->context); fw_iso_context_queue_flush(s->context);
...@@ -767,10 +776,9 @@ static void in_stream_callback(struct fw_iso_context *context, u32 tstamp, ...@@ -767,10 +776,9 @@ static void in_stream_callback(struct fw_iso_context *context, u32 tstamp,
for (i = 0; i < packets; i++) { for (i = 0; i < packets; i++) {
u32 iso_header = be32_to_cpu(ctx_header[0]); u32 iso_header = be32_to_cpu(ctx_header[0]);
unsigned int cycle; u32 cycle;
tstamp = be32_to_cpu(ctx_header[1]) & HEADER_TSTAMP_MASK; cycle = compute_cycle_count(ctx_header[1]);
cycle = compute_cycle_count(tstamp);
/* The number of bytes in this packet */ /* The number of bytes in this packet */
payload_length = iso_header >> ISO_DATA_LENGTH_SHIFT; payload_length = iso_header >> ISO_DATA_LENGTH_SHIFT;
...@@ -802,9 +810,8 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context, ...@@ -802,9 +810,8 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context,
void *header, void *private_data) void *header, void *private_data)
{ {
struct amdtp_stream *s = private_data; struct amdtp_stream *s = private_data;
__be32 *ctx_header = header; const __be32 *ctx_header = header;
u32 cycle; u32 cycle;
unsigned int packets;
/* /*
* For in-stream, first packet has come. * For in-stream, first packet has come.
...@@ -814,8 +821,7 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context, ...@@ -814,8 +821,7 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context,
wake_up(&s->callback_wait); wake_up(&s->callback_wait);
if (s->direction == AMDTP_IN_STREAM) { if (s->direction == AMDTP_IN_STREAM) {
tstamp = be32_to_cpu(ctx_header[1]) & HEADER_TSTAMP_MASK; cycle = compute_cycle_count(ctx_header[1]);
cycle = compute_cycle_count(tstamp);
context->callback.sc = in_stream_callback; context->callback.sc = in_stream_callback;
if (s->flags & CIP_NO_HEADER) if (s->flags & CIP_NO_HEADER)
...@@ -823,9 +829,8 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context, ...@@ -823,9 +829,8 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context,
else else
s->handle_packet = handle_in_packet; s->handle_packet = handle_in_packet;
} else { } else {
packets = header_length / 4; cycle = compute_it_cycle(*ctx_header);
cycle = compute_cycle_count(tstamp);
cycle = increment_cycle_count(cycle, QUEUE_LENGTH - packets);
context->callback.sc = out_stream_callback; context->callback.sc = out_stream_callback;
if (s->flags & CIP_NO_HEADER) if (s->flags & CIP_NO_HEADER)
s->handle_packet = handle_out_packet_without_header; s->handle_packet = handle_out_packet_without_header;
......
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