[PATCH 0/3] ALSA: firewire-lib: drop initial NODATA packets or empty packets
Hi,
This patchset is for convenience of ALSA bebob and firewire-tascam drivers.
The devices based on BeBoB ASICs or the devices in Tascam FireWire series transfer a batch of NODATA packet or empty packet in initial step of streaming. To avoid processing them, current implementation uses an option to skip processing content of tx packet during some initial cycles. However, the hard-coded number is not enough useful.
In 1st patch, ALSA IEC 61883-1/6 packet streaming engine becomes to drop the initial packets. As a result, The tx_init_skip_cycles argument of amdtp_domain_start() function changes its meaning. In the following patches, ALSA bebob driver is refactored.
Takashi Sakamoto (3): ALSA: firewire-lib: drop initial tx packets with NODATA or empty ALSA: bebob: cancel switching connection order ALSA: bebob: distinguish M-Audio ProFire Lightbridge quirk
sound/firewire/amdtp-stream.c | 130 +++++++++++++++++++++------- sound/firewire/amdtp-stream.h | 3 + sound/firewire/bebob/bebob.c | 10 ++- sound/firewire/bebob/bebob.h | 1 + sound/firewire/bebob/bebob_stream.c | 25 ++---- 5 files changed, 119 insertions(+), 50 deletions(-)
The devices based on BeBoB ASICs or the devices in Tascam FireWire series transfer a batch of NODATA packet or empty packet in initial step of streaming. To avoid processing them, current implementation uses an option to skip processing content of tx packet during some initial cycles. However, the hard-coded number is not enough useful.
This commit drops content of packets till the packet includes any event. The function of option is to skip processing content of tx packet with any event after dropping.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- sound/firewire/amdtp-stream.c | 130 +++++++++++++++++++++++++--------- sound/firewire/amdtp-stream.h | 3 + 2 files changed, 100 insertions(+), 33 deletions(-)
diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c index 6dceb8cd6e0c..3576cda3f000 100644 --- a/sound/firewire/amdtp-stream.c +++ b/sound/firewire/amdtp-stream.c @@ -49,8 +49,10 @@ #define CIP_FMT_MASK 0x3f000000 #define CIP_FDF_MASK 0x00ff0000 #define CIP_FDF_SHIFT 16 +#define CIP_FDF_NO_DATA 0xff #define CIP_SYT_MASK 0x0000ffff #define CIP_SYT_NO_INFO 0xffff +#define CIP_NO_DATA ((CIP_FDF_NO_DATA << CIP_FDF_SHIFT) | CIP_SYT_NO_INFO)
#define CIP_HEADER_SIZE (sizeof(__be32) * CIP_HEADER_QUADLETS)
@@ -1198,6 +1200,99 @@ static void process_tx_packets_intermediately(struct fw_iso_context *context, u3 } }
+static void drop_tx_packets_initially(struct fw_iso_context *context, u32 tstamp, + size_t header_length, void *header, void *private_data) +{ + struct amdtp_stream *s = private_data; + struct amdtp_domain *d = s->domain; + __be32 *ctx_header; + unsigned int count; + unsigned int events; + int i; + + if (s->packet_index < 0) + return; + + count = header_length / s->ctx_data.tx.ctx_header_size; + + // Attempt to detect any event in the batch of packets. + events = 0; + ctx_header = header; + for (i = 0; i < count; ++i) { + unsigned int payload_quads = + (be32_to_cpu(*ctx_header) >> ISO_DATA_LENGTH_SHIFT) / sizeof(__be32); + unsigned int data_blocks; + + if (s->flags & CIP_NO_HEADER) { + data_blocks = payload_quads / s->data_block_quadlets; + } else { + __be32 *cip_headers = ctx_header + IR_CTX_HEADER_DEFAULT_QUADLETS; + + if (payload_quads < CIP_HEADER_QUADLETS) { + data_blocks = 0; + } else { + payload_quads -= CIP_HEADER_QUADLETS; + + if (s->flags & CIP_UNAWARE_SYT) { + data_blocks = payload_quads / s->data_block_quadlets; + } else { + u32 cip1 = be32_to_cpu(cip_headers[1]); + + // NODATA packet can includes any data blocks but they are + // not available as event. + if ((cip1 & CIP_NO_DATA) == CIP_NO_DATA) + data_blocks = 0; + else + data_blocks = payload_quads / s->data_block_quadlets; + } + } + } + + events += data_blocks; + + ctx_header += s->ctx_data.tx.ctx_header_size / sizeof(__be32); + } + + drop_tx_packets(context, tstamp, header_length, header, s); + + if (events > 0) + s->ctx_data.tx.event_starts = true; + + // Decide the cycle count to begin processing content of packet in IR contexts. + { + unsigned int stream_count = 0; + unsigned int event_starts_count = 0; + unsigned int cycle = UINT_MAX; + + list_for_each_entry(s, &d->streams, list) { + if (s->direction == AMDTP_IN_STREAM) { + ++stream_count; + if (s->ctx_data.tx.event_starts) + ++event_starts_count; + } + } + + if (stream_count == event_starts_count) { + unsigned int next_cycle; + + list_for_each_entry(s, &d->streams, list) { + if (s->direction != AMDTP_IN_STREAM) + continue; + + next_cycle = increment_ohci_cycle_count(s->next_cycle, + d->processing_cycle.tx_init_skip); + if (cycle == UINT_MAX || + compare_ohci_cycle_count(next_cycle, cycle) > 0) + cycle = next_cycle; + + s->context->callback.sc = process_tx_packets_intermediately; + } + + d->processing_cycle.tx_start = cycle; + } + } +} + static void process_ctxs_in_domain(struct amdtp_domain *d) { struct amdtp_stream *s; @@ -1287,7 +1382,7 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context, if (s->direction == AMDTP_IN_STREAM) { cycle = compute_ohci_cycle_count(ctx_header[1]);
- context->callback.sc = drop_tx_packets; + context->callback.sc = drop_tx_packets_initially; } else { cycle = compute_ohci_it_cycle(*ctx_header, s->queue_size);
@@ -1298,38 +1393,6 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context, }
context->callback.sc(context, tstamp, header_length, header, s); - - // Decide the cycle count to begin processing content of packet in IR contexts. - if (s->direction == AMDTP_IN_STREAM) { - unsigned int stream_count = 0; - unsigned int callbacked_count = 0; - - list_for_each_entry(s, &d->streams, list) { - if (s->direction == AMDTP_IN_STREAM) { - ++stream_count; - if (s->callbacked) - ++callbacked_count; - } - } - - if (stream_count == callbacked_count) { - unsigned int next_cycle; - - list_for_each_entry(s, &d->streams, list) { - if (s->direction != AMDTP_IN_STREAM) - continue; - - next_cycle = increment_ohci_cycle_count(s->next_cycle, - d->processing_cycle.tx_init_skip); - if (compare_ohci_cycle_count(next_cycle, cycle) > 0) - cycle = next_cycle; - - s->context->callback.sc = process_tx_packets_intermediately; - } - - d->processing_cycle.tx_start = cycle; - } - } }
/** @@ -1409,6 +1472,7 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed, if (s->direction == AMDTP_IN_STREAM) { s->ctx_data.tx.max_ctx_payload_length = max_ctx_payload_size; s->ctx_data.tx.ctx_header_size = ctx_header_size; + s->ctx_data.tx.event_starts = false; } else { static const struct { unsigned int data_block; diff --git a/sound/firewire/amdtp-stream.h b/sound/firewire/amdtp-stream.h index 467d5021624b..d3ba2e1c1522 100644 --- a/sound/firewire/amdtp-stream.h +++ b/sound/firewire/amdtp-stream.h @@ -138,6 +138,9 @@ struct amdtp_stream { // Fixed interval of dbc between previos/current // packets. unsigned int dbc_interval; + + // The device starts multiplexing events to the packet. + bool event_starts; } tx; struct { // To generate CIP header.
Hi Takashi,
I love your patch! Perhaps something to improve:
[auto build test WARNING on sound/for-next] [cannot apply to v5.13-rc2 next-20210521] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Takashi-Sakamoto/ALSA-firewire-lib-... base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next config: s390-allyesconfig (attached as .config) compiler: s390-linux-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/a1c11b8ba891b02a7669df5e99ea3f407ee3... git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Takashi-Sakamoto/ALSA-firewire-lib-drop-initial-NODATA-packets-or-empty-packets/20210523-204607 git checkout a1c11b8ba891b02a7669df5e99ea3f407ee3efb7 # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot lkp@intel.com
All warnings (new ones prefixed by >>):
sound/firewire/amdtp-stream.c: In function 'amdtp_stream_first_callback':
sound/firewire/amdtp-stream.c:1376:6: warning: variable 'cycle' set but not used [-Wunused-but-set-variable]
1376 | u32 cycle; | ^~~~~
vim +/cycle +1376 sound/firewire/amdtp-stream.c
9b1fcd9bf80206 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-20 1367 60dd49298ec580 sound/firewire/amdtp-stream.c Takashi Sakamoto 2019-10-18 1368 // this is executed one time. 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1369 static void amdtp_stream_first_callback(struct fw_iso_context *context, 73fc7f080105b1 sound/firewire/amdtp-stream.c Takashi Sakamoto 2016-05-09 1370 u32 tstamp, size_t header_length, 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1371 void *header, void *private_data) 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1372 { 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1373 struct amdtp_stream *s = private_data; da3623abfbef44 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-20 1374 struct amdtp_domain *d = s->domain; 26cd1e5850b70b sound/firewire/amdtp-stream.c Takashi Sakamoto 2019-05-21 1375 const __be32 *ctx_header = header; a04513f8b1980e sound/firewire/amdtp-stream.c Takashi Sakamoto 2017-03-22 @1376 u32 cycle; 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1377 bdaedca74d6293 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-20 1378 // For in-stream, first packet has come. bdaedca74d6293 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-20 1379 // For out-stream, prepared to transmit first packet 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1380 s->callbacked = true; 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1381 cc4f8e91c4ed04 sound/firewire/amdtp-stream.c Takashi Sakamoto 2019-03-17 1382 if (s->direction == AMDTP_IN_STREAM) { 3e106f4f690ef0 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-18 1383 cycle = compute_ohci_cycle_count(ctx_header[1]); a04513f8b1980e sound/firewire/amdtp-stream.c Takashi Sakamoto 2017-03-22 1384 a1c11b8ba891b0 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-23 1385 context->callback.sc = drop_tx_packets_initially; a04513f8b1980e sound/firewire/amdtp-stream.c Takashi Sakamoto 2017-03-22 1386 } else { 3e106f4f690ef0 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-18 1387 cycle = compute_ohci_it_cycle(*ctx_header, s->queue_size); 26cd1e5850b70b sound/firewire/amdtp-stream.c Takashi Sakamoto 2019-05-21 1388 da3623abfbef44 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-20 1389 if (s == d->irq_target) 9b1fcd9bf80206 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-20 1390 context->callback.sc = irq_target_callback_skip; 2472cfb3232caf sound/firewire/amdtp-stream.c Takashi Sakamoto 2020-05-08 1391 else 9b1fcd9bf80206 sound/firewire/amdtp-stream.c Takashi Sakamoto 2021-05-20 1392 context->callback.sc = skip_rx_packets; a04513f8b1980e sound/firewire/amdtp-stream.c Takashi Sakamoto 2017-03-22 1393 } a04513f8b1980e sound/firewire/amdtp-stream.c Takashi Sakamoto 2017-03-22 1394 73fc7f080105b1 sound/firewire/amdtp-stream.c Takashi Sakamoto 2016-05-09 1395 context->callback.sc(context, tstamp, header_length, header, s); 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1396 } 7b3b0d8583c926 sound/firewire/amdtp.c Takashi Sakamoto 2014-04-25 1397
--- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
The order to establish connection seems to be meaningless.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- sound/firewire/bebob/bebob_stream.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c index df764171f84b..975670a29a72 100644 --- a/sound/firewire/bebob/bebob_stream.c +++ b/sound/firewire/bebob/bebob_stream.c @@ -623,7 +623,6 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob)
if (!amdtp_stream_running(&bebob->rx_stream)) { enum snd_bebob_clock_type src; - struct amdtp_stream *master, *slave; unsigned int curr_rate; unsigned int tx_init_skip_cycles;
@@ -637,19 +636,11 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob) if (err < 0) return err;
- if (src != SND_BEBOB_CLOCK_TYPE_SYT) { - master = &bebob->tx_stream; - slave = &bebob->rx_stream; - } else { - master = &bebob->rx_stream; - slave = &bebob->tx_stream; - } - - err = start_stream(bebob, master); + err = start_stream(bebob, &bebob->rx_stream); if (err < 0) goto error;
- err = start_stream(bebob, slave); + err = start_stream(bebob, &bebob->tx_stream); if (err < 0) goto error;
In former commit, ALSA IEC 61883-1/6 packet streaming engine drops initial tx packets till the packet includes any event. This allows ALSA bebob driver not to give option to skip initial packet since the engine does drop the initial packet.
However, M-Audio ProFire Lightbridge has a quirk to stop packet transmission after start multiplexing event to the packet. After several thousands cycles, it restart packet transmission again.
This commit specializes the usage of initial skip option for the model. Additionally, this commit expands timeout enough to wait processing content of tx packet.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- sound/firewire/bebob/bebob.c | 10 +++++++++- sound/firewire/bebob/bebob.h | 1 + sound/firewire/bebob/bebob_stream.c | 12 +++++++----- 3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/sound/firewire/bebob/bebob.c b/sound/firewire/bebob/bebob.c index 90e98a6d1546..5938aa325f5e 100644 --- a/sound/firewire/bebob/bebob.c +++ b/sound/firewire/bebob/bebob.c @@ -64,6 +64,7 @@ static DECLARE_BITMAP(devices_used, SNDRV_CARDS); #define MODEL_MAUDIO_AUDIOPHILE_BOTH 0x00010060 #define MODEL_MAUDIO_FW1814 0x00010071 #define MODEL_MAUDIO_PROJECTMIX 0x00010091 +#define MODEL_MAUDIO_PROFIRELIGHTBRIDGE 0x000100a1
static int name_device(struct snd_bebob *bebob) @@ -210,6 +211,13 @@ do_registration(struct work_struct *work) if (err < 0) goto error;
+ // M-Audio ProFire Lightbridge has a quirk to transfer packets with discontinuous cycle or + // data block counter in early stage of packet streaming. The cycle span from the first + // packet with event is variable. + if (bebob->entry->vendor_id == VEN_MAUDIO1 && + bebob->entry->model_id == MODEL_MAUDIO_PROFIRELIGHTBRIDGE) + bebob->discontinuity_quirk = true; + err = snd_bebob_stream_init_duplex(bebob); if (err < 0) goto error; @@ -476,7 +484,7 @@ static const struct ieee1394_device_id bebob_id_table[] = { /* M-Audio NRV10 */ SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x00010081, &maudio_nrv10_spec), /* M-Audio, ProFireLightbridge */ - SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x000100a1, &spec_normal), + SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_PROFIRELIGHTBRIDGE, &spec_normal), /* Firewire 1814 */ SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x00010070, NULL), /* bootloader */ SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_FW1814, diff --git a/sound/firewire/bebob/bebob.h b/sound/firewire/bebob/bebob.h index 4e0ed84adbee..cba6793bfdb2 100644 --- a/sound/firewire/bebob/bebob.h +++ b/sound/firewire/bebob/bebob.h @@ -115,6 +115,7 @@ struct snd_bebob {
/* For BeBoB version quirk. */ unsigned int version; + bool discontinuity_quirk;
struct amdtp_domain domain; }; diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c index 975670a29a72..91306da1bafe 100644 --- a/sound/firewire/bebob/bebob_stream.c +++ b/sound/firewire/bebob/bebob_stream.c @@ -7,7 +7,7 @@
#include "./bebob.h"
-#define READY_TIMEOUT_MS 2500 +#define READY_TIMEOUT_MS 4000
/* * NOTE; @@ -644,12 +644,14 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob) if (err < 0) goto error;
- // Some devices transfer isoc packets with discontinuous counter in the beginning - // of packet streaming. - if (bebob->version < 2) - tx_init_skip_cycles = 3200; + if (!bebob->discontinuity_quirk) + tx_init_skip_cycles = 0; else tx_init_skip_cycles = 16000; + + // MEMO: In the early stage of packet streaming, the device transfers NODATA packets. + // After several hundred cycles, it begins to multiplex event into the packet with + // syt information. err = amdtp_domain_start(&bebob->domain, tx_init_skip_cycles); if (err < 0) goto error;
participants (2)
-
kernel test robot
-
Takashi Sakamoto