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: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
index b11a8d2..e813d31 100644
--- a/sound/firewire/amdtp-stream.c
+++ b/sound/firewire/amdtp-stream.c
@@ -430,30 +430,15 @@
 		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 = 0;
+	int err;
 
-	if (IS_ERR(s->context))
-		goto end;
+	params->interrupt = IS_ALIGNED(s->packet_index + 1, INTERRUPT_INTERVAL);
+	params->tag = s->tag;
+	params->sy = 0;
 
-	p.interrupt = IS_ALIGNED(s->packet_index + 1, INTERRUPT_INTERVAL);
-	p.tag = s->tag;
-
-	if (s->direction == AMDTP_IN_STREAM) {
-		// Queue one packet for IR context.
-		p.header_length = s->ctx_data.tx.ctx_header_size;
-	} else {
-		// No header for this packet.
-		p.header_length = 0;
-	}
-
-	if (payload_length > 0)
-		p.payload_length = payload_length;
-	else
-		p.skip = true;
-	err = fw_iso_context_queue(s->context, &p, &s->buffer.iso_buffer,
+	err = fw_iso_context_queue(s->context, params, &s->buffer.iso_buffer,
 				   s->buffer.packets[s->packet_index].offset);
 	if (err < 0) {
 		dev_err(&s->unit->device, "queueing error: %d\n", err);
@@ -467,14 +452,24 @@
 }
 
 static inline int queue_out_packet(struct amdtp_stream *s,
+				   struct fw_iso_packet *params,
 				   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],
@@ -500,6 +495,7 @@
 	__be32 *cip_header;
 	unsigned int pcm_frames;
 	struct snd_pcm_substream *pcm;
+	struct fw_iso_packet params = {0};
 
 	syt = calculate_syt(s, cycle);
 	data_blocks = calculate_data_blocks(s, syt);
@@ -529,7 +525,7 @@
 	trace_amdtp_packet(s, cycle, cip_header, payload_length, data_blocks,
 			   index);
 
-	if (queue_out_packet(s, payload_length) < 0)
+	if (queue_out_packet(s, &params, payload_length) < 0)
 		return -EIO;
 
 	pcm = READ_ONCE(s->pcm);
@@ -651,6 +647,7 @@
 	unsigned int data_blocks;
 	struct snd_pcm_substream *pcm;
 	unsigned int pcm_frames;
+	struct fw_iso_packet params = {0};
 	int err;
 
 	payload_length = be32_to_cpu(ctx_header[0]) >> ISO_DATA_LENGTH_SHIFT;
@@ -684,7 +681,7 @@
 
 	pcm_frames = s->process_data_blocks(s, buffer, data_blocks, &syt);
 end:
-	if (queue_in_packet(s) < 0)
+	if (queue_in_packet(s, &params) < 0)
 		return -EIO;
 
 	pcm = READ_ONCE(s->pcm);
@@ -920,10 +917,11 @@
 
 	s->packet_index = 0;
 	do {
+		struct fw_iso_packet params;
 		if (s->direction == AMDTP_IN_STREAM)
-			err = queue_in_packet(s);
+			err = queue_in_packet(s, &params);
 		else
-			err = queue_out_packet(s, 0);
+			err = queue_out_packet(s, &params, 0);
 		if (err < 0)
 			goto err_context;
 	} while (s->packet_index > 0);