Skip to contentSkip to conversation

Enhancement of support for Firewire devices

GIT PULL In review Takashi Iwai 3 participants 75 messages Mar 5, 2014 – Mar 14, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

At Wed, 05 Mar 2014 12:13:03 +0900,

Quoted 6 lines · Takashi Sakamoto

This pull-request is an update for my previous pull-request:
[alsa-devel] [GIT PULL][PATCH 00/39] Enhancement of support for Firewire devices
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-February/073446.html

Quoted 14 lines

Updates since previous pull-request:
firewire-lib:
- use swap() instead of local macro
- check NULL at memory allocation for sort table
fireworks:
- use bitmap.h for card slots
- add 'firewire' subdirectory for card node in procfs
- add sanity check of module parameter with clamp()
bebob:
- use bitmap.h for card slots
- add 'firewire' subdirectory for card node in procfs
- simplify codes for metering
- use swap() instead of local macro
- change order of last two commits

Could you submit v2 patches to ML? The patches need review, and I want get them acked by Clemens before applying.

thanks,

Takashi

Quoted 125 lines

----------------------------------------------------------------
The following changes since commit 31278997add61ee13b709e274934c7b0085accce:

ALSA: hda/realtek - Add headset quirk for Dell DT (2014-03-03 10:48:55
+0100)

are available in the git repository at:

https://github.com/takaswie/sound.git request

for you to fetch changes up to 5b354e20ec3c64fa0a8fa7fbc7355201d881a8cc:

bebob: Send a cue to load firmware for M-Audio Firewire series
(2014-03-05 12:00:32 +0900)

----------------------------------------------------------------
Takashi Sakamoto (39):
firewire-lib: Rename functions, structure, member for AMDTP
firewire-lib: Add macros instead of fixed value for AMDTP
firewire-lib: Add 'direction' member to 'amdtp_stream' structure
firewire-lib: Split some codes into functions to reuse for both
streams
firewire-lib: Add support for AMDTP in-stream and PCM capture
firewire-lib: Add support for MIDI capture/playback
firewire-lib: Give syt value as parameter to handle_out_packet()
firewire-lib: Add support for duplex streams synchronization in
blocking mode
firewire-lib: Add sort function for transmitted packet
firewire-lib: Add transfer delay to synchronized duplex streams
firewire-lib: Add support for channel mapping
firewire-lib: Rename macros, variables and functions for CMP
firewire-lib: Add 'direction' member to 'cmp_connection' structure
firewire-lib: Add handling output connection by CMP
firewire-lib: Add a new function to check others' connection
firewire-lib: Add some AV/C general commands
firewire-lib: Add quirks for Fireworks
firewire-lib: Add a fallback at RCODE_CANCELLED
fireworks: Add skelton for Fireworks based devices
fireworks: Add transaction and some commands
fireworks: Add connection and stream management
fireworks: Add proc interface for debugging purpose
fireworks: Add MIDI interface
fireworks: Add PCM interface
fireworks: Add hwdep interface
fireworks: Add command/response functionality into hwdep interface
bebob: Add skelton for BeBoB based devices
bebob: Add commands and connections/streams management
bebob: Add proc interface for debugging purpose
bebob: Add MIDI interface
bebob: Add PCM interface
bebob: Add hwdep interface
bebob: Prepare for device specific operations
bebob: Add support for Terratec PHASE, EWS series and Aureon
bebob: Add support for Yamaha GO series
bebob: Add support for Focusrite Saffire/SaffirePro series
bebob: Add support for M-Audio usual Firewire series
bebob: Add support for M-Audio special Firewire series
bebob: Send a cue to load firmware for M-Audio Firewire series

 include/uapi/sound/asound.h                      |   4 +-
 include/uapi/sound/firewire.h                    |  22 +-
 sound/firewire/Kconfig                           |  59 ++
 sound/firewire/Makefile                          |   2 +
 sound/firewire/amdtp.c                           | 891
+++++++++++++++++------
 sound/firewire/amdtp.h                           | 175 ++++-
 sound/firewire/bebob/Makefile                    |   4 +
 sound/firewire/bebob/bebob.c                     | 450 ++++++++++++
 sound/firewire/bebob/bebob.h                     | 260 +++++++
 sound/firewire/bebob/bebob_command.c             | 354 +++++++++
 sound/firewire/bebob/bebob_focusrite.c           | 287 ++++++++
 sound/firewire/bebob/bebob_hwdep.c               | 197 +++++
 sound/firewire/bebob/bebob_maudio.c              | 828
+++++++++++++++++++++
 sound/firewire/bebob/bebob_midi.c                | 170 +++++
 sound/firewire/bebob/bebob_pcm.c                 | 451 ++++++++++++
 sound/firewire/bebob/bebob_proc.c                | 201 +++++
 sound/firewire/bebob/bebob_stream.c              | 869
++++++++++++++++++++++
 sound/firewire/bebob/bebob_terratec.c            |  68 ++
 sound/firewire/bebob/bebob_yamaha.c              |  50 ++
 sound/firewire/cmp.c                             | 229 ++++--
 sound/firewire/cmp.h                             |  14 +-
 sound/firewire/dice.c                            |  46 +-
 sound/firewire/fcp.c                             | 160 +++-
 sound/firewire/fcp.h                             |  21 +
 sound/firewire/fireworks/Makefile                |   4 +
 sound/firewire/fireworks/fireworks.c             | 326 +++++++++
 sound/firewire/fireworks/fireworks.h             | 223 ++++++
 sound/firewire/fireworks/fireworks_command.c     | 397 ++++++++++
 sound/firewire/fireworks/fireworks_hwdep.c       | 294 ++++++++
 sound/firewire/fireworks/fireworks_midi.c        | 179 +++++
 sound/firewire/fireworks/fireworks_pcm.c         | 477 ++++++++++++
 sound/firewire/fireworks/fireworks_proc.c        | 233 ++++++
 sound/firewire/fireworks/fireworks_stream.c      | 337 +++++++++
 sound/firewire/fireworks/fireworks_transaction.c | 327 +++++++++
 sound/firewire/lib.c                             |   6 +-
 sound/firewire/lib.h                             |   1 +
 sound/firewire/speakers.c                        |  93 +--
 37 files changed, 8307 insertions(+), 402 deletions(-)
 create mode 100644 sound/firewire/bebob/Makefile
 create mode 100644 sound/firewire/bebob/bebob.c
 create mode 100644 sound/firewire/bebob/bebob.h
 create mode 100644 sound/firewire/bebob/bebob_command.c
 create mode 100644 sound/firewire/bebob/bebob_focusrite.c
 create mode 100644 sound/firewire/bebob/bebob_hwdep.c
 create mode 100644 sound/firewire/bebob/bebob_maudio.c
 create mode 100644 sound/firewire/bebob/bebob_midi.c
 create mode 100644 sound/firewire/bebob/bebob_pcm.c
 create mode 100644 sound/firewire/bebob/bebob_proc.c
 create mode 100644 sound/firewire/bebob/bebob_stream.c
 create mode 100644 sound/firewire/bebob/bebob_terratec.c
 create mode 100644 sound/firewire/bebob/bebob_yamaha.c
 create mode 100644 sound/firewire/fireworks/Makefile
 create mode 100644 sound/firewire/fireworks/fireworks.c
 create mode 100644 sound/firewire/fireworks/fireworks.h
 create mode 100644 sound/firewire/fireworks/fireworks_command.c
 create mode 100644 sound/firewire/fireworks/fireworks_hwdep.c
 create mode 100644 sound/firewire/fireworks/fireworks_midi.c
 create mode 100644 sound/firewire/fireworks/fireworks_pcm.c
 create mode 100644 sound/firewire/fireworks/fireworks_proc.c
 create mode 100644 sound/firewire/fireworks/fireworks_stream.c
 create mode 100644 sound/firewire/fireworks/fireworks_transaction.c
maintainer
#5 lore raw
In reply to a message not in the archive

This pull-request is an update for my previous pull-request:
[alsa-devel] [GIT PULL][PATCH 00/39] Enhancement of support for Firewire devices
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-February/073446.html

Updates since previous pull-request:
firewire-lib:
- use swap() instead of local macro
- check NULL at memory allocation for sort table
fireworks:
- use bitmap.h for card slots
- add 'firewire' subdirectory to card node in procfs
- add sanity check of module parameter with clamp()
bebob:
- use bitmap.h for card slots
- add 'firewire' subdirectory to card node in procfs
- simplify codes for metering
- use swap() instead of local macro
- change order of last two commits

----------------------------------------------------------------
The following changes since commit 31278997add61ee13b709e274934c7b0085accce:

ALSA: hda/realtek - Add headset quirk for Dell DT (2014-03-03 10:48:55 +0100)

are available in the git repository at:

https://github.com/takaswie/sound.git request

for you to fetch changes up to 5b354e20ec3c64fa0a8fa7fbc7355201d881a8cc:

bebob: Send a cue to load firmware for M-Audio Firewire series (2014-03-05 12:00:32 +0900)

----------------------------------------------------------------
Takashi Sakamoto (39):
firewire-lib: Rename functions, structure, member for AMDTP
firewire-lib: Add macros instead of fixed value for AMDTP
firewire-lib: Add 'direction' member to 'amdtp_stream' structure
firewire-lib: Split some codes into functions to reuse for both streams
firewire-lib: Add support for AMDTP in-stream and PCM capture
firewire-lib: Add support for MIDI capture/playback
firewire-lib: Give syt value as parameter to handle_out_packet()
firewire-lib: Add support for duplex streams synchronization in blocking mode
firewire-lib: Add sort function for transmitted packet
firewire-lib: Add transfer delay to synchronized duplex streams
firewire-lib: Add support for channel mapping
firewire-lib: Rename macros, variables and functions for CMP
firewire-lib: Add 'direction' member to 'cmp_connection' structure
firewire-lib: Add handling output connection by CMP
firewire-lib: Add a new function to check others' connection
firewire-lib: Add some AV/C general commands
firewire-lib: Add quirks for Fireworks
firewire-lib: Add a fallback at RCODE_CANCELLED
fireworks: Add skelton for Fireworks based devices
fireworks: Add transaction and some commands
fireworks: Add connection and stream management
fireworks: Add proc interface for debugging purpose
fireworks: Add MIDI interface
fireworks: Add PCM interface
fireworks: Add hwdep interface
fireworks: Add command/response functionality into hwdep interface
bebob: Add skelton for BeBoB based devices
bebob: Add commands and connections/streams management
bebob: Add proc interface for debugging purpose
bebob: Add MIDI interface
bebob: Add PCM interface
bebob: Add hwdep interface
bebob: Prepare for device specific operations
bebob: Add support for Terratec PHASE, EWS series and Aureon
bebob: Add support for Yamaha GO series
bebob: Add support for Focusrite Saffire/SaffirePro series
bebob: Add support for M-Audio usual Firewire series
bebob: Add support for M-Audio special Firewire series
bebob: Send a cue to load firmware for M-Audio Firewire series

 include/uapi/sound/asound.h                      |   4 +-
 include/uapi/sound/firewire.h                    |  22 +-
 sound/firewire/Kconfig                           |  59 ++
 sound/firewire/Makefile                          |   2 +
 sound/firewire/amdtp.c                           | 891 +++++++++++++++++------
 sound/firewire/amdtp.h                           | 175 ++++-
 sound/firewire/bebob/Makefile                    |   4 +
 sound/firewire/bebob/bebob.c                     | 450 ++++++++++++
 sound/firewire/bebob/bebob.h                     | 260 +++++++
 sound/firewire/bebob/bebob_command.c             | 354 +++++++++
 sound/firewire/bebob/bebob_focusrite.c           | 287 ++++++++
 sound/firewire/bebob/bebob_hwdep.c               | 197 +++++
 sound/firewire/bebob/bebob_maudio.c              | 828 +++++++++++++++++++++
 sound/firewire/bebob/bebob_midi.c                | 170 +++++
 sound/firewire/bebob/bebob_pcm.c                 | 451 ++++++++++++
 sound/firewire/bebob/bebob_proc.c                | 201 +++++
 sound/firewire/bebob/bebob_stream.c              | 869 ++++++++++++++++++++++
 sound/firewire/bebob/bebob_terratec.c            |  68 ++
 sound/firewire/bebob/bebob_yamaha.c              |  50 ++
 sound/firewire/cmp.c                             | 229 ++++--
 sound/firewire/cmp.h                             |  14 +-
 sound/firewire/dice.c                            |  46 +-
 sound/firewire/fcp.c                             | 160 +++-
 sound/firewire/fcp.h                             |  21 +
 sound/firewire/fireworks/Makefile                |   4 +
 sound/firewire/fireworks/fireworks.c             | 326 +++++++++
 sound/firewire/fireworks/fireworks.h             | 223 ++++++
 sound/firewire/fireworks/fireworks_command.c     | 397 ++++++++++
 sound/firewire/fireworks/fireworks_hwdep.c       | 294 ++++++++
 sound/firewire/fireworks/fireworks_midi.c        | 179 +++++
 sound/firewire/fireworks/fireworks_pcm.c         | 477 ++++++++++++
 sound/firewire/fireworks/fireworks_proc.c        | 233 ++++++
 sound/firewire/fireworks/fireworks_stream.c      | 337 +++++++++
 sound/firewire/fireworks/fireworks_transaction.c | 327 +++++++++
 sound/firewire/lib.c                             |   6 +-
 sound/firewire/lib.h                             |   1 +
 sound/firewire/speakers.c                        |  93 +--
 37 files changed, 8307 insertions(+), 402 deletions(-)
 create mode 100644 sound/firewire/bebob/Makefile
 create mode 100644 sound/firewire/bebob/bebob.c
 create mode 100644 sound/firewire/bebob/bebob.h
 create mode 100644 sound/firewire/bebob/bebob_command.c
 create mode 100644 sound/firewire/bebob/bebob_focusrite.c
 create mode 100644 sound/firewire/bebob/bebob_hwdep.c
 create mode 100644 sound/firewire/bebob/bebob_maudio.c
 create mode 100644 sound/firewire/bebob/bebob_midi.c
 create mode 100644 sound/firewire/bebob/bebob_pcm.c
 create mode 100644 sound/firewire/bebob/bebob_proc.c
 create mode 100644 sound/firewire/bebob/bebob_stream.c
 create mode 100644 sound/firewire/bebob/bebob_terratec.c
 create mode 100644 sound/firewire/bebob/bebob_yamaha.c
 create mode 100644 sound/firewire/fireworks/Makefile
 create mode 100644 sound/firewire/fireworks/fireworks.c
 create mode 100644 sound/firewire/fireworks/fireworks.h
 create mode 100644 sound/firewire/fireworks/fireworks_command.c
 create mode 100644 sound/firewire/fireworks/fireworks_hwdep.c
 create mode 100644 sound/firewire/fireworks/fireworks_midi.c
 create mode 100644 sound/firewire/fireworks/fireworks_pcm.c
 create mode 100644 sound/firewire/fireworks/fireworks_proc.c
 create mode 100644 sound/firewire/fireworks/fireworks_stream.c
 create mode 100644 sound/firewire/fireworks/fireworks_transaction.c
maintainer
#6 lore raw

PATCH 1/39 firewire-lib: Rename functions, structure, member for AMDTP

This patch renames some functions, structure and member to reuse them in both AMDTP in/out stream.

---
 sound/firewire/amdtp.c    | 154 +++++++++++++++++++++++-----------------------
 sound/firewire/amdtp.h    |  64 ++++++++++---------
 sound/firewire/dice.c     |  46 +++++++-------
 sound/firewire/speakers.c |  46 +++++++-------
 4 files changed, 158 insertions(+), 152 deletions(-)
sound/firewire/amdtp.c +77 -77
index 9048777..16fe858 100644
@@ -34,13 +34,13 @@
 static void pcm_period_tasklet(unsigned long data);
 
 /**
- * amdtp_out_stream_init - initialize an AMDTP output stream structure
- * @s: the AMDTP output stream to initialize
+ * amdtp_stream_init - initialize an AMDTP stream structure
+ * @s: the AMDTP stream to initialize
  * @unit: the target of the stream
  * @flags: the packet transmission method to use
  */
-int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
-			  enum cip_out_flags flags)
+int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
+		      enum cip_flags flags)
 {
 	s->unit = fw_unit_get(unit);
 	s->flags = flags;
@@ -51,19 +51,19 @@ int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
 
 	return 0;
 }
-EXPORT_SYMBOL(amdtp_out_stream_init);
+EXPORT_SYMBOL(amdtp_stream_init);
 
 /**
- * amdtp_out_stream_destroy - free stream resources
- * @s: the AMDTP output stream to destroy
+ * amdtp_stream_destroy - free stream resources
+ * @s: the AMDTP stream to destroy
  */
-void amdtp_out_stream_destroy(struct amdtp_out_stream *s)
+void amdtp_stream_destroy(struct amdtp_stream *s)
 {
-	WARN_ON(amdtp_out_stream_running(s));
+	WARN_ON(amdtp_stream_running(s));
 	mutex_destroy(&s->mutex);
 	fw_unit_put(s->unit);
 }
-EXPORT_SYMBOL(amdtp_out_stream_destroy);
+EXPORT_SYMBOL(amdtp_stream_destroy);
 
 const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = {
 	[CIP_SFC_32000]  =  8,
@@ -77,8 +77,8 @@ const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = {
 EXPORT_SYMBOL(amdtp_syt_intervals);
 
 /**
- * amdtp_out_stream_set_parameters - set stream parameters
- * @s: the AMDTP output stream to configure
+ * amdtp_stream_set_parameters - set stream parameters
+ * @s: the AMDTP stream to configure
  * @rate: the sample rate
  * @pcm_channels: the number of PCM samples in each data block, to be encoded
  *                as AM824 multi-bit linear audio
@@ -87,10 +87,10 @@ EXPORT_SYMBOL(amdtp_syt_intervals);
  * The parameters must be set before the stream is started, and must not be
  * changed while the stream is running.
  */
-void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
-				     unsigned int rate,
-				     unsigned int pcm_channels,
-				     unsigned int midi_ports)
+void amdtp_stream_set_parameters(struct amdtp_stream *s,
+				 unsigned int rate,
+				 unsigned int pcm_channels,
+				 unsigned int midi_ports)
 {
 	static const unsigned int rates[] = {
 		[CIP_SFC_32000]  =  32000,
@@ -103,7 +103,7 @@ void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
 	};
 	unsigned int sfc;
 
-	if (WARN_ON(amdtp_out_stream_running(s)))
+	if (WARN_ON(amdtp_stream_running(s)))
 		return;
 
 	for (sfc = 0; sfc < CIP_SFC_COUNT; ++sfc)
@@ -132,47 +132,47 @@ sfc_found:
 		/* additional buffering needed to adjust for no-data packets */
 		s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate;
 }
-EXPORT_SYMBOL(amdtp_out_stream_set_parameters);
+EXPORT_SYMBOL(amdtp_stream_set_parameters);
 
 /**
- * amdtp_out_stream_get_max_payload - get the stream's packet size
- * @s: the AMDTP output stream
+ * amdtp_stream_get_max_payload - get the stream's packet size
+ * @s: the AMDTP stream
  *
  * This function must not be called before the stream has been configured
- * with amdtp_out_stream_set_parameters().
+ * with amdtp_stream_set_parameters().
  */
-unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s)
+unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s)
 {
 	return 8 + s->syt_interval * s->data_block_quadlets * 4;
 }
-EXPORT_SYMBOL(amdtp_out_stream_get_max_payload);
+EXPORT_SYMBOL(amdtp_stream_get_max_payload);
 
-static void amdtp_write_s16(struct amdtp_out_stream *s,
+static void amdtp_write_s16(struct amdtp_stream *s,
 			    struct snd_pcm_substream *pcm,
 			    __be32 *buffer, unsigned int frames);
-static void amdtp_write_s32(struct amdtp_out_stream *s,
+static void amdtp_write_s32(struct amdtp_stream *s,
 			    struct snd_pcm_substream *pcm,
 			    __be32 *buffer, unsigned int frames);
-static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s,
+static void amdtp_write_s16_dualwire(struct amdtp_stream *s,
 				     struct snd_pcm_substream *pcm,
 				     __be32 *buffer, unsigned int frames);
-static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s,
+static void amdtp_write_s32_dualwire(struct amdtp_stream *s,
 				     struct snd_pcm_substream *pcm,
 				     __be32 *buffer, unsigned int frames);
 
 /**
- * amdtp_out_stream_set_pcm_format - set the PCM format
- * @s: the AMDTP output stream to configure
+ * amdtp_stream_set_pcm_format - set the PCM format
+ * @s: the AMDTP stream to configure
  * @format: the format of the ALSA PCM device
  *
  * The sample format must be set after the other paramters (rate/PCM channels/
  * MIDI) and before the stream is started, and must not be changed while the
  * stream is running.
  */
-void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
-				     snd_pcm_format_t format)
+void amdtp_stream_set_pcm_format(struct amdtp_stream *s,
+				 snd_pcm_format_t format)
 {
-	if (WARN_ON(amdtp_out_stream_running(s)))
+	if (WARN_ON(amdtp_stream_running(s)))
 		return;
 
 	switch (format) {
@@ -193,24 +193,24 @@ void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
 		break;
 	}
 }
-EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format);
+EXPORT_SYMBOL(amdtp_stream_set_pcm_format);
 
 /**
- * amdtp_out_stream_pcm_prepare - prepare PCM device for running
- * @s: the AMDTP output stream
+ * amdtp_stream_pcm_prepare - prepare PCM device for running
+ * @s: the AMDTP stream
  *
  * This function should be called from the PCM device's .prepare callback.
  */
-void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
+void amdtp_stream_pcm_prepare(struct amdtp_stream *s)
 {
 	tasklet_kill(&s->period_tasklet);
 	s->pcm_buffer_pointer = 0;
 	s->pcm_period_pointer = 0;
 	s->pointer_flush = true;
 }
-EXPORT_SYMBOL(amdtp_out_stream_pcm_prepare);
+EXPORT_SYMBOL(amdtp_stream_pcm_prepare);
 
-static unsigned int calculate_data_blocks(struct amdtp_out_stream *s)
+static unsigned int calculate_data_blocks(struct amdtp_stream *s)
 {
 	unsigned int phase, data_blocks;
 
@@ -243,7 +243,7 @@ static unsigned int calculate_data_blocks(struct amdtp_out_stream *s)
 	return data_blocks;
 }
 
-static unsigned int calculate_syt(struct amdtp_out_stream *s,
+static unsigned int calculate_syt(struct amdtp_stream *s,
 				  unsigned int cycle)
 {
 	unsigned int syt_offset, phase, index, syt;
@@ -286,7 +286,7 @@ static unsigned int calculate_syt(struct amdtp_out_stream *s,
 	}
 }
 
-static void amdtp_write_s32(struct amdtp_out_stream *s,
+static void amdtp_write_s32(struct amdtp_stream *s,
 			    struct snd_pcm_substream *pcm,
 			    __be32 *buffer, unsigned int frames)
 {
@@ -312,7 +312,7 @@ static void amdtp_write_s32(struct amdtp_out_stream *s,
 	}
 }
 
-static void amdtp_write_s16(struct amdtp_out_stream *s,
+static void amdtp_write_s16(struct amdtp_stream *s,
 			    struct snd_pcm_substream *pcm,
 			    __be32 *buffer, unsigned int frames)
 {
@@ -338,7 +338,7 @@ static void amdtp_write_s16(struct amdtp_out_stream *s,
 	}
 }
 
-static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s,
+static void amdtp_write_s32_dualwire(struct amdtp_stream *s,
 				     struct snd_pcm_substream *pcm,
 				     __be32 *buffer, unsigned int frames)
 {
@@ -369,7 +369,7 @@ static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s,
 	}
 }
 
-static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s,
+static void amdtp_write_s16_dualwire(struct amdtp_stream *s,
 				     struct snd_pcm_substream *pcm,
 				     __be32 *buffer, unsigned int frames)
 {
@@ -400,7 +400,7 @@ static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s,
 	}
 }
 
-static void amdtp_fill_pcm_silence(struct amdtp_out_stream *s,
+static void amdtp_fill_pcm_silence(struct amdtp_stream *s,
 				   __be32 *buffer, unsigned int frames)
 {
 	unsigned int i, c;
@@ -412,7 +412,7 @@ static void amdtp_fill_pcm_silence(struct amdtp_out_stream *s,
 	}
 }
 
-static void amdtp_fill_midi(struct amdtp_out_stream *s,
+static void amdtp_fill_midi(struct amdtp_stream *s,
 			    __be32 *buffer, unsigned int frames)
 {
 	unsigned int i;
@@ -422,7 +422,7 @@ static void amdtp_fill_midi(struct amdtp_out_stream *s,
 						cpu_to_be32(0x80000000);
 }
 
-static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
+static void queue_out_packet(struct amdtp_stream *s, unsigned int cycle)
 {
 	__be32 *buffer;
 	unsigned int index, data_blocks, syt, ptr;
@@ -473,7 +473,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
 	if (err < 0) {
 		dev_err(&s->unit->device, "queueing error: %d\n", err);
 		s->packet_index = -1;
-		amdtp_out_stream_pcm_abort(s);
+		amdtp_stream_pcm_abort(s);
 		return;
 	}
 
@@ -501,7 +501,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
 
 static void pcm_period_tasklet(unsigned long data)
 {
-	struct amdtp_out_stream *s = (void *)data;
+	struct amdtp_stream *s = (void *)data;
 	struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm);
 
 	if (pcm)
@@ -509,9 +509,9 @@ static void pcm_period_tasklet(unsigned long data)
 }
 
 static void out_packet_callback(struct fw_iso_context *context, u32 cycle,
-				size_t header_length, void *header, void *data)
+			size_t header_length, void *header, void *private_data)
 {
-	struct amdtp_out_stream *s = data;
+	struct amdtp_stream *s = private_data;
 	unsigned int i, packets = header_length / 4;
 
 	/*
@@ -526,7 +526,7 @@ static void out_packet_callback(struct fw_iso_context *context, u32 cycle,
 	fw_iso_context_queue_flush(s->context);
 }
 
-static int queue_initial_skip_packets(struct amdtp_out_stream *s)
+static int queue_initial_skip_packets(struct amdtp_stream *s)
 {
 	struct fw_iso_packet skip_packet = {
 		.skip = 1,
@@ -548,16 +548,16 @@ static int queue_initial_skip_packets(struct amdtp_out_stream *s)
 }
 
 /**
- * amdtp_out_stream_start - start sending packets
- * @s: the AMDTP output stream to start
+ * amdtp_stream_start - start transferring packets
+ * @s: the AMDTP stream to start
  * @channel: the isochronous channel on the bus
  * @speed: firewire speed code
  *
  * The stream cannot be started until it has been configured with
- * amdtp_out_stream_set_parameters() and amdtp_out_stream_set_pcm_format(),
- * and it must be started before any PCM or MIDI device can be started.
+ * amdtp_stream_set_parameters() and it must be started before any PCM or MIDI
+ * device can be started.
  */
-int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
+int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 {
 	static const struct {
 		unsigned int data_block;
@@ -575,7 +575,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
 
 	mutex_lock(&s->mutex);
 
-	if (WARN_ON(amdtp_out_stream_running(s) ||
+	if (WARN_ON(amdtp_stream_running(s) ||
 		    (!s->pcm_channels && !s->midi_ports))) {
 		err = -EBADFD;
 		goto err_unlock;
@@ -586,7 +586,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
 	s->last_syt_offset = TICKS_PER_CYCLE;
 
 	err = iso_packets_buffer_init(&s->buffer, s->unit, QUEUE_LENGTH,
-				      amdtp_out_stream_get_max_payload(s),
+				      amdtp_stream_get_max_payload(s),
 				      DMA_TO_DEVICE);
 	if (err < 0)
 		goto err_unlock;
@@ -599,11 +599,11 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
 		err = PTR_ERR(s->context);
 		if (err == -EBUSY)
 			dev_err(&s->unit->device,
-				"no free output stream on this controller\n");
+				"no free stream on this controller\n");
 		goto err_buffer;
 	}
 
-	amdtp_out_stream_update(s);
+	amdtp_stream_update(s);
 
 	s->packet_index = 0;
 	s->data_block_counter = 0;
@@ -629,15 +629,15 @@ err_unlock:
 
 	return err;
 }
-EXPORT_SYMBOL(amdtp_out_stream_start);
+EXPORT_SYMBOL(amdtp_stream_start);
 
 /**
- * amdtp_out_stream_pcm_pointer - get the PCM buffer position
- * @s: the AMDTP output stream that transports the PCM data
+ * amdtp_stream_pcm_pointer - get the PCM buffer position
+ * @s: the AMDTP stream that transports the PCM data
  *
  * Returns the current buffer position, in frames.
  */
-unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s)
+unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s)
 {
 	/* this optimization is allowed to be racy */
 	if (s->pointer_flush)
@@ -647,31 +647,31 @@ unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s)
 
 	return ACCESS_ONCE(s->pcm_buffer_pointer);
 }
-EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
+EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
 
 /**
- * amdtp_out_stream_update - update the stream after a bus reset
- * @s: the AMDTP output stream
+ * amdtp_stream_update - update the stream after a bus reset
+ * @s: the AMDTP stream
  */
-void amdtp_out_stream_update(struct amdtp_out_stream *s)
+void amdtp_stream_update(struct amdtp_stream *s)
 {
 	ACCESS_ONCE(s->source_node_id_field) =
 		(fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
 }
-EXPORT_SYMBOL(amdtp_out_stream_update);
+EXPORT_SYMBOL(amdtp_stream_update);
 
 /**
- * amdtp_out_stream_stop - stop sending packets
- * @s: the AMDTP output stream to stop
+ * amdtp_stream_stop - stop sending packets
+ * @s: the AMDTP stream to stop
  *
  * All PCM and MIDI devices of the stream must be stopped before the stream
  * itself can be stopped.
  */
-void amdtp_out_stream_stop(struct amdtp_out_stream *s)
+void amdtp_stream_stop(struct amdtp_stream *s)
 {
 	mutex_lock(&s->mutex);
 
-	if (!amdtp_out_stream_running(s)) {
+	if (!amdtp_stream_running(s)) {
 		mutex_unlock(&s->mutex);
 		return;
 	}
@@ -684,16 +684,16 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s)
 
 	mutex_unlock(&s->mutex);
 }
-EXPORT_SYMBOL(amdtp_out_stream_stop);
+EXPORT_SYMBOL(amdtp_stream_stop);
 
 /**
- * amdtp_out_stream_pcm_abort - abort the running PCM device
+ * amdtp_stream_pcm_abort - abort the running PCM device
  * @s: the AMDTP stream about to be stopped
  *
  * If the isochronous stream needs to be stopped asynchronously, call this
  * function first to stop the PCM device.
  */
-void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s)
+void amdtp_stream_pcm_abort(struct amdtp_stream *s)
 {
 	struct snd_pcm_substream *pcm;
 
@@ -705,4 +705,4 @@ void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s)
 		snd_pcm_stream_unlock_irq(pcm);
 	}
 }
-EXPORT_SYMBOL(amdtp_out_stream_pcm_abort);
+EXPORT_SYMBOL(amdtp_stream_pcm_abort);
sound/firewire/amdtp.h +35 -29

121 lines not on this page · raw message

sound/firewire/dice.c +23 -23

132 lines not on this page · raw message

sound/firewire/speakers.c +23 -23

125 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#7 lore raw

PATCH 2/39 firewire-lib: Add macros instead of fixed value for AMDTP

In reply to Takashi Sakamoto

This patch adds some macros instead of fixed value for AMDTP in IEC 61883-6. These macros will also be used by followed patches.

---
 sound/firewire/amdtp.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
sound/firewire/amdtp.c +23 -7
index 16fe858..38013f9 100644
@@ -20,12 +20,28 @@
 
 #define TRANSFER_DELAY_TICKS	0x2e00 /* 479.17 µs */
 
+/* isochronous header parameters */
+#define ISO_DATA_LENGTH_SHIFT	16
 #define TAG_CIP			1
 
+/* common isochronous packet header parameters */
 #define CIP_EOH			(1u << 31)
+#define CIP_EOH_MASK		0x80000000
 #define CIP_FMT_AM		(0x10 << 24)
-#define AMDTP_FDF_AM824		(0 << 19)
-#define AMDTP_FDF_SFC_SHIFT	16
+#define CIP_FMT_MASK		0x3f000000
+#define CIP_SYT_MASK		0x0000ffff
+#define CIP_SYT_NO_INFO		0xffff
+#define CIP_FDF_MASK		0x00ff0000
+#define CIP_FDF_SFC_SHIFT	16
+
+/*
+ * Audio and Music transfer protocol specific parameters
+ * only "Clock-based rate control mode" is supported
+ */
+#define AMDTP_FDF_AM824		(0 << (CIP_FDF_SFC_SHIFT + 3))
+#define AMDTP_DBS_MASK		0x00ff0000
+#define AMDTP_DBS_SHIFT		16
+#define AMDTP_DBC_MASK		0x000000ff
 
 /* TODO: make these configurable */
 #define INTERRUPT_INTERVAL	16
@@ -280,9 +296,9 @@ static unsigned int calculate_syt(struct amdtp_stream *s,
 		syt = (cycle + syt_offset / TICKS_PER_CYCLE) << 12;
 		syt += syt_offset % TICKS_PER_CYCLE;
 
-		return syt & 0xffff;
+		return syt & CIP_SYT_MASK;
 	} else {
-		return 0xffff; /* no info */
+		return CIP_SYT_NO_INFO;
 	}
 }
 
@@ -438,17 +454,17 @@ static void queue_out_packet(struct amdtp_stream *s, unsigned int cycle)
 	syt = calculate_syt(s, cycle);
 	if (!(s->flags & CIP_BLOCKING))
 		data_blocks = calculate_data_blocks(s);
-	else if (syt != 0xffff)
+	else if (syt != CIP_SYT_NO_INFO)
 		data_blocks = s->syt_interval;
 	else
 		data_blocks = 0;
 
 	buffer = s->buffer.packets[index].buffer;
 	buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
-				(s->data_block_quadlets << 16) |
+				(s->data_block_quadlets << AMDTP_DBS_SHIFT) |
 				s->data_block_counter);
 	buffer[1] = cpu_to_be32(CIP_EOH | CIP_FMT_AM | AMDTP_FDF_AM824 |
-				(s->sfc << AMDTP_FDF_SFC_SHIFT) | syt);
+				(s->sfc << CIP_FDF_SFC_SHIFT) | syt);
 	buffer += 2;
 
 	pcm = ACCESS_ONCE(s->pcm);
Signature · 6 lines
1.8.3.2

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#8 lore raw

PATCH 3/39 firewire-lib: Add 'direction' member to 'amdtp_stream' structure

In reply to Takashi Sakamoto

This patch adds 'direction' member to amdtp_stream structure to indicate its direction. This patch also adds 'direction' argument to amdtp_stream_init() function to determine its direction.

The amdtp_stream_init() function is exported and used by firewire-speakers and dice so this patch also affects them.

This patch just add them. Actual implementation will be done by followed patches.

---
 sound/firewire/amdtp.c    | 4 +++-
 sound/firewire/amdtp.h    | 7 +++++++
 sound/firewire/dice.c     | 2 +-
 sound/firewire/speakers.c | 3 ++-
 4 files changed, 13 insertions(+), 3 deletions(-)
sound/firewire/amdtp.c +3 -1
index 38013f9..95c5a15 100644
@@ -53,12 +53,14 @@ static void pcm_period_tasklet(unsigned long data);
  * amdtp_stream_init - initialize an AMDTP stream structure
  * @s: the AMDTP stream to initialize
  * @unit: the target of the stream
+ * @dir: the direction of stream
  * @flags: the packet transmission method to use
  */
 int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
-		      enum cip_flags flags)
+		      enum amdtp_stream_direction dir, enum cip_flags flags)
 {
 	s->unit = fw_unit_get(unit);
+	s->direction = dir;
 	s->flags = flags;
 	s->context = ERR_PTR(-1);
 	mutex_init(&s->mutex);
sound/firewire/amdtp.h +7 -0
index 60028c7..019134e 100644
@@ -48,9 +48,15 @@ struct fw_unit;
 struct fw_iso_context;
 struct snd_pcm_substream;
 
+enum amdtp_stream_direction {
+	AMDTP_OUT_STREAM = 0,
+	AMDTP_IN_STREAM
+};
+
 struct amdtp_stream {
 	struct fw_unit *unit;
 	enum cip_flags flags;
+	enum amdtp_stream_direction direction;
 	struct fw_iso_context *context;
 	struct mutex mutex;
 
@@ -85,6 +91,7 @@ struct amdtp_stream {
 };
 
 int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
+		      enum amdtp_stream_direction dir,
 		      enum cip_flags flags);
 void amdtp_stream_destroy(struct amdtp_stream *s);
 
sound/firewire/dice.c +1 -1
index ca12fcb..26b2158 100644
@@ -1360,7 +1360,7 @@ static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
 		goto err_owner;
 	dice->resources.channels_mask = 0x00000000ffffffffuLL;
 
-	err = amdtp_stream_init(&dice->stream, unit,
+	err = amdtp_stream_init(&dice->stream, unit, AMDTP_OUT_STREAM,
 				CIP_BLOCKING | CIP_HI_DUALWIRE);
 	if (err < 0)
 		goto err_resources;
sound/firewire/speakers.c +2 -1
index 2096ad7..c07e7cd 100644
@@ -683,7 +683,8 @@ static int fwspk_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto err_unit;
 
-	err = amdtp_stream_init(&fwspk->stream, unit, CIP_NONBLOCKING);
+	err = amdtp_stream_init(&fwspk->stream, unit, AMDTP_OUT_STREAM,
+				CIP_NONBLOCKING);
 	if (err < 0)
 		goto err_connection;
 
Signature · 1 line
1.8.3.2
maintainer
#9 lore raw

PATCH 4/39 firewire-lib: Split some codes into functions to reuse for both streams

In reply to Takashi Sakamoto

Some codes can be reused to handle in stream. This commit adds new functions. This commit also renames some functions to keep naming consistency.

---
 sound/firewire/amdtp.c | 156 ++++++++++++++++++++++++++-----------------------
 1 file changed, 82 insertions(+), 74 deletions(-)
sound/firewire/amdtp.c +82 -74
index 95c5a15..ca79cb4 100644
@@ -47,6 +47,8 @@
 #define INTERRUPT_INTERVAL	16
 #define QUEUE_LENGTH		48
 
+#define OUT_PACKET_HEADER_SIZE	0
+
 static void pcm_period_tasklet(unsigned long data);
 
 /**
@@ -440,13 +442,74 @@ static void amdtp_fill_midi(struct amdtp_stream *s,
 						cpu_to_be32(0x80000000);
 }
 
-static void queue_out_packet(struct amdtp_stream *s, unsigned int cycle)
+static void update_pcm_pointers(struct amdtp_stream *s,
+				struct snd_pcm_substream *pcm,
+				unsigned int frames)
+{	unsigned int ptr;
+
+	if (s->dual_wire)
+		frames *= 2;
+
+	ptr = s->pcm_buffer_pointer + frames;
+	if (ptr >= pcm->runtime->buffer_size)
+		ptr -= pcm->runtime->buffer_size;
+	ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
+
+	s->pcm_period_pointer += frames;
+	if (s->pcm_period_pointer >= pcm->runtime->period_size) {
+		s->pcm_period_pointer -= pcm->runtime->period_size;
+		s->pointer_flush = false;
+		tasklet_hi_schedule(&s->period_tasklet);
+	}
+}
+
+static void pcm_period_tasklet(unsigned long data)
+{
+	struct amdtp_stream *s = (void *)data;
+	struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm);
+
+	if (pcm)
+		snd_pcm_period_elapsed(pcm);
+}
+
+static int queue_packet(struct amdtp_stream *s,
+			unsigned int header_length,
+			unsigned int payload_length, bool skip)
+{
+	struct fw_iso_packet p = {0};
+	int err;
+
+	p.interrupt = IS_ALIGNED(s->packet_index + 1, INTERRUPT_INTERVAL);
+	p.tag = TAG_CIP;
+	p.header_length = header_length;
+	p.payload_length = (!skip) ? payload_length : 0;
+	p.skip = skip;
+	err = fw_iso_context_queue(s->context, &p, &s->buffer.iso_buffer,
+				   s->buffer.packets[s->packet_index].offset);
+	if (err < 0) {
+		dev_err(&s->unit->device, "queueing error: %d\n", err);
+		s->packet_index = -1;
+		goto end;
+	}
+
+	if (++s->packet_index >= QUEUE_LENGTH)
+		s->packet_index = 0;
+end:
+	return err;
+}
+
+static inline int queue_out_packet(struct amdtp_stream *s,
+				   unsigned int payload_length, bool skip)
+{
+	return queue_packet(s, OUT_PACKET_HEADER_SIZE,
+			    payload_length, skip);
+}
+
+static void handle_out_packet(struct amdtp_stream *s, unsigned int cycle)
 {
 	__be32 *buffer;
-	unsigned int index, data_blocks, syt, ptr;
+	unsigned int index, data_blocks, syt, payload_length;
 	struct snd_pcm_substream *pcm;
-	struct fw_iso_packet packet;
-	int err;
 
 	if (s->packet_index < 0)
 		return;
@@ -479,55 +542,19 @@ static void queue_out_packet(struct amdtp_stream *s, unsigned int cycle)
 
 	s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;
 
-	packet.payload_length = 8 + data_blocks * 4 * s->data_block_quadlets;
-	packet.interrupt = IS_ALIGNED(index + 1, INTERRUPT_INTERVAL);
-	packet.skip = 0;
-	packet.tag = TAG_CIP;
-	packet.sy = 0;
-	packet.header_length = 0;
-
-	err = fw_iso_context_queue(s->context, &packet, &s->buffer.iso_buffer,
-				   s->buffer.packets[index].offset);
-	if (err < 0) {
-		dev_err(&s->unit->device, "queueing error: %d\n", err);
-		s->packet_index = -1;
+	payload_length = 8 + data_blocks * 4 * s->data_block_quadlets;
+	if (queue_out_packet(s, payload_length, false) < 0) {
 		amdtp_stream_pcm_abort(s);
 		return;
 	}
 
-	if (++index >= QUEUE_LENGTH)
-		index = 0;
-	s->packet_index = index;
-
-	if (pcm) {
-		if (s->dual_wire)
-			data_blocks *= 2;
-
-		ptr = s->pcm_buffer_pointer + data_blocks;
-		if (ptr >= pcm->runtime->buffer_size)
-			ptr -= pcm->runtime->buffer_size;
-		ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
-
-		s->pcm_period_pointer += data_blocks;
-		if (s->pcm_period_pointer >= pcm->runtime->period_size) {
-			s->pcm_period_pointer -= pcm->runtime->period_size;
-			s->pointer_flush = false;
-			tasklet_hi_schedule(&s->period_tasklet);
-		}
-	}
-}
-
-static void pcm_period_tasklet(unsigned long data)
-{
-	struct amdtp_stream *s = (void *)data;
-	struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm);
-
 	if (pcm)
-		snd_pcm_period_elapsed(pcm);
+		update_pcm_pointers(s, pcm, data_blocks);
 }
 
-static void out_packet_callback(struct fw_iso_context *context, u32 cycle,
-			size_t header_length, void *header, void *private_data)
+static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
+				size_t header_length, void *header,
+				void *private_data)
 {
 	struct amdtp_stream *s = private_data;
 	unsigned int i, packets = header_length / 4;
@@ -540,31 +567,10 @@ static void out_packet_callback(struct fw_iso_context *context, u32 cycle,
 	cycle += QUEUE_LENGTH - packets;
 
 	for (i = 0; i < packets; ++i)
-		queue_out_packet(s, ++cycle);
+		handle_out_packet(s, ++cycle);
 	fw_iso_context_queue_flush(s->context);
 }
 
-static int queue_initial_skip_packets(struct amdtp_stream *s)
-{
-	struct fw_iso_packet skip_packet = {
-		.skip = 1,
-	};
-	unsigned int i;
-	int err;
-
-	for (i = 0; i < QUEUE_LENGTH; ++i) {
-		skip_packet.interrupt = IS_ALIGNED(s->packet_index + 1,
-						   INTERRUPT_INTERVAL);
-		err = fw_iso_context_queue(s->context, &skip_packet, NULL, 0);
-		if (err < 0)
-			return err;
-		if (++s->packet_index >= QUEUE_LENGTH)
-			s->packet_index = 0;
-	}
-
-	return 0;
-}
-
 /**
  * amdtp_stream_start - start transferring packets
  * @s: the AMDTP stream to start
@@ -594,7 +600,7 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 	mutex_lock(&s->mutex);
 
 	if (WARN_ON(amdtp_stream_running(s) ||
-		    (!s->pcm_channels && !s->midi_ports))) {
+		    (s->data_block_quadlets < 1))) {
 		err = -EBADFD;
 		goto err_unlock;
 	}
@@ -612,7 +618,7 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 	s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,
 					   FW_ISO_CONTEXT_TRANSMIT,
 					   channel, speed, 0,
-					   out_packet_callback, s);
+					   out_stream_callback, s);
 	if (IS_ERR(s->context)) {
 		err = PTR_ERR(s->context);
 		if (err == -EBUSY)
@@ -624,11 +630,13 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 	amdtp_stream_update(s);
 
 	s->packet_index = 0;
-	s->data_block_counter = 0;
-	err = queue_initial_skip_packets(s);
-	if (err < 0)
-		goto err_context;
+	do {
+		err = queue_out_packet(s, 0, true);
+		if (err < 0)
+			goto err_context;
+	} while (s->packet_index > 0);
 
+	s->data_block_counter = 0;
 	err = fw_iso_context_start(s->context, -1, 0, 0);
 	if (err < 0)
 		goto err_context;
Signature · 1 line
1.8.3.2
maintainer
#10 lore raw

PATCH 5/39 firewire-lib: Add support for AMDTP in-stream and PCM capture

In reply to Takashi Sakamoto

For capturing PCM, this commit adds the functionality to handle in-stream. This is also applied for dual-wire mode.

Currently, capturing 32bit samples are supported.

---
 sound/firewire/amdtp.c | 218 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 201 insertions(+), 17 deletions(-)
sound/firewire/amdtp.c +201 -17
index ca79cb4..4ebfd67 100644
@@ -39,6 +39,7 @@
  * only "Clock-based rate control mode" is supported
  */
 #define AMDTP_FDF_AM824		(0 << (CIP_FDF_SFC_SHIFT + 3))
+#define AMDTP_FDF_NO_DATA	0xff
 #define AMDTP_DBS_MASK		0x00ff0000
 #define AMDTP_DBS_SHIFT		16
 #define AMDTP_DBC_MASK		0x000000ff
@@ -47,6 +48,7 @@
 #define INTERRUPT_INTERVAL	16
 #define QUEUE_LENGTH		48
 
+#define IN_PACKET_HEADER_SIZE	4
 #define OUT_PACKET_HEADER_SIZE	0
 
 static void pcm_period_tasklet(unsigned long data);
@@ -179,6 +181,12 @@ static void amdtp_write_s16_dualwire(struct amdtp_stream *s,
 static void amdtp_write_s32_dualwire(struct amdtp_stream *s,
 				     struct snd_pcm_substream *pcm,
 				     __be32 *buffer, unsigned int frames);
+static void amdtp_read_s32(struct amdtp_stream *s,
+			   struct snd_pcm_substream *pcm,
+			   __be32 *buffer, unsigned int frames);
+static void amdtp_read_s32_dualwire(struct amdtp_stream *s,
+				    struct snd_pcm_substream *pcm,
+				    __be32 *buffer, unsigned int frames);
 
 /**
  * amdtp_stream_set_pcm_format - set the PCM format
@@ -200,16 +208,26 @@ void amdtp_stream_set_pcm_format(struct amdtp_stream *s,
 		WARN_ON(1);
 		/* fall through */
 	case SNDRV_PCM_FORMAT_S16:
-		if (s->dual_wire)
-			s->transfer_samples = amdtp_write_s16_dualwire;
-		else
-			s->transfer_samples = amdtp_write_s16;
-		break;
+		if (s->direction == AMDTP_OUT_STREAM) {
+			if (s->dual_wire)
+				s->transfer_samples = amdtp_write_s16_dualwire;
+			else
+				s->transfer_samples = amdtp_write_s16;
+			break;
+		}
+		WARN_ON(1);
+		/* fall through */
 	case SNDRV_PCM_FORMAT_S32:
-		if (s->dual_wire)
-			s->transfer_samples = amdtp_write_s32_dualwire;
-		else
-			s->transfer_samples = amdtp_write_s32;
+		if (s->direction == AMDTP_OUT_STREAM) {
+			if (s->dual_wire)
+				s->transfer_samples = amdtp_write_s32_dualwire;
+			else
+				s->transfer_samples = amdtp_write_s32;
+		} else if (s->dual_wire) {
+			s->transfer_samples = amdtp_read_s32_dualwire;
+		} else {
+			s->transfer_samples = amdtp_read_s32;
+		}
 		break;
 	}
 }
@@ -420,6 +438,58 @@ static void amdtp_write_s16_dualwire(struct amdtp_stream *s,
 	}
 }
 
+static void amdtp_read_s32(struct amdtp_stream *s,
+			   struct snd_pcm_substream *pcm,
+			   __be32 *buffer, unsigned int frames)
+{
+	struct snd_pcm_runtime *runtime = pcm->runtime;
+	unsigned int remaining_frames, i, c;
+	u32 *dst;
+
+	dst  = (void *)runtime->dma_area +
+			frames_to_bytes(runtime, s->pcm_buffer_pointer);
+	remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
+
+	for (i = 0; i < frames; ++i) {
+		for (c = 0; c < s->pcm_channels; ++c) {
+			*dst = be32_to_cpu(buffer[c]) << 8;
+			dst++;
+		}
+		buffer += s->data_block_quadlets;
+		if (--remaining_frames == 0)
+			dst = (void *)runtime->dma_area;
+	}
+}
+
+static void amdtp_read_s32_dualwire(struct amdtp_stream *s,
+				    struct snd_pcm_substream *pcm,
+				    __be32 *buffer, unsigned int frames)
+{
+	struct snd_pcm_runtime *runtime = pcm->runtime;
+	unsigned int channels, remaining_frames, i, c;
+	u32 *dst;
+
+	dst = (void *)runtime->dma_area +
+			frames_to_bytes(runtime, s->pcm_buffer_pointer);
+	remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
+	channels = s->pcm_channels / 2;
+
+	for (i = 0; i < frames; ++i) {
+		for (c = 0; c < channels; ++c) {
+			*dst = be32_to_cpu(buffer[c * 2]) << 8;
+			dst++;
+		}
+		buffer += 1;
+		for (c = 0; c < channels; ++c) {
+			*dst = be32_to_cpu(buffer[c * 2]) << 8;
+			dst++;
+		}
+		buffer += s->data_block_quadlets - 1;
+		if (--remaining_frames == 0)
+			dst = (void *)runtime->dma_area;
+	}
+}
+
 static void amdtp_fill_pcm_silence(struct amdtp_stream *s,
 				   __be32 *buffer, unsigned int frames)
 {
@@ -505,6 +575,12 @@ static inline int queue_out_packet(struct amdtp_stream *s,
 			    payload_length, skip);
 }
 
+static inline int queue_in_packet(struct amdtp_stream *s)
+{
+	return queue_packet(s, IN_PACKET_HEADER_SIZE,
+			    amdtp_stream_get_max_payload(s), false);
+}
+
 static void handle_out_packet(struct amdtp_stream *s, unsigned int cycle)
 {
 	__be32 *buffer;
@@ -552,6 +628,67 @@ static void handle_out_packet(struct amdtp_stream *s, unsigned int cycle)
 		update_pcm_pointers(s, pcm, data_blocks);
 }
 
+static void handle_in_packet(struct amdtp_stream *s,
+			     unsigned int payload_quadlets,
+			     __be32 *buffer)
+{
+	u32 cip_header[2];
+	unsigned int data_block_quadlets, data_blocks, data_block_counter;
+	struct snd_pcm_substream *pcm;
+
+	cip_header[0] = be32_to_cpu(buffer[0]);
+	cip_header[1] = be32_to_cpu(buffer[1]);
+
+	/*
+	 * This module supports 'Two-quadlet CIP header with SYT field'.
+	 * For convinience, also check FMT field is AM824 or not.
+	 */
+	if (((cip_header[0] & CIP_EOH_MASK) == CIP_EOH) ||
+	    ((cip_header[1] & CIP_EOH_MASK) != CIP_EOH) ||
+	    ((cip_header[1] & CIP_FMT_MASK) != CIP_FMT_AM)) {
+		dev_info_ratelimited(&s->unit->device,
+				"Invalid CIP header for AMDTP: %08X:%08X\n",
+				cip_header[0], cip_header[1]);
+		return;
+	}
+
+	/* ignore empty CIP packet or NO-DATA AMDTP packet */
+	if ((payload_quadlets < 3) ||
+	    (((cip_header[1] & CIP_FDF_MASK) >> CIP_FDF_SFC_SHIFT) ==
+							AMDTP_FDF_NO_DATA))
+		return;
+
+	data_block_quadlets =
+			(cip_header[1] & AMDTP_DBS_MASK) >> AMDTP_DBS_SHIFT;
+	/* avoid division by zero */
+	if (data_block_quadlets == 0) {
+		dev_info_ratelimited(&s->unit->device,
+				 "Detect invalid value in dbs field: %08X\n",
+				 data_block_quadlets);
+		return;
+	}
+
+	data_blocks = (payload_quadlets - 2) / data_block_quadlets;
+	data_block_counter = cip_header[1] & AMDTP_DBC_MASK;
+
+	/* check packet continuity */
+	s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;
+	if (s->data_block_counter != data_block_counter) {
+		dev_info_ratelimited(&s->unit->device,
+				     "Detect uncontinuity of CIP packets\n");
+		s->data_block_counter = data_block_counter;
+		return;
+	}
+
+	buffer += 2;
+
+	pcm = ACCESS_ONCE(s->pcm);
+	if (pcm) {
+		s->transfer_samples(s, pcm, buffer, data_blocks);
+		update_pcm_pointers(s, pcm, data_blocks);
+	}
+}
+
 static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
 				size_t header_length, void *header,
 				void *private_data)
@@ -571,6 +708,35 @@ static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
 	fw_iso_context_queue_flush(s->context);
 }
 
+static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
+			       size_t header_length, void *header,
+			       void *private_data)
+{
+	struct amdtp_stream *s = private_data;
+	unsigned int p, packets, data_quadlets;
+	__be32 *buffer, *headers = header;
+
+	/* The number of packets in buffer */
+	packets = header_length / IN_PACKET_HEADER_SIZE;
+
+	for (p = 0; p < packets; p++) {
+		buffer = s->buffer.packets[s->packet_index].buffer;
+
+		/* The number of quadlets in this packet */
+		data_quadlets =
+			(be32_to_cpu(headers[p]) >> ISO_DATA_LENGTH_SHIFT) / 4;
+		/* handle each packet data */
+		handle_in_packet(s, data_quadlets, buffer);
+
+		if (queue_in_packet(s) < 0) {
+			amdtp_stream_pcm_abort(s);
+			return;
+		}
+	}
+
+	fw_iso_context_queue_flush(s->context);
+}
+
 /**
  * amdtp_stream_start - start transferring packets
  * @s: the AMDTP stream to start
@@ -595,7 +761,10 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 		[CIP_SFC_88200]  = {  0,   67 },
 		[CIP_SFC_176400] = {  0,   67 },
 	};
-	int err;
+	unsigned int header_size;
+	enum dma_data_direction dir;
+	fw_iso_callback_t cb;
+	int type, err;
 
 	mutex_lock(&s->mutex);
 
@@ -609,16 +778,26 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 	s->syt_offset_state = initial_state[s->sfc].syt_offset;
 	s->last_syt_offset = TICKS_PER_CYCLE;
 
+	/* initialize packet buffer */
+	if (s->direction == AMDTP_IN_STREAM) {
+		dir = DMA_FROM_DEVICE;
+		type = FW_ISO_CONTEXT_RECEIVE;
+		header_size = IN_PACKET_HEADER_SIZE;
+		cb = in_stream_callback;
+	} else {
+		dir = DMA_TO_DEVICE;
+		type = FW_ISO_CONTEXT_TRANSMIT;
+		header_size = OUT_PACKET_HEADER_SIZE;
+		cb = out_stream_callback;
+	}
 	err = iso_packets_buffer_init(&s->buffer, s->unit, QUEUE_LENGTH,
-				      amdtp_stream_get_max_payload(s),
-				      DMA_TO_DEVICE);
+				      amdtp_stream_get_max_payload(s), dir);
 	if (err < 0)
 		goto err_unlock;
 
 	s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,
-					   FW_ISO_CONTEXT_TRANSMIT,
-					   channel, speed, 0,
-					   out_stream_callback, s);
+					   type, channel, speed, header_size,
+					   cb, s);
 	if (IS_ERR(s->context)) {
 		err = PTR_ERR(s->context);
 		if (err == -EBUSY)
@@ -631,13 +810,18 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 
 	s->packet_index = 0;
 	do {
-		err = queue_out_packet(s, 0, true);
+		if (s->direction == AMDTP_IN_STREAM)
+			err = queue_in_packet(s);
+		else
+			err = queue_out_packet(s, 0, true);
 		if (err < 0)
 			goto err_context;
 	} while (s->packet_index > 0);
 
+	/* NOTE: TAG1 matches CIP. This just affects in stream */
 	s->data_block_counter = 0;
-	err = fw_iso_context_start(s->context, -1, 0, 0);
+	err = fw_iso_context_start(s->context, -1, 0,
+				   FW_ISO_CONTEXT_MATCH_TAG1);
 	if (err < 0)
 		goto err_context;
 
Signature · 1 line
1.8.3.2
maintainer
#15 lore raw

PATCH 6/39 firewire-lib: Add support for MIDI capture/playback

In reply to Takashi Sakamoto

For capturing/playbacking MIDI messages, this commit adds one MIDI conformant data channel. This channel supports 8 MPX-MIDI data streams then maximum number of supported MIDI ports is limited by 8.

And this commit allows to set PCM format even if AMDTP stream already starts. I suppose the case that PCM stream is going to be joined into AMDTP streams after AMDTP stream is already started by MIDI. Each driver must count how many MIDI substreams use AMDTP stream to stop AMDTP stream.

IEC 61883-6 refers to AMEI/MMA RP-027 for implementation of MIDI conformant data. In the specification, 'MIDI1.0-2x/3x-SPEED' mode are described with 'negotiation procedure' and 'encapsulation details'. But there is no specifications to define them. This module implement 'MIDI1.0-1x-SPEED' mode.

---
 sound/firewire/amdtp.c | 63 ++++++++++++++++++++++++++++++++++++++++++--------
 sound/firewire/amdtp.h | 43 ++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 10 deletions(-)
sound/firewire/amdtp.c +53 -10
index 4ebfd67..ad3521f 100644
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <sound/pcm.h>
+#include <sound/rawmidi.h>
 #include "amdtp.h"
 
 #define TICKS_PER_CYCLE		3072
@@ -123,9 +124,12 @@ void amdtp_stream_set_parameters(struct amdtp_stream *s,
 		[CIP_SFC_176400] = 176400,
 		[CIP_SFC_192000] = 192000,
 	};
-	unsigned int sfc;
+	unsigned int sfc, midi_channels;
 
-	if (WARN_ON(amdtp_stream_running(s)))
+	midi_channels = DIV_ROUND_UP(midi_ports, 8);
+
+	if (WARN_ON(amdtp_stream_running(s)) ||
+	    WARN_ON(midi_channels > AMDTP_MAX_CHANNELS_FOR_MIDI))
 		return;
 
 	for (sfc = 0; sfc < CIP_SFC_COUNT; ++sfc)
@@ -142,7 +146,7 @@ sfc_found:
 		pcm_channels *= 2;
 	}
 	s->sfc = sfc;
-	s->data_block_quadlets = pcm_channels + DIV_ROUND_UP(midi_ports, 8);
+	s->data_block_quadlets = pcm_channels + midi_channels;
 	s->pcm_channels = pcm_channels;
 	s->midi_ports = midi_ports;
 
@@ -200,7 +204,7 @@ static void amdtp_read_s32_dualwire(struct amdtp_stream *s,
 void amdtp_stream_set_pcm_format(struct amdtp_stream *s,
 				 snd_pcm_format_t format)
 {
-	if (WARN_ON(amdtp_stream_running(s)))
+	if (WARN_ON(amdtp_stream_pcm_running(s)))
 		return;
 
 	switch (format) {
@@ -505,11 +509,46 @@ static void amdtp_fill_pcm_silence(struct amdtp_stream *s,
 static void amdtp_fill_midi(struct amdtp_stream *s,
 			    __be32 *buffer, unsigned int frames)
 {
-	unsigned int i;
+	unsigned int f, port;
+	u8 *b;
+
+	for (f = 0; f < frames; f++) {
+		buffer[s->pcm_channels + 1] = 0x00;
+		b = (u8 *)&buffer[s->pcm_channels + 1];
+
+		port = (s->data_block_counter + f) % 8;
+		if ((s->midi[port] == NULL) ||
+		    (snd_rawmidi_transmit(s->midi[port], b + 1, 1) <= 0)) {
+			b[0] = 0x80;
+			b[1] = 0x00;	/* confirm to be zero */
+		} else {
+			b[0] = 0x81;
+		}
+		buffer += s->data_block_quadlets;
+	}
+}
+
+static void amdtp_pull_midi(struct amdtp_stream *s,
+			    __be32 *buffer, unsigned int frames)
+{
+	unsigned int f, port;
+	int len;
+	u8 *b;
+
+	for (f = 0; f < frames; f++) {
+		port = (s->data_block_counter + f) % 8;
+		b = (u8 *)&buffer[s->pcm_channels + 1];
+
+		len = b[0] - 0x80;
+		if (len < 1 || 3 < len)
+			continue;
 
-	for (i = 0; i < frames; ++i)
-		buffer[s->pcm_channels + i * s->data_block_quadlets] =
-						cpu_to_be32(0x80000000);
+		if (s->midi[port] == NULL)
+			continue;
+
+		snd_rawmidi_receive(s->midi[port], b + 1, len);
+		buffer += s->data_block_quadlets;
+	}
 }
 
 static void update_pcm_pointers(struct amdtp_stream *s,
@@ -683,10 +722,14 @@ static void handle_in_packet(struct amdtp_stream *s,
 	buffer += 2;
 
 	pcm = ACCESS_ONCE(s->pcm);
-	if (pcm) {
+	if (pcm)
 		s->transfer_samples(s, pcm, buffer, data_blocks);
+
+	if (s->midi_ports)
+		amdtp_pull_midi(s, buffer, data_blocks);
+
+	if (pcm)
 		update_pcm_pointers(s, pcm, data_blocks);
-	}
 }
 
 static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
sound/firewire/amdtp.h +43 -0

70 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#18 lore raw

PATCH 7/39 firewire-lib: Give syt value as parameter to handle_out_packet()

In reply to Takashi Sakamoto

For duplex streams with synchronization, drivers should pick up 'presentation timestamp' from in-packets and use the timestamp for out-packets. This commit is preparation for this.

---
 sound/firewire/amdtp.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
sound/firewire/amdtp.c +12 -12
index ad3521f..56b01c8 100644
@@ -256,7 +256,9 @@ static unsigned int calculate_data_blocks(struct amdtp_stream *s)
 {
 	unsigned int phase, data_blocks;
 
-	if (!cip_sfc_is_base_44100(s->sfc)) {
+	if (s->flags & CIP_BLOCKING)
+		data_blocks = s->syt_interval;
+	else if (!cip_sfc_is_base_44100(s->sfc)) {
 		/* Sample_rate / 8000 is an integer, and precomputed. */
 		data_blocks = s->data_block_state;
 	} else {
@@ -620,26 +622,22 @@ static inline int queue_in_packet(struct amdtp_stream *s)
 			    amdtp_stream_get_max_payload(s), false);
 }
 
-static void handle_out_packet(struct amdtp_stream *s, unsigned int cycle)
+static void handle_out_packet(struct amdtp_stream *s, unsigned int syt)
 {
 	__be32 *buffer;
-	unsigned int index, data_blocks, syt, payload_length;
+	unsigned int data_blocks, payload_length;
 	struct snd_pcm_substream *pcm;
 
 	if (s->packet_index < 0)
 		return;
-	index = s->packet_index;
 
 	/* this module generate empty packet for 'no data' */
-	syt = calculate_syt(s, cycle);
-	if (!(s->flags & CIP_BLOCKING))
+	if (!(s->flags & CIP_BLOCKING) || (syt != CIP_SYT_NO_INFO))
 		data_blocks = calculate_data_blocks(s);
-	else if (syt != CIP_SYT_NO_INFO)
-		data_blocks = s->syt_interval;
 	else
 		data_blocks = 0;
 
-	buffer = s->buffer.packets[index].buffer;
+	buffer = s->buffer.packets[s->packet_index].buffer;
 	buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
 				(s->data_block_quadlets << AMDTP_DBS_SHIFT) |
 				s->data_block_counter);
@@ -737,7 +735,7 @@ static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
 				void *private_data)
 {
 	struct amdtp_stream *s = private_data;
-	unsigned int i, packets = header_length / 4;
+	unsigned int i, syt, packets = header_length / 4;
 
 	/*
 	 * Compute the cycle of the last queued packet.
@@ -746,8 +744,10 @@ static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
 	 */
 	cycle += QUEUE_LENGTH - packets;
 
-	for (i = 0; i < packets; ++i)
-		handle_out_packet(s, ++cycle);
+	for (i = 0; i < packets; ++i) {
+		syt = calculate_syt(s, ++cycle);
+		handle_out_packet(s, syt);
+	}
 	fw_iso_context_queue_flush(s->context);
 }
 
Signature · 1 line
1.8.3.2
maintainer
#19 lore raw

PATCH 8/39 firewire-lib: Add support for duplex streams synchronization in blocking mode

In reply to Takashi Sakamoto

Generally, the devices can synchronize to handle 'presentation timestamp' in CIP packets. This commit adds functionality to pick up this timestamp from in-packets transmitted by the device, then use it for out packets.

In current implementation, this module generated the timestamp by itself. This is 'SYT Match' mode. Then this drive acts as synchronization master. This commit allows this module to act as synchronization slave.

This commit restricts this mechanism is only available in blocking mode because handling the timestamp in non-blocking mode is more complicated than in blocking mode.

---
 sound/firewire/amdtp.c | 65 +++++++++++++++++++++++++++++++++++++++++++++-----
 sound/firewire/amdtp.h | 46 ++++++++++++++++++++++++++++++++---
 2 files changed, 102 insertions(+), 9 deletions(-)
sound/firewire/amdtp.c +59 -6
index 56b01c8..9415992 100644
@@ -11,6 +11,7 @@
 #include <linux/firewire.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/sched.h>
 #include <sound/pcm.h>
 #include <sound/rawmidi.h>
 #include "amdtp.h"
@@ -72,6 +73,10 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
 	tasklet_init(&s->period_tasklet, pcm_period_tasklet, (unsigned long)s);
 	s->packet_index = 0;
 
+	init_waitqueue_head(&s->callback_wait);
+	s->callbacked = false;
+	s->sync_slave = ERR_PTR(-1);
+
 	return 0;
 }
 EXPORT_SYMBOL(amdtp_stream_init);
@@ -626,7 +631,7 @@ static void handle_out_packet(struct amdtp_stream *s, unsigned int syt)
 {
 	__be32 *buffer;
 	unsigned int data_blocks, payload_length;
-	struct snd_pcm_substream *pcm;
+	struct snd_pcm_substream *pcm = NULL;
 
 	if (s->packet_index < 0)
 		return;
@@ -756,7 +761,7 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
 			       void *private_data)
 {
 	struct amdtp_stream *s = private_data;
-	unsigned int p, packets, data_quadlets;
+	unsigned int p, packets, syt, data_quadlets;
 	__be32 *buffer, *headers = header;
 
 	/* The number of packets in buffer */
@@ -768,6 +773,15 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
 		/* The number of quadlets in this packet */
 		data_quadlets =
 			(be32_to_cpu(headers[p]) >> ISO_DATA_LENGTH_SHIFT) / 4;
+
+		/* Process sync slave stream */
+		if ((s->flags & CIP_BLOCKING) &&
+		    (s->flags & CIP_SYNC_TO_DEVICE) &&
+		    s->sync_slave->callbacked) {
+			syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK;
+			handle_out_packet(s->sync_slave, syt);
+		}
+
 		/* handle each packet data */
 		handle_in_packet(s, data_quadlets, buffer);
 
@@ -777,9 +791,48 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
 		}
 	}
 
+	/* when sync to device, flush the packets for slave stream */
+	if ((s->flags & CIP_BLOCKING) &&
+	    (s->flags & CIP_SYNC_TO_DEVICE) && s->sync_slave->callbacked)
+		fw_iso_context_queue_flush(s->sync_slave->context);
+
 	fw_iso_context_queue_flush(s->context);
 }
 
+/* processing is done by master callback */
+static void slave_stream_callback(struct fw_iso_context *context, u32 cycle,
+				  size_t header_length, void *header,
+				  void *private_data)
+{
+	return;
+}
+
+/* this is executed one time */
+static void amdtp_stream_callback(struct fw_iso_context *context, u32 cycle,
+				  size_t header_length, void *header,
+				  void *private_data)
+{
+	struct amdtp_stream *s = private_data;
+
+	/*
+	 * For in-stream, first packet has come.
+	 * For out-stream, prepared to transmit first packet
+	 */
+	s->callbacked = true;
+	wake_up(&s->callback_wait);
+
+	if (s->direction == AMDTP_IN_STREAM)
+		context->callback.sc = in_stream_callback;
+	else if ((s->flags & CIP_BLOCKING) && (s->flags & CIP_SYNC_TO_DEVICE))
+		context->callback.sc = slave_stream_callback;
+	else
+		context->callback.sc = out_stream_callback;
+
+	context->callback.sc(context, cycle, header_length, header, s);
+
+	return;
+}
+
 /**
  * amdtp_stream_start - start transferring packets
  * @s: the AMDTP stream to start
@@ -806,7 +859,6 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 	};
 	unsigned int header_size;
 	enum dma_data_direction dir;
-	fw_iso_callback_t cb;
 	int type, err;
 
 	mutex_lock(&s->mutex);
@@ -826,12 +878,10 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 		dir = DMA_FROM_DEVICE;
 		type = FW_ISO_CONTEXT_RECEIVE;
 		header_size = IN_PACKET_HEADER_SIZE;
-		cb = in_stream_callback;
 	} else {
 		dir = DMA_TO_DEVICE;
 		type = FW_ISO_CONTEXT_TRANSMIT;
 		header_size = OUT_PACKET_HEADER_SIZE;
-		cb = out_stream_callback;
 	}
 	err = iso_packets_buffer_init(&s->buffer, s->unit, QUEUE_LENGTH,
 				      amdtp_stream_get_max_payload(s), dir);
@@ -840,7 +890,7 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 
 	s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,
 					   type, channel, speed, header_size,
-					   cb, s);
+					   amdtp_stream_callback, s);
 	if (IS_ERR(s->context)) {
 		err = PTR_ERR(s->context);
 		if (err == -EBUSY)
@@ -863,6 +913,7 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 
 	/* NOTE: TAG1 matches CIP. This just affects in stream */
 	s->data_block_counter = 0;
+	s->callbacked = false;
 	err = fw_iso_context_start(s->context, -1, 0,
 				   FW_ISO_CONTEXT_MATCH_TAG1);
 	if (err < 0)
@@ -935,6 +986,8 @@ void amdtp_stream_stop(struct amdtp_stream *s)
 	s->context = ERR_PTR(-1);
 	iso_packets_buffer_destroy(&s->buffer, s->unit);
 
+	s->callbacked = false;
+
 	mutex_unlock(&s->mutex);
 }
 EXPORT_SYMBOL(amdtp_stream_stop);
sound/firewire/amdtp.h +43 -3

64 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#22 lore raw

PATCH 9/39 firewire-lib: Add sort function for transmitted packet

In reply to Takashi Sakamoto

This commit is to assure the continuity of timestamp in in-packets transmitted by devices.

Fireworks with firmware version 5.5 or former is a type of device which transmits packets with a bit disorder.

This commit add sorting of in-packets. When callback of receive-context is processed, the parameters of in-packets are stored in sort table and sorted by its value of data block counter. The sort algorism works faster in ordered sequence than in messy sequence. This is convinient for this purpose because the sequence is assumed not to be so messy. After sorting, packets are processed except for a last few packets in sort table. These packets are stored in buffer once and used in next cycle.

---
 sound/firewire/amdtp.c | 129 +++++++++++++++++++++++++++++++++++++++++++------
 sound/firewire/amdtp.h |   4 ++
 2 files changed, 119 insertions(+), 14 deletions(-)
sound/firewire/amdtp.c +115 -14
index 9415992..d3cf7bf 100644
@@ -45,6 +45,7 @@
 #define AMDTP_DBS_MASK		0x00ff0000
 #define AMDTP_DBS_SHIFT		16
 #define AMDTP_DBC_MASK		0x000000ff
+#define DBC_THRESHOLD		(AMDTP_DBC_MASK / 2)
 
 /* TODO: make these configurable */
 #define INTERRUPT_INTERVAL	16
@@ -53,6 +54,13 @@
 #define IN_PACKET_HEADER_SIZE	4
 #define OUT_PACKET_HEADER_SIZE	0
 
+/* for re-ordering receive packets */
+struct sort_table {
+	unsigned int id;
+	unsigned int dbc;
+	unsigned int payload_size;
+};
+
 static void pcm_period_tasklet(unsigned long data);
 
 /**
@@ -77,6 +85,9 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
 	s->callbacked = false;
 	s->sync_slave = ERR_PTR(-1);
 
+	s->sort_table = NULL;
+	s->left_packets = NULL;
+
 	return 0;
 }
 EXPORT_SYMBOL(amdtp_stream_init);
@@ -735,6 +746,34 @@ static void handle_in_packet(struct amdtp_stream *s,
 		update_pcm_pointers(s, pcm, data_blocks);
 }
 
+static void packet_sort(struct sort_table *tbl, unsigned int len)
+{
+	unsigned int i, j, k;
+
+	i = 0;
+	do {
+		for (j = i + 1; j < len; j++) {
+			if (((tbl[i].dbc > tbl[j].dbc) &&
+			     (tbl[i].dbc - tbl[j].dbc < DBC_THRESHOLD))) {
+				swap(tbl[i], tbl[j]);
+			} else if ((tbl[j].dbc > tbl[i].dbc) &&
+				   (tbl[j].dbc - tbl[i].dbc >
+							DBC_THRESHOLD)) {
+				for (k = i; k > 0; k--) {
+					if ((tbl[k].dbc > tbl[j].dbc) ||
+					    (tbl[j].dbc - tbl[k].dbc >
+							DBC_THRESHOLD)) {
+						swap(tbl[j], tbl[k]);
+					}
+					break;
+				}
+			}
+			break;
+		}
+		i = j;
+	} while (i < len);
+}
+
 static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
 				size_t header_length, void *header,
 				void *private_data)
@@ -761,30 +800,66 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
 			       void *private_data)
 {
 	struct amdtp_stream *s = private_data;
-	unsigned int p, packets, syt, data_quadlets;
+	struct sort_table *entry, *tbl = s->sort_table;
+	unsigned int i, j, k, index, packets, syt, remain_packets;
 	__be32 *buffer, *headers = header;
 
 	/* The number of packets in buffer */
 	packets = header_length / IN_PACKET_HEADER_SIZE;
 
-	for (p = 0; p < packets; p++) {
-		buffer = s->buffer.packets[s->packet_index].buffer;
+	/* Store into sort table and sort. */
+	for (i = 0; i < packets; i++) {
+		entry = &tbl[s->remain_packets + i];
+		entry->id = i;
+
+		index = s->packet_index + i;
+		if (index >= QUEUE_LENGTH)
+			index -= QUEUE_LENGTH;
+		buffer = s->buffer.packets[index].buffer;
+		entry->dbc = be32_to_cpu(buffer[0]) & AMDTP_DBC_MASK;
 
-		/* The number of quadlets in this packet */
-		data_quadlets =
-			(be32_to_cpu(headers[p]) >> ISO_DATA_LENGTH_SHIFT) / 4;
+		entry->payload_size = be32_to_cpu(headers[i]) >>
+				      ISO_DATA_LENGTH_SHIFT;
+	}
+	packet_sort(tbl, packets + s->remain_packets);
 
-		/* Process sync slave stream */
-		if ((s->flags & CIP_BLOCKING) &&
-		    (s->flags & CIP_SYNC_TO_DEVICE) &&
-		    s->sync_slave->callbacked) {
-			syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK;
-			handle_out_packet(s->sync_slave, syt);
+	/*
+	 * for convinience, tbl[i].id >= QUEUE_LENGTH is a label to identify
+	 * previous packets in buffer.
+	 */
+	remain_packets = s->remain_packets;
+	s->remain_packets = packets / 4;
+	for (i = 0, j = 0, k = 0; i < remain_packets + packets; i++) {
+		if (tbl[i].id < QUEUE_LENGTH) {
+			index = s->packet_index + tbl[i].id;
+			if (index >= QUEUE_LENGTH)
+				index -= QUEUE_LENGTH;
+			buffer = s->buffer.packets[index].buffer;
+		} else {
+			buffer = s->left_packets +
+				 amdtp_stream_get_max_payload(s) * j++;
 		}
 
-		/* handle each packet data */
-		handle_in_packet(s, data_quadlets, buffer);
+		if (i < remain_packets + packets - s->remain_packets) {
+			/* Process sync slave stream */
+			if ((s->flags & CIP_BLOCKING) &&
+			    (s->flags & CIP_SYNC_TO_DEVICE) &&
+			    s->sync_slave->callbacked) {
+				syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK;
+				handle_out_packet(s->sync_slave, syt);
+			}
+			handle_in_packet(s, tbl[i].payload_size / 4, buffer);
+		} else {
+			tbl[k].id = tbl[i].id + QUEUE_LENGTH;
+			tbl[k].dbc = tbl[i].dbc;
+			tbl[k].payload_size = tbl[i].payload_size;
+			memcpy(s->left_packets +
+					amdtp_stream_get_max_payload(s) * k++,
+			       buffer, tbl[i].payload_size);
+		}
+	}
 
+	for (i = 0; i < packets; i++) {
 		if (queue_in_packet(s) < 0) {
 			amdtp_stream_pcm_abort(s);
 			return;
@@ -888,6 +963,19 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 	if (err < 0)
 		goto err_unlock;
 
+	/* for sorting transmitted packets */
+	if (s->direction == AMDTP_IN_STREAM) {
+		s->remain_packets = 0;
+		s->sort_table = kzalloc(sizeof(struct sort_table) *
+					QUEUE_LENGTH, GFP_KERNEL);
+		if (s->sort_table == NULL)
+			goto err_buffer;
+		s->left_packets = kzalloc(amdtp_stream_get_max_payload(s) *
+					  QUEUE_LENGTH / 4, GFP_KERNEL);
+		if (s->left_packets == NULL)
+			goto err_buffer;
+	}
+
 	s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,
 					   type, channel, speed, header_size,
 					   amdtp_stream_callback, s);
@@ -927,6 +1015,12 @@ err_context:
 	fw_iso_context_destroy(s->context);
 	s->context = ERR_PTR(-1);
 err_buffer:
+	if (s->sort_table != NULL)
+		kfree(s->sort_table);
+	if (s->left_packets != NULL)
+		kfree(s->left_packets);
+	s->sort_table = NULL;
+	s->left_packets = NULL;
 	iso_packets_buffer_destroy(&s->buffer, s->unit);
 err_unlock:
 	mutex_unlock(&s->mutex);
@@ -986,6 +1080,13 @@ void amdtp_stream_stop(struct amdtp_stream *s)
 	s->context = ERR_PTR(-1);
 	iso_packets_buffer_destroy(&s->buffer, s->unit);
 
+	if (s->sort_table != NULL)
+		kfree(s->sort_table);
+	if (s->left_packets != NULL)
+		kfree(s->left_packets);
+	s->sort_table = NULL;
+	s->left_packets = NULL;
+
 	s->callbacked = false;
 
 	mutex_unlock(&s->mutex);
sound/firewire/amdtp.h +4 -0
index efa2d25..d502646 100644
@@ -109,6 +109,10 @@ struct amdtp_stream {
 	bool callbacked;
 	wait_queue_head_t callback_wait;
 	struct amdtp_stream *sync_slave;
+
+	void *sort_table;
+	void *left_packets;
+	unsigned int remain_packets;
 };
 
 int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
Signature · 1 line
1.8.3.2
maintainer
#28 lore raw

PATCH 10/39 firewire-lib: Add transfer delay to synchronized duplex streams

In reply to Takashi Sakamoto

Currently, in duplex streams with synchronization mode, this module just pass 'presentation timestamp' from in-packets to out-packets. This is enough to handle actual device but logically the timestamp should include 'transfer delay' and 'processing time'. This means the timestamp in out-packet should be at future.

To be simple, this commit add only 'transfer delay'.

---
 sound/firewire/amdtp.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
sound/firewire/amdtp.c +10 -0
index d3cf7bf..9383392 100644
@@ -774,6 +774,15 @@ static void packet_sort(struct sort_table *tbl, unsigned int len)
 	} while (i < len);
 }
 
+static inline void add_transfer_delay(struct amdtp_stream *s, unsigned int *syt)
+{
+	if (*syt != CIP_SYT_NO_INFO) {
+		*syt += (s->transfer_delay / TICKS_PER_CYCLE) << 12;
+		*syt += s->transfer_delay % TICKS_PER_CYCLE;
+		*syt &= CIP_SYT_MASK;
+	}
+}
+
 static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
 				size_t header_length, void *header,
 				void *private_data)
@@ -846,6 +855,7 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
 			    (s->flags & CIP_SYNC_TO_DEVICE) &&
 			    s->sync_slave->callbacked) {
 				syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK;
+				add_transfer_delay(s, &syt);
 				handle_out_packet(s->sync_slave, syt);
 			}
 			handle_in_packet(s, tbl[i].payload_size / 4, buffer);
Signature · 1 line
1.8.3.2
maintainer
#32 lore raw

PATCH 11/39 firewire-lib: Add support for channel mapping

In reply to Takashi Sakamoto

Some devices arrange the position of PCM/MIDI data channel in AMDTP packet. This commit allows drivers to set channel mapping.

To be simple, the mapping table is an array with fixed length. Then the number of channels for PCM is restricted by 64 channels.

---
 sound/firewire/amdtp.c | 122 +++++++++++++++++++++++++++++--------------------
 sound/firewire/amdtp.h |   8 ++++
 2 files changed, 80 insertions(+), 50 deletions(-)
sound/firewire/amdtp.c +72 -50
index 9383392..57608f8 100644
@@ -140,11 +140,12 @@ void amdtp_stream_set_parameters(struct amdtp_stream *s,
 		[CIP_SFC_176400] = 176400,
 		[CIP_SFC_192000] = 192000,
 	};
-	unsigned int sfc, midi_channels;
+	unsigned int i, sfc, midi_channels;
 
 	midi_channels = DIV_ROUND_UP(midi_ports, 8);
 
-	if (WARN_ON(amdtp_stream_running(s)) ||
+	if (WARN_ON(amdtp_stream_running(s)) |
+	    WARN_ON(pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM) |
 	    WARN_ON(midi_channels > AMDTP_MAX_CHANNELS_FOR_MIDI))
 		return;
 
@@ -159,11 +160,12 @@ sfc_found:
 	if (s->dual_wire) {
 		sfc -= 2;
 		rate /= 2;
-		pcm_channels *= 2;
+		s->pcm_channels = pcm_channels * 2;
+	} else {
+		s->pcm_channels = pcm_channels;
 	}
 	s->sfc = sfc;
-	s->data_block_quadlets = pcm_channels + midi_channels;
-	s->pcm_channels = pcm_channels;
+	s->data_block_quadlets = s->pcm_channels + midi_channels;
 	s->midi_ports = midi_ports;
 
 	s->syt_interval = amdtp_syt_intervals[sfc];
@@ -173,6 +175,11 @@ sfc_found:
 	if (s->flags & CIP_BLOCKING)
 		/* additional buffering needed to adjust for no-data packets */
 		s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate;
+
+	/* init the position map for PCM and MIDI channels */
+	for (i = 0; i < pcm_channels; i++)
+		s->pcm_positions[i] = i;
+	s->midi_position = s->pcm_channels;
 }
 EXPORT_SYMBOL(amdtp_stream_set_parameters);
 
@@ -351,22 +358,20 @@ static void amdtp_write_s32(struct amdtp_stream *s,
 			    __be32 *buffer, unsigned int frames)
 {
 	struct snd_pcm_runtime *runtime = pcm->runtime;
-	unsigned int channels, remaining_frames, frame_step, i, c;
+	unsigned int remaining_frames, i, c;
 	const u32 *src;
 
-	channels = s->pcm_channels;
 	src = (void *)runtime->dma_area +
 			frames_to_bytes(runtime, s->pcm_buffer_pointer);
 	remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
-	frame_step = s->data_block_quadlets - channels;
 
 	for (i = 0; i < frames; ++i) {
-		for (c = 0; c < channels; ++c) {
-			*buffer = cpu_to_be32((*src >> 8) | 0x40000000);
+		for (c = 0; c < s->pcm_channels; ++c) {
+			buffer[s->pcm_positions[c]] =
+					cpu_to_be32((*src >> 8) | 0x40000000);
 			src++;
-			buffer++;
 		}
-		buffer += frame_step;
+		buffer += s->data_block_quadlets;
 		if (--remaining_frames == 0)
 			src = (void *)runtime->dma_area;
 	}
@@ -377,22 +382,20 @@ static void amdtp_write_s16(struct amdtp_stream *s,
 			    __be32 *buffer, unsigned int frames)
 {
 	struct snd_pcm_runtime *runtime = pcm->runtime;
-	unsigned int channels, remaining_frames, frame_step, i, c;
+	unsigned int remaining_frames, i, c;
 	const u16 *src;
 
-	channels = s->pcm_channels;
 	src = (void *)runtime->dma_area +
 			frames_to_bytes(runtime, s->pcm_buffer_pointer);
 	remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
-	frame_step = s->data_block_quadlets - channels;
 
 	for (i = 0; i < frames; ++i) {
-		for (c = 0; c < channels; ++c) {
-			*buffer = cpu_to_be32((*src << 8) | 0x40000000);
+		for (c = 0; c < s->pcm_channels; ++c) {
+			buffer[s->pcm_positions[c]] =
+					cpu_to_be32((*src << 8) | 0x40000000);
 			src++;
-			buffer++;
 		}
-		buffer += frame_step;
+		buffer += s->data_block_quadlets;
 		if (--remaining_frames == 0)
 			src = (void *)runtime->dma_area;
 	}
@@ -403,29 +406,29 @@ static void amdtp_write_s32_dualwire(struct amdtp_stream *s,
 				     __be32 *buffer, unsigned int frames)
 {
 	struct snd_pcm_runtime *runtime = pcm->runtime;
-	unsigned int channels, frame_adjust_1, frame_adjust_2, i, c;
+	unsigned int channels, remaining_frames, i, c;
 	const u32 *src;
 
-	channels = s->pcm_channels;
 	src = (void *)runtime->dma_area +
-			s->pcm_buffer_pointer * (runtime->frame_bits / 8);
-	frame_adjust_1 = channels - 1;
-	frame_adjust_2 = 1 - (s->data_block_quadlets - channels);
+			frames_to_bytes(runtime, s->pcm_buffer_pointer);
+	remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
+	channels = s->pcm_channels / 2;
 
-	channels /= 2;
 	for (i = 0; i < frames; ++i) {
 		for (c = 0; c < channels; ++c) {
-			*buffer = cpu_to_be32((*src >> 8) | 0x40000000);
+			buffer[s->pcm_positions[c] * 2] =
+					cpu_to_be32((*src >> 8) | 0x40000000);
 			src++;
-			buffer += 2;
 		}
-		buffer -= frame_adjust_1;
+		buffer += 1;
 		for (c = 0; c < channels; ++c) {
-			*buffer = cpu_to_be32((*src >> 8) | 0x40000000);
+			buffer[s->pcm_positions[c] * 2] =
+					cpu_to_be32((*src >> 8) | 0x40000000);
 			src++;
-			buffer += 2;
 		}
-		buffer -= frame_adjust_2;
+		buffer += s->data_block_quadlets - 1;
+		if (--remaining_frames == 0)
+			src = (void *)runtime->dma_area;
 	}
 }
 
@@ -434,29 +437,29 @@ static void amdtp_write_s16_dualwire(struct amdtp_stream *s,
 				     __be32 *buffer, unsigned int frames)
 {
 	struct snd_pcm_runtime *runtime = pcm->runtime;
-	unsigned int channels, frame_adjust_1, frame_adjust_2, i, c;
+	unsigned int channels, remaining_frames, i, c;
 	const u16 *src;
 
-	channels = s->pcm_channels;
 	src = (void *)runtime->dma_area +
-			s->pcm_buffer_pointer * (runtime->frame_bits / 8);
-	frame_adjust_1 = channels - 1;
-	frame_adjust_2 = 1 - (s->data_block_quadlets - channels);
+			frames_to_bytes(runtime, s->pcm_buffer_pointer);
+	remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
+	channels = s->pcm_channels / 2;
 
-	channels /= 2;
 	for (i = 0; i < frames; ++i) {
 		for (c = 0; c < channels; ++c) {
-			*buffer = cpu_to_be32((*src << 8) | 0x40000000);
+			buffer[s->pcm_positions[c] * 2] =
+					cpu_to_be32((*src << 8) | 0x40000000);
 			src++;
-			buffer += 2;
 		}
-		buffer -= frame_adjust_1;
+		buffer += 1;
 		for (c = 0; c < channels; ++c) {
-			*buffer = cpu_to_be32((*src << 8) | 0x40000000);
+			buffer[s->pcm_positions[c] * 2] =
+					cpu_to_be32((*src << 8) | 0x40000000);
 			src++;
-			buffer += 2;
 		}
-		buffer -= frame_adjust_2;
+		buffer += s->data_block_quadlets - 1;
+		if (--remaining_frames == 0)
+			src = (void *)runtime->dma_area;
 	}
 }
 
@@ -474,7 +477,7 @@ static void amdtp_read_s32(struct amdtp_stream *s,
 
 	for (i = 0; i < frames; ++i) {
 		for (c = 0; c < s->pcm_channels; ++c) {
-			*dst = be32_to_cpu(buffer[c]) << 8;
+			*dst = be32_to_cpu(buffer[s->pcm_positions[c]]) << 8;
 			dst++;
 		}
 		buffer += s->data_block_quadlets;
@@ -498,12 +501,14 @@ static void amdtp_read_s32_dualwire(struct amdtp_stream *s,
 
 	for (i = 0; i < frames; ++i) {
 		for (c = 0; c < channels; ++c) {
-			*dst = be32_to_cpu(buffer[c * 2]) << 8;
+			*dst =
+			     be32_to_cpu(buffer[s->pcm_positions[c] * 2]) << 8;
 			dst++;
 		}
 		buffer += 1;
 		for (c = 0; c < channels; ++c) {
-			*dst = be32_to_cpu(buffer[c * 2]) << 8;
+			*dst =
+			     be32_to_cpu(buffer[s->pcm_positions[c] * 2]) << 8;
 			dst++;
 		}
 		buffer += s->data_block_quadlets - 1;
@@ -519,11 +524,26 @@ static void amdtp_fill_pcm_silence(struct amdtp_stream *s,
 
 	for (i = 0; i < frames; ++i) {
 		for (c = 0; c < s->pcm_channels; ++c)
-			buffer[c] = cpu_to_be32(0x40000000);
+			buffer[s->pcm_positions[c]] = cpu_to_be32(0x40000000);
 		buffer += s->data_block_quadlets;
 	}
 }
 
+static void amdtp_fill_pcm_silence_dualwire(struct amdtp_stream *s,
+					   __be32 *buffer, unsigned int frames)
+{
+	unsigned int i, c, channels;
+
+	channels = s->pcm_channels / 2;
+	for (i = 0; i < frames; ++i) {
+		for (c = 0; c < channels; ++c) {
+			buffer[s->pcm_positions[c] * 2] =
+			buffer[s->pcm_positions[c] * 2 + 1] =
+						cpu_to_be32(0x40000000);
+		}
+		buffer += s->data_block_quadlets;
+	}
+}
 static void amdtp_fill_midi(struct amdtp_stream *s,
 			    __be32 *buffer, unsigned int frames)
 {
@@ -531,8 +551,8 @@ static void amdtp_fill_midi(struct amdtp_stream *s,
 	u8 *b;
 
 	for (f = 0; f < frames; f++) {
-		buffer[s->pcm_channels + 1] = 0x00;
-		b = (u8 *)&buffer[s->pcm_channels + 1];
+		buffer[s->midi_position] = 0x00;
+		b = (u8 *)&buffer[s->midi_position];
 
 		port = (s->data_block_counter + f) % 8;
 		if ((s->midi[port] == NULL) ||
@@ -555,7 +575,7 @@ static void amdtp_pull_midi(struct amdtp_stream *s,
 
 	for (f = 0; f < frames; f++) {
 		port = (s->data_block_counter + f) % 8;
-		b = (u8 *)&buffer[s->pcm_channels + 1];
+		b = (u8 *)&buffer[s->midi_position];
 
 		len = b[0] - 0x80;
 		if (len < 1 || 3 < len)
@@ -664,6 +684,8 @@ static void handle_out_packet(struct amdtp_stream *s, unsigned int syt)
 	pcm = ACCESS_ONCE(s->pcm);
 	if (pcm)
 		s->transfer_samples(s, pcm, buffer, data_blocks);
+	else if (s->dual_wire)
+		amdtp_fill_pcm_silence_dualwire(s, buffer, data_blocks);
 	else
 		amdtp_fill_pcm_silence(s, buffer, data_blocks);
 	if (s->midi_ports)
sound/firewire/amdtp.h +8 -0
index d502646..2fb5175 100644
@@ -49,6 +49,12 @@ enum cip_sfc {
 
 
 /*
+ * This module supports maximum 64 PCM channels for one PCM stream
+ * This is for our convinience.
+ */
+#define AMDTP_MAX_CHANNELS_FOR_PCM	64
+
+/*
  * AMDTP packet can include channels for MIDI conformant data.
  * Each MIDI conformant data channel includes 8 MPX-MIDI data stream.
  * Each MPX-MIDI data stream includes one data stream from/to MIDI ports.
@@ -83,6 +89,8 @@ struct amdtp_stream {
 	void (*transfer_samples)(struct amdtp_stream *s,
 				 struct snd_pcm_substream *pcm,
 				 __be32 *buffer, unsigned int frames);
+	u8 pcm_positions[AMDTP_MAX_CHANNELS_FOR_PCM];
+	u8 midi_position;
 
 	unsigned int syt_interval;
 	unsigned int transfer_delay;
Signature · 1 line
1.8.3.2
maintainer
#38 lore raw

PATCH 12/39 firewire-lib: Rename macros, variables and functions for CMP

In reply to Takashi Sakamoto

Referring to IEC 61883-1, oMPR and iMPR, oPCR and iPCR have some fields with the same role in the same position. This patch renames some macros, variables and function arguments with "i" in its prefix to reuse them between oMPR and iMPR, oPCR and iPCR.

---
 sound/firewire/cmp.c | 91 ++++++++++++++++++++++++++--------------------------
 sound/firewire/cmp.h |  6 ++--
 2 files changed, 49 insertions(+), 48 deletions(-)
sound/firewire/cmp.c +46 -45
index efdbf58..17ad4f2 100644
@@ -14,18 +14,20 @@
 #include "iso-resources.h"
 #include "cmp.h"
 
-#define IMPR_SPEED_MASK		0xc0000000
-#define IMPR_SPEED_SHIFT	30
-#define IMPR_XSPEED_MASK	0x00000060
-#define IMPR_XSPEED_SHIFT	5
-#define IMPR_PLUGS_MASK		0x0000001f
-
-#define IPCR_ONLINE		0x80000000
-#define IPCR_BCAST_CONN		0x40000000
-#define IPCR_P2P_CONN_MASK	0x3f000000
-#define IPCR_P2P_CONN_SHIFT	24
-#define IPCR_CHANNEL_MASK	0x003f0000
-#define IPCR_CHANNEL_SHIFT	16
+/* MPR common fields */
+#define MPR_SPEED_MASK		0xc0000000
+#define MPR_SPEED_SHIFT		30
+#define MPR_XSPEED_MASK		0x00000060
+#define MPR_XSPEED_SHIFT	5
+#define MPR_PLUGS_MASK		0x0000001f
+
+/* PCR common fields */
+#define PCR_ONLINE		0x80000000
+#define PCR_BCAST_CONN		0x40000000
+#define PCR_P2P_CONN_MASK	0x3f000000
+#define PCR_P2P_CONN_SHIFT	24
+#define PCR_CHANNEL_MASK	0x003f0000
+#define PCR_CHANNEL_SHIFT	16
 
 enum bus_reset_handling {
 	ABORT_ON_BUS_RESET,
@@ -88,24 +90,24 @@ static int pcr_modify(struct cmp_connection *c,
  * cmp_connection_init - initializes a connection manager
  * @c: the connection manager to initialize
  * @unit: a unit of the target device
- * @ipcr_index: the index of the iPCR on the target device
+ * @pcr_index: the index of the iPCR/oPCR on the target device
  */
 int cmp_connection_init(struct cmp_connection *c,
 			struct fw_unit *unit,
-			unsigned int ipcr_index)
+			unsigned int pcr_index)
 {
-	__be32 impr_be;
-	u32 impr;
+	__be32 mpr_be;
+	u32 mpr;
 	int err;
 
 	err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
 				 CSR_REGISTER_BASE + CSR_IMPR,
-				 &impr_be, 4, 0);
+				 &mpr_be, 4, 0);
 	if (err < 0)
 		return err;
-	impr = be32_to_cpu(impr_be);
+	mpr = be32_to_cpu(mpr_be);
 
-	if (ipcr_index >= (impr & IMPR_PLUGS_MASK))
+	if (pcr_index >= (mpr & MPR_PLUGS_MASK))
 		return -EINVAL;
 
 	err = fw_iso_resources_init(&c->resources, unit);
@@ -115,10 +117,10 @@ int cmp_connection_init(struct cmp_connection *c,
 	c->connected = false;
 	mutex_init(&c->mutex);
 	c->last_pcr_value = cpu_to_be32(0x80000000);
-	c->pcr_index = ipcr_index;
-	c->max_speed = (impr & IMPR_SPEED_MASK) >> IMPR_SPEED_SHIFT;
+	c->pcr_index = pcr_index;
+	c->max_speed = (mpr & MPR_SPEED_MASK) >> MPR_SPEED_SHIFT;
 	if (c->max_speed == SCODE_BETA)
-		c->max_speed += (impr & IMPR_XSPEED_MASK) >> IMPR_XSPEED_SHIFT;
+		c->max_speed += (mpr & MPR_XSPEED_MASK) >> MPR_XSPEED_SHIFT;
 
 	return 0;
 }
@@ -139,23 +141,23 @@ EXPORT_SYMBOL(cmp_connection_destroy);
 
 static __be32 ipcr_set_modify(struct cmp_connection *c, __be32 ipcr)
 {
-	ipcr &= ~cpu_to_be32(IPCR_BCAST_CONN |
-			     IPCR_P2P_CONN_MASK |
-			     IPCR_CHANNEL_MASK);
-	ipcr |= cpu_to_be32(1 << IPCR_P2P_CONN_SHIFT);
-	ipcr |= cpu_to_be32(c->resources.channel << IPCR_CHANNEL_SHIFT);
+	ipcr &= ~cpu_to_be32(PCR_BCAST_CONN |
+			     PCR_P2P_CONN_MASK |
+			     PCR_CHANNEL_MASK);
+	ipcr |= cpu_to_be32(1 << PCR_P2P_CONN_SHIFT);
+	ipcr |= cpu_to_be32(c->resources.channel << PCR_CHANNEL_SHIFT);
 
 	return ipcr;
 }
 
-static int ipcr_set_check(struct cmp_connection *c, __be32 ipcr)
+static int pcr_set_check(struct cmp_connection *c, __be32 pcr)
 {
-	if (ipcr & cpu_to_be32(IPCR_BCAST_CONN |
-			       IPCR_P2P_CONN_MASK)) {
+	if (pcr & cpu_to_be32(PCR_BCAST_CONN |
+			       PCR_P2P_CONN_MASK)) {
 		cmp_error(c, "plug is already in use\n");
 		return -EBUSY;
 	}
-	if (!(ipcr & cpu_to_be32(IPCR_ONLINE))) {
+	if (!(pcr & cpu_to_be32(PCR_ONLINE))) {
 		cmp_error(c, "plug is not on-line\n");
 		return -ECONNREFUSED;
 	}
@@ -170,9 +172,9 @@ static int ipcr_set_check(struct cmp_connection *c, __be32 ipcr)
  *
  * This function establishes a point-to-point connection from the local
  * computer to the target by allocating isochronous resources (channel and
- * bandwidth) and setting the target's input plug control register.  When this
- * function succeeds, the caller is responsible for starting transmitting
- * packets.
+ * bandwidth) and setting the target's input/output plug control register.
+ * When this function succeeds, the caller is responsible for starting
+ * transmitting packets.
  */
 int cmp_connection_establish(struct cmp_connection *c,
 			     unsigned int max_payload_bytes)
@@ -193,7 +195,7 @@ retry_after_bus_reset:
 	if (err < 0)
 		goto err_mutex;
 
-	err = pcr_modify(c, ipcr_set_modify, ipcr_set_check,
+	err = pcr_modify(c, ipcr_set_modify, pcr_set_check,
 			 ABORT_ON_BUS_RESET);
 	if (err == -EAGAIN) {
 		fw_iso_resources_free(&c->resources);
@@ -221,8 +223,8 @@ EXPORT_SYMBOL(cmp_connection_establish);
  * cmp_connection_update - update the connection after a bus reset
  * @c: the connection manager
  *
- * This function must be called from the driver's .update handler to reestablish
- * any connection that might have been active.
+ * This function must be called from the driver's .update handler to
+ * reestablish any connection that might have been active.
  *
  * Returns zero on success, or a negative error code.  On an error, the
  * connection is broken and the caller must stop transmitting iso packets.
@@ -242,7 +244,7 @@ int cmp_connection_update(struct cmp_connection *c)
 	if (err < 0)
 		goto err_unconnect;
 
-	err = pcr_modify(c, ipcr_set_modify, ipcr_set_check,
+	err = pcr_modify(c, ipcr_set_modify, pcr_set_check,
 			 SUCCEED_ON_BUS_RESET);
 	if (err < 0)
 		goto err_resources;
@@ -261,19 +263,18 @@ err_unconnect:
 }
 EXPORT_SYMBOL(cmp_connection_update);
 
-
-static __be32 ipcr_break_modify(struct cmp_connection *c, __be32 ipcr)
+static __be32 pcr_break_modify(struct cmp_connection *c, __be32 pcr)
 {
-	return ipcr & ~cpu_to_be32(IPCR_BCAST_CONN | IPCR_P2P_CONN_MASK);
+	return pcr & ~cpu_to_be32(PCR_BCAST_CONN | PCR_P2P_CONN_MASK);
 }
 
 /**
  * cmp_connection_break - break the connection to the target
  * @c: the connection manager
  *
- * This function deactives the connection in the target's input plug control
- * register, and frees the isochronous resources of the connection.  Before
- * calling this function, the caller should cease transmitting packets.
+ * This function deactives the connection in the target's input/output plug
+ * control register, and frees the isochronous resources of the connection.
+ * Before calling this function, the caller should cease transmitting packets.
  */
 void cmp_connection_break(struct cmp_connection *c)
 {
@@ -286,7 +287,7 @@ void cmp_connection_break(struct cmp_connection *c)
 		return;
 	}
 
-	err = pcr_modify(c, ipcr_break_modify, NULL, SUCCEED_ON_BUS_RESET);
+	err = pcr_modify(c, pcr_break_modify, NULL, SUCCEED_ON_BUS_RESET);
 	if (err < 0)
 		cmp_error(c, "plug is still connected\n");
 
sound/firewire/cmp.h +3 -3
index f47de08..2320cd4 100644
@@ -11,8 +11,8 @@ struct fw_unit;
  * struct cmp_connection - manages an isochronous connection to a device
  * @speed: the connection's actual speed
  *
- * This structure manages (using CMP) an isochronous stream from the local
- * computer to a device's input plug (iPCR).
+ * This structure manages (using CMP) an isochronous stream between the local
+ * computer and a device's input plug (iPCR) and output plug (oPCR).
  *
  * There is no corresponding oPCR created on the local computer, so it is not
  * possible to overlay connections on top of this one.
@@ -30,7 +30,7 @@ struct cmp_connection {
 
 int cmp_connection_init(struct cmp_connection *connection,
 			struct fw_unit *unit,
-			unsigned int ipcr_index);
+			unsigned int pcr_index);
 void cmp_connection_destroy(struct cmp_connection *connection);
 
 int cmp_connection_establish(struct cmp_connection *connection,
Signature · 1 line
1.8.3.2
maintainer
#39 lore raw

PATCH 13/39 firewire-lib: Add 'direction' member to 'cmp_connection' structure

In reply to Takashi Sakamoto

This patch adds 'direction' member to 'cmp_connection' structure to indicate the direction of connection. This patch also adds 'direction' argument to cmp_connection_init() function to determine the direction.

The cmp_connection_init() function is exported and used in snd-firewire-speakers so this patch also affect it.

This patch just add them. Actual implementation will be done by followed patches.

---
 sound/firewire/cmp.c      | 3 ++-
 sound/firewire/cmp.h      | 7 +++++++
 sound/firewire/speakers.c | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)
sound/firewire/cmp.c +2 -1
index 17ad4f2..c7f7a31 100644
@@ -94,6 +94,7 @@ static int pcr_modify(struct cmp_connection *c,
  */
 int cmp_connection_init(struct cmp_connection *c,
 			struct fw_unit *unit,
+			enum cmp_direction direction,
 			unsigned int pcr_index)
 {
 	__be32 mpr_be;
@@ -153,7 +154,7 @@ static __be32 ipcr_set_modify(struct cmp_connection *c, __be32 ipcr)
 static int pcr_set_check(struct cmp_connection *c, __be32 pcr)
 {
 	if (pcr & cpu_to_be32(PCR_BCAST_CONN |
-			       PCR_P2P_CONN_MASK)) {
+			      PCR_P2P_CONN_MASK)) {
 		cmp_error(c, "plug is already in use\n");
 		return -EBUSY;
 	}
sound/firewire/cmp.h +7 -0
index 2320cd4..9b58448 100644
@@ -7,6 +7,11 @@
 
 struct fw_unit;
 
+enum cmp_direction {
+	CMP_INPUT = 0,
+	CMP_OUTPUT,
+};
+
 /**
  * struct cmp_connection - manages an isochronous connection to a device
  * @speed: the connection's actual speed
@@ -26,10 +31,12 @@ struct cmp_connection {
 	__be32 last_pcr_value;
 	unsigned int pcr_index;
 	unsigned int max_speed;
+	enum cmp_direction direction;
 };
 
 int cmp_connection_init(struct cmp_connection *connection,
 			struct fw_unit *unit,
+			enum cmp_direction direction,
 			unsigned int pcr_index);
 void cmp_connection_destroy(struct cmp_connection *connection);
 
sound/firewire/speakers.c +1 -1
index c07e7cd..4a9b48b 100644
@@ -679,7 +679,7 @@ static int fwspk_probe(struct fw_unit *unit,
 	fwspk->unit = fw_unit_get(unit);
 	fwspk->device_info = (const struct device_info *)id->driver_data;
 
-	err = cmp_connection_init(&fwspk->connection, unit, 0);
+	err = cmp_connection_init(&fwspk->connection, unit, CMP_INPUT, 0);
 	if (err < 0)
 		goto err_unit;
 
Signature · 1 line
1.8.3.2
maintainer
#40 lore raw

PATCH 14/39 firewire-lib: Add handling output connection by CMP

In reply to Takashi Sakamoto

This patch adds some macros, codes with condition of direction and new functions to handle output connection. Once cmp_connection_init() is executed with its direction, CMP input and output connection can be handled by the same way.

---
 sound/firewire/cmp.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 93 insertions(+), 9 deletions(-)
sound/firewire/cmp.c +93 -9
index c7f7a31..60d2e17 100644
@@ -29,6 +29,14 @@
 #define PCR_CHANNEL_MASK	0x003f0000
 #define PCR_CHANNEL_SHIFT	16
 
+/* oPCR specific fields */
+#define OPCR_XSPEED_MASK	0x00C00000
+#define OPCR_XSPEED_SHIFT	22
+#define OPCR_SPEED_MASK		0x0000C000
+#define OPCR_SPEED_SHIFT	14
+#define OPCR_OVERHEAD_ID_MASK	0x00003C00
+#define OPCR_OVERHEAD_ID_SHIFT	10
+
 enum bus_reset_handling {
 	ABORT_ON_BUS_RESET,
 	SUCCEED_ON_BUS_RESET,
@@ -41,10 +49,30 @@ void cmp_error(struct cmp_connection *c, const char *fmt, ...)
 
 	va_start(va, fmt);
 	dev_err(&c->resources.unit->device, "%cPCR%u: %pV",
-		'i', c->pcr_index, &(struct va_format){ fmt, &va });
+		(c->direction == CMP_INPUT) ? 'i' : 'o',
+		c->pcr_index, &(struct va_format){ fmt, &va });
 	va_end(va);
 }
 
+static unsigned long long get_offset(struct cmp_connection *c, bool master)
+{
+	unsigned long long offset = CSR_REGISTER_BASE;
+
+	if (!master) {
+		if (c->direction == CMP_INPUT)
+			offset += CSR_IPCR(c->pcr_index);
+		else
+			offset += CSR_OPCR(c->pcr_index);
+	} else {
+		if (c->direction == CMP_INPUT)
+			offset += CSR_IMPR;
+		else
+			offset += CSR_OMPR;
+	}
+
+	return offset;
+}
+
 static int pcr_modify(struct cmp_connection *c,
 		      __be32 (*modify)(struct cmp_connection *c, __be32 old),
 		      int (*check)(struct cmp_connection *c, __be32 pcr),
@@ -60,8 +88,7 @@ static int pcr_modify(struct cmp_connection *c,
 
 		err = snd_fw_transaction(
 				c->resources.unit, TCODE_LOCK_COMPARE_SWAP,
-				CSR_REGISTER_BASE + CSR_IPCR(c->pcr_index),
-				buffer, 8,
+				get_offset(c, false), buffer, 8,
 				FW_FIXED_GENERATION | c->resources.generation);
 
 		if (err < 0) {
@@ -102,8 +129,7 @@ int cmp_connection_init(struct cmp_connection *c,
 	int err;
 
 	err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
-				 CSR_REGISTER_BASE + CSR_IMPR,
-				 &mpr_be, 4, 0);
+				 get_offset(c, true), &mpr_be, 4, 0);
 	if (err < 0)
 		return err;
 	mpr = be32_to_cpu(mpr_be);
@@ -122,6 +148,7 @@ int cmp_connection_init(struct cmp_connection *c,
 	c->max_speed = (mpr & MPR_SPEED_MASK) >> MPR_SPEED_SHIFT;
 	if (c->max_speed == SCODE_BETA)
 		c->max_speed += (mpr & MPR_XSPEED_MASK) >> MPR_XSPEED_SHIFT;
+	c->direction = direction;
 
 	return 0;
 }
@@ -151,6 +178,53 @@ static __be32 ipcr_set_modify(struct cmp_connection *c, __be32 ipcr)
 	return ipcr;
 }
 
+static int get_overhead_id(struct cmp_connection *c)
+{
+	int id;
+
+	/*
+	 * apply "oPCR overhead ID encoding"
+	 * the encoding table can convert up to 512.
+	 * here the value over 512 is converted as the same way as 512.
+	 */
+	for (id = 1; id < 16; id++) {
+		if (c->resources.bandwidth_overhead < (id << 5))
+			break;
+	}
+	if (id == 16)
+		id = 0;
+
+	return id;
+}
+
+static __be32 opcr_set_modify(struct cmp_connection *c, __be32 opcr)
+{
+	unsigned int spd, xspd;
+
+	/* generate speed and extended speed field value */
+	if (c->speed > SCODE_400) {
+		spd  = SCODE_800;
+		xspd = c->speed - SCODE_800;
+	} else {
+		spd = c->speed;
+		xspd = 0;
+	}
+
+	opcr &= ~cpu_to_be32(PCR_BCAST_CONN |
+			     PCR_P2P_CONN_MASK |
+			     OPCR_XSPEED_MASK |
+			     PCR_CHANNEL_MASK |
+			     OPCR_SPEED_MASK |
+			     OPCR_OVERHEAD_ID_MASK);
+	opcr |= cpu_to_be32(1 << PCR_P2P_CONN_SHIFT);
+	opcr |= cpu_to_be32(xspd << OPCR_XSPEED_SHIFT);
+	opcr |= cpu_to_be32(c->resources.channel << PCR_CHANNEL_SHIFT);
+	opcr |= cpu_to_be32(spd << OPCR_SPEED_SHIFT);
+	opcr |= cpu_to_be32(get_overhead_id(c) << OPCR_OVERHEAD_ID_SHIFT);
+
+	return opcr;
+}
+
 static int pcr_set_check(struct cmp_connection *c, __be32 pcr)
 {
 	if (pcr & cpu_to_be32(PCR_BCAST_CONN |
@@ -196,8 +270,13 @@ retry_after_bus_reset:
 	if (err < 0)
 		goto err_mutex;
 
-	err = pcr_modify(c, ipcr_set_modify, pcr_set_check,
-			 ABORT_ON_BUS_RESET);
+	if (c->direction == CMP_OUTPUT)
+		err = pcr_modify(c, opcr_set_modify, pcr_set_check,
+				 ABORT_ON_BUS_RESET);
+	else
+		err = pcr_modify(c, ipcr_set_modify, pcr_set_check,
+				 ABORT_ON_BUS_RESET);
+
 	if (err == -EAGAIN) {
 		fw_iso_resources_free(&c->resources);
 		goto retry_after_bus_reset;
@@ -245,8 +324,13 @@ int cmp_connection_update(struct cmp_connection *c)
 	if (err < 0)
 		goto err_unconnect;
 
-	err = pcr_modify(c, ipcr_set_modify, pcr_set_check,
-			 SUCCEED_ON_BUS_RESET);
+	if (c->direction == CMP_OUTPUT)
+		err = pcr_modify(c, opcr_set_modify, pcr_set_check,
+				 SUCCEED_ON_BUS_RESET);
+	else
+		err = pcr_modify(c, ipcr_set_modify, pcr_set_check,
+				 SUCCEED_ON_BUS_RESET);
+
 	if (err < 0)
 		goto err_resources;
 
Signature · 1 line
1.8.3.2
maintainer
#43 lore raw

PATCH 15/39 firewire-lib: Add a new function to check others' connection

In reply to Takashi Sakamoto

Plug Control Registers have two fields related to the number of established connections, one is 'Broadcast connection counter' and another is 'Point-to-point connection counter'. The driver can know there are established connections or not to check these fields.

This is considering for JACK/FFADO streaming. Currently, when JACK/FFADO starts its streaming to the device, cmp_connection_establish() is failed expectedly. This seems to be enough but there are some devices which needs to change samplling frequency before trying to establish connections. For such devices, this functionality is needed.

---
 sound/firewire/cmp.c | 18 ++++++++++++++++++
 sound/firewire/cmp.h |  1 +
 2 files changed, 19 insertions(+)
sound/firewire/cmp.c +18 -0
index 60d2e17..a8199fd 100644
@@ -155,6 +155,24 @@ int cmp_connection_init(struct cmp_connection *c,
 EXPORT_SYMBOL(cmp_connection_init);
 
 /**
+ * cmp_connection_check_used - check connection is already esablished or not
+ * @c: the connection manager to be checked
+ */
+int cmp_connection_check_used(struct cmp_connection *c, bool *used)
+{
+	__be32 pcr;
+	int err;
+
+	err = snd_fw_transaction(
+			c->resources.unit, TCODE_READ_QUADLET_REQUEST,
+			get_offset(c, false), &pcr, 4, 0);
+	if (err >= 0)
+		*used = (pcr & cpu_to_be32(PCR_BCAST_CONN | PCR_P2P_CONN_MASK));
+	return err;
+}
+EXPORT_SYMBOL(cmp_connection_check_used);
+
+/**
  * cmp_connection_destroy - free connection manager resources
  * @c: the connection manager
  */
sound/firewire/cmp.h +1 -0
index 9b58448..ebcb484 100644
@@ -38,6 +38,7 @@ int cmp_connection_init(struct cmp_connection *connection,
 			struct fw_unit *unit,
 			enum cmp_direction direction,
 			unsigned int pcr_index);
+int cmp_connection_check_used(struct cmp_connection *connection, bool *used);
 void cmp_connection_destroy(struct cmp_connection *connection);
 
 int cmp_connection_establish(struct cmp_connection *connection,
Signature · 1 line
1.8.3.2
maintainer
#44 lore raw

PATCH 16/39 firewire-lib: Add some AV/C general commands

In reply to Takashi Sakamoto

This commit adds three commands, which may be used by some firewire device drivers. These commands are defined in 'AV/C Digital Interface Command Set General Specification Version 4.2 (2004006, 1394TA)'.

1. PLUG INFO command (10.1)
2. INPUT PLUG SIGNAL FORMAT command (10.10)
3. OUTPUT PLUG SIGNAL FORMAT command (10.11)

By the command 1, the drivers can get the number of plugs for AV/C unit or subunit.
By the command 2 and 3, the drivers can get/set sampling frequency.

The 'firewire-speakers' already uses INPUT PLUG SIGNAL FORMAT command to set sampling rate. So this commit also affects the driver.

---
 sound/firewire/amdtp.c    |  24 +++----
 sound/firewire/amdtp.h    |   1 +
 sound/firewire/fcp.c      | 155 ++++++++++++++++++++++++++++++++++++++++++++++
 sound/firewire/fcp.h      |  21 +++++++
 sound/firewire/speakers.c |  44 +++----------
 5 files changed, 197 insertions(+), 48 deletions(-)
sound/firewire/amdtp.c +13 -11
index 57608f8..402b8e4 100644
@@ -115,6 +115,17 @@ const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = {
 };
 EXPORT_SYMBOL(amdtp_syt_intervals);
 
+const unsigned int amdtp_rate_table[] = {
+	[CIP_SFC_32000]  =  32000,
+	[CIP_SFC_44100]  =  44100,
+	[CIP_SFC_48000]  =  48000,
+	[CIP_SFC_88200]  =  88200,
+	[CIP_SFC_96000]  =  96000,
+	[CIP_SFC_176400] = 176400,
+	[CIP_SFC_192000] = 192000,
+};
+EXPORT_SYMBOL(amdtp_rate_table);
+
 /**
  * amdtp_stream_set_parameters - set stream parameters
  * @s: the AMDTP stream to configure
@@ -131,15 +142,6 @@ void amdtp_stream_set_parameters(struct amdtp_stream *s,
 				 unsigned int pcm_channels,
 				 unsigned int midi_ports)
 {
-	static const unsigned int rates[] = {
-		[CIP_SFC_32000]  =  32000,
-		[CIP_SFC_44100]  =  44100,
-		[CIP_SFC_48000]  =  48000,
-		[CIP_SFC_88200]  =  88200,
-		[CIP_SFC_96000]  =  96000,
-		[CIP_SFC_176400] = 176400,
-		[CIP_SFC_192000] = 192000,
-	};
 	unsigned int i, sfc, midi_channels;
 
 	midi_channels = DIV_ROUND_UP(midi_ports, 8);
@@ -149,8 +151,8 @@ void amdtp_stream_set_parameters(struct amdtp_stream *s,
 	    WARN_ON(midi_channels > AMDTP_MAX_CHANNELS_FOR_MIDI))
 		return;
 
-	for (sfc = 0; sfc < CIP_SFC_COUNT; ++sfc)
-		if (rates[sfc] == rate)
+	for (sfc = 0; sfc < sizeof(amdtp_rate_table); ++sfc)
+		if (amdtp_rate_table[sfc] == rate)
 			goto sfc_found;
 	WARN_ON(1);
 	return;
sound/firewire/amdtp.h +1 -0
index 2fb5175..861f509 100644
@@ -145,6 +145,7 @@ unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s);
 void amdtp_stream_pcm_abort(struct amdtp_stream *s);
 
 extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
+extern const unsigned int amdtp_rate_table[CIP_SFC_COUNT];
 
 /**
  * amdtp_stream_running - check stream is running or not
sound/firewire/fcp.c +155 -0

173 lines not on this page · raw message

sound/firewire/fcp.h +21 -0
index 8659568..cb62eb6 100644
@@ -1,8 +1,29 @@
 #ifndef SOUND_FIREWIRE_FCP_H_INCLUDED
 #define SOUND_FIREWIRE_FCP_H_INCLUDED
 
+#define	AVC_PLUG_INFO_BUF_COUNT	4
+
 struct fw_unit;
 
+/*
+ * AV/C Digital Interface Command Set General Specification 4.2
+ * (Sep 2004, 1394TA)
+ */
+enum avc_general_plug_dir {
+	AVC_GENERAL_PLUG_DIR_IN		= 0,
+	AVC_GENERAL_PLUG_DIR_OUT	= 1,
+	AVC_GENERAL_PLUG_DIR_COUNT
+};
+int avc_general_set_sig_fmt(struct fw_unit *unit, unsigned int rate,
+			    enum avc_general_plug_dir dir,
+			    unsigned short plug);
+int avc_general_get_sig_fmt(struct fw_unit *unit, unsigned int *rate,
+			    enum avc_general_plug_dir dir,
+			    unsigned short plug);
+int avc_general_get_plug_info(struct fw_unit *unit, unsigned int subunit_type,
+			      unsigned int subunit_id, unsigned int subfunction,
+			      u8 info[AVC_PLUG_INFO_BUF_COUNT]);
+
 int fcp_avc_transaction(struct fw_unit *unit,
 			const void *command, unsigned int command_size,
 			void *response, unsigned int response_size,
sound/firewire/speakers.c +7 -37

58 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#49 lore raw

PATCH 17/39 firewire-lib: Add quirks for Fireworks

In reply to Takashi Sakamoto

This commit adds three modifications for Echo Audio's Fireworks quirks.

1.Making this module to support both TAG0 and TAG1
In IEC 61883-1, each common isochronous packet (CIP) has 'tag' field in its packet header. The value is generally 0x01 (CIP header is included = TAG1). But Fireworks in 'IEC 61883 compliant' mode transmits 'no data' packet with 0x00 (No CIP header is included = TAG0) but the packet includes CIP structure. To process 'presentation timestamp' for duplex streams synchronization correctly, this packets needs to be handled.

2.Making this module to calculate data block size and not to check continuity One of Fireworks device, AudioFirePre8, always reports 8 data block size in in-packets and the data block counter is incremented by 8. But actual value is different.

3.Making this module to have the numebr of first data blocks for MIDI messages in out-packet
Fireworks can pick up MIDI messages in first 8 data blocks and ignore in other data blocks.

I confirm these quirks in firmware version between 4.8 and 5.8 with Windows. I didn't investigate for the other versions. But according to contact person in Echo Audio, there is no differences between firmwares installed by Windows or OS X.

---
 sound/firewire/amdtp.c | 50 +++++++++++++++++++++++++-------------------------
 sound/firewire/amdtp.h |  2 ++
 2 files changed, 27 insertions(+), 25 deletions(-)
sound/firewire/amdtp.c +25 -25
index 402b8e4..f961d26 100644
@@ -88,6 +88,8 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
 	s->sort_table = NULL;
 	s->left_packets = NULL;
 
+	s->blocks_for_midi = UINT_MAX;
+
 	return 0;
 }
 EXPORT_SYMBOL(amdtp_stream_init);
@@ -556,8 +558,14 @@ static void amdtp_fill_midi(struct amdtp_stream *s,
 		buffer[s->midi_position] = 0x00;
 		b = (u8 *)&buffer[s->midi_position];
 
+		/*
+		 * NOTE:
+		 * Fireworks ignores midi messages in more than first 8
+		 * data blocks of an packet.
+		 */
 		port = (s->data_block_counter + f) % 8;
-		if ((s->midi[port] == NULL) ||
+		if ((f >= s->blocks_for_midi) ||
+		    (s->midi[port] == NULL) ||
 		    (snd_rawmidi_transmit(s->midi[port], b + 1, 1) <= 0)) {
 			b[0] = 0x80;
 			b[1] = 0x00;	/* confirm to be zero */
@@ -710,7 +718,7 @@ static void handle_in_packet(struct amdtp_stream *s,
 			     __be32 *buffer)
 {
 	u32 cip_header[2];
-	unsigned int data_block_quadlets, data_blocks, data_block_counter;
+	unsigned int data_blocks;
 	struct snd_pcm_substream *pcm;
 
 	cip_header[0] = be32_to_cpu(buffer[0]);
@@ -735,27 +743,16 @@ static void handle_in_packet(struct amdtp_stream *s,
 							AMDTP_FDF_NO_DATA))
 		return;
 
-	data_block_quadlets =
-			(cip_header[1] & AMDTP_DBS_MASK) >> AMDTP_DBS_SHIFT;
-	/* avoid division by zero */
-	if (data_block_quadlets == 0) {
-		dev_info_ratelimited(&s->unit->device,
-				 "Detect invalid value in dbs field: %08X\n",
-				 data_block_quadlets);
-		return;
-	}
-
-	data_blocks = (payload_quadlets - 2) / data_block_quadlets;
-	data_block_counter = cip_header[1] & AMDTP_DBC_MASK;
-
-	/* check packet continuity */
-	s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;
-	if (s->data_block_counter != data_block_counter) {
-		dev_info_ratelimited(&s->unit->device,
-				     "Detect uncontinuity of CIP packets\n");
-		s->data_block_counter = data_block_counter;
-		return;
-	}
+	/*
+	 * This module don't use the value of dbs and dbc beceause Echo
+	 * AudioFirePre8 reports inappropriate value.
+	 *
+	 * This model always reports a fixed value "8" as data block size at
+	 * any sampling rates but actually data block size is different.
+	 * Additionally the value of data block count always incremented by
+	 * "8" at any sampling rates but actually it's different.
+	 */
+	data_blocks = (payload_quadlets - 2) / s->data_block_quadlets;
 
 	buffer += 2;
 
@@ -1033,11 +1030,14 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 			goto err_context;
 	} while (s->packet_index > 0);
 
-	/* NOTE: TAG1 matches CIP. This just affects in stream */
+	/*
+	 * NOTE: TAG1 matches CIP. This just affects in stream.
+	 * Fireworks transmits NODATA packets with TAG0.
+	 */
 	s->data_block_counter = 0;
 	s->callbacked = false;
 	err = fw_iso_context_start(s->context, -1, 0,
-				   FW_ISO_CONTEXT_MATCH_TAG1);
+			FW_ISO_CONTEXT_MATCH_TAG0 | FW_ISO_CONTEXT_MATCH_TAG1);
 	if (err < 0)
 		goto err_context;
 
sound/firewire/amdtp.h +2 -0
index 861f509..dce3903 100644
@@ -113,6 +113,8 @@ struct amdtp_stream {
 	bool pointer_flush;
 
 	struct snd_rawmidi_substream *midi[AMDTP_MAX_CHANNELS_FOR_MIDI * 8];
+	/* quirk: the first count of data blocks in an AMDTP packet for MIDI */
+	unsigned int blocks_for_midi;
 
 	bool callbacked;
 	wait_queue_head_t callback_wait;
Signature · 1 line
1.8.3.2
maintainer
#52 lore raw

PATCH 18/39 firewire-lib: Add a fallback at RCODE_CANCELLED

In reply to Takashi Sakamoto

I confirm that some devices often send no response against driver's request even if the devices handle the request. In this case, drivers should not retry the request because it's not clear whether the devices already handled an operation of the request or not. The second request may bring errors or make no sence if the request was handled.

This patch adds a flag, FW_RETURN_TIMEOUT, for snd_fw_transaction(). With this flag, this function returns -ETIMEOUT when fw_run_transaction() returns RCODE_CALCELLED.

For FCP, this patch modifies fcp_avc_transaction() with this flag. The -ETIMEDOUT is handled as success. Linux Firewire Subsystem currently gives 2,000msec for default timeout (See DEFAULT_SPLIT_TIMEOUT in core-card.c). firewire-lib gives 125msec for wait_event_timeout(). As a result, in worst case that all of three retries are timeout and devices don't send responses, fcp_avc_transaction() returns 6sec later ((2000 + 125) msec * 3 times). But this is rare.

For CMP, this patch modifies pcr_modify() with this flag. The -ETIMEOUT generates another read transaction to check current value of PCR. If this read transaction returns errors, then pcr_modify() returns the error code.

---
 sound/firewire/cmp.c | 23 +++++++++++++++++++++--
 sound/firewire/fcp.c |  5 +++--
 sound/firewire/lib.c |  6 +++++-
 sound/firewire/lib.h |  1 +
 4 files changed, 30 insertions(+), 5 deletions(-)
sound/firewire/cmp.c +21 -2
index a8199fd..73f5f26 100644
@@ -89,13 +89,32 @@ static int pcr_modify(struct cmp_connection *c,
 		err = snd_fw_transaction(
 				c->resources.unit, TCODE_LOCK_COMPARE_SWAP,
 				get_offset(c, false), buffer, 8,
-				FW_FIXED_GENERATION | c->resources.generation);
+				FW_FIXED_GENERATION | c->resources.generation |
+				FW_RETURN_TIMEOUT);
 
 		if (err < 0) {
 			if (err == -EAGAIN &&
 			    bus_reset_handling == SUCCEED_ON_BUS_RESET)
 				err = 0;
-			return err;
+
+			if (err != -ETIMEDOUT)
+				return err;
+
+			/* Check current PCR. */
+			err = snd_fw_transaction(
+				c->resources.unit, TCODE_READ_QUADLET_REQUEST,
+				get_offset(c, false), buffer, 4,
+				FW_FIXED_GENERATION | c->resources.generation);
+			if (err < 0)
+				return err;
+
+			/* The lock transaction may be failed, retry */
+			if (buffer[0] != buffer[1]) {
+				buffer[0] = c->last_pcr_value;
+				continue;
+			}
+
+			break;
 		}
 
 		if (buffer[0] == old_arg) /* success? */
sound/firewire/fcp.c +3 -2
index e903ddb..6fc813f 100644
@@ -245,8 +245,9 @@ int fcp_avc_transaction(struct fw_unit *unit,
 					  : TCODE_WRITE_BLOCK_REQUEST;
 		ret = snd_fw_transaction(t.unit, tcode,
 					 CSR_REGISTER_BASE + CSR_FCP_COMMAND,
-					 (void *)command, command_size, 0);
-		if (ret < 0)
+					 (void *)command, command_size,
+					 FW_RETURN_TIMEOUT);
+		if ((ret < 0) && (ret != -ETIMEDOUT))
 			break;
 
 		wait_event_timeout(t.wait, t.state != STATE_PENDING,
sound/firewire/lib.c +5 -1
index 7409edb..de42748 100644
@@ -22,7 +22,7 @@
  * @length: length of @buffer
  * @flags: use %FW_FIXED_GENERATION and add the generation value to attempt the
  *         request only in that generation; use %FW_QUIET to suppress error
- *         messages
+ *         messages; use %FW_RETURN_TIMEOUT to avoid retry at RCODE_CANCELLED
  *
  * Submits an asynchronous request to the target device, and waits for the
  * response.  The node ID and the current generation are derived from @unit.
@@ -53,6 +53,10 @@ int snd_fw_transaction(struct fw_unit *unit, int tcode,
 		if (rcode == RCODE_GENERATION && (flags & FW_FIXED_GENERATION))
 			return -EAGAIN;
 
+		/* timeout */
+		if ((rcode == RCODE_CANCELLED) && (flags & FW_RETURN_TIMEOUT))
+			return -ETIMEDOUT;
+
 		if (rcode_is_permanent_error(rcode) || ++tries >= 3) {
 			if (!(flags & FW_QUIET))
 				dev_err(&unit->device,
sound/firewire/lib.h +1 -0
index 02cfabc..b8ea90b 100644
@@ -9,6 +9,7 @@ struct fw_unit;
 #define FW_GENERATION_MASK	0x00ff
 #define FW_FIXED_GENERATION	0x0100
 #define FW_QUIET		0x0200
+#define FW_RETURN_TIMEOUT	0x0400
 
 int snd_fw_transaction(struct fw_unit *unit, int tcode,
 		       u64 offset, void *buffer, size_t length,
Signature · 1 line
1.8.3.2
maintainer
#53 lore raw

PATCH 19/39 fireworks: Add skelton for Fireworks based devices

In reply to Takashi Sakamoto

This commit adds a new driver with no functionality. This driver just creates/removes card instance according to callbacks.

Fireworks is a board module which Echo Audio produced. This module consists of three chipsets:
- Communication chipset for IEEE1394 PHY/Link and IEC 61883-1/6
- DSP or/and FPGA for signal processing
- Flash Memory to store firmwares

Current supported devices:
- Mackie Onyx 400F/1200F
- Echo AudioFire12/8(until 2009 July)
- Echo AudioFire2/4/Pre8/8(since 2009 July)
- Echo Fireworks 8/HDMI
- Gibson Robot Interface pack/GoldTop

---
 sound/firewire/Kconfig               |  14 +++
 sound/firewire/Makefile              |   1 +
 sound/firewire/fireworks/Makefile    |   2 +
 sound/firewire/fireworks/fireworks.c | 180 +++++++++++++++++++++++++++++++++++
 sound/firewire/fireworks/fireworks.h |  41 ++++++++
 5 files changed, 238 insertions(+)
 create mode 100644 sound/firewire/fireworks/Makefile
 create mode 100644 sound/firewire/fireworks/fireworks.c
 create mode 100644 sound/firewire/fireworks/fireworks.h
sound/firewire/Kconfig +14 -0
index b3e274f..8cd4f1f 100644
@@ -61,4 +61,18 @@ config SND_SCS1X
 	  To compile this driver as a module, choose M here: the module
 	  will be called snd-scs1x.
 
+config SND_FIREWORKS
+	tristate "Echo Fireworks board module support"
+	help
+	  Say Y here to include support for FireWire devices based
+	  on Echo Digital Audio Fireworks board:
+	   * Mackie Onyx 400F/1200F
+	   * Echo AudioFire12/8(until 2009 July)
+	   * Echo AudioFire2/4/Pre8/8(since 2009 July)
+	   * Echo Fireworks 8/HDMI
+	   * Gibson Robot Interface Pack/GoldTop
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called snd-fireworks.
+
 endif # SND_FIREWIRE
sound/firewire/Makefile +1 -0
index 5099550..5cd39dc 100644
@@ -10,3 +10,4 @@ obj-$(CONFIG_SND_DICE) += snd-dice.o
 obj-$(CONFIG_SND_FIREWIRE_SPEAKERS) += snd-firewire-speakers.o
 obj-$(CONFIG_SND_ISIGHT) += snd-isight.o
 obj-$(CONFIG_SND_SCS1X) += snd-scs1x.o
+obj-$(CONFIG_SND_FIREWORKS) += fireworks/
sound/firewire/fireworks/Makefile new file +2 -0
new file mode 100644
index 0000000..99f6fc3
@@ -0,0 +1,2 @@
+snd-fireworks-objs := fireworks.o
+obj-m += snd-fireworks.o
sound/firewire/fireworks/fireworks.c new file +180 -0

180 lines not on this page · raw message

sound/firewire/fireworks/fireworks.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#54 lore raw

PATCH 20/39 fireworks: Add transaction and some commands

In reply to Takashi Sakamoto

Fireworks uses own command and response. This commit adds functionality to transact and adds some commands required for sound card instance and kernel streaming.

There are two ways to deliver substance of this transaction:
1.AV/C vendor dependent command for command/response 2.Async transaction to specific addresses for command/response

By way 1, I confirm AudioFire12 cannot correctly response to some commands with firmware version 5.0 or later. This is also confirmed by FFADO. So this driver implement way 2.

The address for response gives an issue. When this driver allocate own callback function into the address, then no one can allocate its own callback function. This situation is not good for applications in user-land. This issue is solved in later commit.

I note there is a command to change the address for response if the device supports. But this driver uses default value. So users should not execute this command as long as hoping this driver works correctly.

---
 sound/firewire/Kconfig                           |   1 +
 sound/firewire/fireworks/Makefile                |   2 +-
 sound/firewire/fireworks/fireworks.c             |  74 ++++-
 sound/firewire/fireworks/fireworks.h             | 120 +++++++
 sound/firewire/fireworks/fireworks_command.c     | 395 +++++++++++++++++++++++
 sound/firewire/fireworks/fireworks_transaction.c | 191 +++++++++++
 6 files changed, 773 insertions(+), 10 deletions(-)
 create mode 100644 sound/firewire/fireworks/fireworks_command.c
 create mode 100644 sound/firewire/fireworks/fireworks_transaction.c
sound/firewire/Kconfig +1 -0
index 8cd4f1f..0b85ebd 100644
@@ -63,6 +63,7 @@ config SND_SCS1X
 
 config SND_FIREWORKS
 	tristate "Echo Fireworks board module support"
+	select SND_FIREWIRE_LIB
 	help
 	  Say Y here to include support for FireWire devices based
 	  on Echo Digital Audio Fireworks board:
sound/firewire/fireworks/Makefile +1 -1
index 99f6fc3..a6ce214 100644
@@ -1,2 +1,2 @@
-snd-fireworks-objs := fireworks.o
+snd-fireworks-objs := fireworks_transaction.o fireworks_command.o fireworks.o
 obj-m += snd-fireworks.o
sound/firewire/fireworks/fireworks.c +65 -9

108 lines not on this page · raw message

sound/firewire/fireworks/fireworks.h +120 -0

133 lines not on this page · raw message

sound/firewire/fireworks/fireworks_command.c new file +395 -0

395 lines not on this page · raw message

sound/firewire/fireworks/fireworks_transaction.c new file +191 -0

191 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#55 lore raw

PATCH 21/39 fireworks: Add connection and stream management

In reply to Takashi Sakamoto

Fireworks manages connections by CMP and can transmit/receive AMDTP streams with a few quirks. This commit adds functionality to start/stop the streams.

Major Fireworks products don't support 'SYT-Match' modes, except for AudioFire12/8(till 2009 July) with firmware version 1.0. Already in previous commit, this driver don't support such old firmwares. So this commit adds support for non 'SYT-Match' modes.

I note that this driver has a short gap for MIDI streams when starting PCM stream. When AMDTP streams are running only for MIDI data and PCM data is going to be joined at different sampling rate, then AMDTP streams are stopped once and started again after changing sampling rate.

Fireworks quirks:

1.Fireworks transmits packets with both TAG0 and TAG1
In IEC 61883-1, each common isochronous packet (CIP) has 'tag' field in its packet header. The value is generally 0x01 ('CIP header is included' = TAG1). But Fireworks in 'IEC 61883 compliant mode' transmits 'no data' packet with 0x00 ('No CIP header is included' = TAG0) but actually the packet includes CIP structure. To handle 'presentation timestamp' for duplex streams synchronization, this packets must be handled.

2.Fireworks transmits 'no data' packet out of specification Fireworks transmits 'no data' packet with 'NO-DATA' FDF and no dummy data. It includes CIP headers only. In IEC 61883-6, 'no data' packet is generated by two ways. One is empty CIP packet defined in IEC 61883-1. Another is 'special non-empty packet' defined in IEC 61883-6. Fireworks uses strange combination of them.

3.Fireworks transmits packets with a bit disorder
A sequence of DBC field in packets transmitted by Fireworks includes a bit disorder. See logs in the end of this commit.

4.Fireworks can handle MIDI messages in the first 8 data blocks of out-packet Fireworks ignores MIDI messages in other data blocks.

5.AudioFirePre8 transmits packets with wrong data block size
One of Fireworks device, AudioFirePre8, always reports 8 data block size in transmitted packets and increments the data block counter by 8. But this is not actual value.

I confirm them with firmware version 4.8 or later with Windows. According to a contact persion in Echo Audio, there is no difference between firmwares installed by Windows/OS X.

Here, an example of a sequence of packets transmitted by Fireworks:

Index  Payload  CIP header 1  CIP header 2
023    210      3F1100F8      900478E9
024    002      3F1100F8      90FFFFFF
025    210      3F110000      900490E9
026    210      3F110008      9004A4E9
027    210      3F110010      9004B8E9
028    002      3F110010      90FFFFFF
029    210      3F110020      9004E4E8 <-
030    210      3F110018      9004D0E8 <-
031    210      3F110028      9004F8E8
032    002      3F110028      90FFFFFF
033    210      3F110030      900410E8
034    210      3F110038      900424E8
035    210      3F110040      900438E8
036    002      3F110040      90FFFFFF
037    210      3F110050      900464E8 <-
038    210      3F110048      900450E8 <-
039    210      3F110058      900478E8
040    002      3F110058      90FFFFFF
041    210      3F110068      9004A4E8 <-
042    210      3F110060      900490E8 <-
043    210      3F110070      9004B8E8
044    002      3F110070      90FFFFFF
045    210      3F110080      9004E4E7 <-
046    210      3F110078      9004D0E8 <-
---
 sound/firewire/fireworks/Makefile           |   3 +-
 sound/firewire/fireworks/fireworks.c        |  46 ++++
 sound/firewire/fireworks/fireworks.h        |  28 +++
 sound/firewire/fireworks/fireworks_stream.c | 331 ++++++++++++++++++++++++++++
 4 files changed, 407 insertions(+), 1 deletion(-)
 create mode 100644 sound/firewire/fireworks/fireworks_stream.c
sound/firewire/fireworks/Makefile +2 -1
index a6ce214..1bccb65 100644
@@ -1,2 +1,3 @@
-snd-fireworks-objs := fireworks_transaction.o fireworks_command.o fireworks.o
+snd-fireworks-objs := fireworks_transaction.o fireworks_command.o \
+		      fireworks_stream.o fireworks.o
 obj-m += snd-fireworks.o
sound/firewire/fireworks/fireworks.c +46 -0

71 lines not on this page · raw message

sound/firewire/fireworks/fireworks.h +28 -0
index 751302d..c022c71 100644
@@ -22,9 +22,15 @@
 #include <sound/initval.h>
 #include <sound/pcm.h>
 
+#include "../packets-buffer.h"
+#include "../iso-resources.h"
+#include "../amdtp.h"
 #include "../cmp.h"
 #include "../lib.h"
 
+#define SND_EFW_MAX_MIDI_OUT_PORTS	2
+#define SND_EFW_MAX_MIDI_IN_PORTS	2
+
 #define SND_EFW_MUITIPLIER_MODES	3
 #define HWINFO_NAME_SIZE_BYTES		32
 #define HWINFO_MAX_CAPS_GROUPS		8
@@ -45,6 +51,20 @@ struct snd_efw {
 	/* for transaction */
 	u32 seqnum;
 	bool resp_addr_changable;
+
+	unsigned int midi_in_ports;
+	unsigned int midi_out_ports;
+
+	unsigned int supported_sampling_rate;
+	unsigned int pcm_capture_channels[SND_EFW_MUITIPLIER_MODES];
+	unsigned int pcm_playback_channels[SND_EFW_MUITIPLIER_MODES];
+
+	struct amdtp_stream tx_stream;
+	struct amdtp_stream rx_stream;
+	struct cmp_connection out_conn;
+	struct cmp_connection in_conn;
+	unsigned int capture_substreams;
+	unsigned int playback_substreams;
 };
 
 struct snd_efw_transaction {
@@ -150,6 +170,14 @@ int snd_efw_command_set_clock_source(struct snd_efw *efw,
 int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
 int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
 
+int snd_efw_stream_init_duplex(struct snd_efw *efw);
+int snd_efw_stream_start_duplex(struct snd_efw *efw,
+				struct amdtp_stream *request,
+				int sampling_rate);
+int snd_efw_stream_stop_duplex(struct snd_efw *efw);
+void snd_efw_stream_update_duplex(struct snd_efw *efw);
+void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
+
 #define SND_EFW_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/fireworks/fireworks_stream.c new file +331 -0

331 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#56 lore raw

PATCH 22/39 fireworks: Add proc interface for debugging purpose

In reply to Takashi Sakamoto

This commit adds proc interface to output infomation for debugging.
- firmware information
- sampling rate and clock source
- physical metering (linear value)

---
 sound/firewire/fireworks/Makefile         |   2 +-
 sound/firewire/fireworks/fireworks.c      |  14 +-
 sound/firewire/fireworks/fireworks.h      |  11 ++
 sound/firewire/fireworks/fireworks_proc.c | 215 ++++++++++++++++++++++++++++++
 4 files changed, 239 insertions(+), 3 deletions(-)
 create mode 100644 sound/firewire/fireworks/fireworks_proc.c
sound/firewire/fireworks/Makefile +1 -1
index 1bccb65..52bd15e 100644
@@ -1,3 +1,3 @@
 snd-fireworks-objs := fireworks_transaction.o fireworks_command.o \
-		      fireworks_stream.o fireworks.o
+		      fireworks_stream.o fireworks_proc.o fireworks.o
 obj-m += snd-fireworks.o
sound/firewire/fireworks/fireworks.c +12 -2
index e483b55..52adce0 100644
@@ -130,6 +130,16 @@ get_hardware_info(struct snd_efw *efw)
 	efw->pcm_playback_channels[0] = hwinfo->amdtp_rx_pcm_channels;
 	efw->pcm_playback_channels[1] = hwinfo->amdtp_rx_pcm_channels_2x;
 	efw->pcm_playback_channels[2] = hwinfo->amdtp_rx_pcm_channels_4x;
+
+	/* hardware metering */
+	efw->phys_out = hwinfo->phys_out;
+	efw->phys_in = hwinfo->phys_in;
+	efw->phys_out_grp_count = hwinfo->phys_out_grp_count;
+	efw->phys_in_grp_count = hwinfo->phys_in_grp_count;
+	memcpy(&efw->phys_out_grps, hwinfo->phys_out_grps,
+	       sizeof(struct snd_efw_phys_grp) * HWINFO_MAX_CAPS_GROUPS);
+	memcpy(&efw->phys_in_grps, hwinfo->phys_in_grps,
+	       sizeof(struct snd_efw_phys_grp) * HWINFO_MAX_CAPS_GROUPS);
 end:
 	kfree(hwinfo);
 	return err;
@@ -189,6 +199,8 @@ efw_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto error;
 
+	snd_efw_proc_init(efw);
+
 	err = snd_card_register(card);
 	if (err < 0)
 		goto error;
@@ -211,8 +223,6 @@ static void efw_update(struct fw_unit *unit)
 
 	snd_efw_transaction_bus_reset(efw->unit);
 	snd_efw_stream_update_duplex(efw);
-
-	return;
 }
 
 static void efw_remove(struct fw_unit *unit)
sound/firewire/fireworks/fireworks.h +11 -0
index c022c71..4d69c0d 100644
@@ -21,6 +21,7 @@
 #include <sound/core.h>
 #include <sound/initval.h>
 #include <sound/pcm.h>
+#include <sound/info.h>
 
 #include "../packets-buffer.h"
 #include "../iso-resources.h"
@@ -65,6 +66,14 @@ struct snd_efw {
 	struct cmp_connection in_conn;
 	unsigned int capture_substreams;
 	unsigned int playback_substreams;
+
+	/* hardware metering parameters */
+	unsigned int phys_out;
+	unsigned int phys_in;
+	unsigned int phys_out_grp_count;
+	unsigned int phys_in_grp_count;
+	struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
+	struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
 };
 
 struct snd_efw_transaction {
@@ -178,6 +187,8 @@ int snd_efw_stream_stop_duplex(struct snd_efw *efw);
 void snd_efw_stream_update_duplex(struct snd_efw *efw);
 void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
 
+void snd_efw_proc_init(struct snd_efw *efw);
+
 #define SND_EFW_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/fireworks/fireworks_proc.c new file +215 -0

215 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#57 lore raw

PATCH 23/39 fireworks: Add MIDI interface

In reply to Takashi Sakamoto

This commit adds a functionality to capture/playback MIDI messages.

When no AMDTP streams are running, this driver starts AMDTP stream for MIDI stream at current sampling rate.

---
 sound/firewire/Kconfig                    |   1 +
 sound/firewire/fireworks/Makefile         |   3 +-
 sound/firewire/fireworks/fireworks.c      |   6 ++
 sound/firewire/fireworks/fireworks.h      |   3 +
 sound/firewire/fireworks/fireworks_midi.c | 158 ++++++++++++++++++++++++++++++
 5 files changed, 170 insertions(+), 1 deletion(-)
 create mode 100644 sound/firewire/fireworks/fireworks_midi.c
sound/firewire/Kconfig +1 -0
index 0b85ebd..36a1212 100644
@@ -64,6 +64,7 @@ config SND_SCS1X
 config SND_FIREWORKS
 	tristate "Echo Fireworks board module support"
 	select SND_FIREWIRE_LIB
+	select SND_RAWMIDI
 	help
 	  Say Y here to include support for FireWire devices based
 	  on Echo Digital Audio Fireworks board:
sound/firewire/fireworks/Makefile +2 -1
index 52bd15e..a2cecc6 100644
@@ -1,3 +1,4 @@
 snd-fireworks-objs := fireworks_transaction.o fireworks_command.o \
-		      fireworks_stream.o fireworks_proc.o fireworks.o
+		      fireworks_stream.o fireworks_proc.o fireworks_midi.o \
+		      fireworks.o
 obj-m += snd-fireworks.o
sound/firewire/fireworks/fireworks.c +6 -0
index 52adce0..85dbad3 100644
@@ -201,6 +201,12 @@ efw_probe(struct fw_unit *unit,
 
 	snd_efw_proc_init(efw);
 
+	if (efw->midi_out_ports || efw->midi_in_ports) {
+		err = snd_efw_create_midi_devices(efw);
+		if (err < 0)
+			goto error;
+	}
+
 	err = snd_card_register(card);
 	if (err < 0)
 		goto error;
sound/firewire/fireworks/fireworks.h +3 -0
index 4d69c0d..0dfed97 100644
@@ -22,6 +22,7 @@
 #include <sound/initval.h>
 #include <sound/pcm.h>
 #include <sound/info.h>
+#include <sound/rawmidi.h>
 
 #include "../packets-buffer.h"
 #include "../iso-resources.h"
@@ -189,6 +190,8 @@ void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
 
 void snd_efw_proc_init(struct snd_efw *efw);
 
+int snd_efw_create_midi_devices(struct snd_efw *efw);
+
 #define SND_EFW_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/fireworks/fireworks_midi.c new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#58 lore raw

PATCH 24/39 fireworks: Add PCM interface

In reply to Takashi Sakamoto

This commit adds a functionality to capture/playback PCM samples.

When AMDTP stream is already running for PCM or the source of clock is not internal, available sampling rate is limited at current one.

---
 sound/firewire/Kconfig                      |   1 +
 sound/firewire/fireworks/Makefile           |   2 +-
 sound/firewire/fireworks/fireworks.c        |   4 +
 sound/firewire/fireworks/fireworks.h        |   4 +
 sound/firewire/fireworks/fireworks_pcm.c    | 468 ++++++++++++++++++++++++++++
 sound/firewire/fireworks/fireworks_stream.c |  33 --
 6 files changed, 478 insertions(+), 34 deletions(-)
 create mode 100644 sound/firewire/fireworks/fireworks_pcm.c
sound/firewire/Kconfig +1 -0
index 36a1212..fb39f9c 100644
@@ -65,6 +65,7 @@ config SND_FIREWORKS
 	tristate "Echo Fireworks board module support"
 	select SND_FIREWIRE_LIB
 	select SND_RAWMIDI
+	select SND_PCM
 	help
 	  Say Y here to include support for FireWire devices based
 	  on Echo Digital Audio Fireworks board:
sound/firewire/fireworks/Makefile +1 -1
index a2cecc6..d7ebf83 100644
@@ -1,4 +1,4 @@
 snd-fireworks-objs := fireworks_transaction.o fireworks_command.o \
 		      fireworks_stream.o fireworks_proc.o fireworks_midi.o \
-		      fireworks.o
+		      fireworks_pcm.o fireworks.o
 obj-m += snd-fireworks.o
sound/firewire/fireworks/fireworks.c +4 -0
index 85dbad3..2d3d1ed 100644
@@ -207,6 +207,10 @@ efw_probe(struct fw_unit *unit,
 			goto error;
 	}
 
+	err = snd_efw_create_pcm_devices(efw);
+	if (err < 0)
+		goto error;
+
 	err = snd_card_register(card);
 	if (err < 0)
 		goto error;
sound/firewire/fireworks/fireworks.h +4 -0
index 0dfed97..11d42cc 100644
@@ -23,6 +23,7 @@
 #include <sound/pcm.h>
 #include <sound/info.h>
 #include <sound/rawmidi.h>
+#include <sound/pcm_params.h>
 
 #include "../packets-buffer.h"
 #include "../iso-resources.h"
@@ -192,6 +193,9 @@ void snd_efw_proc_init(struct snd_efw *efw);
 
 int snd_efw_create_midi_devices(struct snd_efw *efw);
 
+int snd_efw_create_pcm_devices(struct snd_efw *efw);
+int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
+
 #define SND_EFW_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/fireworks/fireworks_pcm.c new file +468 -0

468 lines not on this page · raw message

sound/firewire/fireworks/fireworks_stream.c +0 -33
index f41aee4..7ff4406 100644
@@ -9,39 +9,6 @@
 
 #define CALLBACK_TIMEOUT	100
 
-static unsigned int freq_table[] = {
-	/* multiplier mode 0 */
-	[0] = 32000,
-	[1] = 44100,
-	[2] = 48000,
-	/* multiplier mode 1 */
-	[3] = 88200,
-	[4] = 96000,
-	/* multiplier mode 2 */
-	[5] = 176400,
-	[6] = 192000,
-};
-
-static inline unsigned int
-get_multiplier_mode_with_index(unsigned int index)
-{
-	return ((int)index - 1) / 2;
-}
-
-int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode)
-{
-	unsigned int i;
-
-	for (i = 0; i < sizeof(freq_table); i++) {
-		if (freq_table[i] == sampling_rate) {
-			*mode = get_multiplier_mode_with_index(i);
-			return 0;
-		}
-	}
-
-	return -EINVAL;
-}
-
 static int
 init_stream(struct snd_efw *efw, struct amdtp_stream *stream)
 {
Signature · 1 line
1.8.3.2
maintainer
#59 lore raw

PATCH 25/39 fireworks: Add hwdep interface

In reply to Takashi Sakamoto

This interface is designed for mixer/control application. To use hwdep interface, the application can get information about firewire node, can lock/unlock kernel streaming and can get notification at starting/stopping kernel streaming.

---
 include/uapi/sound/asound.h                 |   3 +-
 include/uapi/sound/firewire.h               |   3 +-
 sound/firewire/Kconfig                      |   1 +
 sound/firewire/fireworks/Makefile           |   2 +-
 sound/firewire/fireworks/fireworks.c        |   5 +
 sound/firewire/fireworks/fireworks.h        |  12 ++
 sound/firewire/fireworks/fireworks_hwdep.c  | 197 ++++++++++++++++++++++++++++
 sound/firewire/fireworks/fireworks_midi.c   |  25 +++-
 sound/firewire/fireworks/fireworks_pcm.c    |  15 ++-
 sound/firewire/fireworks/fireworks_stream.c |  39 ++++++
 10 files changed, 294 insertions(+), 8 deletions(-)
 create mode 100644 sound/firewire/fireworks/fireworks_hwdep.c
include/uapi/sound/asound.h +2 -1
index 9fc6219..5dfbfdf 100644
@@ -94,9 +94,10 @@ enum {
 	SNDRV_HWDEP_IFACE_HDA,		/* HD-audio */
 	SNDRV_HWDEP_IFACE_USB_STREAM,	/* direct access to usb stream */
 	SNDRV_HWDEP_IFACE_FW_DICE,	/* TC DICE FireWire device */
+	SNDRV_HWDEP_IFACE_FW_FIREWORKS,	/* Echo Audio Fireworks based device */
 
 	/* Don't forget to change the following: */
-	SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_DICE
+	SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_FIREWORKS
 };
 
 struct snd_hwdep_info {
include/uapi/sound/firewire.h +2 -1
index 59f5961..fc9afb2 100644
@@ -34,7 +34,8 @@ union snd_firewire_event {
 #define SNDRV_FIREWIRE_IOCTL_UNLOCK    _IO('H', 0xfa)
 
 #define SNDRV_FIREWIRE_TYPE_DICE	1
-/* Fireworks, AV/C, RME, MOTU, ... */
+#define SNDRV_FIREWIRE_TYPE_FIREWORKS	2
+/* AV/C, RME, MOTU, ... */
 
 struct snd_firewire_get_info {
 	unsigned int type; /* SNDRV_FIREWIRE_TYPE_xxx */
sound/firewire/Kconfig +1 -0
index fb39f9c..875af02 100644
@@ -66,6 +66,7 @@ config SND_FIREWORKS
 	select SND_FIREWIRE_LIB
 	select SND_RAWMIDI
 	select SND_PCM
+	select SND_HWDEP
 	help
 	  Say Y here to include support for FireWire devices based
 	  on Echo Digital Audio Fireworks board:
sound/firewire/fireworks/Makefile +1 -1
index d7ebf83..0c74408 100644
@@ -1,4 +1,4 @@
 snd-fireworks-objs := fireworks_transaction.o fireworks_command.o \
 		      fireworks_stream.o fireworks_proc.o fireworks_midi.o \
-		      fireworks_pcm.o fireworks.o
+		      fireworks_pcm.o fireworks_hwdep.o fireworks.o
 obj-m += snd-fireworks.o
sound/firewire/fireworks/fireworks.c +5 -0
index 2d3d1ed..6e7536c 100644
@@ -190,6 +190,7 @@ efw_probe(struct fw_unit *unit,
 	efw->card_index = -1;
 	mutex_init(&efw->mutex);
 	spin_lock_init(&efw->lock);
+	init_waitqueue_head(&efw->hwdep_wait);
 
 	err = get_hardware_info(efw);
 	if (err < 0)
@@ -211,6 +212,10 @@ efw_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto error;
 
+	err = snd_efw_create_hwdep_device(efw);
+	if (err < 0)
+		goto error;
+
 	err = snd_card_register(card);
 	if (err < 0)
 		goto error;
sound/firewire/fireworks/fireworks.h +12 -0
index 11d42cc..4ab4887 100644
@@ -24,6 +24,8 @@
 #include <sound/info.h>
 #include <sound/rawmidi.h>
 #include <sound/pcm_params.h>
+#include <sound/firewire.h>
+#include <sound/hwdep.h>
 
 #include "../packets-buffer.h"
 #include "../iso-resources.h"
@@ -76,6 +78,11 @@ struct snd_efw {
 	unsigned int phys_in_grp_count;
 	struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
 	struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
+
+	/* for uapi */
+	int dev_lock_count;
+	bool dev_lock_changed;
+	wait_queue_head_t hwdep_wait;
 };
 
 struct snd_efw_transaction {
@@ -188,6 +195,9 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw,
 int snd_efw_stream_stop_duplex(struct snd_efw *efw);
 void snd_efw_stream_update_duplex(struct snd_efw *efw);
 void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
+void snd_efw_stream_lock_changed(struct snd_efw *efw);
+int snd_efw_stream_lock_try(struct snd_efw *efw);
+void snd_efw_stream_lock_release(struct snd_efw *efw);
 
 void snd_efw_proc_init(struct snd_efw *efw);
 
@@ -196,6 +206,8 @@ int snd_efw_create_midi_devices(struct snd_efw *efw);
 int snd_efw_create_pcm_devices(struct snd_efw *efw);
 int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
 
+int snd_efw_create_hwdep_device(struct snd_efw *efw);
+
 #define SND_EFW_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/fireworks/fireworks_hwdep.c new file +197 -0

197 lines not on this page · raw message

sound/firewire/fireworks/fireworks_midi.c +23 -2
index a950fd1..2924599 100644
@@ -11,17 +11,36 @@
 static int midi_capture_open(struct snd_rawmidi_substream *substream)
 {
 	struct snd_efw *efw = substream->rmidi->private_data;
+	int err;
+
+	err = snd_efw_stream_lock_try(efw);
+	if (err < 0)
+		goto end;
 
 	efw->capture_substreams++;
-	return snd_efw_stream_start_duplex(efw, &efw->tx_stream, 0);
+	err = snd_efw_stream_start_duplex(efw, &efw->tx_stream, 0);
+	if (err < 0)
+		snd_efw_stream_lock_release(efw);
+
+end:
+	return err;
 }
 
 static int midi_playback_open(struct snd_rawmidi_substream *substream)
 {
 	struct snd_efw *efw = substream->rmidi->private_data;
+	int err;
+
+	err = snd_efw_stream_lock_try(efw);
+	if (err < 0)
+		goto end;
 
 	efw->playback_substreams++;
-	return snd_efw_stream_start_duplex(efw, &efw->rx_stream, 0);
+	err = snd_efw_stream_start_duplex(efw, &efw->rx_stream, 0);
+	if (err < 0)
+		snd_efw_stream_lock_release(efw);
+end:
+	return err;
 }
 
 static int midi_capture_close(struct snd_rawmidi_substream *substream)
@@ -31,6 +50,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
 	efw->capture_substreams--;
 	snd_efw_stream_stop_duplex(efw);
 
+	snd_efw_stream_lock_release(efw);
 	return 0;
 }
 
@@ -41,6 +61,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
 	efw->playback_substreams--;
 	snd_efw_stream_stop_duplex(efw);
 
+	snd_efw_stream_lock_release(efw);
 	return 0;
 }
 
sound/firewire/fireworks/fireworks_pcm.c +12 -3
index 88c1d53..5ea33b9 100644
@@ -273,13 +273,17 @@ static int pcm_open(struct snd_pcm_substream *substream)
 	unsigned int clock_source;
 	int err;
 
-	err = pcm_init_hw_params(efw, substream);
+	err = snd_efw_stream_lock_try(efw);
 	if (err < 0)
 		goto end;
 
+	err = pcm_init_hw_params(efw, substream);
+	if (err < 0)
+		goto err_locked;
+
 	err = snd_efw_command_get_clock_source(efw, &clock_source);
 	if (err < 0)
-		goto end;
+		goto err_locked;
 
 	/*
 	 * When source of clock is not internal or any PCM streams are running,
@@ -290,7 +294,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
 	    amdtp_stream_pcm_running(&efw->rx_stream)) {
 		err = snd_efw_command_get_sampling_rate(efw, &sampling_rate);
 		if (err < 0)
-			goto end;
+			goto err_locked;
 		substream->runtime->hw.rate_min = sampling_rate;
 		substream->runtime->hw.rate_max = sampling_rate;
 	}
@@ -298,10 +302,15 @@ static int pcm_open(struct snd_pcm_substream *substream)
 	snd_pcm_set_sync(substream);
 end:
 	return err;
+err_locked:
+	snd_efw_stream_lock_release(efw);
+	return err;
 }
 
 static int pcm_close(struct snd_pcm_substream *substream)
 {
+	struct snd_efw *efw = substream->private_data;
+	snd_efw_stream_lock_release(efw);
 	return 0;
 }
 
sound/firewire/fireworks/fireworks_stream.c +39 -0
index 7ff4406..b07ea1e 100644
@@ -296,3 +296,42 @@ void snd_efw_stream_destroy_duplex(struct snd_efw *efw)
 
 	mutex_unlock(&efw->mutex);
 }
+
+void snd_efw_stream_lock_changed(struct snd_efw *efw)
+{
+	efw->dev_lock_changed = true;
+	wake_up(&efw->hwdep_wait);
+}
+
+int snd_efw_stream_lock_try(struct snd_efw *efw)
+{
+	int err;
+
+	spin_lock_irq(&efw->lock);
+
+	/* user land lock this */
+	if (efw->dev_lock_count < 0) {
+		err = -EBUSY;
+		goto end;
+	}
+
+	/* this is the first time */
+	if (efw->dev_lock_count++ == 0)
+		snd_efw_stream_lock_changed(efw);
+	err = 0;
+end:
+	spin_unlock_irq(&efw->lock);
+	return err;
+}
+
+void snd_efw_stream_lock_release(struct snd_efw *efw)
+{
+	spin_lock_irq(&efw->lock);
+
+	if (WARN_ON(efw->dev_lock_count <= 0))
+		goto end;
+	if (--efw->dev_lock_count == 0)
+		snd_efw_stream_lock_changed(efw);
+end:
+	spin_unlock_irq(&efw->lock);
+}
Signature · 1 line
1.8.3.2
maintainer
#60 lore raw

PATCH 26/39 fireworks: Add command/response functionality into hwdep interface

In reply to Takashi Sakamoto

This commit adds two functionality for hwdep interface, adds two parameters for this driver, add a node for proc interface.

To receive responses from devices, this driver already allocate own callback into initial memory space in host controller. This means no one can allocate its own callback to the address. So this driver must give a way for user applications to receive responses.

This commit adds a functionality to receive responses via hwdep interface. The application can receive responses to read from this interface. To achieve this, this commit adds a buffer to queue responses. The default size of this buffer is 1024 bytes. This size can be changed to give preferrable size to 'resp_buf_size' parameter for this driver. The application should notice rest of space in this buffer because this driver don't push responses when this buffer has no space.

Additionaly, this commit adds a functionality to transmit commands via hwdep interface. The application can transmit commands to write into this interface. I note that the application can transmit one command at once, but can receive as many responses as possible untill the user-buffer is full.

When using these interfaces, the application must keep maximum number of sequence number in command within the number in firewire.h because this driver uses this number to distinguish the response is against the command by the application or this driver.

Usually responses against commands which the application transmits are pushed into this buffer. But to enable 'resp_buf_debug' parameter for this driver, all responses are pushed into the buffer. When using this mode, I reccomend to expand the size of buffer.

Finally this commit adds a new node into proc interface to output status of the buffer.

---
 include/uapi/sound/firewire.h                    |  18 +++
 sound/firewire/fireworks/fireworks.c             |  19 +++
 sound/firewire/fireworks/fireworks.h             |  22 +--
 sound/firewire/fireworks/fireworks_command.c     |   6 +-
 sound/firewire/fireworks/fireworks_hwdep.c       | 129 ++++++++++++++---
 sound/firewire/fireworks/fireworks_proc.c        |  18 +++
 sound/firewire/fireworks/fireworks_transaction.c | 176 ++++++++++++++++++++---
 7 files changed, 341 insertions(+), 47 deletions(-)
include/uapi/sound/firewire.h +18 -0
index fc9afb2..7f4c419 100644
@@ -7,6 +7,7 @@
 
 #define SNDRV_FIREWIRE_EVENT_LOCK_STATUS	0x000010cc
 #define SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION	0xd1ce004e
+#define SNDRV_FIREWIRE_EVENT_EFW_RESPONSE	0x4e617475
 
 struct snd_firewire_event_common {
 	unsigned int type; /* SNDRV_FIREWIRE_EVENT_xxx */
@@ -22,10 +23,27 @@ struct snd_firewire_event_dice_notification {
 	unsigned int notification; /* DICE-specific bits */
 };
 
+#define SND_EFW_TRANSACTION_SEQNUM_MAX	((uint32_t)(BIT(28) - 1))
+/* each field should be in big endian */
+struct snd_efw_transaction {
+	uint32_t length;
+	uint32_t version;
+	uint32_t seqnum;
+	uint32_t category;
+	uint32_t command;
+	uint32_t status;
+	uint32_t params[0];
+};
+struct snd_firewire_event_efw_response {
+	unsigned int type;
+	uint32_t response[0];	/* some responses */
+};
+
 union snd_firewire_event {
 	struct snd_firewire_event_common            common;
 	struct snd_firewire_event_lock_status       lock_status;
 	struct snd_firewire_event_dice_notification dice_notification;
+	struct snd_firewire_event_efw_response      efw_response;
 };
 
 
sound/firewire/fireworks/fireworks.c +19 -0
index 6e7536c..ca00708 100644
@@ -24,6 +24,8 @@ MODULE_LICENSE("GPL v2");
 static int index[SNDRV_CARDS]	= SNDRV_DEFAULT_IDX;
 static char *id[SNDRV_CARDS]	= SNDRV_DEFAULT_STR;
 static bool enable[SNDRV_CARDS]	= SNDRV_DEFAULT_ENABLE_PNP;
+unsigned int resp_buf_size	= 1024;
+bool resp_buf_debug		= false;
 
 module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "card index");
@@ -31,6 +33,11 @@ module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string");
 module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "enable Fireworks sound card");
+module_param(resp_buf_size, uint, 0444);
+MODULE_PARM_DESC(resp_buf_size, "response buffer size "
+		 "(min 300, max 4096, default 1024)");
+module_param(resp_buf_debug, bool, 0444);
+MODULE_PARM_DESC(resp_buf_debug, "store all responses to buffer");
 
 static DEFINE_MUTEX(devices_mutex);
 static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
@@ -165,6 +172,7 @@ efw_probe(struct fw_unit *unit,
 {
 	struct snd_card *card;
 	struct snd_efw *efw;
+	void *resp_buf;
 	int card_index, err;
 
 	mutex_lock(&devices_mutex);
@@ -178,6 +186,14 @@ efw_probe(struct fw_unit *unit,
 		goto end;
 	}
 
+	/* prepare response buffer */
+	resp_buf_size = clamp(resp_buf_size, 300U, 4096U);
+	resp_buf = kzalloc(resp_buf_size, GFP_KERNEL);
+	if (resp_buf == NULL) {
+		err = -ENOMEM;
+		goto end;
+	}
+
 	err = snd_card_new(&unit->device, index[card_index], id[card_index],
 			   THIS_MODULE, sizeof(struct snd_efw), &card);
 	if (err < 0)
@@ -191,6 +207,7 @@ efw_probe(struct fw_unit *unit,
 	mutex_init(&efw->mutex);
 	spin_lock_init(&efw->lock);
 	init_waitqueue_head(&efw->hwdep_wait);
+	efw->resp_buf = efw->pull_ptr = efw->push_ptr = resp_buf;
 
 	err = get_hardware_info(efw);
 	if (err < 0)
@@ -212,6 +229,7 @@ efw_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto error;
 
+	snd_efw_transaction_add_instance(efw);
 	err = snd_efw_create_hwdep_device(efw);
 	if (err < 0)
 		goto error;
@@ -245,6 +263,7 @@ static void efw_remove(struct fw_unit *unit)
 	struct snd_efw *efw = dev_get_drvdata(&unit->device);
 
 	snd_efw_stream_destroy_duplex(efw);
+	snd_efw_transaction_remove_instance(efw);
 
 	snd_card_disconnect(efw->card);
 	snd_card_free_when_closed(efw->card);
sound/firewire/fireworks/fireworks.h +13 -9
index 4ab4887..283e316 100644
@@ -40,6 +40,9 @@
 #define HWINFO_NAME_SIZE_BYTES		32
 #define HWINFO_MAX_CAPS_GROUPS		8
 
+extern unsigned int resp_buf_size;
+extern bool resp_buf_debug;
+
 struct snd_efw_phys_grp {
 	u8 type;	/* see enum snd_efw_grp_type */
 	u8 count;
@@ -83,23 +86,24 @@ struct snd_efw {
 	int dev_lock_count;
 	bool dev_lock_changed;
 	wait_queue_head_t hwdep_wait;
-};
 
-struct snd_efw_transaction {
-	u32 length;
-	u32 version;
-	u32 seqnum;
-	u32 category;
-	u32 command;
-	u32 status;
-	u32 params[0];
+	/* response queue */
+	u8 *resp_buf;
+	u8 *pull_ptr;
+	u8 *push_ptr;
+	unsigned int resp_queues;
 };
+
+int snd_efw_transaction_cmd(struct fw_unit *unit,
+			    const void *cmd, unsigned int size);
 int snd_efw_transaction_run(struct fw_unit *unit,
 			    const void *cmd, unsigned int cmd_size,
 			    void *resp, unsigned int resp_size, u32 seqnum);
 int snd_efw_transaction_register(void);
 void snd_efw_transaction_unregister(void);
 void snd_efw_transaction_bus_reset(struct fw_unit *unit);
+void snd_efw_transaction_add_instance(struct snd_efw *efw);
+void snd_efw_transaction_remove_instance(struct snd_efw *efw);
 
 struct snd_efw_hwinfo {
 	u32 flags;
sound/firewire/fireworks/fireworks_command.c +4 -2
index 9b19e3e..92f3325 100644
@@ -22,6 +22,7 @@
  * Information commands. But this module don't use them.
  */
 
+#define EFW_TRANSACTION_SEQNUM_MIN	(SND_EFW_TRANSACTION_SEQNUM_MAX + 1)
 #define EFW_TRANSACTION_SEQNUM_MAX	((u32)~0)
 
 /* for clock source and sampling rate */
@@ -120,8 +121,9 @@ efw_transaction(struct snd_efw *efw, unsigned int category,
 
 	/* to keep consistency of sequence number */
 	spin_lock(&efw->lock);
-	if (efw->seqnum + 1 >= EFW_TRANSACTION_SEQNUM_MAX)
-		efw->seqnum = 0;
+	if ((efw->seqnum < EFW_TRANSACTION_SEQNUM_MIN) ||
+	    (efw->seqnum >= EFW_TRANSACTION_SEQNUM_MAX - 2))
+		efw->seqnum = EFW_TRANSACTION_SEQNUM_MIN;
 	else
 		efw->seqnum += 2;
 	seqnum = efw->seqnum;
sound/firewire/fireworks/fireworks_hwdep.c +113 -16

178 lines not on this page · raw message

sound/firewire/fireworks/fireworks_proc.c +18 -0
index 54b2ee0..1e64210 100644
@@ -177,6 +177,23 @@ end:
 }
 
 static void
+proc_read_queues_state(struct snd_info_entry *entry,
+		       struct snd_info_buffer *buffer)
+{
+	struct snd_efw *efw = entry->private_data;
+	unsigned int consumed;
+
+	if (efw->pull_ptr > efw->push_ptr)
+		consumed = resp_buf_size -
+			   (unsigned int)(efw->pull_ptr - efw->push_ptr);
+	else
+		consumed = (unsigned int)(efw->push_ptr - efw->pull_ptr);
+
+	snd_iprintf(buffer, "%d %d/%d\n",
+		    efw->resp_queues, consumed, resp_buf_size);
+}
+
+static void
 add_node(struct snd_efw *efw, struct snd_info_entry *root, const char *name,
 	 void (*op)(struct snd_info_entry *e, struct snd_info_buffer *b))
 {
@@ -212,4 +229,5 @@ void snd_efw_proc_init(struct snd_efw *efw)
 	add_node(efw, root, "clock", proc_read_clock);
 	add_node(efw, root, "firmware", proc_read_hwinfo);
 	add_node(efw, root, "meters", proc_read_phys_meters);
+	add_node(efw, root, "queues", proc_read_queues_state);
 }
sound/firewire/fireworks/fireworks_transaction.c +156 -20

218 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#61 lore raw

PATCH 27/39 bebob: Add skelton for BeBoB based devices

In reply to Takashi Sakamoto

This commit add a new driver for BeBoB based devices with no functionality. This driver just create/remove card instance according to callbacks.

BeBoB is 'BridgeCo enhanced Breakout Box'. This is installed to firewire devices with DM1000/1000E/1100/1500 chipset. It gives common way for host system to handle BeBoB based devices.

Current supported devices:
- Edirol FA-66/FA-101
- PreSonus FIREBOX/FIREPOD/FP10/Inspire1394
- BridgeCo RDAudio1/Audio5
- Mackie Onyx 1220/1620/1640 (Firewire I/O Card)
- Mackie d.2 (Firewire Option)
- Stanton FinalScratch 2 (ScratchAmp)
- Tascam IF-FW DM
- Behringer XENIX UFX 1204/1604
- Behringer Digital Mixer X32 series (X-UF Card)
- Apogee Rosetta 200/Rosetta 400 (X-FireWire card)
- Apogee DA-16X/AD-16X/DD-16X (X-FireWire card)
- Apogee Ensemble
- ESI Quotafire610
- AcousticReality eARMasterOne
- CME MatrixKFW
- Phonix Helix Board 12 MkII/18 MkII/24 MkII
- Phonic Helix Board 12 Universal/18 Universal/24 Universal
- Lynx Aurora 8/16 (LT-FW)
- ICON FireXon
- PrismSound Orpheus/ADA-8XR

Devices possible to be supported if identifying IDs:
- Apogee Mini-Me Firewire/Mini-DAC Firewire
- Behringer F-Control Audio 610/1616
- Cakewalk Sonar Power Studio 66
- CME UF400e
- ESI Quotafire XL
- Infrasonic DewX/Windy6
- Mackie Digital X Bus x.200/400
- Phonic Helix Board 12/18/24
- Phonic FireFly 202/302
- Rolf Spuler Firewire Guitar

---
 sound/firewire/Kconfig        |  30 +++++
 sound/firewire/Makefile       |   1 +
 sound/firewire/bebob/Makefile |   2 +
 sound/firewire/bebob/bebob.c  | 296 ++++++++++++++++++++++++++++++++++++++++++
 sound/firewire/bebob/bebob.h  |  64 +++++++++
 5 files changed, 393 insertions(+)
 create mode 100644 sound/firewire/bebob/Makefile
 create mode 100644 sound/firewire/bebob/bebob.c
 create mode 100644 sound/firewire/bebob/bebob.h
sound/firewire/Kconfig +30 -0
index 875af02..9027b23 100644
@@ -79,4 +79,34 @@ config SND_FIREWORKS
 	  To compile this driver as a module, choose M here: the module
 	  will be called snd-fireworks.
 
+config SND_BEBOB
+	tristate "BridgeCo DM1000/1500 with BeBoB firmware"
+	select SND_FIREWIRE_LIB
+        help
+	 Say Y here to include support for FireWire devices based
+	 on BridgeCo DM1000/1500 with BeBoB firmware:
+	  * Edirol FA-66/FA-101
+	  * PreSonus FIREBOX/FIREPOD/FP10/Inspire1394
+	  * BridgeCo RDAudio1/Audio5
+	  * Mackie Onyx 1220/1620/1640 (Firewire I/O Card)
+	  * Mackie d.2 (Firewire Option)
+	  * Stanton FinalScratch 2 (ScratchAmp)
+	  * Tascam IF-FW/DM
+	  * Behringer XENIX UFX 1204/1604
+	  * Behringer Digital Mixer X32 series (X-UF Card)
+	  * Apogee Rosetta 200/400 (X-FireWire card)
+	  * Apogee DA/AD/DD-16X (X-FireWire card)
+	  * Apogee Ensemble
+	  * ESI Quotafire610
+	  * AcousticReality eARMasterOne
+	  * CME MatrixKFW
+	  * Phonic Helix Board 12 MkII/18 MkII/24 MkII
+	  * Phonic Helix Board 12 Universal/18 Universal/24 Universal
+	  * Lynx Aurora 8/16 (LT-FW)
+	  * ICON FireXon
+	  * PrismSound Orpheus/ADA-8XR
+
+          To compile this driver as a module, choose M here: the module
+          will be called snd-bebob.
+
 endif # SND_FIREWIRE
sound/firewire/Makefile +1 -0
index 5cd39dc..fad8d49 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_SND_FIREWIRE_SPEAKERS) += snd-firewire-speakers.o
 obj-$(CONFIG_SND_ISIGHT) += snd-isight.o
 obj-$(CONFIG_SND_SCS1X) += snd-scs1x.o
 obj-$(CONFIG_SND_FIREWORKS) += fireworks/
+obj-$(CONFIG_SND_BEBOB) += bebob/
sound/firewire/bebob/Makefile new file +2 -0
new file mode 100644
index 0000000..c6f0141
@@ -0,0 +1,2 @@
+snd-bebob-objs := bebob.o
+obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c new file +296 -0

296 lines not on this page · raw message

sound/firewire/bebob/bebob.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#62 lore raw

PATCH 28/39 bebob: Add commands and connections/streams management

In reply to Takashi Sakamoto

This commit adds management functionality for connections and streams. BeBoB uses CMP to manage connections and uses AMDTP for streams.

This commit also adds some BridgeCo's AV/C extension commands. There are many BridgeCo's AV/C extension commands but this commit adds below commands to get device's capability and status:

1.Extended Plug Info commands
- Plug Channel Position Specific Data
- Plug Type Specific Data
- Cluster(Section) Info Specific Data
- Plug Input Specific Data
2.Extended Stream Format Information commands
- Extended Stream Format Information Command - Single Request

For Extended Plug Info commands for Cluster Info Specific Data, I pick up 'section' instead of 'cluster' from document to prevent from misunderstanding because 'cluster' is also used in IEC 61883-6.

---
 sound/firewire/bebob/Makefile        |   2 +-
 sound/firewire/bebob/bebob.c         |  10 +
 sound/firewire/bebob/bebob.h         | 122 ++++++
 sound/firewire/bebob/bebob_command.c | 273 ++++++++++++
 sound/firewire/bebob/bebob_stream.c  | 784 +++++++++++++++++++++++++++++++++++
 5 files changed, 1190 insertions(+), 1 deletion(-)
 create mode 100644 sound/firewire/bebob/bebob_command.c
 create mode 100644 sound/firewire/bebob/bebob_stream.c
sound/firewire/bebob/Makefile +1 -1
index c6f0141..5cece62 100644
@@ -1,2 +1,2 @@
-snd-bebob-objs := bebob.o
+snd-bebob-objs := bebob_command.o bebob_stream.o bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +10 -0
index 3626557..39fe17c 100644
@@ -157,6 +157,14 @@ bebob_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto error;
 
+	err = snd_bebob_stream_discover(bebob);
+	if (err < 0)
+		goto error;
+
+	err = snd_bebob_stream_init_duplex(bebob);
+	if (err < 0)
+		goto error;
+
 	err = snd_card_register(card);
 	if (err < 0) {
 		snd_card_free(card);
@@ -179,12 +187,14 @@ bebob_update(struct fw_unit *unit)
 {
 	struct snd_bebob *bebob = dev_get_drvdata(&unit->device);
 	fcp_bus_reset(bebob->unit);
+	snd_bebob_stream_update_duplex(bebob);
 }
 
 
 static void bebob_remove(struct fw_unit *unit)
 {
 	struct snd_bebob *bebob = dev_get_drvdata(&unit->device);
+	snd_bebob_stream_destroy_duplex(bebob);
 	snd_card_disconnect(bebob->card);
 	snd_card_free_when_closed(bebob->card);
 }
sound/firewire/bebob/bebob.h +122 -0

145 lines not on this page · raw message

sound/firewire/bebob/bebob_command.c new file +273 -0

273 lines not on this page · raw message

sound/firewire/bebob/bebob_stream.c new file +784 -0

784 lines not on this page · raw message

Signature · 6 lines
1.8.3.2

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#63 lore raw

PATCH 29/39 bebob: Add proc interface for debugging purpose

In reply to Takashi Sakamoto

This commit adds proc interface to get information for debugging.
- firmware information
- stream formation
- current clock source and sampling rate

---
 sound/firewire/bebob/Makefile     |   2 +-
 sound/firewire/bebob/bebob.c      |   2 +
 sound/firewire/bebob/bebob.h      |   3 +
 sound/firewire/bebob/bebob_proc.c | 155 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 sound/firewire/bebob/bebob_proc.c
sound/firewire/bebob/Makefile +1 -1
index 5cece62..757c40e 100644
@@ -1,2 +1,2 @@
-snd-bebob-objs := bebob_command.o bebob_stream.o bebob.o
+snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +2 -0
index 39fe17c..d0ad889 100644
@@ -165,6 +165,8 @@ bebob_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto error;
 
+	snd_bebob_proc_init(bebob);
+
 	err = snd_card_register(card);
 	if (err < 0) {
 		snd_card_free(card);
sound/firewire/bebob/bebob.h +3 -0
index b3a641c..83ee15a 100644
@@ -20,6 +20,7 @@
 
 #include <sound/core.h>
 #include <sound/initval.h>
+#include <sound/info.h>
 
 #include "../lib.h"
 #include "../fcp.h"
@@ -175,6 +176,8 @@ int snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
 void snd_bebob_stream_update_duplex(struct snd_bebob *bebob);
 void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
 
+void snd_bebob_proc_init(struct snd_bebob *bebob);
+
 #define SND_BEBOB_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/bebob/bebob_proc.c new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#64 lore raw

PATCH 30/39 bebob: Add MIDI interface

In reply to Takashi Sakamoto

This commit adds a functionality to capture/playback MIDI messages.

When no AMDTP streams are running, this module starts AMDTP stream at current sampling rate for MIDI stream.

---
 sound/firewire/Kconfig            |   1 +
 sound/firewire/bebob/Makefile     |   3 +-
 sound/firewire/bebob/bebob.c      |   7 ++
 sound/firewire/bebob/bebob.h      |   3 +
 sound/firewire/bebob/bebob_midi.c | 148 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 sound/firewire/bebob/bebob_midi.c
sound/firewire/Kconfig +1 -0
index 9027b23..8081ca1 100644
@@ -82,6 +82,7 @@ config SND_FIREWORKS
 config SND_BEBOB
 	tristate "BridgeCo DM1000/1500 with BeBoB firmware"
 	select SND_FIREWIRE_LIB
+	select SND_RAWMIDI
         help
 	 Say Y here to include support for FireWire devices based
 	 on BridgeCo DM1000/1500 with BeBoB firmware:
sound/firewire/bebob/Makefile +2 -1
index 757c40e..1e39e59 100644
@@ -1,2 +1,3 @@
-snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob.o
+snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob_midi.o \
+		  bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +7 -0
index d0ad889..3872854 100644
@@ -167,6 +167,13 @@ bebob_probe(struct fw_unit *unit,
 
 	snd_bebob_proc_init(bebob);
 
+	if ((bebob->midi_input_ports > 0) ||
+	    (bebob->midi_output_ports > 0)) {
+		err = snd_bebob_create_midi_devices(bebob);
+		if (err < 0)
+			goto error;
+	}
+
 	err = snd_card_register(card);
 	if (err < 0) {
 		snd_card_free(card);
sound/firewire/bebob/bebob.h +3 -0
index 83ee15a..1e1db6c 100644
@@ -21,6 +21,7 @@
 #include <sound/core.h>
 #include <sound/initval.h>
 #include <sound/info.h>
+#include <sound/rawmidi.h>
 
 #include "../lib.h"
 #include "../fcp.h"
@@ -178,6 +179,8 @@ void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
 
 void snd_bebob_proc_init(struct snd_bebob *bebob);
 
+int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
+
 #define SND_BEBOB_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/bebob/bebob_midi.c new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#65 lore raw

PATCH 31/39 bebob: Add PCM interface

In reply to Takashi Sakamoto

This commit adds a functionality to capture/playback PCM samples.

When AMDTP stream is already running for PCM or the source of clock is not internal, available sampling rate is limited at current one.

---
 sound/firewire/Kconfig           |   1 +
 sound/firewire/bebob/Makefile    |   1 +
 sound/firewire/bebob/bebob.c     |   4 +
 sound/firewire/bebob/bebob.h     |   4 +
 sound/firewire/bebob/bebob_pcm.c | 442 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 452 insertions(+)
 create mode 100644 sound/firewire/bebob/bebob_pcm.c
sound/firewire/Kconfig +1 -0
index 8081ca1..022fee0 100644
@@ -83,6 +83,7 @@ config SND_BEBOB
 	tristate "BridgeCo DM1000/1500 with BeBoB firmware"
 	select SND_FIREWIRE_LIB
 	select SND_RAWMIDI
+	select SND_PCM
         help
 	 Say Y here to include support for FireWire devices based
 	 on BridgeCo DM1000/1500 with BeBoB firmware:
sound/firewire/bebob/Makefile +1 -0
index 1e39e59..533718a 100644
@@ -1,3 +1,4 @@
 snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob_midi.o \
+		  bebob_pcm.o \
 		  bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +4 -0
index 3872854..dea3ef3 100644
@@ -174,6 +174,10 @@ bebob_probe(struct fw_unit *unit,
 			goto error;
 	}
 
+	err = snd_bebob_create_pcm_devices(bebob);
+	if (err < 0)
+		goto error;
+
 	err = snd_card_register(card);
 	if (err < 0) {
 		snd_card_free(card);
sound/firewire/bebob/bebob.h +4 -0
index 1e1db6c..b310c85 100644
@@ -22,6 +22,8 @@
 #include <sound/initval.h>
 #include <sound/info.h>
 #include <sound/rawmidi.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
 
 #include "../lib.h"
 #include "../fcp.h"
@@ -181,6 +183,8 @@ void snd_bebob_proc_init(struct snd_bebob *bebob);
 
 int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
 
+int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
+
 #define SND_BEBOB_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/bebob/bebob_pcm.c new file +442 -0

442 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#66 lore raw

PATCH 32/39 bebob: Add hwdep interface

In reply to Takashi Sakamoto

This interface is designed for mixer/control application. To use hwdep interface, the application can get information about firewire node, can lock/unlock kernel streaming and can get notification at starting/stopping kernel streaming.

---
 include/uapi/sound/asound.h         |   3 +-
 include/uapi/sound/firewire.h       |   1 +
 sound/firewire/Kconfig              |   1 +
 sound/firewire/bebob/Makefile       |   2 +-
 sound/firewire/bebob/bebob.c        |   5 +
 sound/firewire/bebob/bebob.h        |  13 +++
 sound/firewire/bebob/bebob_hwdep.c  | 197 ++++++++++++++++++++++++++++++++++++
 sound/firewire/bebob/bebob_midi.c   |  26 ++++-
 sound/firewire/bebob/bebob_pcm.c    |  16 ++-
 sound/firewire/bebob/bebob_stream.c |  39 +++++++
 10 files changed, 295 insertions(+), 8 deletions(-)
 create mode 100644 sound/firewire/bebob/bebob_hwdep.c
include/uapi/sound/asound.h +2 -1
index 5dfbfdf..2249483 100644
@@ -95,9 +95,10 @@ enum {
 	SNDRV_HWDEP_IFACE_USB_STREAM,	/* direct access to usb stream */
 	SNDRV_HWDEP_IFACE_FW_DICE,	/* TC DICE FireWire device */
 	SNDRV_HWDEP_IFACE_FW_FIREWORKS,	/* Echo Audio Fireworks based device */
+	SNDRV_HWDEP_IFACE_FW_BEBOB,	/* BridgeCo BeBoB based device */
 
 	/* Don't forget to change the following: */
-	SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_FIREWORKS
+	SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_BEBOB
 };
 
 struct snd_hwdep_info {
include/uapi/sound/firewire.h +1 -0
index 7f4c419..d69c0b6 100644
@@ -53,6 +53,7 @@ union snd_firewire_event {
 
 #define SNDRV_FIREWIRE_TYPE_DICE	1
 #define SNDRV_FIREWIRE_TYPE_FIREWORKS	2
+#define SNDRV_FIREWIRE_TYPE_BEBOB	3
 /* AV/C, RME, MOTU, ... */
 
 struct snd_firewire_get_info {
sound/firewire/Kconfig +1 -0
index 022fee0..060fe7e 100644
@@ -84,6 +84,7 @@ config SND_BEBOB
 	select SND_FIREWIRE_LIB
 	select SND_RAWMIDI
 	select SND_PCM
+	select SND_HWDEP
         help
 	 Say Y here to include support for FireWire devices based
 	 on BridgeCo DM1000/1500 with BeBoB firmware:
sound/firewire/bebob/Makefile +1 -1
index 533718a..7808777 100644
@@ -1,4 +1,4 @@
 snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob_midi.o \
-		  bebob_pcm.o \
+		  bebob_pcm.o bebob_hwdep.o \
 		  bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +5 -0
index dea3ef3..d833277b 100644
@@ -152,6 +152,7 @@ bebob_probe(struct fw_unit *unit,
 	bebob->card_index = -1;
 	mutex_init(&bebob->mutex);
 	spin_lock_init(&bebob->lock);
+	init_waitqueue_head(&bebob->hwdep_wait);
 
 	err = name_device(bebob, entry->vendor_id);
 	if (err < 0)
@@ -178,6 +179,10 @@ bebob_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto error;
 
+	err = snd_bebob_create_hwdep_device(bebob);
+	if (err < 0)
+		goto error;
+
 	err = snd_card_register(card);
 	if (err < 0) {
 		snd_card_free(card);
sound/firewire/bebob/bebob.h +13 -0
index b310c85..933e7e6 100644
@@ -24,6 +24,8 @@
 #include <sound/rawmidi.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
+#include <sound/firewire.h>
+#include <sound/hwdep.h>
 
 #include "../lib.h"
 #include "../fcp.h"
@@ -70,6 +72,11 @@ struct snd_bebob {
 		rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
 
 	int sync_input_plug;
+
+	/* for uapi */
+	int dev_lock_count;
+	bool dev_lock_changed;
+	wait_queue_head_t hwdep_wait;
 };
 
 static inline int
@@ -179,12 +186,18 @@ int snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
 void snd_bebob_stream_update_duplex(struct snd_bebob *bebob);
 void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
 
+void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);
+int snd_bebob_stream_lock_try(struct snd_bebob *bebob);
+void snd_bebob_stream_lock_release(struct snd_bebob *bebob);
+
 void snd_bebob_proc_init(struct snd_bebob *bebob);
 
 int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
 
 int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
 
+int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
+
 #define SND_BEBOB_DEV_ENTRY(vendor, model) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/bebob/bebob_hwdep.c new file +197 -0

197 lines not on this page · raw message

sound/firewire/bebob/bebob_midi.c +24 -2
index 9312b34..8943565 100644
@@ -11,17 +11,37 @@
 static int midi_capture_open(struct snd_rawmidi_substream *substream)
 {
 	struct snd_bebob *bebob = substream->rmidi->private_data;
+	int err;
+
+	err = snd_bebob_stream_lock_try(bebob);
+	if (err < 0)
+		goto end;
 
 	bebob->capture_substreams++;
-	return snd_bebob_stream_start_duplex(bebob, &bebob->tx_stream, 0);
+	err = snd_bebob_stream_start_duplex(bebob,
+					    &bebob->tx_stream, 0);
+	if (err < 0)
+		snd_bebob_stream_lock_release(bebob);
+end:
+	return err;
 }
 
 static int midi_playback_open(struct snd_rawmidi_substream *substream)
 {
 	struct snd_bebob *bebob = substream->rmidi->private_data;
+	int err;
+
+	err = snd_bebob_stream_lock_try(bebob);
+	if (err < 0)
+		goto end;
 
 	bebob->playback_substreams++;
-	return snd_bebob_stream_start_duplex(bebob, &bebob->rx_stream, 0);
+	err = snd_bebob_stream_start_duplex(bebob,
+					    &bebob->rx_stream, 0);
+	if (err < 0)
+		snd_bebob_stream_lock_release(bebob);
+end:
+	return err;
 }
 
 static int midi_capture_close(struct snd_rawmidi_substream *substream)
@@ -31,6 +51,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
 	bebob->capture_substreams--;
 	snd_bebob_stream_stop_duplex(bebob);
 
+	snd_bebob_stream_lock_release(bebob);
 	return 0;
 }
 
@@ -41,6 +62,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
 	bebob->playback_substreams--;
 	snd_bebob_stream_stop_duplex(bebob);
 
+	snd_bebob_stream_lock_release(bebob);
 	return 0;
 }
 
sound/firewire/bebob/bebob_pcm.c +12 -4
index db9c87f..9e0b12c 100644
@@ -233,13 +233,17 @@ pcm_open(struct snd_pcm_substream *substream)
 	bool internal;
 	int err;
 
-	err = pcm_init_hw_params(bebob, substream);
+	err = snd_bebob_stream_lock_try(bebob);
 	if (err < 0)
 		goto end;
 
+	err = pcm_init_hw_params(bebob, substream);
+	if (err < 0)
+		goto err_locked;
+
 	err = snd_bebob_stream_check_internal_clock(bebob, &internal);
 	if (err < 0)
-		goto end;
+		goto err_locked;
 
 	/*
 	 * When source of clock is internal or any PCM stream are running,
@@ -250,21 +254,25 @@ pcm_open(struct snd_pcm_substream *substream)
 	    amdtp_stream_pcm_running(&bebob->rx_stream)) {
 		err = snd_bebob_stream_get_rate(bebob, &sampling_rate);
 		if (err < 0)
-			goto end;
+			goto err_locked;
 
 		substream->runtime->hw.rate_min = sampling_rate;
 		substream->runtime->hw.rate_max = sampling_rate;
 	}
 
 	snd_pcm_set_sync(substream);
-
 end:
 	return err;
+err_locked:
+	snd_bebob_stream_lock_release(bebob);
+	return err;
 }
 
 static int
 pcm_close(struct snd_pcm_substream *substream)
 {
+	struct snd_bebob *bebob = substream->private_data;
+	snd_bebob_stream_lock_release(bebob);
 	return 0;
 }
 
sound/firewire/bebob/bebob_stream.c +39 -0
index 497d1c6..797fcb0 100644
@@ -782,3 +782,42 @@ int snd_bebob_stream_discover(struct snd_bebob *bebob)
 end:
 	return err;
 }
+
+void snd_bebob_stream_lock_changed(struct snd_bebob *bebob)
+{
+	bebob->dev_lock_changed = true;
+	wake_up(&bebob->hwdep_wait);
+}
+
+int snd_bebob_stream_lock_try(struct snd_bebob *bebob)
+{
+	int err;
+
+	spin_lock_irq(&bebob->lock);
+
+	/* user land lock this */
+	if (bebob->dev_lock_count < 0) {
+		err = -EBUSY;
+		goto end;
+	}
+
+	/* this is the first time */
+	if (bebob->dev_lock_count++ == 0)
+		snd_bebob_stream_lock_changed(bebob);
+	err = 0;
+end:
+	spin_unlock_irq(&bebob->lock);
+	return err;
+}
+
+void snd_bebob_stream_lock_release(struct snd_bebob *bebob)
+{
+	spin_lock_irq(&bebob->lock);
+
+	if (WARN_ON(bebob->dev_lock_count <= 0))
+		goto end;
+	if (--bebob->dev_lock_count == 0)
+		snd_bebob_stream_lock_changed(bebob);
+end:
+	spin_unlock_irq(&bebob->lock);
+}
Signature · 1 line
1.8.3.2
maintainer
#67 lore raw

PATCH 33/39 bebob: Prepare for device specific operations

In reply to Takashi Sakamoto

This commit is for some devices which have its own operations or quirks.

Many functionality should be implemented in user land. Then this commit adds functionality related to stream such as sampling frequency or clock source. For help to debug, this commit adds the functionality to get metering information if it's available.

To help these functionalities, this commit adds some AV/C commands defined in 'AV/C Audio Subunit Specification (1394TA).

---
 sound/firewire/bebob/Makefile        |  3 +-
 sound/firewire/bebob/bebob.c         | 72 ++++++++++++++++++++------------
 sound/firewire/bebob/bebob.h         | 33 ++++++++++++++-
 sound/firewire/bebob/bebob_command.c | 79 ++++++++++++++++++++++++++++++++++++
 sound/firewire/bebob/bebob_pcm.c     |  3 +-
 sound/firewire/bebob/bebob_proc.c    | 60 +++++++++++++++++++++++----
 sound/firewire/bebob/bebob_stream.c  | 26 +++++++++---
 7 files changed, 233 insertions(+), 43 deletions(-)
sound/firewire/bebob/Makefile +1 -2
index 7808777..e4b08e3 100644
@@ -1,4 +1,3 @@
 snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob_midi.o \
-		  bebob_pcm.o bebob_hwdep.o \
-		  bebob.o
+		  bebob_pcm.o bebob_hwdep.o bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +45 -27

125 lines not on this page · raw message

sound/firewire/bebob/bebob.h +32 -1
index 933e7e6..6976097 100644
@@ -48,6 +48,28 @@ struct snd_bebob_stream_formation {
 /* this is a lookup table for index of stream formations */
 extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
 
+/* device specific operations */
+#define SND_BEBOB_CLOCK_INTERNAL	"Internal"
+struct snd_bebob_clock_spec {
+	unsigned int num;
+	char **labels;
+	int (*get)(struct snd_bebob *bebob, unsigned int *id);
+};
+struct snd_bebob_rate_spec {
+	int (*get)(struct snd_bebob *bebob, unsigned int *rate);
+	int (*set)(struct snd_bebob *bebob, unsigned int rate);
+};
+struct snd_bebob_meter_spec {
+	unsigned int num;
+	char **labels;
+	int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);
+};
+struct snd_bebob_spec {
+	struct snd_bebob_clock_spec *clock;
+	struct snd_bebob_rate_spec *rate;
+	struct snd_bebob_meter_spec *meter;
+};
+
 struct snd_bebob {
 	struct snd_card *card;
 	struct fw_unit *unit;
@@ -56,6 +78,8 @@ struct snd_bebob {
 	struct mutex mutex;
 	spinlock_t lock;
 
+	const struct snd_bebob_spec *spec;
+
 	unsigned int midi_input_ports;
 	unsigned int midi_output_ports;
 
@@ -95,6 +119,12 @@ snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)
 				  (void *)buf, sizeof(u32), 0);
 }
 
+/* AV/C Audio Subunit Specification 1.0 (Oct 2000, 1394TA) */
+int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
+			   unsigned int fb_id, unsigned int num);
+int avc_audio_get_selector(struct fw_unit *unit, unsigned  int subunit_id,
+			   unsigned int fb_id, unsigned int *num);
+
 /*
  * AVC command extensions, AV/C Unit and Subunit, Revision 17
  * (Nov 2003, BridgeCo)
@@ -198,12 +228,13 @@ int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
 
 int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
 
-#define SND_BEBOB_DEV_ENTRY(vendor, model) \
+#define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
 			  IEEE1394_MATCH_MODEL_ID, \
 	.vendor_id	= vendor, \
 	.model_id	= model, \
+	.driver_data	= (kernel_ulong_t)data \
 }
 
 #endif
sound/firewire/bebob/bebob_command.c +79 -0

85 lines not on this page · raw message

sound/firewire/bebob/bebob_pcm.c +2 -1
index 9e0b12c..32ce990 100644
@@ -229,6 +229,7 @@ static int
 pcm_open(struct snd_pcm_substream *substream)
 {
 	struct snd_bebob *bebob = substream->private_data;
+	struct snd_bebob_rate_spec *spec = bebob->spec->rate;
 	unsigned int sampling_rate;
 	bool internal;
 	int err;
@@ -252,7 +253,7 @@ pcm_open(struct snd_pcm_substream *substream)
 	if (!internal ||
 	    amdtp_stream_pcm_running(&bebob->tx_stream) ||
 	    amdtp_stream_pcm_running(&bebob->rx_stream)) {
-		err = snd_bebob_stream_get_rate(bebob, &sampling_rate);
+		err = spec->get(bebob, &sampling_rate);
 		if (err < 0)
 			goto err_locked;
 
sound/firewire/bebob/bebob_proc.c +53 -7

81 lines not on this page · raw message

sound/firewire/bebob/bebob_stream.c +21 -5
index 797fcb0..de80756 100644
@@ -99,13 +99,26 @@ end:
 int
 snd_bebob_stream_check_internal_clock(struct snd_bebob *bebob, bool *internal)
 {
+	struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
 	u8 addr[AVC_BRIDGECO_ADDR_BYTES], input[7];
+	unsigned int id;
 	int err = 0;
 
 	*internal = false;
 
+	/* 1.The device has its own operation to switch source of clock */
+	if (clk_spec) {
+		err = clk_spec->get(bebob, &id);
+		if (err < 0)
+			goto end;
+		if (strncmp(clk_spec->labels[id], SND_BEBOB_CLOCK_INTERNAL,
+			    strlen(SND_BEBOB_CLOCK_INTERNAL)) == 0)
+			*internal = true;
+		goto end;
+	}
+
 	/*
-	 * 1.The device don't support for switching source of clock
+	 * 2.The device don't support for switching source of clock
 	 *   then assumed to use internal clock always
 	 */
 	if (bebob->sync_input_plug < 0) {
@@ -114,7 +127,7 @@ snd_bebob_stream_check_internal_clock(struct snd_bebob *bebob, bool *internal)
 	}
 
 	/*
-	 * 2.The device supports to switch source of clock by an usual way.
+	 * 3.The device supports to switch source of clock by an usual way.
 	 *   Let's check input for 'Music Sub Unit Sync Input' plug.
 	 */
 	avc_bridgeco_fill_subunit_addr(addr, 0x60, AVC_BRIDGECO_PLUG_DIR_IN,
@@ -400,6 +413,7 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob,
 				  struct amdtp_stream *request,
 				  unsigned int rate)
 {
+	struct snd_bebob_rate_spec *rate_spec = bebob->spec->rate;
 	struct amdtp_stream *master, *slave;
 	enum cip_flags sync_mode;
 	unsigned int curr_rate;
@@ -430,7 +444,7 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob,
 		amdtp_stream_stop(master);
 
 	/* stop streams if rate is different */
-	err = snd_bebob_stream_get_rate(bebob, &curr_rate);
+	err = rate_spec->get(bebob, &curr_rate);
 	if (err < 0)
 		goto end;
 	if (rate == 0)
@@ -450,7 +464,7 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob,
 		 * If establishing connections at first, Yamaha GO46
 		 * (and maybe Terratec X24) don't generate sound.
 		 */
-		err = snd_bebob_stream_set_rate(bebob, rate);
+		err = rate_spec->set(bebob, rate);
 		if (err < 0)
 			goto end;
 
@@ -705,6 +719,7 @@ end:
 int snd_bebob_stream_discover(struct snd_bebob *bebob)
 {
 	u8 plugs[AVC_PLUG_INFO_BUF_COUNT], addr[AVC_BRIDGECO_ADDR_BYTES];
+	struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
 	enum avc_bridgeco_plug_type type;
 	unsigned int i;
 	int err;
@@ -778,7 +793,8 @@ int snd_bebob_stream_discover(struct snd_bebob *bebob)
 	}
 
 	/* for check source of clock later */
-	err = seek_msu_sync_input_plug(bebob);
+	if (!clk_spec)
+		err = seek_msu_sync_input_plug(bebob);
 end:
 	return err;
 }
Signature · 1 line
1.8.3.2
maintainer
#68 lore raw

PATCH 34/39 bebob: Add support for Terratec PHASE, EWS series and Aureon

In reply to Takashi Sakamoto

This commit allows this driver to support all of models which Terratec produced with DM1000/BeBoB. They are:
- PHASE 24 FW
- PHASE X24 FW
- PHASE 88 Rack FW
- EWS MIC2
- EWS MIC4
- Aureon 7.1 Firewire

For Phase series, this commit adds a Terratec specific operation. To get source of clock. AV/C Audio Subunit command is used.

For EWS series and Aureon, this module uses normal operations.

---
 sound/firewire/Kconfig                |  3 ++
 sound/firewire/bebob/Makefile         |  2 +-
 sound/firewire/bebob/bebob.c          | 11 ++++++
 sound/firewire/bebob/bebob.h          |  4 +++
 sound/firewire/bebob/bebob_terratec.c | 68 +++++++++++++++++++++++++++++++++++
 5 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 sound/firewire/bebob/bebob_terratec.c
sound/firewire/Kconfig +3 -0
index 060fe7e..0a7918a 100644
@@ -108,6 +108,9 @@ config SND_BEBOB
 	  * Lynx Aurora 8/16 (LT-FW)
 	  * ICON FireXon
 	  * PrismSound Orpheus/ADA-8XR
+	  * TerraTec PHASE 24 FW/PHASE X24 FW/PHASE 88 Rack FW
+	  * Terratec EWS MIC2/EWS MIC4
+	  * Terratec Aureon 7.1 Firewire
 
           To compile this driver as a module, choose M here: the module
           will be called snd-bebob.
sound/firewire/bebob/Makefile +1 -1
index e4b08e3..cb38dd1 100644
@@ -1,3 +1,3 @@
 snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob_midi.o \
-		  bebob_pcm.o bebob_hwdep.o bebob.o
+		  bebob_pcm.o bebob_hwdep.o bebob_terratec.o bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +11 -0
index a581425..cd898fe 100644
@@ -52,6 +52,7 @@ static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
 #define VEN_LYNX	0x000019e5
 #define VEN_ICON	0x00001a9e
 #define VEN_PRISMSOUND	0x00001198
+#define VEN_TERRATEC	0x00000aac
 
 static int
 name_device(struct snd_bebob *bebob, unsigned int vendor_id)
@@ -291,6 +292,16 @@ static const struct ieee1394_device_id bebob_id_table[] = {
 	SND_BEBOB_DEV_ENTRY(VEN_PRISMSOUND, 0x00010048, &spec_normal),
 	/* PrismSound, ADA-8XR */
 	SND_BEBOB_DEV_ENTRY(VEN_PRISMSOUND, 0x0000ada8, &spec_normal),
+	/* TerraTec Electronic GmbH, PHASE 88 Rack FW */
+	SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000003, &phase88_rack_spec),
+	/* TerraTec Electronic GmbH, PHASE 24 FW */
+	SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000004, &phase24_series_spec),
+	/* TerraTec Electronic GmbH, Phase X24 FW */
+	SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000007, &phase24_series_spec),
+	/* TerraTec Electronic GmbH, EWS MIC2/MIC8 */
+	SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000005, &spec_normal),
+	/* Terratec Electronic GmbH, Aureon 7.1 Firewire */
+	SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000002, &spec_normal),
 	/* IDs are unknown but able to be supported */
 	/*  Apogee, Mini-ME Firewire */
 	/*  Apogee, Mini-DAC Firewire */
sound/firewire/bebob/bebob.h +4 -0
index 6976097..a5422ea 100644
@@ -228,6 +228,10 @@ int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
 
 int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
 
+/* model specific operations */
+extern struct snd_bebob_spec phase88_rack_spec;
+extern struct snd_bebob_spec phase24_series_spec;
+
 #define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
 { \
 	.match_flags	= IEEE1394_MATCH_VENDOR_ID | \
sound/firewire/bebob/bebob_terratec.c new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#69 lore raw

PATCH 35/39 bebob: Add support for Yamaha GO series

In reply to Takashi Sakamoto

This commit allows this driver to support all of models which Yamaha produced with DM1000/BeBoB. They are:
- GO44
- GO46

This commit adds Yamaha specific operations. To get source of clock, AV/C Audio Subunit command is used.

I note that their appearances are similar to some models of TerraTec; 'Go44' is similar to 'PHASE 24 FW' and 'GO46' is similar to 'PHASE X24 FW'. But their combination of Audio/Music subunit are a bit different.

---
 sound/firewire/Kconfig              |  1 +
 sound/firewire/bebob/Makefile       |  3 ++-
 sound/firewire/bebob/bebob.c        |  5 ++++
 sound/firewire/bebob/bebob.h        |  1 +
 sound/firewire/bebob/bebob_yamaha.c | 50 +++++++++++++++++++++++++++++++++++++
 5 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 sound/firewire/bebob/bebob_yamaha.c
sound/firewire/Kconfig +1 -0
index 0a7918a..e7605ff 100644
@@ -111,6 +111,7 @@ config SND_BEBOB
 	  * TerraTec PHASE 24 FW/PHASE X24 FW/PHASE 88 Rack FW
 	  * Terratec EWS MIC2/EWS MIC4
 	  * Terratec Aureon 7.1 Firewire
+	  * Yamaha GO44/GO46
 
           To compile this driver as a module, choose M here: the module
           will be called snd-bebob.
sound/firewire/bebob/Makefile +2 -1
index cb38dd1..c35eee1 100644
@@ -1,3 +1,4 @@
 snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob_midi.o \
-		  bebob_pcm.o bebob_hwdep.o bebob_terratec.o bebob.o
+		  bebob_pcm.o bebob_hwdep.o bebob_terratec.o bebob_yamaha.o \
+		  bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +5 -0
index cd898fe..3efb620 100644
@@ -53,6 +53,7 @@ static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
 #define VEN_ICON	0x00001a9e
 #define VEN_PRISMSOUND	0x00001198
 #define VEN_TERRATEC	0x00000aac
+#define VEN_YAMAHA	0x0000a0de
 
 static int
 name_device(struct snd_bebob *bebob, unsigned int vendor_id)
@@ -302,6 +303,10 @@ static const struct ieee1394_device_id bebob_id_table[] = {
 	SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000005, &spec_normal),
 	/* Terratec Electronic GmbH, Aureon 7.1 Firewire */
 	SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000002, &spec_normal),
+	/* Yamaha, GO44 */
+	SND_BEBOB_DEV_ENTRY(VEN_YAMAHA, 0x0010000b, &yamaha_go_spec),
+	/* YAMAHA, GO46 */
+	SND_BEBOB_DEV_ENTRY(VEN_YAMAHA, 0x0010000c, &yamaha_go_spec),
 	/* IDs are unknown but able to be supported */
 	/*  Apogee, Mini-ME Firewire */
 	/*  Apogee, Mini-DAC Firewire */
sound/firewire/bebob/bebob.h +1 -0
index a5422ea..8192da4 100644
@@ -231,6 +231,7 @@ int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
 /* model specific operations */
 extern struct snd_bebob_spec phase88_rack_spec;
 extern struct snd_bebob_spec phase24_series_spec;
+extern struct snd_bebob_spec yamaha_go_spec;
 
 #define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
 { \
sound/firewire/bebob/bebob_yamaha.c new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#70 lore raw

PATCH 36/39 bebob: Add support for Focusrite Saffire/SaffirePro series

In reply to Takashi Sakamoto

This commit allows this driver to support all of models which Focusrite produces with DM1000/BeBoB. They are:
- Saffire
- Saffire LE
- SaffirePro 10 I/O
- SaffirePro 26 I/O

This commit adds Focusrite specific operations:
1. Get source of clock
2. Get/Set sampling frequency
3. Get metering information

The driver uses these functionalities to read/write specific address by async transaction.

---
 sound/firewire/Kconfig                 |   1 +
 sound/firewire/bebob/Makefile          |   2 +-
 sound/firewire/bebob/bebob.c           |  30 +++-
 sound/firewire/bebob/bebob.h           |   4 +
 sound/firewire/bebob/bebob_focusrite.c | 287 +++++++++++++++++++++++++++++++++
 5 files changed, 322 insertions(+), 2 deletions(-)
 create mode 100644 sound/firewire/bebob/bebob_focusrite.c
sound/firewire/Kconfig +1 -0
index e7605ff..14ae19c 100644
@@ -112,6 +112,7 @@ config SND_BEBOB
 	  * Terratec EWS MIC2/EWS MIC4
 	  * Terratec Aureon 7.1 Firewire
 	  * Yamaha GO44/GO46
+	  * Focusrite Saffire/Saffire LE/SaffirePro10 IO/SaffirePro26 IO
 
           To compile this driver as a module, choose M here: the module
           will be called snd-bebob.
sound/firewire/bebob/Makefile +1 -1
index c35eee1..6565420 100644
@@ -1,4 +1,4 @@
 snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob_midi.o \
 		  bebob_pcm.o bebob_hwdep.o bebob_terratec.o bebob_yamaha.o \
-		  bebob.o
+		  bebob_focusrite.o bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +29 -1
index 3efb620..9ffba70 100644
@@ -54,6 +54,9 @@ static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
 #define VEN_PRISMSOUND	0x00001198
 #define VEN_TERRATEC	0x00000aac
 #define VEN_YAMAHA	0x0000a0de
+#define VEN_FOCUSRITE	0x0000130e
+
+#define MODEL_FOCUSRITE_SAFFIRE_BOTH	0x00000000
 
 static int
 name_device(struct snd_bebob *bebob, unsigned int vendor_id)
@@ -122,6 +125,20 @@ bebob_card_free(struct snd_card *card)
 	mutex_destroy(&bebob->mutex);
 }
 
+static const struct snd_bebob_spec *
+get_saffire_spec(struct fw_unit *unit)
+{
+	char name[24] = {0};
+
+	if (fw_csr_string(unit->directory, CSR_MODEL, name, sizeof(name)) < 0)
+		return NULL;
+
+	if (strcmp(name, "SaffireLE") == 0)
+		return &saffire_le_spec;
+	else
+		return &saffire_spec;
+}
+
 static int
 bebob_probe(struct fw_unit *unit,
 	    const struct ieee1394_device_id *entry)
@@ -143,7 +160,11 @@ bebob_probe(struct fw_unit *unit,
 		goto end;
 	}
 
-	spec = (const struct snd_bebob_spec *)entry->driver_data;
+	if ((entry->vendor_id == VEN_FOCUSRITE) &&
+	    (entry->model_id == MODEL_FOCUSRITE_SAFFIRE_BOTH))
+		spec = get_saffire_spec(unit);
+	else
+		spec = (const struct snd_bebob_spec *)entry->driver_data;
 	if (spec == NULL) {
 		err = -ENOSYS;
 		goto end;
@@ -307,6 +328,13 @@ static const struct ieee1394_device_id bebob_id_table[] = {
 	SND_BEBOB_DEV_ENTRY(VEN_YAMAHA, 0x0010000b, &yamaha_go_spec),
 	/* YAMAHA, GO46 */
 	SND_BEBOB_DEV_ENTRY(VEN_YAMAHA, 0x0010000c, &yamaha_go_spec),
+	/* Focusrite, SaffirePro 26 I/O */
+	SND_BEBOB_DEV_ENTRY(VEN_FOCUSRITE, 0x00000003, &saffirepro_26_spec),
+	/* Focusrite, SaffirePro 10 I/O */
+	SND_BEBOB_DEV_ENTRY(VEN_FOCUSRITE, 0x00000006, &saffirepro_10_spec),
+	/* Focusrite, Saffire(no label and LE) */
+	SND_BEBOB_DEV_ENTRY(VEN_FOCUSRITE, MODEL_FOCUSRITE_SAFFIRE_BOTH,
+			    &saffire_spec),
 	/* IDs are unknown but able to be supported */
 	/*  Apogee, Mini-ME Firewire */
 	/*  Apogee, Mini-DAC Firewire */
sound/firewire/bebob/bebob.h +4 -0
index 8192da4..8e5b0da 100644
@@ -232,6 +232,10 @@ int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
 extern struct snd_bebob_spec phase88_rack_spec;
 extern struct snd_bebob_spec phase24_series_spec;
 extern struct snd_bebob_spec yamaha_go_spec;
+extern struct snd_bebob_spec saffirepro_26_spec;
+extern struct snd_bebob_spec saffirepro_10_spec;
+extern struct snd_bebob_spec saffire_le_spec;
+extern struct snd_bebob_spec saffire_spec;
 
 #define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
 { \
sound/firewire/bebob/bebob_focusrite.c new file +287 -0

287 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#71 lore raw

PATCH 37/39 bebob: Add support for M-Audio usual Firewire series

In reply to Takashi Sakamoto

This commit allows this driver to support some models which M-Audio produces with DM1000/DM1000E with usual firmware. They are:
- Firewire 410
- Firewire AudioPhile
- Firewire Solo
- Ozonic
- NRV10
- FirewireLightBridge

According to person of BridgeCo, Some models are produced with 'Pre-BeBoB'. This means that these products were released before BeBoB was officially produced. So these models have some quirks.

M-Audio usual firmware quirks:
- Just after powering on, 'Firewire 410' waits to download firmware. This state is changed when receiving cue. Then bus reset is generated and the device is recognized as a different model with the uploaded firmware.
- 'Firewire Audiophile' also waits to download firmware but its vendor id/model id is the same as the one after loading firmware.
- The information of channel mapping for MIDI conformant data channel is invalid against BridgeCo specification.

This commit adds some codes for these quirks but don't support to upload firmware.

This commit also adds specific operations to get metering information. The metering information also includes status of clock synchronization if the model supports to switch source of clock.

The specification of FirewireLightBridge is unknown. So in this time, normal operations are applied for this model.

---
 sound/firewire/Kconfig              |   2 +
 sound/firewire/bebob/Makefile       |   2 +-
 sound/firewire/bebob/bebob.c        |  45 ++++++++-
 sound/firewire/bebob/bebob.h        |   5 +
 sound/firewire/bebob/bebob_maudio.c | 180 ++++++++++++++++++++++++++++++++++++
 sound/firewire/bebob/bebob_stream.c |   9 ++
 6 files changed, 240 insertions(+), 3 deletions(-)
 create mode 100644 sound/firewire/bebob/bebob_maudio.c
sound/firewire/Kconfig +2 -0
index 14ae19c..f9aa176 100644
@@ -113,6 +113,8 @@ config SND_BEBOB
 	  * Terratec Aureon 7.1 Firewire
 	  * Yamaha GO44/GO46
 	  * Focusrite Saffire/Saffire LE/SaffirePro10 IO/SaffirePro26 IO
+	  * M-Audio Firewire410/AudioPhile/Solo
+	  * M-Audio Ozonic/NRV10/ProfireLightBridge
 
           To compile this driver as a module, choose M here: the module
           will be called snd-bebob.
sound/firewire/bebob/Makefile +1 -1
index 6565420..6cf470c 100644
@@ -1,4 +1,4 @@
 snd-bebob-objs := bebob_command.o bebob_stream.o bebob_proc.o bebob_midi.o \
 		  bebob_pcm.o bebob_hwdep.o bebob_terratec.o bebob_yamaha.o \
-		  bebob_focusrite.o bebob.o
+		  bebob_focusrite.o bebob_maudio.o bebob.o
 obj-m += snd-bebob.o
sound/firewire/bebob/bebob.c +43 -2

85 lines not on this page · raw message

sound/firewire/bebob/bebob.h +5 -0
index 8e5b0da..1e9af0e 100644
@@ -236,6 +236,11 @@ extern struct snd_bebob_spec saffirepro_26_spec;
 extern struct snd_bebob_spec saffirepro_10_spec;
 extern struct snd_bebob_spec saffire_le_spec;
 extern struct snd_bebob_spec saffire_spec;
+extern struct snd_bebob_spec maudio_fw410_spec;
+extern struct snd_bebob_spec maudio_audiophile_spec;
+extern struct snd_bebob_spec maudio_solo_spec;
+extern struct snd_bebob_spec maudio_ozonic_spec;
+extern struct snd_bebob_spec maudio_nrv10_spec;
 
 #define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
 { \
sound/firewire/bebob/bebob_maudio.c new file +180 -0

180 lines not on this page · raw message

sound/firewire/bebob/bebob_stream.c +9 -0
index de80756..92e91a7 100644
@@ -216,6 +216,15 @@ map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
 			/* location of this channel in this section */
 			sec_loc = buf[pos++] - 1;
 
+			/*
+			 * Basically the number of location is within the
+			 * number of channels in this section. But some models
+			 * of M-Audio don't follow this. Its location for MIDI
+			 * is the position of MIDI channels in AMDTP packet.
+			 */
+			if (sec_loc >= channels)
+				sec_loc = ch;
+
 			switch (type) {
 			/* for MIDI conformant data channel */
 			case 0x0a:
Signature · 1 line
1.8.3.2
maintainer
#72 lore raw

PATCH 38/39 bebob: Add support for M-Audio special Firewire series

In reply to Takashi Sakamoto

This commit allows this driver to support some models which M-Audio produces with DM1000 but its firmware is special. They are:
- Firewire 1814
- ProjectMix I/O

They have heavily customized firmware. The usual operations can't be applied to them. For this reason, this commit adds a model specific member in 'struct snd_bebob' and some model specific functions. Some parameters are write-only so this commit also adds control interface for applications.

M-Audio special firmware quirks:
- Just after powering on, they wait to download firmware. This state is changed when receiving cue. Then bus reset is generated and the device is recognized as a different model with the uploaded firmware.
- They don't respond against BridgeCo AV/C extension commands. So drivers can't get their stream formations and so on.
- They do not start to transmit packets only by establishing connection but also by receiving SIGNAL FORMAT command.
- They often handle requests without responding. In this reason, this driver often fail to handle them correctly.

This module don't support to upload firmware.

Here are three examples of transactions between BeBoB driver and M-Audio Firewire 1814. An fallback at timeout in the operations for CMP was already added by previous commit. But for isochronous resource management, no fallbacks are added. Further works are needed for Linux Firewire Subsystem.

At releasing connections/resources for both direction:

[27200.724273] firewire_ohci 0000:0c:06.0: AT spd 2 tl 28, ffc0 -> ffc1, ack_pending , Lk req, fffff0000984 8,2
[27200.724921] firewire_ohci 0000:0c:06.0: AR spd 2 tl 28, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27200.725037] firewire_ohci 0000:0c:06.0: AT spd 0 tl 29, ffc0 -> ffc1, ack_pending , Lk req, fffff0000224 8,2
[27200.725598] firewire_ohci 0000:0c:06.0: AR spd 2 tl 29, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27200.725714] firewire_ohci 0000:0c:06.0: AT spd 0 tl 2a, ffc0 -> ffc1, ack_pending , Lk req, fffff0000220 8,2
[27202.727199] firewire_ohci 0000:0c:06.0: AT spd 0 tl 2b, ffc0 -> ffc1, ack_pending , Lk req, fffff0000220 8,2
[27202.727735] firewire_ohci 0000:0c:06.0: AR spd 2 tl 2b, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27202.727858] firewire_ohci 0000:0c:06.0: AT spd 2 tl 2c, ffc0 -> ffc1, ack_pending , Lk req, fffff0000904 8,2
[27204.750950] firewire_ohci 0000:0c:06.0: AT spd 2 tl 2d, ffc0 -> ffc1, ack_pending , Lk req, fffff0000904 8,2
[27206.777677] firewire_ohci 0000:0c:06.0: AT spd 2 tl 2e, ffc0 -> ffc1, ack_pending , Lk req, fffff0000904 8,2
[27208.779327] snd-bebob fw1.0: transaction failed: timeout
[27208.779333] snd-bebob fw1.0: oPCR0: plug is still connected

(The device handled a first operation for oPCR0 but not respond.)

At releasing connections/resources for both direction:

[27603.200092] firewire_ohci 0000:0c:06.0: AT spd 2 tl 02, ffc0 -> ffc1, ack_pending , Lk req, fffff0000904 8,2
[27603.200455] firewire_ohci 0000:0c:06.0: AR spd 2 tl 02, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27603.200629] firewire_ohci 0000:0c:06.0: AT spd 0 tl 03, ffc0 -> ffc1, ack_pending , Lk req, fffff0000224 8,2
[27605.203315] firewire_ohci 0000:0c:06.0: AT spd 0 tl 04, ffc0 -> ffc1, ack_pending , Lk req, fffff0000224 8,2
[27605.203962] firewire_ohci 0000:0c:06.0: AR spd 2 tl 04, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27605.204077] firewire_ohci 0000:0c:06.0: AT spd 0 tl 05, ffc0 -> ffc1, ack_pending , Lk req, fffff0000220 8,2
[27605.204507] firewire_ohci 0000:0c:06.0: AR spd 2 tl 05, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27605.204569] snd-bebob fw1.0: isochronous resource deallocation failed

(The device handled a first operation for CSR_CHANNELS_AVAILABLE_HI but not respond.)

At keeping resources and establising connections:

[27212.950366] firewire_ohci 0000:0c:06.0: AT spd 0 tl 35, ffc0 -> ffc1, ack_pending , Lk req, fffff0000224 8,2
[27212.950922] firewire_ohci 0000:0c:06.0: AR spd 2 tl 35, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27212.951060] firewire_ohci 0000:0c:06.0: AT spd 0 tl 36, ffc0 -> ffc1, ack_pending , Lk req, fffff0000224 8,2
[27212.951505] firewire_ohci 0000:0c:06.0: AR spd 2 tl 36, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27212.951590] firewire_ohci 0000:0c:06.0: AT spd 0 tl 37, ffc0 -> ffc1, ack_pending , Lk req, fffff0000220 8,2
[27212.952101] firewire_ohci 0000:0c:06.0: AR spd 2 tl 37, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27212.952220] firewire_ohci 0000:0c:06.0: AT spd 2 tl 38, ffc0 -> ffc1, ack_pending , Lk req, fffff0000904 8,2
[27212.952568] firewire_ohci 0000:0c:06.0: AR spd 2 tl 38, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27212.952715] firewire_ohci 0000:0c:06.0: AT spd 2 tl 39, ffc0 -> ffc1, ack_pending , Lk req, fffff0000904 8,2
[27212.953044] firewire_ohci 0000:0c:06.0: AR spd 2 tl 39, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27212.953178] firewire_ohci 0000:0c:06.0: AT spd 0 tl 3a, ffc0 -> ffc1, ack_pending , Lk req, fffff0000224 8,2
[27212.953504] firewire_ohci 0000:0c:06.0: AR spd 2 tl 3a, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27212.953588] firewire_ohci 0000:0c:06.0: AT spd 0 tl 3b, ffc0 -> ffc1, ack_pending , Lk req, fffff0000224 8,2
[27212.954017] firewire_ohci 0000:0c:06.0: AR spd 2 tl 3b, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27212.954077] firewire_ohci 0000:0c:06.0: AT spd 0 tl 3c, ffc0 -> ffc1, ack_pending , Lk req, fffff0000220 8,2
[27212.954364] firewire_ohci 0000:0c:06.0: AR spd 2 tl 3c, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27212.954429] firewire_ohci 0000:0c:06.0: AT spd 2 tl 3d, ffc0 -> ffc1, ack_pending , Lk req, fffff0000984 8,2
[27214.980602] firewire_ohci 0000:0c:06.0: AT spd 2 tl 3e, ffc0 -> ffc1, ack_pending , Lk req, fffff0000984 8,2
[27214.981135] firewire_ohci 0000:0c:06.0: AR spd 2 tl 3e, ffc1 -> ffc0, ack_complete, Lk resp 4,2
[27214.981195] snd-bebob fw1.0: iPCR0: plug is already in use
(The device handled a first operation for iPCR0 but not respond.)
---
 sound/firewire/Kconfig                |   1 +
 sound/firewire/bebob/bebob.c          |  20 +-
 sound/firewire/bebob/bebob.h          |   9 +-
 sound/firewire/bebob/bebob_command.c  |  16 +-
 sound/firewire/bebob/bebob_maudio.c   | 581 +++++++++++++++++++++++++++++++++-
 sound/firewire/bebob/bebob_stream.c   |  39 ++-
 sound/firewire/bebob/bebob_terratec.c |   6 +-
 sound/firewire/bebob/bebob_yamaha.c   |   2 +-
 8 files changed, 650 insertions(+), 24 deletions(-)
sound/firewire/Kconfig +1 -0
index f9aa176..b719ecf 100644
@@ -115,6 +115,7 @@ config SND_BEBOB
 	  * Focusrite Saffire/Saffire LE/SaffirePro10 IO/SaffirePro26 IO
 	  * M-Audio Firewire410/AudioPhile/Solo
 	  * M-Audio Ozonic/NRV10/ProfireLightBridge
+	  * M-Audio Firewire 1814/ProjectMix IO
 
           To compile this driver as a module, choose M here: the module
           will be called snd-bebob.
sound/firewire/bebob/bebob.c +19 -1
index e8a22e6..d6f245e 100644
@@ -60,6 +60,8 @@ static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
 
 #define MODEL_FOCUSRITE_SAFFIRE_BOTH	0x00000000
 #define MODEL_MAUDIO_AUDIOPHILE_BOTH	0x00010060
+#define MODEL_MAUDIO_FW1814		0x00010071
+#define MODEL_MAUDIO_PROJECTMIX		0x00010091
 
 static int
 name_device(struct snd_bebob *bebob, unsigned int vendor_id)
@@ -209,7 +211,14 @@ bebob_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto error;
 
-	err = snd_bebob_stream_discover(bebob);
+	if ((entry->vendor_id == VEN_MAUDIO1) &&
+	    (entry->model_id == MODEL_MAUDIO_FW1814))
+		err = snd_bebob_maudio_special_discover(bebob, true);
+	else if ((entry->vendor_id == VEN_MAUDIO1) &&
+		 (entry->model_id == MODEL_MAUDIO_PROJECTMIX))
+		err = snd_bebob_maudio_special_discover(bebob, false);
+	else
+		err = snd_bebob_stream_discover(bebob);
 	if (err < 0)
 		goto error;
 
@@ -271,6 +280,9 @@ static void bebob_remove(struct fw_unit *unit)
 	if (bebob == NULL)
 		return;
 
+	if (bebob->maudio_special_quirk != NULL)
+		kfree(bebob->maudio_special_quirk);
+
 	snd_bebob_stream_destroy_duplex(bebob);
 	snd_card_disconnect(bebob->card);
 	snd_card_free_when_closed(bebob->card);
@@ -376,6 +388,12 @@ static const struct ieee1394_device_id bebob_id_table[] = {
 	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x00010081, &maudio_nrv10_spec),
 	/* M-Audio, ProFireLightbridge */
 	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x000100a1, &spec_normal),
+	/* Firewire 1814 */
+	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_FW1814,
+			    &maudio_special_spec),
+	/* M-Audio ProjectMix */
+	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_PROJECTMIX,
+			    &maudio_special_spec),
 	/* IDs are unknown but able to be supported */
 	/*  Apogee, Mini-ME Firewire */
 	/*  Apogee, Mini-DAC Firewire */
sound/firewire/bebob/bebob.h +7 -2
index 1e9af0e..ef74049 100644
@@ -101,6 +101,9 @@ struct snd_bebob {
 	int dev_lock_count;
 	bool dev_lock_changed;
 	wait_queue_head_t hwdep_wait;
+
+	/* for M-Audio special devices */
+	void *maudio_special_quirk;
 };
 
 static inline int
@@ -123,7 +126,7 @@ snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)
 int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
 			   unsigned int fb_id, unsigned int num);
 int avc_audio_get_selector(struct fw_unit *unit, unsigned  int subunit_id,
-			   unsigned int fb_id, unsigned int *num);
+			   unsigned int fb_id, unsigned int *num, bool quiet);
 
 /*
  * AVC command extensions, AV/C Unit and Subunit, Revision 17
@@ -196,7 +199,7 @@ int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
 				   unsigned int *len);
 
 int snd_bebob_get_rate(struct snd_bebob *bebob, unsigned int *rate,
-		       enum avc_general_plug_dir dir);
+		       enum avc_general_plug_dir dir, bool quiet);
 int snd_bebob_set_rate(struct snd_bebob *bebob, unsigned int rate,
 		       enum avc_general_plug_dir dir);
 
@@ -241,6 +244,8 @@ extern struct snd_bebob_spec maudio_audiophile_spec;
 extern struct snd_bebob_spec maudio_solo_spec;
 extern struct snd_bebob_spec maudio_ozonic_spec;
 extern struct snd_bebob_spec maudio_nrv10_spec;
+extern struct snd_bebob_spec maudio_special_spec;
+int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
 
 #define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
 { \
sound/firewire/bebob/bebob_command.c +9 -7
index 1813384..78d02a0 100644
@@ -50,7 +50,7 @@ end:
 }
 
 int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,
-			   unsigned int fb_id, unsigned int *num)
+			   unsigned int fb_id, unsigned int *num, bool quiet)
 {
 	u8 *buf;
 	int err;
@@ -76,9 +76,10 @@ int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,
 	if (err < 0)
 		goto end;
 	if ((err < 6) || (buf[0] != 0x0c)) {
-		dev_err(&unit->device,
-			"failed to get selector %d: 0x%02X\n",
-			fb_id, buf[0]);
+		if (!quiet)
+			dev_err(&unit->device,
+				"failed to get selector %d: 0x%02X\n",
+				fb_id, buf[0]);
 		err = -EIO;
 		goto end;
 	}
@@ -314,7 +315,7 @@ end:
 }
 
 int snd_bebob_get_rate(struct snd_bebob *bebob, unsigned int *rate,
-		       enum avc_general_plug_dir dir)
+		       enum avc_general_plug_dir dir, bool quiet)
 {
 	int err;
 
@@ -324,8 +325,9 @@ int snd_bebob_get_rate(struct snd_bebob *bebob, unsigned int *rate,
 
 	/* IMPLEMENTED/STABLE is OK */
 	if (err != 0x0c) {
-		dev_err(&bebob->unit->device,
-			"failed to get sampling rate\n");
+		if (!quiet)
+			dev_err(&bebob->unit->device,
+				"failed to get sampling rate\n");
 		err = -EIO;
 	}
 end:
sound/firewire/bebob/bebob_maudio.c +580 -1

620 lines not on this page · raw message

sound/firewire/bebob/bebob_stream.c +30 -9
index 92e91a7..1939e16 100644
@@ -64,11 +64,13 @@ snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *curr_rate)
 	unsigned int tx_rate, rx_rate;
 	int err;
 
-	err = snd_bebob_get_rate(bebob, &tx_rate, AVC_GENERAL_PLUG_DIR_OUT);
+	err = snd_bebob_get_rate(bebob, &tx_rate, AVC_GENERAL_PLUG_DIR_OUT,
+				 false);
 	if (err < 0)
 		goto end;
 
-	err = snd_bebob_get_rate(bebob, &rx_rate, AVC_GENERAL_PLUG_DIR_IN);
+	err = snd_bebob_get_rate(bebob, &rx_rate, AVC_GENERAL_PLUG_DIR_IN,
+				 false);
 	if (err < 0)
 		goto end;
 
@@ -344,7 +346,6 @@ break_both_connections(struct snd_bebob *bebob)
 {
 	cmp_connection_break(&bebob->in_conn);
 	cmp_connection_break(&bebob->out_conn);
-	return;
 }
 
 static void
@@ -381,9 +382,11 @@ start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream,
 		conn = &bebob->out_conn;
 
 	/* channel mapping */
-	err = map_data_channels(bebob, stream);
-	if (err < 0)
-		goto end;
+	if (bebob->maudio_special_quirk == NULL) {
+		err = map_data_channels(bebob, stream);
+		if (err < 0)
+			goto end;
+	}
 
 	/* start amdtp stream */
 	err = amdtp_stream_start(stream,
@@ -472,10 +475,14 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob,
 		 * NOTE:
 		 * If establishing connections at first, Yamaha GO46
 		 * (and maybe Terratec X24) don't generate sound.
+		 *
+		 * For firmware customized by M-Audio, refer to next NOTE.
 		 */
-		err = rate_spec->set(bebob, rate);
-		if (err < 0)
-			goto end;
+		if (bebob->maudio_special_quirk == NULL) {
+			err = rate_spec->set(bebob, rate);
+			if (err < 0)
+				goto end;
+		}
 
 		err = make_both_connections(bebob, rate);
 		if (err < 0)
@@ -489,6 +496,20 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob,
 			goto end;
 		}
 
+		/*
+		 * NOTE:
+		 * The firmware customized by M-Audio uses these commands to
+		 * start transmitting stream. This is not usual way.
+		 */
+		if (bebob->maudio_special_quirk != NULL) {
+			err = rate_spec->set(bebob, rate);
+			if (err < 0) {
+				amdtp_stream_stop(master);
+				break_both_connections(bebob);
+				goto end;
+			}
+		}
+
 		/* wait first callback */
 		if (!amdtp_stream_wait_callback(master, CALLBACK_TIMEOUT)) {
 			amdtp_stream_stop(master);
sound/firewire/bebob/bebob_terratec.c +3 -3
index 9c2cebf..d5da8de 100644
@@ -17,10 +17,10 @@ phase88_rack_clk_src_get(struct snd_bebob *bebob, unsigned int *id)
 	unsigned int enable_ext, enable_word;
 	int err;
 
-	err = avc_audio_get_selector(bebob->unit, 0, 0, &enable_ext);
+	err = avc_audio_get_selector(bebob->unit, 0, 0, &enable_ext, false);
 	if (err < 0)
 		goto end;
-	err = avc_audio_get_selector(bebob->unit, 0, 0, &enable_word);
+	err = avc_audio_get_selector(bebob->unit, 0, 0, &enable_word, false);
 	if (err < 0)
 		goto end;
 
@@ -35,7 +35,7 @@ static char *phase24_series_clk_src_labels[] = {
 static int
 phase24_series_clk_src_get(struct snd_bebob *bebob, unsigned int *id)
 {
-	return avc_audio_get_selector(bebob->unit, 0, 4, id);
+	return avc_audio_get_selector(bebob->unit, 0, 4, id, false);
 }
 
 struct snd_bebob_rate_spec phase_series_rate_spec = {
sound/firewire/bebob/bebob_yamaha.c +1 -1
index f71af6b..23ca489 100644
@@ -32,7 +32,7 @@ static char *clk_src_labels[] = {SND_BEBOB_CLOCK_INTERNAL, "SPDIF"};
 static int
 clk_src_get(struct snd_bebob *bebob, unsigned int *id)
 {
-	return avc_audio_get_selector(bebob->unit, 0, 4, id);
+	return avc_audio_get_selector(bebob->unit, 0, 4, id, false);
 }
 static struct snd_bebob_clock_spec clock_spec = {
 	.num	= ARRAY_SIZE(clk_src_labels),
Signature · 1 line
1.8.3.2
maintainer
#73 lore raw

PATCH 39/39 bebob: Send a cue to load firmware for M-Audio Firewire series

In reply to Takashi Sakamoto

Just powering on, these devices below wait to download firmware.
- Firewire Audiophile
- Firewire 410
- Firewire 1814
- ProjectMix I/O

But firmware version 5058 or later, flash memory in the device stores the firmware. So this driver can enable these devices by sending a certain cue to load the firmware.

---
 sound/firewire/bebob/bebob.c        | 23 ++++++++-----
 sound/firewire/bebob/bebob.h        |  1 +
 sound/firewire/bebob/bebob_maudio.c | 69 +++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 9 deletions(-)
sound/firewire/bebob/bebob.c +14 -9
index d6f245e..aa0a893 100644
@@ -177,18 +177,21 @@ bebob_probe(struct fw_unit *unit,
 	}
 
 	if ((entry->vendor_id == VEN_FOCUSRITE) &&
-	    (entry->model_id == MODEL_FOCUSRITE_SAFFIRE_BOTH)) {
+	    (entry->model_id == MODEL_FOCUSRITE_SAFFIRE_BOTH))
 		spec = get_saffire_spec(unit);
-	} else if ((entry->vendor_id == VEN_MAUDIO1) &&
-		   (entry->model_id == MODEL_MAUDIO_AUDIOPHILE_BOTH) &&
-		   !check_audiophile_booted(unit)) {
-			err = 0;
-			goto end;
-	} else {
+	else if ((entry->vendor_id == VEN_MAUDIO1) &&
+		 (entry->model_id == MODEL_MAUDIO_AUDIOPHILE_BOTH) &&
+		 !check_audiophile_booted(unit))
+		spec = NULL;
+	else
 		spec = (const struct snd_bebob_spec *)entry->driver_data;
-	}
+
 	if (spec == NULL) {
-		err = -ENOSYS;
+		if ((entry->vendor_id == VEN_MAUDIO1) ||
+		    (entry->vendor_id == VEN_MAUDIO2))
+			err = snd_bebob_maudio_load_firmware(unit);
+		else
+			err = -ENOSYS;
 		goto end;
 	}
 
@@ -376,6 +379,7 @@ static const struct ieee1394_device_id bebob_id_table[] = {
 	SND_BEBOB_DEV_ENTRY(VEN_FOCUSRITE, MODEL_FOCUSRITE_SAFFIRE_BOTH,
 			    &saffire_spec),
 	/* M-Audio, Firewire 410 */
+	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO2, 0x00010058, NULL),	/* bootloader */
 	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO2, 0x00010046, &maudio_fw410_spec),
 	/* M-Audio, Firewire Audiophile */
 	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_AUDIOPHILE_BOTH,
@@ -389,6 +393,7 @@ static const struct ieee1394_device_id bebob_id_table[] = {
 	/* M-Audio, ProFireLightbridge */
 	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x000100a1, &spec_normal),
 	/* Firewire 1814 */
+	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x00010070, NULL),     /* bootloader */
 	SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_FW1814,
 			    &maudio_special_spec),
 	/* M-Audio ProjectMix */
sound/firewire/bebob/bebob.h +1 -0
index ef74049..2226381 100644
@@ -246,6 +246,7 @@ extern struct snd_bebob_spec maudio_ozonic_spec;
 extern struct snd_bebob_spec maudio_nrv10_spec;
 extern struct snd_bebob_spec maudio_special_spec;
 int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
+int snd_bebob_maudio_load_firmware(struct fw_unit *unit);
 
 #define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
 { \
sound/firewire/bebob/bebob_maudio.c +69 -0

87 lines not on this page · raw message

Signature · 1 line
1.8.3.2
maintainer
#2 lore raw
In reply to Takashi Iwai

Iwa-san,

Quoted 2 lines · Takashi Iwai

Could you submit v2 patches to ML? The patches need review, and I want get them acked by Clemens before applying.

OK. I sent patches now to this thread.

Quoted 2 lines · Takashi Iwai

The end-result patches must be identical, so you don't have to resend them to ML, though.

I think to have misunderstood what you mean in this message.
Did you ask me not to send patches with 'GIT PULL' because you can read commits in repository?

# And this mailman ignored my message again...

Regards

Takashi Sakamoto
[email protected]

#3 lore raw

At Wed, 05 Mar 2014 20:00:00 +0900,

Quoted 9 lines · Takashi Sakamoto

Iwa-san,

Quoted 2 lines · Takashi Iwai

Could you submit v2 patches to ML? The patches need review, and I want get them acked by Clemens before applying.

OK. I sent patches now to this thread.

Quoted 7 lines
Quoted 2 lines · Takashi Iwai

The end-result patches must be identical, so you don't have to resend them to ML, though.

I think to have misunderstood what you mean in this message. Did you ask me not to send patches with 'GIT PULL' because you can read commits in repository?

I meant that the rebased patches weren't needed to be resent, if rebase were the only action you made. But you fixed other things, right? Then each patch must be submitted again.

And, in general, I won't do git pull to my repo from github. So, the subject prefix '[GIT PULL]' makes no sense to me. It's still useful to keep the git repo for easier review, though.

Quoted 1 line

# And this mailman ignored my message again...

Relax, it's not lost. It just takes time due to SPAM filtering or whatever running there.

thanks,

Takashi

maintainer
#4 lore raw
Quoted 3 lines · Takashi Iwai

I meant that the rebased patches weren't needed to be resent, if rebase were the only action you made. But you fixed other things, right? Then each patch must be submitted again.

Right. I added changes into the patches since last pull-request. Now I understand what you meant.

Quoted 3 lines

And, in general, I won't do git pull to my repo from github. So, the subject prefix '[GIT PULL]' makes no sense to me. It's still useful to keep the git repo for easier review, though.

OK. I remember it for my future work.

Quoted 4 lines
Quoted 1 line

# And this mailman ignored my message again...

Relax, it's not lost. It just takes time due to SPAM filtering or whatever running there.

Hmm. I'll wait for blasting my message a bit more...

Thanks

Takashi Sakamoto
[email protected]

#74 lore raw
In reply to a message not in the archive

At Wed, 05 Mar 2014 12:13:03 +0900,

Quoted 6 lines · Takashi Sakamoto

This pull-request is an update for my previous pull-request:
[alsa-devel] [GIT PULL][PATCH 00/39] Enhancement of support for Firewire devices
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-February/073446.html

Quoted 14 lines

Updates since previous pull-request:
firewire-lib:
- use swap() instead of local macro
- check NULL at memory allocation for sort table
fireworks:
- use bitmap.h for card slots
- add 'firewire' subdirectory for card node in procfs
- add sanity check of module parameter with clamp()
bebob:
- use bitmap.h for card slots
- add 'firewire' subdirectory for card node in procfs
- simplify codes for metering
- use swap() instead of local macro
- change order of last two commits

Clemens, could you review this new series?

thanks,

Takashi

maintainer
#75 lore raw
Quoted 20 lines · Takashi Iwai
Quoted 4 lines · Takashi Sakamoto

This pull-request is an update for my previous pull-request:
[alsa-devel] [GIT PULL][PATCH 00/39] Enhancement of support for Firewire devices
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-February/073446.html

Quoted 14 lines

Updates since previous pull-request:
firewire-lib:
- use swap() instead of local macro
- check NULL at memory allocation for sort table
fireworks:
- use bitmap.h for card slots
- add 'firewire' subdirectory for card node in procfs
- add sanity check of module parameter with clamp()
bebob:
- use bitmap.h for card slots
- add 'firewire' subdirectory for card node in procfs
- simplify codes for metering
- use swap() instead of local macro
- change order of last two commits

Quoted 1 line

Clemens, could you review this new series?

I'll see what I can do this weekend ...

Regards,
Clemens

maintainer
#11 lore raw

Re: [PATCH 05/39] firewire-lib: Add support for AMDTP in-stream and PCM capture

In reply to Takashi Sakamoto
Quoted 5 lines · Takashi Sakamoto

For capturing PCM, this commit adds the functionality to handle in-stream. This is also applied for dual-wire mode.

+++ b/sound/firewire/amdtp.c

sound/firewire/amdtp.c void amdtp_stream_set_pcm_format(struct amdtp_stream *s, · line 217

Quoted 10 lines
sound/firewire/amdtp.c +10 -0
@@ -200,16 +208,26 @@ void amdtp_stream_set_pcm_format(struct amdtp_stream *s,
+		if (s->direction == AMDTP_OUT_STREAM) {
+			if (s->dual_wire)
+				s->transfer_samples = amdtp_write_s32_dualwire;
+			else
+				s->transfer_samples = amdtp_write_s32;
+		} else if (s->dual_wire) {
+			s->transfer_samples = amdtp_read_s32_dualwire;
+		} else {
+			s->transfer_samples = amdtp_read_s32;
+		}

Please format the if/else branches in the same way.

sound/firewire/amdtp.c static void handle_out_packet(struct amdtp_stream *s, unsigned int cycle) · line 658

Quoted 6 lines
sound/firewire/amdtp.c +5 -0
+static void handle_in_packet(struct amdtp_stream *s,
...
+	/* ignore empty CIP packet or NO-DATA AMDTP packet */
+	if ((payload_quadlets < 3) ||
+	    (((cip_header[1] & CIP_FDF_MASK) >> CIP_FDF_SFC_SHIFT) ==
+							AMDTP_FDF_NO_DATA))

(AMDTP_FDF_NO_DATA << CIP_FDF_SFC_SHIFT) would be a constant that could be computed at compile time.

sound/firewire/amdtp.c static void handle_out_packet(struct amdtp_stream *s, unsigned int cycle) · line 680

Quoted 7 lines
sound/firewire/amdtp.c +7 -0
+	/* check packet continuity */
+	s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;
+	if (s->data_block_counter != data_block_counter) {
+		dev_info_ratelimited(&s->unit->device,
+				     "Detect uncontinuity of CIP packets\n");
+		s->data_block_counter = data_block_counter;
+		return;

In practice, this error means that a packet was dropped. I guess this doesn't actually happen too often, but eventually, we should handle this either by inserting some samples or by stopping the stream.

Regards,
Clemens

maintainer
#16 lore raw

Re: [PATCH 06/39] firewire-lib: Add support for MIDI capture/playback

In reply to Takashi Sakamoto
Quoted 16 lines · Takashi Sakamoto

For capturing/playbacking MIDI messages, this commit adds one MIDI conformant data channel. This channel supports 8 MPX-MIDI data streams then maximum number of supported MIDI ports is limited by 8.

And this commit allows to set PCM format even if AMDTP stream already starts. I suppose the case that PCM stream is going to be joined into AMDTP streams after AMDTP stream is already started by MIDI. Each driver must count how many MIDI substreams use AMDTP stream to stop AMDTP stream.

IEC 61883-6 refers to AMEI/MMA RP-027 for implementation of MIDI conformant data. In the specification, 'MIDI1.0-2x/3x-SPEED' mode are described with 'negotiation procedure' and 'encapsulation details'. But there is no specifications to define them. This module implement 'MIDI1.0-1x-SPEED' mode.

+++ b/sound/firewire/amdtp.c

sound/firewire/amdtp.c static void amdtp_fill_pcm_silence(struct amdtp_stream *s, · line 515

Quoted 7 lines
sound/firewire/amdtp.c +5 -0
@@ -505,11 +509,46 @@ static void amdtp_fill_pcm_silence(struct amdtp_stream *s,
 static void amdtp_fill_midi(struct amdtp_stream *s,
 
+	unsigned int f, port;
+	u8 *b;
+
+	for (f = 0; f < frames; f++) {
+		buffer[s->pcm_channels + 1] = 0x00;

This is a 32-bit value.

sound/firewire/amdtp.c static void amdtp_fill_pcm_silence(struct amdtp_stream *s, · line 523

Quoted 7 lines
sound/firewire/amdtp.c +7 -0
+		b = (u8 *)&buffer[s->pcm_channels + 1];
+
+		port = (s->data_block_counter + f) % 8;
+		if ((s->midi[port] == NULL) ||
+		    (snd_rawmidi_transmit(s->midi[port], b + 1, 1) <= 0)) {
+			b[0] = 0x80;
+			b[1] = 0x00;	/* confirm to be zero */

snd_rawmidi_transmit() will not write an unsused byte, and in any case, zero can be a valid MIDI data byte.

sound/firewire/amdtp.c static void amdtp_fill_pcm_silence(struct amdtp_stream *s, · line 551

Quoted 11 lines
sound/firewire/amdtp.c +10 -0
+static void amdtp_pull_midi(struct amdtp_stream *s,
+			    __be32 *buffer, unsigned int frames)
+{
+	for (f = 0; f < frames; f++) {
...
+		if (s->midi[port] == NULL)
+			continue;
+
+		snd_rawmidi_receive(s->midi[port], b + 1, len);
+		buffer += s->data_block_quadlets;
+	}

The buffer pointer must be increased even when there is no active port.

sound/firewire/amdtp.h static inline bool amdtp_streaming_error(struct amdtp_stream *s) · line 162

Quoted 11 lines

+++ b/sound/firewire/amdtp.h
/**
+ * amdtp_stream_pcm_running - check PCM stream is running or not
+ * @s: the AMDTP stream
+ *
+ * If this function returns true, PCM stream in the stream is running.
+ */

sound/firewire/amdtp.h +4 -0
+static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
+{
+	return !IS_ERR_OR_NULL(s->pcm);
+}

fw_iso_context_create() can return an error code, but for s->pcm, all the IS_ERR stuff is not necessary. This should be a plain NULL check.

Regards,
Clemens

maintainer
#20 lore raw

Re: [PATCH 08/39] firewire-lib: Add support for duplex streams synchronization in blocking mode

In reply to Takashi Sakamoto
Quoted 14 lines · Takashi Sakamoto

Generally, the devices can synchronize to handle 'presentation timestamp' in CIP packets. This commit adds functionality to pick up this timestamp from in-packets transmitted by the device, then use it for out packets.

In current implementation, this module generated the timestamp by itself. This is 'SYT Match' mode. Then this drive acts as synchronization master. This commit allows this module to act as synchronization slave.

This commit restricts this mechanism is only available in blocking mode because handling the timestamp in non-blocking mode is more complicated than in blocking mode.

+++ b/sound/firewire/amdtp.c

sound/firewire/amdtp.c int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit, · line 73

Quoted 1 line
sound/firewire/amdtp.c +1 -0
@@ -72,6 +73,10 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
+	s->sync_slave = ERR_PTR(-1);

This pointer does not report any actual error code either.

sound/firewire/amdtp.c static void handle_out_packet(struct amdtp_stream *s, unsigned int syt) · line 632

Quoted 4 lines
sound/firewire/amdtp.c +1 -1
@@ -626,7 +631,7 @@ static void handle_out_packet(struct amdtp_stream *s, unsigned int syt)
 {
-	struct snd_pcm_substream *pcm;
+	struct snd_pcm_substream *pcm = NULL;

Why this change in this patch?

sound/firewire/amdtp.c static void in_stream_callback(struct fw_iso_context *context, u32 cycle, · line 776

Quoted 5 lines
sound/firewire/amdtp.c +4 -0
@@ -768,6 +773,15 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
+		/* Process sync slave stream */
+		if ((s->flags & CIP_BLOCKING) &&
+		    (s->flags & CIP_SYNC_TO_DEVICE) &&
+		    s->sync_slave->callbacked) {

It might be easier to check just s->sync_slave instead of multiple flags.

sound/firewire/amdtp.c static void in_stream_callback(struct fw_iso_context *context, u32 cycle, · line 796

Quoted 3 lines
sound/firewire/amdtp.c +3 -0
+	/* when sync to device, flush the packets for slave stream */
+	if ((s->flags & CIP_BLOCKING) &&
+	    (s->flags & CIP_SYNC_TO_DEVICE) && s->sync_slave->callbacked)

Same here.

sound/firewire/amdtp.c static void in_stream_callback(struct fw_iso_context *context, u32 cycle, · line 811

Quoted 2 lines
sound/firewire/amdtp.c +2 -0
+/* this is executed one time */
+static void amdtp_stream_callback(struct fw_iso_context *context, u32 cycle,

This name is rather generic; this is not "the" callback, but the "initial" or "first" callback.

Review

Quoted 3 lines

...

(quoted diff) +2 -0
+	return;
+}

This is not necessary here.

sound/firewire/amdtp.h static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc) · line 215

Quoted 7 lines
sound/firewire/amdtp.h +7 -0
+static inline void amdtp_stream_set_sync(enum cip_flags sync_mode,
+					 struct amdtp_stream *master,
+					 struct amdtp_stream *slave)
+{
+	/* clear sync flag */
+	master->flags &= ~CIP_SYNC_TO_DEVICE;
+	slave->flags &= ~CIP_SYNC_TO_DEVICE;

This needs to be done only if sync_mode != CIP_SYNC_TO_DEVICE.

Regards,
Clemens

maintainer
#23 lore raw

Re: [PATCH 09/39] firewire-lib: Add sort function for transmitted packet

In reply to Takashi Sakamoto
Quoted 5 lines · Takashi Sakamoto

This commit is to assure the continuity of timestamp in in-packets transmitted by devices.

Fireworks with firmware version 5.5 or former is a type of device which transmits packets with a bit disorder.

Then this should be done only when we actually have one of these known devices (and only when this error is known to happen, i.e., directly after a no-data packet); otherwise, this could, in theory, interfere with dropped packets.

Quoted 7 lines

This commit add sorting of in-packets. When callback of receive-context is processed, the parameters of in-packets are stored in sort table and sorted by its value of data block counter. The sort algorism works faster in ordered sequence than in messy sequence. This is convinient for this purpose because the sequence is assumed not to be so messy. After sorting, packets are processed except for a last few packets in sort table. These packets are stored in buffer once and used in next cycle.

Only a single packet is out of order, i.e., only two packets are exchanged. So it is not necessary to run a general-purpose sorting algorithm; it would be sufficient to store a single packet if it is out of order.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (s->sort_table != NULL)
+		kfree(s->sort_table);

A NULL check is not necessary for kfree().

Regards,
Clemens

maintainer
#29 lore raw

Re: [PATCH 10/39] firewire-lib: Add transfer delay to synchronized duplex streams

In reply to Takashi Sakamoto

sound/firewire/amdtp.c static void packet_sort(struct sort_table *tbl, unsigned int len) · line 782

Quoted 11 lines · Takashi Sakamoto

Currently, in duplex streams with synchronization mode, this module just pass 'presentation timestamp' from in-packets to out-packets. This is enough to handle actual device but logically the timestamp should include 'transfer delay' and 'processing time'. This means the timestamp in out-packet should be at future.

To be simple, this commit add only 'transfer delay'.

sound/firewire/amdtp.c +3 -0
+		*syt += (s->transfer_delay / TICKS_PER_CYCLE) << 12;
+		*syt += s->transfer_delay % TICKS_PER_CYCLE;
+		*syt &= CIP_SYT_MASK;

The transfer delay is the offset between the frame in which the packet is transmitted and the intended presentation time. This delay was already added by the device when it sent the input packets, so we don't need to send it again.

The frame in which the out-packet will be sent is QUEUE_LENGTH frames later than that of the in-packet, so we need to adjust the SYT by that amount. (However, 48 % 16 == 0.)

Regards,
Clemens

maintainer
#33 lore raw

Re: [PATCH 11/39] firewire-lib: Add support for channel mapping

In reply to Takashi Sakamoto
Quoted 8 lines · Takashi Sakamoto

Some devices arrange the position of PCM/MIDI data channel in AMDTP packet. This commit allows drivers to set channel mapping.

To be simple, the mapping table is an array with fixed length. Then the number of channels for PCM is restricted by 64 channels.

+++ b/sound/firewire/amdtp.c

sound/firewire/amdtp.c static void amdtp_write_s32(struct amdtp_stream *s, · line 357

Quoted 8 lines
sound/firewire/amdtp.c +1 -2
@@ -351,22 +358,20 @@ static void amdtp_write_s32(struct amdtp_stream *s,
 			    __be32 *buffer, unsigned int frames)
 {
 	struct snd_pcm_runtime *runtime = pcm->runtime;
-	unsigned int channels, remaining_frames, frame_step, i, c;
+	unsigned int remaining_frames, i, c;
 	const u32 *src;
 
-	channels = s->pcm_channels;

This change is not necessary. I used a separate local variable deliberately to allow the compiler to recognize that it cannot be aliased with the buffer contents.

Quoted 7 lines
sound/firewire/amdtp.c +2 -0
@@ -403,29 +406,29 @@ static void amdtp_write_s32_dualwire(struct amdtp_stream *s,
 	for (i = 0; i < frames; ++i) {
 		for (c = 0; c < channels; ++c) {
+			buffer[s->pcm_positions[c] * 2] =
+					cpu_to_be32((*src >> 8) | 0x40000000);
 			src++;
 		}

sound/firewire/amdtp.c static void amdtp_write_s32_dualwire(struct amdtp_stream *s, · line 421

Quoted 10 lines
sound/firewire/amdtp.c +6 -0
+		buffer += 1;
 		for (c = 0; c < channels; ++c) {
+			buffer[s->pcm_positions[c] * 2] =
+					cpu_to_be32((*src >> 8) | 0x40000000);
 			src++;
 		}
+		buffer += s->data_block_quadlets - 1;
+		if (--remaining_frames == 0)
+			src = (void *)runtime->dma_area;
 	}

AFAICS the dual-wire format could be handled easier by setting pcm_positions[] in the dice driver.

Regards,
Clemens

maintainer
#41 lore raw

Re: [PATCH 14/39] firewire-lib: Add handling output connection by CMP

In reply to Takashi Sakamoto
Quoted 13 lines · Takashi Sakamoto

This patch adds some macros, codes with condition of direction and new functions to handle output connection. Once cmp_connection_init() is executed with its direction, CMP input and output connection can be handled by the same way.

+++ b/sound/firewire/cmp.c

sound/firewire/cmp.c +8 -0
+static unsigned long long get_offset(struct cmp_connection *c, bool master)
+{
+	unsigned long long offset = CSR_REGISTER_BASE;
+
+	if (!master) {
+		if (c->direction == CMP_INPUT)
+			offset += CSR_IPCR(c->pcr_index);
+		else

sound/firewire/cmp.c void cmp_error(struct cmp_connection *c, const char *fmt, ...) · line 74

Quoted 10 lines
sound/firewire/cmp.c +10 -0
+			offset += CSR_OPCR(c->pcr_index);
+	} else {
+		if (c->direction == CMP_INPUT)
+			offset += CSR_IMPR;
+		else
+			offset += CSR_OMPR;
+	}
+
+	return offset;
+}

This function is always used with a constant master parameter, and the two branches don't really share much code. Two functions would be simpler:

static u64 mpr_address(struct cmp_connection *c)

{
	if (c->direction == CMP_INPUT)
		return CSR_REGISTER_BASE + CSR_IMPR;
	else
		return CSR_REGISTER_BASE + CSR_OMPR;
}

static u64 pcr_address(struct cmp_connection *c)

{
	if (c->direction == CMP_INPUT)
		return CSR_REGISTER_BASE + CSR_IPCR(c->pcr_index);
	else
		return CSR_REGISTER_BASE + CSR_OPCR(c->pcr_index);
}

Regards,
Clemens

maintainer
#45 lore raw

Re: [PATCH 16/39] firewire-lib: Add some AV/C general commands

In reply to Takashi Sakamoto
Quoted 11 lines · Takashi Sakamoto

This commit adds three commands, which may be used by some firewire device drivers. These commands are defined in 'AV/C Digital Interface Command Set General Specification Version 4.2 (2004006, 1394TA)'.

1. PLUG INFO command (10.1)
2. INPUT PLUG SIGNAL FORMAT command (10.10)
3. OUTPUT PLUG SIGNAL FORMAT command (10.11)

By the command 1, the drivers can get the number of plugs for AV/C unit or subunit.
By the command 2 and 3, the drivers can get/set sampling frequency.

All these functions return errors with two different mechanisms, the AV/C response code or a negative Linux error code. This forces the caller to add a second error check that duplicates the one inside the function:

sound/firewire/speakers.c static int fwspk_hw_params(struct snd_pcm_substream *substream, · line 227

Quoted 9 lines
sound/firewire/speakers.c +7 -0
+	err = avc_general_set_sig_fmt(fwspk->unit, params_rate(hw_params),
+				      AVC_GENERAL_PLUG_DIR_IN, 0);
 	if (err < 0)
 		goto err_buffer;
+	if (err != 0x09 /* ACCEPTED */) {
+		dev_err(&fwspk->unit->device, "failed to set sample rate\n");
+		err = -EIO;
+		goto error;
+	}

Would there be problems if any response except ACCEPTED resulted in -EIO?

(And here, error should be err_buffer.)

Regards,
Clemens

maintainer
#50 lore raw

Re: [PATCH 17/39] firewire-lib: Add quirks for Fireworks

In reply to Takashi Sakamoto
Quoted 6 lines · Takashi Sakamoto

This commit adds three modifications for Echo Audio's Fireworks quirks.
...
2.Making this module to calculate data block size and not to check continuity One of Fireworks device, AudioFirePre8, always reports 8 data block size in in-packets and the data block counter is incremented by 8. But actual value is different.

Does this really make it impossible to check DBC?

Quoted 4 lines

3.Making this module to have the numebr of first data blocks for MIDI messages in out-packet
Fireworks can pick up MIDI messages in first 8 data blocks and ignore in other data blocks.

Can this ever make the MIDI rate less than 3125 bytes per second? If not, then we can simply apply this quirk to all devices.

(Which reminds me: we must ensure that the rate never exceeds 3125 bytes/s; most other devices have a smaller buffer than Fireworks devices, and even those will eventually overflow.)

Regards,
Clemens

maintainer
#12 lore raw

Re: [PATCH 05/39] firewire-lib: Add support for AMDTP in-stream and PCM capture

In reply to Clemens Ladisch
Quoted 1 line · Clemens Ladisch

Please format the if/else branches in the same way.

Do you mean these codes should be like this?:
###

if (s->direction == AMDTP_OUT_STREAM) {
	if (s->dual_wire)
		s->transfer_samples = amdtp_write_s32_dualwire;
	else
		s->transfer_samples = amdtp_write_s32;
} else {
	if (s->dual_wire)
		s->transfer_samples = amdtp_read_s32_dualwire;
	else
		s->transfer_samples = amdtp_read_s32;
}

###

Quoted 2 lines

(AMDTP_FDF_NO_DATA << CIP_FDF_SFC_SHIFT) would be a constant that could be computed at compile time.

It's nice, OK.

Quoted 1 line

In practice, this error means that a packet was dropped.

In theory, it's true.

But BeBoB based devices have a quirk related to this. (I forgot to mention about it.) Just after connecting, they transmit packets with 0x00 for its DBC field.

Yamaha GO46:

[13803.762518] 00050000 9001ffff
[13803.762523] 00050000 9001ffff
[13803.762525] 00050000 9001ffff
[13803.762527] 00050000 9001ffff
...
[13804.737925] 00050000 90014a1d
[13804.737927] 00050008 90016387
[13804.737929] 00050010 9001ffff

...

Quoted 2 lines

I guess this doesn't actually happen too often, but eventually, we should handle this either by inserting some samples or by stopping the stream.

So if doing something for this state, we shouldn't stop streams (of cource, we can add a flag for BeBoB.) We should insert some zero PCM samples or zero MIDI messages.

But this idea forces PCM/MIDI functionality to work for these meaningless data. I think it's a waste of resources.

Thanks

Takashi Sakamoto
[email protected]

maintainer
#17 lore raw

Re: [PATCH 06/39] firewire-lib: Add support for MIDI capture/playback

In reply to Clemens Ladisch
Quoted 1 line · Clemens Ladisch

This is a 32-bit value.

OK.

Is it OK to use an assignment conversion here? Like:
for (f = 0; f < frames; f++) {
+ buffer[s->pcm_channels + 1] = 0x00;

Quoted 2 lines

snd_rawmidi_transmit() will not write an unsused byte, and in any case, zero can be a valid MIDI data byte.

OK. The line is needless.

Quoted 1 line

The buffer pointer must be increased even when there is no active port.

Exactly. I confirm M-Audio Ozonic (opens two MIDI ports) receives wrong sequence of MIDI data because of this bug...

Quoted 3 lines

fw_iso_context_create() can return an error code, but for s->pcm, all the IS_ERR stuff is not necessary. This should be a plain NULL check.

OK.

Thanks

Takashi Sakamoto
[email protected]

maintainer
#21 lore raw

Re: [PATCH 08/39] firewire-lib: Add support for duplex streams synchronization in blocking mode

In reply to Clemens Ladisch
Quoted 1 line · Clemens Ladisch

This pointer does not report any actual error code either.

OK. I use NULL instead of this.

Quoted 1 line

Why this change in this patch?

It's my mistake and should be removed.

Quoted 3 lines

It might be easier to check just s->sync_slave instead of multiple flags.

Same here.

Hm. But s->sync_slave->callbacked is also needed. So:

###
if (s->sync_slave && s->sync_slave->callbacked)
###

Quoted 2 lines

This name is rather generic; this is not "the" callback, but the "initial" or "first" callback.

OK. I use "amdtp_stream_first_callback" instead of "amdtp_stream_callback".

Quoted 1 line

This is not necessary here.

Exactly.

Quoted 1 line

This needs to be done only if sync_mode != CIP_SYNC_TO_DEVICE.

OK.

Regards

Takashi Sakamoto
[email protected]

maintainer
#34 lore raw

Re: [PATCH 11/39] firewire-lib: Add support for channel mapping

In reply to Clemens Ladisch
Quoted 3 lines · Clemens Ladisch

This change is not necessary. I used a separate local variable deliberately to allow the compiler to recognize that it cannot be aliased with the buffer contents.

I cannot understand your intention.

Quoted 2 lines

AFAICS the dual-wire format could be handled easier by setting pcm_positions[] in the dice driver.

Currently I have no interests of dice driver.

Thanks

Takashi Sakamoto
[email protected]

maintainer
#42 lore raw

Re: [PATCH 14/39] firewire-lib: Add handling output connection by CMP

In reply to Clemens Ladisch
Quoted 11 lines · Clemens Ladisch

This function is always used with a constant master parameter, and the two branches don't really share much code. Two functions would be simpler:

static u64 mpr_address(struct cmp_connection *c)

{
	if (c->direction == CMP_INPUT)
		return CSR_REGISTER_BASE + CSR_IMPR;
	else
		return CSR_REGISTER_BASE + CSR_OMPR;
}
Quoted 7 lines

static u64 pcr_address(struct cmp_connection *c)

{
	if (c->direction == CMP_INPUT)
		return CSR_REGISTER_BASE + CSR_IPCR(c->pcr_index);
	else
		return CSR_REGISTER_BASE + CSR_OPCR(c->pcr_index);
}

This is a good idea.

Takashi Sakamoto
[email protected]

maintainer
#51 lore raw

Re: [PATCH 17/39] firewire-lib: Add quirks for Fireworks

In reply to Clemens Ladisch
Quoted 1 line · Clemens Ladisch

Does this really make it impossible to check DBC?

Just with this quirk, I cannot disable this checking. I should have described BeBoB quirks here.

Quoted 2 lines

Can this ever make the MIDI rate less than 3125 bytes per second? If not, then we can simply apply this quirk to all devices.

I note that this quirk does not relate to MIDI rate.

Fireworks just ignores MIDI messages in more data blocks than 8 even if MIDI rate is enough low.

Quoted 3 lines

(Which reminds me: we must ensure that the rate never exceeds 3125 bytes/s; most other devices have a smaller buffer than Fireworks devices, and even those will eventually overflow.)

It's another issue, not for fireworks. It should be discussed in the other opportunities.

Thanks

Takashi Sakamoto
[email protected]

maintainer
#46 lore raw

Re: [PATCH 16/39] firewire-lib: Add some AV/C general commands

In reply to Clemens Ladisch
Quoted 3 lines · Clemens Ladisch

All these functions return errors with two different mechanisms, the AV/C response code or a negative Linux error code. This forces the caller to add a second error check that duplicates the one inside the function:

It's my intension.

Currently firewire-lib doesn't support 'deferred transaction' defined in 'AV/C Digital Interface Command Set General Specification (4.0 or later as long as I know)'. Then each driver needs to judge response codes.

Quoted 1 line

Would there be problems if any response except ACCEPTED resulted in -EIO?

The speakers.c did it. So I just keep it.

Quoted 1 line

(And here, error should be err_buffer.)

Exactly.

Thanks

Takashi Sakamoto
[email protected]

maintainer
#24 lore raw

Re: [PATCH 09/39] firewire-lib: Add sort function for transmitted packet

In reply to Clemens Ladisch
Quoted 13 lines · Clemens Ladisch

Then this should be done only when we actually have one of these known devices (and only when this error is known to happen, i.e., directly after a no-data packet); otherwise, this could, in theory, interfere with dropped packets.

Quoted 7 lines

This commit add sorting of in-packets. When callback of receive-context is processed, the parameters of in-packets are stored in sort table and sorted by its value of data block counter. The sort algorism works faster in ordered sequence than in messy sequence. This is convinient for this purpose because the sequence is assumed not to be so messy. After sorting, packets are processed except for a last few packets in sort table. These packets are stored in buffer once and used in next cycle.

Quoted 3 lines

Only a single packet is out of order, i.e., only two packets are exchanged. So it is not necessary to run a general-purpose sorting algorithm; it would be sufficient to store a single packet if it is out of order.

I cannot prove 'there are only two packets are exchanged'. What I can prove is 'the sequence of packets includes a bit disorder'.

I think keeping packet sequence is important to all of devices. So here I applied generic processing for this purpose.

(I wonder why I received nothing about my RFC in November...)

Quoted 1 line

A NULL check is not necessary for kfree().

I did read /mm/slab.c and realize it.

Thanks

Takashi Sakamoto
[email protected]

maintainer
#30 lore raw

Re: [PATCH 10/39] firewire-lib: Add transfer delay to synchronized duplex streams

In reply to Clemens Ladisch
Quoted 4 lines · Clemens Ladisch

The transfer delay is the offset between the frame in which the packet is transmitted and the intended presentation time. This delay was already added by the device when it sent the input packets, so we don't need to send it again.

Exactly. Adding TRANSFER_DELAY for out-packets is needless...

IEC 61883-6 said:
"If a function block receives a CIP, processes it and subsequently re-transmits it, then the SYT of the outgoing CIP shall be the sum of the incoming SYT and the processing delay."

Quoted 3 lines

The frame in which the out-packet will be sent is QUEUE_LENGTH frames later than that of the in-packet, so we need to adjust the SYT by that amount. (However, 48 % 16 == 0.)

So basically we need to add nothing to SYT for out-packet. This patch should be removed.

Thanks

Takashi Sakamoto
[email protected]

maintainer
#25 lore raw

Re: [PATCH 09/39] firewire-lib: Add sort function for transmitted packet

In reply to Takashi Sakamoto
Quoted 9 lines · Takashi Sakamoto
Quoted 5 lines · Clemens Ladisch
Quoted 1 line

This commit add sorting of in-packets. [...]

Only a single packet is out of order, i.e., only two packets are exchanged. So it is not necessary to run a general-purpose sorting algorithm; it would be sufficient to store a single packet if it is out of order.

I cannot prove 'there are only two packets are exchanged'. What I can prove is 'the sequence of packets includes a bit disorder'.

AFAIK this error happens only on some specific devices with some specific (now outdated) firmware versions, and two exchanged packets is all that is actually observed. Furthermore, hardware implementations of IEC 16883-6 construct packets in nearly real time and _cannot_ store many packets.

Thus, I think it is extremely unlikely that we will ever see more than two exchanged packets.

Quoted 1 line

I think keeping packet sequence is important to all of devices.

But there is no other device with a similar bug. I think the driver should keep the ability to detect dropped packets.

Regards,
Clemens

maintainer
#31 lore raw

Re: [PATCH 10/39] firewire-lib: Add transfer delay to synchronized duplex streams

In reply to Takashi Sakamoto
Quoted 6 lines · Takashi Sakamoto
Quoted 3 lines · Clemens Ladisch

The frame in which the out-packet will be sent is QUEUE_LENGTH frames later than that of the in-packet, so we need to adjust the SYT by that amount. (However, 48 % 16 == 0.)

So basically we need to add nothing to SYT for out-packet.

It would be possible to do the QUEUE_LENGTH adjustment in the code and rely on the compiler to optimize it away, but that would be silly. OTOH a comment might be useful.

Regards,
Clemens

maintainer
#36 lore raw

Re: [PATCH 11/39] firewire-lib: Add support for channel mapping

In reply to Takashi Sakamoto
Quoted 6 lines · Takashi Sakamoto
Quoted 3 lines · Clemens Ladisch

This change is not necessary. I used a separate local variable deliberately to allow the compiler to recognize that it cannot be aliased with the buffer contents.

I cannot understand your intention.

In code like this:

        for (... s->channels ...)
            buffer[i] = ...;

it is, as far as the compiler knows, possible that &buffer[i] and &s->channels actually point to the same variable, so s->channels must be reloaded in every loop iteration. A local variable avoids that.

(Whether this optimization is worth it is another question ...)

Quoted 4 lines
Quoted 2 lines

AFAICS the dual-wire format could be handled easier by setting pcm_positions[] in the dice driver.

Currently I have no interests of dice driver.

Okay, I'll write a patch on top of that.

Regards,
Clemens

maintainer
#37 lore raw

Re: [PATCH 11/39] firewire-lib: Add support for channel mapping

Quoted 10 lines · Clemens Ladisch

In code like this:

         for (... s->channels ...)
             buffer[i] = ...;

it is, as far as the compiler knows, possible that &buffer[i] and &s->channels actually point to the same variable, so s->channels must be reloaded in every loop iteration. A local variable avoids that.

(Whether this optimization is worth it is another question ...)

As long as I test with simple codes and gcc, this optimization reduce one opcode in a loop. Codes with your way compares address content to a register, but codes with my way once push address content to another register and compare the two registers.

The read/write functions are called the most freqently, so shorter codes are preferable. I realize I should keep it what you wrote. Thanks for your indication.

Thanks

Takashi Sakamoto
[email protected]

maintainer
#26 lore raw

Re: [PATCH 09/39] firewire-lib: Add sort function for transmitted packet

In reply to Clemens Ladisch

Clemens,

I have no time to discuss about this issue.
(If it was last November, I could have done it.)

I decide to remove this patch and drop support for Fireworks version 4.8 or former. I guess a support for some devices are also dropped because hardware vendor has never released firmware version 5.0 or later for the devices.

For detecting dropped packets, please reply to [05/39] patch.

Regards

Takashi Sakamoto
[email protected]

maintainer
#13 lore raw

Re: [PATCH 05/39] firewire-lib: Add support for AMDTP in-stream and PCM capture

In reply to Clemens Ladisch
Quoted 3 lines · Clemens Ladisch

In practice, this error means that a packet was dropped. I guess this doesn't actually happen too often, but eventually, we should handle this either by inserting some samples or by stopping the stream.

For inserting some samples, I realize that there are some difficulties:
- In non-blocking mode, assuming the number of PCM samples in dropped
packets is difficult because specification just define '0 <= N <= SYT_INTERVAL' (N = the number of events in packet). Each device can have different sequence of N in packets.
- In blocking mode, assuming the value of syt in dropped packets is
difficult because it's related to timing.

So I give up to think about recovering from dropped packets and make firewire-lib stops streaming when detecting this state.

But this is not better for BeBoB based devices as I mentioned in previous message. So I'll add some flags and codes for BeBoB.

Regards

Takashi Sakamoto
[email protected]

#27 lore raw

Re: [PATCH 09/39] firewire-lib: Add sort function for transmitted packet

In reply to Takashi Sakamoto

At Wed, 12 Mar 2014 10:23:45 +0900,

Quoted 10 lines · Takashi Sakamoto

Clemens,

I have no time to discuss about this issue.
(If it was last November, I could have done it.)

I decide to remove this patch and drop support for Fireworks version 4.8 or former. I guess a support for some devices are also dropped because hardware vendor has never released firmware version 5.0 or later for the devices.

His suggestion is to apply this workaround only for the limited devices with old firmwares. I guess it's feasible relatively easily?

Takashi

maintainer
#14 lore raw

Re: [PATCH 05/39] firewire-lib: Add support for AMDTP in-stream and PCM capture

In reply to Clemens Ladisch

Clemens,

Quoted 3 lines

In practice, this error means that a packet was dropped. I guess this doesn't actually happen too often, but eventually, we should handle this either by inserting some samples or by stopping the stream.

I'm working for this and I realize Fireworks has some quirks.

(I guess that I had experienced this last year then remove codes to check it and forget it now...)

Well, in IEC 61883-1, the value of dbc field corresponds to the first data block in a packet. And the value of dbc in a first packet is zero. So it also means count of transmitted data blocks (described in IEC 61883-6).

But for Fireworks, the value of dbc field corresponds to the end data block in a packet. See two samples below.

BeBoB - M-Audio Firewire Solo:
34 02040010 900234B2
02 02040018 9002FFFF
34 02040018 900248B2
34 02040020 900260B2
34 02040028 900274B2
02 02040030 9002FFFF
34 02040030 900288B2
34 02040038 9002A0B2
34 02040040 9002B4B2
02 02040048 9002FFFF
34 02040048 9002C8B2
34 02040050 9002E0B2
34 02040058 9002F4B2
02 02040060 9002FFFF
34 02040060 900208B2

Fireworks - AudioFire4(firmware 5.21):
Payload CIP0 CIP1
3A 00070028 9001C704
02 00070028 90FFFFFF
3A 00070030 9001E06E
3A 00070038 9001F5D8
3A 00070040 90010B42
02 00070040 90FFFFFF
3A 00070048 900124AC
3A 00070050 90013A16
02 00070050 90FFFFFF
3A 00070058 90015380
3A 00070060 900168EA
02 00070060 90FFFFFF
3A 00070068 90018254

Let us focus on the value of dbc in empty packet. In BeBoB, the value of dbc in packets following to empty packet is the same as the value in the empty packet. In Fireworks, the value of dbc in packets following to empty packet is not the same as the value in the empty packet, however the value of dbc in packets followed by empty packet is the same as the value in the empty packet. This means dbc corresponds to the end of data block in current packet. I can see this quirk on AudioFire4/AudioFirePre8 with firmware version 4.8-5.8, so I guess all of Fireworks have this quirk. (quirk 1)

Additionally, firmware version 5.5 seems to have a quirk to report fix value (0x08) for dbc interval in all sampling rates. I confirm this on AudioFire4 and AudioFirePre8, so I guess all of Fireworks with firmware version 5.5 have this quirk. (quirk 2)

Furthermore, Firmware named 'AudioFire9' seems to have a quirk to report fix value (0x11) for dbs in all sampling rates instead of actual value. I confirm this on AudioFirePre8 with firmware version 4.8-5.8. AudioFire8 (since July 2009) uses the same firmware so I guess this model has also this quirk. (quirk 3)

And as I mentioned before, BeBoB has a quirk not to increment dbc in initial state of transmitting. (quirk 4)

If firewire-lib has codes for these quirks, it can check dbc continuity. So I'll to add some flags for these issue into 'struct amdtp_stream', like:
struct amdtp_stream {
...
bool tx_dbc_is_end_event; // for quirk 1
unsigned int tx_dbc_interval; // for quirk 2
bool tx_dbs_is_wrong; // for quirk 3
bool skip_initial_tx_packets; // for quirk 4
...
};

But 'struct amdtp_stream' has 'flag' member. Should I use this member instead of adding new members?

Regards

Takashi Sakamoto
[email protected]

maintainer
#47 lore raw

Re: [PATCH 16/39] firewire-lib: Add some AV/C general commands

In reply to Clemens Ladisch

Clemens,

Quoted 3 lines · Clemens Ladisch

All these functions return errors with two different mechanisms, the AV/C response code or a negative Linux error code. This forces the caller to add a second error check that duplicates the one inside the function:

I realize a need to simplify these return value and decide to work for deferred transaction defined in 'AV/C Digital Interface Command Set General Specification'. If firewire-lib can handle deferred transaction, it's OK that AV/C functions in firewire-lib returns Linux error codes instead of combination error codes and response codes.

Well, can I request your comments about corresponding between response codes and Linux error codes?

Current my idea is below.

Return codes of CONTROL command:
if (err != 8) /* length of response is out of specification */

	err = -EIO;
else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
	err = -ENOSYS;
else if (buf[0] == 0x0a) /* REJECTED */
	err = -EINVAL;

Return codes of STATUS command:
if (err != 8) /* length of response is not our expectation */

	err = -EIO;
else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
	err = -ENOSYS;
else if (buf[0] == 0x0a) /* REJECTED */
	err = -EINVAL;
else if (buf[0] == 0x0b) /* IN TRANSITION */
	err = -EAGAIN;

Are these better?

Regards

Takashi Sakamoto
[email protected]

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

maintainer
#48 lore raw

Re: [PATCH 16/39] firewire-lib: Add some AV/C general commands

Quoted 22 lines · Takashi Sakamoto

can I request your comments about corresponding between response codes and Linux error codes?

Current my idea is below.

Return codes of CONTROL command:
if (err != 8) /* length of response is out of specification */

    err = -EIO;
else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
    err = -ENOSYS;
else if (buf[0] == 0x0a) /* REJECTED */
    err = -EINVAL;

Return codes of STATUS command:
if (err != 8) /* length of response is not our expectation */

    err = -EIO;
else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
    err = -ENOSYS;
else if (buf[0] == 0x0a) /* REJECTED */
    err = -EINVAL;
else if (buf[0] == 0x0b) /* IN TRANSITION */
    err = -EAGAIN;
Quoted 1 line

Are these better?

Yes, these look like the codes that match best.

Regards,
Clemens