Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5205634rwd; Mon, 12 Jun 2023 01:19:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4XT0REXyazc/2cp8Q9Gy9d+PIIci6ByXFeiuHBab/BhaS0LW0+YPpbG4t8Fz3uaII8Ev5/ X-Received: by 2002:a05:6a20:a58b:b0:104:b21f:26b0 with SMTP id bc11-20020a056a20a58b00b00104b21f26b0mr8594901pzb.47.1686557966115; Mon, 12 Jun 2023 01:19:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686557966; cv=none; d=google.com; s=arc-20160816; b=jTaSCAwX2ppTtLtwAVnkVPVhukXfvVTNgX8zfdgXcPHxLCv61q/grR9BbfifTXNjOW xnyDpvf0tvJn1+1JBZSRLdxV+d2AlfbzASJpdZ/I3n/EmLF/NqZpM9OiLVVol/j1gmyI EBlMyOewa/w8MiMYH7w7BmXgauksaTQ6eX7IqtNW1QnujkG9arJZ4bklLhiPM67v0ZgI Gz6n4j60b0YN3m1VJp0kGuWDK9/gfn7vBOePCyWw+FPQJLS9l/gTgbbEMKJ9oLQ/SEhJ n07DhrJhFSG1wmhtttOQ6wafUqDISMnQwjGJYTmgnmqnIKw0xpAZPbjN+l5iHaABFZHz Fa+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=/lmTcnQvPXfOqzH45/oFPrEnvSagw7pp+VGlRZVQxy0=; b=EL6UPjC4gU++k0bbVekCyEaM/dvFH+fWOUlIqJsVLNGuXga6BbsJIiVAlw1XoLeqdI 1eD5KG42zl2E+hdLNNn9VKlqyIwsWmDCjUJ5hOKm1ixaV9Vs8iBoWv9QHF3C8jkjB5j2 TAoDBI2Vxd12trOdpytyJLAWY3IAwBwogXvT1tWnnIr1bqLHESVAbd5dr33f1lFAdqXV SX2q+FlPXTPELCN1vxwMJP2X1/rkkFjPh0HjveQ/uZ2pKXZN8Mo3ISRA0xKeD4dF4FTc n8WoVZTkOsg0eVtg64kFGW1C/ZScbj8qtAdCgnCXl/mhQDIfWAF8/QmC15xLlfx7tM7T YQyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ZwWy25Wi; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=VjkFupeZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a056a0000c700b00643a730d50bsi6499826pfj.389.2023.06.12.01.19.13; Mon, 12 Jun 2023 01:19:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ZwWy25Wi; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=VjkFupeZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbjFLILt (ORCPT + 99 others); Mon, 12 Jun 2023 04:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbjFLILm (ORCPT ); Mon, 12 Jun 2023 04:11:42 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C4001705 for ; Mon, 12 Jun 2023 01:11:15 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5874722859; Mon, 12 Jun 2023 08:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1686557466; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/lmTcnQvPXfOqzH45/oFPrEnvSagw7pp+VGlRZVQxy0=; b=ZwWy25Wi7mWIYGktowrhQBkUdfrGcfYdO6CuIVy7IatV9PpS1CvY5c4U5rnFzuFXb0RaS7 BMcxg1DGDDHboKkbsa1qiDZhw1GXSKUxaA3oa5eEukGvJeyQFXxdWu+BgdGGA1JHhBI9Ja lP5RFfQvebtGQJ6jdEwkgHEWX3grepc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1686557466; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/lmTcnQvPXfOqzH45/oFPrEnvSagw7pp+VGlRZVQxy0=; b=VjkFupeZ3cvFKjx73fDBh5DudaA5oWnZMdhX46kxI8ixgSVGMnU5KTPEudm6tF2lq5Y9yk 4w53TQ3FuI/vojAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 37309138EC; Mon, 12 Jun 2023 08:11:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sKe0DBrThmSLcAAAMHmgww (envelope-from ); Mon, 12 Jun 2023 08:11:06 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 03/10] ALSA: usb-audio: Parse UMP Endpoint and Function Blocks at first Date: Mon, 12 Jun 2023 10:10:47 +0200 Message-Id: <20230612081054.17200-4-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230612081054.17200-1-tiwai@suse.de> References: <20230612081054.17200-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Try to parse the UMP Endpoint and UMP Function Blocks for building the topology at first. Only when those are missing (e.g. on an older USB MIDI 2.0 spec or a unidirectional endpoint), the driver still creates blocks based on USB group terminal block information as fallback. Signed-off-by: Takashi Iwai --- sound/usb/midi2.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/sound/usb/midi2.c b/sound/usb/midi2.c index 341783418a6a..fad094e15999 100644 --- a/sound/usb/midi2.c +++ b/sound/usb/midi2.c @@ -80,6 +80,7 @@ struct snd_usb_midi2_ump { struct snd_usb_midi2_endpoint *eps[2]; /* USB MIDI endpoints */ int index; /* rawmidi device index */ unsigned char usb_block_id; /* USB GTB id used for finding a pair */ + bool ump_parsed; /* Parsed UMP 1.1 EP/FB info*/ struct list_head list; /* list to umidi->rawmidi_list */ }; @@ -786,6 +787,31 @@ static int find_matching_ep_partner(struct snd_usb_midi2_interface *umidi, return 0; } +/* Call UMP helper to parse UMP endpoints; + * this needs to be called after starting the input streams for bi-directional + * communications + */ +static int parse_ump_endpoints(struct snd_usb_midi2_interface *umidi) +{ + struct snd_usb_midi2_ump *rmidi; + int err; + + list_for_each_entry(rmidi, &umidi->rawmidi_list, list) { + if (!rmidi->ump || + !(rmidi->ump->core.info_flags & SNDRV_RAWMIDI_INFO_DUPLEX)) + continue; + err = snd_ump_parse_endpoint(rmidi->ump); + if (!err) { + rmidi->ump_parsed = true; + } else { + if (err == -ENOMEM) + return err; + /* fall back to GTB later */ + } + } + return 0; +} + /* create a UMP block from a GTB entry */ static int create_gtb_block(struct snd_usb_midi2_ump *rmidi, int dir, int blk) { @@ -856,7 +882,7 @@ static int create_blocks_from_gtb(struct snd_usb_midi2_interface *umidi) if (!rmidi->ump) continue; /* Blocks have been already created? */ - if (rmidi->ump->info.num_blocks) + if (rmidi->ump_parsed || rmidi->ump->info.num_blocks) continue; /* loop over GTBs */ for (dir = 0; dir < 2; dir++) { @@ -1110,6 +1136,12 @@ int snd_usb_midi_v2_create(struct snd_usb_audio *chip, goto error; } + err = parse_ump_endpoints(umidi); + if (err < 0) { + usb_audio_err(chip, "Failed to parse UMP endpoint\n"); + goto error; + } + err = create_blocks_from_gtb(umidi); if (err < 0) { usb_audio_err(chip, "Failed to create GTB blocks\n"); -- 2.35.3