Skip to content

Commit ec00f5e

Browse files
cladischtiwai
authored andcommitted
ALSA: firewire-lib, firewire-speakers: handle packet queueing errors
Add an AMDTP stream error state that occurs when we fail to queue another packet. In this case, the stream is stopped, and the error can be reported when the application tries to restart the PCM stream. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 5b2599a commit ec00f5e

3 files changed

Lines changed: 37 additions & 13 deletions

File tree

‎sound/firewire/amdtp.c‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
4747
s->flags = flags;
4848
s->context = ERR_PTR(-1);
4949
mutex_init(&s->mutex);
50+
s->packet_index = 0;
5051

5152
return 0;
5253
}
@@ -316,15 +317,19 @@ static void amdtp_fill_midi(struct amdtp_out_stream *s,
316317
static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
317318
{
318319
__be32 *buffer;
319-
unsigned int data_blocks, syt, ptr;
320+
unsigned int index, data_blocks, syt, ptr;
320321
struct snd_pcm_substream *pcm;
321322
struct fw_iso_packet packet;
322323
int err;
323324

325+
if (s->packet_index < 0)
326+
return;
327+
index = s->packet_index;
328+
324329
data_blocks = calculate_data_blocks(s);
325330
syt = calculate_syt(s, cycle);
326331

327-
buffer = s->buffer.packets[s->packet_counter].buffer;
332+
buffer = s->buffer.packets[index].buffer;
328333
buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
329334
(s->data_block_quadlets << 16) |
330335
s->data_block_counter);
@@ -343,20 +348,24 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
343348
s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;
344349

345350
packet.payload_length = 8 + data_blocks * 4 * s->data_block_quadlets;
346-
packet.interrupt = IS_ALIGNED(s->packet_counter + 1,
347-
INTERRUPT_INTERVAL);
351+
packet.interrupt = IS_ALIGNED(index + 1, INTERRUPT_INTERVAL);
348352
packet.skip = 0;
349353
packet.tag = TAG_CIP;
350354
packet.sy = 0;
351355
packet.header_length = 0;
352356

353357
err = fw_iso_context_queue(s->context, &packet, &s->buffer.iso_buffer,
354-
s->buffer.packets[s->packet_counter].offset);
355-
if (err < 0)
358+
s->buffer.packets[index].offset);
359+
if (err < 0) {
356360
dev_err(&s->unit->device, "queueing error: %d\n", err);
361+
s->packet_index = -1;
362+
amdtp_out_stream_pcm_abort(s);
363+
return;
364+
}
357365

358-
if (++s->packet_counter >= QUEUE_LENGTH)
359-
s->packet_counter = 0;
366+
if (++index >= QUEUE_LENGTH)
367+
index = 0;
368+
s->packet_index = index;
360369

361370
if (pcm) {
362371
ptr = s->pcm_buffer_pointer + data_blocks;
@@ -398,13 +407,13 @@ static int queue_initial_skip_packets(struct amdtp_out_stream *s)
398407
int err;
399408

400409
for (i = 0; i < QUEUE_LENGTH; ++i) {
401-
skip_packet.interrupt = IS_ALIGNED(s->packet_counter + 1,
410+
skip_packet.interrupt = IS_ALIGNED(s->packet_index + 1,
402411
INTERRUPT_INTERVAL);
403412
err = fw_iso_context_queue(s->context, &skip_packet, NULL, 0);
404413
if (err < 0)
405414
return err;
406-
if (++s->packet_counter >= QUEUE_LENGTH)
407-
s->packet_counter = 0;
415+
if (++s->packet_index >= QUEUE_LENGTH)
416+
s->packet_index = 0;
408417
}
409418

410419
return 0;
@@ -469,7 +478,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
469478

470479
amdtp_out_stream_update(s);
471480

472-
s->packet_counter = 0;
481+
s->packet_index = 0;
473482
s->data_block_counter = 0;
474483
err = queue_initial_skip_packets(s);
475484
if (err < 0)

‎sound/firewire/amdtp.h‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct amdtp_out_stream {
5656

5757
struct snd_pcm_substream *pcm;
5858

59-
unsigned int packet_counter;
59+
int packet_index;
6060
unsigned int data_block_counter;
6161

6262
unsigned int data_block_state;
@@ -110,6 +110,18 @@ static inline void amdtp_out_stream_set_midi(struct amdtp_out_stream *s,
110110
s->midi_ports = midi_ports;
111111
}
112112

113+
/**
114+
* amdtp_out_streaming_error - check for streaming error
115+
* @s: the AMDTP output stream
116+
*
117+
* If this function returns true, the stream's packet queue has stopped due to
118+
* an asynchronous error.
119+
*/
120+
static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
121+
{
122+
return s->packet_index < 0;
123+
}
124+
113125
/**
114126
* amdtp_out_stream_pcm_prepare - prepare PCM device for running
115127
* @s: the AMDTP output stream

‎sound/firewire/speakers.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ static int fwspk_prepare(struct snd_pcm_substream *substream)
283283

284284
mutex_lock(&fwspk->mutex);
285285

286+
if (amdtp_out_streaming_error(&fwspk->stream))
287+
fwspk_stop_stream(fwspk);
288+
286289
if (!fwspk->stream_running) {
287290
err = cmp_connection_establish(&fwspk->connection,
288291
amdtp_out_stream_get_max_payload(&fwspk->stream));

0 commit comments

Comments
 (0)