From patchwork Sat Sep 19 02:21:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 7221591 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 708DBBEEC1 for ; Sat, 19 Sep 2015 02:24:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7DB0E2091B for ; Sat, 19 Sep 2015 02:24:56 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 2FDBC20913 for ; Sat, 19 Sep 2015 02:24:55 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 38DAB2664A5; Sat, 19 Sep 2015 04:24:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 7EB482604F0; Sat, 19 Sep 2015 04:22:31 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 170712604D6; Sat, 19 Sep 2015 04:22:29 +0200 (CEST) Received: from smtp303.phy.lolipop.jp (smtp303.phy.lolipop.jp [210.157.22.87]) by alsa0.perex.cz (Postfix) with ESMTP id 0F5A02604D6 for ; Sat, 19 Sep 2015 04:22:14 +0200 (CEST) Received: from smtp303.phy.lolipop.lan (HELO smtp303.phy.lolipop.jp) (172.17.1.87) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp303.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Sat, 19 Sep 2015 11:22:10 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp303.phy.lolipop.jp (LOLIPOP-Fsecure); Sat, 19 Sep 2015 11:22:03 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: clemens@ladisch.de, tiwai@suse.de Date: Sat, 19 Sep 2015 11:21:53 +0900 Message-Id: <1442629322-15457-7-git-send-email-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1442629322-15457-1-git-send-email-o-takashi@sakamocchi.jp> References: <1442629322-15457-1-git-send-email-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org, ffado-devel@lists.sf.net Subject: [alsa-devel] [PATCH 06/15] ALSA: firewire-lib: add support arbitrary value for fmt/fdf fields in CIP header X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Some vendor specific protocol uses its own value for fmt/fdf fields in CIP header. This commit support to set arbitrary values for the fields. In IEC 61883-6, NO-DATA code is defined for FDF field. A packet with this code includes no data even if it includes some data blocks. This commit still leaves a condition to handle this special packet. Signed-off-by: Takashi Sakamoto --- sound/firewire/amdtp.c | 31 +++++++++++++++++++++++-------- sound/firewire/amdtp.h | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c index 5a3a452..b251f4b 100644 --- a/sound/firewire/amdtp.c +++ b/sound/firewire/amdtp.c @@ -59,8 +59,8 @@ * Audio and Music transfer protocol specific parameters * only "Clock-based rate control mode" is supported */ -#define CIP_FMT_AM (0x10 << CIP_FMT_SHIFT) -#define AMDTP_FDF_AM824 (0 << (CIP_FDF_SHIFT + 3)) +#define CIP_FMT_AM 0x10 +#define AMDTP_FDF_AM824 0x00 #define AMDTP_FDF_NO_DATA 0xff /* TODO: make these configurable */ @@ -94,6 +94,8 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit, s->callbacked = false; s->sync_slave = NULL; + s->fmt = CIP_FMT_AM; + return 0; } EXPORT_SYMBOL(amdtp_stream_init); @@ -225,6 +227,8 @@ int amdtp_stream_set_parameters(struct amdtp_stream *s, s->data_block_quadlets = s->pcm_channels + midi_channels; s->midi_ports = midi_ports; + s->fdf = AMDTP_FDF_AM824 | s->sfc; + /* * In IEC 61883-6, one data block represents one event. In ALSA, one * event equals to one PCM frame. But Dice has a quirk at higher @@ -691,8 +695,10 @@ static int handle_out_packet(struct amdtp_stream *s, unsigned int data_blocks, buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) | (s->data_block_quadlets << CIP_DBS_SHIFT) | s->data_block_counter); - buffer[1] = cpu_to_be32(CIP_EOH | CIP_FMT_AM | AMDTP_FDF_AM824 | - (s->sfc << CIP_FDF_SHIFT) | syt); + buffer[1] = cpu_to_be32(CIP_EOH | + ((s->fmt << CIP_FMT_SHIFT) & CIP_FMT_MASK) | + ((s->fdf << CIP_FDF_SHIFT) & CIP_FDF_MASK) | + (syt & CIP_SYT_MASK)); s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff; @@ -732,6 +738,7 @@ static int handle_in_packet(struct amdtp_stream *s, unsigned int *data_blocks, unsigned int syt) { u32 cip_header[2]; + unsigned int fmt, fdf; unsigned int data_block_quadlets, data_block_counter, dbc_interval; struct snd_pcm_substream *pcm; unsigned int pcm_frames; @@ -745,8 +752,7 @@ static int handle_in_packet(struct amdtp_stream *s, * For convenience, 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)) { + ((cip_header[1] & CIP_EOH_MASK) != CIP_EOH)) { dev_info_ratelimited(&s->unit->device, "Invalid CIP header for AMDTP: %08X:%08X\n", cip_header[0], cip_header[1]); @@ -755,10 +761,19 @@ static int handle_in_packet(struct amdtp_stream *s, goto end; } + /* Check valid protocol or not. */ + fmt = (cip_header[1] & CIP_FMT_MASK) >> CIP_FMT_SHIFT; + if (fmt != s->fmt) { + dev_err(&s->unit->device, + "Detect unexpected protocol: %08x %08x\n", + cip_header[0], cip_header[1]); + return -EIO; + } + /* Calculate data blocks */ + fdf = (cip_header[1] & CIP_FDF_MASK) >> CIP_FDF_SHIFT; if (payload_quadlets < 3 || - ((cip_header[1] & CIP_FDF_MASK) == - (AMDTP_FDF_NO_DATA << CIP_FDF_SHIFT))) { + (fmt == CIP_FMT_AM && fdf == AMDTP_FDF_NO_DATA)) { *data_blocks = 0; } else { data_block_quadlets = diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h index 6522925..883bb1a 100644 --- a/sound/firewire/amdtp.h +++ b/sound/firewire/amdtp.h @@ -128,6 +128,8 @@ struct amdtp_stream { unsigned int source_node_id_field; unsigned int data_block_quadlets; unsigned int data_block_counter; + unsigned int fmt; + unsigned int fdf; /* quirk: fixed interval of dbc between previos/current packets. */ unsigned int tx_dbc_interval; /* quirk: indicate the value of dbc field in a first packet. */