Received: by 10.223.185.116 with SMTP id b49csp1087064wrg; Sat, 3 Mar 2018 15:11:30 -0800 (PST) X-Google-Smtp-Source: AG47ELtLRVGKfgaJ2W3F0eQp9vmv1i8xQGmQkC3BNBB40tYti0O270Ud/KKO4tvg+s8C8/6GiEFg X-Received: by 10.98.198.92 with SMTP id m89mr1701319pfg.73.1520118690592; Sat, 03 Mar 2018 15:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520118690; cv=none; d=google.com; s=arc-20160816; b=d5mX9bjNM0msAOlhgVrNd4UD4rfbl3yixKhsC5oqTg0wt3LjtcSDqQj0ge6TXMt369 mwroNbPr+jEmqyVxlTNMAhTaYIUTWPcMktFBI0zQvml11ELIqXoScviDm3GOjqRNrDPt uUOIWK1rGCdaqA0843KZ1YTnho5HluwOA7KjzUPVN+dwj7BkcW0Sq4fupty5V/0eZcjb 9xrJWF/zpps3vcfFClA+lspu5mc+Q3EDFLqIIS6lL39In2G6tX1QzxVk2XYdnCU/9epL AgLwfhnBgOKCSrD1FqHf1Ijbsw2xdZ2ypQKKc0uX7c/J1KSoVsKxMfXB46V4VVuZti6b Jlog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=yoPASsUQm32GijiwuUOHnC8Ar/Wz1Xmgzqh2Q3+NCVk=; b=Ovk5wb41lPwBVWiDnJZb4OJqdNg4lMhbKxvPEKKjCMgO9IxlERK9fydfa64CRCn/cl Wso2XrJTPTr9Lx44MZlpaNkjUiVLiFMYGCvygOMEdK7c4O4dXOVv2WmwMU5+zp9c0Vst 0kwO7sZvYRDHUrvrRtap/PxTIZxdWUq1tPeI/dSA+t744vDw6lyQUJDUBawr7wCvoJ/h ScP2WLq23dWtf9zOP1KfFFdM6FBj/ayekHReWS4u8CXYLFWaOTTBlPAR1XI3Ub33Y39M 7RmJqzYYIyDNxTPzO3EkyVDOEKYAv0GoU+BFojGJqci7n/ctSmbazBVRI4buh5UmFS+2 qlBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Rc5xM/A7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a31-v6si6905107pla.427.2018.03.03.15.11.16; Sat, 03 Mar 2018 15:11:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Rc5xM/A7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935096AbeCCXKL (ORCPT + 99 others); Sat, 3 Mar 2018 18:10:11 -0500 Received: from mail-co1nam03on0108.outbound.protection.outlook.com ([104.47.40.108]:14523 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935095AbeCCWj0 (ORCPT ); Sat, 3 Mar 2018 17:39:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=yoPASsUQm32GijiwuUOHnC8Ar/Wz1Xmgzqh2Q3+NCVk=; b=Rc5xM/A7riV8NZU3qWdXNqr2VFRFehgZx5ehB9Lfv1bai2GNiHvfrpG3KpKDVVrkAxyN1PiZQuBAMARDDnBKEtpkfw0Z8SfxIWbnfqPW4k3UEUCER7ExKTbCdWYInRcMKMrixd2PeriTtGkHkXOwSbGuWI0Db4Dy3Qg3mcX06rk= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB1113.namprd21.prod.outlook.com (52.132.149.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.588.1; Sat, 3 Mar 2018 22:39:20 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:39:20 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Takashi Sakamoto , Takashi Iwai , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 057/115] ALSA: firewire-digi00x: handle all MIDI messages on streaming packets Thread-Topic: [PATCH AUTOSEL for 4.4 057/115] ALSA: firewire-digi00x: handle all MIDI messages on streaming packets Thread-Index: AQHTsz9bi2lWEq40S0S4w51p9Hvo0A== Date: Sat, 3 Mar 2018 22:31:21 +0000 Message-ID: <20180303223010.27106-57-alexander.levin@microsoft.com> References: <20180303223010.27106-1-alexander.levin@microsoft.com> In-Reply-To: <20180303223010.27106-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB1113;6:WE5hxGk3N9stgc43SU1hT12UXRYlIcBNsLWLcnDaoNWCk5orIEbtIAKRzGlcjvcS0stFRU+6X0z+2t6CQK01Nfz7bVr19xuujLHK/+8wyPQScXWzD6rt3vgg6CGcl/doqJXjNm2RanIEtMz/wT8GnoQrdXeAnC/eNGklvjueNKJyJ/YSqJ6zjg5t70I0LSiLtaN3YgcPiAuokRGfcNur3CXHREQtErkLAzoBO8r5s5Jt/uTvRxJDWn8BT4jcDusGRgmGXHd4SYbPw3c8LMWLwIVmhoz95Q7s/LYfzCbcEHa65vf87DenhfC8GuW1YLzDunndwK8YKfT+oGRO2mA4PlId5eVduh3C8L2DrHIzaS/CiS8w0l8rqUQUPZUNqN+W;5:rUw3lx8+MIYxkoQvfjptJPVxNjqJn8XxxASblts4IoBWqll6X7SzG5nXxhRUzcjHvBj/hjHjqlbH1crdbYAM1buC1nP74ax3xbCT6KUk1qEcmAcS5aKkN/Cy9kBjgPvdfbnM/edNyG2zGUwlJbQwMubd0vLcM41uofHCYew+Pw4=;24:kLSOBKWg9PdlokC+RaY/rRZ+nS5j1UGrjj09pTSnWzfuxXaCVLMpfrWpMZrLbs4CkKJ0zd3FW0GzHf6i+4UmutIdak9YDp3wdl/VtNbn89g=;7:sdHKZQaV655wibj/tmpalfJR7BRBszXw2AmKVDRXNDwL+65L/iD07T1eNYcsWNJEpu03jwxcj6jmPdy1YOc3ozMAp0YyfADgE1mGgV1xmaNX8Y9eJ3AZh3GMJwVb6kb7P0lWs0lrAgAOb2hQAJiJ7iPuD5Ze2HukP4ygavqaalbpT1h/q6uzMSS1XUG8Hc9OCAiEYps0+QpZmgyCcCo1Vumw0qrh03bWx5gPO79L69kuh415vCB1eTFNAKLkHOWB x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 11a327c8-4d57-40b8-ba28-08d581579acf x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020);SRVR:MW2PR2101MB1113; x-ms-traffictypediagnostic: MW2PR2101MB1113: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(3231220)(944501244)(52105095)(10201501046)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011);SRVR:MW2PR2101MB1113;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1113; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(366004)(346002)(39860400002)(396003)(376002)(199004)(189003)(68736007)(7736002)(10090500001)(6116002)(3846002)(1076002)(2906002)(5250100002)(6486002)(2501003)(6436002)(76176011)(575784001)(86362001)(22452003)(6512007)(53936002)(66066001)(86612001)(99286004)(59450400001)(2900100001)(316002)(36756003)(54906003)(106356001)(110136005)(6506007)(102836004)(186003)(97736004)(26005)(6346003)(14454004)(3660700001)(8936002)(107886003)(10290500003)(5660300001)(81166006)(478600001)(15650500001)(3280700002)(105586002)(8676002)(81156014)(4326008)(72206003)(2950100002)(305945005)(25786009)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1113;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: yfm+sWp2hGe7fkq7tgyUV6My5c+4/clNWdpXEhFeYHqeMji8dODoZTOdm63VsAdW3gKttdbgfkjWszeXAK2e9LGZnY624SliBQ5GQhPSMT18HUkiMlhIpNFyp20DYoD5FBNKIIPAXCgU7V5YBccWLSi44XbWkBUd6LJio0yeiZA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11a327c8-4d57-40b8-ba28-08d581579acf X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:31:21.9946 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1113 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Sakamoto [ Upstream commit 8820a4cf0cb4cd5c6540a9a18b2cedbdfd5a6891 ] At a commit 9dc5d31cdceb ("ALSA: firewire-digi00x: handle MIDI messages in isochronous packets"), a functionality to handle MIDI messages on isochronous packet was supported. But this includes some of my misunderstanding. This commit is to fix them. For digi00x series, first data channel of data blocks in rx/tx packet includes MIDI messages. The data channel has 0x80 in 8 bit of its MSB, however it's against IEC 61883-6. Unique data format is applied: - Upper 4 bits of LSB represent port number. - 0x0: port 1. - 0x2: port 2. - 0xe: console port. - Lower 4 bits of LSB represent the number of included MIDI message bytes; 0x0/0x1/0x2. - Two bytes of middle of this data channel have MIDI bytes. Especially, MIDI messages from/to console surface are also transferred by isochronous packets, as well as physical MIDI ports. Signed-off-by: Takashi Sakamoto Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/firewire/digi00x/amdtp-dot.c | 55 +++++++++++++++++++++++++---------= ---- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/sound/firewire/digi00x/amdtp-dot.c b/sound/firewire/digi00x/am= dtp-dot.c index b02a5e8cad44..30e4925bf6b0 100644 --- a/sound/firewire/digi00x/amdtp-dot.c +++ b/sound/firewire/digi00x/amdtp-dot.c @@ -28,6 +28,9 @@ */ #define MAX_MIDI_RX_BLOCKS 8 =20 +/* 3 =3D MAX(DOT_MIDI_IN_PORTS, DOT_MIDI_OUT_PORTS) + 1. */ +#define MAX_MIDI_PORTS 3 + /* * The double-oh-three algorithm was discovered by Robin Gareus and Damien * Zammit in 2012, with reverse-engineering for Digi 003 Rack. @@ -42,10 +45,8 @@ struct amdtp_dot { unsigned int pcm_channels; struct dot_state state; =20 - unsigned int midi_ports; - /* 2 =3D MAX(DOT_MIDI_IN_PORTS, DOT_MIDI_OUT_PORTS) */ - struct snd_rawmidi_substream *midi[2]; - int midi_fifo_used[2]; + struct snd_rawmidi_substream *midi[MAX_MIDI_PORTS]; + int midi_fifo_used[MAX_MIDI_PORTS]; int midi_fifo_limit; =20 void (*transfer_samples)(struct amdtp_stream *s, @@ -124,8 +125,8 @@ int amdtp_dot_set_parameters(struct amdtp_stream *s, un= signed int rate, return -EBUSY; =20 /* - * A first data channel is for MIDI conformant data channel, the rest is - * Multi Bit Linear Audio data channel. + * A first data channel is for MIDI messages, the rest is Multi Bit + * Linear Audio data channel. */ err =3D amdtp_stream_set_parameters(s, rate, pcm_channels + 1); if (err < 0) @@ -135,11 +136,6 @@ int amdtp_dot_set_parameters(struct amdtp_stream *s, u= nsigned int rate, =20 p->pcm_channels =3D pcm_channels; =20 - if (s->direction =3D=3D AMDTP_IN_STREAM) - p->midi_ports =3D DOT_MIDI_IN_PORTS; - else - p->midi_ports =3D DOT_MIDI_OUT_PORTS; - /* * We do not know the actual MIDI FIFO size of most devices. Just * assume two bytes, i.e., one byte can be received over the bus while @@ -281,13 +277,25 @@ static void write_midi_messages(struct amdtp_stream *= s, __be32 *buffer, b =3D (u8 *)&buffer[0]; =20 len =3D 0; - if (port < p->midi_ports && + if (port < MAX_MIDI_PORTS && midi_ratelimit_per_packet(s, port) && p->midi[port] !=3D NULL) len =3D snd_rawmidi_transmit(p->midi[port], b + 1, 2); =20 if (len > 0) { - b[3] =3D (0x10 << port) | len; + /* + * Upper 4 bits of LSB represent port number. + * - 0000b: physical MIDI port 1. + * - 0010b: physical MIDI port 2. + * - 1110b: console MIDI port. + */ + if (port =3D=3D 2) + b[3] =3D 0xe0; + else if (port =3D=3D 1) + b[3] =3D 0x20; + else + b[3] =3D 0x00; + b[3] |=3D len; midi_use_bytes(s, port, len); } else { b[1] =3D 0; @@ -309,11 +317,22 @@ static void read_midi_messages(struct amdtp_stream *s= , __be32 *buffer, =20 for (f =3D 0; f < data_blocks; f++) { b =3D (u8 *)&buffer[0]; - port =3D b[3] >> 4; - len =3D b[3] & 0x0f; =20 - if (port < p->midi_ports && p->midi[port] && len > 0) - snd_rawmidi_receive(p->midi[port], b + 1, len); + len =3D b[3] & 0x0f; + if (len > 0) { + /* + * Upper 4 bits of LSB represent port number. + * - 0000b: physical MIDI port 1. Use port 0. + * - 1110b: console MIDI port. Use port 2. + */ + if (b[3] >> 4 > 0) + port =3D 2; + else + port =3D 0; + + if (port < MAX_MIDI_PORTS && p->midi[port]) + snd_rawmidi_receive(p->midi[port], b + 1, len); + } =20 buffer +=3D s->data_block_quadlets; } @@ -364,7 +383,7 @@ void amdtp_dot_midi_trigger(struct amdtp_stream *s, uns= igned int port, { struct amdtp_dot *p =3D s->protocol; =20 - if (port < p->midi_ports) + if (port < MAX_MIDI_PORTS) ACCESS_ONCE(p->midi[port]) =3D midi; } =20 --=20 2.14.1