Commit 6007bf54 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai

ALSA: firewire-lib: code refactoring to queueing packets

This commit is a preparation to queue IT packet with header. To enable
packet handler to fill the header, this commit uses kernel stack for
data structure of packet parameter in several part of this file.
Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 16be4589
...@@ -430,30 +430,15 @@ static void pcm_period_tasklet(unsigned long data) ...@@ -430,30 +430,15 @@ static void pcm_period_tasklet(unsigned long data)
snd_pcm_period_elapsed(pcm); snd_pcm_period_elapsed(pcm);
} }
static int queue_packet(struct amdtp_stream *s, unsigned int payload_length) static int queue_packet(struct amdtp_stream *s, struct fw_iso_packet *params)
{ {
struct fw_iso_packet p = {0}; int err;
int err = 0;
if (IS_ERR(s->context))
goto end;
p.interrupt = IS_ALIGNED(s->packet_index + 1, INTERRUPT_INTERVAL);
p.tag = s->tag;
if (s->direction == AMDTP_IN_STREAM) { params->interrupt = IS_ALIGNED(s->packet_index + 1, INTERRUPT_INTERVAL);
// Queue one packet for IR context. params->tag = s->tag;
p.header_length = s->ctx_data.tx.ctx_header_size; params->sy = 0;
} else {
// No header for this packet.
p.header_length = 0;
}
if (payload_length > 0) err = fw_iso_context_queue(s->context, params, &s->buffer.iso_buffer,
p.payload_length = payload_length;
else
p.skip = true;
err = fw_iso_context_queue(s->context, &p, &s->buffer.iso_buffer,
s->buffer.packets[s->packet_index].offset); s->buffer.packets[s->packet_index].offset);
if (err < 0) { if (err < 0) {
dev_err(&s->unit->device, "queueing error: %d\n", err); dev_err(&s->unit->device, "queueing error: %d\n", err);
...@@ -467,14 +452,24 @@ static int queue_packet(struct amdtp_stream *s, unsigned int payload_length) ...@@ -467,14 +452,24 @@ static int queue_packet(struct amdtp_stream *s, unsigned int payload_length)
} }
static inline int queue_out_packet(struct amdtp_stream *s, static inline int queue_out_packet(struct amdtp_stream *s,
struct fw_iso_packet *params,
unsigned int payload_length) unsigned int payload_length)
{ {
return queue_packet(s, payload_length); // No header for this packet.
params->header_length = 0;
params->payload_length = payload_length;
params->skip = !!(payload_length == 0);
return queue_packet(s, params);
} }
static inline int queue_in_packet(struct amdtp_stream *s) static inline int queue_in_packet(struct amdtp_stream *s,
struct fw_iso_packet *params)
{ {
return queue_packet(s, s->ctx_data.tx.max_ctx_payload_length); // Queue one packet for IR context.
params->header_length = s->ctx_data.tx.ctx_header_size;
params->payload_length = s->ctx_data.tx.max_ctx_payload_length;
params->skip = false;
return queue_packet(s, params);
} }
static void generate_cip_header(struct amdtp_stream *s, __be32 cip_header[2], static void generate_cip_header(struct amdtp_stream *s, __be32 cip_header[2],
...@@ -500,6 +495,7 @@ static int handle_out_packet(struct amdtp_stream *s, unsigned int cycle, ...@@ -500,6 +495,7 @@ static int handle_out_packet(struct amdtp_stream *s, unsigned int cycle,
__be32 *cip_header; __be32 *cip_header;
unsigned int pcm_frames; unsigned int pcm_frames;
struct snd_pcm_substream *pcm; struct snd_pcm_substream *pcm;
struct fw_iso_packet params = {0};
syt = calculate_syt(s, cycle); syt = calculate_syt(s, cycle);
data_blocks = calculate_data_blocks(s, syt); data_blocks = calculate_data_blocks(s, syt);
...@@ -529,7 +525,7 @@ static int handle_out_packet(struct amdtp_stream *s, unsigned int cycle, ...@@ -529,7 +525,7 @@ static int handle_out_packet(struct amdtp_stream *s, unsigned int cycle,
trace_amdtp_packet(s, cycle, cip_header, payload_length, data_blocks, trace_amdtp_packet(s, cycle, cip_header, payload_length, data_blocks,
index); index);
if (queue_out_packet(s, payload_length) < 0) if (queue_out_packet(s, &params, payload_length) < 0)
return -EIO; return -EIO;
pcm = READ_ONCE(s->pcm); pcm = READ_ONCE(s->pcm);
...@@ -651,6 +647,7 @@ static int handle_in_packet(struct amdtp_stream *s, unsigned int cycle, ...@@ -651,6 +647,7 @@ static int handle_in_packet(struct amdtp_stream *s, unsigned int cycle,
unsigned int data_blocks; unsigned int data_blocks;
struct snd_pcm_substream *pcm; struct snd_pcm_substream *pcm;
unsigned int pcm_frames; unsigned int pcm_frames;
struct fw_iso_packet params = {0};
int err; int err;
payload_length = be32_to_cpu(ctx_header[0]) >> ISO_DATA_LENGTH_SHIFT; payload_length = be32_to_cpu(ctx_header[0]) >> ISO_DATA_LENGTH_SHIFT;
...@@ -684,7 +681,7 @@ static int handle_in_packet(struct amdtp_stream *s, unsigned int cycle, ...@@ -684,7 +681,7 @@ static int handle_in_packet(struct amdtp_stream *s, unsigned int cycle,
pcm_frames = s->process_data_blocks(s, buffer, data_blocks, &syt); pcm_frames = s->process_data_blocks(s, buffer, data_blocks, &syt);
end: end:
if (queue_in_packet(s) < 0) if (queue_in_packet(s, &params) < 0)
return -EIO; return -EIO;
pcm = READ_ONCE(s->pcm); pcm = READ_ONCE(s->pcm);
...@@ -920,10 +917,11 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed) ...@@ -920,10 +917,11 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
s->packet_index = 0; s->packet_index = 0;
do { do {
struct fw_iso_packet params;
if (s->direction == AMDTP_IN_STREAM) if (s->direction == AMDTP_IN_STREAM)
err = queue_in_packet(s); err = queue_in_packet(s, &params);
else else
err = queue_out_packet(s, 0); err = queue_out_packet(s, &params, 0);
if (err < 0) if (err < 0)
goto err_context; goto err_context;
} while (s->packet_index > 0); } while (s->packet_index > 0);
......
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