Skip to content

Commit 6fc6b9c

Browse files
takaswietiwai
authored andcommitted
ALSA: firewire-lib: pass the number of data blocks in incoming packets to outgoing packets
Current implementation reuses the value of syt field in incoming packet to outgoing packet for full duplex timestamp synchronization, while the number of data blocks in outgoing packets refers to hard-coded table and the synchronization cannot be applied to non-blocking stream. This commit passes the number of data blocks from incoming packet processing to outgoing packet processing for the synchronization. For normal mode, isochronous callback handler is changed to generate the values of syt and data blocks. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 875be09 commit 6fc6b9c

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

‎sound/firewire/amdtp.c‎

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,16 @@ static inline int queue_in_packet(struct amdtp_stream *s)
647647
amdtp_stream_get_max_payload(s), false);
648648
}
649649

650-
static void handle_out_packet(struct amdtp_stream *s, unsigned int syt)
650+
static void handle_out_packet(struct amdtp_stream *s, unsigned int data_blocks,
651+
unsigned int syt)
651652
{
652653
__be32 *buffer;
653-
unsigned int data_blocks, payload_length;
654+
unsigned int payload_length;
654655
struct snd_pcm_substream *pcm;
655656

656657
if (s->packet_index < 0)
657658
return;
658659

659-
data_blocks = calculate_data_blocks(s, syt);
660-
661660
buffer = s->buffer.packets[s->packet_index].buffer;
662661
buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
663662
(s->data_block_quadlets << AMDTP_DBS_SHIFT) |
@@ -687,13 +686,12 @@ static void handle_out_packet(struct amdtp_stream *s, unsigned int syt)
687686
update_pcm_pointers(s, pcm, data_blocks);
688687
}
689688

690-
static void handle_in_packet(struct amdtp_stream *s,
691-
unsigned int payload_quadlets,
692-
__be32 *buffer)
689+
static int handle_in_packet(struct amdtp_stream *s,
690+
unsigned int payload_quadlets, __be32 *buffer)
693691
{
694692
u32 cip_header[2];
695-
unsigned int data_blocks, data_block_quadlets, data_block_counter,
696-
dbc_interval;
693+
unsigned int data_blocks;
694+
unsigned int data_block_quadlets, data_block_counter, dbc_interval;
697695
struct snd_pcm_substream *pcm = NULL;
698696
bool lost;
699697

@@ -710,6 +708,7 @@ static void handle_in_packet(struct amdtp_stream *s,
710708
dev_info_ratelimited(&s->unit->device,
711709
"Invalid CIP header for AMDTP: %08X:%08X\n",
712710
cip_header[0], cip_header[1]);
711+
data_blocks = 0;
713712
goto end;
714713
}
715714

@@ -726,7 +725,7 @@ static void handle_in_packet(struct amdtp_stream *s,
726725
dev_info_ratelimited(&s->unit->device,
727726
"Detect invalid value in dbs field: %08X\n",
728727
cip_header[0]);
729-
goto err;
728+
return -EIO;
730729
}
731730
if (s->flags & CIP_WRONG_DBS)
732731
data_block_quadlets = s->data_block_quadlets;
@@ -759,7 +758,7 @@ static void handle_in_packet(struct amdtp_stream *s,
759758
dev_info(&s->unit->device,
760759
"Detect discontinuity of CIP: %02X %02X\n",
761760
s->data_block_counter, data_block_counter);
762-
goto err;
761+
return -EIO;
763762
}
764763

765764
if (data_blocks > 0) {
@@ -780,15 +779,12 @@ static void handle_in_packet(struct amdtp_stream *s,
780779
(data_block_counter + data_blocks) & 0xff;
781780
end:
782781
if (queue_in_packet(s) < 0)
783-
goto err;
782+
return -EIO;
784783

785784
if (pcm)
786785
update_pcm_pointers(s, pcm, data_blocks);
787786

788-
return;
789-
err:
790-
s->packet_index = -1;
791-
amdtp_stream_pcm_abort(s);
787+
return data_blocks;
792788
}
793789

794790
static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
@@ -797,6 +793,7 @@ static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
797793
{
798794
struct amdtp_stream *s = private_data;
799795
unsigned int i, syt, packets = header_length / 4;
796+
unsigned int data_blocks;
800797

801798
/*
802799
* Compute the cycle of the last queued packet.
@@ -807,7 +804,9 @@ static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
807804

808805
for (i = 0; i < packets; ++i) {
809806
syt = calculate_syt(s, ++cycle);
810-
handle_out_packet(s, syt);
807+
data_blocks = calculate_data_blocks(s, syt);
808+
809+
handle_out_packet(s, data_blocks, syt);
811810
}
812811
fw_iso_context_queue_flush(s->context);
813812
}
@@ -819,6 +818,7 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
819818
struct amdtp_stream *s = private_data;
820819
unsigned int p, syt, packets;
821820
unsigned int payload_quadlets, max_payload_quadlets;
821+
unsigned int data_blocks;
822822
__be32 *buffer, *headers = header;
823823

824824
/* The number of packets in buffer */
@@ -833,12 +833,6 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
833833

834834
buffer = s->buffer.packets[s->packet_index].buffer;
835835

836-
/* Process sync slave stream */
837-
if (s->sync_slave && s->sync_slave->callbacked) {
838-
syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK;
839-
handle_out_packet(s->sync_slave, syt);
840-
}
841-
842836
/* The number of quadlets in this packet */
843837
payload_quadlets =
844838
(be32_to_cpu(headers[p]) >> ISO_DATA_LENGTH_SHIFT) / 4;
@@ -850,11 +844,23 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
850844
break;
851845
}
852846

853-
handle_in_packet(s, payload_quadlets, buffer);
847+
data_blocks = handle_in_packet(s, payload_quadlets, buffer);
848+
if (data_blocks < 0) {
849+
s->packet_index = -1;
850+
break;
851+
}
852+
853+
/* Process sync slave stream */
854+
if (s->sync_slave && s->sync_slave->callbacked) {
855+
syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK;
856+
handle_out_packet(s->sync_slave, data_blocks, syt);
857+
}
854858
}
855859

856860
/* Queueing error or detecting discontinuity */
857861
if (s->packet_index < 0) {
862+
amdtp_stream_pcm_abort(s);
863+
858864
/* Abort sync slave. */
859865
if (s->sync_slave) {
860866
s->sync_slave->packet_index = -1;

0 commit comments

Comments
 (0)